summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c231
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c112
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c323
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c195
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c90
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c83
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c337
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c113
-rw-r--r--src/lib/libcrypto/asn1/a_int.c435
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c390
-rw-r--r--src/lib/libcrypto/asn1/a_object.c304
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c95
-rw-r--r--src/lib/libcrypto/asn1/a_print.c197
-rw-r--r--src/lib/libcrypto/asn1/a_set.c217
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c148
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c247
-rw-r--r--src/lib/libcrypto/asn1/a_time.c129
-rw-r--r--src/lib/libcrypto/asn1/a_type.c348
-rw-r--r--src/lib/libcrypto/asn1/a_utf8.c238
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c119
-rw-r--r--src/lib/libcrypto/asn1/asn1.h1067
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c352
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c424
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h560
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c385
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c145
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c137
-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.c348
-rw-r--r--src/lib/libcrypto/asn1/nsseq.c118
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c157
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c282
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c127
-rw-r--r--src/lib/libcrypto/asn1/t_bitst.c99
-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.c254
-rw-r--r--src/lib/libcrypto/asn1/t_spki.c116
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c409
-rw-r--r--src/lib/libcrypto/asn1/t_x509a.c102
-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.c343
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c139
-rw-r--r--src/lib/libcrypto/asn1/x_info.c114
-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.c366
-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.c210
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c200
-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.c306
-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.h125
-rw-r--r--src/lib/libcrypto/bio/b_dump.c128
-rw-r--r--src/lib/libcrypto/bio/b_print.c844
-rw-r--r--src/lib/libcrypto/bio/b_sock.c717
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c511
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c256
-rw-r--r--src/lib/libcrypto/bio/bf_null.c184
-rw-r--r--src/lib/libcrypto/bio/bio.h667
-rw-r--r--src/lib/libcrypto/bio/bio_cb.c133
-rw-r--r--src/lib/libcrypto/bio/bio_err.c147
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c534
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c467
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c857
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c650
-rw-r--r--src/lib/libcrypto/bio/bss_fd.c62
-rw-r--r--src/lib/libcrypto/bio/bss_file.c310
-rw-r--r--src/lib/libcrypto/bio/bss_log.c336
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c312
-rw-r--r--src/lib/libcrypto/bio/bss_null.c150
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c424
-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.h510
-rw-r--r--src/lib/libcrypto/bn/bn_add.c307
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c837
-rw-r--r--src/lib/libcrypto/bn/bn_blind.c144
-rw-r--r--src/lib/libcrypto/bn/bn_ctx.c144
-rw-r--r--src/lib/libcrypto/bn/bn_div.c380
-rw-r--r--src/lib/libcrypto/bn/bn_err.c119
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c749
-rw-r--r--src/lib/libcrypto/bn/bn_exp2.c199
-rw-r--r--src/lib/libcrypto/bn/bn_gcd.c210
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h321
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c755
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c339
-rw-r--r--src/lib/libcrypto/bn/bn_mpi.c129
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c794
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c465
-rw-r--r--src/lib/libcrypto/bn/bn_prime.h325
-rw-r--r--src/lib/libcrypto/bn/bn_prime.pl117
-rw-r--r--src/lib/libcrypto/bn/bn_print.c332
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c136
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c220
-rw-r--r--src/lib/libcrypto/bn/bn_shift.c200
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c288
-rw-r--r--src/lib/libcrypto/bn/bn_word.c194
-rw-r--r--src/lib/libcrypto/buffer/buf_err.c95
-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.h61
-rw-r--r--src/lib/libcrypto/comp/comp_err.c92
-rw-r--r--src/lib/libcrypto/comp/comp_lib.c78
-rw-r--r--src/lib/libcrypto/conf/conf.h116
-rw-r--r--src/lib/libcrypto/conf/conf_err.c101
-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.c95
-rw-r--r--src/lib/libcrypto/cryptlib.c302
-rw-r--r--src/lib/libcrypto/cryptlib.h96
-rw-r--r--src/lib/libcrypto/crypto.h373
-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.h267
-rw-r--r--src/lib/libcrypto/des/des_enc.c406
-rw-r--r--src/lib/libcrypto/des/des_locl.h412
-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.c171
-rw-r--r--src/lib/libcrypto/des/fcrypt.c152
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c145
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c148
-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.c129
-rw-r--r--src/lib/libcrypto/des/rand_key.c73
-rw-r--r--src/lib/libcrypto/des/set_key.c402
-rw-r--r--src/lib/libcrypto/des/spr.h204
-rw-r--r--src/lib/libcrypto/des/str2key.c155
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c194
-rw-r--r--src/lib/libcrypto/dh/dh.h201
-rw-r--r--src/lib/libcrypto/dh/dh_check.c120
-rw-r--r--src/lib/libcrypto/dh/dh_err.c99
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c153
-rw-r--r--src/lib/libcrypto/dh/dh_key.c211
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c187
-rw-r--r--src/lib/libcrypto/doc/DH_generate_key.pod50
-rw-r--r--src/lib/libcrypto/doc/DH_generate_parameters.pod72
-rw-r--r--src/lib/libcrypto/doc/DH_get_ex_new_index.pod36
-rw-r--r--src/lib/libcrypto/doc/DH_new.pod40
-rw-r--r--src/lib/libcrypto/doc/DH_set_method.pod99
-rw-r--r--src/lib/libcrypto/doc/DH_size.pod33
-rw-r--r--src/lib/libcrypto/doc/DSA_SIG_new.pod39
-rw-r--r--src/lib/libcrypto/doc/DSA_do_sign.pod47
-rw-r--r--src/lib/libcrypto/doc/DSA_dup_DH.pod36
-rw-r--r--src/lib/libcrypto/doc/DSA_generate_key.pod33
-rw-r--r--src/lib/libcrypto/doc/DSA_generate_parameters.pod105
-rw-r--r--src/lib/libcrypto/doc/DSA_get_ex_new_index.pod36
-rw-r--r--src/lib/libcrypto/doc/DSA_new.pod41
-rw-r--r--src/lib/libcrypto/doc/DSA_set_method.pod112
-rw-r--r--src/lib/libcrypto/doc/DSA_sign.pod66
-rw-r--r--src/lib/libcrypto/doc/DSA_size.pod33
-rw-r--r--src/lib/libcrypto/doc/ERR_GET_LIB.pod51
-rw-r--r--src/lib/libcrypto/doc/ERR_clear_error.pod29
-rw-r--r--src/lib/libcrypto/doc/ERR_error_string.pod65
-rw-r--r--src/lib/libcrypto/doc/ERR_get_error.pod62
-rw-r--r--src/lib/libcrypto/doc/ERR_load_crypto_strings.pod46
-rw-r--r--src/lib/libcrypto/doc/ERR_load_strings.pod54
-rw-r--r--src/lib/libcrypto/doc/ERR_print_errors.pod51
-rw-r--r--src/lib/libcrypto/doc/ERR_put_error.pod44
-rw-r--r--src/lib/libcrypto/doc/ERR_remove_state.pod34
-rw-r--r--src/lib/libcrypto/doc/EVP_DigestInit.pod197
-rw-r--r--src/lib/libcrypto/doc/EVP_EncryptInit.pod224
-rw-r--r--src/lib/libcrypto/doc/EVP_OpenInit.pod51
-rw-r--r--src/lib/libcrypto/doc/EVP_SealInit.pod70
-rw-r--r--src/lib/libcrypto/doc/EVP_SignInit.pod85
-rw-r--r--src/lib/libcrypto/doc/EVP_VerifyInit.pod71
-rw-r--r--src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod46
-rw-r--r--src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod65
-rw-r--r--src/lib/libcrypto/doc/RAND_add.pod77
-rw-r--r--src/lib/libcrypto/doc/RAND_bytes.pod46
-rw-r--r--src/lib/libcrypto/doc/RAND_cleanup.pod29
-rw-r--r--src/lib/libcrypto/doc/RAND_load_file.pod53
-rw-r--r--src/lib/libcrypto/doc/RAND_set_rand_method.pod59
-rw-r--r--src/lib/libcrypto/doc/RSA_blinding_on.pod43
-rw-r--r--src/lib/libcrypto/doc/RSA_check_key.pod39
-rw-r--r--src/lib/libcrypto/doc/RSA_generate_key.pod68
-rw-r--r--src/lib/libcrypto/doc/RSA_get_ex_new_index.pod122
-rw-r--r--src/lib/libcrypto/doc/RSA_new.pod39
-rw-r--r--src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod124
-rw-r--r--src/lib/libcrypto/doc/RSA_print.pod48
-rw-r--r--src/lib/libcrypto/doc/RSA_private_encrypt.pod70
-rw-r--r--src/lib/libcrypto/doc/RSA_public_encrypt.pod86
-rw-r--r--src/lib/libcrypto/doc/RSA_set_method.pod154
-rw-r--r--src/lib/libcrypto/doc/RSA_sign.pod62
-rw-r--r--src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod59
-rw-r--r--src/lib/libcrypto/doc/RSA_size.pod33
-rw-r--r--src/lib/libcrypto/doc/bn.pod148
-rw-r--r--src/lib/libcrypto/doc/d2i_DHparams.pod30
-rw-r--r--src/lib/libcrypto/doc/d2i_RSAPublicKey.pod39
-rw-r--r--src/lib/libcrypto/doc/dh.pod68
-rw-r--r--src/lib/libcrypto/doc/dsa.pod104
-rw-r--r--src/lib/libcrypto/doc/lh_stats.pod60
-rw-r--r--src/lib/libcrypto/doc/rsa.pod116
-rw-r--r--src/lib/libcrypto/dsa/dsa.h241
-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.c294
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c113
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c246
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c321
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c92
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c94
-rw-r--r--src/lib/libcrypto/err/err.c747
-rw-r--r--src/lib/libcrypto/err/err.h265
-rw-r--r--src/lib/libcrypto/err/err_all.c122
-rw-r--r--src/lib/libcrypto/err/err_prn.c105
-rw-r--r--src/lib/libcrypto/err/openssl.ec72
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c540
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c425
-rw-r--r--src/lib/libcrypto/evp/bio_md.c261
-rw-r--r--src/lib/libcrypto/evp/c_all.c67
-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.h743
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c270
-rw-r--r--src/lib/libcrypto/evp/evp_err.c143
-rw-r--r--src/lib/libcrypto/evp/evp_key.c159
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c142
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c134
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c407
-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.c123
-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.c333
-rw-r--r--src/lib/libcrypto/evp/p_open.c119
-rw-r--r--src/lib/libcrypto/evp/p_seal.c109
-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.c152
-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.c461
-rw-r--r--src/lib/libcrypto/lhash/lhash.h145
-rw-r--r--src/lib/libcrypto/md32_common.h607
-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.c319
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h172
-rw-r--r--src/lib/libcrypto/md5/md5_one.c95
-rw-r--r--src/lib/libcrypto/mem_dbg.c738
-rw-r--r--src/lib/libcrypto/objects/o_names.c265
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c649
-rw-r--r--src/lib/libcrypto/objects/obj_dat.pl275
-rw-r--r--src/lib/libcrypto/objects/obj_err.c99
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c126
-rw-r--r--src/lib/libcrypto/objects/objects.h1032
-rw-r--r--src/lib/libcrypto/objects/objects.txt40
-rw-r--r--src/lib/libcrypto/opensslv.h32
-rw-r--r--src/lib/libcrypto/pem/message16
-rw-r--r--src/lib/libcrypto/pem/pem.h663
-rw-r--r--src/lib/libcrypto/pem/pem2.h60
-rw-r--r--src/lib/libcrypto/pem/pem_all.c203
-rw-r--r--src/lib/libcrypto/pem/pem_err.c131
-rw-r--r--src/lib/libcrypto/pem/pem_info.c364
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c963
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c184
-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.pl118
-rw-r--r--src/lib/libcrypto/pkcs12/p12_add.c216
-rw-r--r--src/lib/libcrypto/pkcs12/p12_attr.c238
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crpt.c124
-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.c189
-rw-r--r--src/lib/libcrypto/pkcs12/p12_kiss.c254
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c173
-rw-r--r--src/lib/libcrypto/pkcs12/p12_npas.c212
-rw-r--r--src/lib/libcrypto/pkcs12/p12_utl.c118
-rw-r--r--src/lib/libcrypto/pkcs12/pk12err.c139
-rw-r--r--src/lib/libcrypto/pkcs12/pkcs12.h340
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c85
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c960
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c469
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_mime.c673
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c427
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.h498
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7err.c161
-rw-r--r--src/lib/libcrypto/rand/rand.h117
-rw-r--r--src/lib/libcrypto/rand/rand_err.c94
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c117
-rw-r--r--src/lib/libcrypto/rand/randfile.c260
-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.c315
-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.pl590
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.h101
-rw-r--r--src/lib/libcrypto/ripemd/rmd_dgst.c493
-rw-r--r--src/lib/libcrypto/ripemd/rmd_locl.h160
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c76
-rw-r--r--src/lib/libcrypto/ripemd/rmdconst.h399
-rw-r--r--src/lib/libcrypto/rsa/rsa.h338
-rw-r--r--src/lib/libcrypto/rsa/rsa_chk.c184
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c491
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c148
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c197
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c333
-rw-r--r--src/lib/libcrypto/rsa/rsa_none.c98
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c163
-rw-r--r--src/lib/libcrypto/rsa/rsa_pk1.c224
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c144
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c221
-rw-r--r--src/lib/libcrypto/rsa/rsa_ssl.c154
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl538
-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.c73
-rw-r--r--src/lib/libcrypto/sha/sha_locl.h471
-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.pl519
-rw-r--r--src/lib/libcrypto/x509/by_dir.c349
-rw-r--r--src/lib/libcrypto/x509/by_file.c298
-rw-r--r--src/lib/libcrypto/x509/x509.h1204
-rw-r--r--src/lib/libcrypto/x509/x509_att.c326
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c308
-rw-r--r--src/lib/libcrypto/x509/x509_d2.c107
-rw-r--r--src/lib/libcrypto/x509/x509_def.c81
-rw-r--r--src/lib/libcrypto/x509/x509_err.c152
-rw-r--r--src/lib/libcrypto/x509/x509_ext.c191
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c427
-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.c278
-rw-r--r--src/lib/libcrypto/x509/x509_set.c150
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c264
-rw-r--r--src/lib/libcrypto/x509/x509_txt.c141
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c267
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c815
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.h362
-rw-r--r--src/lib/libcrypto/x509/x509name.c383
-rw-r--r--src/lib/libcrypto/x509/x509rset.c83
-rw-r--r--src/lib/libcrypto/x509/x509spki.c121
-rw-r--r--src/lib/libcrypto/x509/x509type.c114
-rw-r--r--src/lib/libcrypto/x509/x_all.c531
-rw-r--r--src/lib/libcrypto/x509v3/ext_dat.h97
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c249
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c401
-rw-r--r--src/lib/libcrypto/x509v3/v3_bcons.c164
-rw-r--r--src/lib/libcrypto/x509v3/v3_bitst.c141
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c390
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c655
-rw-r--r--src/lib/libcrypto/x509v3/v3_crld.c285
-rw-r--r--src/lib/libcrypto/x509v3/v3_enum.c96
-rw-r--r--src/lib/libcrypto/x509v3/v3_extku.c150
-rw-r--r--src/lib/libcrypto/x509v3/v3_genn.c291
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c113
-rw-r--r--src/lib/libcrypto/x509v3/v3_info.c236
-rw-r--r--src/lib/libcrypto/x509v3/v3_int.c72
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c221
-rw-r--r--src/lib/libcrypto/x509v3/v3_pku.c151
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c151
-rw-r--r--src/lib/libcrypto/x509v3/v3_purp.c463
-rw-r--r--src/lib/libcrypto/x509v3/v3_skey.c149
-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.c176
-rw-r--r--src/lib/libcrypto/x509v3/x509v3.h644
-rw-r--r--src/lib/libssl/LICENSE127
-rw-r--r--src/lib/libssl/bio_ssl.c586
-rw-r--r--src/lib/libssl/doc/openssl.cnf244
-rw-r--r--src/lib/libssl/doc/openssl.txt1176
-rw-r--r--src/lib/libssl/s23_clnt.c473
-rw-r--r--src/lib/libssl/s23_lib.c226
-rw-r--r--src/lib/libssl/s23_pkt.c117
-rw-r--r--src/lib/libssl/s23_srvr.c568
-rw-r--r--src/lib/libssl/s3_both.c588
-rw-r--r--src/lib/libssl/s3_clnt.c1730
-rw-r--r--src/lib/libssl/s3_lib.c1339
-rw-r--r--src/lib/libssl/s3_pkt.c1194
-rw-r--r--src/lib/libssl/s3_srvr.c1740
-rw-r--r--src/lib/libssl/shlib_version2
-rw-r--r--src/lib/libssl/ssl.h1533
-rw-r--r--src/lib/libssl/ssl2.h265
-rw-r--r--src/lib/libssl/ssl23.h83
-rw-r--r--src/lib/libssl/ssl3.h426
-rw-r--r--src/lib/libssl/ssl_algs.c103
-rw-r--r--src/lib/libssl/ssl_asn1.c349
-rw-r--r--src/lib/libssl/ssl_cert.c753
-rw-r--r--src/lib/libssl/ssl_ciph.c1069
-rw-r--r--src/lib/libssl/ssl_err.c430
-rw-r--r--src/lib/libssl/ssl_err2.c70
-rw-r--r--src/lib/libssl/ssl_lib.c2061
-rw-r--r--src/lib/libssl/ssl_locl.h555
-rw-r--r--src/lib/libssl/ssl_rsa.c815
-rw-r--r--src/lib/libssl/ssl_sess.c680
-rw-r--r--src/lib/libssl/ssl_stat.c454
-rw-r--r--src/lib/libssl/ssl_txt.c176
-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.c149
-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/testgen32
-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/testssl81
-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
517 files changed, 0 insertions, 120289 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
deleted file mode 100644
index c77456b315..0000000000
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ /dev/null
@@ -1,231 +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
63ASN1_BIT_STRING *ASN1_BIT_STRING_new(void)
64{ return M_ASN1_BIT_STRING_new(); }
65
66void ASN1_BIT_STRING_free(ASN1_BIT_STRING *x)
67{ M_ASN1_BIT_STRING_free(x); }
68
69int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
70{ return M_ASN1_BIT_STRING_set(x, d, len); }
71
72int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
73 {
74 int ret,j,r,bits,len;
75 unsigned char *p,*d;
76
77 if (a == NULL) return(0);
78
79 len=a->length;
80
81 if (len > 0)
82 {
83 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT)
84 {
85 bits=(int)a->flags&0x07;
86 }
87 else
88 {
89 for ( ; len > 0; len--)
90 {
91 if (a->data[len-1]) break;
92 }
93 j=a->data[len-1];
94 if (j & 0x01) bits=0;
95 else if (j & 0x02) bits=1;
96 else if (j & 0x04) bits=2;
97 else if (j & 0x08) bits=3;
98 else if (j & 0x10) bits=4;
99 else if (j & 0x20) bits=5;
100 else if (j & 0x40) bits=6;
101 else if (j & 0x80) bits=7;
102 else bits=0; /* should not happen */
103 }
104 }
105 else
106 bits=0;
107 ret=1+len;
108 r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING);
109 if (pp == NULL) return(r);
110 p= *pp;
111
112 ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL);
113 *(p++)=(unsigned char)bits;
114 d=a->data;
115 memcpy(p,d,len);
116 p+=len;
117 if (len > 0) p[-1]&=(0xff<<bits);
118 *pp=p;
119 return(r);
120 }
121
122ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
123 long length)
124 {
125 ASN1_BIT_STRING *ret=NULL;
126 unsigned char *p,*s;
127 long len;
128 int inf,tag,xclass;
129 int i;
130
131 if ((a == NULL) || ((*a) == NULL))
132 {
133 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
134 }
135 else
136 ret=(*a);
137
138 p= *pp;
139 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
140 if (inf & 0x80)
141 {
142 i=ASN1_R_BAD_OBJECT_HEADER;
143 goto err;
144 }
145
146 if (tag != V_ASN1_BIT_STRING)
147 {
148 i=ASN1_R_EXPECTING_A_BIT_STRING;
149 goto err;
150 }
151 if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; }
152
153 i= *(p++);
154 /* We do this to preserve the settings. If we modify
155 * the settings, via the _set_bit function, we will recalculate
156 * on output */
157 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
158 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
159
160 if (len-- > 1) /* using one because of the bits left byte */
161 {
162 s=(unsigned char *)Malloc((int)len);
163 if (s == NULL)
164 {
165 i=ERR_R_MALLOC_FAILURE;
166 goto err;
167 }
168 memcpy(s,p,(int)len);
169 s[len-1]&=(0xff<<i);
170 p+=len;
171 }
172 else
173 s=NULL;
174
175 ret->length=(int)len;
176 if (ret->data != NULL) Free(ret->data);
177 ret->data=s;
178 ret->type=V_ASN1_BIT_STRING;
179 if (a != NULL) (*a)=ret;
180 *pp=p;
181 return(ret);
182err:
183 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
184 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
185 M_ASN1_BIT_STRING_free(ret);
186 return(NULL);
187 }
188
189/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
190 */
191int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
192 {
193 int w,v,iv;
194 unsigned char *c;
195
196 w=n/8;
197 v=1<<(7-(n&0x07));
198 iv= ~v;
199
200 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
201
202 if (a == NULL) return(0);
203 if ((a->length < (w+1)) || (a->data == NULL))
204 {
205 if (!value) return(1); /* Don't need to set */
206 if (a->data == NULL)
207 c=(unsigned char *)Malloc(w+1);
208 else
209 c=(unsigned char *)Realloc(a->data,w+1);
210 if (c == NULL) return(0);
211 a->data=c;
212 a->length=w+1;
213 c[w]=0;
214 }
215 a->data[w]=((a->data[w])&iv)|v;
216 while ((a->length > 0) && (a->data[a->length-1] == 0))
217 a->length--;
218 return(1);
219 }
220
221int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
222 {
223 int w,v;
224
225 w=n/8;
226 v=1<<(7-(n&0x07));
227 if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL))
228 return(0);
229 return((a->data[w]&v) != 0);
230 }
231
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 8cde695804..0000000000
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ /dev/null
@@ -1,323 +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_primitive(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(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_primitive(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(ret->data);
222 s=(unsigned char *)Malloc((int)len + 1);
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 s[len] = '\0';
233 p+=len;
234 }
235 else
236 {
237 s=NULL;
238 if (ret->data != NULL) Free(ret->data);
239 }
240
241 ret->length=(int)len;
242 ret->data=s;
243 ret->type=Ptag;
244 }
245
246 if (a != NULL) (*a)=ret;
247 *pp=p;
248 return(ret);
249err:
250 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
251 ASN1_STRING_free(ret);
252 ASN1err(ASN1_F_D2I_ASN1_BYTES,i);
253 return(NULL);
254 }
255
256
257/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
258 * them into the one structure that is then returned */
259/* There have been a few bug fixes for this function from
260 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
261static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c)
262 {
263 ASN1_STRING *os=NULL;
264 BUF_MEM b;
265 int num;
266
267 b.length=0;
268 b.max=0;
269 b.data=NULL;
270
271 if (a == NULL)
272 {
273 c->error=ERR_R_PASSED_NULL_PARAMETER;
274 goto err;
275 }
276
277 num=0;
278 for (;;)
279 {
280 if (c->inf & 1)
281 {
282 c->eos=ASN1_check_infinite_end(&c->p,
283 (long)(c->max-c->p));
284 if (c->eos) break;
285 }
286 else
287 {
288 if (c->slen <= 0) break;
289 }
290
291 c->q=c->p;
292 if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass)
293 == NULL)
294 {
295 c->error=ERR_R_ASN1_LIB;
296 goto err;
297 }
298
299 if (!BUF_MEM_grow(&b,num+os->length))
300 {
301 c->error=ERR_R_BUF_LIB;
302 goto err;
303 }
304 memcpy(&(b.data[num]),os->data,os->length);
305 if (!(c->inf & 1))
306 c->slen-=(c->p-c->q);
307 num+=os->length;
308 }
309
310 if (!asn1_Finish(c)) goto err;
311
312 a->length=num;
313 if (a->data != NULL) Free(a->data);
314 a->data=(unsigned char *)b.data;
315 if (os != NULL) ASN1_STRING_free(os);
316 return(1);
317err:
318 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
319 if (os != NULL) ASN1_STRING_free(os);
320 if (b.data != NULL) Free(b.data);
321 return(0);
322 }
323
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 3370aae998..0000000000
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ /dev/null
@@ -1,90 +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
62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
68#include <openssl/evp.h>
69#include <openssl/buffer.h>
70#include <openssl/x509.h>
71
72int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
73 unsigned char *md, unsigned int *len)
74 {
75 EVP_MD_CTX ctx;
76 int i;
77 unsigned char *str,*p;
78
79 i=i2d(data,NULL);
80 if ((str=(unsigned char *)Malloc(i)) == NULL) return(0);
81 p=str;
82 i2d(data,&p);
83
84 EVP_DigestInit(&ctx,type);
85 EVP_DigestUpdate(&ctx,str,i);
86 EVP_DigestFinal(&ctx,md,len);
87 Free(str);
88 return(1);
89 }
90
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
deleted file mode 100644
index 3202a816d0..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(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 ccf62e5a04..0000000000
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ /dev/null
@@ -1,337 +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
68ASN1_ENUMERATED *ASN1_ENUMERATED_new(void)
69{ return M_ASN1_ENUMERATED_new(); }
70
71void ASN1_ENUMERATED_free(ASN1_ENUMERATED *x)
72{ M_ASN1_ENUMERATED_free(x); }
73
74int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
75 {
76 int pad=0,ret,r,i,t;
77 unsigned char *p,*n,pb=0;
78
79 if ((a == NULL) || (a->data == NULL)) return(0);
80 t=a->type;
81 if (a->length == 0)
82 ret=1;
83 else
84 {
85 ret=a->length;
86 i=a->data[0];
87 if ((t == V_ASN1_ENUMERATED) && (i > 127)) {
88 pad=1;
89 pb=0;
90 } else if(t == V_ASN1_NEG_ENUMERATED) {
91 if(i>128) {
92 pad=1;
93 pb=0xFF;
94 } else if(i == 128) {
95 for(i = 1; i < a->length; i++) if(a->data[i]) {
96 pad=1;
97 pb=0xFF;
98 break;
99 }
100 }
101 }
102 ret+=pad;
103 }
104 r=ASN1_object_size(0,ret,V_ASN1_ENUMERATED);
105 if (pp == NULL) return(r);
106 p= *pp;
107
108 ASN1_put_object(&p,0,ret,V_ASN1_ENUMERATED,V_ASN1_UNIVERSAL);
109 if (pad) *(p++)=pb;
110 if (a->length == 0)
111 *(p++)=0;
112 else if (t == V_ASN1_ENUMERATED)
113 {
114 memcpy(p,a->data,(unsigned int)a->length);
115 p+=a->length;
116 }
117 else {
118 /* Begin at the end of the encoding */
119 n=a->data + a->length - 1;
120 p += a->length - 1;
121 i = a->length;
122 /* Copy zeros to destination as long as source is zero */
123 while(!*n) {
124 *(p--) = 0;
125 n--;
126 i--;
127 }
128 /* Complement and increment next octet */
129 *(p--) = ((*(n--)) ^ 0xff) + 1;
130 i--;
131 /* Complement any octets left */
132 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
133 p += a->length;
134 }
135
136 *pp=p;
137 return(r);
138 }
139
140ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
141 long length)
142 {
143 ASN1_ENUMERATED *ret=NULL;
144 unsigned char *p,*to,*s;
145 long len;
146 int inf,tag,xclass;
147 int i;
148
149 if ((a == NULL) || ((*a) == NULL))
150 {
151 if ((ret=M_ASN1_ENUMERATED_new()) == NULL) return(NULL);
152 ret->type=V_ASN1_ENUMERATED;
153 }
154 else
155 ret=(*a);
156
157 p= *pp;
158 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
159 if (inf & 0x80)
160 {
161 i=ASN1_R_BAD_OBJECT_HEADER;
162 goto err;
163 }
164
165 if (tag != V_ASN1_ENUMERATED)
166 {
167 i=ASN1_R_EXPECTING_AN_ENUMERATED;
168 goto err;
169 }
170
171 /* We must Malloc stuff, even for 0 bytes otherwise it
172 * signifies a missing NULL parameter. */
173 s=(unsigned char *)Malloc((int)len+1);
174 if (s == NULL)
175 {
176 i=ERR_R_MALLOC_FAILURE;
177 goto err;
178 }
179 to=s;
180 if(!len) {
181 /* Strictly speaking this is an illegal ENUMERATED but we
182 * tolerate it.
183 */
184 ret->type=V_ASN1_ENUMERATED;
185 } else if (*p & 0x80) /* a negative number */
186 {
187 ret->type=V_ASN1_NEG_ENUMERATED;
188 if ((*p == 0xff) && (len != 1)) {
189 p++;
190 len--;
191 }
192 i = len;
193 p += i - 1;
194 to += i - 1;
195 while((!*p) && i) {
196 *(to--) = 0;
197 i--;
198 p--;
199 }
200 if(!i) {
201 *s = 1;
202 s[len] = 0;
203 p += len;
204 len++;
205 } else {
206 *(to--) = (*(p--) ^ 0xff) + 1;
207 i--;
208 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
209 p += len;
210 }
211 } else {
212 ret->type=V_ASN1_ENUMERATED;
213 if ((*p == 0) && (len != 1))
214 {
215 p++;
216 len--;
217 }
218 memcpy(s,p,(int)len);
219 p+=len;
220 }
221
222 if (ret->data != NULL) Free(ret->data);
223 ret->data=s;
224 ret->length=(int)len;
225 if (a != NULL) (*a)=ret;
226 *pp=p;
227 return(ret);
228err:
229 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
230 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
231 M_ASN1_ENUMERATED_free(ret);
232 return(NULL);
233 }
234
235int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
236 {
237 int i,j,k;
238 unsigned char buf[sizeof(long)+1];
239 long d;
240
241 a->type=V_ASN1_ENUMERATED;
242 if (a->length < (sizeof(long)+1))
243 {
244 if (a->data != NULL)
245 Free(a->data);
246 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
247 memset((char *)a->data,0,sizeof(long)+1);
248 }
249 if (a->data == NULL)
250 {
251 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
252 return(0);
253 }
254 d=v;
255 if (d < 0)
256 {
257 d= -d;
258 a->type=V_ASN1_NEG_ENUMERATED;
259 }
260
261 for (i=0; i<sizeof(long); i++)
262 {
263 if (d == 0) break;
264 buf[i]=(int)d&0xff;
265 d>>=8;
266 }
267 j=0;
268 for (k=i-1; k >=0; k--)
269 a->data[j++]=buf[k];
270 a->length=j;
271 return(1);
272 }
273
274long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
275 {
276 int neg=0,i;
277 long r=0;
278
279 if (a == NULL) return(0L);
280 i=a->type;
281 if (i == V_ASN1_NEG_ENUMERATED)
282 neg=1;
283 else if (i != V_ASN1_ENUMERATED)
284 return(0);
285
286 if (a->length > sizeof(long))
287 {
288 /* hmm... a bit ugly */
289 return(0xffffffffL);
290 }
291 if (a->data == NULL)
292 return(0);
293
294 for (i=0; i<a->length; i++)
295 {
296 r<<=8;
297 r|=(unsigned char)a->data[i];
298 }
299 if (neg) r= -r;
300 return(r);
301 }
302
303ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
304 {
305 ASN1_ENUMERATED *ret;
306 int len,j;
307
308 if (ai == NULL)
309 ret=M_ASN1_ENUMERATED_new();
310 else
311 ret=ai;
312 if (ret == NULL)
313 {
314 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
315 goto err;
316 }
317 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
318 else ret->type=V_ASN1_ENUMERATED;
319 j=BN_num_bits(bn);
320 len=((j == 0)?0:((j/8)+1));
321 ret->data=(unsigned char *)Malloc(len+4);
322 ret->length=BN_bn2bin(bn,ret->data);
323 return(ret);
324err:
325 if (ret != ai) M_ASN1_ENUMERATED_free(ret);
326 return(NULL);
327 }
328
329BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
330 {
331 BIGNUM *ret;
332
333 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
334 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
335 if(ai->type == V_ASN1_NEG_ENUMERATED) bn->neg = 1;
336 return(ret);
337 }
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 d9b8035e17..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(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 8b6794e8c1..0000000000
--- a/src/lib/libcrypto/asn1/a_int.c
+++ /dev/null
@@ -1,435 +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
63ASN1_INTEGER *ASN1_INTEGER_new(void)
64{ return M_ASN1_INTEGER_new();}
65
66void ASN1_INTEGER_free(ASN1_INTEGER *x)
67{ M_ASN1_INTEGER_free(x);}
68
69ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x)
70{ return M_ASN1_INTEGER_dup(x);}
71
72int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y)
73{ return M_ASN1_INTEGER_cmp(x,y);}
74
75/*
76 * This converts an ASN1 INTEGER into its DER encoding.
77 * The internal representation is an ASN1_STRING whose data is a big endian
78 * representation of the value, ignoring the sign. The sign is determined by
79 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
80 *
81 * Positive integers are no problem: they are almost the same as the DER
82 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
83 *
84 * Negative integers are a bit trickier...
85 * The DER representation of negative integers is in 2s complement form.
86 * The internal form is converted by complementing each octet and finally
87 * adding one to the result. This can be done less messily with a little trick.
88 * If the internal form has trailing zeroes then they will become FF by the
89 * complement and 0 by the add one (due to carry) so just copy as many trailing
90 * zeros to the destination as there are in the source. The carry will add one
91 * to the last none zero octet: so complement this octet and add one and finally
92 * complement any left over until you get to the start of the string.
93 *
94 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad
95 * with 0xff. However if the first byte is 0x80 and one of the following bytes
96 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80
97 * followed by optional zeros isn't padded.
98 */
99
100int i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
101 {
102 int pad=0,ret,r,i,t;
103 unsigned char *p,*n,pb=0;
104
105 if ((a == NULL) || (a->data == NULL)) return(0);
106 t=a->type;
107 if (a->length == 0)
108 ret=1;
109 else
110 {
111 ret=a->length;
112 i=a->data[0];
113 if ((t == V_ASN1_INTEGER) && (i > 127)) {
114 pad=1;
115 pb=0;
116 } else if(t == V_ASN1_NEG_INTEGER) {
117 if(i>128) {
118 pad=1;
119 pb=0xFF;
120 } else if(i == 128) {
121 /*
122 * Special case: if any other bytes non zero we pad:
123 * otherwise we don't.
124 */
125 for(i = 1; i < a->length; i++) if(a->data[i]) {
126 pad=1;
127 pb=0xFF;
128 break;
129 }
130 }
131 }
132 ret+=pad;
133 }
134 r=ASN1_object_size(0,ret,V_ASN1_INTEGER);
135 if (pp == NULL) return(r);
136 p= *pp;
137
138 ASN1_put_object(&p,0,ret,V_ASN1_INTEGER,V_ASN1_UNIVERSAL);
139 if (pad) *(p++)=pb;
140 if (a->length == 0) *(p++)=0;
141 else if (t == V_ASN1_INTEGER) memcpy(p,a->data,(unsigned int)a->length);
142 else {
143 /* Begin at the end of the encoding */
144 n=a->data + a->length - 1;
145 p += a->length - 1;
146 i = a->length;
147 /* Copy zeros to destination as long as source is zero */
148 while(!*n) {
149 *(p--) = 0;
150 n--;
151 i--;
152 }
153 /* Complement and increment next octet */
154 *(p--) = ((*(n--)) ^ 0xff) + 1;
155 i--;
156 /* Complement any octets left */
157 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
158 }
159
160 *pp+=r;
161 return(r);
162 }
163
164ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
165 long length)
166 {
167 ASN1_INTEGER *ret=NULL;
168 unsigned char *p,*to,*s, *pend;
169 long len;
170 int inf,tag,xclass;
171 int i;
172
173 if ((a == NULL) || ((*a) == NULL))
174 {
175 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
176 ret->type=V_ASN1_INTEGER;
177 }
178 else
179 ret=(*a);
180
181 p= *pp;
182 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
183 pend = p + len;
184 if (inf & 0x80)
185 {
186 i=ASN1_R_BAD_OBJECT_HEADER;
187 goto err;
188 }
189
190 if (tag != V_ASN1_INTEGER)
191 {
192 i=ASN1_R_EXPECTING_AN_INTEGER;
193 goto err;
194 }
195
196 /* We must Malloc stuff, even for 0 bytes otherwise it
197 * signifies a missing NULL parameter. */
198 s=(unsigned char *)Malloc((int)len+1);
199 if (s == NULL)
200 {
201 i=ERR_R_MALLOC_FAILURE;
202 goto err;
203 }
204 to=s;
205 if(!len) {
206 /* Strictly speaking this is an illegal INTEGER but we
207 * tolerate it.
208 */
209 ret->type=V_ASN1_INTEGER;
210 } else if (*p & 0x80) /* a negative number */
211 {
212 ret->type=V_ASN1_NEG_INTEGER;
213 if ((*p == 0xff) && (len != 1)) {
214 p++;
215 len--;
216 }
217 i = len;
218 p += i - 1;
219 to += i - 1;
220 while((!*p) && i) {
221 *(to--) = 0;
222 i--;
223 p--;
224 }
225 /* Special case: if all zeros then the number will be of
226 * the form FF followed by n zero bytes: this corresponds to
227 * 1 followed by n zero bytes. We've already written n zeros
228 * so we just append an extra one and set the first byte to
229 * a 1. This is treated separately because it is the only case
230 * where the number of bytes is larger than len.
231 */
232 if(!i) {
233 *s = 1;
234 s[len] = 0;
235 len++;
236 } else {
237 *(to--) = (*(p--) ^ 0xff) + 1;
238 i--;
239 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
240 }
241 } else {
242 ret->type=V_ASN1_INTEGER;
243 if ((*p == 0) && (len != 1))
244 {
245 p++;
246 len--;
247 }
248 memcpy(s,p,(int)len);
249 }
250
251 if (ret->data != NULL) Free(ret->data);
252 ret->data=s;
253 ret->length=(int)len;
254 if (a != NULL) (*a)=ret;
255 *pp=pend;
256 return(ret);
257err:
258 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
259 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
260 M_ASN1_INTEGER_free(ret);
261 return(NULL);
262 }
263
264/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of
265 * ASN1 integers: some broken software can encode a positive INTEGER
266 * with its MSB set as negative (it doesn't add a padding zero).
267 */
268
269ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
270 long length)
271 {
272 ASN1_INTEGER *ret=NULL;
273 unsigned char *p,*to,*s;
274 long len;
275 int inf,tag,xclass;
276 int i;
277
278 if ((a == NULL) || ((*a) == NULL))
279 {
280 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
281 ret->type=V_ASN1_INTEGER;
282 }
283 else
284 ret=(*a);
285
286 p= *pp;
287 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
288 if (inf & 0x80)
289 {
290 i=ASN1_R_BAD_OBJECT_HEADER;
291 goto err;
292 }
293
294 if (tag != V_ASN1_INTEGER)
295 {
296 i=ASN1_R_EXPECTING_AN_INTEGER;
297 goto err;
298 }
299
300 /* We must Malloc stuff, even for 0 bytes otherwise it
301 * signifies a missing NULL parameter. */
302 s=(unsigned char *)Malloc((int)len+1);
303 if (s == NULL)
304 {
305 i=ERR_R_MALLOC_FAILURE;
306 goto err;
307 }
308 to=s;
309 ret->type=V_ASN1_INTEGER;
310 if(len) {
311 if ((*p == 0) && (len != 1))
312 {
313 p++;
314 len--;
315 }
316 memcpy(s,p,(int)len);
317 p+=len;
318 }
319
320 if (ret->data != NULL) Free(ret->data);
321 ret->data=s;
322 ret->length=(int)len;
323 if (a != NULL) (*a)=ret;
324 *pp=p;
325 return(ret);
326err:
327 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
328 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
329 M_ASN1_INTEGER_free(ret);
330 return(NULL);
331 }
332
333int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
334 {
335 int i,j,k;
336 unsigned char buf[sizeof(long)+1];
337 long d;
338
339 a->type=V_ASN1_INTEGER;
340 if (a->length < (sizeof(long)+1))
341 {
342 if (a->data != NULL)
343 Free(a->data);
344 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
345 memset((char *)a->data,0,sizeof(long)+1);
346 }
347 if (a->data == NULL)
348 {
349 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
350 return(0);
351 }
352 d=v;
353 if (d < 0)
354 {
355 d= -d;
356 a->type=V_ASN1_NEG_INTEGER;
357 }
358
359 for (i=0; i<sizeof(long); i++)
360 {
361 if (d == 0) break;
362 buf[i]=(int)d&0xff;
363 d>>=8;
364 }
365 j=0;
366 for (k=i-1; k >=0; k--)
367 a->data[j++]=buf[k];
368 a->length=j;
369 return(1);
370 }
371
372long ASN1_INTEGER_get(ASN1_INTEGER *a)
373 {
374 int neg=0,i;
375 long r=0;
376
377 if (a == NULL) return(0L);
378 i=a->type;
379 if (i == V_ASN1_NEG_INTEGER)
380 neg=1;
381 else if (i != V_ASN1_INTEGER)
382 return(0);
383
384 if (a->length > sizeof(long))
385 {
386 /* hmm... a bit ugly */
387 return(0xffffffffL);
388 }
389 if (a->data == NULL)
390 return(0);
391
392 for (i=0; i<a->length; i++)
393 {
394 r<<=8;
395 r|=(unsigned char)a->data[i];
396 }
397 if (neg) r= -r;
398 return(r);
399 }
400
401ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
402 {
403 ASN1_INTEGER *ret;
404 int len,j;
405
406 if (ai == NULL)
407 ret=M_ASN1_INTEGER_new();
408 else
409 ret=ai;
410 if (ret == NULL)
411 {
412 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
413 goto err;
414 }
415 if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
416 else ret->type=V_ASN1_INTEGER;
417 j=BN_num_bits(bn);
418 len=((j == 0)?0:((j/8)+1));
419 ret->data=(unsigned char *)Malloc(len+4);
420 ret->length=BN_bn2bin(bn,ret->data);
421 return(ret);
422err:
423 if (ret != ai) M_ASN1_INTEGER_free(ret);
424 return(NULL);
425 }
426
427BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
428 {
429 BIGNUM *ret;
430
431 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
432 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
433 if(ai->type == V_ASN1_NEG_INTEGER) bn->neg = 1;
434 return(ret);
435 }
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
deleted file mode 100644
index 7a710d5459..0000000000
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ /dev/null
@@ -1,390 +0,0 @@
1/* a_mbstr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63
64static int traverse_string(const unsigned char *p, int len, int inform,
65 int (*rfunc)(unsigned long value, void *in), void *arg);
66static int in_utf8(unsigned long value, void *arg);
67static int out_utf8(unsigned long value, void *arg);
68static int type_str(unsigned long value, void *arg);
69static int cpy_asc(unsigned long value, void *arg);
70static int cpy_bmp(unsigned long value, void *arg);
71static int cpy_univ(unsigned long value, void *arg);
72static int cpy_utf8(unsigned long value, void *arg);
73static int is_printable(unsigned long value);
74
75/* These functions take a string in UTF8, ASCII or multibyte form and
76 * a mask of permissible ASN1 string types. It then works out the minimal
77 * type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8)
78 * and creates a string of the correct type with the supplied data.
79 * Yes this is horrible: it has to be :-(
80 * The 'ncopy' form checks minimum and maximum size limits too.
81 */
82
83int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
84 int inform, unsigned long mask)
85{
86 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
87}
88
89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
90 int inform, unsigned long mask,
91 long minsize, long maxsize)
92{
93 int str_type;
94 int ret;
95 int outform, outlen;
96 ASN1_STRING *dest;
97 unsigned char *p;
98 int nchar;
99 char strbuf[32];
100 int (*cpyfunc)(unsigned long,void *) = NULL;
101 if(len == -1) len = strlen((const char *)in);
102 if(!mask) mask = DIRSTRING_TYPE;
103
104 /* First do a string check and work out the number of characters */
105 switch(inform) {
106
107 case MBSTRING_BMP:
108 if(len & 1) {
109 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
110 ASN1_R_INVALID_BMPSTRING_LENGTH);
111 return -1;
112 }
113 nchar = len >> 1;
114 break;
115
116 case MBSTRING_UNIV:
117 if(len & 3) {
118 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
119 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
120 return -1;
121 }
122 nchar = len >> 2;
123 break;
124
125 case MBSTRING_UTF8:
126 nchar = 0;
127 /* This counts the characters and does utf8 syntax checking */
128 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
129 if(ret < 0) {
130 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
131 ASN1_R_INVALID_UTF8STRING);
132 return -1;
133 }
134 break;
135
136 case MBSTRING_ASC:
137 nchar = len;
138 break;
139
140 default:
141 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT);
142 return -1;
143 }
144
145 if((minsize > 0) && (nchar < minsize)) {
146 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT);
147 sprintf(strbuf, "%ld", minsize);
148 ERR_add_error_data(2, "minsize=", strbuf);
149 return -1;
150 }
151
152 if((maxsize > 0) && (nchar > maxsize)) {
153 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG);
154 sprintf(strbuf, "%ld", maxsize);
155 ERR_add_error_data(2, "maxsize=", strbuf);
156 return -1;
157 }
158
159 /* Now work out minimal type (if any) */
160 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
161 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS);
162 return -1;
163 }
164
165
166 /* Now work out output format and string type */
167 outform = MBSTRING_ASC;
168 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
169 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
170 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
171 else if(mask & B_ASN1_BMPSTRING) {
172 str_type = V_ASN1_BMPSTRING;
173 outform = MBSTRING_BMP;
174 } else if(mask & B_ASN1_UNIVERSALSTRING) {
175 str_type = V_ASN1_UNIVERSALSTRING;
176 outform = MBSTRING_UNIV;
177 } else {
178 str_type = V_ASN1_UTF8STRING;
179 outform = MBSTRING_UTF8;
180 }
181 if(!out) return str_type;
182 if(*out) {
183 dest = *out;
184 if(dest->data) {
185 dest->length = 0;
186 Free(dest->data);
187 dest->data = NULL;
188 }
189 dest->type = str_type;
190 } else {
191 dest = ASN1_STRING_type_new(str_type);
192 if(!dest) {
193 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
194 ERR_R_MALLOC_FAILURE);
195 return -1;
196 }
197 *out = dest;
198 }
199 /* If both the same type just copy across */
200 if(inform == outform) {
201 if(!ASN1_STRING_set(dest, in, len)) {
202 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
203 return -1;
204 }
205 return str_type;
206 }
207
208 /* Work out how much space the destination will need */
209 switch(outform) {
210 case MBSTRING_ASC:
211 outlen = nchar;
212 cpyfunc = cpy_asc;
213 break;
214
215 case MBSTRING_BMP:
216 outlen = nchar << 1;
217 cpyfunc = cpy_bmp;
218 break;
219
220 case MBSTRING_UNIV:
221 outlen = nchar << 2;
222 cpyfunc = cpy_univ;
223 break;
224
225 case MBSTRING_UTF8:
226 outlen = 0;
227 traverse_string(in, len, inform, out_utf8, &outlen);
228 cpyfunc = cpy_utf8;
229 break;
230 }
231 if(!(p = Malloc(outlen + 1))) {
232 ASN1_STRING_free(dest);
233 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
234 return -1;
235 }
236 dest->length = outlen;
237 dest->data = p;
238 p[outlen] = 0;
239 traverse_string(in, len, inform, cpyfunc, &p);
240 return str_type;
241}
242
243/* This function traverses a string and passes the value of each character
244 * to an optional function along with a void * argument.
245 */
246
247static int traverse_string(const unsigned char *p, int len, int inform,
248 int (*rfunc)(unsigned long value, void *in), void *arg)
249{
250 unsigned long value;
251 int ret;
252 while(len) {
253 if(inform == MBSTRING_ASC) {
254 value = *p++;
255 len--;
256 } else if(inform == MBSTRING_BMP) {
257 value = *p++ << 8;
258 value |= *p++;
259 len -= 2;
260 } else if(inform == MBSTRING_UNIV) {
261 value = *p++ << 24;
262 value |= *p++ << 16;
263 value |= *p++ << 8;
264 value |= *p++;
265 len -= 4;
266 } else {
267 ret = UTF8_getc(p, len, &value);
268 if(ret < 0) return -1;
269 len -= ret;
270 p += ret;
271 }
272 if(rfunc) {
273 ret = rfunc(value, arg);
274 if(ret <= 0) return ret;
275 }
276 }
277 return 1;
278}
279
280/* Various utility functions for traverse_string */
281
282/* Just count number of characters */
283
284static int in_utf8(unsigned long value, void *arg)
285{
286 int *nchar;
287 nchar = arg;
288 (*nchar)++;
289 return 1;
290}
291
292/* Determine size of output as a UTF8 String */
293
294static int out_utf8(unsigned long value, void *arg)
295{
296 long *outlen;
297 outlen = arg;
298 *outlen += UTF8_putc(NULL, -1, value);
299 return 1;
300}
301
302/* Determine the "type" of a string: check each character against a
303 * supplied "mask".
304 */
305
306static int type_str(unsigned long value, void *arg)
307{
308 unsigned long types;
309 types = *((unsigned long *)arg);
310 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
311 types &= ~B_ASN1_PRINTABLESTRING;
312 if((types & B_ASN1_IA5STRING) && (value > 127))
313 types &= ~B_ASN1_IA5STRING;
314 if((types & B_ASN1_T61STRING) && (value > 0xff))
315 types &= ~B_ASN1_T61STRING;
316 if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
317 types &= ~B_ASN1_BMPSTRING;
318 if(!types) return -1;
319 *((unsigned long *)arg) = types;
320 return 1;
321}
322
323/* Copy one byte per character ASCII like strings */
324
325static int cpy_asc(unsigned long value, void *arg)
326{
327 unsigned char **p, *q;
328 p = arg;
329 q = *p;
330 *q = (unsigned char) value;
331 (*p)++;
332 return 1;
333}
334
335/* Copy two byte per character BMPStrings */
336
337static int cpy_bmp(unsigned long value, void *arg)
338{
339 unsigned char **p, *q;
340 p = arg;
341 q = *p;
342 *q++ = (unsigned char) ((value >> 8) & 0xff);
343 *q = (unsigned char) (value & 0xff);
344 *p += 2;
345 return 1;
346}
347
348/* Copy four byte per character UniversalStrings */
349
350static int cpy_univ(unsigned long value, void *arg)
351{
352 unsigned char **p, *q;
353 p = arg;
354 q = *p;
355 *q++ = (unsigned char) ((value >> 24) & 0xff);
356 *q++ = (unsigned char) ((value >> 16) & 0xff);
357 *q++ = (unsigned char) ((value >> 8) & 0xff);
358 *q = (unsigned char) (value & 0xff);
359 *p += 4;
360 return 1;
361}
362
363/* Copy to a UTF8String */
364
365static int cpy_utf8(unsigned long value, void *arg)
366{
367 unsigned char **p;
368 int ret;
369 p = arg;
370 /* We already know there is enough room so pass 0xff as the length */
371 ret = UTF8_putc(*p, 0xff, value);
372 *p += ret;
373 return 1;
374}
375
376/* Return 1 if the character is permitted in a PrintableString */
377static int is_printable(unsigned long value)
378{
379 int ch;
380 if(value > 0x7f) return 0;
381 ch = (int) value;
382 /* Note: we can't use 'isalnum' because certain accented
383 * characters may count as alphanumeric in some environments.
384 */
385 if((ch >= 'a') && (ch <= 'z')) return 1;
386 if((ch >= 'A') && (ch <= 'Z')) return 1;
387 if((ch >= '0') && (ch <= '9')) return 1;
388 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
389 return 0;
390}
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
deleted file mode 100644
index 09d56fb669..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(ret->data);
226 ret->data=(unsigned char *)Malloc(len ? (int)len : 1);
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 memory 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 2586f4327d..0000000000
--- a/src/lib/libcrypto/asn1/a_octet.c
+++ /dev/null
@@ -1,95 +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
63ASN1_OCTET_STRING *ASN1_OCTET_STRING_new(void)
64{ return M_ASN1_OCTET_STRING_new(); }
65
66void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *x)
67{ M_ASN1_OCTET_STRING_free(x); }
68
69ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x)
70{ return M_ASN1_OCTET_STRING_dup(x); }
71
72int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b)
73{ return M_ASN1_OCTET_STRING_cmp(a, b); }
74
75int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len)
76{ return M_ASN1_OCTET_STRING_set(x, d, len); }
77
78int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)
79{ return M_i2d_ASN1_OCTET_STRING(a, pp); }
80
81ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
82 unsigned char **pp, long length)
83 {
84 ASN1_OCTET_STRING *ret=NULL;
85
86 ret=(ASN1_OCTET_STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
87 pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL);
88 if (ret == NULL)
89 {
90 ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ERR_R_NESTED_ASN1_ERROR);
91 return(NULL);
92 }
93 return(ret);
94 }
95
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c
deleted file mode 100644
index b7bd2bd18a..0000000000
--- a/src/lib/libcrypto/asn1/a_print.c
+++ /dev/null
@@ -1,197 +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
63ASN1_IA5STRING *ASN1_IA5STRING_new(void)
64{ return M_ASN1_IA5STRING_new();}
65
66void ASN1_IA5STRING_free(ASN1_IA5STRING *x)
67{ M_ASN1_IA5STRING_free(x);}
68
69int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **pp)
70 { return(M_i2d_ASN1_IA5STRING(a,pp)); }
71
72ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, unsigned char **pp,
73 long l)
74 { return(M_d2i_ASN1_IA5STRING(a,pp,l)); }
75
76ASN1_T61STRING *ASN1_T61STRING_new(void)
77{ return M_ASN1_T61STRING_new();}
78
79void ASN1_T61STRING_free(ASN1_T61STRING *x)
80{ M_ASN1_T61STRING_free(x);}
81
82ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, unsigned char **pp,
83 long l)
84 { return(M_d2i_ASN1_T61STRING(a,pp,l)); }
85
86ASN1_PRINTABLESTRING *ASN1_PRINTABLESTRING_new(void)
87{ return M_ASN1_PRINTABLESTRING_new();}
88
89void ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *x)
90{ M_ASN1_PRINTABLESTRING_free(x);}
91
92ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
93 unsigned char **pp, long l)
94 { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,
95 l)); }
96
97int i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **pp)
98 { return(M_i2d_ASN1_PRINTABLESTRING(a,pp)); }
99
100int i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **pp)
101 { return(M_i2d_ASN1_PRINTABLE(a,pp)); }
102
103ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, unsigned char **pp,
104 long l)
105 { return(M_d2i_ASN1_PRINTABLE(a,pp,l)); }
106
107int ASN1_PRINTABLE_type(unsigned char *s, int len)
108 {
109 int c;
110 int ia5=0;
111 int t61=0;
112
113 if (len <= 0) len= -1;
114 if (s == NULL) return(V_ASN1_PRINTABLESTRING);
115
116 while ((*s) && (len-- != 0))
117 {
118 c= *(s++);
119#ifndef CHARSET_EBCDIC
120 if (!( ((c >= 'a') && (c <= 'z')) ||
121 ((c >= 'A') && (c <= 'Z')) ||
122 (c == ' ') ||
123 ((c >= '0') && (c <= '9')) ||
124 (c == ' ') || (c == '\'') ||
125 (c == '(') || (c == ')') ||
126 (c == '+') || (c == ',') ||
127 (c == '-') || (c == '.') ||
128 (c == '/') || (c == ':') ||
129 (c == '=') || (c == '?')))
130 ia5=1;
131 if (c&0x80)
132 t61=1;
133#else
134 if (!isalnum(c) && (c != ' ') &&
135 strchr("'()+,-./:=?", c) == NULL)
136 ia5=1;
137 if (os_toascii[c] & 0x80)
138 t61=1;
139#endif
140 }
141 if (t61) return(V_ASN1_T61STRING);
142 if (ia5) return(V_ASN1_IA5STRING);
143 return(V_ASN1_PRINTABLESTRING);
144 }
145
146int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
147 {
148 int i;
149 unsigned char *p;
150
151 if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
152 if ((s->length%4) != 0) return(0);
153 p=s->data;
154 for (i=0; i<s->length; i+=4)
155 {
156 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
157 break;
158 else
159 p+=4;
160 }
161 if (i < s->length) return(0);
162 p=s->data;
163 for (i=3; i<s->length; i+=4)
164 {
165 *(p++)=s->data[i];
166 }
167 *(p)='\0';
168 s->length/=4;
169 s->type=ASN1_PRINTABLE_type(s->data,s->length);
170 return(1);
171 }
172
173ASN1_STRING *DIRECTORYSTRING_new(void)
174{ return M_DIRECTORYSTRING_new();}
175
176void DIRECTORYSTRING_free(ASN1_STRING *x)
177{ M_DIRECTORYSTRING_free(x);}
178
179int i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **pp)
180 { return(M_i2d_DIRECTORYSTRING(a,pp)); }
181
182ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
183 long l)
184 { return(M_d2i_DIRECTORYSTRING(a,pp,l)); }
185
186ASN1_STRING *DISPLAYTEXT_new(void)
187{ return M_DISPLAYTEXT_new();}
188
189void DISPLAYTEXT_free(ASN1_STRING *x)
190{ M_DISPLAYTEXT_free(x);}
191
192int i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **pp)
193 { return(M_i2d_DISPLAYTEXT(a,pp)); }
194
195ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp,
196 long l)
197 { 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 cfb4bca4f1..0000000000
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ /dev/null
@@ -1,148 +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
62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
68#include <openssl/bn.h>
69#include <openssl/evp.h>
70#include <openssl/x509.h>
71#include <openssl/objects.h>
72#include <openssl/buffer.h>
73
74int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
75 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
76 const EVP_MD *type)
77 {
78 EVP_MD_CTX ctx;
79 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
80 int i,inl=0,outl=0,outll=0;
81 X509_ALGOR *a;
82
83 for (i=0; i<2; i++)
84 {
85 if (i == 0)
86 a=algor1;
87 else
88 a=algor2;
89 if (a == NULL) continue;
90 if ( (a->parameter == NULL) ||
91 (a->parameter->type != V_ASN1_NULL))
92 {
93 ASN1_TYPE_free(a->parameter);
94 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
95 a->parameter->type=V_ASN1_NULL;
96 }
97 ASN1_OBJECT_free(a->algorithm);
98 a->algorithm=OBJ_nid2obj(type->pkey_type);
99 if (a->algorithm == NULL)
100 {
101 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
102 goto err;
103 }
104 if (a->algorithm->length == 0)
105 {
106 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
107 goto err;
108 }
109 }
110 inl=i2d(data,NULL);
111 buf_in=(unsigned char *)Malloc((unsigned int)inl);
112 outll=outl=EVP_PKEY_size(pkey);
113 buf_out=(unsigned char *)Malloc((unsigned int)outl);
114 if ((buf_in == NULL) || (buf_out == NULL))
115 {
116 outl=0;
117 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
118 goto err;
119 }
120 p=buf_in;
121
122 i2d(data,&p);
123 EVP_SignInit(&ctx,type);
124 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
125 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
126 (unsigned int *)&outl,pkey))
127 {
128 outl=0;
129 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
130 goto err;
131 }
132 if (signature->data != NULL) Free(signature->data);
133 signature->data=buf_out;
134 buf_out=NULL;
135 signature->length=outl;
136 /* In the interests of compatibility, I'll make sure that
137 * the bit string has a 'not-used bits' value of 0
138 */
139 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
140 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
141err:
142 memset(&ctx,0,sizeof(ctx));
143 if (buf_in != NULL)
144 { memset((char *)buf_in,0,(unsigned int)inl); Free(buf_in); }
145 if (buf_out != NULL)
146 { memset((char *)buf_out,0,outll); Free(buf_out); }
147 return(outl);
148 }
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
deleted file mode 100644
index ab8417ffab..0000000000
--- a/src/lib/libcrypto/asn1/a_strnid.c
+++ /dev/null
@@ -1,247 +0,0 @@
1/* a_strnid.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64
65
66static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
67static void st_free(ASN1_STRING_TABLE *tbl);
68static int sk_table_cmp(ASN1_STRING_TABLE **a, ASN1_STRING_TABLE **b);
69static int table_cmp(ASN1_STRING_TABLE *a, ASN1_STRING_TABLE *b);
70
71
72/* This is the global mask for the mbstring functions: this is use to
73 * mask out certain types (such as BMPString and UTF8String) because
74 * certain software (e.g. Netscape) has problems with them.
75 */
76
77static unsigned long global_mask = 0xFFFFFFFFL;
78
79void ASN1_STRING_set_default_mask(unsigned long mask)
80{
81 global_mask = mask;
82}
83
84unsigned long ASN1_STRING_get_default_mask(void)
85{
86 return global_mask;
87}
88
89/* This function sets the default to various "flavours" of configuration.
90 * based on an ASCII string. Currently this is:
91 * MASK:XXXX : a numerical mask value.
92 * nobmp : Don't use BMPStrings (just Printable, T61).
93 * pkix : PKIX recommendation in RFC2459.
94 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
95 * default: the default value, Printable, T61, BMP.
96 */
97
98int ASN1_STRING_set_default_mask_asc(char *p)
99{
100 unsigned long mask;
101 char *end;
102 if(!strncmp(p, "MASK:", 5)) {
103 if(!p[5]) return 0;
104 mask = strtoul(p + 5, &end, 0);
105 if(*end) return 0;
106 } else if(!strcmp(p, "nombstr"))
107 mask = ~(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING);
108 else if(!strcmp(p, "pkix"))
109 mask = ~B_ASN1_T61STRING;
110 else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING;
111 else if(!strcmp(p, "default"))
112 mask = 0xFFFFFFFFL;
113 else return 0;
114 ASN1_STRING_set_default_mask(mask);
115 return 1;
116}
117
118/* The following function generates an ASN1_STRING based on limits in a table.
119 * Frequently the types and length of an ASN1_STRING are restricted by a
120 * corresponding OID. For example certificates and certificate requests.
121 */
122
123ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
124 int inlen, int inform, int nid)
125{
126 ASN1_STRING_TABLE *tbl;
127 ASN1_STRING *str = NULL;
128 unsigned long mask;
129 int ret;
130 if(!out) out = &str;
131 tbl = ASN1_STRING_TABLE_get(nid);
132 if(tbl) {
133 mask = tbl->mask;
134 if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask;
135 ret = ASN1_mbstring_ncopy(out, in, inlen, inform, tbl->mask,
136 tbl->minsize, tbl->maxsize);
137 } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask);
138 if(ret <= 0) return NULL;
139 return *out;
140}
141
142/* Now the tables and helper functions for the string table:
143 */
144
145/* size limits: this stuff is taken straight from RFC2459 */
146
147#define ub_name 32768
148#define ub_common_name 64
149#define ub_locality_name 128
150#define ub_state_name 128
151#define ub_organization_name 64
152#define ub_organization_unit_name 64
153#define ub_title 64
154#define ub_email_address 128
155
156/* This table must be kept in NID order */
157
158static ASN1_STRING_TABLE tbl_standard[] = {
159{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
160{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
161{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
162{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
163{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
164{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0},
165{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK},
166{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
167{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
168{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
169{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
170{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
171{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
172{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
173{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}
174};
175
176static int sk_table_cmp(ASN1_STRING_TABLE **a, ASN1_STRING_TABLE **b)
177{
178 return (*a)->nid - (*b)->nid;
179}
180
181static int table_cmp(ASN1_STRING_TABLE *a, ASN1_STRING_TABLE *b)
182{
183 return a->nid - b->nid;
184}
185
186ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
187{
188 int idx;
189 ASN1_STRING_TABLE *ttmp;
190 ASN1_STRING_TABLE fnd;
191 fnd.nid = nid;
192 ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
193 (char *)tbl_standard,
194 sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
195 sizeof(ASN1_STRING_TABLE), (int(*)())table_cmp);
196 if(ttmp) return ttmp;
197 if(!stable) return NULL;
198 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
199 if(idx < 0) return NULL;
200 return sk_ASN1_STRING_TABLE_value(stable, idx);
201}
202
203int ASN1_STRING_TABLE_add(int nid,
204 long minsize, long maxsize, unsigned long mask,
205 unsigned long flags)
206{
207 ASN1_STRING_TABLE *tmp;
208 char new_nid = 0;
209 flags &= ~STABLE_FLAGS_MALLOC;
210 if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
211 if(!stable) {
212 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
213 return 0;
214 }
215 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
216 tmp = Malloc(sizeof(ASN1_STRING_TABLE));
217 if(!tmp) {
218 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
219 ERR_R_MALLOC_FAILURE);
220 return 0;
221 }
222 tmp->flags = flags | STABLE_FLAGS_MALLOC;
223 tmp->nid = nid;
224 new_nid = 1;
225 } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
226 if(minsize != -1) tmp->minsize = minsize;
227 if(maxsize != -1) tmp->maxsize = maxsize;
228 tmp->mask = mask;
229 if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp);
230 return 1;
231}
232
233void ASN1_STRING_TABLE_cleanup(void)
234{
235 STACK_OF(ASN1_STRING_TABLE) *tmp;
236 tmp = stable;
237 if(!tmp) return;
238 stable = NULL;
239 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
240}
241
242static void st_free(ASN1_STRING_TABLE *tbl)
243{
244 if(tbl->flags & STABLE_FLAGS_MALLOC) Free(tbl);
245}
246
247IMPLEMENT_STACK_OF(ASN1_STRING_TABLE)
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
deleted file mode 100644
index b193f1c71f..0000000000
--- a/src/lib/libcrypto/asn1/a_time.c
+++ /dev/null
@@ -1,129 +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
69ASN1_TIME *ASN1_TIME_new(void)
70{ return M_ASN1_TIME_new(); }
71
72void ASN1_TIME_free(ASN1_TIME *x)
73{ M_ASN1_TIME_free(x); }
74
75int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
76 {
77#ifdef CHARSET_EBCDIC
78 /* KLUDGE! We convert to ascii before writing DER */
79 char tmp[24];
80 ASN1_STRING tmpstr;
81
82 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
83 int len;
84
85 tmpstr = *(ASN1_STRING *)a;
86 len = tmpstr.length;
87 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
88 tmpstr.data = tmp;
89 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
90 }
91#endif
92 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
93 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
94 a->type ,V_ASN1_UNIVERSAL));
95 ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
96 return -1;
97 }
98
99
100ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **a, unsigned char **pp, long length)
101 {
102 unsigned char tag;
103 tag = **pp & ~V_ASN1_CONSTRUCTED;
104 if(tag == (V_ASN1_UTCTIME|V_ASN1_UNIVERSAL))
105 return d2i_ASN1_UTCTIME(a, pp, length);
106 if(tag == (V_ASN1_GENERALIZEDTIME|V_ASN1_UNIVERSAL))
107 return d2i_ASN1_GENERALIZEDTIME(a, pp, length);
108 ASN1err(ASN1_F_D2I_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
109 return(NULL);
110 }
111
112
113ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
114 {
115 struct tm *ts;
116#if defined(THREADS) && !defined(WIN32)
117 struct tm data;
118#endif
119
120#if defined(THREADS) && !defined(WIN32)
121 gmtime_r(&t,&data);
122 ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */
123#else
124 ts=gmtime(&t);
125#endif
126 if((ts->tm_year >= 50) && (ts->tm_year < 150))
127 return ASN1_UTCTIME_set(s, t);
128 return ASN1_GENERALIZEDTIME_set(s,t);
129 }
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
deleted file mode 100644
index 161ef81197..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(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 b5125af224..0000000000
--- a/src/lib/libcrypto/asn1/a_utf8.c
+++ /dev/null
@@ -1,238 +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
63ASN1_UTF8STRING *ASN1_UTF8STRING_new(void)
64{ return M_ASN1_UTF8STRING_new();}
65
66void ASN1_UTF8STRING_free(ASN1_UTF8STRING *x)
67{ M_ASN1_UTF8STRING_free(x);}
68
69int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **pp)
70 {
71 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
72 V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL));
73 }
74
75ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, unsigned char **pp,
76 long length)
77 {
78 ASN1_UTF8STRING *ret=NULL;
79
80 ret=(ASN1_UTF8STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
81 pp,length,V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL);
82 if (ret == NULL)
83 {
84 ASN1err(ASN1_F_D2I_ASN1_UTF8STRING,ERR_R_NESTED_ASN1_ERROR);
85 return(NULL);
86 }
87 return(ret);
88 }
89
90
91/* UTF8 utilities */
92
93/* This parses a UTF8 string one character at a time. It is passed a pointer
94 * to the string and the length of the string. It sets 'value' to the value of
95 * the current character. It returns the number of characters read or a
96 * negative error code:
97 * -1 = string too short
98 * -2 = illegal character
99 * -3 = subsequent characters not of the form 10xxxxxx
100 * -4 = character encoded incorrectly (not minimal length).
101 */
102
103int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
104{
105 const unsigned char *p;
106 unsigned long value;
107 int ret;
108 if(len <= 0) return 0;
109 p = str;
110
111 /* Check syntax and work out the encoded value (if correct) */
112 if((*p & 0x80) == 0) {
113 value = *p++ & 0x7f;
114 ret = 1;
115 } else if((*p & 0xe0) == 0xc0) {
116 if(len < 2) return -1;
117 if((p[1] & 0xc0) != 0x80) return -3;
118 value = (*p++ & 0x1f) << 6;
119 value |= *p++ & 0x3f;
120 if(value < 0x80) return -4;
121 ret = 2;
122 } else if((*p & 0xf0) == 0xe0) {
123 if(len < 3) return -1;
124 if( ((p[1] & 0xc0) != 0x80)
125 || ((p[2] & 0xc0) != 0x80) ) return -3;
126 value = (*p++ & 0xf) << 12;
127 value |= (*p++ & 0x3f) << 6;
128 value |= *p++ & 0x3f;
129 if(value < 0x800) return -4;
130 ret = 3;
131 } else if((*p & 0xf8) == 0xf0) {
132 if(len < 4) return -1;
133 if( ((p[1] & 0xc0) != 0x80)
134 || ((p[2] & 0xc0) != 0x80)
135 || ((p[3] & 0xc0) != 0x80) ) return -3;
136 value = (*p++ & 0x7) << 18;
137 value |= (*p++ & 0x3f) << 12;
138 value |= (*p++ & 0x3f) << 6;
139 value |= *p++ & 0x3f;
140 if(value < 0x10000) return -4;
141 ret = 4;
142 } else if((*p & 0xfc) == 0xf8) {
143 if(len < 5) return -1;
144 if( ((p[1] & 0xc0) != 0x80)
145 || ((p[2] & 0xc0) != 0x80)
146 || ((p[3] & 0xc0) != 0x80)
147 || ((p[4] & 0xc0) != 0x80) ) return -3;
148 value = (*p++ & 0x3) << 24;
149 value |= (*p++ & 0x3f) << 18;
150 value |= (*p++ & 0x3f) << 12;
151 value |= (*p++ & 0x3f) << 6;
152 value |= *p++ & 0x3f;
153 if(value < 0x200000) return -4;
154 ret = 5;
155 } else if((*p & 0xfe) == 0xfc) {
156 if(len < 6) return -1;
157 if( ((p[1] & 0xc0) != 0x80)
158 || ((p[2] & 0xc0) != 0x80)
159 || ((p[3] & 0xc0) != 0x80)
160 || ((p[4] & 0xc0) != 0x80)
161 || ((p[5] & 0xc0) != 0x80) ) return -3;
162 value = (*p++ & 0x1) << 30;
163 value |= (*p++ & 0x3f) << 24;
164 value |= (*p++ & 0x3f) << 18;
165 value |= (*p++ & 0x3f) << 12;
166 value |= (*p++ & 0x3f) << 6;
167 value |= *p++ & 0x3f;
168 if(value < 0x4000000) return -4;
169 ret = 6;
170 } else return -2;
171 *val = value;
172 return ret;
173}
174
175/* This takes a character 'value' and writes the UTF8 encoded value in
176 * 'str' where 'str' is a buffer containing 'len' characters. Returns
177 * the number of characters written or -1 if 'len' is too small. 'str' can
178 * be set to NULL in which case it just returns the number of characters.
179 * It will need at most 6 characters.
180 */
181
182int UTF8_putc(unsigned char *str, int len, unsigned long value)
183{
184 if(!str) len = 6; /* Maximum we will need */
185 else if(len <= 0) return -1;
186 if(value < 0x80) {
187 if(str) *str = (unsigned char)value;
188 return 1;
189 }
190 if(value < 0x800) {
191 if(len < 2) return -1;
192 if(str) {
193 *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0);
194 *str = (unsigned char)((value & 0x3f) | 0x80);
195 }
196 return 2;
197 }
198 if(value < 0x10000) {
199 if(len < 3) return -1;
200 if(str) {
201 *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0);
202 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
203 *str = (unsigned char)((value & 0x3f) | 0x80);
204 }
205 return 3;
206 }
207 if(value < 0x200000) {
208 if(len < 4) return -1;
209 if(str) {
210 *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0);
211 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
212 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
213 *str = (unsigned char)((value & 0x3f) | 0x80);
214 }
215 return 4;
216 }
217 if(value < 0x4000000) {
218 if(len < 5) return -1;
219 if(str) {
220 *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8);
221 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
222 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
223 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
224 *str = (unsigned char)((value & 0x3f) | 0x80);
225 }
226 return 5;
227 }
228 if(len < 6) return -1;
229 if(str) {
230 *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc);
231 *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80);
232 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
233 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
234 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
235 *str = (unsigned char)((value & 0x3f) | 0x80);
236 }
237 return 6;
238}
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
deleted file mode 100644
index d4aede85c3..0000000000
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ /dev/null
@@ -1,119 +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
62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
68#include <openssl/bn.h>
69#include <openssl/x509.h>
70#include <openssl/objects.h>
71#include <openssl/buffer.h>
72#include <openssl/evp.h>
73
74int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
75 char *data, EVP_PKEY *pkey)
76 {
77 EVP_MD_CTX ctx;
78 const EVP_MD *type;
79 unsigned char *p,*buf_in=NULL;
80 int ret= -1,i,inl;
81
82 i=OBJ_obj2nid(a->algorithm);
83 type=EVP_get_digestbyname(OBJ_nid2sn(i));
84 if (type == NULL)
85 {
86 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
87 goto err;
88 }
89
90 inl=i2d(data,NULL);
91 buf_in=Malloc((unsigned int)inl);
92 if (buf_in == NULL)
93 {
94 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
95 goto err;
96 }
97 p=buf_in;
98
99 i2d(data,&p);
100 EVP_VerifyInit(&ctx,type);
101 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
102
103 memset(buf_in,0,(unsigned int)inl);
104 Free(buf_in);
105
106 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
107 (unsigned int)signature->length,pkey) <= 0)
108 {
109 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
110 ret=0;
111 goto err;
112 }
113 /* we don't need to zero the 'ctx' because we just checked
114 * public information */
115 /* memset(&ctx,0,sizeof(ctx)); */
116 ret=1;
117err:
118 return(ret);
119 }
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
deleted file mode 100644
index 99bd64a11e..0000000000
--- a/src/lib/libcrypto/asn1/asn1.h
+++ /dev/null
@@ -1,1067 +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#ifdef VMS
72#include <openssl/vms_idhacks.h>
73#endif
74
75#define V_ASN1_UNIVERSAL 0x00
76#define V_ASN1_APPLICATION 0x40
77#define V_ASN1_CONTEXT_SPECIFIC 0x80
78#define V_ASN1_PRIVATE 0xc0
79
80#define V_ASN1_CONSTRUCTED 0x20
81#define V_ASN1_PRIMITIVE_TAG 0x1f
82#define V_ASN1_PRIMATIVE_TAG 0x1f
83
84#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
85
86#define V_ASN1_UNDEF -1
87#define V_ASN1_EOC 0
88#define V_ASN1_BOOLEAN 1 /**/
89#define V_ASN1_INTEGER 2
90#define V_ASN1_NEG_INTEGER (2+0x100)
91#define V_ASN1_BIT_STRING 3
92#define V_ASN1_OCTET_STRING 4
93#define V_ASN1_NULL 5
94#define V_ASN1_OBJECT 6
95#define V_ASN1_OBJECT_DESCRIPTOR 7
96#define V_ASN1_EXTERNAL 8
97#define V_ASN1_REAL 9
98#define V_ASN1_ENUMERATED 10
99#define V_ASN1_NEG_ENUMERATED (10+0x100)
100#define V_ASN1_UTF8STRING 12
101#define V_ASN1_SEQUENCE 16
102#define V_ASN1_SET 17
103#define V_ASN1_NUMERICSTRING 18 /**/
104#define V_ASN1_PRINTABLESTRING 19
105#define V_ASN1_T61STRING 20
106#define V_ASN1_TELETEXSTRING 20 /* alias */
107#define V_ASN1_VIDEOTEXSTRING 21 /**/
108#define V_ASN1_IA5STRING 22
109#define V_ASN1_UTCTIME 23
110#define V_ASN1_GENERALIZEDTIME 24 /**/
111#define V_ASN1_GRAPHICSTRING 25 /**/
112#define V_ASN1_ISO64STRING 26 /**/
113#define V_ASN1_VISIBLESTRING 26 /* alias */
114#define V_ASN1_GENERALSTRING 27 /**/
115#define V_ASN1_UNIVERSALSTRING 28 /**/
116#define V_ASN1_BMPSTRING 30
117
118/* For use with d2i_ASN1_type_bytes() */
119#define B_ASN1_NUMERICSTRING 0x0001
120#define B_ASN1_PRINTABLESTRING 0x0002
121#define B_ASN1_T61STRING 0x0004
122#define B_ASN1_TELETEXSTRING 0x0008
123#define B_ASN1_VIDEOTEXSTRING 0x0008
124#define B_ASN1_IA5STRING 0x0010
125#define B_ASN1_GRAPHICSTRING 0x0020
126#define B_ASN1_ISO64STRING 0x0040
127#define B_ASN1_VISIBLESTRING 0x0040
128#define B_ASN1_GENERALSTRING 0x0080
129#define B_ASN1_UNIVERSALSTRING 0x0100
130#define B_ASN1_OCTET_STRING 0x0200
131#define B_ASN1_BIT_STRING 0x0400
132#define B_ASN1_BMPSTRING 0x0800
133#define B_ASN1_UNKNOWN 0x1000
134#define B_ASN1_UTF8STRING 0x2000
135
136/* For use with ASN1_mbstring_copy() */
137#define MBSTRING_FLAG 0x1000
138#define MBSTRING_ASC (MBSTRING_FLAG|1)
139#define MBSTRING_BMP (MBSTRING_FLAG|2)
140#define MBSTRING_UNIV (MBSTRING_FLAG|3)
141#define MBSTRING_UTF8 (MBSTRING_FLAG|4)
142
143#define DECLARE_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); \
147STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
148 long length, \
149 type *(*func)(type **, \
150 unsigned char **,long), \
151 void (*free_func)(type *), \
152 int ex_tag,int ex_class);
153
154#define IMPLEMENT_ASN1_SET_OF(type) \
155int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
156 int (*func)(type *,unsigned char **), int ex_tag, \
157 int ex_class, int is_set) \
158 { return i2d_ASN1_SET((STACK *)a,pp,func,ex_tag,ex_class,is_set); } \
159STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
160 long length, \
161 type *(*func)(type **, \
162 unsigned char **,long), \
163 void (*free_func)(type *), \
164 int ex_tag,int ex_class) \
165 { return (STACK_OF(type) *)d2i_ASN1_SET((STACK **)a,pp,length, \
166 (char *(*)())func, \
167 (void (*)())free_func, \
168 ex_tag,ex_class); }
169
170typedef struct asn1_ctx_st
171 {
172 unsigned char *p;/* work char pointer */
173 int eos; /* end of sequence read for indefinite encoding */
174 int error; /* error code to use when returning an error */
175 int inf; /* constructed if 0x20, indefinite is 0x21 */
176 int tag; /* tag from last 'get object' */
177 int xclass; /* class from last 'get object' */
178 long slen; /* length of last 'get object' */
179 unsigned char *max; /* largest value of p allowed */
180 unsigned char *q;/* temporary variable */
181 unsigned char **pp;/* variable */
182 int line; /* used in error processing */
183 } ASN1_CTX;
184
185/* These are used internally in the ASN1_OBJECT to keep track of
186 * whether the names and data need to be free()ed */
187#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
188#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
189#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
190#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
191typedef struct asn1_object_st
192 {
193 const char *sn,*ln;
194 int nid;
195 int length;
196 unsigned char *data;
197 int flags; /* Should we free this one */
198 } ASN1_OBJECT;
199
200#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
201/* This is the base type that holds just about everything :-) */
202typedef struct asn1_string_st
203 {
204 int length;
205 int type;
206 unsigned char *data;
207 /* The value of the following field depends on the type being
208 * held. It is mostly being used for BIT_STRING so if the
209 * input data has a non-zero 'unused bits' value, it will be
210 * handled correctly */
211 long flags;
212 } ASN1_STRING;
213
214#define STABLE_FLAGS_MALLOC 0x01
215#define STABLE_NO_MASK 0x02
216#define DIRSTRING_TYPE \
217 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
218#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
219
220typedef struct asn1_string_table_st {
221 int nid;
222 long minsize;
223 long maxsize;
224 unsigned long mask;
225 unsigned long flags;
226} ASN1_STRING_TABLE;
227
228DECLARE_STACK_OF(ASN1_STRING_TABLE)
229
230/* size limits: this stuff is taken straight from RFC2459 */
231
232#define ub_name 32768
233#define ub_common_name 64
234#define ub_locality_name 128
235#define ub_state_name 128
236#define ub_organization_name 64
237#define ub_organization_unit_name 64
238#define ub_title 64
239#define ub_email_address 128
240
241#ifdef NO_ASN1_TYPEDEFS
242#define ASN1_INTEGER ASN1_STRING
243#define ASN1_ENUMERATED ASN1_STRING
244#define ASN1_BIT_STRING ASN1_STRING
245#define ASN1_OCTET_STRING ASN1_STRING
246#define ASN1_PRINTABLESTRING ASN1_STRING
247#define ASN1_T61STRING ASN1_STRING
248#define ASN1_IA5STRING ASN1_STRING
249#define ASN1_UTCTIME ASN1_STRING
250#define ASN1_GENERALIZEDTIME ASN1_STRING
251#define ASN1_TIME ASN1_STRING
252#define ASN1_GENERALSTRING ASN1_STRING
253#define ASN1_UNIVERSALSTRING ASN1_STRING
254#define ASN1_BMPSTRING ASN1_STRING
255#define ASN1_VISIBLESTRING ASN1_STRING
256#define ASN1_UTF8STRING ASN1_STRING
257#else
258typedef struct asn1_string_st ASN1_INTEGER;
259typedef struct asn1_string_st ASN1_ENUMERATED;
260typedef struct asn1_string_st ASN1_BIT_STRING;
261typedef struct asn1_string_st ASN1_OCTET_STRING;
262typedef struct asn1_string_st ASN1_PRINTABLESTRING;
263typedef struct asn1_string_st ASN1_T61STRING;
264typedef struct asn1_string_st ASN1_IA5STRING;
265typedef struct asn1_string_st ASN1_GENERALSTRING;
266typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
267typedef struct asn1_string_st ASN1_BMPSTRING;
268typedef struct asn1_string_st ASN1_UTCTIME;
269typedef struct asn1_string_st ASN1_TIME;
270typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
271typedef struct asn1_string_st ASN1_VISIBLESTRING;
272typedef struct asn1_string_st ASN1_UTF8STRING;
273#endif
274
275typedef int ASN1_NULL;
276
277typedef struct asn1_type_st
278 {
279 int type;
280 union {
281 char *ptr;
282 ASN1_STRING * asn1_string;
283 ASN1_OBJECT * object;
284 ASN1_INTEGER * integer;
285 ASN1_ENUMERATED * enumerated;
286 ASN1_BIT_STRING * bit_string;
287 ASN1_OCTET_STRING * octet_string;
288 ASN1_PRINTABLESTRING * printablestring;
289 ASN1_T61STRING * t61string;
290 ASN1_IA5STRING * ia5string;
291 ASN1_GENERALSTRING * generalstring;
292 ASN1_BMPSTRING * bmpstring;
293 ASN1_UNIVERSALSTRING * universalstring;
294 ASN1_UTCTIME * utctime;
295 ASN1_GENERALIZEDTIME * generalizedtime;
296 ASN1_VISIBLESTRING * visiblestring;
297 ASN1_UTF8STRING * utf8string;
298 /* set and sequence are left complete and still
299 * contain the set or sequence bytes */
300 ASN1_STRING * set;
301 ASN1_STRING * sequence;
302 } value;
303 } ASN1_TYPE;
304
305DECLARE_STACK_OF(ASN1_TYPE)
306DECLARE_ASN1_SET_OF(ASN1_TYPE)
307
308typedef struct asn1_method_st
309 {
310 int (*i2d)();
311 char *(*d2i)();
312 char *(*create)();
313 void (*destroy)();
314 } ASN1_METHOD;
315
316/* This is used when parsing some Netscape objects */
317typedef struct asn1_header_st
318 {
319 ASN1_OCTET_STRING *header;
320 char *data;
321 ASN1_METHOD *meth;
322 } ASN1_HEADER;
323
324/* This is used to contain a list of bit names */
325typedef struct BIT_STRING_BITNAME_st {
326 int bitnum;
327 const char *lname;
328 const char *sname;
329} BIT_STRING_BITNAME;
330
331
332#define M_ASN1_STRING_length(x) ((x)->length)
333#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
334#define M_ASN1_STRING_type(x) ((x)->type)
335#define M_ASN1_STRING_data(x) ((x)->data)
336
337/* Macros for string operations */
338#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
339 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
340#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
341#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
342 ASN1_STRING_dup((ASN1_STRING *)a)
343#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
344 (ASN1_STRING *)a,(ASN1_STRING *)b)
345#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
346
347#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
348 ASN1_STRING_type_new(V_ASN1_INTEGER)
349#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
350#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
351#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
352 (ASN1_STRING *)a,(ASN1_STRING *)b)
353
354#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
355 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
356#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
357#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
358#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
359 (ASN1_STRING *)a,(ASN1_STRING *)b)
360
361#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
362 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
363#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
364#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
365 ASN1_STRING_dup((ASN1_STRING *)a)
366#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
367 (ASN1_STRING *)a,(ASN1_STRING *)b)
368#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
369#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
370#define M_i2d_ASN1_OCTET_STRING(a,pp) \
371 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
372 V_ASN1_UNIVERSAL)
373
374#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
375#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
376#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
377 pp,a->type,V_ASN1_UNIVERSAL)
378#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
379 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
380 B_ASN1_PRINTABLESTRING| \
381 B_ASN1_T61STRING| \
382 B_ASN1_IA5STRING| \
383 B_ASN1_BIT_STRING| \
384 B_ASN1_UNIVERSALSTRING|\
385 B_ASN1_BMPSTRING|\
386 B_ASN1_UTF8STRING|\
387 B_ASN1_UNKNOWN)
388
389#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
390#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
391#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
392 pp,a->type,V_ASN1_UNIVERSAL)
393#define M_d2i_DIRECTORYSTRING(a,pp,l) \
394 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
395 B_ASN1_PRINTABLESTRING| \
396 B_ASN1_TELETEXSTRING|\
397 B_ASN1_BMPSTRING|\
398 B_ASN1_UNIVERSALSTRING|\
399 B_ASN1_UTF8STRING)
400
401#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
402#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
403#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
404 pp,a->type,V_ASN1_UNIVERSAL)
405#define M_d2i_DISPLAYTEXT(a,pp,l) \
406 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
407 B_ASN1_VISIBLESTRING| \
408 B_ASN1_BMPSTRING|\
409 B_ASN1_UTF8STRING)
410
411#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
412 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
413#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
414#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
415 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
416 V_ASN1_UNIVERSAL)
417#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
418 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
419 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
420
421#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
422 ASN1_STRING_type_new(V_ASN1_T61STRING)
423#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
424#define M_i2d_ASN1_T61STRING(a,pp) \
425 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
426 V_ASN1_UNIVERSAL)
427#define M_d2i_ASN1_T61STRING(a,pp,l) \
428 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
429 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
430
431#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
432 ASN1_STRING_type_new(V_ASN1_IA5STRING)
433#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
434#define M_ASN1_IA5STRING_dup(a) \
435 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
436#define M_i2d_ASN1_IA5STRING(a,pp) \
437 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
438 V_ASN1_UNIVERSAL)
439#define M_d2i_ASN1_IA5STRING(a,pp,l) \
440 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
441 B_ASN1_IA5STRING)
442
443#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
444 ASN1_STRING_type_new(V_ASN1_UTCTIME)
445#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
446#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
447
448#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
449 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
450#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
451#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
452 (ASN1_STRING *)a)
453
454#define M_ASN1_TIME_new() (ASN1_TIME *)\
455 ASN1_STRING_type_new(V_ASN1_UTCTIME)
456#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
457#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
458
459#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
460 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
461#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
462#define M_i2d_ASN1_GENERALSTRING(a,pp) \
463 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
464 V_ASN1_UNIVERSAL)
465#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
466 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
467 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
468
469#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
470 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
471#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
472#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
473 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
474 V_ASN1_UNIVERSAL)
475#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
476 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
477 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
478
479#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
480 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
481#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
482#define M_i2d_ASN1_BMPSTRING(a,pp) \
483 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
484 V_ASN1_UNIVERSAL)
485#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
486 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
487 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
488
489#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
490 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
491#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
492#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
493 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
494 V_ASN1_UNIVERSAL)
495#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
496 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
497 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
498
499#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
500 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
501#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
502#define M_i2d_ASN1_UTF8STRING(a,pp) \
503 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
504 V_ASN1_UNIVERSAL)
505#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
506 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
507 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
508
509 /* for the is_set parameter to i2d_ASN1_SET */
510#define IS_SEQUENCE 0
511#define IS_SET 1
512
513ASN1_TYPE * ASN1_TYPE_new(void );
514void ASN1_TYPE_free(ASN1_TYPE *a);
515int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);
516ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);
517int ASN1_TYPE_get(ASN1_TYPE *a);
518void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
519
520ASN1_OBJECT * ASN1_OBJECT_new(void );
521void ASN1_OBJECT_free(ASN1_OBJECT *a);
522int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
523ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
524 long length);
525
526DECLARE_STACK_OF(ASN1_OBJECT)
527DECLARE_ASN1_SET_OF(ASN1_OBJECT)
528
529ASN1_STRING * ASN1_STRING_new(void);
530void ASN1_STRING_free(ASN1_STRING *a);
531ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
532ASN1_STRING * ASN1_STRING_type_new(int type );
533int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
534 /* Since this is used to store all sorts of things, via macros, for now, make
535 its data void * */
536int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
537int ASN1_STRING_length(ASN1_STRING *x);
538void ASN1_STRING_length_set(ASN1_STRING *x, int n);
539int ASN1_STRING_type(ASN1_STRING *x);
540unsigned char * ASN1_STRING_data(ASN1_STRING *x);
541
542ASN1_BIT_STRING * ASN1_BIT_STRING_new(void);
543void ASN1_BIT_STRING_free(ASN1_BIT_STRING *a);
544int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
545ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
546 long length);
547int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
548 int length );
549int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
550int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
551
552#ifdef HEADER_BIO_H
553int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
554 BIT_STRING_BITNAME *tbl, int indent);
555#endif
556int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
557int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
558 BIT_STRING_BITNAME *tbl);
559
560int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
561int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
562
563ASN1_INTEGER * ASN1_INTEGER_new(void);
564void ASN1_INTEGER_free(ASN1_INTEGER *a);
565int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
566ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
567 long length);
568ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
569 long length);
570ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
571int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
572
573ASN1_ENUMERATED * ASN1_ENUMERATED_new(void);
574void ASN1_ENUMERATED_free(ASN1_ENUMERATED *a);
575int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp);
576ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp,
577 long length);
578
579int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
580ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
581int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
582
583int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
584ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
585int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
586
587ASN1_OCTET_STRING * ASN1_OCTET_STRING_new(void);
588void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a);
589int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
590ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
591 unsigned char **pp,long length);
592ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
593int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
594int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
595
596ASN1_VISIBLESTRING * ASN1_VISIBLESTRING_new(void);
597void ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *a);
598int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp);
599ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a,
600 unsigned char **pp,long length);
601
602ASN1_UTF8STRING * ASN1_UTF8STRING_new(void);
603void ASN1_UTF8STRING_free(ASN1_UTF8STRING *a);
604int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
605ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
606 unsigned char **pp,long length);
607
608ASN1_NULL * ASN1_NULL_new(void);
609void ASN1_NULL_free(ASN1_NULL *a);
610int i2d_ASN1_NULL(ASN1_NULL *a,unsigned char **pp);
611ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **a, unsigned char **pp,long length);
612
613ASN1_BMPSTRING * ASN1_BMPSTRING_new(void);
614void ASN1_BMPSTRING_free(ASN1_BMPSTRING *a);
615int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
616ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp,
617 long length);
618
619
620int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
621int UTF8_putc(unsigned char *str, int len, unsigned long value);
622
623int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
624ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
625 unsigned char **pp, long l);
626
627ASN1_PRINTABLESTRING * ASN1_PRINTABLESTRING_new(void);
628void ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *a);
629ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
630 unsigned char **pp, long l);
631int i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **pp);
632
633ASN1_STRING * DIRECTORYSTRING_new(void);
634void DIRECTORYSTRING_free(ASN1_STRING *a);
635int i2d_DIRECTORYSTRING(ASN1_STRING *a,unsigned char **pp);
636ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
637 long length);
638
639ASN1_STRING * DISPLAYTEXT_new(void);
640void DISPLAYTEXT_free(ASN1_STRING *a);
641int i2d_DISPLAYTEXT(ASN1_STRING *a,unsigned char **pp);
642ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, long length);
643
644ASN1_T61STRING * ASN1_T61STRING_new(void);
645void ASN1_T61STRING_free(ASN1_IA5STRING *a);
646ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
647 unsigned char **pp, long l);
648
649ASN1_IA5STRING * ASN1_IA5STRING_new(void);
650void ASN1_IA5STRING_free(ASN1_IA5STRING *a);
651int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
652ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a,
653 unsigned char **pp, long l);
654
655ASN1_UTCTIME * ASN1_UTCTIME_new(void);
656void ASN1_UTCTIME_free(ASN1_UTCTIME *a);
657int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
658ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
659 long length);
660
661ASN1_GENERALIZEDTIME * ASN1_GENERALIZEDTIME_new(void);
662void ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *a);
663int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp);
664ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp,
665 long length);
666
667ASN1_TIME * ASN1_TIME_new(void);
668void ASN1_TIME_free(ASN1_TIME *a);
669int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp);
670ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length);
671ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
672
673int i2d_ASN1_SET(STACK *a, unsigned char **pp,
674 int (*func)(), int ex_tag, int ex_class, int is_set);
675STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
676 char *(*func)(), void (*free_func)(),
677 int ex_tag, int ex_class);
678
679#ifdef HEADER_BIO_H
680int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
681int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
682int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
683int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
684int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
685int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
686int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
687#endif
688int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
689
690int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
691ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
692 char *sn, char *ln);
693
694int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
695long ASN1_INTEGER_get(ASN1_INTEGER *a);
696ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
697BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
698
699int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
700long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
701ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
702BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
703
704/* General */
705/* given a string, return the correct type, max is the maximum length */
706int ASN1_PRINTABLE_type(unsigned char *s, int max);
707
708int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
709ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
710 long length, int Ptag, int Pclass);
711/* type is one or more of the B_ASN1_ values. */
712ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
713 long length,int type);
714
715/* PARSING */
716int asn1_Finish(ASN1_CTX *c);
717
718/* SPECIALS */
719int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
720 int *pclass, long omax);
721int ASN1_check_infinite_end(unsigned char **p,long len);
722void ASN1_put_object(unsigned char **pp, int constructed, int length,
723 int tag, int xclass);
724int ASN1_object_size(int constructed, int length, int tag);
725
726/* Used to implement other functions */
727char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
728
729#ifndef NO_FP_API
730char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
731int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
732#endif
733
734#ifdef HEADER_BIO_H
735char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
736int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
737int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
738int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
739int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
740int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
741int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
742#endif
743const char *ASN1_tag2str(int tag);
744
745/* Used to load and write netscape format cert/key */
746int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
747ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
748ASN1_HEADER *ASN1_HEADER_new(void );
749void ASN1_HEADER_free(ASN1_HEADER *a);
750
751int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
752
753void ERR_load_ASN1_strings(void);
754
755/* Not used that much at this point, except for the first two */
756ASN1_METHOD *X509_asn1_meth(void);
757ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
758ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
759ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
760
761int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
762 unsigned char *data, int len);
763int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
764 unsigned char *data, int max_len);
765int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
766 unsigned char *data, int len);
767int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
768 unsigned char *data, int max_len);
769
770STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
771 void (*free_func)() );
772unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
773 int *len );
774void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
775ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
776
777void ASN1_STRING_set_default_mask(unsigned long mask);
778int ASN1_STRING_set_default_mask_asc(char *p);
779unsigned long ASN1_STRING_get_default_mask(void);
780int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
781 int inform, unsigned long mask);
782int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
783 int inform, unsigned long mask,
784 long minsize, long maxsize);
785
786ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
787 const unsigned char *in, int inlen, int inform, int nid);
788ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
789int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
790void ASN1_STRING_TABLE_cleanup(void);
791
792/* BEGIN ERROR CODES */
793/* The following lines are auto generated by the script mkerr.pl. Any changes
794 * made after this point may be overwritten when the script is next run.
795 */
796
797/* Error codes for the ASN1 functions. */
798
799/* Function codes. */
800#define ASN1_F_A2D_ASN1_OBJECT 100
801#define ASN1_F_A2I_ASN1_ENUMERATED 236
802#define ASN1_F_A2I_ASN1_INTEGER 101
803#define ASN1_F_A2I_ASN1_STRING 102
804#define ASN1_F_ACCESS_DESCRIPTION_NEW 291
805#define ASN1_F_ASN1_COLLATE_PRIMITIVE 103
806#define ASN1_F_ASN1_D2I_BIO 104
807#define ASN1_F_ASN1_D2I_FP 105
808#define ASN1_F_ASN1_DUP 106
809#define ASN1_F_ASN1_ENUMERATED_SET 232
810#define ASN1_F_ASN1_ENUMERATED_TO_BN 233
811#define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222
812#define ASN1_F_ASN1_GET_OBJECT 107
813#define ASN1_F_ASN1_HEADER_NEW 108
814#define ASN1_F_ASN1_I2D_BIO 109
815#define ASN1_F_ASN1_I2D_FP 110
816#define ASN1_F_ASN1_INTEGER_SET 111
817#define ASN1_F_ASN1_INTEGER_TO_BN 112
818#define ASN1_F_ASN1_MBSTRING_COPY 282
819#define ASN1_F_ASN1_OBJECT_NEW 113
820#define ASN1_F_ASN1_PACK_STRING 245
821#define ASN1_F_ASN1_PBE_SET 253
822#define ASN1_F_ASN1_SEQ_PACK 246
823#define ASN1_F_ASN1_SEQ_UNPACK 247
824#define ASN1_F_ASN1_SIGN 114
825#define ASN1_F_ASN1_STRING_NEW 115
826#define ASN1_F_ASN1_STRING_TABLE_ADD 283
827#define ASN1_F_ASN1_STRING_TYPE_NEW 116
828#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117
829#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118
830#define ASN1_F_ASN1_TYPE_NEW 119
831#define ASN1_F_ASN1_UNPACK_STRING 248
832#define ASN1_F_ASN1_UTCTIME_NEW 120
833#define ASN1_F_ASN1_VERIFY 121
834#define ASN1_F_AUTHORITY_KEYID_NEW 237
835#define ASN1_F_BASIC_CONSTRAINTS_NEW 226
836#define ASN1_F_BN_TO_ASN1_ENUMERATED 234
837#define ASN1_F_BN_TO_ASN1_INTEGER 122
838#define ASN1_F_D2I_ACCESS_DESCRIPTION 284
839#define ASN1_F_D2I_ASN1_BIT_STRING 123
840#define ASN1_F_D2I_ASN1_BMPSTRING 124
841#define ASN1_F_D2I_ASN1_BOOLEAN 125
842#define ASN1_F_D2I_ASN1_BYTES 126
843#define ASN1_F_D2I_ASN1_ENUMERATED 235
844#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
845#define ASN1_F_D2I_ASN1_HEADER 127
846#define ASN1_F_D2I_ASN1_INTEGER 128
847#define ASN1_F_D2I_ASN1_NULL 292
848#define ASN1_F_D2I_ASN1_OBJECT 129
849#define ASN1_F_D2I_ASN1_OCTET_STRING 130
850#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
851#define ASN1_F_D2I_ASN1_SET 132
852#define ASN1_F_D2I_ASN1_TIME 224
853#define ASN1_F_D2I_ASN1_TYPE 133
854#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
855#define ASN1_F_D2I_ASN1_UINTEGER 280
856#define ASN1_F_D2I_ASN1_UTCTIME 135
857#define ASN1_F_D2I_ASN1_UTF8STRING 266
858#define ASN1_F_D2I_ASN1_VISIBLESTRING 267
859#define ASN1_F_D2I_AUTHORITY_KEYID 238
860#define ASN1_F_D2I_BASIC_CONSTRAINTS 227
861#define ASN1_F_D2I_DHPARAMS 136
862#define ASN1_F_D2I_DIST_POINT 276
863#define ASN1_F_D2I_DIST_POINT_NAME 277
864#define ASN1_F_D2I_DSAPARAMS 137
865#define ASN1_F_D2I_DSAPRIVATEKEY 138
866#define ASN1_F_D2I_DSAPUBLICKEY 139
867#define ASN1_F_D2I_GENERAL_NAME 230
868#define ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE 228
869#define ASN1_F_D2I_NETSCAPE_PKEY 140
870#define ASN1_F_D2I_NETSCAPE_RSA 141
871#define ASN1_F_D2I_NETSCAPE_RSA_2 142
872#define ASN1_F_D2I_NETSCAPE_SPKAC 143
873#define ASN1_F_D2I_NETSCAPE_SPKI 144
874#define ASN1_F_D2I_NOTICEREF 268
875#define ASN1_F_D2I_OTHERNAME 287
876#define ASN1_F_D2I_PBE2PARAM 262
877#define ASN1_F_D2I_PBEPARAM 249
878#define ASN1_F_D2I_PBKDF2PARAM 263
879#define ASN1_F_D2I_PKCS12 254
880#define ASN1_F_D2I_PKCS12_BAGS 255
881#define ASN1_F_D2I_PKCS12_MAC_DATA 256
882#define ASN1_F_D2I_PKCS12_SAFEBAG 257
883#define ASN1_F_D2I_PKCS7 145
884#define ASN1_F_D2I_PKCS7_DIGEST 146
885#define ASN1_F_D2I_PKCS7_ENCRYPT 147
886#define ASN1_F_D2I_PKCS7_ENC_CONTENT 148
887#define ASN1_F_D2I_PKCS7_ENVELOPE 149
888#define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150
889#define ASN1_F_D2I_PKCS7_RECIP_INFO 151
890#define ASN1_F_D2I_PKCS7_SIGNED 152
891#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153
892#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154
893#define ASN1_F_D2I_PKCS8_PRIV_KEY_INFO 250
894#define ASN1_F_D2I_PKEY_USAGE_PERIOD 239
895#define ASN1_F_D2I_POLICYINFO 269
896#define ASN1_F_D2I_POLICYQUALINFO 270
897#define ASN1_F_D2I_PRIVATEKEY 155
898#define ASN1_F_D2I_PUBLICKEY 156
899#define ASN1_F_D2I_RSAPRIVATEKEY 157
900#define ASN1_F_D2I_RSAPUBLICKEY 158
901#define ASN1_F_D2I_SXNET 241
902#define ASN1_F_D2I_SXNETID 243
903#define ASN1_F_D2I_USERNOTICE 271
904#define ASN1_F_D2I_X509 159
905#define ASN1_F_D2I_X509_ALGOR 160
906#define ASN1_F_D2I_X509_ATTRIBUTE 161
907#define ASN1_F_D2I_X509_CERT_AUX 285
908#define ASN1_F_D2I_X509_CINF 162
909#define ASN1_F_D2I_X509_CRL 163
910#define ASN1_F_D2I_X509_CRL_INFO 164
911#define ASN1_F_D2I_X509_EXTENSION 165
912#define ASN1_F_D2I_X509_KEY 166
913#define ASN1_F_D2I_X509_NAME 167
914#define ASN1_F_D2I_X509_NAME_ENTRY 168
915#define ASN1_F_D2I_X509_PKEY 169
916#define ASN1_F_D2I_X509_PUBKEY 170
917#define ASN1_F_D2I_X509_REQ 171
918#define ASN1_F_D2I_X509_REQ_INFO 172
919#define ASN1_F_D2I_X509_REVOKED 173
920#define ASN1_F_D2I_X509_SIG 174
921#define ASN1_F_D2I_X509_VAL 175
922#define ASN1_F_DIST_POINT_NAME_NEW 278
923#define ASN1_F_DIST_POINT_NEW 279
924#define ASN1_F_GENERAL_NAME_NEW 231
925#define ASN1_F_I2D_ASN1_HEADER 176
926#define ASN1_F_I2D_ASN1_TIME 225
927#define ASN1_F_I2D_DHPARAMS 177
928#define ASN1_F_I2D_DSAPARAMS 178
929#define ASN1_F_I2D_DSAPRIVATEKEY 179
930#define ASN1_F_I2D_DSAPUBLICKEY 180
931#define ASN1_F_I2D_DSA_PUBKEY 290
932#define ASN1_F_I2D_NETSCAPE_RSA 181
933#define ASN1_F_I2D_PKCS7 182
934#define ASN1_F_I2D_PRIVATEKEY 183
935#define ASN1_F_I2D_PUBLICKEY 184
936#define ASN1_F_I2D_RSAPRIVATEKEY 185
937#define ASN1_F_I2D_RSAPUBLICKEY 186
938#define ASN1_F_I2D_RSA_PUBKEY 289
939#define ASN1_F_I2D_X509_ATTRIBUTE 187
940#define ASN1_F_I2T_ASN1_OBJECT 188
941#define ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW 229
942#define ASN1_F_NETSCAPE_PKEY_NEW 189
943#define ASN1_F_NETSCAPE_SPKAC_NEW 190
944#define ASN1_F_NETSCAPE_SPKI_NEW 191
945#define ASN1_F_NOTICEREF_NEW 272
946#define ASN1_F_OTHERNAME_NEW 288
947#define ASN1_F_PBE2PARAM_NEW 264
948#define ASN1_F_PBEPARAM_NEW 251
949#define ASN1_F_PBKDF2PARAM_NEW 265
950#define ASN1_F_PKCS12_BAGS_NEW 258
951#define ASN1_F_PKCS12_MAC_DATA_NEW 259
952#define ASN1_F_PKCS12_NEW 260
953#define ASN1_F_PKCS12_SAFEBAG_NEW 261
954#define ASN1_F_PKCS5_PBE2_SET 281
955#define ASN1_F_PKCS7_DIGEST_NEW 192
956#define ASN1_F_PKCS7_ENCRYPT_NEW 193
957#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194
958#define ASN1_F_PKCS7_ENVELOPE_NEW 195
959#define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196
960#define ASN1_F_PKCS7_NEW 197
961#define ASN1_F_PKCS7_RECIP_INFO_NEW 198
962#define ASN1_F_PKCS7_SIGNED_NEW 199
963#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200
964#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201
965#define ASN1_F_PKCS8_PRIV_KEY_INFO_NEW 252
966#define ASN1_F_PKEY_USAGE_PERIOD_NEW 240
967#define ASN1_F_POLICYINFO_NEW 273
968#define ASN1_F_POLICYQUALINFO_NEW 274
969#define ASN1_F_SXNETID_NEW 244
970#define ASN1_F_SXNET_NEW 242
971#define ASN1_F_USERNOTICE_NEW 275
972#define ASN1_F_X509_ALGOR_NEW 202
973#define ASN1_F_X509_ATTRIBUTE_NEW 203
974#define ASN1_F_X509_CERT_AUX_NEW 286
975#define ASN1_F_X509_CINF_NEW 204
976#define ASN1_F_X509_CRL_INFO_NEW 205
977#define ASN1_F_X509_CRL_NEW 206
978#define ASN1_F_X509_DHPARAMS_NEW 207
979#define ASN1_F_X509_EXTENSION_NEW 208
980#define ASN1_F_X509_INFO_NEW 209
981#define ASN1_F_X509_KEY_NEW 210
982#define ASN1_F_X509_NAME_ENTRY_NEW 211
983#define ASN1_F_X509_NAME_NEW 212
984#define ASN1_F_X509_NEW 213
985#define ASN1_F_X509_PKEY_NEW 214
986#define ASN1_F_X509_PUBKEY_NEW 215
987#define ASN1_F_X509_REQ_INFO_NEW 216
988#define ASN1_F_X509_REQ_NEW 217
989#define ASN1_F_X509_REVOKED_NEW 218
990#define ASN1_F_X509_SIG_NEW 219
991#define ASN1_F_X509_VAL_FREE 220
992#define ASN1_F_X509_VAL_NEW 221
993
994/* Reason codes. */
995#define ASN1_R_BAD_CLASS 100
996#define ASN1_R_BAD_OBJECT_HEADER 101
997#define ASN1_R_BAD_PASSWORD_READ 102
998#define ASN1_R_BAD_PKCS7_CONTENT 103
999#define ASN1_R_BAD_PKCS7_TYPE 104
1000#define ASN1_R_BAD_TAG 105
1001#define ASN1_R_BAD_TYPE 106
1002#define ASN1_R_BN_LIB 107
1003#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108
1004#define ASN1_R_BUFFER_TOO_SMALL 109
1005#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 166
1006#define ASN1_R_DATA_IS_WRONG 110
1007#define ASN1_R_DECODE_ERROR 155
1008#define ASN1_R_DECODING_ERROR 111
1009#define ASN1_R_ENCODE_ERROR 156
1010#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112
1011#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 157
1012#define ASN1_R_EXPECTING_AN_ENUMERATED 154
1013#define ASN1_R_EXPECTING_AN_INTEGER 113
1014#define ASN1_R_EXPECTING_AN_OBJECT 114
1015#define ASN1_R_EXPECTING_AN_OCTET_STRING 115
1016#define ASN1_R_EXPECTING_A_BIT_STRING 116
1017#define ASN1_R_EXPECTING_A_BOOLEAN 117
1018#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151
1019#define ASN1_R_EXPECTING_A_NULL 164
1020#define ASN1_R_EXPECTING_A_TIME 152
1021#define ASN1_R_EXPECTING_A_UTCTIME 118
1022#define ASN1_R_FIRST_NUM_TOO_LARGE 119
1023#define ASN1_R_GENERALIZEDTIME_TOO_LONG 153
1024#define ASN1_R_HEADER_TOO_LONG 120
1025#define ASN1_R_ILLEGAL_CHARACTERS 158
1026#define ASN1_R_INVALID_BMPSTRING_LENGTH 159
1027#define ASN1_R_INVALID_DIGIT 121
1028#define ASN1_R_INVALID_SEPARATOR 122
1029#define ASN1_R_INVALID_TIME_FORMAT 123
1030#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 160
1031#define ASN1_R_INVALID_UTF8STRING 161
1032#define ASN1_R_IV_TOO_LARGE 124
1033#define ASN1_R_LENGTH_ERROR 125
1034#define ASN1_R_MISSING_SECOND_NUMBER 126
1035#define ASN1_R_NON_HEX_CHARACTERS 127
1036#define ASN1_R_NOT_ENOUGH_DATA 128
1037#define ASN1_R_NULL_IS_WRONG_LENGTH 165
1038#define ASN1_R_ODD_NUMBER_OF_CHARS 129
1039#define ASN1_R_PARSING 130
1040#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131
1041#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132
1042#define ASN1_R_SHORT_LINE 133
1043#define ASN1_R_STRING_TOO_LONG 163
1044#define ASN1_R_STRING_TOO_SHORT 134
1045#define ASN1_R_TAG_VALUE_TOO_HIGH 135
1046#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136
1047#define ASN1_R_TOO_LONG 137
1048#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138
1049#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139
1050#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140
1051#define ASN1_R_UNKNOWN_FORMAT 162
1052#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141
1053#define ASN1_R_UNKNOWN_OBJECT_TYPE 142
1054#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143
1055#define ASN1_R_UNSUPPORTED_CIPHER 144
1056#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 145
1057#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 146
1058#define ASN1_R_UTCTIME_TOO_LONG 147
1059#define ASN1_R_WRONG_PRINTABLE_TYPE 148
1060#define ASN1_R_WRONG_TAG 149
1061#define ASN1_R_WRONG_TYPE 150
1062
1063#ifdef __cplusplus
1064}
1065#endif
1066#endif
1067
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
deleted file mode 100644
index cecd555c88..0000000000
--- a/src/lib/libcrypto/asn1/asn1_err.c
+++ /dev/null
@@ -1,352 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/asn1.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA ASN1_str_functs[]=
68 {
69{ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"},
70{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"},
71{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"},
72{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"},
73{ERR_PACK(0,ASN1_F_ACCESS_DESCRIPTION_NEW,0), "ACCESS_DESCRIPTION_new"},
74{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"},
75{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
76{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
77{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
78{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
79{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
80{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_new"},
81{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
82{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
83{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
84{ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"},
85{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"},
86{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"},
87{ERR_PACK(0,ASN1_F_ASN1_MBSTRING_COPY,0), "ASN1_mbstring_copy"},
88{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"},
89{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"},
90{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"},
91{ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"},
92{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"},
93{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"},
94{ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"},
95{ERR_PACK(0,ASN1_F_ASN1_STRING_TABLE_ADD,0), "ASN1_STRING_TABLE_add"},
96{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
97{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"},
98{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
99{ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"},
100{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"},
101{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_new"},
102{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"},
103{ERR_PACK(0,ASN1_F_AUTHORITY_KEYID_NEW,0), "AUTHORITY_KEYID_new"},
104{ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_new"},
105{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
106{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
107{ERR_PACK(0,ASN1_F_D2I_ACCESS_DESCRIPTION,0), "d2i_ACCESS_DESCRIPTION"},
108{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"},
109{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"},
110{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
111{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"},
112{ERR_PACK(0,ASN1_F_D2I_ASN1_ENUMERATED,0), "d2i_ASN1_ENUMERATED"},
113{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"},
114{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
115{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"},
116{ERR_PACK(0,ASN1_F_D2I_ASN1_NULL,0), "d2i_ASN1_NULL"},
117{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
118{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"},
119{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"},
120{ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"},
121{ERR_PACK(0,ASN1_F_D2I_ASN1_TIME,0), "d2i_ASN1_TIME"},
122{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"},
123{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"},
124{ERR_PACK(0,ASN1_F_D2I_ASN1_UINTEGER,0), "d2i_ASN1_UINTEGER"},
125{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"},
126{ERR_PACK(0,ASN1_F_D2I_ASN1_UTF8STRING,0), "d2i_ASN1_UTF8STRING"},
127{ERR_PACK(0,ASN1_F_D2I_ASN1_VISIBLESTRING,0), "d2i_ASN1_VISIBLESTRING"},
128{ERR_PACK(0,ASN1_F_D2I_AUTHORITY_KEYID,0), "d2i_AUTHORITY_KEYID"},
129{ERR_PACK(0,ASN1_F_D2I_BASIC_CONSTRAINTS,0), "d2i_BASIC_CONSTRAINTS"},
130{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "d2i_DHparams"},
131{ERR_PACK(0,ASN1_F_D2I_DIST_POINT,0), "d2i_DIST_POINT"},
132{ERR_PACK(0,ASN1_F_D2I_DIST_POINT_NAME,0), "d2i_DIST_POINT_NAME"},
133{ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "d2i_DSAparams"},
134{ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "d2i_DSAPrivateKey"},
135{ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "d2i_DSAPublicKey"},
136{ERR_PACK(0,ASN1_F_D2I_GENERAL_NAME,0), "d2i_GENERAL_NAME"},
137{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE,0), "d2i_NETSCAPE_CERT_SEQUENCE"},
138{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_PKEY,0), "D2I_NETSCAPE_PKEY"},
139{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "d2i_Netscape_RSA"},
140{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "d2i_Netscape_RSA_2"},
141{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "d2i_NETSCAPE_SPKAC"},
142{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "d2i_NETSCAPE_SPKI"},
143{ERR_PACK(0,ASN1_F_D2I_NOTICEREF,0), "d2i_NOTICEREF"},
144{ERR_PACK(0,ASN1_F_D2I_OTHERNAME,0), "d2i_OTHERNAME"},
145{ERR_PACK(0,ASN1_F_D2I_PBE2PARAM,0), "d2i_PBE2PARAM"},
146{ERR_PACK(0,ASN1_F_D2I_PBEPARAM,0), "d2i_PBEPARAM"},
147{ERR_PACK(0,ASN1_F_D2I_PBKDF2PARAM,0), "d2i_PBKDF2PARAM"},
148{ERR_PACK(0,ASN1_F_D2I_PKCS12,0), "d2i_PKCS12"},
149{ERR_PACK(0,ASN1_F_D2I_PKCS12_BAGS,0), "d2i_PKCS12_BAGS"},
150{ERR_PACK(0,ASN1_F_D2I_PKCS12_MAC_DATA,0), "d2i_PKCS12_MAC_DATA"},
151{ERR_PACK(0,ASN1_F_D2I_PKCS12_SAFEBAG,0), "d2i_PKCS12_SAFEBAG"},
152{ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "d2i_PKCS7"},
153{ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "d2i_PKCS7_DIGEST"},
154{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "d2i_PKCS7_ENCRYPT"},
155{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "d2i_PKCS7_ENC_CONTENT"},
156{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "d2i_PKCS7_ENVELOPE"},
157{ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "d2i_PKCS7_ISSUER_AND_SERIAL"},
158{ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "d2i_PKCS7_RECIP_INFO"},
159{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "d2i_PKCS7_SIGNED"},
160{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "d2i_PKCS7_SIGNER_INFO"},
161{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "d2i_PKCS7_SIGN_ENVELOPE"},
162{ERR_PACK(0,ASN1_F_D2I_PKCS8_PRIV_KEY_INFO,0), "d2i_PKCS8_PRIV_KEY_INFO"},
163{ERR_PACK(0,ASN1_F_D2I_PKEY_USAGE_PERIOD,0), "d2i_PKEY_USAGE_PERIOD"},
164{ERR_PACK(0,ASN1_F_D2I_POLICYINFO,0), "d2i_POLICYINFO"},
165{ERR_PACK(0,ASN1_F_D2I_POLICYQUALINFO,0), "d2i_POLICYQUALINFO"},
166{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"},
167{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"},
168{ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "d2i_RSAPrivateKey"},
169{ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "d2i_RSAPublicKey"},
170{ERR_PACK(0,ASN1_F_D2I_SXNET,0), "d2i_SXNET"},
171{ERR_PACK(0,ASN1_F_D2I_SXNETID,0), "d2i_SXNETID"},
172{ERR_PACK(0,ASN1_F_D2I_USERNOTICE,0), "d2i_USERNOTICE"},
173{ERR_PACK(0,ASN1_F_D2I_X509,0), "d2i_X509"},
174{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "d2i_X509_ALGOR"},
175{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "d2i_X509_ATTRIBUTE"},
176{ERR_PACK(0,ASN1_F_D2I_X509_CERT_AUX,0), "d2i_X509_CERT_AUX"},
177{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "d2i_X509_CINF"},
178{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "d2i_X509_CRL"},
179{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "d2i_X509_CRL_INFO"},
180{ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "d2i_X509_EXTENSION"},
181{ERR_PACK(0,ASN1_F_D2I_X509_KEY,0), "D2I_X509_KEY"},
182{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "d2i_X509_NAME"},
183{ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "d2i_X509_NAME_ENTRY"},
184{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"},
185{ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "d2i_X509_PUBKEY"},
186{ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "d2i_X509_REQ"},
187{ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "d2i_X509_REQ_INFO"},
188{ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "d2i_X509_REVOKED"},
189{ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "d2i_X509_SIG"},
190{ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "d2i_X509_VAL"},
191{ERR_PACK(0,ASN1_F_DIST_POINT_NAME_NEW,0), "DIST_POINT_NAME_new"},
192{ERR_PACK(0,ASN1_F_DIST_POINT_NEW,0), "DIST_POINT_new"},
193{ERR_PACK(0,ASN1_F_GENERAL_NAME_NEW,0), "GENERAL_NAME_new"},
194{ERR_PACK(0,ASN1_F_I2D_ASN1_HEADER,0), "i2d_ASN1_HEADER"},
195{ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "i2d_ASN1_TIME"},
196{ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "i2d_DHparams"},
197{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "i2d_DSAparams"},
198{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "i2d_DSAPrivateKey"},
199{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "i2d_DSAPublicKey"},
200{ERR_PACK(0,ASN1_F_I2D_DSA_PUBKEY,0), "i2d_DSA_PUBKEY"},
201{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"},
202{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "i2d_PKCS7"},
203{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"},
204{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"},
205{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "i2d_RSAPrivateKey"},
206{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "i2d_RSAPublicKey"},
207{ERR_PACK(0,ASN1_F_I2D_RSA_PUBKEY,0), "i2d_RSA_PUBKEY"},
208{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "i2d_X509_ATTRIBUTE"},
209{ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"},
210{ERR_PACK(0,ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW,0), "NETSCAPE_CERT_SEQUENCE_new"},
211{ERR_PACK(0,ASN1_F_NETSCAPE_PKEY_NEW,0), "NETSCAPE_PKEY_NEW"},
212{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_new"},
213{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_new"},
214{ERR_PACK(0,ASN1_F_NOTICEREF_NEW,0), "NOTICEREF_new"},
215{ERR_PACK(0,ASN1_F_OTHERNAME_NEW,0), "OTHERNAME_new"},
216{ERR_PACK(0,ASN1_F_PBE2PARAM_NEW,0), "PBE2PARAM_new"},
217{ERR_PACK(0,ASN1_F_PBEPARAM_NEW,0), "PBEPARAM_new"},
218{ERR_PACK(0,ASN1_F_PBKDF2PARAM_NEW,0), "PBKDF2PARAM_new"},
219{ERR_PACK(0,ASN1_F_PKCS12_BAGS_NEW,0), "PKCS12_BAGS_new"},
220{ERR_PACK(0,ASN1_F_PKCS12_MAC_DATA_NEW,0), "PKCS12_MAC_DATA_new"},
221{ERR_PACK(0,ASN1_F_PKCS12_NEW,0), "PKCS12_new"},
222{ERR_PACK(0,ASN1_F_PKCS12_SAFEBAG_NEW,0), "PKCS12_SAFEBAG_new"},
223{ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"},
224{ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_new"},
225{ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_new"},
226{ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_new"},
227{ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_new"},
228{ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_new"},
229{ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_new"},
230{ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_new"},
231{ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_new"},
232{ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_new"},
233{ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_new"},
234{ERR_PACK(0,ASN1_F_PKCS8_PRIV_KEY_INFO_NEW,0), "PKCS8_PRIV_KEY_INFO_new"},
235{ERR_PACK(0,ASN1_F_PKEY_USAGE_PERIOD_NEW,0), "PKEY_USAGE_PERIOD_new"},
236{ERR_PACK(0,ASN1_F_POLICYINFO_NEW,0), "POLICYINFO_new"},
237{ERR_PACK(0,ASN1_F_POLICYQUALINFO_NEW,0), "POLICYQUALINFO_new"},
238{ERR_PACK(0,ASN1_F_SXNETID_NEW,0), "SXNETID_new"},
239{ERR_PACK(0,ASN1_F_SXNET_NEW,0), "SXNET_new"},
240{ERR_PACK(0,ASN1_F_USERNOTICE_NEW,0), "USERNOTICE_new"},
241{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_new"},
242{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_new"},
243{ERR_PACK(0,ASN1_F_X509_CERT_AUX_NEW,0), "X509_CERT_AUX_new"},
244{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_new"},
245{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_new"},
246{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_new"},
247{ERR_PACK(0,ASN1_F_X509_DHPARAMS_NEW,0), "X509_DHPARAMS_NEW"},
248{ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_new"},
249{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_new"},
250{ERR_PACK(0,ASN1_F_X509_KEY_NEW,0), "X509_KEY_NEW"},
251{ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_new"},
252{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_new"},
253{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_new"},
254{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_new"},
255{ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_new"},
256{ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_new"},
257{ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_new"},
258{ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_new"},
259{ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_new"},
260{ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_free"},
261{ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_new"},
262{0,NULL}
263 };
264
265static ERR_STRING_DATA ASN1_str_reasons[]=
266 {
267{ASN1_R_BAD_CLASS ,"bad class"},
268{ASN1_R_BAD_OBJECT_HEADER ,"bad object header"},
269{ASN1_R_BAD_PASSWORD_READ ,"bad password read"},
270{ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"},
271{ASN1_R_BAD_PKCS7_TYPE ,"bad pkcs7 type"},
272{ASN1_R_BAD_TAG ,"bad tag"},
273{ASN1_R_BAD_TYPE ,"bad type"},
274{ASN1_R_BN_LIB ,"bn lib"},
275{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"},
276{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"},
277{ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"},
278{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
279{ASN1_R_DECODE_ERROR ,"decode error"},
280{ASN1_R_DECODING_ERROR ,"decoding error"},
281{ASN1_R_ENCODE_ERROR ,"encode error"},
282{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"},
283{ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"},
284{ASN1_R_EXPECTING_AN_ENUMERATED ,"expecting an enumerated"},
285{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"},
286{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"},
287{ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"},
288{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"},
289{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
290{ASN1_R_EXPECTING_A_GENERALIZEDTIME ,"expecting a generalizedtime"},
291{ASN1_R_EXPECTING_A_NULL ,"expecting a null"},
292{ASN1_R_EXPECTING_A_TIME ,"expecting a time"},
293{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"},
294{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
295{ASN1_R_GENERALIZEDTIME_TOO_LONG ,"generalizedtime too long"},
296{ASN1_R_HEADER_TOO_LONG ,"header too long"},
297{ASN1_R_ILLEGAL_CHARACTERS ,"illegal characters"},
298{ASN1_R_INVALID_BMPSTRING_LENGTH ,"invalid bmpstring length"},
299{ASN1_R_INVALID_DIGIT ,"invalid digit"},
300{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
301{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
302{ASN1_R_INVALID_UNIVERSALSTRING_LENGTH ,"invalid universalstring length"},
303{ASN1_R_INVALID_UTF8STRING ,"invalid utf8string"},
304{ASN1_R_IV_TOO_LARGE ,"iv too large"},
305{ASN1_R_LENGTH_ERROR ,"length error"},
306{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
307{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
308{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
309{ASN1_R_NULL_IS_WRONG_LENGTH ,"null is wrong length"},
310{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
311{ASN1_R_PARSING ,"parsing"},
312{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},
313{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"},
314{ASN1_R_SHORT_LINE ,"short line"},
315{ASN1_R_STRING_TOO_LONG ,"string too long"},
316{ASN1_R_STRING_TOO_SHORT ,"string too short"},
317{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"},
318{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
319{ASN1_R_TOO_LONG ,"too long"},
320{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"},
321{ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"},
322{ASN1_R_UNKNOWN_ATTRIBUTE_TYPE ,"unknown attribute type"},
323{ASN1_R_UNKNOWN_FORMAT ,"unknown format"},
324{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"},
325{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"},
326{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"},
327{ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
328{ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"},
329{ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"},
330{ASN1_R_UTCTIME_TOO_LONG ,"utctime too long"},
331{ASN1_R_WRONG_PRINTABLE_TYPE ,"wrong printable type"},
332{ASN1_R_WRONG_TAG ,"wrong tag"},
333{ASN1_R_WRONG_TYPE ,"wrong type"},
334{0,NULL}
335 };
336
337#endif
338
339void ERR_load_ASN1_strings(void)
340 {
341 static int init=1;
342
343 if (init)
344 {
345 init=0;
346#ifndef NO_ERR
347 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs);
348 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_reasons);
349#endif
350
351 }
352 }
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
deleted file mode 100644
index be8daa8688..0000000000
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ /dev/null
@@ -1,424 +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 indefinite 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 allowance 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(a->data);
385 Free(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
414int ASN1_STRING_length(ASN1_STRING *x)
415{ return M_ASN1_STRING_length(x); }
416
417void ASN1_STRING_length_set(ASN1_STRING *x, int len)
418{ M_ASN1_STRING_length_set(x, len); return; }
419
420int ASN1_STRING_type(ASN1_STRING *x)
421{ return M_ASN1_STRING_type(x); }
422
423unsigned char * ASN1_STRING_data(ASN1_STRING *x)
424{ return M_ASN1_STRING_data(x); }
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
deleted file mode 100644
index 4f2a82d340..0000000000
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ /dev/null
@@ -1,560 +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/* Begin reading ASN1 without a surrounding sequence */
110#define M_ASN1_D2I_begin() \
111 c.slen = length;
112
113/* End reading ASN1 with no check on length */
114#define M_ASN1_D2I_Finish_nolen(a, func, e) \
115 *pp=c.p; \
116 if (a != NULL) (*a)=ret; \
117 return(ret); \
118err:\
119 ASN1_MAC_H_err((e),c.error,c.line); \
120 asn1_add_error(*pp,(int)(c.q- *pp)); \
121 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
122 return(NULL)
123
124#define M_ASN1_D2I_end_sequence() \
125 (((c.inf&1) == 0)?(c.slen <= 0): \
126 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
127
128/* Don't use this with d2i_ASN1_BOOLEAN() */
129#define M_ASN1_D2I_get(b,func) \
130 c.q=c.p; \
131 if (func(&(b),&c.p,c.slen) == NULL) \
132 {c.line=__LINE__; goto err; } \
133 c.slen-=(c.p-c.q);
134
135/* use this instead () */
136#define M_ASN1_D2I_get_int(b,func) \
137 c.q=c.p; \
138 if (func(&(b),&c.p,c.slen) < 0) \
139 {c.line=__LINE__; goto err; } \
140 c.slen-=(c.p-c.q);
141
142#define M_ASN1_D2I_get_opt(b,func,type) \
143 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
144 == (V_ASN1_UNIVERSAL|(type)))) \
145 { \
146 M_ASN1_D2I_get(b,func); \
147 }
148
149#define M_ASN1_D2I_get_imp(b,func, type) \
150 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
151 c.q=c.p; \
152 if (func(&(b),&c.p,c.slen) == NULL) \
153 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
154 c.slen-=(c.p-c.q);\
155 M_ASN1_next_prev=_tmp;
156
157#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
158 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
159 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
160 { \
161 unsigned char _tmp = M_ASN1_next; \
162 M_ASN1_D2I_get_imp(b,func, type);\
163 }
164
165#define M_ASN1_D2I_get_set(r,func,free_func) \
166 M_ASN1_D2I_get_imp_set(r,func,free_func, \
167 V_ASN1_SET,V_ASN1_UNIVERSAL);
168
169#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
170 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
171 V_ASN1_SET,V_ASN1_UNIVERSAL);
172
173#define M_ASN1_D2I_get_set_opt(r,func,free_func) \
174 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
175 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
176 { M_ASN1_D2I_get_set(r,func,free_func); }
177
178#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
179 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
180 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
181 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
182
183#define M_ASN1_I2D_len_SET_opt(a,f) \
184 if ((a != NULL) && (sk_num(a) != 0)) \
185 M_ASN1_I2D_len_SET(a,f);
186
187#define M_ASN1_I2D_put_SET_opt(a,f) \
188 if ((a != NULL) && (sk_num(a) != 0)) \
189 M_ASN1_I2D_put_SET(a,f);
190
191#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
192 if ((a != NULL) && (sk_num(a) != 0)) \
193 M_ASN1_I2D_put_SEQUENCE(a,f);
194
195#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
196 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
197 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
198
199#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
200 if ((c.slen != 0) && \
201 (M_ASN1_next == \
202 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
203 { \
204 M_ASN1_D2I_get_imp_set(b,func,free_func,\
205 tag,V_ASN1_CONTEXT_SPECIFIC); \
206 }
207
208#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
209 if ((c.slen != 0) && \
210 (M_ASN1_next == \
211 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
212 { \
213 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
214 tag,V_ASN1_CONTEXT_SPECIFIC); \
215 }
216
217#define M_ASN1_D2I_get_seq(r,func,free_func) \
218 M_ASN1_D2I_get_imp_set(r,func,free_func,\
219 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
220
221#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
222 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
223 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
224
225#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
226 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
227 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
228 { M_ASN1_D2I_get_seq(r,func,free_func); }
229
230#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
231 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
232 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
233 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
234
235#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
236 M_ASN1_D2I_get_imp_set(r,func,free_func,\
237 x,V_ASN1_CONTEXT_SPECIFIC);
238
239#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
240 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
241 x,V_ASN1_CONTEXT_SPECIFIC);
242
243#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
244 c.q=c.p; \
245 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
246 (void (*)())free_func,a,b) == NULL) \
247 { c.line=__LINE__; goto err; } \
248 c.slen-=(c.p-c.q);
249
250#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
251 c.q=c.p; \
252 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
253 free_func,a,b) == NULL) \
254 { c.line=__LINE__; goto err; } \
255 c.slen-=(c.p-c.q);
256
257#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
258 c.q=c.p; \
259 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
260 { c.line=__LINE__; goto err; } \
261 c.slen-=(c.p-c.q);
262
263#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
264 if ((c.slen != 0L) && (M_ASN1_next == \
265 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
266 { \
267 int Tinf,Ttag,Tclass; \
268 long Tlen; \
269 \
270 c.q=c.p; \
271 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
272 if (Tinf & 0x80) \
273 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
274 c.line=__LINE__; goto err; } \
275 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
276 Tlen = c.slen - (c.p - c.q) - 2; \
277 if (func(&(r),&c.p,Tlen) == NULL) \
278 { c.line=__LINE__; goto err; } \
279 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
280 Tlen = c.slen - (c.p - c.q); \
281 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
282 { c.error=ERR_R_MISSING_ASN1_EOS; \
283 c.line=__LINE__; goto err; } \
284 }\
285 c.slen-=(c.p-c.q); \
286 }
287
288#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
289 if ((c.slen != 0) && (M_ASN1_next == \
290 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
291 { \
292 int Tinf,Ttag,Tclass; \
293 long Tlen; \
294 \
295 c.q=c.p; \
296 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
297 if (Tinf & 0x80) \
298 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
299 c.line=__LINE__; goto err; } \
300 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
301 Tlen = c.slen - (c.p - c.q) - 2; \
302 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
303 (void (*)())free_func, \
304 b,V_ASN1_UNIVERSAL) == NULL) \
305 { c.line=__LINE__; goto err; } \
306 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
307 Tlen = c.slen - (c.p - c.q); \
308 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
309 { c.error=ERR_R_MISSING_ASN1_EOS; \
310 c.line=__LINE__; goto err; } \
311 }\
312 c.slen-=(c.p-c.q); \
313 }
314
315#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
316 if ((c.slen != 0) && (M_ASN1_next == \
317 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
318 { \
319 int Tinf,Ttag,Tclass; \
320 long Tlen; \
321 \
322 c.q=c.p; \
323 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
324 if (Tinf & 0x80) \
325 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
326 c.line=__LINE__; goto err; } \
327 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
328 Tlen = c.slen - (c.p - c.q) - 2; \
329 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
330 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
331 { c.line=__LINE__; goto err; } \
332 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
333 Tlen = c.slen - (c.p - c.q); \
334 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
335 { c.error=ERR_R_MISSING_ASN1_EOS; \
336 c.line=__LINE__; goto err; } \
337 }\
338 c.slen-=(c.p-c.q); \
339 }
340
341/* New macros */
342#define M_ASN1_New_Malloc(ret,type) \
343 if ((ret=(type *)Malloc(sizeof(type))) == NULL) \
344 { c.line=__LINE__; goto err2; }
345
346#define M_ASN1_New(arg,func) \
347 if (((arg)=func()) == NULL) return(NULL)
348
349#define M_ASN1_New_Error(a) \
350/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
351 return(NULL);*/ \
352 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
353 return(NULL)
354
355
356#define M_ASN1_next (*c.p)
357#define M_ASN1_next_prev (*c.q)
358
359/*************************************************/
360
361#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
362 unsigned char *p; \
363 if (a == NULL) return(0)
364
365/* Length Macros */
366#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
367#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
368
369#define M_ASN1_I2D_len_SET(a,f) \
370 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
371
372#define M_ASN1_I2D_len_SET_type(type,a,f) \
373 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
374 V_ASN1_UNIVERSAL,IS_SET);
375
376#define M_ASN1_I2D_len_SEQUENCE(a,f) \
377 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
378 IS_SEQUENCE);
379
380#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
381 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
382 V_ASN1_UNIVERSAL,IS_SEQUENCE)
383
384#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
385 if ((a != NULL) && (sk_num(a) != 0)) \
386 M_ASN1_I2D_len_SEQUENCE(a,f);
387
388#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
389 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
390 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
391
392#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
393 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
394
395#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
396 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
397 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
398
399#define M_ASN1_I2D_len_IMP_SET_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_SET);
403
404#define M_ASN1_I2D_len_IMP_SET_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,IS_SET);
408
409#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
410 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
411 IS_SEQUENCE);
412
413#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
414 if ((a != NULL) && (sk_num(a) != 0)) \
415 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
416 IS_SEQUENCE);
417
418#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
419 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
420 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
421 V_ASN1_CONTEXT_SPECIFIC, \
422 IS_SEQUENCE);
423
424#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
425 if (a != NULL)\
426 { \
427 v=f(a,NULL); \
428 ret+=ASN1_object_size(1,v,mtag); \
429 }
430
431#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
432 if ((a != NULL) && (sk_num(a) != 0))\
433 { \
434 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
435 ret+=ASN1_object_size(1,v,mtag); \
436 }
437
438#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
439 if ((a != NULL) && (sk_num(a) != 0))\
440 { \
441 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
442 IS_SEQUENCE); \
443 ret+=ASN1_object_size(1,v,mtag); \
444 }
445
446#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
447 if ((a != NULL) && (sk_##type##_num(a) != 0))\
448 { \
449 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
450 V_ASN1_UNIVERSAL, \
451 IS_SEQUENCE); \
452 ret+=ASN1_object_size(1,v,mtag); \
453 }
454
455/* Put Macros */
456#define M_ASN1_I2D_put(a,f) f(a,&p)
457
458#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
459 if (a != NULL) \
460 { \
461 unsigned char *q=p; \
462 f(a,&p); \
463 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
464 }
465
466#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
467 V_ASN1_UNIVERSAL,IS_SET)
468#define M_ASN1_I2D_put_SET_type(type,a,f) \
469 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
470#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
471 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
472#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
473 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
474#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
475 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
476
477#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
478 V_ASN1_UNIVERSAL,IS_SEQUENCE)
479
480#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
481 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
482 IS_SEQUENCE)
483
484#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
485 if ((a != NULL) && (sk_num(a) != 0)) \
486 M_ASN1_I2D_put_SEQUENCE(a,f);
487
488#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
489 if ((a != NULL) && (sk_num(a) != 0)) \
490 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
491 IS_SET); }
492
493#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
494 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
495 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
496 V_ASN1_CONTEXT_SPECIFIC, \
497 IS_SET); }
498
499#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
500 if ((a != NULL) && (sk_num(a) != 0)) \
501 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
502 IS_SEQUENCE); }
503
504#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
505 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
506 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
507 V_ASN1_CONTEXT_SPECIFIC, \
508 IS_SEQUENCE); }
509
510#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
511 if (a != NULL) \
512 { \
513 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
514 f(a,&p); \
515 }
516
517#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
518 if ((a != NULL) && (sk_num(a) != 0)) \
519 { \
520 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
521 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
522 }
523
524#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
525 if ((a != NULL) && (sk_num(a) != 0)) \
526 { \
527 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
528 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
529 }
530
531#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
532 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
533 { \
534 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
535 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
536 IS_SEQUENCE); \
537 }
538
539#define M_ASN1_I2D_seq_total() \
540 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
541 if (pp == NULL) return(r); \
542 p= *pp; \
543 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
544
545#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
546 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
547 *(p++)=0x80
548
549#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
550
551#define M_ASN1_I2D_finish() *pp=p; \
552 return(r);
553
554int asn1_GetSequence(ASN1_CTX *c, long *length);
555void asn1_add_error(unsigned char *address,int offset);
556#ifdef __cplusplus
557}
558#endif
559
560#endif
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c
deleted file mode 100644
index d1e9816bad..0000000000
--- a/src/lib/libcrypto/asn1/asn1_par.c
+++ /dev/null
@@ -1,385 +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 p = ASN1_tag2str(tag);
97
98 if (p2 != NULL)
99 {
100 if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err;
101 }
102 else
103 {
104 if (BIO_printf(bp,fmt,p) <= 0) goto err;
105 }
106 return(1);
107err:
108 return(0);
109 }
110
111int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent)
112 {
113 return(asn1_parse2(bp,&pp,len,0,0,indent));
114 }
115
116static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
117 int depth, int indent)
118 {
119 unsigned char *p,*ep,*tot,*op,*opp;
120 long len;
121 int tag,xclass,ret=0;
122 int nl,hl,j,r;
123 ASN1_OBJECT *o=NULL;
124 ASN1_OCTET_STRING *os=NULL;
125 /* ASN1_BMPSTRING *bmp=NULL;*/
126
127 p= *pp;
128 tot=p+length;
129 op=p-1;
130 while ((p < tot) && (op < p))
131 {
132 op=p;
133 j=ASN1_get_object(&p,&len,&tag,&xclass,length);
134#ifdef LINT
135 j=j;
136#endif
137 if (j & 0x80)
138 {
139 if (BIO_write(bp,"Error in encoding\n",18) <= 0)
140 goto end;
141 ret=0;
142 goto end;
143 }
144 hl=(p-op);
145 length-=hl;
146 /* if j == 0x21 it is a constructed indefinite length object */
147 if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
148 <= 0) goto end;
149
150 if (j != (V_ASN1_CONSTRUCTED | 1))
151 {
152 if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
153 depth,(long)hl,len) <= 0)
154 goto end;
155 }
156 else
157 {
158 if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
159 depth,(long)hl) <= 0)
160 goto end;
161 }
162 if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
163 goto end;
164 if (j & V_ASN1_CONSTRUCTED)
165 {
166 ep=p+len;
167 if (BIO_write(bp,"\n",1) <= 0) goto end;
168 if (len > length)
169 {
170 BIO_printf(bp,
171 "length is greater than %ld\n",length);
172 ret=0;
173 goto end;
174 }
175 if ((j == 0x21) && (len == 0))
176 {
177 for (;;)
178 {
179 r=asn1_parse2(bp,&p,(long)(tot-p),
180 offset+(p - *pp),depth+1,
181 indent);
182 if (r == 0) { ret=0; goto end; }
183 if ((r == 2) || (p >= tot)) break;
184 }
185 }
186 else
187 while (p < ep)
188 {
189 r=asn1_parse2(bp,&p,(long)len,
190 offset+(p - *pp),depth+1,
191 indent);
192 if (r == 0) { ret=0; goto end; }
193 }
194 }
195 else if (xclass != 0)
196 {
197 p+=len;
198 if (BIO_write(bp,"\n",1) <= 0) goto end;
199 }
200 else
201 {
202 nl=0;
203 if ( (tag == V_ASN1_PRINTABLESTRING) ||
204 (tag == V_ASN1_T61STRING) ||
205 (tag == V_ASN1_IA5STRING) ||
206 (tag == V_ASN1_VISIBLESTRING) ||
207 (tag == V_ASN1_UTCTIME) ||
208 (tag == V_ASN1_GENERALIZEDTIME))
209 {
210 if (BIO_write(bp,":",1) <= 0) goto end;
211 if ((len > 0) &&
212 BIO_write(bp,(char *)p,(int)len)
213 != (int)len)
214 goto end;
215 }
216 else if (tag == V_ASN1_OBJECT)
217 {
218 opp=op;
219 if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
220 {
221 if (BIO_write(bp,":",1) <= 0) goto end;
222 i2a_ASN1_OBJECT(bp,o);
223 }
224 else
225 {
226 if (BIO_write(bp,":BAD OBJECT",11) <= 0)
227 goto end;
228 }
229 }
230 else if (tag == V_ASN1_BOOLEAN)
231 {
232 int ii;
233
234 opp=op;
235 ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
236 if (ii < 0)
237 {
238 if (BIO_write(bp,"Bad boolean\n",12))
239 goto end;
240 }
241 BIO_printf(bp,":%d",ii);
242 }
243 else if (tag == V_ASN1_BMPSTRING)
244 {
245 /* do the BMP thang */
246 }
247 else if (tag == V_ASN1_OCTET_STRING)
248 {
249 int i,printable=1;
250
251 opp=op;
252 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
253 if (os != NULL)
254 {
255 opp=os->data;
256 for (i=0; i<os->length; i++)
257 {
258 if (( (opp[i] < ' ') &&
259 (opp[i] != '\n') &&
260 (opp[i] != '\r') &&
261 (opp[i] != '\t')) ||
262 (opp[i] > '~'))
263 {
264 printable=0;
265 break;
266 }
267 }
268 if (printable && (os->length > 0))
269 {
270 if (BIO_write(bp,":",1) <= 0)
271 goto end;
272 if (BIO_write(bp,(char *)opp,
273 os->length) <= 0)
274 goto end;
275 }
276 M_ASN1_OCTET_STRING_free(os);
277 os=NULL;
278 }
279 }
280 else if (tag == V_ASN1_INTEGER)
281 {
282 ASN1_INTEGER *bs;
283 int i;
284
285 opp=op;
286 bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
287 if (bs != NULL)
288 {
289 if (BIO_write(bp,":",1) <= 0) goto end;
290 if (bs->type == V_ASN1_NEG_INTEGER)
291 if (BIO_write(bp,"-",1) <= 0)
292 goto end;
293 for (i=0; i<bs->length; i++)
294 {
295 if (BIO_printf(bp,"%02X",
296 bs->data[i]) <= 0)
297 goto end;
298 }
299 if (bs->length == 0)
300 {
301 if (BIO_write(bp,"00",2) <= 0)
302 goto end;
303 }
304 }
305 else
306 {
307 if (BIO_write(bp,"BAD INTEGER",11) <= 0)
308 goto end;
309 }
310 M_ASN1_INTEGER_free(bs);
311 }
312 else if (tag == V_ASN1_ENUMERATED)
313 {
314 ASN1_ENUMERATED *bs;
315 int i;
316
317 opp=op;
318 bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
319 if (bs != NULL)
320 {
321 if (BIO_write(bp,":",1) <= 0) goto end;
322 if (bs->type == V_ASN1_NEG_ENUMERATED)
323 if (BIO_write(bp,"-",1) <= 0)
324 goto end;
325 for (i=0; i<bs->length; i++)
326 {
327 if (BIO_printf(bp,"%02X",
328 bs->data[i]) <= 0)
329 goto end;
330 }
331 if (bs->length == 0)
332 {
333 if (BIO_write(bp,"00",2) <= 0)
334 goto end;
335 }
336 }
337 else
338 {
339 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
340 goto end;
341 }
342 M_ASN1_ENUMERATED_free(bs);
343 }
344
345 if (!nl)
346 {
347 if (BIO_write(bp,"\n",1) <= 0) goto end;
348 }
349 p+=len;
350 if ((tag == V_ASN1_EOC) && (xclass == 0))
351 {
352 ret=2; /* End of sequence */
353 goto end;
354 }
355 }
356 length-=len;
357 }
358 ret=1;
359end:
360 if (o != NULL) ASN1_OBJECT_free(o);
361 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
362 *pp=p;
363 return(ret);
364 }
365
366const char *ASN1_tag2str(int tag)
367{
368 const static char *tag2str[] = {
369 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */
370 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */
371 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */
372 "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */
373 "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */
374 "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */
375 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */
376 "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */
377 };
378
379 if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED))
380 tag &= ~0x100;
381
382 if(tag < 0 || tag > 30) return "(unknown)";
383 return tag2str[tag];
384}
385
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 c92b8325d8..0000000000
--- a/src/lib/libcrypto/asn1/d2i_pr.c
+++ /dev/null
@@ -1,137 +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
115/* This works like d2i_PrivateKey() except it automatically works out the type */
116
117EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
118 long length)
119{
120 STACK_OF(ASN1_TYPE) *inkey;
121 unsigned char *p;
122 int keytype;
123 p = *pp;
124 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
125 * by analyzing it we can determine the passed structure: this
126 * assumes the input is surrounded by an ASN1 SEQUENCE.
127 */
128 inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE,
129 ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
130 /* Since we only need to discern "traditional format" RSA and DSA
131 * keys we can just count the elements.
132 */
133 if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA;
134 else keytype = EVP_PKEY_RSA;
135 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
136 return d2i_PrivateKey(keytype, a, pp, length);
137}
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 3506005a71..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=M_ASN1_OCTET_STRING_new()) == NULL) return(0);
69 if (!M_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=M_ASN1_STRING_data(a->value.octet_string);
87 ret=M_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 M_ASN1_STRING_length_set(osp, size);
121 p=M_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=M_ASN1_STRING_data(a->value.sequence);
149 length=M_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=M_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,M_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) M_ASN1_OCTET_STRING_free(os);
182 if (ai != NULL) M_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 3d0b1107cb..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(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 cd57331c3f..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(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 088313689a..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(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 d804986b73..0000000000
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ /dev/null
@@ -1,348 +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(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 M_ASN1_BIT_STRING_free(os);
209 goto err;
210 }
211 M_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) M_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,M_ASN1_INTEGER_new);
325 M_ASN1_New(ret->algor,X509_ALGOR_new);
326 M_ASN1_New(ret->private_key,M_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 M_ASN1_INTEGER_free(a->version);
335 X509_ALGOR_free(a->algor);
336 M_ASN1_OCTET_STRING_free(a->private_key);
337 Free(a);
338 }
339
340#endif /* NO_RC4 */
341
342#else /* !NO_RSA */
343
344# if PEDANTIC
345static void *dummy=&dummy;
346# endif
347
348#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 a147ac3295..0000000000
--- a/src/lib/libcrypto/asn1/p5_pbe.c
+++ /dev/null
@@ -1,157 +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,M_ASN1_INTEGER_new);
86 M_ASN1_New(ret->salt,M_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 M_ASN1_OCTET_STRING_free(a->salt);
105 M_ASN1_INTEGER_free (a->iter);
106 Free (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 if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0)
133 return NULL;
134
135 if (!(astype = ASN1_TYPE_new())) {
136 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
137 return NULL;
138 }
139
140 astype->type = V_ASN1_SEQUENCE;
141 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
142 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
143 return NULL;
144 }
145 PBEPARAM_free (pbe);
146
147 al = OBJ_nid2obj(alg); /* never need to free al */
148 if (!(algor = X509_ALGOR_new())) {
149 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
150 return NULL;
151 }
152 ASN1_OBJECT_free(algor->algorithm);
153 algor->algorithm = al;
154 algor->parameter = astype;
155
156 return (algor);
157}
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
deleted file mode 100644
index 1bbdb10c71..0000000000
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ /dev/null
@@ -1,282 +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 (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, M_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 M_ASN1_INTEGER_free(a->iter);
159 M_ASN1_INTEGER_free(a->keylength);
160 X509_ALGOR_free(a->prf);
161 Free (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 ASN1_OBJECT *obj;
179
180 alg_nid = EVP_CIPHER_type(cipher);
181 if(alg_nid == NID_undef) {
182 ASN1err(ASN1_F_PKCS5_PBE2_SET,
183 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
184 goto err;
185 }
186 obj = OBJ_nid2obj(alg_nid);
187
188 if(!(pbe2 = PBE2PARAM_new())) goto merr;
189
190 /* Setup the AlgorithmIdentifier for the encryption scheme */
191 scheme = pbe2->encryption;
192
193 scheme->algorithm = obj;
194 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
195
196 /* Create random IV */
197 if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
198 goto err;
199
200 /* Dummy cipherinit to just setup the IV */
201 EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
202 if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
203 ASN1err(ASN1_F_PKCS5_PBE2_SET,
204 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
205 goto err;
206 }
207 EVP_CIPHER_CTX_cleanup(&ctx);
208
209 if(!(kdf = PBKDF2PARAM_new())) goto merr;
210 if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr;
211
212 if (!saltlen) saltlen = PKCS5_SALT_LEN;
213 if (!(osalt->data = Malloc (saltlen))) goto merr;
214 osalt->length = saltlen;
215 if (salt) memcpy (osalt->data, salt, saltlen);
216 else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) goto merr;
217
218 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
219 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
220
221 /* Now include salt in kdf structure */
222 kdf->salt->value.octet_string = osalt;
223 kdf->salt->type = V_ASN1_OCTET_STRING;
224 osalt = NULL;
225
226 /* If its RC2 then we'd better setup the key length */
227
228 if(alg_nid == NID_rc2_cbc) {
229 if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr;
230 if(!ASN1_INTEGER_set (kdf->keylength,
231 EVP_CIPHER_key_length(cipher))) goto merr;
232 }
233
234 /* prf can stay NULL because we are using hmacWithSHA1 */
235
236 /* Now setup the PBE2PARAM keyfunc structure */
237
238 pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
239
240 /* Encode PBKDF2PARAM into parameter of pbe2 */
241
242 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
243
244 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
245 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
246 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
247
248 PBKDF2PARAM_free(kdf);
249 kdf = NULL;
250
251 /* Now set up top level AlgorithmIdentifier */
252
253 if(!(ret = X509_ALGOR_new())) goto merr;
254 if(!(ret->parameter = ASN1_TYPE_new())) goto merr;
255
256 ret->algorithm = OBJ_nid2obj(NID_pbes2);
257
258 /* Encode PBE2PARAM into parameter */
259
260 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
261 &ret->parameter->value.sequence)) goto merr;
262 ret->parameter->type = V_ASN1_SEQUENCE;
263
264 PBE2PARAM_free(pbe2);
265 pbe2 = NULL;
266
267 return ret;
268
269 merr:
270 ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
271
272 err:
273 PBE2PARAM_free(pbe2);
274 /* Note 'scheme' is freed as part of pbe2 */
275 M_ASN1_OCTET_STRING_free(osalt);
276 PBKDF2PARAM_free(kdf);
277 X509_ALGOR_free(kalg);
278 X509_ALGOR_free(ret);
279
280 return NULL;
281
282}
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
deleted file mode 100644
index 59cfbe7f28..0000000000
--- a/src/lib/libcrypto/asn1/p8_pkey.c
+++ /dev/null
@@ -1,127 +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, M_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 M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO);
113}
114
115void PKCS8_PRIV_KEY_INFO_free (PKCS8_PRIV_KEY_INFO *a)
116{
117 if (a == NULL) return;
118 M_ASN1_INTEGER_free (a->version);
119 X509_ALGOR_free(a->pkeyalg);
120 /* Clear sensitive data */
121 if (a->pkey->value.octet_string)
122 memset (a->pkey->value.octet_string->data,
123 0, a->pkey->value.octet_string->length);
124 ASN1_TYPE_free (a->pkey);
125 sk_X509_ATTRIBUTE_pop_free (a->attributes, X509_ATTRIBUTE_free);
126 Free (a);
127}
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c
deleted file mode 100644
index 8ee789f082..0000000000
--- a/src/lib/libcrypto/asn1/t_bitst.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/* t_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
65 BIT_STRING_BITNAME *tbl, int indent)
66{
67 BIT_STRING_BITNAME *bnam;
68 char first = 1;
69 BIO_printf(out, "%*s", indent, "");
70 for(bnam = tbl; bnam->lname; bnam++) {
71 if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
72 if(!first) BIO_puts(out, ", ");
73 BIO_puts(out, bnam->lname);
74 first = 0;
75 }
76 }
77 BIO_puts(out, "\n");
78 return 1;
79}
80
81int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
82 BIT_STRING_BITNAME *tbl)
83{
84 int bitnum;
85 bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
86 if(bitnum < 0) return 0;
87 if(bs) ASN1_BIT_STRING_set_bit(bs, bitnum, value);
88 return 1;
89}
90
91int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
92{
93 BIT_STRING_BITNAME *bnam;
94 for(bnam = tbl; bnam->lname; bnam++) {
95 if(!strcmp(bnam->sname, name) ||
96 !strcmp(bnam->lname, name) ) return bnam->bitnum;
97 }
98 return -1;
99}
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
deleted file mode 100644
index d78e4a8f88..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 M_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 e570ed1c47..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(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(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," recommended-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(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(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 ea1af092db..0000000000
--- a/src/lib/libcrypto/asn1/t_req.c
+++ /dev/null
@@ -1,254 +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#include <openssl/x509v3.h>
66
67#ifndef NO_FP_API
68int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
69 {
70 BIO *b;
71 int ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=X509_REQ_print(b, x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85int X509_REQ_print(BIO *bp, X509_REQ *x)
86 {
87 unsigned long l;
88 int i,n;
89 char *s;
90 const char *neg;
91 X509_REQ_INFO *ri;
92 EVP_PKEY *pkey;
93 STACK_OF(X509_ATTRIBUTE) *sk;
94 STACK_OF(X509_EXTENSION) *exts;
95 char str[128];
96
97 ri=x->req_info;
98 sprintf(str,"Certificate Request:\n");
99 if (BIO_puts(bp,str) <= 0) goto err;
100 sprintf(str,"%4sData:\n","");
101 if (BIO_puts(bp,str) <= 0) goto err;
102
103 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
104 l=0;
105 for (i=0; i<ri->version->length; i++)
106 { l<<=8; l+=ri->version->data[i]; }
107 sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l);
108 if (BIO_puts(bp,str) <= 0) goto err;
109 sprintf(str,"%8sSubject: ","");
110 if (BIO_puts(bp,str) <= 0) goto err;
111
112 X509_NAME_print(bp,ri->subject,16);
113 sprintf(str,"\n%8sSubject Public Key Info:\n","");
114 if (BIO_puts(bp,str) <= 0) goto err;
115 i=OBJ_obj2nid(ri->pubkey->algor->algorithm);
116 sprintf(str,"%12sPublic Key Algorithm: %s\n","",
117 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
118 if (BIO_puts(bp,str) <= 0) goto err;
119
120 pkey=X509_REQ_get_pubkey(x);
121#ifndef NO_RSA
122 if (pkey != NULL && pkey->type == EVP_PKEY_RSA)
123 {
124 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
125 BN_num_bits(pkey->pkey.rsa->n));
126 RSA_print(bp,pkey->pkey.rsa,16);
127 }
128 else
129#endif
130#ifndef NO_DSA
131 if (pkey != NULL && pkey->type == EVP_PKEY_DSA)
132 {
133 BIO_printf(bp,"%12sDSA Public Key:\n","");
134 DSA_print(bp,pkey->pkey.dsa,16);
135 }
136 else
137#endif
138 BIO_printf(bp,"%12sUnknown Public Key:\n","");
139
140 if (pkey != NULL)
141 EVP_PKEY_free(pkey);
142
143 /* may not be */
144 sprintf(str,"%8sAttributes:\n","");
145 if (BIO_puts(bp,str) <= 0) goto err;
146
147 sk=x->req_info->attributes;
148 if ((sk == NULL) || (sk_X509_ATTRIBUTE_num(sk) == 0))
149 {
150 if (!x->req_info->req_kludge)
151 {
152 sprintf(str,"%12sa0:00\n","");
153 if (BIO_puts(bp,str) <= 0) goto err;
154 }
155 }
156 else
157 {
158 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
159 {
160 ASN1_TYPE *at;
161 X509_ATTRIBUTE *a;
162 ASN1_BIT_STRING *bs=NULL;
163 ASN1_TYPE *t;
164 int j,type=0,count=1,ii=0;
165
166 a=sk_X509_ATTRIBUTE_value(sk,i);
167 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
168 continue;
169 sprintf(str,"%12s","");
170 if (BIO_puts(bp,str) <= 0) goto err;
171 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
172 {
173 if (a->set)
174 {
175 ii=0;
176 count=sk_ASN1_TYPE_num(a->value.set);
177get_next:
178 at=sk_ASN1_TYPE_value(a->value.set,ii);
179 type=at->type;
180 bs=at->value.asn1_string;
181 }
182 else
183 {
184 t=a->value.single;
185 type=t->type;
186 bs=t->value.bit_string;
187 }
188 }
189 for (j=25-j; j>0; j--)
190 if (BIO_write(bp," ",1) != 1) goto err;
191 if (BIO_puts(bp,":") <= 0) goto err;
192 if ( (type == V_ASN1_PRINTABLESTRING) ||
193 (type == V_ASN1_T61STRING) ||
194 (type == V_ASN1_IA5STRING))
195 {
196 if (BIO_write(bp,(char *)bs->data,bs->length)
197 != bs->length)
198 goto err;
199 BIO_puts(bp,"\n");
200 }
201 else
202 {
203 BIO_puts(bp,"unable to print attribute\n");
204 }
205 if (++ii < count) goto get_next;
206 }
207 }
208
209 exts = X509_REQ_get_extensions(x);
210 if(exts) {
211 BIO_printf(bp,"%8sRequested Extensions:\n","");
212 for (i=0; i<sk_X509_EXTENSION_num(exts); i++) {
213 ASN1_OBJECT *obj;
214 X509_EXTENSION *ex;
215 int j;
216 ex=sk_X509_EXTENSION_value(exts, i);
217 if (BIO_printf(bp,"%12s","") <= 0) goto err;
218 obj=X509_EXTENSION_get_object(ex);
219 i2a_ASN1_OBJECT(bp,obj);
220 j=X509_EXTENSION_get_critical(ex);
221 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
222 goto err;
223 if(!X509V3_EXT_print(bp, ex, 0, 16)) {
224 BIO_printf(bp, "%16s", "");
225 M_ASN1_OCTET_STRING_print(bp,ex->value);
226 }
227 if (BIO_write(bp,"\n",1) <= 0) goto err;
228 }
229 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
230 }
231
232 i=OBJ_obj2nid(x->sig_alg->algorithm);
233 sprintf(str,"%4sSignature Algorithm: %s","",
234 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
235 if (BIO_puts(bp,str) <= 0) goto err;
236
237 n=x->signature->length;
238 s=(char *)x->signature->data;
239 for (i=0; i<n; i++)
240 {
241 if ((i%18) == 0)
242 {
243 sprintf(str,"\n%8s","");
244 if (BIO_puts(bp,str) <= 0) goto err;
245 }
246 sprintf(str,"%02x%s",(unsigned char)s[i],((i+1) == n)?"":":");
247 if (BIO_puts(bp,str) <= 0) goto err;
248 }
249 if (BIO_puts(bp,"\n") <= 0) goto err;
250 return(1);
251err:
252 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
253 return(0);
254 }
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c
deleted file mode 100644
index d708434fca..0000000000
--- a/src/lib/libcrypto/asn1/t_spki.c
+++ /dev/null
@@ -1,116 +0,0 @@
1/* t_spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/asn1_mac.h>
63
64/* Print out an SPKI */
65
66int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
67{
68 EVP_PKEY *pkey;
69 ASN1_IA5STRING *chal;
70 int i, n;
71 char *s;
72 BIO_printf(out, "Netscape SPKI:\n");
73 i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm);
74 BIO_printf(out," Public Key Algorithm: %s\n",
75 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
76 pkey = X509_PUBKEY_get(spki->spkac->pubkey);
77 if(!pkey) BIO_printf(out, " Unable to load public key\n");
78 else {
79#ifndef NO_RSA
80 if (pkey->type == EVP_PKEY_RSA)
81 {
82 BIO_printf(out," RSA Public Key: (%d bit)\n",
83 BN_num_bits(pkey->pkey.rsa->n));
84 RSA_print(out,pkey->pkey.rsa,2);
85 }
86 else
87#endif
88#ifndef NO_DSA
89 if (pkey->type == EVP_PKEY_DSA)
90 {
91 BIO_printf(out," DSA Public Key:\n");
92 DSA_print(out,pkey->pkey.dsa,2);
93 }
94 else
95#endif
96 BIO_printf(out," Unknown Public Key:\n");
97 EVP_PKEY_free(pkey);
98 }
99 chal = spki->spkac->challenge;
100 if(chal->length)
101 BIO_printf(out, " Challenge String: %s\n", chal->data);
102 i=OBJ_obj2nid(spki->sig_algor->algorithm);
103 BIO_printf(out," Signature Algorithm: %s",
104 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
105
106 n=spki->signature->length;
107 s=(char *)spki->signature->data;
108 for (i=0; i<n; i++)
109 {
110 if ((i%18) == 0) BIO_write(out,"\n ",7);
111 BIO_printf(out,"%02x%s",(unsigned char)s[i],
112 ((i+1) == n)?"":":");
113 }
114 BIO_write(out,"\n",1);
115 return 1;
116}
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
deleted file mode 100644
index 6ee1065ce9..0000000000
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ /dev/null
@@ -1,409 +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 ASN1_OBJECT *obj;
192 ex=X509_get_ext(x,i);
193 if (BIO_printf(bp,"%12s","") <= 0) goto err;
194 obj=X509_EXTENSION_get_object(ex);
195 i2a_ASN1_OBJECT(bp,obj);
196 j=X509_EXTENSION_get_critical(ex);
197 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
198 goto err;
199 if(!X509V3_EXT_print(bp, ex, 0, 16))
200 {
201 BIO_printf(bp, "%16s", "");
202 M_ASN1_OCTET_STRING_print(bp,ex->value);
203 }
204 if (BIO_write(bp,"\n",1) <= 0) goto err;
205 }
206 }
207
208 i=OBJ_obj2nid(x->sig_alg->algorithm);
209 if (BIO_printf(bp,"%4sSignature Algorithm: %s","",
210 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
211
212 n=x->signature->length;
213 s=(char *)x->signature->data;
214 for (i=0; i<n; i++)
215 {
216 if ((i%18) == 0)
217 if (BIO_write(bp,"\n ",9) <= 0) goto err;
218 if (BIO_printf(bp,"%02x%s",(unsigned char)s[i],
219 ((i+1) == n)?"":":") <= 0) goto err;
220 }
221 if (BIO_write(bp,"\n",1) != 1) goto err;
222 if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err;
223 ret=1;
224err:
225 if (str != NULL) ASN1_STRING_free(str);
226 if (m != NULL) Free(m);
227 return(ret);
228 }
229
230int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
231 {
232 int i,n;
233 char buf[80],*p;;
234
235 if (v == NULL) return(0);
236 n=0;
237 p=(char *)v->data;
238 for (i=0; i<v->length; i++)
239 {
240 if ((p[i] > '~') || ((p[i] < ' ') &&
241 (p[i] != '\n') && (p[i] != '\r')))
242 buf[n]='.';
243 else
244 buf[n]=p[i];
245 n++;
246 if (n >= 80)
247 {
248 if (BIO_write(bp,buf,n) <= 0)
249 return(0);
250 n=0;
251 }
252 }
253 if (n > 0)
254 if (BIO_write(bp,buf,n) <= 0)
255 return(0);
256 return(1);
257 }
258
259int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
260{
261 if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
262 if(tm->type == V_ASN1_GENERALIZEDTIME)
263 return ASN1_GENERALIZEDTIME_print(bp, tm);
264 BIO_write(bp,"Bad time value",14);
265 return(0);
266}
267
268static const char *mon[12]=
269 {
270 "Jan","Feb","Mar","Apr","May","Jun",
271 "Jul","Aug","Sep","Oct","Nov","Dec"
272 };
273
274int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
275 {
276 char *v;
277 int gmt=0;
278 int i;
279 int y=0,M=0,d=0,h=0,m=0,s=0;
280
281 i=tm->length;
282 v=(char *)tm->data;
283
284 if (i < 12) goto err;
285 if (v[i-1] == 'Z') gmt=1;
286 for (i=0; i<12; i++)
287 if ((v[i] > '9') || (v[i] < '0')) goto err;
288 y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
289 M= (v[4]-'0')*10+(v[5]-'0');
290 if ((M > 12) || (M < 1)) goto err;
291 d= (v[6]-'0')*10+(v[7]-'0');
292 h= (v[8]-'0')*10+(v[9]-'0');
293 m= (v[10]-'0')*10+(v[11]-'0');
294 if ( (v[12] >= '0') && (v[12] <= '9') &&
295 (v[13] >= '0') && (v[13] <= '9'))
296 s= (v[12]-'0')*10+(v[13]-'0');
297
298 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
299 mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
300 return(0);
301 else
302 return(1);
303err:
304 BIO_write(bp,"Bad time value",14);
305 return(0);
306 }
307
308int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
309 {
310 char *v;
311 int gmt=0;
312 int i;
313 int y=0,M=0,d=0,h=0,m=0,s=0;
314
315 i=tm->length;
316 v=(char *)tm->data;
317
318 if (i < 10) goto err;
319 if (v[i-1] == 'Z') gmt=1;
320 for (i=0; i<10; i++)
321 if ((v[i] > '9') || (v[i] < '0')) goto err;
322 y= (v[0]-'0')*10+(v[1]-'0');
323 if (y < 50) y+=100;
324 M= (v[2]-'0')*10+(v[3]-'0');
325 if ((M > 12) || (M < 1)) goto err;
326 d= (v[4]-'0')*10+(v[5]-'0');
327 h= (v[6]-'0')*10+(v[7]-'0');
328 m= (v[8]-'0')*10+(v[9]-'0');
329 if ( (v[10] >= '0') && (v[10] <= '9') &&
330 (v[11] >= '0') && (v[11] <= '9'))
331 s= (v[10]-'0')*10+(v[11]-'0');
332
333 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
334 mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0)
335 return(0);
336 else
337 return(1);
338err:
339 BIO_write(bp,"Bad time value",14);
340 return(0);
341 }
342
343int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
344 {
345 char *s,*c;
346 int ret=0,l,ll,i,first=1;
347 char buf[256];
348
349 ll=80-2-obase;
350
351 s=X509_NAME_oneline(name,buf,256);
352 s++; /* skip the first slash */
353
354 l=ll;
355 c=s;
356 for (;;)
357 {
358#ifndef CHARSET_EBCDIC
359 if ( ((*s == '/') &&
360 ((s[1] >= 'A') && (s[1] <= 'Z') && (
361 (s[2] == '=') ||
362 ((s[2] >= 'A') && (s[2] <= 'Z') &&
363 (s[3] == '='))
364 ))) ||
365 (*s == '\0'))
366#else
367 if ( ((*s == '/') &&
368 (isupper(s[1]) && (
369 (s[2] == '=') ||
370 (isupper(s[2]) &&
371 (s[3] == '='))
372 ))) ||
373 (*s == '\0'))
374#endif
375 {
376 if ((l <= 0) && !first)
377 {
378 first=0;
379 if (BIO_write(bp,"\n",1) != 1) goto err;
380 for (i=0; i<obase; i++)
381 {
382 if (BIO_write(bp," ",1) != 1) goto err;
383 }
384 l=ll;
385 }
386 i=s-c;
387 if (BIO_write(bp,c,i) != i) goto err;
388 c+=i;
389 c++;
390 if (*s != '\0')
391 {
392 if (BIO_write(bp,", ",2) != 2) goto err;
393 }
394 l--;
395 }
396 if (*s == '\0') break;
397 s++;
398 l--;
399 }
400
401 ret=1;
402 if (0)
403 {
404err:
405 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
406 }
407 return(ret);
408 }
409
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c
deleted file mode 100644
index a18ebb586c..0000000000
--- a/src/lib/libcrypto/asn1/t_x509a.c
+++ /dev/null
@@ -1,102 +0,0 @@
1/* t_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX and string set routines
66 */
67
68int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
69{
70 char oidstr[80], first;
71 int i;
72 if(!aux) return 1;
73 if(aux->trust) {
74 first = 1;
75 BIO_printf(out, "%*sTrusted Uses:\n%*s",
76 indent, "", indent + 2, "");
77 for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {
78 if(!first) BIO_puts(out, ", ");
79 else first = 0;
80 OBJ_obj2txt(oidstr, 80,
81 sk_ASN1_OBJECT_value(aux->trust, i), 0);
82 BIO_puts(out, oidstr);
83 }
84 BIO_puts(out, "\n");
85 } else BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
86 if(aux->reject) {
87 first = 1;
88 BIO_printf(out, "%*sRejected Uses:\n%*s",
89 indent, "", indent + 2, "");
90 for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {
91 if(!first) BIO_puts(out, ", ");
92 else first = 0;
93 OBJ_obj2txt(oidstr, 80,
94 sk_ASN1_OBJECT_value(aux->reject, i), 0);
95 BIO_puts(out, oidstr);
96 }
97 BIO_puts(out, "\n");
98 } else BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
99 if(aux->alias) BIO_printf(out, "%*sAlias: %s\n", indent, "",
100 aux->alias->data);
101 return 1;
102}
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
deleted file mode 100644
index fe023842f8..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(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 a874df79db..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(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 12a42d04c7..0000000000
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ /dev/null
@@ -1,343 +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_TIME);
134 if (a->nextUpdate != NULL)
135 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_TIME); }
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 M_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 /* First try UTCTime */
168 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME, V_ASN1_UTCTIME);
169 /* If that doesn't work try GeneralizedTime */
170 if(!ret->nextUpdate)
171 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME,
172 V_ASN1_GENERALIZEDTIME);
173 if (ret->revoked != NULL)
174 {
175 while (sk_X509_REVOKED_num(ret->revoked))
176 X509_REVOKED_free(sk_X509_REVOKED_pop(ret->revoked));
177 }
178 M_ASN1_D2I_get_seq_opt_type(X509_REVOKED,ret->revoked,d2i_X509_REVOKED,
179 X509_REVOKED_free);
180
181 if (ret->revoked != NULL)
182 {
183 for (i=0; i<sk_X509_REVOKED_num(ret->revoked); i++)
184 {
185 sk_X509_REVOKED_value(ret->revoked,i)->sequence=i;
186 }
187 }
188
189 if (ret->extensions != NULL)
190 {
191 while (sk_X509_EXTENSION_num(ret->extensions))
192 X509_EXTENSION_free(
193 sk_X509_EXTENSION_pop(ret->extensions));
194 }
195
196 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
197 d2i_X509_EXTENSION,
198 X509_EXTENSION_free,0,
199 V_ASN1_SEQUENCE);
200
201 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO);
202 }
203
204int i2d_X509_CRL(X509_CRL *a, unsigned char **pp)
205 {
206 M_ASN1_I2D_vars(a);
207
208 M_ASN1_I2D_len(a->crl,i2d_X509_CRL_INFO);
209 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
210 M_ASN1_I2D_len(a->signature,i2d_ASN1_BIT_STRING);
211
212 M_ASN1_I2D_seq_total();
213
214 M_ASN1_I2D_put(a->crl,i2d_X509_CRL_INFO);
215 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
216 M_ASN1_I2D_put(a->signature,i2d_ASN1_BIT_STRING);
217
218 M_ASN1_I2D_finish();
219 }
220
221X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length)
222 {
223 M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new);
224
225 M_ASN1_D2I_Init();
226 M_ASN1_D2I_start_sequence();
227 M_ASN1_D2I_get(ret->crl,d2i_X509_CRL_INFO);
228 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
229 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
230
231 M_ASN1_D2I_Finish(a,X509_CRL_free,ASN1_F_D2I_X509_CRL);
232 }
233
234
235X509_REVOKED *X509_REVOKED_new(void)
236 {
237 X509_REVOKED *ret=NULL;
238 ASN1_CTX c;
239
240 M_ASN1_New_Malloc(ret,X509_REVOKED);
241 M_ASN1_New(ret->serialNumber,M_ASN1_INTEGER_new);
242 M_ASN1_New(ret->revocationDate,M_ASN1_UTCTIME_new);
243 ret->extensions=NULL;
244 return(ret);
245 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW);
246 }
247
248X509_CRL_INFO *X509_CRL_INFO_new(void)
249 {
250 X509_CRL_INFO *ret=NULL;
251 ASN1_CTX c;
252
253 M_ASN1_New_Malloc(ret,X509_CRL_INFO);
254 ret->version=NULL;
255 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
256 M_ASN1_New(ret->issuer,X509_NAME_new);
257 M_ASN1_New(ret->lastUpdate,M_ASN1_UTCTIME_new);
258 ret->nextUpdate=NULL;
259 M_ASN1_New(ret->revoked,sk_X509_REVOKED_new_null);
260 M_ASN1_New(ret->extensions,sk_X509_EXTENSION_new_null);
261 sk_X509_REVOKED_set_cmp_func(ret->revoked,X509_REVOKED_cmp);
262 return(ret);
263 M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW);
264 }
265
266X509_CRL *X509_CRL_new(void)
267 {
268 X509_CRL *ret=NULL;
269 ASN1_CTX c;
270
271 M_ASN1_New_Malloc(ret,X509_CRL);
272 ret->references=1;
273 M_ASN1_New(ret->crl,X509_CRL_INFO_new);
274 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
275 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
276 return(ret);
277 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW);
278 }
279
280void X509_REVOKED_free(X509_REVOKED *a)
281 {
282 if (a == NULL) return;
283 M_ASN1_INTEGER_free(a->serialNumber);
284 M_ASN1_UTCTIME_free(a->revocationDate);
285 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
286 Free(a);
287 }
288
289void X509_CRL_INFO_free(X509_CRL_INFO *a)
290 {
291 if (a == NULL) return;
292 M_ASN1_INTEGER_free(a->version);
293 X509_ALGOR_free(a->sig_alg);
294 X509_NAME_free(a->issuer);
295 M_ASN1_UTCTIME_free(a->lastUpdate);
296 if (a->nextUpdate)
297 M_ASN1_UTCTIME_free(a->nextUpdate);
298 sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free);
299 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
300 Free(a);
301 }
302
303void X509_CRL_free(X509_CRL *a)
304 {
305 int i;
306
307 if (a == NULL) return;
308
309 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_CRL);
310#ifdef REF_PRINT
311 REF_PRINT("X509_CRL",a);
312#endif
313 if (i > 0) return;
314#ifdef REF_CHECK
315 if (i < 0)
316 {
317 fprintf(stderr,"X509_CRL_free, bad reference count\n");
318 abort();
319 }
320#endif
321
322 X509_CRL_INFO_free(a->crl);
323 X509_ALGOR_free(a->sig_alg);
324 M_ASN1_BIT_STRING_free(a->signature);
325 Free(a);
326 }
327
328static int X509_REVOKED_cmp(X509_REVOKED **a, X509_REVOKED **b)
329 {
330 return(ASN1_STRING_cmp(
331 (ASN1_STRING *)(*a)->serialNumber,
332 (ASN1_STRING *)(*b)->serialNumber));
333 }
334
335static int X509_REVOKED_seq_cmp(X509_REVOKED **a, X509_REVOKED **b)
336 {
337 return((*a)->sequence-(*b)->sequence);
338 }
339
340IMPLEMENT_STACK_OF(X509_REVOKED)
341IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
342IMPLEMENT_STACK_OF(X509_CRL)
343IMPLEMENT_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 185cbd78a0..0000000000
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ /dev/null
@@ -1,139 +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 ret->netscape_hack=0;
104 if ((c.slen != 0) &&
105 (M_ASN1_next == (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN)))
106 {
107 c.q=c.p;
108 if (d2i_ASN1_BOOLEAN(&i,&c.p,c.slen) < 0) goto err;
109 ret->critical=i;
110 c.slen-=(c.p-c.q);
111 if (ret->critical == 0) ret->netscape_hack=1;
112 }
113 M_ASN1_D2I_get(ret->value,d2i_ASN1_OCTET_STRING);
114
115 M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION);
116 }
117
118X509_EXTENSION *X509_EXTENSION_new(void)
119 {
120 X509_EXTENSION *ret=NULL;
121 ASN1_CTX c;
122
123 M_ASN1_New_Malloc(ret,X509_EXTENSION);
124 ret->object=OBJ_nid2obj(NID_undef);
125 M_ASN1_New(ret->value,M_ASN1_OCTET_STRING_new);
126 ret->critical=0;
127 ret->netscape_hack=0;
128 return(ret);
129 M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW);
130 }
131
132void X509_EXTENSION_free(X509_EXTENSION *a)
133 {
134 if (a == NULL) return;
135 ASN1_OBJECT_free(a->object);
136 M_ASN1_OCTET_STRING_free(a->value);
137 Free(a);
138 }
139
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
deleted file mode 100644
index 7fdc6f9dc8..0000000000
--- a/src/lib/libcrypto/asn1/x_info.c
+++ /dev/null
@@ -1,114 +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 if (x->enc_data != NULL) Free(x->enc_data);
110 Free(x);
111 }
112
113IMPLEMENT_STACK_OF(X509_INFO)
114
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
deleted file mode 100644
index 64baf5719d..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 M_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 fe58919dbb..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,M_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) M_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(x->key_data);
150 Free(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 7a05d575c9..0000000000
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ /dev/null
@@ -1,366 +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,M_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 M_ASN1_BIT_STRING_free(a->public_key);
114 if (a->pkey != NULL) EVP_PKEY_free(a->pkey);
115 Free(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 (!M_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#if 0
187 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
188 pk->pkey=pkey;
189#endif
190
191 if (*x != NULL)
192 X509_PUBKEY_free(*x);
193
194 *x=pk;
195 pk=NULL;
196
197 ok=1;
198err:
199 if (pk != NULL) X509_PUBKEY_free(pk);
200 return(ok);
201 }
202
203EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
204 {
205 EVP_PKEY *ret=NULL;
206 long j;
207 int type;
208 unsigned char *p;
209#ifndef NO_DSA
210 X509_ALGOR *a;
211#endif
212
213 if (key == NULL) goto err;
214
215 if (key->pkey != NULL)
216 {
217 CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
218 return(key->pkey);
219 }
220
221 if (key->public_key == NULL) goto err;
222
223 type=OBJ_obj2nid(key->algor->algorithm);
224 p=key->public_key->data;
225 j=key->public_key->length;
226 if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
227 {
228 X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
229 goto err;
230 }
231 ret->save_parameters=0;
232
233#ifndef NO_DSA
234 a=key->algor;
235 if (ret->type == EVP_PKEY_DSA)
236 {
237 if (a->parameter->type == V_ASN1_SEQUENCE)
238 {
239 ret->pkey.dsa->write_params=0;
240 p=a->parameter->value.sequence->data;
241 j=a->parameter->value.sequence->length;
242 if (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))
243 goto err;
244 }
245 ret->save_parameters=1;
246 }
247#endif
248 key->pkey=ret;
249 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
250 return(ret);
251err:
252 if (ret != NULL)
253 EVP_PKEY_free(ret);
254 return(NULL);
255 }
256
257/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
258 * and encode or decode as X509_PUBKEY
259 */
260
261EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
262 long length)
263{
264 X509_PUBKEY *xpk;
265 EVP_PKEY *pktmp;
266 xpk = d2i_X509_PUBKEY(NULL, pp, length);
267 if(!xpk) return NULL;
268 pktmp = X509_PUBKEY_get(xpk);
269 X509_PUBKEY_free(xpk);
270 if(!pktmp) return NULL;
271 if(a) {
272 EVP_PKEY_free(*a);
273 *a = pktmp;
274 }
275 return pktmp;
276}
277
278int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
279{
280 X509_PUBKEY *xpk=NULL;
281 int ret;
282 if(!a) return 0;
283 if(!X509_PUBKEY_set(&xpk, a)) return 0;
284 ret = i2d_X509_PUBKEY(xpk, pp);
285 X509_PUBKEY_free(xpk);
286 return ret;
287}
288
289/* The following are equivalents but which return RSA and DSA
290 * keys
291 */
292#ifndef NO_RSA
293RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
294 long length)
295{
296 EVP_PKEY *pkey;
297 RSA *key;
298 unsigned char *q;
299 q = *pp;
300 pkey = d2i_PUBKEY(NULL, &q, length);
301 if(!pkey) return NULL;
302 key = EVP_PKEY_get1_RSA(pkey);
303 EVP_PKEY_free(pkey);
304 if(!key) return NULL;
305 *pp = q;
306 if(a) {
307 RSA_free(*a);
308 *a = key;
309 }
310 return key;
311}
312
313int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
314{
315 EVP_PKEY *pktmp;
316 int ret;
317 if(!a) return 0;
318 pktmp = EVP_PKEY_new();
319 if(!pktmp) {
320 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
321 return 0;
322 }
323 EVP_PKEY_set1_RSA(pktmp, a);
324 ret = i2d_PUBKEY(pktmp, pp);
325 EVP_PKEY_free(pktmp);
326 return ret;
327}
328#endif
329
330#ifndef NO_DSA
331DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
332 long length)
333{
334 EVP_PKEY *pkey;
335 DSA *key;
336 unsigned char *q;
337 q = *pp;
338 pkey = d2i_PUBKEY(NULL, &q, length);
339 if(!pkey) return NULL;
340 key = EVP_PKEY_get1_DSA(pkey);
341 EVP_PKEY_free(pkey);
342 if(!key) return NULL;
343 *pp = q;
344 if(a) {
345 DSA_free(*a);
346 *a = key;
347 }
348 return key;
349}
350
351int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
352{
353 EVP_PKEY *pktmp;
354 int ret;
355 if(!a) return 0;
356 pktmp = EVP_PKEY_new();
357 if(!pktmp) {
358 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
359 return 0;
360 }
361 EVP_PKEY_set1_DSA(pktmp, a);
362 ret = i2d_PUBKEY(pktmp, pp);
363 EVP_PKEY_free(pktmp);
364 return ret;
365}
366#endif
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
deleted file mode 100644
index 0cd572ee73..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 Attributes
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 Attributes
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 Attributes
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,M_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 M_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(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,M_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 M_ASN1_BIT_STRING_free(a->signature);
233 Free(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 3559bd5368..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,M_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 M_ASN1_OCTET_STRING_free(a->digest);
107 Free(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 8f5e7e6380..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 permission
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,M_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 M_ASN1_IA5STRING_free(a->challenge);
112 Free(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,M_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 M_ASN1_BIT_STRING_free(a->signature);
164 Free(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 1a2f49ffdf..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,M_ASN1_TIME_new);
97 M_ASN1_New(ret->notAfter,M_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 M_ASN1_TIME_free(a->notBefore);
106 M_ASN1_TIME_free(a->notAfter);
107 Free(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 11e564ea30..0000000000
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ /dev/null
@@ -1,210 +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 int x509_meth_num = 0;
66static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_meth = NULL;
67
68static ASN1_METHOD meth={
69 (int (*)()) i2d_X509,
70 (char *(*)())d2i_X509,
71 (char *(*)())X509_new,
72 (void (*)()) X509_free};
73
74ASN1_METHOD *X509_asn1_meth(void)
75 {
76 return(&meth);
77 }
78
79int i2d_X509(X509 *a, unsigned char **pp)
80 {
81 M_ASN1_I2D_vars(a);
82
83 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
84 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
85 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
86
87 M_ASN1_I2D_seq_total();
88
89 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
90 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
91 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
92
93 M_ASN1_I2D_finish();
94 }
95
96X509 *d2i_X509(X509 **a, unsigned char **pp, long length)
97 {
98 M_ASN1_D2I_vars(a,X509 *,X509_new);
99
100 M_ASN1_D2I_Init();
101 M_ASN1_D2I_start_sequence();
102 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
103 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
104 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
105 if (ret->name != NULL) Free(ret->name);
106 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
107
108 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
109 }
110
111X509 *X509_new(void)
112 {
113 X509 *ret=NULL;
114 ASN1_CTX c;
115
116 M_ASN1_New_Malloc(ret,X509);
117 ret->references=1;
118 ret->valid=0;
119 ret->ex_flags = 0;
120 ret->name=NULL;
121 ret->aux=NULL;
122 M_ASN1_New(ret->cert_info,X509_CINF_new);
123 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
124 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
125 CRYPTO_new_ex_data(x509_meth, ret, &ret->ex_data);
126 return(ret);
127 M_ASN1_New_Error(ASN1_F_X509_NEW);
128 }
129
130void X509_free(X509 *a)
131 {
132 int i;
133
134 if (a == NULL) return;
135
136 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509);
137#ifdef REF_PRINT
138 REF_PRINT("X509",a);
139#endif
140 if (i > 0) return;
141#ifdef REF_CHECK
142 if (i < 0)
143 {
144 fprintf(stderr,"X509_free, bad reference count\n");
145 abort();
146 }
147#endif
148
149 CRYPTO_free_ex_data(x509_meth,a,&a->ex_data);
150 X509_CINF_free(a->cert_info);
151 X509_ALGOR_free(a->sig_alg);
152 M_ASN1_BIT_STRING_free(a->signature);
153 X509_CERT_AUX_free(a->aux);
154
155 if (a->name != NULL) Free(a->name);
156 Free(a);
157 }
158
159int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
160 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
161 {
162 x509_meth_num++;
163 return(CRYPTO_get_ex_new_index(x509_meth_num-1,
164 &x509_meth,argl,argp,new_func,dup_func,free_func));
165 }
166
167int X509_set_ex_data(X509 *r, int idx, void *arg)
168 {
169 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
170 }
171
172void *X509_get_ex_data(X509 *r, int idx)
173 {
174 return(CRYPTO_get_ex_data(&r->ex_data,idx));
175 }
176
177/* X509_AUX ASN1 routines. X509_AUX is the name given to
178 * a certificate with extra info tagged on the end. Since these
179 * functions set how a certificate is trusted they should only
180 * be used when the certificate comes from a reliable source
181 * such as local storage.
182 *
183 */
184
185X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length)
186{
187 unsigned char *q;
188 X509 *ret;
189 /* Save start position */
190 q = *pp;
191 ret = d2i_X509(a, pp, length);
192 /* If certificate unreadable then forget it */
193 if(!ret) return NULL;
194 /* update length */
195 length -= *pp - q;
196 if(!length) return ret;
197 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err;
198 return ret;
199 err:
200 X509_free(ret);
201 return NULL;
202}
203
204int i2d_X509_AUX(X509 *a, unsigned char **pp)
205{
206 int length;
207 length = i2d_X509(a, pp);
208 if(a) length += i2d_X509_CERT_AUX(a->aux, pp);
209 return length;
210}
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
deleted file mode 100644
index b9987ea968..0000000000
--- a/src/lib/libcrypto/asn1/x_x509a.c
+++ /dev/null
@@ -1,200 +0,0 @@
1/* a_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX routines. These are used to encode additional
66 * user modifiable data about a certificate. This data is
67 * appended to the X509 encoding when the *_X509_AUX routines
68 * are used. This means that the "traditional" X509 routines
69 * will simply ignore the extra data.
70 */
71
72static X509_CERT_AUX *aux_get(X509 *x);
73
74X509_CERT_AUX *d2i_X509_CERT_AUX(X509_CERT_AUX **a, unsigned char **pp, long length)
75{
76 M_ASN1_D2I_vars(a, X509_CERT_AUX *, X509_CERT_AUX_new);
77
78 M_ASN1_D2I_Init();
79 M_ASN1_D2I_start_sequence();
80
81 M_ASN1_D2I_get_seq_opt_type(ASN1_OBJECT, ret->trust,
82 d2i_ASN1_OBJECT, ASN1_OBJECT_free);
83 M_ASN1_D2I_get_IMP_set_opt_type(ASN1_OBJECT, ret->reject,
84 d2i_ASN1_OBJECT, ASN1_OBJECT_free, 0);
85 M_ASN1_D2I_get_opt(ret->alias, d2i_ASN1_UTF8STRING, V_ASN1_UTF8STRING);
86 M_ASN1_D2I_get_opt(ret->keyid, d2i_ASN1_OCTET_STRING, V_ASN1_OCTET_STRING);
87 M_ASN1_D2I_get_IMP_set_opt_type(X509_ALGOR, ret->other,
88 d2i_X509_ALGOR, X509_ALGOR_free, 1);
89
90 M_ASN1_D2I_Finish(a, X509_CERT_AUX_free, ASN1_F_D2I_X509_CERT_AUX);
91}
92
93X509_CERT_AUX *X509_CERT_AUX_new()
94{
95 X509_CERT_AUX *ret = NULL;
96 ASN1_CTX c;
97 M_ASN1_New_Malloc(ret, X509_CERT_AUX);
98 ret->trust = NULL;
99 ret->reject = NULL;
100 ret->alias = NULL;
101 ret->keyid = NULL;
102 ret->other = NULL;
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_CERT_AUX_NEW);
105}
106
107void X509_CERT_AUX_free(X509_CERT_AUX *a)
108{
109 if(a == NULL) return;
110 sk_ASN1_OBJECT_pop_free(a->trust, ASN1_OBJECT_free);
111 sk_ASN1_OBJECT_pop_free(a->reject, ASN1_OBJECT_free);
112 ASN1_UTF8STRING_free(a->alias);
113 ASN1_OCTET_STRING_free(a->keyid);
114 sk_X509_ALGOR_pop_free(a->other, X509_ALGOR_free);
115 Free(a);
116}
117
118int i2d_X509_CERT_AUX(X509_CERT_AUX *a, unsigned char **pp)
119{
120 M_ASN1_I2D_vars(a);
121
122 M_ASN1_I2D_len_SEQUENCE_opt_type(ASN1_OBJECT, a->trust, i2d_ASN1_OBJECT);
123 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->reject, i2d_ASN1_OBJECT, 0);
124
125 M_ASN1_I2D_len(a->alias, i2d_ASN1_UTF8STRING);
126 M_ASN1_I2D_len(a->keyid, i2d_ASN1_OCTET_STRING);
127 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(X509_ALGOR, a->other, i2d_X509_ALGOR, 1);
128
129 M_ASN1_I2D_seq_total();
130
131 M_ASN1_I2D_put_SEQUENCE_opt_type(ASN1_OBJECT, a->trust, i2d_ASN1_OBJECT);
132 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->reject, i2d_ASN1_OBJECT, 0);
133
134 M_ASN1_I2D_put(a->alias, i2d_ASN1_UTF8STRING);
135 M_ASN1_I2D_put(a->keyid, i2d_ASN1_OCTET_STRING);
136 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(X509_ALGOR, a->other, i2d_X509_ALGOR, 1);
137
138 M_ASN1_I2D_finish();
139}
140
141static X509_CERT_AUX *aux_get(X509 *x)
142{
143 if(!x) return NULL;
144 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL;
145 return x->aux;
146}
147
148int X509_alias_set1(X509 *x, unsigned char *name, int len)
149{
150 X509_CERT_AUX *aux;
151 if(!(aux = aux_get(x))) return 0;
152 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
153 return ASN1_STRING_set(aux->alias, name, len);
154}
155
156unsigned char *X509_alias_get0(X509 *x, int *len)
157{
158 if(!x->aux || !x->aux->alias) return NULL;
159 if(len) *len = x->aux->alias->length;
160 return x->aux->alias->data;
161}
162
163int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
164{
165 X509_CERT_AUX *aux;
166 ASN1_OBJECT *objtmp;
167 if(!(objtmp = OBJ_dup(obj))) return 0;
168 if(!(aux = aux_get(x))) return 0;
169 if(!aux->trust
170 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0;
171 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
172}
173
174int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
175{
176 X509_CERT_AUX *aux;
177 ASN1_OBJECT *objtmp;
178 if(!(objtmp = OBJ_dup(obj))) return 0;
179 if(!(aux = aux_get(x))) return 0;
180 if(!aux->reject
181 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0;
182 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
183}
184
185void X509_trust_clear(X509 *x)
186{
187 if(x->aux && x->aux->trust) {
188 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
189 x->aux->trust = NULL;
190 }
191}
192
193void X509_reject_clear(X509 *x)
194{
195 if(x->aux && x->aux->reject) {
196 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
197 x->aux->reject = NULL;
198 }
199}
200
diff --git a/src/lib/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 f949629dc6..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(const unsigned char *in, unsigned char *out, long length,
63 const BF_KEY *schedule, unsigned char *ivec, 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(ivec,tout0);
73 n2l(ivec,tout1);
74 ivec-=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,schedule);
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,schedule);
97 tout0=tin[0];
98 tout1=tin[1];
99 l2n(tout0,out);
100 l2n(tout1,out);
101 }
102 l2n(tout0,ivec);
103 l2n(tout1,ivec);
104 }
105 else
106 {
107 n2l(ivec,xor0);
108 n2l(ivec,xor1);
109 ivec-=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,schedule);
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,schedule);
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,ivec);
138 l2n(xor1,ivec);
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 6451c8d407..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(const unsigned char *in, unsigned char *out, long length,
68 const 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 341991636f..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 COMPUTER 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(const unsigned char *in, unsigned char *out,
82 const BF_KEY *key, 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,key);
90 else
91 BF_decrypt(d,key);
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 b380acf959..0000000000
--- a/src/lib/libcrypto/bf/bf_enc.c
+++ /dev/null
@@ -1,306 +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 COMPUTER 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, const BF_KEY *key)
73 {
74#ifndef BF_PTR2
75 register BF_LONG l,r;
76 const register BF_LONG *p,*s;
77
78 p=key->P;
79 s= &(key->S[0]);
80 l=data[0];
81 r=data[1];
82
83 l^=p[0];
84 BF_ENC(r,l,s,p[ 1]);
85 BF_ENC(l,r,s,p[ 2]);
86 BF_ENC(r,l,s,p[ 3]);
87 BF_ENC(l,r,s,p[ 4]);
88 BF_ENC(r,l,s,p[ 5]);
89 BF_ENC(l,r,s,p[ 6]);
90 BF_ENC(r,l,s,p[ 7]);
91 BF_ENC(l,r,s,p[ 8]);
92 BF_ENC(r,l,s,p[ 9]);
93 BF_ENC(l,r,s,p[10]);
94 BF_ENC(r,l,s,p[11]);
95 BF_ENC(l,r,s,p[12]);
96 BF_ENC(r,l,s,p[13]);
97 BF_ENC(l,r,s,p[14]);
98 BF_ENC(r,l,s,p[15]);
99 BF_ENC(l,r,s,p[16]);
100#if BF_ROUNDS == 20
101 BF_ENC(r,l,s,p[17]);
102 BF_ENC(l,r,s,p[18]);
103 BF_ENC(r,l,s,p[19]);
104 BF_ENC(l,r,s,p[20]);
105#endif
106 r^=p[BF_ROUNDS+1];
107
108 data[1]=l&0xffffffffL;
109 data[0]=r&0xffffffffL;
110#else
111 register BF_LONG l,r,t,*k;
112
113 l=data[0];
114 r=data[1];
115 k=(BF_LONG*)key;
116
117 l^=k[0];
118 BF_ENC(r,l,k, 1);
119 BF_ENC(l,r,k, 2);
120 BF_ENC(r,l,k, 3);
121 BF_ENC(l,r,k, 4);
122 BF_ENC(r,l,k, 5);
123 BF_ENC(l,r,k, 6);
124 BF_ENC(r,l,k, 7);
125 BF_ENC(l,r,k, 8);
126 BF_ENC(r,l,k, 9);
127 BF_ENC(l,r,k,10);
128 BF_ENC(r,l,k,11);
129 BF_ENC(l,r,k,12);
130 BF_ENC(r,l,k,13);
131 BF_ENC(l,r,k,14);
132 BF_ENC(r,l,k,15);
133 BF_ENC(l,r,k,16);
134#if BF_ROUNDS == 20
135 BF_ENC(r,l,k,17);
136 BF_ENC(l,r,k,18);
137 BF_ENC(r,l,k,19);
138 BF_ENC(l,r,k,20);
139#endif
140 r^=k[BF_ROUNDS+1];
141
142 data[1]=l&0xffffffffL;
143 data[0]=r&0xffffffffL;
144#endif
145 }
146
147#ifndef BF_DEFAULT_OPTIONS
148
149void BF_decrypt(BF_LONG *data, const BF_KEY *key)
150 {
151#ifndef BF_PTR2
152 register BF_LONG l,r;
153 const register BF_LONG *p,*s;
154
155 p=key->P;
156 s= &(key->S[0]);
157 l=data[0];
158 r=data[1];
159
160 l^=p[BF_ROUNDS+1];
161#if BF_ROUNDS == 20
162 BF_ENC(r,l,s,p[20]);
163 BF_ENC(l,r,s,p[19]);
164 BF_ENC(r,l,s,p[18]);
165 BF_ENC(l,r,s,p[17]);
166#endif
167 BF_ENC(r,l,s,p[16]);
168 BF_ENC(l,r,s,p[15]);
169 BF_ENC(r,l,s,p[14]);
170 BF_ENC(l,r,s,p[13]);
171 BF_ENC(r,l,s,p[12]);
172 BF_ENC(l,r,s,p[11]);
173 BF_ENC(r,l,s,p[10]);
174 BF_ENC(l,r,s,p[ 9]);
175 BF_ENC(r,l,s,p[ 8]);
176 BF_ENC(l,r,s,p[ 7]);
177 BF_ENC(r,l,s,p[ 6]);
178 BF_ENC(l,r,s,p[ 5]);
179 BF_ENC(r,l,s,p[ 4]);
180 BF_ENC(l,r,s,p[ 3]);
181 BF_ENC(r,l,s,p[ 2]);
182 BF_ENC(l,r,s,p[ 1]);
183 r^=p[0];
184
185 data[1]=l&0xffffffffL;
186 data[0]=r&0xffffffffL;
187#else
188 register BF_LONG l,r,t,*k;
189
190 l=data[0];
191 r=data[1];
192 k=(BF_LONG *)key;
193
194 l^=k[BF_ROUNDS+1];
195#if BF_ROUNDS == 20
196 BF_ENC(r,l,k,20);
197 BF_ENC(l,r,k,19);
198 BF_ENC(r,l,k,18);
199 BF_ENC(l,r,k,17);
200#endif
201 BF_ENC(r,l,k,16);
202 BF_ENC(l,r,k,15);
203 BF_ENC(r,l,k,14);
204 BF_ENC(l,r,k,13);
205 BF_ENC(r,l,k,12);
206 BF_ENC(l,r,k,11);
207 BF_ENC(r,l,k,10);
208 BF_ENC(l,r,k, 9);
209 BF_ENC(r,l,k, 8);
210 BF_ENC(l,r,k, 7);
211 BF_ENC(r,l,k, 6);
212 BF_ENC(l,r,k, 5);
213 BF_ENC(r,l,k, 4);
214 BF_ENC(l,r,k, 3);
215 BF_ENC(r,l,k, 2);
216 BF_ENC(l,r,k, 1);
217 r^=k[0];
218
219 data[1]=l&0xffffffffL;
220 data[0]=r&0xffffffffL;
221#endif
222 }
223
224void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
225 const BF_KEY *schedule, unsigned char *ivec, int encrypt)
226 {
227 register BF_LONG tin0,tin1;
228 register BF_LONG tout0,tout1,xor0,xor1;
229 register long l=length;
230 BF_LONG tin[2];
231
232 if (encrypt)
233 {
234 n2l(ivec,tout0);
235 n2l(ivec,tout1);
236 ivec-=8;
237 for (l-=8; l>=0; l-=8)
238 {
239 n2l(in,tin0);
240 n2l(in,tin1);
241 tin0^=tout0;
242 tin1^=tout1;
243 tin[0]=tin0;
244 tin[1]=tin1;
245 BF_encrypt(tin,schedule);
246 tout0=tin[0];
247 tout1=tin[1];
248 l2n(tout0,out);
249 l2n(tout1,out);
250 }
251 if (l != -8)
252 {
253 n2ln(in,tin0,tin1,l+8);
254 tin0^=tout0;
255 tin1^=tout1;
256 tin[0]=tin0;
257 tin[1]=tin1;
258 BF_encrypt(tin,schedule);
259 tout0=tin[0];
260 tout1=tin[1];
261 l2n(tout0,out);
262 l2n(tout1,out);
263 }
264 l2n(tout0,ivec);
265 l2n(tout1,ivec);
266 }
267 else
268 {
269 n2l(ivec,xor0);
270 n2l(ivec,xor1);
271 ivec-=8;
272 for (l-=8; l>=0; l-=8)
273 {
274 n2l(in,tin0);
275 n2l(in,tin1);
276 tin[0]=tin0;
277 tin[1]=tin1;
278 BF_decrypt(tin,schedule);
279 tout0=tin[0]^xor0;
280 tout1=tin[1]^xor1;
281 l2n(tout0,out);
282 l2n(tout1,out);
283 xor0=tin0;
284 xor1=tin1;
285 }
286 if (l != -8)
287 {
288 n2l(in,tin0);
289 n2l(in,tin1);
290 tin[0]=tin0;
291 tin[1]=tin1;
292 BF_decrypt(tin,schedule);
293 tout0=tin[0]^xor0;
294 tout1=tin[1]^xor1;
295 l2nn(tout0,tout1,out,l+8);
296 xor0=tin0;
297 xor1=tin1;
298 }
299 l2n(xor0,ivec);
300 l2n(xor1,ivec);
301 }
302 tin0=tin1=tout0=tout1=xor0=xor1=0;
303 tin[0]=tin[1]=0;
304 }
305
306#endif
diff --git a/src/lib/libcrypto/bf/bf_locl.h b/src/lib/libcrypto/bf/bf_locl.h
deleted file mode 100644
index cc7c3ec992..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 significant 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 explicitly "multiply" array index by sizeof(BF_LONG)
187 * in order to calculate 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 f2a9ff6e41..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(const unsigned char *in, unsigned char *out, long length,
67 const 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 9949513c68..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 const 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 4d6a232fe0..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, const unsigned char *data)
66 {
67 int i;
68 BF_LONG *p,ri,in[2];
69 const 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 78acfd63b4..0000000000
--- a/src/lib/libcrypto/bf/blowfish.h
+++ /dev/null
@@ -1,125 +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, const unsigned char *data);
107
108void BF_encrypt(BF_LONG *data,const BF_KEY *key);
109void BF_decrypt(BF_LONG *data,const BF_KEY *key);
110
111void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
112 const BF_KEY *key, int enc);
113void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
114 const BF_KEY *schedule, unsigned char *ivec, int enc);
115void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
116 const BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
117void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
118 const BF_KEY *schedule, unsigned char *ivec, int *num);
119const char *BF_options(void);
120
121#ifdef __cplusplus
122}
123#endif
124
125#endif
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
deleted file mode 100644
index f5aeb237f5..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)*(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)*(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 b11b501512..0000000000
--- a/src/lib/libcrypto/bio/b_print.c
+++ /dev/null
@@ -1,844 +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 <string.h>
66#include <ctype.h>
67#include <assert.h>
68#include <limits.h>
69#include "cryptlib.h"
70#ifndef NO_SYS_TYPES_H
71#include <sys/types.h>
72#endif
73#include <openssl/bio.h>
74
75#ifdef BN_LLONG
76# ifndef HAVE_LONG_LONG
77# define HAVE_LONG_LONG 1
78# endif
79#endif
80
81static void dopr (char *buffer, size_t maxlen, size_t *retlen,
82 const char *format, va_list args);
83#ifdef USE_ALLOCATING_PRINT
84static void doapr (char **buffer, size_t *retlen,
85 const char *format, va_list args);
86#endif
87
88int BIO_printf (BIO *bio, ...)
89 {
90 va_list args;
91 char *format;
92 int ret;
93 size_t retlen;
94#ifdef USE_ALLOCATING_PRINT
95 char *hugebuf;
96#else
97 MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */
98#endif
99
100 va_start(args, bio);
101 format=va_arg(args, char *);
102
103#ifndef USE_ALLOCATING_PRINT
104 hugebuf[0]='\0';
105 dopr(hugebuf, sizeof(hugebuf), &retlen, format, args);
106#else
107 hugebuf = NULL;
108 CRYPTO_push_info("doapr()");
109 doapr(&hugebuf, &retlen, format, args);
110 if (hugebuf)
111 {
112#endif
113 ret=BIO_write(bio, hugebuf, (int)retlen);
114
115#ifdef USE_ALLOCATING_PRINT
116 Free(hugebuf);
117 }
118 CRYPTO_pop_info();
119#endif
120 va_end(args);
121 return(ret);
122 }
123
124/*
125 * Copyright Patrick Powell 1995
126 * This code is based on code written by Patrick Powell <papowell@astart.com>
127 * It may be used for any purpose as long as this notice remains intact
128 * on all source code distributions.
129 */
130
131/*
132 * This code contains numerious changes and enhancements which were
133 * made by lots of contributors over the last years to Patrick Powell's
134 * original code:
135 *
136 * o Patrick Powell <papowell@astart.com> (1995)
137 * o Brandon Long <blong@fiction.net> (1996, for Mutt)
138 * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)
139 * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)
140 * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
141 * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
142 * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)
143 */
144
145#if HAVE_LONG_DOUBLE
146#define LDOUBLE long double
147#else
148#define LDOUBLE double
149#endif
150
151#if HAVE_LONG_LONG
152#define LLONG long long
153#else
154#define LLONG long
155#endif
156
157static void fmtstr (void (*)(char **, size_t *, size_t *, int),
158 char **, size_t *, size_t *, const char *, int, int,
159 int);
160static void fmtint (void (*)(char **, size_t *, size_t *, int),
161 char **, size_t *, size_t *, LLONG, int, int, int, int);
162static void fmtfp (void (*)(char **, size_t *, size_t *, int),
163 char **, size_t *, size_t *, LDOUBLE, int, int, int);
164#ifndef USE_ALLOCATING_PRINT
165static int dopr_isbig (size_t, size_t);
166static int dopr_copy (size_t);
167static void dopr_outch (char **, size_t *, size_t *, int);
168#else
169static int doapr_isbig (size_t, size_t);
170static int doapr_copy (size_t);
171static void doapr_outch (char **, size_t *, size_t *, int);
172#endif
173static void _dopr(void (*)(char **, size_t *, size_t *, int),
174 int (*)(size_t, size_t), int (*)(size_t),
175 char **buffer, size_t *maxlen, size_t *retlen,
176 const char *format, va_list args);
177
178/* format read states */
179#define DP_S_DEFAULT 0
180#define DP_S_FLAGS 1
181#define DP_S_MIN 2
182#define DP_S_DOT 3
183#define DP_S_MAX 4
184#define DP_S_MOD 5
185#define DP_S_CONV 6
186#define DP_S_DONE 7
187
188/* format flags - Bits */
189#define DP_F_MINUS (1 << 0)
190#define DP_F_PLUS (1 << 1)
191#define DP_F_SPACE (1 << 2)
192#define DP_F_NUM (1 << 3)
193#define DP_F_ZERO (1 << 4)
194#define DP_F_UP (1 << 5)
195#define DP_F_UNSIGNED (1 << 6)
196
197/* conversion flags */
198#define DP_C_SHORT 1
199#define DP_C_LONG 2
200#define DP_C_LDOUBLE 3
201#define DP_C_LLONG 4
202
203/* some handy macros */
204#define char_to_int(p) (p - '0')
205#define MAX(p,q) ((p >= q) ? p : q)
206
207#ifndef USE_ALLOCATING_PRINT
208static void
209dopr(
210 char *buffer,
211 size_t maxlen,
212 size_t *retlen,
213 const char *format,
214 va_list args)
215{
216 _dopr(dopr_outch, dopr_isbig, dopr_copy,
217 &buffer, &maxlen, retlen, format, args);
218}
219
220#else
221static void
222doapr(
223 char **buffer,
224 size_t *retlen,
225 const char *format,
226 va_list args)
227{
228 size_t dummy_maxlen = 0;
229 _dopr(doapr_outch, doapr_isbig, doapr_copy,
230 buffer, &dummy_maxlen, retlen, format, args);
231}
232#endif
233
234static void
235_dopr(
236 void (*outch_fn)(char **, size_t *, size_t *, int),
237 int (*isbig_fn)(size_t, size_t),
238 int (*copy_fn)(size_t),
239 char **buffer,
240 size_t *maxlen,
241 size_t *retlen,
242 const char *format,
243 va_list args)
244{
245 char ch;
246 LLONG value;
247 LDOUBLE fvalue;
248 char *strvalue;
249 int min;
250 int max;
251 int state;
252 int flags;
253 int cflags;
254 size_t currlen;
255
256 state = DP_S_DEFAULT;
257 flags = currlen = cflags = min = 0;
258 max = -1;
259 ch = *format++;
260
261 while (state != DP_S_DONE) {
262 if ((ch == '\0') || (*isbig_fn)(currlen, *maxlen))
263 state = DP_S_DONE;
264
265 switch (state) {
266 case DP_S_DEFAULT:
267 if (ch == '%')
268 state = DP_S_FLAGS;
269 else
270 (*outch_fn)(buffer, &currlen, maxlen, ch);
271 ch = *format++;
272 break;
273 case DP_S_FLAGS:
274 switch (ch) {
275 case '-':
276 flags |= DP_F_MINUS;
277 ch = *format++;
278 break;
279 case '+':
280 flags |= DP_F_PLUS;
281 ch = *format++;
282 break;
283 case ' ':
284 flags |= DP_F_SPACE;
285 ch = *format++;
286 break;
287 case '#':
288 flags |= DP_F_NUM;
289 ch = *format++;
290 break;
291 case '0':
292 flags |= DP_F_ZERO;
293 ch = *format++;
294 break;
295 default:
296 state = DP_S_MIN;
297 break;
298 }
299 break;
300 case DP_S_MIN:
301 if (isdigit((unsigned char)ch)) {
302 min = 10 * min + char_to_int(ch);
303 ch = *format++;
304 } else if (ch == '*') {
305 min = va_arg(args, int);
306 ch = *format++;
307 state = DP_S_DOT;
308 } else
309 state = DP_S_DOT;
310 break;
311 case DP_S_DOT:
312 if (ch == '.') {
313 state = DP_S_MAX;
314 ch = *format++;
315 } else
316 state = DP_S_MOD;
317 break;
318 case DP_S_MAX:
319 if (isdigit((unsigned char)ch)) {
320 if (max < 0)
321 max = 0;
322 max = 10 * max + char_to_int(ch);
323 ch = *format++;
324 } else if (ch == '*') {
325 max = va_arg(args, int);
326 ch = *format++;
327 state = DP_S_MOD;
328 } else
329 state = DP_S_MOD;
330 break;
331 case DP_S_MOD:
332 switch (ch) {
333 case 'h':
334 cflags = DP_C_SHORT;
335 ch = *format++;
336 break;
337 case 'l':
338 if (*format == 'l') {
339 cflags = DP_C_LLONG;
340 format++;
341 } else
342 cflags = DP_C_LONG;
343 ch = *format++;
344 break;
345 case 'q':
346 cflags = DP_C_LLONG;
347 ch = *format++;
348 break;
349 case 'L':
350 cflags = DP_C_LDOUBLE;
351 ch = *format++;
352 break;
353 default:
354 break;
355 }
356 state = DP_S_CONV;
357 break;
358 case DP_S_CONV:
359 switch (ch) {
360 case 'd':
361 case 'i':
362 switch (cflags) {
363 case DP_C_SHORT:
364 value = (short int)va_arg(args, int);
365 break;
366 case DP_C_LONG:
367 value = va_arg(args, long int);
368 break;
369 case DP_C_LLONG:
370 value = va_arg(args, LLONG);
371 break;
372 default:
373 value = va_arg(args, int);
374 break;
375 }
376 fmtint(outch_fn, buffer, &currlen, maxlen,
377 value, 10, min, max, flags);
378 break;
379 case 'X':
380 flags |= DP_F_UP;
381 /* FALLTHROUGH */
382 case 'x':
383 case 'o':
384 case 'u':
385 flags |= DP_F_UNSIGNED;
386 switch (cflags) {
387 case DP_C_SHORT:
388 value = (unsigned short int)va_arg(args, unsigned int);
389 break;
390 case DP_C_LONG:
391 value = (LLONG) va_arg(args,
392 unsigned long int);
393 break;
394 case DP_C_LLONG:
395 value = va_arg(args, unsigned LLONG);
396 break;
397 default:
398 value = (LLONG) va_arg(args,
399 unsigned int);
400 break;
401 }
402 fmtint(outch_fn, buffer, &currlen, maxlen, value,
403 ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
404 min, max, flags);
405 break;
406 case 'f':
407 if (cflags == DP_C_LDOUBLE)
408 fvalue = va_arg(args, LDOUBLE);
409 else
410 fvalue = va_arg(args, double);
411 fmtfp(outch_fn, buffer, &currlen, maxlen,
412 fvalue, min, max, flags);
413 break;
414 case 'E':
415 flags |= DP_F_UP;
416 case 'e':
417 if (cflags == DP_C_LDOUBLE)
418 fvalue = va_arg(args, LDOUBLE);
419 else
420 fvalue = va_arg(args, double);
421 break;
422 case 'G':
423 flags |= DP_F_UP;
424 case 'g':
425 if (cflags == DP_C_LDOUBLE)
426 fvalue = va_arg(args, LDOUBLE);
427 else
428 fvalue = va_arg(args, double);
429 break;
430 case 'c':
431 (*outch_fn)(buffer, &currlen, maxlen,
432 va_arg(args, int));
433 break;
434 case 's':
435 strvalue = va_arg(args, char *);
436 if (max < 0)
437 max = (*copy_fn)(*maxlen);
438 fmtstr(outch_fn, buffer, &currlen, maxlen, strvalue,
439 flags, min, max);
440 break;
441 case 'p':
442 value = (long)va_arg(args, void *);
443 fmtint(outch_fn, buffer, &currlen, maxlen,
444 value, 16, min, max, flags);
445 break;
446 case 'n': /* XXX */
447 if (cflags == DP_C_SHORT) {
448 short int *num;
449 num = va_arg(args, short int *);
450 *num = currlen;
451 } else if (cflags == DP_C_LONG) { /* XXX */
452 long int *num;
453 num = va_arg(args, long int *);
454 *num = (long int) currlen;
455 } else if (cflags == DP_C_LLONG) { /* XXX */
456 LLONG *num;
457 num = va_arg(args, LLONG *);
458 *num = (LLONG) currlen;
459 } else {
460 int *num;
461 num = va_arg(args, int *);
462 *num = currlen;
463 }
464 break;
465 case '%':
466 (*outch_fn)(buffer, &currlen, maxlen, ch);
467 break;
468 case 'w':
469 /* not supported yet, treat as next char */
470 ch = *format++;
471 break;
472 default:
473 /* unknown, skip */
474 break;
475 }
476 ch = *format++;
477 state = DP_S_DEFAULT;
478 flags = cflags = min = 0;
479 max = -1;
480 break;
481 case DP_S_DONE:
482 break;
483 default:
484 break;
485 }
486 }
487 if (currlen >= *maxlen - 1)
488 currlen = *maxlen - 1;
489 (*buffer)[currlen] = '\0';
490 *retlen = currlen;
491 return;
492}
493
494static void
495fmtstr(
496 void (*outch_fn)(char **, size_t *, size_t *, int),
497 char **buffer,
498 size_t *currlen,
499 size_t *maxlen,
500 const char *value,
501 int flags,
502 int min,
503 int max)
504{
505 int padlen, strln;
506 int cnt = 0;
507
508 if (value == 0)
509 value = "<NULL>";
510 for (strln = 0; value[strln]; ++strln)
511 ;
512 padlen = min - strln;
513 if (padlen < 0)
514 padlen = 0;
515 if (flags & DP_F_MINUS)
516 padlen = -padlen;
517
518 while ((padlen > 0) && (cnt < max)) {
519 (*outch_fn)(buffer, currlen, maxlen, ' ');
520 --padlen;
521 ++cnt;
522 }
523 while (*value && (cnt < max)) {
524 (*outch_fn)(buffer, currlen, maxlen, *value++);
525 ++cnt;
526 }
527 while ((padlen < 0) && (cnt < max)) {
528 (*outch_fn)(buffer, currlen, maxlen, ' ');
529 ++padlen;
530 ++cnt;
531 }
532}
533
534static void
535fmtint(
536 void (*outch_fn)(char **, size_t *, size_t *, int),
537 char **buffer,
538 size_t *currlen,
539 size_t *maxlen,
540 LLONG value,
541 int base,
542 int min,
543 int max,
544 int flags)
545{
546 int signvalue = 0;
547 unsigned LLONG uvalue;
548 char convert[20];
549 int place = 0;
550 int spadlen = 0;
551 int zpadlen = 0;
552 int caps = 0;
553
554 if (max < 0)
555 max = 0;
556 uvalue = value;
557 if (!(flags & DP_F_UNSIGNED)) {
558 if (value < 0) {
559 signvalue = '-';
560 uvalue = -value;
561 } else if (flags & DP_F_PLUS)
562 signvalue = '+';
563 else if (flags & DP_F_SPACE)
564 signvalue = ' ';
565 }
566 if (flags & DP_F_UP)
567 caps = 1;
568 do {
569 convert[place++] =
570 (caps ? "0123456789ABCDEF" : "0123456789abcdef")
571 [uvalue % (unsigned) base];
572 uvalue = (uvalue / (unsigned) base);
573 } while (uvalue && (place < 20));
574 if (place == 20)
575 place--;
576 convert[place] = 0;
577
578 zpadlen = max - place;
579 spadlen = min - MAX(max, place) - (signvalue ? 1 : 0);
580 if (zpadlen < 0)
581 zpadlen = 0;
582 if (spadlen < 0)
583 spadlen = 0;
584 if (flags & DP_F_ZERO) {
585 zpadlen = MAX(zpadlen, spadlen);
586 spadlen = 0;
587 }
588 if (flags & DP_F_MINUS)
589 spadlen = -spadlen;
590
591 /* spaces */
592 while (spadlen > 0) {
593 (*outch_fn)(buffer, currlen, maxlen, ' ');
594 --spadlen;
595 }
596
597 /* sign */
598 if (signvalue)
599 (*outch_fn)(buffer, currlen, maxlen, signvalue);
600
601 /* zeros */
602 if (zpadlen > 0) {
603 while (zpadlen > 0) {
604 (*outch_fn)(buffer, currlen, maxlen, '0');
605 --zpadlen;
606 }
607 }
608 /* digits */
609 while (place > 0)
610 (*outch_fn)(buffer, currlen, maxlen, convert[--place]);
611
612 /* left justified spaces */
613 while (spadlen < 0) {
614 (*outch_fn)(buffer, currlen, maxlen, ' ');
615 ++spadlen;
616 }
617 return;
618}
619
620static LDOUBLE
621abs_val(LDOUBLE value)
622{
623 LDOUBLE result = value;
624 if (value < 0)
625 result = -value;
626 return result;
627}
628
629static LDOUBLE
630pow10(int exp)
631{
632 LDOUBLE result = 1;
633 while (exp) {
634 result *= 10;
635 exp--;
636 }
637 return result;
638}
639
640static long
641round(LDOUBLE value)
642{
643 long intpart;
644 intpart = (long) value;
645 value = value - intpart;
646 if (value >= 0.5)
647 intpart++;
648 return intpart;
649}
650
651static void
652fmtfp(
653 void (*outch_fn)(char **, size_t *, size_t *, int),
654 char **buffer,
655 size_t *currlen,
656 size_t *maxlen,
657 LDOUBLE fvalue,
658 int min,
659 int max,
660 int flags)
661{
662 int signvalue = 0;
663 LDOUBLE ufvalue;
664 char iconvert[20];
665 char fconvert[20];
666 int iplace = 0;
667 int fplace = 0;
668 int padlen = 0;
669 int zpadlen = 0;
670 int caps = 0;
671 long intpart;
672 long fracpart;
673
674 if (max < 0)
675 max = 6;
676 ufvalue = abs_val(fvalue);
677 if (fvalue < 0)
678 signvalue = '-';
679 else if (flags & DP_F_PLUS)
680 signvalue = '+';
681 else if (flags & DP_F_SPACE)
682 signvalue = ' ';
683
684 intpart = (long)ufvalue;
685
686 /* sorry, we only support 9 digits past the decimal because of our
687 conversion method */
688 if (max > 9)
689 max = 9;
690
691 /* we "cheat" by converting the fractional part to integer by
692 multiplying by a factor of 10 */
693 fracpart = round((pow10(max)) * (ufvalue - intpart));
694
695 if (fracpart >= pow10(max)) {
696 intpart++;
697 fracpart -= (long)pow10(max);
698 }
699
700 /* convert integer part */
701 do {
702 iconvert[iplace++] =
703 (caps ? "0123456789ABCDEF"
704 : "0123456789abcdef")[intpart % 10];
705 intpart = (intpart / 10);
706 } while (intpart && (iplace < 20));
707 if (iplace == 20)
708 iplace--;
709 iconvert[iplace] = 0;
710
711 /* convert fractional part */
712 do {
713 fconvert[fplace++] =
714 (caps ? "0123456789ABCDEF"
715 : "0123456789abcdef")[fracpart % 10];
716 fracpart = (fracpart / 10);
717 } while (fracpart && (fplace < 20));
718 if (fplace == 20)
719 fplace--;
720 fconvert[fplace] = 0;
721
722 /* -1 for decimal point, another -1 if we are printing a sign */
723 padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
724 zpadlen = max - fplace;
725 if (zpadlen < 0)
726 zpadlen = 0;
727 if (padlen < 0)
728 padlen = 0;
729 if (flags & DP_F_MINUS)
730 padlen = -padlen;
731
732 if ((flags & DP_F_ZERO) && (padlen > 0)) {
733 if (signvalue) {
734 (*outch_fn)(buffer, currlen, maxlen, signvalue);
735 --padlen;
736 signvalue = 0;
737 }
738 while (padlen > 0) {
739 (*outch_fn)(buffer, currlen, maxlen, '0');
740 --padlen;
741 }
742 }
743 while (padlen > 0) {
744 (*outch_fn)(buffer, currlen, maxlen, ' ');
745 --padlen;
746 }
747 if (signvalue)
748 (*outch_fn)(buffer, currlen, maxlen, signvalue);
749
750 while (iplace > 0)
751 (*outch_fn)(buffer, currlen, maxlen, iconvert[--iplace]);
752
753 /*
754 * Decimal point. This should probably use locale to find the correct
755 * char to print out.
756 */
757 if (max > 0) {
758 (*outch_fn)(buffer, currlen, maxlen, '.');
759
760 while (fplace > 0)
761 (*outch_fn)(buffer, currlen, maxlen, fconvert[--fplace]);
762 }
763 while (zpadlen > 0) {
764 (*outch_fn)(buffer, currlen, maxlen, '0');
765 --zpadlen;
766 }
767
768 while (padlen < 0) {
769 (*outch_fn)(buffer, currlen, maxlen, ' ');
770 ++padlen;
771 }
772}
773
774static int
775dopr_copy(
776 size_t len)
777{
778 return len;
779}
780
781#ifdef USE_ALLOCATING_PRINT
782static int
783doapr_copy(
784 size_t len)
785{
786 /* Return as high an integer as possible */
787 return INT_MAX;
788}
789#endif
790
791static int
792dopr_isbig(
793 size_t currlen,
794 size_t maxlen)
795{
796 return currlen > maxlen;
797}
798
799#ifdef USE_ALLOCATING_PRINT
800static int
801doapr_isbig(
802 size_t currlen,
803 size_t maxlen)
804{
805 return 0;
806}
807#endif
808
809static void
810dopr_outch(
811 char **buffer,
812 size_t *currlen,
813 size_t *maxlen,
814 int c)
815{
816 if (*currlen < *maxlen)
817 (*buffer)[(*currlen)++] = (char)c;
818 return;
819}
820
821#ifdef USE_ALLOCATING_PRINT
822static void
823doapr_outch(
824 char **buffer,
825 size_t *currlen,
826 size_t *maxlen,
827 int c)
828{
829 if (*buffer == NULL) {
830 if (*maxlen == 0)
831 *maxlen = 1024;
832 *buffer = Malloc(*maxlen);
833 }
834 while (*currlen >= *maxlen) {
835 *maxlen += 1024;
836 *buffer = Realloc(*buffer, *maxlen);
837 }
838 /* What to do if *buffer is NULL? */
839 assert(*buffer != NULL);
840
841 (*buffer)[(*currlen)++] = (char)c;
842 return;
843}
844#endif
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
deleted file mode 100644
index 6409f98f57..0000000000
--- a/src/lib/libcrypto/bio/b_sock.c
+++ /dev/null
@@ -1,717 +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 /* Note: under VMS with SOCKETSHR, it seems like the first
167 * parameter is 'char *', instead of 'const char *'
168 */
169 s=getservbyname(
170#ifndef CONST_STRICT
171 (char *)
172#endif
173 str,"tcp");
174 if(s != NULL)
175 *port_ptr=ntohs((unsigned short)s->s_port);
176 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
177 if(s == NULL)
178 {
179 if (strcmp(str,"http") == 0)
180 *port_ptr=80;
181 else if (strcmp(str,"telnet") == 0)
182 *port_ptr=23;
183 else if (strcmp(str,"socks") == 0)
184 *port_ptr=1080;
185 else if (strcmp(str,"https") == 0)
186 *port_ptr=443;
187 else if (strcmp(str,"ssl") == 0)
188 *port_ptr=443;
189 else if (strcmp(str,"ftp") == 0)
190 *port_ptr=21;
191 else if (strcmp(str,"gopher") == 0)
192 *port_ptr=70;
193#if 0
194 else if (strcmp(str,"wais") == 0)
195 *port_ptr=21;
196#endif
197 else
198 {
199 SYSerr(SYS_F_GETSERVBYNAME,get_last_socket_error());
200 ERR_add_error_data(3,"service='",str,"'");
201 return(0);
202 }
203 }
204 }
205 return(1);
206 }
207
208int BIO_sock_error(int sock)
209 {
210 int j,i;
211 int size;
212
213 size=sizeof(int);
214 /* Note: under Windows the third parameter is of type (char *)
215 * whereas under other systems it is (void *) if you don't have
216 * a cast it will choke the compiler: if you do have a cast then
217 * you can either go for (char *) or (void *).
218 */
219 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size);
220 if (i < 0)
221 return(1);
222 else
223 return(j);
224 }
225
226long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
227 {
228 int i;
229 char **p;
230
231 switch (cmd)
232 {
233 case BIO_GHBN_CTRL_HITS:
234 return(BIO_ghbn_hits);
235 /* break; */
236 case BIO_GHBN_CTRL_MISSES:
237 return(BIO_ghbn_miss);
238 /* break; */
239 case BIO_GHBN_CTRL_CACHE_SIZE:
240 return(GHBN_NUM);
241 /* break; */
242 case BIO_GHBN_CTRL_GET_ENTRY:
243 if ((iarg >= 0) && (iarg <GHBN_NUM) &&
244 (ghbn_cache[iarg].order > 0))
245 {
246 p=(char **)parg;
247 if (p == NULL) return(0);
248 *p=ghbn_cache[iarg].name;
249 ghbn_cache[iarg].name[128]='\0';
250 return(1);
251 }
252 return(0);
253 /* break; */
254 case BIO_GHBN_CTRL_FLUSH:
255 for (i=0; i<GHBN_NUM; i++)
256 ghbn_cache[i].order=0;
257 break;
258 default:
259 return(0);
260 }
261 return(1);
262 }
263
264static struct hostent *ghbn_dup(struct hostent *a)
265 {
266 struct hostent *ret;
267 int i,j;
268
269 MemCheck_off();
270 ret=(struct hostent *)Malloc(sizeof(struct hostent));
271 if (ret == NULL) return(NULL);
272 memset(ret,0,sizeof(struct hostent));
273
274 for (i=0; a->h_aliases[i] != NULL; i++)
275 ;
276 i++;
277 ret->h_aliases = (char **)Malloc(i*sizeof(char *));
278 if (ret->h_aliases == NULL)
279 goto err;
280 memset(ret->h_aliases, 0, i*sizeof(char *));
281
282 for (i=0; a->h_addr_list[i] != NULL; i++)
283 ;
284 i++;
285 ret->h_addr_list=(char **)Malloc(i*sizeof(char *));
286 if (ret->h_addr_list == NULL)
287 goto err;
288 memset(ret->h_addr_list, 0, i*sizeof(char *));
289
290 j=strlen(a->h_name)+1;
291 if ((ret->h_name=Malloc(j)) == NULL) goto err;
292 memcpy((char *)ret->h_name,a->h_name,j);
293 for (i=0; a->h_aliases[i] != NULL; i++)
294 {
295 j=strlen(a->h_aliases[i])+1;
296 if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err;
297 memcpy(ret->h_aliases[i],a->h_aliases[i],j);
298 }
299 ret->h_length=a->h_length;
300 ret->h_addrtype=a->h_addrtype;
301 for (i=0; a->h_addr_list[i] != NULL; i++)
302 {
303 if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL)
304 goto err;
305 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
306 }
307 if (0)
308 {
309err:
310 if (ret != NULL)
311 ghbn_free(ret);
312 ret=NULL;
313 }
314 MemCheck_on();
315 return(ret);
316 }
317
318static void ghbn_free(struct hostent *a)
319 {
320 int i;
321
322 if(a == NULL)
323 return;
324
325 if (a->h_aliases != NULL)
326 {
327 for (i=0; a->h_aliases[i] != NULL; i++)
328 Free(a->h_aliases[i]);
329 Free(a->h_aliases);
330 }
331 if (a->h_addr_list != NULL)
332 {
333 for (i=0; a->h_addr_list[i] != NULL; i++)
334 Free(a->h_addr_list[i]);
335 Free(a->h_addr_list);
336 }
337 if (a->h_name != NULL) Free(a->h_name);
338 Free(a);
339 }
340
341struct hostent *BIO_gethostbyname(const char *name)
342 {
343 struct hostent *ret;
344 int i,lowi=0,j;
345 unsigned long low= (unsigned long)-1;
346
347/* return(gethostbyname(name)); */
348
349#if 0 /* It doesn't make sense to use locking here: The function interface
350 * is not thread-safe, because threads can never be sure when
351 * some other thread destroys the data they were given a pointer to.
352 */
353 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
354#endif
355 j=strlen(name);
356 if (j < 128)
357 {
358 for (i=0; i<GHBN_NUM; i++)
359 {
360 if (low > ghbn_cache[i].order)
361 {
362 low=ghbn_cache[i].order;
363 lowi=i;
364 }
365 if (ghbn_cache[i].order > 0)
366 {
367 if (strncmp(name,ghbn_cache[i].name,128) == 0)
368 break;
369 }
370 }
371 }
372 else
373 i=GHBN_NUM;
374
375 if (i == GHBN_NUM) /* no hit*/
376 {
377 BIO_ghbn_miss++;
378 /* Note: under VMS with SOCKETSHR, it seems like the first
379 * parameter is 'char *', instead of 'const char *'
380 */
381 ret=gethostbyname(
382#ifndef CONST_STRICT
383 (char *)
384#endif
385 name);
386
387 if (ret == NULL)
388 goto end;
389 if (j > 128) /* too big to cache */
390 {
391#if 0 /* If we were trying to make this function thread-safe (which
392 * is bound to fail), we'd have to give up in this case
393 * (or allocate more memory). */
394 ret = NULL;
395#endif
396 goto end;
397 }
398
399 /* else add to cache */
400 if (ghbn_cache[lowi].ent != NULL)
401 ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
402 ghbn_cache[lowi].name[0] = '\0';
403
404 if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
405 {
406 BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE);
407 goto end;
408 }
409 strncpy(ghbn_cache[lowi].name,name,128);
410 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
411 }
412 else
413 {
414 BIO_ghbn_hits++;
415 ret= ghbn_cache[i].ent;
416 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
417 }
418end:
419#if 0
420 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
421#endif
422 return(ret);
423 }
424
425int BIO_sock_init(void)
426 {
427#ifdef WINDOWS
428 static struct WSAData wsa_state;
429
430 if (!wsa_init_done)
431 {
432 int err;
433
434#ifdef SIGINT
435 signal(SIGINT,(void (*)(int))BIO_sock_cleanup);
436#endif
437 wsa_init_done=1;
438 memset(&wsa_state,0,sizeof(wsa_state));
439 if (WSAStartup(0x0101,&wsa_state)!=0)
440 {
441 err=WSAGetLastError();
442 SYSerr(SYS_F_WSASTARTUP,err);
443 BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
444 return(-1);
445 }
446 }
447#endif /* WINDOWS */
448 return(1);
449 }
450
451void BIO_sock_cleanup(void)
452 {
453#ifdef WINDOWS
454 if (wsa_init_done)
455 {
456 wsa_init_done=0;
457 WSACancelBlockingCall();
458 WSACleanup();
459 }
460#endif
461 }
462
463#if !defined(VMS) || __VMS_VER >= 70000000
464
465int BIO_socket_ioctl(int fd, long type, unsigned long *arg)
466 {
467 int i;
468
469 i=ioctlsocket(fd,type,arg);
470 if (i < 0)
471 SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error());
472 return(i);
473 }
474#endif /* __VMS_VER */
475
476/* The reason I have implemented this instead of using sscanf is because
477 * Visual C 1.52c gives an unresolved external when linking a DLL :-( */
478static int get_ip(const char *str, unsigned char ip[4])
479 {
480 unsigned int tmp[4];
481 int num=0,c,ok=0;
482
483 tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
484
485 for (;;)
486 {
487 c= *(str++);
488 if ((c >= '0') && (c <= '9'))
489 {
490 ok=1;
491 tmp[num]=tmp[num]*10+c-'0';
492 if (tmp[num] > 255) return(-1);
493 }
494 else if (c == '.')
495 {
496 if (!ok) return(-1);
497 if (num == 3) break;
498 num++;
499 ok=0;
500 }
501 else if ((num == 3) && ok)
502 break;
503 else
504 return(0);
505 }
506 ip[0]=tmp[0];
507 ip[1]=tmp[1];
508 ip[2]=tmp[2];
509 ip[3]=tmp[3];
510 return(1);
511 }
512
513int BIO_get_accept_socket(char *host, int bind_mode)
514 {
515 int ret=0;
516 struct sockaddr_in server,client;
517 int s= -1,cs;
518 unsigned char ip[4];
519 unsigned short port;
520 char *str,*e;
521 const char *h,*p;
522 unsigned long l;
523 int err_num;
524
525 if (!BIO_sock_init()) return(INVALID_SOCKET);
526
527 if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);
528
529 h=p=NULL;
530 h=str;
531 for (e=str; *e; e++)
532 {
533 if (*e == ':')
534 {
535 p= &(e[1]);
536 *e='\0';
537 }
538 else if (*e == '/')
539 {
540 *e='\0';
541 break;
542 }
543 }
544
545 if (p == NULL)
546 {
547 p=h;
548 h="*";
549 }
550
551 if (!BIO_get_port(p,&port)) return(INVALID_SOCKET);
552
553 memset((char *)&server,0,sizeof(server));
554 server.sin_family=AF_INET;
555 server.sin_port=htons(port);
556
557 if (strcmp(h,"*") == 0)
558 server.sin_addr.s_addr=INADDR_ANY;
559 else
560 {
561 if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET);
562 l=(unsigned long)
563 ((unsigned long)ip[0]<<24L)|
564 ((unsigned long)ip[1]<<16L)|
565 ((unsigned long)ip[2]<< 8L)|
566 ((unsigned long)ip[3]);
567 server.sin_addr.s_addr=htonl(l);
568 }
569
570again:
571 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
572 if (s == INVALID_SOCKET)
573 {
574 SYSerr(SYS_F_SOCKET,get_last_socket_error());
575 ERR_add_error_data(3,"port='",host,"'");
576 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
577 goto err;
578 }
579
580#ifdef SO_REUSEADDR
581 if (bind_mode == BIO_BIND_REUSEADDR)
582 {
583 int i=1;
584
585 ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
586 bind_mode=BIO_BIND_NORMAL;
587 }
588#endif
589 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
590 {
591#ifdef SO_REUSEADDR
592 err_num=get_last_socket_error();
593 if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
594 (err_num == EADDRINUSE))
595 {
596 memcpy((char *)&client,(char *)&server,sizeof(server));
597 if (strcmp(h,"*") == 0)
598 client.sin_addr.s_addr=htonl(0x7F000001);
599 cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
600 if (cs != INVALID_SOCKET)
601 {
602 int ii;
603 ii=connect(cs,(struct sockaddr *)&client,
604 sizeof(client));
605 closesocket(cs);
606 if (ii == INVALID_SOCKET)
607 {
608 bind_mode=BIO_BIND_REUSEADDR;
609 closesocket(s);
610 goto again;
611 }
612 /* else error */
613 }
614 /* else error */
615 }
616#endif
617 SYSerr(SYS_F_BIND,err_num);
618 ERR_add_error_data(3,"port='",host,"'");
619 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
620 goto err;
621 }
622 if (listen(s,MAX_LISTEN) == -1)
623 {
624 SYSerr(SYS_F_BIND,get_last_socket_error());
625 ERR_add_error_data(3,"port='",host,"'");
626 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
627 goto err;
628 }
629 ret=1;
630err:
631 if (str != NULL) Free(str);
632 if ((ret == 0) && (s != INVALID_SOCKET))
633 {
634 closesocket(s);
635 s= INVALID_SOCKET;
636 }
637 return(s);
638 }
639
640int BIO_accept(int sock, char **addr)
641 {
642 int ret=INVALID_SOCKET;
643 static struct sockaddr_in from;
644 unsigned long l;
645 unsigned short port;
646 int len;
647 char *p;
648
649 memset((char *)&from,0,sizeof(from));
650 len=sizeof(from);
651 /* Note: under VMS with SOCKETSHR the fourth parameter is currently
652 * of type (int *) whereas under other systems it is (void *) if
653 * you don't have a cast it will choke the compiler: if you do
654 * have a cast then you can either go for (int *) or (void *).
655 */
656 ret=accept(sock,(struct sockaddr *)&from,(void *)&len);
657 if (ret == INVALID_SOCKET)
658 {
659 SYSerr(SYS_F_ACCEPT,get_last_socket_error());
660 BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR);
661 goto end;
662 }
663
664 if (addr == NULL) goto end;
665
666 l=ntohl(from.sin_addr.s_addr);
667 port=ntohs(from.sin_port);
668 if (*addr == NULL)
669 {
670 if ((p=Malloc(24)) == NULL)
671 {
672 BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
673 goto end;
674 }
675 *addr=p;
676 }
677 sprintf(*addr,"%d.%d.%d.%d:%d",
678 (unsigned char)(l>>24L)&0xff,
679 (unsigned char)(l>>16L)&0xff,
680 (unsigned char)(l>> 8L)&0xff,
681 (unsigned char)(l )&0xff,
682 port);
683end:
684 return(ret);
685 }
686
687int BIO_set_tcp_ndelay(int s, int on)
688 {
689 int ret=0;
690#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
691 int opt;
692
693#ifdef SOL_TCP
694 opt=SOL_TCP;
695#else
696#ifdef IPPROTO_TCP
697 opt=IPPROTO_TCP;
698#endif
699#endif
700
701 ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on));
702#endif
703 return(ret == 0);
704 }
705#endif
706
707int BIO_socket_nbio(int s, int mode)
708 {
709 int ret= -1;
710 unsigned long l;
711
712 l=mode;
713#ifdef FIONBIO
714 ret=BIO_socket_ioctl(s,FIONBIO,&l);
715#endif
716 return(ret == 0);
717 }
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
deleted file mode 100644
index ff0c9070ae..0000000000
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ /dev/null
@@ -1,511 +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);
72static long buffer_callback_ctrl(BIO *h,int cmd, void (*fp)());
73#define DEFAULT_BUFFER_SIZE 1024
74
75static BIO_METHOD methods_buffer=
76 {
77 BIO_TYPE_BUFFER,
78 "buffer",
79 buffer_write,
80 buffer_read,
81 buffer_puts,
82 buffer_gets,
83 buffer_ctrl,
84 buffer_new,
85 buffer_free,
86 buffer_callback_ctrl,
87 };
88
89BIO_METHOD *BIO_f_buffer(void)
90 {
91 return(&methods_buffer);
92 }
93
94static int buffer_new(BIO *bi)
95 {
96 BIO_F_BUFFER_CTX *ctx;
97
98 ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX));
99 if (ctx == NULL) return(0);
100 ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE);
101 if (ctx->ibuf == NULL) { Free(ctx); return(0); }
102 ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE);
103 if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); }
104 ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
105 ctx->obuf_size=DEFAULT_BUFFER_SIZE;
106 ctx->ibuf_len=0;
107 ctx->ibuf_off=0;
108 ctx->obuf_len=0;
109 ctx->obuf_off=0;
110
111 bi->init=1;
112 bi->ptr=(char *)ctx;
113 bi->flags=0;
114 return(1);
115 }
116
117static int buffer_free(BIO *a)
118 {
119 BIO_F_BUFFER_CTX *b;
120
121 if (a == NULL) return(0);
122 b=(BIO_F_BUFFER_CTX *)a->ptr;
123 if (b->ibuf != NULL) Free(b->ibuf);
124 if (b->obuf != NULL) Free(b->obuf);
125 Free(a->ptr);
126 a->ptr=NULL;
127 a->init=0;
128 a->flags=0;
129 return(1);
130 }
131
132static int buffer_read(BIO *b, char *out, int outl)
133 {
134 int i,num=0;
135 BIO_F_BUFFER_CTX *ctx;
136
137 if (out == NULL) return(0);
138 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
139
140 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
141 num=0;
142 BIO_clear_retry_flags(b);
143
144start:
145 i=ctx->ibuf_len;
146 /* If there is stuff left over, grab it */
147 if (i != 0)
148 {
149 if (i > outl) i=outl;
150 memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i);
151 ctx->ibuf_off+=i;
152 ctx->ibuf_len-=i;
153 num+=i;
154 if (outl == i) return(num);
155 outl-=i;
156 out+=i;
157 }
158
159 /* We may have done a partial read. try to do more.
160 * We have nothing in the buffer.
161 * If we get an error and have read some data, just return it
162 * and let them retry to get the error again.
163 * copy direct to parent address space */
164 if (outl > ctx->ibuf_size)
165 {
166 for (;;)
167 {
168 i=BIO_read(b->next_bio,out,outl);
169 if (i <= 0)
170 {
171 BIO_copy_next_retry(b);
172 if (i < 0) return((num > 0)?num:i);
173 if (i == 0) return(num);
174 }
175 num+=i;
176 if (outl == i) return(num);
177 out+=i;
178 outl-=i;
179 }
180 }
181 /* else */
182
183 /* we are going to be doing some buffering */
184 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
185 if (i <= 0)
186 {
187 BIO_copy_next_retry(b);
188 if (i < 0) return((num > 0)?num:i);
189 if (i == 0) return(num);
190 }
191 ctx->ibuf_off=0;
192 ctx->ibuf_len=i;
193
194 /* Lets re-read using ourselves :-) */
195 goto start;
196 }
197
198static int buffer_write(BIO *b, char *in, int inl)
199 {
200 int i,num=0;
201 BIO_F_BUFFER_CTX *ctx;
202
203 if ((in == NULL) || (inl <= 0)) return(0);
204 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
205 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
206
207 BIO_clear_retry_flags(b);
208start:
209 i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off);
210 /* add to buffer and return */
211 if (i >= inl)
212 {
213 memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl);
214 ctx->obuf_len+=inl;
215 return(num+inl);
216 }
217 /* else */
218 /* stuff already in buffer, so add to it first, then flush */
219 if (ctx->obuf_len != 0)
220 {
221 if (i > 0) /* lets fill it up if we can */
222 {
223 memcpy(&(ctx->obuf[ctx->obuf_len]),in,i);
224 in+=i;
225 inl-=i;
226 num+=i;
227 ctx->obuf_len+=i;
228 }
229 /* we now have a full buffer needing flushing */
230 for (;;)
231 {
232 i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]),
233 ctx->obuf_len);
234 if (i <= 0)
235 {
236 BIO_copy_next_retry(b);
237
238 if (i < 0) return((num > 0)?num:i);
239 if (i == 0) return(num);
240 }
241 ctx->obuf_off+=i;
242 ctx->obuf_len-=i;
243 if (ctx->obuf_len == 0) break;
244 }
245 }
246 /* we only get here if the buffer has been flushed and we
247 * still have stuff to write */
248 ctx->obuf_off=0;
249
250 /* we now have inl bytes to write */
251 while (inl >= ctx->obuf_size)
252 {
253 i=BIO_write(b->next_bio,in,inl);
254 if (i <= 0)
255 {
256 BIO_copy_next_retry(b);
257 if (i < 0) return((num > 0)?num:i);
258 if (i == 0) return(num);
259 }
260 num+=i;
261 in+=i;
262 inl-=i;
263 if (inl == 0) return(num);
264 }
265
266 /* copy the rest into the buffer since we have only a small
267 * amount left */
268 goto start;
269 }
270
271static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
272 {
273 BIO *dbio;
274 BIO_F_BUFFER_CTX *ctx;
275 long ret=1;
276 char *p1,*p2;
277 int r,i,*ip;
278 int ibs,obs;
279
280 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
281
282 switch (cmd)
283 {
284 case BIO_CTRL_RESET:
285 ctx->ibuf_off=0;
286 ctx->ibuf_len=0;
287 ctx->obuf_off=0;
288 ctx->obuf_len=0;
289 if (b->next_bio == NULL) return(0);
290 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
291 break;
292 case BIO_CTRL_INFO:
293 ret=(long)ctx->obuf_len;
294 break;
295 case BIO_C_GET_BUFF_NUM_LINES:
296 ret=0;
297 p1=ctx->ibuf;
298 for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++)
299 {
300 if (p1[i] == '\n') ret++;
301 }
302 break;
303 case BIO_CTRL_WPENDING:
304 ret=(long)ctx->obuf_len;
305 if (ret == 0)
306 {
307 if (b->next_bio == NULL) return(0);
308 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
309 }
310 break;
311 case BIO_CTRL_PENDING:
312 ret=(long)ctx->ibuf_len;
313 if (ret == 0)
314 {
315 if (b->next_bio == NULL) return(0);
316 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
317 }
318 break;
319 case BIO_C_SET_BUFF_READ_DATA:
320 if (num > ctx->ibuf_size)
321 {
322 p1=Malloc((int)num);
323 if (p1 == NULL) goto malloc_error;
324 if (ctx->ibuf != NULL) Free(ctx->ibuf);
325 ctx->ibuf=p1;
326 }
327 ctx->ibuf_off=0;
328 ctx->ibuf_len=(int)num;
329 memcpy(ctx->ibuf,ptr,(int)num);
330 ret=1;
331 break;
332 case BIO_C_SET_BUFF_SIZE:
333 if (ptr != NULL)
334 {
335 ip=(int *)ptr;
336 if (*ip == 0)
337 {
338 ibs=(int)num;
339 obs=ctx->obuf_size;
340 }
341 else /* if (*ip == 1) */
342 {
343 ibs=ctx->ibuf_size;
344 obs=(int)num;
345 }
346 }
347 else
348 {
349 ibs=(int)num;
350 obs=(int)num;
351 }
352 p1=ctx->ibuf;
353 p2=ctx->obuf;
354 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
355 {
356 p1=(char *)Malloc((int)num);
357 if (p1 == NULL) goto malloc_error;
358 }
359 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
360 {
361 p2=(char *)Malloc((int)num);
362 if (p2 == NULL)
363 {
364 if (p1 != ctx->ibuf) Free(p1);
365 goto malloc_error;
366 }
367 }
368 if (ctx->ibuf != p1)
369 {
370 Free(ctx->ibuf);
371 ctx->ibuf=p1;
372 ctx->ibuf_off=0;
373 ctx->ibuf_len=0;
374 ctx->ibuf_size=ibs;
375 }
376 if (ctx->obuf != p2)
377 {
378 Free(ctx->obuf);
379 ctx->obuf=p2;
380 ctx->obuf_off=0;
381 ctx->obuf_len=0;
382 ctx->obuf_size=obs;
383 }
384 break;
385 case BIO_C_DO_STATE_MACHINE:
386 if (b->next_bio == NULL) return(0);
387 BIO_clear_retry_flags(b);
388 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
389 BIO_copy_next_retry(b);
390 break;
391
392 case BIO_CTRL_FLUSH:
393 if (b->next_bio == NULL) return(0);
394 if (ctx->obuf_len <= 0)
395 {
396 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
397 break;
398 }
399
400 for (;;)
401 {
402 BIO_clear_retry_flags(b);
403 if (ctx->obuf_len > ctx->obuf_off)
404 {
405 r=BIO_write(b->next_bio,
406 &(ctx->obuf[ctx->obuf_off]),
407 ctx->obuf_len-ctx->obuf_off);
408#if 0
409fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r);
410#endif
411 BIO_copy_next_retry(b);
412 if (r <= 0) return((long)r);
413 ctx->obuf_off+=r;
414 }
415 else
416 {
417 ctx->obuf_len=0;
418 ctx->obuf_off=0;
419 ret=1;
420 break;
421 }
422 }
423 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
424 break;
425 case BIO_CTRL_DUP:
426 dbio=(BIO *)ptr;
427 if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) ||
428 !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
429 ret=0;
430 break;
431 default:
432 if (b->next_bio == NULL) return(0);
433 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
434 break;
435 }
436 return(ret);
437malloc_error:
438 BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE);
439 return(0);
440 }
441
442static long buffer_callback_ctrl(BIO *b, int cmd, void (*fp)())
443 {
444 long ret=1;
445
446 if (b->next_bio == NULL) return(0);
447 switch (cmd)
448 {
449 default:
450 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
451 break;
452 }
453 return(ret);
454 }
455
456static int buffer_gets(BIO *b, char *buf, int size)
457 {
458 BIO_F_BUFFER_CTX *ctx;
459 int num=0,i,flag;
460 char *p;
461
462 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
463 size--; /* reserve space for a '\0' */
464 BIO_clear_retry_flags(b);
465
466 for (;;)
467 {
468 if (ctx->ibuf_len > 0)
469 {
470 p= &(ctx->ibuf[ctx->ibuf_off]);
471 flag=0;
472 for (i=0; (i<ctx->ibuf_len) && (i<size); i++)
473 {
474 *(buf++)=p[i];
475 if (p[i] == '\n')
476 {
477 flag=1;
478 i++;
479 break;
480 }
481 }
482 num+=i;
483 size-=i;
484 ctx->ibuf_len-=i;
485 ctx->ibuf_off+=i;
486 if ((flag) || (i == size))
487 {
488 *buf='\0';
489 return(num);
490 }
491 }
492 else /* read another chunk */
493 {
494 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
495 if (i <= 0)
496 {
497 BIO_copy_next_retry(b);
498 if (i < 0) return((num > 0)?num:i);
499 if (i == 0) return(num);
500 }
501 ctx->ibuf_len=i;
502 ctx->ibuf_off=0;
503 }
504 }
505 }
506
507static int buffer_puts(BIO *b, char *str)
508 {
509 return(BIO_write(b,str,strlen(str)));
510 }
511
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
deleted file mode 100644
index 5e574b7231..0000000000
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ /dev/null
@@ -1,256 +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);
76static long nbiof_callback_ctrl(BIO *h,int cmd,void (*fp)());
77typedef struct nbio_test_st
78 {
79 /* only set if we sent a 'should retry' error */
80 int lrn;
81 int lwn;
82 } NBIO_TEST;
83
84static BIO_METHOD methods_nbiof=
85 {
86 BIO_TYPE_NBIO_TEST,
87 "non-blocking IO test filter",
88 nbiof_write,
89 nbiof_read,
90 nbiof_puts,
91 nbiof_gets,
92 nbiof_ctrl,
93 nbiof_new,
94 nbiof_free,
95 nbiof_callback_ctrl,
96 };
97
98BIO_METHOD *BIO_f_nbio_test(void)
99 {
100 return(&methods_nbiof);
101 }
102
103static int nbiof_new(BIO *bi)
104 {
105 NBIO_TEST *nt;
106
107 nt=(NBIO_TEST *)Malloc(sizeof(NBIO_TEST));
108 nt->lrn= -1;
109 nt->lwn= -1;
110 bi->ptr=(char *)nt;
111 bi->init=1;
112 bi->flags=0;
113 return(1);
114 }
115
116static int nbiof_free(BIO *a)
117 {
118 if (a == NULL) return(0);
119 if (a->ptr != NULL)
120 Free(a->ptr);
121 a->ptr=NULL;
122 a->init=0;
123 a->flags=0;
124 return(1);
125 }
126
127static int nbiof_read(BIO *b, char *out, int outl)
128 {
129 NBIO_TEST *nt;
130 int ret=0;
131#if 0
132 int num;
133 unsigned char n;
134#endif
135
136 if (out == NULL) return(0);
137 if (b->next_bio == NULL) return(0);
138 nt=(NBIO_TEST *)b->ptr;
139
140 BIO_clear_retry_flags(b);
141#if 0
142 RAND_pseudo_bytes(&n,1);
143 num=(n&0x07);
144
145 if (outl > num) outl=num;
146
147 if (num == 0)
148 {
149 ret= -1;
150 BIO_set_retry_read(b);
151 }
152 else
153#endif
154 {
155 ret=BIO_read(b->next_bio,out,outl);
156 if (ret < 0)
157 BIO_copy_next_retry(b);
158 }
159 return(ret);
160 }
161
162static int nbiof_write(BIO *b, char *in, int inl)
163 {
164 NBIO_TEST *nt;
165 int ret=0;
166 int num;
167 unsigned char n;
168
169 if ((in == NULL) || (inl <= 0)) return(0);
170 if (b->next_bio == NULL) return(0);
171 nt=(NBIO_TEST *)b->ptr;
172
173 BIO_clear_retry_flags(b);
174
175#if 1
176 if (nt->lwn > 0)
177 {
178 num=nt->lwn;
179 nt->lwn=0;
180 }
181 else
182 {
183 RAND_pseudo_bytes(&n,1);
184 num=(n&7);
185 }
186
187 if (inl > num) inl=num;
188
189 if (num == 0)
190 {
191 ret= -1;
192 BIO_set_retry_write(b);
193 }
194 else
195#endif
196 {
197 ret=BIO_write(b->next_bio,in,inl);
198 if (ret < 0)
199 {
200 BIO_copy_next_retry(b);
201 nt->lwn=inl;
202 }
203 }
204 return(ret);
205 }
206
207static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr)
208 {
209 long ret;
210
211 if (b->next_bio == NULL) return(0);
212 switch (cmd)
213 {
214 case BIO_C_DO_STATE_MACHINE:
215 BIO_clear_retry_flags(b);
216 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
217 BIO_copy_next_retry(b);
218 break;
219 case BIO_CTRL_DUP:
220 ret=0L;
221 break;
222 default:
223 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
224 break;
225 }
226 return(ret);
227 }
228
229static long nbiof_callback_ctrl(BIO *b, int cmd, void (*fp)())
230 {
231 long ret=1;
232
233 if (b->next_bio == NULL) return(0);
234 switch (cmd)
235 {
236 default:
237 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
238 break;
239 }
240 return(ret);
241 }
242
243static int nbiof_gets(BIO *bp, char *buf, int size)
244 {
245 if (bp->next_bio == NULL) return(0);
246 return(BIO_gets(bp->next_bio,buf,size));
247 }
248
249
250static int nbiof_puts(BIO *bp, char *str)
251 {
252 if (bp->next_bio == NULL) return(0);
253 return(BIO_puts(bp->next_bio,str));
254 }
255
256
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c
deleted file mode 100644
index 0d183a6d9a..0000000000
--- a/src/lib/libcrypto/bio/bf_null.c
+++ /dev/null
@@ -1,184 +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 long nullf_callback_ctrl(BIO *h,int cmd,void (*fp)());
76static BIO_METHOD methods_nullf=
77 {
78 BIO_TYPE_NULL_FILTER,
79 "NULL filter",
80 nullf_write,
81 nullf_read,
82 nullf_puts,
83 nullf_gets,
84 nullf_ctrl,
85 nullf_new,
86 nullf_free,
87 nullf_callback_ctrl,
88 };
89
90BIO_METHOD *BIO_f_null(void)
91 {
92 return(&methods_nullf);
93 }
94
95static int nullf_new(BIO *bi)
96 {
97 bi->init=1;
98 bi->ptr=NULL;
99 bi->flags=0;
100 return(1);
101 }
102
103static int nullf_free(BIO *a)
104 {
105 if (a == NULL) return(0);
106/* a->ptr=NULL;
107 a->init=0;
108 a->flags=0;*/
109 return(1);
110 }
111
112static int nullf_read(BIO *b, char *out, int outl)
113 {
114 int ret=0;
115
116 if (out == NULL) return(0);
117 if (b->next_bio == NULL) return(0);
118 ret=BIO_read(b->next_bio,out,outl);
119 BIO_clear_retry_flags(b);
120 BIO_copy_next_retry(b);
121 return(ret);
122 }
123
124static int nullf_write(BIO *b, char *in, int inl)
125 {
126 int ret=0;
127
128 if ((in == NULL) || (inl <= 0)) return(0);
129 if (b->next_bio == NULL) return(0);
130 ret=BIO_write(b->next_bio,in,inl);
131 BIO_clear_retry_flags(b);
132 BIO_copy_next_retry(b);
133 return(ret);
134 }
135
136static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr)
137 {
138 long ret;
139
140 if (b->next_bio == NULL) return(0);
141 switch(cmd)
142 {
143 case BIO_C_DO_STATE_MACHINE:
144 BIO_clear_retry_flags(b);
145 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
146 BIO_copy_next_retry(b);
147 break;
148 case BIO_CTRL_DUP:
149 ret=0L;
150 break;
151 default:
152 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
153 }
154 return(ret);
155 }
156
157static long nullf_callback_ctrl(BIO *b, int cmd, void (*fp)())
158 {
159 long ret=1;
160
161 if (b->next_bio == NULL) return(0);
162 switch (cmd)
163 {
164 default:
165 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
166 break;
167 }
168 return(ret);
169 }
170
171static int nullf_gets(BIO *bp, char *buf, int size)
172 {
173 if (bp->next_bio == NULL) return(0);
174 return(BIO_gets(bp->next_bio,buf,size));
175 }
176
177
178static int nullf_puts(BIO *bp, char *str)
179 {
180 if (bp->next_bio == NULL) return(0);
181 return(BIO_puts(bp->next_bio,str));
182 }
183
184
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
deleted file mode 100644
index ebdb18170b..0000000000
--- a/src/lib/libcrypto/bio/bio.h
+++ /dev/null
@@ -1,667 +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) /* passive 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/* This is used with memory BIOs: it means we shouldn't free up or change the
151 * data in any way.
152 */
153#define BIO_FLAGS_MEM_RDONLY 0x200
154
155#define BIO_set_flags(b,f) ((b)->flags|=(f))
156#define BIO_get_flags(b) ((b)->flags)
157#define BIO_set_retry_special(b) \
158 ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
159#define BIO_set_retry_read(b) \
160 ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
161#define BIO_set_retry_write(b) \
162 ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
163
164/* These are normally used internally in BIOs */
165#define BIO_clear_flags(b,f) ((b)->flags&= ~(f))
166#define BIO_clear_retry_flags(b) \
167 ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
168#define BIO_get_retry_flags(b) \
169 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
170
171/* These should be used by the application to tell why we should retry */
172#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
173#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
174#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
175#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
176#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
177
178/* The next two are used in conjunction with the
179 * BIO_should_io_special() condition. After this returns true,
180 * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO
181 * stack and return the 'reason' for the special and the offending BIO.
182 * Given a BIO, BIO_get_retry_reason(bio) will return the code. */
183/* Returned from the SSL bio when the certificate retrieval code had an error */
184#define BIO_RR_SSL_X509_LOOKUP 0x01
185/* Returned from the connect BIO when a connect would have blocked */
186#define BIO_RR_CONNECT 0x02
187
188/* These are passed by the BIO callback */
189#define BIO_CB_FREE 0x01
190#define BIO_CB_READ 0x02
191#define BIO_CB_WRITE 0x03
192#define BIO_CB_PUTS 0x04
193#define BIO_CB_GETS 0x05
194#define BIO_CB_CTRL 0x06
195
196/* The callback is called before and after the underling operation,
197 * The BIO_CB_RETURN flag indicates if it is after the call */
198#define BIO_CB_RETURN 0x80
199#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
200#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
201#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
202
203#define BIO_set_callback(b,cb) ((b)->callback=(cb))
204#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg))
205#define BIO_get_callback_arg(b) ((b)->cb_arg)
206#define BIO_get_callback(b) ((b)->callback)
207#define BIO_method_name(b) ((b)->method->name)
208#define BIO_method_type(b) ((b)->method->type)
209
210#ifndef WIN16
211typedef struct bio_method_st
212 {
213 int type;
214 const char *name;
215 int (*bwrite)();
216 int (*bread)();
217 int (*bputs)();
218 int (*bgets)();
219 long (*ctrl)();
220 int (*create)();
221 int (*destroy)();
222 long (*callback_ctrl)();
223 } BIO_METHOD;
224#else
225typedef struct bio_method_st
226 {
227 int type;
228 const char *name;
229 int (_far *bwrite)();
230 int (_far *bread)();
231 int (_far *bputs)();
232 int (_far *bgets)();
233 long (_far *ctrl)();
234 int (_far *create)();
235 int (_far *destroy)();
236 long (_fat *callback_ctrl)();
237 } BIO_METHOD;
238#endif
239
240typedef struct bio_st
241 {
242 BIO_METHOD *method;
243 /* bio, mode, argp, argi, argl, ret */
244 long (*callback)(struct bio_st *,int,const char *,int, long,long);
245 char *cb_arg; /* first argument for the callback */
246
247 int init;
248 int shutdown;
249 int flags; /* extra storage */
250 int retry_reason;
251 int num;
252 void *ptr;
253 struct bio_st *next_bio; /* used by filter BIOs */
254 struct bio_st *prev_bio; /* used by filter BIOs */
255 int references;
256 unsigned long num_read;
257 unsigned long num_write;
258
259 CRYPTO_EX_DATA ex_data;
260 } BIO;
261
262typedef struct bio_f_buffer_ctx_struct
263 {
264 /* BIO *bio; */ /* this is now in the BIO struct */
265 int ibuf_size; /* how big is the input buffer */
266 int obuf_size; /* how big is the output buffer */
267
268 char *ibuf; /* the char array */
269 int ibuf_len; /* how many bytes are in it */
270 int ibuf_off; /* write/read offset */
271
272 char *obuf; /* the char array */
273 int obuf_len; /* how many bytes are in it */
274 int obuf_off; /* write/read offset */
275 } BIO_F_BUFFER_CTX;
276
277/* connect BIO stuff */
278#define BIO_CONN_S_BEFORE 1
279#define BIO_CONN_S_GET_IP 2
280#define BIO_CONN_S_GET_PORT 3
281#define BIO_CONN_S_CREATE_SOCKET 4
282#define BIO_CONN_S_CONNECT 5
283#define BIO_CONN_S_OK 6
284#define BIO_CONN_S_BLOCKED_CONNECT 7
285#define BIO_CONN_S_NBIO 8
286/*#define BIO_CONN_get_param_hostname BIO_ctrl */
287
288#define BIO_C_SET_CONNECT 100
289#define BIO_C_DO_STATE_MACHINE 101
290#define BIO_C_SET_NBIO 102
291#define BIO_C_SET_PROXY_PARAM 103
292#define BIO_C_SET_FD 104
293#define BIO_C_GET_FD 105
294#define BIO_C_SET_FILE_PTR 106
295#define BIO_C_GET_FILE_PTR 107
296#define BIO_C_SET_FILENAME 108
297#define BIO_C_SET_SSL 109
298#define BIO_C_GET_SSL 110
299#define BIO_C_SET_MD 111
300#define BIO_C_GET_MD 112
301#define BIO_C_GET_CIPHER_STATUS 113
302#define BIO_C_SET_BUF_MEM 114
303#define BIO_C_GET_BUF_MEM_PTR 115
304#define BIO_C_GET_BUFF_NUM_LINES 116
305#define BIO_C_SET_BUFF_SIZE 117
306#define BIO_C_SET_ACCEPT 118
307#define BIO_C_SSL_MODE 119
308#define BIO_C_GET_MD_CTX 120
309#define BIO_C_GET_PROXY_PARAM 121
310#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */
311#define BIO_C_GET_CONNECT 123
312#define BIO_C_GET_ACCEPT 124
313#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125
314#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126
315#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127
316#define BIO_C_FILE_SEEK 128
317#define BIO_C_GET_CIPHER_CTX 129
318#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/
319#define BIO_C_SET_BIND_MODE 131
320#define BIO_C_GET_BIND_MODE 132
321#define BIO_C_FILE_TELL 133
322#define BIO_C_GET_SOCKS 134
323#define BIO_C_SET_SOCKS 135
324
325#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */
326#define BIO_C_GET_WRITE_BUF_SIZE 137
327#define BIO_C_MAKE_BIO_PAIR 138
328#define BIO_C_DESTROY_BIO_PAIR 139
329#define BIO_C_GET_WRITE_GUARANTEE 140
330#define BIO_C_GET_READ_REQUEST 141
331#define BIO_C_SHUTDOWN_WR 142
332#define BIO_C_NREAD0 143
333#define BIO_C_NREAD 144
334#define BIO_C_NWRITE0 145
335#define BIO_C_NWRITE 146
336#define BIO_C_RESET_READ_REQUEST 147
337
338
339#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg)
340#define BIO_get_app_data(s) BIO_get_ex_data(s,0)
341
342/* BIO_s_connect() and BIO_s_socks4a_connect() */
343#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
344#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
345#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)
346#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)
347#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
348#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
349#define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2)
350#define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port)
351
352
353#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
354
355/* BIO_s_accept_socket() */
356#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
357#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)
358/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
359#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)
360#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
361
362#define BIO_BIND_NORMAL 0
363#define BIO_BIND_REUSEADDR_IF_UNUSED 1
364#define BIO_BIND_REUSEADDR 2
365#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
366#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
367
368#define BIO_do_connect(b) BIO_do_handshake(b)
369#define BIO_do_accept(b) BIO_do_handshake(b)
370#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
371
372/* BIO_s_proxy_client() */
373#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url))
374#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p))
375/* BIO_set_nbio(b,n) */
376#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))
377/* BIO *BIO_get_filter_bio(BIO *bio); */
378#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)()))
379#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)
380#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)
381
382#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp)
383#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p))
384#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url))
385#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL)
386
387#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
388#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
389
390#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
391#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
392
393#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
394#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
395
396/* name is cast to lose const, but might be better to route through a function
397 so we can do it safely */
398#ifdef CONST_STRICT
399/* If you are wondering why this isn't defined, its because CONST_STRICT is
400 * purely a compile-time kludge to allow const to be checked.
401 */
402int BIO_read_filename(BIO *b,const char *name);
403#else
404#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
405 BIO_CLOSE|BIO_FP_READ,(char *)name)
406#endif
407#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
408 BIO_CLOSE|BIO_FP_WRITE,name)
409#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
410 BIO_CLOSE|BIO_FP_APPEND,name)
411#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
412 BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
413
414/* WARNING WARNING, this ups the reference count on the read bio of the
415 * SSL structure. This is because the ssl read BIO is now pointed to by
416 * the next_bio field in the bio. So when you free the BIO, make sure
417 * you are doing a BIO_free_all() to catch the underlying BIO. */
418#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
419#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
420#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
421#define BIO_set_ssl_renegotiate_bytes(b,num) \
422 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);
423#define BIO_get_num_renegotiates(b) \
424 BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL);
425#define BIO_set_ssl_renegotiate_timeout(b,seconds) \
426 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);
427
428/* defined in evp.h */
429/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
430
431#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
432#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
433#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
434#define BIO_set_mem_eof_return(b,v) \
435 BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
436
437/* For the BIO_f_buffer() type */
438#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
439#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
440#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
441#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
442#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
443
444/* Don't use the next one unless you know what you are doing :-) */
445#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
446
447#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
448#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
449#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
450#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
451#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
452#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
453/* ...pending macros have inappropriate return type */
454size_t BIO_ctrl_pending(BIO *b);
455size_t BIO_ctrl_wpending(BIO *b);
456#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
457#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(void (**)())(cbp))
458#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,(void (*)())(cb))
459
460/* For the BIO_f_buffer() type */
461#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
462
463/* For BIO_s_bio() */
464#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
465#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
466#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
467#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
468/* macros with inappropriate type -- but ...pending macros use int too: */
469#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
470#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
471size_t BIO_ctrl_get_write_guarantee(BIO *b);
472size_t BIO_ctrl_get_read_request(BIO *b);
473int BIO_ctrl_reset_read_request(BIO *b);
474
475#ifdef NO_STDIO
476#define NO_FP_API
477#endif
478
479
480/* These two aren't currently implemented */
481/* int BIO_get_ex_num(BIO *bio); */
482/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
483int BIO_set_ex_data(BIO *bio,int idx,void *data);
484void *BIO_get_ex_data(BIO *bio,int idx);
485int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
486 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
487unsigned long BIO_number_read(BIO *bio);
488unsigned long BIO_number_written(BIO *bio);
489
490# if defined(WIN16) && defined(_WINDLL)
491BIO_METHOD *BIO_s_file_internal(void);
492BIO *BIO_new_file_internal(char *filename, char *mode);
493BIO *BIO_new_fp_internal(FILE *stream, int close_flag);
494# define BIO_s_file BIO_s_file_internal
495# define BIO_new_file BIO_new_file_internal
496# define BIO_new_fp BIO_new_fp_internal
497# else /* FP_API */
498BIO_METHOD *BIO_s_file(void );
499BIO *BIO_new_file(const char *filename, const char *mode);
500BIO *BIO_new_fp(FILE *stream, int close_flag);
501# define BIO_s_file_internal BIO_s_file
502# define BIO_new_file_internal BIO_new_file
503# define BIO_new_fp_internal BIO_s_file
504# endif /* FP_API */
505BIO * BIO_new(BIO_METHOD *type);
506int BIO_set(BIO *a,BIO_METHOD *type);
507int BIO_free(BIO *a);
508int BIO_read(BIO *b, void *data, int len);
509int BIO_gets(BIO *bp,char *buf, int size);
510int BIO_write(BIO *b, const void *data, int len);
511int BIO_puts(BIO *bp,const char *buf);
512long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
513long BIO_callback_ctrl(BIO *bp,int cmd,void (*fp)());
514char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
515long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
516BIO * BIO_push(BIO *b,BIO *append);
517BIO * BIO_pop(BIO *b);
518void BIO_free_all(BIO *a);
519BIO * BIO_find_type(BIO *b,int bio_type);
520BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
521int BIO_get_retry_reason(BIO *bio);
522BIO * BIO_dup_chain(BIO *in);
523
524int BIO_nread0(BIO *bio, char **buf);
525int BIO_nread(BIO *bio, char **buf, int num);
526int BIO_nwrite0(BIO *bio, char **buf);
527int BIO_nwrite(BIO *bio, char **buf, int num);
528
529#ifndef WIN16
530long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
531 long argl,long ret);
532#else
533long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
534 long argl,long ret);
535#endif
536
537BIO_METHOD *BIO_s_mem(void);
538BIO *BIO_new_mem_buf(void *buf, int len);
539BIO_METHOD *BIO_s_socket(void);
540BIO_METHOD *BIO_s_connect(void);
541BIO_METHOD *BIO_s_accept(void);
542BIO_METHOD *BIO_s_fd(void);
543BIO_METHOD *BIO_s_log(void);
544BIO_METHOD *BIO_s_bio(void);
545BIO_METHOD *BIO_s_null(void);
546BIO_METHOD *BIO_f_null(void);
547BIO_METHOD *BIO_f_buffer(void);
548BIO_METHOD *BIO_f_nbio_test(void);
549/* BIO_METHOD *BIO_f_ber(void); */
550
551int BIO_sock_should_retry(int i);
552int BIO_sock_non_fatal_error(int error);
553int BIO_fd_should_retry(int i);
554int BIO_fd_non_fatal_error(int error);
555int BIO_dump(BIO *b,const char *bytes,int len);
556
557struct hostent *BIO_gethostbyname(const char *name);
558/* We might want a thread-safe interface too:
559 * struct hostent *BIO_gethostbyname_r(const char *name,
560 * struct hostent *result, void *buffer, size_t buflen);
561 * or something similar (caller allocates a struct hostent,
562 * pointed to by "result", and additional buffer space for the various
563 * substructures; if the buffer does not suffice, NULL is returned
564 * and an appropriate error code is set).
565 */
566int BIO_sock_error(int sock);
567int BIO_socket_ioctl(int fd, long type, unsigned long *arg);
568int BIO_socket_nbio(int fd,int mode);
569int BIO_get_port(const char *str, unsigned short *port_ptr);
570int BIO_get_host_ip(const char *str, unsigned char *ip);
571int BIO_get_accept_socket(char *host_port,int mode);
572int BIO_accept(int sock,char **ip_port);
573int BIO_sock_init(void );
574void BIO_sock_cleanup(void);
575int BIO_set_tcp_ndelay(int sock,int turn_on);
576
577void ERR_load_BIO_strings(void );
578
579BIO *BIO_new_socket(int sock, int close_flag);
580BIO *BIO_new_fd(int fd, int close_flag);
581BIO *BIO_new_connect(char *host_port);
582BIO *BIO_new_accept(char *host_port);
583
584int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
585 BIO **bio2, size_t writebuf2);
586/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
587 * Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
588 * Size 0 uses default value.
589 */
590
591void BIO_copy_next_retry(BIO *b);
592
593long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
594
595int BIO_printf(BIO *bio, ...);
596
597/* BEGIN ERROR CODES */
598/* The following lines are auto generated by the script mkerr.pl. Any changes
599 * made after this point may be overwritten when the script is next run.
600 */
601
602/* Error codes for the BIO functions. */
603
604/* Function codes. */
605#define BIO_F_ACPT_STATE 100
606#define BIO_F_BIO_ACCEPT 101
607#define BIO_F_BIO_BER_GET_HEADER 102
608#define BIO_F_BIO_CTRL 103
609#define BIO_F_BIO_GETHOSTBYNAME 120
610#define BIO_F_BIO_GETS 104
611#define BIO_F_BIO_GET_ACCEPT_SOCKET 105
612#define BIO_F_BIO_GET_HOST_IP 106
613#define BIO_F_BIO_GET_PORT 107
614#define BIO_F_BIO_MAKE_PAIR 121
615#define BIO_F_BIO_NEW 108
616#define BIO_F_BIO_NEW_FILE 109
617#define BIO_F_BIO_NEW_MEM_BUF 126
618#define BIO_F_BIO_NREAD 123
619#define BIO_F_BIO_NREAD0 124
620#define BIO_F_BIO_NWRITE 125
621#define BIO_F_BIO_NWRITE0 122
622#define BIO_F_BIO_PUTS 110
623#define BIO_F_BIO_READ 111
624#define BIO_F_BIO_SOCK_INIT 112
625#define BIO_F_BIO_WRITE 113
626#define BIO_F_BUFFER_CTRL 114
627#define BIO_F_CONN_CTRL 127
628#define BIO_F_CONN_STATE 115
629#define BIO_F_FILE_CTRL 116
630#define BIO_F_MEM_WRITE 117
631#define BIO_F_SSL_NEW 118
632#define BIO_F_WSASTARTUP 119
633
634/* Reason codes. */
635#define BIO_R_ACCEPT_ERROR 100
636#define BIO_R_BAD_FOPEN_MODE 101
637#define BIO_R_BAD_HOSTNAME_LOOKUP 102
638#define BIO_R_BROKEN_PIPE 124
639#define BIO_R_CONNECT_ERROR 103
640#define BIO_R_ERROR_SETTING_NBIO 104
641#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
642#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
643#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
644#define BIO_R_INVALID_ARGUMENT 125
645#define BIO_R_INVALID_IP_ADDRESS 108
646#define BIO_R_IN_USE 123
647#define BIO_R_KEEPALIVE 109
648#define BIO_R_NBIO_CONNECT_ERROR 110
649#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
650#define BIO_R_NO_HOSTNAME_SPECIFIED 112
651#define BIO_R_NO_PORT_DEFINED 113
652#define BIO_R_NO_PORT_SPECIFIED 114
653#define BIO_R_NULL_PARAMETER 115
654#define BIO_R_TAG_MISMATCH 116
655#define BIO_R_UNABLE_TO_BIND_SOCKET 117
656#define BIO_R_UNABLE_TO_CREATE_SOCKET 118
657#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119
658#define BIO_R_UNINITIALIZED 120
659#define BIO_R_UNSUPPORTED_METHOD 121
660#define BIO_R_WRITE_TO_READ_ONLY_BIO 126
661#define BIO_R_WSASTARTUP 122
662
663#ifdef __cplusplus
664}
665#endif
666#endif
667
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 f38e7b9178..0000000000
--- a/src/lib/libcrypto/bio/bio_err.c
+++ /dev/null
@@ -1,147 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/bio.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA BIO_str_functs[]=
68 {
69{ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"},
70{ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"},
71{ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"},
72{ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"},
73{ERR_PACK(0,BIO_F_BIO_GETHOSTBYNAME,0), "BIO_gethostbyname"},
74{ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"},
75{ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"},
76{ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"},
77{ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"},
78{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"},
79{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"},
80{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"},
81{ERR_PACK(0,BIO_F_BIO_NEW_MEM_BUF,0), "BIO_new_mem_buf"},
82{ERR_PACK(0,BIO_F_BIO_NREAD,0), "BIO_nread"},
83{ERR_PACK(0,BIO_F_BIO_NREAD0,0), "BIO_nread0"},
84{ERR_PACK(0,BIO_F_BIO_NWRITE,0), "BIO_nwrite"},
85{ERR_PACK(0,BIO_F_BIO_NWRITE0,0), "BIO_nwrite0"},
86{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"},
87{ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"},
88{ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"},
89{ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"},
90{ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"},
91{ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"},
92{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
93{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
94{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
95{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"},
96{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"},
97{0,NULL}
98 };
99
100static ERR_STRING_DATA BIO_str_reasons[]=
101 {
102{BIO_R_ACCEPT_ERROR ,"accept error"},
103{BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"},
104{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"},
105{BIO_R_BROKEN_PIPE ,"broken pipe"},
106{BIO_R_CONNECT_ERROR ,"connect error"},
107{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"},
108{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"},
109{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"},
110{BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"},
111{BIO_R_INVALID_ARGUMENT ,"invalid argument"},
112{BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"},
113{BIO_R_IN_USE ,"in use"},
114{BIO_R_KEEPALIVE ,"keepalive"},
115{BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"},
116{BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"},
117{BIO_R_NO_HOSTNAME_SPECIFIED ,"no hostname specified"},
118{BIO_R_NO_PORT_DEFINED ,"no port defined"},
119{BIO_R_NO_PORT_SPECIFIED ,"no port specified"},
120{BIO_R_NULL_PARAMETER ,"null parameter"},
121{BIO_R_TAG_MISMATCH ,"tag mismatch"},
122{BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"},
123{BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"},
124{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
125{BIO_R_UNINITIALIZED ,"uninitialized"},
126{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
127{BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only bio"},
128{BIO_R_WSASTARTUP ,"wsastartup"},
129{0,NULL}
130 };
131
132#endif
133
134void ERR_load_BIO_strings(void)
135 {
136 static int init=1;
137
138 if (init)
139 {
140 init=0;
141#ifndef NO_ERR
142 ERR_load_strings(ERR_LIB_BIO,BIO_str_functs);
143 ERR_load_strings(ERR_LIB_BIO,BIO_str_reasons);
144#endif
145
146 }
147 }
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
deleted file mode 100644
index e88dcc80f3..0000000000
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ /dev/null
@@ -1,534 +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_OF(CRYPTO_EX_DATA_FUNCS) *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,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,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 void *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
320long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)())
321 {
322 long ret;
323 long (*cb)();
324
325 if (b == NULL) return(0);
326
327 if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
328 {
329 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
330 return(-2);
331 }
332
333 cb=b->callback;
334
335 if ((cb != NULL) &&
336 ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0))
337 return(ret);
338
339 ret=b->method->callback_ctrl(b,cmd,fp);
340
341 if (cb != NULL)
342 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd,
343 0,ret);
344 return(ret);
345 }
346
347/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
348 * do; but those macros have inappropriate return type, and for interfacing
349 * from other programming languages, C macros aren't much of a help anyway. */
350size_t BIO_ctrl_pending(BIO *bio)
351 {
352 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
353 }
354
355size_t BIO_ctrl_wpending(BIO *bio)
356 {
357 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
358 }
359
360
361/* put the 'bio' on the end of b's list of operators */
362BIO *BIO_push(BIO *b, BIO *bio)
363 {
364 BIO *lb;
365
366 if (b == NULL) return(bio);
367 lb=b;
368 while (lb->next_bio != NULL)
369 lb=lb->next_bio;
370 lb->next_bio=bio;
371 if (bio != NULL)
372 bio->prev_bio=lb;
373 /* called to do internal processing */
374 BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL);
375 return(b);
376 }
377
378/* Remove the first and return the rest */
379BIO *BIO_pop(BIO *b)
380 {
381 BIO *ret;
382
383 if (b == NULL) return(NULL);
384 ret=b->next_bio;
385
386 if (b->prev_bio != NULL)
387 b->prev_bio->next_bio=b->next_bio;
388 if (b->next_bio != NULL)
389 b->next_bio->prev_bio=b->prev_bio;
390
391 b->next_bio=NULL;
392 b->prev_bio=NULL;
393 BIO_ctrl(b,BIO_CTRL_POP,0,NULL);
394 return(ret);
395 }
396
397BIO *BIO_get_retry_BIO(BIO *bio, int *reason)
398 {
399 BIO *b,*last;
400
401 b=last=bio;
402 for (;;)
403 {
404 if (!BIO_should_retry(b)) break;
405 last=b;
406 b=b->next_bio;
407 if (b == NULL) break;
408 }
409 if (reason != NULL) *reason=last->retry_reason;
410 return(last);
411 }
412
413int BIO_get_retry_reason(BIO *bio)
414 {
415 return(bio->retry_reason);
416 }
417
418BIO *BIO_find_type(BIO *bio, int type)
419 {
420 int mt,mask;
421
422 mask=type&0xff;
423 do {
424 if (bio->method != NULL)
425 {
426 mt=bio->method->type;
427
428 if (!mask)
429 {
430 if (mt & type) return(bio);
431 }
432 else if (mt == type)
433 return(bio);
434 }
435 bio=bio->next_bio;
436 } while (bio != NULL);
437 return(NULL);
438 }
439
440void BIO_free_all(BIO *bio)
441 {
442 BIO *b;
443 int ref;
444
445 while (bio != NULL)
446 {
447 b=bio;
448 ref=b->references;
449 bio=bio->next_bio;
450 BIO_free(b);
451 /* Since ref count > 1, don't free anyone else. */
452 if (ref > 1) break;
453 }
454 }
455
456BIO *BIO_dup_chain(BIO *in)
457 {
458 BIO *ret=NULL,*eoc=NULL,*bio,*new;
459
460 for (bio=in; bio != NULL; bio=bio->next_bio)
461 {
462 if ((new=BIO_new(bio->method)) == NULL) goto err;
463 new->callback=bio->callback;
464 new->cb_arg=bio->cb_arg;
465 new->init=bio->init;
466 new->shutdown=bio->shutdown;
467 new->flags=bio->flags;
468
469 /* This will let SSL_s_sock() work with stdin/stdout */
470 new->num=bio->num;
471
472 if (!BIO_dup_state(bio,(char *)new))
473 {
474 BIO_free(new);
475 goto err;
476 }
477
478 /* copy app data */
479 if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data))
480 goto err;
481
482 if (ret == NULL)
483 {
484 eoc=new;
485 ret=eoc;
486 }
487 else
488 {
489 BIO_push(eoc,new);
490 eoc=new;
491 }
492 }
493 return(ret);
494err:
495 if (ret != NULL)
496 BIO_free(ret);
497 return(NULL);
498 }
499
500void BIO_copy_next_retry(BIO *b)
501 {
502 BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
503 b->retry_reason=b->next_bio->retry_reason;
504 }
505
506int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
507 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
508 {
509 bio_meth_num++;
510 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth,
511 argl,argp,new_func,dup_func,free_func));
512 }
513
514int BIO_set_ex_data(BIO *bio, int idx, void *data)
515 {
516 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
517 }
518
519void *BIO_get_ex_data(BIO *bio, int idx)
520 {
521 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
522 }
523
524unsigned long BIO_number_read(BIO *bio)
525{
526 if(bio) return bio->num_read;
527 return 0;
528}
529
530unsigned long BIO_number_written(BIO *bio)
531{
532 if(bio) return bio->num_write;
533 return 0;
534}
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
deleted file mode 100644
index 9afa636406..0000000000
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ /dev/null
@@ -1,467 +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 NULL,
122 };
123
124BIO_METHOD *BIO_s_accept(void)
125 {
126 return(&methods_acceptp);
127 }
128
129static int acpt_new(BIO *bi)
130 {
131 BIO_ACCEPT *ba;
132
133 bi->init=0;
134 bi->num=INVALID_SOCKET;
135 bi->flags=0;
136 if ((ba=BIO_ACCEPT_new()) == NULL)
137 return(0);
138 bi->ptr=(char *)ba;
139 ba->state=ACPT_S_BEFORE;
140 bi->shutdown=1;
141 return(1);
142 }
143
144BIO_ACCEPT *BIO_ACCEPT_new(void)
145 {
146 BIO_ACCEPT *ret;
147
148 if ((ret=(BIO_ACCEPT *)Malloc(sizeof(BIO_ACCEPT))) == NULL)
149 return(NULL);
150
151 memset(ret,0,sizeof(BIO_ACCEPT));
152 ret->accept_sock=INVALID_SOCKET;
153 ret->bind_mode=BIO_BIND_NORMAL;
154 return(ret);
155 }
156
157void BIO_ACCEPT_free(BIO_ACCEPT *a)
158 {
159 if(a == NULL)
160 return;
161
162 if (a->param_addr != NULL) Free(a->param_addr);
163 if (a->addr != NULL) Free(a->addr);
164 if (a->bio_chain != NULL) BIO_free(a->bio_chain);
165 Free(a);
166 }
167
168static void acpt_close_socket(BIO *bio)
169 {
170 BIO_ACCEPT *c;
171
172 c=(BIO_ACCEPT *)bio->ptr;
173 if (c->accept_sock != INVALID_SOCKET)
174 {
175 shutdown(c->accept_sock,2);
176 closesocket(c->accept_sock);
177 c->accept_sock=INVALID_SOCKET;
178 bio->num=INVALID_SOCKET;
179 }
180 }
181
182static int acpt_free(BIO *a)
183 {
184 BIO_ACCEPT *data;
185
186 if (a == NULL) return(0);
187 data=(BIO_ACCEPT *)a->ptr;
188
189 if (a->shutdown)
190 {
191 acpt_close_socket(a);
192 BIO_ACCEPT_free(data);
193 a->ptr=NULL;
194 a->flags=0;
195 a->init=0;
196 }
197 return(1);
198 }
199
200static int acpt_state(BIO *b, BIO_ACCEPT *c)
201 {
202 BIO *bio=NULL,*dbio;
203 int s= -1;
204 int i;
205
206again:
207 switch (c->state)
208 {
209 case ACPT_S_BEFORE:
210 if (c->param_addr == NULL)
211 {
212 BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
213 return(-1);
214 }
215 s=BIO_get_accept_socket(c->param_addr,c->bind_mode);
216 if (s == INVALID_SOCKET)
217 return(-1);
218
219 if (c->accept_nbio)
220 {
221 if (!BIO_socket_nbio(s,1))
222 {
223 closesocket(s);
224 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
225 return(-1);
226 }
227 }
228 c->accept_sock=s;
229 b->num=s;
230 c->state=ACPT_S_GET_ACCEPT_SOCKET;
231 return(1);
232 /* break; */
233 case ACPT_S_GET_ACCEPT_SOCKET:
234 if (b->next_bio != NULL)
235 {
236 c->state=ACPT_S_OK;
237 goto again;
238 }
239 i=BIO_accept(c->accept_sock,&(c->addr));
240 if (i < 0) return(i);
241 bio=BIO_new_socket(i,BIO_CLOSE);
242 if (bio == NULL) goto err;
243
244 BIO_set_callback(bio,BIO_get_callback(b));
245 BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
246
247 if (c->nbio)
248 {
249 if (!BIO_socket_nbio(i,1))
250 {
251 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
252 goto err;
253 }
254 }
255
256 /* If the accept BIO has an bio_chain, we dup it and
257 * put the new socket at the end. */
258 if (c->bio_chain != NULL)
259 {
260 if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
261 goto err;
262 if (!BIO_push(dbio,bio)) goto err;
263 bio=dbio;
264 }
265 if (BIO_push(b,bio) == NULL) goto err;
266
267 c->state=ACPT_S_OK;
268 return(1);
269err:
270 if (bio != NULL)
271 BIO_free(bio);
272 else if (s >= 0)
273 closesocket(s);
274 return(0);
275 /* break; */
276 case ACPT_S_OK:
277 if (b->next_bio == NULL)
278 {
279 c->state=ACPT_S_GET_ACCEPT_SOCKET;
280 goto again;
281 }
282 return(1);
283 /* break; */
284 default:
285 return(0);
286 /* break; */
287 }
288
289 }
290
291static int acpt_read(BIO *b, char *out, int outl)
292 {
293 int ret=0;
294 BIO_ACCEPT *data;
295
296 BIO_clear_retry_flags(b);
297 data=(BIO_ACCEPT *)b->ptr;
298
299 while (b->next_bio == NULL)
300 {
301 ret=acpt_state(b,data);
302 if (ret <= 0) return(ret);
303 }
304
305 ret=BIO_read(b->next_bio,out,outl);
306 BIO_copy_next_retry(b);
307 return(ret);
308 }
309
310static int acpt_write(BIO *b, char *in, int inl)
311 {
312 int ret;
313 BIO_ACCEPT *data;
314
315 BIO_clear_retry_flags(b);
316 data=(BIO_ACCEPT *)b->ptr;
317
318 while (b->next_bio == NULL)
319 {
320 ret=acpt_state(b,data);
321 if (ret <= 0) return(ret);
322 }
323
324 ret=BIO_write(b->next_bio,in,inl);
325 BIO_copy_next_retry(b);
326 return(ret);
327 }
328
329static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr)
330 {
331 BIO *dbio;
332 int *ip;
333 long ret=1;
334 BIO_ACCEPT *data;
335 char **pp;
336
337 data=(BIO_ACCEPT *)b->ptr;
338
339 switch (cmd)
340 {
341 case BIO_CTRL_RESET:
342 ret=0;
343 data->state=ACPT_S_BEFORE;
344 acpt_close_socket(b);
345 b->flags=0;
346 break;
347 case BIO_C_DO_STATE_MACHINE:
348 /* use this one to start the connection */
349 ret=(long)acpt_state(b,data);
350 break;
351 case BIO_C_SET_ACCEPT:
352 if (ptr != NULL)
353 {
354 if (num == 0)
355 {
356 b->init=1;
357 if (data->param_addr != NULL)
358 Free(data->param_addr);
359 data->param_addr=BUF_strdup(ptr);
360 }
361 else if (num == 1)
362 {
363 data->accept_nbio=(ptr != NULL);
364 }
365 else if (num == 2)
366 {
367 if (data->bio_chain != NULL)
368 BIO_free(data->bio_chain);
369 data->bio_chain=(BIO *)ptr;
370 }
371 }
372 break;
373 case BIO_C_SET_NBIO:
374 data->nbio=(int)num;
375 break;
376 case BIO_C_SET_FD:
377 b->init=1;
378 b->num= *((int *)ptr);
379 data->accept_sock=b->num;
380 data->state=ACPT_S_GET_ACCEPT_SOCKET;
381 b->shutdown=(int)num;
382 b->init=1;
383 break;
384 case BIO_C_GET_FD:
385 if (b->init)
386 {
387 ip=(int *)ptr;
388 if (ip != NULL)
389 *ip=data->accept_sock;
390 ret=data->accept_sock;
391 }
392 else
393 ret= -1;
394 break;
395 case BIO_C_GET_ACCEPT:
396 if (b->init)
397 {
398 if (ptr != NULL)
399 {
400 pp=(char **)ptr;
401 *pp=data->param_addr;
402 }
403 else
404 ret= -1;
405 }
406 else
407 ret= -1;
408 break;
409 case BIO_CTRL_GET_CLOSE:
410 ret=b->shutdown;
411 break;
412 case BIO_CTRL_SET_CLOSE:
413 b->shutdown=(int)num;
414 break;
415 case BIO_CTRL_PENDING:
416 case BIO_CTRL_WPENDING:
417 ret=0;
418 break;
419 case BIO_CTRL_FLUSH:
420 break;
421 case BIO_C_SET_BIND_MODE:
422 data->bind_mode=(int)num;
423 break;
424 case BIO_C_GET_BIND_MODE:
425 ret=(long)data->bind_mode;
426 break;
427 case BIO_CTRL_DUP:
428 dbio=(BIO *)ptr;
429/* if (data->param_port) EAY EAY
430 BIO_set_port(dbio,data->param_port);
431 if (data->param_hostname)
432 BIO_set_hostname(dbio,data->param_hostname);
433 BIO_set_nbio(dbio,data->nbio); */
434 break;
435
436 default:
437 ret=0;
438 break;
439 }
440 return(ret);
441 }
442
443static int acpt_puts(BIO *bp, char *str)
444 {
445 int n,ret;
446
447 n=strlen(str);
448 ret=acpt_write(bp,str,n);
449 return(ret);
450 }
451
452BIO *BIO_new_accept(char *str)
453 {
454 BIO *ret;
455
456 ret=BIO_new(BIO_s_accept());
457 if (ret == NULL) return(NULL);
458 if (BIO_set_accept_port(ret,str))
459 return(ret);
460 else
461 {
462 BIO_free(ret);
463 return(NULL);
464 }
465 }
466
467#endif
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
deleted file mode 100644
index 1e2d7491f2..0000000000
--- a/src/lib/libcrypto/bio/bss_bio.c
+++ /dev/null
@@ -1,857 +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 <limits.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include <openssl/bio.h>
21#include <openssl/err.h>
22#include <openssl/err.h>
23#include <openssl/crypto.h>
24
25#include "openssl/e_os.h"
26#ifndef SSIZE_MAX
27# define SSIZE_MAX INT_MAX
28#endif
29
30static int bio_new(BIO *bio);
31static int bio_free(BIO *bio);
32static int bio_read(BIO *bio, char *buf, int size);
33static int bio_write(BIO *bio, char *buf, int num);
34static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
35static int bio_puts(BIO *bio, char *str);
36
37static int bio_make_pair(BIO *bio1, BIO *bio2);
38static void bio_destroy_pair(BIO *bio);
39
40static BIO_METHOD methods_biop =
41{
42 BIO_TYPE_BIO,
43 "BIO pair",
44 bio_write,
45 bio_read,
46 bio_puts,
47 NULL /* no bio_gets */,
48 bio_ctrl,
49 bio_new,
50 bio_free,
51 NULL /* no bio_callback_ctrl */
52};
53
54BIO_METHOD *BIO_s_bio(void)
55 {
56 return &methods_biop;
57 }
58
59struct bio_bio_st
60{
61 BIO *peer; /* NULL if buf == NULL.
62 * If peer != NULL, then peer->ptr is also a bio_bio_st,
63 * and its "peer" member points back to us.
64 * peer != NULL iff init != 0 in the BIO. */
65
66 /* This is for what we write (i.e. reading uses peer's struct): */
67 int closed; /* valid iff peer != NULL */
68 size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
69 size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
70 size_t size;
71 char *buf; /* "size" elements (if != NULL) */
72
73 size_t request; /* valid iff peer != NULL; 0 if len != 0,
74 * otherwise set by peer to number of bytes
75 * it (unsuccessfully) tried to read,
76 * never more than buffer space (size-len) warrants. */
77};
78
79static int bio_new(BIO *bio)
80 {
81 struct bio_bio_st *b;
82
83 b = Malloc(sizeof *b);
84 if (b == NULL)
85 return 0;
86
87 b->peer = NULL;
88 b->size = 17*1024; /* enough for one TLS record (just a default) */
89 b->buf = NULL;
90
91 bio->ptr = b;
92 return 1;
93 }
94
95
96static int bio_free(BIO *bio)
97 {
98 struct bio_bio_st *b;
99
100 if (bio == NULL)
101 return 0;
102 b = bio->ptr;
103
104 assert(b != NULL);
105
106 if (b->peer)
107 bio_destroy_pair(bio);
108
109 if (b->buf != NULL)
110 {
111 Free(b->buf);
112 }
113
114 Free(b);
115
116 return 1;
117 }
118
119
120
121static int bio_read(BIO *bio, char *buf, int size_)
122 {
123 size_t size = size_;
124 size_t rest;
125 struct bio_bio_st *b, *peer_b;
126
127 BIO_clear_retry_flags(bio);
128
129 if (!bio->init)
130 return 0;
131
132 b = bio->ptr;
133 assert(b != NULL);
134 assert(b->peer != NULL);
135 peer_b = b->peer->ptr;
136 assert(peer_b != NULL);
137 assert(peer_b->buf != NULL);
138
139 peer_b->request = 0; /* will be set in "retry_read" situation */
140
141 if (buf == NULL || size == 0)
142 return 0;
143
144 if (peer_b->len == 0)
145 {
146 if (peer_b->closed)
147 return 0; /* writer has closed, and no data is left */
148 else
149 {
150 BIO_set_retry_read(bio); /* buffer is empty */
151 if (size <= peer_b->size)
152 peer_b->request = size;
153 else
154 /* don't ask for more than the peer can
155 * deliver in one write */
156 peer_b->request = peer_b->size;
157 return -1;
158 }
159 }
160
161 /* we can read */
162 if (peer_b->len < size)
163 size = peer_b->len;
164
165 /* now read "size" bytes */
166
167 rest = size;
168
169 assert(rest > 0);
170 do /* one or two iterations */
171 {
172 size_t chunk;
173
174 assert(rest <= peer_b->len);
175 if (peer_b->offset + rest <= peer_b->size)
176 chunk = rest;
177 else
178 /* wrap around ring buffer */
179 chunk = peer_b->size - peer_b->offset;
180 assert(peer_b->offset + chunk <= peer_b->size);
181
182 memcpy(buf, peer_b->buf + peer_b->offset, chunk);
183
184 peer_b->len -= chunk;
185 if (peer_b->len)
186 {
187 peer_b->offset += chunk;
188 assert(peer_b->offset <= peer_b->size);
189 if (peer_b->offset == peer_b->size)
190 peer_b->offset = 0;
191 buf += chunk;
192 }
193 else
194 {
195 /* buffer now empty, no need to advance "buf" */
196 assert(chunk == rest);
197 peer_b->offset = 0;
198 }
199 rest -= chunk;
200 }
201 while (rest);
202
203 return size;
204 }
205
206/* non-copying interface: provide pointer to available data in buffer
207 * bio_nread0: return number of available bytes
208 * bio_nread: also advance index
209 * (example usage: bio_nread0(), read from buffer, bio_nread()
210 * or just bio_nread(), read from buffer)
211 */
212/* WARNING: The non-copying interface is largely untested as of yet
213 * and may contain bugs. */
214static ssize_t bio_nread0(BIO *bio, char **buf)
215 {
216 struct bio_bio_st *b, *peer_b;
217 ssize_t num;
218
219 BIO_clear_retry_flags(bio);
220
221 if (!bio->init)
222 return 0;
223
224 b = bio->ptr;
225 assert(b != NULL);
226 assert(b->peer != NULL);
227 peer_b = b->peer->ptr;
228 assert(peer_b != NULL);
229 assert(peer_b->buf != NULL);
230
231 peer_b->request = 0;
232
233 if (peer_b->len == 0)
234 {
235 char dummy;
236
237 /* avoid code duplication -- nothing available for reading */
238 return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
239 }
240
241 num = peer_b->len;
242 if (peer_b->size < peer_b->offset + num)
243 /* no ring buffer wrap-around for non-copying interface */
244 num = peer_b->size - peer_b->offset;
245 assert(num > 0);
246
247 if (buf != NULL)
248 *buf = peer_b->buf + peer_b->offset;
249 return num;
250 }
251
252static ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
253 {
254 struct bio_bio_st *b, *peer_b;
255 ssize_t num, available;
256
257 if (num_ > SSIZE_MAX)
258 num = SSIZE_MAX;
259 else
260 num = (ssize_t)num_;
261
262 available = bio_nread0(bio, buf);
263 if (num > available)
264 num = available;
265 if (num <= 0)
266 return num;
267
268 b = bio->ptr;
269 peer_b = b->peer->ptr;
270
271 peer_b->len -= num;
272 if (peer_b->len)
273 {
274 peer_b->offset += num;
275 assert(peer_b->offset <= peer_b->size);
276 if (peer_b->offset == peer_b->size)
277 peer_b->offset = 0;
278 }
279 else
280 peer_b->offset = 0;
281
282 return num;
283 }
284
285
286static int bio_write(BIO *bio, char *buf, int num_)
287 {
288 size_t num = num_;
289 size_t rest;
290 struct bio_bio_st *b;
291
292 BIO_clear_retry_flags(bio);
293
294 if (!bio->init || buf == NULL || num == 0)
295 return 0;
296
297 b = bio->ptr;
298 assert(b != NULL);
299 assert(b->peer != NULL);
300 assert(b->buf != NULL);
301
302 b->request = 0;
303 if (b->closed)
304 {
305 /* we already closed */
306 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
307 return -1;
308 }
309
310 assert(b->len <= b->size);
311
312 if (b->len == b->size)
313 {
314 BIO_set_retry_write(bio); /* buffer is full */
315 return -1;
316 }
317
318 /* we can write */
319 if (num > b->size - b->len)
320 num = b->size - b->len;
321
322 /* now write "num" bytes */
323
324 rest = num;
325
326 assert(rest > 0);
327 do /* one or two iterations */
328 {
329 size_t write_offset;
330 size_t chunk;
331
332 assert(b->len + rest <= b->size);
333
334 write_offset = b->offset + b->len;
335 if (write_offset >= b->size)
336 write_offset -= b->size;
337 /* b->buf[write_offset] is the first byte we can write to. */
338
339 if (write_offset + rest <= b->size)
340 chunk = rest;
341 else
342 /* wrap around ring buffer */
343 chunk = b->size - write_offset;
344
345 memcpy(b->buf + write_offset, buf, chunk);
346
347 b->len += chunk;
348
349 assert(b->len <= b->size);
350
351 rest -= chunk;
352 buf += chunk;
353 }
354 while (rest);
355
356 return num;
357 }
358
359/* non-copying interface: provide pointer to region to write to
360 * bio_nwrite0: check how much space is available
361 * bio_nwrite: also increase length
362 * (example usage: bio_nwrite0(), write to buffer, bio_nwrite()
363 * or just bio_nwrite(), write to buffer)
364 */
365static ssize_t bio_nwrite0(BIO *bio, char **buf)
366 {
367 struct bio_bio_st *b;
368 size_t num;
369 size_t write_offset;
370
371 BIO_clear_retry_flags(bio);
372
373 if (!bio->init)
374 return 0;
375
376 b = bio->ptr;
377 assert(b != NULL);
378 assert(b->peer != NULL);
379 assert(b->buf != NULL);
380
381 b->request = 0;
382 if (b->closed)
383 {
384 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE);
385 return -1;
386 }
387
388 assert(b->len <= b->size);
389
390 if (b->len == b->size)
391 {
392 BIO_set_retry_write(bio);
393 return -1;
394 }
395
396 num = b->size - b->len;
397 write_offset = b->offset + b->len;
398 if (write_offset >= b->size)
399 write_offset -= b->size;
400 if (write_offset + num > b->size)
401 /* no ring buffer wrap-around for non-copying interface
402 * (to fulfil the promise by BIO_ctrl_get_write_guarantee,
403 * BIO_nwrite may have to be called twice) */
404 num = b->size - write_offset;
405
406 if (buf != NULL)
407 *buf = b->buf + write_offset;
408 assert(write_offset + num <= b->size);
409
410 return num;
411 }
412
413static ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_)
414 {
415 struct bio_bio_st *b;
416 ssize_t num, space;
417
418 if (num_ > SSIZE_MAX)
419 num = SSIZE_MAX;
420 else
421 num = (ssize_t)num_;
422
423 space = bio_nwrite0(bio, buf);
424 if (num > space)
425 num = space;
426 if (num <= 0)
427 return num;
428 b = bio->ptr;
429 assert(b != NULL);
430 b->len += num;
431 assert(b->len <= b->size);
432
433 return num;
434 }
435
436
437static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
438 {
439 long ret;
440 struct bio_bio_st *b = bio->ptr;
441
442 assert(b != NULL);
443
444 switch (cmd)
445 {
446 /* specific CTRL codes */
447
448 case BIO_C_SET_WRITE_BUF_SIZE:
449 if (b->peer)
450 {
451 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
452 ret = 0;
453 }
454 else if (num == 0)
455 {
456 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
457 ret = 0;
458 }
459 else
460 {
461 size_t new_size = num;
462
463 if (b->size != new_size)
464 {
465 if (b->buf)
466 {
467 Free(b->buf);
468 b->buf = NULL;
469 }
470 b->size = new_size;
471 }
472 ret = 1;
473 }
474 break;
475
476 case BIO_C_GET_WRITE_BUF_SIZE:
477 num = (long) b->size;
478
479 case BIO_C_MAKE_BIO_PAIR:
480 {
481 BIO *other_bio = ptr;
482
483 if (bio_make_pair(bio, other_bio))
484 ret = 1;
485 else
486 ret = 0;
487 }
488 break;
489
490 case BIO_C_DESTROY_BIO_PAIR:
491 /* Effects both BIOs in the pair -- call just once!
492 * Or let BIO_free(bio1); BIO_free(bio2); do the job. */
493 bio_destroy_pair(bio);
494 ret = 1;
495 break;
496
497 case BIO_C_GET_WRITE_GUARANTEE:
498 /* How many bytes can the caller feed to the next write
499 * without having to keep any? */
500 if (b->peer == NULL || b->closed)
501 ret = 0;
502 else
503 ret = (long) b->size - b->len;
504 break;
505
506 case BIO_C_GET_READ_REQUEST:
507 /* If the peer unsuccessfully tried to read, how many bytes
508 * were requested? (As with BIO_CTRL_PENDING, that number
509 * can usually be treated as boolean.) */
510 ret = (long) b->request;
511 break;
512
513 case BIO_C_RESET_READ_REQUEST:
514 /* Reset request. (Can be useful after read attempts
515 * at the other side that are meant to be non-blocking,
516 * e.g. when probing SSL_read to see if any data is
517 * available.) */
518 b->request = 0;
519 ret = 1;
520 break;
521
522 case BIO_C_SHUTDOWN_WR:
523 /* similar to shutdown(..., SHUT_WR) */
524 b->closed = 1;
525 ret = 1;
526 break;
527
528 case BIO_C_NREAD0:
529 /* prepare for non-copying read */
530 ret = (long) bio_nread0(bio, ptr);
531 break;
532
533 case BIO_C_NREAD:
534 /* non-copying read */
535 ret = (long) bio_nread(bio, ptr, (size_t) num);
536 break;
537
538 case BIO_C_NWRITE0:
539 /* prepare for non-copying write */
540 ret = (long) bio_nwrite0(bio, ptr);
541 break;
542
543 case BIO_C_NWRITE:
544 /* non-copying write */
545 ret = (long) bio_nwrite(bio, ptr, (size_t) num);
546 break;
547
548
549 /* standard CTRL codes follow */
550
551 case BIO_CTRL_RESET:
552 if (b->buf != NULL)
553 {
554 b->len = 0;
555 b->offset = 0;
556 }
557 ret = 0;
558 break;
559
560 case BIO_CTRL_GET_CLOSE:
561 ret = bio->shutdown;
562 break;
563
564 case BIO_CTRL_SET_CLOSE:
565 bio->shutdown = (int) num;
566 ret = 1;
567 break;
568
569 case BIO_CTRL_PENDING:
570 if (b->peer != NULL)
571 {
572 struct bio_bio_st *peer_b = b->peer->ptr;
573
574 ret = (long) peer_b->len;
575 }
576 else
577 ret = 0;
578 break;
579
580 case BIO_CTRL_WPENDING:
581 if (b->buf != NULL)
582 ret = (long) b->len;
583 else
584 ret = 0;
585 break;
586
587 case BIO_CTRL_DUP:
588 /* See BIO_dup_chain for circumstances we have to expect. */
589 {
590 BIO *other_bio = ptr;
591 struct bio_bio_st *other_b;
592
593 assert(other_bio != NULL);
594 other_b = other_bio->ptr;
595 assert(other_b != NULL);
596
597 assert(other_b->buf == NULL); /* other_bio is always fresh */
598
599 other_b->size = b->size;
600 }
601
602 ret = 1;
603 break;
604
605 case BIO_CTRL_FLUSH:
606 ret = 1;
607 break;
608
609 case BIO_CTRL_EOF:
610 {
611 BIO *other_bio = ptr;
612
613 if (other_bio)
614 {
615 struct bio_bio_st *other_b = other_bio->ptr;
616
617 assert(other_b != NULL);
618 ret = other_b->len == 0 && other_b->closed;
619 }
620 else
621 ret = 1;
622 }
623 break;
624
625 default:
626 ret = 0;
627 }
628 return ret;
629 }
630
631static int bio_puts(BIO *bio, char *str)
632 {
633 return bio_write(bio, str, strlen(str));
634 }
635
636
637static int bio_make_pair(BIO *bio1, BIO *bio2)
638 {
639 struct bio_bio_st *b1, *b2;
640
641 assert(bio1 != NULL);
642 assert(bio2 != NULL);
643
644 b1 = bio1->ptr;
645 b2 = bio2->ptr;
646
647 if (b1->peer != NULL || b2->peer != NULL)
648 {
649 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
650 return 0;
651 }
652
653 if (b1->buf == NULL)
654 {
655 b1->buf = Malloc(b1->size);
656 if (b1->buf == NULL)
657 {
658 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
659 return 0;
660 }
661 b1->len = 0;
662 b1->offset = 0;
663 }
664
665 if (b2->buf == NULL)
666 {
667 b2->buf = Malloc(b2->size);
668 if (b2->buf == NULL)
669 {
670 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
671 return 0;
672 }
673 b2->len = 0;
674 b2->offset = 0;
675 }
676
677 b1->peer = bio2;
678 b1->closed = 0;
679 b1->request = 0;
680 b2->peer = bio1;
681 b2->closed = 0;
682 b2->request = 0;
683
684 bio1->init = 1;
685 bio2->init = 1;
686
687 return 1;
688 }
689
690static void bio_destroy_pair(BIO *bio)
691 {
692 struct bio_bio_st *b = bio->ptr;
693
694 if (b != NULL)
695 {
696 BIO *peer_bio = b->peer;
697
698 if (peer_bio != NULL)
699 {
700 struct bio_bio_st *peer_b = peer_bio->ptr;
701
702 assert(peer_b != NULL);
703 assert(peer_b->peer == bio);
704
705 peer_b->peer = NULL;
706 peer_bio->init = 0;
707 assert(peer_b->buf != NULL);
708 peer_b->len = 0;
709 peer_b->offset = 0;
710
711 b->peer = NULL;
712 bio->init = 0;
713 assert(b->buf != NULL);
714 b->len = 0;
715 b->offset = 0;
716 }
717 }
718 }
719
720
721/* Exported convenience functions */
722int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
723 BIO **bio2_p, size_t writebuf2)
724 {
725 BIO *bio1 = NULL, *bio2 = NULL;
726 long r;
727 int ret = 0;
728
729 bio1 = BIO_new(BIO_s_bio());
730 if (bio1 == NULL)
731 goto err;
732 bio2 = BIO_new(BIO_s_bio());
733 if (bio2 == NULL)
734 goto err;
735
736 if (writebuf1)
737 {
738 r = BIO_set_write_buf_size(bio1, writebuf1);
739 if (!r)
740 goto err;
741 }
742 if (writebuf2)
743 {
744 r = BIO_set_write_buf_size(bio2, writebuf2);
745 if (!r)
746 goto err;
747 }
748
749 r = BIO_make_bio_pair(bio1, bio2);
750 if (!r)
751 goto err;
752 ret = 1;
753
754 err:
755 if (ret == 0)
756 {
757 if (bio1)
758 {
759 BIO_free(bio1);
760 bio1 = NULL;
761 }
762 if (bio2)
763 {
764 BIO_free(bio2);
765 bio2 = NULL;
766 }
767 }
768
769 *bio1_p = bio1;
770 *bio2_p = bio2;
771 return ret;
772 }
773
774size_t BIO_ctrl_get_write_guarantee(BIO *bio)
775 {
776 return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
777 }
778
779size_t BIO_ctrl_get_read_request(BIO *bio)
780 {
781 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
782 }
783
784int BIO_ctrl_reset_read_request(BIO *bio)
785 {
786 return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
787 }
788
789
790/* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now
791 * (conceivably some other BIOs could allow non-copying reads and writes too.)
792 */
793int BIO_nread0(BIO *bio, char **buf)
794 {
795 long ret;
796
797 if (!bio->init)
798 {
799 BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED);
800 return -2;
801 }
802
803 ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf);
804 if (ret > INT_MAX)
805 return INT_MAX;
806 else
807 return (int) ret;
808 }
809
810int BIO_nread(BIO *bio, char **buf, int num)
811 {
812 int ret;
813
814 if (!bio->init)
815 {
816 BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED);
817 return -2;
818 }
819
820 ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf);
821 if (ret > 0)
822 bio->num_read += ret;
823 return ret;
824 }
825
826int BIO_nwrite0(BIO *bio, char **buf)
827 {
828 long ret;
829
830 if (!bio->init)
831 {
832 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED);
833 return -2;
834 }
835
836 ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf);
837 if (ret > INT_MAX)
838 return INT_MAX;
839 else
840 return (int) ret;
841 }
842
843int BIO_nwrite(BIO *bio, char **buf, int num)
844 {
845 int ret;
846
847 if (!bio->init)
848 {
849 BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED);
850 return -2;
851 }
852
853 ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf);
854 if (ret > 0)
855 bio->num_read += ret;
856 return ret;
857 }
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
deleted file mode 100644
index 22d00b369e..0000000000
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ /dev/null
@@ -1,650 +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 * compatible 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 compatibility 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);
107static long conn_callback_ctrl(BIO *h,int cmd,void *(*fp)());
108
109static int conn_state(BIO *b, BIO_CONNECT *c);
110static void conn_close_socket(BIO *data);
111BIO_CONNECT *BIO_CONNECT_new(void );
112void BIO_CONNECT_free(BIO_CONNECT *a);
113
114static BIO_METHOD methods_connectp=
115 {
116 BIO_TYPE_CONNECT,
117 "socket connect",
118 conn_write,
119 conn_read,
120 conn_puts,
121 NULL, /* connect_gets, */
122 conn_ctrl,
123 conn_new,
124 conn_free,
125 conn_callback_ctrl,
126 };
127
128static int conn_state(BIO *b, BIO_CONNECT *c)
129 {
130 int ret= -1,i;
131 unsigned long l;
132 char *p,*q;
133 int (*cb)()=NULL;
134
135 if (c->info_callback != NULL)
136 cb=c->info_callback;
137
138 for (;;)
139 {
140 switch (c->state)
141 {
142 case BIO_CONN_S_BEFORE:
143 p=c->param_hostname;
144 if (p == NULL)
145 {
146 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED);
147 goto exit_loop;
148 }
149 for ( ; *p != '\0'; p++)
150 {
151 if ((*p == ':') || (*p == '/')) break;
152 }
153
154 i= *p;
155 if ((i == ':') || (i == '/'))
156 {
157
158 *(p++)='\0';
159 if (i == ':')
160 {
161 for (q=p; *q; q++)
162 if (*q == '/')
163 {
164 *q='\0';
165 break;
166 }
167 if (c->param_port != NULL)
168 Free(c->param_port);
169 c->param_port=BUF_strdup(p);
170 }
171 }
172
173 if (c->param_port == NULL)
174 {
175 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);
176 ERR_add_error_data(2,"host=",c->param_hostname);
177 goto exit_loop;
178 }
179 c->state=BIO_CONN_S_GET_IP;
180 break;
181
182 case BIO_CONN_S_GET_IP:
183 if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0)
184 goto exit_loop;
185 c->state=BIO_CONN_S_GET_PORT;
186 break;
187
188 case BIO_CONN_S_GET_PORT:
189 if (c->param_port == NULL)
190 {
191 abort();
192 goto exit_loop;
193 }
194 else if (BIO_get_port(c->param_port,&c->port) <= 0)
195 goto exit_loop;
196 c->state=BIO_CONN_S_CREATE_SOCKET;
197 break;
198
199 case BIO_CONN_S_CREATE_SOCKET:
200 /* now setup address */
201 memset((char *)&c->them,0,sizeof(c->them));
202 c->them.sin_family=AF_INET;
203 c->them.sin_port=htons((unsigned short)c->port);
204 l=(unsigned long)
205 ((unsigned long)c->ip[0]<<24L)|
206 ((unsigned long)c->ip[1]<<16L)|
207 ((unsigned long)c->ip[2]<< 8L)|
208 ((unsigned long)c->ip[3]);
209 c->them.sin_addr.s_addr=htonl(l);
210 c->state=BIO_CONN_S_CREATE_SOCKET;
211
212 ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
213 if (ret == INVALID_SOCKET)
214 {
215 SYSerr(SYS_F_SOCKET,get_last_socket_error());
216 ERR_add_error_data(4,"host=",c->param_hostname,
217 ":",c->param_port);
218 BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET);
219 goto exit_loop;
220 }
221 b->num=ret;
222 c->state=BIO_CONN_S_NBIO;
223 break;
224
225 case BIO_CONN_S_NBIO:
226 if (c->nbio)
227 {
228 if (!BIO_socket_nbio(b->num,1))
229 {
230 BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);
231 ERR_add_error_data(4,"host=",
232 c->param_hostname,
233 ":",c->param_port);
234 goto exit_loop;
235 }
236 }
237 c->state=BIO_CONN_S_CONNECT;
238
239#ifdef SO_KEEPALIVE
240 i=1;
241 i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
242 if (i < 0)
243 {
244 SYSerr(SYS_F_SOCKET,get_last_socket_error());
245 ERR_add_error_data(4,"host=",c->param_hostname,
246 ":",c->param_port);
247 BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE);
248 goto exit_loop;
249 }
250#endif
251 break;
252
253 case BIO_CONN_S_CONNECT:
254 BIO_clear_retry_flags(b);
255 ret=connect(b->num,
256 (struct sockaddr *)&c->them,
257 sizeof(c->them));
258 b->retry_reason=0;
259 if (ret < 0)
260 {
261 if (BIO_sock_should_retry(ret))
262 {
263 BIO_set_retry_special(b);
264 c->state=BIO_CONN_S_BLOCKED_CONNECT;
265 b->retry_reason=BIO_RR_CONNECT;
266 }
267 else
268 {
269 SYSerr(SYS_F_CONNECT,get_last_socket_error());
270 ERR_add_error_data(4,"host=",
271 c->param_hostname,
272 ":",c->param_port);
273 BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR);
274 }
275 goto exit_loop;
276 }
277 else
278 c->state=BIO_CONN_S_OK;
279 break;
280
281 case BIO_CONN_S_BLOCKED_CONNECT:
282 i=BIO_sock_error(b->num);
283 if (i)
284 {
285 BIO_clear_retry_flags(b);
286 SYSerr(SYS_F_CONNECT,i);
287 ERR_add_error_data(4,"host=",
288 c->param_hostname,
289 ":",c->param_port);
290 BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR);
291 ret=0;
292 goto exit_loop;
293 }
294 else
295 c->state=BIO_CONN_S_OK;
296 break;
297
298 case BIO_CONN_S_OK:
299 ret=1;
300 goto exit_loop;
301 default:
302 abort();
303 goto exit_loop;
304 }
305
306 if (cb != NULL)
307 {
308 if (!(ret=cb((BIO *)b,c->state,ret)))
309 goto end;
310 }
311 }
312
313 /* Loop does not exit */
314exit_loop:
315 if (cb != NULL)
316 ret=cb((BIO *)b,c->state,ret);
317end:
318 return(ret);
319 }
320
321BIO_CONNECT *BIO_CONNECT_new(void)
322 {
323 BIO_CONNECT *ret;
324
325 if ((ret=(BIO_CONNECT *)Malloc(sizeof(BIO_CONNECT))) == NULL)
326 return(NULL);
327 ret->state=BIO_CONN_S_BEFORE;
328 ret->param_hostname=NULL;
329 ret->param_port=NULL;
330 ret->info_callback=NULL;
331 ret->nbio=0;
332 ret->ip[0]=0;
333 ret->ip[1]=0;
334 ret->ip[2]=0;
335 ret->ip[3]=0;
336 ret->port=0;
337 memset((char *)&ret->them,0,sizeof(ret->them));
338 return(ret);
339 }
340
341void BIO_CONNECT_free(BIO_CONNECT *a)
342 {
343 if(a == NULL)
344 return;
345
346 if (a->param_hostname != NULL)
347 Free(a->param_hostname);
348 if (a->param_port != NULL)
349 Free(a->param_port);
350 Free(a);
351 }
352
353BIO_METHOD *BIO_s_connect(void)
354 {
355 return(&methods_connectp);
356 }
357
358static int conn_new(BIO *bi)
359 {
360 bi->init=0;
361 bi->num=INVALID_SOCKET;
362 bi->flags=0;
363 if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL)
364 return(0);
365 else
366 return(1);
367 }
368
369static void conn_close_socket(BIO *bio)
370 {
371 BIO_CONNECT *c;
372
373 c=(BIO_CONNECT *)bio->ptr;
374 if (bio->num != INVALID_SOCKET)
375 {
376 /* Only do a shutdown if things were established */
377 if (c->state == BIO_CONN_S_OK)
378 shutdown(bio->num,2);
379 closesocket(bio->num);
380 bio->num=INVALID_SOCKET;
381 }
382 }
383
384static int conn_free(BIO *a)
385 {
386 BIO_CONNECT *data;
387
388 if (a == NULL) return(0);
389 data=(BIO_CONNECT *)a->ptr;
390
391 if (a->shutdown)
392 {
393 conn_close_socket(a);
394 BIO_CONNECT_free(data);
395 a->ptr=NULL;
396 a->flags=0;
397 a->init=0;
398 }
399 return(1);
400 }
401
402static int conn_read(BIO *b, char *out, int outl)
403 {
404 int ret=0;
405 BIO_CONNECT *data;
406
407 data=(BIO_CONNECT *)b->ptr;
408 if (data->state != BIO_CONN_S_OK)
409 {
410 ret=conn_state(b,data);
411 if (ret <= 0)
412 return(ret);
413 }
414
415 if (out != NULL)
416 {
417 clear_socket_error();
418 ret=readsocket(b->num,out,outl);
419 BIO_clear_retry_flags(b);
420 if (ret <= 0)
421 {
422 if (BIO_sock_should_retry(ret))
423 BIO_set_retry_read(b);
424 }
425 }
426 return(ret);
427 }
428
429static int conn_write(BIO *b, char *in, int inl)
430 {
431 int ret;
432 BIO_CONNECT *data;
433
434 data=(BIO_CONNECT *)b->ptr;
435 if (data->state != BIO_CONN_S_OK)
436 {
437 ret=conn_state(b,data);
438 if (ret <= 0) return(ret);
439 }
440
441 clear_socket_error();
442 ret=writesocket(b->num,in,inl);
443 BIO_clear_retry_flags(b);
444 if (ret <= 0)
445 {
446 if (BIO_sock_should_retry(ret))
447 BIO_set_retry_write(b);
448 }
449 return(ret);
450 }
451
452static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
453 {
454 BIO *dbio;
455 int *ip;
456 const char **pptr;
457 long ret=1;
458 BIO_CONNECT *data;
459
460 data=(BIO_CONNECT *)b->ptr;
461
462 switch (cmd)
463 {
464 case BIO_CTRL_RESET:
465 ret=0;
466 data->state=BIO_CONN_S_BEFORE;
467 conn_close_socket(b);
468 b->flags=0;
469 break;
470 case BIO_C_DO_STATE_MACHINE:
471 /* use this one to start the connection */
472 if (!data->state != BIO_CONN_S_OK)
473 ret=(long)conn_state(b,data);
474 else
475 ret=1;
476 break;
477 case BIO_C_GET_CONNECT:
478 if (ptr != NULL)
479 {
480 pptr=(const char **)ptr;
481 if (num == 0)
482 {
483 *pptr=data->param_hostname;
484
485 }
486 else if (num == 1)
487 {
488 *pptr=data->param_port;
489 }
490 else if (num == 2)
491 {
492 *pptr= (char *)&(data->ip[0]);
493 }
494 else if (num == 3)
495 {
496 *((int *)ptr)=data->port;
497 }
498 if ((!b->init) || (ptr == NULL))
499 *pptr="not initialized";
500 ret=1;
501 }
502 break;
503 case BIO_C_SET_CONNECT:
504 if (ptr != NULL)
505 {
506 b->init=1;
507 if (num == 0)
508 {
509 if (data->param_hostname != NULL)
510 Free(data->param_hostname);
511 data->param_hostname=BUF_strdup(ptr);
512 }
513 else if (num == 1)
514 {
515 if (data->param_port != NULL)
516 Free(data->param_port);
517 data->param_port=BUF_strdup(ptr);
518 }
519 else if (num == 2)
520 {
521 char buf[16];
522
523 sprintf(buf,"%d.%d.%d.%d",
524 ptr[0],ptr[1],ptr[2],ptr[3]);
525 if (data->param_hostname != NULL)
526 Free(data->param_hostname);
527 data->param_hostname=BUF_strdup(buf);
528 memcpy(&(data->ip[0]),ptr,4);
529 }
530 else if (num == 3)
531 {
532 char buf[16];
533
534 sprintf(buf,"%d",*(int *)ptr);
535 if (data->param_port != NULL)
536 Free(data->param_port);
537 data->param_port=BUF_strdup(buf);
538 data->port= *(int *)ptr;
539 }
540 }
541 break;
542 case BIO_C_SET_NBIO:
543 data->nbio=(int)num;
544 break;
545 case BIO_C_GET_FD:
546 if (b->init)
547 {
548 ip=(int *)ptr;
549 if (ip != NULL)
550 *ip=b->num;
551 ret=b->num;
552 }
553 else
554 ret= -1;
555 break;
556 case BIO_CTRL_GET_CLOSE:
557 ret=b->shutdown;
558 break;
559 case BIO_CTRL_SET_CLOSE:
560 b->shutdown=(int)num;
561 break;
562 case BIO_CTRL_PENDING:
563 case BIO_CTRL_WPENDING:
564 ret=0;
565 break;
566 case BIO_CTRL_FLUSH:
567 break;
568 case BIO_CTRL_DUP:
569 {
570 dbio=(BIO *)ptr;
571 if (data->param_port)
572 BIO_set_conn_port(dbio,data->param_port);
573 if (data->param_hostname)
574 BIO_set_conn_hostname(dbio,data->param_hostname);
575 BIO_set_nbio(dbio,data->nbio);
576 (void)BIO_set_info_callback(dbio,(void *(*)())(data->info_callback));
577 }
578 break;
579 case BIO_CTRL_SET_CALLBACK:
580 {
581#if 0 /* FIXME: Should this be used? -- Richard Levitte */
582 BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
583 ret = -1;
584#else
585 ret=0;
586#endif
587 }
588 break;
589 case BIO_CTRL_GET_CALLBACK:
590 {
591 int (**fptr)();
592
593 fptr=(int (**)())ptr;
594 *fptr=data->info_callback;
595 }
596 break;
597 default:
598 ret=0;
599 break;
600 }
601 return(ret);
602 }
603
604static long conn_callback_ctrl(BIO *b, int cmd, void *(*fp)())
605 {
606 long ret=1;
607 BIO_CONNECT *data;
608
609 data=(BIO_CONNECT *)b->ptr;
610
611 switch (cmd)
612 {
613 case BIO_CTRL_SET_CALLBACK:
614 {
615 data->info_callback=(int (*)())fp;
616 }
617 break;
618 default:
619 ret=0;
620 break;
621 }
622 return(ret);
623 }
624
625static int conn_puts(BIO *bp, char *str)
626 {
627 int n,ret;
628
629 n=strlen(str);
630 ret=conn_write(bp,str,n);
631 return(ret);
632 }
633
634BIO *BIO_new_connect(char *str)
635 {
636 BIO *ret;
637
638 ret=BIO_new(BIO_s_connect());
639 if (ret == NULL) return(NULL);
640 if (BIO_set_conn_hostname(ret,str))
641 return(ret);
642 else
643 {
644 BIO_free(ret);
645 return(NULL);
646 }
647 }
648
649#endif
650
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 0d44dc3889..0000000000
--- a/src/lib/libcrypto/bio/bss_file.c
+++ /dev/null
@@ -1,310 +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 NULL,
95 };
96
97BIO *BIO_new_file(const char *filename, const char *mode)
98 {
99 BIO *ret;
100 FILE *file;
101
102 if ((file=fopen(filename,mode)) == NULL)
103 {
104 SYSerr(SYS_F_FOPEN,get_last_sys_error());
105 ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
106 BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
107 return(NULL);
108 }
109 if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
110 return(NULL);
111
112 BIO_set_fp(ret,file,BIO_CLOSE);
113 return(ret);
114 }
115
116BIO *BIO_new_fp(FILE *stream, int close_flag)
117 {
118 BIO *ret;
119
120 if ((ret=BIO_new(BIO_s_file())) == NULL)
121 return(NULL);
122
123 BIO_set_fp(ret,stream,close_flag);
124 return(ret);
125 }
126
127BIO_METHOD *BIO_s_file(void)
128 {
129 return(&methods_filep);
130 }
131
132static int MS_CALLBACK file_new(BIO *bi)
133 {
134 bi->init=0;
135 bi->num=0;
136 bi->ptr=NULL;
137 return(1);
138 }
139
140static int MS_CALLBACK file_free(BIO *a)
141 {
142 if (a == NULL) return(0);
143 if (a->shutdown)
144 {
145 if ((a->init) && (a->ptr != NULL))
146 {
147 fclose((FILE *)a->ptr);
148 a->ptr=NULL;
149 }
150 a->init=0;
151 }
152 return(1);
153 }
154
155static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
156 {
157 int ret=0;
158
159 if (b->init && (out != NULL))
160 {
161 ret=fread(out,1,(int)outl,(FILE *)b->ptr);
162 }
163 return(ret);
164 }
165
166static int MS_CALLBACK file_write(BIO *b, char *in, int inl)
167 {
168 int ret=0;
169
170 if (b->init && (in != NULL))
171 {
172 if (fwrite(in,(int)inl,1,(FILE *)b->ptr))
173 ret=inl;
174 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
175 /* according to Tim Hudson <tjh@cryptsoft.com>, the commented
176 * out version above can cause 'inl' write calls under
177 * some stupid stdio implementations (VMS) */
178 }
179 return(ret);
180 }
181
182static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, char *ptr)
183 {
184 long ret=1;
185 FILE *fp=(FILE *)b->ptr;
186 FILE **fpp;
187 char p[4];
188
189 switch (cmd)
190 {
191 case BIO_C_FILE_SEEK:
192 case BIO_CTRL_RESET:
193 ret=(long)fseek(fp,num,0);
194 break;
195 case BIO_CTRL_EOF:
196 ret=(long)feof(fp);
197 break;
198 case BIO_C_FILE_TELL:
199 case BIO_CTRL_INFO:
200 ret=ftell(fp);
201 break;
202 case BIO_C_SET_FILE_PTR:
203 file_free(b);
204 b->shutdown=(int)num&BIO_CLOSE;
205 b->ptr=(char *)ptr;
206 b->init=1;
207#if defined(MSDOS) || defined(WINDOWS)
208 /* Set correct text/binary mode */
209 if (num & BIO_FP_TEXT)
210 _setmode(fileno((FILE *)ptr),_O_TEXT);
211 else
212 _setmode(fileno((FILE *)ptr),_O_BINARY);
213#endif
214 break;
215 case BIO_C_SET_FILENAME:
216 file_free(b);
217 b->shutdown=(int)num&BIO_CLOSE;
218 if (num & BIO_FP_APPEND)
219 {
220 if (num & BIO_FP_READ)
221 strcpy(p,"a+");
222 else strcpy(p,"a");
223 }
224 else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
225 strcpy(p,"r+");
226 else if (num & BIO_FP_WRITE)
227 strcpy(p,"w");
228 else if (num & BIO_FP_READ)
229 strcpy(p,"r");
230 else
231 {
232 BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE);
233 ret=0;
234 break;
235 }
236#if defined(MSDOS) || defined(WINDOWS)
237 if (!(num & BIO_FP_TEXT))
238 strcat(p,"b");
239 else
240 strcat(p,"t");
241#endif
242 fp=fopen(ptr,p);
243 if (fp == NULL)
244 {
245 SYSerr(SYS_F_FOPEN,get_last_sys_error());
246 ERR_add_error_data(5,"fopen('",ptr,"','",p,"')");
247 BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB);
248 ret=0;
249 break;
250 }
251 b->ptr=(char *)fp;
252 b->init=1;
253 break;
254 case BIO_C_GET_FILE_PTR:
255 /* the ptr parameter is actually a FILE ** in this case. */
256 if (ptr != NULL)
257 {
258 fpp=(FILE **)ptr;
259 *fpp=(FILE *)b->ptr;
260 }
261 break;
262 case BIO_CTRL_GET_CLOSE:
263 ret=(long)b->shutdown;
264 break;
265 case BIO_CTRL_SET_CLOSE:
266 b->shutdown=(int)num;
267 break;
268 case BIO_CTRL_FLUSH:
269 fflush((FILE *)b->ptr);
270 break;
271 case BIO_CTRL_DUP:
272 ret=1;
273 break;
274
275 case BIO_CTRL_WPENDING:
276 case BIO_CTRL_PENDING:
277 case BIO_CTRL_PUSH:
278 case BIO_CTRL_POP:
279 default:
280 ret=0;
281 break;
282 }
283 return(ret);
284 }
285
286static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
287 {
288 int ret=0;
289
290 buf[0]='\0';
291 fgets(buf,size,(FILE *)bp->ptr);
292 if (buf[0] != '\0')
293 ret=strlen(buf);
294 return(ret);
295 }
296
297static int MS_CALLBACK file_puts(BIO *bp, char *str)
298 {
299 int n,ret;
300
301 n=strlen(str);
302 ret=file_write(bp,str,n);
303 return(ret);
304 }
305
306#endif /* NO_STDIO */
307
308#endif /* HEADER_BSS_FILE_C */
309
310
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
deleted file mode 100644
index 497eb1af72..0000000000
--- a/src/lib/libcrypto/bio/bss_log.c
+++ /dev/null
@@ -1,336 +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 (on system that
61 commonly use that), or event log (on NT), or OPCOM (on OpenVMS).
62
63*/
64
65
66#include <stdio.h>
67#include <errno.h>
68
69#if defined(WIN32)
70# include <process.h>
71#elif defined(VMS) || defined(__VMS)
72# include <opcdef.h>
73# include <descrip.h>
74# include <lib$routines.h>
75# include <starlet.h>
76#elif defined(__ultrix)
77# include <sys/syslog.h>
78#elif !defined(MSDOS) /* Unix */
79# include <syslog.h>
80#endif
81
82#include "cryptlib.h"
83#include <openssl/buffer.h>
84#include <openssl/err.h>
85
86#ifndef NO_SYSLOG
87
88#if defined(WIN32)
89#define LOG_EMERG 0
90#define LOG_ALERT 1
91#define LOG_CRIT 2
92#define LOG_ERR 3
93#define LOG_WARNING 4
94#define LOG_NOTICE 5
95#define LOG_INFO 6
96#define LOG_DEBUG 7
97
98#define LOG_DAEMON (3<<3)
99#elif defined(VMS)
100/* On VMS, we don't really care about these, but we need them to compile */
101#define LOG_EMERG 0
102#define LOG_ALERT 1
103#define LOG_CRIT 2
104#define LOG_ERR 3
105#define LOG_WARNING 4
106#define LOG_NOTICE 5
107#define LOG_INFO 6
108#define LOG_DEBUG 7
109
110#define LOG_DAEMON OPC$M_NM_NTWORK
111#endif
112
113static int MS_CALLBACK slg_write(BIO *h,char *buf,int num);
114static int MS_CALLBACK slg_puts(BIO *h,char *str);
115static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2);
116static int MS_CALLBACK slg_new(BIO *h);
117static int MS_CALLBACK slg_free(BIO *data);
118static void xopenlog(BIO* bp, const char* name, int level);
119static void xsyslog(BIO* bp, int priority, const char* string);
120static void xcloselog(BIO* bp);
121
122static BIO_METHOD methods_slg=
123 {
124 BIO_TYPE_MEM,"syslog",
125 slg_write,
126 NULL,
127 slg_puts,
128 NULL,
129 slg_ctrl,
130 slg_new,
131 slg_free,
132 NULL,
133 };
134
135BIO_METHOD *BIO_s_log(void)
136 {
137 return(&methods_slg);
138 }
139
140static int MS_CALLBACK slg_new(BIO *bi)
141 {
142 bi->init=1;
143 bi->num=0;
144 bi->ptr=NULL;
145 xopenlog(bi, "application", LOG_DAEMON);
146 return(1);
147 }
148
149static int MS_CALLBACK slg_free(BIO *a)
150 {
151 if (a == NULL) return(0);
152 xcloselog(a);
153 return(1);
154 }
155
156static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
157 {
158 int ret= inl;
159 char* buf= in;
160 char* pp;
161 int priority;
162
163 if((buf= (char *)Malloc(inl+ 1)) == NULL){
164 return(0);
165 }
166 strncpy(buf, in, inl);
167 buf[inl]= '\0';
168
169 if(strncmp(buf, "ERR ", 4) == 0){
170 priority= LOG_ERR;
171 pp= buf+ 4;
172 }else if(strncmp(buf, "WAR ", 4) == 0){
173 priority= LOG_WARNING;
174 pp= buf+ 4;
175 }else if(strncmp(buf, "INF ", 4) == 0){
176 priority= LOG_INFO;
177 pp= buf+ 4;
178 }else{
179 priority= LOG_ERR;
180 pp= buf;
181 }
182
183 xsyslog(b, priority, pp);
184
185 Free(buf);
186 return(ret);
187 }
188
189static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr)
190 {
191 switch (cmd)
192 {
193 case BIO_CTRL_SET:
194 xcloselog(b);
195 xopenlog(b, ptr, num);
196 break;
197 default:
198 break;
199 }
200 return(0);
201 }
202
203static int MS_CALLBACK slg_puts(BIO *bp, char *str)
204 {
205 int n,ret;
206
207 n=strlen(str);
208 ret=slg_write(bp,str,n);
209 return(ret);
210 }
211
212#if defined(WIN32)
213
214static void xopenlog(BIO* bp, const char* name, int level)
215{
216 bp->ptr= (char *)RegisterEventSource(NULL, name);
217}
218
219static void xsyslog(BIO *bp, int priority, const char *string)
220{
221 LPCSTR lpszStrings[2];
222 WORD evtype= EVENTLOG_ERROR_TYPE;
223 int pid = _getpid();
224 char pidbuf[20];
225
226 switch (priority)
227 {
228 case LOG_ERR:
229 evtype = EVENTLOG_ERROR_TYPE;
230 break;
231 case LOG_WARNING:
232 evtype = EVENTLOG_WARNING_TYPE;
233 break;
234 case LOG_INFO:
235 evtype = EVENTLOG_INFORMATION_TYPE;
236 break;
237 default:
238 evtype = EVENTLOG_ERROR_TYPE;
239 break;
240 }
241
242 sprintf(pidbuf, "[%d] ", pid);
243 lpszStrings[0] = pidbuf;
244 lpszStrings[1] = string;
245
246 if(bp->ptr)
247 ReportEvent(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
248 lpszStrings, NULL);
249}
250
251static void xcloselog(BIO* bp)
252{
253 if(bp->ptr)
254 DeregisterEventSource((HANDLE)(bp->ptr));
255 bp->ptr= NULL;
256}
257
258#elif defined(VMS)
259
260static int VMS_OPC_target = LOG_DAEMON;
261
262static void xopenlog(BIO* bp, const char* name, int level)
263{
264 VMS_OPC_target = level;
265}
266
267static void xsyslog(BIO *bp, int priority, const char *string)
268{
269 struct dsc$descriptor_s opc_dsc;
270 struct opcdef *opcdef_p;
271 char buf[10240];
272 unsigned int len;
273 struct dsc$descriptor_s buf_dsc;
274 $DESCRIPTOR(fao_cmd, "!AZ: !AZ");
275 char *priority_tag;
276
277 switch (priority)
278 {
279 case LOG_EMERG: priority_tag = "Emergency"; break;
280 case LOG_ALERT: priority_tag = "Alert"; break;
281 case LOG_CRIT: priority_tag = "Critical"; break;
282 case LOG_ERR: priority_tag = "Error"; break;
283 case LOG_WARNING: priority_tag = "Warning"; break;
284 case LOG_NOTICE: priority_tag = "Notice"; break;
285 case LOG_INFO: priority_tag = "Info"; break;
286 case LOG_DEBUG: priority_tag = "DEBUG"; break;
287 }
288
289 buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
290 buf_dsc.dsc$b_class = DSC$K_CLASS_S;
291 buf_dsc.dsc$a_pointer = buf;
292 buf_dsc.dsc$w_length = sizeof(buf) - 1;
293
294 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
295
296 /* we know there's an 8 byte header. That's documented */
297 opcdef_p = (struct opcdef *) Malloc(8 + len);
298 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
299 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
300 opcdef_p->opc$l_ms_rqstid = 0;
301 memcpy(&opcdef_p->opc$l_ms_text, buf, len);
302
303 opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
304 opc_dsc.dsc$b_class = DSC$K_CLASS_S;
305 opc_dsc.dsc$a_pointer = (char *)opcdef_p;
306 opc_dsc.dsc$w_length = len + 8;
307
308 sys$sndopr(opc_dsc, 0);
309
310 Free(opcdef_p);
311}
312
313static void xcloselog(BIO* bp)
314{
315}
316
317#else /* Unix */
318
319static void xopenlog(BIO* bp, const char* name, int level)
320{
321 openlog(name, LOG_PID|LOG_CONS, level);
322}
323
324static void xsyslog(BIO *bp, int priority, const char *string)
325{
326 syslog(priority, "%s", string);
327}
328
329static void xcloselog(BIO* bp)
330{
331 closelog();
332}
333
334#endif /* Unix */
335
336#endif /* NO_SYSLOG */
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c
deleted file mode 100644
index 41eab92415..0000000000
--- a/src/lib/libcrypto/bio/bss_mem.c
+++ /dev/null
@@ -1,312 +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 NULL,
83 };
84
85/* bio->num is used to hold the value to return on 'empty', if it is
86 * 0, should_retry is not set */
87
88BIO_METHOD *BIO_s_mem(void)
89 {
90 return(&mem_method);
91 }
92
93BIO *BIO_new_mem_buf(void *buf, int len)
94{
95 BIO *ret;
96 BUF_MEM *b;
97 if (!buf) {
98 BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
99 return NULL;
100 }
101 if(len == -1) len = strlen(buf);
102 if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
103 b = (BUF_MEM *)ret->ptr;
104 b->data = buf;
105 b->length = len;
106 b->max = len;
107 ret->flags |= BIO_FLAGS_MEM_RDONLY;
108 /* Since this is static data retrying wont help */
109 ret->num = 0;
110 return ret;
111}
112
113static int mem_new(BIO *bi)
114 {
115 BUF_MEM *b;
116
117 if ((b=BUF_MEM_new()) == NULL)
118 return(0);
119 bi->shutdown=1;
120 bi->init=1;
121 bi->num= -1;
122 bi->ptr=(char *)b;
123 return(1);
124 }
125
126static int mem_free(BIO *a)
127 {
128 if (a == NULL) return(0);
129 if (a->shutdown)
130 {
131 if ((a->init) && (a->ptr != NULL))
132 {
133 BUF_MEM *b;
134 b = (BUF_MEM *)a->ptr;
135 if(a->flags & BIO_FLAGS_MEM_RDONLY) b->data = NULL;
136 BUF_MEM_free(b);
137 a->ptr=NULL;
138 }
139 }
140 return(1);
141 }
142
143static int mem_read(BIO *b, char *out, int outl)
144 {
145 int ret= -1;
146 BUF_MEM *bm;
147 int i;
148 char *from,*to;
149
150 bm=(BUF_MEM *)b->ptr;
151 BIO_clear_retry_flags(b);
152 ret=(outl > bm->length)?bm->length:outl;
153 if ((out != NULL) && (ret > 0)) {
154 memcpy(out,bm->data,ret);
155 bm->length-=ret;
156 /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */
157 if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
158 else {
159 from=(char *)&(bm->data[ret]);
160 to=(char *)&(bm->data[0]);
161 for (i=0; i<bm->length; i++)
162 to[i]=from[i];
163 }
164 } else if (bm->length == 0)
165 {
166 if (b->num != 0)
167 BIO_set_retry_read(b);
168 ret= b->num;
169 }
170 return(ret);
171 }
172
173static int mem_write(BIO *b, char *in, int inl)
174 {
175 int ret= -1;
176 int blen;
177 BUF_MEM *bm;
178
179 bm=(BUF_MEM *)b->ptr;
180 if (in == NULL)
181 {
182 BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER);
183 goto end;
184 }
185
186 if(b->flags & BIO_FLAGS_MEM_RDONLY) {
187 BIOerr(BIO_F_MEM_WRITE,BIO_R_WRITE_TO_READ_ONLY_BIO);
188 goto end;
189 }
190
191 BIO_clear_retry_flags(b);
192 blen=bm->length;
193 if (BUF_MEM_grow(bm,blen+inl) != (blen+inl))
194 goto end;
195 memcpy(&(bm->data[blen]),in,inl);
196 ret=inl;
197end:
198 return(ret);
199 }
200
201static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
202 {
203 long ret=1;
204 char **pptr;
205
206 BUF_MEM *bm=(BUF_MEM *)b->ptr;
207
208 switch (cmd)
209 {
210 case BIO_CTRL_RESET:
211 if (bm->data != NULL) {
212 /* For read only case reset to the start again */
213 if(b->flags & BIO_FLAGS_MEM_RDONLY)
214 bm->data -= bm->max - bm->length;
215 else {
216 memset(bm->data,0,bm->max);
217 bm->length=0;
218 }
219 }
220 break;
221 case BIO_CTRL_EOF:
222 ret=(long)(bm->length == 0);
223 break;
224 case BIO_C_SET_BUF_MEM_EOF_RETURN:
225 b->num=(int)num;
226 break;
227 case BIO_CTRL_INFO:
228 ret=(long)bm->length;
229 if (ptr != NULL)
230 {
231 pptr=(char **)ptr;
232 *pptr=(char *)&(bm->data[0]);
233 }
234 break;
235 case BIO_C_SET_BUF_MEM:
236 mem_free(b);
237 b->shutdown=(int)num;
238 b->ptr=ptr;
239 break;
240 case BIO_C_GET_BUF_MEM_PTR:
241 if (ptr != NULL)
242 {
243 pptr=(char **)ptr;
244 *pptr=(char *)bm;
245 }
246 break;
247 case BIO_CTRL_GET_CLOSE:
248 ret=(long)b->shutdown;
249 break;
250 case BIO_CTRL_SET_CLOSE:
251 b->shutdown=(int)num;
252 break;
253
254 case BIO_CTRL_WPENDING:
255 ret=0L;
256 break;
257 case BIO_CTRL_PENDING:
258 ret=(long)bm->length;
259 break;
260 case BIO_CTRL_DUP:
261 case BIO_CTRL_FLUSH:
262 ret=1;
263 break;
264 case BIO_CTRL_PUSH:
265 case BIO_CTRL_POP:
266 default:
267 ret=0;
268 break;
269 }
270 return(ret);
271 }
272
273static int mem_gets(BIO *bp, char *buf, int size)
274 {
275 int i,j;
276 int ret= -1;
277 char *p;
278 BUF_MEM *bm=(BUF_MEM *)bp->ptr;
279
280 BIO_clear_retry_flags(bp);
281 j=bm->length;
282 if (j <= 0) return(0);
283 p=bm->data;
284 for (i=0; i<j; i++)
285 {
286 if (p[i] == '\n') break;
287 }
288 if (i == j)
289 {
290 BIO_set_retry_read(bp);
291 /* return(-1); change the semantics 0.6.6a */
292 }
293 else
294 i++;
295 /* i is the max to copy */
296 if ((size-1) < i) i=size-1;
297 i=mem_read(bp,buf,i);
298 if (i > 0) buf[i]='\0';
299 ret=i;
300 return(ret);
301 }
302
303static int mem_puts(BIO *bp, char *str)
304 {
305 int n,ret;
306
307 n=strlen(str);
308 ret=mem_write(bp,str,n);
309 /* memory semantics is that it will always work */
310 return(ret);
311 }
312
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c
deleted file mode 100644
index aee18e3ada..0000000000
--- a/src/lib/libcrypto/bio/bss_null.c
+++ /dev/null
@@ -1,150 +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 NULL,
83 };
84
85BIO_METHOD *BIO_s_null(void)
86 {
87 return(&null_method);
88 }
89
90static int null_new(BIO *bi)
91 {
92 bi->init=1;
93 bi->num=0;
94 bi->ptr=(NULL);
95 return(1);
96 }
97
98static int null_free(BIO *a)
99 {
100 if (a == NULL) return(0);
101 return(1);
102 }
103
104static int null_read(BIO *b, char *out, int outl)
105 {
106 return(0);
107 }
108
109static int null_write(BIO *b, char *in, int inl)
110 {
111 return(inl);
112 }
113
114static long null_ctrl(BIO *b, int cmd, long num, char *ptr)
115 {
116 long ret=1;
117
118 switch (cmd)
119 {
120 case BIO_CTRL_RESET:
121 case BIO_CTRL_EOF:
122 case BIO_CTRL_SET:
123 case BIO_CTRL_SET_CLOSE:
124 case BIO_CTRL_FLUSH:
125 case BIO_CTRL_DUP:
126 ret=1;
127 break;
128 case BIO_CTRL_GET_CLOSE:
129 case BIO_CTRL_INFO:
130 case BIO_CTRL_GET:
131 case BIO_CTRL_PENDING:
132 case BIO_CTRL_WPENDING:
133 default:
134 ret=0;
135 break;
136 }
137 return(ret);
138 }
139
140static int null_gets(BIO *bp, char *buf, int size)
141 {
142 return(0);
143 }
144
145static int null_puts(BIO *bp, char *str)
146 {
147 if (str == NULL) return(0);
148 return(strlen(str));
149 }
150
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
deleted file mode 100644
index 8ce80ef68d..0000000000
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ /dev/null
@@ -1,424 +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 NULL,
99 };
100
101BIO_METHOD *BIO_s_socket(void)
102 {
103 return(&methods_sockp);
104 }
105#else
106static BIO_METHOD methods_fdp=
107 {
108 BIO_TYPE_FD,"file descriptor",
109 fd_write,
110 fd_read,
111 fd_puts,
112 NULL, /* fd_gets, */
113 fd_ctrl,
114 fd_new,
115 fd_free,
116 NULL,
117 };
118
119BIO_METHOD *BIO_s_fd(void)
120 {
121 return(&methods_fdp);
122 }
123#endif
124
125#ifndef BIO_FD
126BIO *BIO_new_socket(int fd, int close_flag)
127#else
128BIO *BIO_new_fd(int fd,int close_flag)
129#endif
130 {
131 BIO *ret;
132
133#ifndef BIO_FD
134 ret=BIO_new(BIO_s_socket());
135#else
136 ret=BIO_new(BIO_s_fd());
137#endif
138 if (ret == NULL) return(NULL);
139 BIO_set_fd(ret,fd,close_flag);
140 return(ret);
141 }
142
143#ifndef BIO_FD
144static int sock_new(BIO *bi)
145#else
146static int fd_new(BIO *bi)
147#endif
148 {
149 bi->init=0;
150 bi->num=0;
151 bi->ptr=NULL;
152 bi->flags=0;
153 return(1);
154 }
155
156#ifndef BIO_FD
157static int sock_free(BIO *a)
158#else
159static int fd_free(BIO *a)
160#endif
161 {
162 if (a == NULL) return(0);
163 if (a->shutdown)
164 {
165 if (a->init)
166 {
167#ifndef BIO_FD
168 SHUTDOWN2(a->num);
169#else /* BIO_FD */
170 close(a->num);
171#endif
172
173 }
174 a->init=0;
175 a->flags=0;
176 }
177 return(1);
178 }
179
180#ifndef BIO_FD
181static int sock_read(BIO *b, char *out, int outl)
182#else
183static int fd_read(BIO *b, char *out,int outl)
184#endif
185 {
186 int ret=0;
187
188 if (out != NULL)
189 {
190#ifndef BIO_FD
191 clear_socket_error();
192 ret=readsocket(b->num,out,outl);
193#else
194 clear_sys_error();
195 ret=read(b->num,out,outl);
196#endif
197 BIO_clear_retry_flags(b);
198 if (ret <= 0)
199 {
200#ifndef BIO_FD
201 if (BIO_sock_should_retry(ret))
202#else
203 if (BIO_fd_should_retry(ret))
204#endif
205 BIO_set_retry_read(b);
206 }
207 }
208 return(ret);
209 }
210
211#ifndef BIO_FD
212static int sock_write(BIO *b, char *in, int inl)
213#else
214static int fd_write(BIO *b, char *in, int inl)
215#endif
216 {
217 int ret;
218
219#ifndef BIO_FD
220 clear_socket_error();
221 ret=writesocket(b->num,in,inl);
222#else
223 clear_sys_error();
224 ret=write(b->num,in,inl);
225#endif
226 BIO_clear_retry_flags(b);
227 if (ret <= 0)
228 {
229#ifndef BIO_FD
230 if (BIO_sock_should_retry(ret))
231#else
232 if (BIO_fd_should_retry(ret))
233#endif
234 BIO_set_retry_write(b);
235 }
236 return(ret);
237 }
238
239#ifndef BIO_FD
240static long sock_ctrl(BIO *b, int cmd, long num, char *ptr)
241#else
242static long fd_ctrl(BIO *b, int cmd, long num, char *ptr)
243#endif
244 {
245 long ret=1;
246 int *ip;
247
248 switch (cmd)
249 {
250 case BIO_CTRL_RESET:
251 num=0;
252 case BIO_C_FILE_SEEK:
253#ifdef BIO_FD
254 ret=(long)lseek(b->num,num,0);
255#else
256 ret=0;
257#endif
258 break;
259 case BIO_C_FILE_TELL:
260 case BIO_CTRL_INFO:
261#ifdef BIO_FD
262 ret=(long)lseek(b->num,0,1);
263#else
264 ret=0;
265#endif
266 break;
267 case BIO_C_SET_FD:
268#ifndef BIO_FD
269 sock_free(b);
270#else
271 fd_free(b);
272#endif
273 b->num= *((int *)ptr);
274 b->shutdown=(int)num;
275 b->init=1;
276 break;
277 case BIO_C_GET_FD:
278 if (b->init)
279 {
280 ip=(int *)ptr;
281 if (ip != NULL) *ip=b->num;
282 ret=b->num;
283 }
284 else
285 ret= -1;
286 break;
287 case BIO_CTRL_GET_CLOSE:
288 ret=b->shutdown;
289 break;
290 case BIO_CTRL_SET_CLOSE:
291 b->shutdown=(int)num;
292 break;
293 case BIO_CTRL_PENDING:
294 case BIO_CTRL_WPENDING:
295 ret=0;
296 break;
297 case BIO_CTRL_DUP:
298 case BIO_CTRL_FLUSH:
299 ret=1;
300 break;
301 default:
302 ret=0;
303 break;
304 }
305 return(ret);
306 }
307
308#ifdef undef
309static int sock_gets(BIO *bp, char *buf,int size)
310 {
311 return(-1);
312 }
313#endif
314
315#ifndef BIO_FD
316static int sock_puts(BIO *bp, char *str)
317#else
318static int fd_puts(BIO *bp, char *str)
319#endif
320 {
321 int n,ret;
322
323 n=strlen(str);
324#ifndef BIO_FD
325 ret=sock_write(bp,str,n);
326#else
327 ret=fd_write(bp,str,n);
328#endif
329 return(ret);
330 }
331
332#ifndef BIO_FD
333int BIO_sock_should_retry(int i)
334#else
335int BIO_fd_should_retry(int i)
336#endif
337 {
338 int err;
339
340 if ((i == 0) || (i == -1))
341 {
342#ifndef BIO_FD
343 err=get_last_socket_error();
344#else
345 err=get_last_sys_error();
346#endif
347
348#if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
349 if ((i == -1) && (err == 0))
350 return(1);
351#endif
352
353#ifndef BIO_FD
354 return(BIO_sock_non_fatal_error(err));
355#else
356 return(BIO_fd_non_fatal_error(err));
357#endif
358 }
359 return(0);
360 }
361
362#ifndef BIO_FD
363int BIO_sock_non_fatal_error(int err)
364#else
365int BIO_fd_non_fatal_error(int err)
366#endif
367 {
368 switch (err)
369 {
370#if !defined(BIO_FD) && defined(WINDOWS)
371# if defined(WSAEWOULDBLOCK)
372 case WSAEWOULDBLOCK:
373# endif
374
375# if 0 /* This appears to always be an error */
376# if defined(WSAENOTCONN)
377 case WSAENOTCONN:
378# endif
379# endif
380#endif
381
382#ifdef EWOULDBLOCK
383# ifdef WSAEWOULDBLOCK
384# if WSAEWOULDBLOCK != EWOULDBLOCK
385 case EWOULDBLOCK:
386# endif
387# else
388 case EWOULDBLOCK:
389# endif
390#endif
391
392#if defined(ENOTCONN)
393 case ENOTCONN:
394#endif
395
396#ifdef EINTR
397 case EINTR:
398#endif
399
400#ifdef EAGAIN
401#if EWOULDBLOCK != EAGAIN
402 case EAGAIN:
403# endif
404#endif
405
406#ifdef EPROTO
407 case EPROTO:
408#endif
409
410#ifdef EINPROGRESS
411 case EINPROGRESS:
412#endif
413
414#ifdef EALREADY
415 case EALREADY:
416#endif
417 return(1);
418 /* break; */
419 default:
420 break;
421 }
422 return(0);
423 }
424#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 009b0eb685..0000000000
--- a/src/lib/libcrypto/bn/bn.h
+++ /dev/null
@@ -1,510 +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 normal cc. This would
87 * be a common occurrence 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 assembler code. */
92#if defined(MSDOS) || defined(WINDOWS) || defined(WIN32) || 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 relevant
122 * assembler 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
243#define BN_CTX_NUM_POS 12
244typedef struct bignum_ctx
245 {
246 int tos;
247 BIGNUM bn[BN_CTX_NUM];
248 int flags;
249 int depth;
250 int pos[BN_CTX_NUM_POS];
251 int too_many;
252 } BN_CTX;
253
254typedef struct bn_blinding_st
255 {
256 int init;
257 BIGNUM *A;
258 BIGNUM *Ai;
259 BIGNUM *mod; /* just a reference */
260 } BN_BLINDING;
261
262/* Used for montgomery multiplication */
263typedef struct bn_mont_ctx_st
264 {
265 int ri; /* number of bits in R */
266 BIGNUM RR; /* used to convert to montgomery form */
267 BIGNUM N; /* The modulus */
268 BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
269 * (Ni is only stored for bignum algorithm) */
270 BN_ULONG n0; /* least significant word of Ni */
271 int flags;
272 } BN_MONT_CTX;
273
274/* Used for reciprocal division/mod functions
275 * It cannot be shared between threads
276 */
277typedef struct bn_recp_ctx_st
278 {
279 BIGNUM N; /* the divisor */
280 BIGNUM Nr; /* the reciprocal */
281 int num_bits;
282 int shift;
283 int flags;
284 } BN_RECP_CTX;
285
286#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
287 r,a,&((mont)->RR),(mont),ctx)
288
289#define BN_prime_checks 0 /* default: select number of iterations
290 based on the size of the number */
291
292/* number of Miller-Rabin iterations for an error rate of less than 2^-80
293 * for random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook
294 * of Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996];
295 * original paper: Damgaard, Landrock, Pomerance: Average case error estimates
296 * for the strong probable prime test. -- Math. Comp. 61 (1993) 177-194) */
297#define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \
298 (b) >= 850 ? 3 : \
299 (b) >= 650 ? 4 : \
300 (b) >= 550 ? 5 : \
301 (b) >= 450 ? 6 : \
302 (b) >= 400 ? 7 : \
303 (b) >= 350 ? 8 : \
304 (b) >= 300 ? 9 : \
305 (b) >= 250 ? 12 : \
306 (b) >= 200 ? 15 : \
307 (b) >= 150 ? 18 : \
308 /* b >= 100 */ 27)
309
310#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
311#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
312#define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0))
313#define BN_is_one(a) (BN_is_word((a),1))
314#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))
315#define BN_one(a) (BN_set_word((a),1))
316#define BN_zero(a) (BN_set_word((a),0))
317
318/*#define BN_ascii2bn(a) BN_hex2bn(a) */
319/*#define BN_bn2ascii(a) BN_bn2hex(a) */
320
321BIGNUM *BN_value_one(void);
322char * BN_options(void);
323BN_CTX *BN_CTX_new(void);
324void BN_CTX_init(BN_CTX *c);
325void BN_CTX_free(BN_CTX *c);
326void BN_CTX_start(BN_CTX *ctx);
327BIGNUM *BN_CTX_get(BN_CTX *ctx);
328void BN_CTX_end(BN_CTX *ctx);
329int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
330int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom);
331int BN_num_bits(const BIGNUM *a);
332int BN_num_bits_word(BN_ULONG);
333BIGNUM *BN_new(void);
334void BN_init(BIGNUM *);
335void BN_clear_free(BIGNUM *a);
336BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
337BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
338int BN_bn2bin(const BIGNUM *a, unsigned char *to);
339BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret);
340int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
341int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
342int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
343int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
344int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
345int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
346int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
347 BN_CTX *ctx);
348int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
349int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx);
350BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
351BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
352int BN_mul_word(BIGNUM *a, BN_ULONG w);
353int BN_add_word(BIGNUM *a, BN_ULONG w);
354int BN_sub_word(BIGNUM *a, BN_ULONG w);
355int BN_set_word(BIGNUM *a, BN_ULONG w);
356BN_ULONG BN_get_word(BIGNUM *a);
357int BN_cmp(const BIGNUM *a, const BIGNUM *b);
358void BN_free(BIGNUM *a);
359int BN_is_bit_set(const BIGNUM *a, int n);
360int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
361int BN_lshift1(BIGNUM *r, BIGNUM *a);
362int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx);
363int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
364 const BIGNUM *m,BN_CTX *ctx);
365int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
366 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
367int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2,
368 BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx);
369int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p,
370 BIGNUM *m,BN_CTX *ctx);
371int BN_mask_bits(BIGNUM *a,int n);
372int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
373#ifndef NO_FP_API
374int BN_print_fp(FILE *fp, const BIGNUM *a);
375#endif
376#ifdef HEADER_BIO_H
377int BN_print(BIO *fp, const BIGNUM *a);
378#else
379int BN_print(void *fp, const BIGNUM *a);
380#endif
381int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx);
382int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
383int BN_rshift1(BIGNUM *r, BIGNUM *a);
384void BN_clear(BIGNUM *a);
385BIGNUM *BN_dup(const BIGNUM *a);
386int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
387int BN_set_bit(BIGNUM *a, int n);
388int BN_clear_bit(BIGNUM *a, int n);
389char * BN_bn2hex(const BIGNUM *a);
390char * BN_bn2dec(const BIGNUM *a);
391int BN_hex2bn(BIGNUM **a, const char *str);
392int BN_dec2bn(BIGNUM **a, const char *str);
393int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx);
394BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
395BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,BIGNUM *add,
396 BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg);
397int BN_is_prime(const BIGNUM *p,int nchecks,
398 void (*callback)(int,int,void *),
399 BN_CTX *ctx,void *cb_arg);
400int BN_is_prime_fasttest(const BIGNUM *p,int nchecks,
401 void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg,
402 int do_trial_division);
403void ERR_load_BN_strings(void );
404
405BN_MONT_CTX *BN_MONT_CTX_new(void );
406void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
407int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont,
408 BN_CTX *ctx);
409int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx);
410void BN_MONT_CTX_free(BN_MONT_CTX *mont);
411int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx);
412BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);
413
414BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod);
415void BN_BLINDING_free(BN_BLINDING *b);
416int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
417int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx);
418int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
419
420void BN_set_params(int mul,int high,int low,int mont);
421int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */
422
423void BN_RECP_CTX_init(BN_RECP_CTX *recp);
424BN_RECP_CTX *BN_RECP_CTX_new(void);
425void BN_RECP_CTX_free(BN_RECP_CTX *recp);
426int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx);
427int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y,
428 BN_RECP_CTX *recp,BN_CTX *ctx);
429int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
430 const BIGNUM *m, BN_CTX *ctx);
431int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m,
432 BN_RECP_CTX *recp, BN_CTX *ctx);
433
434/* library internal functions */
435
436#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->max)?\
437 (a):bn_expand2((a),(bits)/BN_BITS2+1))
438#define bn_wexpand(a,words) (((words) <= (a)->max)?(a):bn_expand2((a),(words)))
439BIGNUM *bn_expand2(BIGNUM *a, int words);
440
441#define bn_fix_top(a) \
442 { \
443 BN_ULONG *ftl; \
444 if ((a)->top > 0) \
445 { \
446 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
447 if (*(ftl--)) break; \
448 } \
449 }
450
451BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
452BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
453void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
454BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
455BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
456BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
457
458#ifdef BN_DEBUG
459 void bn_dump1(FILE *o, const char *a, BN_ULONG *b,int n);
460# define bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \
461 fprintf(stderr,"\n");}
462# define bn_dump(a,n) bn_dump1(stderr,#a,a,n);
463#else
464# define bn_print(a)
465# define bn_dump(a,b)
466#endif
467
468/* BEGIN ERROR CODES */
469/* The following lines are auto generated by the script mkerr.pl. Any changes
470 * made after this point may be overwritten when the script is next run.
471 */
472
473/* Error codes for the BN functions. */
474
475/* Function codes. */
476#define BN_F_BN_BLINDING_CONVERT 100
477#define BN_F_BN_BLINDING_INVERT 101
478#define BN_F_BN_BLINDING_NEW 102
479#define BN_F_BN_BLINDING_UPDATE 103
480#define BN_F_BN_BN2DEC 104
481#define BN_F_BN_BN2HEX 105
482#define BN_F_BN_CTX_GET 116
483#define BN_F_BN_CTX_NEW 106
484#define BN_F_BN_DIV 107
485#define BN_F_BN_EXPAND2 108
486#define BN_F_BN_MOD_EXP_MONT 109
487#define BN_F_BN_MOD_INVERSE 110
488#define BN_F_BN_MOD_MUL_RECIPROCAL 111
489#define BN_F_BN_MPI2BN 112
490#define BN_F_BN_NEW 113
491#define BN_F_BN_RAND 114
492#define BN_F_BN_USUB 115
493
494/* Reason codes. */
495#define BN_R_ARG2_LT_ARG3 100
496#define BN_R_BAD_RECIPROCAL 101
497#define BN_R_CALLED_WITH_EVEN_MODULUS 102
498#define BN_R_DIV_BY_ZERO 103
499#define BN_R_ENCODING_ERROR 104
500#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105
501#define BN_R_INVALID_LENGTH 106
502#define BN_R_NOT_INITIALIZED 107
503#define BN_R_NO_INVERSE 108
504#define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109
505
506#ifdef __cplusplus
507}
508#endif
509#endif
510
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
deleted file mode 100644
index 5d24691233..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, const BIGNUM *a, const BIGNUM *b)
65 {
66 const 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 3329cc18e6..0000000000
--- a/src/lib/libcrypto/bn/bn_asm.c
+++ /dev/null
@@ -1,837 +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#ifndef BN_DEBUG
60# undef NDEBUG /* avoid conflicting definitions */
61# define NDEBUG
62#endif
63
64#include <stdio.h>
65#include <assert.h>
66#include "cryptlib.h"
67#include "bn_lcl.h"
68
69#if defined(BN_LLONG) || defined(BN_UMULT_HIGH)
70
71BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
72 {
73 BN_ULONG c1=0;
74
75 assert(num >= 0);
76 if (num <= 0) return(c1);
77
78 while (num&~3)
79 {
80 mul_add(rp[0],ap[0],w,c1);
81 mul_add(rp[1],ap[1],w,c1);
82 mul_add(rp[2],ap[2],w,c1);
83 mul_add(rp[3],ap[3],w,c1);
84 ap+=4; rp+=4; num-=4;
85 }
86 if (num)
87 {
88 mul_add(rp[0],ap[0],w,c1); if (--num==0) return c1;
89 mul_add(rp[1],ap[1],w,c1); if (--num==0) return c1;
90 mul_add(rp[2],ap[2],w,c1); return c1;
91 }
92
93 return(c1);
94 }
95
96BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
97 {
98 BN_ULONG c1=0;
99
100 assert(num >= 0);
101 if (num <= 0) return(c1);
102
103 while (num&~3)
104 {
105 mul(rp[0],ap[0],w,c1);
106 mul(rp[1],ap[1],w,c1);
107 mul(rp[2],ap[2],w,c1);
108 mul(rp[3],ap[3],w,c1);
109 ap+=4; rp+=4; num-=4;
110 }
111 if (num)
112 {
113 mul(rp[0],ap[0],w,c1); if (--num == 0) return c1;
114 mul(rp[1],ap[1],w,c1); if (--num == 0) return c1;
115 mul(rp[2],ap[2],w,c1);
116 }
117 return(c1);
118 }
119
120void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
121 {
122 assert(n >= 0);
123 if (n <= 0) return;
124 while (n&~3)
125 {
126 sqr(r[0],r[1],a[0]);
127 sqr(r[2],r[3],a[1]);
128 sqr(r[4],r[5],a[2]);
129 sqr(r[6],r[7],a[3]);
130 a+=4; r+=8; n-=4;
131 }
132 if (n)
133 {
134 sqr(r[0],r[1],a[0]); if (--n == 0) return;
135 sqr(r[2],r[3],a[1]); if (--n == 0) return;
136 sqr(r[4],r[5],a[2]);
137 }
138 }
139
140#else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
141
142BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
143 {
144 BN_ULONG c=0;
145 BN_ULONG bl,bh;
146
147 assert(num >= 0);
148 if (num <= 0) return((BN_ULONG)0);
149
150 bl=LBITS(w);
151 bh=HBITS(w);
152
153 for (;;)
154 {
155 mul_add(rp[0],ap[0],bl,bh,c);
156 if (--num == 0) break;
157 mul_add(rp[1],ap[1],bl,bh,c);
158 if (--num == 0) break;
159 mul_add(rp[2],ap[2],bl,bh,c);
160 if (--num == 0) break;
161 mul_add(rp[3],ap[3],bl,bh,c);
162 if (--num == 0) break;
163 ap+=4;
164 rp+=4;
165 }
166 return(c);
167 }
168
169BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
170 {
171 BN_ULONG carry=0;
172 BN_ULONG bl,bh;
173
174 assert(num >= 0);
175 if (num <= 0) return((BN_ULONG)0);
176
177 bl=LBITS(w);
178 bh=HBITS(w);
179
180 for (;;)
181 {
182 mul(rp[0],ap[0],bl,bh,carry);
183 if (--num == 0) break;
184 mul(rp[1],ap[1],bl,bh,carry);
185 if (--num == 0) break;
186 mul(rp[2],ap[2],bl,bh,carry);
187 if (--num == 0) break;
188 mul(rp[3],ap[3],bl,bh,carry);
189 if (--num == 0) break;
190 ap+=4;
191 rp+=4;
192 }
193 return(carry);
194 }
195
196void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
197 {
198 assert(n >= 0);
199 if (n <= 0) return;
200 for (;;)
201 {
202 sqr64(r[0],r[1],a[0]);
203 if (--n == 0) break;
204
205 sqr64(r[2],r[3],a[1]);
206 if (--n == 0) break;
207
208 sqr64(r[4],r[5],a[2]);
209 if (--n == 0) break;
210
211 sqr64(r[6],r[7],a[3]);
212 if (--n == 0) break;
213
214 a+=4;
215 r+=8;
216 }
217 }
218
219#endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
220
221#if defined(BN_LLONG) && defined(BN_DIV2W)
222
223BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
224 {
225 return((BN_ULONG)(((((BN_ULLONG)h)<<BN_BITS2)|l)/(BN_ULLONG)d));
226 }
227
228#else
229
230/* Divide h-l by d and return the result. */
231/* I need to test this some more :-( */
232BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
233 {
234 BN_ULONG dh,dl,q,ret=0,th,tl,t;
235 int i,count=2;
236
237 if (d == 0) return(BN_MASK2);
238
239 i=BN_num_bits_word(d);
240 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i))
241 {
242#if !defined(NO_STDIO) && !defined(WIN16)
243 fprintf(stderr,"Division would overflow (%d)\n",i);
244#endif
245 abort();
246 }
247 i=BN_BITS2-i;
248 if (h >= d) h-=d;
249
250 if (i)
251 {
252 d<<=i;
253 h=(h<<i)|(l>>(BN_BITS2-i));
254 l<<=i;
255 }
256 dh=(d&BN_MASK2h)>>BN_BITS4;
257 dl=(d&BN_MASK2l);
258 for (;;)
259 {
260 if ((h>>BN_BITS4) == dh)
261 q=BN_MASK2l;
262 else
263 q=h/dh;
264
265 th=q*dh;
266 tl=dl*q;
267 for (;;)
268 {
269 t=h-th;
270 if ((t&BN_MASK2h) ||
271 ((tl) <= (
272 (t<<BN_BITS4)|
273 ((l&BN_MASK2h)>>BN_BITS4))))
274 break;
275 q--;
276 th-=dh;
277 tl-=dl;
278 }
279 t=(tl>>BN_BITS4);
280 tl=(tl<<BN_BITS4)&BN_MASK2h;
281 th+=t;
282
283 if (l < tl) th++;
284 l-=tl;
285 if (h < th)
286 {
287 h+=d;
288 q--;
289 }
290 h-=th;
291
292 if (--count == 0) break;
293
294 ret=q<<BN_BITS4;
295 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
296 l=(l&BN_MASK2l)<<BN_BITS4;
297 }
298 ret|=q;
299 return(ret);
300 }
301#endif /* !defined(BN_LLONG) && defined(BN_DIV2W) */
302
303#ifdef BN_LLONG
304BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
305 {
306 BN_ULLONG ll=0;
307
308 assert(n >= 0);
309 if (n <= 0) return((BN_ULONG)0);
310
311 for (;;)
312 {
313 ll+=(BN_ULLONG)a[0]+b[0];
314 r[0]=(BN_ULONG)ll&BN_MASK2;
315 ll>>=BN_BITS2;
316 if (--n <= 0) break;
317
318 ll+=(BN_ULLONG)a[1]+b[1];
319 r[1]=(BN_ULONG)ll&BN_MASK2;
320 ll>>=BN_BITS2;
321 if (--n <= 0) break;
322
323 ll+=(BN_ULLONG)a[2]+b[2];
324 r[2]=(BN_ULONG)ll&BN_MASK2;
325 ll>>=BN_BITS2;
326 if (--n <= 0) break;
327
328 ll+=(BN_ULLONG)a[3]+b[3];
329 r[3]=(BN_ULONG)ll&BN_MASK2;
330 ll>>=BN_BITS2;
331 if (--n <= 0) break;
332
333 a+=4;
334 b+=4;
335 r+=4;
336 }
337 return((BN_ULONG)ll);
338 }
339#else /* !BN_LLONG */
340BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
341 {
342 BN_ULONG c,l,t;
343
344 assert(n >= 0);
345 if (n <= 0) return((BN_ULONG)0);
346
347 c=0;
348 for (;;)
349 {
350 t=a[0];
351 t=(t+c)&BN_MASK2;
352 c=(t < c);
353 l=(t+b[0])&BN_MASK2;
354 c+=(l < t);
355 r[0]=l;
356 if (--n <= 0) break;
357
358 t=a[1];
359 t=(t+c)&BN_MASK2;
360 c=(t < c);
361 l=(t+b[1])&BN_MASK2;
362 c+=(l < t);
363 r[1]=l;
364 if (--n <= 0) break;
365
366 t=a[2];
367 t=(t+c)&BN_MASK2;
368 c=(t < c);
369 l=(t+b[2])&BN_MASK2;
370 c+=(l < t);
371 r[2]=l;
372 if (--n <= 0) break;
373
374 t=a[3];
375 t=(t+c)&BN_MASK2;
376 c=(t < c);
377 l=(t+b[3])&BN_MASK2;
378 c+=(l < t);
379 r[3]=l;
380 if (--n <= 0) break;
381
382 a+=4;
383 b+=4;
384 r+=4;
385 }
386 return((BN_ULONG)c);
387 }
388#endif /* !BN_LLONG */
389
390BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
391 {
392 BN_ULONG t1,t2;
393 int c=0;
394
395 assert(n >= 0);
396 if (n <= 0) return((BN_ULONG)0);
397
398 for (;;)
399 {
400 t1=a[0]; t2=b[0];
401 r[0]=(t1-t2-c)&BN_MASK2;
402 if (t1 != t2) c=(t1 < t2);
403 if (--n <= 0) break;
404
405 t1=a[1]; t2=b[1];
406 r[1]=(t1-t2-c)&BN_MASK2;
407 if (t1 != t2) c=(t1 < t2);
408 if (--n <= 0) break;
409
410 t1=a[2]; t2=b[2];
411 r[2]=(t1-t2-c)&BN_MASK2;
412 if (t1 != t2) c=(t1 < t2);
413 if (--n <= 0) break;
414
415 t1=a[3]; t2=b[3];
416 r[3]=(t1-t2-c)&BN_MASK2;
417 if (t1 != t2) c=(t1 < t2);
418 if (--n <= 0) break;
419
420 a+=4;
421 b+=4;
422 r+=4;
423 }
424 return(c);
425 }
426
427#ifdef BN_MUL_COMBA
428
429#undef bn_mul_comba8
430#undef bn_mul_comba4
431#undef bn_sqr_comba8
432#undef bn_sqr_comba4
433
434/* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */
435/* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */
436/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
437/* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
438
439#ifdef BN_LLONG
440#define mul_add_c(a,b,c0,c1,c2) \
441 t=(BN_ULLONG)a*b; \
442 t1=(BN_ULONG)Lw(t); \
443 t2=(BN_ULONG)Hw(t); \
444 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
445 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
446
447#define mul_add_c2(a,b,c0,c1,c2) \
448 t=(BN_ULLONG)a*b; \
449 tt=(t+t)&BN_MASK; \
450 if (tt < t) c2++; \
451 t1=(BN_ULONG)Lw(tt); \
452 t2=(BN_ULONG)Hw(tt); \
453 c0=(c0+t1)&BN_MASK2; \
454 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
455 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
456
457#define sqr_add_c(a,i,c0,c1,c2) \
458 t=(BN_ULLONG)a[i]*a[i]; \
459 t1=(BN_ULONG)Lw(t); \
460 t2=(BN_ULONG)Hw(t); \
461 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
462 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
463
464#define sqr_add_c2(a,i,j,c0,c1,c2) \
465 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
466
467#elif defined(BN_UMULT_HIGH)
468
469#define mul_add_c(a,b,c0,c1,c2) { \
470 BN_ULONG ta=(a),tb=(b); \
471 t1 = ta * tb; \
472 t2 = BN_UMULT_HIGH(ta,tb); \
473 c0 += t1; t2 += (c0<t1)?1:0; \
474 c1 += t2; c2 += (c1<t2)?1:0; \
475 }
476
477#define mul_add_c2(a,b,c0,c1,c2) { \
478 BN_ULONG ta=(a),tb=(b),t0; \
479 t1 = BN_UMULT_HIGH(ta,tb); \
480 t0 = ta * tb; \
481 t2 = t1+t1; c2 += (t2<t1)?1:0; \
482 t1 = t0+t0; t2 += (t1<t0)?1:0; \
483 c0 += t1; t2 += (c0<t1)?1:0; \
484 c1 += t2; c2 += (c1<t2)?1:0; \
485 }
486
487#define sqr_add_c(a,i,c0,c1,c2) { \
488 BN_ULONG ta=(a)[i]; \
489 t1 = ta * ta; \
490 t2 = BN_UMULT_HIGH(ta,ta); \
491 c0 += t1; t2 += (c0<t1)?1:0; \
492 c1 += t2; c2 += (c1<t2)?1:0; \
493 }
494
495#define sqr_add_c2(a,i,j,c0,c1,c2) \
496 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
497
498#else /* !BN_LLONG */
499#define mul_add_c(a,b,c0,c1,c2) \
500 t1=LBITS(a); t2=HBITS(a); \
501 bl=LBITS(b); bh=HBITS(b); \
502 mul64(t1,t2,bl,bh); \
503 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
504 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
505
506#define mul_add_c2(a,b,c0,c1,c2) \
507 t1=LBITS(a); t2=HBITS(a); \
508 bl=LBITS(b); bh=HBITS(b); \
509 mul64(t1,t2,bl,bh); \
510 if (t2 & BN_TBIT) c2++; \
511 t2=(t2+t2)&BN_MASK2; \
512 if (t1 & BN_TBIT) t2++; \
513 t1=(t1+t1)&BN_MASK2; \
514 c0=(c0+t1)&BN_MASK2; \
515 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
516 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
517
518#define sqr_add_c(a,i,c0,c1,c2) \
519 sqr64(t1,t2,(a)[i]); \
520 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
521 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
522
523#define sqr_add_c2(a,i,j,c0,c1,c2) \
524 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
525#endif /* !BN_LLONG */
526
527void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
528 {
529#ifdef BN_LLONG
530 BN_ULLONG t;
531#else
532 BN_ULONG bl,bh;
533#endif
534 BN_ULONG t1,t2;
535 BN_ULONG c1,c2,c3;
536
537 c1=0;
538 c2=0;
539 c3=0;
540 mul_add_c(a[0],b[0],c1,c2,c3);
541 r[0]=c1;
542 c1=0;
543 mul_add_c(a[0],b[1],c2,c3,c1);
544 mul_add_c(a[1],b[0],c2,c3,c1);
545 r[1]=c2;
546 c2=0;
547 mul_add_c(a[2],b[0],c3,c1,c2);
548 mul_add_c(a[1],b[1],c3,c1,c2);
549 mul_add_c(a[0],b[2],c3,c1,c2);
550 r[2]=c3;
551 c3=0;
552 mul_add_c(a[0],b[3],c1,c2,c3);
553 mul_add_c(a[1],b[2],c1,c2,c3);
554 mul_add_c(a[2],b[1],c1,c2,c3);
555 mul_add_c(a[3],b[0],c1,c2,c3);
556 r[3]=c1;
557 c1=0;
558 mul_add_c(a[4],b[0],c2,c3,c1);
559 mul_add_c(a[3],b[1],c2,c3,c1);
560 mul_add_c(a[2],b[2],c2,c3,c1);
561 mul_add_c(a[1],b[3],c2,c3,c1);
562 mul_add_c(a[0],b[4],c2,c3,c1);
563 r[4]=c2;
564 c2=0;
565 mul_add_c(a[0],b[5],c3,c1,c2);
566 mul_add_c(a[1],b[4],c3,c1,c2);
567 mul_add_c(a[2],b[3],c3,c1,c2);
568 mul_add_c(a[3],b[2],c3,c1,c2);
569 mul_add_c(a[4],b[1],c3,c1,c2);
570 mul_add_c(a[5],b[0],c3,c1,c2);
571 r[5]=c3;
572 c3=0;
573 mul_add_c(a[6],b[0],c1,c2,c3);
574 mul_add_c(a[5],b[1],c1,c2,c3);
575 mul_add_c(a[4],b[2],c1,c2,c3);
576 mul_add_c(a[3],b[3],c1,c2,c3);
577 mul_add_c(a[2],b[4],c1,c2,c3);
578 mul_add_c(a[1],b[5],c1,c2,c3);
579 mul_add_c(a[0],b[6],c1,c2,c3);
580 r[6]=c1;
581 c1=0;
582 mul_add_c(a[0],b[7],c2,c3,c1);
583 mul_add_c(a[1],b[6],c2,c3,c1);
584 mul_add_c(a[2],b[5],c2,c3,c1);
585 mul_add_c(a[3],b[4],c2,c3,c1);
586 mul_add_c(a[4],b[3],c2,c3,c1);
587 mul_add_c(a[5],b[2],c2,c3,c1);
588 mul_add_c(a[6],b[1],c2,c3,c1);
589 mul_add_c(a[7],b[0],c2,c3,c1);
590 r[7]=c2;
591 c2=0;
592 mul_add_c(a[7],b[1],c3,c1,c2);
593 mul_add_c(a[6],b[2],c3,c1,c2);
594 mul_add_c(a[5],b[3],c3,c1,c2);
595 mul_add_c(a[4],b[4],c3,c1,c2);
596 mul_add_c(a[3],b[5],c3,c1,c2);
597 mul_add_c(a[2],b[6],c3,c1,c2);
598 mul_add_c(a[1],b[7],c3,c1,c2);
599 r[8]=c3;
600 c3=0;
601 mul_add_c(a[2],b[7],c1,c2,c3);
602 mul_add_c(a[3],b[6],c1,c2,c3);
603 mul_add_c(a[4],b[5],c1,c2,c3);
604 mul_add_c(a[5],b[4],c1,c2,c3);
605 mul_add_c(a[6],b[3],c1,c2,c3);
606 mul_add_c(a[7],b[2],c1,c2,c3);
607 r[9]=c1;
608 c1=0;
609 mul_add_c(a[7],b[3],c2,c3,c1);
610 mul_add_c(a[6],b[4],c2,c3,c1);
611 mul_add_c(a[5],b[5],c2,c3,c1);
612 mul_add_c(a[4],b[6],c2,c3,c1);
613 mul_add_c(a[3],b[7],c2,c3,c1);
614 r[10]=c2;
615 c2=0;
616 mul_add_c(a[4],b[7],c3,c1,c2);
617 mul_add_c(a[5],b[6],c3,c1,c2);
618 mul_add_c(a[6],b[5],c3,c1,c2);
619 mul_add_c(a[7],b[4],c3,c1,c2);
620 r[11]=c3;
621 c3=0;
622 mul_add_c(a[7],b[5],c1,c2,c3);
623 mul_add_c(a[6],b[6],c1,c2,c3);
624 mul_add_c(a[5],b[7],c1,c2,c3);
625 r[12]=c1;
626 c1=0;
627 mul_add_c(a[6],b[7],c2,c3,c1);
628 mul_add_c(a[7],b[6],c2,c3,c1);
629 r[13]=c2;
630 c2=0;
631 mul_add_c(a[7],b[7],c3,c1,c2);
632 r[14]=c3;
633 r[15]=c1;
634 }
635
636void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
637 {
638#ifdef BN_LLONG
639 BN_ULLONG t;
640#else
641 BN_ULONG bl,bh;
642#endif
643 BN_ULONG t1,t2;
644 BN_ULONG c1,c2,c3;
645
646 c1=0;
647 c2=0;
648 c3=0;
649 mul_add_c(a[0],b[0],c1,c2,c3);
650 r[0]=c1;
651 c1=0;
652 mul_add_c(a[0],b[1],c2,c3,c1);
653 mul_add_c(a[1],b[0],c2,c3,c1);
654 r[1]=c2;
655 c2=0;
656 mul_add_c(a[2],b[0],c3,c1,c2);
657 mul_add_c(a[1],b[1],c3,c1,c2);
658 mul_add_c(a[0],b[2],c3,c1,c2);
659 r[2]=c3;
660 c3=0;
661 mul_add_c(a[0],b[3],c1,c2,c3);
662 mul_add_c(a[1],b[2],c1,c2,c3);
663 mul_add_c(a[2],b[1],c1,c2,c3);
664 mul_add_c(a[3],b[0],c1,c2,c3);
665 r[3]=c1;
666 c1=0;
667 mul_add_c(a[3],b[1],c2,c3,c1);
668 mul_add_c(a[2],b[2],c2,c3,c1);
669 mul_add_c(a[1],b[3],c2,c3,c1);
670 r[4]=c2;
671 c2=0;
672 mul_add_c(a[2],b[3],c3,c1,c2);
673 mul_add_c(a[3],b[2],c3,c1,c2);
674 r[5]=c3;
675 c3=0;
676 mul_add_c(a[3],b[3],c1,c2,c3);
677 r[6]=c1;
678 r[7]=c2;
679 }
680
681void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
682 {
683#ifdef BN_LLONG
684 BN_ULLONG t,tt;
685#else
686 BN_ULONG bl,bh;
687#endif
688 BN_ULONG t1,t2;
689 BN_ULONG c1,c2,c3;
690
691 c1=0;
692 c2=0;
693 c3=0;
694 sqr_add_c(a,0,c1,c2,c3);
695 r[0]=c1;
696 c1=0;
697 sqr_add_c2(a,1,0,c2,c3,c1);
698 r[1]=c2;
699 c2=0;
700 sqr_add_c(a,1,c3,c1,c2);
701 sqr_add_c2(a,2,0,c3,c1,c2);
702 r[2]=c3;
703 c3=0;
704 sqr_add_c2(a,3,0,c1,c2,c3);
705 sqr_add_c2(a,2,1,c1,c2,c3);
706 r[3]=c1;
707 c1=0;
708 sqr_add_c(a,2,c2,c3,c1);
709 sqr_add_c2(a,3,1,c2,c3,c1);
710 sqr_add_c2(a,4,0,c2,c3,c1);
711 r[4]=c2;
712 c2=0;
713 sqr_add_c2(a,5,0,c3,c1,c2);
714 sqr_add_c2(a,4,1,c3,c1,c2);
715 sqr_add_c2(a,3,2,c3,c1,c2);
716 r[5]=c3;
717 c3=0;
718 sqr_add_c(a,3,c1,c2,c3);
719 sqr_add_c2(a,4,2,c1,c2,c3);
720 sqr_add_c2(a,5,1,c1,c2,c3);
721 sqr_add_c2(a,6,0,c1,c2,c3);
722 r[6]=c1;
723 c1=0;
724 sqr_add_c2(a,7,0,c2,c3,c1);
725 sqr_add_c2(a,6,1,c2,c3,c1);
726 sqr_add_c2(a,5,2,c2,c3,c1);
727 sqr_add_c2(a,4,3,c2,c3,c1);
728 r[7]=c2;
729 c2=0;
730 sqr_add_c(a,4,c3,c1,c2);
731 sqr_add_c2(a,5,3,c3,c1,c2);
732 sqr_add_c2(a,6,2,c3,c1,c2);
733 sqr_add_c2(a,7,1,c3,c1,c2);
734 r[8]=c3;
735 c3=0;
736 sqr_add_c2(a,7,2,c1,c2,c3);
737 sqr_add_c2(a,6,3,c1,c2,c3);
738 sqr_add_c2(a,5,4,c1,c2,c3);
739 r[9]=c1;
740 c1=0;
741 sqr_add_c(a,5,c2,c3,c1);
742 sqr_add_c2(a,6,4,c2,c3,c1);
743 sqr_add_c2(a,7,3,c2,c3,c1);
744 r[10]=c2;
745 c2=0;
746 sqr_add_c2(a,7,4,c3,c1,c2);
747 sqr_add_c2(a,6,5,c3,c1,c2);
748 r[11]=c3;
749 c3=0;
750 sqr_add_c(a,6,c1,c2,c3);
751 sqr_add_c2(a,7,5,c1,c2,c3);
752 r[12]=c1;
753 c1=0;
754 sqr_add_c2(a,7,6,c2,c3,c1);
755 r[13]=c2;
756 c2=0;
757 sqr_add_c(a,7,c3,c1,c2);
758 r[14]=c3;
759 r[15]=c1;
760 }
761
762void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
763 {
764#ifdef BN_LLONG
765 BN_ULLONG t,tt;
766#else
767 BN_ULONG bl,bh;
768#endif
769 BN_ULONG t1,t2;
770 BN_ULONG c1,c2,c3;
771
772 c1=0;
773 c2=0;
774 c3=0;
775 sqr_add_c(a,0,c1,c2,c3);
776 r[0]=c1;
777 c1=0;
778 sqr_add_c2(a,1,0,c2,c3,c1);
779 r[1]=c2;
780 c2=0;
781 sqr_add_c(a,1,c3,c1,c2);
782 sqr_add_c2(a,2,0,c3,c1,c2);
783 r[2]=c3;
784 c3=0;
785 sqr_add_c2(a,3,0,c1,c2,c3);
786 sqr_add_c2(a,2,1,c1,c2,c3);
787 r[3]=c1;
788 c1=0;
789 sqr_add_c(a,2,c2,c3,c1);
790 sqr_add_c2(a,3,1,c2,c3,c1);
791 r[4]=c2;
792 c2=0;
793 sqr_add_c2(a,3,2,c3,c1,c2);
794 r[5]=c3;
795 c3=0;
796 sqr_add_c(a,3,c1,c2,c3);
797 r[6]=c1;
798 r[7]=c2;
799 }
800#else /* !BN_MUL_COMBA */
801
802/* hmm... is it faster just to do a multiply? */
803#undef bn_sqr_comba4
804void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
805 {
806 BN_ULONG t[8];
807 bn_sqr_normal(r,a,4,t);
808 }
809
810#undef bn_sqr_comba8
811void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
812 {
813 BN_ULONG t[16];
814 bn_sqr_normal(r,a,8,t);
815 }
816
817void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
818 {
819 r[4]=bn_mul_words( &(r[0]),a,4,b[0]);
820 r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]);
821 r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]);
822 r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]);
823 }
824
825void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
826 {
827 r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
828 r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
829 r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
830 r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
831 r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
832 r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
833 r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
834 r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
835 }
836
837#endif /* !BN_MUL_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_ctx.c b/src/lib/libcrypto/bn/bn_ctx.c
deleted file mode 100644
index 46132fd180..0000000000
--- a/src/lib/libcrypto/bn/bn_ctx.c
+++ /dev/null
@@ -1,144 +0,0 @@
1/* crypto/bn/bn_ctx.c */
2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ====================================================================
4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@openssl.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#ifndef BN_CTX_DEBUG
58# undef NDEBUG /* avoid conflicting definitions */
59# define NDEBUG
60#endif
61
62#include <stdio.h>
63#include <assert.h>
64#include "cryptlib.h"
65#include <openssl/bn.h>
66
67
68BN_CTX *BN_CTX_new(void)
69 {
70 BN_CTX *ret;
71
72 ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
73 if (ret == NULL)
74 {
75 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
76 return(NULL);
77 }
78
79 BN_CTX_init(ret);
80 ret->flags=BN_FLG_MALLOCED;
81 return(ret);
82 }
83
84void BN_CTX_init(BN_CTX *ctx)
85 {
86 int i;
87 ctx->tos = 0;
88 ctx->flags = 0;
89 ctx->depth = 0;
90 ctx->too_many = 0;
91 for (i = 0; i < BN_CTX_NUM; i++)
92 BN_init(&(ctx->bn[i]));
93 }
94
95void BN_CTX_free(BN_CTX *ctx)
96 {
97 int i;
98
99 if (ctx == NULL) return;
100 assert(ctx->depth == 0);
101
102 for (i=0; i < BN_CTX_NUM; i++)
103 BN_clear_free(&(ctx->bn[i]));
104 if (ctx->flags & BN_FLG_MALLOCED)
105 Free(ctx);
106 }
107
108void BN_CTX_start(BN_CTX *ctx)
109 {
110 if (ctx->depth < BN_CTX_NUM_POS)
111 ctx->pos[ctx->depth] = ctx->tos;
112 ctx->depth++;
113 }
114
115BIGNUM *BN_CTX_get(BN_CTX *ctx)
116 {
117 if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
118 {
119 if (!ctx->too_many)
120 {
121 BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
122 /* disable error code until BN_CTX_end is called: */
123 ctx->too_many = 1;
124 }
125 return NULL;
126 }
127 return (&(ctx->bn[ctx->tos++]));
128 }
129
130void BN_CTX_end(BN_CTX *ctx)
131 {
132 if (ctx == NULL) return;
133 assert(ctx->depth > 0);
134 if (ctx->depth == 0)
135 /* should never happen, but we can tolerate it if not in
136 * debug mode (could be a 'goto err' in the calling function
137 * before BN_CTX_start was reached) */
138 BN_CTX_start(ctx);
139
140 ctx->too_many = 0;
141 ctx->depth--;
142 if (ctx->depth < BN_CTX_NUM_POS)
143 ctx->tos = ctx->pos[ctx->depth];
144 }
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
deleted file mode 100644
index 07af1d3b44..0000000000
--- a/src/lib/libcrypto/bn/bn_div.c
+++ /dev/null
@@ -1,380 +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, const BIGNUM *m, const BIGNUM *d,
67 BN_CTX *ctx)
68 {
69 int i,nm,nd;
70 int ret = 0;
71 BIGNUM *D;
72
73 bn_check_top(m);
74 bn_check_top(d);
75 if (BN_is_zero(d))
76 {
77 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
78 return(0);
79 }
80
81 if (BN_ucmp(m,d) < 0)
82 {
83 if (rem != NULL)
84 { if (BN_copy(rem,m) == NULL) return(0); }
85 if (dv != NULL) BN_zero(dv);
86 return(1);
87 }
88
89 BN_CTX_start(ctx);
90 D = BN_CTX_get(ctx);
91 if (dv == NULL) dv = BN_CTX_get(ctx);
92 if (rem == NULL) rem = BN_CTX_get(ctx);
93 if (D == NULL || dv == NULL || rem == NULL)
94 goto end;
95
96 nd=BN_num_bits(d);
97 nm=BN_num_bits(m);
98 if (BN_copy(D,d) == NULL) goto end;
99 if (BN_copy(rem,m) == NULL) goto end;
100
101 /* The next 2 are needed so we can do a dv->d[0]|=1 later
102 * since BN_lshift1 will only work once there is a value :-) */
103 BN_zero(dv);
104 bn_wexpand(dv,1);
105 dv->top=1;
106
107 if (!BN_lshift(D,D,nm-nd)) goto end;
108 for (i=nm-nd; i>=0; i--)
109 {
110 if (!BN_lshift1(dv,dv)) goto end;
111 if (BN_ucmp(rem,D) >= 0)
112 {
113 dv->d[0]|=1;
114 if (!BN_usub(rem,rem,D)) goto end;
115 }
116/* CAN IMPROVE (and have now :=) */
117 if (!BN_rshift1(D,D)) goto end;
118 }
119 rem->neg=BN_is_zero(rem)?0:m->neg;
120 dv->neg=m->neg^d->neg;
121 ret = 1;
122 end:
123 BN_CTX_end(ctx);
124 return(ret);
125 }
126
127#else
128
129#if !defined(NO_ASM) && !defined(NO_INLINE_ASM) && !defined(PEDANTIC) && !defined(BN_DIV3W)
130# if defined(__GNUC__) && __GNUC__>=2
131# if defined(__i386)
132 /*
133 * There were two reasons for implementing this template:
134 * - GNU C generates a call to a function (__udivdi3 to be exact)
135 * in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to
136 * understand why...);
137 * - divl doesn't only calculate quotient, but also leaves
138 * remainder in %edx which we can definitely use here:-)
139 *
140 * <appro@fy.chalmers.se>
141 */
142# define bn_div_words(n0,n1,d0) \
143 ({ asm volatile ( \
144 "divl %4" \
145 : "=a"(q), "=d"(rem) \
146 : "a"(n1), "d"(n0), "g"(d0) \
147 : "cc"); \
148 q; \
149 })
150# define REMAINDER_IS_ALREADY_CALCULATED
151# endif /* __<cpu> */
152# endif /* __GNUC__ */
153#endif /* NO_ASM */
154
155int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
156 BN_CTX *ctx)
157 {
158 int norm_shift,i,j,loop;
159 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
160 BN_ULONG *resp,*wnump;
161 BN_ULONG d0,d1;
162 int num_n,div_n;
163
164 bn_check_top(num);
165 bn_check_top(divisor);
166
167 if (BN_is_zero(divisor))
168 {
169 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
170 return(0);
171 }
172
173 if (BN_ucmp(num,divisor) < 0)
174 {
175 if (rm != NULL)
176 { if (BN_copy(rm,num) == NULL) return(0); }
177 if (dv != NULL) BN_zero(dv);
178 return(1);
179 }
180
181 BN_CTX_start(ctx);
182 tmp=BN_CTX_get(ctx);
183 tmp->neg=0;
184 snum=BN_CTX_get(ctx);
185 sdiv=BN_CTX_get(ctx);
186 if (dv == NULL)
187 res=BN_CTX_get(ctx);
188 else res=dv;
189 if (res == NULL) goto err;
190
191 /* First we normalise the numbers */
192 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
193 BN_lshift(sdiv,divisor,norm_shift);
194 sdiv->neg=0;
195 norm_shift+=BN_BITS2;
196 BN_lshift(snum,num,norm_shift);
197 snum->neg=0;
198 div_n=sdiv->top;
199 num_n=snum->top;
200 loop=num_n-div_n;
201
202 /* Lets setup a 'window' into snum
203 * This is the part that corresponds to the current
204 * 'area' being divided */
205 BN_init(&wnum);
206 wnum.d= &(snum->d[loop]);
207 wnum.top= div_n;
208 wnum.max= snum->max+1; /* a bit of a lie */
209
210 /* Get the top 2 words of sdiv */
211 /* i=sdiv->top; */
212 d0=sdiv->d[div_n-1];
213 d1=(div_n == 1)?0:sdiv->d[div_n-2];
214
215 /* pointer to the 'top' of snum */
216 wnump= &(snum->d[num_n-1]);
217
218 /* Setup to 'res' */
219 res->neg= (num->neg^divisor->neg);
220 if (!bn_wexpand(res,(loop+1))) goto err;
221 res->top=loop;
222 resp= &(res->d[loop-1]);
223
224 /* space for temp */
225 if (!bn_wexpand(tmp,(div_n+1))) goto err;
226
227 if (BN_ucmp(&wnum,sdiv) >= 0)
228 {
229 if (!BN_usub(&wnum,&wnum,sdiv)) goto err;
230 *resp=1;
231 res->d[res->top-1]=1;
232 }
233 else
234 res->top--;
235 resp--;
236
237 for (i=0; i<loop-1; i++)
238 {
239 BN_ULONG q,l0;
240#ifdef BN_DIV3W
241 q=bn_div_3_words(wnump,d1,d0);
242#else
243 BN_ULONG n0,n1,rem=0;
244
245 n0=wnump[0];
246 n1=wnump[-1];
247 if (n0 == d0)
248 q=BN_MASK2;
249 else /* n0 < d0 */
250 {
251#ifdef BN_LLONG
252 BN_ULLONG t2;
253
254#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
255 q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);
256#else
257 q=bn_div_words(n0,n1,d0);
258#endif
259
260#ifndef REMAINDER_IS_ALREADY_CALCULATED
261 /*
262 * rem doesn't have to be BN_ULLONG. The least we
263 * know it's less that d0, isn't it?
264 */
265 rem=(n1-q*d0)&BN_MASK2;
266#endif
267 t2=(BN_ULLONG)d1*q;
268
269 for (;;)
270 {
271 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
272 break;
273 q--;
274 rem += d0;
275 if (rem < d0) break; /* don't let rem overflow */
276 t2 -= d1;
277 }
278#else /* !BN_LLONG */
279 BN_ULONG t2l,t2h,ql,qh;
280
281 q=bn_div_words(n0,n1,d0);
282#ifndef REMAINDER_IS_ALREADY_CALCULATED
283 rem=(n1-q*d0)&BN_MASK2;
284#endif
285
286#ifdef BN_UMULT_HIGH
287 t2l = d1 * q;
288 t2h = BN_UMULT_HIGH(d1,q);
289#else
290 t2l=LBITS(d1); t2h=HBITS(d1);
291 ql =LBITS(q); qh =HBITS(q);
292 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
293#endif
294
295 for (;;)
296 {
297 if ((t2h < rem) ||
298 ((t2h == rem) && (t2l <= wnump[-2])))
299 break;
300 q--;
301 rem += d0;
302 if (rem < d0) break; /* don't let rem overflow */
303 if (t2l < d1) t2h--; t2l -= d1;
304 }
305#endif /* !BN_LLONG */
306 }
307#endif /* !BN_DIV3W */
308
309 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
310 wnum.d--; wnum.top++;
311 tmp->d[div_n]=l0;
312 for (j=div_n+1; j>0; j--)
313 if (tmp->d[j-1]) break;
314 tmp->top=j;
315
316 j=wnum.top;
317 BN_sub(&wnum,&wnum,tmp);
318
319 snum->top=snum->top+wnum.top-j;
320
321 if (wnum.neg)
322 {
323 q--;
324 j=wnum.top;
325 BN_add(&wnum,&wnum,sdiv);
326 snum->top+=wnum.top-j;
327 }
328 *(resp--)=q;
329 wnump--;
330 }
331 if (rm != NULL)
332 {
333 BN_rshift(rm,snum,norm_shift);
334 rm->neg=num->neg;
335 }
336 BN_CTX_end(ctx);
337 return(1);
338err:
339 BN_CTX_end(ctx);
340 return(0);
341 }
342
343#endif
344
345/* rem != m */
346int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
347 {
348#if 0 /* The old slow way */
349 int i,nm,nd;
350 BIGNUM *dv;
351
352 if (BN_ucmp(m,d) < 0)
353 return((BN_copy(rem,m) == NULL)?0:1);
354
355 BN_CTX_start(ctx);
356 dv=BN_CTX_get(ctx);
357
358 if (!BN_copy(rem,m)) goto err;
359
360 nm=BN_num_bits(rem);
361 nd=BN_num_bits(d);
362 if (!BN_lshift(dv,d,nm-nd)) goto err;
363 for (i=nm-nd; i>=0; i--)
364 {
365 if (BN_cmp(rem,dv) >= 0)
366 {
367 if (!BN_sub(rem,rem,dv)) goto err;
368 }
369 if (!BN_rshift1(dv,dv)) goto err;
370 }
371 BN_CTX_end(ctx);
372 return(1);
373 err:
374 BN_CTX_end(ctx);
375 return(0);
376#else
377 return(BN_div(NULL,rem,m,d,ctx));
378#endif
379 }
380
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c
deleted file mode 100644
index 988270bcf4..0000000000
--- a/src/lib/libcrypto/bn/bn_err.c
+++ /dev/null
@@ -1,119 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/bn.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA BN_str_functs[]=
68 {
69{ERR_PACK(0,BN_F_BN_BLINDING_CONVERT,0), "BN_BLINDING_convert"},
70{ERR_PACK(0,BN_F_BN_BLINDING_INVERT,0), "BN_BLINDING_invert"},
71{ERR_PACK(0,BN_F_BN_BLINDING_NEW,0), "BN_BLINDING_new"},
72{ERR_PACK(0,BN_F_BN_BLINDING_UPDATE,0), "BN_BLINDING_update"},
73{ERR_PACK(0,BN_F_BN_BN2DEC,0), "BN_bn2dec"},
74{ERR_PACK(0,BN_F_BN_BN2HEX,0), "BN_bn2hex"},
75{ERR_PACK(0,BN_F_BN_CTX_GET,0), "BN_CTX_get"},
76{ERR_PACK(0,BN_F_BN_CTX_NEW,0), "BN_CTX_new"},
77{ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"},
78{ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"},
79{ERR_PACK(0,BN_F_BN_MOD_EXP_MONT,0), "BN_mod_exp_mont"},
80{ERR_PACK(0,BN_F_BN_MOD_INVERSE,0), "BN_mod_inverse"},
81{ERR_PACK(0,BN_F_BN_MOD_MUL_RECIPROCAL,0), "BN_mod_mul_reciprocal"},
82{ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"},
83{ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"},
84{ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"},
85{ERR_PACK(0,BN_F_BN_USUB,0), "BN_usub"},
86{0,NULL}
87 };
88
89static ERR_STRING_DATA BN_str_reasons[]=
90 {
91{BN_R_ARG2_LT_ARG3 ,"arg2 lt arg3"},
92{BN_R_BAD_RECIPROCAL ,"bad reciprocal"},
93{BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"},
94{BN_R_DIV_BY_ZERO ,"div by zero"},
95{BN_R_ENCODING_ERROR ,"encoding error"},
96{BN_R_EXPAND_ON_STATIC_BIGNUM_DATA ,"expand on static bignum data"},
97{BN_R_INVALID_LENGTH ,"invalid length"},
98{BN_R_NOT_INITIALIZED ,"not initialized"},
99{BN_R_NO_INVERSE ,"no inverse"},
100{BN_R_TOO_MANY_TEMPORARY_VARIABLES ,"too many temporary variables"},
101{0,NULL}
102 };
103
104#endif
105
106void ERR_load_BN_strings(void)
107 {
108 static int init=1;
109
110 if (init)
111 {
112 init=0;
113#ifndef NO_ERR
114 ERR_load_strings(ERR_LIB_BN,BN_str_functs);
115 ERR_load_strings(ERR_LIB_BN,BN_str_reasons);
116#endif
117
118 }
119 }
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
deleted file mode 100644
index 0c11601675..0000000000
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ /dev/null
@@ -1,749 +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#ifdef ATALLA
63# include <alloca.h>
64# include <atasi.h>
65# include <assert.h>
66# include <dlfcn.h>
67#endif
68
69#define TABLE_SIZE 16
70
71/* slow but works */
72int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
73 {
74 BIGNUM *t;
75 int r=0;
76
77 bn_check_top(a);
78 bn_check_top(b);
79 bn_check_top(m);
80
81 BN_CTX_start(ctx);
82 if ((t = BN_CTX_get(ctx)) == NULL) goto err;
83 if (a == b)
84 { if (!BN_sqr(t,a,ctx)) goto err; }
85 else
86 { if (!BN_mul(t,a,b,ctx)) goto err; }
87 if (!BN_mod(ret,t,m,ctx)) goto err;
88 r=1;
89err:
90 BN_CTX_end(ctx);
91 return(r);
92 }
93
94#if 0
95/* this one works - simple but works */
96int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)
97 {
98 int i,bits,ret=0;
99 BIGNUM *v,*tmp;
100
101 BN_CTX_start(ctx);
102 v = BN_CTX_get(ctx);
103 tmp = BN_CTX_get(ctx);
104 if (v == NULL || tmp == NULL) goto err;
105
106 if (BN_copy(v,a) == NULL) goto err;
107 bits=BN_num_bits(p);
108
109 if (BN_is_odd(p))
110 { if (BN_copy(r,a) == NULL) goto err; }
111 else { if (!BN_one(r)) goto err; }
112
113 for (i=1; i<bits; i++)
114 {
115 if (!BN_sqr(tmp,v,ctx)) goto err;
116 if (!BN_mod(v,tmp,m,ctx)) goto err;
117 if (BN_is_bit_set(p,i))
118 {
119 if (!BN_mul(tmp,r,v,ctx)) goto err;
120 if (!BN_mod(r,tmp,m,ctx)) goto err;
121 }
122 }
123 ret=1;
124err:
125 BN_CTX_end(ctx);
126 return(ret);
127 }
128
129#endif
130
131/* this one works - simple but works */
132int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx)
133 {
134 int i,bits,ret=0;
135 BIGNUM *v,*rr;
136
137 BN_CTX_start(ctx);
138 if ((r == a) || (r == p))
139 rr = BN_CTX_get(ctx);
140 else
141 rr = r;
142 if ((v = BN_CTX_get(ctx)) == NULL) goto err;
143
144 if (BN_copy(v,a) == NULL) goto err;
145 bits=BN_num_bits(p);
146
147 if (BN_is_odd(p))
148 { if (BN_copy(rr,a) == NULL) goto err; }
149 else { if (!BN_one(rr)) goto err; }
150
151 for (i=1; i<bits; i++)
152 {
153 if (!BN_sqr(v,v,ctx)) goto err;
154 if (BN_is_bit_set(p,i))
155 {
156 if (!BN_mul(rr,rr,v,ctx)) goto err;
157 }
158 }
159 ret=1;
160err:
161 if (r != rr) BN_copy(r,rr);
162 BN_CTX_end(ctx);
163 return(ret);
164 }
165
166#ifdef ATALLA
167
168/*
169 * This routine will dynamically check for the existance of an Atalla AXL-200
170 * SSL accelerator module. If one is found, the variable
171 * asi_accelerator_present is set to 1 and the function pointers
172 * ptr_ASI_xxxxxx above will be initialized to corresponding ASI API calls.
173 */
174typedef int tfnASI_GetPerformanceStatistics(int reset_flag,
175 unsigned int *ret_buf);
176typedef int tfnASI_GetHardwareConfig(long card_num, unsigned int *ret_buf);
177typedef int tfnASI_RSAPrivateKeyOpFn(RSAPrivateKey * rsaKey,
178 unsigned char *output,
179 unsigned char *input,
180 unsigned int modulus_len);
181
182static tfnASI_GetHardwareConfig *ptr_ASI_GetHardwareConfig;
183static tfnASI_RSAPrivateKeyOpFn *ptr_ASI_RSAPrivateKeyOpFn;
184static tfnASI_GetPerformanceStatistics *ptr_ASI_GetPerformanceStatistics;
185static int asi_accelerator_present;
186static int tried_atalla;
187
188void atalla_initialize_accelerator_handle(void)
189 {
190 void *dl_handle;
191 int status;
192 unsigned int config_buf[1024];
193 static int tested;
194
195 if(tested)
196 return;
197
198 tested=1;
199
200 bzero((void *)config_buf, 1024);
201
202 /*
203 * Check to see if the library is present on the system
204 */
205 dl_handle = dlopen("atasi.so", RTLD_NOW);
206 if (dl_handle == (void *) NULL)
207 {
208/* printf("atasi.so library is not present on the system\n");
209 printf("No HW acceleration available\n");*/
210 return;
211 }
212
213 /*
214 * The library is present. Now we'll check to insure that the
215 * LDM is up and running. First we'll get the address of the
216 * function in the atasi library that we need to see if the
217 * LDM is operating.
218 */
219
220 ptr_ASI_GetHardwareConfig =
221 (tfnASI_GetHardwareConfig *)dlsym(dl_handle,"ASI_GetHardwareConfig");
222
223 if (ptr_ASI_GetHardwareConfig)
224 {
225 /*
226 * We found the call, now we'll get our config
227 * status. If we get a non 0 result, the LDM is not
228 * running and we cannot use the Atalla ASI *
229 * library.
230 */
231 status = (*ptr_ASI_GetHardwareConfig)(0L, config_buf);
232 if (status != 0)
233 {
234 printf("atasi.so library is present but not initialized\n");
235 printf("No HW acceleration available\n");
236 return;
237 }
238 }
239 else
240 {
241/* printf("We found the library, but not the function. Very Strange!\n");*/
242 return ;
243 }
244
245 /*
246 * It looks like we have acceleration capabilities. Load up the
247 * pointers to our ASI API calls.
248 */
249 ptr_ASI_RSAPrivateKeyOpFn=
250 (tfnASI_RSAPrivateKeyOpFn *)dlsym(dl_handle, "ASI_RSAPrivateKeyOpFn");
251 if (ptr_ASI_RSAPrivateKeyOpFn == NULL)
252 {
253/* printf("We found the library, but no RSA function. Very Strange!\n");*/
254 return;
255 }
256
257 ptr_ASI_GetPerformanceStatistics =
258 (tfnASI_GetPerformanceStatistics *)dlsym(dl_handle, "ASI_GetPerformanceStatistics");
259 if (ptr_ASI_GetPerformanceStatistics == NULL)
260 {
261/* printf("We found the library, but no stat function. Very Strange!\n");*/
262 return;
263 }
264
265 /*
266 * Indicate that acceleration is available
267 */
268 asi_accelerator_present = 1;
269
270/* printf("This system has acceleration!\n");*/
271
272 return;
273 }
274
275/* make sure this only gets called once when bn_mod_exp calls bn_mod_exp_mont */
276int BN_mod_exp_atalla(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m)
277 {
278 unsigned char *abin;
279 unsigned char *pbin;
280 unsigned char *mbin;
281 unsigned char *rbin;
282 int an,pn,mn,ret;
283 RSAPrivateKey keydata;
284
285 atalla_initialize_accelerator_handle();
286 if(!asi_accelerator_present)
287 return 0;
288
289
290/* We should be able to run without size testing */
291# define ASIZE 128
292 an=BN_num_bytes(a);
293 pn=BN_num_bytes(p);
294 mn=BN_num_bytes(m);
295
296 if(an <= ASIZE && pn <= ASIZE && mn <= ASIZE)
297 {
298 int size=mn;
299
300 assert(an <= mn);
301 abin=alloca(size);
302 memset(abin,'\0',mn);
303 BN_bn2bin(a,abin+size-an);
304
305 pbin=alloca(pn);
306 BN_bn2bin(p,pbin);
307
308 mbin=alloca(size);
309 memset(mbin,'\0',mn);
310 BN_bn2bin(m,mbin+size-mn);
311
312 rbin=alloca(size);
313
314 memset(&keydata,'\0',sizeof keydata);
315 keydata.privateExponent.data=pbin;
316 keydata.privateExponent.len=pn;
317 keydata.modulus.data=mbin;
318 keydata.modulus.len=size;
319
320 ret=(*ptr_ASI_RSAPrivateKeyOpFn)(&keydata,rbin,abin,keydata.modulus.len);
321/*fprintf(stderr,"!%s\n",BN_bn2hex(a));*/
322 if(!ret)
323 {
324 BN_bin2bn(rbin,keydata.modulus.len,r);
325/*fprintf(stderr,"?%s\n",BN_bn2hex(r));*/
326 return 1;
327 }
328 }
329 return 0;
330 }
331#endif /* def ATALLA */
332
333int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
334 BN_CTX *ctx)
335 {
336 int ret;
337
338 bn_check_top(a);
339 bn_check_top(p);
340 bn_check_top(m);
341
342#ifdef ATALLA
343 if(BN_mod_exp_atalla(r,a,p,m))
344 return 1;
345/* If it fails, try the other methods (but don't try atalla again) */
346 tried_atalla=1;
347#endif
348
349#ifdef MONT_MUL_MOD
350 /* I have finally been able to take out this pre-condition of
351 * the top bit being set. It was caused by an error in BN_div
352 * with negatives. There was also another problem when for a^b%m
353 * a >= m. eay 07-May-97 */
354/* if ((m->d[m->top-1]&BN_TBIT) && BN_is_odd(m)) */
355
356 if (BN_is_odd(m))
357 { ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); }
358 else
359#endif
360#ifdef RECP_MUL_MOD
361 { ret=BN_mod_exp_recp(r,a,p,m,ctx); }
362#else
363 { ret=BN_mod_exp_simple(r,a,p,m,ctx); }
364#endif
365
366#ifdef ATALLA
367 tried_atalla=0;
368#endif
369
370 return(ret);
371 }
372
373/* #ifdef RECP_MUL_MOD */
374int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
375 const BIGNUM *m, BN_CTX *ctx)
376 {
377 int i,j,bits,ret=0,wstart,wend,window,wvalue;
378 int start=1,ts=0;
379 BIGNUM *aa;
380 BIGNUM val[TABLE_SIZE];
381 BN_RECP_CTX recp;
382
383 bits=BN_num_bits(p);
384
385 if (bits == 0)
386 {
387 BN_one(r);
388 return(1);
389 }
390
391 BN_CTX_start(ctx);
392 if ((aa = BN_CTX_get(ctx)) == NULL) goto err;
393
394 BN_RECP_CTX_init(&recp);
395 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;
396
397 BN_init(&(val[0]));
398 ts=1;
399
400 if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */
401 if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))
402 goto err; /* 2 */
403
404 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */
405 window=1;
406 else if (bits >= 256)
407 window=5; /* max size of window */
408 else if (bits >= 128)
409 window=4;
410 else
411 window=3;
412
413 j=1<<(window-1);
414 for (i=1; i<j; i++)
415 {
416 BN_init(&val[i]);
417 if (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))
418 goto err;
419 }
420 ts=i;
421
422 start=1; /* This is used to avoid multiplication etc
423 * when there is only the value '1' in the
424 * buffer. */
425 wvalue=0; /* The 'value' of the window */
426 wstart=bits-1; /* The top bit of the window */
427 wend=0; /* The bottom bit of the window */
428
429 if (!BN_one(r)) goto err;
430
431 for (;;)
432 {
433 if (BN_is_bit_set(p,wstart) == 0)
434 {
435 if (!start)
436 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
437 goto err;
438 if (wstart == 0) break;
439 wstart--;
440 continue;
441 }
442 /* We now have wstart on a 'set' bit, we now need to work out
443 * how bit a window to do. To do this we need to scan
444 * forward until the last set bit before the end of the
445 * window */
446 j=wstart;
447 wvalue=1;
448 wend=0;
449 for (i=1; i<window; i++)
450 {
451 if (wstart-i < 0) break;
452 if (BN_is_bit_set(p,wstart-i))
453 {
454 wvalue<<=(i-wend);
455 wvalue|=1;
456 wend=i;
457 }
458 }
459
460 /* wend is the size of the current window */
461 j=wend+1;
462 /* add the 'bytes above' */
463 if (!start)
464 for (i=0; i<j; i++)
465 {
466 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
467 goto err;
468 }
469
470 /* wvalue will be an odd number < 2^window */
471 if (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))
472 goto err;
473
474 /* move the 'window' down further */
475 wstart-=wend+1;
476 wvalue=0;
477 start=0;
478 if (wstart < 0) break;
479 }
480 ret=1;
481err:
482 BN_CTX_end(ctx);
483 for (i=0; i<ts; i++)
484 BN_clear_free(&(val[i]));
485 BN_RECP_CTX_free(&recp);
486 return(ret);
487 }
488/* #endif */
489
490/* #ifdef MONT_MUL_MOD */
491int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, const BIGNUM *p,
492 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
493 {
494 int i,j,bits,ret=0,wstart,wend,window,wvalue;
495 int start=1,ts=0;
496 BIGNUM *d,*r;
497 BIGNUM *aa;
498 BIGNUM val[TABLE_SIZE];
499 BN_MONT_CTX *mont=NULL;
500
501 bn_check_top(a);
502 bn_check_top(p);
503 bn_check_top(m);
504
505#ifdef ATALLA
506 if(!tried_atalla && BN_mod_exp_atalla(rr,a,p,m))
507 return 1;
508/* If it fails, try the other methods */
509#endif
510
511 if (!(m->d[0] & 1))
512 {
513 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
514 return(0);
515 }
516 bits=BN_num_bits(p);
517 if (bits == 0)
518 {
519 BN_one(rr);
520 return(1);
521 }
522 BN_CTX_start(ctx);
523 d = BN_CTX_get(ctx);
524 r = BN_CTX_get(ctx);
525 if (d == NULL || r == NULL) goto err;
526
527 /* If this is not done, things will break in the montgomery
528 * part */
529
530#if 1
531 if (in_mont != NULL)
532 mont=in_mont;
533 else
534#endif
535 {
536 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
537 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
538 }
539
540 BN_init(&val[0]);
541 ts=1;
542 if (BN_ucmp(a,m) >= 0)
543 {
544 BN_mod(&(val[0]),a,m,ctx);
545 aa= &(val[0]);
546 }
547 else
548 aa=a;
549 if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */
550 if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */
551
552 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */
553 window=1;
554 else if (bits >= 256)
555 window=5; /* max size of window */
556 else if (bits >= 128)
557 window=4;
558 else
559 window=3;
560
561 j=1<<(window-1);
562 for (i=1; i<j; i++)
563 {
564 BN_init(&(val[i]));
565 if (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))
566 goto err;
567 }
568 ts=i;
569
570 start=1; /* This is used to avoid multiplication etc
571 * when there is only the value '1' in the
572 * buffer. */
573 wvalue=0; /* The 'value' of the window */
574 wstart=bits-1; /* The top bit of the window */
575 wend=0; /* The bottom bit of the window */
576
577 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
578 for (;;)
579 {
580 if (BN_is_bit_set(p,wstart) == 0)
581 {
582 if (!start)
583 {
584 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
585 goto err;
586 }
587 if (wstart == 0) break;
588 wstart--;
589 continue;
590 }
591 /* We now have wstart on a 'set' bit, we now need to work out
592 * how bit a window to do. To do this we need to scan
593 * forward until the last set bit before the end of the
594 * window */
595 j=wstart;
596 wvalue=1;
597 wend=0;
598 for (i=1; i<window; i++)
599 {
600 if (wstart-i < 0) break;
601 if (BN_is_bit_set(p,wstart-i))
602 {
603 wvalue<<=(i-wend);
604 wvalue|=1;
605 wend=i;
606 }
607 }
608
609 /* wend is the size of the current window */
610 j=wend+1;
611 /* add the 'bytes above' */
612 if (!start)
613 for (i=0; i<j; i++)
614 {
615 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
616 goto err;
617 }
618
619 /* wvalue will be an odd number < 2^window */
620 if (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))
621 goto err;
622
623 /* move the 'window' down further */
624 wstart-=wend+1;
625 wvalue=0;
626 start=0;
627 if (wstart < 0) break;
628 }
629 BN_from_montgomery(rr,r,mont,ctx);
630 ret=1;
631err:
632 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
633 BN_CTX_end(ctx);
634 for (i=0; i<ts; i++)
635 BN_clear_free(&(val[i]));
636 return(ret);
637 }
638/* #endif */
639
640/* The old fallback, simple version :-) */
641int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,
642 BN_CTX *ctx)
643 {
644 int i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;
645 int start=1;
646 BIGNUM *d;
647 BIGNUM val[TABLE_SIZE];
648
649 bits=BN_num_bits(p);
650
651 if (bits == 0)
652 {
653 BN_one(r);
654 return(1);
655 }
656
657 BN_CTX_start(ctx);
658 if ((d = BN_CTX_get(ctx)) == NULL) goto err;
659
660 BN_init(&(val[0]));
661 ts=1;
662 if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */
663 if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))
664 goto err; /* 2 */
665
666 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */
667 window=1;
668 else if (bits >= 256)
669 window=5; /* max size of window */
670 else if (bits >= 128)
671 window=4;
672 else
673 window=3;
674
675 j=1<<(window-1);
676 for (i=1; i<j; i++)
677 {
678 BN_init(&(val[i]));
679 if (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))
680 goto err;
681 }
682 ts=i;
683
684 start=1; /* This is used to avoid multiplication etc
685 * when there is only the value '1' in the
686 * buffer. */
687 wvalue=0; /* The 'value' of the window */
688 wstart=bits-1; /* The top bit of the window */
689 wend=0; /* The bottom bit of the window */
690
691 if (!BN_one(r)) goto err;
692
693 for (;;)
694 {
695 if (BN_is_bit_set(p,wstart) == 0)
696 {
697 if (!start)
698 if (!BN_mod_mul(r,r,r,m,ctx))
699 goto err;
700 if (wstart == 0) break;
701 wstart--;
702 continue;
703 }
704 /* We now have wstart on a 'set' bit, we now need to work out
705 * how bit a window to do. To do this we need to scan
706 * forward until the last set bit before the end of the
707 * window */
708 j=wstart;
709 wvalue=1;
710 wend=0;
711 for (i=1; i<window; i++)
712 {
713 if (wstart-i < 0) break;
714 if (BN_is_bit_set(p,wstart-i))
715 {
716 wvalue<<=(i-wend);
717 wvalue|=1;
718 wend=i;
719 }
720 }
721
722 /* wend is the size of the current window */
723 j=wend+1;
724 /* add the 'bytes above' */
725 if (!start)
726 for (i=0; i<j; i++)
727 {
728 if (!BN_mod_mul(r,r,r,m,ctx))
729 goto err;
730 }
731
732 /* wvalue will be an odd number < 2^window */
733 if (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx))
734 goto err;
735
736 /* move the 'window' down further */
737 wstart-=wend+1;
738 wvalue=0;
739 start=0;
740 if (wstart < 0) break;
741 }
742 ret=1;
743err:
744 BN_CTX_end(ctx);
745 for (i=0; i<ts; i++)
746 BN_clear_free(&(val[i]));
747 return(ret);
748 }
749
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c
deleted file mode 100644
index 4f4e9e3299..0000000000
--- a/src/lib/libcrypto/bn/bn_exp2.c
+++ /dev/null
@@ -1,199 +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 improvement 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 bits1=BN_num_bits(p1);
39 bits2=BN_num_bits(p2);
40 if ((bits1 == 0) && (bits2 == 0))
41 {
42 BN_one(rr);
43 return(1);
44 }
45
46 BN_CTX_start(ctx);
47 d = BN_CTX_get(ctx);
48 r = BN_CTX_get(ctx);
49 if (d == NULL || r == NULL) goto err;
50
51 bits=(bits1 > bits2)?bits1:bits2;
52
53 /* If this is not done, things will break in the montgomery
54 * part */
55
56 if (in_mont != NULL)
57 mont=in_mont;
58 else
59 {
60 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
61 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
62 }
63
64 BN_init(&(val[0][0]));
65 BN_init(&(val[1][1]));
66 BN_init(&(val[0][1]));
67 BN_init(&(val[1][0]));
68 ts=1;
69 if (BN_ucmp(a1,m) >= 0)
70 {
71 BN_mod(&(val[1][0]),a1,m,ctx);
72 aa1= &(val[1][0]);
73 }
74 else
75 aa1=a1;
76 if (BN_ucmp(a2,m) >= 0)
77 {
78 BN_mod(&(val[0][1]),a2,m,ctx);
79 aa2= &(val[0][1]);
80 }
81 else
82 aa2=a2;
83 if (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err;
84 if (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err;
85 if (!BN_mod_mul_montgomery(&(val[1][1]),
86 &(val[1][0]),&(val[0][1]),mont,ctx))
87 goto err;
88
89#if 0
90 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */
91 window=1;
92 else if (bits > 250)
93 window=5; /* max size of window */
94 else if (bits >= 120)
95 window=4;
96 else
97 window=3;
98#else
99 window=EXP2_TABLE_BITS;
100#endif
101
102 k=1<<window;
103 for (x=0; x<k; x++)
104 {
105 if (x >= 2)
106 {
107 BN_init(&(val[x][0]));
108 BN_init(&(val[x][1]));
109 if (!BN_mod_mul_montgomery(&(val[x][0]),
110 &(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err;
111 if (!BN_mod_mul_montgomery(&(val[x][1]),
112 &(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err;
113 }
114 for (y=2; y<k; y++)
115 {
116 BN_init(&(val[x][y]));
117 if (!BN_mod_mul_montgomery(&(val[x][y]),
118 &(val[x][y-1]),&(val[0][1]),mont,ctx))
119 goto err;
120 }
121 }
122 ts=k;
123
124 start=1; /* This is used to avoid multiplication etc
125 * when there is only the value '1' in the
126 * buffer. */
127 xvalue=0; /* The 'x value' of the window */
128 yvalue=0; /* The 'y value' of the window */
129 wstart=bits-1; /* The top bit of the window */
130 wend=0; /* The bottom bit of the window */
131
132 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
133 for (;;)
134 {
135 xvalue=BN_is_bit_set(p1,wstart);
136 yvalue=BN_is_bit_set(p2,wstart);
137 if (!(xvalue || yvalue))
138 {
139 if (!start)
140 {
141 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
142 goto err;
143 }
144 wstart--;
145 if (wstart < 0) break;
146 continue;
147 }
148 /* We now have wstart on a 'set' bit, we now need to work out
149 * how bit a window to do. To do this we need to scan
150 * forward until the last set bit before the end of the
151 * window */
152 j=wstart;
153 /* xvalue=BN_is_bit_set(p1,wstart); already set */
154 /* yvalue=BN_is_bit_set(p1,wstart); already set */
155 wend=0;
156 for (i=1; i<window; i++)
157 {
158 if (wstart-i < 0) break;
159 xvalue+=xvalue;
160 xvalue|=BN_is_bit_set(p1,wstart-i);
161 yvalue+=yvalue;
162 yvalue|=BN_is_bit_set(p2,wstart-i);
163 }
164
165 /* i is the size of the current window */
166 /* add the 'bytes above' */
167 if (!start)
168 for (j=0; j<i; j++)
169 {
170 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
171 goto err;
172 }
173
174 /* wvalue will be an odd number < 2^window */
175 if (xvalue || yvalue)
176 {
177 if (!BN_mod_mul_montgomery(r,r,&(val[xvalue][yvalue]),
178 mont,ctx)) goto err;
179 }
180
181 /* move the 'window' down further */
182 wstart-=i;
183 start=0;
184 if (wstart < 0) break;
185 }
186 BN_from_montgomery(rr,r,mont,ctx);
187 ret=1;
188err:
189 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
190 BN_CTX_end(ctx);
191 for (i=0; i<ts; i++)
192 {
193 for (j=0; j<ts; j++)
194 {
195 BN_clear_free(&(val[i][j]));
196 }
197 }
198 return(ret);
199 }
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c
deleted file mode 100644
index 398207196b..0000000000
--- a/src/lib/libcrypto/bn/bn_gcd.c
+++ /dev/null
@@ -1,210 +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);
64
65int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx)
66 {
67 BIGNUM *a,*b,*t;
68 int ret=0;
69
70 bn_check_top(in_a);
71 bn_check_top(in_b);
72
73 BN_CTX_start(ctx);
74 a = BN_CTX_get(ctx);
75 b = BN_CTX_get(ctx);
76 if (a == NULL || b == NULL) goto err;
77
78 if (BN_copy(a,in_a) == NULL) goto err;
79 if (BN_copy(b,in_b) == NULL) goto err;
80
81 if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; }
82 t=euclid(a,b);
83 if (t == NULL) goto err;
84
85 if (BN_copy(r,t) == NULL) goto err;
86 ret=1;
87err:
88 BN_CTX_end(ctx);
89 return(ret);
90 }
91
92static BIGNUM *euclid(BIGNUM *a, BIGNUM *b)
93 {
94 BIGNUM *t;
95 int shifts=0;
96
97 bn_check_top(a);
98 bn_check_top(b);
99
100 for (;;)
101 {
102 if (BN_is_zero(b))
103 break;
104
105 if (BN_is_odd(a))
106 {
107 if (BN_is_odd(b))
108 {
109 if (!BN_sub(a,a,b)) goto err;
110 if (!BN_rshift1(a,a)) goto err;
111 if (BN_cmp(a,b) < 0)
112 { t=a; a=b; b=t; }
113 }
114 else /* a odd - b even */
115 {
116 if (!BN_rshift1(b,b)) goto err;
117 if (BN_cmp(a,b) < 0)
118 { t=a; a=b; b=t; }
119 }
120 }
121 else /* a is even */
122 {
123 if (BN_is_odd(b))
124 {
125 if (!BN_rshift1(a,a)) goto err;
126 if (BN_cmp(a,b) < 0)
127 { t=a; a=b; b=t; }
128 }
129 else /* a even - b even */
130 {
131 if (!BN_rshift1(a,a)) goto err;
132 if (!BN_rshift1(b,b)) goto err;
133 shifts++;
134 }
135 }
136 }
137 if (shifts)
138 {
139 if (!BN_lshift(a,a,shifts)) goto err;
140 }
141 return(a);
142err:
143 return(NULL);
144 }
145
146/* solves ax == 1 (mod n) */
147BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
148 {
149 BIGNUM *A,*B,*X,*Y,*M,*D,*R=NULL;
150 BIGNUM *T,*ret=NULL;
151 int sign;
152
153 bn_check_top(a);
154 bn_check_top(n);
155
156 BN_CTX_start(ctx);
157 A = BN_CTX_get(ctx);
158 B = BN_CTX_get(ctx);
159 X = BN_CTX_get(ctx);
160 D = BN_CTX_get(ctx);
161 M = BN_CTX_get(ctx);
162 Y = BN_CTX_get(ctx);
163 if (Y == NULL) goto err;
164
165 if (in == NULL)
166 R=BN_new();
167 else
168 R=in;
169 if (R == NULL) goto err;
170
171 BN_zero(X);
172 BN_one(Y);
173 if (BN_copy(A,a) == NULL) goto err;
174 if (BN_copy(B,n) == NULL) goto err;
175 sign=1;
176
177 while (!BN_is_zero(B))
178 {
179 if (!BN_div(D,M,A,B,ctx)) goto err;
180 T=A;
181 A=B;
182 B=M;
183 /* T has a struct, M does not */
184
185 if (!BN_mul(T,D,X,ctx)) goto err;
186 if (!BN_add(T,T,Y)) goto err;
187 M=Y;
188 Y=X;
189 X=T;
190 sign= -sign;
191 }
192 if (sign < 0)
193 {
194 if (!BN_sub(Y,n,Y)) goto err;
195 }
196
197 if (BN_is_one(A))
198 { if (!BN_mod(R,Y,n,ctx)) goto err; }
199 else
200 {
201 BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);
202 goto err;
203 }
204 ret=R;
205err:
206 if ((ret == NULL) && (in == NULL)) BN_free(R);
207 BN_CTX_end(ctx);
208 return(ret);
209 }
210
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h
deleted file mode 100644
index e36ccbc4c2..0000000000
--- a/src/lib/libcrypto/bn/bn_lcl.h
+++ /dev/null
@@ -1,321 +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 !defined(NO_ASM) && !defined(NO_INLINE_ASM) && !defined(PEDANTIC)
77/*
78 * BN_UMULT_HIGH section.
79 *
80 * No, I'm not trying to overwhelm you when stating that the
81 * product of N-bit numbers is 2*N bits wide:-) No, I don't expect
82 * you to be impressed when I say that if the compiler doesn't
83 * support 2*N integer type, then you have to replace every N*N
84 * multiplication with 4 (N/2)*(N/2) accompanied by some shifts
85 * and additions which unavoidably results in severe performance
86 * penalties. Of course provided that the hardware is capable of
87 * producing 2*N result... That's when you normally start
88 * considering assembler implementation. However! It should be
89 * pointed out that some CPUs (most notably Alpha, PowerPC and
90 * upcoming IA-64 family:-) provide *separate* instruction
91 * calculating the upper half of the product placing the result
92 * into a general purpose register. Now *if* the compiler supports
93 * inline assembler, then it's not impossible to implement the
94 * "bignum" routines (and have the compiler optimize 'em)
95 * exhibiting "native" performance in C. That's what BN_UMULT_HIGH
96 * macro is about:-)
97 *
98 * <appro@fy.chalmers.se>
99 */
100# if defined(__alpha) && (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT))
101# if defined(__DECC)
102# include <c_asm.h>
103# define BN_UMULT_HIGH(a,b) (BN_ULONG)asm("umulh %a0,%a1,%v0",(a),(b))
104# elif defined(__GNUC__)
105# define BN_UMULT_HIGH(a,b) ({ \
106 register BN_ULONG ret; \
107 asm ("umulh %1,%2,%0" \
108 : "=r"(ret) \
109 : "r"(a), "r"(b)); \
110 ret; })
111# endif /* compiler */
112# elif defined(_ARCH_PPC) && defined(__64BIT__) && defined(SIXTY_FOUR_BIT_LONG)
113# if defined(__GNUC__)
114# define BN_UMULT_HIGH(a,b) ({ \
115 register BN_ULONG ret; \
116 asm ("mulhdu %0,%1,%2" \
117 : "=r"(ret) \
118 : "r"(a), "r"(b)); \
119 ret; })
120# endif /* compiler */
121# endif /* cpu */
122#endif /* NO_ASM */
123
124/*************************************************************
125 * Using the long long type
126 */
127#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
128#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
129
130/* This is used for internal error checking and is not normally used */
131#ifdef BN_DEBUG
132# include <assert.h>
133# define bn_check_top(a) assert ((a)->top >= 0 && (a)->top <= (a)->max);
134#else
135# define bn_check_top(a)
136#endif
137
138/* This macro is to add extra stuff for development checking */
139#ifdef BN_DEBUG
140#define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA))
141#else
142#define bn_set_max(r)
143#endif
144
145/* These macros are used to 'take' a section of a bignum for read only use */
146#define bn_set_low(r,a,n) \
147 { \
148 (r)->top=((a)->top > (n))?(n):(a)->top; \
149 (r)->d=(a)->d; \
150 (r)->neg=(a)->neg; \
151 (r)->flags|=BN_FLG_STATIC_DATA; \
152 bn_set_max(r); \
153 }
154
155#define bn_set_high(r,a,n) \
156 { \
157 if ((a)->top > (n)) \
158 { \
159 (r)->top=(a)->top-n; \
160 (r)->d= &((a)->d[n]); \
161 } \
162 else \
163 (r)->top=0; \
164 (r)->neg=(a)->neg; \
165 (r)->flags|=BN_FLG_STATIC_DATA; \
166 bn_set_max(r); \
167 }
168
169#ifdef BN_LLONG
170#define mul_add(r,a,w,c) { \
171 BN_ULLONG t; \
172 t=(BN_ULLONG)w * (a) + (r) + (c); \
173 (r)= Lw(t); \
174 (c)= Hw(t); \
175 }
176
177#define mul(r,a,w,c) { \
178 BN_ULLONG t; \
179 t=(BN_ULLONG)w * (a) + (c); \
180 (r)= Lw(t); \
181 (c)= Hw(t); \
182 }
183
184#define sqr(r0,r1,a) { \
185 BN_ULLONG t; \
186 t=(BN_ULLONG)(a)*(a); \
187 (r0)=Lw(t); \
188 (r1)=Hw(t); \
189 }
190
191#elif defined(BN_UMULT_HIGH)
192#define mul_add(r,a,w,c) { \
193 BN_ULONG high,low,ret,tmp=(a); \
194 ret = (r); \
195 high= BN_UMULT_HIGH(w,tmp); \
196 ret += (c); \
197 low = (w) * tmp; \
198 (c) = (ret<(c))?1:0; \
199 (c) += high; \
200 ret += low; \
201 (c) += (ret<low)?1:0; \
202 (r) = ret; \
203 }
204
205#define mul(r,a,w,c) { \
206 BN_ULONG high,low,ret,ta=(a); \
207 low = (w) * ta; \
208 high= BN_UMULT_HIGH(w,ta); \
209 ret = low + (c); \
210 (c) = high; \
211 (c) += (ret<low)?1:0; \
212 (r) = ret; \
213 }
214
215#define sqr(r0,r1,a) { \
216 BN_ULONG tmp=(a); \
217 (r0) = tmp * tmp; \
218 (r1) = BN_UMULT_HIGH(tmp,tmp); \
219 }
220
221#else
222/*************************************************************
223 * No long long type
224 */
225
226#define LBITS(a) ((a)&BN_MASK2l)
227#define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l)
228#define L2HBITS(a) ((BN_ULONG)((a)&BN_MASK2l)<<BN_BITS4)
229
230#define LLBITS(a) ((a)&BN_MASKl)
231#define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl)
232#define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2)
233
234#define mul64(l,h,bl,bh) \
235 { \
236 BN_ULONG m,m1,lt,ht; \
237 \
238 lt=l; \
239 ht=h; \
240 m =(bh)*(lt); \
241 lt=(bl)*(lt); \
242 m1=(bl)*(ht); \
243 ht =(bh)*(ht); \
244 m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS(1L); \
245 ht+=HBITS(m); \
246 m1=L2HBITS(m); \
247 lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \
248 (l)=lt; \
249 (h)=ht; \
250 }
251
252#define sqr64(lo,ho,in) \
253 { \
254 BN_ULONG l,h,m; \
255 \
256 h=(in); \
257 l=LBITS(h); \
258 h=HBITS(h); \
259 m =(l)*(h); \
260 l*=l; \
261 h*=h; \
262 h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \
263 m =(m&BN_MASK2l)<<(BN_BITS4+1); \
264 l=(l+m)&BN_MASK2; if (l < m) h++; \
265 (lo)=l; \
266 (ho)=h; \
267 }
268
269#define mul_add(r,a,bl,bh,c) { \
270 BN_ULONG l,h; \
271 \
272 h= (a); \
273 l=LBITS(h); \
274 h=HBITS(h); \
275 mul64(l,h,(bl),(bh)); \
276 \
277 /* non-multiply part */ \
278 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
279 (c)=(r); \
280 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
281 (c)=h&BN_MASK2; \
282 (r)=l; \
283 }
284
285#define mul(r,a,bl,bh,c) { \
286 BN_ULONG l,h; \
287 \
288 h= (a); \
289 l=LBITS(h); \
290 h=HBITS(h); \
291 mul64(l,h,(bl),(bh)); \
292 \
293 /* non-multiply part */ \
294 l+=(c); if ((l&BN_MASK2) < (c)) h++; \
295 (c)=h&BN_MASK2; \
296 (r)=l&BN_MASK2; \
297 }
298#endif /* !BN_LLONG */
299
300void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb);
301void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
302void bn_mul_comba4(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
303void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp);
304void bn_sqr_comba8(BN_ULONG *r,BN_ULONG *a);
305void bn_sqr_comba4(BN_ULONG *r,BN_ULONG *a);
306int bn_cmp_words(BN_ULONG *a,BN_ULONG *b,int n);
307void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,BN_ULONG *t);
308void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,
309 int tn, int n,BN_ULONG *t);
310void bn_sqr_recursive(BN_ULONG *r,BN_ULONG *a, int n2, BN_ULONG *t);
311void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n);
312void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,
313 BN_ULONG *t);
314void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2,
315 BN_ULONG *t);
316
317#ifdef __cplusplus
318}
319#endif
320
321#endif
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
deleted file mode 100644
index 0e6b12d9c3..0000000000
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ /dev/null
@@ -1,755 +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 */
74static int bn_limit_bits=0;
75static int bn_limit_num=8; /* (1<<bn_limit_bits) */
76static int bn_limit_bits_low=0;
77static int bn_limit_num_low=8; /* (1<<bn_limit_bits_low) */
78static int bn_limit_bits_high=0;
79static int bn_limit_num_high=8; /* (1<<bn_limit_bits_high) */
80static int bn_limit_bits_mont=0;
81static 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/* This is an internal function that should not be used in applications.
308 * It ensures that 'b' has enough room for a 'words' word number number.
309 * It is mostly used by the various BIGNUM routines. If there is an error,
310 * NULL is returned. If not, 'b' is returned. */
311
312BIGNUM *bn_expand2(BIGNUM *b, int words)
313 {
314 BN_ULONG *A,*a;
315 const BN_ULONG *B;
316 int i;
317
318 bn_check_top(b);
319
320 if (words > b->max)
321 {
322 bn_check_top(b);
323 if (BN_get_flags(b,BN_FLG_STATIC_DATA))
324 {
325 BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
326 return(NULL);
327 }
328 a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
329 if (A == NULL)
330 {
331 BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
332 return(NULL);
333 }
334#if 1
335 B=b->d;
336 /* Check if the previous number needs to be copied */
337 if (B != NULL)
338 {
339#if 0
340 /* This lot is an unrolled loop to copy b->top
341 * BN_ULONGs from B to A
342 */
343/*
344 * I have nothing against unrolling but it's usually done for
345 * several reasons, namely:
346 * - minimize percentage of decision making code, i.e. branches;
347 * - avoid cache trashing;
348 * - make it possible to schedule loads earlier;
349 * Now let's examine the code below. The cornerstone of C is
350 * "programmer is always right" and that's what we love it for:-)
351 * For this very reason C compilers have to be paranoid when it
352 * comes to data aliasing and assume the worst. Yeah, but what
353 * does it mean in real life? This means that loop body below will
354 * be compiled to sequence of loads immediately followed by stores
355 * as compiler assumes the worst, something in A==B+1 style. As a
356 * result CPU pipeline is going to starve for incoming data. Secondly
357 * if A and B happen to share same cache line such code is going to
358 * cause severe cache trashing. Both factors have severe impact on
359 * performance of modern CPUs and this is the reason why this
360 * particular piece of code is #ifdefed away and replaced by more
361 * "friendly" version found in #else section below. This comment
362 * also applies to BN_copy function.
363 *
364 * <appro@fy.chalmers.se>
365 */
366 for (i=b->top&(~7); i>0; i-=8)
367 {
368 A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
369 A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
370 A+=8;
371 B+=8;
372 }
373 switch (b->top&7)
374 {
375 case 7:
376 A[6]=B[6];
377 case 6:
378 A[5]=B[5];
379 case 5:
380 A[4]=B[4];
381 case 4:
382 A[3]=B[3];
383 case 3:
384 A[2]=B[2];
385 case 2:
386 A[1]=B[1];
387 case 1:
388 A[0]=B[0];
389 case 0:
390 /* I need the 'case 0' entry for utrix cc.
391 * If the optimizer is turned on, it does the
392 * switch table by doing
393 * a=top&7
394 * a--;
395 * goto jump_table[a];
396 * If top is 0, this makes us jump to 0xffffffc
397 * which is rather bad :-(.
398 * eric 23-Apr-1998
399 */
400 ;
401 }
402#else
403 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
404 {
405 /*
406 * The fact that the loop is unrolled
407 * 4-wise is a tribute to Intel. It's
408 * the one that doesn't have enough
409 * registers to accomodate more data.
410 * I'd unroll it 8-wise otherwise:-)
411 *
412 * <appro@fy.chalmers.se>
413 */
414 BN_ULONG a0,a1,a2,a3;
415 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
416 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
417 }
418 switch (b->top&3)
419 {
420 case 3: A[2]=B[2];
421 case 2: A[1]=B[1];
422 case 1: A[0]=B[0];
423 case 0: ; /* ultrix cc workaround, see above */
424 }
425#endif
426 Free(b->d);
427 }
428
429 b->d=a;
430 b->max=words;
431
432 /* Now need to zero any data between b->top and b->max */
433
434 A= &(b->d[b->top]);
435 for (i=(b->max - b->top)>>3; i>0; i--,A+=8)
436 {
437 A[0]=0; A[1]=0; A[2]=0; A[3]=0;
438 A[4]=0; A[5]=0; A[6]=0; A[7]=0;
439 }
440 for (i=(b->max - b->top)&7; i>0; i--,A++)
441 A[0]=0;
442#else
443 memset(A,0,sizeof(BN_ULONG)*(words+1));
444 memcpy(A,b->d,sizeof(b->d[0])*b->top);
445 b->d=a;
446 b->max=words;
447#endif
448
449/* memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG)); */
450/* { int i; for (i=b->max; i<words+1; i++) p[i]=i;} */
451
452 }
453 return(b);
454 }
455
456BIGNUM *BN_dup(const BIGNUM *a)
457 {
458 BIGNUM *r;
459
460 if (a == NULL) return NULL;
461
462 bn_check_top(a);
463
464 r=BN_new();
465 if (r == NULL) return(NULL);
466 return((BIGNUM *)BN_copy(r,a));
467 }
468
469BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
470 {
471 int i;
472 BN_ULONG *A;
473 const BN_ULONG *B;
474
475 bn_check_top(b);
476
477 if (a == b) return(a);
478 if (bn_wexpand(a,b->top) == NULL) return(NULL);
479
480#if 1
481 A=a->d;
482 B=b->d;
483 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
484 {
485 BN_ULONG a0,a1,a2,a3;
486 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
487 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
488 }
489 switch (b->top&3)
490 {
491 case 3: A[2]=B[2];
492 case 2: A[1]=B[1];
493 case 1: A[0]=B[0];
494 case 0: ; /* ultrix cc workaround, see comments in bn_expand2 */
495 }
496#else
497 memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
498#endif
499
500/* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/
501 a->top=b->top;
502 if ((a->top == 0) && (a->d != NULL))
503 a->d[0]=0;
504 a->neg=b->neg;
505 return(a);
506 }
507
508void BN_clear(BIGNUM *a)
509 {
510 if (a->d != NULL)
511 memset(a->d,0,a->max*sizeof(a->d[0]));
512 a->top=0;
513 a->neg=0;
514 }
515
516BN_ULONG BN_get_word(BIGNUM *a)
517 {
518 int i,n;
519 BN_ULONG ret=0;
520
521 n=BN_num_bytes(a);
522 if (n > sizeof(BN_ULONG))
523 return(BN_MASK2);
524 for (i=a->top-1; i>=0; i--)
525 {
526#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
527 ret<<=BN_BITS4; /* stops the compiler complaining */
528 ret<<=BN_BITS4;
529#else
530 ret=0;
531#endif
532 ret|=a->d[i];
533 }
534 return(ret);
535 }
536
537int BN_set_word(BIGNUM *a, BN_ULONG w)
538 {
539 int i,n;
540 if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);
541
542 n=sizeof(BN_ULONG)/BN_BYTES;
543 a->neg=0;
544 a->top=0;
545 a->d[0]=(BN_ULONG)w&BN_MASK2;
546 if (a->d[0] != 0) a->top=1;
547 for (i=1; i<n; i++)
548 {
549 /* the following is done instead of
550 * w>>=BN_BITS2 so compilers don't complain
551 * on builds where sizeof(long) == BN_TYPES */
552#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
553 w>>=BN_BITS4;
554 w>>=BN_BITS4;
555#else
556 w=0;
557#endif
558 a->d[i]=(BN_ULONG)w&BN_MASK2;
559 if (a->d[i] != 0) a->top=i+1;
560 }
561 return(1);
562 }
563
564/* ignore negative */
565BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
566 {
567 unsigned int i,m;
568 unsigned int n;
569 BN_ULONG l;
570
571 if (ret == NULL) ret=BN_new();
572 if (ret == NULL) return(NULL);
573 l=0;
574 n=len;
575 if (n == 0)
576 {
577 ret->top=0;
578 return(ret);
579 }
580 if (bn_expand(ret,(int)(n+2)*8) == NULL)
581 return(NULL);
582 i=((n-1)/BN_BYTES)+1;
583 m=((n-1)%(BN_BYTES));
584 ret->top=i;
585 while (n-- > 0)
586 {
587 l=(l<<8L)| *(s++);
588 if (m-- == 0)
589 {
590 ret->d[--i]=l;
591 l=0;
592 m=BN_BYTES-1;
593 }
594 }
595 /* need to call this due to clear byte at top if avoiding
596 * having the top bit set (-ve number) */
597 bn_fix_top(ret);
598 return(ret);
599 }
600
601/* ignore negative */
602int BN_bn2bin(const BIGNUM *a, unsigned char *to)
603 {
604 int n,i;
605 BN_ULONG l;
606
607 n=i=BN_num_bytes(a);
608 while (i-- > 0)
609 {
610 l=a->d[i/BN_BYTES];
611 *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
612 }
613 return(n);
614 }
615
616int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
617 {
618 int i;
619 BN_ULONG t1,t2,*ap,*bp;
620
621 bn_check_top(a);
622 bn_check_top(b);
623
624 i=a->top-b->top;
625 if (i != 0) return(i);
626 ap=a->d;
627 bp=b->d;
628 for (i=a->top-1; i>=0; i--)
629 {
630 t1= ap[i];
631 t2= bp[i];
632 if (t1 != t2)
633 return(t1 > t2?1:-1);
634 }
635 return(0);
636 }
637
638int BN_cmp(const BIGNUM *a, const BIGNUM *b)
639 {
640 int i;
641 int gt,lt;
642 BN_ULONG t1,t2;
643
644 if ((a == NULL) || (b == NULL))
645 {
646 if (a != NULL)
647 return(-1);
648 else if (b != NULL)
649 return(1);
650 else
651 return(0);
652 }
653
654 bn_check_top(a);
655 bn_check_top(b);
656
657 if (a->neg != b->neg)
658 {
659 if (a->neg)
660 return(-1);
661 else return(1);
662 }
663 if (a->neg == 0)
664 { gt=1; lt= -1; }
665 else { gt= -1; lt=1; }
666
667 if (a->top > b->top) return(gt);
668 if (a->top < b->top) return(lt);
669 for (i=a->top-1; i>=0; i--)
670 {
671 t1=a->d[i];
672 t2=b->d[i];
673 if (t1 > t2) return(gt);
674 if (t1 < t2) return(lt);
675 }
676 return(0);
677 }
678
679int BN_set_bit(BIGNUM *a, int n)
680 {
681 int i,j,k;
682
683 i=n/BN_BITS2;
684 j=n%BN_BITS2;
685 if (a->top <= i)
686 {
687 if (bn_wexpand(a,i+1) == NULL) return(0);
688 for(k=a->top; k<i+1; k++)
689 a->d[k]=0;
690 a->top=i+1;
691 }
692
693 a->d[i]|=(((BN_ULONG)1)<<j);
694 return(1);
695 }
696
697int BN_clear_bit(BIGNUM *a, int n)
698 {
699 int i,j;
700
701 i=n/BN_BITS2;
702 j=n%BN_BITS2;
703 if (a->top <= i) return(0);
704
705 a->d[i]&=(~(((BN_ULONG)1)<<j));
706 bn_fix_top(a);
707 return(1);
708 }
709
710int BN_is_bit_set(const BIGNUM *a, int n)
711 {
712 int i,j;
713
714 if (n < 0) return(0);
715 i=n/BN_BITS2;
716 j=n%BN_BITS2;
717 if (a->top <= i) return(0);
718 return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
719 }
720
721int BN_mask_bits(BIGNUM *a, int n)
722 {
723 int b,w;
724
725 w=n/BN_BITS2;
726 b=n%BN_BITS2;
727 if (w >= a->top) return(0);
728 if (b == 0)
729 a->top=w;
730 else
731 {
732 a->top=w+1;
733 a->d[w]&= ~(BN_MASK2<<b);
734 }
735 bn_fix_top(a);
736 return(1);
737 }
738
739int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n)
740 {
741 int i;
742 BN_ULONG aa,bb;
743
744 aa=a[n-1];
745 bb=b[n-1];
746 if (aa != bb) return((aa > bb)?1:-1);
747 for (i=n-2; i>=0; i--)
748 {
749 aa=a[i];
750 bb=b[i];
751 if (aa != bb) return((aa > bb)?1:-1);
752 }
753 return(0);
754 }
755
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
deleted file mode 100644
index 598fecbf0c..0000000000
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ /dev/null
@@ -1,339 +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://security.ece.orst.edu/publications.html, e.g.
62 * http://security.ece.orst.edu/koc/papers/j37acmon.pdf and
63 * sections 3.8 and 4.2 in http://security.ece.orst.edu/koc/papers/r01rsasw.pdf
64 */
65
66#include <stdio.h>
67#include "cryptlib.h"
68#include "bn_lcl.h"
69
70#define MONT_WORD /* use the faster word-based algorithm */
71
72int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
73 BN_MONT_CTX *mont, BN_CTX *ctx)
74 {
75 BIGNUM *tmp,*tmp2;
76 int ret=0;
77
78 BN_CTX_start(ctx);
79 tmp = BN_CTX_get(ctx);
80 tmp2 = BN_CTX_get(ctx);
81 if (tmp == NULL || tmp2 == NULL) goto err;
82
83 bn_check_top(tmp);
84 bn_check_top(tmp2);
85
86 if (a == b)
87 {
88#if 0
89 bn_wexpand(tmp,a->top*2);
90 bn_wexpand(tmp2,a->top*4);
91 bn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);
92 tmp->top=a->top*2;
93 if (tmp->d[tmp->top-1] == 0)
94 tmp->top--;
95#else
96 if (!BN_sqr(tmp,a,ctx)) goto err;
97#endif
98 }
99 else
100 {
101 if (!BN_mul(tmp,a,b,ctx)) goto err;
102 }
103 /* reduce from aRR to aR */
104 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
105 ret=1;
106err:
107 BN_CTX_end(ctx);
108 return(ret);
109 }
110
111int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
112 BN_CTX *ctx)
113 {
114 int retn=0;
115
116#ifdef MONT_WORD
117 BIGNUM *n,*r;
118 BN_ULONG *ap,*np,*rp,n0,v,*nrp;
119 int al,nl,max,i,x,ri;
120
121 BN_CTX_start(ctx);
122 if ((r = BN_CTX_get(ctx)) == NULL) goto err;
123
124 if (!BN_copy(r,a)) goto err;
125 n= &(mont->N);
126
127 ap=a->d;
128 /* mont->ri is the size of mont->N in bits (rounded up
129 to the word size) */
130 al=ri=mont->ri/BN_BITS2;
131
132 nl=n->top;
133 if ((al == 0) || (nl == 0)) { r->top=0; return(1); }
134
135 max=(nl+al+1); /* allow for overflow (no?) XXX */
136 if (bn_wexpand(r,max) == NULL) goto err;
137 if (bn_wexpand(ret,max) == NULL) goto err;
138
139 r->neg=a->neg^n->neg;
140 np=n->d;
141 rp=r->d;
142 nrp= &(r->d[nl]);
143
144 /* clear the top words of T */
145#if 1
146 for (i=r->top; i<max; i++) /* memset? XXX */
147 r->d[i]=0;
148#else
149 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
150#endif
151
152 r->top=max;
153 n0=mont->n0;
154
155#ifdef BN_COUNT
156 printf("word BN_from_montgomery %d * %d\n",nl,nl);
157#endif
158 for (i=0; i<nl; i++)
159 {
160 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
161 nrp++;
162 rp++;
163 if (((nrp[-1]+=v)&BN_MASK2) >= v)
164 continue;
165 else
166 {
167 if (((++nrp[0])&BN_MASK2) != 0) continue;
168 if (((++nrp[1])&BN_MASK2) != 0) continue;
169 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
170 }
171 }
172 bn_fix_top(r);
173
174 /* mont->ri will be a multiple of the word size */
175#if 0
176 BN_rshift(ret,r,mont->ri);
177#else
178 x=ri;
179 rp=ret->d;
180 ap= &(r->d[x]);
181 if (r->top < x)
182 al=0;
183 else
184 al=r->top-x;
185 ret->top=al;
186 al-=4;
187 for (i=0; i<al; i+=4)
188 {
189 BN_ULONG t1,t2,t3,t4;
190
191 t1=ap[i+0];
192 t2=ap[i+1];
193 t3=ap[i+2];
194 t4=ap[i+3];
195 rp[i+0]=t1;
196 rp[i+1]=t2;
197 rp[i+2]=t3;
198 rp[i+3]=t4;
199 }
200 al+=4;
201 for (; i<al; i++)
202 rp[i]=ap[i];
203#endif
204#else /* !MONT_WORD */
205 BIGNUM *t1,*t2;
206
207 BN_CTX_start(ctx);
208 t1 = BN_CTX_get(ctx);
209 t2 = BN_CTX_get(ctx);
210 if (t1 == NULL || t2 == NULL) goto err;
211
212 if (!BN_copy(t1,a)) goto err;
213 BN_mask_bits(t1,mont->ri);
214
215 if (!BN_mul(t2,t1,&mont->Ni,ctx)) goto err;
216 BN_mask_bits(t2,mont->ri);
217
218 if (!BN_mul(t1,t2,&mont->N,ctx)) goto err;
219 if (!BN_add(t2,a,t1)) goto err;
220 BN_rshift(ret,t2,mont->ri);
221#endif /* MONT_WORD */
222
223 if (BN_ucmp(ret, &(mont->N)) >= 0)
224 {
225 BN_usub(ret,ret,&(mont->N));
226 }
227 retn=1;
228 err:
229 BN_CTX_end(ctx);
230 return(retn);
231 }
232
233BN_MONT_CTX *BN_MONT_CTX_new(void)
234 {
235 BN_MONT_CTX *ret;
236
237 if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
238 return(NULL);
239
240 BN_MONT_CTX_init(ret);
241 ret->flags=BN_FLG_MALLOCED;
242 return(ret);
243 }
244
245void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
246 {
247 ctx->ri=0;
248 BN_init(&(ctx->RR));
249 BN_init(&(ctx->N));
250 BN_init(&(ctx->Ni));
251 ctx->flags=0;
252 }
253
254void BN_MONT_CTX_free(BN_MONT_CTX *mont)
255 {
256 if(mont == NULL)
257 return;
258
259 BN_free(&(mont->RR));
260 BN_free(&(mont->N));
261 BN_free(&(mont->Ni));
262 if (mont->flags & BN_FLG_MALLOCED)
263 Free(mont);
264 }
265
266int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
267 {
268 BIGNUM Ri,*R;
269
270 BN_init(&Ri);
271 R= &(mont->RR); /* grab RR as a temp */
272 BN_copy(&(mont->N),mod); /* Set N */
273
274#ifdef MONT_WORD
275 {
276 BIGNUM tmod;
277 BN_ULONG buf[2];
278
279 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
280 BN_zero(R);
281 BN_set_bit(R,BN_BITS2); /* R */
282
283 buf[0]=mod->d[0]; /* tmod = N mod word size */
284 buf[1]=0;
285 tmod.d=buf;
286 tmod.top=1;
287 tmod.max=2;
288 tmod.neg=mod->neg;
289 /* Ri = R^-1 mod N*/
290 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)
291 goto err;
292 BN_lshift(&Ri,&Ri,BN_BITS2); /* R*Ri */
293 if (!BN_is_zero(&Ri))
294 BN_sub_word(&Ri,1);
295 else /* if N mod word size == 1 */
296 BN_set_word(&Ri,BN_MASK2); /* Ri-- (mod word size) */
297 BN_div(&Ri,NULL,&Ri,&tmod,ctx); /* Ni = (R*Ri-1)/N,
298 * keep only least significant word: */
299 mont->n0=Ri.d[0];
300 BN_free(&Ri);
301 }
302#else /* !MONT_WORD */
303 { /* bignum version */
304 mont->ri=BN_num_bits(mod);
305 BN_zero(R);
306 BN_set_bit(R,mont->ri); /* R = 2^ri */
307 /* Ri = R^-1 mod N*/
308 if ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)
309 goto err;
310 BN_lshift(&Ri,&Ri,mont->ri); /* R*Ri */
311 BN_sub_word(&Ri,1);
312 /* Ni = (R*Ri-1) / N */
313 BN_div(&(mont->Ni),NULL,&Ri,mod,ctx);
314 BN_free(&Ri);
315 }
316#endif
317
318 /* setup RR for conversions */
319 BN_zero(&(mont->RR));
320 BN_set_bit(&(mont->RR),mont->ri*2);
321 BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);
322
323 return(1);
324err:
325 return(0);
326 }
327
328BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
329 {
330 if (to == from) return(to);
331
332 BN_copy(&(to->RR),&(from->RR));
333 BN_copy(&(to->N),&(from->N));
334 BN_copy(&(to->Ni),&(from->Ni));
335 to->ri=from->ri;
336 to->n0=from->n0;
337 return(to);
338 }
339
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 3e8baaad9a..0000000000
--- a/src/lib/libcrypto/bn/bn_mul.c
+++ /dev/null
@@ -1,794 +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/* Karatsuba recursive multiplication algorithm
65 * (cf. Knuth, The Art of Computer Programming, Vol. 2) */
66
67/* r is 2*n2 words in size,
68 * a and b are both n2 words in size.
69 * n2 must be a power of 2.
70 * We multiply and return the result.
71 * t must be 2*n2 words in size
72 * We calculate
73 * a[0]*b[0]
74 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
75 * a[1]*b[1]
76 */
77void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
78 BN_ULONG *t)
79 {
80 int n=n2/2,c1,c2;
81 unsigned int neg,zero;
82 BN_ULONG ln,lo,*p;
83
84# ifdef BN_COUNT
85 printf(" bn_mul_recursive %d * %d\n",n2,n2);
86# endif
87# ifdef BN_MUL_COMBA
88# if 0
89 if (n2 == 4)
90 {
91 bn_mul_comba4(r,a,b);
92 return;
93 }
94# endif
95 if (n2 == 8)
96 {
97 bn_mul_comba8(r,a,b);
98 return;
99 }
100# endif /* BN_MUL_COMBA */
101 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)
102 {
103 /* This should not happen */
104 bn_mul_normal(r,a,n2,b,n2);
105 return;
106 }
107 /* r=(a[0]-a[1])*(b[1]-b[0]) */
108 c1=bn_cmp_words(a,&(a[n]),n);
109 c2=bn_cmp_words(&(b[n]),b,n);
110 zero=neg=0;
111 switch (c1*3+c2)
112 {
113 case -4:
114 bn_sub_words(t, &(a[n]),a, n); /* - */
115 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
116 break;
117 case -3:
118 zero=1;
119 break;
120 case -2:
121 bn_sub_words(t, &(a[n]),a, n); /* - */
122 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
123 neg=1;
124 break;
125 case -1:
126 case 0:
127 case 1:
128 zero=1;
129 break;
130 case 2:
131 bn_sub_words(t, a, &(a[n]),n); /* + */
132 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
133 neg=1;
134 break;
135 case 3:
136 zero=1;
137 break;
138 case 4:
139 bn_sub_words(t, a, &(a[n]),n);
140 bn_sub_words(&(t[n]),&(b[n]),b, n);
141 break;
142 }
143
144# ifdef BN_MUL_COMBA
145 if (n == 4)
146 {
147 if (!zero)
148 bn_mul_comba4(&(t[n2]),t,&(t[n]));
149 else
150 memset(&(t[n2]),0,8*sizeof(BN_ULONG));
151
152 bn_mul_comba4(r,a,b);
153 bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));
154 }
155 else if (n == 8)
156 {
157 if (!zero)
158 bn_mul_comba8(&(t[n2]),t,&(t[n]));
159 else
160 memset(&(t[n2]),0,16*sizeof(BN_ULONG));
161
162 bn_mul_comba8(r,a,b);
163 bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));
164 }
165 else
166# endif /* BN_MUL_COMBA */
167 {
168 p= &(t[n2*2]);
169 if (!zero)
170 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
171 else
172 memset(&(t[n2]),0,n2*sizeof(BN_ULONG));
173 bn_mul_recursive(r,a,b,n,p);
174 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);
175 }
176
177 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
178 * r[10] holds (a[0]*b[0])
179 * r[32] holds (b[1]*b[1])
180 */
181
182 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
183
184 if (neg) /* if t[32] is negative */
185 {
186 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
187 }
188 else
189 {
190 /* Might have a carry */
191 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));
192 }
193
194 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
195 * r[10] holds (a[0]*b[0])
196 * r[32] holds (b[1]*b[1])
197 * c1 holds the carry bits
198 */
199 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
200 if (c1)
201 {
202 p= &(r[n+n2]);
203 lo= *p;
204 ln=(lo+c1)&BN_MASK2;
205 *p=ln;
206
207 /* The overflow will stop before we over write
208 * words we should not overwrite */
209 if (ln < (BN_ULONG)c1)
210 {
211 do {
212 p++;
213 lo= *p;
214 ln=(lo+1)&BN_MASK2;
215 *p=ln;
216 } while (ln == 0);
217 }
218 }
219 }
220
221/* n+tn is the word length
222 * t needs to be n*4 is size, as does r */
223void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
224 int n, BN_ULONG *t)
225 {
226 int i,j,n2=n*2;
227 unsigned int c1,c2,neg,zero;
228 BN_ULONG ln,lo,*p;
229
230# ifdef BN_COUNT
231 printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
232# endif
233 if (n < 8)
234 {
235 i=tn+n;
236 bn_mul_normal(r,a,i,b,i);
237 return;
238 }
239
240 /* r=(a[0]-a[1])*(b[1]-b[0]) */
241 c1=bn_cmp_words(a,&(a[n]),n);
242 c2=bn_cmp_words(&(b[n]),b,n);
243 zero=neg=0;
244 switch (c1*3+c2)
245 {
246 case -4:
247 bn_sub_words(t, &(a[n]),a, n); /* - */
248 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
249 break;
250 case -3:
251 zero=1;
252 /* break; */
253 case -2:
254 bn_sub_words(t, &(a[n]),a, n); /* - */
255 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
256 neg=1;
257 break;
258 case -1:
259 case 0:
260 case 1:
261 zero=1;
262 /* break; */
263 case 2:
264 bn_sub_words(t, a, &(a[n]),n); /* + */
265 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
266 neg=1;
267 break;
268 case 3:
269 zero=1;
270 /* break; */
271 case 4:
272 bn_sub_words(t, a, &(a[n]),n);
273 bn_sub_words(&(t[n]),&(b[n]),b, n);
274 break;
275 }
276 /* The zero case isn't yet implemented here. The speedup
277 would probably be negligible. */
278# if 0
279 if (n == 4)
280 {
281 bn_mul_comba4(&(t[n2]),t,&(t[n]));
282 bn_mul_comba4(r,a,b);
283 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
284 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
285 }
286 else
287# endif
288 if (n == 8)
289 {
290 bn_mul_comba8(&(t[n2]),t,&(t[n]));
291 bn_mul_comba8(r,a,b);
292 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
293 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
294 }
295 else
296 {
297 p= &(t[n2*2]);
298 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
299 bn_mul_recursive(r,a,b,n,p);
300 i=n/2;
301 /* If there is only a bottom half to the number,
302 * just do it */
303 j=tn-i;
304 if (j == 0)
305 {
306 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);
307 memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));
308 }
309 else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */
310 {
311 bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),
312 j,i,p);
313 memset(&(r[n2+tn*2]),0,
314 sizeof(BN_ULONG)*(n2-tn*2));
315 }
316 else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */
317 {
318 memset(&(r[n2]),0,sizeof(BN_ULONG)*n2);
319 if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)
320 {
321 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
322 }
323 else
324 {
325 for (;;)
326 {
327 i/=2;
328 if (i < tn)
329 {
330 bn_mul_part_recursive(&(r[n2]),
331 &(a[n]),&(b[n]),
332 tn-i,i,p);
333 break;
334 }
335 else if (i == tn)
336 {
337 bn_mul_recursive(&(r[n2]),
338 &(a[n]),&(b[n]),
339 i,p);
340 break;
341 }
342 }
343 }
344 }
345 }
346
347 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
348 * r[10] holds (a[0]*b[0])
349 * r[32] holds (b[1]*b[1])
350 */
351
352 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
353
354 if (neg) /* if t[32] is negative */
355 {
356 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
357 }
358 else
359 {
360 /* Might have a carry */
361 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));
362 }
363
364 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
365 * r[10] holds (a[0]*b[0])
366 * r[32] holds (b[1]*b[1])
367 * c1 holds the carry bits
368 */
369 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
370 if (c1)
371 {
372 p= &(r[n+n2]);
373 lo= *p;
374 ln=(lo+c1)&BN_MASK2;
375 *p=ln;
376
377 /* The overflow will stop before we over write
378 * words we should not overwrite */
379 if (ln < c1)
380 {
381 do {
382 p++;
383 lo= *p;
384 ln=(lo+1)&BN_MASK2;
385 *p=ln;
386 } while (ln == 0);
387 }
388 }
389 }
390
391/* a and b must be the same size, which is n2.
392 * r needs to be n2 words and t needs to be n2*2
393 */
394void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
395 BN_ULONG *t)
396 {
397 int n=n2/2;
398
399# ifdef BN_COUNT
400 printf(" bn_mul_low_recursive %d * %d\n",n2,n2);
401# endif
402
403 bn_mul_recursive(r,a,b,n,&(t[0]));
404 if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL)
405 {
406 bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2]));
407 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
408 bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2]));
409 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
410 }
411 else
412 {
413 bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n);
414 bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n);
415 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
416 bn_add_words(&(r[n]),&(r[n]),&(t[n]),n);
417 }
418 }
419
420/* a and b must be the same size, which is n2.
421 * r needs to be n2 words and t needs to be n2*2
422 * l is the low words of the output.
423 * t needs to be n2*3
424 */
425void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
426 BN_ULONG *t)
427 {
428 int i,n;
429 int c1,c2;
430 int neg,oneg,zero;
431 BN_ULONG ll,lc,*lp,*mp;
432
433# ifdef BN_COUNT
434 printf(" bn_mul_high %d * %d\n",n2,n2);
435# endif
436 n=n2/2;
437
438 /* Calculate (al-ah)*(bh-bl) */
439 neg=zero=0;
440 c1=bn_cmp_words(&(a[0]),&(a[n]),n);
441 c2=bn_cmp_words(&(b[n]),&(b[0]),n);
442 switch (c1*3+c2)
443 {
444 case -4:
445 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
446 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
447 break;
448 case -3:
449 zero=1;
450 break;
451 case -2:
452 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
453 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
454 neg=1;
455 break;
456 case -1:
457 case 0:
458 case 1:
459 zero=1;
460 break;
461 case 2:
462 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
463 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
464 neg=1;
465 break;
466 case 3:
467 zero=1;
468 break;
469 case 4:
470 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
471 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
472 break;
473 }
474
475 oneg=neg;
476 /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */
477 /* r[10] = (a[1]*b[1]) */
478# ifdef BN_MUL_COMBA
479 if (n == 8)
480 {
481 bn_mul_comba8(&(t[0]),&(r[0]),&(r[n]));
482 bn_mul_comba8(r,&(a[n]),&(b[n]));
483 }
484 else
485# endif
486 {
487 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2]));
488 bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2]));
489 }
490
491 /* s0 == low(al*bl)
492 * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl)
493 * We know s0 and s1 so the only unknown is high(al*bl)
494 * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl))
495 * high(al*bl) == s1 - (r[0]+l[0]+t[0])
496 */
497 if (l != NULL)
498 {
499 lp= &(t[n2+n]);
500 c1=(int)(bn_add_words(lp,&(r[0]),&(l[0]),n));
501 }
502 else
503 {
504 c1=0;
505 lp= &(r[0]);
506 }
507
508 if (neg)
509 neg=(int)(bn_sub_words(&(t[n2]),lp,&(t[0]),n));
510 else
511 {
512 bn_add_words(&(t[n2]),lp,&(t[0]),n);
513 neg=0;
514 }
515
516 if (l != NULL)
517 {
518 bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n);
519 }
520 else
521 {
522 lp= &(t[n2+n]);
523 mp= &(t[n2]);
524 for (i=0; i<n; i++)
525 lp[i]=((~mp[i])+1)&BN_MASK2;
526 }
527
528 /* s[0] = low(al*bl)
529 * t[3] = high(al*bl)
530 * t[10] = (a[0]-a[1])*(b[1]-b[0]) neg is the sign
531 * r[10] = (a[1]*b[1])
532 */
533 /* R[10] = al*bl
534 * R[21] = al*bl + ah*bh + (a[0]-a[1])*(b[1]-b[0])
535 * R[32] = ah*bh
536 */
537 /* R[1]=t[3]+l[0]+r[0](+-)t[0] (have carry/borrow)
538 * R[2]=r[0]+t[3]+r[1](+-)t[1] (have carry/borrow)
539 * R[3]=r[1]+(carry/borrow)
540 */
541 if (l != NULL)
542 {
543 lp= &(t[n2]);
544 c1= (int)(bn_add_words(lp,&(t[n2+n]),&(l[0]),n));
545 }
546 else
547 {
548 lp= &(t[n2+n]);
549 c1=0;
550 }
551 c1+=(int)(bn_add_words(&(t[n2]),lp, &(r[0]),n));
552 if (oneg)
553 c1-=(int)(bn_sub_words(&(t[n2]),&(t[n2]),&(t[0]),n));
554 else
555 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),&(t[0]),n));
556
557 c2 =(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n2+n]),n));
558 c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(r[n]),n));
559 if (oneg)
560 c2-=(int)(bn_sub_words(&(r[0]),&(r[0]),&(t[n]),n));
561 else
562 c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n]),n));
563
564 if (c1 != 0) /* Add starting at r[0], could be +ve or -ve */
565 {
566 i=0;
567 if (c1 > 0)
568 {
569 lc=c1;
570 do {
571 ll=(r[i]+lc)&BN_MASK2;
572 r[i++]=ll;
573 lc=(lc > ll);
574 } while (lc);
575 }
576 else
577 {
578 lc= -c1;
579 do {
580 ll=r[i];
581 r[i++]=(ll-lc)&BN_MASK2;
582 lc=(lc > ll);
583 } while (lc);
584 }
585 }
586 if (c2 != 0) /* Add starting at r[1] */
587 {
588 i=n;
589 if (c2 > 0)
590 {
591 lc=c2;
592 do {
593 ll=(r[i]+lc)&BN_MASK2;
594 r[i++]=ll;
595 lc=(lc > ll);
596 } while (lc);
597 }
598 else
599 {
600 lc= -c2;
601 do {
602 ll=r[i];
603 r[i++]=(ll-lc)&BN_MASK2;
604 lc=(lc > ll);
605 } while (lc);
606 }
607 }
608 }
609#endif /* BN_RECURSION */
610
611int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
612 {
613 int top,al,bl;
614 BIGNUM *rr;
615 int ret = 0;
616#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
617 int i;
618#endif
619#ifdef BN_RECURSION
620 BIGNUM *t;
621 int j,k;
622#endif
623
624#ifdef BN_COUNT
625 printf("BN_mul %d * %d\n",a->top,b->top);
626#endif
627
628 bn_check_top(a);
629 bn_check_top(b);
630 bn_check_top(r);
631
632 al=a->top;
633 bl=b->top;
634 r->neg=a->neg^b->neg;
635
636 if ((al == 0) || (bl == 0))
637 {
638 BN_zero(r);
639 return(1);
640 }
641 top=al+bl;
642
643 BN_CTX_start(ctx);
644 if ((r == a) || (r == b))
645 {
646 if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
647 }
648 else
649 rr = r;
650
651#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
652 i = al-bl;
653#endif
654#ifdef BN_MUL_COMBA
655 if (i == 0)
656 {
657# if 0
658 if (al == 4)
659 {
660 if (bn_wexpand(rr,8) == NULL) goto err;
661 rr->top=8;
662 bn_mul_comba4(rr->d,a->d,b->d);
663 goto end;
664 }
665# endif
666 if (al == 8)
667 {
668 if (bn_wexpand(rr,16) == NULL) goto err;
669 rr->top=16;
670 bn_mul_comba8(rr->d,a->d,b->d);
671 goto end;
672 }
673 }
674#endif /* BN_MUL_COMBA */
675#ifdef BN_RECURSION
676 if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))
677 {
678 if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))
679 {
680 bn_wexpand(b,al);
681 b->d[bl]=0;
682 bl++;
683 i--;
684 }
685 else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))
686 {
687 bn_wexpand(a,bl);
688 a->d[al]=0;
689 al++;
690 i++;
691 }
692 if (i == 0)
693 {
694 /* symmetric and > 4 */
695 /* 16 or larger */
696 j=BN_num_bits_word((BN_ULONG)al);
697 j=1<<(j-1);
698 k=j+j;
699 t = BN_CTX_get(ctx);
700 if (al == j) /* exact multiple */
701 {
702 bn_wexpand(t,k*2);
703 bn_wexpand(rr,k*2);
704 bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
705 }
706 else
707 {
708 bn_wexpand(a,k);
709 bn_wexpand(b,k);
710 bn_wexpand(t,k*4);
711 bn_wexpand(rr,k*4);
712 for (i=a->top; i<k; i++)
713 a->d[i]=0;
714 for (i=b->top; i<k; i++)
715 b->d[i]=0;
716 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
717 }
718 rr->top=top;
719 goto end;
720 }
721 }
722#endif /* BN_RECURSION */
723 if (bn_wexpand(rr,top) == NULL) goto err;
724 rr->top=top;
725 bn_mul_normal(rr->d,a->d,al,b->d,bl);
726
727#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
728end:
729#endif
730 bn_fix_top(rr);
731 if (r != rr) BN_copy(r,rr);
732 ret=1;
733err:
734 BN_CTX_end(ctx);
735 return(ret);
736 }
737
738void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
739 {
740 BN_ULONG *rr;
741
742#ifdef BN_COUNT
743 printf(" bn_mul_normal %d * %d\n",na,nb);
744#endif
745
746 if (na < nb)
747 {
748 int itmp;
749 BN_ULONG *ltmp;
750
751 itmp=na; na=nb; nb=itmp;
752 ltmp=a; a=b; b=ltmp;
753
754 }
755 rr= &(r[na]);
756 rr[0]=bn_mul_words(r,a,na,b[0]);
757
758 for (;;)
759 {
760 if (--nb <= 0) return;
761 rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
762 if (--nb <= 0) return;
763 rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
764 if (--nb <= 0) return;
765 rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
766 if (--nb <= 0) return;
767 rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
768 rr+=4;
769 r+=4;
770 b+=4;
771 }
772 }
773
774void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
775 {
776#ifdef BN_COUNT
777 printf(" bn_mul_low_normal %d * %d\n",n,n);
778#endif
779 bn_mul_words(r,a,n,b[0]);
780
781 for (;;)
782 {
783 if (--n <= 0) return;
784 bn_mul_add_words(&(r[1]),a,n,b[1]);
785 if (--n <= 0) return;
786 bn_mul_add_words(&(r[2]),a,n,b[2]);
787 if (--n <= 0) return;
788 bn_mul_add_words(&(r[3]),a,n,b[3]);
789 if (--n <= 0) return;
790 bn_mul_add_words(&(r[4]),a,n,b[4]);
791 r+=4;
792 b+=4;
793 }
794 }
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
deleted file mode 100644
index a5f01b92eb..0000000000
--- a/src/lib/libcrypto/bn/bn_prime.c
+++ /dev/null
@@ -1,465 +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 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include <time.h>
114#include "cryptlib.h"
115#include "bn_lcl.h"
116#include <openssl/rand.h>
117
118/* The quick sieve algorithm approach to weeding out primes is
119 * Philip Zimmermann's, as implemented in PGP. I have had a read of
120 * his comments and implemented my own version.
121 */
122#include "bn_prime.h"
123
124static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
125 const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont);
126static int probable_prime(BIGNUM *rnd, int bits);
127static int probable_prime_dh(BIGNUM *rnd, int bits,
128 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
129static int probable_prime_dh_safe(BIGNUM *rnd, int bits,
130 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
131
132BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, BIGNUM *add,
133 BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg)
134 {
135 BIGNUM *rnd=NULL;
136 BIGNUM t;
137 int found=0;
138 int i,j,c1=0;
139 BN_CTX *ctx;
140 int checks = BN_prime_checks_for_size(bits);
141
142 ctx=BN_CTX_new();
143 if (ctx == NULL) goto err;
144 if (ret == NULL)
145 {
146 if ((rnd=BN_new()) == NULL) goto err;
147 }
148 else
149 rnd=ret;
150 BN_init(&t);
151loop:
152 /* make a random number and set the top and bottom bits */
153 if (add == NULL)
154 {
155 if (!probable_prime(rnd,bits)) goto err;
156 }
157 else
158 {
159 if (safe)
160 {
161 if (!probable_prime_dh_safe(rnd,bits,add,rem,ctx))
162 goto err;
163 }
164 else
165 {
166 if (!probable_prime_dh(rnd,bits,add,rem,ctx))
167 goto err;
168 }
169 }
170 /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */
171 if (callback != NULL) callback(0,c1++,cb_arg);
172
173 if (!safe)
174 {
175 i=BN_is_prime_fasttest(rnd,checks,callback,ctx,cb_arg,0);
176 if (i == -1) goto err;
177 if (i == 0) goto loop;
178 }
179 else
180 {
181 /* for "safe prime" generation,
182 * check that (p-1)/2 is prime.
183 * Since a prime is odd, We just
184 * need to divide by 2 */
185 if (!BN_rshift1(&t,rnd)) goto err;
186
187 for (i=0; i<checks; i++)
188 {
189 j=BN_is_prime_fasttest(rnd,1,callback,ctx,cb_arg,0);
190 if (j == -1) goto err;
191 if (j == 0) goto loop;
192
193 j=BN_is_prime_fasttest(&t,1,callback,ctx,cb_arg,0);
194 if (j == -1) goto err;
195 if (j == 0) goto loop;
196
197 if (callback != NULL) callback(2,c1-1,cb_arg);
198 /* We have a safe prime test pass */
199 }
200 }
201 /* we have a prime :-) */
202 found = 1;
203err:
204 if (!found && (ret == NULL) && (rnd != NULL)) BN_free(rnd);
205 BN_free(&t);
206 if (ctx != NULL) BN_CTX_free(ctx);
207 return(found ? rnd : NULL);
208 }
209
210int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
211 BN_CTX *ctx_passed, void *cb_arg)
212 {
213 return BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);
214 }
215
216int BN_is_prime_fasttest(const BIGNUM *a, int checks,
217 void (*callback)(int,int,void *),
218 BN_CTX *ctx_passed, void *cb_arg,
219 int do_trial_division)
220 {
221 int i, j, ret = -1;
222 int k;
223 BN_CTX *ctx = NULL;
224 BIGNUM *A1, *A1_odd, *check; /* taken from ctx */
225 BN_MONT_CTX *mont = NULL;
226 const BIGNUM *A = NULL;
227
228 if (checks == BN_prime_checks)
229 checks = BN_prime_checks_for_size(BN_num_bits(a));
230
231 /* first look for small factors */
232 if (!BN_is_odd(a))
233 return(0);
234 if (do_trial_division)
235 {
236 for (i = 1; i < NUMPRIMES; i++)
237 if (BN_mod_word(a, primes[i]) == 0)
238 return 0;
239 if (callback != NULL) callback(1, -1, cb_arg);
240 }
241
242 if (ctx_passed != NULL)
243 ctx = ctx_passed;
244 else
245 if ((ctx=BN_CTX_new()) == NULL)
246 goto err;
247 BN_CTX_start(ctx);
248
249 /* A := abs(a) */
250 if (a->neg)
251 {
252 BIGNUM *t;
253 if ((t = BN_CTX_get(ctx)) == NULL) goto err;
254 BN_copy(t, a);
255 t->neg = 0;
256 A = t;
257 }
258 else
259 A = a;
260 A1 = BN_CTX_get(ctx);
261 A1_odd = BN_CTX_get(ctx);
262 check = BN_CTX_get(ctx);
263 if (check == NULL) goto err;
264
265 /* compute A1 := A - 1 */
266 if (!BN_copy(A1, A))
267 goto err;
268 if (!BN_sub_word(A1, 1))
269 goto err;
270 if (BN_is_zero(A1))
271 {
272 ret = 0;
273 goto err;
274 }
275
276 /* write A1 as A1_odd * 2^k */
277 k = 1;
278 while (!BN_is_bit_set(A1, k))
279 k++;
280 if (!BN_rshift(A1_odd, A1, k))
281 goto err;
282
283 /* Montgomery setup for computations mod A */
284 mont = BN_MONT_CTX_new();
285 if (mont == NULL)
286 goto err;
287 if (!BN_MONT_CTX_set(mont, A, ctx))
288 goto err;
289
290 for (i = 0; i < checks; i++)
291 {
292 if (!BN_pseudo_rand(check, BN_num_bits(A1), 0, 0))
293 goto err;
294 if (BN_cmp(check, A1) >= 0)
295 if (!BN_sub(check, check, A1))
296 goto err;
297 if (!BN_add_word(check, 1))
298 goto err;
299 /* now 1 <= check < A */
300
301 j = witness(check, A, A1, A1_odd, k, ctx, mont);
302 if (j == -1) goto err;
303 if (j)
304 {
305 ret=0;
306 goto err;
307 }
308 if (callback != NULL) callback(1,i,cb_arg);
309 }
310 ret=1;
311err:
312 if (ctx != NULL)
313 {
314 BN_CTX_end(ctx);
315 if (ctx_passed == NULL)
316 BN_CTX_free(ctx);
317 }
318 if (mont != NULL)
319 BN_MONT_CTX_free(mont);
320
321 return(ret);
322 }
323
324static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
325 const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont)
326 {
327 if (!BN_mod_exp_mont(w, w, a1_odd, a, ctx, mont)) /* w := w^a1_odd mod a */
328 return -1;
329 if (BN_is_one(w))
330 return 0; /* probably prime */
331 if (BN_cmp(w, a1) == 0)
332 return 0; /* w == -1 (mod a), 'a' is probably prime */
333 while (--k)
334 {
335 if (!BN_mod_mul(w, w, w, a, ctx)) /* w := w^2 mod a */
336 return -1;
337 if (BN_is_one(w))
338 return 1; /* 'a' is composite, otherwise a previous 'w' would
339 * have been == -1 (mod 'a') */
340 if (BN_cmp(w, a1) == 0)
341 return 0; /* w == -1 (mod a), 'a' is probably prime */
342 }
343 /* If we get here, 'w' is the (a-1)/2-th power of the original 'w',
344 * and it is neither -1 nor +1 -- so 'a' cannot be prime */
345 return 1;
346 }
347
348static int probable_prime(BIGNUM *rnd, int bits)
349 {
350 int i;
351 BN_ULONG mods[NUMPRIMES];
352 BN_ULONG delta,d;
353
354again:
355 if (!BN_rand(rnd,bits,1,1)) return(0);
356 /* we now have a random number 'rand' to test. */
357 for (i=1; i<NUMPRIMES; i++)
358 mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);
359 delta=0;
360 loop: for (i=1; i<NUMPRIMES; i++)
361 {
362 /* check that rnd is not a prime and also
363 * that gcd(rnd-1,primes) == 1 (except for 2) */
364 if (((mods[i]+delta)%primes[i]) <= 1)
365 {
366 d=delta;
367 delta+=2;
368 /* perhaps need to check for overflow of
369 * delta (but delta can be up to 2^32)
370 * 21-May-98 eay - added overflow check */
371 if (delta < d) goto again;
372 goto loop;
373 }
374 }
375 if (!BN_add_word(rnd,delta)) return(0);
376 return(1);
377 }
378
379static int probable_prime_dh(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem,
380 BN_CTX *ctx)
381 {
382 int i,ret=0;
383 BIGNUM *t1;
384
385 BN_CTX_start(ctx);
386 if ((t1 = BN_CTX_get(ctx)) == NULL) goto err;
387
388 if (!BN_rand(rnd,bits,0,1)) goto err;
389
390 /* we need ((rnd-rem) % add) == 0 */
391
392 if (!BN_mod(t1,rnd,add,ctx)) goto err;
393 if (!BN_sub(rnd,rnd,t1)) goto err;
394 if (rem == NULL)
395 { if (!BN_add_word(rnd,1)) goto err; }
396 else
397 { if (!BN_add(rnd,rnd,rem)) goto err; }
398
399 /* we now have a random number 'rand' to test. */
400
401 loop: for (i=1; i<NUMPRIMES; i++)
402 {
403 /* check that rnd is a prime */
404 if (BN_mod_word(rnd,(BN_ULONG)primes[i]) <= 1)
405 {
406 if (!BN_add(rnd,rnd,add)) goto err;
407 goto loop;
408 }
409 }
410 ret=1;
411err:
412 BN_CTX_end(ctx);
413 return(ret);
414 }
415
416static int probable_prime_dh_safe(BIGNUM *p, int bits, BIGNUM *padd,
417 BIGNUM *rem, BN_CTX *ctx)
418 {
419 int i,ret=0;
420 BIGNUM *t1,*qadd,*q;
421
422 bits--;
423 BN_CTX_start(ctx);
424 t1 = BN_CTX_get(ctx);
425 q = BN_CTX_get(ctx);
426 qadd = BN_CTX_get(ctx);
427 if (qadd == NULL) goto err;
428
429 if (!BN_rshift1(qadd,padd)) goto err;
430
431 if (!BN_rand(q,bits,0,1)) goto err;
432
433 /* we need ((rnd-rem) % add) == 0 */
434 if (!BN_mod(t1,q,qadd,ctx)) goto err;
435 if (!BN_sub(q,q,t1)) goto err;
436 if (rem == NULL)
437 { if (!BN_add_word(q,1)) goto err; }
438 else
439 {
440 if (!BN_rshift1(t1,rem)) goto err;
441 if (!BN_add(q,q,t1)) goto err;
442 }
443
444 /* we now have a random number 'rand' to test. */
445 if (!BN_lshift1(p,q)) goto err;
446 if (!BN_add_word(p,1)) goto err;
447
448 loop: for (i=1; i<NUMPRIMES; i++)
449 {
450 /* check that p and q are prime */
451 /* check that for p and q
452 * gcd(p-1,primes) == 1 (except for 2) */
453 if ( (BN_mod_word(p,(BN_ULONG)primes[i]) == 0) ||
454 (BN_mod_word(q,(BN_ULONG)primes[i]) == 0))
455 {
456 if (!BN_add(p,p,padd)) goto err;
457 if (!BN_add(q,q,qadd)) goto err;
458 goto loop;
459 }
460 }
461 ret=1;
462err:
463 BN_CTX_end(ctx);
464 return(ret);
465 }
diff --git a/src/lib/libcrypto/bn/bn_prime.h b/src/lib/libcrypto/bn/bn_prime.h
deleted file mode 100644
index b7cf9a9bfe..0000000000
--- a/src/lib/libcrypto/bn/bn_prime.h
+++ /dev/null
@@ -1,325 +0,0 @@
1/* Auto generated by bn_prime.pl */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. 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 const 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 9fc3765486..0000000000
--- a/src/lib/libcrypto/bn/bn_prime.pl
+++ /dev/null
@@ -1,117 +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
21# print <<"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#
30# EOF
31
32print <<\EOF;
33/* Auto generated by bn_prime.pl */
34/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
35 * All rights reserved.
36 *
37 * This package is an SSL implementation written
38 * by Eric Young (eay@cryptsoft.com).
39 * The implementation was written so as to conform with Netscapes SSL.
40 *
41 * This library is free for commercial and non-commercial use as long as
42 * the following conditions are aheared to. The following conditions
43 * apply to all code found in this distribution, be it the RC4, RSA,
44 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
45 * included with this distribution is covered by the same copyright terms
46 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
47 *
48 * Copyright remains Eric Young's, and as such any Copyright notices in
49 * the code are not to be removed.
50 * If this package is used in a product, Eric Young should be given attribution
51 * as the author of the parts of the library used.
52 * This can be in the form of a textual message at program startup or
53 * in documentation (online or textual) provided with the package.
54 *
55 * Redistribution and use in source and binary forms, with or without
56 * modification, are permitted provided that the following conditions
57 * are met:
58 * 1. Redistributions of source code must retain the copyright
59 * notice, this list of conditions and the following disclaimer.
60 * 2. Redistributions in binary form must reproduce the above copyright
61 * notice, this list of conditions and the following disclaimer in the
62 * documentation and/or other materials provided with the distribution.
63 * 3. All advertising materials mentioning features or use of this software
64 * must display the following acknowledgement:
65 * "This product includes cryptographic software written by
66 * Eric Young (eay@cryptsoft.com)"
67 * The word 'cryptographic' can be left out if the rouines from the library
68 * being used are not cryptographic related :-).
69 * 4. If you include any Windows specific code (or a derivative thereof) from
70 * the apps directory (application code) you must include an acknowledgement:
71 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
72 *
73 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
74 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
77 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
78 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
79 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
80 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
81 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
82 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
83 * SUCH DAMAGE.
84 *
85 * The licence and distribution terms for any publically available version or
86 * derivative of this code cannot be changed. i.e. this code cannot simply be
87 * copied and put under another distribution licence
88 * [including the GNU Public Licence.]
89 */
90
91EOF
92
93for ($i=0; $i <= $#primes; $i++)
94 {
95 if ($primes[$i] > 256)
96 {
97 $eight=$i;
98 last;
99 }
100 }
101
102printf "#ifndef EIGHT_BIT\n";
103printf "#define NUMPRIMES %d\n",$num;
104printf "#else\n";
105printf "#define NUMPRIMES %d\n",$eight;
106printf "#endif\n";
107print "static const unsigned int primes[NUMPRIMES]=\n\t{\n\t";
108$init=0;
109for ($i=0; $i <= $#primes; $i++)
110 {
111 printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++);
112 printf("\n\t") if (($i%8) == 0) && ($i != 0);
113 printf("%4d,",$primes[$i]);
114 }
115print "\n#endif\n\t};\n";
116
117
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
deleted file mode 100644
index 782a96e7e0..0000000000
--- a/src/lib/libcrypto/bn/bn_print.c
+++ /dev/null
@@ -1,332 +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 truncation.
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 digits, 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 significant '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 digits, and it is 'i' long.
240 * We chop it into BN_DEC_NUM digits 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#ifndef NO_FP_API
282int BN_print_fp(FILE *fp, const BIGNUM *a)
283 {
284 BIO *b;
285 int ret;
286
287 if ((b=BIO_new(BIO_s_file())) == NULL)
288 return(0);
289 BIO_set_fp(b,fp,BIO_NOCLOSE);
290 ret=BN_print(b,a);
291 BIO_free(b);
292 return(ret);
293 }
294#endif
295
296int BN_print(BIO *bp, const BIGNUM *a)
297 {
298 int i,j,v,z=0;
299 int ret=0;
300
301 if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end;
302 if ((a->top == 0) && (BIO_write(bp,"0",1) != 1)) goto end;
303 for (i=a->top-1; i >=0; i--)
304 {
305 for (j=BN_BITS2-4; j >= 0; j-=4)
306 {
307 /* strip leading zeros */
308 v=((int)(a->d[i]>>(long)j))&0x0f;
309 if (z || (v != 0))
310 {
311 if (BIO_write(bp,&(Hex[v]),1) != 1)
312 goto end;
313 z=1;
314 }
315 }
316 }
317 ret=1;
318end:
319 return(ret);
320 }
321#endif
322
323#ifdef BN_DEBUG
324void bn_dump1(FILE *o, const char *a, BN_ULONG *b,int n)
325 {
326 int i;
327 fprintf(o, "%s=", a);
328 for (i=n-1;i>=0;i--)
329 fprintf(o, "%08lX", b[i]); /* assumes 32-bit BN_ULONG */
330 fprintf(o, "\n");
331 }
332#endif
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
deleted file mode 100644
index 943712c15b..0000000000
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ /dev/null
@@ -1,136 +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
65static int bnrand(int pseudorand, 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_add(&tim,sizeof(tim),0);
85
86 if (pseudorand)
87 {
88 if (RAND_pseudo_bytes(buf, bytes) == -1)
89 goto err;
90 }
91 else
92 {
93 if (RAND_bytes(buf, bytes) <= 0)
94 goto err;
95 }
96
97 if (top)
98 {
99 if (bit == 0)
100 {
101 buf[0]=1;
102 buf[1]|=0x80;
103 }
104 else
105 {
106 buf[0]|=(3<<(bit-1));
107 buf[0]&= ~(mask<<1);
108 }
109 }
110 else
111 {
112 buf[0]|=(1<<bit);
113 buf[0]&= ~(mask<<1);
114 }
115 if (bottom) /* set bottom bits to whatever odd is */
116 buf[bytes-1]|=1;
117 if (!BN_bin2bn(buf,bytes,rnd)) goto err;
118 ret=1;
119err:
120 if (buf != NULL)
121 {
122 memset(buf,0,bytes);
123 Free(buf);
124 }
125 return(ret);
126 }
127
128int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
129 {
130 return bnrand(0, rnd, bits, top, bottom);
131 }
132
133int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
134 {
135 return bnrand(1, rnd, bits, top, bottom);
136 }
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
deleted file mode 100644
index a8796bd0aa..0000000000
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ /dev/null
@@ -1,220 +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 BN_CTX_start(ctx);
110 if ((a = BN_CTX_get(ctx)) == NULL) goto err;
111 if (y != NULL)
112 {
113 if (x == y)
114 { if (!BN_sqr(a,x,ctx)) goto err; }
115 else
116 { if (!BN_mul(a,x,y,ctx)) goto err; }
117 }
118 else
119 a=x; /* Just do the mod */
120
121 BN_div_recp(NULL,r,a,recp,ctx);
122 ret=1;
123err:
124 BN_CTX_end(ctx);
125 return(ret);
126 }
127
128int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
129 BN_CTX *ctx)
130 {
131 int i,j,ret=0;
132 BIGNUM *a,*b,*d,*r;
133
134 BN_CTX_start(ctx);
135 a=BN_CTX_get(ctx);
136 b=BN_CTX_get(ctx);
137 if (dv != NULL)
138 d=dv;
139 else
140 d=BN_CTX_get(ctx);
141 if (rem != NULL)
142 r=rem;
143 else
144 r=BN_CTX_get(ctx);
145 if (a == NULL || b == NULL || d == NULL || r == NULL) goto err;
146
147 if (BN_ucmp(m,&(recp->N)) < 0)
148 {
149 BN_zero(d);
150 BN_copy(r,m);
151 BN_CTX_end(ctx);
152 return(1);
153 }
154
155 /* We want the remainder
156 * Given input of ABCDEF / ab
157 * we need multiply ABCDEF by 3 digests of the reciprocal of ab
158 *
159 */
160 i=BN_num_bits(m);
161
162 j=recp->num_bits<<1;
163 if (j>i) i=j;
164 j>>=1;
165
166 if (i != recp->shift)
167 recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
168 i,ctx);
169
170 if (!BN_rshift(a,m,j)) goto err;
171 if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;
172 if (!BN_rshift(d,b,i-j)) goto err;
173 d->neg=0;
174 if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
175 if (!BN_usub(r,m,b)) goto err;
176 r->neg=0;
177
178#if 1
179 j=0;
180 while (BN_ucmp(r,&(recp->N)) >= 0)
181 {
182 if (j++ > 2)
183 {
184 BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);
185 goto err;
186 }
187 if (!BN_usub(r,r,&(recp->N))) goto err;
188 if (!BN_add_word(d,1)) goto err;
189 }
190#endif
191
192 r->neg=BN_is_zero(r)?0:m->neg;
193 d->neg=m->neg^recp->N.neg;
194 ret=1;
195err:
196 BN_CTX_end(ctx);
197 return(ret);
198 }
199
200/* len is the expected size of the result
201 * We actually calculate with an extra word of precision, so
202 * we can do faster division if the remainder is not required.
203 */
204int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx)
205 {
206 int ret= -1;
207 BIGNUM t;
208
209 BN_init(&t);
210
211 BN_zero(&t);
212 if (!BN_set_bit(&t,len)) goto err;
213
214 if (!BN_div(r,NULL,&t,m,ctx)) goto err;
215 ret=len;
216err:
217 BN_free(&t);
218 return(ret);
219 }
220
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 fe00c5f69a..0000000000
--- a/src/lib/libcrypto/bn/bn_sqr.c
+++ /dev/null
@@ -1,288 +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 int ret = 0;
69 BIGNUM *tmp,*rr;
70
71#ifdef BN_COUNT
72printf("BN_sqr %d * %d\n",a->top,a->top);
73#endif
74 bn_check_top(a);
75
76 al=a->top;
77 if (al <= 0)
78 {
79 r->top=0;
80 return(1);
81 }
82
83 BN_CTX_start(ctx);
84 rr=(a != r) ? r : BN_CTX_get(ctx);
85 tmp=BN_CTX_get(ctx);
86 if (tmp == NULL) goto err;
87
88 max=(al+al);
89 if (bn_wexpand(rr,max+1) == NULL) goto err;
90
91 r->neg=0;
92 if (al == 4)
93 {
94#ifndef BN_SQR_COMBA
95 BN_ULONG t[8];
96 bn_sqr_normal(rr->d,a->d,4,t);
97#else
98 bn_sqr_comba4(rr->d,a->d);
99#endif
100 }
101 else if (al == 8)
102 {
103#ifndef BN_SQR_COMBA
104 BN_ULONG t[16];
105 bn_sqr_normal(rr->d,a->d,8,t);
106#else
107 bn_sqr_comba8(rr->d,a->d);
108#endif
109 }
110 else
111 {
112#if defined(BN_RECURSION)
113 if (al < BN_SQR_RECURSIVE_SIZE_NORMAL)
114 {
115 BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];
116 bn_sqr_normal(rr->d,a->d,al,t);
117 }
118 else
119 {
120 int j,k;
121
122 j=BN_num_bits_word((BN_ULONG)al);
123 j=1<<(j-1);
124 k=j+j;
125 if (al == j)
126 {
127 if (bn_wexpand(a,k*2) == NULL) goto err;
128 if (bn_wexpand(tmp,k*2) == NULL) goto err;
129 bn_sqr_recursive(rr->d,a->d,al,tmp->d);
130 }
131 else
132 {
133 if (bn_wexpand(tmp,max) == NULL) goto err;
134 bn_sqr_normal(rr->d,a->d,al,tmp->d);
135 }
136 }
137#else
138 if (bn_wexpand(tmp,max) == NULL) goto err;
139 bn_sqr_normal(rr->d,a->d,al,tmp->d);
140#endif
141 }
142
143 rr->top=max;
144 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
145 if (rr != r) BN_copy(r,rr);
146 ret = 1;
147 err:
148 BN_CTX_end(ctx);
149 return(ret);
150 }
151
152/* tmp must have 2*n words */
153void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)
154 {
155 int i,j,max;
156 BN_ULONG *ap,*rp;
157
158 max=n*2;
159 ap=a;
160 rp=r;
161 rp[0]=rp[max-1]=0;
162 rp++;
163 j=n;
164
165 if (--j > 0)
166 {
167 ap++;
168 rp[j]=bn_mul_words(rp,ap,j,ap[-1]);
169 rp+=2;
170 }
171
172 for (i=n-2; i>0; i--)
173 {
174 j--;
175 ap++;
176 rp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);
177 rp+=2;
178 }
179
180 bn_add_words(r,r,r,max);
181
182 /* There will not be a carry */
183
184 bn_sqr_words(tmp,a,n);
185
186 bn_add_words(r,r,tmp,max);
187 }
188
189#ifdef BN_RECURSION
190/* r is 2*n words in size,
191 * a and b are both n words in size.
192 * n must be a power of 2.
193 * We multiply and return the result.
194 * t must be 2*n words in size
195 * We calculate
196 * a[0]*b[0]
197 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
198 * a[1]*b[1]
199 */
200void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *t)
201 {
202 int n=n2/2;
203 int zero,c1;
204 BN_ULONG ln,lo,*p;
205
206#ifdef BN_COUNT
207printf(" bn_sqr_recursive %d * %d\n",n2,n2);
208#endif
209 if (n2 == 4)
210 {
211#ifndef BN_SQR_COMBA
212 bn_sqr_normal(r,a,4,t);
213#else
214 bn_sqr_comba4(r,a);
215#endif
216 return;
217 }
218 else if (n2 == 8)
219 {
220#ifndef BN_SQR_COMBA
221 bn_sqr_normal(r,a,8,t);
222#else
223 bn_sqr_comba8(r,a);
224#endif
225 return;
226 }
227 if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL)
228 {
229 bn_sqr_normal(r,a,n2,t);
230 return;
231 }
232 /* r=(a[0]-a[1])*(a[1]-a[0]) */
233 c1=bn_cmp_words(a,&(a[n]),n);
234 zero=0;
235 if (c1 > 0)
236 bn_sub_words(t,a,&(a[n]),n);
237 else if (c1 < 0)
238 bn_sub_words(t,&(a[n]),a,n);
239 else
240 zero=1;
241
242 /* The result will always be negative unless it is zero */
243 p= &(t[n2*2]);
244
245 if (!zero)
246 bn_sqr_recursive(&(t[n2]),t,n,p);
247 else
248 memset(&(t[n2]),0,n*sizeof(BN_ULONG));
249 bn_sqr_recursive(r,a,n,p);
250 bn_sqr_recursive(&(r[n2]),&(a[n]),n,p);
251
252 /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero
253 * r[10] holds (a[0]*b[0])
254 * r[32] holds (b[1]*b[1])
255 */
256
257 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
258
259 /* t[32] is negative */
260 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
261
262 /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1])
263 * r[10] holds (a[0]*a[0])
264 * r[32] holds (a[1]*a[1])
265 * c1 holds the carry bits
266 */
267 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
268 if (c1)
269 {
270 p= &(r[n+n2]);
271 lo= *p;
272 ln=(lo+c1)&BN_MASK2;
273 *p=ln;
274
275 /* The overflow will stop before we over write
276 * words we should not overwrite */
277 if (ln < (BN_ULONG)c1)
278 {
279 do {
280 p++;
281 lo= *p;
282 ln=(lo+1)&BN_MASK2;
283 *p=ln;
284 } while (ln == 0);
285 }
286 }
287 }
288#endif
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
deleted file mode 100644
index 73157a7d43..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(const 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 2f971a5f38..0000000000
--- a/src/lib/libcrypto/buffer/buf_err.c
+++ /dev/null
@@ -1,95 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/buffer.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA BUF_str_functs[]=
68 {
69{ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"},
70{ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"},
71{ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"},
72{0,NULL}
73 };
74
75static ERR_STRING_DATA BUF_str_reasons[]=
76 {
77{0,NULL}
78 };
79
80#endif
81
82void ERR_load_BUF_strings(void)
83 {
84 static int init=1;
85
86 if (init)
87 {
88 init=0;
89#ifndef NO_ERR
90 ERR_load_strings(ERR_LIB_BUF,BUF_str_functs);
91 ERR_load_strings(ERR_LIB_BUF,BUF_str_reasons);
92#endif
93
94 }
95 }
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 0b3da9ad87..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
63const char *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 5fab8a43f6..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) && defined(_MSC_VER)
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 const CAST_LONG CAST_S_table0[256];
220OPENSSL_EXTERN const CAST_LONG CAST_S_table1[256];
221OPENSSL_EXTERN const CAST_LONG CAST_S_table2[256];
222OPENSSL_EXTERN const CAST_LONG CAST_S_table3[256];
223OPENSSL_EXTERN const CAST_LONG CAST_S_table4[256];
224OPENSSL_EXTERN const CAST_LONG CAST_S_table5[256];
225OPENSSL_EXTERN const CAST_LONG CAST_S_table6[256];
226OPENSSL_EXTERN const 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 c483fd5e43..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 const 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 const 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 const 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 const 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 const 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 const 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 const 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 const 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 811cb5833d..0000000000
--- a/src/lib/libcrypto/comp/comp.h
+++ /dev/null
@@ -1,61 +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 long (*callback_ctrl)();
21 } COMP_METHOD;
22
23typedef struct comp_ctx_st
24 {
25 COMP_METHOD *meth;
26 unsigned long compress_in;
27 unsigned long compress_out;
28 unsigned long expand_in;
29 unsigned long expand_out;
30
31 CRYPTO_EX_DATA ex_data;
32 } COMP_CTX;
33
34
35COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
36void COMP_CTX_free(COMP_CTX *ctx);
37int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
38 unsigned char *in, int ilen);
39int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
40 unsigned char *in, int ilen);
41COMP_METHOD *COMP_rle(void );
42#ifdef ZLIB
43COMP_METHOD *COMP_zlib(void );
44#endif
45
46/* BEGIN ERROR CODES */
47/* The following lines are auto generated by the script mkerr.pl. Any changes
48 * made after this point may be overwritten when the script is next run.
49 */
50
51/* Error codes for the COMP functions. */
52
53/* Function codes. */
54
55/* Reason codes. */
56
57#ifdef __cplusplus
58}
59#endif
60#endif
61
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
deleted file mode 100644
index c10282a73c..0000000000
--- a/src/lib/libcrypto/comp/comp_err.c
+++ /dev/null
@@ -1,92 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/comp.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA COMP_str_functs[]=
68 {
69{0,NULL}
70 };
71
72static ERR_STRING_DATA COMP_str_reasons[]=
73 {
74{0,NULL}
75 };
76
77#endif
78
79void ERR_load_COMP_strings(void)
80 {
81 static int init=1;
82
83 if (init)
84 {
85 init=0;
86#ifndef NO_ERR
87 ERR_load_strings(ERR_LIB_COMP,COMP_str_functs);
88 ERR_load_strings(ERR_LIB_COMP,COMP_str_reasons);
89#endif
90
91 }
92 }
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 21831a92a3..0000000000
--- a/src/lib/libcrypto/conf/conf.h
+++ /dev/null
@@ -1,116 +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);
81#ifndef NO_FP_API
82LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
83#endif
84LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
85STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section);
86char *CONF_get_string(LHASH *conf,char *group,char *name);
87long CONF_get_number(LHASH *conf,char *group,char *name);
88void CONF_free(LHASH *conf);
89void ERR_load_CONF_strings(void );
90
91
92/* BEGIN ERROR CODES */
93/* The following lines are auto generated by the script mkerr.pl. Any changes
94 * made after this point may be overwritten when the script is next run.
95 */
96
97/* Error codes for the CONF functions. */
98
99/* Function codes. */
100#define CONF_F_CONF_LOAD 100
101#define CONF_F_CONF_LOAD_BIO 102
102#define CONF_F_CONF_LOAD_FP 103
103#define CONF_F_STR_COPY 101
104
105/* Reason codes. */
106#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
107#define CONF_R_MISSING_EQUAL_SIGN 101
108#define CONF_R_NO_CLOSE_BRACE 102
109#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
110#define CONF_R_VARIABLE_HAS_NO_VALUE 104
111
112#ifdef __cplusplus
113}
114#endif
115#endif
116
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
deleted file mode 100644
index 5c1ca59090..0000000000
--- a/src/lib/libcrypto/conf/conf_err.c
+++ /dev/null
@@ -1,101 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/conf.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA CONF_str_functs[]=
68 {
69{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
70{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"},
71{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"},
72{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
73{0,NULL}
74 };
75
76static ERR_STRING_DATA CONF_str_reasons[]=
77 {
78{CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"},
79{CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"},
80{CONF_R_NO_CLOSE_BRACE ,"no close brace"},
81{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"},
82{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"},
83{0,NULL}
84 };
85
86#endif
87
88void ERR_load_CONF_strings(void)
89 {
90 static int init=1;
91
92 if (init)
93 {
94 init=0;
95#ifndef NO_ERR
96 ERR_load_strings(ERR_LIB_CONF,CONF_str_functs);
97 ERR_load_strings(ERR_LIB_CONF,CONF_str_reasons);
98#endif
99
100 }
101 }
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 dadd8d8d92..0000000000
--- a/src/lib/libcrypto/cpt_err.c
+++ /dev/null
@@ -1,95 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/crypto.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA CRYPTO_str_functs[]=
68 {
69{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,0), "CRYPTO_get_ex_new_index"},
70{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_LOCKID,0), "CRYPTO_get_new_lockid"},
71{ERR_PACK(0,CRYPTO_F_CRYPTO_SET_EX_DATA,0), "CRYPTO_set_ex_data"},
72{0,NULL}
73 };
74
75static ERR_STRING_DATA CRYPTO_str_reasons[]=
76 {
77{0,NULL}
78 };
79
80#endif
81
82void ERR_load_CRYPTO_strings(void)
83 {
84 static int init=1;
85
86 if (init)
87 {
88 init=0;
89#ifndef NO_ERR
90 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_functs);
91 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_reasons);
92#endif
93
94 }
95 }
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
deleted file mode 100644
index a8f29f1e65..0000000000
--- a/src/lib/libcrypto/cryptlib.c
+++ /dev/null
@@ -1,302 +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 "dh",
96 "debug_malloc2",
97#if CRYPTO_NUM_LOCKS != 26
98# error "Inconsistency between crypto.h and cryptlib.c"
99#endif
100 };
101
102static STACK *app_locks=NULL;
103
104static void (MS_FAR *locking_callback)(int mode,int type,
105 const char *file,int line)=NULL;
106static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
107 int type,const char *file,int line)=NULL;
108static unsigned long (MS_FAR *id_callback)(void)=NULL;
109int CRYPTO_get_new_lockid(char *name)
110 {
111 char *str;
112 int i;
113
114 /* A hack to make Visual C++ 5.0 work correctly when linking as
115 * a DLL using /MT. Without this, the application cannot use
116 * and floating point printf's.
117 * It also seems to be needed for Visual C 1.5 (win16) */
118#if defined(WIN32) || defined(WIN16)
119 SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
120#endif
121
122 if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL))
123 {
124 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
125 return(0);
126 }
127 if ((str=BUF_strdup(name)) == NULL)
128 return(0);
129 i=sk_push(app_locks,str);
130 if (!i)
131 Free(str);
132 else
133 i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */
134 return(i);
135 }
136
137int CRYPTO_num_locks(void)
138 {
139 return CRYPTO_NUM_LOCKS;
140 }
141
142void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
143 int line)
144 {
145 return(locking_callback);
146 }
147
148int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
149 const char *file,int line)
150 {
151 return(add_lock_callback);
152 }
153
154void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
155 const char *file,int line))
156 {
157 locking_callback=func;
158 }
159
160void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
161 const char *file,int line))
162 {
163 add_lock_callback=func;
164 }
165
166unsigned long (*CRYPTO_get_id_callback(void))(void)
167 {
168 return(id_callback);
169 }
170
171void CRYPTO_set_id_callback(unsigned long (*func)(void))
172 {
173 id_callback=func;
174 }
175
176unsigned long CRYPTO_thread_id(void)
177 {
178 unsigned long ret=0;
179
180 if (id_callback == NULL)
181 {
182#ifdef WIN16
183 ret=(unsigned long)GetCurrentTask();
184#elif defined(WIN32)
185 ret=(unsigned long)GetCurrentThreadId();
186#elif defined(GETPID_IS_MEANINGLESS)
187 ret=1L;
188#else
189 ret=(unsigned long)getpid();
190#endif
191 }
192 else
193 ret=id_callback();
194 return(ret);
195 }
196
197void CRYPTO_lock(int mode, int type, const char *file, int line)
198 {
199#ifdef LOCK_DEBUG
200 {
201 char *rw_text,*operation_text;
202
203 if (mode & CRYPTO_LOCK)
204 operation_text="lock ";
205 else if (mode & CRYPTO_UNLOCK)
206 operation_text="unlock";
207 else
208 operation_text="ERROR ";
209
210 if (mode & CRYPTO_READ)
211 rw_text="r";
212 else if (mode & CRYPTO_WRITE)
213 rw_text="w";
214 else
215 rw_text="ERROR";
216
217 fprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\n",
218 CRYPTO_thread_id(), rw_text, operation_text,
219 CRYPTO_get_lock_name(type), file, line);
220 }
221#endif
222 if (locking_callback != NULL)
223 locking_callback(mode,type,file,line);
224 }
225
226int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
227 int line)
228 {
229 int ret;
230
231 if (add_lock_callback != NULL)
232 {
233#ifdef LOCK_DEBUG
234 int before= *pointer;
235#endif
236
237 ret=add_lock_callback(pointer,amount,type,file,line);
238#ifdef LOCK_DEBUG
239 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
240 CRYPTO_thread_id(),
241 before,amount,ret,
242 CRYPTO_get_lock_name(type),
243 file,line);
244#endif
245 *pointer=ret;
246 }
247 else
248 {
249 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);
250
251 ret= *pointer+amount;
252#ifdef LOCK_DEBUG
253 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
254 CRYPTO_thread_id(),
255 *pointer,amount,ret,
256 CRYPTO_get_lock_name(type),
257 file,line);
258#endif
259 *pointer=ret;
260 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
261 }
262 return(ret);
263 }
264
265const char *CRYPTO_get_lock_name(int type)
266 {
267 if (type < 0)
268 return("ERROR");
269 else if (type < CRYPTO_NUM_LOCKS)
270 return(lock_names[type]);
271 else if (type-CRYPTO_NUM_LOCKS >= sk_num(app_locks))
272 return("ERROR");
273 else
274 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
275 }
276
277#ifdef _DLL
278#ifdef WIN32
279
280/* All we really need to do is remove the 'error' state when a thread
281 * detaches */
282
283BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason,
284 LPVOID lpvReserved)
285 {
286 switch(fdwReason)
287 {
288 case DLL_PROCESS_ATTACH:
289 break;
290 case DLL_THREAD_ATTACH:
291 break;
292 case DLL_THREAD_DETACH:
293 ERR_remove_state(0);
294 break;
295 case DLL_PROCESS_DETACH:
296 break;
297 }
298 return(TRUE);
299 }
300#endif
301
302#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 41c937966e..0000000000
--- a/src/lib/libcrypto/crypto.h
+++ /dev/null
@@ -1,373 +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#include <stdlib.h>
67
68#ifndef NO_FP_API
69#include <stdio.h>
70#endif
71
72#include <openssl/stack.h>
73#include <openssl/safestack.h>
74#include <openssl/opensslv.h>
75
76#ifdef CHARSET_EBCDIC
77#include <openssl/ebcdic.h>
78#endif
79
80#if defined(VMS) || defined(__VMS)
81#include "vms_idhacks.h"
82#endif
83
84
85/* Backward compatibility to SSLeay */
86/* This is more to be used to check the correct DLL is being used
87 * in the MS world. */
88#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
89#define SSLEAY_VERSION 0
90/* #define SSLEAY_OPTIONS 1 no longer supported */
91#define SSLEAY_CFLAGS 2
92#define SSLEAY_BUILT_ON 3
93#define SSLEAY_PLATFORM 4
94
95/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
96 * names in cryptlib.c
97 */
98
99#define CRYPTO_LOCK_ERR 1
100#define CRYPTO_LOCK_ERR_HASH 2
101#define CRYPTO_LOCK_X509 3
102#define CRYPTO_LOCK_X509_INFO 4
103#define CRYPTO_LOCK_X509_PKEY 5
104#define CRYPTO_LOCK_X509_CRL 6
105#define CRYPTO_LOCK_X509_REQ 7
106#define CRYPTO_LOCK_DSA 8
107#define CRYPTO_LOCK_RSA 9
108#define CRYPTO_LOCK_EVP_PKEY 10
109#define CRYPTO_LOCK_X509_STORE 11
110#define CRYPTO_LOCK_SSL_CTX 12
111#define CRYPTO_LOCK_SSL_CERT 13
112#define CRYPTO_LOCK_SSL_SESSION 14
113#define CRYPTO_LOCK_SSL_SESS_CERT 15
114#define CRYPTO_LOCK_SSL 16
115#define CRYPTO_LOCK_RAND 17
116#define CRYPTO_LOCK_MALLOC 18
117#define CRYPTO_LOCK_BIO 19
118#define CRYPTO_LOCK_GETHOSTBYNAME 20
119#define CRYPTO_LOCK_GETSERVBYNAME 21
120#define CRYPTO_LOCK_READDIR 22
121#define CRYPTO_LOCK_RSA_BLINDING 23
122#define CRYPTO_LOCK_DH 24
123#define CRYPTO_LOCK_MALLOC2 25
124#define CRYPTO_NUM_LOCKS 26
125
126#define CRYPTO_LOCK 1
127#define CRYPTO_UNLOCK 2
128#define CRYPTO_READ 4
129#define CRYPTO_WRITE 8
130
131#ifndef NO_LOCKING
132#ifndef CRYPTO_w_lock
133#define CRYPTO_w_lock(type) \
134 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
135#define CRYPTO_w_unlock(type) \
136 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
137#define CRYPTO_r_lock(type) \
138 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
139#define CRYPTO_r_unlock(type) \
140 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
141#define CRYPTO_add(addr,amount,type) \
142 CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
143#endif
144#else
145#define CRYPTO_w_lock(a)
146#define CRYPTO_w_unlock(a)
147#define CRYPTO_r_lock(a)
148#define CRYPTO_r_unlock(a)
149#define CRYPTO_add(a,b,c) ((*(a))+=(b))
150#endif
151
152/* The following can be used to detect memory leaks in the SSLeay library.
153 * It used, it turns on malloc checking */
154
155#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */
156#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */
157#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */
158#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */
159
160/* The following are bit values to turn on or off options connected to the
161 * malloc checking functionality */
162
163/* Adds time to the memory checking information */
164#define V_CRYPTO_MDEBUG_TIME 0x1 /* a bit */
165/* Adds thread number to the memory checking information */
166#define V_CRYPTO_MDEBUG_THREAD 0x2 /* a bit */
167
168#define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)
169
170
171/* predec of the BIO type */
172typedef struct bio_st BIO_dummy;
173
174typedef struct crypto_ex_data_st
175 {
176 STACK *sk;
177 int dummy; /* gcc is screwing up this data structure :-( */
178 } CRYPTO_EX_DATA;
179
180/* Called when a new object is created */
181typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
182 int idx, long argl, void *argp);
183/* Called when an object is free()ed */
184typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
185 int idx, long argl, void *argp);
186/* Called when we need to dup an object */
187typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
188 int idx, long argl, void *argp);
189
190/* This stuff is basically class callback functions
191 * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */
192
193typedef struct crypto_ex_data_func_st
194 {
195 long argl; /* Arbitary long */
196 void *argp; /* Arbitary void * */
197 CRYPTO_EX_new *new_func;
198 CRYPTO_EX_free *free_func;
199 CRYPTO_EX_dup *dup_func;
200 } CRYPTO_EX_DATA_FUNCS;
201
202DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
203
204/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
205 * entry.
206 */
207
208#define CRYPTO_EX_INDEX_BIO 0
209#define CRYPTO_EX_INDEX_SSL 1
210#define CRYPTO_EX_INDEX_SSL_CTX 2
211#define CRYPTO_EX_INDEX_SSL_SESSION 3
212#define CRYPTO_EX_INDEX_X509_STORE 4
213#define CRYPTO_EX_INDEX_X509_STORE_CTX 5
214
215
216/* This is the default callbacks, but we can have others as well:
217 * this is needed in Win32 where the application malloc and the
218 * library malloc may not be the same.
219 */
220#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
221 malloc, realloc, free)
222
223#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
224# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
225# define CRYPTO_MDEBUG
226# endif
227#endif
228
229/* Set standard debugging functions (not done by default
230 * unless CRYPTO_MDEBUG is defined) */
231#define CRYPTO_malloc_debug_init() do {\
232 CRYPTO_set_mem_debug_functions(\
233 (void (*)())CRYPTO_dbg_malloc,\
234 (void (*)())CRYPTO_dbg_realloc,\
235 (void (*)())CRYPTO_dbg_free,\
236 (void (*)())CRYPTO_dbg_set_options,\
237 (long (*)())CRYPTO_dbg_get_options);\
238 } while(0)
239
240int CRYPTO_mem_ctrl(int mode);
241int CRYPTO_is_mem_check_on(void);
242
243/* for applications */
244#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
245#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
246
247/* for library-internal use */
248#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
249#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
250#define is_MemCheck_on() CRYPTO_is_mem_check_on()
251
252#define Malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__)
253#define Realloc(addr,num) \
254 CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__)
255#define Remalloc(addr,num) \
256 CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
257#define FreeFunc CRYPTO_free
258#define Free(addr) CRYPTO_free(addr)
259
260#define Malloc_locked(num) CRYPTO_malloc_locked((int)num,__FILE__,__LINE__)
261#define Free_locked(addr) CRYPTO_free_locked(addr)
262
263
264/* Case insensiteve linking causes problems.... */
265#if defined(WIN16) || defined(VMS)
266#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
267#endif
268
269
270const char *SSLeay_version(int type);
271unsigned long SSLeay(void);
272
273int CRYPTO_get_ex_new_index(int idx, STACK_OF(CRYPTO_EX_DATA_FUNCS) **skp, long argl, void *argp,
274 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
275int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);
276void *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad,int idx);
277int CRYPTO_dup_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, CRYPTO_EX_DATA *to,
278 CRYPTO_EX_DATA *from);
279void CRYPTO_free_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad);
280void CRYPTO_new_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad);
281
282int CRYPTO_get_new_lockid(char *name);
283
284int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
285void CRYPTO_lock(int mode, int type,const char *file,int line);
286void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
287 const char *file,int line));
288void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
289 int line);
290void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
291 const char *file, int line));
292int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
293 const char *file,int line);
294void CRYPTO_set_id_callback(unsigned long (*func)(void));
295unsigned long (*CRYPTO_get_id_callback(void))(void);
296unsigned long CRYPTO_thread_id(void);
297const char *CRYPTO_get_lock_name(int type);
298int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
299 int line);
300
301/* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions --
302 * call the latter last if you need different functions */
303int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *));
304int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *));
305int CRYPTO_set_mem_debug_functions(void (*m)(),void (*r)(),void (*f)(),void (*so)(),long (*go)());
306void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));
307void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));
308void CRYPTO_get_mem_debug_functions(void (**m)(),void (**r)(),void (**f)(),void (**so)(),long (**go)());
309
310void *CRYPTO_malloc_locked(int num, const char *file, int line);
311void CRYPTO_free_locked(void *);
312void *CRYPTO_malloc(int num, const char *file, int line);
313void CRYPTO_free(void *);
314void *CRYPTO_realloc(void *addr,int num, const char *file, int line);
315void *CRYPTO_remalloc(void *addr,int num, const char *file, int line);
316
317void CRYPTO_set_mem_debug_options(long bits);
318long CRYPTO_get_mem_debug_options(void);
319
320#define CRYPTO_push_info(info) \
321 CRYPTO_push_info_(info, __FILE__, __LINE__);
322int CRYPTO_push_info_(const char *info, const char *file, int line);
323int CRYPTO_pop_info(void);
324int CRYPTO_remove_all_info(void);
325
326/* The last argument has the following significance:
327 *
328 * 0: called before the actual memory allocation has taken place
329 * 1: called after the actual memory allocation has taken place
330 */
331void CRYPTO_dbg_malloc(void *addr,int num,const char *file,int line,int before_p);
332void CRYPTO_dbg_realloc(void *addr1,void *addr2,int num,const char *file,int line,int before_p);
333void CRYPTO_dbg_free(void *addr,int before_p);
334
335/* Tell the debugging code about options. By default, the following values
336 * apply:
337 *
338 * 0: Clear all options.
339 * 1: Set the "Show Time" option.
340 * 2: Set the "Show Thread Number" option.
341 * 3: 1 + 2
342 */
343void CRYPTO_dbg_set_options(long bits);
344long CRYPTO_dbg_get_options(void);
345
346#ifndef NO_FP_API
347void CRYPTO_mem_leaks_fp(FILE *);
348#endif
349void CRYPTO_mem_leaks(struct bio_st *bio);
350/* unsigned long order, char *file, int line, int num_bytes, char *addr */
351void CRYPTO_mem_leaks_cb(void (*cb)());
352
353void ERR_load_CRYPTO_strings(void);
354
355/* BEGIN ERROR CODES */
356/* The following lines are auto generated by the script mkerr.pl. Any changes
357 * made after this point may be overwritten when the script is next run.
358 */
359
360/* Error codes for the CRYPTO functions. */
361
362/* Function codes. */
363#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
364#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101
365#define CRYPTO_F_CRYPTO_SET_EX_DATA 102
366
367/* Reason codes. */
368
369#ifdef __cplusplus
370}
371#endif
372#endif
373
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 ead67986d9..0000000000
--- a/src/lib/libcrypto/des/des.h
+++ /dev/null
@@ -1,267 +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
83typedef struct des_ks_struct
84 {
85 union {
86 des_cblock cblock;
87 /* make sure things are correct size on machines with
88 * 8 byte longs */
89 DES_LONG deslong[2];
90 } ks;
91 int weak_key;
92 } des_key_schedule[16];
93
94#define DES_KEY_SZ (sizeof(des_cblock))
95#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
96
97#define DES_ENCRYPT 1
98#define DES_DECRYPT 0
99
100#define DES_CBC_MODE 0
101#define DES_PCBC_MODE 1
102
103#define des_ecb2_encrypt(i,o,k1,k2,e) \
104 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
105
106#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
107 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
108
109#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
110 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
111
112#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
113 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
114
115OPENSSL_EXTERN int des_check_key; /* defaults to false */
116OPENSSL_EXTERN int des_rw_mode; /* defaults to DES_PCBC_MODE */
117OPENSSL_EXTERN int des_set_weak_key_flag; /* set the weak key flag */
118
119const char *des_options(void);
120void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output,
121 des_key_schedule ks1,des_key_schedule ks2,
122 des_key_schedule ks3, int enc);
123DES_LONG des_cbc_cksum(const unsigned char *input,des_cblock *output,
124 long length,des_key_schedule schedule,
125 const_des_cblock *ivec);
126/* des_cbc_encrypt does not update the IV! Use des_ncbc_encrypt instead. */
127void des_cbc_encrypt(const unsigned char *input,unsigned char *output,
128 long length,des_key_schedule schedule,des_cblock *ivec,
129 int enc);
130void des_ncbc_encrypt(const unsigned char *input,unsigned char *output,
131 long length,des_key_schedule schedule,des_cblock *ivec,
132 int enc);
133void des_xcbc_encrypt(const unsigned char *input,unsigned char *output,
134 long length,des_key_schedule schedule,des_cblock *ivec,
135 const_des_cblock *inw,const_des_cblock *outw,int enc);
136void des_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
137 long length,des_key_schedule schedule,des_cblock *ivec,
138 int enc);
139void des_ecb_encrypt(const_des_cblock *input,des_cblock *output,
140 des_key_schedule ks,int enc);
141
142/* This is the DES encryption function that gets called by just about
143 every other DES routine in the library. You should not use this
144 function except to implement 'modes' of DES. I say this because the
145 functions that call this routine do the conversion from 'char *' to
146 long, and this needs to be done to make sure 'non-aligned' memory
147 access do not occur. The characters are loaded 'little endian'.
148 Data is a pointer to 2 unsigned long's and ks is the
149 des_key_schedule to use. enc, is non zero specifies encryption,
150 zero if decryption. */
151void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
152
153/* This functions is the same as des_encrypt() except that the DES
154 initial permutation (IP) and final permutation (FP) have been left
155 out. As for des_encrypt(), you should not use this function.
156 It is used by the routines in the library that implement triple DES.
157 IP() des_encrypt2() des_encrypt2() des_encrypt2() FP() is the same
158 as des_encrypt() des_encrypt() des_encrypt() except faster :-). */
159void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
160
161void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
162 des_key_schedule ks2, des_key_schedule ks3);
163void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
164 des_key_schedule ks2, des_key_schedule ks3);
165void des_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
166 long length,
167 des_key_schedule ks1,des_key_schedule ks2,
168 des_key_schedule ks3,des_cblock *ivec,int enc);
169void des_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
170 long length,
171 des_key_schedule ks1,des_key_schedule ks2,
172 des_key_schedule ks3,
173 des_cblock *ivec1,des_cblock *ivec2,
174 int enc);
175void des_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
176 long length,des_key_schedule ks1,
177 des_key_schedule ks2,des_key_schedule ks3,
178 des_cblock *ivec,int *num,int enc);
179void des_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
180 long length,des_key_schedule ks1,
181 des_key_schedule ks2,des_key_schedule ks3,
182 des_cblock *ivec,int *num);
183
184void des_xwhite_in2out(const_des_cblock *des_key,const_des_cblock *in_white,
185 des_cblock *out_white);
186
187int des_enc_read(int fd,void *buf,int len,des_key_schedule sched,
188 des_cblock *iv);
189int des_enc_write(int fd,const void *buf,int len,des_key_schedule sched,
190 des_cblock *iv);
191char *des_fcrypt(const char *buf,const char *salt, char *ret);
192char *des_crypt(const char *buf,const char *salt);
193#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
194char *crypt(const char *buf,const char *salt);
195#endif
196void des_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
197 long length,des_key_schedule schedule,des_cblock *ivec);
198void des_pcbc_encrypt(const unsigned char *input,unsigned char *output,
199 long length,des_key_schedule schedule,des_cblock *ivec,
200 int enc);
201DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[],
202 long length,int out_count,des_cblock *seed);
203void des_random_seed(des_cblock *key);
204int des_random_key(des_cblock *ret);
205int des_read_password(des_cblock *key,const char *prompt,int verify);
206int des_read_2passwords(des_cblock *key1,des_cblock *key2,
207 const char *prompt,int verify);
208int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
209void des_set_odd_parity(des_cblock *key);
210int des_check_key_parity(const_des_cblock *key);
211int des_is_weak_key(const_des_cblock *key);
212/* des_set_key (= set_key = des_key_sched = key_sched) calls
213 * des_set_key_checked if global variable des_check_key is set,
214 * des_set_key_unchecked otherwise. */
215int des_set_key(const_des_cblock *key,des_key_schedule schedule);
216int des_key_sched(const_des_cblock *key,des_key_schedule schedule);
217int des_set_key_checked(const_des_cblock *key,des_key_schedule schedule);
218void des_set_key_unchecked(const_des_cblock *key,des_key_schedule schedule);
219void des_string_to_key(const char *str,des_cblock *key);
220void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2);
221void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
222 des_key_schedule schedule,des_cblock *ivec,int *num,
223 int enc);
224void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
225 des_key_schedule schedule,des_cblock *ivec,int *num);
226int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
227
228/* The following definitions provide compatibility with the MIT Kerberos
229 * library. The des_key_schedule structure is not binary compatible. */
230
231#define _KERBEROS_DES_H
232
233#define KRBDES_ENCRYPT DES_ENCRYPT
234#define KRBDES_DECRYPT DES_DECRYPT
235
236#ifdef KERBEROS
237# define ENCRYPT DES_ENCRYPT
238# define DECRYPT DES_DECRYPT
239#endif
240
241#ifndef NCOMPAT
242# define C_Block des_cblock
243# define Key_schedule des_key_schedule
244# define KEY_SZ DES_KEY_SZ
245# define string_to_key des_string_to_key
246# define read_pw_string des_read_pw_string
247# define random_key des_random_key
248# define pcbc_encrypt des_pcbc_encrypt
249# define set_key des_set_key
250# define key_sched des_key_sched
251# define ecb_encrypt des_ecb_encrypt
252# define cbc_encrypt des_cbc_encrypt
253# define ncbc_encrypt des_ncbc_encrypt
254# define xcbc_encrypt des_xcbc_encrypt
255# define cbc_cksum des_cbc_cksum
256# define quad_cksum des_quad_cksum
257# define check_parity des_check_key_parity
258#endif
259
260typedef des_key_schedule bit_64;
261#define des_fixup_key_parity des_set_odd_parity
262
263#ifdef __cplusplus
264}
265#endif
266
267#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 1ace8f5930..0000000000
--- a/src/lib/libcrypto/des/des_locl.h
+++ /dev/null
@@ -1,412 +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#ifdef OPENSSL_UNISTD
76# include OPENSSL_UNISTD
77#else
78# include <unistd.h>
79#endif
80#include <math.h>
81#endif
82#endif
83#include <openssl/des.h>
84
85#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */
86#include <stdlib.h>
87#include <errno.h>
88#include <time.h>
89#include <io.h>
90#endif
91
92#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
93#include <string.h>
94#endif
95
96#define ITERATIONS 16
97#define HALF_ITERATIONS 8
98
99/* used in des_read and des_write */
100#define MAXWRITE (1024*16)
101#define BSIZE (MAXWRITE+4)
102
103#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
104 l|=((DES_LONG)(*((c)++)))<< 8L, \
105 l|=((DES_LONG)(*((c)++)))<<16L, \
106 l|=((DES_LONG)(*((c)++)))<<24L)
107
108/* NOTE - c is not incremented as per c2l */
109#define c2ln(c,l1,l2,n) { \
110 c+=n; \
111 l1=l2=0; \
112 switch (n) { \
113 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
114 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
115 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
116 case 5: l2|=((DES_LONG)(*(--(c)))); \
117 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
118 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
119 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
120 case 1: l1|=((DES_LONG)(*(--(c)))); \
121 } \
122 }
123
124#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
125 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
126 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
127 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
128
129/* replacements for htonl and ntohl since I have no idea what to do
130 * when faced with machines with 8 byte longs. */
131#define HDRSIZE 4
132
133#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
134 l|=((DES_LONG)(*((c)++)))<<16L, \
135 l|=((DES_LONG)(*((c)++)))<< 8L, \
136 l|=((DES_LONG)(*((c)++))))
137
138#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
139 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
140 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
141 *((c)++)=(unsigned char)(((l) )&0xff))
142
143/* NOTE - c is not incremented as per l2c */
144#define l2cn(l1,l2,c,n) { \
145 c+=n; \
146 switch (n) { \
147 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
148 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
149 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
150 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
151 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
152 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
153 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
154 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
155 } \
156 }
157
158#if defined(WIN32) && defined(_MSC_VER)
159#define ROTATE(a,n) (_lrotr(a,n))
160#else
161#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
162#endif
163
164/* Don't worry about the LOAD_DATA() stuff, that is used by
165 * fcrypt() to add it's little bit to the front */
166
167#ifdef DES_FCRYPT
168
169#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
170 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
171
172#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
173 t=R^(R>>16L); \
174 u=t&E0; t&=E1; \
175 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
176 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
177#else
178#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
179#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
180 u=R^s[S ]; \
181 t=R^s[S+1]
182#endif
183
184/* The changes to this macro may help or hinder, depending on the
185 * compiler and the architecture. gcc2 always seems to do well :-).
186 * Inspired by Dana How <how@isl.stanford.edu>
187 * DO NOT use the alternative version on machines with 8 byte longs.
188 * It does not seem to work on the Alpha, even when DES_LONG is 4
189 * bytes, probably an issue of accessing non-word aligned objects :-( */
190#ifdef DES_PTR
191
192/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
193 * is no reason to not xor all the sub items together. This potentially
194 * saves a register since things can be xored directly into L */
195
196#if defined(DES_RISC1) || defined(DES_RISC2)
197#ifdef DES_RISC1
198#define D_ENCRYPT(LL,R,S) { \
199 unsigned int u1,u2,u3; \
200 LOAD_DATA(R,S,u,t,E0,E1,u1); \
201 u2=(int)u>>8L; \
202 u1=(int)u&0xfc; \
203 u2&=0xfc; \
204 t=ROTATE(t,4); \
205 u>>=16L; \
206 LL^= *(const DES_LONG *)(des_SP +u1); \
207 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
208 u3=(int)(u>>8L); \
209 u1=(int)u&0xfc; \
210 u3&=0xfc; \
211 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
212 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
213 u2=(int)t>>8L; \
214 u1=(int)t&0xfc; \
215 u2&=0xfc; \
216 t>>=16L; \
217 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
218 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
219 u3=(int)t>>8L; \
220 u1=(int)t&0xfc; \
221 u3&=0xfc; \
222 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
223 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
224#endif
225#ifdef DES_RISC2
226#define D_ENCRYPT(LL,R,S) { \
227 unsigned int u1,u2,s1,s2; \
228 LOAD_DATA(R,S,u,t,E0,E1,u1); \
229 u2=(int)u>>8L; \
230 u1=(int)u&0xfc; \
231 u2&=0xfc; \
232 t=ROTATE(t,4); \
233 LL^= *(const DES_LONG *)(des_SP +u1); \
234 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
235 s1=(int)(u>>16L); \
236 s2=(int)(u>>24L); \
237 s1&=0xfc; \
238 s2&=0xfc; \
239 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
240 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
241 u2=(int)t>>8L; \
242 u1=(int)t&0xfc; \
243 u2&=0xfc; \
244 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
245 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
246 s1=(int)(t>>16L); \
247 s2=(int)(t>>24L); \
248 s1&=0xfc; \
249 s2&=0xfc; \
250 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
251 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
252#endif
253#else
254#define D_ENCRYPT(LL,R,S) { \
255 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
256 t=ROTATE(t,4); \
257 LL^= \
258 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
259 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
260 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
261 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
262 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
263 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
264 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
265 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
266#endif
267
268#else /* original version */
269
270#if defined(DES_RISC1) || defined(DES_RISC2)
271#ifdef DES_RISC1
272#define D_ENCRYPT(LL,R,S) {\
273 unsigned int u1,u2,u3; \
274 LOAD_DATA(R,S,u,t,E0,E1,u1); \
275 u>>=2L; \
276 t=ROTATE(t,6); \
277 u2=(int)u>>8L; \
278 u1=(int)u&0x3f; \
279 u2&=0x3f; \
280 u>>=16L; \
281 LL^=des_SPtrans[0][u1]; \
282 LL^=des_SPtrans[2][u2]; \
283 u3=(int)u>>8L; \
284 u1=(int)u&0x3f; \
285 u3&=0x3f; \
286 LL^=des_SPtrans[4][u1]; \
287 LL^=des_SPtrans[6][u3]; \
288 u2=(int)t>>8L; \
289 u1=(int)t&0x3f; \
290 u2&=0x3f; \
291 t>>=16L; \
292 LL^=des_SPtrans[1][u1]; \
293 LL^=des_SPtrans[3][u2]; \
294 u3=(int)t>>8L; \
295 u1=(int)t&0x3f; \
296 u3&=0x3f; \
297 LL^=des_SPtrans[5][u1]; \
298 LL^=des_SPtrans[7][u3]; }
299#endif
300#ifdef DES_RISC2
301#define D_ENCRYPT(LL,R,S) {\
302 unsigned int u1,u2,s1,s2; \
303 LOAD_DATA(R,S,u,t,E0,E1,u1); \
304 u>>=2L; \
305 t=ROTATE(t,6); \
306 u2=(int)u>>8L; \
307 u1=(int)u&0x3f; \
308 u2&=0x3f; \
309 LL^=des_SPtrans[0][u1]; \
310 LL^=des_SPtrans[2][u2]; \
311 s1=(int)u>>16L; \
312 s2=(int)u>>24L; \
313 s1&=0x3f; \
314 s2&=0x3f; \
315 LL^=des_SPtrans[4][s1]; \
316 LL^=des_SPtrans[6][s2]; \
317 u2=(int)t>>8L; \
318 u1=(int)t&0x3f; \
319 u2&=0x3f; \
320 LL^=des_SPtrans[1][u1]; \
321 LL^=des_SPtrans[3][u2]; \
322 s1=(int)t>>16; \
323 s2=(int)t>>24L; \
324 s1&=0x3f; \
325 s2&=0x3f; \
326 LL^=des_SPtrans[5][s1]; \
327 LL^=des_SPtrans[7][s2]; }
328#endif
329
330#else
331
332#define D_ENCRYPT(LL,R,S) {\
333 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
334 t=ROTATE(t,4); \
335 LL^=\
336 des_SPtrans[0][(u>> 2L)&0x3f]^ \
337 des_SPtrans[2][(u>>10L)&0x3f]^ \
338 des_SPtrans[4][(u>>18L)&0x3f]^ \
339 des_SPtrans[6][(u>>26L)&0x3f]^ \
340 des_SPtrans[1][(t>> 2L)&0x3f]^ \
341 des_SPtrans[3][(t>>10L)&0x3f]^ \
342 des_SPtrans[5][(t>>18L)&0x3f]^ \
343 des_SPtrans[7][(t>>26L)&0x3f]; }
344#endif
345#endif
346
347 /* IP and FP
348 * The problem is more of a geometric problem that random bit fiddling.
349 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
350 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
351 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
352 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
353
354 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
355 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
356 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
357 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
358
359 The output has been subject to swaps of the form
360 0 1 -> 3 1 but the odd and even bits have been put into
361 2 3 2 0
362 different words. The main trick is to remember that
363 t=((l>>size)^r)&(mask);
364 r^=t;
365 l^=(t<<size);
366 can be used to swap and move bits between words.
367
368 So l = 0 1 2 3 r = 16 17 18 19
369 4 5 6 7 20 21 22 23
370 8 9 10 11 24 25 26 27
371 12 13 14 15 28 29 30 31
372 becomes (for size == 2 and mask == 0x3333)
373 t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
374 6^20 7^21 -- -- 4 5 20 21 6 7 22 23
375 10^24 11^25 -- -- 8 9 24 25 10 11 24 25
376 14^28 15^29 -- -- 12 13 28 29 14 15 28 29
377
378 Thanks for hints from Richard Outerbridge - he told me IP&FP
379 could be done in 15 xor, 10 shifts and 5 ands.
380 When I finally started to think of the problem in 2D
381 I first got ~42 operations without xors. When I remembered
382 how to use xors :-) I got it to its final state.
383 */
384#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
385 (b)^=(t),\
386 (a)^=((t)<<(n)))
387
388#define IP(l,r) \
389 { \
390 register DES_LONG tt; \
391 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
392 PERM_OP(l,r,tt,16,0x0000ffffL); \
393 PERM_OP(r,l,tt, 2,0x33333333L); \
394 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
395 PERM_OP(r,l,tt, 1,0x55555555L); \
396 }
397
398#define FP(l,r) \
399 { \
400 register DES_LONG tt; \
401 PERM_OP(l,r,tt, 1,0x55555555L); \
402 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
403 PERM_OP(l,r,tt, 2,0x33333333L); \
404 PERM_OP(r,l,tt,16,0x0000ffffL); \
405 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
406 }
407
408OPENSSL_EXTERN const DES_LONG des_SPtrans[8][64];
409
410void fcrypt_body(DES_LONG *out,des_key_schedule ks,
411 DES_LONG Eswap0, DES_LONG Eswap1);
412#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 7399ff7269..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,(void *)&(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,(void *)&(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 4d3452724e..0000000000
--- a/src/lib/libcrypto/des/enc_writ.c
+++ /dev/null
@@ -1,171 +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_pseudo_bytes(shortbuf+len, 8-len);
134 rnum=8;
135 }
136 else
137 {
138 cp=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 up to. */
156 i=write(fd,(void *)&(outbuf[j]),outnum-j);
157 if (i == -1)
158 {
159#ifdef EINTR
160 if (errno == EINTR)
161 i=0;
162 else
163#endif
164 /* This is really a bad error - very bad
165 * It will stuff-up both ends. */
166 return(-1);
167 }
168 }
169
170 return(len);
171 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
deleted file mode 100644
index 9b21f81cc2..0000000000
--- a/src/lib/libcrypto/des/fcrypt.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/* NOCW */
2#include <stdio.h>
3
4/* This version of crypt has been developed from my MIT compatible
5 * DES library.
6 * Eric Young (eay@cryptsoft.com)
7 */
8
9/* Modification by Jens Kupferschmidt (Cu)
10 * I have included directive PARA for shared memory computers.
11 * I have included a directive LONGCRYPT to using this routine to cipher
12 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
13 * definition is the maximum of length of password and can changed. I have
14 * defined 24.
15 */
16
17#include "des_locl.h"
18
19/* Added more values to handle illegal salt values the way normal
20 * crypt() implementations do. The patch was sent by
21 * Bjorn Gronvall <bg@sics.se>
22 */
23static unsigned const char con_salt[128]={
240xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,
250xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,
260xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,
270xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,
280xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
290xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01,
300x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
310x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
320x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
330x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
340x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
350x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
360x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
370x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
380x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
390x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,
40};
41
42static unsigned const char cov_2char[64]={
430x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
440x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
450x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
460x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
470x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
480x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
490x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
500x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
51};
52
53#ifndef NOPROTO
54void fcrypt_body(DES_LONG *out,des_key_schedule ks,
55 DES_LONG Eswap0, DES_LONG Eswap1);
56
57#if defined(PERL5) || defined(FreeBSD) || defined(__OpenBSD__)
58char *des_crypt(const char *buf,const char *salt);
59#else
60char *crypt(const char *buf,const char *salt);
61#endif
62#else
63void fcrypt_body();
64#ifdef PERL5
65char *des_crypt();
66#else
67char *crypt();
68#endif
69#endif
70
71#if defined(PERL5) || defined(FreeBSD) || defined(__OpenBSD__)
72char *des_crypt(buf,salt)
73#else
74char *crypt(buf,salt)
75#endif
76const char *buf;
77const char *salt;
78 {
79 static char buff[14];
80
81 return(des_fcrypt(buf,salt,buff));
82 }
83
84
85char *des_fcrypt(buf,salt,ret)
86const char *buf;
87const char *salt;
88char *ret;
89 {
90 unsigned int i,j,x,y;
91 DES_LONG Eswap0,Eswap1;
92 DES_LONG out[2],ll;
93 des_cblock key;
94 des_key_schedule ks;
95 unsigned char bb[9];
96 unsigned char *b=bb;
97 unsigned char c,u;
98
99 /* eay 25/08/92
100 * If you call crypt("pwd","*") as often happens when you
101 * have * as the pwd field in /etc/passwd, the function
102 * returns *\0XXXXXXXXX
103 * The \0 makes the string look like * so the pwd "*" would
104 * crypt to "*". This was found when replacing the crypt in
105 * our shared libraries. People found that the disabled
106 * accounts effectively had no passwd :-(. */
107 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
108 Eswap0=con_salt[x]<<2;
109 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
110 Eswap1=con_salt[x]<<6;
111
112/* EAY
113r=strlen(buf);
114r=(r+7)/8;
115*/
116 for (i=0; i<8; i++)
117 {
118 c= *(buf++);
119 if (!c) break;
120 key[i]=(c<<1);
121 }
122 for (; i<8; i++)
123 key[i]=0;
124
125 des_set_key_unchecked(&key,ks);
126 fcrypt_body(&(out[0]),ks,Eswap0,Eswap1);
127
128 ll=out[0]; l2c(ll,b);
129 ll=out[1]; l2c(ll,b);
130 y=0;
131 u=0x80;
132 bb[8]=0;
133 for (i=2; i<13; i++)
134 {
135 c=0;
136 for (j=0; j<6; j++)
137 {
138 c<<=1;
139 if (bb[y] & u) c|=1;
140 u>>=1;
141 if (!u)
142 {
143 y++;
144 u=0x80;
145 }
146 }
147 ret[i]=cov_2char[c];
148 }
149 ret[13]='\0';
150 return(ret);
151 }
152
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
deleted file mode 100644
index 22c87f5983..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 compatible
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#ifndef 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 3b681691a9..0000000000
--- a/src/lib/libcrypto/des/ncbc_enc.c
+++ /dev/null
@@ -1,148 +0,0 @@
1/* crypto/des/ncbc_enc.c */
2/*
3 * #included by:
4 * cbc_enc.c (des_cbc_encrypt)
5 * des_enc.c (des_ncbc_encrypt)
6 */
7/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
8 * All rights reserved.
9 *
10 * This package is an SSL implementation written
11 * by Eric Young (eay@cryptsoft.com).
12 * The implementation was written so as to conform with Netscapes SSL.
13 *
14 * This library is free for commercial and non-commercial use as long as
15 * the following conditions are aheared to. The following conditions
16 * apply to all code found in this distribution, be it the RC4, RSA,
17 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
18 * included with this distribution is covered by the same copyright terms
19 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
20 *
21 * Copyright remains Eric Young's, and as such any Copyright notices in
22 * the code are not to be removed.
23 * If this package is used in a product, Eric Young should be given attribution
24 * as the author of the parts of the library used.
25 * This can be in the form of a textual message at program startup or
26 * in documentation (online or textual) provided with the package.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * "This product includes cryptographic software written by
39 * Eric Young (eay@cryptsoft.com)"
40 * The word 'cryptographic' can be left out if the rouines from the library
41 * being used are not cryptographic related :-).
42 * 4. If you include any Windows specific code (or a derivative thereof) from
43 * the apps directory (application code) you must include an acknowledgement:
44 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
45 *
46 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * The licence and distribution terms for any publically available version or
59 * derivative of this code cannot be changed. i.e. this code cannot simply be
60 * copied and put under another distribution licence
61 * [including the GNU Public Licence.]
62 */
63
64#include "des_locl.h"
65
66#ifdef CBC_ENC_C__DONT_UPDATE_IV
67void des_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
68 des_key_schedule schedule, des_cblock *ivec, int enc)
69#else
70void des_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
71 des_key_schedule schedule, des_cblock *ivec, int enc)
72#endif
73 {
74 register DES_LONG tin0,tin1;
75 register DES_LONG tout0,tout1,xor0,xor1;
76 register long l=length;
77 DES_LONG tin[2];
78 unsigned char *iv;
79
80 iv = &(*ivec)[0];
81
82 if (enc)
83 {
84 c2l(iv,tout0);
85 c2l(iv,tout1);
86 for (l-=8; l>=0; l-=8)
87 {
88 c2l(in,tin0);
89 c2l(in,tin1);
90 tin0^=tout0; tin[0]=tin0;
91 tin1^=tout1; tin[1]=tin1;
92 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
93 tout0=tin[0]; l2c(tout0,out);
94 tout1=tin[1]; l2c(tout1,out);
95 }
96 if (l != -8)
97 {
98 c2ln(in,tin0,tin1,l+8);
99 tin0^=tout0; tin[0]=tin0;
100 tin1^=tout1; tin[1]=tin1;
101 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
102 tout0=tin[0]; l2c(tout0,out);
103 tout1=tin[1]; l2c(tout1,out);
104 }
105#ifndef CBC_ENC_C__DONT_UPDATE_IV
106 iv = &(*ivec)[0];
107 l2c(tout0,iv);
108 l2c(tout1,iv);
109#endif
110 }
111 else
112 {
113 c2l(iv,xor0);
114 c2l(iv,xor1);
115 for (l-=8; l>=0; l-=8)
116 {
117 c2l(in,tin0); tin[0]=tin0;
118 c2l(in,tin1); tin[1]=tin1;
119 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
120 tout0=tin[0]^xor0;
121 tout1=tin[1]^xor1;
122 l2c(tout0,out);
123 l2c(tout1,out);
124 xor0=tin0;
125 xor1=tin1;
126 }
127 if (l != -8)
128 {
129 c2l(in,tin0); tin[0]=tin0;
130 c2l(in,tin1); tin[1]=tin1;
131 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
132 tout0=tin[0]^xor0;
133 tout1=tin[1]^xor1;
134 l2cn(tout0,tout1,out,l+8);
135#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 xor0=tin0;
137 xor1=tin1;
138#endif
139 }
140#ifndef CBC_ENC_C__DONT_UPDATE_IV
141 iv = &(*ivec)[0];
142 l2c(xor0,iv);
143 l2c(xor1,iv);
144#endif
145 }
146 tin0=tin1=tout0=tout1=xor0=xor1=0;
147 tin[0]=tin[1]=0;
148 }
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 5f0ec5387f..0000000000
--- a/src/lib/libcrypto/des/qud_cksm.c
+++ /dev/null
@@ -1,129 +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#ifdef _CRAY
84 short *lp;
85#else
86 DES_LONG *lp;
87#endif
88
89 if (out_count < 1) out_count=1;
90 lp = (DES_LONG *) &(output[0])[0];
91
92 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
93 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
94
95 for (i=0; ((i<4)&&(i<out_count)); i++)
96 {
97 cp=input;
98 l=length;
99 while (l > 0)
100 {
101 if (l > 1)
102 {
103 t0= (DES_LONG)(*(cp++));
104 t0|=(DES_LONG)Q_B1(*(cp++));
105 l--;
106 }
107 else
108 t0= (DES_LONG)(*(cp++));
109 l--;
110 /* add */
111 t0+=z0;
112 t0&=0xffffffffL;
113 t1=z1;
114 /* square, well sort of square */
115 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL))
116 &0xffffffffL)%0x7fffffffL;
117 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL;
118 }
119 if (lp != NULL)
120 {
121 /* The MIT library assumes that the checksum is
122 * composed of 2*out_count 32 bit ints */
123 *lp++ = z0;
124 *lp++ = z1;
125 }
126 }
127 return(z0);
128 }
129
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
deleted file mode 100644
index ee1a6c274e..0000000000
--- a/src/lib/libcrypto/des/rand_key.c
+++ /dev/null
@@ -1,73 +0,0 @@
1/* crypto/des/rand_key.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/des.h>
57#include <openssl/rand.h>
58
59void des_random_seed(des_cblock *key)
60 {
61 RAND_seed(key, sizeof(des_cblock));
62 }
63
64int des_random_key(des_cblock *ret)
65 {
66 do
67 {
68 if (RAND_bytes((unsigned char *)ret, sizeof(des_cblock)) != 1)
69 return (0);
70 } while (des_is_weak_key(ret));
71 des_set_odd_parity(ret);
72 return (1);
73 }
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
deleted file mode 100644
index 09afd4fc03..0000000000
--- a/src/lib/libcrypto/des/set_key.c
+++ /dev/null
@@ -1,402 +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
68OPENSSL_GLOBAL int des_check_key=0;
69
70static const unsigned char odd_parity[256]={
71 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
72 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
73 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
74 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
75 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
76 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
77 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
78112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
79128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
80145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
81161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
82176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
83193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
84208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
85224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
86241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
87
88void des_set_odd_parity(des_cblock *key)
89 {
90 int i;
91
92 for (i=0; i<DES_KEY_SZ; i++)
93 (*key)[i]=odd_parity[(*key)[i]];
94 }
95
96int des_check_key_parity(const_des_cblock *key)
97 {
98 int i;
99
100 for (i=0; i<DES_KEY_SZ; i++)
101 {
102 if ((*key)[i] != odd_parity[(*key)[i]])
103 return(0);
104 }
105 return(1);
106 }
107
108/* Weak and semi week keys as take from
109 * %A D.W. Davies
110 * %A W.L. Price
111 * %T Security for Computer Networks
112 * %I John Wiley & Sons
113 * %D 1984
114 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
115 * (and actual cblock values).
116 */
117#define NUM_WEAK_KEY 16
118static des_cblock weak_keys[NUM_WEAK_KEY]={
119 /* weak keys */
120 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
121 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
122 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
123 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
124 /* semi-weak keys */
125 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
126 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
127 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
128 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
129 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
130 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
131 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
132 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
133 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
134 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
135 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
136 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
137
138int des_is_weak_key(const_des_cblock *key)
139 {
140 int i;
141
142 for (i=0; i<NUM_WEAK_KEY; i++)
143 /* Added == 0 to comparison, I obviously don't run
144 * this section very often :-(, thanks to
145 * engineering@MorningStar.Com for the fix
146 * eay 93/06/29
147 * Another problem, I was comparing only the first 4
148 * bytes, 97/03/18 */
149 if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1);
150 return(0);
151 }
152
153/* NOW DEFINED IN des_local.h
154 * See ecb_encrypt.c for a pseudo description of these macros.
155 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
156 * (b)^=(t),\
157 * (a)=((a)^((t)<<(n))))
158 */
159
160#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
161 (a)=(a)^(t)^(t>>(16-(n))))
162
163static const DES_LONG des_skb[8][64]={
164 {
165 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
166 0x00000000L,0x00000010L,0x20000000L,0x20000010L,
167 0x00010000L,0x00010010L,0x20010000L,0x20010010L,
168 0x00000800L,0x00000810L,0x20000800L,0x20000810L,
169 0x00010800L,0x00010810L,0x20010800L,0x20010810L,
170 0x00000020L,0x00000030L,0x20000020L,0x20000030L,
171 0x00010020L,0x00010030L,0x20010020L,0x20010030L,
172 0x00000820L,0x00000830L,0x20000820L,0x20000830L,
173 0x00010820L,0x00010830L,0x20010820L,0x20010830L,
174 0x00080000L,0x00080010L,0x20080000L,0x20080010L,
175 0x00090000L,0x00090010L,0x20090000L,0x20090010L,
176 0x00080800L,0x00080810L,0x20080800L,0x20080810L,
177 0x00090800L,0x00090810L,0x20090800L,0x20090810L,
178 0x00080020L,0x00080030L,0x20080020L,0x20080030L,
179 0x00090020L,0x00090030L,0x20090020L,0x20090030L,
180 0x00080820L,0x00080830L,0x20080820L,0x20080830L,
181 0x00090820L,0x00090830L,0x20090820L,0x20090830L,
182 },{
183 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
184 0x00000000L,0x02000000L,0x00002000L,0x02002000L,
185 0x00200000L,0x02200000L,0x00202000L,0x02202000L,
186 0x00000004L,0x02000004L,0x00002004L,0x02002004L,
187 0x00200004L,0x02200004L,0x00202004L,0x02202004L,
188 0x00000400L,0x02000400L,0x00002400L,0x02002400L,
189 0x00200400L,0x02200400L,0x00202400L,0x02202400L,
190 0x00000404L,0x02000404L,0x00002404L,0x02002404L,
191 0x00200404L,0x02200404L,0x00202404L,0x02202404L,
192 0x10000000L,0x12000000L,0x10002000L,0x12002000L,
193 0x10200000L,0x12200000L,0x10202000L,0x12202000L,
194 0x10000004L,0x12000004L,0x10002004L,0x12002004L,
195 0x10200004L,0x12200004L,0x10202004L,0x12202004L,
196 0x10000400L,0x12000400L,0x10002400L,0x12002400L,
197 0x10200400L,0x12200400L,0x10202400L,0x12202400L,
198 0x10000404L,0x12000404L,0x10002404L,0x12002404L,
199 0x10200404L,0x12200404L,0x10202404L,0x12202404L,
200 },{
201 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
202 0x00000000L,0x00000001L,0x00040000L,0x00040001L,
203 0x01000000L,0x01000001L,0x01040000L,0x01040001L,
204 0x00000002L,0x00000003L,0x00040002L,0x00040003L,
205 0x01000002L,0x01000003L,0x01040002L,0x01040003L,
206 0x00000200L,0x00000201L,0x00040200L,0x00040201L,
207 0x01000200L,0x01000201L,0x01040200L,0x01040201L,
208 0x00000202L,0x00000203L,0x00040202L,0x00040203L,
209 0x01000202L,0x01000203L,0x01040202L,0x01040203L,
210 0x08000000L,0x08000001L,0x08040000L,0x08040001L,
211 0x09000000L,0x09000001L,0x09040000L,0x09040001L,
212 0x08000002L,0x08000003L,0x08040002L,0x08040003L,
213 0x09000002L,0x09000003L,0x09040002L,0x09040003L,
214 0x08000200L,0x08000201L,0x08040200L,0x08040201L,
215 0x09000200L,0x09000201L,0x09040200L,0x09040201L,
216 0x08000202L,0x08000203L,0x08040202L,0x08040203L,
217 0x09000202L,0x09000203L,0x09040202L,0x09040203L,
218 },{
219 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
220 0x00000000L,0x00100000L,0x00000100L,0x00100100L,
221 0x00000008L,0x00100008L,0x00000108L,0x00100108L,
222 0x00001000L,0x00101000L,0x00001100L,0x00101100L,
223 0x00001008L,0x00101008L,0x00001108L,0x00101108L,
224 0x04000000L,0x04100000L,0x04000100L,0x04100100L,
225 0x04000008L,0x04100008L,0x04000108L,0x04100108L,
226 0x04001000L,0x04101000L,0x04001100L,0x04101100L,
227 0x04001008L,0x04101008L,0x04001108L,0x04101108L,
228 0x00020000L,0x00120000L,0x00020100L,0x00120100L,
229 0x00020008L,0x00120008L,0x00020108L,0x00120108L,
230 0x00021000L,0x00121000L,0x00021100L,0x00121100L,
231 0x00021008L,0x00121008L,0x00021108L,0x00121108L,
232 0x04020000L,0x04120000L,0x04020100L,0x04120100L,
233 0x04020008L,0x04120008L,0x04020108L,0x04120108L,
234 0x04021000L,0x04121000L,0x04021100L,0x04121100L,
235 0x04021008L,0x04121008L,0x04021108L,0x04121108L,
236 },{
237 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
238 0x00000000L,0x10000000L,0x00010000L,0x10010000L,
239 0x00000004L,0x10000004L,0x00010004L,0x10010004L,
240 0x20000000L,0x30000000L,0x20010000L,0x30010000L,
241 0x20000004L,0x30000004L,0x20010004L,0x30010004L,
242 0x00100000L,0x10100000L,0x00110000L,0x10110000L,
243 0x00100004L,0x10100004L,0x00110004L,0x10110004L,
244 0x20100000L,0x30100000L,0x20110000L,0x30110000L,
245 0x20100004L,0x30100004L,0x20110004L,0x30110004L,
246 0x00001000L,0x10001000L,0x00011000L,0x10011000L,
247 0x00001004L,0x10001004L,0x00011004L,0x10011004L,
248 0x20001000L,0x30001000L,0x20011000L,0x30011000L,
249 0x20001004L,0x30001004L,0x20011004L,0x30011004L,
250 0x00101000L,0x10101000L,0x00111000L,0x10111000L,
251 0x00101004L,0x10101004L,0x00111004L,0x10111004L,
252 0x20101000L,0x30101000L,0x20111000L,0x30111000L,
253 0x20101004L,0x30101004L,0x20111004L,0x30111004L,
254 },{
255 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
256 0x00000000L,0x08000000L,0x00000008L,0x08000008L,
257 0x00000400L,0x08000400L,0x00000408L,0x08000408L,
258 0x00020000L,0x08020000L,0x00020008L,0x08020008L,
259 0x00020400L,0x08020400L,0x00020408L,0x08020408L,
260 0x00000001L,0x08000001L,0x00000009L,0x08000009L,
261 0x00000401L,0x08000401L,0x00000409L,0x08000409L,
262 0x00020001L,0x08020001L,0x00020009L,0x08020009L,
263 0x00020401L,0x08020401L,0x00020409L,0x08020409L,
264 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
265 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
266 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
267 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
268 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
269 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
270 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
271 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
272 },{
273 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
274 0x00000000L,0x00000100L,0x00080000L,0x00080100L,
275 0x01000000L,0x01000100L,0x01080000L,0x01080100L,
276 0x00000010L,0x00000110L,0x00080010L,0x00080110L,
277 0x01000010L,0x01000110L,0x01080010L,0x01080110L,
278 0x00200000L,0x00200100L,0x00280000L,0x00280100L,
279 0x01200000L,0x01200100L,0x01280000L,0x01280100L,
280 0x00200010L,0x00200110L,0x00280010L,0x00280110L,
281 0x01200010L,0x01200110L,0x01280010L,0x01280110L,
282 0x00000200L,0x00000300L,0x00080200L,0x00080300L,
283 0x01000200L,0x01000300L,0x01080200L,0x01080300L,
284 0x00000210L,0x00000310L,0x00080210L,0x00080310L,
285 0x01000210L,0x01000310L,0x01080210L,0x01080310L,
286 0x00200200L,0x00200300L,0x00280200L,0x00280300L,
287 0x01200200L,0x01200300L,0x01280200L,0x01280300L,
288 0x00200210L,0x00200310L,0x00280210L,0x00280310L,
289 0x01200210L,0x01200310L,0x01280210L,0x01280310L,
290 },{
291 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
292 0x00000000L,0x04000000L,0x00040000L,0x04040000L,
293 0x00000002L,0x04000002L,0x00040002L,0x04040002L,
294 0x00002000L,0x04002000L,0x00042000L,0x04042000L,
295 0x00002002L,0x04002002L,0x00042002L,0x04042002L,
296 0x00000020L,0x04000020L,0x00040020L,0x04040020L,
297 0x00000022L,0x04000022L,0x00040022L,0x04040022L,
298 0x00002020L,0x04002020L,0x00042020L,0x04042020L,
299 0x00002022L,0x04002022L,0x00042022L,0x04042022L,
300 0x00000800L,0x04000800L,0x00040800L,0x04040800L,
301 0x00000802L,0x04000802L,0x00040802L,0x04040802L,
302 0x00002800L,0x04002800L,0x00042800L,0x04042800L,
303 0x00002802L,0x04002802L,0x00042802L,0x04042802L,
304 0x00000820L,0x04000820L,0x00040820L,0x04040820L,
305 0x00000822L,0x04000822L,0x00040822L,0x04040822L,
306 0x00002820L,0x04002820L,0x00042820L,0x04042820L,
307 0x00002822L,0x04002822L,0x00042822L,0x04042822L,
308 }};
309
310int des_set_key(const_des_cblock *key, des_key_schedule schedule)
311 {
312 if (des_check_key)
313 {
314 return des_set_key_checked(key, schedule);
315 }
316 else
317 {
318 des_set_key_unchecked(key, schedule);
319 return 0;
320 }
321 }
322
323/* return 0 if key parity is odd (correct),
324 * return -1 if key parity error,
325 * return -2 if illegal weak key.
326 */
327int des_set_key_checked(const_des_cblock *key, des_key_schedule schedule)
328 {
329 if (!des_check_key_parity(key))
330 return(-1);
331 if (des_is_weak_key(key))
332 return(-2);
333 des_set_key_unchecked(key, schedule);
334 return 0;
335 }
336
337void des_set_key_unchecked(const_des_cblock *key, des_key_schedule schedule)
338 {
339 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
340 register DES_LONG c,d,t,s,t2;
341 register const unsigned char *in;
342 register DES_LONG *k;
343 register int i;
344
345 k = &schedule->ks.deslong[0];
346 in = &(*key)[0];
347
348 c2l(in,c);
349 c2l(in,d);
350
351 /* do PC1 in 47 simple operations :-)
352 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
353 * for the inspiration. :-) */
354 PERM_OP (d,c,t,4,0x0f0f0f0fL);
355 HPERM_OP(c,t,-2,0xcccc0000L);
356 HPERM_OP(d,t,-2,0xcccc0000L);
357 PERM_OP (d,c,t,1,0x55555555L);
358 PERM_OP (c,d,t,8,0x00ff00ffL);
359 PERM_OP (d,c,t,1,0x55555555L);
360 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
361 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
362 c&=0x0fffffffL;
363
364 for (i=0; i<ITERATIONS; i++)
365 {
366 if (shifts2[i])
367 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
368 else
369 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
370 c&=0x0fffffffL;
371 d&=0x0fffffffL;
372 /* could be a few less shifts but I am to lazy at this
373 * point in time to investigate */
374 s= des_skb[0][ (c )&0x3f ]|
375 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
376 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
377 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
378 ((c>>22L)&0x38)];
379 t= des_skb[4][ (d )&0x3f ]|
380 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
381 des_skb[6][ (d>>15L)&0x3f ]|
382 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
383
384 /* table contained 0213 4657 */
385 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
386 *(k++)=ROTATE(t2,30)&0xffffffffL;
387
388 t2=((s>>16L)|(t&0xffff0000L));
389 *(k++)=ROTATE(t2,26)&0xffffffffL;
390 }
391 }
392
393int des_key_sched(const_des_cblock *key, des_key_schedule schedule)
394 {
395 return(des_set_key(key,schedule));
396 }
397
398#undef des_fixup_key_parity
399void des_fixup_key_parity(des_cblock *key)
400 {
401 des_set_odd_parity(key);
402 }
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 c6abb87201..0000000000
--- a/src/lib/libcrypto/des/str2key.c
+++ /dev/null
@@ -1,155 +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
61void des_string_to_key(const char *str, des_cblock *key)
62 {
63 des_key_schedule ks;
64 int i,length;
65 register unsigned char j;
66
67 memset(key,0,8);
68 length=strlen(str);
69#ifdef OLD_STR_TO_KEY
70 for (i=0; i<length; i++)
71 (*key)[i%8]^=(str[i]<<1);
72#else /* MIT COMPATIBLE */
73 for (i=0; i<length; i++)
74 {
75 j=str[i];
76 if ((i%16) < 8)
77 (*key)[i%8]^=(j<<1);
78 else
79 {
80 /* Reverse the bit order 05/05/92 eay */
81 j=((j<<4)&0xf0)|((j>>4)&0x0f);
82 j=((j<<2)&0xcc)|((j>>2)&0x33);
83 j=((j<<1)&0xaa)|((j>>1)&0x55);
84 (*key)[7-(i%8)]^=j;
85 }
86 }
87#endif
88 des_set_odd_parity(key);
89 des_set_key_unchecked(key,ks);
90 des_cbc_cksum((const unsigned char*)str,key,length,ks,key);
91 memset(ks,0,sizeof(ks));
92 des_set_odd_parity(key);
93 }
94
95void des_string_to_2keys(const char *str, des_cblock *key1, des_cblock *key2)
96 {
97 des_key_schedule ks;
98 int i,length;
99 register unsigned char j;
100
101 memset(key1,0,8);
102 memset(key2,0,8);
103 length=strlen(str);
104#ifdef OLD_STR_TO_KEY
105 if (length <= 8)
106 {
107 for (i=0; i<length; i++)
108 {
109 (*key2)[i]=(*key1)[i]=(str[i]<<1);
110 }
111 }
112 else
113 {
114 for (i=0; i<length; i++)
115 {
116 if ((i/8)&1)
117 (*key2)[i%8]^=(str[i]<<1);
118 else
119 (*key1)[i%8]^=(str[i]<<1);
120 }
121 }
122#else /* MIT COMPATIBLE */
123 for (i=0; i<length; i++)
124 {
125 j=str[i];
126 if ((i%32) < 16)
127 {
128 if ((i%16) < 8)
129 (*key1)[i%8]^=(j<<1);
130 else
131 (*key2)[i%8]^=(j<<1);
132 }
133 else
134 {
135 j=((j<<4)&0xf0)|((j>>4)&0x0f);
136 j=((j<<2)&0xcc)|((j>>2)&0x33);
137 j=((j<<1)&0xaa)|((j>>1)&0x55);
138 if ((i%16) < 8)
139 (*key1)[7-(i%8)]^=j;
140 else
141 (*key2)[7-(i%8)]^=j;
142 }
143 }
144 if (length <= 8) memcpy(key2,key1,8);
145#endif
146 des_set_odd_parity(key1);
147 des_set_odd_parity(key2);
148 des_set_key_unchecked(key1,ks);
149 des_cbc_cksum((const unsigned char*)str,key1,length,ks,key1);
150 des_set_key_unchecked(key2,ks);
151 des_cbc_cksum((const unsigned char*)str,key2,length,ks,key2);
152 memset(ks,0,sizeof(ks));
153 des_set_odd_parity(key1);
154 des_set_odd_parity(key2);
155 }
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 c15b2ad483..0000000000
--- a/src/lib/libcrypto/dh/dh.h
+++ /dev/null
@@ -1,201 +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#include <openssl/crypto.h>
72
73#define DH_FLAG_CACHE_MONT_P 0x01
74
75typedef struct dh_st DH;
76
77typedef struct dh_method {
78 const char *name;
79 /* Methods here */
80 int (*generate_key)(DH *dh);
81 int (*compute_key)(unsigned char *key,BIGNUM *pub_key,DH *dh);
82 int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
83 const BIGNUM *m, BN_CTX *ctx,
84 BN_MONT_CTX *m_ctx); /* Can be null */
85
86 int (*init)(DH *dh);
87 int (*finish)(DH *dh);
88 int flags;
89 char *app_data;
90} DH_METHOD;
91
92struct dh_st
93 {
94 /* This first argument is used to pick up errors when
95 * a DH is passed instead of a EVP_PKEY */
96 int pad;
97 int version;
98 BIGNUM *p;
99 BIGNUM *g;
100 int length; /* optional */
101 BIGNUM *pub_key; /* g^x */
102 BIGNUM *priv_key; /* x */
103
104 int flags;
105 char *method_mont_p;
106 /* Place holders if we want to do X9.42 DH */
107 BIGNUM *q;
108 BIGNUM *j;
109 unsigned char *seed;
110 int seedlen;
111 BIGNUM *counter;
112
113 int references;
114 CRYPTO_EX_DATA ex_data;
115 DH_METHOD *meth;
116 };
117
118#define DH_GENERATOR_2 2
119/* #define DH_GENERATOR_3 3 */
120#define DH_GENERATOR_5 5
121
122/* DH_check error codes */
123#define DH_CHECK_P_NOT_PRIME 0x01
124#define DH_CHECK_P_NOT_SAFE_PRIME 0x02
125#define DH_UNABLE_TO_CHECK_GENERATOR 0x04
126#define DH_NOT_SUITABLE_GENERATOR 0x08
127
128/* primes p where (p-1)/2 is prime too are called "safe"; we define
129 this for backward compatibility: */
130#define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME
131
132#define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \
133 (char *(*)())d2i_DHparams,(char *)(x))
134#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \
135 (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x))
136#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \
137 (unsigned char *)(x))
138#define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \
139 (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x))
140#ifdef __cplusplus
141#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \
142 (unsigned char *)(x))
143#else
144#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \
145 (unsigned char *)(x))
146#endif
147
148DH_METHOD *DH_OpenSSL(void);
149
150void DH_set_default_method(DH_METHOD *meth);
151DH_METHOD *DH_get_default_method(void);
152DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
153DH *DH_new_method(DH_METHOD *meth);
154
155DH * DH_new(void);
156void DH_free(DH *dh);
157int DH_size(DH *dh);
158int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
159 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
160int DH_set_ex_data(DH *d, int idx, void *arg);
161void *DH_get_ex_data(DH *d, int idx);
162DH * DH_generate_parameters(int prime_len,int generator,
163 void (*callback)(int,int,void *),void *cb_arg);
164int DH_check(DH *dh,int *codes);
165int DH_generate_key(DH *dh);
166int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh);
167DH * d2i_DHparams(DH **a,unsigned char **pp, long length);
168int i2d_DHparams(DH *a,unsigned char **pp);
169#ifndef NO_FP_API
170int DHparams_print_fp(FILE *fp, DH *x);
171#endif
172#ifdef HEADER_BIO_H
173int DHparams_print(BIO *bp, DH *x);
174#else
175int DHparams_print(char *bp, DH *x);
176#endif
177void ERR_load_DH_strings(void );
178
179/* BEGIN ERROR CODES */
180/* The following lines are auto generated by the script mkerr.pl. Any changes
181 * made after this point may be overwritten when the script is next run.
182 */
183
184/* Error codes for the DH functions. */
185
186/* Function codes. */
187#define DH_F_DHPARAMS_PRINT 100
188#define DH_F_DHPARAMS_PRINT_FP 101
189#define DH_F_DH_COMPUTE_KEY 102
190#define DH_F_DH_GENERATE_KEY 103
191#define DH_F_DH_GENERATE_PARAMETERS 104
192#define DH_F_DH_NEW 105
193
194/* Reason codes. */
195#define DH_R_NO_PRIVATE_VALUE 100
196
197#ifdef __cplusplus
198}
199#endif
200#endif
201
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c
deleted file mode 100644
index 7e5cfd8bfc..0000000000
--- a/src/lib/libcrypto/dh/dh_check.c
+++ /dev/null
@@ -1,120 +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 safe 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#if 0
92 else if (BN_is_word(dh->g,DH_GENERATOR_3))
93 {
94 l=BN_mod_word(dh->p,12);
95 if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;
96 }
97#endif
98 else if (BN_is_word(dh->g,DH_GENERATOR_5))
99 {
100 l=BN_mod_word(dh->p,10);
101 if ((l != 3) && (l != 7))
102 *ret|=DH_NOT_SUITABLE_GENERATOR;
103 }
104 else
105 *ret|=DH_UNABLE_TO_CHECK_GENERATOR;
106
107 if (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL))
108 *ret|=DH_CHECK_P_NOT_PRIME;
109 else
110 {
111 if (!BN_rshift1(q,dh->p)) goto err;
112 if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))
113 *ret|=DH_CHECK_P_NOT_SAFE_PRIME;
114 }
115 ok=1;
116err:
117 if (ctx != NULL) BN_CTX_free(ctx);
118 if (q != NULL) BN_free(q);
119 return(ok);
120 }
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c
deleted file mode 100644
index ff2d1684c2..0000000000
--- a/src/lib/libcrypto/dh/dh_err.c
+++ /dev/null
@@ -1,99 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/dh.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA DH_str_functs[]=
68 {
69{ERR_PACK(0,DH_F_DHPARAMS_PRINT,0), "DHparams_print"},
70{ERR_PACK(0,DH_F_DHPARAMS_PRINT_FP,0), "DHparams_print_fp"},
71{ERR_PACK(0,DH_F_DH_COMPUTE_KEY,0), "DH_compute_key"},
72{ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"},
73{ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"},
74{ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"},
75{0,NULL}
76 };
77
78static ERR_STRING_DATA DH_str_reasons[]=
79 {
80{DH_R_NO_PRIVATE_VALUE ,"no private value"},
81{0,NULL}
82 };
83
84#endif
85
86void ERR_load_DH_strings(void)
87 {
88 static int init=1;
89
90 if (init)
91 {
92 init=0;
93#ifndef NO_ERR
94 ERR_load_strings(ERR_LIB_DH,DH_str_functs);
95 ERR_load_strings(ERR_LIB_DH,DH_str_reasons);
96#endif
97
98 }
99 }
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c
deleted file mode 100644
index 7a6a38fbb4..0000000000
--- a/src/lib/libcrypto/dh/dh_gen.c
+++ /dev/null
@@ -1,153 +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 safe 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 safe 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 BN_CTX_start(ctx);
99 t1 = BN_CTX_get(ctx);
100 t2 = BN_CTX_get(ctx);
101 if (t1 == NULL || t2 == NULL) goto err;
102
103 if (generator == DH_GENERATOR_2)
104 {
105 BN_set_word(t1,24);
106 BN_set_word(t2,11);
107 g=2;
108 }
109#ifdef undef /* does not work for safe primes */
110 else if (generator == DH_GENERATOR_3)
111 {
112 BN_set_word(t1,12);
113 BN_set_word(t2,5);
114 g=3;
115 }
116#endif
117 else if (generator == DH_GENERATOR_5)
118 {
119 BN_set_word(t1,10);
120 BN_set_word(t2,3);
121 /* BN_set_word(t3,7); just have to miss
122 * out on these ones :-( */
123 g=5;
124 }
125 else
126 g=generator;
127
128 p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg);
129 if (p == NULL) goto err;
130 if (callback != NULL) callback(3,0,cb_arg);
131 ret->p=p;
132 ret->g=BN_new();
133 if (!BN_set_word(ret->g,g)) goto err;
134 ok=1;
135err:
136 if (ok == -1)
137 {
138 DHerr(DH_F_DH_GENERATE_PARAMETERS,ERR_R_BN_LIB);
139 ok=0;
140 }
141
142 if (ctx != NULL)
143 {
144 BN_CTX_end(ctx);
145 BN_CTX_free(ctx);
146 }
147 if (!ok && (ret != NULL))
148 {
149 DH_free(ret);
150 ret=NULL;
151 }
152 return(ret);
153 }
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
deleted file mode 100644
index 0c7eeaf260..0000000000
--- a/src/lib/libcrypto/dh/dh_key.c
+++ /dev/null
@@ -1,211 +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
65static int generate_key(DH *dh);
66static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
67static int dh_bn_mod_exp(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
68 const BIGNUM *m, BN_CTX *ctx,
69 BN_MONT_CTX *m_ctx);
70static int dh_init(DH *dh);
71static int dh_finish(DH *dh);
72
73int DH_generate_key(DH *dh)
74 {
75 return dh->meth->generate_key(dh);
76 }
77
78int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
79 {
80 return dh->meth->compute_key(key, pub_key, dh);
81 }
82
83static DH_METHOD dh_ossl = {
84"OpenSSL DH Method",
85generate_key,
86compute_key,
87dh_bn_mod_exp,
88dh_init,
89dh_finish,
900,
91NULL
92};
93
94DH_METHOD *DH_OpenSSL(void)
95{
96 return &dh_ossl;
97}
98
99static int generate_key(DH *dh)
100 {
101 int ok=0;
102 unsigned int i;
103 BN_CTX ctx;
104 BN_MONT_CTX *mont;
105 BIGNUM *pub_key=NULL,*priv_key=NULL;
106
107 BN_CTX_init(&ctx);
108
109 if (dh->priv_key == NULL)
110 {
111 i=dh->length;
112 if (i == 0)
113 {
114 /* Make the number p-1 bits long */
115 i=BN_num_bits(dh->p)-1;
116 }
117 priv_key=BN_new();
118 if (priv_key == NULL) goto err;
119 if (!BN_rand(priv_key,i,0,0)) goto err;
120 }
121 else
122 priv_key=dh->priv_key;
123
124 if (dh->pub_key == NULL)
125 {
126 pub_key=BN_new();
127 if (pub_key == NULL) goto err;
128 }
129 else
130 pub_key=dh->pub_key;
131
132 if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
133 {
134 if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
135 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
136 dh->p,&ctx)) goto err;
137 }
138 mont=(BN_MONT_CTX *)dh->method_mont_p;
139
140 if (!dh->meth->bn_mod_exp(dh, pub_key,dh->g,priv_key,dh->p,&ctx,mont))
141 goto err;
142
143 dh->pub_key=pub_key;
144 dh->priv_key=priv_key;
145 ok=1;
146err:
147 if (ok != 1)
148 DHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB);
149
150 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
151 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
152 BN_CTX_free(&ctx);
153 return(ok);
154 }
155
156static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
157 {
158 BN_CTX ctx;
159 BN_MONT_CTX *mont;
160 BIGNUM *tmp;
161 int ret= -1;
162
163 BN_CTX_init(&ctx);
164 BN_CTX_start(&ctx);
165 tmp = BN_CTX_get(&ctx);
166
167 if (dh->priv_key == NULL)
168 {
169 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
170 goto err;
171 }
172 if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
173 {
174 if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
175 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
176 dh->p,&ctx)) goto err;
177 }
178
179 mont=(BN_MONT_CTX *)dh->method_mont_p;
180 if (!dh->meth->bn_mod_exp(dh, tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
181 {
182 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
183 goto err;
184 }
185
186 ret=BN_bn2bin(tmp,key);
187err:
188 BN_CTX_end(&ctx);
189 BN_CTX_free(&ctx);
190 return(ret);
191 }
192
193static int dh_bn_mod_exp(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
194 const BIGNUM *m, BN_CTX *ctx,
195 BN_MONT_CTX *m_ctx)
196{
197 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
198}
199
200static int dh_init(DH *dh)
201{
202 dh->flags |= DH_FLAG_CACHE_MONT_P;
203 return(1);
204}
205
206static int dh_finish(DH *dh)
207{
208 if(dh->method_mont_p)
209 BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
210 return(1);
211}
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
deleted file mode 100644
index 6c21463028..0000000000
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ /dev/null
@@ -1,187 +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
66static DH_METHOD *default_DH_method;
67static int dh_meth_num = 0;
68static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dh_meth = NULL;
69
70void DH_set_default_method(DH_METHOD *meth)
71{
72 default_DH_method = meth;
73}
74
75DH_METHOD *DH_get_default_method(void)
76{
77 if(!default_DH_method) default_DH_method = DH_OpenSSL();
78 return default_DH_method;
79}
80
81DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth)
82{
83 DH_METHOD *mtmp;
84 mtmp = dh->meth;
85 if (mtmp->finish) mtmp->finish(dh);
86 dh->meth = meth;
87 if (meth->init) meth->init(dh);
88 return mtmp;
89}
90
91DH *DH_new(void)
92{
93 return DH_new_method(NULL);
94}
95
96DH *DH_new_method(DH_METHOD *meth)
97 {
98 DH *ret;
99 ret=(DH *)Malloc(sizeof(DH));
100
101 if (ret == NULL)
102 {
103 DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE);
104 return(NULL);
105 }
106 if(!default_DH_method) default_DH_method = DH_OpenSSL();
107 if(meth) ret->meth = meth;
108 else ret->meth = default_DH_method;
109 ret->pad=0;
110 ret->version=0;
111 ret->p=NULL;
112 ret->g=NULL;
113 ret->length=0;
114 ret->pub_key=NULL;
115 ret->priv_key=NULL;
116 ret->q=NULL;
117 ret->j=NULL;
118 ret->seed = NULL;
119 ret->seedlen = 0;
120 ret->counter = NULL;
121 ret->method_mont_p=NULL;
122 ret->references = 1;
123 ret->flags=ret->meth->flags;
124 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
125 {
126 Free(ret);
127 ret=NULL;
128 }
129 else
130 CRYPTO_new_ex_data(dh_meth,ret,&ret->ex_data);
131 return(ret);
132 }
133
134void DH_free(DH *r)
135 {
136 int i;
137 if(r == NULL) return;
138 i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
139#ifdef REF_PRINT
140 REF_PRINT("DH",r);
141#endif
142 if (i > 0) return;
143#ifdef REF_CHECK
144 if (i < 0)
145 {
146 fprintf(stderr,"DH_free, bad reference count\n");
147 abort();
148 }
149#endif
150
151 CRYPTO_free_ex_data(dh_meth, r, &r->ex_data);
152
153 if(r->meth->finish) r->meth->finish(r);
154
155 if (r->p != NULL) BN_clear_free(r->p);
156 if (r->g != NULL) BN_clear_free(r->g);
157 if (r->q != NULL) BN_clear_free(r->q);
158 if (r->j != NULL) BN_clear_free(r->j);
159 if (r->seed) Free(r->seed);
160 if (r->counter != NULL) BN_clear_free(r->counter);
161 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
162 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
163 Free(r);
164 }
165
166int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
167 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
168 {
169 dh_meth_num++;
170 return(CRYPTO_get_ex_new_index(dh_meth_num-1,
171 &dh_meth,argl,argp,new_func,dup_func,free_func));
172 }
173
174int DH_set_ex_data(DH *d, int idx, void *arg)
175 {
176 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
177 }
178
179void *DH_get_ex_data(DH *d, int idx)
180 {
181 return(CRYPTO_get_ex_data(&d->ex_data,idx));
182 }
183
184int DH_size(DH *dh)
185 {
186 return(BN_num_bytes(dh->p));
187 }
diff --git a/src/lib/libcrypto/doc/DH_generate_key.pod b/src/lib/libcrypto/doc/DH_generate_key.pod
deleted file mode 100644
index 81f09fdf45..0000000000
--- a/src/lib/libcrypto/doc/DH_generate_key.pod
+++ /dev/null
@@ -1,50 +0,0 @@
1=pod
2
3=head1 NAME
4
5DH_generate_key, DH_compute_key - perform Diffie-Hellman key exchange
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_generate_key(DH *dh);
12
13 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
14
15=head1 DESCRIPTION
16
17DH_generate_key() performs the first step of a Diffie-Hellman key
18exchange by generating private and public DH values. By calling
19DH_compute_key(), these are combined with the other party's public
20value to compute the shared key.
21
22DH_generate_key() expects B<dh> to contain the shared parameters
23B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
24unless B<dh-E<gt>priv_key> is already set, and computes the
25corresponding public value B<dh-E<gt>pub_key>, which can then be
26published.
27
28DH_compute_key() computes the shared secret from the private DH value
29in B<dh> and the other party's public value in B<pub_key> and stores
30it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
31
32=head1 RETURN VALUES
33
34DH_generate_key() returns 1 on success, 0 otherwise.
35
36DH_compute_key() returns the size of the shared secret on success, -1
37on error.
38
39The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
40
41=head1 SEE ALSO
42
43L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<DH_size(3)|DH_size(3)>
44
45=head1 HISTORY
46
47DH_generate_key() and DH_compute_key() are available in all versions
48of SSLeay and OpenSSL.
49
50=cut
diff --git a/src/lib/libcrypto/doc/DH_generate_parameters.pod b/src/lib/libcrypto/doc/DH_generate_parameters.pod
deleted file mode 100644
index 4a2d653758..0000000000
--- a/src/lib/libcrypto/doc/DH_generate_parameters.pod
+++ /dev/null
@@ -1,72 +0,0 @@
1=pod
2
3=head1 NAME
4
5DH_generate_parameters, DH_check - generate and check Diffie-Hellman parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH *DH_generate_parameters(int prime_len, int generator,
12 void (*callback)(int, int, void *), void *cb_arg);
13
14 int DH_check(DH *dh, int *codes);
15
16=head1 DESCRIPTION
17
18DH_generate_parameters() generates Diffie-Hellman parameters that can
19be shared among a group of users, and returns them in a newly
20allocated B<DH> structure. The pseudo-random number generator must be
21seeded prior to calling DH_generate_parameters().
22
23B<prime_len> is the length in bits of the safe prime to be generated.
24B<generator> is a small number E<gt> 1, typically 2 or 5.
25
26A callback function may be used to provide feedback about the progress
27of the key generation. If B<callback> is not B<NULL>, it will be
28called as described in L<BN_generate_prime(3)|BN_generate_prime(3)> while a random prime
29number is generated, and when a prime has been found, B<callback(3,
300, cb_arg)> is called.
31
32DH_check() validates Diffie-Hellman parameters. It checks that B<p> is
33a safe prime, and that B<g> is a suitable generator. In the case of an
34error, the bit flags DH_CHECK_P_NOT_SAFE_PRIME or
35DH_NOT_SUITABLE_GENERATOR are set in B<*codes>.
36DH_UNABLE_TO_CHECK_GENERATOR is set if the generator cannot be
37checked, i.e. it does not equal 2 or 5.
38
39=head1 RETURN VALUES
40
41DH_generate_parameters() returns a pointer to the DH structure, or
42NULL if the parameter generation fails. The error codes can be
43obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
44
45DH_check() returns 1 if the check could be performed, 0 otherwise.
46
47=head1 NOTES
48
49DH_generate_parameters() may run for several hours before finding a
50suitable prime.
51
52The parameters generated by DH_generate_parameters() are not to be
53used in signature schemes.
54
55=head1 BUGS
56
57If B<generator> is not 2 or 5, B<dh-E<gt>g>=B<generator> is not
58a usable generator.
59
60=head1 SEE ALSO
61
62L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<DH_free(3)|DH_free(3)>
63
64=head1 HISTORY
65
66DH_check() is available in all versions of SSLeay and OpenSSL.
67The B<cb_arg> argument to DH_generate_parameters() was added in SSLeay 0.9.0.
68
69In versions before OpenSSL 0.9.5, DH_CHECK_P_NOT_STRONG_PRIME is used
70instead of DH_CHECK_P_NOT_SAFE_PRIME.
71
72=cut
diff --git a/src/lib/libcrypto/doc/DH_get_ex_new_index.pod b/src/lib/libcrypto/doc/DH_get_ex_new_index.pod
deleted file mode 100644
index 82e2548bcd..0000000000
--- a/src/lib/libcrypto/doc/DH_get_ex_new_index.pod
+++ /dev/null
@@ -1,36 +0,0 @@
1=pod
2
3=head1 NAME
4
5DH_get_ex_new_index, DH_set_ex_data, DH_get_ex_data - add application specific data to DH structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int DH_set_ex_data(DH *d, int idx, void *arg);
17
18 char *DH_get_ex_data(DH *d, int idx);
19
20=head1 DESCRIPTION
21
22These functions handle application specific data in DH
23structures. Their usage is identical to that of
24RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
25as described in L<RSA_get_ex_new_index(3)>.
26
27=head1 SEE ALSO
28
29L<RSA_get_ex_new_index()|RSA_get_ex_new_index()>, L<dh(3)|dh(3)>
30
31=head1 HISTORY
32
33DH_get_ex_new_index(), DH_set_ex_data() and DH_get_ex_data() are
34available since OpenSSL 0.9.5.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DH_new.pod b/src/lib/libcrypto/doc/DH_new.pod
deleted file mode 100644
index 60c930093e..0000000000
--- a/src/lib/libcrypto/doc/DH_new.pod
+++ /dev/null
@@ -1,40 +0,0 @@
1=pod
2
3=head1 NAME
4
5DH_new, DH_free - allocate and free DH objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH* DH_new(void);
12
13 void DH_free(DH *dh);
14
15=head1 DESCRIPTION
16
17DH_new() allocates and initializes a B<DH> structure.
18
19DH_free() frees the B<DH> structure and its components. The values are
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DH_new() returns B<NULL> and sets an error
25code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
26a pointer to the newly allocated structure.
27
28DH_free() returns no value.
29
30=head1 SEE ALSO
31
32L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
33L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
34L<DH_generate_key(3)|DH_generate_key(3)>
35
36=head1 HISTORY
37
38DH_new() and DH_free() are available in all versions of SSLeay and OpenSSL.
39
40=cut
diff --git a/src/lib/libcrypto/doc/DH_set_method.pod b/src/lib/libcrypto/doc/DH_set_method.pod
deleted file mode 100644
index a8f75bdd9d..0000000000
--- a/src/lib/libcrypto/doc/DH_set_method.pod
+++ /dev/null
@@ -1,99 +0,0 @@
1=pod
2
3=head1 NAME
4
5DH_set_default_method, DH_get_default_method, DH_set_method,
6DH_new_method, DH_OpenSSL - select DH method
7
8=head1 SYNOPSIS
9
10 #include <openssl/dh.h>
11
12 void DH_set_default_method(DH_METHOD *meth);
13
14 DH_METHOD *DH_get_default_method(void);
15
16 DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
17
18 DH *DH_new_method(DH_METHOD *meth);
19
20 DH_METHOD *DH_OpenSSL(void);
21
22=head1 DESCRIPTION
23
24A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman
25operations. By modifying the method, alternative implementations
26such as hardware accelerators may be used.
27
28Initially, the default is to use the OpenSSL internal implementation.
29DH_OpenSSL() returns a pointer to that method.
30
31DH_set_default_method() makes B<meth> the default method for all B<DH>
32structures created later.
33
34DH_get_default_method() returns a pointer to the current default
35method.
36
37DH_set_method() selects B<meth> for all operations using the structure B<dh>.
38
39DH_get_method() returns a pointer to the method currently selected
40for B<dh>.
41
42DH_new_method() allocates and initializes a B<DH> structure so that
43B<method> will be used for the DH operations. If B<method> is B<NULL>,
44the default method is used.
45
46=head1 THE DH_METHOD STRUCTURE
47
48 typedef struct dh_meth_st
49 {
50 /* name of the implementation */
51 const char *name;
52
53 /* generate private and public DH values for key agreement */
54 int (*generate_key)(DH *dh);
55
56 /* compute shared secret */
57 int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
58
59 /* compute r = a ^ p mod m (May be NULL for some implementations) */
60 int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
61 const BIGNUM *m, BN_CTX *ctx,
62 BN_MONT_CTX *m_ctx);
63
64 /* called at DH_new */
65 int (*init)(DH *dh);
66
67 /* called at DH_free */
68 int (*finish)(DH *dh);
69
70 int flags;
71
72 char *app_data; /* ?? */
73
74 } DH_METHOD;
75
76=head1 RETURN VALUES
77
78DH_OpenSSL(), DH_get_default_method() and DH_get_method() return
79pointers to the respective B<DH_METHOD>s.
80
81DH_set_default_method() returns no value.
82
83DH_set_method() returns a pointer to the B<DH_METHOD> previously
84associated with B<dh>.
85
86DH_new_method() returns B<NULL> and sets an error code that can be
87obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
88returns a pointer to the newly allocated structure.
89
90=head1 SEE ALSO
91
92L<dh(3)|dh(3)>, L<DH_new(3)|DH_new(3)>
93
94=head1 HISTORY
95
96DH_set_default_method(), DH_get_default_method(), DH_set_method(),
97DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4.
98
99=cut
diff --git a/src/lib/libcrypto/doc/DH_size.pod b/src/lib/libcrypto/doc/DH_size.pod
deleted file mode 100644
index 97f26fda78..0000000000
--- a/src/lib/libcrypto/doc/DH_size.pod
+++ /dev/null
@@ -1,33 +0,0 @@
1=pod
2
3=head1 NAME
4
5DH_size - get Diffie-Hellman prime size
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_size(DH *dh);
12
13=head1 DESCRIPTION
14
15This function returns the Diffie-Hellman size in bytes. It can be used
16to determine how much memory must be allocated for the shared secret
17computed by DH_compute_key().
18
19B<dh-E<gt>p> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<dh(3)|dh(3)>, L<DH_generate_key(3)|DH_generate_key(3)>
28
29=head1 HISTORY
30
31DH_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/DSA_SIG_new.pod b/src/lib/libcrypto/doc/DSA_SIG_new.pod
deleted file mode 100644
index 45df4c0661..0000000000
--- a/src/lib/libcrypto/doc/DSA_SIG_new.pod
+++ /dev/null
@@ -1,39 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_SIG_new, DSA_SIG_free - allocate and free DSA signature objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA_SIG *DSA_SIG_new(void);
12
13 void DSA_SIG_free(DSA_SIG *a);
14
15=head1 DESCRIPTION
16
17DSA_SIG_new() allocates and initializes a B<DSA_SIG> structure.
18
19DSA_SIG_free() frees the B<DSA_SIG> structure and its components. The
20values are erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DSA_SIG_new() returns B<NULL> and sets an
25error code that can be obtained by
26L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
27to the newly allocated structure.
28
29DSA_SIG_free() returns no value.
30
31=head1 SEE ALSO
32
33L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<DSA_do_sign(3)|DSA_do_sign(3)>
34
35=head1 HISTORY
36
37DSA_SIG_new() and DSA_SIG_free() were added in OpenSSL 0.9.3.
38
39=cut
diff --git a/src/lib/libcrypto/doc/DSA_do_sign.pod b/src/lib/libcrypto/doc/DSA_do_sign.pod
deleted file mode 100644
index 5dfc733b20..0000000000
--- a/src/lib/libcrypto/doc/DSA_do_sign.pod
+++ /dev/null
@@ -1,47 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_do_sign, DSA_do_verify - raw DSA signature operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
12
13 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
14 DSA_SIG *sig, DSA *dsa);
15
16=head1 DESCRIPTION
17
18DSA_do_sign() computes a digital signature on the B<len> byte message
19digest B<dgst> using the private key B<dsa> and returns it in a
20newly allocated B<DSA_SIG> structure.
21
22L<DSA_sign_setup(3)|DSA_sign_setup(3)> may be used to precompute part
23of the signing operation in case signature generation is
24time-critical.
25
26DSA_do_verify() verifies that the signature B<sig> matches a given
27message digest B<dgst> of size B<len>. B<dsa> is the signer's public
28key.
29
30=head1 RETURN VALUES
31
32DSA_do_sign() returns the signature, NULL on error. DSA_do_verify()
33returns 1 for a valid signature, 0 for an incorrect signature and -1
34on error. The error codes can be obtained by
35L<ERR_get_error(3)|ERR_get_error(3)>.
36
37=head1 SEE ALSO
38
39L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
40L<DSA_SIG_new(3)|DSA_SIG_new(3)>,
41L<DSA_sign(3)|DSA_sign(3)>
42
43=head1 HISTORY
44
45DSA_do_sign() and DSA_do_verify() were added in OpenSSL 0.9.3.
46
47=cut
diff --git a/src/lib/libcrypto/doc/DSA_dup_DH.pod b/src/lib/libcrypto/doc/DSA_dup_DH.pod
deleted file mode 100644
index 695f99a13b..0000000000
--- a/src/lib/libcrypto/doc/DSA_dup_DH.pod
+++ /dev/null
@@ -1,36 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_dup_DH - create a DH structure out of DSA structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DH * DSA_dup_DH(DSA *r);
12
13=head1 DESCRIPTION
14
15DSA_dup_DH() duplicates DSA parameters/keys as DH parameters/keys. q
16is lost during that conversion, but the resulting DH parameters
17contain its length.
18
19=head1 RETURN VALUE
20
21DSA_dup_DH() returns the new B<DH> structure, and NULL on error. The
22error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
23
24=head1 NOTE
25
26Be careful to avoid small subgroup attacks when using this.
27
28=head1 SEE ALSO
29
30L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
31
32=head1 HISTORY
33
34DSA_dup_DH() was added in OpenSSL 0.9.4.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DSA_generate_key.pod b/src/lib/libcrypto/doc/DSA_generate_key.pod
deleted file mode 100644
index 9906a2d7e0..0000000000
--- a/src/lib/libcrypto/doc/DSA_generate_key.pod
+++ /dev/null
@@ -1,33 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_generate_key - generate DSA key pair
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_generate_key(DSA *a);
12
13=head1 DESCRIPTION
14
15DSA_generate_key() expects B<a> to contain DSA parameters. It generates
16a new key pair and stores it in B<a-E<gt>pub_key> and B<a-E<gt>priv_key>.
17
18The PRNG must be seeded prior to calling DSA_generate_key().
19
20=head1 RETURN VALUE
21
22DSA_generate_key() returns 1 on success, 0 otherwise.
23The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
24
25=head1 SEE ALSO
26
27L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>
28
29=head1 HISTORY
30
31DSA_generate_key() is available since SSLeay 0.8.
32
33=cut
diff --git a/src/lib/libcrypto/doc/DSA_generate_parameters.pod b/src/lib/libcrypto/doc/DSA_generate_parameters.pod
deleted file mode 100644
index be7c924ff8..0000000000
--- a/src/lib/libcrypto/doc/DSA_generate_parameters.pod
+++ /dev/null
@@ -1,105 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_generate_parameters - generate DSA parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA *DSA_generate_parameters(int bits, unsigned char *seed,
12 int seed_len, int *counter_ret, unsigned long *h_ret,
13 void (*callback)(int, int, void *), void *cb_arg);
14
15=head1 DESCRIPTION
16
17DSA_generate_parameters() generates primes p and q and a generator g
18for use in the DSA.
19
20B<bits> is the length of the prime to be generated; the DSS allows a
21maximum of 1024 bits.
22
23If B<seed> is B<NULL> or B<seed_len> E<lt> 20, the primes will be
24generated at random. Otherwise, the seed is used to generate
25them. If the given seed does not yield a prime q, a new random
26seed is chosen and placed at B<seed>.
27
28DSA_generate_parameters() places the iteration count in
29*B<counter_ret> and a counter used for finding a generator in
30*B<h_ret>, unless these are B<NULL>.
31
32A callback function may be used to provide feedback about the progress
33of the key generation. If B<callback> is not B<NULL>, it will be
34called as follows:
35
36=over 4
37
38=item *
39
40When a candidate for q is generated, B<callback(0, m++, cb_arg)> is called
41(m is 0 for the first candidate).
42
43=item *
44
45When a candidate for q has passed a test by trial division,
46B<callback(1, -1, cb_arg)> is called.
47While a candidate for q is tested by Miller-Rabin primality tests,
48B<callback(1, i, cb_arg)> is called in the outer loop
49(once for each witness that confirms that the candidate may be prime);
50i is the loop counter (starting at 0).
51
52=item *
53
54When a prime q has been found, B<callback(2, 0, cb_arg)> and
55B<callback(3, 0, cb_arg)> are called.
56
57=item *
58
59Before a candidate for p (other than the first) is generated and tested,
60B<callback(0, counter, cb_arg)> is called.
61
62=item *
63
64When a candidate for p has passed the test by trial division,
65B<callback(1, -1, cb_arg)> is called.
66While it is tested by the Miller-Rabin primality test,
67B<callback(1, i, cb_arg)> is called in the outer loop
68(once for each witness that confirms that the candidate may be prime).
69i is the loop counter (starting at 0).
70
71=item *
72
73When p has been found, B<callback(2, 1, cb_arg)> is called.
74
75=item *
76
77When the generator has been found, B<callback(3, 1, cb_arg)> is called.
78
79=back
80
81=head1 RETURN VALUE
82
83DSA_generate_parameters() returns a pointer to the DSA structure, or
84B<NULL> if the parameter generation fails. The error codes can be
85obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
86
87=head1 BUGS
88
89Seed lengths E<gt> 20 are not supported.
90
91=head1 SEE ALSO
92
93L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
94L<DSA_free(3)|DSA_free(3)>
95
96=head1 HISTORY
97
98DSA_generate_parameters() appeared in SSLeay 0.8. The B<cb_arg>
99argument was added in SSLeay 0.9.0.
100In versions up to OpenSSL 0.9.4, B<callback(1, ...)> was called
101in the inner loop of the Miller-Rabin test whenever it reached the
102squaring step (the parameters to B<callback> did not reveal how many
103witnesses had been tested); since OpenSSL 0.9.5, B<callback(1, ...)>
104is called as in BN_is_prime(3), i.e. once for each witness.
105=cut
diff --git a/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod b/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod
deleted file mode 100644
index 4612e708ec..0000000000
--- a/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod
+++ /dev/null
@@ -1,36 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_get_ex_new_index, DSA_set_ex_data, DSA_get_ex_data - add application specific data to DSA structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/DSA.h>
10
11 int DSA_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int DSA_set_ex_data(DSA *d, int idx, void *arg);
17
18 char *DSA_get_ex_data(DSA *d, int idx);
19
20=head1 DESCRIPTION
21
22These functions handle application specific data in DSA
23structures. Their usage is identical to that of
24RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
25as described in L<RSA_get_ex_new_index(3)>.
26
27=head1 SEE ALSO
28
29L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>, L<dsa(3)|dsa(3)>
30
31=head1 HISTORY
32
33DSA_get_ex_new_index(), DSA_set_ex_data() and DSA_get_ex_data() are
34available since OpenSSL 0.9.5.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DSA_new.pod b/src/lib/libcrypto/doc/DSA_new.pod
deleted file mode 100644
index 301af912dd..0000000000
--- a/src/lib/libcrypto/doc/DSA_new.pod
+++ /dev/null
@@ -1,41 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_new, DSA_free - allocate and free DSA objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA* DSA_new(void);
12
13 void DSA_free(DSA *dsa);
14
15=head1 DESCRIPTION
16
17DSA_new() allocates and initializes a B<DSA> structure.
18
19DSA_free() frees the B<DSA> structure and its components. The values are
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DSA_new() returns B<NULL> and sets an error
25code that can be obtained by
26L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
27to the newly allocated structure.
28
29DSA_free() returns no value.
30
31=head1 SEE ALSO
32
33L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
34L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
35L<DSA_generate_key(3)|DSA_generate_key(3)>
36
37=head1 HISTORY
38
39DSA_new() and DSA_free() are available in all versions of SSLeay and OpenSSL.
40
41=cut
diff --git a/src/lib/libcrypto/doc/DSA_set_method.pod b/src/lib/libcrypto/doc/DSA_set_method.pod
deleted file mode 100644
index edec46413d..0000000000
--- a/src/lib/libcrypto/doc/DSA_set_method.pod
+++ /dev/null
@@ -1,112 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_set_default_method, DSA_get_default_method, DSA_set_method,
6DSA_new_method, DSA_OpenSSL - select RSA method
7
8=head1 SYNOPSIS
9
10 #include <openssl/DSA.h>
11
12 void DSA_set_default_method(DSA_METHOD *meth);
13
14 DSA_METHOD *DSA_get_default_method(void);
15
16 DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth);
17
18 DSA *DSA_new_method(DSA_METHOD *meth);
19
20 DSA_METHOD *DSA_OpenSSL(void);
21
22=head1 DESCRIPTION
23
24A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA
25operations. By modifying the method, alternative implementations
26such as hardware accelerators may be used.
27
28Initially, the default is to use the OpenSSL internal implementation.
29DSA_OpenSSL() returns a pointer to that method.
30
31DSA_set_default_method() makes B<meth> the default method for all B<DSA>
32structures created later.
33
34DSA_get_default_method() returns a pointer to the current default
35method.
36
37DSA_set_method() selects B<meth> for all operations using the structure B<DSA>.
38
39DSA_get_method() returns a pointer to the method currently selected
40for B<DSA>.
41
42DSA_new_method() allocates and initializes a B<DSA> structure so that
43B<method> will be used for the DSA operations. If B<method> is B<NULL>,
44the default method is used.
45
46=head1 THE DSA_METHOD STRUCTURE
47
48struct
49 {
50 /* name of the implementation */
51 const char *name;
52
53 /* sign */
54 DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen,
55 DSA *dsa);
56
57 /* pre-compute k^-1 and r */
58 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
59 BIGNUM **rp);
60
61 /* verify */
62 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
63 DSA_SIG *sig, DSA *dsa);
64
65 /* compute rr = a1^p1 * a2^p2 mod m (May be NULL for some
66 implementations) */
67 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
68 BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
69 BN_CTX *ctx, BN_MONT_CTX *in_mont);
70
71 /* compute r = a ^ p mod m (May be NULL for some implementations) */
72 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a,
73 const BIGNUM *p, const BIGNUM *m,
74 BN_CTX *ctx, BN_MONT_CTX *m_ctx);
75
76 /* called at DSA_new */
77 int (*init)(DSA *DSA);
78
79 /* called at DSA_free */
80 int (*finish)(DSA *DSA);
81
82 int flags;
83
84 char *app_data; /* ?? */
85
86 } DSA_METHOD;
87
88=head1 RETURN VALUES
89
90DSA_OpenSSL(), DSA_get_default_method() and DSA_get_method() return
91pointers to the respective B<DSA_METHOD>s.
92
93DSA_set_default_method() returns no value.
94
95DSA_set_method() returns a pointer to the B<DSA_METHOD> previously
96associated with B<dsa>.
97
98DSA_new_method() returns B<NULL> and sets an error code that can be
99obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation
100fails. Otherwise it returns a pointer to the newly allocated
101structure.
102
103=head1 SEE ALSO
104
105L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)>
106
107=head1 HISTORY
108
109DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(),
110DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4.
111
112=cut
diff --git a/src/lib/libcrypto/doc/DSA_sign.pod b/src/lib/libcrypto/doc/DSA_sign.pod
deleted file mode 100644
index 97389e8ec8..0000000000
--- a/src/lib/libcrypto/doc/DSA_sign.pod
+++ /dev/null
@@ -1,66 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_sign, DSA_sign_setup, DSA_verify - DSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_sign(int type, const unsigned char *dgst, int len,
12 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
13
14 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
15 BIGNUM **rp);
16
17 int DSA_verify(int type, const unsigned char *dgst, int len,
18 unsigned char *sigbuf, int siglen, DSA *dsa);
19
20=head1 DESCRIPTION
21
22DSA_sign() computes a digital signature on the B<len> byte message
23digest B<dgst> using the private key B<dsa> and places its ASN.1 DER
24encoding at B<sigret>. The length of the signature is places in
25*B<siglen>. B<sigret> must point to DSA_size(B<dsa>) bytes of memory.
26
27DSA_sign_setup() may be used to precompute part of the signing
28operation in case signature generation is time-critical. It expects
29B<dsa> to contain DSA parameters. It places the precomputed values
30in newly allocated B<BIGNUM>s at *B<kinvp> and *B<rp>, after freeing
31the old ones unless *B<kinvp> and *B<rp> are NULL. These values may
32be passed to DSA_sign() in B<dsa-E<gt>kinv> and B<dsa-E<gt>r>.
33B<ctx> is a pre-allocated B<BN_CTX> or NULL.
34
35DSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
36matches a given message digest B<dgst> of size B<len>.
37B<dsa> is the signer's public key.
38
39The B<type> parameter is ignored.
40
41The PRNG must be seeded before DSA_sign() (or DSA_sign_setup())
42is called.
43
44=head1 RETURN VALUES
45
46DSA_sign() and DSA_sign_setup() return 1 on success, 0 on error.
47DSA_verify() returns 1 for a valid signature, 0 for an incorrect
48signature and -1 on error. The error codes can be obtained by
49L<ERR_get_error(3)|ERR_get_error(3)>.
50
51=head1 CONFORMING TO
52
53US Federal Information Processing Standard FIPS 186 (Digital Signature
54Standard, DSS), ANSI X9.30
55
56=head1 SEE ALSO
57
58L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>,
59L<DSA_do_sign(3)|DSA_do_sign(3)>
60
61=head1 HISTORY
62
63DSA_sign() and DSA_verify() are available in all versions of SSLeay.
64DSA_sign_setup() was added in SSLeay 0.8.
65
66=cut
diff --git a/src/lib/libcrypto/doc/DSA_size.pod b/src/lib/libcrypto/doc/DSA_size.pod
deleted file mode 100644
index 23b6320a4d..0000000000
--- a/src/lib/libcrypto/doc/DSA_size.pod
+++ /dev/null
@@ -1,33 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_size - get DSA signature size
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_size(DSA *dsa);
12
13=head1 DESCRIPTION
14
15This function returns the size of an ASN.1 encoded DSA signature in
16bytes. It can be used to determine how much memory must be allocated
17for a DSA signature.
18
19B<dsa-E<gt>q> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<dsa(3)|dsa(3)>, L<DSA_sign(3)|DSA_sign(3)>
28
29=head1 HISTORY
30
31DSA_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/ERR_GET_LIB.pod b/src/lib/libcrypto/doc/ERR_GET_LIB.pod
deleted file mode 100644
index 2a129da036..0000000000
--- a/src/lib/libcrypto/doc/ERR_GET_LIB.pod
+++ /dev/null
@@ -1,51 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_GET_LIB, ERR_GET_FUNC, ERR_GET_REASON - get library, function and
6reason code
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 int ERR_GET_LIB(unsigned long e);
13
14 int ERR_GET_FUNC(unsigned long e);
15
16 int ERR_GET_REASON(unsigned long e);
17
18=head1 DESCRIPTION
19
20The error code returned by ERR_get_error() consists of a library
21number, function code and reason code. ERR_GET_LIB(), ERR_GET_FUNC()
22and ERR_GET_REASON() can be used to extract these.
23
24The library number and function code describe where the error
25occurred, the reason code is the information about what went wrong.
26
27Each sub-library of OpenSSL has a unique library number; function and
28reason codes are unique within each sub-library. Note that different
29libraries may use the same value to signal different functions and
30reasons.
31
32B<ERR_R_...> reason codes such as B<ERR_R_MALLOC_FAILURE> are globally
33unique. However, when checking for sub-library specific reason codes,
34be sure to also compare the library number.
35
36ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are macros.
37
38=head1 RETURN VALUES
39
40The library number, function code and reason code respectively.
41
42=head1 SEE ALSO
43
44L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
45
46=head1 HISTORY
47
48ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are available in
49all versions of SSLeay and OpenSSL.
50
51=cut
diff --git a/src/lib/libcrypto/doc/ERR_clear_error.pod b/src/lib/libcrypto/doc/ERR_clear_error.pod
deleted file mode 100644
index 566e1f4e31..0000000000
--- a/src/lib/libcrypto/doc/ERR_clear_error.pod
+++ /dev/null
@@ -1,29 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_clear_error - clear the error queue
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_clear_error(void);
12
13=head1 DESCRIPTION
14
15ERR_clear_error() empties the current thread's error queue.
16
17=head1 RETURN VALUES
18
19ERR_clear_error() has no return value.
20
21=head1 SEE ALSO
22
23L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
24
25=head1 HISTORY
26
27ERR_clear_error() is available in all versions of SSLeay and OpenSSL.
28
29=cut
diff --git a/src/lib/libcrypto/doc/ERR_error_string.pod b/src/lib/libcrypto/doc/ERR_error_string.pod
deleted file mode 100644
index 0d2417599c..0000000000
--- a/src/lib/libcrypto/doc/ERR_error_string.pod
+++ /dev/null
@@ -1,65 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_error_string - obtain human-readable error message
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 char *ERR_error_string(unsigned long e, char *buf);
12
13 const char *ERR_lib_error_string(unsigned long e);
14 const char *ERR_func_error_string(unsigned long e);
15 const char *ERR_reason_error_string(unsigned long e);
16
17=head1 DESCRIPTION
18
19ERR_error_string() generates a human-readable string representing the
20error code B<e>, and places it at B<buf>. B<buf> must be at least 120
21bytes long. If B<buf> is B<NULL>, the error string is placed in a
22static buffer.
23
24The string will have the following format:
25
26 error:[error code]:[library name]:[function name]:[reason string]
27
28I<error code> is an 8 digit hexadecimal number, I<library name>,
29I<function name> and I<reason string> are ASCII text.
30
31ERR_lib_error_string(), ERR_func_error_string() and
32ERR_reason_error_string() return the library name, function
33name and reason string respectively.
34
35The OpenSSL error strings should be loaded by calling
36L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)> or, for SSL
37applications, L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
38first.
39If there is no text string registered for the given error code,
40the error string will contain the numeric code.
41
42L<ERR_print_errors(3)|ERR_print_errors(3)> can be used to print
43all error codes currently in the queue.
44
45=head1 RETURN VALUES
46
47ERR_error_string() returns a pointer to a static buffer containing the
48string if B<buf == NULL>, B<buf> otherwise.
49
50ERR_lib_error_string(), ERR_func_error_string() and
51ERR_reason_error_string() return the strings, and B<NULL> if
52none is registered for the error code.
53
54=head1 SEE ALSO
55
56L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
57L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
58L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
59L<ERR_print_errors(3)|ERR_print_errors(3)>
60
61=head1 HISTORY
62
63ERR_error_string() is available in all versions of SSLeay and OpenSSL.
64
65=cut
diff --git a/src/lib/libcrypto/doc/ERR_get_error.pod b/src/lib/libcrypto/doc/ERR_get_error.pod
deleted file mode 100644
index 75ece00d97..0000000000
--- a/src/lib/libcrypto/doc/ERR_get_error.pod
+++ /dev/null
@@ -1,62 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_get_error, ERR_peek_error - obtain error code
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 unsigned long ERR_get_error(void);
12 unsigned long ERR_peek_error(void);
13
14 unsigned long ERR_get_error_line(const char **file, int *line);
15 unsigned long ERR_peek_error_line(const char **file, int *line);
16
17 unsigned long ERR_get_error_line_data(const char **file, int *line,
18 const char **data, int *flags);
19 unsigned long ERR_peek_error_line_data(const char **file, int *line,
20 const char **data, int *flags);
21
22=head1 DESCRIPTION
23
24ERR_get_error() returns the last error code from the thread's error
25queue and removes the entry. This function can be called repeatedly
26until there are no more error codes to return.
27
28ERR_peek_error() returns the last error code from the thread's
29error queue without modifying it.
30
31See L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> for obtaining information about
32location and reason of the error, and
33L<ERR_error_string(3)|ERR_error_string(3)> for human-readable error
34messages.
35
36ERR_get_error_line() and ERR_peek_error_line() are the same as the
37above, but they additionally store the file name and line number where
38the error occurred in *B<file> and *B<line>, unless these are B<NULL>.
39
40ERR_get_error_line_data() and ERR_peek_error_line_data() store
41additional data and flags associated with the error code in *B<data>
42and *B<flags>, unless these are B<NULL>. *B<data> contains a string
43if *B<flags>&B<ERR_TXT_STRING>. If it has been allocated by Malloc(),
44*B<flags>&B<ERR_TXT_MALLOCED> is true.
45
46=head1 RETURN VALUES
47
48The error code, or 0 if there is no error in the queue.
49
50=head1 SEE ALSO
51
52L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
53L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>
54
55=head1 HISTORY
56
57ERR_get_error(), ERR_peek_error(), ERR_get_error_line() and
58ERR_peek_error_line() are available in all versions of SSLeay and
59OpenSSL. ERR_get_error_line_data() and ERR_peek_error_line_data()
60were added in SSLeay 0.9.0.
61
62=cut
diff --git a/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod b/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod
deleted file mode 100644
index 9bdec75a46..0000000000
--- a/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod
+++ /dev/null
@@ -1,46 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_load_crypto_strings, SSL_load_error_strings, ERR_free_strings -
6load and free error strings
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 void ERR_load_crypto_strings(void);
13 void ERR_free_strings(void);
14
15 #include <openssl/ssl.h>
16
17 void SSL_load_error_strings(void);
18
19=head1 DESCRIPTION
20
21ERR_load_crypto_strings() registers the error strings for all
22B<libcrypto> functions. SSL_load_error_strings() does the same,
23but also registers the B<libssl> error strings.
24
25One of these functions should be called before generating
26textual error messages. However, this is not required when memory
27usage is an issue.
28
29ERR_free_strings() frees all previously loaded error strings.
30
31=head1 RETURN VALUES
32
33ERR_load_crypto_strings(), SSL_load_error_strings() and
34ERR_free_strings() return no values.
35
36=head1 SEE ALSO
37
38L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>
39
40=head1 HISTORY
41
42ERR_load_error_strings(), SSL_load_error_strings() and
43ERR_free_strings() are available in all versions of SSLeay and
44OpenSSL.
45
46=cut
diff --git a/src/lib/libcrypto/doc/ERR_load_strings.pod b/src/lib/libcrypto/doc/ERR_load_strings.pod
deleted file mode 100644
index 5acdd0edbc..0000000000
--- a/src/lib/libcrypto/doc/ERR_load_strings.pod
+++ /dev/null
@@ -1,54 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_load_strings, ERR_PACK, ERR_get_next_error_library - load
6arbitrary error strings
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 void ERR_load_strings(int lib, ERR_STRING_DATA str[]);
13
14 int ERR_get_next_error_library(void);
15
16 unsigned long ERR_PACK(int lib, int func, int reason);
17
18=head1 DESCRIPTION
19
20ERR_load_strings() registers error strings for library number B<lib>.
21
22B<str> is an array of error string data:
23
24 typedef struct ERR_string_data_st
25 {
26 unsigned long error;
27 char *string;
28 } ERR_STRING_DATA;
29
30The error code is generated from the library number and a function and
31reason code: B<error> = ERR_PACK(B<lib>, B<func>, B<reason>).
32ERR_PACK() is a macro.
33
34The last entry in the array is {0,0}.
35
36ERR_get_next_error_library() can be used to assign library numbers
37to user libraries at runtime.
38
39=head1 RETURN VALUE
40
41ERR_load_strings() returns no value. ERR_PACK() return the error code.
42ERR_get_next_error_library() returns a new library number.
43
44=head1 SEE ALSO
45
46L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
47
48=head1 HISTORY
49
50ERR_load_error_strings() and ERR_PACK() are available in all versions
51of SSLeay and OpenSSL. ERR_get_next_error_library() was added in
52SSLeay 0.9.0.
53
54=cut
diff --git a/src/lib/libcrypto/doc/ERR_print_errors.pod b/src/lib/libcrypto/doc/ERR_print_errors.pod
deleted file mode 100644
index b100a5fa2b..0000000000
--- a/src/lib/libcrypto/doc/ERR_print_errors.pod
+++ /dev/null
@@ -1,51 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_print_errors, ERR_print_errors_fp - print error messages
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_print_errors(BIO *bp);
12 void ERR_print_errors_fp(FILE *fp);
13
14=head1 DESCRIPTION
15
16ERR_print_errors() is a convenience function that prints the error
17strings for all errors that OpenSSL has recorded to B<bp>, thus
18emptying the error queue.
19
20ERR_print_errors_fp() is the same, except that the output goes to a
21B<FILE>.
22
23
24The error strings will have the following format:
25
26 [pid]:error:[error code]:[library name]:[function name]:[reason string]:[file name]:[line]:[optional text message]
27
28I<error code> is an 8 digit hexadecimal number. I<library name>,
29I<function name> and I<reason string> are ASCII text, as is I<optional
30text message> if one was set for the respective error code.
31
32If there is no text string registered for the given error code,
33the error string will contain the numeric code.
34
35=head1 RETURN VALUES
36
37ERR_print_errors() and ERR_print_errors_fp() return no values.
38
39=head1 SEE ALSO
40
41L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
42L<ERR_get_error(3)|ERR_get_error(3)>,
43L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
44L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
45
46=head1 HISTORY
47
48ERR_print_errors() and ERR_print_errors_fp()
49are available in all versions of SSLeay and OpenSSL.
50
51=cut
diff --git a/src/lib/libcrypto/doc/ERR_put_error.pod b/src/lib/libcrypto/doc/ERR_put_error.pod
deleted file mode 100644
index acd241fbe4..0000000000
--- a/src/lib/libcrypto/doc/ERR_put_error.pod
+++ /dev/null
@@ -1,44 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_put_error, ERR_add_error_data - record an error
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_put_error(int lib, int func, int reason, const char *file,
12 int line);
13
14 void ERR_add_error_data(int num, ...);
15
16=head1 DESCRIPTION
17
18ERR_put_error() adds an error code to the thread's error queue. It
19signals that the error of reason code B<reason> occurred in function
20B<func> of library B<lib>, in line number B<line> of B<file>.
21This function is usually called by a macro.
22
23ERR_add_error_data() associates the concatenation of its B<num> string
24arguments with the error code added last.
25
26L<ERR_load_strings(3)|ERR_load_strings(3)> can be used to register
27error strings so that the application can a generate human-readable
28error messages for the error code.
29
30=head1 RETURN VALUES
31
32ERR_put_error() and ERR_add_error_data() return
33no values.
34
35=head1 SEE ALSO
36
37L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
38
39=head1 HISTORY
40
41ERR_put_error() is available in all versions of SSLeay and OpenSSL.
42ERR_add_error_data() was added in SSLeay 0.9.0.
43
44=cut
diff --git a/src/lib/libcrypto/doc/ERR_remove_state.pod b/src/lib/libcrypto/doc/ERR_remove_state.pod
deleted file mode 100644
index ebcdc0f5a5..0000000000
--- a/src/lib/libcrypto/doc/ERR_remove_state.pod
+++ /dev/null
@@ -1,34 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_remove_state - free a thread's error queue
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_remove_state(unsigned long pid);
12
13=head1 DESCRIPTION
14
15ERR_remove_state() frees the error queue associated with thread B<pid>.
16If B<pid> == 0, the current thread will have its error queue removed.
17
18Since error queue data structures are allocated automatically for new
19threads, they must be freed when threads are terminated in oder to
20avoid memory leaks.
21
22=head1 RETURN VALUE
23
24ERR_remove_state() returns no value.
25
26=head1 SEE ALSO
27
28L<err(3)|err(3)>
29
30=head1 HISTORY
31
32ERR_remove_state() is available in all versions of SSLeay and OpenSSL.
33
34=cut
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod
deleted file mode 100644
index 6d4e156ae3..0000000000
--- a/src/lib/libcrypto/doc/EVP_DigestInit.pod
+++ /dev/null
@@ -1,197 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal - EVP digest routines
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
12 void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
14 unsigned int *s);
15
16 #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
17
18 int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
19
20 #define EVP_MD_type(e) ((e)->type)
21 #define EVP_MD_pkey_type(e) ((e)->pkey_type)
22 #define EVP_MD_size(e) ((e)->md_size)
23 #define EVP_MD_block_size(e) ((e)->block_size)
24
25 #define EVP_MD_CTX_md(e) (e)->digest)
26 #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
27 #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
28 #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
29
30 EVP_MD *EVP_md_null(void);
31 EVP_MD *EVP_md2(void);
32 EVP_MD *EVP_md5(void);
33 EVP_MD *EVP_sha(void);
34 EVP_MD *EVP_sha1(void);
35 EVP_MD *EVP_dss(void);
36 EVP_MD *EVP_dss1(void);
37 EVP_MD *EVP_mdc2(void);
38 EVP_MD *EVP_ripemd160(void);
39
40 const EVP_MD *EVP_get_digestbyname(const char *name);
41 #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
42 #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
43
44=head1 DESCRIPTION
45
46The EVP digest routines are a high level interface to message digests.
47
48EVP_DigestInit() initialises a digest context B<ctx> to use a digest
49B<type>: this will typically be supplied by a function such as
50EVP_sha1().
51
52EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the
53digest context B<ctx>. This funtion can be called several times on the
54same B<ctx> to hash additional data.
55
56EVP_DigestFinal() retrieves the digest value from B<ctx> and places
57it in B<md>. If the B<s> parameter is not NULL then the number of
58bytes of data written (i.e. the length of the digest) will be written
59to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written.
60After calling EVP_DigestFinal() no additional calls to EVP_DigestUpdate()
61can be made, but EVP_DigestInit() can be called to initialiase a new
62digest operation.
63
64EVP_MD_CTX_copy() can be used to copy the message digest state from
65B<in> to B<out>. This is useful if large amounts of data are to be
66hashed which only differ in the last few bytes.
67
68EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest
69when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the
70hash.
71
72EVP_MD_block_size() and EVP_MD_CTX_block_size() return the block size of the
73message digest when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure.
74
75EVP_MD_type() and EVP_MD_CTX_type() return the NID of the OBJECT IDENTIFIER
76representing the given message digest when passed an B<EVP_MD> structure.
77For example EVP_MD_type(EVP_sha1()) returns B<NID_sha1>. This function is
78normally used when setting ASN1 OIDs.
79
80EVP_MD_CTX_md() returns the B<EVP_MD> structure corresponding to the passed
81B<EVP_MD_CTX>.
82
83EVP_MD_pkey_type() returns the NID of the public key signing algorithm associated
84with this digest. For example EVP_sha1() is associated with RSA so this will
85return B<NID_sha1WithRSAEncryption>. This "link" between digests and signature
86algorithms may not be retained in future versions of OpenSSL.
87
88EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_mdc2() and EVP_ripemd160()
89return B<EVP_MD> structures for the MD2, MD5, SHA, SHA1, MDC2 and RIPEMD160 digest
90algorithms respectively. The associated signature algorithm is RSA in each case.
91
92EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA and SHA1 digest
93algorithms but using DSS (DSA) for the signature algorithm.
94
95EVP_md_null() is a "null" message digest that does nothing: i.e. the hash it
96returns is of zero length.
97
98EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
99return an B<EVP_MD> structure when passed a digest name, a digest NID or
100an ASN1_OBJECT structure respectively. The digest table must be initialised
101using, for example, OpenSSL_add_all_digests() for these functions to work.
102
103=head1 RETURN VALUES
104
105EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() do not return values.
106
107EVP_MD_CTX_copy() returns 1 if successful or 0 for failure.
108
109EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the
110corresponding OBJECT IDENTIFIER or NID_undef if none exists.
111
112EVP_MD_size(), EVP_MD_block_size(), EVP_MD_CTX_size(e), EVP_MD_size(),
113EVP_MD_CTX_block_size() and EVP_MD_block_size() return the digest or block
114size in bytes.
115
116EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_dss(),
117EVP_dss1(), EVP_mdc2() and EVP_ripemd160() return pointers to the
118corresponding EVP_MD structures.
119
120EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
121return either an B<EVP_MD> structure or NULL if an error occurs.
122
123=head1 NOTES
124
125The B<EVP> interface to message digests should almost always be used in
126preference to the low level interfaces. This is because the code then becomes
127transparent to the digest used and much more flexible.
128
129SHA1 is the digest of choice for new applications. The other digest algorithms
130are still in common use.
131
132=head1 EXAMPLE
133
134This example digests the data "Test Message\n" and "Hello World\n", using the
135digest name passed on the command line.
136
137 #include <stdio.h>
138 #include <openssl/evp.h>
139
140 main(int argc, char *argv[])
141 {
142 EVP_MD_CTX mdctx;
143 const EVP_MD *md;
144 char mess1[] = "Test Message\n";
145 char mess2[] = "Hello World\n";
146 unsigned char md_value[EVP_MAX_MD_SIZE];
147 int md_len, i;
148
149 OpenSSL_add_all_digests();
150
151 if(!argv[1]) {
152 printf("Usage: mdtest digestname\n");
153 exit(1);
154 }
155
156 md = EVP_get_digestbyname(argv[1]);
157
158 if(!md) {
159 printf("Unknown message digest %s\n", argv[1]);
160 exit(1);
161 }
162
163 EVP_DigestInit(&mdctx, md);
164 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
165 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
166 EVP_DigestFinal(&mdctx, md_value, &md_len);
167
168 printf("Digest is: ");
169 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
170 printf("\n");
171 }
172
173=head1 BUGS
174
175Several of the functions do not return values: maybe they should. Although the
176internal digest operations will never fail some future hardware based operations
177might.
178
179The link between digests and signing algorithms results in a situation where
180EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS
181even though they are identical digests.
182
183The size of an B<EVP_MD_CTX> structure is determined at compile time: this results
184in code that must be recompiled if the size of B<EVP_MD_CTX> increases.
185
186=head1 SEE ALSO
187
188L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
189L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD160(3)|RIPEMD160(3)>,
190L<SHA1(3)|SHA1(3)>
191
192=head1 HISTORY
193
194EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are
195available in all versions of SSLeay and OpenSSL.
196
197=cut
diff --git a/src/lib/libcrypto/doc/EVP_EncryptInit.pod b/src/lib/libcrypto/doc/EVP_EncryptInit.pod
deleted file mode 100644
index 77ed4ccdba..0000000000
--- a/src/lib/libcrypto/doc/EVP_EncryptInit.pod
+++ /dev/null
@@ -1,224 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_EncryptInit, EVP_EncryptUpdate, EVP_EncryptFinal - EVP cipher routines
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
12 unsigned char *key, unsigned char *iv);
13 void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
16 int *outl);
17
18 void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
19 unsigned char *key, unsigned char *iv);
20 void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
21 int *outl, unsigned char *in, int inl);
22 int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
23 int *outl);
24
25 void EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
26 unsigned char *key, unsigned char *iv, int enc);
27 void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
28 int *outl, unsigned char *in, int inl);
29 int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
30 int *outl);
31
32 void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
33
34 const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
35 #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
36 #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
37
38 #define EVP_CIPHER_nid(e) ((e)->nid)
39 #define EVP_CIPHER_block_size(e) ((e)->block_size)
40 #define EVP_CIPHER_key_length(e) ((e)->key_len)
41 #define EVP_CIPHER_iv_length(e) ((e)->iv_len)
42
43 int EVP_CIPHER_type(const EVP_CIPHER *ctx);
44 #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
45 #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
46 #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
47 #define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len)
48 #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
49 #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
50
51 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
52 int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
53
54=head1 DESCRIPTION
55
56The EVP cipher routines are a high level interface to certain
57symmetric ciphers.
58
59EVP_EncryptInit() initialises a cipher context B<ctx> for encryption
60with cipher B<type>. B<type> is normally supplied by a function such
61as EVP_des_cbc() . B<key> is the symmetric key to use and B<iv> is the
62IV to use (if necessary), the actual number of bytes used for the
63key and IV depends on the cipher. It is possible to set all parameters
64to NULL except B<type> in an initial call and supply the remaining
65parameters in subsequent calls. This is normally done when the
66EVP_CIPHER_asn1_to_param() function is called to set the cipher
67parameters from an ASN1 AlgorithmIdentifier and the key from a
68different source.
69
70EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and
71writes the encrypted version to B<out>. This function can be called
72multiple times to encrypt successive blocks of data. The amount
73of data written depends on the block alignment of the encrypted data:
74as a result the amount of data written may be anything from zero bytes
75to (inl + cipher_block_size - 1) so B<outl> should contain sufficient
76room. The actual number of bytes written is placed in B<outl>.
77
78EVP_EncryptFinal() encrypts the "final" data, that is any data that
79remains in a partial block. It uses L<standard block padding|/NOTES> (aka PKCS
80padding). The encrypted final data is written to B<out> which should
81have sufficient space for one cipher block. The number of bytes written
82is placed in B<outl>. After this function is called the encryption operation
83is finished and no further calls to EVP_EncryptUpdate() should be made.
84
85EVP_DecryptInit(), EVP_DecryptUpdate() and EVP_DecryptFinal() are the
86corresponding decryption operations. EVP_DecryptFinal() will return an
87error code if the final block is not correctly formatted. The parameters
88and restrictions are identical to the encryption operations except that
89the decrypted data buffer B<out> passed to EVP_DecryptUpdate() should
90have sufficient room for (B<inl> + cipher_block_size) bytes unless the
91cipher block size is 1 in which case B<inl> bytes is sufficient.
92
93EVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal() are functions
94that can be used for decryption or encryption. The operation performed
95depends on the value of the B<enc> parameter. It should be set to 1 for
96encryption and 0 for decryption.
97
98EVP_CIPHER_CTX_cleanup() clears all information from a cipher context.
99It should be called after all operations using a cipher are complete
100so sensitive information does not remain in memory.
101
102EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
103return an EVP_CIPHER structure when passed a cipher name, a NID or an
104ASN1_OBJECT structure.
105
106EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return the NID of a cipher when
107passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> structure. The actual NID
108value is an internal value which may not have a corresponding OBJECT
109IDENTIFIER.
110
111EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
112length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
113structure. The constant B<EVP_MAX_KEY_LENGTH> is the maximum key length
114for all ciphers.
115
116EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
117length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>.
118It will return zero if the cipher does not use an IV. The constant
119B<EVP_MAX_IV_LENGTH> is the maximum IV length for all ciphers.
120
121EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
122size of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
123structure. The constant B<EVP_MAX_IV_LENGTH> is also the maximum block
124length for all ciphers.
125
126EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the type of the passed
127cipher or context. This "type" is the actual NID of the cipher OBJECT
128IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and
129128 bit RC2 have the same NID. If the cipher does not have an object
130identifier or does not have ASN1 support this function will return
131B<NID_undef>.
132
133EVP_CIPHER_CTX_cipher() returns the B<EVP_CIPHER> structure when passed
134an B<EVP_CIPHER_CTX> structure.
135
136EVP_CIPHER_param_to_asn1() sets the AlgorithmIdentifier "parameter" based
137on the passed cipher. This will typically include any parameters and an
138IV. The cipher IV (if any) must be set when this call is made. This call
139should be made before the cipher is actually "used" (before any
140EVP_EncryptUpdate(), EVP_DecryptUpdate() calls for example). This function
141may fail if the cipher does not have any ASN1 support.
142
143EVP_CIPHER_asn1_to_param() sets the cipher parameters based on an ASN1
144AlgorithmIdentifier "parameter". The precise effect depends on the cipher
145In the case of RC2, for example, it will set the IV and effective key length.
146This function should be called after the base cipher type is set but before
147the key is set. For example EVP_CipherInit() will be called with the IV and
148key set to NULL, EVP_CIPHER_asn1_to_param() will be called and finally
149EVP_CipherInit() again with all parameters except the key set to NULL. It is
150possible for this function to fail if the cipher does not have any ASN1 support
151or the parameters cannot be set (for example the RC2 effective key length
152does not have an B<EVP_CIPHER> structure).
153
154=head1 RETURN VALUES
155
156EVP_EncryptInit(), EVP_EncryptUpdate() and EVP_EncryptFinal() do not return
157values.
158
159EVP_DecryptInit() and EVP_DecryptUpdate() do not return values.
160EVP_DecryptFinal() returns 0 if the decrypt failed or 1 for success.
161
162EVP_CipherInit() and EVP_CipherUpdate() do not return values.
163EVP_CipherFinal() returns 1 for a decryption failure or 1 for success, if
164the operation is encryption then it always returns 1.
165
166EVP_CIPHER_CTX_cleanup() does not return a value.
167
168EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
169return an B<EVP_CIPHER> structure or NULL on error.
170
171EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return a NID.
172
173EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
174size.
175
176EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
177length.
178
179EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
180length or zero if the cipher does not use an IV.
181
182EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the NID of the cipher's
183OBJECT IDENTIFIER or NID_undef if it has no defined OBJECT IDENTIFIER.
184
185EVP_CIPHER_CTX_cipher() returns an B<EVP_CIPHER> structure.
186
187EVP_CIPHER_param_to_asn1() and EVP_CIPHER_asn1_to_param() return 1 for
188success or zero for failure.
189
190=head1 NOTES
191
192Where possible the B<EVP> interface to symmetric ciphers should be used in
193preference to the low level interfaces. This is because the code then becomes
194transparent to the cipher used and much more flexible.
195
196PKCS padding works by adding B<n> padding bytes of value B<n> to make the total
197length of the encrypted data a multiple of the block size. Padding is always
198added so if the data is already a multiple of the block size B<n> will equal
199the block size. For example if the block size is 8 and 11 bytes are to be
200encrypted then 5 padding bytes of value 5 will be added.
201
202When decrypting the final block is checked to see if it has the correct form.
203
204Although the decryption operation can produce an error, it is not a strong
205test that the input data or key is correct. A random block has better than
2061 in 256 chance of being of the correct format and problems with the
207input data earlier on will not produce a final decrypt error.
208
209=head1 BUGS
210
211The current B<EVP> cipher interface is not as flexible as it should be. Only
212certain "spot" encryption algorithms can be used for ciphers which have various
213parameters associated with them (RC2, RC5 for example) this is inadequate.
214
215Several of the functions do not return error codes because the software versions
216can never fail. This is not true of hardware versions.
217
218=head1 SEE ALSO
219
220L<evp(3)|evp(3)>
221
222=head1 HISTORY
223
224=cut
diff --git a/src/lib/libcrypto/doc/EVP_OpenInit.pod b/src/lib/libcrypto/doc/EVP_OpenInit.pod
deleted file mode 100644
index 50edb124e4..0000000000
--- a/src/lib/libcrypto/doc/EVP_OpenInit.pod
+++ /dev/null
@@ -1,51 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_OpenInit, EVP_OpenUpdate, EVP_OpenFinal - EVP envelope decryption
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
12 int ekl,unsigned char *iv,EVP_PKEY *priv);
13 void EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 void EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
16 int *outl);
17
18=head1 DESCRIPTION
19
20The EVP envelope routines are a high level interface to envelope
21decryption. They decrypt a public key encrypted symmetric key and
22then decrypt data using it.
23
24EVP_OpenInit() initialises a cipher context B<ctx> for decryption
25with cipher B<type>. It decrypts the encrypted symmetric key of length
26B<ekl> bytes passed in the B<ek> parameter using the private key B<priv>.
27The IV is supplied in the B<iv> parameter.
28
29EVP_OpenUpdate() and EVP_OpenFinal() have exactly the same properties
30as the EVP_DecryptUpdate() and EVP_DecryptFinal() routines, as
31documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
32page.
33
34=head1 RETURN VALUES
35
36EVP_OpenInit() returns -1 on error or an non zero integer (actually the
37recovered secret key size) if successful.
38
39EVP_SealUpdate() does not return a value.
40
41EVP_SealFinal() returns 0 if the decrypt failed or 1 for success.
42
43=head1 SEE ALSO
44
45L<evp(3)|evp(3)>,
46L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
47L<EVP_SealInit(3)|EVP_SealInit(3)>
48
49=head1 HISTORY
50
51=cut
diff --git a/src/lib/libcrypto/doc/EVP_SealInit.pod b/src/lib/libcrypto/doc/EVP_SealInit.pod
deleted file mode 100644
index 42beed33bd..0000000000
--- a/src/lib/libcrypto/doc/EVP_SealInit.pod
+++ /dev/null
@@ -1,70 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
12 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
13 void EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
16 int *outl);
17
18=head1 DESCRIPTION
19
20The EVP envelope routines are a high level interface to envelope
21encryption. They generate a random key and then "envelope" it by
22using public key encryption. Data can then be encrypted using this
23key.
24
25EVP_SealInit() initialises a cipher context B<ctx> for encryption
26with cipher B<type> using a random secret key and IV supplied in
27the B<iv> parameter. B<type> is normally supplied by a function such
28as EVP_des_cbc(). The secret key is encrypted using one or more public
29keys, this allows the same encrypted data to be decrypted using any
30of the corresponding private keys. B<ek> is an array of buffers where
31the public key encrypted secret key will be written, each buffer must
32contain enough room for the corresponding encrypted key: that is
33B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual
34size of each encrypted secret key is written to the array B<ekl>. B<pubk> is
35an array of B<npubk> public keys.
36
37EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties
38as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as
39documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
40page.
41
42=head1 RETURN VALUES
43
44EVP_SealInit() returns -1 on error or B<npubk> if successful.
45
46EVP_SealUpdate() and EVP_SealFinal() do not return values.
47
48=head1 NOTES
49
50Because a random secret key is generated the random number generator
51must be seeded before calling EVP_SealInit().
52
53The public key must be RSA because it is the only OpenSSL public key
54algorithm that supports key transport.
55
56Envelope encryption is the usual method of using public key encryption
57on large amounts of data, this is because public key encryption is slow
58but symmetric encryption is fast. So symmetric encryption is used for
59bulk encryption and the small random symmetric key used is transferred
60using public key encryption.
61
62=head1 SEE ALSO
63
64L<evp(3)|evp(3)>,
65L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
66L<EVP_OpenInit(3)|EVP_OpenInit(3)>
67
68=head1 HISTORY
69
70=cut
diff --git a/src/lib/libcrypto/doc/EVP_SignInit.pod b/src/lib/libcrypto/doc/EVP_SignInit.pod
deleted file mode 100644
index 1167cefb45..0000000000
--- a/src/lib/libcrypto/doc/EVP_SignInit.pod
+++ /dev/null
@@ -1,85 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_SignInit, EVP_SignUpdate, EVP_SignFinal - EVP signing functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
12 void EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *sig,unsigned int *s, EVP_PKEY *pkey);
14
15 int EVP_PKEY_size(EVP_PKEY *pkey);
16
17=head1 DESCRIPTION
18
19The EVP signature routines are a high level interface to digital
20signatures.
21
22EVP_SignInit() initialises a signing context B<ctx> to using digest
23B<type>: this will typically be supplied by a function such as
24EVP_sha1().
25
26EVP_SignUpdate() hashes B<cnt> bytes of data at B<d> into the
27signature context B<ctx>. This funtion can be called several times on the
28same B<ctx> to include additional data.
29
30EVP_SignFinal() signs the data in B<ctx> using the private key B<pkey>
31and places the signature in B<sig>. If the B<s> parameter is not NULL
32then the number of bytes of data written (i.e. the length of the signature)
33will be written to the integer at B<s>, at most EVP_PKEY_size(pkey) bytes
34will be written. After calling EVP_SignFinal() no additional calls to
35EVP_SignUpdate() can be made, but EVP_SignInit() can be called to initialiase
36a new signature operation.
37
38EVP_PKEY_size() returns the maximum size of a signature in bytes. The actual
39signature returned by EVP_SignFinal() may be smaller.
40
41=head1 RETURN VALUES
42
43EVP_SignInit() and EVP_SignUpdate() do not return values.
44
45EVP_SignFinal() returns 1 for success and 0 for failure.
46
47EVP_PKEY_size() returns the maximum size of a signature in bytes.
48
49The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
50
51=head1 NOTES
52
53The B<EVP> interface to digital signatures should almost always be used in
54preference to the low level interfaces. This is because the code then becomes
55transparent to the algorithm used and much more flexible.
56
57Due to the link between message digests and public key algorithms the correct
58digest algorithm must be used with the correct public key type. A list of
59algorithms and associated public key algorithms appears in
60L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
61
62When signing with DSA private keys the random number generator must be seeded
63or the operation will fail. The random number generator does not need to be
64seeded for RSA signatures.
65
66=head1 BUGS
67
68Several of the functions do not return values: maybe they should. Although the
69internal digest operations will never fail some future hardware based operations
70might.
71
72=head1 SEE ALSO
73
74L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
75L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
76L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
77L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD(3)|RIPEMD(3)>,
78L<SHA1(3)|SHA1(3)>, L<digest(1)|digest(1)>
79
80=head1 HISTORY
81
82EVP_SignInit(), EVP_SignUpdate() and EVP_SignFinal() are
83available in all versions of SSLeay and OpenSSL.
84
85=cut
diff --git a/src/lib/libcrypto/doc/EVP_VerifyInit.pod b/src/lib/libcrypto/doc/EVP_VerifyInit.pod
deleted file mode 100644
index 5e74c5dcf9..0000000000
--- a/src/lib/libcrypto/doc/EVP_VerifyInit.pod
+++ /dev/null
@@ -1,71 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_VerifyInit, EVP_VerifyUpdate, EVP_VerifyFinal - EVP signature verification functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type);
12 void EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, unsigned int siglen,EVP_PKEY *pkey);
14
15=head1 DESCRIPTION
16
17The EVP signature verification routines are a high level interface to digital
18signatures.
19
20EVP_VerifyInit() initialises a verification context B<ctx> to using digest
21B<type>: this will typically be supplied by a function such as EVP_sha1().
22
23EVP_VerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
24verification context B<ctx>. This funtion can be called several times on the
25same B<ctx> to include additional data.
26
27EVP_VerifyFinal() verifies the data in B<ctx> using the public key B<pkey>
28and against the B<siglen> bytes at B<sigbuf>. After calling EVP_VerifyFinal()
29no additional calls to EVP_VerifyUpdate() can be made, but EVP_VerifyInit()
30can be called to initialiase a new verification operation.
31
32=head1 RETURN VALUES
33
34EVP_VerifyInit() and EVP_VerifyUpdate() do not return values.
35
36EVP_VerifyFinal() returns 1 for a correct signature, 0 for failure and -1 if some
37other error occurred.
38
39The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
40
41=head1 NOTES
42
43The B<EVP> interface to digital signatures should almost always be used in
44preference to the low level interfaces. This is because the code then becomes
45transparent to the algorithm used and much more flexible.
46
47Due to the link between message digests and public key algorithms the correct
48digest algorithm must be used with the correct public key type. A list of
49algorithms and associated public key algorithms appears in
50L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
51
52=head1 BUGS
53
54Several of the functions do not return values: maybe they should. Although the
55internal digest operations will never fail some future hardware based operations
56might.
57
58=head1 SEE ALSO
59
60L<EVP_SignInit(3)|EVP_SignInit(3)>,
61L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
62L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
63L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD(3)|RIPEMD(3)>,
64L<SHA1(3)|SHA1(3)>, L<digest(1)|digest(1)>
65
66=head1 HISTORY
67
68EVP_VerifyInit(), EVP_VerifyUpdate() and EVP_VerifyFinal() are
69available in all versions of SSLeay and OpenSSL.
70
71=cut
diff --git a/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod b/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod
deleted file mode 100644
index b0b1058d19..0000000000
--- a/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod
+++ /dev/null
@@ -1,46 +0,0 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_VERSION_NUMBER, SSLeay - get OpenSSL version number
6
7=head1 SYNOPSIS
8
9 #include <openssl/opensslv.h>
10 #define OPENSSL_VERSION_NUMBER 0xnnnnnnnnnL
11
12 #include <openssl/crypto.h>
13 long SSLeay(void);
14
15=head1 DESCRIPTION
16
17OPENSSL_VERSION_NUMBER is a numeric release version identifier:
18
19 MMNNFFRBB major minor fix final beta/patch
20
21for example
22
23 0x000904100 == 0.9.4 release
24 0x000905000 == 0.9.5 dev
25
26Versions prior to 0.9.3 have identifiers E<lt> 0x0930.
27For backward compatibility, SSLEAY_VERSION_NUMBER is also defined.
28
29SSLeay() returns this number. The return value can be compared to the
30macro to make sure that the correct version of the library has been
31loaded, especially when using DLLs on Windows systems.
32
33=head1 RETURN VALUE
34
35The version number.
36
37=head1 SEE ALSO
38
39L<crypto(3)|crypto(3)>
40
41=head1 HISTORY
42
43SSLeay() and SSLEAY_VERSION_NUMBER are available in all versions of SSLeay and OpenSSL.
44OPENSSL_VERSION_NUMBER is available in all versions of OpenSSL.
45
46=cut
diff --git a/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod b/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod
deleted file mode 100644
index 015d4eaf36..0000000000
--- a/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod
+++ /dev/null
@@ -1,65 +0,0 @@
1=pod
2
3=head1 NAME
4
5OpenSSL_add_all_algorithms() - add algorithms to internal table
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void OpenSSL_add_all_algorithms(void);
12 void OpenSSL_add_all_ciphers(void);
13 void OpenSSL_add_all_digests(void);
14
15 void EVP_cleanup(void);
16
17=head1 DESCRIPTION
18
19OpenSSL keeps an internal table of digest algorithms and ciphers. It uses
20this table to lookup ciphers via functions such as EVP_get_cipher_byname().
21
22OpenSSL_add_all_digests() adds all digest algorithms to the table.
23
24OpenSSL_add_all_algorithms() adds all algorithms to the table (digests and
25ciphers).
26
27OpenSSL_add_all_ciphers() adds all encryption algorithms to the table including
28password based encryption algorithms.
29
30EVP_cleanup() removes all ciphers and digests from the table.
31
32=head1 RETURN VALUES
33
34None of the functions return a value.
35
36=head1 NOTES
37
38A typical application will call OpenSSL_add_all_algorithms() initially and
39EVP_cleanup() before exiting.
40
41An application does not need to add algorithms to use them explicitly, for example
42by EVP_sha1(). It just needs to add them if it (or any of the functions it calls)
43needs to lookup algorithms.
44
45The cipher and digest lookup functions are used in many parts of the library. If
46the table is not initialised several functions will misbehave and complain they
47cannot find algorithms. This includes the PEM, PKCS#12, SSL and S/MIME libraries.
48This is a common query in the OpenSSL mailing lists.
49
50Calling OpenSSL_add_all_algorithms() links in all algorithms: as a result a
51statically linked executable can be quite large. If this is important it is possible
52to just add the required ciphers and digests.
53
54=head1 BUGS
55
56Although the functions do not return error codes it is possible for them to fail.
57This will only happen as a result of a memory allocation failure so this is not
58too much of a problem in practice.
59
60=head1 SEE ALSO
61
62L<evp(3)|evp(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
63L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
64
65=cut
diff --git a/src/lib/libcrypto/doc/RAND_add.pod b/src/lib/libcrypto/doc/RAND_add.pod
deleted file mode 100644
index 67c66f3e0c..0000000000
--- a/src/lib/libcrypto/doc/RAND_add.pod
+++ /dev/null
@@ -1,77 +0,0 @@
1=pod
2
3=head1 NAME
4
5RAND_add, RAND_seed, RAND_status, RAND_event, RAND_screen - add
6entropy to the PRNG
7
8=head1 SYNOPSIS
9
10 #include <openssl/rand.h>
11
12 void RAND_seed(const void *buf, int num);
13
14 void RAND_add(const void *buf, int num, double entropy);
15
16 int RAND_status(void);
17
18 int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam);
19 void RAND_screen(void);
20
21=head1 DESCRIPTION
22
23RAND_add() mixes the B<num> bytes at B<buf> into the PRNG state. Thus,
24if the data at B<buf> are unpredictable to an adversary, this
25increases the uncertainty about the state and makes the PRNG output
26less predictable. Suitable input comes from user interaction (random
27key presses, mouse movements) and certain hardware events. The
28B<entropy> argument is (the lower bound of) an estimate of how much
29randomness is contained in B<buf>, measured in bytes. Details about
30sources of randomness and how to estimate their entropy can be found
31in the literature, e.g. RFC 1750.
32
33RAND_add() may be called with sensitive data such as user entered
34passwords. The seed values cannot be recovered from the PRNG output.
35
36OpenSSL makes sure that the PRNG state is unique for each thread. On
37systems that provide C</dev/urandom>, the randomness device is used
38to seed the PRNG transparently. However, on all other systems, the
39application is responsible for seeding the PRNG by calling RAND_add(),
40L<RAND_egd(3)|RAND_egd(3)>
41or L<RAND_load_file(3)|RAND_load_file(3)>.
42
43RAND_seed() is equivalent to RAND_add() when B<num == entropy>.
44
45RAND_event() collects the entropy from Windows events such as mouse
46movements and other user interaction. It should be called with the
47B<iMsg>, B<wParam> and B<lParam> arguments of I<all> messages sent to
48the window procedure. It will estimate the entropy contained in the
49event message (if any), and add it to the PRNG. The program can then
50process the messages as usual.
51
52The RAND_screen() function is available for the convenience of Windows
53programmers. It adds the current contents of the screen to the PRNG.
54For applications that can catch Windows events, seeding the PRNG by
55calling RAND_event() is a significantly better source of
56randomness. It should be noted that both methods cannot be used on
57servers that run without user interaction.
58
59=head1 RETURN VALUES
60
61RAND_status() and RAND_event() return 1 if the PRNG has been seeded
62with enough data, 0 otherwise.
63
64The other functions do not return values.
65
66=head1 SEE ALSO
67
68L<rand(3)|rand(3)>, L<RAND_egd(3)|RAND_egd(3)>,
69L<RAND_load_file(3)|RAND_load_file(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
70
71=head1 HISTORY
72
73RAND_seed() and RAND_screen() are available in all versions of SSLeay
74and OpenSSL. RAND_add() and RAND_status() have been added in OpenSSL
750.9.5, RAND_event() in OpenSSL 0.9.5a.
76
77=cut
diff --git a/src/lib/libcrypto/doc/RAND_bytes.pod b/src/lib/libcrypto/doc/RAND_bytes.pod
deleted file mode 100644
index b03748b918..0000000000
--- a/src/lib/libcrypto/doc/RAND_bytes.pod
+++ /dev/null
@@ -1,46 +0,0 @@
1=pod
2
3=head1 NAME
4
5RAND_bytes, RAND_pseudo_bytes - generate random data
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 int RAND_bytes(unsigned char *buf, int num);
12
13 int RAND_pseudo_bytes(unsigned char *buf, int num);
14
15=head1 DESCRIPTION
16
17RAND_bytes() puts B<num> cryptographically strong pseudo-random bytes
18into B<buf>. An error occurs if the PRNG has not been seeded with
19enough randomness to ensure an unpredictable byte sequence.
20
21RAND_pseudo_bytes() puts B<num> pseudo-random bytes into B<buf>.
22Pseudo-random byte sequences generated by RAND_pseudo_bytes() will be
23unique if they are of sufficient length, but are not necessarily
24unpredictable. They can be used for non-cryptographic purposes and for
25certain purposes in cryptographic protocols, but usually not for key
26generation etc.
27
28=head1 RETURN VALUES
29
30RAND_bytes() returns 1 on success, 0 otherwise. The error code can be
31obtained by L<ERR_get_error(3)|ERR_get_error(3)>. RAND_pseudo_bytes() returns 1 if the
32bytes generated are cryptographically strong, 0 otherwise. Both
33functions return -1 if they are not supported by the current RAND
34method.
35
36=head1 SEE ALSO
37
38L<rand(3)|rand(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<RAND_add(3)|RAND_add(3)>
39
40=head1 HISTORY
41
42RAND_bytes() is available in all versions of SSLeay and OpenSSL. It
43has a return value since OpenSSL 0.9.5. RAND_pseudo_bytes() was added
44in OpenSSL 0.9.5.
45
46=cut
diff --git a/src/lib/libcrypto/doc/RAND_cleanup.pod b/src/lib/libcrypto/doc/RAND_cleanup.pod
deleted file mode 100644
index 3a8f0749a8..0000000000
--- a/src/lib/libcrypto/doc/RAND_cleanup.pod
+++ /dev/null
@@ -1,29 +0,0 @@
1=pod
2
3=head1 NAME
4
5RAND_cleanup - erase the PRNG state
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_cleanup(void);
12
13=head1 DESCRIPTION
14
15RAND_cleanup() erases the memory used by the PRNG.
16
17=head1 RETURN VALUE
18
19RAND_cleanup() returns no value.
20
21=head1 SEE ALSO
22
23L<rand(3)|rand(3)>
24
25=head1 HISTORY
26
27RAND_cleanup() is available in all versions of SSLeay and OpenSSL.
28
29=cut
diff --git a/src/lib/libcrypto/doc/RAND_load_file.pod b/src/lib/libcrypto/doc/RAND_load_file.pod
deleted file mode 100644
index 8dd700ca3d..0000000000
--- a/src/lib/libcrypto/doc/RAND_load_file.pod
+++ /dev/null
@@ -1,53 +0,0 @@
1=pod
2
3=head1 NAME
4
5RAND_load_file, RAND_write_file, RAND_file_name - PRNG seed file
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 const char *RAND_file_name(char *buf, int num);
12
13 int RAND_load_file(const char *filename, long max_bytes);
14
15 int RAND_write_file(const char *filename);
16
17=head1 DESCRIPTION
18
19RAND_file_name() generates a default path for the random seed
20file. B<buf> points to a buffer of size B<num> in which to store the
21filename. The seed file is $RANDFILE if that environment variable is
22set, $HOME/.rnd otherwise. If $HOME is not set either, or B<num> is
23too small for the path name, an error occurs.
24
25RAND_load_file() reads a number of bytes from file B<filename> and
26adds them to the PRNG. If B<max_bytes> is non-negative,
27up to to B<max_bytes> are read; starting with OpenSSL 0.9.5,
28if B<max_bytes> is -1, the complete file is read.
29
30RAND_write_file() writes a number of random bytes (currently 1024) to
31file B<filename> which can be used to initialize the PRNG by calling
32RAND_load_file() in a later session.
33
34=head1 RETURN VALUES
35
36RAND_load_file() returns the number of bytes read.
37
38RAND_write_file() returns the number of bytes written, and -1 if the
39bytes written were generated without appropriate seed.
40
41RAND_file_name() returns a pointer to B<buf> on success, and NULL on
42error.
43
44=head1 SEE ALSO
45
46L<rand(3)|rand(3)>, L<RAND_add(3)|RAND_add(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
47
48=head1 HISTORY
49
50RAND_load_file(), RAND_write_file() and RAND_file_name() are available in
51all versions of SSLeay and OpenSSL.
52
53=cut
diff --git a/src/lib/libcrypto/doc/RAND_set_rand_method.pod b/src/lib/libcrypto/doc/RAND_set_rand_method.pod
deleted file mode 100644
index 464eba416d..0000000000
--- a/src/lib/libcrypto/doc/RAND_set_rand_method.pod
+++ /dev/null
@@ -1,59 +0,0 @@
1=pod
2
3=head1 NAME
4
5RAND_set_rand_method, RAND_get_rand_method, RAND_SSLeay - select RAND method
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_set_rand_method(RAND_METHOD *meth);
12
13 RAND_METHOD *RAND_get_rand_method(void);
14
15 RAND_METHOD *RAND_SSLeay(void);
16
17=head1 DESCRIPTION
18
19A B<RAND_METHOD> specifies the functions that OpenSSL uses for random
20number generation. By modifying the method, alternative
21implementations such as hardware RNGs may be used. Initially, the
22default is to use the OpenSSL internal implementation. RAND_SSLeay()
23returns a pointer to that method.
24
25RAND_set_rand_method() sets the RAND method to B<meth>.
26RAND_get_rand_method() returns a pointer to the current method.
27
28=head1 THE RAND_METHOD STRUCTURE
29
30 typedef struct rand_meth_st
31 {
32 void (*seed)(const void *buf, int num);
33 int (*bytes)(unsigned char *buf, int num);
34 void (*cleanup)(void);
35 void (*add)(const void *buf, int num, int entropy);
36 int (*pseudorand)(unsigned char *buf, int num);
37 int (*status)(void);
38 } RAND_METHOD;
39
40The components point to the implementation of RAND_seed(),
41RAND_bytes(), RAND_cleanup(), RAND_add(), RAND_pseudo_rand()
42and RAND_status().
43Each component may be NULL if the function is not implemented.
44
45=head1 RETURN VALUES
46
47RAND_set_rand_method() returns no value. RAND_get_rand_method() and
48RAND_SSLeay() return pointers to the respective methods.
49
50=head1 SEE ALSO
51
52L<rand(3)|rand(3)>
53
54=head1 HISTORY
55
56RAND_set_rand_method(), RAND_get_rand_method() and RAND_SSLeay() are
57available in all versions of OpenSSL.
58
59=cut
diff --git a/src/lib/libcrypto/doc/RSA_blinding_on.pod b/src/lib/libcrypto/doc/RSA_blinding_on.pod
deleted file mode 100644
index fd2c69abd8..0000000000
--- a/src/lib/libcrypto/doc/RSA_blinding_on.pod
+++ /dev/null
@@ -1,43 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_blinding_on, RSA_blinding_off - protect the RSA operation from timing attacks
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
12
13 void RSA_blinding_off(RSA *rsa);
14
15=head1 DESCRIPTION
16
17RSA is vulnerable to timing attacks. In a setup where attackers can
18measure the time of RSA decryption or signature operations, blinding
19must be used to protect the RSA operation from that attack.
20
21RSA_blinding_on() turns blinding on for key B<rsa> and generates a
22random blinding factor. B<ctx> is B<NULL> or a pre-allocated and
23initialized B<BN_CTX>. The random number generator must be seeded
24prior to calling RSA_blinding_on().
25
26RSA_blinding_off() turns blinding off and frees the memory used for
27the blinding factor.
28
29=head1 RETURN VALUES
30
31RSA_blinding_on() returns 1 on success, and 0 if an error occurred.
32
33RSA_blinding_off() returns no value.
34
35=head1 SEE ALSO
36
37L<rsa(3)|rsa(3)>, L<rand(3)|rand(3)>
38
39=head1 HISTORY
40
41RSA_blinding_on() and RSA_blinding_off() appeared in SSLeay 0.9.0.
42
43=cut
diff --git a/src/lib/libcrypto/doc/RSA_check_key.pod b/src/lib/libcrypto/doc/RSA_check_key.pod
deleted file mode 100644
index 1db6d736ab..0000000000
--- a/src/lib/libcrypto/doc/RSA_check_key.pod
+++ /dev/null
@@ -1,39 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_check_key - validate private RSA keys
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_check_key(RSA *rsa);
12
13=head1 DESCRIPTION
14
15This function validates RSA keys. It checks that B<p> and B<q> are
16in fact prime, and that B<n = p*q>.
17
18It also checks that B<d*e = 1 mod (p-1*q-1)>,
19and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>.
20
21The key's public components may not be B<NULL>.
22
23=head1 RETURN VALUE
24
25RSA_check_key() returns 1 if B<rsa> is a valid RSA key, and 0 otherwise.
26-1 is returned if an error occurs while checking the key.
27
28If the key is invalid or an error occurred, the reason code can be
29obtained using L<ERR_get_error(3)|ERR_get_error(3)>.
30
31=head1 SEE ALSO
32
33L<rsa(3)|rsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
34
35=head1 HISTORY
36
37RSA_check() appeared in OpenSSL 0.9.4.
38
39=cut
diff --git a/src/lib/libcrypto/doc/RSA_generate_key.pod b/src/lib/libcrypto/doc/RSA_generate_key.pod
deleted file mode 100644
index 0e0f0a764c..0000000000
--- a/src/lib/libcrypto/doc/RSA_generate_key.pod
+++ /dev/null
@@ -1,68 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_generate_key - generate RSA key pair
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA *RSA_generate_key(int num, unsigned long e,
12 void (*callback)(int,int,void *), void *cb_arg);
13
14=head1 DESCRIPTION
15
16RSA_generate_key() generates a key pair and returns it in a newly
17allocated B<RSA> structure. The pseudo-random number generator must
18be seeded prior to calling RSA_generate_key().
19
20The modulus size will be B<num> bits, and the public exponent will be
21B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure.
22The exponent is an odd number, typically 3 or 65535.
23
24A callback function may be used to provide feedback about the
25progress of the key generation. If B<callback> is not B<NULL>, it
26will be called as follows:
27
28=over 4
29
30=item *
31
32While a random prime number is generated, it is called as
33described in L<BN_generate_prime(3)|BN_generate_prime(3)>.
34
35=item *
36
37When the n-th randomly generated prime is rejected as not
38suitable for the key, B<callback(2, n, cb_arg)> is called.
39
40=item *
41
42When a random p has been found with p-1 relatively prime to B<e>,
43it is called as B<callback(3, 0, cb_arg)>.
44
45=back
46
47The process is then repeated for prime q with B<callback(3, 1, cb_arg)>.
48
49=head1 RETURN VALUE
50
51If key generation fails, RSA_generate_key() returns B<NULL>; the
52error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
53
54=head1 BUGS
55
56B<callback(2, x, cb_arg)> is used with two different meanings.
57
58RSA_generate_key() goes into an infinite loop for illegal input values.
59
60=head1 SEE ALSO
61
62L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_free(3)|RSA_free(3)>
63
64=head1 HISTORY
65
66The B<cb_arg> argument was added in SSLeay 0.9.0.
67
68=cut
diff --git a/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod b/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
deleted file mode 100644
index 920dc76325..0000000000
--- a/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
+++ /dev/null
@@ -1,122 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_get_ex_new_index, RSA_set_ex_data, RSA_get_ex_data - add application specific data to RSA structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int RSA_set_ex_data(RSA *r, int idx, void *arg);
17
18 void *RSA_get_ex_data(RSA *r, int idx);
19
20 int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22
23 void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
24 int idx, long argl, void *argp);
25
26 int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
27 int idx, long argl, void *argp);
28
29=head1 DESCRIPTION
30
31Several OpenSSL structures can have application specific data attached to them.
32This has several potential uses, it can be used to cache data associated with
33a structure (for example the hash of some part of the structure) or some
34additional data (for example a handle to the data in an external library).
35
36Since the application data can be anything at all it is passed and retrieved
37as a B<void *> type.
38
39The B<RSA_get_ex_new_index()> function is initially called to "register" some
40new application specific data. It takes three optional function pointers which
41are called when the parent structure (in this case an RSA structure) is
42initially created, when it is copied and when it is freed up. If any or all of
43these function pointer arguments are not used they should be set to NULL. The
44precise manner in which these function pointers are called is described in more
45detail below. B<RSA_get_ex_new_index()> also takes additional long and pointer
46parameters which will be passed to the supplied functions but which otherwise
47have no special meaning. It returns an B<index> which should be stored
48(typically in a static variable) and passed used in the B<idx> parameter in
49the remaining functions. Each successful call to B<RSA_get_ex_new_index()>
50will return an index greater than any previously returned, this is important
51because the optional functions are called in order of increasing index value.
52
53B<RSA_set_ex_data()> is used to set application specific data, the data is
54supplied in the B<arg> parameter and its precise meaning is up to the
55application.
56
57B<RSA_get_ex_data()> is used to retrieve application specific data. The data
58is returned to the application, this will be the same value as supplied to
59a previous B<RSA_set_ex_data()> call.
60
61B<new_func()> is called when a structure is initially allocated (for example
62with B<RSA_new()>. The parent structure members will not have any meaningful
63values at this point. This function will typically be used to allocate any
64application specific structure.
65
66B<free_func()> is called when a structure is being freed up. The dynamic parent
67structure members should not be accessed because they will be freed up when
68this function is called.
69
70B<new_func()> and B<free_func()> take the same parameters. B<parent> is a
71pointer to the parent RSA structure. B<ptr> is a the application specific data
72(this wont be of much use in B<new_func()>. B<ad> is a pointer to the
73B<CRYPTO_EX_DATA> structure from the parent RSA structure: the functions
74B<CRYPTO_get_ex_data()> and B<CRYPTO_set_ex_data()> can be called to manipulate
75it. The B<idx> parameter is the index: this will be the same value returned by
76B<RSA_get_ex_new_index()> when the functions were initially registered. Finally
77the B<argl> and B<argp> parameters are the values originally passed to the same
78corresponding parameters when B<RSA_get_ex_new_index()> was called.
79
80B<dup_func()> is called when a structure is being copied. Pointers to the
81destination and source B<CRYPTO_EX_DATA> structures are passed in the B<to> and
82B<from> parameters respectively. The B<from_d> parameter is passed a pointer to
83the source application data when the function is called, when the function returns
84the value is copied to the destination: the application can thus modify the data
85pointed to by B<from_d> and have different values in the source and destination.
86The B<idx>, B<argl> and B<argp> parameters are the same as those in B<new_func()>
87and B<free_func()>.
88
89=head1 RETURN VALUES
90
91B<RSA_get_ex_new_index()> returns a new index or -1 on failure (note 0 is a valid
92index value).
93
94B<RSA_set_ex_data()> returns 1 on success or 0 on failure.
95
96B<RSA_get_ex_data()> returns the application data or 0 on failure. 0 may also
97be valid application data but currently it can only fail if given an invalid B<idx>
98parameter.
99
100B<new_func()> and B<dup_func()> should return 0 for failure and 1 for success.
101
102On failure an error code can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
103
104=head1 BUGS
105
106B<dup_func()> is currently never called.
107
108The return value of B<new_func()> is ignored.
109
110The B<new_func()> function isn't very useful because no meaningful values are
111present in the parent RSA structure when it is called.
112
113=head1 SEE ALSO
114
115L<rsa(3)|rsa(3)>, L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
116
117=head1 HISTORY
118
119RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data() are
120available since SSLeay 0.9.0.
121
122=cut
diff --git a/src/lib/libcrypto/doc/RSA_new.pod b/src/lib/libcrypto/doc/RSA_new.pod
deleted file mode 100644
index 299047f31f..0000000000
--- a/src/lib/libcrypto/doc/RSA_new.pod
+++ /dev/null
@@ -1,39 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_new, RSA_free - allocate and free RSA objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * RSA_new(void);
12
13 void RSA_free(RSA *rsa);
14
15=head1 DESCRIPTION
16
17RSA_new() allocates and initializes an B<RSA> structure.
18
19RSA_free() frees the B<RSA> structure and its components. The key is
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, RSA_new() returns B<NULL> and sets an error
25code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
26a pointer to the newly allocated structure.
27
28RSA_free() returns no value.
29
30=head1 SEE ALSO
31
32L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>,
33L<RSA_generate_key(3)|RSA_generate_key(3)>
34
35=head1 HISTORY
36
37RSA_new() and RSA_free() are available in all versions of SSLeay and OpenSSL.
38
39=cut
diff --git a/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod b/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod
deleted file mode 100644
index b8f678fe72..0000000000
--- a/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod
+++ /dev/null
@@ -1,124 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_padding_add_PKCS1_type_1, RSA_padding_check_PKCS1_type_1,
6RSA_padding_add_PKCS1_type_2, RSA_padding_check_PKCS1_type_2,
7RSA_padding_add_PKCS1_OAEP, RSA_padding_check_PKCS1_OAEP,
8RSA_padding_add_SSLv23, RSA_padding_check_SSLv23,
9RSA_padding_add_none, RSA_padding_check_none - asymmetric encryption
10padding
11
12=head1 SYNOPSIS
13
14 #include <openssl/rsa.h>
15
16 int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
17 unsigned char *f, int fl);
18
19 int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
20 unsigned char *f, int fl, int rsa_len);
21
22 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
23 unsigned char *f, int fl);
24
25 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
26 unsigned char *f, int fl, int rsa_len);
27
28 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
29 unsigned char *f, int fl, unsigned char *p, int pl);
30
31 int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
32 unsigned char *f, int fl, int rsa_len, unsigned char *p, int pl);
33
34 int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
35 unsigned char *f, int fl);
36
37 int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
38 unsigned char *f, int fl, int rsa_len);
39
40 int RSA_padding_add_none(unsigned char *to, int tlen,
41 unsigned char *f, int fl);
42
43 int RSA_padding_check_none(unsigned char *to, int tlen,
44 unsigned char *f, int fl, int rsa_len);
45
46=head1 DESCRIPTION
47
48The RSA_padding_xxx_xxx() functions are called from the RSA encrypt,
49decrypt, sign and verify functions. Normally they should not be called
50from application programs.
51
52However, they can also be called directly to implement padding for other
53asymmetric ciphers. RSA_padding_add_PKCS1_OAEP() and
54RSA_padding_check_PKCS1_OAEP() may be used in an application combined
55with B<RSA_NO_PADDING> in order to implement OAEP with an encoding
56parameter.
57
58RSA_padding_add_xxx() encodes B<fl> bytes from B<f> so as to fit into
59B<tlen> bytes and stores the result at B<to>. An error occurs if B<fl>
60does not meet the size requirements of the encoding method.
61
62The following encoding methods are implemented:
63
64=over 4
65
66=item PKCS1_type_1
67
68PKCS #1 v2.0 EMSA-PKCS1-v1_5 (PKCS #1 v1.5 block type 1); used for signatures
69
70=item PKCS1_type_2
71
72PKCS #1 v2.0 EME-PKCS1-v1_5 (PKCS #1 v1.5 block type 2)
73
74=item PKCS1_OAEP
75
76PKCS #1 v2.0 EME-OAEP
77
78=item SSLv23
79
80PKCS #1 EME-PKCS1-v1_5 with SSL-specific modification
81
82=item none
83
84simply copy the data
85
86=back
87
88The random number generator must be seeded prior to calling
89RSA_padding_add_xxx().
90
91RSA_padding_check_xxx() verifies that the B<fl> bytes at B<f> contain
92a valid encoding for a B<rsa_len> byte RSA key in the respective
93encoding method and stores the recovered data of at most B<tlen> bytes
94(for B<RSA_NO_PADDING>: of size B<tlen>)
95at B<to>.
96
97For RSA_padding_xxx_OAEP(), B<p> points to the encoding parameter
98of length B<pl>. B<p> may be B<NULL> if B<pl> is 0.
99
100=head1 RETURN VALUES
101
102The RSA_padding_add_xxx() functions return 1 on success, 0 on error.
103The RSA_padding_check_xxx() functions return the length of the
104recovered data, -1 on error. Error codes can be obtained by calling
105L<ERR_get_error(3)|ERR_get_error(3)>.
106
107=head1 SEE ALSO
108
109L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
110L<RSA_private_decrypt(3)|RSA_private_decrypt(3)>,
111L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
112
113=head1 HISTORY
114
115RSA_padding_add_PKCS1_type_1(), RSA_padding_check_PKCS1_type_1(),
116RSA_padding_add_PKCS1_type_2(), RSA_padding_check_PKCS1_type_2(),
117RSA_padding_add_SSLv23(), RSA_padding_check_SSLv23(),
118RSA_padding_add_none() and RSA_padding_check_none() appeared in
119SSLeay 0.9.0.
120
121RSA_padding_add_PKCS1_OAEP() and RSA_padding_check_PKCS1_OAEP() were
122added in OpenSSL 0.9.2b.
123
124=cut
diff --git a/src/lib/libcrypto/doc/RSA_print.pod b/src/lib/libcrypto/doc/RSA_print.pod
deleted file mode 100644
index dd968a5274..0000000000
--- a/src/lib/libcrypto/doc/RSA_print.pod
+++ /dev/null
@@ -1,48 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_print, RSA_print_fp, DHparams_print, DHparams_print_fp - print
6cryptographic parameters
7
8=head1 SYNOPSIS
9
10 #include <openssl/rsa.h>
11
12 int RSA_print(BIO *bp, RSA *x, int offset);
13 int RSA_print_fp(FILE *fp, RSA *x, int offset);
14
15 #include <openssl/dsa.h>
16
17 int DSAparams_print(BIO *bp, DSA *x);
18 int DSAparams_print_fp(FILE *fp, DSA *x);
19 int DSA_print(BIO *bp, DSA *x, int offset);
20 int DSA_print_fp(FILE *fp, DSA *x, int offset);
21
22 #include <openssl/dh.h>
23
24 int DHparams_print(BIO *bp, DH *x);
25 int DHparams_print_fp(FILE *fp, DH *x);
26
27=head1 DESCRIPTION
28
29A human-readable hexadecimal output of the components of the RSA
30key, DSA parameters or key or DH parameters is printed to B<bp> or B<fp>.
31
32The output lines are indented by B<offset> spaces.
33
34=head1 RETURN VALUES
35
36These functions return 1 on success, 0 on error.
37
38=head1 SEE ALSO
39
40L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<rsa(3)|rsa(3)>, L<BN_bn2bin(3)|BN_bn2bin(3)>
41
42=head1 HISTORY
43
44RSA_print(), RSA_print_fp(), DSA_print(), DSA_print_fp(), DH_print(),
45DH_print_fp() are available in all versions of SSLeay and OpenSSL.
46DSAparams_print() and DSAparams_print_pf() were added in SSLeay 0.8.
47
48=cut
diff --git a/src/lib/libcrypto/doc/RSA_private_encrypt.pod b/src/lib/libcrypto/doc/RSA_private_encrypt.pod
deleted file mode 100644
index 0d1b2bd541..0000000000
--- a/src/lib/libcrypto/doc/RSA_private_encrypt.pod
+++ /dev/null
@@ -1,70 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_private_encrypt, RSA_public_decrypt - low level signature operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_private_encrypt(int flen, unsigned char *from,
12 unsigned char *to, RSA *rsa, int padding);
13
14 int RSA_public_decrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16
17=head1 DESCRIPTION
18
19These functions handle RSA signatures at a low level.
20
21RSA_private_encrypt() signs the B<flen> bytes at B<from> (usually a
22message digest with an algorithm identifier) using the private key
23B<rsa> and stores the signature in B<to>. B<to> must point to
24B<RSA_size(rsa)> bytes of memory.
25
26B<padding> denotes one of the following modes:
27
28=over 4
29
30=item RSA_PKCS1_PADDING
31
32PKCS #1 v1.5 padding. This function does not handle the
33B<algorithmIdentifier> specified in PKCS #1. When generating or
34verifying PKCS #1 signatures, L<RSA_sign(3)|RSA_sign(3)> and L<RSA_verify(3)|RSA_verify(3)> should be
35used.
36
37=item RSA_NO_PADDING
38
39Raw RSA signature. This mode should I<only> be used to implement
40cryptographically sound padding modes in the application code.
41Signing user data directly with RSA is insecure.
42
43=back
44
45RSA_public_decrypt() recovers the message digest from the B<flen>
46bytes long signature at B<from> using the signer's public key
47B<rsa>. B<to> must point to a memory section large enough to hold the
48message digest (which is smaller than B<RSA_size(rsa) -
4911>). B<padding> is the padding mode that was used to sign the data.
50
51=head1 RETURN VALUES
52
53RSA_private_encrypt() returns the size of the signature (i.e.,
54RSA_size(rsa)). RSA_public_decrypt() returns the size of the
55recovered message digest.
56
57On error, -1 is returned; the error codes can be
58obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
59
60=head1 SEE ALSO
61
62L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>,
63L<RSA_verify(3)|RSA_verify(3)>
64
65=head1 HISTORY
66
67The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
68available since SSLeay 0.9.0.
69
70=cut
diff --git a/src/lib/libcrypto/doc/RSA_public_encrypt.pod b/src/lib/libcrypto/doc/RSA_public_encrypt.pod
deleted file mode 100644
index 13b7df62be..0000000000
--- a/src/lib/libcrypto/doc/RSA_public_encrypt.pod
+++ /dev/null
@@ -1,86 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_public_encrypt, RSA_private_decrypt - RSA public key cryptography
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_public_encrypt(int flen, unsigned char *from,
12 unsigned char *to, RSA *rsa, int padding);
13
14 int RSA_private_decrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16
17=head1 DESCRIPTION
18
19RSA_public_encrypt() encrypts the B<flen> bytes at B<from> (usually a
20session key) using the public key B<rsa> and stores the ciphertext in
21B<to>. B<to> must point to RSA_size(B<rsa>) bytes of memory.
22
23B<padding> denotes one of the following modes:
24
25=over 4
26
27=item RSA_PKCS1_PADDING
28
29PKCS #1 v1.5 padding. This currently is the most widely used mode.
30
31=item RSA_PKCS1_OAEP_PADDING
32
33EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
34encoding parameter. This mode is recommended for all new applications.
35
36=item RSA_SSLV23_PADDING
37
38PKCS #1 v1.5 padding with an SSL-specific modification that denotes
39that the server is SSL3 capable.
40
41=item RSA_NO_PADDING
42
43Raw RSA encryption. This mode should I<only> be used to implement
44cryptographically sound padding modes in the application code.
45Encrypting user data directly with RSA is insecure.
46
47=back
48
49B<flen> must be less than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5
50based padding modes, and less than RSA_size(B<rsa>) - 21 for
51RSA_PKCS1_OAEP_PADDING. The random number generator must be seeded
52prior to calling RSA_public_encrypt().
53
54RSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the
55private key B<rsa> and stores the plaintext in B<to>. B<to> must point
56to a memory section large enough to hold the decrypted data (which is
57smaller than RSA_size(B<rsa>)). B<padding> is the padding mode that
58was used to encrypt the data.
59
60=head1 RETURN VALUES
61
62RSA_public_encrypt() returns the size of the encrypted data (i.e.,
63RSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the
64recovered plaintext.
65
66On error, -1 is returned; the error codes can be
67obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
68
69=head1 CONFORMING TO
70
71SSL, PKCS #1 v2.0
72
73=head1 SEE ALSO
74
75L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_size(3)|RSA_size(3)>
76
77=head1 NOTES
78
79The L<RSA_PKCS1_RSAref(3)|RSA_PKCS1_RSAref(3)> method supports only the RSA_PKCS1_PADDING mode.
80
81=head1 HISTORY
82
83The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
84available since SSLeay 0.9.0, OAEP was added in OpenSSL 0.9.2b.
85
86=cut
diff --git a/src/lib/libcrypto/doc/RSA_set_method.pod b/src/lib/libcrypto/doc/RSA_set_method.pod
deleted file mode 100644
index 14b0b4cf35..0000000000
--- a/src/lib/libcrypto/doc/RSA_set_method.pod
+++ /dev/null
@@ -1,154 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_set_default_method, RSA_get_default_method, RSA_set_method,
6RSA_get_method, RSA_PKCS1_SSLeay, RSA_PKCS1_RSAref,
7RSA_PKCS1_null_method, RSA_flags, RSA_new_method - select RSA method
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12
13 void RSA_set_default_method(RSA_METHOD *meth);
14
15 RSA_METHOD *RSA_get_default_method(void);
16
17 RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
18
19 RSA_METHOD *RSA_get_method(RSA *rsa);
20
21 RSA_METHOD *RSA_PKCS1_SSLeay(void);
22
23 RSA_METHOD *RSA_PKCS1_RSAref(void);
24
25 RSA_METHOD *RSA_null_method(void);
26
27 int RSA_flags(RSA *rsa);
28
29 RSA *RSA_new_method(RSA_METHOD *method);
30
31=head1 DESCRIPTION
32
33An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
34operations. By modifying the method, alternative implementations
35such as hardware accelerators may be used.
36
37Initially, the default is to use the OpenSSL internal implementation,
38unless OpenSSL was configured with the C<rsaref> or C<-DRSA_NULL>
39options. RSA_PKCS1_SSLeay() returns a pointer to that method.
40
41RSA_PKCS1_RSAref() returns a pointer to a method that uses the RSAref
42library. This is the default method in the C<rsaref> configuration;
43the function is not available in other configurations.
44RSA_null_method() returns a pointer to a method that does not support
45the RSA transformation. It is the default if OpenSSL is compiled with
46C<-DRSA_NULL>. These methods may be useful in the USA because of a
47patent on the RSA cryptosystem.
48
49RSA_set_default_method() makes B<meth> the default method for all B<RSA>
50structures created later.
51
52RSA_get_default_method() returns a pointer to the current default
53method.
54
55RSA_set_method() selects B<meth> for all operations using the key
56B<rsa>.
57
58RSA_get_method() returns a pointer to the method currently selected
59for B<rsa>.
60
61RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
62
63RSA_new_method() allocates and initializes an B<RSA> structure so that
64B<method> will be used for the RSA operations. If B<method> is B<NULL>,
65the default method is used.
66
67=head1 THE RSA_METHOD STRUCTURE
68
69 typedef struct rsa_meth_st
70 {
71 /* name of the implementation */
72 const char *name;
73
74 /* encrypt */
75 int (*rsa_pub_enc)(int flen, unsigned char *from,
76 unsigned char *to, RSA *rsa, int padding);
77
78 /* verify arbitrary data */
79 int (*rsa_pub_dec)(int flen, unsigned char *from,
80 unsigned char *to, RSA *rsa, int padding);
81
82 /* sign arbitrary data */
83 int (*rsa_priv_enc)(int flen, unsigned char *from,
84 unsigned char *to, RSA *rsa, int padding);
85
86 /* decrypt */
87 int (*rsa_priv_dec)(int flen, unsigned char *from,
88 unsigned char *to, RSA *rsa, int padding);
89
90 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
91 implementations) */
92 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
93
94 /* compute r = a ^ p mod m (May be NULL for some implementations) */
95 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
96 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
97
98 /* called at RSA_new */
99 int (*init)(RSA *rsa);
100
101 /* called at RSA_free */
102 int (*finish)(RSA *rsa);
103
104 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
105 * operations, even if p,q,dmp1,dmq1,iqmp
106 * are NULL
107 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
108 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
109 */
110 int flags;
111
112 char *app_data; /* ?? */
113
114 /* sign. For backward compatibility, this is used only
115 * if (flags & RSA_FLAG_SIGN_VER)
116 */
117 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
118 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
119
120 /* verify. For backward compatibility, this is used only
121 * if (flags & RSA_FLAG_SIGN_VER)
122 */
123 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
124 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
125
126 } RSA_METHOD;
127
128=head1 RETURN VALUES
129
130RSA_PKCS1_SSLeay(), RSA_PKCS1_RSAref(), RSA_PKCS1_null_method(),
131RSA_get_default_method() and RSA_get_method() return pointers to the
132respective B<RSA_METHOD>s.
133
134RSA_set_default_method() returns no value.
135
136RSA_set_method() returns a pointer to the B<RSA_METHOD> previously
137associated with B<rsa>.
138
139RSA_new_method() returns B<NULL> and sets an error code that can be
140obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
141returns a pointer to the newly allocated structure.
142
143=head1 SEE ALSO
144
145L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
146
147=head1 HISTORY
148
149RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
150RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
151well as the rsa_sign and rsa_verify components of RSA_METHOD were
152added in OpenSSL 0.9.4.
153
154=cut
diff --git a/src/lib/libcrypto/doc/RSA_sign.pod b/src/lib/libcrypto/doc/RSA_sign.pod
deleted file mode 100644
index 71688a665e..0000000000
--- a/src/lib/libcrypto/doc/RSA_sign.pod
+++ /dev/null
@@ -1,62 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_sign, RSA_verify - RSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
12 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
13
14 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
15 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
16
17=head1 DESCRIPTION
18
19RSA_sign() signs the message digest B<m> of size B<m_len> using the
20private key B<rsa> as specified in PKCS #1 v2.0. It stores the
21signature in B<sigret> and the signature size in B<siglen>. B<sigret>
22must point to RSA_size(B<rsa>) bytes of memory.
23
24B<type> denotes the message digest algorithm that was used to generate
25B<m>. It usually is one of B<NID_sha1>, B<NID_ripemd160> and B<NID_md5>;
26see L<objects(3)|objects(3)> for details. If B<type> is B<NID_md5_sha1>,
27an SSL signature (MD5 and SHA1 message digests with PKCS #1 padding
28and no algorithm identifier) is created.
29
30RSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
31matches a given message digest B<m> of size B<m_len>. B<type> denotes
32the message digest algorithm that was used to generate the signature.
33B<rsa> is the signer's public key.
34
35=head1 RETURN VALUES
36
37RSA_sign() returns 1 on success, 0 otherwise. RSA_verify() returns 1
38on successful verification, 0 otherwise.
39
40The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
41
42=head1 BUGS
43
44Certain signatures with an improper algorithm identifier are accepted
45for compatibility with SSLeay 0.4.5 :-)
46
47=head1 CONFORMING TO
48
49SSL, PKCS #1 v2.0
50
51=head1 SEE ALSO
52
53L<ERR_get_error(3)|ERR_get_error(3)>, L<objects(3)|objects(3)>,
54L<rsa(3)|rsa(3)>, L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
55L<RSA_public_decrypt(3)|RSA_public_decrypt(3)>
56
57=head1 HISTORY
58
59RSA_sign() and RSA_verify() are available in all versions of SSLeay
60and OpenSSL.
61
62=cut
diff --git a/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod b/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod
deleted file mode 100644
index b8c7bbb7e3..0000000000
--- a/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod
+++ /dev/null
@@ -1,59 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_sign_ASN1_OCTET_STRING, RSA_verify_ASN1_OCTET_STRING - RSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
12 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
13 RSA *rsa);
14
15 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
16 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
17 RSA *rsa);
18
19=head1 DESCRIPTION
20
21RSA_sign_ASN1_OCTET_STRING() signs the octet string B<m> of size
22B<m_len> using the private key B<rsa> represented in DER using PKCS #1
23padding. It stores the signature in B<sigret> and the signature size
24in B<siglen>. B<sigret> must point to B<RSA_size(rsa)> bytes of
25memory.
26
27B<dummy> is ignored.
28
29The random number generator must be seeded prior to calling RSA_sign_ASN1_OCTET_STRING().
30
31RSA_verify_ASN1_OCTET_STRING() verifies that the signature B<sigbuf>
32of size B<siglen> is the DER representation of a given octet string
33B<m> of size B<m_len>. B<dummy> is ignored. B<rsa> is the signer's
34public key.
35
36=head1 RETURN VALUES
37
38RSA_sign_ASN1_OCTET_STRING() returns 1 on success, 0 otherwise.
39RSA_verify_ASN1_OCTET_STRING() returns 1 on successful verification, 0
40otherwise.
41
42The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
43
44=head1 BUGS
45
46These functions serve no recognizable purpose.
47
48=head1 SEE ALSO
49
50L<ERR_get_error(3)|ERR_get_error(3)>, L<objects(3)|objects(3)>, L<rand(3)|rand(3)>,
51L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>,
52L<RSA_verify(3)|RSA_verify(3)>
53
54=head1 HISTORY
55
56RSA_sign_ASN1_OCTET_STRING() and RSA_verify_ASN1_OCTET_STRING() were
57added in SSLeay 0.8.
58
59=cut
diff --git a/src/lib/libcrypto/doc/RSA_size.pod b/src/lib/libcrypto/doc/RSA_size.pod
deleted file mode 100644
index b36b4d58d5..0000000000
--- a/src/lib/libcrypto/doc/RSA_size.pod
+++ /dev/null
@@ -1,33 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_size - get RSA modulus size
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_size(RSA *rsa);
12
13=head1 DESCRIPTION
14
15This function returns the RSA modulus size in bytes. It can be used to
16determine how much memory must be allocated for an RSA encrypted
17value.
18
19B<rsa-E<gt>n> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<rsa(3)|rsa(3)>
28
29=head1 HISTORY
30
31RSA_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/bn.pod b/src/lib/libcrypto/doc/bn.pod
deleted file mode 100644
index 1504a1c92d..0000000000
--- a/src/lib/libcrypto/doc/bn.pod
+++ /dev/null
@@ -1,148 +0,0 @@
1=pod
2
3=head1 NAME
4
5bn - multiprecision integer arithmetics
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BIGNUM *BN_new(void);
12 void BN_free(BIGNUM *a);
13 void BN_init(BIGNUM *);
14 void BN_clear(BIGNUM *a);
15 void BN_clear_free(BIGNUM *a);
16
17 BN_CTX *BN_CTX_new(void);
18 void BN_CTX_init(BN_CTX *c);
19 void BN_CTX_free(BN_CTX *c);
20
21 BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
22 BIGNUM *BN_dup(const BIGNUM *a);
23
24 int BN_num_bytes(const BIGNUM *a);
25 int BN_num_bits(const BIGNUM *a);
26 int BN_num_bits_word(BN_ULONG w);
27
28 int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
29 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
30 int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
31 int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
32 BN_CTX *ctx);
33 int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
34 int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
35 int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
36 BN_CTX *ctx);
37 int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
38 int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
39 const BIGNUM *m, BN_CTX *ctx);
40 int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
41
42 int BN_add_word(BIGNUM *a, BN_ULONG w);
43 int BN_sub_word(BIGNUM *a, BN_ULONG w);
44 int BN_mul_word(BIGNUM *a, BN_ULONG w);
45 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
46 BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
47
48 int BN_cmp(BIGNUM *a, BIGNUM *b);
49 int BN_ucmp(BIGNUM *a, BIGNUM *b);
50 int BN_is_zero(BIGNUM *a);
51 int BN_is_one(BIGNUM *a);
52 int BN_is_word(BIGNUM *a, BN_ULONG w);
53 int BN_is_odd(BIGNUM *a);
54
55 int BN_zero(BIGNUM *a);
56 int BN_one(BIGNUM *a);
57 BIGNUM *BN_value_one(void);
58 int BN_set_word(BIGNUM *a, unsigned long w);
59 unsigned long BN_get_word(BIGNUM *a);
60
61 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
62 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
63
64 BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
65 BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
66 int BN_is_prime(const BIGNUM *p, int nchecks,
67 void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
68
69 int BN_set_bit(BIGNUM *a, int n);
70 int BN_clear_bit(BIGNUM *a, int n);
71 int BN_is_bit_set(const BIGNUM *a, int n);
72 int BN_mask_bits(BIGNUM *a, int n);
73 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
74 int BN_lshift1(BIGNUM *r, BIGNUM *a);
75 int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
76 int BN_rshift1(BIGNUM *r, BIGNUM *a);
77
78 int BN_bn2bin(const BIGNUM *a, unsigned char *to);
79 BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
80 char *BN_bn2hex(const BIGNUM *a);
81 char *BN_bn2dec(const BIGNUM *a);
82 int BN_hex2bn(BIGNUM **a, const char *str);
83 int BN_dec2bn(BIGNUM **a, const char *str);
84 int BN_print(BIO *fp, const BIGNUM *a);
85 int BN_print_fp(FILE *fp, const BIGNUM *a);
86 int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
87 BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
88
89 BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
90 BN_CTX *ctx);
91
92 BN_RECP_CTX *BN_RECP_CTX_new(void);
93 void BN_RECP_CTX_init(BN_RECP_CTX *recp);
94 void BN_RECP_CTX_free(BN_RECP_CTX *recp);
95 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
96 int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
97 BN_RECP_CTX *recp, BN_CTX *ctx);
98
99 BN_MONT_CTX *BN_MONT_CTX_new(void);
100 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
101 void BN_MONT_CTX_free(BN_MONT_CTX *mont);
102 int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
103 BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
104 int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
105 BN_MONT_CTX *mont, BN_CTX *ctx);
106 int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
107 BN_CTX *ctx);
108 int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
109 BN_CTX *ctx);
110
111
112=head1 DESCRIPTION
113
114This library performs arithmetic operations on integers of arbitrary
115size. It was written for use in public key cryptography, such as RSA
116and Diffie-Hellman.
117
118It uses dynamic memory allocation for storing its data structures.
119That means that there is no limit on the size of the numbers
120manipulated by these functions, but return values must always be
121checked in case a memory allocation error has occurred.
122
123The basic object in this library is a B<BIGNUM>. It is used to hold a
124single large integer. This type should be considered opaque and fields
125should not be modified or accessed directly.
126
127The creation of B<BIGNUM> objects is described in L<BN_new(3)|BN_new(3)>;
128L<BN_add(3)|BN_add(3)> describes most of the arithmetic operations.
129Comparison is described in L<BN_cmp(3)|BN_cmp(3)>; L<BN_zero(3)|BN_zero(3)>
130describes certain assignments, L<BN_rand(3)|BN_rand(3)> the generation of
131random numbers, L<BN_generate_prime(3)|BN_generate_prime(3)> deals with prime
132numbers and L<BN_set_bit(3)|BN_set_bit(3)> with bit operations. The conversion
133of B<BIGNUM>s to external formats is described in L<BN_bn2bin(3)|BN_bn2bin(3)>.
134
135=head1 SEE ALSO
136
137L<bn_internal(3)|bn_internal(3)>,
138L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
139L<BN_new(3)|BN_new(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
140L<BN_copy(3)|BN_copy(3)>, L<BN_num_bytes(3)|BN_num_bytes(3)>,
141L<BN_add(3)|BN_add(3)>, L<BN_add_word(3)|BN_add_word(3)>,
142L<BN_cmp(3)|BN_cmp(3)>, L<BN_zero(3)|BN_zero(3)>, L<BN_rand(3)|BN_rand(3)>,
143L<BN_generate_prime(3)|BN_generate_prime(3)>, L<BN_set_bit(3)|BN_set_bit(3)>,
144L<BN_bn2bin(3)|BN_bn2bin(3)>, L<BN_mod_inverse(3)|BN_mod_inverse(3)>,
145L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>,
146L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>
147
148=cut
diff --git a/src/lib/libcrypto/doc/d2i_DHparams.pod b/src/lib/libcrypto/doc/d2i_DHparams.pod
deleted file mode 100644
index a6d1743d39..0000000000
--- a/src/lib/libcrypto/doc/d2i_DHparams.pod
+++ /dev/null
@@ -1,30 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_DHparams, i2d_DHparams - ...
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH *d2i_DHparams(DH **a, unsigned char **pp, long length);
12 int i2d_DHparams(DH *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16...
17
18=head1 RETURN VALUES
19
20...
21
22=head1 SEE ALSO
23
24...
25
26=head1 HISTORY
27
28...
29
30=cut
diff --git a/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod b/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod
deleted file mode 100644
index ff4d0d57db..0000000000
--- a/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod
+++ /dev/null
@@ -1,39 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey, i2d_Netscape_RSA, d2i_Netscape_RSA - ...
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
12
13 int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
14
15 RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
16
17 int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
18
19 int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
20
21 RSA * d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
22
23=head1 DESCRIPTION
24
25...
26
27=head1 RETURN VALUES
28
29...
30
31=head1 SEE ALSO
32
33...
34
35=head1 HISTORY
36
37...
38
39=cut
diff --git a/src/lib/libcrypto/doc/dh.pod b/src/lib/libcrypto/doc/dh.pod
deleted file mode 100644
index 0a9b7c03a2..0000000000
--- a/src/lib/libcrypto/doc/dh.pod
+++ /dev/null
@@ -1,68 +0,0 @@
1=pod
2
3=head1 NAME
4
5dh - Diffie-Hellman key agreement
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH * DH_new(void);
12 void DH_free(DH *dh);
13
14 int DH_size(DH *dh);
15
16 DH * DH_generate_parameters(int prime_len, int generator,
17 void (*callback)(int, int, void *), void *cb_arg);
18 int DH_check(DH *dh, int *codes);
19
20 int DH_generate_key(DH *dh);
21 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
22
23 void DH_set_default_method(DH_METHOD *meth);
24 DH_METHOD *DH_get_default_method(void);
25 DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
26 DH *DH_new_method(DH_METHOD *meth);
27 DH_METHOD *DH_OpenSSL(void);
28
29 int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(),
30 int (*dup_func)(), void (*free_func)());
31 int DH_set_ex_data(DH *d, int idx, char *arg);
32 char *DH_get_ex_data(DH *d, int idx);
33
34 DH * d2i_DHparams(DH **a, unsigned char **pp, long length);
35 int i2d_DHparams(DH *a, unsigned char **pp);
36
37 int DHparams_print_fp(FILE *fp, DH *x);
38 int DHparams_print(BIO *bp, DH *x);
39
40=head1 DESCRIPTION
41
42These functions implement the Diffie-Hellman key agreement protocol.
43The generation of shared DH parameters is described in
44L<DH_generate_parameters(3)|DH_generate_parameters(3)>; L<DH_generate_key(3)|DH_generate_key(3)> describes how
45to perform a key agreement.
46
47The B<DH> structure consists of several BIGNUM components.
48
49 struct
50 {
51 BIGNUM *p; // prime number (shared)
52 BIGNUM *g; // generator of Z_p (shared)
53 BIGNUM *priv_key; // private DH value x
54 BIGNUM *pub_key; // public DH value g^x
55 // ...
56 };
57 DH
58
59=head1 SEE ALSO
60
61L<dhparam(1)|dhparam(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>,
62L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<DH_set_method(3)|DH_set_method(3)>,
63L<DH_new(3)|DH_new(3)>, L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>,
64L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
65L<DH_compute_key(3)|DH_compute_key(3)>, L<d2i_DHparams(3)|d2i_DHparams(3)>,
66L<RSA_print(3)|RSA_print(3)>
67
68=cut
diff --git a/src/lib/libcrypto/doc/dsa.pod b/src/lib/libcrypto/doc/dsa.pod
deleted file mode 100644
index 80ecf38178..0000000000
--- a/src/lib/libcrypto/doc/dsa.pod
+++ /dev/null
@@ -1,104 +0,0 @@
1=pod
2
3=head1 NAME
4
5dsa - Digital Signature Algorithm
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA * DSA_new(void);
12 void DSA_free(DSA *dsa);
13
14 int DSA_size(DSA *dsa);
15
16 DSA * DSA_generate_parameters(int bits, unsigned char *seed,
17 int seed_len, int *counter_ret, unsigned long *h_ret,
18 void (*callback)(int, int, void *), void *cb_arg);
19
20 DH * DSA_dup_DH(DSA *r);
21
22 int DSA_generate_key(DSA *dsa);
23
24 int DSA_sign(int dummy, const unsigned char *dgst, int len,
25 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
26 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
27 BIGNUM **rp);
28 int DSA_verify(int dummy, const unsigned char *dgst, int len,
29 unsigned char *sigbuf, int siglen, DSA *dsa);
30
31 void DSA_set_default_method(DSA_METHOD *meth);
32 DSA_METHOD *DSA_get_default_method(void);
33 DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth);
34 DSA *DSA_new_method(DSA_METHOD *meth);
35 DSA_METHOD *DSA_OpenSSL(void);
36
37 int DSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
38 int (*dup_func)(), void (*free_func)());
39 int DSA_set_ex_data(DSA *d, int idx, char *arg);
40 char *DSA_get_ex_data(DSA *d, int idx);
41
42 DSA_SIG *DSA_SIG_new(void);
43 void DSA_SIG_free(DSA_SIG *a);
44 int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp);
45 DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
46
47 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
48 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
49 DSA_SIG *sig, DSA *dsa);
50
51 DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
52 DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
53 DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
54 int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
55 int i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
56 int i2d_DSAparams(DSA *a,unsigned char **pp);
57
58 int DSAparams_print(BIO *bp, DSA *x);
59 int DSAparams_print_fp(FILE *fp, DSA *x);
60 int DSA_print(BIO *bp, DSA *x, int off);
61 int DSA_print_fp(FILE *bp, DSA *x, int off);
62
63=head1 DESCRIPTION
64
65These functions implement the Digital Signature Algorithm (DSA). The
66generation of shared DSA parameters is described in
67L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>;
68L<DSA_generate_key(3)|DSA_generate_key(3)> describes how to
69generate a signature key. Signature generation and verification are
70described in L<DSA_sign(3)|DSA_sign(3)>.
71
72The B<DSA> structure consists of several BIGNUM components.
73
74 struct
75 {
76 BIGNUM *p; // prime number (public)
77 BIGNUM *q; // 160-bit subprime, q | p-1 (public)
78 BIGNUM *g; // generator of subgroup (public)
79 BIGNUM *priv_key; // private key x
80 BIGNUM *pub_key; // public key y = g^x
81 // ...
82 }
83 DSA;
84
85In public keys, B<priv_key> is NULL.
86
87=head1 CONFORMING TO
88
89US Federal Information Processing Standard FIPS 186 (Digital Signature
90Standard, DSS), ANSI X9.30
91
92=head1 SEE ALSO
93
94L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
95L<rsa(3)|rsa(3)>, L<SHA1(3)|SHA1(3)>, L<DSA_new(3)|DSA_new(3)>,
96L<DSA_size(3)|DSA_size(3)>,
97L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
98L<DSA_dup_DH(3)|DSA_dup_DH(3)>,
99L<DSA_generate_key(3)|DSA_generate_key(3)>,
100L<DSA_sign(3)|DSA_sign(3)>, L<DSA_set_method(3)|DSA_set_method(3)>,
101L<DSA_get_ex_new_index(3)|DSA_get_ex_new_index(3)>,
102L<RSA_print(3)|RSA_print(3)>
103
104=cut
diff --git a/src/lib/libcrypto/doc/lh_stats.pod b/src/lib/libcrypto/doc/lh_stats.pod
deleted file mode 100644
index 3eeaa72e52..0000000000
--- a/src/lib/libcrypto/doc/lh_stats.pod
+++ /dev/null
@@ -1,60 +0,0 @@
1=pod
2
3=head1 NAME
4
5lh_stats, lh_node_stats, lh_node_usage_stats, lh_stats_bio,
6lh_node_stats_bio, lh_node_usage_stats_bio - LHASH statistics
7
8=head1 SYNOPSIS
9
10 #include <openssl/lhash.h>
11
12 void lh_stats(LHASH *table, FILE *out);
13 void lh_node_stats(LHASH *table, FILE *out);
14 void lh_node_usage_stats(LHASH *table, FILE *out);
15
16 void lh_stats_bio(LHASH *table, BIO *out);
17 void lh_node_stats_bio(LHASH *table, BIO *out);
18 void lh_node_usage_stats_bio(LHASH *table, BIO *out);
19
20=head1 DESCRIPTION
21
22The B<LHASH> structure records statistics about most aspects of
23accessing the hash table. This is mostly a legacy of Eric Young
24writing this library for the reasons of implementing what looked like
25a nice algorithm rather than for a particular software product.
26
27lh_stats() prints out statistics on the size of the hash table, how
28many entries are in it, and the number and result of calls to the
29routines in this library.
30
31lh_node_stats() prints the number of entries for each 'bucket' in the
32hash table.
33
34lh_node_usage_stats() prints out a short summary of the state of the
35hash table. It prints the 'load' and the 'actual load'. The load is
36the average number of data items per 'bucket' in the hash table. The
37'actual load' is the average number of items per 'bucket', but only
38for buckets which contain entries. So the 'actual load' is the
39average number of searches that will need to find an item in the hash
40table, while the 'load' is the average number that will be done to
41record a miss.
42
43lh_stats_bio(), lh_node_stats_bio() and lh_node_usage_stats_bio()
44are the same as the above, except that the output goes to a B<BIO>.
45
46=head1 RETURN VALUES
47
48These functions do not return values.
49
50=head1 SEE ALSO
51
52L<bio(3)|bio(3)>, L<lhash(3)|lhash(3)>
53
54=head1 HISTORY
55
56These functions are available in all versions of SSLeay and OpenSSL.
57
58This manpage is derived from the SSLeay documentation.
59
60=cut
diff --git a/src/lib/libcrypto/doc/rsa.pod b/src/lib/libcrypto/doc/rsa.pod
deleted file mode 100644
index eb8ba612c4..0000000000
--- a/src/lib/libcrypto/doc/rsa.pod
+++ /dev/null
@@ -1,116 +0,0 @@
1=pod
2
3=head1 NAME
4
5rsa - RSA public key cryptosystem
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * RSA_new(void);
12 void RSA_free(RSA *rsa);
13
14 int RSA_public_encrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16 int RSA_private_decrypt(int flen, unsigned char *from,
17 unsigned char *to, RSA *rsa, int padding);
18
19 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
20 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
21 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
22 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
23
24 int RSA_size(RSA *rsa);
25
26 RSA *RSA_generate_key(int num, unsigned long e,
27 void (*callback)(int,int,void *), void *cb_arg);
28
29 int RSA_check_key(RSA *rsa);
30
31 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
32 void RSA_blinding_off(RSA *rsa);
33
34 void RSA_set_default_method(RSA_METHOD *meth);
35 RSA_METHOD *RSA_get_default_method(void);
36 RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
37 RSA_METHOD *RSA_get_method(RSA *rsa);
38 RSA_METHOD *RSA_PKCS1_SSLeay(void);
39 RSA_METHOD *RSA_PKCS1_RSAref(void);
40 RSA_METHOD *RSA_null_method(void);
41 int RSA_flags(RSA *rsa);
42 RSA *RSA_new_method(RSA_METHOD *method);
43
44 int RSA_print(BIO *bp, RSA *x, int offset);
45 int RSA_print_fp(FILE *fp, RSA *x, int offset);
46
47 int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
48 int (*dup_func)(), void (*free_func)());
49 int RSA_set_ex_data(RSA *r,int idx,char *arg);
50 char *RSA_get_ex_data(RSA *r, int idx);
51
52 int RSA_private_encrypt(int flen, unsigned char *from,
53 unsigned char *to, RSA *rsa,int padding);
54 int RSA_public_decrypt(int flen, unsigned char *from,
55 unsigned char *to, RSA *rsa,int padding);
56
57 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
58 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
59 RSA *rsa);
60 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
61 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
62 RSA *rsa);
63
64=head1 DESCRIPTION
65
66These functions implement RSA public key encryption and signatures
67as defined in PKCS #1 v2.0 [RFC 2437].
68
69The B<RSA> structure consists of several BIGNUM components. It can
70contain public as well as private RSA keys:
71
72 struct
73 {
74 BIGNUM *n; // public modulus
75 BIGNUM *e; // public exponent
76 BIGNUM *d; // private exponent
77 BIGNUM *p; // secret prime factor
78 BIGNUM *q; // secret prime factor
79 BIGNUM *dmp1; // d mod (p-1)
80 BIGNUM *dmq1; // d mod (q-1)
81 BIGNUM *iqmp; // q^-1 mod p
82 // ...
83 };
84 RSA
85
86In public keys, the private exponent and the related secret values are
87B<NULL>.
88
89B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private
90keys, but the RSA operations are much faster when these values are
91available.
92
93=head1 CONFORMING TO
94
95SSL, PKCS #1 v2.0
96
97=head1 PATENTS
98
99RSA is covered by a US patent which expires in September 2000.
100
101=head1 SEE ALSO
102
103L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>,
104L<rand(3)|rand(3)>, L<RSA_new(3)|RSA_new(3)>,
105L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
106L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>,
107L<RSA_generate_key(3)|RSA_generate_key(3)>,
108L<RSA_check_key(3)|RSA_check_key(3)>,
109L<RSA_blinding_on(3)|RSA_blinding_on(3)>,
110L<RSA_set_method(3)|RSA_set_method(3)>, L<RSA_print(3)|RSA_print(3)>,
111L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
112L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
113L<RSA_sign_ASN_OCTET_STRING(3)|RSA_sign_ASN_OCTET_STRING(3)>,
114L<RSA_padding_add_PKCS1_type_1(3)|RSA_padding_add_PKCS1_type_1(3)>
115
116=cut
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
deleted file mode 100644
index 68d9912cbc..0000000000
--- a/src/lib/libcrypto/dsa/dsa.h
+++ /dev/null
@@ -1,241 +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#include <openssl/crypto.h>
78#ifndef NO_DH
79# include <openssl/dh.h>
80#endif
81
82#define DSA_FLAG_CACHE_MONT_P 0x01
83
84typedef struct dsa_st DSA;
85
86typedef struct DSA_SIG_st
87 {
88 BIGNUM *r;
89 BIGNUM *s;
90 } DSA_SIG;
91
92typedef struct dsa_method {
93 const char *name;
94 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
95 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
96 BIGNUM **rp);
97 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
98 DSA_SIG *sig, DSA *dsa);
99 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
100 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
101 BN_MONT_CTX *in_mont);
102 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
103 const BIGNUM *m, BN_CTX *ctx,
104 BN_MONT_CTX *m_ctx); /* Can be null */
105 int (*init)(DSA *dsa);
106 int (*finish)(DSA *dsa);
107 int flags;
108 char *app_data;
109} DSA_METHOD;
110
111struct dsa_st
112 {
113 /* This first variable is used to pick up errors where
114 * a DSA is passed instead of of a EVP_PKEY */
115 int pad;
116 int version;
117 int write_params;
118 BIGNUM *p;
119 BIGNUM *q; /* == 20 */
120 BIGNUM *g;
121
122 BIGNUM *pub_key; /* y public key */
123 BIGNUM *priv_key; /* x private key */
124
125 BIGNUM *kinv; /* Signing pre-calc */
126 BIGNUM *r; /* Signing pre-calc */
127
128 int flags;
129 /* Normally used to cache montgomery values */
130 char *method_mont_p;
131 int references;
132 CRYPTO_EX_DATA ex_data;
133 DSA_METHOD *meth;
134 };
135
136#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
137 (char *(*)())d2i_DSAparams,(char *)(x))
138#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
139 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
140#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
141 (unsigned char *)(x))
142#define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \
143 (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x))
144#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \
145 (unsigned char *)(x))
146
147
148DSA_SIG * DSA_SIG_new(void);
149void DSA_SIG_free(DSA_SIG *a);
150int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp);
151DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
152
153DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
154int DSA_do_verify(const unsigned char *dgst,int dgst_len,
155 DSA_SIG *sig,DSA *dsa);
156
157DSA_METHOD *DSA_OpenSSL(void);
158
159void DSA_set_default_method(DSA_METHOD *);
160DSA_METHOD *DSA_get_default_method(void);
161DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *);
162
163DSA * DSA_new(void);
164DSA * DSA_new_method(DSA_METHOD *meth);
165int DSA_size(DSA *);
166 /* next 4 return -1 on error */
167int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
168int DSA_sign(int type,const unsigned char *dgst,int dlen,
169 unsigned char *sig, unsigned int *siglen, DSA *dsa);
170int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
171 unsigned char *sigbuf, int siglen, DSA *dsa);
172void DSA_free (DSA *r);
173int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
174 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
175int DSA_set_ex_data(DSA *d, int idx, void *arg);
176void *DSA_get_ex_data(DSA *d, int idx);
177
178void ERR_load_DSA_strings(void );
179
180DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
181DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
182DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
183DSA * DSA_generate_parameters(int bits, unsigned char *seed,int seed_len,
184 int *counter_ret, unsigned long *h_ret,void
185 (*callback)(int, int, void *),void *cb_arg);
186int DSA_generate_key(DSA *a);
187int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
188int i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
189int i2d_DSAparams(DSA *a,unsigned char **pp);
190
191#ifdef HEADER_BIO_H
192int DSAparams_print(BIO *bp, DSA *x);
193int DSA_print(BIO *bp, DSA *x, int off);
194#endif
195#ifndef NO_FP_API
196int DSAparams_print_fp(FILE *fp, DSA *x);
197int DSA_print_fp(FILE *bp, DSA *x, int off);
198#endif
199
200#define DSS_prime_checks 50
201/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:
202 * 50 rounds of Rabin-Miller */
203#define DSA_is_prime(n, callback, cb_arg) \
204 BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
205
206#ifndef NO_DH
207/* Convert DSA structure (key or just parameters) into DH structure
208 * (be careful to avoid small subgroup attacks when using this!) */
209DH *DSA_dup_DH(DSA *r);
210#endif
211
212/* BEGIN ERROR CODES */
213/* The following lines are auto generated by the script mkerr.pl. Any changes
214 * made after this point may be overwritten when the script is next run.
215 */
216
217/* Error codes for the DSA functions. */
218
219/* Function codes. */
220#define DSA_F_D2I_DSA_SIG 110
221#define DSA_F_DSAPARAMS_PRINT 100
222#define DSA_F_DSAPARAMS_PRINT_FP 101
223#define DSA_F_DSA_DO_SIGN 112
224#define DSA_F_DSA_DO_VERIFY 113
225#define DSA_F_DSA_NEW 103
226#define DSA_F_DSA_PRINT 104
227#define DSA_F_DSA_PRINT_FP 105
228#define DSA_F_DSA_SIGN 106
229#define DSA_F_DSA_SIGN_SETUP 107
230#define DSA_F_DSA_SIG_NEW 109
231#define DSA_F_DSA_VERIFY 108
232#define DSA_F_I2D_DSA_SIG 111
233
234/* Reason codes. */
235#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
236
237#ifdef __cplusplus
238}
239#endif
240#endif
241
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
deleted file mode 100644
index c9b32b4db7..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 M_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) M_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 2b3ab3a9ad..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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/dsa.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA DSA_str_functs[]=
68 {
69{ERR_PACK(0,DSA_F_D2I_DSA_SIG,0), "d2i_DSA_SIG"},
70{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"},
71{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"},
72{ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"},
73{ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"},
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 2294a362d9..0000000000
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ /dev/null
@@ -1,294 +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/* Parameter generation follows the original release of FIPS PUB 186,
63 * Appendix 2.2 (i.e. use SHA as defined in FIPS PUB 180) */
64#define HASH SHA
65#else
66/* Parameter generation follows the updated Appendix 2.2 for FIPS PUB 186,
67 * also Appendix 2.2 of FIPS PUB 186-1 (i.e. use SHA as defined in
68 * FIPS PUB 180-1) */
69#define HASH SHA1
70#endif
71
72#ifndef NO_SHA
73
74#include <stdio.h>
75#include <time.h>
76#include "cryptlib.h"
77#include <openssl/sha.h>
78#include <openssl/bn.h>
79#include <openssl/dsa.h>
80#include <openssl/rand.h>
81
82DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
83 int *counter_ret, unsigned long *h_ret,
84 void (*callback)(int, int, void *),
85 void *cb_arg)
86 {
87 int ok=0;
88 unsigned char seed[SHA_DIGEST_LENGTH];
89 unsigned char md[SHA_DIGEST_LENGTH];
90 unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
91 BIGNUM *r0,*W,*X,*c,*test;
92 BIGNUM *g=NULL,*q=NULL,*p=NULL;
93 BN_MONT_CTX *mont=NULL;
94 int k,n=0,i,b,m=0;
95 int counter=0;
96 int r=0;
97 BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL;
98 unsigned int h=2;
99 DSA *ret=NULL;
100
101 if (bits < 512) bits=512;
102 bits=(bits+63)/64*64;
103
104 if (seed_len < 20)
105 seed_in = NULL; /* seed buffer too small -- ignore */
106 if (seed_len > 20)
107 seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
108 * but our internal buffers are restricted to 160 bits*/
109 if ((seed_in != NULL) && (seed_len == 20))
110 memcpy(seed,seed_in,seed_len);
111
112 if ((ctx=BN_CTX_new()) == NULL) goto err;
113 if ((ctx2=BN_CTX_new()) == NULL) goto err;
114 if ((ctx3=BN_CTX_new()) == NULL) goto err;
115 if ((ret=DSA_new()) == NULL) goto err;
116
117 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
118
119 BN_CTX_start(ctx2);
120 r0 = BN_CTX_get(ctx2);
121 g = BN_CTX_get(ctx2);
122 W = BN_CTX_get(ctx2);
123 q = BN_CTX_get(ctx2);
124 X = BN_CTX_get(ctx2);
125 c = BN_CTX_get(ctx2);
126 p = BN_CTX_get(ctx2);
127 test = BN_CTX_get(ctx2);
128
129 BN_lshift(test,BN_value_one(),bits-1);
130
131 for (;;)
132 {
133 for (;;) /* find q */
134 {
135 int seed_is_random;
136
137 /* step 1 */
138 if (callback != NULL) callback(0,m++,cb_arg);
139
140 if (!seed_len)
141 {
142 RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH);
143 seed_is_random = 1;
144 }
145 else
146 {
147 seed_is_random = 0;
148 seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
149 }
150 memcpy(buf,seed,SHA_DIGEST_LENGTH);
151 memcpy(buf2,seed,SHA_DIGEST_LENGTH);
152 /* precompute "SEED + 1" for step 7: */
153 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
154 {
155 buf[i]++;
156 if (buf[i] != 0) break;
157 }
158
159 /* step 2 */
160 HASH(seed,SHA_DIGEST_LENGTH,md);
161 HASH(buf,SHA_DIGEST_LENGTH,buf2);
162 for (i=0; i<SHA_DIGEST_LENGTH; i++)
163 md[i]^=buf2[i];
164
165 /* step 3 */
166 md[0]|=0x80;
167 md[SHA_DIGEST_LENGTH-1]|=0x01;
168 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
169
170 /* step 4 */
171 r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, cb_arg, seed_is_random);
172 if (r > 0)
173 break;
174 if (r != 0)
175 goto err;
176
177 /* do a callback call */
178 /* step 5 */
179 }
180
181 if (callback != NULL) callback(2,0,cb_arg);
182 if (callback != NULL) callback(3,0,cb_arg);
183
184 /* step 6 */
185 counter=0;
186 /* "offset = 2" */
187
188 n=(bits-1)/160;
189 b=(bits-1)-n*160;
190
191 for (;;)
192 {
193 if (callback != NULL && counter != 0)
194 callback(0,counter,cb_arg);
195
196 /* step 7 */
197 BN_zero(W);
198 /* now 'buf' contains "SEED + offset - 1" */
199 for (k=0; k<=n; k++)
200 {
201 /* obtain "SEED + offset + k" by incrementing: */
202 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
203 {
204 buf[i]++;
205 if (buf[i] != 0) break;
206 }
207
208 HASH(buf,SHA_DIGEST_LENGTH,md);
209
210 /* step 8 */
211 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
212 goto err;
213 BN_lshift(r0,r0,160*k);
214 BN_add(W,W,r0);
215 }
216
217 /* more of step 8 */
218 BN_mask_bits(W,bits-1);
219 BN_copy(X,W); /* this should be ok */
220 BN_add(X,X,test); /* this should be ok */
221
222 /* step 9 */
223 BN_lshift1(r0,q);
224 BN_mod(c,X,r0,ctx);
225 BN_sub(r0,c,BN_value_one());
226 BN_sub(p,X,r0);
227
228 /* step 10 */
229 if (BN_cmp(p,test) >= 0)
230 {
231 /* step 11 */
232 r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, cb_arg, 1);
233 if (r > 0)
234 goto end; /* found it */
235 if (r != 0)
236 goto err;
237 }
238
239 /* step 13 */
240 counter++;
241 /* "offset = offset + n + 1" */
242
243 /* step 14 */
244 if (counter >= 4096) break;
245 }
246 }
247end:
248 if (callback != NULL) callback(2,1,cb_arg);
249
250 /* We now need to generate g */
251 /* Set r0=(p-1)/q */
252 BN_sub(test,p,BN_value_one());
253 BN_div(r0,NULL,test,q,ctx);
254
255 BN_set_word(test,h);
256 BN_MONT_CTX_set(mont,p,ctx);
257
258 for (;;)
259 {
260 /* g=test^r0%p */
261 BN_mod_exp_mont(g,test,r0,p,ctx,mont);
262 if (!BN_is_one(g)) break;
263 BN_add(test,test,BN_value_one());
264 h++;
265 }
266
267 if (callback != NULL) callback(3,1,cb_arg);
268
269 ok=1;
270err:
271 if (!ok)
272 {
273 if (ret != NULL) DSA_free(ret);
274 }
275 else
276 {
277 ret->p=BN_dup(p);
278 ret->q=BN_dup(q);
279 ret->g=BN_dup(g);
280 if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);
281 if (counter_ret != NULL) *counter_ret=counter;
282 if (h_ret != NULL) *h_ret=h;
283 }
284 if (ctx != NULL) BN_CTX_free(ctx);
285 if (ctx2 != NULL)
286 {
287 BN_CTX_end(ctx2);
288 BN_CTX_free(ctx2);
289 }
290 if (ctx3 != NULL) BN_CTX_free(ctx3);
291 if (mont != NULL) BN_MONT_CTX_free(mont);
292 return(ok?ret:NULL);
293 }
294#endif
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
deleted file mode 100644
index 5aef2d5fcf..0000000000
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ /dev/null
@@ -1,113 +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 if (!BN_rand(priv_key,i,1,0))
88 goto err;
89 if (BN_cmp(priv_key,dsa->q) >= 0)
90 BN_sub(priv_key,priv_key,dsa->q);
91 if (!BN_is_zero(priv_key)) break;
92 }
93
94 if (dsa->pub_key == NULL)
95 {
96 if ((pub_key=BN_new()) == NULL) goto err;
97 }
98 else
99 pub_key=dsa->pub_key;
100
101 if (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err;
102
103 dsa->priv_key=priv_key;
104 dsa->pub_key=pub_key;
105 ok=1;
106
107err:
108 if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);
109 if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);
110 if (ctx != NULL) BN_CTX_free(ctx);
111 return(ok);
112 }
113#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
deleted file mode 100644
index 224e412afc..0000000000
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ /dev/null
@@ -1,246 +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
69static DSA_METHOD *default_DSA_method;
70static int dsa_meth_num = 0;
71static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dsa_meth = NULL;
72
73void DSA_set_default_method(DSA_METHOD *meth)
74{
75 default_DSA_method = meth;
76}
77
78DSA_METHOD *DSA_get_default_method(void)
79{
80 if(!default_DSA_method) default_DSA_method = DSA_OpenSSL();
81 return default_DSA_method;
82}
83
84DSA *DSA_new(void)
85{
86 return DSA_new_method(NULL);
87}
88
89DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth)
90{
91 DSA_METHOD *mtmp;
92 mtmp = dsa->meth;
93 if (mtmp->finish) mtmp->finish(dsa);
94 dsa->meth = meth;
95 if (meth->init) meth->init(dsa);
96 return mtmp;
97}
98
99
100DSA *DSA_new_method(DSA_METHOD *meth)
101 {
102 DSA *ret;
103
104 ret=(DSA *)Malloc(sizeof(DSA));
105 if (ret == NULL)
106 {
107 DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE);
108 return(NULL);
109 }
110 if(!default_DSA_method) default_DSA_method = DSA_OpenSSL();
111 if(meth) ret->meth = meth;
112 else ret->meth = default_DSA_method;
113 ret->pad=0;
114 ret->version=0;
115 ret->write_params=1;
116 ret->p=NULL;
117 ret->q=NULL;
118 ret->g=NULL;
119
120 ret->pub_key=NULL;
121 ret->priv_key=NULL;
122
123 ret->kinv=NULL;
124 ret->r=NULL;
125 ret->method_mont_p=NULL;
126
127 ret->references=1;
128 ret->flags=ret->meth->flags;
129 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
130 {
131 Free(ret);
132 ret=NULL;
133 }
134 else
135 CRYPTO_new_ex_data(dsa_meth,ret,&ret->ex_data);
136
137 return(ret);
138 }
139
140void DSA_free(DSA *r)
141 {
142 int i;
143
144 if (r == NULL) return;
145
146 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA);
147#ifdef REF_PRINT
148 REF_PRINT("DSA",r);
149#endif
150 if (i > 0) return;
151#ifdef REF_CHECK
152 if (i < 0)
153 {
154 fprintf(stderr,"DSA_free, bad reference count\n");
155 abort();
156 }
157#endif
158
159 CRYPTO_free_ex_data(dsa_meth, r, &r->ex_data);
160
161 if(r->meth->finish) r->meth->finish(r);
162
163 if (r->p != NULL) BN_clear_free(r->p);
164 if (r->q != NULL) BN_clear_free(r->q);
165 if (r->g != NULL) BN_clear_free(r->g);
166 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
167 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
168 if (r->kinv != NULL) BN_clear_free(r->kinv);
169 if (r->r != NULL) BN_clear_free(r->r);
170 Free(r);
171 }
172
173int DSA_size(DSA *r)
174 {
175 int ret,i;
176 ASN1_INTEGER bs;
177 unsigned char buf[4];
178
179 i=BN_num_bits(r->q);
180 bs.length=(i+7)/8;
181 bs.data=buf;
182 bs.type=V_ASN1_INTEGER;
183 /* If the top bit is set the asn1 encoding is 1 larger. */
184 buf[0]=0xff;
185
186 i=i2d_ASN1_INTEGER(&bs,NULL);
187 i+=i; /* r and s */
188 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
189 return(ret);
190 }
191
192int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
193 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
194 {
195 dsa_meth_num++;
196 return(CRYPTO_get_ex_new_index(dsa_meth_num-1,
197 &dsa_meth,argl,argp,new_func,dup_func,free_func));
198 }
199
200int DSA_set_ex_data(DSA *d, int idx, void *arg)
201 {
202 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
203 }
204
205void *DSA_get_ex_data(DSA *d, int idx)
206 {
207 return(CRYPTO_get_ex_data(&d->ex_data,idx));
208 }
209
210#ifndef NO_DH
211DH *DSA_dup_DH(DSA *r)
212 {
213 /* DSA has p, q, g, optional pub_key, optional priv_key.
214 * DH has p, optional length, g, optional pub_key, optional priv_key.
215 */
216
217 DH *ret = NULL;
218
219 if (r == NULL)
220 goto err;
221 ret = DH_new();
222 if (ret == NULL)
223 goto err;
224 if (r->p != NULL)
225 if ((ret->p = BN_dup(r->p)) == NULL)
226 goto err;
227 if (r->q != NULL)
228 ret->length = BN_num_bits(r->q);
229 if (r->g != NULL)
230 if ((ret->g = BN_dup(r->g)) == NULL)
231 goto err;
232 if (r->pub_key != NULL)
233 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
234 goto err;
235 if (r->priv_key != NULL)
236 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
237 goto err;
238
239 return ret;
240
241 err:
242 if (ret != NULL)
243 DH_free(ret);
244 return NULL;
245 }
246#endif
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
deleted file mode 100644
index b51cf6ad8d..0000000000
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ /dev/null
@@ -1,321 +0,0 @@
1/* crypto/dsa/dsa_ossl.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67
68static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
69static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
70static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
71 DSA *dsa);
72static int dsa_init(DSA *dsa);
73static int dsa_finish(DSA *dsa);
74static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
75 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
76 BN_MONT_CTX *in_mont);
77static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
78 const BIGNUM *m, BN_CTX *ctx,
79 BN_MONT_CTX *m_ctx);
80
81static DSA_METHOD openssl_dsa_meth = {
82"OpenSSL DSA method",
83dsa_do_sign,
84dsa_sign_setup,
85dsa_do_verify,
86dsa_mod_exp,
87dsa_bn_mod_exp,
88dsa_init,
89dsa_finish,
900,
91NULL
92};
93
94DSA_METHOD *DSA_OpenSSL(void)
95{
96 return &openssl_dsa_meth;
97}
98
99static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
100 {
101 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
102 BIGNUM m;
103 BIGNUM xr;
104 BN_CTX *ctx=NULL;
105 int i,reason=ERR_R_BN_LIB;
106 DSA_SIG *ret=NULL;
107
108 BN_init(&m);
109 BN_init(&xr);
110 s=BN_new();
111 if (s == NULL) goto err;
112
113 i=BN_num_bytes(dsa->q); /* should be 20 */
114 if ((dlen > i) || (dlen > 50))
115 {
116 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
117 goto err;
118 }
119
120 ctx=BN_CTX_new();
121 if (ctx == NULL) goto err;
122
123 if ((dsa->kinv == NULL) || (dsa->r == NULL))
124 {
125 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
126 }
127 else
128 {
129 kinv=dsa->kinv;
130 dsa->kinv=NULL;
131 r=dsa->r;
132 dsa->r=NULL;
133 }
134
135 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
136
137 /* Compute s = inv(k) (m + xr) mod q */
138 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
139 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
140 if (BN_cmp(s,dsa->q) > 0)
141 BN_sub(s,s,dsa->q);
142 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
143
144 ret=DSA_SIG_new();
145 if (ret == NULL) goto err;
146 ret->r = r;
147 ret->s = s;
148
149err:
150 if (!ret)
151 {
152 DSAerr(DSA_F_DSA_DO_SIGN,reason);
153 BN_free(r);
154 BN_free(s);
155 }
156 if (ctx != NULL) BN_CTX_free(ctx);
157 BN_clear_free(&m);
158 BN_clear_free(&xr);
159 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
160 BN_clear_free(kinv);
161 return(ret);
162 }
163
164static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
165 {
166 BN_CTX *ctx;
167 BIGNUM k,*kinv=NULL,*r=NULL;
168 int ret=0;
169
170 if (ctx_in == NULL)
171 {
172 if ((ctx=BN_CTX_new()) == NULL) goto err;
173 }
174 else
175 ctx=ctx_in;
176
177 BN_init(&k);
178 if ((r=BN_new()) == NULL) goto err;
179 kinv=NULL;
180
181 /* Get random k */
182 for (;;)
183 {
184 if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err;
185 if (BN_cmp(&k,dsa->q) >= 0)
186 BN_sub(&k,&k,dsa->q);
187 if (!BN_is_zero(&k)) break;
188 }
189
190 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
191 {
192 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
193 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
194 dsa->p,ctx)) goto err;
195 }
196
197 /* Compute r = (g^k mod p) mod q */
198 if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx,
199 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
200 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
201
202 /* Compute part of 's = inv(k) (m + xr) mod q' */
203 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
204
205 if (*kinvp != NULL) BN_clear_free(*kinvp);
206 *kinvp=kinv;
207 kinv=NULL;
208 if (*rp != NULL) BN_clear_free(*rp);
209 *rp=r;
210 ret=1;
211err:
212 if (!ret)
213 {
214 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
215 if (kinv != NULL) BN_clear_free(kinv);
216 if (r != NULL) BN_clear_free(r);
217 }
218 if (ctx_in == NULL) BN_CTX_free(ctx);
219 if (kinv != NULL) BN_clear_free(kinv);
220 BN_clear_free(&k);
221 return(ret);
222 }
223
224static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
225 DSA *dsa)
226 {
227 BN_CTX *ctx;
228 BIGNUM u1,u2,t1;
229 BN_MONT_CTX *mont=NULL;
230 int ret = -1;
231
232 if ((ctx=BN_CTX_new()) == NULL) goto err;
233 BN_init(&u1);
234 BN_init(&u2);
235 BN_init(&t1);
236
237 /* Calculate W = inv(S) mod Q
238 * save W in u2 */
239 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
240
241 /* save M in u1 */
242 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
243
244 /* u1 = M * w mod q */
245 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
246
247 /* u2 = r * w mod q */
248 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
249
250 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
251 {
252 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
253 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
254 dsa->p,ctx)) goto err;
255 }
256 mont=(BN_MONT_CTX *)dsa->method_mont_p;
257
258#if 0
259 {
260 BIGNUM t2;
261
262 BN_init(&t2);
263 /* v = ( g^u1 * y^u2 mod p ) mod q */
264 /* let t1 = g ^ u1 mod p */
265 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
266 /* let t2 = y ^ u2 mod p */
267 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
268 /* let u1 = t1 * t2 mod p */
269 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
270 BN_free(&t2);
271 }
272 /* let u1 = u1 mod q */
273 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
274#else
275 {
276 if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
277 dsa->p,ctx,mont)) goto err;
278 /* BN_copy(&u1,&t1); */
279 /* let u1 = u1 mod q */
280 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
281 }
282#endif
283 /* V is now in u1. If the signature is correct, it will be
284 * equal to R. */
285 ret=(BN_ucmp(&u1, sig->r) == 0);
286
287 err:
288 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
289 if (ctx != NULL) BN_CTX_free(ctx);
290 BN_free(&u1);
291 BN_free(&u2);
292 BN_free(&t1);
293 return(ret);
294 }
295
296static int dsa_init(DSA *dsa)
297{
298 dsa->flags|=DSA_FLAG_CACHE_MONT_P;
299 return(1);
300}
301
302static int dsa_finish(DSA *dsa)
303{
304 if(dsa->method_mont_p)
305 BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
306 return(1);
307}
308
309static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
310 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
311 BN_MONT_CTX *in_mont)
312{
313 return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
314}
315
316static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
317 const BIGNUM *m, BN_CTX *ctx,
318 BN_MONT_CTX *m_ctx)
319{
320 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
321}
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
deleted file mode 100644
index 89205026f0..0000000000
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ /dev/null
@@ -1,92 +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 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
71 }
72
73int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
74 unsigned int *siglen, DSA *dsa)
75 {
76 DSA_SIG *s;
77 s=DSA_do_sign(dgst,dlen,dsa);
78 if (s == NULL)
79 {
80 *siglen=0;
81 return(0);
82 }
83 *siglen=i2d_DSA_SIG(s,&sig);
84 DSA_SIG_free(s);
85 return(1);
86 }
87
88int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
89 {
90 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
91 }
92
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
deleted file mode 100644
index 03277f80fd..0000000000
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ /dev/null
@@ -1,94 +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 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
73 }
74
75/* data has already been hashed (probably with SHA or SHA-1). */
76/* returns
77 * 1: correct signature
78 * 0: incorrect signature
79 * -1: error
80 */
81int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
82 unsigned char *sigbuf, int siglen, DSA *dsa)
83 {
84 DSA_SIG *s;
85 int ret=-1;
86
87 s = DSA_SIG_new();
88 if (s == NULL) return(ret);
89 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
90 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
91err:
92 DSA_SIG_free(s);
93 return(ret);
94 }
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
deleted file mode 100644
index eb8c76aa0b..0000000000
--- a/src/lib/libcrypto/err/err.c
+++ /dev/null
@@ -1,747 +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 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include <stdarg.h>
114#include <string.h>
115#include <openssl/lhash.h>
116#include <openssl/crypto.h>
117#include "cryptlib.h"
118#include <openssl/buffer.h>
119#include <openssl/err.h>
120#include <openssl/crypto.h>
121
122
123static LHASH *error_hash=NULL;
124static LHASH *thread_hash=NULL;
125
126static unsigned long err_hash(ERR_STRING_DATA *a);
127static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b);
128static unsigned long pid_hash(ERR_STATE *pid);
129static int pid_cmp(ERR_STATE *a,ERR_STATE *pid);
130static unsigned long get_error_values(int inc,const char **file,int *line,
131 const char **data,int *flags);
132static void ERR_STATE_free(ERR_STATE *s);
133#ifndef NO_ERR
134static ERR_STRING_DATA ERR_str_libraries[]=
135 {
136{ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"},
137{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"},
138{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"},
139{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"},
140{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"},
141{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"},
142{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"},
143{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
144{ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"},
145{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"},
146{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"},
147{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"},
148{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuration file routines"},
149{ERR_PACK(ERR_LIB_METH,0,0) ,"X509 lookup 'method' routines"},
150{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"},
151{ERR_PACK(ERR_LIB_RSAREF,0,0) ,"RSAref routines"},
152{ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"},
153{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
154{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
155{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
156{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
157{ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"},
158{0,NULL},
159 };
160
161static ERR_STRING_DATA ERR_str_functs[]=
162 {
163 {ERR_PACK(0,SYS_F_FOPEN,0), "fopen"},
164 {ERR_PACK(0,SYS_F_CONNECT,0), "connect"},
165 {ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"},
166 {ERR_PACK(0,SYS_F_SOCKET,0), "socket"},
167 {ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"},
168 {ERR_PACK(0,SYS_F_BIND,0), "bind"},
169 {ERR_PACK(0,SYS_F_LISTEN,0), "listen"},
170 {ERR_PACK(0,SYS_F_ACCEPT,0), "accept"},
171#ifdef WINDOWS
172 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
173#endif
174 {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
175 {0,NULL},
176 };
177
178static ERR_STRING_DATA ERR_str_reasons[]=
179 {
180{ERR_R_FATAL ,"fatal"},
181{ERR_R_SYS_LIB ,"system lib"},
182{ERR_R_BN_LIB ,"BN lib"},
183{ERR_R_RSA_LIB ,"RSA lib"},
184{ERR_R_DH_LIB ,"DH lib"},
185{ERR_R_EVP_LIB ,"EVP lib"},
186{ERR_R_BUF_LIB ,"BUF lib"},
187{ERR_R_BIO_LIB ,"BIO lib"},
188{ERR_R_OBJ_LIB ,"OBJ lib"},
189{ERR_R_PEM_LIB ,"PEM lib"},
190{ERR_R_X509_LIB ,"X509 lib"},
191{ERR_R_METH_LIB ,"METH lib"},
192{ERR_R_ASN1_LIB ,"ASN1 lib"},
193{ERR_R_CONF_LIB ,"CONF lib"},
194{ERR_R_SSL_LIB ,"SSL lib"},
195{ERR_R_PROXY_LIB ,"PROXY lib"},
196{ERR_R_BIO_LIB ,"BIO lib"},
197{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
198{ERR_R_PKCS12_LIB ,"PKCS12 lib"},
199{ERR_R_MALLOC_FAILURE ,"Malloc failure"},
200{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
201{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
202{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"},
203{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"},
204{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"},
205{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
206{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
207{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
208
209{0,NULL},
210 };
211
212
213#define NUM_SYS_STR_REASONS 127
214#define LEN_SYS_STR_REASON 32
215
216static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
217/* SYS_str_reasons is filled with copies of strerror() results at
218 * initialization.
219 * 'errno' values up to 127 should cover all usual errors,
220 * others will be displayed numerically by ERR_error_string.
221 * It is crucial that we have something for each reason code
222 * that occurs in ERR_str_reasons, or bogus reason strings
223 * will be returned for SYSerr(), which always gets an errno
224 * value and never one of those 'standard' reason codes. */
225
226static void build_SYS_str_reasons()
227 {
228 /* Malloc cannot be used here, use static storage instead */
229 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
230 int i;
231
232 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
233
234 for (i = 1; i <= NUM_SYS_STR_REASONS; i++)
235 {
236 ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
237
238 str->error = (unsigned long)i;
239 if (str->string == NULL)
240 {
241 char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]);
242 char *src = strerror(i);
243 if (src != NULL)
244 {
245 strncpy(*dest, src, sizeof *dest);
246 (*dest)[sizeof *dest - 1] = '\0';
247 str->string = *dest;
248 }
249 }
250 if (str->string == NULL)
251 str->string = "unknown";
252 }
253
254 /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
255 * as required by ERR_load_strings. */
256
257 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
258 }
259#endif
260
261#define err_clear_data(p,i) \
262 if (((p)->err_data[i] != NULL) && \
263 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
264 { \
265 Free((p)->err_data[i]); \
266 (p)->err_data[i]=NULL; \
267 } \
268 (p)->err_data_flags[i]=0;
269
270static void ERR_STATE_free(ERR_STATE *s)
271 {
272 int i;
273
274 if(s == NULL)
275 return;
276
277 for (i=0; i<ERR_NUM_ERRORS; i++)
278 {
279 err_clear_data(s,i);
280 }
281 Free(s);
282 }
283
284void ERR_load_ERR_strings(void)
285 {
286 static int init=1;
287
288 if (init)
289 {
290 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
291 if (init == 0)
292 {
293 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
294 return;
295 }
296 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
297
298#ifndef NO_ERR
299 ERR_load_strings(0,ERR_str_libraries);
300 ERR_load_strings(0,ERR_str_reasons);
301 ERR_load_strings(ERR_LIB_SYS,ERR_str_functs);
302 build_SYS_str_reasons();
303 ERR_load_strings(ERR_LIB_SYS,SYS_str_reasons);
304#endif
305 init=0;
306 }
307 }
308
309void ERR_load_strings(int lib, ERR_STRING_DATA *str)
310 {
311 if (error_hash == NULL)
312 {
313 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
314 error_hash=lh_new(err_hash,err_cmp);
315 if (error_hash == NULL)
316 {
317 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
318 return;
319 }
320 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
321
322 ERR_load_ERR_strings();
323 }
324
325 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
326 while (str->error)
327 {
328 str->error|=ERR_PACK(lib,0,0);
329 lh_insert(error_hash,str);
330 str++;
331 }
332 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
333 }
334
335void ERR_free_strings(void)
336 {
337 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
338
339 if (error_hash != NULL)
340 {
341 lh_free(error_hash);
342 error_hash=NULL;
343 }
344
345 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
346 }
347
348/********************************************************/
349
350void ERR_put_error(int lib, int func, int reason, const char *file,
351 int line)
352 {
353 ERR_STATE *es;
354
355#ifdef _OSD_POSIX
356 /* In the BS2000-OSD POSIX subsystem, the compiler generates
357 * path names in the form "*POSIX(/etc/passwd)".
358 * This dirty hack strips them to something sensible.
359 * @@@ We shouldn't modify a const string, though.
360 */
361 if (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
362 char *end;
363
364 /* Skip the "*POSIX(" prefix */
365 file += sizeof("*POSIX(")-1;
366 end = &file[strlen(file)-1];
367 if (*end == ')')
368 *end = '\0';
369 /* Optional: use the basename of the path only. */
370 if ((end = strrchr(file, '/')) != NULL)
371 file = &end[1];
372 }
373#endif
374 es=ERR_get_state();
375
376 es->top=(es->top+1)%ERR_NUM_ERRORS;
377 if (es->top == es->bottom)
378 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
379 es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
380 es->err_file[es->top]=file;
381 es->err_line[es->top]=line;
382 err_clear_data(es,es->top);
383 }
384
385void ERR_clear_error(void)
386 {
387 ERR_STATE *es;
388
389 es=ERR_get_state();
390
391#if 0
392 /* hmm... is this needed */
393 for (i=0; i<ERR_NUM_ERRORS; i++)
394 {
395 es->err_buffer[i]=0;
396 es->err_file[i]=NULL;
397 es->err_line[i]= -1;
398 err_clear_data(es,i);
399 }
400#endif
401 es->top=es->bottom=0;
402 }
403
404
405unsigned long ERR_get_error(void)
406 { return(get_error_values(1,NULL,NULL,NULL,NULL)); }
407
408unsigned long ERR_get_error_line(const char **file,
409 int *line)
410 { return(get_error_values(1,file,line,NULL,NULL)); }
411
412unsigned long ERR_get_error_line_data(const char **file, int *line,
413 const char **data, int *flags)
414 { return(get_error_values(1,file,line,
415 data,flags)); }
416
417unsigned long ERR_peek_error(void)
418 { return(get_error_values(0,NULL,NULL,NULL,NULL)); }
419
420unsigned long ERR_peek_error_line(const char **file,
421 int *line)
422 { return(get_error_values(0,file,line,NULL,NULL)); }
423
424unsigned long ERR_peek_error_line_data(const char **file, int *line,
425 const char **data, int *flags)
426 { return(get_error_values(0,file,line,
427 data,flags)); }
428
429static unsigned long get_error_values(int inc, const char **file, int *line,
430 const char **data, int *flags)
431 {
432 int i=0;
433 ERR_STATE *es;
434 unsigned long ret;
435
436 es=ERR_get_state();
437
438 if (es->bottom == es->top) return(0);
439 i=(es->bottom+1)%ERR_NUM_ERRORS;
440
441 ret=es->err_buffer[i];
442 if (inc)
443 {
444 es->bottom=i;
445 es->err_buffer[i]=0;
446 }
447
448 if ((file != NULL) && (line != NULL))
449 {
450 if (es->err_file[i] == NULL)
451 {
452 *file="NA";
453 if (line != NULL) *line=0;
454 }
455 else
456 {
457 *file=es->err_file[i];
458 if (line != NULL) *line=es->err_line[i];
459 }
460 }
461
462 if (data != NULL)
463 {
464 if (es->err_data[i] == NULL)
465 {
466 *data="";
467 if (flags != NULL) *flags=0;
468 }
469 else
470 {
471 *data=es->err_data[i];
472 if (flags != NULL) *flags=es->err_data_flags[i];
473 }
474 }
475 return(ret);
476 }
477
478/* BAD for multi-threaded, uses a local buffer if ret == NULL */
479char *ERR_error_string(unsigned long e, char *ret)
480 {
481 static char buf[256];
482 const char *ls,*fs,*rs;
483 unsigned long l,f,r;
484 int i;
485
486 l=ERR_GET_LIB(e);
487 f=ERR_GET_FUNC(e);
488 r=ERR_GET_REASON(e);
489
490 ls=ERR_lib_error_string(e);
491 fs=ERR_func_error_string(e);
492 rs=ERR_reason_error_string(e);
493
494 if (ret == NULL) ret=buf;
495
496 sprintf(&(ret[0]),"error:%08lX:",e);
497 i=strlen(ret);
498 if (ls == NULL)
499 sprintf(&(ret[i]),":lib(%lu) ",l);
500 else sprintf(&(ret[i]),"%s",ls);
501 i=strlen(ret);
502 if (fs == NULL)
503 sprintf(&(ret[i]),":func(%lu) ",f);
504 else sprintf(&(ret[i]),":%s",fs);
505 i=strlen(ret);
506 if (rs == NULL)
507 sprintf(&(ret[i]),":reason(%lu)",r);
508 else sprintf(&(ret[i]),":%s",rs);
509
510 return(ret);
511 }
512
513LHASH *ERR_get_string_table(void)
514 {
515 return(error_hash);
516 }
517
518LHASH *ERR_get_err_state_table(void)
519 {
520 return(thread_hash);
521 }
522
523const char *ERR_lib_error_string(unsigned long e)
524 {
525 ERR_STRING_DATA d,*p=NULL;
526 unsigned long l;
527
528 l=ERR_GET_LIB(e);
529
530 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
531
532 if (error_hash != NULL)
533 {
534 d.error=ERR_PACK(l,0,0);
535 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
536 }
537
538 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
539
540 return((p == NULL)?NULL:p->string);
541 }
542
543const char *ERR_func_error_string(unsigned long e)
544 {
545 ERR_STRING_DATA d,*p=NULL;
546 unsigned long l,f;
547
548 l=ERR_GET_LIB(e);
549 f=ERR_GET_FUNC(e);
550
551 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
552
553 if (error_hash != NULL)
554 {
555 d.error=ERR_PACK(l,f,0);
556 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
557 }
558
559 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
560
561 return((p == NULL)?NULL:p->string);
562 }
563
564const char *ERR_reason_error_string(unsigned long e)
565 {
566 ERR_STRING_DATA d,*p=NULL;
567 unsigned long l,r;
568
569 l=ERR_GET_LIB(e);
570 r=ERR_GET_REASON(e);
571
572 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
573
574 if (error_hash != NULL)
575 {
576 d.error=ERR_PACK(l,0,r);
577 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
578 if (p == NULL)
579 {
580 d.error=ERR_PACK(0,0,r);
581 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
582 }
583 }
584
585 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
586
587 return((p == NULL)?NULL:p->string);
588 }
589
590static unsigned long err_hash(ERR_STRING_DATA *a)
591 {
592 unsigned long ret,l;
593
594 l=a->error;
595 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
596 return(ret^ret%19*13);
597 }
598
599static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b)
600 {
601 return((int)(a->error-b->error));
602 }
603
604static unsigned long pid_hash(ERR_STATE *a)
605 {
606 return(a->pid*13);
607 }
608
609static int pid_cmp(ERR_STATE *a, ERR_STATE *b)
610 {
611 return((int)((long)a->pid - (long)b->pid));
612 }
613
614void ERR_remove_state(unsigned long pid)
615 {
616 ERR_STATE *p,tmp;
617
618 if (thread_hash == NULL)
619 return;
620 if (pid == 0)
621 pid=(unsigned long)CRYPTO_thread_id();
622 tmp.pid=pid;
623 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
624 p=(ERR_STATE *)lh_delete(thread_hash,&tmp);
625 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
626
627 if (p != NULL) ERR_STATE_free(p);
628 }
629
630ERR_STATE *ERR_get_state(void)
631 {
632 static ERR_STATE fallback;
633 ERR_STATE *ret=NULL,tmp,*tmpp;
634 int i;
635 unsigned long pid;
636
637 pid=(unsigned long)CRYPTO_thread_id();
638
639 CRYPTO_r_lock(CRYPTO_LOCK_ERR);
640 if (thread_hash == NULL)
641 {
642 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
643 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
644 if (thread_hash == NULL)
645 {
646 MemCheck_off();
647 thread_hash=lh_new(pid_hash,pid_cmp);
648 MemCheck_on();
649 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
650 if (thread_hash == NULL) return(&fallback);
651 }
652 else
653 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
654 }
655 else
656 {
657 tmp.pid=pid;
658 ret=(ERR_STATE *)lh_retrieve(thread_hash,&tmp);
659 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
660 }
661
662 /* ret == the error state, if NULL, make a new one */
663 if (ret == NULL)
664 {
665 ret=(ERR_STATE *)Malloc(sizeof(ERR_STATE));
666 if (ret == NULL) return(&fallback);
667 ret->pid=pid;
668 ret->top=0;
669 ret->bottom=0;
670 for (i=0; i<ERR_NUM_ERRORS; i++)
671 {
672 ret->err_data[i]=NULL;
673 ret->err_data_flags[i]=0;
674 }
675 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
676 tmpp=(ERR_STATE *)lh_insert(thread_hash,ret);
677 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
678 if (tmpp != NULL) /* old entry - should not happen */
679 {
680 ERR_STATE_free(tmpp);
681 }
682 }
683 return(ret);
684 }
685
686int ERR_get_next_error_library(void)
687 {
688 static int value=ERR_LIB_USER;
689
690 return(value++);
691 }
692
693void ERR_set_error_data(char *data, int flags)
694 {
695 ERR_STATE *es;
696 int i;
697
698 es=ERR_get_state();
699
700 i=es->top;
701 if (i == 0)
702 i=ERR_NUM_ERRORS-1;
703
704 es->err_data[i]=data;
705 es->err_data_flags[es->top]=flags;
706 }
707
708void ERR_add_error_data(int num, ...)
709 {
710 va_list args;
711 int i,n,s;
712 char *str,*p,*a;
713
714 s=64;
715 str=Malloc(s+1);
716 if (str == NULL) return;
717 str[0]='\0';
718
719 va_start(args, num);
720 n=0;
721 for (i=0; i<num; i++)
722 {
723 a=va_arg(args, char*);
724 /* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
725 if (a != NULL)
726 {
727 n+=strlen(a);
728 if (n > s)
729 {
730 s=n+20;
731 p=Realloc(str,s+1);
732 if (p == NULL)
733 {
734 Free(str);
735 return;
736 }
737 else
738 str=p;
739 }
740 strcat(str,a);
741 }
742 }
743 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
744
745 va_end(args);
746 }
747
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h
deleted file mode 100644
index 15bafbff43..0000000000
--- a/src/lib/libcrypto/err/err.h
+++ /dev/null
@@ -1,265 +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#define ERR_LIB_RAND 36
126
127#define ERR_LIB_USER 128
128
129#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),ERR_file_name,__LINE__)
130#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),ERR_file_name,__LINE__)
131#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),ERR_file_name,__LINE__)
132#define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),ERR_file_name,__LINE__)
133#define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),ERR_file_name,__LINE__)
134#define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),ERR_file_name,__LINE__)
135#define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),ERR_file_name,__LINE__)
136#define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),ERR_file_name,__LINE__)
137#define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),ERR_file_name,__LINE__)
138#define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),ERR_file_name,__LINE__)
139#define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),ERR_file_name,__LINE__)
140#define METHerr(f,r) ERR_PUT_error(ERR_LIB_METH,(f),(r),ERR_file_name,__LINE__)
141#define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),ERR_file_name,__LINE__)
142#define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),ERR_file_name,__LINE__)
143#define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),ERR_file_name,__LINE__)
144#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),ERR_file_name,__LINE__)
145#define SSL23err(f,r) ERR_PUT_error(ERR_LIB_SSL23,(f),(r),ERR_file_name,__LINE__)
146#define SSL2err(f,r) ERR_PUT_error(ERR_LIB_SSL2,(f),(r),ERR_file_name,__LINE__)
147#define SSL3err(f,r) ERR_PUT_error(ERR_LIB_SSL3,(f),(r),ERR_file_name,__LINE__)
148#define RSAREFerr(f,r) ERR_PUT_error(ERR_LIB_RSAREF,(f),(r),ERR_file_name,__LINE__)
149#define PROXYerr(f,r) ERR_PUT_error(ERR_LIB_PROXY,(f),(r),ERR_file_name,__LINE__)
150#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__)
151#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__)
152#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__)
153#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),ERR_file_name,__LINE__)
154
155/* Borland C seems too stupid to be able to shift and do longs in
156 * the pre-processor :-( */
157#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)*0x1000000)| \
158 ((((unsigned long)f)&0xfffL)*0x1000)| \
159 ((((unsigned long)r)&0xfffL)))
160#define ERR_GET_LIB(l) (int)((((unsigned long)l)>>24L)&0xffL)
161#define ERR_GET_FUNC(l) (int)((((unsigned long)l)>>12L)&0xfffL)
162#define ERR_GET_REASON(l) (int)((l)&0xfffL)
163#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL)
164
165/* OS functions */
166#define SYS_F_FOPEN 1
167#define SYS_F_CONNECT 2
168#define SYS_F_GETSERVBYNAME 3
169#define SYS_F_SOCKET 4
170#define SYS_F_IOCTLSOCKET 5
171#define SYS_F_BIND 6
172#define SYS_F_LISTEN 7
173#define SYS_F_ACCEPT 8
174#define SYS_F_WSASTARTUP 9 /* Winsock stuff */
175#define SYS_F_OPENDIR 10
176
177#define ERR_R_FATAL 32
178/* reasons */
179#define ERR_R_SYS_LIB ERR_LIB_SYS
180#define ERR_R_BN_LIB ERR_LIB_BN
181#define ERR_R_RSA_LIB ERR_LIB_RSA
182#define ERR_R_DSA_LIB ERR_LIB_DSA
183#define ERR_R_DH_LIB ERR_LIB_DH
184#define ERR_R_EVP_LIB ERR_LIB_EVP
185#define ERR_R_BUF_LIB ERR_LIB_BUF
186#define ERR_R_BIO_LIB ERR_LIB_BIO
187#define ERR_R_OBJ_LIB ERR_LIB_OBJ
188#define ERR_R_PEM_LIB ERR_LIB_PEM
189#define ERR_R_X509_LIB ERR_LIB_X509
190#define ERR_R_METH_LIB ERR_LIB_METH
191#define ERR_R_ASN1_LIB ERR_LIB_ASN1
192#define ERR_R_CONF_LIB ERR_LIB_CONF
193#define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO
194#define ERR_R_SSL_LIB ERR_LIB_SSL
195#define ERR_R_SSL23_LIB ERR_LIB_SSL23
196#define ERR_R_SSL2_LIB ERR_LIB_SSL2
197#define ERR_R_SSL3_LIB ERR_LIB_SSL3
198#define ERR_R_PROXY_LIB ERR_LIB_PROXY
199#define ERR_R_BIO_LIB ERR_LIB_BIO
200#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7
201#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12
202
203/* fatal error */
204#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
205#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
206#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
207#define ERR_R_NESTED_ASN1_ERROR (4)
208#define ERR_R_BAD_ASN1_OBJECT_HEADER (5)
209#define ERR_R_BAD_GET_ASN1_OBJECT_CALL (6)
210#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE (7)
211#define ERR_R_ASN1_LENGTH_MISMATCH (8)
212#define ERR_R_MISSING_ASN1_EOS (9)
213
214typedef struct ERR_string_data_st
215 {
216 unsigned long error;
217 const char *string;
218 } ERR_STRING_DATA;
219
220void ERR_put_error(int lib, int func,int reason,const char *file,int line);
221void ERR_set_error_data(char *data,int flags);
222
223unsigned long ERR_get_error(void );
224unsigned long ERR_get_error_line(const char **file,int *line);
225unsigned long ERR_get_error_line_data(const char **file,int *line,
226 const char **data, int *flags);
227unsigned long ERR_peek_error(void );
228unsigned long ERR_peek_error_line(const char **file,int *line);
229unsigned long ERR_peek_error_line_data(const char **file,int *line,
230 const char **data,int *flags);
231void ERR_clear_error(void );
232char *ERR_error_string(unsigned long e,char *buf);
233const char *ERR_lib_error_string(unsigned long e);
234const char *ERR_func_error_string(unsigned long e);
235const char *ERR_reason_error_string(unsigned long e);
236#ifndef NO_FP_API
237void ERR_print_errors_fp(FILE *fp);
238#endif
239#ifdef HEADER_BIO_H
240void ERR_print_errors(BIO *bp);
241void ERR_add_error_data(int num, ...);
242#endif
243void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
244void ERR_load_ERR_strings(void);
245void ERR_load_crypto_strings(void);
246void ERR_free_strings(void);
247
248void ERR_remove_state(unsigned long pid); /* if zero we look it up */
249ERR_STATE *ERR_get_state(void);
250
251#ifdef HEADER_LHASH_H
252LHASH *ERR_get_string_table(void );
253LHASH *ERR_get_err_state_table(void );
254#else
255char *ERR_get_string_table(void );
256char *ERR_get_err_state_table(void );
257#endif
258
259int ERR_get_next_error_library(void );
260
261#ifdef __cplusplus
262}
263#endif
264
265#endif
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
deleted file mode 100644
index 10c463b389..0000000000
--- a/src/lib/libcrypto/err/err_all.c
+++ /dev/null
@@ -1,122 +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/rand.h>
84#include <openssl/err.h>
85
86void ERR_load_crypto_strings(void)
87 {
88 static int done=0;
89
90 if (done) return;
91 done=1;
92#ifndef NO_ERR
93 ERR_load_ASN1_strings();
94 ERR_load_BN_strings();
95 ERR_load_BUF_strings();
96 ERR_load_BIO_strings();
97 ERR_load_CONF_strings();
98#ifndef NO_RSA
99#ifdef RSAref
100 ERR_load_RSAREF_strings();
101#else
102 ERR_load_RSA_strings();
103#endif
104#endif
105#ifndef NO_DH
106 ERR_load_DH_strings();
107#endif
108#ifndef NO_DSA
109 ERR_load_DSA_strings();
110#endif
111 ERR_load_ERR_strings();
112 ERR_load_EVP_strings();
113 ERR_load_OBJ_strings();
114 ERR_load_PEM_strings();
115 ERR_load_X509_strings();
116 ERR_load_X509V3_strings();
117 ERR_load_CRYPTO_strings();
118 ERR_load_PKCS7_strings();
119 ERR_load_PKCS12_strings();
120 ERR_load_RAND_strings();
121#endif
122 }
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 e132ba3182..0000000000
--- a/src/lib/libcrypto/err/openssl.ec
+++ /dev/null
@@ -1,72 +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
24L RAND crypto/rand/rand.h crypto/rand/rand_err.c
25
26
27F RSAREF_F_RSA_BN2BIN
28F RSAREF_F_RSA_PRIVATE_DECRYPT
29F RSAREF_F_RSA_PRIVATE_ENCRYPT
30F RSAREF_F_RSA_PUBLIC_DECRYPT
31F RSAREF_F_RSA_PUBLIC_ENCRYPT
32#F SSL_F_CLIENT_CERTIFICATE
33
34R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
35R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
36R SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
37R SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
38R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
39R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
40R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
41R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
42R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
43R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
44R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
45R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
46R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
47R SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
48R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
49R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
50R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
51R SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
52R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
53R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
54R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
55R SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
56R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
57
58R RSAREF_R_CONTENT_ENCODING 0x0400
59R RSAREF_R_DATA 0x0401
60R RSAREF_R_DIGEST_ALGORITHM 0x0402
61R RSAREF_R_ENCODING 0x0403
62R RSAREF_R_KEY 0x0404
63R RSAREF_R_KEY_ENCODING 0x0405
64R RSAREF_R_LEN 0x0406
65R RSAREF_R_MODULUS_LEN 0x0407
66R RSAREF_R_NEED_RANDOM 0x0408
67R RSAREF_R_PRIVATE_KEY 0x0409
68R RSAREF_R_PUBLIC_KEY 0x040a
69R RSAREF_R_SIGNATURE 0x040b
70R RSAREF_R_SIGNATURE_ENCODING 0x040c
71R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d
72
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
deleted file mode 100644
index bd5e24f993..0000000000
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ /dev/null
@@ -1,540 +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);
72static long b64_callback_ctrl(BIO *h,int cmd,void (*fp)());
73#define B64_BLOCK_SIZE 1024
74#define B64_BLOCK_SIZE2 768
75#define B64_NONE 0
76#define B64_ENCODE 1
77#define B64_DECODE 2
78
79typedef struct b64_struct
80 {
81 /*BIO *bio; moved to the BIO structure */
82 int buf_len;
83 int buf_off;
84 int tmp_len; /* used to find the start when decoding */
85 int tmp_nl; /* If true, scan until '\n' */
86 int encode;
87 int start; /* have we started decoding yet? */
88 int cont; /* <= 0 when finished */
89 EVP_ENCODE_CTX base64;
90 char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10];
91 char tmp[B64_BLOCK_SIZE];
92 } BIO_B64_CTX;
93
94static BIO_METHOD methods_b64=
95 {
96 BIO_TYPE_BASE64,"base64 encoding",
97 b64_write,
98 b64_read,
99 NULL, /* b64_puts, */
100 NULL, /* b64_gets, */
101 b64_ctrl,
102 b64_new,
103 b64_free,
104 b64_callback_ctrl,
105 };
106
107BIO_METHOD *BIO_f_base64(void)
108 {
109 return(&methods_b64);
110 }
111
112static int b64_new(BIO *bi)
113 {
114 BIO_B64_CTX *ctx;
115
116 ctx=(BIO_B64_CTX *)Malloc(sizeof(BIO_B64_CTX));
117 if (ctx == NULL) return(0);
118
119 ctx->buf_len=0;
120 ctx->tmp_len=0;
121 ctx->tmp_nl=0;
122 ctx->buf_off=0;
123 ctx->cont=1;
124 ctx->start=1;
125 ctx->encode=0;
126
127 bi->init=1;
128 bi->ptr=(char *)ctx;
129 bi->flags=0;
130 return(1);
131 }
132
133static int b64_free(BIO *a)
134 {
135 if (a == NULL) return(0);
136 Free(a->ptr);
137 a->ptr=NULL;
138 a->init=0;
139 a->flags=0;
140 return(1);
141 }
142
143static int b64_read(BIO *b, char *out, int outl)
144 {
145 int ret=0,i,ii,j,k,x,n,num,ret_code=0;
146 BIO_B64_CTX *ctx;
147 unsigned char *p,*q;
148
149 if (out == NULL) return(0);
150 ctx=(BIO_B64_CTX *)b->ptr;
151
152 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
153
154 if (ctx->encode != B64_DECODE)
155 {
156 ctx->encode=B64_DECODE;
157 ctx->buf_len=0;
158 ctx->buf_off=0;
159 ctx->tmp_len=0;
160 EVP_DecodeInit(&(ctx->base64));
161 }
162
163 /* First check if there are bytes decoded/encoded */
164 if (ctx->buf_len > 0)
165 {
166 i=ctx->buf_len-ctx->buf_off;
167 if (i > outl) i=outl;
168 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
169 ret=i;
170 out+=i;
171 outl-=i;
172 ctx->buf_off+=i;
173 if (ctx->buf_len == ctx->buf_off)
174 {
175 ctx->buf_len=0;
176 ctx->buf_off=0;
177 }
178 }
179
180 /* At this point, we have room of outl bytes and an empty
181 * buffer, so we should read in some more. */
182
183 ret_code=0;
184 while (outl > 0)
185 {
186 if (ctx->cont <= 0) break;
187
188 i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]),
189 B64_BLOCK_SIZE-ctx->tmp_len);
190
191 if (i <= 0)
192 {
193 ret_code=i;
194
195 /* Should be continue next time we are called? */
196 if (!BIO_should_retry(b->next_bio))
197 ctx->cont=i;
198 /* else we should continue when called again */
199 break;
200 }
201 i+=ctx->tmp_len;
202
203 /* We need to scan, a line at a time until we
204 * have a valid line if we are starting. */
205 if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL))
206 {
207 /* ctx->start=1; */
208 ctx->tmp_len=0;
209 }
210 else if (ctx->start)
211 {
212 q=p=(unsigned char *)ctx->tmp;
213 for (j=0; j<i; j++)
214 {
215 if (*(q++) != '\n') continue;
216
217 /* due to a previous very long line,
218 * we need to keep on scanning for a '\n'
219 * before we even start looking for
220 * base64 encoded stuff. */
221 if (ctx->tmp_nl)
222 {
223 p=q;
224 ctx->tmp_nl=0;
225 continue;
226 }
227
228 k=EVP_DecodeUpdate(&(ctx->base64),
229 (unsigned char *)ctx->buf,
230 &num,p,q-p);
231 if ((k <= 0) && (num == 0) && (ctx->start))
232 EVP_DecodeInit(&ctx->base64);
233 else
234 {
235 if (p != (unsigned char *)
236 &(ctx->tmp[0]))
237 {
238 i-=(p- (unsigned char *)
239 &(ctx->tmp[0]));
240 for (x=0; x < i; x++)
241 ctx->tmp[x]=p[x];
242 }
243 EVP_DecodeInit(&ctx->base64);
244 ctx->start=0;
245 break;
246 }
247 p=q;
248 }
249
250 /* we fell off the end without starting */
251 if (j == i)
252 {
253 /* Is this is one long chunk?, if so, keep on
254 * reading until a new line. */
255 if (p == (unsigned char *)&(ctx->tmp[0]))
256 {
257 ctx->tmp_nl=1;
258 ctx->tmp_len=0;
259 }
260 else if (p != q) /* finished on a '\n' */
261 {
262 n=q-p;
263 for (ii=0; ii<n; ii++)
264 ctx->tmp[ii]=p[ii];
265 ctx->tmp_len=n;
266 }
267 /* else finished on a '\n' */
268 continue;
269 }
270 else
271 ctx->tmp_len=0;
272 }
273
274 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
275 {
276 int z,jj;
277
278 jj=(i>>2)<<2;
279 z=EVP_DecodeBlock((unsigned char *)ctx->buf,
280 (unsigned char *)ctx->tmp,jj);
281 if (jj > 2)
282 {
283 if (ctx->tmp[jj-1] == '=')
284 {
285 z--;
286 if (ctx->tmp[jj-2] == '=')
287 z--;
288 }
289 }
290 /* z is now number of output bytes and jj is the
291 * number consumed */
292 if (jj != i)
293 {
294 memcpy((unsigned char *)ctx->tmp,
295 (unsigned char *)&(ctx->tmp[jj]),i-jj);
296 ctx->tmp_len=i-jj;
297 }
298 ctx->buf_len=0;
299 if (z > 0)
300 {
301 ctx->buf_len=z;
302 i=1;
303 }
304 else
305 i=z;
306 }
307 else
308 {
309 i=EVP_DecodeUpdate(&(ctx->base64),
310 (unsigned char *)ctx->buf,&ctx->buf_len,
311 (unsigned char *)ctx->tmp,i);
312 }
313 ctx->cont=i;
314 ctx->buf_off=0;
315 if (i < 0)
316 {
317 ret_code=0;
318 ctx->buf_len=0;
319 break;
320 }
321
322 if (ctx->buf_len <= outl)
323 i=ctx->buf_len;
324 else
325 i=outl;
326
327 memcpy(out,ctx->buf,i);
328 ret+=i;
329 ctx->buf_off=i;
330 if (ctx->buf_off == ctx->buf_len)
331 {
332 ctx->buf_len=0;
333 ctx->buf_off=0;
334 }
335 outl-=i;
336 out+=i;
337 }
338 BIO_clear_retry_flags(b);
339 BIO_copy_next_retry(b);
340 return((ret == 0)?ret_code:ret);
341 }
342
343static int b64_write(BIO *b, char *in, int inl)
344 {
345 int ret=inl,n,i;
346 BIO_B64_CTX *ctx;
347
348 ctx=(BIO_B64_CTX *)b->ptr;
349 BIO_clear_retry_flags(b);
350
351 if (ctx->encode != B64_ENCODE)
352 {
353 ctx->encode=B64_ENCODE;
354 ctx->buf_len=0;
355 ctx->buf_off=0;
356 ctx->tmp_len=0;
357 EVP_EncodeInit(&(ctx->base64));
358 }
359
360 n=ctx->buf_len-ctx->buf_off;
361 while (n > 0)
362 {
363 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
364 if (i <= 0)
365 {
366 BIO_copy_next_retry(b);
367 return(i);
368 }
369 ctx->buf_off+=i;
370 n-=i;
371 }
372 /* at this point all pending data has been written */
373
374 if ((in == NULL) || (inl <= 0)) return(0);
375
376 ctx->buf_off=0;
377 while (inl > 0)
378 {
379 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
380
381 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
382 {
383 if (ctx->tmp_len > 0)
384 {
385 n=3-ctx->tmp_len;
386 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
387 ctx->tmp_len+=n;
388 n=ctx->tmp_len;
389 if (n < 3)
390 break;
391 ctx->buf_len=EVP_EncodeBlock(
392 (unsigned char *)ctx->buf,
393 (unsigned char *)ctx->tmp,n);
394 }
395 else
396 {
397 if (n < 3)
398 {
399 memcpy(&(ctx->tmp[0]),in,n);
400 ctx->tmp_len=n;
401 break;
402 }
403 n-=n%3;
404 ctx->buf_len=EVP_EncodeBlock(
405 (unsigned char *)ctx->buf,
406 (unsigned char *)in,n);
407 }
408 }
409 else
410 {
411 EVP_EncodeUpdate(&(ctx->base64),
412 (unsigned char *)ctx->buf,&ctx->buf_len,
413 (unsigned char *)in,n);
414 }
415 inl-=n;
416 in+=n;
417
418 ctx->buf_off=0;
419 n=ctx->buf_len;
420 while (n > 0)
421 {
422 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
423 if (i <= 0)
424 {
425 BIO_copy_next_retry(b);
426 return((ret == 0)?i:ret);
427 }
428 n-=i;
429 ctx->buf_off+=i;
430 }
431 ctx->buf_len=0;
432 ctx->buf_off=0;
433 }
434 return(ret);
435 }
436
437static long b64_ctrl(BIO *b, int cmd, long num, char *ptr)
438 {
439 BIO_B64_CTX *ctx;
440 long ret=1;
441 int i;
442
443 ctx=(BIO_B64_CTX *)b->ptr;
444
445 switch (cmd)
446 {
447 case BIO_CTRL_RESET:
448 ctx->cont=1;
449 ctx->start=1;
450 ctx->encode=B64_NONE;
451 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
452 break;
453 case BIO_CTRL_EOF: /* More to read */
454 if (ctx->cont <= 0)
455 ret=1;
456 else
457 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
458 break;
459 case BIO_CTRL_WPENDING: /* More to write in buffer */
460 ret=ctx->buf_len-ctx->buf_off;
461 if ((ret == 0) && (ctx->base64.num != 0))
462 ret=1;
463 else if (ret <= 0)
464 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
465 break;
466 case BIO_CTRL_PENDING: /* More to read in buffer */
467 ret=ctx->buf_len-ctx->buf_off;
468 if (ret <= 0)
469 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
470 break;
471 case BIO_CTRL_FLUSH:
472 /* do a final write */
473again:
474 while (ctx->buf_len != ctx->buf_off)
475 {
476 i=b64_write(b,NULL,0);
477 if (i < 0)
478 {
479 ret=i;
480 break;
481 }
482 }
483 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
484 {
485 if (ctx->tmp_len != 0)
486 {
487 ctx->buf_len=EVP_EncodeBlock(
488 (unsigned char *)ctx->buf,
489 (unsigned char *)ctx->tmp,
490 ctx->tmp_len);
491 ctx->buf_off=0;
492 ctx->tmp_len=0;
493 goto again;
494 }
495 }
496 else if (ctx->base64.num != 0)
497 {
498 ctx->buf_off=0;
499 EVP_EncodeFinal(&(ctx->base64),
500 (unsigned char *)ctx->buf,
501 &(ctx->buf_len));
502 /* push out the bytes */
503 goto again;
504 }
505 /* Finally flush the underlying BIO */
506 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
507 break;
508
509 case BIO_C_DO_STATE_MACHINE:
510 BIO_clear_retry_flags(b);
511 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
512 BIO_copy_next_retry(b);
513 break;
514
515 case BIO_CTRL_DUP:
516 break;
517 case BIO_CTRL_INFO:
518 case BIO_CTRL_GET:
519 case BIO_CTRL_SET:
520 default:
521 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
522 break;
523 }
524 return(ret);
525 }
526
527static long b64_callback_ctrl(BIO *b, int cmd, void (*fp)())
528 {
529 long ret=1;
530
531 if (b->next_bio == NULL) return(0);
532 switch (cmd)
533 {
534 default:
535 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
536 break;
537 }
538 return(ret);
539 }
540
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
deleted file mode 100644
index 629bf4b95d..0000000000
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ /dev/null
@@ -1,425 +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);
72static long enc_callback_ctrl(BIO *h,int cmd,void (*fp)());
73#define ENC_BLOCK_SIZE (1024*4)
74
75typedef struct enc_struct
76 {
77 int buf_len;
78 int buf_off;
79 int cont; /* <= 0 when finished */
80 int finished;
81 int ok; /* bad decrypt */
82 EVP_CIPHER_CTX cipher;
83 char buf[ENC_BLOCK_SIZE+10];
84 } BIO_ENC_CTX;
85
86static BIO_METHOD methods_enc=
87 {
88 BIO_TYPE_CIPHER,"cipher",
89 enc_write,
90 enc_read,
91 NULL, /* enc_puts, */
92 NULL, /* enc_gets, */
93 enc_ctrl,
94 enc_new,
95 enc_free,
96 enc_callback_ctrl,
97 };
98
99BIO_METHOD *BIO_f_cipher(void)
100 {
101 return(&methods_enc);
102 }
103
104static int enc_new(BIO *bi)
105 {
106 BIO_ENC_CTX *ctx;
107
108 ctx=(BIO_ENC_CTX *)Malloc(sizeof(BIO_ENC_CTX));
109 EVP_CIPHER_CTX_init(&ctx->cipher);
110 if (ctx == NULL) return(0);
111
112 ctx->buf_len=0;
113 ctx->buf_off=0;
114 ctx->cont=1;
115 ctx->finished=0;
116 ctx->ok=1;
117
118 bi->init=0;
119 bi->ptr=(char *)ctx;
120 bi->flags=0;
121 return(1);
122 }
123
124static int enc_free(BIO *a)
125 {
126 BIO_ENC_CTX *b;
127
128 if (a == NULL) return(0);
129 b=(BIO_ENC_CTX *)a->ptr;
130 EVP_CIPHER_CTX_cleanup(&(b->cipher));
131 memset(a->ptr,0,sizeof(BIO_ENC_CTX));
132 Free(a->ptr);
133 a->ptr=NULL;
134 a->init=0;
135 a->flags=0;
136 return(1);
137 }
138
139static int enc_read(BIO *b, char *out, int outl)
140 {
141 int ret=0,i;
142 BIO_ENC_CTX *ctx;
143
144 if (out == NULL) return(0);
145 ctx=(BIO_ENC_CTX *)b->ptr;
146
147 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
148
149 /* First check if there are bytes decoded/encoded */
150 if (ctx->buf_len > 0)
151 {
152 i=ctx->buf_len-ctx->buf_off;
153 if (i > outl) i=outl;
154 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
155 ret=i;
156 out+=i;
157 outl-=i;
158 ctx->buf_off+=i;
159 if (ctx->buf_len == ctx->buf_off)
160 {
161 ctx->buf_len=0;
162 ctx->buf_off=0;
163 }
164 }
165
166 /* At this point, we have room of outl bytes and an empty
167 * buffer, so we should read in some more. */
168
169 while (outl > 0)
170 {
171 if (ctx->cont <= 0) break;
172
173 /* read in at offset 8, read the EVP_Cipher
174 * documentation about why */
175 i=BIO_read(b->next_bio,&(ctx->buf[8]),ENC_BLOCK_SIZE);
176
177 if (i <= 0)
178 {
179 /* Should be continue next time we are called? */
180 if (!BIO_should_retry(b->next_bio))
181 {
182 ctx->cont=i;
183 i=EVP_CipherFinal(&(ctx->cipher),
184 (unsigned char *)ctx->buf,
185 &(ctx->buf_len));
186 ctx->ok=i;
187 ctx->buf_off=0;
188 }
189 else
190 {
191 ret=(ret == 0)?i:ret;
192 break;
193 }
194 }
195 else
196 {
197 EVP_CipherUpdate(&(ctx->cipher),
198 (unsigned char *)ctx->buf,&ctx->buf_len,
199 (unsigned char *)&(ctx->buf[8]),i);
200 ctx->cont=1;
201 /* Note: it is possible for EVP_CipherUpdate to
202 * decrypt zero bytes because this is or looks like
203 * the final block: if this happens we should retry
204 * and either read more data or decrypt the final
205 * block
206 */
207 if(ctx->buf_len == 0) continue;
208 }
209
210 if (ctx->buf_len <= outl)
211 i=ctx->buf_len;
212 else
213 i=outl;
214 if (i <= 0) break;
215 memcpy(out,ctx->buf,i);
216 ret+=i;
217 ctx->buf_off=i;
218 outl-=i;
219 out+=i;
220 }
221
222 BIO_clear_retry_flags(b);
223 BIO_copy_next_retry(b);
224 return((ret == 0)?ctx->cont:ret);
225 }
226
227static int enc_write(BIO *b, char *in, int inl)
228 {
229 int ret=0,n,i;
230 BIO_ENC_CTX *ctx;
231
232 ctx=(BIO_ENC_CTX *)b->ptr;
233 ret=inl;
234
235 BIO_clear_retry_flags(b);
236 n=ctx->buf_len-ctx->buf_off;
237 while (n > 0)
238 {
239 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
240 if (i <= 0)
241 {
242 BIO_copy_next_retry(b);
243 return(i);
244 }
245 ctx->buf_off+=i;
246 n-=i;
247 }
248 /* at this point all pending data has been written */
249
250 if ((in == NULL) || (inl <= 0)) return(0);
251
252 ctx->buf_off=0;
253 while (inl > 0)
254 {
255 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
256 EVP_CipherUpdate(&(ctx->cipher),
257 (unsigned char *)ctx->buf,&ctx->buf_len,
258 (unsigned char *)in,n);
259 inl-=n;
260 in+=n;
261
262 ctx->buf_off=0;
263 n=ctx->buf_len;
264 while (n > 0)
265 {
266 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
267 if (i <= 0)
268 {
269 BIO_copy_next_retry(b);
270 return(i);
271 }
272 n-=i;
273 ctx->buf_off+=i;
274 }
275 ctx->buf_len=0;
276 ctx->buf_off=0;
277 }
278 BIO_copy_next_retry(b);
279 return(ret);
280 }
281
282static long enc_ctrl(BIO *b, int cmd, long num, char *ptr)
283 {
284 BIO *dbio;
285 BIO_ENC_CTX *ctx,*dctx;
286 long ret=1;
287 int i;
288 EVP_CIPHER_CTX **c_ctx;
289
290 ctx=(BIO_ENC_CTX *)b->ptr;
291
292 switch (cmd)
293 {
294 case BIO_CTRL_RESET:
295 ctx->ok=1;
296 ctx->finished=0;
297 EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL,
298 ctx->cipher.encrypt);
299 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
300 break;
301 case BIO_CTRL_EOF: /* More to read */
302 if (ctx->cont <= 0)
303 ret=1;
304 else
305 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
306 break;
307 case BIO_CTRL_WPENDING:
308 ret=ctx->buf_len-ctx->buf_off;
309 if (ret <= 0)
310 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
311 break;
312 case BIO_CTRL_PENDING: /* More to read in buffer */
313 ret=ctx->buf_len-ctx->buf_off;
314 if (ret <= 0)
315 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
316 break;
317 case BIO_CTRL_FLUSH:
318 /* do a final write */
319again:
320 while (ctx->buf_len != ctx->buf_off)
321 {
322 i=enc_write(b,NULL,0);
323 if (i < 0)
324 {
325 ret=i;
326 break;
327 }
328 }
329
330 if (!ctx->finished)
331 {
332 ctx->finished=1;
333 ctx->buf_off=0;
334 ret=EVP_CipherFinal(&(ctx->cipher),
335 (unsigned char *)ctx->buf,
336 &(ctx->buf_len));
337 ctx->ok=(int)ret;
338 if (ret <= 0) break;
339
340 /* push out the bytes */
341 goto again;
342 }
343
344 /* Finally flush the underlying BIO */
345 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
346 break;
347 case BIO_C_GET_CIPHER_STATUS:
348 ret=(long)ctx->ok;
349 break;
350 case BIO_C_DO_STATE_MACHINE:
351 BIO_clear_retry_flags(b);
352 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
353 BIO_copy_next_retry(b);
354 break;
355 case BIO_C_GET_CIPHER_CTX:
356 c_ctx=(EVP_CIPHER_CTX **)ptr;
357 (*c_ctx)= &(ctx->cipher);
358 b->init=1;
359 break;
360 case BIO_CTRL_DUP:
361 dbio=(BIO *)ptr;
362 dctx=(BIO_ENC_CTX *)dbio->ptr;
363 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
364 dbio->init=1;
365 break;
366 default:
367 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
368 break;
369 }
370 return(ret);
371 }
372
373static long enc_callback_ctrl(BIO *b, int cmd, void (*fp)())
374 {
375 long ret=1;
376
377 if (b->next_bio == NULL) return(0);
378 switch (cmd)
379 {
380 default:
381 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
382 break;
383 }
384 return(ret);
385 }
386
387/*
388void BIO_set_cipher_ctx(b,c)
389BIO *b;
390EVP_CIPHER_ctx *c;
391 {
392 if (b == NULL) return;
393
394 if ((b->callback != NULL) &&
395 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
396 return;
397
398 b->init=1;
399 ctx=(BIO_ENC_CTX *)b->ptr;
400 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
401
402 if (b->callback != NULL)
403 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
404 }
405*/
406
407void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
408 unsigned char *i, int e)
409 {
410 BIO_ENC_CTX *ctx;
411
412 if (b == NULL) return;
413
414 if ((b->callback != NULL) &&
415 (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0))
416 return;
417
418 b->init=1;
419 ctx=(BIO_ENC_CTX *)b->ptr;
420 EVP_CipherInit(&(ctx->cipher),c,k,i,e);
421
422 if (b->callback != NULL)
423 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);
424 }
425
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
deleted file mode 100644
index aef928dd8f..0000000000
--- a/src/lib/libcrypto/evp/bio_md.c
+++ /dev/null
@@ -1,261 +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 long md_callback_ctrl(BIO *h,int cmd,void (*fp)());
76
77static BIO_METHOD methods_md=
78 {
79 BIO_TYPE_MD,"message digest",
80 md_write,
81 md_read,
82 NULL, /* md_puts, */
83 md_gets,
84 md_ctrl,
85 md_new,
86 md_free,
87 md_callback_ctrl,
88 };
89
90BIO_METHOD *BIO_f_md(void)
91 {
92 return(&methods_md);
93 }
94
95static int md_new(BIO *bi)
96 {
97 EVP_MD_CTX *ctx;
98
99 ctx=(EVP_MD_CTX *)Malloc(sizeof(EVP_MD_CTX));
100 if (ctx == NULL) return(0);
101
102 bi->init=0;
103 bi->ptr=(char *)ctx;
104 bi->flags=0;
105 return(1);
106 }
107
108static int md_free(BIO *a)
109 {
110 if (a == NULL) return(0);
111 Free(a->ptr);
112 a->ptr=NULL;
113 a->init=0;
114 a->flags=0;
115 return(1);
116 }
117
118static int md_read(BIO *b, char *out, int outl)
119 {
120 int ret=0;
121 EVP_MD_CTX *ctx;
122
123 if (out == NULL) return(0);
124 ctx=(EVP_MD_CTX *)b->ptr;
125
126 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
127
128 ret=BIO_read(b->next_bio,out,outl);
129 if (b->init)
130 {
131 if (ret > 0)
132 {
133 EVP_DigestUpdate(ctx,(unsigned char *)out,
134 (unsigned int)ret);
135 }
136 }
137 BIO_clear_retry_flags(b);
138 BIO_copy_next_retry(b);
139 return(ret);
140 }
141
142static int md_write(BIO *b, char *in, int inl)
143 {
144 int ret=0;
145 EVP_MD_CTX *ctx;
146
147 if ((in == NULL) || (inl <= 0)) return(0);
148 ctx=(EVP_MD_CTX *)b->ptr;
149
150 if ((ctx != NULL) && (b->next_bio != NULL))
151 ret=BIO_write(b->next_bio,in,inl);
152 if (b->init)
153 {
154 if (ret > 0)
155 {
156 EVP_DigestUpdate(ctx,(unsigned char *)in,
157 (unsigned int)ret);
158 }
159 }
160 BIO_clear_retry_flags(b);
161 BIO_copy_next_retry(b);
162 return(ret);
163 }
164
165static long md_ctrl(BIO *b, int cmd, long num, char *ptr)
166 {
167 EVP_MD_CTX *ctx,*dctx,**pctx;
168 const EVP_MD **ppmd;
169 EVP_MD *md;
170 long ret=1;
171 BIO *dbio;
172
173 ctx=(EVP_MD_CTX *)b->ptr;
174
175 switch (cmd)
176 {
177 case BIO_CTRL_RESET:
178 if (b->init)
179 EVP_DigestInit(ctx,ctx->digest);
180 else
181 ret=0;
182 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
183 break;
184 case BIO_C_GET_MD:
185 if (b->init)
186 {
187 ppmd=(const EVP_MD **)ptr;
188 *ppmd=ctx->digest;
189 }
190 else
191 ret=0;
192 break;
193 case BIO_C_GET_MD_CTX:
194 if (b->init)
195 {
196 pctx=(EVP_MD_CTX **)ptr;
197 *pctx=ctx;
198 }
199 else
200 ret=0;
201 break;
202 case BIO_C_DO_STATE_MACHINE:
203 BIO_clear_retry_flags(b);
204 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
205 BIO_copy_next_retry(b);
206 break;
207
208 case BIO_C_SET_MD:
209 md=(EVP_MD *)ptr;
210 EVP_DigestInit(ctx,md);
211 b->init=1;
212 break;
213 case BIO_CTRL_DUP:
214 dbio=(BIO *)ptr;
215 dctx=(EVP_MD_CTX *)dbio->ptr;
216 memcpy(dctx,ctx,sizeof(ctx));
217 b->init=1;
218 break;
219 default:
220 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
221 break;
222 }
223 return(ret);
224 }
225
226static long md_callback_ctrl(BIO *b, int cmd, void (*fp)())
227 {
228 long ret=1;
229
230 if (b->next_bio == NULL) return(0);
231 switch (cmd)
232 {
233 default:
234 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
235 break;
236 }
237 return(ret);
238 }
239
240static int md_gets(BIO *bp, char *buf, int size)
241 {
242 EVP_MD_CTX *ctx;
243 unsigned int ret;
244
245
246 ctx=(EVP_MD_CTX *)bp->ptr;
247 if (size < ctx->digest->md_size)
248 return(0);
249 EVP_DigestFinal(ctx,(unsigned char *)buf,&ret);
250 return((int)ret);
251 }
252
253/*
254static int md_puts(bp,str)
255BIO *bp;
256char *str;
257 {
258 return(-1);
259 }
260*/
261
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
deleted file mode 100644
index 1e185830a3..0000000000
--- a/src/lib/libcrypto/evp/c_all.c
+++ /dev/null
@@ -1,67 +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
63void OpenSSL_add_all_algorithms(void)
64{
65 OpenSSL_add_all_ciphers();
66 OpenSSL_add_all_digests();
67}
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 7568fad4ff..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_unchecked(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 14a4cb11f6..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, const 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, const 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 54215b0905..0000000000
--- a/src/lib/libcrypto/evp/evp.h
+++ /dev/null
@@ -1,743 +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 * arbitrary 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; /* application 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_md(e) ((e)->digest)
425#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
426#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
427#define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
428
429#define EVP_CIPHER_nid(e) ((e)->nid)
430#define EVP_CIPHER_block_size(e) ((e)->block_size)
431#define EVP_CIPHER_key_length(e) ((e)->key_len)
432#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
433
434#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
435#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
436#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
437#define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len)
438#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
439#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
440#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
441#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
442
443#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
444#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
445
446#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
447#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
448#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
449#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
450#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
451#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
452
453#ifdef CONST_STRICT
454void BIO_set_md(BIO *,const EVP_MD *md);
455#else
456# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
457#endif
458#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
459#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
460#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
461#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
462
463#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
464
465#define EVP_add_cipher_alias(n,alias) \
466 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
467#define EVP_add_digest_alias(n,alias) \
468 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
469#define EVP_delete_cipher_alias(alias) \
470 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
471#define EVP_delete_digest_alias(alias) \
472 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
473
474
475int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
476void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
477void EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
478 unsigned int cnt);
479void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
480
481int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
482void EVP_set_pw_prompt(char *prompt);
483char * EVP_get_pw_prompt(void);
484
485int EVP_BytesToKey(const EVP_CIPHER *type,EVP_MD *md,unsigned char *salt,
486 unsigned char *data, int datal, int count,
487 unsigned char *key,unsigned char *iv);
488
489void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
490 unsigned char *key, unsigned char *iv);
491void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
492 int *outl, unsigned char *in, int inl);
493void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
494
495void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
496 unsigned char *key, unsigned char *iv);
497void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
498 int *outl, unsigned char *in, int inl);
499int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
500
501void EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
502 unsigned char *key,unsigned char *iv,int enc);
503void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
504 int *outl, unsigned char *in, int inl);
505int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
506
507int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
508 EVP_PKEY *pkey);
509
510int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
511 unsigned int siglen,EVP_PKEY *pkey);
512
513int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
514 int ekl,unsigned char *iv,EVP_PKEY *priv);
515int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
516
517int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
518 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
519void EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
520
521void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
522void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
523 int *outl,unsigned char *in,int inl);
524void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
525int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
526
527void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
528int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
529 unsigned char *in, int inl);
530int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
531 char *out, int *outl);
532int EVP_DecodeBlock(unsigned char *t, const unsigned 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 OpenSSL_add_all_algorithms(void);
598void OpenSSL_add_all_ciphers(void);
599void OpenSSL_add_all_digests(void);
600#define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms()
601#define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers()
602#define SSLeay_add_all_digests() OpenSSL_add_all_digests()
603
604int EVP_add_cipher(EVP_CIPHER *cipher);
605int EVP_add_digest(EVP_MD *digest);
606
607const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
608const EVP_MD *EVP_get_digestbyname(const char *name);
609void EVP_cleanup(void);
610
611int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
612 int enc_key_len,EVP_PKEY *private_key);
613int EVP_PKEY_encrypt(unsigned char *enc_key,
614 unsigned char *key,int key_len,EVP_PKEY *pub_key);
615int EVP_PKEY_type(int type);
616int EVP_PKEY_bits(EVP_PKEY *pkey);
617int EVP_PKEY_size(EVP_PKEY *pkey);
618int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
619#ifndef NO_RSA
620int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key);
621RSA * EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
622#endif
623#ifndef NO_DSA
624int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key);
625DSA * EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
626#endif
627#ifndef NO_DH
628int EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key);
629DH * EVP_PKEY_get1_DH(EVP_PKEY *pkey);
630#endif
631EVP_PKEY * EVP_PKEY_new(void);
632void EVP_PKEY_free(EVP_PKEY *pkey);
633EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
634 long length);
635int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
636
637EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
638 long length);
639EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
640 long length);
641int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
642
643int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
644int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
645int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
646int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
647
648int EVP_CIPHER_type(const EVP_CIPHER *ctx);
649
650/* calls methods */
651int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
652int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
653
654/* These are used by EVP_CIPHER methods */
655int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
656int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
657
658/* PKCS5 password based encryption */
659int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
660 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
661 int en_de);
662int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
663 unsigned char *salt, int saltlen, int iter,
664 int keylen, unsigned char *out);
665int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
666 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
667 int en_de);
668
669void PKCS5_PBE_add(void);
670
671int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
672 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
673int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md,
674 EVP_PBE_KEYGEN *keygen);
675void EVP_PBE_cleanup(void);
676
677/* BEGIN ERROR CODES */
678/* The following lines are auto generated by the script mkerr.pl. Any changes
679 * made after this point may be overwritten when the script is next run.
680 */
681
682/* Error codes for the EVP functions. */
683
684/* Function codes. */
685#define EVP_F_D2I_PKEY 100
686#define EVP_F_EVP_DECRYPTFINAL 101
687#define EVP_F_EVP_MD_CTX_COPY 110
688#define EVP_F_EVP_OPENINIT 102
689#define EVP_F_EVP_PBE_ALG_ADD 115
690#define EVP_F_EVP_PBE_CIPHERINIT 116
691#define EVP_F_EVP_PKCS82PKEY 111
692#define EVP_F_EVP_PKCS8_SET_BROKEN 112
693#define EVP_F_EVP_PKEY2PKCS8 113
694#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
695#define EVP_F_EVP_PKEY_DECRYPT 104
696#define EVP_F_EVP_PKEY_ENCRYPT 105
697#define EVP_F_EVP_PKEY_GET1_DH 119
698#define EVP_F_EVP_PKEY_GET1_DSA 120
699#define EVP_F_EVP_PKEY_GET1_RSA 121
700#define EVP_F_EVP_PKEY_NEW 106
701#define EVP_F_EVP_SIGNFINAL 107
702#define EVP_F_EVP_VERIFYFINAL 108
703#define EVP_F_PKCS5_PBE_KEYIVGEN 117
704#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
705#define EVP_F_RC2_MAGIC_TO_METH 109
706
707/* Reason codes. */
708#define EVP_R_BAD_DECRYPT 100
709#define EVP_R_BN_DECODE_ERROR 112
710#define EVP_R_BN_PUBKEY_ERROR 113
711#define EVP_R_CIPHER_PARAMETER_ERROR 122
712#define EVP_R_DECODE_ERROR 114
713#define EVP_R_DIFFERENT_KEY_TYPES 101
714#define EVP_R_ENCODE_ERROR 115
715#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
716#define EVP_R_EXPECTING_AN_RSA_KEY 127
717#define EVP_R_EXPECTING_A_DH_KEY 128
718#define EVP_R_EXPECTING_A_DSA_KEY 129
719#define EVP_R_INPUT_NOT_INITIALIZED 111
720#define EVP_R_IV_TOO_LARGE 102
721#define EVP_R_KEYGEN_FAILURE 120
722#define EVP_R_MISSING_PARAMETERS 103
723#define EVP_R_NO_DSA_PARAMETERS 116
724#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
725#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
726#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
727#define EVP_R_PUBLIC_KEY_NOT_RSA 106
728#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
729#define EVP_R_UNSUPPORTED_CIPHER 107
730#define EVP_R_UNSUPPORTED_KEYLENGTH 123
731#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124
732#define EVP_R_UNSUPPORTED_KEY_SIZE 108
733#define EVP_R_UNSUPPORTED_PRF 125
734#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118
735#define EVP_R_UNSUPPORTED_SALT_TYPE 126
736#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
737#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
738
739#ifdef __cplusplus
740}
741#endif
742#endif
743
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 fc149cbb1a..0000000000
--- a/src/lib/libcrypto/evp/evp_err.c
+++ /dev/null
@@ -1,143 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/evp.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA EVP_str_functs[]=
68 {
69{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
70{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
71{ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"},
72{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
73{ERR_PACK(0,EVP_F_EVP_PBE_ALG_ADD,0), "EVP_PBE_alg_add"},
74{ERR_PACK(0,EVP_F_EVP_PBE_CIPHERINIT,0), "EVP_PBE_CipherInit"},
75{ERR_PACK(0,EVP_F_EVP_PKCS82PKEY,0), "EVP_PKCS82PKEY"},
76{ERR_PACK(0,EVP_F_EVP_PKCS8_SET_BROKEN,0), "EVP_PKCS8_SET_BROKEN"},
77{ERR_PACK(0,EVP_F_EVP_PKEY2PKCS8,0), "EVP_PKEY2PKCS8"},
78{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
79{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
80{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
81{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DH,0), "EVP_PKEY_get1_DH"},
82{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DSA,0), "EVP_PKEY_get1_DSA"},
83{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_RSA,0), "EVP_PKEY_get1_RSA"},
84{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
85{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
86{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
87{ERR_PACK(0,EVP_F_PKCS5_PBE_KEYIVGEN,0), "PKCS5_PBE_keyivgen"},
88{ERR_PACK(0,EVP_F_PKCS5_V2_PBE_KEYIVGEN,0), "PKCS5_v2_PBE_keyivgen"},
89{ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"},
90{0,NULL}
91 };
92
93static ERR_STRING_DATA EVP_str_reasons[]=
94 {
95{EVP_R_BAD_DECRYPT ,"bad decrypt"},
96{EVP_R_BN_DECODE_ERROR ,"bn decode error"},
97{EVP_R_BN_PUBKEY_ERROR ,"bn pubkey error"},
98{EVP_R_CIPHER_PARAMETER_ERROR ,"cipher parameter error"},
99{EVP_R_DECODE_ERROR ,"decode error"},
100{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
101{EVP_R_ENCODE_ERROR ,"encode error"},
102{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"},
103{EVP_R_EXPECTING_AN_RSA_KEY ,"expecting an rsa key"},
104{EVP_R_EXPECTING_A_DH_KEY ,"expecting a dh key"},
105{EVP_R_EXPECTING_A_DSA_KEY ,"expecting a dsa key"},
106{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"},
107{EVP_R_IV_TOO_LARGE ,"iv too large"},
108{EVP_R_KEYGEN_FAILURE ,"keygen failure"},
109{EVP_R_MISSING_PARAMETERS ,"missing parameters"},
110{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"},
111{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
112{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
113{EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE ,"pkcs8 unknown broken type"},
114{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
115{EVP_R_UNKNOWN_PBE_ALGORITHM ,"unknown pbe algorithm"},
116{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
117{EVP_R_UNSUPPORTED_KEYLENGTH ,"unsupported keylength"},
118{EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION,"unsupported key derivation function"},
119{EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"},
120{EVP_R_UNSUPPORTED_PRF ,"unsupported prf"},
121{EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM ,"unsupported private key algorithm"},
122{EVP_R_UNSUPPORTED_SALT_TYPE ,"unsupported salt type"},
123{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
124{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
125{0,NULL}
126 };
127
128#endif
129
130void ERR_load_EVP_strings(void)
131 {
132 static int init=1;
133
134 if (init)
135 {
136 init=0;
137#ifndef NO_ERR
138 ERR_load_strings(ERR_LIB_EVP,EVP_str_functs);
139 ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons);
140#endif
141
142 }
143 }
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
deleted file mode 100644
index 667c21cca8..0000000000
--- a/src/lib/libcrypto/evp/evp_key.c
+++ /dev/null
@@ -1,159 +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/* For historical reasons, the standard function for reading passwords is
85 * in the DES library -- if someone ever wants to disable DES,
86 * this function will fail */
87int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
88 {
89#ifndef NO_DES
90 if ((prompt == NULL) && (prompt_string[0] != '\0'))
91 prompt=prompt_string;
92 return(des_read_pw_string(buf,len,prompt,verify));
93#else
94 return -1;
95#endif
96 }
97
98int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, unsigned char *salt,
99 unsigned char *data, int datal, int count, unsigned char *key,
100 unsigned char *iv)
101 {
102 EVP_MD_CTX c;
103 unsigned char md_buf[EVP_MAX_MD_SIZE];
104 int niv,nkey,addmd=0;
105 unsigned int mds=0,i;
106
107 nkey=type->key_len;
108 niv=type->iv_len;
109
110 if (data == NULL) return(nkey);
111
112 for (;;)
113 {
114 EVP_DigestInit(&c,md);
115 if (addmd++)
116 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
117 EVP_DigestUpdate(&c,data,datal);
118 if (salt != NULL)
119 EVP_DigestUpdate(&c,salt,8);
120 EVP_DigestFinal(&c,&(md_buf[0]),&mds);
121
122 for (i=1; i<(unsigned int)count; i++)
123 {
124 EVP_DigestInit(&c,md);
125 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
126 EVP_DigestFinal(&c,&(md_buf[0]),&mds);
127 }
128 i=0;
129 if (nkey)
130 {
131 for (;;)
132 {
133 if (nkey == 0) break;
134 if (i == mds) break;
135 if (key != NULL)
136 *(key++)=md_buf[i];
137 nkey--;
138 i++;
139 }
140 }
141 if (niv && (i != mds))
142 {
143 for (;;)
144 {
145 if (niv == 0) break;
146 if (i == mds) break;
147 if (iv != NULL)
148 *(iv++)=md_buf[i];
149 niv--;
150 i++;
151 }
152 }
153 if ((nkey == 0) && (niv == 0)) break;
154 }
155 memset(&c,0,sizeof(c));
156 memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE);
157 return(type->key_len);
158 }
159
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
deleted file mode 100644
index a431945ef5..0000000000
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ /dev/null
@@ -1,142 +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 ASN1_OBJECT *otmp;
119 nid = EVP_CIPHER_nid(ctx);
120
121 switch(nid) {
122
123 case NID_rc2_cbc:
124 case NID_rc2_64_cbc:
125 case NID_rc2_40_cbc:
126
127 return NID_rc2_cbc;
128
129 case NID_rc4:
130 case NID_rc4_40:
131
132 return NID_rc4;
133
134 default:
135 /* Check it has an OID and it is valid */
136 otmp = OBJ_nid2obj(nid);
137 if(!otmp || !otmp->data) nid = NID_undef;
138 ASN1_OBJECT_free(otmp);
139 return nid;
140 }
141}
142
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 4ab091fa56..0000000000
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ /dev/null
@@ -1,407 +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
65static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
66
67/* Extract a private key from a PKCS8 structure */
68
69EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
70{
71 EVP_PKEY *pkey = NULL;
72#ifndef NO_RSA
73 RSA *rsa = NULL;
74#endif
75#ifndef NO_DSA
76 DSA *dsa = NULL;
77 ASN1_INTEGER *privkey;
78 ASN1_TYPE *t1, *t2, *param = NULL;
79 STACK *ndsa = NULL;
80 BN_CTX *ctx = NULL;
81 int plen;
82#endif
83 X509_ALGOR *a;
84 unsigned char *p;
85 int pkeylen;
86 char obj_tmp[80];
87
88 if(p8->pkey->type == V_ASN1_OCTET_STRING) {
89 p8->broken = PKCS8_OK;
90 p = p8->pkey->value.octet_string->data;
91 pkeylen = p8->pkey->value.octet_string->length;
92 } else {
93 p8->broken = PKCS8_NO_OCTET;
94 p = p8->pkey->value.sequence->data;
95 pkeylen = p8->pkey->value.sequence->length;
96 }
97 if (!(pkey = EVP_PKEY_new())) {
98 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
99 return NULL;
100 }
101 a = p8->pkeyalg;
102 switch (OBJ_obj2nid(a->algorithm))
103 {
104#ifndef NO_RSA
105 case NID_rsaEncryption:
106 if (!(rsa = d2i_RSAPrivateKey (NULL, &p, pkeylen))) {
107 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
108 return NULL;
109 }
110 EVP_PKEY_assign_RSA (pkey, rsa);
111 break;
112#endif
113#ifndef NO_DSA
114 case NID_dsa:
115 /* PKCS#8 DSA is weird: you just get a private key integer
116 * and parameters in the AlgorithmIdentifier the pubkey must
117 * be recalculated.
118 */
119
120 /* Check for broken DSA PKCS#8, UGH! */
121 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
122 if(!(ndsa = ASN1_seq_unpack(p, pkeylen,
123 (char *(*)())d2i_ASN1_TYPE,
124 ASN1_TYPE_free))) {
125 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
126 goto dsaerr;
127 }
128 if(sk_num(ndsa) != 2 ) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 goto dsaerr;
131 }
132 /* Handle Two broken types:
133 * SEQUENCE {parameters, priv_key}
134 * SEQUENCE {pub_key, priv_key}
135 */
136
137 t1 = (ASN1_TYPE *)sk_value(ndsa, 0);
138 t2 = (ASN1_TYPE *)sk_value(ndsa, 1);
139 if(t1->type == V_ASN1_SEQUENCE) {
140 p8->broken = PKCS8_EMBEDDED_PARAM;
141 param = t1;
142 } else if(a->parameter->type == V_ASN1_SEQUENCE) {
143 p8->broken = PKCS8_NS_DB;
144 param = a->parameter;
145 } else {
146 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
147 goto dsaerr;
148 }
149
150 if(t2->type != V_ASN1_INTEGER) {
151 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
152 goto dsaerr;
153 }
154 privkey = t2->value.integer;
155 } else {
156 if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
157 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
158 goto dsaerr;
159 }
160 param = p8->pkeyalg->parameter;
161 }
162 if (!param || (param->type != V_ASN1_SEQUENCE)) {
163 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
164 goto dsaerr;
165 }
166 p = param->value.sequence->data;
167 plen = param->value.sequence->length;
168 if (!(dsa = d2i_DSAparams (NULL, &p, plen))) {
169 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
170 goto dsaerr;
171 }
172 /* We have parameters now set private key */
173 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
174 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
175 goto dsaerr;
176 }
177 /* Calculate public key (ouch!) */
178 if (!(dsa->pub_key = BN_new())) {
179 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
180 goto dsaerr;
181 }
182 if (!(ctx = BN_CTX_new())) {
183 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
184 goto dsaerr;
185 }
186
187 if (!BN_mod_exp(dsa->pub_key, dsa->g,
188 dsa->priv_key, dsa->p, ctx)) {
189
190 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
191 goto dsaerr;
192 }
193
194 EVP_PKEY_assign_DSA(pkey, dsa);
195 BN_CTX_free (ctx);
196 if(ndsa) sk_pop_free(ndsa, ASN1_TYPE_free);
197 else ASN1_INTEGER_free(privkey);
198 break;
199 dsaerr:
200 BN_CTX_free (ctx);
201 sk_pop_free(ndsa, ASN1_TYPE_free);
202 DSA_free(dsa);
203 EVP_PKEY_free(pkey);
204 return NULL;
205 break;
206#endif
207 default:
208 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
209 if (!a->algorithm) strcpy (obj_tmp, "NULL");
210 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
211 ERR_add_error_data(2, "TYPE=", obj_tmp);
212 EVP_PKEY_free (pkey);
213 return NULL;
214 }
215 return pkey;
216}
217
218PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
219{
220 return EVP_PKEY2PKCS8_broken(pkey, PKCS8_OK);
221}
222
223/* Turn a private key into a PKCS8 structure */
224
225PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
226{
227 PKCS8_PRIV_KEY_INFO *p8;
228
229 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
230 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
231 return NULL;
232 }
233 p8->broken = broken;
234 ASN1_INTEGER_set (p8->version, 0);
235 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
236 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
237 PKCS8_PRIV_KEY_INFO_free (p8);
238 return NULL;
239 }
240 p8->pkey->type = V_ASN1_OCTET_STRING;
241 switch (EVP_PKEY_type(pkey->type)) {
242#ifndef NO_RSA
243 case EVP_PKEY_RSA:
244
245 if(p8->broken == PKCS8_NO_OCTET) p8->pkey->type = V_ASN1_SEQUENCE;
246
247 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
248 p8->pkeyalg->parameter->type = V_ASN1_NULL;
249 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
250 &p8->pkey->value.octet_string)) {
251 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
252 PKCS8_PRIV_KEY_INFO_free (p8);
253 return NULL;
254 }
255 break;
256#endif
257#ifndef NO_DSA
258 case EVP_PKEY_DSA:
259 if(!dsa_pkey2pkcs8(p8, pkey)) {
260 PKCS8_PRIV_KEY_INFO_free (p8);
261 return NULL;
262 }
263
264 break;
265#endif
266 default:
267 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
268 PKCS8_PRIV_KEY_INFO_free (p8);
269 return NULL;
270 }
271 RAND_add(p8->pkey->value.octet_string->data,
272 p8->pkey->value.octet_string->length, 0);
273 return p8;
274}
275
276PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
277{
278 switch (broken) {
279
280 case PKCS8_OK:
281 p8->broken = PKCS8_OK;
282 return p8;
283 break;
284
285 case PKCS8_NO_OCTET:
286 p8->broken = PKCS8_NO_OCTET;
287 p8->pkey->type = V_ASN1_SEQUENCE;
288 return p8;
289 break;
290
291 default:
292 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
293 return NULL;
294 break;
295
296 }
297}
298
299#ifndef NO_DSA
300static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
301{
302 ASN1_STRING *params;
303 ASN1_INTEGER *prkey;
304 ASN1_TYPE *ttmp;
305 STACK *ndsa;
306 unsigned char *p, *q;
307 int len;
308 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
309 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
310 if (!(p = Malloc(len))) {
311 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
312 PKCS8_PRIV_KEY_INFO_free (p8);
313 return 0;
314 }
315 q = p;
316 i2d_DSAparams (pkey->pkey.dsa, &q);
317 params = ASN1_STRING_new();
318 ASN1_STRING_set(params, p, len);
319 Free(p);
320 /* Get private key into integer */
321 if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
322 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
323 return 0;
324 }
325
326 switch(p8->broken) {
327
328 case PKCS8_OK:
329 case PKCS8_NO_OCTET:
330
331 if (!ASN1_pack_string((char *)prkey, i2d_ASN1_INTEGER,
332 &p8->pkey->value.octet_string)) {
333 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
334 M_ASN1_INTEGER_free (prkey);
335 return 0;
336 }
337
338 M_ASN1_INTEGER_free (prkey);
339 p8->pkeyalg->parameter->value.sequence = params;
340 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
341
342 break;
343
344 case PKCS8_NS_DB:
345
346 p8->pkeyalg->parameter->value.sequence = params;
347 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
348 ndsa = sk_new_null();
349 ttmp = ASN1_TYPE_new();
350 if (!(ttmp->value.integer = BN_to_ASN1_INTEGER (pkey->pkey.dsa->pub_key, NULL))) {
351 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
352 PKCS8_PRIV_KEY_INFO_free(p8);
353 return 0;
354 }
355 ttmp->type = V_ASN1_INTEGER;
356 sk_push(ndsa, (char *)ttmp);
357
358 ttmp = ASN1_TYPE_new();
359 ttmp->value.integer = prkey;
360 ttmp->type = V_ASN1_INTEGER;
361 sk_push(ndsa, (char *)ttmp);
362
363 p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
364
365 if (!ASN1_seq_pack(ndsa, i2d_ASN1_TYPE,
366 &p8->pkey->value.octet_string->data,
367 &p8->pkey->value.octet_string->length)) {
368
369 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
370 sk_pop_free(ndsa, ASN1_TYPE_free);
371 M_ASN1_INTEGER_free(prkey);
372 return 0;
373 }
374 sk_pop_free(ndsa, ASN1_TYPE_free);
375 break;
376
377 case PKCS8_EMBEDDED_PARAM:
378
379 p8->pkeyalg->parameter->type = V_ASN1_NULL;
380 ndsa = sk_new_null();
381 ttmp = ASN1_TYPE_new();
382 ttmp->value.sequence = params;
383 ttmp->type = V_ASN1_SEQUENCE;
384 sk_push(ndsa, (char *)ttmp);
385
386 ttmp = ASN1_TYPE_new();
387 ttmp->value.integer = prkey;
388 ttmp->type = V_ASN1_INTEGER;
389 sk_push(ndsa, (char *)ttmp);
390
391 p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
392
393 if (!ASN1_seq_pack(ndsa, i2d_ASN1_TYPE,
394 &p8->pkey->value.octet_string->data,
395 &p8->pkey->value.octet_string->length)) {
396
397 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
398 sk_pop_free(ndsa, ASN1_TYPE_free);
399 M_ASN1_INTEGER_free (prkey);
400 return 0;
401 }
402 sk_pop_free(ndsa, ASN1_TYPE_free);
403 break;
404 }
405 return 1;
406}
407#endif
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 620f43feaa..0000000000
--- a/src/lib/libcrypto/evp/names.c
+++ /dev/null
@@ -1,123 +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 /* The above calls will only clean out the contents of the name
118 hash table, but not the hash table itself. The following line
119 does that part. -- Richard Levitte */
120 OBJ_NAME_cleanup(-1);
121
122 EVP_PBE_cleanup();
123 }
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 4cb387f8de..0000000000
--- a/src/lib/libcrypto/evp/p_lib.c
+++ /dev/null
@@ -1,333 +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_PARAMETERS);
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(key != NULL);
206 }
207
208#ifndef NO_RSA
209int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
210{
211 int ret = EVP_PKEY_assign_RSA(pkey, key);
212 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_RSA);
213 return ret;
214}
215
216RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
217 {
218 if(pkey->type != EVP_PKEY_RSA) {
219 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
220 return NULL;
221 }
222 CRYPTO_add(&pkey->pkey.rsa->references, 1, CRYPTO_LOCK_RSA);
223 return pkey->pkey.rsa;
224}
225#endif
226
227#ifndef NO_DSA
228int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
229{
230 int ret = EVP_PKEY_assign_DSA(pkey, key);
231 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_DSA);
232 return ret;
233}
234
235DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
236 {
237 if(pkey->type != EVP_PKEY_DSA) {
238 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
239 return NULL;
240 }
241 CRYPTO_add(&pkey->pkey.dsa->references, 1, CRYPTO_LOCK_DSA);
242 return pkey->pkey.dsa;
243}
244#endif
245
246#ifndef NO_DH
247
248int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
249{
250 int ret = EVP_PKEY_assign_DH(pkey, key);
251 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_DH);
252 return ret;
253}
254
255DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
256 {
257 if(pkey->type != EVP_PKEY_DH) {
258 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
259 return NULL;
260 }
261 CRYPTO_add(&pkey->pkey.dh->references, 1, CRYPTO_LOCK_DH);
262 return pkey->pkey.dh;
263}
264#endif
265
266int EVP_PKEY_type(int type)
267 {
268 switch (type)
269 {
270 case EVP_PKEY_RSA:
271 case EVP_PKEY_RSA2:
272 return(EVP_PKEY_RSA);
273 case EVP_PKEY_DSA:
274 case EVP_PKEY_DSA1:
275 case EVP_PKEY_DSA2:
276 case EVP_PKEY_DSA3:
277 case EVP_PKEY_DSA4:
278 return(EVP_PKEY_DSA);
279 case EVP_PKEY_DH:
280 return(EVP_PKEY_DH);
281 default:
282 return(NID_undef);
283 }
284 }
285
286void EVP_PKEY_free(EVP_PKEY *x)
287 {
288 int i;
289
290 if (x == NULL) return;
291
292 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
293#ifdef REF_PRINT
294 REF_PRINT("EVP_PKEY",x);
295#endif
296 if (i > 0) return;
297#ifdef REF_CHECK
298 if (i < 0)
299 {
300 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
301 abort();
302 }
303#endif
304 EVP_PKEY_free_it(x);
305 Free(x);
306 }
307
308static void EVP_PKEY_free_it(EVP_PKEY *x)
309 {
310 switch (x->type)
311 {
312#ifndef NO_RSA
313 case EVP_PKEY_RSA:
314 case EVP_PKEY_RSA2:
315 RSA_free(x->pkey.rsa);
316 break;
317#endif
318#ifndef NO_DSA
319 case EVP_PKEY_DSA:
320 case EVP_PKEY_DSA2:
321 case EVP_PKEY_DSA3:
322 case EVP_PKEY_DSA4:
323 DSA_free(x->pkey.dsa);
324 break;
325#endif
326#ifndef NO_DH
327 case EVP_PKEY_DH:
328 DH_free(x->pkey.dh);
329 break;
330#endif
331 }
332 }
333
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
deleted file mode 100644
index b9ca7892c2..0000000000
--- a/src/lib/libcrypto/evp/p_open.c
+++ /dev/null
@@ -1,119 +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#else /* !NO_RSA */
114
115# ifdef PEDANTIC
116static void *dummy=&dummy;
117# endif
118
119#endif
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c
deleted file mode 100644
index d449e892bf..0000000000
--- a/src/lib/libcrypto/evp/p_seal.c
+++ /dev/null
@@ -1,109 +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 if (RAND_bytes(key,EVP_MAX_KEY_LENGTH) <= 0)
77 return(0);
78 if (type->iv_len > 0)
79 RAND_pseudo_bytes(iv,type->iv_len);
80
81 EVP_CIPHER_CTX_init(ctx);
82 EVP_EncryptInit(ctx,type,key,iv);
83
84 for (i=0; i<npubk; i++)
85 {
86 ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_key_length(type),
87 pubk[i]);
88 if (ekl[i] <= 0) return(-1);
89 }
90 return(npubk);
91 }
92
93/* MACRO
94void EVP_SealUpdate(ctx,out,outl,in,inl)
95EVP_CIPHER_CTX *ctx;
96unsigned char *out;
97int *outl;
98unsigned char *in;
99int inl;
100 {
101 EVP_EncryptUpdate(ctx,out,outl,in,inl);
102 }
103*/
104
105void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
106 {
107 EVP_EncryptFinal(ctx,out,outl);
108 EVP_EncryptInit(ctx,NULL,NULL,NULL);
109 }
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 a057dd3b68..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_OF(CRYPTO_EX_DATA_FUNCS) **skp, long argl, void *argp,
67 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
68 {
69 int ret= -1;
70 CRYPTO_EX_DATA_FUNCS *a;
71
72 MemCheck_off();
73 if (*skp == NULL)
74 *skp=sk_CRYPTO_EX_DATA_FUNCS_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_CRYPTO_EX_DATA_FUNCS_num(*skp) <= idx)
92 {
93 if (!sk_CRYPTO_EX_DATA_FUNCS_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_CRYPTO_EX_DATA_FUNCS_set(*skp,idx, a);
101 ret=idx;
102err:
103 MemCheck_on();
104 return(idx);
105 }
106
107int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *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
134void *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_OF(CRYPTO_EX_DATA_FUNCS) *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_CRYPTO_EX_DATA_FUNCS_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=sk_CRYPTO_EX_DATA_FUNCS_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_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad)
176 {
177 CRYPTO_EX_DATA_FUNCS *m;
178 void *ptr;
179 int i,max;
180
181 if (meth != NULL)
182 {
183 max=sk_CRYPTO_EX_DATA_FUNCS_num(meth);
184 for (i=0; i<max; i++)
185 {
186 m=sk_CRYPTO_EX_DATA_FUNCS_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_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad)
202 {
203 CRYPTO_EX_DATA_FUNCS *m;
204 void *ptr;
205 int i,max;
206
207 ad->sk=NULL;
208 if (meth != NULL)
209 {
210 max=sk_CRYPTO_EX_DATA_FUNCS_num(meth);
211 for (i=0; i<max; i++)
212 {
213 m=sk_CRYPTO_EX_DATA_FUNCS_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
223IMPLEMENT_STACK_OF(CRYPTO_EX_DATA_FUNCS)
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c
deleted file mode 100644
index e1ec79e093..0000000000
--- a/src/lib/libcrypto/hmac/hmac.c
+++ /dev/null
@@ -1,152 +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 ctx->key_length=len;
92 }
93 if(ctx->key_length != HMAC_MAX_MD_CBLOCK)
94 memset(&ctx->key[ctx->key_length], 0,
95 HMAC_MAX_MD_CBLOCK - ctx->key_length);
96 }
97
98 if (reset)
99 {
100 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
101 pad[i]=0x36^ctx->key[i];
102 EVP_DigestInit(&ctx->i_ctx,md);
103 EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md));
104
105 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
106 pad[i]=0x5c^ctx->key[i];
107 EVP_DigestInit(&ctx->o_ctx,md);
108 EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md));
109 }
110
111 memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx));
112 }
113
114void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len)
115 {
116 EVP_DigestUpdate(&(ctx->md_ctx),data,len);
117 }
118
119void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
120 {
121 int j;
122 unsigned int i;
123 unsigned char buf[EVP_MAX_MD_SIZE];
124
125 j=EVP_MD_block_size(ctx->md);
126
127 EVP_DigestFinal(&(ctx->md_ctx),buf,&i);
128 memcpy(&(ctx->md_ctx),&(ctx->o_ctx),sizeof(ctx->o_ctx));
129 EVP_DigestUpdate(&(ctx->md_ctx),buf,i);
130 EVP_DigestFinal(&(ctx->md_ctx),md,len);
131 }
132
133void HMAC_cleanup(HMAC_CTX *ctx)
134 {
135 memset(ctx,0,sizeof(HMAC_CTX));
136 }
137
138unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
139 const unsigned char *d, int n, unsigned char *md,
140 unsigned int *md_len)
141 {
142 HMAC_CTX c;
143 static unsigned char m[EVP_MAX_MD_SIZE];
144
145 if (md == NULL) md=m;
146 HMAC_Init(&c,key,key_len,evp_md);
147 HMAC_Update(&c,d,n);
148 HMAC_Final(&c,md,md_len);
149 HMAC_cleanup(&c);
150 return(md);
151 }
152
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
deleted file mode 100644
index 223eeda7f3..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, const unsigned char *data, 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 const 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 7eb92a18bc..0000000000
--- a/src/lib/libcrypto/lhash/lhash.c
+++ /dev/null
@@ -1,461 +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 occurred 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 * skipping 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
110static void expand(LHASH *lh);
111static void contract(LHASH *lh);
112static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash);
113
114LHASH *lh_new(unsigned long (*h)(), int (*c)())
115 {
116 LHASH *ret;
117 int i;
118
119 if ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)
120 goto err0;
121 if ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
122 goto err1;
123 for (i=0; i<MIN_NODES; i++)
124 ret->b[i]=NULL;
125 ret->comp=((c == NULL)?(int (*)())strcmp:c);
126 ret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h);
127 ret->num_nodes=MIN_NODES/2;
128 ret->num_alloc_nodes=MIN_NODES;
129 ret->p=0;
130 ret->pmax=MIN_NODES/2;
131 ret->up_load=UP_LOAD;
132 ret->down_load=DOWN_LOAD;
133 ret->num_items=0;
134
135 ret->num_expands=0;
136 ret->num_expand_reallocs=0;
137 ret->num_contracts=0;
138 ret->num_contract_reallocs=0;
139 ret->num_hash_calls=0;
140 ret->num_comp_calls=0;
141 ret->num_insert=0;
142 ret->num_replace=0;
143 ret->num_delete=0;
144 ret->num_no_delete=0;
145 ret->num_retrieve=0;
146 ret->num_retrieve_miss=0;
147 ret->num_hash_comps=0;
148
149 ret->error=0;
150 return(ret);
151err1:
152 Free(ret);
153err0:
154 return(NULL);
155 }
156
157void lh_free(LHASH *lh)
158 {
159 unsigned int i;
160 LHASH_NODE *n,*nn;
161
162 if (lh == NULL)
163 return;
164
165 for (i=0; i<lh->num_nodes; i++)
166 {
167 n=lh->b[i];
168 while (n != NULL)
169 {
170 nn=n->next;
171 Free(n);
172 n=nn;
173 }
174 }
175 Free(lh->b);
176 Free(lh);
177 }
178
179void *lh_insert(LHASH *lh, void *data)
180 {
181 unsigned long hash;
182 LHASH_NODE *nn,**rn;
183 void *ret;
184
185 lh->error=0;
186 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
187 expand(lh);
188
189 rn=getrn(lh,data,&hash);
190
191 if (*rn == NULL)
192 {
193 if ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)
194 {
195 lh->error++;
196 return(NULL);
197 }
198 nn->data=data;
199 nn->next=NULL;
200#ifndef NO_HASH_COMP
201 nn->hash=hash;
202#endif
203 *rn=nn;
204 ret=NULL;
205 lh->num_insert++;
206 lh->num_items++;
207 }
208 else /* replace same key */
209 {
210 ret= (*rn)->data;
211 (*rn)->data=data;
212 lh->num_replace++;
213 }
214 return(ret);
215 }
216
217void *lh_delete(LHASH *lh, void *data)
218 {
219 unsigned long hash;
220 LHASH_NODE *nn,**rn;
221 void *ret;
222
223 lh->error=0;
224 rn=getrn(lh,data,&hash);
225
226 if (*rn == NULL)
227 {
228 lh->num_no_delete++;
229 return(NULL);
230 }
231 else
232 {
233 nn= *rn;
234 *rn=nn->next;
235 ret=nn->data;
236 Free(nn);
237 lh->num_delete++;
238 }
239
240 lh->num_items--;
241 if ((lh->num_nodes > MIN_NODES) &&
242 (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
243 contract(lh);
244
245 return(ret);
246 }
247
248void *lh_retrieve(LHASH *lh, void *data)
249 {
250 unsigned long hash;
251 LHASH_NODE **rn;
252 void *ret;
253
254 lh->error=0;
255 rn=getrn(lh,data,&hash);
256
257 if (*rn == NULL)
258 {
259 lh->num_retrieve_miss++;
260 return(NULL);
261 }
262 else
263 {
264 ret= (*rn)->data;
265 lh->num_retrieve++;
266 }
267 return(ret);
268 }
269
270void lh_doall(LHASH *lh, void (*func)())
271 {
272 lh_doall_arg(lh,func,NULL);
273 }
274
275void lh_doall_arg(LHASH *lh, void (*func)(), void *arg)
276 {
277 int i;
278 LHASH_NODE *a,*n;
279
280 /* reverse the order so we search from 'top to bottom'
281 * We were having memory leaks otherwise */
282 for (i=lh->num_nodes-1; i>=0; i--)
283 {
284 a=lh->b[i];
285 while (a != NULL)
286 {
287 /* 28/05/91 - eay - n added so items can be deleted
288 * via lh_doall */
289 n=a->next;
290 func(a->data,arg);
291 a=n;
292 }
293 }
294 }
295
296static void expand(LHASH *lh)
297 {
298 LHASH_NODE **n,**n1,**n2,*np;
299 unsigned int p,i,j;
300 unsigned long hash,nni;
301
302 lh->num_nodes++;
303 lh->num_expands++;
304 p=(int)lh->p++;
305 n1= &(lh->b[p]);
306 n2= &(lh->b[p+(int)lh->pmax]);
307 *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
308 nni=lh->num_alloc_nodes;
309
310 for (np= *n1; np != NULL; )
311 {
312#ifndef NO_HASH_COMP
313 hash=np->hash;
314#else
315 hash=(*(lh->hash))(np->data);
316 lh->num_hash_calls++;
317#endif
318 if ((hash%nni) != p)
319 { /* move it */
320 *n1= (*n1)->next;
321 np->next= *n2;
322 *n2=np;
323 }
324 else
325 n1= &((*n1)->next);
326 np= *n1;
327 }
328
329 if ((lh->p) >= lh->pmax)
330 {
331 j=(int)lh->num_alloc_nodes*2;
332 n=(LHASH_NODE **)Realloc(lh->b,
333 (unsigned int)sizeof(LHASH_NODE *)*j);
334 if (n == NULL)
335 {
336/* fputs("realloc error in lhash",stderr); */
337 lh->error++;
338 lh->p=0;
339 return;
340 }
341 /* else */
342 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
343 n[i]=NULL; /* 02/03/92 eay */
344 lh->pmax=lh->num_alloc_nodes;
345 lh->num_alloc_nodes=j;
346 lh->num_expand_reallocs++;
347 lh->p=0;
348 lh->b=n;
349 }
350 }
351
352static void contract(LHASH *lh)
353 {
354 LHASH_NODE **n,*n1,*np;
355
356 np=lh->b[lh->p+lh->pmax-1];
357 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
358 if (lh->p == 0)
359 {
360 n=(LHASH_NODE **)Realloc(lh->b,
361 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
362 if (n == NULL)
363 {
364/* fputs("realloc error in lhash",stderr); */
365 lh->error++;
366 return;
367 }
368 lh->num_contract_reallocs++;
369 lh->num_alloc_nodes/=2;
370 lh->pmax/=2;
371 lh->p=lh->pmax-1;
372 lh->b=n;
373 }
374 else
375 lh->p--;
376
377 lh->num_nodes--;
378 lh->num_contracts++;
379
380 n1=lh->b[(int)lh->p];
381 if (n1 == NULL)
382 lh->b[(int)lh->p]=np;
383 else
384 {
385 while (n1->next != NULL)
386 n1=n1->next;
387 n1->next=np;
388 }
389 }
390
391static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash)
392 {
393 LHASH_NODE **ret,*n1;
394 unsigned long hash,nn;
395 int (*cf)();
396
397 hash=(*(lh->hash))(data);
398 lh->num_hash_calls++;
399 *rhash=hash;
400
401 nn=hash%lh->pmax;
402 if (nn < lh->p)
403 nn=hash%lh->num_alloc_nodes;
404
405 cf=lh->comp;
406 ret= &(lh->b[(int)nn]);
407 for (n1= *ret; n1 != NULL; n1=n1->next)
408 {
409#ifndef NO_HASH_COMP
410 lh->num_hash_comps++;
411 if (n1->hash != hash)
412 {
413 ret= &(n1->next);
414 continue;
415 }
416#endif
417 lh->num_comp_calls++;
418 if ((*cf)(n1->data,data) == 0)
419 break;
420 ret= &(n1->next);
421 }
422 return(ret);
423 }
424
425/* The following hash seems to work very well on normal text strings
426 * no collisions on /usr/dict/words and it distributes on %2^n quite
427 * well, not as good as MD5, but still good.
428 */
429unsigned long lh_strhash(const char *c)
430 {
431 unsigned long ret=0;
432 long n;
433 unsigned long v;
434 int r;
435
436 if ((c == NULL) || (*c == '\0'))
437 return(ret);
438/*
439 unsigned char b[16];
440 MD5(c,strlen(c),b);
441 return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24));
442*/
443
444 n=0x100;
445 while (*c)
446 {
447 v=n|(*c);
448 n+=0x100;
449 r= (int)((v>>2)^v)&0x0f;
450 ret=(ret<<r)|(ret>>(32-r));
451 ret&=0xFFFFFFFFL;
452 ret^=v*v;
453 c++;
454 }
455 return((ret>>16)^ret);
456 }
457
458unsigned long lh_num_items(LHASH *lh)
459 {
460 return lh ? lh->num_items : 0;
461 }
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h
deleted file mode 100644
index d315fd9c6d..0000000000
--- a/src/lib/libcrypto/lhash/lhash.h
+++ /dev/null
@@ -1,145 +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 void *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)(/* void *a */), int (*c)(/* void *a,void *b */));
120void lh_free(LHASH *lh);
121void *lh_insert(LHASH *lh, void *data);
122void *lh_delete(LHASH *lh, void *data);
123void *lh_retrieve(LHASH *lh, void *data);
124 void lh_doall(LHASH *lh, void (*func)(/*void *b*/));
125void lh_doall_arg(LHASH *lh, void (*func)(/*void *a,void *b*/),void *arg);
126unsigned long lh_strhash(const char *c);
127unsigned long lh_num_items(LHASH *lh);
128
129#ifndef NO_FP_API
130void lh_stats(LHASH *lh, FILE *out);
131void lh_node_stats(LHASH *lh, FILE *out);
132void lh_node_usage_stats(LHASH *lh, FILE *out);
133#endif
134
135#ifdef HEADER_BIO_H
136void lh_stats_bio(LHASH *lh, BIO *out);
137void lh_node_stats_bio(LHASH *lh, BIO *out);
138void lh_node_usage_stats_bio(LHASH *lh, BIO *out);
139#endif
140#ifdef __cplusplus
141}
142#endif
143
144#endif
145
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h
deleted file mode 100644
index 1a404a458d..0000000000
--- a/src/lib/libcrypto/md32_common.h
+++ /dev/null
@@ -1,607 +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 * HASH_MAKE_STRING
98 * macro convering context variables to an ASCII hash string.
99 *
100 * Optional macros:
101 *
102 * B_ENDIAN or L_ENDIAN
103 * defines host byte-order.
104 * HASH_LONG_LOG2
105 * defaults to 2 if not states otherwise.
106 * HASH_LBLOCK
107 * assumed to be HASH_CBLOCK/4 if not stated otherwise.
108 * HASH_BLOCK_DATA_ORDER_ALIGNED
109 * alternative "block" function capable of treating
110 * aligned input message in original (data) order,
111 * implemented externally.
112 *
113 * MD5 example:
114 *
115 * #define DATA_ORDER_IS_LITTLE_ENDIAN
116 *
117 * #define HASH_LONG MD5_LONG
118 * #define HASH_LONG_LOG2 MD5_LONG_LOG2
119 * #define HASH_CTX MD5_CTX
120 * #define HASH_CBLOCK MD5_CBLOCK
121 * #define HASH_LBLOCK MD5_LBLOCK
122 * #define HASH_UPDATE MD5_Update
123 * #define HASH_TRANSFORM MD5_Transform
124 * #define HASH_FINAL MD5_Final
125 * #define HASH_BLOCK_HOST_ORDER md5_block_host_order
126 * #define HASH_BLOCK_DATA_ORDER md5_block_data_order
127 *
128 * <appro@fy.chalmers.se>
129 */
130
131#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
132#error "DATA_ORDER must be defined!"
133#endif
134
135#ifndef HASH_CBLOCK
136#error "HASH_CBLOCK must be defined!"
137#endif
138#ifndef HASH_LONG
139#error "HASH_LONG must be defined!"
140#endif
141#ifndef HASH_CTX
142#error "HASH_CTX must be defined!"
143#endif
144
145#ifndef HASH_UPDATE
146#error "HASH_UPDATE must be defined!"
147#endif
148#ifndef HASH_TRANSFORM
149#error "HASH_TRANSFORM must be defined!"
150#endif
151#ifndef HASH_FINAL
152#error "HASH_FINAL must be defined!"
153#endif
154
155#ifndef HASH_BLOCK_HOST_ORDER
156#error "HASH_BLOCK_HOST_ORDER must be defined!"
157#endif
158
159#if 0
160/*
161 * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
162 * isn't defined.
163 */
164#ifndef HASH_BLOCK_DATA_ORDER
165#error "HASH_BLOCK_DATA_ORDER must be defined!"
166#endif
167#endif
168
169#ifndef HASH_LBLOCK
170#define HASH_LBLOCK (HASH_CBLOCK/4)
171#endif
172
173#ifndef HASH_LONG_LOG2
174#define HASH_LONG_LOG2 2
175#endif
176
177/*
178 * Engage compiler specific rotate intrinsic function if available.
179 */
180#undef ROTATE
181#ifndef PEDANTIC
182# if defined(_MSC_VER)
183# define ROTATE(a,n) _lrotl(a,n)
184# elif defined(__MWERKS__)
185# if defined(__POWERPC__)
186# define ROTATE(a,n) __rlwinm(a,n,0,31)
187# elif defined(__MC68K__)
188 /* Motorola specific tweak. <appro@fy.chalmers.se> */
189# define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) )
190# else
191# define ROTATE(a,n) __rol(a,n)
192# endif
193# elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) && !defined(NO_INLINE_ASM)
194 /*
195 * Some GNU C inline assembler templates. Note that these are
196 * rotates by *constant* number of bits! But that's exactly
197 * what we need here...
198 *
199 * <appro@fy.chalmers.se>
200 */
201# if defined(__i386)
202# define ROTATE(a,n) ({ register unsigned int ret; \
203 asm ( \
204 "roll %1,%0" \
205 : "=r"(ret) \
206 : "I"(n), "0"(a) \
207 : "cc"); \
208 ret; \
209 })
210# elif defined(__powerpc) || defined(__ppc)
211# define ROTATE(a,n) ({ register unsigned int ret; \
212 asm ( \
213 "rlwinm %0,%1,%2,0,31" \
214 : "=r"(ret) \
215 : "r"(a), "I"(n)); \
216 ret; \
217 })
218# endif
219# endif
220
221/*
222 * Engage compiler specific "fetch in reverse byte order"
223 * intrinsic function if available.
224 */
225# if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) && !defined(NO_INLINE_ASM)
226 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
227# if defined(__i386) && !defined(I386_ONLY)
228# define BE_FETCH32(a) ({ register unsigned int l=(a);\
229 asm ( \
230 "bswapl %0" \
231 : "=r"(l) : "0"(l)); \
232 l; \
233 })
234# elif defined(__powerpc)
235# define LE_FETCH32(a) ({ register unsigned int l; \
236 asm ( \
237 "lwbrx %0,0,%1" \
238 : "=r"(l) \
239 : "r"(a)); \
240 l; \
241 })
242
243# elif defined(__sparc) && defined(ULTRASPARC)
244# define LE_FETCH32(a) ({ register unsigned int l; \
245 asm ( \
246 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
247 : "=r"(l) \
248 : "r"(a)); \
249 l; \
250 })
251# endif
252# endif
253#endif /* PEDANTIC */
254
255#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */
256/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
257#ifdef ROTATE
258/* 5 instructions with rotate instruction, else 9 */
259#define REVERSE_FETCH32(a,l) ( \
260 l=*(const HASH_LONG *)(a), \
261 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
262 )
263#else
264/* 6 instructions with rotate instruction, else 8 */
265#define REVERSE_FETCH32(a,l) ( \
266 l=*(const HASH_LONG *)(a), \
267 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
268 ROTATE(l,16) \
269 )
270/*
271 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
272 * It's rewritten as above for two reasons:
273 * - RISCs aren't good at long constants and have to explicitely
274 * compose 'em with several (well, usually 2) instructions in a
275 * register before performing the actual operation and (as you
276 * already realized:-) having same constant should inspire the
277 * compiler to permanently allocate the only register for it;
278 * - most modern CPUs have two ALUs, but usually only one has
279 * circuitry for shifts:-( this minor tweak inspires compiler
280 * to schedule shift instructions in a better way...
281 *
282 * <appro@fy.chalmers.se>
283 */
284#endif
285#endif
286
287#ifndef ROTATE
288#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
289#endif
290
291/*
292 * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
293 * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
294 * and host are of the same "endianess". It's possible to mask
295 * this with blank #define HASH_BLOCK_DATA_ORDER though...
296 *
297 * <appro@fy.chalmers.se>
298 */
299#if defined(B_ENDIAN)
300# if defined(DATA_ORDER_IS_BIG_ENDIAN)
301# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
302# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
303# endif
304# elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
305# ifndef HOST_FETCH32
306# ifdef LE_FETCH32
307# define HOST_FETCH32(p,l) LE_FETCH32(p)
308# elif defined(REVERSE_FETCH32)
309# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
310# endif
311# endif
312# endif
313#elif defined(L_ENDIAN)
314# if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
315# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
316# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
317# endif
318# elif defined(DATA_ORDER_IS_BIG_ENDIAN)
319# ifndef HOST_FETCH32
320# ifdef BE_FETCH32
321# define HOST_FETCH32(p,l) BE_FETCH32(p)
322# elif defined(REVERSE_FETCH32)
323# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
324# endif
325# endif
326# endif
327#endif
328
329#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
330#ifndef HASH_BLOCK_DATA_ORDER
331#error "HASH_BLOCK_DATA_ORDER must be defined!"
332#endif
333#endif
334
335#if defined(DATA_ORDER_IS_BIG_ENDIAN)
336
337#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
338 l|=(((unsigned long)(*((c)++)))<<16), \
339 l|=(((unsigned long)(*((c)++)))<< 8), \
340 l|=(((unsigned long)(*((c)++))) ), \
341 l)
342#define HOST_p_c2l(c,l,n) { \
343 switch (n) { \
344 case 0: l =((unsigned long)(*((c)++)))<<24; \
345 case 1: l|=((unsigned long)(*((c)++)))<<16; \
346 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
347 case 3: l|=((unsigned long)(*((c)++))); \
348 } }
349#define HOST_p_c2l_p(c,l,sc,len) { \
350 switch (sc) { \
351 case 0: l =((unsigned long)(*((c)++)))<<24; \
352 if (--len == 0) break; \
353 case 1: l|=((unsigned long)(*((c)++)))<<16; \
354 if (--len == 0) break; \
355 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
356 } }
357/* NOTE the pointer is not incremented at the end of this */
358#define HOST_c2l_p(c,l,n) { \
359 l=0; (c)+=n; \
360 switch (n) { \
361 case 3: l =((unsigned long)(*(--(c))))<< 8; \
362 case 2: l|=((unsigned long)(*(--(c))))<<16; \
363 case 1: l|=((unsigned long)(*(--(c))))<<24; \
364 } }
365#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
366 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
367 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
368 *((c)++)=(unsigned char)(((l) )&0xff), \
369 l)
370
371#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
372
373#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
374 l|=(((unsigned long)(*((c)++)))<< 8), \
375 l|=(((unsigned long)(*((c)++)))<<16), \
376 l|=(((unsigned long)(*((c)++)))<<24), \
377 l)
378#define HOST_p_c2l(c,l,n) { \
379 switch (n) { \
380 case 0: l =((unsigned long)(*((c)++))); \
381 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
382 case 2: l|=((unsigned long)(*((c)++)))<<16; \
383 case 3: l|=((unsigned long)(*((c)++)))<<24; \
384 } }
385#define HOST_p_c2l_p(c,l,sc,len) { \
386 switch (sc) { \
387 case 0: l =((unsigned long)(*((c)++))); \
388 if (--len == 0) break; \
389 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
390 if (--len == 0) break; \
391 case 2: l|=((unsigned long)(*((c)++)))<<16; \
392 } }
393/* NOTE the pointer is not incremented at the end of this */
394#define HOST_c2l_p(c,l,n) { \
395 l=0; (c)+=n; \
396 switch (n) { \
397 case 3: l =((unsigned long)(*(--(c))))<<16; \
398 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
399 case 1: l|=((unsigned long)(*(--(c)))); \
400 } }
401#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
402 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
403 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
404 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
405 l)
406
407#endif
408
409/*
410 * Time for some action:-)
411 */
412
413void HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
414 {
415 const unsigned char *data=data_;
416 register HASH_LONG * p;
417 register unsigned long l;
418 int sw,sc,ew,ec;
419
420 if (len==0) return;
421
422 l=(c->Nl+(len<<3))&0xffffffffL;
423 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
424 * Wei Dai <weidai@eskimo.com> for pointing it out. */
425 if (l < c->Nl) /* overflow */
426 c->Nh++;
427 c->Nh+=(len>>29);
428 c->Nl=l;
429
430 if (c->num != 0)
431 {
432 p=c->data;
433 sw=c->num>>2;
434 sc=c->num&0x03;
435
436 if ((c->num+len) >= HASH_CBLOCK)
437 {
438 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
439 for (; sw<HASH_LBLOCK; sw++)
440 {
441 HOST_c2l(data,l); p[sw]=l;
442 }
443 HASH_BLOCK_HOST_ORDER (c,p,1);
444 len-=(HASH_CBLOCK-c->num);
445 c->num=0;
446 /* drop through and do the rest */
447 }
448 else
449 {
450 c->num+=len;
451 if ((sc+len) < 4) /* ugly, add char's to a word */
452 {
453 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
454 }
455 else
456 {
457 ew=(c->num>>2);
458 ec=(c->num&0x03);
459 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
460 for (; sw < ew; sw++)
461 {
462 HOST_c2l(data,l); p[sw]=l;
463 }
464 if (ec)
465 {
466 HOST_c2l_p(data,l,ec); p[sw]=l;
467 }
468 }
469 return;
470 }
471 }
472
473 sw=len/HASH_CBLOCK;
474 if (sw > 0)
475 {
476#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
477 /*
478 * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
479 * only if sizeof(HASH_LONG)==4.
480 */
481 if ((((unsigned long)data)%4) == 0)
482 {
483 /* data is properly aligned so that we can cast it: */
484 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
485 sw*=HASH_CBLOCK;
486 data+=sw;
487 len-=sw;
488 }
489 else
490#if !defined(HASH_BLOCK_DATA_ORDER)
491 while (sw--)
492 {
493 memcpy (p=c->data,data,HASH_CBLOCK);
494 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
495 data+=HASH_CBLOCK;
496 len-=HASH_CBLOCK;
497 }
498#endif
499#endif
500#if defined(HASH_BLOCK_DATA_ORDER)
501 {
502 HASH_BLOCK_DATA_ORDER(c,data,sw);
503 sw*=HASH_CBLOCK;
504 data+=sw;
505 len-=sw;
506 }
507#endif
508 }
509
510 if (len!=0)
511 {
512 p = c->data;
513 c->num = len;
514 ew=len>>2; /* words to copy */
515 ec=len&0x03;
516 for (; ew; ew--,p++)
517 {
518 HOST_c2l(data,l); *p=l;
519 }
520 HOST_c2l_p(data,l,ec);
521 *p=l;
522 }
523 }
524
525
526void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
527 {
528#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
529 if ((((unsigned long)data)%4) == 0)
530 /* data is properly aligned so that we can cast it: */
531 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
532 else
533#if !defined(HASH_BLOCK_DATA_ORDER)
534 {
535 memcpy (c->data,data,HASH_CBLOCK);
536 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
537 }
538#endif
539#endif
540#if defined(HASH_BLOCK_DATA_ORDER)
541 HASH_BLOCK_DATA_ORDER (c,data,1);
542#endif
543 }
544
545
546void HASH_FINAL (unsigned char *md, HASH_CTX *c)
547 {
548 register HASH_LONG *p;
549 register unsigned long l;
550 register int i,j;
551 static const unsigned char end[4]={0x80,0x00,0x00,0x00};
552 const unsigned char *cp=end;
553
554 /* c->num should definitly have room for at least one more byte. */
555 p=c->data;
556 i=c->num>>2;
557 j=c->num&0x03;
558
559#if 0
560 /* purify often complains about the following line as an
561 * Uninitialized Memory Read. While this can be true, the
562 * following p_c2l macro will reset l when that case is true.
563 * This is because j&0x03 contains the number of 'valid' bytes
564 * already in p[i]. If and only if j&0x03 == 0, the UMR will
565 * occur but this is also the only time p_c2l will do
566 * l= *(cp++) instead of l|= *(cp++)
567 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
568 * 'potential bug' */
569#ifdef PURIFY
570 if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
571#endif
572 l=p[i];
573#else
574 l = (j==0) ? 0 : p[i];
575#endif
576 HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
577
578 if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
579 {
580 if (i<HASH_LBLOCK) p[i]=0;
581 HASH_BLOCK_HOST_ORDER (c,p,1);
582 i=0;
583 }
584 for (; i<(HASH_LBLOCK-2); i++)
585 p[i]=0;
586
587#if defined(DATA_ORDER_IS_BIG_ENDIAN)
588 p[HASH_LBLOCK-2]=c->Nh;
589 p[HASH_LBLOCK-1]=c->Nl;
590#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
591 p[HASH_LBLOCK-2]=c->Nl;
592 p[HASH_LBLOCK-1]=c->Nh;
593#endif
594 HASH_BLOCK_HOST_ORDER (c,p,1);
595
596#ifndef HASH_MAKE_STRING
597#error "HASH_MAKE_STRING must be defined!"
598#else
599 HASH_MAKE_STRING(c,md);
600#endif
601
602 c->num=0;
603 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
604 * but I'm not worried :-)
605 memset((void *)c,0,sizeof(HASH_CTX));
606 */
607 }
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 d10bc8397f..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 void *data, unsigned long len);
107void MD5_Final(unsigned char *md, MD5_CTX *c);
108unsigned char *MD5(const 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 23d196b8d4..0000000000
--- a/src/lib/libcrypto/md5/md5_dgst.c
+++ /dev/null
@@ -1,319 +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
63const char *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
189#ifdef X
190#undef X
191#endif
192void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
193 {
194 const unsigned char *data=data_;
195 register unsigned long A,B,C,D,l;
196 /*
197 * In case you wonder why A-D are declared as long and not
198 * as MD5_LONG. Doing so results in slight performance
199 * boost on LP64 architectures. The catch is we don't
200 * really care if 32 MSBs of a 64-bit register get polluted
201 * with eventual overflows as we *save* only 32 LSBs in
202 * *either* case. Now declaring 'em long excuses the compiler
203 * from keeping 32 MSBs zeroed resulting in 13% performance
204 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
205 * Well, to be honest it should say that this *prevents*
206 * performance degradation.
207 *
208 * <appro@fy.chalmers.se>
209 */
210#ifndef MD32_XARRAY
211 /* See comment in crypto/sha/sha_locl.h for details. */
212 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
213 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
214# define X(i) XX##i
215#else
216 MD5_LONG XX[MD5_LBLOCK];
217# define X(i) XX[i]
218#endif
219
220 A=c->A;
221 B=c->B;
222 C=c->C;
223 D=c->D;
224
225 for (;num--;)
226 {
227 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
228 /* Round 0 */
229 R0(A,B,C,D,X( 0), 7,0xd76aa478L); HOST_c2l(data,l); X( 2)=l;
230 R0(D,A,B,C,X( 1),12,0xe8c7b756L); HOST_c2l(data,l); X( 3)=l;
231 R0(C,D,A,B,X( 2),17,0x242070dbL); HOST_c2l(data,l); X( 4)=l;
232 R0(B,C,D,A,X( 3),22,0xc1bdceeeL); HOST_c2l(data,l); X( 5)=l;
233 R0(A,B,C,D,X( 4), 7,0xf57c0fafL); HOST_c2l(data,l); X( 6)=l;
234 R0(D,A,B,C,X( 5),12,0x4787c62aL); HOST_c2l(data,l); X( 7)=l;
235 R0(C,D,A,B,X( 6),17,0xa8304613L); HOST_c2l(data,l); X( 8)=l;
236 R0(B,C,D,A,X( 7),22,0xfd469501L); HOST_c2l(data,l); X( 9)=l;
237 R0(A,B,C,D,X( 8), 7,0x698098d8L); HOST_c2l(data,l); X(10)=l;
238 R0(D,A,B,C,X( 9),12,0x8b44f7afL); HOST_c2l(data,l); X(11)=l;
239 R0(C,D,A,B,X(10),17,0xffff5bb1L); HOST_c2l(data,l); X(12)=l;
240 R0(B,C,D,A,X(11),22,0x895cd7beL); HOST_c2l(data,l); X(13)=l;
241 R0(A,B,C,D,X(12), 7,0x6b901122L); HOST_c2l(data,l); X(14)=l;
242 R0(D,A,B,C,X(13),12,0xfd987193L); HOST_c2l(data,l); X(15)=l;
243 R0(C,D,A,B,X(14),17,0xa679438eL);
244 R0(B,C,D,A,X(15),22,0x49b40821L);
245 /* Round 1 */
246 R1(A,B,C,D,X( 1), 5,0xf61e2562L);
247 R1(D,A,B,C,X( 6), 9,0xc040b340L);
248 R1(C,D,A,B,X(11),14,0x265e5a51L);
249 R1(B,C,D,A,X( 0),20,0xe9b6c7aaL);
250 R1(A,B,C,D,X( 5), 5,0xd62f105dL);
251 R1(D,A,B,C,X(10), 9,0x02441453L);
252 R1(C,D,A,B,X(15),14,0xd8a1e681L);
253 R1(B,C,D,A,X( 4),20,0xe7d3fbc8L);
254 R1(A,B,C,D,X( 9), 5,0x21e1cde6L);
255 R1(D,A,B,C,X(14), 9,0xc33707d6L);
256 R1(C,D,A,B,X( 3),14,0xf4d50d87L);
257 R1(B,C,D,A,X( 8),20,0x455a14edL);
258 R1(A,B,C,D,X(13), 5,0xa9e3e905L);
259 R1(D,A,B,C,X( 2), 9,0xfcefa3f8L);
260 R1(C,D,A,B,X( 7),14,0x676f02d9L);
261 R1(B,C,D,A,X(12),20,0x8d2a4c8aL);
262 /* Round 2 */
263 R2(A,B,C,D,X( 5), 4,0xfffa3942L);
264 R2(D,A,B,C,X( 8),11,0x8771f681L);
265 R2(C,D,A,B,X(11),16,0x6d9d6122L);
266 R2(B,C,D,A,X(14),23,0xfde5380cL);
267 R2(A,B,C,D,X( 1), 4,0xa4beea44L);
268 R2(D,A,B,C,X( 4),11,0x4bdecfa9L);
269 R2(C,D,A,B,X( 7),16,0xf6bb4b60L);
270 R2(B,C,D,A,X(10),23,0xbebfbc70L);
271 R2(A,B,C,D,X(13), 4,0x289b7ec6L);
272 R2(D,A,B,C,X( 0),11,0xeaa127faL);
273 R2(C,D,A,B,X( 3),16,0xd4ef3085L);
274 R2(B,C,D,A,X( 6),23,0x04881d05L);
275 R2(A,B,C,D,X( 9), 4,0xd9d4d039L);
276 R2(D,A,B,C,X(12),11,0xe6db99e5L);
277 R2(C,D,A,B,X(15),16,0x1fa27cf8L);
278 R2(B,C,D,A,X( 2),23,0xc4ac5665L);
279 /* Round 3 */
280 R3(A,B,C,D,X( 0), 6,0xf4292244L);
281 R3(D,A,B,C,X( 7),10,0x432aff97L);
282 R3(C,D,A,B,X(14),15,0xab9423a7L);
283 R3(B,C,D,A,X( 5),21,0xfc93a039L);
284 R3(A,B,C,D,X(12), 6,0x655b59c3L);
285 R3(D,A,B,C,X( 3),10,0x8f0ccc92L);
286 R3(C,D,A,B,X(10),15,0xffeff47dL);
287 R3(B,C,D,A,X( 1),21,0x85845dd1L);
288 R3(A,B,C,D,X( 8), 6,0x6fa87e4fL);
289 R3(D,A,B,C,X(15),10,0xfe2ce6e0L);
290 R3(C,D,A,B,X( 6),15,0xa3014314L);
291 R3(B,C,D,A,X(13),21,0x4e0811a1L);
292 R3(A,B,C,D,X( 4), 6,0xf7537e82L);
293 R3(D,A,B,C,X(11),10,0xbd3af235L);
294 R3(C,D,A,B,X( 2),15,0x2ad7d2bbL);
295 R3(B,C,D,A,X( 9),21,0xeb86d391L);
296
297 A = c->A += A;
298 B = c->B += B;
299 C = c->C += C;
300 D = c->D += D;
301 }
302 }
303#endif
304
305#ifdef undef
306int printit(unsigned long *l)
307 {
308 int i,ii;
309
310 for (i=0; i<2; i++)
311 {
312 for (ii=0; ii<8; ii++)
313 {
314 fprintf(stderr,"%08lx ",l[i*8+ii]);
315 }
316 fprintf(stderr,"\n");
317 }
318 }
319#endif
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h
deleted file mode 100644
index c912484122..0000000000
--- a/src/lib/libcrypto/md5/md5_locl.h
+++ /dev/null
@@ -1,172 +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) || defined(__INTEL__)
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) || defined(__INTEL__)
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 "endianness" 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_MAKE_STRING(c,s) do { \
116 unsigned long ll; \
117 ll=(c)->A; HOST_l2c(ll,(s)); \
118 ll=(c)->B; HOST_l2c(ll,(s)); \
119 ll=(c)->C; HOST_l2c(ll,(s)); \
120 ll=(c)->D; HOST_l2c(ll,(s)); \
121 } while (0)
122#define HASH_BLOCK_HOST_ORDER md5_block_host_order
123#if !defined(L_ENDIAN) || defined(md5_block_data_order)
124#define HASH_BLOCK_DATA_ORDER md5_block_data_order
125/*
126 * Little-endians (Intel and Alpha) feel better without this.
127 * It looks like memcpy does better job than generic
128 * md5_block_data_order on copying-n-aligning input data.
129 * But frankly speaking I didn't expect such result on Alpha.
130 * On the other hand I've got this with egcs-1.0.2 and if
131 * program is compiled with another (better?) compiler it
132 * might turn out other way around.
133 *
134 * <appro@fy.chalmers.se>
135 */
136#endif
137
138#include "md32_common.h"
139
140/*
141#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
142#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
143*/
144
145/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
146 * simplified to the code below. Wei attributes these optimizations
147 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
148 */
149#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
150#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
151#define H(b,c,d) ((b) ^ (c) ^ (d))
152#define I(b,c,d) (((~(d)) | (b)) ^ (c))
153
154#define R0(a,b,c,d,k,s,t) { \
155 a+=((k)+(t)+F((b),(c),(d))); \
156 a=ROTATE(a,s); \
157 a+=b; };\
158
159#define R1(a,b,c,d,k,s,t) { \
160 a+=((k)+(t)+G((b),(c),(d))); \
161 a=ROTATE(a,s); \
162 a+=b; };
163
164#define R2(a,b,c,d,k,s,t) { \
165 a+=((k)+(t)+H((b),(c),(d))); \
166 a=ROTATE(a,s); \
167 a+=b; };
168
169#define R3(a,b,c,d,k,s,t) { \
170 a+=((k)+(t)+I((b),(c),(d))); \
171 a=ROTATE(a,s); \
172 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 b89dec850d..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(const 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/mem_dbg.c b/src/lib/libcrypto/mem_dbg.c
deleted file mode 100644
index a399485300..0000000000
--- a/src/lib/libcrypto/mem_dbg.c
+++ /dev/null
@@ -1,738 +0,0 @@
1/* crypto/mem_dbg.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <time.h>
62#include <openssl/crypto.h>
63#include <openssl/buffer.h>
64#include <openssl/bio.h>
65#include <openssl/lhash.h>
66#include "cryptlib.h"
67
68static int mh_mode=CRYPTO_MEM_CHECK_OFF;
69/* The state changes to CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE
70 * when the application asks for it (usually after library initialisation
71 * for which no book-keeping is desired).
72 *
73 * State CRYPTO_MEM_CHECK_ON exists only temporarily when the library
74 * thinks that certain allocations should not be checked (e.g. the data
75 * structures used for memory checking). It is not suitable as an initial
76 * state: the library will unexpectedly enable memory checking when it
77 * executes one of those sections that want to disable checking
78 * temporarily.
79 *
80 * State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes no sense whatsoever.
81 */
82
83static unsigned long order = 0; /* number of memory requests */
84static LHASH *mh=NULL; /* hash-table of memory requests (address as key) */
85
86
87typedef struct app_mem_info_st
88/* For application-defined information (static C-string `info')
89 * to be displayed in memory leak list.
90 * Each thread has its own stack. For applications, there is
91 * CRYPTO_push_info("...") to push an entry,
92 * CRYPTO_pop_info() to pop an entry,
93 * CRYPTO_remove_all_info() to pop all entries.
94 */
95 {
96 unsigned long thread;
97 const char *file;
98 int line;
99 const char *info;
100 struct app_mem_info_st *next; /* tail of thread's stack */
101 int references;
102 } APP_INFO;
103
104static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's
105 * that are at the top of their thread's stack
106 * (with `thread' as key) */
107
108typedef struct mem_st
109/* memory-block description */
110 {
111 char *addr;
112 int num;
113 const char *file;
114 int line;
115 unsigned long thread;
116 unsigned long order;
117 time_t time;
118 APP_INFO *app_info;
119 } MEM;
120
121static long options = /* extra information to be recorded */
122#if defined(CRYPTO_MDEBUG_TIME) || defined(CRYPTO_MDEBUG_ALL)
123 V_CRYPTO_MDEBUG_TIME |
124#endif
125#if defined(CRYPTO_MDEBUG_THREAD) || defined(CRYPTO_MDEBUG_ALL)
126 V_CRYPTO_MDEBUG_THREAD |
127#endif
128 0;
129
130
131static unsigned long disabling_thread = 0;
132
133int CRYPTO_mem_ctrl(int mode)
134 {
135 int ret=mh_mode;
136
137 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
138 switch (mode)
139 {
140 /* for applications: */
141 case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */
142 mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE;
143 disabling_thread = 0;
144 break;
145 case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
146 mh_mode = 0;
147 disabling_thread = 0;
148 break;
149
150 /* switch off temporarily (for library-internal use): */
151 case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
152 if (mh_mode & CRYPTO_MEM_CHECK_ON)
153 {
154 mh_mode&= ~CRYPTO_MEM_CHECK_ENABLE;
155 if (disabling_thread != CRYPTO_thread_id()) /* otherwise we already have the MALLOC2 lock */
156 {
157 /* Long-time lock CRYPTO_LOCK_MALLOC2 must not be claimed while
158 * we're holding CRYPTO_LOCK_MALLOC, or we'll deadlock if
159 * somebody else holds CRYPTO_LOCK_MALLOC2 (and cannot release
160 * it because we block entry to this function).
161 * Give them a chance, first, and then claim the locks in
162 * appropriate order (long-time lock first).
163 */
164 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
165 /* Note that after we have waited for CRYPTO_LOCK_MALLOC2
166 * and CRYPTO_LOCK_MALLOC, we'll still be in the right
167 * "case" and "if" branch because MemCheck_start and
168 * MemCheck_stop may never be used while there are multiple
169 * OpenSSL threads. */
170 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
171 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
172 disabling_thread=CRYPTO_thread_id();
173 }
174 }
175 break;
176 case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
177 if (mh_mode & CRYPTO_MEM_CHECK_ON)
178 {
179 mh_mode|=CRYPTO_MEM_CHECK_ENABLE;
180 if (disabling_thread != 0)
181 {
182 disabling_thread=0;
183 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
184 }
185 }
186 break;
187
188 default:
189 break;
190 }
191 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
192 return(ret);
193 }
194
195int CRYPTO_is_mem_check_on(void)
196 {
197 int ret = 0;
198
199 if (mh_mode & CRYPTO_MEM_CHECK_ON)
200 {
201 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
202
203 ret = (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
204 && disabling_thread != CRYPTO_thread_id();
205
206 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
207 }
208 return(ret);
209 }
210
211
212void CRYPTO_dbg_set_options(long bits)
213 {
214 options = bits;
215 }
216
217long CRYPTO_dbg_get_options(void)
218 {
219 return options;
220 }
221
222static int mem_cmp(MEM *a, MEM *b)
223 {
224 return(a->addr - b->addr);
225 }
226
227static unsigned long mem_hash(MEM *a)
228 {
229 unsigned long ret;
230
231 ret=(unsigned long)a->addr;
232
233 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
234 return(ret);
235 }
236
237static int app_info_cmp(APP_INFO *a, APP_INFO *b)
238 {
239 return(a->thread != b->thread);
240 }
241
242static unsigned long app_info_hash(APP_INFO *a)
243 {
244 unsigned long ret;
245
246 ret=(unsigned long)a->thread;
247
248 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
249 return(ret);
250 }
251
252static APP_INFO *pop_info()
253 {
254 APP_INFO tmp;
255 APP_INFO *ret = NULL;
256
257 if (amih != NULL)
258 {
259 tmp.thread=CRYPTO_thread_id();
260 if ((ret=(APP_INFO *)lh_delete(amih,&tmp)) != NULL)
261 {
262 APP_INFO *next=ret->next;
263
264 if (next != NULL)
265 {
266 next->references++;
267 lh_insert(amih,(char *)next);
268 }
269#ifdef LEVITTE_DEBUG
270 if (ret->thread != tmp.thread)
271 {
272 fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
273 ret->thread, tmp.thread);
274 abort();
275 }
276#endif
277 if (--(ret->references) <= 0)
278 {
279 ret->next = NULL;
280 if (next != NULL)
281 next->references--;
282 Free(ret);
283 }
284 }
285 }
286 return(ret);
287 }
288
289int CRYPTO_push_info_(const char *info, const char *file, int line)
290 {
291 APP_INFO *ami, *amim;
292 int ret=0;
293
294 if (is_MemCheck_on())
295 {
296 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
297
298 if ((ami = (APP_INFO *)Malloc(sizeof(APP_INFO))) == NULL)
299 {
300 ret=0;
301 goto err;
302 }
303 if (amih == NULL)
304 {
305 if ((amih=lh_new(app_info_hash,app_info_cmp)) == NULL)
306 {
307 Free(ami);
308 ret=0;
309 goto err;
310 }
311 }
312
313 ami->thread=CRYPTO_thread_id();
314 ami->file=file;
315 ami->line=line;
316 ami->info=info;
317 ami->references=1;
318 ami->next=NULL;
319
320 if ((amim=(APP_INFO *)lh_insert(amih,(char *)ami)) != NULL)
321 {
322#ifdef LEVITTE_DEBUG
323 if (ami->thread != amim->thread)
324 {
325 fprintf(stderr, "CRYPTO_push_info(): previous info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
326 amim->thread, ami->thread);
327 abort();
328 }
329#endif
330 ami->next=amim;
331 }
332 err:
333 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
334 }
335
336 return(ret);
337 }
338
339int CRYPTO_pop_info(void)
340 {
341 int ret=0;
342
343 if (is_MemCheck_on()) /* _must_ be true, or something went severely wrong */
344 {
345 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
346
347 ret=(pop_info() != NULL);
348
349 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
350 }
351 return(ret);
352 }
353
354int CRYPTO_remove_all_info(void)
355 {
356 int ret=0;
357
358 if (is_MemCheck_on()) /* _must_ be true */
359 {
360 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
361
362 while(pop_info() != NULL)
363 ret++;
364
365 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
366 }
367 return(ret);
368 }
369
370
371static unsigned long break_order_num=0;
372void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
373 int before_p)
374 {
375 MEM *m,*mm;
376 APP_INFO tmp,*amim;
377
378 switch(before_p & 127)
379 {
380 case 0:
381 break;
382 case 1:
383 if (addr == NULL)
384 break;
385
386 if (is_MemCheck_on())
387 {
388 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
389 if ((m=(MEM *)Malloc(sizeof(MEM))) == NULL)
390 {
391 Free(addr);
392 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
393 return;
394 }
395 if (mh == NULL)
396 {
397 if ((mh=lh_new(mem_hash,mem_cmp)) == NULL)
398 {
399 Free(addr);
400 Free(m);
401 addr=NULL;
402 goto err;
403 }
404 }
405
406 m->addr=addr;
407 m->file=file;
408 m->line=line;
409 m->num=num;
410 if (options & V_CRYPTO_MDEBUG_THREAD)
411 m->thread=CRYPTO_thread_id();
412 else
413 m->thread=0;
414
415 if (order == break_order_num)
416 {
417 /* BREAK HERE */
418 m->order=order;
419 }
420 m->order=order++;
421#ifdef LEVITTE_DEBUG
422 fprintf(stderr, "LEVITTE_DEBUG: [%5d] %c 0x%p (%d)\n",
423 m->order,
424 (before_p & 128) ? '*' : '+',
425 m->addr, m->num);
426#endif
427 if (options & V_CRYPTO_MDEBUG_TIME)
428 m->time=time(NULL);
429 else
430 m->time=0;
431
432 tmp.thread=CRYPTO_thread_id();
433 m->app_info=NULL;
434 if (amih != NULL
435 && (amim=(APP_INFO *)lh_retrieve(amih,(char *)&tmp)) != NULL)
436 {
437 m->app_info = amim;
438 amim->references++;
439 }
440
441 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
442 {
443 /* Not good, but don't sweat it */
444 if (mm->app_info != NULL)
445 {
446 mm->app_info->references--;
447 }
448 Free(mm);
449 }
450 err:
451 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
452 }
453 break;
454 }
455 return;
456 }
457
458void CRYPTO_dbg_free(void *addr, int before_p)
459 {
460 MEM m,*mp;
461
462 switch(before_p)
463 {
464 case 0:
465 if (addr == NULL)
466 break;
467
468 if (is_MemCheck_on() && (mh != NULL))
469 {
470 MemCheck_off();
471
472 m.addr=addr;
473 mp=(MEM *)lh_delete(mh,(char *)&m);
474 if (mp != NULL)
475 {
476#ifdef LEVITTE_DEBUG
477 fprintf(stderr, "LEVITTE_DEBUG: [%5d] - 0x%p (%d)\n",
478 mp->order, mp->addr, mp->num);
479#endif
480 if (mp->app_info != NULL)
481 {
482 mp->app_info->references--;
483 }
484 Free(mp);
485 }
486
487 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
488 }
489 break;
490 case 1:
491 break;
492 }
493 }
494
495void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,
496 const char *file, int line, int before_p)
497 {
498 MEM m,*mp;
499
500#ifdef LEVITTE_DEBUG
501 fprintf(stderr, "LEVITTE_DEBUG: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \"%s\", line = %d, before_p = %d)\n",
502 addr1, addr2, num, file, line, before_p);
503#endif
504
505 switch(before_p)
506 {
507 case 0:
508 break;
509 case 1:
510 if (addr2 == NULL)
511 break;
512
513 if (addr1 == NULL)
514 {
515 CRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);
516 break;
517 }
518
519 if (is_MemCheck_on())
520 {
521 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
522
523 m.addr=addr1;
524 mp=(MEM *)lh_delete(mh,(char *)&m);
525 if (mp != NULL)
526 {
527#ifdef LEVITTE_DEBUG
528 fprintf(stderr, "LEVITTE_DEBUG: [%5d] * 0x%p (%d) -> 0x%p (%d)\n",
529 mp->order,
530 mp->addr, mp->num,
531 addr2, num);
532#endif
533 mp->addr=addr2;
534 mp->num=num;
535 lh_insert(mh,(char *)mp);
536 }
537
538 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
539 }
540 break;
541 }
542 return;
543 }
544
545
546typedef struct mem_leak_st
547 {
548 BIO *bio;
549 int chunks;
550 long bytes;
551 } MEM_LEAK;
552
553static void print_leak(MEM *m, MEM_LEAK *l)
554 {
555 char buf[1024];
556 char *bufp = buf;
557 APP_INFO *amip;
558 int ami_cnt;
559 struct tm *lcl = NULL;
560 unsigned long ti;
561
562 if(m->addr == (char *)l->bio)
563 return;
564
565 if (options & V_CRYPTO_MDEBUG_TIME)
566 {
567 lcl = localtime(&m->time);
568
569 sprintf(bufp, "[%02d:%02d:%02d] ",
570 lcl->tm_hour,lcl->tm_min,lcl->tm_sec);
571 bufp += strlen(bufp);
572 }
573
574 sprintf(bufp, "%5lu file=%s, line=%d, ",
575 m->order,m->file,m->line);
576 bufp += strlen(bufp);
577
578 if (options & V_CRYPTO_MDEBUG_THREAD)
579 {
580 sprintf(bufp, "thread=%lu, ", m->thread);
581 bufp += strlen(bufp);
582 }
583
584 sprintf(bufp, "number=%d, address=%08lX\n",
585 m->num,(unsigned long)m->addr);
586 bufp += strlen(bufp);
587
588 BIO_puts(l->bio,buf);
589
590 l->chunks++;
591 l->bytes+=m->num;
592
593 amip=m->app_info;
594 ami_cnt=0;
595 if (!amip)
596 return;
597 ti=amip->thread;
598
599 do
600 {
601 int buf_len;
602 int info_len;
603
604 ami_cnt++;
605 memset(buf,'>',ami_cnt);
606 sprintf(buf + ami_cnt,
607 " thread=%lu, file=%s, line=%d, info=\"",
608 amip->thread, amip->file, amip->line);
609 buf_len=strlen(buf);
610 info_len=strlen(amip->info);
611 if (128 - buf_len - 3 < info_len)
612 {
613 memcpy(buf + buf_len, amip->info, 128 - buf_len - 3);
614 buf_len = 128 - 3;
615 }
616 else
617 {
618 strcpy(buf + buf_len, amip->info);
619 buf_len = strlen(buf);
620 }
621 sprintf(buf + buf_len, "\"\n");
622
623 BIO_puts(l->bio,buf);
624
625 amip = amip->next;
626 }
627 while(amip && amip->thread == ti);
628
629#ifdef LEVITTE_DEBUG
630 if (amip)
631 {
632 fprintf(stderr, "Thread switch detected in backtrace!!!!\n");
633 abort();
634 }
635#endif
636 }
637
638void CRYPTO_mem_leaks(BIO *b)
639 {
640 MEM_LEAK ml;
641 char buf[80];
642
643 if (mh == NULL && amih == NULL)
644 return;
645 ml.bio=b;
646 ml.bytes=0;
647 ml.chunks=0;
648 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
649 if (mh != NULL)
650 lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml);
651 if (ml.chunks != 0)
652 {
653 sprintf(buf,"%ld bytes leaked in %d chunks\n",
654 ml.bytes,ml.chunks);
655 BIO_puts(b,buf);
656 }
657 else
658 {
659 /* Make sure that, if we found no leaks, memory-leak debugging itself
660 * does not introduce memory leaks (which might irritate
661 * external debugging tools).
662 * (When someone enables leak checking, but does not call
663 * this function, we declare it to be their fault.)
664 *
665 * XXX This should be in CRYPTO_mem_leaks_cb,
666 * and CRYPTO_mem_leaks should be implemented by
667 * using CRYPTO_mem_leaks_cb.
668 * (Also their should be a variant of lh_doall_arg
669 * that takes a function pointer instead of a void *;
670 * this would obviate the ugly and illegal
671 * void_fn_to_char kludge in CRYPTO_mem_leaks_cb.
672 * Otherwise the code police will come and get us.)
673 */
674 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
675 if (mh != NULL)
676 {
677 lh_free(mh);
678 mh = NULL;
679 }
680 if (amih != NULL)
681 {
682 if (lh_num_items(amih) == 0)
683 {
684 lh_free(amih);
685 amih = NULL;
686 }
687 }
688 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
689 }
690 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
691
692#if 0
693 lh_stats_bio(mh,b);
694 lh_node_stats_bio(mh,b);
695 lh_node_usage_stats_bio(mh,b);
696#endif
697 }
698
699union void_fn_to_char_u
700 {
701 char *char_p;
702 void (*fn_p)();
703 };
704
705static void cb_leak(MEM *m, char *cb)
706 {
707 union void_fn_to_char_u mem_callback;
708
709 mem_callback.char_p=cb;
710 mem_callback.fn_p(m->order,m->file,m->line,m->num,m->addr);
711 }
712
713void CRYPTO_mem_leaks_cb(void (*cb)())
714 {
715 union void_fn_to_char_u mem_cb;
716
717 if (mh == NULL) return;
718 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
719 mem_cb.fn_p=cb;
720 lh_doall_arg(mh,(void (*)())cb_leak,mem_cb.char_p);
721 mem_cb.char_p=NULL;
722 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
723 }
724
725#ifndef NO_FP_API
726void CRYPTO_mem_leaks_fp(FILE *fp)
727 {
728 BIO *b;
729
730 if (mh == NULL) return;
731 if ((b=BIO_new(BIO_s_file())) == NULL)
732 return;
733 BIO_set_fp(b,fp,BIO_NOCLOSE);
734 CRYPTO_mem_leaks(b);
735 BIO_free(b);
736 }
737#endif
738
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
deleted file mode 100644
index d9389a5e5a..0000000000
--- a/src/lib/libcrypto/objects/o_names.c
+++ /dev/null
@@ -1,265 +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#include <openssl/safestack.h>
8
9/* I use the ex_data stuff to manage the identifiers for the obj_name_types
10 * that applications may define. I only really use the free function field.
11 */
12static LHASH *names_lh=NULL;
13static int names_type_num=OBJ_NAME_TYPE_NUM;
14
15typedef struct name_funcs_st
16 {
17 unsigned long (*hash_func)();
18 int (*cmp_func)();
19 void (*free_func)();
20 } NAME_FUNCS;
21
22DECLARE_STACK_OF(NAME_FUNCS)
23IMPLEMENT_STACK_OF(NAME_FUNCS)
24
25static STACK_OF(NAME_FUNCS) *name_funcs_stack;
26
27static unsigned long obj_name_hash(OBJ_NAME *a);
28static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b);
29
30int OBJ_NAME_init(void)
31 {
32 if (names_lh != NULL) return(1);
33 MemCheck_off();
34 names_lh=lh_new(obj_name_hash,obj_name_cmp);
35 MemCheck_on();
36 return(names_lh != NULL);
37 }
38
39int OBJ_NAME_new_index(unsigned long (*hash_func)(), int (*cmp_func)(),
40 void (*free_func)())
41 {
42 int ret;
43 int i;
44 NAME_FUNCS *name_funcs;
45
46 if (name_funcs_stack == NULL)
47 {
48 MemCheck_off();
49 name_funcs_stack=sk_NAME_FUNCS_new_null();
50 MemCheck_on();
51 }
52 if ((name_funcs_stack == NULL))
53 {
54 /* ERROR */
55 return(0);
56 }
57 ret=names_type_num;
58 names_type_num++;
59 for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++)
60 {
61 MemCheck_off();
62 name_funcs = Malloc(sizeof(NAME_FUNCS));
63 name_funcs->hash_func = lh_strhash;
64 name_funcs->cmp_func = (int (*)())strcmp;
65 name_funcs->free_func = 0; /* NULL is often declared to
66 * ((void *)0), which according
67 * to Compaq C is not really
68 * compatible with a function
69 * pointer. -- Richard Levitte*/
70 sk_NAME_FUNCS_push(name_funcs_stack,name_funcs);
71 MemCheck_on();
72 }
73 name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
74 if (hash_func != NULL)
75 name_funcs->hash_func = hash_func;
76 if (cmp_func != NULL)
77 name_funcs->cmp_func = cmp_func;
78 if (free_func != NULL)
79 name_funcs->free_func = free_func;
80 return(ret);
81 }
82
83static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b)
84 {
85 int ret;
86
87 ret=a->type-b->type;
88 if (ret == 0)
89 {
90 if ((name_funcs_stack != NULL)
91 && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
92 {
93 ret=sk_NAME_FUNCS_value(name_funcs_stack,a->type)
94 ->cmp_func(a->name,b->name);
95 }
96 else
97 ret=strcmp(a->name,b->name);
98 }
99 return(ret);
100 }
101
102static unsigned long obj_name_hash(OBJ_NAME *a)
103 {
104 unsigned long ret;
105
106 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
107 {
108 ret=sk_NAME_FUNCS_value(name_funcs_stack,a->type)
109 ->hash_func(a->name);
110 }
111 else
112 {
113 ret=lh_strhash(a->name);
114 }
115 ret^=a->type;
116 return(ret);
117 }
118
119const char *OBJ_NAME_get(const char *name, int type)
120 {
121 OBJ_NAME on,*ret;
122 int num=0,alias;
123
124 if (name == NULL) return(NULL);
125 if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL);
126
127 alias=type&OBJ_NAME_ALIAS;
128 type&= ~OBJ_NAME_ALIAS;
129
130 on.name=name;
131 on.type=type;
132
133 for (;;)
134 {
135 ret=(OBJ_NAME *)lh_retrieve(names_lh,&on);
136 if (ret == NULL) return(NULL);
137 if ((ret->alias) && !alias)
138 {
139 if (++num > 10) return(NULL);
140 on.name=ret->data;
141 }
142 else
143 {
144 return(ret->data);
145 }
146 }
147 }
148
149int OBJ_NAME_add(const char *name, int type, const char *data)
150 {
151 OBJ_NAME *onp,*ret;
152 int alias;
153
154 if ((names_lh == NULL) && !OBJ_NAME_init()) return(0);
155
156 alias=type&OBJ_NAME_ALIAS;
157 type&= ~OBJ_NAME_ALIAS;
158
159 onp=(OBJ_NAME *)Malloc(sizeof(OBJ_NAME));
160 if (onp == NULL)
161 {
162 /* ERROR */
163 return(0);
164 }
165
166 onp->name=name;
167 onp->alias=alias;
168 onp->type=type;
169 onp->data=data;
170
171 ret=(OBJ_NAME *)lh_insert(names_lh,onp);
172 if (ret != NULL)
173 {
174 /* free things */
175 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
176 {
177 /* XXX: I'm not sure I understand why the free
178 * function should get three arguments...
179 * -- Richard Levitte
180 */
181 sk_NAME_FUNCS_value(name_funcs_stack,ret->type)
182 ->free_func(ret->name,ret->type,ret->data);
183 }
184 Free(ret);
185 }
186 else
187 {
188 if (lh_error(names_lh))
189 {
190 /* ERROR */
191 return(0);
192 }
193 }
194 return(1);
195 }
196
197int OBJ_NAME_remove(const char *name, int type)
198 {
199 OBJ_NAME on,*ret;
200
201 if (names_lh == NULL) return(0);
202
203 type&= ~OBJ_NAME_ALIAS;
204 on.name=name;
205 on.type=type;
206 ret=(OBJ_NAME *)lh_delete(names_lh,&on);
207 if (ret != NULL)
208 {
209 /* free things */
210 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
211 {
212 /* XXX: I'm not sure I understand why the free
213 * function should get three arguments...
214 * -- Richard Levitte
215 */
216 sk_NAME_FUNCS_value(name_funcs_stack,ret->type)
217 ->free_func(ret->name,ret->type,ret->data);
218 }
219 Free(ret);
220 return(1);
221 }
222 else
223 return(0);
224 }
225
226static int free_type;
227
228static void names_lh_free(OBJ_NAME *onp, int type)
229{
230 if(onp == NULL)
231 return;
232
233 if ((free_type < 0) || (free_type == onp->type))
234 {
235 OBJ_NAME_remove(onp->name,onp->type);
236 }
237 }
238
239static void name_funcs_free(NAME_FUNCS *ptr)
240 {
241 Free(ptr);
242 }
243
244void OBJ_NAME_cleanup(int type)
245 {
246 unsigned long down_load;
247
248 if (names_lh == NULL) return;
249
250 free_type=type;
251 down_load=names_lh->down_load;
252 names_lh->down_load=0;
253
254 lh_doall(names_lh,names_lh_free);
255 if (type < 0)
256 {
257 lh_free(names_lh);
258 sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free);
259 names_lh=NULL;
260 name_funcs_stack = NULL;
261 }
262 else
263 names_lh->down_load=down_load;
264 }
265
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
deleted file mode 100644
index da6df3762a..0000000000
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ /dev/null
@@ -1,649 +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]={NULL,NULL,NULL,NULL},*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_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
224 if ((o->length != 0) && (obj->data != NULL))
225 ao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
226 if (o->sn != NULL)
227 ao[ADDED_SNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
228 if (o->ln != NULL)
229 ao[ADDED_LNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
230
231 for (i=ADDED_DATA; i<=ADDED_NID; i++)
232 {
233 if (ao[i] != NULL)
234 {
235 ao[i]->type=i;
236 ao[i]->obj=o;
237 aop=(ADDED_OBJ *)lh_insert(added,ao[i]);
238 /* memory leak, buit should not normally matter */
239 if (aop != NULL)
240 Free(aop);
241 }
242 }
243 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
244 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
245
246 return(o->nid);
247err:
248 for (i=ADDED_DATA; i<=ADDED_NID; i++)
249 if (ao[i] != NULL) Free(ao[i]);
250 if (o != NULL) Free(o);
251 return(NID_undef);
252 }
253
254ASN1_OBJECT *OBJ_nid2obj(int n)
255 {
256 ADDED_OBJ ad,*adp;
257 ASN1_OBJECT ob;
258
259 if ((n >= 0) && (n < NUM_NID))
260 {
261 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
262 {
263 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
264 return(NULL);
265 }
266 return((ASN1_OBJECT *)&(nid_objs[n]));
267 }
268 else if (added == NULL)
269 return(NULL);
270 else
271 {
272 ad.type=ADDED_NID;
273 ad.obj= &ob;
274 ob.nid=n;
275 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
276 if (adp != NULL)
277 return(adp->obj);
278 else
279 {
280 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
281 return(NULL);
282 }
283 }
284 }
285
286const char *OBJ_nid2sn(int n)
287 {
288 ADDED_OBJ ad,*adp;
289 ASN1_OBJECT ob;
290
291 if ((n >= 0) && (n < NUM_NID))
292 {
293 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
294 {
295 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
296 return(NULL);
297 }
298 return(nid_objs[n].sn);
299 }
300 else if (added == NULL)
301 return(NULL);
302 else
303 {
304 ad.type=ADDED_NID;
305 ad.obj= &ob;
306 ob.nid=n;
307 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
308 if (adp != NULL)
309 return(adp->obj->sn);
310 else
311 {
312 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
313 return(NULL);
314 }
315 }
316 }
317
318const char *OBJ_nid2ln(int n)
319 {
320 ADDED_OBJ ad,*adp;
321 ASN1_OBJECT ob;
322
323 if ((n >= 0) && (n < NUM_NID))
324 {
325 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
326 {
327 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
328 return(NULL);
329 }
330 return(nid_objs[n].ln);
331 }
332 else if (added == NULL)
333 return(NULL);
334 else
335 {
336 ad.type=ADDED_NID;
337 ad.obj= &ob;
338 ob.nid=n;
339 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
340 if (adp != NULL)
341 return(adp->obj->ln);
342 else
343 {
344 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
345 return(NULL);
346 }
347 }
348 }
349
350int OBJ_obj2nid(ASN1_OBJECT *a)
351 {
352 ASN1_OBJECT **op;
353 ADDED_OBJ ad,*adp;
354
355 if (a == NULL)
356 return(NID_undef);
357 if (a->nid != 0)
358 return(a->nid);
359
360 if (added != NULL)
361 {
362 ad.type=ADDED_DATA;
363 ad.obj=a;
364 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
365 if (adp != NULL) return (adp->obj->nid);
366 }
367 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,
368 sizeof(ASN1_OBJECT *),(int (*)())obj_cmp);
369 if (op == NULL)
370 return(NID_undef);
371 return((*op)->nid);
372 }
373
374/* Convert an object name into an ASN1_OBJECT
375 * if "noname" is not set then search for short and long names first.
376 * This will convert the "dotted" form into an object: unlike OBJ_txt2nid
377 * it can be used with any objects, not just registered ones.
378 */
379
380ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
381 {
382 int nid = NID_undef;
383 ASN1_OBJECT *op=NULL;
384 unsigned char *buf,*p;
385 int i, j;
386
387 if(!no_name) {
388 if( ((nid = OBJ_sn2nid(s)) != NID_undef) ||
389 ((nid = OBJ_ln2nid(s)) != NID_undef) )
390 return OBJ_nid2obj(nid);
391 }
392
393 /* Work out size of content octets */
394 i=a2d_ASN1_OBJECT(NULL,0,s,-1);
395 if (i <= 0) {
396 /* Clear the error */
397 ERR_get_error();
398 return NULL;
399 }
400 /* Work out total size */
401 j = ASN1_object_size(0,i,V_ASN1_OBJECT);
402
403 if((buf=(unsigned char *)Malloc(j)) == NULL) return NULL;
404
405 p = buf;
406 /* Write out tag+length */
407 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
408 /* Write out contents */
409 a2d_ASN1_OBJECT(p,i,s,-1);
410
411 p=buf;
412 op=d2i_ASN1_OBJECT(NULL,&p,i);
413 Free(buf);
414 return op;
415 }
416
417int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name)
418{
419 int i,idx=0,n=0,len,nid;
420 unsigned long l;
421 unsigned char *p;
422 const char *s;
423 char tbuf[32];
424
425 if (buf_len <= 0) return(0);
426
427 if ((a == NULL) || (a->data == NULL)) {
428 buf[0]='\0';
429 return(0);
430 }
431
432 nid=OBJ_obj2nid(a);
433 if ((nid == NID_undef) || no_name) {
434 len=a->length;
435 p=a->data;
436
437 idx=0;
438 l=0;
439 while (idx < a->length) {
440 l|=(p[idx]&0x7f);
441 if (!(p[idx] & 0x80)) break;
442 l<<=7L;
443 idx++;
444 }
445 idx++;
446 i=(int)(l/40);
447 if (i > 2) i=2;
448 l-=(long)(i*40);
449
450 sprintf(tbuf,"%d.%lu",i,l);
451 i=strlen(tbuf);
452 strncpy(buf,tbuf,buf_len);
453 buf_len-=i;
454 buf+=i;
455 n+=i;
456
457 l=0;
458 for (; idx<len; idx++) {
459 l|=p[idx]&0x7f;
460 if (!(p[idx] & 0x80)) {
461 sprintf(tbuf,".%lu",l);
462 i=strlen(tbuf);
463 if (buf_len > 0)
464 strncpy(buf,tbuf,buf_len);
465 buf_len-=i;
466 buf+=i;
467 n+=i;
468 l=0;
469 }
470 l<<=7L;
471 }
472 } else {
473 s=OBJ_nid2ln(nid);
474 if (s == NULL)
475 s=OBJ_nid2sn(nid);
476 strncpy(buf,s,buf_len);
477 n=strlen(s);
478 }
479 buf[buf_len-1]='\0';
480 return(n);
481}
482
483int OBJ_txt2nid(char *s)
484{
485 ASN1_OBJECT *obj;
486 int nid;
487 obj = OBJ_txt2obj(s, 0);
488 nid = OBJ_obj2nid(obj);
489 ASN1_OBJECT_free(obj);
490 return nid;
491}
492
493int OBJ_ln2nid(const char *s)
494 {
495 ASN1_OBJECT o,*oo= &o,**op;
496 ADDED_OBJ ad,*adp;
497
498 o.ln=s;
499 if (added != NULL)
500 {
501 ad.type=ADDED_LNAME;
502 ad.obj= &o;
503 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
504 if (adp != NULL) return (adp->obj->nid);
505 }
506 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN,
507 sizeof(ASN1_OBJECT *),(int (*)())ln_cmp);
508 if (op == NULL) return(NID_undef);
509 return((*op)->nid);
510 }
511
512int OBJ_sn2nid(const char *s)
513 {
514 ASN1_OBJECT o,*oo= &o,**op;
515 ADDED_OBJ ad,*adp;
516
517 o.sn=s;
518 if (added != NULL)
519 {
520 ad.type=ADDED_SNAME;
521 ad.obj= &o;
522 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
523 if (adp != NULL) return (adp->obj->nid);
524 }
525 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
526 sizeof(ASN1_OBJECT *),(int (*)())sn_cmp);
527 if (op == NULL) return(NID_undef);
528 return((*op)->nid);
529 }
530
531static int obj_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
532 {
533 int j;
534 ASN1_OBJECT *a= *ap;
535 ASN1_OBJECT *b= *bp;
536
537 j=(a->length - b->length);
538 if (j) return(j);
539 return(memcmp(a->data,b->data,a->length));
540 }
541
542char *OBJ_bsearch(char *key, char *base, int num, int size, int (*cmp)())
543 {
544 int l,h,i,c;
545 char *p;
546
547 if (num == 0) return(NULL);
548 l=0;
549 h=num;
550 while (l < h)
551 {
552 i=(l+h)/2;
553 p= &(base[i*size]);
554 c=(*cmp)(key,p);
555 if (c < 0)
556 h=i;
557 else if (c > 0)
558 l=i+1;
559 else
560 return(p);
561 }
562#ifdef CHARSET_EBCDIC
563/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and
564 * I don't have perl (yet), we revert to a *LINEAR* search
565 * when the object wasn't found in the binary search.
566 */
567 for (i=0; i<num; ++i) {
568 p= &(base[i*size]);
569 if ((*cmp)(key,p) == 0)
570 return p;
571 }
572#endif
573 return(NULL);
574 }
575
576int OBJ_create_objects(BIO *in)
577 {
578 MS_STATIC char buf[512];
579 int i,num=0;
580 char *o,*s,*l=NULL;
581
582 for (;;)
583 {
584 s=o=NULL;
585 i=BIO_gets(in,buf,512);
586 if (i <= 0) return(num);
587 buf[i-1]='\0';
588 if (!isalnum((unsigned char)buf[0])) return(num);
589 o=s=buf;
590 while (isdigit((unsigned char)*s) || (*s == '.'))
591 s++;
592 if (*s != '\0')
593 {
594 *(s++)='\0';
595 while (isspace((unsigned char)*s))
596 s++;
597 if (*s == '\0')
598 s=NULL;
599 else
600 {
601 l=s;
602 while ((*l != '\0') && !isspace((unsigned char)*l))
603 l++;
604 if (*l != '\0')
605 {
606 *(l++)='\0';
607 while (isspace((unsigned char)*l))
608 l++;
609 if (*l == '\0') l=NULL;
610 }
611 else
612 l=NULL;
613 }
614 }
615 else
616 s=NULL;
617 if ((o == NULL) || (*o == '\0')) return(num);
618 if (!OBJ_create(o,s,l)) return(num);
619 num++;
620 }
621 /* return(num); */
622 }
623
624int OBJ_create(char *oid, char *sn, char *ln)
625 {
626 int ok=0;
627 ASN1_OBJECT *op=NULL;
628 unsigned char *buf;
629 int i;
630
631 i=a2d_ASN1_OBJECT(NULL,0,oid,-1);
632 if (i <= 0) return(0);
633
634 if ((buf=(unsigned char *)Malloc(i)) == NULL)
635 {
636 OBJerr(OBJ_F_OBJ_CREATE,OBJ_R_MALLOC_FAILURE);
637 return(0);
638 }
639 i=a2d_ASN1_OBJECT(buf,i,oid,-1);
640 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
641 if (op == NULL)
642 goto err;
643 ok=OBJ_add_object(op);
644err:
645 ASN1_OBJECT_free(op);
646 Free(buf);
647 return(ok);
648 }
649
diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl
deleted file mode 100644
index e6e3c3b9c0..0000000000
--- a/src/lib/libcrypto/objects/obj_dat.pl
+++ /dev/null
@@ -1,275 +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
41open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
42open (OUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
43
44while (<IN>)
45 {
46 next unless /^\#define\s+(\S+)\s+(.*)$/;
47 $v=$1;
48 $d=$2;
49 if ($v =~ /^SN_(.*)$/)
50 { $sn{$1}=$d; }
51 elsif ($v =~ /^LN_(.*)$/)
52 { $ln{$1}=$d; }
53 elsif ($v =~ /^NID_(.*)$/)
54 { $nid{$d}=$1; }
55 elsif ($v =~ /^OBJ_(.*)$/)
56 {
57 $obj{$1}=$v;
58 $objd{$v}=$d;
59 }
60 }
61close IN;
62
63%ob=&expand_obj(*objd);
64
65@a=sort { $a <=> $b } keys %nid;
66$n=$a[$#a]+1;
67
68@lvalues=();
69$lvalues=0;
70
71for ($i=0; $i<$n; $i++)
72 {
73 if (!defined($nid{$i}))
74 {
75 push(@out,"{NULL,NULL,NID_undef,0,NULL},\n");
76 }
77 else
78 {
79 $sn=defined($sn{$nid{$i}})?"$sn{$nid{$i}}":"NULL";
80 $ln=defined($ln{$nid{$i}})?"$ln{$nid{$i}}":"NULL";
81 $sn=$ln if ($sn eq "NULL");
82 $ln=$sn if ($ln eq "NULL");
83 $out ="{";
84 $out.=$sn;
85 $out.=",".$ln;
86 $out.=",NID_$nid{$i},";
87 if (defined($obj{$nid{$i}}))
88 {
89 $v=$objd{$obj{$nid{$i}}};
90 $v =~ s/L//g;
91 $v =~ s/,/ /g;
92 $r=&der_it($v);
93 $z="";
94 $length=0;
95 foreach (unpack("C*",$r))
96 {
97 $z.=sprintf("0x%02X,",$_);
98 $length++;
99 }
100 $obj_der{$obj{$nid{$i}}}=$z;
101 $obj_len{$obj{$nid{$i}}}=$length;
102
103 push(@lvalues,sprintf("%-45s/* [%3d] %s */\n",
104 $z,$lvalues,$obj{$nid{$i}}));
105 $out.="$length,&(lvalues[$lvalues]),0";
106 $lvalues+=$length;
107 }
108 else
109 {
110 $out.="0,NULL";
111 }
112 $out.="},\n";
113 push(@out,$out);
114 }
115 }
116
117@a=grep(defined($sn{$nid{$_}}),0 .. $n);
118foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a)
119 {
120 push(@sn,sprintf("&(nid_objs[%2d]),/* $sn{$nid{$_}} */\n",$_));
121 }
122
123@a=grep(defined($ln{$nid{$_}}),0 .. $n);
124foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a)
125 {
126 push(@ln,sprintf("&(nid_objs[%2d]),/* $ln{$nid{$_}} */\n",$_));
127 }
128
129@a=grep(defined($obj{$nid{$_}}),0 .. $n);
130foreach (sort obj_cmp @a)
131 {
132 $m=$obj{$nid{$_}};
133 $v=$objd{$m};
134 $v =~ s/L//g;
135 $v =~ s/,/ /g;
136 push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v));
137 }
138
139print OUT <<'EOF';
140/* lib/obj/obj_dat.h */
141/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
142 * All rights reserved.
143 *
144 * This package is an SSL implementation written
145 * by Eric Young (eay@cryptsoft.com).
146 * The implementation was written so as to conform with Netscapes SSL.
147 *
148 * This library is free for commercial and non-commercial use as long as
149 * the following conditions are aheared to. The following conditions
150 * apply to all code found in this distribution, be it the RC4, RSA,
151 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
152 * included with this distribution is covered by the same copyright terms
153 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
154 *
155 * Copyright remains Eric Young's, and as such any Copyright notices in
156 * the code are not to be removed.
157 * If this package is used in a product, Eric Young should be given attribution
158 * as the author of the parts of the library used.
159 * This can be in the form of a textual message at program startup or
160 * in documentation (online or textual) provided with the package.
161 *
162 * Redistribution and use in source and binary forms, with or without
163 * modification, are permitted provided that the following conditions
164 * are met:
165 * 1. Redistributions of source code must retain the copyright
166 * notice, this list of conditions and the following disclaimer.
167 * 2. Redistributions in binary form must reproduce the above copyright
168 * notice, this list of conditions and the following disclaimer in the
169 * documentation and/or other materials provided with the distribution.
170 * 3. All advertising materials mentioning features or use of this software
171 * must display the following acknowledgement:
172 * "This product includes cryptographic software written by
173 * Eric Young (eay@cryptsoft.com)"
174 * The word 'cryptographic' can be left out if the rouines from the library
175 * being used are not cryptographic related :-).
176 * 4. If you include any Windows specific code (or a derivative thereof) from
177 * the apps directory (application code) you must include an acknowledgement:
178 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
179 *
180 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
181 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
183 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
184 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
185 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
186 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
187 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
188 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
189 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
190 * SUCH DAMAGE.
191 *
192 * The licence and distribution terms for any publically available version or
193 * derivative of this code cannot be changed. i.e. this code cannot simply be
194 * copied and put under another distribution licence
195 * [including the GNU Public Licence.]
196 */
197
198/* THIS FILE IS GENERATED FROM Objects.h by obj_dat.pl via the
199 * following command:
200 * perl obj_dat.pl objects.h obj_dat.h
201 */
202
203EOF
204
205printf OUT "#define NUM_NID %d\n",$n;
206printf OUT "#define NUM_SN %d\n",$#sn+1;
207printf OUT "#define NUM_LN %d\n",$#ln+1;
208printf OUT "#define NUM_OBJ %d\n\n",$#ob+1;
209
210printf OUT "static unsigned char lvalues[%d]={\n",$lvalues+1;
211print OUT @lvalues;
212print OUT "};\n\n";
213
214printf OUT "static ASN1_OBJECT nid_objs[NUM_NID]={\n";
215foreach (@out)
216 {
217 if (length($_) > 75)
218 {
219 $out="";
220 foreach (split(/,/))
221 {
222 $t=$out.$_.",";
223 if (length($t) > 70)
224 {
225 print OUT "$out\n";
226 $t="\t$_,";
227 }
228 $out=$t;
229 }
230 chop $out;
231 print OUT "$out";
232 }
233 else
234 { print OUT $_; }
235 }
236print OUT "};\n\n";
237
238printf OUT "static ASN1_OBJECT *sn_objs[NUM_SN]={\n";
239print OUT @sn;
240print OUT "};\n\n";
241
242printf OUT "static ASN1_OBJECT *ln_objs[NUM_LN]={\n";
243print OUT @ln;
244print OUT "};\n\n";
245
246printf OUT "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n";
247print OUT @ob;
248print OUT "};\n\n";
249
250close OUT;
251
252sub der_it
253 {
254 local($v)=@_;
255 local(@a,$i,$ret,@r);
256
257 @a=split(/\s+/,$v);
258 $ret.=pack("C*",$a[0]*40+$a[1]);
259 shift @a;
260 shift @a;
261 foreach (@a)
262 {
263 @r=();
264 $t=0;
265 while ($_ >= 128)
266 {
267 $x=$_%128;
268 $_/=128;
269 push(@r,((($t++)?0x80:0)|$x));
270 }
271 push(@r,((($t++)?0x80:0)|$_));
272 $ret.=pack("C*",reverse(@r));
273 }
274 return($ret);
275 }
diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c
deleted file mode 100644
index 7aec0ed47a..0000000000
--- a/src/lib/libcrypto/objects/obj_err.c
+++ /dev/null
@@ -1,99 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/objects.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA OBJ_str_functs[]=
68 {
69{ERR_PACK(0,OBJ_F_OBJ_CREATE,0), "OBJ_create"},
70{ERR_PACK(0,OBJ_F_OBJ_DUP,0), "OBJ_dup"},
71{ERR_PACK(0,OBJ_F_OBJ_NID2LN,0), "OBJ_nid2ln"},
72{ERR_PACK(0,OBJ_F_OBJ_NID2OBJ,0), "OBJ_nid2obj"},
73{ERR_PACK(0,OBJ_F_OBJ_NID2SN,0), "OBJ_nid2sn"},
74{0,NULL}
75 };
76
77static ERR_STRING_DATA OBJ_str_reasons[]=
78 {
79{OBJ_R_MALLOC_FAILURE ,"malloc failure"},
80{OBJ_R_UNKNOWN_NID ,"unknown nid"},
81{0,NULL}
82 };
83
84#endif
85
86void ERR_load_OBJ_strings(void)
87 {
88 static int init=1;
89
90 if (init)
91 {
92 init=0;
93#ifndef NO_ERR
94 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_functs);
95 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_reasons);
96#endif
97
98 }
99 }
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 95c8a21568..0000000000
--- a/src/lib/libcrypto/objects/objects.h
+++ /dev/null
@@ -1,1032 +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 SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES"
114#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
115#define NID_pbeWithMD2AndDES_CBC 9
116#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L
117
118#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES"
119#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
120#define NID_pbeWithMD5AndDES_CBC 10
121#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L
122
123#define LN_X500 "X500"
124#define NID_X500 11
125#define OBJ_X500 2L,5L
126
127#define LN_X509 "X509"
128#define NID_X509 12
129#define OBJ_X509 OBJ_X500,4L
130
131#define SN_commonName "CN"
132#define LN_commonName "commonName"
133#define NID_commonName 13
134#define OBJ_commonName OBJ_X509,3L
135
136#define SN_countryName "C"
137#define LN_countryName "countryName"
138#define NID_countryName 14
139#define OBJ_countryName OBJ_X509,6L
140
141#define SN_localityName "L"
142#define LN_localityName "localityName"
143#define NID_localityName 15
144#define OBJ_localityName OBJ_X509,7L
145
146/* Postal Address? PA */
147
148/* should be "ST" (rfc1327) but MS uses 'S' */
149#define SN_stateOrProvinceName "ST"
150#define LN_stateOrProvinceName "stateOrProvinceName"
151#define NID_stateOrProvinceName 16
152#define OBJ_stateOrProvinceName OBJ_X509,8L
153
154#define SN_organizationName "O"
155#define LN_organizationName "organizationName"
156#define NID_organizationName 17
157#define OBJ_organizationName OBJ_X509,10L
158
159#define SN_organizationalUnitName "OU"
160#define LN_organizationalUnitName "organizationalUnitName"
161#define NID_organizationalUnitName 18
162#define OBJ_organizationalUnitName OBJ_X509,11L
163
164#define SN_rsa "RSA"
165#define LN_rsa "rsa"
166#define NID_rsa 19
167#define OBJ_rsa OBJ_X500,8L,1L,1L
168
169#define LN_pkcs7 "pkcs7"
170#define NID_pkcs7 20
171#define OBJ_pkcs7 OBJ_pkcs,7L
172
173#define LN_pkcs7_data "pkcs7-data"
174#define NID_pkcs7_data 21
175#define OBJ_pkcs7_data OBJ_pkcs7,1L
176
177#define LN_pkcs7_signed "pkcs7-signedData"
178#define NID_pkcs7_signed 22
179#define OBJ_pkcs7_signed OBJ_pkcs7,2L
180
181#define LN_pkcs7_enveloped "pkcs7-envelopedData"
182#define NID_pkcs7_enveloped 23
183#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L
184
185#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData"
186#define NID_pkcs7_signedAndEnveloped 24
187#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L
188
189#define LN_pkcs7_digest "pkcs7-digestData"
190#define NID_pkcs7_digest 25
191#define OBJ_pkcs7_digest OBJ_pkcs7,5L
192
193#define LN_pkcs7_encrypted "pkcs7-encryptedData"
194#define NID_pkcs7_encrypted 26
195#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L
196
197#define LN_pkcs3 "pkcs3"
198#define NID_pkcs3 27
199#define OBJ_pkcs3 OBJ_pkcs,3L
200
201#define LN_dhKeyAgreement "dhKeyAgreement"
202#define NID_dhKeyAgreement 28
203#define OBJ_dhKeyAgreement OBJ_pkcs3,1L
204
205#define SN_des_ecb "DES-ECB"
206#define LN_des_ecb "des-ecb"
207#define NID_des_ecb 29
208#define OBJ_des_ecb OBJ_algorithm,6L
209
210#define SN_des_cfb64 "DES-CFB"
211#define LN_des_cfb64 "des-cfb"
212#define NID_des_cfb64 30
213/* IV + num */
214#define OBJ_des_cfb64 OBJ_algorithm,9L
215
216#define SN_des_cbc "DES-CBC"
217#define LN_des_cbc "des-cbc"
218#define NID_des_cbc 31
219/* IV */
220#define OBJ_des_cbc OBJ_algorithm,7L
221
222#define SN_des_ede "DES-EDE"
223#define LN_des_ede "des-ede"
224#define NID_des_ede 32
225/* ?? */
226#define OBJ_des_ede OBJ_algorithm,17L
227
228#define SN_des_ede3 "DES-EDE3"
229#define LN_des_ede3 "des-ede3"
230#define NID_des_ede3 33
231
232#define SN_idea_cbc "IDEA-CBC"
233#define LN_idea_cbc "idea-cbc"
234#define NID_idea_cbc 34
235#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L
236
237#define SN_idea_cfb64 "IDEA-CFB"
238#define LN_idea_cfb64 "idea-cfb"
239#define NID_idea_cfb64 35
240
241#define SN_idea_ecb "IDEA-ECB"
242#define LN_idea_ecb "idea-ecb"
243#define NID_idea_ecb 36
244
245#define SN_rc2_cbc "RC2-CBC"
246#define LN_rc2_cbc "rc2-cbc"
247#define NID_rc2_cbc 37
248#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L
249
250#define SN_rc2_ecb "RC2-ECB"
251#define LN_rc2_ecb "rc2-ecb"
252#define NID_rc2_ecb 38
253
254#define SN_rc2_cfb64 "RC2-CFB"
255#define LN_rc2_cfb64 "rc2-cfb"
256#define NID_rc2_cfb64 39
257
258#define SN_rc2_ofb64 "RC2-OFB"
259#define LN_rc2_ofb64 "rc2-ofb"
260#define NID_rc2_ofb64 40
261
262#define SN_sha "SHA"
263#define LN_sha "sha"
264#define NID_sha 41
265#define OBJ_sha OBJ_algorithm,18L
266
267#define SN_shaWithRSAEncryption "RSA-SHA"
268#define LN_shaWithRSAEncryption "shaWithRSAEncryption"
269#define NID_shaWithRSAEncryption 42
270#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L
271
272#define SN_des_ede_cbc "DES-EDE-CBC"
273#define LN_des_ede_cbc "des-ede-cbc"
274#define NID_des_ede_cbc 43
275
276#define SN_des_ede3_cbc "DES-EDE3-CBC"
277#define LN_des_ede3_cbc "des-ede3-cbc"
278#define NID_des_ede3_cbc 44
279#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L
280
281#define SN_des_ofb64 "DES-OFB"
282#define LN_des_ofb64 "des-ofb"
283#define NID_des_ofb64 45
284#define OBJ_des_ofb64 OBJ_algorithm,8L
285
286#define SN_idea_ofb64 "IDEA-OFB"
287#define LN_idea_ofb64 "idea-ofb"
288#define NID_idea_ofb64 46
289
290#define LN_pkcs9 "pkcs9"
291#define NID_pkcs9 47
292#define OBJ_pkcs9 OBJ_pkcs,9L
293
294#define SN_pkcs9_emailAddress "Email"
295#define LN_pkcs9_emailAddress "emailAddress"
296#define NID_pkcs9_emailAddress 48
297#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L
298
299#define LN_pkcs9_unstructuredName "unstructuredName"
300#define NID_pkcs9_unstructuredName 49
301#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L
302
303#define LN_pkcs9_contentType "contentType"
304#define NID_pkcs9_contentType 50
305#define OBJ_pkcs9_contentType OBJ_pkcs9,3L
306
307#define LN_pkcs9_messageDigest "messageDigest"
308#define NID_pkcs9_messageDigest 51
309#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L
310
311#define LN_pkcs9_signingTime "signingTime"
312#define NID_pkcs9_signingTime 52
313#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L
314
315#define LN_pkcs9_countersignature "countersignature"
316#define NID_pkcs9_countersignature 53
317#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L
318
319#define LN_pkcs9_challengePassword "challengePassword"
320#define NID_pkcs9_challengePassword 54
321#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L
322
323#define LN_pkcs9_unstructuredAddress "unstructuredAddress"
324#define NID_pkcs9_unstructuredAddress 55
325#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L
326
327#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes"
328#define NID_pkcs9_extCertAttributes 56
329#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L
330
331#define SN_netscape "Netscape"
332#define LN_netscape "Netscape Communications Corp."
333#define NID_netscape 57
334#define OBJ_netscape 2L,16L,840L,1L,113730L
335
336#define SN_netscape_cert_extension "nsCertExt"
337#define LN_netscape_cert_extension "Netscape Certificate Extension"
338#define NID_netscape_cert_extension 58
339#define OBJ_netscape_cert_extension OBJ_netscape,1L
340
341#define SN_netscape_data_type "nsDataType"
342#define LN_netscape_data_type "Netscape Data Type"
343#define NID_netscape_data_type 59
344#define OBJ_netscape_data_type OBJ_netscape,2L
345
346#define SN_des_ede_cfb64 "DES-EDE-CFB"
347#define LN_des_ede_cfb64 "des-ede-cfb"
348#define NID_des_ede_cfb64 60
349
350#define SN_des_ede3_cfb64 "DES-EDE3-CFB"
351#define LN_des_ede3_cfb64 "des-ede3-cfb"
352#define NID_des_ede3_cfb64 61
353
354#define SN_des_ede_ofb64 "DES-EDE-OFB"
355#define LN_des_ede_ofb64 "des-ede-ofb"
356#define NID_des_ede_ofb64 62
357
358#define SN_des_ede3_ofb64 "DES-EDE3-OFB"
359#define LN_des_ede3_ofb64 "des-ede3-ofb"
360#define NID_des_ede3_ofb64 63
361
362/* I'm not sure about the object ID */
363#define SN_sha1 "SHA1"
364#define LN_sha1 "sha1"
365#define NID_sha1 64
366#define OBJ_sha1 OBJ_algorithm,26L
367/* 28 Jun 1996 - eay */
368/* #define OBJ_sha1 1L,3L,14L,2L,26L,05L <- wrong */
369
370#define SN_sha1WithRSAEncryption "RSA-SHA1"
371#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption"
372#define NID_sha1WithRSAEncryption 65
373#define OBJ_sha1WithRSAEncryption OBJ_pkcs,1L,5L
374
375#define SN_dsaWithSHA "DSA-SHA"
376#define LN_dsaWithSHA "dsaWithSHA"
377#define NID_dsaWithSHA 66
378#define OBJ_dsaWithSHA OBJ_algorithm,13L
379
380#define SN_dsa_2 "DSA-old"
381#define LN_dsa_2 "dsaEncryption-old"
382#define NID_dsa_2 67
383#define OBJ_dsa_2 OBJ_algorithm,12L
384
385/* proposed by microsoft to RSA */
386#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
387#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
388#define NID_pbeWithSHA1AndRC2_CBC 68
389#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
390
391/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now
392 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something
393 * completely different.
394 */
395#define LN_id_pbkdf2 "PBKDF2"
396#define NID_id_pbkdf2 69
397#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L
398
399#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
400#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
401#define NID_dsaWithSHA1_2 70
402/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */
403#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
404
405#define SN_netscape_cert_type "nsCertType"
406#define LN_netscape_cert_type "Netscape Cert Type"
407#define NID_netscape_cert_type 71
408#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L
409
410#define SN_netscape_base_url "nsBaseUrl"
411#define LN_netscape_base_url "Netscape Base Url"
412#define NID_netscape_base_url 72
413#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L
414
415#define SN_netscape_revocation_url "nsRevocationUrl"
416#define LN_netscape_revocation_url "Netscape Revocation Url"
417#define NID_netscape_revocation_url 73
418#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L
419
420#define SN_netscape_ca_revocation_url "nsCaRevocationUrl"
421#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url"
422#define NID_netscape_ca_revocation_url 74
423#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L
424
425#define SN_netscape_renewal_url "nsRenewalUrl"
426#define LN_netscape_renewal_url "Netscape Renewal Url"
427#define NID_netscape_renewal_url 75
428#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L
429
430#define SN_netscape_ca_policy_url "nsCaPolicyUrl"
431#define LN_netscape_ca_policy_url "Netscape CA Policy Url"
432#define NID_netscape_ca_policy_url 76
433#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L
434
435#define SN_netscape_ssl_server_name "nsSslServerName"
436#define LN_netscape_ssl_server_name "Netscape SSL Server Name"
437#define NID_netscape_ssl_server_name 77
438#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L
439
440#define SN_netscape_comment "nsComment"
441#define LN_netscape_comment "Netscape Comment"
442#define NID_netscape_comment 78
443#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L
444
445#define SN_netscape_cert_sequence "nsCertSequence"
446#define LN_netscape_cert_sequence "Netscape Certificate Sequence"
447#define NID_netscape_cert_sequence 79
448#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L
449
450#define SN_desx_cbc "DESX-CBC"
451#define LN_desx_cbc "desx-cbc"
452#define NID_desx_cbc 80
453
454#define SN_ld_ce "ld-ce"
455#define NID_ld_ce 81
456#define OBJ_ld_ce 2L,5L,29L
457
458#define SN_subject_key_identifier "subjectKeyIdentifier"
459#define LN_subject_key_identifier "X509v3 Subject Key Identifier"
460#define NID_subject_key_identifier 82
461#define OBJ_subject_key_identifier OBJ_ld_ce,14L
462
463#define SN_key_usage "keyUsage"
464#define LN_key_usage "X509v3 Key Usage"
465#define NID_key_usage 83
466#define OBJ_key_usage OBJ_ld_ce,15L
467
468#define SN_private_key_usage_period "privateKeyUsagePeriod"
469#define LN_private_key_usage_period "X509v3 Private Key Usage Period"
470#define NID_private_key_usage_period 84
471#define OBJ_private_key_usage_period OBJ_ld_ce,16L
472
473#define SN_subject_alt_name "subjectAltName"
474#define LN_subject_alt_name "X509v3 Subject Alternative Name"
475#define NID_subject_alt_name 85
476#define OBJ_subject_alt_name OBJ_ld_ce,17L
477
478#define SN_issuer_alt_name "issuerAltName"
479#define LN_issuer_alt_name "X509v3 Issuer Alternative Name"
480#define NID_issuer_alt_name 86
481#define OBJ_issuer_alt_name OBJ_ld_ce,18L
482
483#define SN_basic_constraints "basicConstraints"
484#define LN_basic_constraints "X509v3 Basic Constraints"
485#define NID_basic_constraints 87
486#define OBJ_basic_constraints OBJ_ld_ce,19L
487
488#define SN_crl_number "crlNumber"
489#define LN_crl_number "X509v3 CRL Number"
490#define NID_crl_number 88
491#define OBJ_crl_number OBJ_ld_ce,20L
492
493#define SN_certificate_policies "certificatePolicies"
494#define LN_certificate_policies "X509v3 Certificate Policies"
495#define NID_certificate_policies 89
496#define OBJ_certificate_policies OBJ_ld_ce,32L
497
498#define SN_authority_key_identifier "authorityKeyIdentifier"
499#define LN_authority_key_identifier "X509v3 Authority Key Identifier"
500#define NID_authority_key_identifier 90
501#define OBJ_authority_key_identifier OBJ_ld_ce,35L
502
503#define SN_bf_cbc "BF-CBC"
504#define LN_bf_cbc "bf-cbc"
505#define NID_bf_cbc 91
506#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L
507
508#define SN_bf_ecb "BF-ECB"
509#define LN_bf_ecb "bf-ecb"
510#define NID_bf_ecb 92
511
512#define SN_bf_cfb64 "BF-CFB"
513#define LN_bf_cfb64 "bf-cfb"
514#define NID_bf_cfb64 93
515
516#define SN_bf_ofb64 "BF-OFB"
517#define LN_bf_ofb64 "bf-ofb"
518#define NID_bf_ofb64 94
519
520#define SN_mdc2 "MDC2"
521#define LN_mdc2 "mdc2"
522#define NID_mdc2 95
523#define OBJ_mdc2 2L,5L,8L,3L,101L
524/* An alternative? 1L,3L,14L,3L,2L,19L */
525
526#define SN_mdc2WithRSA "RSA-MDC2"
527#define LN_mdc2WithRSA "mdc2withRSA"
528#define NID_mdc2WithRSA 96
529#define OBJ_mdc2WithRSA 2L,5L,8L,3L,100L
530
531#define SN_rc4_40 "RC4-40"
532#define LN_rc4_40 "rc4-40"
533#define NID_rc4_40 97
534
535#define SN_rc2_40_cbc "RC2-40-CBC"
536#define LN_rc2_40_cbc "rc2-40-cbc"
537#define NID_rc2_40_cbc 98
538
539#define SN_givenName "G"
540#define LN_givenName "givenName"
541#define NID_givenName 99
542#define OBJ_givenName OBJ_X509,42L
543
544#define SN_surname "S"
545#define LN_surname "surname"
546#define NID_surname 100
547#define OBJ_surname OBJ_X509,4L
548
549#define SN_initials "I"
550#define LN_initials "initials"
551#define NID_initials 101
552#define OBJ_initials OBJ_X509,43L
553
554#define SN_uniqueIdentifier "UID"
555#define LN_uniqueIdentifier "uniqueIdentifier"
556#define NID_uniqueIdentifier 102
557#define OBJ_uniqueIdentifier OBJ_X509,45L
558
559#define SN_crl_distribution_points "crlDistributionPoints"
560#define LN_crl_distribution_points "X509v3 CRL Distribution Points"
561#define NID_crl_distribution_points 103
562#define OBJ_crl_distribution_points OBJ_ld_ce,31L
563
564#define SN_md5WithRSA "RSA-NP-MD5"
565#define LN_md5WithRSA "md5WithRSA"
566#define NID_md5WithRSA 104
567#define OBJ_md5WithRSA OBJ_algorithm,3L
568
569#define SN_serialNumber "SN"
570#define LN_serialNumber "serialNumber"
571#define NID_serialNumber 105
572#define OBJ_serialNumber OBJ_X509,5L
573
574#define SN_title "T"
575#define LN_title "title"
576#define NID_title 106
577#define OBJ_title OBJ_X509,12L
578
579#define SN_description "D"
580#define LN_description "description"
581#define NID_description 107
582#define OBJ_description OBJ_X509,13L
583
584/* CAST5 is CAST-128, I'm just sticking with the documentation */
585#define SN_cast5_cbc "CAST5-CBC"
586#define LN_cast5_cbc "cast5-cbc"
587#define NID_cast5_cbc 108
588#define OBJ_cast5_cbc 1L,2L,840L,113533L,7L,66L,10L
589
590#define SN_cast5_ecb "CAST5-ECB"
591#define LN_cast5_ecb "cast5-ecb"
592#define NID_cast5_ecb 109
593
594#define SN_cast5_cfb64 "CAST5-CFB"
595#define LN_cast5_cfb64 "cast5-cfb"
596#define NID_cast5_cfb64 110
597
598#define SN_cast5_ofb64 "CAST5-OFB"
599#define LN_cast5_ofb64 "cast5-ofb"
600#define NID_cast5_ofb64 111
601
602#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC"
603#define NID_pbeWithMD5AndCast5_CBC 112
604#define OBJ_pbeWithMD5AndCast5_CBC 1L,2L,840L,113533L,7L,66L,12L
605
606/* This is one sun will soon be using :-(
607 * id-dsa-with-sha1 ID ::= {
608 * iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 }
609 */
610#define SN_dsaWithSHA1 "DSA-SHA1"
611#define LN_dsaWithSHA1 "dsaWithSHA1"
612#define NID_dsaWithSHA1 113
613#define OBJ_dsaWithSHA1 1L,2L,840L,10040L,4L,3L
614
615#define NID_md5_sha1 114
616#define SN_md5_sha1 "MD5-SHA1"
617#define LN_md5_sha1 "md5-sha1"
618
619#define SN_sha1WithRSA "RSA-SHA1-2"
620#define LN_sha1WithRSA "sha1WithRSA"
621#define NID_sha1WithRSA 115
622#define OBJ_sha1WithRSA OBJ_algorithm,29L
623
624#define SN_dsa "DSA"
625#define LN_dsa "dsaEncryption"
626#define NID_dsa 116
627#define OBJ_dsa 1L,2L,840L,10040L,4L,1L
628
629#define SN_ripemd160 "RIPEMD160"
630#define LN_ripemd160 "ripemd160"
631#define NID_ripemd160 117
632#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
633
634/* The name should actually be rsaSignatureWithripemd160, but I'm going
635 * to continue using the convention I'm using with the other ciphers */
636#define SN_ripemd160WithRSA "RSA-RIPEMD160"
637#define LN_ripemd160WithRSA "ripemd160WithRSA"
638#define NID_ripemd160WithRSA 119
639#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L
640
641/* Taken from rfc2040
642 * RC5_CBC_Parameters ::= SEQUENCE {
643 * version INTEGER (v1_0(16)),
644 * rounds INTEGER (8..127),
645 * blockSizeInBits INTEGER (64, 128),
646 * iv OCTET STRING OPTIONAL
647 * }
648 */
649#define SN_rc5_cbc "RC5-CBC"
650#define LN_rc5_cbc "rc5-cbc"
651#define NID_rc5_cbc 120
652#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L
653
654#define SN_rc5_ecb "RC5-ECB"
655#define LN_rc5_ecb "rc5-ecb"
656#define NID_rc5_ecb 121
657
658#define SN_rc5_cfb64 "RC5-CFB"
659#define LN_rc5_cfb64 "rc5-cfb"
660#define NID_rc5_cfb64 122
661
662#define SN_rc5_ofb64 "RC5-OFB"
663#define LN_rc5_ofb64 "rc5-ofb"
664#define NID_rc5_ofb64 123
665
666#define SN_rle_compression "RLE"
667#define LN_rle_compression "run length compression"
668#define NID_rle_compression 124
669#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L
670
671#define SN_zlib_compression "ZLIB"
672#define LN_zlib_compression "zlib compression"
673#define NID_zlib_compression 125
674#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L
675
676#define SN_ext_key_usage "extendedKeyUsage"
677#define LN_ext_key_usage "X509v3 Extended Key Usage"
678#define NID_ext_key_usage 126
679#define OBJ_ext_key_usage OBJ_ld_ce,37
680
681#define SN_id_pkix "PKIX"
682#define NID_id_pkix 127
683#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L
684
685#define SN_id_kp "id-kp"
686#define NID_id_kp 128
687#define OBJ_id_kp OBJ_id_pkix,3L
688
689/* PKIX extended key usage OIDs */
690
691#define SN_server_auth "serverAuth"
692#define LN_server_auth "TLS Web Server Authentication"
693#define NID_server_auth 129
694#define OBJ_server_auth OBJ_id_kp,1L
695
696#define SN_client_auth "clientAuth"
697#define LN_client_auth "TLS Web Client Authentication"
698#define NID_client_auth 130
699#define OBJ_client_auth OBJ_id_kp,2L
700
701#define SN_code_sign "codeSigning"
702#define LN_code_sign "Code Signing"
703#define NID_code_sign 131
704#define OBJ_code_sign OBJ_id_kp,3L
705
706#define SN_email_protect "emailProtection"
707#define LN_email_protect "E-mail Protection"
708#define NID_email_protect 132
709#define OBJ_email_protect OBJ_id_kp,4L
710
711#define SN_time_stamp "timeStamping"
712#define LN_time_stamp "Time Stamping"
713#define NID_time_stamp 133
714#define OBJ_time_stamp OBJ_id_kp,8L
715
716/* Additional extended key usage OIDs: Microsoft */
717
718#define SN_ms_code_ind "msCodeInd"
719#define LN_ms_code_ind "Microsoft Individual Code Signing"
720#define NID_ms_code_ind 134
721#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
722
723#define SN_ms_code_com "msCodeCom"
724#define LN_ms_code_com "Microsoft Commercial Code Signing"
725#define NID_ms_code_com 135
726#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
727
728#define SN_ms_ctl_sign "msCTLSign"
729#define LN_ms_ctl_sign "Microsoft Trust List Signing"
730#define NID_ms_ctl_sign 136
731#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
732
733#define SN_ms_sgc "msSGC"
734#define LN_ms_sgc "Microsoft Server Gated Crypto"
735#define NID_ms_sgc 137
736#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
737
738#define SN_ms_efs "msEFS"
739#define LN_ms_efs "Microsoft Encrypted File System"
740#define NID_ms_efs 138
741#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
742
743/* Additional usage: Netscape */
744
745#define SN_ns_sgc "nsSGC"
746#define LN_ns_sgc "Netscape Server Gated Crypto"
747#define NID_ns_sgc 139
748#define OBJ_ns_sgc OBJ_netscape,4L,1L
749
750#define SN_delta_crl "deltaCRL"
751#define LN_delta_crl "X509v3 Delta CRL Indicator"
752#define NID_delta_crl 140
753#define OBJ_delta_crl OBJ_ld_ce,27L
754
755#define SN_crl_reason "CRLReason"
756#define LN_crl_reason "CRL Reason Code"
757#define NID_crl_reason 141
758#define OBJ_crl_reason OBJ_ld_ce,21L
759
760#define SN_invalidity_date "invalidityDate"
761#define LN_invalidity_date "Invalidity Date"
762#define NID_invalidity_date 142
763#define OBJ_invalidity_date OBJ_ld_ce,24L
764
765#define SN_sxnet "SXNetID"
766#define LN_sxnet "Strong Extranet ID"
767#define NID_sxnet 143
768#define OBJ_sxnet 1L,3L,101L,1L,4L,1L
769
770/* PKCS12 and related OBJECT IDENTIFIERS */
771
772#define OBJ_pkcs12 OBJ_pkcs,12L
773#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1
774
775#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128"
776#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
777#define NID_pbe_WithSHA1And128BitRC4 144
778#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L
779
780#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40"
781#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
782#define NID_pbe_WithSHA1And40BitRC4 145
783#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L
784
785#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES"
786#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
787#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
788#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L
789
790#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES"
791#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
792#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
793#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L
794
795#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128"
796#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
797#define NID_pbe_WithSHA1And128BitRC2_CBC 148
798#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L
799
800#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40"
801#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
802#define NID_pbe_WithSHA1And40BitRC2_CBC 149
803#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L
804
805#define OBJ_pkcs12_Version1 OBJ_pkcs12, 10L
806
807#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1, 1L
808
809#define LN_keyBag "keyBag"
810#define NID_keyBag 150
811#define OBJ_keyBag OBJ_pkcs12_BagIds, 1L
812
813#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"
814#define NID_pkcs8ShroudedKeyBag 151
815#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds, 2L
816
817#define LN_certBag "certBag"
818#define NID_certBag 152
819#define OBJ_certBag OBJ_pkcs12_BagIds, 3L
820
821#define LN_crlBag "crlBag"
822#define NID_crlBag 153
823#define OBJ_crlBag OBJ_pkcs12_BagIds, 4L
824
825#define LN_secretBag "secretBag"
826#define NID_secretBag 154
827#define OBJ_secretBag OBJ_pkcs12_BagIds, 5L
828
829#define LN_safeContentsBag "safeContentsBag"
830#define NID_safeContentsBag 155
831#define OBJ_safeContentsBag OBJ_pkcs12_BagIds, 6L
832
833#define LN_friendlyName "friendlyName"
834#define NID_friendlyName 156
835#define OBJ_friendlyName OBJ_pkcs9, 20L
836
837#define LN_localKeyID "localKeyID"
838#define NID_localKeyID 157
839#define OBJ_localKeyID OBJ_pkcs9, 21L
840
841#define OBJ_certTypes OBJ_pkcs9, 22L
842
843#define LN_x509Certificate "x509Certificate"
844#define NID_x509Certificate 158
845#define OBJ_x509Certificate OBJ_certTypes, 1L
846
847#define LN_sdsiCertificate "sdsiCertificate"
848#define NID_sdsiCertificate 159
849#define OBJ_sdsiCertificate OBJ_certTypes, 2L
850
851#define OBJ_crlTypes OBJ_pkcs9, 23L
852
853#define LN_x509Crl "x509Crl"
854#define NID_x509Crl 160
855#define OBJ_x509Crl OBJ_crlTypes, 1L
856
857/* PKCS#5 v2 OIDs */
858
859#define LN_pbes2 "PBES2"
860#define NID_pbes2 161
861#define OBJ_pbes2 OBJ_pkcs,5L,13L
862
863#define LN_pbmac1 "PBMAC1"
864#define NID_pbmac1 162
865#define OBJ_pbmac1 OBJ_pkcs,5L,14L
866
867#define LN_hmacWithSHA1 "hmacWithSHA1"
868#define NID_hmacWithSHA1 163
869#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L
870
871/* Policy Qualifier Ids */
872
873#define LN_id_qt_cps "Policy Qualifier CPS"
874#define SN_id_qt_cps "id-qt-cps"
875#define NID_id_qt_cps 164
876#define OBJ_id_qt_cps OBJ_id_pkix,2L,1L
877
878#define LN_id_qt_unotice "Policy Qualifier User Notice"
879#define SN_id_qt_unotice "id-qt-unotice"
880#define NID_id_qt_unotice 165
881#define OBJ_id_qt_unotice OBJ_id_pkix,2L,2L
882
883#define SN_rc2_64_cbc "RC2-64-CBC"
884#define LN_rc2_64_cbc "rc2-64-cbc"
885#define NID_rc2_64_cbc 166
886
887#define SN_SMIMECapabilities "SMIME-CAPS"
888#define LN_SMIMECapabilities "S/MIME Capabilities"
889#define NID_SMIMECapabilities 167
890#define OBJ_SMIMECapabilities OBJ_pkcs9,15L
891
892#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64"
893#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
894#define NID_pbeWithMD2AndRC2_CBC 168
895#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L
896
897#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64"
898#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
899#define NID_pbeWithMD5AndRC2_CBC 169
900#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L
901
902#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES"
903#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
904#define NID_pbeWithSHA1AndDES_CBC 170
905#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L
906
907/* Extension request OIDs */
908
909#define LN_ms_ext_req "Microsoft Extension Request"
910#define SN_ms_ext_req "msExtReq"
911#define NID_ms_ext_req 171
912#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L
913
914#define LN_ext_req "Extension Request"
915#define SN_ext_req "extReq"
916#define NID_ext_req 172
917#define OBJ_ext_req OBJ_pkcs9,14L
918
919#define SN_name "name"
920#define LN_name "name"
921#define NID_name 173
922#define OBJ_name OBJ_X509,41L
923
924#define SN_dnQualifier "dnQualifier"
925#define LN_dnQualifier "dnQualifier"
926#define NID_dnQualifier 174
927#define OBJ_dnQualifier OBJ_X509,46L
928
929#define SN_id_pe "id-pe"
930#define NID_id_pe 175
931#define OBJ_id_pe OBJ_id_pkix,1L
932
933#define SN_id_ad "id-ad"
934#define NID_id_ad 176
935#define OBJ_id_ad OBJ_id_pkix,48L
936
937#define SN_info_access "authorityInfoAccess"
938#define LN_info_access "Authority Information Access"
939#define NID_info_access 177
940#define OBJ_info_access OBJ_id_pe,1L
941
942#define SN_ad_OCSP "OCSP"
943#define LN_ad_OCSP "OCSP"
944#define NID_ad_OCSP 178
945#define OBJ_ad_OCSP OBJ_id_ad,1L
946
947#define SN_ad_ca_issuers "caIssuers"
948#define LN_ad_ca_issuers "CA Issuers"
949#define NID_ad_ca_issuers 179
950#define OBJ_ad_ca_issuers OBJ_id_ad,2L
951
952#define SN_OCSP_sign "OCSPSigning"
953#define LN_OCSP_sign "OCSP Signing"
954#define NID_OCSP_sign 180
955#define OBJ_OCSP_sign OBJ_id_kp,9L
956
957#include <openssl/bio.h>
958#include <openssl/asn1.h>
959
960#define OBJ_NAME_TYPE_UNDEF 0x00
961#define OBJ_NAME_TYPE_MD_METH 0x01
962#define OBJ_NAME_TYPE_CIPHER_METH 0x02
963#define OBJ_NAME_TYPE_PKEY_METH 0x03
964#define OBJ_NAME_TYPE_COMP_METH 0x04
965#define OBJ_NAME_TYPE_NUM 0x05
966
967#define OBJ_NAME_ALIAS 0x8000
968
969
970typedef struct obj_name_st
971 {
972 int type;
973 int alias;
974 const char *name;
975 const char *data;
976 } OBJ_NAME;
977
978#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
979
980
981int OBJ_NAME_init(void);
982int OBJ_NAME_new_index(unsigned long (*hash_func)(),int (*cmp_func)(),
983 void (*free_func)());
984const char *OBJ_NAME_get(const char *name,int type);
985int OBJ_NAME_add(const char *name,int type,const char *data);
986int OBJ_NAME_remove(const char *name,int type);
987void OBJ_NAME_cleanup(int type); /* -1 for everything */
988
989ASN1_OBJECT * OBJ_dup(ASN1_OBJECT *o);
990ASN1_OBJECT * OBJ_nid2obj(int n);
991const char * OBJ_nid2ln(int n);
992const char * OBJ_nid2sn(int n);
993int OBJ_obj2nid(ASN1_OBJECT *o);
994ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
995int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name);
996int OBJ_txt2nid(char *s);
997int OBJ_ln2nid(const char *s);
998int OBJ_sn2nid(const char *s);
999int OBJ_cmp(ASN1_OBJECT *a,ASN1_OBJECT *b);
1000char * OBJ_bsearch(char *key,char *base,int num,int size,int (*cmp)());
1001
1002void ERR_load_OBJ_strings(void );
1003
1004int OBJ_new_nid(int num);
1005int OBJ_add_object(ASN1_OBJECT *obj);
1006int OBJ_create(char *oid,char *sn,char *ln);
1007void OBJ_cleanup(void );
1008int OBJ_create_objects(BIO *in);
1009
1010/* BEGIN ERROR CODES */
1011/* The following lines are auto generated by the script mkerr.pl. Any changes
1012 * made after this point may be overwritten when the script is next run.
1013 */
1014
1015/* Error codes for the OBJ functions. */
1016
1017/* Function codes. */
1018#define OBJ_F_OBJ_CREATE 100
1019#define OBJ_F_OBJ_DUP 101
1020#define OBJ_F_OBJ_NID2LN 102
1021#define OBJ_F_OBJ_NID2OBJ 103
1022#define OBJ_F_OBJ_NID2SN 104
1023
1024/* Reason codes. */
1025#define OBJ_R_MALLOC_FAILURE 100
1026#define OBJ_R_UNKNOWN_NID 101
1027
1028#ifdef __cplusplus
1029}
1030#endif
1031#endif
1032
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 55ec97389f..0000000000
--- a/src/lib/libcrypto/opensslv.h
+++ /dev/null
@@ -1,32 +0,0 @@
1#ifndef HEADER_OPENSSLV_H
2#define HEADER_OPENSSLV_H
3
4/* Numeric release version identifier:
5 * MMNNFFPPS: major minor fix patch status
6 * The status nibble has one of the values 0 for development, 1 to e for betas
7 * 1 to 14, and f for release. The patch level is exactly that.
8 * For example:
9 * 0.9.3-dev 0x00903000
10 * 0.9.3-beta1 0x00903001
11 * 0.9.3-beta2-dev 0x00903002
12 * 0.9.3-beta2 0x00903002 (same as ...beta2-dev)
13 * 0.9.3 0x0090300f
14 * 0.9.3a 0x0090301f
15 * 0.9.4 0x0090400f
16 * 1.2.3z 0x102031af
17 *
18 * For continuity reasons (because 0.9.5 is already out, and is coded
19 * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level
20 * part is slightly different, by setting the highest bit. This means
21 * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start
22 * with 0x0090600S...
23 *
24 * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.)
25 * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
26 * major minor fix final patch/beta)
27 */
28#define OPENSSL_VERSION_NUMBER 0x0090581fL
29#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.5a 1 Apr 2000"
30#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
31
32#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 e4bae0b4aa..0000000000
--- a/src/lib/libcrypto/pem/pem.h
+++ /dev/null
@@ -1,663 +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_TRUSTED "TRUSTED CERTIFICATE"
107#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
108#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
109#define PEM_STRING_X509_CRL "X509 CRL"
110#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
111#define PEM_STRING_PUBLIC "PUBLIC KEY"
112#define PEM_STRING_RSA "RSA PRIVATE KEY"
113#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
114#define PEM_STRING_DSA "DSA PRIVATE KEY"
115#define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
116#define PEM_STRING_PKCS7 "PKCS7"
117#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
118#define PEM_STRING_PKCS8INF "PRIVATE KEY"
119#define PEM_STRING_DHPARAMS "DH PARAMETERS"
120#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
121#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
122
123
124typedef struct PEM_Encode_Seal_st
125 {
126 EVP_ENCODE_CTX encode;
127 EVP_MD_CTX md;
128 EVP_CIPHER_CTX cipher;
129 } PEM_ENCODE_SEAL_CTX;
130
131/* enc_type is one off */
132#define PEM_TYPE_ENCRYPTED 10
133#define PEM_TYPE_MIC_ONLY 20
134#define PEM_TYPE_MIC_CLEAR 30
135#define PEM_TYPE_CLEAR 40
136
137typedef struct pem_recip_st
138 {
139 char *name;
140 X509_NAME *dn;
141
142 int cipher;
143 int key_enc;
144 char iv[8];
145 } PEM_USER;
146
147typedef struct pem_ctx_st
148 {
149 int type; /* what type of object */
150
151 struct {
152 int version;
153 int mode;
154 } proc_type;
155
156 char *domain;
157
158 struct {
159 int cipher;
160 unsigned char iv[8];
161 } DEK_info;
162
163 PEM_USER *originator;
164
165 int num_recipient;
166 PEM_USER **recipient;
167
168#ifdef HEADER_STACK_H
169 STACK *x509_chain; /* certificate chain */
170#else
171 char *x509_chain; /* certificate chain */
172#endif
173 EVP_MD *md; /* signature type */
174
175 int md_enc; /* is the md encrypted or not? */
176 int md_len; /* length of md_data */
177 char *md_data; /* message digest, could be pkey encrypted */
178
179 EVP_CIPHER *dec; /* date encryption cipher */
180 int key_len; /* key length */
181 unsigned char *key; /* key */
182 unsigned char iv[8]; /* the iv */
183
184
185 int data_enc; /* is the data encrypted */
186 int data_len;
187 unsigned char *data;
188 } PEM_CTX;
189
190/* These macros make the PEM_read/PEM_write functions easier to maintain and
191 * write. Now they are all implemented with either:
192 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
193 */
194
195#ifdef NO_FP_API
196
197#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
198#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
199#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
200
201#else
202
203#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
204type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
205{ \
206return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
207 cb,u)); \
208} \
209
210#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
211int PEM_write_##name(FILE *fp, type *x) \
212{ \
213return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
214 NULL,NULL,0,NULL,NULL)); \
215}
216
217#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
218int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
219 unsigned char *kstr, int klen, pem_password_cb *cb, \
220 void *u) \
221 { \
222 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
223 (char *)x,enc,kstr,klen,cb,u)); \
224 }
225
226#endif
227
228#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
229type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
230{ \
231return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
232 (char **)x,cb,u)); \
233}
234
235#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
236int PEM_write_bio_##name(BIO *bp, type *x) \
237{ \
238return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
239 NULL,NULL,0,NULL,NULL)); \
240}
241
242#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
243int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
244 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
245 { \
246 return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \
247 (char *)x,enc,kstr,klen,cb,u)); \
248 }
249
250#define IMPLEMENT_PEM_write(name, type, str, asn1) \
251 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
252 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
253
254#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
255 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
256 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
257
258#define IMPLEMENT_PEM_read(name, type, str, asn1) \
259 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
260 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
261
262#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
263 IMPLEMENT_PEM_read(name, type, str, asn1) \
264 IMPLEMENT_PEM_write(name, type, str, asn1)
265
266#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
267 IMPLEMENT_PEM_read(name, type, str, asn1) \
268 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
269
270/* These are the same except they are for the declarations */
271
272#if defined(WIN16) || defined(NO_FP_API)
273
274#define DECLARE_PEM_read_fp(name, type) /**/
275#define DECLARE_PEM_write_fp(name, type) /**/
276#define DECLARE_PEM_write_cb_fp(name, type) /**/
277
278#else
279
280#define DECLARE_PEM_read_fp(name, type) \
281 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
282
283#define DECLARE_PEM_write_fp(name, type) \
284 int PEM_write_##name(FILE *fp, type *x);
285
286#define DECLARE_PEM_write_cb_fp(name, type) \
287 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
288 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
289
290#endif
291
292#ifdef HEADER_BIO_H
293#define DECLARE_PEM_read_bio(name, type) \
294 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
295
296#define DECLARE_PEM_write_bio(name, type) \
297 int PEM_write_bio_##name(BIO *bp, type *x);
298
299#define DECLARE_PEM_write_cb_bio(name, type) \
300 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
301 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
302
303#else
304
305#define DECLARE_PEM_read_bio(name, type) /**/
306#define DECLARE_PEM_write_bio(name, type) /**/
307#define DECLARE_PEM_write_cb_bio(name, type) /**/
308
309#endif
310
311#define DECLARE_PEM_write(name, type) \
312 DECLARE_PEM_write_bio(name, type) \
313 DECLARE_PEM_write_fp(name, type)
314
315#define DECLARE_PEM_write_cb(name, type) \
316 DECLARE_PEM_write_cb_bio(name, type) \
317 DECLARE_PEM_write_cb_fp(name, type)
318
319#define DECLARE_PEM_read(name, type) \
320 DECLARE_PEM_read_bio(name, type) \
321 DECLARE_PEM_read_fp(name, type)
322
323#define DECLARE_PEM_rw(name, type) \
324 DECLARE_PEM_read(name, type) \
325 DECLARE_PEM_write(name, type)
326
327#define DECLARE_PEM_rw_cb(name, type) \
328 DECLARE_PEM_read(name, type) \
329 DECLARE_PEM_write_cb(name, type)
330
331#ifdef SSLEAY_MACROS
332
333#define PEM_write_SSL_SESSION(fp,x) \
334 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
335 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
336#define PEM_write_X509(fp,x) \
337 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
338 (char *)x, NULL,NULL,0,NULL,NULL)
339#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
340 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
341 NULL,NULL,0,NULL,NULL)
342#define PEM_write_X509_CRL(fp,x) \
343 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
344 fp,(char *)x, NULL,NULL,0,NULL,NULL)
345#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
346 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
347 (char *)x,enc,kstr,klen,cb,u)
348#define PEM_write_RSAPublicKey(fp,x) \
349 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
350 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
351#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
352 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
353 (char *)x,enc,kstr,klen,cb,u)
354#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
355 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
356 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
357 bp,(char *)x,enc,kstr,klen,cb,u)
358#define PEM_write_PKCS7(fp,x) \
359 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
360 (char *)x, NULL,NULL,0,NULL,NULL)
361#define PEM_write_DHparams(fp,x) \
362 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
363 (char *)x,NULL,NULL,0,NULL,NULL)
364
365#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
366 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
367 PEM_STRING_X509,fp, \
368 (char *)x, NULL,NULL,0,NULL,NULL)
369
370#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
371 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
372#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
373 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
374#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
375 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
376#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
377 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
378#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
379 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
380#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
381 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
382#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
383 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
384#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
385 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
386#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
387 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
388#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
389 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
390
391#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
392 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
393 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
394 (char **)x,cb,u)
395
396#define PEM_write_bio_SSL_SESSION(bp,x) \
397 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
398 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
399#define PEM_write_bio_X509(bp,x) \
400 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
401 (char *)x, NULL,NULL,0,NULL,NULL)
402#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
403 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
404 NULL,NULL,0,NULL,NULL)
405#define PEM_write_bio_X509_CRL(bp,x) \
406 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
407 bp,(char *)x, NULL,NULL,0,NULL,NULL)
408#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
409 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
410 bp,(char *)x,enc,kstr,klen,cb,u)
411#define PEM_write_bio_RSAPublicKey(bp,x) \
412 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
413 PEM_STRING_RSA_PUBLIC,\
414 bp,(char *)x,NULL,NULL,0,NULL,NULL)
415#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
416 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
417 bp,(char *)x,enc,kstr,klen,cb,u)
418#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
419 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
420 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
421 bp,(char *)x,enc,kstr,klen,cb,u)
422#define PEM_write_bio_PKCS7(bp,x) \
423 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
424 (char *)x, NULL,NULL,0,NULL,NULL)
425#define PEM_write_bio_DHparams(bp,x) \
426 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
427 bp,(char *)x,NULL,NULL,0,NULL,NULL)
428#define PEM_write_bio_DSAparams(bp,x) \
429 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
430 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
431
432#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
433 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
434 PEM_STRING_X509,bp, \
435 (char *)x, NULL,NULL,0,NULL,NULL)
436
437#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
438 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
439#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
440 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
441#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
442 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
443#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
444 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
445#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
446 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
447#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
448 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
449#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
450 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
451#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
452 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
453
454#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
455 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
456#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
457 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
458#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
459 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
460
461#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
462 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
463 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
464 (char **)x,cb,u)
465
466#endif
467
468#if 1
469/* "userdata": new with OpenSSL 0.9.4 */
470typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
471#else
472/* OpenSSL 0.9.3, 0.9.3a */
473typedef int pem_password_cb(char *buf, int size, int rwflag);
474#endif
475
476int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
477int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
478 pem_password_cb *callback,void *u);
479
480#ifdef HEADER_BIO_H
481int PEM_read_bio(BIO *bp, char **name, char **header,
482 unsigned char **data,long *len);
483int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
484 long len);
485char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
486 pem_password_cb *cb, void *u);
487int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
488 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
489 pem_password_cb *cb, void *u);
490STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
491int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
492 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
493#endif
494
495#ifndef WIN16
496int PEM_read(FILE *fp, char **name, char **header,
497 unsigned char **data,long *len);
498int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
499char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
500 pem_password_cb *cb, void *u);
501int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
502 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
503 pem_password_cb *callback, void *u);
504STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
505 pem_password_cb *cb, void *u);
506#endif
507
508int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
509 EVP_MD *md_type, unsigned char **ek, int *ekl,
510 unsigned char *iv, EVP_PKEY **pubk, int npubk);
511void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
512 unsigned char *in, int inl);
513int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
514 unsigned char *out, int *outl, EVP_PKEY *priv);
515
516void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
517void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
518int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
519 unsigned int *siglen, EVP_PKEY *pkey);
520
521void ERR_load_PEM_strings(void);
522
523void PEM_proc_type(char *buf, int type);
524void PEM_dek_info(char *buf, const char *type, int len, char *str);
525
526#ifndef SSLEAY_MACROS
527
528#ifdef VMS
529#include <openssl/vms_idhacks.h>
530#endif
531
532DECLARE_PEM_rw(X509, X509)
533
534DECLARE_PEM_rw(X509_AUX, X509)
535
536DECLARE_PEM_rw(X509_REQ, X509_REQ)
537DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
538
539DECLARE_PEM_rw(X509_CRL, X509_CRL)
540
541DECLARE_PEM_rw(PKCS7, PKCS7)
542
543DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
544
545DECLARE_PEM_rw(PKCS8, X509_SIG)
546
547DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
548
549#ifndef NO_RSA
550
551DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
552
553DECLARE_PEM_rw(RSAPublicKey, RSA)
554DECLARE_PEM_rw(RSA_PUBKEY, RSA)
555
556#endif
557
558#ifndef NO_DSA
559
560DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
561
562DECLARE_PEM_rw(DSA_PUBKEY, DSA)
563
564DECLARE_PEM_rw(DSAparams, DSA)
565
566#endif
567
568#ifndef NO_DH
569
570DECLARE_PEM_rw(DHparams, DH)
571
572#endif
573
574DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
575
576DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
577
578int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
579 char *kstr, int klen,
580 pem_password_cb *cb, void *u);
581int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
582 char *, int, pem_password_cb *, void *);
583int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
584 char *kstr, int klen,
585 pem_password_cb *cb, void *u);
586int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
587 char *kstr, int klen,
588 pem_password_cb *cb, void *u);
589EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
590
591int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
592 char *kstr, int klen,
593 pem_password_cb *cb, void *u);
594int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
595 char *kstr, int klen,
596 pem_password_cb *cb, void *u);
597int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
598 char *kstr, int klen,
599 pem_password_cb *cb, void *u);
600
601EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
602
603int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
604 char *kstr,int klen, pem_password_cb *cd, void *u);
605
606#endif /* SSLEAY_MACROS */
607
608
609/* BEGIN ERROR CODES */
610/* The following lines are auto generated by the script mkerr.pl. Any changes
611 * made after this point may be overwritten when the script is next run.
612 */
613
614/* Error codes for the PEM functions. */
615
616/* Function codes. */
617#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
618#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
619#define PEM_F_DEF_CALLBACK 100
620#define PEM_F_LOAD_IV 101
621#define PEM_F_PEM_ASN1_READ 102
622#define PEM_F_PEM_ASN1_READ_BIO 103
623#define PEM_F_PEM_ASN1_WRITE 104
624#define PEM_F_PEM_ASN1_WRITE_BIO 105
625#define PEM_F_PEM_DO_HEADER 106
626#define PEM_F_PEM_F_DO_PK8KEY_FP 122
627#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
628#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
629#define PEM_F_PEM_READ 108
630#define PEM_F_PEM_READ_BIO 109
631#define PEM_F_PEM_SEALFINAL 110
632#define PEM_F_PEM_SEALINIT 111
633#define PEM_F_PEM_SIGNFINAL 112
634#define PEM_F_PEM_WRITE 113
635#define PEM_F_PEM_WRITE_BIO 114
636#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
637#define PEM_F_PEM_X509_INFO_READ 115
638#define PEM_F_PEM_X509_INFO_READ_BIO 116
639#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
640
641/* Reason codes. */
642#define PEM_R_BAD_BASE64_DECODE 100
643#define PEM_R_BAD_DECRYPT 101
644#define PEM_R_BAD_END_LINE 102
645#define PEM_R_BAD_IV_CHARS 103
646#define PEM_R_BAD_PASSWORD_READ 104
647#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
648#define PEM_R_NOT_DEK_INFO 105
649#define PEM_R_NOT_ENCRYPTED 106
650#define PEM_R_NOT_PROC_TYPE 107
651#define PEM_R_NO_START_LINE 108
652#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
653#define PEM_R_PUBLIC_KEY_NO_RSA 110
654#define PEM_R_READ_KEY 111
655#define PEM_R_SHORT_HEADER 112
656#define PEM_R_UNSUPPORTED_CIPHER 113
657#define PEM_R_UNSUPPORTED_ENCRYPTION 114
658
659#ifdef __cplusplus
660}
661#endif
662#endif
663
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 dc9c35b4b4..0000000000
--- a/src/lib/libcrypto/pem/pem_all.c
+++ /dev/null
@@ -1,203 +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
68#ifndef NO_RSA
69static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa);
70#endif
71#ifndef NO_DSA
72static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa);
73#endif
74
75IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
76
77IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)
78
79IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
80
81IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ)
82
83IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
84
85IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
86
87IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
88 PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
89
90IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
91IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
92 PKCS8_PRIV_KEY_INFO)
93
94#ifndef NO_RSA
95
96/* We treat RSA or DSA private keys as a special case.
97 *
98 * For private keys we read in an EVP_PKEY structure with
99 * PEM_read_bio_PrivateKey() and extract the relevant private
100 * key: this means can handle "traditional" and PKCS#8 formats
101 * transparently.
102 */
103
104static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa)
105{
106 RSA *rtmp;
107 if(!key) return NULL;
108 rtmp = EVP_PKEY_get1_RSA(key);
109 EVP_PKEY_free(key);
110 if(!rtmp) return NULL;
111 if(rsa) {
112 RSA_free(*rsa);
113 *rsa = rtmp;
114 }
115 return rtmp;
116}
117
118RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb,
119 void *u)
120{
121 EVP_PKEY *pktmp;
122 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
123 return pkey_get_rsa(pktmp, rsa);
124}
125
126#ifndef NO_FP_API
127
128RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
129 void *u)
130{
131 EVP_PKEY *pktmp;
132 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
133 return pkey_get_rsa(pktmp, rsa);
134}
135
136#endif
137
138IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
139IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
140IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
141
142#endif
143
144#ifndef NO_DSA
145
146static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa)
147{
148 DSA *dtmp;
149 if(!key) return NULL;
150 dtmp = EVP_PKEY_get1_DSA(key);
151 EVP_PKEY_free(key);
152 if(!dtmp) return NULL;
153 if(dsa) {
154 DSA_free(*dsa);
155 *dsa = dtmp;
156 }
157 return dtmp;
158}
159
160DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
161 void *u)
162{
163 EVP_PKEY *pktmp;
164 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
165 return pkey_get_dsa(pktmp, dsa);
166}
167
168IMPLEMENT_PEM_write_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
169IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
170
171#ifndef NO_FP_API
172
173DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
174 void *u)
175{
176 EVP_PKEY *pktmp;
177 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
178 return pkey_get_dsa(pktmp, dsa);
179}
180
181#endif
182
183IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
184
185#endif
186
187#ifndef NO_DH
188
189IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
190
191#endif
192
193
194/* The PrivateKey case is not that straightforward.
195 * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
196 * does not work, RSA and DSA keys have specific strings.
197 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
198 * appropriate.)
199 */
200IMPLEMENT_PEM_read(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
201IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
202
203IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
deleted file mode 100644
index 8b1789b11c..0000000000
--- a/src/lib/libcrypto/pem/pem_err.c
+++ /dev/null
@@ -1,131 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/pem.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA PEM_str_functs[]=
68 {
69{ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_BIO,0), "d2i_PKCS8PrivateKey_bio"},
70{ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_FP,0), "d2i_PKCS8PrivateKey_fp"},
71{ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"},
72{ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"},
73{ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"},
74{ERR_PACK(0,PEM_F_PEM_ASN1_READ_BIO,0), "PEM_ASN1_read_bio"},
75{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"},
76{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"},
77{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"},
78{ERR_PACK(0,PEM_F_PEM_F_DO_PK8KEY_FP,0), "PEM_F_DO_PK8KEY_FP"},
79{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
80{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"},
81{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"},
82{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"},
83{ERR_PACK(0,PEM_F_PEM_SEALFINAL,0), "PEM_SealFinal"},
84{ERR_PACK(0,PEM_F_PEM_SEALINIT,0), "PEM_SealInit"},
85{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"},
86{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"},
87{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"},
88{ERR_PACK(0,PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,0), "PEM_write_bio_PKCS8PrivateKey"},
89{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"},
90{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"},
91{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"},
92{0,NULL}
93 };
94
95static ERR_STRING_DATA PEM_str_reasons[]=
96 {
97{PEM_R_BAD_BASE64_DECODE ,"bad base64 decode"},
98{PEM_R_BAD_DECRYPT ,"bad decrypt"},
99{PEM_R_BAD_END_LINE ,"bad end line"},
100{PEM_R_BAD_IV_CHARS ,"bad iv chars"},
101{PEM_R_BAD_PASSWORD_READ ,"bad password read"},
102{PEM_R_ERROR_CONVERTING_PRIVATE_KEY ,"error converting private key"},
103{PEM_R_NOT_DEK_INFO ,"not dek info"},
104{PEM_R_NOT_ENCRYPTED ,"not encrypted"},
105{PEM_R_NOT_PROC_TYPE ,"not proc type"},
106{PEM_R_NO_START_LINE ,"no start line"},
107{PEM_R_PROBLEMS_GETTING_PASSWORD ,"problems getting password"},
108{PEM_R_PUBLIC_KEY_NO_RSA ,"public key no rsa"},
109{PEM_R_READ_KEY ,"read key"},
110{PEM_R_SHORT_HEADER ,"short header"},
111{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
112{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"},
113{0,NULL}
114 };
115
116#endif
117
118void ERR_load_PEM_strings(void)
119 {
120 static int init=1;
121
122 if (init)
123 {
124 init=0;
125#ifndef NO_ERR
126 ERR_load_strings(ERR_LIB_PEM,PEM_str_functs);
127 ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons);
128#endif
129
130 }
131 }
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
deleted file mode 100644
index b65239a920..0000000000
--- a/src/lib/libcrypto/pem/pem_info.c
+++ /dev/null
@@ -1,364 +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_TRUSTED) == 0))
136 {
137 d2i=(char *(*)())d2i_X509_AUX;
138 if (xi->x509 != 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->x509);
145 }
146 else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
147 {
148 d2i=(char *(*)())d2i_X509_CRL;
149 if (xi->crl != NULL)
150 {
151 if (!sk_X509_INFO_push(ret,xi)) goto err;
152 if ((xi=X509_INFO_new()) == NULL) goto err;
153 goto start;
154 }
155 pp=(char **)&(xi->crl);
156 }
157 else
158#ifndef NO_RSA
159 if (strcmp(name,PEM_STRING_RSA) == 0)
160 {
161 d2i=(char *(*)())d2i_RSAPrivateKey;
162 if (xi->x_pkey != NULL)
163 {
164 if (!sk_X509_INFO_push(ret,xi)) goto err;
165 if ((xi=X509_INFO_new()) == NULL) goto err;
166 goto start;
167 }
168
169 xi->enc_data=NULL;
170 xi->enc_len=0;
171
172 xi->x_pkey=X509_PKEY_new();
173 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
174 goto err;
175 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
176 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa);
177 if ((int)strlen(header) > 10) /* assume encrypted */
178 raw=1;
179 }
180 else
181#endif
182#ifndef NO_DSA
183 if (strcmp(name,PEM_STRING_DSA) == 0)
184 {
185 d2i=(char *(*)())d2i_DSAPrivateKey;
186 if (xi->x_pkey != NULL)
187 {
188 if (!sk_X509_INFO_push(ret,xi)) goto err;
189 if ((xi=X509_INFO_new()) == NULL) goto err;
190 goto start;
191 }
192
193 xi->enc_data=NULL;
194 xi->enc_len=0;
195
196 xi->x_pkey=X509_PKEY_new();
197 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
198 goto err;
199 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
200 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa);
201 if ((int)strlen(header) > 10) /* assume encrypted */
202 raw=1;
203 }
204 else
205#endif
206 {
207 d2i=NULL;
208 pp=NULL;
209 }
210
211 if (d2i != NULL)
212 {
213 if (!raw)
214 {
215 EVP_CIPHER_INFO cipher;
216
217 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
218 goto err;
219 if (!PEM_do_header(&cipher,data,&len,cb,u))
220 goto err;
221 p=data;
222 if (d2i(pp,&p,len) == NULL)
223 {
224 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
225 goto err;
226 }
227 }
228 else
229 { /* encrypted RSA data */
230 if (!PEM_get_EVP_CIPHER_INFO(header,
231 &xi->enc_cipher)) goto err;
232 xi->enc_data=(char *)data;
233 xi->enc_len=(int)len;
234 data=NULL;
235 }
236 }
237 else {
238 /* unknown */
239 }
240 if (name != NULL) Free(name);
241 if (header != NULL) Free(header);
242 if (data != NULL) Free(data);
243 name=NULL;
244 header=NULL;
245 data=NULL;
246 }
247
248 /* if the last one hasn't been pushed yet and there is anything
249 * in it then add it to the stack ...
250 */
251 if ((xi->x509 != NULL) || (xi->crl != NULL) ||
252 (xi->x_pkey != NULL) || (xi->enc_data != NULL))
253 {
254 if (!sk_X509_INFO_push(ret,xi)) goto err;
255 xi=NULL;
256 }
257 ok=1;
258err:
259 if (xi != NULL) X509_INFO_free(xi);
260 if (!ok)
261 {
262 for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
263 {
264 xi=sk_X509_INFO_value(ret,i);
265 X509_INFO_free(xi);
266 }
267 if (ret != sk) sk_X509_INFO_free(ret);
268 ret=NULL;
269 }
270
271 if (name != NULL) Free(name);
272 if (header != NULL) Free(header);
273 if (data != NULL) Free(data);
274 return(ret);
275 }
276
277
278/* A TJH addition */
279int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
280 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
281 {
282 EVP_CIPHER_CTX ctx;
283 int i,ret=0;
284 unsigned char *data=NULL;
285 const char *objstr=NULL;
286 char buf[PEM_BUFSIZE];
287 unsigned char *iv=NULL;
288
289 if (enc != NULL)
290 {
291 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
292 if (objstr == NULL)
293 {
294 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
295 goto err;
296 }
297 }
298
299 /* now for the fun part ... if we have a private key then
300 * we have to be able to handle a not-yet-decrypted key
301 * being written out correctly ... if it is decrypted or
302 * it is non-encrypted then we use the base code
303 */
304 if (xi->x_pkey!=NULL)
305 {
306 if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
307 {
308 /* copy from wierdo names into more normal things */
309 iv=xi->enc_cipher.iv;
310 data=(unsigned char *)xi->enc_data;
311 i=xi->enc_len;
312
313 /* we take the encryption data from the
314 * internal stuff rather than what the
315 * user has passed us ... as we have to
316 * match exactly for some strange reason
317 */
318 objstr=OBJ_nid2sn(
319 EVP_CIPHER_nid(xi->enc_cipher.cipher));
320 if (objstr == NULL)
321 {
322 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
323 goto err;
324 }
325
326 /* create the right magic header stuff */
327 buf[0]='\0';
328 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
329 PEM_dek_info(buf,objstr,8,(char *)iv);
330
331 /* use the normal code to write things out */
332 i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
333 if (i <= 0) goto err;
334 }
335 else
336 {
337 /* Add DSA/DH */
338#ifndef NO_RSA
339 /* normal optionally encrypted stuff */
340 if (PEM_write_bio_RSAPrivateKey(bp,
341 xi->x_pkey->dec_pkey->pkey.rsa,
342 enc,kstr,klen,cb,u)<=0)
343 goto err;
344#endif
345 }
346 }
347
348 /* if we have a certificate then write it out now */
349 if ((xi->x509 != NULL) || (PEM_write_bio_X509(bp,xi->x509) <= 0))
350 goto err;
351
352 /* we are ignoring anything else that is loaded into the X509_INFO
353 * structure for the moment ... as I don't need it so I'm not
354 * coding it here and Eric can do it when this makes it into the
355 * base library --tjh
356 */
357
358 ret=1;
359
360err:
361 memset((char *)&ctx,0,sizeof(ctx));
362 memset(buf,0,PEM_BUFSIZE);
363 return(ret);
364 }
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
deleted file mode 100644
index b5e0a650f8..0000000000
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ /dev/null
@@ -1,963 +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);
78static int check_pem(const char *nm, const char *name);
79static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder,
80 int nid, const EVP_CIPHER *enc,
81 char *kstr, int klen,
82 pem_password_cb *cb, void *u);
83static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder,
84 int nid, const EVP_CIPHER *enc,
85 char *kstr, int klen,
86 pem_password_cb *cb, void *u);
87
88static int def_callback(char *buf, int num, int w, void *key)
89 {
90#ifdef NO_FP_API
91 /* We should not ever call the default callback routine from
92 * windows. */
93 PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
94 return(-1);
95#else
96 int i,j;
97 const char *prompt;
98 if(key) {
99 i=strlen(key);
100 i=(i > num)?num:i;
101 memcpy(buf,key,i);
102 return(i);
103 }
104
105 prompt=EVP_get_pw_prompt();
106 if (prompt == NULL)
107 prompt="Enter PEM pass phrase:";
108
109 for (;;)
110 {
111 i=EVP_read_pw_string(buf,num,prompt,w);
112 if (i != 0)
113 {
114 PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
115 memset(buf,0,(unsigned int)num);
116 return(-1);
117 }
118 j=strlen(buf);
119 if (j < MIN_LENGTH)
120 {
121 fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH);
122 }
123 else
124 break;
125 }
126 return(j);
127#endif
128 }
129
130void PEM_proc_type(char *buf, int type)
131 {
132 const char *str;
133
134 if (type == PEM_TYPE_ENCRYPTED)
135 str="ENCRYPTED";
136 else if (type == PEM_TYPE_MIC_CLEAR)
137 str="MIC-CLEAR";
138 else if (type == PEM_TYPE_MIC_ONLY)
139 str="MIC-ONLY";
140 else
141 str="BAD-TYPE";
142
143 strcat(buf,"Proc-Type: 4,");
144 strcat(buf,str);
145 strcat(buf,"\n");
146 }
147
148void PEM_dek_info(char *buf, const char *type, int len, char *str)
149 {
150 static unsigned char map[17]="0123456789ABCDEF";
151 long i;
152 int j;
153
154 strcat(buf,"DEK-Info: ");
155 strcat(buf,type);
156 strcat(buf,",");
157 j=strlen(buf);
158 for (i=0; i<len; i++)
159 {
160 buf[j+i*2] =map[(str[i]>>4)&0x0f];
161 buf[j+i*2+1]=map[(str[i] )&0x0f];
162 }
163 buf[j+i*2]='\n';
164 buf[j+i*2+1]='\0';
165 }
166
167#ifndef NO_FP_API
168char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
169 pem_password_cb *cb, void *u)
170 {
171 BIO *b;
172 char *ret;
173
174 if ((b=BIO_new(BIO_s_file())) == NULL)
175 {
176 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
177 return(0);
178 }
179 BIO_set_fp(b,fp,BIO_NOCLOSE);
180 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u);
181 BIO_free(b);
182 return(ret);
183 }
184#endif
185
186static int check_pem(const char *nm, const char *name)
187{
188 /* Normal matching nm and name */
189 if (!strcmp(nm,name)) return 1;
190
191 /* Make PEM_STRING_EVP_PKEY match any private key */
192
193 if(!strcmp(nm,PEM_STRING_PKCS8) &&
194 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
195
196 if(!strcmp(nm,PEM_STRING_PKCS8INF) &&
197 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
198
199 if(!strcmp(nm,PEM_STRING_RSA) &&
200 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
201
202 if(!strcmp(nm,PEM_STRING_DSA) &&
203 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
204
205 /* Permit older strings */
206
207 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
208 !strcmp(name,PEM_STRING_X509)) return 1;
209
210 if(!strcmp(nm,PEM_STRING_X509_REQ_OLD) &&
211 !strcmp(name,PEM_STRING_X509_REQ)) return 1;
212
213 /* Allow normal certs to be read as trusted certs */
214 if(!strcmp(nm,PEM_STRING_X509) &&
215 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
216
217 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
218 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
219
220 /* Some CAs use PKCS#7 with CERTIFICATE headers */
221 if(!strcmp(nm, PEM_STRING_X509) &&
222 !strcmp(name, PEM_STRING_PKCS7)) return 1;
223
224 return 0;
225}
226
227char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
228 pem_password_cb *cb, void *u)
229 {
230 EVP_CIPHER_INFO cipher;
231 char *nm=NULL,*header=NULL;
232 unsigned char *p=NULL,*data=NULL;
233 long len;
234 char *ret=NULL;
235
236 for (;;)
237 {
238 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) {
239 if(ERR_GET_REASON(ERR_peek_error()) ==
240 PEM_R_NO_START_LINE)
241 ERR_add_error_data(2, "Expecting: ", name);
242 return(NULL);
243 }
244 if(check_pem(nm, name)) break;
245 Free(nm);
246 Free(header);
247 Free(data);
248 }
249 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
250 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
251 p=data;
252 if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) {
253 if (strcmp(nm,PEM_STRING_RSA) == 0)
254 ret=d2i(EVP_PKEY_RSA,x,&p,len);
255 else if (strcmp(nm,PEM_STRING_DSA) == 0)
256 ret=d2i(EVP_PKEY_DSA,x,&p,len);
257 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
258 PKCS8_PRIV_KEY_INFO *p8inf;
259 p8inf=d2i_PKCS8_PRIV_KEY_INFO(
260 (PKCS8_PRIV_KEY_INFO **) x, &p, len);
261 ret = (char *)EVP_PKCS82PKEY(p8inf);
262 PKCS8_PRIV_KEY_INFO_free(p8inf);
263 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
264 PKCS8_PRIV_KEY_INFO *p8inf;
265 X509_SIG *p8;
266 int klen;
267 char psbuf[PEM_BUFSIZE];
268 p8 = d2i_X509_SIG(NULL, &p, len);
269 if(!p8) goto p8err;
270 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
271 else klen=def_callback(psbuf,PEM_BUFSIZE,0,u);
272 if (klen <= 0) {
273 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
274 PEM_R_BAD_PASSWORD_READ);
275 goto err;
276 }
277 p8inf = M_PKCS8_decrypt(p8, psbuf, klen);
278 X509_SIG_free(p8);
279 if(!p8inf) goto p8err;
280 ret = (char *)EVP_PKCS82PKEY(p8inf);
281 if(x) {
282 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
283 *x = ret;
284 }
285 PKCS8_PRIV_KEY_INFO_free(p8inf);
286 }
287 } else ret=d2i(x,&p,len);
288p8err:
289 if (ret == NULL)
290 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
291err:
292 Free(nm);
293 Free(header);
294 Free(data);
295 return(ret);
296 }
297
298#ifndef NO_FP_API
299int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
300 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
301 pem_password_cb *callback, void *u)
302 {
303 BIO *b;
304 int ret;
305
306 if ((b=BIO_new(BIO_s_file())) == NULL)
307 {
308 PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB);
309 return(0);
310 }
311 BIO_set_fp(b,fp,BIO_NOCLOSE);
312 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u);
313 BIO_free(b);
314 return(ret);
315 }
316#endif
317
318int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
319 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
320 pem_password_cb *callback, void *u)
321 {
322 EVP_CIPHER_CTX ctx;
323 int dsize=0,i,j,ret=0;
324 unsigned char *p,*data=NULL;
325 const char *objstr=NULL;
326 char buf[PEM_BUFSIZE];
327 unsigned char key[EVP_MAX_KEY_LENGTH];
328 unsigned char iv[EVP_MAX_IV_LENGTH];
329
330 if (enc != NULL)
331 {
332 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
333 if (objstr == NULL)
334 {
335 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
336 goto err;
337 }
338 }
339
340 if ((dsize=i2d(x,NULL)) < 0)
341 {
342 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
343 dsize=0;
344 goto err;
345 }
346 /* dzise + 8 bytes are needed */
347 data=(unsigned char *)Malloc((unsigned int)dsize+20);
348 if (data == NULL)
349 {
350 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
351 goto err;
352 }
353 p=data;
354 i=i2d(x,&p);
355
356 if (enc != NULL)
357 {
358 if (kstr == NULL)
359 {
360 if (callback == NULL)
361 klen=def_callback(buf,PEM_BUFSIZE,1,u);
362 else
363 klen=(*callback)(buf,PEM_BUFSIZE,1,u);
364 if (klen <= 0)
365 {
366 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
367 goto err;
368 }
369#ifdef CHARSET_EBCDIC
370 /* Convert the pass phrase from EBCDIC */
371 ebcdic2ascii(buf, buf, klen);
372#endif
373 kstr=(unsigned char *)buf;
374 }
375 RAND_add(data,i,0);/* put in the RSA key. */
376 if (RAND_pseudo_bytes(iv,8) < 0) /* Generate a salt */
377 goto err;
378 /* The 'iv' is used as the iv and as a salt. It is
379 * NOT taken from the BytesToKey function */
380 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
381
382 if (kstr == (unsigned char *)buf) memset(buf,0,PEM_BUFSIZE);
383
384 buf[0]='\0';
385 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
386 PEM_dek_info(buf,objstr,8,(char *)iv);
387 /* k=strlen(buf); */
388
389 EVP_EncryptInit(&ctx,enc,key,iv);
390 EVP_EncryptUpdate(&ctx,data,&j,data,i);
391 EVP_EncryptFinal(&ctx,&(data[j]),&i);
392 i+=j;
393 ret=1;
394 }
395 else
396 {
397 ret=1;
398 buf[0]='\0';
399 }
400 i=PEM_write_bio(bp,name,buf,data,i);
401 if (i <= 0) ret=0;
402err:
403 memset(key,0,sizeof(key));
404 memset(iv,0,sizeof(iv));
405 memset((char *)&ctx,0,sizeof(ctx));
406 memset(buf,0,PEM_BUFSIZE);
407 memset(data,0,(unsigned int)dsize);
408 Free(data);
409 return(ret);
410 }
411
412int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
413 pem_password_cb *callback,void *u)
414 {
415 int i,j,o,klen;
416 long len;
417 EVP_CIPHER_CTX ctx;
418 unsigned char key[EVP_MAX_KEY_LENGTH];
419 char buf[PEM_BUFSIZE];
420
421 len= *plen;
422
423 if (cipher->cipher == NULL) return(1);
424 if (callback == NULL)
425 klen=def_callback(buf,PEM_BUFSIZE,0,u);
426 else
427 klen=callback(buf,PEM_BUFSIZE,0,u);
428 if (klen <= 0)
429 {
430 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
431 return(0);
432 }
433#ifdef CHARSET_EBCDIC
434 /* Convert the pass phrase from EBCDIC */
435 ebcdic2ascii(buf, buf, klen);
436#endif
437
438 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
439 (unsigned char *)buf,klen,1,key,NULL);
440
441 j=(int)len;
442 EVP_DecryptInit(&ctx,cipher->cipher,key,&(cipher->iv[0]));
443 EVP_DecryptUpdate(&ctx,data,&i,data,j);
444 o=EVP_DecryptFinal(&ctx,&(data[i]),&j);
445 EVP_CIPHER_CTX_cleanup(&ctx);
446 memset((char *)buf,0,sizeof(buf));
447 memset((char *)key,0,sizeof(key));
448 j+=i;
449 if (!o)
450 {
451 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT);
452 return(0);
453 }
454 *plen=j;
455 return(1);
456 }
457
458int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
459 {
460 int o;
461 const EVP_CIPHER *enc=NULL;
462 char *p,c;
463
464 cipher->cipher=NULL;
465 if ((header == NULL) || (*header == '\0') || (*header == '\n'))
466 return(1);
467 if (strncmp(header,"Proc-Type: ",11) != 0)
468 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); }
469 header+=11;
470 if (*header != '4') return(0); header++;
471 if (*header != ',') return(0); header++;
472 if (strncmp(header,"ENCRYPTED",9) != 0)
473 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); }
474 for (; (*header != '\n') && (*header != '\0'); header++)
475 ;
476 if (*header == '\0')
477 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); }
478 header++;
479 if (strncmp(header,"DEK-Info: ",10) != 0)
480 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); }
481 header+=10;
482
483 p=header;
484 for (;;)
485 {
486 c= *header;
487#ifndef CHARSET_EBCDIC
488 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
489 ((c >= '0') && (c <= '9'))))
490 break;
491#else
492 if (!( isupper(c) || (c == '-') ||
493 isdigit(c)))
494 break;
495#endif
496 header++;
497 }
498 *header='\0';
499 o=OBJ_sn2nid(p);
500 cipher->cipher=enc=EVP_get_cipherbyname(p);
501 *header=c;
502 header++;
503
504 if (enc == NULL)
505 {
506 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION);
507 return(0);
508 }
509 if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),8)) return(0);
510
511 return(1);
512 }
513
514static int load_iv(unsigned char **fromp, unsigned char *to, int num)
515 {
516 int v,i;
517 unsigned char *from;
518
519 from= *fromp;
520 for (i=0; i<num; i++) to[i]=0;
521 num*=2;
522 for (i=0; i<num; i++)
523 {
524 if ((*from >= '0') && (*from <= '9'))
525 v= *from-'0';
526 else if ((*from >= 'A') && (*from <= 'F'))
527 v= *from-'A'+10;
528 else if ((*from >= 'a') && (*from <= 'f'))
529 v= *from-'a'+10;
530 else
531 {
532 PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS);
533 return(0);
534 }
535 from++;
536 to[i/2]|=v<<(long)((!(i&1))*4);
537 }
538
539 *fromp=from;
540 return(1);
541 }
542
543#ifndef NO_FP_API
544int PEM_write(FILE *fp, char *name, char *header, unsigned char *data,
545 long len)
546 {
547 BIO *b;
548 int ret;
549
550 if ((b=BIO_new(BIO_s_file())) == NULL)
551 {
552 PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB);
553 return(0);
554 }
555 BIO_set_fp(b,fp,BIO_NOCLOSE);
556 ret=PEM_write_bio(b, name, header, data,len);
557 BIO_free(b);
558 return(ret);
559 }
560#endif
561
562int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
563 long len)
564 {
565 int nlen,n,i,j,outl;
566 unsigned char *buf;
567 EVP_ENCODE_CTX ctx;
568 int reason=ERR_R_BUF_LIB;
569
570 EVP_EncodeInit(&ctx);
571 nlen=strlen(name);
572
573 if ( (BIO_write(bp,"-----BEGIN ",11) != 11) ||
574 (BIO_write(bp,name,nlen) != nlen) ||
575 (BIO_write(bp,"-----\n",6) != 6))
576 goto err;
577
578 i=strlen(header);
579 if (i > 0)
580 {
581 if ( (BIO_write(bp,header,i) != i) ||
582 (BIO_write(bp,"\n",1) != 1))
583 goto err;
584 }
585
586 buf=(unsigned char *)Malloc(PEM_BUFSIZE*8);
587 if (buf == NULL)
588 {
589 reason=ERR_R_MALLOC_FAILURE;
590 goto err;
591 }
592
593 i=j=0;
594 while (len > 0)
595 {
596 n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len);
597 EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n);
598 if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl))
599 goto err;
600 i+=outl;
601 len-=n;
602 j+=n;
603 }
604 EVP_EncodeFinal(&ctx,buf,&outl);
605 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
606 Free(buf);
607 if ( (BIO_write(bp,"-----END ",9) != 9) ||
608 (BIO_write(bp,name,nlen) != nlen) ||
609 (BIO_write(bp,"-----\n",6) != 6))
610 goto err;
611 return(i+outl);
612err:
613 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
614 return(0);
615 }
616
617#ifndef NO_FP_API
618int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
619 long *len)
620 {
621 BIO *b;
622 int ret;
623
624 if ((b=BIO_new(BIO_s_file())) == NULL)
625 {
626 PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB);
627 return(0);
628 }
629 BIO_set_fp(b,fp,BIO_NOCLOSE);
630 ret=PEM_read_bio(b, name, header, data,len);
631 BIO_free(b);
632 return(ret);
633 }
634#endif
635
636int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
637 long *len)
638 {
639 EVP_ENCODE_CTX ctx;
640 int end=0,i,k,bl=0,hl=0,nohead=0;
641 char buf[256];
642 BUF_MEM *nameB;
643 BUF_MEM *headerB;
644 BUF_MEM *dataB,*tmpB;
645
646 nameB=BUF_MEM_new();
647 headerB=BUF_MEM_new();
648 dataB=BUF_MEM_new();
649 if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))
650 {
651 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
652 return(0);
653 }
654
655 buf[254]='\0';
656 for (;;)
657 {
658 i=BIO_gets(bp,buf,254);
659
660 if (i <= 0)
661 {
662 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);
663 goto err;
664 }
665
666 while ((i >= 0) && (buf[i] <= ' ')) i--;
667 buf[++i]='\n'; buf[++i]='\0';
668
669 if (strncmp(buf,"-----BEGIN ",11) == 0)
670 {
671 i=strlen(&(buf[11]));
672
673 if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0)
674 continue;
675 if (!BUF_MEM_grow(nameB,i+9))
676 {
677 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
678 goto err;
679 }
680 memcpy(nameB->data,&(buf[11]),i-6);
681 nameB->data[i-6]='\0';
682 break;
683 }
684 }
685 hl=0;
686 if (!BUF_MEM_grow(headerB,256))
687 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
688 headerB->data[0]='\0';
689 for (;;)
690 {
691 i=BIO_gets(bp,buf,254);
692 if (i <= 0) break;
693
694 while ((i >= 0) && (buf[i] <= ' ')) i--;
695 buf[++i]='\n'; buf[++i]='\0';
696
697 if (buf[0] == '\n') break;
698 if (!BUF_MEM_grow(headerB,hl+i+9))
699 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
700 if (strncmp(buf,"-----END ",9) == 0)
701 {
702 nohead=1;
703 break;
704 }
705 memcpy(&(headerB->data[hl]),buf,i);
706 headerB->data[hl+i]='\0';
707 hl+=i;
708 }
709
710 bl=0;
711 if (!BUF_MEM_grow(dataB,1024))
712 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
713 dataB->data[0]='\0';
714 if (!nohead)
715 {
716 for (;;)
717 {
718 i=BIO_gets(bp,buf,254);
719 if (i <= 0) break;
720
721 while ((i >= 0) && (buf[i] <= ' ')) i--;
722 buf[++i]='\n'; buf[++i]='\0';
723
724 if (i != 65) end=1;
725 if (strncmp(buf,"-----END ",9) == 0)
726 break;
727 if (i > 65) break;
728 if (!BUF_MEM_grow(dataB,i+bl+9))
729 {
730 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
731 goto err;
732 }
733 memcpy(&(dataB->data[bl]),buf,i);
734 dataB->data[bl+i]='\0';
735 bl+=i;
736 if (end)
737 {
738 buf[0]='\0';
739 i=BIO_gets(bp,buf,254);
740 if (i <= 0) break;
741
742 while ((i >= 0) && (buf[i] <= ' ')) i--;
743 buf[++i]='\n'; buf[++i]='\0';
744
745 break;
746 }
747 }
748 }
749 else
750 {
751 tmpB=headerB;
752 headerB=dataB;
753 dataB=tmpB;
754 bl=hl;
755 }
756 i=strlen(nameB->data);
757 if ( (strncmp(buf,"-----END ",9) != 0) ||
758 (strncmp(nameB->data,&(buf[9]),i) != 0) ||
759 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
760 {
761 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
762 goto err;
763 }
764
765 EVP_DecodeInit(&ctx);
766 i=EVP_DecodeUpdate(&ctx,
767 (unsigned char *)dataB->data,&bl,
768 (unsigned char *)dataB->data,bl);
769 if (i < 0)
770 {
771 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
772 goto err;
773 }
774 i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);
775 if (i < 0)
776 {
777 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
778 goto err;
779 }
780 bl+=k;
781
782 if (bl == 0) goto err;
783 *name=nameB->data;
784 *header=headerB->data;
785 *data=(unsigned char *)dataB->data;
786 *len=bl;
787 Free(nameB);
788 Free(headerB);
789 Free(dataB);
790 return(1);
791err:
792 BUF_MEM_free(nameB);
793 BUF_MEM_free(headerB);
794 BUF_MEM_free(dataB);
795 return(0);
796 }
797
798/* These functions write a private key in PKCS#8 format: it is a "drop in"
799 * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
800 * is NULL then it uses the unencrypted private key form. The 'nid' versions
801 * uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
802 */
803
804int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
805 char *kstr, int klen,
806 pem_password_cb *cb, void *u)
807{
808 return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
809}
810
811int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
812 char *kstr, int klen,
813 pem_password_cb *cb, void *u)
814{
815 return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
816}
817
818int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
819 char *kstr, int klen,
820 pem_password_cb *cb, void *u)
821{
822 return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
823}
824
825int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
826 char *kstr, int klen,
827 pem_password_cb *cb, void *u)
828{
829 return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
830}
831
832static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
833 char *kstr, int klen,
834 pem_password_cb *cb, void *u)
835{
836 X509_SIG *p8;
837 PKCS8_PRIV_KEY_INFO *p8inf;
838 char buf[PEM_BUFSIZE];
839 int ret;
840 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
841 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
842 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
843 return 0;
844 }
845 if(enc || (nid != -1)) {
846 if(!kstr) {
847 if(!cb) klen = def_callback(buf, PEM_BUFSIZE, 1, u);
848 else klen = cb(buf, PEM_BUFSIZE, 1, u);
849 if(klen <= 0) {
850 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
851 PEM_R_READ_KEY);
852 PKCS8_PRIV_KEY_INFO_free(p8inf);
853 return 0;
854 }
855
856 kstr = buf;
857 }
858 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
859 if(kstr == buf) memset(buf, 0, klen);
860 PKCS8_PRIV_KEY_INFO_free(p8inf);
861 if(isder) ret = i2d_PKCS8_bio(bp, p8);
862 else ret = PEM_write_bio_PKCS8(bp, p8);
863 X509_SIG_free(p8);
864 return ret;
865 } else {
866 if(isder) ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
867 else ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
868 PKCS8_PRIV_KEY_INFO_free(p8inf);
869 return ret;
870 }
871}
872
873/* Finally the DER version to read PKCS#8 encrypted private keys. It has to be
874 * here to access the default callback.
875 */
876
877EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
878{
879 PKCS8_PRIV_KEY_INFO *p8inf = NULL;
880 X509_SIG *p8 = NULL;
881 int klen;
882 EVP_PKEY *ret;
883 char psbuf[PEM_BUFSIZE];
884 p8 = d2i_PKCS8_bio(bp, NULL);
885 if(!p8) return NULL;
886 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
887 else klen=def_callback(psbuf,PEM_BUFSIZE,0,u);
888 if (klen <= 0) {
889 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
890 X509_SIG_free(p8);
891 return NULL;
892 }
893 p8inf = M_PKCS8_decrypt(p8, psbuf, klen);
894 X509_SIG_free(p8);
895 if(!p8inf) return NULL;
896 ret = EVP_PKCS82PKEY(p8inf);
897 PKCS8_PRIV_KEY_INFO_free(p8inf);
898 if(!ret) return NULL;
899 if(x) {
900 if(*x) EVP_PKEY_free(*x);
901 *x = ret;
902 }
903 return ret;
904}
905
906#ifndef NO_FP_API
907
908int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
909 char *kstr, int klen,
910 pem_password_cb *cb, void *u)
911{
912 return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
913}
914
915int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
916 char *kstr, int klen,
917 pem_password_cb *cb, void *u)
918{
919 return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
920}
921
922int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
923 char *kstr, int klen,
924 pem_password_cb *cb, void *u)
925{
926 return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
927}
928
929int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
930 char *kstr, int klen, pem_password_cb *cb, void *u)
931{
932 return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
933}
934
935static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
936 char *kstr, int klen,
937 pem_password_cb *cb, void *u)
938{
939 BIO *bp;
940 int ret;
941 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
942 PEMerr(PEM_F_PEM_F_DO_PK8KEY_FP,ERR_R_BUF_LIB);
943 return(0);
944 }
945 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
946 BIO_free(bp);
947 return ret;
948}
949
950EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
951{
952 BIO *bp;
953 EVP_PKEY *ret;
954 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
955 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP,ERR_R_BUF_LIB);
956 return NULL;
957 }
958 ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
959 BIO_free(bp);
960 return ret;
961}
962
963#endif
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
deleted file mode 100644
index 126e29d375..0000000000
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ /dev/null
@@ -1,184 +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#else /* !NO_RSA */
179
180# if PEDANTIC
181static void *dummy=&dummy;
182# endif
183
184#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 81c6e64e87..0000000000
--- a/src/lib/libcrypto/perlasm/x86asm.pl
+++ /dev/null
@@ -1,118 +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=$gaswin=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 "gaswin"))
27 { $gaswin=1; $aout=1; require "x86unix.pl"; }
28 elsif ( ($type eq "sol"))
29 { $sol=1; require "x86unix.pl"; }
30 elsif ( ($type eq "cpp"))
31 { $cpp=1; require "x86unix.pl"; }
32 elsif ( ($type eq "win32"))
33 { $win32=1; require "x86ms.pl"; }
34 elsif ( ($type eq "win32n"))
35 { $win32=1; require "x86nasm.pl"; }
36 else
37 {
38 print STDERR <<"EOF";
39Pick one target type from
40 elf - linux, FreeBSD etc
41 a.out - old linux
42 sol - x86 solaris
43 cpp - format so x86unix.cpp can be used
44 win32 - Windows 95/Windows NT
45 win32n - Windows 95/Windows NT NASM format
46EOF
47 exit(1);
48 }
49
50 &asm_init_output();
51
52&comment("Don't even think of reading this code");
53&comment("It was automatically generated by $filename");
54&comment("Which is a perl program used to generate the x86 assember for");
55&comment("any of elf, a.out, BSDI, Win32, gaswin (for GNU as on Win32) or Solaris");
56&comment("eric <eay\@cryptsoft.com>");
57&comment("");
58
59 $filename =~ s/\.pl$//;
60 &file($filename);
61 }
62
63sub asm_finish_cpp
64 {
65 return unless $cpp;
66
67 local($tmp,$i);
68 foreach $i (&get_labels())
69 {
70 $tmp.="#define $i _$i\n";
71 }
72 print <<"EOF";
73/* Run the C pre-processor over this file with one of the following defined
74 * ELF - elf object files,
75 * OUT - a.out object files,
76 * BSDI - BSDI style a.out object files
77 * SOL - Solaris style elf
78 */
79
80#define TYPE(a,b) .type a,b
81#define SIZE(a,b) .size a,b
82
83#if defined(OUT) || (defined(BSDI) && !defined(ELF))
84$tmp
85#endif
86
87#ifdef OUT
88#define OK 1
89#define ALIGN 4
90#endif
91
92#if defined(BSDI) && !defined(ELF)
93#define OK 1
94#define ALIGN 4
95#undef SIZE
96#undef TYPE
97#define SIZE(a,b)
98#define TYPE(a,b)
99#endif
100
101#if defined(ELF) || defined(SOL)
102#define OK 1
103#define ALIGN 16
104#endif
105
106#ifndef OK
107You need to define one of
108ELF - elf systems - linux-elf, NetBSD and DG-UX
109OUT - a.out systems - linux-a.out and FreeBSD
110SOL - solaris systems, which are elf with strange comment lines
111BSDI - a.out with a very primative version of as.
112#endif
113
114/* Let the Assembler begin :-) */
115EOF
116 }
117
1181;
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c
deleted file mode 100644
index d045cbba8d..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_add.c
+++ /dev/null
@@ -1,216 +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 = M_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 if(!PKCS7_set_type(p7, NID_pkcs7_encrypted)) {
161 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA,
162 PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE);
163 return NULL;
164 }
165 if (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) {
166 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
167 return NULL;
168 }
169 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm);
170 p7->d.encrypted->enc_data->algorithm = pbe;
171 M_ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data);
172 if (!(p7->d.encrypted->enc_data->enc_data =
173 PKCS12_i2d_encrypt (pbe, i2d_PKCS12_SAFEBAG, pass, passlen,
174 (char *)bags, 1))) {
175 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, PKCS12_R_ENCRYPT_ERROR);
176 return NULL;
177 }
178
179 return p7;
180}
181
182X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
183 const char *pass, int passlen,
184 unsigned char *salt, int saltlen, int iter,
185 PKCS8_PRIV_KEY_INFO *p8inf)
186{
187 X509_SIG *p8;
188 X509_ALGOR *pbe;
189
190 if (!(p8 = X509_SIG_new())) {
191 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
192 goto err;
193 }
194
195 if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
196 else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
197 if(!pbe) {
198 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB);
199 goto err;
200 }
201 X509_ALGOR_free(p8->algor);
202 p8->algor = pbe;
203 M_ASN1_OCTET_STRING_free(p8->digest);
204 if (!(p8->digest =
205 PKCS12_i2d_encrypt (pbe, i2d_PKCS8_PRIV_KEY_INFO, pass, passlen,
206 (char *)p8inf, 0))) {
207 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR);
208 goto err;
209 }
210
211 return p8;
212
213 err:
214 X509_SIG_free(p8);
215 return NULL;
216}
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c
deleted file mode 100644
index f559351d18..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 = M_ASN1_OCTET_STRING_new())) {
77 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 if (!M_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 = M_ASN1_BIT_STRING_new())) {
119 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
120 return 0;
121 }
122 if (!M_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 = M_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 7b96584f07..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_crpt.c
+++ /dev/null
@@ -1,124 +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
73#ifndef NO_DES
74EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
75 EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
76EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
77 EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
78#endif
79#ifndef NO_RC2
80EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(),
81 EVP_sha1(), PKCS12_PBE_keyivgen);
82EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC2_CBC, EVP_rc2_40_cbc(),
83 EVP_sha1(), PKCS12_PBE_keyivgen);
84#endif
85}
86
87int PKCS12_PBE_keyivgen (EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
88 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, int en_de)
89{
90 PBEPARAM *pbe;
91 int saltlen, iter;
92 unsigned char *salt, *pbuf;
93 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
94
95 /* Extract useful info from parameter */
96 pbuf = param->value.sequence->data;
97 if (!param || (param->type != V_ASN1_SEQUENCE) ||
98 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
99 EVPerr(PKCS12_F_PKCS12_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
100 return 0;
101 }
102
103 if (!pbe->iter) iter = 1;
104 else iter = ASN1_INTEGER_get (pbe->iter);
105 salt = pbe->salt->data;
106 saltlen = pbe->salt->length;
107 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_KEY_ID,
108 iter, EVP_CIPHER_key_length(cipher), key, md)) {
109 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_KEY_GEN_ERROR);
110 PBEPARAM_free(pbe);
111 return 0;
112 }
113 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_IV_ID,
114 iter, EVP_CIPHER_iv_length(cipher), iv, md)) {
115 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_IV_GEN_ERROR);
116 PBEPARAM_free(pbe);
117 return 0;
118 }
119 PBEPARAM_free(pbe);
120 EVP_CipherInit(ctx, cipher, key, iv, en_de);
121 memset(key, 0, EVP_MAX_KEY_LENGTH);
122 memset(iv, 0, EVP_MAX_IV_LENGTH);
123 return 1;
124}
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c
deleted file mode 100644
index ee8aed54c7..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_OF(X509) *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_X509_num(ca); i++) {
107 tcert = sk_X509_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 4be44eac50..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 = M_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 d5d4884c82..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 = M_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 M_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 b364671ed2..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ /dev/null
@@ -1,189 +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 <openssl/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#endif
108
109 if (!pass) {
110 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_PASSED_NULL_PARAMETER);
111 return 0;
112 }
113
114#ifdef DEBUG_KEYGEN
115 fprintf(stderr, "KEYGEN DEBUG\n");
116 fprintf(stderr, "ID %d, ITER %d\n", id, iter);
117 fprintf(stderr, "Password (length %d):\n", passlen);
118 h__dump(pass, passlen);
119 fprintf(stderr, "Salt (length %d):\n", saltlen);
120 h__dump(salt, saltlen);
121#endif
122 v = EVP_MD_block_size (md_type);
123 u = EVP_MD_size (md_type);
124 D = Malloc (v);
125 Ai = Malloc (u);
126 B = Malloc (v + 1);
127 Slen = v * ((saltlen+v-1)/v);
128 Plen = v * ((passlen+v-1)/v);
129 Ilen = Slen + Plen;
130 I = Malloc (Ilen);
131 Ij = BN_new();
132 Bpl1 = BN_new();
133 if (!D || !Ai || !B || !I || !Ij || !Bpl1) {
134 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE);
135 return 0;
136 }
137 for (i = 0; i < v; i++) D[i] = id;
138 p = I;
139 for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen];
140 for (i = 0; i < Plen; i++) *p++ = pass[i % passlen];
141 for (;;) {
142 EVP_DigestInit (&ctx, md_type);
143 EVP_DigestUpdate (&ctx, D, v);
144 EVP_DigestUpdate (&ctx, I, Ilen);
145 EVP_DigestFinal (&ctx, Ai, NULL);
146 for (j = 1; j < iter; j++) {
147 EVP_DigestInit (&ctx, md_type);
148 EVP_DigestUpdate (&ctx, Ai, u);
149 EVP_DigestFinal (&ctx, Ai, NULL);
150 }
151 memcpy (out, Ai, min (n, u));
152 if (u >= n) {
153 Free (Ai);
154 Free (B);
155 Free (D);
156 Free (I);
157 BN_free (Ij);
158 BN_free (Bpl1);
159#ifdef DEBUG_KEYGEN
160 fprintf(stderr, "Output KEY (length %d)\n", tmpn);
161 h__dump(tmpout, tmpn);
162#endif
163 return 1;
164 }
165 n -= u;
166 out += u;
167 for (j = 0; j < v; j++) B[j] = Ai[j % u];
168 /* Work out B + 1 first then can use B as tmp space */
169 BN_bin2bn (B, v, Bpl1);
170 BN_add_word (Bpl1, 1);
171 for (j = 0; j < Ilen ; j+=v) {
172 BN_bin2bn (I + j, v, Ij);
173 BN_add (Ij, Ij, Bpl1);
174 BN_bn2bin (Ij, B);
175 /* If more than 2^(v*8) - 1 cut off MSB */
176 if (BN_num_bytes (Ij) > v) {
177 BN_bn2bin (Ij, B);
178 memcpy (I + j, B + 1, v);
179 } else BN_bn2bin (Ij, I + j);
180 }
181 }
182}
183#ifdef DEBUG_KEYGEN
184void h__dump (unsigned char *p, int len)
185{
186 for (; len --; p++) fprintf(stderr, "%02X", *p);
187 fprintf(stderr, "\n");
188}
189#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c
deleted file mode 100644
index ee257ffbad..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_kiss.c
+++ /dev/null
@@ -1,254 +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,
66 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca);
67
68static int parse_bags( STACK *bags, const char *pass, int passlen,
69 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
70 ASN1_OCTET_STRING **keyid, char *keymatch);
71
72static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen,
73 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
74 ASN1_OCTET_STRING **keyid, char *keymatch);
75
76/* Parse and decrypt a PKCS#12 structure returning user key, user cert
77 * and other (CA) certs. Note either ca should be NULL, *ca should be NULL,
78 * or it should point to a valid STACK structure. pkey and cert can be
79 * passed unitialised.
80 */
81
82int PKCS12_parse (PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
83 STACK_OF(X509) **ca)
84{
85
86 /* Check for NULL PKCS12 structure */
87
88 if(!p12)
89 {
90 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
91 return 0;
92 }
93
94 /* Allocate stack for ca certificates if needed */
95 if ((ca != NULL) && (*ca == NULL))
96 {
97 if (!(*ca = sk_X509_new(NULL)))
98 {
99 PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE);
100 return 0;
101 }
102 }
103
104 if(pkey) *pkey = NULL;
105 if(cert) *cert = NULL;
106
107 /* Check the mac */
108
109 if (!PKCS12_verify_mac (p12, pass, -1))
110 {
111 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
112 goto err;
113 }
114
115 if (!parse_pk12 (p12, pass, -1, pkey, cert, ca))
116 {
117 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_PARSE_ERROR);
118 goto err;
119 }
120
121 return 1;
122
123 err:
124
125 if (pkey && *pkey) EVP_PKEY_free (*pkey);
126 if (cert && *cert) X509_free (*cert);
127 if (ca) sk_X509_pop_free (*ca, X509_free);
128 return 0;
129
130}
131
132/* Parse the outer PKCS#12 structure */
133
134static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen,
135 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
136{
137 STACK *asafes, *bags;
138 int i, bagnid;
139 PKCS7 *p7;
140 ASN1_OCTET_STRING *keyid = NULL;
141 char keymatch = 0;
142 if (!( asafes = M_PKCS12_unpack_authsafes (p12))) return 0;
143 for (i = 0; i < sk_num (asafes); i++) {
144 p7 = (PKCS7 *) sk_value (asafes, i);
145 bagnid = OBJ_obj2nid (p7->type);
146 if (bagnid == NID_pkcs7_data) {
147 bags = M_PKCS12_unpack_p7data (p7);
148 } else if (bagnid == NID_pkcs7_encrypted) {
149 bags = M_PKCS12_unpack_p7encdata (p7, pass, passlen);
150 } else continue;
151 if (!bags) {
152 sk_pop_free (asafes, PKCS7_free);
153 return 0;
154 }
155 if (!parse_bags(bags, pass, passlen, pkey, cert, ca,
156 &keyid, &keymatch)) {
157 sk_pop_free(bags, PKCS12_SAFEBAG_free);
158 sk_pop_free(asafes, PKCS7_free);
159 return 0;
160 }
161 sk_pop_free(bags, PKCS12_SAFEBAG_free);
162 }
163 sk_pop_free(asafes, PKCS7_free);
164 if (keyid) M_ASN1_OCTET_STRING_free(keyid);
165 return 1;
166}
167
168
169static int parse_bags (STACK *bags, const char *pass, int passlen,
170 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
171 ASN1_OCTET_STRING **keyid, char *keymatch)
172{
173 int i;
174 for (i = 0; i < sk_num(bags); i++) {
175 if (!parse_bag((PKCS12_SAFEBAG *)sk_value (bags, i),
176 pass, passlen, pkey, cert, ca, keyid,
177 keymatch)) return 0;
178 }
179 return 1;
180}
181
182#define MATCH_KEY 0x1
183#define MATCH_CERT 0x2
184#define MATCH_ALL 0x3
185
186static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
187 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
188 ASN1_OCTET_STRING **keyid,
189 char *keymatch)
190{
191 PKCS8_PRIV_KEY_INFO *p8;
192 X509 *x509;
193 ASN1_OCTET_STRING *lkey = NULL;
194 ASN1_TYPE *attrib;
195
196
197 if ((attrib = PKCS12_get_attr (bag, NID_localKeyID)))
198 lkey = attrib->value.octet_string;
199
200 /* Check for any local key id matching (if needed) */
201 if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) {
202 if (*keyid) {
203 if (M_ASN1_OCTET_STRING_cmp(*keyid, lkey)) lkey = NULL;
204 } else {
205 if (!(*keyid = M_ASN1_OCTET_STRING_dup(lkey))) {
206 PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE);
207 return 0;
208 }
209 }
210 }
211
212 switch (M_PKCS12_bag_type(bag))
213 {
214 case NID_keyBag:
215 if (!lkey || !pkey) return 1;
216 if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag))) return 0;
217 *keymatch |= MATCH_KEY;
218 break;
219
220 case NID_pkcs8ShroudedKeyBag:
221 if (!lkey || !pkey) return 1;
222 if (!(p8 = M_PKCS12_decrypt_skey(bag, pass, passlen)))
223 return 0;
224 *pkey = EVP_PKCS82PKEY(p8);
225 PKCS8_PRIV_KEY_INFO_free(p8);
226 if (!(*pkey)) return 0;
227 *keymatch |= MATCH_KEY;
228 break;
229
230 case NID_certBag:
231 if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate )
232 return 1;
233 if (!(x509 = M_PKCS12_certbag2x509(bag))) return 0;
234 if (lkey) {
235 *keymatch |= MATCH_CERT;
236 if (cert) *cert = x509;
237 } else {
238 if(ca) sk_X509_push (*ca, x509);
239 else X509_free(x509);
240 }
241 break;
242
243 case NID_safeContentsBag:
244 return parse_bags(bag->value.safes, pass, passlen,
245 pkey, cert, ca, keyid, keymatch);
246 break;
247
248 default:
249 return 1;
250 break;
251 }
252 return 1;
253}
254
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
deleted file mode 100644
index 369257ed4c..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_mutl.c
+++ /dev/null
@@ -1,173 +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 (!(M_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 = M_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) {
160 if (RAND_pseudo_bytes (p12->mac->salt->data, saltlen) < 0)
161 return 0;
162 }
163 else memcpy (p12->mac->salt->data, salt, saltlen);
164 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type));
165 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) {
166 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
167 return 0;
168 }
169 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL;
170
171 return 1;
172}
173#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c
deleted file mode 100644
index ee71707e2c..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_npas.c
+++ /dev/null
@@ -1,212 +0,0 @@
1/* p12_npas.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64#include <openssl/pkcs12.h>
65
66/* PKCS#12 password change routine */
67
68static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass);
69static int newpass_bags(STACK *bags, char *oldpass, char *newpass);
70static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass);
71static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen);
72
73/*
74 * Change the password on a PKCS#12 structure.
75 */
76
77int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
78{
79
80/* Check for NULL PKCS12 structure */
81
82if(!p12) {
83 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
84 return 0;
85}
86
87/* Check the mac */
88
89if (!PKCS12_verify_mac(p12, oldpass, -1)) {
90 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE);
91 return 0;
92}
93
94if (!newpass_p12(p12, oldpass, newpass)) {
95 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR);
96 return 0;
97}
98
99return 1;
100
101}
102
103/* Parse the outer PKCS#12 structure */
104
105static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass)
106{
107 STACK *asafes, *newsafes, *bags;
108 int i, bagnid, pbe_nid, pbe_iter, pbe_saltlen;
109 PKCS7 *p7, *p7new;
110 ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL;
111 unsigned char mac[EVP_MAX_MD_SIZE];
112 unsigned int maclen;
113 if (!(asafes = M_PKCS12_unpack_authsafes(p12))) return 0;
114 if(!(newsafes = sk_new(NULL))) return 0;
115 for (i = 0; i < sk_num (asafes); i++) {
116 p7 = (PKCS7 *) sk_value(asafes, i);
117 bagnid = OBJ_obj2nid(p7->type);
118 if (bagnid == NID_pkcs7_data) {
119 bags = M_PKCS12_unpack_p7data(p7);
120 } else if (bagnid == NID_pkcs7_encrypted) {
121 bags = M_PKCS12_unpack_p7encdata(p7, oldpass, -1);
122 alg_get(p7->d.encrypted->enc_data->algorithm,
123 &pbe_nid, &pbe_iter, &pbe_saltlen);
124 } else continue;
125 if (!bags) {
126 sk_pop_free(asafes, PKCS7_free);
127 return 0;
128 }
129 if (!newpass_bags(bags, oldpass, newpass)) {
130 sk_pop_free(bags, PKCS12_SAFEBAG_free);
131 sk_pop_free(asafes, PKCS7_free);
132 return 0;
133 }
134 /* Repack bag in same form with new password */
135 if (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags);
136 else p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL,
137 pbe_saltlen, pbe_iter, bags);
138 sk_pop_free(bags, PKCS12_SAFEBAG_free);
139 if(!p7new) {
140 sk_pop_free(asafes, PKCS7_free);
141 return 0;
142 }
143 sk_push(newsafes, (char *)p7new);
144 }
145 sk_pop_free(asafes, PKCS7_free);
146
147 /* Repack safe: save old safe in case of error */
148
149 p12_data_tmp = p12->authsafes->d.data;
150 if(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr;
151 if(!M_PKCS12_pack_authsafes(p12, newsafes)) goto saferr;
152
153 if(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr;
154 if(!(macnew = ASN1_OCTET_STRING_new())) goto saferr;
155 if(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr;
156 ASN1_OCTET_STRING_free(p12->mac->dinfo->digest);
157 p12->mac->dinfo->digest = macnew;
158 ASN1_OCTET_STRING_free(p12_data_tmp);
159
160 return 1;
161
162 saferr:
163 /* Restore old safe */
164 ASN1_OCTET_STRING_free(p12->authsafes->d.data);
165 ASN1_OCTET_STRING_free(macnew);
166 p12->authsafes->d.data = p12_data_tmp;
167 return 0;
168
169}
170
171
172static int newpass_bags(STACK *bags, char *oldpass, char *newpass)
173{
174 int i;
175 for (i = 0; i < sk_num(bags); i++) {
176 if (!newpass_bag((PKCS12_SAFEBAG *)sk_value(bags, i),
177 oldpass, newpass)) return 0;
178 }
179 return 1;
180}
181
182/* Change password of safebag: only needs handle shrouded keybags */
183
184static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass)
185{
186 PKCS8_PRIV_KEY_INFO *p8;
187 X509_SIG *p8new;
188 int p8_nid, p8_saltlen, p8_iter;
189
190 if(M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) return 1;
191
192 if (!(p8 = M_PKCS12_decrypt_skey(bag, oldpass, -1))) return 0;
193 alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter, &p8_saltlen);
194 if(!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen,
195 p8_iter, p8))) return 0;
196 X509_SIG_free(bag->value.shkeybag);
197 bag->value.shkeybag = p8new;
198 return 1;
199}
200
201static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen)
202{
203 PBEPARAM *pbe;
204 unsigned char *p;
205 p = alg->parameter->value.sequence->data;
206 pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length);
207 *pnid = OBJ_obj2nid(alg->algorithm);
208 *piter = ASN1_INTEGER_get(pbe->iter);
209 *psaltlen = pbe->salt->length;
210 PBEPARAM_free(pbe);
211 return 0;
212}
diff --git a/src/lib/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 12db54f49e..0000000000
--- a/src/lib/libcrypto/pkcs12/pk12err.c
+++ /dev/null
@@ -1,139 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/pkcs12.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA PKCS12_str_functs[]=
68 {
69{ERR_PACK(0,PKCS12_F_PARSE_BAGS,0), "PARSE_BAGS"},
70{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME,0), "PKCS12_ADD_FRIENDLYNAME"},
71{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC,0), "PKCS12_add_friendlyname_asc"},
72{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,0), "PKCS12_add_friendlyname_uni"},
73{ERR_PACK(0,PKCS12_F_PKCS12_ADD_LOCALKEYID,0), "PKCS12_add_localkeyid"},
74{ERR_PACK(0,PKCS12_F_PKCS12_CREATE,0), "PKCS12_create"},
75{ERR_PACK(0,PKCS12_F_PKCS12_DECRYPT_D2I,0), "PKCS12_decrypt_d2i"},
76{ERR_PACK(0,PKCS12_F_PKCS12_GEN_MAC,0), "PKCS12_gen_mac"},
77{ERR_PACK(0,PKCS12_F_PKCS12_I2D_ENCRYPT,0), "PKCS12_i2d_encrypt"},
78{ERR_PACK(0,PKCS12_F_PKCS12_INIT,0), "PKCS12_init"},
79{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_ASC,0), "PKCS12_key_gen_asc"},
80{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_UNI,0), "PKCS12_key_gen_uni"},
81{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_KEYBAG,0), "PKCS12_MAKE_KEYBAG"},
82{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_SHKEYBAG,0), "PKCS12_MAKE_SHKEYBAG"},
83{ERR_PACK(0,PKCS12_F_PKCS12_NEWPASS,0), "PKCS12_newpass"},
84{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7DATA,0), "PKCS12_pack_p7data"},
85{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7ENCDATA,0), "PKCS12_pack_p7encdata"},
86{ERR_PACK(0,PKCS12_F_PKCS12_PACK_SAFEBAG,0), "PKCS12_pack_safebag"},
87{ERR_PACK(0,PKCS12_F_PKCS12_PARSE,0), "PKCS12_parse"},
88{ERR_PACK(0,PKCS12_F_PKCS12_PBE_CRYPT,0), "PKCS12_pbe_crypt"},
89{ERR_PACK(0,PKCS12_F_PKCS12_PBE_KEYIVGEN,0), "PKCS12_PBE_keyivgen"},
90{ERR_PACK(0,PKCS12_F_PKCS12_SETUP_MAC,0), "PKCS12_setup_mac"},
91{ERR_PACK(0,PKCS12_F_PKCS12_SET_MAC,0), "PKCS12_set_mac"},
92{ERR_PACK(0,PKCS12_F_PKCS8_ADD_KEYUSAGE,0), "PKCS8_add_keyusage"},
93{ERR_PACK(0,PKCS12_F_PKCS8_ENCRYPT,0), "PKCS8_encrypt"},
94{ERR_PACK(0,PKCS12_F_VERIFY_MAC,0), "VERIFY_MAC"},
95{0,NULL}
96 };
97
98static ERR_STRING_DATA PKCS12_str_reasons[]=
99 {
100{PKCS12_R_CANT_PACK_STRUCTURE ,"cant pack structure"},
101{PKCS12_R_DECODE_ERROR ,"decode error"},
102{PKCS12_R_ENCODE_ERROR ,"encode error"},
103{PKCS12_R_ENCRYPT_ERROR ,"encrypt error"},
104{PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE,"error setting encrypted data type"},
105{PKCS12_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
106{PKCS12_R_INVALID_NULL_PKCS12_POINTER ,"invalid null pkcs12 pointer"},
107{PKCS12_R_IV_GEN_ERROR ,"iv gen error"},
108{PKCS12_R_KEY_GEN_ERROR ,"key gen error"},
109{PKCS12_R_MAC_ABSENT ,"mac absent"},
110{PKCS12_R_MAC_GENERATION_ERROR ,"mac generation error"},
111{PKCS12_R_MAC_SETUP_ERROR ,"mac setup error"},
112{PKCS12_R_MAC_STRING_SET_ERROR ,"mac string set error"},
113{PKCS12_R_MAC_VERIFY_ERROR ,"mac verify error"},
114{PKCS12_R_MAC_VERIFY_FAILURE ,"mac verify failure"},
115{PKCS12_R_PARSE_ERROR ,"parse error"},
116{PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR ,"pkcs12 algor cipherinit error"},
117{PKCS12_R_PKCS12_CIPHERFINAL_ERROR ,"pkcs12 cipherfinal error"},
118{PKCS12_R_PKCS12_PBE_CRYPT_ERROR ,"pkcs12 pbe crypt error"},
119{PKCS12_R_UNKNOWN_DIGEST_ALGORITHM ,"unknown digest algorithm"},
120{PKCS12_R_UNSUPPORTED_PKCS12_MODE ,"unsupported pkcs12 mode"},
121{0,NULL}
122 };
123
124#endif
125
126void ERR_load_PKCS12_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_PKCS12,PKCS12_str_functs);
135 ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_reasons);
136#endif
137
138 }
139 }
diff --git a/src/lib/libcrypto/pkcs12/pkcs12.h b/src/lib/libcrypto/pkcs12/pkcs12.h
deleted file mode 100644
index dad356c00f..0000000000
--- a/src/lib/libcrypto/pkcs12/pkcs12.h
+++ /dev/null
@@ -1,340 +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_OF(X509) **ca);
269PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
270 STACK_OF(X509) *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);
276int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
277
278/* BEGIN ERROR CODES */
279/* The following lines are auto generated by the script mkerr.pl. Any changes
280 * made after this point may be overwritten when the script is next run.
281 */
282
283/* Error codes for the PKCS12 functions. */
284
285/* Function codes. */
286#define PKCS12_F_PARSE_BAGS 103
287#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100
288#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127
289#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102
290#define PKCS12_F_PKCS12_ADD_LOCALKEYID 104
291#define PKCS12_F_PKCS12_CREATE 105
292#define PKCS12_F_PKCS12_DECRYPT_D2I 106
293#define PKCS12_F_PKCS12_GEN_MAC 107
294#define PKCS12_F_PKCS12_I2D_ENCRYPT 108
295#define PKCS12_F_PKCS12_INIT 109
296#define PKCS12_F_PKCS12_KEY_GEN_ASC 110
297#define PKCS12_F_PKCS12_KEY_GEN_UNI 111
298#define PKCS12_F_PKCS12_MAKE_KEYBAG 112
299#define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113
300#define PKCS12_F_PKCS12_NEWPASS 128
301#define PKCS12_F_PKCS12_PACK_P7DATA 114
302#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115
303#define PKCS12_F_PKCS12_PACK_SAFEBAG 117
304#define PKCS12_F_PKCS12_PARSE 118
305#define PKCS12_F_PKCS12_PBE_CRYPT 119
306#define PKCS12_F_PKCS12_PBE_KEYIVGEN 120
307#define PKCS12_F_PKCS12_SETUP_MAC 122
308#define PKCS12_F_PKCS12_SET_MAC 123
309#define PKCS12_F_PKCS8_ADD_KEYUSAGE 124
310#define PKCS12_F_PKCS8_ENCRYPT 125
311#define PKCS12_F_VERIFY_MAC 126
312
313/* Reason codes. */
314#define PKCS12_R_CANT_PACK_STRUCTURE 100
315#define PKCS12_R_DECODE_ERROR 101
316#define PKCS12_R_ENCODE_ERROR 102
317#define PKCS12_R_ENCRYPT_ERROR 103
318#define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120
319#define PKCS12_R_INVALID_NULL_ARGUMENT 104
320#define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105
321#define PKCS12_R_IV_GEN_ERROR 106
322#define PKCS12_R_KEY_GEN_ERROR 107
323#define PKCS12_R_MAC_ABSENT 108
324#define PKCS12_R_MAC_GENERATION_ERROR 109
325#define PKCS12_R_MAC_SETUP_ERROR 110
326#define PKCS12_R_MAC_STRING_SET_ERROR 111
327#define PKCS12_R_MAC_VERIFY_ERROR 112
328#define PKCS12_R_MAC_VERIFY_FAILURE 113
329#define PKCS12_R_PARSE_ERROR 114
330#define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115
331#define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116
332#define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117
333#define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118
334#define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119
335
336#ifdef __cplusplus
337}
338#endif
339#endif
340
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
deleted file mode 100644
index 3b9c0fe3f2..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_attr.c
+++ /dev/null
@@ -1,85 +0,0 @@
1/* pk7_attr.c */
2/* S/MIME code.
3 * Copyright (C) 1997-8 Dr S N Henson (shenson@bigfoot.com)
4 * All Rights Reserved.
5 * Redistribution of this code without the authors permission is expressly
6 * prohibited.
7 */
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <openssl/bio.h>
12#include <openssl/asn1.h>
13#include <openssl/pem.h>
14#include <openssl/pkcs7.h>
15#include <openssl/err.h>
16
17int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK *cap)
18{
19 ASN1_STRING *seq;
20 unsigned char *p, *pp;
21 int len;
22 len=i2d_ASN1_SET(cap,NULL,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
23 V_ASN1_UNIVERSAL, IS_SEQUENCE);
24 if(!(pp=(unsigned char *)Malloc(len))) {
25 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
26 return 0;
27 }
28 p=pp;
29 i2d_ASN1_SET(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
30 V_ASN1_UNIVERSAL, IS_SEQUENCE);
31 if(!(seq = ASN1_STRING_new())) {
32 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
33 return 0;
34 }
35 if(!ASN1_STRING_set (seq, pp, len)) {
36 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
37 return 0;
38 }
39 Free (pp);
40 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
41 V_ASN1_SEQUENCE, seq);
42}
43
44STACK *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
45{
46 ASN1_TYPE *cap;
47 unsigned char *p;
48 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities);
49 if (!cap) return NULL;
50 p = cap->value.sequence->data;
51 return d2i_ASN1_SET (NULL, &p, cap->value.sequence->length,
52 (char *(*)())d2i_X509_ALGOR, X509_ALGOR_free, V_ASN1_SEQUENCE,
53 V_ASN1_UNIVERSAL);
54}
55
56/* Basic smime-capabilities OID and optional integer arg */
57int PKCS7_simple_smimecap(STACK *sk, int nid, int arg)
58{
59 X509_ALGOR *alg;
60 if(!(alg = X509_ALGOR_new())) {
61 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
62 return 0;
63 }
64 ASN1_OBJECT_free(alg->algorithm);
65 alg->algorithm = OBJ_nid2obj (nid);
66 if (arg > 0) {
67 ASN1_INTEGER *nbit;
68 if(!(alg->parameter = ASN1_TYPE_new())) {
69 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
70 return 0;
71 }
72 if(!(nbit = ASN1_INTEGER_new())) {
73 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
74 return 0;
75 }
76 if(!ASN1_INTEGER_set (nbit, arg)) {
77 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 alg->parameter->value.integer = nbit;
81 alg->parameter->type = V_ASN1_INTEGER;
82 }
83 sk_push (sk, (char *)alg);
84 return 1;
85}
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
deleted file mode 100644
index 4ab24a86f5..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ /dev/null
@@ -1,960 +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#include <openssl/x509v3.h>
65
66static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
67 void *value);
68static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid);
69
70BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
71 {
72 int i,j;
73 BIO *out=NULL,*btmp=NULL;
74 X509_ALGOR *xa;
75 const EVP_MD *evp_md;
76 const EVP_CIPHER *evp_cipher=NULL;
77 STACK_OF(X509_ALGOR) *md_sk=NULL;
78 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
79 X509_ALGOR *xalg=NULL;
80 PKCS7_RECIP_INFO *ri=NULL;
81 EVP_PKEY *pkey;
82
83 i=OBJ_obj2nid(p7->type);
84 p7->state=PKCS7_S_HEADER;
85
86 switch (i)
87 {
88 case NID_pkcs7_signed:
89 md_sk=p7->d.sign->md_algs;
90 break;
91 case NID_pkcs7_signedAndEnveloped:
92 rsk=p7->d.signed_and_enveloped->recipientinfo;
93 md_sk=p7->d.signed_and_enveloped->md_algs;
94 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
95 evp_cipher=p7->d.signed_and_enveloped->enc_data->cipher;
96 if (evp_cipher == NULL)
97 {
98 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
99 PKCS7_R_CIPHER_NOT_INITIALIZED);
100 goto err;
101 }
102 break;
103 case NID_pkcs7_enveloped:
104 rsk=p7->d.enveloped->recipientinfo;
105 xalg=p7->d.enveloped->enc_data->algorithm;
106 evp_cipher=p7->d.enveloped->enc_data->cipher;
107 if (evp_cipher == NULL)
108 {
109 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
110 PKCS7_R_CIPHER_NOT_INITIALIZED);
111 goto err;
112 }
113 break;
114 default:
115 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
116 goto err;
117 }
118
119 if (md_sk != NULL)
120 {
121 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
122 {
123 xa=sk_X509_ALGOR_value(md_sk,i);
124 if ((btmp=BIO_new(BIO_f_md())) == NULL)
125 {
126 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
127 goto err;
128 }
129
130 j=OBJ_obj2nid(xa->algorithm);
131 evp_md=EVP_get_digestbyname(OBJ_nid2sn(j));
132 if (evp_md == NULL)
133 {
134 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNKNOWN_DIGEST_TYPE);
135 goto err;
136 }
137
138 BIO_set_md(btmp,evp_md);
139 if (out == NULL)
140 out=btmp;
141 else
142 BIO_push(out,btmp);
143 btmp=NULL;
144 }
145 }
146
147 if (evp_cipher != NULL)
148 {
149 unsigned char key[EVP_MAX_KEY_LENGTH];
150 unsigned char iv[EVP_MAX_IV_LENGTH];
151 int keylen,ivlen;
152 int jj,max;
153 unsigned char *tmp;
154 EVP_CIPHER_CTX *ctx;
155
156 if ((btmp=BIO_new(BIO_f_cipher())) == NULL)
157 {
158 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
159 goto err;
160 }
161 BIO_get_cipher_ctx(btmp, &ctx);
162 keylen=EVP_CIPHER_key_length(evp_cipher);
163 ivlen=EVP_CIPHER_iv_length(evp_cipher);
164 if (RAND_bytes(key,keylen) <= 0)
165 goto err;
166 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
167 if (ivlen > 0) RAND_pseudo_bytes(iv,ivlen);
168 EVP_CipherInit(ctx, evp_cipher, key, iv, 1);
169
170 if (ivlen > 0) {
171 if (xalg->parameter == NULL)
172 xalg->parameter=ASN1_TYPE_new();
173 if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0)
174 goto err;
175 }
176
177 /* Lets do the pub key stuff :-) */
178 max=0;
179 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
180 {
181 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
182 if (ri->cert == NULL)
183 {
184 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO);
185 goto err;
186 }
187 pkey=X509_get_pubkey(ri->cert);
188 jj=EVP_PKEY_size(pkey);
189 EVP_PKEY_free(pkey);
190 if (max < jj) max=jj;
191 }
192 if ((tmp=(unsigned char *)Malloc(max)) == NULL)
193 {
194 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_MALLOC_FAILURE);
195 goto err;
196 }
197 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
198 {
199 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
200 pkey=X509_get_pubkey(ri->cert);
201 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
202 EVP_PKEY_free(pkey);
203 if (jj <= 0)
204 {
205 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB);
206 Free(tmp);
207 goto err;
208 }
209 M_ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj);
210 }
211 Free(tmp);
212 memset(key, 0, keylen);
213
214 if (out == NULL)
215 out=btmp;
216 else
217 BIO_push(out,btmp);
218 btmp=NULL;
219 }
220
221 if (bio == NULL) {
222 if (p7->detached)
223 bio=BIO_new(BIO_s_null());
224 else {
225 if (PKCS7_type_is_signed(p7) &&
226 PKCS7_type_is_data(p7->d.sign->contents)) {
227 ASN1_OCTET_STRING *os;
228 os=p7->d.sign->contents->d.data;
229 if (os->length > 0) bio =
230 BIO_new_mem_buf(os->data, os->length);
231 }
232 if(bio == NULL) {
233 bio=BIO_new(BIO_s_mem());
234 BIO_set_mem_eof_return(bio,0);
235 }
236 }
237 }
238 BIO_push(out,bio);
239 bio=NULL;
240 if (0)
241 {
242err:
243 if (out != NULL)
244 BIO_free_all(out);
245 if (btmp != NULL)
246 BIO_free_all(btmp);
247 out=NULL;
248 }
249 return(out);
250 }
251
252/* int */
253BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
254 {
255 int i,j;
256 BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
257 unsigned char *tmp=NULL;
258 X509_ALGOR *xa;
259 ASN1_OCTET_STRING *data_body=NULL;
260 const EVP_MD *evp_md;
261 const EVP_CIPHER *evp_cipher=NULL;
262 EVP_CIPHER_CTX *evp_ctx=NULL;
263 X509_ALGOR *enc_alg=NULL;
264 STACK_OF(X509_ALGOR) *md_sk=NULL;
265 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
266 X509_ALGOR *xalg=NULL;
267 PKCS7_RECIP_INFO *ri=NULL;
268#ifndef NO_RC2
269 char is_rc2 = 0;
270#endif
271/* EVP_PKEY *pkey; */
272#if 0
273 X509_STORE_CTX s_ctx;
274#endif
275
276 i=OBJ_obj2nid(p7->type);
277 p7->state=PKCS7_S_HEADER;
278
279 switch (i)
280 {
281 case NID_pkcs7_signed:
282 data_body=p7->d.sign->contents->d.data;
283 md_sk=p7->d.sign->md_algs;
284 break;
285 case NID_pkcs7_signedAndEnveloped:
286 rsk=p7->d.signed_and_enveloped->recipientinfo;
287 md_sk=p7->d.signed_and_enveloped->md_algs;
288 data_body=p7->d.signed_and_enveloped->enc_data->enc_data;
289 enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;
290 evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm)));
291 if (evp_cipher == NULL)
292 {
293 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
294 goto err;
295 }
296 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
297 break;
298 case NID_pkcs7_enveloped:
299 rsk=p7->d.enveloped->recipientinfo;
300 enc_alg=p7->d.enveloped->enc_data->algorithm;
301 data_body=p7->d.enveloped->enc_data->enc_data;
302 evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm)));
303 if (evp_cipher == NULL)
304 {
305 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
306 goto err;
307 }
308 xalg=p7->d.enveloped->enc_data->algorithm;
309 break;
310 default:
311 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
312 goto err;
313 }
314
315 if(EVP_CIPHER_nid(evp_cipher) == NID_rc2_cbc)
316 {
317#ifndef NO_RC2
318 is_rc2 = 1;
319#else
320 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
321 goto err;
322#endif
323 }
324
325 /* We will be checking the signature */
326 if (md_sk != NULL)
327 {
328 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
329 {
330 xa=sk_X509_ALGOR_value(md_sk,i);
331 if ((btmp=BIO_new(BIO_f_md())) == NULL)
332 {
333 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
334 goto err;
335 }
336
337 j=OBJ_obj2nid(xa->algorithm);
338 evp_md=EVP_get_digestbyname(OBJ_nid2sn(j));
339 if (evp_md == NULL)
340 {
341 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);
342 goto err;
343 }
344
345 BIO_set_md(btmp,evp_md);
346 if (out == NULL)
347 out=btmp;
348 else
349 BIO_push(out,btmp);
350 btmp=NULL;
351 }
352 }
353
354 if (evp_cipher != NULL)
355 {
356#if 0
357 unsigned char key[EVP_MAX_KEY_LENGTH];
358 unsigned char iv[EVP_MAX_IV_LENGTH];
359 unsigned char *p;
360 int keylen,ivlen;
361 int max;
362 X509_OBJECT ret;
363#endif
364 int jj;
365
366 if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
367 {
368 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
369 goto err;
370 }
371
372 /* It was encrypted, we need to decrypt the secret key
373 * with the private key */
374
375 /* Find the recipientInfo which matches the passed certificate
376 * (if any)
377 */
378
379 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
380 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
381 if(!X509_NAME_cmp(ri->issuer_and_serial->issuer,
382 pcert->cert_info->issuer) &&
383 !M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
384 ri->issuer_and_serial->serial)) break;
385 ri=NULL;
386 }
387 if (ri == NULL) {
388 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
389 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
390 return(NULL);
391 }
392
393 jj=EVP_PKEY_size(pkey);
394 tmp=(unsigned char *)Malloc(jj+10);
395 if (tmp == NULL)
396 {
397 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
398 goto err;
399 }
400
401 jj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key),
402 M_ASN1_STRING_length(ri->enc_key), pkey);
403 if (jj <= 0)
404 {
405 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);
406 goto err;
407 }
408
409 evp_ctx=NULL;
410 BIO_get_cipher_ctx(etmp,&evp_ctx);
411 EVP_CipherInit(evp_ctx,evp_cipher,NULL,NULL,0);
412 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
413 return(NULL);
414
415 if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) {
416 /* HACK: some S/MIME clients don't use the same key
417 * and effective key length. The key length is
418 * determined by the size of the decrypted RSA key.
419 * So we hack things to manually set the RC2 key
420 * because we currently can't do this with the EVP
421 * interface.
422 */
423#ifndef NO_RC2
424 if(is_rc2) RC2_set_key(&(evp_ctx->c.rc2_ks),jj, tmp,
425 EVP_CIPHER_CTX_key_length(evp_ctx)*8);
426 else
427#endif
428 {
429 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
430 PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
431 goto err;
432 }
433 } else EVP_CipherInit(evp_ctx,NULL,tmp,NULL,0);
434
435 memset(tmp,0,jj);
436
437 if (out == NULL)
438 out=etmp;
439 else
440 BIO_push(out,etmp);
441 etmp=NULL;
442 }
443
444#if 1
445 if (p7->detached || (in_bio != NULL))
446 {
447 bio=in_bio;
448 }
449 else
450 {
451#if 0
452 bio=BIO_new(BIO_s_mem());
453 /* We need to set this so that when we have read all
454 * the data, the encrypt BIO, if present, will read
455 * EOF and encode the last few bytes */
456 BIO_set_mem_eof_return(bio,0);
457
458 if (data_body->length > 0)
459 BIO_write(bio,(char *)data_body->data,data_body->length);
460#else
461 if (data_body->length > 0)
462 bio = BIO_new_mem_buf(data_body->data,data_body->length);
463 else {
464 bio=BIO_new(BIO_s_mem());
465 BIO_set_mem_eof_return(bio,0);
466 }
467#endif
468 }
469 BIO_push(out,bio);
470 bio=NULL;
471#endif
472 if (0)
473 {
474err:
475 if (out != NULL) BIO_free_all(out);
476 if (btmp != NULL) BIO_free_all(btmp);
477 if (etmp != NULL) BIO_free_all(etmp);
478 if (bio != NULL) BIO_free_all(bio);
479 out=NULL;
480 }
481 if (tmp != NULL)
482 Free(tmp);
483 return(out);
484 }
485
486int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
487 {
488 int ret=0;
489 int i,j;
490 BIO *btmp;
491 BUF_MEM *buf_mem=NULL;
492 BUF_MEM *buf=NULL;
493 PKCS7_SIGNER_INFO *si;
494 EVP_MD_CTX *mdc,ctx_tmp;
495 STACK_OF(X509_ATTRIBUTE) *sk;
496 STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL;
497 unsigned char *p,*pp=NULL;
498 int x;
499 ASN1_OCTET_STRING *os=NULL;
500
501 i=OBJ_obj2nid(p7->type);
502 p7->state=PKCS7_S_HEADER;
503
504 switch (i)
505 {
506 case NID_pkcs7_signedAndEnveloped:
507 /* XXXXXXXXXXXXXXXX */
508 si_sk=p7->d.signed_and_enveloped->signer_info;
509 os=M_ASN1_OCTET_STRING_new();
510 p7->d.signed_and_enveloped->enc_data->enc_data=os;
511 break;
512 case NID_pkcs7_enveloped:
513 /* XXXXXXXXXXXXXXXX */
514 os=M_ASN1_OCTET_STRING_new();
515 p7->d.enveloped->enc_data->enc_data=os;
516 break;
517 case NID_pkcs7_signed:
518 si_sk=p7->d.sign->signer_info;
519 os=p7->d.sign->contents->d.data;
520 /* If detached data then the content is excluded */
521 if(p7->detached) {
522 M_ASN1_OCTET_STRING_free(os);
523 p7->d.sign->contents->d.data = NULL;
524 }
525 break;
526 }
527
528 if (si_sk != NULL)
529 {
530 if ((buf=BUF_MEM_new()) == NULL)
531 {
532 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
533 goto err;
534 }
535 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
536 {
537 si=sk_PKCS7_SIGNER_INFO_value(si_sk,i);
538 if (si->pkey == NULL) continue;
539
540 j=OBJ_obj2nid(si->digest_alg->algorithm);
541
542 btmp=bio;
543 for (;;)
544 {
545 if ((btmp=BIO_find_type(btmp,BIO_TYPE_MD))
546 == NULL)
547 {
548 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
549 goto err;
550 }
551 BIO_get_md_ctx(btmp,&mdc);
552 if (mdc == NULL)
553 {
554 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR);
555 goto err;
556 }
557 if (EVP_MD_CTX_type(mdc) == j)
558 break;
559 else
560 btmp=btmp->next_bio;
561 }
562
563 /* We now have the EVP_MD_CTX, lets do the
564 * signing. */
565 memcpy(&ctx_tmp,mdc,sizeof(ctx_tmp));
566 if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey)))
567 {
568 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
569 goto err;
570 }
571
572 sk=si->auth_attr;
573
574 /* If there are attributes, we add the digest
575 * attribute and only sign the attributes */
576 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
577 {
578 unsigned char md_data[EVP_MAX_MD_SIZE];
579 unsigned int md_len;
580 ASN1_OCTET_STRING *digest;
581 ASN1_UTCTIME *sign_time;
582 const EVP_MD *md_tmp;
583
584 /* Add signing time */
585 sign_time=X509_gmtime_adj(NULL,0);
586 PKCS7_add_signed_attribute(si,
587 NID_pkcs9_signingTime,
588 V_ASN1_UTCTIME,sign_time);
589
590 /* Add digest */
591 md_tmp=EVP_MD_CTX_md(&ctx_tmp);
592 EVP_DigestFinal(&ctx_tmp,md_data,&md_len);
593 digest=M_ASN1_OCTET_STRING_new();
594 M_ASN1_OCTET_STRING_set(digest,md_data,md_len);
595 PKCS7_add_signed_attribute(si,
596 NID_pkcs9_messageDigest,
597 V_ASN1_OCTET_STRING,digest);
598
599 /* Now sign the mess */
600 EVP_SignInit(&ctx_tmp,md_tmp);
601 x=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,
602 i2d_X509_ATTRIBUTE,
603 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
604 pp=(unsigned char *)Malloc(x);
605 p=pp;
606 i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,
607 i2d_X509_ATTRIBUTE,
608 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
609 EVP_SignUpdate(&ctx_tmp,pp,x);
610 Free(pp);
611 pp=NULL;
612 }
613
614 if (si->pkey->type == EVP_PKEY_DSA)
615 ctx_tmp.digest=EVP_dss1();
616
617 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data,
618 (unsigned int *)&buf->length,si->pkey))
619 {
620 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_EVP_LIB);
621 goto err;
622 }
623 if (!ASN1_STRING_set(si->enc_digest,
624 (unsigned char *)buf->data,buf->length))
625 {
626 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_ASN1_LIB);
627 goto err;
628 }
629 }
630 }
631
632 if (!p7->detached)
633 {
634 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
635 if (btmp == NULL)
636 {
637 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
638 goto err;
639 }
640 BIO_get_mem_ptr(btmp,&buf_mem);
641 /* Mark the BIO read only then we can use its copy of the data
642 * instead of making an extra copy.
643 */
644 BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
645 BIO_set_mem_eof_return(btmp, 0);
646 os->data = (unsigned char *)buf_mem->data;
647 os->length = buf_mem->length;
648#if 0
649 M_ASN1_OCTET_STRING_set(os,
650 (unsigned char *)buf_mem->data,buf_mem->length);
651#endif
652 }
653 if (pp != NULL) Free(pp);
654 pp=NULL;
655
656 ret=1;
657err:
658 if (buf != NULL) BUF_MEM_free(buf);
659 return(ret);
660 }
661
662int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
663 PKCS7 *p7, PKCS7_SIGNER_INFO *si)
664 {
665 PKCS7_ISSUER_AND_SERIAL *ias;
666 int ret=0,i;
667 STACK_OF(X509) *cert;
668 X509 *x509;
669
670 if (PKCS7_type_is_signed(p7))
671 {
672 cert=p7->d.sign->cert;
673 }
674 else if (PKCS7_type_is_signedAndEnveloped(p7))
675 {
676 cert=p7->d.signed_and_enveloped->cert;
677 }
678 else
679 {
680 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE);
681 goto err;
682 }
683 /* XXXXXXXXXXXXXXXXXXXXXXX */
684 ias=si->issuer_and_serial;
685
686 x509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial);
687
688 /* were we able to find the cert in passed to us */
689 if (x509 == NULL)
690 {
691 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
692 goto err;
693 }
694
695 /* Lets verify */
696 X509_STORE_CTX_init(ctx,cert_store,x509,cert);
697 X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN);
698 i=X509_verify_cert(ctx);
699 if (i <= 0)
700 {
701 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
702 X509_STORE_CTX_cleanup(ctx);
703 goto err;
704 }
705 X509_STORE_CTX_cleanup(ctx);
706
707 return PKCS7_signatureVerify(bio, p7, si, x509);
708 err:
709 return ret;
710 }
711
712int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
713 X509 *x509)
714 {
715 ASN1_OCTET_STRING *os;
716 EVP_MD_CTX mdc_tmp,*mdc;
717 unsigned char *pp,*p;
718 int ret=0,i;
719 int md_type;
720 STACK_OF(X509_ATTRIBUTE) *sk;
721 BIO *btmp;
722 EVP_PKEY *pkey;
723
724 if (!PKCS7_type_is_signed(p7) &&
725 !PKCS7_type_is_signedAndEnveloped(p7)) {
726 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
727 PKCS7_R_WRONG_PKCS7_TYPE);
728 goto err;
729 }
730
731 md_type=OBJ_obj2nid(si->digest_alg->algorithm);
732
733 btmp=bio;
734 for (;;)
735 {
736 if ((btmp == NULL) ||
737 ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))
738 {
739 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
740 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
741 goto err;
742 }
743 BIO_get_md_ctx(btmp,&mdc);
744 if (mdc == NULL)
745 {
746 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
747 PKCS7_R_INTERNAL_ERROR);
748 goto err;
749 }
750 if (EVP_MD_CTX_type(mdc) == md_type)
751 break;
752 btmp=btmp->next_bio;
753 }
754
755 /* mdc is the digest ctx that we want, unless there are attributes,
756 * in which case the digest is the signed attributes */
757 memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp));
758
759 sk=si->auth_attr;
760 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
761 {
762 unsigned char md_dat[EVP_MAX_MD_SIZE];
763 unsigned int md_len;
764 ASN1_OCTET_STRING *message_digest;
765
766 EVP_DigestFinal(&mdc_tmp,md_dat,&md_len);
767 message_digest=PKCS7_digest_from_attributes(sk);
768 if (!message_digest)
769 {
770 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
771 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
772 goto err;
773 }
774 if ((message_digest->length != (int)md_len) ||
775 (memcmp(message_digest->data,md_dat,md_len)))
776 {
777#if 0
778{
779int ii;
780for (ii=0; ii<message_digest->length; ii++)
781 printf("%02X",message_digest->data[ii]); printf(" sent\n");
782for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
783}
784#endif
785 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
786 PKCS7_R_DIGEST_FAILURE);
787 ret= -1;
788 goto err;
789 }
790
791 EVP_VerifyInit(&mdc_tmp,EVP_get_digestbynid(md_type));
792 /* Note: when forming the encoding of the attributes we
793 * shouldn't reorder them or this will break the signature.
794 * This is done by using the IS_SEQUENCE flag.
795 */
796 i=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,i2d_X509_ATTRIBUTE,
797 V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);
798 pp=Malloc(i);
799 p=pp;
800 i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,i2d_X509_ATTRIBUTE,
801 V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);
802 EVP_VerifyUpdate(&mdc_tmp,pp,i);
803
804 Free(pp);
805 }
806
807 os=si->enc_digest;
808 pkey = X509_get_pubkey(x509);
809 if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();
810
811 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);
812 EVP_PKEY_free(pkey);
813 if (i <= 0)
814 {
815 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
816 PKCS7_R_SIGNATURE_FAILURE);
817 ret= -1;
818 goto err;
819 }
820 else
821 ret=1;
822err:
823 return(ret);
824 }
825
826PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx)
827 {
828 STACK_OF(PKCS7_RECIP_INFO) *rsk;
829 PKCS7_RECIP_INFO *ri;
830 int i;
831
832 i=OBJ_obj2nid(p7->type);
833 if (i != NID_pkcs7_signedAndEnveloped) return(NULL);
834 rsk=p7->d.signed_and_enveloped->recipientinfo;
835 ri=sk_PKCS7_RECIP_INFO_value(rsk,0);
836 if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL);
837 ri=sk_PKCS7_RECIP_INFO_value(rsk,idx);
838 return(ri->issuer_and_serial);
839 }
840
841ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid)
842 {
843 return(get_attribute(si->auth_attr,nid));
844 }
845
846ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
847 {
848 return(get_attribute(si->unauth_attr,nid));
849 }
850
851static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid)
852 {
853 int i;
854 X509_ATTRIBUTE *xa;
855 ASN1_OBJECT *o;
856
857 o=OBJ_nid2obj(nid);
858 if (!o || !sk) return(NULL);
859 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
860 {
861 xa=sk_X509_ATTRIBUTE_value(sk,i);
862 if (OBJ_cmp(xa->object,o) == 0)
863 {
864 if (xa->set && sk_ASN1_TYPE_num(xa->value.set))
865 return(sk_ASN1_TYPE_value(xa->value.set,0));
866 else
867 return(NULL);
868 }
869 }
870 return(NULL);
871 }
872
873ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
874{
875 ASN1_TYPE *astype;
876 if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL;
877 return astype->value.octet_string;
878}
879
880int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
881 STACK_OF(X509_ATTRIBUTE) *sk)
882 {
883 int i;
884
885 if (p7si->auth_attr != NULL)
886 sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
887 p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk);
888 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
889 {
890 if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i,
891 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
892 == NULL)
893 return(0);
894 }
895 return(1);
896 }
897
898int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk)
899 {
900 int i;
901
902 if (p7si->unauth_attr != NULL)
903 sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr,
904 X509_ATTRIBUTE_free);
905 p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk);
906 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
907 {
908 if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i,
909 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
910 == NULL)
911 return(0);
912 }
913 return(1);
914 }
915
916int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
917 void *value)
918 {
919 return(add_attribute(&(p7si->auth_attr),nid,atrtype,value));
920 }
921
922int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
923 void *value)
924 {
925 return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value));
926 }
927
928static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
929 void *value)
930 {
931 X509_ATTRIBUTE *attr=NULL;
932
933 if (*sk == NULL)
934 {
935 *sk = sk_X509_ATTRIBUTE_new(NULL);
936new_attrib:
937 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
938 sk_X509_ATTRIBUTE_push(*sk,attr);
939 }
940 else
941 {
942 int i;
943
944 for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++)
945 {
946 attr=sk_X509_ATTRIBUTE_value(*sk,i);
947 if (OBJ_obj2nid(attr->object) == nid)
948 {
949 X509_ATTRIBUTE_free(attr);
950 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
951 sk_X509_ATTRIBUTE_set(*sk,i,attr);
952 goto end;
953 }
954 }
955 goto new_attrib;
956 }
957end:
958 return(1);
959 }
960
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
deleted file mode 100644
index 45973fe850..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ /dev/null
@@ -1,469 +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_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=M_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 break;
169 case NID_pkcs7_enveloped:
170 p7->type=obj;
171 if ((p7->d.enveloped=PKCS7_ENVELOPE_new())
172 == NULL) goto err;
173 ASN1_INTEGER_set(p7->d.enveloped->version,0);
174 break;
175 case NID_pkcs7_encrypted:
176 p7->type=obj;
177 if ((p7->d.encrypted=PKCS7_ENCRYPT_new())
178 == NULL) goto err;
179 ASN1_INTEGER_set(p7->d.encrypted->version,0);
180 break;
181
182 case NID_pkcs7_digest:
183 default:
184 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
185 goto err;
186 }
187 return(1);
188err:
189 return(0);
190 }
191
192int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
193 {
194 int i,j,nid;
195 X509_ALGOR *alg;
196 STACK_OF(PKCS7_SIGNER_INFO) *signer_sk;
197 STACK_OF(X509_ALGOR) *md_sk;
198
199 i=OBJ_obj2nid(p7->type);
200 switch (i)
201 {
202 case NID_pkcs7_signed:
203 signer_sk= p7->d.sign->signer_info;
204 md_sk= p7->d.sign->md_algs;
205 break;
206 case NID_pkcs7_signedAndEnveloped:
207 signer_sk= p7->d.signed_and_enveloped->signer_info;
208 md_sk= p7->d.signed_and_enveloped->md_algs;
209 break;
210 default:
211 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,PKCS7_R_WRONG_CONTENT_TYPE);
212 return(0);
213 }
214
215 nid=OBJ_obj2nid(psi->digest_alg->algorithm);
216
217 /* If the digest is not currently listed, add it */
218 j=0;
219 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
220 {
221 alg=sk_X509_ALGOR_value(md_sk,i);
222 if (OBJ_obj2nid(alg->algorithm) == nid)
223 {
224 j=1;
225 break;
226 }
227 }
228 if (!j) /* we need to add another algorithm */
229 {
230 if(!(alg=X509_ALGOR_new())
231 || !(alg->parameter = ASN1_TYPE_new())) {
232 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE);
233 return(0);
234 }
235 alg->algorithm=OBJ_nid2obj(nid);
236 alg->parameter->type = V_ASN1_NULL;
237 sk_X509_ALGOR_push(md_sk,alg);
238 }
239
240 sk_PKCS7_SIGNER_INFO_push(signer_sk,psi);
241 return(1);
242 }
243
244int PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
245 {
246 int i;
247 STACK_OF(X509) **sk;
248
249 i=OBJ_obj2nid(p7->type);
250 switch (i)
251 {
252 case NID_pkcs7_signed:
253 sk= &(p7->d.sign->cert);
254 break;
255 case NID_pkcs7_signedAndEnveloped:
256 sk= &(p7->d.signed_and_enveloped->cert);
257 break;
258 default:
259 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,PKCS7_R_WRONG_CONTENT_TYPE);
260 return(0);
261 }
262
263 if (*sk == NULL)
264 *sk=sk_X509_new_null();
265 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
266 sk_X509_push(*sk,x509);
267 return(1);
268 }
269
270int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
271 {
272 int i;
273 STACK_OF(X509_CRL) **sk;
274
275 i=OBJ_obj2nid(p7->type);
276 switch (i)
277 {
278 case NID_pkcs7_signed:
279 sk= &(p7->d.sign->crl);
280 break;
281 case NID_pkcs7_signedAndEnveloped:
282 sk= &(p7->d.signed_and_enveloped->crl);
283 break;
284 default:
285 PKCS7err(PKCS7_F_PKCS7_ADD_CRL,PKCS7_R_WRONG_CONTENT_TYPE);
286 return(0);
287 }
288
289 if (*sk == NULL)
290 *sk=sk_X509_CRL_new_null();
291
292 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL);
293 sk_X509_CRL_push(*sk,crl);
294 return(1);
295 }
296
297int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
298 EVP_MD *dgst)
299 {
300 char is_dsa;
301 if (pkey->type == EVP_PKEY_DSA) is_dsa = 1;
302 else is_dsa = 0;
303 /* We now need to add another PKCS7_SIGNER_INFO entry */
304 ASN1_INTEGER_set(p7i->version,1);
305 X509_NAME_set(&p7i->issuer_and_serial->issuer,
306 X509_get_issuer_name(x509));
307
308 /* because ASN1_INTEGER_set is used to set a 'long' we will do
309 * things the ugly way. */
310 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
311 p7i->issuer_and_serial->serial=
312 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509));
313
314 /* lets keep the pkey around for a while */
315 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
316 p7i->pkey=pkey;
317
318 /* Set the algorithms */
319 if (is_dsa) p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1);
320 else
321 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst));
322
323 if (p7i->digest_alg->parameter != NULL)
324 ASN1_TYPE_free(p7i->digest_alg->parameter);
325 if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL)
326 goto err;
327 p7i->digest_alg->parameter->type=V_ASN1_NULL;
328
329 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type));
330
331 if (p7i->digest_enc_alg->parameter != NULL)
332 ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
333 if(is_dsa) p7i->digest_enc_alg->parameter = NULL;
334 else {
335 if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new()))
336 goto err;
337 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
338 }
339
340 return(1);
341err:
342 return(0);
343 }
344
345PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
346 EVP_MD *dgst)
347 {
348 PKCS7_SIGNER_INFO *si;
349
350 if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err;
351 if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err;
352 if (!PKCS7_add_signer(p7,si)) goto err;
353 return(si);
354err:
355 return(NULL);
356 }
357
358STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
359 {
360 if (PKCS7_type_is_signed(p7))
361 {
362 return(p7->d.sign->signer_info);
363 }
364 else if (PKCS7_type_is_signedAndEnveloped(p7))
365 {
366 return(p7->d.signed_and_enveloped->signer_info);
367 }
368 else
369 return(NULL);
370 }
371
372PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
373 {
374 PKCS7_RECIP_INFO *ri;
375
376 if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err;
377 if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err;
378 if (!PKCS7_add_recipient_info(p7,ri)) goto err;
379 return(ri);
380err:
381 return(NULL);
382 }
383
384int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
385 {
386 int i;
387 STACK_OF(PKCS7_RECIP_INFO) *sk;
388
389 i=OBJ_obj2nid(p7->type);
390 switch (i)
391 {
392 case NID_pkcs7_signedAndEnveloped:
393 sk= p7->d.signed_and_enveloped->recipientinfo;
394 break;
395 case NID_pkcs7_enveloped:
396 sk= p7->d.enveloped->recipientinfo;
397 break;
398 default:
399 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE);
400 return(0);
401 }
402
403 sk_PKCS7_RECIP_INFO_push(sk,ri);
404 return(1);
405 }
406
407int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
408 {
409 ASN1_INTEGER_set(p7i->version,0);
410 X509_NAME_set(&p7i->issuer_and_serial->issuer,
411 X509_get_issuer_name(x509));
412
413 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
414 p7i->issuer_and_serial->serial=
415 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509));
416
417 X509_ALGOR_free(p7i->key_enc_algor);
418 p7i->key_enc_algor=(X509_ALGOR *)ASN1_dup(i2d_X509_ALGOR,
419 (char *(*)())d2i_X509_ALGOR,
420 (char *)x509->cert_info->key->algor);
421
422 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
423 p7i->cert=x509;
424
425 return(1);
426 }
427
428X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
429 {
430 if (PKCS7_type_is_signed(p7))
431 return(X509_find_by_issuer_and_serial(p7->d.sign->cert,
432 si->issuer_and_serial->issuer,
433 si->issuer_and_serial->serial));
434 else
435 return(NULL);
436 }
437
438int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
439 {
440 int i;
441 ASN1_OBJECT *objtmp;
442 PKCS7_ENC_CONTENT *ec;
443
444 i=OBJ_obj2nid(p7->type);
445 switch (i)
446 {
447 case NID_pkcs7_signedAndEnveloped:
448 ec=p7->d.signed_and_enveloped->enc_data;
449 break;
450 case NID_pkcs7_enveloped:
451 ec=p7->d.enveloped->enc_data;
452 break;
453 default:
454 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE);
455 return(0);
456 }
457
458 /* Check cipher OID exists and has data in it*/
459 i = EVP_CIPHER_type(cipher);
460 if(i == NID_undef) {
461 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
462 return(0);
463 }
464 objtmp = OBJ_nid2obj(i);
465
466 ec->cipher = cipher;
467 return 1;
468 }
469
diff --git a/src/lib/libcrypto/pkcs7/pk7_mime.c b/src/lib/libcrypto/pkcs7/pk7_mime.c
deleted file mode 100644
index 734643be28..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_mime.c
+++ /dev/null
@@ -1,673 +0,0 @@
1/* pk7_mime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/rand.h>
63#include <openssl/x509.h>
64
65/* MIME and related routines */
66
67/* MIME format structures
68 * Note that all are translated to lower case apart from
69 * parameter values. Quotes are stripped off
70 */
71
72typedef struct {
73char *name; /* Name of line e.g. "content-type" */
74char *value; /* Value of line e.g. "text/plain" */
75STACK /* MIME_PARAM */ *params; /* Zero or more parameters */
76} MIME_HEADER;
77
78typedef struct {
79char *param_name; /* Param name e.g. "micalg" */
80char *param_value; /* Param value e.g. "sha1" */
81} MIME_PARAM;
82
83
84static int B64_write_PKCS7(BIO *bio, PKCS7 *p7);
85static PKCS7 *B64_read_PKCS7(BIO *bio);
86static char * strip_ends(char *name);
87static char * strip_start(char *name);
88static char * strip_end(char *name);
89static MIME_HEADER *mime_hdr_new(char *name, char *value);
90static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value);
91static STACK *mime_parse_hdr(BIO *bio);
92static int mime_hdr_cmp(MIME_HEADER **a, MIME_HEADER **b);
93static int mime_param_cmp(MIME_PARAM **a, MIME_PARAM **b);
94static void mime_param_free(MIME_PARAM *param);
95static int mime_bound_check(char *line, int linelen, char *bound, int blen);
96static int multi_split(BIO *bio, char *bound, STACK **ret);
97static int iscrlf(char c);
98static MIME_HEADER *mime_hdr_find(STACK *hdrs, char *name);
99static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name);
100static void mime_hdr_free(MIME_HEADER *hdr);
101
102#define MAX_SMLEN 1024
103#define mime_debug(x) /* x */
104
105
106typedef void (*stkfree)();
107
108/* Base 64 read and write of PKCS#7 structure */
109
110static int B64_write_PKCS7(BIO *bio, PKCS7 *p7)
111{
112 BIO *b64;
113 if(!(b64 = BIO_new(BIO_f_base64()))) {
114 PKCS7err(PKCS7_F_B64_WRITE_PKCS7,ERR_R_MALLOC_FAILURE);
115 return 0;
116 }
117 bio = BIO_push(b64, bio);
118 i2d_PKCS7_bio(bio, p7);
119 BIO_flush(bio);
120 bio = BIO_pop(bio);
121 BIO_free(b64);
122 return 1;
123}
124
125static PKCS7 *B64_read_PKCS7(BIO *bio)
126{
127 BIO *b64;
128 PKCS7 *p7;
129 if(!(b64 = BIO_new(BIO_f_base64()))) {
130 PKCS7err(PKCS7_F_B64_READ_PKCS7,ERR_R_MALLOC_FAILURE);
131 return 0;
132 }
133 bio = BIO_push(b64, bio);
134 if(!(p7 = d2i_PKCS7_bio(bio, NULL)))
135 PKCS7err(PKCS7_F_B64_READ_PKCS7,PKCS7_R_DECODE_ERROR);
136 BIO_flush(bio);
137 bio = BIO_pop(bio);
138 BIO_free(b64);
139 return p7;
140}
141
142/* SMIME sender */
143
144int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
145{
146 char linebuf[MAX_SMLEN];
147 char bound[33], c;
148 int i;
149 if((flags & PKCS7_DETACHED) && data) {
150 /* We want multipart/signed */
151 /* Generate a random boundary */
152 RAND_pseudo_bytes((unsigned char *)bound, 32);
153 for(i = 0; i < 32; i++) {
154 c = bound[i] & 0xf;
155 if(c < 10) c += '0';
156 else c += 'A' - 10;
157 bound[i] = c;
158 }
159 bound[32] = 0;
160 BIO_printf(bio, "MIME-Version: 1.0\n");
161 BIO_printf(bio, "Content-Type: multipart/signed ; ");
162 BIO_printf(bio, "protocol=\"application/x-pkcs7-signature\" ; ");
163 BIO_printf(bio, "micalg=sha1 ; boundary=\"----%s\"\n\n", bound);
164 BIO_printf(bio, "This is an S/MIME signed message\n\n");
165 /* Now write out the first part */
166 BIO_printf(bio, "------%s\r\n", bound);
167 if(flags & PKCS7_TEXT) BIO_printf(bio, "Content-Type: text/plain\n\n");
168 while((i = BIO_read(data, linebuf, MAX_SMLEN)) > 0)
169 BIO_write(bio, linebuf, i);
170 BIO_printf(bio, "\n------%s\n", bound);
171
172 /* Headers for signature */
173
174 BIO_printf(bio, "Content-Type: application/x-pkcs7-signature; name=\"smime.p7s\"\n");
175 BIO_printf(bio, "Content-Transfer-Encoding: base64\n");
176 BIO_printf(bio, "Content-Disposition: attachment; filename=\"smime.p7s\"\n\n");
177 B64_write_PKCS7(bio, p7);
178 BIO_printf(bio,"\n------%s--\n\n", bound);
179 return 1;
180 }
181 /* MIME headers */
182 BIO_printf(bio, "MIME-Version: 1.0\n");
183 BIO_printf(bio, "Content-Disposition: attachment; filename=\"smime.p7m\"\n");
184 BIO_printf(bio, "Content-Type: application/x-pkcs7-mime; name=\"smime.p7m\"\n");
185 BIO_printf(bio, "Content-Transfer-Encoding: base64\n\n");
186 B64_write_PKCS7(bio, p7);
187 BIO_printf(bio, "\n");
188 return 1;
189}
190
191/* SMIME reader: handle multipart/signed and opaque signing.
192 * in multipart case the content is placed in a memory BIO
193 * pointed to by "bcont". In opaque this is set to NULL
194 */
195
196PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
197{
198 BIO *p7in;
199 STACK *headers = NULL;
200 STACK *parts = NULL;
201 MIME_HEADER *hdr;
202 MIME_PARAM *prm;
203 PKCS7 *p7;
204 int ret;
205
206 if(bcont) *bcont = NULL;
207
208 if (!(headers = mime_parse_hdr(bio))) {
209 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_PARSE_ERROR);
210 return NULL;
211 }
212
213 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
214 sk_pop_free(headers, mime_hdr_free);
215 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_CONTENT_TYPE);
216 return NULL;
217 }
218
219 /* Handle multipart/signed */
220
221 if(!strcmp(hdr->value, "multipart/signed")) {
222 /* Split into two parts */
223 prm = mime_param_find(hdr, "boundary");
224 if(!prm || !prm->param_value) {
225 sk_pop_free(headers, mime_hdr_free);
226 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BOUNDARY);
227 return NULL;
228 }
229 ret = multi_split(bio, prm->param_value, &parts);
230 sk_pop_free(headers, mime_hdr_free);
231 if(!ret || (sk_num(parts) != 2) ) {
232 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BODY_FAILURE);
233 sk_pop_free(parts, (stkfree)BIO_free);
234 return NULL;
235 }
236
237 /* Parse the signature piece */
238 p7in = (BIO *)sk_value(parts, 1);
239
240 if (!(headers = mime_parse_hdr(p7in))) {
241 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_SIG_PARSE_ERROR);
242 sk_pop_free(parts, (stkfree)BIO_free);
243 return NULL;
244 }
245
246 /* Get content type */
247
248 if(!(hdr = mime_hdr_find(headers, "content-type")) ||
249 !hdr->value) {
250 sk_pop_free(headers, mime_hdr_free);
251 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_SIG_CONTENT_TYPE);
252 return NULL;
253 }
254
255 if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
256 strcmp(hdr->value, "application/pkcs7-signature")) {
257 sk_pop_free(headers, mime_hdr_free);
258 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_SIG_INVALID_MIME_TYPE);
259 ERR_add_error_data(2, "type: ", hdr->value);
260 sk_pop_free(parts, (stkfree)BIO_free);
261 return NULL;
262 }
263 sk_pop_free(headers, mime_hdr_free);
264 /* Read in PKCS#7 */
265 if(!(p7 = B64_read_PKCS7(p7in))) {
266 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_PKCS7_SIG_PARSE_ERROR);
267 sk_pop_free(parts, (stkfree)BIO_free);
268 return NULL;
269 }
270
271 if(bcont) {
272 *bcont = (BIO *)sk_value(parts, 0);
273 BIO_free(p7in);
274 sk_free(parts);
275 } else sk_pop_free(parts, (stkfree)BIO_free);
276 return p7;
277 }
278
279 /* OK, if not multipart/signed try opaque signature */
280
281 if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
282 strcmp (hdr->value, "application/pkcs7-mime")) {
283 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_INVALID_MIME_TYPE);
284 ERR_add_error_data(2, "type: ", hdr->value);
285 sk_pop_free(headers, mime_hdr_free);
286 return NULL;
287 }
288
289 sk_pop_free(headers, mime_hdr_free);
290
291 if(!(p7 = B64_read_PKCS7(bio))) {
292 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_PKCS7_PARSE_ERROR);
293 return NULL;
294 }
295 return p7;
296
297}
298
299/* Copy text from one BIO to another making the output CRLF at EOL */
300int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
301{
302 char eol;
303 int len;
304 char linebuf[MAX_SMLEN];
305 if(flags & PKCS7_BINARY) {
306 while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
307 BIO_write(out, linebuf, len);
308 return 1;
309 }
310 if(flags & PKCS7_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
311 while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
312 eol = 0;
313 while(iscrlf(linebuf[len - 1])) {
314 len--;
315 eol = 1;
316 }
317 BIO_write(out, linebuf, len);
318 if(eol) BIO_write(out, "\r\n", 2);
319 }
320 return 1;
321}
322
323/* Strip off headers if they are text/plain */
324int SMIME_text(BIO *in, BIO *out)
325{
326 char iobuf[4096];
327 int len;
328 STACK *headers;
329 MIME_HEADER *hdr;
330 if (!(headers = mime_parse_hdr(in))) {
331 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_PARSE_ERROR);
332 return 0;
333 }
334 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
335 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_NO_CONTENT_TYPE);
336 sk_pop_free(headers, mime_hdr_free);
337 return 0;
338 }
339 if (strcmp (hdr->value, "text/plain")) {
340 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_INVALID_MIME_TYPE);
341 ERR_add_error_data(2, "type: ", hdr->value);
342 sk_pop_free(headers, mime_hdr_free);
343 return 0;
344 }
345 sk_pop_free(headers, mime_hdr_free);
346 while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
347 BIO_write(out, iobuf, len);
348 return 1;
349}
350
351/* Split a multipart/XXX message body into component parts: result is
352 * canonical parts in a STACK of bios
353 */
354
355static int multi_split(BIO *bio, char *bound, STACK **ret)
356{
357 char linebuf[MAX_SMLEN];
358 int len, blen;
359 BIO *bpart = NULL;
360 STACK *parts;
361 char state, part, first;
362 blen = strlen(bound);
363 part = 0;
364 state = 0;
365 first = 1;
366 parts = sk_new(NULL);
367 *ret = parts;
368 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
369 state = mime_bound_check(linebuf, len, bound, blen);
370 if(state == 1) {
371 first = 1;
372 part++;
373 } else if(state == 2) {
374 sk_push(parts, (char *)bpart);
375 return 1;
376 } else if(part) {
377 if(first) {
378 first = 0;
379 if(bpart) sk_push(parts, (char *)bpart);
380 bpart = BIO_new(BIO_s_mem());
381
382 } else BIO_write(bpart, "\r\n", 2);
383 /* Strip CR+LF from linebuf */
384 while(iscrlf(linebuf[len - 1])) len--;
385 BIO_write(bpart, linebuf, len);
386 }
387 }
388 return 0;
389}
390
391static int iscrlf(char c)
392{
393 if(c == '\r' || c == '\n') return 1;
394 return 0;
395}
396
397/* This is the big one: parse MIME header lines up to message body */
398
399#define MIME_INVALID 0
400#define MIME_START 1
401#define MIME_TYPE 2
402#define MIME_NAME 3
403#define MIME_VALUE 4
404#define MIME_QUOTE 5
405#define MIME_COMMENT 6
406
407
408static STACK *mime_parse_hdr(BIO *bio)
409{
410 char *p, *q, c;
411 char *ntmp;
412 char linebuf[MAX_SMLEN];
413 MIME_HEADER *mhdr = NULL;
414 STACK *headers;
415 int len, state, save_state = 0;
416 headers = sk_new(mime_hdr_cmp);
417 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
418 /* If whitespace at line start then continuation line */
419 if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
420 else state = MIME_START;
421 ntmp = NULL;
422 /* Go through all characters */
423 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
424
425 /* State machine to handle MIME headers
426 * if this looks horrible that's because it *is*
427 */
428
429 switch(state) {
430 case MIME_START:
431 if(c == ':') {
432 state = MIME_TYPE;
433 *p = 0;
434 ntmp = strip_ends(q);
435 q = p + 1;
436 }
437 break;
438
439 case MIME_TYPE:
440 if(c == ';') {
441 mime_debug("Found End Value\n");
442 *p = 0;
443 mhdr = mime_hdr_new(ntmp, strip_ends(q));
444 sk_push(headers, (char *)mhdr);
445 ntmp = NULL;
446 q = p + 1;
447 state = MIME_NAME;
448 } else if(c == '(') {
449 save_state = state;
450 state = MIME_COMMENT;
451 }
452 break;
453
454 case MIME_COMMENT:
455 if(c == ')') {
456 state = save_state;
457 }
458 break;
459
460 case MIME_NAME:
461 if(c == '=') {
462 state = MIME_VALUE;
463 *p = 0;
464 ntmp = strip_ends(q);
465 q = p + 1;
466 }
467 break ;
468
469 case MIME_VALUE:
470 if(c == ';') {
471 state = MIME_NAME;
472 *p = 0;
473 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
474 ntmp = NULL;
475 q = p + 1;
476 } else if (c == '"') {
477 mime_debug("Found Quote\n");
478 state = MIME_QUOTE;
479 } else if(c == '(') {
480 save_state = state;
481 state = MIME_COMMENT;
482 }
483 break;
484
485 case MIME_QUOTE:
486 if(c == '"') {
487 mime_debug("Found Match Quote\n");
488 state = MIME_VALUE;
489 }
490 break;
491 }
492 }
493
494 if(state == MIME_TYPE) {
495 mhdr = mime_hdr_new(ntmp, strip_ends(q));
496 sk_push(headers, (char *)mhdr);
497 } else if(state == MIME_VALUE)
498 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
499 if(p == linebuf) break; /* Blank line means end of headers */
500}
501
502return headers;
503
504}
505
506static char *strip_ends(char *name)
507{
508 return strip_end(strip_start(name));
509}
510
511/* Strip a parameter of whitespace from start of param */
512static char *strip_start(char *name)
513{
514 char *p, c;
515 /* Look for first non white space or quote */
516 for(p = name; (c = *p) ;p++) {
517 if(c == '"') {
518 /* Next char is start of string if non null */
519 if(p[1]) return p + 1;
520 /* Else null string */
521 return NULL;
522 }
523 if(!isspace((unsigned char)c)) return p;
524 }
525 return NULL;
526}
527
528/* As above but strip from end of string : maybe should handle brackets? */
529static char *strip_end(char *name)
530{
531 char *p, c;
532 if(!name) return NULL;
533 /* Look for first non white space or quote */
534 for(p = name + strlen(name) - 1; p >= name ;p--) {
535 c = *p;
536 if(c == '"') {
537 if(p - 1 == name) return NULL;
538 *p = 0;
539 return name;
540 }
541 if(isspace((unsigned char)c)) *p = 0;
542 else return name;
543 }
544 return NULL;
545}
546
547static MIME_HEADER *mime_hdr_new(char *name, char *value)
548{
549 MIME_HEADER *mhdr;
550 char *tmpname, *tmpval, *p;
551 int c;
552 if(name) {
553 if(!(tmpname = BUF_strdup(name))) return NULL;
554 for(p = tmpname ; *p; p++) {
555 c = *p;
556 if(isupper(c)) {
557 c = tolower(c);
558 *p = c;
559 }
560 }
561 } else tmpname = NULL;
562 if(value) {
563 if(!(tmpval = BUF_strdup(value))) return NULL;
564 for(p = tmpval ; *p; p++) {
565 c = *p;
566 if(isupper(c)) {
567 c = tolower(c);
568 *p = c;
569 }
570 }
571 } else tmpval = NULL;
572 mhdr = (MIME_HEADER *) Malloc(sizeof(MIME_HEADER));
573 if(!mhdr) return NULL;
574 mhdr->name = tmpname;
575 mhdr->value = tmpval;
576 if(!(mhdr->params = sk_new(mime_param_cmp))) return NULL;
577 return mhdr;
578}
579
580static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
581{
582 char *tmpname, *tmpval, *p;
583 int c;
584 MIME_PARAM *mparam;
585 if(name) {
586 tmpname = BUF_strdup(name);
587 if(!tmpname) return 0;
588 for(p = tmpname ; *p; p++) {
589 c = *p;
590 if(isupper(c)) {
591 c = tolower(c);
592 *p = c;
593 }
594 }
595 } else tmpname = NULL;
596 if(value) {
597 tmpval = BUF_strdup(value);
598 if(!tmpval) return 0;
599 } else tmpval = NULL;
600 /* Parameter values are case sensitive so leave as is */
601 mparam = (MIME_PARAM *) Malloc(sizeof(MIME_PARAM));
602 if(!mparam) return 0;
603 mparam->param_name = tmpname;
604 mparam->param_value = tmpval;
605 sk_push(mhdr->params, (char *)mparam);
606 return 1;
607}
608
609static int mime_hdr_cmp(MIME_HEADER **a, MIME_HEADER **b)
610{
611 return(strcmp((*a)->name, (*b)->name));
612}
613
614static int mime_param_cmp(MIME_PARAM **a, MIME_PARAM **b)
615{
616 return(strcmp((*a)->param_name, (*b)->param_name));
617}
618
619/* Find a header with a given name (if possible) */
620
621static MIME_HEADER *mime_hdr_find(STACK *hdrs, char *name)
622{
623 MIME_HEADER htmp;
624 int idx;
625 htmp.name = name;
626 idx = sk_find(hdrs, (char *)&htmp);
627 if(idx < 0) return NULL;
628 return (MIME_HEADER *)sk_value(hdrs, idx);
629}
630
631static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
632{
633 MIME_PARAM param;
634 int idx;
635 param.param_name = name;
636 idx = sk_find(hdr->params, (char *)&param);
637 if(idx < 0) return NULL;
638 return (MIME_PARAM *)sk_value(hdr->params, idx);
639}
640
641static void mime_hdr_free(MIME_HEADER *hdr)
642{
643 if(hdr->name) Free(hdr->name);
644 if(hdr->value) Free(hdr->value);
645 if(hdr->params) sk_pop_free(hdr->params, mime_param_free);
646 Free(hdr);
647}
648
649static void mime_param_free(MIME_PARAM *param)
650{
651 if(param->param_name) Free(param->param_name);
652 if(param->param_value) Free(param->param_value);
653 Free(param);
654}
655
656/* Check for a multipart boundary. Returns:
657 * 0 : no boundary
658 * 1 : part boundary
659 * 2 : final boundary
660 */
661static int mime_bound_check(char *line, int linelen, char *bound, int blen)
662{
663 if(linelen == -1) linelen = strlen(line);
664 if(blen == -1) blen = strlen(bound);
665 /* Quickly eliminate if line length too short */
666 if(blen + 2 > linelen) return 0;
667 /* Check for part boundary */
668 if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
669 if(!strncmp(line + blen + 2, "--", 2)) return 2;
670 else return 1;
671 }
672 return 0;
673}
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
deleted file mode 100644
index b41f42ed04..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_smime.c
+++ /dev/null
@@ -1,427 +0,0 @@
1/* pk7_smime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Simple PKCS#7 processing functions */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
67 BIO *data, int flags)
68{
69 PKCS7 *p7;
70 PKCS7_SIGNER_INFO *si;
71 BIO *p7bio;
72 STACK *smcap;
73 int i;
74
75 if(!X509_check_private_key(signcert, pkey)) {
76 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
77 return NULL;
78 }
79
80 if(!(p7 = PKCS7_new())) {
81 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
82 return NULL;
83 }
84
85 PKCS7_set_type(p7, NID_pkcs7_signed);
86
87 PKCS7_content_new(p7, NID_pkcs7_data);
88
89 if (!(si = PKCS7_add_signature(p7,signcert,pkey,EVP_sha1()))) {
90 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
91 return NULL;
92 }
93
94 if(!(flags & PKCS7_NOCERTS)) {
95 PKCS7_add_certificate(p7, signcert);
96 if(certs) for(i = 0; i < sk_X509_num(certs); i++)
97 PKCS7_add_certificate(p7, sk_X509_value(certs, i));
98 }
99
100 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
101 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104
105
106 SMIME_crlf_copy(data, p7bio, flags);
107
108 if(!(flags & PKCS7_NOATTR)) {
109 PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
110 V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data));
111 /* Add SMIMECapabilities */
112 if(!(smcap = sk_new(NULL))) {
113 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
114 return NULL;
115 }
116#ifndef NO_DES
117 PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1);
118#endif
119#ifndef NO_RC2
120 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128);
121 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64);
122#endif
123#ifndef NO_DES
124 PKCS7_simple_smimecap (smcap, NID_des_cbc, -1);
125#endif
126#ifndef NO_RC2
127 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40);
128#endif
129 PKCS7_add_attrib_smimecap (si, smcap);
130 sk_pop_free(smcap, X509_ALGOR_free);
131 }
132
133 if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1);
134
135 if (!PKCS7_dataFinal(p7,p7bio)) {
136 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN);
137 return NULL;
138 }
139
140 BIO_free_all(p7bio);
141 return p7;
142}
143
144int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
145 BIO *indata, BIO *out, int flags)
146{
147 STACK_OF(X509) *signers;
148 X509 *signer;
149 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
150 PKCS7_SIGNER_INFO *si;
151 X509_STORE_CTX cert_ctx;
152 char buf[4096];
153 int i, j=0;
154 BIO *p7bio;
155 BIO *tmpout;
156
157 if(!p7) {
158 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER);
159 return 0;
160 }
161
162 if(!PKCS7_type_is_signed(p7)) {
163 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_WRONG_CONTENT_TYPE);
164 return 0;
165 }
166
167 /* Check for no data and no content: no data to verify signature */
168 if(PKCS7_get_detached(p7) && !indata) {
169 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_CONTENT);
170 return 0;
171 }
172
173 /* Check for data and content: two sets of data */
174 if(!PKCS7_get_detached(p7) && indata) {
175 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CONTENT_AND_DATA_PRESENT);
176 return 0;
177 }
178
179 sinfos = PKCS7_get_signer_info(p7);
180
181 if(!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) {
182 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_SIGNATURES_ON_DATA);
183 return 0;
184 }
185
186
187 signers = PKCS7_get0_signers(p7, certs, flags);
188
189 if(!signers) return 0;
190
191 /* Now verify the certificates */
192
193 if (!(flags & PKCS7_NOVERIFY)) for (i = 0; i < sk_X509_num(signers); i++) {
194 signer = sk_X509_value (signers, i);
195 if (!(flags & PKCS7_NOCHAIN)) {
196 X509_STORE_CTX_init(&cert_ctx, store, signer,
197 p7->d.sign->cert);
198 X509_STORE_CTX_set_purpose(&cert_ctx,
199 X509_PURPOSE_SMIME_SIGN);
200 } else X509_STORE_CTX_init (&cert_ctx, store, signer, NULL);
201 i = X509_verify_cert(&cert_ctx);
202 if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx);
203 X509_STORE_CTX_cleanup(&cert_ctx);
204 if (i <= 0) {
205 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CERTIFICATE_VERIFY_ERROR);
206 ERR_add_error_data(2, "Verify error:",
207 X509_verify_cert_error_string(j));
208 sk_X509_free(signers);
209 return 0;
210 }
211 /* Check for revocation status here */
212 }
213
214 p7bio=PKCS7_dataInit(p7,indata);
215
216 if(flags & PKCS7_TEXT) {
217 if(!(tmpout = BIO_new(BIO_s_mem()))) {
218 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
219 goto err;
220 }
221 } else tmpout = out;
222
223 /* We now have to 'read' from p7bio to calculate digests etc. */
224 for (;;)
225 {
226 i=BIO_read(p7bio,buf,sizeof(buf));
227 if (i <= 0) break;
228 if (tmpout) BIO_write(tmpout, buf, i);
229 }
230
231 if(flags & PKCS7_TEXT) {
232 if(!SMIME_text(tmpout, out)) {
233 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SMIME_TEXT_ERROR);
234 BIO_free(tmpout);
235 goto err;
236 }
237 BIO_free(tmpout);
238 }
239
240 /* Now Verify All Signatures */
241 if (!(flags & PKCS7_NOSIGS))
242 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
243 {
244 si=sk_PKCS7_SIGNER_INFO_value(sinfos,i);
245 signer = sk_X509_value (signers, i);
246 j=PKCS7_signatureVerify(p7bio,p7,si, signer);
247 if (j <= 0) {
248 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SIGNATURE_FAILURE);
249 goto err;
250 }
251 }
252
253 sk_X509_free(signers);
254 if(indata) BIO_pop(p7bio);
255 BIO_free_all(p7bio);
256
257 return 1;
258
259 err:
260
261 sk_X509_free(signers);
262 BIO_free(p7bio);
263
264 return 0;
265}
266
267STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
268{
269 STACK_OF(X509) *signers;
270 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
271 PKCS7_SIGNER_INFO *si;
272 PKCS7_ISSUER_AND_SERIAL *ias;
273 X509 *signer;
274 int i;
275
276 if(!p7) {
277 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_INVALID_NULL_POINTER);
278 return NULL;
279 }
280
281 if(!PKCS7_type_is_signed(p7)) {
282 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE);
283 return NULL;
284 }
285 if(!(signers = sk_X509_new(NULL))) {
286 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE);
287 return NULL;
288 }
289
290 /* Collect all the signers together */
291
292 sinfos = PKCS7_get_signer_info(p7);
293
294 if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
295 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
296 return 0;
297 }
298
299 for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
300 {
301 si = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
302 ias = si->issuer_and_serial;
303 signer = NULL;
304 /* If any certificates passed they take priority */
305 if (certs) signer = X509_find_by_issuer_and_serial (certs,
306 ias->issuer, ias->serial);
307 if (!signer && !(flags & PKCS7_NOINTERN)
308 && p7->d.sign->cert) signer =
309 X509_find_by_issuer_and_serial (p7->d.sign->cert,
310 ias->issuer, ias->serial);
311 if (!signer) {
312 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
313 sk_X509_free(signers);
314 return 0;
315 }
316
317 sk_X509_push(signers, signer);
318 }
319 return signers;
320}
321
322
323/* Build a complete PKCS#7 enveloped data */
324
325PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
326 int flags)
327{
328 PKCS7 *p7;
329 BIO *p7bio = NULL;
330 int i;
331 X509 *x509;
332 if(!(p7 = PKCS7_new())) {
333 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
334 return NULL;
335 }
336
337 PKCS7_set_type(p7, NID_pkcs7_enveloped);
338 if(!PKCS7_set_cipher(p7, cipher)) {
339 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER);
340 goto err;
341 }
342
343 for(i = 0; i < sk_X509_num(certs); i++) {
344 x509 = sk_X509_value(certs, i);
345 if(!PKCS7_add_recipient(p7, x509)) {
346 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,
347 PKCS7_R_ERROR_ADDING_RECIPIENT);
348 goto err;
349 }
350 }
351
352 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
353 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
354 goto err;
355 }
356
357 SMIME_crlf_copy(in, p7bio, flags);
358
359 BIO_flush(p7bio);
360
361 if (!PKCS7_dataFinal(p7,p7bio)) {
362 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR);
363 goto err;
364 }
365 BIO_free_all(p7bio);
366
367 return p7;
368
369 err:
370
371 BIO_free(p7bio);
372 PKCS7_free(p7);
373 return NULL;
374
375}
376
377int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
378{
379 BIO *tmpmem;
380 int ret, i;
381 char buf[4096];
382
383 if(!p7) {
384 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_INVALID_NULL_POINTER);
385 return 0;
386 }
387
388 if(!PKCS7_type_is_enveloped(p7)) {
389 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_WRONG_CONTENT_TYPE);
390 return 0;
391 }
392
393 if(!X509_check_private_key(cert, pkey)) {
394 PKCS7err(PKCS7_F_PKCS7_DECRYPT,
395 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
396 return 0;
397 }
398
399 if(!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) {
400 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR);
401 return 0;
402 }
403
404 if (flags & PKCS7_TEXT) {
405 BIO *tmpbuf, *bread;
406 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
407 if(!(tmpbuf = BIO_new(BIO_f_buffer()))) {
408 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
409 return 0;
410 }
411 if(!(bread = BIO_push(tmpbuf, tmpmem))) {
412 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
413 return 0;
414 }
415 ret = SMIME_text(bread, data);
416 BIO_free_all(bread);
417 return ret;
418 } else {
419 for(;;) {
420 i = BIO_read(tmpmem, buf, sizeof(buf));
421 if(i <= 0) break;
422 BIO_write(data, buf, i);
423 }
424 BIO_free_all(tmpmem);
425 return 1;
426 }
427}
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h
deleted file mode 100644
index 3ec725d226..0000000000
--- a/src/lib/libcrypto/pkcs7/pkcs7.h
+++ /dev/null
@@ -1,498 +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 thes are defined in wincrypt.h */
75#undef PKCS7_ISSUER_AND_SERIAL
76#undef PKCS7_SIGNER_INFO
77#endif
78
79/*
80Encryption_ID DES-CBC
81Digest_ID MD5
82Digest_Encryption_ID rsaEncryption
83Key_Encryption_ID rsaEncryption
84*/
85
86typedef struct pkcs7_issuer_and_serial_st
87 {
88 X509_NAME *issuer;
89 ASN1_INTEGER *serial;
90 } PKCS7_ISSUER_AND_SERIAL;
91
92typedef struct pkcs7_signer_info_st
93 {
94 ASN1_INTEGER *version; /* version 1 */
95 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
96 X509_ALGOR *digest_alg;
97 STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */
98 X509_ALGOR *digest_enc_alg;
99 ASN1_OCTET_STRING *enc_digest;
100 STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */
101
102 /* The private key to sign with */
103 EVP_PKEY *pkey;
104 } PKCS7_SIGNER_INFO;
105
106DECLARE_STACK_OF(PKCS7_SIGNER_INFO)
107DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO)
108
109typedef struct pkcs7_recip_info_st
110 {
111 ASN1_INTEGER *version; /* version 0 */
112 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
113 X509_ALGOR *key_enc_algor;
114 ASN1_OCTET_STRING *enc_key;
115 X509 *cert; /* get the pub-key from this */
116 } PKCS7_RECIP_INFO;
117
118DECLARE_STACK_OF(PKCS7_RECIP_INFO)
119DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO)
120
121typedef struct pkcs7_signed_st
122 {
123 ASN1_INTEGER *version; /* version 1 */
124 STACK_OF(X509_ALGOR) *md_algs; /* md used */
125 STACK_OF(X509) *cert; /* [ 0 ] */
126 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
127 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
128
129 struct pkcs7_st *contents;
130 } PKCS7_SIGNED;
131/* The above structure is very very similar to PKCS7_SIGN_ENVELOPE.
132 * How about merging the two */
133
134typedef struct pkcs7_enc_content_st
135 {
136 ASN1_OBJECT *content_type;
137 X509_ALGOR *algorithm;
138 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */
139 const EVP_CIPHER *cipher;
140 } PKCS7_ENC_CONTENT;
141
142typedef struct pkcs7_enveloped_st
143 {
144 ASN1_INTEGER *version; /* version 0 */
145 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
146 PKCS7_ENC_CONTENT *enc_data;
147 } PKCS7_ENVELOPE;
148
149typedef struct pkcs7_signedandenveloped_st
150 {
151 ASN1_INTEGER *version; /* version 1 */
152 STACK_OF(X509_ALGOR) *md_algs; /* md used */
153 STACK_OF(X509) *cert; /* [ 0 ] */
154 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
155 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
156
157 PKCS7_ENC_CONTENT *enc_data;
158 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
159 } PKCS7_SIGN_ENVELOPE;
160
161typedef struct pkcs7_digest_st
162 {
163 ASN1_INTEGER *version; /* version 0 */
164 X509_ALGOR *md; /* md used */
165 struct pkcs7_st *contents;
166 ASN1_OCTET_STRING *digest;
167 } PKCS7_DIGEST;
168
169typedef struct pkcs7_encrypted_st
170 {
171 ASN1_INTEGER *version; /* version 0 */
172 PKCS7_ENC_CONTENT *enc_data;
173 } PKCS7_ENCRYPT;
174
175typedef struct pkcs7_st
176 {
177 /* The following is non NULL if it contains ASN1 encoding of
178 * this structure */
179 unsigned char *asn1;
180 long length;
181
182#define PKCS7_S_HEADER 0
183#define PKCS7_S_BODY 1
184#define PKCS7_S_TAIL 2
185 int state; /* used during processing */
186
187 int detached;
188
189 ASN1_OBJECT *type;
190 /* content as defined by the type */
191 /* all encryption/message digests are applied to the 'contents',
192 * leaving out the 'type' field. */
193 union {
194 char *ptr;
195
196 /* NID_pkcs7_data */
197 ASN1_OCTET_STRING *data;
198
199 /* NID_pkcs7_signed */
200 PKCS7_SIGNED *sign;
201
202 /* NID_pkcs7_enveloped */
203 PKCS7_ENVELOPE *enveloped;
204
205 /* NID_pkcs7_signedAndEnveloped */
206 PKCS7_SIGN_ENVELOPE *signed_and_enveloped;
207
208 /* NID_pkcs7_digest */
209 PKCS7_DIGEST *digest;
210
211 /* NID_pkcs7_encrypted */
212 PKCS7_ENCRYPT *encrypted;
213 } d;
214 } PKCS7;
215
216#define PKCS7_OP_SET_DETACHED_SIGNATURE 1
217#define PKCS7_OP_GET_DETACHED_SIGNATURE 2
218
219#define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
220#define PKCS7_get_attributes(si) ((si)->unauth_attr)
221
222#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
223#define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped)
224#define PKCS7_type_is_signedAndEnveloped(a) \
225 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
226#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
227
228#define PKCS7_set_detached(p,v) \
229 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
230#define PKCS7_get_detached(p) \
231 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
232
233#ifdef SSLEAY_MACROS
234#ifndef PKCS7_ISSUER_AND_SERIAL_digest
235#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
236 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
237 (char *)data,md,len)
238#endif
239#endif
240
241/* S/MIME related flags */
242
243#define PKCS7_TEXT 0x1
244#define PKCS7_NOCERTS 0x2
245#define PKCS7_NOSIGS 0x4
246#define PKCS7_NOCHAIN 0x8
247#define PKCS7_NOINTERN 0x10
248#define PKCS7_NOVERIFY 0x20
249#define PKCS7_DETACHED 0x40
250#define PKCS7_BINARY 0x80
251#define PKCS7_NOATTR 0x100
252
253/* Flags: for compatibility with older code */
254
255#define SMIME_TEXT PKCS7_TEXT
256#define SMIME_NOCERTS PKCS7_NOCERTS
257#define SMIME_NOSIGS PKCS7_NOSIGS
258#define SMIME_NOCHAIN PKCS7_NOCHAIN
259#define SMIME_NOINTERN PKCS7_NOINTERN
260#define SMIME_NOVERIFY PKCS7_NOVERIFY
261#define SMIME_DETACHED PKCS7_DETACHED
262#define SMIME_BINARY PKCS7_BINARY
263#define SMIME_NOATTR PKCS7_NOATTR
264
265PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void );
266void PKCS7_ISSUER_AND_SERIAL_free(
267 PKCS7_ISSUER_AND_SERIAL *a);
268int i2d_PKCS7_ISSUER_AND_SERIAL(
269 PKCS7_ISSUER_AND_SERIAL *a,unsigned char **pp);
270PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(
271 PKCS7_ISSUER_AND_SERIAL **a,
272 unsigned char **pp, long length);
273
274#ifndef SSLEAY_MACROS
275int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type,
276 unsigned char *md,unsigned int *len);
277#ifndef NO_FP_API
278PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
279int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
280#endif
281PKCS7 *PKCS7_dup(PKCS7 *p7);
282PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
283int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
284#endif
285
286PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void);
287void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a);
288int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a,
289 unsigned char **pp);
290PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a,
291 unsigned char **pp,long length);
292
293PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void);
294void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a);
295int i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO *a,
296 unsigned char **pp);
297PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO **a,
298 unsigned char **pp,long length);
299
300PKCS7_SIGNED *PKCS7_SIGNED_new(void);
301void PKCS7_SIGNED_free(PKCS7_SIGNED *a);
302int i2d_PKCS7_SIGNED(PKCS7_SIGNED *a,
303 unsigned char **pp);
304PKCS7_SIGNED *d2i_PKCS7_SIGNED(PKCS7_SIGNED **a,
305 unsigned char **pp,long length);
306
307PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(void);
308void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a);
309int i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT *a,
310 unsigned char **pp);
311PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT **a,
312 unsigned char **pp,long length);
313
314PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void);
315void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a);
316int i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE *a,
317 unsigned char **pp);
318PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE **a,
319 unsigned char **pp,long length);
320
321PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void);
322void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a);
323int i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE *a,
324 unsigned char **pp);
325PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE **a,
326 unsigned char **pp,long length);
327
328PKCS7_DIGEST *PKCS7_DIGEST_new(void);
329void PKCS7_DIGEST_free(PKCS7_DIGEST *a);
330int i2d_PKCS7_DIGEST(PKCS7_DIGEST *a,
331 unsigned char **pp);
332PKCS7_DIGEST *d2i_PKCS7_DIGEST(PKCS7_DIGEST **a,
333 unsigned char **pp,long length);
334
335PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void);
336void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a);
337int i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT *a,
338 unsigned char **pp);
339PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a,
340 unsigned char **pp,long length);
341
342PKCS7 *PKCS7_new(void);
343void PKCS7_free(PKCS7 *a);
344void PKCS7_content_free(PKCS7 *a);
345int i2d_PKCS7(PKCS7 *a,
346 unsigned char **pp);
347PKCS7 *d2i_PKCS7(PKCS7 **a,
348 unsigned char **pp,long length);
349
350void ERR_load_PKCS7_strings(void);
351
352
353long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
354
355int PKCS7_set_type(PKCS7 *p7, int type);
356int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
357int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
358 EVP_MD *dgst);
359int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
360int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
361int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
362int PKCS7_content_new(PKCS7 *p7, int nid);
363int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
364 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
365int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
366 X509 *x509);
367
368BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
369int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
370BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
371
372
373PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
374 EVP_PKEY *pkey, EVP_MD *dgst);
375X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
376STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
377
378PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
379int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
380int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
381int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
382
383PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
384ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
385int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,
386 void *data);
387int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
388 void *value);
389ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
390ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
391int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
392 STACK_OF(X509_ATTRIBUTE) *sk);
393int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
394
395
396PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
397 BIO *data, int flags);
398int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
399 BIO *indata, BIO *out, int flags);
400STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
401PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
402 int flags);
403int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
404
405int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK *cap);
406STACK *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
407int PKCS7_simple_smimecap(STACK *sk, int nid, int arg);
408
409int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
410PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
411int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
412int SMIME_text(BIO *in, BIO *out);
413
414/* BEGIN ERROR CODES */
415/* The following lines are auto generated by the script mkerr.pl. Any changes
416 * made after this point may be overwritten when the script is next run.
417 */
418
419/* Error codes for the PKCS7 functions. */
420
421/* Function codes. */
422#define PKCS7_F_B64_READ_PKCS7 120
423#define PKCS7_F_B64_WRITE_PKCS7 121
424#define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118
425#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
426#define PKCS7_F_PKCS7_ADD_CRL 101
427#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
428#define PKCS7_F_PKCS7_ADD_SIGNER 103
429#define PKCS7_F_PKCS7_CTRL 104
430#define PKCS7_F_PKCS7_DATADECODE 112
431#define PKCS7_F_PKCS7_DATAINIT 105
432#define PKCS7_F_PKCS7_DATASIGN 106
433#define PKCS7_F_PKCS7_DATAVERIFY 107
434#define PKCS7_F_PKCS7_DECRYPT 114
435#define PKCS7_F_PKCS7_ENCRYPT 115
436#define PKCS7_F_PKCS7_GET0_SIGNERS 124
437#define PKCS7_F_PKCS7_SET_CIPHER 108
438#define PKCS7_F_PKCS7_SET_CONTENT 109
439#define PKCS7_F_PKCS7_SET_TYPE 110
440#define PKCS7_F_PKCS7_SIGN 116
441#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
442#define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119
443#define PKCS7_F_PKCS7_VERIFY 117
444#define PKCS7_F_SMIME_READ_PKCS7 122
445#define PKCS7_F_SMIME_TEXT 123
446
447/* Reason codes. */
448#define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117
449#define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144
450#define PKCS7_R_CIPHER_NOT_INITIALIZED 116
451#define PKCS7_R_CONTENT_AND_DATA_PRESENT 118
452#define PKCS7_R_DECODE_ERROR 130
453#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100
454#define PKCS7_R_DECRYPT_ERROR 119
455#define PKCS7_R_DIGEST_FAILURE 101
456#define PKCS7_R_ERROR_ADDING_RECIPIENT 120
457#define PKCS7_R_ERROR_SETTING_CIPHER 121
458#define PKCS7_R_INTERNAL_ERROR 102
459#define PKCS7_R_INVALID_MIME_TYPE 131
460#define PKCS7_R_INVALID_NULL_POINTER 143
461#define PKCS7_R_MIME_NO_CONTENT_TYPE 132
462#define PKCS7_R_MIME_PARSE_ERROR 133
463#define PKCS7_R_MIME_SIG_PARSE_ERROR 134
464#define PKCS7_R_MISSING_CERIPEND_INFO 103
465#define PKCS7_R_NO_CONTENT 122
466#define PKCS7_R_NO_CONTENT_TYPE 135
467#define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136
468#define PKCS7_R_NO_MULTIPART_BOUNDARY 137
469#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
470#define PKCS7_R_NO_SIGNATURES_ON_DATA 123
471#define PKCS7_R_NO_SIGNERS 142
472#define PKCS7_R_NO_SIG_CONTENT_TYPE 138
473#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
474#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124
475#define PKCS7_R_PKCS7_DATAFINAL_ERROR 125
476#define PKCS7_R_PKCS7_DATASIGN 126
477#define PKCS7_R_PKCS7_PARSE_ERROR 139
478#define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140
479#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127
480#define PKCS7_R_SIGNATURE_FAILURE 105
481#define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128
482#define PKCS7_R_SIG_INVALID_MIME_TYPE 141
483#define PKCS7_R_SMIME_TEXT_ERROR 129
484#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106
485#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107
486#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108
487#define PKCS7_R_UNKNOWN_DIGEST_TYPE 109
488#define PKCS7_R_UNKNOWN_OPERATION 110
489#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111
490#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112
491#define PKCS7_R_WRONG_CONTENT_TYPE 113
492#define PKCS7_R_WRONG_PKCS7_TYPE 114
493
494#ifdef __cplusplus
495}
496#endif
497#endif
498
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c
deleted file mode 100644
index 8ded8913db..0000000000
--- a/src/lib/libcrypto/pkcs7/pkcs7err.c
+++ /dev/null
@@ -1,161 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/pkcs7.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA PKCS7_str_functs[]=
68 {
69{ERR_PACK(0,PKCS7_F_B64_READ_PKCS7,0), "B64_READ_PKCS7"},
70{ERR_PACK(0,PKCS7_F_B64_WRITE_PKCS7,0), "B64_WRITE_PKCS7"},
71{ERR_PACK(0,PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,0), "PKCS7_add_attrib_smimecap"},
72{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CERTIFICATE,0), "PKCS7_add_certificate"},
73{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CRL,0), "PKCS7_add_crl"},
74{ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"},
75{ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"},
76{ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"},
77{ERR_PACK(0,PKCS7_F_PKCS7_DATADECODE,0), "PKCS7_dataDecode"},
78{ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"},
79{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_DATASIGN"},
80{ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"},
81{ERR_PACK(0,PKCS7_F_PKCS7_DECRYPT,0), "PKCS7_decrypt"},
82{ERR_PACK(0,PKCS7_F_PKCS7_ENCRYPT,0), "PKCS7_encrypt"},
83{ERR_PACK(0,PKCS7_F_PKCS7_GET0_SIGNERS,0), "PKCS7_get0_signers"},
84{ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"},
85{ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"},
86{ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"},
87{ERR_PACK(0,PKCS7_F_PKCS7_SIGN,0), "PKCS7_sign"},
88{ERR_PACK(0,PKCS7_F_PKCS7_SIGNATUREVERIFY,0), "PKCS7_signatureVerify"},
89{ERR_PACK(0,PKCS7_F_PKCS7_SIMPLE_SMIMECAP,0), "PKCS7_simple_smimecap"},
90{ERR_PACK(0,PKCS7_F_PKCS7_VERIFY,0), "PKCS7_verify"},
91{ERR_PACK(0,PKCS7_F_SMIME_READ_PKCS7,0), "SMIME_read_PKCS7"},
92{ERR_PACK(0,PKCS7_F_SMIME_TEXT,0), "SMIME_text"},
93{0,NULL}
94 };
95
96static ERR_STRING_DATA PKCS7_str_reasons[]=
97 {
98{PKCS7_R_CERTIFICATE_VERIFY_ERROR ,"certificate verify error"},
99{PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"},
100{PKCS7_R_CIPHER_NOT_INITIALIZED ,"cipher not initialized"},
101{PKCS7_R_CONTENT_AND_DATA_PRESENT ,"content and data present"},
102{PKCS7_R_DECODE_ERROR ,"decode error"},
103{PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH ,"decrypted key is wrong length"},
104{PKCS7_R_DECRYPT_ERROR ,"decrypt error"},
105{PKCS7_R_DIGEST_FAILURE ,"digest failure"},
106{PKCS7_R_ERROR_ADDING_RECIPIENT ,"error adding recipient"},
107{PKCS7_R_ERROR_SETTING_CIPHER ,"error setting cipher"},
108{PKCS7_R_INTERNAL_ERROR ,"internal error"},
109{PKCS7_R_INVALID_MIME_TYPE ,"invalid mime type"},
110{PKCS7_R_INVALID_NULL_POINTER ,"invalid null pointer"},
111{PKCS7_R_MIME_NO_CONTENT_TYPE ,"mime no content type"},
112{PKCS7_R_MIME_PARSE_ERROR ,"mime parse error"},
113{PKCS7_R_MIME_SIG_PARSE_ERROR ,"mime sig parse error"},
114{PKCS7_R_MISSING_CERIPEND_INFO ,"missing ceripend info"},
115{PKCS7_R_NO_CONTENT ,"no content"},
116{PKCS7_R_NO_CONTENT_TYPE ,"no content type"},
117{PKCS7_R_NO_MULTIPART_BODY_FAILURE ,"no multipart body failure"},
118{PKCS7_R_NO_MULTIPART_BOUNDARY ,"no multipart boundary"},
119{PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE,"no recipient matches certificate"},
120{PKCS7_R_NO_SIGNATURES_ON_DATA ,"no signatures on data"},
121{PKCS7_R_NO_SIGNERS ,"no signers"},
122{PKCS7_R_NO_SIG_CONTENT_TYPE ,"no sig content type"},
123{PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"},
124{PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR ,"pkcs7 add signature error"},
125{PKCS7_R_PKCS7_DATAFINAL_ERROR ,"pkcs7 datafinal error"},
126{PKCS7_R_PKCS7_DATASIGN ,"pkcs7 datasign"},
127{PKCS7_R_PKCS7_PARSE_ERROR ,"pkcs7 parse error"},
128{PKCS7_R_PKCS7_SIG_PARSE_ERROR ,"pkcs7 sig parse error"},
129{PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE,"private key does not match certificate"},
130{PKCS7_R_SIGNATURE_FAILURE ,"signature failure"},
131{PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND ,"signer certificate not found"},
132{PKCS7_R_SIG_INVALID_MIME_TYPE ,"sig invalid mime type"},
133{PKCS7_R_SMIME_TEXT_ERROR ,"smime text error"},
134{PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"},
135{PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"},
136{PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"},
137{PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"},
138{PKCS7_R_UNKNOWN_OPERATION ,"unknown operation"},
139{PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"},
140{PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"},
141{PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"},
142{PKCS7_R_WRONG_PKCS7_TYPE ,"wrong pkcs7 type"},
143{0,NULL}
144 };
145
146#endif
147
148void ERR_load_PKCS7_strings(void)
149 {
150 static int init=1;
151
152 if (init)
153 {
154 init=0;
155#ifndef NO_ERR
156 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_functs);
157 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_reasons);
158#endif
159
160 }
161 }
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h
deleted file mode 100644
index 2973ee90e4..0000000000
--- a/src/lib/libcrypto/rand/rand.h
+++ /dev/null
@@ -1,117 +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 int (*bytes)(unsigned char *buf, int num);
70 void (*cleanup)(void);
71 void (*add)(const void *buf, int num, double entropy);
72 int (*pseudorand)(unsigned char *buf, int num);
73 int (*status)(void);
74 } RAND_METHOD;
75
76#ifdef BN_DEBUG
77extern int rand_predictable;
78#endif
79
80void RAND_set_rand_method(RAND_METHOD *meth);
81RAND_METHOD *RAND_get_rand_method(void );
82RAND_METHOD *RAND_SSLeay(void);
83void RAND_cleanup(void );
84int RAND_bytes(unsigned char *buf,int num);
85int RAND_pseudo_bytes(unsigned char *buf,int num);
86void RAND_seed(const void *buf,int num);
87void RAND_add(const void *buf,int num,double entropy);
88int RAND_load_file(const char *file,long max_bytes);
89int RAND_write_file(const char *file);
90const char *RAND_file_name(char *file,int num);
91int RAND_status(void);
92int RAND_egd(const char *path);
93#if defined(WINDOWS) || defined(WIN32)
94#include <windows.h>
95void RAND_screen(void);
96int RAND_event(UINT, WPARAM, LPARAM);
97#endif
98void ERR_load_RAND_strings(void);
99
100/* BEGIN ERROR CODES */
101/* The following lines are auto generated by the script mkerr.pl. Any changes
102 * made after this point may be overwritten when the script is next run.
103 */
104
105/* Error codes for the RAND functions. */
106
107/* Function codes. */
108#define RAND_F_SSLEAY_RAND_BYTES 100
109
110/* Reason codes. */
111#define RAND_R_PRNG_NOT_SEEDED 100
112
113#ifdef __cplusplus
114}
115#endif
116#endif
117
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c
deleted file mode 100644
index 1af0aa0b8a..0000000000
--- a/src/lib/libcrypto/rand/rand_err.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/* crypto/rand/rand_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/rand.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA RAND_str_functs[]=
68 {
69{ERR_PACK(0,RAND_F_SSLEAY_RAND_BYTES,0), "SSLEAY_RAND_BYTES"},
70{0,NULL}
71 };
72
73static ERR_STRING_DATA RAND_str_reasons[]=
74 {
75{RAND_R_PRNG_NOT_SEEDED ,"PRNG not seeded"},
76{0,NULL}
77 };
78
79#endif
80
81void ERR_load_RAND_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_RAND,RAND_str_functs);
90 ERR_load_strings(ERR_LIB_RAND,RAND_str_reasons);
91#endif
92
93 }
94 }
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
deleted file mode 100644
index 7da74aab0e..0000000000
--- a/src/lib/libcrypto/rand/rand_lib.c
+++ /dev/null
@@ -1,117 +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 <time.h>
61#include <openssl/rand.h>
62
63#ifdef NO_RAND
64static RAND_METHOD *rand_meth=NULL;
65#else
66extern RAND_METHOD rand_ssleay_meth;
67static RAND_METHOD *rand_meth= &rand_ssleay_meth;
68#endif
69
70void RAND_set_rand_method(RAND_METHOD *meth)
71 {
72 rand_meth=meth;
73 }
74
75RAND_METHOD *RAND_get_rand_method(void)
76 {
77 return(rand_meth);
78 }
79
80void RAND_cleanup(void)
81 {
82 if (rand_meth != NULL)
83 rand_meth->cleanup();
84 }
85
86void RAND_seed(const void *buf, int num)
87 {
88 if (rand_meth != NULL)
89 rand_meth->seed(buf,num);
90 }
91
92void RAND_add(const void *buf, int num, double entropy)
93 {
94 if (rand_meth != NULL)
95 rand_meth->add(buf,num,entropy);
96 }
97
98int RAND_bytes(unsigned char *buf, int num)
99 {
100 if (rand_meth != NULL)
101 return rand_meth->bytes(buf,num);
102 return(-1);
103 }
104
105int RAND_pseudo_bytes(unsigned char *buf, int num)
106 {
107 if (rand_meth != NULL)
108 return rand_meth->pseudorand(buf,num);
109 return(-1);
110 }
111
112int RAND_status(void)
113 {
114 if (rand_meth != NULL)
115 return rand_meth->status();
116 return 0;
117 }
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
deleted file mode 100644
index c6ff27be0e..0000000000
--- a/src/lib/libcrypto/rand/randfile.c
+++ /dev/null
@@ -1,260 +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
64#include "openssl/e_os.h"
65
66#ifdef VMS
67#include <unixio.h>
68#endif
69#ifndef NO_SYS_TYPES_H
70# include <sys/types.h>
71#endif
72#ifdef MAC_OS_pre_X
73# include <stat.h>
74#else
75# include <sys/stat.h>
76#endif
77
78#include <openssl/crypto.h>
79#include <openssl/rand.h>
80
81#undef BUFSIZE
82#define BUFSIZE 1024
83#define RAND_DATA 1024
84
85/* #define RFILE ".rnd" - defined in ../../e_os.h */
86
87int RAND_load_file(const char *file, long bytes)
88 {
89 /* If bytes >= 0, read up to 'bytes' bytes.
90 * if bytes == -1, read complete file. */
91
92 MS_STATIC unsigned char buf[BUFSIZE];
93 struct stat sb;
94 int i,ret=0,n;
95 FILE *in;
96
97 if (file == NULL) return(0);
98
99 i=stat(file,&sb);
100 if (i < 0) {
101 /* If the state fails, put some crap in anyway */
102 RAND_add(&sb,sizeof(sb),0);
103 return(0);
104 }
105 if (bytes == 0) return(ret);
106 in=fopen(file,"rb");
107 if (in == NULL) goto err;
108 if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
109 /* this file is a device. we don't want read an infinite number
110 * of bytes from a random device, nor do we want to use buffered
111 * I/O because we will waste system entropy.
112 */
113 bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */
114 setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */
115 }
116 for (;;)
117 {
118 if (bytes > 0)
119 n = (bytes < BUFSIZE)?(int)bytes:BUFSIZE;
120 else
121 n = BUFSIZE;
122 i=fread(buf,1,n,in);
123 if (i <= 0) break;
124 /* even if n != i, use the full array */
125 RAND_add(buf,n,i);
126 ret+=i;
127 if (bytes > 0)
128 {
129 bytes-=n;
130 if (bytes <= 0) break;
131 }
132 }
133 fclose(in);
134 memset(buf,0,BUFSIZE);
135err:
136 return(ret);
137 }
138
139int RAND_write_file(const char *file)
140 {
141 unsigned char buf[BUFSIZE];
142 int i,ret=0,err=0;
143 FILE *out = NULL;
144 int n;
145 struct stat sb;
146
147 i=stat(file,&sb);
148 if (i != -1) {
149 if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
150 /* this file is a device. we don't write back to it.
151 * we "succeed" on the assumption this is some sort
152 * of random device. Otherwise attempting to write to
153 * and chmod the device causes problems.
154 */
155 return(1);
156 }
157 }
158
159#if defined(O_CREAT) && defined(O_EXCL) && !defined(WIN32)
160 /* For some reason Win32 can't write to files created this way */
161
162 /* chmod(..., 0600) is too late to protect the file,
163 * permissions should be restrictive from the start */
164 int fd = open(file, O_CREAT | O_EXCL, 0600);
165 if (fd != -1)
166 out = fdopen(fd, "wb");
167#endif
168 if (out == NULL)
169 out = fopen(file,"wb");
170 if (out == NULL) goto err;
171
172#ifndef NO_CHMOD
173 chmod(file,0600);
174#endif
175 n=RAND_DATA;
176 for (;;)
177 {
178 i=(n > BUFSIZE)?BUFSIZE:n;
179 n-=BUFSIZE;
180 if (RAND_bytes(buf,i) <= 0)
181 err=1;
182 i=fwrite(buf,1,i,out);
183 if (i <= 0)
184 {
185 ret=0;
186 break;
187 }
188 ret+=i;
189 if (n <= 0) break;
190 }
191#ifdef VMS
192 /* Try to delete older versions of the file, until there aren't
193 any */
194 {
195 char *tmpf;
196
197 tmpf = Malloc(strlen(file) + 4); /* to add ";-1" and a nul */
198 if (tmpf)
199 {
200 strcpy(tmpf, file);
201 strcat(tmpf, ";-1");
202 while(delete(tmpf) == 0)
203 ;
204 rename(file,";1"); /* Make sure it's version 1, or we
205 will reach the limit (32767) at
206 some point... */
207 }
208 }
209#endif /* VMS */
210
211 fclose(out);
212 memset(buf,0,BUFSIZE);
213err:
214 return(err ? -1 : ret);
215 }
216
217const char *RAND_file_name(char *buf, int size)
218 {
219 char *s;
220 char *ret=NULL;
221 struct stat sb;
222
223 s=getenv("RANDFILE");
224 if (s != NULL)
225 {
226 strncpy(buf,s,size-1);
227 buf[size-1]='\0';
228 ret=buf;
229 }
230 else
231 {
232 s=getenv("HOME");
233 if (s == NULL || *s == '\0')
234 ret = RFILE;
235 if (((int)(strlen(s)+strlen(RFILE)+2)) > size)
236 ret=RFILE;
237 else
238 {
239 strlcpy(buf,s,size);
240#ifndef VMS
241 strcat(buf,"/");
242#endif
243 strlcat(buf,RFILE,size);
244 ret=buf;
245 }
246 }
247#ifdef DEVRANDOM
248 /* given that all random loads just fail if the file can't be
249 * seen on a stat, we stat the file we're returning, if it
250 * fails, use DEVRANDOM instead. the allows the user to
251 * use their own source for good random data, but defaults
252 * to something hopefully decent if that isn't available.
253 */
254
255 if (stat(ret,&sb) == -1)
256 ret = DEVRANDOM;
257#endif
258 return(ret);
259 }
260
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 8556dddab0..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, const unsigned char *data);
81void RC4(RC4_KEY *key, unsigned long len, const 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 d5f18a3a70..0000000000
--- a/src/lib/libcrypto/rc4/rc4_enc.c
+++ /dev/null
@@ -1,315 +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, const 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#if defined(RC4_CHUNK)
82 /*
83 * The original reason for implementing this(*) was the fact that
84 * pre-21164a Alpha CPUs don't have byte load/store instructions
85 * and e.g. a byte store has to be done with 64-bit load, shift,
86 * and, or and finally 64-bit store. Peaking data and operating
87 * at natural word size made it possible to reduce amount of
88 * instructions as well as to perform early read-ahead without
89 * suffering from RAW (read-after-write) hazard. This resulted
90 * in ~40%(**) performance improvement on 21064 box with gcc.
91 * But it's not only Alpha users who win here:-) Thanks to the
92 * early-n-wide read-ahead this implementation also exhibits
93 * >40% speed-up on SPARC and 20-30% on 64-bit MIPS (depending
94 * on sizeof(RC4_INT)).
95 *
96 * (*) "this" means code which recognizes the case when input
97 * and output pointers appear to be aligned at natural CPU
98 * word boundary
99 * (**) i.e. according to 'apps/openssl speed rc4' benchmark,
100 * crypto/rc4/rc4speed.c exhibits almost 70% speed-up...
101 *
102 * Cavets.
103 *
104 * - RC4_CHUNK="unsigned long long" should be a #1 choice for
105 * UltraSPARC. Unfortunately gcc generates very slow code
106 * (2.5-3 times slower than one generated by Sun's WorkShop
107 * C) and therefore gcc (at least 2.95 and earlier) should
108 * always be told that RC4_CHUNK="unsigned long".
109 *
110 * <appro@fy.chalmers.se>
111 */
112
113# define RC4_STEP ( \
114 x=(x+1) &0xff, \
115 tx=d[x], \
116 y=(tx+y)&0xff, \
117 ty=d[y], \
118 d[y]=tx, \
119 d[x]=ty, \
120 (RC4_CHUNK)d[(tx+ty)&0xff]\
121 )
122
123 if ( ( ((unsigned long)indata & (sizeof(RC4_CHUNK)-1)) |
124 ((unsigned long)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
125 {
126 RC4_CHUNK ichunk,otp;
127 const union { long one; char little; } is_endian = {1};
128
129 /*
130 * I reckon we can afford to implement both endian
131 * cases and to decide which way to take at run-time
132 * because the machine code appears to be very compact
133 * and redundant 1-2KB is perfectly tolerable (i.e.
134 * in case the compiler fails to eliminate it:-). By
135 * suggestion from Terrel Larson <terr@terralogic.net>
136 * who also stands for the is_endian union:-)
137 *
138 * Special notes.
139 *
140 * - is_endian is declared automatic as doing otherwise
141 * (declaring static) prevents gcc from eliminating
142 * the redundant code;
143 * - compilers (those I've tried) don't seem to have
144 * problems eliminating either the operators guarded
145 * by "if (sizeof(RC4_CHUNK)==8)" or the condition
146 * expressions themselves so I've got 'em to replace
147 * corresponding #ifdefs from the previous version;
148 * - I chose to let the redundant switch cases when
149 * sizeof(RC4_CHUNK)!=8 be (were also #ifdefed
150 * before);
151 * - in case you wonder "&(sizeof(RC4_CHUNK)*8-1)" in
152 * [LB]ESHFT guards against "shift is out of range"
153 * warnings when sizeof(RC4_CHUNK)!=8
154 *
155 * <appro@fy.chalmers.se>
156 */
157 if (!is_endian.little)
158 { /* BIG-ENDIAN CASE */
159# define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
160 for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK))
161 {
162 ichunk = *(RC4_CHUNK *)indata;
163 otp = RC4_STEP<<BESHFT(0);
164 otp |= RC4_STEP<<BESHFT(1);
165 otp |= RC4_STEP<<BESHFT(2);
166 otp |= RC4_STEP<<BESHFT(3);
167 if (sizeof(RC4_CHUNK)==8)
168 {
169 otp |= RC4_STEP<<BESHFT(4);
170 otp |= RC4_STEP<<BESHFT(5);
171 otp |= RC4_STEP<<BESHFT(6);
172 otp |= RC4_STEP<<BESHFT(7);
173 }
174 *(RC4_CHUNK *)outdata = otp^ichunk;
175 indata += sizeof(RC4_CHUNK);
176 outdata += sizeof(RC4_CHUNK);
177 }
178 if (len)
179 {
180 RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
181
182 ichunk = *(RC4_CHUNK *)indata;
183 ochunk = *(RC4_CHUNK *)outdata;
184 otp = 0;
185 i = BESHFT(0);
186 mask <<= (sizeof(RC4_CHUNK)-len)<<3;
187 switch (len&(sizeof(RC4_CHUNK)-1))
188 {
189 case 7: otp = RC4_STEP<<i, i-=8;
190 case 6: otp |= RC4_STEP<<i, i-=8;
191 case 5: otp |= RC4_STEP<<i, i-=8;
192 case 4: otp |= RC4_STEP<<i, i-=8;
193 case 3: otp |= RC4_STEP<<i, i-=8;
194 case 2: otp |= RC4_STEP<<i, i-=8;
195 case 1: otp |= RC4_STEP<<i, i-=8;
196 case 0: ; /*
197 * it's never the case,
198 * but it has to be here
199 * for ultrix?
200 */
201 }
202 ochunk &= ~mask;
203 ochunk |= (otp^ichunk) & mask;
204 *(RC4_CHUNK *)outdata = ochunk;
205 }
206 key->x=x;
207 key->y=y;
208 return;
209 }
210 else
211 { /* LITTLE-ENDIAN CASE */
212# define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1))
213 for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK))
214 {
215 ichunk = *(RC4_CHUNK *)indata;
216 otp = RC4_STEP;
217 otp |= RC4_STEP<<8;
218 otp |= RC4_STEP<<16;
219 otp |= RC4_STEP<<24;
220 if (sizeof(RC4_CHUNK)==8)
221 {
222 otp |= RC4_STEP<<LESHFT(4);
223 otp |= RC4_STEP<<LESHFT(5);
224 otp |= RC4_STEP<<LESHFT(6);
225 otp |= RC4_STEP<<LESHFT(7);
226 }
227 *(RC4_CHUNK *)outdata = otp^ichunk;
228 indata += sizeof(RC4_CHUNK);
229 outdata += sizeof(RC4_CHUNK);
230 }
231 if (len)
232 {
233 RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
234
235 ichunk = *(RC4_CHUNK *)indata;
236 ochunk = *(RC4_CHUNK *)outdata;
237 otp = 0;
238 i = 0;
239 mask >>= (sizeof(RC4_CHUNK)-len)<<3;
240 switch (len&(sizeof(RC4_CHUNK)-1))
241 {
242 case 7: otp = RC4_STEP, i+=8;
243 case 6: otp |= RC4_STEP<<i, i+=8;
244 case 5: otp |= RC4_STEP<<i, i+=8;
245 case 4: otp |= RC4_STEP<<i, i+=8;
246 case 3: otp |= RC4_STEP<<i, i+=8;
247 case 2: otp |= RC4_STEP<<i, i+=8;
248 case 1: otp |= RC4_STEP<<i, i+=8;
249 case 0: ; /*
250 * it's never the case,
251 * but it has to be here
252 * for ultrix?
253 */
254 }
255 ochunk &= ~mask;
256 ochunk |= (otp^ichunk) & mask;
257 *(RC4_CHUNK *)outdata = ochunk;
258 }
259 key->x=x;
260 key->y=y;
261 return;
262 }
263 }
264#endif
265#define LOOP(in,out) \
266 x=((x+1)&0xff); \
267 tx=d[x]; \
268 y=(tx+y)&0xff; \
269 d[x]=ty=d[y]; \
270 d[y]=tx; \
271 (out) = d[(tx+ty)&0xff]^ (in);
272
273#ifndef RC4_INDEX
274#define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++))
275#else
276#define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
277#endif
278
279 i=(int)(len>>3L);
280 if (i)
281 {
282 for (;;)
283 {
284 RC4_LOOP(indata,outdata,0);
285 RC4_LOOP(indata,outdata,1);
286 RC4_LOOP(indata,outdata,2);
287 RC4_LOOP(indata,outdata,3);
288 RC4_LOOP(indata,outdata,4);
289 RC4_LOOP(indata,outdata,5);
290 RC4_LOOP(indata,outdata,6);
291 RC4_LOOP(indata,outdata,7);
292#ifdef RC4_INDEX
293 indata+=8;
294 outdata+=8;
295#endif
296 if (--i == 0) break;
297 }
298 }
299 i=(int)len&0x07;
300 if (i)
301 {
302 for (;;)
303 {
304 RC4_LOOP(indata,outdata,0); if (--i == 0) break;
305 RC4_LOOP(indata,outdata,1); if (--i == 0) break;
306 RC4_LOOP(indata,outdata,2); if (--i == 0) break;
307 RC4_LOOP(indata,outdata,3); if (--i == 0) break;
308 RC4_LOOP(indata,outdata,4); if (--i == 0) break;
309 RC4_LOOP(indata,outdata,5); if (--i == 0) break;
310 RC4_LOOP(indata,outdata,6); if (--i == 0) break;
311 }
312 }
313 key->x=x;
314 key->y=y;
315 }
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 bb10c1ebe2..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, const 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 0ab6f76bff..0000000000
--- a/src/lib/libcrypto/ripemd/asm/rmd-586.pl
+++ /dev/null
@@ -1,590 +0,0 @@
1#!/usr/local/bin/perl
2
3# Normal is the
4# ripemd160_block_asm_host_order(RIPEMD160_CTX *c, ULONG *X,int blocks);
5
6$normal=0;
7
8push(@INC,"perlasm","../../perlasm");
9require "x86asm.pl";
10
11&asm_init($ARGV[0],$0);
12
13$A="ecx";
14$B="esi";
15$C="edi";
16$D="ebx";
17$E="ebp";
18$tmp1="eax";
19$tmp2="edx";
20
21$KL1=0x5A827999;
22$KL2=0x6ED9EBA1;
23$KL3=0x8F1BBCDC;
24$KL4=0xA953FD4E;
25$KR0=0x50A28BE6;
26$KR1=0x5C4DD124;
27$KR2=0x6D703EF3;
28$KR3=0x7A6D76E9;
29
30
31@wl=( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,
32 7, 4,13, 1,10, 6,15, 3,12, 0, 9, 5, 2,14,11, 8,
33 3,10,14, 4, 9,15, 8, 1, 2, 7, 0, 6,13,11, 5,12,
34 1, 9,11,10, 0, 8,12, 4,13, 3, 7,15,14, 5, 6, 2,
35 4, 0, 5, 9, 7,12, 2,10,14, 1, 3, 8,11, 6,15,13,
36 );
37
38@wr=( 5,14, 7, 0, 9, 2,11, 4,13, 6,15, 8, 1,10, 3,12,
39 6,11, 3, 7, 0,13, 5,10,14,15, 8,12, 4, 9, 1, 2,
40 15, 5, 1, 3, 7,14, 6, 9,11, 8,12, 2,10, 0, 4,13,
41 8, 6, 4, 1, 3,11,15, 0, 5,12, 2,13, 9, 7,10,14,
42 12,15,10, 4, 1, 5, 8, 7, 6, 2,13,14, 0, 3, 9,11,
43 );
44
45@sl=( 11,14,15,12, 5, 8, 7, 9,11,13,14,15, 6, 7, 9, 8,
46 7, 6, 8,13,11, 9, 7,15, 7,12,15, 9,11, 7,13,12,
47 11,13, 6, 7,14, 9,13,15,14, 8,13, 6, 5,12, 7, 5,
48 11,12,14,15,14,15, 9, 8, 9,14, 5, 6, 8, 6, 5,12,
49 9,15, 5,11, 6, 8,13,12, 5,12,13,14,11, 8, 5, 6,
50 );
51
52@sr=( 8, 9, 9,11,13,15,15, 5, 7, 7, 8,11,14,14,12, 6,
53 9,13,15, 7,12, 8, 9,11, 7, 7,12, 7, 6,15,13,11,
54 9, 7,15,11, 8, 6, 6,14,12,13, 5,14,13,13, 7, 5,
55 15, 5, 8,11,14,14, 6,14, 6, 9,12, 9,12, 5,15, 8,
56 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11,
57 );
58
59&ripemd160_block("ripemd160_block_asm_host_order");
60&asm_finish();
61
62sub Xv
63 {
64 local($n)=@_;
65 return(&swtmp($n));
66 # tmp on stack
67 }
68
69sub Np
70 {
71 local($p)=@_;
72 local(%n)=($A,$E,$B,$A,$C,$B,$D,$C,$E,$D);
73 return($n{$p});
74 }
75
76sub RIP1
77 {
78 local($a,$b,$c,$d,$e,$pos,$s,$o,$pos2)=@_;
79
80 &comment($p++);
81 if ($p & 1)
82 {
83 #&mov($tmp1, $c) if $o == -1;
84 &xor($tmp1, $d) if $o == -1;
85 &mov($tmp2, &Xv($pos));
86 &xor($tmp1, $b);
87 &add($a, $tmp2);
88 &rotl($c, 10);
89 &add($a, $tmp1);
90 &mov($tmp1, &Np($c)); # NEXT
91 # XXX
92 &rotl($a, $s);
93 &add($a, $e);
94 }
95 else
96 {
97 &xor($tmp1, $d);
98 &mov($tmp2, &Xv($pos));
99 &xor($tmp1, $b);
100 &add($a, $tmp1);
101 &mov($tmp1, &Np($c)) if $o <= 0;
102 &mov($tmp1, -1) if $o == 1;
103 # XXX if $o == 2;
104 &rotl($c, 10);
105 &add($a, $tmp2);
106 &xor($tmp1, &Np($d)) if $o <= 0;
107 &mov($tmp2, &Xv($pos2)) if $o == 1;
108 &mov($tmp2, &wparam(0)) if $o == 2;
109 &rotl($a, $s);
110 &add($a, $e);
111 }
112 }
113
114sub RIP2
115 {
116 local($a,$b,$c,$d,$e,$pos,$pos2,$s,$K,$o)=@_;
117
118# XXXXXX
119 &comment($p++);
120 if ($p & 1)
121 {
122# &mov($tmp2, &Xv($pos)) if $o < -1;
123# &mov($tmp1, -1) if $o < -1;
124
125 &add($a, $tmp2);
126 &mov($tmp2, $c);
127 &sub($tmp1, $b);
128 &and($tmp2, $b);
129 &and($tmp1, $d);
130 &or($tmp2, $tmp1);
131 &mov($tmp1, &Xv($pos2)) if $o <= 0; # XXXXXXXXXXXXXX
132 # XXX
133 &rotl($c, 10);
134 &lea($a, &DWP($K,$a,$tmp2,1));
135 &mov($tmp2, -1) if $o <= 0;
136 # XXX
137 &rotl($a, $s);
138 &add($a, $e);
139 }
140 else
141 {
142 # XXX
143 &add($a, $tmp1);
144 &mov($tmp1, $c);
145 &sub($tmp2, $b);
146 &and($tmp1, $b);
147 &and($tmp2, $d);
148 if ($o != 2)
149 {
150 &or($tmp1, $tmp2);
151 &mov($tmp2, &Xv($pos2)) if $o <= 0;
152 &mov($tmp2, -1) if $o == 1;
153 &rotl($c, 10);
154 &lea($a, &DWP($K,$a,$tmp1,1));
155 &mov($tmp1, -1) if $o <= 0;
156 &sub($tmp2, &Np($c)) if $o == 1;
157 } else {
158 &or($tmp2, $tmp1);
159 &mov($tmp1, &Np($c));
160 &rotl($c, 10);
161 &lea($a, &DWP($K,$a,$tmp2,1));
162 &xor($tmp1, &Np($d));
163 }
164 &rotl($a, $s);
165 &add($a, $e);
166 }
167 }
168
169sub RIP3
170 {
171 local($a,$b,$c,$d,$e,$pos,$s,$K,$o,$pos2)=@_;
172
173 &comment($p++);
174 if ($p & 1)
175 {
176# &mov($tmp2, -1) if $o < -1;
177# &sub($tmp2, $c) if $o < -1;
178 &mov($tmp1, &Xv($pos));
179 &or($tmp2, $b);
180 &add($a, $tmp1);
181 &xor($tmp2, $d);
182 &mov($tmp1, -1) if $o <= 0; # NEXT
183 # XXX
184 &rotl($c, 10);
185 &lea($a, &DWP($K,$a,$tmp2,1));
186 &sub($tmp1, &Np($c)) if $o <= 0; # NEXT
187 # XXX
188 &rotl($a, $s);
189 &add($a, $e);
190 }
191 else
192 {
193 &mov($tmp2, &Xv($pos));
194 &or($tmp1, $b);
195 &add($a, $tmp2);
196 &xor($tmp1, $d);
197 &mov($tmp2, -1) if $o <= 0; # NEXT
198 &mov($tmp2, -1) if $o == 1;
199 &mov($tmp2, &Xv($pos2)) if $o == 2;
200 &rotl($c, 10);
201 &lea($a, &DWP($K,$a,$tmp1,1));
202 &sub($tmp2, &Np($c)) if $o <= 0; # NEXT
203 &mov($tmp1, &Np($d)) if $o == 1;
204 &mov($tmp1, -1) if $o == 2;
205 &rotl($a, $s);
206 &add($a, $e);
207 }
208 }
209
210sub RIP4
211 {
212 local($a,$b,$c,$d,$e,$pos,$s,$K,$o)=@_;
213
214 &comment($p++);
215 if ($p & 1)
216 {
217# &mov($tmp2, -1) if $o == -2;
218# &mov($tmp1, $d) if $o == -2;
219 &sub($tmp2, $d);
220 &and($tmp1, $b);
221 &and($tmp2, $c);
222 &or($tmp2, $tmp1);
223 &mov($tmp1, &Xv($pos));
224 &rotl($c, 10);
225 &lea($a, &DWP($K,$a,$tmp2));
226 &mov($tmp2, -1) unless $o > 0; # NEXT
227 # XXX
228 &add($a, $tmp1);
229 &mov($tmp1, &Np($d)) unless $o > 0; # NEXT
230 # XXX
231 &rotl($a, $s);
232 &add($a, $e);
233 }
234 else
235 {
236 &sub($tmp2, $d);
237 &and($tmp1, $b);
238 &and($tmp2, $c);
239 &or($tmp2, $tmp1);
240 &mov($tmp1, &Xv($pos));
241 &rotl($c, 10);
242 &lea($a, &DWP($K,$a,$tmp2));
243 &mov($tmp2, -1) if $o == 0; # NEXT
244 &mov($tmp2, -1) if $o == 1;
245 &mov($tmp2, -1) if $o == 2;
246 # XXX
247 &add($a, $tmp1);
248 &mov($tmp1, &Np($d)) if $o == 0; # NEXT
249 &sub($tmp2, &Np($d)) if $o == 1;
250 &sub($tmp2, &Np($c)) if $o == 2;
251 # XXX
252 &rotl($a, $s);
253 &add($a, $e);
254 }
255 }
256
257sub RIP5
258 {
259 local($a,$b,$c,$d,$e,$pos,$s,$K,$o)=@_;
260
261 &comment($p++);
262 if ($p & 1)
263 {
264 &mov($tmp2, -1) if $o == -2;
265 &sub($tmp2, $d) if $o == -2;
266 &mov($tmp1, &Xv($pos));
267 &or($tmp2, $c);
268 &add($a, $tmp1);
269 &xor($tmp2, $b);
270 &mov($tmp1, -1) if $o <= 0;
271 # XXX
272 &rotl($c, 10);
273 &lea($a, &DWP($K,$a,$tmp2,1));
274 &sub($tmp1, &Np($d)) if $o <= 0;
275 # XXX
276 &rotl($a, $s);
277 &add($a, $e);
278 }
279 else
280 {
281 &mov($tmp2, &Xv($pos));
282 &or($tmp1, $c);
283 &add($a, $tmp2);
284 &xor($tmp1, $b);
285 &mov($tmp2, -1) if $o <= 0;
286 &mov($tmp2, &wparam(0)) if $o == 1; # Middle code
287 &mov($tmp2, -1) if $o == 2;
288 &rotl($c, 10);
289 &lea($a, &DWP($K,$a,$tmp1,1));
290 &sub($tmp2, &Np($d)) if $o <= 0;
291 &mov(&swtmp(16), $A) if $o == 1;
292 &mov($tmp1, &Np($d)) if $o == 2;
293 &rotl($a, $s);
294 &add($a, $e);
295 }
296 }
297
298sub ripemd160_block
299 {
300 local($name)=@_;
301
302 &function_begin_B($name,"",3);
303
304 # parameter 1 is the RIPEMD160_CTX structure.
305 # A 0
306 # B 4
307 # C 8
308 # D 12
309 # E 16
310
311 &mov($tmp2, &wparam(0));
312 &mov($tmp1, &wparam(1));
313 &push("esi");
314 &mov($A, &DWP( 0,$tmp2,"",0));
315 &push("edi");
316 &mov($B, &DWP( 4,$tmp2,"",0));
317 &push("ebp");
318 &mov($C, &DWP( 8,$tmp2,"",0));
319 &push("ebx");
320 &stack_push(16+5+6);
321 # Special comment about the figure of 6.
322 # Idea is to pad the current frame so
323 # that the top of the stack gets fairly
324 # aligned. Well, as you realize it would
325 # always depend on how the frame below is
326 # aligned. The good news are that gcc-2.95
327 # and later does keep first argument at
328 # least double-wise aligned.
329 # <appro@fy.chalmers.se>
330
331 &set_label("start") unless $normal;
332 &comment("");
333
334 # &mov($tmp1, &wparam(1)); # Done at end of loop
335 # &mov($tmp2, &wparam(0)); # Done at end of loop
336
337 for ($z=0; $z<16; $z+=2)
338 {
339 &mov($D, &DWP( $z*4,$tmp1,"",0));
340 &mov($E, &DWP( ($z+1)*4,$tmp1,"",0));
341 &mov(&swtmp($z), $D);
342 &mov(&swtmp($z+1), $E);
343 }
344 &mov($tmp1, $C);
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(16), $A);
435 &mov($A, &DWP( 0,$tmp2,"",0));
436 &mov(&swtmp(16+1), $B);
437 &mov(&swtmp(16+2), $C);
438 &mov($B, &DWP( 4,$tmp2,"",0));
439 &mov(&swtmp(16+3), $D);
440 &mov($C, &DWP( 8,$tmp2,"",0));
441 &mov(&swtmp(16+4), $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(16+2)); # $c
535 &add($D, $tmp1);
536
537 &mov($tmp1, &DWP( 8,$tmp2,"",0)); # ctx->C
538 &add($E, $tmp1);
539 &mov($tmp1, &swtmp(16+3)); # $d
540 &add($E, $tmp1);
541
542 &mov($tmp1, &DWP(12,$tmp2,"",0)); # ctx->D
543 &add($A, $tmp1);
544 &mov($tmp1, &swtmp(16+4)); # $e
545 &add($A, $tmp1);
546
547
548 &mov($tmp1, &DWP(16,$tmp2,"",0)); # ctx->E
549 &add($B, $tmp1);
550 &mov($tmp1, &swtmp(16+0)); # $a
551 &add($B, $tmp1);
552
553 &mov($tmp1, &DWP( 0,$tmp2,"",0)); # ctx->A
554 &add($C, $tmp1);
555 &mov($tmp1, &swtmp(16+1)); # $b
556 &add($C, $tmp1);
557
558 &mov($tmp1, &wparam(2));
559
560 &mov(&DWP( 0,$tmp2,"",0), $D);
561 &mov(&DWP( 4,$tmp2,"",0), $E);
562 &mov(&DWP( 8,$tmp2,"",0), $A);
563 &sub($tmp1,1);
564 &mov(&DWP(12,$tmp2,"",0), $B);
565 &mov(&DWP(16,$tmp2,"",0), $C);
566
567 &jle(&label("get_out"));
568
569 &mov(&wparam(2),$tmp1);
570 &mov($C, $A);
571 &mov($tmp1, &wparam(1));
572 &mov($A, $D);
573 &add($tmp1, 64);
574 &mov($B, $E);
575 &mov(&wparam(1),$tmp1);
576
577 &jmp(&label("start"));
578
579 &set_label("get_out");
580
581 &stack_pop(16+5+6);
582
583 &pop("ebx");
584 &pop("ebp");
585 &pop("edi");
586 &pop("esi");
587 &ret();
588 &function_end_B($name);
589 }
590
diff --git a/src/lib/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h
deleted file mode 100644
index dd1627cf40..0000000000
--- a/src/lib/libcrypto/ripemd/ripemd.h
+++ /dev/null
@@ -1,101 +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#if defined(WIN16) || defined(__LP32__)
71#define RIPEMD160_LONG unsigned long
72#elif defined(_CRAY) || defined(__ILP64__)
73#define RIPEMD160_LONG unsigned long
74#define RIPEMD160_LONG_LOG2 3
75#else
76#define RIPEMD160_LONG unsigned int
77#endif
78
79#define RIPEMD160_CBLOCK 64
80#define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4)
81#define RIPEMD160_DIGEST_LENGTH 20
82
83typedef struct RIPEMD160state_st
84 {
85 RIPEMD160_LONG A,B,C,D,E;
86 RIPEMD160_LONG Nl,Nh;
87 RIPEMD160_LONG data[RIPEMD160_LBLOCK];
88 int num;
89 } RIPEMD160_CTX;
90
91void RIPEMD160_Init(RIPEMD160_CTX *c);
92void RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, unsigned long len);
93void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
94unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
95 unsigned char *md);
96void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);
97#ifdef __cplusplus
98}
99#endif
100
101#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c
deleted file mode 100644
index bdfae270b6..0000000000
--- a/src/lib/libcrypto/ripemd/rmd_dgst.c
+++ /dev/null
@@ -1,493 +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
63const char *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
71
72void RIPEMD160_Init(RIPEMD160_CTX *c)
73 {
74 c->A=RIPEMD160_A;
75 c->B=RIPEMD160_B;
76 c->C=RIPEMD160_C;
77 c->D=RIPEMD160_D;
78 c->E=RIPEMD160_E;
79 c->Nl=0;
80 c->Nh=0;
81 c->num=0;
82 }
83
84#ifndef ripemd160_block_host_order
85#ifdef X
86#undef X
87#endif
88#define X(i) XX[i]
89void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num)
90 {
91 const RIPEMD160_LONG *XX=p;
92 register unsigned long A,B,C,D,E;
93 register unsigned long a,b,c,d,e;
94
95 for (;num--;XX+=HASH_LBLOCK)
96 {
97
98 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
99
100 RIP1(A,B,C,D,E,WL00,SL00);
101 RIP1(E,A,B,C,D,WL01,SL01);
102 RIP1(D,E,A,B,C,WL02,SL02);
103 RIP1(C,D,E,A,B,WL03,SL03);
104 RIP1(B,C,D,E,A,WL04,SL04);
105 RIP1(A,B,C,D,E,WL05,SL05);
106 RIP1(E,A,B,C,D,WL06,SL06);
107 RIP1(D,E,A,B,C,WL07,SL07);
108 RIP1(C,D,E,A,B,WL08,SL08);
109 RIP1(B,C,D,E,A,WL09,SL09);
110 RIP1(A,B,C,D,E,WL10,SL10);
111 RIP1(E,A,B,C,D,WL11,SL11);
112 RIP1(D,E,A,B,C,WL12,SL12);
113 RIP1(C,D,E,A,B,WL13,SL13);
114 RIP1(B,C,D,E,A,WL14,SL14);
115 RIP1(A,B,C,D,E,WL15,SL15);
116
117 RIP2(E,A,B,C,D,WL16,SL16,KL1);
118 RIP2(D,E,A,B,C,WL17,SL17,KL1);
119 RIP2(C,D,E,A,B,WL18,SL18,KL1);
120 RIP2(B,C,D,E,A,WL19,SL19,KL1);
121 RIP2(A,B,C,D,E,WL20,SL20,KL1);
122 RIP2(E,A,B,C,D,WL21,SL21,KL1);
123 RIP2(D,E,A,B,C,WL22,SL22,KL1);
124 RIP2(C,D,E,A,B,WL23,SL23,KL1);
125 RIP2(B,C,D,E,A,WL24,SL24,KL1);
126 RIP2(A,B,C,D,E,WL25,SL25,KL1);
127 RIP2(E,A,B,C,D,WL26,SL26,KL1);
128 RIP2(D,E,A,B,C,WL27,SL27,KL1);
129 RIP2(C,D,E,A,B,WL28,SL28,KL1);
130 RIP2(B,C,D,E,A,WL29,SL29,KL1);
131 RIP2(A,B,C,D,E,WL30,SL30,KL1);
132 RIP2(E,A,B,C,D,WL31,SL31,KL1);
133
134 RIP3(D,E,A,B,C,WL32,SL32,KL2);
135 RIP3(C,D,E,A,B,WL33,SL33,KL2);
136 RIP3(B,C,D,E,A,WL34,SL34,KL2);
137 RIP3(A,B,C,D,E,WL35,SL35,KL2);
138 RIP3(E,A,B,C,D,WL36,SL36,KL2);
139 RIP3(D,E,A,B,C,WL37,SL37,KL2);
140 RIP3(C,D,E,A,B,WL38,SL38,KL2);
141 RIP3(B,C,D,E,A,WL39,SL39,KL2);
142 RIP3(A,B,C,D,E,WL40,SL40,KL2);
143 RIP3(E,A,B,C,D,WL41,SL41,KL2);
144 RIP3(D,E,A,B,C,WL42,SL42,KL2);
145 RIP3(C,D,E,A,B,WL43,SL43,KL2);
146 RIP3(B,C,D,E,A,WL44,SL44,KL2);
147 RIP3(A,B,C,D,E,WL45,SL45,KL2);
148 RIP3(E,A,B,C,D,WL46,SL46,KL2);
149 RIP3(D,E,A,B,C,WL47,SL47,KL2);
150
151 RIP4(C,D,E,A,B,WL48,SL48,KL3);
152 RIP4(B,C,D,E,A,WL49,SL49,KL3);
153 RIP4(A,B,C,D,E,WL50,SL50,KL3);
154 RIP4(E,A,B,C,D,WL51,SL51,KL3);
155 RIP4(D,E,A,B,C,WL52,SL52,KL3);
156 RIP4(C,D,E,A,B,WL53,SL53,KL3);
157 RIP4(B,C,D,E,A,WL54,SL54,KL3);
158 RIP4(A,B,C,D,E,WL55,SL55,KL3);
159 RIP4(E,A,B,C,D,WL56,SL56,KL3);
160 RIP4(D,E,A,B,C,WL57,SL57,KL3);
161 RIP4(C,D,E,A,B,WL58,SL58,KL3);
162 RIP4(B,C,D,E,A,WL59,SL59,KL3);
163 RIP4(A,B,C,D,E,WL60,SL60,KL3);
164 RIP4(E,A,B,C,D,WL61,SL61,KL3);
165 RIP4(D,E,A,B,C,WL62,SL62,KL3);
166 RIP4(C,D,E,A,B,WL63,SL63,KL3);
167
168 RIP5(B,C,D,E,A,WL64,SL64,KL4);
169 RIP5(A,B,C,D,E,WL65,SL65,KL4);
170 RIP5(E,A,B,C,D,WL66,SL66,KL4);
171 RIP5(D,E,A,B,C,WL67,SL67,KL4);
172 RIP5(C,D,E,A,B,WL68,SL68,KL4);
173 RIP5(B,C,D,E,A,WL69,SL69,KL4);
174 RIP5(A,B,C,D,E,WL70,SL70,KL4);
175 RIP5(E,A,B,C,D,WL71,SL71,KL4);
176 RIP5(D,E,A,B,C,WL72,SL72,KL4);
177 RIP5(C,D,E,A,B,WL73,SL73,KL4);
178 RIP5(B,C,D,E,A,WL74,SL74,KL4);
179 RIP5(A,B,C,D,E,WL75,SL75,KL4);
180 RIP5(E,A,B,C,D,WL76,SL76,KL4);
181 RIP5(D,E,A,B,C,WL77,SL77,KL4);
182 RIP5(C,D,E,A,B,WL78,SL78,KL4);
183 RIP5(B,C,D,E,A,WL79,SL79,KL4);
184
185 a=A; b=B; c=C; d=D; e=E;
186 /* Do other half */
187 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
188
189 RIP5(A,B,C,D,E,WR00,SR00,KR0);
190 RIP5(E,A,B,C,D,WR01,SR01,KR0);
191 RIP5(D,E,A,B,C,WR02,SR02,KR0);
192 RIP5(C,D,E,A,B,WR03,SR03,KR0);
193 RIP5(B,C,D,E,A,WR04,SR04,KR0);
194 RIP5(A,B,C,D,E,WR05,SR05,KR0);
195 RIP5(E,A,B,C,D,WR06,SR06,KR0);
196 RIP5(D,E,A,B,C,WR07,SR07,KR0);
197 RIP5(C,D,E,A,B,WR08,SR08,KR0);
198 RIP5(B,C,D,E,A,WR09,SR09,KR0);
199 RIP5(A,B,C,D,E,WR10,SR10,KR0);
200 RIP5(E,A,B,C,D,WR11,SR11,KR0);
201 RIP5(D,E,A,B,C,WR12,SR12,KR0);
202 RIP5(C,D,E,A,B,WR13,SR13,KR0);
203 RIP5(B,C,D,E,A,WR14,SR14,KR0);
204 RIP5(A,B,C,D,E,WR15,SR15,KR0);
205
206 RIP4(E,A,B,C,D,WR16,SR16,KR1);
207 RIP4(D,E,A,B,C,WR17,SR17,KR1);
208 RIP4(C,D,E,A,B,WR18,SR18,KR1);
209 RIP4(B,C,D,E,A,WR19,SR19,KR1);
210 RIP4(A,B,C,D,E,WR20,SR20,KR1);
211 RIP4(E,A,B,C,D,WR21,SR21,KR1);
212 RIP4(D,E,A,B,C,WR22,SR22,KR1);
213 RIP4(C,D,E,A,B,WR23,SR23,KR1);
214 RIP4(B,C,D,E,A,WR24,SR24,KR1);
215 RIP4(A,B,C,D,E,WR25,SR25,KR1);
216 RIP4(E,A,B,C,D,WR26,SR26,KR1);
217 RIP4(D,E,A,B,C,WR27,SR27,KR1);
218 RIP4(C,D,E,A,B,WR28,SR28,KR1);
219 RIP4(B,C,D,E,A,WR29,SR29,KR1);
220 RIP4(A,B,C,D,E,WR30,SR30,KR1);
221 RIP4(E,A,B,C,D,WR31,SR31,KR1);
222
223 RIP3(D,E,A,B,C,WR32,SR32,KR2);
224 RIP3(C,D,E,A,B,WR33,SR33,KR2);
225 RIP3(B,C,D,E,A,WR34,SR34,KR2);
226 RIP3(A,B,C,D,E,WR35,SR35,KR2);
227 RIP3(E,A,B,C,D,WR36,SR36,KR2);
228 RIP3(D,E,A,B,C,WR37,SR37,KR2);
229 RIP3(C,D,E,A,B,WR38,SR38,KR2);
230 RIP3(B,C,D,E,A,WR39,SR39,KR2);
231 RIP3(A,B,C,D,E,WR40,SR40,KR2);
232 RIP3(E,A,B,C,D,WR41,SR41,KR2);
233 RIP3(D,E,A,B,C,WR42,SR42,KR2);
234 RIP3(C,D,E,A,B,WR43,SR43,KR2);
235 RIP3(B,C,D,E,A,WR44,SR44,KR2);
236 RIP3(A,B,C,D,E,WR45,SR45,KR2);
237 RIP3(E,A,B,C,D,WR46,SR46,KR2);
238 RIP3(D,E,A,B,C,WR47,SR47,KR2);
239
240 RIP2(C,D,E,A,B,WR48,SR48,KR3);
241 RIP2(B,C,D,E,A,WR49,SR49,KR3);
242 RIP2(A,B,C,D,E,WR50,SR50,KR3);
243 RIP2(E,A,B,C,D,WR51,SR51,KR3);
244 RIP2(D,E,A,B,C,WR52,SR52,KR3);
245 RIP2(C,D,E,A,B,WR53,SR53,KR3);
246 RIP2(B,C,D,E,A,WR54,SR54,KR3);
247 RIP2(A,B,C,D,E,WR55,SR55,KR3);
248 RIP2(E,A,B,C,D,WR56,SR56,KR3);
249 RIP2(D,E,A,B,C,WR57,SR57,KR3);
250 RIP2(C,D,E,A,B,WR58,SR58,KR3);
251 RIP2(B,C,D,E,A,WR59,SR59,KR3);
252 RIP2(A,B,C,D,E,WR60,SR60,KR3);
253 RIP2(E,A,B,C,D,WR61,SR61,KR3);
254 RIP2(D,E,A,B,C,WR62,SR62,KR3);
255 RIP2(C,D,E,A,B,WR63,SR63,KR3);
256
257 RIP1(B,C,D,E,A,WR64,SR64);
258 RIP1(A,B,C,D,E,WR65,SR65);
259 RIP1(E,A,B,C,D,WR66,SR66);
260 RIP1(D,E,A,B,C,WR67,SR67);
261 RIP1(C,D,E,A,B,WR68,SR68);
262 RIP1(B,C,D,E,A,WR69,SR69);
263 RIP1(A,B,C,D,E,WR70,SR70);
264 RIP1(E,A,B,C,D,WR71,SR71);
265 RIP1(D,E,A,B,C,WR72,SR72);
266 RIP1(C,D,E,A,B,WR73,SR73);
267 RIP1(B,C,D,E,A,WR74,SR74);
268 RIP1(A,B,C,D,E,WR75,SR75);
269 RIP1(E,A,B,C,D,WR76,SR76);
270 RIP1(D,E,A,B,C,WR77,SR77);
271 RIP1(C,D,E,A,B,WR78,SR78);
272 RIP1(B,C,D,E,A,WR79,SR79);
273
274 D =ctx->B+c+D;
275 ctx->B=ctx->C+d+E;
276 ctx->C=ctx->D+e+A;
277 ctx->D=ctx->E+a+B;
278 ctx->E=ctx->A+b+C;
279 ctx->A=D;
280
281 }
282 }
283#endif
284
285#ifndef ripemd160_block_data_order
286#ifdef X
287#undef X
288#endif
289void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, int num)
290 {
291 const unsigned char *data=p;
292 register unsigned long A,B,C,D,E;
293 unsigned long a,b,c,d,e,l;
294#ifndef MD32_XARRAY
295 /* See comment in crypto/sha/sha_locl.h for details. */
296 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
297 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
298# define X(i) XX##i
299#else
300 RIPEMD160_LONG XX[16];
301# define X(i) XX[i]
302#endif
303
304 for (;num--;)
305 {
306
307 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
308
309 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
310 RIP1(A,B,C,D,E,WL00,SL00); HOST_c2l(data,l); X( 2)=l;
311 RIP1(E,A,B,C,D,WL01,SL01); HOST_c2l(data,l); X( 3)=l;
312 RIP1(D,E,A,B,C,WL02,SL02); HOST_c2l(data,l); X( 4)=l;
313 RIP1(C,D,E,A,B,WL03,SL03); HOST_c2l(data,l); X( 5)=l;
314 RIP1(B,C,D,E,A,WL04,SL04); HOST_c2l(data,l); X( 6)=l;
315 RIP1(A,B,C,D,E,WL05,SL05); HOST_c2l(data,l); X( 7)=l;
316 RIP1(E,A,B,C,D,WL06,SL06); HOST_c2l(data,l); X( 8)=l;
317 RIP1(D,E,A,B,C,WL07,SL07); HOST_c2l(data,l); X( 9)=l;
318 RIP1(C,D,E,A,B,WL08,SL08); HOST_c2l(data,l); X(10)=l;
319 RIP1(B,C,D,E,A,WL09,SL09); HOST_c2l(data,l); X(11)=l;
320 RIP1(A,B,C,D,E,WL10,SL10); HOST_c2l(data,l); X(12)=l;
321 RIP1(E,A,B,C,D,WL11,SL11); HOST_c2l(data,l); X(13)=l;
322 RIP1(D,E,A,B,C,WL12,SL12); HOST_c2l(data,l); X(14)=l;
323 RIP1(C,D,E,A,B,WL13,SL13); HOST_c2l(data,l); X(15)=l;
324 RIP1(B,C,D,E,A,WL14,SL14);
325 RIP1(A,B,C,D,E,WL15,SL15);
326
327 RIP2(E,A,B,C,D,WL16,SL16,KL1);
328 RIP2(D,E,A,B,C,WL17,SL17,KL1);
329 RIP2(C,D,E,A,B,WL18,SL18,KL1);
330 RIP2(B,C,D,E,A,WL19,SL19,KL1);
331 RIP2(A,B,C,D,E,WL20,SL20,KL1);
332 RIP2(E,A,B,C,D,WL21,SL21,KL1);
333 RIP2(D,E,A,B,C,WL22,SL22,KL1);
334 RIP2(C,D,E,A,B,WL23,SL23,KL1);
335 RIP2(B,C,D,E,A,WL24,SL24,KL1);
336 RIP2(A,B,C,D,E,WL25,SL25,KL1);
337 RIP2(E,A,B,C,D,WL26,SL26,KL1);
338 RIP2(D,E,A,B,C,WL27,SL27,KL1);
339 RIP2(C,D,E,A,B,WL28,SL28,KL1);
340 RIP2(B,C,D,E,A,WL29,SL29,KL1);
341 RIP2(A,B,C,D,E,WL30,SL30,KL1);
342 RIP2(E,A,B,C,D,WL31,SL31,KL1);
343
344 RIP3(D,E,A,B,C,WL32,SL32,KL2);
345 RIP3(C,D,E,A,B,WL33,SL33,KL2);
346 RIP3(B,C,D,E,A,WL34,SL34,KL2);
347 RIP3(A,B,C,D,E,WL35,SL35,KL2);
348 RIP3(E,A,B,C,D,WL36,SL36,KL2);
349 RIP3(D,E,A,B,C,WL37,SL37,KL2);
350 RIP3(C,D,E,A,B,WL38,SL38,KL2);
351 RIP3(B,C,D,E,A,WL39,SL39,KL2);
352 RIP3(A,B,C,D,E,WL40,SL40,KL2);
353 RIP3(E,A,B,C,D,WL41,SL41,KL2);
354 RIP3(D,E,A,B,C,WL42,SL42,KL2);
355 RIP3(C,D,E,A,B,WL43,SL43,KL2);
356 RIP3(B,C,D,E,A,WL44,SL44,KL2);
357 RIP3(A,B,C,D,E,WL45,SL45,KL2);
358 RIP3(E,A,B,C,D,WL46,SL46,KL2);
359 RIP3(D,E,A,B,C,WL47,SL47,KL2);
360
361 RIP4(C,D,E,A,B,WL48,SL48,KL3);
362 RIP4(B,C,D,E,A,WL49,SL49,KL3);
363 RIP4(A,B,C,D,E,WL50,SL50,KL3);
364 RIP4(E,A,B,C,D,WL51,SL51,KL3);
365 RIP4(D,E,A,B,C,WL52,SL52,KL3);
366 RIP4(C,D,E,A,B,WL53,SL53,KL3);
367 RIP4(B,C,D,E,A,WL54,SL54,KL3);
368 RIP4(A,B,C,D,E,WL55,SL55,KL3);
369 RIP4(E,A,B,C,D,WL56,SL56,KL3);
370 RIP4(D,E,A,B,C,WL57,SL57,KL3);
371 RIP4(C,D,E,A,B,WL58,SL58,KL3);
372 RIP4(B,C,D,E,A,WL59,SL59,KL3);
373 RIP4(A,B,C,D,E,WL60,SL60,KL3);
374 RIP4(E,A,B,C,D,WL61,SL61,KL3);
375 RIP4(D,E,A,B,C,WL62,SL62,KL3);
376 RIP4(C,D,E,A,B,WL63,SL63,KL3);
377
378 RIP5(B,C,D,E,A,WL64,SL64,KL4);
379 RIP5(A,B,C,D,E,WL65,SL65,KL4);
380 RIP5(E,A,B,C,D,WL66,SL66,KL4);
381 RIP5(D,E,A,B,C,WL67,SL67,KL4);
382 RIP5(C,D,E,A,B,WL68,SL68,KL4);
383 RIP5(B,C,D,E,A,WL69,SL69,KL4);
384 RIP5(A,B,C,D,E,WL70,SL70,KL4);
385 RIP5(E,A,B,C,D,WL71,SL71,KL4);
386 RIP5(D,E,A,B,C,WL72,SL72,KL4);
387 RIP5(C,D,E,A,B,WL73,SL73,KL4);
388 RIP5(B,C,D,E,A,WL74,SL74,KL4);
389 RIP5(A,B,C,D,E,WL75,SL75,KL4);
390 RIP5(E,A,B,C,D,WL76,SL76,KL4);
391 RIP5(D,E,A,B,C,WL77,SL77,KL4);
392 RIP5(C,D,E,A,B,WL78,SL78,KL4);
393 RIP5(B,C,D,E,A,WL79,SL79,KL4);
394
395 a=A; b=B; c=C; d=D; e=E;
396 /* Do other half */
397 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
398
399 RIP5(A,B,C,D,E,WR00,SR00,KR0);
400 RIP5(E,A,B,C,D,WR01,SR01,KR0);
401 RIP5(D,E,A,B,C,WR02,SR02,KR0);
402 RIP5(C,D,E,A,B,WR03,SR03,KR0);
403 RIP5(B,C,D,E,A,WR04,SR04,KR0);
404 RIP5(A,B,C,D,E,WR05,SR05,KR0);
405 RIP5(E,A,B,C,D,WR06,SR06,KR0);
406 RIP5(D,E,A,B,C,WR07,SR07,KR0);
407 RIP5(C,D,E,A,B,WR08,SR08,KR0);
408 RIP5(B,C,D,E,A,WR09,SR09,KR0);
409 RIP5(A,B,C,D,E,WR10,SR10,KR0);
410 RIP5(E,A,B,C,D,WR11,SR11,KR0);
411 RIP5(D,E,A,B,C,WR12,SR12,KR0);
412 RIP5(C,D,E,A,B,WR13,SR13,KR0);
413 RIP5(B,C,D,E,A,WR14,SR14,KR0);
414 RIP5(A,B,C,D,E,WR15,SR15,KR0);
415
416 RIP4(E,A,B,C,D,WR16,SR16,KR1);
417 RIP4(D,E,A,B,C,WR17,SR17,KR1);
418 RIP4(C,D,E,A,B,WR18,SR18,KR1);
419 RIP4(B,C,D,E,A,WR19,SR19,KR1);
420 RIP4(A,B,C,D,E,WR20,SR20,KR1);
421 RIP4(E,A,B,C,D,WR21,SR21,KR1);
422 RIP4(D,E,A,B,C,WR22,SR22,KR1);
423 RIP4(C,D,E,A,B,WR23,SR23,KR1);
424 RIP4(B,C,D,E,A,WR24,SR24,KR1);
425 RIP4(A,B,C,D,E,WR25,SR25,KR1);
426 RIP4(E,A,B,C,D,WR26,SR26,KR1);
427 RIP4(D,E,A,B,C,WR27,SR27,KR1);
428 RIP4(C,D,E,A,B,WR28,SR28,KR1);
429 RIP4(B,C,D,E,A,WR29,SR29,KR1);
430 RIP4(A,B,C,D,E,WR30,SR30,KR1);
431 RIP4(E,A,B,C,D,WR31,SR31,KR1);
432
433 RIP3(D,E,A,B,C,WR32,SR32,KR2);
434 RIP3(C,D,E,A,B,WR33,SR33,KR2);
435 RIP3(B,C,D,E,A,WR34,SR34,KR2);
436 RIP3(A,B,C,D,E,WR35,SR35,KR2);
437 RIP3(E,A,B,C,D,WR36,SR36,KR2);
438 RIP3(D,E,A,B,C,WR37,SR37,KR2);
439 RIP3(C,D,E,A,B,WR38,SR38,KR2);
440 RIP3(B,C,D,E,A,WR39,SR39,KR2);
441 RIP3(A,B,C,D,E,WR40,SR40,KR2);
442 RIP3(E,A,B,C,D,WR41,SR41,KR2);
443 RIP3(D,E,A,B,C,WR42,SR42,KR2);
444 RIP3(C,D,E,A,B,WR43,SR43,KR2);
445 RIP3(B,C,D,E,A,WR44,SR44,KR2);
446 RIP3(A,B,C,D,E,WR45,SR45,KR2);
447 RIP3(E,A,B,C,D,WR46,SR46,KR2);
448 RIP3(D,E,A,B,C,WR47,SR47,KR2);
449
450 RIP2(C,D,E,A,B,WR48,SR48,KR3);
451 RIP2(B,C,D,E,A,WR49,SR49,KR3);
452 RIP2(A,B,C,D,E,WR50,SR50,KR3);
453 RIP2(E,A,B,C,D,WR51,SR51,KR3);
454 RIP2(D,E,A,B,C,WR52,SR52,KR3);
455 RIP2(C,D,E,A,B,WR53,SR53,KR3);
456 RIP2(B,C,D,E,A,WR54,SR54,KR3);
457 RIP2(A,B,C,D,E,WR55,SR55,KR3);
458 RIP2(E,A,B,C,D,WR56,SR56,KR3);
459 RIP2(D,E,A,B,C,WR57,SR57,KR3);
460 RIP2(C,D,E,A,B,WR58,SR58,KR3);
461 RIP2(B,C,D,E,A,WR59,SR59,KR3);
462 RIP2(A,B,C,D,E,WR60,SR60,KR3);
463 RIP2(E,A,B,C,D,WR61,SR61,KR3);
464 RIP2(D,E,A,B,C,WR62,SR62,KR3);
465 RIP2(C,D,E,A,B,WR63,SR63,KR3);
466
467 RIP1(B,C,D,E,A,WR64,SR64);
468 RIP1(A,B,C,D,E,WR65,SR65);
469 RIP1(E,A,B,C,D,WR66,SR66);
470 RIP1(D,E,A,B,C,WR67,SR67);
471 RIP1(C,D,E,A,B,WR68,SR68);
472 RIP1(B,C,D,E,A,WR69,SR69);
473 RIP1(A,B,C,D,E,WR70,SR70);
474 RIP1(E,A,B,C,D,WR71,SR71);
475 RIP1(D,E,A,B,C,WR72,SR72);
476 RIP1(C,D,E,A,B,WR73,SR73);
477 RIP1(B,C,D,E,A,WR74,SR74);
478 RIP1(A,B,C,D,E,WR75,SR75);
479 RIP1(E,A,B,C,D,WR76,SR76);
480 RIP1(D,E,A,B,C,WR77,SR77);
481 RIP1(C,D,E,A,B,WR78,SR78);
482 RIP1(B,C,D,E,A,WR79,SR79);
483
484 D =ctx->B+c+D;
485 ctx->B=ctx->C+d+E;
486 ctx->C=ctx->D+e+A;
487 ctx->D=ctx->E+a+B;
488 ctx->E=ctx->A+b+C;
489 ctx->A=D;
490
491 }
492 }
493#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h
deleted file mode 100644
index f537b88867..0000000000
--- a/src/lib/libcrypto/ripemd/rmd_locl.h
+++ /dev/null
@@ -1,160 +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/opensslconf.h>
62#include <openssl/ripemd.h>
63
64#ifndef RIPEMD160_LONG_LOG2
65#define RIPEMD160_LONG_LOG2 2 /* default to 32 bits */
66#endif
67
68/*
69 * DO EXAMINE COMMENTS IN crypto/md5/md5_locl.h & crypto/md5/md5_dgst.c
70 * FOR EXPLANATIONS ON FOLLOWING "CODE."
71 * <appro@fy.chalmers.se>
72 */
73#ifdef RMD160_ASM
74# if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
75# define ripemd160_block_host_order ripemd160_block_asm_host_order
76# endif
77#endif
78
79void ripemd160_block_host_order (RIPEMD160_CTX *c, const void *p,int num);
80void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,int num);
81
82#if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
83#define ripemd160_block_data_order ripemd160_block_host_order
84#endif
85
86#define DATA_ORDER_IS_LITTLE_ENDIAN
87
88#define HASH_LONG RIPEMD160_LONG
89#define HASH_LONG_LOG2 RIPEMD160_LONG_LOG2
90#define HASH_CTX RIPEMD160_CTX
91#define HASH_CBLOCK RIPEMD160_CBLOCK
92#define HASH_LBLOCK RIPEMD160_LBLOCK
93#define HASH_UPDATE RIPEMD160_Update
94#define HASH_TRANSFORM RIPEMD160_Transform
95#define HASH_FINAL RIPEMD160_Final
96#define HASH_BLOCK_HOST_ORDER ripemd160_block_host_order
97#define HASH_MAKE_STRING(c,s) do { \
98 unsigned long ll; \
99 ll=(c)->A; HOST_l2c(ll,(s)); \
100 ll=(c)->B; HOST_l2c(ll,(s)); \
101 ll=(c)->C; HOST_l2c(ll,(s)); \
102 ll=(c)->D; HOST_l2c(ll,(s)); \
103 ll=(c)->E; HOST_l2c(ll,(s)); \
104 } while (0)
105#if !defined(L_ENDIAN) || defined(ripemd160_block_data_order)
106#define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order
107#endif
108
109#include "md32_common.h"
110
111#if 0
112#define F1(x,y,z) ((x)^(y)^(z))
113#define F2(x,y,z) (((x)&(y))|((~x)&z))
114#define F3(x,y,z) (((x)|(~y))^(z))
115#define F4(x,y,z) (((x)&(z))|((y)&(~(z))))
116#define F5(x,y,z) ((x)^((y)|(~(z))))
117#else
118/*
119 * Transformed F2 and F4 are courtesy of Wei Dai <weidai@eskimo.com>
120 */
121#define F1(x,y,z) ((x) ^ (y) ^ (z))
122#define F2(x,y,z) ((((y) ^ (z)) & (x)) ^ (z))
123#define F3(x,y,z) (((~(y)) | (x)) ^ (z))
124#define F4(x,y,z) ((((x) ^ (y)) & (z)) ^ (y))
125#define F5(x,y,z) (((~(z)) | (y)) ^ (x))
126#endif
127
128#define RIPEMD160_A 0x67452301L
129#define RIPEMD160_B 0xEFCDAB89L
130#define RIPEMD160_C 0x98BADCFEL
131#define RIPEMD160_D 0x10325476L
132#define RIPEMD160_E 0xC3D2E1F0L
133
134#include "rmdconst.h"
135
136#define RIP1(a,b,c,d,e,w,s) { \
137 a+=F1(b,c,d)+X(w); \
138 a=ROTATE(a,s)+e; \
139 c=ROTATE(c,10); }
140
141#define RIP2(a,b,c,d,e,w,s,K) { \
142 a+=F2(b,c,d)+X(w)+K; \
143 a=ROTATE(a,s)+e; \
144 c=ROTATE(c,10); }
145
146#define RIP3(a,b,c,d,e,w,s,K) { \
147 a+=F3(b,c,d)+X(w)+K; \
148 a=ROTATE(a,s)+e; \
149 c=ROTATE(c,10); }
150
151#define RIP4(a,b,c,d,e,w,s,K) { \
152 a+=F4(b,c,d)+X(w)+K; \
153 a=ROTATE(a,s)+e; \
154 c=ROTATE(c,10); }
155
156#define RIP5(a,b,c,d,e,w,s,K) { \
157 a+=F5(b,c,d)+X(w)+K; \
158 a=ROTATE(a,s)+e; \
159 c=ROTATE(c,10); }
160
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c
deleted file mode 100644
index efdf2dd6ef..0000000000
--- a/src/lib/libcrypto/ripemd/rmd_one.c
+++ /dev/null
@@ -1,76 +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 <string.h>
61#include <openssl/ripemd.h>
62
63unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
64 unsigned char *md)
65 {
66 RIPEMD160_CTX c;
67 static unsigned char m[RIPEMD160_DIGEST_LENGTH];
68
69 if (md == NULL) md=m;
70 RIPEMD160_Init(&c);
71 RIPEMD160_Update(&c,d,n);
72 RIPEMD160_Final(md,&c);
73 memset(&c,0,sizeof(c)); /* security consideration */
74 return(md);
75 }
76
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 f9f9b5cfe9..0000000000
--- a/src/lib/libcrypto/rsa/rsa.h
+++ /dev/null
@@ -1,338 +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/* New sign and verify functions: some libraries don't allow arbitrary data
95 * to be signed/verified: this allows them to be used. Note: for this to work
96 * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used
97 * RSA_sign(), RSA_verify() should be used instead. Note: for backwards
98 * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER
99 * option is set in 'flags'.
100 */
101 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
102 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
103 int (*rsa_verify)(int dtype, unsigned char *m, unsigned int m_len,
104 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
105
106 } RSA_METHOD;
107
108struct rsa_st
109 {
110 /* The first parameter is used to pickup errors where
111 * this is passed instead of aEVP_PKEY, it is set to 0 */
112 int pad;
113 int version;
114 RSA_METHOD *meth;
115 BIGNUM *n;
116 BIGNUM *e;
117 BIGNUM *d;
118 BIGNUM *p;
119 BIGNUM *q;
120 BIGNUM *dmp1;
121 BIGNUM *dmq1;
122 BIGNUM *iqmp;
123 /* be careful using this if the RSA structure is shared */
124 CRYPTO_EX_DATA ex_data;
125 int references;
126 int flags;
127
128 /* Used to cache montgomery values */
129 BN_MONT_CTX *_method_mod_n;
130 BN_MONT_CTX *_method_mod_p;
131 BN_MONT_CTX *_method_mod_q;
132
133 /* all BIGNUM values are actually in the following data, if it is not
134 * NULL */
135 char *bignum_data;
136 BN_BLINDING *blinding;
137 };
138
139#define RSA_3 0x3L
140#define RSA_F4 0x10001L
141
142#define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */
143
144#define RSA_FLAG_CACHE_PUBLIC 0x02
145#define RSA_FLAG_CACHE_PRIVATE 0x04
146#define RSA_FLAG_BLINDING 0x08
147#define RSA_FLAG_THREAD_SAFE 0x10
148/* This flag means the private key operations will be handled by rsa_mod_exp
149 * and that they do not depend on the private key components being present:
150 * for example a key stored in external hardware. Without this flag bn_mod_exp
151 * gets called when private key components are absent.
152 */
153#define RSA_FLAG_EXT_PKEY 0x20
154
155/* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions.
156 */
157#define RSA_FLAG_SIGN_VER 0x40
158
159#define RSA_PKCS1_PADDING 1
160#define RSA_SSLV23_PADDING 2
161#define RSA_NO_PADDING 3
162#define RSA_PKCS1_OAEP_PADDING 4
163
164#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg)
165#define RSA_get_app_data(s) RSA_get_ex_data(s,0)
166
167RSA * RSA_new(void);
168RSA * RSA_new_method(RSA_METHOD *method);
169int RSA_size(RSA *);
170RSA * RSA_generate_key(int bits, unsigned long e,void
171 (*callback)(int,int,void *),void *cb_arg);
172int RSA_check_key(RSA *);
173 /* next 4 return -1 on error */
174int RSA_public_encrypt(int flen, unsigned char *from,
175 unsigned char *to, RSA *rsa,int padding);
176int RSA_private_encrypt(int flen, unsigned char *from,
177 unsigned char *to, RSA *rsa,int padding);
178int RSA_public_decrypt(int flen, unsigned char *from,
179 unsigned char *to, RSA *rsa,int padding);
180int RSA_private_decrypt(int flen, unsigned char *from,
181 unsigned char *to, RSA *rsa,int padding);
182void RSA_free (RSA *r);
183
184int RSA_flags(RSA *r);
185
186void RSA_set_default_method(RSA_METHOD *meth);
187RSA_METHOD *RSA_get_default_method(void);
188RSA_METHOD *RSA_get_method(RSA *rsa);
189RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
190
191/* This function needs the memory locking malloc callbacks to be installed */
192int RSA_memory_lock(RSA *r);
193
194/* If you have RSAref compiled in. */
195RSA_METHOD *RSA_PKCS1_RSAref(void);
196
197/* these are the actual SSLeay RSA functions */
198RSA_METHOD *RSA_PKCS1_SSLeay(void);
199
200RSA_METHOD *RSA_null_method(void);
201
202void ERR_load_RSA_strings(void );
203
204RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
205int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
206RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
207int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
208#ifndef NO_FP_API
209int RSA_print_fp(FILE *fp, RSA *r,int offset);
210#endif
211
212#ifdef HEADER_BIO_H
213int RSA_print(BIO *bp, RSA *r,int offset);
214#endif
215
216int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
217RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
218/* Naughty internal function required elsewhere, to handle a MS structure
219 * that is the same as the netscape one :-) */
220RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length, int (*cb)());
221
222/* The following 2 functions sign and verify a X509_SIG ASN1 object
223 * inside PKCS#1 padded RSA encryption */
224int RSA_sign(int type, unsigned char *m, unsigned int m_len,
225 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
226int RSA_verify(int type, unsigned char *m, unsigned int m_len,
227 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
228
229/* The following 2 function sign and verify a ASN1_OCTET_STRING
230 * object inside PKCS#1 padded RSA encryption */
231int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
232 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
233int RSA_verify_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
234 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
235
236int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
237void RSA_blinding_off(RSA *rsa);
238
239int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,
240 unsigned char *f,int fl);
241int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen,
242 unsigned char *f,int fl,int rsa_len);
243int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen,
244 unsigned char *f,int fl);
245int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen,
246 unsigned char *f,int fl,int rsa_len);
247int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen,
248 unsigned char *f,int fl,unsigned char *p,
249 int pl);
250int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen,
251 unsigned char *f,int fl,int rsa_len,
252 unsigned char *p,int pl);
253int RSA_padding_add_SSLv23(unsigned char *to,int tlen,
254 unsigned char *f,int fl);
255int RSA_padding_check_SSLv23(unsigned char *to,int tlen,
256 unsigned char *f,int fl,int rsa_len);
257int RSA_padding_add_none(unsigned char *to,int tlen,
258 unsigned char *f,int fl);
259int RSA_padding_check_none(unsigned char *to,int tlen,
260 unsigned char *f,int fl,int rsa_len);
261
262int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
263 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
264int RSA_set_ex_data(RSA *r,int idx,void *arg);
265void *RSA_get_ex_data(RSA *r, int idx);
266
267/* BEGIN ERROR CODES */
268/* The following lines are auto generated by the script mkerr.pl. Any changes
269 * made after this point may be overwritten when the script is next run.
270 */
271
272/* Error codes for the RSA functions. */
273
274/* Function codes. */
275#define RSA_F_MEMORY_LOCK 100
276#define RSA_F_RSA_CHECK_KEY 123
277#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101
278#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102
279#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103
280#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104
281#define RSA_F_RSA_GENERATE_KEY 105
282#define RSA_F_RSA_NEW_METHOD 106
283#define RSA_F_RSA_NULL 124
284#define RSA_F_RSA_PADDING_ADD_NONE 107
285#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
286#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
287#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109
288#define RSA_F_RSA_PADDING_ADD_SSLV23 110
289#define RSA_F_RSA_PADDING_CHECK_NONE 111
290#define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122
291#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112
292#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113
293#define RSA_F_RSA_PADDING_CHECK_SSLV23 114
294#define RSA_F_RSA_PRINT 115
295#define RSA_F_RSA_PRINT_FP 116
296#define RSA_F_RSA_SIGN 117
297#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
298#define RSA_F_RSA_VERIFY 119
299#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120
300
301/* Reason codes. */
302#define RSA_R_ALGORITHM_MISMATCH 100
303#define RSA_R_BAD_E_VALUE 101
304#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
305#define RSA_R_BAD_PAD_BYTE_COUNT 103
306#define RSA_R_BAD_SIGNATURE 104
307#define RSA_R_BLOCK_TYPE_IS_NOT_01 106
308#define RSA_R_BLOCK_TYPE_IS_NOT_02 107
309#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
310#define RSA_R_DATA_TOO_LARGE 109
311#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
312#define RSA_R_DATA_TOO_SMALL 111
313#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
314#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
315#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
316#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
317#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
318#define RSA_R_INVALID_MESSAGE_LENGTH 131
319#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
320#define RSA_R_KEY_SIZE_TOO_SMALL 120
321#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
322#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
323#define RSA_R_OAEP_DECODING_ERROR 121
324#define RSA_R_PADDING_CHECK_FAILED 114
325#define RSA_R_P_NOT_PRIME 128
326#define RSA_R_Q_NOT_PRIME 129
327#define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130
328#define RSA_R_SSLV3_ROLLBACK_ATTACK 115
329#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
330#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
331#define RSA_R_UNKNOWN_PADDING_TYPE 118
332#define RSA_R_WRONG_SIGNATURE_LENGTH 119
333
334#ifdef __cplusplus
335}
336#endif
337#endif
338
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 b7d2460754..0000000000
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ /dev/null
@@ -1,491 +0,0 @@
1/* crypto/rsa/rsa_eay.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot 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
65#ifndef RSA_NULL
66
67static int RSA_eay_public_encrypt(int flen, unsigned char *from,
68 unsigned char *to, RSA *rsa,int padding);
69static int RSA_eay_private_encrypt(int flen, unsigned char *from,
70 unsigned char *to, RSA *rsa,int padding);
71static int RSA_eay_public_decrypt(int flen, unsigned char *from,
72 unsigned char *to, RSA *rsa,int padding);
73static int RSA_eay_private_decrypt(int flen, unsigned char *from,
74 unsigned char *to, RSA *rsa,int padding);
75static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa);
76static int RSA_eay_init(RSA *rsa);
77static int RSA_eay_finish(RSA *rsa);
78static RSA_METHOD rsa_pkcs1_eay_meth={
79 "Eric Young's PKCS#1 RSA",
80 RSA_eay_public_encrypt,
81 RSA_eay_public_decrypt,
82 RSA_eay_private_encrypt,
83 RSA_eay_private_decrypt,
84 RSA_eay_mod_exp,
85 BN_mod_exp_mont,
86 RSA_eay_init,
87 RSA_eay_finish,
88 0,
89 NULL,
90 };
91
92RSA_METHOD *RSA_PKCS1_SSLeay(void)
93 {
94 return(&rsa_pkcs1_eay_meth);
95 }
96
97static int RSA_eay_public_encrypt(int flen, unsigned char *from,
98 unsigned char *to, RSA *rsa, int padding)
99 {
100 BIGNUM f,ret;
101 int i,j,k,num=0,r= -1;
102 unsigned char *buf=NULL;
103 BN_CTX *ctx=NULL;
104
105 BN_init(&f);
106 BN_init(&ret);
107 if ((ctx=BN_CTX_new()) == NULL) goto err;
108 num=BN_num_bytes(rsa->n);
109 if ((buf=(unsigned char *)Malloc(num)) == NULL)
110 {
111 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
112 goto err;
113 }
114
115 switch (padding)
116 {
117 case RSA_PKCS1_PADDING:
118 i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);
119 break;
120#ifndef NO_SHA
121 case RSA_PKCS1_OAEP_PADDING:
122 i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);
123 break;
124#endif
125 case RSA_SSLV23_PADDING:
126 i=RSA_padding_add_SSLv23(buf,num,from,flen);
127 break;
128 case RSA_NO_PADDING:
129 i=RSA_padding_add_none(buf,num,from,flen);
130 break;
131 default:
132 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
133 goto err;
134 }
135 if (i <= 0) goto err;
136
137 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
138
139 if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
140 {
141 if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)
142 if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))
143 goto err;
144 }
145
146 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
147 rsa->_method_mod_n)) goto err;
148
149 /* put in leading 0 bytes if the number is less than the
150 * length of the modulus */
151 j=BN_num_bytes(&ret);
152 i=BN_bn2bin(&ret,&(to[num-j]));
153 for (k=0; k<(num-i); k++)
154 to[k]=0;
155
156 r=num;
157err:
158 if (ctx != NULL) BN_CTX_free(ctx);
159 BN_clear_free(&f);
160 BN_clear_free(&ret);
161 if (buf != NULL)
162 {
163 memset(buf,0,num);
164 Free(buf);
165 }
166 return(r);
167 }
168
169static int RSA_eay_private_encrypt(int flen, unsigned char *from,
170 unsigned char *to, RSA *rsa, int padding)
171 {
172 BIGNUM f,ret;
173 int i,j,k,num=0,r= -1;
174 unsigned char *buf=NULL;
175 BN_CTX *ctx=NULL;
176
177 BN_init(&f);
178 BN_init(&ret);
179
180 if ((ctx=BN_CTX_new()) == NULL) goto err;
181 num=BN_num_bytes(rsa->n);
182 if ((buf=(unsigned char *)Malloc(num)) == NULL)
183 {
184 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
185 goto err;
186 }
187
188 switch (padding)
189 {
190 case RSA_PKCS1_PADDING:
191 i=RSA_padding_add_PKCS1_type_1(buf,num,from,flen);
192 break;
193 case RSA_NO_PADDING:
194 i=RSA_padding_add_none(buf,num,from,flen);
195 break;
196 case RSA_SSLV23_PADDING:
197 default:
198 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
199 goto err;
200 }
201 if (i <= 0) goto err;
202
203 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
204
205 if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))
206 RSA_blinding_on(rsa,ctx);
207 if (rsa->flags & RSA_FLAG_BLINDING)
208 if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;
209
210 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
211 ((rsa->p != NULL) &&
212 (rsa->q != NULL) &&
213 (rsa->dmp1 != NULL) &&
214 (rsa->dmq1 != NULL) &&
215 (rsa->iqmp != NULL)) )
216 { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }
217 else
218 {
219 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err;
220 }
221
222 if (rsa->flags & RSA_FLAG_BLINDING)
223 if (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err;
224
225 /* put in leading 0 bytes if the number is less than the
226 * length of the modulus */
227 j=BN_num_bytes(&ret);
228 i=BN_bn2bin(&ret,&(to[num-j]));
229 for (k=0; k<(num-i); k++)
230 to[k]=0;
231
232 r=num;
233err:
234 if (ctx != NULL) BN_CTX_free(ctx);
235 BN_clear_free(&ret);
236 BN_clear_free(&f);
237 if (buf != NULL)
238 {
239 memset(buf,0,num);
240 Free(buf);
241 }
242 return(r);
243 }
244
245static int RSA_eay_private_decrypt(int flen, unsigned char *from,
246 unsigned char *to, RSA *rsa, int padding)
247 {
248 BIGNUM f,ret;
249 int j,num=0,r= -1;
250 unsigned char *p;
251 unsigned char *buf=NULL;
252 BN_CTX *ctx=NULL;
253
254 BN_init(&f);
255 BN_init(&ret);
256 ctx=BN_CTX_new();
257 if (ctx == NULL) goto err;
258
259 num=BN_num_bytes(rsa->n);
260
261 if ((buf=(unsigned char *)Malloc(num)) == NULL)
262 {
263 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);
264 goto err;
265 }
266
267 /* This check was for equality but PGP does evil things
268 * and chops off the top '0' bytes */
269 if (flen > num)
270 {
271 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
272 goto err;
273 }
274
275 /* make data into a big number */
276 if (BN_bin2bn(from,(int)flen,&f) == NULL) goto err;
277
278 if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))
279 RSA_blinding_on(rsa,ctx);
280 if (rsa->flags & RSA_FLAG_BLINDING)
281 if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;
282
283 /* do the decrypt */
284 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
285 ((rsa->p != NULL) &&
286 (rsa->q != NULL) &&
287 (rsa->dmp1 != NULL) &&
288 (rsa->dmq1 != NULL) &&
289 (rsa->iqmp != NULL)) )
290 { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }
291 else
292 {
293 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL))
294 goto err;
295 }
296
297 if (rsa->flags & RSA_FLAG_BLINDING)
298 if (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err;
299
300 p=buf;
301 j=BN_bn2bin(&ret,p); /* j is only used with no-padding mode */
302
303 switch (padding)
304 {
305 case RSA_PKCS1_PADDING:
306 r=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);
307 break;
308#ifndef NO_SHA
309 case RSA_PKCS1_OAEP_PADDING:
310 r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);
311 break;
312#endif
313 case RSA_SSLV23_PADDING:
314 r=RSA_padding_check_SSLv23(to,num,buf,j,num);
315 break;
316 case RSA_NO_PADDING:
317 r=RSA_padding_check_none(to,num,buf,j,num);
318 break;
319 default:
320 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
321 goto err;
322 }
323 if (r < 0)
324 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
325
326err:
327 if (ctx != NULL) BN_CTX_free(ctx);
328 BN_clear_free(&f);
329 BN_clear_free(&ret);
330 if (buf != NULL)
331 {
332 memset(buf,0,num);
333 Free(buf);
334 }
335 return(r);
336 }
337
338static int RSA_eay_public_decrypt(int flen, unsigned char *from,
339 unsigned char *to, RSA *rsa, int padding)
340 {
341 BIGNUM f,ret;
342 int i,num=0,r= -1;
343 unsigned char *p;
344 unsigned char *buf=NULL;
345 BN_CTX *ctx=NULL;
346
347 BN_init(&f);
348 BN_init(&ret);
349 ctx=BN_CTX_new();
350 if (ctx == NULL) goto err;
351
352 num=BN_num_bytes(rsa->n);
353 buf=(unsigned char *)Malloc(num);
354 if (buf == NULL)
355 {
356 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
357 goto err;
358 }
359
360 /* This check was for equality but PGP does evil things
361 * and chops off the top '0' bytes */
362 if (flen > num)
363 {
364 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
365 goto err;
366 }
367
368 if (BN_bin2bn(from,flen,&f) == NULL) goto err;
369 /* do the decrypt */
370 if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
371 {
372 if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)
373 if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))
374 goto err;
375 }
376
377 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
378 rsa->_method_mod_n)) goto err;
379
380 p=buf;
381 i=BN_bn2bin(&ret,p);
382
383 switch (padding)
384 {
385 case RSA_PKCS1_PADDING:
386 r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
387 break;
388 case RSA_NO_PADDING:
389 r=RSA_padding_check_none(to,num,buf,i,num);
390 break;
391 default:
392 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
393 goto err;
394 }
395 if (r < 0)
396 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
397
398err:
399 if (ctx != NULL) BN_CTX_free(ctx);
400 BN_clear_free(&f);
401 BN_clear_free(&ret);
402 if (buf != NULL)
403 {
404 memset(buf,0,num);
405 Free(buf);
406 }
407 return(r);
408 }
409
410static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
411 {
412 BIGNUM r1,m1;
413 int ret=0;
414 BN_CTX *ctx;
415
416 if ((ctx=BN_CTX_new()) == NULL) goto err;
417 BN_init(&m1);
418 BN_init(&r1);
419
420 if (rsa->flags & RSA_FLAG_CACHE_PRIVATE)
421 {
422 if (rsa->_method_mod_p == NULL)
423 {
424 if ((rsa->_method_mod_p=BN_MONT_CTX_new()) != NULL)
425 if (!BN_MONT_CTX_set(rsa->_method_mod_p,rsa->p,
426 ctx))
427 goto err;
428 }
429 if (rsa->_method_mod_q == NULL)
430 {
431 if ((rsa->_method_mod_q=BN_MONT_CTX_new()) != NULL)
432 if (!BN_MONT_CTX_set(rsa->_method_mod_q,rsa->q,
433 ctx))
434 goto err;
435 }
436 }
437
438 if (!BN_mod(&r1,I,rsa->q,ctx)) goto err;
439 if (!rsa->meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx,
440 rsa->_method_mod_q)) goto err;
441
442 if (!BN_mod(&r1,I,rsa->p,ctx)) goto err;
443 if (!rsa->meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx,
444 rsa->_method_mod_p)) goto err;
445
446 if (!BN_sub(r0,r0,&m1)) goto err;
447 /* This will help stop the size of r0 increasing, which does
448 * affect the multiply if it optimised for a power of 2 size */
449 if (r0->neg)
450 if (!BN_add(r0,r0,rsa->p)) goto err;
451
452 if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;
453 if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;
454 /* If p < q it is occasionally possible for the correction of
455 * adding 'p' if r0 is negative above to leave the result still
456 * negative. This can break the private key operations: the following
457 * second correction should *always* correct this rare occurrence.
458 * This will *never* happen with OpenSSL generated keys because
459 * they ensure p > q [steve]
460 */
461 if (r0->neg)
462 if (!BN_add(r0,r0,rsa->p)) goto err;
463 if (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;
464 if (!BN_add(r0,&r1,&m1)) goto err;
465
466 ret=1;
467err:
468 BN_clear_free(&m1);
469 BN_clear_free(&r1);
470 BN_CTX_free(ctx);
471 return(ret);
472 }
473
474static int RSA_eay_init(RSA *rsa)
475 {
476 rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
477 return(1);
478 }
479
480static int RSA_eay_finish(RSA *rsa)
481 {
482 if (rsa->_method_mod_n != NULL)
483 BN_MONT_CTX_free(rsa->_method_mod_n);
484 if (rsa->_method_mod_p != NULL)
485 BN_MONT_CTX_free(rsa->_method_mod_p);
486 if (rsa->_method_mod_q != NULL)
487 BN_MONT_CTX_free(rsa->_method_mod_q);
488 return(1);
489 }
490
491#endif
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c
deleted file mode 100644
index 1cde7c0da4..0000000000
--- a/src/lib/libcrypto/rsa/rsa_err.c
+++ /dev/null
@@ -1,148 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/rsa.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA RSA_str_functs[]=
68 {
69{ERR_PACK(0,RSA_F_MEMORY_LOCK,0), "MEMORY_LOCK"},
70{ERR_PACK(0,RSA_F_RSA_CHECK_KEY,0), "RSA_check_key"},
71{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"},
72{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"},
73{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"},
74{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"},
75{ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"},
76{ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"},
77{ERR_PACK(0,RSA_F_RSA_NULL,0), "RSA_NULL"},
78{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"},
79{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"},
80{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"},
81{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"},
82{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"},
83{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"},
84{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,0), "RSA_padding_check_PKCS1_OAEP"},
85{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"},
86{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"},
87{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"},
88{ERR_PACK(0,RSA_F_RSA_PRINT,0), "RSA_print"},
89{ERR_PACK(0,RSA_F_RSA_PRINT_FP,0), "RSA_print_fp"},
90{ERR_PACK(0,RSA_F_RSA_SIGN,0), "RSA_sign"},
91{ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"},
92{ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"},
93{ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"},
94{0,NULL}
95 };
96
97static ERR_STRING_DATA RSA_str_reasons[]=
98 {
99{RSA_R_ALGORITHM_MISMATCH ,"algorithm mismatch"},
100{RSA_R_BAD_E_VALUE ,"bad e value"},
101{RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"},
102{RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"},
103{RSA_R_BAD_SIGNATURE ,"bad signature"},
104{RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"},
105{RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"},
106{RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"},
107{RSA_R_DATA_TOO_LARGE ,"data too large"},
108{RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
109{RSA_R_DATA_TOO_SMALL ,"data too small"},
110{RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"},
111{RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"},
112{RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"},
113{RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"},
114{RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"},
115{RSA_R_INVALID_MESSAGE_LENGTH ,"invalid message length"},
116{RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"},
117{RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"},
118{RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"},
119{RSA_R_N_DOES_NOT_EQUAL_P_Q ,"n does not equal p q"},
120{RSA_R_OAEP_DECODING_ERROR ,"oaep decoding error"},
121{RSA_R_PADDING_CHECK_FAILED ,"padding check failed"},
122{RSA_R_P_NOT_PRIME ,"p not prime"},
123{RSA_R_Q_NOT_PRIME ,"q not prime"},
124{RSA_R_RSA_OPERATIONS_NOT_SUPPORTED ,"rsa operations not supported"},
125{RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"},
126{RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
127{RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
128{RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"},
129{RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
130{0,NULL}
131 };
132
133#endif
134
135void ERR_load_RSA_strings(void)
136 {
137 static int init=1;
138
139 if (init)
140 {
141 init=0;
142#ifndef NO_ERR
143 ERR_load_strings(ERR_LIB_RSA,RSA_str_functs);
144 ERR_load_strings(ERR_LIB_RSA,RSA_str_reasons);
145#endif
146
147 }
148 }
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
deleted file mode 100644
index 95e636d3f0..0000000000
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ /dev/null
@@ -1,197 +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 BN_CTX_start(ctx);
78 r0 = BN_CTX_get(ctx);
79 r1 = BN_CTX_get(ctx);
80 r2 = BN_CTX_get(ctx);
81 r3 = BN_CTX_get(ctx);
82 if (r3 == NULL) goto err;
83
84 bitsp=(bits+1)/2;
85 bitsq=bits-bitsp;
86 rsa=RSA_new();
87 if (rsa == NULL) goto err;
88
89 /* set e */
90 rsa->e=BN_new();
91 if (rsa->e == NULL) goto err;
92
93#if 1
94 /* The problem is when building with 8, 16, or 32 BN_ULONG,
95 * unsigned long can be larger */
96 for (i=0; i<sizeof(unsigned long)*8; i++)
97 {
98 if (e_value & (1<<i))
99 BN_set_bit(rsa->e,i);
100 }
101#else
102 if (!BN_set_word(rsa->e,e_value)) goto err;
103#endif
104
105 /* generate p and q */
106 for (;;)
107 {
108 rsa->p=BN_generate_prime(NULL,bitsp,0,NULL,NULL,callback,cb_arg);
109 if (rsa->p == NULL) goto err;
110 if (!BN_sub(r2,rsa->p,BN_value_one())) goto err;
111 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
112 if (BN_is_one(r1)) break;
113 if (callback != NULL) callback(2,n++,cb_arg);
114 BN_free(rsa->p);
115 }
116 if (callback != NULL) callback(3,0,cb_arg);
117 for (;;)
118 {
119 rsa->q=BN_generate_prime(NULL,bitsq,0,NULL,NULL,callback,cb_arg);
120 if (rsa->q == NULL) goto err;
121 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err;
122 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
123 if (BN_is_one(r1) && (BN_cmp(rsa->p,rsa->q) != 0))
124 break;
125 if (callback != NULL) callback(2,n++,cb_arg);
126 BN_free(rsa->q);
127 }
128 if (callback != NULL) callback(3,1,cb_arg);
129 if (BN_cmp(rsa->p,rsa->q) < 0)
130 {
131 tmp=rsa->p;
132 rsa->p=rsa->q;
133 rsa->q=tmp;
134 }
135
136 /* calculate n */
137 rsa->n=BN_new();
138 if (rsa->n == NULL) goto err;
139 if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err;
140
141 /* calculate d */
142 if (!BN_sub(r1,rsa->p,BN_value_one())) goto err; /* p-1 */
143 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; /* q-1 */
144 if (!BN_mul(r0,r1,r2,ctx)) goto err; /* (p-1)(q-1) */
145
146/* should not be needed, since gcd(p-1,e) == 1 and gcd(q-1,e) == 1 */
147/* for (;;)
148 {
149 if (!BN_gcd(r3,r0,rsa->e,ctx)) goto err;
150 if (BN_is_one(r3)) break;
151
152 if (1)
153 {
154 if (!BN_add_word(rsa->e,2L)) goto err;
155 continue;
156 }
157 RSAerr(RSA_F_RSA_GENERATE_KEY,RSA_R_BAD_E_VALUE);
158 goto err;
159 }
160*/
161 rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2); /* d */
162 if (rsa->d == NULL) goto err;
163
164 /* calculate d mod (p-1) */
165 rsa->dmp1=BN_new();
166 if (rsa->dmp1 == NULL) goto err;
167 if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx)) goto err;
168
169 /* calculate d mod (q-1) */
170 rsa->dmq1=BN_new();
171 if (rsa->dmq1 == NULL) goto err;
172 if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx)) goto err;
173
174 /* calculate inverse of q mod p */
175 rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);
176 if (rsa->iqmp == NULL) goto err;
177
178 ok=1;
179err:
180 if (ok == -1)
181 {
182 RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
183 ok=0;
184 }
185 BN_CTX_end(ctx);
186 BN_CTX_free(ctx);
187 BN_CTX_free(ctx2);
188
189 if (!ok)
190 {
191 if (rsa != NULL) RSA_free(rsa);
192 return(NULL);
193 }
194 else
195 return(rsa);
196 }
197
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
deleted file mode 100644
index 074a4f5074..0000000000
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ /dev/null
@@ -1,333 +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_OF(CRYPTO_EX_DATA_FUNCS) *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 RSA_NULL
109 default_RSA_meth=RSA_null_method();
110#else
111#ifdef RSAref
112 default_RSA_meth=RSA_PKCS1_RSAref();
113#else
114 default_RSA_meth=RSA_PKCS1_SSLeay();
115#endif
116#endif
117 }
118 ret=(RSA *)Malloc(sizeof(RSA));
119 if (ret == NULL)
120 {
121 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
122 return(NULL);
123 }
124
125 if (meth == NULL)
126 ret->meth=default_RSA_meth;
127 else
128 ret->meth=meth;
129
130 ret->pad=0;
131 ret->version=0;
132 ret->n=NULL;
133 ret->e=NULL;
134 ret->d=NULL;
135 ret->p=NULL;
136 ret->q=NULL;
137 ret->dmp1=NULL;
138 ret->dmq1=NULL;
139 ret->iqmp=NULL;
140 ret->references=1;
141 ret->_method_mod_n=NULL;
142 ret->_method_mod_p=NULL;
143 ret->_method_mod_q=NULL;
144 ret->blinding=NULL;
145 ret->bignum_data=NULL;
146 ret->flags=ret->meth->flags;
147 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
148 {
149 Free(ret);
150 ret=NULL;
151 }
152 else
153 CRYPTO_new_ex_data(rsa_meth,ret,&ret->ex_data);
154 return(ret);
155 }
156
157void RSA_free(RSA *r)
158 {
159 int i;
160
161 if (r == NULL) return;
162
163 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
164#ifdef REF_PRINT
165 REF_PRINT("RSA",r);
166#endif
167 if (i > 0) return;
168#ifdef REF_CHECK
169 if (i < 0)
170 {
171 fprintf(stderr,"RSA_free, bad reference count\n");
172 abort();
173 }
174#endif
175
176 CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data);
177
178 if (r->meth->finish != NULL)
179 r->meth->finish(r);
180
181 if (r->n != NULL) BN_clear_free(r->n);
182 if (r->e != NULL) BN_clear_free(r->e);
183 if (r->d != NULL) BN_clear_free(r->d);
184 if (r->p != NULL) BN_clear_free(r->p);
185 if (r->q != NULL) BN_clear_free(r->q);
186 if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
187 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
188 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
189 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
190 if (r->bignum_data != NULL) Free_locked(r->bignum_data);
191 Free(r);
192 }
193
194int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
195 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
196 {
197 rsa_meth_num++;
198 return(CRYPTO_get_ex_new_index(rsa_meth_num-1,
199 &rsa_meth,argl,argp,new_func,dup_func,free_func));
200 }
201
202int RSA_set_ex_data(RSA *r, int idx, void *arg)
203 {
204 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
205 }
206
207void *RSA_get_ex_data(RSA *r, int idx)
208 {
209 return(CRYPTO_get_ex_data(&r->ex_data,idx));
210 }
211
212int RSA_size(RSA *r)
213 {
214 return(BN_num_bytes(r->n));
215 }
216
217int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to,
218 RSA *rsa, int padding)
219 {
220 return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding));
221 }
222
223int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to,
224 RSA *rsa, int padding)
225 {
226 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding));
227 }
228
229int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to,
230 RSA *rsa, int padding)
231 {
232 return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding));
233 }
234
235int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to,
236 RSA *rsa, int padding)
237 {
238 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));
239 }
240
241int RSA_flags(RSA *r)
242 {
243 return((r == NULL)?0:r->meth->flags);
244 }
245
246void RSA_blinding_off(RSA *rsa)
247 {
248 if (rsa->blinding != NULL)
249 {
250 BN_BLINDING_free(rsa->blinding);
251 rsa->blinding=NULL;
252 }
253 rsa->flags&= ~RSA_FLAG_BLINDING;
254 }
255
256int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
257 {
258 BIGNUM *A,*Ai;
259 BN_CTX *ctx;
260 int ret=0;
261
262 if (p_ctx == NULL)
263 {
264 if ((ctx=BN_CTX_new()) == NULL) goto err;
265 }
266 else
267 ctx=p_ctx;
268
269 if (rsa->blinding != NULL)
270 BN_BLINDING_free(rsa->blinding);
271
272 BN_CTX_start(ctx);
273 A = BN_CTX_get(ctx);
274 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
275 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
276
277 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
278 goto err;
279 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n);
280 rsa->flags|=RSA_FLAG_BLINDING;
281 BN_free(Ai);
282 ret=1;
283err:
284 BN_CTX_end(ctx);
285 if (ctx != p_ctx) BN_CTX_free(ctx);
286 return(ret);
287 }
288
289int RSA_memory_lock(RSA *r)
290 {
291 int i,j,k,off;
292 char *p;
293 BIGNUM *bn,**t[6],*b;
294 BN_ULONG *ul;
295
296 if (r->d == NULL) return(1);
297 t[0]= &r->d;
298 t[1]= &r->p;
299 t[2]= &r->q;
300 t[3]= &r->dmp1;
301 t[4]= &r->dmq1;
302 t[5]= &r->iqmp;
303 k=sizeof(BIGNUM)*6;
304 off=k/sizeof(BN_ULONG)+1;
305 j=1;
306 for (i=0; i<6; i++)
307 j+= (*t[i])->top;
308 if ((p=Malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
309 {
310 RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
311 return(0);
312 }
313 bn=(BIGNUM *)p;
314 ul=(BN_ULONG *)&(p[off]);
315 for (i=0; i<6; i++)
316 {
317 b= *(t[i]);
318 *(t[i])= &(bn[i]);
319 memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
320 bn[i].flags=BN_FLG_STATIC_DATA;
321 bn[i].d=ul;
322 memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
323 ul+=b->top;
324 BN_clear_free(b);
325 }
326
327 /* I should fix this so it can still be done */
328 r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
329
330 r->bignum_data=p;
331 return(1);
332 }
333
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 1465c01f4f..0000000000
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ /dev/null
@@ -1,163 +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 if (RAND_bytes(seed, SHA_DIGEST_LENGTH) <= 0)
54 return (0);
55#ifdef PKCS_TESTVECT
56 memcpy(seed,
57 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f",
58 20);
59#endif
60
61 MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH);
62 for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)
63 db[i] ^= dbmask[i];
64
65 MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH);
66 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
67 seed[i] ^= seedmask[i];
68
69 Free(dbmask);
70 return (1);
71 }
72
73int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
74 unsigned char *from, int flen, int num, unsigned char *param,
75 int plen)
76 {
77 int i, dblen, mlen = -1;
78 unsigned char *maskeddb;
79 int lzero;
80 unsigned char *db, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH];
81
82 if (--num < 2 * SHA_DIGEST_LENGTH + 1)
83 {
84 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
85 return (-1);
86 }
87
88 dblen = num - SHA_DIGEST_LENGTH;
89 db = Malloc(dblen);
90 if (db == NULL)
91 {
92 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
93 return (-1);
94 }
95
96 lzero = num - flen;
97 maskeddb = from - lzero + SHA_DIGEST_LENGTH;
98
99 MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen);
100 for (i = lzero; i < SHA_DIGEST_LENGTH; i++)
101 seed[i] ^= from[i - lzero];
102
103 MGF1(db, dblen, seed, SHA_DIGEST_LENGTH);
104 for (i = 0; i < dblen; i++)
105 db[i] ^= maskeddb[i];
106
107 SHA1(param, plen, phash);
108
109 if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0)
110 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
111 else
112 {
113 for (i = SHA_DIGEST_LENGTH; i < dblen; i++)
114 if (db[i] != 0x00)
115 break;
116 if (db[i] != 0x01 || i++ >= dblen)
117 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,
118 RSA_R_OAEP_DECODING_ERROR);
119 else
120 {
121 mlen = dblen - i;
122 if (tlen < mlen)
123 {
124 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE);
125 mlen = -1;
126 }
127 else
128 memcpy(to, db + i, mlen);
129 }
130 }
131 Free(db);
132 return (mlen);
133 }
134
135int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen)
136 {
137 long i, outlen = 0;
138 unsigned char cnt[4];
139 SHA_CTX c;
140 unsigned char md[SHA_DIGEST_LENGTH];
141
142 for (i = 0; outlen < len; i++)
143 {
144 cnt[0] = (i >> 24) & 255, cnt[1] = (i >> 16) & 255,
145 cnt[2] = (i >> 8) & 255, cnt[3] = i & 255;
146 SHA1_Init(&c);
147 SHA1_Update(&c, seed, seedlen);
148 SHA1_Update(&c, cnt, 4);
149 if (outlen + SHA_DIGEST_LENGTH <= len)
150 {
151 SHA1_Final(mask + outlen, &c);
152 outlen += SHA_DIGEST_LENGTH;
153 }
154 else
155 {
156 SHA1_Final(md, &c);
157 memcpy(mask + outlen, md, len - outlen);
158 outlen = len;
159 }
160 }
161 return (0);
162 }
163#endif
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c
deleted file mode 100644
index 48a32bc264..0000000000
--- a/src/lib/libcrypto/rsa/rsa_pk1.c
+++ /dev/null
@@ -1,224 +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 /* pad 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 if (j > tlen)
134 {
135 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE);
136 return(-1);
137 }
138 memcpy(to,p,(unsigned int)j);
139
140 return(j);
141 }
142
143int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
144 unsigned char *from, int flen)
145 {
146 int i,j;
147 unsigned char *p;
148
149 if (flen > (tlen-11))
150 {
151 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
152 return(0);
153 }
154
155 p=(unsigned char *)to;
156
157 *(p++)=0;
158 *(p++)=2; /* Public Key BT (Block Type) */
159
160 /* pad out with non-zero random data */
161 j=tlen-3-flen;
162
163 if (RAND_bytes(p,j) <= 0)
164 return(0);
165 for (i=0; i<j; i++)
166 {
167 if (*p == '\0')
168 do {
169 if (RAND_bytes(p,1) <= 0)
170 return(0);
171 } while (*p == '\0');
172 p++;
173 }
174
175 *(p++)='\0';
176
177 memcpy(p,from,(unsigned int)flen);
178 return(1);
179 }
180
181int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
182 unsigned char *from, int flen, int num)
183 {
184 int i,j;
185 unsigned char *p;
186
187 p=from;
188 if ((num != (flen+1)) || (*(p++) != 02))
189 {
190 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02);
191 return(-1);
192 }
193#ifdef PKCS1_CHECK
194 return(num-11);
195#endif
196
197 /* scan over padding data */
198 j=flen-1; /* one for type. */
199 for (i=0; i<j; i++)
200 if (*(p++) == 0) break;
201
202 if (i == j)
203 {
204 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_NULL_BEFORE_BLOCK_MISSING);
205 return(-1);
206 }
207
208 if (i < 8)
209 {
210 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BAD_PAD_BYTE_COUNT);
211 return(-1);
212 }
213 i++; /* Skip over the '\0' */
214 j-=i;
215 if (j > tlen)
216 {
217 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE);
218 return(-1);
219 }
220 memcpy(to,p,(unsigned int)j);
221
222 return(j);
223 }
224
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
deleted file mode 100644
index 61efb0b00f..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) M_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 05bb7fb74a..0000000000
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ /dev/null
@@ -1,221 +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
66/* Size of an SSL signature: MD5+SHA1 */
67#define SSL_SIG_LENGTH 36
68
69int RSA_sign(int type, unsigned char *m, unsigned int m_len,
70 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
71 {
72 X509_SIG sig;
73 ASN1_TYPE parameter;
74 int i,j,ret=1;
75 unsigned char *p,*s = NULL;
76 X509_ALGOR algor;
77 ASN1_OCTET_STRING digest;
78 if(rsa->flags & RSA_FLAG_SIGN_VER)
79 return rsa->meth->rsa_sign(type, m, m_len, sigret, siglen, rsa);
80 /* Special case: SSL signature, just check the length */
81 if(type == NID_md5_sha1) {
82 if(m_len != SSL_SIG_LENGTH) {
83 RSAerr(RSA_F_RSA_SIGN,RSA_R_INVALID_MESSAGE_LENGTH);
84 return(0);
85 }
86 i = SSL_SIG_LENGTH;
87 s = m;
88 } else {
89 sig.algor= &algor;
90 sig.algor->algorithm=OBJ_nid2obj(type);
91 if (sig.algor->algorithm == NULL)
92 {
93 RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE);
94 return(0);
95 }
96 if (sig.algor->algorithm->length == 0)
97 {
98 RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
99 return(0);
100 }
101 parameter.type=V_ASN1_NULL;
102 parameter.value.ptr=NULL;
103 sig.algor->parameter= &parameter;
104
105 sig.digest= &digest;
106 sig.digest->data=m;
107 sig.digest->length=m_len;
108
109 i=i2d_X509_SIG(&sig,NULL);
110 }
111 j=RSA_size(rsa);
112 if ((i-RSA_PKCS1_PADDING) > j)
113 {
114 RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
115 return(0);
116 }
117 if(type != NID_md5_sha1) {
118 s=(unsigned char *)Malloc((unsigned int)j+1);
119 if (s == NULL)
120 {
121 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE);
122 return(0);
123 }
124 p=s;
125 i2d_X509_SIG(&sig,&p);
126 }
127 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
128 if (i <= 0)
129 ret=0;
130 else
131 *siglen=i;
132
133 if(type != NID_md5_sha1) {
134 memset(s,0,(unsigned int)j+1);
135 Free(s);
136 }
137 return(ret);
138 }
139
140int RSA_verify(int dtype, unsigned char *m, unsigned int m_len,
141 unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
142 {
143 int i,ret=0,sigtype;
144 unsigned char *p,*s;
145 X509_SIG *sig=NULL;
146
147 if (siglen != (unsigned int)RSA_size(rsa))
148 {
149 RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
150 return(0);
151 }
152
153 if(rsa->flags & RSA_FLAG_SIGN_VER)
154 return rsa->meth->rsa_verify(dtype, m, m_len, sigbuf, siglen, rsa);
155
156 s=(unsigned char *)Malloc((unsigned int)siglen);
157 if (s == NULL)
158 {
159 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
160 goto err;
161 }
162 if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {
163 RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
164 return(0);
165 }
166 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
167
168 if (i <= 0) goto err;
169
170 /* Special case: SSL signature */
171 if(dtype == NID_md5_sha1) {
172 if((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))
173 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
174 else ret = 1;
175 } else {
176 p=s;
177 sig=d2i_X509_SIG(NULL,&p,(long)i);
178
179 if (sig == NULL) goto err;
180 sigtype=OBJ_obj2nid(sig->algor->algorithm);
181
182
183 #ifdef RSA_DEBUG
184 /* put a backward compatibility flag in EAY */
185 fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype),
186 OBJ_nid2ln(dtype));
187 #endif
188 if (sigtype != dtype)
189 {
190 if (((dtype == NID_md5) &&
191 (sigtype == NID_md5WithRSAEncryption)) ||
192 ((dtype == NID_md2) &&
193 (sigtype == NID_md2WithRSAEncryption)))
194 {
195 /* ok, we will let it through */
196 #if !defined(NO_STDIO) && !defined(WIN16)
197 fprintf(stderr,"signature has problems, re-make with post SSLeay045\n");
198 #endif
199 }
200 else
201 {
202 RSAerr(RSA_F_RSA_VERIFY,
203 RSA_R_ALGORITHM_MISMATCH);
204 goto err;
205 }
206 }
207 if ( ((unsigned int)sig->digest->length != m_len) ||
208 (memcmp(m,sig->digest->data,m_len) != 0))
209 {
210 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
211 }
212 else
213 ret=1;
214 }
215err:
216 if (sig != NULL) X509_SIG_free(sig);
217 memset(s,0,(unsigned int)siglen);
218 Free(s);
219 return(ret);
220 }
221
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c
deleted file mode 100644
index 81a857c813..0000000000
--- a/src/lib/libcrypto/rsa/rsa_ssl.c
+++ /dev/null
@@ -1,154 +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 if (RAND_bytes(p,j) <= 0)
86 return(0);
87 for (i=0; i<j; i++)
88 {
89 if (*p == '\0')
90 do {
91 if (RAND_bytes(p,1) <= 0)
92 return(0);
93 } while (*p == '\0');
94 p++;
95 }
96
97 memset(p,3,8);
98 p+=8;
99 *(p++)='\0';
100
101 memcpy(p,from,(unsigned int)flen);
102 return(1);
103 }
104
105int RSA_padding_check_SSLv23(unsigned char *to, int tlen, unsigned char *from,
106 int flen, int num)
107 {
108 int i,j,k;
109 unsigned char *p;
110
111 p=from;
112 if (flen < 10)
113 {
114 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL);
115 return(-1);
116 }
117 if ((num != (flen+1)) || (*(p++) != 02))
118 {
119 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02);
120 return(-1);
121 }
122
123 /* scan over padding data */
124 j=flen-1; /* one for type */
125 for (i=0; i<j; i++)
126 if (*(p++) == 0) break;
127
128 if ((i == j) || (i < 8))
129 {
130 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_NULL_BEFORE_BLOCK_MISSING);
131 return(-1);
132 }
133 for (k= -8; k<0; k++)
134 {
135 if (p[k] != 0x03) break;
136 }
137 if (k == 0)
138 {
139 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK);
140 return(-1);
141 }
142
143 i++; /* Skip over the '\0' */
144 j-=i;
145 if (j > tlen)
146 {
147 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_LARGE);
148 return(-1);
149 }
150 memcpy(to,p,(unsigned int)j);
151
152 return(j);
153 }
154
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 09df993ecd..0000000000
--- a/src/lib/libcrypto/sha/asm/sha1-586.pl
+++ /dev/null
@@ -1,538 +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="ecx";
12$C="ebx";
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_data("sha1_block_asm_data_order");
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+=2)
57 {
58 &mov($A,&DWP(($i+0)*4,$in,"",0));# unless $i == 0;
59 &mov($B,&DWP(($i+1)*4,$in,"",0));
60 &bswap($A);
61 &bswap($B);
62 &mov(&swtmp($i+0),$A);
63 &mov(&swtmp($i+1),$B);
64 }
65
66 &comment("We now have the X array on the stack");
67 &comment("starting at sp-4");
68 }
69
70# Rules of engagement
71# F is always trashable at the start, the running total.
72# E becomes the next F so it can be trashed after it has been 'accumulated'
73# F becomes A in the next round. We don't need to access it much.
74# During the X update part, the result ends up in $X[$n0].
75
76sub BODY_00_15
77 {
78 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
79
80return if $n & 1;
81 &comment("00_15 $n");
82
83 &mov($f,$c);
84
85 &mov($tmp1,$a);
86 &xor($f,$d); # F2
87
88 &rotl($tmp1,5); # A2
89
90 &and($f,$b); # F3
91 &add($tmp1,$e);
92
93 &rotr($b,1); # B1 <- F
94 &mov($e,&swtmp($n)); # G1
95
96 &rotr($b,1); # B1 <- F
97 &xor($f,$d); # F4
98
99 &lea($tmp1,&DWP($K,$tmp1,$e,1));
100
101############################
102# &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
103# &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
104$n++;
105 local($n0,$n1,$n2,$n3,$np)=&Na($n);
106 ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f);
107
108 &mov($f,$c);
109
110 &add($a,$tmp1); # MOVED DOWN
111 &xor($f,$d); # F2
112
113 &mov($tmp1,$a);
114 &and($f,$b); # F3
115
116 &rotl($tmp1,5); # A2
117
118 &add($tmp1,$e);
119 &mov($e,&swtmp($n)); # G1
120
121 &rotr($b,1); # B1 <- F
122 &xor($f,$d); # F4
123
124 &rotr($b,1); # B1 <- F
125 &lea($tmp1,&DWP($K,$tmp1,$e,1));
126
127 &add($f,$tmp1);
128 }
129
130sub BODY_16_19
131 {
132 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
133 local($n0,$n1,$n2,$n3,$np)=&Na($n);
134
135return if $n & 1;
136 &comment("16_19 $n");
137
138 &nop() if ($pos < 0);
139&mov($tmp1,&swtmp($n0)); # X1
140 &mov($f,&swtmp($n1)); # X2
141&xor($f,$tmp1); # X3
142 &mov($tmp1,&swtmp($n2)); # X4
143&xor($f,$tmp1); # X5
144 &mov($tmp1,&swtmp($n3)); # X6
145&xor($f,$tmp1); # X7 - slot
146 &mov($tmp1,$c); # F1
147&rotl($f,1); # X8 - slot
148 &xor($tmp1,$d); # F2
149&mov(&swtmp($n0),$f); # X9 - anytime
150 &and($tmp1,$b); # F3
151&lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
152 &xor($tmp1,$d); # F4
153&mov($e,$a); # A1
154 &add($f,$tmp1); # tot+=F();
155
156&rotl($e,5); # A2
157
158&rotr($b,1); # B1 <- F
159 &add($f,$e); # tot+=a
160
161############################
162# &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
163# &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
164$n++;
165 local($n0,$n1,$n2,$n3,$np)=&Na($n);
166 ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f);
167
168
169&mov($f,&swtmp($n0)); # X1
170 &mov($tmp1,&swtmp($n1)); # X2
171&xor($f,$tmp1); # X3
172 &mov($tmp1,&swtmp($n2)); # X4
173&xor($f,$tmp1); # X5
174 &mov($tmp1,&swtmp($n3)); # X6
175&rotr($c,1); #&rotr($b,1); # B1 <- F # MOVED DOWN
176 &xor($f,$tmp1); # X7 - slot
177&rotl($f,1); # X8 - slot
178 &mov($tmp1,$c); # F1
179&xor($tmp1,$d); # F2
180 &mov(&swtmp($n0),$f); # X9 - anytime
181&and($tmp1,$b); # F3
182 &lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
183
184&xor($tmp1,$d); # F4
185 &mov($e,$a); # A1
186
187&rotl($e,5); # A2
188
189&rotr($b,1); # B1 <- F
190 &add($f,$e); # tot+=a
191
192&rotr($b,1); # B1 <- F
193 &add($f,$tmp1); # tot+=F();
194
195 }
196
197sub BODY_20_39
198 {
199 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
200
201 &comment("20_39 $n");
202 local($n0,$n1,$n2,$n3,$np)=&Na($n);
203
204&mov($f,&swtmp($n0)); # X1
205 &mov($tmp1,&swtmp($n1)); # X2
206&xor($f,$tmp1); # X3
207 &mov($tmp1,&swtmp($n2)); # X4
208&xor($f,$tmp1); # X5
209 &mov($tmp1,&swtmp($n3)); # X6
210&xor($f,$tmp1); # X7 - slot
211 &mov($tmp1,$b); # F1
212&rotl($f,1); # X8 - slot
213 &xor($tmp1,$c); # F2
214&mov(&swtmp($n0),$f); # X9 - anytime
215 &xor($tmp1,$d); # F3
216
217&lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
218 &mov($e,$a); # A1
219
220&rotl($e,5); # A2
221
222if ($n != 79) # last loop
223 {
224 &rotr($b,1); # B1 <- F
225 &add($e,$tmp1); # tmp1=F()+a
226
227 &rotr($b,1); # B2 <- F
228 &add($f,$e); # tot+=tmp1;
229 }
230else
231 {
232 &add($e,$tmp1); # tmp1=F()+a
233 &mov($tmp1,&wparam(0));
234
235 &rotr($b,1); # B1 <- F
236 &add($f,$e); # tot+=tmp1;
237
238 &rotr($b,1); # B2 <- F
239 }
240 }
241
242sub BODY_40_59
243 {
244 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
245
246 &comment("40_59 $n");
247 return if $n & 1;
248 local($n0,$n1,$n2,$n3,$np)=&Na($n);
249
250&mov($f,&swtmp($n0)); # X1
251 &mov($tmp1,&swtmp($n1)); # X2
252&xor($f,$tmp1); # X3
253 &mov($tmp1,&swtmp($n2)); # X4
254&xor($f,$tmp1); # X5
255 &mov($tmp1,&swtmp($n3)); # X6
256&xor($f,$tmp1); # X7 - slot
257 &mov($tmp1,$b); # F1
258&rotl($f,1); # X8 - slot
259 &or($tmp1,$c); # F2
260&mov(&swtmp($n0),$f); # X9 - anytime
261 &and($tmp1,$d); # F3
262
263&lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
264 &mov($e,$b); # F4
265
266&rotr($b,1); # B1 <- F
267 &and($e,$c); # F5
268
269&or($tmp1,$e); # F6
270 &mov($e,$a); # A1
271
272&rotl($e,5); # A2
273
274&add($tmp1,$e); # tmp1=F()+a
275
276############################
277# &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
278# &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
279$n++;
280 local($n0,$n1,$n2,$n3,$np)=&Na($n);
281 ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f);
282
283 &mov($f,&swtmp($n0)); # X1
284&add($a,$tmp1); # tot+=tmp1; # moved was add f,tmp1
285 &mov($tmp1,&swtmp($n1)); # X2
286&xor($f,$tmp1); # X3
287 &mov($tmp1,&swtmp($n2)); # X4
288&xor($f,$tmp1); # X5
289 &mov($tmp1,&swtmp($n3)); # X6
290&rotr($c,1); # B2 <- F # moved was rotr b,1
291 &xor($f,$tmp1); # X7 - slot
292&rotl($f,1); # X8 - slot
293 &mov($tmp1,$b); # F1
294&mov(&swtmp($n0),$f); # X9 - anytime
295 &or($tmp1,$c); # F2
296&lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
297 &mov($e,$b); # F4
298&and($tmp1,$d); # F3
299 &and($e,$c); # F5
300
301&or($tmp1,$e); # F6
302 &mov($e,$a); # A1
303
304&rotl($e,5); # A2
305
306&rotr($b,1); # B1 <- F
307 &add($tmp1,$e); # tmp1=F()+a
308
309&rotr($b,1); # B2 <- F
310 &add($f,$tmp1); # tot+=tmp1;
311 }
312
313sub BODY_60_79
314 {
315 &BODY_20_39(@_);
316 }
317
318sub sha1_block_host
319 {
320 local($name)=@_;
321
322 &function_begin_B($name,"");
323
324 # parameter 1 is the MD5_CTX structure.
325 # A 0
326 # B 4
327 # C 8
328 # D 12
329 # E 16
330
331 &mov("ecx", &wparam(2));
332 &push("esi");
333 &shl("ecx",6);
334 &mov("esi", &wparam(1));
335 &push("ebp");
336 &add("ecx","esi"); # offset to leave on
337 &push("ebx");
338 &mov("ebp", &wparam(0));
339 &push("edi");
340 &mov($D, &DWP(12,"ebp","",0));
341 &stack_push(18+9);
342 &mov($E, &DWP(16,"ebp","",0));
343 &mov($C, &DWP( 8,"ebp","",0));
344 &mov(&swtmp(17),"ecx");
345
346 &comment("First we need to setup the X array");
347
348 for ($i=0; $i<16; $i+=2)
349 {
350 &mov($A,&DWP(($i+0)*4,"esi","",0));# unless $i == 0;
351 &mov($B,&DWP(($i+1)*4,"esi","",0));
352 &mov(&swtmp($i+0),$A);
353 &mov(&swtmp($i+1),$B);
354 }
355 &jmp(&label("shortcut"));
356 &function_end_B($name);
357 }
358
359
360sub sha1_block_data
361 {
362 local($name)=@_;
363
364 &function_begin_B($name,"");
365
366 # parameter 1 is the MD5_CTX structure.
367 # A 0
368 # B 4
369 # C 8
370 # D 12
371 # E 16
372
373 &mov("ecx", &wparam(2));
374 &push("esi");
375 &shl("ecx",6);
376 &mov("esi", &wparam(1));
377 &push("ebp");
378 &add("ecx","esi"); # offset to leave on
379 &push("ebx");
380 &mov("ebp", &wparam(0));
381 &push("edi");
382 &mov($D, &DWP(12,"ebp","",0));
383 &stack_push(18+9);
384 &mov($E, &DWP(16,"ebp","",0));
385 &mov($C, &DWP( 8,"ebp","",0));
386 &mov(&swtmp(17),"ecx");
387
388 &comment("First we need to setup the X array");
389
390 &set_label("start") unless $normal;
391
392 &X_expand("esi");
393 &mov(&wparam(1),"esi");
394
395 &set_label("shortcut", 0, 1);
396 &comment("");
397 &comment("Start processing");
398
399 # odd start
400 &mov($A, &DWP( 0,"ebp","",0));
401 &mov($B, &DWP( 4,"ebp","",0));
402 $X="esp";
403 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T);
404 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E);
405 &BODY_00_15( 0,$K[0],$X, 2,$E,$T,$A,$B,$C,$D);
406 &BODY_00_15( 0,$K[0],$X, 3,$D,$E,$T,$A,$B,$C);
407 &BODY_00_15( 0,$K[0],$X, 4,$C,$D,$E,$T,$A,$B);
408 &BODY_00_15( 0,$K[0],$X, 5,$B,$C,$D,$E,$T,$A);
409 &BODY_00_15( 0,$K[0],$X, 6,$A,$B,$C,$D,$E,$T);
410 &BODY_00_15( 0,$K[0],$X, 7,$T,$A,$B,$C,$D,$E);
411 &BODY_00_15( 0,$K[0],$X, 8,$E,$T,$A,$B,$C,$D);
412 &BODY_00_15( 0,$K[0],$X, 9,$D,$E,$T,$A,$B,$C);
413 &BODY_00_15( 0,$K[0],$X,10,$C,$D,$E,$T,$A,$B);
414 &BODY_00_15( 0,$K[0],$X,11,$B,$C,$D,$E,$T,$A);
415 &BODY_00_15( 0,$K[0],$X,12,$A,$B,$C,$D,$E,$T);
416 &BODY_00_15( 0,$K[0],$X,13,$T,$A,$B,$C,$D,$E);
417 &BODY_00_15( 0,$K[0],$X,14,$E,$T,$A,$B,$C,$D);
418 &BODY_00_15( 1,$K[0],$X,15,$D,$E,$T,$A,$B,$C);
419 &BODY_16_19(-1,$K[0],$X,16,$C,$D,$E,$T,$A,$B);
420 &BODY_16_19( 0,$K[0],$X,17,$B,$C,$D,$E,$T,$A);
421 &BODY_16_19( 0,$K[0],$X,18,$A,$B,$C,$D,$E,$T);
422 &BODY_16_19( 1,$K[0],$X,19,$T,$A,$B,$C,$D,$E);
423
424 &BODY_20_39(-1,$K[1],$X,20,$E,$T,$A,$B,$C,$D);
425 &BODY_20_39( 0,$K[1],$X,21,$D,$E,$T,$A,$B,$C);
426 &BODY_20_39( 0,$K[1],$X,22,$C,$D,$E,$T,$A,$B);
427 &BODY_20_39( 0,$K[1],$X,23,$B,$C,$D,$E,$T,$A);
428 &BODY_20_39( 0,$K[1],$X,24,$A,$B,$C,$D,$E,$T);
429 &BODY_20_39( 0,$K[1],$X,25,$T,$A,$B,$C,$D,$E);
430 &BODY_20_39( 0,$K[1],$X,26,$E,$T,$A,$B,$C,$D);
431 &BODY_20_39( 0,$K[1],$X,27,$D,$E,$T,$A,$B,$C);
432 &BODY_20_39( 0,$K[1],$X,28,$C,$D,$E,$T,$A,$B);
433 &BODY_20_39( 0,$K[1],$X,29,$B,$C,$D,$E,$T,$A);
434 &BODY_20_39( 0,$K[1],$X,30,$A,$B,$C,$D,$E,$T);
435 &BODY_20_39( 0,$K[1],$X,31,$T,$A,$B,$C,$D,$E);
436 &BODY_20_39( 0,$K[1],$X,32,$E,$T,$A,$B,$C,$D);
437 &BODY_20_39( 0,$K[1],$X,33,$D,$E,$T,$A,$B,$C);
438 &BODY_20_39( 0,$K[1],$X,34,$C,$D,$E,$T,$A,$B);
439 &BODY_20_39( 0,$K[1],$X,35,$B,$C,$D,$E,$T,$A);
440 &BODY_20_39( 0,$K[1],$X,36,$A,$B,$C,$D,$E,$T);
441 &BODY_20_39( 0,$K[1],$X,37,$T,$A,$B,$C,$D,$E);
442 &BODY_20_39( 0,$K[1],$X,38,$E,$T,$A,$B,$C,$D);
443 &BODY_20_39( 1,$K[1],$X,39,$D,$E,$T,$A,$B,$C);
444
445 &BODY_40_59(-1,$K[2],$X,40,$C,$D,$E,$T,$A,$B);
446 &BODY_40_59( 0,$K[2],$X,41,$B,$C,$D,$E,$T,$A);
447 &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
448 &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
449 &BODY_40_59( 0,$K[2],$X,44,$E,$T,$A,$B,$C,$D);
450 &BODY_40_59( 0,$K[2],$X,45,$D,$E,$T,$A,$B,$C);
451 &BODY_40_59( 0,$K[2],$X,46,$C,$D,$E,$T,$A,$B);
452 &BODY_40_59( 0,$K[2],$X,47,$B,$C,$D,$E,$T,$A);
453 &BODY_40_59( 0,$K[2],$X,48,$A,$B,$C,$D,$E,$T);
454 &BODY_40_59( 0,$K[2],$X,49,$T,$A,$B,$C,$D,$E);
455 &BODY_40_59( 0,$K[2],$X,50,$E,$T,$A,$B,$C,$D);
456 &BODY_40_59( 0,$K[2],$X,51,$D,$E,$T,$A,$B,$C);
457 &BODY_40_59( 0,$K[2],$X,52,$C,$D,$E,$T,$A,$B);
458 &BODY_40_59( 0,$K[2],$X,53,$B,$C,$D,$E,$T,$A);
459 &BODY_40_59( 0,$K[2],$X,54,$A,$B,$C,$D,$E,$T);
460 &BODY_40_59( 0,$K[2],$X,55,$T,$A,$B,$C,$D,$E);
461 &BODY_40_59( 0,$K[2],$X,56,$E,$T,$A,$B,$C,$D);
462 &BODY_40_59( 0,$K[2],$X,57,$D,$E,$T,$A,$B,$C);
463 &BODY_40_59( 0,$K[2],$X,58,$C,$D,$E,$T,$A,$B);
464 &BODY_40_59( 1,$K[2],$X,59,$B,$C,$D,$E,$T,$A);
465
466 &BODY_60_79(-1,$K[3],$X,60,$A,$B,$C,$D,$E,$T);
467 &BODY_60_79( 0,$K[3],$X,61,$T,$A,$B,$C,$D,$E);
468 &BODY_60_79( 0,$K[3],$X,62,$E,$T,$A,$B,$C,$D);
469 &BODY_60_79( 0,$K[3],$X,63,$D,$E,$T,$A,$B,$C);
470 &BODY_60_79( 0,$K[3],$X,64,$C,$D,$E,$T,$A,$B);
471 &BODY_60_79( 0,$K[3],$X,65,$B,$C,$D,$E,$T,$A);
472 &BODY_60_79( 0,$K[3],$X,66,$A,$B,$C,$D,$E,$T);
473 &BODY_60_79( 0,$K[3],$X,67,$T,$A,$B,$C,$D,$E);
474 &BODY_60_79( 0,$K[3],$X,68,$E,$T,$A,$B,$C,$D);
475 &BODY_60_79( 0,$K[3],$X,69,$D,$E,$T,$A,$B,$C);
476 &BODY_60_79( 0,$K[3],$X,70,$C,$D,$E,$T,$A,$B);
477 &BODY_60_79( 0,$K[3],$X,71,$B,$C,$D,$E,$T,$A);
478 &BODY_60_79( 0,$K[3],$X,72,$A,$B,$C,$D,$E,$T);
479 &BODY_60_79( 0,$K[3],$X,73,$T,$A,$B,$C,$D,$E);
480 &BODY_60_79( 0,$K[3],$X,74,$E,$T,$A,$B,$C,$D);
481 &BODY_60_79( 0,$K[3],$X,75,$D,$E,$T,$A,$B,$C);
482 &BODY_60_79( 0,$K[3],$X,76,$C,$D,$E,$T,$A,$B);
483 &BODY_60_79( 0,$K[3],$X,77,$B,$C,$D,$E,$T,$A);
484 &BODY_60_79( 0,$K[3],$X,78,$A,$B,$C,$D,$E,$T);
485 &BODY_60_79( 2,$K[3],$X,79,$T,$A,$B,$C,$D,$E);
486
487 &comment("End processing");
488 &comment("");
489 # D is the tmp value
490
491 # E -> A
492 # T -> B
493 # A -> C
494 # B -> D
495 # C -> E
496 # D -> T
497
498 # The last 2 have been moved into the last loop
499 # &mov($tmp1,&wparam(0));
500
501 &mov($D, &DWP(12,$tmp1,"",0));
502 &add($D,$B);
503 &mov($B, &DWP( 4,$tmp1,"",0));
504 &add($B,$T);
505 &mov($T, $A);
506 &mov($A, &DWP( 0,$tmp1,"",0));
507 &mov(&DWP(12,$tmp1,"",0),$D);
508
509 &add($A,$E);
510 &mov($E, &DWP(16,$tmp1,"",0));
511 &add($E,$C);
512 &mov($C, &DWP( 8,$tmp1,"",0));
513 &add($C,$T);
514
515 &mov(&DWP( 0,$tmp1,"",0),$A);
516 &mov("esi",&wparam(1));
517 &mov(&DWP( 8,$tmp1,"",0),$C);
518 &add("esi",64);
519 &mov("eax",&swtmp(17));
520 &mov(&DWP(16,$tmp1,"",0),$E);
521 &cmp("esi","eax");
522 &mov(&DWP( 4,$tmp1,"",0),$B);
523 &jl(&label("start"));
524
525 &stack_pop(18+9);
526 &pop("edi");
527 &pop("ebx");
528 &pop("ebp");
529 &pop("esi");
530 &ret();
531
532 # it has to reside within sha1_block_asm_host_order body
533 # because it calls &jmp(&label("shortcut"));
534 &sha1_block_host("sha1_block_asm_host_order");
535
536 &function_end_B($name);
537 }
538
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h
deleted file mode 100644
index 77f6d9695e..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#if defined(NO_SHA) || (defined(NO_SHA0) && defined(NO_SHA1))
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 void *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, const unsigned char *data);
107#endif
108#ifndef NO_SHA1
109void SHA1_Init(SHA_CTX *c);
110void SHA1_Update(SHA_CTX *c, const void *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, const 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 c09edb4cd7..0000000000
--- a/src/lib/libcrypto/sha/sha1dgst.c
+++ /dev/null
@@ -1,73 +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#if !defined(NO_SHA1) && !defined(NO_SHA)
60
61#undef SHA_0
62#define SHA_1
63
64#include <openssl/opensslv.h>
65
66const char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
67
68/* The implementation is in ../md32_common.h */
69
70#include "sha_locl.h"
71
72#endif
73
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h
deleted file mode 100644
index 2f8aef83f3..0000000000
--- a/src/lib/libcrypto/sha/sha_locl.h
+++ /dev/null
@@ -1,471 +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#include <openssl/sha.h>
64
65#ifndef SHA_LONG_LOG2
66#define SHA_LONG_LOG2 2 /* default to 32 bits */
67#endif
68
69#define DATA_ORDER_IS_BIG_ENDIAN
70
71#define HASH_LONG SHA_LONG
72#define HASH_LONG_LOG2 SHA_LONG_LOG2
73#define HASH_CTX SHA_CTX
74#define HASH_CBLOCK SHA_CBLOCK
75#define HASH_LBLOCK SHA_LBLOCK
76#define HASH_MAKE_STRING(c,s) do { \
77 unsigned long ll; \
78 ll=(c)->h0; HOST_l2c(ll,(s)); \
79 ll=(c)->h1; HOST_l2c(ll,(s)); \
80 ll=(c)->h2; HOST_l2c(ll,(s)); \
81 ll=(c)->h3; HOST_l2c(ll,(s)); \
82 ll=(c)->h4; HOST_l2c(ll,(s)); \
83 } while (0)
84
85#if defined(SHA_0)
86
87# define HASH_UPDATE SHA_Update
88# define HASH_TRANSFORM SHA_Transform
89# define HASH_FINAL SHA_Final
90# define HASH_INIT SHA_Init
91# define HASH_BLOCK_HOST_ORDER sha_block_host_order
92# define HASH_BLOCK_DATA_ORDER sha_block_data_order
93# define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id))
94
95 void sha_block_host_order (SHA_CTX *c, const void *p,int num);
96 void sha_block_data_order (SHA_CTX *c, const void *p,int num);
97
98#elif defined(SHA_1)
99
100# define HASH_UPDATE SHA1_Update
101# define HASH_TRANSFORM SHA1_Transform
102# define HASH_FINAL SHA1_Final
103# define HASH_INIT SHA1_Init
104# define HASH_BLOCK_HOST_ORDER sha1_block_host_order
105# define HASH_BLOCK_DATA_ORDER sha1_block_data_order
106# if defined(__MWERKS__) && defined(__MC68K__)
107 /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */
108# define Xupdate(a,ix,ia,ib,ic,id) do { (a)=(ia^ib^ic^id); \
109 ix=(a)=ROTATE((a),1); \
110 } while (0)
111# else
112# define Xupdate(a,ix,ia,ib,ic,id) ( (a)=(ia^ib^ic^id), \
113 ix=(a)=ROTATE((a),1) \
114 )
115# endif
116
117# ifdef SHA1_ASM
118# if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
119# define sha1_block_host_order sha1_block_asm_host_order
120# define DONT_IMPLEMENT_BLOCK_HOST_ORDER
121# define sha1_block_data_order sha1_block_asm_data_order
122# define DONT_IMPLEMENT_BLOCK_DATA_ORDER
123# define HASH_BLOCK_DATA_ORDER_ALIGNED sha1_block_asm_data_order
124# endif
125# endif
126 void sha1_block_host_order (SHA_CTX *c, const void *p,int num);
127 void sha1_block_data_order (SHA_CTX *c, const void *p,int num);
128
129#else
130# error "Either SHA_0 or SHA_1 must be defined."
131#endif
132
133#include "md32_common.h"
134
135#define INIT_DATA_h0 0x67452301UL
136#define INIT_DATA_h1 0xefcdab89UL
137#define INIT_DATA_h2 0x98badcfeUL
138#define INIT_DATA_h3 0x10325476UL
139#define INIT_DATA_h4 0xc3d2e1f0UL
140
141void HASH_INIT (SHA_CTX *c)
142 {
143 c->h0=INIT_DATA_h0;
144 c->h1=INIT_DATA_h1;
145 c->h2=INIT_DATA_h2;
146 c->h3=INIT_DATA_h3;
147 c->h4=INIT_DATA_h4;
148 c->Nl=0;
149 c->Nh=0;
150 c->num=0;
151 }
152
153#define K_00_19 0x5a827999UL
154#define K_20_39 0x6ed9eba1UL
155#define K_40_59 0x8f1bbcdcUL
156#define K_60_79 0xca62c1d6UL
157
158/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
159 * simplified to the code in F_00_19. Wei attributes these optimisations
160 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
161 * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
162 * I've just become aware of another tweak to be made, again from Wei Dai,
163 * in F_40_59, (x&a)|(y&a) -> (x|y)&a
164 */
165#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
166#define F_20_39(b,c,d) ((b) ^ (c) ^ (d))
167#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
168#define F_60_79(b,c,d) F_20_39(b,c,d)
169
170#define BODY_00_15(i,a,b,c,d,e,f,xi) \
171 (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
172 (b)=ROTATE((b),30);
173
174#define BODY_16_19(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
175 Xupdate(f,xi,xa,xb,xc,xd); \
176 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
177 (b)=ROTATE((b),30);
178
179#define BODY_20_31(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
180 Xupdate(f,xi,xa,xb,xc,xd); \
181 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
182 (b)=ROTATE((b),30);
183
184#define BODY_32_39(i,a,b,c,d,e,f,xa,xb,xc,xd) \
185 Xupdate(f,xa,xa,xb,xc,xd); \
186 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
187 (b)=ROTATE((b),30);
188
189#define BODY_40_59(i,a,b,c,d,e,f,xa,xb,xc,xd) \
190 Xupdate(f,xa,xa,xb,xc,xd); \
191 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
192 (b)=ROTATE((b),30);
193
194#define BODY_60_79(i,a,b,c,d,e,f,xa,xb,xc,xd) \
195 Xupdate(f,xa,xa,xb,xc,xd); \
196 (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
197 (b)=ROTATE((b),30);
198
199#ifdef X
200#undef X
201#endif
202#ifndef MD32_XARRAY
203 /*
204 * Originally X was an array. As it's automatic it's natural
205 * to expect RISC compiler to accomodate at least part of it in
206 * the register bank, isn't it? Unfortunately not all compilers
207 * "find" this expectation reasonable:-( On order to make such
208 * compilers generate better code I replace X[] with a bunch of
209 * X0, X1, etc. See the function body below...
210 * <appro@fy.chalmers.se>
211 */
212# define X(i) XX##i
213#else
214 /*
215 * However! Some compilers (most notably HP C) get overwhelmed by
216 * that many local variables so that we have to have the way to
217 * fall down to the original behavior.
218 */
219# define X(i) XX[i]
220#endif
221
222#ifndef DONT_IMPLEMENT_BLOCK_HOST_ORDER
223void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num)
224 {
225 const SHA_LONG *W=d;
226 register unsigned long A,B,C,D,E,T;
227#ifndef MD32_XARRAY
228 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
229 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
230#else
231 SHA_LONG XX[16];
232#endif
233
234 A=c->h0;
235 B=c->h1;
236 C=c->h2;
237 D=c->h3;
238 E=c->h4;
239
240 for (;;)
241 {
242 BODY_00_15( 0,A,B,C,D,E,T,W[ 0]);
243 BODY_00_15( 1,T,A,B,C,D,E,W[ 1]);
244 BODY_00_15( 2,E,T,A,B,C,D,W[ 2]);
245 BODY_00_15( 3,D,E,T,A,B,C,W[ 3]);
246 BODY_00_15( 4,C,D,E,T,A,B,W[ 4]);
247 BODY_00_15( 5,B,C,D,E,T,A,W[ 5]);
248 BODY_00_15( 6,A,B,C,D,E,T,W[ 6]);
249 BODY_00_15( 7,T,A,B,C,D,E,W[ 7]);
250 BODY_00_15( 8,E,T,A,B,C,D,W[ 8]);
251 BODY_00_15( 9,D,E,T,A,B,C,W[ 9]);
252 BODY_00_15(10,C,D,E,T,A,B,W[10]);
253 BODY_00_15(11,B,C,D,E,T,A,W[11]);
254 BODY_00_15(12,A,B,C,D,E,T,W[12]);
255 BODY_00_15(13,T,A,B,C,D,E,W[13]);
256 BODY_00_15(14,E,T,A,B,C,D,W[14]);
257 BODY_00_15(15,D,E,T,A,B,C,W[15]);
258
259 BODY_16_19(16,C,D,E,T,A,B,X( 0),W[ 0],W[ 2],W[ 8],W[13]);
260 BODY_16_19(17,B,C,D,E,T,A,X( 1),W[ 1],W[ 3],W[ 9],W[14]);
261 BODY_16_19(18,A,B,C,D,E,T,X( 2),W[ 2],W[ 4],W[10],W[15]);
262 BODY_16_19(19,T,A,B,C,D,E,X( 3),W[ 3],W[ 5],W[11],X( 0));
263
264 BODY_20_31(20,E,T,A,B,C,D,X( 4),W[ 4],W[ 6],W[12],X( 1));
265 BODY_20_31(21,D,E,T,A,B,C,X( 5),W[ 5],W[ 7],W[13],X( 2));
266 BODY_20_31(22,C,D,E,T,A,B,X( 6),W[ 6],W[ 8],W[14],X( 3));
267 BODY_20_31(23,B,C,D,E,T,A,X( 7),W[ 7],W[ 9],W[15],X( 4));
268 BODY_20_31(24,A,B,C,D,E,T,X( 8),W[ 8],W[10],X( 0),X( 5));
269 BODY_20_31(25,T,A,B,C,D,E,X( 9),W[ 9],W[11],X( 1),X( 6));
270 BODY_20_31(26,E,T,A,B,C,D,X(10),W[10],W[12],X( 2),X( 7));
271 BODY_20_31(27,D,E,T,A,B,C,X(11),W[11],W[13],X( 3),X( 8));
272 BODY_20_31(28,C,D,E,T,A,B,X(12),W[12],W[14],X( 4),X( 9));
273 BODY_20_31(29,B,C,D,E,T,A,X(13),W[13],W[15],X( 5),X(10));
274 BODY_20_31(30,A,B,C,D,E,T,X(14),W[14],X( 0),X( 6),X(11));
275 BODY_20_31(31,T,A,B,C,D,E,X(15),W[15],X( 1),X( 7),X(12));
276
277 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
278 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
279 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
280 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
281 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
282 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
283 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
284 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
285
286 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
287 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
288 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
289 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
290 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
291 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
292 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
293 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
294 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
295 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
296 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
297 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
298 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
299 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
300 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
301 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
302 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
303 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
304 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
305 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
306
307 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
308 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
309 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
310 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
311 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
312 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
313 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
314 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
315 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
316 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
317 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
318 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
319 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
320 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
321 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
322 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
323 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
324 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
325 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
326 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
327
328 c->h0=(c->h0+E)&0xffffffffL;
329 c->h1=(c->h1+T)&0xffffffffL;
330 c->h2=(c->h2+A)&0xffffffffL;
331 c->h3=(c->h3+B)&0xffffffffL;
332 c->h4=(c->h4+C)&0xffffffffL;
333
334 if (--num <= 0) break;
335
336 A=c->h0;
337 B=c->h1;
338 C=c->h2;
339 D=c->h3;
340 E=c->h4;
341
342 W+=SHA_LBLOCK;
343 }
344 }
345#endif
346
347#ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER
348void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num)
349 {
350 const unsigned char *data=p;
351 register unsigned long A,B,C,D,E,T,l;
352#ifndef MD32_XARRAY
353 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
354 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
355#else
356 SHA_LONG XX[16];
357#endif
358
359 A=c->h0;
360 B=c->h1;
361 C=c->h2;
362 D=c->h3;
363 E=c->h4;
364
365 for (;;)
366 {
367
368 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
369 BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l;
370 BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l;
371 BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l;
372 BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l;
373 BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l;
374 BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l;
375 BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l;
376 BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l;
377 BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l;
378 BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l;
379 BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l;
380 BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l;
381 BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l;
382 BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l;
383 BODY_00_15(14,E,T,A,B,C,D,X(14));
384 BODY_00_15(15,D,E,T,A,B,C,X(15));
385
386 BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13));
387 BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14));
388 BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15));
389 BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0));
390
391 BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1));
392 BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2));
393 BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3));
394 BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4));
395 BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5));
396 BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6));
397 BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7));
398 BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8));
399 BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9));
400 BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10));
401 BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11));
402 BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12));
403
404 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
405 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
406 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
407 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
408 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
409 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
410 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
411 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
412
413 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
414 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
415 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
416 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
417 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
418 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
419 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
420 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
421 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
422 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
423 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
424 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
425 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
426 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
427 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
428 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
429 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
430 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
431 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
432 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
433
434 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
435 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
436 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
437 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
438 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
439 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
440 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
441 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
442 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
443 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
444 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
445 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
446 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
447 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
448 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
449 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
450 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
451 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
452 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
453 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
454
455 c->h0=(c->h0+E)&0xffffffffL;
456 c->h1=(c->h1+T)&0xffffffffL;
457 c->h2=(c->h2+A)&0xffffffffL;
458 c->h3=(c->h3+B)&0xffffffffL;
459 c->h4=(c->h4+C)&0xffffffffL;
460
461 if (--num <= 0) break;
462
463 A=c->h0;
464 B=c->h1;
465 C=c->h2;
466 D=c->h3;
467 E=c->h4;
468
469 }
470 }
471#endif
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 58e9126339..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 searched 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(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(st->data);
280 Free(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 a615d9b4c9..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) ? (sk)->num:-1)
80#define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL)
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 33acc81f3f..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(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,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],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],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 8e18f3c2df..0000000000
--- a/src/lib/libcrypto/util/mkerr.pl
+++ /dev/null
@@ -1,519 +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 # First, read any existing reason string definitions:
288 my %err_reason_strings;
289 if (open(IN,"<$cfile")) {
290 while (<IN>) {
291 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
292 $err_reason_strings{$1} = $2;
293 }
294 }
295 close(IN);
296 }
297
298 my $hincf;
299 if($static) {
300 $hfile =~ /([^\/]+)$/;
301 $hincf = "<openssl/$1>";
302 } else {
303 $hincf = "\"$hfile\"";
304 }
305
306
307 open (OUT,">$cfile") || die "Can't open $cfile for writing";
308
309 print OUT <<"EOF";
310/* $cfile */
311/* ====================================================================
312 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
313 *
314 * Redistribution and use in source and binary forms, with or without
315 * modification, are permitted provided that the following conditions
316 * are met:
317 *
318 * 1. Redistributions of source code must retain the above copyright
319 * notice, this list of conditions and the following disclaimer.
320 *
321 * 2. Redistributions in binary form must reproduce the above copyright
322 * notice, this list of conditions and the following disclaimer in
323 * the documentation and/or other materials provided with the
324 * distribution.
325 *
326 * 3. All advertising materials mentioning features or use of this
327 * software must display the following acknowledgment:
328 * "This product includes software developed by the OpenSSL Project
329 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
330 *
331 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
332 * endorse or promote products derived from this software without
333 * prior written permission. For written permission, please contact
334 * openssl-core\@OpenSSL.org.
335 *
336 * 5. Products derived from this software may not be called "OpenSSL"
337 * nor may "OpenSSL" appear in their names without prior written
338 * permission of the OpenSSL Project.
339 *
340 * 6. Redistributions of any form whatsoever must retain the following
341 * acknowledgment:
342 * "This product includes software developed by the OpenSSL Project
343 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
344 *
345 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
346 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
347 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
348 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
349 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
350 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
351 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
352 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
353 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
354 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
355 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
356 * OF THE POSSIBILITY OF SUCH DAMAGE.
357 * ====================================================================
358 *
359 * This product includes cryptographic software written by Eric Young
360 * (eay\@cryptsoft.com). This product includes software written by Tim
361 * Hudson (tjh\@cryptsoft.com).
362 *
363 */
364
365/* NOTE: this file was auto generated by the mkerr.pl script: any changes
366 * made to it will be overwritten when the script next updates this file,
367 * only reason strings will be preserved.
368 */
369
370#include <stdio.h>
371#include <openssl/err.h>
372#include $hincf
373
374/* BEGIN ERROR CODES */
375#ifndef NO_ERR
376static ERR_STRING_DATA ${lib}_str_functs[]=
377 {
378EOF
379 # Add each function code: if a function name is found then use it.
380 foreach $i (@function) {
381 my $fn;
382 $i =~ /^${lib}_F_(\S+)$/;
383 $fn = $1;
384 if(exists $ftrans{$fn}) {
385 $fn = $ftrans{$fn};
386 }
387 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
388 }
389 print OUT <<"EOF";
390{0,NULL}
391 };
392
393static ERR_STRING_DATA ${lib}_str_reasons[]=
394 {
395EOF
396 # Add each reason code.
397 foreach $i (@reasons) {
398 my $rn;
399 my $nspc = 0;
400 if (exists $err_reason_strings{$i}) {
401 $rn = $err_reason_strings{$i};
402 } else {
403 $i =~ /^${lib}_R_(\S+)$/;
404 $rn = $1;
405 $rn =~ tr/_[A-Z]/ [a-z]/;
406 }
407 $nspc = 40 - length($i) unless length($i) > 40;
408 $nspc = " " x $nspc;
409 print OUT "{${i}${nspc},\"$rn\"},\n";
410 }
411if($static) {
412 print OUT <<"EOF";
413{0,NULL}
414 };
415
416#endif
417
418void ERR_load_${lib}_strings(void)
419 {
420 static int init=1;
421
422 if (init)
423 {
424 init=0;
425#ifndef NO_ERR
426 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
427 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
428#endif
429
430 }
431 }
432EOF
433} else {
434 print OUT <<"EOF";
435{0,NULL}
436 };
437
438#endif
439
440#ifdef ${lib}_LIB_NAME
441static ERR_STRING_DATA ${lib}_lib_name[]=
442 {
443{0 ,${lib}_LIB_NAME},
444{0,NULL}
445 };
446#endif
447
448
449int ${lib}_lib_error_code=0;
450
451void ERR_load_${lib}_strings(void)
452 {
453 static int init=1;
454
455 if (${lib}_lib_error_code == 0)
456 ${lib}_lib_error_code=ERR_get_next_error_library();
457
458 if (init)
459 {
460 init=0;
461#ifndef NO_ERR
462 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
463 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
464#endif
465
466#ifdef ${lib}_LIB_NAME
467 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
468 ERR_load_strings(0,${lib}_lib_name);
469#endif
470 }
471 }
472
473void ERR_${lib}_error(int function, int reason, char *file, int line)
474 {
475 if (${lib}_lib_error_code == 0)
476 ${lib}_lib_error_code=ERR_get_next_error_library();
477 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
478 }
479EOF
480
481}
482
483 close OUT;
484 undef %err_reason_strings;
485}
486
487if($debug && defined(%notrans)) {
488 print STDERR "The following function codes were not translated:\n";
489 foreach(sort keys %notrans)
490 {
491 print STDERR "$_\n";
492 }
493}
494
495# Make a list of unreferenced function and reason codes
496
497foreach (keys %fcodes) {
498 push (@funref, $_) unless exists $ufcodes{$_};
499}
500
501foreach (keys %rcodes) {
502 push (@runref, $_) unless exists $urcodes{$_};
503}
504
505if($debug && defined(@funref) ) {
506 print STDERR "The following function codes were not referenced:\n";
507 foreach(sort @funref)
508 {
509 print STDERR "$_\n";
510 }
511}
512
513if($debug && defined(@runref) ) {
514 print STDERR "The following reason codes were not referenced:\n";
515 foreach(sort @runref)
516 {
517 print STDERR "$_\n";
518 }
519}
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c
deleted file mode 100644
index 14d12c56bd..0000000000
--- a/src/lib/libcrypto/x509/by_dir.c
+++ /dev/null
@@ -1,349 +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
63#include "cryptlib.h"
64
65#ifndef NO_SYS_TYPES_H
66# include <sys/types.h>
67#endif
68#ifdef MAC_OS_pre_X
69# include <stat.h>
70#else
71# include <sys/stat.h>
72#endif
73
74#include <openssl/lhash.h>
75#include <openssl/x509.h>
76
77typedef struct lookup_dir_st
78 {
79 BUF_MEM *buffer;
80 int num_dirs;
81 char **dirs;
82 int *dirs_type;
83 int num_dirs_alloced;
84 } BY_DIR;
85
86static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
87 char **ret);
88static int new_dir(X509_LOOKUP *lu);
89static void free_dir(X509_LOOKUP *lu);
90static int add_cert_dir(BY_DIR *ctx,const char *dir,int type);
91static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name,
92 X509_OBJECT *ret);
93X509_LOOKUP_METHOD x509_dir_lookup=
94 {
95 "Load certs from files in a directory",
96 new_dir, /* new */
97 free_dir, /* free */
98 NULL, /* init */
99 NULL, /* shutdown */
100 dir_ctrl, /* ctrl */
101 get_cert_by_subject, /* get_by_subject */
102 NULL, /* get_by_issuer_serial */
103 NULL, /* get_by_fingerprint */
104 NULL, /* get_by_alias */
105 };
106
107X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void)
108 {
109 return(&x509_dir_lookup);
110 }
111
112static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
113 char **retp)
114 {
115 int ret=0;
116 BY_DIR *ld;
117 char *dir;
118
119 ld=(BY_DIR *)ctx->method_data;
120
121 switch (cmd)
122 {
123 case X509_L_ADD_DIR:
124 if (argl == X509_FILETYPE_DEFAULT)
125 {
126 ret=add_cert_dir(ld,X509_get_default_cert_dir(),
127 X509_FILETYPE_PEM);
128 if (!ret)
129 {
130 X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR);
131 }
132 else
133 {
134 dir=(char *)Getenv(X509_get_default_cert_dir_env());
135 ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
136 }
137 }
138 else
139 ret=add_cert_dir(ld,argp,(int)argl);
140 break;
141 }
142 return(ret);
143 }
144
145static int new_dir(X509_LOOKUP *lu)
146 {
147 BY_DIR *a;
148
149 if ((a=(BY_DIR *)Malloc(sizeof(BY_DIR))) == NULL)
150 return(0);
151 if ((a->buffer=BUF_MEM_new()) == NULL)
152 {
153 Free(a);
154 return(0);
155 }
156 a->num_dirs=0;
157 a->dirs=NULL;
158 a->dirs_type=NULL;
159 a->num_dirs_alloced=0;
160 lu->method_data=(char *)a;
161 return(1);
162 }
163
164static void free_dir(X509_LOOKUP *lu)
165 {
166 BY_DIR *a;
167 int i;
168
169 a=(BY_DIR *)lu->method_data;
170 for (i=0; i<a->num_dirs; i++)
171 if (a->dirs[i] != NULL) Free(a->dirs[i]);
172 if (a->dirs != NULL) Free(a->dirs);
173 if (a->dirs_type != NULL) Free(a->dirs_type);
174 if (a->buffer != NULL) BUF_MEM_free(a->buffer);
175 Free(a);
176 }
177
178static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
179 {
180 int j,len;
181 int *ip;
182 const char *s,*ss,*p;
183 char **pp;
184
185 if (dir == NULL || !*dir)
186 {
187 X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY);
188 return 0;
189 }
190
191 s=dir;
192 p=s;
193 for (;;)
194 {
195 if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0'))
196 {
197 ss=s;
198 s=p+1;
199 len=(int)(p-ss);
200 if (len == 0) continue;
201 for (j=0; j<ctx->num_dirs; j++)
202 if (strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
203 continue;
204 if (ctx->num_dirs_alloced < (ctx->num_dirs+1))
205 {
206 ctx->num_dirs_alloced+=10;
207 pp=(char **)Malloc(ctx->num_dirs_alloced*
208 sizeof(char *));
209 ip=(int *)Malloc(ctx->num_dirs_alloced*
210 sizeof(int));
211 if ((pp == NULL) || (ip == NULL))
212 {
213 X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE);
214 return(0);
215 }
216 memcpy(pp,ctx->dirs,(ctx->num_dirs_alloced-10)*
217 sizeof(char *));
218 memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)*
219 sizeof(int));
220 if (ctx->dirs != NULL)
221 Free(ctx->dirs);
222 if (ctx->dirs_type != NULL)
223 Free(ctx->dirs_type);
224 ctx->dirs=pp;
225 ctx->dirs_type=ip;
226 }
227 ctx->dirs_type[ctx->num_dirs]=type;
228 ctx->dirs[ctx->num_dirs]=(char *)Malloc((unsigned int)len+1);
229 if (ctx->dirs[ctx->num_dirs] == NULL) return(0);
230 strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len);
231 ctx->dirs[ctx->num_dirs][len]='\0';
232 ctx->num_dirs++;
233 }
234 if (*p == '\0') break;
235 p++;
236 }
237 return(1);
238 }
239
240static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
241 X509_OBJECT *ret)
242 {
243 BY_DIR *ctx;
244 union {
245 struct {
246 X509 st_x509;
247 X509_CINF st_x509_cinf;
248 } x509;
249 struct {
250 X509_CRL st_crl;
251 X509_CRL_INFO st_crl_info;
252 } crl;
253 } data;
254 int ok=0;
255 int i,j,k;
256 unsigned long h;
257 BUF_MEM *b=NULL;
258 struct stat st;
259 X509_OBJECT stmp,*tmp;
260 const char *postfix="";
261
262 if (name == NULL) return(0);
263
264 stmp.type=type;
265 if (type == X509_LU_X509)
266 {
267 data.x509.st_x509.cert_info= &data.x509.st_x509_cinf;
268 data.x509.st_x509_cinf.subject=name;
269 stmp.data.x509= &data.x509.st_x509;
270 postfix="";
271 }
272 else if (type == X509_LU_CRL)
273 {
274 data.crl.st_crl.crl= &data.crl.st_crl_info;
275 data.crl.st_crl_info.issuer=name;
276 stmp.data.crl= &data.crl.st_crl;
277 postfix="r";
278 }
279 else
280 {
281 X509err(X509_F_GET_CERT_BY_SUBJECT,X509_R_WRONG_LOOKUP_TYPE);
282 goto finish;
283 }
284
285 if ((b=BUF_MEM_new()) == NULL)
286 {
287 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_BUF_LIB);
288 goto finish;
289 }
290
291 ctx=(BY_DIR *)xl->method_data;
292
293 h=X509_NAME_hash(name);
294 for (i=0; i<ctx->num_dirs; i++)
295 {
296 j=strlen(ctx->dirs[i])+1+8+6+1+1;
297 if (!BUF_MEM_grow(b,j))
298 {
299 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE);
300 goto finish;
301 }
302 k=0;
303 for (;;)
304 {
305 sprintf(b->data,"%s/%08lx.%s%d",ctx->dirs[i],h,
306 postfix,k);
307 k++;
308 if (stat(b->data,&st) < 0)
309 break;
310 /* found one. */
311 if (type == X509_LU_X509)
312 {
313 if ((X509_load_cert_file(xl,b->data,
314 ctx->dirs_type[i])) == 0)
315 break;
316 }
317 else if (type == X509_LU_CRL)
318 {
319 if ((X509_load_crl_file(xl,b->data,
320 ctx->dirs_type[i])) == 0)
321 break;
322 }
323 /* else case will caught higher up */
324 }
325
326 /* we have added it to the cache so now pull
327 * it out again */
328 CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE);
329 tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs,&stmp);
330 CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
331
332 if (tmp != NULL)
333 {
334 ok=1;
335 ret->type=tmp->type;
336 memcpy(&ret->data,&tmp->data,sizeof(ret->data));
337 /* If we were going to up the reference count,
338 * we would need to do it on a perl 'type'
339 * basis */
340 /* CRYPTO_add(&tmp->data.x509->references,1,
341 CRYPTO_LOCK_X509);*/
342 goto finish;
343 }
344 }
345finish:
346 if (b != NULL) BUF_MEM_free(b);
347 return(ok);
348 }
349
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c
deleted file mode 100644
index 78e9240a8d..0000000000
--- a/src/lib/libcrypto/x509/by_file.c
+++ /dev/null
@@ -1,298 +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
63#include "cryptlib.h"
64#include <openssl/lhash.h>
65#include <openssl/buffer.h>
66#include <openssl/x509.h>
67#include <openssl/pem.h>
68
69#ifndef NO_STDIO
70
71static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
72 long argl, char **ret);
73X509_LOOKUP_METHOD x509_file_lookup=
74 {
75 "Load file into cache",
76 NULL, /* new */
77 NULL, /* free */
78 NULL, /* init */
79 NULL, /* shutdown */
80 by_file_ctrl, /* ctrl */
81 NULL, /* get_by_subject */
82 NULL, /* get_by_issuer_serial */
83 NULL, /* get_by_fingerprint */
84 NULL, /* get_by_alias */
85 };
86
87X509_LOOKUP_METHOD *X509_LOOKUP_file(void)
88 {
89 return(&x509_file_lookup);
90 }
91
92static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
93 char **ret)
94 {
95 int ok=0;
96 char *file;
97
98 switch (cmd)
99 {
100 case X509_L_FILE_LOAD:
101 if (argl == X509_FILETYPE_DEFAULT)
102 {
103 ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(),
104 X509_FILETYPE_PEM) != 0);
105 if (!ok)
106 {
107 X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS);
108 }
109 else
110 {
111 file=(char *)Getenv(X509_get_default_cert_file_env());
112 ok = (X509_load_cert_crl_file(ctx,file,
113 X509_FILETYPE_PEM) != 0);
114 }
115 }
116 else
117 {
118 if(argl == X509_FILETYPE_PEM)
119 ok = (X509_load_cert_crl_file(ctx,argp,
120 X509_FILETYPE_PEM) != 0);
121 else
122 ok = (X509_load_cert_file(ctx,argp,(int)argl) != 0);
123 }
124 break;
125 }
126 return(ok);
127 }
128
129int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
130 {
131 int ret=0;
132 BIO *in=NULL;
133 int i,count=0;
134 X509 *x=NULL;
135
136 if (file == NULL) return(1);
137 in=BIO_new(BIO_s_file_internal());
138
139 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
140 {
141 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB);
142 goto err;
143 }
144
145 if (type == X509_FILETYPE_PEM)
146 {
147 for (;;)
148 {
149 x=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL);
150 if (x == NULL)
151 {
152 if ((ERR_GET_REASON(ERR_peek_error()) ==
153 PEM_R_NO_START_LINE) && (count > 0))
154 {
155 ERR_clear_error();
156 break;
157 }
158 else
159 {
160 X509err(X509_F_X509_LOAD_CERT_FILE,
161 ERR_R_PEM_LIB);
162 goto err;
163 }
164 }
165 i=X509_STORE_add_cert(ctx->store_ctx,x);
166 if (!i) goto err;
167 count++;
168 X509_free(x);
169 x=NULL;
170 }
171 ret=count;
172 }
173 else if (type == X509_FILETYPE_ASN1)
174 {
175 x=d2i_X509_bio(in,NULL);
176 if (x == NULL)
177 {
178 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB);
179 goto err;
180 }
181 i=X509_STORE_add_cert(ctx->store_ctx,x);
182 if (!i) goto err;
183 ret=i;
184 }
185 else
186 {
187 X509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE);
188 goto err;
189 }
190err:
191 if (x != NULL) X509_free(x);
192 if (in != NULL) BIO_free(in);
193 return(ret);
194 }
195
196int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
197 {
198 int ret=0;
199 BIO *in=NULL;
200 int i,count=0;
201 X509_CRL *x=NULL;
202
203 if (file == NULL) return(1);
204 in=BIO_new(BIO_s_file_internal());
205
206 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
207 {
208 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_SYS_LIB);
209 goto err;
210 }
211
212 if (type == X509_FILETYPE_PEM)
213 {
214 for (;;)
215 {
216 x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);
217 if (x == NULL)
218 {
219 if ((ERR_GET_REASON(ERR_peek_error()) ==
220 PEM_R_NO_START_LINE) && (count > 0))
221 {
222 ERR_clear_error();
223 break;
224 }
225 else
226 {
227 X509err(X509_F_X509_LOAD_CRL_FILE,
228 ERR_R_PEM_LIB);
229 goto err;
230 }
231 }
232 i=X509_STORE_add_crl(ctx->store_ctx,x);
233 if (!i) goto err;
234 count++;
235 X509_CRL_free(x);
236 x=NULL;
237 }
238 ret=count;
239 }
240 else if (type == X509_FILETYPE_ASN1)
241 {
242 x=d2i_X509_CRL_bio(in,NULL);
243 if (x == NULL)
244 {
245 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_ASN1_LIB);
246 goto err;
247 }
248 i=X509_STORE_add_crl(ctx->store_ctx,x);
249 if (!i) goto err;
250 ret=i;
251 }
252 else
253 {
254 X509err(X509_F_X509_LOAD_CRL_FILE,X509_R_BAD_X509_FILETYPE);
255 goto err;
256 }
257err:
258 if (x != NULL) X509_CRL_free(x);
259 if (in != NULL) BIO_free(in);
260 return(ret);
261 }
262
263int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type)
264{
265 STACK_OF(X509_INFO) *inf;
266 X509_INFO *itmp;
267 BIO *in;
268 int i, count = 0;
269 if(type != X509_FILETYPE_PEM)
270 return X509_load_cert_file(ctx, file, type);
271 in = BIO_new_file(file, "r");
272 if(!in) {
273 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_SYS_LIB);
274 return 0;
275 }
276 inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
277 BIO_free(in);
278 if(!inf) {
279 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB);
280 return 0;
281 }
282 for(i = 0; i < sk_X509_INFO_num(inf); i++) {
283 itmp = sk_X509_INFO_value(inf, i);
284 if(itmp->x509) {
285 X509_STORE_add_cert(ctx->store_ctx, itmp->x509);
286 count++;
287 } else if(itmp->crl) {
288 X509_STORE_add_crl(ctx->store_ctx, itmp->crl);
289 count++;
290 }
291 }
292 sk_X509_INFO_pop_free(inf, X509_INFO_free);
293 return count;
294}
295
296
297#endif /* NO_STDIO */
298
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
deleted file mode 100644
index 0192272e7c..0000000000
--- a/src/lib/libcrypto/x509/x509.h
+++ /dev/null
@@ -1,1204 +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 struct v3_ext_method *method; /* V3 method to use */
180 void *ext_val; /* extension value */
181 } X509_EXTENSION;
182
183DECLARE_STACK_OF(X509_EXTENSION)
184DECLARE_ASN1_SET_OF(X509_EXTENSION)
185
186/* a sequence of these are used */
187typedef struct x509_attributes_st
188 {
189 ASN1_OBJECT *object;
190 int set; /* 1 for a set, 0 for a single item (which is wrong) */
191 union {
192 char *ptr;
193/* 1 */ STACK_OF(ASN1_TYPE) *set;
194/* 0 */ ASN1_TYPE *single;
195 } value;
196 } X509_ATTRIBUTE;
197
198DECLARE_STACK_OF(X509_ATTRIBUTE)
199DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)
200
201typedef struct X509_req_info_st
202 {
203 ASN1_INTEGER *version;
204 X509_NAME *subject;
205 X509_PUBKEY *pubkey;
206 /* d=2 hl=2 l= 0 cons: cont: 00 */
207 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
208 int req_kludge;
209 } X509_REQ_INFO;
210
211typedef struct X509_req_st
212 {
213 X509_REQ_INFO *req_info;
214 X509_ALGOR *sig_alg;
215 ASN1_BIT_STRING *signature;
216 int references;
217 } X509_REQ;
218
219typedef struct x509_cinf_st
220 {
221 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
222 ASN1_INTEGER *serialNumber;
223 X509_ALGOR *signature;
224 X509_NAME *issuer;
225 X509_VAL *validity;
226 X509_NAME *subject;
227 X509_PUBKEY *key;
228 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
229 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
230 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
231 } X509_CINF;
232
233/* This stuff is certificate "auxiliary info"
234 * it contains details which are useful in certificate
235 * stores and databases. When used this is tagged onto
236 * the end of the certificate itself
237 */
238
239typedef struct x509_cert_aux_st
240 {
241 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
242 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
243 ASN1_UTF8STRING *alias; /* "friendly name" */
244 ASN1_OCTET_STRING *keyid; /* key id of private key */
245 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
246 } X509_CERT_AUX;
247
248typedef struct x509_st
249 {
250 X509_CINF *cert_info;
251 X509_ALGOR *sig_alg;
252 ASN1_BIT_STRING *signature;
253 int valid;
254 int references;
255 char *name;
256 CRYPTO_EX_DATA ex_data;
257 /* These contain copies of various extension values */
258 long ex_pathlen;
259 unsigned long ex_flags;
260 unsigned long ex_kusage;
261 unsigned long ex_xkusage;
262 unsigned long ex_nscert;
263#ifndef NO_SHA
264 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
265#endif
266 X509_CERT_AUX *aux;
267 } X509;
268
269DECLARE_STACK_OF(X509)
270DECLARE_ASN1_SET_OF(X509)
271
272/* This is used for a table of trust checking functions */
273
274typedef struct x509_trust_st {
275 int trust;
276 int flags;
277 int (*check_trust)(struct x509_trust_st *, X509 *, int);
278 char *name;
279 int arg1;
280 void *arg2;
281} X509_TRUST;
282
283DECLARE_STACK_OF(X509_TRUST)
284
285/* standard trust ids */
286
287#define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */
288
289#define X509_TRUST_COMPAT 1
290#define X509_TRUST_SSL_CLIENT 2
291#define X509_TRUST_SSL_SERVER 3
292#define X509_TRUST_EMAIL 4
293#define X509_TRUST_OBJECT_SIGN 5
294
295/* Keep these up to date! */
296#define X509_TRUST_MIN 1
297#define X509_TRUST_MAX 5
298
299
300/* trust_flags values */
301#define X509_TRUST_DYNAMIC 1
302#define X509_TRUST_DYNAMIC_NAME 2
303
304/* check_trust return codes */
305
306#define X509_TRUST_TRUSTED 1
307#define X509_TRUST_REJECTED 2
308#define X509_TRUST_UNTRUSTED 3
309
310typedef struct X509_revoked_st
311 {
312 ASN1_INTEGER *serialNumber;
313 ASN1_UTCTIME *revocationDate;
314 STACK_OF(X509_EXTENSION) /* optional */ *extensions;
315 int sequence; /* load sequence */
316 } X509_REVOKED;
317
318DECLARE_STACK_OF(X509_REVOKED)
319DECLARE_ASN1_SET_OF(X509_REVOKED)
320
321typedef struct X509_crl_info_st
322 {
323 ASN1_INTEGER *version;
324 X509_ALGOR *sig_alg;
325 X509_NAME *issuer;
326 ASN1_UTCTIME *lastUpdate;
327 ASN1_UTCTIME *nextUpdate;
328 STACK_OF(X509_REVOKED) *revoked;
329 STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
330 } X509_CRL_INFO;
331
332typedef struct X509_crl_st
333 {
334 /* actual signature */
335 X509_CRL_INFO *crl;
336 X509_ALGOR *sig_alg;
337 ASN1_BIT_STRING *signature;
338 int references;
339 } X509_CRL;
340
341DECLARE_STACK_OF(X509_CRL)
342DECLARE_ASN1_SET_OF(X509_CRL)
343
344typedef struct private_key_st
345 {
346 int version;
347 /* The PKCS#8 data types */
348 X509_ALGOR *enc_algor;
349 ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */
350
351 /* When decrypted, the following will not be NULL */
352 EVP_PKEY *dec_pkey;
353
354 /* used to encrypt and decrypt */
355 int key_length;
356 char *key_data;
357 int key_free; /* true if we should auto free key_data */
358
359 /* expanded version of 'enc_algor' */
360 EVP_CIPHER_INFO cipher;
361
362 int references;
363 } X509_PKEY;
364
365#ifdef HEADER_ENVELOPE_H
366typedef struct X509_info_st
367 {
368 X509 *x509;
369 X509_CRL *crl;
370 X509_PKEY *x_pkey;
371
372 EVP_CIPHER_INFO enc_cipher;
373 int enc_len;
374 char *enc_data;
375
376 int references;
377 } X509_INFO;
378
379DECLARE_STACK_OF(X509_INFO)
380#endif
381
382/* The next 2 structures and their 8 routines were sent to me by
383 * Pat Richard <patr@x509.com> and are used to manipulate
384 * Netscapes spki structures - useful if you are writing a CA web page
385 */
386typedef struct Netscape_spkac_st
387 {
388 X509_PUBKEY *pubkey;
389 ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */
390 } NETSCAPE_SPKAC;
391
392typedef struct Netscape_spki_st
393 {
394 NETSCAPE_SPKAC *spkac; /* signed public key and challenge */
395 X509_ALGOR *sig_algor;
396 ASN1_BIT_STRING *signature;
397 } NETSCAPE_SPKI;
398
399/* Netscape certificate sequence structure */
400typedef struct Netscape_certificate_sequence
401 {
402 ASN1_OBJECT *type;
403 STACK_OF(X509) *certs;
404 } NETSCAPE_CERT_SEQUENCE;
405
406typedef struct CBCParameter_st
407 {
408 unsigned char iv[8];
409 } CBC_PARAM;
410
411/* Password based encryption structure */
412
413typedef struct PBEPARAM_st {
414ASN1_OCTET_STRING *salt;
415ASN1_INTEGER *iter;
416} PBEPARAM;
417
418/* Password based encryption V2 structures */
419
420typedef struct PBE2PARAM_st {
421X509_ALGOR *keyfunc;
422X509_ALGOR *encryption;
423} PBE2PARAM;
424
425typedef struct PBKDF2PARAM_st {
426ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */
427ASN1_INTEGER *iter;
428ASN1_INTEGER *keylength;
429X509_ALGOR *prf;
430} PBKDF2PARAM;
431
432
433/* PKCS#8 private key info structure */
434
435typedef struct pkcs8_priv_key_info_st
436 {
437 int broken; /* Flag for various broken formats */
438#define PKCS8_OK 0
439#define PKCS8_NO_OCTET 1
440#define PKCS8_EMBEDDED_PARAM 2
441#define PKCS8_NS_DB 3
442 ASN1_INTEGER *version;
443 X509_ALGOR *pkeyalg;
444 ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
445 STACK_OF(X509_ATTRIBUTE) *attributes;
446 } PKCS8_PRIV_KEY_INFO;
447
448#include <openssl/x509_vfy.h>
449#include <openssl/pkcs7.h>
450
451#ifdef SSLEAY_MACROS
452#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
453 a->signature,(char *)a->cert_info,r)
454#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
455 a->sig_alg,a->signature,(char *)a->req_info,r)
456#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
457 a->sig_alg, a->signature,(char *)a->crl,r)
458
459#define X509_sign(x,pkey,md) \
460 ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
461 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
462#define X509_REQ_sign(x,pkey,md) \
463 ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
464 x->signature, (char *)x->req_info,pkey,md)
465#define X509_CRL_sign(x,pkey,md) \
466 ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
467 x->signature, (char *)x->crl,pkey,md)
468#define NETSCAPE_SPKI_sign(x,pkey,md) \
469 ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
470 x->signature, (char *)x->spkac,pkey,md)
471
472#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
473 (char *(*)())d2i_X509,(char *)x509)
474#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
475 (int (*)())i2d_X509_ATTRIBUTE, \
476 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
477#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
478 (int (*)())i2d_X509_EXTENSION, \
479 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
480#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
481 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
482#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
483#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
484 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
485#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
486
487#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
488 (char *(*)())d2i_X509_CRL,(char *)crl)
489#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
490 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
491 (unsigned char **)(crl))
492#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
493 (unsigned char *)crl)
494#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
495 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
496 (unsigned char **)(crl))
497#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
498 (unsigned char *)crl)
499
500#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
501 (char *(*)())d2i_PKCS7,(char *)p7)
502#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
503 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
504 (unsigned char **)(p7))
505#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
506 (unsigned char *)p7)
507#define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
508 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
509 (unsigned char **)(p7))
510#define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
511 (unsigned char *)p7)
512
513#define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
514 (char *(*)())d2i_X509_REQ,(char *)req)
515#define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
516 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
517 (unsigned char **)(req))
518#define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
519 (unsigned char *)req)
520#define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
521 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
522 (unsigned char **)(req))
523#define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
524 (unsigned char *)req)
525
526#define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
527 (char *(*)())d2i_RSAPublicKey,(char *)rsa)
528#define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
529 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
530
531#define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
532 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
533 (unsigned char **)(rsa))
534#define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
535 (unsigned char *)rsa)
536#define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
537 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
538 (unsigned char **)(rsa))
539#define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
540 (unsigned char *)rsa)
541
542#define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
543 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
544 (unsigned char **)(rsa))
545#define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
546 (unsigned char *)rsa)
547#define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
548 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
549 (unsigned char **)(rsa))
550#define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
551 (unsigned char *)rsa)
552
553#define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
554 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
555 (unsigned char **)(dsa))
556#define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
557 (unsigned char *)dsa)
558#define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
559 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
560 (unsigned char **)(dsa))
561#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
562 (unsigned char *)dsa)
563
564#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
565 (char *(*)())d2i_X509_ALGOR,(char *)xn)
566
567#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
568 (char *(*)())d2i_X509_NAME,(char *)xn)
569#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
570 (int (*)())i2d_X509_NAME_ENTRY, \
571 (char *(*)())d2i_X509_NAME_ENTRY,\
572 (char *)ne)
573
574#define X509_digest(data,type,md,len) \
575 ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
576#define X509_NAME_digest(data,type,md,len) \
577 ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
578#ifndef PKCS7_ISSUER_AND_SERIAL_digest
579#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
580 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
581 (char *)data,md,len)
582#endif
583#endif
584
585#define X509_EXT_PACK_UNKNOWN 1
586#define X509_EXT_PACK_STRING 2
587
588#define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
589/* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
590#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
591#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
592#define X509_extract_key(x) X509_get_pubkey(x) /*****/
593#define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
594#define X509_REQ_get_subject_name(x) ((x)->req_info->subject)
595#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
596#define X509_name_cmp(a,b) X509_NAME_cmp((a),(b))
597#define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
598
599#define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
600#define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
601#define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
602#define X509_CRL_get_issuer(x) ((x)->crl->issuer)
603#define X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
604
605/* This one is only used so that a binary form can output, as in
606 * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
607#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
608
609
610const char *X509_verify_cert_error_string(long n);
611
612#ifndef SSLEAY_MACROS
613#ifdef HEADER_ENVELOPE_H
614int X509_verify(X509 *a, EVP_PKEY *r);
615
616int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
617int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
618int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
619
620NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len);
621char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x);
622EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x);
623int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);
624
625int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);
626
627int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
628int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
629int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
630int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
631
632int X509_digest(X509 *data,const EVP_MD *type,unsigned char *md,unsigned int *len);
633int X509_NAME_digest(X509_NAME *data,const EVP_MD *type,
634 unsigned char *md,unsigned int *len);
635#endif
636
637#ifndef NO_FP_API
638X509 *d2i_X509_fp(FILE *fp, X509 **x509);
639int i2d_X509_fp(FILE *fp,X509 *x509);
640X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
641int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
642X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
643int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
644#ifndef NO_RSA
645RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
646int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
647RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
648int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
649RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa);
650int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa);
651#endif
652#ifndef NO_DSA
653DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);
654int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
655DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
656int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
657#endif
658X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
659int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
660PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
661 PKCS8_PRIV_KEY_INFO **p8inf);
662int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
663int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);
664int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
665EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
666#endif
667
668#ifdef HEADER_BIO_H
669X509 *d2i_X509_bio(BIO *bp,X509 **x509);
670int i2d_X509_bio(BIO *bp,X509 *x509);
671X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
672int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
673X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
674int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
675#ifndef NO_RSA
676RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
677int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
678RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
679int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
680RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);
681int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);
682#endif
683#ifndef NO_DSA
684DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);
685int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
686DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
687int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
688#endif
689X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
690int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
691PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
692 PKCS8_PRIV_KEY_INFO **p8inf);
693int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
694int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);
695int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);
696EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
697#endif
698
699X509 *X509_dup(X509 *x509);
700X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
701X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
702X509_CRL *X509_CRL_dup(X509_CRL *crl);
703X509_REQ *X509_REQ_dup(X509_REQ *req);
704X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
705X509_NAME *X509_NAME_dup(X509_NAME *xn);
706X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
707#ifndef NO_RSA
708RSA *RSAPublicKey_dup(RSA *rsa);
709RSA *RSAPrivateKey_dup(RSA *rsa);
710#endif
711
712#endif /* !SSLEAY_MACROS */
713
714int X509_cmp_current_time(ASN1_UTCTIME *s);
715ASN1_UTCTIME * X509_gmtime_adj(ASN1_UTCTIME *s, long adj);
716
717const char * X509_get_default_cert_area(void );
718const char * X509_get_default_cert_dir(void );
719const char * X509_get_default_cert_file(void );
720const char * X509_get_default_cert_dir_env(void );
721const char * X509_get_default_cert_file_env(void );
722const char * X509_get_default_private_dir(void );
723
724X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
725X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
726void ERR_load_X509_strings(void );
727
728X509_ALGOR * X509_ALGOR_new(void );
729void X509_ALGOR_free(X509_ALGOR *a);
730int i2d_X509_ALGOR(X509_ALGOR *a,unsigned char **pp);
731X509_ALGOR * d2i_X509_ALGOR(X509_ALGOR **a,unsigned char **pp,
732 long length);
733
734X509_VAL * X509_VAL_new(void );
735void X509_VAL_free(X509_VAL *a);
736int i2d_X509_VAL(X509_VAL *a,unsigned char **pp);
737X509_VAL * d2i_X509_VAL(X509_VAL **a,unsigned char **pp,
738 long length);
739
740X509_PUBKEY * X509_PUBKEY_new(void );
741void X509_PUBKEY_free(X509_PUBKEY *a);
742int i2d_X509_PUBKEY(X509_PUBKEY *a,unsigned char **pp);
743X509_PUBKEY * d2i_X509_PUBKEY(X509_PUBKEY **a,unsigned char **pp,
744 long length);
745int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
746EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
747int X509_get_pubkey_parameters(EVP_PKEY *pkey,
748 STACK_OF(X509) *chain);
749int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
750EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,unsigned char **pp,
751 long length);
752#ifndef NO_RSA
753int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
754RSA * d2i_RSA_PUBKEY(RSA **a,unsigned char **pp,
755 long length);
756#endif
757#ifndef NO_DSA
758int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
759DSA * d2i_DSA_PUBKEY(DSA **a,unsigned char **pp,
760 long length);
761#endif
762
763X509_SIG * X509_SIG_new(void );
764void X509_SIG_free(X509_SIG *a);
765int i2d_X509_SIG(X509_SIG *a,unsigned char **pp);
766X509_SIG * d2i_X509_SIG(X509_SIG **a,unsigned char **pp,long length);
767
768X509_REQ_INFO *X509_REQ_INFO_new(void);
769void X509_REQ_INFO_free(X509_REQ_INFO *a);
770int i2d_X509_REQ_INFO(X509_REQ_INFO *a,unsigned char **pp);
771X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a,unsigned char **pp,
772 long length);
773
774X509_REQ * X509_REQ_new(void);
775void X509_REQ_free(X509_REQ *a);
776int i2d_X509_REQ(X509_REQ *a,unsigned char **pp);
777X509_REQ * d2i_X509_REQ(X509_REQ **a,unsigned char **pp,long length);
778
779X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
780void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
781int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp);
782X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp,
783 long length);
784X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
785
786
787X509_EXTENSION *X509_EXTENSION_new(void );
788void X509_EXTENSION_free(X509_EXTENSION *a);
789int i2d_X509_EXTENSION(X509_EXTENSION *a,unsigned char **pp);
790X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a,unsigned char **pp,
791 long length);
792
793X509_NAME_ENTRY *X509_NAME_ENTRY_new(void);
794void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a);
795int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a,unsigned char **pp);
796X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a,unsigned char **pp,
797 long length);
798
799X509_NAME * X509_NAME_new(void);
800void X509_NAME_free(X509_NAME *a);
801int i2d_X509_NAME(X509_NAME *a,unsigned char **pp);
802X509_NAME * d2i_X509_NAME(X509_NAME **a,unsigned char **pp,long length);
803int X509_NAME_set(X509_NAME **xn, X509_NAME *name);
804
805
806X509_CINF * X509_CINF_new(void);
807void X509_CINF_free(X509_CINF *a);
808int i2d_X509_CINF(X509_CINF *a,unsigned char **pp);
809X509_CINF * d2i_X509_CINF(X509_CINF **a,unsigned char **pp,long length);
810
811X509 * X509_new(void);
812void X509_free(X509 *a);
813int i2d_X509(X509 *a,unsigned char **pp);
814X509 * d2i_X509(X509 **a,unsigned char **pp,long length);
815int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
816 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
817int X509_set_ex_data(X509 *r, int idx, void *arg);
818void *X509_get_ex_data(X509 *r, int idx);
819int i2d_X509_AUX(X509 *a,unsigned char **pp);
820X509 * d2i_X509_AUX(X509 **a,unsigned char **pp,long length);
821
822X509_CERT_AUX * X509_CERT_AUX_new(void);
823void X509_CERT_AUX_free(X509_CERT_AUX *a);
824int i2d_X509_CERT_AUX(X509_CERT_AUX *a,unsigned char **pp);
825X509_CERT_AUX * d2i_X509_CERT_AUX(X509_CERT_AUX **a,unsigned char **pp,
826 long length);
827int X509_alias_set1(X509 *x, unsigned char *name, int len);
828unsigned char * X509_alias_get0(X509 *x, int *len);
829int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);
830int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
831int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj);
832void X509_trust_clear(X509 *x);
833void X509_reject_clear(X509 *x);
834
835X509_REVOKED * X509_REVOKED_new(void);
836void X509_REVOKED_free(X509_REVOKED *a);
837int i2d_X509_REVOKED(X509_REVOKED *a,unsigned char **pp);
838X509_REVOKED * d2i_X509_REVOKED(X509_REVOKED **a,unsigned char **pp,long length);
839
840X509_CRL_INFO *X509_CRL_INFO_new(void);
841void X509_CRL_INFO_free(X509_CRL_INFO *a);
842int i2d_X509_CRL_INFO(X509_CRL_INFO *a,unsigned char **pp);
843X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a,unsigned char **pp,
844 long length);
845
846X509_CRL * X509_CRL_new(void);
847void X509_CRL_free(X509_CRL *a);
848int i2d_X509_CRL(X509_CRL *a,unsigned char **pp);
849X509_CRL * d2i_X509_CRL(X509_CRL **a,unsigned char **pp,long length);
850
851X509_PKEY * X509_PKEY_new(void );
852void X509_PKEY_free(X509_PKEY *a);
853int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
854X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
855
856NETSCAPE_SPKI * NETSCAPE_SPKI_new(void );
857void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a);
858int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a,unsigned char **pp);
859NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a,unsigned char **pp,
860 long length);
861
862NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void );
863void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a);
864int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp);
865NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp,
866 long length);
867
868
869int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp);
870NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void);
871NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length);
872void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a);
873
874#ifdef HEADER_ENVELOPE_H
875X509_INFO * X509_INFO_new(void);
876void X509_INFO_free(X509_INFO *a);
877char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
878
879int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
880 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
881
882int ASN1_digest(int (*i2d)(),const EVP_MD *type,char *data,
883 unsigned char *md,unsigned int *len);
884
885int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
886 ASN1_BIT_STRING *signature,
887 char *data,EVP_PKEY *pkey, const EVP_MD *type);
888#endif
889
890int X509_set_version(X509 *x,long version);
891int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
892ASN1_INTEGER * X509_get_serialNumber(X509 *x);
893int X509_set_issuer_name(X509 *x, X509_NAME *name);
894X509_NAME * X509_get_issuer_name(X509 *a);
895int X509_set_subject_name(X509 *x, X509_NAME *name);
896X509_NAME * X509_get_subject_name(X509 *a);
897int X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm);
898int X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm);
899int X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
900EVP_PKEY * X509_get_pubkey(X509 *x);
901int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
902
903int X509_REQ_set_version(X509_REQ *x,long version);
904int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
905int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
906EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req);
907int X509_REQ_extension_nid(int nid);
908int * X509_REQ_get_extension_nids(void);
909void X509_REQ_set_extension_nids(int *nids);
910STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);
911int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
912 int nid);
913int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts);
914int X509_REQ_get_attr_count(const X509_REQ *req);
915int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
916 int lastpos);
917int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
918 int lastpos);
919X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
920X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
921int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
922int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
923 ASN1_OBJECT *obj, int type,
924 unsigned char *bytes, int len);
925int X509_REQ_add1_attr_by_NID(X509_REQ *req,
926 int nid, int type,
927 unsigned char *bytes, int len);
928int X509_REQ_add1_attr_by_txt(X509_REQ *req,
929 char *attrname, int type,
930 unsigned char *bytes, int len);
931
932int X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
933
934int X509_issuer_and_serial_cmp(X509 *a, X509 *b);
935unsigned long X509_issuer_and_serial_hash(X509 *a);
936
937int X509_issuer_name_cmp(X509 *a, X509 *b);
938unsigned long X509_issuer_name_hash(X509 *a);
939
940int X509_subject_name_cmp(X509 *a,X509 *b);
941unsigned long X509_subject_name_hash(X509 *x);
942
943int X509_cmp (X509 *a, X509 *b);
944int X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
945unsigned long X509_NAME_hash(X509_NAME *x);
946
947int X509_CRL_cmp(X509_CRL *a,X509_CRL *b);
948#ifndef NO_FP_API
949int X509_print_fp(FILE *bp,X509 *x);
950int X509_CRL_print_fp(FILE *bp,X509_CRL *x);
951int X509_REQ_print_fp(FILE *bp,X509_REQ *req);
952#endif
953
954#ifdef HEADER_BIO_H
955int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
956int X509_print(BIO *bp,X509 *x);
957int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent);
958int X509_CRL_print(BIO *bp,X509_CRL *x);
959int X509_REQ_print(BIO *bp,X509_REQ *req);
960#endif
961
962int X509_NAME_entry_count(X509_NAME *name);
963int X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
964 char *buf,int len);
965int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
966 char *buf,int len);
967
968/* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use
969 * lastpos, search after that position on. */
970int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
971int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
972 int lastpos);
973X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
974X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
975int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
976 int loc, int set);
977int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
978 unsigned char *bytes, int len, int loc, int set);
979int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
980 unsigned char *bytes, int len, int loc, int set);
981X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
982 char *field, int type, unsigned char *bytes, int len);
983X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
984 int type,unsigned char *bytes, int len);
985int X509_NAME_add_entry_by_txt(X509_NAME *name, char *field, int type,
986 unsigned char *bytes, int len, int loc, int set);
987X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
988 ASN1_OBJECT *obj, int type,unsigned char *bytes,
989 int len);
990int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
991 ASN1_OBJECT *obj);
992int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
993 unsigned char *bytes, int len);
994ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
995ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
996
997int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
998int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
999 int nid, int lastpos);
1000int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
1001 ASN1_OBJECT *obj,int lastpos);
1002int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
1003 int crit, int lastpos);
1004X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
1005X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
1006STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
1007 X509_EXTENSION *ex, int loc);
1008
1009int X509_get_ext_count(X509 *x);
1010int X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
1011int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
1012int X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
1013X509_EXTENSION *X509_get_ext(X509 *x, int loc);
1014X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
1015int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
1016void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
1017
1018int X509_CRL_get_ext_count(X509_CRL *x);
1019int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
1020int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
1021int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
1022X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
1023X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
1024int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
1025void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
1026
1027int X509_REVOKED_get_ext_count(X509_REVOKED *x);
1028int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
1029int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
1030int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
1031X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
1032X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
1033int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
1034void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
1035
1036X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
1037 int nid, int crit, ASN1_OCTET_STRING *data);
1038X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
1039 ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
1040int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
1041int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
1042int X509_EXTENSION_set_data(X509_EXTENSION *ex,
1043 ASN1_OCTET_STRING *data);
1044ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex);
1045ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
1046int X509_EXTENSION_get_critical(X509_EXTENSION *ex);
1047
1048int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
1049int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
1050 int lastpos);
1051int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
1052 int lastpos);
1053X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
1054X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
1055STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
1056 X509_ATTRIBUTE *attr);
1057STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
1058 ASN1_OBJECT *obj, int type,
1059 unsigned char *bytes, int len);
1060STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
1061 int nid, int type,
1062 unsigned char *bytes, int len);
1063STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
1064 char *attrname, int type,
1065 unsigned char *bytes, int len);
1066X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
1067 int atrtype, void *data, int len);
1068X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
1069 ASN1_OBJECT *obj, int atrtype, void *data, int len);
1070X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
1071 char *atrname, int type, unsigned char *bytes, int len);
1072int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, ASN1_OBJECT *obj);
1073int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, void *data, int len);
1074void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
1075 int atrtype, void *data);
1076int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
1077ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
1078ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
1079
1080int X509_verify_cert(X509_STORE_CTX *ctx);
1081
1082/* lookup a cert from a X509 STACK */
1083X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
1084 ASN1_INTEGER *serial);
1085X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
1086
1087int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp);
1088PBEPARAM *PBEPARAM_new(void);
1089PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length);
1090void PBEPARAM_free(PBEPARAM *a);
1091X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
1092X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
1093 unsigned char *salt, int saltlen);
1094
1095int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp);
1096PBKDF2PARAM *PBKDF2PARAM_new(void);
1097PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, long length);
1098void PBKDF2PARAM_free(PBKDF2PARAM *a);
1099
1100int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp);
1101PBE2PARAM *PBE2PARAM_new(void);
1102PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length);
1103void PBE2PARAM_free(PBE2PARAM *a);
1104
1105/* PKCS#8 utilities */
1106
1107int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **pp);
1108PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void);
1109PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
1110 unsigned char **pp, long length);
1111void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
1112
1113EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
1114PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
1115PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken);
1116PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
1117
1118int X509_check_trust(X509 *x, int id, int flags);
1119int X509_TRUST_get_count(void);
1120X509_TRUST * X509_TRUST_get0(int idx);
1121int X509_TRUST_get_by_id(int id);
1122int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
1123 char *name, int arg1, void *arg2);
1124void X509_TRUST_cleanup(void);
1125int X509_TRUST_get_flags(X509_TRUST *xp);
1126char *X509_TRUST_get0_name(X509_TRUST *xp);
1127int X509_TRUST_get_trust(X509_TRUST *xp);
1128
1129/* BEGIN ERROR CODES */
1130/* The following lines are auto generated by the script mkerr.pl. Any changes
1131 * made after this point may be overwritten when the script is next run.
1132 */
1133
1134/* Error codes for the X509 functions. */
1135
1136/* Function codes. */
1137#define X509_F_ADD_CERT_DIR 100
1138#define X509_F_BY_FILE_CTRL 101
1139#define X509_F_DIR_CTRL 102
1140#define X509_F_GET_CERT_BY_SUBJECT 103
1141#define X509_F_NETSCAPE_SPKI_B64_DECODE 129
1142#define X509_F_NETSCAPE_SPKI_B64_ENCODE 130
1143#define X509_F_X509V3_ADD_EXT 104
1144#define X509_F_X509_ADD_ATTR 135
1145#define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136
1146#define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137
1147#define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140
1148#define X509_F_X509_ATTRIBUTE_GET0_DATA 139
1149#define X509_F_X509_ATTRIBUTE_SET1_DATA 138
1150#define X509_F_X509_CHECK_PRIVATE_KEY 128
1151#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
1152#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
1153#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
1154#define X509_F_X509_LOAD_CERT_CRL_FILE 132
1155#define X509_F_X509_LOAD_CERT_FILE 111
1156#define X509_F_X509_LOAD_CRL_FILE 112
1157#define X509_F_X509_NAME_ADD_ENTRY 113
1158#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114
1159#define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131
1160#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
1161#define X509_F_X509_NAME_ONELINE 116
1162#define X509_F_X509_NAME_PRINT 117
1163#define X509_F_X509_PRINT_FP 118
1164#define X509_F_X509_PUBKEY_GET 119
1165#define X509_F_X509_PUBKEY_SET 120
1166#define X509_F_X509_REQ_PRINT 121
1167#define X509_F_X509_REQ_PRINT_FP 122
1168#define X509_F_X509_REQ_TO_X509 123
1169#define X509_F_X509_STORE_ADD_CERT 124
1170#define X509_F_X509_STORE_ADD_CRL 125
1171#define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134
1172#define X509_F_X509_TO_X509_REQ 126
1173#define X509_F_X509_TRUST_ADD 133
1174#define X509_F_X509_VERIFY_CERT 127
1175
1176/* Reason codes. */
1177#define X509_R_BAD_X509_FILETYPE 100
1178#define X509_R_BASE64_DECODE_ERROR 118
1179#define X509_R_CANT_CHECK_DH_KEY 114
1180#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
1181#define X509_R_ERR_ASN1_LIB 102
1182#define X509_R_INVALID_DIRECTORY 113
1183#define X509_R_INVALID_FIELD_NAME 119
1184#define X509_R_KEY_TYPE_MISMATCH 115
1185#define X509_R_KEY_VALUES_MISMATCH 116
1186#define X509_R_LOADING_CERT_DIR 103
1187#define X509_R_LOADING_DEFAULTS 104
1188#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105
1189#define X509_R_SHOULD_RETRY 106
1190#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107
1191#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
1192#define X509_R_UNKNOWN_KEY_TYPE 117
1193#define X509_R_UNKNOWN_NID 109
1194#define X509_R_UNKNOWN_PURPOSE_ID 121
1195#define X509_R_UNKNOWN_TRUST_ID 120
1196#define X509_R_UNSUPPORTED_ALGORITHM 111
1197#define X509_R_WRONG_LOOKUP_TYPE 112
1198#define X509_R_WRONG_TYPE 122
1199
1200#ifdef __cplusplus
1201}
1202#endif
1203#endif
1204
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c
deleted file mode 100644
index caafde658f..0000000000
--- a/src/lib/libcrypto/x509/x509_att.c
+++ /dev/null
@@ -1,326 +0,0 @@
1/* crypto/x509/x509_att.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x)
69{
70 if (!x) return 0;
71 return(sk_X509_ATTRIBUTE_num(x));
72}
73
74int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
75 int lastpos)
76{
77 ASN1_OBJECT *obj;
78
79 obj=OBJ_nid2obj(nid);
80 if (obj == NULL) return(-2);
81 return(X509at_get_attr_by_OBJ(x,obj,lastpos));
82}
83
84int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
85 int lastpos)
86{
87 int n;
88 X509_ATTRIBUTE *ex;
89
90 if (sk == NULL) return(-1);
91 lastpos++;
92 if (lastpos < 0)
93 lastpos=0;
94 n=sk_X509_ATTRIBUTE_num(sk);
95 for ( ; lastpos < n; lastpos++)
96 {
97 ex=sk_X509_ATTRIBUTE_value(sk,lastpos);
98 if (OBJ_cmp(ex->object,obj) == 0)
99 return(lastpos);
100 }
101 return(-1);
102}
103
104X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc)
105{
106 if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)
107 return NULL;
108 else
109 return sk_X509_ATTRIBUTE_value(x,loc);
110}
111
112X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc)
113{
114 X509_ATTRIBUTE *ret;
115
116 if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)
117 return(NULL);
118 ret=sk_X509_ATTRIBUTE_delete(x,loc);
119 return(ret);
120}
121
122STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
123 X509_ATTRIBUTE *attr)
124{
125 X509_ATTRIBUTE *new_attr=NULL;
126 STACK_OF(X509_ATTRIBUTE) *sk=NULL;
127
128 if ((x != NULL) && (*x == NULL))
129 {
130 if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL)
131 goto err;
132 }
133 else
134 sk= *x;
135
136 if ((new_attr=X509_ATTRIBUTE_dup(attr)) == NULL)
137 goto err2;
138 if (!sk_X509_ATTRIBUTE_push(sk,new_attr))
139 goto err;
140 if ((x != NULL) && (*x == NULL))
141 *x=sk;
142 return(sk);
143err:
144 X509err(X509_F_X509_ADD_ATTR,ERR_R_MALLOC_FAILURE);
145err2:
146 if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr);
147 if (sk != NULL) sk_X509_ATTRIBUTE_free(sk);
148 return(NULL);
149}
150
151STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
152 ASN1_OBJECT *obj, int type,
153 unsigned char *bytes, int len)
154{
155 X509_ATTRIBUTE *attr;
156 STACK_OF(X509_ATTRIBUTE) *ret;
157 attr = X509_ATTRIBUTE_create_by_OBJ(NULL, obj, type, bytes, len);
158 if(!attr) return 0;
159 ret = X509at_add1_attr(x, attr);
160 X509_ATTRIBUTE_free(attr);
161 return ret;
162}
163
164STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
165 int nid, int type,
166 unsigned char *bytes, int len)
167{
168 X509_ATTRIBUTE *attr;
169 STACK_OF(X509_ATTRIBUTE) *ret;
170 attr = X509_ATTRIBUTE_create_by_NID(NULL, nid, type, bytes, len);
171 if(!attr) return 0;
172 ret = X509at_add1_attr(x, attr);
173 X509_ATTRIBUTE_free(attr);
174 return ret;
175}
176
177STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
178 char *attrname, int type,
179 unsigned char *bytes, int len)
180{
181 X509_ATTRIBUTE *attr;
182 STACK_OF(X509_ATTRIBUTE) *ret;
183 attr = X509_ATTRIBUTE_create_by_txt(NULL, attrname, type, bytes, len);
184 if(!attr) return 0;
185 ret = X509at_add1_attr(x, attr);
186 X509_ATTRIBUTE_free(attr);
187 return ret;
188}
189
190X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
191 int atrtype, void *data, int len)
192{
193 ASN1_OBJECT *obj;
194 X509_ATTRIBUTE *ret;
195
196 obj=OBJ_nid2obj(nid);
197 if (obj == NULL)
198 {
199 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_NID,X509_R_UNKNOWN_NID);
200 return(NULL);
201 }
202 ret=X509_ATTRIBUTE_create_by_OBJ(attr,obj,atrtype,data,len);
203 if (ret == NULL) ASN1_OBJECT_free(obj);
204 return(ret);
205}
206
207X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
208 ASN1_OBJECT *obj, int atrtype, void *data, int len)
209{
210 X509_ATTRIBUTE *ret;
211
212 if ((attr == NULL) || (*attr == NULL))
213 {
214 if ((ret=X509_ATTRIBUTE_new()) == NULL)
215 {
216 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
217 return(NULL);
218 }
219 }
220 else
221 ret= *attr;
222
223 if (!X509_ATTRIBUTE_set1_object(ret,obj))
224 goto err;
225 if (!X509_ATTRIBUTE_set1_data(ret,atrtype,data,len))
226 goto err;
227
228 if ((attr != NULL) && (*attr == NULL)) *attr=ret;
229 return(ret);
230err:
231 if ((attr == NULL) || (ret != *attr))
232 X509_ATTRIBUTE_free(ret);
233 return(NULL);
234}
235
236X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
237 char *atrname, int type, unsigned char *bytes, int len)
238 {
239 ASN1_OBJECT *obj;
240 X509_ATTRIBUTE *nattr;
241
242 obj=OBJ_txt2obj(atrname, 0);
243 if (obj == NULL)
244 {
245 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT,
246 X509_R_INVALID_FIELD_NAME);
247 ERR_add_error_data(2, "name=", atrname);
248 return(NULL);
249 }
250 nattr = X509_ATTRIBUTE_create_by_OBJ(attr,obj,type,bytes,len);
251 ASN1_OBJECT_free(obj);
252 return nattr;
253 }
254
255int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, ASN1_OBJECT *obj)
256{
257 if ((attr == NULL) || (obj == NULL))
258 return(0);
259 ASN1_OBJECT_free(attr->object);
260 attr->object=OBJ_dup(obj);
261 return(1);
262}
263
264int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, void *data, int len)
265{
266 ASN1_TYPE *ttmp;
267 ASN1_STRING *stmp;
268 int atype;
269 if (!attr) return 0;
270 if(attrtype & MBSTRING_FLAG) {
271 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,
272 OBJ_obj2nid(attr->object));
273 if(!stmp) {
274 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_ASN1_LIB);
275 return 0;
276 }
277 atype = stmp->type;
278 } else {
279 if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err;
280 if(!ASN1_STRING_set(stmp, data, len)) goto err;
281 atype = attrtype;
282 }
283 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
284 if(!(ttmp = ASN1_TYPE_new())) goto err;
285 if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err;
286 attr->set = 1;
287 ASN1_TYPE_set(ttmp, atype, stmp);
288 return 1;
289 err:
290 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);
291 return 0;
292}
293
294int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr)
295{
296 if(attr->set) return sk_ASN1_TYPE_num(attr->value.set);
297 if(attr->value.single) return 1;
298 return 0;
299}
300
301ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr)
302{
303 if (attr == NULL) return(NULL);
304 return(attr->object);
305}
306
307void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
308 int atrtype, void *data)
309{
310 ASN1_TYPE *ttmp;
311 ttmp = X509_ATTRIBUTE_get0_type(attr, idx);
312 if(!ttmp) return NULL;
313 if(atrtype != ASN1_TYPE_get(ttmp)){
314 X509err(X509_F_X509_ATTRIBUTE_GET0_DATA, X509_R_WRONG_TYPE);
315 return NULL;
316 }
317 return ttmp->value.ptr;
318}
319
320ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx)
321{
322 if (attr == NULL) return(NULL);
323 if(idx >= X509_ATTRIBUTE_count(attr)) return NULL;
324 if(attr->set) return sk_ASN1_TYPE_value(attr->value.set, idx);
325 else return attr->value.single;
326}
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c
deleted file mode 100644
index a8a5ca8b03..0000000000
--- a/src/lib/libcrypto/x509/x509_cmp.c
+++ /dev/null
@@ -1,308 +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 "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66int X509_issuer_and_serial_cmp(X509 *a, X509 *b)
67 {
68 int i;
69 X509_CINF *ai,*bi;
70
71 ai=a->cert_info;
72 bi=b->cert_info;
73 i=M_ASN1_INTEGER_cmp(ai->serialNumber,bi->serialNumber);
74 if (i) return(i);
75 return(X509_NAME_cmp(ai->issuer,bi->issuer));
76 }
77
78#ifndef NO_MD5
79unsigned long X509_issuer_and_serial_hash(X509 *a)
80 {
81 unsigned long ret=0;
82 MD5_CTX ctx;
83 unsigned char md[16];
84 char str[256];
85
86 X509_NAME_oneline(a->cert_info->issuer,str,256);
87 ret=strlen(str);
88 MD5_Init(&ctx);
89 MD5_Update(&ctx,(unsigned char *)str,ret);
90 MD5_Update(&ctx,(unsigned char *)a->cert_info->serialNumber->data,
91 (unsigned long)a->cert_info->serialNumber->length);
92 MD5_Final(&(md[0]),&ctx);
93 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
94 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
95 )&0xffffffffL;
96 return(ret);
97 }
98#endif
99
100int X509_issuer_name_cmp(X509 *a, X509 *b)
101 {
102 return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer));
103 }
104
105int X509_subject_name_cmp(X509 *a, X509 *b)
106 {
107 return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject));
108 }
109
110int X509_CRL_cmp(X509_CRL *a, X509_CRL *b)
111 {
112 return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer));
113 }
114
115X509_NAME *X509_get_issuer_name(X509 *a)
116 {
117 return(a->cert_info->issuer);
118 }
119
120unsigned long X509_issuer_name_hash(X509 *x)
121 {
122 return(X509_NAME_hash(x->cert_info->issuer));
123 }
124
125X509_NAME *X509_get_subject_name(X509 *a)
126 {
127 return(a->cert_info->subject);
128 }
129
130ASN1_INTEGER *X509_get_serialNumber(X509 *a)
131 {
132 return(a->cert_info->serialNumber);
133 }
134
135unsigned long X509_subject_name_hash(X509 *x)
136 {
137 return(X509_NAME_hash(x->cert_info->subject));
138 }
139
140#ifndef NO_SHA
141/* Compare two certificates: they must be identical for
142 * this to work.
143 */
144int X509_cmp(X509 *a, X509 *b)
145{
146 /* ensure hash is valid */
147 X509_check_purpose(a, -1, 0);
148 X509_check_purpose(b, -1, 0);
149
150 return memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH);
151}
152#endif
153
154int X509_NAME_cmp(X509_NAME *a, X509_NAME *b)
155 {
156 int i,j;
157 X509_NAME_ENTRY *na,*nb;
158
159 if (sk_X509_NAME_ENTRY_num(a->entries)
160 != sk_X509_NAME_ENTRY_num(b->entries))
161 return sk_X509_NAME_ENTRY_num(a->entries)
162 -sk_X509_NAME_ENTRY_num(b->entries);
163 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
164 {
165 na=sk_X509_NAME_ENTRY_value(a->entries,i);
166 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
167 j=na->value->length-nb->value->length;
168 if (j) return(j);
169 j=memcmp(na->value->data,nb->value->data,
170 na->value->length);
171 if (j) return(j);
172 j=na->set-nb->set;
173 if (j) return(j);
174 }
175
176 /* We will check the object types after checking the values
177 * since the values will more often be different than the object
178 * types. */
179 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
180 {
181 na=sk_X509_NAME_ENTRY_value(a->entries,i);
182 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
183 j=OBJ_cmp(na->object,nb->object);
184 if (j) return(j);
185 }
186 return(0);
187 }
188
189#ifndef NO_MD5
190/* I now DER encode the name and hash it. Since I cache the DER encoding,
191 * this is reasonably efficient. */
192unsigned long X509_NAME_hash(X509_NAME *x)
193 {
194 unsigned long ret=0;
195 unsigned char md[16];
196 unsigned char str[256],*p,*pp;
197 int i;
198
199 i=i2d_X509_NAME(x,NULL);
200 if (i > sizeof(str))
201 p=Malloc(i);
202 else
203 p=str;
204
205 pp=p;
206 i2d_X509_NAME(x,&pp);
207 MD5((unsigned char *)p,i,&(md[0]));
208 if (p != str) Free(p);
209
210 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
211 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
212 )&0xffffffffL;
213 return(ret);
214 }
215#endif
216
217/* Search a stack of X509 for a match */
218X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name,
219 ASN1_INTEGER *serial)
220 {
221 int i;
222 X509_CINF cinf;
223 X509 x,*x509=NULL;
224
225 if(!sk) return NULL;
226
227 x.cert_info= &cinf;
228 cinf.serialNumber=serial;
229 cinf.issuer=name;
230
231 for (i=0; i<sk_X509_num(sk); i++)
232 {
233 x509=sk_X509_value(sk,i);
234 if (X509_issuer_and_serial_cmp(x509,&x) == 0)
235 return(x509);
236 }
237 return(NULL);
238 }
239
240X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name)
241 {
242 X509 *x509;
243 int i;
244
245 for (i=0; i<sk_X509_num(sk); i++)
246 {
247 x509=sk_X509_value(sk,i);
248 if (X509_NAME_cmp(X509_get_subject_name(x509),name) == 0)
249 return(x509);
250 }
251 return(NULL);
252 }
253
254EVP_PKEY *X509_get_pubkey(X509 *x)
255 {
256 if ((x == NULL) || (x->cert_info == NULL))
257 return(NULL);
258 return(X509_PUBKEY_get(x->cert_info->key));
259 }
260
261int X509_check_private_key(X509 *x, EVP_PKEY *k)
262 {
263 EVP_PKEY *xk=NULL;
264 int ok=0;
265
266 xk=X509_get_pubkey(x);
267 if (xk->type != k->type)
268 {
269 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);
270 goto err;
271 }
272 switch (k->type)
273 {
274#ifndef NO_RSA
275 case EVP_PKEY_RSA:
276 if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0
277 || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)
278 {
279 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
280 goto err;
281 }
282 break;
283#endif
284#ifndef NO_DSA
285 case EVP_PKEY_DSA:
286 if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)
287 {
288 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
289 goto err;
290 }
291 break;
292#endif
293#ifndef NO_DH
294 case EVP_PKEY_DH:
295 /* No idea */
296 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);
297 goto err;
298#endif
299 default:
300 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);
301 goto err;
302 }
303
304 ok=1;
305err:
306 EVP_PKEY_free(xk);
307 return(ok);
308 }
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c
deleted file mode 100644
index 753d53eb43..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 "cryptlib.h"
61#include <openssl/crypto.h>
62#include <openssl/x509.h>
63
64#ifndef NO_STDIO
65int X509_STORE_set_default_paths(X509_STORE *ctx)
66 {
67 X509_LOOKUP *lookup;
68
69 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
70 if (lookup == NULL) return(0);
71 X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
72
73 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
74 if (lookup == NULL) return(0);
75 X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
76
77 /* clear any errors */
78 ERR_clear_error();
79
80 return(1);
81 }
82
83int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
84 const char *path)
85 {
86 X509_LOOKUP *lookup;
87
88 if (file != NULL)
89 {
90 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
91 if (lookup == NULL) return(0);
92 if (X509_LOOKUP_load_file(lookup,file,X509_FILETYPE_PEM) != 1)
93 return(0);
94 }
95 if (path != NULL)
96 {
97 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
98 if (lookup == NULL) return(0);
99 if (X509_LOOKUP_add_dir(lookup,path,X509_FILETYPE_PEM) != 1)
100 return(0);
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 e0ac151a76..0000000000
--- a/src/lib/libcrypto/x509/x509_def.c
+++ /dev/null
@@ -1,81 +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 "cryptlib.h"
61#include <openssl/crypto.h>
62#include <openssl/x509.h>
63
64const char *X509_get_default_private_dir(void)
65 { return(X509_PRIVATE_DIR); }
66
67const char *X509_get_default_cert_area(void)
68 { return(X509_CERT_AREA); }
69
70const char *X509_get_default_cert_dir(void)
71 { return(X509_CERT_DIR); }
72
73const char *X509_get_default_cert_file(void)
74 { return(X509_CERT_FILE); }
75
76const char *X509_get_default_cert_dir_env(void)
77 { return(X509_CERT_DIR_EVP); }
78
79const char *X509_get_default_cert_file_env(void)
80 { return(X509_CERT_FILE_EVP); }
81
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c
deleted file mode 100644
index 848add56e9..0000000000
--- a/src/lib/libcrypto/x509/x509_err.c
+++ /dev/null
@@ -1,152 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/x509.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA X509_str_functs[]=
68 {
69{ERR_PACK(0,X509_F_ADD_CERT_DIR,0), "ADD_CERT_DIR"},
70{ERR_PACK(0,X509_F_BY_FILE_CTRL,0), "BY_FILE_CTRL"},
71{ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"},
72{ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"},
73{ERR_PACK(0,X509_F_NETSCAPE_SPKI_B64_DECODE,0), "NETSCAPE_SPKI_b64_decode"},
74{ERR_PACK(0,X509_F_NETSCAPE_SPKI_B64_ENCODE,0), "NETSCAPE_SPKI_b64_encode"},
75{ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"},
76{ERR_PACK(0,X509_F_X509_ADD_ATTR,0), "X509_ADD_ATTR"},
77{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_NID,0), "X509_ATTRIBUTE_create_by_NID"},
78{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ,0), "X509_ATTRIBUTE_create_by_OBJ"},
79{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_TXT,0), "X509_ATTRIBUTE_create_by_txt"},
80{ERR_PACK(0,X509_F_X509_ATTRIBUTE_GET0_DATA,0), "X509_ATTRIBUTE_get0_data"},
81{ERR_PACK(0,X509_F_X509_ATTRIBUTE_SET1_DATA,0), "X509_ATTRIBUTE_set1_data"},
82{ERR_PACK(0,X509_F_X509_CHECK_PRIVATE_KEY,0), "X509_check_private_key"},
83{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"},
84{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"},
85{ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"},
86{ERR_PACK(0,X509_F_X509_LOAD_CERT_CRL_FILE,0), "X509_load_cert_crl_file"},
87{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_load_cert_file"},
88{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_load_crl_file"},
89{ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"},
90{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"},
91{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_TXT,0), "X509_NAME_ENTRY_create_by_txt"},
92{ERR_PACK(0,X509_F_X509_NAME_ENTRY_SET_OBJECT,0), "X509_NAME_ENTRY_set_object"},
93{ERR_PACK(0,X509_F_X509_NAME_ONELINE,0), "X509_NAME_oneline"},
94{ERR_PACK(0,X509_F_X509_NAME_PRINT,0), "X509_NAME_print"},
95{ERR_PACK(0,X509_F_X509_PRINT_FP,0), "X509_print_fp"},
96{ERR_PACK(0,X509_F_X509_PUBKEY_GET,0), "X509_PUBKEY_get"},
97{ERR_PACK(0,X509_F_X509_PUBKEY_SET,0), "X509_PUBKEY_set"},
98{ERR_PACK(0,X509_F_X509_REQ_PRINT,0), "X509_REQ_print"},
99{ERR_PACK(0,X509_F_X509_REQ_PRINT_FP,0), "X509_REQ_print_fp"},
100{ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"},
101{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_add_cert"},
102{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_add_crl"},
103{ERR_PACK(0,X509_F_X509_STORE_CTX_PURPOSE_INHERIT,0), "X509_STORE_CTX_purpose_inherit"},
104{ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"},
105{ERR_PACK(0,X509_F_X509_TRUST_ADD,0), "X509_TRUST_add"},
106{ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"},
107{0,NULL}
108 };
109
110static ERR_STRING_DATA X509_str_reasons[]=
111 {
112{X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"},
113{X509_R_BASE64_DECODE_ERROR ,"base64 decode error"},
114{X509_R_CANT_CHECK_DH_KEY ,"cant check dh key"},
115{X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"},
116{X509_R_ERR_ASN1_LIB ,"err asn1 lib"},
117{X509_R_INVALID_DIRECTORY ,"invalid directory"},
118{X509_R_INVALID_FIELD_NAME ,"invalid field name"},
119{X509_R_KEY_TYPE_MISMATCH ,"key type mismatch"},
120{X509_R_KEY_VALUES_MISMATCH ,"key values mismatch"},
121{X509_R_LOADING_CERT_DIR ,"loading cert dir"},
122{X509_R_LOADING_DEFAULTS ,"loading defaults"},
123{X509_R_NO_CERT_SET_FOR_US_TO_VERIFY ,"no cert set for us to verify"},
124{X509_R_SHOULD_RETRY ,"should retry"},
125{X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN,"unable to find parameters in chain"},
126{X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"},
127{X509_R_UNKNOWN_KEY_TYPE ,"unknown key type"},
128{X509_R_UNKNOWN_NID ,"unknown nid"},
129{X509_R_UNKNOWN_PURPOSE_ID ,"unknown purpose id"},
130{X509_R_UNKNOWN_TRUST_ID ,"unknown trust id"},
131{X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"},
132{X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"},
133{X509_R_WRONG_TYPE ,"wrong type"},
134{0,NULL}
135 };
136
137#endif
138
139void ERR_load_X509_strings(void)
140 {
141 static int init=1;
142
143 if (init)
144 {
145 init=0;
146#ifndef NO_ERR
147 ERR_load_strings(ERR_LIB_X509,X509_str_functs);
148 ERR_load_strings(ERR_LIB_X509,X509_str_reasons);
149#endif
150
151 }
152 }
diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c
deleted file mode 100644
index 2955989807..0000000000
--- a/src/lib/libcrypto/x509/x509_ext.c
+++ /dev/null
@@ -1,191 +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#include <openssl/x509v3.h>
67
68
69int X509_CRL_get_ext_count(X509_CRL *x)
70 {
71 return(X509v3_get_ext_count(x->crl->extensions));
72 }
73
74int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos)
75 {
76 return(X509v3_get_ext_by_NID(x->crl->extensions,nid,lastpos));
77 }
78
79int X509_CRL_get_ext_by_OBJ(X509_CRL *x, ASN1_OBJECT *obj, int lastpos)
80 {
81 return(X509v3_get_ext_by_OBJ(x->crl->extensions,obj,lastpos));
82 }
83
84int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos)
85 {
86 return(X509v3_get_ext_by_critical(x->crl->extensions,crit,lastpos));
87 }
88
89X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc)
90 {
91 return(X509v3_get_ext(x->crl->extensions,loc));
92 }
93
94X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc)
95 {
96 return(X509v3_delete_ext(x->crl->extensions,loc));
97 }
98
99void *X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx)
100{
101 return X509V3_get_d2i(x->crl->extensions, nid, crit, idx);
102}
103
104int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc)
105 {
106 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL);
107 }
108
109int X509_get_ext_count(X509 *x)
110 {
111 return(X509v3_get_ext_count(x->cert_info->extensions));
112 }
113
114int X509_get_ext_by_NID(X509 *x, int nid, int lastpos)
115 {
116 return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos));
117 }
118
119int X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos)
120 {
121 return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos));
122 }
123
124int X509_get_ext_by_critical(X509 *x, int crit, int lastpos)
125 {
126 return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos));
127 }
128
129X509_EXTENSION *X509_get_ext(X509 *x, int loc)
130 {
131 return(X509v3_get_ext(x->cert_info->extensions,loc));
132 }
133
134X509_EXTENSION *X509_delete_ext(X509 *x, int loc)
135 {
136 return(X509v3_delete_ext(x->cert_info->extensions,loc));
137 }
138
139int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
140 {
141 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL);
142 }
143
144void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)
145{
146 return X509V3_get_d2i(x->cert_info->extensions, nid, crit, idx);
147}
148
149int X509_REVOKED_get_ext_count(X509_REVOKED *x)
150 {
151 return(X509v3_get_ext_count(x->extensions));
152 }
153
154int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos)
155 {
156 return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos));
157 }
158
159int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x, ASN1_OBJECT *obj,
160 int lastpos)
161 {
162 return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos));
163 }
164
165int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos)
166 {
167 return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos));
168 }
169
170X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc)
171 {
172 return(X509v3_get_ext(x->extensions,loc));
173 }
174
175X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc)
176 {
177 return(X509v3_delete_ext(x->extensions,loc));
178 }
179
180int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc)
181 {
182 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL);
183 }
184
185void *X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx)
186{
187 return X509V3_get_d2i(x->extensions, nid, crit, idx);
188}
189
190IMPLEMENT_STACK_OF(X509_EXTENSION)
191IMPLEMENT_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 a20006d67e..0000000000
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ /dev/null
@@ -1,427 +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_OF(CRYPTO_EX_DATA_FUNCS) *x509_store_meth=NULL;
65static STACK_OF(CRYPTO_EX_DATA_FUNCS) *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,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,&stmp);
381 return(tmp);
382 }
383
384X509_STORE_CTX *X509_STORE_CTX_new(void)
385{
386 X509_STORE_CTX *ctx;
387 ctx = (X509_STORE_CTX *)Malloc(sizeof(X509_STORE_CTX));
388 if(ctx) memset(ctx, 0, sizeof(X509_STORE_CTX));
389 return ctx;
390}
391
392void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
393{
394 X509_STORE_CTX_cleanup(ctx);
395 Free(ctx);
396}
397
398void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
399 STACK_OF(X509) *chain)
400 {
401 ctx->ctx=store;
402 ctx->current_method=0;
403 ctx->cert=x509;
404 ctx->untrusted=chain;
405 ctx->last_untrusted=0;
406 ctx->purpose=0;
407 ctx->trust=0;
408 ctx->valid=0;
409 ctx->chain=NULL;
410 ctx->depth=9;
411 ctx->error=0;
412 ctx->current_cert=NULL;
413 memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA));
414 }
415
416void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
417 {
418 if (ctx->chain != NULL)
419 {
420 sk_X509_pop_free(ctx->chain,X509_free);
421 ctx->chain=NULL;
422 }
423 CRYPTO_free_ex_data(x509_store_ctx_meth,ctx,&(ctx->ex_data));
424 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA));
425 }
426
427IMPLEMENT_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 db051033d9..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=M_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 baef8790eb..0000000000
--- a/src/lib/libcrypto/x509/x509_req.c
+++ /dev/null
@@ -1,278 +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, const 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
116/* It seems several organisations had the same idea of including a list of
117 * extensions in a certificate request. There are at least two OIDs that are
118 * used and there may be more: so the list is configurable.
119 */
120
121static int ext_nid_list[] = { NID_ms_ext_req, NID_ext_req, NID_undef};
122
123static int *ext_nids = ext_nid_list;
124
125int X509_REQ_extension_nid(int req_nid)
126{
127 int i, nid;
128 for(i = 0; ; i++) {
129 nid = ext_nids[i];
130 if(nid == NID_undef) return 0;
131 else if (req_nid == nid) return 1;
132 }
133}
134
135int *X509_REQ_get_extension_nids(void)
136{
137 return ext_nids;
138}
139
140void X509_REQ_set_extension_nids(int *nids)
141{
142 ext_nids = nids;
143}
144
145STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
146{
147 X509_ATTRIBUTE *attr;
148 STACK_OF(X509_ATTRIBUTE) *sk;
149 ASN1_TYPE *ext = NULL;
150 int i;
151 unsigned char *p;
152 if ((req == NULL) || (req->req_info == NULL))
153 return(NULL);
154 sk=req->req_info->attributes;
155 if (!sk) return NULL;
156 for(i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {
157 attr = sk_X509_ATTRIBUTE_value(sk, i);
158 if(X509_REQ_extension_nid(OBJ_obj2nid(attr->object))) {
159 if(attr->set && sk_ASN1_TYPE_num(attr->value.set))
160 ext = sk_ASN1_TYPE_value(attr->value.set, 0);
161 else ext = attr->value.single;
162 break;
163 }
164 }
165 if(!ext || (ext->type != V_ASN1_SEQUENCE)) return NULL;
166 p = ext->value.sequence->data;
167 return d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p,
168 ext->value.sequence->length,
169 d2i_X509_EXTENSION, X509_EXTENSION_free,
170 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
171}
172
173/* Add a STACK_OF extensions to a certificate request: allow alternative OIDs
174 * in case we want to create a non standard one.
175 */
176
177int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
178 int nid)
179{
180 unsigned char *p = NULL, *q;
181 long len;
182 ASN1_TYPE *at = NULL;
183 X509_ATTRIBUTE *attr = NULL;
184 if(!(at = ASN1_TYPE_new()) ||
185 !(at->value.sequence = ASN1_STRING_new())) goto err;
186
187 at->type = V_ASN1_SEQUENCE;
188 /* Generate encoding of extensions */
189 len = i2d_ASN1_SET_OF_X509_EXTENSION(exts, NULL, i2d_X509_EXTENSION,
190 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
191 if(!(p = Malloc(len))) goto err;
192 q = p;
193 i2d_ASN1_SET_OF_X509_EXTENSION(exts, &q, i2d_X509_EXTENSION,
194 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
195 at->value.sequence->data = p;
196 p = NULL;
197 at->value.sequence->length = len;
198 if(!(attr = X509_ATTRIBUTE_new())) goto err;
199 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
200 if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err;
201 at = NULL;
202 attr->set = 1;
203 attr->object = OBJ_nid2obj(nid);
204 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err;
205 return 1;
206 err:
207 if(p) Free(p);
208 X509_ATTRIBUTE_free(attr);
209 ASN1_TYPE_free(at);
210 return 0;
211}
212/* This is the normal usage: use the "official" OID */
213int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts)
214{
215 return X509_REQ_add_extensions_nid(req, exts, NID_ext_req);
216}
217
218/* Request attribute functions */
219
220int X509_REQ_get_attr_count(const X509_REQ *req)
221{
222 return X509at_get_attr_count(req->req_info->attributes);
223}
224
225int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
226 int lastpos)
227{
228 return X509at_get_attr_by_NID(req->req_info->attributes, nid, lastpos);
229}
230
231int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
232 int lastpos)
233{
234 return X509at_get_attr_by_OBJ(req->req_info->attributes, obj, lastpos);
235}
236
237X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc)
238{
239 return X509at_get_attr(req->req_info->attributes, loc);
240}
241
242X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc)
243{
244 return X509at_delete_attr(req->req_info->attributes, loc);
245}
246
247int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr)
248{
249 if(X509at_add1_attr(&req->req_info->attributes, attr)) return 1;
250 return 0;
251}
252
253int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
254 ASN1_OBJECT *obj, int type,
255 unsigned char *bytes, int len)
256{
257 if(X509at_add1_attr_by_OBJ(&req->req_info->attributes, obj,
258 type, bytes, len)) return 1;
259 return 0;
260}
261
262int X509_REQ_add1_attr_by_NID(X509_REQ *req,
263 int nid, int type,
264 unsigned char *bytes, int len)
265{
266 if(X509at_add1_attr_by_NID(&req->req_info->attributes, nid,
267 type, bytes, len)) return 1;
268 return 0;
269}
270
271int X509_REQ_add1_attr_by_txt(X509_REQ *req,
272 char *attrname, int type,
273 unsigned char *bytes, int len)
274{
275 if(X509at_add1_attr_by_txt(&req->req_info->attributes, attrname,
276 type, bytes, len)) return 1;
277 return 0;
278}
diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c
deleted file mode 100644
index add842d17a..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=M_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=M_ASN1_INTEGER_dup(serial);
86 if (in != NULL)
87 {
88 M_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=M_ASN1_UTCTIME_dup(tm);
116 if (in != NULL)
117 {
118 M_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=M_ASN1_UTCTIME_dup(tm);
134 if (in != NULL)
135 {
136 M_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_trs.c b/src/lib/libcrypto/x509/x509_trs.c
deleted file mode 100644
index c779aaf94d..0000000000
--- a/src/lib/libcrypto/x509/x509_trs.c
+++ /dev/null
@@ -1,264 +0,0 @@
1/* x509_trs.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63
64static int tr_cmp(X509_TRUST **a, X509_TRUST **b);
65static void trtable_free(X509_TRUST *p);
66
67static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags);
68static int trust_compat(X509_TRUST *trust, X509 *x, int flags);
69
70static int obj_trust(int id, X509 *x, int flags);
71static int (*default_trust)(int id, X509 *x, int flags) = obj_trust;
72
73/* WARNING: the following table should be kept in order of trust
74 * and without any gaps so we can just subtract the minimum trust
75 * value to get an index into the table
76 */
77
78static X509_TRUST trstandard[] = {
79{X509_TRUST_COMPAT, 0, trust_compat, "compatible", 0, NULL},
80{X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL},
81{X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Client", NID_server_auth, NULL},
82{X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL},
83};
84
85#define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST))
86
87IMPLEMENT_STACK_OF(X509_TRUST)
88
89static STACK_OF(X509_TRUST) *trtable = NULL;
90
91static int tr_cmp(X509_TRUST **a, X509_TRUST **b)
92{
93 return (*a)->trust - (*b)->trust;
94}
95
96int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int)
97{
98int (*oldtrust)(int , X509 *, int);
99oldtrust = default_trust;
100default_trust = trust;
101return oldtrust;
102}
103
104
105int X509_check_trust(X509 *x, int id, int flags)
106{
107 X509_TRUST *pt;
108 int idx;
109 if(id == -1) return 1;
110 idx = X509_TRUST_get_by_id(id);
111 if(idx == -1) return default_trust(id, x, flags);
112 pt = X509_TRUST_get0(idx);
113 return pt->check_trust(pt, x, flags);
114}
115
116int X509_TRUST_get_count(void)
117{
118 if(!trtable) return X509_TRUST_COUNT;
119 return sk_X509_TRUST_num(trtable) + X509_TRUST_COUNT;
120}
121
122X509_TRUST * X509_TRUST_get0(int idx)
123{
124 if(idx < 0) return NULL;
125 if(idx < X509_TRUST_COUNT) return trstandard + idx;
126 return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
127}
128
129int X509_TRUST_get_by_id(int id)
130{
131 X509_TRUST tmp;
132 int idx;
133 if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
134 return id - X509_TRUST_MIN;
135 tmp.trust = id;
136 if(!trtable) return -1;
137 idx = sk_X509_TRUST_find(trtable, &tmp);
138 if(idx == -1) return -1;
139 return idx + X509_TRUST_COUNT;
140}
141
142int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
143 char *name, int arg1, void *arg2)
144{
145 int idx;
146 X509_TRUST *trtmp;
147 /* This is set according to what we change: application can't set it */
148 flags &= ~X509_TRUST_DYNAMIC;
149 /* This will always be set for application modified trust entries */
150 flags |= X509_TRUST_DYNAMIC_NAME;
151 /* Get existing entry if any */
152 idx = X509_TRUST_get_by_id(id);
153 /* Need a new entry */
154 if(idx == -1) {
155 if(!(trtmp = Malloc(sizeof(X509_TRUST)))) {
156 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
157 return 0;
158 }
159 trtmp->flags = X509_TRUST_DYNAMIC;
160 } else trtmp = X509_TRUST_get0(idx);
161
162 /* Free existing name if dynamic */
163 if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) Free(trtmp->name);
164 /* dup supplied name */
165 if(!(trtmp->name = BUF_strdup(name))) {
166 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
167 return 0;
168 }
169 /* Keep the dynamic flag of existing entry */
170 trtmp->flags &= X509_TRUST_DYNAMIC;
171 /* Set all other flags */
172 trtmp->flags |= flags;
173
174 trtmp->trust = id;
175 trtmp->check_trust = ck;
176 trtmp->arg1 = arg1;
177 trtmp->arg2 = arg2;
178
179 /* If its a new entry manage the dynamic table */
180 if(idx == -1) {
181 if(!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) {
182 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
183 return 0;
184 }
185 if (!sk_X509_TRUST_push(trtable, trtmp)) {
186 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
187 return 0;
188 }
189 }
190 return 1;
191}
192
193static void trtable_free(X509_TRUST *p)
194 {
195 if(!p) return;
196 if (p->flags & X509_TRUST_DYNAMIC)
197 {
198 if (p->flags & X509_TRUST_DYNAMIC_NAME)
199 Free(p->name);
200 Free(p);
201 }
202 }
203
204void X509_TRUST_cleanup(void)
205{
206 int i;
207 for(i = 0; i < X509_TRUST_COUNT; i++) trtable_free(trstandard + i);
208 sk_X509_TRUST_pop_free(trtable, trtable_free);
209 trtable = NULL;
210}
211
212int X509_TRUST_get_flags(X509_TRUST *xp)
213{
214 return xp->flags;
215}
216
217char *X509_TRUST_get0_name(X509_TRUST *xp)
218{
219 return xp->name;
220}
221
222int X509_TRUST_get_trust(X509_TRUST *xp)
223{
224 return xp->trust;
225}
226
227static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags)
228{
229 if(x->aux) return obj_trust(trust->arg1, x, flags);
230 /* we don't have any trust settings: for compatibility
231 * we return trusted if it is self signed
232 */
233 return trust_compat(trust, x, flags);
234}
235
236static int trust_compat(X509_TRUST *trust, X509 *x, int flags)
237{
238 X509_check_purpose(x, -1, 0);
239 if(x->ex_flags & EXFLAG_SS) return X509_TRUST_TRUSTED;
240 else return X509_TRUST_UNTRUSTED;
241}
242
243static int obj_trust(int id, X509 *x, int flags)
244{
245 ASN1_OBJECT *obj;
246 int i;
247 X509_CERT_AUX *ax;
248 ax = x->aux;
249 if(!ax) return X509_TRUST_UNTRUSTED;
250 if(ax->reject) {
251 for(i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) {
252 obj = sk_ASN1_OBJECT_value(ax->reject, i);
253 if(OBJ_obj2nid(obj) == id) return X509_TRUST_REJECTED;
254 }
255 }
256 if(ax->trust) {
257 for(i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) {
258 obj = sk_ASN1_OBJECT_value(ax->trust, i);
259 if(OBJ_obj2nid(obj) == id) return X509_TRUST_TRUSTED;
260 }
261 }
262 return X509_TRUST_UNTRUSTED;
263}
264
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c
deleted file mode 100644
index 209cf53191..0000000000
--- a/src/lib/libcrypto/x509/x509_txt.c
+++ /dev/null
@@ -1,141 +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
63#include "cryptlib.h"
64#include <openssl/lhash.h>
65#include <openssl/buffer.h>
66#include <openssl/evp.h>
67#include <openssl/asn1.h>
68#include <openssl/x509.h>
69#include <openssl/objects.h>
70
71const char *X509_verify_cert_error_string(long n)
72 {
73 static char buf[100];
74
75 switch ((int)n)
76 {
77 case X509_V_OK:
78 return("ok");
79 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
80 return("unable to get issuer certificate");
81 case X509_V_ERR_UNABLE_TO_GET_CRL:
82 return("unable to get certificate CRL");
83 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
84 return("unable to decrypt certificate's signature");
85 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
86 return("unable to decrypt CRL's's signature");
87 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
88 return("unable to decode issuer public key");
89 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
90 return("certificate signature failure");
91 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
92 return("CRL signature failure");
93 case X509_V_ERR_CERT_NOT_YET_VALID:
94 return("certificate is not yet valid");
95 case X509_V_ERR_CRL_NOT_YET_VALID:
96 return("CRL is not yet valid");
97 case X509_V_ERR_CERT_HAS_EXPIRED:
98 return("Certificate has expired");
99 case X509_V_ERR_CRL_HAS_EXPIRED:
100 return("CRL has expired");
101 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
102 return("format error in certificate's notBefore field");
103 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
104 return("format error in certificate's notAfter field");
105 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
106 return("format error in CRL's lastUpdate field");
107 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
108 return("format error in CRL's nextUpdate field");
109 case X509_V_ERR_OUT_OF_MEM:
110 return("out of memory");
111 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
112 return("self signed certificate");
113 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
114 return("self signed certificate in certificate chain");
115 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
116 return("unable to get local issuer certificate");
117 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
118 return("unable to verify the first certificate");
119 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
120 return("certificate chain too long");
121 case X509_V_ERR_CERT_REVOKED:
122 return("certificate revoked");
123 case X509_V_ERR_INVALID_CA:
124 return ("invalid CA certificate");
125 case X509_V_ERR_PATH_LENGTH_EXCEEDED:
126 return ("path length constraint exceeded");
127 case X509_V_ERR_INVALID_PURPOSE:
128 return ("unsupported certificate purpose");
129 case X509_V_ERR_CERT_UNTRUSTED:
130 return ("certificate not trusted");
131 case X509_V_ERR_CERT_REJECTED:
132 return ("certificate rejected");
133 case X509_V_ERR_APPLICATION_VERIFICATION:
134 return("application verification failure");
135 default:
136 sprintf(buf,"error number %ld",n);
137 return(buf);
138 }
139 }
140
141
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
deleted file mode 100644
index 52887986fe..0000000000
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ /dev/null
@@ -1,267 +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#include <openssl/x509v3.h>
67
68int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x)
69 {
70 if (x == NULL) return(0);
71 return(sk_X509_EXTENSION_num(x));
72 }
73
74int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid,
75 int lastpos)
76 {
77 ASN1_OBJECT *obj;
78
79 obj=OBJ_nid2obj(nid);
80 if (obj == NULL) return(-2);
81 return(X509v3_get_ext_by_OBJ(x,obj,lastpos));
82 }
83
84int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj,
85 int lastpos)
86 {
87 int n;
88 X509_EXTENSION *ex;
89
90 if (sk == NULL) return(-1);
91 lastpos++;
92 if (lastpos < 0)
93 lastpos=0;
94 n=sk_X509_EXTENSION_num(sk);
95 for ( ; lastpos < n; lastpos++)
96 {
97 ex=sk_X509_EXTENSION_value(sk,lastpos);
98 if (OBJ_cmp(ex->object,obj) == 0)
99 return(lastpos);
100 }
101 return(-1);
102 }
103
104int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,
105 int lastpos)
106 {
107 int n;
108 X509_EXTENSION *ex;
109
110 if (sk == NULL) return(-1);
111 lastpos++;
112 if (lastpos < 0)
113 lastpos=0;
114 n=sk_X509_EXTENSION_num(sk);
115 for ( ; lastpos < n; lastpos++)
116 {
117 ex=sk_X509_EXTENSION_value(sk,lastpos);
118 if ( (ex->critical && crit) ||
119 (!ex->critical && !crit))
120 return(lastpos);
121 }
122 return(-1);
123 }
124
125X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc)
126 {
127 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
128 return NULL;
129 else
130 return sk_X509_EXTENSION_value(x,loc);
131 }
132
133X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc)
134 {
135 X509_EXTENSION *ret;
136
137 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
138 return(NULL);
139 ret=sk_X509_EXTENSION_delete(x,loc);
140 return(ret);
141 }
142
143STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
144 X509_EXTENSION *ex, int loc)
145 {
146 X509_EXTENSION *new_ex=NULL;
147 int n;
148 STACK_OF(X509_EXTENSION) *sk=NULL;
149
150 if ((x != NULL) && (*x == NULL))
151 {
152 if ((sk=sk_X509_EXTENSION_new_null()) == NULL)
153 goto err;
154 }
155 else
156 sk= *x;
157
158 n=sk_X509_EXTENSION_num(sk);
159 if (loc > n) loc=n;
160 else if (loc < 0) loc=n;
161
162 if ((new_ex=X509_EXTENSION_dup(ex)) == NULL)
163 goto err2;
164 if (!sk_X509_EXTENSION_insert(sk,new_ex,loc))
165 goto err;
166 if ((x != NULL) && (*x == NULL))
167 *x=sk;
168 return(sk);
169err:
170 X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE);
171err2:
172 if (new_ex != NULL) X509_EXTENSION_free(new_ex);
173 if (sk != NULL) sk_X509_EXTENSION_free(sk);
174 return(NULL);
175 }
176
177X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,
178 int crit, ASN1_OCTET_STRING *data)
179 {
180 ASN1_OBJECT *obj;
181 X509_EXTENSION *ret;
182
183 obj=OBJ_nid2obj(nid);
184 if (obj == NULL)
185 {
186 X509err(X509_F_X509_EXTENSION_CREATE_BY_NID,X509_R_UNKNOWN_NID);
187 return(NULL);
188 }
189 ret=X509_EXTENSION_create_by_OBJ(ex,obj,crit,data);
190 if (ret == NULL) ASN1_OBJECT_free(obj);
191 return(ret);
192 }
193
194X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
195 ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data)
196 {
197 X509_EXTENSION *ret;
198
199 if ((ex == NULL) || (*ex == NULL))
200 {
201 if ((ret=X509_EXTENSION_new()) == NULL)
202 {
203 X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
204 return(NULL);
205 }
206 }
207 else
208 ret= *ex;
209
210 if (!X509_EXTENSION_set_object(ret,obj))
211 goto err;
212 if (!X509_EXTENSION_set_critical(ret,crit))
213 goto err;
214 if (!X509_EXTENSION_set_data(ret,data))
215 goto err;
216
217 if ((ex != NULL) && (*ex == NULL)) *ex=ret;
218 return(ret);
219err:
220 if ((ex == NULL) || (ret != *ex))
221 X509_EXTENSION_free(ret);
222 return(NULL);
223 }
224
225int X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj)
226 {
227 if ((ex == NULL) || (obj == NULL))
228 return(0);
229 ASN1_OBJECT_free(ex->object);
230 ex->object=OBJ_dup(obj);
231 return(1);
232 }
233
234int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit)
235 {
236 if (ex == NULL) return(0);
237 ex->critical=(crit)?0xFF:0;
238 return(1);
239 }
240
241int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)
242 {
243 int i;
244
245 if (ex == NULL) return(0);
246 i=M_ASN1_OCTET_STRING_set(ex->value,data->data,data->length);
247 if (!i) return(0);
248 return(1);
249 }
250
251ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex)
252 {
253 if (ex == NULL) return(NULL);
254 return(ex->object);
255 }
256
257ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex)
258 {
259 if (ex == NULL) return(NULL);
260 return(ex->value);
261 }
262
263int X509_EXTENSION_get_critical(X509_EXTENSION *ex)
264 {
265 if (ex == NULL) return(0);
266 return(ex->critical);
267 }
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
deleted file mode 100644
index 3ddb2303d3..0000000000
--- a/src/lib/libcrypto/x509/x509_vfy.c
+++ /dev/null
@@ -1,815 +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
63#include "cryptlib.h"
64#include <openssl/crypto.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/x509v3.h>
71#include <openssl/objects.h>
72
73static int null_callback(int ok,X509_STORE_CTX *e);
74static int check_chain_purpose(X509_STORE_CTX *ctx);
75static int check_trust(X509_STORE_CTX *ctx);
76static int internal_verify(X509_STORE_CTX *ctx);
77const char *X509_version="X.509" OPENSSL_VERSION_PTEXT;
78
79static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_store_ctx_method=NULL;
80static int x509_store_ctx_num=0;
81#if 0
82static int x509_store_num=1;
83static STACK *x509_store_method=NULL;
84#endif
85
86static int null_callback(int ok, X509_STORE_CTX *e)
87 {
88 return(ok);
89 }
90
91#if 0
92static int x509_subject_cmp(X509 **a, X509 **b)
93 {
94 return(X509_subject_name_cmp(*a,*b));
95 }
96#endif
97
98int X509_verify_cert(X509_STORE_CTX *ctx)
99 {
100 X509 *x,*xtmp,*chain_ss=NULL;
101 X509_NAME *xn;
102 X509_OBJECT obj;
103 int depth,i,ok=0;
104 int num;
105 int (*cb)();
106 STACK_OF(X509) *sktmp=NULL;
107
108 if (ctx->cert == NULL)
109 {
110 X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
111 return(-1);
112 }
113
114 cb=ctx->ctx->verify_cb;
115 if (cb == NULL) cb=null_callback;
116
117 /* first we make sure the chain we are going to build is
118 * present and that the first entry is in place */
119 if (ctx->chain == NULL)
120 {
121 if ( ((ctx->chain=sk_X509_new_null()) == NULL) ||
122 (!sk_X509_push(ctx->chain,ctx->cert)))
123 {
124 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
125 goto end;
126 }
127 CRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);
128 ctx->last_untrusted=1;
129 }
130
131 /* We use a temporary STACK so we can chop and hack at it */
132 if (ctx->untrusted != NULL
133 && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
134 {
135 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
136 goto end;
137 }
138
139 num=sk_X509_num(ctx->chain);
140 x=sk_X509_value(ctx->chain,num-1);
141 depth=ctx->depth;
142
143
144 for (;;)
145 {
146 /* If we have enough, we break */
147 if (depth < num) break; /* FIXME: If this happens, we should take
148 * note of it and, if appropriate, use the
149 * X509_V_ERR_CERT_CHAIN_TOO_LONG error
150 * code later.
151 */
152
153 /* If we are self signed, we break */
154 xn=X509_get_issuer_name(x);
155 if (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)
156 break;
157
158 /* If we were passed a cert chain, use it first */
159 if (ctx->untrusted != NULL)
160 {
161 xtmp=X509_find_by_subject(sktmp,xn);
162 if (xtmp != NULL)
163 {
164 if (!sk_X509_push(ctx->chain,xtmp))
165 {
166 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
167 goto end;
168 }
169 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
170 sk_X509_delete_ptr(sktmp,xtmp);
171 ctx->last_untrusted++;
172 x=xtmp;
173 num++;
174 /* reparse the full chain for
175 * the next one */
176 continue;
177 }
178 }
179 break;
180 }
181
182 /* at this point, chain should contain a list of untrusted
183 * certificates. We now need to add at least one trusted one,
184 * if possible, otherwise we complain. */
185
186 i=sk_X509_num(ctx->chain);
187 x=sk_X509_value(ctx->chain,i-1);
188 xn = X509_get_subject_name(x);
189 if (X509_NAME_cmp(xn,X509_get_issuer_name(x))
190 == 0)
191 {
192 /* we have a self signed certificate */
193 if (sk_X509_num(ctx->chain) == 1)
194 {
195 /* We have a single self signed certificate: see if
196 * we can find it in the store. We must have an exact
197 * match to avoid possible impersonation.
198 */
199 ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);
200 if ((ok != X509_LU_X509) || X509_cmp(x, obj.data.x509))
201 {
202 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
203 ctx->current_cert=x;
204 ctx->error_depth=i-1;
205 if(ok == X509_LU_X509) X509_OBJECT_free_contents(&obj);
206 ok=cb(0,ctx);
207 if (!ok) goto end;
208 }
209 else
210 {
211 /* We have a match: replace certificate with store version
212 * so we get any trust settings.
213 */
214 X509_free(x);
215 x = obj.data.x509;
216 sk_X509_set(ctx->chain, i - 1, x);
217 ctx->last_untrusted=0;
218 }
219 }
220 else
221 {
222 /* worry more about this one elsewhere */
223 chain_ss=sk_X509_pop(ctx->chain);
224 ctx->last_untrusted--;
225 num--;
226 x=sk_X509_value(ctx->chain,num-1);
227 }
228 }
229
230 /* We now lookup certs from the certificate store */
231 for (;;)
232 {
233 /* If we have enough, we break */
234 if (depth < num) break;
235
236 /* If we are self signed, we break */
237 xn=X509_get_issuer_name(x);
238 if (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)
239 break;
240
241 ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);
242 if (ok != X509_LU_X509)
243 {
244 if (ok == X509_LU_RETRY)
245 {
246 X509_OBJECT_free_contents(&obj);
247 X509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);
248 return(ok);
249 }
250 else if (ok != X509_LU_FAIL)
251 {
252 X509_OBJECT_free_contents(&obj);
253 /* not good :-(, break anyway */
254 return(ok);
255 }
256 break;
257 }
258 x=obj.data.x509;
259 if (!sk_X509_push(ctx->chain,obj.data.x509))
260 {
261 X509_OBJECT_free_contents(&obj);
262 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
263 return(0);
264 }
265 num++;
266 }
267
268 /* we now have our chain, lets check it... */
269 xn=X509_get_issuer_name(x);
270 if (X509_NAME_cmp(X509_get_subject_name(x),xn) != 0)
271 {
272 if ((chain_ss == NULL) || (X509_NAME_cmp(X509_get_subject_name(chain_ss),xn) != 0))
273 {
274 if (ctx->last_untrusted >= num)
275 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
276 else
277 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;
278 ctx->current_cert=x;
279 }
280 else
281 {
282
283 sk_X509_push(ctx->chain,chain_ss);
284 num++;
285 ctx->last_untrusted=num;
286 ctx->current_cert=chain_ss;
287 ctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
288 chain_ss=NULL;
289 }
290
291 ctx->error_depth=num-1;
292 ok=cb(0,ctx);
293 if (!ok) goto end;
294 }
295
296 /* We have the chain complete: now we need to check its purpose */
297 if(ctx->purpose > 0) ok = check_chain_purpose(ctx);
298
299 if(!ok) goto end;
300
301 /* The chain extensions are OK: check trust */
302
303 if(ctx->trust > 0) ok = check_trust(ctx);
304
305 if(!ok) goto end;
306
307 /* We may as well copy down any DSA parameters that are required */
308 X509_get_pubkey_parameters(NULL,ctx->chain);
309
310 /* At this point, we have a chain and just need to verify it */
311 if (ctx->ctx->verify != NULL)
312 ok=ctx->ctx->verify(ctx);
313 else
314 ok=internal_verify(ctx);
315 if (0)
316 {
317end:
318 X509_get_pubkey_parameters(NULL,ctx->chain);
319 }
320 if (sktmp != NULL) sk_X509_free(sktmp);
321 if (chain_ss != NULL) X509_free(chain_ss);
322 return(ok);
323 }
324
325/* Check a certificate chains extensions for consistency
326 * with the supplied purpose
327 */
328
329static int check_chain_purpose(X509_STORE_CTX *ctx)
330{
331#ifdef NO_CHAIN_VERIFY
332 return 1;
333#else
334 int i, ok=0;
335 X509 *x;
336 int (*cb)();
337 cb=ctx->ctx->verify_cb;
338 if (cb == NULL) cb=null_callback;
339 /* Check all untrusted certificates */
340 for(i = 0; i < ctx->last_untrusted; i++) {
341 x = sk_X509_value(ctx->chain, i);
342 if(!X509_check_purpose(x, ctx->purpose, i)) {
343 if(i) ctx->error = X509_V_ERR_INVALID_CA;
344 else ctx->error = X509_V_ERR_INVALID_PURPOSE;
345 ctx->error_depth = i;
346 ctx->current_cert = x;
347 ok=cb(0,ctx);
348 if(!ok) goto end;
349 }
350 /* Check pathlen */
351 if((i > 1) && (x->ex_pathlen != -1)
352 && (i > (x->ex_pathlen + 1))) {
353 ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
354 ctx->error_depth = i;
355 ctx->current_cert = x;
356 ok=cb(0,ctx);
357 if(!ok) goto end;
358 }
359 }
360 ok = 1;
361 end:
362 return(ok);
363#endif
364}
365
366static int check_trust(X509_STORE_CTX *ctx)
367{
368#ifdef NO_CHAIN_VERIFY
369 return 1;
370#else
371 int i, ok;
372 X509 *x;
373 int (*cb)();
374 cb=ctx->ctx->verify_cb;
375 if (cb == NULL) cb=null_callback;
376/* For now just check the last certificate in the chain */
377 i = sk_X509_num(ctx->chain) - 1;
378 x = sk_X509_value(ctx->chain, i);
379 ok = X509_check_trust(x, ctx->trust, 0);
380 if(ok == X509_TRUST_TRUSTED) return 1;
381 ctx->error_depth = sk_X509_num(ctx->chain) - 1;
382 ctx->current_cert = x;
383 if(ok == X509_TRUST_REJECTED) ctx->error = X509_V_ERR_CERT_REJECTED;
384 else ctx->error = X509_V_ERR_CERT_UNTRUSTED;
385 ok = cb(0, ctx);
386 return(ok);
387#endif
388}
389
390static int internal_verify(X509_STORE_CTX *ctx)
391 {
392 int i,ok=0,n;
393 X509 *xs,*xi;
394 EVP_PKEY *pkey=NULL;
395 int (*cb)();
396
397 cb=ctx->ctx->verify_cb;
398 if (cb == NULL) cb=null_callback;
399
400 n=sk_X509_num(ctx->chain);
401 ctx->error_depth=n-1;
402 n--;
403 xi=sk_X509_value(ctx->chain,n);
404 if (X509_NAME_cmp(X509_get_subject_name(xi),
405 X509_get_issuer_name(xi)) == 0)
406 xs=xi;
407 else
408 {
409 if (n <= 0)
410 {
411 ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
412 ctx->current_cert=xi;
413 ok=cb(0,ctx);
414 goto end;
415 }
416 else
417 {
418 n--;
419 ctx->error_depth=n;
420 xs=sk_X509_value(ctx->chain,n);
421 }
422 }
423
424/* ctx->error=0; not needed */
425 while (n >= 0)
426 {
427 ctx->error_depth=n;
428 if (!xs->valid)
429 {
430 if ((pkey=X509_get_pubkey(xi)) == NULL)
431 {
432 ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
433 ctx->current_cert=xi;
434 ok=(*cb)(0,ctx);
435 if (!ok) goto end;
436 }
437 if (X509_verify(xs,pkey) <= 0)
438 {
439 ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
440 ctx->current_cert=xs;
441 ok=(*cb)(0,ctx);
442 if (!ok)
443 {
444 EVP_PKEY_free(pkey);
445 goto end;
446 }
447 }
448 EVP_PKEY_free(pkey);
449 pkey=NULL;
450
451 i=X509_cmp_current_time(X509_get_notBefore(xs));
452 if (i == 0)
453 {
454 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
455 ctx->current_cert=xs;
456 ok=(*cb)(0,ctx);
457 if (!ok) goto end;
458 }
459 if (i > 0)
460 {
461 ctx->error=X509_V_ERR_CERT_NOT_YET_VALID;
462 ctx->current_cert=xs;
463 ok=(*cb)(0,ctx);
464 if (!ok) goto end;
465 }
466 xs->valid=1;
467 }
468
469 i=X509_cmp_current_time(X509_get_notAfter(xs));
470 if (i == 0)
471 {
472 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
473 ctx->current_cert=xs;
474 ok=(*cb)(0,ctx);
475 if (!ok) goto end;
476 }
477
478 if (i < 0)
479 {
480 ctx->error=X509_V_ERR_CERT_HAS_EXPIRED;
481 ctx->current_cert=xs;
482 ok=(*cb)(0,ctx);
483 if (!ok) goto end;
484 }
485
486 /* CRL CHECK */
487
488 /* The last error (if any) is still in the error value */
489 ctx->current_cert=xs;
490 ok=(*cb)(1,ctx);
491 if (!ok) goto end;
492
493 n--;
494 if (n >= 0)
495 {
496 xi=xs;
497 xs=sk_X509_value(ctx->chain,n);
498 }
499 }
500 ok=1;
501end:
502 return(ok);
503 }
504
505int X509_cmp_current_time(ASN1_UTCTIME *ctm)
506 {
507 char *str;
508 ASN1_UTCTIME atm;
509 time_t offset;
510 char buff1[24],buff2[24],*p;
511 int i,j;
512
513 p=buff1;
514 i=ctm->length;
515 str=(char *)ctm->data;
516 if ((i < 11) || (i > 17)) return(0);
517 memcpy(p,str,10);
518 p+=10;
519 str+=10;
520
521 if ((*str == 'Z') || (*str == '-') || (*str == '+'))
522 { *(p++)='0'; *(p++)='0'; }
523 else { *(p++)= *(str++); *(p++)= *(str++); }
524 *(p++)='Z';
525 *(p++)='\0';
526
527 if (*str == 'Z')
528 offset=0;
529 else
530 {
531 if ((*str != '+') && (str[5] != '-'))
532 return(0);
533 offset=((str[1]-'0')*10+(str[2]-'0'))*60;
534 offset+=(str[3]-'0')*10+(str[4]-'0');
535 if (*str == '-')
536 offset= -offset;
537 }
538 atm.type=V_ASN1_UTCTIME;
539 atm.length=sizeof(buff2);
540 atm.data=(unsigned char *)buff2;
541
542 X509_gmtime_adj(&atm,-offset*60);
543
544 i=(buff1[0]-'0')*10+(buff1[1]-'0');
545 if (i < 50) i+=100; /* cf. RFC 2459 */
546 j=(buff2[0]-'0')*10+(buff2[1]-'0');
547 if (j < 50) j+=100;
548
549 if (i < j) return (-1);
550 if (i > j) return (1);
551 i=strcmp(buff1,buff2);
552 if (i == 0) /* wait a second then return younger :-) */
553 return(-1);
554 else
555 return(i);
556 }
557
558ASN1_UTCTIME *X509_gmtime_adj(ASN1_UTCTIME *s, long adj)
559 {
560 time_t t;
561
562 time(&t);
563 t+=adj;
564 return(ASN1_UTCTIME_set(s,t));
565 }
566
567int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
568 {
569 EVP_PKEY *ktmp=NULL,*ktmp2;
570 int i,j;
571
572 if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return(1);
573
574 for (i=0; i<sk_X509_num(chain); i++)
575 {
576 ktmp=X509_get_pubkey(sk_X509_value(chain,i));
577 if (ktmp == NULL)
578 {
579 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);
580 return(0);
581 }
582 if (!EVP_PKEY_missing_parameters(ktmp))
583 break;
584 else
585 {
586 EVP_PKEY_free(ktmp);
587 ktmp=NULL;
588 }
589 }
590 if (ktmp == NULL)
591 {
592 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN);
593 return(0);
594 }
595
596 /* first, populate the other certs */
597 for (j=i-1; j >= 0; j--)
598 {
599 ktmp2=X509_get_pubkey(sk_X509_value(chain,j));
600 EVP_PKEY_copy_parameters(ktmp2,ktmp);
601 EVP_PKEY_free(ktmp2);
602 }
603
604 if (pkey != NULL) EVP_PKEY_copy_parameters(pkey,ktmp);
605 EVP_PKEY_free(ktmp);
606 return(1);
607 }
608
609int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
610 {
611 X509_OBJECT *obj,*r;
612 int ret=1;
613
614 if (x == NULL) return(0);
615 obj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));
616 if (obj == NULL)
617 {
618 X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);
619 return(0);
620 }
621 obj->type=X509_LU_X509;
622 obj->data.x509=x;
623
624 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
625
626 X509_OBJECT_up_ref_count(obj);
627
628 r=(X509_OBJECT *)lh_insert(ctx->certs,obj);
629 if (r != NULL)
630 { /* oops, put it back */
631 lh_delete(ctx->certs,obj);
632 X509_OBJECT_free_contents(obj);
633 Free(obj);
634 lh_insert(ctx->certs,r);
635 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);
636 ret=0;
637 }
638
639 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
640
641 return(ret);
642 }
643
644int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
645 {
646 X509_OBJECT *obj,*r;
647 int ret=1;
648
649 if (x == NULL) return(0);
650 obj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));
651 if (obj == NULL)
652 {
653 X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE);
654 return(0);
655 }
656 obj->type=X509_LU_CRL;
657 obj->data.crl=x;
658
659 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
660
661 X509_OBJECT_up_ref_count(obj);
662
663 r=(X509_OBJECT *)lh_insert(ctx->certs,obj);
664 if (r != NULL)
665 { /* oops, put it back */
666 lh_delete(ctx->certs,obj);
667 X509_OBJECT_free_contents(obj);
668 Free(obj);
669 lh_insert(ctx->certs,r);
670 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE);
671 ret=0;
672 }
673
674 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
675
676 return(ret);
677 }
678
679int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
680 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
681 {
682 x509_store_ctx_num++;
683 return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1,
684 &x509_store_ctx_method,
685 argl,argp,new_func,dup_func,free_func));
686 }
687
688int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data)
689 {
690 return(CRYPTO_set_ex_data(&ctx->ex_data,idx,data));
691 }
692
693void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx)
694 {
695 return(CRYPTO_get_ex_data(&ctx->ex_data,idx));
696 }
697
698int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx)
699 {
700 return(ctx->error);
701 }
702
703void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err)
704 {
705 ctx->error=err;
706 }
707
708int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx)
709 {
710 return(ctx->error_depth);
711 }
712
713X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx)
714 {
715 return(ctx->current_cert);
716 }
717
718STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx)
719 {
720 return(ctx->chain);
721 }
722
723STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
724 {
725 int i;
726 X509 *x;
727 STACK_OF(X509) *chain;
728 if(!ctx->chain || !(chain = sk_X509_dup(ctx->chain))) return NULL;
729 for(i = 0; i < sk_X509_num(chain); i++) {
730 x = sk_X509_value(chain, i);
731 CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
732 }
733 return(chain);
734 }
735
736void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)
737 {
738 ctx->cert=x;
739 }
740
741void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
742 {
743 ctx->untrusted=sk;
744 }
745
746int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose)
747 {
748 return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0);
749 }
750
751int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust)
752 {
753 return X509_STORE_CTX_purpose_inherit(ctx, 0, 0, trust);
754 }
755
756/* This function is used to set the X509_STORE_CTX purpose and trust
757 * values. This is intended to be used when another structure has its
758 * own trust and purpose values which (if set) will be inherited by
759 * the ctx. If they aren't set then we will usually have a default
760 * purpose in mind which should then be used to set the trust value.
761 * An example of this is SSL use: an SSL structure will have its own
762 * purpose and trust settings which the application can set: if they
763 * aren't set then we use the default of SSL client/server.
764 */
765
766int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
767 int purpose, int trust)
768{
769 int idx;
770 /* If purpose not set use default */
771 if(!purpose) purpose = def_purpose;
772 /* If we have a purpose then check it is valid */
773 if(purpose) {
774 X509_PURPOSE *ptmp;
775 idx = X509_PURPOSE_get_by_id(purpose);
776 if(idx == -1) {
777 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
778 X509_R_UNKNOWN_PURPOSE_ID);
779 return 0;
780 }
781 ptmp = X509_PURPOSE_get0(idx);
782 if(ptmp->trust == X509_TRUST_DEFAULT) {
783 idx = X509_PURPOSE_get_by_id(def_purpose);
784 if(idx == -1) {
785 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
786 X509_R_UNKNOWN_PURPOSE_ID);
787 return 0;
788 }
789 ptmp = X509_PURPOSE_get0(idx);
790 }
791 /* If trust not set then get from purpose default */
792 if(!trust) trust = ptmp->trust;
793 }
794 if(trust) {
795 idx = X509_TRUST_get_by_id(trust);
796 if(idx == -1) {
797 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
798 X509_R_UNKNOWN_TRUST_ID);
799 return 0;
800 }
801 }
802
803 if(purpose) ctx->purpose = purpose;
804 if(trust) ctx->trust = trust;
805 return 1;
806}
807
808
809IMPLEMENT_STACK_OF(X509)
810IMPLEMENT_ASN1_SET_OF(X509)
811
812IMPLEMENT_STACK_OF(X509_NAME)
813
814IMPLEMENT_STACK_OF(X509_ATTRIBUTE)
815IMPLEMENT_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 4637aecedf..0000000000
--- a/src/lib/libcrypto/x509/x509_vfy.h
+++ /dev/null
@@ -1,362 +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 int purpose; /* purpose to check untrusted certificates */
206 int trust; /* trust setting to check */
207
208 /* The following is built up */
209 int depth; /* how far to go looking up certs */
210 int valid; /* if 0, rebuild chain */
211 int last_untrusted; /* index of last untrusted cert */
212 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */
213
214 /* When something goes wrong, this is why */
215 int error_depth;
216 int error;
217 X509 *current_cert;
218
219 CRYPTO_EX_DATA ex_data;
220 };
221
222#define X509_STORE_CTX_set_depth(ctx,d) ((ctx)->depth=(d))
223
224#define X509_STORE_CTX_set_app_data(ctx,data) \
225 X509_STORE_CTX_set_ex_data(ctx,0,data)
226#define X509_STORE_CTX_get_app_data(ctx) \
227 X509_STORE_CTX_get_ex_data(ctx,0)
228
229#define X509_L_FILE_LOAD 1
230#define X509_L_ADD_DIR 2
231
232#define X509_LOOKUP_load_file(x,name,type) \
233 X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL)
234
235#define X509_LOOKUP_add_dir(x,name,type) \
236 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)
237
238#define X509_V_OK 0
239/* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */
240
241#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
242#define X509_V_ERR_UNABLE_TO_GET_CRL 3
243#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4
244#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5
245#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6
246#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7
247#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8
248#define X509_V_ERR_CERT_NOT_YET_VALID 9
249#define X509_V_ERR_CERT_HAS_EXPIRED 10
250#define X509_V_ERR_CRL_NOT_YET_VALID 11
251#define X509_V_ERR_CRL_HAS_EXPIRED 12
252#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13
253#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14
254#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15
255#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16
256#define X509_V_ERR_OUT_OF_MEM 17
257#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18
258#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19
259#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20
260#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21
261#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22
262#define X509_V_ERR_CERT_REVOKED 23
263#define X509_V_ERR_INVALID_CA 24
264#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25
265#define X509_V_ERR_INVALID_PURPOSE 26
266#define X509_V_ERR_CERT_UNTRUSTED 27
267#define X509_V_ERR_CERT_REJECTED 28
268
269/* The application is not happy */
270#define X509_V_ERR_APPLICATION_VERIFICATION 50
271
272 /* These functions are being redefined in another directory,
273 and clash when the linker is case-insensitive, so let's
274 hide them a little, by giving them an extra 'o' at the
275 beginning of the name... */
276#ifdef VMS
277#undef X509v3_cleanup_extensions
278#define X509v3_cleanup_extensions oX509v3_cleanup_extensions
279#undef X509v3_add_extension
280#define X509v3_add_extension oX509v3_add_extension
281#undef X509v3_add_netscape_extensions
282#define X509v3_add_netscape_extensions oX509v3_add_netscape_extensions
283#undef X509v3_add_standard_extensions
284#define X509v3_add_standard_extensions oX509v3_add_standard_extensions
285#endif
286
287#ifdef HEADER_LHASH_H
288X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h,int type,X509_NAME *name);
289#endif
290void X509_OBJECT_up_ref_count(X509_OBJECT *a);
291void X509_OBJECT_free_contents(X509_OBJECT *a);
292X509_STORE *X509_STORE_new(void );
293void X509_STORE_free(X509_STORE *v);
294
295X509_STORE_CTX *X509_STORE_CTX_new(void);
296void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
297void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
298 X509 *x509, STACK_OF(X509) *chain);
299void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
300
301X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);
302
303X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
304X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
305
306int X509_STORE_add_cert(X509_STORE *ctx, X509 *x);
307int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x);
308
309int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name,
310 X509_OBJECT *ret);
311
312int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
313 long argl, char **ret);
314
315#ifndef NO_STDIO
316int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
317int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
318int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type);
319#endif
320
321
322X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
323void X509_LOOKUP_free(X509_LOOKUP *ctx);
324int X509_LOOKUP_init(X509_LOOKUP *ctx);
325int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
326 X509_OBJECT *ret);
327int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
328 ASN1_INTEGER *serial, X509_OBJECT *ret);
329int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
330 unsigned char *bytes, int len, X509_OBJECT *ret);
331int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str,
332 int len, X509_OBJECT *ret);
333int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
334
335#ifndef NO_STDIO
336int X509_STORE_load_locations (X509_STORE *ctx,
337 const char *file, const char *dir);
338int X509_STORE_set_default_paths(X509_STORE *ctx);
339#endif
340
341int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
342 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
343int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data);
344void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
345int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
346void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
347int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
348X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
349STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
350STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
351void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
352void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);
353int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
354int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
355int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
356 int purpose, int trust);
357
358#ifdef __cplusplus
359}
360#endif
361#endif
362
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c
deleted file mode 100644
index 4c20e03ece..0000000000
--- a/src/lib/libcrypto/x509/x509name.c
+++ /dev/null
@@ -1,383 +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
174int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
175 unsigned char *bytes, int len, int loc, int set)
176{
177 X509_NAME_ENTRY *ne;
178 int ret;
179 ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len);
180 if(!ne) return 0;
181 ret = X509_NAME_add_entry(name, ne, loc, set);
182 X509_NAME_ENTRY_free(ne);
183 return ret;
184}
185
186int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
187 unsigned char *bytes, int len, int loc, int set)
188{
189 X509_NAME_ENTRY *ne;
190 int ret;
191 ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len);
192 if(!ne) return 0;
193 ret = X509_NAME_add_entry(name, ne, loc, set);
194 X509_NAME_ENTRY_free(ne);
195 return ret;
196}
197
198int X509_NAME_add_entry_by_txt(X509_NAME *name, char *field, int type,
199 unsigned char *bytes, int len, int loc, int set)
200{
201 X509_NAME_ENTRY *ne;
202 int ret;
203 ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len);
204 if(!ne) return 0;
205 ret = X509_NAME_add_entry(name, ne, loc, set);
206 X509_NAME_ENTRY_free(ne);
207 return ret;
208}
209
210/* if set is -1, append to previous set, 0 'a new one', and 1,
211 * prepend to the guy we are about to stomp on. */
212int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
213 int set)
214 {
215 X509_NAME_ENTRY *new_name=NULL;
216 int n,i,inc;
217 STACK_OF(X509_NAME_ENTRY) *sk;
218
219 if (name == NULL) return(0);
220 sk=name->entries;
221 n=sk_X509_NAME_ENTRY_num(sk);
222 if (loc > n) loc=n;
223 else if (loc < 0) loc=n;
224
225 name->modified=1;
226
227 if (set == -1)
228 {
229 if (loc == 0)
230 {
231 set=0;
232 inc=1;
233 }
234 else
235 {
236 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set;
237 inc=0;
238 }
239 }
240 else /* if (set >= 0) */
241 {
242 if (loc >= n)
243 {
244 if (loc != 0)
245 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set+1;
246 else
247 set=0;
248 }
249 else
250 set=sk_X509_NAME_ENTRY_value(sk,loc)->set;
251 inc=(set == 0)?1:0;
252 }
253
254 if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL)
255 goto err;
256 new_name->set=set;
257 if (!sk_X509_NAME_ENTRY_insert(sk,new_name,loc))
258 {
259 X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE);
260 goto err;
261 }
262 if (inc)
263 {
264 n=sk_X509_NAME_ENTRY_num(sk);
265 for (i=loc+1; i<n; i++)
266 sk_X509_NAME_ENTRY_value(sk,i-1)->set+=1;
267 }
268 return(1);
269err:
270 if (new_name != NULL)
271 X509_NAME_ENTRY_free(new_name);
272 return(0);
273 }
274
275X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
276 char *field, int type, unsigned char *bytes, int len)
277 {
278 ASN1_OBJECT *obj;
279 X509_NAME_ENTRY *nentry;
280
281 obj=OBJ_txt2obj(field, 0);
282 if (obj == NULL)
283 {
284 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT,
285 X509_R_INVALID_FIELD_NAME);
286 ERR_add_error_data(2, "name=", field);
287 return(NULL);
288 }
289 nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len);
290 ASN1_OBJECT_free(obj);
291 return nentry;
292 }
293
294X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
295 int type, unsigned char *bytes, int len)
296 {
297 ASN1_OBJECT *obj;
298 X509_NAME_ENTRY *nentry;
299
300 obj=OBJ_nid2obj(nid);
301 if (obj == NULL)
302 {
303 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID);
304 return(NULL);
305 }
306 nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len);
307 ASN1_OBJECT_free(obj);
308 return nentry;
309 }
310
311X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
312 ASN1_OBJECT *obj, int type, unsigned char *bytes, int len)
313 {
314 X509_NAME_ENTRY *ret;
315
316 if ((ne == NULL) || (*ne == NULL))
317 {
318 if ((ret=X509_NAME_ENTRY_new()) == NULL)
319 return(NULL);
320 }
321 else
322 ret= *ne;
323
324 if (!X509_NAME_ENTRY_set_object(ret,obj))
325 goto err;
326 if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len))
327 goto err;
328
329 if ((ne != NULL) && (*ne == NULL)) *ne=ret;
330 return(ret);
331err:
332 if ((ne == NULL) || (ret != *ne))
333 X509_NAME_ENTRY_free(ret);
334 return(NULL);
335 }
336
337int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj)
338 {
339 if ((ne == NULL) || (obj == NULL))
340 {
341 X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,ERR_R_PASSED_NULL_PARAMETER);
342 return(0);
343 }
344 ASN1_OBJECT_free(ne->object);
345 ne->object=OBJ_dup(obj);
346 return((ne->object == NULL)?0:1);
347 }
348
349int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
350 unsigned char *bytes, int len)
351 {
352 int i;
353
354 if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0);
355 if((type > 0) && (type & MBSTRING_FLAG))
356 return ASN1_STRING_set_by_NID(&ne->value, bytes,
357 len, type,
358 OBJ_obj2nid(ne->object)) ? 1 : 0;
359 if (len < 0) len=strlen((char *)bytes);
360 i=ASN1_STRING_set(ne->value,bytes,len);
361 if (!i) return(0);
362 if (type != V_ASN1_UNDEF)
363 {
364 if (type == V_ASN1_APP_CHOOSE)
365 ne->value->type=ASN1_PRINTABLE_type(bytes,len);
366 else
367 ne->value->type=type;
368 }
369 return(1);
370 }
371
372ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne)
373 {
374 if (ne == NULL) return(NULL);
375 return(ne->object);
376 }
377
378ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
379 {
380 if (ne == NULL) return(NULL);
381 return(ne->value);
382 }
383
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/x509spki.c b/src/lib/libcrypto/x509/x509spki.c
deleted file mode 100644
index b35c3f92e7..0000000000
--- a/src/lib/libcrypto/x509/x509spki.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/* x509spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/asn1_mac.h>
63
64int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey)
65{
66 if ((x == NULL) || (x->spkac == NULL)) return(0);
67 return(X509_PUBKEY_set(&(x->spkac->pubkey),pkey));
68}
69
70EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x)
71{
72 if ((x == NULL) || (x->spkac == NULL))
73 return(NULL);
74 return(X509_PUBKEY_get(x->spkac->pubkey));
75}
76
77/* Load a Netscape SPKI from a base64 encoded string */
78
79NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len)
80{
81 unsigned char *spki_der, *p;
82 int spki_len;
83 NETSCAPE_SPKI *spki;
84 if(len <= 0) len = strlen(str);
85 if (!(spki_der = Malloc(len + 1))) {
86 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89 spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len);
90 if(spki_len < 0) {
91 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE,
92 X509_R_BASE64_DECODE_ERROR);
93 Free(spki_der);
94 return NULL;
95 }
96 p = spki_der;
97 spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len);
98 Free(spki_der);
99 return spki;
100}
101
102/* Generate a base64 encoded string from an SPKI */
103
104char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
105{
106 unsigned char *der_spki, *p;
107 char *b64_str;
108 int der_len;
109 der_len = i2d_NETSCAPE_SPKI(spki, NULL);
110 der_spki = Malloc(der_len);
111 b64_str = Malloc(der_len * 2);
112 if(!der_spki || !b64_str) {
113 X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE);
114 return NULL;
115 }
116 p = der_spki;
117 i2d_NETSCAPE_SPKI(spki, &p);
118 EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len);
119 Free(der_spki);
120 return b64_str;
121}
diff --git a/src/lib/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 d2bf3c8e1c..0000000000
--- a/src/lib/libcrypto/x509/x_all.c
+++ /dev/null
@@ -1,531 +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
288RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa)
289 {
290 return((RSA *)ASN1_d2i_fp((char *(*)())
291 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (fp),
292 (unsigned char **)(rsa)));
293 }
294
295int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
296 {
297 return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa));
298 }
299
300int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa)
301 {
302 return(ASN1_i2d_fp(i2d_RSA_PUBKEY,fp,(unsigned char *)rsa));
303 }
304#endif
305
306RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa)
307 {
308 return((RSA *)ASN1_d2i_bio((char *(*)())
309 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp),
310 (unsigned char **)(rsa)));
311 }
312
313int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa)
314 {
315 return(ASN1_i2d_bio(i2d_RSAPrivateKey,bp,(unsigned char *)rsa));
316 }
317
318RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa)
319 {
320 return((RSA *)ASN1_d2i_bio((char *(*)())
321 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp),
322 (unsigned char **)(rsa)));
323 }
324
325RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa)
326 {
327 return((RSA *)ASN1_d2i_bio((char *(*)())
328 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (bp),
329 (unsigned char **)(rsa)));
330 }
331
332int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
333 {
334 return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa));
335 }
336
337int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
338 {
339 return(ASN1_i2d_bio(i2d_RSA_PUBKEY,bp,(unsigned char *)rsa));
340 }
341#endif
342
343#ifndef NO_DSA
344#ifndef NO_FP_API
345DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa)
346 {
347 return((DSA *)ASN1_d2i_fp((char *(*)())
348 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp),
349 (unsigned char **)(dsa)));
350 }
351
352int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
353 {
354 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
355 }
356
357DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa)
358 {
359 return((DSA *)ASN1_d2i_fp((char *(*)())
360 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (fp),
361 (unsigned char **)(dsa)));
362 }
363
364int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa)
365 {
366 return(ASN1_i2d_fp(i2d_DSA_PUBKEY,fp,(unsigned char *)dsa));
367 }
368#endif
369
370DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa)
371 {
372 return((DSA *)ASN1_d2i_bio((char *(*)())
373 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp),
374 (unsigned char **)(dsa)));
375 }
376
377int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa)
378 {
379 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
380 }
381
382DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa)
383 {
384 return((DSA *)ASN1_d2i_bio((char *(*)())
385 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (bp),
386 (unsigned char **)(dsa)));
387 }
388
389int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa)
390 {
391 return(ASN1_i2d_bio(i2d_DSA_PUBKEY,bp,(unsigned char *)dsa));
392 }
393
394#endif
395
396X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn)
397 {
398 return((X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,
399 (char *(*)())d2i_X509_ALGOR,(char *)xn));
400 }
401
402X509_NAME *X509_NAME_dup(X509_NAME *xn)
403 {
404 return((X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME,
405 (char *(*)())d2i_X509_NAME,(char *)xn));
406 }
407
408X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne)
409 {
410 return((X509_NAME_ENTRY *)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY,
411 (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne));
412 }
413
414int X509_digest(X509 *data, const EVP_MD *type, unsigned char *md,
415 unsigned int *len)
416 {
417 return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len));
418 }
419
420int X509_NAME_digest(X509_NAME *data, const EVP_MD *type, unsigned char *md,
421 unsigned int *len)
422 {
423 return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len));
424 }
425
426int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type,
427 unsigned char *md, unsigned int *len)
428 {
429 return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,
430 (char *)data,md,len));
431 }
432
433
434#ifndef NO_FP_API
435X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8)
436 {
437 return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new,
438 (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8)));
439 }
440
441int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8)
442 {
443 return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8));
444 }
445#endif
446
447X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8)
448 {
449 return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new,
450 (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8)));
451 }
452
453int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8)
454 {
455 return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8));
456 }
457
458#ifndef NO_FP_API
459PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
460 PKCS8_PRIV_KEY_INFO **p8inf)
461 {
462 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp(
463 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
464 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp),
465 (unsigned char **)(p8inf)));
466 }
467
468int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
469 {
470 return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf));
471 }
472
473int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key)
474 {
475 PKCS8_PRIV_KEY_INFO *p8inf;
476 int ret;
477 p8inf = EVP_PKEY2PKCS8(key);
478 if(!p8inf) return 0;
479 ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf);
480 PKCS8_PRIV_KEY_INFO_free(p8inf);
481 return ret;
482 }
483
484int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey)
485 {
486 return(ASN1_i2d_fp(i2d_PrivateKey,fp,(unsigned char *)pkey));
487 }
488
489EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
490{
491 return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new,
492 (char *(*)())d2i_AutoPrivateKey, (fp),(unsigned char **)(a)));
493}
494
495#endif
496
497PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
498 PKCS8_PRIV_KEY_INFO **p8inf)
499 {
500 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio(
501 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
502 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp),
503 (unsigned char **)(p8inf)));
504 }
505
506int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
507 {
508 return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf));
509 }
510
511int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
512 {
513 PKCS8_PRIV_KEY_INFO *p8inf;
514 int ret;
515 p8inf = EVP_PKEY2PKCS8(key);
516 if(!p8inf) return 0;
517 ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
518 PKCS8_PRIV_KEY_INFO_free(p8inf);
519 return ret;
520 }
521
522int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey)
523 {
524 return(ASN1_i2d_bio(i2d_PrivateKey,bp,(unsigned char *)pkey));
525 }
526
527EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a)
528 {
529 return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new,
530 (char *(*)())d2i_AutoPrivateKey, (bp),(unsigned char **)(a)));
531 }
diff --git a/src/lib/libcrypto/x509v3/ext_dat.h b/src/lib/libcrypto/x509v3/ext_dat.h
deleted file mode 100644
index 801a585a52..0000000000
--- a/src/lib/libcrypto/x509v3/ext_dat.h
+++ /dev/null
@@ -1,97 +0,0 @@
1/* ext_dat.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* This file contains a table of "standard" extensions */
59
60extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
61extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet, v3_info;
62extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
63extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld;
64
65/* This table will be searched using OBJ_bsearch so it *must* kept in
66 * order of the ext_nid values.
67 */
68
69static X509V3_EXT_METHOD *standard_exts[] = {
70&v3_nscert,
71&v3_ns_ia5_list[0],
72&v3_ns_ia5_list[1],
73&v3_ns_ia5_list[2],
74&v3_ns_ia5_list[3],
75&v3_ns_ia5_list[4],
76&v3_ns_ia5_list[5],
77&v3_ns_ia5_list[6],
78&v3_skey_id,
79&v3_key_usage,
80&v3_pkey_usage_period,
81&v3_alt[0],
82&v3_alt[1],
83&v3_bcons,
84&v3_crl_num,
85&v3_cpols,
86&v3_akey_id,
87&v3_crld,
88&v3_ext_ku,
89&v3_crl_reason,
90&v3_sxnet,
91&v3_info,
92};
93
94/* Number of standard extensions */
95
96#define STANDARD_EXTENSION_COUNT (sizeof(standard_exts)/sizeof(X509V3_EXT_METHOD *))
97
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c
deleted file mode 100644
index 96c04fe4f5..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 M_ASN1_OCTET_STRING_free(a->keyid);
133 sk_GENERAL_NAME_pop_free(a->issuer, GENERAL_NAME_free);
134 M_ASN1_INTEGER_free (a->serial);
135 Free (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 = M_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);
244M_ASN1_INTEGER_free(serial);
245M_ASN1_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 5ccd1e0e3d..0000000000
--- a/src/lib/libcrypto/x509v3/v3_alt.c
+++ /dev/null
@@ -1,401 +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},
87};
88
89STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
90 STACK_OF(GENERAL_NAME) *gens, STACK_OF(CONF_VALUE) *ret)
91{
92 int i;
93 GENERAL_NAME *gen;
94 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
95 gen = sk_GENERAL_NAME_value(gens, i);
96 ret = i2v_GENERAL_NAME(method, gen, ret);
97 }
98 if(!ret) return sk_CONF_VALUE_new_null();
99 return ret;
100}
101
102STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
103 GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret)
104{
105 char oline[256];
106 unsigned char *p;
107 switch (gen->type)
108 {
109 case GEN_OTHERNAME:
110 X509V3_add_value("othername","<unsupported>", &ret);
111 break;
112
113 case GEN_X400:
114 X509V3_add_value("X400Name","<unsupported>", &ret);
115 break;
116
117 case GEN_EDIPARTY:
118 X509V3_add_value("EdiPartyName","<unsupported>", &ret);
119 break;
120
121 case GEN_EMAIL:
122 X509V3_add_value_uchar("email",gen->d.ia5->data, &ret);
123 break;
124
125 case GEN_DNS:
126 X509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret);
127 break;
128
129 case GEN_URI:
130 X509V3_add_value_uchar("URI",gen->d.ia5->data, &ret);
131 break;
132
133 case GEN_DIRNAME:
134 X509_NAME_oneline(gen->d.dirn, oline, 256);
135 X509V3_add_value("DirName",oline, &ret);
136 break;
137
138 case GEN_IPADD:
139 p = gen->d.ip->data;
140 /* BUG: doesn't support IPV6 */
141 if(gen->d.ip->length != 4) {
142 X509V3_add_value("IP Address","<invalid>", &ret);
143 break;
144 }
145 sprintf(oline, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
146 X509V3_add_value("IP Address",oline, &ret);
147 break;
148
149 case GEN_RID:
150 i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
151 X509V3_add_value("Registered ID",oline, &ret);
152 break;
153 }
154 return ret;
155}
156
157static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method,
158 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
159{
160 STACK_OF(GENERAL_NAME) *gens = NULL;
161 CONF_VALUE *cnf;
162 int i;
163 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
164 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
165 return NULL;
166 }
167 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
168 cnf = sk_CONF_VALUE_value(nval, i);
169 if(!name_cmp(cnf->name, "issuer") && cnf->value &&
170 !strcmp(cnf->value, "copy")) {
171 if(!copy_issuer(ctx, gens)) goto err;
172 } else {
173 GENERAL_NAME *gen;
174 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
175 goto err;
176 sk_GENERAL_NAME_push(gens, gen);
177 }
178 }
179 return gens;
180 err:
181 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
182 return NULL;
183}
184
185/* Append subject altname of issuer to issuer alt name of subject */
186
187static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
188{
189 STACK_OF(GENERAL_NAME) *ialt;
190 GENERAL_NAME *gen;
191 X509_EXTENSION *ext;
192 int i;
193 if(ctx && (ctx->flags == CTX_TEST)) return 1;
194 if(!ctx || !ctx->issuer_cert) {
195 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_NO_ISSUER_DETAILS);
196 goto err;
197 }
198 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
199 if(i < 0) return 1;
200 if(!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
201 !(ialt = X509V3_EXT_d2i(ext)) ) {
202 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR);
203 goto err;
204 }
205
206 for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
207 gen = sk_GENERAL_NAME_value(ialt, i);
208 if(!sk_GENERAL_NAME_push(gens, gen)) {
209 X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE);
210 goto err;
211 }
212 }
213 sk_GENERAL_NAME_free(ialt);
214
215 return 1;
216
217 err:
218 return 0;
219
220}
221
222static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method,
223 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
224{
225 STACK_OF(GENERAL_NAME) *gens = NULL;
226 CONF_VALUE *cnf;
227 int i;
228 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
229 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
230 return NULL;
231 }
232 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
233 cnf = sk_CONF_VALUE_value(nval, i);
234 if(!name_cmp(cnf->name, "email") && cnf->value &&
235 !strcmp(cnf->value, "copy")) {
236 if(!copy_email(ctx, gens)) goto err;
237 } else {
238 GENERAL_NAME *gen;
239 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
240 goto err;
241 sk_GENERAL_NAME_push(gens, gen);
242 }
243 }
244 return gens;
245 err:
246 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
247 return NULL;
248}
249
250/* Copy any email addresses in a certificate or request to
251 * GENERAL_NAMES
252 */
253
254static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
255{
256 X509_NAME *nm;
257 ASN1_IA5STRING *email = NULL;
258 X509_NAME_ENTRY *ne;
259 GENERAL_NAME *gen = NULL;
260 int i;
261 if(ctx->flags == CTX_TEST) return 1;
262 if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
263 X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS);
264 goto err;
265 }
266 /* Find the subject name */
267 if(ctx->subject_cert) nm = X509_get_subject_name(ctx->subject_cert);
268 else nm = X509_REQ_get_subject_name(ctx->subject_req);
269
270 /* Now add any email address(es) to STACK */
271 i = -1;
272 while((i = X509_NAME_get_index_by_NID(nm,
273 NID_pkcs9_emailAddress, i)) > 0) {
274 ne = X509_NAME_get_entry(nm, i);
275 email = M_ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne));
276 if(!email || !(gen = GENERAL_NAME_new())) {
277 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
278 goto err;
279 }
280 gen->d.ia5 = email;
281 email = NULL;
282 gen->type = GEN_EMAIL;
283 if(!sk_GENERAL_NAME_push(gens, gen)) {
284 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
285 goto err;
286 }
287 gen = NULL;
288 }
289
290
291 return 1;
292
293 err:
294 GENERAL_NAME_free(gen);
295 M_ASN1_IA5STRING_free(email);
296 return 0;
297
298}
299
300STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
301 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
302{
303 GENERAL_NAME *gen;
304 STACK_OF(GENERAL_NAME) *gens = NULL;
305 CONF_VALUE *cnf;
306 int i;
307 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
308 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
309 return NULL;
310 }
311 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
312 cnf = sk_CONF_VALUE_value(nval, i);
313 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
314 sk_GENERAL_NAME_push(gens, gen);
315 }
316 return gens;
317 err:
318 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
319 return NULL;
320}
321
322GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
323 CONF_VALUE *cnf)
324{
325char is_string = 0;
326int type;
327GENERAL_NAME *gen = NULL;
328
329char *name, *value;
330
331name = cnf->name;
332value = cnf->value;
333
334if(!value) {
335 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE);
336 return NULL;
337}
338
339if(!(gen = GENERAL_NAME_new())) {
340 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
341 return NULL;
342}
343
344if(!name_cmp(name, "email")) {
345 is_string = 1;
346 type = GEN_EMAIL;
347} else if(!name_cmp(name, "URI")) {
348 is_string = 1;
349 type = GEN_URI;
350} else if(!name_cmp(name, "DNS")) {
351 is_string = 1;
352 type = GEN_DNS;
353} else if(!name_cmp(name, "RID")) {
354 ASN1_OBJECT *obj;
355 if(!(obj = OBJ_txt2obj(value,0))) {
356 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT);
357 ERR_add_error_data(2, "value=", value);
358 goto err;
359 }
360 gen->d.rid = obj;
361 type = GEN_RID;
362} else if(!name_cmp(name, "IP")) {
363 int i1,i2,i3,i4;
364 unsigned char ip[4];
365 if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) ||
366 (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) ||
367 (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) {
368 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS);
369 ERR_add_error_data(2, "value=", value);
370 goto err;
371 }
372 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4;
373 if(!(gen->d.ip = M_ASN1_OCTET_STRING_new()) ||
374 !ASN1_STRING_set(gen->d.ip, ip, 4)) {
375 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
376 goto err;
377 }
378 type = GEN_IPADD;
379} else {
380 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION);
381 ERR_add_error_data(2, "name=", name);
382 goto err;
383}
384
385if(is_string) {
386 if(!(gen->d.ia5 = M_ASN1_IA5STRING_new()) ||
387 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
388 strlen(value))) {
389 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
390 goto err;
391 }
392}
393
394gen->type = type;
395
396return gen;
397
398err:
399GENERAL_NAME_free(gen);
400return NULL;
401}
diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c
deleted file mode 100644
index 1e3edc205f..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 M_ASN1_INTEGER_free (a->pathlen);
126 Free (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 0e1167d05c..0000000000
--- a/src/lib/libcrypto/x509v3/v3_bitst.c
+++ /dev/null
@@ -1,141 +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 *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
65 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
67 ASN1_BIT_STRING *bits,
68 STACK_OF(CONF_VALUE) *extlist);
69static BIT_STRING_BITNAME ns_cert_type_table[] = {
70{0, "SSL Client", "client"},
71{1, "SSL Server", "server"},
72{2, "S/MIME", "email"},
73{3, "Object Signing", "objsign"},
74{4, "Unused", "reserved"},
75{5, "SSL CA", "sslCA"},
76{6, "S/MIME CA", "emailCA"},
77{7, "Object Signing CA", "objCA"},
78{-1, NULL, NULL}
79};
80
81static BIT_STRING_BITNAME key_usage_type_table[] = {
82{0, "Digital Signature", "digitalSignature"},
83{1, "Non Repudiation", "nonRepudiation"},
84{2, "Key Encipherment", "keyEncipherment"},
85{3, "Data Encipherment", "dataEncipherment"},
86{4, "Key Agreement", "keyAgreement"},
87{5, "Certificate Sign", "keyCertSign"},
88{6, "CRL Sign", "cRLSign"},
89{7, "Encipher Only", "encipherOnly"},
90{8, "Decipher Only", "decipherOnly"},
91{-1, NULL, NULL}
92};
93
94
95
96X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
97X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table);
98
99static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
100 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret)
101{
102 BIT_STRING_BITNAME *bnam;
103 for(bnam =method->usr_data; bnam->lname; bnam++) {
104 if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
105 X509V3_add_value(bnam->lname, NULL, &ret);
106 }
107 return ret;
108}
109
110static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
111 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
112{
113 CONF_VALUE *val;
114 ASN1_BIT_STRING *bs;
115 int i;
116 BIT_STRING_BITNAME *bnam;
117 if(!(bs = M_ASN1_BIT_STRING_new())) {
118 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE);
119 return NULL;
120 }
121 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
122 val = sk_CONF_VALUE_value(nval, i);
123 for(bnam = method->usr_data; bnam->lname; bnam++) {
124 if(!strcmp(bnam->sname, val->name) ||
125 !strcmp(bnam->lname, val->name) ) {
126 ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1);
127 break;
128 }
129 }
130 if(!bnam->lname) {
131 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
132 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
133 X509V3_conf_err(val);
134 M_ASN1_BIT_STRING_free(bs);
135 return NULL;
136 }
137 }
138 return bs;
139}
140
141
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
deleted file mode 100644
index b2f03010cc..0000000000
--- a/src/lib/libcrypto/x509v3/v3_conf.c
+++ /dev/null
@@ -1,390 +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 = M_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 M_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 DER 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 = M_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);
257M_ASN1_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/* Add extensions to certificate request */
306
307int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
308 X509_REQ *req)
309{
310 X509_EXTENSION *ext;
311 STACK_OF(X509_EXTENSION) *extlist = NULL;
312 STACK_OF(CONF_VALUE) *nval;
313 CONF_VALUE *val;
314 int i;
315 if(!(nval = CONF_get_section(conf, section))) return 0;
316 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
317 val = sk_CONF_VALUE_value(nval, i);
318 if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value)))
319 return 0;
320 if(!extlist) extlist = sk_X509_EXTENSION_new_null();
321 sk_X509_EXTENSION_push(extlist, ext);
322 }
323 if(req) i = X509_REQ_add_extensions(req, extlist);
324 else i = 1;
325 sk_X509_EXTENSION_pop_free(extlist, X509_EXTENSION_free);
326 return i;
327}
328
329/* Config database functions */
330
331char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
332{
333 if(ctx->db_meth->get_string)
334 return ctx->db_meth->get_string(ctx->db, name, section);
335 return NULL;
336}
337
338STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section)
339{
340 if(ctx->db_meth->get_section)
341 return ctx->db_meth->get_section(ctx->db, section);
342 return NULL;
343}
344
345void X509V3_string_free(X509V3_CTX *ctx, char *str)
346{
347 if(!str) return;
348 if(ctx->db_meth->free_string)
349 ctx->db_meth->free_string(ctx->db, str);
350}
351
352void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
353{
354 if(!section) return;
355 if(ctx->db_meth->free_section)
356 ctx->db_meth->free_section(ctx->db, section);
357}
358
359static char *conf_lhash_get_string(void *db, char *section, char *value)
360{
361 return CONF_get_string(db, section, value);
362}
363
364static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section)
365{
366 return CONF_get_section(db, section);
367}
368
369static X509V3_CONF_METHOD conf_lhash_method = {
370conf_lhash_get_string,
371conf_lhash_get_section,
372NULL,
373NULL
374};
375
376void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash)
377{
378 ctx->db_meth = &conf_lhash_method;
379 ctx->db = lhash;
380}
381
382void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
383 X509_CRL *crl, int flags)
384{
385 ctx->issuer_cert = issuer;
386 ctx->subject_cert = subj;
387 ctx->crl = crl;
388 ctx->subject_req = req;
389 ctx->flags = flags;
390}
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
deleted file mode 100644
index 466713b50d..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 = M_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 = M_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 = M_ASN1_IA5STRING_new();
242 else nref->organization = M_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 M_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 M_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 M_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 e459d2595a..0000000000
--- a/src/lib/libcrypto/x509v3/v3_crld.c
+++ /dev/null
@@ -1,285 +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 M_ASN1_BIT_STRING_free(a->reasons);
215 sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free);
216 Free (a);
217}
218
219int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
220{
221 M_ASN1_I2D_vars(a);
222
223 if(a->fullname) {
224 M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES);
225 } else {
226 M_ASN1_I2D_len_IMP_SET_opt_type(X509_NAME_ENTRY,
227 a->relativename, i2d_X509_NAME_ENTRY, 1);
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_IMP_SET_opt_type(X509_NAME_ENTRY,
238 a->relativename, i2d_X509_NAME_ENTRY, 1);
239 }
240 M_ASN1_I2D_finish();
241}
242
243DIST_POINT_NAME *DIST_POINT_NAME_new(void)
244{
245 DIST_POINT_NAME *ret=NULL;
246 ASN1_CTX c;
247 M_ASN1_New_Malloc(ret, DIST_POINT_NAME);
248 ret->fullname = NULL;
249 ret->relativename = NULL;
250 return (ret);
251 M_ASN1_New_Error(ASN1_F_DIST_POINT_NAME_NEW);
252}
253
254void DIST_POINT_NAME_free(DIST_POINT_NAME *a)
255{
256 if (a == NULL) return;
257 sk_X509_NAME_ENTRY_pop_free(a->relativename, X509_NAME_ENTRY_free);
258 sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free);
259 Free (a);
260}
261
262DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
263 long length)
264{
265 unsigned char _tmp, tag;
266 M_ASN1_D2I_vars(a,DIST_POINT_NAME *,DIST_POINT_NAME_new);
267 M_ASN1_D2I_Init();
268 c.slen = length;
269
270 _tmp = M_ASN1_next;
271 tag = _tmp & ~V_ASN1_CONSTRUCTED;
272
273 if(tag == (0|V_ASN1_CONTEXT_SPECIFIC)) {
274 M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES,
275 V_ASN1_SEQUENCE);
276 } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) {
277 M_ASN1_D2I_get_IMP_set_opt_type (X509_NAME_ENTRY,
278 ret->relativename, d2i_X509_NAME_ENTRY, X509_NAME_ENTRY_free, 1);
279 } else {
280 c.error = ASN1_R_BAD_TAG;
281 goto err;
282 }
283
284 M_ASN1_D2I_Finish(a, DIST_POINT_NAME_free, ASN1_F_D2I_DIST_POINT_NAME);
285}
diff --git a/src/lib/libcrypto/x509v3/v3_enum.c b/src/lib/libcrypto/x509v3/v3_enum.c
deleted file mode 100644
index aecfdc87f8..0000000000
--- a/src/lib/libcrypto/x509v3/v3_enum.c
+++ /dev/null
@@ -1,96 +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 ENUMERATED_NAMES crl_reasons[] = {
64{0, "Unspecified", "unspecified"},
65{1, "Key Compromise", "keyCompromise"},
66{2, "CA Compromise", "CACompromise"},
67{3, "Affiliation Changed", "affiliationChanged"},
68{4, "Superseded", "superseded"},
69{5, "Cessation Of Operation", "cessationOfOperation"},
70{6, "Certificate Hold", "certificateHold"},
71{8, "Remove From CRL", "removeFromCRL"},
72{-1, NULL, NULL}
73};
74
75X509V3_EXT_METHOD v3_crl_reason = {
76NID_crl_reason, 0,
77(X509V3_EXT_NEW)ASN1_ENUMERATED_new,
78(X509V3_EXT_FREE)ASN1_ENUMERATED_free,
79(X509V3_EXT_D2I)d2i_ASN1_ENUMERATED,
80(X509V3_EXT_I2D)i2d_ASN1_ENUMERATED,
81(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
82(X509V3_EXT_S2I)0,
83NULL, NULL, NULL, NULL, crl_reasons};
84
85
86char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
87 ASN1_ENUMERATED *e)
88{
89 ENUMERATED_NAMES *enam;
90 long strval;
91 strval = ASN1_ENUMERATED_get(e);
92 for(enam = method->usr_data; enam->lname; enam++) {
93 if(strval == enam->bitnum) return BUF_strdup(enam->lname);
94 }
95 return i2s_ASN1_ENUMERATED(method, e);
96}
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 894afa7e03..0000000000
--- a/src/lib/libcrypto/x509v3/v3_genn.c
+++ /dev/null
@@ -1,291 +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_X400:
92 case GEN_EDIPARTY:
93 ret = i2d_ASN1_TYPE(a->d.other, pp);
94 break;
95
96 case GEN_OTHERNAME:
97 ret = i2d_OTHERNAME(a->d.otherName, pp);
98 break;
99
100 case GEN_EMAIL:
101 case GEN_DNS:
102 case GEN_URI:
103 ret = i2d_ASN1_IA5STRING(a->d.ia5, pp);
104 break;
105
106 case GEN_IPADD:
107 ret = i2d_ASN1_OCTET_STRING(a->d.ip, pp);
108 break;
109
110 case GEN_RID:
111 ret = i2d_ASN1_OBJECT(a->d.rid, pp);
112 break;
113 }
114 /* Replace TAG with IMPLICIT value */
115 if(p) *p = (*p & V_ASN1_CONSTRUCTED) | a->type;
116 return ret;
117}
118
119GENERAL_NAME *GENERAL_NAME_new()
120{
121 GENERAL_NAME *ret=NULL;
122 ASN1_CTX c;
123 M_ASN1_New_Malloc(ret, GENERAL_NAME);
124 ret->type = -1;
125 ret->d.ptr = NULL;
126 return (ret);
127 M_ASN1_New_Error(ASN1_F_GENERAL_NAME_NEW);
128}
129
130GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp,
131 long length)
132{
133 unsigned char _tmp;
134 M_ASN1_D2I_vars(a,GENERAL_NAME *,GENERAL_NAME_new);
135 M_ASN1_D2I_Init();
136 c.slen = length;
137
138 _tmp = M_ASN1_next;
139 ret->type = _tmp & ~V_ASN1_CONSTRUCTED;
140
141 switch(ret->type) {
142 /* Just put these in a "blob" for now */
143 case GEN_X400:
144 case GEN_EDIPARTY:
145 M_ASN1_D2I_get_imp(ret->d.other, d2i_ASN1_TYPE,V_ASN1_SEQUENCE);
146 break;
147
148 case GEN_OTHERNAME:
149 M_ASN1_D2I_get_imp(ret->d.otherName, d2i_OTHERNAME,V_ASN1_SEQUENCE);
150 break;
151
152 case GEN_EMAIL:
153 case GEN_DNS:
154 case GEN_URI:
155 M_ASN1_D2I_get_imp(ret->d.ia5, d2i_ASN1_IA5STRING,
156 V_ASN1_IA5STRING);
157 break;
158
159 case GEN_DIRNAME:
160 M_ASN1_D2I_get_EXP_opt(ret->d.dirn, d2i_X509_NAME, 4);
161 break;
162
163 case GEN_IPADD:
164 M_ASN1_D2I_get_imp(ret->d.ip, d2i_ASN1_OCTET_STRING,
165 V_ASN1_OCTET_STRING);
166 break;
167
168 case GEN_RID:
169 M_ASN1_D2I_get_imp(ret->d.rid, d2i_ASN1_OBJECT,V_ASN1_OBJECT);
170 break;
171
172 default:
173 c.error = ASN1_R_BAD_TAG;
174 goto err;
175 }
176
177 c.slen = 0;
178 M_ASN1_D2I_Finish(a, GENERAL_NAME_free, ASN1_F_D2I_GENERAL_NAME);
179}
180
181void GENERAL_NAME_free(GENERAL_NAME *a)
182{
183 if (a == NULL) return;
184 switch(a->type) {
185 case GEN_X400:
186 case GEN_EDIPARTY:
187 ASN1_TYPE_free(a->d.other);
188 break;
189
190 case GEN_OTHERNAME:
191 OTHERNAME_free(a->d.otherName);
192 break;
193
194 case GEN_EMAIL:
195 case GEN_DNS:
196 case GEN_URI:
197
198 M_ASN1_IA5STRING_free(a->d.ia5);
199 break;
200
201 case GEN_DIRNAME:
202 X509_NAME_free(a->d.dirn);
203 break;
204
205 case GEN_IPADD:
206 M_ASN1_OCTET_STRING_free(a->d.ip);
207 break;
208
209 case GEN_RID:
210 ASN1_OBJECT_free(a->d.rid);
211 break;
212
213 }
214 Free (a);
215}
216
217/* Now the GeneralNames versions: a SEQUENCE OF GeneralName. These are needed as
218 * explicit functions.
219 */
220
221STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new()
222{
223 return sk_GENERAL_NAME_new(NULL);
224}
225
226void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a)
227{
228 sk_GENERAL_NAME_pop_free(a, GENERAL_NAME_free);
229}
230
231STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a,
232 unsigned char **pp, long length)
233{
234return d2i_ASN1_SET_OF_GENERAL_NAME(a, pp, length, d2i_GENERAL_NAME,
235 GENERAL_NAME_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
236}
237
238int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp)
239{
240return i2d_ASN1_SET_OF_GENERAL_NAME(a, pp, i2d_GENERAL_NAME, V_ASN1_SEQUENCE,
241 V_ASN1_UNIVERSAL, IS_SEQUENCE);
242}
243
244IMPLEMENT_STACK_OF(GENERAL_NAME)
245IMPLEMENT_ASN1_SET_OF(GENERAL_NAME)
246
247int i2d_OTHERNAME(OTHERNAME *a, unsigned char **pp)
248{
249 int v = 0;
250 M_ASN1_I2D_vars(a);
251
252 M_ASN1_I2D_len(a->type_id, i2d_ASN1_OBJECT);
253 M_ASN1_I2D_len_EXP_opt(a->value, i2d_ASN1_TYPE, 0, v);
254
255 M_ASN1_I2D_seq_total();
256
257 M_ASN1_I2D_put(a->type_id, i2d_ASN1_OBJECT);
258 M_ASN1_I2D_put_EXP_opt(a->value, i2d_ASN1_TYPE, 0, v);
259
260 M_ASN1_I2D_finish();
261}
262
263OTHERNAME *OTHERNAME_new(void)
264{
265 OTHERNAME *ret=NULL;
266 ASN1_CTX c;
267 M_ASN1_New_Malloc(ret, OTHERNAME);
268 ret->type_id = OBJ_nid2obj(NID_undef);
269 M_ASN1_New(ret->value, ASN1_TYPE_new);
270 return (ret);
271 M_ASN1_New_Error(ASN1_F_OTHERNAME_NEW);
272}
273
274OTHERNAME *d2i_OTHERNAME(OTHERNAME **a, unsigned char **pp, long length)
275{
276 M_ASN1_D2I_vars(a,OTHERNAME *,OTHERNAME_new);
277 M_ASN1_D2I_Init();
278 M_ASN1_D2I_start_sequence();
279 M_ASN1_D2I_get(ret->type_id, d2i_ASN1_OBJECT);
280 M_ASN1_D2I_get_EXP_opt(ret->value, d2i_ASN1_TYPE, 0);
281 M_ASN1_D2I_Finish(a, OTHERNAME_free, ASN1_F_D2I_OTHERNAME);
282}
283
284void OTHERNAME_free(OTHERNAME *a)
285{
286 if (a == NULL) return;
287 ASN1_OBJECT_free(a->type_id);
288 ASN1_TYPE_free(a->value);
289 Free (a);
290}
291
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
deleted file mode 100644
index af3525f33e..0000000000
--- a/src/lib/libcrypto/x509v3/v3_ia5.c
+++ /dev/null
@@ -1,113 +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 char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5);
67static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
68X509V3_EXT_METHOD v3_ns_ia5_list[] = {
69EXT_IA5STRING(NID_netscape_base_url),
70EXT_IA5STRING(NID_netscape_revocation_url),
71EXT_IA5STRING(NID_netscape_ca_revocation_url),
72EXT_IA5STRING(NID_netscape_renewal_url),
73EXT_IA5STRING(NID_netscape_ca_policy_url),
74EXT_IA5STRING(NID_netscape_ssl_server_name),
75EXT_IA5STRING(NID_netscape_comment),
76EXT_END
77};
78
79
80static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
81 ASN1_IA5STRING *ia5)
82{
83 char *tmp;
84 if(!ia5 || !ia5->length) return NULL;
85 tmp = Malloc(ia5->length + 1);
86 memcpy(tmp, ia5->data, ia5->length);
87 tmp[ia5->length] = 0;
88 return tmp;
89}
90
91static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
92 X509V3_CTX *ctx, char *str)
93{
94 ASN1_IA5STRING *ia5;
95 if(!str) {
96 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT);
97 return NULL;
98 }
99 if(!(ia5 = M_ASN1_IA5STRING_new())) goto err;
100 if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str,
101 strlen(str))) {
102 M_ASN1_IA5STRING_free(ia5);
103 goto err;
104 }
105#ifdef CHARSET_EBCDIC
106 ebcdic2ascii(ia5->data, ia5->data, ia5->length);
107#endif /*CHARSET_EBCDIC*/
108 return ia5;
109 err:
110 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
111 return NULL;
112}
113
diff --git a/src/lib/libcrypto/x509v3/v3_info.c b/src/lib/libcrypto/x509v3/v3_info.c
deleted file mode 100644
index 78d2135046..0000000000
--- a/src/lib/libcrypto/x509v3/v3_info.c
+++ /dev/null
@@ -1,236 +0,0 @@
1/* v3_info.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
67 STACK_OF(ACCESS_DESCRIPTION) *ainfo,
68 STACK_OF(CONF_VALUE) *ret);
69static STACK_OF(ACCESS_DESCRIPTION) *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
70 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
71
72X509V3_EXT_METHOD v3_info =
73{ NID_info_access, X509V3_EXT_MULTILINE,
74(X509V3_EXT_NEW)AUTHORITY_INFO_ACCESS_new,
75(X509V3_EXT_FREE)AUTHORITY_INFO_ACCESS_free,
76(X509V3_EXT_D2I)d2i_AUTHORITY_INFO_ACCESS,
77(X509V3_EXT_I2D)i2d_AUTHORITY_INFO_ACCESS,
78NULL, NULL,
79(X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
80(X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
81NULL, NULL, NULL};
82
83static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
84 STACK_OF(ACCESS_DESCRIPTION) *ainfo,
85 STACK_OF(CONF_VALUE) *ret)
86{
87 ACCESS_DESCRIPTION *desc;
88 int i;
89 char objtmp[80], *ntmp;
90 CONF_VALUE *vtmp;
91 for(i = 0; i < sk_ACCESS_DESCRIPTION_num(ainfo); i++) {
92 desc = sk_ACCESS_DESCRIPTION_value(ainfo, i);
93 ret = i2v_GENERAL_NAME(method, desc->location, ret);
94 if(!ret) break;
95 vtmp = sk_CONF_VALUE_value(ret, i);
96 i2t_ASN1_OBJECT(objtmp, 80, desc->method);
97 ntmp = Malloc(strlen(objtmp) + strlen(vtmp->name) + 5);
98 if(!ntmp) {
99 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS,
100 ERR_R_MALLOC_FAILURE);
101 return NULL;
102 }
103 strcpy(ntmp, objtmp);
104 strcat(ntmp, " - ");
105 strcat(ntmp, vtmp->name);
106 Free(vtmp->name);
107 vtmp->name = ntmp;
108
109 }
110 if(!ret) return sk_CONF_VALUE_new_null();
111 return ret;
112}
113
114static STACK_OF(ACCESS_DESCRIPTION) *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
115 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
116{
117 STACK_OF(ACCESS_DESCRIPTION) *ainfo = NULL;
118 CONF_VALUE *cnf, ctmp;
119 ACCESS_DESCRIPTION *acc;
120 int i, objlen;
121 char *objtmp, *ptmp;
122 if(!(ainfo = sk_ACCESS_DESCRIPTION_new(NULL))) {
123 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
124 return NULL;
125 }
126 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
127 cnf = sk_CONF_VALUE_value(nval, i);
128 if(!(acc = ACCESS_DESCRIPTION_new())
129 || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) {
130 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
131 goto err;
132 }
133 ptmp = strchr(cnf->name, ';');
134 if(!ptmp) {
135 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_INVALID_SYNTAX);
136 goto err;
137 }
138 objlen = ptmp - cnf->name;
139 ctmp.name = ptmp + 1;
140 ctmp.value = cnf->value;
141 if(!(acc->location = v2i_GENERAL_NAME(method, ctx, &ctmp)))
142 goto err;
143 if(!(objtmp = Malloc(objlen + 1))) {
144 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
145 goto err;
146 }
147 strncpy(objtmp, cnf->name, objlen);
148 objtmp[objlen] = 0;
149 acc->method = OBJ_txt2obj(objtmp, 0);
150 if(!acc->method) {
151 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_BAD_OBJECT);
152 ERR_add_error_data(2, "value=", objtmp);
153 Free(objtmp);
154 goto err;
155 }
156 Free(objtmp);
157
158 }
159 return ainfo;
160 err:
161 sk_ACCESS_DESCRIPTION_pop_free(ainfo, ACCESS_DESCRIPTION_free);
162 return NULL;
163}
164
165int i2d_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION *a, unsigned char **pp)
166{
167 M_ASN1_I2D_vars(a);
168
169 M_ASN1_I2D_len(a->method, i2d_ASN1_OBJECT);
170 M_ASN1_I2D_len(a->location, i2d_GENERAL_NAME);
171
172 M_ASN1_I2D_seq_total();
173
174 M_ASN1_I2D_put(a->method, i2d_ASN1_OBJECT);
175 M_ASN1_I2D_put(a->location, i2d_GENERAL_NAME);
176
177 M_ASN1_I2D_finish();
178}
179
180ACCESS_DESCRIPTION *ACCESS_DESCRIPTION_new(void)
181{
182 ACCESS_DESCRIPTION *ret=NULL;
183 ASN1_CTX c;
184 M_ASN1_New_Malloc(ret, ACCESS_DESCRIPTION);
185 ret->method = OBJ_nid2obj(NID_undef);
186 ret->location = NULL;
187 return (ret);
188 M_ASN1_New_Error(ASN1_F_ACCESS_DESCRIPTION_NEW);
189}
190
191ACCESS_DESCRIPTION *d2i_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION **a, unsigned char **pp,
192 long length)
193{
194 M_ASN1_D2I_vars(a,ACCESS_DESCRIPTION *,ACCESS_DESCRIPTION_new);
195 M_ASN1_D2I_Init();
196 M_ASN1_D2I_start_sequence();
197 M_ASN1_D2I_get(ret->method, d2i_ASN1_OBJECT);
198 M_ASN1_D2I_get(ret->location, d2i_GENERAL_NAME);
199 M_ASN1_D2I_Finish(a, ACCESS_DESCRIPTION_free, ASN1_F_D2I_ACCESS_DESCRIPTION);
200}
201
202void ACCESS_DESCRIPTION_free(ACCESS_DESCRIPTION *a)
203{
204 if (a == NULL) return;
205 ASN1_OBJECT_free(a->method);
206 GENERAL_NAME_free(a->location);
207 Free (a);
208}
209
210STACK_OF(ACCESS_DESCRIPTION) *AUTHORITY_INFO_ACCESS_new(void)
211{
212 return sk_ACCESS_DESCRIPTION_new(NULL);
213}
214
215void AUTHORITY_INFO_ACCESS_free(STACK_OF(ACCESS_DESCRIPTION) *a)
216{
217 sk_ACCESS_DESCRIPTION_pop_free(a, ACCESS_DESCRIPTION_free);
218}
219
220STACK_OF(ACCESS_DESCRIPTION) *d2i_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) **a,
221 unsigned char **pp, long length)
222{
223return d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(a, pp, length, d2i_ACCESS_DESCRIPTION,
224 ACCESS_DESCRIPTION_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
225}
226
227int i2d_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) *a, unsigned char **pp)
228{
229return i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(a, pp, i2d_ACCESS_DESCRIPTION, V_ASN1_SEQUENCE,
230 V_ASN1_UNIVERSAL, IS_SEQUENCE);
231}
232
233IMPLEMENT_STACK_OF(ACCESS_DESCRIPTION)
234IMPLEMENT_ASN1_SET_OF(ACCESS_DESCRIPTION)
235
236
diff --git a/src/lib/libcrypto/x509v3/v3_int.c b/src/lib/libcrypto/x509v3/v3_int.c
deleted file mode 100644
index 63c201e5f4..0000000000
--- a/src/lib/libcrypto/x509v3/v3_int.c
+++ /dev/null
@@ -1,72 +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
63X509V3_EXT_METHOD v3_crl_num = {
64NID_crl_number, 0,
65(X509V3_EXT_NEW)ASN1_INTEGER_new,
66(X509V3_EXT_FREE)ASN1_INTEGER_free,
67(X509V3_EXT_D2I)d2i_ASN1_INTEGER,
68(X509V3_EXT_I2D)i2d_ASN1_INTEGER,
69(X509V3_EXT_I2S)i2s_ASN1_INTEGER,
70(X509V3_EXT_S2I)0,
71NULL, NULL, NULL, NULL, NULL};
72
diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c
deleted file mode 100644
index 4242d130a2..0000000000
--- a/src/lib/libcrypto/x509v3/v3_lib.c
+++ /dev/null
@@ -1,221 +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
65#include "ext_dat.h"
66
67static STACK *ext_list = NULL;
68
69static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
70static void ext_list_free(X509V3_EXT_METHOD *ext);
71
72int X509V3_EXT_add(X509V3_EXT_METHOD *ext)
73{
74 if(!ext_list && !(ext_list = sk_new(ext_cmp))) {
75 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
76 return 0;
77 }
78 if(!sk_push(ext_list, (char *)ext)) {
79 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
80 return 0;
81 }
82 return 1;
83}
84
85static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b)
86{
87 return ((*a)->ext_nid - (*b)->ext_nid);
88}
89
90X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
91{
92 X509V3_EXT_METHOD tmp, *t = &tmp, **ret;
93 int idx;
94 if(nid < 0) return NULL;
95 tmp.ext_nid = nid;
96 ret = (X509V3_EXT_METHOD **) OBJ_bsearch((char *)&t,
97 (char *)standard_exts, STANDARD_EXTENSION_COUNT,
98 sizeof(X509V3_EXT_METHOD *), (int (*)())ext_cmp);
99 if(ret) return *ret;
100 if(!ext_list) return NULL;
101 idx = sk_find(ext_list, (char *)&tmp);
102 if(idx == -1) return NULL;
103 return (X509V3_EXT_METHOD *)sk_value(ext_list, idx);
104}
105
106X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
107{
108 int nid;
109 if((nid = OBJ_obj2nid(ext->object)) == NID_undef) return NULL;
110 return X509V3_EXT_get_nid(nid);
111}
112
113
114int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist)
115{
116 for(;extlist->ext_nid!=-1;extlist++)
117 if(!X509V3_EXT_add(extlist)) return 0;
118 return 1;
119}
120
121int X509V3_EXT_add_alias(int nid_to, int nid_from)
122{
123 X509V3_EXT_METHOD *ext, *tmpext;
124 if(!(ext = X509V3_EXT_get_nid(nid_from))) {
125 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
126 return 0;
127 }
128 if(!(tmpext = (X509V3_EXT_METHOD *)Malloc(sizeof(X509V3_EXT_METHOD)))) {
129 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE);
130 return 0;
131 }
132 *tmpext = *ext;
133 tmpext->ext_nid = nid_to;
134 tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
135 return X509V3_EXT_add(tmpext);
136}
137
138void X509V3_EXT_cleanup(void)
139{
140 sk_pop_free(ext_list, ext_list_free);
141 ext_list = NULL;
142}
143
144static void ext_list_free(X509V3_EXT_METHOD *ext)
145{
146 if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext);
147}
148
149/* Legacy function: we don't need to add standard extensions
150 * any more because they are now kept in ext_dat.h.
151 */
152
153int X509V3_add_standard_extensions(void)
154{
155 return 1;
156}
157
158/* Return an extension internal structure */
159
160void *X509V3_EXT_d2i(X509_EXTENSION *ext)
161{
162 X509V3_EXT_METHOD *method;
163 unsigned char *p;
164 if(!(method = X509V3_EXT_get(ext)) || !method->d2i) return NULL;
165 p = ext->value->data;
166 return method->d2i(NULL, &p, ext->value->length);
167}
168
169/* Get critical flag and decoded version of extension from a NID.
170 * The "idx" variable returns the last found extension and can
171 * be used to retrieve multiple extensions of the same NID.
172 * However multiple extensions with the same NID is usually
173 * due to a badly encoded certificate so if idx is NULL we
174 * choke if multiple extensions exist.
175 * The "crit" variable is set to the critical value.
176 * The return value is the decoded extension or NULL on
177 * error. The actual error can have several different causes,
178 * the value of *crit reflects the cause:
179 * >= 0, extension found but not decoded (reflects critical value).
180 * -1 extension not found.
181 * -2 extension occurs more than once.
182 */
183
184void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx)
185{
186 int lastpos, i;
187 X509_EXTENSION *ex, *found_ex = NULL;
188 if(!x) {
189 if(idx) *idx = -1;
190 if(crit) *crit = -1;
191 return NULL;
192 }
193 if(idx) lastpos = *idx + 1;
194 else lastpos = 0;
195 if(lastpos < 0) lastpos = 0;
196 for(i = lastpos; i < sk_X509_EXTENSION_num(x); i++)
197 {
198 ex = sk_X509_EXTENSION_value(x, i);
199 if(OBJ_obj2nid(ex->object) == nid) {
200 if(idx) {
201 *idx = i;
202 break;
203 } else if(found_ex) {
204 /* Found more than one */
205 if(crit) *crit = -2;
206 return NULL;
207 }
208 found_ex = ex;
209 }
210 }
211 if(found_ex) {
212 /* Found it */
213 if(crit) *crit = found_ex->critical;
214 return X509V3_EXT_d2i(found_ex);
215 }
216
217 /* Extension not found */
218 if(idx) *idx = -1;
219 if(crit) *crit = -1;
220 return NULL;
221}
diff --git a/src/lib/libcrypto/x509v3/v3_pku.c b/src/lib/libcrypto/x509v3/v3_pku.c
deleted file mode 100644
index 30a62c6090..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 M_ASN1_GENERALIZEDTIME_free(a->notBefore);
123 M_ASN1_GENERALIZEDTIME_free(a->notAfter);
124 Free (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 bee624c6be..0000000000
--- a/src/lib/libcrypto/x509v3/v3_prn.c
+++ /dev/null
@@ -1,151 +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#ifndef CHARSET_EBCDIC
85 else BIO_printf(out, "%s:%s", nval->name, nval->value);
86#else
87 else {
88 char tmp[10240]; /* 10k is BIO_printf's limit anyway */
89 ascii2ebcdic(tmp, nval->value, strlen(nval->value)+1);
90 BIO_printf(out, "%s:%s", nval->name, tmp);
91 }
92#endif
93 if(ml) BIO_puts(out, "\n");
94 }
95}
96
97/* Main routine: print out a general extension */
98
99int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent)
100{
101 char *ext_str = NULL, *value = NULL;
102 unsigned char *p;
103 X509V3_EXT_METHOD *method;
104 STACK_OF(CONF_VALUE) *nval = NULL;
105 int ok = 1;
106 if(!(method = X509V3_EXT_get(ext))) return 0;
107 p = ext->value->data;
108 if(!(ext_str = method->d2i(NULL, &p, ext->value->length))) return 0;
109 if(method->i2s) {
110 if(!(value = method->i2s(method, ext_str))) {
111 ok = 0;
112 goto err;
113 }
114#ifndef CHARSET_EBCDIC
115 BIO_printf(out, "%*s%s", indent, "", value);
116#else
117 {
118 char tmp[10240]; /* 10k is BIO_printf's limit anyway */
119 ascii2ebcdic(tmp, value, strlen(value)+1);
120 BIO_printf(out, "%*s%s", indent, "", tmp);
121 }
122#endif
123 } else if(method->i2v) {
124 if(!(nval = method->i2v(method, ext_str, NULL))) {
125 ok = 0;
126 goto err;
127 }
128 X509V3_EXT_val_prn(out, nval, indent,
129 method->ext_flags & X509V3_EXT_MULTILINE);
130 } else if(method->i2r) {
131 if(!method->i2r(method, ext_str, out, indent)) ok = 0;
132 } else ok = 0;
133
134 err:
135 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
136 if(value) Free(value);
137 method->ext_free(ext_str);
138 return ok;
139}
140
141#ifndef NO_FP_API
142int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent)
143{
144 BIO *bio_tmp;
145 int ret;
146 if(!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) return 0;
147 ret = X509V3_EXT_print(bio_tmp, ext, flag, indent);
148 BIO_free(bio_tmp);
149 return ret;
150}
151#endif
diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c
deleted file mode 100644
index 5594a1d64f..0000000000
--- a/src/lib/libcrypto/x509v3/v3_purp.c
+++ /dev/null
@@ -1,463 +0,0 @@
1/* v3_purp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63
64static void x509v3_cache_extensions(X509 *x);
65
66static int ca_check(X509 *x);
67static int check_purpose_ssl_client(X509_PURPOSE *xp, X509 *x, int ca);
68static int check_purpose_ssl_server(X509_PURPOSE *xp, X509 *x, int ca);
69static int check_purpose_ns_ssl_server(X509_PURPOSE *xp, X509 *x, int ca);
70static int purpose_smime(X509 *x, int ca);
71static int check_purpose_smime_sign(X509_PURPOSE *xp, X509 *x, int ca);
72static int check_purpose_smime_encrypt(X509_PURPOSE *xp, X509 *x, int ca);
73static int check_purpose_crl_sign(X509_PURPOSE *xp, X509 *x, int ca);
74static int no_check(X509_PURPOSE *xp, X509 *x, int ca);
75
76static int xp_cmp(X509_PURPOSE **a, X509_PURPOSE **b);
77static void xptable_free(X509_PURPOSE *p);
78
79static X509_PURPOSE xstandard[] = {
80 {X509_PURPOSE_SSL_CLIENT, X509_TRUST_SSL_CLIENT, 0, check_purpose_ssl_client, "SSL client", "sslclient", NULL},
81 {X509_PURPOSE_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ssl_server, "SSL server", "sslserver", NULL},
82 {X509_PURPOSE_NS_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ns_ssl_server, "Netscape SSL server", "nssslserver", NULL},
83 {X509_PURPOSE_SMIME_SIGN, X509_TRUST_EMAIL, 0, check_purpose_smime_sign, "S/MIME signing", "smimesign", NULL},
84 {X509_PURPOSE_SMIME_ENCRYPT, X509_TRUST_EMAIL, 0, check_purpose_smime_encrypt, "S/MIME encryption", "smimeencrypt", NULL},
85 {X509_PURPOSE_CRL_SIGN, X509_TRUST_COMPAT, 0, check_purpose_crl_sign, "CRL signing", "crlsign", NULL},
86 {X509_PURPOSE_ANY, X509_TRUST_DEFAULT, 0, no_check, "Any Purpose", "any", NULL},
87};
88
89#define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
90
91IMPLEMENT_STACK_OF(X509_PURPOSE)
92
93static STACK_OF(X509_PURPOSE) *xptable = NULL;
94
95static int xp_cmp(X509_PURPOSE **a, X509_PURPOSE **b)
96{
97 return (*a)->purpose - (*b)->purpose;
98}
99
100int X509_check_purpose(X509 *x, int id, int ca)
101{
102 int idx;
103 X509_PURPOSE *pt;
104 if(!(x->ex_flags & EXFLAG_SET)) {
105 CRYPTO_w_lock(CRYPTO_LOCK_X509);
106 x509v3_cache_extensions(x);
107 CRYPTO_w_unlock(CRYPTO_LOCK_X509);
108 }
109 if(id == -1) return 1;
110 idx = X509_PURPOSE_get_by_id(id);
111 if(idx == -1) return -1;
112 pt = X509_PURPOSE_get0(idx);
113 return pt->check_purpose(pt, x, ca);
114}
115
116int X509_PURPOSE_get_count(void)
117{
118 if(!xptable) return X509_PURPOSE_COUNT;
119 return sk_X509_PURPOSE_num(xptable) + X509_PURPOSE_COUNT;
120}
121
122X509_PURPOSE * X509_PURPOSE_get0(int idx)
123{
124 if(idx < 0) return NULL;
125 if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
126 return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
127}
128
129int X509_PURPOSE_get_by_sname(char *sname)
130{
131 int i;
132 X509_PURPOSE *xptmp;
133 for(i = 0; i < X509_PURPOSE_get_count(); i++) {
134 xptmp = X509_PURPOSE_get0(i);
135 if(!strcmp(xptmp->sname, sname)) return i;
136 }
137 return -1;
138}
139
140
141int X509_PURPOSE_get_by_id(int purpose)
142{
143 X509_PURPOSE tmp;
144 int idx;
145 if((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
146 return purpose - X509_PURPOSE_MIN;
147 tmp.purpose = purpose;
148 if(!xptable) return -1;
149 idx = sk_X509_PURPOSE_find(xptable, &tmp);
150 if(idx == -1) return -1;
151 return idx + X509_PURPOSE_COUNT;
152}
153
154int X509_PURPOSE_add(int id, int trust, int flags,
155 int (*ck)(X509_PURPOSE *, X509 *, int),
156 char *name, char *sname, void *arg)
157{
158 int idx;
159 X509_PURPOSE *ptmp;
160 /* This is set according to what we change: application can't set it */
161 flags &= ~X509_PURPOSE_DYNAMIC;
162 /* This will always be set for application modified trust entries */
163 flags |= X509_PURPOSE_DYNAMIC_NAME;
164 /* Get existing entry if any */
165 idx = X509_PURPOSE_get_by_id(id);
166 /* Need a new entry */
167 if(idx == -1) {
168 if(!(ptmp = Malloc(sizeof(X509_PURPOSE)))) {
169 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
170 return 0;
171 }
172 ptmp->flags = X509_PURPOSE_DYNAMIC;
173 } else ptmp = X509_PURPOSE_get0(idx);
174
175 /* Free existing name if dynamic */
176 if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
177 Free(ptmp->name);
178 Free(ptmp->sname);
179 }
180 /* dup supplied name */
181 ptmp->name = BUF_strdup(name);
182 ptmp->sname = BUF_strdup(sname);
183 if(!ptmp->name || !ptmp->sname) {
184 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
185 return 0;
186 }
187 /* Keep the dynamic flag of existing entry */
188 ptmp->flags &= X509_PURPOSE_DYNAMIC;
189 /* Set all other flags */
190 ptmp->flags |= flags;
191
192 ptmp->purpose = id;
193 ptmp->trust = trust;
194 ptmp->check_purpose = ck;
195 ptmp->usr_data = arg;
196
197 /* If its a new entry manage the dynamic table */
198 if(idx == -1) {
199 if(!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) {
200 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
201 return 0;
202 }
203 if (!sk_X509_PURPOSE_push(xptable, ptmp)) {
204 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
205 return 0;
206 }
207 }
208 return 1;
209}
210
211static void xptable_free(X509_PURPOSE *p)
212 {
213 if(!p) return;
214 if (p->flags & X509_PURPOSE_DYNAMIC)
215 {
216 if (p->flags & X509_PURPOSE_DYNAMIC_NAME) {
217 Free(p->name);
218 Free(p->sname);
219 }
220 Free(p);
221 }
222 }
223
224void X509_PURPOSE_cleanup(void)
225{
226 int i;
227 sk_X509_PURPOSE_pop_free(xptable, xptable_free);
228 for(i = 0; i < X509_PURPOSE_COUNT; i++) xptable_free(xstandard + i);
229 xptable = NULL;
230}
231
232int X509_PURPOSE_get_id(X509_PURPOSE *xp)
233{
234 return xp->purpose;
235}
236
237char *X509_PURPOSE_get0_name(X509_PURPOSE *xp)
238{
239 return xp->name;
240}
241
242char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp)
243{
244 return xp->sname;
245}
246
247int X509_PURPOSE_get_trust(X509_PURPOSE *xp)
248{
249 return xp->trust;
250}
251
252#ifndef NO_SHA
253static void x509v3_cache_extensions(X509 *x)
254{
255 BASIC_CONSTRAINTS *bs;
256 ASN1_BIT_STRING *usage;
257 ASN1_BIT_STRING *ns;
258 STACK_OF(ASN1_OBJECT) *extusage;
259 int i;
260 if(x->ex_flags & EXFLAG_SET) return;
261 X509_digest(x, EVP_sha1(), x->sha1_hash, NULL);
262 /* Does subject name match issuer ? */
263 if(!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x)))
264 x->ex_flags |= EXFLAG_SS;
265 /* V1 should mean no extensions ... */
266 if(!X509_get_version(x)) x->ex_flags |= EXFLAG_V1;
267 /* Handle basic constraints */
268 if((bs=X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {
269 if(bs->ca) x->ex_flags |= EXFLAG_CA;
270 if(bs->pathlen) {
271 if((bs->pathlen->type == V_ASN1_NEG_INTEGER)
272 || !bs->ca) {
273 x->ex_flags |= EXFLAG_INVALID;
274 x->ex_pathlen = 0;
275 } else x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);
276 } else x->ex_pathlen = -1;
277 BASIC_CONSTRAINTS_free(bs);
278 x->ex_flags |= EXFLAG_BCONS;
279 }
280 /* Handle key usage */
281 if((usage=X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {
282 if(usage->length > 0) {
283 x->ex_kusage = usage->data[0];
284 if(usage->length > 1)
285 x->ex_kusage |= usage->data[1] << 8;
286 } else x->ex_kusage = 0;
287 x->ex_flags |= EXFLAG_KUSAGE;
288 ASN1_BIT_STRING_free(usage);
289 }
290 x->ex_xkusage = 0;
291 if((extusage=X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {
292 x->ex_flags |= EXFLAG_XKUSAGE;
293 for(i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {
294 switch(OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage,i))) {
295 case NID_server_auth:
296 x->ex_xkusage |= XKU_SSL_SERVER;
297 break;
298
299 case NID_client_auth:
300 x->ex_xkusage |= XKU_SSL_CLIENT;
301 break;
302
303 case NID_email_protect:
304 x->ex_xkusage |= XKU_SMIME;
305 break;
306
307 case NID_code_sign:
308 x->ex_xkusage |= XKU_CODE_SIGN;
309 break;
310
311 case NID_ms_sgc:
312 case NID_ns_sgc:
313 x->ex_xkusage |= XKU_SGC;
314 }
315 }
316 sk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);
317 }
318
319 if((ns=X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {
320 if(ns->length > 0) x->ex_nscert = ns->data[0];
321 else x->ex_nscert = 0;
322 x->ex_flags |= EXFLAG_NSCERT;
323 ASN1_BIT_STRING_free(ns);
324 }
325 x->ex_flags |= EXFLAG_SET;
326}
327#endif
328
329/* CA checks common to all purposes
330 * return codes:
331 * 0 not a CA
332 * 1 is a CA
333 * 2 basicConstraints absent so "maybe" a CA
334 * 3 basicConstraints absent but self signed V1.
335 */
336
337#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)
338#define ku_reject(x, usage) \
339 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
340#define xku_reject(x, usage) \
341 (((x)->ex_flags & EXFLAG_XKUSAGE) && !((x)->ex_xkusage & (usage)))
342#define ns_reject(x, usage) \
343 (((x)->ex_flags & EXFLAG_NSCERT) && !((x)->ex_nscert & (usage)))
344
345static int ca_check(X509 *x)
346{
347 /* keyUsage if present should allow cert signing */
348 if(ku_reject(x, KU_KEY_CERT_SIGN)) return 0;
349 if(x->ex_flags & EXFLAG_BCONS) {
350 if(x->ex_flags & EXFLAG_CA) return 1;
351 /* If basicConstraints says not a CA then say so */
352 else return 0;
353 } else {
354 if((x->ex_flags & V1_ROOT) == V1_ROOT) return 3;
355 else return 2;
356 }
357}
358
359
360static int check_purpose_ssl_client(X509_PURPOSE *xp, X509 *x, int ca)
361{
362 if(xku_reject(x,XKU_SSL_CLIENT)) return 0;
363 if(ca) {
364 int ca_ret;
365 ca_ret = ca_check(x);
366 if(!ca_ret) return 0;
367 /* check nsCertType if present */
368 if(x->ex_flags & EXFLAG_NSCERT) {
369 if(x->ex_nscert & NS_SSL_CA) return ca_ret;
370 return 0;
371 }
372 if(ca_ret != 2) return ca_ret;
373 else return 0;
374 }
375 /* We need to do digital signatures with it */
376 if(ku_reject(x,KU_DIGITAL_SIGNATURE)) return 0;
377 /* nsCertType if present should allow SSL client use */
378 if(ns_reject(x, NS_SSL_CLIENT)) return 0;
379 return 1;
380}
381
382static int check_purpose_ssl_server(X509_PURPOSE *xp, X509 *x, int ca)
383{
384 if(xku_reject(x,XKU_SSL_SERVER|XKU_SGC)) return 0;
385 /* Otherwise same as SSL client for a CA */
386 if(ca) return check_purpose_ssl_client(xp, x, 1);
387
388 if(ns_reject(x, NS_SSL_SERVER)) return 0;
389 /* Now as for keyUsage: we'll at least need to sign OR encipher */
390 if(ku_reject(x, KU_DIGITAL_SIGNATURE|KU_KEY_ENCIPHERMENT)) return 0;
391
392 return 1;
393
394}
395
396static int check_purpose_ns_ssl_server(X509_PURPOSE *xp, X509 *x, int ca)
397{
398 int ret;
399 ret = check_purpose_ssl_server(xp, x, ca);
400 if(!ret || ca) return ret;
401 /* We need to encipher or Netscape complains */
402 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
403 return ret;
404}
405
406/* common S/MIME checks */
407static int purpose_smime(X509 *x, int ca)
408{
409 if(xku_reject(x,XKU_SMIME)) return 0;
410 if(ca) {
411 int ca_ret;
412 ca_ret = ca_check(x);
413 if(!ca_ret) return 0;
414 /* check nsCertType if present */
415 if(x->ex_flags & EXFLAG_NSCERT) {
416 if(x->ex_nscert & NS_SMIME_CA) return ca_ret;
417 return 0;
418 }
419 if(ca_ret != 2) return ca_ret;
420 else return 0;
421 }
422 if(x->ex_flags & EXFLAG_NSCERT) {
423 if(x->ex_nscert & NS_SMIME) return 1;
424 /* Workaround for some buggy certificates */
425 if(x->ex_nscert & NS_SSL_CLIENT) return 2;
426 return 0;
427 }
428 return 1;
429}
430
431static int check_purpose_smime_sign(X509_PURPOSE *xp, X509 *x, int ca)
432{
433 int ret;
434 ret = purpose_smime(x, ca);
435 if(!ret || ca) return ret;
436 if(ku_reject(x, KU_DIGITAL_SIGNATURE)) return 0;
437 return ret;
438}
439
440static int check_purpose_smime_encrypt(X509_PURPOSE *xp, X509 *x, int ca)
441{
442 int ret;
443 ret = purpose_smime(x, ca);
444 if(!ret || ca) return ret;
445 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
446 return ret;
447}
448
449static int check_purpose_crl_sign(X509_PURPOSE *xp, X509 *x, int ca)
450{
451 if(ca) {
452 int ca_ret;
453 if((ca_ret = ca_check(x)) != 2) return ca_ret;
454 else return 0;
455 }
456 if(ku_reject(x, KU_CRL_SIGN)) return 0;
457 return 1;
458}
459
460static int no_check(X509_PURPOSE *xp, X509 *x, int ca)
461{
462 return 1;
463}
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c
deleted file mode 100644
index 939845fa8f..0000000000
--- a/src/lib/libcrypto/x509v3/v3_skey.c
+++ /dev/null
@@ -1,149 +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 *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
65X509V3_EXT_METHOD v3_skey_id = {
66NID_subject_key_identifier, 0,
67(X509V3_EXT_NEW)ASN1_OCTET_STRING_new,
68(X509V3_EXT_FREE)ASN1_OCTET_STRING_free,
69(X509V3_EXT_D2I)d2i_ASN1_OCTET_STRING,
70(X509V3_EXT_I2D)i2d_ASN1_OCTET_STRING,
71(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING,
72(X509V3_EXT_S2I)s2i_skey_id,
73NULL, NULL, NULL, NULL, NULL};
74
75char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
76 ASN1_OCTET_STRING *oct)
77{
78 return hex_to_string(oct->data, oct->length);
79}
80
81ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
82 X509V3_CTX *ctx, char *str)
83{
84 ASN1_OCTET_STRING *oct;
85 long length;
86
87 if(!(oct = M_ASN1_OCTET_STRING_new())) {
88 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
89 return NULL;
90 }
91
92 if(!(oct->data = string_to_hex(str, &length))) {
93 M_ASN1_OCTET_STRING_free(oct);
94 return NULL;
95 }
96
97 oct->length = length;
98
99 return oct;
100
101}
102
103static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
104 X509V3_CTX *ctx, char *str)
105{
106 ASN1_OCTET_STRING *oct;
107 ASN1_BIT_STRING *pk;
108 unsigned char pkey_dig[EVP_MAX_MD_SIZE];
109 EVP_MD_CTX md;
110 unsigned int diglen;
111
112 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str);
113
114 if(!(oct = M_ASN1_OCTET_STRING_new())) {
115 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
116 return NULL;
117 }
118
119 if(ctx && (ctx->flags == CTX_TEST)) return oct;
120
121 if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
122 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
123 goto err;
124 }
125
126 if(ctx->subject_req)
127 pk = ctx->subject_req->req_info->pubkey->public_key;
128 else pk = ctx->subject_cert->cert_info->key->public_key;
129
130 if(!pk) {
131 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
132 goto err;
133 }
134
135 EVP_DigestInit(&md, EVP_sha1());
136 EVP_DigestUpdate(&md, pk->data, pk->length);
137 EVP_DigestFinal(&md, pkey_dig, &diglen);
138
139 if(!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
140 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
141 goto err;
142 }
143
144 return oct;
145
146 err:
147 M_ASN1_OCTET_STRING_free(oct);
148 return NULL;
149}
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
deleted file mode 100644
index 20ba8ac8d6..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,M_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 M_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,M_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 M_ASN1_INTEGER_free(a->zone);
178 M_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 M_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 = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
248 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
249 M_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(!M_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 M_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 = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
319 X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);
320 M_ASN1_INTEGER_free(izone);
321 return NULL;
322 }
323 oct = SXNET_get_id_INTEGER(sx, izone);
324 M_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(!M_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 4c2c4a9483..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(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 aa4a605dc4..0000000000
--- a/src/lib/libcrypto/x509v3/v3err.c
+++ /dev/null
@@ -1,176 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/x509v3.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA X509V3_str_functs[]=
68 {
69{ERR_PACK(0,X509V3_F_COPY_EMAIL,0), "COPY_EMAIL"},
70{ERR_PACK(0,X509V3_F_COPY_ISSUER,0), "COPY_ISSUER"},
71{ERR_PACK(0,X509V3_F_DO_EXT_CONF,0), "DO_EXT_CONF"},
72{ERR_PACK(0,X509V3_F_DO_EXT_I2D,0), "DO_EXT_I2D"},
73{ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"},
74{ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"},
75{ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"},
76{ERR_PACK(0,X509V3_F_I2V_AUTHORITY_INFO_ACCESS,0), "I2V_AUTHORITY_INFO_ACCESS"},
77{ERR_PACK(0,X509V3_F_NOTICE_SECTION,0), "NOTICE_SECTION"},
78{ERR_PACK(0,X509V3_F_NREF_NOS,0), "NREF_NOS"},
79{ERR_PACK(0,X509V3_F_POLICY_SECTION,0), "POLICY_SECTION"},
80{ERR_PACK(0,X509V3_F_R2I_CERTPOL,0), "R2I_CERTPOL"},
81{ERR_PACK(0,X509V3_F_S2I_ASN1_IA5STRING,0), "S2I_ASN1_IA5STRING"},
82{ERR_PACK(0,X509V3_F_S2I_ASN1_INTEGER,0), "s2i_ASN1_INTEGER"},
83{ERR_PACK(0,X509V3_F_S2I_ASN1_OCTET_STRING,0), "s2i_ASN1_OCTET_STRING"},
84{ERR_PACK(0,X509V3_F_S2I_ASN1_SKEY_ID,0), "S2I_ASN1_SKEY_ID"},
85{ERR_PACK(0,X509V3_F_S2I_S2I_SKEY_ID,0), "S2I_S2I_SKEY_ID"},
86{ERR_PACK(0,X509V3_F_STRING_TO_HEX,0), "string_to_hex"},
87{ERR_PACK(0,X509V3_F_SXNET_ADD_ASC,0), "SXNET_ADD_ASC"},
88{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_INTEGER,0), "SXNET_add_id_INTEGER"},
89{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_ULONG,0), "SXNET_add_id_ulong"},
90{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ASC,0), "SXNET_get_id_asc"},
91{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ULONG,0), "SXNET_get_id_ulong"},
92{ERR_PACK(0,X509V3_F_V2I_ACCESS_DESCRIPTION,0), "V2I_ACCESS_DESCRIPTION"},
93{ERR_PACK(0,X509V3_F_V2I_ASN1_BIT_STRING,0), "V2I_ASN1_BIT_STRING"},
94{ERR_PACK(0,X509V3_F_V2I_AUTHORITY_KEYID,0), "V2I_AUTHORITY_KEYID"},
95{ERR_PACK(0,X509V3_F_V2I_BASIC_CONSTRAINTS,0), "V2I_BASIC_CONSTRAINTS"},
96{ERR_PACK(0,X509V3_F_V2I_CRLD,0), "V2I_CRLD"},
97{ERR_PACK(0,X509V3_F_V2I_EXT_KU,0), "V2I_EXT_KU"},
98{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAME,0), "v2i_GENERAL_NAME"},
99{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAMES,0), "v2i_GENERAL_NAMES"},
100{ERR_PACK(0,X509V3_F_V3_GENERIC_EXTENSION,0), "V3_GENERIC_EXTENSION"},
101{ERR_PACK(0,X509V3_F_X509V3_ADD_VALUE,0), "X509V3_add_value"},
102{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD,0), "X509V3_EXT_add"},
103{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD_ALIAS,0), "X509V3_EXT_add_alias"},
104{ERR_PACK(0,X509V3_F_X509V3_EXT_CONF,0), "X509V3_EXT_conf"},
105{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"},
106{ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"},
107{ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"},
108{ERR_PACK(0,X509V3_F_X509_PURPOSE_ADD,0), "X509_PURPOSE_add"},
109{0,NULL}
110 };
111
112static ERR_STRING_DATA X509V3_str_reasons[]=
113 {
114{X509V3_R_BAD_IP_ADDRESS ,"bad ip address"},
115{X509V3_R_BAD_OBJECT ,"bad object"},
116{X509V3_R_BN_DEC2BN_ERROR ,"bn dec2bn error"},
117{X509V3_R_BN_TO_ASN1_INTEGER_ERROR ,"bn to asn1 integer error"},
118{X509V3_R_DUPLICATE_ZONE_ID ,"duplicate zone id"},
119{X509V3_R_ERROR_CONVERTING_ZONE ,"error converting zone"},
120{X509V3_R_ERROR_IN_EXTENSION ,"error in extension"},
121{X509V3_R_EXPECTED_A_SECTION_NAME ,"expected a section name"},
122{X509V3_R_EXTENSION_NAME_ERROR ,"extension name error"},
123{X509V3_R_EXTENSION_NOT_FOUND ,"extension not found"},
124{X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED,"extension setting not supported"},
125{X509V3_R_EXTENSION_VALUE_ERROR ,"extension value error"},
126{X509V3_R_ILLEGAL_HEX_DIGIT ,"illegal hex digit"},
127{X509V3_R_INVALID_BOOLEAN_STRING ,"invalid boolean string"},
128{X509V3_R_INVALID_EXTENSION_STRING ,"invalid extension string"},
129{X509V3_R_INVALID_NAME ,"invalid name"},
130{X509V3_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
131{X509V3_R_INVALID_NULL_NAME ,"invalid null name"},
132{X509V3_R_INVALID_NULL_VALUE ,"invalid null value"},
133{X509V3_R_INVALID_NUMBER ,"invalid number"},
134{X509V3_R_INVALID_NUMBERS ,"invalid numbers"},
135{X509V3_R_INVALID_OBJECT_IDENTIFIER ,"invalid object identifier"},
136{X509V3_R_INVALID_OPTION ,"invalid option"},
137{X509V3_R_INVALID_POLICY_IDENTIFIER ,"invalid policy identifier"},
138{X509V3_R_INVALID_SECTION ,"invalid section"},
139{X509V3_R_INVALID_SYNTAX ,"invalid syntax"},
140{X509V3_R_ISSUER_DECODE_ERROR ,"issuer decode error"},
141{X509V3_R_MISSING_VALUE ,"missing value"},
142{X509V3_R_NEED_ORGANIZATION_AND_NUMBERS ,"need organization and numbers"},
143{X509V3_R_NO_CONFIG_DATABASE ,"no config database"},
144{X509V3_R_NO_ISSUER_CERTIFICATE ,"no issuer certificate"},
145{X509V3_R_NO_ISSUER_DETAILS ,"no issuer details"},
146{X509V3_R_NO_POLICY_IDENTIFIER ,"no policy identifier"},
147{X509V3_R_NO_PUBLIC_KEY ,"no public key"},
148{X509V3_R_NO_SUBJECT_DETAILS ,"no subject details"},
149{X509V3_R_ODD_NUMBER_OF_DIGITS ,"odd number of digits"},
150{X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS ,"unable to get issuer details"},
151{X509V3_R_UNABLE_TO_GET_ISSUER_KEYID ,"unable to get issuer keyid"},
152{X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT ,"unknown bit string argument"},
153{X509V3_R_UNKNOWN_EXTENSION ,"unknown extension"},
154{X509V3_R_UNKNOWN_EXTENSION_NAME ,"unknown extension name"},
155{X509V3_R_UNKNOWN_OPTION ,"unknown option"},
156{X509V3_R_UNSUPPORTED_OPTION ,"unsupported option"},
157{X509V3_R_USER_TOO_LONG ,"user too long"},
158{0,NULL}
159 };
160
161#endif
162
163void ERR_load_X509V3_strings(void)
164 {
165 static int init=1;
166
167 if (init)
168 {
169 init=0;
170#ifndef NO_ERR
171 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_functs);
172 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_reasons);
173#endif
174
175 }
176 }
diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h
deleted file mode 100644
index 96ceb7c4fb..0000000000
--- a/src/lib/libcrypto/x509v3/x509v3.h
+++ /dev/null
@@ -1,644 +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 BIT_STRING_BITNAME ENUMERATED_NAMES;
140
141typedef struct BASIC_CONSTRAINTS_st {
142int ca;
143ASN1_INTEGER *pathlen;
144} BASIC_CONSTRAINTS;
145
146
147typedef struct PKEY_USAGE_PERIOD_st {
148ASN1_GENERALIZEDTIME *notBefore;
149ASN1_GENERALIZEDTIME *notAfter;
150} PKEY_USAGE_PERIOD;
151
152typedef struct otherName_st {
153ASN1_OBJECT *type_id;
154ASN1_TYPE *value;
155} OTHERNAME;
156
157typedef struct GENERAL_NAME_st {
158
159#define GEN_OTHERNAME (0|V_ASN1_CONTEXT_SPECIFIC)
160#define GEN_EMAIL (1|V_ASN1_CONTEXT_SPECIFIC)
161#define GEN_DNS (2|V_ASN1_CONTEXT_SPECIFIC)
162#define GEN_X400 (3|V_ASN1_CONTEXT_SPECIFIC)
163#define GEN_DIRNAME (4|V_ASN1_CONTEXT_SPECIFIC)
164#define GEN_EDIPARTY (5|V_ASN1_CONTEXT_SPECIFIC)
165#define GEN_URI (6|V_ASN1_CONTEXT_SPECIFIC)
166#define GEN_IPADD (7|V_ASN1_CONTEXT_SPECIFIC)
167#define GEN_RID (8|V_ASN1_CONTEXT_SPECIFIC)
168
169int type;
170union {
171 char *ptr;
172 ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */
173 ASN1_OCTET_STRING *ip; /* iPAddress */
174 X509_NAME *dirn; /* dirn */
175 ASN1_OBJECT *rid; /* registeredID */
176 OTHERNAME *otherName; /* otherName */
177 ASN1_TYPE *other; /* ediPartyName, x400Address */
178} d;
179} GENERAL_NAME;
180
181typedef struct ACCESS_DESCRIPTION_st {
182 ASN1_OBJECT *method;
183 GENERAL_NAME *location;
184} ACCESS_DESCRIPTION;
185
186DECLARE_STACK_OF(GENERAL_NAME)
187DECLARE_ASN1_SET_OF(GENERAL_NAME)
188
189DECLARE_STACK_OF(ACCESS_DESCRIPTION)
190DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION)
191
192typedef struct DIST_POINT_NAME_st {
193/* NB: this is a CHOICE type and only one of these should be set */
194STACK_OF(GENERAL_NAME) *fullname;
195STACK_OF(X509_NAME_ENTRY) *relativename;
196} DIST_POINT_NAME;
197
198typedef struct DIST_POINT_st {
199DIST_POINT_NAME *distpoint;
200ASN1_BIT_STRING *reasons;
201STACK_OF(GENERAL_NAME) *CRLissuer;
202} DIST_POINT;
203
204DECLARE_STACK_OF(DIST_POINT)
205DECLARE_ASN1_SET_OF(DIST_POINT)
206
207typedef struct AUTHORITY_KEYID_st {
208ASN1_OCTET_STRING *keyid;
209STACK_OF(GENERAL_NAME) *issuer;
210ASN1_INTEGER *serial;
211} AUTHORITY_KEYID;
212
213/* Strong extranet structures */
214
215typedef struct SXNET_ID_st {
216 ASN1_INTEGER *zone;
217 ASN1_OCTET_STRING *user;
218} SXNETID;
219
220DECLARE_STACK_OF(SXNETID)
221DECLARE_ASN1_SET_OF(SXNETID)
222
223typedef struct SXNET_st {
224 ASN1_INTEGER *version;
225 STACK_OF(SXNETID) *ids;
226} SXNET;
227
228typedef struct NOTICEREF_st {
229 ASN1_STRING *organization;
230 STACK *noticenos;
231} NOTICEREF;
232
233typedef struct USERNOTICE_st {
234 NOTICEREF *noticeref;
235 ASN1_STRING *exptext;
236} USERNOTICE;
237
238typedef struct POLICYQUALINFO_st {
239 ASN1_OBJECT *pqualid;
240 union {
241 ASN1_IA5STRING *cpsuri;
242 USERNOTICE *usernotice;
243 ASN1_TYPE *other;
244 } d;
245} POLICYQUALINFO;
246
247DECLARE_STACK_OF(POLICYQUALINFO)
248DECLARE_ASN1_SET_OF(POLICYQUALINFO)
249
250typedef struct POLICYINFO_st {
251 ASN1_OBJECT *policyid;
252 STACK_OF(POLICYQUALINFO) *qualifiers;
253} POLICYINFO;
254
255DECLARE_STACK_OF(POLICYINFO)
256DECLARE_ASN1_SET_OF(POLICYINFO)
257
258#define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \
259",name:", val->name, ",value:", val->value);
260
261#define X509V3_set_ctx_test(ctx) \
262 X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST)
263#define X509V3_set_ctx_nodb(ctx) ctx->db = NULL;
264
265#define EXT_BITSTRING(nid, table) { nid, 0, \
266 (X509V3_EXT_NEW)ASN1_BIT_STRING_new, \
267 (X509V3_EXT_FREE)ASN1_BIT_STRING_free, \
268 (X509V3_EXT_D2I)d2i_ASN1_BIT_STRING, \
269 (X509V3_EXT_I2D)i2d_ASN1_BIT_STRING, \
270 NULL, NULL, \
271 (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \
272 (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \
273 NULL, NULL, \
274 (char *)table}
275
276#define EXT_IA5STRING(nid) { nid, 0, \
277 (X509V3_EXT_NEW)ASN1_IA5STRING_new, \
278 (X509V3_EXT_FREE)ASN1_IA5STRING_free, \
279 (X509V3_EXT_D2I)d2i_ASN1_IA5STRING, \
280 (X509V3_EXT_I2D)i2d_ASN1_IA5STRING, \
281 (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \
282 (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \
283 NULL, NULL, NULL, NULL, \
284 NULL}
285
286#define EXT_END { -1, 0, NULL, NULL, NULL, NULL, NULL, NULL, \
287 NULL, NULL, NULL, NULL, \
288 NULL}
289
290
291/* X509_PURPOSE stuff */
292
293#define EXFLAG_BCONS 0x1
294#define EXFLAG_KUSAGE 0x2
295#define EXFLAG_XKUSAGE 0x4
296#define EXFLAG_NSCERT 0x8
297
298#define EXFLAG_CA 0x10
299#define EXFLAG_SS 0x20
300#define EXFLAG_V1 0x40
301#define EXFLAG_INVALID 0x80
302#define EXFLAG_SET 0x100
303
304#define KU_DIGITAL_SIGNATURE 0x0080
305#define KU_NON_REPUDIATION 0x0040
306#define KU_KEY_ENCIPHERMENT 0x0020
307#define KU_DATA_ENCIPHERMENT 0x0010
308#define KU_KEY_AGREEMENT 0x0008
309#define KU_KEY_CERT_SIGN 0x0004
310#define KU_CRL_SIGN 0x0002
311#define KU_ENCIPHER_ONLY 0x0001
312#define KU_DECIPHER_ONLY 0x8000
313
314#define NS_SSL_CLIENT 0x80
315#define NS_SSL_SERVER 0x40
316#define NS_SMIME 0x20
317#define NS_OBJSIGN 0x10
318#define NS_SSL_CA 0x04
319#define NS_SMIME_CA 0x02
320#define NS_OBJSIGN_CA 0x01
321
322#define XKU_SSL_SERVER 0x1
323#define XKU_SSL_CLIENT 0x2
324#define XKU_SMIME 0x4
325#define XKU_CODE_SIGN 0x8
326#define XKU_SGC 0x10
327
328#define X509_PURPOSE_DYNAMIC 0x1
329#define X509_PURPOSE_DYNAMIC_NAME 0x2
330
331typedef struct x509_purpose_st {
332 int purpose;
333 int trust; /* Default trust ID */
334 int flags;
335 int (*check_purpose)(struct x509_purpose_st *, X509 *, int);
336 char *name;
337 char *sname;
338 void *usr_data;
339} X509_PURPOSE;
340
341#define X509_PURPOSE_SSL_CLIENT 1
342#define X509_PURPOSE_SSL_SERVER 2
343#define X509_PURPOSE_NS_SSL_SERVER 3
344#define X509_PURPOSE_SMIME_SIGN 4
345#define X509_PURPOSE_SMIME_ENCRYPT 5
346#define X509_PURPOSE_CRL_SIGN 6
347#define X509_PURPOSE_ANY 7
348
349#define X509_PURPOSE_MIN 1
350#define X509_PURPOSE_MAX 7
351
352DECLARE_STACK_OF(X509_PURPOSE)
353
354void ERR_load_X509V3_strings(void);
355int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp);
356BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length);
357BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void);
358void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a);
359
360int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp);
361GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp, long length);
362GENERAL_NAME *GENERAL_NAME_new(void);
363void GENERAL_NAME_free(GENERAL_NAME *a);
364STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret);
365
366int i2d_SXNET(SXNET *a, unsigned char **pp);
367SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length);
368SXNET *SXNET_new(void);
369void SXNET_free(SXNET *a);
370
371int i2d_SXNETID(SXNETID *a, unsigned char **pp);
372SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length);
373SXNETID *SXNETID_new(void);
374void SXNETID_free(SXNETID *a);
375
376int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen);
377int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen);
378int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, char *user, int userlen);
379
380ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone);
381ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone);
382ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone);
383
384int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *a, unsigned char **pp);
385AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp, long length);
386AUTHORITY_KEYID *AUTHORITY_KEYID_new(void);
387void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a);
388
389int i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **pp);
390PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a, unsigned char **pp, long length);
391PKEY_USAGE_PERIOD *PKEY_USAGE_PERIOD_new(void);
392void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a);
393
394STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new(void);
395void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a);
396STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a, unsigned char **pp, long length);
397int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp);
398STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
399 STACK_OF(GENERAL_NAME) *gen, STACK_OF(CONF_VALUE) *extlist);
400STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
401 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
402
403int i2d_OTHERNAME(OTHERNAME *a, unsigned char **pp);
404OTHERNAME *OTHERNAME_new(void);
405OTHERNAME *d2i_OTHERNAME(OTHERNAME **a, unsigned char **pp, long length);
406void OTHERNAME_free(OTHERNAME *a);
407
408char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
409ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
410
411int i2d_ext_ku(STACK_OF(ASN1_OBJECT) *a, unsigned char **pp);
412STACK_OF(ASN1_OBJECT) *d2i_ext_ku(STACK_OF(ASN1_OBJECT) **a,
413 unsigned char **pp, long length);
414void ext_ku_free(STACK_OF(ASN1_OBJECT) *a);
415STACK_OF(ASN1_OBJECT) *ext_ku_new(void);
416
417int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp);
418STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void);
419void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a);
420STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a, unsigned char **pp, long length);
421
422int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp);
423POLICYINFO *POLICYINFO_new(void);
424POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp, long length);
425void POLICYINFO_free(POLICYINFO *a);
426
427int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp);
428POLICYQUALINFO *POLICYQUALINFO_new(void);
429POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp,
430 long length);
431void POLICYQUALINFO_free(POLICYQUALINFO *a);
432
433int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp);
434USERNOTICE *USERNOTICE_new(void);
435USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp, long length);
436void USERNOTICE_free(USERNOTICE *a);
437
438int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp);
439NOTICEREF *NOTICEREF_new(void);
440NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp, long length);
441void NOTICEREF_free(NOTICEREF *a);
442
443int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp);
444STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void);
445void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a);
446STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a,
447 unsigned char **pp,long length);
448
449int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp);
450DIST_POINT *DIST_POINT_new(void);
451DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length);
452void DIST_POINT_free(DIST_POINT *a);
453
454int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp);
455DIST_POINT_NAME *DIST_POINT_NAME_new(void);
456void DIST_POINT_NAME_free(DIST_POINT_NAME *a);
457DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
458 long length);
459
460int i2d_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION *a, unsigned char **pp);
461ACCESS_DESCRIPTION *ACCESS_DESCRIPTION_new(void);
462void ACCESS_DESCRIPTION_free(ACCESS_DESCRIPTION *a);
463ACCESS_DESCRIPTION *d2i_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION **a, unsigned char **pp,
464 long length);
465
466STACK_OF(ACCESS_DESCRIPTION) *AUTHORITY_INFO_ACCESS_new(void);
467void AUTHORITY_INFO_ACCESS_free(STACK_OF(ACCESS_DESCRIPTION) *a);
468STACK_OF(ACCESS_DESCRIPTION) *d2i_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) **a,
469 unsigned char **pp, long length);
470int i2d_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) *a, unsigned char **pp);
471
472
473
474#ifdef HEADER_CONF_H
475GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf);
476void X509V3_conf_free(CONF_VALUE *val);
477X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
478X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
479int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
480int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);
481int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
482int X509V3_add_value_bool_nf(char *name, int asn1_bool,
483 STACK_OF(CONF_VALUE) **extlist);
484int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
485int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
486void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
487#endif
488
489char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
490STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
491void X509V3_string_free(X509V3_CTX *ctx, char *str);
492void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
493void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
494 X509_REQ *req, X509_CRL *crl, int flags);
495
496int X509V3_add_value(const char *name, const char *value,
497 STACK_OF(CONF_VALUE) **extlist);
498int X509V3_add_value_uchar(const char *name, const unsigned char *value,
499 STACK_OF(CONF_VALUE) **extlist);
500int X509V3_add_value_bool(const char *name, int asn1_bool,
501 STACK_OF(CONF_VALUE) **extlist);
502int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
503 STACK_OF(CONF_VALUE) **extlist);
504char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
505ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
506char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
507char * i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
508int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
509int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist);
510int X509V3_EXT_add_alias(int nid_to, int nid_from);
511void X509V3_EXT_cleanup(void);
512
513X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
514X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
515int X509V3_add_standard_extensions(void);
516STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line);
517void *X509V3_EXT_d2i(X509_EXTENSION *ext);
518void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
519
520X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
521
522char *hex_to_string(unsigned char *buffer, long len);
523unsigned char *string_to_hex(char *str, long *len);
524int name_cmp(const char *name, const char *cmp);
525
526void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,
527 int ml);
528int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
529int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
530
531int X509_check_purpose(X509 *x, int id, int ca);
532int X509_PURPOSE_get_count(void);
533X509_PURPOSE * X509_PURPOSE_get0(int idx);
534int X509_PURPOSE_get_by_sname(char *sname);
535int X509_PURPOSE_get_by_id(int id);
536int X509_PURPOSE_add(int id, int trust, int flags,
537 int (*ck)(X509_PURPOSE *, X509 *, int),
538 char *name, char *sname, void *arg);
539char *X509_PURPOSE_get0_name(X509_PURPOSE *xp);
540char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp);
541int X509_PURPOSE_get_trust(X509_PURPOSE *xp);
542void X509_PURPOSE_cleanup(void);
543int X509_PURPOSE_get_id(X509_PURPOSE *);
544
545/* BEGIN ERROR CODES */
546/* The following lines are auto generated by the script mkerr.pl. Any changes
547 * made after this point may be overwritten when the script is next run.
548 */
549
550/* Error codes for the X509V3 functions. */
551
552/* Function codes. */
553#define X509V3_F_COPY_EMAIL 122
554#define X509V3_F_COPY_ISSUER 123
555#define X509V3_F_DO_EXT_CONF 124
556#define X509V3_F_DO_EXT_I2D 135
557#define X509V3_F_HEX_TO_STRING 111
558#define X509V3_F_I2S_ASN1_ENUMERATED 121
559#define X509V3_F_I2S_ASN1_INTEGER 120
560#define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138
561#define X509V3_F_NOTICE_SECTION 132
562#define X509V3_F_NREF_NOS 133
563#define X509V3_F_POLICY_SECTION 131
564#define X509V3_F_R2I_CERTPOL 130
565#define X509V3_F_S2I_ASN1_IA5STRING 100
566#define X509V3_F_S2I_ASN1_INTEGER 108
567#define X509V3_F_S2I_ASN1_OCTET_STRING 112
568#define X509V3_F_S2I_ASN1_SKEY_ID 114
569#define X509V3_F_S2I_S2I_SKEY_ID 115
570#define X509V3_F_STRING_TO_HEX 113
571#define X509V3_F_SXNET_ADD_ASC 125
572#define X509V3_F_SXNET_ADD_ID_INTEGER 126
573#define X509V3_F_SXNET_ADD_ID_ULONG 127
574#define X509V3_F_SXNET_GET_ID_ASC 128
575#define X509V3_F_SXNET_GET_ID_ULONG 129
576#define X509V3_F_V2I_ACCESS_DESCRIPTION 139
577#define X509V3_F_V2I_ASN1_BIT_STRING 101
578#define X509V3_F_V2I_AUTHORITY_KEYID 119
579#define X509V3_F_V2I_BASIC_CONSTRAINTS 102
580#define X509V3_F_V2I_CRLD 134
581#define X509V3_F_V2I_EXT_KU 103
582#define X509V3_F_V2I_GENERAL_NAME 117
583#define X509V3_F_V2I_GENERAL_NAMES 118
584#define X509V3_F_V3_GENERIC_EXTENSION 116
585#define X509V3_F_X509V3_ADD_VALUE 105
586#define X509V3_F_X509V3_EXT_ADD 104
587#define X509V3_F_X509V3_EXT_ADD_ALIAS 106
588#define X509V3_F_X509V3_EXT_CONF 107
589#define X509V3_F_X509V3_EXT_I2D 136
590#define X509V3_F_X509V3_GET_VALUE_BOOL 110
591#define X509V3_F_X509V3_PARSE_LIST 109
592#define X509V3_F_X509_PURPOSE_ADD 137
593
594/* Reason codes. */
595#define X509V3_R_BAD_IP_ADDRESS 118
596#define X509V3_R_BAD_OBJECT 119
597#define X509V3_R_BN_DEC2BN_ERROR 100
598#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101
599#define X509V3_R_DUPLICATE_ZONE_ID 133
600#define X509V3_R_ERROR_CONVERTING_ZONE 131
601#define X509V3_R_ERROR_IN_EXTENSION 128
602#define X509V3_R_EXPECTED_A_SECTION_NAME 137
603#define X509V3_R_EXTENSION_NAME_ERROR 115
604#define X509V3_R_EXTENSION_NOT_FOUND 102
605#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103
606#define X509V3_R_EXTENSION_VALUE_ERROR 116
607#define X509V3_R_ILLEGAL_HEX_DIGIT 113
608#define X509V3_R_INVALID_BOOLEAN_STRING 104
609#define X509V3_R_INVALID_EXTENSION_STRING 105
610#define X509V3_R_INVALID_NAME 106
611#define X509V3_R_INVALID_NULL_ARGUMENT 107
612#define X509V3_R_INVALID_NULL_NAME 108
613#define X509V3_R_INVALID_NULL_VALUE 109
614#define X509V3_R_INVALID_NUMBER 140
615#define X509V3_R_INVALID_NUMBERS 141
616#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110
617#define X509V3_R_INVALID_OPTION 138
618#define X509V3_R_INVALID_POLICY_IDENTIFIER 134
619#define X509V3_R_INVALID_SECTION 135
620#define X509V3_R_INVALID_SYNTAX 143
621#define X509V3_R_ISSUER_DECODE_ERROR 126
622#define X509V3_R_MISSING_VALUE 124
623#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142
624#define X509V3_R_NO_CONFIG_DATABASE 136
625#define X509V3_R_NO_ISSUER_CERTIFICATE 121
626#define X509V3_R_NO_ISSUER_DETAILS 127
627#define X509V3_R_NO_POLICY_IDENTIFIER 139
628#define X509V3_R_NO_PUBLIC_KEY 114
629#define X509V3_R_NO_SUBJECT_DETAILS 125
630#define X509V3_R_ODD_NUMBER_OF_DIGITS 112
631#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122
632#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123
633#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111
634#define X509V3_R_UNKNOWN_EXTENSION 129
635#define X509V3_R_UNKNOWN_EXTENSION_NAME 130
636#define X509V3_R_UNKNOWN_OPTION 120
637#define X509V3_R_UNSUPPORTED_OPTION 117
638#define X509V3_R_USER_TOO_LONG 132
639
640#ifdef __cplusplus
641}
642#endif
643#endif
644
diff --git a/src/lib/libssl/LICENSE b/src/lib/libssl/LICENSE
deleted file mode 100644
index bdd5f7bdd0..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-2000 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 d73c41adcd..0000000000
--- a/src/lib/libssl/bio_ssl.c
+++ /dev/null
@@ -1,586 +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);
74static long ssl_callback_ctrl(BIO *h,int cmd,void (*fp)());
75typedef struct bio_ssl_st
76 {
77 SSL *ssl; /* The ssl handle :-) */
78 /* re-negotiate every time the total number of bytes is this size */
79 int num_renegotiates;
80 unsigned long renegotiate_count;
81 unsigned long byte_count;
82 unsigned long renegotiate_timeout;
83 unsigned long last_time;
84 } BIO_SSL;
85
86static BIO_METHOD methods_sslp=
87 {
88 BIO_TYPE_SSL,"ssl",
89 ssl_write,
90 ssl_read,
91 ssl_puts,
92 NULL, /* ssl_gets, */
93 ssl_ctrl,
94 ssl_new,
95 ssl_free,
96 ssl_callback_ctrl,
97 };
98
99BIO_METHOD *BIO_f_ssl(void)
100 {
101 return(&methods_sslp);
102 }
103
104static int ssl_new(BIO *bi)
105 {
106 BIO_SSL *bs;
107
108 bs=(BIO_SSL *)Malloc(sizeof(BIO_SSL));
109 if (bs == NULL)
110 {
111 BIOerr(BIO_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
112 return(0);
113 }
114 memset(bs,0,sizeof(BIO_SSL));
115 bi->init=0;
116 bi->ptr=(char *)bs;
117 bi->flags=0;
118 return(1);
119 }
120
121static int ssl_free(BIO *a)
122 {
123 BIO_SSL *bs;
124
125 if (a == NULL) return(0);
126 bs=(BIO_SSL *)a->ptr;
127 if (bs->ssl != NULL) SSL_shutdown(bs->ssl);
128 if (a->shutdown)
129 {
130 if (a->init && (bs->ssl != NULL))
131 SSL_free(bs->ssl);
132 a->init=0;
133 a->flags=0;
134 }
135 if (a->ptr != NULL)
136 Free(a->ptr);
137 return(1);
138 }
139
140static int ssl_read(BIO *b, char *out, int outl)
141 {
142 int ret=1;
143 BIO_SSL *sb;
144 SSL *ssl;
145 int retry_reason=0;
146 int r=0;
147
148 if (out == NULL) return(0);
149 sb=(BIO_SSL *)b->ptr;
150 ssl=sb->ssl;
151
152 BIO_clear_retry_flags(b);
153
154#if 0
155 if (!SSL_is_init_finished(ssl))
156 {
157/* ret=SSL_do_handshake(ssl); */
158 if (ret > 0)
159 {
160
161 outflags=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);
162 ret= -1;
163 goto end;
164 }
165 }
166#endif
167/* if (ret > 0) */
168 ret=SSL_read(ssl,out,outl);
169
170 switch (SSL_get_error(ssl,ret))
171 {
172 case SSL_ERROR_NONE:
173 if (ret <= 0) break;
174 if (sb->renegotiate_count > 0)
175 {
176 sb->byte_count+=ret;
177 if (sb->byte_count > sb->renegotiate_count)
178 {
179 sb->byte_count=0;
180 sb->num_renegotiates++;
181 SSL_renegotiate(ssl);
182 r=1;
183 }
184 }
185 if ((sb->renegotiate_timeout > 0) && (!r))
186 {
187 unsigned long tm;
188
189 tm=(unsigned long)time(NULL);
190 if (tm > sb->last_time+sb->renegotiate_timeout)
191 {
192 sb->last_time=tm;
193 sb->num_renegotiates++;
194 SSL_renegotiate(ssl);
195 }
196 }
197
198 break;
199 case SSL_ERROR_WANT_READ:
200 BIO_set_retry_read(b);
201 break;
202 case SSL_ERROR_WANT_WRITE:
203 BIO_set_retry_write(b);
204 break;
205 case SSL_ERROR_WANT_X509_LOOKUP:
206 BIO_set_retry_special(b);
207 retry_reason=BIO_RR_SSL_X509_LOOKUP;
208 break;
209 case SSL_ERROR_WANT_CONNECT:
210 BIO_set_retry_special(b);
211 retry_reason=BIO_RR_CONNECT;
212 break;
213 case SSL_ERROR_SYSCALL:
214 case SSL_ERROR_SSL:
215 case SSL_ERROR_ZERO_RETURN:
216 default:
217 break;
218 }
219
220 b->retry_reason=retry_reason;
221 return(ret);
222 }
223
224static int ssl_write(BIO *b, char *out, int outl)
225 {
226 int ret,r=0;
227 int retry_reason=0;
228 SSL *ssl;
229 BIO_SSL *bs;
230
231 if (out == NULL) return(0);
232 bs=(BIO_SSL *)b->ptr;
233 ssl=bs->ssl;
234
235 BIO_clear_retry_flags(b);
236
237/* ret=SSL_do_handshake(ssl);
238 if (ret > 0) */
239 ret=SSL_write(ssl,out,outl);
240
241 switch (SSL_get_error(ssl,ret))
242 {
243 case SSL_ERROR_NONE:
244 if (ret <= 0) break;
245 if (bs->renegotiate_count > 0)
246 {
247 bs->byte_count+=ret;
248 if (bs->byte_count > bs->renegotiate_count)
249 {
250 bs->byte_count=0;
251 bs->num_renegotiates++;
252 SSL_renegotiate(ssl);
253 r=1;
254 }
255 }
256 if ((bs->renegotiate_timeout > 0) && (!r))
257 {
258 unsigned long tm;
259
260 tm=(unsigned long)time(NULL);
261 if (tm > bs->last_time+bs->renegotiate_timeout)
262 {
263 bs->last_time=tm;
264 bs->num_renegotiates++;
265 SSL_renegotiate(ssl);
266 }
267 }
268 break;
269 case SSL_ERROR_WANT_WRITE:
270 BIO_set_retry_write(b);
271 break;
272 case SSL_ERROR_WANT_READ:
273 BIO_set_retry_read(b);
274 break;
275 case SSL_ERROR_WANT_X509_LOOKUP:
276 BIO_set_retry_special(b);
277 retry_reason=BIO_RR_SSL_X509_LOOKUP;
278 break;
279 case SSL_ERROR_WANT_CONNECT:
280 BIO_set_retry_special(b);
281 retry_reason=BIO_RR_CONNECT;
282 case SSL_ERROR_SYSCALL:
283 case SSL_ERROR_SSL:
284 default:
285 break;
286 }
287
288 b->retry_reason=retry_reason;
289 return(ret);
290 }
291
292static long ssl_ctrl(BIO *b, int cmd, long num, char *ptr)
293 {
294 SSL **sslp,*ssl;
295 BIO_SSL *bs;
296 BIO *dbio,*bio;
297 long ret=1;
298
299 bs=(BIO_SSL *)b->ptr;
300 ssl=bs->ssl;
301 if ((ssl == NULL) && (cmd != BIO_C_SET_SSL))
302 return(0);
303 switch (cmd)
304 {
305 case BIO_CTRL_RESET:
306 SSL_shutdown(ssl);
307
308 if (ssl->handshake_func == ssl->method->ssl_connect)
309 SSL_set_connect_state(ssl);
310 else if (ssl->handshake_func == ssl->method->ssl_accept)
311 SSL_set_accept_state(ssl);
312
313 SSL_clear(ssl);
314
315 if (b->next_bio != NULL)
316 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
317 else if (ssl->rbio != NULL)
318 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
319 else
320 ret=1;
321 break;
322 case BIO_CTRL_INFO:
323 ret=0;
324 break;
325 case BIO_C_SSL_MODE:
326 if (num) /* client mode */
327 SSL_set_connect_state(ssl);
328 else
329 SSL_set_accept_state(ssl);
330 break;
331 case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT:
332 ret=bs->renegotiate_timeout;
333 if (num < 60) num=5;
334 bs->renegotiate_timeout=(unsigned long)num;
335 bs->last_time=(unsigned long)time(NULL);
336 break;
337 case BIO_C_SET_SSL_RENEGOTIATE_BYTES:
338 ret=bs->renegotiate_count;
339 if ((long)num >=512)
340 bs->renegotiate_count=(unsigned long)num;
341 break;
342 case BIO_C_GET_SSL_NUM_RENEGOTIATES:
343 ret=bs->num_renegotiates;
344 break;
345 case BIO_C_SET_SSL:
346 if (ssl != NULL)
347 ssl_free(b);
348 b->shutdown=(int)num;
349 ssl=(SSL *)ptr;
350 ((BIO_SSL *)b->ptr)->ssl=ssl;
351 bio=SSL_get_rbio(ssl);
352 if (bio != NULL)
353 {
354 if (b->next_bio != NULL)
355 BIO_push(bio,b->next_bio);
356 b->next_bio=bio;
357 CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO);
358 }
359 b->init=1;
360 break;
361 case BIO_C_GET_SSL:
362 if (ptr != NULL)
363 {
364 sslp=(SSL **)ptr;
365 *sslp=ssl;
366 }
367 else
368 ret=0;
369 break;
370 case BIO_CTRL_GET_CLOSE:
371 ret=b->shutdown;
372 break;
373 case BIO_CTRL_SET_CLOSE:
374 b->shutdown=(int)num;
375 break;
376 case BIO_CTRL_WPENDING:
377 ret=BIO_ctrl(ssl->wbio,cmd,num,ptr);
378 break;
379 case BIO_CTRL_PENDING:
380 ret=SSL_pending(ssl);
381 if (ret == 0)
382 ret=BIO_pending(ssl->rbio);
383 break;
384 case BIO_CTRL_FLUSH:
385 BIO_clear_retry_flags(b);
386 ret=BIO_ctrl(ssl->wbio,cmd,num,ptr);
387 BIO_copy_next_retry(b);
388 break;
389 case BIO_CTRL_PUSH:
390 if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio))
391 {
392 SSL_set_bio(ssl,b->next_bio,b->next_bio);
393 CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);
394 }
395 break;
396 case BIO_CTRL_POP:
397 /* ugly bit of a hack */
398 if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */
399 {
400 BIO_free_all(ssl->wbio);
401 }
402 ssl->wbio=NULL;
403 ssl->rbio=NULL;
404 break;
405 case BIO_C_DO_STATE_MACHINE:
406 BIO_clear_retry_flags(b);
407
408 b->retry_reason=0;
409 ret=(int)SSL_do_handshake(ssl);
410
411 switch (SSL_get_error(ssl,(int)ret))
412 {
413 case SSL_ERROR_WANT_READ:
414 BIO_set_flags(b,
415 BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);
416 break;
417 case SSL_ERROR_WANT_WRITE:
418 BIO_set_flags(b,
419 BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY);
420 break;
421 case SSL_ERROR_WANT_CONNECT:
422 BIO_set_flags(b,
423 BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY);
424 b->retry_reason=b->next_bio->retry_reason;
425 break;
426 default:
427 break;
428 }
429 break;
430 case BIO_CTRL_DUP:
431 dbio=(BIO *)ptr;
432 if (((BIO_SSL *)dbio->ptr)->ssl != NULL)
433 SSL_free(((BIO_SSL *)dbio->ptr)->ssl);
434 ((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl);
435 ((BIO_SSL *)dbio->ptr)->renegotiate_count=
436 ((BIO_SSL *)b->ptr)->renegotiate_count;
437 ((BIO_SSL *)dbio->ptr)->byte_count=
438 ((BIO_SSL *)b->ptr)->byte_count;
439 ((BIO_SSL *)dbio->ptr)->renegotiate_timeout=
440 ((BIO_SSL *)b->ptr)->renegotiate_timeout;
441 ((BIO_SSL *)dbio->ptr)->last_time=
442 ((BIO_SSL *)b->ptr)->last_time;
443 ret=(((BIO_SSL *)dbio->ptr)->ssl != NULL);
444 break;
445 case BIO_C_GET_FD:
446 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
447 break;
448 case BIO_CTRL_SET_CALLBACK:
449 {
450#if 0 /* FIXME: Should this be used? -- Richard Levitte */
451 BIOerr(SSL_F_SSL_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
452 ret = -1;
453#else
454 ret=0;
455#endif
456 }
457 break;
458 case BIO_CTRL_GET_CALLBACK:
459 {
460 void (**fptr)();
461
462 fptr=(void (**)())ptr;
463 *fptr=SSL_get_info_callback(ssl);
464 }
465 break;
466 default:
467 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
468 break;
469 }
470 return(ret);
471 }
472
473static long ssl_callback_ctrl(BIO *b, int cmd, void (*fp)())
474 {
475 SSL *ssl;
476 BIO_SSL *bs;
477 long ret=1;
478
479 bs=(BIO_SSL *)b->ptr;
480 ssl=bs->ssl;
481 switch (cmd)
482 {
483 case BIO_CTRL_SET_CALLBACK:
484 {
485 SSL_set_info_callback(ssl,fp);
486 }
487 break;
488 default:
489 ret=BIO_callback_ctrl(ssl->rbio,cmd,fp);
490 break;
491 }
492 return(ret);
493 }
494
495static int ssl_puts(BIO *bp, char *str)
496 {
497 int n,ret;
498
499 n=strlen(str);
500 ret=BIO_write(bp,str,n);
501 return(ret);
502 }
503
504BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx)
505 {
506 BIO *ret=NULL,*buf=NULL,*ssl=NULL;
507
508 if ((buf=BIO_new(BIO_f_buffer())) == NULL)
509 return(NULL);
510 if ((ssl=BIO_new_ssl_connect(ctx)) == NULL)
511 goto err;
512 if ((ret=BIO_push(buf,ssl)) == NULL)
513 goto err;
514 return(ret);
515err:
516 if (buf != NULL) BIO_free(buf);
517 if (ssl != NULL) BIO_free(ssl);
518 return(NULL);
519 }
520
521BIO *BIO_new_ssl_connect(SSL_CTX *ctx)
522 {
523 BIO *ret=NULL,*con=NULL,*ssl=NULL;
524
525 if ((con=BIO_new(BIO_s_connect())) == NULL)
526 return(NULL);
527 if ((ssl=BIO_new_ssl(ctx,1)) == NULL)
528 goto err;
529 if ((ret=BIO_push(ssl,con)) == NULL)
530 goto err;
531 return(ret);
532err:
533 if (con != NULL) BIO_free(con);
534 if (ret != NULL) BIO_free(ret);
535 return(NULL);
536 }
537
538BIO *BIO_new_ssl(SSL_CTX *ctx, int client)
539 {
540 BIO *ret;
541 SSL *ssl;
542
543 if ((ret=BIO_new(BIO_f_ssl())) == NULL)
544 return(NULL);
545 if ((ssl=SSL_new(ctx)) == NULL)
546 {
547 BIO_free(ret);
548 return(NULL);
549 }
550 if (client)
551 SSL_set_connect_state(ssl);
552 else
553 SSL_set_accept_state(ssl);
554
555 BIO_set_ssl(ret,ssl,BIO_CLOSE);
556 return(ret);
557 }
558
559int BIO_ssl_copy_session_id(BIO *t, BIO *f)
560 {
561 t=BIO_find_type(t,BIO_TYPE_SSL);
562 f=BIO_find_type(f,BIO_TYPE_SSL);
563 if ((t == NULL) || (f == NULL))
564 return(0);
565 if ( (((BIO_SSL *)t->ptr)->ssl == NULL) ||
566 (((BIO_SSL *)f->ptr)->ssl == NULL))
567 return(0);
568 SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl,((BIO_SSL *)f->ptr)->ssl);
569 return(1);
570 }
571
572void BIO_ssl_shutdown(BIO *b)
573 {
574 SSL *s;
575
576 while (b != NULL)
577 {
578 if (b->method->type == BIO_TYPE_SSL)
579 {
580 s=((BIO_SSL *)b->ptr)->ssl;
581 SSL_shutdown(s);
582 break;
583 }
584 b=b->next_bio;
585 }
586 }
diff --git a/src/lib/libssl/doc/openssl.cnf b/src/lib/libssl/doc/openssl.cnf
deleted file mode 100644
index dbe8cbefe0..0000000000
--- a/src/lib/libssl/doc/openssl.cnf
+++ /dev/null
@@ -1,244 +0,0 @@
1#
2# OpenSSL example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6# This definition stops the following lines choking if HOME isn't
7# defined.
8HOME = .
9RANDFILE = $ENV::HOME/.rnd
10
11# Extra OBJECT IDENTIFIER info:
12#oid_file = $ENV::HOME/.oid
13oid_section = new_oids
14
15# To use this configuration file with the "-extfile" option of the
16# "openssl x509" utility, name here the section containing the
17# X.509v3 extensions to use:
18# extensions =
19# (Alternatively, use a configuration file that has only
20# X.509v3 extensions in its main [= default] section.)
21
22[ new_oids ]
23
24# We can add new OIDs in here for use by 'ca' and 'req'.
25# Add a simple OID like this:
26# testoid1=1.2.3.4
27# Or use config file substitution like this:
28# testoid2=${testoid1}.5.6
29
30####################################################################
31[ ca ]
32default_ca = CA_default # The default ca section
33
34####################################################################
35[ CA_default ]
36
37dir = ./demoCA # Where everything is kept
38certs = $dir/certs # Where the issued certs are kept
39crl_dir = $dir/crl # Where the issued crl are kept
40database = $dir/index.txt # database index file.
41new_certs_dir = $dir/newcerts # default place for new certs.
42
43certificate = $dir/cacert.pem # The CA certificate
44serial = $dir/serial # The current serial number
45crl = $dir/crl.pem # The current CRL
46private_key = $dir/private/cakey.pem# The private key
47RANDFILE = $dir/private/.rand # private random number file
48
49x509_extensions = usr_cert # The extentions to add to the cert
50
51# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
52# so this is commented out by default to leave a V1 CRL.
53# crl_extensions = crl_ext
54
55default_days = 365 # how long to certify for
56default_crl_days= 30 # how long before next CRL
57default_md = md5 # which md to use.
58preserve = no # keep passed DN ordering
59
60# A few difference way of specifying how similar the request should look
61# For type CA, the listed attributes must be the same, and the optional
62# and supplied fields are just that :-)
63policy = policy_match
64
65# For the CA policy
66[ policy_match ]
67countryName = match
68stateOrProvinceName = match
69organizationName = match
70organizationalUnitName = optional
71commonName = supplied
72emailAddress = optional
73
74# For the 'anything' policy
75# At this point in time, you must list all acceptable 'object'
76# types.
77[ policy_anything ]
78countryName = optional
79stateOrProvinceName = optional
80localityName = optional
81organizationName = optional
82organizationalUnitName = optional
83commonName = supplied
84emailAddress = optional
85
86####################################################################
87[ req ]
88default_bits = 1024
89default_keyfile = privkey.pem
90distinguished_name = req_distinguished_name
91attributes = req_attributes
92x509_extensions = v3_ca # The extentions to add to the self signed cert
93
94# Passwords for private keys if not present they will be prompted for
95# input_password = secret
96# output_password = secret
97
98# This sets a mask for permitted string types. There are several options.
99# default: PrintableString, T61String, BMPString.
100# pkix : PrintableString, BMPString.
101# utf8only: only UTF8Strings.
102# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
103# MASK:XXXX a literal mask value.
104# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings
105# so use this option with caution!
106string_mask = nombstr
107
108# req_extensions = v3_req # The extensions to add to a certificate request
109
110[ req_distinguished_name ]
111countryName = Country Name (2 letter code)
112countryName_default = AU
113countryName_min = 2
114countryName_max = 2
115
116stateOrProvinceName = State or Province Name (full name)
117stateOrProvinceName_default = Some-State
118
119localityName = Locality Name (eg, city)
120
1210.organizationName = Organization Name (eg, company)
1220.organizationName_default = Internet Widgits Pty Ltd
123
124# we can do this but it is not needed normally :-)
125#1.organizationName = Second Organization Name (eg, company)
126#1.organizationName_default = World Wide Web Pty Ltd
127
128organizationalUnitName = Organizational Unit Name (eg, section)
129#organizationalUnitName_default =
130
131commonName = Common Name (eg, YOUR name)
132commonName_max = 64
133
134emailAddress = Email Address
135emailAddress_max = 40
136
137# SET-ex3 = SET extension number 3
138
139[ req_attributes ]
140challengePassword = A challenge password
141challengePassword_min = 4
142challengePassword_max = 20
143
144unstructuredName = An optional company name
145
146[ usr_cert ]
147
148# These extensions are added when 'ca' signs a request.
149
150# This goes against PKIX guidelines but some CAs do it and some software
151# requires this to avoid interpreting an end user certificate as a CA.
152
153basicConstraints=CA:FALSE
154
155# Here are some examples of the usage of nsCertType. If it is omitted
156# the certificate can be used for anything *except* object signing.
157
158# This is OK for an SSL server.
159# nsCertType = server
160
161# For an object signing certificate this would be used.
162# nsCertType = objsign
163
164# For normal client use this is typical
165# nsCertType = client, email
166
167# and for everything including object signing:
168# nsCertType = client, email, objsign
169
170# This is typical in keyUsage for a client certificate.
171# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
172
173# This will be displayed in Netscape's comment listbox.
174nsComment = "OpenSSL Generated Certificate"
175
176# PKIX recommendations harmless if included in all certificates.
177subjectKeyIdentifier=hash
178authorityKeyIdentifier=keyid,issuer:always
179
180# This stuff is for subjectAltName and issuerAltname.
181# Import the email address.
182# subjectAltName=email:copy
183
184# Copy subject details
185# issuerAltName=issuer:copy
186
187#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
188#nsBaseUrl
189#nsRevocationUrl
190#nsRenewalUrl
191#nsCaPolicyUrl
192#nsSslServerName
193
194[ v3_req ]
195
196# Extensions to add to a certificate request
197
198basicConstraints = CA:FALSE
199keyUsage = nonRepudiation, digitalSignature, keyEncipherment
200
201[ v3_ca ]
202
203
204# Extensions for a typical CA
205
206
207# PKIX recommendation.
208
209subjectKeyIdentifier=hash
210
211authorityKeyIdentifier=keyid:always,issuer:always
212
213# This is what PKIX recommends but some broken software chokes on critical
214# extensions.
215#basicConstraints = critical,CA:true
216# So we do this instead.
217basicConstraints = CA:true
218
219# Key usage: this is typical for a CA certificate. However since it will
220# prevent it being used as an test self-signed certificate it is best
221# left out by default.
222# keyUsage = cRLSign, keyCertSign
223
224# Some might want this also
225# nsCertType = sslCA, emailCA
226
227# Include email address in subject alt name: another PKIX recommendation
228# subjectAltName=email:copy
229# Copy issuer details
230# issuerAltName=issuer:copy
231
232# DER hex encoding of an extension: beware experts only!
233# obj=DER:02:03
234# Where 'obj' is a standard or added object
235# You can even override a supported extension:
236# basicConstraints= critical, DER:30:03:01:01:FF
237
238[ crl_ext ]
239
240# CRL extensions.
241# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
242
243# issuerAltName=issuer:copy
244authorityKeyIdentifier=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 880eace4da..0000000000
--- a/src/lib/libssl/doc/openssl.txt
+++ /dev/null
@@ -1,1176 +0,0 @@
1
2This is some preliminary documentation for OpenSSL.
3
4Contents:
5
6 OpenSSL X509V3 extension configuration
7 X509V3 Extension code: programmers guide
8 PKCS#12 Library
9
10
11==============================================================================
12 OpenSSL X509V3 extension configuration
13==============================================================================
14
15OpenSSL X509V3 extension configuration: preliminary documentation.
16
17INTRODUCTION.
18
19For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now
20possible to add and print out common X509 V3 certificate and CRL extensions.
21
22BEGINNERS NOTE
23
24For most simple applications you don't need to know too much about extensions:
25the default openssl.cnf values will usually do sensible things.
26
27If you want to know more you can initially quickly look through the sections
28describing how the standard OpenSSL utilities display and add extensions and
29then the list of supported extensions.
30
31For more technical information about the meaning of extensions see:
32
33http://www.imc.org/ietf-pkix/
34http://home.netscape.com/eng/security/certs.html
35
36PRINTING EXTENSIONS.
37
38Extension values are automatically printed out for supported extensions.
39
40openssl x509 -in cert.pem -text
41openssl crl -in crl.pem -text
42
43will give information in the extension printout, for example:
44
45 X509v3 extensions:
46 X509v3 Basic Constraints:
47 CA:TRUE
48 X509v3 Subject Key Identifier:
49 73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15
50 X509v3 Authority Key Identifier:
51 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
52 X509v3 Key Usage:
53 Certificate Sign, CRL Sign
54 X509v3 Subject Alternative Name:
55 email:email@1.address, email:email@2.address
56
57CONFIGURATION FILES.
58
59The OpenSSL utilities 'ca' and 'req' can now have extension sections listing
60which certificate extensions to include. In each case a line:
61
62x509_extensions = extension_section
63
64indicates which section contains the extensions. In the case of 'req' the
65extension section is used when the -x509 option is present to create a
66self signed root certificate.
67
68The 'x509' utility also supports extensions when it signs a certificate.
69The -extfile option is used to set the configuration file containing the
70extensions. In this case a line with:
71
72extensions = extension_section
73
74in the nameless (default) section is used. If no such line is included then
75it uses the default section.
76
77You can also add extensions to CRLs: a line
78
79crl_extensions = crl_extension_section
80
81will include extensions when the -gencrl option is used with the 'ca' utility.
82You can add any extension to a CRL but of the supported extensions only
83issuerAltName and authorityKeyIdentifier make any real sense. Note: these are
84CRL extensions NOT CRL *entry* extensions which cannot currently be generated.
85CRL entry extensions can be displayed.
86
87NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL
88you should not include a crl_extensions line in the configuration file.
89
90As with all configuration files you can use the inbuilt environment expansion
91to allow the values to be passed in the environment. Therefore if you have
92several extension sections used for different purposes you can have a line:
93
94x509_extensions = $ENV::ENV_EXT
95
96and set the ENV_EXT environment variable before calling the relevant utility.
97
98EXTENSION SYNTAX.
99
100Extensions have the basic form:
101
102extension_name=[critical,] extension_options
103
104the use of the critical option makes the extension critical. Extreme caution
105should be made when using the critical flag. If an extension is marked
106as critical then any client that does not understand the extension should
107reject it as invalid. Some broken software will reject certificates which
108have *any* critical extensions (these violates PKIX but we have to live
109with it).
110
111There are three main types of extension: string extensions, multi-valued
112extensions, and raw extensions.
113
114String extensions simply have a string which contains either the value itself
115or how it is obtained.
116
117For example:
118
119nsComment="This is a Comment"
120
121Multi-valued extensions have a short form and a long form. The short form
122is a list of names and values:
123
124basicConstraints=critical,CA:true,pathlen:1
125
126The long form allows the values to be placed in a separate section:
127
128basicConstraints=critical,@bs_section
129
130[bs_section]
131
132CA=true
133pathlen=1
134
135Both forms are equivalent. However it should be noted that in some cases the
136same name can appear multiple times, for example,
137
138subjectAltName=email:steve@here,email:steve@there
139
140in this case an equivalent long form is:
141
142subjectAltName=@alt_section
143
144[alt_section]
145
146email.1=steve@here
147email.2=steve@there
148
149This is because the configuration file code cannot handle the same name
150occurring twice in the same section.
151
152The syntax of raw extensions is governed by the extension code: it can
153for example contain data in multiple sections. The correct syntax to
154use is defined by the extension code itself: check out the certificate
155policies extension for an example.
156
157In addition it is also possible to use the word DER to include arbitrary
158data in any extension.
159
1601.2.3.4=critical,DER:01:02:03:04
1611.2.3.4=DER:01020304
162
163The value following DER is a hex dump of the DER encoding of the extension
164Any extension can be placed in this form to override the default behaviour.
165For example:
166
167basicConstraints=critical,DER:00:01:02:03
168
169WARNING: DER should be used with caution. It is possible to create totally
170invalid extensions unless care is taken.
171
172CURRENTLY SUPPORTED EXTENSIONS.
173
174If you aren't sure about extensions then they can be largely ignored: its only
175when you want to do things like restrict certificate usage when you need to
176worry about them.
177
178The only extension that a beginner might want to look at is Basic Constraints.
179If in addition you want to try Netscape object signing the you should also
180look at Netscape Certificate Type.
181
182Literal String extensions.
183
184In each case the 'value' of the extension is placed directly in the
185extension. Currently supported extensions in this category are: nsBaseUrl,
186nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl,
187nsSslServerName and nsComment.
188
189For example:
190
191nsComment="This is a test comment"
192
193Bit Strings.
194
195Bit string extensions just consist of a list of supported bits, currently
196two extensions are in this category: PKIX keyUsage and the Netscape specific
197nsCertType.
198
199nsCertType (netscape certificate type) takes the flags: client, server, email,
200objsign, reserved, sslCA, emailCA, objCA.
201
202keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation,
203keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign,
204encipherOnly, decipherOnly.
205
206For example:
207
208nsCertType=server
209
210keyUsage=digitalSignature, nonRepudiation
211
212Hints on Netscape Certificate Type.
213
214Other than Basic Constraints this is the only extension a beginner might
215want to use, if you want to try Netscape object signing, otherwise it can
216be ignored.
217
218If you want a certificate that can be used just for object signing then:
219
220nsCertType=objsign
221
222will do the job. If you want to use it as a normal end user and server
223certificate as well then
224
225nsCertType=objsign,email,server
226
227is more appropriate. You cannot use a self signed certificate for object
228signing (well Netscape signtool can but it cheats!) so you need to create
229a CA certificate and sign an end user certificate with it.
230
231Side note: If you want to conform to the Netscape specifications then you
232should really also set:
233
234nsCertType=objCA
235
236in the *CA* certificate for just an object signing CA and
237
238nsCertType=objCA,emailCA,sslCA
239
240for everything. Current Netscape software doesn't enforce this so it can
241be omitted.
242
243Basic Constraints.
244
245This is generally the only extension you need to worry about for simple
246applications. If you want your certificate to be usable as a CA certificate
247(in addition to an end user certificate) then you set this to:
248
249basicConstraints=CA:TRUE
250
251if you want to be certain the certificate cannot be used as a CA then do:
252
253basicConstraints=CA:FALSE
254
255The rest of this section describes more advanced usage.
256
257Basic constraints is a multi-valued extension that supports a CA and an
258optional pathlen option. The CA option takes the values true and false and
259pathlen takes an integer. Note if the CA option is false the pathlen option
260should be omitted.
261
262The pathlen parameter indicates the maximum number of CAs that can appear
263below this one in a chain. So if you have a CA with a pathlen of zero it can
264only be used to sign end user certificates and not further CAs. This all
265assumes that the software correctly interprets this extension of course.
266
267Examples:
268
269basicConstraints=CA:TRUE
270basicConstraints=critical,CA:TRUE, pathlen:0
271
272NOTE: for a CA to be considered valid it must have the CA option set to
273TRUE. An end user certificate MUST NOT have the CA value set to true.
274According to PKIX recommendations it should exclude the extension entirely,
275however some software may require CA set to FALSE for end entity certificates.
276
277Extended Key Usage.
278
279This extensions consists of a list of usages.
280
281These can either be object short names of the dotted numerical form of OIDs.
282While any OID can be used only certain values make sense. In particular the
283following PKIX, NS and MS values are meaningful:
284
285Value Meaning
286----- -------
287serverAuth SSL/TLS Web Server Authentication.
288clientAuth SSL/TLS Web Client Authentication.
289codeSigning Code signing.
290emailProtection E-mail Protection (S/MIME).
291timeStamping Trusted Timestamping
292msCodeInd Microsoft Individual Code Signing (authenticode)
293msCodeCom Microsoft Commercial Code Signing (authenticode)
294msCTLSign Microsoft Trust List Signing
295msSGC Microsoft Server Gated Crypto
296msEFS Microsoft Encrypted File System
297nsSGC Netscape Server Gated Crypto
298
299For example, under IE5 a CA can be used for any purpose: by including a list
300of the above usages the CA can be restricted to only authorised uses.
301
302Note: software packages may place additional interpretations on certificate
303use, in particular some usages may only work for selected CAs. Don't for example
304expect just including msSGC or nsSGC will automatically mean that a certificate
305can be used for SGC ("step up" encryption) otherwise anyone could use it.
306
307Examples:
308
309extendedKeyUsage=critical,codeSigning,1.2.3.4
310extendedKeyUsage=nsSGC,msSGC
311
312Subject Key Identifier.
313
314This is really a string extension and can take two possible values. Either
315a hex string giving details of the extension value to include or the word
316'hash' which then automatically follow PKIX guidelines in selecting and
317appropriate key identifier. The use of the hex string is strongly discouraged.
318
319Example: subjectKeyIdentifier=hash
320
321Authority Key Identifier.
322
323The authority key identifier extension permits two options. keyid and issuer:
324both can take the optional value "always".
325
326If the keyid option is present an attempt is made to copy the subject key
327identifier from the parent certificate. If the value "always" is present
328then an error is returned if the option fails.
329
330The issuer option copies the issuer and serial number from the issuer
331certificate. Normally this will only be done if the keyid option fails or
332is not included: the "always" flag will always include the value.
333
334Subject Alternative Name.
335
336The subject alternative name extension allows various literal values to be
337included in the configuration file. These include "email" (an email address)
338"URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a
339registered ID: OBJECT IDENTIFIER) and IP (and IP address).
340
341Also the email option include a special 'copy' value. This will automatically
342include and email addresses contained in the certificate subject name in
343the extension.
344
345Examples:
346
347subjectAltName=email:copy,email:my@other.address,URL:http://my.url.here/
348subjectAltName=email:my@other.address,RID:1.2.3.4
349
350Issuer Alternative Name.
351
352The issuer alternative name option supports all the literal options of
353subject alternative name. It does *not* support the email:copy option because
354that would not make sense. It does support an additional issuer:copy option
355that will copy all the subject alternative name values from the issuer
356certificate (if possible).
357
358CRL distribution points.
359
360This is a multi-valued extension that supports all the literal options of
361subject alternative name. Of the few software packages that currently interpret
362this extension most only interpret the URI option.
363
364Currently each option will set a new DistributionPoint with the fullName
365field set to the given value.
366
367Other fields like cRLissuer and reasons cannot currently be set or displayed:
368at this time no examples were available that used these fields.
369
370If you see this extension with <UNSUPPORTED> when you attempt to print it out
371or it doesn't appear to display correctly then let me know, including the
372certificate (mail me at steve@openssl.org) .
373
374Examples:
375
376crlDistributionPoints=URI:http://www.myhost.com/myca.crl
377crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
378
379Certificate Policies.
380
381This is a RAW extension. It attempts to display the contents of this extension:
382unfortunately this extension is often improperly encoded.
383
384The certificate policies extension will rarely be used in practice: few
385software packages interpret it correctly or at all. IE5 does partially
386support this extension: but it needs the 'ia5org' option because it will
387only correctly support a broken encoding. Of the options below only the
388policy OID, explicitText and CPS options are displayed with IE5.
389
390All the fields of this extension can be set by using the appropriate syntax.
391
392If you follow the PKIX recommendations of not including any qualifiers and just
393using only one OID then you just include the value of that OID. Multiple OIDs
394can be set separated by commas, for example:
395
396certificatePolicies= 1.2.4.5, 1.1.3.4
397
398If you wish to include qualifiers then the policy OID and qualifiers need to
399be specified in a separate section: this is done by using the @section syntax
400instead of a literal OID value.
401
402The section referred to must include the policy OID using the name
403policyIdentifier, cPSuri qualifiers can be included using the syntax:
404
405CPS.nnn=value
406
407userNotice qualifiers can be set using the syntax:
408
409userNotice.nnn=@notice
410
411The value of the userNotice qualifier is specified in the relevant section.
412This section can include explicitText, organization and noticeNumbers
413options. explicitText and organization are text strings, noticeNumbers is a
414comma separated list of numbers. The organization and noticeNumbers options
415(if included) must BOTH be present. If you use the userNotice option with IE5
416then you need the 'ia5org' option at the top level to modify the encoding:
417otherwise it will not be interpreted properly.
418
419Example:
420
421certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
422
423[polsect]
424
425policyIdentifier = 1.3.5.8
426CPS.1="http://my.host.name/"
427CPS.2="http://my.your.name/"
428userNotice.1=@notice
429
430[notice]
431
432explicitText="Explicit Text Here"
433organization="Organisation Name"
434noticeNumbers=1,2,3,4
435
436TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
437according to PKIX it should be of type DisplayText but Verisign uses an
438IA5STRING and IE5 needs this too.
439
440Display only extensions.
441
442Some extensions are only partially supported and currently are only displayed
443but cannot be set. These include private key usage period, CRL number, and
444CRL reason.
445
446==============================================================================
447 X509V3 Extension code: programmers guide
448==============================================================================
449
450The purpose of the extension code is twofold. It allows an extension to be
451created from a string or structure describing its contents and it prints out an
452extension in a human or machine readable form.
453
4541. Initialisation and cleanup.
455
456No special initialisation is needed before calling the extension functions.
457You used to have to call X509V3_add_standard_extensions(); but this is no longer
458required and this function no longer does anything.
459
460void X509V3_EXT_cleanup(void);
461
462This function should be called to cleanup the extension code if any custom
463extensions have been added. If no custom extensions have been added then this
464call does nothing. After this call all custom extension code is freed up but
465you can still use the standard extensions.
466
4672. Printing and parsing extensions.
468
469The simplest way to print out extensions is via the standard X509 printing
470routines: if you use the standard X509_print() function, the supported
471extensions will be printed out automatically.
472
473The following functions allow finer control over extension display:
474
475int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
476int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
477
478These two functions print out an individual extension to a BIO or FILE pointer.
479Currently the flag argument is unused and should be set to 0. The 'indent'
480argument is the number of spaces to indent each line.
481
482void *X509V3_EXT_d2i(X509_EXTENSION *ext);
483
484This function parses an extension and returns its internal structure. The
485precise structure you get back depends on the extension being parsed. If the
486extension if basicConstraints you will get back a pointer to a
487BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
488details about the structures returned. The returned structure should be freed
489after use using the relevant free function, BASIC_CONSTRAINTS_free() for
490example.
491
4923. Generating extensions.
493
494An extension will typically be generated from a configuration file, or some
495other kind of configuration database.
496
497int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
498 X509 *cert);
499int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
500 X509_CRL *crl);
501
502These functions add all the extensions in the given section to the given
503certificate or CRL. They will normally be called just before the certificate
504or CRL is due to be signed. Both return 0 on error on non zero for success.
505
506In each case 'conf' is the LHASH pointer of the configuration file to use
507and 'section' is the section containing the extension details.
508
509See the 'context functions' section for a description of the ctx parameter.
510
511
512X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
513 char *value);
514
515This function returns an extension based on a name and value pair, if the
516pair will not need to access other sections in a config file (or there is no
517config file) then the 'conf' parameter can be set to NULL.
518
519X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
520 char *value);
521
522This function creates an extension in the same way as X509V3_EXT_conf() but
523takes the NID of the extension rather than its name.
524
525For example to produce basicConstraints with the CA flag and a path length of
52610:
527
528x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10");
529
530
531X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
532
533This function sets up an extension from its internal structure. The ext_nid
534parameter is the NID of the extension and 'crit' is the critical flag.
535
5364. Context functions.
537
538The following functions set and manipulate an extension context structure.
539The purpose of the extension context is to allow the extension code to
540access various structures relating to the "environment" of the certificate:
541for example the issuers certificate or the certificate request.
542
543void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
544 X509_REQ *req, X509_CRL *crl, int flags);
545
546This function sets up an X509V3_CTX structure with details of the certificate
547environment: specifically the issuers certificate, the subject certificate,
548the certificate request and the CRL: if these are not relevant or not
549available then they can be set to NULL. The 'flags' parameter should be set
550to zero.
551
552X509V3_set_ctx_test(ctx)
553
554This macro is used to set the 'ctx' structure to a 'test' value: this is to
555allow the syntax of an extension (or configuration file) to be tested.
556
557X509V3_set_ctx_nodb(ctx)
558
559This macro is used when no configuration database is present.
560
561void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
562
563This function is used to set the configuration database when it is an LHASH
564structure: typically a configuration file.
565
566The following functions are used to access a configuration database: they
567should only be used in RAW extensions.
568
569char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
570
571This function returns the value of the parameter "name" in "section", or NULL
572if there has been an error.
573
574void X509V3_string_free(X509V3_CTX *ctx, char *str);
575
576This function frees up the string returned by the above function.
577
578STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
579
580This function returns a whole section as a STACK_OF(CONF_VALUE) .
581
582void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
583
584This function frees up the STACK returned by the above function.
585
586Note: it is possible to use the extension code with a custom configuration
587database. To do this the "db_meth" element of the X509V3_CTX structure should
588be set to an X509V3_CTX_METHOD structure. This structure contains the following
589function pointers:
590
591char * (*get_string)(void *db, char *section, char *value);
592STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
593void (*free_string)(void *db, char * string);
594void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
595
596these will be called and passed the 'db' element in the X509V3_CTX structure
597to access the database. If a given function is not implemented or not required
598it can be set to NULL.
599
6005. String helper functions.
601
602There are several "i2s" and "s2i" functions that convert structures to and
603from ASCII strings. In all the "i2s" cases the returned string should be
604freed using Free() after use. Since some of these are part of other extension
605code they may take a 'method' parameter. Unless otherwise stated it can be
606safely set to NULL.
607
608char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
609
610This returns a hex string from an ASN1_OCTET_STRING.
611
612char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
613char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
614
615These return a string decimal representations of an ASN1_INTEGER and an
616ASN1_ENUMERATED type, respectively.
617
618ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
619 X509V3_CTX *ctx, char *str);
620
621This converts an ASCII hex string to an ASN1_OCTET_STRING.
622
623ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
624
625This converts a decimal ASCII string into an ASN1_INTEGER.
626
6276. Multi valued extension helper functions.
628
629The following functions can be used to manipulate STACKs of CONF_VALUE
630structures, as used by multi valued extensions.
631
632int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
633
634This function expects a boolean value in 'value' and sets 'asn1_bool' to
635it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
636strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
637"false", "N", "n", "NO" or "no".
638
639int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
640
641This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
642
643int X509V3_add_value(const char *name, const char *value,
644 STACK_OF(CONF_VALUE) **extlist);
645
646This simply adds a string name and value pair.
647
648int X509V3_add_value_uchar(const char *name, const unsigned char *value,
649 STACK_OF(CONF_VALUE) **extlist);
650
651The same as above but for an unsigned character value.
652
653int X509V3_add_value_bool(const char *name, int asn1_bool,
654 STACK_OF(CONF_VALUE) **extlist);
655
656This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool'
657
658int X509V3_add_value_bool_nf(char *name, int asn1_bool,
659 STACK_OF(CONF_VALUE) **extlist);
660
661This is the same as above except it adds nothing if asn1_bool is FALSE.
662
663int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
664 STACK_OF(CONF_VALUE) **extlist);
665
666This function adds the value of the ASN1_INTEGER in decimal form.
667
6687. Other helper functions.
669
670<to be added>
671
672ADDING CUSTOM EXTENSIONS.
673
674Currently there are three types of supported extensions.
675
676String extensions are simple strings where the value is placed directly in the
677extensions, and the string returned is printed out.
678
679Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
680or return a STACK_OF(CONF_VALUE).
681
682Raw extensions are just passed a BIO or a value and it is the extensions
683responsibility to handle all the necessary printing.
684
685There are two ways to add an extension. One is simply as an alias to an already
686existing extension. An alias is an extension that is identical in ASN1 structure
687to an existing extension but has a different OBJECT IDENTIFIER. This can be
688done by calling:
689
690int X509V3_EXT_add_alias(int nid_to, int nid_from);
691
692'nid_to' is the new extension NID and 'nid_from' is the already existing
693extension NID.
694
695Alternatively an extension can be written from scratch. This involves writing
696the ASN1 code to encode and decode the extension and functions to print out and
697generate the extension from strings. The relevant functions are then placed in
698a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
699called.
700
701The X509V3_EXT_METHOD structure is described below.
702
703strut {
704int ext_nid;
705int ext_flags;
706X509V3_EXT_NEW ext_new;
707X509V3_EXT_FREE ext_free;
708X509V3_EXT_D2I d2i;
709X509V3_EXT_I2D i2d;
710X509V3_EXT_I2S i2s;
711X509V3_EXT_S2I s2i;
712X509V3_EXT_I2V i2v;
713X509V3_EXT_V2I v2i;
714X509V3_EXT_R2I r2i;
715X509V3_EXT_I2R i2r;
716
717void *usr_data;
718};
719
720The elements have the following meanings.
721
722ext_nid is the NID of the object identifier of the extension.
723
724ext_flags is set of flags. Currently the only external flag is
725 X509V3_EXT_MULTILINE which means a multi valued extensions
726 should be printed on separate lines.
727
728usr_data is an extension specific pointer to any relevant data. This
729 allows extensions to share identical code but have different
730 uses. An example of this is the bit string extension which uses
731 usr_data to contain a list of the bit names.
732
733All the remaining elements are function pointers.
734
735ext_new is a pointer to a function that allocates memory for the
736 extension ASN1 structure: for example ASN1_OBJECT_new().
737
738ext_free is a pointer to a function that free up memory of the extension
739 ASN1 structure: for example ASN1_OBJECT_free().
740
741d2i is the standard ASN1 function that converts a DER buffer into
742 the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
743
744i2d is the standard ASN1 function that converts the internal
745 structure into the DER representation: for example
746 i2d_ASN1_IA5STRING().
747
748The remaining functions are depend on the type of extension. One i2X and
749one X2i should be set and the rest set to NULL. The types set do not need
750to match up, for example the extension could be set using the multi valued
751v2i function and printed out using the raw i2r.
752
753All functions have the X509V3_EXT_METHOD passed to them in the 'method'
754parameter and an X509V3_CTX structure. Extension code can then access the
755parent structure via the 'method' parameter to for example make use of the value
756of usr_data. If the code needs to use detail relating to the request it can
757use the 'ctx' parameter.
758
759A note should be given here about the 'flags' member of the 'ctx' parameter.
760If it has the value CTX_TEST then the configuration syntax is being checked
761and no actual certificate or CRL exists. Therefore any attempt in the config
762file to access such information should silently succeed. If the syntax is OK
763then it should simply return a (possibly bogus) extension, otherwise it
764should return NULL.
765
766char *i2s(struct v3_ext_method *method, void *ext);
767
768This function takes the internal structure in the ext parameter and returns
769a Malloc'ed string representing its value.
770
771void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
772
773This function takes the string representation in the ext parameter and returns
774an allocated internal structure: ext_free() will be used on this internal
775structure after use.
776
777i2v and v2i handle a STACK_OF(CONF_VALUE):
778
779typedef struct
780{
781 char *section;
782 char *name;
783 char *value;
784} CONF_VALUE;
785
786Only the name and value members are currently used.
787
788STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
789
790This function is passed the internal structure in the ext parameter and
791returns a STACK of CONF_VALUE structures. The values of name, value,
792section and the structure itself will be freed up with Free after use.
793Several helper functions are available to add values to this STACK.
794
795void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
796 STACK_OF(CONF_VALUE) *values);
797
798This function takes a STACK_OF(CONF_VALUE) structures and should set the
799values of the external structure. This typically uses the name element to
800determine which structure element to set and the value element to determine
801what to set it to. Several helper functions are available for this
802purpose (see above).
803
804int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
805
806This function is passed the internal extension structure in the ext parameter
807and sends out a human readable version of the extension to out. The 'indent'
808parameter should be noted to determine the necessary amount of indentation
809needed on the output.
810
811void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
812
813This is just passed the string representation of the extension. It is intended
814to be used for more elaborate extensions where the standard single and multi
815valued options are insufficient. They can use the 'ctx' parameter to parse the
816configuration database themselves. See the context functions section for details
817of how to do this.
818
819Note: although this type takes the same parameters as the "r2s" function there
820is a subtle difference. Whereas an "r2i" function can access a configuration
821database an "s2i" function MUST NOT. This is so the internal code can safely
822assume that an "s2i" function will work without a configuration database.
823
824==============================================================================
825 PKCS#12 Library
826==============================================================================
827
828This section describes the internal PKCS#12 support. There are very few
829differences between the old external library and the new internal code at
830present. This may well change because the external library will not be updated
831much in future.
832
833This version now includes a couple of high level PKCS#12 functions which
834generally "do the right thing" and should make it much easier to handle PKCS#12
835structures.
836
837HIGH LEVEL FUNCTIONS.
838
839For most applications you only need concern yourself with the high level
840functions. They can parse and generate simple PKCS#12 files as produced by
841Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
842private key and certificate pair.
843
8441. Initialisation and cleanup.
845
846No special initialisation is needed for the internal PKCS#12 library: the
847standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
848add all algorithms (you should at least add SHA1 though) then you can manually
849initialise the PKCS#12 library with:
850
851PKCS12_PBE_add();
852
853The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
854called or it can be directly freed with:
855
856EVP_PBE_cleanup();
857
858after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
859be called.
860
8612. I/O functions.
862
863i2d_PKCS12_bio(bp, p12)
864
865This writes out a PKCS12 structure to a BIO.
866
867i2d_PKCS12_fp(fp, p12)
868
869This is the same but for a FILE pointer.
870
871d2i_PKCS12_bio(bp, p12)
872
873This reads in a PKCS12 structure from a BIO.
874
875d2i_PKCS12_fp(fp, p12)
876
877This is the same but for a FILE pointer.
878
8793. High level functions.
880
8813.1 Parsing with PKCS12_parse().
882
883int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
884 STACK **ca);
885
886This function takes a PKCS12 structure and a password (ASCII, null terminated)
887and returns the private key, the corresponding certificate and any CA
888certificates. If any of these is not required it can be passed as a NULL.
889The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
890structure. Typically to read in a PKCS#12 file you might do:
891
892p12 = d2i_PKCS12_fp(fp, NULL);
893PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */
894PKCS12_free(p12);
895
8963.2 PKCS#12 creation with PKCS12_create().
897
898PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
899 STACK *ca, int nid_key, int nid_cert, int iter,
900 int mac_iter, int keytype);
901
902This function will create a PKCS12 structure from a given password, name,
903private key, certificate and optional STACK of CA certificates. The remaining
9045 parameters can be set to 0 and sensible defaults will be used.
905
906The parameters nid_key and nid_cert are the key and certificate encryption
907algorithms, iter is the encryption iteration count, mac_iter is the MAC
908iteration count and keytype is the type of private key. If you really want
909to know what these last 5 parameters do then read the low level section.
910
911Typically to create a PKCS#12 file the following could be used:
912
913p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
914i2d_PKCS12_fp(fp, p12);
915PKCS12_free(p12);
916
9173.3 Changing a PKCS#12 structure password.
918
919int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
920
921This changes the password of an already existing PKCS#12 structure. oldpass
922is the old password and newpass is the new one. An error occurs if the old
923password is incorrect.
924
925LOW LEVEL FUNCTIONS.
926
927In some cases the high level functions do not provide the necessary
928functionality. For example if you want to generate or parse more complex
929PKCS#12 files. The sample pkcs12 application uses the low level functions
930to display details about the internal structure of a PKCS#12 file.
931
932Introduction.
933
934This is a brief description of how a PKCS#12 file is represented internally:
935some knowledge of PKCS#12 is assumed.
936
937A PKCS#12 object contains several levels.
938
939At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
940CRL, a private key, encrypted or unencrypted, a set of safebags (so the
941structure can be nested) or other secrets (not documented at present).
942A safebag can optionally have attributes, currently these are: a unicode
943friendlyName (a Unicode string) or a localKeyID (a string of bytes).
944
945At the next level is an authSafe which is a set of safebags collected into
946a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
947
948At the top level is the PKCS12 structure itself which contains a set of
949authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
950contains a MAC which is a kind of password protected digest to preserve
951integrity (so any unencrypted stuff below can't be tampered with).
952
953The reason for these levels is so various objects can be encrypted in various
954ways. For example you might want to encrypt a set of private keys with
955triple-DES and then include the related certificates either unencrypted or
956with lower encryption. Yes it's the dreaded crypto laws at work again which
957allow strong encryption on private keys and only weak encryption on other
958stuff.
959
960To build one of these things you turn all certificates and keys into safebags
961(with optional attributes). You collect the safebags into (one or more) STACKS
962and convert these into authsafes (encrypted or unencrypted). The authsafes
963are collected into a STACK and added to a PKCS12 structure. Finally a MAC
964inserted.
965
966Pulling one apart is basically the reverse process. The MAC is verified against
967the given password. The authsafes are extracted and each authsafe split into
968a set of safebags (possibly involving decryption). Finally the safebags are
969decomposed into the original keys and certificates and the attributes used to
970match up private key and certificate pairs.
971
972Anyway here are the functions that do the dirty work.
973
9741. Construction functions.
975
9761.1 Safebag functions.
977
978M_PKCS12_x5092certbag(x509)
979
980This macro takes an X509 structure and returns a certificate bag. The
981X509 structure can be freed up after calling this function.
982
983M_PKCS12_x509crl2certbag(crl)
984
985As above but for a CRL.
986
987PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
988
989Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
990Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
991structure contains a private key data in plain text form it should be free'd
992up as soon as it has been encrypted for security reasons (freeing up the
993structure zeros out the sensitive data). This can be done with
994PKCS8_PRIV_KEY_INFO_free().
995
996PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
997
998This sets the key type when a key is imported into MSIE or Outlook 98. Two
999values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
1000key that can also be used for signing but its size is limited in the export
1001versions of MS software to 512 bits, it is also the default. KEY_SIG is a
1002signing only key but the keysize is unlimited (well 16K is supposed to work).
1003If you are using the domestic version of MSIE then you can ignore this because
1004KEY_EX is not limited and can be used for both.
1005
1006PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
1007
1008Convert a PKCS8 private key structure into a keybag. This routine embeds the
1009p8 structure in the keybag so p8 should not be freed up or used after it is
1010called. The p8 structure will be freed up when the safebag is freed.
1011
1012PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
1013
1014Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
1015embedded and can be freed up after use.
1016
1017int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1018int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1019
1020Add a local key id or a friendlyname to a safebag.
1021
10221.2 Authsafe functions.
1023
1024PKCS7 *PKCS12_pack_p7data(STACK *sk)
1025Take a stack of safebags and convert them into an unencrypted authsafe. The
1026stack of safebags can be freed up after calling this function.
1027
1028PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
1029
1030As above but encrypted.
1031
10321.3 PKCS12 functions.
1033
1034PKCS12 *PKCS12_init(int mode)
1035
1036Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
1037
1038M_PKCS12_pack_authsafes(p12, safes)
1039
1040This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
1041
1042int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
1043
1044Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
1045that SHA-1 should be used.
1046
10472. Extraction Functions.
1048
10492.1 Safebags.
1050
1051M_PKCS12_bag_type(bag)
1052
1053Return the type of "bag". Returns one of the following
1054
1055NID_keyBag
1056NID_pkcs8ShroudedKeyBag 7
1057NID_certBag 8
1058NID_crlBag 9
1059NID_secretBag 10
1060NID_safeContentsBag 11
1061
1062M_PKCS12_cert_bag_type(bag)
1063
1064Returns type of certificate bag, following are understood.
1065
1066NID_x509Certificate 14
1067NID_sdsiCertificate 15
1068
1069M_PKCS12_crl_bag_type(bag)
1070
1071Returns crl bag type, currently only NID_crlBag is recognised.
1072
1073M_PKCS12_certbag2x509(bag)
1074
1075This macro extracts an X509 certificate from a certificate bag.
1076
1077M_PKCS12_certbag2x509crl(bag)
1078
1079As above but for a CRL.
1080
1081EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
1082
1083Extract a private key from a PKCS8 private key info structure.
1084
1085M_PKCS12_decrypt_skey(bag, pass, passlen)
1086
1087Decrypt a shrouded key bag and return a PKCS8 private key info structure.
1088Works with both RSA and DSA keys
1089
1090char *PKCS12_get_friendlyname(bag)
1091
1092Returns the friendlyName of a bag if present or NULL if none. The returned
1093string is a null terminated ASCII string allocated with Malloc(). It should
1094thus be freed up with Free() after use.
1095
10962.2 AuthSafe functions.
1097
1098M_PKCS12_unpack_p7data(p7)
1099
1100Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
1101
1102#define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
1103
1104As above but for an encrypted content info.
1105
11062.3 PKCS12 functions.
1107
1108M_PKCS12_unpack_authsafes(p12)
1109
1110Extract a STACK of authsafes from a PKCS12 structure.
1111
1112M_PKCS12_mac_present(p12)
1113
1114Check to see if a MAC is present.
1115
1116int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
1117
1118Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
1119
1120
1121Notes.
1122
11231. All the function return 0 or NULL on error.
11242. Encryption based functions take a common set of parameters. These are
1125described below.
1126
1127pass, passlen
1128ASCII password and length. The password on the MAC is called the "integrity
1129password" the encryption password is called the "privacy password" in the
1130PKCS#12 documentation. The passwords do not have to be the same. If -1 is
1131passed for the length it is worked out by the function itself (currently
1132this is sometimes done whatever is passed as the length but that may change).
1133
1134salt, saltlen
1135A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
1136default length is used.
1137
1138iter
1139Iteration count. This is a measure of how many times an internal function is
1140called to encrypt the data. The larger this value is the longer it takes, it
1141makes dictionary attacks on passwords harder. NOTE: Some implementations do
1142not support an iteration count on the MAC. If the password for the MAC and
1143encryption is the same then there is no point in having a high iteration
1144count for encryption if the MAC has no count. The MAC could be attacked
1145and the password used for the main decryption.
1146
1147pbe_nid
1148This is the NID of the password based encryption method used. The following are
1149supported.
1150NID_pbe_WithSHA1And128BitRC4
1151NID_pbe_WithSHA1And40BitRC4
1152NID_pbe_WithSHA1And3_Key_TripleDES_CBC
1153NID_pbe_WithSHA1And2_Key_TripleDES_CBC
1154NID_pbe_WithSHA1And128BitRC2_CBC
1155NID_pbe_WithSHA1And40BitRC2_CBC
1156
1157Which you use depends on the implementation you are exporting to. "Export
1158grade" (i.e. cryptographically challenged) products cannot support all
1159algorithms. Typically you may be able to use any encryption on shrouded key
1160bags but they must then be placed in an unencrypted authsafe. Other authsafes
1161may only support 40bit encryption. Of course if you are using SSLeay
1162throughout you can strongly encrypt everything and have high iteration counts
1163on everything.
1164
11653. For decryption routines only the password and length are needed.
1166
11674. Unlike the external version the nid's of objects are the values of the
1168constants: that is NID_certBag is the real nid, therefore there is no
1169PKCS12_obj_offset() function. Note the object constants are not the same as
1170those of the external version. If you use these constants then you will need
1171to recompile your code.
1172
11735. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or
1174macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
1175reused or freed up safely.
1176
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c
deleted file mode 100644
index aaedf6a9bb..0000000000
--- a/src/lib/libssl/s23_clnt.c
+++ /dev/null
@@ -1,473 +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#ifndef NO_SSL2
72 if (ver == SSL2_VERSION)
73 return(SSLv2_client_method());
74#endif
75 if (ver == SSL3_VERSION)
76 return(SSLv3_client_method());
77 else if (ver == TLS1_VERSION)
78 return(TLSv1_client_method());
79 else
80 return(NULL);
81 }
82
83SSL_METHOD *SSLv23_client_method(void)
84 {
85 static int init=1;
86 static SSL_METHOD SSLv23_client_data;
87
88 if (init)
89 {
90 memcpy((char *)&SSLv23_client_data,
91 (char *)sslv23_base_method(),sizeof(SSL_METHOD));
92 SSLv23_client_data.ssl_connect=ssl23_connect;
93 SSLv23_client_data.get_ssl_method=ssl23_get_client_method;
94 init=0;
95 }
96 return(&SSLv23_client_data);
97 }
98
99int ssl23_connect(SSL *s)
100 {
101 BUF_MEM *buf;
102 unsigned long Time=time(NULL);
103 void (*cb)()=NULL;
104 int ret= -1;
105 int new_state,state;
106
107 RAND_add(&Time,sizeof(Time),0);
108 ERR_clear_error();
109 clear_sys_error();
110
111 if (s->info_callback != NULL)
112 cb=s->info_callback;
113 else if (s->ctx->info_callback != NULL)
114 cb=s->ctx->info_callback;
115
116 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
117 s->in_handshake++;
118
119 for (;;)
120 {
121 state=s->state;
122
123 switch(s->state)
124 {
125 case SSL_ST_BEFORE:
126 case SSL_ST_CONNECT:
127 case SSL_ST_BEFORE|SSL_ST_CONNECT:
128 case SSL_ST_OK|SSL_ST_CONNECT:
129
130 if (s->session != NULL)
131 {
132 SSLerr(SSL_F_SSL23_CONNECT,SSL_R_SSL23_DOING_SESSION_ID_REUSE);
133 ret= -1;
134 goto end;
135 }
136 s->server=0;
137 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
138
139 /* s->version=TLS1_VERSION; */
140 s->type=SSL_ST_CONNECT;
141
142 if (s->init_buf == NULL)
143 {
144 if ((buf=BUF_MEM_new()) == NULL)
145 {
146 ret= -1;
147 goto end;
148 }
149 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
150 {
151 ret= -1;
152 goto end;
153 }
154 s->init_buf=buf;
155 }
156
157 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
158
159 ssl3_init_finished_mac(s);
160
161 s->state=SSL23_ST_CW_CLNT_HELLO_A;
162 s->ctx->stats.sess_connect++;
163 s->init_num=0;
164 break;
165
166 case SSL23_ST_CW_CLNT_HELLO_A:
167 case SSL23_ST_CW_CLNT_HELLO_B:
168
169 s->shutdown=0;
170 ret=ssl23_client_hello(s);
171 if (ret <= 0) goto end;
172 s->state=SSL23_ST_CR_SRVR_HELLO_A;
173 s->init_num=0;
174
175 break;
176
177 case SSL23_ST_CR_SRVR_HELLO_A:
178 case SSL23_ST_CR_SRVR_HELLO_B:
179 ret=ssl23_get_server_hello(s);
180 if (ret >= 0) cb=NULL;
181 goto end;
182 /* break; */
183
184 default:
185 SSLerr(SSL_F_SSL23_CONNECT,SSL_R_UNKNOWN_STATE);
186 ret= -1;
187 goto end;
188 /* break; */
189 }
190
191 if (s->debug) { (void)BIO_flush(s->wbio); }
192
193 if ((cb != NULL) && (s->state != state))
194 {
195 new_state=s->state;
196 s->state=state;
197 cb(s,SSL_CB_CONNECT_LOOP,1);
198 s->state=new_state;
199 }
200 }
201end:
202 s->in_handshake--;
203 if (cb != NULL)
204 cb(s,SSL_CB_CONNECT_EXIT,ret);
205 return(ret);
206 }
207
208
209static int ssl23_client_hello(SSL *s)
210 {
211 unsigned char *buf;
212 unsigned char *p,*d;
213 int i,ch_len;
214
215 buf=(unsigned char *)s->init_buf->data;
216 if (s->state == SSL23_ST_CW_CLNT_HELLO_A)
217 {
218#if 0
219 /* don't reuse session-id's */
220 if (!ssl_get_new_session(s,0))
221 {
222 return(-1);
223 }
224#endif
225
226 p=s->s3->client_random;
227 RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE);
228
229 /* Do the message type and length last */
230 d= &(buf[2]);
231 p=d+9;
232
233 *(d++)=SSL2_MT_CLIENT_HELLO;
234 if (!(s->options & SSL_OP_NO_TLSv1))
235 {
236 *(d++)=TLS1_VERSION_MAJOR;
237 *(d++)=TLS1_VERSION_MINOR;
238 s->client_version=TLS1_VERSION;
239 }
240 else if (!(s->options & SSL_OP_NO_SSLv3))
241 {
242 *(d++)=SSL3_VERSION_MAJOR;
243 *(d++)=SSL3_VERSION_MINOR;
244 s->client_version=SSL3_VERSION;
245 }
246 else if (!(s->options & SSL_OP_NO_SSLv2))
247 {
248 *(d++)=SSL2_VERSION_MAJOR;
249 *(d++)=SSL2_VERSION_MINOR;
250 s->client_version=SSL2_VERSION;
251 }
252 else
253 {
254 SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_PROTOCOLS_AVAILABLE);
255 return(-1);
256 }
257
258 /* Ciphers supported */
259 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),p);
260 if (i == 0)
261 {
262 /* no ciphers */
263 SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
264 return(-1);
265 }
266 s2n(i,d);
267 p+=i;
268
269 /* put in the session-id, zero since there is no
270 * reuse. */
271#if 0
272 s->session->session_id_length=0;
273#endif
274 s2n(0,d);
275
276 if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
277 ch_len=SSL2_CHALLENGE_LENGTH;
278 else
279 ch_len=SSL2_MAX_CHALLENGE_LENGTH;
280
281 /* write out sslv2 challenge */
282 if (SSL3_RANDOM_SIZE < ch_len)
283 i=SSL3_RANDOM_SIZE;
284 else
285 i=ch_len;
286 s2n(i,d);
287 memset(&(s->s3->client_random[0]),0,SSL3_RANDOM_SIZE);
288 RAND_pseudo_bytes(&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
289 memcpy(p,&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
290 p+=i;
291
292 i= p- &(buf[2]);
293 buf[0]=((i>>8)&0xff)|0x80;
294 buf[1]=(i&0xff);
295
296 s->state=SSL23_ST_CW_CLNT_HELLO_B;
297 /* number of bytes to write */
298 s->init_num=i+2;
299 s->init_off=0;
300
301 ssl3_finish_mac(s,&(buf[2]),i);
302 }
303
304 /* SSL3_ST_CW_CLNT_HELLO_B */
305 return(ssl23_write_bytes(s));
306 }
307
308static int ssl23_get_server_hello(SSL *s)
309 {
310 char buf[8];
311 unsigned char *p;
312 int i;
313 int n;
314
315 n=ssl23_read_bytes(s,7);
316
317 if (n != 7) return(n);
318 p=s->packet;
319
320 memcpy(buf,p,n);
321
322 if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) &&
323 (p[5] == 0x00) && (p[6] == 0x02))
324 {
325#ifdef NO_SSL2
326 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
327 goto err;
328#else
329 /* we are talking sslv2 */
330 /* we need to clean up the SSLv3 setup and put in the
331 * sslv2 stuff. */
332 int ch_len;
333
334 if (s->options & SSL_OP_NO_SSLv2)
335 {
336 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
337 goto err;
338 }
339 if (s->s2 == NULL)
340 {
341 if (!ssl2_new(s))
342 goto err;
343 }
344 else
345 ssl2_clear(s);
346
347 if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
348 ch_len=SSL2_CHALLENGE_LENGTH;
349 else
350 ch_len=SSL2_MAX_CHALLENGE_LENGTH;
351
352 /* write out sslv2 challenge */
353 i=(SSL3_RANDOM_SIZE < ch_len)
354 ?SSL3_RANDOM_SIZE:ch_len;
355 s->s2->challenge_length=i;
356 memcpy(s->s2->challenge,
357 &(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
358
359 if (s->s3 != NULL) ssl3_free(s);
360
361 if (!BUF_MEM_grow(s->init_buf,
362 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
363 {
364 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB);
365 goto err;
366 }
367
368 s->state=SSL2_ST_GET_SERVER_HELLO_A;
369 s->s2->ssl2_rollback=1;
370
371 /* setup the 5 bytes we have read so we get them from
372 * the sslv2 buffer */
373 s->rstate=SSL_ST_READ_HEADER;
374 s->packet_length=n;
375 s->packet= &(s->s2->rbuf[0]);
376 memcpy(s->packet,buf,n);
377 s->s2->rbuf_left=n;
378 s->s2->rbuf_offs=0;
379
380 /* we have already written one */
381 s->s2->write_sequence=1;
382
383 s->method=SSLv2_client_method();
384 s->handshake_func=s->method->ssl_connect;
385#endif
386 }
387 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
388 (p[1] == SSL3_VERSION_MAJOR) &&
389 ((p[2] == SSL3_VERSION_MINOR) ||
390 (p[2] == TLS1_VERSION_MINOR)) &&
391 (p[5] == SSL3_MT_SERVER_HELLO))
392 {
393 /* we have sslv3 or tls1 */
394
395 if (!ssl_init_wbio_buffer(s,1)) goto err;
396
397 /* we are in this state */
398 s->state=SSL3_ST_CR_SRVR_HELLO_A;
399
400 /* put the 5 bytes we have read into the input buffer
401 * for SSLv3 */
402 s->rstate=SSL_ST_READ_HEADER;
403 s->packet_length=n;
404 s->packet= &(s->s3->rbuf.buf[0]);
405 memcpy(s->packet,buf,n);
406 s->s3->rbuf.left=n;
407 s->s3->rbuf.offset=0;
408
409 if ((p[2] == SSL3_VERSION_MINOR) &&
410 !(s->options & SSL_OP_NO_SSLv3))
411 {
412 s->version=SSL3_VERSION;
413 s->method=SSLv3_client_method();
414 }
415 else if ((p[2] == TLS1_VERSION_MINOR) &&
416 !(s->options & SSL_OP_NO_TLSv1))
417 {
418 s->version=TLS1_VERSION;
419 s->method=TLSv1_client_method();
420 }
421 else
422 {
423 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
424 goto err;
425 }
426
427 s->handshake_func=s->method->ssl_connect;
428 }
429 else if ((p[0] == SSL3_RT_ALERT) &&
430 (p[1] == SSL3_VERSION_MAJOR) &&
431 ((p[2] == SSL3_VERSION_MINOR) ||
432 (p[2] == TLS1_VERSION_MINOR)) &&
433 (p[3] == 0) &&
434 (p[4] == 2))
435 {
436 void (*cb)()=NULL;
437 int j;
438
439 /* An alert */
440 if (s->info_callback != NULL)
441 cb=s->info_callback;
442 else if (s->ctx->info_callback != NULL)
443 cb=s->ctx->info_callback;
444
445 i=p[5];
446 if (cb != NULL)
447 {
448 j=(i<<8)|p[6];
449 cb(s,SSL_CB_READ_ALERT,j);
450 }
451
452 s->rwstate=SSL_NOTHING;
453 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_AD_REASON_OFFSET+p[6]);
454 goto err;
455 }
456 else
457 {
458 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL);
459 goto err;
460 }
461 s->init_num=0;
462
463 /* Since, if we are sending a ssl23 client hello, we are not
464 * reusing a session-id */
465 if (!ssl_get_new_session(s,0))
466 goto err;
467
468 s->first_packet=1;
469 return(SSL_connect(s));
470err:
471 return(-1);
472 }
473
diff --git a/src/lib/libssl/s23_lib.c b/src/lib/libssl/s23_lib.c
deleted file mode 100644
index dded7a19c5..0000000000
--- a/src/lib/libssl/s23_lib.c
+++ /dev/null
@@ -1,226 +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);
70const char *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 ssl_undefined_function,
96 ssl3_callback_ctrl,
97 ssl3_ctx_callback_ctrl,
98 };
99
100static long ssl23_default_timeout(void)
101 {
102 return(300);
103 }
104
105SSL_METHOD *sslv23_base_method(void)
106 {
107 return(&SSLv23_data);
108 }
109
110static int ssl23_num_ciphers(void)
111 {
112 return(ssl3_num_ciphers()
113#ifndef NO_SSL2
114 + ssl2_num_ciphers()
115#endif
116 );
117 }
118
119static SSL_CIPHER *ssl23_get_cipher(unsigned int u)
120 {
121 unsigned int uu=ssl3_num_ciphers();
122
123 if (u < uu)
124 return(ssl3_get_cipher(u));
125 else
126#ifndef NO_SSL2
127 return(ssl2_get_cipher(u-uu));
128#else
129 return(NULL);
130#endif
131 }
132
133/* This function needs to check if the ciphers required are actually
134 * available */
135static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
136 {
137 SSL_CIPHER c,*cp;
138 unsigned long id;
139 int n;
140
141 n=ssl3_num_ciphers();
142 id=0x03000000|((unsigned long)p[0]<<16L)|
143 ((unsigned long)p[1]<<8L)|(unsigned long)p[2];
144 c.id=id;
145 cp=ssl3_get_cipher_by_char(p);
146#ifndef NO_SSL2
147 if (cp == NULL)
148 cp=ssl2_get_cipher_by_char(p);
149#endif
150 return(cp);
151 }
152
153static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
154 {
155 long l;
156
157 /* We can write SSLv2 and SSLv3 ciphers */
158 if (p != NULL)
159 {
160 l=c->id;
161 p[0]=((unsigned char)(l>>16L))&0xFF;
162 p[1]=((unsigned char)(l>> 8L))&0xFF;
163 p[2]=((unsigned char)(l ))&0xFF;
164 }
165 return(3);
166 }
167
168static int ssl23_read(SSL *s, void *buf, int len)
169 {
170 int n;
171
172#if 0
173 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
174 {
175 s->rwstate=SSL_NOTHING;
176 return(0);
177 }
178#endif
179 clear_sys_error();
180 if (SSL_in_init(s) && (!s->in_handshake))
181 {
182 n=s->handshake_func(s);
183 if (n < 0) return(n);
184 if (n == 0)
185 {
186 SSLerr(SSL_F_SSL23_READ,SSL_R_SSL_HANDSHAKE_FAILURE);
187 return(-1);
188 }
189 return(SSL_read(s,buf,len));
190 }
191 else
192 {
193 ssl_undefined_function(s);
194 return(-1);
195 }
196 }
197
198static int ssl23_write(SSL *s, const void *buf, int len)
199 {
200 int n;
201
202#if 0
203 if (s->shutdown & SSL_SENT_SHUTDOWN)
204 {
205 s->rwstate=SSL_NOTHING;
206 return(0);
207 }
208#endif
209 clear_sys_error();
210 if (SSL_in_init(s) && (!s->in_handshake))
211 {
212 n=s->handshake_func(s);
213 if (n < 0) return(n);
214 if (n == 0)
215 {
216 SSLerr(SSL_F_SSL23_WRITE,SSL_R_SSL_HANDSHAKE_FAILURE);
217 return(-1);
218 }
219 return(SSL_write(s,buf,len));
220 }
221 else
222 {
223 ssl_undefined_function(s);
224 return(-1);
225 }
226 }
diff --git a/src/lib/libssl/s23_pkt.c b/src/lib/libssl/s23_pkt.c
deleted file mode 100644
index f45e1ce3d8..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/* return regularly only when we have read (at least) '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 6a3bbb10b9..0000000000
--- a/src/lib/libssl/s23_srvr.c
+++ /dev/null
@@ -1,568 +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#ifndef NO_SSL2
71 if (ver == SSL2_VERSION)
72 return(SSLv2_server_method());
73#endif
74 if (ver == SSL3_VERSION)
75 return(SSLv3_server_method());
76 else if (ver == TLS1_VERSION)
77 return(TLSv1_server_method());
78 else
79 return(NULL);
80 }
81
82SSL_METHOD *SSLv23_server_method(void)
83 {
84 static int init=1;
85 static SSL_METHOD SSLv23_server_data;
86
87 if (init)
88 {
89 memcpy((char *)&SSLv23_server_data,
90 (char *)sslv23_base_method(),sizeof(SSL_METHOD));
91 SSLv23_server_data.ssl_accept=ssl23_accept;
92 SSLv23_server_data.get_ssl_method=ssl23_get_server_method;
93 init=0;
94 }
95 return(&SSLv23_server_data);
96 }
97
98int ssl23_accept(SSL *s)
99 {
100 BUF_MEM *buf;
101 unsigned long Time=time(NULL);
102 void (*cb)()=NULL;
103 int ret= -1;
104 int new_state,state;
105
106 RAND_add(&Time,sizeof(Time),0);
107 ERR_clear_error();
108 clear_sys_error();
109
110 if (s->info_callback != NULL)
111 cb=s->info_callback;
112 else if (s->ctx->info_callback != NULL)
113 cb=s->ctx->info_callback;
114
115 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
116 s->in_handshake++;
117
118 for (;;)
119 {
120 state=s->state;
121
122 switch(s->state)
123 {
124 case SSL_ST_BEFORE:
125 case SSL_ST_ACCEPT:
126 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
127 case SSL_ST_OK|SSL_ST_ACCEPT:
128
129 s->server=1;
130 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
131
132 /* s->version=SSL3_VERSION; */
133 s->type=SSL_ST_ACCEPT;
134
135 if (s->init_buf == NULL)
136 {
137 if ((buf=BUF_MEM_new()) == NULL)
138 {
139 ret= -1;
140 goto end;
141 }
142 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
143 {
144 ret= -1;
145 goto end;
146 }
147 s->init_buf=buf;
148 }
149
150 ssl3_init_finished_mac(s);
151
152 s->state=SSL23_ST_SR_CLNT_HELLO_A;
153 s->ctx->stats.sess_accept++;
154 s->init_num=0;
155 break;
156
157 case SSL23_ST_SR_CLNT_HELLO_A:
158 case SSL23_ST_SR_CLNT_HELLO_B:
159
160 s->shutdown=0;
161 ret=ssl23_get_client_hello(s);
162 if (ret >= 0) cb=NULL;
163 goto end;
164 /* break; */
165
166 default:
167 SSLerr(SSL_F_SSL23_ACCEPT,SSL_R_UNKNOWN_STATE);
168 ret= -1;
169 goto end;
170 /* break; */
171 }
172
173 if ((cb != NULL) && (s->state != state))
174 {
175 new_state=s->state;
176 s->state=state;
177 cb(s,SSL_CB_ACCEPT_LOOP,1);
178 s->state=new_state;
179 }
180 }
181end:
182 if (cb != NULL)
183 cb(s,SSL_CB_ACCEPT_EXIT,ret);
184 s->in_handshake--;
185 return(ret);
186 }
187
188
189int ssl23_get_client_hello(SSL *s)
190 {
191 char buf_space[11]; /* Request this many bytes in initial read.
192 * We can detect SSL 3.0/TLS 1.0 Client Hellos
193 * ('type == 3') correctly only when the following
194 * is in a single record, which is not guaranteed by
195 * the protocol specification:
196 * Byte Content
197 * 0 type \
198 * 1/2 version > record header
199 * 3/4 length /
200 * 5 msg_type \
201 * 6-8 length > Client Hello message
202 * 9/10 client_version /
203 */
204 char *buf= &(buf_space[0]);
205 unsigned char *p,*d,*dd;
206 unsigned int i;
207 unsigned int csl,sil,cl;
208 int n=0,j;
209 int type=0;
210 int v[2];
211#ifndef NO_RSA
212 int use_sslv2_strong=0;
213#endif
214
215 if (s->state == SSL23_ST_SR_CLNT_HELLO_A)
216 {
217 /* read the initial header */
218 v[0]=v[1]=0;
219
220 if (!ssl3_setup_buffers(s)) goto err;
221
222 n=ssl23_read_bytes(s, sizeof buf_space);
223 if (n != sizeof buf_space) return(n); /* n == -1 || n == 0 */
224
225 p=s->packet;
226
227 memcpy(buf,p,n);
228
229 if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO))
230 {
231 /*
232 * SSLv2 header
233 */
234 if ((p[3] == 0x00) && (p[4] == 0x02))
235 {
236 v[0]=p[3]; v[1]=p[4];
237 /* SSLv2 */
238 if (!(s->options & SSL_OP_NO_SSLv2))
239 type=1;
240 }
241 else if (p[3] == SSL3_VERSION_MAJOR)
242 {
243 v[0]=p[3]; v[1]=p[4];
244 /* SSLv3/TLSv1 */
245 if (p[4] >= TLS1_VERSION_MINOR)
246 {
247 if (!(s->options & SSL_OP_NO_TLSv1))
248 {
249 s->version=TLS1_VERSION;
250 /* type=2; */ /* done later to survive restarts */
251 s->state=SSL23_ST_SR_CLNT_HELLO_B;
252 }
253 else if (!(s->options & SSL_OP_NO_SSLv3))
254 {
255 s->version=SSL3_VERSION;
256 /* type=2; */
257 s->state=SSL23_ST_SR_CLNT_HELLO_B;
258 }
259 else if (!(s->options & SSL_OP_NO_SSLv2))
260 {
261 type=1;
262 }
263 }
264 else if (!(s->options & SSL_OP_NO_SSLv3))
265 {
266 s->version=SSL3_VERSION;
267 /* type=2; */
268 s->state=SSL23_ST_SR_CLNT_HELLO_B;
269 }
270 else if (!(s->options & SSL_OP_NO_SSLv2))
271 type=1;
272
273 if (s->options & SSL_OP_NON_EXPORT_FIRST)
274 /* Not only utterly confusing, but broken
275 * ('fractured programming'?) -- the details
276 * of this block nearly make it work
277 * as intended in this environment, but on one
278 * of the fine points (w.r.t. restarts) it fails.
279 * The obvious fix would be even more devastating
280 * to program structure; if you want the functionality,
281 * throw this away and implement it in a way
282 * that makes sense */
283 {
284#if 0
285 STACK_OF(SSL_CIPHER) *sk;
286 SSL_CIPHER *c;
287 int ne2,ne3;
288
289 j=((p[0]&0x7f)<<8)|p[1];
290 if (j > (1024*4))
291 {
292 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
293 goto err;
294 }
295
296 n=ssl23_read_bytes(s,j+2);
297 if (n <= 0) return(n);
298 p=s->packet;
299
300 if ((buf=Malloc(n)) == NULL)
301 {
302 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE);
303 goto err;
304 }
305 memcpy(buf,p,n);
306
307 p+=5;
308 n2s(p,csl);
309 p+=4;
310
311 sk=ssl_bytes_to_cipher_list(
312 s,p,csl,NULL);
313 if (sk != NULL)
314 {
315 ne2=ne3=0;
316 for (j=0; j<sk_SSL_CIPHER_num(sk); j++)
317 {
318 c=sk_SSL_CIPHER_value(sk,j);
319 if (!SSL_C_IS_EXPORT(c))
320 {
321 if ((c->id>>24L) == 2L)
322 ne2=1;
323 else
324 ne3=1;
325 }
326 }
327 if (ne2 && !ne3)
328 {
329 type=1;
330 use_sslv2_strong=1;
331 goto next_bit;
332 }
333 }
334#else
335 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_OPTION);
336 goto err;
337#endif
338 }
339 }
340 }
341 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
342 (p[1] == SSL3_VERSION_MAJOR) &&
343 (p[5] == SSL3_MT_CLIENT_HELLO) &&
344 ((p[3] == 0 && p[4] < 5 /* silly record length? */)
345 || (p[9] == p[1])))
346 {
347 /*
348 * SSLv3 or tls1 header
349 */
350
351 v[0]=p[1]; /* major version */
352 /* We must look at client_version inside the Client Hello message
353 * to get the correct minor version: */
354 v[1]=p[10];
355 /* However if we have only a pathologically small fragment of the
356 * Client Hello message, we simply use the version from the
357 * record header -- this is incorrect but unlikely to fail in
358 * practice */
359 if (p[3] == 0 && p[4] < 6)
360 v[1]=p[2];
361 if (v[1] >= TLS1_VERSION_MINOR)
362 {
363 if (!(s->options & SSL_OP_NO_TLSv1))
364 {
365 s->version=TLS1_VERSION;
366 type=3;
367 }
368 else if (!(s->options & SSL_OP_NO_SSLv3))
369 {
370 s->version=SSL3_VERSION;
371 type=3;
372 }
373 }
374 else if (!(s->options & SSL_OP_NO_SSLv3))
375 {
376 s->version=SSL3_VERSION;
377 type=3;
378 }
379 }
380 else if ((strncmp("GET ", (char *)p,4) == 0) ||
381 (strncmp("POST ",(char *)p,5) == 0) ||
382 (strncmp("HEAD ",(char *)p,5) == 0) ||
383 (strncmp("PUT ", (char *)p,4) == 0))
384 {
385 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST);
386 goto err;
387 }
388 else if (strncmp("CONNECT",(char *)p,7) == 0)
389 {
390 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST);
391 goto err;
392 }
393 }
394
395 if (s->state == SSL23_ST_SR_CLNT_HELLO_B)
396 {
397 /* we have SSLv3/TLSv1 in an SSLv2 header
398 * (other cases skip this state) */
399
400 type=2;
401 p=s->packet;
402 v[0] = p[3]; /* == SSL3_VERSION_MAJOR */
403 v[1] = p[4];
404
405 n=((p[0]&0x7f)<<8)|p[1];
406 if (n > (1024*4))
407 {
408 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
409 goto err;
410 }
411
412 j=ssl23_read_bytes(s,n+2);
413 if (j <= 0) return(j);
414
415 ssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2);
416
417 p=s->packet;
418 p+=5;
419 n2s(p,csl);
420 n2s(p,sil);
421 n2s(p,cl);
422 d=(unsigned char *)s->init_buf->data;
423 if ((csl+sil+cl+11) != s->packet_length)
424 {
425 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH);
426 goto err;
427 }
428
429 *(d++) = SSL3_VERSION_MAJOR; /* == v[0] */
430 *(d++) = v[1];
431
432 /* lets populate the random area */
433 /* get the challenge_length */
434 i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl;
435 memset(d,0,SSL3_RANDOM_SIZE);
436 memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i);
437 d+=SSL3_RANDOM_SIZE;
438
439 /* no session-id reuse */
440 *(d++)=0;
441
442 /* ciphers */
443 j=0;
444 dd=d;
445 d+=2;
446 for (i=0; i<csl; i+=3)
447 {
448 if (p[i] != 0) continue;
449 *(d++)=p[i+1];
450 *(d++)=p[i+2];
451 j+=2;
452 }
453 s2n(j,dd);
454
455 /* COMPRESSION */
456 *(d++)=1;
457 *(d++)=0;
458
459 i=(d-(unsigned char *)s->init_buf->data);
460
461 /* get the data reused from the init_buf */
462 s->s3->tmp.reuse_message=1;
463 s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO;
464 s->s3->tmp.message_size=i;
465 }
466
467 /* imaginary new state (for program structure): */
468 /* s->state = SSL23_SR_CLNT_HELLO_C */
469
470 if (type == 1)
471 {
472#ifdef NO_SSL2
473 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
474 goto err;
475#else
476 /* we are talking sslv2 */
477 /* we need to clean up the SSLv3/TLSv1 setup and put in the
478 * sslv2 stuff. */
479
480 if (s->s2 == NULL)
481 {
482 if (!ssl2_new(s))
483 goto err;
484 }
485 else
486 ssl2_clear(s);
487
488 if (s->s3 != NULL) ssl3_free(s);
489
490 if (!BUF_MEM_grow(s->init_buf,
491 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
492 {
493 goto err;
494 }
495
496 s->state=SSL2_ST_GET_CLIENT_HELLO_A;
497 if ((s->options & SSL_OP_MSIE_SSLV2_RSA_PADDING) ||
498 use_sslv2_strong)
499 s->s2->ssl2_rollback=0;
500 else
501 s->s2->ssl2_rollback=1;
502
503 /* setup the n bytes we have read so we get them from
504 * the sslv2 buffer */
505 s->rstate=SSL_ST_READ_HEADER;
506 s->packet_length=n;
507 s->packet= &(s->s2->rbuf[0]);
508 memcpy(s->packet,buf,n);
509 s->s2->rbuf_left=n;
510 s->s2->rbuf_offs=0;
511
512 s->method=SSLv2_server_method();
513 s->handshake_func=s->method->ssl_accept;
514#endif
515 }
516
517 if ((type == 2) || (type == 3))
518 {
519 /* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */
520
521 if (!ssl_init_wbio_buffer(s,1)) goto err;
522
523 /* we are in this state */
524 s->state=SSL3_ST_SR_CLNT_HELLO_A;
525
526 if (type == 3)
527 {
528 /* put the 'n' bytes we have read into the input buffer
529 * for SSLv3 */
530 s->rstate=SSL_ST_READ_HEADER;
531 s->packet_length=n;
532 s->packet= &(s->s3->rbuf.buf[0]);
533 memcpy(s->packet,buf,n);
534 s->s3->rbuf.left=n;
535 s->s3->rbuf.offset=0;
536 }
537 else
538 {
539 s->packet_length=0;
540 s->s3->rbuf.left=0;
541 s->s3->rbuf.offset=0;
542 }
543
544 if (s->version == TLS1_VERSION)
545 s->method = TLSv1_server_method();
546 else
547 s->method = SSLv3_server_method();
548#if 0 /* ssl3_get_client_hello does this */
549 s->client_version=(v[0]<<8)|v[1];
550#endif
551 s->handshake_func=s->method->ssl_accept;
552 }
553
554 if ((type < 1) || (type > 3))
555 {
556 /* bad, very bad */
557 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL);
558 goto err;
559 }
560 s->init_num=0;
561
562 if (buf != buf_space) Free(buf);
563 s->first_packet=1;
564 return(SSL_accept(s));
565err:
566 if (buf != buf_space) Free(buf);
567 return(-1);
568 }
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c
deleted file mode 100644
index 03e0c38770..0000000000
--- a/src/lib/libssl/s3_both.c
+++ /dev/null
@@ -1,588 +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 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <string.h>
113#include <stdio.h>
114#include <openssl/buffer.h>
115#include <openssl/rand.h>
116#include <openssl/objects.h>
117#include <openssl/evp.h>
118#include <openssl/x509.h>
119#include "ssl_locl.h"
120
121/* send s->init_buf in records of type 'type' */
122int ssl3_do_write(SSL *s, int type)
123 {
124 int ret;
125
126 ret=ssl3_write_bytes(s,type,&s->init_buf->data[s->init_off],
127 s->init_num);
128 if (ret < 0) return(-1);
129 if (type == SSL3_RT_HANDSHAKE)
130 /* should not be done for 'Hello Request's, but in that case
131 * we'll ignore the result anyway */
132 ssl3_finish_mac(s,(unsigned char *)&s->init_buf->data[s->init_off],ret);
133
134 if (ret == s->init_num)
135 return(1);
136 s->init_off+=ret;
137 s->init_num-=ret;
138 return(0);
139 }
140
141int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen)
142 {
143 unsigned char *p,*d;
144 int i;
145 unsigned long l;
146
147 if (s->state == a)
148 {
149 d=(unsigned char *)s->init_buf->data;
150 p= &(d[4]);
151
152 i=s->method->ssl3_enc->final_finish_mac(s,
153 &(s->s3->finish_dgst1),
154 &(s->s3->finish_dgst2),
155 sender,slen,s->s3->tmp.finish_md);
156 s->s3->tmp.finish_md_len = i;
157 memcpy(p, s->s3->tmp.finish_md, i);
158 p+=i;
159 l=i;
160
161#ifdef WIN16
162 /* MSVC 1.5 does not clear the top bytes of the word unless
163 * I do this.
164 */
165 l&=0xffff;
166#endif
167
168 *(d++)=SSL3_MT_FINISHED;
169 l2n3(l,d);
170 s->init_num=(int)l+4;
171 s->init_off=0;
172
173 s->state=b;
174 }
175
176 /* SSL3_ST_SEND_xxxxxx_HELLO_B */
177 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
178 }
179
180int ssl3_get_finished(SSL *s, int a, int b)
181 {
182 int al,i,ok;
183 long n;
184 unsigned char *p;
185
186 /* the mac has already been generated when we received the
187 * change cipher spec message and is in s->s3->tmp.peer_finish_md
188 */
189
190 n=ssl3_get_message(s,
191 a,
192 b,
193 SSL3_MT_FINISHED,
194 64, /* should actually be 36+4 :-) */
195 &ok);
196
197 if (!ok) return((int)n);
198
199 /* If this occurs, we have missed a message */
200 if (!s->s3->change_cipher_spec)
201 {
202 al=SSL_AD_UNEXPECTED_MESSAGE;
203 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS);
204 goto f_err;
205 }
206 s->s3->change_cipher_spec=0;
207
208 p = (unsigned char *)s->init_buf->data;
209 i = s->s3->tmp.peer_finish_md_len;
210
211 if (i != n)
212 {
213 al=SSL_AD_DECODE_ERROR;
214 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH);
215 goto f_err;
216 }
217
218 if (memcmp(p, s->s3->tmp.peer_finish_md, i) != 0)
219 {
220 al=SSL_AD_DECRYPT_ERROR;
221 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED);
222 goto f_err;
223 }
224
225 return(1);
226f_err:
227 ssl3_send_alert(s,SSL3_AL_FATAL,al);
228 return(0);
229 }
230
231/* for these 2 messages, we need to
232 * ssl->enc_read_ctx re-init
233 * ssl->s3->read_sequence zero
234 * ssl->s3->read_mac_secret re-init
235 * ssl->session->read_sym_enc assign
236 * ssl->session->read_compression assign
237 * ssl->session->read_hash assign
238 */
239int ssl3_send_change_cipher_spec(SSL *s, int a, int b)
240 {
241 unsigned char *p;
242
243 if (s->state == a)
244 {
245 p=(unsigned char *)s->init_buf->data;
246 *p=SSL3_MT_CCS;
247 s->init_num=1;
248 s->init_off=0;
249
250 s->state=b;
251 }
252
253 /* SSL3_ST_CW_CHANGE_B */
254 return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC));
255 }
256
257unsigned long ssl3_output_cert_chain(SSL *s, X509 *x)
258 {
259 unsigned char *p;
260 int n,i;
261 unsigned long l=7;
262 BUF_MEM *buf;
263 X509_STORE_CTX xs_ctx;
264 X509_OBJECT obj;
265
266 /* TLSv1 sends a chain with nothing in it, instead of an alert */
267 buf=s->init_buf;
268 if (!BUF_MEM_grow(buf,(int)(10)))
269 {
270 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
271 return(0);
272 }
273 if (x != NULL)
274 {
275 X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL);
276
277 for (;;)
278 {
279 n=i2d_X509(x,NULL);
280 if (!BUF_MEM_grow(buf,(int)(n+l+3)))
281 {
282 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
283 return(0);
284 }
285 p=(unsigned char *)&(buf->data[l]);
286 l2n3(n,p);
287 i2d_X509(x,&p);
288 l+=n+3;
289 if (X509_NAME_cmp(X509_get_subject_name(x),
290 X509_get_issuer_name(x)) == 0) break;
291
292 i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509,
293 X509_get_issuer_name(x),&obj);
294 if (i <= 0) break;
295 x=obj.data.x509;
296 /* Count is one too high since the X509_STORE_get uped the
297 * ref count */
298 X509_free(x);
299 }
300
301 X509_STORE_CTX_cleanup(&xs_ctx);
302 }
303
304 /* Thawte special :-) */
305 if (s->ctx->extra_certs != NULL)
306 for (i=0; i<sk_X509_num(s->ctx->extra_certs); i++)
307 {
308 x=sk_X509_value(s->ctx->extra_certs,i);
309 n=i2d_X509(x,NULL);
310 if (!BUF_MEM_grow(buf,(int)(n+l+3)))
311 {
312 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
313 return(0);
314 }
315 p=(unsigned char *)&(buf->data[l]);
316 l2n3(n,p);
317 i2d_X509(x,&p);
318 l+=n+3;
319 }
320
321 l-=7;
322 p=(unsigned char *)&(buf->data[4]);
323 l2n3(l,p);
324 l+=3;
325 p=(unsigned char *)&(buf->data[0]);
326 *(p++)=SSL3_MT_CERTIFICATE;
327 l2n3(l,p);
328 l+=4;
329 return(l);
330 }
331
332/* Obtain handshake message of message type 'mt' (any if mt == -1),
333 * maximum acceptable body length 'max'.
334 * The first four bytes (msg_type and length) are read in state 'st1',
335 * the body is read in state 'stn'.
336 */
337long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
338 {
339 unsigned char *p;
340 unsigned long l;
341 long n;
342 int i,al;
343
344 if (s->s3->tmp.reuse_message)
345 {
346 s->s3->tmp.reuse_message=0;
347 if ((mt >= 0) && (s->s3->tmp.message_type != mt))
348 {
349 al=SSL_AD_UNEXPECTED_MESSAGE;
350 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
351 goto f_err;
352 }
353 *ok=1;
354 return((int)s->s3->tmp.message_size);
355 }
356
357 p=(unsigned char *)s->init_buf->data;
358
359 if (s->state == st1) /* s->init_num < 4 */
360 {
361 int skip_message;
362
363 do
364 {
365 while (s->init_num < 4)
366 {
367 i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],
368 4 - s->init_num);
369 if (i <= 0)
370 {
371 s->rwstate=SSL_READING;
372 *ok = 0;
373 return i;
374 }
375 s->init_num+=i;
376 }
377
378 skip_message = 0;
379 if (!s->server)
380 if (p[0] == SSL3_MT_HELLO_REQUEST)
381 /* The server may always send 'Hello Request' messages --
382 * we are doing a handshake anyway now, so ignore them
383 * if their format is correct. Does not count for
384 * 'Finished' MAC. */
385 if (p[1] == 0 && p[2] == 0 &&p[3] == 0)
386 skip_message = 1;
387 }
388 while (skip_message);
389
390 /* s->init_num == 4 */
391
392 if ((mt >= 0) && (*p != mt))
393 {
394 al=SSL_AD_UNEXPECTED_MESSAGE;
395 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
396 goto f_err;
397 }
398 if ((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&
399 (st1 == SSL3_ST_SR_CERT_A) &&
400 (stn == SSL3_ST_SR_CERT_B))
401 {
402 /* At this point we have got an MS SGC second client
403 * hello (maybe we should always allow the client to
404 * start a new handshake?). We need to restart the mac.
405 * Don't increment {num,total}_renegotiations because
406 * we have not completed the handshake. */
407 ssl3_init_finished_mac(s);
408 }
409
410 ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, 4);
411
412 s->s3->tmp.message_type= *(p++);
413
414 n2l3(p,l);
415 if (l > (unsigned long)max)
416 {
417 al=SSL_AD_ILLEGAL_PARAMETER;
418 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);
419 goto f_err;
420 }
421 if (l && !BUF_MEM_grow(s->init_buf,(int)l))
422 {
423 SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);
424 goto err;
425 }
426 s->s3->tmp.message_size=l;
427 s->state=stn;
428
429 s->init_num=0;
430 }
431
432 /* next state (stn) */
433 p=(unsigned char *)s->init_buf->data;
434 n=s->s3->tmp.message_size;
435 while (n > 0)
436 {
437 i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n);
438 if (i <= 0)
439 {
440 s->rwstate=SSL_READING;
441 *ok = 0;
442 return i;
443 }
444 s->init_num += i;
445 n -= i;
446 }
447 ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num);
448 *ok=1;
449 return s->init_num;
450f_err:
451 ssl3_send_alert(s,SSL3_AL_FATAL,al);
452err:
453 *ok=0;
454 return(-1);
455 }
456
457int ssl_cert_type(X509 *x, EVP_PKEY *pkey)
458 {
459 EVP_PKEY *pk;
460 int ret= -1,i,j;
461
462 if (pkey == NULL)
463 pk=X509_get_pubkey(x);
464 else
465 pk=pkey;
466 if (pk == NULL) goto err;
467
468 i=pk->type;
469 if (i == EVP_PKEY_RSA)
470 {
471 ret=SSL_PKEY_RSA_ENC;
472 if (x != NULL)
473 {
474 j=X509_get_ext_count(x);
475 /* check to see if this is a signing only certificate */
476 /* EAY EAY EAY EAY */
477 }
478 }
479 else if (i == EVP_PKEY_DSA)
480 {
481 ret=SSL_PKEY_DSA_SIGN;
482 }
483 else if (i == EVP_PKEY_DH)
484 {
485 /* if we just have a key, we needs to be guess */
486
487 if (x == NULL)
488 ret=SSL_PKEY_DH_DSA;
489 else
490 {
491 j=X509_get_signature_type(x);
492 if (j == EVP_PKEY_RSA)
493 ret=SSL_PKEY_DH_RSA;
494 else if (j== EVP_PKEY_DSA)
495 ret=SSL_PKEY_DH_DSA;
496 else ret= -1;
497 }
498 }
499 else
500 ret= -1;
501
502err:
503 if(!pkey) EVP_PKEY_free(pk);
504 return(ret);
505 }
506
507int ssl_verify_alarm_type(long type)
508 {
509 int al;
510
511 switch(type)
512 {
513 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
514 case X509_V_ERR_UNABLE_TO_GET_CRL:
515 al=SSL_AD_UNKNOWN_CA;
516 break;
517 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
518 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
519 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
520 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
521 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
522 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
523 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
524 case X509_V_ERR_CERT_NOT_YET_VALID:
525 case X509_V_ERR_CRL_NOT_YET_VALID:
526 al=SSL_AD_BAD_CERTIFICATE;
527 break;
528 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
529 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
530 al=SSL_AD_DECRYPT_ERROR;
531 break;
532 case X509_V_ERR_CERT_HAS_EXPIRED:
533 case X509_V_ERR_CRL_HAS_EXPIRED:
534 al=SSL_AD_CERTIFICATE_EXPIRED;
535 break;
536 case X509_V_ERR_CERT_REVOKED:
537 al=SSL_AD_CERTIFICATE_REVOKED;
538 break;
539 case X509_V_ERR_OUT_OF_MEM:
540 al=SSL_AD_INTERNAL_ERROR;
541 break;
542 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
543 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
544 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
545 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
546 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
547 al=SSL_AD_UNKNOWN_CA;
548 break;
549 case X509_V_ERR_APPLICATION_VERIFICATION:
550 al=SSL_AD_HANDSHAKE_FAILURE;
551 break;
552 default:
553 al=SSL_AD_CERTIFICATE_UNKNOWN;
554 break;
555 }
556 return(al);
557 }
558
559int ssl3_setup_buffers(SSL *s)
560 {
561 unsigned char *p;
562 unsigned int extra;
563
564 if (s->s3->rbuf.buf == NULL)
565 {
566 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
567 extra=SSL3_RT_MAX_EXTRA;
568 else
569 extra=0;
570 if ((p=Malloc(SSL3_RT_MAX_PACKET_SIZE+extra))
571 == NULL)
572 goto err;
573 s->s3->rbuf.buf=p;
574 }
575
576 if (s->s3->wbuf.buf == NULL)
577 {
578 if ((p=Malloc(SSL3_RT_MAX_PACKET_SIZE))
579 == NULL)
580 goto err;
581 s->s3->wbuf.buf=p;
582 }
583 s->packet= &(s->s3->rbuf.buf[0]);
584 return(1);
585err:
586 SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE);
587 return(0);
588 }
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c
deleted file mode 100644
index 0c8f551f73..0000000000
--- a/src/lib/libssl/s3_clnt.c
+++ /dev/null
@@ -1,1730 +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_add(&Time,sizeof(Time),0);
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_label,
329 s->method->ssl3_enc->client_finished_label_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_pseudo_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 /* Inconsistency alert: cert_chain does include the peer's
776 * certificate, which we don't include in s3_srvr.c */
777 x=sk_X509_value(sk,0);
778 sk=NULL;
779
780 pkey=X509_get_pubkey(x);
781
782 if ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey))
783 {
784 x=NULL;
785 al=SSL3_AL_FATAL;
786 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS);
787 goto f_err;
788 }
789
790 i=ssl_cert_type(x,pkey);
791 if (i < 0)
792 {
793 x=NULL;
794 al=SSL3_AL_FATAL;
795 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
796 goto f_err;
797 }
798
799 sc->peer_cert_type=i;
800 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
801 if (sc->peer_pkeys[i].x509 != NULL) /* Why would this ever happen?
802 * We just created sc a couple of
803 * lines ago. */
804 X509_free(sc->peer_pkeys[i].x509);
805 sc->peer_pkeys[i].x509=x;
806 sc->peer_key= &(sc->peer_pkeys[i]);
807
808 if (s->session->peer != NULL)
809 X509_free(s->session->peer);
810 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
811 s->session->peer=x;
812
813 x=NULL;
814 ret=1;
815
816 if (0)
817 {
818f_err:
819 ssl3_send_alert(s,SSL3_AL_FATAL,al);
820 }
821err:
822 EVP_PKEY_free(pkey);
823 X509_free(x);
824 sk_X509_pop_free(sk,X509_free);
825 return(ret);
826 }
827
828static int ssl3_get_key_exchange(SSL *s)
829 {
830#ifndef NO_RSA
831 unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];
832#endif
833 EVP_MD_CTX md_ctx;
834 unsigned char *param,*p;
835 int al,i,j,param_len,ok;
836 long n,alg;
837 EVP_PKEY *pkey=NULL;
838#ifndef NO_RSA
839 RSA *rsa=NULL;
840#endif
841#ifndef NO_DH
842 DH *dh=NULL;
843#endif
844
845 n=ssl3_get_message(s,
846 SSL3_ST_CR_KEY_EXCH_A,
847 SSL3_ST_CR_KEY_EXCH_B,
848 -1,
849 1024*8, /* ?? */
850 &ok);
851
852 if (!ok) return((int)n);
853
854 if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)
855 {
856 s->s3->tmp.reuse_message=1;
857 return(1);
858 }
859
860 param=p=(unsigned char *)s->init_buf->data;
861
862 if (s->session->sess_cert != NULL)
863 {
864#ifndef NO_RSA
865 if (s->session->sess_cert->peer_rsa_tmp != NULL)
866 {
867 RSA_free(s->session->sess_cert->peer_rsa_tmp);
868 s->session->sess_cert->peer_rsa_tmp=NULL;
869 }
870#endif
871#ifndef NO_DH
872 if (s->session->sess_cert->peer_dh_tmp)
873 {
874 DH_free(s->session->sess_cert->peer_dh_tmp);
875 s->session->sess_cert->peer_dh_tmp=NULL;
876 }
877#endif
878 }
879 else
880 {
881 s->session->sess_cert=ssl_sess_cert_new();
882 }
883
884 param_len=0;
885 alg=s->s3->tmp.new_cipher->algorithms;
886
887#ifndef NO_RSA
888 if (alg & SSL_kRSA)
889 {
890 if ((rsa=RSA_new()) == NULL)
891 {
892 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
893 goto err;
894 }
895 n2s(p,i);
896 param_len=i+2;
897 if (param_len > n)
898 {
899 al=SSL_AD_DECODE_ERROR;
900 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);
901 goto f_err;
902 }
903 if (!(rsa->n=BN_bin2bn(p,i,rsa->n)))
904 {
905 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
906 goto err;
907 }
908 p+=i;
909
910 n2s(p,i);
911 param_len+=i+2;
912 if (param_len > n)
913 {
914 al=SSL_AD_DECODE_ERROR;
915 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);
916 goto f_err;
917 }
918 if (!(rsa->e=BN_bin2bn(p,i,rsa->e)))
919 {
920 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
921 goto err;
922 }
923 p+=i;
924 n-=param_len;
925
926 /* this should be because we are using an export cipher */
927 if (alg & SSL_aRSA)
928 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
929 else
930 {
931 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
932 goto err;
933 }
934 s->session->sess_cert->peer_rsa_tmp=rsa;
935 rsa=NULL;
936 }
937 else
938#endif
939#ifndef NO_DH
940 if (alg & SSL_kEDH)
941 {
942 if ((dh=DH_new()) == NULL)
943 {
944 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB);
945 goto err;
946 }
947 n2s(p,i);
948 param_len=i+2;
949 if (param_len > n)
950 {
951 al=SSL_AD_DECODE_ERROR;
952 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH);
953 goto f_err;
954 }
955 if (!(dh->p=BN_bin2bn(p,i,NULL)))
956 {
957 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
958 goto err;
959 }
960 p+=i;
961
962 n2s(p,i);
963 param_len+=i+2;
964 if (param_len > n)
965 {
966 al=SSL_AD_DECODE_ERROR;
967 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH);
968 goto f_err;
969 }
970 if (!(dh->g=BN_bin2bn(p,i,NULL)))
971 {
972 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
973 goto err;
974 }
975 p+=i;
976
977 n2s(p,i);
978 param_len+=i+2;
979 if (param_len > n)
980 {
981 al=SSL_AD_DECODE_ERROR;
982 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH);
983 goto f_err;
984 }
985 if (!(dh->pub_key=BN_bin2bn(p,i,NULL)))
986 {
987 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
988 goto err;
989 }
990 p+=i;
991 n-=param_len;
992
993#ifndef NO_RSA
994 if (alg & SSL_aRSA)
995 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
996 else
997#endif
998#ifndef NO_DSA
999 if (alg & SSL_aDSS)
1000 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509);
1001#endif
1002 /* else anonymous DH, so no certificate or pkey. */
1003
1004 s->session->sess_cert->peer_dh_tmp=dh;
1005 dh=NULL;
1006 }
1007 else if ((alg & SSL_kDHr) || (alg & SSL_kDHd))
1008 {
1009 al=SSL_AD_ILLEGAL_PARAMETER;
1010 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1011 goto f_err;
1012 }
1013#endif
1014 if (alg & SSL_aFZA)
1015 {
1016 al=SSL_AD_HANDSHAKE_FAILURE;
1017 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1018 goto f_err;
1019 }
1020
1021
1022 /* p points to the next byte, there are 'n' bytes left */
1023
1024
1025 /* if it was signed, check the signature */
1026 if (pkey != NULL)
1027 {
1028 n2s(p,i);
1029 n-=2;
1030 j=EVP_PKEY_size(pkey);
1031
1032 if ((i != n) || (n > j) || (n <= 0))
1033 {
1034 /* wrong packet length */
1035 al=SSL_AD_DECODE_ERROR;
1036 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH);
1037 goto f_err;
1038 }
1039
1040#ifndef NO_RSA
1041 if (pkey->type == EVP_PKEY_RSA)
1042 {
1043 int num;
1044
1045 j=0;
1046 q=md_buf;
1047 for (num=2; num > 0; num--)
1048 {
1049 EVP_DigestInit(&md_ctx,(num == 2)
1050 ?s->ctx->md5:s->ctx->sha1);
1051 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1052 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1053 EVP_DigestUpdate(&md_ctx,param,param_len);
1054 EVP_DigestFinal(&md_ctx,q,(unsigned int *)&i);
1055 q+=i;
1056 j+=i;
1057 }
1058 i=RSA_verify(NID_md5_sha1, md_buf, j, p, n,
1059 pkey->pkey.rsa);
1060 if (i < 0)
1061 {
1062 al=SSL_AD_DECRYPT_ERROR;
1063 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1064 goto f_err;
1065 }
1066 if (i == 0)
1067 {
1068 /* bad signature */
1069 al=SSL_AD_DECRYPT_ERROR;
1070 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1071 goto f_err;
1072 }
1073 }
1074 else
1075#endif
1076#ifndef NO_DSA
1077 if (pkey->type == EVP_PKEY_DSA)
1078 {
1079 /* lets do DSS */
1080 EVP_VerifyInit(&md_ctx,EVP_dss1());
1081 EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1082 EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1083 EVP_VerifyUpdate(&md_ctx,param,param_len);
1084 if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))
1085 {
1086 /* bad signature */
1087 al=SSL_AD_DECRYPT_ERROR;
1088 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1089 goto f_err;
1090 }
1091 }
1092 else
1093#endif
1094 {
1095 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1096 goto err;
1097 }
1098 }
1099 else
1100 {
1101 /* still data left over */
1102 if (!(alg & SSL_aNULL))
1103 {
1104 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1105 goto err;
1106 }
1107 if (n != 0)
1108 {
1109 al=SSL_AD_DECODE_ERROR;
1110 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE);
1111 goto f_err;
1112 }
1113 }
1114 EVP_PKEY_free(pkey);
1115 return(1);
1116f_err:
1117 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1118err:
1119 EVP_PKEY_free(pkey);
1120#ifndef NO_RSA
1121 if (rsa != NULL)
1122 RSA_free(rsa);
1123#endif
1124#ifndef NO_DH
1125 if (dh != NULL)
1126 DH_free(dh);
1127#endif
1128 return(-1);
1129 }
1130
1131static int ssl3_get_certificate_request(SSL *s)
1132 {
1133 int ok,ret=0;
1134 unsigned long n,nc,l;
1135 unsigned int llen,ctype_num,i;
1136 X509_NAME *xn=NULL;
1137 unsigned char *p,*d,*q;
1138 STACK_OF(X509_NAME) *ca_sk=NULL;
1139
1140 n=ssl3_get_message(s,
1141 SSL3_ST_CR_CERT_REQ_A,
1142 SSL3_ST_CR_CERT_REQ_B,
1143 -1,
1144#if defined(MSDOS) && !defined(WIN32)
1145 1024*30, /* 30k max cert list :-) */
1146#else
1147 1024*100, /* 100k max cert list :-) */
1148#endif
1149 &ok);
1150
1151 if (!ok) return((int)n);
1152
1153 s->s3->tmp.cert_req=0;
1154
1155 if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)
1156 {
1157 s->s3->tmp.reuse_message=1;
1158 return(1);
1159 }
1160
1161 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)
1162 {
1163 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1164 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);
1165 goto err;
1166 }
1167
1168 /* TLS does not like anon-DH with client cert */
1169 if (s->version > SSL3_VERSION)
1170 {
1171 l=s->s3->tmp.new_cipher->algorithms;
1172 if (l & SSL_aNULL)
1173 {
1174 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1175 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);
1176 goto err;
1177 }
1178 }
1179
1180 d=p=(unsigned char *)s->init_buf->data;
1181
1182 if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL)
1183 {
1184 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1185 goto err;
1186 }
1187
1188 /* get the certificate types */
1189 ctype_num= *(p++);
1190 if (ctype_num > SSL3_CT_NUMBER)
1191 ctype_num=SSL3_CT_NUMBER;
1192 for (i=0; i<ctype_num; i++)
1193 s->s3->tmp.ctype[i]= p[i];
1194 p+=ctype_num;
1195
1196 /* get the CA RDNs */
1197 n2s(p,llen);
1198#if 0
1199{
1200FILE *out;
1201out=fopen("/tmp/vsign.der","w");
1202fwrite(p,1,llen,out);
1203fclose(out);
1204}
1205#endif
1206
1207 if ((llen+ctype_num+2+1) != n)
1208 {
1209 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1210 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);
1211 goto err;
1212 }
1213
1214 for (nc=0; nc<llen; )
1215 {
1216 n2s(p,l);
1217 if ((l+nc+2) > llen)
1218 {
1219 if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1220 goto cont; /* netscape bugs */
1221 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1222 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);
1223 goto err;
1224 }
1225
1226 q=p;
1227
1228 if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)
1229 {
1230 /* If netscape tolerance is on, ignore errors */
1231 if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)
1232 goto cont;
1233 else
1234 {
1235 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1236 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);
1237 goto err;
1238 }
1239 }
1240
1241 if (q != (p+l))
1242 {
1243 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1244 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);
1245 goto err;
1246 }
1247 if (!sk_X509_NAME_push(ca_sk,xn))
1248 {
1249 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1250 goto err;
1251 }
1252
1253 p+=l;
1254 nc+=l+2;
1255 }
1256
1257 if (0)
1258 {
1259cont:
1260 ERR_clear_error();
1261 }
1262
1263 /* we should setup a certificate to return.... */
1264 s->s3->tmp.cert_req=1;
1265 s->s3->tmp.ctype_num=ctype_num;
1266 if (s->s3->tmp.ca_names != NULL)
1267 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1268 s->s3->tmp.ca_names=ca_sk;
1269 ca_sk=NULL;
1270
1271 ret=1;
1272err:
1273 if (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free);
1274 return(ret);
1275 }
1276
1277static int ca_dn_cmp(X509_NAME **a, X509_NAME **b)
1278 {
1279 return(X509_NAME_cmp(*a,*b));
1280 }
1281
1282static int ssl3_get_server_done(SSL *s)
1283 {
1284 int ok,ret=0;
1285 long n;
1286
1287 n=ssl3_get_message(s,
1288 SSL3_ST_CR_SRVR_DONE_A,
1289 SSL3_ST_CR_SRVR_DONE_B,
1290 SSL3_MT_SERVER_DONE,
1291 30, /* should be very small, like 0 :-) */
1292 &ok);
1293
1294 if (!ok) return((int)n);
1295 if (n > 0)
1296 {
1297 /* should contain no data */
1298 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1299 SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH);
1300 }
1301 ret=1;
1302 return(ret);
1303 }
1304
1305static int ssl3_send_client_key_exchange(SSL *s)
1306 {
1307 unsigned char *p,*d;
1308 int n;
1309 unsigned long l;
1310#ifndef NO_RSA
1311 unsigned char *q;
1312 EVP_PKEY *pkey=NULL;
1313#endif
1314
1315 if (s->state == SSL3_ST_CW_KEY_EXCH_A)
1316 {
1317 d=(unsigned char *)s->init_buf->data;
1318 p= &(d[4]);
1319
1320 l=s->s3->tmp.new_cipher->algorithms;
1321
1322#ifndef NO_RSA
1323 if (l & SSL_kRSA)
1324 {
1325 RSA *rsa;
1326 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
1327
1328 if (s->session->sess_cert->peer_rsa_tmp != NULL)
1329 rsa=s->session->sess_cert->peer_rsa_tmp;
1330 else
1331 {
1332 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
1333 if ((pkey == NULL) ||
1334 (pkey->type != EVP_PKEY_RSA) ||
1335 (pkey->pkey.rsa == NULL))
1336 {
1337 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1338 goto err;
1339 }
1340 rsa=pkey->pkey.rsa;
1341 EVP_PKEY_free(pkey);
1342 }
1343
1344 tmp_buf[0]=s->client_version>>8;
1345 tmp_buf[1]=s->client_version&0xff;
1346 if (RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2) <= 0)
1347 goto err;
1348
1349 s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
1350
1351 q=p;
1352 /* Fix buf for TLS and beyond */
1353 if (s->version > SSL3_VERSION)
1354 p+=2;
1355 n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH,
1356 tmp_buf,p,rsa,RSA_PKCS1_PADDING);
1357#ifdef PKCS1_CHECK
1358 if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++;
1359 if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70;
1360#endif
1361 if (n <= 0)
1362 {
1363 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT);
1364 goto err;
1365 }
1366
1367 /* Fix buf for TLS and beyond */
1368 if (s->version > SSL3_VERSION)
1369 {
1370 s2n(n,q);
1371 n+=2;
1372 }
1373
1374 s->session->master_key_length=
1375 s->method->ssl3_enc->generate_master_secret(s,
1376 s->session->master_key,
1377 tmp_buf,SSL_MAX_MASTER_KEY_LENGTH);
1378 memset(tmp_buf,0,SSL_MAX_MASTER_KEY_LENGTH);
1379 }
1380 else
1381#endif
1382#ifndef NO_DH
1383 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1384 {
1385 DH *dh_srvr,*dh_clnt;
1386
1387 if (s->session->sess_cert->peer_dh_tmp != NULL)
1388 dh_srvr=s->session->sess_cert->peer_dh_tmp;
1389 else
1390 {
1391 /* we get them from the cert */
1392 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1393 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS);
1394 goto err;
1395 }
1396
1397 /* generate a new random key */
1398 if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL)
1399 {
1400 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1401 goto err;
1402 }
1403 if (!DH_generate_key(dh_clnt))
1404 {
1405 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1406 goto err;
1407 }
1408
1409 /* use the 'p' output buffer for the DH key, but
1410 * make sure to clear it out afterwards */
1411
1412 n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt);
1413
1414 if (n <= 0)
1415 {
1416 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1417 goto err;
1418 }
1419
1420 /* generate master key from the result */
1421 s->session->master_key_length=
1422 s->method->ssl3_enc->generate_master_secret(s,
1423 s->session->master_key,p,n);
1424 /* clean up */
1425 memset(p,0,n);
1426
1427 /* send off the data */
1428 n=BN_num_bytes(dh_clnt->pub_key);
1429 s2n(n,p);
1430 BN_bn2bin(dh_clnt->pub_key,p);
1431 n+=2;
1432
1433 DH_free(dh_clnt);
1434
1435 /* perhaps clean things up a bit EAY EAY EAY EAY*/
1436 }
1437 else
1438#endif
1439 {
1440 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1441 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1442 goto err;
1443 }
1444
1445 *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE;
1446 l2n3(n,d);
1447
1448 s->state=SSL3_ST_CW_KEY_EXCH_B;
1449 /* number of bytes to write */
1450 s->init_num=n+4;
1451 s->init_off=0;
1452 }
1453
1454 /* SSL3_ST_CW_KEY_EXCH_B */
1455 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1456err:
1457 return(-1);
1458 }
1459
1460static int ssl3_send_client_verify(SSL *s)
1461 {
1462 unsigned char *p,*d;
1463 unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
1464 EVP_PKEY *pkey;
1465#ifndef NO_RSA
1466 unsigned u=0;
1467#endif
1468 unsigned long n;
1469#ifndef NO_DSA
1470 int j;
1471#endif
1472
1473 if (s->state == SSL3_ST_CW_CERT_VRFY_A)
1474 {
1475 d=(unsigned char *)s->init_buf->data;
1476 p= &(d[4]);
1477 pkey=s->cert->key->privatekey;
1478
1479 s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
1480 &(data[MD5_DIGEST_LENGTH]));
1481
1482#ifndef NO_RSA
1483 if (pkey->type == EVP_PKEY_RSA)
1484 {
1485 s->method->ssl3_enc->cert_verify_mac(s,
1486 &(s->s3->finish_dgst1),&(data[0]));
1487 if (RSA_sign(NID_md5_sha1, data,
1488 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
1489 &(p[2]), &u, pkey->pkey.rsa) <= 0 )
1490 {
1491 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB);
1492 goto err;
1493 }
1494 s2n(u,p);
1495 n=u+2;
1496 }
1497 else
1498#endif
1499#ifndef NO_DSA
1500 if (pkey->type == EVP_PKEY_DSA)
1501 {
1502 if (!DSA_sign(pkey->save_type,
1503 &(data[MD5_DIGEST_LENGTH]),
1504 SHA_DIGEST_LENGTH,&(p[2]),
1505 (unsigned int *)&j,pkey->pkey.dsa))
1506 {
1507 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB);
1508 goto err;
1509 }
1510 s2n(j,p);
1511 n=j+2;
1512 }
1513 else
1514#endif
1515 {
1516 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,SSL_R_INTERNAL_ERROR);
1517 goto err;
1518 }
1519 *(d++)=SSL3_MT_CERTIFICATE_VERIFY;
1520 l2n3(n,d);
1521
1522 s->init_num=(int)n+4;
1523 s->init_off=0;
1524 }
1525 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1526err:
1527 return(-1);
1528 }
1529
1530static int ssl3_send_client_certificate(SSL *s)
1531 {
1532 X509 *x509=NULL;
1533 EVP_PKEY *pkey=NULL;
1534 int i;
1535 unsigned long l;
1536
1537 if (s->state == SSL3_ST_CW_CERT_A)
1538 {
1539 if ((s->cert == NULL) ||
1540 (s->cert->key->x509 == NULL) ||
1541 (s->cert->key->privatekey == NULL))
1542 s->state=SSL3_ST_CW_CERT_B;
1543 else
1544 s->state=SSL3_ST_CW_CERT_C;
1545 }
1546
1547 /* We need to get a client cert */
1548 if (s->state == SSL3_ST_CW_CERT_B)
1549 {
1550 /* If we get an error, we need to
1551 * ssl->rwstate=SSL_X509_LOOKUP; return(-1);
1552 * We then get retied later */
1553 i=0;
1554 if (s->ctx->client_cert_cb != NULL)
1555 i=s->ctx->client_cert_cb(s,&(x509),&(pkey));
1556 if (i < 0)
1557 {
1558 s->rwstate=SSL_X509_LOOKUP;
1559 return(-1);
1560 }
1561 s->rwstate=SSL_NOTHING;
1562 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
1563 {
1564 s->state=SSL3_ST_CW_CERT_B;
1565 if ( !SSL_use_certificate(s,x509) ||
1566 !SSL_use_PrivateKey(s,pkey))
1567 i=0;
1568 }
1569 else if (i == 1)
1570 {
1571 i=0;
1572 SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
1573 }
1574
1575 if (x509 != NULL) X509_free(x509);
1576 if (pkey != NULL) EVP_PKEY_free(pkey);
1577 if (i == 0)
1578 {
1579 if (s->version == SSL3_VERSION)
1580 {
1581 s->s3->tmp.cert_req=0;
1582 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE);
1583 return(1);
1584 }
1585 else
1586 {
1587 s->s3->tmp.cert_req=2;
1588 }
1589 }
1590
1591 /* Ok, we have a cert */
1592 s->state=SSL3_ST_CW_CERT_C;
1593 }
1594
1595 if (s->state == SSL3_ST_CW_CERT_C)
1596 {
1597 s->state=SSL3_ST_CW_CERT_D;
1598 l=ssl3_output_cert_chain(s,
1599 (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509);
1600 s->init_num=(int)l;
1601 s->init_off=0;
1602 }
1603 /* SSL3_ST_CW_CERT_D */
1604 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1605 }
1606
1607#define has_bits(i,m) (((i)&(m)) == (m))
1608
1609static int ssl3_check_cert_and_algorithm(SSL *s)
1610 {
1611 int i,idx;
1612 long algs;
1613 EVP_PKEY *pkey=NULL;
1614 SESS_CERT *sc;
1615#ifndef NO_RSA
1616 RSA *rsa;
1617#endif
1618#ifndef NO_DH
1619 DH *dh;
1620#endif
1621
1622 sc=s->session->sess_cert;
1623
1624 if (sc == NULL)
1625 {
1626 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR);
1627 goto err;
1628 }
1629
1630 algs=s->s3->tmp.new_cipher->algorithms;
1631
1632 /* we don't have a certificate */
1633 if (algs & (SSL_aDH|SSL_aNULL))
1634 return(1);
1635
1636#ifndef NO_RSA
1637 rsa=s->session->sess_cert->peer_rsa_tmp;
1638#endif
1639#ifndef NO_DH
1640 dh=s->session->sess_cert->peer_dh_tmp;
1641#endif
1642
1643 /* This is the passed certificate */
1644
1645 idx=sc->peer_cert_type;
1646 pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509);
1647 i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey);
1648 EVP_PKEY_free(pkey);
1649
1650
1651 /* Check that we have a certificate if we require one */
1652 if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
1653 {
1654 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);
1655 goto f_err;
1656 }
1657#ifndef NO_DSA
1658 else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
1659 {
1660 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);
1661 goto f_err;
1662 }
1663#endif
1664#ifndef NO_RSA
1665 if ((algs & SSL_kRSA) &&
1666 !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))
1667 {
1668 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);
1669 goto f_err;
1670 }
1671#endif
1672#ifndef NO_DH
1673 if ((algs & SSL_kEDH) &&
1674 !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))
1675 {
1676 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);
1677 goto f_err;
1678 }
1679 else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
1680 {
1681 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);
1682 goto f_err;
1683 }
1684#ifndef NO_DSA
1685 else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
1686 {
1687 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);
1688 goto f_err;
1689 }
1690#endif
1691#endif
1692
1693 if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))
1694 {
1695#ifndef NO_RSA
1696 if (algs & SSL_kRSA)
1697 {
1698 if (rsa == NULL
1699 || RSA_size(rsa) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
1700 {
1701 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
1702 goto f_err;
1703 }
1704 }
1705 else
1706#endif
1707#ifndef NO_DH
1708 if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1709 {
1710 if (dh == NULL
1711 || DH_size(dh) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
1712 {
1713 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);
1714 goto f_err;
1715 }
1716 }
1717 else
1718#endif
1719 {
1720 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1721 goto f_err;
1722 }
1723 }
1724 return(1);
1725f_err:
1726 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1727err:
1728 return(0);
1729 }
1730
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
deleted file mode 100644
index 7ada26cbb6..0000000000
--- a/src/lib/libssl/s3_lib.c
+++ /dev/null
@@ -1,1339 +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_SSLV3,
79 SSL_NOT_EXP,
80 0,
81 0,
82 0,
83 SSL_ALL_CIPHERS,
84 SSL_ALL_STRENGTHS,
85 },
86/* Cipher 02 */
87 {
88 1,
89 SSL3_TXT_RSA_NULL_SHA,
90 SSL3_CK_RSA_NULL_SHA,
91 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3,
92 SSL_NOT_EXP,
93 0,
94 0,
95 0,
96 SSL_ALL_CIPHERS,
97 SSL_ALL_STRENGTHS,
98 },
99
100/* anon DH */
101/* Cipher 17 */
102 {
103 1,
104 SSL3_TXT_ADH_RC4_40_MD5,
105 SSL3_CK_ADH_RC4_40_MD5,
106 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
107 SSL_EXPORT|SSL_EXP40,
108 0,
109 40,
110 128,
111 SSL_ALL_CIPHERS,
112 SSL_ALL_STRENGTHS,
113 },
114/* Cipher 18 */
115 {
116 1,
117 SSL3_TXT_ADH_RC4_128_MD5,
118 SSL3_CK_ADH_RC4_128_MD5,
119 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
120 SSL_NOT_EXP,
121 0,
122 128,
123 128,
124 SSL_ALL_CIPHERS,
125 SSL_ALL_STRENGTHS,
126 },
127/* Cipher 19 */
128 {
129 1,
130 SSL3_TXT_ADH_DES_40_CBC_SHA,
131 SSL3_CK_ADH_DES_40_CBC_SHA,
132 SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3,
133 SSL_EXPORT|SSL_EXP40,
134 0,
135 40,
136 128,
137 SSL_ALL_CIPHERS,
138 SSL_ALL_STRENGTHS,
139 },
140/* Cipher 1A */
141 {
142 1,
143 SSL3_TXT_ADH_DES_64_CBC_SHA,
144 SSL3_CK_ADH_DES_64_CBC_SHA,
145 SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_SSLV3,
146 SSL_NOT_EXP,
147 0,
148 56,
149 56,
150 SSL_ALL_CIPHERS,
151 SSL_ALL_STRENGTHS,
152 },
153/* Cipher 1B */
154 {
155 1,
156 SSL3_TXT_ADH_DES_192_CBC_SHA,
157 SSL3_CK_ADH_DES_192_CBC_SHA,
158 SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3,
159 SSL_NOT_EXP,
160 0,
161 168,
162 168,
163 SSL_ALL_CIPHERS,
164 SSL_ALL_STRENGTHS,
165 },
166
167/* RSA again */
168/* Cipher 03 */
169 {
170 1,
171 SSL3_TXT_RSA_RC4_40_MD5,
172 SSL3_CK_RSA_RC4_40_MD5,
173 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
174 SSL_EXPORT|SSL_EXP40,
175 0,
176 40,
177 128,
178 SSL_ALL_CIPHERS,
179 SSL_ALL_STRENGTHS,
180 },
181/* Cipher 04 */
182 {
183 1,
184 SSL3_TXT_RSA_RC4_128_MD5,
185 SSL3_CK_RSA_RC4_128_MD5,
186 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_SSLV3,
187 SSL_NOT_EXP|SSL_MEDIUM,
188 0,
189 128,
190 128,
191 SSL_ALL_CIPHERS,
192 SSL_ALL_STRENGTHS,
193 },
194/* Cipher 05 */
195 {
196 1,
197 SSL3_TXT_RSA_RC4_128_SHA,
198 SSL3_CK_RSA_RC4_128_SHA,
199 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_SSLV3,
200 SSL_NOT_EXP|SSL_MEDIUM,
201 0,
202 128,
203 128,
204 SSL_ALL_CIPHERS,
205 SSL_ALL_STRENGTHS,
206 },
207/* Cipher 06 */
208 {
209 1,
210 SSL3_TXT_RSA_RC2_40_MD5,
211 SSL3_CK_RSA_RC2_40_MD5,
212 SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_SSLV3,
213 SSL_EXPORT|SSL_EXP40,
214 0,
215 40,
216 128,
217 SSL_ALL_CIPHERS,
218 SSL_ALL_STRENGTHS,
219 },
220/* Cipher 07 */
221 {
222 1,
223 SSL3_TXT_RSA_IDEA_128_SHA,
224 SSL3_CK_RSA_IDEA_128_SHA,
225 SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_SSLV3,
226 SSL_NOT_EXP|SSL_MEDIUM,
227 0,
228 128,
229 128,
230 SSL_ALL_CIPHERS,
231 SSL_ALL_STRENGTHS,
232 },
233/* Cipher 08 */
234 {
235 1,
236 SSL3_TXT_RSA_DES_40_CBC_SHA,
237 SSL3_CK_RSA_DES_40_CBC_SHA,
238 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
239 SSL_EXPORT|SSL_EXP40,
240 0,
241 40,
242 56,
243 SSL_ALL_CIPHERS,
244 SSL_ALL_STRENGTHS,
245 },
246/* Cipher 09 */
247 {
248 1,
249 SSL3_TXT_RSA_DES_64_CBC_SHA,
250 SSL3_CK_RSA_DES_64_CBC_SHA,
251 SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3,
252 SSL_NOT_EXP|SSL_LOW,
253 0,
254 56,
255 56,
256 SSL_ALL_CIPHERS,
257 SSL_ALL_STRENGTHS,
258 },
259/* Cipher 0A */
260 {
261 1,
262 SSL3_TXT_RSA_DES_192_CBC3_SHA,
263 SSL3_CK_RSA_DES_192_CBC3_SHA,
264 SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
265 SSL_NOT_EXP|SSL_HIGH,
266 0,
267 168,
268 168,
269 SSL_ALL_CIPHERS,
270 SSL_ALL_STRENGTHS,
271 },
272
273/* The DH ciphers */
274/* Cipher 0B */
275 {
276 0,
277 SSL3_TXT_DH_DSS_DES_40_CBC_SHA,
278 SSL3_CK_DH_DSS_DES_40_CBC_SHA,
279 SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
280 SSL_EXPORT|SSL_EXP40,
281 0,
282 40,
283 56,
284 SSL_ALL_CIPHERS,
285 SSL_ALL_STRENGTHS,
286 },
287/* Cipher 0C */
288 {
289 0,
290 SSL3_TXT_DH_DSS_DES_64_CBC_SHA,
291 SSL3_CK_DH_DSS_DES_64_CBC_SHA,
292 SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3,
293 SSL_NOT_EXP|SSL_LOW,
294 0,
295 56,
296 56,
297 SSL_ALL_CIPHERS,
298 SSL_ALL_STRENGTHS,
299 },
300/* Cipher 0D */
301 {
302 0,
303 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA,
304 SSL3_CK_DH_DSS_DES_192_CBC3_SHA,
305 SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
306 SSL_NOT_EXP|SSL_HIGH,
307 0,
308 168,
309 168,
310 SSL_ALL_CIPHERS,
311 SSL_ALL_STRENGTHS,
312 },
313/* Cipher 0E */
314 {
315 0,
316 SSL3_TXT_DH_RSA_DES_40_CBC_SHA,
317 SSL3_CK_DH_RSA_DES_40_CBC_SHA,
318 SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
319 SSL_EXPORT|SSL_EXP40,
320 0,
321 40,
322 56,
323 SSL_ALL_CIPHERS,
324 SSL_ALL_STRENGTHS,
325 },
326/* Cipher 0F */
327 {
328 0,
329 SSL3_TXT_DH_RSA_DES_64_CBC_SHA,
330 SSL3_CK_DH_RSA_DES_64_CBC_SHA,
331 SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3,
332 SSL_NOT_EXP|SSL_LOW,
333 0,
334 56,
335 56,
336 SSL_ALL_CIPHERS,
337 SSL_ALL_STRENGTHS,
338 },
339/* Cipher 10 */
340 {
341 0,
342 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA,
343 SSL3_CK_DH_RSA_DES_192_CBC3_SHA,
344 SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
345 SSL_NOT_EXP|SSL_HIGH,
346 0,
347 168,
348 168,
349 SSL_ALL_CIPHERS,
350 SSL_ALL_STRENGTHS,
351 },
352
353/* The Ephemeral DH ciphers */
354/* Cipher 11 */
355 {
356 1,
357 SSL3_TXT_EDH_DSS_DES_40_CBC_SHA,
358 SSL3_CK_EDH_DSS_DES_40_CBC_SHA,
359 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3,
360 SSL_EXPORT|SSL_EXP40,
361 0,
362 40,
363 56,
364 SSL_ALL_CIPHERS,
365 SSL_ALL_STRENGTHS,
366 },
367/* Cipher 12 */
368 {
369 1,
370 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA,
371 SSL3_CK_EDH_DSS_DES_64_CBC_SHA,
372 SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_SSLV3,
373 SSL_NOT_EXP|SSL_LOW,
374 0,
375 56,
376 56,
377 SSL_ALL_CIPHERS,
378 SSL_ALL_STRENGTHS,
379 },
380/* Cipher 13 */
381 {
382 1,
383 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA,
384 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA,
385 SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3,
386 SSL_NOT_EXP|SSL_HIGH,
387 0,
388 168,
389 168,
390 SSL_ALL_CIPHERS,
391 SSL_ALL_STRENGTHS,
392 },
393/* Cipher 14 */
394 {
395 1,
396 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA,
397 SSL3_CK_EDH_RSA_DES_40_CBC_SHA,
398 SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
399 SSL_EXPORT|SSL_EXP40,
400 0,
401 40,
402 56,
403 SSL_ALL_CIPHERS,
404 SSL_ALL_STRENGTHS,
405 },
406/* Cipher 15 */
407 {
408 1,
409 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA,
410 SSL3_CK_EDH_RSA_DES_64_CBC_SHA,
411 SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3,
412 SSL_NOT_EXP|SSL_LOW,
413 0,
414 56,
415 56,
416 SSL_ALL_CIPHERS,
417 SSL_ALL_STRENGTHS,
418 },
419/* Cipher 16 */
420 {
421 1,
422 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA,
423 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA,
424 SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
425 SSL_NOT_EXP|SSL_HIGH,
426 0,
427 168,
428 168,
429 SSL_ALL_CIPHERS,
430 SSL_ALL_STRENGTHS,
431 },
432
433/* Fortezza */
434/* Cipher 1C */
435 {
436 0,
437 SSL3_TXT_FZA_DMS_NULL_SHA,
438 SSL3_CK_FZA_DMS_NULL_SHA,
439 SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_SSLV3,
440 SSL_NOT_EXP,
441 0,
442 0,
443 0,
444 SSL_ALL_CIPHERS,
445 SSL_ALL_STRENGTHS,
446 },
447
448/* Cipher 1D */
449 {
450 0,
451 SSL3_TXT_FZA_DMS_FZA_SHA,
452 SSL3_CK_FZA_DMS_FZA_SHA,
453 SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_SSLV3,
454 SSL_NOT_EXP,
455 0,
456 0,
457 0,
458 SSL_ALL_CIPHERS,
459 SSL_ALL_STRENGTHS,
460 },
461
462/* Cipher 1E */
463 {
464 0,
465 SSL3_TXT_FZA_DMS_RC4_SHA,
466 SSL3_CK_FZA_DMS_RC4_SHA,
467 SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_SSLV3,
468 SSL_NOT_EXP,
469 0,
470 128,
471 128,
472 SSL_ALL_CIPHERS,
473 SSL_ALL_STRENGTHS,
474 },
475
476#if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
477 /* New TLS Export CipherSuites */
478 /* Cipher 60 */
479 {
480 1,
481 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5,
482 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5,
483 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_TLSV1,
484 SSL_EXPORT|SSL_EXP56,
485 0,
486 56,
487 128,
488 SSL_ALL_CIPHERS,
489 SSL_ALL_STRENGTHS,
490 },
491 /* Cipher 61 */
492 {
493 1,
494 TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
495 TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
496 SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_TLSV1,
497 SSL_EXPORT|SSL_EXP56,
498 0,
499 56,
500 128,
501 SSL_ALL_CIPHERS,
502 SSL_ALL_STRENGTHS,
503 },
504 /* Cipher 62 */
505 {
506 1,
507 TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA,
508 TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA,
509 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1,
510 SSL_EXPORT|SSL_EXP56,
511 0,
512 56,
513 56,
514 SSL_ALL_CIPHERS,
515 SSL_ALL_STRENGTHS,
516 },
517 /* Cipher 63 */
518 {
519 1,
520 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
521 TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
522 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1,
523 SSL_EXPORT|SSL_EXP56,
524 0,
525 56,
526 56,
527 SSL_ALL_CIPHERS,
528 SSL_ALL_STRENGTHS,
529 },
530 /* Cipher 64 */
531 {
532 1,
533 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA,
534 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA,
535 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
536 SSL_EXPORT|SSL_EXP56,
537 0,
538 56,
539 128,
540 SSL_ALL_CIPHERS,
541 SSL_ALL_STRENGTHS,
542 },
543 /* Cipher 65 */
544 {
545 1,
546 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
547 TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
548 SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
549 SSL_EXPORT|SSL_EXP56,
550 0,
551 56,
552 128,
553 SSL_ALL_CIPHERS,
554 SSL_ALL_STRENGTHS,
555 },
556 /* Cipher 66 */
557 {
558 1,
559 TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA,
560 TLS1_CK_DHE_DSS_WITH_RC4_128_SHA,
561 SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
562 SSL_NOT_EXP,
563 0,
564 128,
565 128,
566 SSL_ALL_CIPHERS,
567 SSL_ALL_STRENGTHS
568 },
569#endif
570
571/* end of list */
572 };
573
574static SSL3_ENC_METHOD SSLv3_enc_data={
575 ssl3_enc,
576 ssl3_mac,
577 ssl3_setup_key_block,
578 ssl3_generate_master_secret,
579 ssl3_change_cipher_state,
580 ssl3_final_finish_mac,
581 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
582 ssl3_cert_verify_mac,
583 SSL3_MD_CLIENT_FINISHED_CONST,4,
584 SSL3_MD_SERVER_FINISHED_CONST,4,
585 ssl3_alert_code,
586 };
587
588static SSL_METHOD SSLv3_data= {
589 SSL3_VERSION,
590 ssl3_new,
591 ssl3_clear,
592 ssl3_free,
593 ssl_undefined_function,
594 ssl_undefined_function,
595 ssl3_read,
596 ssl3_peek,
597 ssl3_write,
598 ssl3_shutdown,
599 ssl3_renegotiate,
600 ssl3_renegotiate_check,
601 ssl3_ctrl,
602 ssl3_ctx_ctrl,
603 ssl3_get_cipher_by_char,
604 ssl3_put_cipher_by_char,
605 ssl3_pending,
606 ssl3_num_ciphers,
607 ssl3_get_cipher,
608 ssl_bad_method,
609 ssl3_default_timeout,
610 &SSLv3_enc_data,
611 ssl_undefined_function,
612 ssl3_callback_ctrl,
613 ssl3_ctx_callback_ctrl,
614 };
615
616static long ssl3_default_timeout(void)
617 {
618 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
619 * is way too long for http, the cache would over fill */
620 return(60*60*2);
621 }
622
623SSL_METHOD *sslv3_base_method(void)
624 {
625 return(&SSLv3_data);
626 }
627
628int ssl3_num_ciphers(void)
629 {
630 return(SSL3_NUM_CIPHERS);
631 }
632
633SSL_CIPHER *ssl3_get_cipher(unsigned int u)
634 {
635 if (u < SSL3_NUM_CIPHERS)
636 return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
637 else
638 return(NULL);
639 }
640
641/* The problem is that it may not be the correct record type */
642int ssl3_pending(SSL *s)
643 {
644 return(s->s3->rrec.length);
645 }
646
647int ssl3_new(SSL *s)
648 {
649 SSL3_STATE *s3;
650
651 if ((s3=Malloc(sizeof *s3)) == NULL) goto err;
652 memset(s3,0,sizeof *s3);
653
654 s->s3=s3;
655
656 s->method->ssl_clear(s);
657 return(1);
658err:
659 return(0);
660 }
661
662void ssl3_free(SSL *s)
663 {
664 if(s == NULL)
665 return;
666
667 ssl3_cleanup_key_block(s);
668 if (s->s3->rbuf.buf != NULL)
669 Free(s->s3->rbuf.buf);
670 if (s->s3->wbuf.buf != NULL)
671 Free(s->s3->wbuf.buf);
672 if (s->s3->rrec.comp != NULL)
673 Free(s->s3->rrec.comp);
674#ifndef NO_DH
675 if (s->s3->tmp.dh != NULL)
676 DH_free(s->s3->tmp.dh);
677#endif
678 if (s->s3->tmp.ca_names != NULL)
679 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
680 memset(s->s3,0,sizeof *s->s3);
681 Free(s->s3);
682 s->s3=NULL;
683 }
684
685void ssl3_clear(SSL *s)
686 {
687 unsigned char *rp,*wp;
688
689 ssl3_cleanup_key_block(s);
690 if (s->s3->tmp.ca_names != NULL)
691 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
692
693 if (s->s3->rrec.comp != NULL)
694 {
695 Free(s->s3->rrec.comp);
696 s->s3->rrec.comp=NULL;
697 }
698#ifndef NO_DH
699 if (s->s3->tmp.dh != NULL)
700 DH_free(s->s3->tmp.dh);
701#endif
702
703 rp=s->s3->rbuf.buf;
704 wp=s->s3->wbuf.buf;
705
706 memset(s->s3,0,sizeof *s->s3);
707 if (rp != NULL) s->s3->rbuf.buf=rp;
708 if (wp != NULL) s->s3->wbuf.buf=wp;
709
710 ssl_free_wbio_buffer(s);
711
712 s->packet_length=0;
713 s->s3->renegotiate=0;
714 s->s3->total_renegotiations=0;
715 s->s3->num_renegotiations=0;
716 s->s3->in_read_app_data=0;
717 s->version=SSL3_VERSION;
718 }
719
720long ssl3_ctrl(SSL *s, int cmd, long larg, char *parg)
721 {
722 int ret=0;
723
724#if !defined(NO_DSA) || !defined(NO_RSA)
725 if (
726#ifndef NO_RSA
727 cmd == SSL_CTRL_SET_TMP_RSA ||
728 cmd == SSL_CTRL_SET_TMP_RSA_CB ||
729#endif
730#ifndef NO_DSA
731 cmd == SSL_CTRL_SET_TMP_DH ||
732 cmd == SSL_CTRL_SET_TMP_DH_CB ||
733#endif
734 0)
735 {
736 if (!ssl_cert_inst(&s->cert))
737 {
738 SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE);
739 return(0);
740 }
741 }
742#endif
743
744 switch (cmd)
745 {
746 case SSL_CTRL_GET_SESSION_REUSED:
747 ret=s->hit;
748 break;
749 case SSL_CTRL_GET_CLIENT_CERT_REQUEST:
750 break;
751 case SSL_CTRL_GET_NUM_RENEGOTIATIONS:
752 ret=s->s3->num_renegotiations;
753 break;
754 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:
755 ret=s->s3->num_renegotiations;
756 s->s3->num_renegotiations=0;
757 break;
758 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS:
759 ret=s->s3->total_renegotiations;
760 break;
761 case SSL_CTRL_GET_FLAGS:
762 ret=(int)(s->s3->flags);
763 break;
764#ifndef NO_RSA
765 case SSL_CTRL_NEED_TMP_RSA:
766 if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) &&
767 ((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
768 (EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))))
769 ret = 1;
770 break;
771 case SSL_CTRL_SET_TMP_RSA:
772 {
773 RSA *rsa = (RSA *)parg;
774 if (rsa == NULL)
775 {
776 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
777 return(ret);
778 }
779 if ((rsa = RSAPrivateKey_dup(rsa)) == NULL)
780 {
781 SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB);
782 return(ret);
783 }
784 if (s->cert->rsa_tmp != NULL)
785 RSA_free(s->cert->rsa_tmp);
786 s->cert->rsa_tmp = rsa;
787 ret = 1;
788 }
789 break;
790 case SSL_CTRL_SET_TMP_RSA_CB:
791 {
792 SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
793 return(ret);
794 }
795 break;
796#endif
797#ifndef NO_DH
798 case SSL_CTRL_SET_TMP_DH:
799 {
800 DH *dh = (DH *)parg;
801 if (dh == NULL)
802 {
803 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
804 return(ret);
805 }
806 if ((dh = DHparams_dup(dh)) == NULL)
807 {
808 SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
809 return(ret);
810 }
811 if (!(s->options & SSL_OP_SINGLE_DH_USE))
812 {
813 if (!DH_generate_key(dh))
814 {
815 DH_free(dh);
816 SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
817 return(ret);
818 }
819 }
820 if (s->cert->dh_tmp != NULL)
821 DH_free(s->cert->dh_tmp);
822 s->cert->dh_tmp = dh;
823 ret = 1;
824 }
825 break;
826 case SSL_CTRL_SET_TMP_DH_CB:
827 {
828 SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
829 return(ret);
830 }
831 break;
832#endif
833 default:
834 break;
835 }
836 return(ret);
837 }
838
839long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)())
840 {
841 int ret=0;
842
843#if !defined(NO_DSA) || !defined(NO_RSA)
844 if (
845#ifndef NO_RSA
846 cmd == SSL_CTRL_SET_TMP_RSA_CB ||
847#endif
848#ifndef NO_DSA
849 cmd == SSL_CTRL_SET_TMP_DH_CB ||
850#endif
851 0)
852 {
853 if (!ssl_cert_inst(&s->cert))
854 {
855 SSLerr(SSL_F_SSL3_CALLBACK_CTRL, ERR_R_MALLOC_FAILURE);
856 return(0);
857 }
858 }
859#endif
860
861 switch (cmd)
862 {
863#ifndef NO_RSA
864 case SSL_CTRL_SET_TMP_RSA_CB:
865 {
866 s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
867 }
868 break;
869#endif
870#ifndef NO_DH
871 case SSL_CTRL_SET_TMP_DH_CB:
872 {
873 s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
874 }
875 break;
876#endif
877 default:
878 break;
879 }
880 return(ret);
881 }
882
883long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, char *parg)
884 {
885 CERT *cert;
886
887 cert=ctx->cert;
888
889 switch (cmd)
890 {
891#ifndef NO_RSA
892 case SSL_CTRL_NEED_TMP_RSA:
893 if ( (cert->rsa_tmp == NULL) &&
894 ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
895 (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))
896 )
897 return(1);
898 else
899 return(0);
900 /* break; */
901 case SSL_CTRL_SET_TMP_RSA:
902 {
903 RSA *rsa;
904 int i;
905
906 rsa=(RSA *)parg;
907 i=1;
908 if (rsa == NULL)
909 i=0;
910 else
911 {
912 if ((rsa=RSAPrivateKey_dup(rsa)) == NULL)
913 i=0;
914 }
915 if (!i)
916 {
917 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB);
918 return(0);
919 }
920 else
921 {
922 if (cert->rsa_tmp != NULL)
923 RSA_free(cert->rsa_tmp);
924 cert->rsa_tmp=rsa;
925 return(1);
926 }
927 }
928 /* break; */
929 case SSL_CTRL_SET_TMP_RSA_CB:
930 {
931 SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
932 return(0);
933 }
934 break;
935#endif
936#ifndef NO_DH
937 case SSL_CTRL_SET_TMP_DH:
938 {
939 DH *new=NULL,*dh;
940
941 dh=(DH *)parg;
942 if ((new=DHparams_dup(dh)) == NULL)
943 {
944 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
945 return 0;
946 }
947 if (!(ctx->options & SSL_OP_SINGLE_DH_USE))
948 {
949 if (!DH_generate_key(new))
950 {
951 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
952 DH_free(new);
953 return 0;
954 }
955 }
956 if (cert->dh_tmp != NULL)
957 DH_free(cert->dh_tmp);
958 cert->dh_tmp=new;
959 return 1;
960 }
961 /*break; */
962 case SSL_CTRL_SET_TMP_DH_CB:
963 {
964 SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
965 return(0);
966 }
967 break;
968#endif
969 /* A Thawte special :-) */
970 case SSL_CTRL_EXTRA_CHAIN_CERT:
971 if (ctx->extra_certs == NULL)
972 {
973 if ((ctx->extra_certs=sk_X509_new_null()) == NULL)
974 return(0);
975 }
976 sk_X509_push(ctx->extra_certs,(X509 *)parg);
977 break;
978
979 default:
980 return(0);
981 }
982 return(1);
983 }
984
985long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
986 {
987 CERT *cert;
988
989 cert=ctx->cert;
990
991 switch (cmd)
992 {
993#ifndef NO_RSA
994 case SSL_CTRL_SET_TMP_RSA_CB:
995 {
996 cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
997 }
998 break;
999#endif
1000#ifndef NO_DH
1001 case SSL_CTRL_SET_TMP_DH_CB:
1002 {
1003 cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
1004 }
1005 break;
1006#endif
1007 default:
1008 return(0);
1009 }
1010 return(1);
1011 }
1012
1013/* This function needs to check if the ciphers required are actually
1014 * available */
1015SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
1016 {
1017 static int init=1;
1018 static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS];
1019 SSL_CIPHER c,*cp= &c,**cpp;
1020 unsigned long id;
1021 int i;
1022
1023 if (init)
1024 {
1025 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
1026
1027 for (i=0; i<SSL3_NUM_CIPHERS; i++)
1028 sorted[i]= &(ssl3_ciphers[i]);
1029
1030 qsort( (char *)sorted,
1031 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
1032 FP_ICC ssl_cipher_ptr_id_cmp);
1033
1034 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
1035
1036 init=0;
1037 }
1038
1039 id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
1040 c.id=id;
1041 cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp,
1042 (char *)sorted,
1043 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
1044 (int (*)())ssl_cipher_ptr_id_cmp);
1045 if ((cpp == NULL) || !(*cpp)->valid)
1046 return(NULL);
1047 else
1048 return(*cpp);
1049 }
1050
1051int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
1052 {
1053 long l;
1054
1055 if (p != NULL)
1056 {
1057 l=c->id;
1058 if ((l & 0xff000000) != 0x03000000) return(0);
1059 p[0]=((unsigned char)(l>> 8L))&0xFF;
1060 p[1]=((unsigned char)(l ))&0xFF;
1061 }
1062 return(2);
1063 }
1064
1065SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *have,
1066 STACK_OF(SSL_CIPHER) *pref)
1067 {
1068 SSL_CIPHER *c,*ret=NULL;
1069 int i,j,ok;
1070 CERT *cert;
1071 unsigned long alg,mask,emask;
1072
1073 /* Let's see which ciphers we can support */
1074 cert=s->cert;
1075
1076 sk_SSL_CIPHER_set_cmp_func(pref,ssl_cipher_ptr_id_cmp);
1077
1078#ifdef CIPHER_DEBUG
1079 printf("Have:\n");
1080 for(i=0 ; i < sk_num(pref) ; ++i)
1081 {
1082 c=(SSL_CIPHER *)sk_value(pref,i);
1083 printf("%p:%s\n",c,c->name);
1084 }
1085#endif
1086
1087 for (i=0; i<sk_SSL_CIPHER_num(have); i++)
1088 {
1089 c=sk_SSL_CIPHER_value(have,i);
1090
1091 ssl_set_cert_masks(cert,c);
1092 mask=cert->mask;
1093 emask=cert->export_mask;
1094
1095 alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1096 if (SSL_C_IS_EXPORT(c))
1097 {
1098 ok=((alg & emask) == alg)?1:0;
1099#ifdef CIPHER_DEBUG
1100 printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask,
1101 c,c->name);
1102#endif
1103 }
1104 else
1105 {
1106 ok=((alg & mask) == alg)?1:0;
1107#ifdef CIPHER_DEBUG
1108 printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c,
1109 c->name);
1110#endif
1111 }
1112
1113 if (!ok) continue;
1114
1115 j=sk_SSL_CIPHER_find(pref,c);
1116 if (j >= 0)
1117 {
1118 ret=sk_SSL_CIPHER_value(pref,j);
1119 break;
1120 }
1121 }
1122 return(ret);
1123 }
1124
1125int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
1126 {
1127 int ret=0;
1128 unsigned long alg;
1129
1130 alg=s->s3->tmp.new_cipher->algorithms;
1131
1132#ifndef NO_DH
1133 if (alg & (SSL_kDHr|SSL_kEDH))
1134 {
1135# ifndef NO_RSA
1136 p[ret++]=SSL3_CT_RSA_FIXED_DH;
1137# endif
1138# ifndef NO_DSA
1139 p[ret++]=SSL3_CT_DSS_FIXED_DH;
1140# endif
1141 }
1142 if ((s->version == SSL3_VERSION) &&
1143 (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
1144 {
1145# ifndef NO_RSA
1146 p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH;
1147# endif
1148# ifndef NO_DSA
1149 p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH;
1150# endif
1151 }
1152#endif /* !NO_DH */
1153#ifndef NO_RSA
1154 p[ret++]=SSL3_CT_RSA_SIGN;
1155#endif
1156#ifndef NO_DSA
1157 p[ret++]=SSL3_CT_DSS_SIGN;
1158#endif
1159 return(ret);
1160 }
1161
1162int ssl3_shutdown(SSL *s)
1163 {
1164
1165 /* Don't do anything much if we have not done the handshake or
1166 * we don't want to send messages :-) */
1167 if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE))
1168 {
1169 s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
1170 return(1);
1171 }
1172
1173 if (!(s->shutdown & SSL_SENT_SHUTDOWN))
1174 {
1175 s->shutdown|=SSL_SENT_SHUTDOWN;
1176#if 1
1177 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY);
1178#endif
1179 /* our shutdown alert has been sent now, and if it still needs
1180 * to be written, s->s3->alert_dispatch will be true */
1181 }
1182 else if (s->s3->alert_dispatch)
1183 {
1184 /* resend it if not sent */
1185#if 1
1186 ssl3_dispatch_alert(s);
1187#endif
1188 }
1189 else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
1190 {
1191 /* If we are waiting for a close from our peer, we are closed */
1192 ssl3_read_bytes(s,0,NULL,0);
1193 }
1194
1195 if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
1196 !s->s3->alert_dispatch)
1197 return(1);
1198 else
1199 return(0);
1200 }
1201
1202int ssl3_write(SSL *s, const void *buf, int len)
1203 {
1204 int ret,n;
1205
1206#if 0
1207 if (s->shutdown & SSL_SEND_SHUTDOWN)
1208 {
1209 s->rwstate=SSL_NOTHING;
1210 return(0);
1211 }
1212#endif
1213 clear_sys_error();
1214 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
1215
1216 /* This is an experimental flag that sends the
1217 * last handshake message in the same packet as the first
1218 * use data - used to see if it helps the TCP protocol during
1219 * session-id reuse */
1220 /* The second test is because the buffer may have been removed */
1221 if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
1222 {
1223 /* First time through, we write into the buffer */
1224 if (s->s3->delay_buf_pop_ret == 0)
1225 {
1226 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
1227 buf,len);
1228 if (ret <= 0) return(ret);
1229
1230 s->s3->delay_buf_pop_ret=ret;
1231 }
1232
1233 s->rwstate=SSL_WRITING;
1234 n=BIO_flush(s->wbio);
1235 if (n <= 0) return(n);
1236 s->rwstate=SSL_NOTHING;
1237
1238 /* We have flushed the buffer, so remove it */
1239 ssl_free_wbio_buffer(s);
1240 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
1241
1242 ret=s->s3->delay_buf_pop_ret;
1243 s->s3->delay_buf_pop_ret=0;
1244 }
1245 else
1246 {
1247 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
1248 buf,len);
1249 if (ret <= 0) return(ret);
1250 }
1251
1252 return(ret);
1253 }
1254
1255int ssl3_read(SSL *s, void *buf, int len)
1256 {
1257 int ret;
1258
1259 clear_sys_error();
1260 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
1261 s->s3->in_read_app_data=1;
1262 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len);
1263 if ((ret == -1) && (s->s3->in_read_app_data == 0))
1264 {
1265 /* ssl3_read_bytes decided to call s->handshake_func, which
1266 * called ssl3_read_bytes to read handshake data.
1267 * However, ssl3_read_bytes actually found application data
1268 * and thinks that application data makes sense here (signalled
1269 * by resetting 'in_read_app_data', strangely); so disable
1270 * handshake processing and try to read application data again. */
1271 s->in_handshake++;
1272 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len);
1273 s->in_handshake--;
1274 }
1275 else
1276 s->s3->in_read_app_data=0;
1277
1278 return(ret);
1279 }
1280
1281int ssl3_peek(SSL *s, char *buf, int len)
1282 {
1283 SSL3_RECORD *rr;
1284 int n;
1285
1286 rr= &(s->s3->rrec);
1287 if ((rr->length == 0) || (rr->type != SSL3_RT_APPLICATION_DATA))
1288 {
1289 n=ssl3_read(s,buf,1);
1290 if (n <= 0) return(n);
1291 rr->length++;
1292 rr->off--;
1293 }
1294
1295 if ((unsigned int)len > rr->length)
1296 n=rr->length;
1297 else
1298 n=len;
1299 memcpy(buf,&(rr->data[rr->off]),(unsigned int)n);
1300 return(n);
1301 }
1302
1303int ssl3_renegotiate(SSL *s)
1304 {
1305 if (s->handshake_func == NULL)
1306 return(1);
1307
1308 if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
1309 return(0);
1310
1311 s->s3->renegotiate=1;
1312 return(1);
1313 }
1314
1315int ssl3_renegotiate_check(SSL *s)
1316 {
1317 int ret=0;
1318
1319 if (s->s3->renegotiate)
1320 {
1321 if ( (s->s3->rbuf.left == 0) &&
1322 (s->s3->wbuf.left == 0) &&
1323 !SSL_in_init(s))
1324 {
1325/*
1326if we are the server, and we have sent a 'RENEGOTIATE' message, we
1327need to go to SSL_ST_ACCEPT.
1328*/
1329 /* SSL_ST_ACCEPT */
1330 s->state=SSL_ST_RENEGOTIATE;
1331 s->s3->renegotiate=0;
1332 s->s3->num_renegotiations++;
1333 s->s3->total_renegotiations++;
1334 ret=1;
1335 }
1336 }
1337 return(ret);
1338 }
1339
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c
deleted file mode 100644
index eb965310d9..0000000000
--- a/src/lib/libssl/s3_pkt.c
+++ /dev/null
@@ -1,1194 +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 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include <errno.h>
114#define USE_SOCKETS
115#include <openssl/evp.h>
116#include <openssl/buffer.h>
117#include "ssl_locl.h"
118
119static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
120 unsigned int len);
121static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
122 unsigned int len);
123static int ssl3_get_record(SSL *s);
124static int do_compress(SSL *ssl);
125static int do_uncompress(SSL *ssl);
126static int do_change_cipher_spec(SSL *ssl);
127
128/* used only by ssl3_get_record */
129static int ssl3_read_n(SSL *s, int n, int max, int extend)
130 {
131 /* If extend == 0, obtain new n-byte packet; if extend == 1, increase
132 * packet by another n bytes.
133 * The packet will be in the sub-array of s->s3->rbuf.buf specified
134 * by s->packet and s->packet_length.
135 * (If s->read_ahead is set, 'max' bytes may be stored in rbuf
136 * [plus s->packet_length bytes if extend == 1].)
137 */
138 int i,off,newb;
139
140 if (!extend)
141 {
142 /* start with empty packet ... */
143 if (s->s3->rbuf.left == 0)
144 s->s3->rbuf.offset = 0;
145 s->packet = s->s3->rbuf.buf + s->s3->rbuf.offset;
146 s->packet_length = 0;
147 /* ... now we can act as if 'extend' was set */
148 }
149
150 /* if there is enough in the buffer from a previous read, take some */
151 if (s->s3->rbuf.left >= (int)n)
152 {
153 s->packet_length+=n;
154 s->s3->rbuf.left-=n;
155 s->s3->rbuf.offset+=n;
156 return(n);
157 }
158
159 /* else we need to read more data */
160 if (!s->read_ahead)
161 max=n;
162
163 {
164 /* avoid buffer overflow */
165 int max_max = SSL3_RT_MAX_PACKET_SIZE - s->packet_length;
166 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
167 max_max += SSL3_RT_MAX_EXTRA;
168 if (max > max_max)
169 max = max_max;
170 }
171 if (n > max) /* does not happen */
172 {
173 SSLerr(SSL_F_SSL3_READ_N,SSL_R_INTERNAL_ERROR);
174 return -1;
175 }
176
177 off = s->packet_length;
178 newb = s->s3->rbuf.left;
179 /* Move any available bytes to front of buffer:
180 * 'off' bytes already pointed to by 'packet',
181 * 'newb' extra ones at the end */
182 if (s->packet != s->s3->rbuf.buf)
183 {
184 /* off > 0 */
185 memmove(s->s3->rbuf.buf, s->packet, off+newb);
186 s->packet = s->s3->rbuf.buf;
187 }
188
189 while (newb < n)
190 {
191 /* Now we have off+newb bytes at the front of s->s3->rbuf.buf and need
192 * to read in more until we have off+n (up to off+max if possible) */
193
194 clear_sys_error();
195 if (s->rbio != NULL)
196 {
197 s->rwstate=SSL_READING;
198 i=BIO_read(s->rbio, &(s->s3->rbuf.buf[off+newb]), max-newb);
199 }
200 else
201 {
202 SSLerr(SSL_F_SSL3_READ_N,SSL_R_READ_BIO_NOT_SET);
203 i = -1;
204 }
205
206 if (i <= 0)
207 {
208 s->s3->rbuf.left = newb;
209 return(i);
210 }
211 newb+=i;
212 }
213
214 /* done reading, now the book-keeping */
215 s->s3->rbuf.offset = off + n;
216 s->s3->rbuf.left = newb - n;
217 s->packet_length += n;
218 s->rwstate=SSL_NOTHING;
219 return(n);
220 }
221
222/* Call this to get a new input record.
223 * It will return <= 0 if more data is needed, normally due to an error
224 * or non-blocking IO.
225 * When it finishes, one packet has been decoded and can be found in
226 * ssl->s3->rrec.type - is the type of record
227 * ssl->s3->rrec.data, - data
228 * ssl->s3->rrec.length, - number of bytes
229 */
230/* used only by ssl3_read_bytes */
231static int ssl3_get_record(SSL *s)
232 {
233 int ssl_major,ssl_minor,al;
234 int n,i,ret= -1;
235 SSL3_RECORD *rr;
236 SSL_SESSION *sess;
237 unsigned char *p;
238 unsigned char md[EVP_MAX_MD_SIZE];
239 short version;
240 unsigned int mac_size;
241 int clear=0,extra;
242
243 rr= &(s->s3->rrec);
244 sess=s->session;
245
246 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
247 extra=SSL3_RT_MAX_EXTRA;
248 else
249 extra=0;
250
251again:
252 /* check if we have the header */
253 if ( (s->rstate != SSL_ST_READ_BODY) ||
254 (s->packet_length < SSL3_RT_HEADER_LENGTH))
255 {
256 n=ssl3_read_n(s,SSL3_RT_HEADER_LENGTH,
257 SSL3_RT_MAX_PACKET_SIZE,0);
258 if (n <= 0) return(n); /* error or non-blocking */
259 s->rstate=SSL_ST_READ_BODY;
260
261 p=s->packet;
262
263 /* Pull apart the header into the SSL3_RECORD */
264 rr->type= *(p++);
265 ssl_major= *(p++);
266 ssl_minor= *(p++);
267 version=(ssl_major<<8)|ssl_minor;
268 n2s(p,rr->length);
269
270 /* Lets check version */
271 if (s->first_packet)
272 {
273 s->first_packet=0;
274 }
275 else
276 {
277 if (version != s->version)
278 {
279 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
280 /* Send back error using their
281 * version number :-) */
282 s->version=version;
283 al=SSL_AD_PROTOCOL_VERSION;
284 goto f_err;
285 }
286 }
287
288 if ((version>>8) != SSL3_VERSION_MAJOR)
289 {
290 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
291 goto err;
292 }
293
294 if (rr->length >
295 (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
296 {
297 al=SSL_AD_RECORD_OVERFLOW;
298 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG);
299 goto f_err;
300 }
301
302 /* now s->rstate == SSL_ST_READ_BODY */
303 }
304
305 /* s->rstate == SSL_ST_READ_BODY, get and decode the data */
306
307 if (rr->length > (s->packet_length-SSL3_RT_HEADER_LENGTH))
308 {
309 /* now s->packet_length == SSL3_RT_HEADER_LENGTH */
310 i=rr->length;
311 n=ssl3_read_n(s,i,i,1);
312 if (n <= 0) return(n); /* error or non-blocking io */
313 /* now n == rr->length,
314 * and s->packet_length == SSL3_RT_HEADER_LENGTH + rr->length */
315 }
316
317 s->rstate=SSL_ST_READ_HEADER; /* set state for later operations */
318
319 /* At this point, s->packet_length == SSL3_RT_HEADER_LNGTH + rr->length,
320 * and we have that many bytes in s->packet
321 */
322 rr->input= &(s->packet[SSL3_RT_HEADER_LENGTH]);
323
324 /* ok, we can now read from 's->packet' data into 'rr'
325 * rr->input points at rr->length bytes, which
326 * need to be copied into rr->data by either
327 * the decryption or by the decompression
328 * When the data is 'copied' into the rr->data buffer,
329 * rr->input will be pointed at the new buffer */
330
331 /* We now have - encrypted [ MAC [ compressed [ plain ] ] ]
332 * rr->length bytes of encrypted compressed stuff. */
333
334 /* check is not needed I believe */
335 if (rr->length > (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
336 {
337 al=SSL_AD_RECORD_OVERFLOW;
338 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG);
339 goto f_err;
340 }
341
342 /* decrypt in place in 'rr->input' */
343 rr->data=rr->input;
344
345 if (!s->method->ssl3_enc->enc(s,0))
346 {
347 al=SSL_AD_DECRYPT_ERROR;
348 goto f_err;
349 }
350#ifdef TLS_DEBUG
351printf("dec %d\n",rr->length);
352{ unsigned int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?' ':'\n'); }
353printf("\n");
354#endif
355 /* r->length is now the compressed data plus mac */
356 if ( (sess == NULL) ||
357 (s->enc_read_ctx == NULL) ||
358 (s->read_hash == NULL))
359 clear=1;
360
361 if (!clear)
362 {
363 mac_size=EVP_MD_size(s->read_hash);
364
365 if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra+mac_size)
366 {
367 al=SSL_AD_RECORD_OVERFLOW;
368 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG);
369 goto f_err;
370 }
371 /* check the MAC for rr->input (it's in mac_size bytes at the tail) */
372 if (rr->length < mac_size)
373 {
374 al=SSL_AD_DECODE_ERROR;
375 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT);
376 goto f_err;
377 }
378 rr->length-=mac_size;
379 i=s->method->ssl3_enc->mac(s,md,0);
380 if (memcmp(md,&(rr->data[rr->length]),mac_size) != 0)
381 {
382 al=SSL_AD_BAD_RECORD_MAC;
383 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_MAC_DECODE);
384 ret= -1;
385 goto f_err;
386 }
387 }
388
389 /* r->length is now just compressed */
390 if (s->expand != NULL)
391 {
392 if (rr->length >
393 (unsigned int)SSL3_RT_MAX_COMPRESSED_LENGTH+extra)
394 {
395 al=SSL_AD_RECORD_OVERFLOW;
396 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG);
397 goto f_err;
398 }
399 if (!do_uncompress(s))
400 {
401 al=SSL_AD_DECOMPRESSION_FAILURE;
402 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION);
403 goto f_err;
404 }
405 }
406
407 if (rr->length > (unsigned int)SSL3_RT_MAX_PLAIN_LENGTH+extra)
408 {
409 al=SSL_AD_RECORD_OVERFLOW;
410 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DATA_LENGTH_TOO_LONG);
411 goto f_err;
412 }
413
414 rr->off=0;
415 /* So at this point the following is true
416 * ssl->s3->rrec.type is the type of record
417 * ssl->s3->rrec.length == number of bytes in record
418 * ssl->s3->rrec.off == offset to first valid byte
419 * ssl->s3->rrec.data == where to take bytes from, increment
420 * after use :-).
421 */
422
423 /* we have pulled in a full packet so zero things */
424 s->packet_length=0;
425
426 /* just read a 0 length packet */
427 if (rr->length == 0) goto again;
428
429 return(1);
430f_err:
431 ssl3_send_alert(s,SSL3_AL_FATAL,al);
432err:
433 return(ret);
434 }
435
436static int do_uncompress(SSL *ssl)
437 {
438 int i;
439 SSL3_RECORD *rr;
440
441 rr= &(ssl->s3->rrec);
442 i=COMP_expand_block(ssl->expand,rr->comp,
443 SSL3_RT_MAX_PLAIN_LENGTH,rr->data,(int)rr->length);
444 if (i < 0)
445 return(0);
446 else
447 rr->length=i;
448 rr->data=rr->comp;
449
450 return(1);
451 }
452
453static int do_compress(SSL *ssl)
454 {
455 int i;
456 SSL3_RECORD *wr;
457
458 wr= &(ssl->s3->wrec);
459 i=COMP_compress_block(ssl->compress,wr->data,
460 SSL3_RT_MAX_COMPRESSED_LENGTH,
461 wr->input,(int)wr->length);
462 if (i < 0)
463 return(0);
464 else
465 wr->length=i;
466
467 wr->input=wr->data;
468 return(1);
469 }
470
471/* Call this to write data in records of type 'type'
472 * It will return <= 0 if not all data has been sent or non-blocking IO.
473 */
474int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
475 {
476 const unsigned char *buf=buf_;
477 unsigned int tot,n,nw;
478 int i;
479
480 s->rwstate=SSL_NOTHING;
481 tot=s->s3->wnum;
482 s->s3->wnum=0;
483
484 if (SSL_in_init(s) && !s->in_handshake)
485 {
486 i=s->handshake_func(s);
487 if (i < 0) return(i);
488 if (i == 0)
489 {
490 SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
491 return(-1);
492 }
493 }
494
495 n=(len-tot);
496 for (;;)
497 {
498 if (n > SSL3_RT_MAX_PLAIN_LENGTH)
499 nw=SSL3_RT_MAX_PLAIN_LENGTH;
500 else
501 nw=n;
502
503 i=do_ssl3_write(s,type,&(buf[tot]),nw);
504 if (i <= 0)
505 {
506 s->s3->wnum=tot;
507 return(i);
508 }
509
510 if ((i == (int)n) ||
511 (type == SSL3_RT_APPLICATION_DATA &&
512 (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE)))
513 {
514 return(tot+i);
515 }
516
517 n-=i;
518 tot+=i;
519 }
520 }
521
522static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
523 unsigned int len)
524 {
525 unsigned char *p,*plen;
526 int i,mac_size,clear=0;
527 SSL3_RECORD *wr;
528 SSL3_BUFFER *wb;
529 SSL_SESSION *sess;
530
531 /* first check is there is a SSL3_RECORD still being written
532 * out. This will happen with non blocking IO */
533 if (s->s3->wbuf.left != 0)
534 return(ssl3_write_pending(s,type,buf,len));
535
536 /* If we have an alert to send, lets send it */
537 if (s->s3->alert_dispatch)
538 {
539 i=ssl3_dispatch_alert(s);
540 if (i <= 0)
541 return(i);
542 /* if it went, fall through and send more stuff */
543 }
544
545 if (len == 0) return(len);
546
547 wr= &(s->s3->wrec);
548 wb= &(s->s3->wbuf);
549 sess=s->session;
550
551 if ( (sess == NULL) ||
552 (s->enc_write_ctx == NULL) ||
553 (s->write_hash == NULL))
554 clear=1;
555
556 if (clear)
557 mac_size=0;
558 else
559 mac_size=EVP_MD_size(s->write_hash);
560
561 p=wb->buf;
562
563 /* write the header */
564 *(p++)=type&0xff;
565 wr->type=type;
566
567 *(p++)=(s->version>>8);
568 *(p++)=s->version&0xff;
569
570 /* record where we are to write out packet length */
571 plen=p;
572 p+=2;
573
574 /* lets setup the record stuff. */
575 wr->data=p;
576 wr->length=(int)len;
577 wr->input=(unsigned char *)buf;
578
579 /* we now 'read' from wr->input, wr->length bytes into
580 * wr->data */
581
582 /* first we compress */
583 if (s->compress != NULL)
584 {
585 if (!do_compress(s))
586 {
587 SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE);
588 goto err;
589 }
590 }
591 else
592 {
593 memcpy(wr->data,wr->input,wr->length);
594 wr->input=wr->data;
595 }
596
597 /* we should still have the output to wr->data and the input
598 * from wr->input. Length should be wr->length.
599 * wr->data still points in the wb->buf */
600
601 if (mac_size != 0)
602 {
603 s->method->ssl3_enc->mac(s,&(p[wr->length]),1);
604 wr->length+=mac_size;
605 wr->input=p;
606 wr->data=p;
607 }
608
609 /* ssl3_enc can only have an error on read */
610 s->method->ssl3_enc->enc(s,1);
611
612 /* record length after mac and block padding */
613 s2n(wr->length,plen);
614
615 /* we should now have
616 * wr->data pointing to the encrypted data, which is
617 * wr->length long */
618 wr->type=type; /* not needed but helps for debugging */
619 wr->length+=SSL3_RT_HEADER_LENGTH;
620
621 /* Now lets setup wb */
622 wb->left=wr->length;
623 wb->offset=0;
624
625 s->s3->wpend_tot=len;
626 s->s3->wpend_buf=buf;
627 s->s3->wpend_type=type;
628 s->s3->wpend_ret=len;
629
630 /* we now just need to write the buffer */
631 return(ssl3_write_pending(s,type,buf,len));
632err:
633 return(-1);
634 }
635
636/* if s->s3->wbuf.left != 0, we need to call this */
637static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
638 unsigned int len)
639 {
640 int i;
641
642/* XXXX */
643 if ((s->s3->wpend_tot > (int)len)
644 || ((s->s3->wpend_buf != buf) &&
645 !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))
646 || (s->s3->wpend_type != type))
647 {
648 SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BAD_WRITE_RETRY);
649 return(-1);
650 }
651
652 for (;;)
653 {
654 clear_sys_error();
655 if (s->wbio != NULL)
656 {
657 s->rwstate=SSL_WRITING;
658 i=BIO_write(s->wbio,
659 (char *)&(s->s3->wbuf.buf[s->s3->wbuf.offset]),
660 (unsigned int)s->s3->wbuf.left);
661 }
662 else
663 {
664 SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BIO_NOT_SET);
665 i= -1;
666 }
667 if (i == s->s3->wbuf.left)
668 {
669 s->s3->wbuf.left=0;
670 s->rwstate=SSL_NOTHING;
671 return(s->s3->wpend_ret);
672 }
673 else if (i <= 0)
674 return(i);
675 s->s3->wbuf.offset+=i;
676 s->s3->wbuf.left-=i;
677 }
678 }
679
680/* Return up to 'len' payload bytes received in 'type' records.
681 * 'type' is one of the following:
682 *
683 * - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
684 * - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us)
685 * - 0 (during a shutdown, no data has to be returned)
686 *
687 * If we don't have stored data to work from, read a SSL/TLS record first
688 * (possibly multiple records if we still don't have anything to return).
689 *
690 * This function must handle any surprises the peer may have for us, such as
691 * Alert records (e.g. close_notify), ChangeCipherSpec records (not really
692 * a surprise, but handled as if it were), or renegotiation requests.
693 * Also if record payloads contain fragments too small to process, we store
694 * them until there is enough for the respective protocol (the record protocol
695 * may use arbitrary fragmentation and even interleaving):
696 * Change cipher spec protocol
697 * just 1 byte needed, no need for keeping anything stored
698 * Alert protocol
699 * 2 bytes needed (AlertLevel, AlertDescription)
700 * Handshake protocol
701 * 4 bytes needed (HandshakeType, uint24 length) -- we just have
702 * to detect unexpected Client Hello and Hello Request messages
703 * here, anything else is handled by higher layers
704 * Application data protocol
705 * none of our business
706 */
707int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len)
708 {
709 int al,i,j,ret;
710 unsigned int n;
711 SSL3_RECORD *rr;
712 void (*cb)()=NULL;
713
714 if (s->s3->rbuf.buf == NULL) /* Not initialized yet */
715 if (!ssl3_setup_buffers(s))
716 return(-1);
717
718 if ((type != SSL3_RT_APPLICATION_DATA) && (type != SSL3_RT_HANDSHAKE) && type)
719 {
720 SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_INTERNAL_ERROR);
721 return -1;
722 }
723
724 if ((type == SSL3_RT_HANDSHAKE) && (s->s3->handshake_fragment_len > 0))
725 /* (partially) satisfy request from storage */
726 {
727 unsigned char *src = s->s3->handshake_fragment;
728 unsigned char *dst = buf;
729 unsigned int k;
730
731 n = 0;
732 while ((len > 0) && (s->s3->handshake_fragment_len > 0))
733 {
734 *dst++ = *src++;
735 len--; s->s3->handshake_fragment_len--;
736 n++;
737 }
738 /* move any remaining fragment bytes: */
739 for (k = 0; k < s->s3->handshake_fragment_len; k++)
740 s->s3->handshake_fragment[k] = *src++;
741 return n;
742 }
743
744 /* Now s->s3->handshake_fragment_len == 0 if type == SSL3_RT_HANDSHAKE. */
745
746 if (!s->in_handshake && SSL_in_init(s))
747 {
748 /* type == SSL3_RT_APPLICATION_DATA */
749 i=s->handshake_func(s);
750 if (i < 0) return(i);
751 if (i == 0)
752 {
753 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
754 return(-1);
755 }
756 }
757start:
758 s->rwstate=SSL_NOTHING;
759
760 /* s->s3->rrec.type - is the type of record
761 * s->s3->rrec.data, - data
762 * s->s3->rrec.off, - offset into 'data' for next read
763 * s->s3->rrec.length, - number of bytes. */
764 rr = &(s->s3->rrec);
765
766 /* get new packet */
767 if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY))
768 {
769 ret=ssl3_get_record(s);
770 if (ret <= 0) return(ret);
771 }
772
773 /* we now have a packet which can be read and processed */
774
775 if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
776 * reset by ssl3_get_finished */
777 && (rr->type != SSL3_RT_HANDSHAKE))
778 {
779 al=SSL_AD_UNEXPECTED_MESSAGE;
780 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED);
781 goto err;
782 }
783
784 /* If the other end has shutdown, throw anything we read away */
785 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
786 {
787 rr->length=0;
788 s->rwstate=SSL_NOTHING;
789 return(0);
790 }
791
792
793 if (type == rr->type) /* SSL3_RT_APPLICATION_DATA or SSL3_RT_HANDSHAKE */
794 {
795 /* make sure that we are not getting application data when we
796 * are doing a handshake for the first time */
797 if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&
798 (s->enc_read_ctx == NULL))
799 {
800 al=SSL_AD_UNEXPECTED_MESSAGE;
801 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE);
802 goto f_err;
803 }
804
805 if (len <= 0) return(len);
806
807 if ((unsigned int)len > rr->length)
808 n = rr->length;
809 else
810 n = (unsigned int)len;
811
812 memcpy(buf,&(rr->data[rr->off]),n);
813 rr->length-=n;
814 rr->off+=n;
815 if (rr->length == 0)
816 {
817 s->rstate=SSL_ST_READ_HEADER;
818 rr->off=0;
819 }
820 return(n);
821 }
822
823
824 /* If we get here, then type != rr->type; if we have a handshake
825 * message, then it was unexpected (Hello Request or Client Hello). */
826
827 /* In case of record types for which we have 'fragment' storage,
828 * fill that so that we can process the data at a fixed place.
829 */
830 {
831 unsigned int dest_maxlen = 0;
832 unsigned char *dest = NULL;
833 unsigned int *dest_len = NULL;
834
835 if (rr->type == SSL3_RT_HANDSHAKE)
836 {
837 dest_maxlen = sizeof s->s3->handshake_fragment;
838 dest = s->s3->handshake_fragment;
839 dest_len = &s->s3->handshake_fragment_len;
840 }
841 else if (rr->type == SSL3_RT_ALERT)
842 {
843 dest_maxlen = sizeof s->s3->alert_fragment;
844 dest = s->s3->alert_fragment;
845 dest_len = &s->s3->alert_fragment_len;
846 }
847
848 if (dest_maxlen > 0)
849 {
850 n = dest_maxlen - *dest_len; /* available space in 'dest' */
851 if (rr->length < n)
852 n = rr->length; /* available bytes */
853
854 /* now move 'n' bytes: */
855 while (n-- > 0)
856 {
857 dest[(*dest_len)++] = rr->data[rr->off++];
858 rr->length--;
859 }
860
861 if (*dest_len < dest_maxlen)
862 goto start; /* fragment was too small */
863 }
864 }
865
866 /* s->s3->handshake_fragment_len == 4 iff rr->type == SSL3_RT_HANDSHAKE;
867 * s->s3->alert_fragment_len == 2 iff rr->type == SSL3_RT_ALERT.
868 * (Possibly rr is 'empty' now, i.e. rr->length may be 0.) */
869
870 /* If we are a client, check for an incoming 'Hello Request': */
871 if ((!s->server) &&
872 (s->s3->handshake_fragment_len >= 4) &&
873 (s->s3->handshake_fragment[0] == SSL3_MT_HELLO_REQUEST) &&
874 (s->session != NULL) && (s->session->cipher != NULL))
875 {
876 s->s3->handshake_fragment_len = 0;
877
878 if ((s->s3->handshake_fragment[1] != 0) ||
879 (s->s3->handshake_fragment[2] != 0) ||
880 (s->s3->handshake_fragment[3] != 0))
881 {
882 al=SSL_AD_DECODE_ERROR;
883 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_HELLO_REQUEST);
884 goto err;
885 }
886
887 if (SSL_is_init_finished(s) &&
888 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&
889 !s->s3->renegotiate)
890 {
891 ssl3_renegotiate(s);
892 if (ssl3_renegotiate_check(s))
893 {
894 i=s->handshake_func(s);
895 if (i < 0) return(i);
896 if (i == 0)
897 {
898 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
899 return(-1);
900 }
901
902 if (s->s3->rbuf.left == 0) /* no read-ahead left? */
903 {
904 BIO *bio;
905 /* In the case where we try to read application data
906 * the first time, but we trigger an SSL handshake, we
907 * return -1 with the retry option set. I do this
908 * otherwise renegotiation can cause nasty problems
909 * in the blocking world */ /* ? */
910 s->rwstate=SSL_READING;
911 bio=SSL_get_rbio(s);
912 BIO_clear_retry_flags(bio);
913 BIO_set_retry_read(bio);
914 return(-1);
915 }
916 }
917 }
918 /* we either finished a handshake or ignored the request,
919 * now try again to obtain the (application) data we were asked for */
920 goto start;
921 }
922
923 if (s->s3->alert_fragment_len >= 2)
924 {
925 int alert_level = s->s3->alert_fragment[0];
926 int alert_descr = s->s3->alert_fragment[1];
927
928 s->s3->alert_fragment_len = 0;
929
930 if (s->info_callback != NULL)
931 cb=s->info_callback;
932 else if (s->ctx->info_callback != NULL)
933 cb=s->ctx->info_callback;
934
935 if (cb != NULL)
936 {
937 j = (alert_level << 8) | alert_descr;
938 cb(s, SSL_CB_READ_ALERT, j);
939 }
940
941 if (alert_level == 1) /* warning */
942 {
943 s->s3->warn_alert = alert_descr;
944 if (alert_descr == SSL_AD_CLOSE_NOTIFY)
945 {
946 s->shutdown |= SSL_RECEIVED_SHUTDOWN;
947 return(0);
948 }
949 }
950 else if (alert_level == 2) /* fatal */
951 {
952 char tmp[16];
953
954 s->rwstate=SSL_NOTHING;
955 s->s3->fatal_alert = alert_descr;
956 SSLerr(SSL_F_SSL3_READ_BYTES, SSL_AD_REASON_OFFSET + alert_descr);
957 sprintf(tmp,"%d",alert_descr);
958 ERR_add_error_data(2,"SSL alert number ",tmp);
959 s->shutdown|=SSL_RECEIVED_SHUTDOWN;
960 SSL_CTX_remove_session(s->ctx,s->session);
961 return(0);
962 }
963 else
964 {
965 al=SSL_AD_ILLEGAL_PARAMETER;
966 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE);
967 goto f_err;
968 }
969
970 goto start;
971 }
972
973 if (s->shutdown & SSL_SENT_SHUTDOWN) /* but we have not received a shutdown */
974 {
975 s->rwstate=SSL_NOTHING;
976 rr->length=0;
977 return(0);
978 }
979
980 if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC)
981 {
982 /* 'Change Cipher Spec' is just a single byte, so we know
983 * exactly what the record payload has to look like */
984 if ( (rr->length != 1) || (rr->off != 0) ||
985 (rr->data[0] != SSL3_MT_CCS))
986 {
987 i=SSL_AD_ILLEGAL_PARAMETER;
988 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC);
989 goto err;
990 }
991
992 rr->length=0;
993 s->s3->change_cipher_spec=1;
994 if (!do_change_cipher_spec(s))
995 goto err;
996 else
997 goto start;
998 }
999
1000 /* Unexpected handshake message (Client Hello, or protocol violation) */
1001 if ((s->s3->handshake_fragment_len >= 4) && !s->in_handshake)
1002 {
1003 if (((s->state&SSL_ST_MASK) == SSL_ST_OK) &&
1004 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS))
1005 {
1006#if 0 /* worked only because C operator preferences are not as expected (and
1007 * because this is not really needed for clients except for detecting
1008 * protocol violations): */
1009 s->state=SSL_ST_BEFORE|(s->server)
1010 ?SSL_ST_ACCEPT
1011 :SSL_ST_CONNECT;
1012#else
1013 s->state = s->server ? SSL_ST_ACCEPT : SSL_ST_CONNECT;
1014#endif
1015 s->new_session=1;
1016 }
1017 i=s->handshake_func(s);
1018 if (i < 0) return(i);
1019 if (i == 0)
1020 {
1021 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
1022 return(-1);
1023 }
1024
1025 if (s->s3->rbuf.left == 0) /* no read-ahead left? */
1026 {
1027 BIO *bio;
1028 /* In the case where we try to read application data
1029 * the first time, but we trigger an SSL handshake, we
1030 * return -1 with the retry option set. I do this
1031 * otherwise renegotiation can cause nasty problems
1032 * in the blocking world */ /* ? */
1033 s->rwstate=SSL_READING;
1034 bio=SSL_get_rbio(s);
1035 BIO_clear_retry_flags(bio);
1036 BIO_set_retry_read(bio);
1037 return(-1);
1038 }
1039 goto start;
1040 }
1041
1042 switch (rr->type)
1043 {
1044 default:
1045#ifndef NO_TLS
1046 /* TLS just ignores unknown message types */
1047 if (s->version == TLS1_VERSION)
1048 {
1049 goto start;
1050 }
1051#endif
1052 al=SSL_AD_UNEXPECTED_MESSAGE;
1053 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
1054 goto f_err;
1055 case SSL3_RT_CHANGE_CIPHER_SPEC:
1056 case SSL3_RT_ALERT:
1057 case SSL3_RT_HANDSHAKE:
1058 /* we already handled all of these, with the possible exception
1059 * of SSL3_RT_HANDSHAKE when s->in_handshake is set, but that
1060 * should not happen when type != rr->type */
1061 al=SSL_AD_UNEXPECTED_MESSAGE;
1062 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_INTERNAL_ERROR);
1063 goto f_err;
1064 case SSL3_RT_APPLICATION_DATA:
1065 /* At this point, we were expecting handshake data,
1066 * but have application data. If the library was
1067 * running inside ssl3_read() (i.e. in_read_app_data
1068 * is set) and it makes sense to read application data
1069 * at this point (session renegotiation not yet started),
1070 * we will indulge it.
1071 */
1072 if (s->s3->in_read_app_data &&
1073 (s->s3->total_renegotiations != 0) &&
1074 ((
1075 (s->state & SSL_ST_CONNECT) &&
1076 (s->state >= SSL3_ST_CW_CLNT_HELLO_A) &&
1077 (s->state <= SSL3_ST_CR_SRVR_HELLO_A)
1078 ) || (
1079 (s->state & SSL_ST_ACCEPT) &&
1080 (s->state <= SSL3_ST_SW_HELLO_REQ_A) &&
1081 (s->state >= SSL3_ST_SR_CLNT_HELLO_A)
1082 )
1083 ))
1084 {
1085 s->s3->in_read_app_data=0;
1086 return(-1);
1087 }
1088 else
1089 {
1090 al=SSL_AD_UNEXPECTED_MESSAGE;
1091 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
1092 goto f_err;
1093 }
1094 }
1095 /* not reached */
1096
1097f_err:
1098 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1099err:
1100 return(-1);
1101 }
1102
1103static int do_change_cipher_spec(SSL *s)
1104 {
1105 int i;
1106 const char *sender;
1107 int slen;
1108
1109 if (s->state & SSL_ST_ACCEPT)
1110 i=SSL3_CHANGE_CIPHER_SERVER_READ;
1111 else
1112 i=SSL3_CHANGE_CIPHER_CLIENT_READ;
1113
1114 if (s->s3->tmp.key_block == NULL)
1115 {
1116 s->session->cipher=s->s3->tmp.new_cipher;
1117 if (!s->method->ssl3_enc->setup_key_block(s)) return(0);
1118 }
1119
1120 if (!s->method->ssl3_enc->change_cipher_state(s,i))
1121 return(0);
1122
1123 /* we have to record the message digest at
1124 * this point so we can get it before we read
1125 * the finished message */
1126 if (s->state & SSL_ST_CONNECT)
1127 {
1128 sender=s->method->ssl3_enc->server_finished_label;
1129 slen=s->method->ssl3_enc->server_finished_label_len;
1130 }
1131 else
1132 {
1133 sender=s->method->ssl3_enc->client_finished_label;
1134 slen=s->method->ssl3_enc->client_finished_label_len;
1135 }
1136
1137 s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
1138 &(s->s3->finish_dgst1),
1139 &(s->s3->finish_dgst2),
1140 sender,slen,s->s3->tmp.peer_finish_md);
1141
1142 return(1);
1143 }
1144
1145void ssl3_send_alert(SSL *s, int level, int desc)
1146 {
1147 /* Map tls/ssl alert value to correct one */
1148 desc=s->method->ssl3_enc->alert_value(desc);
1149 if (desc < 0) return;
1150 /* If a fatal one, remove from cache */
1151 if ((level == 2) && (s->session != NULL))
1152 SSL_CTX_remove_session(s->ctx,s->session);
1153
1154 s->s3->alert_dispatch=1;
1155 s->s3->send_alert[0]=level;
1156 s->s3->send_alert[1]=desc;
1157 if (s->s3->wbuf.left == 0) /* data still being written out */
1158 ssl3_dispatch_alert(s);
1159 /* else data is still being written out, we will get written
1160 * some time in the future */
1161 }
1162
1163int ssl3_dispatch_alert(SSL *s)
1164 {
1165 int i,j;
1166 void (*cb)()=NULL;
1167
1168 s->s3->alert_dispatch=0;
1169 i=do_ssl3_write(s,SSL3_RT_ALERT,&s->s3->send_alert[0],2);
1170 if (i <= 0)
1171 {
1172 s->s3->alert_dispatch=1;
1173 }
1174 else
1175 {
1176 /* If it is important, send it now. If the message
1177 * does not get sent due to non-blocking IO, we will
1178 * not worry too much. */
1179 if (s->s3->send_alert[0] == SSL3_AL_FATAL)
1180 (void)BIO_flush(s->wbio);
1181
1182 if (s->info_callback != NULL)
1183 cb=s->info_callback;
1184 else if (s->ctx->info_callback != NULL)
1185 cb=s->ctx->info_callback;
1186
1187 if (cb != NULL)
1188 {
1189 j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1];
1190 cb(s,SSL_CB_WRITE_ALERT,j);
1191 }
1192 }
1193 return(i);
1194 }
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c
deleted file mode 100644
index e23ca20bd3..0000000000
--- a/src/lib/libssl/s3_srvr.c
+++ /dev/null
@@ -1,1740 +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#define NETSCAPE_HANG_BUG
61
62
63#include <stdio.h>
64#include <openssl/buffer.h>
65#include <openssl/rand.h>
66#include <openssl/objects.h>
67#include <openssl/md5.h>
68#include <openssl/sha.h>
69#include <openssl/evp.h>
70#include <openssl/x509.h>
71#include "ssl_locl.h"
72
73static SSL_METHOD *ssl3_get_server_method(int ver);
74static int ssl3_get_client_hello(SSL *s);
75static int ssl3_check_client_hello(SSL *s);
76static int ssl3_send_server_hello(SSL *s);
77static int ssl3_send_server_key_exchange(SSL *s);
78static int ssl3_send_certificate_request(SSL *s);
79static int ssl3_send_server_done(SSL *s);
80static int ssl3_get_client_key_exchange(SSL *s);
81static int ssl3_get_client_certificate(SSL *s);
82static int ssl3_get_cert_verify(SSL *s);
83static int ssl3_send_hello_request(SSL *s);
84
85static SSL_METHOD *ssl3_get_server_method(int ver)
86 {
87 if (ver == SSL3_VERSION)
88 return(SSLv3_server_method());
89 else
90 return(NULL);
91 }
92
93SSL_METHOD *SSLv3_server_method(void)
94 {
95 static int init=1;
96 static SSL_METHOD SSLv3_server_data;
97
98 if (init)
99 {
100 memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
101 sizeof(SSL_METHOD));
102 SSLv3_server_data.ssl_accept=ssl3_accept;
103 SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
104 init=0;
105 }
106 return(&SSLv3_server_data);
107 }
108
109int ssl3_accept(SSL *s)
110 {
111 BUF_MEM *buf;
112 unsigned long l,Time=time(NULL);
113 void (*cb)()=NULL;
114 long num1;
115 int ret= -1;
116 int new_state,state,skip=0;
117
118 RAND_add(&Time,sizeof(Time),0);
119 ERR_clear_error();
120 clear_sys_error();
121
122 if (s->info_callback != NULL)
123 cb=s->info_callback;
124 else if (s->ctx->info_callback != NULL)
125 cb=s->ctx->info_callback;
126
127 /* init things to blank */
128 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
129 s->in_handshake++;
130
131 if (s->cert == NULL)
132 {
133 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET);
134 return(-1);
135 }
136
137 for (;;)
138 {
139 state=s->state;
140
141 switch (s->state)
142 {
143 case SSL_ST_RENEGOTIATE:
144 s->new_session=1;
145 /* s->state=SSL_ST_ACCEPT; */
146
147 case SSL_ST_BEFORE:
148 case SSL_ST_ACCEPT:
149 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
150 case SSL_ST_OK|SSL_ST_ACCEPT:
151
152 s->server=1;
153 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
154
155 if ((s->version>>8) != 3)
156 abort();
157 s->type=SSL_ST_ACCEPT;
158
159 if (s->init_buf == NULL)
160 {
161 if ((buf=BUF_MEM_new()) == NULL)
162 {
163 ret= -1;
164 goto end;
165 }
166 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
167 {
168 ret= -1;
169 goto end;
170 }
171 s->init_buf=buf;
172 }
173
174 if (!ssl3_setup_buffers(s))
175 {
176 ret= -1;
177 goto end;
178 }
179
180 /* Ok, we now need to push on a buffering BIO so that
181 * the output is sent in a way that TCP likes :-)
182 */
183 if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }
184
185 s->init_num=0;
186
187 if (s->state != SSL_ST_RENEGOTIATE)
188 {
189 ssl3_init_finished_mac(s);
190 s->state=SSL3_ST_SR_CLNT_HELLO_A;
191 s->ctx->stats.sess_accept++;
192 }
193 else
194 {
195 s->ctx->stats.sess_accept_renegotiate++;
196 s->state=SSL3_ST_SW_HELLO_REQ_A;
197 }
198 break;
199
200 case SSL3_ST_SW_HELLO_REQ_A:
201 case SSL3_ST_SW_HELLO_REQ_B:
202
203 s->shutdown=0;
204 ret=ssl3_send_hello_request(s);
205 if (ret <= 0) goto end;
206 s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;
207 s->state=SSL3_ST_SW_FLUSH;
208 s->init_num=0;
209
210 ssl3_init_finished_mac(s);
211 break;
212
213 case SSL3_ST_SW_HELLO_REQ_C:
214 s->state=SSL_ST_OK;
215 ret=1;
216 goto end;
217 /* break; */
218
219 case SSL3_ST_SR_CLNT_HELLO_A:
220 case SSL3_ST_SR_CLNT_HELLO_B:
221 case SSL3_ST_SR_CLNT_HELLO_C:
222
223 s->shutdown=0;
224 ret=ssl3_get_client_hello(s);
225 if (ret <= 0) goto end;
226 s->state=SSL3_ST_SW_SRVR_HELLO_A;
227 s->init_num=0;
228 break;
229
230 case SSL3_ST_SW_SRVR_HELLO_A:
231 case SSL3_ST_SW_SRVR_HELLO_B:
232 ret=ssl3_send_server_hello(s);
233 if (ret <= 0) goto end;
234
235 if (s->hit)
236 s->state=SSL3_ST_SW_CHANGE_A;
237 else
238 s->state=SSL3_ST_SW_CERT_A;
239 s->init_num=0;
240 break;
241
242 case SSL3_ST_SW_CERT_A:
243 case SSL3_ST_SW_CERT_B:
244 /* Check if it is anon DH */
245 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
246 {
247 ret=ssl3_send_server_certificate(s);
248 if (ret <= 0) goto end;
249 }
250 else
251 skip=1;
252 s->state=SSL3_ST_SW_KEY_EXCH_A;
253 s->init_num=0;
254 break;
255
256 case SSL3_ST_SW_KEY_EXCH_A:
257 case SSL3_ST_SW_KEY_EXCH_B:
258 l=s->s3->tmp.new_cipher->algorithms;
259
260 /* clear this, it may get reset by
261 * send_server_key_exchange */
262 if (s->options & SSL_OP_EPHEMERAL_RSA)
263 s->s3->tmp.use_rsa_tmp=1;
264 else
265 s->s3->tmp.use_rsa_tmp=0;
266
267 /* only send if a DH key exchange, fortezza or
268 * RSA but we have a sign only certificate */
269 if (s->s3->tmp.use_rsa_tmp
270 || (l & (SSL_DH|SSL_kFZA))
271 || ((l & SSL_kRSA)
272 && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL
273 || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)
274 && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)
275 )
276 )
277 )
278 )
279 {
280 ret=ssl3_send_server_key_exchange(s);
281 if (ret <= 0) goto end;
282 }
283 else
284 skip=1;
285
286 s->state=SSL3_ST_SW_CERT_REQ_A;
287 s->init_num=0;
288 break;
289
290 case SSL3_ST_SW_CERT_REQ_A:
291 case SSL3_ST_SW_CERT_REQ_B:
292 if (/* don't request cert unless asked for it: */
293 !(s->verify_mode & SSL_VERIFY_PEER) ||
294 /* if SSL_VERIFY_CLIENT_ONCE is set,
295 * don't request cert during re-negotiation: */
296 ((s->session->peer != NULL) &&
297 (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||
298 /* never request cert in anonymous ciphersuites
299 * (see section "Certificate request" in SSL 3 drafts
300 * and in RFC 2246): */
301 ((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) &&
302 /* ... except when the application insists on verification
303 * (against the specs, but s3_clnt.c accepts this for SSL 3) */
304 !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)))
305 {
306 /* no cert request */
307 skip=1;
308 s->s3->tmp.cert_request=0;
309 s->state=SSL3_ST_SW_SRVR_DONE_A;
310 }
311 else
312 {
313 s->s3->tmp.cert_request=1;
314 ret=ssl3_send_certificate_request(s);
315 if (ret <= 0) goto end;
316#ifndef NETSCAPE_HANG_BUG
317 s->state=SSL3_ST_SW_SRVR_DONE_A;
318#else
319 s->state=SSL3_ST_SW_FLUSH;
320 s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
321#endif
322 s->init_num=0;
323 }
324 break;
325
326 case SSL3_ST_SW_SRVR_DONE_A:
327 case SSL3_ST_SW_SRVR_DONE_B:
328 ret=ssl3_send_server_done(s);
329 if (ret <= 0) goto end;
330 s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
331 s->state=SSL3_ST_SW_FLUSH;
332 s->init_num=0;
333 break;
334
335 case SSL3_ST_SW_FLUSH:
336 /* number of bytes to be flushed */
337 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
338 if (num1 > 0)
339 {
340 s->rwstate=SSL_WRITING;
341 num1=BIO_flush(s->wbio);
342 if (num1 <= 0) { ret= -1; goto end; }
343 s->rwstate=SSL_NOTHING;
344 }
345
346 s->state=s->s3->tmp.next_state;
347 break;
348
349 case SSL3_ST_SR_CERT_A:
350 case SSL3_ST_SR_CERT_B:
351 /* Check for second client hello (MS SGC) */
352 ret = ssl3_check_client_hello(s);
353 if (ret <= 0)
354 goto end;
355 if (ret == 2)
356 s->state = SSL3_ST_SR_CLNT_HELLO_C;
357 else {
358 /* could be sent for a DH cert, even if we
359 * have not asked for it :-) */
360 ret=ssl3_get_client_certificate(s);
361 if (ret <= 0) goto end;
362 s->init_num=0;
363 s->state=SSL3_ST_SR_KEY_EXCH_A;
364 }
365 break;
366
367 case SSL3_ST_SR_KEY_EXCH_A:
368 case SSL3_ST_SR_KEY_EXCH_B:
369 ret=ssl3_get_client_key_exchange(s);
370 if (ret <= 0) goto end;
371 s->state=SSL3_ST_SR_CERT_VRFY_A;
372 s->init_num=0;
373
374 /* We need to get hashes here so if there is
375 * a client cert, it can be verified */
376 s->method->ssl3_enc->cert_verify_mac(s,
377 &(s->s3->finish_dgst1),
378 &(s->s3->tmp.cert_verify_md[0]));
379 s->method->ssl3_enc->cert_verify_mac(s,
380 &(s->s3->finish_dgst2),
381 &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));
382
383 break;
384
385 case SSL3_ST_SR_CERT_VRFY_A:
386 case SSL3_ST_SR_CERT_VRFY_B:
387
388 /* we should decide if we expected this one */
389 ret=ssl3_get_cert_verify(s);
390 if (ret <= 0) goto end;
391
392 s->state=SSL3_ST_SR_FINISHED_A;
393 s->init_num=0;
394 break;
395
396 case SSL3_ST_SR_FINISHED_A:
397 case SSL3_ST_SR_FINISHED_B:
398 ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
399 SSL3_ST_SR_FINISHED_B);
400 if (ret <= 0) goto end;
401 if (s->hit)
402 s->state=SSL_ST_OK;
403 else
404 s->state=SSL3_ST_SW_CHANGE_A;
405 s->init_num=0;
406 break;
407
408 case SSL3_ST_SW_CHANGE_A:
409 case SSL3_ST_SW_CHANGE_B:
410
411 s->session->cipher=s->s3->tmp.new_cipher;
412 if (!s->method->ssl3_enc->setup_key_block(s))
413 { ret= -1; goto end; }
414
415 ret=ssl3_send_change_cipher_spec(s,
416 SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);
417
418 if (ret <= 0) goto end;
419 s->state=SSL3_ST_SW_FINISHED_A;
420 s->init_num=0;
421
422 if (!s->method->ssl3_enc->change_cipher_state(s,
423 SSL3_CHANGE_CIPHER_SERVER_WRITE))
424 {
425 ret= -1;
426 goto end;
427 }
428
429 break;
430
431 case SSL3_ST_SW_FINISHED_A:
432 case SSL3_ST_SW_FINISHED_B:
433 ret=ssl3_send_finished(s,
434 SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,
435 s->method->ssl3_enc->server_finished_label,
436 s->method->ssl3_enc->server_finished_label_len);
437 if (ret <= 0) goto end;
438 s->state=SSL3_ST_SW_FLUSH;
439 if (s->hit)
440 s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
441 else
442 s->s3->tmp.next_state=SSL_ST_OK;
443 s->init_num=0;
444 break;
445
446 case SSL_ST_OK:
447 /* clean a few things up */
448 ssl3_cleanup_key_block(s);
449
450 BUF_MEM_free(s->init_buf);
451 s->init_buf=NULL;
452
453 /* remove buffering on output */
454 ssl_free_wbio_buffer(s);
455
456 s->new_session=0;
457 s->init_num=0;
458
459 ssl_update_cache(s,SSL_SESS_CACHE_SERVER);
460
461 s->ctx->stats.sess_accept_good++;
462 /* s->server=1; */
463 s->handshake_func=ssl3_accept;
464 ret=1;
465
466 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
467
468 goto end;
469 /* break; */
470
471 default:
472 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE);
473 ret= -1;
474 goto end;
475 /* break; */
476 }
477
478 if (!s->s3->tmp.reuse_message && !skip)
479 {
480 if (s->debug)
481 {
482 if ((ret=BIO_flush(s->wbio)) <= 0)
483 goto end;
484 }
485
486
487 if ((cb != NULL) && (s->state != state))
488 {
489 new_state=s->state;
490 s->state=state;
491 cb(s,SSL_CB_ACCEPT_LOOP,1);
492 s->state=new_state;
493 }
494 }
495 skip=0;
496 }
497end:
498 /* BIO_flush(s->wbio); */
499
500 if (cb != NULL)
501 cb(s,SSL_CB_ACCEPT_EXIT,ret);
502 s->in_handshake--;
503 return(ret);
504 }
505
506static int ssl3_send_hello_request(SSL *s)
507 {
508 unsigned char *p;
509
510 if (s->state == SSL3_ST_SW_HELLO_REQ_A)
511 {
512 p=(unsigned char *)s->init_buf->data;
513 *(p++)=SSL3_MT_HELLO_REQUEST;
514 *(p++)=0;
515 *(p++)=0;
516 *(p++)=0;
517
518 s->state=SSL3_ST_SW_HELLO_REQ_B;
519 /* number of bytes to write */
520 s->init_num=4;
521 s->init_off=0;
522 }
523
524 /* SSL3_ST_SW_HELLO_REQ_B */
525 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
526 }
527
528static int ssl3_check_client_hello(SSL *s)
529 {
530 int ok;
531 long n;
532
533 n=ssl3_get_message(s,
534 SSL3_ST_SR_CERT_A,
535 SSL3_ST_SR_CERT_B,
536 -1,
537 SSL3_RT_MAX_PLAIN_LENGTH,
538 &ok);
539 if (!ok) return((int)n);
540 s->s3->tmp.reuse_message = 1;
541 if (s->s3->tmp.message_type == SSL3_MT_CLIENT_HELLO)
542 {
543 /* Throw away what we have done so far in the current handshake,
544 * which will now be aborted. (A full SSL_clear would be too much.)
545 * I hope that tmp.dh is the only thing that may need to be cleared
546 * when a handshake is not completed ... */
547#ifndef NO_DH
548 if (s->s3->tmp.dh != NULL)
549 {
550 DH_free(s->s3->tmp.dh);
551 s->s3->tmp.dh = NULL;
552 }
553#endif
554 return 2;
555 }
556 return 1;
557}
558
559static int ssl3_get_client_hello(SSL *s)
560 {
561 int i,j,ok,al,ret= -1;
562 long n;
563 unsigned long id;
564 unsigned char *p,*d,*q;
565 SSL_CIPHER *c;
566 SSL_COMP *comp=NULL;
567 STACK_OF(SSL_CIPHER) *ciphers=NULL;
568
569 /* We do this so that we will respond with our native type.
570 * If we are TLSv1 and we get SSLv3, we will respond with TLSv1,
571 * This down switching should be handled by a different method.
572 * If we are SSLv3, we will respond with SSLv3, even if prompted with
573 * TLSv1.
574 */
575 if (s->state == SSL3_ST_SR_CLNT_HELLO_A)
576 {
577 s->first_packet=1;
578 s->state=SSL3_ST_SR_CLNT_HELLO_B;
579 }
580 n=ssl3_get_message(s,
581 SSL3_ST_SR_CLNT_HELLO_B,
582 SSL3_ST_SR_CLNT_HELLO_C,
583 SSL3_MT_CLIENT_HELLO,
584 SSL3_RT_MAX_PLAIN_LENGTH,
585 &ok);
586
587 if (!ok) return((int)n);
588 d=p=(unsigned char *)s->init_buf->data;
589
590 /* use version from inside client hello, not from record header
591 * (may differ: see RFC 2246, Appendix E, second paragraph) */
592 s->client_version=(((int)p[0])<<8)|(int)p[1];
593 p+=2;
594
595 /* load the client random */
596 memcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);
597 p+=SSL3_RANDOM_SIZE;
598
599 /* get the session-id */
600 j= *(p++);
601
602 s->hit=0;
603 if (j == 0)
604 {
605 if (!ssl_get_new_session(s,1))
606 goto err;
607 }
608 else
609 {
610 i=ssl_get_prev_session(s,p,j);
611 if (i == 1)
612 { /* previous session */
613 s->hit=1;
614 }
615 else if (i == -1)
616 goto err;
617 else /* i == 0 */
618 {
619 if (!ssl_get_new_session(s,1))
620 goto err;
621 }
622 }
623
624 p+=j;
625 n2s(p,i);
626 if ((i == 0) && (j != 0))
627 {
628 /* we need a cipher if we are not resuming a session */
629 al=SSL_AD_ILLEGAL_PARAMETER;
630 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);
631 goto f_err;
632 }
633 if ((i+p) > (d+n))
634 {
635 /* not enough data */
636 al=SSL_AD_DECODE_ERROR;
637 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
638 goto f_err;
639 }
640 if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))
641 == NULL))
642 {
643 goto err;
644 }
645 p+=i;
646
647 /* If it is a hit, check that the cipher is in the list */
648 if ((s->hit) && (i > 0))
649 {
650 j=0;
651 id=s->session->cipher->id;
652
653#ifdef CIPHER_DEBUG
654 printf("client sent %d ciphers\n",sk_num(ciphers));
655#endif
656 for (i=0; i<sk_SSL_CIPHER_num(ciphers); i++)
657 {
658 c=sk_SSL_CIPHER_value(ciphers,i);
659#ifdef CIPHER_DEBUG
660 printf("client [%2d of %2d]:%s\n",
661 i,sk_num(ciphers),SSL_CIPHER_get_name(c));
662#endif
663 if (c->id == id)
664 {
665 j=1;
666 break;
667 }
668 }
669 if (j == 0)
670 {
671 if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1))
672 {
673 /* Very bad for multi-threading.... */
674 s->session->cipher=sk_SSL_CIPHER_value(ciphers,
675 0);
676 }
677 else
678 {
679 /* we need to have the cipher in the cipher
680 * list if we are asked to reuse it */
681 al=SSL_AD_ILLEGAL_PARAMETER;
682 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);
683 goto f_err;
684 }
685 }
686 }
687
688 /* compression */
689 i= *(p++);
690 q=p;
691 for (j=0; j<i; j++)
692 {
693 if (p[j] == 0) break;
694 }
695
696 p+=i;
697 if (j >= i)
698 {
699 /* no compress */
700 al=SSL_AD_DECODE_ERROR;
701 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);
702 goto f_err;
703 }
704
705 /* Worst case, we will use the NULL compression, but if we have other
706 * options, we will now look for them. We have i-1 compression
707 * algorithms from the client, starting at q. */
708 s->s3->tmp.new_compression=NULL;
709 if (s->ctx->comp_methods != NULL)
710 { /* See if we have a match */
711 int m,nn,o,v,done=0;
712
713 nn=sk_SSL_COMP_num(s->ctx->comp_methods);
714 for (m=0; m<nn; m++)
715 {
716 comp=sk_SSL_COMP_value(s->ctx->comp_methods,m);
717 v=comp->id;
718 for (o=0; o<i; o++)
719 {
720 if (v == q[o])
721 {
722 done=1;
723 break;
724 }
725 }
726 if (done) break;
727 }
728 if (done)
729 s->s3->tmp.new_compression=comp;
730 else
731 comp=NULL;
732 }
733
734 /* TLS does not mind if there is extra stuff */
735 if (s->version == SSL3_VERSION)
736 {
737 if (p > (d+n))
738 {
739 /* wrong number of bytes,
740 * there could be more to follow */
741 al=SSL_AD_DECODE_ERROR;
742 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
743 goto f_err;
744 }
745 }
746
747 /* Given s->session->ciphers and ssl_get_ciphers_by_id(s), we must
748 * pick a cipher */
749
750 if (!s->hit)
751 {
752 s->session->compress_meth=(comp == NULL)?0:comp->id;
753 if (s->session->ciphers != NULL)
754 sk_SSL_CIPHER_free(s->session->ciphers);
755 s->session->ciphers=ciphers;
756 if (ciphers == NULL)
757 {
758 al=SSL_AD_ILLEGAL_PARAMETER;
759 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);
760 goto f_err;
761 }
762 ciphers=NULL;
763 c=ssl3_choose_cipher(s,s->session->ciphers,
764 ssl_get_ciphers_by_id(s));
765
766 if (c == NULL)
767 {
768 al=SSL_AD_HANDSHAKE_FAILURE;
769 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
770 goto f_err;
771 }
772 s->s3->tmp.new_cipher=c;
773 }
774 else
775 {
776 /* Session-id reuse */
777#ifdef REUSE_CIPHER_BUG
778 STACK_OF(SSL_CIPHER) *sk;
779 SSL_CIPHER *nc=NULL;
780 SSL_CIPHER *ec=NULL;
781
782 if (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
783 {
784 sk=s->session->ciphers;
785 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
786 {
787 c=sk_SSL_CIPHER_value(sk,i);
788 if (c->algorithms & SSL_eNULL)
789 nc=c;
790 if (SSL_C_IS_EXPORT(c))
791 ec=c;
792 }
793 if (nc != NULL)
794 s->s3->tmp.new_cipher=nc;
795 else if (ec != NULL)
796 s->s3->tmp.new_cipher=ec;
797 else
798 s->s3->tmp.new_cipher=s->session->cipher;
799 }
800 else
801#endif
802 s->s3->tmp.new_cipher=s->session->cipher;
803 }
804
805 /* we now have the following setup.
806 * client_random
807 * cipher_list - our prefered list of ciphers
808 * ciphers - the clients prefered list of ciphers
809 * compression - basically ignored right now
810 * ssl version is set - sslv3
811 * s->session - The ssl session has been setup.
812 * s->hit - session reuse flag
813 * s->tmp.new_cipher - the new cipher to use.
814 */
815
816 ret=1;
817 if (0)
818 {
819f_err:
820 ssl3_send_alert(s,SSL3_AL_FATAL,al);
821 }
822err:
823 if (ciphers != NULL) sk_SSL_CIPHER_free(ciphers);
824 return(ret);
825 }
826
827static int ssl3_send_server_hello(SSL *s)
828 {
829 unsigned char *buf;
830 unsigned char *p,*d;
831 int i,sl;
832 unsigned long l,Time;
833
834 if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
835 {
836 buf=(unsigned char *)s->init_buf->data;
837 p=s->s3->server_random;
838 Time=time(NULL); /* Time */
839 l2n(Time,p);
840 RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time));
841 /* Do the message type and length last */
842 d=p= &(buf[4]);
843
844 *(p++)=s->version>>8;
845 *(p++)=s->version&0xff;
846
847 /* Random stuff */
848 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
849 p+=SSL3_RANDOM_SIZE;
850
851 /* now in theory we have 3 options to sending back the
852 * session id. If it is a re-use, we send back the
853 * old session-id, if it is a new session, we send
854 * back the new session-id or we send back a 0 length
855 * session-id if we want it to be single use.
856 * Currently I will not implement the '0' length session-id
857 * 12-Jan-98 - I'll now support the '0' length stuff.
858 */
859 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER))
860 s->session->session_id_length=0;
861
862 sl=s->session->session_id_length;
863 *(p++)=sl;
864 memcpy(p,s->session->session_id,sl);
865 p+=sl;
866
867 /* put the cipher */
868 i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p);
869 p+=i;
870
871 /* put the compression method */
872 if (s->s3->tmp.new_compression == NULL)
873 *(p++)=0;
874 else
875 *(p++)=s->s3->tmp.new_compression->id;
876
877 /* do the header */
878 l=(p-d);
879 d=buf;
880 *(d++)=SSL3_MT_SERVER_HELLO;
881 l2n3(l,d);
882
883 s->state=SSL3_ST_CW_CLNT_HELLO_B;
884 /* number of bytes to write */
885 s->init_num=p-buf;
886 s->init_off=0;
887 }
888
889 /* SSL3_ST_CW_CLNT_HELLO_B */
890 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
891 }
892
893static int ssl3_send_server_done(SSL *s)
894 {
895 unsigned char *p;
896
897 if (s->state == SSL3_ST_SW_SRVR_DONE_A)
898 {
899 p=(unsigned char *)s->init_buf->data;
900
901 /* do the header */
902 *(p++)=SSL3_MT_SERVER_DONE;
903 *(p++)=0;
904 *(p++)=0;
905 *(p++)=0;
906
907 s->state=SSL3_ST_SW_SRVR_DONE_B;
908 /* number of bytes to write */
909 s->init_num=4;
910 s->init_off=0;
911 }
912
913 /* SSL3_ST_CW_CLNT_HELLO_B */
914 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
915 }
916
917static int ssl3_send_server_key_exchange(SSL *s)
918 {
919#ifndef NO_RSA
920 unsigned char *q;
921 int j,num;
922 RSA *rsa;
923 unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
924 unsigned int u;
925#endif
926#ifndef NO_DH
927 DH *dh=NULL,*dhp;
928#endif
929 EVP_PKEY *pkey;
930 unsigned char *p,*d;
931 int al,i;
932 unsigned long type;
933 int n;
934 CERT *cert;
935 BIGNUM *r[4];
936 int nr[4],kn;
937 BUF_MEM *buf;
938 EVP_MD_CTX md_ctx;
939
940 if (s->state == SSL3_ST_SW_KEY_EXCH_A)
941 {
942 type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK;
943 cert=s->cert;
944
945 buf=s->init_buf;
946
947 r[0]=r[1]=r[2]=r[3]=NULL;
948 n=0;
949#ifndef NO_RSA
950 if (type & SSL_kRSA)
951 {
952 rsa=cert->rsa_tmp;
953 if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL))
954 {
955 rsa=s->cert->rsa_tmp_cb(s,
956 SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
957 SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
958 if(rsa == NULL)
959 {
960 al=SSL_AD_HANDSHAKE_FAILURE;
961 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_ERROR_GENERATING_TMP_RSA_KEY);
962 goto f_err;
963 }
964 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
965 cert->rsa_tmp=rsa;
966 }
967 if (rsa == NULL)
968 {
969 al=SSL_AD_HANDSHAKE_FAILURE;
970 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY);
971 goto f_err;
972 }
973 r[0]=rsa->n;
974 r[1]=rsa->e;
975 s->s3->tmp.use_rsa_tmp=1;
976 }
977 else
978#endif
979#ifndef NO_DH
980 if (type & SSL_kEDH)
981 {
982 dhp=cert->dh_tmp;
983 if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL))
984 dhp=s->cert->dh_tmp_cb(s,
985 !SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
986 SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
987 if (dhp == NULL)
988 {
989 al=SSL_AD_HANDSHAKE_FAILURE;
990 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
991 goto f_err;
992 }
993
994 if (s->s3->tmp.dh != NULL)
995 {
996 DH_free(dh);
997 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, SSL_R_INTERNAL_ERROR);
998 goto err;
999 }
1000
1001 if ((dh=DHparams_dup(dhp)) == NULL)
1002 {
1003 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
1004 goto err;
1005 }
1006
1007 s->s3->tmp.dh=dh;
1008 if ((dhp->pub_key == NULL ||
1009 dhp->priv_key == NULL ||
1010 (s->options & SSL_OP_SINGLE_DH_USE)))
1011 {
1012 if(!DH_generate_key(dh))
1013 {
1014 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
1015 ERR_R_DH_LIB);
1016 goto err;
1017 }
1018 }
1019 else
1020 {
1021 dh->pub_key=BN_dup(dhp->pub_key);
1022 dh->priv_key=BN_dup(dhp->priv_key);
1023 if ((dh->pub_key == NULL) ||
1024 (dh->priv_key == NULL))
1025 {
1026 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
1027 goto err;
1028 }
1029 }
1030 r[0]=dh->p;
1031 r[1]=dh->g;
1032 r[2]=dh->pub_key;
1033 }
1034 else
1035#endif
1036 {
1037 al=SSL_AD_HANDSHAKE_FAILURE;
1038 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1039 goto f_err;
1040 }
1041 for (i=0; r[i] != NULL; i++)
1042 {
1043 nr[i]=BN_num_bytes(r[i]);
1044 n+=2+nr[i];
1045 }
1046
1047 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
1048 {
1049 if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher))
1050 == NULL)
1051 {
1052 al=SSL_AD_DECODE_ERROR;
1053 goto f_err;
1054 }
1055 kn=EVP_PKEY_size(pkey);
1056 }
1057 else
1058 {
1059 pkey=NULL;
1060 kn=0;
1061 }
1062
1063 if (!BUF_MEM_grow(buf,n+4+kn))
1064 {
1065 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF);
1066 goto err;
1067 }
1068 d=(unsigned char *)s->init_buf->data;
1069 p= &(d[4]);
1070
1071 for (i=0; r[i] != NULL; i++)
1072 {
1073 s2n(nr[i],p);
1074 BN_bn2bin(r[i],p);
1075 p+=nr[i];
1076 }
1077
1078 /* not anonymous */
1079 if (pkey != NULL)
1080 {
1081 /* n is the length of the params, they start at &(d[4])
1082 * and p points to the space at the end. */
1083#ifndef NO_RSA
1084 if (pkey->type == EVP_PKEY_RSA)
1085 {
1086 q=md_buf;
1087 j=0;
1088 for (num=2; num > 0; num--)
1089 {
1090 EVP_DigestInit(&md_ctx,(num == 2)
1091 ?s->ctx->md5:s->ctx->sha1);
1092 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1093 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1094 EVP_DigestUpdate(&md_ctx,&(d[4]),n);
1095 EVP_DigestFinal(&md_ctx,q,
1096 (unsigned int *)&i);
1097 q+=i;
1098 j+=i;
1099 }
1100 if (RSA_sign(NID_md5_sha1, md_buf, j,
1101 &(p[2]), &u, pkey->pkey.rsa) <= 0)
1102 {
1103 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA);
1104 goto err;
1105 }
1106 s2n(u,p);
1107 n+=u+2;
1108 }
1109 else
1110#endif
1111#if !defined(NO_DSA)
1112 if (pkey->type == EVP_PKEY_DSA)
1113 {
1114 /* lets do DSS */
1115 EVP_SignInit(&md_ctx,EVP_dss1());
1116 EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1117 EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1118 EVP_SignUpdate(&md_ctx,&(d[4]),n);
1119 if (!EVP_SignFinal(&md_ctx,&(p[2]),
1120 (unsigned int *)&i,pkey))
1121 {
1122 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA);
1123 goto err;
1124 }
1125 s2n(i,p);
1126 n+=i+2;
1127 }
1128 else
1129#endif
1130 {
1131 /* Is this error check actually needed? */
1132 al=SSL_AD_HANDSHAKE_FAILURE;
1133 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE);
1134 goto f_err;
1135 }
1136 }
1137
1138 *(d++)=SSL3_MT_SERVER_KEY_EXCHANGE;
1139 l2n3(n,d);
1140
1141 /* we should now have things packed up, so lets send
1142 * it off */
1143 s->init_num=n+4;
1144 s->init_off=0;
1145 }
1146
1147 s->state = SSL3_ST_SW_KEY_EXCH_B;
1148 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1149f_err:
1150 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1151err:
1152 return(-1);
1153 }
1154
1155static int ssl3_send_certificate_request(SSL *s)
1156 {
1157 unsigned char *p,*d;
1158 int i,j,nl,off,n;
1159 STACK_OF(X509_NAME) *sk=NULL;
1160 X509_NAME *name;
1161 BUF_MEM *buf;
1162
1163 if (s->state == SSL3_ST_SW_CERT_REQ_A)
1164 {
1165 buf=s->init_buf;
1166
1167 d=p=(unsigned char *)&(buf->data[4]);
1168
1169 /* get the list of acceptable cert types */
1170 p++;
1171 n=ssl3_get_req_cert_type(s,p);
1172 d[0]=n;
1173 p+=n;
1174 n++;
1175
1176 off=n;
1177 p+=2;
1178 n+=2;
1179
1180 sk=SSL_get_client_CA_list(s);
1181 nl=0;
1182 if (sk != NULL)
1183 {
1184 for (i=0; i<sk_X509_NAME_num(sk); i++)
1185 {
1186 name=sk_X509_NAME_value(sk,i);
1187 j=i2d_X509_NAME(name,NULL);
1188 if (!BUF_MEM_grow(buf,4+n+j+2))
1189 {
1190 SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB);
1191 goto err;
1192 }
1193 p=(unsigned char *)&(buf->data[4+n]);
1194 if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1195 {
1196 s2n(j,p);
1197 i2d_X509_NAME(name,&p);
1198 n+=2+j;
1199 nl+=2+j;
1200 }
1201 else
1202 {
1203 d=p;
1204 i2d_X509_NAME(name,&p);
1205 j-=2; s2n(j,d); j+=2;
1206 n+=j;
1207 nl+=j;
1208 }
1209 }
1210 }
1211 /* else no CA names */
1212 p=(unsigned char *)&(buf->data[4+off]);
1213 s2n(nl,p);
1214
1215 d=(unsigned char *)buf->data;
1216 *(d++)=SSL3_MT_CERTIFICATE_REQUEST;
1217 l2n3(n,d);
1218
1219 /* we should now have things packed up, so lets send
1220 * it off */
1221
1222 s->init_num=n+4;
1223 s->init_off=0;
1224#ifdef NETSCAPE_HANG_BUG
1225 p=(unsigned char *)s->init_buf->data + s->init_num;
1226
1227 /* do the header */
1228 *(p++)=SSL3_MT_SERVER_DONE;
1229 *(p++)=0;
1230 *(p++)=0;
1231 *(p++)=0;
1232 s->init_num += 4;
1233#endif
1234
1235 }
1236
1237 /* SSL3_ST_SW_CERT_REQ_B */
1238 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1239err:
1240 return(-1);
1241 }
1242
1243static int ssl3_get_client_key_exchange(SSL *s)
1244 {
1245 int i,al,ok;
1246 long n;
1247 unsigned long l;
1248 unsigned char *p;
1249#ifndef NO_RSA
1250 RSA *rsa=NULL;
1251 EVP_PKEY *pkey=NULL;
1252#endif
1253#ifndef NO_DH
1254 BIGNUM *pub=NULL;
1255 DH *dh_srvr;
1256#endif
1257
1258 n=ssl3_get_message(s,
1259 SSL3_ST_SR_KEY_EXCH_A,
1260 SSL3_ST_SR_KEY_EXCH_B,
1261 SSL3_MT_CLIENT_KEY_EXCHANGE,
1262 400, /* ???? */
1263 &ok);
1264
1265 if (!ok) return((int)n);
1266 p=(unsigned char *)s->init_buf->data;
1267
1268 l=s->s3->tmp.new_cipher->algorithms;
1269
1270#ifndef NO_RSA
1271 if (l & SSL_kRSA)
1272 {
1273 /* FIX THIS UP EAY EAY EAY EAY */
1274 if (s->s3->tmp.use_rsa_tmp)
1275 {
1276 if ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))
1277 rsa=s->cert->rsa_tmp;
1278 /* Don't do a callback because rsa_tmp should
1279 * be sent already */
1280 if (rsa == NULL)
1281 {
1282 al=SSL_AD_HANDSHAKE_FAILURE;
1283 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);
1284 goto f_err;
1285
1286 }
1287 }
1288 else
1289 {
1290 pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;
1291 if ( (pkey == NULL) ||
1292 (pkey->type != EVP_PKEY_RSA) ||
1293 (pkey->pkey.rsa == NULL))
1294 {
1295 al=SSL_AD_HANDSHAKE_FAILURE;
1296 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);
1297 goto f_err;
1298 }
1299 rsa=pkey->pkey.rsa;
1300 }
1301
1302 /* TLS */
1303 if (s->version > SSL3_VERSION)
1304 {
1305 n2s(p,i);
1306 if (n != i+2)
1307 {
1308 if (!(s->options & SSL_OP_TLS_D5_BUG))
1309 {
1310 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);
1311 goto err;
1312 }
1313 else
1314 p-=2;
1315 }
1316 else
1317 n=i;
1318 }
1319
1320 i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);
1321
1322 if (i != SSL_MAX_MASTER_KEY_LENGTH)
1323 {
1324 al=SSL_AD_DECODE_ERROR;
1325 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1326 goto f_err;
1327 }
1328
1329 if ((p[0] != (s->client_version>>8)) || (p[1] != (s->client_version & 0xff)))
1330 {
1331 al=SSL_AD_DECODE_ERROR;
1332 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER);
1333 goto f_err;
1334 }
1335
1336 s->session->master_key_length=
1337 s->method->ssl3_enc->generate_master_secret(s,
1338 s->session->master_key,
1339 p,i);
1340 memset(p,0,i);
1341 }
1342 else
1343#endif
1344#ifndef NO_DH
1345 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1346 {
1347 n2s(p,i);
1348 if (n != i+2)
1349 {
1350 if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))
1351 {
1352 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);
1353 goto err;
1354 }
1355 else
1356 {
1357 p-=2;
1358 i=(int)n;
1359 }
1360 }
1361
1362 if (n == 0L) /* the parameters are in the cert */
1363 {
1364 al=SSL_AD_HANDSHAKE_FAILURE;
1365 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);
1366 goto f_err;
1367 }
1368 else
1369 {
1370 if (s->s3->tmp.dh == NULL)
1371 {
1372 al=SSL_AD_HANDSHAKE_FAILURE;
1373 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
1374 goto f_err;
1375 }
1376 else
1377 dh_srvr=s->s3->tmp.dh;
1378 }
1379
1380 pub=BN_bin2bn(p,i,NULL);
1381 if (pub == NULL)
1382 {
1383 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);
1384 goto err;
1385 }
1386
1387 i=DH_compute_key(p,pub,dh_srvr);
1388
1389 if (i <= 0)
1390 {
1391 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1392 goto err;
1393 }
1394
1395 DH_free(s->s3->tmp.dh);
1396 s->s3->tmp.dh=NULL;
1397
1398 BN_clear_free(pub);
1399 pub=NULL;
1400 s->session->master_key_length=
1401 s->method->ssl3_enc->generate_master_secret(s,
1402 s->session->master_key,p,i);
1403 }
1404 else
1405#endif
1406 {
1407 al=SSL_AD_HANDSHAKE_FAILURE;
1408 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNKNOWN_CIPHER_TYPE);
1409 goto f_err;
1410 }
1411
1412 return(1);
1413f_err:
1414 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1415#if !defined(NO_DH) || !defined(NO_RSA)
1416err:
1417#endif
1418 return(-1);
1419 }
1420
1421static int ssl3_get_cert_verify(SSL *s)
1422 {
1423 EVP_PKEY *pkey=NULL;
1424 unsigned char *p;
1425 int al,ok,ret=0;
1426 long n;
1427 int type=0,i,j;
1428 X509 *peer;
1429
1430 n=ssl3_get_message(s,
1431 SSL3_ST_SR_CERT_VRFY_A,
1432 SSL3_ST_SR_CERT_VRFY_B,
1433 -1,
1434 512, /* 512? */
1435 &ok);
1436
1437 if (!ok) return((int)n);
1438
1439 if (s->session->peer != NULL)
1440 {
1441 peer=s->session->peer;
1442 pkey=X509_get_pubkey(peer);
1443 type=X509_certificate_type(peer,pkey);
1444 }
1445 else
1446 {
1447 peer=NULL;
1448 pkey=NULL;
1449 }
1450
1451 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY)
1452 {
1453 s->s3->tmp.reuse_message=1;
1454 if ((peer != NULL) && (type | EVP_PKT_SIGN))
1455 {
1456 al=SSL_AD_UNEXPECTED_MESSAGE;
1457 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_MISSING_VERIFY_MESSAGE);
1458 goto f_err;
1459 }
1460 ret=1;
1461 goto end;
1462 }
1463
1464 if (peer == NULL)
1465 {
1466 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_NO_CLIENT_CERT_RECEIVED);
1467 al=SSL_AD_UNEXPECTED_MESSAGE;
1468 goto f_err;
1469 }
1470
1471 if (!(type & EVP_PKT_SIGN))
1472 {
1473 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);
1474 al=SSL_AD_ILLEGAL_PARAMETER;
1475 goto f_err;
1476 }
1477
1478 if (s->s3->change_cipher_spec)
1479 {
1480 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY);
1481 al=SSL_AD_UNEXPECTED_MESSAGE;
1482 goto f_err;
1483 }
1484
1485 /* we now have a signature that we need to verify */
1486 p=(unsigned char *)s->init_buf->data;
1487 n2s(p,i);
1488 n-=2;
1489 if (i > n)
1490 {
1491 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH);
1492 al=SSL_AD_DECODE_ERROR;
1493 goto f_err;
1494 }
1495
1496 j=EVP_PKEY_size(pkey);
1497 if ((i > j) || (n > j) || (n <= 0))
1498 {
1499 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_WRONG_SIGNATURE_SIZE);
1500 al=SSL_AD_DECODE_ERROR;
1501 goto f_err;
1502 }
1503
1504#ifndef NO_RSA
1505 if (pkey->type == EVP_PKEY_RSA)
1506 {
1507 i=RSA_verify(NID_md5_sha1, s->s3->tmp.cert_verify_md,
1508 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, p, i,
1509 pkey->pkey.rsa);
1510 if (i < 0)
1511 {
1512 al=SSL_AD_DECRYPT_ERROR;
1513 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_DECRYPT);
1514 goto f_err;
1515 }
1516 if (i == 0)
1517 {
1518 al=SSL_AD_DECRYPT_ERROR;
1519 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_SIGNATURE);
1520 goto f_err;
1521 }
1522 }
1523 else
1524#endif
1525#ifndef NO_DSA
1526 if (pkey->type == EVP_PKEY_DSA)
1527 {
1528 j=DSA_verify(pkey->save_type,
1529 &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]),
1530 SHA_DIGEST_LENGTH,p,i,pkey->pkey.dsa);
1531 if (j <= 0)
1532 {
1533 /* bad signature */
1534 al=SSL_AD_DECRYPT_ERROR;
1535 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_DSA_SIGNATURE);
1536 goto f_err;
1537 }
1538 }
1539 else
1540#endif
1541 {
1542 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_INTERNAL_ERROR);
1543 al=SSL_AD_UNSUPPORTED_CERTIFICATE;
1544 goto f_err;
1545 }
1546
1547
1548 ret=1;
1549 if (0)
1550 {
1551f_err:
1552 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1553 }
1554end:
1555 EVP_PKEY_free(pkey);
1556 return(ret);
1557 }
1558
1559static int ssl3_get_client_certificate(SSL *s)
1560 {
1561 int i,ok,al,ret= -1;
1562 X509 *x=NULL;
1563 unsigned long l,nc,llen,n;
1564 unsigned char *p,*d,*q;
1565 STACK_OF(X509) *sk=NULL;
1566
1567 n=ssl3_get_message(s,
1568 SSL3_ST_SR_CERT_A,
1569 SSL3_ST_SR_CERT_B,
1570 -1,
1571#if defined(MSDOS) && !defined(WIN32)
1572 1024*30, /* 30k max cert list :-) */
1573#else
1574 1024*100, /* 100k max cert list :-) */
1575#endif
1576 &ok);
1577
1578 if (!ok) return((int)n);
1579
1580 if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE)
1581 {
1582 if ( (s->verify_mode & SSL_VERIFY_PEER) &&
1583 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1584 {
1585 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1586 al=SSL_AD_HANDSHAKE_FAILURE;
1587 goto f_err;
1588 }
1589 /* If tls asked for a client cert, the client must return a 0 list */
1590 if ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request)
1591 {
1592 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST);
1593 al=SSL_AD_UNEXPECTED_MESSAGE;
1594 goto f_err;
1595 }
1596 s->s3->tmp.reuse_message=1;
1597 return(1);
1598 }
1599
1600 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
1601 {
1602 al=SSL_AD_UNEXPECTED_MESSAGE;
1603 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE);
1604 goto f_err;
1605 }
1606 d=p=(unsigned char *)s->init_buf->data;
1607
1608 if ((sk=sk_X509_new_null()) == NULL)
1609 {
1610 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1611 goto err;
1612 }
1613
1614 n2l3(p,llen);
1615 if (llen+3 != n)
1616 {
1617 al=SSL_AD_DECODE_ERROR;
1618 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
1619 goto f_err;
1620 }
1621 for (nc=0; nc<llen; )
1622 {
1623 n2l3(p,l);
1624 if ((l+nc+3) > llen)
1625 {
1626 al=SSL_AD_DECODE_ERROR;
1627 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1628 goto f_err;
1629 }
1630
1631 q=p;
1632 x=d2i_X509(NULL,&p,l);
1633 if (x == NULL)
1634 {
1635 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB);
1636 goto err;
1637 }
1638 if (p != (q+l))
1639 {
1640 al=SSL_AD_DECODE_ERROR;
1641 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1642 goto f_err;
1643 }
1644 if (!sk_X509_push(sk,x))
1645 {
1646 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1647 goto err;
1648 }
1649 x=NULL;
1650 nc+=l+3;
1651 }
1652
1653 if (sk_X509_num(sk) <= 0)
1654 {
1655 /* TLS does not mind 0 certs returned */
1656 if (s->version == SSL3_VERSION)
1657 {
1658 al=SSL_AD_HANDSHAKE_FAILURE;
1659 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED);
1660 goto f_err;
1661 }
1662 /* Fail for TLS only if we required a certificate */
1663 else if ((s->verify_mode & SSL_VERIFY_PEER) &&
1664 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1665 {
1666 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1667 al=SSL_AD_HANDSHAKE_FAILURE;
1668 goto f_err;
1669 }
1670 }
1671 else
1672 {
1673 i=ssl_verify_cert_chain(s,sk);
1674 if (!i)
1675 {
1676 al=ssl_verify_alarm_type(s->verify_result);
1677 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED);
1678 goto f_err;
1679 }
1680 }
1681
1682 if (s->session->peer != NULL) /* This should not be needed */
1683 X509_free(s->session->peer);
1684 s->session->peer=sk_X509_shift(sk);
1685 s->session->verify_result = s->verify_result;
1686
1687 /* With the current implementation, sess_cert will always be NULL
1688 * when we arrive here. */
1689 if (s->session->sess_cert == NULL)
1690 {
1691 s->session->sess_cert = ssl_sess_cert_new();
1692 if (s->session->sess_cert == NULL)
1693 {
1694 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE, ERR_R_MALLOC_FAILURE);
1695 goto err;
1696 }
1697 }
1698 if (s->session->sess_cert->cert_chain != NULL)
1699 sk_X509_pop_free(s->session->sess_cert->cert_chain, X509_free);
1700 s->session->sess_cert->cert_chain=sk;
1701 /* Inconsistency alert: cert_chain does *not* include the
1702 * peer's own certificate, while we do include it in s3_clnt.c */
1703
1704 sk=NULL;
1705
1706 ret=1;
1707 if (0)
1708 {
1709f_err:
1710 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1711 }
1712err:
1713 if (x != NULL) X509_free(x);
1714 if (sk != NULL) sk_X509_pop_free(sk,X509_free);
1715 return(ret);
1716 }
1717
1718int ssl3_send_server_certificate(SSL *s)
1719 {
1720 unsigned long l;
1721 X509 *x;
1722
1723 if (s->state == SSL3_ST_SW_CERT_A)
1724 {
1725 x=ssl_get_server_send_cert(s);
1726 if (x == NULL)
1727 {
1728 SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,SSL_R_INTERNAL_ERROR);
1729 return(0);
1730 }
1731
1732 l=ssl3_output_cert_chain(s,x);
1733 s->state=SSL3_ST_SW_CERT_B;
1734 s->init_num=(int)l;
1735 s->init_off=0;
1736 }
1737
1738 /* SSL3_ST_SW_CERT_B */
1739 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1740 }
diff --git a/src/lib/libssl/shlib_version b/src/lib/libssl/shlib_version
deleted file mode 100644
index c87e1c60d4..0000000000
--- a/src/lib/libssl/shlib_version
+++ /dev/null
@@ -1,2 +0,0 @@
1major=2
2minor=4
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
deleted file mode 100644
index bb846f491c..0000000000
--- a/src/lib/libssl/ssl.h
+++ /dev/null
@@ -1,1533 +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_EXP "EXP"
127#define SSL_TXT_EXPORT "EXPORT"
128#define SSL_TXT_EXP40 "EXPORT40"
129#define SSL_TXT_EXP56 "EXPORT56"
130#define SSL_TXT_SSLV2 "SSLv2"
131#define SSL_TXT_SSLV3 "SSLv3"
132#define SSL_TXT_TLSV1 "TLSv1"
133#define SSL_TXT_ALL "ALL"
134
135/* 'DEFAULT' at the start of the cipher list insert the following string
136 * in addition to this being the default cipher string */
137#define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH"
138
139/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
140#define SSL_SENT_SHUTDOWN 1
141#define SSL_RECEIVED_SHUTDOWN 2
142
143#include <openssl/crypto.h>
144#include <openssl/lhash.h>
145#include <openssl/buffer.h>
146#include <openssl/bio.h>
147#include <openssl/pem.h>
148#include <openssl/x509.h>
149
150#if (defined(NO_RSA) || defined(NO_MD5)) && !defined(NO_SSL2)
151#define NO_SSL2
152#endif
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 algo_strength; /* strength and export flags */
170 unsigned long algorithm2; /* Extra flags */
171 int strength_bits; /* Number of bits really used */
172 int alg_bits; /* Number of bits for algorithm */
173 unsigned long mask; /* used for matching */
174 unsigned long mask_strength; /* also used for matching */
175 } SSL_CIPHER;
176
177DECLARE_STACK_OF(SSL_CIPHER)
178
179typedef struct ssl_st SSL;
180typedef struct ssl_ctx_st SSL_CTX;
181
182/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
183typedef struct ssl_method_st
184 {
185 int version;
186 int (*ssl_new)(SSL *s);
187 void (*ssl_clear)(SSL *s);
188 void (*ssl_free)(SSL *s);
189 int (*ssl_accept)(SSL *s);
190 int (*ssl_connect)(SSL *s);
191 int (*ssl_read)(SSL *s,void *buf,int len);
192 int (*ssl_peek)(SSL *s,char *buf,int len);
193 int (*ssl_write)(SSL *s,const void *buf,int len);
194 int (*ssl_shutdown)(SSL *s);
195 int (*ssl_renegotiate)(SSL *s);
196 int (*ssl_renegotiate_check)(SSL *s);
197 long (*ssl_ctrl)(SSL *s,int cmd,long larg,char *parg);
198 long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,char *parg);
199 SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
200 int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr);
201 int (*ssl_pending)(SSL *s);
202 int (*num_ciphers)(void);
203 SSL_CIPHER *(*get_cipher)(unsigned ncipher);
204 struct ssl_method_st *(*get_ssl_method)(int version);
205 long (*get_timeout)(void);
206 struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
207 int (*ssl_version)();
208 long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)());
209 long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)());
210 } SSL_METHOD;
211
212/* Lets make this into an ASN.1 type structure as follows
213 * SSL_SESSION_ID ::= SEQUENCE {
214 * version INTEGER, -- structure version number
215 * SSLversion INTEGER, -- SSL version number
216 * Cipher OCTET_STRING, -- the 3 byte cipher ID
217 * Session_ID OCTET_STRING, -- the Session ID
218 * Master_key OCTET_STRING, -- the master key
219 * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument
220 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
221 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
222 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
223 * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context
224 * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer'
225 * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX
226 * }
227 * Look in ssl/ssl_asn1.c for more details
228 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
229 */
230typedef struct ssl_session_st
231 {
232 int ssl_version; /* what ssl version session info is
233 * being kept in here? */
234
235 /* only really used in SSLv2 */
236 unsigned int key_arg_length;
237 unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];
238 int master_key_length;
239 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
240 /* session_id - valid? */
241 unsigned int session_id_length;
242 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
243 /* this is used to determine whether the session is being reused in
244 * the appropriate context. It is up to the application to set this,
245 * via SSL_new */
246 unsigned int sid_ctx_length;
247 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
248
249 int not_resumable;
250
251 /* The cert is the certificate used to establish this connection */
252 struct sess_cert_st /* SESS_CERT */ *sess_cert;
253
254 /* This is the cert for the other end.
255 * On clients, it will be the same as sess_cert->peer_key->x509
256 * (the latter is not enough as sess_cert is not retained
257 * in the external representation of sessions, see ssl_asn1.c). */
258 X509 *peer;
259 /* when app_verify_callback accepts a session where the peer's certificate
260 * is not ok, we must remember the error for session reuse: */
261 long verify_result; /* only for servers */
262
263 int references;
264 long timeout;
265 long time;
266
267 int compress_meth; /* Need to lookup the method */
268
269 SSL_CIPHER *cipher;
270 unsigned long cipher_id; /* when ASN.1 loaded, this
271 * needs to be used to load
272 * the 'cipher' structure */
273
274 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
275
276 CRYPTO_EX_DATA ex_data; /* application specific data */
277
278 /* These are used to make removal of session-ids more
279 * efficient and to implement a maximum cache size. */
280 struct ssl_session_st *prev,*next;
281 } SSL_SESSION;
282
283#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L
284#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L
285#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L
286#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L
287#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L
288#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L
289#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L
290#define SSL_OP_TLS_D5_BUG 0x00000100L
291#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L
292#define SSL_OP_TLS_ROLLBACK_BUG 0x00000400L
293
294/* If set, always create a new key when using tmp_dh parameters */
295#define SSL_OP_SINGLE_DH_USE 0x00100000L
296/* Set to also use the tmp_rsa key when doing RSA operations. */
297#define SSL_OP_EPHEMERAL_RSA 0x00200000L
298
299/* The next flag deliberately changes the ciphertest, this is a check
300 * for the PKCS#1 attack */
301#define SSL_OP_PKCS1_CHECK_1 0x08000000L
302#define SSL_OP_PKCS1_CHECK_2 0x10000000L
303#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L
304/* SSL_OP_NON_EXPORT_FIRST looks utterly broken .. */
305#define SSL_OP_NON_EXPORT_FIRST 0x40000000L
306#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000L
307#define SSL_OP_ALL 0x000FFFFFL
308
309#define SSL_OP_NO_SSLv2 0x01000000L
310#define SSL_OP_NO_SSLv3 0x02000000L
311#define SSL_OP_NO_TLSv1 0x04000000L
312
313/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
314 * when just a single record has been written): */
315#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
316/* Make it possible to retry SSL_write() with changed buffer location
317 * (buffer contents must stay the same!); this is not the default to avoid
318 * the misconception that non-blocking SSL_write() behaves like
319 * non-blocking write(): */
320#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
321
322/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
323 * they cannot be used to clear bits. */
324
325#define SSL_CTX_set_options(ctx,op) \
326 SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,op,NULL)
327#define SSL_CTX_get_options(ctx) \
328 SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,0,NULL)
329#define SSL_set_options(ssl,op) \
330 SSL_ctrl(ssl,SSL_CTRL_OPTIONS,op,NULL)
331#define SSL_get_options(ssl) \
332 SSL_ctrl(ssl,SSL_CTRL_OPTIONS,0,NULL)
333
334#define SSL_CTX_set_mode(ctx,op) \
335 SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,op,NULL)
336#define SSL_CTX_get_mode(ctx) \
337 SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,0,NULL)
338#define SSL_set_mode(ssl,op) \
339 SSL_ctrl(ssl,SSL_CTRL_MODE,op,NULL)
340#define SSL_get_mode(ssl) \
341 SSL_ctrl(ssl,SSL_CTRL_MODE,0,NULL)
342
343#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
344
345typedef struct ssl_comp_st
346{
347 int id;
348 char *name;
349#ifdef HEADER_COMP_H
350 COMP_METHOD *method;
351#else
352 char *method;
353#endif
354} SSL_COMP;
355
356DECLARE_STACK_OF(SSL_COMP)
357
358struct ssl_ctx_st
359 {
360 SSL_METHOD *method;
361 unsigned long options;
362 unsigned long mode;
363
364 STACK_OF(SSL_CIPHER) *cipher_list;
365 /* same as above but sorted for lookup */
366 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
367
368 struct x509_store_st /* X509_STORE */ *cert_store;
369 struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */
370 /* Most session-ids that will be cached, default is
371 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
372 unsigned long session_cache_size;
373 struct ssl_session_st *session_cache_head;
374 struct ssl_session_st *session_cache_tail;
375
376 /* This can have one of 2 values, ored together,
377 * SSL_SESS_CACHE_CLIENT,
378 * SSL_SESS_CACHE_SERVER,
379 * Default is SSL_SESSION_CACHE_SERVER, which means only
380 * SSL_accept which cache SSL_SESSIONS. */
381 int session_cache_mode;
382
383 /* If timeout is not 0, it is the default timeout value set
384 * when SSL_new() is called. This has been put in to make
385 * life easier to set things up */
386 long session_timeout;
387
388 /* If this callback is not null, it will be called each
389 * time a session id is added to the cache. If this function
390 * returns 1, it means that the callback will do a
391 * SSL_SESSION_free() when it has finished using it. Otherwise,
392 * on 0, it means the callback has finished with it.
393 * If remove_session_cb is not null, it will be called when
394 * a session-id is removed from the cache. After the call,
395 * OpenSSL will SSL_SESSION_free() it. */
396 int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);
397 void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);
398 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
399 unsigned char *data,int len,int *copy);
400 struct
401 {
402 int sess_connect; /* SSL new conn - started */
403 int sess_connect_renegotiate;/* SSL reneg - requested */
404 int sess_connect_good; /* SSL new conne/reneg - finished */
405 int sess_accept; /* SSL new accept - started */
406 int sess_accept_renegotiate;/* SSL reneg - requested */
407 int sess_accept_good; /* SSL accept/reneg - finished */
408 int sess_miss; /* session lookup misses */
409 int sess_timeout; /* reuse attempt on timeouted session */
410 int sess_cache_full; /* session removed due to full cache */
411 int sess_hit; /* session reuse actually done */
412 int sess_cb_hit; /* session-id that was not
413 * in the cache was
414 * passed back via the callback. This
415 * indicates that the application is
416 * supplying session-id's from other
417 * processes - spooky :-) */
418 } stats;
419
420 int references;
421
422/**/ void (*info_callback)();
423
424 /* if defined, these override the X509_verify_cert() calls */
425/**/ int (*app_verify_callback)();
426/**/ char *app_verify_arg; /* never used; should be void * */
427
428 /* default values to use in SSL structures */
429/**/ struct cert_st /* CERT */ *cert;
430/**/ int read_ahead;
431/**/ int verify_mode;
432/**/ int verify_depth;
433/**/ unsigned int sid_ctx_length;
434/**/ unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
435/**/ int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx);
436
437 int purpose; /* Purpose setting */
438 int trust; /* Trust setting */
439
440 /* Default password callback. */
441/**/ pem_password_cb *default_passwd_callback;
442
443 /* Default password callback user data. */
444/**/ void *default_passwd_callback_userdata;
445
446 /* get client cert callback */
447/**/ int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */);
448
449 /* what we put in client cert requests */
450 STACK_OF(X509_NAME) *client_CA;
451
452/**/ int quiet_shutdown;
453
454 CRYPTO_EX_DATA ex_data;
455
456 const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */
457 const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
458 const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */
459
460 STACK_OF(X509) *extra_certs;
461 STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */
462 };
463
464#define SSL_SESS_CACHE_OFF 0x0000
465#define SSL_SESS_CACHE_CLIENT 0x0001
466#define SSL_SESS_CACHE_SERVER 0x0002
467#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
468#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
469/* This one, when set, makes the server session-id lookup not look
470 * in the cache. If there is an application get_session callback
471 * defined, this will still get called. */
472#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
473
474 struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);
475#define SSL_CTX_sess_number(ctx) \
476 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
477#define SSL_CTX_sess_connect(ctx) \
478 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
479#define SSL_CTX_sess_connect_good(ctx) \
480 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
481#define SSL_CTX_sess_connect_renegotiate(ctx) \
482 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
483#define SSL_CTX_sess_accept(ctx) \
484 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
485#define SSL_CTX_sess_accept_renegotiate(ctx) \
486 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
487#define SSL_CTX_sess_accept_good(ctx) \
488 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
489#define SSL_CTX_sess_hits(ctx) \
490 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
491#define SSL_CTX_sess_cb_hits(ctx) \
492 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
493#define SSL_CTX_sess_misses(ctx) \
494 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
495#define SSL_CTX_sess_timeouts(ctx) \
496 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
497#define SSL_CTX_sess_cache_full(ctx) \
498 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)
499
500#define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))
501#define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb)
502#define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb))
503#define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)
504#define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))
505#define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb)
506#define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb))
507#define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback)
508#define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb))
509#define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb)
510
511#define SSL_NOTHING 1
512#define SSL_WRITING 2
513#define SSL_READING 3
514#define SSL_X509_LOOKUP 4
515
516/* These will only be used when doing non-blocking IO */
517#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)
518#define SSL_want_read(s) (SSL_want(s) == SSL_READING)
519#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)
520#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)
521
522struct ssl_st
523 {
524 /* protocol version
525 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION)
526 */
527 int version;
528 int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
529
530 SSL_METHOD *method; /* SSLv3 */
531
532 /* There are 2 BIO's even though they are normally both the
533 * same. This is so data can be read and written to different
534 * handlers */
535
536#ifdef HEADER_BIO_H
537 BIO *rbio; /* used by SSL_read */
538 BIO *wbio; /* used by SSL_write */
539 BIO *bbio; /* used during session-id reuse to concatinate
540 * messages */
541#else
542 char *rbio; /* used by SSL_read */
543 char *wbio; /* used by SSL_write */
544 char *bbio;
545#endif
546 /* This holds a variable that indicates what we were doing
547 * when a 0 or -1 is returned. This is needed for
548 * non-blocking IO so we know what request needs re-doing when
549 * in SSL_accept or SSL_connect */
550 int rwstate;
551
552 /* true when we are actually in SSL_accept() or SSL_connect() */
553 int in_handshake;
554 int (*handshake_func)();
555
556 /* Imagine that here's a boolean member "init" that is
557 * switched as soon as SSL_set_{accept/connect}_state
558 * is called for the first time, so that "state" and
559 * "handshake_func" are properly initialized. But as
560 * handshake_func is == 0 until then, we use this
561 * test instead of an "init" member.
562 */
563
564 int server; /* are we the server side? - mostly used by SSL_clear*/
565
566 int new_session;/* 1 if we are to use a new session */
567 int quiet_shutdown;/* don't send shutdown packets */
568 int shutdown; /* we have shut things down, 0x01 sent, 0x02
569 * for received */
570 int state; /* where we are */
571 int rstate; /* where we are when reading */
572
573 BUF_MEM *init_buf; /* buffer used during init */
574 int init_num; /* amount read/written */
575 int init_off; /* amount read/written */
576
577 /* used internally to point at a raw packet */
578 unsigned char *packet;
579 unsigned int packet_length;
580
581 struct ssl2_state_st *s2; /* SSLv2 variables */
582 struct ssl3_state_st *s3; /* SSLv3 variables */
583
584 int read_ahead; /* Read as many input bytes as possible
585 * (for non-blocking reads) */
586 int hit; /* reusing a previous session */
587
588 int purpose; /* Purpose setting */
589 int trust; /* Trust setting */
590
591 /* crypto */
592 STACK_OF(SSL_CIPHER) *cipher_list;
593 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
594
595 /* These are the ones being used, the ones in SSL_SESSION are
596 * the ones to be 'copied' into these ones */
597
598 EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
599 const EVP_MD *read_hash; /* used for mac generation */
600#ifdef HEADER_COMP_H
601 COMP_CTX *expand; /* uncompress */
602#else
603 char *expand;
604#endif
605
606 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
607 const EVP_MD *write_hash; /* used for mac generation */
608#ifdef HEADER_COMP_H
609 COMP_CTX *compress; /* compression */
610#else
611 char *compress;
612#endif
613
614 /* session info */
615
616 /* client cert? */
617 /* This is used to hold the server certificate used */
618 struct cert_st /* CERT */ *cert;
619
620 /* the session_id_context is used to ensure sessions are only reused
621 * in the appropriate context */
622 unsigned int sid_ctx_length;
623 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
624
625 /* This can also be in the session once a session is established */
626 SSL_SESSION *session;
627
628 /* Used in SSL2 and SSL3 */
629 int verify_mode; /* 0 don't care about verify failure.
630 * 1 fail if verify fails */
631 int verify_depth;
632 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
633 void (*info_callback)(); /* optional informational callback */
634
635 int error; /* error bytes to be written */
636 int error_code; /* actual code */
637
638 SSL_CTX *ctx;
639 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
640 * and SSL_write() calls, good for nbio debuging :-) */
641 int debug;
642
643 /* extra application data */
644 long verify_result;
645 CRYPTO_EX_DATA ex_data;
646
647 /* for server side, keep the list of CA_dn we can use */
648 STACK_OF(X509_NAME) *client_CA;
649
650 int references;
651 unsigned long options; /* protocol behaviour */
652 unsigned long mode; /* API behaviour */
653 int first_packet;
654 int client_version; /* what was passed, used for
655 * SSLv3/TLS rollback check */
656 };
657
658#include <openssl/ssl2.h>
659#include <openssl/ssl3.h>
660#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */
661#include <openssl/ssl23.h>
662
663/* compatibility */
664#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
665#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
666#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
667#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
668#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
669#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
670
671/* The following are the possible values for ssl->state are are
672 * used to indicate where we are up to in the SSL connection establishment.
673 * The macros that follow are about the only things you should need to use
674 * and even then, only when using non-blocking IO.
675 * It can also be useful to work out where you were when the connection
676 * failed */
677
678#define SSL_ST_CONNECT 0x1000
679#define SSL_ST_ACCEPT 0x2000
680#define SSL_ST_MASK 0x0FFF
681#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
682#define SSL_ST_BEFORE 0x4000
683#define SSL_ST_OK 0x03
684#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
685
686#define SSL_CB_LOOP 0x01
687#define SSL_CB_EXIT 0x02
688#define SSL_CB_READ 0x04
689#define SSL_CB_WRITE 0x08
690#define SSL_CB_ALERT 0x4000 /* used in callback */
691#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
692#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
693#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
694#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
695#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
696#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
697#define SSL_CB_HANDSHAKE_START 0x10
698#define SSL_CB_HANDSHAKE_DONE 0x20
699
700/* Is the SSL_connection established? */
701#define SSL_get_state(a) SSL_state(a)
702#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)
703#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)
704#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)
705#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)
706#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
707
708/* The following 2 states are kept in ssl->rstate when reads fail,
709 * you should not need these */
710#define SSL_ST_READ_HEADER 0xF0
711#define SSL_ST_READ_BODY 0xF1
712#define SSL_ST_READ_DONE 0xF2
713
714/* Obtain latest Finished message
715 * -- that we sent (SSL_get_finished)
716 * -- that we expected from peer (SSL_get_peer_finished).
717 * Returns length (0 == no Finished so far), copies up to 'count' bytes. */
718size_t SSL_get_finished(SSL *s, void *buf, size_t count);
719size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count);
720
721/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
722 * are 'ored' with SSL_VERIFY_PEER if they are desired */
723#define SSL_VERIFY_NONE 0x00
724#define SSL_VERIFY_PEER 0x01
725#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
726#define SSL_VERIFY_CLIENT_ONCE 0x04
727
728#define OpenSSL_add_ssl_algorithms() SSL_library_init()
729#define SSLeay_add_ssl_algorithms() SSL_library_init()
730
731/* this is for backward compatibility */
732#if 0 /* NEW_SSLEAY */
733#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)
734#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n)
735#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b))
736#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b))
737#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b))
738#endif
739/* More backward compatibility */
740#define SSL_get_cipher(s) \
741 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
742#define SSL_get_cipher_bits(s,np) \
743 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
744#define SSL_get_cipher_version(s) \
745 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
746#define SSL_get_cipher_name(s) \
747 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
748#define SSL_get_time(a) SSL_SESSION_get_time(a)
749#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
750#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
751#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
752
753#if 1 /*SSLEAY_MACROS*/
754#define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
755 (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
756 (bp),(unsigned char **)(s_id))
757#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \
758 bp,(unsigned char *)s_id)
759#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
760 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
761#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
762 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
763#define PEM_write_SSL_SESSION(fp,x) \
764 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
765 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
766#define PEM_write_bio_SSL_SESSION(bp,x) \
767 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
768 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
769#endif
770
771#define SSL_AD_REASON_OFFSET 1000
772/* These alert types are for SSLv3 and TLSv1 */
773#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
774#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
775#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */
776#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
777#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
778#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */
779#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */
780#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */
781#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
782#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
783#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
784#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
785#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
786#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */
787#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */
788#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */
789#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */
790#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
791#define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */
792#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */
793#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */
794#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */
795#define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED
796#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
797
798#define SSL_ERROR_NONE 0
799#define SSL_ERROR_SSL 1
800#define SSL_ERROR_WANT_READ 2
801#define SSL_ERROR_WANT_WRITE 3
802#define SSL_ERROR_WANT_X509_LOOKUP 4
803#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */
804#define SSL_ERROR_ZERO_RETURN 6
805#define SSL_ERROR_WANT_CONNECT 7
806
807#define SSL_CTRL_NEED_TMP_RSA 1
808#define SSL_CTRL_SET_TMP_RSA 2
809#define SSL_CTRL_SET_TMP_DH 3
810#define SSL_CTRL_SET_TMP_RSA_CB 4
811#define SSL_CTRL_SET_TMP_DH_CB 5
812/* Add these ones */
813#define SSL_CTRL_GET_SESSION_REUSED 6
814#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7
815#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8
816#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9
817#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10
818#define SSL_CTRL_GET_FLAGS 11
819#define SSL_CTRL_EXTRA_CHAIN_CERT 12
820
821/* Stats */
822#define SSL_CTRL_SESS_NUMBER 20
823#define SSL_CTRL_SESS_CONNECT 21
824#define SSL_CTRL_SESS_CONNECT_GOOD 22
825#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23
826#define SSL_CTRL_SESS_ACCEPT 24
827#define SSL_CTRL_SESS_ACCEPT_GOOD 25
828#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26
829#define SSL_CTRL_SESS_HIT 27
830#define SSL_CTRL_SESS_CB_HIT 28
831#define SSL_CTRL_SESS_MISSES 29
832#define SSL_CTRL_SESS_TIMEOUTS 30
833#define SSL_CTRL_SESS_CACHE_FULL 31
834#define SSL_CTRL_OPTIONS 32
835#define SSL_CTRL_MODE 33
836
837#define SSL_CTRL_GET_READ_AHEAD 40
838#define SSL_CTRL_SET_READ_AHEAD 41
839#define SSL_CTRL_SET_SESS_CACHE_SIZE 42
840#define SSL_CTRL_GET_SESS_CACHE_SIZE 43
841#define SSL_CTRL_SET_SESS_CACHE_MODE 44
842#define SSL_CTRL_GET_SESS_CACHE_MODE 45
843
844#define SSL_session_reused(ssl) \
845 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
846#define SSL_num_renegotiations(ssl) \
847 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
848#define SSL_clear_num_renegotiations(ssl) \
849 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
850#define SSL_total_renegotiations(ssl) \
851 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
852
853#define SSL_CTX_need_tmp_RSA(ctx) \
854 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
855#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
856 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
857#define SSL_CTX_set_tmp_dh(ctx,dh) \
858 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
859
860#define SSL_need_tmp_RSA(ssl) \
861 SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
862#define SSL_set_tmp_rsa(ssl,rsa) \
863 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
864#define SSL_set_tmp_dh(ssl,dh) \
865 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
866
867#define SSL_CTX_add_extra_chain_cert(ctx,x509) \
868 SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
869
870/* VMS uses only 31 characters for symbols. */
871#ifdef VMS
872#undef SSL_CTX_set_cert_verify_callback
873#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb
874#undef SSL_CTX_use_certificate_chain_file
875#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file
876#undef SSL_CTX_set_default_verify_paths
877#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths
878#undef SSL_get_ex_data_X509_STORE_CTX_idx
879#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_data_X509_STOR_CTX_i
880#undef SSL_add_file_cert_subjects_to_stack
881#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_sub_to_stack
882#undef SSL_add_dir_cert_subjects_to_stack
883#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_sub_to_stack
884#endif
885
886#ifdef HEADER_BIO_H
887BIO_METHOD *BIO_f_ssl(void);
888BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
889BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
890BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
891int BIO_ssl_copy_session_id(BIO *to,BIO *from);
892void BIO_ssl_shutdown(BIO *ssl_bio);
893
894#endif
895
896int SSL_CTX_set_cipher_list(SSL_CTX *,const char *str);
897SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
898void SSL_CTX_free(SSL_CTX *);
899long SSL_CTX_set_timeout(SSL_CTX *ctx,long t);
900long SSL_CTX_get_timeout(SSL_CTX *ctx);
901X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *);
902void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *);
903int SSL_want(SSL *s);
904int SSL_clear(SSL *s);
905
906void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
907
908SSL_CIPHER *SSL_get_current_cipher(SSL *s);
909int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits);
910char * SSL_CIPHER_get_version(SSL_CIPHER *c);
911const char * SSL_CIPHER_get_name(SSL_CIPHER *c);
912
913int SSL_get_fd(SSL *s);
914const char * SSL_get_cipher_list(SSL *s,int n);
915char * SSL_get_shared_ciphers(SSL *s, char *buf, int len);
916int SSL_get_read_ahead(SSL * s);
917int SSL_pending(SSL *s);
918#ifndef NO_SOCK
919int SSL_set_fd(SSL *s, int fd);
920int SSL_set_rfd(SSL *s, int fd);
921int SSL_set_wfd(SSL *s, int fd);
922#endif
923#ifdef HEADER_BIO_H
924void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
925BIO * SSL_get_rbio(SSL *s);
926BIO * SSL_get_wbio(SSL *s);
927#endif
928int SSL_set_cipher_list(SSL *s, const char *str);
929void SSL_set_read_ahead(SSL *s, int yes);
930int SSL_get_verify_mode(SSL *s);
931int SSL_get_verify_depth(SSL *s);
932int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *);
933void SSL_set_verify(SSL *s, int mode,
934 int (*callback)(int ok,X509_STORE_CTX *ctx));
935void SSL_set_verify_depth(SSL *s, int depth);
936#ifndef NO_RSA
937int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
938#endif
939int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
940int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
941int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
942int SSL_use_certificate(SSL *ssl, X509 *x);
943int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
944
945#ifndef NO_STDIO
946int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
947int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
948int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
949int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
950int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
951int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
952int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
953STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
954int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
955 const char *file);
956int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
957 const char *dir);
958#endif
959
960void ERR_load_SSL_strings(void );
961void SSL_load_error_strings(void );
962char * SSL_state_string(SSL *s);
963char * SSL_rstate_string(SSL *s);
964char * SSL_state_string_long(SSL *s);
965char * SSL_rstate_string_long(SSL *s);
966long SSL_SESSION_get_time(SSL_SESSION *s);
967long SSL_SESSION_set_time(SSL_SESSION *s, long t);
968long SSL_SESSION_get_timeout(SSL_SESSION *s);
969long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
970void SSL_copy_session_id(SSL *to,SSL *from);
971
972SSL_SESSION *SSL_SESSION_new(void);
973unsigned long SSL_SESSION_hash(SSL_SESSION *a);
974int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b);
975#ifndef NO_FP_API
976int SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses);
977#endif
978#ifdef HEADER_BIO_H
979int SSL_SESSION_print(BIO *fp,SSL_SESSION *ses);
980#endif
981void SSL_SESSION_free(SSL_SESSION *ses);
982int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
983int SSL_set_session(SSL *to, SSL_SESSION *session);
984int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
985int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
986SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
987
988#ifdef HEADER_X509_H
989X509 * SSL_get_peer_certificate(SSL *s);
990#endif
991
992STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s);
993
994#ifdef VMS
995#define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud
996#endif
997
998int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
999int SSL_CTX_get_verify_depth(SSL_CTX *ctx);
1000int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *);
1001void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,
1002 int (*callback)(int, X509_STORE_CTX *));
1003void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
1004void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(),char *arg);
1005#ifndef NO_RSA
1006int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
1007#endif
1008int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
1009int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
1010int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
1011 unsigned char *d, long len);
1012int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
1013int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
1014
1015void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
1016void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
1017
1018int SSL_CTX_check_private_key(SSL_CTX *ctx);
1019int SSL_check_private_key(SSL *ctx);
1020
1021int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
1022 unsigned int sid_ctx_len);
1023
1024SSL * SSL_new(SSL_CTX *ctx);
1025int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
1026 unsigned int sid_ctx_len);
1027
1028int SSL_CTX_set_purpose(SSL_CTX *s, int purpose);
1029int SSL_set_purpose(SSL *s, int purpose);
1030int SSL_CTX_set_trust(SSL_CTX *s, int trust);
1031int SSL_set_trust(SSL *s, int trust);
1032
1033void SSL_free(SSL *ssl);
1034int SSL_accept(SSL *ssl);
1035int SSL_connect(SSL *ssl);
1036int SSL_read(SSL *ssl,char *buf,int num);
1037int SSL_peek(SSL *ssl,char *buf,int num);
1038int SSL_write(SSL *ssl,const char *buf,int num);
1039long SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg);
1040long SSL_callback_ctrl(SSL *, int, void (*)());
1041long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, char *parg);
1042long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)());
1043
1044int SSL_get_error(SSL *s,int ret_code);
1045const char *SSL_get_version(SSL *s);
1046
1047/* This sets the 'default' SSL version that SSL_new() will create */
1048int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
1049
1050SSL_METHOD *SSLv2_method(void); /* SSLv2 */
1051SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */
1052SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */
1053
1054SSL_METHOD *SSLv3_method(void); /* SSLv3 */
1055SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */
1056SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */
1057
1058SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */
1059SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */
1060SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */
1061
1062SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
1063SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
1064SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
1065
1066STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s);
1067
1068int SSL_do_handshake(SSL *s);
1069int SSL_renegotiate(SSL *s);
1070int SSL_shutdown(SSL *s);
1071
1072SSL_METHOD *SSL_get_ssl_method(SSL *s);
1073int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
1074char *SSL_alert_type_string_long(int value);
1075char *SSL_alert_type_string(int value);
1076char *SSL_alert_desc_string_long(int value);
1077char *SSL_alert_desc_string(int value);
1078
1079void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *list);
1080void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *list);
1081STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s);
1082STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *s);
1083int SSL_add_client_CA(SSL *ssl,X509 *x);
1084int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);
1085
1086void SSL_set_connect_state(SSL *s);
1087void SSL_set_accept_state(SSL *s);
1088
1089long SSL_get_default_timeout(SSL *s);
1090
1091int SSL_library_init(void );
1092
1093char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
1094STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk);
1095
1096SSL *SSL_dup(SSL *ssl);
1097
1098X509 *SSL_get_certificate(SSL *ssl);
1099/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
1100
1101void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
1102int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx);
1103void SSL_set_quiet_shutdown(SSL *ssl,int mode);
1104int SSL_get_quiet_shutdown(SSL *ssl);
1105void SSL_set_shutdown(SSL *ssl,int mode);
1106int SSL_get_shutdown(SSL *ssl);
1107int SSL_version(SSL *ssl);
1108int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
1109int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1110 const char *CApath);
1111#define SSL_get0_session SSL_get_session /* just peek at pointer */
1112SSL_SESSION *SSL_get_session(SSL *ssl);
1113SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
1114SSL_CTX *SSL_get_SSL_CTX(SSL *ssl);
1115void SSL_set_info_callback(SSL *ssl,void (*cb)());
1116void (*SSL_get_info_callback(SSL *ssl))();
1117int SSL_state(SSL *ssl);
1118
1119void SSL_set_verify_result(SSL *ssl,long v);
1120long SSL_get_verify_result(SSL *ssl);
1121
1122int SSL_set_ex_data(SSL *ssl,int idx,void *data);
1123void *SSL_get_ex_data(SSL *ssl,int idx);
1124int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1125 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1126
1127int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data);
1128void *SSL_SESSION_get_ex_data(SSL_SESSION *ss,int idx);
1129int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1130 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1131
1132int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data);
1133void *SSL_CTX_get_ex_data(SSL_CTX *ssl,int idx);
1134int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1135 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1136
1137int SSL_get_ex_data_X509_STORE_CTX_idx(void );
1138
1139#define SSL_CTX_sess_set_cache_size(ctx,t) \
1140 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
1141#define SSL_CTX_sess_get_cache_size(ctx) \
1142 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
1143#define SSL_CTX_set_session_cache_mode(ctx,m) \
1144 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
1145#define SSL_CTX_get_session_cache_mode(ctx) \
1146 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
1147
1148#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
1149#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
1150#define SSL_CTX_get_read_ahead(ctx) \
1151 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
1152#define SSL_CTX_set_read_ahead(ctx,m) \
1153 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,0,NULL)
1154
1155 /* NB: the keylength is only applicable when is_export is true */
1156#ifndef NO_RSA
1157void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
1158 RSA *(*cb)(SSL *ssl,int is_export,
1159 int keylength));
1160
1161void SSL_set_tmp_rsa_callback(SSL *ssl,
1162 RSA *(*cb)(SSL *ssl,int is_export,
1163 int keylength));
1164#endif
1165#ifndef NO_DH
1166void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
1167 DH *(*dh)(SSL *ssl,int is_export,
1168 int keylength));
1169void SSL_set_tmp_dh_callback(SSL *ssl,
1170 DH *(*dh)(SSL *ssl,int is_export,
1171 int keylength));
1172#endif
1173
1174#ifdef HEADER_COMP_H
1175int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);
1176#else
1177int SSL_COMP_add_compression_method(int id,char *cm);
1178#endif
1179
1180/* BEGIN ERROR CODES */
1181/* The following lines are auto generated by the script mkerr.pl. Any changes
1182 * made after this point may be overwritten when the script is next run.
1183 */
1184
1185/* Error codes for the SSL functions. */
1186
1187/* Function codes. */
1188#define SSL_F_CLIENT_CERTIFICATE 100
1189#define SSL_F_CLIENT_HELLO 101
1190#define SSL_F_CLIENT_MASTER_KEY 102
1191#define SSL_F_D2I_SSL_SESSION 103
1192#define SSL_F_DO_SSL3_WRITE 104
1193#define SSL_F_GET_CLIENT_FINISHED 105
1194#define SSL_F_GET_CLIENT_HELLO 106
1195#define SSL_F_GET_CLIENT_MASTER_KEY 107
1196#define SSL_F_GET_SERVER_FINISHED 108
1197#define SSL_F_GET_SERVER_HELLO 109
1198#define SSL_F_GET_SERVER_VERIFY 110
1199#define SSL_F_I2D_SSL_SESSION 111
1200#define SSL_F_READ_N 112
1201#define SSL_F_REQUEST_CERTIFICATE 113
1202#define SSL_F_SERVER_HELLO 114
1203#define SSL_F_SSL23_ACCEPT 115
1204#define SSL_F_SSL23_CLIENT_HELLO 116
1205#define SSL_F_SSL23_CONNECT 117
1206#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1207#define SSL_F_SSL23_GET_SERVER_HELLO 119
1208#define SSL_F_SSL23_READ 120
1209#define SSL_F_SSL23_WRITE 121
1210#define SSL_F_SSL2_ACCEPT 122
1211#define SSL_F_SSL2_CONNECT 123
1212#define SSL_F_SSL2_ENC_INIT 124
1213#define SSL_F_SSL2_READ 125
1214#define SSL_F_SSL2_SET_CERTIFICATE 126
1215#define SSL_F_SSL2_WRITE 127
1216#define SSL_F_SSL3_ACCEPT 128
1217#define SSL_F_SSL3_CALLBACK_CTRL 233
1218#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1219#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1220#define SSL_F_SSL3_CLIENT_HELLO 131
1221#define SSL_F_SSL3_CONNECT 132
1222#define SSL_F_SSL3_CTRL 213
1223#define SSL_F_SSL3_CTX_CTRL 133
1224#define SSL_F_SSL3_ENC 134
1225#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1226#define SSL_F_SSL3_GET_CERT_VERIFY 136
1227#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1228#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1229#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1230#define SSL_F_SSL3_GET_FINISHED 140
1231#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1232#define SSL_F_SSL3_GET_MESSAGE 142
1233#define SSL_F_SSL3_GET_RECORD 143
1234#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1235#define SSL_F_SSL3_GET_SERVER_DONE 145
1236#define SSL_F_SSL3_GET_SERVER_HELLO 146
1237#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1238#define SSL_F_SSL3_READ_BYTES 148
1239#define SSL_F_SSL3_READ_N 149
1240#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1241#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1242#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1243#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1244#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1245#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1246#define SSL_F_SSL3_SETUP_BUFFERS 156
1247#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1248#define SSL_F_SSL3_WRITE_BYTES 158
1249#define SSL_F_SSL3_WRITE_PENDING 159
1250#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215
1251#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216
1252#define SSL_F_SSL_BAD_METHOD 160
1253#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1254#define SSL_F_SSL_CERT_DUP 221
1255#define SSL_F_SSL_CERT_INST 222
1256#define SSL_F_SSL_CERT_INSTANTIATE 214
1257#define SSL_F_SSL_CERT_NEW 162
1258#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1259#define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230
1260#define SSL_F_SSL_CIPHER_STRENGTH_SORT 231
1261#define SSL_F_SSL_CLEAR 164
1262#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165
1263#define SSL_F_SSL_CREATE_CIPHER_LIST 166
1264#define SSL_F_SSL_CTRL 232
1265#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168
1266#define SSL_F_SSL_CTX_NEW 169
1267#define SSL_F_SSL_CTX_SET_PURPOSE 226
1268#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219
1269#define SSL_F_SSL_CTX_SET_SSL_VERSION 170
1270#define SSL_F_SSL_CTX_SET_TRUST 229
1271#define SSL_F_SSL_CTX_USE_CERTIFICATE 171
1272#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172
1273#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220
1274#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173
1275#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174
1276#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175
1277#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176
1278#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
1279#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
1280#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
1281#define SSL_F_SSL_DO_HANDSHAKE 180
1282#define SSL_F_SSL_GET_NEW_SESSION 181
1283#define SSL_F_SSL_GET_PREV_SESSION 217
1284#define SSL_F_SSL_GET_SERVER_SEND_CERT 182
1285#define SSL_F_SSL_GET_SIGN_PKEY 183
1286#define SSL_F_SSL_INIT_WBIO_BUFFER 184
1287#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185
1288#define SSL_F_SSL_NEW 186
1289#define SSL_F_SSL_READ 223
1290#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187
1291#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188
1292#define SSL_F_SSL_SESSION_NEW 189
1293#define SSL_F_SSL_SESSION_PRINT_FP 190
1294#define SSL_F_SSL_SESS_CERT_NEW 225
1295#define SSL_F_SSL_SET_CERT 191
1296#define SSL_F_SSL_SET_FD 192
1297#define SSL_F_SSL_SET_PKEY 193
1298#define SSL_F_SSL_SET_PURPOSE 227
1299#define SSL_F_SSL_SET_RFD 194
1300#define SSL_F_SSL_SET_SESSION 195
1301#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218
1302#define SSL_F_SSL_SET_TRUST 228
1303#define SSL_F_SSL_SET_WFD 196
1304#define SSL_F_SSL_SHUTDOWN 224
1305#define SSL_F_SSL_UNDEFINED_FUNCTION 197
1306#define SSL_F_SSL_USE_CERTIFICATE 198
1307#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199
1308#define SSL_F_SSL_USE_CERTIFICATE_FILE 200
1309#define SSL_F_SSL_USE_PRIVATEKEY 201
1310#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202
1311#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203
1312#define SSL_F_SSL_USE_RSAPRIVATEKEY 204
1313#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205
1314#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206
1315#define SSL_F_SSL_VERIFY_CERT_CHAIN 207
1316#define SSL_F_SSL_WRITE 208
1317#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209
1318#define SSL_F_TLS1_ENC 210
1319#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
1320#define SSL_F_WRITE_PENDING 212
1321
1322/* Reason codes. */
1323#define SSL_R_APP_DATA_IN_HANDSHAKE 100
1324#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272
1325#define SSL_R_BAD_ALERT_RECORD 101
1326#define SSL_R_BAD_AUTHENTICATION_TYPE 102
1327#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
1328#define SSL_R_BAD_CHECKSUM 104
1329#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
1330#define SSL_R_BAD_DECOMPRESSION 107
1331#define SSL_R_BAD_DH_G_LENGTH 108
1332#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
1333#define SSL_R_BAD_DH_P_LENGTH 110
1334#define SSL_R_BAD_DIGEST_LENGTH 111
1335#define SSL_R_BAD_DSA_SIGNATURE 112
1336#define SSL_R_BAD_HELLO_REQUEST 105
1337#define SSL_R_BAD_LENGTH 271
1338#define SSL_R_BAD_MAC_DECODE 113
1339#define SSL_R_BAD_MESSAGE_TYPE 114
1340#define SSL_R_BAD_PACKET_LENGTH 115
1341#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
1342#define SSL_R_BAD_RESPONSE_ARGUMENT 117
1343#define SSL_R_BAD_RSA_DECRYPT 118
1344#define SSL_R_BAD_RSA_ENCRYPT 119
1345#define SSL_R_BAD_RSA_E_LENGTH 120
1346#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
1347#define SSL_R_BAD_RSA_SIGNATURE 122
1348#define SSL_R_BAD_SIGNATURE 123
1349#define SSL_R_BAD_SSL_FILETYPE 124
1350#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
1351#define SSL_R_BAD_STATE 126
1352#define SSL_R_BAD_WRITE_RETRY 127
1353#define SSL_R_BIO_NOT_SET 128
1354#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
1355#define SSL_R_BN_LIB 130
1356#define SSL_R_CA_DN_LENGTH_MISMATCH 131
1357#define SSL_R_CA_DN_TOO_LONG 132
1358#define SSL_R_CCS_RECEIVED_EARLY 133
1359#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
1360#define SSL_R_CERT_LENGTH_MISMATCH 135
1361#define SSL_R_CHALLENGE_IS_DIFFERENT 136
1362#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
1363#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
1364#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
1365#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
1366#define SSL_R_COMPRESSION_FAILURE 141
1367#define SSL_R_COMPRESSION_LIBRARY_ERROR 142
1368#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143
1369#define SSL_R_CONNECTION_TYPE_NOT_SET 144
1370#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145
1371#define SSL_R_DATA_LENGTH_TOO_LONG 146
1372#define SSL_R_DECRYPTION_FAILED 147
1373#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148
1374#define SSL_R_DIGEST_CHECK_FAILED 149
1375#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150
1376#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 1092
1377#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151
1378#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152
1379#define SSL_R_EXTRA_DATA_IN_MESSAGE 153
1380#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154
1381#define SSL_R_HTTPS_PROXY_REQUEST 155
1382#define SSL_R_HTTP_REQUEST 156
1383#define SSL_R_INTERNAL_ERROR 157
1384#define SSL_R_INVALID_CHALLENGE_LENGTH 158
1385#define SSL_R_INVALID_COMMAND 280
1386#define SSL_R_INVALID_PURPOSE 278
1387#define SSL_R_INVALID_TRUST 279
1388#define SSL_R_LENGTH_MISMATCH 159
1389#define SSL_R_LENGTH_TOO_SHORT 160
1390#define SSL_R_LIBRARY_BUG 274
1391#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161
1392#define SSL_R_MISSING_DH_DSA_CERT 162
1393#define SSL_R_MISSING_DH_KEY 163
1394#define SSL_R_MISSING_DH_RSA_CERT 164
1395#define SSL_R_MISSING_DSA_SIGNING_CERT 165
1396#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166
1397#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167
1398#define SSL_R_MISSING_RSA_CERTIFICATE 168
1399#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169
1400#define SSL_R_MISSING_RSA_SIGNING_CERT 170
1401#define SSL_R_MISSING_TMP_DH_KEY 171
1402#define SSL_R_MISSING_TMP_RSA_KEY 172
1403#define SSL_R_MISSING_TMP_RSA_PKEY 173
1404#define SSL_R_MISSING_VERIFY_MESSAGE 174
1405#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
1406#define SSL_R_NO_CERTIFICATES_RETURNED 176
1407#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
1408#define SSL_R_NO_CERTIFICATE_RETURNED 178
1409#define SSL_R_NO_CERTIFICATE_SET 179
1410#define SSL_R_NO_CERTIFICATE_SPECIFIED 180
1411#define SSL_R_NO_CIPHERS_AVAILABLE 181
1412#define SSL_R_NO_CIPHERS_PASSED 182
1413#define SSL_R_NO_CIPHERS_SPECIFIED 183
1414#define SSL_R_NO_CIPHER_LIST 184
1415#define SSL_R_NO_CIPHER_MATCH 185
1416#define SSL_R_NO_CLIENT_CERT_RECEIVED 186
1417#define SSL_R_NO_COMPRESSION_SPECIFIED 187
1418#define SSL_R_NO_METHOD_SPECIFIED 188
1419#define SSL_R_NO_PRIVATEKEY 189
1420#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190
1421#define SSL_R_NO_PROTOCOLS_AVAILABLE 191
1422#define SSL_R_NO_PUBLICKEY 192
1423#define SSL_R_NO_SHARED_CIPHER 193
1424#define SSL_R_NO_VERIFY_CALLBACK 194
1425#define SSL_R_NULL_SSL_CTX 195
1426#define SSL_R_NULL_SSL_METHOD_PASSED 196
1427#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197
1428#define SSL_R_PACKET_LENGTH_TOO_LONG 198
1429#define SSL_R_PATH_TOO_LONG 270
1430#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199
1431#define SSL_R_PEER_ERROR 200
1432#define SSL_R_PEER_ERROR_CERTIFICATE 201
1433#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202
1434#define SSL_R_PEER_ERROR_NO_CIPHER 203
1435#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204
1436#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205
1437#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206
1438#define SSL_R_PROTOCOL_IS_SHUTDOWN 207
1439#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208
1440#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209
1441#define SSL_R_PUBLIC_KEY_NOT_RSA 210
1442#define SSL_R_READ_BIO_NOT_SET 211
1443#define SSL_R_READ_WRONG_PACKET_TYPE 212
1444#define SSL_R_RECORD_LENGTH_MISMATCH 213
1445#define SSL_R_RECORD_TOO_LARGE 214
1446#define SSL_R_REQUIRED_CIPHER_MISSING 215
1447#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216
1448#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217
1449#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218
1450#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277
1451#define SSL_R_SHORT_READ 219
1452#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220
1453#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221
1454#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222
1455#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
1456#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
1457#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
1458#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
1459#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
1460#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
1461#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
1462#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
1463#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
1464#define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE 223
1465#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE 224
1466#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER 225
1467#define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 226
1468#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
1469#define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE 227
1470#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
1471#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228
1472#define SSL_R_SSL_HANDSHAKE_FAILURE 229
1473#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230
1474#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273
1475#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231
1476#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
1477#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
1478#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
1479#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
1480#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
1481#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
1482#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
1483#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
1484#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
1485#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
1486#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
1487#define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
1488#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232
1489#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
1490#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234
1491#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235
1492#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236
1493#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237
1494#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238
1495#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239
1496#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240
1497#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241
1498#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242
1499#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243
1500#define SSL_R_UNEXPECTED_MESSAGE 244
1501#define SSL_R_UNEXPECTED_RECORD 245
1502#define SSL_R_UNINITIALIZED 276
1503#define SSL_R_UNKNOWN_ALERT_TYPE 246
1504#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247
1505#define SSL_R_UNKNOWN_CIPHER_RETURNED 248
1506#define SSL_R_UNKNOWN_CIPHER_TYPE 249
1507#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250
1508#define SSL_R_UNKNOWN_PKEY_TYPE 251
1509#define SSL_R_UNKNOWN_PROTOCOL 252
1510#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253
1511#define SSL_R_UNKNOWN_SSL_VERSION 254
1512#define SSL_R_UNKNOWN_STATE 255
1513#define SSL_R_UNSUPPORTED_CIPHER 256
1514#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257
1515#define SSL_R_UNSUPPORTED_OPTION 1091
1516#define SSL_R_UNSUPPORTED_PROTOCOL 258
1517#define SSL_R_UNSUPPORTED_SSL_VERSION 259
1518#define SSL_R_WRITE_BIO_NOT_SET 260
1519#define SSL_R_WRONG_CIPHER_RETURNED 261
1520#define SSL_R_WRONG_MESSAGE_TYPE 262
1521#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263
1522#define SSL_R_WRONG_SIGNATURE_LENGTH 264
1523#define SSL_R_WRONG_SIGNATURE_SIZE 265
1524#define SSL_R_WRONG_SSL_VERSION 266
1525#define SSL_R_WRONG_VERSION_NUMBER 267
1526#define SSL_R_X509_LIB 268
1527#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
1528
1529#ifdef __cplusplus
1530}
1531#endif
1532#endif
1533
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h
deleted file mode 100644
index 01d41c88c5..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_state_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_STATE;
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 f616763830..0000000000
--- a/src/lib/libssl/ssl3.h
+++ /dev/null
@@ -1,426 +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#define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54"
162#define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52"
163
164#define SSL3_VERSION 0x0300
165#define SSL3_VERSION_MAJOR 0x03
166#define SSL3_VERSION_MINOR 0x00
167
168#define SSL3_RT_CHANGE_CIPHER_SPEC 20
169#define SSL3_RT_ALERT 21
170#define SSL3_RT_HANDSHAKE 22
171#define SSL3_RT_APPLICATION_DATA 23
172
173#define SSL3_AL_WARNING 1
174#define SSL3_AL_FATAL 2
175
176#define SSL3_AD_CLOSE_NOTIFY 0
177#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
178#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
179#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
180#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
181#define SSL3_AD_NO_CERTIFICATE 41
182#define SSL3_AD_BAD_CERTIFICATE 42
183#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
184#define SSL3_AD_CERTIFICATE_REVOKED 44
185#define SSL3_AD_CERTIFICATE_EXPIRED 45
186#define SSL3_AD_CERTIFICATE_UNKNOWN 46
187#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
188
189typedef struct ssl3_record_st
190 {
191/*r */ int type; /* type of record */
192/*rw*/ unsigned int length; /* How many bytes available */
193/*r */ unsigned int off; /* read/write offset into 'buf' */
194/*rw*/ unsigned char *data; /* pointer to the record data */
195/*rw*/ unsigned char *input; /* where the decode bytes are */
196/*r */ unsigned char *comp; /* only used with decompression - malloc()ed */
197 } SSL3_RECORD;
198
199typedef struct ssl3_buffer_st
200 {
201 unsigned char *buf; /* SSL3_RT_MAX_PACKET_SIZE bytes (more if
202 * SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER is set) */
203 int offset; /* where to 'copy from' */
204 int left; /* how many bytes left */
205 } SSL3_BUFFER;
206
207#define SSL3_CT_RSA_SIGN 1
208#define SSL3_CT_DSS_SIGN 2
209#define SSL3_CT_RSA_FIXED_DH 3
210#define SSL3_CT_DSS_FIXED_DH 4
211#define SSL3_CT_RSA_EPHEMERAL_DH 5
212#define SSL3_CT_DSS_EPHEMERAL_DH 6
213#define SSL3_CT_FORTEZZA_DMS 20
214#define SSL3_CT_NUMBER 7
215
216#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
217#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
218#define SSL3_FLAGS_POP_BUFFER 0x0004
219#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
220
221typedef struct ssl3_state_st
222 {
223 long flags;
224 int delay_buf_pop_ret;
225
226 unsigned char read_sequence[8];
227 unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
228 unsigned char write_sequence[8];
229 unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
230
231 unsigned char server_random[SSL3_RANDOM_SIZE];
232 unsigned char client_random[SSL3_RANDOM_SIZE];
233
234 SSL3_BUFFER rbuf; /* read IO goes into here */
235 SSL3_BUFFER wbuf; /* write IO goes into here */
236
237 SSL3_RECORD rrec; /* each decoded record goes in here */
238 SSL3_RECORD wrec; /* goes out from here */
239
240 /* storage for Alert/Handshake protocol data received but not
241 * yet processed by ssl3_read_bytes: */
242 unsigned char alert_fragment[2];
243 unsigned int alert_fragment_len;
244 unsigned char handshake_fragment[4];
245 unsigned int handshake_fragment_len;
246
247 /* partial write - check the numbers match */
248 unsigned int wnum; /* number of bytes sent so far */
249 int wpend_tot; /* number bytes written */
250 int wpend_type;
251 int wpend_ret; /* number of bytes submitted */
252 const unsigned char *wpend_buf;
253
254 /* used during startup, digest all incoming/outgoing packets */
255 EVP_MD_CTX finish_dgst1;
256 EVP_MD_CTX finish_dgst2;
257
258 /* this is set whenerver we see a change_cipher_spec message
259 * come in when we are not looking for one */
260 int change_cipher_spec;
261
262 int warn_alert;
263 int fatal_alert;
264 /* we allow one fatal and one warning alert to be outstanding,
265 * send close alert via the warning alert */
266 int alert_dispatch;
267 unsigned char send_alert[2];
268
269 /* This flag is set when we should renegotiate ASAP, basically when
270 * there is no more data in the read or write buffers */
271 int renegotiate;
272 int total_renegotiations;
273 int num_renegotiations;
274
275 int in_read_app_data;
276
277 struct {
278 /* actually only needs to be 16+20 */
279 unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];
280
281 /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
282 unsigned char finish_md[EVP_MAX_MD_SIZE*2];
283 int finish_md_len;
284 unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2];
285 int peer_finish_md_len;
286
287 unsigned long message_size;
288 int message_type;
289
290 /* used to hold the new cipher we are going to use */
291 SSL_CIPHER *new_cipher;
292#ifndef NO_DH
293 DH *dh;
294#endif
295 /* used when SSL_ST_FLUSH_DATA is entered */
296 int next_state;
297
298 int reuse_message;
299
300 /* used for certificate requests */
301 int cert_req;
302 int ctype_num;
303 char ctype[SSL3_CT_NUMBER];
304 STACK_OF(X509_NAME) *ca_names;
305
306 int use_rsa_tmp;
307
308 int key_block_length;
309 unsigned char *key_block;
310
311 const EVP_CIPHER *new_sym_enc;
312 const EVP_MD *new_hash;
313#ifdef HEADER_COMP_H
314 const SSL_COMP *new_compression;
315#else
316 char *new_compression;
317#endif
318 int cert_request;
319 } tmp;
320
321 } SSL3_STATE;
322
323/* SSLv3 */
324/*client */
325/* extra state */
326#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
327/* write to server */
328#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
329#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
330/* read from server */
331#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
332#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
333#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
334#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
335#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
336#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
337#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
338#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
339#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
340#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
341/* write to server */
342#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
343#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
344#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
345#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
346#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
347#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
348#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
349#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
350#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
351#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
352#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
353#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
354/* read from server */
355#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
356#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
357#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
358#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
359
360/* server */
361/* extra state */
362#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
363/* read from client */
364/* Do not change the number values, they do matter */
365#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
366#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
367#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
368/* write to client */
369#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
370#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
371#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
372#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
373#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
374#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
375#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
376#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
377#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
378#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
379#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
380#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
381#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
382/* read from client */
383#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
384#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
385#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
386#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
387#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
388#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
389#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
390#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
391#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
392#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
393/* write to client */
394#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
395#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
396#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
397#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
398
399#define SSL3_MT_HELLO_REQUEST 0
400#define SSL3_MT_CLIENT_HELLO 1
401#define SSL3_MT_SERVER_HELLO 2
402#define SSL3_MT_CERTIFICATE 11
403#define SSL3_MT_SERVER_KEY_EXCHANGE 12
404#define SSL3_MT_CERTIFICATE_REQUEST 13
405#define SSL3_MT_SERVER_DONE 14
406#define SSL3_MT_CERTIFICATE_VERIFY 15
407#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
408#define SSL3_MT_FINISHED 20
409
410#define SSL3_MT_CCS 1
411
412/* These are used when changing over to a new cipher */
413#define SSL3_CC_READ 0x01
414#define SSL3_CC_WRITE 0x02
415#define SSL3_CC_CLIENT 0x10
416#define SSL3_CC_SERVER 0x20
417#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
418#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
419#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
420#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
421
422#ifdef __cplusplus
423}
424#endif
425#endif
426
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 e77cdddfd3..0000000000
--- a/src/lib/libssl/ssl_asn1.c
+++ /dev/null
@@ -1,349 +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 <openssl/x509.h>
64#include "ssl_locl.h"
65
66typedef struct ssl_session_asn1_st
67 {
68 ASN1_INTEGER version;
69 ASN1_INTEGER ssl_version;
70 ASN1_OCTET_STRING cipher;
71 ASN1_OCTET_STRING master_key;
72 ASN1_OCTET_STRING session_id;
73 ASN1_OCTET_STRING session_id_context;
74 ASN1_OCTET_STRING key_arg;
75 ASN1_INTEGER time;
76 ASN1_INTEGER timeout;
77 ASN1_INTEGER verify_result;
78 } SSL_SESSION_ASN1;
79
80int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
81 {
82#define LSIZE2 (sizeof(long)*2)
83 int v1=0,v2=0,v3=0,v4=0,v5=0;
84 unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2];
85 unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2];
86 long l;
87 SSL_SESSION_ASN1 a;
88 M_ASN1_I2D_vars(in);
89
90 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
91 return(0);
92
93 /* Note that I cheat in the following 2 assignments. I know
94 * that if the ASN1_INTEGER passed to ASN1_INTEGER_set
95 * is > sizeof(long)+1, the buffer will not be re-Malloc()ed.
96 * This is a bit evil but makes things simple, no dynamic allocation
97 * to clean up :-) */
98 a.version.length=LSIZE2;
99 a.version.type=V_ASN1_INTEGER;
100 a.version.data=ibuf1;
101 ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION);
102
103 a.ssl_version.length=LSIZE2;
104 a.ssl_version.type=V_ASN1_INTEGER;
105 a.ssl_version.data=ibuf2;
106 ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version);
107
108 a.cipher.type=V_ASN1_OCTET_STRING;
109 a.cipher.data=buf;
110
111 if (in->cipher == NULL)
112 l=in->cipher_id;
113 else
114 l=in->cipher->id;
115 if (in->ssl_version == SSL2_VERSION)
116 {
117 a.cipher.length=3;
118 buf[0]=((unsigned char)(l>>16L))&0xff;
119 buf[1]=((unsigned char)(l>> 8L))&0xff;
120 buf[2]=((unsigned char)(l ))&0xff;
121 }
122 else
123 {
124 a.cipher.length=2;
125 buf[0]=((unsigned char)(l>>8L))&0xff;
126 buf[1]=((unsigned char)(l ))&0xff;
127 }
128
129 a.master_key.length=in->master_key_length;
130 a.master_key.type=V_ASN1_OCTET_STRING;
131 a.master_key.data=in->master_key;
132
133 a.session_id.length=in->session_id_length;
134 a.session_id.type=V_ASN1_OCTET_STRING;
135 a.session_id.data=in->session_id;
136
137 a.session_id_context.length=in->sid_ctx_length;
138 a.session_id_context.type=V_ASN1_OCTET_STRING;
139 a.session_id_context.data=in->sid_ctx;
140
141 a.key_arg.length=in->key_arg_length;
142 a.key_arg.type=V_ASN1_OCTET_STRING;
143 a.key_arg.data=in->key_arg;
144
145 if (in->time != 0L)
146 {
147 a.time.length=LSIZE2;
148 a.time.type=V_ASN1_INTEGER;
149 a.time.data=ibuf3;
150 ASN1_INTEGER_set(&(a.time),in->time);
151 }
152
153 if (in->timeout != 0L)
154 {
155 a.timeout.length=LSIZE2;
156 a.timeout.type=V_ASN1_INTEGER;
157 a.timeout.data=ibuf4;
158 ASN1_INTEGER_set(&(a.timeout),in->timeout);
159 }
160
161 if (in->verify_result != X509_V_OK)
162 {
163 a.verify_result.length=LSIZE2;
164 a.verify_result.type=V_ASN1_INTEGER;
165 a.verify_result.data=ibuf5;
166 ASN1_INTEGER_set(&a.verify_result,in->verify_result);
167 }
168
169 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
170 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
171 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
172 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
173 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
174 if (in->key_arg_length > 0)
175 M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING);
176 if (in->time != 0L)
177 M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
178 if (in->timeout != 0L)
179 M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
180 if (in->peer != NULL)
181 M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3);
182 M_ASN1_I2D_len_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,v4);
183 if (in->verify_result != X509_V_OK)
184 M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5);
185
186 M_ASN1_I2D_seq_total();
187
188 M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
189 M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
190 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
191 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
192 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
193 if (in->key_arg_length > 0)
194 M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0);
195 if (in->time != 0L)
196 M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
197 if (in->timeout != 0L)
198 M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
199 if (in->peer != NULL)
200 M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3);
201 M_ASN1_I2D_put_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,
202 v4);
203 if (in->verify_result != X509_V_OK)
204 M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5);
205 M_ASN1_I2D_finish();
206 }
207
208SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp,
209 long length)
210 {
211 int version,ssl_version=0,i;
212 long id;
213 ASN1_INTEGER ai,*aip;
214 ASN1_OCTET_STRING os,*osp;
215 M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new);
216
217 aip= &ai;
218 osp= &os;
219
220 M_ASN1_D2I_Init();
221 M_ASN1_D2I_start_sequence();
222
223 ai.data=NULL; ai.length=0;
224 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
225 version=(int)ASN1_INTEGER_get(aip);
226 if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; }
227
228 /* we don't care about the version right now :-) */
229 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
230 ssl_version=(int)ASN1_INTEGER_get(aip);
231 ret->ssl_version=ssl_version;
232 if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; }
233
234 os.data=NULL; os.length=0;
235 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
236 if (ssl_version == SSL2_VERSION)
237 {
238 if (os.length != 3)
239 {
240 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
241 goto err;
242 }
243 id=0x02000000L|
244 ((unsigned long)os.data[0]<<16L)|
245 ((unsigned long)os.data[1]<< 8L)|
246 (unsigned long)os.data[2];
247 }
248 else if ((ssl_version>>8) == 3)
249 {
250 if (os.length != 2)
251 {
252 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
253 goto err;
254 }
255 id=0x03000000L|
256 ((unsigned long)os.data[0]<<8L)|
257 (unsigned long)os.data[1];
258 }
259 else
260 {
261 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION);
262 return(NULL);
263 }
264
265 ret->cipher=NULL;
266 ret->cipher_id=id;
267
268 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
269 if ((ssl_version>>8) == SSL3_VERSION)
270 i=SSL3_MAX_SSL_SESSION_ID_LENGTH;
271 else /* if (ssl_version == SSL2_VERSION) */
272 i=SSL2_MAX_SSL_SESSION_ID_LENGTH;
273
274 if (os.length > i)
275 os.length=i;
276
277 ret->session_id_length=os.length;
278 memcpy(ret->session_id,os.data,os.length);
279
280 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
281 if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH)
282 ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
283 else
284 ret->master_key_length=os.length;
285 memcpy(ret->master_key,os.data,ret->master_key_length);
286
287 os.length=0;
288 M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING);
289 if (os.length > SSL_MAX_KEY_ARG_LENGTH)
290 ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH;
291 else
292 ret->key_arg_length=os.length;
293 memcpy(ret->key_arg,os.data,ret->key_arg_length);
294 if (os.data != NULL) Free(os.data);
295
296 ai.length=0;
297 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1);
298 if (ai.data != NULL)
299 {
300 ret->time=ASN1_INTEGER_get(aip);
301 Free(ai.data); ai.data=NULL; ai.length=0;
302 }
303 else
304 ret->time=time(NULL);
305
306 ai.length=0;
307 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2);
308 if (ai.data != NULL)
309 {
310 ret->timeout=ASN1_INTEGER_get(aip);
311 Free(ai.data); ai.data=NULL; ai.length=0;
312 }
313 else
314 ret->timeout=3;
315
316 if (ret->peer != NULL)
317 {
318 X509_free(ret->peer);
319 ret->peer=NULL;
320 }
321 M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3);
322
323 os.length=0;
324 os.data=NULL;
325 M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,4);
326
327 if(os.data != NULL)
328 {
329 if (os.length > SSL_MAX_SID_CTX_LENGTH)
330 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH);
331 ret->sid_ctx_length=os.length;
332 memcpy(ret->sid_ctx,os.data,os.length);
333 Free(os.data); os.data=NULL; os.length=0;
334 }
335 else
336 ret->sid_ctx_length=0;
337
338 ai.length=0;
339 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,5);
340 if (ai.data != NULL)
341 {
342 ret->verify_result=ASN1_INTEGER_get(aip);
343 Free(ai.data); ai.data=NULL; ai.length=0;
344 }
345 else
346 ret->verify_result=X509_V_OK;
347
348 M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION);
349 }
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c
deleted file mode 100644
index f2335d5650..0000000000
--- a/src/lib/libssl/ssl_cert.c
+++ /dev/null
@@ -1,753 +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
109#include "openssl/e_os.h"
110
111#ifndef NO_SYS_TYPES_H
112# include <sys/types.h>
113#endif
114
115#if !defined(WIN32) && !defined(VSM) && !defined(NeXT) && !defined(MAC_OS_pre_X)
116#include <dirent.h>
117#endif
118
119#ifdef NeXT
120#include <sys/dir.h>
121#define dirent direct
122#endif
123
124#include <openssl/objects.h>
125#include <openssl/bio.h>
126#include <openssl/pem.h>
127#include <openssl/x509v3.h>
128#include "ssl_locl.h"
129
130int SSL_get_ex_data_X509_STORE_CTX_idx(void)
131 {
132 static int ssl_x509_store_ctx_idx= -1;
133
134 if (ssl_x509_store_ctx_idx < 0)
135 {
136 ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index(
137 0,"SSL for verify callback",NULL,NULL,NULL);
138 }
139 return(ssl_x509_store_ctx_idx);
140 }
141
142CERT *ssl_cert_new(void)
143 {
144 CERT *ret;
145
146 ret=(CERT *)Malloc(sizeof(CERT));
147 if (ret == NULL)
148 {
149 SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE);
150 return(NULL);
151 }
152 memset(ret,0,sizeof(CERT));
153
154 ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]);
155 ret->references=1;
156
157 return(ret);
158 }
159
160CERT *ssl_cert_dup(CERT *cert)
161 {
162 CERT *ret;
163 int i;
164
165 ret = (CERT *)Malloc(sizeof(CERT));
166 if (ret == NULL)
167 {
168 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE);
169 return(NULL);
170 }
171
172 memset(ret, 0, sizeof(CERT));
173
174 ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
175 /* or ret->key = ret->pkeys + (cert->key - cert->pkeys),
176 * if you find that more readable */
177
178 ret->valid = cert->valid;
179 ret->mask = cert->mask;
180 ret->export_mask = cert->export_mask;
181
182#ifndef NO_RSA
183 if (cert->rsa_tmp != NULL)
184 {
185 ret->rsa_tmp = cert->rsa_tmp;
186 CRYPTO_add(&ret->rsa_tmp->references, 1, CRYPTO_LOCK_RSA);
187 }
188 ret->rsa_tmp_cb = cert->rsa_tmp_cb;
189#endif
190
191#ifndef NO_DH
192 if (cert->dh_tmp != NULL)
193 {
194 /* DH parameters don't have a reference count */
195 ret->dh_tmp = DHparams_dup(cert->dh_tmp);
196 if (ret->dh_tmp == NULL)
197 {
198 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_DH_LIB);
199 goto err;
200 }
201 if (cert->dh_tmp->priv_key)
202 {
203 BIGNUM *b = BN_dup(cert->dh_tmp->priv_key);
204 if (!b)
205 {
206 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
207 goto err;
208 }
209 ret->dh_tmp->priv_key = b;
210 }
211 if (cert->dh_tmp->pub_key)
212 {
213 BIGNUM *b = BN_dup(cert->dh_tmp->pub_key);
214 if (!b)
215 {
216 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
217 goto err;
218 }
219 ret->dh_tmp->pub_key = b;
220 }
221 }
222 ret->dh_tmp_cb = cert->dh_tmp_cb;
223#endif
224
225 for (i = 0; i < SSL_PKEY_NUM; i++)
226 {
227 if (cert->pkeys[i].x509 != NULL)
228 {
229 ret->pkeys[i].x509 = cert->pkeys[i].x509;
230 CRYPTO_add(&ret->pkeys[i].x509->references, 1,
231 CRYPTO_LOCK_X509);
232 }
233
234 if (cert->pkeys[i].privatekey != NULL)
235 {
236 ret->pkeys[i].privatekey = cert->pkeys[i].privatekey;
237 CRYPTO_add(&ret->pkeys[i].privatekey->references, 1,
238 CRYPTO_LOCK_EVP_PKEY);
239
240 switch(i)
241 {
242 /* If there was anything special to do for
243 * certain types of keys, we'd do it here.
244 * (Nothing at the moment, I think.) */
245
246 case SSL_PKEY_RSA_ENC:
247 case SSL_PKEY_RSA_SIGN:
248 /* We have an RSA key. */
249 break;
250
251 case SSL_PKEY_DSA_SIGN:
252 /* We have a DSA key. */
253 break;
254
255 case SSL_PKEY_DH_RSA:
256 case SSL_PKEY_DH_DSA:
257 /* We have a DH key. */
258 break;
259
260 default:
261 /* Can't happen. */
262 SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG);
263 }
264 }
265 }
266
267 /* ret->extra_certs *should* exist, but currently the own certificate
268 * chain is held inside SSL_CTX */
269
270 ret->references=1;
271
272 return(ret);
273
274err:
275#ifndef NO_RSA
276 if (ret->rsa_tmp != NULL)
277 RSA_free(ret->rsa_tmp);
278#endif
279#ifndef NO_DH
280 if (ret->dh_tmp != NULL)
281 DH_free(ret->dh_tmp);
282#endif
283
284 for (i = 0; i < SSL_PKEY_NUM; i++)
285 {
286 if (ret->pkeys[i].x509 != NULL)
287 X509_free(ret->pkeys[i].x509);
288 if (ret->pkeys[i].privatekey != NULL)
289 EVP_PKEY_free(ret->pkeys[i].privatekey);
290 }
291
292 return NULL;
293 }
294
295
296void ssl_cert_free(CERT *c)
297 {
298 int i;
299
300 if(c == NULL)
301 return;
302
303 i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT);
304#ifdef REF_PRINT
305 REF_PRINT("CERT",c);
306#endif
307 if (i > 0) return;
308#ifdef REF_CHECK
309 if (i < 0)
310 {
311 fprintf(stderr,"ssl_cert_free, bad reference count\n");
312 abort(); /* ok */
313 }
314#endif
315
316#ifndef NO_RSA
317 if (c->rsa_tmp) RSA_free(c->rsa_tmp);
318#endif
319#ifndef NO_DH
320 if (c->dh_tmp) DH_free(c->dh_tmp);
321#endif
322
323 for (i=0; i<SSL_PKEY_NUM; i++)
324 {
325 if (c->pkeys[i].x509 != NULL)
326 X509_free(c->pkeys[i].x509);
327 if (c->pkeys[i].privatekey != NULL)
328 EVP_PKEY_free(c->pkeys[i].privatekey);
329#if 0
330 if (c->pkeys[i].publickey != NULL)
331 EVP_PKEY_free(c->pkeys[i].publickey);
332#endif
333 }
334 Free(c);
335 }
336
337int ssl_cert_inst(CERT **o)
338 {
339 /* Create a CERT if there isn't already one
340 * (which cannot really happen, as it is initially created in
341 * SSL_CTX_new; but the earlier code usually allows for that one
342 * being non-existant, so we follow that behaviour, as it might
343 * turn out that there actually is a reason for it -- but I'm
344 * not sure that *all* of the existing code could cope with
345 * s->cert being NULL, otherwise we could do without the
346 * initialization in SSL_CTX_new).
347 */
348
349 if (o == NULL)
350 {
351 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_PASSED_NULL_PARAMETER);
352 return(0);
353 }
354 if (*o == NULL)
355 {
356 if ((*o = ssl_cert_new()) == NULL)
357 {
358 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_MALLOC_FAILURE);
359 return(0);
360 }
361 }
362 return(1);
363 }
364
365
366SESS_CERT *ssl_sess_cert_new(void)
367 {
368 SESS_CERT *ret;
369
370 ret = Malloc(sizeof *ret);
371 if (ret == NULL)
372 {
373 SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE);
374 return NULL;
375 }
376
377 memset(ret, 0 ,sizeof *ret);
378 ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]);
379 ret->references = 1;
380
381 return ret;
382 }
383
384void ssl_sess_cert_free(SESS_CERT *sc)
385 {
386 int i;
387
388 if (sc == NULL)
389 return;
390
391 i = CRYPTO_add(&sc->references, -1, CRYPTO_LOCK_SSL_SESS_CERT);
392#ifdef REF_PRINT
393 REF_PRINT("SESS_CERT", sc);
394#endif
395 if (i > 0)
396 return;
397#ifdef REF_CHECK
398 if (i < 0)
399 {
400 fprintf(stderr,"ssl_sess_cert_free, bad reference count\n");
401 abort(); /* ok */
402 }
403#endif
404
405 /* i == 0 */
406 if (sc->cert_chain != NULL)
407 sk_X509_pop_free(sc->cert_chain, X509_free);
408 for (i = 0; i < SSL_PKEY_NUM; i++)
409 {
410 if (sc->peer_pkeys[i].x509 != NULL)
411 X509_free(sc->peer_pkeys[i].x509);
412#if 0 /* We don't have the peer's private key. These lines are just
413 * here as a reminder that we're still using a not-quite-appropriate
414 * data structure. */
415 if (sc->peer_pkeys[i].privatekey != NULL)
416 EVP_PKEY_free(sc->peer_pkeys[i].privatekey);
417#endif
418 }
419
420#ifndef NO_RSA
421 if (sc->peer_rsa_tmp != NULL)
422 RSA_free(sc->peer_rsa_tmp);
423#endif
424#ifndef NO_DH
425 if (sc->peer_dh_tmp != NULL)
426 DH_free(sc->peer_dh_tmp);
427#endif
428
429 Free(sc);
430 }
431
432int ssl_set_peer_cert_type(SESS_CERT *sc,int type)
433 {
434 sc->peer_cert_type = type;
435 return(1);
436 }
437
438int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
439 {
440 X509 *x;
441 int i;
442 X509_STORE_CTX ctx;
443
444 if ((sk == NULL) || (sk_X509_num(sk) == 0))
445 return(0);
446
447 x=sk_X509_value(sk,0);
448 X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk);
449 if (SSL_get_verify_depth(s) >= 0)
450 X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s));
451 X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s);
452 /* We need to set the verify purpose. The purpose can be determined by
453 * the context: if its a server it will verify SSL client certificates
454 * or vice versa.
455 */
456
457 if(s->server) i = X509_PURPOSE_SSL_CLIENT;
458 else i = X509_PURPOSE_SSL_SERVER;
459
460 X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust);
461
462 if (s->ctx->app_verify_callback != NULL)
463 i=s->ctx->app_verify_callback(&ctx); /* should pass app_verify_arg */
464 else
465 {
466#ifndef NO_X509_VERIFY
467 i=X509_verify_cert(&ctx);
468#else
469 i=0;
470 ctx.error=X509_V_ERR_APPLICATION_VERIFICATION;
471 SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,SSL_R_NO_VERIFY_CALLBACK);
472#endif
473 }
474
475 s->verify_result=ctx.error;
476 X509_STORE_CTX_cleanup(&ctx);
477
478 return(i);
479 }
480
481static void set_client_CA_list(STACK_OF(X509_NAME) **ca_list,STACK_OF(X509_NAME) *list)
482 {
483 if (*ca_list != NULL)
484 sk_X509_NAME_pop_free(*ca_list,X509_NAME_free);
485
486 *ca_list=list;
487 }
488
489STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk)
490 {
491 int i;
492 STACK_OF(X509_NAME) *ret;
493 X509_NAME *name;
494
495 ret=sk_X509_NAME_new_null();
496 for (i=0; i<sk_X509_NAME_num(sk); i++)
497 {
498 name=X509_NAME_dup(sk_X509_NAME_value(sk,i));
499 if ((name == NULL) || !sk_X509_NAME_push(ret,name))
500 {
501 sk_X509_NAME_pop_free(ret,X509_NAME_free);
502 return(NULL);
503 }
504 }
505 return(ret);
506 }
507
508void SSL_set_client_CA_list(SSL *s,STACK_OF(X509_NAME) *list)
509 {
510 set_client_CA_list(&(s->client_CA),list);
511 }
512
513void SSL_CTX_set_client_CA_list(SSL_CTX *ctx,STACK_OF(X509_NAME) *list)
514 {
515 set_client_CA_list(&(ctx->client_CA),list);
516 }
517
518STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *ctx)
519 {
520 return(ctx->client_CA);
521 }
522
523STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s)
524 {
525 if (s->type == SSL_ST_CONNECT)
526 { /* we are in the client */
527 if (((s->version>>8) == SSL3_VERSION_MAJOR) &&
528 (s->s3 != NULL))
529 return(s->s3->tmp.ca_names);
530 else
531 return(NULL);
532 }
533 else
534 {
535 if (s->client_CA != NULL)
536 return(s->client_CA);
537 else
538 return(s->ctx->client_CA);
539 }
540 }
541
542static int add_client_CA(STACK_OF(X509_NAME) **sk,X509 *x)
543 {
544 X509_NAME *name;
545
546 if (x == NULL) return(0);
547 if ((*sk == NULL) && ((*sk=sk_X509_NAME_new_null()) == NULL))
548 return(0);
549
550 if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL)
551 return(0);
552
553 if (!sk_X509_NAME_push(*sk,name))
554 {
555 X509_NAME_free(name);
556 return(0);
557 }
558 return(1);
559 }
560
561int SSL_add_client_CA(SSL *ssl,X509 *x)
562 {
563 return(add_client_CA(&(ssl->client_CA),x));
564 }
565
566int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x)
567 {
568 return(add_client_CA(&(ctx->client_CA),x));
569 }
570
571static int xname_cmp(X509_NAME **a,X509_NAME **b)
572 {
573 return(X509_NAME_cmp(*a,*b));
574 }
575
576#ifndef NO_STDIO
577/*!
578 * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed;
579 * it doesn't really have anything to do with clients (except that a common use
580 * for a stack of CAs is to send it to the client). Actually, it doesn't have
581 * much to do with CAs, either, since it will load any old cert.
582 * \param file the file containing one or more certs.
583 * \return a ::STACK containing the certs.
584 */
585STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file)
586 {
587 BIO *in;
588 X509 *x=NULL;
589 X509_NAME *xn=NULL;
590 STACK_OF(X509_NAME) *ret,*sk;
591
592 ret=sk_X509_NAME_new(NULL);
593 sk=sk_X509_NAME_new(xname_cmp);
594
595 in=BIO_new(BIO_s_file_internal());
596
597 if ((ret == NULL) || (sk == NULL) || (in == NULL))
598 {
599 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE);
600 goto err;
601 }
602
603 if (!BIO_read_filename(in,file))
604 goto err;
605
606 for (;;)
607 {
608 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
609 break;
610 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
611 /* check for duplicates */
612 xn=X509_NAME_dup(xn);
613 if (xn == NULL) goto err;
614 if (sk_X509_NAME_find(sk,xn) >= 0)
615 X509_NAME_free(xn);
616 else
617 {
618 sk_X509_NAME_push(sk,xn);
619 sk_X509_NAME_push(ret,xn);
620 }
621 }
622
623 if (0)
624 {
625err:
626 if (ret != NULL) sk_X509_NAME_pop_free(ret,X509_NAME_free);
627 ret=NULL;
628 }
629 if (sk != NULL) sk_X509_NAME_free(sk);
630 if (in != NULL) BIO_free(in);
631 if (x != NULL) X509_free(x);
632 return(ret);
633 }
634#endif
635
636/*!
637 * Add a file of certs to a stack.
638 * \param stack the stack to add to.
639 * \param file the file to add from. All certs in this file that are not
640 * already in the stack will be added.
641 * \return 1 for success, 0 for failure. Note that in the case of failure some
642 * certs may have been added to \c stack.
643 */
644
645int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
646 const char *file)
647 {
648 BIO *in;
649 X509 *x=NULL;
650 X509_NAME *xn=NULL;
651 int ret=1;
652 int (*oldcmp)(X509_NAME **a, X509_NAME **b);
653
654 oldcmp=sk_X509_NAME_set_cmp_func(stack,xname_cmp);
655
656 in=BIO_new(BIO_s_file_internal());
657
658 if (in == NULL)
659 {
660 SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,ERR_R_MALLOC_FAILURE);
661 goto err;
662 }
663
664 if (!BIO_read_filename(in,file))
665 goto err;
666
667 for (;;)
668 {
669 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
670 break;
671 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
672 xn=X509_NAME_dup(xn);
673 if (xn == NULL) goto err;
674 if (sk_X509_NAME_find(stack,xn) >= 0)
675 X509_NAME_free(xn);
676 else
677 sk_X509_NAME_push(stack,xn);
678 }
679
680 if (0)
681 {
682err:
683 ret=0;
684 }
685 if(in != NULL)
686 BIO_free(in);
687 if(x != NULL)
688 X509_free(x);
689
690 sk_X509_NAME_set_cmp_func(stack,oldcmp);
691
692 return ret;
693 }
694
695/*!
696 * Add a directory of certs to a stack.
697 * \param stack the stack to append to.
698 * \param dir the directory to append from. All files in this directory will be
699 * examined as potential certs. Any that are acceptable to
700 * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will be
701 * included.
702 * \return 1 for success, 0 for failure. Note that in the case of failure some
703 * certs may have been added to \c stack.
704 */
705
706#ifndef WIN32
707#ifndef VMS /* XXXX This may be fixed in the future */
708#ifndef MAC_OS_pre_X
709
710int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
711 const char *dir)
712 {
713 DIR *d;
714 struct dirent *dstruct;
715 int ret = 0;
716
717 CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
718 d = opendir(dir);
719
720 /* Note that a side effect is that the CAs will be sorted by name */
721 if(!d)
722 {
723 SYSerr(SYS_F_OPENDIR, get_last_sys_error());
724 ERR_add_error_data(3, "opendir('", dir, "')");
725 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
726 goto err;
727 }
728
729 while((dstruct=readdir(d)))
730 {
731 char buf[1024];
732
733 if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
734 {
735 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
736 goto err;
737 }
738
739 sprintf(buf,"%s/%s",dir,dstruct->d_name);
740 if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
741 goto err;
742 }
743 ret = 1;
744
745err:
746 closedir(d);
747 CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
748 return ret;
749 }
750
751#endif
752#endif
753#endif
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
deleted file mode 100644
index 7436a50ad1..0000000000
--- a/src/lib/libssl/ssl_ciph.c
+++ /dev/null
@@ -1,1069 +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
86#define CIPHER_ADD 1
87#define CIPHER_KILL 2
88#define CIPHER_DEL 3
89#define CIPHER_ORD 4
90#define CIPHER_SPECIAL 5
91
92typedef struct cipher_order_st
93 {
94 SSL_CIPHER *cipher;
95 int active;
96 int dead;
97 struct cipher_order_st *next,*prev;
98 } CIPHER_ORDER;
99
100static const SSL_CIPHER cipher_aliases[]={
101 /* Don't include eNULL unless specifically enabled */
102 {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */
103 {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0},
104 {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0},
105 {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0},
106 {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0},
107 {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0},
108 {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0},
109 {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0},
110
111 {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0},
112 {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0},
113 {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,0,0,0,SSL_AUTH_MASK,0},
114 {0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0},
115 {0,SSL_TXT_aDH, 0,SSL_aDH, 0,0,0,0,SSL_AUTH_MASK,0},
116 {0,SSL_TXT_DSS, 0,SSL_DSS, 0,0,0,0,SSL_AUTH_MASK,0},
117
118 {0,SSL_TXT_DES, 0,SSL_DES, 0,0,0,0,SSL_ENC_MASK,0},
119 {0,SSL_TXT_3DES,0,SSL_3DES, 0,0,0,0,SSL_ENC_MASK,0},
120 {0,SSL_TXT_RC4, 0,SSL_RC4, 0,0,0,0,SSL_ENC_MASK,0},
121 {0,SSL_TXT_RC2, 0,SSL_RC2, 0,0,0,0,SSL_ENC_MASK,0},
122 {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0},
123 {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0},
124 {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0},
125
126 {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0},
127 {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0},
128 {0,SSL_TXT_SHA, 0,SSL_SHA, 0,0,0,0,SSL_MAC_MASK,0},
129
130 {0,SSL_TXT_NULL,0,SSL_NULL, 0,0,0,0,SSL_ENC_MASK,0},
131 {0,SSL_TXT_RSA, 0,SSL_RSA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
132 {0,SSL_TXT_ADH, 0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
133 {0,SSL_TXT_FZA, 0,SSL_FZA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0},
134
135 {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0},
136 {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0},
137 {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0},
138
139 {0,SSL_TXT_EXP ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
140 {0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
141 {0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK},
142 {0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK},
143 {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK},
144 {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK},
145 {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK},
146 };
147
148static int init_ciphers=1;
149
150static void load_ciphers(void)
151 {
152 init_ciphers=0;
153 ssl_cipher_methods[SSL_ENC_DES_IDX]=
154 EVP_get_cipherbyname(SN_des_cbc);
155 ssl_cipher_methods[SSL_ENC_3DES_IDX]=
156 EVP_get_cipherbyname(SN_des_ede3_cbc);
157 ssl_cipher_methods[SSL_ENC_RC4_IDX]=
158 EVP_get_cipherbyname(SN_rc4);
159 ssl_cipher_methods[SSL_ENC_RC2_IDX]=
160 EVP_get_cipherbyname(SN_rc2_cbc);
161 ssl_cipher_methods[SSL_ENC_IDEA_IDX]=
162 EVP_get_cipherbyname(SN_idea_cbc);
163
164 ssl_digest_methods[SSL_MD_MD5_IDX]=
165 EVP_get_digestbyname(SN_md5);
166 ssl_digest_methods[SSL_MD_SHA1_IDX]=
167 EVP_get_digestbyname(SN_sha1);
168 }
169
170int ssl_cipher_get_evp(SSL_SESSION *s, const EVP_CIPHER **enc,
171 const EVP_MD **md, SSL_COMP **comp)
172 {
173 int i;
174 SSL_CIPHER *c;
175
176 c=s->cipher;
177 if (c == NULL) return(0);
178 if (comp != NULL)
179 {
180 SSL_COMP ctmp;
181
182 if (s->compress_meth == 0)
183 *comp=NULL;
184 else if (ssl_comp_methods == NULL)
185 {
186 /* bad */
187 *comp=NULL;
188 }
189 else
190 {
191
192 ctmp.id=s->compress_meth;
193 i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
194 if (i >= 0)
195 *comp=sk_SSL_COMP_value(ssl_comp_methods,i);
196 else
197 *comp=NULL;
198 }
199 }
200
201 if ((enc == NULL) || (md == NULL)) return(0);
202
203 switch (c->algorithms & SSL_ENC_MASK)
204 {
205 case SSL_DES:
206 i=SSL_ENC_DES_IDX;
207 break;
208 case SSL_3DES:
209 i=SSL_ENC_3DES_IDX;
210 break;
211 case SSL_RC4:
212 i=SSL_ENC_RC4_IDX;
213 break;
214 case SSL_RC2:
215 i=SSL_ENC_RC2_IDX;
216 break;
217 case SSL_IDEA:
218 i=SSL_ENC_IDEA_IDX;
219 break;
220 case SSL_eNULL:
221 i=SSL_ENC_NULL_IDX;
222 break;
223 default:
224 i= -1;
225 break;
226 }
227
228 if ((i < 0) || (i > SSL_ENC_NUM_IDX))
229 *enc=NULL;
230 else
231 {
232 if (i == SSL_ENC_NULL_IDX)
233 *enc=EVP_enc_null();
234 else
235 *enc=ssl_cipher_methods[i];
236 }
237
238 switch (c->algorithms & SSL_MAC_MASK)
239 {
240 case SSL_MD5:
241 i=SSL_MD_MD5_IDX;
242 break;
243 case SSL_SHA1:
244 i=SSL_MD_SHA1_IDX;
245 break;
246 default:
247 i= -1;
248 break;
249 }
250 if ((i < 0) || (i > SSL_MD_NUM_IDX))
251 *md=NULL;
252 else
253 *md=ssl_digest_methods[i];
254
255 if ((*enc != NULL) && (*md != NULL))
256 return(1);
257 else
258 return(0);
259 }
260
261#define ITEM_SEP(a) \
262 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
263
264static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
265 CIPHER_ORDER **tail)
266 {
267 if (curr == *tail) return;
268 if (curr == *head)
269 *head=curr->next;
270 if (curr->prev != NULL)
271 curr->prev->next=curr->next;
272 if (curr->next != NULL) /* should always be true */
273 curr->next->prev=curr->prev;
274 (*tail)->next=curr;
275 curr->prev= *tail;
276 curr->next=NULL;
277 *tail=curr;
278 }
279
280static unsigned long ssl_cipher_get_disabled(void)
281 {
282 unsigned long mask;
283
284 mask = SSL_kFZA;
285#ifdef NO_RSA
286 mask |= SSL_aRSA|SSL_kRSA;
287#endif
288#ifdef NO_DSA
289 mask |= SSL_aDSS;
290#endif
291#ifdef NO_DH
292 mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
293#endif
294
295#ifdef SSL_FORBID_ENULL
296 mask |= SSL_eNULL;
297#endif
298
299 mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0;
300 mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0;
301 mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0;
302 mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0;
303 mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0;
304 mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0;
305
306 mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0;
307 mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0;
308
309 return(mask);
310 }
311
312static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
313 int num_of_ciphers, unsigned long mask, CIPHER_ORDER *list,
314 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
315 {
316 int i, list_num;
317 SSL_CIPHER *c;
318
319 /*
320 * We have num_of_ciphers descriptions compiled in, depending on the
321 * method selected (SSLv2 and/or SSLv3, TLSv1 etc).
322 * These will later be sorted in a linked list with at most num
323 * entries.
324 */
325
326 /* Get the initial list of ciphers */
327 list_num = 0; /* actual count of ciphers */
328 for (i = 0; i < num_of_ciphers; i++)
329 {
330 c = ssl_method->get_cipher(i);
331 /* drop those that use any of that is not available */
332 if ((c != NULL) && c->valid && !(c->algorithms & mask))
333 {
334 list[list_num].cipher = c;
335 list[list_num].next = NULL;
336 list[list_num].prev = NULL;
337 list[list_num].active = 0;
338 list_num++;
339 /*
340 if (!sk_push(ca_list,(char *)c)) goto err;
341 */
342 }
343 }
344
345 /*
346 * Prepare linked list from list entries
347 */
348 for (i = 1; i < list_num - 1; i++)
349 {
350 list[i].prev = &(list[i-1]);
351 list[i].next = &(list[i+1]);
352 }
353 if (list_num > 0)
354 {
355 (*head_p) = &(list[0]);
356 (*head_p)->prev = NULL;
357 (*head_p)->next = &(list[1]);
358 (*tail_p) = &(list[list_num - 1]);
359 (*tail_p)->prev = &(list[list_num - 2]);
360 (*tail_p)->next = NULL;
361 }
362 }
363
364static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list,
365 int num_of_group_aliases, unsigned long mask,
366 CIPHER_ORDER *head)
367 {
368 CIPHER_ORDER *ciph_curr;
369 SSL_CIPHER **ca_curr;
370 int i;
371
372 /*
373 * First, add the real ciphers as already collected
374 */
375 ciph_curr = head;
376 ca_curr = ca_list;
377 while (ciph_curr != NULL)
378 {
379 *ca_curr = ciph_curr->cipher;
380 ca_curr++;
381 ciph_curr = ciph_curr->next;
382 }
383
384 /*
385 * Now we add the available ones from the cipher_aliases[] table.
386 * They represent either an algorithm, that must be fully
387 * supported (not match any bit in mask) or represent a cipher
388 * strength value (will be added in any case because algorithms=0).
389 */
390 for (i = 0; i < num_of_group_aliases; i++)
391 {
392 if ((i == 0) || /* always fetch "ALL" */
393 !(cipher_aliases[i].algorithms & mask))
394 {
395 *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
396 ca_curr++;
397 }
398 }
399
400 *ca_curr = NULL; /* end of list */
401 }
402
403static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask,
404 unsigned long algo_strength, unsigned long mask_strength,
405 int rule, int strength_bits, CIPHER_ORDER *list,
406 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
407 {
408 CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2;
409 SSL_CIPHER *cp;
410 unsigned long ma, ma_s;
411
412#ifdef CIPHER_DEBUG
413 printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n",
414 rule, algorithms, mask, algo_strength, mask_strength,
415 strength_bits);
416#endif
417
418 curr = head = *head_p;
419 curr2 = head;
420 tail2 = tail = *tail_p;
421 for (;;)
422 {
423 if ((curr == NULL) || (curr == tail2)) break;
424 curr = curr2;
425 curr2 = curr->next;
426
427 cp = curr->cipher;
428
429 /*
430 * Selection criteria is either the number of strength_bits
431 * or the algorithm used.
432 */
433 if (strength_bits == -1)
434 {
435 ma = mask & cp->algorithms;
436 ma_s = mask_strength & cp->algo_strength;
437
438#ifdef CIPHER_DEBUG
439 printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength);
440 printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength);
441#endif
442 /*
443 * Select: if none of the mask bit was met from the
444 * cipher or not all of the bits were met, the
445 * selection does not apply.
446 */
447 if (((ma == 0) && (ma_s == 0)) ||
448 ((ma & algorithms) != ma) ||
449 ((ma_s & algo_strength) != ma_s))
450 continue; /* does not apply */
451 }
452 else if (strength_bits != cp->strength_bits)
453 continue; /* does not apply */
454
455#ifdef CIPHER_DEBUG
456 printf("Action = %d\n", rule);
457#endif
458
459 /* add the cipher if it has not been added yet. */
460 if (rule == CIPHER_ADD)
461 {
462 if (!curr->active)
463 {
464 ll_append_tail(&head, curr, &tail);
465 curr->active = 1;
466 }
467 }
468 /* Move the added cipher to this location */
469 else if (rule == CIPHER_ORD)
470 {
471 if (curr->active)
472 {
473 ll_append_tail(&head, curr, &tail);
474 }
475 }
476 else if (rule == CIPHER_DEL)
477 curr->active = 0;
478 else if (rule == CIPHER_KILL)
479 {
480 if (head == curr)
481 head = curr->next;
482 else
483 curr->prev->next = curr->next;
484 if (tail == curr)
485 tail = curr->prev;
486 curr->active = 0;
487 if (curr->next != NULL)
488 curr->next->prev = curr->prev;
489 if (curr->prev != NULL)
490 curr->prev->next = curr->next;
491 curr->next = NULL;
492 curr->prev = NULL;
493 }
494 }
495
496 *head_p = head;
497 *tail_p = tail;
498 }
499
500static int ssl_cipher_strength_sort(CIPHER_ORDER *list, CIPHER_ORDER **head_p,
501 CIPHER_ORDER **tail_p)
502 {
503 int max_strength_bits, i, *number_uses;
504 CIPHER_ORDER *curr;
505
506 /*
507 * This routine sorts the ciphers with descending strength. The sorting
508 * must keep the pre-sorted sequence, so we apply the normal sorting
509 * routine as '+' movement to the end of the list.
510 */
511 max_strength_bits = 0;
512 curr = *head_p;
513 while (curr != NULL)
514 {
515 if (curr->active &&
516 (curr->cipher->strength_bits > max_strength_bits))
517 max_strength_bits = curr->cipher->strength_bits;
518 curr = curr->next;
519 }
520
521 number_uses = Malloc((max_strength_bits + 1) * sizeof(int));
522 if (!number_uses)
523 {
524 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE);
525 return(0);
526 }
527 memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
528
529 /*
530 * Now find the strength_bits values actually used
531 */
532 curr = *head_p;
533 while (curr != NULL)
534 {
535 if (curr->active)
536 number_uses[curr->cipher->strength_bits]++;
537 curr = curr->next;
538 }
539 /*
540 * Go through the list of used strength_bits values in descending
541 * order.
542 */
543 for (i = max_strength_bits; i >= 0; i--)
544 if (number_uses[i] > 0)
545 ssl_cipher_apply_rule(0, 0, 0, 0, CIPHER_ORD, i,
546 list, head_p, tail_p);
547
548 Free(number_uses);
549 return(1);
550 }
551
552static int ssl_cipher_process_rulestr(const char *rule_str,
553 CIPHER_ORDER *list, CIPHER_ORDER **head_p,
554 CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)
555 {
556 unsigned long algorithms, mask, algo_strength, mask_strength;
557 const char *l, *start, *buf;
558 int j, multi, found, rule, retval, ok, buflen;
559 char ch;
560
561 retval = 1;
562 l = rule_str;
563 for (;;)
564 {
565 ch = *l;
566
567 if (ch == '\0')
568 break; /* done */
569 if (ch == '-')
570 { rule = CIPHER_DEL; l++; }
571 else if (ch == '+')
572 { rule = CIPHER_ORD; l++; }
573 else if (ch == '!')
574 { rule = CIPHER_KILL; l++; }
575 else if (ch == '@')
576 { rule = CIPHER_SPECIAL; l++; }
577 else
578 { rule = CIPHER_ADD; }
579
580 if (ITEM_SEP(ch))
581 {
582 l++;
583 continue;
584 }
585
586 algorithms = mask = algo_strength = mask_strength = 0;
587
588 start=l;
589 for (;;)
590 {
591 ch = *l;
592 buf = l;
593 buflen = 0;
594#ifndef CHARSET_EBCDIC
595 while ( ((ch >= 'A') && (ch <= 'Z')) ||
596 ((ch >= '0') && (ch <= '9')) ||
597 ((ch >= 'a') && (ch <= 'z')) ||
598 (ch == '-'))
599#else
600 while ( isalnum(ch) || (ch == '-'))
601#endif
602 {
603 ch = *(++l);
604 buflen++;
605 }
606
607 if (buflen == 0)
608 {
609 /*
610 * We hit something we cannot deal with,
611 * it is no command or separator nor
612 * alphanumeric, so we call this an error.
613 */
614 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
615 SSL_R_INVALID_COMMAND);
616 retval = found = 0;
617 l++;
618 break;
619 }
620
621 if (rule == CIPHER_SPECIAL)
622 {
623 found = 0; /* unused -- avoid compiler warning */
624 break; /* special treatment */
625 }
626
627 /* check for multi-part specification */
628 if (ch == '+')
629 {
630 multi=1;
631 l++;
632 }
633 else
634 multi=0;
635
636 /*
637 * Now search for the cipher alias in the ca_list. Be careful
638 * with the strncmp, because the "buflen" limitation
639 * will make the rule "ADH:SOME" and the cipher
640 * "ADH-MY-CIPHER" look like a match for buflen=3.
641 * So additionally check whether the cipher name found
642 * has the correct length. We can save a strlen() call:
643 * just checking for the '\0' at the right place is
644 * sufficient, we have to strncmp() anyway.
645 */
646 j = found = 0;
647 while (ca_list[j])
648 {
649 if ((ca_list[j]->name[buflen] == '\0') &&
650 !strncmp(buf, ca_list[j]->name, buflen))
651 {
652 found = 1;
653 break;
654 }
655 else
656 j++;
657 }
658 if (!found)
659 break; /* ignore this entry */
660
661 algorithms |= ca_list[j]->algorithms;
662 mask |= ca_list[j]->mask;
663 algo_strength |= ca_list[j]->algo_strength;
664 mask_strength |= ca_list[j]->mask_strength;
665
666 if (!multi) break;
667 }
668
669 /*
670 * Ok, we have the rule, now apply it
671 */
672 if (rule == CIPHER_SPECIAL)
673 { /* special command */
674 ok = 0;
675 if ((buflen == 8) &&
676 !strncmp(buf, "STRENGTH", 8))
677 ok = ssl_cipher_strength_sort(list,
678 head_p, tail_p);
679 else
680 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
681 SSL_R_INVALID_COMMAND);
682 if (ok == 0)
683 retval = 0;
684 /*
685 * We do not support any "multi" options
686 * together with "@", so throw away the
687 * rest of the command, if any left, until
688 * end or ':' is found.
689 */
690 while ((*l != '\0') && ITEM_SEP(*l))
691 l++;
692 }
693 else if (found)
694 {
695 ssl_cipher_apply_rule(algorithms, mask,
696 algo_strength, mask_strength, rule, -1,
697 list, head_p, tail_p);
698 }
699 else
700 {
701 while ((*l != '\0') && ITEM_SEP(*l))
702 l++;
703 }
704 if (*l == '\0') break; /* done */
705 }
706
707 return(retval);
708 }
709
710STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
711 STACK_OF(SSL_CIPHER) **cipher_list,
712 STACK_OF(SSL_CIPHER) **cipher_list_by_id,
713 const char *rule_str)
714 {
715 int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
716 unsigned long disabled_mask;
717 STACK_OF(SSL_CIPHER) *cipherstack;
718 const char *rule_p;
719 CIPHER_ORDER *list = NULL, *head = NULL, *tail = NULL, *curr;
720 SSL_CIPHER **ca_list = NULL;
721
722 /*
723 * Return with error if nothing to do.
724 */
725 if (rule_str == NULL) return(NULL);
726
727 if (init_ciphers) load_ciphers();
728
729 /*
730 * To reduce the work to do we only want to process the compiled
731 * in algorithms, so we first get the mask of disabled ciphers.
732 */
733 disabled_mask = ssl_cipher_get_disabled();
734
735 /*
736 * Now we have to collect the available ciphers from the compiled
737 * in ciphers. We cannot get more than the number compiled in, so
738 * it is used for allocation.
739 */
740 num_of_ciphers = ssl_method->num_ciphers();
741 list = (CIPHER_ORDER *)Malloc(sizeof(CIPHER_ORDER) * num_of_ciphers);
742 if (list == NULL)
743 {
744 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
745 return(NULL); /* Failure */
746 }
747
748 ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask,
749 list, &head, &tail);
750
751 /*
752 * We also need cipher aliases for selecting based on the rule_str.
753 * There might be two types of entries in the rule_str: 1) names
754 * of ciphers themselves 2) aliases for groups of ciphers.
755 * For 1) we need the available ciphers and for 2) the cipher
756 * groups of cipher_aliases added together in one list (otherwise
757 * we would be happy with just the cipher_aliases table).
758 */
759 num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
760 num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
761 ca_list =
762 (SSL_CIPHER **)Malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
763 if (ca_list == NULL)
764 {
765 Free(list);
766 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
767 return(NULL); /* Failure */
768 }
769 ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask,
770 head);
771
772 /*
773 * If the rule_string begins with DEFAULT, apply the default rule
774 * before using the (possibly available) additional rules.
775 */
776 ok = 1;
777 rule_p = rule_str;
778 if (strncmp(rule_str,"DEFAULT",7) == 0)
779 {
780 ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
781 list, &head, &tail, ca_list);
782 rule_p += 7;
783 if (*rule_p == ':')
784 rule_p++;
785 }
786
787 if (ok && (strlen(rule_p) > 0))
788 ok = ssl_cipher_process_rulestr(rule_p, list, &head, &tail,
789 ca_list);
790
791 Free(ca_list); /* Not needed anymore */
792
793 if (!ok)
794 { /* Rule processing failure */
795 Free(list);
796 return(NULL);
797 }
798 /*
799 * Allocate new "cipherstack" for the result, return with error
800 * if we cannot get one.
801 */
802 if ((cipherstack = sk_SSL_CIPHER_new(NULL)) == NULL)
803 {
804 Free(list);
805 return(NULL);
806 }
807
808 /*
809 * The cipher selection for the list is done. The ciphers are added
810 * to the resulting precedence to the STACK_OF(SSL_CIPHER).
811 */
812 for (curr = head; curr != NULL; curr = curr->next)
813 {
814 if (curr->active)
815 {
816 sk_SSL_CIPHER_push(cipherstack, curr->cipher);
817#ifdef CIPHER_DEBUG
818 printf("<%s>\n",curr->cipher->name);
819#endif
820 }
821 }
822 Free(list); /* Not needed any longer */
823
824 /*
825 * The following passage is a little bit odd. If pointer variables
826 * were supplied to hold STACK_OF(SSL_CIPHER) return information,
827 * the old memory pointed to is free()ed. Then, however, the
828 * cipher_list entry will be assigned just a copy of the returned
829 * cipher stack. For cipher_list_by_id a copy of the cipher stack
830 * will be created. See next comment...
831 */
832 if (cipher_list != NULL)
833 {
834 if (*cipher_list != NULL)
835 sk_SSL_CIPHER_free(*cipher_list);
836 *cipher_list = cipherstack;
837 }
838
839 if (cipher_list_by_id != NULL)
840 {
841 if (*cipher_list_by_id != NULL)
842 sk_SSL_CIPHER_free(*cipher_list_by_id);
843 *cipher_list_by_id = sk_SSL_CIPHER_dup(cipherstack);
844 }
845
846 /*
847 * Now it is getting really strange. If something failed during
848 * the previous pointer assignment or if one of the pointers was
849 * not requested, the error condition is met. That might be
850 * discussable. The strange thing is however that in this case
851 * the memory "ret" pointed to is "free()ed" and hence the pointer
852 * cipher_list becomes wild. The memory reserved for
853 * cipher_list_by_id however is not "free()ed" and stays intact.
854 */
855 if ( (cipher_list_by_id == NULL) ||
856 (*cipher_list_by_id == NULL) ||
857 (cipher_list == NULL) ||
858 (*cipher_list == NULL))
859 {
860 sk_SSL_CIPHER_free(cipherstack);
861 return(NULL);
862 }
863
864 sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
865
866 return(cipherstack);
867 }
868
869char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len)
870 {
871 int is_export,pkl,kl;
872 char *ver,*exp;
873 char *kx,*au,*enc,*mac;
874 unsigned long alg,alg2,alg_s;
875 static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
876
877 alg=cipher->algorithms;
878 alg_s=cipher->algo_strength;
879 alg2=cipher->algorithm2;
880
881 is_export=SSL_C_IS_EXPORT(cipher);
882 pkl=SSL_C_EXPORT_PKEYLENGTH(cipher);
883 kl=SSL_C_EXPORT_KEYLENGTH(cipher);
884 exp=is_export?" export":"";
885
886 if (alg & SSL_SSLV2)
887 ver="SSLv2";
888 else if (alg & SSL_SSLV3)
889 ver="SSLv3";
890 else
891 ver="unknown";
892
893 switch (alg&SSL_MKEY_MASK)
894 {
895 case SSL_kRSA:
896 kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA";
897 break;
898 case SSL_kDHr:
899 kx="DH/RSA";
900 break;
901 case SSL_kDHd:
902 kx="DH/DSS";
903 break;
904 case SSL_kFZA:
905 kx="Fortezza";
906 break;
907 case SSL_kEDH:
908 kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH";
909 break;
910 default:
911 kx="unknown";
912 }
913
914 switch (alg&SSL_AUTH_MASK)
915 {
916 case SSL_aRSA:
917 au="RSA";
918 break;
919 case SSL_aDSS:
920 au="DSS";
921 break;
922 case SSL_aDH:
923 au="DH";
924 break;
925 case SSL_aFZA:
926 case SSL_aNULL:
927 au="None";
928 break;
929 default:
930 au="unknown";
931 break;
932 }
933
934 switch (alg&SSL_ENC_MASK)
935 {
936 case SSL_DES:
937 enc=(is_export && kl == 5)?"DES(40)":"DES(56)";
938 break;
939 case SSL_3DES:
940 enc="3DES(168)";
941 break;
942 case SSL_RC4:
943 enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)")
944 :((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)");
945 break;
946 case SSL_RC2:
947 enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)";
948 break;
949 case SSL_IDEA:
950 enc="IDEA(128)";
951 break;
952 case SSL_eFZA:
953 enc="Fortezza";
954 break;
955 case SSL_eNULL:
956 enc="None";
957 break;
958 default:
959 enc="unknown";
960 break;
961 }
962
963 switch (alg&SSL_MAC_MASK)
964 {
965 case SSL_MD5:
966 mac="MD5";
967 break;
968 case SSL_SHA1:
969 mac="SHA1";
970 break;
971 default:
972 mac="unknown";
973 break;
974 }
975
976 if (buf == NULL)
977 {
978 buf=Malloc(128);
979 if (buf == NULL) return("Malloc Error");
980 }
981 else if (len < 128)
982 return("Buffer too small");
983
984 sprintf(buf,format,cipher->name,ver,kx,au,enc,mac,exp);
985 return(buf);
986 }
987
988char *SSL_CIPHER_get_version(SSL_CIPHER *c)
989 {
990 int i;
991
992 if (c == NULL) return("(NONE)");
993 i=(int)(c->id>>24L);
994 if (i == 3)
995 return("TLSv1/SSLv3");
996 else if (i == 2)
997 return("SSLv2");
998 else
999 return("unknown");
1000 }
1001
1002/* return the actual cipher being used */
1003const char *SSL_CIPHER_get_name(SSL_CIPHER *c)
1004 {
1005 if (c != NULL)
1006 return(c->name);
1007 return("(NONE)");
1008 }
1009
1010/* number of bits for symmetric cipher */
1011int SSL_CIPHER_get_bits(SSL_CIPHER *c, int *alg_bits)
1012 {
1013 int ret=0;
1014
1015 if (c != NULL)
1016 {
1017 if (alg_bits != NULL) *alg_bits = c->alg_bits;
1018 ret = c->strength_bits;
1019 }
1020 return(ret);
1021 }
1022
1023SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
1024 {
1025 SSL_COMP *ctmp;
1026 int i,nn;
1027
1028 if ((n == 0) || (sk == NULL)) return(NULL);
1029 nn=sk_SSL_COMP_num(sk);
1030 for (i=0; i<nn; i++)
1031 {
1032 ctmp=sk_SSL_COMP_value(sk,i);
1033 if (ctmp->id == n)
1034 return(ctmp);
1035 }
1036 return(NULL);
1037 }
1038
1039static int sk_comp_cmp(SSL_COMP **a,SSL_COMP **b)
1040 {
1041 return((*a)->id-(*b)->id);
1042 }
1043
1044STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void)
1045 {
1046 return(ssl_comp_methods);
1047 }
1048
1049int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
1050 {
1051 SSL_COMP *comp;
1052 STACK_OF(SSL_COMP) *sk;
1053
1054 comp=(SSL_COMP *)Malloc(sizeof(SSL_COMP));
1055 comp->id=id;
1056 comp->method=cm;
1057 if (ssl_comp_methods == NULL)
1058 sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp);
1059 else
1060 sk=ssl_comp_methods;
1061 if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp))
1062 {
1063 SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);
1064 return(0);
1065 }
1066 else
1067 return(1);
1068 }
1069
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
deleted file mode 100644
index 642c3f93e7..0000000000
--- a/src/lib/libssl/ssl_err.c
+++ /dev/null
@@ -1,430 +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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ssl.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA SSL_str_functs[]=
68 {
69{ERR_PACK(0,SSL_F_CLIENT_CERTIFICATE,0), "CLIENT_CERTIFICATE"},
70{ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"},
71{ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"},
72{ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"},
73{ERR_PACK(0,SSL_F_DO_SSL3_WRITE,0), "DO_SSL3_WRITE"},
74{ERR_PACK(0,SSL_F_GET_CLIENT_FINISHED,0), "GET_CLIENT_FINISHED"},
75{ERR_PACK(0,SSL_F_GET_CLIENT_HELLO,0), "GET_CLIENT_HELLO"},
76{ERR_PACK(0,SSL_F_GET_CLIENT_MASTER_KEY,0), "GET_CLIENT_MASTER_KEY"},
77{ERR_PACK(0,SSL_F_GET_SERVER_FINISHED,0), "GET_SERVER_FINISHED"},
78{ERR_PACK(0,SSL_F_GET_SERVER_HELLO,0), "GET_SERVER_HELLO"},
79{ERR_PACK(0,SSL_F_GET_SERVER_VERIFY,0), "GET_SERVER_VERIFY"},
80{ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"},
81{ERR_PACK(0,SSL_F_READ_N,0), "READ_N"},
82{ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"},
83{ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"},
84{ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"},
85{ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"},
86{ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"},
87{ERR_PACK(0,SSL_F_SSL23_GET_CLIENT_HELLO,0), "SSL23_GET_CLIENT_HELLO"},
88{ERR_PACK(0,SSL_F_SSL23_GET_SERVER_HELLO,0), "SSL23_GET_SERVER_HELLO"},
89{ERR_PACK(0,SSL_F_SSL23_READ,0), "SSL23_READ"},
90{ERR_PACK(0,SSL_F_SSL23_WRITE,0), "SSL23_WRITE"},
91{ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"},
92{ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"},
93{ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"},
94{ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"},
95{ERR_PACK(0,SSL_F_SSL2_SET_CERTIFICATE,0), "SSL2_SET_CERTIFICATE"},
96{ERR_PACK(0,SSL_F_SSL2_WRITE,0), "SSL2_WRITE"},
97{ERR_PACK(0,SSL_F_SSL3_ACCEPT,0), "SSL3_ACCEPT"},
98{ERR_PACK(0,SSL_F_SSL3_CALLBACK_CTRL,0), "SSL3_CALLBACK_CTRL"},
99{ERR_PACK(0,SSL_F_SSL3_CHANGE_CIPHER_STATE,0), "SSL3_CHANGE_CIPHER_STATE"},
100{ERR_PACK(0,SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,0), "SSL3_CHECK_CERT_AND_ALGORITHM"},
101{ERR_PACK(0,SSL_F_SSL3_CLIENT_HELLO,0), "SSL3_CLIENT_HELLO"},
102{ERR_PACK(0,SSL_F_SSL3_CONNECT,0), "SSL3_CONNECT"},
103{ERR_PACK(0,SSL_F_SSL3_CTRL,0), "SSL3_CTRL"},
104{ERR_PACK(0,SSL_F_SSL3_CTX_CTRL,0), "SSL3_CTX_CTRL"},
105{ERR_PACK(0,SSL_F_SSL3_ENC,0), "SSL3_ENC"},
106{ERR_PACK(0,SSL_F_SSL3_GET_CERTIFICATE_REQUEST,0), "SSL3_GET_CERTIFICATE_REQUEST"},
107{ERR_PACK(0,SSL_F_SSL3_GET_CERT_VERIFY,0), "SSL3_GET_CERT_VERIFY"},
108{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_CERTIFICATE,0), "SSL3_GET_CLIENT_CERTIFICATE"},
109{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_HELLO,0), "SSL3_GET_CLIENT_HELLO"},
110{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,0), "SSL3_GET_CLIENT_KEY_EXCHANGE"},
111{ERR_PACK(0,SSL_F_SSL3_GET_FINISHED,0), "SSL3_GET_FINISHED"},
112{ERR_PACK(0,SSL_F_SSL3_GET_KEY_EXCHANGE,0), "SSL3_GET_KEY_EXCHANGE"},
113{ERR_PACK(0,SSL_F_SSL3_GET_MESSAGE,0), "SSL3_GET_MESSAGE"},
114{ERR_PACK(0,SSL_F_SSL3_GET_RECORD,0), "SSL3_GET_RECORD"},
115{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_CERTIFICATE,0), "SSL3_GET_SERVER_CERTIFICATE"},
116{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_DONE,0), "SSL3_GET_SERVER_DONE"},
117{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_HELLO,0), "SSL3_GET_SERVER_HELLO"},
118{ERR_PACK(0,SSL_F_SSL3_OUTPUT_CERT_CHAIN,0), "SSL3_OUTPUT_CERT_CHAIN"},
119{ERR_PACK(0,SSL_F_SSL3_READ_BYTES,0), "SSL3_READ_BYTES"},
120{ERR_PACK(0,SSL_F_SSL3_READ_N,0), "SSL3_READ_N"},
121{ERR_PACK(0,SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,0), "SSL3_SEND_CERTIFICATE_REQUEST"},
122{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,0), "SSL3_SEND_CLIENT_CERTIFICATE"},
123{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"},
124{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"},
125{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"},
126{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"},
127{ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"},
128{ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"},
129{ERR_PACK(0,SSL_F_SSL3_WRITE_BYTES,0), "SSL3_WRITE_BYTES"},
130{ERR_PACK(0,SSL_F_SSL3_WRITE_PENDING,0), "SSL3_WRITE_PENDING"},
131{ERR_PACK(0,SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,0), "SSL_add_dir_cert_subjects_to_stack"},
132{ERR_PACK(0,SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,0), "SSL_add_file_cert_subjects_to_stack"},
133{ERR_PACK(0,SSL_F_SSL_BAD_METHOD,0), "SSL_BAD_METHOD"},
134{ERR_PACK(0,SSL_F_SSL_BYTES_TO_CIPHER_LIST,0), "SSL_BYTES_TO_CIPHER_LIST"},
135{ERR_PACK(0,SSL_F_SSL_CERT_DUP,0), "SSL_CERT_DUP"},
136{ERR_PACK(0,SSL_F_SSL_CERT_INST,0), "SSL_CERT_INST"},
137{ERR_PACK(0,SSL_F_SSL_CERT_INSTANTIATE,0), "SSL_CERT_INSTANTIATE"},
138{ERR_PACK(0,SSL_F_SSL_CERT_NEW,0), "SSL_CERT_NEW"},
139{ERR_PACK(0,SSL_F_SSL_CHECK_PRIVATE_KEY,0), "SSL_check_private_key"},
140{ERR_PACK(0,SSL_F_SSL_CIPHER_PROCESS_RULESTR,0), "SSL_CIPHER_PROCESS_RULESTR"},
141{ERR_PACK(0,SSL_F_SSL_CIPHER_STRENGTH_SORT,0), "SSL_CIPHER_STRENGTH_SORT"},
142{ERR_PACK(0,SSL_F_SSL_CLEAR,0), "SSL_clear"},
143{ERR_PACK(0,SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,0), "SSL_COMP_add_compression_method"},
144{ERR_PACK(0,SSL_F_SSL_CREATE_CIPHER_LIST,0), "SSL_CREATE_CIPHER_LIST"},
145{ERR_PACK(0,SSL_F_SSL_CTRL,0), "SSL_ctrl"},
146{ERR_PACK(0,SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,0), "SSL_CTX_check_private_key"},
147{ERR_PACK(0,SSL_F_SSL_CTX_NEW,0), "SSL_CTX_new"},
148{ERR_PACK(0,SSL_F_SSL_CTX_SET_PURPOSE,0), "SSL_CTX_set_purpose"},
149{ERR_PACK(0,SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,0), "SSL_CTX_set_session_id_context"},
150{ERR_PACK(0,SSL_F_SSL_CTX_SET_SSL_VERSION,0), "SSL_CTX_set_ssl_version"},
151{ERR_PACK(0,SSL_F_SSL_CTX_SET_TRUST,0), "SSL_CTX_set_trust"},
152{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE,0), "SSL_CTX_use_certificate"},
153{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,0), "SSL_CTX_use_certificate_ASN1"},
154{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,0), "SSL_CTX_use_certificate_chain_file"},
155{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,0), "SSL_CTX_use_certificate_file"},
156{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY,0), "SSL_CTX_use_PrivateKey"},
157{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,0), "SSL_CTX_use_PrivateKey_ASN1"},
158{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,0), "SSL_CTX_use_PrivateKey_file"},
159{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,0), "SSL_CTX_use_RSAPrivateKey"},
160{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,0), "SSL_CTX_use_RSAPrivateKey_ASN1"},
161{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,0), "SSL_CTX_use_RSAPrivateKey_file"},
162{ERR_PACK(0,SSL_F_SSL_DO_HANDSHAKE,0), "SSL_do_handshake"},
163{ERR_PACK(0,SSL_F_SSL_GET_NEW_SESSION,0), "SSL_GET_NEW_SESSION"},
164{ERR_PACK(0,SSL_F_SSL_GET_PREV_SESSION,0), "SSL_GET_PREV_SESSION"},
165{ERR_PACK(0,SSL_F_SSL_GET_SERVER_SEND_CERT,0), "SSL_GET_SERVER_SEND_CERT"},
166{ERR_PACK(0,SSL_F_SSL_GET_SIGN_PKEY,0), "SSL_GET_SIGN_PKEY"},
167{ERR_PACK(0,SSL_F_SSL_INIT_WBIO_BUFFER,0), "SSL_INIT_WBIO_BUFFER"},
168{ERR_PACK(0,SSL_F_SSL_LOAD_CLIENT_CA_FILE,0), "SSL_load_client_CA_file"},
169{ERR_PACK(0,SSL_F_SSL_NEW,0), "SSL_new"},
170{ERR_PACK(0,SSL_F_SSL_READ,0), "SSL_read"},
171{ERR_PACK(0,SSL_F_SSL_RSA_PRIVATE_DECRYPT,0), "SSL_RSA_PRIVATE_DECRYPT"},
172{ERR_PACK(0,SSL_F_SSL_RSA_PUBLIC_ENCRYPT,0), "SSL_RSA_PUBLIC_ENCRYPT"},
173{ERR_PACK(0,SSL_F_SSL_SESSION_NEW,0), "SSL_SESSION_new"},
174{ERR_PACK(0,SSL_F_SSL_SESSION_PRINT_FP,0), "SSL_SESSION_print_fp"},
175{ERR_PACK(0,SSL_F_SSL_SESS_CERT_NEW,0), "SSL_SESS_CERT_NEW"},
176{ERR_PACK(0,SSL_F_SSL_SET_CERT,0), "SSL_SET_CERT"},
177{ERR_PACK(0,SSL_F_SSL_SET_FD,0), "SSL_set_fd"},
178{ERR_PACK(0,SSL_F_SSL_SET_PKEY,0), "SSL_SET_PKEY"},
179{ERR_PACK(0,SSL_F_SSL_SET_PURPOSE,0), "SSL_set_purpose"},
180{ERR_PACK(0,SSL_F_SSL_SET_RFD,0), "SSL_set_rfd"},
181{ERR_PACK(0,SSL_F_SSL_SET_SESSION,0), "SSL_set_session"},
182{ERR_PACK(0,SSL_F_SSL_SET_SESSION_ID_CONTEXT,0), "SSL_set_session_id_context"},
183{ERR_PACK(0,SSL_F_SSL_SET_TRUST,0), "SSL_set_trust"},
184{ERR_PACK(0,SSL_F_SSL_SET_WFD,0), "SSL_set_wfd"},
185{ERR_PACK(0,SSL_F_SSL_SHUTDOWN,0), "SSL_shutdown"},
186{ERR_PACK(0,SSL_F_SSL_UNDEFINED_FUNCTION,0), "SSL_UNDEFINED_FUNCTION"},
187{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE,0), "SSL_use_certificate"},
188{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_ASN1,0), "SSL_use_certificate_ASN1"},
189{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_FILE,0), "SSL_use_certificate_file"},
190{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY,0), "SSL_use_PrivateKey"},
191{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_ASN1,0), "SSL_use_PrivateKey_ASN1"},
192{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_FILE,0), "SSL_use_PrivateKey_file"},
193{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY,0), "SSL_use_RSAPrivateKey"},
194{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,0), "SSL_use_RSAPrivateKey_ASN1"},
195{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,0), "SSL_use_RSAPrivateKey_file"},
196{ERR_PACK(0,SSL_F_SSL_VERIFY_CERT_CHAIN,0), "SSL_VERIFY_CERT_CHAIN"},
197{ERR_PACK(0,SSL_F_SSL_WRITE,0), "SSL_write"},
198{ERR_PACK(0,SSL_F_TLS1_CHANGE_CIPHER_STATE,0), "TLS1_CHANGE_CIPHER_STATE"},
199{ERR_PACK(0,SSL_F_TLS1_ENC,0), "TLS1_ENC"},
200{ERR_PACK(0,SSL_F_TLS1_SETUP_KEY_BLOCK,0), "TLS1_SETUP_KEY_BLOCK"},
201{ERR_PACK(0,SSL_F_WRITE_PENDING,0), "WRITE_PENDING"},
202{0,NULL}
203 };
204
205static ERR_STRING_DATA SSL_str_reasons[]=
206 {
207{SSL_R_APP_DATA_IN_HANDSHAKE ,"app data in handshake"},
208{SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT,"attempt to reuse session in different context"},
209{SSL_R_BAD_ALERT_RECORD ,"bad alert record"},
210{SSL_R_BAD_AUTHENTICATION_TYPE ,"bad authentication type"},
211{SSL_R_BAD_CHANGE_CIPHER_SPEC ,"bad change cipher spec"},
212{SSL_R_BAD_CHECKSUM ,"bad checksum"},
213{SSL_R_BAD_DATA_RETURNED_BY_CALLBACK ,"bad data returned by callback"},
214{SSL_R_BAD_DECOMPRESSION ,"bad decompression"},
215{SSL_R_BAD_DH_G_LENGTH ,"bad dh g length"},
216{SSL_R_BAD_DH_PUB_KEY_LENGTH ,"bad dh pub key length"},
217{SSL_R_BAD_DH_P_LENGTH ,"bad dh p length"},
218{SSL_R_BAD_DIGEST_LENGTH ,"bad digest length"},
219{SSL_R_BAD_DSA_SIGNATURE ,"bad dsa signature"},
220{SSL_R_BAD_HELLO_REQUEST ,"bad hello request"},
221{SSL_R_BAD_LENGTH ,"bad length"},
222{SSL_R_BAD_MAC_DECODE ,"bad mac decode"},
223{SSL_R_BAD_MESSAGE_TYPE ,"bad message type"},
224{SSL_R_BAD_PACKET_LENGTH ,"bad packet length"},
225{SSL_R_BAD_PROTOCOL_VERSION_NUMBER ,"bad protocol version number"},
226{SSL_R_BAD_RESPONSE_ARGUMENT ,"bad response argument"},
227{SSL_R_BAD_RSA_DECRYPT ,"bad rsa decrypt"},
228{SSL_R_BAD_RSA_ENCRYPT ,"bad rsa encrypt"},
229{SSL_R_BAD_RSA_E_LENGTH ,"bad rsa e length"},
230{SSL_R_BAD_RSA_MODULUS_LENGTH ,"bad rsa modulus length"},
231{SSL_R_BAD_RSA_SIGNATURE ,"bad rsa signature"},
232{SSL_R_BAD_SIGNATURE ,"bad signature"},
233{SSL_R_BAD_SSL_FILETYPE ,"bad ssl filetype"},
234{SSL_R_BAD_SSL_SESSION_ID_LENGTH ,"bad ssl session id length"},
235{SSL_R_BAD_STATE ,"bad state"},
236{SSL_R_BAD_WRITE_RETRY ,"bad write retry"},
237{SSL_R_BIO_NOT_SET ,"bio not set"},
238{SSL_R_BLOCK_CIPHER_PAD_IS_WRONG ,"block cipher pad is wrong"},
239{SSL_R_BN_LIB ,"bn lib"},
240{SSL_R_CA_DN_LENGTH_MISMATCH ,"ca dn length mismatch"},
241{SSL_R_CA_DN_TOO_LONG ,"ca dn too long"},
242{SSL_R_CCS_RECEIVED_EARLY ,"ccs received early"},
243{SSL_R_CERTIFICATE_VERIFY_FAILED ,"certificate verify failed"},
244{SSL_R_CERT_LENGTH_MISMATCH ,"cert length mismatch"},
245{SSL_R_CHALLENGE_IS_DIFFERENT ,"challenge is different"},
246{SSL_R_CIPHER_CODE_WRONG_LENGTH ,"cipher code wrong length"},
247{SSL_R_CIPHER_OR_HASH_UNAVAILABLE ,"cipher or hash unavailable"},
248{SSL_R_CIPHER_TABLE_SRC_ERROR ,"cipher table src error"},
249{SSL_R_COMPRESSED_LENGTH_TOO_LONG ,"compressed length too long"},
250{SSL_R_COMPRESSION_FAILURE ,"compression failure"},
251{SSL_R_COMPRESSION_LIBRARY_ERROR ,"compression library error"},
252{SSL_R_CONNECTION_ID_IS_DIFFERENT ,"connection id is different"},
253{SSL_R_CONNECTION_TYPE_NOT_SET ,"connection type not set"},
254{SSL_R_DATA_BETWEEN_CCS_AND_FINISHED ,"data between ccs and finished"},
255{SSL_R_DATA_LENGTH_TOO_LONG ,"data length too long"},
256{SSL_R_DECRYPTION_FAILED ,"decryption failed"},
257{SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG ,"dh public value length is wrong"},
258{SSL_R_DIGEST_CHECK_FAILED ,"digest check failed"},
259{SSL_R_ENCRYPTED_LENGTH_TOO_LONG ,"encrypted length too long"},
260{SSL_R_ERROR_GENERATING_TMP_RSA_KEY ,"error generating tmp rsa key"},
261{SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST ,"error in received cipher list"},
262{SSL_R_EXCESSIVE_MESSAGE_SIZE ,"excessive message size"},
263{SSL_R_EXTRA_DATA_IN_MESSAGE ,"extra data in message"},
264{SSL_R_GOT_A_FIN_BEFORE_A_CCS ,"got a fin before a ccs"},
265{SSL_R_HTTPS_PROXY_REQUEST ,"https proxy request"},
266{SSL_R_HTTP_REQUEST ,"http request"},
267{SSL_R_INTERNAL_ERROR ,"internal error"},
268{SSL_R_INVALID_CHALLENGE_LENGTH ,"invalid challenge length"},
269{SSL_R_INVALID_COMMAND ,"invalid command"},
270{SSL_R_INVALID_PURPOSE ,"invalid purpose"},
271{SSL_R_INVALID_TRUST ,"invalid trust"},
272{SSL_R_LENGTH_MISMATCH ,"length mismatch"},
273{SSL_R_LENGTH_TOO_SHORT ,"length too short"},
274{SSL_R_LIBRARY_BUG ,"library bug"},
275{SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"},
276{SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"},
277{SSL_R_MISSING_DH_KEY ,"missing dh key"},
278{SSL_R_MISSING_DH_RSA_CERT ,"missing dh rsa cert"},
279{SSL_R_MISSING_DSA_SIGNING_CERT ,"missing dsa signing cert"},
280{SSL_R_MISSING_EXPORT_TMP_DH_KEY ,"missing export tmp dh key"},
281{SSL_R_MISSING_EXPORT_TMP_RSA_KEY ,"missing export tmp rsa key"},
282{SSL_R_MISSING_RSA_CERTIFICATE ,"missing rsa certificate"},
283{SSL_R_MISSING_RSA_ENCRYPTING_CERT ,"missing rsa encrypting cert"},
284{SSL_R_MISSING_RSA_SIGNING_CERT ,"missing rsa signing cert"},
285{SSL_R_MISSING_TMP_DH_KEY ,"missing tmp dh key"},
286{SSL_R_MISSING_TMP_RSA_KEY ,"missing tmp rsa key"},
287{SSL_R_MISSING_TMP_RSA_PKEY ,"missing tmp rsa pkey"},
288{SSL_R_MISSING_VERIFY_MESSAGE ,"missing verify message"},
289{SSL_R_NON_SSLV2_INITIAL_PACKET ,"non sslv2 initial packet"},
290{SSL_R_NO_CERTIFICATES_RETURNED ,"no certificates returned"},
291{SSL_R_NO_CERTIFICATE_ASSIGNED ,"no certificate assigned"},
292{SSL_R_NO_CERTIFICATE_RETURNED ,"no certificate returned"},
293{SSL_R_NO_CERTIFICATE_SET ,"no certificate set"},
294{SSL_R_NO_CERTIFICATE_SPECIFIED ,"no certificate specified"},
295{SSL_R_NO_CIPHERS_AVAILABLE ,"no ciphers available"},
296{SSL_R_NO_CIPHERS_PASSED ,"no ciphers passed"},
297{SSL_R_NO_CIPHERS_SPECIFIED ,"no ciphers specified"},
298{SSL_R_NO_CIPHER_LIST ,"no cipher list"},
299{SSL_R_NO_CIPHER_MATCH ,"no cipher match"},
300{SSL_R_NO_CLIENT_CERT_RECEIVED ,"no client cert received"},
301{SSL_R_NO_COMPRESSION_SPECIFIED ,"no compression specified"},
302{SSL_R_NO_METHOD_SPECIFIED ,"no method specified"},
303{SSL_R_NO_PRIVATEKEY ,"no privatekey"},
304{SSL_R_NO_PRIVATE_KEY_ASSIGNED ,"no private key assigned"},
305{SSL_R_NO_PROTOCOLS_AVAILABLE ,"no protocols available"},
306{SSL_R_NO_PUBLICKEY ,"no publickey"},
307{SSL_R_NO_SHARED_CIPHER ,"no shared cipher"},
308{SSL_R_NO_VERIFY_CALLBACK ,"no verify callback"},
309{SSL_R_NULL_SSL_CTX ,"null ssl ctx"},
310{SSL_R_NULL_SSL_METHOD_PASSED ,"null ssl method passed"},
311{SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED ,"old session cipher not returned"},
312{SSL_R_PACKET_LENGTH_TOO_LONG ,"packet length too long"},
313{SSL_R_PATH_TOO_LONG ,"path too long"},
314{SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE ,"peer did not return a certificate"},
315{SSL_R_PEER_ERROR ,"peer error"},
316{SSL_R_PEER_ERROR_CERTIFICATE ,"peer error certificate"},
317{SSL_R_PEER_ERROR_NO_CERTIFICATE ,"peer error no certificate"},
318{SSL_R_PEER_ERROR_NO_CIPHER ,"peer error no cipher"},
319{SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"peer error unsupported certificate type"},
320{SSL_R_PRE_MAC_LENGTH_TOO_LONG ,"pre mac length too long"},
321{SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS ,"problems mapping cipher functions"},
322{SSL_R_PROTOCOL_IS_SHUTDOWN ,"protocol is shutdown"},
323{SSL_R_PUBLIC_KEY_ENCRYPT_ERROR ,"public key encrypt error"},
324{SSL_R_PUBLIC_KEY_IS_NOT_RSA ,"public key is not rsa"},
325{SSL_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
326{SSL_R_READ_BIO_NOT_SET ,"read bio not set"},
327{SSL_R_READ_WRONG_PACKET_TYPE ,"read wrong packet type"},
328{SSL_R_RECORD_LENGTH_MISMATCH ,"record length mismatch"},
329{SSL_R_RECORD_TOO_LARGE ,"record too large"},
330{SSL_R_REQUIRED_CIPHER_MISSING ,"required cipher missing"},
331{SSL_R_REUSE_CERT_LENGTH_NOT_ZERO ,"reuse cert length not zero"},
332{SSL_R_REUSE_CERT_TYPE_NOT_ZERO ,"reuse cert type not zero"},
333{SSL_R_REUSE_CIPHER_LIST_NOT_ZERO ,"reuse cipher list not zero"},
334{SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED ,"session id context uninitialized"},
335{SSL_R_SHORT_READ ,"short read"},
336{SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"},
337{SSL_R_SSL23_DOING_SESSION_ID_REUSE ,"ssl23 doing session id reuse"},
338{SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"},
339{SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"},
340{SSL_R_SSLV3_ALERT_BAD_RECORD_MAC ,"sslv3 alert bad record mac"},
341{SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED ,"sslv3 alert certificate expired"},
342{SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED ,"sslv3 alert certificate revoked"},
343{SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN ,"sslv3 alert certificate unknown"},
344{SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE ,"sslv3 alert decompression failure"},
345{SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE ,"sslv3 alert handshake failure"},
346{SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER ,"sslv3 alert illegal parameter"},
347{SSL_R_SSLV3_ALERT_NO_CERTIFICATE ,"sslv3 alert no certificate"},
348{SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE,"sslv3 alert peer error certificate"},
349{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE,"sslv3 alert peer error no certificate"},
350{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER ,"sslv3 alert peer error no cipher"},
351{SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"sslv3 alert peer error unsupported certificate type"},
352{SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE ,"sslv3 alert unexpected message"},
353{SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE,"sslv3 alert unknown remote error type"},
354{SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE,"sslv3 alert unsupported certificate"},
355{SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION,"ssl ctx has no default ssl version"},
356{SSL_R_SSL_HANDSHAKE_FAILURE ,"ssl handshake failure"},
357{SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS ,"ssl library has no ciphers"},
358{SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG ,"ssl session id context too long"},
359{SSL_R_SSL_SESSION_ID_IS_DIFFERENT ,"ssl session id is different"},
360{SSL_R_TLSV1_ALERT_ACCESS_DENIED ,"tlsv1 alert access denied"},
361{SSL_R_TLSV1_ALERT_DECODE_ERROR ,"tlsv1 alert decode error"},
362{SSL_R_TLSV1_ALERT_DECRYPTION_FAILED ,"tlsv1 alert decryption failed"},
363{SSL_R_TLSV1_ALERT_DECRYPT_ERROR ,"tlsv1 alert decrypt error"},
364{SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION ,"tlsv1 alert export restriction"},
365{SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY ,"tlsv1 alert insufficient security"},
366{SSL_R_TLSV1_ALERT_INTERNAL_ERROR ,"tlsv1 alert internal error"},
367{SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ,"tlsv1 alert no renegotiation"},
368{SSL_R_TLSV1_ALERT_PROTOCOL_VERSION ,"tlsv1 alert protocol version"},
369{SSL_R_TLSV1_ALERT_RECORD_OVERFLOW ,"tlsv1 alert record overflow"},
370{SSL_R_TLSV1_ALERT_UNKNOWN_CA ,"tlsv1 alert unknown ca"},
371{SSL_R_TLSV1_ALERT_USER_CANCELLED ,"tlsv1 alert user cancelled"},
372{SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER,"tls client cert req with anon cipher"},
373{SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST,"tls peer did not respond with certificate list"},
374{SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG,"tls rsa encrypted value length is wrong"},
375{SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER ,"tried to use unsupported cipher"},
376{SSL_R_UNABLE_TO_DECODE_DH_CERTS ,"unable to decode dh certs"},
377{SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY ,"unable to extract public key"},
378{SSL_R_UNABLE_TO_FIND_DH_PARAMETERS ,"unable to find dh parameters"},
379{SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS,"unable to find public key parameters"},
380{SSL_R_UNABLE_TO_FIND_SSL_METHOD ,"unable to find ssl method"},
381{SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES ,"unable to load ssl2 md5 routines"},
382{SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES ,"unable to load ssl3 md5 routines"},
383{SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES ,"unable to load ssl3 sha1 routines"},
384{SSL_R_UNEXPECTED_MESSAGE ,"unexpected message"},
385{SSL_R_UNEXPECTED_RECORD ,"unexpected record"},
386{SSL_R_UNINITIALIZED ,"uninitialized"},
387{SSL_R_UNKNOWN_ALERT_TYPE ,"unknown alert type"},
388{SSL_R_UNKNOWN_CERTIFICATE_TYPE ,"unknown certificate type"},
389{SSL_R_UNKNOWN_CIPHER_RETURNED ,"unknown cipher returned"},
390{SSL_R_UNKNOWN_CIPHER_TYPE ,"unknown cipher type"},
391{SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE ,"unknown key exchange type"},
392{SSL_R_UNKNOWN_PKEY_TYPE ,"unknown pkey type"},
393{SSL_R_UNKNOWN_PROTOCOL ,"unknown protocol"},
394{SSL_R_UNKNOWN_REMOTE_ERROR_TYPE ,"unknown remote error type"},
395{SSL_R_UNKNOWN_SSL_VERSION ,"unknown ssl version"},
396{SSL_R_UNKNOWN_STATE ,"unknown state"},
397{SSL_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
398{SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM ,"unsupported compression algorithm"},
399{SSL_R_UNSUPPORTED_OPTION ,"unsupported option"},
400{SSL_R_UNSUPPORTED_PROTOCOL ,"unsupported protocol"},
401{SSL_R_UNSUPPORTED_SSL_VERSION ,"unsupported ssl version"},
402{SSL_R_WRITE_BIO_NOT_SET ,"write bio not set"},
403{SSL_R_WRONG_CIPHER_RETURNED ,"wrong cipher returned"},
404{SSL_R_WRONG_MESSAGE_TYPE ,"wrong message type"},
405{SSL_R_WRONG_NUMBER_OF_KEY_BITS ,"wrong number of key bits"},
406{SSL_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
407{SSL_R_WRONG_SIGNATURE_SIZE ,"wrong signature size"},
408{SSL_R_WRONG_SSL_VERSION ,"wrong ssl version"},
409{SSL_R_WRONG_VERSION_NUMBER ,"wrong version number"},
410{SSL_R_X509_LIB ,"x509 lib"},
411{SSL_R_X509_VERIFICATION_SETUP_PROBLEMS ,"x509 verification setup problems"},
412{0,NULL}
413 };
414
415#endif
416
417void ERR_load_SSL_strings(void)
418 {
419 static int init=1;
420
421 if (init)
422 {
423 init=0;
424#ifndef NO_ERR
425 ERR_load_strings(ERR_LIB_SSL,SSL_str_functs);
426 ERR_load_strings(ERR_LIB_SSL,SSL_str_reasons);
427#endif
428
429 }
430 }
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 c515c41b4e..0000000000
--- a/src/lib/libssl/ssl_lib.c
+++ /dev/null
@@ -1,2061 +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 <openssl/x509v3.h>
65#include "ssl_locl.h"
66
67const char *SSL_version_str=OPENSSL_VERSION_TEXT;
68
69static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_meth=NULL;
70static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_ctx_meth=NULL;
71static int ssl_meth_num=0;
72static int ssl_ctx_meth_num=0;
73
74OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={
75 /* evil casts, but these functions are only called if there's a library bug */
76 (int (*)(SSL *,int))ssl_undefined_function,
77 (int (*)(SSL *, unsigned char *, int))ssl_undefined_function,
78 ssl_undefined_function,
79 (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function,
80 (int (*)(SSL*, int))ssl_undefined_function,
81 (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function
82 };
83
84int SSL_clear(SSL *s)
85 {
86 int state;
87
88 if (s->method == NULL)
89 {
90 SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);
91 return(0);
92 }
93
94 s->error=0;
95 s->hit=0;
96 s->shutdown=0;
97
98#if 0 /* Disabled since version 1.10 of this file (early return not
99 * needed because SSL_clear is not called when doing renegotiation) */
100 /* This is set if we are doing dynamic renegotiation so keep
101 * the old cipher. It is sort of a SSL_clear_lite :-) */
102 if (s->new_session) return(1);
103#else
104 if (s->new_session)
105 {
106 SSLerr(SSL_F_SSL_CLEAR,SSL_R_INTERNAL_ERROR);
107 return 0;
108 }
109#endif
110
111 state=s->state; /* Keep to check if we throw away the session-id */
112 s->type=0;
113
114 s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);
115
116 s->version=s->method->version;
117 s->client_version=s->version;
118 s->rwstate=SSL_NOTHING;
119 s->rstate=SSL_ST_READ_HEADER;
120 s->read_ahead=s->ctx->read_ahead;
121
122 if (s->init_buf != NULL)
123 {
124 BUF_MEM_free(s->init_buf);
125 s->init_buf=NULL;
126 }
127
128 ssl_clear_cipher_ctx(s);
129
130 if (ssl_clear_bad_session(s))
131 {
132 SSL_SESSION_free(s->session);
133 s->session=NULL;
134 }
135
136 s->first_packet=0;
137
138#if 1
139 /* Check to see if we were changed into a different method, if
140 * so, revert back if we are not doing session-id reuse. */
141 if ((s->session == NULL) && (s->method != s->ctx->method))
142 {
143 s->method->ssl_free(s);
144 s->method=s->ctx->method;
145 if (!s->method->ssl_new(s))
146 return(0);
147 }
148 else
149#endif
150 s->method->ssl_clear(s);
151 return(1);
152 }
153
154/** Used to change an SSL_CTXs default SSL method type */
155int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth)
156 {
157 STACK_OF(SSL_CIPHER) *sk;
158
159 ctx->method=meth;
160
161 sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list),
162 &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST);
163 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0))
164 {
165 SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
166 return(0);
167 }
168 return(1);
169 }
170
171SSL *SSL_new(SSL_CTX *ctx)
172 {
173 SSL *s;
174
175 if (ctx == NULL)
176 {
177 SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);
178 return(NULL);
179 }
180 if (ctx->method == NULL)
181 {
182 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
183 return(NULL);
184 }
185
186 s=(SSL *)Malloc(sizeof(SSL));
187 if (s == NULL) goto err;
188 memset(s,0,sizeof(SSL));
189
190 if (ctx->cert != NULL)
191 {
192 /* Earlier library versions used to copy the pointer to
193 * the CERT, not its contents; only when setting new
194 * parameters for the per-SSL copy, ssl_cert_new would be
195 * called (and the direct reference to the per-SSL_CTX
196 * settings would be lost, but those still were indirectly
197 * accessed for various purposes, and for that reason they
198 * used to be known as s->ctx->default_cert).
199 * Now we don't look at the SSL_CTX's CERT after having
200 * duplicated it once. */
201
202 s->cert = ssl_cert_dup(ctx->cert);
203 if (s->cert == NULL)
204 goto err;
205 }
206 else
207 s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */
208 s->sid_ctx_length=ctx->sid_ctx_length;
209 memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));
210 s->verify_mode=ctx->verify_mode;
211 s->verify_depth=ctx->verify_depth;
212 s->verify_callback=ctx->default_verify_callback;
213 s->purpose = ctx->purpose;
214 s->trust = ctx->trust;
215 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
216 s->ctx=ctx;
217
218 s->verify_result=X509_V_OK;
219
220 s->method=ctx->method;
221
222 if (!s->method->ssl_new(s))
223 goto err;
224
225 s->quiet_shutdown=ctx->quiet_shutdown;
226 s->references=1;
227 s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;
228 s->options=ctx->options;
229 s->mode=ctx->mode;
230 SSL_clear(s);
231
232 CRYPTO_new_ex_data(ssl_meth,s,&s->ex_data);
233
234 return(s);
235err:
236 if (s != NULL)
237 {
238 if (s->cert != NULL)
239 ssl_cert_free(s->cert);
240 if (s->ctx != NULL)
241 SSL_CTX_free(s->ctx); /* decrement reference count */
242 Free(s);
243 }
244 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
245 return(NULL);
246 }
247
248int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
249 unsigned int sid_ctx_len)
250 {
251 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
252 {
253 SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
254 return 0;
255 }
256 ctx->sid_ctx_length=sid_ctx_len;
257 memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len);
258
259 return 1;
260 }
261
262int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
263 unsigned int sid_ctx_len)
264 {
265 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
266 {
267 SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
268 return 0;
269 }
270 ssl->sid_ctx_length=sid_ctx_len;
271 memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len);
272
273 return 1;
274 }
275
276int SSL_CTX_set_purpose(SSL_CTX *s, int purpose)
277{
278 if(X509_PURPOSE_get_by_id(purpose) == -1) {
279 SSLerr(SSL_F_SSL_CTX_SET_PURPOSE, SSL_R_INVALID_PURPOSE);
280 return 0;
281 }
282 s->purpose = purpose;
283 return 1;
284}
285
286int SSL_set_purpose(SSL *s, int purpose)
287{
288 if(X509_PURPOSE_get_by_id(purpose) == -1) {
289 SSLerr(SSL_F_SSL_SET_PURPOSE, SSL_R_INVALID_PURPOSE);
290 return 0;
291 }
292 s->purpose = purpose;
293 return 1;
294}
295
296int SSL_CTX_set_trust(SSL_CTX *s, int trust)
297{
298 if(X509_TRUST_get_by_id(trust) == -1) {
299 SSLerr(SSL_F_SSL_CTX_SET_TRUST, SSL_R_INVALID_TRUST);
300 return 0;
301 }
302 s->trust = trust;
303 return 1;
304}
305
306int SSL_set_trust(SSL *s, int trust)
307{
308 if(X509_TRUST_get_by_id(trust) == -1) {
309 SSLerr(SSL_F_SSL_SET_TRUST, SSL_R_INVALID_TRUST);
310 return 0;
311 }
312 s->trust = trust;
313 return 1;
314}
315
316void SSL_free(SSL *s)
317 {
318 int i;
319
320 if(s == NULL)
321 return;
322
323 i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);
324#ifdef REF_PRINT
325 REF_PRINT("SSL",s);
326#endif
327 if (i > 0) return;
328#ifdef REF_CHECK
329 if (i < 0)
330 {
331 fprintf(stderr,"SSL_free, bad reference count\n");
332 abort(); /* ok */
333 }
334#endif
335
336 CRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data);
337
338 if (s->bbio != NULL)
339 {
340 /* If the buffering BIO is in place, pop it off */
341 if (s->bbio == s->wbio)
342 {
343 s->wbio=BIO_pop(s->wbio);
344 }
345 BIO_free(s->bbio);
346 s->bbio=NULL;
347 }
348 if (s->rbio != NULL)
349 BIO_free_all(s->rbio);
350 if ((s->wbio != NULL) && (s->wbio != s->rbio))
351 BIO_free_all(s->wbio);
352
353 if (s->init_buf != NULL) BUF_MEM_free(s->init_buf);
354
355 /* add extra stuff */
356 if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);
357 if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);
358
359 /* Make the next call work :-) */
360 if (s->session != NULL)
361 {
362 ssl_clear_bad_session(s);
363 SSL_SESSION_free(s->session);
364 }
365
366 ssl_clear_cipher_ctx(s);
367
368 if (s->cert != NULL) ssl_cert_free(s->cert);
369 /* Free up if allocated */
370
371 if (s->ctx) SSL_CTX_free(s->ctx);
372
373 if (s->client_CA != NULL)
374 sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
375
376 if (s->method != NULL) s->method->ssl_free(s);
377
378 Free(s);
379 }
380
381void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
382 {
383 /* If the output buffering BIO is still in place, remove it
384 */
385 if (s->bbio != NULL)
386 {
387 if (s->wbio == s->bbio)
388 {
389 s->wbio=s->wbio->next_bio;
390 s->bbio->next_bio=NULL;
391 }
392 }
393 if ((s->rbio != NULL) && (s->rbio != rbio))
394 BIO_free_all(s->rbio);
395 if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio))
396 BIO_free_all(s->wbio);
397 s->rbio=rbio;
398 s->wbio=wbio;
399 }
400
401BIO *SSL_get_rbio(SSL *s)
402 { return(s->rbio); }
403
404BIO *SSL_get_wbio(SSL *s)
405 { return(s->wbio); }
406
407int SSL_get_fd(SSL *s)
408 {
409 int ret= -1;
410 BIO *b,*r;
411
412 b=SSL_get_rbio(s);
413 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
414 if (r != NULL)
415 BIO_get_fd(r,&ret);
416 return(ret);
417 }
418
419#ifndef NO_SOCK
420int SSL_set_fd(SSL *s,int fd)
421 {
422 int ret=0;
423 BIO *bio=NULL;
424
425 bio=BIO_new(BIO_s_socket());
426
427 if (bio == NULL)
428 {
429 SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB);
430 goto err;
431 }
432 BIO_set_fd(bio,fd,BIO_NOCLOSE);
433 SSL_set_bio(s,bio,bio);
434 ret=1;
435err:
436 return(ret);
437 }
438
439int SSL_set_wfd(SSL *s,int fd)
440 {
441 int ret=0;
442 BIO *bio=NULL;
443
444 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
445 || ((int)BIO_get_fd(s->rbio,NULL) != fd))
446 {
447 bio=BIO_new(BIO_s_socket());
448
449 if (bio == NULL)
450 { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; }
451 BIO_set_fd(bio,fd,BIO_NOCLOSE);
452 SSL_set_bio(s,SSL_get_rbio(s),bio);
453 }
454 else
455 SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s));
456 ret=1;
457err:
458 return(ret);
459 }
460
461int SSL_set_rfd(SSL *s,int fd)
462 {
463 int ret=0;
464 BIO *bio=NULL;
465
466 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
467 || ((int)BIO_get_fd(s->wbio,NULL) != fd))
468 {
469 bio=BIO_new(BIO_s_socket());
470
471 if (bio == NULL)
472 {
473 SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB);
474 goto err;
475 }
476 BIO_set_fd(bio,fd,BIO_NOCLOSE);
477 SSL_set_bio(s,bio,SSL_get_wbio(s));
478 }
479 else
480 SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s));
481 ret=1;
482err:
483 return(ret);
484 }
485#endif
486
487
488/* return length of latest Finished message we sent, copy to 'buf' */
489size_t SSL_get_finished(SSL *s, void *buf, size_t count)
490 {
491 size_t ret = 0;
492
493 if (s->s3 != NULL)
494 {
495 ret = s->s3->tmp.finish_md_len;
496 if (count > ret)
497 count = ret;
498 memcpy(buf, s->s3->tmp.finish_md, count);
499 }
500 return ret;
501 }
502
503/* return length of latest Finished message we expected, copy to 'buf' */
504size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count)
505 {
506 size_t ret = 0;
507
508 if (s->s3 != NULL)
509 {
510 ret = s->s3->tmp.peer_finish_md_len;
511 if (count > ret)
512 count = ret;
513 memcpy(buf, s->s3->tmp.peer_finish_md, count);
514 }
515 return ret;
516 }
517
518
519int SSL_get_verify_mode(SSL *s)
520 {
521 return(s->verify_mode);
522 }
523
524int SSL_get_verify_depth(SSL *s)
525 {
526 return(s->verify_depth);
527 }
528
529int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *)
530 {
531 return(s->verify_callback);
532 }
533
534int SSL_CTX_get_verify_mode(SSL_CTX *ctx)
535 {
536 return(ctx->verify_mode);
537 }
538
539int SSL_CTX_get_verify_depth(SSL_CTX *ctx)
540 {
541 return(ctx->verify_depth);
542 }
543
544int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *)
545 {
546 return(ctx->default_verify_callback);
547 }
548
549void SSL_set_verify(SSL *s,int mode,
550 int (*callback)(int ok,X509_STORE_CTX *ctx))
551 {
552 s->verify_mode=mode;
553 if (callback != NULL)
554 s->verify_callback=callback;
555 }
556
557void SSL_set_verify_depth(SSL *s,int depth)
558 {
559 s->verify_depth=depth;
560 }
561
562void SSL_set_read_ahead(SSL *s,int yes)
563 {
564 s->read_ahead=yes;
565 }
566
567int SSL_get_read_ahead(SSL *s)
568 {
569 return(s->read_ahead);
570 }
571
572int SSL_pending(SSL *s)
573 {
574 return(s->method->ssl_pending(s));
575 }
576
577X509 *SSL_get_peer_certificate(SSL *s)
578 {
579 X509 *r;
580
581 if ((s == NULL) || (s->session == NULL))
582 r=NULL;
583 else
584 r=s->session->peer;
585
586 if (r == NULL) return(r);
587
588 CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509);
589
590 return(r);
591 }
592
593STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s)
594 {
595 STACK_OF(X509) *r;
596
597 if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL))
598 r=NULL;
599 else
600 r=s->session->sess_cert->cert_chain;
601
602 /* If we are a client, cert_chain includes the peer's own
603 * certificate; if we are a server, it does not. */
604
605 return(r);
606 }
607
608/* Now in theory, since the calling process own 't' it should be safe to
609 * modify. We need to be able to read f without being hassled */
610void SSL_copy_session_id(SSL *t,SSL *f)
611 {
612 CERT *tmp;
613
614 /* Do we need to to SSL locking? */
615 SSL_set_session(t,SSL_get_session(f));
616
617 /* what if we are setup as SSLv2 but want to talk SSLv3 or
618 * vice-versa */
619 if (t->method != f->method)
620 {
621 t->method->ssl_free(t); /* cleanup current */
622 t->method=f->method; /* change method */
623 t->method->ssl_new(t); /* setup new */
624 }
625
626 tmp=t->cert;
627 if (f->cert != NULL)
628 {
629 CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT);
630 t->cert=f->cert;
631 }
632 else
633 t->cert=NULL;
634 if (tmp != NULL) ssl_cert_free(tmp);
635 SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length);
636 }
637
638/* Fix this so it checks all the valid key/cert options */
639int SSL_CTX_check_private_key(SSL_CTX *ctx)
640 {
641 if ( (ctx == NULL) ||
642 (ctx->cert == NULL) ||
643 (ctx->cert->key->x509 == NULL))
644 {
645 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
646 return(0);
647 }
648 if (ctx->cert->key->privatekey == NULL)
649 {
650 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
651 return(0);
652 }
653 return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey));
654 }
655
656/* Fix this function so that it takes an optional type parameter */
657int SSL_check_private_key(SSL *ssl)
658 {
659 if (ssl == NULL)
660 {
661 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER);
662 return(0);
663 }
664 if (ssl->cert == NULL)
665 {
666 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
667 return 0;
668 }
669 if (ssl->cert->key->x509 == NULL)
670 {
671 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
672 return(0);
673 }
674 if (ssl->cert->key->privatekey == NULL)
675 {
676 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
677 return(0);
678 }
679 return(X509_check_private_key(ssl->cert->key->x509,
680 ssl->cert->key->privatekey));
681 }
682
683int SSL_accept(SSL *s)
684 {
685 if (s->handshake_func == 0)
686 /* Not properly initialized yet */
687 SSL_set_accept_state(s);
688
689 return(s->method->ssl_accept(s));
690 }
691
692int SSL_connect(SSL *s)
693 {
694 if (s->handshake_func == 0)
695 /* Not properly initialized yet */
696 SSL_set_connect_state(s);
697
698 return(s->method->ssl_connect(s));
699 }
700
701long SSL_get_default_timeout(SSL *s)
702 {
703 return(s->method->get_timeout());
704 }
705
706int SSL_read(SSL *s,char *buf,int num)
707 {
708 if (s->handshake_func == 0)
709 {
710 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
711 return -1;
712 }
713
714 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
715 {
716 s->rwstate=SSL_NOTHING;
717 return(0);
718 }
719 return(s->method->ssl_read(s,buf,num));
720 }
721
722int SSL_peek(SSL *s,char *buf,int num)
723 {
724 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
725 {
726 return(0);
727 }
728 return(s->method->ssl_peek(s,buf,num));
729 }
730
731int SSL_write(SSL *s,const char *buf,int num)
732 {
733 if (s->handshake_func == 0)
734 {
735 SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED);
736 return -1;
737 }
738
739 if (s->shutdown & SSL_SENT_SHUTDOWN)
740 {
741 s->rwstate=SSL_NOTHING;
742 SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN);
743 return(-1);
744 }
745 return(s->method->ssl_write(s,buf,num));
746 }
747
748int SSL_shutdown(SSL *s)
749 {
750 /* Note that this function behaves differently from what one might
751 * expect. Return values are 0 for no success (yet),
752 * 1 for success; but calling it once is usually not enough,
753 * even if blocking I/O is used (see ssl3_shutdown).
754 */
755
756 if (s->handshake_func == 0)
757 {
758 SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED);
759 return -1;
760 }
761
762 if ((s != NULL) && !SSL_in_init(s))
763 return(s->method->ssl_shutdown(s));
764 else
765 return(1);
766 }
767
768int SSL_renegotiate(SSL *s)
769 {
770 s->new_session=1;
771 return(s->method->ssl_renegotiate(s));
772 }
773
774long SSL_ctrl(SSL *s,int cmd,long larg,char *parg)
775 {
776 long l;
777
778 switch (cmd)
779 {
780 case SSL_CTRL_GET_READ_AHEAD:
781 return(s->read_ahead);
782 case SSL_CTRL_SET_READ_AHEAD:
783 l=s->read_ahead;
784 s->read_ahead=larg;
785 return(l);
786 case SSL_CTRL_OPTIONS:
787 return(s->options|=larg);
788 case SSL_CTRL_MODE:
789 return(s->mode|=larg);
790 default:
791 return(s->method->ssl_ctrl(s,cmd,larg,parg));
792 }
793 }
794
795long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)())
796 {
797 switch(cmd)
798 {
799 default:
800 return(s->method->ssl_callback_ctrl(s,cmd,fp));
801 }
802 }
803
804struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx)
805 {
806 return ctx->sessions;
807 }
808
809long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,char *parg)
810 {
811 long l;
812
813 switch (cmd)
814 {
815 case SSL_CTRL_GET_READ_AHEAD:
816 return(ctx->read_ahead);
817 case SSL_CTRL_SET_READ_AHEAD:
818 l=ctx->read_ahead;
819 ctx->read_ahead=larg;
820 return(l);
821
822 case SSL_CTRL_SET_SESS_CACHE_SIZE:
823 l=ctx->session_cache_size;
824 ctx->session_cache_size=larg;
825 return(l);
826 case SSL_CTRL_GET_SESS_CACHE_SIZE:
827 return(ctx->session_cache_size);
828 case SSL_CTRL_SET_SESS_CACHE_MODE:
829 l=ctx->session_cache_mode;
830 ctx->session_cache_mode=larg;
831 return(l);
832 case SSL_CTRL_GET_SESS_CACHE_MODE:
833 return(ctx->session_cache_mode);
834
835 case SSL_CTRL_SESS_NUMBER:
836 return(ctx->sessions->num_items);
837 case SSL_CTRL_SESS_CONNECT:
838 return(ctx->stats.sess_connect);
839 case SSL_CTRL_SESS_CONNECT_GOOD:
840 return(ctx->stats.sess_connect_good);
841 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
842 return(ctx->stats.sess_connect_renegotiate);
843 case SSL_CTRL_SESS_ACCEPT:
844 return(ctx->stats.sess_accept);
845 case SSL_CTRL_SESS_ACCEPT_GOOD:
846 return(ctx->stats.sess_accept_good);
847 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
848 return(ctx->stats.sess_accept_renegotiate);
849 case SSL_CTRL_SESS_HIT:
850 return(ctx->stats.sess_hit);
851 case SSL_CTRL_SESS_CB_HIT:
852 return(ctx->stats.sess_cb_hit);
853 case SSL_CTRL_SESS_MISSES:
854 return(ctx->stats.sess_miss);
855 case SSL_CTRL_SESS_TIMEOUTS:
856 return(ctx->stats.sess_timeout);
857 case SSL_CTRL_SESS_CACHE_FULL:
858 return(ctx->stats.sess_cache_full);
859 case SSL_CTRL_OPTIONS:
860 return(ctx->options|=larg);
861 case SSL_CTRL_MODE:
862 return(ctx->mode|=larg);
863 default:
864 return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg));
865 }
866 }
867
868long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
869 {
870 switch(cmd)
871 {
872 default:
873 return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp));
874 }
875 }
876
877int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b)
878 {
879 long l;
880
881 l=a->id-b->id;
882 if (l == 0L)
883 return(0);
884 else
885 return((l > 0)?1:-1);
886 }
887
888int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp)
889 {
890 long l;
891
892 l=(*ap)->id-(*bp)->id;
893 if (l == 0L)
894 return(0);
895 else
896 return((l > 0)?1:-1);
897 }
898
899/** return a STACK of the ciphers available for the SSL and in order of
900 * preference */
901STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s)
902 {
903 if ((s != NULL) && (s->cipher_list != NULL))
904 {
905 return(s->cipher_list);
906 }
907 else if ((s->ctx != NULL) &&
908 (s->ctx->cipher_list != NULL))
909 {
910 return(s->ctx->cipher_list);
911 }
912 return(NULL);
913 }
914
915/** return a STACK of the ciphers available for the SSL and in order of
916 * algorithm id */
917STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s)
918 {
919 if ((s != NULL) && (s->cipher_list_by_id != NULL))
920 {
921 return(s->cipher_list_by_id);
922 }
923 else if ((s != NULL) && (s->ctx != NULL) &&
924 (s->ctx->cipher_list_by_id != NULL))
925 {
926 return(s->ctx->cipher_list_by_id);
927 }
928 return(NULL);
929 }
930
931/** The old interface to get the same thing as SSL_get_ciphers() */
932const char *SSL_get_cipher_list(SSL *s,int n)
933 {
934 SSL_CIPHER *c;
935 STACK_OF(SSL_CIPHER) *sk;
936
937 if (s == NULL) return(NULL);
938 sk=SSL_get_ciphers(s);
939 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n))
940 return(NULL);
941 c=sk_SSL_CIPHER_value(sk,n);
942 if (c == NULL) return(NULL);
943 return(c->name);
944 }
945
946/** specify the ciphers to be used by default by the SSL_CTX */
947int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
948 {
949 STACK_OF(SSL_CIPHER) *sk;
950
951 sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list,
952 &ctx->cipher_list_by_id,str);
953/* XXXX */
954 return((sk == NULL)?0:1);
955 }
956
957/** specify the ciphers to be used by the SSL */
958int SSL_set_cipher_list(SSL *s,const char *str)
959 {
960 STACK_OF(SSL_CIPHER) *sk;
961
962 sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list,
963 &s->cipher_list_by_id,str);
964/* XXXX */
965 return((sk == NULL)?0:1);
966 }
967
968/* works well for SSLv2, not so good for SSLv3 */
969char *SSL_get_shared_ciphers(SSL *s,char *buf,int len)
970 {
971 char *p;
972 const char *cp;
973 STACK_OF(SSL_CIPHER) *sk;
974 SSL_CIPHER *c;
975 int i;
976
977 if ((s->session == NULL) || (s->session->ciphers == NULL) ||
978 (len < 2))
979 return(NULL);
980
981 p=buf;
982 sk=s->session->ciphers;
983 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
984 {
985 /* Decrement for either the ':' or a '\0' */
986 len--;
987 c=sk_SSL_CIPHER_value(sk,i);
988 for (cp=c->name; *cp; )
989 {
990 if (len-- == 0)
991 {
992 *p='\0';
993 return(buf);
994 }
995 else
996 *(p++)= *(cp++);
997 }
998 *(p++)=':';
999 }
1000 p[-1]='\0';
1001 return(buf);
1002 }
1003
1004int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p)
1005 {
1006 int i,j=0;
1007 SSL_CIPHER *c;
1008 unsigned char *q;
1009
1010 if (sk == NULL) return(0);
1011 q=p;
1012
1013 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
1014 {
1015 c=sk_SSL_CIPHER_value(sk,i);
1016 j=ssl_put_cipher_by_char(s,c,p);
1017 p+=j;
1018 }
1019 return(p-q);
1020 }
1021
1022STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
1023 STACK_OF(SSL_CIPHER) **skp)
1024 {
1025 SSL_CIPHER *c;
1026 STACK_OF(SSL_CIPHER) *sk;
1027 int i,n;
1028
1029 n=ssl_put_cipher_by_char(s,NULL,NULL);
1030 if ((num%n) != 0)
1031 {
1032 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1033 return(NULL);
1034 }
1035 if ((skp == NULL) || (*skp == NULL))
1036 sk=sk_SSL_CIPHER_new(NULL); /* change perhaps later */
1037 else
1038 {
1039 sk= *skp;
1040 sk_SSL_CIPHER_zero(sk);
1041 }
1042
1043 for (i=0; i<num; i+=n)
1044 {
1045 c=ssl_get_cipher_by_char(s,p);
1046 p+=n;
1047 if (c != NULL)
1048 {
1049 if (!sk_SSL_CIPHER_push(sk,c))
1050 {
1051 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
1052 goto err;
1053 }
1054 }
1055 }
1056
1057 if (skp != NULL)
1058 *skp=sk;
1059 return(sk);
1060err:
1061 if ((skp == NULL) || (*skp == NULL))
1062 sk_SSL_CIPHER_free(sk);
1063 return(NULL);
1064 }
1065
1066unsigned long SSL_SESSION_hash(SSL_SESSION *a)
1067 {
1068 unsigned long l;
1069
1070 l=(unsigned long)
1071 ((unsigned int) a->session_id[0] )|
1072 ((unsigned int) a->session_id[1]<< 8L)|
1073 ((unsigned long)a->session_id[2]<<16L)|
1074 ((unsigned long)a->session_id[3]<<24L);
1075 return(l);
1076 }
1077
1078int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b)
1079 {
1080 if (a->ssl_version != b->ssl_version)
1081 return(1);
1082 if (a->session_id_length != b->session_id_length)
1083 return(1);
1084 return(memcmp(a->session_id,b->session_id,a->session_id_length));
1085 }
1086
1087SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
1088 {
1089 SSL_CTX *ret=NULL;
1090
1091 if (meth == NULL)
1092 {
1093 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);
1094 return(NULL);
1095 }
1096
1097 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
1098 {
1099 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
1100 goto err;
1101 }
1102 ret=(SSL_CTX *)Malloc(sizeof(SSL_CTX));
1103 if (ret == NULL)
1104 goto err;
1105
1106 memset(ret,0,sizeof(SSL_CTX));
1107
1108 ret->method=meth;
1109
1110 ret->cert_store=NULL;
1111 ret->session_cache_mode=SSL_SESS_CACHE_SERVER;
1112 ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
1113 ret->session_cache_head=NULL;
1114 ret->session_cache_tail=NULL;
1115
1116 /* We take the system default */
1117 ret->session_timeout=meth->get_timeout();
1118
1119 ret->new_session_cb=NULL;
1120 ret->remove_session_cb=NULL;
1121 ret->get_session_cb=NULL;
1122
1123 memset((char *)&ret->stats,0,sizeof(ret->stats));
1124
1125 ret->references=1;
1126 ret->quiet_shutdown=0;
1127
1128/* ret->cipher=NULL;*/
1129/* ret->s2->challenge=NULL;
1130 ret->master_key=NULL;
1131 ret->key_arg=NULL;
1132 ret->s2->conn_id=NULL; */
1133
1134 ret->info_callback=NULL;
1135
1136 ret->app_verify_callback=NULL;
1137 ret->app_verify_arg=NULL;
1138
1139 ret->read_ahead=0;
1140 ret->verify_mode=SSL_VERIFY_NONE;
1141 ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */
1142 ret->default_verify_callback=NULL;
1143 if ((ret->cert=ssl_cert_new()) == NULL)
1144 goto err;
1145
1146 ret->default_passwd_callback=NULL;
1147 ret->default_passwd_callback_userdata=NULL;
1148 ret->client_cert_cb=NULL;
1149
1150 ret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp);
1151 if (ret->sessions == NULL) goto err;
1152 ret->cert_store=X509_STORE_new();
1153 if (ret->cert_store == NULL) goto err;
1154
1155 ssl_create_cipher_list(ret->method,
1156 &ret->cipher_list,&ret->cipher_list_by_id,
1157 SSL_DEFAULT_CIPHER_LIST);
1158 if (ret->cipher_list == NULL
1159 || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)
1160 {
1161 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);
1162 goto err2;
1163 }
1164
1165 if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)
1166 {
1167 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);
1168 goto err2;
1169 }
1170 if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)
1171 {
1172 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);
1173 goto err2;
1174 }
1175 if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)
1176 {
1177 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);
1178 goto err2;
1179 }
1180
1181 if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)
1182 goto err;
1183
1184 CRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data);
1185
1186 ret->extra_certs=NULL;
1187 ret->comp_methods=SSL_COMP_get_compression_methods();
1188
1189 return(ret);
1190err:
1191 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
1192err2:
1193 if (ret != NULL) SSL_CTX_free(ret);
1194 return(NULL);
1195 }
1196
1197static void SSL_COMP_free(SSL_COMP *comp)
1198 { Free(comp); }
1199
1200void SSL_CTX_free(SSL_CTX *a)
1201 {
1202 int i;
1203
1204 if (a == NULL) return;
1205
1206 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);
1207#ifdef REF_PRINT
1208 REF_PRINT("SSL_CTX",a);
1209#endif
1210 if (i > 0) return;
1211#ifdef REF_CHECK
1212 if (i < 0)
1213 {
1214 fprintf(stderr,"SSL_CTX_free, bad reference count\n");
1215 abort(); /* ok */
1216 }
1217#endif
1218 CRYPTO_free_ex_data(ssl_ctx_meth,(char *)a,&a->ex_data);
1219
1220 if (a->sessions != NULL)
1221 {
1222 SSL_CTX_flush_sessions(a,0);
1223 lh_free(a->sessions);
1224 }
1225 if (a->cert_store != NULL)
1226 X509_STORE_free(a->cert_store);
1227 if (a->cipher_list != NULL)
1228 sk_SSL_CIPHER_free(a->cipher_list);
1229 if (a->cipher_list_by_id != NULL)
1230 sk_SSL_CIPHER_free(a->cipher_list_by_id);
1231 if (a->cert != NULL)
1232 ssl_cert_free(a->cert);
1233 if (a->client_CA != NULL)
1234 sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);
1235 if (a->extra_certs != NULL)
1236 sk_X509_pop_free(a->extra_certs,X509_free);
1237 if (a->comp_methods != NULL)
1238 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1239 Free(a);
1240 }
1241
1242void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1243 {
1244 ctx->default_passwd_callback=cb;
1245 }
1246
1247void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u)
1248 {
1249 ctx->default_passwd_callback_userdata=u;
1250 }
1251
1252void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,int (*cb)(),char *arg)
1253 {
1254 /* now
1255 * int (*cb)(X509_STORE_CTX *),
1256 * but should be
1257 * int (*cb)(X509_STORE_CTX *, void *arg)
1258 */
1259 ctx->app_verify_callback=cb;
1260 ctx->app_verify_arg=arg; /* never used */
1261 }
1262
1263void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *))
1264 {
1265 ctx->verify_mode=mode;
1266 ctx->default_verify_callback=cb;
1267 /* This needs cleaning up EAY EAY EAY */
1268 X509_STORE_set_verify_cb_func(ctx->cert_store,cb);
1269 }
1270
1271void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth)
1272 {
1273 ctx->verify_depth=depth;
1274 }
1275
1276void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
1277 {
1278 CERT_PKEY *cpk;
1279 int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;
1280 int rsa_enc_export,dh_rsa_export,dh_dsa_export;
1281 int rsa_tmp_export,dh_tmp_export,kl;
1282 unsigned long mask,emask;
1283
1284 if (c == NULL) return;
1285
1286 kl=SSL_C_EXPORT_PKEYLENGTH(cipher);
1287
1288#ifndef NO_RSA
1289 rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL);
1290 rsa_tmp_export=(c->rsa_tmp_cb != NULL ||
1291 (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl));
1292#else
1293 rsa_tmp=rsa_tmp_export=0;
1294#endif
1295#ifndef NO_DH
1296 dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL);
1297 dh_tmp_export=(c->dh_tmp_cb != NULL ||
1298 (dh_tmp && DH_size(c->dh_tmp)*8 <= kl));
1299#else
1300 dh_tmp=dh_tmp_export=0;
1301#endif
1302
1303 cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);
1304 rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL);
1305 rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1306 cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]);
1307 rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1308 cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]);
1309 dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1310 cpk= &(c->pkeys[SSL_PKEY_DH_RSA]);
1311 dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1312 dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1313 cpk= &(c->pkeys[SSL_PKEY_DH_DSA]);
1314/* FIX THIS EAY EAY EAY */
1315 dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1316 dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1317
1318 mask=0;
1319 emask=0;
1320
1321#ifdef CIPHER_DEBUG
1322 printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n",
1323 rsa_tmp,rsa_tmp_export,dh_tmp,
1324 rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa);
1325#endif
1326
1327 if (rsa_enc || (rsa_tmp && rsa_sign))
1328 mask|=SSL_kRSA;
1329 if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc)))
1330 emask|=SSL_kRSA;
1331
1332#if 0
1333 /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */
1334 if ( (dh_tmp || dh_rsa || dh_dsa) &&
1335 (rsa_enc || rsa_sign || dsa_sign))
1336 mask|=SSL_kEDH;
1337 if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&
1338 (rsa_enc || rsa_sign || dsa_sign))
1339 emask|=SSL_kEDH;
1340#endif
1341
1342 if (dh_tmp_export)
1343 emask|=SSL_kEDH;
1344
1345 if (dh_tmp)
1346 mask|=SSL_kEDH;
1347
1348 if (dh_rsa) mask|=SSL_kDHr;
1349 if (dh_rsa_export) emask|=SSL_kDHr;
1350
1351 if (dh_dsa) mask|=SSL_kDHd;
1352 if (dh_dsa_export) emask|=SSL_kDHd;
1353
1354 if (rsa_enc || rsa_sign)
1355 {
1356 mask|=SSL_aRSA;
1357 emask|=SSL_aRSA;
1358 }
1359
1360 if (dsa_sign)
1361 {
1362 mask|=SSL_aDSS;
1363 emask|=SSL_aDSS;
1364 }
1365
1366 mask|=SSL_aNULL;
1367 emask|=SSL_aNULL;
1368
1369 c->mask=mask;
1370 c->export_mask=emask;
1371 c->valid=1;
1372 }
1373
1374/* THIS NEEDS CLEANING UP */
1375X509 *ssl_get_server_send_cert(SSL *s)
1376 {
1377 unsigned long alg,mask,kalg;
1378 CERT *c;
1379 int i,is_export;
1380
1381 c=s->cert;
1382 ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
1383 alg=s->s3->tmp.new_cipher->algorithms;
1384 is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
1385 mask=is_export?c->export_mask:c->mask;
1386 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1387
1388 if (kalg & SSL_kDHr)
1389 i=SSL_PKEY_DH_RSA;
1390 else if (kalg & SSL_kDHd)
1391 i=SSL_PKEY_DH_DSA;
1392 else if (kalg & SSL_aDSS)
1393 i=SSL_PKEY_DSA_SIGN;
1394 else if (kalg & SSL_aRSA)
1395 {
1396 if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
1397 i=SSL_PKEY_RSA_SIGN;
1398 else
1399 i=SSL_PKEY_RSA_ENC;
1400 }
1401 else /* if (kalg & SSL_aNULL) */
1402 {
1403 SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,SSL_R_INTERNAL_ERROR);
1404 return(NULL);
1405 }
1406 if (c->pkeys[i].x509 == NULL) return(NULL);
1407 return(c->pkeys[i].x509);
1408 }
1409
1410EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher)
1411 {
1412 unsigned long alg;
1413 CERT *c;
1414
1415 alg=cipher->algorithms;
1416 c=s->cert;
1417
1418 if ((alg & SSL_aDSS) &&
1419 (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
1420 return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey);
1421 else if (alg & SSL_aRSA)
1422 {
1423 if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
1424 return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey);
1425 else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL)
1426 return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey);
1427 else
1428 return(NULL);
1429 }
1430 else /* if (alg & SSL_aNULL) */
1431 {
1432 SSLerr(SSL_F_SSL_GET_SIGN_PKEY,SSL_R_INTERNAL_ERROR);
1433 return(NULL);
1434 }
1435 }
1436
1437void ssl_update_cache(SSL *s,int mode)
1438 {
1439 int i;
1440
1441 /* If the session_id_length is 0, we are not supposed to cache it,
1442 * and it would be rather hard to do anyway :-) */
1443 if (s->session->session_id_length == 0) return;
1444
1445 if ((s->ctx->session_cache_mode & mode)
1446 && (!s->hit)
1447 && SSL_CTX_add_session(s->ctx,s->session)
1448 && (s->ctx->new_session_cb != NULL))
1449 {
1450 CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);
1451 if (!s->ctx->new_session_cb(s,s->session))
1452 SSL_SESSION_free(s->session);
1453 }
1454
1455 /* auto flush every 255 connections */
1456 i=s->ctx->session_cache_mode;
1457 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&
1458 ((i & mode) == mode))
1459 {
1460 if ( (((mode & SSL_SESS_CACHE_CLIENT)
1461 ?s->ctx->stats.sess_connect_good
1462 :s->ctx->stats.sess_accept_good) & 0xff) == 0xff)
1463 {
1464 SSL_CTX_flush_sessions(s->ctx,time(NULL));
1465 }
1466 }
1467 }
1468
1469SSL_METHOD *SSL_get_ssl_method(SSL *s)
1470 {
1471 return(s->method);
1472 }
1473
1474int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth)
1475 {
1476 int conn= -1;
1477 int ret=1;
1478
1479 if (s->method != meth)
1480 {
1481 if (s->handshake_func != NULL)
1482 conn=(s->handshake_func == s->method->ssl_connect);
1483
1484 if (s->method->version == meth->version)
1485 s->method=meth;
1486 else
1487 {
1488 s->method->ssl_free(s);
1489 s->method=meth;
1490 ret=s->method->ssl_new(s);
1491 }
1492
1493 if (conn == 1)
1494 s->handshake_func=meth->ssl_connect;
1495 else if (conn == 0)
1496 s->handshake_func=meth->ssl_accept;
1497 }
1498 return(ret);
1499 }
1500
1501int SSL_get_error(SSL *s,int i)
1502 {
1503 int reason;
1504 unsigned long l;
1505 BIO *bio;
1506
1507 if (i > 0) return(SSL_ERROR_NONE);
1508
1509 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
1510 * etc, where we do encode the error */
1511 if ((l=ERR_peek_error()) != 0)
1512 {
1513 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
1514 return(SSL_ERROR_SYSCALL);
1515 else
1516 return(SSL_ERROR_SSL);
1517 }
1518
1519 if ((i < 0) && SSL_want_read(s))
1520 {
1521 bio=SSL_get_rbio(s);
1522 if (BIO_should_read(bio))
1523 return(SSL_ERROR_WANT_READ);
1524 else if (BIO_should_write(bio))
1525 /* This one doesn't make too much sense ... We never try
1526 * to write to the rbio, and an application program where
1527 * rbio and wbio are separate couldn't even know what it
1528 * should wait for.
1529 * However if we ever set s->rwstate incorrectly
1530 * (so that we have SSL_want_read(s) instead of
1531 * SSL_want_write(s)) and rbio and wbio *are* the same,
1532 * this test works around that bug; so it might be safer
1533 * to keep it. */
1534 return(SSL_ERROR_WANT_WRITE);
1535 else if (BIO_should_io_special(bio))
1536 {
1537 reason=BIO_get_retry_reason(bio);
1538 if (reason == BIO_RR_CONNECT)
1539 return(SSL_ERROR_WANT_CONNECT);
1540 else
1541 return(SSL_ERROR_SYSCALL); /* unknown */
1542 }
1543 }
1544
1545 if ((i < 0) && SSL_want_write(s))
1546 {
1547 bio=SSL_get_wbio(s);
1548 if (BIO_should_write(bio))
1549 return(SSL_ERROR_WANT_WRITE);
1550 else if (BIO_should_read(bio))
1551 /* See above (SSL_want_read(s) with BIO_should_write(bio)) */
1552 return(SSL_ERROR_WANT_READ);
1553 else if (BIO_should_io_special(bio))
1554 {
1555 reason=BIO_get_retry_reason(bio);
1556 if (reason == BIO_RR_CONNECT)
1557 return(SSL_ERROR_WANT_CONNECT);
1558 else
1559 return(SSL_ERROR_SYSCALL);
1560 }
1561 }
1562 if ((i < 0) && SSL_want_x509_lookup(s))
1563 {
1564 return(SSL_ERROR_WANT_X509_LOOKUP);
1565 }
1566
1567 if (i == 0)
1568 {
1569 if (s->version == SSL2_VERSION)
1570 {
1571 /* assume it is the socket being closed */
1572 return(SSL_ERROR_ZERO_RETURN);
1573 }
1574 else
1575 {
1576 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
1577 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
1578 return(SSL_ERROR_ZERO_RETURN);
1579 }
1580 }
1581 return(SSL_ERROR_SYSCALL);
1582 }
1583
1584int SSL_do_handshake(SSL *s)
1585 {
1586 int ret=1;
1587
1588 if (s->handshake_func == NULL)
1589 {
1590 SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET);
1591 return(-1);
1592 }
1593
1594 s->method->ssl_renegotiate_check(s);
1595
1596 if (SSL_in_init(s) || SSL_in_before(s))
1597 {
1598 ret=s->handshake_func(s);
1599 }
1600 return(ret);
1601 }
1602
1603/* For the next 2 functions, SSL_clear() sets shutdown and so
1604 * one of these calls will reset it */
1605void SSL_set_accept_state(SSL *s)
1606 {
1607 s->server=1;
1608 s->shutdown=0;
1609 s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE;
1610 s->handshake_func=s->method->ssl_accept;
1611 /* clear the current cipher */
1612 ssl_clear_cipher_ctx(s);
1613 }
1614
1615void SSL_set_connect_state(SSL *s)
1616 {
1617 s->server=0;
1618 s->shutdown=0;
1619 s->state=SSL_ST_CONNECT|SSL_ST_BEFORE;
1620 s->handshake_func=s->method->ssl_connect;
1621 /* clear the current cipher */
1622 ssl_clear_cipher_ctx(s);
1623 }
1624
1625int ssl_undefined_function(SSL *s)
1626 {
1627 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1628 return(0);
1629 }
1630
1631SSL_METHOD *ssl_bad_method(int ver)
1632 {
1633 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1634 return(NULL);
1635 }
1636
1637const char *SSL_get_version(SSL *s)
1638 {
1639 if (s->version == TLS1_VERSION)
1640 return("TLSv1");
1641 else if (s->version == SSL3_VERSION)
1642 return("SSLv3");
1643 else if (s->version == SSL2_VERSION)
1644 return("SSLv2");
1645 else
1646 return("unknown");
1647 }
1648
1649SSL *SSL_dup(SSL *s)
1650 {
1651 STACK_OF(X509_NAME) *sk;
1652 X509_NAME *xn;
1653 SSL *ret;
1654 int i;
1655
1656 if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL)
1657 return(NULL);
1658
1659 if (s->session != NULL)
1660 {
1661 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
1662 SSL_copy_session_id(ret,s);
1663 }
1664 else
1665 {
1666 /* No session has been established yet, so we have to expect
1667 * that s->cert or ret->cert will be changed later --
1668 * they should not both point to the same object,
1669 * and thus we can't use SSL_copy_session_id. */
1670
1671 ret->method = s->method;
1672 ret->method->ssl_new(ret);
1673
1674 if (s->cert != NULL)
1675 {
1676 ret->cert = ssl_cert_dup(s->cert);
1677 if (ret->cert == NULL)
1678 goto err;
1679 }
1680
1681 SSL_set_session_id_context(ret,
1682 s->sid_ctx, s->sid_ctx_length);
1683 }
1684
1685 SSL_set_read_ahead(ret,SSL_get_read_ahead(s));
1686 SSL_set_verify(ret,SSL_get_verify_mode(s),
1687 SSL_get_verify_callback(s));
1688 SSL_set_verify_depth(ret,SSL_get_verify_depth(s));
1689
1690 SSL_set_info_callback(ret,SSL_get_info_callback(s));
1691
1692 ret->debug=s->debug;
1693 ret->options=s->options;
1694
1695 /* copy app data, a little dangerous perhaps */
1696 if (!CRYPTO_dup_ex_data(ssl_meth,&ret->ex_data,&s->ex_data))
1697 goto err;
1698
1699 /* setup rbio, and wbio */
1700 if (s->rbio != NULL)
1701 {
1702 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
1703 goto err;
1704 }
1705 if (s->wbio != NULL)
1706 {
1707 if (s->wbio != s->rbio)
1708 {
1709 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
1710 goto err;
1711 }
1712 else
1713 ret->wbio=ret->rbio;
1714 }
1715
1716 /* dup the cipher_list and cipher_list_by_id stacks */
1717 if (s->cipher_list != NULL)
1718 {
1719 if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
1720 goto err;
1721 }
1722 if (s->cipher_list_by_id != NULL)
1723 if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id))
1724 == NULL)
1725 goto err;
1726
1727 /* Dup the client_CA list */
1728 if (s->client_CA != NULL)
1729 {
1730 if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;
1731 ret->client_CA=sk;
1732 for (i=0; i<sk_X509_NAME_num(sk); i++)
1733 {
1734 xn=sk_X509_NAME_value(sk,i);
1735 if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL)
1736 {
1737 X509_NAME_free(xn);
1738 goto err;
1739 }
1740 }
1741 }
1742
1743 ret->shutdown=s->shutdown;
1744 ret->state=s->state;
1745 ret->handshake_func=s->handshake_func;
1746 ret->server=s->server;
1747
1748 if (0)
1749 {
1750err:
1751 if (ret != NULL) SSL_free(ret);
1752 ret=NULL;
1753 }
1754 return(ret);
1755 }
1756
1757void ssl_clear_cipher_ctx(SSL *s)
1758 {
1759 if (s->enc_read_ctx != NULL)
1760 {
1761 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
1762 Free(s->enc_read_ctx);
1763 s->enc_read_ctx=NULL;
1764 }
1765 if (s->enc_write_ctx != NULL)
1766 {
1767 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
1768 Free(s->enc_write_ctx);
1769 s->enc_write_ctx=NULL;
1770 }
1771 if (s->expand != NULL)
1772 {
1773 COMP_CTX_free(s->expand);
1774 s->expand=NULL;
1775 }
1776 if (s->compress != NULL)
1777 {
1778 COMP_CTX_free(s->compress);
1779 s->compress=NULL;
1780 }
1781 }
1782
1783/* Fix this function so that it takes an optional type parameter */
1784X509 *SSL_get_certificate(SSL *s)
1785 {
1786 if (s->cert != NULL)
1787 return(s->cert->key->x509);
1788 else
1789 return(NULL);
1790 }
1791
1792/* Fix this function so that it takes an optional type parameter */
1793EVP_PKEY *SSL_get_privatekey(SSL *s)
1794 {
1795 if (s->cert != NULL)
1796 return(s->cert->key->privatekey);
1797 else
1798 return(NULL);
1799 }
1800
1801SSL_CIPHER *SSL_get_current_cipher(SSL *s)
1802 {
1803 if ((s->session != NULL) && (s->session->cipher != NULL))
1804 return(s->session->cipher);
1805 return(NULL);
1806 }
1807
1808int ssl_init_wbio_buffer(SSL *s,int push)
1809 {
1810 BIO *bbio;
1811
1812 if (s->bbio == NULL)
1813 {
1814 bbio=BIO_new(BIO_f_buffer());
1815 if (bbio == NULL) return(0);
1816 s->bbio=bbio;
1817 }
1818 else
1819 {
1820 bbio=s->bbio;
1821 if (s->bbio == s->wbio)
1822 s->wbio=BIO_pop(s->wbio);
1823 }
1824 (void)BIO_reset(bbio);
1825/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
1826 if (!BIO_set_read_buffer_size(bbio,1))
1827 {
1828 SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB);
1829 return(0);
1830 }
1831 if (push)
1832 {
1833 if (s->wbio != bbio)
1834 s->wbio=BIO_push(bbio,s->wbio);
1835 }
1836 else
1837 {
1838 if (s->wbio == bbio)
1839 s->wbio=BIO_pop(bbio);
1840 }
1841 return(1);
1842 }
1843
1844void ssl_free_wbio_buffer(SSL *s)
1845 {
1846 BIO *under;
1847
1848 if (s->bbio == NULL) return;
1849
1850 if (s->bbio == s->wbio)
1851 {
1852 /* remove buffering */
1853 under=BIO_pop(s->wbio);
1854 if (under != NULL)
1855 s->wbio=under;
1856 else
1857 abort(); /* ok */
1858 }
1859 BIO_free(s->bbio);
1860 s->bbio=NULL;
1861 }
1862
1863void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
1864 {
1865 ctx->quiet_shutdown=mode;
1866 }
1867
1868int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx)
1869 {
1870 return(ctx->quiet_shutdown);
1871 }
1872
1873void SSL_set_quiet_shutdown(SSL *s,int mode)
1874 {
1875 s->quiet_shutdown=mode;
1876 }
1877
1878int SSL_get_quiet_shutdown(SSL *s)
1879 {
1880 return(s->quiet_shutdown);
1881 }
1882
1883void SSL_set_shutdown(SSL *s,int mode)
1884 {
1885 s->shutdown=mode;
1886 }
1887
1888int SSL_get_shutdown(SSL *s)
1889 {
1890 return(s->shutdown);
1891 }
1892
1893int SSL_version(SSL *s)
1894 {
1895 return(s->version);
1896 }
1897
1898SSL_CTX *SSL_get_SSL_CTX(SSL *ssl)
1899 {
1900 return(ssl->ctx);
1901 }
1902
1903#ifndef NO_STDIO
1904int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
1905 {
1906 return(X509_STORE_set_default_paths(ctx->cert_store));
1907 }
1908
1909int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1910 const char *CApath)
1911 {
1912 return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath));
1913 }
1914#endif
1915
1916void SSL_set_info_callback(SSL *ssl,void (*cb)())
1917 {
1918 ssl->info_callback=cb;
1919 }
1920
1921void (*SSL_get_info_callback(SSL *ssl))(void)
1922 {
1923 return((void (*)())ssl->info_callback);
1924 }
1925
1926int SSL_state(SSL *ssl)
1927 {
1928 return(ssl->state);
1929 }
1930
1931void SSL_set_verify_result(SSL *ssl,long arg)
1932 {
1933 ssl->verify_result=arg;
1934 }
1935
1936long SSL_get_verify_result(SSL *ssl)
1937 {
1938 return(ssl->verify_result);
1939 }
1940
1941int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
1942 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
1943 {
1944 ssl_meth_num++;
1945 return(CRYPTO_get_ex_new_index(ssl_meth_num-1,
1946 &ssl_meth,argl,argp,new_func,dup_func,free_func));
1947 }
1948
1949int SSL_set_ex_data(SSL *s,int idx,void *arg)
1950 {
1951 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1952 }
1953
1954void *SSL_get_ex_data(SSL *s,int idx)
1955 {
1956 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1957 }
1958
1959int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
1960 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
1961 {
1962 ssl_ctx_meth_num++;
1963 return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1,
1964 &ssl_ctx_meth,argl,argp,new_func,dup_func,free_func));
1965 }
1966
1967int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg)
1968 {
1969 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1970 }
1971
1972void *SSL_CTX_get_ex_data(SSL_CTX *s,int idx)
1973 {
1974 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1975 }
1976
1977int ssl_ok(SSL *s)
1978 {
1979 return(1);
1980 }
1981
1982X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx)
1983 {
1984 return(ctx->cert_store);
1985 }
1986
1987void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store)
1988 {
1989 if (ctx->cert_store != NULL)
1990 X509_STORE_free(ctx->cert_store);
1991 ctx->cert_store=store;
1992 }
1993
1994int SSL_want(SSL *s)
1995 {
1996 return(s->rwstate);
1997 }
1998
1999/*!
2000 * \brief Set the callback for generating temporary RSA keys.
2001 * \param ctx the SSL context.
2002 * \param cb the callback
2003 */
2004
2005#ifndef NO_RSA
2006void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl,
2007 int is_export,
2008 int keylength))
2009 {
2010 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2011 }
2012
2013void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl,
2014 int is_export,
2015 int keylength))
2016 {
2017 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2018 }
2019#endif
2020
2021#ifdef DOXYGEN
2022/*!
2023 * \brief The RSA temporary key callback function.
2024 * \param ssl the SSL session.
2025 * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite.
2026 * \param keylength if \c is_export is \c TRUE, then \c keylength is the size
2027 * of the required key in bits.
2028 * \return the temporary RSA key.
2029 * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback
2030 */
2031
2032RSA *cb(SSL *ssl,int is_export,int keylength)
2033 {}
2034#endif
2035
2036/*!
2037 * \brief Set the callback for generating temporary DH keys.
2038 * \param ctx the SSL context.
2039 * \param dh the callback
2040 */
2041
2042#ifndef NO_DH
2043void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export,
2044 int keylength))
2045 {
2046 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2047 }
2048
2049void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export,
2050 int keylength))
2051 {
2052 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2053 }
2054#endif
2055
2056#if defined(_WINDLL) && defined(WIN16)
2057#include "../crypto/bio/bss_file.c"
2058#endif
2059
2060IMPLEMENT_STACK_OF(SSL_CIPHER)
2061IMPLEMENT_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 9a52bab254..0000000000
--- a/src/lib/libssl/ssl_locl.h
+++ /dev/null
@@ -1,555 +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/*
159 * Define the Bitmasks for SSL_CIPHER.algorithms.
160 * This bits are used packed as dense as possible. If new methods/ciphers
161 * etc will be added, the bits a likely to change, so this information
162 * is for internal library use only, even though SSL_CIPHER.algorithms
163 * can be publicly accessed.
164 * Use the according functions for cipher management instead.
165 *
166 * The bit mask handling in the selection and sorting scheme in
167 * ssl_create_cipher_list() has only limited capabilities, reflecting
168 * that the different entities within are mutually exclusive:
169 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
170 */
171#define SSL_MKEY_MASK 0x0000001FL
172#define SSL_kRSA 0x00000001L /* RSA key exchange */
173#define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */
174#define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */
175#define SSL_kFZA 0x00000008L
176#define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */
177#define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL))
178
179#define SSL_AUTH_MASK 0x000003e0L
180#define SSL_aRSA 0x00000020L /* Authenticate with RSA */
181#define SSL_aDSS 0x00000040L /* Authenticate with DSS */
182#define SSL_DSS SSL_aDSS
183#define SSL_aFZA 0x00000080L
184#define SSL_aNULL 0x00000100L /* no Authenticate, ADH */
185#define SSL_aDH 0x00000200L /* no Authenticate, ADH */
186
187#define SSL_NULL (SSL_eNULL)
188#define SSL_ADH (SSL_kEDH|SSL_aNULL)
189#define SSL_RSA (SSL_kRSA|SSL_aRSA)
190#define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH)
191#define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA)
192
193#define SSL_ENC_MASK 0x0001Fc00L
194#define SSL_DES 0x00000400L
195#define SSL_3DES 0x00000800L
196#define SSL_RC4 0x00001000L
197#define SSL_RC2 0x00002000L
198#define SSL_IDEA 0x00004000L
199#define SSL_eFZA 0x00008000L
200#define SSL_eNULL 0x00010000L
201
202#define SSL_MAC_MASK 0x00060000L
203#define SSL_MD5 0x00020000L
204#define SSL_SHA1 0x00040000L
205#define SSL_SHA (SSL_SHA1)
206
207#define SSL_SSL_MASK 0x00180000L
208#define SSL_SSLV2 0x00080000L
209#define SSL_SSLV3 0x00100000L
210#define SSL_TLSV1 SSL_SSLV3 /* for now */
211
212/* we have used 001fffff - 11 bits left to go */
213
214/*
215 * Export and cipher strength information. For each cipher we have to decide
216 * whether it is exportable or not. This information is likely to change
217 * over time, since the export control rules are no static technical issue.
218 *
219 * Independent of the export flag the cipher strength is sorted into classes.
220 * SSL_EXP40 was denoting the 40bit US export limit of past times, which now
221 * is at 56bit (SSL_EXP56). If the exportable cipher class is going to change
222 * again (eg. to 64bit) the use of "SSL_EXP*" becomes blurred even more,
223 * since SSL_EXP64 could be similar to SSL_LOW.
224 * For this reason SSL_MICRO and SSL_MINI macros are included to widen the
225 * namespace of SSL_LOW-SSL_HIGH to lower values. As development of speed
226 * and ciphers goes, another extension to SSL_SUPER and/or SSL_ULTRA would
227 * be possible.
228 */
229#define SSL_EXP_MASK 0x00000003L
230#define SSL_NOT_EXP 0x00000001L
231#define SSL_EXPORT 0x00000002L
232
233#define SSL_STRONG_MASK 0x0000007cL
234#define SSL_EXP40 0x00000004L
235#define SSL_MICRO (SSL_EXP40)
236#define SSL_EXP56 0x00000008L
237#define SSL_MINI (SSL_EXP56)
238#define SSL_LOW 0x00000010L
239#define SSL_MEDIUM 0x00000020L
240#define SSL_HIGH 0x00000040L
241
242/* we have used 0000007f - 25 bits left to go */
243
244/*
245 * Macros to check the export status and cipher strength for export ciphers.
246 * Even though the macros for EXPORT and EXPORT40/56 have similar names,
247 * their meaning is different:
248 * *_EXPORT macros check the 'exportable' status.
249 * *_EXPORT40/56 macros are used to check whether a certain cipher strength
250 * is given.
251 * Since the SSL_IS_EXPORT* and SSL_EXPORT* macros depend on the correct
252 * algorithm structure element to be passed (algorithms, algo_strength) and no
253 * typechecking can be done as they are all of type unsigned long, their
254 * direct usage is discouraged.
255 * Use the SSL_C_* macros instead.
256 */
257#define SSL_IS_EXPORT(a) ((a)&SSL_EXPORT)
258#define SSL_IS_EXPORT56(a) ((a)&SSL_EXP56)
259#define SSL_IS_EXPORT40(a) ((a)&SSL_EXP40)
260#define SSL_C_IS_EXPORT(c) SSL_IS_EXPORT((c)->algo_strength)
261#define SSL_C_IS_EXPORT56(c) SSL_IS_EXPORT56((c)->algo_strength)
262#define SSL_C_IS_EXPORT40(c) SSL_IS_EXPORT40((c)->algo_strength)
263
264#define SSL_EXPORT_KEYLENGTH(a,s) (SSL_IS_EXPORT40(s) ? 5 : \
265 ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7)
266#define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024)
267#define SSL_C_EXPORT_KEYLENGTH(c) SSL_EXPORT_KEYLENGTH((c)->algorithms, \
268 (c)->algo_strength)
269#define SSL_C_EXPORT_PKEYLENGTH(c) SSL_EXPORT_PKEYLENGTH((c)->algo_strength)
270
271
272#define SSL_ALL 0xffffffffL
273#define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\
274 SSL_MAC_MASK)
275#define SSL_ALL_STRENGTHS (SSL_EXP_MASK|SSL_STRONG_MASK)
276
277/* Mostly for SSLv3 */
278#define SSL_PKEY_RSA_ENC 0
279#define SSL_PKEY_RSA_SIGN 1
280#define SSL_PKEY_DSA_SIGN 2
281#define SSL_PKEY_DH_RSA 3
282#define SSL_PKEY_DH_DSA 4
283#define SSL_PKEY_NUM 5
284
285/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
286 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
287 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
288 * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN
289 * SSL_aRSA <- RSA_ENC | RSA_SIGN
290 * SSL_aDSS <- DSA_SIGN
291 */
292
293/*
294#define CERT_INVALID 0
295#define CERT_PUBLIC_KEY 1
296#define CERT_PRIVATE_KEY 2
297*/
298
299typedef struct cert_pkey_st
300 {
301 X509 *x509;
302 EVP_PKEY *privatekey;
303 } CERT_PKEY;
304
305typedef struct cert_st
306 {
307 /* Current active set */
308 CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array
309 * Probably it would make more sense to store
310 * an index, not a pointer. */
311
312 /* The following masks are for the key and auth
313 * algorithms that are supported by the certs below */
314 int valid;
315 unsigned long mask;
316 unsigned long export_mask;
317#ifndef NO_RSA
318 RSA *rsa_tmp;
319 RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize);
320#endif
321#ifndef NO_DH
322 DH *dh_tmp;
323 DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize);
324#endif
325
326 CERT_PKEY pkeys[SSL_PKEY_NUM];
327
328 int references; /* >1 only if SSL_copy_session_id is used */
329 } CERT;
330
331
332typedef struct sess_cert_st
333 {
334 STACK_OF(X509) *cert_chain; /* as received from peer (not for SSL2) */
335
336 /* The 'peer_...' members are used only by clients. */
337 int peer_cert_type;
338
339 CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */
340 CERT_PKEY peer_pkeys[SSL_PKEY_NUM];
341 /* Obviously we don't have the private keys of these,
342 * so maybe we shouldn't even use the CERT_PKEY type here. */
343
344#ifndef NO_RSA
345 RSA *peer_rsa_tmp; /* not used for SSL 2 */
346#endif
347#ifndef NO_DH
348 DH *peer_dh_tmp; /* not used for SSL 2 */
349#endif
350
351 int references; /* actually always 1 at the moment */
352 } SESS_CERT;
353
354
355/*#define MAC_DEBUG */
356
357/*#define ERR_DEBUG */
358/*#define ABORT_DEBUG */
359/*#define PKT_DEBUG 1 */
360/*#define DES_DEBUG */
361/*#define DES_OFB_DEBUG */
362/*#define SSL_DEBUG */
363/*#define RSA_DEBUG */
364/*#define IDEA_DEBUG */
365
366#define FP_ICC (int (*)(const void *,const void *))
367#define ssl_put_cipher_by_char(ssl,ciph,ptr) \
368 ((ssl)->method->put_cipher_by_char((ciph),(ptr)))
369#define ssl_get_cipher_by_char(ssl,ptr) \
370 ((ssl)->method->get_cipher_by_char(ptr))
371
372/* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff
373 * It is a bit of a mess of functions, but hell, think of it as
374 * an opaque structure :-) */
375typedef struct ssl3_enc_method
376 {
377 int (*enc)(SSL *, int);
378 int (*mac)(SSL *, unsigned char *, int);
379 int (*setup_key_block)(SSL *);
380 int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *, int);
381 int (*change_cipher_state)(SSL *, int);
382 int (*final_finish_mac)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char *, int, unsigned char *);
383 int finish_mac_length;
384 int (*cert_verify_mac)(SSL *, EVP_MD_CTX *, unsigned char *);
385 const char *client_finished_label;
386 int client_finished_label_len;
387 const char *server_finished_label;
388 int server_finished_label_len;
389 int (*alert_value)(int);
390 } SSL3_ENC_METHOD;
391
392/* Used for holding the relevant compression methods loaded into SSL_CTX */
393typedef struct ssl3_comp_st
394 {
395 int comp_id; /* The identifier byte for this compression type */
396 char *name; /* Text name used for the compression type */
397 COMP_METHOD *method; /* The method :-) */
398 } SSL3_COMP;
399
400OPENSSL_EXTERN SSL3_ENC_METHOD ssl3_undef_enc_method;
401OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[];
402OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[];
403
404#ifdef VMS
405#undef SSL_COMP_get_compression_methods
406#define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods
407#endif
408
409
410SSL_METHOD *ssl_bad_method(int ver);
411SSL_METHOD *sslv2_base_method(void);
412SSL_METHOD *sslv23_base_method(void);
413SSL_METHOD *sslv3_base_method(void);
414
415void ssl_clear_cipher_ctx(SSL *s);
416int ssl_clear_bad_session(SSL *s);
417CERT *ssl_cert_new(void);
418CERT *ssl_cert_dup(CERT *cert);
419int ssl_cert_inst(CERT **o);
420void ssl_cert_free(CERT *c);
421SESS_CERT *ssl_sess_cert_new(void);
422void ssl_sess_cert_free(SESS_CERT *sc);
423int ssl_set_peer_cert_type(SESS_CERT *c, int type);
424int ssl_get_new_session(SSL *s, int session);
425int ssl_get_prev_session(SSL *s, unsigned char *session,int len);
426int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b);
427int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp);
428STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
429 STACK_OF(SSL_CIPHER) **skp);
430int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p);
431STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
432 STACK_OF(SSL_CIPHER) **pref,
433 STACK_OF(SSL_CIPHER) **sorted,
434 const char *rule_str);
435void ssl_update_cache(SSL *s, int mode);
436int ssl_cipher_get_evp(SSL_SESSION *s,const EVP_CIPHER **enc,const EVP_MD **md,
437 SSL_COMP **comp);
438int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);
439int ssl_undefined_function(SSL *s);
440X509 *ssl_get_server_send_cert(SSL *);
441EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
442int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
443void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher);
444STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
445int ssl_verify_alarm_type(long type);
446
447int ssl2_enc_init(SSL *s, int client);
448void ssl2_generate_key_material(SSL *s);
449void ssl2_enc(SSL *s,int send_data);
450void ssl2_mac(SSL *s,unsigned char *mac,int send_data);
451SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);
452int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
453int ssl2_part_read(SSL *s, unsigned long f, int i);
454int ssl2_do_write(SSL *s);
455int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data);
456void ssl2_return_error(SSL *s,int reason);
457void ssl2_write_error(SSL *s);
458int ssl2_num_ciphers(void);
459SSL_CIPHER *ssl2_get_cipher(unsigned int u);
460int ssl2_new(SSL *s);
461void ssl2_free(SSL *s);
462int ssl2_accept(SSL *s);
463int ssl2_connect(SSL *s);
464int ssl2_read(SSL *s, void *buf, int len);
465int ssl2_peek(SSL *s, char *buf, int len);
466int ssl2_write(SSL *s, const void *buf, int len);
467int ssl2_shutdown(SSL *s);
468void ssl2_clear(SSL *s);
469long ssl2_ctrl(SSL *s,int cmd, long larg, char *parg);
470long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
471long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)());
472long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
473int ssl2_pending(SSL *s);
474
475SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
476int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
477void ssl3_init_finished_mac(SSL *s);
478int ssl3_send_server_certificate(SSL *s);
479int ssl3_get_finished(SSL *s,int state_a,int state_b);
480int ssl3_setup_key_block(SSL *s);
481int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b);
482int ssl3_change_cipher_state(SSL *s,int which);
483void ssl3_cleanup_key_block(SSL *s);
484int ssl3_do_write(SSL *s,int type);
485void ssl3_send_alert(SSL *s,int level, int desc);
486int ssl3_generate_master_secret(SSL *s, unsigned char *out,
487 unsigned char *p, int len);
488int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
489long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
490int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen);
491int ssl3_num_ciphers(void);
492SSL_CIPHER *ssl3_get_cipher(unsigned int u);
493int ssl3_renegotiate(SSL *ssl);
494int ssl3_renegotiate_check(SSL *ssl);
495int ssl3_dispatch_alert(SSL *s);
496int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len);
497int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
498int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2,
499 const char *sender, int slen,unsigned char *p);
500int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
501void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len);
502int ssl3_enc(SSL *s, int send_data);
503int ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
504unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
505SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *have,
506 STACK_OF(SSL_CIPHER) *pref);
507int ssl3_setup_buffers(SSL *s);
508int ssl3_new(SSL *s);
509void ssl3_free(SSL *s);
510int ssl3_accept(SSL *s);
511int ssl3_connect(SSL *s);
512int ssl3_read(SSL *s, void *buf, int len);
513int ssl3_peek(SSL *s,char *buf, int len);
514int ssl3_write(SSL *s, const void *buf, int len);
515int ssl3_shutdown(SSL *s);
516void ssl3_clear(SSL *s);
517long ssl3_ctrl(SSL *s,int cmd, long larg, char *parg);
518long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
519long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)());
520long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
521int ssl3_pending(SSL *s);
522
523int ssl23_accept(SSL *s);
524int ssl23_connect(SSL *s);
525int ssl23_read_bytes(SSL *s, int n);
526int ssl23_write_bytes(SSL *s);
527
528int tls1_new(SSL *s);
529void tls1_free(SSL *s);
530void tls1_clear(SSL *s);
531long tls1_ctrl(SSL *s,int cmd, long larg, char *parg);
532long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)());
533SSL_METHOD *tlsv1_base_method(void );
534
535int ssl_init_wbio_buffer(SSL *s, int push);
536void ssl_free_wbio_buffer(SSL *s);
537
538int tls1_change_cipher_state(SSL *s, int which);
539int tls1_setup_key_block(SSL *s);
540int tls1_enc(SSL *s, int snd);
541int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
542 const char *str, int slen, unsigned char *p);
543int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
544int tls1_mac(SSL *ssl, unsigned char *md, int snd);
545int tls1_generate_master_secret(SSL *s, unsigned char *out,
546 unsigned char *p, int len);
547int tls1_alert_code(int code);
548int ssl3_alert_code(int code);
549int ssl_ok(SSL *s);
550
551SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
552STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
553
554
555#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 9e01f72753..0000000000
--- a/src/lib/libssl/ssl_sess.c
+++ /dev/null
@@ -1,680 +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_OF(CRYPTO_EX_DATA_FUNCS) *ssl_session_meth=NULL;
69
70SSL_SESSION *SSL_get_session(SSL *ssl)
71/* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
72 {
73 return(ssl->session);
74 }
75
76SSL_SESSION *SSL_get1_session(SSL *ssl)
77/* variant of SSL_get_session: caller really gets something */
78 {
79 SSL_SESSION *sess;
80 /* Need to lock this all up rather than just use CRYPTO_add so that
81 * somebody doesn't free ssl->session between when we check it's
82 * non-null and when we up the reference count. */
83 CRYPTO_r_lock(CRYPTO_LOCK_SSL_SESSION);
84 sess = ssl->session;
85 if(sess)
86 sess->references++;
87 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_SESSION);
88 return(sess);
89 }
90
91int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
92 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
93 {
94 ssl_session_num++;
95 return(CRYPTO_get_ex_new_index(ssl_session_num-1,
96 &ssl_session_meth,
97 argl,argp,new_func,dup_func,free_func));
98 }
99
100int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
101 {
102 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
103 }
104
105void *SSL_SESSION_get_ex_data(SSL_SESSION *s, int idx)
106 {
107 return(CRYPTO_get_ex_data(&s->ex_data,idx));
108 }
109
110SSL_SESSION *SSL_SESSION_new(void)
111 {
112 SSL_SESSION *ss;
113
114 ss=(SSL_SESSION *)Malloc(sizeof(SSL_SESSION));
115 if (ss == NULL)
116 {
117 SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);
118 return(0);
119 }
120 memset(ss,0,sizeof(SSL_SESSION));
121
122 ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
123 ss->references=1;
124 ss->timeout=60*5+4; /* 5 minute timeout by default */
125 ss->time=time(NULL);
126 ss->prev=NULL;
127 ss->next=NULL;
128 ss->compress_meth=0;
129 CRYPTO_new_ex_data(ssl_session_meth,ss,&ss->ex_data);
130 return(ss);
131 }
132
133int ssl_get_new_session(SSL *s, int session)
134 {
135 /* This gets used by clients and servers. */
136
137 SSL_SESSION *ss=NULL;
138
139 if ((ss=SSL_SESSION_new()) == NULL) return(0);
140
141 /* If the context has a default timeout, use it */
142 if (s->ctx->session_timeout == 0)
143 ss->timeout=SSL_get_default_timeout(s);
144 else
145 ss->timeout=s->ctx->session_timeout;
146
147 if (s->session != NULL)
148 {
149 SSL_SESSION_free(s->session);
150 s->session=NULL;
151 }
152
153 if (session)
154 {
155 if (s->version == SSL2_VERSION)
156 {
157 ss->ssl_version=SSL2_VERSION;
158 ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH;
159 }
160 else if (s->version == SSL3_VERSION)
161 {
162 ss->ssl_version=SSL3_VERSION;
163 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
164 }
165 else if (s->version == TLS1_VERSION)
166 {
167 ss->ssl_version=TLS1_VERSION;
168 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
169 }
170 else
171 {
172 SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION);
173 SSL_SESSION_free(ss);
174 return(0);
175 }
176
177 for (;;)
178 {
179 SSL_SESSION *r;
180
181 RAND_pseudo_bytes(ss->session_id,ss->session_id_length);
182 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
183 r=(SSL_SESSION *)lh_retrieve(s->ctx->sessions, ss);
184 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
185 if (r == NULL) break;
186 /* else - woops a session_id match */
187 /* XXX We should also check the external cache --
188 * but the probability of a collision is negligible, and
189 * we could not prevent the concurrent creation of sessions
190 * with identical IDs since we currently don't have means
191 * to atomically check whether a session ID already exists
192 * and make a reservation for it if it does not
193 * (this problem applies to the internal cache as well).
194 */
195 }
196 }
197 else
198 {
199 ss->session_id_length=0;
200 }
201
202 memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length);
203 ss->sid_ctx_length=s->sid_ctx_length;
204 s->session=ss;
205 ss->ssl_version=s->version;
206 ss->verify_result = X509_V_OK;
207
208 return(1);
209 }
210
211int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len)
212 {
213 /* This is used only by servers. */
214
215 SSL_SESSION *ret=NULL,data;
216 int fatal = 0;
217
218 data.ssl_version=s->version;
219 data.session_id_length=len;
220 if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
221 goto err;
222 memcpy(data.session_id,session_id,len);
223
224 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
225 {
226 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
227 ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data);
228 if (ret != NULL)
229 /* don't allow other threads to steal it: */
230 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
231 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
232 }
233
234 if (ret == NULL)
235 {
236 int copy=1;
237
238 s->ctx->stats.sess_miss++;
239 ret=NULL;
240 if (s->ctx->get_session_cb != NULL
241 && (ret=s->ctx->get_session_cb(s,session_id,len,&copy))
242 != NULL)
243 {
244 s->ctx->stats.sess_cb_hit++;
245
246 /* Increment reference count now if the session callback
247 * asks us to do so (note that if the session structures
248 * returned by the callback are shared between threads,
249 * it must handle the reference count itself [i.e. copy == 0],
250 * or things won't be thread-safe). */
251 if (copy)
252 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
253
254 /* The following should not return 1, otherwise,
255 * things are very strange */
256 SSL_CTX_add_session(s->ctx,ret);
257 }
258 if (ret == NULL)
259 goto err;
260 }
261
262 /* Now ret is non-NULL, and we own one of its reference counts. */
263
264 if((s->verify_mode&SSL_VERIFY_PEER)
265 && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length
266 || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length)))
267 {
268 /* We've found the session named by the client, but we don't
269 * want to use it in this context. */
270
271 if (s->sid_ctx_length == 0)
272 {
273 /* application should have used SSL[_CTX]_set_session_id_context
274 * -- we could tolerate this and just pretend we never heard
275 * of this session, but then applications could effectively
276 * disable the session cache by accident without anyone noticing */
277
278 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
279 fatal = 1;
280 goto err;
281 }
282 else
283 {
284#if 0 /* The client cannot always know when a session is not appropriate,
285 * so we shouldn't generate an error message. */
286
287 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
288#endif
289 goto err; /* treat like cache miss */
290 }
291 }
292
293 if (ret->cipher == NULL)
294 {
295 unsigned char buf[5],*p;
296 unsigned long l;
297
298 p=buf;
299 l=ret->cipher_id;
300 l2n(l,p);
301 if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR)
302 ret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));
303 else
304 ret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));
305 if (ret->cipher == NULL)
306 goto err;
307 }
308
309
310#if 0 /* This is way too late. */
311
312 /* If a thread got the session, then 'swaped', and another got
313 * it and then due to a time-out decided to 'Free' it we could
314 * be in trouble. So I'll increment it now, then double decrement
315 * later - am I speaking rubbish?. */
316 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
317#endif
318
319 if ((long)(ret->time+ret->timeout) < (long)time(NULL)) /* timeout */
320 {
321 s->ctx->stats.sess_timeout++;
322 /* remove it from the cache */
323 SSL_CTX_remove_session(s->ctx,ret);
324 goto err;
325 }
326
327 s->ctx->stats.sess_hit++;
328
329 /* ret->time=time(NULL); */ /* rezero timeout? */
330 /* again, just leave the session
331 * if it is the same session, we have just incremented and
332 * then decremented the reference count :-) */
333 if (s->session != NULL)
334 SSL_SESSION_free(s->session);
335 s->session=ret;
336 s->verify_result = s->session->verify_result;
337 return(1);
338
339 err:
340 if (ret != NULL)
341 SSL_SESSION_free(ret);
342 if (fatal)
343 return -1;
344 else
345 return 0;
346 }
347
348int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
349 {
350 int ret=0;
351 SSL_SESSION *s;
352
353 /* add just 1 reference count for the SSL_CTX's session cache
354 * even though it has two ways of access: each session is in a
355 * doubly linked list and an lhash */
356 CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);
357 /* if session c is in already in cache, we take back the increment later */
358
359 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
360 s=(SSL_SESSION *)lh_insert(ctx->sessions,c);
361
362 /* s != NULL iff we already had a session with the given PID.
363 * In this case, s == c should hold (then we did not really modify
364 * ctx->sessions), or we're in trouble. */
365 if (s != NULL && s != c)
366 {
367 /* We *are* in trouble ... */
368 SSL_SESSION_list_remove(ctx,s);
369 SSL_SESSION_free(s);
370 /* ... so pretend the other session did not exist in cache
371 * (we cannot handle two SSL_SESSION structures with identical
372 * session ID in the same cache, which could happen e.g. when
373 * two threads concurrently obtain the same session from an external
374 * cache) */
375 s = NULL;
376 }
377
378 /* Put at the head of the queue unless it is already in the cache */
379 if (s == NULL)
380 SSL_SESSION_list_add(ctx,c);
381
382 if (s != NULL)
383 {
384 /* existing cache entry -- decrement previously incremented reference
385 * count because it already takes into account the cache */
386
387 SSL_SESSION_free(s); /* s == c */
388 ret=0;
389 }
390 else
391 {
392 /* new cache entry -- remove old ones if cache has become too large */
393
394 ret=1;
395
396 if (SSL_CTX_sess_get_cache_size(ctx) > 0)
397 {
398 while (SSL_CTX_sess_number(ctx) >
399 SSL_CTX_sess_get_cache_size(ctx))
400 {
401 if (!remove_session_lock(ctx,
402 ctx->session_cache_tail, 0))
403 break;
404 else
405 ctx->stats.sess_cache_full++;
406 }
407 }
408 }
409 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
410 return(ret);
411 }
412
413int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
414{
415 return remove_session_lock(ctx, c, 1);
416}
417
418static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
419 {
420 SSL_SESSION *r;
421 int ret=0;
422
423 if ((c != NULL) && (c->session_id_length != 0))
424 {
425 if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
426 r=(SSL_SESSION *)lh_delete(ctx->sessions,c);
427 if (r != NULL)
428 {
429 ret=1;
430 SSL_SESSION_list_remove(ctx,c);
431 }
432
433 if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
434
435 if (ret)
436 {
437 r->not_resumable=1;
438 if (ctx->remove_session_cb != NULL)
439 ctx->remove_session_cb(ctx,r);
440 SSL_SESSION_free(r);
441 }
442 }
443 else
444 ret=0;
445 return(ret);
446 }
447
448void SSL_SESSION_free(SSL_SESSION *ss)
449 {
450 int i;
451
452 if(ss == NULL)
453 return;
454
455 i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION);
456#ifdef REF_PRINT
457 REF_PRINT("SSL_SESSION",ss);
458#endif
459 if (i > 0) return;
460#ifdef REF_CHECK
461 if (i < 0)
462 {
463 fprintf(stderr,"SSL_SESSION_free, bad reference count\n");
464 abort(); /* ok */
465 }
466#endif
467
468 CRYPTO_free_ex_data(ssl_session_meth,ss,&ss->ex_data);
469
470 memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH);
471 memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH);
472 memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH);
473 if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert);
474 if (ss->peer != NULL) X509_free(ss->peer);
475 if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers);
476 memset(ss,0,sizeof(*ss));
477 Free(ss);
478 }
479
480int SSL_set_session(SSL *s, SSL_SESSION *session)
481 {
482 int ret=0;
483 SSL_METHOD *meth;
484
485 if (session != NULL)
486 {
487 meth=s->ctx->method->get_ssl_method(session->ssl_version);
488 if (meth == NULL)
489 meth=s->method->get_ssl_method(session->ssl_version);
490 if (meth == NULL)
491 {
492 SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD);
493 return(0);
494 }
495
496 if (meth != s->method)
497 {
498 if (!SSL_set_ssl_method(s,meth))
499 return(0);
500 if (s->ctx->session_timeout == 0)
501 session->timeout=SSL_get_default_timeout(s);
502 else
503 session->timeout=s->ctx->session_timeout;
504 }
505
506 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
507 CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION);
508 if (s->session != NULL)
509 SSL_SESSION_free(s->session);
510 s->session=session;
511 /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/
512 ret=1;
513 }
514 else
515 {
516 if (s->session != NULL)
517 {
518 SSL_SESSION_free(s->session);
519 s->session=NULL;
520 }
521
522 meth=s->ctx->method;
523 if (meth != s->method)
524 {
525 if (!SSL_set_ssl_method(s,meth))
526 return(0);
527 }
528 ret=1;
529 }
530 return(ret);
531 }
532
533long SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
534 {
535 if (s == NULL) return(0);
536 s->timeout=t;
537 return(1);
538 }
539
540long SSL_SESSION_get_timeout(SSL_SESSION *s)
541 {
542 if (s == NULL) return(0);
543 return(s->timeout);
544 }
545
546long SSL_SESSION_get_time(SSL_SESSION *s)
547 {
548 if (s == NULL) return(0);
549 return(s->time);
550 }
551
552long SSL_SESSION_set_time(SSL_SESSION *s, long t)
553 {
554 if (s == NULL) return(0);
555 s->time=t;
556 return(t);
557 }
558
559long SSL_CTX_set_timeout(SSL_CTX *s, long t)
560 {
561 long l;
562 if (s == NULL) return(0);
563 l=s->session_timeout;
564 s->session_timeout=t;
565 return(l);
566 }
567
568long SSL_CTX_get_timeout(SSL_CTX *s)
569 {
570 if (s == NULL) return(0);
571 return(s->session_timeout);
572 }
573
574typedef struct timeout_param_st
575 {
576 SSL_CTX *ctx;
577 long time;
578 LHASH *cache;
579 } TIMEOUT_PARAM;
580
581static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p)
582 {
583 if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */
584 {
585 /* The reason we don't call SSL_CTX_remove_session() is to
586 * save on locking overhead */
587 lh_delete(p->cache,s);
588 SSL_SESSION_list_remove(p->ctx,s);
589 s->not_resumable=1;
590 if (p->ctx->remove_session_cb != NULL)
591 p->ctx->remove_session_cb(p->ctx,s);
592 SSL_SESSION_free(s);
593 }
594 }
595
596void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
597 {
598 unsigned long i;
599 TIMEOUT_PARAM tp;
600
601 tp.ctx=s;
602 tp.cache=s->sessions;
603 if (tp.cache == NULL) return;
604 tp.time=t;
605 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
606 i=tp.cache->down_load;
607 tp.cache->down_load=0;
608 lh_doall_arg(tp.cache,(void (*)())timeout,&tp);
609 tp.cache->down_load=i;
610 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
611 }
612
613int ssl_clear_bad_session(SSL *s)
614 {
615 if ( (s->session != NULL) &&
616 !(s->shutdown & SSL_SENT_SHUTDOWN) &&
617 !(SSL_in_init(s) || SSL_in_before(s)))
618 {
619 SSL_CTX_remove_session(s->ctx,s->session);
620 return(1);
621 }
622 else
623 return(0);
624 }
625
626/* locked by SSL_CTX in the calling function */
627static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
628 {
629 if ((s->next == NULL) || (s->prev == NULL)) return;
630
631 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail))
632 { /* last element in list */
633 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
634 { /* only one element in list */
635 ctx->session_cache_head=NULL;
636 ctx->session_cache_tail=NULL;
637 }
638 else
639 {
640 ctx->session_cache_tail=s->prev;
641 s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail);
642 }
643 }
644 else
645 {
646 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
647 { /* first element in list */
648 ctx->session_cache_head=s->next;
649 s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head);
650 }
651 else
652 { /* middle of list */
653 s->next->prev=s->prev;
654 s->prev->next=s->next;
655 }
656 }
657 s->prev=s->next=NULL;
658 }
659
660static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
661 {
662 if ((s->next != NULL) && (s->prev != NULL))
663 SSL_SESSION_list_remove(ctx,s);
664
665 if (ctx->session_cache_head == NULL)
666 {
667 ctx->session_cache_head=s;
668 ctx->session_cache_tail=s;
669 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
670 s->next=(SSL_SESSION *)&(ctx->session_cache_tail);
671 }
672 else
673 {
674 s->next=ctx->session_cache_head;
675 s->next->prev=s;
676 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
677 ctx->session_cache_head=s;
678 }
679 }
680
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c
deleted file mode 100644
index 8e12461f3b..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 compatibility 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 compatibility 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="unexpected_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="certificate 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 c07d957576..0000000000
--- a/src/lib/libssl/ssl_txt.c
+++ /dev/null
@@ -1,176 +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,"\n Session-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 if (BIO_puts(bp, " Verify return code: ") <= 0) goto err;
168 sprintf(str, "%ld (%s)\n", x->verify_result,
169 X509_verify_cert_error_string(x->verify_result));
170 if (BIO_puts(bp,str) <= 0) goto err;
171
172 return(1);
173err:
174 return(0);
175 }
176
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 279e45db5d..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 const 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_RESTRICTION: return(TLS1_AD_EXPORT_RESTRICTION);
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_CANCELLED: return(TLS1_AD_USER_CANCELLED);
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 ca6c03d5af..0000000000
--- a/src/lib/libssl/t1_lib.c
+++ /dev/null
@@ -1,149 +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
63const char *tls1_version_str="TLSv1" OPENSSL_VERSION_PTEXT;
64
65static long tls1_default_timeout(void);
66
67static SSL3_ENC_METHOD TLSv1_enc_data={
68 tls1_enc,
69 tls1_mac,
70 tls1_setup_key_block,
71 tls1_generate_master_secret,
72 tls1_change_cipher_state,
73 tls1_final_finish_mac,
74 TLS1_FINISH_MAC_LENGTH,
75 tls1_cert_verify_mac,
76 TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
77 TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
78 tls1_alert_code,
79 };
80
81static SSL_METHOD TLSv1_data= {
82 TLS1_VERSION,
83 tls1_new,
84 tls1_clear,
85 tls1_free,
86 ssl_undefined_function,
87 ssl_undefined_function,
88 ssl3_read,
89 ssl3_peek,
90 ssl3_write,
91 ssl3_shutdown,
92 ssl3_renegotiate,
93 ssl3_renegotiate_check,
94 ssl3_ctrl,
95 ssl3_ctx_ctrl,
96 ssl3_get_cipher_by_char,
97 ssl3_put_cipher_by_char,
98 ssl3_pending,
99 ssl3_num_ciphers,
100 ssl3_get_cipher,
101 ssl_bad_method,
102 tls1_default_timeout,
103 &TLSv1_enc_data,
104 ssl_undefined_function,
105 ssl3_callback_ctrl,
106 ssl3_ctx_callback_ctrl,
107 };
108
109static long tls1_default_timeout(void)
110 {
111 /* 2 hours, the 24 hours mentioned in the TLSv1 spec
112 * is way too long for http, the cache would over fill */
113 return(60*60*2);
114 }
115
116SSL_METHOD *tlsv1_base_method(void)
117 {
118 return(&TLSv1_data);
119 }
120
121int tls1_new(SSL *s)
122 {
123 if (!ssl3_new(s)) return(0);
124 s->method->ssl_clear(s);
125 return(1);
126 }
127
128void tls1_free(SSL *s)
129 {
130 ssl3_free(s);
131 }
132
133void tls1_clear(SSL *s)
134 {
135 ssl3_clear(s);
136 s->version=TLS1_VERSION;
137 }
138
139#if 0
140long tls1_ctrl(SSL *s, int cmd, long larg, char *parg)
141 {
142 return(0);
143 }
144
145long tls1_callback_ctrl(SSL *s, int cmd, void *(*fp)())
146 {
147 return(0);
148 }
149#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 c5f61b582b..0000000000
--- a/src/lib/libssl/test/testgen
+++ /dev/null
@@ -1,32 +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
18echo "string to make the random number generator think it has entropy" >> ./.rnd
19
20../apps/openssl req -config test.cnf -new -out testreq.pem
21if [ $? != 0 ]; then
22echo problems creating request
23exit 1
24fi
25
26../apps/openssl req -config test.cnf -verify -in testreq.pem -noout
27if [ $? != 0 ]; then
28echo signature on req is wrong
29exit 1
30fi
31
32exit 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 a88e290c57..0000000000
--- a/src/lib/libssl/test/testssl
+++ /dev/null
@@ -1,81 +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 w/o DHE via BIO pair
67./ssltest -bio_pair -no_dhe || exit 1
68
69echo test sslv2/sslv3 with 1024bit DHE
70./ssltest -bio_pair -dhe1024 -v || exit 1
71
72echo test sslv2/sslv3 with server authentication
73./ssltest -bio_pair -server_auth -CApath ../certs || exit 1
74
75echo test sslv2/sslv3 with client authentication via BIO pair
76./ssltest -bio_pair -client_auth -CApath ../certs || exit 1
77
78echo test sslv2/sslv3 with both client and server authentication via BIO pair
79./ssltest -bio_pair -server_auth -client_auth -CApath ../certs || exit 1
80
81exit 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 6e2b06d34f..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 1
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_RESTRICTION 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_CANCELLED 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