summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/aes/README3
-rw-r--r--src/lib/libcrypto/aes/aes.h127
-rw-r--r--src/lib/libcrypto/aes/aes_cbc.c133
-rw-r--r--src/lib/libcrypto/aes/aes_cfb.c225
-rw-r--r--src/lib/libcrypto/aes/aes_core.c1261
-rw-r--r--src/lib/libcrypto/aes/aes_ctr.c139
-rw-r--r--src/lib/libcrypto/aes/aes_ecb.c73
-rw-r--r--src/lib/libcrypto/aes/aes_locl.h85
-rw-r--r--src/lib/libcrypto/aes/aes_misc.c64
-rw-r--r--src/lib/libcrypto/aes/aes_ofb.c142
-rw-r--r--src/lib/libcrypto/aes/asm/aes-586.pl1541
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c222
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c114
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c312
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c262
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c111
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c107
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c180
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c163
-rw-r--r--src/lib/libcrypto/asn1/a_int.c453
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c400
-rw-r--r--src/lib/libcrypto/asn1/a_object.c320
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c71
-rw-r--r--src/lib/libcrypto/asn1/a_print.c127
-rw-r--r--src/lib/libcrypto/asn1/a_set.c235
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c294
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c567
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c290
-rw-r--r--src/lib/libcrypto/asn1/a_time.c164
-rw-r--r--src/lib/libcrypto/asn1/a_type.c84
-rw-r--r--src/lib/libcrypto/asn1/a_utf8.c211
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c181
-rw-r--r--src/lib/libcrypto/asn1/asn1.h1113
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c254
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c433
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h560
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c418
-rw-r--r--src/lib/libcrypto/asn1/asn1t.h846
-rw-r--r--src/lib/libcrypto/asn1/asn_moid.c100
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c191
-rw-r--r--src/lib/libcrypto/asn1/charmap.h15
-rw-r--r--src/lib/libcrypto/asn1/charmap.pl80
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c145
-rw-r--r--src/lib/libcrypto/asn1/d2i_pu.c122
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c189
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c207
-rw-r--r--src/lib/libcrypto/asn1/f_int.c219
-rw-r--r--src/lib/libcrypto/asn1/f_string.c212
-rw-r--r--src/lib/libcrypto/asn1/i2d_pr.c90
-rw-r--r--src/lib/libcrypto/asn1/i2d_pu.c88
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c333
-rw-r--r--src/lib/libcrypto/asn1/nsseq.c82
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c130
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c205
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c84
-rw-r--r--src/lib/libcrypto/asn1/t_bitst.c102
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c134
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c387
-rw-r--r--src/lib/libcrypto/asn1/t_req.c276
-rw-r--r--src/lib/libcrypto/asn1/t_spki.c116
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c505
-rw-r--r--src/lib/libcrypto/asn1/t_x509a.c110
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c1023
-rw-r--r--src/lib/libcrypto/asn1/tasn_enc.c500
-rw-r--r--src/lib/libcrypto/asn1/tasn_fre.c229
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c351
-rw-r--r--src/lib/libcrypto/asn1/tasn_prn.c198
-rw-r--r--src/lib/libcrypto/asn1/tasn_typ.c133
-rw-r--r--src/lib/libcrypto/asn1/tasn_utl.c253
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c73
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c118
-rw-r--r--src/lib/libcrypto/asn1/x_bignum.c137
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c140
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c71
-rw-r--r--src/lib/libcrypto/asn1/x_info.c114
-rw-r--r--src/lib/libcrypto/asn1/x_long.c169
-rw-r--r--src/lib/libcrypto/asn1/x_name.c275
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c151
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c360
-rw-r--r--src/lib/libcrypto/asn1/x_req.c112
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c69
-rw-r--r--src/lib/libcrypto/asn1/x_spki.c81
-rw-r--r--src/lib/libcrypto/asn1/x_val.c69
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c189
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c151
-rw-r--r--src/lib/libcrypto/bf/COPYRIGHT46
-rw-r--r--src/lib/libcrypto/bf/INSTALL14
-rw-r--r--src/lib/libcrypto/bf/README8
-rw-r--r--src/lib/libcrypto/bf/VERSION6
-rw-r--r--src/lib/libcrypto/bf/asm/bf-586.pl136
-rw-r--r--src/lib/libcrypto/bf/bf_cbc.c143
-rw-r--r--src/lib/libcrypto/bf/bf_cfb64.c121
-rw-r--r--src/lib/libcrypto/bf/bf_ecb.c96
-rw-r--r--src/lib/libcrypto/bf/bf_enc.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.c118
-rw-r--r--src/lib/libcrypto/bf/blowfish.h130
-rw-r--r--src/lib/libcrypto/bio/b_dump.c156
-rw-r--r--src/lib/libcrypto/bio/b_print.c841
-rw-r--r--src/lib/libcrypto/bio/b_sock.c752
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c511
-rw-r--r--src/lib/libcrypto/bio/bf_lbuf.c397
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c255
-rw-r--r--src/lib/libcrypto/bio/bf_null.c183
-rw-r--r--src/lib/libcrypto/bio/bio.h695
-rw-r--r--src/lib/libcrypto/bio/bio_cb.c139
-rw-r--r--src/lib/libcrypto/bio/bio_err.c156
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c556
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c479
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c924
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c652
-rw-r--r--src/lib/libcrypto/bio/bss_fd.c282
-rw-r--r--src/lib/libcrypto/bio/bss_file.c343
-rw-r--r--src/lib/libcrypto/bio/bss_log.c400
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c321
-rw-r--r--src/lib/libcrypto/bio/bss_null.c150
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c305
-rw-r--r--src/lib/libcrypto/bn/asm/bn-586.pl593
-rw-r--r--src/lib/libcrypto/bn/asm/co-586.pl286
-rw-r--r--src/lib/libcrypto/bn/asm/ia64.S1560
-rw-r--r--src/lib/libcrypto/bn/asm/pa-risc2.s1618
-rw-r--r--src/lib/libcrypto/bn/asm/pa-risc2W.s1605
-rw-r--r--src/lib/libcrypto/bn/asm/ppc.pl2078
-rw-r--r--src/lib/libcrypto/bn/asm/sparcv8.S1458
-rw-r--r--src/lib/libcrypto/bn/asm/sparcv8plus.S1547
-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/asm/x86_64-gcc.c593
-rw-r--r--src/lib/libcrypto/bn/bn.h583
-rw-r--r--src/lib/libcrypto/bn/bn_add.c309
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c832
-rw-r--r--src/lib/libcrypto/bn/bn_blind.c144
-rw-r--r--src/lib/libcrypto/bn/bn_ctx.c155
-rw-r--r--src/lib/libcrypto/bn/bn_div.c387
-rw-r--r--src/lib/libcrypto/bn/bn_err.c139
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c987
-rw-r--r--src/lib/libcrypto/bn/bn_exp2.c313
-rw-r--r--src/lib/libcrypto/bn/bn_gcd.c490
-rw-r--r--src/lib/libcrypto/bn/bn_kron.c182
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h492
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c824
-rw-r--r--src/lib/libcrypto/bn/bn_mod.c296
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c421
-rw-r--r--src/lib/libcrypto/bn/bn_mpi.c129
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c802
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c468
-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.c333
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c291
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c230
-rw-r--r--src/lib/libcrypto/bn/bn_shift.c205
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c288
-rw-r--r--src/lib/libcrypto/bn/bn_sqrt.c387
-rw-r--r--src/lib/libcrypto/bn/bn_word.c208
-rw-r--r--src/lib/libcrypto/bn/bn_x931p.c282
-rw-r--r--src/lib/libcrypto/buffer/buf_err.c99
-rw-r--r--src/lib/libcrypto/buffer/buffer.c202
-rw-r--r--src/lib/libcrypto/buffer/buffer.h105
-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.c209
-rw-r--r--src/lib/libcrypto/cast/c_ofb64.c111
-rw-r--r--src/lib/libcrypto/cast/c_skey.c169
-rw-r--r--src/lib/libcrypto/cast/cast.h106
-rw-r--r--src/lib/libcrypto/cast/cast_lcl.h227
-rw-r--r--src/lib/libcrypto/cast/cast_s.h585
-rw-r--r--src/lib/libcrypto/comp/c_rle.c62
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c215
-rw-r--r--src/lib/libcrypto/comp/comp.h59
-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/README78
-rw-r--r--src/lib/libcrypto/conf/conf.h250
-rw-r--r--src/lib/libcrypto/conf/conf_api.c308
-rw-r--r--src/lib/libcrypto/conf/conf_api.h89
-rw-r--r--src/lib/libcrypto/conf/conf_def.c750
-rw-r--r--src/lib/libcrypto/conf/conf_def.h180
-rw-r--r--src/lib/libcrypto/conf/conf_err.c130
-rw-r--r--src/lib/libcrypto/conf/conf_lib.c401
-rw-r--r--src/lib/libcrypto/conf/conf_mall.c80
-rw-r--r--src/lib/libcrypto/conf/conf_mod.c616
-rw-r--r--src/lib/libcrypto/conf/conf_sap.c111
-rw-r--r--src/lib/libcrypto/conf/keysets.pl185
-rw-r--r--src/lib/libcrypto/conf/ssleay.cnf78
-rw-r--r--src/lib/libcrypto/cpt_err.c106
-rw-r--r--src/lib/libcrypto/cryptlib.c744
-rw-r--r--src/lib/libcrypto/cryptlib.h104
-rw-r--r--src/lib/libcrypto/crypto.h518
-rw-r--r--src/lib/libcrypto/cversion.c120
-rw-r--r--src/lib/libcrypto/des/COPYRIGHT50
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl208
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl255
-rw-r--r--src/lib/libcrypto/des/asm/desboth.pl79
-rw-r--r--src/lib/libcrypto/des/cbc_cksm.c106
-rw-r--r--src/lib/libcrypto/des/cbc_enc.c61
-rw-r--r--src/lib/libcrypto/des/cfb64ede.c254
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c121
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c174
-rw-r--r--src/lib/libcrypto/des/des.h246
-rw-r--r--src/lib/libcrypto/des/des_enc.c417
-rw-r--r--src/lib/libcrypto/des/des_locl.h428
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c81
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c123
-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.c173
-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.c125
-rw-r--r--src/lib/libcrypto/des/ofb64enc.c110
-rw-r--r--src/lib/libcrypto/des/ofb_enc.c135
-rw-r--r--src/lib/libcrypto/des/pcbc_enc.c123
-rw-r--r--src/lib/libcrypto/des/qud_cksm.c139
-rw-r--r--src/lib/libcrypto/des/rand_key.c68
-rw-r--r--src/lib/libcrypto/des/set_key.c411
-rw-r--r--src/lib/libcrypto/des/spr.h204
-rw-r--r--src/lib/libcrypto/des/str2key.c173
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c195
-rw-r--r--src/lib/libcrypto/dh/dh.h223
-rw-r--r--src/lib/libcrypto/dh/dh_asn1.c87
-rw-r--r--src/lib/libcrypto/dh/dh_check.c146
-rw-r--r--src/lib/libcrypto/dh/dh_err.c106
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c175
-rw-r--r--src/lib/libcrypto/dh/dh_key.c266
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c247
-rw-r--r--src/lib/libcrypto/doc/DH_generate_key.pod50
-rw-r--r--src/lib/libcrypto/doc/DH_generate_parameters.pod73
-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.pod129
-rw-r--r--src/lib/libcrypto/doc/DH_size.pod33
-rw-r--r--src/lib/libcrypto/doc/DSA_SIG_new.pod40
-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.pod34
-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.pod42
-rw-r--r--src/lib/libcrypto/doc/DSA_set_method.pod143
-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.pod73
-rw-r--r--src/lib/libcrypto/doc/ERR_get_error.pod76
-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_BytesToKey.pod67
-rw-r--r--src/lib/libcrypto/doc/EVP_DigestInit.pod256
-rw-r--r--src/lib/libcrypto/doc/EVP_EncryptInit.pod511
-rw-r--r--src/lib/libcrypto/doc/EVP_OpenInit.pod63
-rw-r--r--src/lib/libcrypto/doc/EVP_PKEY_new.pod47
-rw-r--r--src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod80
-rw-r--r--src/lib/libcrypto/doc/EVP_SealInit.pod85
-rw-r--r--src/lib/libcrypto/doc/EVP_SignInit.pod95
-rw-r--r--src/lib/libcrypto/doc/EVP_VerifyInit.pod86
-rw-r--r--src/lib/libcrypto/doc/OBJ_nid2obj.pod149
-rw-r--r--src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod101
-rw-r--r--src/lib/libcrypto/doc/OPENSSL_config.pod82
-rw-r--r--src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod51
-rw-r--r--src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod66
-rw-r--r--src/lib/libcrypto/doc/PKCS12_create.pod57
-rw-r--r--src/lib/libcrypto/doc/PKCS12_parse.pod50
-rw-r--r--src/lib/libcrypto/doc/PKCS7_decrypt.pod53
-rw-r--r--src/lib/libcrypto/doc/PKCS7_encrypt.pod65
-rw-r--r--src/lib/libcrypto/doc/PKCS7_sign.pod85
-rw-r--r--src/lib/libcrypto/doc/PKCS7_verify.pod116
-rw-r--r--src/lib/libcrypto/doc/RAND_add.pod77
-rw-r--r--src/lib/libcrypto/doc/RAND_bytes.pod47
-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.pod83
-rw-r--r--src/lib/libcrypto/doc/RSA_blinding_on.pod43
-rw-r--r--src/lib/libcrypto/doc/RSA_check_key.pod67
-rw-r--r--src/lib/libcrypto/doc/RSA_generate_key.pod69
-rw-r--r--src/lib/libcrypto/doc/RSA_get_ex_new_index.pod120
-rw-r--r--src/lib/libcrypto/doc/RSA_new.pod41
-rw-r--r--src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod124
-rw-r--r--src/lib/libcrypto/doc/RSA_print.pod49
-rw-r--r--src/lib/libcrypto/doc/RSA_private_encrypt.pod70
-rw-r--r--src/lib/libcrypto/doc/RSA_public_encrypt.pod84
-rw-r--r--src/lib/libcrypto/doc/RSA_set_method.pod202
-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/SMIME_read_PKCS7.pod71
-rw-r--r--src/lib/libcrypto/doc/SMIME_write_PKCS7.pod59
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod72
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod114
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod106
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_print_ex.pod105
-rw-r--r--src/lib/libcrypto/doc/X509_new.pod37
-rw-r--r--src/lib/libcrypto/doc/bn.pod158
-rw-r--r--src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod29
-rw-r--r--src/lib/libcrypto/doc/d2i_DHparams.pod30
-rw-r--r--src/lib/libcrypto/doc/d2i_DSAPublicKey.pod83
-rw-r--r--src/lib/libcrypto/doc/d2i_RSAPublicKey.pod67
-rw-r--r--src/lib/libcrypto/doc/d2i_X509.pod231
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_ALGOR.pod30
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_CRL.pod37
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_NAME.pod31
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_REQ.pod36
-rw-r--r--src/lib/libcrypto/doc/d2i_X509_SIG.pod30
-rw-r--r--src/lib/libcrypto/doc/dh.pod78
-rw-r--r--src/lib/libcrypto/doc/dsa.pod113
-rw-r--r--src/lib/libcrypto/doc/engine.pod621
-rw-r--r--src/lib/libcrypto/doc/evp.pod45
-rw-r--r--src/lib/libcrypto/doc/lh_stats.pod60
-rw-r--r--src/lib/libcrypto/doc/rsa.pod123
-rw-r--r--src/lib/libcrypto/dsa/dsa.h272
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c140
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c114
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c305
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c121
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c308
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c393
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c106
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c103
-rw-r--r--src/lib/libcrypto/dso/dso.h322
-rw-r--r--src/lib/libcrypto/dso/dso_dlfcn.c325
-rw-r--r--src/lib/libcrypto/dso/dso_err.c139
-rw-r--r--src/lib/libcrypto/dso/dso_lib.c439
-rw-r--r--src/lib/libcrypto/dso/dso_null.c86
-rw-r--r--src/lib/libcrypto/dso/dso_openssl.c81
-rw-r--r--src/lib/libcrypto/ec/ec.h243
-rw-r--r--src/lib/libcrypto/ec/ec_cvt.c80
-rw-r--r--src/lib/libcrypto/ec/ec_err.c153
-rw-r--r--src/lib/libcrypto/ec/ec_lcl.h277
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c656
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c485
-rw-r--r--src/lib/libcrypto/ec/ecp_mont.c304
-rw-r--r--src/lib/libcrypto/ec/ecp_nist.c134
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c1717
-rw-r--r--src/lib/libcrypto/engine/README211
-rw-r--r--src/lib/libcrypto/engine/eng_all.c113
-rw-r--r--src/lib/libcrypto/engine/eng_cnf.c242
-rw-r--r--src/lib/libcrypto/engine/eng_ctrl.c391
-rw-r--r--src/lib/libcrypto/engine/eng_dyn.c460
-rw-r--r--src/lib/libcrypto/engine/eng_err.c170
-rw-r--r--src/lib/libcrypto/engine/eng_fat.c147
-rw-r--r--src/lib/libcrypto/engine/eng_init.c157
-rw-r--r--src/lib/libcrypto/engine/eng_int.h185
-rw-r--r--src/lib/libcrypto/engine/eng_lib.c321
-rw-r--r--src/lib/libcrypto/engine/eng_list.c394
-rw-r--r--src/lib/libcrypto/engine/eng_openssl.c361
-rw-r--r--src/lib/libcrypto/engine/eng_pkey.c157
-rw-r--r--src/lib/libcrypto/engine/eng_table.c361
-rw-r--r--src/lib/libcrypto/engine/engine.h729
-rw-r--r--src/lib/libcrypto/engine/tb_cipher.c145
-rw-r--r--src/lib/libcrypto/engine/tb_dh.c120
-rw-r--r--src/lib/libcrypto/engine/tb_digest.c145
-rw-r--r--src/lib/libcrypto/engine/tb_dsa.c120
-rw-r--r--src/lib/libcrypto/engine/tb_rand.c120
-rw-r--r--src/lib/libcrypto/engine/tb_rsa.c120
-rw-r--r--src/lib/libcrypto/err/err.c1079
-rw-r--r--src/lib/libcrypto/err/err.h302
-rw-r--r--src/lib/libcrypto/err/err_all.c137
-rw-r--r--src/lib/libcrypto/err/err_prn.c106
-rw-r--r--src/lib/libcrypto/err/openssl.ec82
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c567
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c426
-rw-r--r--src/lib/libcrypto/evp/bio_md.c264
-rw-r--r--src/lib/libcrypto/evp/c_all.c84
-rw-r--r--src/lib/libcrypto/evp/digest.c379
-rw-r--r--src/lib/libcrypto/evp/e_aes.c118
-rw-r--r--src/lib/libcrypto/evp/e_bf.c88
-rw-r--r--src/lib/libcrypto/evp/e_cast.c90
-rw-r--r--src/lib/libcrypto/evp/e_des.c154
-rw-r--r--src/lib/libcrypto/evp/e_des3.c232
-rw-r--r--src/lib/libcrypto/evp/e_idea.c118
-rw-r--r--src/lib/libcrypto/evp/e_null.c101
-rw-r--r--src/lib/libcrypto/evp/e_old.c108
-rw-r--r--src/lib/libcrypto/evp/e_rc2.c230
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c134
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c122
-rw-r--r--src/lib/libcrypto/evp/encode.c446
-rw-r--r--src/lib/libcrypto/evp/evp.h910
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c592
-rw-r--r--src/lib/libcrypto/evp/evp_err.c171
-rw-r--r--src/lib/libcrypto/evp/evp_key.c175
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c168
-rw-r--r--src/lib/libcrypto/evp/evp_locl.h252
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c136
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c468
-rw-r--r--src/lib/libcrypto/evp/m_dss.c95
-rw-r--r--src/lib/libcrypto/evp/m_dss1.c102
-rw-r--r--src/lib/libcrypto/evp/m_md4.c97
-rw-r--r--src/lib/libcrypto/evp/m_md5.c97
-rw-r--r--src/lib/libcrypto/evp/m_null.c95
-rw-r--r--src/lib/libcrypto/evp/m_ripemd.c96
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c214
-rw-r--r--src/lib/libcrypto/evp/names.c126
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c153
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c256
-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.c337
-rw-r--r--src/lib/libcrypto/evp/p_open.c123
-rw-r--r--src/lib/libcrypto/evp/p_seal.c115
-rw-r--r--src/lib/libcrypto/evp/p_sign.c114
-rw-r--r--src/lib/libcrypto/evp/p_verify.c101
-rw-r--r--src/lib/libcrypto/ex_data.c636
-rw-r--r--src/lib/libcrypto/hmac/hmac.c183
-rw-r--r--src/lib/libcrypto/hmac/hmac.h111
-rw-r--r--src/lib/libcrypto/idea/idea.h103
-rw-r--r--src/lib/libcrypto/krb5/krb5_asn.c167
-rw-r--r--src/lib/libcrypto/krb5/krb5_asn.h256
-rw-r--r--src/lib/libcrypto/lhash/lh_stats.c248
-rw-r--r--src/lib/libcrypto/lhash/lhash.c470
-rw-r--r--src/lib/libcrypto/lhash/lhash.h199
-rw-r--r--src/lib/libcrypto/md32_common.h649
-rw-r--r--src/lib/libcrypto/md4/md4.h119
-rw-r--r--src/lib/libcrypto/md4/md4_dgst.c258
-rw-r--r--src/lib/libcrypto/md4/md4_locl.h154
-rw-r--r--src/lib/libcrypto/md4/md4_one.c97
-rw-r--r--src/lib/libcrypto/md5/asm/md5-586.pl306
-rw-r--r--src/lib/libcrypto/md5/md5.h119
-rw-r--r--src/lib/libcrypto/md5/md5_dgst.c292
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h172
-rw-r--r--src/lib/libcrypto/md5/md5_one.c97
-rw-r--r--src/lib/libcrypto/mem_clr.c75
-rw-r--r--src/lib/libcrypto/mem_dbg.c787
-rw-r--r--src/lib/libcrypto/o_str.c96
-rw-r--r--src/lib/libcrypto/o_time.c217
-rw-r--r--src/lib/libcrypto/o_time.h66
-rw-r--r--src/lib/libcrypto/objects/o_names.c369
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c668
-rw-r--r--src/lib/libcrypto/objects/obj_dat.pl307
-rw-r--r--src/lib/libcrypto/objects/obj_err.c105
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c127
-rw-r--r--src/lib/libcrypto/objects/obj_mac.num675
-rw-r--r--src/lib/libcrypto/objects/objects.README44
-rw-r--r--src/lib/libcrypto/objects/objects.h1044
-rw-r--r--src/lib/libcrypto/objects/objects.pl230
-rw-r--r--src/lib/libcrypto/objects/objects.txt952
-rw-r--r--src/lib/libcrypto/ocsp/ocsp.h619
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_asn.c182
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_cl.c370
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_err.c143
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ext.c538
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ht.c173
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_lib.c262
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_prn.c291
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_srv.c264
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_vfy.c444
-rw-r--r--src/lib/libcrypto/opensslv.h89
-rw-r--r--src/lib/libcrypto/ossl_typ.h122
-rw-r--r--src/lib/libcrypto/pem/message16
-rw-r--r--src/lib/libcrypto/pem/pem.h672
-rw-r--r--src/lib/libcrypto/pem/pem2.h70
-rw-r--r--src/lib/libcrypto/pem/pem_all.c315
-rw-r--r--src/lib/libcrypto/pem/pem_err.c135
-rw-r--r--src/lib/libcrypto/pem/pem_info.c365
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c776
-rw-r--r--src/lib/libcrypto/pem/pem_oth.c85
-rw-r--r--src/lib/libcrypto/pem/pem_pk8.c243
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c145
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c187
-rw-r--r--src/lib/libcrypto/pem/pem_sign.c102
-rw-r--r--src/lib/libcrypto/pem/pem_x509.c69
-rw-r--r--src/lib/libcrypto/pem/pem_xaux.c68
-rw-r--r--src/lib/libcrypto/pem/pkcs7.lis22
-rw-r--r--src/lib/libcrypto/perlasm/cbc.pl349
-rw-r--r--src/lib/libcrypto/perlasm/readme124
-rw-r--r--src/lib/libcrypto/perlasm/x86asm.pl135
-rw-r--r--src/lib/libcrypto/pkcs12/p12_add.c224
-rw-r--r--src/lib/libcrypto/pkcs12/p12_asn.c125
-rw-r--r--src/lib/libcrypto/pkcs12/p12_attr.c145
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crpt.c124
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crt.c172
-rw-r--r--src/lib/libcrypto/pkcs12/p12_decr.c176
-rw-r--r--src/lib/libcrypto/pkcs12/p12_init.c92
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c206
-rw-r--r--src/lib/libcrypto/pkcs12/p12_kiss.c297
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c182
-rw-r--r--src/lib/libcrypto/pkcs12/p12_npas.c217
-rw-r--r--src/lib/libcrypto/pkcs12/p12_p8d.c68
-rw-r--r--src/lib/libcrypto/pkcs12/p12_p8e.c97
-rw-r--r--src/lib/libcrypto/pkcs12/p12_utl.c146
-rw-r--r--src/lib/libcrypto/pkcs12/pk12err.c146
-rw-r--r--src/lib/libcrypto/pkcs12/pkcs12.h323
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_asn1.c213
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c140
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c1013
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c500
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_mime.c734
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c469
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.h451
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7err.c164
-rw-r--r--src/lib/libcrypto/rand/rand.h143
-rw-r--r--src/lib/libcrypto/rand/rand_err.c105
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c192
-rw-r--r--src/lib/libcrypto/rand/randfile.c285
-rw-r--r--src/lib/libcrypto/rc2/rc2.h104
-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.c152
-rw-r--r--src/lib/libcrypto/rc2/rc2cfb64.c122
-rw-r--r--src/lib/libcrypto/rc2/rc2ofb64.c111
-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.pl229
-rwxr-xr-xsrc/lib/libcrypto/rc4/asm/rc4-x86_64.pl150
-rw-r--r--src/lib/libcrypto/rc4/rc4.h91
-rw-r--r--src/lib/libcrypto/rc4/rc4_enc.c315
-rw-r--r--src/lib/libcrypto/rc4/rc4_locl.h5
-rw-r--r--src/lib/libcrypto/rc4/rc4_skey.c120
-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.h106
-rw-r--r--src/lib/libcrypto/ripemd/rmd_dgst.c495
-rw-r--r--src/lib/libcrypto/ripemd/rmd_locl.h160
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c78
-rw-r--r--src/lib/libcrypto/ripemd/rmdconst.h399
-rw-r--r--src/lib/libcrypto/rsa/rsa.h413
-rw-r--r--src/lib/libcrypto/rsa/rsa_asn1.c121
-rw-r--r--src/lib/libcrypto/rsa/rsa_chk.c184
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c818
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c165
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c201
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c414
-rw-r--r--src/lib/libcrypto/rsa/rsa_none.c98
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c212
-rw-r--r--src/lib/libcrypto/rsa/rsa_pk1.c224
-rw-r--r--src/lib/libcrypto/rsa/rsa_pss.c261
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c149
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c249
-rw-r--r--src/lib/libcrypto/rsa/rsa_ssl.c154
-rw-r--r--src/lib/libcrypto/rsa/rsa_x931.c177
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl425
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-ia64.pl549
-rw-r--r--src/lib/libcrypto/sha/sha.h128
-rw-r--r--src/lib/libcrypto/sha/sha1_one.c78
-rw-r--r--src/lib/libcrypto/sha/sha1dgst.c81
-rw-r--r--src/lib/libcrypto/sha/sha_locl.h481
-rw-r--r--src/lib/libcrypto/stack/safestack.h1574
-rw-r--r--src/lib/libcrypto/stack/stack.c340
-rw-r--r--src/lib/libcrypto/stack/stack.h108
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.c383
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.h108
-rw-r--r--src/lib/libcrypto/ui/ui.h387
-rw-r--r--src/lib/libcrypto/ui/ui_compat.h83
-rw-r--r--src/lib/libcrypto/ui/ui_err.c115
-rw-r--r--src/lib/libcrypto/ui/ui_lib.c902
-rw-r--r--src/lib/libcrypto/ui/ui_locl.h148
-rw-r--r--src/lib/libcrypto/ui/ui_openssl.c674
-rw-r--r--src/lib/libcrypto/ui/ui_util.c91
-rw-r--r--src/lib/libcrypto/util/mkerr.pl653
-rw-r--r--src/lib/libcrypto/util/mkstack.pl125
-rw-r--r--src/lib/libcrypto/x509/by_dir.c380
-rw-r--r--src/lib/libcrypto/x509/by_file.c300
-rw-r--r--src/lib/libcrypto/x509/x509.h1259
-rw-r--r--src/lib/libcrypto/x509/x509_att.c326
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c440
-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.c160
-rw-r--r--src/lib/libcrypto/x509/x509_ext.c210
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c557
-rw-r--r--src/lib/libcrypto/x509/x509_obj.c226
-rw-r--r--src/lib/libcrypto/x509/x509_r2x.c112
-rw-r--r--src/lib/libcrypto/x509/x509_req.c279
-rw-r--r--src/lib/libcrypto/x509/x509_set.c150
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c287
-rw-r--r--src/lib/libcrypto/x509/x509_txt.c165
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c268
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c1333
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.h422
-rw-r--r--src/lib/libcrypto/x509/x509cset.c170
-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.c120
-rw-r--r--src/lib/libcrypto/x509/x509type.c115
-rw-r--r--src/lib/libcrypto/x509/x_all.c489
-rw-r--r--src/lib/libcrypto/x509v3/ext_dat.h118
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c190
-rw-r--r--src/lib/libcrypto/x509v3/v3_akeya.c72
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c458
-rw-r--r--src/lib/libcrypto/x509v3/v3_bcons.c124
-rw-r--r--src/lib/libcrypto/x509v3/v3_bitst.c147
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c485
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c431
-rw-r--r--src/lib/libcrypto/x509v3/v3_crld.c162
-rw-r--r--src/lib/libcrypto/x509v3/v3_enum.c94
-rw-r--r--src/lib/libcrypto/x509v3/v3_extku.c142
-rw-r--r--src/lib/libcrypto/x509v3/v3_genn.c101
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c116
-rw-r--r--src/lib/libcrypto/x509v3/v3_info.c194
-rw-r--r--src/lib/libcrypto/x509v3/v3_int.c76
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c302
-rw-r--r--src/lib/libcrypto/x509v3/v3_ocsp.c275
-rw-r--r--src/lib/libcrypto/x509v3/v3_pci.c313
-rw-r--r--src/lib/libcrypto/x509v3/v3_pcia.c55
-rw-r--r--src/lib/libcrypto/x509v3/v3_pku.c108
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c233
-rw-r--r--src/lib/libcrypto/x509v3/v3_purp.c647
-rw-r--r--src/lib/libcrypto/x509v3/v3_skey.c144
-rw-r--r--src/lib/libcrypto/x509v3/v3_sxnet.c262
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c535
-rw-r--r--src/lib/libcrypto/x509v3/v3err.c197
-rw-r--r--src/lib/libcrypto/x509v3/x509v3.h687
-rw-r--r--src/lib/libssl/LICENSE127
-rw-r--r--src/lib/libssl/bio_ssl.c598
-rw-r--r--src/lib/libssl/doc/openssl.cnf313
-rw-r--r--src/lib/libssl/doc/openssl.txt1235
-rw-r--r--src/lib/libssl/doc/standards.txt261
-rw-r--r--src/lib/libssl/s23_clnt.c616
-rw-r--r--src/lib/libssl/s23_lib.c236
-rw-r--r--src/lib/libssl/s23_pkt.c117
-rw-r--r--src/lib/libssl/s23_srvr.c600
-rw-r--r--src/lib/libssl/s3_both.c635
-rw-r--r--src/lib/libssl/s3_clnt.c1985
-rw-r--r--src/lib/libssl/s3_lib.c1799
-rw-r--r--src/lib/libssl/s3_pkt.c1310
-rw-r--r--src/lib/libssl/s3_srvr.c2082
-rw-r--r--src/lib/libssl/shlib_version2
-rw-r--r--src/lib/libssl/ssl.h1853
-rw-r--r--src/lib/libssl/ssl2.h268
-rw-r--r--src/lib/libssl/ssl23.h83
-rw-r--r--src/lib/libssl/ssl3.h526
-rw-r--r--src/lib/libssl/ssl_algs.c111
-rw-r--r--src/lib/libssl/ssl_asn1.c398
-rw-r--r--src/lib/libssl/ssl_cert.c898
-rw-r--r--src/lib/libssl/ssl_ciph.c1139
-rw-r--r--src/lib/libssl/ssl_err.c462
-rw-r--r--src/lib/libssl/ssl_err2.c70
-rw-r--r--src/lib/libssl/ssl_lib.c2355
-rw-r--r--src/lib/libssl/ssl_locl.h623
-rw-r--r--src/lib/libssl/ssl_rsa.c817
-rw-r--r--src/lib/libssl/ssl_sess.c755
-rw-r--r--src/lib/libssl/ssl_stat.c502
-rw-r--r--src/lib/libssl/ssl_txt.c186
-rw-r--r--src/lib/libssl/t1_clnt.c97
-rw-r--r--src/lib/libssl/t1_enc.c816
-rw-r--r--src/lib/libssl/t1_lib.c149
-rw-r--r--src/lib/libssl/t1_meth.c96
-rw-r--r--src/lib/libssl/t1_srvr.c98
-rw-r--r--src/lib/libssl/test/CAss.cnf33
-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/P1ss.cnf37
-rw-r--r--src/lib/libssl/test/P2ss.cnf45
-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.cnf36
-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/bctest111
-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/tcrl85
-rw-r--r--src/lib/libssl/test/test.cnf88
-rw-r--r--src/lib/libssl/test/testca51
-rw-r--r--src/lib/libssl/test/testcrl.pem16
-rw-r--r--src/lib/libssl/test/testenc54
-rw-r--r--src/lib/libssl/test/testgen44
-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/testss163
-rw-r--r--src/lib/libssl/test/testssl145
-rw-r--r--src/lib/libssl/test/testsslproxy10
-rw-r--r--src/lib/libssl/test/testx509.pem10
-rw-r--r--src/lib/libssl/test/times113
-rw-r--r--src/lib/libssl/test/tpkcs755
-rw-r--r--src/lib/libssl/test/tpkcs7d48
-rw-r--r--src/lib/libssl/test/treq90
-rw-r--r--src/lib/libssl/test/trsa90
-rw-r--r--src/lib/libssl/test/tsid85
-rw-r--r--src/lib/libssl/test/tx50985
-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.h195
692 files changed, 0 insertions, 180302 deletions
diff --git a/src/lib/libcrypto/aes/README b/src/lib/libcrypto/aes/README
deleted file mode 100644
index 0f9620a80e..0000000000
--- a/src/lib/libcrypto/aes/README
+++ /dev/null
@@ -1,3 +0,0 @@
1This is an OpenSSL-compatible version of AES (also called Rijndael).
2aes_core.c is basically the same as rijndael-alg-fst.c but with an
3API that looks like the rest of the OpenSSL symmetric cipher suite.
diff --git a/src/lib/libcrypto/aes/aes.h b/src/lib/libcrypto/aes/aes.h
deleted file mode 100644
index 8a3ea0b883..0000000000
--- a/src/lib/libcrypto/aes/aes.h
+++ /dev/null
@@ -1,127 +0,0 @@
1/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef HEADER_AES_H
53#define HEADER_AES_H
54
55#include <openssl/e_os2.h>
56
57#ifdef OPENSSL_NO_AES
58#error AES is disabled.
59#endif
60
61#define AES_ENCRYPT 1
62#define AES_DECRYPT 0
63
64/* Because array size can't be a const in C, the following two are macros.
65 Both sizes are in bytes. */
66#define AES_MAXNR 14
67#define AES_BLOCK_SIZE 16
68
69#if defined(OPENSSL_FIPS)
70#define FIPS_AES_SIZE_T int
71#endif
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77/* This should be a hidden type, but EVP requires that the size be known */
78struct aes_key_st {
79 unsigned long rd_key[4 *(AES_MAXNR + 1)];
80 int rounds;
81};
82typedef struct aes_key_st AES_KEY;
83
84const char *AES_options(void);
85
86int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
87 AES_KEY *key);
88int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
89 AES_KEY *key);
90
91void AES_encrypt(const unsigned char *in, unsigned char *out,
92 const AES_KEY *key);
93void AES_decrypt(const unsigned char *in, unsigned char *out,
94 const AES_KEY *key);
95
96void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
97 const AES_KEY *key, const int enc);
98void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
99 const unsigned long length, const AES_KEY *key,
100 unsigned char *ivec, const int enc);
101void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
102 const unsigned long length, const AES_KEY *key,
103 unsigned char *ivec, int *num, const int enc);
104void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
105 const unsigned long length, const AES_KEY *key,
106 unsigned char *ivec, int *num, const int enc);
107void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
108 const unsigned long length, const AES_KEY *key,
109 unsigned char *ivec, int *num, const int enc);
110void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
111 const int nbits,const AES_KEY *key,
112 unsigned char *ivec,const int enc);
113void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
114 const unsigned long length, const AES_KEY *key,
115 unsigned char *ivec, int *num);
116void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
117 const unsigned long length, const AES_KEY *key,
118 unsigned char ivec[AES_BLOCK_SIZE],
119 unsigned char ecount_buf[AES_BLOCK_SIZE],
120 unsigned int *num);
121
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif /* !HEADER_AES_H */
diff --git a/src/lib/libcrypto/aes/aes_cbc.c b/src/lib/libcrypto/aes/aes_cbc.c
deleted file mode 100644
index 373864cd4b..0000000000
--- a/src/lib/libcrypto/aes/aes_cbc.c
+++ /dev/null
@@ -1,133 +0,0 @@
1/* crypto/aes/aes_cbc.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef AES_DEBUG
53# ifndef NDEBUG
54# define NDEBUG
55# endif
56#endif
57#include <assert.h>
58
59#include <openssl/aes.h>
60#include "aes_locl.h"
61
62#if !defined(OPENSSL_FIPS_AES_ASM)
63void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
64 const unsigned long length, const AES_KEY *key,
65 unsigned char *ivec, const int enc) {
66
67 unsigned long n;
68 unsigned long len = length;
69 unsigned char tmp[AES_BLOCK_SIZE];
70 const unsigned char *iv = ivec;
71
72 assert(in && out && key && ivec);
73 assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
74
75 if (AES_ENCRYPT == enc) {
76 while (len >= AES_BLOCK_SIZE) {
77 for(n=0; n < AES_BLOCK_SIZE; ++n)
78 out[n] = in[n] ^ iv[n];
79 AES_encrypt(out, out, key);
80 iv = out;
81 len -= AES_BLOCK_SIZE;
82 in += AES_BLOCK_SIZE;
83 out += AES_BLOCK_SIZE;
84 }
85 if (len) {
86 for(n=0; n < len; ++n)
87 out[n] = in[n] ^ iv[n];
88 for(n=len; n < AES_BLOCK_SIZE; ++n)
89 out[n] = iv[n];
90 AES_encrypt(out, out, key);
91 iv = out;
92 }
93 memcpy(ivec,iv,AES_BLOCK_SIZE);
94 } else if (in != out) {
95 while (len >= AES_BLOCK_SIZE) {
96 AES_decrypt(in, out, key);
97 for(n=0; n < AES_BLOCK_SIZE; ++n)
98 out[n] ^= iv[n];
99 iv = in;
100 len -= AES_BLOCK_SIZE;
101 in += AES_BLOCK_SIZE;
102 out += AES_BLOCK_SIZE;
103 }
104 if (len) {
105 AES_decrypt(in,tmp,key);
106 for(n=0; n < len; ++n)
107 out[n] = tmp[n] ^ iv[n];
108 iv = in;
109 }
110 memcpy(ivec,iv,AES_BLOCK_SIZE);
111 } else {
112 while (len >= AES_BLOCK_SIZE) {
113 memcpy(tmp, in, AES_BLOCK_SIZE);
114 AES_decrypt(in, out, key);
115 for(n=0; n < AES_BLOCK_SIZE; ++n)
116 out[n] ^= ivec[n];
117 memcpy(ivec, tmp, AES_BLOCK_SIZE);
118 len -= AES_BLOCK_SIZE;
119 in += AES_BLOCK_SIZE;
120 out += AES_BLOCK_SIZE;
121 }
122 if (len) {
123 memcpy(tmp, in, AES_BLOCK_SIZE);
124 AES_decrypt(tmp, out, key);
125 for(n=0; n < len; ++n)
126 out[n] ^= ivec[n];
127 for(n=len; n < AES_BLOCK_SIZE; ++n)
128 out[n] = tmp[n];
129 memcpy(ivec, tmp, AES_BLOCK_SIZE);
130 }
131 }
132}
133#endif
diff --git a/src/lib/libcrypto/aes/aes_cfb.c b/src/lib/libcrypto/aes/aes_cfb.c
deleted file mode 100644
index 49f0411010..0000000000
--- a/src/lib/libcrypto/aes/aes_cfb.c
+++ /dev/null
@@ -1,225 +0,0 @@
1/* crypto/aes/aes_cfb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
52 * All rights reserved.
53 *
54 * This package is an SSL implementation written
55 * by Eric Young (eay@cryptsoft.com).
56 * The implementation was written so as to conform with Netscapes SSL.
57 *
58 * This library is free for commercial and non-commercial use as long as
59 * the following conditions are aheared to. The following conditions
60 * apply to all code found in this distribution, be it the RC4, RSA,
61 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
62 * included with this distribution is covered by the same copyright terms
63 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
64 *
65 * Copyright remains Eric Young's, and as such any Copyright notices in
66 * the code are not to be removed.
67 * If this package is used in a product, Eric Young should be given attribution
68 * as the author of the parts of the library used.
69 * This can be in the form of a textual message at program startup or
70 * in documentation (online or textual) provided with the package.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * "This product includes cryptographic software written by
83 * Eric Young (eay@cryptsoft.com)"
84 * The word 'cryptographic' can be left out if the rouines from the library
85 * being used are not cryptographic related :-).
86 * 4. If you include any Windows specific code (or a derivative thereof) from
87 * the apps directory (application code) you must include an acknowledgement:
88 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
89 *
90 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 *
102 * The licence and distribution terms for any publically available version or
103 * derivative of this code cannot be changed. i.e. this code cannot simply be
104 * copied and put under another distribution licence
105 * [including the GNU Public Licence.]
106 */
107
108#ifndef AES_DEBUG
109# ifndef NDEBUG
110# define NDEBUG
111# endif
112#endif
113#include <assert.h>
114
115#include <openssl/aes.h>
116#include "aes_locl.h"
117#include "e_os.h"
118
119/* The input and output encrypted as though 128bit cfb mode is being
120 * used. The extra state information to record how much of the
121 * 128bit block we have used is contained in *num;
122 */
123
124void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
125 const unsigned long length, const AES_KEY *key,
126 unsigned char *ivec, int *num, const int enc) {
127
128 unsigned int n;
129 unsigned long l = length;
130 unsigned char c;
131
132 assert(in && out && key && ivec && num);
133
134 n = *num;
135
136 if (enc) {
137 while (l--) {
138 if (n == 0) {
139 AES_encrypt(ivec, ivec, key);
140 }
141 ivec[n] = *(out++) = *(in++) ^ ivec[n];
142 n = (n+1) % AES_BLOCK_SIZE;
143 }
144 } else {
145 while (l--) {
146 if (n == 0) {
147 AES_encrypt(ivec, ivec, key);
148 }
149 c = *(in);
150 *(out++) = *(in++) ^ ivec[n];
151 ivec[n] = c;
152 n = (n+1) % AES_BLOCK_SIZE;
153 }
154 }
155
156 *num=n;
157}
158
159/* This expects a single block of size nbits for both in and out. Note that
160 it corrupts any extra bits in the last byte of out */
161void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out,
162 const int nbits,const AES_KEY *key,
163 unsigned char *ivec,const int enc)
164 {
165 int n,rem,num;
166 unsigned char ovec[AES_BLOCK_SIZE*2];
167
168 if (nbits<=0 || nbits>128) return;
169
170 /* fill in the first half of the new IV with the current IV */
171 memcpy(ovec,ivec,AES_BLOCK_SIZE);
172 /* construct the new IV */
173 AES_encrypt(ivec,ivec,key);
174 num = (nbits+7)/8;
175 if (enc) /* encrypt the input */
176 for(n=0 ; n < num ; ++n)
177 out[n] = (ovec[AES_BLOCK_SIZE+n] = in[n] ^ ivec[n]);
178 else /* decrypt the input */
179 for(n=0 ; n < num ; ++n)
180 out[n] = (ovec[AES_BLOCK_SIZE+n] = in[n]) ^ ivec[n];
181 /* shift ovec left... */
182 rem = nbits%8;
183 num = nbits/8;
184 if(rem==0)
185 memcpy(ivec,ovec+num,AES_BLOCK_SIZE);
186 else
187 for(n=0 ; n < AES_BLOCK_SIZE ; ++n)
188 ivec[n] = ovec[n+num]<<rem | ovec[n+num+1]>>(8-rem);
189
190 /* it is not necessary to cleanse ovec, since the IV is not secret */
191 }
192
193/* N.B. This expects the input to be packed, MS bit first */
194void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
195 const unsigned long length, const AES_KEY *key,
196 unsigned char *ivec, int *num, const int enc)
197 {
198 unsigned int n;
199 unsigned char c[1],d[1];
200
201 assert(in && out && key && ivec && num);
202 assert(*num == 0);
203
204 memset(out,0,(length+7)/8);
205 for(n=0 ; n < length ; ++n)
206 {
207 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
208 AES_cfbr_encrypt_block(c,d,1,key,ivec,enc);
209 out[n/8]=(out[n/8]&~(1 << (7-n%8)))|((d[0]&0x80) >> (n%8));
210 }
211 }
212
213void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
214 const unsigned long length, const AES_KEY *key,
215 unsigned char *ivec, int *num, const int enc)
216 {
217 unsigned int n;
218
219 assert(in && out && key && ivec && num);
220 assert(*num == 0);
221
222 for(n=0 ; n < length ; ++n)
223 AES_cfbr_encrypt_block(&in[n],&out[n],8,key,ivec,enc);
224 }
225
diff --git a/src/lib/libcrypto/aes/aes_core.c b/src/lib/libcrypto/aes/aes_core.c
deleted file mode 100644
index ed566a8123..0000000000
--- a/src/lib/libcrypto/aes/aes_core.c
+++ /dev/null
@@ -1,1261 +0,0 @@
1/* crypto/aes/aes_core.c -*- mode:C; c-file-style: "eay" -*- */
2/**
3 * rijndael-alg-fst.c
4 *
5 * @version 3.0 (December 2000)
6 *
7 * Optimised ANSI C code for the Rijndael cipher (now AES)
8 *
9 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
10 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
11 * @author Paulo Barreto <paulo.barreto@terra.com.br>
12 *
13 * This code is hereby placed in the public domain.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* Note: rewritten a little bit to provide error control and an OpenSSL-
29 compatible API */
30
31#ifndef AES_DEBUG
32# ifndef NDEBUG
33# define NDEBUG
34# endif
35#endif
36#include <assert.h>
37
38#include <stdlib.h>
39#include <openssl/aes.h>
40#include <openssl/fips.h>
41#include "aes_locl.h"
42
43#ifndef OPENSSL_FIPS
44
45/*
46Te0[x] = S [x].[02, 01, 01, 03];
47Te1[x] = S [x].[03, 02, 01, 01];
48Te2[x] = S [x].[01, 03, 02, 01];
49Te3[x] = S [x].[01, 01, 03, 02];
50Te4[x] = S [x].[01, 01, 01, 01];
51
52Td0[x] = Si[x].[0e, 09, 0d, 0b];
53Td1[x] = Si[x].[0b, 0e, 09, 0d];
54Td2[x] = Si[x].[0d, 0b, 0e, 09];
55Td3[x] = Si[x].[09, 0d, 0b, 0e];
56Td4[x] = Si[x].[01, 01, 01, 01];
57*/
58
59static const u32 Te0[256] = {
60 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
61 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
62 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
63 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
64 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
65 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
66 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
67 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
68 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
69 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
70 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
71 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
72 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
73 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
74 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
75 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
76 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
77 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
78 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
79 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
80 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
81 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
82 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
83 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
84 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
85 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
86 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
87 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
88 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
89 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
90 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
91 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
92 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
93 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
94 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
95 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
96 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
97 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
98 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
99 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
100 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
101 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
102 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
103 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
104 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
105 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
106 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
107 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
108 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
109 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
110 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
111 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
112 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
113 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
114 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
115 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
116 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
117 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
118 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
119 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
120 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
121 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
122 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
123 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
124};
125static const u32 Te1[256] = {
126 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
127 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
128 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
129 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
130 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
131 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
132 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
133 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
134 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
135 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
136 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
137 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
138 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
139 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
140 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
141 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
142 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
143 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
144 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
145 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
146 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
147 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
148 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
149 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
150 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
151 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
152 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
153 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
154 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
155 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
156 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
157 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
158 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
159 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
160 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
161 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
162 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
163 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
164 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
165 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
166 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
167 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
168 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
169 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
170 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
171 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
172 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
173 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
174 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
175 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
176 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
177 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
178 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
179 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
180 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
181 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
182 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
183 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
184 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
185 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
186 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
187 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
188 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
189 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
190};
191static const u32 Te2[256] = {
192 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
193 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
194 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
195 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
196 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
197 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
198 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
199 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
200 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
201 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
202 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
203 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
204 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
205 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
206 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
207 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
208 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
209 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
210 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
211 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
212 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
213 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
214 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
215 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
216 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
217 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
218 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
219 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
220 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
221 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
222 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
223 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
224 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
225 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
226 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
227 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
228 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
229 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
230 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
231 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
232 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
233 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
234 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
235 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
236 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
237 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
238 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
239 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
240 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
241 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
242 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
243 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
244 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
245 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
246 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
247 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
248 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
249 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
250 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
251 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
252 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
253 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
254 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
255 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
256};
257static const u32 Te3[256] = {
258
259 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
260 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
261 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
262 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
263 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
264 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
265 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
266 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
267 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
268 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
269 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
270 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
271 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
272 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
273 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
274 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
275 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
276 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
277 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
278 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
279 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
280 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
281 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
282 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
283 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
284 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
285 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
286 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
287 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
288 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
289 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
290 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
291 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
292 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
293 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
294 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
295 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
296 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
297 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
298 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
299 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
300 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
301 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
302 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
303 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
304 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
305 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
306 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
307 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
308 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
309 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
310 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
311 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
312 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
313 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
314 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
315 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
316 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
317 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
318 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
319 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
320 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
321 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
322 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
323};
324static const u32 Te4[256] = {
325 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
326 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
327 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
328 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
329 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
330 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
331 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
332 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
333 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
334 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
335 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
336 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
337 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
338 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
339 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
340 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
341 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
342 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
343 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
344 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
345 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
346 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
347 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
348 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
349 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
350 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
351 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
352 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
353 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
354 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
355 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
356 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
357 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
358 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
359 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
360 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
361 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
362 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
363 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
364 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
365 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
366 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
367 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
368 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
369 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
370 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
371 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
372 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
373 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
374 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
375 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
376 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
377 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
378 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
379 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
380 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
381 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
382 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
383 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
384 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
385 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
386 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
387 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
388 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
389};
390static const u32 Td0[256] = {
391 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
392 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
393 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
394 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
395 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
396 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
397 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
398 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
399 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
400 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
401 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
402 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
403 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
404 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
405 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
406 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
407 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
408 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
409 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
410 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
411 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
412 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
413 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
414 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
415 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
416 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
417 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
418 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
419 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
420 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
421 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
422 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
423 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
424 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
425 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
426 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
427 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
428 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
429 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
430 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
431 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
432 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
433 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
434 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
435 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
436 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
437 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
438 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
439 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
440 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
441 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
442 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
443 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
444 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
445 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
446 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
447 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
448 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
449 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
450 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
451 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
452 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
453 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
454 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
455};
456static const u32 Td1[256] = {
457 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
458 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
459 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
460 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
461 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
462 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
463 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
464 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
465 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
466 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
467 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
468 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
469 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
470 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
471 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
472 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
473 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
474 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
475 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
476 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
477 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
478 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
479 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
480 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
481 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
482 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
483 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
484 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
485 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
486 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
487 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
488 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
489 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
490 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
491 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
492 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
493 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
494 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
495 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
496 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
497 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
498 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
499 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
500 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
501 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
502 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
503 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
504 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
505 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
506 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
507 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
508 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
509 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
510 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
511 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
512 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
513 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
514 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
515 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
516 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
517 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
518 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
519 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
520 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
521};
522static const u32 Td2[256] = {
523 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
524 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
525 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
526 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
527 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
528 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
529 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
530 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
531 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
532 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
533 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
534 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
535 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
536 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
537 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
538 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
539 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
540 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
541 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
542 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
543
544 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
545 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
546 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
547 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
548 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
549 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
550 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
551 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
552 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
553 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
554 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
555 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
556 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
557 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
558 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
559 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
560 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
561 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
562 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
563 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
564 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
565 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
566 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
567 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
568 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
569 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
570 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
571 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
572 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
573 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
574 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
575 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
576 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
577 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
578 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
579 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
580 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
581 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
582 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
583 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
584 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
585 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
586 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
587 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
588};
589static const u32 Td3[256] = {
590 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
591 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
592 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
593 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
594 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
595 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
596 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
597 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
598 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
599 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
600 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
601 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
602 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
603 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
604 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
605 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
606 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
607 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
608 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
609 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
610 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
611 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
612 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
613 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
614 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
615 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
616 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
617 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
618 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
619 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
620 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
621 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
622 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
623 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
624 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
625 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
626 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
627 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
628 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
629 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
630 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
631 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
632 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
633 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
634 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
635 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
636 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
637 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
638 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
639 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
640 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
641 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
642 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
643 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
644 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
645 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
646 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
647 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
648 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
649 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
650 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
651 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
652 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
653 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
654};
655static const u32 Td4[256] = {
656 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
657 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
658 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
659 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
660 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
661 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
662 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
663 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
664 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
665 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
666 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
667 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
668 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
669 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
670 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
671 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
672 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
673 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
674 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
675 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
676 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
677 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
678 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
679 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
680 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
681 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
682 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
683 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
684 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
685 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
686 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
687 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
688 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
689 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
690 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
691 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
692 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
693 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
694 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
695 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
696 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
697 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
698 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
699 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
700 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
701 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
702 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
703 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
704 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
705 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
706 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
707 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
708 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
709 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
710 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
711 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
712 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
713 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
714 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
715 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
716 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
717 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
718 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
719 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
720};
721static const u32 rcon[] = {
722 0x01000000, 0x02000000, 0x04000000, 0x08000000,
723 0x10000000, 0x20000000, 0x40000000, 0x80000000,
724 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
725};
726
727/**
728 * Expand the cipher key into the encryption key schedule.
729 */
730int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
731 AES_KEY *key) {
732
733 u32 *rk;
734 int i = 0;
735 u32 temp;
736
737 if (!userKey || !key)
738 return -1;
739 if (bits != 128 && bits != 192 && bits != 256)
740 return -2;
741
742 rk = key->rd_key;
743
744 if (bits==128)
745 key->rounds = 10;
746 else if (bits==192)
747 key->rounds = 12;
748 else
749 key->rounds = 14;
750
751 rk[0] = GETU32(userKey );
752 rk[1] = GETU32(userKey + 4);
753 rk[2] = GETU32(userKey + 8);
754 rk[3] = GETU32(userKey + 12);
755 if (bits == 128) {
756 while (1) {
757 temp = rk[3];
758 rk[4] = rk[0] ^
759 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
760 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
761 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
762 (Te4[(temp >> 24) ] & 0x000000ff) ^
763 rcon[i];
764 rk[5] = rk[1] ^ rk[4];
765 rk[6] = rk[2] ^ rk[5];
766 rk[7] = rk[3] ^ rk[6];
767 if (++i == 10) {
768 return 0;
769 }
770 rk += 4;
771 }
772 }
773 rk[4] = GETU32(userKey + 16);
774 rk[5] = GETU32(userKey + 20);
775 if (bits == 192) {
776 while (1) {
777 temp = rk[ 5];
778 rk[ 6] = rk[ 0] ^
779 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
780 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
781 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
782 (Te4[(temp >> 24) ] & 0x000000ff) ^
783 rcon[i];
784 rk[ 7] = rk[ 1] ^ rk[ 6];
785 rk[ 8] = rk[ 2] ^ rk[ 7];
786 rk[ 9] = rk[ 3] ^ rk[ 8];
787 if (++i == 8) {
788 return 0;
789 }
790 rk[10] = rk[ 4] ^ rk[ 9];
791 rk[11] = rk[ 5] ^ rk[10];
792 rk += 6;
793 }
794 }
795 rk[6] = GETU32(userKey + 24);
796 rk[7] = GETU32(userKey + 28);
797 if (bits == 256) {
798 while (1) {
799 temp = rk[ 7];
800 rk[ 8] = rk[ 0] ^
801 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
802 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
803 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
804 (Te4[(temp >> 24) ] & 0x000000ff) ^
805 rcon[i];
806 rk[ 9] = rk[ 1] ^ rk[ 8];
807 rk[10] = rk[ 2] ^ rk[ 9];
808 rk[11] = rk[ 3] ^ rk[10];
809 if (++i == 7) {
810 return 0;
811 }
812 temp = rk[11];
813 rk[12] = rk[ 4] ^
814 (Te4[(temp >> 24) ] & 0xff000000) ^
815 (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
816 (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
817 (Te4[(temp ) & 0xff] & 0x000000ff);
818 rk[13] = rk[ 5] ^ rk[12];
819 rk[14] = rk[ 6] ^ rk[13];
820 rk[15] = rk[ 7] ^ rk[14];
821
822 rk += 8;
823 }
824 }
825 return 0;
826}
827
828/**
829 * Expand the cipher key into the decryption key schedule.
830 */
831int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
832 AES_KEY *key) {
833
834 u32 *rk;
835 int i, j, status;
836 u32 temp;
837
838 /* first, start with an encryption schedule */
839 status = AES_set_encrypt_key(userKey, bits, key);
840 if (status < 0)
841 return status;
842
843 rk = key->rd_key;
844
845 /* invert the order of the round keys: */
846 for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) {
847 temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp;
848 temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
849 temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
850 temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
851 }
852 /* apply the inverse MixColumn transform to all round keys but the first and the last: */
853 for (i = 1; i < (key->rounds); i++) {
854 rk += 4;
855 rk[0] =
856 Td0[Te4[(rk[0] >> 24) ] & 0xff] ^
857 Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
858 Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
859 Td3[Te4[(rk[0] ) & 0xff] & 0xff];
860 rk[1] =
861 Td0[Te4[(rk[1] >> 24) ] & 0xff] ^
862 Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
863 Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
864 Td3[Te4[(rk[1] ) & 0xff] & 0xff];
865 rk[2] =
866 Td0[Te4[(rk[2] >> 24) ] & 0xff] ^
867 Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
868 Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
869 Td3[Te4[(rk[2] ) & 0xff] & 0xff];
870 rk[3] =
871 Td0[Te4[(rk[3] >> 24) ] & 0xff] ^
872 Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
873 Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
874 Td3[Te4[(rk[3] ) & 0xff] & 0xff];
875 }
876 return 0;
877}
878
879/*
880 * Encrypt a single block
881 * in and out can overlap
882 */
883void AES_encrypt(const unsigned char *in, unsigned char *out,
884 const AES_KEY *key) {
885
886 const u32 *rk;
887 u32 s0, s1, s2, s3, t0, t1, t2, t3;
888#ifndef FULL_UNROLL
889 int r;
890#endif /* ?FULL_UNROLL */
891
892 assert(in && out && key);
893 rk = key->rd_key;
894
895 /*
896 * map byte array block to cipher state
897 * and add initial round key:
898 */
899 s0 = GETU32(in ) ^ rk[0];
900 s1 = GETU32(in + 4) ^ rk[1];
901 s2 = GETU32(in + 8) ^ rk[2];
902 s3 = GETU32(in + 12) ^ rk[3];
903#ifdef FULL_UNROLL
904 /* round 1: */
905 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4];
906 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5];
907 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6];
908 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7];
909 /* round 2: */
910 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8];
911 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9];
912 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10];
913 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11];
914 /* round 3: */
915 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12];
916 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13];
917 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14];
918 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15];
919 /* round 4: */
920 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16];
921 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17];
922 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18];
923 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19];
924 /* round 5: */
925 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20];
926 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21];
927 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22];
928 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23];
929 /* round 6: */
930 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24];
931 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25];
932 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26];
933 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27];
934 /* round 7: */
935 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28];
936 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29];
937 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30];
938 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31];
939 /* round 8: */
940 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32];
941 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33];
942 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34];
943 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35];
944 /* round 9: */
945 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36];
946 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37];
947 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38];
948 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39];
949 if (key->rounds > 10) {
950 /* round 10: */
951 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40];
952 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41];
953 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42];
954 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43];
955 /* round 11: */
956 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44];
957 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45];
958 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46];
959 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47];
960 if (key->rounds > 12) {
961 /* round 12: */
962 s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48];
963 s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49];
964 s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50];
965 s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51];
966 /* round 13: */
967 t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52];
968 t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53];
969 t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54];
970 t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55];
971 }
972 }
973 rk += key->rounds << 2;
974#else /* !FULL_UNROLL */
975 /*
976 * Nr - 1 full rounds:
977 */
978 r = key->rounds >> 1;
979 for (;;) {
980 t0 =
981 Te0[(s0 >> 24) ] ^
982 Te1[(s1 >> 16) & 0xff] ^
983 Te2[(s2 >> 8) & 0xff] ^
984 Te3[(s3 ) & 0xff] ^
985 rk[4];
986 t1 =
987 Te0[(s1 >> 24) ] ^
988 Te1[(s2 >> 16) & 0xff] ^
989 Te2[(s3 >> 8) & 0xff] ^
990 Te3[(s0 ) & 0xff] ^
991 rk[5];
992 t2 =
993 Te0[(s2 >> 24) ] ^
994 Te1[(s3 >> 16) & 0xff] ^
995 Te2[(s0 >> 8) & 0xff] ^
996 Te3[(s1 ) & 0xff] ^
997 rk[6];
998 t3 =
999 Te0[(s3 >> 24) ] ^
1000 Te1[(s0 >> 16) & 0xff] ^
1001 Te2[(s1 >> 8) & 0xff] ^
1002 Te3[(s2 ) & 0xff] ^
1003 rk[7];
1004
1005 rk += 8;
1006 if (--r == 0) {
1007 break;
1008 }
1009
1010 s0 =
1011 Te0[(t0 >> 24) ] ^
1012 Te1[(t1 >> 16) & 0xff] ^
1013 Te2[(t2 >> 8) & 0xff] ^
1014 Te3[(t3 ) & 0xff] ^
1015 rk[0];
1016 s1 =
1017 Te0[(t1 >> 24) ] ^
1018 Te1[(t2 >> 16) & 0xff] ^
1019 Te2[(t3 >> 8) & 0xff] ^
1020 Te3[(t0 ) & 0xff] ^
1021 rk[1];
1022 s2 =
1023 Te0[(t2 >> 24) ] ^
1024 Te1[(t3 >> 16) & 0xff] ^
1025 Te2[(t0 >> 8) & 0xff] ^
1026 Te3[(t1 ) & 0xff] ^
1027 rk[2];
1028 s3 =
1029 Te0[(t3 >> 24) ] ^
1030 Te1[(t0 >> 16) & 0xff] ^
1031 Te2[(t1 >> 8) & 0xff] ^
1032 Te3[(t2 ) & 0xff] ^
1033 rk[3];
1034 }
1035#endif /* ?FULL_UNROLL */
1036 /*
1037 * apply last round and
1038 * map cipher state to byte array block:
1039 */
1040 s0 =
1041 (Te4[(t0 >> 24) ] & 0xff000000) ^
1042 (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
1043 (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
1044 (Te4[(t3 ) & 0xff] & 0x000000ff) ^
1045 rk[0];
1046 PUTU32(out , s0);
1047 s1 =
1048 (Te4[(t1 >> 24) ] & 0xff000000) ^
1049 (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
1050 (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
1051 (Te4[(t0 ) & 0xff] & 0x000000ff) ^
1052 rk[1];
1053 PUTU32(out + 4, s1);
1054 s2 =
1055 (Te4[(t2 >> 24) ] & 0xff000000) ^
1056 (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
1057 (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
1058 (Te4[(t1 ) & 0xff] & 0x000000ff) ^
1059 rk[2];
1060 PUTU32(out + 8, s2);
1061 s3 =
1062 (Te4[(t3 >> 24) ] & 0xff000000) ^
1063 (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
1064 (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
1065 (Te4[(t2 ) & 0xff] & 0x000000ff) ^
1066 rk[3];
1067 PUTU32(out + 12, s3);
1068}
1069
1070/*
1071 * Decrypt a single block
1072 * in and out can overlap
1073 */
1074void AES_decrypt(const unsigned char *in, unsigned char *out,
1075 const AES_KEY *key) {
1076
1077 const u32 *rk;
1078 u32 s0, s1, s2, s3, t0, t1, t2, t3;
1079#ifndef FULL_UNROLL
1080 int r;
1081#endif /* ?FULL_UNROLL */
1082
1083 assert(in && out && key);
1084 rk = key->rd_key;
1085
1086 /*
1087 * map byte array block to cipher state
1088 * and add initial round key:
1089 */
1090 s0 = GETU32(in ) ^ rk[0];
1091 s1 = GETU32(in + 4) ^ rk[1];
1092 s2 = GETU32(in + 8) ^ rk[2];
1093 s3 = GETU32(in + 12) ^ rk[3];
1094#ifdef FULL_UNROLL
1095 /* round 1: */
1096 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4];
1097 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5];
1098 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6];
1099 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7];
1100 /* round 2: */
1101 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8];
1102 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9];
1103 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10];
1104 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11];
1105 /* round 3: */
1106 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12];
1107 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13];
1108 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14];
1109 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15];
1110 /* round 4: */
1111 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16];
1112 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17];
1113 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18];
1114 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19];
1115 /* round 5: */
1116 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20];
1117 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21];
1118 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22];
1119 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23];
1120 /* round 6: */
1121 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24];
1122 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25];
1123 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26];
1124 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27];
1125 /* round 7: */
1126 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28];
1127 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29];
1128 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30];
1129 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31];
1130 /* round 8: */
1131 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32];
1132 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33];
1133 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34];
1134 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35];
1135 /* round 9: */
1136 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36];
1137 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37];
1138 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38];
1139 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39];
1140 if (key->rounds > 10) {
1141 /* round 10: */
1142 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40];
1143 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41];
1144 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42];
1145 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43];
1146 /* round 11: */
1147 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44];
1148 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45];
1149 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46];
1150 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47];
1151 if (key->rounds > 12) {
1152 /* round 12: */
1153 s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48];
1154 s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49];
1155 s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50];
1156 s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51];
1157 /* round 13: */
1158 t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52];
1159 t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53];
1160 t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54];
1161 t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55];
1162 }
1163 }
1164 rk += key->rounds << 2;
1165#else /* !FULL_UNROLL */
1166 /*
1167 * Nr - 1 full rounds:
1168 */
1169 r = key->rounds >> 1;
1170 for (;;) {
1171 t0 =
1172 Td0[(s0 >> 24) ] ^
1173 Td1[(s3 >> 16) & 0xff] ^
1174 Td2[(s2 >> 8) & 0xff] ^
1175 Td3[(s1 ) & 0xff] ^
1176 rk[4];
1177 t1 =
1178 Td0[(s1 >> 24) ] ^
1179 Td1[(s0 >> 16) & 0xff] ^
1180 Td2[(s3 >> 8) & 0xff] ^
1181 Td3[(s2 ) & 0xff] ^
1182 rk[5];
1183 t2 =
1184 Td0[(s2 >> 24) ] ^
1185 Td1[(s1 >> 16) & 0xff] ^
1186 Td2[(s0 >> 8) & 0xff] ^
1187 Td3[(s3 ) & 0xff] ^
1188 rk[6];
1189 t3 =
1190 Td0[(s3 >> 24) ] ^
1191 Td1[(s2 >> 16) & 0xff] ^
1192 Td2[(s1 >> 8) & 0xff] ^
1193 Td3[(s0 ) & 0xff] ^
1194 rk[7];
1195
1196 rk += 8;
1197 if (--r == 0) {
1198 break;
1199 }
1200
1201 s0 =
1202 Td0[(t0 >> 24) ] ^
1203 Td1[(t3 >> 16) & 0xff] ^
1204 Td2[(t2 >> 8) & 0xff] ^
1205 Td3[(t1 ) & 0xff] ^
1206 rk[0];
1207 s1 =
1208 Td0[(t1 >> 24) ] ^
1209 Td1[(t0 >> 16) & 0xff] ^
1210 Td2[(t3 >> 8) & 0xff] ^
1211 Td3[(t2 ) & 0xff] ^
1212 rk[1];
1213 s2 =
1214 Td0[(t2 >> 24) ] ^
1215 Td1[(t1 >> 16) & 0xff] ^
1216 Td2[(t0 >> 8) & 0xff] ^
1217 Td3[(t3 ) & 0xff] ^
1218 rk[2];
1219 s3 =
1220 Td0[(t3 >> 24) ] ^
1221 Td1[(t2 >> 16) & 0xff] ^
1222 Td2[(t1 >> 8) & 0xff] ^
1223 Td3[(t0 ) & 0xff] ^
1224 rk[3];
1225 }
1226#endif /* ?FULL_UNROLL */
1227 /*
1228 * apply last round and
1229 * map cipher state to byte array block:
1230 */
1231 s0 =
1232 (Td4[(t0 >> 24) ] & 0xff000000) ^
1233 (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
1234 (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
1235 (Td4[(t1 ) & 0xff] & 0x000000ff) ^
1236 rk[0];
1237 PUTU32(out , s0);
1238 s1 =
1239 (Td4[(t1 >> 24) ] & 0xff000000) ^
1240 (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
1241 (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
1242 (Td4[(t2 ) & 0xff] & 0x000000ff) ^
1243 rk[1];
1244 PUTU32(out + 4, s1);
1245 s2 =
1246 (Td4[(t2 >> 24) ] & 0xff000000) ^
1247 (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
1248 (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
1249 (Td4[(t3 ) & 0xff] & 0x000000ff) ^
1250 rk[2];
1251 PUTU32(out + 8, s2);
1252 s3 =
1253 (Td4[(t3 >> 24) ] & 0xff000000) ^
1254 (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
1255 (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
1256 (Td4[(t0 ) & 0xff] & 0x000000ff) ^
1257 rk[3];
1258 PUTU32(out + 12, s3);
1259}
1260
1261#endif /* ndef OPENSSL_FIPS */
diff --git a/src/lib/libcrypto/aes/aes_ctr.c b/src/lib/libcrypto/aes/aes_ctr.c
deleted file mode 100644
index f36982be1e..0000000000
--- a/src/lib/libcrypto/aes/aes_ctr.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/* crypto/aes/aes_ctr.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef AES_DEBUG
53# ifndef NDEBUG
54# define NDEBUG
55# endif
56#endif
57#include <assert.h>
58
59#include <openssl/aes.h>
60#include "aes_locl.h"
61
62/* NOTE: the IV/counter CTR mode is big-endian. The rest of the AES code
63 * is endian-neutral. */
64
65/* increment counter (128-bit int) by 1 */
66static void AES_ctr128_inc(unsigned char *counter) {
67 unsigned long c;
68
69 /* Grab bottom dword of counter and increment */
70 c = GETU32(counter + 12);
71 c++; c &= 0xFFFFFFFF;
72 PUTU32(counter + 12, c);
73
74 /* if no overflow, we're done */
75 if (c)
76 return;
77
78 /* Grab 1st dword of counter and increment */
79 c = GETU32(counter + 8);
80 c++; c &= 0xFFFFFFFF;
81 PUTU32(counter + 8, c);
82
83 /* if no overflow, we're done */
84 if (c)
85 return;
86
87 /* Grab 2nd dword of counter and increment */
88 c = GETU32(counter + 4);
89 c++; c &= 0xFFFFFFFF;
90 PUTU32(counter + 4, c);
91
92 /* if no overflow, we're done */
93 if (c)
94 return;
95
96 /* Grab top dword of counter and increment */
97 c = GETU32(counter + 0);
98 c++; c &= 0xFFFFFFFF;
99 PUTU32(counter + 0, c);
100}
101
102/* The input encrypted as though 128bit counter mode is being
103 * used. The extra state information to record how much of the
104 * 128bit block we have used is contained in *num, and the
105 * encrypted counter is kept in ecount_buf. Both *num and
106 * ecount_buf must be initialised with zeros before the first
107 * call to AES_ctr128_encrypt().
108 *
109 * This algorithm assumes that the counter is in the x lower bits
110 * of the IV (ivec), and that the application has full control over
111 * overflow and the rest of the IV. This implementation takes NO
112 * responsability for checking that the counter doesn't overflow
113 * into the rest of the IV when incremented.
114 */
115void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
116 const unsigned long length, const AES_KEY *key,
117 unsigned char ivec[AES_BLOCK_SIZE],
118 unsigned char ecount_buf[AES_BLOCK_SIZE],
119 unsigned int *num) {
120
121 unsigned int n;
122 unsigned long l=length;
123
124 assert(in && out && key && counter && num);
125 assert(*num < AES_BLOCK_SIZE);
126
127 n = *num;
128
129 while (l--) {
130 if (n == 0) {
131 AES_encrypt(ivec, ecount_buf, key);
132 AES_ctr128_inc(ivec);
133 }
134 *(out++) = *(in++) ^ ecount_buf[n];
135 n = (n+1) % AES_BLOCK_SIZE;
136 }
137
138 *num=n;
139}
diff --git a/src/lib/libcrypto/aes/aes_ecb.c b/src/lib/libcrypto/aes/aes_ecb.c
deleted file mode 100644
index 28aa561c2d..0000000000
--- a/src/lib/libcrypto/aes/aes_ecb.c
+++ /dev/null
@@ -1,73 +0,0 @@
1/* crypto/aes/aes_ecb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef AES_DEBUG
53# ifndef NDEBUG
54# define NDEBUG
55# endif
56#endif
57#include <assert.h>
58
59#include <openssl/aes.h>
60#include "aes_locl.h"
61
62void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
63 const AES_KEY *key, const int enc) {
64
65 assert(in && out && key);
66 assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
67
68 if (AES_ENCRYPT == enc)
69 AES_encrypt(in, out, key);
70 else
71 AES_decrypt(in, out, key);
72}
73
diff --git a/src/lib/libcrypto/aes/aes_locl.h b/src/lib/libcrypto/aes/aes_locl.h
deleted file mode 100644
index 4184729e34..0000000000
--- a/src/lib/libcrypto/aes/aes_locl.h
+++ /dev/null
@@ -1,85 +0,0 @@
1/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#ifndef HEADER_AES_LOCL_H
53#define HEADER_AES_LOCL_H
54
55#include <openssl/e_os2.h>
56
57#ifdef OPENSSL_NO_AES
58#error AES is disabled.
59#endif
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64
65#if defined(_MSC_VER) && !defined(_M_IA64) && !defined(OPENSSL_SYS_WINCE)
66# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
67# define GETU32(p) SWAP(*((u32 *)(p)))
68# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
69#else
70# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
71# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
72#endif
73
74typedef unsigned long u32;
75typedef unsigned short u16;
76typedef unsigned char u8;
77
78#define MAXKC (256/32)
79#define MAXKB (256/8)
80#define MAXNR 14
81
82/* This controls loop-unrolling in aes_core.c */
83#undef FULL_UNROLL
84
85#endif /* !HEADER_AES_LOCL_H */
diff --git a/src/lib/libcrypto/aes/aes_misc.c b/src/lib/libcrypto/aes/aes_misc.c
deleted file mode 100644
index 090def25d5..0000000000
--- a/src/lib/libcrypto/aes/aes_misc.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/* crypto/aes/aes_misc.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include <openssl/opensslv.h>
53#include <openssl/aes.h>
54#include "aes_locl.h"
55
56const char *AES_version="AES" OPENSSL_VERSION_PTEXT;
57
58const char *AES_options(void) {
59#ifdef FULL_UNROLL
60 return "aes(full)";
61#else
62 return "aes(partial)";
63#endif
64}
diff --git a/src/lib/libcrypto/aes/aes_ofb.c b/src/lib/libcrypto/aes/aes_ofb.c
deleted file mode 100644
index f358bb39e2..0000000000
--- a/src/lib/libcrypto/aes/aes_ofb.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/* crypto/aes/aes_ofb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
52 * All rights reserved.
53 *
54 * This package is an SSL implementation written
55 * by Eric Young (eay@cryptsoft.com).
56 * The implementation was written so as to conform with Netscapes SSL.
57 *
58 * This library is free for commercial and non-commercial use as long as
59 * the following conditions are aheared to. The following conditions
60 * apply to all code found in this distribution, be it the RC4, RSA,
61 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
62 * included with this distribution is covered by the same copyright terms
63 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
64 *
65 * Copyright remains Eric Young's, and as such any Copyright notices in
66 * the code are not to be removed.
67 * If this package is used in a product, Eric Young should be given attribution
68 * as the author of the parts of the library used.
69 * This can be in the form of a textual message at program startup or
70 * in documentation (online or textual) provided with the package.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * "This product includes cryptographic software written by
83 * Eric Young (eay@cryptsoft.com)"
84 * The word 'cryptographic' can be left out if the rouines from the library
85 * being used are not cryptographic related :-).
86 * 4. If you include any Windows specific code (or a derivative thereof) from
87 * the apps directory (application code) you must include an acknowledgement:
88 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
89 *
90 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 *
102 * The licence and distribution terms for any publically available version or
103 * derivative of this code cannot be changed. i.e. this code cannot simply be
104 * copied and put under another distribution licence
105 * [including the GNU Public Licence.]
106 */
107
108#ifndef AES_DEBUG
109# ifndef NDEBUG
110# define NDEBUG
111# endif
112#endif
113#include <assert.h>
114
115#include <openssl/aes.h>
116#include "aes_locl.h"
117
118/* The input and output encrypted as though 128bit ofb mode is being
119 * used. The extra state information to record how much of the
120 * 128bit block we have used is contained in *num;
121 */
122void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
123 const unsigned long length, const AES_KEY *key,
124 unsigned char *ivec, int *num) {
125
126 unsigned int n;
127 unsigned long l=length;
128
129 assert(in && out && key && ivec && num);
130
131 n = *num;
132
133 while (l--) {
134 if (n == 0) {
135 AES_encrypt(ivec, ivec, key);
136 }
137 *(out++) = *(in++) ^ ivec[n];
138 n = (n+1) % AES_BLOCK_SIZE;
139 }
140
141 *num=n;
142}
diff --git a/src/lib/libcrypto/aes/asm/aes-586.pl b/src/lib/libcrypto/aes/asm/aes-586.pl
deleted file mode 100644
index 688fda21ff..0000000000
--- a/src/lib/libcrypto/aes/asm/aes-586.pl
+++ /dev/null
@@ -1,1541 +0,0 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. Rights for redistribution and usage in source and binary
6# forms are granted according to the OpenSSL license.
7# ====================================================================
8#
9# Version 2.0.
10#
11# You might fail to appreciate this module performance from the first
12# try. If compared to "vanilla" linux-ia32-icc target, i.e. considered
13# to be *the* best Intel C compiler without -KPIC, performance appears
14# to be virtually identical... But try to re-configure with shared
15# library support... Aha! Intel compiler "suddenly" lags behind by 30%
16# [on P4, more on others]:-) And if compared to position-independent
17# code generated by GNU C, this code performs *more* than *twice* as
18# fast! Yes, all this buzz about PIC means that unlike other hand-
19# coded implementations, this one was explicitly designed to be safe
20# to use even in shared library context... This also means that this
21# code isn't necessarily absolutely fastest "ever," because in order
22# to achieve position independence an extra register has to be
23# off-loaded to stack, which affects the benchmark result.
24#
25# Special note about instruction choice. Do you recall RC4_INT code
26# performing poorly on P4? It might be the time to figure out why.
27# RC4_INT code implies effective address calculations in base+offset*4
28# form. Trouble is that it seems that offset scaling turned to be
29# critical path... At least eliminating scaling resulted in 2.8x RC4
30# performance improvement [as you might recall]. As AES code is hungry
31# for scaling too, I [try to] avoid the latter by favoring off-by-2
32# shifts and masking the result with 0xFF<<2 instead of "boring" 0xFF.
33#
34# As was shown by Dean Gaudet <dean@arctic.org>, the above note turned
35# void. Performance improvement with off-by-2 shifts was observed on
36# intermediate implementation, which was spilling yet another register
37# to stack... Final offset*4 code below runs just a tad faster on P4,
38# but exhibits up to 10% improvement on other cores.
39#
40# Second version is "monolithic" replacement for aes_core.c, which in
41# addition to AES_[de|en]crypt implements AES_set_[de|en]cryption_key.
42# This made it possible to implement little-endian variant of the
43# algorithm without modifying the base C code. Motivating factor for
44# the undertaken effort was that it appeared that in tight IA-32
45# register window little-endian flavor could achieve slightly higher
46# Instruction Level Parallelism, and it indeed resulted in up to 15%
47# better performance on most recent µ-archs...
48#
49# Current ECB performance numbers for 128-bit key in cycles per byte
50# [measure commonly used by AES benchmarkers] are:
51#
52# small footprint fully unrolled
53# P4[-3] 23[24] 22[23]
54# AMD K8 19 18
55# PIII 26(*) 23
56# Pentium 63(*) 52
57#
58# (*) Performance difference between small footprint code and fully
59# unrolled in more commonly used CBC mode is not as big, 7% for
60# PIII and 15% for Pentium, which I consider tolerable.
61
62push(@INC,"perlasm","../../perlasm");
63require "x86asm.pl";
64
65&asm_init($ARGV[0],"aes-586.pl",$ARGV[$#ARGV] eq "386");
66
67$small_footprint=1; # $small_footprint=1 code is ~5% slower [on
68 # recent µ-archs], but ~5 times smaller!
69 # I favor compact code, because it minimizes
70 # cache contention...
71$vertical_spin=0; # shift "verticaly" defaults to 0, because of
72 # its proof-of-concept status, see below...
73
74$s0="eax";
75$s1="ebx";
76$s2="ecx";
77$s3="edx";
78$key="esi";
79$acc="edi";
80
81if ($vertical_spin) {
82 # I need high parts of volatile registers to be accessible...
83 $s1="esi"; $key="ebx";
84 $s2="edi"; $acc="ecx";
85}
86# Note that there is no decvert(), as well as last encryption round is
87# performed with "horizontal" shifts. This is because this "vertical"
88# implementation [one which groups shifts on a given $s[i] to form a
89# "column," unlike "horizontal" one, which groups shifts on different
90# $s[i] to form a "row"] is work in progress. It was observed to run
91# few percents faster on Intel cores, but not AMD. On AMD K8 core it's
92# whole 12% slower:-( So we face a trade-off... Shall it be resolved
93# some day? Till then the code is considered experimental and by
94# default remains dormant...
95
96sub encvert()
97{ my ($te,@s) = @_;
98 my $v0 = $acc, $v1 = $key;
99
100 &mov ($v0,$s[3]); # copy s3
101 &mov (&DWP(0,"esp"),$s[2]); # save s2
102 &mov ($v1,$s[0]); # copy s0
103 &mov (&DWP(4,"esp"),$s[1]); # save s1
104
105 &movz ($s[2],&HB($s[0]));
106 &and ($s[0],0xFF);
107 &mov ($s[0],&DWP(1024*0,$te,$s[0],4)); # s0>>0
108 &shr ($v1,16);
109 &mov ($s[3],&DWP(1024*1,$te,$s[2],4)); # s0>>8
110 &movz ($s[1],&HB($v1));
111 &and ($v1,0xFF);
112 &mov ($s[2],&DWP(1024*2,$te,$v1,4)); # s0>>16
113 &mov ($v1,$v0);
114 &mov ($s[1],&DWP(1024*3,$te,$s[1],4)); # s0>>24
115
116 &and ($v0,0xFF);
117 &xor ($s[3],&DWP(1024*0,$te,$v0,4)); # s3>>0
118 &movz ($v0,&HB($v1));
119 &shr ($v1,16);
120 &xor ($s[2],&DWP(1024*1,$te,$v0,4)); # s3>>8
121 &movz ($v0,&HB($v1));
122 &and ($v1,0xFF);
123 &xor ($s[1],&DWP(1024*2,$te,$v1,4)); # s3>>16
124 &mov ($v1,&DWP(0,"esp")); # restore s2
125 &xor ($s[0],&DWP(1024*3,$te,$v0,4)); # s3>>24
126
127 &mov ($v0,$v1);
128 &and ($v1,0xFF);
129 &xor ($s[2],&DWP(1024*0,$te,$v1,4)); # s2>>0
130 &movz ($v1,&HB($v0));
131 &shr ($v0,16);
132 &xor ($s[1],&DWP(1024*1,$te,$v1,4)); # s2>>8
133 &movz ($v1,&HB($v0));
134 &and ($v0,0xFF);
135 &xor ($s[0],&DWP(1024*2,$te,$v0,4)); # s2>>16
136 &mov ($v0,&DWP(4,"esp")); # restore s1
137 &xor ($s[3],&DWP(1024*3,$te,$v1,4)); # s2>>24
138
139 &mov ($v1,$v0);
140 &and ($v0,0xFF);
141 &xor ($s[1],&DWP(1024*0,$te,$v0,4)); # s1>>0
142 &movz ($v0,&HB($v1));
143 &shr ($v1,16);
144 &xor ($s[0],&DWP(1024*1,$te,$v0,4)); # s1>>8
145 &movz ($v0,&HB($v1));
146 &and ($v1,0xFF);
147 &xor ($s[3],&DWP(1024*2,$te,$v1,4)); # s1>>16
148 &mov ($key,&DWP(12,"esp")); # reincarnate v1 as key
149 &xor ($s[2],&DWP(1024*3,$te,$v0,4)); # s1>>24
150}
151
152sub encstep()
153{ my ($i,$te,@s) = @_;
154 my $tmp = $key;
155 my $out = $i==3?$s[0]:$acc;
156
157 # lines marked with #%e?x[i] denote "reordered" instructions...
158 if ($i==3) { &mov ($key,&DWP(12,"esp")); }##%edx
159 else { &mov ($out,$s[0]);
160 &and ($out,0xFF); }
161 if ($i==1) { &shr ($s[0],16); }#%ebx[1]
162 if ($i==2) { &shr ($s[0],24); }#%ecx[2]
163 &mov ($out,&DWP(1024*0,$te,$out,4));
164
165 if ($i==3) { $tmp=$s[1]; }##%eax
166 &movz ($tmp,&HB($s[1]));
167 &xor ($out,&DWP(1024*1,$te,$tmp,4));
168
169 if ($i==3) { $tmp=$s[2]; &mov ($s[1],&DWP(0,"esp")); }##%ebx
170 else { &mov ($tmp,$s[2]);
171 &shr ($tmp,16); }
172 if ($i==2) { &and ($s[1],0xFF); }#%edx[2]
173 &and ($tmp,0xFF);
174 &xor ($out,&DWP(1024*2,$te,$tmp,4));
175
176 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }##%ecx
177 elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2]
178 else { &mov ($tmp,$s[3]);
179 &shr ($tmp,24) }
180 &xor ($out,&DWP(1024*3,$te,$tmp,4));
181 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
182 if ($i==3) { &mov ($s[3],$acc); }
183 &comment();
184}
185
186sub enclast()
187{ my ($i,$te,@s)=@_;
188 my $tmp = $key;
189 my $out = $i==3?$s[0]:$acc;
190
191 if ($i==3) { &mov ($key,&DWP(12,"esp")); }##%edx
192 else { &mov ($out,$s[0]); }
193 &and ($out,0xFF);
194 if ($i==1) { &shr ($s[0],16); }#%ebx[1]
195 if ($i==2) { &shr ($s[0],24); }#%ecx[2]
196 &mov ($out,&DWP(1024*0,$te,$out,4));
197 &and ($out,0x000000ff);
198
199 if ($i==3) { $tmp=$s[1]; }##%eax
200 &movz ($tmp,&HB($s[1]));
201 &mov ($tmp,&DWP(0,$te,$tmp,4));
202 &and ($tmp,0x0000ff00);
203 &xor ($out,$tmp);
204
205 if ($i==3) { $tmp=$s[2]; &mov ($s[1],&DWP(0,"esp")); }##%ebx
206 else { mov ($tmp,$s[2]);
207 &shr ($tmp,16); }
208 if ($i==2) { &and ($s[1],0xFF); }#%edx[2]
209 &and ($tmp,0xFF);
210 &mov ($tmp,&DWP(0,$te,$tmp,4));
211 &and ($tmp,0x00ff0000);
212 &xor ($out,$tmp);
213
214 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }##%ecx
215 elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2]
216 else { &mov ($tmp,$s[3]);
217 &shr ($tmp,24); }
218 &mov ($tmp,&DWP(0,$te,$tmp,4));
219 &and ($tmp,0xff000000);
220 &xor ($out,$tmp);
221 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
222 if ($i==3) { &mov ($s[3],$acc); }
223}
224
225# void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
226&public_label("AES_Te");
227&function_begin("AES_encrypt");
228 &mov ($acc,&wparam(0)); # load inp
229 &mov ($key,&wparam(2)); # load key
230
231 &call (&label("pic_point")); # make it PIC!
232 &set_label("pic_point");
233 &blindpop("ebp");
234 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
235
236 # allocate aligned stack frame
237 &mov ($s0,"esp");
238 &sub ("esp",20);
239 &and ("esp",-16);
240
241 &mov (&DWP(12,"esp"),$key); # save key
242 &mov (&DWP(16,"esp"),$s0); # save %esp
243
244 &mov ($s0,&DWP(0,$acc)); # load input data
245 &mov ($s1,&DWP(4,$acc));
246 &mov ($s2,&DWP(8,$acc));
247 &mov ($s3,&DWP(12,$acc));
248
249 &xor ($s0,&DWP(0,$key));
250 &xor ($s1,&DWP(4,$key));
251 &xor ($s2,&DWP(8,$key));
252 &xor ($s3,&DWP(12,$key));
253
254 &mov ($acc,&DWP(240,$key)); # load key->rounds
255
256 if ($small_footprint) {
257 &lea ($acc,&DWP(-2,$acc,$acc));
258 &lea ($acc,&DWP(0,$key,$acc,8));
259 &mov (&DWP(8,"esp"),$acc); # end of key schedule
260 &align (4);
261 &set_label("loop");
262 if ($vertical_spin) {
263 &encvert("ebp",$s0,$s1,$s2,$s3);
264 } else {
265 &encstep(0,"ebp",$s0,$s1,$s2,$s3);
266 &encstep(1,"ebp",$s1,$s2,$s3,$s0);
267 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
268 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
269 }
270 &add ($key,16); # advance rd_key
271 &xor ($s0,&DWP(0,$key));
272 &xor ($s1,&DWP(4,$key));
273 &xor ($s2,&DWP(8,$key));
274 &xor ($s3,&DWP(12,$key));
275 &cmp ($key,&DWP(8,"esp"));
276 &mov (&DWP(12,"esp"),$key);
277 &jb (&label("loop"));
278 }
279 else {
280 &cmp ($acc,10);
281 &jle (&label("10rounds"));
282 &cmp ($acc,12);
283 &jle (&label("12rounds"));
284
285 &set_label("14rounds");
286 for ($i=1;$i<3;$i++) {
287 if ($vertical_spin) {
288 &encvert("ebp",$s0,$s1,$s2,$s3);
289 } else {
290 &encstep(0,"ebp",$s0,$s1,$s2,$s3);
291 &encstep(1,"ebp",$s1,$s2,$s3,$s0);
292 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
293 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
294 }
295 &xor ($s0,&DWP(16*$i+0,$key));
296 &xor ($s1,&DWP(16*$i+4,$key));
297 &xor ($s2,&DWP(16*$i+8,$key));
298 &xor ($s3,&DWP(16*$i+12,$key));
299 }
300 &add ($key,32);
301 &mov (&DWP(12,"esp"),$key); # advance rd_key
302 &set_label("12rounds");
303 for ($i=1;$i<3;$i++) {
304 if ($vertical_spin) {
305 &encvert("ebp",$s0,$s1,$s2,$s3);
306 } else {
307 &encstep(0,"ebp",$s0,$s1,$s2,$s3);
308 &encstep(1,"ebp",$s1,$s2,$s3,$s0);
309 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
310 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
311 }
312 &xor ($s0,&DWP(16*$i+0,$key));
313 &xor ($s1,&DWP(16*$i+4,$key));
314 &xor ($s2,&DWP(16*$i+8,$key));
315 &xor ($s3,&DWP(16*$i+12,$key));
316 }
317 &add ($key,32);
318 &mov (&DWP(12,"esp"),$key); # advance rd_key
319 &set_label("10rounds");
320 for ($i=1;$i<10;$i++) {
321 if ($vertical_spin) {
322 &encvert("ebp",$s0,$s1,$s2,$s3);
323 } else {
324 &encstep(0,"ebp",$s0,$s1,$s2,$s3);
325 &encstep(1,"ebp",$s1,$s2,$s3,$s0);
326 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
327 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
328 }
329 &xor ($s0,&DWP(16*$i+0,$key));
330 &xor ($s1,&DWP(16*$i+4,$key));
331 &xor ($s2,&DWP(16*$i+8,$key));
332 &xor ($s3,&DWP(16*$i+12,$key));
333 }
334 }
335
336 &add ("ebp",4*1024); # skip to Te4
337 if ($vertical_spin) {
338 # "reincarnate" some registers for "horizontal" spin...
339 &mov ($s1="ebx",$key="esi");
340 &mov ($s2="ecx",$acc="edi");
341 }
342 &enclast(0,"ebp",$s0,$s1,$s2,$s3);
343 &enclast(1,"ebp",$s1,$s2,$s3,$s0);
344 &enclast(2,"ebp",$s2,$s3,$s0,$s1);
345 &enclast(3,"ebp",$s3,$s0,$s1,$s2);
346
347 &mov ("esp",&DWP(16,"esp")); # restore %esp
348 &add ($key,$small_footprint?16:160);
349 &xor ($s0,&DWP(0,$key));
350 &xor ($s1,&DWP(4,$key));
351 &xor ($s2,&DWP(8,$key));
352 &xor ($s3,&DWP(12,$key));
353
354 &mov ($acc,&wparam(1)); # load out
355 &mov (&DWP(0,$acc),$s0); # write output data
356 &mov (&DWP(4,$acc),$s1);
357 &mov (&DWP(8,$acc),$s2);
358 &mov (&DWP(12,$acc),$s3);
359
360 &pop ("edi");
361 &pop ("esi");
362 &pop ("ebx");
363 &pop ("ebp");
364 &ret ();
365
366&set_label("AES_Te",64); # Yes! I keep it in the code segment!
367 &data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
368 &data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
369 &data_word(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56);
370 &data_word(0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec);
371 &data_word(0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa);
372 &data_word(0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb);
373 &data_word(0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45);
374 &data_word(0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b);
375 &data_word(0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c);
376 &data_word(0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83);
377 &data_word(0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9);
378 &data_word(0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a);
379 &data_word(0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d);
380 &data_word(0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f);
381 &data_word(0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df);
382 &data_word(0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea);
383 &data_word(0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34);
384 &data_word(0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b);
385 &data_word(0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d);
386 &data_word(0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413);
387 &data_word(0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1);
388 &data_word(0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6);
389 &data_word(0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972);
390 &data_word(0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85);
391 &data_word(0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed);
392 &data_word(0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511);
393 &data_word(0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe);
394 &data_word(0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b);
395 &data_word(0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05);
396 &data_word(0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1);
397 &data_word(0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142);
398 &data_word(0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf);
399 &data_word(0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3);
400 &data_word(0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e);
401 &data_word(0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a);
402 &data_word(0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6);
403 &data_word(0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3);
404 &data_word(0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b);
405 &data_word(0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428);
406 &data_word(0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad);
407 &data_word(0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14);
408 &data_word(0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8);
409 &data_word(0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4);
410 &data_word(0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2);
411 &data_word(0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda);
412 &data_word(0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949);
413 &data_word(0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf);
414 &data_word(0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810);
415 &data_word(0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c);
416 &data_word(0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697);
417 &data_word(0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e);
418 &data_word(0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f);
419 &data_word(0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc);
420 &data_word(0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c);
421 &data_word(0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969);
422 &data_word(0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27);
423 &data_word(0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122);
424 &data_word(0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433);
425 &data_word(0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9);
426 &data_word(0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5);
427 &data_word(0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a);
428 &data_word(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
429 &data_word(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
430 &data_word(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
431#Te1:
432 &data_word(0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d);
433 &data_word(0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154);
434 &data_word(0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d);
435 &data_word(0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a);
436 &data_word(0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87);
437 &data_word(0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b);
438 &data_word(0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea);
439 &data_word(0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b);
440 &data_word(0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a);
441 &data_word(0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f);
442 &data_word(0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908);
443 &data_word(0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f);
444 &data_word(0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e);
445 &data_word(0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5);
446 &data_word(0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d);
447 &data_word(0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f);
448 &data_word(0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e);
449 &data_word(0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb);
450 &data_word(0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce);
451 &data_word(0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397);
452 &data_word(0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c);
453 &data_word(0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed);
454 &data_word(0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b);
455 &data_word(0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a);
456 &data_word(0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16);
457 &data_word(0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194);
458 &data_word(0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81);
459 &data_word(0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3);
460 &data_word(0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a);
461 &data_word(0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104);
462 &data_word(0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263);
463 &data_word(0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d);
464 &data_word(0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f);
465 &data_word(0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39);
466 &data_word(0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47);
467 &data_word(0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695);
468 &data_word(0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f);
469 &data_word(0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83);
470 &data_word(0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c);
471 &data_word(0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76);
472 &data_word(0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e);
473 &data_word(0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4);
474 &data_word(0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6);
475 &data_word(0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b);
476 &data_word(0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7);
477 &data_word(0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0);
478 &data_word(0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25);
479 &data_word(0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018);
480 &data_word(0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72);
481 &data_word(0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751);
482 &data_word(0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21);
483 &data_word(0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85);
484 &data_word(0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa);
485 &data_word(0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12);
486 &data_word(0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0);
487 &data_word(0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9);
488 &data_word(0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233);
489 &data_word(0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7);
490 &data_word(0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920);
491 &data_word(0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a);
492 &data_word(0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17);
493 &data_word(0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8);
494 &data_word(0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11);
495 &data_word(0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a);
496#Te2:
497 &data_word(0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b);
498 &data_word(0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5);
499 &data_word(0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b);
500 &data_word(0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76);
501 &data_word(0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d);
502 &data_word(0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0);
503 &data_word(0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf);
504 &data_word(0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0);
505 &data_word(0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26);
506 &data_word(0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc);
507 &data_word(0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1);
508 &data_word(0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15);
509 &data_word(0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3);
510 &data_word(0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a);
511 &data_word(0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2);
512 &data_word(0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75);
513 &data_word(0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a);
514 &data_word(0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0);
515 &data_word(0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3);
516 &data_word(0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784);
517 &data_word(0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced);
518 &data_word(0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b);
519 &data_word(0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39);
520 &data_word(0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf);
521 &data_word(0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb);
522 &data_word(0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485);
523 &data_word(0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f);
524 &data_word(0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8);
525 &data_word(0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f);
526 &data_word(0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5);
527 &data_word(0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321);
528 &data_word(0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2);
529 &data_word(0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec);
530 &data_word(0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917);
531 &data_word(0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d);
532 &data_word(0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573);
533 &data_word(0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc);
534 &data_word(0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388);
535 &data_word(0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14);
536 &data_word(0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db);
537 &data_word(0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a);
538 &data_word(0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c);
539 &data_word(0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662);
540 &data_word(0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79);
541 &data_word(0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d);
542 &data_word(0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9);
543 &data_word(0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea);
544 &data_word(0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808);
545 &data_word(0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e);
546 &data_word(0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6);
547 &data_word(0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f);
548 &data_word(0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a);
549 &data_word(0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66);
550 &data_word(0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e);
551 &data_word(0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9);
552 &data_word(0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e);
553 &data_word(0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311);
554 &data_word(0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794);
555 &data_word(0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9);
556 &data_word(0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf);
557 &data_word(0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d);
558 &data_word(0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868);
559 &data_word(0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f);
560 &data_word(0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16);
561#Te3:
562 &data_word(0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b);
563 &data_word(0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5);
564 &data_word(0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b);
565 &data_word(0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676);
566 &data_word(0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d);
567 &data_word(0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0);
568 &data_word(0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf);
569 &data_word(0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0);
570 &data_word(0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626);
571 &data_word(0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc);
572 &data_word(0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1);
573 &data_word(0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515);
574 &data_word(0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3);
575 &data_word(0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a);
576 &data_word(0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2);
577 &data_word(0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575);
578 &data_word(0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a);
579 &data_word(0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0);
580 &data_word(0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3);
581 &data_word(0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484);
582 &data_word(0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded);
583 &data_word(0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b);
584 &data_word(0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939);
585 &data_word(0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf);
586 &data_word(0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb);
587 &data_word(0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585);
588 &data_word(0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f);
589 &data_word(0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8);
590 &data_word(0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f);
591 &data_word(0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5);
592 &data_word(0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121);
593 &data_word(0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2);
594 &data_word(0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec);
595 &data_word(0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717);
596 &data_word(0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d);
597 &data_word(0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373);
598 &data_word(0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc);
599 &data_word(0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888);
600 &data_word(0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414);
601 &data_word(0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb);
602 &data_word(0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a);
603 &data_word(0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c);
604 &data_word(0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262);
605 &data_word(0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979);
606 &data_word(0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d);
607 &data_word(0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9);
608 &data_word(0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea);
609 &data_word(0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808);
610 &data_word(0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e);
611 &data_word(0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6);
612 &data_word(0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f);
613 &data_word(0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a);
614 &data_word(0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666);
615 &data_word(0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e);
616 &data_word(0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9);
617 &data_word(0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e);
618 &data_word(0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111);
619 &data_word(0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494);
620 &data_word(0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9);
621 &data_word(0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf);
622 &data_word(0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d);
623 &data_word(0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868);
624 &data_word(0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f);
625 &data_word(0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616);
626#Te4:
627 &data_word(0x63636363, 0x7c7c7c7c, 0x77777777, 0x7b7b7b7b);
628 &data_word(0xf2f2f2f2, 0x6b6b6b6b, 0x6f6f6f6f, 0xc5c5c5c5);
629 &data_word(0x30303030, 0x01010101, 0x67676767, 0x2b2b2b2b);
630 &data_word(0xfefefefe, 0xd7d7d7d7, 0xabababab, 0x76767676);
631 &data_word(0xcacacaca, 0x82828282, 0xc9c9c9c9, 0x7d7d7d7d);
632 &data_word(0xfafafafa, 0x59595959, 0x47474747, 0xf0f0f0f0);
633 &data_word(0xadadadad, 0xd4d4d4d4, 0xa2a2a2a2, 0xafafafaf);
634 &data_word(0x9c9c9c9c, 0xa4a4a4a4, 0x72727272, 0xc0c0c0c0);
635 &data_word(0xb7b7b7b7, 0xfdfdfdfd, 0x93939393, 0x26262626);
636 &data_word(0x36363636, 0x3f3f3f3f, 0xf7f7f7f7, 0xcccccccc);
637 &data_word(0x34343434, 0xa5a5a5a5, 0xe5e5e5e5, 0xf1f1f1f1);
638 &data_word(0x71717171, 0xd8d8d8d8, 0x31313131, 0x15151515);
639 &data_word(0x04040404, 0xc7c7c7c7, 0x23232323, 0xc3c3c3c3);
640 &data_word(0x18181818, 0x96969696, 0x05050505, 0x9a9a9a9a);
641 &data_word(0x07070707, 0x12121212, 0x80808080, 0xe2e2e2e2);
642 &data_word(0xebebebeb, 0x27272727, 0xb2b2b2b2, 0x75757575);
643 &data_word(0x09090909, 0x83838383, 0x2c2c2c2c, 0x1a1a1a1a);
644 &data_word(0x1b1b1b1b, 0x6e6e6e6e, 0x5a5a5a5a, 0xa0a0a0a0);
645 &data_word(0x52525252, 0x3b3b3b3b, 0xd6d6d6d6, 0xb3b3b3b3);
646 &data_word(0x29292929, 0xe3e3e3e3, 0x2f2f2f2f, 0x84848484);
647 &data_word(0x53535353, 0xd1d1d1d1, 0x00000000, 0xedededed);
648 &data_word(0x20202020, 0xfcfcfcfc, 0xb1b1b1b1, 0x5b5b5b5b);
649 &data_word(0x6a6a6a6a, 0xcbcbcbcb, 0xbebebebe, 0x39393939);
650 &data_word(0x4a4a4a4a, 0x4c4c4c4c, 0x58585858, 0xcfcfcfcf);
651 &data_word(0xd0d0d0d0, 0xefefefef, 0xaaaaaaaa, 0xfbfbfbfb);
652 &data_word(0x43434343, 0x4d4d4d4d, 0x33333333, 0x85858585);
653 &data_word(0x45454545, 0xf9f9f9f9, 0x02020202, 0x7f7f7f7f);
654 &data_word(0x50505050, 0x3c3c3c3c, 0x9f9f9f9f, 0xa8a8a8a8);
655 &data_word(0x51515151, 0xa3a3a3a3, 0x40404040, 0x8f8f8f8f);
656 &data_word(0x92929292, 0x9d9d9d9d, 0x38383838, 0xf5f5f5f5);
657 &data_word(0xbcbcbcbc, 0xb6b6b6b6, 0xdadadada, 0x21212121);
658 &data_word(0x10101010, 0xffffffff, 0xf3f3f3f3, 0xd2d2d2d2);
659 &data_word(0xcdcdcdcd, 0x0c0c0c0c, 0x13131313, 0xecececec);
660 &data_word(0x5f5f5f5f, 0x97979797, 0x44444444, 0x17171717);
661 &data_word(0xc4c4c4c4, 0xa7a7a7a7, 0x7e7e7e7e, 0x3d3d3d3d);
662 &data_word(0x64646464, 0x5d5d5d5d, 0x19191919, 0x73737373);
663 &data_word(0x60606060, 0x81818181, 0x4f4f4f4f, 0xdcdcdcdc);
664 &data_word(0x22222222, 0x2a2a2a2a, 0x90909090, 0x88888888);
665 &data_word(0x46464646, 0xeeeeeeee, 0xb8b8b8b8, 0x14141414);
666 &data_word(0xdededede, 0x5e5e5e5e, 0x0b0b0b0b, 0xdbdbdbdb);
667 &data_word(0xe0e0e0e0, 0x32323232, 0x3a3a3a3a, 0x0a0a0a0a);
668 &data_word(0x49494949, 0x06060606, 0x24242424, 0x5c5c5c5c);
669 &data_word(0xc2c2c2c2, 0xd3d3d3d3, 0xacacacac, 0x62626262);
670 &data_word(0x91919191, 0x95959595, 0xe4e4e4e4, 0x79797979);
671 &data_word(0xe7e7e7e7, 0xc8c8c8c8, 0x37373737, 0x6d6d6d6d);
672 &data_word(0x8d8d8d8d, 0xd5d5d5d5, 0x4e4e4e4e, 0xa9a9a9a9);
673 &data_word(0x6c6c6c6c, 0x56565656, 0xf4f4f4f4, 0xeaeaeaea);
674 &data_word(0x65656565, 0x7a7a7a7a, 0xaeaeaeae, 0x08080808);
675 &data_word(0xbabababa, 0x78787878, 0x25252525, 0x2e2e2e2e);
676 &data_word(0x1c1c1c1c, 0xa6a6a6a6, 0xb4b4b4b4, 0xc6c6c6c6);
677 &data_word(0xe8e8e8e8, 0xdddddddd, 0x74747474, 0x1f1f1f1f);
678 &data_word(0x4b4b4b4b, 0xbdbdbdbd, 0x8b8b8b8b, 0x8a8a8a8a);
679 &data_word(0x70707070, 0x3e3e3e3e, 0xb5b5b5b5, 0x66666666);
680 &data_word(0x48484848, 0x03030303, 0xf6f6f6f6, 0x0e0e0e0e);
681 &data_word(0x61616161, 0x35353535, 0x57575757, 0xb9b9b9b9);
682 &data_word(0x86868686, 0xc1c1c1c1, 0x1d1d1d1d, 0x9e9e9e9e);
683 &data_word(0xe1e1e1e1, 0xf8f8f8f8, 0x98989898, 0x11111111);
684 &data_word(0x69696969, 0xd9d9d9d9, 0x8e8e8e8e, 0x94949494);
685 &data_word(0x9b9b9b9b, 0x1e1e1e1e, 0x87878787, 0xe9e9e9e9);
686 &data_word(0xcececece, 0x55555555, 0x28282828, 0xdfdfdfdf);
687 &data_word(0x8c8c8c8c, 0xa1a1a1a1, 0x89898989, 0x0d0d0d0d);
688 &data_word(0xbfbfbfbf, 0xe6e6e6e6, 0x42424242, 0x68686868);
689 &data_word(0x41414141, 0x99999999, 0x2d2d2d2d, 0x0f0f0f0f);
690 &data_word(0xb0b0b0b0, 0x54545454, 0xbbbbbbbb, 0x16161616);
691#rcon:
692 &data_word(0x00000001, 0x00000002, 0x00000004, 0x00000008);
693 &data_word(0x00000010, 0x00000020, 0x00000040, 0x00000080);
694 &data_word(0x0000001b, 0x00000036);
695&function_end_B("AES_encrypt");
696
697#------------------------------------------------------------------#
698
699$s0="eax";
700$s1="ebx";
701$s2="ecx";
702$s3="edx";
703$key="edi";
704$acc="esi";
705
706sub decstep()
707{ my ($i,$td,@s) = @_;
708 my $tmp = $key;
709 my $out = $i==3?$s[0]:$acc;
710
711 # no instructions are reordered, as performance appears
712 # optimal... or rather that all attempts to reorder didn't
713 # result in better performance [which by the way is not a
714 # bit lower than ecryption].
715 if($i==3) { &mov ($key,&DWP(12,"esp")); }
716 else { &mov ($out,$s[0]); }
717 &and ($out,0xFF);
718 &mov ($out,&DWP(1024*0,$td,$out,4));
719
720 if ($i==3) { $tmp=$s[1]; }
721 &movz ($tmp,&HB($s[1]));
722 &xor ($out,&DWP(1024*1,$td,$tmp,4));
723
724 if ($i==3) { $tmp=$s[2]; &mov ($s[1],$acc); }
725 else { &mov ($tmp,$s[2]); }
726 &shr ($tmp,16);
727 &and ($tmp,0xFF);
728 &xor ($out,&DWP(1024*2,$td,$tmp,4));
729
730 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }
731 else { &mov ($tmp,$s[3]); }
732 &shr ($tmp,24);
733 &xor ($out,&DWP(1024*3,$td,$tmp,4));
734 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
735 if ($i==3) { &mov ($s[3],&DWP(0,"esp")); }
736 &comment();
737}
738
739sub declast()
740{ my ($i,$td,@s)=@_;
741 my $tmp = $key;
742 my $out = $i==3?$s[0]:$acc;
743
744 if($i==3) { &mov ($key,&DWP(12,"esp")); }
745 else { &mov ($out,$s[0]); }
746 &and ($out,0xFF);
747 &mov ($out,&DWP(0,$td,$out,4));
748 &and ($out,0x000000ff);
749
750 if ($i==3) { $tmp=$s[1]; }
751 &movz ($tmp,&HB($s[1]));
752 &mov ($tmp,&DWP(0,$td,$tmp,4));
753 &and ($tmp,0x0000ff00);
754 &xor ($out,$tmp);
755
756 if ($i==3) { $tmp=$s[2]; &mov ($s[1],$acc); }
757 else { mov ($tmp,$s[2]); }
758 &shr ($tmp,16);
759 &and ($tmp,0xFF);
760 &mov ($tmp,&DWP(0,$td,$tmp,4));
761 &and ($tmp,0x00ff0000);
762 &xor ($out,$tmp);
763
764 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }
765 else { &mov ($tmp,$s[3]); }
766 &shr ($tmp,24);
767 &mov ($tmp,&DWP(0,$td,$tmp,4));
768 &and ($tmp,0xff000000);
769 &xor ($out,$tmp);
770 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
771 if ($i==3) { &mov ($s[3],&DWP(0,"esp")); }
772}
773
774# void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
775&public_label("AES_Td");
776&function_begin("AES_decrypt");
777 &mov ($acc,&wparam(0)); # load inp
778 &mov ($key,&wparam(2)); # load key
779
780 &call (&label("pic_point")); # make it PIC!
781 &set_label("pic_point");
782 &blindpop("ebp");
783 &lea ("ebp",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
784
785 # allocate aligned stack frame
786 &mov ($s0,"esp");
787 &sub ("esp",20);
788 &and ("esp",-16);
789
790 &mov (&DWP(12,"esp"),$key); # save key
791 &mov (&DWP(16,"esp"),$s0); # save %esp
792
793 &mov ($s0,&DWP(0,$acc)); # load input data
794 &mov ($s1,&DWP(4,$acc));
795 &mov ($s2,&DWP(8,$acc));
796 &mov ($s3,&DWP(12,$acc));
797
798 &xor ($s0,&DWP(0,$key));
799 &xor ($s1,&DWP(4,$key));
800 &xor ($s2,&DWP(8,$key));
801 &xor ($s3,&DWP(12,$key));
802
803 &mov ($acc,&DWP(240,$key)); # load key->rounds
804
805 if ($small_footprint) {
806 &lea ($acc,&DWP(-2,$acc,$acc));
807 &lea ($acc,&DWP(0,$key,$acc,8));
808 &mov (&DWP(8,"esp"),$acc); # end of key schedule
809 &align (4);
810 &set_label("loop");
811 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
812 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
813 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
814 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
815 &add ($key,16); # advance rd_key
816 &xor ($s0,&DWP(0,$key));
817 &xor ($s1,&DWP(4,$key));
818 &xor ($s2,&DWP(8,$key));
819 &xor ($s3,&DWP(12,$key));
820 &cmp ($key,&DWP(8,"esp"));
821 &mov (&DWP(12,"esp"),$key);
822 &jb (&label("loop"));
823 }
824 else {
825 &cmp ($acc,10);
826 &jle (&label("10rounds"));
827 &cmp ($acc,12);
828 &jle (&label("12rounds"));
829
830 &set_label("14rounds");
831 for ($i=1;$i<3;$i++) {
832 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
833 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
834 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
835 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
836 &xor ($s0,&DWP(16*$i+0,$key));
837 &xor ($s1,&DWP(16*$i+4,$key));
838 &xor ($s2,&DWP(16*$i+8,$key));
839 &xor ($s3,&DWP(16*$i+12,$key));
840 }
841 &add ($key,32);
842 &mov (&DWP(12,"esp"),$key); # advance rd_key
843 &set_label("12rounds");
844 for ($i=1;$i<3;$i++) {
845 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
846 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
847 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
848 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
849 &xor ($s0,&DWP(16*$i+0,$key));
850 &xor ($s1,&DWP(16*$i+4,$key));
851 &xor ($s2,&DWP(16*$i+8,$key));
852 &xor ($s3,&DWP(16*$i+12,$key));
853 }
854 &add ($key,32);
855 &mov (&DWP(12,"esp"),$key); # advance rd_key
856 &set_label("10rounds");
857 for ($i=1;$i<10;$i++) {
858 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
859 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
860 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
861 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
862 &xor ($s0,&DWP(16*$i+0,$key));
863 &xor ($s1,&DWP(16*$i+4,$key));
864 &xor ($s2,&DWP(16*$i+8,$key));
865 &xor ($s3,&DWP(16*$i+12,$key));
866 }
867 }
868
869 &add ("ebp",4*1024); # skip to Te4
870 &declast(0,"ebp",$s0,$s3,$s2,$s1);
871 &declast(1,"ebp",$s1,$s0,$s3,$s2);
872 &declast(2,"ebp",$s2,$s1,$s0,$s3);
873 &declast(3,"ebp",$s3,$s2,$s1,$s0);
874
875 &mov ("esp",&DWP(16,"esp")); # restore %esp
876 &add ($key,$small_footprint?16:160);
877 &xor ($s0,&DWP(0,$key));
878 &xor ($s1,&DWP(4,$key));
879 &xor ($s2,&DWP(8,$key));
880 &xor ($s3,&DWP(12,$key));
881
882 &mov ($key,&wparam(1)); # load out
883 &mov (&DWP(0,$key),$s0); # write output data
884 &mov (&DWP(4,$key),$s1);
885 &mov (&DWP(8,$key),$s2);
886 &mov (&DWP(12,$key),$s3);
887
888 &pop ("edi");
889 &pop ("esi");
890 &pop ("ebx");
891 &pop ("ebp");
892 &ret ();
893
894&set_label("AES_Td",64); # Yes! I keep it in the code segment!
895 &data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a);
896 &data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b);
897 &data_word(0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5);
898 &data_word(0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5);
899 &data_word(0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d);
900 &data_word(0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b);
901 &data_word(0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295);
902 &data_word(0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e);
903 &data_word(0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927);
904 &data_word(0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d);
905 &data_word(0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362);
906 &data_word(0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9);
907 &data_word(0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52);
908 &data_word(0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566);
909 &data_word(0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3);
910 &data_word(0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed);
911 &data_word(0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e);
912 &data_word(0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4);
913 &data_word(0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4);
914 &data_word(0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd);
915 &data_word(0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d);
916 &data_word(0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060);
917 &data_word(0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967);
918 &data_word(0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879);
919 &data_word(0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000);
920 &data_word(0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c);
921 &data_word(0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36);
922 &data_word(0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624);
923 &data_word(0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b);
924 &data_word(0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c);
925 &data_word(0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12);
926 &data_word(0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14);
927 &data_word(0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3);
928 &data_word(0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b);
929 &data_word(0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8);
930 &data_word(0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684);
931 &data_word(0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7);
932 &data_word(0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177);
933 &data_word(0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947);
934 &data_word(0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322);
935 &data_word(0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498);
936 &data_word(0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f);
937 &data_word(0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54);
938 &data_word(0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382);
939 &data_word(0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf);
940 &data_word(0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb);
941 &data_word(0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83);
942 &data_word(0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef);
943 &data_word(0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029);
944 &data_word(0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235);
945 &data_word(0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733);
946 &data_word(0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117);
947 &data_word(0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4);
948 &data_word(0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546);
949 &data_word(0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb);
950 &data_word(0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d);
951 &data_word(0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb);
952 &data_word(0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a);
953 &data_word(0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773);
954 &data_word(0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478);
955 &data_word(0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2);
956 &data_word(0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff);
957 &data_word(0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664);
958 &data_word(0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0);
959#Td1:
960 &data_word(0xa7f45150, 0x65417e53, 0xa4171ac3, 0x5e273a96);
961 &data_word(0x6bab3bcb, 0x459d1ff1, 0x58faacab, 0x03e34b93);
962 &data_word(0xfa302055, 0x6d76adf6, 0x76cc8891, 0x4c02f525);
963 &data_word(0xd7e54ffc, 0xcb2ac5d7, 0x44352680, 0xa362b58f);
964 &data_word(0x5ab1de49, 0x1bba2567, 0x0eea4598, 0xc0fe5de1);
965 &data_word(0x752fc302, 0xf04c8112, 0x97468da3, 0xf9d36bc6);
966 &data_word(0x5f8f03e7, 0x9c921595, 0x7a6dbfeb, 0x595295da);
967 &data_word(0x83bed42d, 0x217458d3, 0x69e04929, 0xc8c98e44);
968 &data_word(0x89c2756a, 0x798ef478, 0x3e58996b, 0x71b927dd);
969 &data_word(0x4fe1beb6, 0xad88f017, 0xac20c966, 0x3ace7db4);
970 &data_word(0x4adf6318, 0x311ae582, 0x33519760, 0x7f536245);
971 &data_word(0x7764b1e0, 0xae6bbb84, 0xa081fe1c, 0x2b08f994);
972 &data_word(0x68487058, 0xfd458f19, 0x6cde9487, 0xf87b52b7);
973 &data_word(0xd373ab23, 0x024b72e2, 0x8f1fe357, 0xab55662a);
974 &data_word(0x28ebb207, 0xc2b52f03, 0x7bc5869a, 0x0837d3a5);
975 &data_word(0x872830f2, 0xa5bf23b2, 0x6a0302ba, 0x8216ed5c);
976 &data_word(0x1ccf8a2b, 0xb479a792, 0xf207f3f0, 0xe2694ea1);
977 &data_word(0xf4da65cd, 0xbe0506d5, 0x6234d11f, 0xfea6c48a);
978 &data_word(0x532e349d, 0x55f3a2a0, 0xe18a0532, 0xebf6a475);
979 &data_word(0xec830b39, 0xef6040aa, 0x9f715e06, 0x106ebd51);
980 &data_word(0x8a213ef9, 0x06dd963d, 0x053eddae, 0xbde64d46);
981 &data_word(0x8d5491b5, 0x5dc47105, 0xd406046f, 0x155060ff);
982 &data_word(0xfb981924, 0xe9bdd697, 0x434089cc, 0x9ed96777);
983 &data_word(0x42e8b0bd, 0x8b890788, 0x5b19e738, 0xeec879db);
984 &data_word(0x0a7ca147, 0x0f427ce9, 0x1e84f8c9, 0x00000000);
985 &data_word(0x86800983, 0xed2b3248, 0x70111eac, 0x725a6c4e);
986 &data_word(0xff0efdfb, 0x38850f56, 0xd5ae3d1e, 0x392d3627);
987 &data_word(0xd90f0a64, 0xa65c6821, 0x545b9bd1, 0x2e36243a);
988 &data_word(0x670a0cb1, 0xe757930f, 0x96eeb4d2, 0x919b1b9e);
989 &data_word(0xc5c0804f, 0x20dc61a2, 0x4b775a69, 0x1a121c16);
990 &data_word(0xba93e20a, 0x2aa0c0e5, 0xe0223c43, 0x171b121d);
991 &data_word(0x0d090e0b, 0xc78bf2ad, 0xa8b62db9, 0xa91e14c8);
992 &data_word(0x19f15785, 0x0775af4c, 0xdd99eebb, 0x607fa3fd);
993 &data_word(0x2601f79f, 0xf5725cbc, 0x3b6644c5, 0x7efb5b34);
994 &data_word(0x29438b76, 0xc623cbdc, 0xfcedb668, 0xf1e4b863);
995 &data_word(0xdc31d7ca, 0x85634210, 0x22971340, 0x11c68420);
996 &data_word(0x244a857d, 0x3dbbd2f8, 0x32f9ae11, 0xa129c76d);
997 &data_word(0x2f9e1d4b, 0x30b2dcf3, 0x52860dec, 0xe3c177d0);
998 &data_word(0x16b32b6c, 0xb970a999, 0x489411fa, 0x64e94722);
999 &data_word(0x8cfca8c4, 0x3ff0a01a, 0x2c7d56d8, 0x903322ef);
1000 &data_word(0x4e4987c7, 0xd138d9c1, 0xa2ca8cfe, 0x0bd49836);
1001 &data_word(0x81f5a6cf, 0xde7aa528, 0x8eb7da26, 0xbfad3fa4);
1002 &data_word(0x9d3a2ce4, 0x9278500d, 0xcc5f6a9b, 0x467e5462);
1003 &data_word(0x138df6c2, 0xb8d890e8, 0xf7392e5e, 0xafc382f5);
1004 &data_word(0x805d9fbe, 0x93d0697c, 0x2dd56fa9, 0x1225cfb3);
1005 &data_word(0x99acc83b, 0x7d1810a7, 0x639ce86e, 0xbb3bdb7b);
1006 &data_word(0x7826cd09, 0x18596ef4, 0xb79aec01, 0x9a4f83a8);
1007 &data_word(0x6e95e665, 0xe6ffaa7e, 0xcfbc2108, 0xe815efe6);
1008 &data_word(0x9be7bad9, 0x366f4ace, 0x099fead4, 0x7cb029d6);
1009 &data_word(0xb2a431af, 0x233f2a31, 0x94a5c630, 0x66a235c0);
1010 &data_word(0xbc4e7437, 0xca82fca6, 0xd090e0b0, 0xd8a73315);
1011 &data_word(0x9804f14a, 0xdaec41f7, 0x50cd7f0e, 0xf691172f);
1012 &data_word(0xd64d768d, 0xb0ef434d, 0x4daacc54, 0x0496e4df);
1013 &data_word(0xb5d19ee3, 0x886a4c1b, 0x1f2cc1b8, 0x5165467f);
1014 &data_word(0xea5e9d04, 0x358c015d, 0x7487fa73, 0x410bfb2e);
1015 &data_word(0x1d67b35a, 0xd2db9252, 0x5610e933, 0x47d66d13);
1016 &data_word(0x61d79a8c, 0x0ca1377a, 0x14f8598e, 0x3c13eb89);
1017 &data_word(0x27a9ceee, 0xc961b735, 0xe51ce1ed, 0xb1477a3c);
1018 &data_word(0xdfd29c59, 0x73f2553f, 0xce141879, 0x37c773bf);
1019 &data_word(0xcdf753ea, 0xaafd5f5b, 0x6f3ddf14, 0xdb447886);
1020 &data_word(0xf3afca81, 0xc468b93e, 0x3424382c, 0x40a3c25f);
1021 &data_word(0xc31d1672, 0x25e2bc0c, 0x493c288b, 0x950dff41);
1022 &data_word(0x01a83971, 0xb30c08de, 0xe4b4d89c, 0xc1566490);
1023 &data_word(0x84cb7b61, 0xb632d570, 0x5c6c4874, 0x57b8d042);
1024#Td2:
1025 &data_word(0xf45150a7, 0x417e5365, 0x171ac3a4, 0x273a965e);
1026 &data_word(0xab3bcb6b, 0x9d1ff145, 0xfaacab58, 0xe34b9303);
1027 &data_word(0x302055fa, 0x76adf66d, 0xcc889176, 0x02f5254c);
1028 &data_word(0xe54ffcd7, 0x2ac5d7cb, 0x35268044, 0x62b58fa3);
1029 &data_word(0xb1de495a, 0xba25671b, 0xea45980e, 0xfe5de1c0);
1030 &data_word(0x2fc30275, 0x4c8112f0, 0x468da397, 0xd36bc6f9);
1031 &data_word(0x8f03e75f, 0x9215959c, 0x6dbfeb7a, 0x5295da59);
1032 &data_word(0xbed42d83, 0x7458d321, 0xe0492969, 0xc98e44c8);
1033 &data_word(0xc2756a89, 0x8ef47879, 0x58996b3e, 0xb927dd71);
1034 &data_word(0xe1beb64f, 0x88f017ad, 0x20c966ac, 0xce7db43a);
1035 &data_word(0xdf63184a, 0x1ae58231, 0x51976033, 0x5362457f);
1036 &data_word(0x64b1e077, 0x6bbb84ae, 0x81fe1ca0, 0x08f9942b);
1037 &data_word(0x48705868, 0x458f19fd, 0xde94876c, 0x7b52b7f8);
1038 &data_word(0x73ab23d3, 0x4b72e202, 0x1fe3578f, 0x55662aab);
1039 &data_word(0xebb20728, 0xb52f03c2, 0xc5869a7b, 0x37d3a508);
1040 &data_word(0x2830f287, 0xbf23b2a5, 0x0302ba6a, 0x16ed5c82);
1041 &data_word(0xcf8a2b1c, 0x79a792b4, 0x07f3f0f2, 0x694ea1e2);
1042 &data_word(0xda65cdf4, 0x0506d5be, 0x34d11f62, 0xa6c48afe);
1043 &data_word(0x2e349d53, 0xf3a2a055, 0x8a0532e1, 0xf6a475eb);
1044 &data_word(0x830b39ec, 0x6040aaef, 0x715e069f, 0x6ebd5110);
1045 &data_word(0x213ef98a, 0xdd963d06, 0x3eddae05, 0xe64d46bd);
1046 &data_word(0x5491b58d, 0xc471055d, 0x06046fd4, 0x5060ff15);
1047 &data_word(0x981924fb, 0xbdd697e9, 0x4089cc43, 0xd967779e);
1048 &data_word(0xe8b0bd42, 0x8907888b, 0x19e7385b, 0xc879dbee);
1049 &data_word(0x7ca1470a, 0x427ce90f, 0x84f8c91e, 0x00000000);
1050 &data_word(0x80098386, 0x2b3248ed, 0x111eac70, 0x5a6c4e72);
1051 &data_word(0x0efdfbff, 0x850f5638, 0xae3d1ed5, 0x2d362739);
1052 &data_word(0x0f0a64d9, 0x5c6821a6, 0x5b9bd154, 0x36243a2e);
1053 &data_word(0x0a0cb167, 0x57930fe7, 0xeeb4d296, 0x9b1b9e91);
1054 &data_word(0xc0804fc5, 0xdc61a220, 0x775a694b, 0x121c161a);
1055 &data_word(0x93e20aba, 0xa0c0e52a, 0x223c43e0, 0x1b121d17);
1056 &data_word(0x090e0b0d, 0x8bf2adc7, 0xb62db9a8, 0x1e14c8a9);
1057 &data_word(0xf1578519, 0x75af4c07, 0x99eebbdd, 0x7fa3fd60);
1058 &data_word(0x01f79f26, 0x725cbcf5, 0x6644c53b, 0xfb5b347e);
1059 &data_word(0x438b7629, 0x23cbdcc6, 0xedb668fc, 0xe4b863f1);
1060 &data_word(0x31d7cadc, 0x63421085, 0x97134022, 0xc6842011);
1061 &data_word(0x4a857d24, 0xbbd2f83d, 0xf9ae1132, 0x29c76da1);
1062 &data_word(0x9e1d4b2f, 0xb2dcf330, 0x860dec52, 0xc177d0e3);
1063 &data_word(0xb32b6c16, 0x70a999b9, 0x9411fa48, 0xe9472264);
1064 &data_word(0xfca8c48c, 0xf0a01a3f, 0x7d56d82c, 0x3322ef90);
1065 &data_word(0x4987c74e, 0x38d9c1d1, 0xca8cfea2, 0xd498360b);
1066 &data_word(0xf5a6cf81, 0x7aa528de, 0xb7da268e, 0xad3fa4bf);
1067 &data_word(0x3a2ce49d, 0x78500d92, 0x5f6a9bcc, 0x7e546246);
1068 &data_word(0x8df6c213, 0xd890e8b8, 0x392e5ef7, 0xc382f5af);
1069 &data_word(0x5d9fbe80, 0xd0697c93, 0xd56fa92d, 0x25cfb312);
1070 &data_word(0xacc83b99, 0x1810a77d, 0x9ce86e63, 0x3bdb7bbb);
1071 &data_word(0x26cd0978, 0x596ef418, 0x9aec01b7, 0x4f83a89a);
1072 &data_word(0x95e6656e, 0xffaa7ee6, 0xbc2108cf, 0x15efe6e8);
1073 &data_word(0xe7bad99b, 0x6f4ace36, 0x9fead409, 0xb029d67c);
1074 &data_word(0xa431afb2, 0x3f2a3123, 0xa5c63094, 0xa235c066);
1075 &data_word(0x4e7437bc, 0x82fca6ca, 0x90e0b0d0, 0xa73315d8);
1076 &data_word(0x04f14a98, 0xec41f7da, 0xcd7f0e50, 0x91172ff6);
1077 &data_word(0x4d768dd6, 0xef434db0, 0xaacc544d, 0x96e4df04);
1078 &data_word(0xd19ee3b5, 0x6a4c1b88, 0x2cc1b81f, 0x65467f51);
1079 &data_word(0x5e9d04ea, 0x8c015d35, 0x87fa7374, 0x0bfb2e41);
1080 &data_word(0x67b35a1d, 0xdb9252d2, 0x10e93356, 0xd66d1347);
1081 &data_word(0xd79a8c61, 0xa1377a0c, 0xf8598e14, 0x13eb893c);
1082 &data_word(0xa9ceee27, 0x61b735c9, 0x1ce1ede5, 0x477a3cb1);
1083 &data_word(0xd29c59df, 0xf2553f73, 0x141879ce, 0xc773bf37);
1084 &data_word(0xf753eacd, 0xfd5f5baa, 0x3ddf146f, 0x447886db);
1085 &data_word(0xafca81f3, 0x68b93ec4, 0x24382c34, 0xa3c25f40);
1086 &data_word(0x1d1672c3, 0xe2bc0c25, 0x3c288b49, 0x0dff4195);
1087 &data_word(0xa8397101, 0x0c08deb3, 0xb4d89ce4, 0x566490c1);
1088 &data_word(0xcb7b6184, 0x32d570b6, 0x6c48745c, 0xb8d04257);
1089#Td3:
1090 &data_word(0x5150a7f4, 0x7e536541, 0x1ac3a417, 0x3a965e27);
1091 &data_word(0x3bcb6bab, 0x1ff1459d, 0xacab58fa, 0x4b9303e3);
1092 &data_word(0x2055fa30, 0xadf66d76, 0x889176cc, 0xf5254c02);
1093 &data_word(0x4ffcd7e5, 0xc5d7cb2a, 0x26804435, 0xb58fa362);
1094 &data_word(0xde495ab1, 0x25671bba, 0x45980eea, 0x5de1c0fe);
1095 &data_word(0xc302752f, 0x8112f04c, 0x8da39746, 0x6bc6f9d3);
1096 &data_word(0x03e75f8f, 0x15959c92, 0xbfeb7a6d, 0x95da5952);
1097 &data_word(0xd42d83be, 0x58d32174, 0x492969e0, 0x8e44c8c9);
1098 &data_word(0x756a89c2, 0xf478798e, 0x996b3e58, 0x27dd71b9);
1099 &data_word(0xbeb64fe1, 0xf017ad88, 0xc966ac20, 0x7db43ace);
1100 &data_word(0x63184adf, 0xe582311a, 0x97603351, 0x62457f53);
1101 &data_word(0xb1e07764, 0xbb84ae6b, 0xfe1ca081, 0xf9942b08);
1102 &data_word(0x70586848, 0x8f19fd45, 0x94876cde, 0x52b7f87b);
1103 &data_word(0xab23d373, 0x72e2024b, 0xe3578f1f, 0x662aab55);
1104 &data_word(0xb20728eb, 0x2f03c2b5, 0x869a7bc5, 0xd3a50837);
1105 &data_word(0x30f28728, 0x23b2a5bf, 0x02ba6a03, 0xed5c8216);
1106 &data_word(0x8a2b1ccf, 0xa792b479, 0xf3f0f207, 0x4ea1e269);
1107 &data_word(0x65cdf4da, 0x06d5be05, 0xd11f6234, 0xc48afea6);
1108 &data_word(0x349d532e, 0xa2a055f3, 0x0532e18a, 0xa475ebf6);
1109 &data_word(0x0b39ec83, 0x40aaef60, 0x5e069f71, 0xbd51106e);
1110 &data_word(0x3ef98a21, 0x963d06dd, 0xddae053e, 0x4d46bde6);
1111 &data_word(0x91b58d54, 0x71055dc4, 0x046fd406, 0x60ff1550);
1112 &data_word(0x1924fb98, 0xd697e9bd, 0x89cc4340, 0x67779ed9);
1113 &data_word(0xb0bd42e8, 0x07888b89, 0xe7385b19, 0x79dbeec8);
1114 &data_word(0xa1470a7c, 0x7ce90f42, 0xf8c91e84, 0x00000000);
1115 &data_word(0x09838680, 0x3248ed2b, 0x1eac7011, 0x6c4e725a);
1116 &data_word(0xfdfbff0e, 0x0f563885, 0x3d1ed5ae, 0x3627392d);
1117 &data_word(0x0a64d90f, 0x6821a65c, 0x9bd1545b, 0x243a2e36);
1118 &data_word(0x0cb1670a, 0x930fe757, 0xb4d296ee, 0x1b9e919b);
1119 &data_word(0x804fc5c0, 0x61a220dc, 0x5a694b77, 0x1c161a12);
1120 &data_word(0xe20aba93, 0xc0e52aa0, 0x3c43e022, 0x121d171b);
1121 &data_word(0x0e0b0d09, 0xf2adc78b, 0x2db9a8b6, 0x14c8a91e);
1122 &data_word(0x578519f1, 0xaf4c0775, 0xeebbdd99, 0xa3fd607f);
1123 &data_word(0xf79f2601, 0x5cbcf572, 0x44c53b66, 0x5b347efb);
1124 &data_word(0x8b762943, 0xcbdcc623, 0xb668fced, 0xb863f1e4);
1125 &data_word(0xd7cadc31, 0x42108563, 0x13402297, 0x842011c6);
1126 &data_word(0x857d244a, 0xd2f83dbb, 0xae1132f9, 0xc76da129);
1127 &data_word(0x1d4b2f9e, 0xdcf330b2, 0x0dec5286, 0x77d0e3c1);
1128 &data_word(0x2b6c16b3, 0xa999b970, 0x11fa4894, 0x472264e9);
1129 &data_word(0xa8c48cfc, 0xa01a3ff0, 0x56d82c7d, 0x22ef9033);
1130 &data_word(0x87c74e49, 0xd9c1d138, 0x8cfea2ca, 0x98360bd4);
1131 &data_word(0xa6cf81f5, 0xa528de7a, 0xda268eb7, 0x3fa4bfad);
1132 &data_word(0x2ce49d3a, 0x500d9278, 0x6a9bcc5f, 0x5462467e);
1133 &data_word(0xf6c2138d, 0x90e8b8d8, 0x2e5ef739, 0x82f5afc3);
1134 &data_word(0x9fbe805d, 0x697c93d0, 0x6fa92dd5, 0xcfb31225);
1135 &data_word(0xc83b99ac, 0x10a77d18, 0xe86e639c, 0xdb7bbb3b);
1136 &data_word(0xcd097826, 0x6ef41859, 0xec01b79a, 0x83a89a4f);
1137 &data_word(0xe6656e95, 0xaa7ee6ff, 0x2108cfbc, 0xefe6e815);
1138 &data_word(0xbad99be7, 0x4ace366f, 0xead4099f, 0x29d67cb0);
1139 &data_word(0x31afb2a4, 0x2a31233f, 0xc63094a5, 0x35c066a2);
1140 &data_word(0x7437bc4e, 0xfca6ca82, 0xe0b0d090, 0x3315d8a7);
1141 &data_word(0xf14a9804, 0x41f7daec, 0x7f0e50cd, 0x172ff691);
1142 &data_word(0x768dd64d, 0x434db0ef, 0xcc544daa, 0xe4df0496);
1143 &data_word(0x9ee3b5d1, 0x4c1b886a, 0xc1b81f2c, 0x467f5165);
1144 &data_word(0x9d04ea5e, 0x015d358c, 0xfa737487, 0xfb2e410b);
1145 &data_word(0xb35a1d67, 0x9252d2db, 0xe9335610, 0x6d1347d6);
1146 &data_word(0x9a8c61d7, 0x377a0ca1, 0x598e14f8, 0xeb893c13);
1147 &data_word(0xceee27a9, 0xb735c961, 0xe1ede51c, 0x7a3cb147);
1148 &data_word(0x9c59dfd2, 0x553f73f2, 0x1879ce14, 0x73bf37c7);
1149 &data_word(0x53eacdf7, 0x5f5baafd, 0xdf146f3d, 0x7886db44);
1150 &data_word(0xca81f3af, 0xb93ec468, 0x382c3424, 0xc25f40a3);
1151 &data_word(0x1672c31d, 0xbc0c25e2, 0x288b493c, 0xff41950d);
1152 &data_word(0x397101a8, 0x08deb30c, 0xd89ce4b4, 0x6490c156);
1153 &data_word(0x7b6184cb, 0xd570b632, 0x48745c6c, 0xd04257b8);
1154#Td4:
1155 &data_word(0x52525252, 0x09090909, 0x6a6a6a6a, 0xd5d5d5d5);
1156 &data_word(0x30303030, 0x36363636, 0xa5a5a5a5, 0x38383838);
1157 &data_word(0xbfbfbfbf, 0x40404040, 0xa3a3a3a3, 0x9e9e9e9e);
1158 &data_word(0x81818181, 0xf3f3f3f3, 0xd7d7d7d7, 0xfbfbfbfb);
1159 &data_word(0x7c7c7c7c, 0xe3e3e3e3, 0x39393939, 0x82828282);
1160 &data_word(0x9b9b9b9b, 0x2f2f2f2f, 0xffffffff, 0x87878787);
1161 &data_word(0x34343434, 0x8e8e8e8e, 0x43434343, 0x44444444);
1162 &data_word(0xc4c4c4c4, 0xdededede, 0xe9e9e9e9, 0xcbcbcbcb);
1163 &data_word(0x54545454, 0x7b7b7b7b, 0x94949494, 0x32323232);
1164 &data_word(0xa6a6a6a6, 0xc2c2c2c2, 0x23232323, 0x3d3d3d3d);
1165 &data_word(0xeeeeeeee, 0x4c4c4c4c, 0x95959595, 0x0b0b0b0b);
1166 &data_word(0x42424242, 0xfafafafa, 0xc3c3c3c3, 0x4e4e4e4e);
1167 &data_word(0x08080808, 0x2e2e2e2e, 0xa1a1a1a1, 0x66666666);
1168 &data_word(0x28282828, 0xd9d9d9d9, 0x24242424, 0xb2b2b2b2);
1169 &data_word(0x76767676, 0x5b5b5b5b, 0xa2a2a2a2, 0x49494949);
1170 &data_word(0x6d6d6d6d, 0x8b8b8b8b, 0xd1d1d1d1, 0x25252525);
1171 &data_word(0x72727272, 0xf8f8f8f8, 0xf6f6f6f6, 0x64646464);
1172 &data_word(0x86868686, 0x68686868, 0x98989898, 0x16161616);
1173 &data_word(0xd4d4d4d4, 0xa4a4a4a4, 0x5c5c5c5c, 0xcccccccc);
1174 &data_word(0x5d5d5d5d, 0x65656565, 0xb6b6b6b6, 0x92929292);
1175 &data_word(0x6c6c6c6c, 0x70707070, 0x48484848, 0x50505050);
1176 &data_word(0xfdfdfdfd, 0xedededed, 0xb9b9b9b9, 0xdadadada);
1177 &data_word(0x5e5e5e5e, 0x15151515, 0x46464646, 0x57575757);
1178 &data_word(0xa7a7a7a7, 0x8d8d8d8d, 0x9d9d9d9d, 0x84848484);
1179 &data_word(0x90909090, 0xd8d8d8d8, 0xabababab, 0x00000000);
1180 &data_word(0x8c8c8c8c, 0xbcbcbcbc, 0xd3d3d3d3, 0x0a0a0a0a);
1181 &data_word(0xf7f7f7f7, 0xe4e4e4e4, 0x58585858, 0x05050505);
1182 &data_word(0xb8b8b8b8, 0xb3b3b3b3, 0x45454545, 0x06060606);
1183 &data_word(0xd0d0d0d0, 0x2c2c2c2c, 0x1e1e1e1e, 0x8f8f8f8f);
1184 &data_word(0xcacacaca, 0x3f3f3f3f, 0x0f0f0f0f, 0x02020202);
1185 &data_word(0xc1c1c1c1, 0xafafafaf, 0xbdbdbdbd, 0x03030303);
1186 &data_word(0x01010101, 0x13131313, 0x8a8a8a8a, 0x6b6b6b6b);
1187 &data_word(0x3a3a3a3a, 0x91919191, 0x11111111, 0x41414141);
1188 &data_word(0x4f4f4f4f, 0x67676767, 0xdcdcdcdc, 0xeaeaeaea);
1189 &data_word(0x97979797, 0xf2f2f2f2, 0xcfcfcfcf, 0xcececece);
1190 &data_word(0xf0f0f0f0, 0xb4b4b4b4, 0xe6e6e6e6, 0x73737373);
1191 &data_word(0x96969696, 0xacacacac, 0x74747474, 0x22222222);
1192 &data_word(0xe7e7e7e7, 0xadadadad, 0x35353535, 0x85858585);
1193 &data_word(0xe2e2e2e2, 0xf9f9f9f9, 0x37373737, 0xe8e8e8e8);
1194 &data_word(0x1c1c1c1c, 0x75757575, 0xdfdfdfdf, 0x6e6e6e6e);
1195 &data_word(0x47474747, 0xf1f1f1f1, 0x1a1a1a1a, 0x71717171);
1196 &data_word(0x1d1d1d1d, 0x29292929, 0xc5c5c5c5, 0x89898989);
1197 &data_word(0x6f6f6f6f, 0xb7b7b7b7, 0x62626262, 0x0e0e0e0e);
1198 &data_word(0xaaaaaaaa, 0x18181818, 0xbebebebe, 0x1b1b1b1b);
1199 &data_word(0xfcfcfcfc, 0x56565656, 0x3e3e3e3e, 0x4b4b4b4b);
1200 &data_word(0xc6c6c6c6, 0xd2d2d2d2, 0x79797979, 0x20202020);
1201 &data_word(0x9a9a9a9a, 0xdbdbdbdb, 0xc0c0c0c0, 0xfefefefe);
1202 &data_word(0x78787878, 0xcdcdcdcd, 0x5a5a5a5a, 0xf4f4f4f4);
1203 &data_word(0x1f1f1f1f, 0xdddddddd, 0xa8a8a8a8, 0x33333333);
1204 &data_word(0x88888888, 0x07070707, 0xc7c7c7c7, 0x31313131);
1205 &data_word(0xb1b1b1b1, 0x12121212, 0x10101010, 0x59595959);
1206 &data_word(0x27272727, 0x80808080, 0xecececec, 0x5f5f5f5f);
1207 &data_word(0x60606060, 0x51515151, 0x7f7f7f7f, 0xa9a9a9a9);
1208 &data_word(0x19191919, 0xb5b5b5b5, 0x4a4a4a4a, 0x0d0d0d0d);
1209 &data_word(0x2d2d2d2d, 0xe5e5e5e5, 0x7a7a7a7a, 0x9f9f9f9f);
1210 &data_word(0x93939393, 0xc9c9c9c9, 0x9c9c9c9c, 0xefefefef);
1211 &data_word(0xa0a0a0a0, 0xe0e0e0e0, 0x3b3b3b3b, 0x4d4d4d4d);
1212 &data_word(0xaeaeaeae, 0x2a2a2a2a, 0xf5f5f5f5, 0xb0b0b0b0);
1213 &data_word(0xc8c8c8c8, 0xebebebeb, 0xbbbbbbbb, 0x3c3c3c3c);
1214 &data_word(0x83838383, 0x53535353, 0x99999999, 0x61616161);
1215 &data_word(0x17171717, 0x2b2b2b2b, 0x04040404, 0x7e7e7e7e);
1216 &data_word(0xbabababa, 0x77777777, 0xd6d6d6d6, 0x26262626);
1217 &data_word(0xe1e1e1e1, 0x69696969, 0x14141414, 0x63636363);
1218 &data_word(0x55555555, 0x21212121, 0x0c0c0c0c, 0x7d7d7d7d);
1219&function_end_B("AES_decrypt");
1220
1221sub enckey()
1222{
1223 &movz ("esi",&LB("edx")); # rk[i]>>0
1224 &mov ("ebx",&DWP(0,"ebp","esi",4));
1225 &movz ("esi",&HB("edx")); # rk[i]>>8
1226 &and ("ebx",0xFF000000);
1227 &xor ("eax","ebx");
1228
1229 &mov ("ebx",&DWP(0,"ebp","esi",4));
1230 &shr ("edx",16);
1231 &and ("ebx",0x000000FF);
1232 &movz ("esi",&LB("edx")); # rk[i]>>16
1233 &xor ("eax","ebx");
1234
1235 &mov ("ebx",&DWP(0,"ebp","esi",4));
1236 &movz ("esi",&HB("edx")); # rk[i]>>24
1237 &and ("ebx",0x0000FF00);
1238 &xor ("eax","ebx");
1239
1240 &mov ("ebx",&DWP(0,"ebp","esi",4));
1241 &and ("ebx",0x00FF0000);
1242 &xor ("eax","ebx");
1243
1244 &xor ("eax",&DWP(1024,"ebp","ecx",4)); # rcon
1245}
1246
1247# int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
1248# AES_KEY *key)
1249&public_label("AES_Te");
1250&function_begin("AES_set_encrypt_key");
1251 &mov ("esi",&wparam(0)); # user supplied key
1252 &mov ("edi",&wparam(2)); # private key schedule
1253
1254 &test ("esi",-1);
1255 &jz (&label("badpointer"));
1256 &test ("edi",-1);
1257 &jz (&label("badpointer"));
1258
1259 &call (&label("pic_point"));
1260 &set_label("pic_point");
1261 &blindpop("ebp");
1262 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
1263 &add ("ebp",1024*4); # skip to Te4
1264
1265 &mov ("ecx",&wparam(1)); # number of bits in key
1266 &cmp ("ecx",128);
1267 &je (&label("10rounds"));
1268 &cmp ("ecx",192);
1269 &je (&label("12rounds"));
1270 &cmp ("ecx",256);
1271 &je (&label("14rounds"));
1272 &mov ("eax",-2); # invalid number of bits
1273 &jmp (&label("exit"));
1274
1275 &set_label("10rounds");
1276 &mov ("eax",&DWP(0,"esi")); # copy first 4 dwords
1277 &mov ("ebx",&DWP(4,"esi"));
1278 &mov ("ecx",&DWP(8,"esi"));
1279 &mov ("edx",&DWP(12,"esi"));
1280 &mov (&DWP(0,"edi"),"eax");
1281 &mov (&DWP(4,"edi"),"ebx");
1282 &mov (&DWP(8,"edi"),"ecx");
1283 &mov (&DWP(12,"edi"),"edx");
1284
1285 &xor ("ecx","ecx");
1286 &jmp (&label("10shortcut"));
1287
1288 &align (4);
1289 &set_label("10loop");
1290 &mov ("eax",&DWP(0,"edi")); # rk[0]
1291 &mov ("edx",&DWP(12,"edi")); # rk[3]
1292 &set_label("10shortcut");
1293 &enckey ();
1294
1295 &mov (&DWP(16,"edi"),"eax"); # rk[4]
1296 &xor ("eax",&DWP(4,"edi"));
1297 &mov (&DWP(20,"edi"),"eax"); # rk[5]
1298 &xor ("eax",&DWP(8,"edi"));
1299 &mov (&DWP(24,"edi"),"eax"); # rk[6]
1300 &xor ("eax",&DWP(12,"edi"));
1301 &mov (&DWP(28,"edi"),"eax"); # rk[7]
1302 &inc ("ecx");
1303 &add ("edi",16);
1304 &cmp ("ecx",10);
1305 &jl (&label("10loop"));
1306
1307 &mov (&DWP(80,"edi"),10); # setup number of rounds
1308 &xor ("eax","eax");
1309 &jmp (&label("exit"));
1310
1311 &set_label("12rounds");
1312 &mov ("eax",&DWP(0,"esi")); # copy first 6 dwords
1313 &mov ("ebx",&DWP(4,"esi"));
1314 &mov ("ecx",&DWP(8,"esi"));
1315 &mov ("edx",&DWP(12,"esi"));
1316 &mov (&DWP(0,"edi"),"eax");
1317 &mov (&DWP(4,"edi"),"ebx");
1318 &mov (&DWP(8,"edi"),"ecx");
1319 &mov (&DWP(12,"edi"),"edx");
1320 &mov ("ecx",&DWP(16,"esi"));
1321 &mov ("edx",&DWP(20,"esi"));
1322 &mov (&DWP(16,"edi"),"ecx");
1323 &mov (&DWP(20,"edi"),"edx");
1324
1325 &xor ("ecx","ecx");
1326 &jmp (&label("12shortcut"));
1327
1328 &align (4);
1329 &set_label("12loop");
1330 &mov ("eax",&DWP(0,"edi")); # rk[0]
1331 &mov ("edx",&DWP(20,"edi")); # rk[5]
1332 &set_label("12shortcut");
1333 &enckey ();
1334
1335 &mov (&DWP(24,"edi"),"eax"); # rk[6]
1336 &xor ("eax",&DWP(4,"edi"));
1337 &mov (&DWP(28,"edi"),"eax"); # rk[7]
1338 &xor ("eax",&DWP(8,"edi"));
1339 &mov (&DWP(32,"edi"),"eax"); # rk[8]
1340 &xor ("eax",&DWP(12,"edi"));
1341 &mov (&DWP(36,"edi"),"eax"); # rk[9]
1342
1343 &cmp ("ecx",7);
1344 &je (&label("12break"));
1345 &inc ("ecx");
1346
1347 &xor ("eax",&DWP(16,"edi"));
1348 &mov (&DWP(40,"edi"),"eax"); # rk[10]
1349 &xor ("eax",&DWP(20,"edi"));
1350 &mov (&DWP(44,"edi"),"eax"); # rk[11]
1351
1352 &add ("edi",24);
1353 &jmp (&label("12loop"));
1354
1355 &set_label("12break");
1356 &mov (&DWP(72,"edi"),12); # setup number of rounds
1357 &xor ("eax","eax");
1358 &jmp (&label("exit"));
1359
1360 &set_label("14rounds");
1361 &mov ("eax",&DWP(0,"esi")); # copy first 8 dwords
1362 &mov ("ebx",&DWP(4,"esi"));
1363 &mov ("ecx",&DWP(8,"esi"));
1364 &mov ("edx",&DWP(12,"esi"));
1365 &mov (&DWP(0,"edi"),"eax");
1366 &mov (&DWP(4,"edi"),"ebx");
1367 &mov (&DWP(8,"edi"),"ecx");
1368 &mov (&DWP(12,"edi"),"edx");
1369 &mov ("eax",&DWP(16,"esi"));
1370 &mov ("ebx",&DWP(20,"esi"));
1371 &mov ("ecx",&DWP(24,"esi"));
1372 &mov ("edx",&DWP(28,"esi"));
1373 &mov (&DWP(16,"edi"),"eax");
1374 &mov (&DWP(20,"edi"),"ebx");
1375 &mov (&DWP(24,"edi"),"ecx");
1376 &mov (&DWP(28,"edi"),"edx");
1377
1378 &xor ("ecx","ecx");
1379 &jmp (&label("14shortcut"));
1380
1381 &align (4);
1382 &set_label("14loop");
1383 &mov ("edx",&DWP(28,"edi")); # rk[7]
1384 &set_label("14shortcut");
1385 &mov ("eax",&DWP(0,"edi")); # rk[0]
1386
1387 &enckey ();
1388
1389 &mov (&DWP(32,"edi"),"eax"); # rk[8]
1390 &xor ("eax",&DWP(4,"edi"));
1391 &mov (&DWP(36,"edi"),"eax"); # rk[9]
1392 &xor ("eax",&DWP(8,"edi"));
1393 &mov (&DWP(40,"edi"),"eax"); # rk[10]
1394 &xor ("eax",&DWP(12,"edi"));
1395 &mov (&DWP(44,"edi"),"eax"); # rk[11]
1396
1397 &cmp ("ecx",6);
1398 &je (&label("14break"));
1399 &inc ("ecx");
1400
1401 &mov ("edx","eax");
1402 &mov ("eax",&DWP(16,"edi")); # rk[4]
1403 &movz ("esi",&LB("edx")); # rk[11]>>0
1404 &mov ("ebx",&DWP(0,"ebp","esi",4));
1405 &movz ("esi",&HB("edx")); # rk[11]>>8
1406 &and ("ebx",0x000000FF);
1407 &xor ("eax","ebx");
1408
1409 &mov ("ebx",&DWP(0,"ebp","esi",4));
1410 &shr ("edx",16);
1411 &and ("ebx",0x0000FF00);
1412 &movz ("esi",&LB("edx")); # rk[11]>>16
1413 &xor ("eax","ebx");
1414
1415 &mov ("ebx",&DWP(0,"ebp","esi",4));
1416 &movz ("esi",&HB("edx")); # rk[11]>>24
1417 &and ("ebx",0x00FF0000);
1418 &xor ("eax","ebx");
1419
1420 &mov ("ebx",&DWP(0,"ebp","esi",4));
1421 &and ("ebx",0xFF000000);
1422 &xor ("eax","ebx");
1423
1424 &mov (&DWP(48,"edi"),"eax"); # rk[12]
1425 &xor ("eax",&DWP(20,"edi"));
1426 &mov (&DWP(52,"edi"),"eax"); # rk[13]
1427 &xor ("eax",&DWP(24,"edi"));
1428 &mov (&DWP(56,"edi"),"eax"); # rk[14]
1429 &xor ("eax",&DWP(28,"edi"));
1430 &mov (&DWP(60,"edi"),"eax"); # rk[15]
1431
1432 &add ("edi",32);
1433 &jmp (&label("14loop"));
1434
1435 &set_label("14break");
1436 &mov (&DWP(48,"edi"),14); # setup number of rounds
1437 &xor ("eax","eax");
1438 &jmp (&label("exit"));
1439
1440 &set_label("badpointer");
1441 &mov ("eax",-1);
1442 &set_label("exit");
1443&function_end("AES_set_encrypt_key");
1444
1445sub deckey()
1446{ my ($i,$ptr,$te4,$td) = @_;
1447
1448 &mov ("eax",&DWP($i,$ptr));
1449 &mov ("edx","eax");
1450 &movz ("ebx",&HB("eax"));
1451 &shr ("edx",16);
1452 &and ("eax",0xFF);
1453 &movz ("eax",&BP(0,$te4,"eax",4));
1454 &movz ("ebx",&BP(0,$te4,"ebx",4));
1455 &mov ("eax",&DWP(1024*0,$td,"eax",4));
1456 &xor ("eax",&DWP(1024*1,$td,"ebx",4));
1457 &movz ("ebx",&HB("edx"));
1458 &and ("edx",0xFF);
1459 &movz ("edx",&BP(0,$te4,"edx",4));
1460 &movz ("ebx",&BP(0,$te4,"ebx",4));
1461 &xor ("eax",&DWP(1024*2,$td,"edx",4));
1462 &xor ("eax",&DWP(1024*3,$td,"ebx",4));
1463 &mov (&DWP($i,$ptr),"eax");
1464}
1465
1466# int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
1467# AES_KEY *key)
1468&public_label("AES_Td");
1469&public_label("AES_Te");
1470&function_begin_B("AES_set_decrypt_key");
1471 &mov ("eax",&wparam(0));
1472 &mov ("ecx",&wparam(1));
1473 &mov ("edx",&wparam(2));
1474 &sub ("esp",12);
1475 &mov (&DWP(0,"esp"),"eax");
1476 &mov (&DWP(4,"esp"),"ecx");
1477 &mov (&DWP(8,"esp"),"edx");
1478 &call ("AES_set_encrypt_key");
1479 &add ("esp",12);
1480 &cmp ("eax",0);
1481 &je (&label("proceed"));
1482 &ret ();
1483
1484 &set_label("proceed");
1485 &push ("ebp");
1486 &push ("ebx");
1487 &push ("esi");
1488 &push ("edi");
1489
1490 &mov ("esi",&wparam(2));
1491 &mov ("ecx",&DWP(240,"esi")); # pull number of rounds
1492 &lea ("ecx",&DWP(0,"","ecx",4));
1493 &lea ("edi",&DWP(0,"esi","ecx",4)); # pointer to last chunk
1494
1495 &align (4);
1496 &set_label("invert"); # invert order of chunks
1497 &mov ("eax",&DWP(0,"esi"));
1498 &mov ("ebx",&DWP(4,"esi"));
1499 &mov ("ecx",&DWP(0,"edi"));
1500 &mov ("edx",&DWP(4,"edi"));
1501 &mov (&DWP(0,"edi"),"eax");
1502 &mov (&DWP(4,"edi"),"ebx");
1503 &mov (&DWP(0,"esi"),"ecx");
1504 &mov (&DWP(4,"esi"),"edx");
1505 &mov ("eax",&DWP(8,"esi"));
1506 &mov ("ebx",&DWP(12,"esi"));
1507 &mov ("ecx",&DWP(8,"edi"));
1508 &mov ("edx",&DWP(12,"edi"));
1509 &mov (&DWP(8,"edi"),"eax");
1510 &mov (&DWP(12,"edi"),"ebx");
1511 &mov (&DWP(8,"esi"),"ecx");
1512 &mov (&DWP(12,"esi"),"edx");
1513 &add ("esi",16);
1514 &sub ("edi",16);
1515 &cmp ("esi","edi");
1516 &jne (&label("invert"));
1517
1518 &call (&label("pic_point"));
1519 &set_label("pic_point");
1520 blindpop("ebp");
1521 &lea ("edi",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
1522 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
1523 &add ("ebp",1024*4); # skip to Te4
1524
1525 &mov ("esi",&wparam(2));
1526 &mov ("ecx",&DWP(240,"esi")); # pull number of rounds
1527 &dec ("ecx");
1528 &align (4);
1529 &set_label("permute"); # permute the key schedule
1530 &add ("esi",16);
1531 &deckey (0,"esi","ebp","edi");
1532 &deckey (4,"esi","ebp","edi");
1533 &deckey (8,"esi","ebp","edi");
1534 &deckey (12,"esi","ebp","edi");
1535 &dec ("ecx");
1536 &jnz (&label("permute"));
1537
1538 &xor ("eax","eax"); # return success
1539&function_end("AES_set_decrypt_key");
1540
1541&asm_finish();
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
deleted file mode 100644
index b81bf4fc81..0000000000
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ /dev/null
@@ -1,222 +0,0 @@
1/* crypto/asn1/a_bitstr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
64{ return M_ASN1_BIT_STRING_set(x, d, len); }
65
66int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
67 {
68 int ret,j,bits,len;
69 unsigned char *p,*d;
70
71 if (a == NULL) return(0);
72
73 len=a->length;
74
75 if (len > 0)
76 {
77 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT)
78 {
79 bits=(int)a->flags&0x07;
80 }
81 else
82 {
83 for ( ; len > 0; len--)
84 {
85 if (a->data[len-1]) break;
86 }
87 j=a->data[len-1];
88 if (j & 0x01) bits=0;
89 else if (j & 0x02) bits=1;
90 else if (j & 0x04) bits=2;
91 else if (j & 0x08) bits=3;
92 else if (j & 0x10) bits=4;
93 else if (j & 0x20) bits=5;
94 else if (j & 0x40) bits=6;
95 else if (j & 0x80) bits=7;
96 else bits=0; /* should not happen */
97 }
98 }
99 else
100 bits=0;
101
102 ret=1+len;
103 if (pp == NULL) return(ret);
104
105 p= *pp;
106
107 *(p++)=(unsigned char)bits;
108 d=a->data;
109 memcpy(p,d,len);
110 p+=len;
111 if (len > 0) p[-1]&=(0xff<<bits);
112 *pp=p;
113 return(ret);
114 }
115
116ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
117 long len)
118 {
119 ASN1_BIT_STRING *ret=NULL;
120 unsigned char *p,*s;
121 int i;
122
123 if (len < 1)
124 {
125 i=ASN1_R_STRING_TOO_SHORT;
126 goto err;
127 }
128
129 if ((a == NULL) || ((*a) == NULL))
130 {
131 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
132 }
133 else
134 ret=(*a);
135
136 p= *pp;
137 i= *(p++);
138 /* We do this to preserve the settings. If we modify
139 * the settings, via the _set_bit function, we will recalculate
140 * on output */
141 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
142 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
143
144 if (len-- > 1) /* using one because of the bits left byte */
145 {
146 s=(unsigned char *)OPENSSL_malloc((int)len);
147 if (s == NULL)
148 {
149 i=ERR_R_MALLOC_FAILURE;
150 goto err;
151 }
152 memcpy(s,p,(int)len);
153 s[len-1]&=(0xff<<i);
154 p+=len;
155 }
156 else
157 s=NULL;
158
159 ret->length=(int)len;
160 if (ret->data != NULL) OPENSSL_free(ret->data);
161 ret->data=s;
162 ret->type=V_ASN1_BIT_STRING;
163 if (a != NULL) (*a)=ret;
164 *pp=p;
165 return(ret);
166err:
167 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
168 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
169 M_ASN1_BIT_STRING_free(ret);
170 return(NULL);
171 }
172
173/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
174 */
175int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
176 {
177 int w,v,iv;
178 unsigned char *c;
179
180 w=n/8;
181 v=1<<(7-(n&0x07));
182 iv= ~v;
183 if (!value) v=0;
184
185 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
186
187 if (a == NULL) return(0);
188 if ((a->length < (w+1)) || (a->data == NULL))
189 {
190 if (!value) return(1); /* Don't need to set */
191 if (a->data == NULL)
192 c=(unsigned char *)OPENSSL_malloc(w+1);
193 else
194 c=(unsigned char *)OPENSSL_realloc_clean(a->data,
195 a->length,
196 w+1);
197 if (c == NULL)
198 {
199 ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT,ERR_R_MALLOC_FAILURE);
200 return 0;
201 }
202 if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length);
203 a->data=c;
204 a->length=w+1;
205 }
206 a->data[w]=((a->data[w])&iv)|v;
207 while ((a->length > 0) && (a->data[a->length-1] == 0))
208 a->length--;
209 return(1);
210 }
211
212int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
213 {
214 int w,v;
215
216 w=n/8;
217 v=1<<(7-(n&0x07));
218 if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL))
219 return(0);
220 return((a->data[w]&v) != 0);
221 }
222
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c
deleted file mode 100644
index 24333ea4d5..0000000000
--- a/src/lib/libcrypto/asn1/a_bool.c
+++ /dev/null
@@ -1,114 +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/asn1t.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 }
113
114
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
deleted file mode 100644
index 2407f7c87a..0000000000
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ /dev/null
@@ -1,312 +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.h>
62
63static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c);
64/* type is a 'bitmap' of acceptable string types.
65 */
66ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
67 long length, int type)
68 {
69 ASN1_STRING *ret=NULL;
70 unsigned char *p,*s;
71 long len;
72 int inf,tag,xclass;
73 int i=0;
74
75 p= *pp;
76 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
77 if (inf & 0x80) goto err;
78
79 if (tag >= 32)
80 {
81 i=ASN1_R_TAG_VALUE_TOO_HIGH;
82 goto err;
83 }
84 if (!(ASN1_tag2bit(tag) & type))
85 {
86 i=ASN1_R_WRONG_TYPE;
87 goto err;
88 }
89
90 /* If a bit-string, exit early */
91 if (tag == V_ASN1_BIT_STRING)
92 return(d2i_ASN1_BIT_STRING(a,pp,length));
93
94 if ((a == NULL) || ((*a) == NULL))
95 {
96 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
97 }
98 else
99 ret=(*a);
100
101 if (len != 0)
102 {
103 s=(unsigned char *)OPENSSL_malloc((int)len+1);
104 if (s == NULL)
105 {
106 i=ERR_R_MALLOC_FAILURE;
107 goto err;
108 }
109 memcpy(s,p,(int)len);
110 s[len]='\0';
111 p+=len;
112 }
113 else
114 s=NULL;
115
116 if (ret->data != NULL) OPENSSL_free(ret->data);
117 ret->length=(int)len;
118 ret->data=s;
119 ret->type=tag;
120 if (a != NULL) (*a)=ret;
121 *pp=p;
122 return(ret);
123err:
124 ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i);
125 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
126 ASN1_STRING_free(ret);
127 return(NULL);
128 }
129
130int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
131 {
132 int ret,r,constructed;
133 unsigned char *p;
134
135 if (a == NULL) return(0);
136
137 if (tag == V_ASN1_BIT_STRING)
138 return(i2d_ASN1_BIT_STRING(a,pp));
139
140 ret=a->length;
141 r=ASN1_object_size(0,ret,tag);
142 if (pp == NULL) return(r);
143 p= *pp;
144
145 if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
146 constructed=1;
147 else
148 constructed=0;
149 ASN1_put_object(&p,constructed,ret,tag,xclass);
150 memcpy(p,a->data,a->length);
151 p+=a->length;
152 *pp= p;
153 return(r);
154 }
155
156ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
157 int Ptag, int Pclass)
158 {
159 ASN1_STRING *ret=NULL;
160 unsigned char *p,*s;
161 long len;
162 int inf,tag,xclass;
163 int i=0;
164
165 if ((a == NULL) || ((*a) == NULL))
166 {
167 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
168 }
169 else
170 ret=(*a);
171
172 p= *pp;
173 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
174 if (inf & 0x80)
175 {
176 i=ASN1_R_BAD_OBJECT_HEADER;
177 goto err;
178 }
179
180 if (tag != Ptag)
181 {
182 i=ASN1_R_WRONG_TAG;
183 goto err;
184 }
185
186 if (inf & V_ASN1_CONSTRUCTED)
187 {
188 ASN1_CTX c;
189
190 c.pp=pp;
191 c.p=p;
192 c.inf=inf;
193 c.slen=len;
194 c.tag=Ptag;
195 c.xclass=Pclass;
196 c.max=(length == 0)?0:(p+length);
197 if (!asn1_collate_primitive(ret,&c))
198 goto err;
199 else
200 {
201 p=c.p;
202 }
203 }
204 else
205 {
206 if (len != 0)
207 {
208 if ((ret->length < len) || (ret->data == NULL))
209 {
210 if (ret->data != NULL) OPENSSL_free(ret->data);
211 s=(unsigned char *)OPENSSL_malloc((int)len + 1);
212 if (s == NULL)
213 {
214 i=ERR_R_MALLOC_FAILURE;
215 goto err;
216 }
217 }
218 else
219 s=ret->data;
220 memcpy(s,p,(int)len);
221 s[len] = '\0';
222 p+=len;
223 }
224 else
225 {
226 s=NULL;
227 if (ret->data != NULL) OPENSSL_free(ret->data);
228 }
229
230 ret->length=(int)len;
231 ret->data=s;
232 ret->type=Ptag;
233 }
234
235 if (a != NULL) (*a)=ret;
236 *pp=p;
237 return(ret);
238err:
239 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
240 ASN1_STRING_free(ret);
241 ASN1err(ASN1_F_D2I_ASN1_BYTES,i);
242 return(NULL);
243 }
244
245
246/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
247 * them into the one structure that is then returned */
248/* There have been a few bug fixes for this function from
249 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
250static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c)
251 {
252 ASN1_STRING *os=NULL;
253 BUF_MEM b;
254 int num;
255
256 b.length=0;
257 b.max=0;
258 b.data=NULL;
259
260 if (a == NULL)
261 {
262 c->error=ERR_R_PASSED_NULL_PARAMETER;
263 goto err;
264 }
265
266 num=0;
267 for (;;)
268 {
269 if (c->inf & 1)
270 {
271 c->eos=ASN1_check_infinite_end(&c->p,
272 (long)(c->max-c->p));
273 if (c->eos) break;
274 }
275 else
276 {
277 if (c->slen <= 0) break;
278 }
279
280 c->q=c->p;
281 if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass)
282 == NULL)
283 {
284 c->error=ERR_R_ASN1_LIB;
285 goto err;
286 }
287
288 if (!BUF_MEM_grow_clean(&b,num+os->length))
289 {
290 c->error=ERR_R_BUF_LIB;
291 goto err;
292 }
293 memcpy(&(b.data[num]),os->data,os->length);
294 if (!(c->inf & 1))
295 c->slen-=(c->p-c->q);
296 num+=os->length;
297 }
298
299 if (!asn1_Finish(c)) goto err;
300
301 a->length=num;
302 if (a->data != NULL) OPENSSL_free(a->data);
303 a->data=(unsigned char *)b.data;
304 if (os != NULL) ASN1_STRING_free(os);
305 return(1);
306err:
307 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
308 if (os != NULL) ASN1_STRING_free(os);
309 if (b.data != NULL) OPENSSL_free(b.data);
310 return(0);
311 }
312
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 b67b75e7c2..0000000000
--- a/src/lib/libcrypto/asn1/a_d2i_fp.c
+++ /dev/null
@@ -1,262 +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
64static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
65
66#ifndef NO_OLD_ASN1
67#ifndef OPENSSL_NO_FP_API
68
69char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
70 unsigned char **x)
71 {
72 BIO *b;
73 char *ret;
74
75 if ((b=BIO_new(BIO_s_file())) == NULL)
76 {
77 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
78 return(NULL);
79 }
80 BIO_set_fp(b,in,BIO_NOCLOSE);
81 ret=ASN1_d2i_bio(xnew,d2i,b,x);
82 BIO_free(b);
83 return(ret);
84 }
85#endif
86
87char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
88 unsigned char **x)
89 {
90 BUF_MEM *b = NULL;
91 unsigned char *p;
92 char *ret=NULL;
93 int len;
94
95 len = asn1_d2i_read_bio(in, &b);
96 if(len < 0) goto err;
97
98 p=(unsigned char *)b->data;
99 ret=d2i(x,&p,len);
100err:
101 if (b != NULL) BUF_MEM_free(b);
102 return(ret);
103 }
104
105#endif
106
107void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
108 {
109 BUF_MEM *b = NULL;
110 unsigned char *p;
111 void *ret=NULL;
112 int len;
113
114 len = asn1_d2i_read_bio(in, &b);
115 if(len < 0) goto err;
116
117 p=(unsigned char *)b->data;
118 ret=ASN1_item_d2i(x,&p,len, it);
119err:
120 if (b != NULL) BUF_MEM_free(b);
121 return(ret);
122 }
123
124#ifndef OPENSSL_NO_FP_API
125void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
126 {
127 BIO *b;
128 char *ret;
129
130 if ((b=BIO_new(BIO_s_file())) == NULL)
131 {
132 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
133 return(NULL);
134 }
135 BIO_set_fp(b,in,BIO_NOCLOSE);
136 ret=ASN1_item_d2i_bio(it,b,x);
137 BIO_free(b);
138 return(ret);
139 }
140#endif
141
142#define HEADER_SIZE 8
143static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
144 {
145 BUF_MEM *b;
146 unsigned char *p;
147 int i;
148 int ret=-1;
149 ASN1_CTX c;
150 int want=HEADER_SIZE;
151 int eos=0;
152#if defined(__GNUC__) && defined(__ia64)
153 /* pathetic compiler bug in all known versions as of Nov. 2002 */
154 long off=0;
155#else
156 int off=0;
157#endif
158 int len=0;
159
160 b=BUF_MEM_new();
161 if (b == NULL)
162 {
163 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
164 return -1;
165 }
166
167 ERR_clear_error();
168 for (;;)
169 {
170 if (want >= (len-off))
171 {
172 want-=(len-off);
173
174 if (!BUF_MEM_grow_clean(b,len+want))
175 {
176 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
177 goto err;
178 }
179 i=BIO_read(in,&(b->data[len]),want);
180 if ((i < 0) && ((len-off) == 0))
181 {
182 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
183 goto err;
184 }
185 if (i > 0)
186 len+=i;
187 }
188 /* else data already loaded */
189
190 p=(unsigned char *)&(b->data[off]);
191 c.p=p;
192 c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass),
193 len-off);
194 if (c.inf & 0x80)
195 {
196 unsigned long e;
197
198 e=ERR_GET_REASON(ERR_peek_error());
199 if (e != ASN1_R_TOO_LONG)
200 goto err;
201 else
202 ERR_get_error(); /* clear error */
203 }
204 i=c.p-p;/* header length */
205 off+=i; /* end of data */
206
207 if (c.inf & 1)
208 {
209 /* no data body so go round again */
210 eos++;
211 want=HEADER_SIZE;
212 }
213 else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC))
214 {
215 /* eos value, so go back and read another header */
216 eos--;
217 if (eos <= 0)
218 break;
219 else
220 want=HEADER_SIZE;
221 }
222 else
223 {
224 /* suck in c.slen bytes of data */
225 want=(int)c.slen;
226 if (want > (len-off))
227 {
228 want-=(len-off);
229 if (!BUF_MEM_grow_clean(b,len+want))
230 {
231 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
232 goto err;
233 }
234 while (want > 0)
235 {
236 i=BIO_read(in,&(b->data[len]),want);
237 if (i <= 0)
238 {
239 ASN1err(ASN1_F_ASN1_D2I_BIO,
240 ASN1_R_NOT_ENOUGH_DATA);
241 goto err;
242 }
243 len+=i;
244 want -= i;
245 }
246 }
247 off+=(int)c.slen;
248 if (eos <= 0)
249 {
250 break;
251 }
252 else
253 want=HEADER_SIZE;
254 }
255 }
256
257 *pb = b;
258 return off;
259err:
260 if (b != NULL) BUF_MEM_free(b);
261 return(ret);
262 }
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
deleted file mode 100644
index 7182e9fa5d..0000000000
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ /dev/null
@@ -1,111 +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/err.h>
69#include <openssl/evp.h>
70#include <openssl/buffer.h>
71#include <openssl/x509.h>
72
73#ifndef NO_ASN1_OLD
74
75int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
76 unsigned char *md, unsigned int *len)
77 {
78 int i;
79 unsigned char *str,*p;
80
81 i=i2d(data,NULL);
82 if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL)
83 {
84 ASN1err(ASN1_F_ASN1_DIGEST,ERR_R_MALLOC_FAILURE);
85 return(0);
86 }
87 p=str;
88 i2d(data,&p);
89
90 EVP_Digest(str, i, md, len, type, NULL);
91 OPENSSL_free(str);
92 return(1);
93 }
94
95#endif
96
97
98int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
99 unsigned char *md, unsigned int *len)
100 {
101 int i;
102 unsigned char *str = NULL;
103
104 i=ASN1_item_i2d(asn,&str, it);
105 if (!str) return(0);
106
107 EVP_Digest(str, i, md, len, type, NULL);
108 OPENSSL_free(str);
109 return(1);
110 }
111
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
deleted file mode 100644
index 58a017884c..0000000000
--- a/src/lib/libcrypto/asn1/a_dup.c
+++ /dev/null
@@ -1,107 +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.h>
62
63#ifndef NO_OLD_ASN1
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 *)OPENSSL_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 OPENSSL_free(b);
82 return(ret);
83 }
84
85#endif
86
87/* ASN1_ITEM version of dup: this follows the model above except we don't need
88 * to allocate the buffer. At some point this could be rewritten to directly dup
89 * the underlying structure instead of doing and encode and decode.
90 */
91
92void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
93 {
94 unsigned char *b = NULL, *p;
95 long i;
96 void *ret;
97
98 if (x == NULL) return(NULL);
99
100 i=ASN1_item_i2d(x,&b,it);
101 if (b == NULL)
102 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
103 p= b;
104 ret=ASN1_item_d2i(NULL,&p,i, it);
105 OPENSSL_free(b);
106 return(ret);
107 }
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
deleted file mode 100644
index 03ede68d1c..0000000000
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ /dev/null
@@ -1,180 +0,0 @@
1/* crypto/asn1/a_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/*
64 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
65 * for comments on encoding see a_int.c
66 */
67
68int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
69 {
70 int i,j,k;
71 unsigned char buf[sizeof(long)+1];
72 long d;
73
74 a->type=V_ASN1_ENUMERATED;
75 if (a->length < (sizeof(long)+1))
76 {
77 if (a->data != NULL)
78 OPENSSL_free(a->data);
79 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL)
80 memset((char *)a->data,0,sizeof(long)+1);
81 }
82 if (a->data == NULL)
83 {
84 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
85 return(0);
86 }
87 d=v;
88 if (d < 0)
89 {
90 d= -d;
91 a->type=V_ASN1_NEG_ENUMERATED;
92 }
93
94 for (i=0; i<sizeof(long); i++)
95 {
96 if (d == 0) break;
97 buf[i]=(int)d&0xff;
98 d>>=8;
99 }
100 j=0;
101 for (k=i-1; k >=0; k--)
102 a->data[j++]=buf[k];
103 a->length=j;
104 return(1);
105 }
106
107long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
108 {
109 int neg=0,i;
110 long r=0;
111
112 if (a == NULL) return(0L);
113 i=a->type;
114 if (i == V_ASN1_NEG_ENUMERATED)
115 neg=1;
116 else if (i != V_ASN1_ENUMERATED)
117 return -1;
118
119 if (a->length > sizeof(long))
120 {
121 /* hmm... a bit ugly */
122 return(0xffffffffL);
123 }
124 if (a->data == NULL)
125 return 0;
126
127 for (i=0; i<a->length; i++)
128 {
129 r<<=8;
130 r|=(unsigned char)a->data[i];
131 }
132 if (neg) r= -r;
133 return(r);
134 }
135
136ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
137 {
138 ASN1_ENUMERATED *ret;
139 int len,j;
140
141 if (ai == NULL)
142 ret=M_ASN1_ENUMERATED_new();
143 else
144 ret=ai;
145 if (ret == NULL)
146 {
147 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
148 goto err;
149 }
150 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
151 else ret->type=V_ASN1_ENUMERATED;
152 j=BN_num_bits(bn);
153 len=((j == 0)?0:((j/8)+1));
154 if (ret->length < len+4)
155 {
156 unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
157 if (!new_data)
158 {
159 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
160 goto err;
161 }
162 ret->data=new_data;
163 }
164
165 ret->length=BN_bn2bin(bn,ret->data);
166 return(ret);
167err:
168 if (ret != ai) M_ASN1_ENUMERATED_free(ret);
169 return(NULL);
170 }
171
172BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
173 {
174 BIGNUM *ret;
175
176 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
177 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
178 else if(ai->type == V_ASN1_NEG_ENUMERATED) ret->neg = 1;
179 return(ret);
180 }
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 f4f1b73ebe..0000000000
--- a/src/lib/libcrypto/asn1/a_i2d_fp.c
+++ /dev/null
@@ -1,163 +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.h>
63
64#ifndef NO_OLD_ASN1
65
66#ifndef OPENSSL_NO_FP_API
67int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x)
68 {
69 BIO *b;
70 int ret;
71
72 if ((b=BIO_new(BIO_s_file())) == NULL)
73 {
74 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
75 return(0);
76 }
77 BIO_set_fp(b,out,BIO_NOCLOSE);
78 ret=ASN1_i2d_bio(i2d,b,x);
79 BIO_free(b);
80 return(ret);
81 }
82#endif
83
84int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x)
85 {
86 char *b;
87 unsigned char *p;
88 int i,j=0,n,ret=1;
89
90 n=i2d(x,NULL);
91 b=(char *)OPENSSL_malloc(n);
92 if (b == NULL)
93 {
94 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
95 return(0);
96 }
97
98 p=(unsigned char *)b;
99 i2d(x,&p);
100
101 for (;;)
102 {
103 i=BIO_write(out,&(b[j]),n);
104 if (i == n) break;
105 if (i <= 0)
106 {
107 ret=0;
108 break;
109 }
110 j+=i;
111 n-=i;
112 }
113 OPENSSL_free(b);
114 return(ret);
115 }
116
117#endif
118
119#ifndef OPENSSL_NO_FP_API
120int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
121 {
122 BIO *b;
123 int ret;
124
125 if ((b=BIO_new(BIO_s_file())) == NULL)
126 {
127 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
128 return(0);
129 }
130 BIO_set_fp(b,out,BIO_NOCLOSE);
131 ret=ASN1_item_i2d_bio(it,b,x);
132 BIO_free(b);
133 return(ret);
134 }
135#endif
136
137int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
138 {
139 unsigned char *b = NULL;
140 int i,j=0,n,ret=1;
141
142 n = ASN1_item_i2d(x, &b, it);
143 if (b == NULL)
144 {
145 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
146 return(0);
147 }
148
149 for (;;)
150 {
151 i=BIO_write(out,&(b[j]),n);
152 if (i == n) break;
153 if (i <= 0)
154 {
155 ret=0;
156 break;
157 }
158 j+=i;
159 n-=i;
160 }
161 OPENSSL_free(b);
162 return(ret);
163 }
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
deleted file mode 100644
index 21cc64bb23..0000000000
--- a/src/lib/libcrypto/asn1/a_int.c
+++ /dev/null
@@ -1,453 +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_dup(ASN1_INTEGER *x)
64{ return M_ASN1_INTEGER_dup(x);}
65
66int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y)
67 {
68 int neg, ret;
69 /* Compare signs */
70 neg = x->type & V_ASN1_NEG;
71 if (neg != (y->type & V_ASN1_NEG))
72 {
73 if (neg)
74 return -1;
75 else
76 return 1;
77 }
78
79 ret = ASN1_STRING_cmp(x, y);
80
81 if (neg)
82 return -ret;
83 else
84 return ret;
85 }
86
87
88/*
89 * This converts an ASN1 INTEGER into its content encoding.
90 * The internal representation is an ASN1_STRING whose data is a big endian
91 * representation of the value, ignoring the sign. The sign is determined by
92 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
93 *
94 * Positive integers are no problem: they are almost the same as the DER
95 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
96 *
97 * Negative integers are a bit trickier...
98 * The DER representation of negative integers is in 2s complement form.
99 * The internal form is converted by complementing each octet and finally
100 * adding one to the result. This can be done less messily with a little trick.
101 * If the internal form has trailing zeroes then they will become FF by the
102 * complement and 0 by the add one (due to carry) so just copy as many trailing
103 * zeros to the destination as there are in the source. The carry will add one
104 * to the last none zero octet: so complement this octet and add one and finally
105 * complement any left over until you get to the start of the string.
106 *
107 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad
108 * with 0xff. However if the first byte is 0x80 and one of the following bytes
109 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80
110 * followed by optional zeros isn't padded.
111 */
112
113int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
114 {
115 int pad=0,ret,i,neg;
116 unsigned char *p,*n,pb=0;
117
118 if ((a == NULL) || (a->data == NULL)) return(0);
119 neg=a->type & V_ASN1_NEG;
120 if (a->length == 0)
121 ret=1;
122 else
123 {
124 ret=a->length;
125 i=a->data[0];
126 if (!neg && (i > 127)) {
127 pad=1;
128 pb=0;
129 } else if(neg) {
130 if(i>128) {
131 pad=1;
132 pb=0xFF;
133 } else if(i == 128) {
134 /*
135 * Special case: if any other bytes non zero we pad:
136 * otherwise we don't.
137 */
138 for(i = 1; i < a->length; i++) if(a->data[i]) {
139 pad=1;
140 pb=0xFF;
141 break;
142 }
143 }
144 }
145 ret+=pad;
146 }
147 if (pp == NULL) return(ret);
148 p= *pp;
149
150 if (pad) *(p++)=pb;
151 if (a->length == 0) *(p++)=0;
152 else if (!neg) memcpy(p,a->data,(unsigned int)a->length);
153 else {
154 /* Begin at the end of the encoding */
155 n=a->data + a->length - 1;
156 p += a->length - 1;
157 i = a->length;
158 /* Copy zeros to destination as long as source is zero */
159 while(!*n) {
160 *(p--) = 0;
161 n--;
162 i--;
163 }
164 /* Complement and increment next octet */
165 *(p--) = ((*(n--)) ^ 0xff) + 1;
166 i--;
167 /* Complement any octets left */
168 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
169 }
170
171 *pp+=ret;
172 return(ret);
173 }
174
175/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
176
177ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
178 long len)
179 {
180 ASN1_INTEGER *ret=NULL;
181 unsigned char *p,*to,*s, *pend;
182 int i;
183
184 if ((a == NULL) || ((*a) == NULL))
185 {
186 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
187 ret->type=V_ASN1_INTEGER;
188 }
189 else
190 ret=(*a);
191
192 p= *pp;
193 pend = p + len;
194
195 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it
196 * signifies a missing NULL parameter. */
197 s=(unsigned char *)OPENSSL_malloc((int)len+1);
198 if (s == NULL)
199 {
200 i=ERR_R_MALLOC_FAILURE;
201 goto err;
202 }
203 to=s;
204 if(!len) {
205 /* Strictly speaking this is an illegal INTEGER but we
206 * tolerate it.
207 */
208 ret->type=V_ASN1_INTEGER;
209 } else if (*p & 0x80) /* a negative number */
210 {
211 ret->type=V_ASN1_NEG_INTEGER;
212 if ((*p == 0xff) && (len != 1)) {
213 p++;
214 len--;
215 }
216 i = len;
217 p += i - 1;
218 to += i - 1;
219 while((!*p) && i) {
220 *(to--) = 0;
221 i--;
222 p--;
223 }
224 /* Special case: if all zeros then the number will be of
225 * the form FF followed by n zero bytes: this corresponds to
226 * 1 followed by n zero bytes. We've already written n zeros
227 * so we just append an extra one and set the first byte to
228 * a 1. This is treated separately because it is the only case
229 * where the number of bytes is larger than len.
230 */
231 if(!i) {
232 *s = 1;
233 s[len] = 0;
234 len++;
235 } else {
236 *(to--) = (*(p--) ^ 0xff) + 1;
237 i--;
238 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
239 }
240 } else {
241 ret->type=V_ASN1_INTEGER;
242 if ((*p == 0) && (len != 1))
243 {
244 p++;
245 len--;
246 }
247 memcpy(s,p,(int)len);
248 }
249
250 if (ret->data != NULL) OPENSSL_free(ret->data);
251 ret->data=s;
252 ret->length=(int)len;
253 if (a != NULL) (*a)=ret;
254 *pp=pend;
255 return(ret);
256err:
257 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
258 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
259 M_ASN1_INTEGER_free(ret);
260 return(NULL);
261 }
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 OPENSSL_malloc stuff, even for 0 bytes otherwise it
301 * signifies a missing NULL parameter. */
302 s=(unsigned char *)OPENSSL_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) OPENSSL_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 OPENSSL_free(a->data);
344 if ((a->data=(unsigned char *)OPENSSL_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 -1;
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 if (ret->length < len+4)
420 {
421 unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
422 if (!new_data)
423 {
424 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
425 goto err;
426 }
427 ret->data=new_data;
428 }
429 ret->length=BN_bn2bin(bn,ret->data);
430 /* Correct zero case */
431 if(!ret->length)
432 {
433 ret->data[0] = 0;
434 ret->length = 1;
435 }
436 return(ret);
437err:
438 if (ret != ai) M_ASN1_INTEGER_free(ret);
439 return(NULL);
440 }
441
442BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
443 {
444 BIGNUM *ret;
445
446 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
447 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
448 else if(ai->type == V_ASN1_NEG_INTEGER) ret->neg = 1;
449 return(ret);
450 }
451
452IMPLEMENT_STACK_OF(ASN1_INTEGER)
453IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER)
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
deleted file mode 100644
index 208b3ec395..0000000000
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ /dev/null
@@ -1,400 +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 char free_out;
96 int outform, outlen;
97 ASN1_STRING *dest;
98 unsigned char *p;
99 int nchar;
100 char strbuf[32];
101 int (*cpyfunc)(unsigned long,void *) = NULL;
102 if(len == -1) len = strlen((const char *)in);
103 if(!mask) mask = DIRSTRING_TYPE;
104
105 /* First do a string check and work out the number of characters */
106 switch(inform) {
107
108 case MBSTRING_BMP:
109 if(len & 1) {
110 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
111 ASN1_R_INVALID_BMPSTRING_LENGTH);
112 return -1;
113 }
114 nchar = len >> 1;
115 break;
116
117 case MBSTRING_UNIV:
118 if(len & 3) {
119 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
120 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
121 return -1;
122 }
123 nchar = len >> 2;
124 break;
125
126 case MBSTRING_UTF8:
127 nchar = 0;
128 /* This counts the characters and does utf8 syntax checking */
129 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
130 if(ret < 0) {
131 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
132 ASN1_R_INVALID_UTF8STRING);
133 return -1;
134 }
135 break;
136
137 case MBSTRING_ASC:
138 nchar = len;
139 break;
140
141 default:
142 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT);
143 return -1;
144 }
145
146 if((minsize > 0) && (nchar < minsize)) {
147 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT);
148 BIO_snprintf(strbuf, sizeof strbuf, "%ld", minsize);
149 ERR_add_error_data(2, "minsize=", strbuf);
150 return -1;
151 }
152
153 if((maxsize > 0) && (nchar > maxsize)) {
154 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG);
155 BIO_snprintf(strbuf, sizeof strbuf, "%ld", maxsize);
156 ERR_add_error_data(2, "maxsize=", strbuf);
157 return -1;
158 }
159
160 /* Now work out minimal type (if any) */
161 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
162 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS);
163 return -1;
164 }
165
166
167 /* Now work out output format and string type */
168 outform = MBSTRING_ASC;
169 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
170 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
171 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
172 else if(mask & B_ASN1_BMPSTRING) {
173 str_type = V_ASN1_BMPSTRING;
174 outform = MBSTRING_BMP;
175 } else if(mask & B_ASN1_UNIVERSALSTRING) {
176 str_type = V_ASN1_UNIVERSALSTRING;
177 outform = MBSTRING_UNIV;
178 } else {
179 str_type = V_ASN1_UTF8STRING;
180 outform = MBSTRING_UTF8;
181 }
182 if(!out) return str_type;
183 if(*out) {
184 free_out = 0;
185 dest = *out;
186 if(dest->data) {
187 dest->length = 0;
188 OPENSSL_free(dest->data);
189 dest->data = NULL;
190 }
191 dest->type = str_type;
192 } else {
193 free_out = 1;
194 dest = ASN1_STRING_type_new(str_type);
195 if(!dest) {
196 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
197 ERR_R_MALLOC_FAILURE);
198 return -1;
199 }
200 *out = dest;
201 }
202 /* If both the same type just copy across */
203 if(inform == outform) {
204 if(!ASN1_STRING_set(dest, in, len)) {
205 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
206 return -1;
207 }
208 return str_type;
209 }
210
211 /* Work out how much space the destination will need */
212 switch(outform) {
213 case MBSTRING_ASC:
214 outlen = nchar;
215 cpyfunc = cpy_asc;
216 break;
217
218 case MBSTRING_BMP:
219 outlen = nchar << 1;
220 cpyfunc = cpy_bmp;
221 break;
222
223 case MBSTRING_UNIV:
224 outlen = nchar << 2;
225 cpyfunc = cpy_univ;
226 break;
227
228 case MBSTRING_UTF8:
229 outlen = 0;
230 traverse_string(in, len, inform, out_utf8, &outlen);
231 cpyfunc = cpy_utf8;
232 break;
233 }
234 if(!(p = OPENSSL_malloc(outlen + 1))) {
235 if(free_out) ASN1_STRING_free(dest);
236 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
237 return -1;
238 }
239 dest->length = outlen;
240 dest->data = p;
241 p[outlen] = 0;
242 traverse_string(in, len, inform, cpyfunc, &p);
243 return str_type;
244}
245
246/* This function traverses a string and passes the value of each character
247 * to an optional function along with a void * argument.
248 */
249
250static int traverse_string(const unsigned char *p, int len, int inform,
251 int (*rfunc)(unsigned long value, void *in), void *arg)
252{
253 unsigned long value;
254 int ret;
255 while(len) {
256 if(inform == MBSTRING_ASC) {
257 value = *p++;
258 len--;
259 } else if(inform == MBSTRING_BMP) {
260 value = *p++ << 8;
261 value |= *p++;
262 len -= 2;
263 } else if(inform == MBSTRING_UNIV) {
264 value = ((unsigned long)*p++) << 24;
265 value |= ((unsigned long)*p++) << 16;
266 value |= *p++ << 8;
267 value |= *p++;
268 len -= 4;
269 } else {
270 ret = UTF8_getc(p, len, &value);
271 if(ret < 0) return -1;
272 len -= ret;
273 p += ret;
274 }
275 if(rfunc) {
276 ret = rfunc(value, arg);
277 if(ret <= 0) return ret;
278 }
279 }
280 return 1;
281}
282
283/* Various utility functions for traverse_string */
284
285/* Just count number of characters */
286
287static int in_utf8(unsigned long value, void *arg)
288{
289 int *nchar;
290 nchar = arg;
291 (*nchar)++;
292 return 1;
293}
294
295/* Determine size of output as a UTF8 String */
296
297static int out_utf8(unsigned long value, void *arg)
298{
299 int *outlen;
300 outlen = arg;
301 *outlen += UTF8_putc(NULL, -1, value);
302 return 1;
303}
304
305/* Determine the "type" of a string: check each character against a
306 * supplied "mask".
307 */
308
309static int type_str(unsigned long value, void *arg)
310{
311 unsigned long types;
312 types = *((unsigned long *)arg);
313 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
314 types &= ~B_ASN1_PRINTABLESTRING;
315 if((types & B_ASN1_IA5STRING) && (value > 127))
316 types &= ~B_ASN1_IA5STRING;
317 if((types & B_ASN1_T61STRING) && (value > 0xff))
318 types &= ~B_ASN1_T61STRING;
319 if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
320 types &= ~B_ASN1_BMPSTRING;
321 if(!types) return -1;
322 *((unsigned long *)arg) = types;
323 return 1;
324}
325
326/* Copy one byte per character ASCII like strings */
327
328static int cpy_asc(unsigned long value, void *arg)
329{
330 unsigned char **p, *q;
331 p = arg;
332 q = *p;
333 *q = (unsigned char) value;
334 (*p)++;
335 return 1;
336}
337
338/* Copy two byte per character BMPStrings */
339
340static int cpy_bmp(unsigned long value, void *arg)
341{
342 unsigned char **p, *q;
343 p = arg;
344 q = *p;
345 *q++ = (unsigned char) ((value >> 8) & 0xff);
346 *q = (unsigned char) (value & 0xff);
347 *p += 2;
348 return 1;
349}
350
351/* Copy four byte per character UniversalStrings */
352
353static int cpy_univ(unsigned long value, void *arg)
354{
355 unsigned char **p, *q;
356 p = arg;
357 q = *p;
358 *q++ = (unsigned char) ((value >> 24) & 0xff);
359 *q++ = (unsigned char) ((value >> 16) & 0xff);
360 *q++ = (unsigned char) ((value >> 8) & 0xff);
361 *q = (unsigned char) (value & 0xff);
362 *p += 4;
363 return 1;
364}
365
366/* Copy to a UTF8String */
367
368static int cpy_utf8(unsigned long value, void *arg)
369{
370 unsigned char **p;
371 int ret;
372 p = arg;
373 /* We already know there is enough room so pass 0xff as the length */
374 ret = UTF8_putc(*p, 0xff, value);
375 *p += ret;
376 return 1;
377}
378
379/* Return 1 if the character is permitted in a PrintableString */
380static int is_printable(unsigned long value)
381{
382 int ch;
383 if(value > 0x7f) return 0;
384 ch = (int) value;
385 /* Note: we can't use 'isalnum' because certain accented
386 * characters may count as alphanumeric in some environments.
387 */
388#ifndef CHARSET_EBCDIC
389 if((ch >= 'a') && (ch <= 'z')) return 1;
390 if((ch >= 'A') && (ch <= 'Z')) return 1;
391 if((ch >= '0') && (ch <= '9')) return 1;
392 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
393#else /*CHARSET_EBCDIC*/
394 if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1;
395 if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1;
396 if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1;
397 if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1;
398#endif /*CHARSET_EBCDIC*/
399 return 0;
400}
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
deleted file mode 100644
index 0a8e6c287c..0000000000
--- a/src/lib/libcrypto/asn1/a_object.c
+++ /dev/null
@@ -1,320 +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 int objsize;
69
70 if ((a == NULL) || (a->data == NULL)) return(0);
71
72 objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT);
73 if (pp == NULL) return objsize;
74
75 p= *pp;
76 ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
77 memcpy(p,a->data,a->length);
78 p+=a->length;
79
80 *pp=p;
81 return(objsize);
82 }
83
84int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
85 {
86 int i,first,len=0,c;
87 char tmp[24];
88 const char *p;
89 unsigned long l;
90
91 if (num == 0)
92 return(0);
93 else if (num == -1)
94 num=strlen(buf);
95
96 p=buf;
97 c= *(p++);
98 num--;
99 if ((c >= '0') && (c <= '2'))
100 {
101 first=(c-'0')*40;
102 }
103 else
104 {
105 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
106 goto err;
107 }
108
109 if (num <= 0)
110 {
111 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
112 goto err;
113 }
114 c= *(p++);
115 num--;
116 for (;;)
117 {
118 if (num <= 0) break;
119 if ((c != '.') && (c != ' '))
120 {
121 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
122 goto err;
123 }
124 l=0;
125 for (;;)
126 {
127 if (num <= 0) break;
128 num--;
129 c= *(p++);
130 if ((c == ' ') || (c == '.'))
131 break;
132 if ((c < '0') || (c > '9'))
133 {
134 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
135 goto err;
136 }
137 l=l*10L+(long)(c-'0');
138 }
139 if (len == 0)
140 {
141 if ((first < 2) && (l >= 40))
142 {
143 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
144 goto err;
145 }
146 l+=(long)first;
147 }
148 i=0;
149 for (;;)
150 {
151 tmp[i++]=(unsigned char)l&0x7f;
152 l>>=7L;
153 if (l == 0L) break;
154 }
155 if (out != NULL)
156 {
157 if (len+i > olen)
158 {
159 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
160 goto err;
161 }
162 while (--i > 0)
163 out[len++]=tmp[i]|0x80;
164 out[len++]=tmp[0];
165 }
166 else
167 len+=i;
168 }
169 return(len);
170err:
171 return(0);
172 }
173
174int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
175{
176 return OBJ_obj2txt(buf, buf_len, a, 0);
177}
178
179int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
180 {
181 char buf[80];
182 int i;
183
184 if ((a == NULL) || (a->data == NULL))
185 return(BIO_write(bp,"NULL",4));
186 i=i2t_ASN1_OBJECT(buf,sizeof buf,a);
187 if (i > sizeof buf) i=sizeof buf;
188 BIO_write(bp,buf,i);
189 return(i);
190 }
191
192ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
193 long length)
194{
195 unsigned char *p;
196 long len;
197 int tag,xclass;
198 int inf,i;
199 ASN1_OBJECT *ret = NULL;
200 p= *pp;
201 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
202 if (inf & 0x80)
203 {
204 i=ASN1_R_BAD_OBJECT_HEADER;
205 goto err;
206 }
207
208 if (tag != V_ASN1_OBJECT)
209 {
210 i=ASN1_R_EXPECTING_AN_OBJECT;
211 goto err;
212 }
213 ret = c2i_ASN1_OBJECT(a, &p, len);
214 if(ret) *pp = p;
215 return ret;
216err:
217 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
218 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
219 ASN1_OBJECT_free(ret);
220 return(NULL);
221}
222ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
223 long len)
224 {
225 ASN1_OBJECT *ret=NULL;
226 unsigned char *p;
227 int i;
228
229 /* only the ASN1_OBJECTs from the 'table' will have values
230 * for ->sn or ->ln */
231 if ((a == NULL) || ((*a) == NULL) ||
232 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
233 {
234 if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
235 }
236 else ret=(*a);
237
238 p= *pp;
239 if ((ret->data == NULL) || (ret->length < len))
240 {
241 if (ret->data != NULL) OPENSSL_free(ret->data);
242 ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1);
243 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
244 if (ret->data == NULL)
245 { i=ERR_R_MALLOC_FAILURE; goto err; }
246 }
247 memcpy(ret->data,p,(int)len);
248 ret->length=(int)len;
249 ret->sn=NULL;
250 ret->ln=NULL;
251 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
252 p+=len;
253
254 if (a != NULL) (*a)=ret;
255 *pp=p;
256 return(ret);
257err:
258 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
259 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
260 ASN1_OBJECT_free(ret);
261 return(NULL);
262 }
263
264ASN1_OBJECT *ASN1_OBJECT_new(void)
265 {
266 ASN1_OBJECT *ret;
267
268 ret=(ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT));
269 if (ret == NULL)
270 {
271 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
272 return(NULL);
273 }
274 ret->length=0;
275 ret->data=NULL;
276 ret->nid=0;
277 ret->sn=NULL;
278 ret->ln=NULL;
279 ret->flags=ASN1_OBJECT_FLAG_DYNAMIC;
280 return(ret);
281 }
282
283void ASN1_OBJECT_free(ASN1_OBJECT *a)
284 {
285 if (a == NULL) return;
286 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
287 {
288#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
289 if (a->sn != NULL) OPENSSL_free((void *)a->sn);
290 if (a->ln != NULL) OPENSSL_free((void *)a->ln);
291#endif
292 a->sn=a->ln=NULL;
293 }
294 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
295 {
296 if (a->data != NULL) OPENSSL_free(a->data);
297 a->data=NULL;
298 a->length=0;
299 }
300 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
301 OPENSSL_free(a);
302 }
303
304ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
305 const char *sn, const char *ln)
306 {
307 ASN1_OBJECT o;
308
309 o.sn=sn;
310 o.ln=ln;
311 o.data=data;
312 o.nid=nid;
313 o.length=len;
314 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
315 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
316 return(OBJ_dup(&o));
317 }
318
319IMPLEMENT_STACK_OF(ASN1_OBJECT)
320IMPLEMENT_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 9690bae0f1..0000000000
--- a/src/lib/libcrypto/asn1/a_octet.c
+++ /dev/null
@@ -1,71 +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_dup(ASN1_OCTET_STRING *x)
64{ return M_ASN1_OCTET_STRING_dup(x); }
65
66int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b)
67{ return M_ASN1_OCTET_STRING_cmp(a, b); }
68
69int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len)
70{ return M_ASN1_OCTET_STRING_set(x, d, len); }
71
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c
deleted file mode 100644
index d18e772320..0000000000
--- a/src/lib/libcrypto/asn1/a_print.c
+++ /dev/null
@@ -1,127 +0,0 @@
1/* crypto/asn1/a_print.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63int ASN1_PRINTABLE_type(const unsigned char *s, int len)
64 {
65 int c;
66 int ia5=0;
67 int t61=0;
68
69 if (len <= 0) len= -1;
70 if (s == NULL) return(V_ASN1_PRINTABLESTRING);
71
72 while ((*s) && (len-- != 0))
73 {
74 c= *(s++);
75#ifndef CHARSET_EBCDIC
76 if (!( ((c >= 'a') && (c <= 'z')) ||
77 ((c >= 'A') && (c <= 'Z')) ||
78 (c == ' ') ||
79 ((c >= '0') && (c <= '9')) ||
80 (c == ' ') || (c == '\'') ||
81 (c == '(') || (c == ')') ||
82 (c == '+') || (c == ',') ||
83 (c == '-') || (c == '.') ||
84 (c == '/') || (c == ':') ||
85 (c == '=') || (c == '?')))
86 ia5=1;
87 if (c&0x80)
88 t61=1;
89#else
90 if (!isalnum(c) && (c != ' ') &&
91 strchr("'()+,-./:=?", c) == NULL)
92 ia5=1;
93 if (os_toascii[c] & 0x80)
94 t61=1;
95#endif
96 }
97 if (t61) return(V_ASN1_T61STRING);
98 if (ia5) return(V_ASN1_IA5STRING);
99 return(V_ASN1_PRINTABLESTRING);
100 }
101
102int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
103 {
104 int i;
105 unsigned char *p;
106
107 if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
108 if ((s->length%4) != 0) return(0);
109 p=s->data;
110 for (i=0; i<s->length; i+=4)
111 {
112 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
113 break;
114 else
115 p+=4;
116 }
117 if (i < s->length) return(0);
118 p=s->data;
119 for (i=3; i<s->length; i+=4)
120 {
121 *(p++)=s->data[i];
122 }
123 *(p)='\0';
124 s->length/=4;
125 s->type=ASN1_PRINTABLE_type(s->data,s->length);
126 return(1);
127 }
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
deleted file mode 100644
index e24061c545..0000000000
--- a/src/lib/libcrypto/asn1/a_set.c
+++ /dev/null
@@ -1,235 +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
63#ifndef NO_ASN1_OLD
64
65typedef struct
66 {
67 unsigned char *pbData;
68 int cbData;
69 } MYBLOB;
70
71/* SetBlobCmp
72 * This function compares two elements of SET_OF block
73 */
74static int SetBlobCmp(const void *elem1, const void *elem2 )
75 {
76 const MYBLOB *b1 = (const MYBLOB *)elem1;
77 const MYBLOB *b2 = (const MYBLOB *)elem2;
78 int r;
79
80 r = memcmp(b1->pbData, b2->pbData,
81 b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
82 if(r != 0)
83 return r;
84 return b1->cbData-b2->cbData;
85 }
86
87/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
88int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,
89 int ex_class, int is_set)
90 {
91 int ret=0,r;
92 int i;
93 unsigned char *p;
94 unsigned char *pStart, *pTempMem;
95 MYBLOB *rgSetBlob;
96 int totSize;
97
98 if (a == NULL) return(0);
99 for (i=sk_num(a)-1; i>=0; i--)
100 ret+=func(sk_value(a,i),NULL);
101 r=ASN1_object_size(1,ret,ex_tag);
102 if (pp == NULL) return(r);
103
104 p= *pp;
105 ASN1_put_object(&p,1,ret,ex_tag,ex_class);
106
107/* Modified by gp@nsj.co.jp */
108 /* And then again by Ben */
109 /* And again by Steve */
110
111 if(!is_set || (sk_num(a) < 2))
112 {
113 for (i=0; i<sk_num(a); i++)
114 func(sk_value(a,i),&p);
115
116 *pp=p;
117 return(r);
118 }
119
120 pStart = p; /* Catch the beg of Setblobs*/
121 /* In this array we will store the SET blobs */
122 rgSetBlob = (MYBLOB *)OPENSSL_malloc(sk_num(a) * sizeof(MYBLOB));
123 if (rgSetBlob == NULL)
124 {
125 ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE);
126 return(0);
127 }
128
129 for (i=0; i<sk_num(a); i++)
130 {
131 rgSetBlob[i].pbData = p; /* catch each set encode blob */
132 func(sk_value(a,i),&p);
133 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
134SetBlob
135*/
136 }
137 *pp=p;
138 totSize = p - pStart; /* This is the total size of all set blobs */
139
140 /* Now we have to sort the blobs. I am using a simple algo.
141 *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/
142 qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);
143 if (!(pTempMem = OPENSSL_malloc(totSize)))
144 {
145 ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE);
146 return(0);
147 }
148
149/* Copy to temp mem */
150 p = pTempMem;
151 for(i=0; i<sk_num(a); ++i)
152 {
153 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
154 p += rgSetBlob[i].cbData;
155 }
156
157/* Copy back to user mem*/
158 memcpy(pStart, pTempMem, totSize);
159 OPENSSL_free(pTempMem);
160 OPENSSL_free(rgSetBlob);
161
162 return(r);
163 }
164
165STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
166 char *(*func)(), void (*free_func)(void *), int ex_tag, int ex_class)
167 {
168 ASN1_CTX c;
169 STACK *ret=NULL;
170
171 if ((a == NULL) || ((*a) == NULL))
172 {
173 if ((ret=sk_new_null()) == NULL)
174 {
175 ASN1err(ASN1_F_D2I_ASN1_SET,ERR_R_MALLOC_FAILURE);
176 goto err;
177 }
178 }
179 else
180 ret=(*a);
181
182 c.p= *pp;
183 c.max=(length == 0)?0:(c.p+length);
184
185 c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);
186 if (c.inf & 0x80) goto err;
187 if (ex_class != c.xclass)
188 {
189 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);
190 goto err;
191 }
192 if (ex_tag != c.tag)
193 {
194 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);
195 goto err;
196 }
197 if ((c.slen+c.p) > c.max)
198 {
199 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);
200 goto err;
201 }
202 /* check for infinite constructed - it can be as long
203 * as the amount of data passed to us */
204 if (c.inf == (V_ASN1_CONSTRUCTED+1))
205 c.slen=length+ *pp-c.p;
206 c.max=c.p+c.slen;
207
208 while (c.p < c.max)
209 {
210 char *s;
211
212 if (M_ASN1_D2I_end_sequence()) break;
213 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
214 {
215 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
216 asn1_add_error(*pp,(int)(c.q- *pp));
217 goto err;
218 }
219 if (!sk_push(ret,s)) goto err;
220 }
221 if (a != NULL) (*a)=ret;
222 *pp=c.p;
223 return(ret);
224err:
225 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
226 {
227 if (free_func != NULL)
228 sk_pop_free(ret,free_func);
229 else
230 sk_free(ret);
231 }
232 return(NULL);
233 }
234
235#endif
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
deleted file mode 100644
index 52ce7e3974..0000000000
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ /dev/null
@@ -1,294 +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 * Copyright (c) 1998-2002 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
115#include "cryptlib.h"
116
117#ifndef NO_SYS_TYPES_H
118# include <sys/types.h>
119#endif
120
121#include <openssl/bn.h>
122#include <openssl/evp.h>
123#include <openssl/x509.h>
124#include <openssl/objects.h>
125#include <openssl/buffer.h>
126
127#ifndef NO_ASN1_OLD
128
129int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
130 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
131 const EVP_MD *type)
132 {
133 EVP_MD_CTX ctx;
134 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
135 int i,inl=0,outl=0,outll=0;
136 X509_ALGOR *a;
137
138 EVP_MD_CTX_init(&ctx);
139 for (i=0; i<2; i++)
140 {
141 if (i == 0)
142 a=algor1;
143 else
144 a=algor2;
145 if (a == NULL) continue;
146 if (type->pkey_type == NID_dsaWithSHA1)
147 {
148 /* special case: RFC 2459 tells us to omit 'parameters'
149 * with id-dsa-with-sha1 */
150 ASN1_TYPE_free(a->parameter);
151 a->parameter = NULL;
152 }
153 else if ((a->parameter == NULL) ||
154 (a->parameter->type != V_ASN1_NULL))
155 {
156 ASN1_TYPE_free(a->parameter);
157 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
158 a->parameter->type=V_ASN1_NULL;
159 }
160 ASN1_OBJECT_free(a->algorithm);
161 a->algorithm=OBJ_nid2obj(type->pkey_type);
162 if (a->algorithm == NULL)
163 {
164 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
165 goto err;
166 }
167 if (a->algorithm->length == 0)
168 {
169 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
170 goto err;
171 }
172 }
173 inl=i2d(data,NULL);
174 buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl);
175 outll=outl=EVP_PKEY_size(pkey);
176 buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
177 if ((buf_in == NULL) || (buf_out == NULL))
178 {
179 outl=0;
180 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
181 goto err;
182 }
183 p=buf_in;
184
185 i2d(data,&p);
186 EVP_SignInit_ex(&ctx,type, NULL);
187 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
188 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
189 (unsigned int *)&outl,pkey))
190 {
191 outl=0;
192 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
193 goto err;
194 }
195 if (signature->data != NULL) OPENSSL_free(signature->data);
196 signature->data=buf_out;
197 buf_out=NULL;
198 signature->length=outl;
199 /* In the interests of compatibility, I'll make sure that
200 * the bit string has a 'not-used bits' value of 0
201 */
202 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
203 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
204err:
205 EVP_MD_CTX_cleanup(&ctx);
206 if (buf_in != NULL)
207 { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); }
208 if (buf_out != NULL)
209 { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); }
210 return(outl);
211 }
212
213#endif
214
215int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
216 ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey,
217 const EVP_MD *type)
218 {
219 EVP_MD_CTX ctx;
220 unsigned char *buf_in=NULL,*buf_out=NULL;
221 int i,inl=0,outl=0,outll=0;
222 X509_ALGOR *a;
223
224 EVP_MD_CTX_init(&ctx);
225 for (i=0; i<2; i++)
226 {
227 if (i == 0)
228 a=algor1;
229 else
230 a=algor2;
231 if (a == NULL) continue;
232 if (type->pkey_type == NID_dsaWithSHA1)
233 {
234 /* special case: RFC 2459 tells us to omit 'parameters'
235 * with id-dsa-with-sha1 */
236 ASN1_TYPE_free(a->parameter);
237 a->parameter = NULL;
238 }
239 else if ((a->parameter == NULL) ||
240 (a->parameter->type != V_ASN1_NULL))
241 {
242 ASN1_TYPE_free(a->parameter);
243 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
244 a->parameter->type=V_ASN1_NULL;
245 }
246 ASN1_OBJECT_free(a->algorithm);
247 a->algorithm=OBJ_nid2obj(type->pkey_type);
248 if (a->algorithm == NULL)
249 {
250 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
251 goto err;
252 }
253 if (a->algorithm->length == 0)
254 {
255 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
256 goto err;
257 }
258 }
259 inl=ASN1_item_i2d(asn,&buf_in, it);
260 outll=outl=EVP_PKEY_size(pkey);
261 buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl);
262 if ((buf_in == NULL) || (buf_out == NULL))
263 {
264 outl=0;
265 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
266 goto err;
267 }
268
269 EVP_SignInit_ex(&ctx,type, NULL);
270 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
271 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
272 (unsigned int *)&outl,pkey))
273 {
274 outl=0;
275 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
276 goto err;
277 }
278 if (signature->data != NULL) OPENSSL_free(signature->data);
279 signature->data=buf_out;
280 buf_out=NULL;
281 signature->length=outl;
282 /* In the interests of compatibility, I'll make sure that
283 * the bit string has a 'not-used bits' value of 0
284 */
285 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
286 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
287err:
288 EVP_MD_CTX_cleanup(&ctx);
289 if (buf_in != NULL)
290 { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); }
291 if (buf_out != NULL)
292 { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); }
293 return(outl);
294 }
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
deleted file mode 100644
index a07122ba47..0000000000
--- a/src/lib/libcrypto/asn1/a_strex.c
+++ /dev/null
@@ -1,567 +0,0 @@
1/* a_strex.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/crypto.h>
62#include <openssl/x509.h>
63#include <openssl/asn1.h>
64
65#include "charmap.h"
66#include "cryptlib.h"
67
68/* ASN1_STRING_print_ex() and X509_NAME_print_ex().
69 * Enhanced string and name printing routines handling
70 * multibyte characters, RFC2253 and a host of other
71 * options.
72 */
73
74
75#define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253)
76
77
78/* Three IO functions for sending data to memory, a BIO and
79 * and a FILE pointer.
80 */
81#if 0 /* never used */
82static int send_mem_chars(void *arg, const void *buf, int len)
83{
84 unsigned char **out = arg;
85 if(!out) return 1;
86 memcpy(*out, buf, len);
87 *out += len;
88 return 1;
89}
90#endif
91
92static int send_bio_chars(void *arg, const void *buf, int len)
93{
94 if(!arg) return 1;
95 if(BIO_write(arg, buf, len) != len) return 0;
96 return 1;
97}
98
99static int send_fp_chars(void *arg, const void *buf, int len)
100{
101 if(!arg) return 1;
102 if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0;
103 return 1;
104}
105
106typedef int char_io(void *arg, const void *buf, int len);
107
108/* This function handles display of
109 * strings, one character at a time.
110 * It is passed an unsigned long for each
111 * character because it could come from 2 or even
112 * 4 byte forms.
113 */
114
115static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg)
116{
117 unsigned char chflgs, chtmp;
118 char tmphex[HEX_SIZE(long)+3];
119
120 if(c > 0xffffffffL)
121 return -1;
122 if(c > 0xffff) {
123 BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c);
124 if(!io_ch(arg, tmphex, 10)) return -1;
125 return 10;
126 }
127 if(c > 0xff) {
128 BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c);
129 if(!io_ch(arg, tmphex, 6)) return -1;
130 return 6;
131 }
132 chtmp = (unsigned char)c;
133 if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB;
134 else chflgs = char_type[chtmp] & flags;
135 if(chflgs & CHARTYPE_BS_ESC) {
136 /* If we don't escape with quotes, signal we need quotes */
137 if(chflgs & ASN1_STRFLGS_ESC_QUOTE) {
138 if(do_quotes) *do_quotes = 1;
139 if(!io_ch(arg, &chtmp, 1)) return -1;
140 return 1;
141 }
142 if(!io_ch(arg, "\\", 1)) return -1;
143 if(!io_ch(arg, &chtmp, 1)) return -1;
144 return 2;
145 }
146 if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) {
147 BIO_snprintf(tmphex, 11, "\\%02X", chtmp);
148 if(!io_ch(arg, tmphex, 3)) return -1;
149 return 3;
150 }
151 if(!io_ch(arg, &chtmp, 1)) return -1;
152 return 1;
153}
154
155#define BUF_TYPE_WIDTH_MASK 0x7
156#define BUF_TYPE_CONVUTF8 0x8
157
158/* This function sends each character in a buffer to
159 * do_esc_char(). It interprets the content formats
160 * and converts to or from UTF8 as appropriate.
161 */
162
163static int do_buf(unsigned char *buf, int buflen,
164 int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg)
165{
166 int i, outlen, len;
167 unsigned char orflags, *p, *q;
168 unsigned long c;
169 p = buf;
170 q = buf + buflen;
171 outlen = 0;
172 while(p != q) {
173 if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
174 else orflags = 0;
175 switch(type & BUF_TYPE_WIDTH_MASK) {
176 case 4:
177 c = ((unsigned long)*p++) << 24;
178 c |= ((unsigned long)*p++) << 16;
179 c |= ((unsigned long)*p++) << 8;
180 c |= *p++;
181 break;
182
183 case 2:
184 c = ((unsigned long)*p++) << 8;
185 c |= *p++;
186 break;
187
188 case 1:
189 c = *p++;
190 break;
191
192 case 0:
193 i = UTF8_getc(p, buflen, &c);
194 if(i < 0) return -1; /* Invalid UTF8String */
195 p += i;
196 break;
197 }
198 if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
199 if(type & BUF_TYPE_CONVUTF8) {
200 unsigned char utfbuf[6];
201 int utflen;
202 utflen = UTF8_putc(utfbuf, sizeof utfbuf, c);
203 for(i = 0; i < utflen; i++) {
204 /* We don't need to worry about setting orflags correctly
205 * because if utflen==1 its value will be correct anyway
206 * otherwise each character will be > 0x7f and so the
207 * character will never be escaped on first and last.
208 */
209 len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg);
210 if(len < 0) return -1;
211 outlen += len;
212 }
213 } else {
214 len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg);
215 if(len < 0) return -1;
216 outlen += len;
217 }
218 }
219 return outlen;
220}
221
222/* This function hex dumps a buffer of characters */
223
224static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
225{
226 const static char hexdig[] = "0123456789ABCDEF";
227 unsigned char *p, *q;
228 char hextmp[2];
229 if(arg) {
230 p = buf;
231 q = buf + buflen;
232 while(p != q) {
233 hextmp[0] = hexdig[*p >> 4];
234 hextmp[1] = hexdig[*p & 0xf];
235 if(!io_ch(arg, hextmp, 2)) return -1;
236 p++;
237 }
238 }
239 return buflen << 1;
240}
241
242/* "dump" a string. This is done when the type is unknown,
243 * or the flags request it. We can either dump the content
244 * octets or the entire DER encoding. This uses the RFC2253
245 * #01234 format.
246 */
247
248static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str)
249{
250 /* Placing the ASN1_STRING in a temp ASN1_TYPE allows
251 * the DER encoding to readily obtained
252 */
253 ASN1_TYPE t;
254 unsigned char *der_buf, *p;
255 int outlen, der_len;
256
257 if(!io_ch(arg, "#", 1)) return -1;
258 /* If we don't dump DER encoding just dump content octets */
259 if(!(lflags & ASN1_STRFLGS_DUMP_DER)) {
260 outlen = do_hex_dump(io_ch, arg, str->data, str->length);
261 if(outlen < 0) return -1;
262 return outlen + 1;
263 }
264 t.type = str->type;
265 t.value.ptr = (char *)str;
266 der_len = i2d_ASN1_TYPE(&t, NULL);
267 der_buf = OPENSSL_malloc(der_len);
268 if(!der_buf) return -1;
269 p = der_buf;
270 i2d_ASN1_TYPE(&t, &p);
271 outlen = do_hex_dump(io_ch, arg, der_buf, der_len);
272 OPENSSL_free(der_buf);
273 if(outlen < 0) return -1;
274 return outlen + 1;
275}
276
277/* Lookup table to convert tags to character widths,
278 * 0 = UTF8 encoded, -1 is used for non string types
279 * otherwise it is the number of bytes per character
280 */
281
282const static signed char tag2nbyte[] = {
283 -1, -1, -1, -1, -1, /* 0-4 */
284 -1, -1, -1, -1, -1, /* 5-9 */
285 -1, -1, 0, -1, /* 10-13 */
286 -1, -1, -1, -1, /* 15-17 */
287 -1, 1, 1, /* 18-20 */
288 -1, 1, 1, 1, /* 21-24 */
289 -1, 1, -1, /* 25-27 */
290 4, -1, 2 /* 28-30 */
291};
292
293#define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \
294 ASN1_STRFLGS_ESC_QUOTE | \
295 ASN1_STRFLGS_ESC_CTRL | \
296 ASN1_STRFLGS_ESC_MSB)
297
298/* This is the main function, print out an
299 * ASN1_STRING taking note of various escape
300 * and display options. Returns number of
301 * characters written or -1 if an error
302 * occurred.
303 */
304
305static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str)
306{
307 int outlen, len;
308 int type;
309 char quotes;
310 unsigned char flags;
311 quotes = 0;
312 /* Keep a copy of escape flags */
313 flags = (unsigned char)(lflags & ESC_FLAGS);
314
315 type = str->type;
316
317 outlen = 0;
318
319
320 if(lflags & ASN1_STRFLGS_SHOW_TYPE) {
321 const char *tagname;
322 tagname = ASN1_tag2str(type);
323 outlen += strlen(tagname);
324 if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1;
325 outlen++;
326 }
327
328 /* Decide what to do with type, either dump content or display it */
329
330 /* Dump everything */
331 if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1;
332 /* Ignore the string type */
333 else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1;
334 else {
335 /* Else determine width based on type */
336 if((type > 0) && (type < 31)) type = tag2nbyte[type];
337 else type = -1;
338 if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1;
339 }
340
341 if(type == -1) {
342 len = do_dump(lflags, io_ch, arg, str);
343 if(len < 0) return -1;
344 outlen += len;
345 return outlen;
346 }
347
348 if(lflags & ASN1_STRFLGS_UTF8_CONVERT) {
349 /* Note: if string is UTF8 and we want
350 * to convert to UTF8 then we just interpret
351 * it as 1 byte per character to avoid converting
352 * twice.
353 */
354 if(!type) type = 1;
355 else type |= BUF_TYPE_CONVUTF8;
356 }
357
358 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
359 if(outlen < 0) return -1;
360 outlen += len;
361 if(quotes) outlen += 2;
362 if(!arg) return outlen;
363 if(quotes && !io_ch(arg, "\"", 1)) return -1;
364 do_buf(str->data, str->length, type, flags, NULL, io_ch, arg);
365 if(quotes && !io_ch(arg, "\"", 1)) return -1;
366 return outlen;
367}
368
369/* Used for line indenting: print 'indent' spaces */
370
371static int do_indent(char_io *io_ch, void *arg, int indent)
372{
373 int i;
374 for(i = 0; i < indent; i++)
375 if(!io_ch(arg, " ", 1)) return 0;
376 return 1;
377}
378
379#define FN_WIDTH_LN 25
380#define FN_WIDTH_SN 10
381
382static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n,
383 int indent, unsigned long flags)
384{
385 int i, prev = -1, orflags, cnt;
386 int fn_opt, fn_nid;
387 ASN1_OBJECT *fn;
388 ASN1_STRING *val;
389 X509_NAME_ENTRY *ent;
390 char objtmp[80];
391 const char *objbuf;
392 int outlen, len;
393 char *sep_dn, *sep_mv, *sep_eq;
394 int sep_dn_len, sep_mv_len, sep_eq_len;
395 if(indent < 0) indent = 0;
396 outlen = indent;
397 if(!do_indent(io_ch, arg, indent)) return -1;
398 switch (flags & XN_FLAG_SEP_MASK)
399 {
400 case XN_FLAG_SEP_MULTILINE:
401 sep_dn = "\n";
402 sep_dn_len = 1;
403 sep_mv = " + ";
404 sep_mv_len = 3;
405 break;
406
407 case XN_FLAG_SEP_COMMA_PLUS:
408 sep_dn = ",";
409 sep_dn_len = 1;
410 sep_mv = "+";
411 sep_mv_len = 1;
412 indent = 0;
413 break;
414
415 case XN_FLAG_SEP_CPLUS_SPC:
416 sep_dn = ", ";
417 sep_dn_len = 2;
418 sep_mv = " + ";
419 sep_mv_len = 3;
420 indent = 0;
421 break;
422
423 case XN_FLAG_SEP_SPLUS_SPC:
424 sep_dn = "; ";
425 sep_dn_len = 2;
426 sep_mv = " + ";
427 sep_mv_len = 3;
428 indent = 0;
429 break;
430
431 default:
432 return -1;
433 }
434
435 if(flags & XN_FLAG_SPC_EQ) {
436 sep_eq = " = ";
437 sep_eq_len = 3;
438 } else {
439 sep_eq = "=";
440 sep_eq_len = 1;
441 }
442
443 fn_opt = flags & XN_FLAG_FN_MASK;
444
445 cnt = X509_NAME_entry_count(n);
446 for(i = 0; i < cnt; i++) {
447 if(flags & XN_FLAG_DN_REV)
448 ent = X509_NAME_get_entry(n, cnt - i - 1);
449 else ent = X509_NAME_get_entry(n, i);
450 if(prev != -1) {
451 if(prev == ent->set) {
452 if(!io_ch(arg, sep_mv, sep_mv_len)) return -1;
453 outlen += sep_mv_len;
454 } else {
455 if(!io_ch(arg, sep_dn, sep_dn_len)) return -1;
456 outlen += sep_dn_len;
457 if(!do_indent(io_ch, arg, indent)) return -1;
458 outlen += indent;
459 }
460 }
461 prev = ent->set;
462 fn = X509_NAME_ENTRY_get_object(ent);
463 val = X509_NAME_ENTRY_get_data(ent);
464 fn_nid = OBJ_obj2nid(fn);
465 if(fn_opt != XN_FLAG_FN_NONE) {
466 int objlen, fld_len;
467 if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) {
468 OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1);
469 fld_len = 0; /* XXX: what should this be? */
470 objbuf = objtmp;
471 } else {
472 if(fn_opt == XN_FLAG_FN_SN) {
473 fld_len = FN_WIDTH_SN;
474 objbuf = OBJ_nid2sn(fn_nid);
475 } else if(fn_opt == XN_FLAG_FN_LN) {
476 fld_len = FN_WIDTH_LN;
477 objbuf = OBJ_nid2ln(fn_nid);
478 } else {
479 fld_len = 0; /* XXX: what should this be? */
480 objbuf = "";
481 }
482 }
483 objlen = strlen(objbuf);
484 if(!io_ch(arg, objbuf, objlen)) return -1;
485 if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) {
486 if (!do_indent(io_ch, arg, fld_len - objlen)) return -1;
487 outlen += fld_len - objlen;
488 }
489 if(!io_ch(arg, sep_eq, sep_eq_len)) return -1;
490 outlen += objlen + sep_eq_len;
491 }
492 /* If the field name is unknown then fix up the DER dump
493 * flag. We might want to limit this further so it will
494 * DER dump on anything other than a few 'standard' fields.
495 */
496 if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS))
497 orflags = ASN1_STRFLGS_DUMP_ALL;
498 else orflags = 0;
499
500 len = do_print_ex(io_ch, arg, flags | orflags, val);
501 if(len < 0) return -1;
502 outlen += len;
503 }
504 return outlen;
505}
506
507/* Wrappers round the main functions */
508
509int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
510{
511 if(flags == XN_FLAG_COMPAT)
512 return X509_NAME_print(out, nm, indent);
513 return do_name_ex(send_bio_chars, out, nm, indent, flags);
514}
515
516
517int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
518{
519 if(flags == XN_FLAG_COMPAT)
520 {
521 BIO *btmp;
522 int ret;
523 btmp = BIO_new_fp(fp, BIO_NOCLOSE);
524 if(!btmp) return -1;
525 ret = X509_NAME_print(btmp, nm, indent);
526 BIO_free(btmp);
527 return ret;
528 }
529 return do_name_ex(send_fp_chars, fp, nm, indent, flags);
530}
531
532int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
533{
534 return do_print_ex(send_bio_chars, out, flags, str);
535}
536
537
538int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
539{
540 return do_print_ex(send_fp_chars, fp, flags, str);
541}
542
543/* Utility function: convert any string type to UTF8, returns number of bytes
544 * in output string or a negative error code
545 */
546
547int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
548{
549 ASN1_STRING stmp, *str = &stmp;
550 int mbflag, type, ret;
551 if(!in) return -1;
552 type = in->type;
553 if((type < 0) || (type > 30)) return -1;
554 mbflag = tag2nbyte[type];
555 if(mbflag == -1) return -1;
556 if (mbflag == 0)
557 mbflag = MBSTRING_UTF8;
558 else if (mbflag == 4)
559 mbflag = MBSTRING_UNIV;
560 else
561 mbflag |= MBSTRING_FLAG;
562 stmp.data = NULL;
563 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
564 if(ret < 0) return ret;
565 *out = stmp.data;
566 return stmp.length;
567}
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
deleted file mode 100644
index 613bbc4a7d..0000000000
--- a/src/lib/libcrypto/asn1/a_strnid.c
+++ /dev/null
@@ -1,290 +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(const ASN1_STRING_TABLE * const *a,
69 const ASN1_STRING_TABLE * const *b);
70static int table_cmp(const void *a, const void *b);
71
72
73/* This is the global mask for the mbstring functions: this is use to
74 * mask out certain types (such as BMPString and UTF8String) because
75 * certain software (e.g. Netscape) has problems with them.
76 */
77
78static unsigned long global_mask = 0xFFFFFFFFL;
79
80void ASN1_STRING_set_default_mask(unsigned long mask)
81{
82 global_mask = mask;
83}
84
85unsigned long ASN1_STRING_get_default_mask(void)
86{
87 return global_mask;
88}
89
90/* This function sets the default to various "flavours" of configuration.
91 * based on an ASCII string. Currently this is:
92 * MASK:XXXX : a numerical mask value.
93 * nobmp : Don't use BMPStrings (just Printable, T61).
94 * pkix : PKIX recommendation in RFC2459.
95 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
96 * default: the default value, Printable, T61, BMP.
97 */
98
99int ASN1_STRING_set_default_mask_asc(char *p)
100{
101 unsigned long mask;
102 char *end;
103 if(!strncmp(p, "MASK:", 5)) {
104 if(!p[5]) return 0;
105 mask = strtoul(p + 5, &end, 0);
106 if(*end) return 0;
107 } else if(!strcmp(p, "nombstr"))
108 mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING));
109 else if(!strcmp(p, "pkix"))
110 mask = ~((unsigned long)B_ASN1_T61STRING);
111 else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING;
112 else if(!strcmp(p, "default"))
113 mask = 0xFFFFFFFFL;
114 else return 0;
115 ASN1_STRING_set_default_mask(mask);
116 return 1;
117}
118
119/* The following function generates an ASN1_STRING based on limits in a table.
120 * Frequently the types and length of an ASN1_STRING are restricted by a
121 * corresponding OID. For example certificates and certificate requests.
122 */
123
124ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
125 int inlen, int inform, int nid)
126{
127 ASN1_STRING_TABLE *tbl;
128 ASN1_STRING *str = NULL;
129 unsigned long mask;
130 int ret;
131 if(!out) out = &str;
132 tbl = ASN1_STRING_TABLE_get(nid);
133 if(tbl) {
134 mask = tbl->mask;
135 if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask;
136 ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask,
137 tbl->minsize, tbl->maxsize);
138 } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask);
139 if(ret <= 0) return NULL;
140 return *out;
141}
142
143/* Now the tables and helper functions for the string table:
144 */
145
146/* size limits: this stuff is taken straight from RFC3280 */
147
148#define ub_name 32768
149#define ub_common_name 64
150#define ub_locality_name 128
151#define ub_state_name 128
152#define ub_organization_name 64
153#define ub_organization_unit_name 64
154#define ub_title 64
155#define ub_email_address 128
156#define ub_serial_number 64
157
158
159/* This table must be kept in NID order */
160
161static ASN1_STRING_TABLE tbl_standard[] = {
162{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
163{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
164{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
165{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
166{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
167{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0},
168{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK},
169{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
170{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
171{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
172{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
173{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
174{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
175{NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
176{NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
177{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
178{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
179{NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
180{NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}
181};
182
183static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
184 const ASN1_STRING_TABLE * const *b)
185{
186 return (*a)->nid - (*b)->nid;
187}
188
189static int table_cmp(const void *a, const void *b)
190{
191 const ASN1_STRING_TABLE *sa = a, *sb = b;
192 return sa->nid - sb->nid;
193}
194
195ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
196{
197 int idx;
198 ASN1_STRING_TABLE *ttmp;
199 ASN1_STRING_TABLE fnd;
200 fnd.nid = nid;
201 ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
202 (char *)tbl_standard,
203 sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
204 sizeof(ASN1_STRING_TABLE), table_cmp);
205 if(ttmp) return ttmp;
206 if(!stable) return NULL;
207 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
208 if(idx < 0) return NULL;
209 return sk_ASN1_STRING_TABLE_value(stable, idx);
210}
211
212int ASN1_STRING_TABLE_add(int nid,
213 long minsize, long maxsize, unsigned long mask,
214 unsigned long flags)
215{
216 ASN1_STRING_TABLE *tmp;
217 char new_nid = 0;
218 flags &= ~STABLE_FLAGS_MALLOC;
219 if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
220 if(!stable) {
221 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
222 return 0;
223 }
224 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
225 tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
226 if(!tmp) {
227 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
228 ERR_R_MALLOC_FAILURE);
229 return 0;
230 }
231 tmp->flags = flags | STABLE_FLAGS_MALLOC;
232 tmp->nid = nid;
233 new_nid = 1;
234 } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
235 if(minsize != -1) tmp->minsize = minsize;
236 if(maxsize != -1) tmp->maxsize = maxsize;
237 tmp->mask = mask;
238 if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp);
239 return 1;
240}
241
242void ASN1_STRING_TABLE_cleanup(void)
243{
244 STACK_OF(ASN1_STRING_TABLE) *tmp;
245 tmp = stable;
246 if(!tmp) return;
247 stable = NULL;
248 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
249}
250
251static void st_free(ASN1_STRING_TABLE *tbl)
252{
253 if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl);
254}
255
256
257IMPLEMENT_STACK_OF(ASN1_STRING_TABLE)
258
259#ifdef STRING_TABLE_TEST
260
261main()
262{
263 ASN1_STRING_TABLE *tmp;
264 int i, last_nid = -1;
265
266 for (tmp = tbl_standard, i = 0;
267 i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
268 {
269 if (tmp->nid < last_nid)
270 {
271 last_nid = 0;
272 break;
273 }
274 last_nid = tmp->nid;
275 }
276
277 if (last_nid != 0)
278 {
279 printf("Table order OK\n");
280 exit(0);
281 }
282
283 for (tmp = tbl_standard, i = 0;
284 i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
285 printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
286 OBJ_nid2ln(tmp->nid));
287
288}
289
290#endif
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
deleted file mode 100644
index 159681fbcb..0000000000
--- a/src/lib/libcrypto/asn1/a_time.c
+++ /dev/null
@@ -1,164 +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 "o_time.h"
68#include <openssl/asn1t.h>
69
70IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME)
71
72IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME)
73
74#if 0
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#endif
99
100
101ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
102 {
103 struct tm *ts;
104 struct tm data;
105
106 ts=OPENSSL_gmtime(&t,&data);
107 if (ts == NULL)
108 {
109 ASN1err(ASN1_F_ASN1_TIME_SET, ASN1_R_ERROR_GETTING_TIME);
110 return NULL;
111 }
112 if((ts->tm_year >= 50) && (ts->tm_year < 150))
113 return ASN1_UTCTIME_set(s, t);
114 return ASN1_GENERALIZEDTIME_set(s,t);
115 }
116
117int ASN1_TIME_check(ASN1_TIME *t)
118 {
119 if (t->type == V_ASN1_GENERALIZEDTIME)
120 return ASN1_GENERALIZEDTIME_check(t);
121 else if (t->type == V_ASN1_UTCTIME)
122 return ASN1_UTCTIME_check(t);
123 return 0;
124 }
125
126/* Convert an ASN1_TIME structure to GeneralizedTime */
127ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out)
128 {
129 ASN1_GENERALIZEDTIME *ret;
130 char *str;
131 int newlen;
132
133 if (!ASN1_TIME_check(t)) return NULL;
134
135 if (!out || !*out)
136 {
137 if (!(ret = ASN1_GENERALIZEDTIME_new ()))
138 return NULL;
139 if (out) *out = ret;
140 }
141 else ret = *out;
142
143 /* If already GeneralizedTime just copy across */
144 if (t->type == V_ASN1_GENERALIZEDTIME)
145 {
146 if(!ASN1_STRING_set(ret, t->data, t->length))
147 return NULL;
148 return ret;
149 }
150
151 /* grow the string */
152 if (!ASN1_STRING_set(ret, NULL, t->length + 2))
153 return NULL;
154 /* ASN1_STRING_set() allocated 'len + 1' bytes. */
155 newlen = t->length + 2 + 1;
156 str = (char *)ret->data;
157 /* Work out the century and prepend */
158 if (t->data[0] >= '5') BUF_strlcpy(str, "19", newlen);
159 else BUF_strlcpy(str, "20", newlen);
160
161 BUF_strlcat(str, (char *)t->data, newlen);
162
163 return ret;
164 }
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
deleted file mode 100644
index 2292d49b93..0000000000
--- a/src/lib/libcrypto/asn1/a_type.c
+++ /dev/null
@@ -1,84 +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 <openssl/asn1t.h>
61#include "cryptlib.h"
62
63int ASN1_TYPE_get(ASN1_TYPE *a)
64 {
65 if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
66 return(a->type);
67 else
68 return(0);
69 }
70
71void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
72 {
73 if (a->value.ptr != NULL)
74 {
75 ASN1_TYPE **tmp_a = &a;
76 ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
77 }
78 a->type=type;
79 a->value.ptr=value;
80 }
81
82
83IMPLEMENT_STACK_OF(ASN1_TYPE)
84IMPLEMENT_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 508e11e527..0000000000
--- a/src/lib/libcrypto/asn1/a_utf8.c
+++ /dev/null
@@ -1,211 +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
63
64/* UTF8 utilities */
65
66/* This parses a UTF8 string one character at a time. It is passed a pointer
67 * to the string and the length of the string. It sets 'value' to the value of
68 * the current character. It returns the number of characters read or a
69 * negative error code:
70 * -1 = string too short
71 * -2 = illegal character
72 * -3 = subsequent characters not of the form 10xxxxxx
73 * -4 = character encoded incorrectly (not minimal length).
74 */
75
76int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
77{
78 const unsigned char *p;
79 unsigned long value;
80 int ret;
81 if(len <= 0) return 0;
82 p = str;
83
84 /* Check syntax and work out the encoded value (if correct) */
85 if((*p & 0x80) == 0) {
86 value = *p++ & 0x7f;
87 ret = 1;
88 } else if((*p & 0xe0) == 0xc0) {
89 if(len < 2) return -1;
90 if((p[1] & 0xc0) != 0x80) return -3;
91 value = (*p++ & 0x1f) << 6;
92 value |= *p++ & 0x3f;
93 if(value < 0x80) return -4;
94 ret = 2;
95 } else if((*p & 0xf0) == 0xe0) {
96 if(len < 3) return -1;
97 if( ((p[1] & 0xc0) != 0x80)
98 || ((p[2] & 0xc0) != 0x80) ) return -3;
99 value = (*p++ & 0xf) << 12;
100 value |= (*p++ & 0x3f) << 6;
101 value |= *p++ & 0x3f;
102 if(value < 0x800) return -4;
103 ret = 3;
104 } else if((*p & 0xf8) == 0xf0) {
105 if(len < 4) return -1;
106 if( ((p[1] & 0xc0) != 0x80)
107 || ((p[2] & 0xc0) != 0x80)
108 || ((p[3] & 0xc0) != 0x80) ) return -3;
109 value = ((unsigned long)(*p++ & 0x7)) << 18;
110 value |= (*p++ & 0x3f) << 12;
111 value |= (*p++ & 0x3f) << 6;
112 value |= *p++ & 0x3f;
113 if(value < 0x10000) return -4;
114 ret = 4;
115 } else if((*p & 0xfc) == 0xf8) {
116 if(len < 5) return -1;
117 if( ((p[1] & 0xc0) != 0x80)
118 || ((p[2] & 0xc0) != 0x80)
119 || ((p[3] & 0xc0) != 0x80)
120 || ((p[4] & 0xc0) != 0x80) ) return -3;
121 value = ((unsigned long)(*p++ & 0x3)) << 24;
122 value |= ((unsigned long)(*p++ & 0x3f)) << 18;
123 value |= ((unsigned long)(*p++ & 0x3f)) << 12;
124 value |= (*p++ & 0x3f) << 6;
125 value |= *p++ & 0x3f;
126 if(value < 0x200000) return -4;
127 ret = 5;
128 } else if((*p & 0xfe) == 0xfc) {
129 if(len < 6) return -1;
130 if( ((p[1] & 0xc0) != 0x80)
131 || ((p[2] & 0xc0) != 0x80)
132 || ((p[3] & 0xc0) != 0x80)
133 || ((p[4] & 0xc0) != 0x80)
134 || ((p[5] & 0xc0) != 0x80) ) return -3;
135 value = ((unsigned long)(*p++ & 0x1)) << 30;
136 value |= ((unsigned long)(*p++ & 0x3f)) << 24;
137 value |= ((unsigned long)(*p++ & 0x3f)) << 18;
138 value |= ((unsigned long)(*p++ & 0x3f)) << 12;
139 value |= (*p++ & 0x3f) << 6;
140 value |= *p++ & 0x3f;
141 if(value < 0x4000000) return -4;
142 ret = 6;
143 } else return -2;
144 *val = value;
145 return ret;
146}
147
148/* This takes a character 'value' and writes the UTF8 encoded value in
149 * 'str' where 'str' is a buffer containing 'len' characters. Returns
150 * the number of characters written or -1 if 'len' is too small. 'str' can
151 * be set to NULL in which case it just returns the number of characters.
152 * It will need at most 6 characters.
153 */
154
155int UTF8_putc(unsigned char *str, int len, unsigned long value)
156{
157 if(!str) len = 6; /* Maximum we will need */
158 else if(len <= 0) return -1;
159 if(value < 0x80) {
160 if(str) *str = (unsigned char)value;
161 return 1;
162 }
163 if(value < 0x800) {
164 if(len < 2) return -1;
165 if(str) {
166 *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0);
167 *str = (unsigned char)((value & 0x3f) | 0x80);
168 }
169 return 2;
170 }
171 if(value < 0x10000) {
172 if(len < 3) return -1;
173 if(str) {
174 *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0);
175 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
176 *str = (unsigned char)((value & 0x3f) | 0x80);
177 }
178 return 3;
179 }
180 if(value < 0x200000) {
181 if(len < 4) return -1;
182 if(str) {
183 *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0);
184 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
185 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
186 *str = (unsigned char)((value & 0x3f) | 0x80);
187 }
188 return 4;
189 }
190 if(value < 0x4000000) {
191 if(len < 5) return -1;
192 if(str) {
193 *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8);
194 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
195 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
196 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
197 *str = (unsigned char)((value & 0x3f) | 0x80);
198 }
199 return 5;
200 }
201 if(len < 6) return -1;
202 if(str) {
203 *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc);
204 *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80);
205 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
206 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
207 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
208 *str = (unsigned char)((value & 0x3f) | 0x80);
209 }
210 return 6;
211}
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
deleted file mode 100644
index 18ef0acf00..0000000000
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ /dev/null
@@ -1,181 +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
74#ifndef NO_ASN1_OLD
75
76int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
77 char *data, EVP_PKEY *pkey)
78 {
79 EVP_MD_CTX ctx;
80 const EVP_MD *type;
81 unsigned char *p,*buf_in=NULL;
82 int ret= -1,i,inl;
83
84 EVP_MD_CTX_init(&ctx);
85 i=OBJ_obj2nid(a->algorithm);
86 type=EVP_get_digestbyname(OBJ_nid2sn(i));
87 if (type == NULL)
88 {
89 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
90 goto err;
91 }
92
93 inl=i2d(data,NULL);
94 buf_in=OPENSSL_malloc((unsigned int)inl);
95 if (buf_in == NULL)
96 {
97 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
98 goto err;
99 }
100 p=buf_in;
101
102 i2d(data,&p);
103 EVP_VerifyInit_ex(&ctx,type, NULL);
104 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
105
106 OPENSSL_cleanse(buf_in,(unsigned int)inl);
107 OPENSSL_free(buf_in);
108
109 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
110 (unsigned int)signature->length,pkey) <= 0)
111 {
112 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
113 ret=0;
114 goto err;
115 }
116 /* we don't need to zero the 'ctx' because we just checked
117 * public information */
118 /* memset(&ctx,0,sizeof(ctx)); */
119 ret=1;
120err:
121 EVP_MD_CTX_cleanup(&ctx);
122 return(ret);
123 }
124
125#endif
126
127
128int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signature,
129 void *asn, EVP_PKEY *pkey)
130 {
131 EVP_MD_CTX ctx;
132 const EVP_MD *type;
133 unsigned char *buf_in=NULL;
134 int ret= -1,i,inl;
135
136 EVP_MD_CTX_init(&ctx);
137 i=OBJ_obj2nid(a->algorithm);
138 type=EVP_get_digestbyname(OBJ_nid2sn(i));
139 if (type == NULL)
140 {
141 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
142 goto err;
143 }
144
145 if (!EVP_VerifyInit_ex(&ctx,type, NULL))
146 {
147 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
148 ret=0;
149 goto err;
150 }
151
152 inl = ASN1_item_i2d(asn, &buf_in, it);
153
154 if (buf_in == NULL)
155 {
156 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
157 goto err;
158 }
159
160 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
161
162 OPENSSL_cleanse(buf_in,(unsigned int)inl);
163 OPENSSL_free(buf_in);
164
165 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
166 (unsigned int)signature->length,pkey) <= 0)
167 {
168 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
169 ret=0;
170 goto err;
171 }
172 /* we don't need to zero the 'ctx' because we just checked
173 * public information */
174 /* memset(&ctx,0,sizeof(ctx)); */
175 ret=1;
176err:
177 EVP_MD_CTX_cleanup(&ctx);
178 return(ret);
179 }
180
181
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
deleted file mode 100644
index 0184b475a7..0000000000
--- a/src/lib/libcrypto/asn1/asn1.h
+++ /dev/null
@@ -1,1113 +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#include <time.h>
63#ifndef OPENSSL_NO_BIO
64#include <openssl/bio.h>
65#endif
66#include <openssl/e_os2.h>
67#include <openssl/bn.h>
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
70
71#include <openssl/symhacks.h>
72
73#include <openssl/ossl_typ.h>
74
75#ifdef OPENSSL_BUILD_SHLIBCRYPTO
76# undef OPENSSL_EXTERN
77# define OPENSSL_EXTERN OPENSSL_EXPORT
78#endif
79
80#ifdef __cplusplus
81extern "C" {
82#endif
83
84#define V_ASN1_UNIVERSAL 0x00
85#define V_ASN1_APPLICATION 0x40
86#define V_ASN1_CONTEXT_SPECIFIC 0x80
87#define V_ASN1_PRIVATE 0xc0
88
89#define V_ASN1_CONSTRUCTED 0x20
90#define V_ASN1_PRIMITIVE_TAG 0x1f
91#define V_ASN1_PRIMATIVE_TAG 0x1f
92
93#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
94#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */
95#define V_ASN1_ANY -4 /* used in ASN1 template code */
96
97#define V_ASN1_NEG 0x100 /* negative flag */
98
99#define V_ASN1_UNDEF -1
100#define V_ASN1_EOC 0
101#define V_ASN1_BOOLEAN 1 /**/
102#define V_ASN1_INTEGER 2
103#define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG)
104#define V_ASN1_BIT_STRING 3
105#define V_ASN1_OCTET_STRING 4
106#define V_ASN1_NULL 5
107#define V_ASN1_OBJECT 6
108#define V_ASN1_OBJECT_DESCRIPTOR 7
109#define V_ASN1_EXTERNAL 8
110#define V_ASN1_REAL 9
111#define V_ASN1_ENUMERATED 10
112#define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG)
113#define V_ASN1_UTF8STRING 12
114#define V_ASN1_SEQUENCE 16
115#define V_ASN1_SET 17
116#define V_ASN1_NUMERICSTRING 18 /**/
117#define V_ASN1_PRINTABLESTRING 19
118#define V_ASN1_T61STRING 20
119#define V_ASN1_TELETEXSTRING 20 /* alias */
120#define V_ASN1_VIDEOTEXSTRING 21 /**/
121#define V_ASN1_IA5STRING 22
122#define V_ASN1_UTCTIME 23
123#define V_ASN1_GENERALIZEDTIME 24 /**/
124#define V_ASN1_GRAPHICSTRING 25 /**/
125#define V_ASN1_ISO64STRING 26 /**/
126#define V_ASN1_VISIBLESTRING 26 /* alias */
127#define V_ASN1_GENERALSTRING 27 /**/
128#define V_ASN1_UNIVERSALSTRING 28 /**/
129#define V_ASN1_BMPSTRING 30
130
131/* For use with d2i_ASN1_type_bytes() */
132#define B_ASN1_NUMERICSTRING 0x0001
133#define B_ASN1_PRINTABLESTRING 0x0002
134#define B_ASN1_T61STRING 0x0004
135#define B_ASN1_TELETEXSTRING 0x0004
136#define B_ASN1_VIDEOTEXSTRING 0x0008
137#define B_ASN1_IA5STRING 0x0010
138#define B_ASN1_GRAPHICSTRING 0x0020
139#define B_ASN1_ISO64STRING 0x0040
140#define B_ASN1_VISIBLESTRING 0x0040
141#define B_ASN1_GENERALSTRING 0x0080
142#define B_ASN1_UNIVERSALSTRING 0x0100
143#define B_ASN1_OCTET_STRING 0x0200
144#define B_ASN1_BIT_STRING 0x0400
145#define B_ASN1_BMPSTRING 0x0800
146#define B_ASN1_UNKNOWN 0x1000
147#define B_ASN1_UTF8STRING 0x2000
148#define B_ASN1_UTCTIME 0x4000
149#define B_ASN1_GENERALIZEDTIME 0x8000
150
151/* For use with ASN1_mbstring_copy() */
152#define MBSTRING_FLAG 0x1000
153#define MBSTRING_ASC (MBSTRING_FLAG|1)
154#define MBSTRING_BMP (MBSTRING_FLAG|2)
155#define MBSTRING_UNIV (MBSTRING_FLAG|3)
156#define MBSTRING_UTF8 (MBSTRING_FLAG|4)
157
158struct X509_algor_st;
159
160#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
161#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
162
163typedef struct asn1_ctx_st
164 {
165 unsigned char *p;/* work char pointer */
166 int eos; /* end of sequence read for indefinite encoding */
167 int error; /* error code to use when returning an error */
168 int inf; /* constructed if 0x20, indefinite is 0x21 */
169 int tag; /* tag from last 'get object' */
170 int xclass; /* class from last 'get object' */
171 long slen; /* length of last 'get object' */
172 unsigned char *max; /* largest value of p allowed */
173 unsigned char *q;/* temporary variable */
174 unsigned char **pp;/* variable */
175 int line; /* used in error processing */
176 } ASN1_CTX;
177
178/* These are used internally in the ASN1_OBJECT to keep track of
179 * whether the names and data need to be free()ed */
180#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
181#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
182#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
183#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
184typedef struct asn1_object_st
185 {
186 const char *sn,*ln;
187 int nid;
188 int length;
189 unsigned char *data;
190 int flags; /* Should we free this one */
191 } ASN1_OBJECT;
192
193#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
194/* This is the base type that holds just about everything :-) */
195typedef struct asn1_string_st
196 {
197 int length;
198 int type;
199 unsigned char *data;
200 /* The value of the following field depends on the type being
201 * held. It is mostly being used for BIT_STRING so if the
202 * input data has a non-zero 'unused bits' value, it will be
203 * handled correctly */
204 long flags;
205 } ASN1_STRING;
206
207/* ASN1_ENCODING structure: this is used to save the received
208 * encoding of an ASN1 type. This is useful to get round
209 * problems with invalid encodings which can break signatures.
210 */
211
212typedef struct ASN1_ENCODING_st
213 {
214 unsigned char *enc; /* DER encoding */
215 long len; /* Length of encoding */
216 int modified; /* set to 1 if 'enc' is invalid */
217 } ASN1_ENCODING;
218
219/* Used with ASN1 LONG type: if a long is set to this it is omitted */
220#define ASN1_LONG_UNDEF 0x7fffffffL
221
222#define STABLE_FLAGS_MALLOC 0x01
223#define STABLE_NO_MASK 0x02
224#define DIRSTRING_TYPE \
225 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
226#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
227
228typedef struct asn1_string_table_st {
229 int nid;
230 long minsize;
231 long maxsize;
232 unsigned long mask;
233 unsigned long flags;
234} ASN1_STRING_TABLE;
235
236DECLARE_STACK_OF(ASN1_STRING_TABLE)
237
238/* size limits: this stuff is taken straight from RFC2459 */
239
240#define ub_name 32768
241#define ub_common_name 64
242#define ub_locality_name 128
243#define ub_state_name 128
244#define ub_organization_name 64
245#define ub_organization_unit_name 64
246#define ub_title 64
247#define ub_email_address 128
248
249/* Declarations for template structures: for full definitions
250 * see asn1t.h
251 */
252typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
253typedef struct ASN1_ITEM_st ASN1_ITEM;
254typedef struct ASN1_TLC_st ASN1_TLC;
255/* This is just an opaque pointer */
256typedef struct ASN1_VALUE_st ASN1_VALUE;
257
258/* Declare ASN1 functions: the implement macro in in asn1t.h */
259
260#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
261
262#define DECLARE_ASN1_FUNCTIONS_name(type, name) \
263 type *name##_new(void); \
264 void name##_free(type *a); \
265 DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)
266
267#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
268 type *name##_new(void); \
269 void name##_free(type *a); \
270 DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
271
272#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
273 type *d2i_##name(type **a, unsigned char **in, long len); \
274 int i2d_##name(type *a, unsigned char **out); \
275 DECLARE_ASN1_ITEM(itname)
276
277#define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
278 type *d2i_##name(type **a, const unsigned char **in, long len); \
279 int i2d_##name(const type *a, unsigned char **out); \
280 DECLARE_ASN1_ITEM(name)
281
282#define DECLARE_ASN1_FUNCTIONS_const(name) \
283 name *name##_new(void); \
284 void name##_free(name *a);
285
286
287/* The following macros and typedefs allow an ASN1_ITEM
288 * to be embedded in a structure and referenced. Since
289 * the ASN1_ITEM pointers need to be globally accessible
290 * (possibly from shared libraries) they may exist in
291 * different forms. On platforms that support it the
292 * ASN1_ITEM structure itself will be globally exported.
293 * Other platforms will export a function that returns
294 * an ASN1_ITEM pointer.
295 *
296 * To handle both cases transparently the macros below
297 * should be used instead of hard coding an ASN1_ITEM
298 * pointer in a structure.
299 *
300 * The structure will look like this:
301 *
302 * typedef struct SOMETHING_st {
303 * ...
304 * ASN1_ITEM_EXP *iptr;
305 * ...
306 * } SOMETHING;
307 *
308 * It would be initialised as e.g.:
309 *
310 * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
311 *
312 * and the actual pointer extracted with:
313 *
314 * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
315 *
316 * Finally an ASN1_ITEM pointer can be extracted from an
317 * appropriate reference with: ASN1_ITEM_rptr(X509). This
318 * would be used when a function takes an ASN1_ITEM * argument.
319 *
320 */
321
322#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
323
324/* ASN1_ITEM pointer exported type */
325typedef const ASN1_ITEM ASN1_ITEM_EXP;
326
327/* Macro to obtain ASN1_ITEM pointer from exported type */
328#define ASN1_ITEM_ptr(iptr) (iptr)
329
330/* Macro to include ASN1_ITEM pointer from base type */
331#define ASN1_ITEM_ref(iptr) (&(iptr##_it))
332
333#define ASN1_ITEM_rptr(ref) (&(ref##_it))
334
335#define DECLARE_ASN1_ITEM(name) \
336 OPENSSL_EXTERN const ASN1_ITEM name##_it;
337
338#else
339
340/* Platforms that can't easily handle shared global variables are declared
341 * as functions returning ASN1_ITEM pointers.
342 */
343
344/* ASN1_ITEM pointer exported type */
345typedef const ASN1_ITEM * ASN1_ITEM_EXP(void);
346
347/* Macro to obtain ASN1_ITEM pointer from exported type */
348#define ASN1_ITEM_ptr(iptr) (iptr())
349
350/* Macro to include ASN1_ITEM pointer from base type */
351#define ASN1_ITEM_ref(iptr) (iptr##_it)
352
353#define ASN1_ITEM_rptr(ref) (ref##_it())
354
355#define DECLARE_ASN1_ITEM(name) \
356 const ASN1_ITEM * name##_it(void);
357
358#endif
359
360/* Parameters used by ASN1_STRING_print_ex() */
361
362/* These determine which characters to escape:
363 * RFC2253 special characters, control characters and
364 * MSB set characters
365 */
366
367#define ASN1_STRFLGS_ESC_2253 1
368#define ASN1_STRFLGS_ESC_CTRL 2
369#define ASN1_STRFLGS_ESC_MSB 4
370
371
372/* This flag determines how we do escaping: normally
373 * RC2253 backslash only, set this to use backslash and
374 * quote.
375 */
376
377#define ASN1_STRFLGS_ESC_QUOTE 8
378
379
380/* These three flags are internal use only. */
381
382/* Character is a valid PrintableString character */
383#define CHARTYPE_PRINTABLESTRING 0x10
384/* Character needs escaping if it is the first character */
385#define CHARTYPE_FIRST_ESC_2253 0x20
386/* Character needs escaping if it is the last character */
387#define CHARTYPE_LAST_ESC_2253 0x40
388
389/* NB the internal flags are safely reused below by flags
390 * handled at the top level.
391 */
392
393/* If this is set we convert all character strings
394 * to UTF8 first
395 */
396
397#define ASN1_STRFLGS_UTF8_CONVERT 0x10
398
399/* If this is set we don't attempt to interpret content:
400 * just assume all strings are 1 byte per character. This
401 * will produce some pretty odd looking output!
402 */
403
404#define ASN1_STRFLGS_IGNORE_TYPE 0x20
405
406/* If this is set we include the string type in the output */
407#define ASN1_STRFLGS_SHOW_TYPE 0x40
408
409/* This determines which strings to display and which to
410 * 'dump' (hex dump of content octets or DER encoding). We can
411 * only dump non character strings or everything. If we
412 * don't dump 'unknown' they are interpreted as character
413 * strings with 1 octet per character and are subject to
414 * the usual escaping options.
415 */
416
417#define ASN1_STRFLGS_DUMP_ALL 0x80
418#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100
419
420/* These determine what 'dumping' does, we can dump the
421 * content octets or the DER encoding: both use the
422 * RFC2253 #XXXXX notation.
423 */
424
425#define ASN1_STRFLGS_DUMP_DER 0x200
426
427/* All the string flags consistent with RFC2253,
428 * escaping control characters isn't essential in
429 * RFC2253 but it is advisable anyway.
430 */
431
432#define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \
433 ASN1_STRFLGS_ESC_CTRL | \
434 ASN1_STRFLGS_ESC_MSB | \
435 ASN1_STRFLGS_UTF8_CONVERT | \
436 ASN1_STRFLGS_DUMP_UNKNOWN | \
437 ASN1_STRFLGS_DUMP_DER)
438
439DECLARE_STACK_OF(ASN1_INTEGER)
440DECLARE_ASN1_SET_OF(ASN1_INTEGER)
441
442DECLARE_STACK_OF(ASN1_GENERALSTRING)
443
444typedef struct asn1_type_st
445 {
446 int type;
447 union {
448 char *ptr;
449 ASN1_BOOLEAN boolean;
450 ASN1_STRING * asn1_string;
451 ASN1_OBJECT * object;
452 ASN1_INTEGER * integer;
453 ASN1_ENUMERATED * enumerated;
454 ASN1_BIT_STRING * bit_string;
455 ASN1_OCTET_STRING * octet_string;
456 ASN1_PRINTABLESTRING * printablestring;
457 ASN1_T61STRING * t61string;
458 ASN1_IA5STRING * ia5string;
459 ASN1_GENERALSTRING * generalstring;
460 ASN1_BMPSTRING * bmpstring;
461 ASN1_UNIVERSALSTRING * universalstring;
462 ASN1_UTCTIME * utctime;
463 ASN1_GENERALIZEDTIME * generalizedtime;
464 ASN1_VISIBLESTRING * visiblestring;
465 ASN1_UTF8STRING * utf8string;
466 /* set and sequence are left complete and still
467 * contain the set or sequence bytes */
468 ASN1_STRING * set;
469 ASN1_STRING * sequence;
470 } value;
471 } ASN1_TYPE;
472
473DECLARE_STACK_OF(ASN1_TYPE)
474DECLARE_ASN1_SET_OF(ASN1_TYPE)
475
476typedef struct asn1_method_st
477 {
478 int (*i2d)();
479 char *(*d2i)();
480 char *(*create)();
481 void (*destroy)();
482 } ASN1_METHOD;
483
484/* This is used when parsing some Netscape objects */
485typedef struct asn1_header_st
486 {
487 ASN1_OCTET_STRING *header;
488 char *data;
489 ASN1_METHOD *meth;
490 } ASN1_HEADER;
491
492/* This is used to contain a list of bit names */
493typedef struct BIT_STRING_BITNAME_st {
494 int bitnum;
495 const char *lname;
496 const char *sname;
497} BIT_STRING_BITNAME;
498
499
500#define M_ASN1_STRING_length(x) ((x)->length)
501#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
502#define M_ASN1_STRING_type(x) ((x)->type)
503#define M_ASN1_STRING_data(x) ((x)->data)
504
505/* Macros for string operations */
506#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
507 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
508#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
509#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
510 ASN1_STRING_dup((ASN1_STRING *)a)
511#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
512 (ASN1_STRING *)a,(ASN1_STRING *)b)
513#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
514
515#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
516 ASN1_STRING_type_new(V_ASN1_INTEGER)
517#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
518#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
519#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
520 (ASN1_STRING *)a,(ASN1_STRING *)b)
521
522#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
523 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
524#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
525#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
526#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
527 (ASN1_STRING *)a,(ASN1_STRING *)b)
528
529#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
530 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
531#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
532#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
533 ASN1_STRING_dup((ASN1_STRING *)a)
534#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
535 (ASN1_STRING *)a,(ASN1_STRING *)b)
536#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
537#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
538#define M_i2d_ASN1_OCTET_STRING(a,pp) \
539 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
540 V_ASN1_UNIVERSAL)
541
542#define B_ASN1_TIME \
543 B_ASN1_UTCTIME | \
544 B_ASN1_GENERALIZEDTIME
545
546#define B_ASN1_PRINTABLE \
547 B_ASN1_PRINTABLESTRING| \
548 B_ASN1_T61STRING| \
549 B_ASN1_IA5STRING| \
550 B_ASN1_BIT_STRING| \
551 B_ASN1_UNIVERSALSTRING|\
552 B_ASN1_BMPSTRING|\
553 B_ASN1_UTF8STRING|\
554 B_ASN1_UNKNOWN
555
556#define B_ASN1_DIRECTORYSTRING \
557 B_ASN1_PRINTABLESTRING| \
558 B_ASN1_TELETEXSTRING|\
559 B_ASN1_BMPSTRING|\
560 B_ASN1_UNIVERSALSTRING|\
561 B_ASN1_UTF8STRING
562
563#define B_ASN1_DISPLAYTEXT \
564 B_ASN1_IA5STRING| \
565 B_ASN1_VISIBLESTRING| \
566 B_ASN1_BMPSTRING|\
567 B_ASN1_UTF8STRING
568
569#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
570#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
571#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
572 pp,a->type,V_ASN1_UNIVERSAL)
573#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
574 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
575 B_ASN1_PRINTABLE)
576
577#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
578#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
579#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
580 pp,a->type,V_ASN1_UNIVERSAL)
581#define M_d2i_DIRECTORYSTRING(a,pp,l) \
582 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
583 B_ASN1_DIRECTORYSTRING)
584
585#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
586#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
587#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
588 pp,a->type,V_ASN1_UNIVERSAL)
589#define M_d2i_DISPLAYTEXT(a,pp,l) \
590 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
591 B_ASN1_DISPLAYTEXT)
592
593#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
594 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
595#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
596#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
597 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
598 V_ASN1_UNIVERSAL)
599#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
600 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
601 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
602
603#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
604 ASN1_STRING_type_new(V_ASN1_T61STRING)
605#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
606#define M_i2d_ASN1_T61STRING(a,pp) \
607 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
608 V_ASN1_UNIVERSAL)
609#define M_d2i_ASN1_T61STRING(a,pp,l) \
610 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
611 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
612
613#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
614 ASN1_STRING_type_new(V_ASN1_IA5STRING)
615#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
616#define M_ASN1_IA5STRING_dup(a) \
617 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
618#define M_i2d_ASN1_IA5STRING(a,pp) \
619 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
620 V_ASN1_UNIVERSAL)
621#define M_d2i_ASN1_IA5STRING(a,pp,l) \
622 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
623 B_ASN1_IA5STRING)
624
625#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
626 ASN1_STRING_type_new(V_ASN1_UTCTIME)
627#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
628#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
629
630#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
631 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
632#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
633#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
634 (ASN1_STRING *)a)
635
636#define M_ASN1_TIME_new() (ASN1_TIME *)\
637 ASN1_STRING_type_new(V_ASN1_UTCTIME)
638#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
639#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
640
641#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
642 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
643#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
644#define M_i2d_ASN1_GENERALSTRING(a,pp) \
645 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
646 V_ASN1_UNIVERSAL)
647#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
648 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
649 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
650
651#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
652 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
653#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
654#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
655 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
656 V_ASN1_UNIVERSAL)
657#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
658 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
659 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
660
661#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
662 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
663#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
664#define M_i2d_ASN1_BMPSTRING(a,pp) \
665 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
666 V_ASN1_UNIVERSAL)
667#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
668 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
669 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
670
671#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
672 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
673#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
674#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
675 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
676 V_ASN1_UNIVERSAL)
677#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
678 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
679 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
680
681#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
682 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
683#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
684#define M_i2d_ASN1_UTF8STRING(a,pp) \
685 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
686 V_ASN1_UNIVERSAL)
687#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
688 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
689 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
690
691 /* for the is_set parameter to i2d_ASN1_SET */
692#define IS_SEQUENCE 0
693#define IS_SET 1
694
695DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
696
697int ASN1_TYPE_get(ASN1_TYPE *a);
698void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
699
700ASN1_OBJECT * ASN1_OBJECT_new(void );
701void ASN1_OBJECT_free(ASN1_OBJECT *a);
702int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
703ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
704 long length);
705ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
706 long length);
707
708DECLARE_ASN1_ITEM(ASN1_OBJECT)
709
710DECLARE_STACK_OF(ASN1_OBJECT)
711DECLARE_ASN1_SET_OF(ASN1_OBJECT)
712
713ASN1_STRING * ASN1_STRING_new(void);
714void ASN1_STRING_free(ASN1_STRING *a);
715ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
716ASN1_STRING * ASN1_STRING_type_new(int type );
717int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
718 /* Since this is used to store all sorts of things, via macros, for now, make
719 its data void * */
720int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
721int ASN1_STRING_length(ASN1_STRING *x);
722void ASN1_STRING_length_set(ASN1_STRING *x, int n);
723int ASN1_STRING_type(ASN1_STRING *x);
724unsigned char * ASN1_STRING_data(ASN1_STRING *x);
725
726DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
727int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
728ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
729 long length);
730int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
731 int length );
732int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
733int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
734
735#ifndef OPENSSL_NO_BIO
736int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
737 BIT_STRING_BITNAME *tbl, int indent);
738#endif
739int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
740int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
741 BIT_STRING_BITNAME *tbl);
742
743int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
744int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
745
746DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
747int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
748ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
749 long length);
750ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
751 long length);
752ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
753int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
754
755DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
756
757int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
758ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
759int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
760int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
761#if 0
762time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
763#endif
764
765int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
766ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
767int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
768
769DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
770ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
771int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
772int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
773
774DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
775DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
776DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
777DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
778DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
779
780int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
781int UTF8_putc(unsigned char *str, int len, unsigned long value);
782
783DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
784
785DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
786DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
787DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
788DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
789DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
790DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
791DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
792DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
793DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
794
795ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
796int ASN1_TIME_check(ASN1_TIME *t);
797ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
798
799int i2d_ASN1_SET(STACK *a, unsigned char **pp,
800 int (*func)(), int ex_tag, int ex_class, int is_set);
801STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
802 char *(*func)(), void (*free_func)(void *),
803 int ex_tag, int ex_class);
804
805#ifndef OPENSSL_NO_BIO
806int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
807int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
808int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
809int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
810int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
811int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
812int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
813#endif
814int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
815
816int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
817ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
818 const char *sn, const char *ln);
819
820int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
821long ASN1_INTEGER_get(ASN1_INTEGER *a);
822ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
823BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
824
825int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
826long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
827ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
828BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
829
830/* General */
831/* given a string, return the correct type, max is the maximum length */
832int ASN1_PRINTABLE_type(const unsigned char *s, int max);
833
834int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
835ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
836 long length, int Ptag, int Pclass);
837unsigned long ASN1_tag2bit(int tag);
838/* type is one or more of the B_ASN1_ values. */
839ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
840 long length,int type);
841
842/* PARSING */
843int asn1_Finish(ASN1_CTX *c);
844
845/* SPECIALS */
846int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
847 int *pclass, long omax);
848int ASN1_check_infinite_end(unsigned char **p,long len);
849void ASN1_put_object(unsigned char **pp, int constructed, int length,
850 int tag, int xclass);
851int ASN1_object_size(int constructed, int length, int tag);
852
853/* Used to implement other functions */
854char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
855
856void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
857
858#ifndef OPENSSL_NO_FP_API
859char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
860void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
861int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
862int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
863int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
864#endif
865
866int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
867
868#ifndef OPENSSL_NO_BIO
869char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
870void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);
871int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
872int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
873int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
874int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
875int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
876int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
877int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
878int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
879int ASN1_parse_dump(BIO *bp,unsigned char *pp,long len,int indent,int dump);
880#endif
881const char *ASN1_tag2str(int tag);
882
883/* Used to load and write netscape format cert/key */
884int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
885ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
886ASN1_HEADER *ASN1_HEADER_new(void );
887void ASN1_HEADER_free(ASN1_HEADER *a);
888
889int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
890
891/* Not used that much at this point, except for the first two */
892ASN1_METHOD *X509_asn1_meth(void);
893ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
894ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
895ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
896
897int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
898 unsigned char *data, int len);
899int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
900 unsigned char *data, int max_len);
901int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
902 unsigned char *data, int len);
903int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
904 unsigned char *data, int max_len);
905
906STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
907 void (*free_func)(void *) );
908unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
909 int *len );
910void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
911void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
912ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
913ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);
914
915void ASN1_STRING_set_default_mask(unsigned long mask);
916int ASN1_STRING_set_default_mask_asc(char *p);
917unsigned long ASN1_STRING_get_default_mask(void);
918int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
919 int inform, unsigned long mask);
920int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
921 int inform, unsigned long mask,
922 long minsize, long maxsize);
923
924ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
925 const unsigned char *in, int inlen, int inform, int nid);
926ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
927int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
928void ASN1_STRING_TABLE_cleanup(void);
929
930/* ASN1 template functions */
931
932/* Old API compatible functions */
933ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
934void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
935ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it);
936int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
937
938void ASN1_add_oid_module(void);
939
940/* BEGIN ERROR CODES */
941/* The following lines are auto generated by the script mkerr.pl. Any changes
942 * made after this point may be overwritten when the script is next run.
943 */
944void ERR_load_ASN1_strings(void);
945
946/* Error codes for the ASN1 functions. */
947
948/* Function codes. */
949#define ASN1_F_A2D_ASN1_OBJECT 100
950#define ASN1_F_A2I_ASN1_ENUMERATED 101
951#define ASN1_F_A2I_ASN1_INTEGER 102
952#define ASN1_F_A2I_ASN1_STRING 103
953#define ASN1_F_ASN1_BIT_STRING_SET_BIT 176
954#define ASN1_F_ASN1_CHECK_TLEN 104
955#define ASN1_F_ASN1_COLLATE_PRIMITIVE 105
956#define ASN1_F_ASN1_COLLECT 106
957#define ASN1_F_ASN1_D2I_BIO 107
958#define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108
959#define ASN1_F_ASN1_D2I_FP 109
960#define ASN1_F_ASN1_DIGEST 177
961#define ASN1_F_ASN1_DO_ADB 110
962#define ASN1_F_ASN1_DUP 111
963#define ASN1_F_ASN1_ENUMERATED_SET 112
964#define ASN1_F_ASN1_ENUMERATED_TO_BN 113
965#define ASN1_F_ASN1_FIND_END 182
966#define ASN1_F_ASN1_GENERALIZEDTIME_SET 178
967#define ASN1_F_ASN1_GET_OBJECT 114
968#define ASN1_F_ASN1_HEADER_NEW 115
969#define ASN1_F_ASN1_I2D_BIO 116
970#define ASN1_F_ASN1_I2D_FP 117
971#define ASN1_F_ASN1_INTEGER_SET 118
972#define ASN1_F_ASN1_INTEGER_TO_BN 119
973#define ASN1_F_ASN1_ITEM_EX_D2I 120
974#define ASN1_F_ASN1_ITEM_NEW 121
975#define ASN1_F_ASN1_MBSTRING_COPY 122
976#define ASN1_F_ASN1_OBJECT_NEW 123
977#define ASN1_F_ASN1_PACK_STRING 124
978#define ASN1_F_ASN1_PBE_SET 125
979#define ASN1_F_ASN1_SEQ_PACK 126
980#define ASN1_F_ASN1_SEQ_UNPACK 127
981#define ASN1_F_ASN1_SIGN 128
982#define ASN1_F_ASN1_STRING_SET 179
983#define ASN1_F_ASN1_STRING_TABLE_ADD 129
984#define ASN1_F_ASN1_STRING_TYPE_NEW 130
985#define ASN1_F_ASN1_TEMPLATE_D2I 131
986#define ASN1_F_ASN1_TEMPLATE_EX_D2I 132
987#define ASN1_F_ASN1_TEMPLATE_NEW 133
988#define ASN1_F_ASN1_TIME_SET 175
989#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134
990#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135
991#define ASN1_F_ASN1_UNPACK_STRING 136
992#define ASN1_F_ASN1_UTCTIME_SET 180
993#define ASN1_F_ASN1_VERIFY 137
994#define ASN1_F_BN_TO_ASN1_ENUMERATED 138
995#define ASN1_F_BN_TO_ASN1_INTEGER 139
996#define ASN1_F_COLLECT_DATA 140
997#define ASN1_F_D2I_ASN1_BIT_STRING 141
998#define ASN1_F_D2I_ASN1_BOOLEAN 142
999#define ASN1_F_D2I_ASN1_BYTES 143
1000#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 144
1001#define ASN1_F_D2I_ASN1_HEADER 145
1002#define ASN1_F_D2I_ASN1_INTEGER 146
1003#define ASN1_F_D2I_ASN1_OBJECT 147
1004#define ASN1_F_D2I_ASN1_SET 148
1005#define ASN1_F_D2I_ASN1_TYPE_BYTES 149
1006#define ASN1_F_D2I_ASN1_UINTEGER 150
1007#define ASN1_F_D2I_ASN1_UTCTIME 151
1008#define ASN1_F_D2I_NETSCAPE_RSA 152
1009#define ASN1_F_D2I_NETSCAPE_RSA_2 153
1010#define ASN1_F_D2I_PRIVATEKEY 154
1011#define ASN1_F_D2I_PUBLICKEY 155
1012#define ASN1_F_D2I_X509 156
1013#define ASN1_F_D2I_X509_CINF 157
1014#define ASN1_F_D2I_X509_NAME 158
1015#define ASN1_F_D2I_X509_PKEY 159
1016#define ASN1_F_I2D_ASN1_SET 181
1017#define ASN1_F_I2D_ASN1_TIME 160
1018#define ASN1_F_I2D_DSA_PUBKEY 161
1019#define ASN1_F_I2D_NETSCAPE_RSA 162
1020#define ASN1_F_I2D_PRIVATEKEY 163
1021#define ASN1_F_I2D_PUBLICKEY 164
1022#define ASN1_F_I2D_RSA_PUBKEY 165
1023#define ASN1_F_LONG_C2I 166
1024#define ASN1_F_OID_MODULE_INIT 174
1025#define ASN1_F_PKCS5_PBE2_SET 167
1026#define ASN1_F_X509_CINF_NEW 168
1027#define ASN1_F_X509_CRL_ADD0_REVOKED 169
1028#define ASN1_F_X509_INFO_NEW 170
1029#define ASN1_F_X509_NAME_NEW 171
1030#define ASN1_F_X509_NEW 172
1031#define ASN1_F_X509_PKEY_NEW 173
1032
1033/* Reason codes. */
1034#define ASN1_R_ADDING_OBJECT 171
1035#define ASN1_R_AUX_ERROR 100
1036#define ASN1_R_BAD_CLASS 101
1037#define ASN1_R_BAD_OBJECT_HEADER 102
1038#define ASN1_R_BAD_PASSWORD_READ 103
1039#define ASN1_R_BAD_TAG 104
1040#define ASN1_R_BN_LIB 105
1041#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106
1042#define ASN1_R_BUFFER_TOO_SMALL 107
1043#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108
1044#define ASN1_R_DATA_IS_WRONG 109
1045#define ASN1_R_DECODE_ERROR 110
1046#define ASN1_R_DECODING_ERROR 111
1047#define ASN1_R_ENCODE_ERROR 112
1048#define ASN1_R_ERROR_GETTING_TIME 173
1049#define ASN1_R_ERROR_LOADING_SECTION 172
1050#define ASN1_R_ERROR_PARSING_SET_ELEMENT 113
1051#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114
1052#define ASN1_R_EXPECTING_AN_INTEGER 115
1053#define ASN1_R_EXPECTING_AN_OBJECT 116
1054#define ASN1_R_EXPECTING_A_BOOLEAN 117
1055#define ASN1_R_EXPECTING_A_TIME 118
1056#define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119
1057#define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120
1058#define ASN1_R_FIELD_MISSING 121
1059#define ASN1_R_FIRST_NUM_TOO_LARGE 122
1060#define ASN1_R_HEADER_TOO_LONG 123
1061#define ASN1_R_ILLEGAL_CHARACTERS 124
1062#define ASN1_R_ILLEGAL_NULL 125
1063#define ASN1_R_ILLEGAL_OPTIONAL_ANY 126
1064#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170
1065#define ASN1_R_ILLEGAL_TAGGED_ANY 127
1066#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
1067#define ASN1_R_INVALID_BMPSTRING_LENGTH 129
1068#define ASN1_R_INVALID_DIGIT 130
1069#define ASN1_R_INVALID_SEPARATOR 131
1070#define ASN1_R_INVALID_TIME_FORMAT 132
1071#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133
1072#define ASN1_R_INVALID_UTF8STRING 134
1073#define ASN1_R_IV_TOO_LARGE 135
1074#define ASN1_R_LENGTH_ERROR 136
1075#define ASN1_R_MISSING_EOC 137
1076#define ASN1_R_MISSING_SECOND_NUMBER 138
1077#define ASN1_R_MSTRING_NOT_UNIVERSAL 139
1078#define ASN1_R_MSTRING_WRONG_TAG 140
1079#define ASN1_R_NESTED_ASN1_STRING 174
1080#define ASN1_R_NON_HEX_CHARACTERS 141
1081#define ASN1_R_NOT_ENOUGH_DATA 142
1082#define ASN1_R_NO_MATCHING_CHOICE_TYPE 143
1083#define ASN1_R_NULL_IS_WRONG_LENGTH 144
1084#define ASN1_R_ODD_NUMBER_OF_CHARS 145
1085#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146
1086#define ASN1_R_SECOND_NUMBER_TOO_LARGE 147
1087#define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148
1088#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149
1089#define ASN1_R_SHORT_LINE 150
1090#define ASN1_R_STRING_TOO_LONG 151
1091#define ASN1_R_STRING_TOO_SHORT 152
1092#define ASN1_R_TAG_VALUE_TOO_HIGH 153
1093#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154
1094#define ASN1_R_TOO_LONG 155
1095#define ASN1_R_TYPE_NOT_CONSTRUCTED 156
1096#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157
1097#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 158
1098#define ASN1_R_UNEXPECTED_EOC 159
1099#define ASN1_R_UNKNOWN_FORMAT 160
1100#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161
1101#define ASN1_R_UNKNOWN_OBJECT_TYPE 162
1102#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163
1103#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164
1104#define ASN1_R_UNSUPPORTED_CIPHER 165
1105#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166
1106#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167
1107#define ASN1_R_WRONG_TAG 168
1108#define ASN1_R_WRONG_TYPE 169
1109
1110#ifdef __cplusplus
1111}
1112#endif
1113#endif
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
deleted file mode 100644
index 315d0a0807..0000000000
--- a/src/lib/libcrypto/asn1/asn1_err.c
+++ /dev/null
@@ -1,254 +0,0 @@
1/* crypto/asn1/asn1_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_ASN1,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason)
70
71static ERR_STRING_DATA ASN1_str_functs[]=
72 {
73{ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"},
74{ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"},
75{ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"},
76{ERR_FUNC(ASN1_F_A2I_ASN1_STRING), "a2i_ASN1_STRING"},
77{ERR_FUNC(ASN1_F_ASN1_BIT_STRING_SET_BIT), "ASN1_BIT_STRING_set_bit"},
78{ERR_FUNC(ASN1_F_ASN1_CHECK_TLEN), "ASN1_CHECK_TLEN"},
79{ERR_FUNC(ASN1_F_ASN1_COLLATE_PRIMITIVE), "ASN1_COLLATE_PRIMITIVE"},
80{ERR_FUNC(ASN1_F_ASN1_COLLECT), "ASN1_COLLECT"},
81{ERR_FUNC(ASN1_F_ASN1_D2I_BIO), "ASN1_d2i_bio"},
82{ERR_FUNC(ASN1_F_ASN1_D2I_EX_PRIMITIVE), "ASN1_D2I_EX_PRIMITIVE"},
83{ERR_FUNC(ASN1_F_ASN1_D2I_FP), "ASN1_d2i_fp"},
84{ERR_FUNC(ASN1_F_ASN1_DIGEST), "ASN1_digest"},
85{ERR_FUNC(ASN1_F_ASN1_DO_ADB), "ASN1_DO_ADB"},
86{ERR_FUNC(ASN1_F_ASN1_DUP), "ASN1_dup"},
87{ERR_FUNC(ASN1_F_ASN1_ENUMERATED_SET), "ASN1_ENUMERATED_set"},
88{ERR_FUNC(ASN1_F_ASN1_ENUMERATED_TO_BN), "ASN1_ENUMERATED_to_BN"},
89{ERR_FUNC(ASN1_F_ASN1_FIND_END), "ASN1_FIND_END"},
90{ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_SET), "ASN1_GENERALIZEDTIME_set"},
91{ERR_FUNC(ASN1_F_ASN1_GET_OBJECT), "ASN1_get_object"},
92{ERR_FUNC(ASN1_F_ASN1_HEADER_NEW), "ASN1_HEADER_new"},
93{ERR_FUNC(ASN1_F_ASN1_I2D_BIO), "ASN1_i2d_bio"},
94{ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"},
95{ERR_FUNC(ASN1_F_ASN1_INTEGER_SET), "ASN1_INTEGER_set"},
96{ERR_FUNC(ASN1_F_ASN1_INTEGER_TO_BN), "ASN1_INTEGER_to_BN"},
97{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_D2I), "ASN1_ITEM_EX_D2I"},
98{ERR_FUNC(ASN1_F_ASN1_ITEM_NEW), "ASN1_item_new"},
99{ERR_FUNC(ASN1_F_ASN1_MBSTRING_COPY), "ASN1_mbstring_copy"},
100{ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"},
101{ERR_FUNC(ASN1_F_ASN1_PACK_STRING), "ASN1_pack_string"},
102{ERR_FUNC(ASN1_F_ASN1_PBE_SET), "ASN1_PBE_SET"},
103{ERR_FUNC(ASN1_F_ASN1_SEQ_PACK), "ASN1_seq_pack"},
104{ERR_FUNC(ASN1_F_ASN1_SEQ_UNPACK), "ASN1_seq_unpack"},
105{ERR_FUNC(ASN1_F_ASN1_SIGN), "ASN1_sign"},
106{ERR_FUNC(ASN1_F_ASN1_STRING_SET), "ASN1_STRING_set"},
107{ERR_FUNC(ASN1_F_ASN1_STRING_TABLE_ADD), "ASN1_STRING_TABLE_add"},
108{ERR_FUNC(ASN1_F_ASN1_STRING_TYPE_NEW), "ASN1_STRING_type_new"},
109{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_D2I), "ASN1_TEMPLATE_D2I"},
110{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I), "ASN1_TEMPLATE_EX_D2I"},
111{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW), "ASN1_TEMPLATE_NEW"},
112{ERR_FUNC(ASN1_F_ASN1_TIME_SET), "ASN1_TIME_set"},
113{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING), "ASN1_TYPE_get_int_octetstring"},
114{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING), "ASN1_TYPE_get_octetstring"},
115{ERR_FUNC(ASN1_F_ASN1_UNPACK_STRING), "ASN1_unpack_string"},
116{ERR_FUNC(ASN1_F_ASN1_UTCTIME_SET), "ASN1_UTCTIME_set"},
117{ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"},
118{ERR_FUNC(ASN1_F_BN_TO_ASN1_ENUMERATED), "BN_to_ASN1_ENUMERATED"},
119{ERR_FUNC(ASN1_F_BN_TO_ASN1_INTEGER), "BN_to_ASN1_INTEGER"},
120{ERR_FUNC(ASN1_F_COLLECT_DATA), "COLLECT_DATA"},
121{ERR_FUNC(ASN1_F_D2I_ASN1_BIT_STRING), "D2I_ASN1_BIT_STRING"},
122{ERR_FUNC(ASN1_F_D2I_ASN1_BOOLEAN), "d2i_ASN1_BOOLEAN"},
123{ERR_FUNC(ASN1_F_D2I_ASN1_BYTES), "d2i_ASN1_bytes"},
124{ERR_FUNC(ASN1_F_D2I_ASN1_GENERALIZEDTIME), "D2I_ASN1_GENERALIZEDTIME"},
125{ERR_FUNC(ASN1_F_D2I_ASN1_HEADER), "d2i_ASN1_HEADER"},
126{ERR_FUNC(ASN1_F_D2I_ASN1_INTEGER), "D2I_ASN1_INTEGER"},
127{ERR_FUNC(ASN1_F_D2I_ASN1_OBJECT), "d2i_ASN1_OBJECT"},
128{ERR_FUNC(ASN1_F_D2I_ASN1_SET), "d2i_ASN1_SET"},
129{ERR_FUNC(ASN1_F_D2I_ASN1_TYPE_BYTES), "d2i_ASN1_type_bytes"},
130{ERR_FUNC(ASN1_F_D2I_ASN1_UINTEGER), "d2i_ASN1_UINTEGER"},
131{ERR_FUNC(ASN1_F_D2I_ASN1_UTCTIME), "D2I_ASN1_UTCTIME"},
132{ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA), "d2i_Netscape_RSA"},
133{ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA_2), "D2I_NETSCAPE_RSA_2"},
134{ERR_FUNC(ASN1_F_D2I_PRIVATEKEY), "d2i_PrivateKey"},
135{ERR_FUNC(ASN1_F_D2I_PUBLICKEY), "d2i_PublicKey"},
136{ERR_FUNC(ASN1_F_D2I_X509), "D2I_X509"},
137{ERR_FUNC(ASN1_F_D2I_X509_CINF), "D2I_X509_CINF"},
138{ERR_FUNC(ASN1_F_D2I_X509_NAME), "D2I_X509_NAME"},
139{ERR_FUNC(ASN1_F_D2I_X509_PKEY), "d2i_X509_PKEY"},
140{ERR_FUNC(ASN1_F_I2D_ASN1_SET), "i2d_ASN1_SET"},
141{ERR_FUNC(ASN1_F_I2D_ASN1_TIME), "I2D_ASN1_TIME"},
142{ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY), "i2d_DSA_PUBKEY"},
143{ERR_FUNC(ASN1_F_I2D_NETSCAPE_RSA), "i2d_Netscape_RSA"},
144{ERR_FUNC(ASN1_F_I2D_PRIVATEKEY), "i2d_PrivateKey"},
145{ERR_FUNC(ASN1_F_I2D_PUBLICKEY), "i2d_PublicKey"},
146{ERR_FUNC(ASN1_F_I2D_RSA_PUBKEY), "i2d_RSA_PUBKEY"},
147{ERR_FUNC(ASN1_F_LONG_C2I), "LONG_C2I"},
148{ERR_FUNC(ASN1_F_OID_MODULE_INIT), "OID_MODULE_INIT"},
149{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET), "PKCS5_pbe2_set"},
150{ERR_FUNC(ASN1_F_X509_CINF_NEW), "X509_CINF_NEW"},
151{ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"},
152{ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"},
153{ERR_FUNC(ASN1_F_X509_NAME_NEW), "X509_NAME_NEW"},
154{ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"},
155{ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"},
156{0,NULL}
157 };
158
159static ERR_STRING_DATA ASN1_str_reasons[]=
160 {
161{ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"},
162{ERR_REASON(ASN1_R_AUX_ERROR) ,"aux error"},
163{ERR_REASON(ASN1_R_BAD_CLASS) ,"bad class"},
164{ERR_REASON(ASN1_R_BAD_OBJECT_HEADER) ,"bad object header"},
165{ERR_REASON(ASN1_R_BAD_PASSWORD_READ) ,"bad password read"},
166{ERR_REASON(ASN1_R_BAD_TAG) ,"bad tag"},
167{ERR_REASON(ASN1_R_BN_LIB) ,"bn lib"},
168{ERR_REASON(ASN1_R_BOOLEAN_IS_WRONG_LENGTH),"boolean is wrong length"},
169{ERR_REASON(ASN1_R_BUFFER_TOO_SMALL) ,"buffer too small"},
170{ERR_REASON(ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER),"cipher has no object identifier"},
171{ERR_REASON(ASN1_R_DATA_IS_WRONG) ,"data is wrong"},
172{ERR_REASON(ASN1_R_DECODE_ERROR) ,"decode error"},
173{ERR_REASON(ASN1_R_DECODING_ERROR) ,"decoding error"},
174{ERR_REASON(ASN1_R_ENCODE_ERROR) ,"encode error"},
175{ERR_REASON(ASN1_R_ERROR_GETTING_TIME) ,"error getting time"},
176{ERR_REASON(ASN1_R_ERROR_LOADING_SECTION),"error loading section"},
177{ERR_REASON(ASN1_R_ERROR_PARSING_SET_ELEMENT),"error parsing set element"},
178{ERR_REASON(ASN1_R_ERROR_SETTING_CIPHER_PARAMS),"error setting cipher params"},
179{ERR_REASON(ASN1_R_EXPECTING_AN_INTEGER) ,"expecting an integer"},
180{ERR_REASON(ASN1_R_EXPECTING_AN_OBJECT) ,"expecting an object"},
181{ERR_REASON(ASN1_R_EXPECTING_A_BOOLEAN) ,"expecting a boolean"},
182{ERR_REASON(ASN1_R_EXPECTING_A_TIME) ,"expecting a time"},
183{ERR_REASON(ASN1_R_EXPLICIT_LENGTH_MISMATCH),"explicit length mismatch"},
184{ERR_REASON(ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED),"explicit tag not constructed"},
185{ERR_REASON(ASN1_R_FIELD_MISSING) ,"field missing"},
186{ERR_REASON(ASN1_R_FIRST_NUM_TOO_LARGE) ,"first num too large"},
187{ERR_REASON(ASN1_R_HEADER_TOO_LONG) ,"header too long"},
188{ERR_REASON(ASN1_R_ILLEGAL_CHARACTERS) ,"illegal characters"},
189{ERR_REASON(ASN1_R_ILLEGAL_NULL) ,"illegal null"},
190{ERR_REASON(ASN1_R_ILLEGAL_OPTIONAL_ANY) ,"illegal optional any"},
191{ERR_REASON(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE),"illegal options on item template"},
192{ERR_REASON(ASN1_R_ILLEGAL_TAGGED_ANY) ,"illegal tagged any"},
193{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),"integer too large for long"},
194{ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),"invalid bmpstring length"},
195{ERR_REASON(ASN1_R_INVALID_DIGIT) ,"invalid digit"},
196{ERR_REASON(ASN1_R_INVALID_SEPARATOR) ,"invalid separator"},
197{ERR_REASON(ASN1_R_INVALID_TIME_FORMAT) ,"invalid time format"},
198{ERR_REASON(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH),"invalid universalstring length"},
199{ERR_REASON(ASN1_R_INVALID_UTF8STRING) ,"invalid utf8string"},
200{ERR_REASON(ASN1_R_IV_TOO_LARGE) ,"iv too large"},
201{ERR_REASON(ASN1_R_LENGTH_ERROR) ,"length error"},
202{ERR_REASON(ASN1_R_MISSING_EOC) ,"missing eoc"},
203{ERR_REASON(ASN1_R_MISSING_SECOND_NUMBER),"missing second number"},
204{ERR_REASON(ASN1_R_MSTRING_NOT_UNIVERSAL),"mstring not universal"},
205{ERR_REASON(ASN1_R_MSTRING_WRONG_TAG) ,"mstring wrong tag"},
206{ERR_REASON(ASN1_R_NESTED_ASN1_STRING) ,"nested asn1 string"},
207{ERR_REASON(ASN1_R_NON_HEX_CHARACTERS) ,"non hex characters"},
208{ERR_REASON(ASN1_R_NOT_ENOUGH_DATA) ,"not enough data"},
209{ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE),"no matching choice type"},
210{ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH) ,"null is wrong length"},
211{ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS) ,"odd number of chars"},
212{ERR_REASON(ASN1_R_PRIVATE_KEY_HEADER_MISSING),"private key header missing"},
213{ERR_REASON(ASN1_R_SECOND_NUMBER_TOO_LARGE),"second number too large"},
214{ERR_REASON(ASN1_R_SEQUENCE_LENGTH_MISMATCH),"sequence length mismatch"},
215{ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED),"sequence not constructed"},
216{ERR_REASON(ASN1_R_SHORT_LINE) ,"short line"},
217{ERR_REASON(ASN1_R_STRING_TOO_LONG) ,"string too long"},
218{ERR_REASON(ASN1_R_STRING_TOO_SHORT) ,"string too short"},
219{ERR_REASON(ASN1_R_TAG_VALUE_TOO_HIGH) ,"tag value too high"},
220{ERR_REASON(ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"},
221{ERR_REASON(ASN1_R_TOO_LONG) ,"too long"},
222{ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED) ,"type not constructed"},
223{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_KEY),"unable to decode rsa key"},
224{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY),"unable to decode rsa private key"},
225{ERR_REASON(ASN1_R_UNEXPECTED_EOC) ,"unexpected eoc"},
226{ERR_REASON(ASN1_R_UNKNOWN_FORMAT) ,"unknown format"},
227{ERR_REASON(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM),"unknown message digest algorithm"},
228{ERR_REASON(ASN1_R_UNKNOWN_OBJECT_TYPE) ,"unknown object type"},
229{ERR_REASON(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE),"unknown public key type"},
230{ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE),"unsupported any defined by type"},
231{ERR_REASON(ASN1_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"},
232{ERR_REASON(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM),"unsupported encryption algorithm"},
233{ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE),"unsupported public key type"},
234{ERR_REASON(ASN1_R_WRONG_TAG) ,"wrong tag"},
235{ERR_REASON(ASN1_R_WRONG_TYPE) ,"wrong type"},
236{0,NULL}
237 };
238
239#endif
240
241void ERR_load_ASN1_strings(void)
242 {
243 static int init=1;
244
245 if (init)
246 {
247 init=0;
248#ifndef OPENSSL_NO_ERR
249 ERR_load_strings(0,ASN1_str_functs);
250 ERR_load_strings(0,ASN1_str_reasons);
251#endif
252
253 }
254 }
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
deleted file mode 100644
index 97b9b35f4b..0000000000
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ /dev/null
@@ -1,433 +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 <limits.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64
65static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
66static void asn1_put_length(unsigned char **pp, int length);
67const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
68
69int ASN1_check_infinite_end(unsigned char **p, long len)
70 {
71 /* If there is 0 or 1 byte left, the length check should pick
72 * things up */
73 if (len <= 0)
74 return(1);
75 else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
76 {
77 (*p)+=2;
78 return(1);
79 }
80 return(0);
81 }
82
83
84int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
85 long omax)
86 {
87 int i,ret;
88 long l;
89 unsigned char *p= *pp;
90 int tag,xclass,inf;
91 long max=omax;
92
93 if (!max) goto err;
94 ret=(*p&V_ASN1_CONSTRUCTED);
95 xclass=(*p&V_ASN1_PRIVATE);
96 i= *p&V_ASN1_PRIMITIVE_TAG;
97 if (i == V_ASN1_PRIMITIVE_TAG)
98 { /* high-tag */
99 p++;
100 if (--max == 0) goto err;
101 l=0;
102 while (*p&0x80)
103 {
104 l<<=7L;
105 l|= *(p++)&0x7f;
106 if (--max == 0) goto err;
107 if (l > (INT_MAX >> 7L)) goto err;
108 }
109 l<<=7L;
110 l|= *(p++)&0x7f;
111 tag=(int)l;
112 if (--max == 0) goto err;
113 }
114 else
115 {
116 tag=i;
117 p++;
118 if (--max == 0) goto err;
119 }
120 *ptag=tag;
121 *pclass=xclass;
122 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
123
124#if 0
125 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
126 (int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
127 (int)(omax+ *pp));
128
129#endif
130 if (*plength > (omax - (p - *pp)))
131 {
132 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
133 /* Set this so that even if things are not long enough
134 * the values are set correctly */
135 ret|=0x80;
136 }
137 *pp=p;
138 return(ret|inf);
139err:
140 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
141 return(0x80);
142 }
143
144static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
145 {
146 unsigned char *p= *pp;
147 unsigned long ret=0;
148 int i;
149
150 if (max-- < 1) return(0);
151 if (*p == 0x80)
152 {
153 *inf=1;
154 ret=0;
155 p++;
156 }
157 else
158 {
159 *inf=0;
160 i= *p&0x7f;
161 if (*(p++) & 0x80)
162 {
163 if (i > sizeof(long))
164 return 0;
165 if (max-- == 0) return(0);
166 while (i-- > 0)
167 {
168 ret<<=8L;
169 ret|= *(p++);
170 if (max-- == 0) return(0);
171 }
172 }
173 else
174 ret=i;
175 }
176 if (ret > LONG_MAX)
177 return 0;
178 *pp=p;
179 *rl=(long)ret;
180 return(1);
181 }
182
183/* class 0 is constructed
184 * constructed == 2 for indefinite length constructed */
185void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
186 int xclass)
187 {
188 unsigned char *p= *pp;
189 int i, ttag;
190
191 i=(constructed)?V_ASN1_CONSTRUCTED:0;
192 i|=(xclass&V_ASN1_PRIVATE);
193 if (tag < 31)
194 *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
195 else
196 {
197 *(p++)=i|V_ASN1_PRIMITIVE_TAG;
198 for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
199 ttag = i;
200 while(i-- > 0)
201 {
202 p[i] = tag & 0x7f;
203 if(i != (ttag - 1)) p[i] |= 0x80;
204 tag >>= 7;
205 }
206 p += ttag;
207 }
208 if ((constructed == 2) && (length == 0))
209 *(p++)=0x80; /* der_put_length would output 0 instead */
210 else
211 asn1_put_length(&p,length);
212 *pp=p;
213 }
214
215static void asn1_put_length(unsigned char **pp, int length)
216 {
217 unsigned char *p= *pp;
218 int i,l;
219 if (length <= 127)
220 *(p++)=(unsigned char)length;
221 else
222 {
223 l=length;
224 for (i=0; l > 0; i++)
225 l>>=8;
226 *(p++)=i|0x80;
227 l=i;
228 while (i-- > 0)
229 {
230 p[i]=length&0xff;
231 length>>=8;
232 }
233 p+=l;
234 }
235 *pp=p;
236 }
237
238int ASN1_object_size(int constructed, int length, int tag)
239 {
240 int ret;
241
242 ret=length;
243 ret++;
244 if (tag >= 31)
245 {
246 while (tag > 0)
247 {
248 tag>>=7;
249 ret++;
250 }
251 }
252 if ((length == 0) && (constructed == 2))
253 ret+=2;
254 ret++;
255 if (length > 127)
256 {
257 while (length > 0)
258 {
259 length>>=8;
260 ret++;
261 }
262 }
263 return(ret);
264 }
265
266int asn1_Finish(ASN1_CTX *c)
267 {
268 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
269 {
270 if (!ASN1_check_infinite_end(&c->p,c->slen))
271 {
272 c->error=ERR_R_MISSING_ASN1_EOS;
273 return(0);
274 }
275 }
276 if ( ((c->slen != 0) && !(c->inf & 1)) ||
277 ((c->slen < 0) && (c->inf & 1)))
278 {
279 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
280 return(0);
281 }
282 return(1);
283 }
284
285int asn1_GetSequence(ASN1_CTX *c, long *length)
286 {
287 unsigned char *q;
288
289 q=c->p;
290 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
291 *length);
292 if (c->inf & 0x80)
293 {
294 c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
295 return(0);
296 }
297 if (c->tag != V_ASN1_SEQUENCE)
298 {
299 c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
300 return(0);
301 }
302 (*length)-=(c->p-q);
303 if (c->max && (*length < 0))
304 {
305 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
306 return(0);
307 }
308 if (c->inf == (1|V_ASN1_CONSTRUCTED))
309 c->slen= *length+ *(c->pp)-c->p;
310 c->eos=0;
311 return(1);
312 }
313
314ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
315 {
316 ASN1_STRING *ret;
317
318 if (str == NULL) return(NULL);
319 if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
320 return(NULL);
321 if (!ASN1_STRING_set(ret,str->data,str->length))
322 {
323 ASN1_STRING_free(ret);
324 return(NULL);
325 }
326 ret->flags = str->flags;
327 return(ret);
328 }
329
330int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
331 {
332 unsigned char *c;
333 const char *data=_data;
334
335 if (len < 0)
336 {
337 if (data == NULL)
338 return(0);
339 else
340 len=strlen(data);
341 }
342 if ((str->length < len) || (str->data == NULL))
343 {
344 c=str->data;
345 if (c == NULL)
346 str->data=OPENSSL_malloc(len+1);
347 else
348 str->data=OPENSSL_realloc(c,len+1);
349
350 if (str->data == NULL)
351 {
352 ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE);
353 str->data=c;
354 return(0);
355 }
356 }
357 str->length=len;
358 if (data != NULL)
359 {
360 memcpy(str->data,data,len);
361 /* an allowance for strings :-) */
362 str->data[len]='\0';
363 }
364 return(1);
365 }
366
367ASN1_STRING *ASN1_STRING_new(void)
368 {
369 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
370 }
371
372
373ASN1_STRING *ASN1_STRING_type_new(int type)
374 {
375 ASN1_STRING *ret;
376
377 ret=(ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING));
378 if (ret == NULL)
379 {
380 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
381 return(NULL);
382 }
383 ret->length=0;
384 ret->type=type;
385 ret->data=NULL;
386 ret->flags=0;
387 return(ret);
388 }
389
390void ASN1_STRING_free(ASN1_STRING *a)
391 {
392 if (a == NULL) return;
393 if (a->data != NULL) OPENSSL_free(a->data);
394 OPENSSL_free(a);
395 }
396
397int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
398 {
399 int i;
400
401 i=(a->length-b->length);
402 if (i == 0)
403 {
404 i=memcmp(a->data,b->data,a->length);
405 if (i == 0)
406 return(a->type-b->type);
407 else
408 return(i);
409 }
410 else
411 return(i);
412 }
413
414void asn1_add_error(unsigned char *address, int offset)
415 {
416 char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1];
417
418 BIO_snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address);
419 BIO_snprintf(buf2,sizeof buf2,"%d",offset);
420 ERR_add_error_data(4,"address=",buf1," offset=",buf2);
421 }
422
423int ASN1_STRING_length(ASN1_STRING *x)
424{ return M_ASN1_STRING_length(x); }
425
426void ASN1_STRING_length_set(ASN1_STRING *x, int len)
427{ M_ASN1_STRING_length_set(x, len); return; }
428
429int ASN1_STRING_type(ASN1_STRING *x)
430{ return M_ASN1_STRING_type(x); }
431
432unsigned char * ASN1_STRING_data(ASN1_STRING *x)
433{ 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 a48649ceeb..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#include <openssl/asn1.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
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),__FILE__,(line))
74
75#define M_ASN1_D2I_vars(a,type,func) \
76 ASN1_CTX c; \
77 type ret=NULL; \
78 \
79 c.pp=(unsigned char **)pp; \
80 c.q= *(unsigned char **)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= *(unsigned char **)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 *(unsigned char **)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(*(unsigned char **)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 *)OPENSSL_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 676d434f03..0000000000
--- a/src/lib/libcrypto/asn1/asn1_par.c
+++ /dev/null
@@ -1,418 +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, int dump);
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 BIO_indent(bp,indent,128);
83
84 p=str;
85 if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
86 BIO_snprintf(str,sizeof str,"priv [ %d ] ",tag);
87 else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
88 BIO_snprintf(str,sizeof str,"cont [ %d ]",tag);
89 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
90 BIO_snprintf(str,sizeof str,"appl [ %d ]",tag);
91 else p = ASN1_tag2str(tag);
92
93 if (p2 != NULL)
94 {
95 if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err;
96 }
97 else
98 {
99 if (BIO_printf(bp,fmt,p) <= 0) goto err;
100 }
101 return(1);
102err:
103 return(0);
104 }
105
106int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent)
107 {
108 return(asn1_parse2(bp,&pp,len,0,0,indent,0));
109 }
110
111int ASN1_parse_dump(BIO *bp, unsigned char *pp, long len, int indent, int dump)
112 {
113 return(asn1_parse2(bp,&pp,len,0,0,indent,dump));
114 }
115
116static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
117 int depth, int indent, int dump)
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 int dump_indent;
127
128#if 0
129 dump_indent = indent;
130#else
131 dump_indent = 6; /* Because we know BIO_dump_indent() */
132#endif
133 p= *pp;
134 tot=p+length;
135 op=p-1;
136 while ((p < tot) && (op < p))
137 {
138 op=p;
139 j=ASN1_get_object(&p,&len,&tag,&xclass,length);
140#ifdef LINT
141 j=j;
142#endif
143 if (j & 0x80)
144 {
145 if (BIO_write(bp,"Error in encoding\n",18) <= 0)
146 goto end;
147 ret=0;
148 goto end;
149 }
150 hl=(p-op);
151 length-=hl;
152 /* if j == 0x21 it is a constructed indefinite length object */
153 if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
154 <= 0) goto end;
155
156 if (j != (V_ASN1_CONSTRUCTED | 1))
157 {
158 if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
159 depth,(long)hl,len) <= 0)
160 goto end;
161 }
162 else
163 {
164 if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
165 depth,(long)hl) <= 0)
166 goto end;
167 }
168 if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
169 goto end;
170 if (j & V_ASN1_CONSTRUCTED)
171 {
172 ep=p+len;
173 if (BIO_write(bp,"\n",1) <= 0) goto end;
174 if (len > length)
175 {
176 BIO_printf(bp,
177 "length is greater than %ld\n",length);
178 ret=0;
179 goto end;
180 }
181 if ((j == 0x21) && (len == 0))
182 {
183 for (;;)
184 {
185 r=asn1_parse2(bp,&p,(long)(tot-p),
186 offset+(p - *pp),depth+1,
187 indent,dump);
188 if (r == 0) { ret=0; goto end; }
189 if ((r == 2) || (p >= tot)) break;
190 }
191 }
192 else
193 while (p < ep)
194 {
195 r=asn1_parse2(bp,&p,(long)len,
196 offset+(p - *pp),depth+1,
197 indent,dump);
198 if (r == 0) { ret=0; goto end; }
199 }
200 }
201 else if (xclass != 0)
202 {
203 p+=len;
204 if (BIO_write(bp,"\n",1) <= 0) goto end;
205 }
206 else
207 {
208 nl=0;
209 if ( (tag == V_ASN1_PRINTABLESTRING) ||
210 (tag == V_ASN1_T61STRING) ||
211 (tag == V_ASN1_IA5STRING) ||
212 (tag == V_ASN1_VISIBLESTRING) ||
213 (tag == V_ASN1_UTCTIME) ||
214 (tag == V_ASN1_GENERALIZEDTIME))
215 {
216 if (BIO_write(bp,":",1) <= 0) goto end;
217 if ((len > 0) &&
218 BIO_write(bp,(char *)p,(int)len)
219 != (int)len)
220 goto end;
221 }
222 else if (tag == V_ASN1_OBJECT)
223 {
224 opp=op;
225 if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
226 {
227 if (BIO_write(bp,":",1) <= 0) goto end;
228 i2a_ASN1_OBJECT(bp,o);
229 }
230 else
231 {
232 if (BIO_write(bp,":BAD OBJECT",11) <= 0)
233 goto end;
234 }
235 }
236 else if (tag == V_ASN1_BOOLEAN)
237 {
238 int ii;
239
240 opp=op;
241 ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
242 if (ii < 0)
243 {
244 if (BIO_write(bp,"Bad boolean\n",12))
245 goto end;
246 }
247 BIO_printf(bp,":%d",ii);
248 }
249 else if (tag == V_ASN1_BMPSTRING)
250 {
251 /* do the BMP thang */
252 }
253 else if (tag == V_ASN1_OCTET_STRING)
254 {
255 int i,printable=1;
256
257 opp=op;
258 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
259 if (os != NULL)
260 {
261 opp=os->data;
262 for (i=0; i<os->length; i++)
263 {
264 if (( (opp[i] < ' ') &&
265 (opp[i] != '\n') &&
266 (opp[i] != '\r') &&
267 (opp[i] != '\t')) ||
268 (opp[i] > '~'))
269 {
270 printable=0;
271 break;
272 }
273 }
274 if (printable && (os->length > 0))
275 {
276 if (BIO_write(bp,":",1) <= 0)
277 goto end;
278 if (BIO_write(bp,(char *)opp,
279 os->length) <= 0)
280 goto end;
281 }
282 if (!printable && (os->length > 0)
283 && dump)
284 {
285 if (!nl)
286 {
287 if (BIO_write(bp,"\n",1) <= 0)
288 goto end;
289 }
290 if (BIO_dump_indent(bp,(char *)opp,
291 ((dump == -1 || dump > os->length)?os->length:dump),
292 dump_indent) <= 0)
293 goto end;
294 nl=1;
295 }
296 M_ASN1_OCTET_STRING_free(os);
297 os=NULL;
298 }
299 }
300 else if (tag == V_ASN1_INTEGER)
301 {
302 ASN1_INTEGER *bs;
303 int i;
304
305 opp=op;
306 bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
307 if (bs != NULL)
308 {
309 if (BIO_write(bp,":",1) <= 0) goto end;
310 if (bs->type == V_ASN1_NEG_INTEGER)
311 if (BIO_write(bp,"-",1) <= 0)
312 goto end;
313 for (i=0; i<bs->length; i++)
314 {
315 if (BIO_printf(bp,"%02X",
316 bs->data[i]) <= 0)
317 goto end;
318 }
319 if (bs->length == 0)
320 {
321 if (BIO_write(bp,"00",2) <= 0)
322 goto end;
323 }
324 }
325 else
326 {
327 if (BIO_write(bp,"BAD INTEGER",11) <= 0)
328 goto end;
329 }
330 M_ASN1_INTEGER_free(bs);
331 }
332 else if (tag == V_ASN1_ENUMERATED)
333 {
334 ASN1_ENUMERATED *bs;
335 int i;
336
337 opp=op;
338 bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
339 if (bs != NULL)
340 {
341 if (BIO_write(bp,":",1) <= 0) goto end;
342 if (bs->type == V_ASN1_NEG_ENUMERATED)
343 if (BIO_write(bp,"-",1) <= 0)
344 goto end;
345 for (i=0; i<bs->length; i++)
346 {
347 if (BIO_printf(bp,"%02X",
348 bs->data[i]) <= 0)
349 goto end;
350 }
351 if (bs->length == 0)
352 {
353 if (BIO_write(bp,"00",2) <= 0)
354 goto end;
355 }
356 }
357 else
358 {
359 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
360 goto end;
361 }
362 M_ASN1_ENUMERATED_free(bs);
363 }
364 else if (len > 0 && dump)
365 {
366 if (!nl)
367 {
368 if (BIO_write(bp,"\n",1) <= 0)
369 goto end;
370 }
371 if (BIO_dump_indent(bp,(char *)p,
372 ((dump == -1 || dump > len)?len:dump),
373 dump_indent) <= 0)
374 goto end;
375 nl=1;
376 }
377
378 if (!nl)
379 {
380 if (BIO_write(bp,"\n",1) <= 0) goto end;
381 }
382 p+=len;
383 if ((tag == V_ASN1_EOC) && (xclass == 0))
384 {
385 ret=2; /* End of sequence */
386 goto end;
387 }
388 }
389 length-=len;
390 }
391 ret=1;
392end:
393 if (o != NULL) ASN1_OBJECT_free(o);
394 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
395 *pp=p;
396 return(ret);
397 }
398
399const char *ASN1_tag2str(int tag)
400{
401 const static char *tag2str[] = {
402 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */
403 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */
404 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */
405 "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */
406 "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */
407 "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */
408 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */
409 "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */
410 };
411
412 if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED))
413 tag &= ~0x100;
414
415 if(tag < 0 || tag > 30) return "(unknown)";
416 return tag2str[tag];
417}
418
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h
deleted file mode 100644
index ed372f8554..0000000000
--- a/src/lib/libcrypto/asn1/asn1t.h
+++ /dev/null
@@ -1,846 +0,0 @@
1/* asn1t.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#ifndef HEADER_ASN1T_H
59#define HEADER_ASN1T_H
60
61#include <stddef.h>
62#include <openssl/e_os2.h>
63#include <openssl/asn1.h>
64
65#ifdef OPENSSL_BUILD_SHLIBCRYPTO
66# undef OPENSSL_EXTERN
67# define OPENSSL_EXTERN OPENSSL_EXPORT
68#endif
69
70/* ASN1 template defines, structures and functions */
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76
77#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
78
79/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
80#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
81
82
83/* Macros for start and end of ASN1_ITEM definition */
84
85#define ASN1_ITEM_start(itname) \
86 OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {
87
88#define ASN1_ITEM_end(itname) \
89 };
90
91#else
92
93/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
94#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))
95
96
97/* Macros for start and end of ASN1_ITEM definition */
98
99#define ASN1_ITEM_start(itname) \
100 const ASN1_ITEM * itname##_it(void) \
101 { \
102 static const ASN1_ITEM local_it = { \
103
104#define ASN1_ITEM_end(itname) \
105 }; \
106 return &local_it; \
107 }
108
109#endif
110
111
112/* Macros to aid ASN1 template writing */
113
114#define ASN1_ITEM_TEMPLATE(tname) \
115 const static ASN1_TEMPLATE tname##_item_tt
116
117#define ASN1_ITEM_TEMPLATE_END(tname) \
118 ;\
119 ASN1_ITEM_start(tname) \
120 ASN1_ITYPE_PRIMITIVE,\
121 -1,\
122 &tname##_item_tt,\
123 0,\
124 NULL,\
125 0,\
126 #tname \
127 ASN1_ITEM_end(tname)
128
129
130/* This is a ASN1 type which just embeds a template */
131
132/* This pair helps declare a SEQUENCE. We can do:
133 *
134 * ASN1_SEQUENCE(stname) = {
135 * ... SEQUENCE components ...
136 * } ASN1_SEQUENCE_END(stname)
137 *
138 * This will produce an ASN1_ITEM called stname_it
139 * for a structure called stname.
140 *
141 * If you want the same structure but a different
142 * name then use:
143 *
144 * ASN1_SEQUENCE(itname) = {
145 * ... SEQUENCE components ...
146 * } ASN1_SEQUENCE_END_name(stname, itname)
147 *
148 * This will create an item called itname_it using
149 * a structure called stname.
150 */
151
152#define ASN1_SEQUENCE(tname) \
153 const static ASN1_TEMPLATE tname##_seq_tt[]
154
155#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
156
157#define ASN1_SEQUENCE_END_name(stname, tname) \
158 ;\
159 ASN1_ITEM_start(tname) \
160 ASN1_ITYPE_SEQUENCE,\
161 V_ASN1_SEQUENCE,\
162 tname##_seq_tt,\
163 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
164 NULL,\
165 sizeof(stname),\
166 #stname \
167 ASN1_ITEM_end(tname)
168
169#define ASN1_SEQUENCE_cb(tname, cb) \
170 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
171 ASN1_SEQUENCE(tname)
172
173#define ASN1_BROKEN_SEQUENCE(tname) \
174 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
175 ASN1_SEQUENCE(tname)
176
177#define ASN1_SEQUENCE_ref(tname, cb, lck) \
178 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
179 ASN1_SEQUENCE(tname)
180
181#define ASN1_SEQUENCE_enc(tname, enc, cb) \
182 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
183 ASN1_SEQUENCE(tname)
184
185#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
186
187#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
188
189#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
190
191#define ASN1_SEQUENCE_END_ref(stname, tname) \
192 ;\
193 ASN1_ITEM_start(tname) \
194 ASN1_ITYPE_SEQUENCE,\
195 V_ASN1_SEQUENCE,\
196 tname##_seq_tt,\
197 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
198 &tname##_aux,\
199 sizeof(stname),\
200 #stname \
201 ASN1_ITEM_end(tname)
202
203
204/* This pair helps declare a CHOICE type. We can do:
205 *
206 * ASN1_CHOICE(chname) = {
207 * ... CHOICE options ...
208 * ASN1_CHOICE_END(chname)
209 *
210 * This will produce an ASN1_ITEM called chname_it
211 * for a structure called chname. The structure
212 * definition must look like this:
213 * typedef struct {
214 * int type;
215 * union {
216 * ASN1_SOMETHING *opt1;
217 * ASN1_SOMEOTHER *opt2;
218 * } value;
219 * } chname;
220 *
221 * the name of the selector must be 'type'.
222 * to use an alternative selector name use the
223 * ASN1_CHOICE_END_selector() version.
224 */
225
226#define ASN1_CHOICE(tname) \
227 const static ASN1_TEMPLATE tname##_ch_tt[]
228
229#define ASN1_CHOICE_cb(tname, cb) \
230 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
231 ASN1_CHOICE(tname)
232
233#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
234
235#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
236
237#define ASN1_CHOICE_END_selector(stname, tname, selname) \
238 ;\
239 ASN1_ITEM_start(tname) \
240 ASN1_ITYPE_CHOICE,\
241 offsetof(stname,selname) ,\
242 tname##_ch_tt,\
243 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
244 NULL,\
245 sizeof(stname),\
246 #stname \
247 ASN1_ITEM_end(tname)
248
249#define ASN1_CHOICE_END_cb(stname, tname, selname) \
250 ;\
251 ASN1_ITEM_start(tname) \
252 ASN1_ITYPE_CHOICE,\
253 offsetof(stname,selname) ,\
254 tname##_ch_tt,\
255 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
256 &tname##_aux,\
257 sizeof(stname),\
258 #stname \
259 ASN1_ITEM_end(tname)
260
261/* This helps with the template wrapper form of ASN1_ITEM */
262
263#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
264 (flags), (tag), 0,\
265 #name, ASN1_ITEM_ref(type) }
266
267/* These help with SEQUENCE or CHOICE components */
268
269/* used to declare other types */
270
271#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
272 (flags), (tag), offsetof(stname, field),\
273 #field, ASN1_ITEM_ref(type) }
274
275/* used when the structure is combined with the parent */
276
277#define ASN1_EX_COMBINE(flags, tag, type) { \
278 (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
279
280/* implicit and explicit helper macros */
281
282#define ASN1_IMP_EX(stname, field, type, tag, ex) \
283 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
284
285#define ASN1_EXP_EX(stname, field, type, tag, ex) \
286 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
287
288/* Any defined by macros: the field used is in the table itself */
289
290#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
291#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
292#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
293#else
294#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
295#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
296#endif
297/* Plain simple type */
298#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
299
300/* OPTIONAL simple type */
301#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
302
303/* IMPLICIT tagged simple type */
304#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
305
306/* IMPLICIT tagged OPTIONAL simple type */
307#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
308
309/* Same as above but EXPLICIT */
310
311#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
312#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
313
314/* SEQUENCE OF type */
315#define ASN1_SEQUENCE_OF(stname, field, type) \
316 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
317
318/* OPTIONAL SEQUENCE OF */
319#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
320 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
321
322/* Same as above but for SET OF */
323
324#define ASN1_SET_OF(stname, field, type) \
325 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
326
327#define ASN1_SET_OF_OPT(stname, field, type) \
328 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
329
330/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
331
332#define ASN1_IMP_SET_OF(stname, field, type, tag) \
333 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
334
335#define ASN1_EXP_SET_OF(stname, field, type, tag) \
336 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
337
338#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
339 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
340
341#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
342 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
343
344#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
345 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
346
347#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
348 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
349
350#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
351 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
352
353#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
354 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
355
356/* Macros for the ASN1_ADB structure */
357
358#define ASN1_ADB(name) \
359 const static ASN1_ADB_TABLE name##_adbtbl[]
360
361#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
362
363#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
364 ;\
365 const static ASN1_ADB name##_adb = {\
366 flags,\
367 offsetof(name, field),\
368 app_table,\
369 name##_adbtbl,\
370 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
371 def,\
372 none\
373 }
374
375#else
376
377#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
378 ;\
379 const static ASN1_ITEM *name##_adb(void) \
380 { \
381 const static ASN1_ADB internal_adb = \
382 {\
383 flags,\
384 offsetof(name, field),\
385 app_table,\
386 name##_adbtbl,\
387 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
388 def,\
389 none\
390 }; \
391 return (const ASN1_ITEM *) &internal_adb; \
392 } \
393 void dummy_function(void)
394
395#endif
396
397#define ADB_ENTRY(val, template) {val, template}
398
399#define ASN1_ADB_TEMPLATE(name) \
400 const static ASN1_TEMPLATE name##_tt
401
402/* This is the ASN1 template structure that defines
403 * a wrapper round the actual type. It determines the
404 * actual position of the field in the value structure,
405 * various flags such as OPTIONAL and the field name.
406 */
407
408struct ASN1_TEMPLATE_st {
409unsigned long flags; /* Various flags */
410long tag; /* tag, not used if no tagging */
411unsigned long offset; /* Offset of this field in structure */
412#ifndef NO_ASN1_FIELD_NAMES
413char *field_name; /* Field name */
414#endif
415ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
416};
417
418/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
419
420#define ASN1_TEMPLATE_item(t) (t->item_ptr)
421#define ASN1_TEMPLATE_adb(t) (t->item_ptr)
422
423typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
424typedef struct ASN1_ADB_st ASN1_ADB;
425
426struct ASN1_ADB_st {
427 unsigned long flags; /* Various flags */
428 unsigned long offset; /* Offset of selector field */
429 STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */
430 const ASN1_ADB_TABLE *tbl; /* Table of possible types */
431 long tblcount; /* Number of entries in tbl */
432 const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
433 const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
434};
435
436struct ASN1_ADB_TABLE_st {
437 long value; /* NID for an object or value for an int */
438 const ASN1_TEMPLATE tt; /* item for this value */
439};
440
441/* template flags */
442
443/* Field is optional */
444#define ASN1_TFLG_OPTIONAL (0x1)
445
446/* Field is a SET OF */
447#define ASN1_TFLG_SET_OF (0x1 << 1)
448
449/* Field is a SEQUENCE OF */
450#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
451
452/* Special case: this refers to a SET OF that
453 * will be sorted into DER order when encoded *and*
454 * the corresponding STACK will be modified to match
455 * the new order.
456 */
457#define ASN1_TFLG_SET_ORDER (0x3 << 1)
458
459/* Mask for SET OF or SEQUENCE OF */
460#define ASN1_TFLG_SK_MASK (0x3 << 1)
461
462/* These flags mean the tag should be taken from the
463 * tag field. If EXPLICIT then the underlying type
464 * is used for the inner tag.
465 */
466
467/* IMPLICIT tagging */
468#define ASN1_TFLG_IMPTAG (0x1 << 3)
469
470
471/* EXPLICIT tagging, inner tag from underlying type */
472#define ASN1_TFLG_EXPTAG (0x2 << 3)
473
474#define ASN1_TFLG_TAG_MASK (0x3 << 3)
475
476/* context specific IMPLICIT */
477#define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
478
479/* context specific EXPLICIT */
480#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
481
482/* If tagging is in force these determine the
483 * type of tag to use. Otherwise the tag is
484 * determined by the underlying type. These
485 * values reflect the actual octet format.
486 */
487
488/* Universal tag */
489#define ASN1_TFLG_UNIVERSAL (0x0<<6)
490/* Application tag */
491#define ASN1_TFLG_APPLICATION (0x1<<6)
492/* Context specific tag */
493#define ASN1_TFLG_CONTEXT (0x2<<6)
494/* Private tag */
495#define ASN1_TFLG_PRIVATE (0x3<<6)
496
497#define ASN1_TFLG_TAG_CLASS (0x3<<6)
498
499/* These are for ANY DEFINED BY type. In this case
500 * the 'item' field points to an ASN1_ADB structure
501 * which contains a table of values to decode the
502 * relevant type
503 */
504
505#define ASN1_TFLG_ADB_MASK (0x3<<8)
506
507#define ASN1_TFLG_ADB_OID (0x1<<8)
508
509#define ASN1_TFLG_ADB_INT (0x1<<9)
510
511/* This flag means a parent structure is passed
512 * instead of the field: this is useful is a
513 * SEQUENCE is being combined with a CHOICE for
514 * example. Since this means the structure and
515 * item name will differ we need to use the
516 * ASN1_CHOICE_END_name() macro for example.
517 */
518
519#define ASN1_TFLG_COMBINE (0x1<<10)
520
521/* This is the actual ASN1 item itself */
522
523struct ASN1_ITEM_st {
524char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */
525long utype; /* underlying type */
526const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */
527long tcount; /* Number of templates if SEQUENCE or CHOICE */
528const void *funcs; /* functions that handle this type */
529long size; /* Structure size (usually)*/
530#ifndef NO_ASN1_FIELD_NAMES
531const char *sname; /* Structure name */
532#endif
533};
534
535/* These are values for the itype field and
536 * determine how the type is interpreted.
537 *
538 * For PRIMITIVE types the underlying type
539 * determines the behaviour if items is NULL.
540 *
541 * Otherwise templates must contain a single
542 * template and the type is treated in the
543 * same way as the type specified in the template.
544 *
545 * For SEQUENCE types the templates field points
546 * to the members, the size field is the
547 * structure size.
548 *
549 * For CHOICE types the templates field points
550 * to each possible member (typically a union)
551 * and the 'size' field is the offset of the
552 * selector.
553 *
554 * The 'funcs' field is used for application
555 * specific functions.
556 *
557 * For COMPAT types the funcs field gives a
558 * set of functions that handle this type, this
559 * supports the old d2i, i2d convention.
560 *
561 * The EXTERN type uses a new style d2i/i2d.
562 * The new style should be used where possible
563 * because it avoids things like the d2i IMPLICIT
564 * hack.
565 *
566 * MSTRING is a multiple string type, it is used
567 * for a CHOICE of character strings where the
568 * actual strings all occupy an ASN1_STRING
569 * structure. In this case the 'utype' field
570 * has a special meaning, it is used as a mask
571 * of acceptable types using the B_ASN1 constants.
572 *
573 */
574
575#define ASN1_ITYPE_PRIMITIVE 0x0
576
577#define ASN1_ITYPE_SEQUENCE 0x1
578
579#define ASN1_ITYPE_CHOICE 0x2
580
581#define ASN1_ITYPE_COMPAT 0x3
582
583#define ASN1_ITYPE_EXTERN 0x4
584
585#define ASN1_ITYPE_MSTRING 0x5
586
587/* Cache for ASN1 tag and length, so we
588 * don't keep re-reading it for things
589 * like CHOICE
590 */
591
592struct ASN1_TLC_st{
593 char valid; /* Values below are valid */
594 int ret; /* return value */
595 long plen; /* length */
596 int ptag; /* class value */
597 int pclass; /* class value */
598 int hdrlen; /* header length */
599};
600
601/* Typedefs for ASN1 function pointers */
602
603typedef ASN1_VALUE * ASN1_new_func(void);
604typedef void ASN1_free_func(ASN1_VALUE *a);
605typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, unsigned char ** in, long length);
606typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
607
608typedef int ASN1_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
609 int tag, int aclass, char opt, ASN1_TLC *ctx);
610
611typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
612typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
613typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
614
615typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
616typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
617
618typedef struct ASN1_COMPAT_FUNCS_st {
619 ASN1_new_func *asn1_new;
620 ASN1_free_func *asn1_free;
621 ASN1_d2i_func *asn1_d2i;
622 ASN1_i2d_func *asn1_i2d;
623} ASN1_COMPAT_FUNCS;
624
625typedef struct ASN1_EXTERN_FUNCS_st {
626 void *app_data;
627 ASN1_ex_new_func *asn1_ex_new;
628 ASN1_ex_free_func *asn1_ex_free;
629 ASN1_ex_free_func *asn1_ex_clear;
630 ASN1_ex_d2i *asn1_ex_d2i;
631 ASN1_ex_i2d *asn1_ex_i2d;
632} ASN1_EXTERN_FUNCS;
633
634typedef struct ASN1_PRIMITIVE_FUNCS_st {
635 void *app_data;
636 unsigned long flags;
637 ASN1_ex_new_func *prim_new;
638 ASN1_ex_free_func *prim_free;
639 ASN1_ex_free_func *prim_clear;
640 ASN1_primitive_c2i *prim_c2i;
641 ASN1_primitive_i2c *prim_i2c;
642} ASN1_PRIMITIVE_FUNCS;
643
644/* This is the ASN1_AUX structure: it handles various
645 * miscellaneous requirements. For example the use of
646 * reference counts and an informational callback.
647 *
648 * The "informational callback" is called at various
649 * points during the ASN1 encoding and decoding. It can
650 * be used to provide minor customisation of the structures
651 * used. This is most useful where the supplied routines
652 * *almost* do the right thing but need some extra help
653 * at a few points. If the callback returns zero then
654 * it is assumed a fatal error has occurred and the
655 * main operation should be abandoned.
656 *
657 * If major changes in the default behaviour are required
658 * then an external type is more appropriate.
659 */
660
661typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it);
662
663typedef struct ASN1_AUX_st {
664 void *app_data;
665 int flags;
666 int ref_offset; /* Offset of reference value */
667 int ref_lock; /* Lock type to use */
668 ASN1_aux_cb *asn1_cb;
669 int enc_offset; /* Offset of ASN1_ENCODING structure */
670} ASN1_AUX;
671
672/* Flags in ASN1_AUX */
673
674/* Use a reference count */
675#define ASN1_AFLG_REFCOUNT 1
676/* Save the encoding of structure (useful for signatures) */
677#define ASN1_AFLG_ENCODING 2
678/* The Sequence length is invalid */
679#define ASN1_AFLG_BROKEN 4
680
681/* operation values for asn1_cb */
682
683#define ASN1_OP_NEW_PRE 0
684#define ASN1_OP_NEW_POST 1
685#define ASN1_OP_FREE_PRE 2
686#define ASN1_OP_FREE_POST 3
687#define ASN1_OP_D2I_PRE 4
688#define ASN1_OP_D2I_POST 5
689#define ASN1_OP_I2D_PRE 6
690#define ASN1_OP_I2D_POST 7
691
692/* Macro to implement a primitive type */
693#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
694#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
695 ASN1_ITEM_start(itname) \
696 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
697 ASN1_ITEM_end(itname)
698
699/* Macro to implement a multi string type */
700#define IMPLEMENT_ASN1_MSTRING(itname, mask) \
701 ASN1_ITEM_start(itname) \
702 ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
703 ASN1_ITEM_end(itname)
704
705/* Macro to implement an ASN1_ITEM in terms of old style funcs */
706
707#define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)
708
709#define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \
710 static const ASN1_COMPAT_FUNCS sname##_ff = { \
711 (ASN1_new_func *)sname##_new, \
712 (ASN1_free_func *)sname##_free, \
713 (ASN1_d2i_func *)d2i_##sname, \
714 (ASN1_i2d_func *)i2d_##sname, \
715 }; \
716 ASN1_ITEM_start(sname) \
717 ASN1_ITYPE_COMPAT, \
718 tag, \
719 NULL, \
720 0, \
721 &sname##_ff, \
722 0, \
723 #sname \
724 ASN1_ITEM_end(sname)
725
726#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
727 ASN1_ITEM_start(sname) \
728 ASN1_ITYPE_EXTERN, \
729 tag, \
730 NULL, \
731 0, \
732 &fptrs, \
733 0, \
734 #sname \
735 ASN1_ITEM_end(sname)
736
737/* Macro to implement standard functions in terms of ASN1_ITEM structures */
738
739#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
740
741#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
742
743#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
744 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
745
746#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
747 stname *fname##_new(void) \
748 { \
749 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
750 } \
751 void fname##_free(stname *a) \
752 { \
753 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
754 }
755
756#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
757 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
758 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
759
760#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
761 stname *d2i_##fname(stname **a, unsigned char **in, long len) \
762 { \
763 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
764 } \
765 int i2d_##fname(stname *a, unsigned char **out) \
766 { \
767 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
768 }
769
770/* This includes evil casts to remove const: they will go away when full
771 * ASN1 constification is done.
772 */
773#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
774 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
775 { \
776 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, (unsigned char **)in, len, ASN1_ITEM_rptr(itname));\
777 } \
778 int i2d_##fname(const stname *a, unsigned char **out) \
779 { \
780 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
781 }
782
783#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
784 stname * stname##_dup(stname *x) \
785 { \
786 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
787 }
788
789#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
790 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
791
792#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
793 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
794 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
795
796/* external definitions for primitive types */
797
798DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
799DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
800DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
801DECLARE_ASN1_ITEM(ASN1_ANY)
802DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
803DECLARE_ASN1_ITEM(CBIGNUM)
804DECLARE_ASN1_ITEM(BIGNUM)
805DECLARE_ASN1_ITEM(LONG)
806DECLARE_ASN1_ITEM(ZLONG)
807
808DECLARE_STACK_OF(ASN1_VALUE)
809
810/* Functions used internally by the ASN1 code */
811
812int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
813void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
814int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
815int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
816
817void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
818int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt);
819int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
820 int tag, int aclass, char opt, ASN1_TLC *ctx);
821
822int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
823int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt);
824void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
825
826int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
827int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
828
829int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
830int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
831
832ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
833
834const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);
835
836int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
837
838void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
839void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
840int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
841int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it);
842
843#ifdef __cplusplus
844}
845#endif
846#endif
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c
deleted file mode 100644
index edb44c988f..0000000000
--- a/src/lib/libcrypto/asn1/asn_moid.c
+++ /dev/null
@@ -1,100 +0,0 @@
1/* asn_moid.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65
66/* Simple ASN1 OID module: add all objects in a given section */
67
68static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
69 {
70 int i;
71 const char *oid_section;
72 STACK_OF(CONF_VALUE) *sktmp;
73 CONF_VALUE *oval;
74 oid_section = CONF_imodule_get_value(md);
75 if(!(sktmp = NCONF_get_section(cnf, oid_section)))
76 {
77 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
78 return 0;
79 }
80 for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
81 {
82 oval = sk_CONF_VALUE_value(sktmp, i);
83 if(OBJ_create(oval->value, oval->name, oval->name) == NID_undef)
84 {
85 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
86 return 0;
87 }
88 }
89 return 1;
90 }
91
92static void oid_module_finish(CONF_IMODULE *md)
93 {
94 OBJ_cleanup();
95 }
96
97void ASN1_add_oid_module(void)
98 {
99 CONF_module_add("oid_section", oid_module_init, oid_module_finish);
100 }
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
deleted file mode 100644
index e6051db2dc..0000000000
--- a/src/lib/libcrypto/asn1/asn_pack.c
+++ /dev/null
@@ -1,191 +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#ifndef NO_ASN1_OLD
64
65/* ASN1 packing and unpacking functions */
66
67/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
68
69STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
70 void (*free_func)(void *))
71{
72 STACK *sk;
73 unsigned char *pbuf;
74 pbuf = buf;
75 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
76 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
77 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR);
78 return sk;
79}
80
81/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
82 * OPENSSL_malloc'ed buffer
83 */
84
85unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
86 int *len)
87{
88 int safelen;
89 unsigned char *safe, *p;
90 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
91 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
92 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);
93 return NULL;
94 }
95 if (!(safe = OPENSSL_malloc (safelen))) {
96 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);
97 return NULL;
98 }
99 p = safe;
100 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
101 IS_SEQUENCE);
102 if (len) *len = safelen;
103 if (buf) *buf = safe;
104 return safe;
105}
106
107/* Extract an ASN1 object from an ASN1_STRING */
108
109void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)())
110{
111 unsigned char *p;
112 char *ret;
113
114 p = oct->data;
115 if(!(ret = d2i(NULL, &p, oct->length)))
116 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
117 return ret;
118}
119
120/* Pack an ASN1 object into an ASN1_STRING */
121
122ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_STRING **oct)
123{
124 unsigned char *p;
125 ASN1_STRING *octmp;
126
127 if (!oct || !*oct) {
128 if (!(octmp = ASN1_STRING_new ())) {
129 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
130 return NULL;
131 }
132 if (oct) *oct = octmp;
133 } else octmp = *oct;
134
135 if (!(octmp->length = i2d(obj, NULL))) {
136 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
137 return NULL;
138 }
139 if (!(p = OPENSSL_malloc (octmp->length))) {
140 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
141 return NULL;
142 }
143 octmp->data = p;
144 i2d (obj, &p);
145 return octmp;
146}
147
148#endif
149
150/* ASN1_ITEM versions of the above */
151
152ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
153{
154 ASN1_STRING *octmp;
155
156 if (!oct || !*oct) {
157 if (!(octmp = ASN1_STRING_new ())) {
158 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
159 return NULL;
160 }
161 if (oct) *oct = octmp;
162 } else octmp = *oct;
163
164 if(octmp->data) {
165 OPENSSL_free(octmp->data);
166 octmp->data = NULL;
167 }
168
169 if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
170 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
171 return NULL;
172 }
173 if (!octmp->data) {
174 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
175 return NULL;
176 }
177 return octmp;
178}
179
180/* Extract an ASN1 object from an ASN1_STRING */
181
182void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
183{
184 unsigned char *p;
185 void *ret;
186
187 p = oct->data;
188 if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
189 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
190 return ret;
191}
diff --git a/src/lib/libcrypto/asn1/charmap.h b/src/lib/libcrypto/asn1/charmap.h
deleted file mode 100644
index bd020a9562..0000000000
--- a/src/lib/libcrypto/asn1/charmap.h
+++ /dev/null
@@ -1,15 +0,0 @@
1/* Auto generated with chartype.pl script.
2 * Mask of various character properties
3 */
4
5static unsigned char char_type[] = {
6 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
8120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16,
916,16,16,16,16,16,16,16,16,16,16, 9, 9,16, 9,16,
10 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1116,16,16,16,16,16,16,16,16,16,16, 0, 1, 0, 0, 0,
12 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1316,16,16,16,16,16,16,16,16,16,16, 0, 0, 0, 0, 2
14};
15
diff --git a/src/lib/libcrypto/asn1/charmap.pl b/src/lib/libcrypto/asn1/charmap.pl
deleted file mode 100644
index 2875c59867..0000000000
--- a/src/lib/libcrypto/asn1/charmap.pl
+++ /dev/null
@@ -1,80 +0,0 @@
1#!/usr/local/bin/perl -w
2
3use strict;
4
5my ($i, @arr);
6
7# Set up an array with the type of ASCII characters
8# Each set bit represents a character property.
9
10# RFC2253 character properties
11my $RFC2253_ESC = 1; # Character escaped with \
12my $ESC_CTRL = 2; # Escaped control character
13# These are used with RFC1779 quoting using "
14my $NOESC_QUOTE = 8; # Not escaped if quoted
15my $PSTRING_CHAR = 0x10; # Valid PrintableString character
16my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character
17my $RFC2253_LAST_ESC = 0x40; # Escaped with \ if last character
18
19for($i = 0; $i < 128; $i++) {
20 # Set the RFC2253 escape characters (control)
21 $arr[$i] = 0;
22 if(($i < 32) || ($i > 126)) {
23 $arr[$i] |= $ESC_CTRL;
24 }
25
26 # Some PrintableString characters
27 if( ( ( $i >= ord("a")) && ( $i <= ord("z")) )
28 || ( ( $i >= ord("A")) && ( $i <= ord("Z")) )
29 || ( ( $i >= ord("0")) && ( $i <= ord("9")) ) ) {
30 $arr[$i] |= $PSTRING_CHAR;
31 }
32}
33
34# Now setup the rest
35
36# Remaining RFC2253 escaped characters
37
38$arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC;
39$arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC;
40
41$arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC;
42$arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC;
43$arr[ord("\"")] |= $RFC2253_ESC;
44$arr[ord("\\")] |= $RFC2253_ESC;
45$arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC;
46$arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC;
47$arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC;
48
49# Remaining PrintableString characters
50
51$arr[ord(" ")] |= $PSTRING_CHAR;
52$arr[ord("'")] |= $PSTRING_CHAR;
53$arr[ord("(")] |= $PSTRING_CHAR;
54$arr[ord(")")] |= $PSTRING_CHAR;
55$arr[ord("+")] |= $PSTRING_CHAR;
56$arr[ord(",")] |= $PSTRING_CHAR;
57$arr[ord("-")] |= $PSTRING_CHAR;
58$arr[ord(".")] |= $PSTRING_CHAR;
59$arr[ord("/")] |= $PSTRING_CHAR;
60$arr[ord(":")] |= $PSTRING_CHAR;
61$arr[ord("=")] |= $PSTRING_CHAR;
62$arr[ord("?")] |= $PSTRING_CHAR;
63
64# Now generate the C code
65
66print <<EOF;
67/* Auto generated with chartype.pl script.
68 * Mask of various character properties
69 */
70
71static unsigned char char_type[] = {
72EOF
73
74for($i = 0; $i < 128; $i++) {
75 print("\n") if($i && (($i % 16) == 0));
76 printf("%2d", $arr[$i]);
77 print(",") if ($i != 127);
78}
79print("\n};\n\n");
80
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c
deleted file mode 100644
index 2e7d96af90..0000000000
--- a/src/lib/libcrypto/asn1/d2i_pr.c
+++ /dev/null
@@ -1,145 +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#ifndef OPENSSL_NO_RSA
66#include <openssl/rsa.h>
67#endif
68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h>
70#endif
71
72EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
73 long length)
74 {
75 EVP_PKEY *ret;
76
77 if ((a == NULL) || (*a == NULL))
78 {
79 if ((ret=EVP_PKEY_new()) == NULL)
80 {
81 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB);
82 return(NULL);
83 }
84 }
85 else ret= *a;
86
87 ret->save_type=type;
88 ret->type=EVP_PKEY_type(type);
89 switch (ret->type)
90 {
91#ifndef OPENSSL_NO_RSA
92 case EVP_PKEY_RSA:
93 if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,
94 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
95 {
96 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
97 goto err;
98 }
99 break;
100#endif
101#ifndef OPENSSL_NO_DSA
102 case EVP_PKEY_DSA:
103 if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,
104 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
105 {
106 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
107 goto err;
108 }
109 break;
110#endif
111 default:
112 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
113 goto err;
114 /* break; */
115 }
116 if (a != NULL) (*a)=ret;
117 return(ret);
118err:
119 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
120 return(NULL);
121 }
122
123/* This works like d2i_PrivateKey() except it automatically works out the type */
124
125EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
126 long length)
127{
128 STACK_OF(ASN1_TYPE) *inkey;
129 unsigned char *p;
130 int keytype;
131 p = *pp;
132 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
133 * by analyzing it we can determine the passed structure: this
134 * assumes the input is surrounded by an ASN1 SEQUENCE.
135 */
136 inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE,
137 ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
138 /* Since we only need to discern "traditional format" RSA and DSA
139 * keys we can just count the elements.
140 */
141 if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA;
142 else keytype = EVP_PKEY_RSA;
143 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
144 return d2i_PrivateKey(keytype, a, pp, length);
145}
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c
deleted file mode 100644
index 71f2eb361b..0000000000
--- a/src/lib/libcrypto/asn1/d2i_pu.c
+++ /dev/null
@@ -1,122 +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#ifndef OPENSSL_NO_RSA
66#include <openssl/rsa.h>
67#endif
68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h>
70#endif
71
72EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
73 long length)
74 {
75 EVP_PKEY *ret;
76
77 if ((a == NULL) || (*a == NULL))
78 {
79 if ((ret=EVP_PKEY_new()) == NULL)
80 {
81 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
82 return(NULL);
83 }
84 }
85 else ret= *a;
86
87 ret->save_type=type;
88 ret->type=EVP_PKEY_type(type);
89 switch (ret->type)
90 {
91#ifndef OPENSSL_NO_RSA
92 case EVP_PKEY_RSA:
93 if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,
94 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
95 {
96 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
97 goto err;
98 }
99 break;
100#endif
101#ifndef OPENSSL_NO_DSA
102 case EVP_PKEY_DSA:
103 if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,
104 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
105 {
106 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
107 goto err;
108 }
109 break;
110#endif
111 default:
112 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
113 goto err;
114 /* break; */
115 }
116 if (a != NULL) (*a)=ret;
117 return(ret);
118err:
119 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
120 return(NULL);
121 }
122
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
deleted file mode 100644
index f92ce6cb5d..0000000000
--- a/src/lib/libcrypto/asn1/evp_asn1.c
+++ /dev/null
@@ -1,189 +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 if (!ASN1_STRING_set(osp,NULL,size))
119 {
120 ASN1_STRING_free(osp);
121 return(0);
122 }
123
124 M_ASN1_STRING_length_set(osp, size);
125 p=M_ASN1_STRING_data(osp);
126
127 ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
128 i2d_ASN1_INTEGER(&in,&p);
129 M_i2d_ASN1_OCTET_STRING(&os,&p);
130
131 ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp);
132 return(1);
133 }
134
135/* we return the actual length..., num may be missing, in which
136 * case, set it to zero */
137/* int max_len: for returned value */
138int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
139 int max_len)
140 {
141 int ret= -1,n;
142 ASN1_INTEGER *ai=NULL;
143 ASN1_OCTET_STRING *os=NULL;
144 unsigned char *p;
145 long length;
146 ASN1_CTX c;
147
148 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
149 {
150 goto err;
151 }
152 p=M_ASN1_STRING_data(a->value.sequence);
153 length=M_ASN1_STRING_length(a->value.sequence);
154
155 c.pp= &p;
156 c.p=p;
157 c.max=p+length;
158 c.error=ASN1_R_DATA_IS_WRONG;
159
160 M_ASN1_D2I_start_sequence();
161 c.q=c.p;
162 if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err;
163 c.slen-=(c.p-c.q);
164 c.q=c.p;
165 if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err;
166 c.slen-=(c.p-c.q);
167 if (!M_ASN1_D2I_end_sequence()) goto err;
168
169 if (num != NULL)
170 *num=ASN1_INTEGER_get(ai);
171
172 ret=M_ASN1_STRING_length(os);
173 if (max_len > ret)
174 n=ret;
175 else
176 n=max_len;
177
178 if (data != NULL)
179 memcpy(data,M_ASN1_STRING_data(os),n);
180 if (0)
181 {
182err:
183 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
184 }
185 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
186 if (ai != NULL) M_ASN1_INTEGER_free(ai);
187 return(ret);
188 }
189
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c
deleted file mode 100644
index 56e3cc8df2..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 *)OPENSSL_malloc(
157 (unsigned int)num+i*2);
158 else
159 sp=(unsigned char *)OPENSSL_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) OPENSSL_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 9494e597ab..0000000000
--- a/src/lib/libcrypto/asn1/f_int.c
+++ /dev/null
@@ -1,219 +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->type & V_ASN1_NEG)
73 {
74 if (BIO_write(bp, "-", 1) != 1) goto err;
75 n = 1;
76 }
77
78 if (a->length == 0)
79 {
80 if (BIO_write(bp,"00",2) != 2) goto err;
81 n += 2;
82 }
83 else
84 {
85 for (i=0; i<a->length; i++)
86 {
87 if ((i != 0) && (i%35 == 0))
88 {
89 if (BIO_write(bp,"\\\n",2) != 2) goto err;
90 n+=2;
91 }
92 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
93 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
94 if (BIO_write(bp,buf,2) != 2) goto err;
95 n+=2;
96 }
97 }
98 return(n);
99err:
100 return(-1);
101 }
102
103int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
104 {
105 int ret=0;
106 int i,j,k,m,n,again,bufsize;
107 unsigned char *s=NULL,*sp;
108 unsigned char *bufp;
109 int num=0,slen=0,first=1;
110
111 bs->type=V_ASN1_INTEGER;
112
113 bufsize=BIO_gets(bp,buf,size);
114 for (;;)
115 {
116 if (bufsize < 1) goto err_sl;
117 i=bufsize;
118 if (buf[i-1] == '\n') buf[--i]='\0';
119 if (i == 0) goto err_sl;
120 if (buf[i-1] == '\r') buf[--i]='\0';
121 if (i == 0) goto err_sl;
122 again=(buf[i-1] == '\\');
123
124 for (j=0; j<i; j++)
125 {
126#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 if (first)
150 {
151 first=0;
152 if ((bufp[0] == '0') && (buf[1] == '0'))
153 {
154 bufp+=2;
155 i-=2;
156 }
157 }
158 k=0;
159 i-=again;
160 if (i%2 != 0)
161 {
162 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS);
163 goto err;
164 }
165 i/=2;
166 if (num+i > slen)
167 {
168 if (s == NULL)
169 sp=(unsigned char *)OPENSSL_malloc(
170 (unsigned int)num+i*2);
171 else
172 sp=OPENSSL_realloc_clean(s,slen,num+i*2);
173 if (sp == NULL)
174 {
175 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
176 if (s != NULL) OPENSSL_free(s);
177 goto err;
178 }
179 s=sp;
180 slen=num+i*2;
181 }
182 for (j=0; j<i; j++,k+=2)
183 {
184 for (n=0; n<2; n++)
185 {
186 m=bufp[k+n];
187 if ((m >= '0') && (m <= '9'))
188 m-='0';
189 else if ((m >= 'a') && (m <= 'f'))
190 m=m-'a'+10;
191 else if ((m >= 'A') && (m <= 'F'))
192 m=m-'A'+10;
193 else
194 {
195 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS);
196 goto err;
197 }
198 s[num+j]<<=4;
199 s[num+j]|=m;
200 }
201 }
202 num+=i;
203 if (again)
204 bufsize=BIO_gets(bp,buf,size);
205 else
206 break;
207 }
208 bs->length=num;
209 bs->data=s;
210 ret=1;
211err:
212 if (0)
213 {
214err_sl:
215 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE);
216 }
217 return(ret);
218 }
219
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
deleted file mode 100644
index 968698a798..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 *)OPENSSL_malloc(
162 (unsigned int)num+i*2);
163 else
164 sp=(unsigned char *)OPENSSL_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) OPENSSL_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 1e951ae01d..0000000000
--- a/src/lib/libcrypto/asn1/i2d_pr.c
+++ /dev/null
@@ -1,90 +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#ifndef OPENSSL_NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70
71int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
72 {
73#ifndef OPENSSL_NO_RSA
74 if (a->type == EVP_PKEY_RSA)
75 {
76 return(i2d_RSAPrivateKey(a->pkey.rsa,pp));
77 }
78 else
79#endif
80#ifndef OPENSSL_NO_DSA
81 if (a->type == EVP_PKEY_DSA)
82 {
83 return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
84 }
85#endif
86
87 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
88 return(-1);
89 }
90
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c
deleted file mode 100644
index 013d19bbf4..0000000000
--- a/src/lib/libcrypto/asn1/i2d_pu.c
+++ /dev/null
@@ -1,88 +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#ifndef OPENSSL_NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70
71int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
72 {
73 switch (a->type)
74 {
75#ifndef OPENSSL_NO_RSA
76 case EVP_PKEY_RSA:
77 return(i2d_RSAPublicKey(a->pkey.rsa,pp));
78#endif
79#ifndef OPENSSL_NO_DSA
80 case EVP_PKEY_DSA:
81 return(i2d_DSAPublicKey(a->pkey.dsa,pp));
82#endif
83 default:
84 ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
85 return(-1);
86 }
87 }
88
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
deleted file mode 100644
index 766b51c538..0000000000
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ /dev/null
@@ -1,333 +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 OPENSSL_NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/asn1t.h>
65#include <openssl/asn1_mac.h>
66#include <openssl/evp.h>
67#include <openssl/x509.h>
68
69
70#ifndef OPENSSL_NO_RC4
71
72typedef struct netscape_pkey_st
73 {
74 long version;
75 X509_ALGOR *algor;
76 ASN1_OCTET_STRING *private_key;
77 } NETSCAPE_PKEY;
78
79typedef struct netscape_encrypted_pkey_st
80 {
81 ASN1_OCTET_STRING *os;
82 /* This is the same structure as DigestInfo so use it:
83 * although this isn't really anything to do with
84 * digests.
85 */
86 X509_SIG *enckey;
87 } NETSCAPE_ENCRYPTED_PKEY;
88
89
90ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = {
91 ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, os, ASN1_OCTET_STRING),
92 ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG)
93} ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY)
94
95DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
96DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY)
97IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
98
99ASN1_SEQUENCE(NETSCAPE_PKEY) = {
100 ASN1_SIMPLE(NETSCAPE_PKEY, version, LONG),
101 ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR),
102 ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING)
103} ASN1_SEQUENCE_END(NETSCAPE_PKEY)
104
105DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
106DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY)
107IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
108
109static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
110 int (*cb)(), int sgckey);
111
112int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)())
113{
114 return i2d_RSA_NET(a, pp, cb, 0);
115}
116
117int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey)
118 {
119 int i, j, ret = 0;
120 int rsalen, pkeylen, olen;
121 NETSCAPE_PKEY *pkey = NULL;
122 NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
123 unsigned char buf[256],*zz;
124 unsigned char key[EVP_MAX_KEY_LENGTH];
125 EVP_CIPHER_CTX ctx;
126
127 if (a == NULL) return(0);
128
129 if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err;
130 if ((enckey=NETSCAPE_ENCRYPTED_PKEY_new()) == NULL) goto err;
131 pkey->version = 0;
132
133 pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption);
134 if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
135 pkey->algor->parameter->type=V_ASN1_NULL;
136
137 rsalen = i2d_RSAPrivateKey(a, NULL);
138
139 /* Fake some octet strings just for the initial length
140 * calculation.
141 */
142
143 pkey->private_key->length=rsalen;
144
145 pkeylen=i2d_NETSCAPE_PKEY(pkey,NULL);
146
147 enckey->enckey->digest->length = pkeylen;
148
149 enckey->os->length = 11; /* "private-key" */
150
151 enckey->enckey->algor->algorithm=OBJ_nid2obj(NID_rc4);
152 if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
153 enckey->enckey->algor->parameter->type=V_ASN1_NULL;
154
155 if (pp == NULL)
156 {
157 olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL);
158 NETSCAPE_PKEY_free(pkey);
159 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
160 return olen;
161 }
162
163
164 /* Since its RC4 encrypted length is actual length */
165 if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL)
166 {
167 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
168 goto err;
169 }
170
171 pkey->private_key->data = zz;
172 /* Write out private key encoding */
173 i2d_RSAPrivateKey(a,&zz);
174
175 if ((zz=OPENSSL_malloc(pkeylen)) == NULL)
176 {
177 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
178 goto err;
179 }
180
181 if (!ASN1_STRING_set(enckey->os, "private-key", -1))
182 {
183 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
184 goto err;
185 }
186 enckey->enckey->digest->data = zz;
187 i2d_NETSCAPE_PKEY(pkey,&zz);
188
189 /* Wipe the private key encoding */
190 OPENSSL_cleanse(pkey->private_key->data, rsalen);
191
192 if (cb == NULL)
193 cb=EVP_read_pw_string;
194 i=cb(buf,256,"Enter Private Key password:",1);
195 if (i != 0)
196 {
197 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ);
198 goto err;
199 }
200 i = strlen((char *)buf);
201 /* If the key is used for SGC the algorithm is modified a little. */
202 if(sgckey) {
203 EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL);
204 memcpy(buf + 16, "SGCKEYSALT", 10);
205 i = 26;
206 }
207
208 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL);
209 OPENSSL_cleanse(buf,256);
210
211 /* Encrypt private key in place */
212 zz = enckey->enckey->digest->data;
213 EVP_CIPHER_CTX_init(&ctx);
214 EVP_EncryptInit_ex(&ctx,EVP_rc4(),NULL,key,NULL);
215 EVP_EncryptUpdate(&ctx,zz,&i,zz,pkeylen);
216 EVP_EncryptFinal_ex(&ctx,zz + i,&j);
217 EVP_CIPHER_CTX_cleanup(&ctx);
218
219 ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp);
220err:
221 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
222 NETSCAPE_PKEY_free(pkey);
223 return(ret);
224 }
225
226
227RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)())
228{
229 return d2i_RSA_NET(a, pp, length, cb, 0);
230}
231
232RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey)
233 {
234 RSA *ret=NULL;
235 const unsigned char *p, *kp;
236 NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
237
238 p = *pp;
239
240 enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length);
241 if(!enckey) {
242 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR);
243 return NULL;
244 }
245
246 if ((enckey->os->length != 11) || (strncmp("private-key",
247 (char *)enckey->os->data,11) != 0))
248 {
249 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
250 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
251 return NULL;
252 }
253 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4)
254 {
255 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
256 goto err;
257 }
258 kp = enckey->enckey->digest->data;
259 if (cb == NULL)
260 cb=EVP_read_pw_string;
261 if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err;
262
263 *pp = p;
264
265 err:
266 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
267 return ret;
268
269 }
270
271static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
272 int (*cb)(), int sgckey)
273 {
274 NETSCAPE_PKEY *pkey=NULL;
275 RSA *ret=NULL;
276 int i,j;
277 unsigned char buf[256];
278 const unsigned char *zz;
279 unsigned char key[EVP_MAX_KEY_LENGTH];
280 EVP_CIPHER_CTX ctx;
281
282 i=cb(buf,256,"Enter Private Key password:",0);
283 if (i != 0)
284 {
285 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ);
286 goto err;
287 }
288
289 i = strlen((char *)buf);
290 if(sgckey){
291 EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL);
292 memcpy(buf + 16, "SGCKEYSALT", 10);
293 i = 26;
294 }
295
296 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL);
297 OPENSSL_cleanse(buf,256);
298
299 EVP_CIPHER_CTX_init(&ctx);
300 EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL);
301 EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length);
302 EVP_DecryptFinal_ex(&ctx,&(os->data[i]),&j);
303 EVP_CIPHER_CTX_cleanup(&ctx);
304 os->length=i+j;
305
306 zz=os->data;
307
308 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
309 {
310 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
311 goto err;
312 }
313
314 zz=pkey->private_key->data;
315 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
316 {
317 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
318 goto err;
319 }
320err:
321 NETSCAPE_PKEY_free(pkey);
322 return(ret);
323 }
324
325#endif /* OPENSSL_NO_RC4 */
326
327#else /* !OPENSSL_NO_RSA */
328
329# if PEDANTIC
330static void *dummy=&dummy;
331# endif
332
333#endif
diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c
deleted file mode 100644
index 50e2d4d07a..0000000000
--- a/src/lib/libcrypto/asn1/nsseq.c
+++ /dev/null
@@ -1,82 +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/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/objects.h>
64
65static int nsseq_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 if(operation == ASN1_OP_NEW_POST) {
68 NETSCAPE_CERT_SEQUENCE *nsseq;
69 nsseq = (NETSCAPE_CERT_SEQUENCE *)*pval;
70 nsseq->type = OBJ_nid2obj(NID_netscape_cert_sequence);
71 }
72 return 1;
73}
74
75/* Netscape certificate sequence structure */
76
77ASN1_SEQUENCE_cb(NETSCAPE_CERT_SEQUENCE, nsseq_cb) = {
78 ASN1_SIMPLE(NETSCAPE_CERT_SEQUENCE, type, ASN1_OBJECT),
79 ASN1_EXP_SEQUENCE_OF_OPT(NETSCAPE_CERT_SEQUENCE, certs, X509, 0)
80} ASN1_SEQUENCE_END_cb(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
81
82IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE)
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
deleted file mode 100644
index ec788267e0..0000000000
--- a/src/lib/libcrypto/asn1/p5_pbe.c
+++ /dev/null
@@ -1,130 +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/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 password based encryption structure */
66
67ASN1_SEQUENCE(PBEPARAM) = {
68 ASN1_SIMPLE(PBEPARAM, salt, ASN1_OCTET_STRING),
69 ASN1_SIMPLE(PBEPARAM, iter, ASN1_INTEGER)
70} ASN1_SEQUENCE_END(PBEPARAM)
71
72IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM)
73
74/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
75
76X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
77 int saltlen)
78{
79 PBEPARAM *pbe=NULL;
80 ASN1_OBJECT *al;
81 X509_ALGOR *algor;
82 ASN1_TYPE *astype=NULL;
83
84 if (!(pbe = PBEPARAM_new ())) {
85 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
86 goto err;
87 }
88 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
89 if (!ASN1_INTEGER_set(pbe->iter, iter)) {
90 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
91 goto err;
92 }
93 if (!saltlen) saltlen = PKCS5_SALT_LEN;
94 if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) {
95 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
96 goto err;
97 }
98 pbe->salt->length = saltlen;
99 if (salt) memcpy (pbe->salt->data, salt, saltlen);
100 else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0)
101 goto err;
102
103 if (!(astype = ASN1_TYPE_new())) {
104 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
105 goto err;
106 }
107
108 astype->type = V_ASN1_SEQUENCE;
109 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
110 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
111 goto err;
112 }
113 PBEPARAM_free (pbe);
114 pbe = NULL;
115
116 al = OBJ_nid2obj(alg); /* never need to free al */
117 if (!(algor = X509_ALGOR_new())) {
118 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
119 goto err;
120 }
121 ASN1_OBJECT_free(algor->algorithm);
122 algor->algorithm = al;
123 algor->parameter = astype;
124
125 return (algor);
126err:
127 if (pbe != NULL) PBEPARAM_free(pbe);
128 if (astype != NULL) ASN1_TYPE_free(astype);
129 return NULL;
130}
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
deleted file mode 100644
index e0dc0ec4ee..0000000000
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ /dev/null
@@ -1,205 +0,0 @@
1/* p5_pbev2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999-2004.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 v2.0 password based encryption structures */
66
67ASN1_SEQUENCE(PBE2PARAM) = {
68 ASN1_SIMPLE(PBE2PARAM, keyfunc, X509_ALGOR),
69 ASN1_SIMPLE(PBE2PARAM, encryption, X509_ALGOR)
70} ASN1_SEQUENCE_END(PBE2PARAM)
71
72IMPLEMENT_ASN1_FUNCTIONS(PBE2PARAM)
73
74ASN1_SEQUENCE(PBKDF2PARAM) = {
75 ASN1_SIMPLE(PBKDF2PARAM, salt, ASN1_ANY),
76 ASN1_SIMPLE(PBKDF2PARAM, iter, ASN1_INTEGER),
77 ASN1_OPT(PBKDF2PARAM, keylength, ASN1_INTEGER),
78 ASN1_OPT(PBKDF2PARAM, prf, X509_ALGOR)
79} ASN1_SEQUENCE_END(PBKDF2PARAM)
80
81IMPLEMENT_ASN1_FUNCTIONS(PBKDF2PARAM)
82
83/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
84 * yes I know this is horrible!
85 */
86
87X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
88 unsigned char *salt, int saltlen)
89{
90 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
91 int alg_nid;
92 EVP_CIPHER_CTX ctx;
93 unsigned char iv[EVP_MAX_IV_LENGTH];
94 PBKDF2PARAM *kdf = NULL;
95 PBE2PARAM *pbe2 = NULL;
96 ASN1_OCTET_STRING *osalt = NULL;
97 ASN1_OBJECT *obj;
98
99 alg_nid = EVP_CIPHER_type(cipher);
100 if(alg_nid == NID_undef) {
101 ASN1err(ASN1_F_PKCS5_PBE2_SET,
102 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
103 goto err;
104 }
105 obj = OBJ_nid2obj(alg_nid);
106
107 if(!(pbe2 = PBE2PARAM_new())) goto merr;
108
109 /* Setup the AlgorithmIdentifier for the encryption scheme */
110 scheme = pbe2->encryption;
111
112 scheme->algorithm = obj;
113 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
114
115 /* Create random IV */
116 if (EVP_CIPHER_iv_length(cipher) &&
117 RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
118 goto err;
119
120 EVP_CIPHER_CTX_init(&ctx);
121
122 /* Dummy cipherinit to just setup the IV */
123 EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0);
124 if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
125 ASN1err(ASN1_F_PKCS5_PBE2_SET,
126 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
127 EVP_CIPHER_CTX_cleanup(&ctx);
128 goto err;
129 }
130 EVP_CIPHER_CTX_cleanup(&ctx);
131
132 if(!(kdf = PBKDF2PARAM_new())) goto merr;
133 if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr;
134
135 if (!saltlen) saltlen = PKCS5_SALT_LEN;
136 if (!(osalt->data = OPENSSL_malloc (saltlen))) goto merr;
137 osalt->length = saltlen;
138 if (salt) memcpy (osalt->data, salt, saltlen);
139 else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) goto merr;
140
141 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
142 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
143
144 /* Now include salt in kdf structure */
145 kdf->salt->value.octet_string = osalt;
146 kdf->salt->type = V_ASN1_OCTET_STRING;
147 osalt = NULL;
148
149 /* If its RC2 then we'd better setup the key length */
150
151 if(alg_nid == NID_rc2_cbc) {
152 if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr;
153 if(!ASN1_INTEGER_set (kdf->keylength,
154 EVP_CIPHER_key_length(cipher))) goto merr;
155 }
156
157 /* prf can stay NULL because we are using hmacWithSHA1 */
158
159 /* Now setup the PBE2PARAM keyfunc structure */
160
161 pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
162
163 /* Encode PBKDF2PARAM into parameter of pbe2 */
164
165 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
166
167 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
168 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
169 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
170
171 PBKDF2PARAM_free(kdf);
172 kdf = NULL;
173
174 /* Now set up top level AlgorithmIdentifier */
175
176 if(!(ret = X509_ALGOR_new())) goto merr;
177 if(!(ret->parameter = ASN1_TYPE_new())) goto merr;
178
179 ret->algorithm = OBJ_nid2obj(NID_pbes2);
180
181 /* Encode PBE2PARAM into parameter */
182
183 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
184 &ret->parameter->value.sequence)) goto merr;
185 ret->parameter->type = V_ASN1_SEQUENCE;
186
187 PBE2PARAM_free(pbe2);
188 pbe2 = NULL;
189
190 return ret;
191
192 merr:
193 ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
194
195 err:
196 PBE2PARAM_free(pbe2);
197 /* Note 'scheme' is freed as part of pbe2 */
198 M_ASN1_OCTET_STRING_free(osalt);
199 PBKDF2PARAM_free(kdf);
200 X509_ALGOR_free(kalg);
201 X509_ALGOR_free(ret);
202
203 return NULL;
204
205}
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
deleted file mode 100644
index 24b409132f..0000000000
--- a/src/lib/libcrypto/asn1/p8_pkey.c
+++ /dev/null
@@ -1,84 +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/asn1t.h>
62#include <openssl/x509.h>
63
64/* Minor tweak to operation: zero private key data */
65static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 /* Since the structure must still be valid use ASN1_OP_FREE_PRE */
68 if(operation == ASN1_OP_FREE_PRE) {
69 PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval;
70 if (key->pkey->value.octet_string)
71 OPENSSL_cleanse(key->pkey->value.octet_string->data,
72 key->pkey->value.octet_string->length);
73 }
74 return 1;
75}
76
77ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = {
78 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER),
79 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR),
80 ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_ANY),
81 ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0)
82} ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
83
84IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c
deleted file mode 100644
index 397332d9b8..0000000000
--- a/src/lib/libcrypto/asn1/t_bitst.c
+++ /dev/null
@@ -1,102 +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) {
88 if(!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
89 return 0;
90 }
91 return 1;
92}
93
94int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
95{
96 BIT_STRING_BITNAME *bnam;
97 for(bnam = tbl; bnam->lname; bnam++) {
98 if(!strcmp(bnam->sname, name) ||
99 !strcmp(bnam->lname, name) ) return bnam->bitnum;
100 }
101 return -1;
102}
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
deleted file mode 100644
index 757c148df8..0000000000
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ /dev/null
@@ -1,134 +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
67#ifndef OPENSSL_NO_FP_API
68int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
69 {
70 BIO *b;
71 int ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=X509_CRL_print(b, x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85int X509_CRL_print(BIO *out, X509_CRL *x)
86{
87 STACK_OF(X509_REVOKED) *rev;
88 X509_REVOKED *r;
89 long l;
90 int i, n;
91 char *p;
92
93 BIO_printf(out, "Certificate Revocation List (CRL):\n");
94 l = X509_CRL_get_version(x);
95 BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l);
96 i = OBJ_obj2nid(x->sig_alg->algorithm);
97 BIO_printf(out, "%8sSignature Algorithm: %s\n", "",
98 (i == NID_undef) ? "NONE" : OBJ_nid2ln(i));
99 p=X509_NAME_oneline(X509_CRL_get_issuer(x),NULL,0);
100 BIO_printf(out,"%8sIssuer: %s\n","",p);
101 OPENSSL_free(p);
102 BIO_printf(out,"%8sLast Update: ","");
103 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
104 BIO_printf(out,"\n%8sNext Update: ","");
105 if (X509_CRL_get_nextUpdate(x))
106 ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x));
107 else BIO_printf(out,"NONE");
108 BIO_printf(out,"\n");
109
110 n=X509_CRL_get_ext_count(x);
111 X509V3_extensions_print(out, "CRL extensions",
112 x->crl->extensions, 0, 8);
113
114 rev = X509_CRL_get_REVOKED(x);
115
116 if(sk_X509_REVOKED_num(rev) > 0)
117 BIO_printf(out, "Revoked Certificates:\n");
118 else BIO_printf(out, "No Revoked Certificates.\n");
119
120 for(i = 0; i < sk_X509_REVOKED_num(rev); i++) {
121 r = sk_X509_REVOKED_value(rev, i);
122 BIO_printf(out," Serial Number: ");
123 i2a_ASN1_INTEGER(out,r->serialNumber);
124 BIO_printf(out,"\n Revocation Date: ","");
125 ASN1_TIME_print(out,r->revocationDate);
126 BIO_printf(out,"\n");
127 X509V3_extensions_print(out, "CRL entry extensions",
128 r->extensions, 0, 8);
129 }
130 X509_signature_print(out, x->sig_alg, x->signature);
131
132 return 1;
133
134}
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
deleted file mode 100644
index d15006e654..0000000000
--- a/src/lib/libcrypto/asn1/t_pkey.c
+++ /dev/null
@@ -1,387 +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 OPENSSL_NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef OPENSSL_NO_DH
67#include <openssl/dh.h>
68#endif
69#ifndef OPENSSL_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 OPENSSL_NO_RSA
76#ifndef OPENSSL_NO_FP_API
77int RSA_print_fp(FILE *fp, const 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, const RSA *x, int off)
95 {
96 char str[128];
97 const char *s;
98 unsigned char *m=NULL;
99 int ret=0;
100 size_t buf_len=0, i;
101
102 if (x->n)
103 buf_len = (size_t)BN_num_bytes(x->n);
104 if (x->e)
105 if (buf_len < (i = (size_t)BN_num_bytes(x->e)))
106 buf_len = i;
107 if (x->d)
108 if (buf_len < (i = (size_t)BN_num_bytes(x->d)))
109 buf_len = i;
110 if (x->p)
111 if (buf_len < (i = (size_t)BN_num_bytes(x->p)))
112 buf_len = i;
113 if (x->q)
114 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
115 buf_len = i;
116 if (x->dmp1)
117 if (buf_len < (i = (size_t)BN_num_bytes(x->dmp1)))
118 buf_len = i;
119 if (x->dmq1)
120 if (buf_len < (i = (size_t)BN_num_bytes(x->dmq1)))
121 buf_len = i;
122 if (x->iqmp)
123 if (buf_len < (i = (size_t)BN_num_bytes(x->iqmp)))
124 buf_len = i;
125
126 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
127 if (m == NULL)
128 {
129 RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
130 goto err;
131 }
132
133 if (x->d != NULL)
134 {
135 if(!BIO_indent(bp,off,128))
136 goto err;
137 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n))
138 <= 0) goto err;
139 }
140
141 if (x->d == NULL)
142 BIO_snprintf(str,sizeof str,"Modulus (%d bit):",BN_num_bits(x->n));
143 else
144 BUF_strlcpy(str,"modulus:",sizeof str);
145 if (!print(bp,str,x->n,m,off)) goto err;
146 s=(x->d == NULL)?"Exponent:":"publicExponent:";
147 if (!print(bp,s,x->e,m,off)) goto err;
148 if (!print(bp,"privateExponent:",x->d,m,off)) goto err;
149 if (!print(bp,"prime1:",x->p,m,off)) goto err;
150 if (!print(bp,"prime2:",x->q,m,off)) goto err;
151 if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err;
152 if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err;
153 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
154 ret=1;
155err:
156 if (m != NULL) OPENSSL_free(m);
157 return(ret);
158 }
159#endif /* OPENSSL_NO_RSA */
160
161#ifndef OPENSSL_NO_DSA
162#ifndef OPENSSL_NO_FP_API
163int DSA_print_fp(FILE *fp, const DSA *x, int off)
164 {
165 BIO *b;
166 int ret;
167
168 if ((b=BIO_new(BIO_s_file())) == NULL)
169 {
170 DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
171 return(0);
172 }
173 BIO_set_fp(b,fp,BIO_NOCLOSE);
174 ret=DSA_print(b,x,off);
175 BIO_free(b);
176 return(ret);
177 }
178#endif
179
180int DSA_print(BIO *bp, const DSA *x, int off)
181 {
182 unsigned char *m=NULL;
183 int ret=0;
184 size_t buf_len=0,i;
185
186 if (x->p)
187 buf_len = (size_t)BN_num_bytes(x->p);
188 if (x->q)
189 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
190 buf_len = i;
191 if (x->g)
192 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
193 buf_len = i;
194 if (x->priv_key)
195 if (buf_len < (i = (size_t)BN_num_bytes(x->priv_key)))
196 buf_len = i;
197 if (x->pub_key)
198 if (buf_len < (i = (size_t)BN_num_bytes(x->pub_key)))
199 buf_len = i;
200
201 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
202 if (m == NULL)
203 {
204 DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
205 goto err;
206 }
207
208 if (x->priv_key != NULL)
209 {
210 if(!BIO_indent(bp,off,128))
211 goto err;
212 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p))
213 <= 0) goto err;
214 }
215
216 if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off))
217 goto err;
218 if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off))
219 goto err;
220 if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err;
221 if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err;
222 if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err;
223 ret=1;
224err:
225 if (m != NULL) OPENSSL_free(m);
226 return(ret);
227 }
228#endif /* !OPENSSL_NO_DSA */
229
230static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
231 int off)
232 {
233 int n,i;
234 const char *neg;
235
236 if (num == NULL) return(1);
237 neg=(num->neg)?"-":"";
238 if(!BIO_indent(bp,off,128))
239 return 0;
240
241 if (BN_num_bytes(num) <= BN_BYTES)
242 {
243 if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
244 (unsigned long)num->d[0],neg,(unsigned long)num->d[0])
245 <= 0) return(0);
246 }
247 else
248 {
249 buf[0]=0;
250 if (BIO_printf(bp,"%s%s",number,
251 (neg[0] == '-')?" (Negative)":"") <= 0)
252 return(0);
253 n=BN_bn2bin(num,&buf[1]);
254
255 if (buf[1] & 0x80)
256 n++;
257 else buf++;
258
259 for (i=0; i<n; i++)
260 {
261 if ((i%15) == 0)
262 {
263 if(BIO_puts(bp,"\n") <= 0
264 || !BIO_indent(bp,off+4,128))
265 return 0;
266 }
267 if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")
268 <= 0) return(0);
269 }
270 if (BIO_write(bp,"\n",1) <= 0) return(0);
271 }
272 return(1);
273 }
274
275#ifndef OPENSSL_NO_DH
276#ifndef OPENSSL_NO_FP_API
277int DHparams_print_fp(FILE *fp, const DH *x)
278 {
279 BIO *b;
280 int ret;
281
282 if ((b=BIO_new(BIO_s_file())) == NULL)
283 {
284 DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
285 return(0);
286 }
287 BIO_set_fp(b,fp,BIO_NOCLOSE);
288 ret=DHparams_print(b, x);
289 BIO_free(b);
290 return(ret);
291 }
292#endif
293
294int DHparams_print(BIO *bp, const DH *x)
295 {
296 unsigned char *m=NULL;
297 int reason=ERR_R_BUF_LIB,ret=0;
298 size_t buf_len=0, i;
299
300 if (x->p)
301 buf_len = (size_t)BN_num_bytes(x->p);
302 if (x->g)
303 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
304 buf_len = i;
305 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
306 if (m == NULL)
307 {
308 reason=ERR_R_MALLOC_FAILURE;
309 goto err;
310 }
311
312 if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n",
313 BN_num_bits(x->p)) <= 0)
314 goto err;
315 if (!print(bp,"prime:",x->p,m,4)) goto err;
316 if (!print(bp,"generator:",x->g,m,4)) goto err;
317 if (x->length != 0)
318 {
319 if (BIO_printf(bp," recommended-private-length: %d bits\n",
320 (int)x->length) <= 0) goto err;
321 }
322 ret=1;
323 if (0)
324 {
325err:
326 DHerr(DH_F_DHPARAMS_PRINT,reason);
327 }
328 if (m != NULL) OPENSSL_free(m);
329 return(ret);
330 }
331#endif
332
333#ifndef OPENSSL_NO_DSA
334#ifndef OPENSSL_NO_FP_API
335int DSAparams_print_fp(FILE *fp, const DSA *x)
336 {
337 BIO *b;
338 int ret;
339
340 if ((b=BIO_new(BIO_s_file())) == NULL)
341 {
342 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
343 return(0);
344 }
345 BIO_set_fp(b,fp,BIO_NOCLOSE);
346 ret=DSAparams_print(b, x);
347 BIO_free(b);
348 return(ret);
349 }
350#endif
351
352int DSAparams_print(BIO *bp, const DSA *x)
353 {
354 unsigned char *m=NULL;
355 int reason=ERR_R_BUF_LIB,ret=0;
356 size_t buf_len=0,i;
357
358 if (x->p)
359 buf_len = (size_t)BN_num_bytes(x->p);
360 if (x->q)
361 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
362 buf_len = i;
363 if (x->g)
364 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
365 buf_len = i;
366 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
367 if (m == NULL)
368 {
369 reason=ERR_R_MALLOC_FAILURE;
370 goto err;
371 }
372
373 if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n",
374 BN_num_bits(x->p)) <= 0)
375 goto err;
376 if (!print(bp,"p:",x->p,m,4)) goto err;
377 if (!print(bp,"q:",x->q,m,4)) goto err;
378 if (!print(bp,"g:",x->g,m,4)) goto err;
379 ret=1;
380err:
381 if (m != NULL) OPENSSL_free(m);
382 DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
383 return(ret);
384 }
385
386#endif /* !OPENSSL_NO_DSA */
387
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
deleted file mode 100644
index 740cee80c0..0000000000
--- a/src/lib/libcrypto/asn1/t_req.c
+++ /dev/null
@@ -1,276 +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 OPENSSL_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_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag)
86 {
87 unsigned long l;
88 int i;
89 const char *neg;
90 X509_REQ_INFO *ri;
91 EVP_PKEY *pkey;
92 STACK_OF(X509_ATTRIBUTE) *sk;
93 STACK_OF(X509_EXTENSION) *exts;
94 char mlch = ' ';
95 int nmindent = 0;
96
97 if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
98 mlch = '\n';
99 nmindent = 12;
100 }
101
102 if(nmflags == X509_FLAG_COMPAT)
103 nmindent = 16;
104
105
106 ri=x->req_info;
107 if(!(cflag & X509_FLAG_NO_HEADER))
108 {
109 if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err;
110 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
111 }
112 if(!(cflag & X509_FLAG_NO_VERSION))
113 {
114 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
115 l=0;
116 for (i=0; i<ri->version->length; i++)
117 { l<<=8; l+=ri->version->data[i]; }
118 if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,
119 l) <= 0)
120 goto err;
121 }
122 if(!(cflag & X509_FLAG_NO_SUBJECT))
123 {
124 if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
125 if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err;
126 if (BIO_write(bp,"\n",1) <= 0) goto err;
127 }
128 if(!(cflag & X509_FLAG_NO_PUBKEY))
129 {
130 if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
131 goto err;
132 if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
133 goto err;
134 if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)
135 goto err;
136 if (BIO_puts(bp, "\n") <= 0)
137 goto err;
138
139 pkey=X509_REQ_get_pubkey(x);
140 if (pkey == NULL)
141 {
142 BIO_printf(bp,"%12sUnable to load Public Key\n","");
143 ERR_print_errors(bp);
144 }
145 else
146#ifndef OPENSSL_NO_RSA
147 if (pkey->type == EVP_PKEY_RSA)
148 {
149 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
150 BN_num_bits(pkey->pkey.rsa->n));
151 RSA_print(bp,pkey->pkey.rsa,16);
152 }
153 else
154#endif
155#ifndef OPENSSL_NO_DSA
156 if (pkey->type == EVP_PKEY_DSA)
157 {
158 BIO_printf(bp,"%12sDSA Public Key:\n","");
159 DSA_print(bp,pkey->pkey.dsa,16);
160 }
161 else
162#endif
163 BIO_printf(bp,"%12sUnknown Public Key:\n","");
164
165 EVP_PKEY_free(pkey);
166 }
167
168 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
169 {
170 /* may not be */
171 if(BIO_printf(bp,"%8sAttributes:\n","") <= 0)
172 goto err;
173
174 sk=x->req_info->attributes;
175 if (sk_X509_ATTRIBUTE_num(sk) == 0)
176 {
177 if(BIO_printf(bp,"%12sa0:00\n","") <= 0)
178 goto err;
179 }
180 else
181 {
182 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
183 {
184 ASN1_TYPE *at;
185 X509_ATTRIBUTE *a;
186 ASN1_BIT_STRING *bs=NULL;
187 ASN1_TYPE *t;
188 int j,type=0,count=1,ii=0;
189
190 a=sk_X509_ATTRIBUTE_value(sk,i);
191 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
192 continue;
193 if(BIO_printf(bp,"%12s","") <= 0)
194 goto err;
195 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
196 {
197 if (a->single)
198 {
199 t=a->value.single;
200 type=t->type;
201 bs=t->value.bit_string;
202 }
203 else
204 {
205 ii=0;
206 count=sk_ASN1_TYPE_num(a->value.set);
207get_next:
208 at=sk_ASN1_TYPE_value(a->value.set,ii);
209 type=at->type;
210 bs=at->value.asn1_string;
211 }
212 }
213 for (j=25-j; j>0; j--)
214 if (BIO_write(bp," ",1) != 1) goto err;
215 if (BIO_puts(bp,":") <= 0) goto err;
216 if ( (type == V_ASN1_PRINTABLESTRING) ||
217 (type == V_ASN1_T61STRING) ||
218 (type == V_ASN1_IA5STRING))
219 {
220 if (BIO_write(bp,(char *)bs->data,bs->length)
221 != bs->length)
222 goto err;
223 BIO_puts(bp,"\n");
224 }
225 else
226 {
227 BIO_puts(bp,"unable to print attribute\n");
228 }
229 if (++ii < count) goto get_next;
230 }
231 }
232 }
233 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
234 {
235 exts = X509_REQ_get_extensions(x);
236 if(exts)
237 {
238 BIO_printf(bp,"%8sRequested Extensions:\n","");
239 for (i=0; i<sk_X509_EXTENSION_num(exts); i++)
240 {
241 ASN1_OBJECT *obj;
242 X509_EXTENSION *ex;
243 int j;
244 ex=sk_X509_EXTENSION_value(exts, i);
245 if (BIO_printf(bp,"%12s","") <= 0) goto err;
246 obj=X509_EXTENSION_get_object(ex);
247 i2a_ASN1_OBJECT(bp,obj);
248 j=X509_EXTENSION_get_critical(ex);
249 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
250 goto err;
251 if(!X509V3_EXT_print(bp, ex, 0, 16))
252 {
253 BIO_printf(bp, "%16s", "");
254 M_ASN1_OCTET_STRING_print(bp,ex->value);
255 }
256 if (BIO_write(bp,"\n",1) <= 0) goto err;
257 }
258 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
259 }
260 }
261
262 if(!(cflag & X509_FLAG_NO_SIGDUMP))
263 {
264 if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err;
265 }
266
267 return(1);
268err:
269 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
270 return(0);
271 }
272
273int X509_REQ_print(BIO *bp, X509_REQ *x)
274 {
275 return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
276 }
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c
deleted file mode 100644
index 5abfbc815e..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.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 OPENSSL_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 OPENSSL_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 30f68561b7..0000000000
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ /dev/null
@@ -1,505 +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 OPENSSL_NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef OPENSSL_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 OPENSSL_NO_FP_API
74int X509_print_fp(FILE *fp, X509 *x)
75 {
76 return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
77 }
78
79int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag)
80 {
81 BIO *b;
82 int ret;
83
84 if ((b=BIO_new(BIO_s_file())) == NULL)
85 {
86 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
87 return(0);
88 }
89 BIO_set_fp(b,fp,BIO_NOCLOSE);
90 ret=X509_print_ex(b, x, nmflag, cflag);
91 BIO_free(b);
92 return(ret);
93 }
94#endif
95
96int X509_print(BIO *bp, X509 *x)
97{
98 return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
99}
100
101int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
102 {
103 long l;
104 int ret=0,i;
105 char *m=NULL,mlch = ' ';
106 int nmindent = 0;
107 X509_CINF *ci;
108 ASN1_INTEGER *bs;
109 EVP_PKEY *pkey=NULL;
110 const char *neg;
111 ASN1_STRING *str=NULL;
112
113 if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
114 mlch = '\n';
115 nmindent = 12;
116 }
117
118 if(nmflags == X509_FLAG_COMPAT)
119 nmindent = 16;
120
121 ci=x->cert_info;
122 if(!(cflag & X509_FLAG_NO_HEADER))
123 {
124 if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err;
125 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
126 }
127 if(!(cflag & X509_FLAG_NO_VERSION))
128 {
129 l=X509_get_version(x);
130 if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err;
131 }
132 if(!(cflag & X509_FLAG_NO_SERIAL))
133 {
134
135 if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
136
137 bs=X509_get_serialNumber(x);
138 if (bs->length <= 4)
139 {
140 l=ASN1_INTEGER_get(bs);
141 if (l < 0)
142 {
143 l= -l;
144 neg="-";
145 }
146 else
147 neg="";
148 if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0)
149 goto err;
150 }
151 else
152 {
153 neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":"";
154 if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err;
155
156 for (i=0; i<bs->length; i++)
157 {
158 if (BIO_printf(bp,"%02x%c",bs->data[i],
159 ((i+1 == bs->length)?'\n':':')) <= 0)
160 goto err;
161 }
162 }
163
164 }
165
166 if(!(cflag & X509_FLAG_NO_SIGNAME))
167 {
168 if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0)
169 goto err;
170 if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0)
171 goto err;
172 if (BIO_puts(bp, "\n") <= 0)
173 goto err;
174 }
175
176 if(!(cflag & X509_FLAG_NO_ISSUER))
177 {
178 if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err;
179 if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err;
180 if (BIO_write(bp,"\n",1) <= 0) goto err;
181 }
182 if(!(cflag & X509_FLAG_NO_VALIDITY))
183 {
184 if (BIO_write(bp," Validity\n",17) <= 0) goto err;
185 if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
186 if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
187 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err;
188 if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
189 if (BIO_write(bp,"\n",1) <= 0) goto err;
190 }
191 if(!(cflag & X509_FLAG_NO_SUBJECT))
192 {
193 if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
194 if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err;
195 if (BIO_write(bp,"\n",1) <= 0) goto err;
196 }
197 if(!(cflag & X509_FLAG_NO_PUBKEY))
198 {
199 if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
200 goto err;
201 if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
202 goto err;
203 if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0)
204 goto err;
205 if (BIO_puts(bp, "\n") <= 0)
206 goto err;
207
208 pkey=X509_get_pubkey(x);
209 if (pkey == NULL)
210 {
211 BIO_printf(bp,"%12sUnable to load Public Key\n","");
212 ERR_print_errors(bp);
213 }
214 else
215#ifndef OPENSSL_NO_RSA
216 if (pkey->type == EVP_PKEY_RSA)
217 {
218 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
219 BN_num_bits(pkey->pkey.rsa->n));
220 RSA_print(bp,pkey->pkey.rsa,16);
221 }
222 else
223#endif
224#ifndef OPENSSL_NO_DSA
225 if (pkey->type == EVP_PKEY_DSA)
226 {
227 BIO_printf(bp,"%12sDSA Public Key:\n","");
228 DSA_print(bp,pkey->pkey.dsa,16);
229 }
230 else
231#endif
232 BIO_printf(bp,"%12sUnknown Public Key:\n","");
233
234 EVP_PKEY_free(pkey);
235 }
236
237 if (!(cflag & X509_FLAG_NO_EXTENSIONS))
238 X509V3_extensions_print(bp, "X509v3 extensions",
239 ci->extensions, cflag, 8);
240
241 if(!(cflag & X509_FLAG_NO_SIGDUMP))
242 {
243 if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err;
244 }
245 if(!(cflag & X509_FLAG_NO_AUX))
246 {
247 if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err;
248 }
249 ret=1;
250err:
251 if (str != NULL) ASN1_STRING_free(str);
252 if (m != NULL) OPENSSL_free(m);
253 return(ret);
254 }
255
256int X509_ocspid_print (BIO *bp, X509 *x)
257 {
258 unsigned char *der=NULL ;
259 unsigned char *dertmp;
260 int derlen;
261 int i;
262 unsigned char SHA1md[SHA_DIGEST_LENGTH];
263
264 /* display the hash of the subject as it would appear
265 in OCSP requests */
266 if (BIO_printf(bp," Subject OCSP hash: ") <= 0)
267 goto err;
268 derlen = i2d_X509_NAME(x->cert_info->subject, NULL);
269 if ((der = dertmp = (unsigned char *)OPENSSL_malloc (derlen)) == NULL)
270 goto err;
271 i2d_X509_NAME(x->cert_info->subject, &dertmp);
272
273 EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL);
274 for (i=0; i < SHA_DIGEST_LENGTH; i++)
275 {
276 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err;
277 }
278 OPENSSL_free (der);
279 der=NULL;
280
281 /* display the hash of the public key as it would appear
282 in OCSP requests */
283 if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0)
284 goto err;
285
286 EVP_Digest(x->cert_info->key->public_key->data,
287 x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL);
288 for (i=0; i < SHA_DIGEST_LENGTH; i++)
289 {
290 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0)
291 goto err;
292 }
293 BIO_printf(bp,"\n");
294
295 return (1);
296err:
297 if (der != NULL) OPENSSL_free(der);
298 return(0);
299 }
300
301int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
302{
303 unsigned char *s;
304 int i, n;
305 if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0;
306 if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
307
308 n=sig->length;
309 s=sig->data;
310 for (i=0; i<n; i++)
311 {
312 if ((i%18) == 0)
313 if (BIO_write(bp,"\n ",9) <= 0) return 0;
314 if (BIO_printf(bp,"%02x%s",s[i],
315 ((i+1) == n)?"":":") <= 0) return 0;
316 }
317 if (BIO_write(bp,"\n",1) != 1) return 0;
318 return 1;
319}
320
321int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
322 {
323 int i,n;
324 char buf[80],*p;
325
326 if (v == NULL) return(0);
327 n=0;
328 p=(char *)v->data;
329 for (i=0; i<v->length; i++)
330 {
331 if ((p[i] > '~') || ((p[i] < ' ') &&
332 (p[i] != '\n') && (p[i] != '\r')))
333 buf[n]='.';
334 else
335 buf[n]=p[i];
336 n++;
337 if (n >= 80)
338 {
339 if (BIO_write(bp,buf,n) <= 0)
340 return(0);
341 n=0;
342 }
343 }
344 if (n > 0)
345 if (BIO_write(bp,buf,n) <= 0)
346 return(0);
347 return(1);
348 }
349
350int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
351{
352 if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
353 if(tm->type == V_ASN1_GENERALIZEDTIME)
354 return ASN1_GENERALIZEDTIME_print(bp, tm);
355 BIO_write(bp,"Bad time value",14);
356 return(0);
357}
358
359static const char *mon[12]=
360 {
361 "Jan","Feb","Mar","Apr","May","Jun",
362 "Jul","Aug","Sep","Oct","Nov","Dec"
363 };
364
365int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
366 {
367 char *v;
368 int gmt=0;
369 int i;
370 int y=0,M=0,d=0,h=0,m=0,s=0;
371
372 i=tm->length;
373 v=(char *)tm->data;
374
375 if (i < 12) goto err;
376 if (v[i-1] == 'Z') gmt=1;
377 for (i=0; i<12; i++)
378 if ((v[i] > '9') || (v[i] < '0')) goto err;
379 y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
380 M= (v[4]-'0')*10+(v[5]-'0');
381 if ((M > 12) || (M < 1)) goto err;
382 d= (v[6]-'0')*10+(v[7]-'0');
383 h= (v[8]-'0')*10+(v[9]-'0');
384 m= (v[10]-'0')*10+(v[11]-'0');
385 if ( (v[12] >= '0') && (v[12] <= '9') &&
386 (v[13] >= '0') && (v[13] <= '9'))
387 s= (v[12]-'0')*10+(v[13]-'0');
388
389 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
390 mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
391 return(0);
392 else
393 return(1);
394err:
395 BIO_write(bp,"Bad time value",14);
396 return(0);
397 }
398
399int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
400 {
401 char *v;
402 int gmt=0;
403 int i;
404 int y=0,M=0,d=0,h=0,m=0,s=0;
405
406 i=tm->length;
407 v=(char *)tm->data;
408
409 if (i < 10) goto err;
410 if (v[i-1] == 'Z') gmt=1;
411 for (i=0; i<10; i++)
412 if ((v[i] > '9') || (v[i] < '0')) goto err;
413 y= (v[0]-'0')*10+(v[1]-'0');
414 if (y < 50) y+=100;
415 M= (v[2]-'0')*10+(v[3]-'0');
416 if ((M > 12) || (M < 1)) goto err;
417 d= (v[4]-'0')*10+(v[5]-'0');
418 h= (v[6]-'0')*10+(v[7]-'0');
419 m= (v[8]-'0')*10+(v[9]-'0');
420 if ( (v[10] >= '0') && (v[10] <= '9') &&
421 (v[11] >= '0') && (v[11] <= '9'))
422 s= (v[10]-'0')*10+(v[11]-'0');
423
424 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
425 mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0)
426 return(0);
427 else
428 return(1);
429err:
430 BIO_write(bp,"Bad time value",14);
431 return(0);
432 }
433
434int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
435 {
436 char *s,*c,*b;
437 int ret=0,l,ll,i,first=1;
438
439 ll=80-2-obase;
440
441 b=s=X509_NAME_oneline(name,NULL,0);
442 if (!*s)
443 {
444 OPENSSL_free(b);
445 return 1;
446 }
447 s++; /* skip the first slash */
448
449 l=ll;
450 c=s;
451 for (;;)
452 {
453#ifndef CHARSET_EBCDIC
454 if ( ((*s == '/') &&
455 ((s[1] >= 'A') && (s[1] <= 'Z') && (
456 (s[2] == '=') ||
457 ((s[2] >= 'A') && (s[2] <= 'Z') &&
458 (s[3] == '='))
459 ))) ||
460 (*s == '\0'))
461#else
462 if ( ((*s == '/') &&
463 (isupper(s[1]) && (
464 (s[2] == '=') ||
465 (isupper(s[2]) &&
466 (s[3] == '='))
467 ))) ||
468 (*s == '\0'))
469#endif
470 {
471 if ((l <= 0) && !first)
472 {
473 first=0;
474 if (BIO_write(bp,"\n",1) != 1) goto err;
475 for (i=0; i<obase; i++)
476 {
477 if (BIO_write(bp," ",1) != 1) goto err;
478 }
479 l=ll;
480 }
481 i=s-c;
482 if (BIO_write(bp,c,i) != i) goto err;
483 c+=i;
484 c++;
485 if (*s != '\0')
486 {
487 if (BIO_write(bp,", ",2) != 2) goto err;
488 }
489 l--;
490 }
491 if (*s == '\0') break;
492 s++;
493 l--;
494 }
495
496 ret=1;
497 if (0)
498 {
499err:
500 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
501 }
502 OPENSSL_free(b);
503 return(ret);
504 }
505
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c
deleted file mode 100644
index ffbbfb51f4..0000000000
--- a/src/lib/libcrypto/asn1/t_x509a.c
+++ /dev/null
@@ -1,110 +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.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, sizeof oidstr,
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, sizeof oidstr,
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 if(aux->keyid) {
102 BIO_printf(out, "%*sKey Id: ", indent, "");
103 for(i = 0; i < aux->keyid->length; i++)
104 BIO_printf(out, "%s%02X",
105 i ? ":" : "",
106 aux->keyid->data[i]);
107 BIO_write(out,"\n",1);
108 }
109 return 1;
110}
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
deleted file mode 100644
index b7e916ef36..0000000000
--- a/src/lib/libcrypto/asn1/tasn_dec.c
+++ /dev/null
@@ -1,1023 +0,0 @@
1/* tasn_dec.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65#include <openssl/buffer.h>
66#include <openssl/err.h>
67
68static int asn1_check_eoc(unsigned char **in, long len);
69static int asn1_find_end(unsigned char **in, long len, char inf);
70static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass);
71static int collect_data(BUF_MEM *buf, unsigned char **p, long plen);
72static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
73 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx);
74static int asn1_template_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
75static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
76static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long len,
77 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
78
79/* Table to convert tags to bit values, used for MSTRING type */
80static unsigned long tag2bit[32]={
810, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
82B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
83B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
84B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
850, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
86B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */
87B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */
88B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */
89B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
90 };
91
92unsigned long ASN1_tag2bit(int tag)
93{
94 if((tag < 0) || (tag > 30)) return 0;
95 return tag2bit[tag];
96}
97
98/* Macro to initialize and invalidate the cache */
99
100#define asn1_tlc_clear(c) if(c) (c)->valid = 0
101
102/* Decode an ASN1 item, this currently behaves just
103 * like a standard 'd2i' function. 'in' points to
104 * a buffer to read the data from, in future we will
105 * have more advanced versions that can input data
106 * a piece at a time and this will simply be a special
107 * case.
108 */
109
110ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it)
111{
112 ASN1_TLC c;
113 ASN1_VALUE *ptmpval = NULL;
114 if(!pval) pval = &ptmpval;
115 asn1_tlc_clear(&c);
116 if(ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
117 return *pval;
118 return NULL;
119}
120
121int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt)
122{
123 ASN1_TLC c;
124 asn1_tlc_clear(&c);
125 return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
126}
127
128
129/* Decode an item, taking care of IMPLICIT tagging, if any.
130 * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
131 */
132
133int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
134 int tag, int aclass, char opt, ASN1_TLC *ctx)
135{
136 const ASN1_TEMPLATE *tt, *errtt = NULL;
137 const ASN1_COMPAT_FUNCS *cf;
138 const ASN1_EXTERN_FUNCS *ef;
139 const ASN1_AUX *aux = it->funcs;
140 ASN1_aux_cb *asn1_cb;
141 unsigned char *p, *q, imphack = 0, oclass;
142 char seq_eoc, seq_nolen, cst, isopt;
143 long tmplen;
144 int i;
145 int otag;
146 int ret = 0;
147 ASN1_VALUE *pchval, **pchptr, *ptmpval;
148 if(!pval) return 0;
149 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
150 else asn1_cb = 0;
151
152 switch(it->itype) {
153
154 case ASN1_ITYPE_PRIMITIVE:
155 if(it->templates) {
156 /* tagging or OPTIONAL is currently illegal on an item template
157 * because the flags can't get passed down. In practice this isn't
158 * a problem: we include the relevant flags from the item template
159 * in the template itself.
160 */
161 if ((tag != -1) || opt) {
162 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
163 goto err;
164 }
165 return asn1_template_ex_d2i(pval, in, len, it->templates, opt, ctx);
166 }
167 return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx);
168 break;
169
170 case ASN1_ITYPE_MSTRING:
171 p = *in;
172 /* Just read in tag and class */
173 ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx);
174 if(!ret) {
175 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
176 goto err;
177 }
178 /* Must be UNIVERSAL class */
179 if(oclass != V_ASN1_UNIVERSAL) {
180 /* If OPTIONAL, assume this is OK */
181 if(opt) return -1;
182 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);
183 goto err;
184 }
185 /* Check tag matches bit map */
186 if(!(ASN1_tag2bit(otag) & it->utype)) {
187 /* If OPTIONAL, assume this is OK */
188 if(opt) return -1;
189 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG);
190 goto err;
191 }
192 return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);
193
194 case ASN1_ITYPE_EXTERN:
195 /* Use new style d2i */
196 ef = it->funcs;
197 return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
198
199 case ASN1_ITYPE_COMPAT:
200 /* we must resort to old style evil hackery */
201 cf = it->funcs;
202
203 /* If OPTIONAL see if it is there */
204 if(opt) {
205 int exptag;
206 p = *in;
207 if(tag == -1) exptag = it->utype;
208 else exptag = tag;
209 /* Don't care about anything other than presence of expected tag */
210 ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx);
211 if(!ret) {
212 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
213 goto err;
214 }
215 if(ret == -1) return -1;
216 }
217 /* This is the old style evil hack IMPLICIT handling:
218 * since the underlying code is expecting a tag and
219 * class other than the one present we change the
220 * buffer temporarily then change it back afterwards.
221 * This doesn't and never did work for tags > 30.
222 *
223 * Yes this is *horrible* but it is only needed for
224 * old style d2i which will hopefully not be around
225 * for much longer.
226 * FIXME: should copy the buffer then modify it so
227 * the input buffer can be const: we should *always*
228 * copy because the old style d2i might modify the
229 * buffer.
230 */
231
232 if(tag != -1) {
233 p = *in;
234 imphack = *p;
235 *p = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | it->utype);
236 }
237
238 ptmpval = cf->asn1_d2i(pval, in, len);
239
240 if(tag != -1) *p = imphack;
241
242 if(ptmpval) return 1;
243 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
244 goto err;
245
246
247 case ASN1_ITYPE_CHOICE:
248 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
249 goto auxerr;
250
251 /* Allocate structure */
252 if(!*pval) {
253 if(!ASN1_item_ex_new(pval, it)) {
254 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
255 goto err;
256 }
257 }
258 /* CHOICE type, try each possibility in turn */
259 pchval = NULL;
260 p = *in;
261 for(i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
262 pchptr = asn1_get_field_ptr(pval, tt);
263 /* We mark field as OPTIONAL so its absence
264 * can be recognised.
265 */
266 ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
267 /* If field not present, try the next one */
268 if(ret == -1) continue;
269 /* If positive return, read OK, break loop */
270 if(ret > 0) break;
271 /* Otherwise must be an ASN1 parsing error */
272 errtt = tt;
273 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
274 goto err;
275 }
276 /* Did we fall off the end without reading anything? */
277 if(i == it->tcount) {
278 /* If OPTIONAL, this is OK */
279 if(opt) {
280 /* Free and zero it */
281 ASN1_item_ex_free(pval, it);
282 return -1;
283 }
284 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE);
285 goto err;
286 }
287 asn1_set_choice_selector(pval, i, it);
288 *in = p;
289 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
290 goto auxerr;
291 return 1;
292
293 case ASN1_ITYPE_SEQUENCE:
294 p = *in;
295 tmplen = len;
296
297 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
298 if(tag == -1) {
299 tag = V_ASN1_SEQUENCE;
300 aclass = V_ASN1_UNIVERSAL;
301 }
302 /* Get SEQUENCE length and update len, p */
303 ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx);
304 if(!ret) {
305 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
306 goto err;
307 } else if(ret == -1) return -1;
308 if(aux && (aux->flags & ASN1_AFLG_BROKEN)) {
309 len = tmplen - (p - *in);
310 seq_nolen = 1;
311 } else seq_nolen = seq_eoc; /* If indefinite we don't do a length check */
312 if(!cst) {
313 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
314 goto err;
315 }
316
317 if(!*pval) {
318 if(!ASN1_item_ex_new(pval, it)) {
319 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
320 goto err;
321 }
322 }
323 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
324 goto auxerr;
325
326 /* Get each field entry */
327 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
328 const ASN1_TEMPLATE *seqtt;
329 ASN1_VALUE **pseqval;
330 seqtt = asn1_do_adb(pval, tt, 1);
331 if(!seqtt) goto err;
332 pseqval = asn1_get_field_ptr(pval, seqtt);
333 /* Have we ran out of data? */
334 if(!len) break;
335 q = p;
336 if(asn1_check_eoc(&p, len)) {
337 if(!seq_eoc) {
338 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC);
339 goto err;
340 }
341 len -= p - q;
342 seq_eoc = 0;
343 q = p;
344 break;
345 }
346 /* This determines the OPTIONAL flag value. The field cannot
347 * be omitted if it is the last of a SEQUENCE and there is
348 * still data to be read. This isn't strictly necessary but
349 * it increases efficiency in some cases.
350 */
351 if(i == (it->tcount - 1)) isopt = 0;
352 else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
353 /* attempt to read in field, allowing each to be OPTIONAL */
354 ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);
355 if(!ret) {
356 errtt = seqtt;
357 goto err;
358 } else if(ret == -1) {
359 /* OPTIONAL component absent. Free and zero the field
360 */
361 ASN1_template_free(pseqval, seqtt);
362 continue;
363 }
364 /* Update length */
365 len -= p - q;
366 }
367 /* Check for EOC if expecting one */
368 if(seq_eoc && !asn1_check_eoc(&p, len)) {
369 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC);
370 goto err;
371 }
372 /* Check all data read */
373 if(!seq_nolen && len) {
374 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
375 goto err;
376 }
377
378 /* If we get here we've got no more data in the SEQUENCE,
379 * however we may not have read all fields so check all
380 * remaining are OPTIONAL and clear any that are.
381 */
382 for(; i < it->tcount; tt++, i++) {
383 const ASN1_TEMPLATE *seqtt;
384 seqtt = asn1_do_adb(pval, tt, 1);
385 if(!seqtt) goto err;
386 if(seqtt->flags & ASN1_TFLG_OPTIONAL) {
387 ASN1_VALUE **pseqval;
388 pseqval = asn1_get_field_ptr(pval, seqtt);
389 ASN1_template_free(pseqval, seqtt);
390 } else {
391 errtt = seqtt;
392 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING);
393 goto err;
394 }
395 }
396 /* Save encoding */
397 if(!asn1_enc_save(pval, *in, p - *in, it)) goto auxerr;
398 *in = p;
399 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
400 goto auxerr;
401 return 1;
402
403 default:
404 return 0;
405 }
406 auxerr:
407 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);
408 err:
409 ASN1_item_ex_free(pval, it);
410 if(errtt) ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
411 else ERR_add_error_data(2, "Type=", it->sname);
412 return 0;
413}
414
415/* Templates are handled with two separate functions. One handles any EXPLICIT tag and the other handles the
416 * rest.
417 */
418
419static int asn1_template_ex_d2i(ASN1_VALUE **val, unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
420{
421 int flags, aclass;
422 int ret;
423 long len;
424 unsigned char *p, *q;
425 char exp_eoc;
426 if(!val) return 0;
427 flags = tt->flags;
428 aclass = flags & ASN1_TFLG_TAG_CLASS;
429
430 p = *in;
431
432 /* Check if EXPLICIT tag expected */
433 if(flags & ASN1_TFLG_EXPTAG) {
434 char cst;
435 /* Need to work out amount of data available to the inner content and where it
436 * starts: so read in EXPLICIT header to get the info.
437 */
438 ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx);
439 q = p;
440 if(!ret) {
441 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
442 return 0;
443 } else if(ret == -1) return -1;
444 if(!cst) {
445 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
446 return 0;
447 }
448 /* We've found the field so it can't be OPTIONAL now */
449 ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
450 if(!ret) {
451 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
452 return 0;
453 }
454 /* We read the field in OK so update length */
455 len -= p - q;
456 if(exp_eoc) {
457 /* If NDEF we must have an EOC here */
458 if(!asn1_check_eoc(&p, len)) {
459 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
460 goto err;
461 }
462 } else {
463 /* Otherwise we must hit the EXPLICIT tag end or its an error */
464 if(len) {
465 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
466 goto err;
467 }
468 }
469 } else
470 return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
471
472 *in = p;
473 return 1;
474
475 err:
476 ASN1_template_free(val, tt);
477 *val = NULL;
478 return 0;
479}
480
481static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
482{
483 int flags, aclass;
484 int ret;
485 unsigned char *p, *q;
486 if(!val) return 0;
487 flags = tt->flags;
488 aclass = flags & ASN1_TFLG_TAG_CLASS;
489
490 p = *in;
491 q = p;
492
493 if(flags & ASN1_TFLG_SK_MASK) {
494 /* SET OF, SEQUENCE OF */
495 int sktag, skaclass;
496 char sk_eoc;
497 /* First work out expected inner tag value */
498 if(flags & ASN1_TFLG_IMPTAG) {
499 sktag = tt->tag;
500 skaclass = aclass;
501 } else {
502 skaclass = V_ASN1_UNIVERSAL;
503 if(flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET;
504 else sktag = V_ASN1_SEQUENCE;
505 }
506 /* Get the tag */
507 ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx);
508 if(!ret) {
509 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
510 return 0;
511 } else if(ret == -1) return -1;
512 if(!*val) *val = (ASN1_VALUE *)sk_new_null();
513 else {
514 /* We've got a valid STACK: free up any items present */
515 STACK *sktmp = (STACK *)*val;
516 ASN1_VALUE *vtmp;
517 while(sk_num(sktmp) > 0) {
518 vtmp = (ASN1_VALUE *)sk_pop(sktmp);
519 ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
520 }
521 }
522
523 if(!*val) {
524 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_MALLOC_FAILURE);
525 goto err;
526 }
527 /* Read as many items as we can */
528 while(len > 0) {
529 ASN1_VALUE *skfield;
530 q = p;
531 /* See if EOC found */
532 if(asn1_check_eoc(&p, len)) {
533 if(!sk_eoc) {
534 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_UNEXPECTED_EOC);
535 goto err;
536 }
537 len -= p - q;
538 sk_eoc = 0;
539 break;
540 }
541 skfield = NULL;
542 if(!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
543 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
544 goto err;
545 }
546 len -= p - q;
547 if(!sk_push((STACK *)*val, (char *)skfield)) {
548 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_MALLOC_FAILURE);
549 goto err;
550 }
551 }
552 if(sk_eoc) {
553 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
554 goto err;
555 }
556 } else if(flags & ASN1_TFLG_IMPTAG) {
557 /* IMPLICIT tagging */
558 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
559 if(!ret) {
560 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
561 goto err;
562 } else if(ret == -1) return -1;
563 } else {
564 /* Nothing special */
565 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx);
566 if(!ret) {
567 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
568 goto err;
569 } else if(ret == -1) return -1;
570 }
571
572 *in = p;
573 return 1;
574
575 err:
576 ASN1_template_free(val, tt);
577 *val = NULL;
578 return 0;
579}
580
581static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long inlen,
582 const ASN1_ITEM *it,
583 int tag, int aclass, char opt, ASN1_TLC *ctx)
584{
585 int ret = 0, utype;
586 long plen;
587 char cst, inf, free_cont = 0;
588 unsigned char *p;
589 BUF_MEM buf;
590 unsigned char *cont = NULL;
591 long len;
592 if(!pval) {
593 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
594 return 0; /* Should never happen */
595 }
596
597 if(it->itype == ASN1_ITYPE_MSTRING) {
598 utype = tag;
599 tag = -1;
600 } else utype = it->utype;
601
602 if(utype == V_ASN1_ANY) {
603 /* If type is ANY need to figure out type from tag */
604 unsigned char oclass;
605 if(tag >= 0) {
606 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY);
607 return 0;
608 }
609 if(opt) {
610 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY);
611 return 0;
612 }
613 p = *in;
614 ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx);
615 if(!ret) {
616 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
617 return 0;
618 }
619 if(oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER;
620 }
621 if(tag == -1) {
622 tag = utype;
623 aclass = V_ASN1_UNIVERSAL;
624 }
625 p = *in;
626 /* Check header */
627 ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx);
628 if(!ret) {
629 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
630 return 0;
631 } else if(ret == -1) return -1;
632
633 ret = 0;
634 /* SEQUENCE, SET and "OTHER" are left in encoded form */
635 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
636 /* Clear context cache for type OTHER because the auto clear when
637 * we have a exact match wont work
638 */
639 if(utype == V_ASN1_OTHER) {
640 asn1_tlc_clear(ctx);
641 /* SEQUENCE and SET must be constructed */
642 } else if(!cst) {
643 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED);
644 return 0;
645 }
646
647 cont = *in;
648 /* If indefinite length constructed find the real end */
649 if(inf) {
650 if(!asn1_find_end(&p, plen, inf)) goto err;
651 len = p - cont;
652 } else {
653 len = p - cont + plen;
654 p += plen;
655 buf.data = NULL;
656 }
657 } else if(cst) {
658 buf.length = 0;
659 buf.max = 0;
660 buf.data = NULL;
661 /* Should really check the internal tags are correct but
662 * some things may get this wrong. The relevant specs
663 * say that constructed string types should be OCTET STRINGs
664 * internally irrespective of the type. So instead just check
665 * for UNIVERSAL class and ignore the tag.
666 */
667 if(!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) goto err;
668 len = buf.length;
669 /* Append a final null to string */
670 if(!BUF_MEM_grow_clean(&buf, len + 1)) {
671 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
672 return 0;
673 }
674 buf.data[len] = 0;
675 cont = (unsigned char *)buf.data;
676 free_cont = 1;
677 } else {
678 cont = p;
679 len = plen;
680 p += plen;
681 }
682
683 /* We now have content length and type: translate into a structure */
684 if(!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) goto err;
685
686 *in = p;
687 ret = 1;
688 err:
689 if(free_cont && buf.data) OPENSSL_free(buf.data);
690 return ret;
691}
692
693/* Translate ASN1 content octets into a structure */
694
695int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
696{
697 ASN1_VALUE **opval = NULL;
698 ASN1_STRING *stmp;
699 ASN1_TYPE *typ = NULL;
700 int ret = 0;
701 const ASN1_PRIMITIVE_FUNCS *pf;
702 ASN1_INTEGER **tint;
703 pf = it->funcs;
704 if(pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
705 /* If ANY type clear type and set pointer to internal value */
706 if(it->utype == V_ASN1_ANY) {
707 if(!*pval) {
708 typ = ASN1_TYPE_new();
709 *pval = (ASN1_VALUE *)typ;
710 } else typ = (ASN1_TYPE *)*pval;
711 if(utype != typ->type) ASN1_TYPE_set(typ, utype, NULL);
712 opval = pval;
713 pval = (ASN1_VALUE **)&typ->value.ptr;
714 }
715 switch(utype) {
716 case V_ASN1_OBJECT:
717 if(!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err;
718 break;
719
720 case V_ASN1_NULL:
721 if(len) {
722 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_NULL_IS_WRONG_LENGTH);
723 goto err;
724 }
725 *pval = (ASN1_VALUE *)1;
726 break;
727
728 case V_ASN1_BOOLEAN:
729 if(len != 1) {
730 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
731 goto err;
732 } else {
733 ASN1_BOOLEAN *tbool;
734 tbool = (ASN1_BOOLEAN *)pval;
735 *tbool = *cont;
736 }
737 break;
738
739 case V_ASN1_BIT_STRING:
740 if(!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err;
741 break;
742
743 case V_ASN1_INTEGER:
744 case V_ASN1_NEG_INTEGER:
745 case V_ASN1_ENUMERATED:
746 case V_ASN1_NEG_ENUMERATED:
747 tint = (ASN1_INTEGER **)pval;
748 if(!c2i_ASN1_INTEGER(tint, &cont, len)) goto err;
749 /* Fixup type to match the expected form */
750 (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
751 break;
752
753 case V_ASN1_OCTET_STRING:
754 case V_ASN1_NUMERICSTRING:
755 case V_ASN1_PRINTABLESTRING:
756 case V_ASN1_T61STRING:
757 case V_ASN1_VIDEOTEXSTRING:
758 case V_ASN1_IA5STRING:
759 case V_ASN1_UTCTIME:
760 case V_ASN1_GENERALIZEDTIME:
761 case V_ASN1_GRAPHICSTRING:
762 case V_ASN1_VISIBLESTRING:
763 case V_ASN1_GENERALSTRING:
764 case V_ASN1_UNIVERSALSTRING:
765 case V_ASN1_BMPSTRING:
766 case V_ASN1_UTF8STRING:
767 case V_ASN1_OTHER:
768 case V_ASN1_SET:
769 case V_ASN1_SEQUENCE:
770 default:
771 /* All based on ASN1_STRING and handled the same */
772 if(!*pval) {
773 stmp = ASN1_STRING_type_new(utype);
774 if(!stmp) {
775 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
776 goto err;
777 }
778 *pval = (ASN1_VALUE *)stmp;
779 } else {
780 stmp = (ASN1_STRING *)*pval;
781 stmp->type = utype;
782 }
783 /* If we've already allocated a buffer use it */
784 if(*free_cont) {
785 if(stmp->data) OPENSSL_free(stmp->data);
786 stmp->data = cont;
787 stmp->length = len;
788 *free_cont = 0;
789 } else {
790 if(!ASN1_STRING_set(stmp, cont, len)) {
791 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
792 ASN1_STRING_free(stmp);
793 *pval = NULL;
794 goto err;
795 }
796 }
797 break;
798 }
799 /* If ASN1_ANY and NULL type fix up value */
800 if(typ && utype==V_ASN1_NULL) typ->value.ptr = NULL;
801
802 ret = 1;
803 err:
804 if(!ret)
805 {
806 ASN1_TYPE_free(typ);
807 if (opval)
808 *opval = NULL;
809 }
810 return ret;
811}
812
813/* This function finds the end of an ASN1 structure when passed its maximum
814 * length, whether it is indefinite length and a pointer to the content.
815 * This is more efficient than calling asn1_collect because it does not
816 * recurse on each indefinite length header.
817 */
818
819static int asn1_find_end(unsigned char **in, long len, char inf)
820 {
821 int expected_eoc;
822 long plen;
823 unsigned char *p = *in, *q;
824 /* If not indefinite length constructed just add length */
825 if (inf == 0)
826 {
827 *in += len;
828 return 1;
829 }
830 expected_eoc = 1;
831 /* Indefinite length constructed form. Find the end when enough EOCs
832 * are found. If more indefinite length constructed headers
833 * are encountered increment the expected eoc count otherwise justi
834 * skip to the end of the data.
835 */
836 while (len > 0)
837 {
838 if(asn1_check_eoc(&p, len))
839 {
840 expected_eoc--;
841 if (expected_eoc == 0)
842 break;
843 len -= 2;
844 continue;
845 }
846 q = p;
847 /* Just read in a header: only care about the length */
848 if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
849 -1, 0, 0, NULL))
850 {
851 ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR);
852 return 0;
853 }
854 if (inf)
855 expected_eoc++;
856 else
857 p += plen;
858 len -= p - q;
859 }
860 if (expected_eoc)
861 {
862 ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC);
863 return 0;
864 }
865 *in = p;
866 return 1;
867 }
868
869/* This function collects the asn1 data from a constructred string
870 * type into a buffer. The values of 'in' and 'len' should refer
871 * to the contents of the constructed type and 'inf' should be set
872 * if it is indefinite length.
873 */
874
875static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass)
876{
877 unsigned char *p, *q;
878 long plen;
879 char cst, ininf;
880 p = *in;
881 inf &= 1;
882 while(len > 0) {
883 q = p;
884 /* Check for EOC */
885 if(asn1_check_eoc(&p, len)) {
886 /* EOC is illegal outside indefinite length constructed form */
887 if(!inf) {
888 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC);
889 return 0;
890 }
891 inf = 0;
892 break;
893 }
894 if(!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, len, tag, aclass, 0, NULL)) {
895 ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
896 return 0;
897 }
898 /* If indefinite length constructed update max length */
899 if(cst) {
900#ifdef OPENSSL_ALLOW_NESTED_ASN1_STRINGS
901 if (!asn1_collect(buf, &p, plen, ininf, tag, aclass))
902 return 0;
903#else
904 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING);
905 return 0;
906#endif
907 } else {
908 if(plen && !collect_data(buf, &p, plen)) return 0;
909 }
910 len -= p - q;
911 }
912 if(inf) {
913 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC);
914 return 0;
915 }
916 *in = p;
917 return 1;
918}
919
920static int collect_data(BUF_MEM *buf, unsigned char **p, long plen)
921{
922 int len;
923 if(buf) {
924 len = buf->length;
925 if(!BUF_MEM_grow_clean(buf, len + plen)) {
926 ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
927 return 0;
928 }
929 memcpy(buf->data + len, *p, plen);
930 }
931 *p += plen;
932 return 1;
933}
934
935/* Check for ASN1 EOC and swallow it if found */
936
937static int asn1_check_eoc(unsigned char **in, long len)
938{
939 unsigned char *p;
940 if(len < 2) return 0;
941 p = *in;
942 if(!p[0] && !p[1]) {
943 *in += 2;
944 return 1;
945 }
946 return 0;
947}
948
949/* Check an ASN1 tag and length: a bit like ASN1_get_object
950 * but it sets the length for indefinite length constructed
951 * form, we don't know the exact length but we can set an
952 * upper bound to the amount of data available minus the
953 * header length just read.
954 */
955
956static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
957 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx)
958{
959 int i;
960 int ptag, pclass;
961 long plen;
962 unsigned char *p, *q;
963 p = *in;
964 q = p;
965
966 if(ctx && ctx->valid) {
967 i = ctx->ret;
968 plen = ctx->plen;
969 pclass = ctx->pclass;
970 ptag = ctx->ptag;
971 p += ctx->hdrlen;
972 } else {
973 i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
974 if(ctx) {
975 ctx->ret = i;
976 ctx->plen = plen;
977 ctx->pclass = pclass;
978 ctx->ptag = ptag;
979 ctx->hdrlen = p - q;
980 ctx->valid = 1;
981 /* If definite length, and no error, length +
982 * header can't exceed total amount of data available.
983 */
984 if(!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
985 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG);
986 asn1_tlc_clear(ctx);
987 return 0;
988 }
989 }
990 }
991
992 if(i & 0x80) {
993 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);
994 asn1_tlc_clear(ctx);
995 return 0;
996 }
997 if(exptag >= 0) {
998 if((exptag != ptag) || (expclass != pclass)) {
999 /* If type is OPTIONAL, not an error, but indicate missing
1000 * type.
1001 */
1002 if(opt) return -1;
1003 asn1_tlc_clear(ctx);
1004 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);
1005 return 0;
1006 }
1007 /* We have a tag and class match, so assume we are going to do something with it */
1008 asn1_tlc_clear(ctx);
1009 }
1010
1011 if(i & 1) plen = len - (p - q);
1012
1013 if(inf) *inf = i & 1;
1014
1015 if(cst) *cst = i & V_ASN1_CONSTRUCTED;
1016
1017 if(olen) *olen = plen;
1018 if(oclass) *oclass = pclass;
1019 if(otag) *otag = ptag;
1020
1021 *in = p;
1022 return 1;
1023}
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c
deleted file mode 100644
index c675c3c832..0000000000
--- a/src/lib/libcrypto/asn1/tasn_enc.c
+++ /dev/null
@@ -1,500 +0,0 @@
1/* tasn_enc.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65
66static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
67static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *seq, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int isset);
68
69/* Encode an ASN1 item, this is compatible with the
70 * standard 'i2d' function. 'out' points to
71 * a buffer to output the data to, in future we will
72 * have more advanced versions that can output data
73 * a piece at a time and this will simply be a special
74 * case.
75 *
76 * The new i2d has one additional feature. If the output
77 * buffer is NULL (i.e. *out == NULL) then a buffer is
78 * allocated and populated with the encoding.
79 */
80
81
82int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
83{
84 if(out && !*out) {
85 unsigned char *p, *buf;
86 int len;
87 len = ASN1_item_ex_i2d(&val, NULL, it, -1, 0);
88 if(len <= 0) return len;
89 buf = OPENSSL_malloc(len);
90 if(!buf) return -1;
91 p = buf;
92 ASN1_item_ex_i2d(&val, &p, it, -1, 0);
93 *out = buf;
94 return len;
95 }
96
97 return ASN1_item_ex_i2d(&val, out, it, -1, 0);
98}
99
100/* Encode an item, taking care of IMPLICIT tagging (if any).
101 * This function performs the normal item handling: it can be
102 * used in external types.
103 */
104
105int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
106{
107 const ASN1_TEMPLATE *tt = NULL;
108 unsigned char *p = NULL;
109 int i, seqcontlen, seqlen;
110 ASN1_STRING *strtmp;
111 const ASN1_COMPAT_FUNCS *cf;
112 const ASN1_EXTERN_FUNCS *ef;
113 const ASN1_AUX *aux = it->funcs;
114 ASN1_aux_cb *asn1_cb;
115 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return 0;
116 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
117 else asn1_cb = 0;
118
119 switch(it->itype) {
120
121 case ASN1_ITYPE_PRIMITIVE:
122 if(it->templates)
123 return ASN1_template_i2d(pval, out, it->templates);
124 return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
125 break;
126
127 case ASN1_ITYPE_MSTRING:
128 strtmp = (ASN1_STRING *)*pval;
129 return asn1_i2d_ex_primitive(pval, out, it, -1, 0);
130
131 case ASN1_ITYPE_CHOICE:
132 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
133 return 0;
134 i = asn1_get_choice_selector(pval, it);
135 if((i >= 0) && (i < it->tcount)) {
136 ASN1_VALUE **pchval;
137 const ASN1_TEMPLATE *chtt;
138 chtt = it->templates + i;
139 pchval = asn1_get_field_ptr(pval, chtt);
140 return ASN1_template_i2d(pchval, out, chtt);
141 }
142 /* Fixme: error condition if selector out of range */
143 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
144 return 0;
145 break;
146
147 case ASN1_ITYPE_EXTERN:
148 /* If new style i2d it does all the work */
149 ef = it->funcs;
150 return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
151
152 case ASN1_ITYPE_COMPAT:
153 /* old style hackery... */
154 cf = it->funcs;
155 if(out) p = *out;
156 i = cf->asn1_i2d(*pval, out);
157 /* Fixup for IMPLICIT tag: note this messes up for tags > 30,
158 * but so did the old code. Tags > 30 are very rare anyway.
159 */
160 if(out && (tag != -1))
161 *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
162 return i;
163
164 case ASN1_ITYPE_SEQUENCE:
165 i = asn1_enc_restore(&seqcontlen, out, pval, it);
166 /* An error occurred */
167 if(i < 0) return 0;
168 /* We have a valid cached encoding... */
169 if(i > 0) return seqcontlen;
170 /* Otherwise carry on */
171 seqcontlen = 0;
172 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
173 if(tag == -1) {
174 tag = V_ASN1_SEQUENCE;
175 aclass = V_ASN1_UNIVERSAL;
176 }
177 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
178 return 0;
179 /* First work out sequence content length */
180 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
181 const ASN1_TEMPLATE *seqtt;
182 ASN1_VALUE **pseqval;
183 seqtt = asn1_do_adb(pval, tt, 1);
184 if(!seqtt) return 0;
185 pseqval = asn1_get_field_ptr(pval, seqtt);
186 /* FIXME: check for errors in enhanced version */
187 /* FIXME: special handling of indefinite length encoding */
188 seqcontlen += ASN1_template_i2d(pseqval, NULL, seqtt);
189 }
190 seqlen = ASN1_object_size(1, seqcontlen, tag);
191 if(!out) return seqlen;
192 /* Output SEQUENCE header */
193 ASN1_put_object(out, 1, seqcontlen, tag, aclass);
194 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
195 const ASN1_TEMPLATE *seqtt;
196 ASN1_VALUE **pseqval;
197 seqtt = asn1_do_adb(pval, tt, 1);
198 if(!seqtt) return 0;
199 pseqval = asn1_get_field_ptr(pval, seqtt);
200 /* FIXME: check for errors in enhanced version */
201 ASN1_template_i2d(pseqval, out, seqtt);
202 }
203 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
204 return 0;
205 return seqlen;
206
207 default:
208 return 0;
209 }
210 return 0;
211}
212
213int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt)
214{
215 int i, ret, flags, aclass;
216 flags = tt->flags;
217 aclass = flags & ASN1_TFLG_TAG_CLASS;
218 if(flags & ASN1_TFLG_SK_MASK) {
219 /* SET OF, SEQUENCE OF */
220 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
221 int isset, sktag, skaclass;
222 int skcontlen, sklen;
223 ASN1_VALUE *skitem;
224 if(!*pval) return 0;
225 if(flags & ASN1_TFLG_SET_OF) {
226 isset = 1;
227 /* 2 means we reorder */
228 if(flags & ASN1_TFLG_SEQUENCE_OF) isset = 2;
229 } else isset = 0;
230 /* First work out inner tag value */
231 if(flags & ASN1_TFLG_IMPTAG) {
232 sktag = tt->tag;
233 skaclass = aclass;
234 } else {
235 skaclass = V_ASN1_UNIVERSAL;
236 if(isset) sktag = V_ASN1_SET;
237 else sktag = V_ASN1_SEQUENCE;
238 }
239 /* Now work out length of items */
240 skcontlen = 0;
241 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
242 skitem = sk_ASN1_VALUE_value(sk, i);
243 skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
244 }
245 sklen = ASN1_object_size(1, skcontlen, sktag);
246 /* If EXPLICIT need length of surrounding tag */
247 if(flags & ASN1_TFLG_EXPTAG)
248 ret = ASN1_object_size(1, sklen, tt->tag);
249 else ret = sklen;
250
251 if(!out) return ret;
252
253 /* Now encode this lot... */
254 /* EXPLICIT tag */
255 if(flags & ASN1_TFLG_EXPTAG)
256 ASN1_put_object(out, 1, sklen, tt->tag, aclass);
257 /* SET or SEQUENCE and IMPLICIT tag */
258 ASN1_put_object(out, 1, skcontlen, sktag, skaclass);
259 /* And finally the stuff itself */
260 asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset);
261
262 return ret;
263 }
264
265 if(flags & ASN1_TFLG_EXPTAG) {
266 /* EXPLICIT tagging */
267 /* Find length of tagged item */
268 i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
269 if(!i) return 0;
270 /* Find length of EXPLICIT tag */
271 ret = ASN1_object_size(1, i, tt->tag);
272 if(out) {
273 /* Output tag and item */
274 ASN1_put_object(out, 1, i, tt->tag, aclass);
275 ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
276 }
277 return ret;
278 }
279 if(flags & ASN1_TFLG_IMPTAG) {
280 /* IMPLICIT tagging */
281 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), tt->tag, aclass);
282 }
283 /* Nothing special: treat as normal */
284 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
285}
286
287/* Temporary structure used to hold DER encoding of items for SET OF */
288
289typedef struct {
290 unsigned char *data;
291 int length;
292 ASN1_VALUE *field;
293} DER_ENC;
294
295static int der_cmp(const void *a, const void *b)
296{
297 const DER_ENC *d1 = a, *d2 = b;
298 int cmplen, i;
299 cmplen = (d1->length < d2->length) ? d1->length : d2->length;
300 i = memcmp(d1->data, d2->data, cmplen);
301 if(i) return i;
302 return d1->length - d2->length;
303}
304
305/* Output the content octets of SET OF or SEQUENCE OF */
306
307static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int do_sort)
308{
309 int i;
310 ASN1_VALUE *skitem;
311 unsigned char *tmpdat = NULL, *p = NULL;
312 DER_ENC *derlst = NULL, *tder;
313 if(do_sort) {
314 /* Don't need to sort less than 2 items */
315 if(sk_ASN1_VALUE_num(sk) < 2) do_sort = 0;
316 else {
317 derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst));
318 tmpdat = OPENSSL_malloc(skcontlen);
319 if(!derlst || !tmpdat) return 0;
320 }
321 }
322 /* If not sorting just output each item */
323 if(!do_sort) {
324 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
325 skitem = sk_ASN1_VALUE_value(sk, i);
326 ASN1_item_i2d(skitem, out, item);
327 }
328 return 1;
329 }
330 p = tmpdat;
331 /* Doing sort: build up a list of each member's DER encoding */
332 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
333 skitem = sk_ASN1_VALUE_value(sk, i);
334 tder->data = p;
335 tder->length = ASN1_item_i2d(skitem, &p, item);
336 tder->field = skitem;
337 }
338 /* Now sort them */
339 qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
340 /* Output sorted DER encoding */
341 p = *out;
342 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
343 memcpy(p, tder->data, tder->length);
344 p += tder->length;
345 }
346 *out = p;
347 /* If do_sort is 2 then reorder the STACK */
348 if(do_sort == 2) {
349 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
350 sk_ASN1_VALUE_set(sk, i, tder->field);
351 }
352 OPENSSL_free(derlst);
353 OPENSSL_free(tmpdat);
354 return 1;
355}
356
357static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
358{
359 int len;
360 int utype;
361 int usetag;
362
363 utype = it->utype;
364
365 /* Get length of content octets and maybe find
366 * out the underlying type.
367 */
368
369 len = asn1_ex_i2c(pval, NULL, &utype, it);
370
371 /* If SEQUENCE, SET or OTHER then header is
372 * included in pseudo content octets so don't
373 * include tag+length. We need to check here
374 * because the call to asn1_ex_i2c() could change
375 * utype.
376 */
377 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
378 (utype == V_ASN1_OTHER))
379 usetag = 0;
380 else usetag = 1;
381
382 /* -1 means omit type */
383
384 if(len == -1) return 0;
385
386 /* If not implicitly tagged get tag from underlying type */
387 if(tag == -1) tag = utype;
388
389 /* Output tag+length followed by content octets */
390 if(out) {
391 if(usetag) ASN1_put_object(out, 0, len, tag, aclass);
392 asn1_ex_i2c(pval, *out, &utype, it);
393 *out += len;
394 }
395
396 if(usetag) return ASN1_object_size(0, len, tag);
397 return len;
398}
399
400/* Produce content octets from a structure */
401
402int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, const ASN1_ITEM *it)
403{
404 ASN1_BOOLEAN *tbool = NULL;
405 ASN1_STRING *strtmp;
406 ASN1_OBJECT *otmp;
407 int utype;
408 unsigned char *cont, c;
409 int len;
410 const ASN1_PRIMITIVE_FUNCS *pf;
411 pf = it->funcs;
412 if(pf && pf->prim_i2c) return pf->prim_i2c(pval, cout, putype, it);
413
414 /* Should type be omitted? */
415 if((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
416 if(!*pval) return -1;
417 }
418
419 if(it->itype == ASN1_ITYPE_MSTRING) {
420 /* If MSTRING type set the underlying type */
421 strtmp = (ASN1_STRING *)*pval;
422 utype = strtmp->type;
423 *putype = utype;
424 } else if(it->utype == V_ASN1_ANY) {
425 /* If ANY set type and pointer to value */
426 ASN1_TYPE *typ;
427 typ = (ASN1_TYPE *)*pval;
428 utype = typ->type;
429 *putype = utype;
430 pval = (ASN1_VALUE **)&typ->value.ptr;
431 } else utype = *putype;
432
433 switch(utype) {
434 case V_ASN1_OBJECT:
435 otmp = (ASN1_OBJECT *)*pval;
436 cont = otmp->data;
437 len = otmp->length;
438 break;
439
440 case V_ASN1_NULL:
441 cont = NULL;
442 len = 0;
443 break;
444
445 case V_ASN1_BOOLEAN:
446 tbool = (ASN1_BOOLEAN *)pval;
447 if(*tbool == -1) return -1;
448 if (it->utype != V_ASN1_ANY)
449 {
450 /* Default handling if value == size field then omit */
451 if(*tbool && (it->size > 0)) return -1;
452 if(!*tbool && !it->size) return -1;
453 }
454 c = (unsigned char)*tbool;
455 cont = &c;
456 len = 1;
457 break;
458
459 case V_ASN1_BIT_STRING:
460 return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL);
461 break;
462
463 case V_ASN1_INTEGER:
464 case V_ASN1_NEG_INTEGER:
465 case V_ASN1_ENUMERATED:
466 case V_ASN1_NEG_ENUMERATED:
467 /* These are all have the same content format
468 * as ASN1_INTEGER
469 */
470 return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
471 break;
472
473 case V_ASN1_OCTET_STRING:
474 case V_ASN1_NUMERICSTRING:
475 case V_ASN1_PRINTABLESTRING:
476 case V_ASN1_T61STRING:
477 case V_ASN1_VIDEOTEXSTRING:
478 case V_ASN1_IA5STRING:
479 case V_ASN1_UTCTIME:
480 case V_ASN1_GENERALIZEDTIME:
481 case V_ASN1_GRAPHICSTRING:
482 case V_ASN1_VISIBLESTRING:
483 case V_ASN1_GENERALSTRING:
484 case V_ASN1_UNIVERSALSTRING:
485 case V_ASN1_BMPSTRING:
486 case V_ASN1_UTF8STRING:
487 case V_ASN1_SEQUENCE:
488 case V_ASN1_SET:
489 default:
490 /* All based on ASN1_STRING and handled the same */
491 strtmp = (ASN1_STRING *)*pval;
492 cont = strtmp->data;
493 len = strtmp->length;
494
495 break;
496
497 }
498 if(cout && len) memcpy(cout, cont, len);
499 return len;
500}
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c
deleted file mode 100644
index 2dd844159e..0000000000
--- a/src/lib/libcrypto/asn1/tasn_fre.c
+++ /dev/null
@@ -1,229 +0,0 @@
1/* tasn_fre.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63#include <openssl/objects.h>
64
65static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
66
67/* Free up an ASN1 structure */
68
69void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
70{
71 asn1_item_combine_free(&val, it, 0);
72}
73
74void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
75{
76 asn1_item_combine_free(pval, it, 0);
77}
78
79static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
80{
81 const ASN1_TEMPLATE *tt = NULL, *seqtt;
82 const ASN1_EXTERN_FUNCS *ef;
83 const ASN1_COMPAT_FUNCS *cf;
84 const ASN1_AUX *aux = it->funcs;
85 ASN1_aux_cb *asn1_cb;
86 int i;
87 if(!pval) return;
88 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return;
89 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
90 else asn1_cb = 0;
91
92 switch(it->itype) {
93
94 case ASN1_ITYPE_PRIMITIVE:
95 if(it->templates) ASN1_template_free(pval, it->templates);
96 else ASN1_primitive_free(pval, it);
97 break;
98
99 case ASN1_ITYPE_MSTRING:
100 ASN1_primitive_free(pval, it);
101 break;
102
103 case ASN1_ITYPE_CHOICE:
104 if(asn1_cb) {
105 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
106 if(i == 2) return;
107 }
108 i = asn1_get_choice_selector(pval, it);
109 if(asn1_cb) asn1_cb(ASN1_OP_FREE_PRE, pval, it);
110 if((i >= 0) && (i < it->tcount)) {
111 ASN1_VALUE **pchval;
112 tt = it->templates + i;
113 pchval = asn1_get_field_ptr(pval, tt);
114 ASN1_template_free(pchval, tt);
115 }
116 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
117 if(!combine) {
118 OPENSSL_free(*pval);
119 *pval = NULL;
120 }
121 break;
122
123 case ASN1_ITYPE_COMPAT:
124 cf = it->funcs;
125 if(cf && cf->asn1_free) cf->asn1_free(*pval);
126 break;
127
128 case ASN1_ITYPE_EXTERN:
129 ef = it->funcs;
130 if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it);
131 break;
132
133 case ASN1_ITYPE_SEQUENCE:
134 if(asn1_do_lock(pval, -1, it) > 0) return;
135 if(asn1_cb) {
136 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
137 if(i == 2) return;
138 }
139 asn1_enc_free(pval, it);
140 /* If we free up as normal we will invalidate any
141 * ANY DEFINED BY field and we wont be able to
142 * determine the type of the field it defines. So
143 * free up in reverse order.
144 */
145 tt = it->templates + it->tcount - 1;
146 for(i = 0; i < it->tcount; tt--, i++) {
147 ASN1_VALUE **pseqval;
148 seqtt = asn1_do_adb(pval, tt, 0);
149 if(!seqtt) continue;
150 pseqval = asn1_get_field_ptr(pval, seqtt);
151 ASN1_template_free(pseqval, seqtt);
152 }
153 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
154 if(!combine) {
155 OPENSSL_free(*pval);
156 *pval = NULL;
157 }
158 break;
159 }
160}
161
162void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
163{
164 int i;
165 if(tt->flags & ASN1_TFLG_SK_MASK) {
166 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
167 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
168 ASN1_VALUE *vtmp;
169 vtmp = sk_ASN1_VALUE_value(sk, i);
170 asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0);
171 }
172 sk_ASN1_VALUE_free(sk);
173 *pval = NULL;
174 } else asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
175 tt->flags & ASN1_TFLG_COMBINE);
176}
177
178void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
179{
180 int utype;
181 if(it) {
182 const ASN1_PRIMITIVE_FUNCS *pf;
183 pf = it->funcs;
184 if(pf && pf->prim_free) {
185 pf->prim_free(pval, it);
186 return;
187 }
188 }
189 /* Special case: if 'it' is NULL free contents of ASN1_TYPE */
190 if(!it) {
191 ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
192 utype = typ->type;
193 pval = (ASN1_VALUE **)&typ->value.ptr;
194 if(!*pval) return;
195 } else if(it->itype == ASN1_ITYPE_MSTRING) {
196 utype = -1;
197 if(!*pval) return;
198 } else {
199 utype = it->utype;
200 if((utype != V_ASN1_BOOLEAN) && !*pval) return;
201 }
202
203 switch(utype) {
204 case V_ASN1_OBJECT:
205 ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
206 break;
207
208 case V_ASN1_BOOLEAN:
209 if (it)
210 *(ASN1_BOOLEAN *)pval = it->size;
211 else
212 *(ASN1_BOOLEAN *)pval = -1;
213 return;
214
215 case V_ASN1_NULL:
216 break;
217
218 case V_ASN1_ANY:
219 ASN1_primitive_free(pval, NULL);
220 OPENSSL_free(*pval);
221 break;
222
223 default:
224 ASN1_STRING_free((ASN1_STRING *)*pval);
225 *pval = NULL;
226 break;
227 }
228 *pval = NULL;
229}
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
deleted file mode 100644
index a0e3db574f..0000000000
--- a/src/lib/libcrypto/asn1/tasn_new.c
+++ /dev/null
@@ -1,351 +0,0 @@
1/* tasn_new.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/err.h>
64#include <openssl/asn1t.h>
65#include <string.h>
66
67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
68static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
70void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
71
72ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
73{
74 ASN1_VALUE *ret = NULL;
75 if(ASN1_item_ex_new(&ret, it) > 0) return ret;
76 return NULL;
77}
78
79/* Allocate an ASN1 structure */
80
81int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
82{
83 return asn1_item_ex_combine_new(pval, it, 0);
84}
85
86static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
87{
88 const ASN1_TEMPLATE *tt = NULL;
89 const ASN1_COMPAT_FUNCS *cf;
90 const ASN1_EXTERN_FUNCS *ef;
91 const ASN1_AUX *aux = it->funcs;
92 ASN1_aux_cb *asn1_cb;
93 ASN1_VALUE **pseqval;
94 int i;
95 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
96 else asn1_cb = 0;
97
98 if(!combine) *pval = NULL;
99
100#ifdef CRYPTO_MDEBUG
101 if(it->sname) CRYPTO_push_info(it->sname);
102#endif
103
104 switch(it->itype) {
105
106 case ASN1_ITYPE_EXTERN:
107 ef = it->funcs;
108 if(ef && ef->asn1_ex_new) {
109 if(!ef->asn1_ex_new(pval, it))
110 goto memerr;
111 }
112 break;
113
114 case ASN1_ITYPE_COMPAT:
115 cf = it->funcs;
116 if(cf && cf->asn1_new) {
117 *pval = cf->asn1_new();
118 if(!*pval) goto memerr;
119 }
120 break;
121
122 case ASN1_ITYPE_PRIMITIVE:
123 if(it->templates) {
124 if(!ASN1_template_new(pval, it->templates))
125 goto memerr;
126 } else {
127 if(!ASN1_primitive_new(pval, it))
128 goto memerr;
129 }
130 break;
131
132 case ASN1_ITYPE_MSTRING:
133 if(!ASN1_primitive_new(pval, it))
134 goto memerr;
135 break;
136
137 case ASN1_ITYPE_CHOICE:
138 if(asn1_cb) {
139 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
140 if(!i) goto auxerr;
141 if(i==2) {
142#ifdef CRYPTO_MDEBUG
143 if(it->sname) CRYPTO_pop_info();
144#endif
145 return 1;
146 }
147 }
148 if(!combine) {
149 *pval = OPENSSL_malloc(it->size);
150 if(!*pval) goto memerr;
151 memset(*pval, 0, it->size);
152 }
153 asn1_set_choice_selector(pval, -1, it);
154 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
155 goto auxerr;
156 break;
157
158 case ASN1_ITYPE_SEQUENCE:
159 if(asn1_cb) {
160 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
161 if(!i) goto auxerr;
162 if(i==2) {
163#ifdef CRYPTO_MDEBUG
164 if(it->sname) CRYPTO_pop_info();
165#endif
166 return 1;
167 }
168 }
169 if(!combine) {
170 *pval = OPENSSL_malloc(it->size);
171 if(!*pval) goto memerr;
172 memset(*pval, 0, it->size);
173 asn1_do_lock(pval, 0, it);
174 asn1_enc_init(pval, it);
175 }
176 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
177 pseqval = asn1_get_field_ptr(pval, tt);
178 if(!ASN1_template_new(pseqval, tt)) goto memerr;
179 }
180 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
181 goto auxerr;
182 break;
183 }
184#ifdef CRYPTO_MDEBUG
185 if(it->sname) CRYPTO_pop_info();
186#endif
187 return 1;
188
189 memerr:
190 ASN1err(ASN1_F_ASN1_ITEM_NEW, ERR_R_MALLOC_FAILURE);
191#ifdef CRYPTO_MDEBUG
192 if(it->sname) CRYPTO_pop_info();
193#endif
194 return 0;
195
196 auxerr:
197 ASN1err(ASN1_F_ASN1_ITEM_NEW, ASN1_R_AUX_ERROR);
198 ASN1_item_ex_free(pval, it);
199#ifdef CRYPTO_MDEBUG
200 if(it->sname) CRYPTO_pop_info();
201#endif
202 return 0;
203
204}
205
206static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
207{
208 const ASN1_EXTERN_FUNCS *ef;
209
210 switch(it->itype) {
211
212 case ASN1_ITYPE_EXTERN:
213 ef = it->funcs;
214 if(ef && ef->asn1_ex_clear)
215 ef->asn1_ex_clear(pval, it);
216 else *pval = NULL;
217 break;
218
219
220 case ASN1_ITYPE_PRIMITIVE:
221 if(it->templates)
222 asn1_template_clear(pval, it->templates);
223 else
224 asn1_primitive_clear(pval, it);
225 break;
226
227 case ASN1_ITYPE_MSTRING:
228 asn1_primitive_clear(pval, it);
229 break;
230
231 case ASN1_ITYPE_COMPAT:
232 case ASN1_ITYPE_CHOICE:
233 case ASN1_ITYPE_SEQUENCE:
234 *pval = NULL;
235 break;
236 }
237}
238
239
240int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
241{
242 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
243 int ret;
244 if(tt->flags & ASN1_TFLG_OPTIONAL) {
245 asn1_template_clear(pval, tt);
246 return 1;
247 }
248 /* If ANY DEFINED BY nothing to do */
249
250 if(tt->flags & ASN1_TFLG_ADB_MASK) {
251 *pval = NULL;
252 return 1;
253 }
254#ifdef CRYPTO_MDEBUG
255 if(tt->field_name) CRYPTO_push_info(tt->field_name);
256#endif
257 /* If SET OF or SEQUENCE OF, its a STACK */
258 if(tt->flags & ASN1_TFLG_SK_MASK) {
259 STACK_OF(ASN1_VALUE) *skval;
260 skval = sk_ASN1_VALUE_new_null();
261 if(!skval) {
262 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
263 ret = 0;
264 goto done;
265 }
266 *pval = (ASN1_VALUE *)skval;
267 ret = 1;
268 goto done;
269 }
270 /* Otherwise pass it back to the item routine */
271 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
272 done:
273#ifdef CRYPTO_MDEBUG
274 if(it->sname) CRYPTO_pop_info();
275#endif
276 return ret;
277}
278
279static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
280{
281 /* If ADB or STACK just NULL the field */
282 if(tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
283 *pval = NULL;
284 else
285 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
286}
287
288
289/* NB: could probably combine most of the real XXX_new() behaviour and junk all the old
290 * functions.
291 */
292
293int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
294{
295 ASN1_TYPE *typ;
296 int utype;
297 const ASN1_PRIMITIVE_FUNCS *pf;
298 pf = it->funcs;
299 if(pf && pf->prim_new) return pf->prim_new(pval, it);
300 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
301 else utype = it->utype;
302 switch(utype) {
303 case V_ASN1_OBJECT:
304 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
305 return 1;
306
307 case V_ASN1_BOOLEAN:
308 if (it)
309 *(ASN1_BOOLEAN *)pval = it->size;
310 else
311 *(ASN1_BOOLEAN *)pval = -1;
312 return 1;
313
314 case V_ASN1_NULL:
315 *pval = (ASN1_VALUE *)1;
316 return 1;
317
318 case V_ASN1_ANY:
319 typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
320 if(!typ) return 0;
321 typ->value.ptr = NULL;
322 typ->type = -1;
323 *pval = (ASN1_VALUE *)typ;
324 break;
325
326 default:
327 *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
328 break;
329 }
330 if(*pval) return 1;
331 return 0;
332}
333
334void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
335{
336 int utype;
337 const ASN1_PRIMITIVE_FUNCS *pf;
338 pf = it->funcs;
339 if(pf) {
340 if(pf->prim_clear)
341 pf->prim_clear(pval, it);
342 else
343 *pval = NULL;
344 return;
345 }
346 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
347 else utype = it->utype;
348 if(utype == V_ASN1_BOOLEAN)
349 *(ASN1_BOOLEAN *)pval = it->size;
350 else *pval = NULL;
351}
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c
deleted file mode 100644
index 719639b511..0000000000
--- a/src/lib/libcrypto/asn1/tasn_prn.c
+++ /dev/null
@@ -1,198 +0,0 @@
1/* tasn_prn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/buffer.h>
64#include <openssl/err.h>
65#include <openssl/nasn.h>
66
67/* Print routines. Print out a whole structure from a template.
68 */
69
70static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name);
71
72int ASN1_item_print(BIO *out, void *fld, int indent, const ASN1_ITEM *it)
73{
74 return asn1_item_print_nm(out, fld, indent, it, it->sname);
75}
76
77static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name)
78{
79 ASN1_STRING *str;
80 const ASN1_TEMPLATE *tt;
81 void *tmpfld;
82 int i;
83 if(!fld) {
84 BIO_printf(out, "%*s%s ABSENT\n", indent, "", name);
85 return 1;
86 }
87 switch(it->itype) {
88
89 case ASN1_ITYPE_PRIMITIVE:
90 if(it->templates)
91 return ASN1_template_print(out, fld, indent, it->templates);
92 return asn1_primitive_print(out, fld, it->utype, indent, name);
93 break;
94
95 case ASN1_ITYPE_MSTRING:
96 str = fld;
97 return asn1_primitive_print(out, fld, str->type, indent, name);
98
99 case ASN1_ITYPE_EXTERN:
100 BIO_printf(out, "%*s%s:EXTERNAL TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
101 return 1;
102 case ASN1_ITYPE_COMPAT:
103 BIO_printf(out, "%*s%s:COMPATIBLE TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT");
104 return 1;
105
106
107 case ASN1_ITYPE_CHOICE:
108 /* CHOICE type, get selector */
109 i = asn1_get_choice_selector(fld, it);
110 /* This should never happen... */
111 if((i < 0) || (i >= it->tcount)) {
112 BIO_printf(out, "%s selector [%d] out of range\n", it->sname, i);
113 return 1;
114 }
115 tt = it->templates + i;
116 tmpfld = asn1_get_field(fld, tt);
117 return ASN1_template_print(out, tmpfld, indent, tt);
118
119 case ASN1_ITYPE_SEQUENCE:
120 BIO_printf(out, "%*s%s {\n", indent, "", name);
121 /* Get each field entry */
122 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
123 tmpfld = asn1_get_field(fld, tt);
124 ASN1_template_print(out, tmpfld, indent + 2, tt);
125 }
126 BIO_printf(out, "%*s}\n", indent, "");
127 return 1;
128
129 default:
130 return 0;
131 }
132}
133
134int ASN1_template_print(BIO *out, void *fld, int indent, const ASN1_TEMPLATE *tt)
135{
136 int i, flags;
137#if 0
138 if(!fld) return 0;
139#endif
140 flags = tt->flags;
141 if(flags & ASN1_TFLG_SK_MASK) {
142 char *tname;
143 void *skitem;
144 /* SET OF, SEQUENCE OF */
145 if(flags & ASN1_TFLG_SET_OF) tname = "SET";
146 else tname = "SEQUENCE";
147 if(fld) {
148 BIO_printf(out, "%*s%s OF %s {\n", indent, "", tname, tt->field_name);
149 for(i = 0; i < sk_num(fld); i++) {
150 skitem = sk_value(fld, i);
151 asn1_item_print_nm(out, skitem, indent + 2, tt->item, "");
152 }
153 BIO_printf(out, "%*s}\n", indent, "");
154 } else
155 BIO_printf(out, "%*s%s OF %s ABSENT\n", indent, "", tname, tt->field_name);
156 return 1;
157 }
158 return asn1_item_print_nm(out, fld, indent, tt->item, tt->field_name);
159}
160
161static int asn1_primitive_print(BIO *out, void *fld, long utype, int indent, const char *name)
162{
163 ASN1_STRING *str = fld;
164 if(fld) {
165 if(utype == V_ASN1_BOOLEAN) {
166 int *bool = fld;
167if(*bool == -1) printf("BOOL MISSING\n");
168 BIO_printf(out, "%*s%s:%s", indent, "", "BOOLEAN", *bool ? "TRUE" : "FALSE");
169 } else if((utype == V_ASN1_INTEGER)
170 || (utype == V_ASN1_ENUMERATED)) {
171 char *s, *nm;
172 s = i2s_ASN1_INTEGER(NULL, fld);
173 if(utype == V_ASN1_INTEGER) nm = "INTEGER";
174 else nm = "ENUMERATED";
175 BIO_printf(out, "%*s%s:%s", indent, "", nm, s);
176 OPENSSL_free(s);
177 } else if(utype == V_ASN1_NULL) {
178 BIO_printf(out, "%*s%s", indent, "", "NULL");
179 } else if(utype == V_ASN1_UTCTIME) {
180 BIO_printf(out, "%*s%s:%s:", indent, "", name, "UTCTIME");
181 ASN1_UTCTIME_print(out, str);
182 } else if(utype == V_ASN1_GENERALIZEDTIME) {
183 BIO_printf(out, "%*s%s:%s:", indent, "", name, "GENERALIZEDTIME");
184 ASN1_GENERALIZEDTIME_print(out, str);
185 } else if(utype == V_ASN1_OBJECT) {
186 char objbuf[80], *ln;
187 ln = OBJ_nid2ln(OBJ_obj2nid(fld));
188 if(!ln) ln = "";
189 OBJ_obj2txt(objbuf, sizeof objbuf, fld, 1);
190 BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf);
191 } else {
192 BIO_printf(out, "%*s%s:", indent, "", name);
193 ASN1_STRING_print_ex(out, str, ASN1_STRFLGS_DUMP_UNKNOWN|ASN1_STRFLGS_SHOW_TYPE);
194 }
195 BIO_printf(out, "\n");
196 } else BIO_printf(out, "%*s%s [ABSENT]\n", indent, "", name);
197 return 1;
198}
diff --git a/src/lib/libcrypto/asn1/tasn_typ.c b/src/lib/libcrypto/asn1/tasn_typ.c
deleted file mode 100644
index 804d2eeba2..0000000000
--- a/src/lib/libcrypto/asn1/tasn_typ.c
+++ /dev/null
@@ -1,133 +0,0 @@
1/* tasn_typ.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <stdio.h>
59#include <openssl/asn1.h>
60#include <openssl/asn1t.h>
61
62/* Declarations for string types */
63
64
65IMPLEMENT_ASN1_TYPE(ASN1_INTEGER)
66IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER)
67
68IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED)
69IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED)
70
71IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING)
72IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING)
73
74IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING)
75IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
76
77IMPLEMENT_ASN1_TYPE(ASN1_NULL)
78IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL)
79
80IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
81
82IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING)
83IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING)
84
85IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING)
86IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
87
88IMPLEMENT_ASN1_TYPE(ASN1_T61STRING)
89IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING)
90
91IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING)
92IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING)
93
94IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING)
95IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
96
97IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME)
98IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME)
99
100IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME)
101IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
102
103IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING)
104IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
105
106IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING)
107IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
108
109IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING)
110IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING)
111
112IMPLEMENT_ASN1_TYPE(ASN1_ANY)
113
114/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
115IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
116
117IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
118
119/* Multistring types */
120
121IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE)
122IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
123
124IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
125IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
126
127IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
128IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
129
130/* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
131IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
132IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1)
133IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c
deleted file mode 100644
index 8996ce8c13..0000000000
--- a/src/lib/libcrypto/asn1/tasn_utl.c
+++ /dev/null
@@ -1,253 +0,0 @@
1/* tasn_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stddef.h>
61#include <string.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/objects.h>
65#include <openssl/err.h>
66
67/* Utility functions for manipulating fields and offsets */
68
69/* Add 'offset' to 'addr' */
70#define offset2ptr(addr, offset) (void *)(((char *) addr) + offset)
71
72/* Given an ASN1_ITEM CHOICE type return
73 * the selector value
74 */
75
76int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
77{
78 int *sel = offset2ptr(*pval, it->utype);
79 return *sel;
80}
81
82/* Given an ASN1_ITEM CHOICE type set
83 * the selector value, return old value.
84 */
85
86int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
87{
88 int *sel, ret;
89 sel = offset2ptr(*pval, it->utype);
90 ret = *sel;
91 *sel = value;
92 return ret;
93}
94
95/* Do reference counting. The value 'op' decides what to do.
96 * if it is +1 then the count is incremented. If op is 0 count is
97 * set to 1. If op is -1 count is decremented and the return value
98 * is the current refrence count or 0 if no reference count exists.
99 */
100
101int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
102{
103 const ASN1_AUX *aux;
104 int *lck, ret;
105 if(it->itype != ASN1_ITYPE_SEQUENCE) return 0;
106 aux = it->funcs;
107 if(!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0;
108 lck = offset2ptr(*pval, aux->ref_offset);
109 if(op == 0) {
110 *lck = 1;
111 return 1;
112 }
113 ret = CRYPTO_add(lck, op, aux->ref_lock);
114#ifdef REF_PRINT
115 fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck);
116#endif
117#ifdef REF_CHECK
118 if(ret < 0)
119 fprintf(stderr, "%s, bad reference count\n", it->sname);
120#endif
121 return ret;
122}
123
124static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
125{
126 const ASN1_AUX *aux;
127 if(!pval || !*pval) return NULL;
128 aux = it->funcs;
129 if(!aux || !(aux->flags & ASN1_AFLG_ENCODING)) return NULL;
130 return offset2ptr(*pval, aux->enc_offset);
131}
132
133void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
134{
135 ASN1_ENCODING *enc;
136 enc = asn1_get_enc_ptr(pval, it);
137 if(enc) {
138 enc->enc = NULL;
139 enc->len = 0;
140 enc->modified = 1;
141 }
142}
143
144void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
145{
146 ASN1_ENCODING *enc;
147 enc = asn1_get_enc_ptr(pval, it);
148 if(enc) {
149 if(enc->enc) OPENSSL_free(enc->enc);
150 enc->enc = NULL;
151 enc->len = 0;
152 enc->modified = 1;
153 }
154}
155
156int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it)
157{
158 ASN1_ENCODING *enc;
159 enc = asn1_get_enc_ptr(pval, it);
160 if(!enc) return 1;
161
162 if(enc->enc) OPENSSL_free(enc->enc);
163 enc->enc = OPENSSL_malloc(inlen);
164 if(!enc->enc) return 0;
165 memcpy(enc->enc, in, inlen);
166 enc->len = inlen;
167 enc->modified = 0;
168
169 return 1;
170}
171
172int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it)
173{
174 ASN1_ENCODING *enc;
175 enc = asn1_get_enc_ptr(pval, it);
176 if(!enc || enc->modified) return 0;
177 if(out) {
178 memcpy(*out, enc->enc, enc->len);
179 *out += enc->len;
180 }
181 if(len) *len = enc->len;
182 return 1;
183}
184
185/* Given an ASN1_TEMPLATE get a pointer to a field */
186ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
187{
188 ASN1_VALUE **pvaltmp;
189 if(tt->flags & ASN1_TFLG_COMBINE) return pval;
190 pvaltmp = offset2ptr(*pval, tt->offset);
191 /* NOTE for BOOLEAN types the field is just a plain
192 * int so we can't return int **, so settle for
193 * (int *).
194 */
195 return pvaltmp;
196}
197
198/* Handle ANY DEFINED BY template, find the selector, look up
199 * the relevant ASN1_TEMPLATE in the table and return it.
200 */
201
202const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
203{
204 const ASN1_ADB *adb;
205 const ASN1_ADB_TABLE *atbl;
206 long selector;
207 ASN1_VALUE **sfld;
208 int i;
209 if(!(tt->flags & ASN1_TFLG_ADB_MASK)) return tt;
210
211 /* Else ANY DEFINED BY ... get the table */
212 adb = ASN1_ADB_ptr(tt->item);
213
214 /* Get the selector field */
215 sfld = offset2ptr(*pval, adb->offset);
216
217 /* Check if NULL */
218 if(!sfld) {
219 if(!adb->null_tt) goto err;
220 return adb->null_tt;
221 }
222
223 /* Convert type to a long:
224 * NB: don't check for NID_undef here because it
225 * might be a legitimate value in the table
226 */
227 if(tt->flags & ASN1_TFLG_ADB_OID)
228 selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
229 else
230 selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
231
232 /* Try to find matching entry in table
233 * Maybe should check application types first to
234 * allow application override? Might also be useful
235 * to have a flag which indicates table is sorted and
236 * we can do a binary search. For now stick to a
237 * linear search.
238 */
239
240 for(atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
241 if(atbl->value == selector) return &atbl->tt;
242
243 /* FIXME: need to search application table too */
244
245 /* No match, return default type */
246 if(!adb->default_tt) goto err;
247 return adb->default_tt;
248
249 err:
250 /* FIXME: should log the value or OID of unsupported type */
251 if(nullerr) ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
252 return NULL;
253}
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
deleted file mode 100644
index 00b9ea54a1..0000000000
--- a/src/lib/libcrypto/asn1/x_algor.c
+++ /dev/null
@@ -1,73 +0,0 @@
1/* x_algor.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stddef.h>
60#include <openssl/x509.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63
64ASN1_SEQUENCE(X509_ALGOR) = {
65 ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT),
66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY)
67} ASN1_SEQUENCE_END(X509_ALGOR)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
70IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
71
72IMPLEMENT_STACK_OF(X509_ALGOR)
73IMPLEMENT_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 1e3713f18f..0000000000
--- a/src/lib/libcrypto/asn1/x_attrib.c
+++ /dev/null
@@ -1,118 +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/asn1t.h>
63#include <openssl/x509.h>
64
65/* X509_ATTRIBUTE: this has the following form:
66 *
67 * typedef struct x509_attributes_st
68 * {
69 * ASN1_OBJECT *object;
70 * int single;
71 * union {
72 * char *ptr;
73 * STACK_OF(ASN1_TYPE) *set;
74 * ASN1_TYPE *single;
75 * } value;
76 * } X509_ATTRIBUTE;
77 *
78 * this needs some extra thought because the CHOICE type is
79 * merged with the main structure and because the value can
80 * be anything at all we *must* try the SET OF first because
81 * the ASN1_ANY type will swallow anything including the whole
82 * SET OF structure.
83 */
84
85ASN1_CHOICE(X509_ATTRIBUTE_SET) = {
86 ASN1_SET_OF(X509_ATTRIBUTE, value.set, ASN1_ANY),
87 ASN1_SIMPLE(X509_ATTRIBUTE, value.single, ASN1_ANY)
88} ASN1_CHOICE_END_selector(X509_ATTRIBUTE, X509_ATTRIBUTE_SET, single)
89
90ASN1_SEQUENCE(X509_ATTRIBUTE) = {
91 ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT),
92 /* CHOICE type merged with parent */
93 ASN1_EX_COMBINE(0, 0, X509_ATTRIBUTE_SET)
94} ASN1_SEQUENCE_END(X509_ATTRIBUTE)
95
96IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
97IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
98
99X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
100 {
101 X509_ATTRIBUTE *ret=NULL;
102 ASN1_TYPE *val=NULL;
103
104 if ((ret=X509_ATTRIBUTE_new()) == NULL)
105 return(NULL);
106 ret->object=OBJ_nid2obj(nid);
107 ret->single=0;
108 if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
109 if ((val=ASN1_TYPE_new()) == NULL) goto err;
110 if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
111
112 ASN1_TYPE_set(val,atrtype,value);
113 return(ret);
114err:
115 if (ret != NULL) X509_ATTRIBUTE_free(ret);
116 if (val != NULL) ASN1_TYPE_free(val);
117 return(NULL);
118 }
diff --git a/src/lib/libcrypto/asn1/x_bignum.c b/src/lib/libcrypto/asn1/x_bignum.c
deleted file mode 100644
index 848c7a0877..0000000000
--- a/src/lib/libcrypto/asn1/x_bignum.c
+++ /dev/null
@@ -1,137 +0,0 @@
1/* x_bignum.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63/* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a
64 * BIGNUM directly. Currently it ignores the sign which isn't a problem since all
65 * BIGNUMs used are non negative and anything that looks negative is normally due
66 * to an encoding error.
67 */
68
69#define BN_SENSITIVE 1
70
71static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
72static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
73
74static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
75static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
76
77static ASN1_PRIMITIVE_FUNCS bignum_pf = {
78 NULL, 0,
79 bn_new,
80 bn_free,
81 0,
82 bn_c2i,
83 bn_i2c
84};
85
86ASN1_ITEM_start(BIGNUM)
87 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM"
88ASN1_ITEM_end(BIGNUM)
89
90ASN1_ITEM_start(CBIGNUM)
91 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM"
92ASN1_ITEM_end(CBIGNUM)
93
94static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
95{
96 *pval = (ASN1_VALUE *)BN_new();
97 if(*pval) return 1;
98 else return 0;
99}
100
101static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
102{
103 if(!*pval) return;
104 if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval);
105 else BN_free((BIGNUM *)*pval);
106 *pval = NULL;
107}
108
109static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
110{
111 BIGNUM *bn;
112 int pad;
113 if(!*pval) return -1;
114 bn = (BIGNUM *)*pval;
115 /* If MSB set in an octet we need a padding byte */
116 if(BN_num_bits(bn) & 0x7) pad = 0;
117 else pad = 1;
118 if(cont) {
119 if(pad) *cont++ = 0;
120 BN_bn2bin(bn, cont);
121 }
122 return pad + BN_num_bytes(bn);
123}
124
125static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
126{
127 BIGNUM *bn;
128 if(!*pval) bn_new(pval, it);
129 bn = (BIGNUM *)*pval;
130 if(!BN_bin2bn(cont, len, bn)) {
131 bn_free(pval, it);
132 return 0;
133 }
134 return 1;
135}
136
137
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
deleted file mode 100644
index b99f8fc522..0000000000
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ /dev/null
@@ -1,140 +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/asn1t.h>
62#include <openssl/x509.h>
63
64static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
65 const X509_REVOKED * const *b);
66
67ASN1_SEQUENCE(X509_REVOKED) = {
68 ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER),
69 ASN1_SIMPLE(X509_REVOKED,revocationDate, ASN1_TIME),
70 ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION)
71} ASN1_SEQUENCE_END(X509_REVOKED)
72
73/* The X509_CRL_INFO structure needs a bit of customisation.
74 * Since we cache the original encoding the signature wont be affected by
75 * reordering of the revoked field.
76 */
77static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
78{
79 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
80
81 if(!a || !a->revoked) return 1;
82 switch(operation) {
83 /* Just set cmp function here. We don't sort because that
84 * would affect the output of X509_CRL_print().
85 */
86 case ASN1_OP_D2I_POST:
87 sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp);
88 break;
89 }
90 return 1;
91}
92
93
94ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = {
95 ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER),
96 ASN1_SIMPLE(X509_CRL_INFO, sig_alg, X509_ALGOR),
97 ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME),
98 ASN1_SIMPLE(X509_CRL_INFO, lastUpdate, ASN1_TIME),
99 ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME),
100 ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED),
101 ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0)
102} ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO)
103
104ASN1_SEQUENCE_ref(X509_CRL, 0, CRYPTO_LOCK_X509_CRL) = {
105 ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO),
106 ASN1_SIMPLE(X509_CRL, sig_alg, X509_ALGOR),
107 ASN1_SIMPLE(X509_CRL, signature, ASN1_BIT_STRING)
108} ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL)
109
110IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED)
111IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO)
112IMPLEMENT_ASN1_FUNCTIONS(X509_CRL)
113IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL)
114
115static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
116 const X509_REVOKED * const *b)
117 {
118 return(ASN1_STRING_cmp(
119 (ASN1_STRING *)(*a)->serialNumber,
120 (ASN1_STRING *)(*b)->serialNumber));
121 }
122
123int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
124{
125 X509_CRL_INFO *inf;
126 inf = crl->crl;
127 if(!inf->revoked)
128 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
129 if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
130 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE);
131 return 0;
132 }
133 inf->enc.modified = 1;
134 return 1;
135}
136
137IMPLEMENT_STACK_OF(X509_REVOKED)
138IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
139IMPLEMENT_STACK_OF(X509_CRL)
140IMPLEMENT_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 702421b6c8..0000000000
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/* x_exten.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stddef.h>
60#include <openssl/x509.h>
61#include <openssl/asn1.h>
62#include <openssl/asn1t.h>
63
64ASN1_SEQUENCE(X509_EXTENSION) = {
65 ASN1_SIMPLE(X509_EXTENSION, object, ASN1_OBJECT),
66 ASN1_OPT(X509_EXTENSION, critical, ASN1_BOOLEAN),
67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING)
68} ASN1_SEQUENCE_END(X509_EXTENSION)
69
70IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
71IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION)
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
deleted file mode 100644
index d44f6cdb01..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.h>
63#include <openssl/x509.h>
64
65X509_INFO *X509_INFO_new(void)
66 {
67 X509_INFO *ret=NULL;
68
69 ret=(X509_INFO *)OPENSSL_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) OPENSSL_free(x->enc_data);
110 OPENSSL_free(x);
111 }
112
113IMPLEMENT_STACK_OF(X509_INFO)
114
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c
deleted file mode 100644
index c5f25956cb..0000000000
--- a/src/lib/libcrypto/asn1/x_long.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/* x_long.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62
63/* Custom primitive type for long handling. This converts between an ASN1_INTEGER
64 * and a long directly.
65 */
66
67
68static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
69static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
70
71static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
72static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
73
74static ASN1_PRIMITIVE_FUNCS long_pf = {
75 NULL, 0,
76 long_new,
77 long_free,
78 long_free, /* Clear should set to initial value */
79 long_c2i,
80 long_i2c
81};
82
83ASN1_ITEM_start(LONG)
84 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG"
85ASN1_ITEM_end(LONG)
86
87ASN1_ITEM_start(ZLONG)
88 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG"
89ASN1_ITEM_end(ZLONG)
90
91static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
92{
93 *(long *)pval = it->size;
94 return 1;
95}
96
97static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
98{
99 *(long *)pval = it->size;
100}
101
102static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
103{
104 long ltmp;
105 unsigned long utmp;
106 int clen, pad, i;
107 /* this exists to bypass broken gcc optimization */
108 char *cp = (char *)pval;
109
110 /* use memcpy, because we may not be long aligned */
111 memcpy(&ltmp, cp, sizeof(long));
112
113 if(ltmp == it->size) return -1;
114 /* Convert the long to positive: we subtract one if negative so
115 * we can cleanly handle the padding if only the MSB of the leading
116 * octet is set.
117 */
118 if(ltmp < 0) utmp = -ltmp - 1;
119 else utmp = ltmp;
120 clen = BN_num_bits_word(utmp);
121 /* If MSB of leading octet set we need to pad */
122 if(!(clen & 0x7)) pad = 1;
123 else pad = 0;
124
125 /* Convert number of bits to number of octets */
126 clen = (clen + 7) >> 3;
127
128 if(cont) {
129 if(pad) *cont++ = (ltmp < 0) ? 0xff : 0;
130 for(i = clen - 1; i >= 0; i--) {
131 cont[i] = (unsigned char)(utmp & 0xff);
132 if(ltmp < 0) cont[i] ^= 0xff;
133 utmp >>= 8;
134 }
135 }
136 return clen + pad;
137}
138
139static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
140{
141 int neg, i;
142 long ltmp;
143 unsigned long utmp = 0;
144 char *cp = (char *)pval;
145 if(len > sizeof(long)) {
146 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
147 return 0;
148 }
149 /* Is it negative? */
150 if(len && (cont[0] & 0x80)) neg = 1;
151 else neg = 0;
152 utmp = 0;
153 for(i = 0; i < len; i++) {
154 utmp <<= 8;
155 if(neg) utmp |= cont[i] ^ 0xff;
156 else utmp |= cont[i];
157 }
158 ltmp = (long)utmp;
159 if(neg) {
160 ltmp++;
161 ltmp = -ltmp;
162 }
163 if(ltmp == it->size) {
164 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
165 return 0;
166 }
167 memcpy(cp, &ltmp, sizeof(long));
168 return 1;
169}
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
deleted file mode 100644
index 31f3377b64..0000000000
--- a/src/lib/libcrypto/asn1/x_name.c
+++ /dev/null
@@ -1,275 +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/asn1t.h>
62#include <openssl/x509.h>
63
64static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it,
65 int tag, int aclass, char opt, ASN1_TLC *ctx);
66
67static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
68static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it);
69static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it);
70
71static int x509_name_encode(X509_NAME *a);
72
73ASN1_SEQUENCE(X509_NAME_ENTRY) = {
74 ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT),
75 ASN1_SIMPLE(X509_NAME_ENTRY, value, ASN1_PRINTABLE)
76} ASN1_SEQUENCE_END(X509_NAME_ENTRY)
77
78IMPLEMENT_ASN1_FUNCTIONS(X509_NAME_ENTRY)
79IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY)
80
81/* For the "Name" type we need a SEQUENCE OF { SET OF X509_NAME_ENTRY }
82 * so declare two template wrappers for this
83 */
84
85ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) =
86 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY)
87ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES)
88
89ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) =
90 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES)
91ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL)
92
93/* Normally that's where it would end: we'd have two nested STACK structures
94 * representing the ASN1. Unfortunately X509_NAME uses a completely different
95 * form and caches encodings so we have to process the internal form and convert
96 * to the external form.
97 */
98
99const ASN1_EXTERN_FUNCS x509_name_ff = {
100 NULL,
101 x509_name_ex_new,
102 x509_name_ex_free,
103 0, /* Default clear behaviour is OK */
104 x509_name_ex_d2i,
105 x509_name_ex_i2d
106};
107
108IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff)
109
110IMPLEMENT_ASN1_FUNCTIONS(X509_NAME)
111IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME)
112
113static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
114{
115 X509_NAME *ret = NULL;
116 ret = OPENSSL_malloc(sizeof(X509_NAME));
117 if(!ret) goto memerr;
118 if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL)
119 goto memerr;
120 if((ret->bytes = BUF_MEM_new()) == NULL) goto memerr;
121 ret->modified=1;
122 *val = (ASN1_VALUE *)ret;
123 return 1;
124
125 memerr:
126 ASN1err(ASN1_F_X509_NAME_NEW, ERR_R_MALLOC_FAILURE);
127 if (ret)
128 {
129 if (ret->entries)
130 sk_X509_NAME_ENTRY_free(ret->entries);
131 OPENSSL_free(ret);
132 }
133 return 0;
134}
135
136static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
137{
138 X509_NAME *a;
139 if(!pval || !*pval)
140 return;
141 a = (X509_NAME *)*pval;
142
143 BUF_MEM_free(a->bytes);
144 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
145 OPENSSL_free(a);
146 *pval = NULL;
147}
148
149/* Used with sk_pop_free() to free up the internal representation.
150 * NB: we only free the STACK and not its contents because it is
151 * already present in the X509_NAME structure.
152 */
153
154static void sk_internal_free(void *a)
155{
156 sk_free(a);
157}
158
159static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it,
160 int tag, int aclass, char opt, ASN1_TLC *ctx)
161{
162 unsigned char *p = *in, *q;
163 STACK *intname = NULL, **intname_pp = &intname;
164 int i, j, ret;
165 X509_NAME *nm = NULL, **nm_pp = &nm;
166 STACK_OF(X509_NAME_ENTRY) *entries;
167 X509_NAME_ENTRY *entry;
168 q = p;
169
170 /* Get internal representation of Name */
171 ret = ASN1_item_ex_d2i((ASN1_VALUE **)intname_pp,
172 &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
173 tag, aclass, opt, ctx);
174
175 if(ret <= 0) return ret;
176
177 if(*val) x509_name_ex_free(val, NULL);
178 if(!x509_name_ex_new((ASN1_VALUE **)nm_pp, NULL)) goto err;
179 /* We've decoded it: now cache encoding */
180 if(!BUF_MEM_grow(nm->bytes, p - q)) goto err;
181 memcpy(nm->bytes->data, q, p - q);
182
183 /* Convert internal representation to X509_NAME structure */
184 for(i = 0; i < sk_num(intname); i++) {
185 entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname, i);
186 for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
187 entry = sk_X509_NAME_ENTRY_value(entries, j);
188 entry->set = i;
189 if(!sk_X509_NAME_ENTRY_push(nm->entries, entry))
190 goto err;
191 }
192 sk_X509_NAME_ENTRY_free(entries);
193 }
194 sk_free(intname);
195 nm->modified = 0;
196 *val = (ASN1_VALUE *)nm;
197 *in = p;
198 return ret;
199 err:
200 ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_NESTED_ASN1_ERROR);
201 return 0;
202}
203
204static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
205{
206 int ret;
207 X509_NAME *a = (X509_NAME *)*val;
208 if(a->modified) {
209 ret = x509_name_encode((X509_NAME *)a);
210 if(ret < 0) return ret;
211 }
212 ret = a->bytes->length;
213 if(out != NULL) {
214 memcpy(*out,a->bytes->data,ret);
215 *out+=ret;
216 }
217 return ret;
218}
219
220static int x509_name_encode(X509_NAME *a)
221{
222 STACK *intname = NULL, **intname_pp = &intname;
223 int len;
224 unsigned char *p;
225 STACK_OF(X509_NAME_ENTRY) *entries = NULL;
226 X509_NAME_ENTRY *entry;
227 int i, set = -1;
228 intname = sk_new_null();
229 if(!intname) goto memerr;
230 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
231 entry = sk_X509_NAME_ENTRY_value(a->entries, i);
232 if(entry->set != set) {
233 entries = sk_X509_NAME_ENTRY_new_null();
234 if(!entries) goto memerr;
235 if(!sk_push(intname, (char *)entries)) goto memerr;
236 set = entry->set;
237 }
238 if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr;
239 }
240 len = ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp, NULL,
241 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
242 if (!BUF_MEM_grow(a->bytes,len)) goto memerr;
243 p=(unsigned char *)a->bytes->data;
244 ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp,
245 &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
246 sk_pop_free(intname, sk_internal_free);
247 a->modified = 0;
248 return len;
249 memerr:
250 sk_pop_free(intname, sk_internal_free);
251 ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_MALLOC_FAILURE);
252 return -1;
253}
254
255
256int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
257 {
258 X509_NAME *in;
259
260 if (!xn || !name) return(0);
261
262 if (*xn != name)
263 {
264 in=X509_NAME_dup(name);
265 if (in != NULL)
266 {
267 X509_NAME_free(*xn);
268 *xn=in;
269 }
270 }
271 return(*xn != NULL);
272 }
273
274IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
275IMPLEMENT_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 f1c6221ac3..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)) OPENSSL_free(x->key_data);
150 OPENSSL_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 7d6d71af88..0000000000
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ /dev/null
@@ -1,360 +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/asn1t.h>
62#include <openssl/x509.h>
63
64/* Minor tweak to operation: free up EVP_PKEY */
65static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
66{
67 if(operation == ASN1_OP_FREE_POST) {
68 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
69 EVP_PKEY_free(pubkey->pkey);
70 }
71 return 1;
72}
73
74ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = {
75 ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR),
76 ASN1_SIMPLE(X509_PUBKEY, public_key, ASN1_BIT_STRING)
77} ASN1_SEQUENCE_END_cb(X509_PUBKEY, X509_PUBKEY)
78
79IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
80
81int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
82 {
83 X509_PUBKEY *pk=NULL;
84 X509_ALGOR *a;
85 ASN1_OBJECT *o;
86 unsigned char *s,*p = NULL;
87 int i;
88
89 if (x == NULL) return(0);
90
91 if ((pk=X509_PUBKEY_new()) == NULL) goto err;
92 a=pk->algor;
93
94 /* set the algorithm id */
95 if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
96 ASN1_OBJECT_free(a->algorithm);
97 a->algorithm=o;
98
99 /* Set the parameter list */
100 if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA))
101 {
102 if ((a->parameter == NULL) ||
103 (a->parameter->type != V_ASN1_NULL))
104 {
105 ASN1_TYPE_free(a->parameter);
106 if (!(a->parameter=ASN1_TYPE_new()))
107 {
108 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
109 goto err;
110 }
111 a->parameter->type=V_ASN1_NULL;
112 }
113 }
114 else
115#ifndef OPENSSL_NO_DSA
116 if (pkey->type == EVP_PKEY_DSA)
117 {
118 unsigned char *pp;
119 DSA *dsa;
120
121 dsa=pkey->pkey.dsa;
122 dsa->write_params=0;
123 ASN1_TYPE_free(a->parameter);
124 if ((i=i2d_DSAparams(dsa,NULL)) <= 0)
125 goto err;
126 if (!(p=(unsigned char *)OPENSSL_malloc(i)))
127 {
128 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
129 goto err;
130 }
131 pp=p;
132 i2d_DSAparams(dsa,&pp);
133 if (!(a->parameter=ASN1_TYPE_new()))
134 {
135 OPENSSL_free(p);
136 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
137 goto err;
138 }
139 a->parameter->type=V_ASN1_SEQUENCE;
140 if (!(a->parameter->value.sequence=ASN1_STRING_new()))
141 {
142 OPENSSL_free(p);
143 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
144 goto err;
145 }
146 if (!ASN1_STRING_set(a->parameter->value.sequence,p,i))
147 {
148 OPENSSL_free(p);
149 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
150 goto err;
151 }
152 OPENSSL_free(p);
153 }
154 else
155#endif
156 {
157 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
158 goto err;
159 }
160
161 if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
162 if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL)
163 {
164 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
165 goto err;
166 }
167 p=s;
168 i2d_PublicKey(pkey,&p);
169 if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i))
170 {
171 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
172 goto err;
173 }
174 /* Set number of unused bits to zero */
175 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
176 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
177
178 OPENSSL_free(s);
179
180#if 0
181 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
182 pk->pkey=pkey;
183#endif
184
185 if (*x != NULL)
186 X509_PUBKEY_free(*x);
187
188 *x=pk;
189
190 return 1;
191err:
192 if (pk != NULL) X509_PUBKEY_free(pk);
193 return 0;
194 }
195
196EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
197 {
198 EVP_PKEY *ret=NULL;
199 long j;
200 int type;
201 unsigned char *p;
202#ifndef OPENSSL_NO_DSA
203 const unsigned char *cp;
204 X509_ALGOR *a;
205#endif
206
207 if (key == NULL) goto err;
208
209 if (key->pkey != NULL)
210 {
211 CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
212 return(key->pkey);
213 }
214
215 if (key->public_key == NULL) goto err;
216
217 type=OBJ_obj2nid(key->algor->algorithm);
218 p=key->public_key->data;
219 j=key->public_key->length;
220 if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
221 {
222 X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
223 goto err;
224 }
225 ret->save_parameters=0;
226
227#ifndef OPENSSL_NO_DSA
228 a=key->algor;
229 if (ret->type == EVP_PKEY_DSA)
230 {
231 if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
232 {
233 ret->pkey.dsa->write_params=0;
234 cp=p=a->parameter->value.sequence->data;
235 j=a->parameter->value.sequence->length;
236 if (!d2i_DSAparams(&ret->pkey.dsa,&cp,(long)j))
237 goto err;
238 }
239 ret->save_parameters=1;
240 }
241#endif
242 key->pkey=ret;
243 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
244 return(ret);
245err:
246 if (ret != NULL)
247 EVP_PKEY_free(ret);
248 return(NULL);
249 }
250
251/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
252 * and encode or decode as X509_PUBKEY
253 */
254
255EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
256 long length)
257{
258 X509_PUBKEY *xpk;
259 EVP_PKEY *pktmp;
260 xpk = d2i_X509_PUBKEY(NULL, pp, length);
261 if(!xpk) return NULL;
262 pktmp = X509_PUBKEY_get(xpk);
263 X509_PUBKEY_free(xpk);
264 if(!pktmp) return NULL;
265 if(a) {
266 EVP_PKEY_free(*a);
267 *a = pktmp;
268 }
269 return pktmp;
270}
271
272int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
273{
274 X509_PUBKEY *xpk=NULL;
275 int ret;
276 if(!a) return 0;
277 if(!X509_PUBKEY_set(&xpk, a)) return 0;
278 ret = i2d_X509_PUBKEY(xpk, pp);
279 X509_PUBKEY_free(xpk);
280 return ret;
281}
282
283/* The following are equivalents but which return RSA and DSA
284 * keys
285 */
286#ifndef OPENSSL_NO_RSA
287RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
288 long length)
289{
290 EVP_PKEY *pkey;
291 RSA *key;
292 unsigned char *q;
293 q = *pp;
294 pkey = d2i_PUBKEY(NULL, &q, length);
295 if(!pkey) return NULL;
296 key = EVP_PKEY_get1_RSA(pkey);
297 EVP_PKEY_free(pkey);
298 if(!key) return NULL;
299 *pp = q;
300 if(a) {
301 RSA_free(*a);
302 *a = key;
303 }
304 return key;
305}
306
307int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
308{
309 EVP_PKEY *pktmp;
310 int ret;
311 if(!a) return 0;
312 pktmp = EVP_PKEY_new();
313 if(!pktmp) {
314 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
315 return 0;
316 }
317 EVP_PKEY_set1_RSA(pktmp, a);
318 ret = i2d_PUBKEY(pktmp, pp);
319 EVP_PKEY_free(pktmp);
320 return ret;
321}
322#endif
323
324#ifndef OPENSSL_NO_DSA
325DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
326 long length)
327{
328 EVP_PKEY *pkey;
329 DSA *key;
330 unsigned char *q;
331 q = *pp;
332 pkey = d2i_PUBKEY(NULL, &q, length);
333 if(!pkey) return NULL;
334 key = EVP_PKEY_get1_DSA(pkey);
335 EVP_PKEY_free(pkey);
336 if(!key) return NULL;
337 *pp = q;
338 if(a) {
339 DSA_free(*a);
340 *a = key;
341 }
342 return key;
343}
344
345int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
346{
347 EVP_PKEY *pktmp;
348 int ret;
349 if(!a) return 0;
350 pktmp = EVP_PKEY_new();
351 if(!pktmp) {
352 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
353 return 0;
354 }
355 EVP_PKEY_set1_DSA(pktmp, a);
356 ret = i2d_PUBKEY(pktmp, pp);
357 EVP_PKEY_free(pktmp);
358 return ret;
359}
360#endif
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
deleted file mode 100644
index b3f18ebc12..0000000000
--- a/src/lib/libcrypto/asn1/x_req.c
+++ /dev/null
@@ -1,112 +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/asn1t.h>
62#include <openssl/x509.h>
63
64/* X509_REQ_INFO is handled in an unusual way to get round
65 * invalid encodings. Some broken certificate requests don't
66 * encode the attributes field if it is empty. This is in
67 * violation of PKCS#10 but we need to tolerate it. We do
68 * this by making the attributes field OPTIONAL then using
69 * the callback to initialise it to an empty STACK.
70 *
71 * This means that the field will be correctly encoded unless
72 * we NULL out the field.
73 *
74 * As a result we no longer need the req_kludge field because
75 * the information is now contained in the attributes field:
76 * 1. If it is NULL then it's the invalid omission.
77 * 2. If it is empty it is the correct encoding.
78 * 3. If it is not empty then some attributes are present.
79 *
80 */
81
82static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
83{
84 X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
85
86 if(operation == ASN1_OP_NEW_POST) {
87 rinf->attributes = sk_X509_ATTRIBUTE_new_null();
88 if(!rinf->attributes) return 0;
89 }
90 return 1;
91}
92
93ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = {
94 ASN1_SIMPLE(X509_REQ_INFO, version, ASN1_INTEGER),
95 ASN1_SIMPLE(X509_REQ_INFO, subject, X509_NAME),
96 ASN1_SIMPLE(X509_REQ_INFO, pubkey, X509_PUBKEY),
97 /* This isn't really OPTIONAL but it gets round invalid
98 * encodings
99 */
100 ASN1_IMP_SET_OF_OPT(X509_REQ_INFO, attributes, X509_ATTRIBUTE, 0)
101} ASN1_SEQUENCE_END_enc(X509_REQ_INFO, X509_REQ_INFO)
102
103IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO)
104
105ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_INFO) = {
106 ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO),
107 ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR),
108 ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING)
109} ASN1_SEQUENCE_END_ref(X509_REQ, X509_REQ)
110
111IMPLEMENT_ASN1_FUNCTIONS(X509_REQ)
112IMPLEMENT_ASN1_DUP_FUNCTION(X509_REQ)
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
deleted file mode 100644
index 42efa86c1c..0000000000
--- a/src/lib/libcrypto/asn1/x_sig.c
+++ /dev/null
@@ -1,69 +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/asn1t.h>
62#include <openssl/x509.h>
63
64ASN1_SEQUENCE(X509_SIG) = {
65 ASN1_SIMPLE(X509_SIG, algor, X509_ALGOR),
66 ASN1_SIMPLE(X509_SIG, digest, ASN1_OCTET_STRING)
67} ASN1_SEQUENCE_END(X509_SIG)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_SIG)
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c
deleted file mode 100644
index 2aece077c5..0000000000
--- a/src/lib/libcrypto/asn1/x_spki.c
+++ /dev/null
@@ -1,81 +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/asn1t.h>
67
68ASN1_SEQUENCE(NETSCAPE_SPKAC) = {
69 ASN1_SIMPLE(NETSCAPE_SPKAC, pubkey, X509_PUBKEY),
70 ASN1_SIMPLE(NETSCAPE_SPKAC, challenge, ASN1_IA5STRING)
71} ASN1_SEQUENCE_END(NETSCAPE_SPKAC)
72
73IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
74
75ASN1_SEQUENCE(NETSCAPE_SPKI) = {
76 ASN1_SIMPLE(NETSCAPE_SPKI, spkac, NETSCAPE_SPKAC),
77 ASN1_SIMPLE(NETSCAPE_SPKI, sig_algor, X509_ALGOR),
78 ASN1_SIMPLE(NETSCAPE_SPKI, signature, ASN1_BIT_STRING)
79} ASN1_SEQUENCE_END(NETSCAPE_SPKI)
80
81IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKI)
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c
deleted file mode 100644
index dc17c67758..0000000000
--- a/src/lib/libcrypto/asn1/x_val.c
+++ /dev/null
@@ -1,69 +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/asn1t.h>
62#include <openssl/x509.h>
63
64ASN1_SEQUENCE(X509_VAL) = {
65 ASN1_SIMPLE(X509_VAL, notBefore, ASN1_TIME),
66 ASN1_SIMPLE(X509_VAL, notAfter, ASN1_TIME)
67} ASN1_SEQUENCE_END(X509_VAL)
68
69IMPLEMENT_ASN1_FUNCTIONS(X509_VAL)
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
deleted file mode 100644
index b50167ce43..0000000000
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ /dev/null
@@ -1,189 +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/asn1t.h>
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66ASN1_SEQUENCE(X509_CINF) = {
67 ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0),
68 ASN1_SIMPLE(X509_CINF, serialNumber, ASN1_INTEGER),
69 ASN1_SIMPLE(X509_CINF, signature, X509_ALGOR),
70 ASN1_SIMPLE(X509_CINF, issuer, X509_NAME),
71 ASN1_SIMPLE(X509_CINF, validity, X509_VAL),
72 ASN1_SIMPLE(X509_CINF, subject, X509_NAME),
73 ASN1_SIMPLE(X509_CINF, key, X509_PUBKEY),
74 ASN1_IMP_OPT(X509_CINF, issuerUID, ASN1_BIT_STRING, 1),
75 ASN1_IMP_OPT(X509_CINF, subjectUID, ASN1_BIT_STRING, 2),
76 ASN1_EXP_SEQUENCE_OF_OPT(X509_CINF, extensions, X509_EXTENSION, 3)
77} ASN1_SEQUENCE_END(X509_CINF)
78
79IMPLEMENT_ASN1_FUNCTIONS(X509_CINF)
80/* X509 top level structure needs a bit of customisation */
81
82static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
83{
84 X509 *ret = (X509 *)*pval;
85
86 switch(operation) {
87
88 case ASN1_OP_NEW_POST:
89 ret->valid=0;
90 ret->name = NULL;
91 ret->ex_flags = 0;
92 ret->ex_pathlen = -1;
93 ret->skid = NULL;
94 ret->akid = NULL;
95 ret->aux = NULL;
96 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
97 break;
98
99 case ASN1_OP_D2I_POST:
100 if (ret->name != NULL) OPENSSL_free(ret->name);
101 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
102 break;
103
104 case ASN1_OP_FREE_POST:
105 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
106 X509_CERT_AUX_free(ret->aux);
107 ASN1_OCTET_STRING_free(ret->skid);
108 AUTHORITY_KEYID_free(ret->akid);
109
110 if (ret->name != NULL) OPENSSL_free(ret->name);
111 break;
112
113 }
114
115 return 1;
116
117}
118
119ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
120 ASN1_SIMPLE(X509, cert_info, X509_CINF),
121 ASN1_SIMPLE(X509, sig_alg, X509_ALGOR),
122 ASN1_SIMPLE(X509, signature, ASN1_BIT_STRING)
123} ASN1_SEQUENCE_END_ref(X509, X509)
124
125IMPLEMENT_ASN1_FUNCTIONS(X509)
126IMPLEMENT_ASN1_DUP_FUNCTION(X509)
127
128static ASN1_METHOD meth={
129 (int (*)()) i2d_X509,
130 (char *(*)())d2i_X509,
131 (char *(*)())X509_new,
132 (void (*)()) X509_free};
133
134ASN1_METHOD *X509_asn1_meth(void)
135 {
136 return(&meth);
137 }
138
139int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
140 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
141 {
142 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp,
143 new_func, dup_func, free_func);
144 }
145
146int X509_set_ex_data(X509 *r, int idx, void *arg)
147 {
148 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
149 }
150
151void *X509_get_ex_data(X509 *r, int idx)
152 {
153 return(CRYPTO_get_ex_data(&r->ex_data,idx));
154 }
155
156/* X509_AUX ASN1 routines. X509_AUX is the name given to
157 * a certificate with extra info tagged on the end. Since these
158 * functions set how a certificate is trusted they should only
159 * be used when the certificate comes from a reliable source
160 * such as local storage.
161 *
162 */
163
164X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length)
165{
166 unsigned char *q;
167 X509 *ret;
168 /* Save start position */
169 q = *pp;
170 ret = d2i_X509(a, pp, length);
171 /* If certificate unreadable then forget it */
172 if(!ret) return NULL;
173 /* update length */
174 length -= *pp - q;
175 if(!length) return ret;
176 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err;
177 return ret;
178 err:
179 X509_free(ret);
180 return NULL;
181}
182
183int i2d_X509_AUX(X509 *a, unsigned char **pp)
184{
185 int length;
186 length = i2d_X509(a, pp);
187 if(a) length += i2d_X509_CERT_AUX(a->aux, pp);
188 return length;
189}
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
deleted file mode 100644
index f244768b7e..0000000000
--- a/src/lib/libcrypto/asn1/x_x509a.c
+++ /dev/null
@@ -1,151 +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/asn1t.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
74ASN1_SEQUENCE(X509_CERT_AUX) = {
75 ASN1_SEQUENCE_OF_OPT(X509_CERT_AUX, trust, ASN1_OBJECT),
76 ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, reject, ASN1_OBJECT, 0),
77 ASN1_OPT(X509_CERT_AUX, alias, ASN1_UTF8STRING),
78 ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING),
79 ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, other, X509_ALGOR, 1)
80} ASN1_SEQUENCE_END(X509_CERT_AUX)
81
82IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX)
83
84static X509_CERT_AUX *aux_get(X509 *x)
85{
86 if(!x) return NULL;
87 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL;
88 return x->aux;
89}
90
91int X509_alias_set1(X509 *x, unsigned char *name, int len)
92{
93 X509_CERT_AUX *aux;
94 if(!(aux = aux_get(x))) return 0;
95 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
96 return ASN1_STRING_set(aux->alias, name, len);
97}
98
99int X509_keyid_set1(X509 *x, unsigned char *id, int len)
100{
101 X509_CERT_AUX *aux;
102 if(!(aux = aux_get(x))) return 0;
103 if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0;
104 return ASN1_STRING_set(aux->keyid, id, len);
105}
106
107unsigned char *X509_alias_get0(X509 *x, int *len)
108{
109 if(!x->aux || !x->aux->alias) return NULL;
110 if(len) *len = x->aux->alias->length;
111 return x->aux->alias->data;
112}
113
114int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
115{
116 X509_CERT_AUX *aux;
117 ASN1_OBJECT *objtmp;
118 if(!(objtmp = OBJ_dup(obj))) return 0;
119 if(!(aux = aux_get(x))) return 0;
120 if(!aux->trust
121 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0;
122 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
123}
124
125int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
126{
127 X509_CERT_AUX *aux;
128 ASN1_OBJECT *objtmp;
129 if(!(objtmp = OBJ_dup(obj))) return 0;
130 if(!(aux = aux_get(x))) return 0;
131 if(!aux->reject
132 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0;
133 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
134}
135
136void X509_trust_clear(X509 *x)
137{
138 if(x->aux && x->aux->trust) {
139 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
140 x->aux->trust = NULL;
141 }
142}
143
144void X509_reject_clear(X509 *x)
145{
146 if(x->aux && x->aux->reject) {
147 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
148 x->aux->reject = NULL;
149 }
150}
151
diff --git a/src/lib/libcrypto/bf/COPYRIGHT b/src/lib/libcrypto/bf/COPYRIGHT
deleted file mode 100644
index 6857223506..0000000000
--- a/src/lib/libcrypto/bf/COPYRIGHT
+++ /dev/null
@@ -1,46 +0,0 @@
1Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
2All rights reserved.
3
4This package is an Blowfish implementation written
5by Eric Young (eay@cryptsoft.com).
6
7This library is free for commercial and non-commercial use as long as
8the following conditions are aheared to. The following conditions
9apply to all code found in this distribution.
10
11Copyright remains Eric Young's, and as such any Copyright notices in
12the code are not to be removed.
13
14Redistribution and use in source and binary forms, with or without
15modification, are permitted provided that the following conditions
16are met:
171. Redistributions of source code must retain the copyright
18 notice, this list of conditions and the following disclaimer.
192. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
223. All advertising materials mentioning features or use of this software
23 must display the following acknowledgement:
24 This product includes software developed by Eric Young (eay@cryptsoft.com)
25
26THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
27ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36SUCH DAMAGE.
37
38The license and distribution terms for any publically available version or
39derivative of this code cannot be changed. i.e. this code cannot simply be
40copied and put under another distrubution license
41[including the GNU Public License.]
42
43The reason behind this being stated in this direct manner is past
44experience in code simply being copied and the attribution removed
45from it and then being distributed as part of other packages. This
46implementation was a non-trivial and unpaid effort.
diff --git a/src/lib/libcrypto/bf/INSTALL b/src/lib/libcrypto/bf/INSTALL
deleted file mode 100644
index 3b25923532..0000000000
--- a/src/lib/libcrypto/bf/INSTALL
+++ /dev/null
@@ -1,14 +0,0 @@
1This Eric Young's blowfish implementation, taken from his SSLeay library
2and made available as a separate library.
3
4The version number (0.7.2m) is the SSLeay version that this library was
5taken from.
6
7To build, just unpack and type make.
8If you are not using gcc, edit the Makefile.
9If you are compiling for an x86 box, try the assembler (it needs improving).
10There are also some compile time options that can improve performance,
11these are documented in the Makefile.
12
13eric 15-Apr-1997
14
diff --git a/src/lib/libcrypto/bf/README b/src/lib/libcrypto/bf/README
deleted file mode 100644
index f2712fd0e7..0000000000
--- a/src/lib/libcrypto/bf/README
+++ /dev/null
@@ -1,8 +0,0 @@
1This is a quick packaging up of my blowfish code into a library.
2It has been lifted from SSLeay.
3The copyright notices seem a little harsh because I have not spent the
4time to rewrite the conditions from the normal SSLeay ones.
5
6Basically if you just want to play with the library, not a problem.
7
8eric 15-Apr-1997
diff --git a/src/lib/libcrypto/bf/VERSION b/src/lib/libcrypto/bf/VERSION
deleted file mode 100644
index be995855e4..0000000000
--- a/src/lib/libcrypto/bf/VERSION
+++ /dev/null
@@ -1,6 +0,0 @@
1The version numbers will follow my SSL implementation
2
30.7.2r - Some reasonable default compiler options from
4 Peter Gutman <pgut001@cs.auckland.ac.nz>
5
60.7.2m - the first release
diff --git a/src/lib/libcrypto/bf/asm/bf-586.pl b/src/lib/libcrypto/bf/asm/bf-586.pl
deleted file mode 100644
index b5a4760d09..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) unless $main'openbsd;
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 1931aba83f..0000000000
--- a/src/lib/libcrypto/bf/bf_skey.c
+++ /dev/null
@@ -1,118 +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/crypto.h>
62#include <openssl/blowfish.h>
63#include <openssl/fips.h>
64#include "bf_locl.h"
65#include "bf_pi.h"
66
67FIPS_NON_FIPS_VCIPHER_Init(BF)
68 {
69 int i;
70 BF_LONG *p,ri,in[2];
71 const unsigned char *d,*end;
72
73
74 memcpy(key,&bf_init,sizeof(BF_KEY));
75 p=key->P;
76
77 if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
78
79 d=data;
80 end= &(data[len]);
81 for (i=0; i<(BF_ROUNDS+2); i++)
82 {
83 ri= *(d++);
84 if (d >= end) d=data;
85
86 ri<<=8;
87 ri|= *(d++);
88 if (d >= end) d=data;
89
90 ri<<=8;
91 ri|= *(d++);
92 if (d >= end) d=data;
93
94 ri<<=8;
95 ri|= *(d++);
96 if (d >= end) d=data;
97
98 p[i]^=ri;
99 }
100
101 in[0]=0L;
102 in[1]=0L;
103 for (i=0; i<(BF_ROUNDS+2); i+=2)
104 {
105 BF_encrypt(in,key);
106 p[i ]=in[0];
107 p[i+1]=in[1];
108 }
109
110 p=key->S;
111 for (i=0; i<4*256; i+=2)
112 {
113 BF_encrypt(in,key);
114 p[i ]=in[0];
115 p[i+1]=in[1];
116 }
117 }
118
diff --git a/src/lib/libcrypto/bf/blowfish.h b/src/lib/libcrypto/bf/blowfish.h
deleted file mode 100644
index b4d8774961..0000000000
--- a/src/lib/libcrypto/bf/blowfish.h
+++ /dev/null
@@ -1,130 +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#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_BF
69#error BF is disabled.
70#endif
71
72#define BF_ENCRYPT 1
73#define BF_DECRYPT 0
74
75/*
76 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 * ! BF_LONG has to be at least 32 bits wide. If it's wider, then !
78 * ! BF_LONG_LOG2 has to be defined along. !
79 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
80 */
81
82#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
83#define BF_LONG unsigned long
84#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
85#define BF_LONG unsigned long
86#define BF_LONG_LOG2 3
87/*
88 * _CRAY note. I could declare short, but I have no idea what impact
89 * does it have on performance on none-T3E machines. I could declare
90 * int, but at least on C90 sizeof(int) can be chosen at compile time.
91 * So I've chosen long...
92 * <appro@fy.chalmers.se>
93 */
94#else
95#define BF_LONG unsigned int
96#endif
97
98#define BF_ROUNDS 16
99#define BF_BLOCK 8
100
101typedef struct bf_key_st
102 {
103 BF_LONG P[BF_ROUNDS+2];
104 BF_LONG S[4*256];
105 } BF_KEY;
106
107
108#ifdef OPENSSL_FIPS
109void private_BF_set_key(BF_KEY *key, int len, const unsigned char *data);
110#endif
111void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
112
113void BF_encrypt(BF_LONG *data,const BF_KEY *key);
114void BF_decrypt(BF_LONG *data,const BF_KEY *key);
115
116void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
117 const BF_KEY *key, int enc);
118void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
119 const BF_KEY *schedule, unsigned char *ivec, int enc);
120void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
121 const BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
122void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
123 const BF_KEY *schedule, unsigned char *ivec, int *num);
124const char *BF_options(void);
125
126#ifdef __cplusplus
127}
128#endif
129
130#endif
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
deleted file mode 100644
index f671e722fa..0000000000
--- a/src/lib/libcrypto/bio/b_dump.c
+++ /dev/null
@@ -1,156 +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#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
70
71int BIO_dump(BIO *bio, const char *s, int len)
72 {
73 return BIO_dump_indent(bio, s, len, 0);
74 }
75
76int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
77 {
78 int ret=0;
79 char buf[288+1],tmp[20],str[128+1];
80 int i,j,rows,trunc;
81 unsigned char ch;
82 int dump_width;
83
84 trunc=0;
85
86#ifdef TRUNCATE
87 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
88 trunc++;
89#endif
90
91 if (indent < 0)
92 indent = 0;
93 if (indent)
94 {
95 if (indent > 128) indent=128;
96 memset(str,' ',indent);
97 }
98 str[indent]='\0';
99
100 dump_width=DUMP_WIDTH_LESS_INDENT(indent);
101 rows=(len/dump_width);
102 if ((rows*dump_width)<len)
103 rows++;
104 for(i=0;i<rows;i++)
105 {
106 buf[0]='\0'; /* start with empty string */
107 BUF_strlcpy(buf,str,sizeof buf);
108 BIO_snprintf(tmp,sizeof tmp,"%04x - ",i*dump_width);
109 BUF_strlcat(buf,tmp,sizeof buf);
110 for(j=0;j<dump_width;j++)
111 {
112 if (((i*dump_width)+j)>=len)
113 {
114 BUF_strlcat(buf," ",sizeof buf);
115 }
116 else
117 {
118 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
119 BIO_snprintf(tmp,sizeof tmp,"%02x%c",ch,
120 j==7?'-':' ');
121 BUF_strlcat(buf,tmp,sizeof buf);
122 }
123 }
124 BUF_strlcat(buf," ",sizeof buf);
125 for(j=0;j<dump_width;j++)
126 {
127 if (((i*dump_width)+j)>=len)
128 break;
129 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
130#ifndef CHARSET_EBCDIC
131 BIO_snprintf(tmp,sizeof tmp,"%c",
132 ((ch>=' ')&&(ch<='~'))?ch:'.');
133#else
134 BIO_snprintf(tmp,sizeof tmp,"%c",
135 ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
136 ? os_toebcdic[ch]
137 : '.');
138#endif
139 BUF_strlcat(buf,tmp,sizeof buf);
140 }
141 BUF_strlcat(buf,"\n",sizeof buf);
142 /* if this is the last call then update the ddt_dump thing so that
143 * we will move the selection point in the debug window
144 */
145 ret+=BIO_write(bio,(char *)buf,strlen(buf));
146 }
147#ifdef TRUNCATE
148 if (trunc > 0)
149 {
150 BIO_snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
151 len+trunc);
152 ret+=BIO_write(bio,(char *)buf,strlen(buf));
153 }
154#endif
155 return(ret);
156 }
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
deleted file mode 100644
index f2bd91d5a0..0000000000
--- a/src/lib/libcrypto/bio/b_print.c
+++ /dev/null
@@ -1,841 +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/* disable assert() unless BIO_DEBUG has been defined */
60#ifndef BIO_DEBUG
61# ifndef NDEBUG
62# define NDEBUG
63# endif
64#endif
65
66/*
67 * Stolen from tjh's ssl/ssl_trc.c stuff.
68 */
69
70#include <stdio.h>
71#include <string.h>
72#include <ctype.h>
73#include <assert.h>
74#include <limits.h>
75#include "cryptlib.h"
76#ifndef NO_SYS_TYPES_H
77#include <sys/types.h>
78#endif
79#include <openssl/bn.h> /* To get BN_LLONG properly defined */
80#include <openssl/bio.h>
81
82#ifdef BN_LLONG
83# ifndef HAVE_LONG_LONG
84# define HAVE_LONG_LONG 1
85# endif
86#endif
87
88/***************************************************************************/
89
90/*
91 * Copyright Patrick Powell 1995
92 * This code is based on code written by Patrick Powell <papowell@astart.com>
93 * It may be used for any purpose as long as this notice remains intact
94 * on all source code distributions.
95 */
96
97/*
98 * This code contains numerious changes and enhancements which were
99 * made by lots of contributors over the last years to Patrick Powell's
100 * original code:
101 *
102 * o Patrick Powell <papowell@astart.com> (1995)
103 * o Brandon Long <blong@fiction.net> (1996, for Mutt)
104 * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)
105 * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)
106 * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
107 * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
108 * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)
109 * o ... (for OpenSSL)
110 */
111
112#ifdef HAVE_LONG_DOUBLE
113#define LDOUBLE long double
114#else
115#define LDOUBLE double
116#endif
117
118#if HAVE_LONG_LONG
119# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
120# define LLONG _int64
121# else
122# define LLONG long long
123# endif
124#else
125#define LLONG long
126#endif
127
128static void fmtstr (char **, char **, size_t *, size_t *,
129 const char *, int, int, int);
130static void fmtint (char **, char **, size_t *, size_t *,
131 LLONG, int, int, int, int);
132static void fmtfp (char **, char **, size_t *, size_t *,
133 LDOUBLE, int, int, int);
134static void doapr_outch (char **, char **, size_t *, size_t *, int);
135static void _dopr(char **sbuffer, char **buffer,
136 size_t *maxlen, size_t *retlen, int *truncated,
137 const char *format, va_list args);
138
139/* format read states */
140#define DP_S_DEFAULT 0
141#define DP_S_FLAGS 1
142#define DP_S_MIN 2
143#define DP_S_DOT 3
144#define DP_S_MAX 4
145#define DP_S_MOD 5
146#define DP_S_CONV 6
147#define DP_S_DONE 7
148
149/* format flags - Bits */
150#define DP_F_MINUS (1 << 0)
151#define DP_F_PLUS (1 << 1)
152#define DP_F_SPACE (1 << 2)
153#define DP_F_NUM (1 << 3)
154#define DP_F_ZERO (1 << 4)
155#define DP_F_UP (1 << 5)
156#define DP_F_UNSIGNED (1 << 6)
157
158/* conversion flags */
159#define DP_C_SHORT 1
160#define DP_C_LONG 2
161#define DP_C_LDOUBLE 3
162#define DP_C_LLONG 4
163
164/* some handy macros */
165#define char_to_int(p) (p - '0')
166#define OSSL_MAX(p,q) ((p >= q) ? p : q)
167
168static void
169_dopr(
170 char **sbuffer,
171 char **buffer,
172 size_t *maxlen,
173 size_t *retlen,
174 int *truncated,
175 const char *format,
176 va_list args)
177{
178 char ch;
179 LLONG value;
180 LDOUBLE fvalue;
181 char *strvalue;
182 int min;
183 int max;
184 int state;
185 int flags;
186 int cflags;
187 size_t currlen;
188
189 state = DP_S_DEFAULT;
190 flags = currlen = cflags = min = 0;
191 max = -1;
192 ch = *format++;
193
194 while (state != DP_S_DONE) {
195 if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
196 state = DP_S_DONE;
197
198 switch (state) {
199 case DP_S_DEFAULT:
200 if (ch == '%')
201 state = DP_S_FLAGS;
202 else
203 doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);
204 ch = *format++;
205 break;
206 case DP_S_FLAGS:
207 switch (ch) {
208 case '-':
209 flags |= DP_F_MINUS;
210 ch = *format++;
211 break;
212 case '+':
213 flags |= DP_F_PLUS;
214 ch = *format++;
215 break;
216 case ' ':
217 flags |= DP_F_SPACE;
218 ch = *format++;
219 break;
220 case '#':
221 flags |= DP_F_NUM;
222 ch = *format++;
223 break;
224 case '0':
225 flags |= DP_F_ZERO;
226 ch = *format++;
227 break;
228 default:
229 state = DP_S_MIN;
230 break;
231 }
232 break;
233 case DP_S_MIN:
234 if (isdigit((unsigned char)ch)) {
235 min = 10 * min + char_to_int(ch);
236 ch = *format++;
237 } else if (ch == '*') {
238 min = va_arg(args, int);
239 ch = *format++;
240 state = DP_S_DOT;
241 } else
242 state = DP_S_DOT;
243 break;
244 case DP_S_DOT:
245 if (ch == '.') {
246 state = DP_S_MAX;
247 ch = *format++;
248 } else
249 state = DP_S_MOD;
250 break;
251 case DP_S_MAX:
252 if (isdigit((unsigned char)ch)) {
253 if (max < 0)
254 max = 0;
255 max = 10 * max + char_to_int(ch);
256 ch = *format++;
257 } else if (ch == '*') {
258 max = va_arg(args, int);
259 ch = *format++;
260 state = DP_S_MOD;
261 } else
262 state = DP_S_MOD;
263 break;
264 case DP_S_MOD:
265 switch (ch) {
266 case 'h':
267 cflags = DP_C_SHORT;
268 ch = *format++;
269 break;
270 case 'l':
271 if (*format == 'l') {
272 cflags = DP_C_LLONG;
273 format++;
274 } else
275 cflags = DP_C_LONG;
276 ch = *format++;
277 break;
278 case 'q':
279 cflags = DP_C_LLONG;
280 ch = *format++;
281 break;
282 case 'L':
283 cflags = DP_C_LDOUBLE;
284 ch = *format++;
285 break;
286 default:
287 break;
288 }
289 state = DP_S_CONV;
290 break;
291 case DP_S_CONV:
292 switch (ch) {
293 case 'd':
294 case 'i':
295 switch (cflags) {
296 case DP_C_SHORT:
297 value = (short int)va_arg(args, int);
298 break;
299 case DP_C_LONG:
300 value = va_arg(args, long int);
301 break;
302 case DP_C_LLONG:
303 value = va_arg(args, LLONG);
304 break;
305 default:
306 value = va_arg(args, int);
307 break;
308 }
309 fmtint(sbuffer, buffer, &currlen, maxlen,
310 value, 10, min, max, flags);
311 break;
312 case 'X':
313 flags |= DP_F_UP;
314 /* FALLTHROUGH */
315 case 'x':
316 case 'o':
317 case 'u':
318 flags |= DP_F_UNSIGNED;
319 switch (cflags) {
320 case DP_C_SHORT:
321 value = (unsigned short int)va_arg(args, unsigned int);
322 break;
323 case DP_C_LONG:
324 value = (LLONG) va_arg(args,
325 unsigned long int);
326 break;
327 case DP_C_LLONG:
328 value = va_arg(args, unsigned LLONG);
329 break;
330 default:
331 value = (LLONG) va_arg(args,
332 unsigned int);
333 break;
334 }
335 fmtint(sbuffer, buffer, &currlen, maxlen, value,
336 ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
337 min, max, flags);
338 break;
339 case 'f':
340 if (cflags == DP_C_LDOUBLE)
341 fvalue = va_arg(args, LDOUBLE);
342 else
343 fvalue = va_arg(args, double);
344 fmtfp(sbuffer, buffer, &currlen, maxlen,
345 fvalue, min, max, flags);
346 break;
347 case 'E':
348 flags |= DP_F_UP;
349 case 'e':
350 if (cflags == DP_C_LDOUBLE)
351 fvalue = va_arg(args, LDOUBLE);
352 else
353 fvalue = va_arg(args, double);
354 break;
355 case 'G':
356 flags |= DP_F_UP;
357 case 'g':
358 if (cflags == DP_C_LDOUBLE)
359 fvalue = va_arg(args, LDOUBLE);
360 else
361 fvalue = va_arg(args, double);
362 break;
363 case 'c':
364 doapr_outch(sbuffer, buffer, &currlen, maxlen,
365 va_arg(args, int));
366 break;
367 case 's':
368 strvalue = va_arg(args, char *);
369 if (max < 0) {
370 if (buffer)
371 max = INT_MAX;
372 else
373 max = *maxlen;
374 }
375 fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
376 flags, min, max);
377 break;
378 case 'p':
379 value = (long)va_arg(args, void *);
380 fmtint(sbuffer, buffer, &currlen, maxlen,
381 value, 16, min, max, flags|DP_F_NUM);
382 break;
383 case 'n': /* XXX */
384 if (cflags == DP_C_SHORT) {
385 short int *num;
386 num = va_arg(args, short int *);
387 *num = currlen;
388 } else if (cflags == DP_C_LONG) { /* XXX */
389 long int *num;
390 num = va_arg(args, long int *);
391 *num = (long int) currlen;
392 } else if (cflags == DP_C_LLONG) { /* XXX */
393 LLONG *num;
394 num = va_arg(args, LLONG *);
395 *num = (LLONG) currlen;
396 } else {
397 int *num;
398 num = va_arg(args, int *);
399 *num = currlen;
400 }
401 break;
402 case '%':
403 doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
404 break;
405 case 'w':
406 /* not supported yet, treat as next char */
407 ch = *format++;
408 break;
409 default:
410 /* unknown, skip */
411 break;
412 }
413 ch = *format++;
414 state = DP_S_DEFAULT;
415 flags = cflags = min = 0;
416 max = -1;
417 break;
418 case DP_S_DONE:
419 break;
420 default:
421 break;
422 }
423 }
424 *truncated = (currlen > *maxlen - 1);
425 if (*truncated)
426 currlen = *maxlen - 1;
427 doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
428 *retlen = currlen - 1;
429 return;
430}
431
432static void
433fmtstr(
434 char **sbuffer,
435 char **buffer,
436 size_t *currlen,
437 size_t *maxlen,
438 const char *value,
439 int flags,
440 int min,
441 int max)
442{
443 int padlen, strln;
444 int cnt = 0;
445
446 if (value == 0)
447 value = "<NULL>";
448 for (strln = 0; value[strln]; ++strln)
449 ;
450 padlen = min - strln;
451 if (padlen < 0)
452 padlen = 0;
453 if (flags & DP_F_MINUS)
454 padlen = -padlen;
455
456 while ((padlen > 0) && (cnt < max)) {
457 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
458 --padlen;
459 ++cnt;
460 }
461 while (*value && (cnt < max)) {
462 doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
463 ++cnt;
464 }
465 while ((padlen < 0) && (cnt < max)) {
466 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
467 ++padlen;
468 ++cnt;
469 }
470}
471
472static void
473fmtint(
474 char **sbuffer,
475 char **buffer,
476 size_t *currlen,
477 size_t *maxlen,
478 LLONG value,
479 int base,
480 int min,
481 int max,
482 int flags)
483{
484 int signvalue = 0;
485 char *prefix = "";
486 unsigned LLONG uvalue;
487 char convert[DECIMAL_SIZE(value)+3];
488 int place = 0;
489 int spadlen = 0;
490 int zpadlen = 0;
491 int caps = 0;
492
493 if (max < 0)
494 max = 0;
495 uvalue = value;
496 if (!(flags & DP_F_UNSIGNED)) {
497 if (value < 0) {
498 signvalue = '-';
499 uvalue = -value;
500 } else if (flags & DP_F_PLUS)
501 signvalue = '+';
502 else if (flags & DP_F_SPACE)
503 signvalue = ' ';
504 }
505 if (flags & DP_F_NUM) {
506 if (base == 8) prefix = "0";
507 if (base == 16) prefix = "0x";
508 }
509 if (flags & DP_F_UP)
510 caps = 1;
511 do {
512 convert[place++] =
513 (caps ? "0123456789ABCDEF" : "0123456789abcdef")
514 [uvalue % (unsigned) base];
515 uvalue = (uvalue / (unsigned) base);
516 } while (uvalue && (place < sizeof convert));
517 if (place == sizeof convert)
518 place--;
519 convert[place] = 0;
520
521 zpadlen = max - place;
522 spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix);
523 if (zpadlen < 0)
524 zpadlen = 0;
525 if (spadlen < 0)
526 spadlen = 0;
527 if (flags & DP_F_ZERO) {
528 zpadlen = OSSL_MAX(zpadlen, spadlen);
529 spadlen = 0;
530 }
531 if (flags & DP_F_MINUS)
532 spadlen = -spadlen;
533
534 /* spaces */
535 while (spadlen > 0) {
536 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
537 --spadlen;
538 }
539
540 /* sign */
541 if (signvalue)
542 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
543
544 /* prefix */
545 while (*prefix) {
546 doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix);
547 prefix++;
548 }
549
550 /* zeros */
551 if (zpadlen > 0) {
552 while (zpadlen > 0) {
553 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
554 --zpadlen;
555 }
556 }
557 /* digits */
558 while (place > 0)
559 doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
560
561 /* left justified spaces */
562 while (spadlen < 0) {
563 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
564 ++spadlen;
565 }
566 return;
567}
568
569static LDOUBLE
570abs_val(LDOUBLE value)
571{
572 LDOUBLE result = value;
573 if (value < 0)
574 result = -value;
575 return result;
576}
577
578static LDOUBLE
579pow_10(int in_exp)
580{
581 LDOUBLE result = 1;
582 while (in_exp) {
583 result *= 10;
584 in_exp--;
585 }
586 return result;
587}
588
589static long
590roundv(LDOUBLE value)
591{
592 long intpart;
593 intpart = (long) value;
594 value = value - intpart;
595 if (value >= 0.5)
596 intpart++;
597 return intpart;
598}
599
600static void
601fmtfp(
602 char **sbuffer,
603 char **buffer,
604 size_t *currlen,
605 size_t *maxlen,
606 LDOUBLE fvalue,
607 int min,
608 int max,
609 int flags)
610{
611 int signvalue = 0;
612 LDOUBLE ufvalue;
613 char iconvert[20];
614 char fconvert[20];
615 int iplace = 0;
616 int fplace = 0;
617 int padlen = 0;
618 int zpadlen = 0;
619 int caps = 0;
620 long intpart;
621 long fracpart;
622
623 if (max < 0)
624 max = 6;
625 ufvalue = abs_val(fvalue);
626 if (fvalue < 0)
627 signvalue = '-';
628 else if (flags & DP_F_PLUS)
629 signvalue = '+';
630 else if (flags & DP_F_SPACE)
631 signvalue = ' ';
632
633 intpart = (long)ufvalue;
634
635 /* sorry, we only support 9 digits past the decimal because of our
636 conversion method */
637 if (max > 9)
638 max = 9;
639
640 /* we "cheat" by converting the fractional part to integer by
641 multiplying by a factor of 10 */
642 fracpart = roundv((pow_10(max)) * (ufvalue - intpart));
643
644 if (fracpart >= (long)pow_10(max)) {
645 intpart++;
646 fracpart -= (long)pow_10(max);
647 }
648
649 /* convert integer part */
650 do {
651 iconvert[iplace++] =
652 (caps ? "0123456789ABCDEF"
653 : "0123456789abcdef")[intpart % 10];
654 intpart = (intpart / 10);
655 } while (intpart && (iplace < sizeof iconvert));
656 if (iplace == sizeof iconvert)
657 iplace--;
658 iconvert[iplace] = 0;
659
660 /* convert fractional part */
661 do {
662 fconvert[fplace++] =
663 (caps ? "0123456789ABCDEF"
664 : "0123456789abcdef")[fracpart % 10];
665 fracpart = (fracpart / 10);
666 } while (fplace < max);
667 if (fplace == sizeof fconvert)
668 fplace--;
669 fconvert[fplace] = 0;
670
671 /* -1 for decimal point, another -1 if we are printing a sign */
672 padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
673 zpadlen = max - fplace;
674 if (zpadlen < 0)
675 zpadlen = 0;
676 if (padlen < 0)
677 padlen = 0;
678 if (flags & DP_F_MINUS)
679 padlen = -padlen;
680
681 if ((flags & DP_F_ZERO) && (padlen > 0)) {
682 if (signvalue) {
683 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
684 --padlen;
685 signvalue = 0;
686 }
687 while (padlen > 0) {
688 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
689 --padlen;
690 }
691 }
692 while (padlen > 0) {
693 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
694 --padlen;
695 }
696 if (signvalue)
697 doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
698
699 while (iplace > 0)
700 doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
701
702 /*
703 * Decimal point. This should probably use locale to find the correct
704 * char to print out.
705 */
706 if (max > 0 || (flags & DP_F_NUM)) {
707 doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
708
709 while (fplace > 0)
710 doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
711 }
712 while (zpadlen > 0) {
713 doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
714 --zpadlen;
715 }
716
717 while (padlen < 0) {
718 doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
719 ++padlen;
720 }
721}
722
723static void
724doapr_outch(
725 char **sbuffer,
726 char **buffer,
727 size_t *currlen,
728 size_t *maxlen,
729 int c)
730{
731 /* If we haven't at least one buffer, someone has doe a big booboo */
732 assert(*sbuffer != NULL || buffer != NULL);
733
734 if (buffer) {
735 while (*currlen >= *maxlen) {
736 if (*buffer == NULL) {
737 if (*maxlen == 0)
738 *maxlen = 1024;
739 *buffer = OPENSSL_malloc(*maxlen);
740 if (*currlen > 0) {
741 assert(*sbuffer != NULL);
742 memcpy(*buffer, *sbuffer, *currlen);
743 }
744 *sbuffer = NULL;
745 } else {
746 *maxlen += 1024;
747 *buffer = OPENSSL_realloc(*buffer, *maxlen);
748 }
749 }
750 /* What to do if *buffer is NULL? */
751 assert(*sbuffer != NULL || *buffer != NULL);
752 }
753
754 if (*currlen < *maxlen) {
755 if (*sbuffer)
756 (*sbuffer)[(*currlen)++] = (char)c;
757 else
758 (*buffer)[(*currlen)++] = (char)c;
759 }
760
761 return;
762}
763
764/***************************************************************************/
765
766int BIO_printf (BIO *bio, const char *format, ...)
767 {
768 va_list args;
769 int ret;
770
771 va_start(args, format);
772
773 ret = BIO_vprintf(bio, format, args);
774
775 va_end(args);
776 return(ret);
777 }
778
779int BIO_vprintf (BIO *bio, const char *format, va_list args)
780 {
781 int ret;
782 size_t retlen;
783 char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable
784 in small-stack environments, like threads
785 or DOS programs. */
786 char *hugebufp = hugebuf;
787 size_t hugebufsize = sizeof(hugebuf);
788 char *dynbuf = NULL;
789 int ignored;
790
791 dynbuf = NULL;
792 CRYPTO_push_info("doapr()");
793 _dopr(&hugebufp, &dynbuf, &hugebufsize,
794 &retlen, &ignored, format, args);
795 if (dynbuf)
796 {
797 ret=BIO_write(bio, dynbuf, (int)retlen);
798 OPENSSL_free(dynbuf);
799 }
800 else
801 {
802 ret=BIO_write(bio, hugebuf, (int)retlen);
803 }
804 CRYPTO_pop_info();
805 return(ret);
806 }
807
808/* As snprintf is not available everywhere, we provide our own implementation.
809 * In case of overflow or error, this returns -1.
810 * This function has nothing to do with BIOs, but it's closely related
811 * to BIO_printf, and we need *some* name prefix ...
812 * (XXX the function should be renamed, but to what?) */
813int BIO_snprintf(char *buf, size_t n, const char *format, ...)
814 {
815 va_list args;
816 int ret;
817
818 va_start(args, format);
819
820 ret = BIO_vsnprintf(buf, n, format, args);
821
822 va_end(args);
823 return(ret);
824 }
825
826int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
827 {
828 size_t retlen;
829 int truncated;
830
831 _dopr(&buf, NULL, &n, &retlen, &truncated, format, args);
832
833 if (truncated)
834 /* In case of truncation, return -1 unlike traditional snprintf.
835 * (Current drafts for ISO/IEC 9899 say snprintf should return
836 * the number of characters that would have been written,
837 * had the buffer been large enough, as it did historically.) */
838 return -1;
839 else
840 return (retlen <= INT_MAX) ? (int)retlen : -1;
841 }
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
deleted file mode 100644
index c851298d1e..0000000000
--- a/src/lib/libcrypto/bio/b_sock.c
+++ /dev/null
@@ -1,752 +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 OPENSSL_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 OPENSSL_SYS_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 SO_MAXCONN
76#elif defined(SOMAXCONN)
77#define MAX_LISTEN SOMAXCONN
78#else
79#define MAX_LISTEN 32
80#endif
81
82#ifdef OPENSSL_SYS_WINDOWS
83static int wsa_init_done=0;
84#endif
85
86#if 0
87static unsigned long BIO_ghbn_hits=0L;
88static unsigned long BIO_ghbn_miss=0L;
89
90#define GHBN_NUM 4
91static struct ghbn_cache_st
92 {
93 char name[129];
94 struct hostent *ent;
95 unsigned long order;
96 } ghbn_cache[GHBN_NUM];
97#endif
98
99static int get_ip(const char *str,unsigned char *ip);
100#if 0
101static void ghbn_free(struct hostent *a);
102static struct hostent *ghbn_dup(struct hostent *a);
103#endif
104int BIO_get_host_ip(const char *str, unsigned char *ip)
105 {
106 int i;
107 int err = 1;
108 int locked = 0;
109 struct hostent *he;
110
111 i=get_ip(str,ip);
112 if (i < 0)
113 {
114 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
115 goto err;
116 }
117
118 /* At this point, we have something that is most probably correct
119 in some way, so let's init the socket. */
120 if (BIO_sock_init() != 1)
121 return 0; /* don't generate another error code here */
122
123 /* If the string actually contained an IP address, we need not do
124 anything more */
125 if (i > 0) return(1);
126
127 /* do a gethostbyname */
128 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
129 locked = 1;
130 he=BIO_gethostbyname(str);
131 if (he == NULL)
132 {
133 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
134 goto err;
135 }
136
137 /* cast to short because of win16 winsock definition */
138 if ((short)he->h_addrtype != AF_INET)
139 {
140 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
141 goto err;
142 }
143 for (i=0; i<4; i++)
144 ip[i]=he->h_addr_list[0][i];
145 err = 0;
146
147 err:
148 if (locked)
149 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
150 if (err)
151 {
152 ERR_add_error_data(2,"host=",str);
153 return 0;
154 }
155 else
156 return 1;
157 }
158
159int BIO_get_port(const char *str, unsigned short *port_ptr)
160 {
161 int i;
162 struct servent *s;
163
164 if (str == NULL)
165 {
166 BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED);
167 return(0);
168 }
169 i=atoi(str);
170 if (i != 0)
171 *port_ptr=(unsigned short)i;
172 else
173 {
174 CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
175 /* Note: under VMS with SOCKETSHR, it seems like the first
176 * parameter is 'char *', instead of 'const char *'
177 */
178 s=getservbyname(
179#ifndef CONST_STRICT
180 (char *)
181#endif
182 str,"tcp");
183 if(s != NULL)
184 *port_ptr=ntohs((unsigned short)s->s_port);
185 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
186 if(s == NULL)
187 {
188 if (strcmp(str,"http") == 0)
189 *port_ptr=80;
190 else if (strcmp(str,"telnet") == 0)
191 *port_ptr=23;
192 else if (strcmp(str,"socks") == 0)
193 *port_ptr=1080;
194 else if (strcmp(str,"https") == 0)
195 *port_ptr=443;
196 else if (strcmp(str,"ssl") == 0)
197 *port_ptr=443;
198 else if (strcmp(str,"ftp") == 0)
199 *port_ptr=21;
200 else if (strcmp(str,"gopher") == 0)
201 *port_ptr=70;
202#if 0
203 else if (strcmp(str,"wais") == 0)
204 *port_ptr=21;
205#endif
206 else
207 {
208 SYSerr(SYS_F_GETSERVBYNAME,get_last_socket_error());
209 ERR_add_error_data(3,"service='",str,"'");
210 return(0);
211 }
212 }
213 }
214 return(1);
215 }
216
217int BIO_sock_error(int sock)
218 {
219 int j,i;
220 int size;
221
222 size=sizeof(int);
223 /* Note: under Windows the third parameter is of type (char *)
224 * whereas under other systems it is (void *) if you don't have
225 * a cast it will choke the compiler: if you do have a cast then
226 * you can either go for (char *) or (void *).
227 */
228 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size);
229 if (i < 0)
230 return(1);
231 else
232 return(j);
233 }
234
235#if 0
236long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
237 {
238 int i;
239 char **p;
240
241 switch (cmd)
242 {
243 case BIO_GHBN_CTRL_HITS:
244 return(BIO_ghbn_hits);
245 /* break; */
246 case BIO_GHBN_CTRL_MISSES:
247 return(BIO_ghbn_miss);
248 /* break; */
249 case BIO_GHBN_CTRL_CACHE_SIZE:
250 return(GHBN_NUM);
251 /* break; */
252 case BIO_GHBN_CTRL_GET_ENTRY:
253 if ((iarg >= 0) && (iarg <GHBN_NUM) &&
254 (ghbn_cache[iarg].order > 0))
255 {
256 p=(char **)parg;
257 if (p == NULL) return(0);
258 *p=ghbn_cache[iarg].name;
259 ghbn_cache[iarg].name[128]='\0';
260 return(1);
261 }
262 return(0);
263 /* break; */
264 case BIO_GHBN_CTRL_FLUSH:
265 for (i=0; i<GHBN_NUM; i++)
266 ghbn_cache[i].order=0;
267 break;
268 default:
269 return(0);
270 }
271 return(1);
272 }
273#endif
274
275#if 0
276static struct hostent *ghbn_dup(struct hostent *a)
277 {
278 struct hostent *ret;
279 int i,j;
280
281 MemCheck_off();
282 ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
283 if (ret == NULL) return(NULL);
284 memset(ret,0,sizeof(struct hostent));
285
286 for (i=0; a->h_aliases[i] != NULL; i++)
287 ;
288 i++;
289 ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *));
290 if (ret->h_aliases == NULL)
291 goto err;
292 memset(ret->h_aliases, 0, i*sizeof(char *));
293
294 for (i=0; a->h_addr_list[i] != NULL; i++)
295 ;
296 i++;
297 ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *));
298 if (ret->h_addr_list == NULL)
299 goto err;
300 memset(ret->h_addr_list, 0, i*sizeof(char *));
301
302 j=strlen(a->h_name)+1;
303 if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err;
304 memcpy((char *)ret->h_name,a->h_name,j);
305 for (i=0; a->h_aliases[i] != NULL; i++)
306 {
307 j=strlen(a->h_aliases[i])+1;
308 if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err;
309 memcpy(ret->h_aliases[i],a->h_aliases[i],j);
310 }
311 ret->h_length=a->h_length;
312 ret->h_addrtype=a->h_addrtype;
313 for (i=0; a->h_addr_list[i] != NULL; i++)
314 {
315 if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL)
316 goto err;
317 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
318 }
319 if (0)
320 {
321err:
322 if (ret != NULL)
323 ghbn_free(ret);
324 ret=NULL;
325 }
326 MemCheck_on();
327 return(ret);
328 }
329
330static void ghbn_free(struct hostent *a)
331 {
332 int i;
333
334 if(a == NULL)
335 return;
336
337 if (a->h_aliases != NULL)
338 {
339 for (i=0; a->h_aliases[i] != NULL; i++)
340 OPENSSL_free(a->h_aliases[i]);
341 OPENSSL_free(a->h_aliases);
342 }
343 if (a->h_addr_list != NULL)
344 {
345 for (i=0; a->h_addr_list[i] != NULL; i++)
346 OPENSSL_free(a->h_addr_list[i]);
347 OPENSSL_free(a->h_addr_list);
348 }
349 if (a->h_name != NULL) OPENSSL_free(a->h_name);
350 OPENSSL_free(a);
351 }
352
353#endif
354
355struct hostent *BIO_gethostbyname(const char *name)
356 {
357#if 1
358 /* Caching gethostbyname() results forever is wrong,
359 * so we have to let the true gethostbyname() worry about this */
360 return gethostbyname(name);
361#else
362 struct hostent *ret;
363 int i,lowi=0,j;
364 unsigned long low= (unsigned long)-1;
365
366
367# if 0
368 /* It doesn't make sense to use locking here: The function interface
369 * is not thread-safe, because threads can never be sure when
370 * some other thread destroys the data they were given a pointer to.
371 */
372 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
373# endif
374 j=strlen(name);
375 if (j < 128)
376 {
377 for (i=0; i<GHBN_NUM; i++)
378 {
379 if (low > ghbn_cache[i].order)
380 {
381 low=ghbn_cache[i].order;
382 lowi=i;
383 }
384 if (ghbn_cache[i].order > 0)
385 {
386 if (strncmp(name,ghbn_cache[i].name,128) == 0)
387 break;
388 }
389 }
390 }
391 else
392 i=GHBN_NUM;
393
394 if (i == GHBN_NUM) /* no hit*/
395 {
396 BIO_ghbn_miss++;
397 /* Note: under VMS with SOCKETSHR, it seems like the first
398 * parameter is 'char *', instead of 'const char *'
399 */
400 ret=gethostbyname(
401# ifndef CONST_STRICT
402 (char *)
403# endif
404 name);
405
406 if (ret == NULL)
407 goto end;
408 if (j > 128) /* too big to cache */
409 {
410# if 0
411 /* If we were trying to make this function thread-safe (which
412 * is bound to fail), we'd have to give up in this case
413 * (or allocate more memory). */
414 ret = NULL;
415# endif
416 goto end;
417 }
418
419 /* else add to cache */
420 if (ghbn_cache[lowi].ent != NULL)
421 ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
422 ghbn_cache[lowi].name[0] = '\0';
423
424 if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
425 {
426 BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE);
427 goto end;
428 }
429 strncpy(ghbn_cache[lowi].name,name,128);
430 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
431 }
432 else
433 {
434 BIO_ghbn_hits++;
435 ret= ghbn_cache[i].ent;
436 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
437 }
438end:
439# if 0
440 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
441# endif
442 return(ret);
443#endif
444 }
445
446
447int BIO_sock_init(void)
448 {
449#ifdef OPENSSL_SYS_WINDOWS
450 static struct WSAData wsa_state;
451
452 if (!wsa_init_done)
453 {
454 int err;
455
456#ifdef SIGINT
457 signal(SIGINT,(void (*)(int))BIO_sock_cleanup);
458#endif
459 wsa_init_done=1;
460 memset(&wsa_state,0,sizeof(wsa_state));
461 if (WSAStartup(0x0101,&wsa_state)!=0)
462 {
463 err=WSAGetLastError();
464 SYSerr(SYS_F_WSASTARTUP,err);
465 BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
466 return(-1);
467 }
468 }
469#endif /* OPENSSL_SYS_WINDOWS */
470#ifdef WATT32
471 extern int _watt_do_exit;
472 _watt_do_exit = 0; /* don't make sock_init() call exit() */
473 if (sock_init())
474 return (-1);
475#endif
476 return(1);
477 }
478
479void BIO_sock_cleanup(void)
480 {
481#ifdef OPENSSL_SYS_WINDOWS
482 if (wsa_init_done)
483 {
484 wsa_init_done=0;
485#ifndef OPENSSL_SYS_WINCE
486 WSACancelBlockingCall();
487#endif
488 WSACleanup();
489 }
490#endif
491 }
492
493#if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000
494
495int BIO_socket_ioctl(int fd, long type, void *arg)
496 {
497 int i;
498
499#ifdef __DJGPP__
500 i=ioctlsocket(fd,type,(char *)arg);
501#else
502 i=ioctlsocket(fd,type,arg);
503#endif /* __DJGPP__ */
504 if (i < 0)
505 SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error());
506 return(i);
507 }
508#endif /* __VMS_VER */
509
510/* The reason I have implemented this instead of using sscanf is because
511 * Visual C 1.52c gives an unresolved external when linking a DLL :-( */
512static int get_ip(const char *str, unsigned char ip[4])
513 {
514 unsigned int tmp[4];
515 int num=0,c,ok=0;
516
517 tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
518
519 for (;;)
520 {
521 c= *(str++);
522 if ((c >= '0') && (c <= '9'))
523 {
524 ok=1;
525 tmp[num]=tmp[num]*10+c-'0';
526 if (tmp[num] > 255) return(0);
527 }
528 else if (c == '.')
529 {
530 if (!ok) return(-1);
531 if (num == 3) return(0);
532 num++;
533 ok=0;
534 }
535 else if (c == '\0' && (num == 3) && ok)
536 break;
537 else
538 return(0);
539 }
540 ip[0]=tmp[0];
541 ip[1]=tmp[1];
542 ip[2]=tmp[2];
543 ip[3]=tmp[3];
544 return(1);
545 }
546
547int BIO_get_accept_socket(char *host, int bind_mode)
548 {
549 int ret=0;
550 struct sockaddr_in server,client;
551 int s=INVALID_SOCKET,cs;
552 unsigned char ip[4];
553 unsigned short port;
554 char *str=NULL,*e;
555 const char *h,*p;
556 unsigned long l;
557 int err_num;
558
559 if (BIO_sock_init() != 1) return(INVALID_SOCKET);
560
561 if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);
562
563 h=p=NULL;
564 h=str;
565 for (e=str; *e; e++)
566 {
567 if (*e == ':')
568 {
569 p= &(e[1]);
570 *e='\0';
571 }
572 else if (*e == '/')
573 {
574 *e='\0';
575 break;
576 }
577 }
578
579 if (p == NULL)
580 {
581 p=h;
582 h="*";
583 }
584
585 if (!BIO_get_port(p,&port)) goto err;
586
587 memset((char *)&server,0,sizeof(server));
588 server.sin_family=AF_INET;
589 server.sin_port=htons(port);
590
591 if (strcmp(h,"*") == 0)
592 server.sin_addr.s_addr=INADDR_ANY;
593 else
594 {
595 if (!BIO_get_host_ip(h,&(ip[0]))) goto err;
596 l=(unsigned long)
597 ((unsigned long)ip[0]<<24L)|
598 ((unsigned long)ip[1]<<16L)|
599 ((unsigned long)ip[2]<< 8L)|
600 ((unsigned long)ip[3]);
601 server.sin_addr.s_addr=htonl(l);
602 }
603
604again:
605 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
606 if (s == INVALID_SOCKET)
607 {
608 SYSerr(SYS_F_SOCKET,get_last_socket_error());
609 ERR_add_error_data(3,"port='",host,"'");
610 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
611 goto err;
612 }
613
614#ifdef SO_REUSEADDR
615 if (bind_mode == BIO_BIND_REUSEADDR)
616 {
617 int i=1;
618
619 ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
620 bind_mode=BIO_BIND_NORMAL;
621 }
622#endif
623 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
624 {
625#ifdef SO_REUSEADDR
626 err_num=get_last_socket_error();
627 if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
628 (err_num == EADDRINUSE))
629 {
630 memcpy((char *)&client,(char *)&server,sizeof(server));
631 if (strcmp(h,"*") == 0)
632 client.sin_addr.s_addr=htonl(0x7F000001);
633 cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
634 if (cs != INVALID_SOCKET)
635 {
636 int ii;
637 ii=connect(cs,(struct sockaddr *)&client,
638 sizeof(client));
639 closesocket(cs);
640 if (ii == INVALID_SOCKET)
641 {
642 bind_mode=BIO_BIND_REUSEADDR;
643 closesocket(s);
644 goto again;
645 }
646 /* else error */
647 }
648 /* else error */
649 }
650#endif
651 SYSerr(SYS_F_BIND,err_num);
652 ERR_add_error_data(3,"port='",host,"'");
653 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
654 goto err;
655 }
656 if (listen(s,MAX_LISTEN) == -1)
657 {
658 SYSerr(SYS_F_BIND,get_last_socket_error());
659 ERR_add_error_data(3,"port='",host,"'");
660 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
661 goto err;
662 }
663 ret=1;
664err:
665 if (str != NULL) OPENSSL_free(str);
666 if ((ret == 0) && (s != INVALID_SOCKET))
667 {
668 closesocket(s);
669 s= INVALID_SOCKET;
670 }
671 return(s);
672 }
673
674int BIO_accept(int sock, char **addr)
675 {
676 int ret=INVALID_SOCKET;
677 static struct sockaddr_in from;
678 unsigned long l;
679 unsigned short port;
680 int len;
681 char *p;
682
683 memset((char *)&from,0,sizeof(from));
684 len=sizeof(from);
685 /* Note: under VMS with SOCKETSHR the fourth parameter is currently
686 * of type (int *) whereas under other systems it is (void *) if
687 * you don't have a cast it will choke the compiler: if you do
688 * have a cast then you can either go for (int *) or (void *).
689 */
690 ret=accept(sock,(struct sockaddr *)&from,(void *)&len);
691 if (ret == INVALID_SOCKET)
692 {
693 if(BIO_sock_should_retry(ret)) return -2;
694 SYSerr(SYS_F_ACCEPT,get_last_socket_error());
695 BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR);
696 goto end;
697 }
698
699 if (addr == NULL) goto end;
700
701 l=ntohl(from.sin_addr.s_addr);
702 port=ntohs(from.sin_port);
703 if (*addr == NULL)
704 {
705 if ((p=OPENSSL_malloc(24)) == NULL)
706 {
707 BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
708 goto end;
709 }
710 *addr=p;
711 }
712 BIO_snprintf(*addr,24,"%d.%d.%d.%d:%d",
713 (unsigned char)(l>>24L)&0xff,
714 (unsigned char)(l>>16L)&0xff,
715 (unsigned char)(l>> 8L)&0xff,
716 (unsigned char)(l )&0xff,
717 port);
718end:
719 return(ret);
720 }
721
722int BIO_set_tcp_ndelay(int s, int on)
723 {
724 int ret=0;
725#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
726 int opt;
727
728#ifdef SOL_TCP
729 opt=SOL_TCP;
730#else
731#ifdef IPPROTO_TCP
732 opt=IPPROTO_TCP;
733#endif
734#endif
735
736 ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on));
737#endif
738 return(ret == 0);
739 }
740#endif
741
742int BIO_socket_nbio(int s, int mode)
743 {
744 int ret= -1;
745 int l;
746
747 l=mode;
748#ifdef FIONBIO
749 ret=BIO_socket_ioctl(s,FIONBIO,&l);
750#endif
751 return(ret == 0);
752 }
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
deleted file mode 100644
index c1fd75aaad..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
64static int buffer_write(BIO *h, const char *buf,int num);
65static int buffer_read(BIO *h, char *buf, int size);
66static int buffer_puts(BIO *h, const char *str);
67static int buffer_gets(BIO *h, char *str, int size);
68static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int buffer_new(BIO *h);
70static int buffer_free(BIO *data);
71static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
72#define DEFAULT_BUFFER_SIZE 4096
73
74static BIO_METHOD methods_buffer=
75 {
76 BIO_TYPE_BUFFER,
77 "buffer",
78 buffer_write,
79 buffer_read,
80 buffer_puts,
81 buffer_gets,
82 buffer_ctrl,
83 buffer_new,
84 buffer_free,
85 buffer_callback_ctrl,
86 };
87
88BIO_METHOD *BIO_f_buffer(void)
89 {
90 return(&methods_buffer);
91 }
92
93static int buffer_new(BIO *bi)
94 {
95 BIO_F_BUFFER_CTX *ctx;
96
97 ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
98 if (ctx == NULL) return(0);
99 ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
100 if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); }
101 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
102 if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); }
103 ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
104 ctx->obuf_size=DEFAULT_BUFFER_SIZE;
105 ctx->ibuf_len=0;
106 ctx->ibuf_off=0;
107 ctx->obuf_len=0;
108 ctx->obuf_off=0;
109
110 bi->init=1;
111 bi->ptr=(char *)ctx;
112 bi->flags=0;
113 return(1);
114 }
115
116static int buffer_free(BIO *a)
117 {
118 BIO_F_BUFFER_CTX *b;
119
120 if (a == NULL) return(0);
121 b=(BIO_F_BUFFER_CTX *)a->ptr;
122 if (b->ibuf != NULL) OPENSSL_free(b->ibuf);
123 if (b->obuf != NULL) OPENSSL_free(b->obuf);
124 OPENSSL_free(a->ptr);
125 a->ptr=NULL;
126 a->init=0;
127 a->flags=0;
128 return(1);
129 }
130
131static int buffer_read(BIO *b, char *out, int outl)
132 {
133 int i,num=0;
134 BIO_F_BUFFER_CTX *ctx;
135
136 if (out == NULL) return(0);
137 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
138
139 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
140 num=0;
141 BIO_clear_retry_flags(b);
142
143start:
144 i=ctx->ibuf_len;
145 /* If there is stuff left over, grab it */
146 if (i != 0)
147 {
148 if (i > outl) i=outl;
149 memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i);
150 ctx->ibuf_off+=i;
151 ctx->ibuf_len-=i;
152 num+=i;
153 if (outl == i) return(num);
154 outl-=i;
155 out+=i;
156 }
157
158 /* We may have done a partial read. try to do more.
159 * We have nothing in the buffer.
160 * If we get an error and have read some data, just return it
161 * and let them retry to get the error again.
162 * copy direct to parent address space */
163 if (outl > ctx->ibuf_size)
164 {
165 for (;;)
166 {
167 i=BIO_read(b->next_bio,out,outl);
168 if (i <= 0)
169 {
170 BIO_copy_next_retry(b);
171 if (i < 0) return((num > 0)?num:i);
172 if (i == 0) return(num);
173 }
174 num+=i;
175 if (outl == i) return(num);
176 out+=i;
177 outl-=i;
178 }
179 }
180 /* else */
181
182 /* we are going to be doing some buffering */
183 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
184 if (i <= 0)
185 {
186 BIO_copy_next_retry(b);
187 if (i < 0) return((num > 0)?num:i);
188 if (i == 0) return(num);
189 }
190 ctx->ibuf_off=0;
191 ctx->ibuf_len=i;
192
193 /* Lets re-read using ourselves :-) */
194 goto start;
195 }
196
197static int buffer_write(BIO *b, const char *in, int inl)
198 {
199 int i,num=0;
200 BIO_F_BUFFER_CTX *ctx;
201
202 if ((in == NULL) || (inl <= 0)) return(0);
203 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
204 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
205
206 BIO_clear_retry_flags(b);
207start:
208 i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off);
209 /* add to buffer and return */
210 if (i >= inl)
211 {
212 memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl);
213 ctx->obuf_len+=inl;
214 return(num+inl);
215 }
216 /* else */
217 /* stuff already in buffer, so add to it first, then flush */
218 if (ctx->obuf_len != 0)
219 {
220 if (i > 0) /* lets fill it up if we can */
221 {
222 memcpy(&(ctx->obuf[ctx->obuf_len]),in,i);
223 in+=i;
224 inl-=i;
225 num+=i;
226 ctx->obuf_len+=i;
227 }
228 /* we now have a full buffer needing flushing */
229 for (;;)
230 {
231 i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]),
232 ctx->obuf_len);
233 if (i <= 0)
234 {
235 BIO_copy_next_retry(b);
236
237 if (i < 0) return((num > 0)?num:i);
238 if (i == 0) return(num);
239 }
240 ctx->obuf_off+=i;
241 ctx->obuf_len-=i;
242 if (ctx->obuf_len == 0) break;
243 }
244 }
245 /* we only get here if the buffer has been flushed and we
246 * still have stuff to write */
247 ctx->obuf_off=0;
248
249 /* we now have inl bytes to write */
250 while (inl >= ctx->obuf_size)
251 {
252 i=BIO_write(b->next_bio,in,inl);
253 if (i <= 0)
254 {
255 BIO_copy_next_retry(b);
256 if (i < 0) return((num > 0)?num:i);
257 if (i == 0) return(num);
258 }
259 num+=i;
260 in+=i;
261 inl-=i;
262 if (inl == 0) return(num);
263 }
264
265 /* copy the rest into the buffer since we have only a small
266 * amount left */
267 goto start;
268 }
269
270static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
271 {
272 BIO *dbio;
273 BIO_F_BUFFER_CTX *ctx;
274 long ret=1;
275 char *p1,*p2;
276 int r,i,*ip;
277 int ibs,obs;
278
279 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
280
281 switch (cmd)
282 {
283 case BIO_CTRL_RESET:
284 ctx->ibuf_off=0;
285 ctx->ibuf_len=0;
286 ctx->obuf_off=0;
287 ctx->obuf_len=0;
288 if (b->next_bio == NULL) return(0);
289 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
290 break;
291 case BIO_CTRL_INFO:
292 ret=(long)ctx->obuf_len;
293 break;
294 case BIO_C_GET_BUFF_NUM_LINES:
295 ret=0;
296 p1=ctx->ibuf;
297 for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++)
298 {
299 if (p1[i] == '\n') ret++;
300 }
301 break;
302 case BIO_CTRL_WPENDING:
303 ret=(long)ctx->obuf_len;
304 if (ret == 0)
305 {
306 if (b->next_bio == NULL) return(0);
307 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
308 }
309 break;
310 case BIO_CTRL_PENDING:
311 ret=(long)ctx->ibuf_len;
312 if (ret == 0)
313 {
314 if (b->next_bio == NULL) return(0);
315 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
316 }
317 break;
318 case BIO_C_SET_BUFF_READ_DATA:
319 if (num > ctx->ibuf_size)
320 {
321 p1=OPENSSL_malloc((int)num);
322 if (p1 == NULL) goto malloc_error;
323 if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf);
324 ctx->ibuf=p1;
325 }
326 ctx->ibuf_off=0;
327 ctx->ibuf_len=(int)num;
328 memcpy(ctx->ibuf,ptr,(int)num);
329 ret=1;
330 break;
331 case BIO_C_SET_BUFF_SIZE:
332 if (ptr != NULL)
333 {
334 ip=(int *)ptr;
335 if (*ip == 0)
336 {
337 ibs=(int)num;
338 obs=ctx->obuf_size;
339 }
340 else /* if (*ip == 1) */
341 {
342 ibs=ctx->ibuf_size;
343 obs=(int)num;
344 }
345 }
346 else
347 {
348 ibs=(int)num;
349 obs=(int)num;
350 }
351 p1=ctx->ibuf;
352 p2=ctx->obuf;
353 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
354 {
355 p1=(char *)OPENSSL_malloc((int)num);
356 if (p1 == NULL) goto malloc_error;
357 }
358 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
359 {
360 p2=(char *)OPENSSL_malloc((int)num);
361 if (p2 == NULL)
362 {
363 if (p1 != ctx->ibuf) OPENSSL_free(p1);
364 goto malloc_error;
365 }
366 }
367 if (ctx->ibuf != p1)
368 {
369 OPENSSL_free(ctx->ibuf);
370 ctx->ibuf=p1;
371 ctx->ibuf_off=0;
372 ctx->ibuf_len=0;
373 ctx->ibuf_size=ibs;
374 }
375 if (ctx->obuf != p2)
376 {
377 OPENSSL_free(ctx->obuf);
378 ctx->obuf=p2;
379 ctx->obuf_off=0;
380 ctx->obuf_len=0;
381 ctx->obuf_size=obs;
382 }
383 break;
384 case BIO_C_DO_STATE_MACHINE:
385 if (b->next_bio == NULL) return(0);
386 BIO_clear_retry_flags(b);
387 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
388 BIO_copy_next_retry(b);
389 break;
390
391 case BIO_CTRL_FLUSH:
392 if (b->next_bio == NULL) return(0);
393 if (ctx->obuf_len <= 0)
394 {
395 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
396 break;
397 }
398
399 for (;;)
400 {
401 BIO_clear_retry_flags(b);
402 if (ctx->obuf_len > ctx->obuf_off)
403 {
404 r=BIO_write(b->next_bio,
405 &(ctx->obuf[ctx->obuf_off]),
406 ctx->obuf_len-ctx->obuf_off);
407#if 0
408fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r);
409#endif
410 BIO_copy_next_retry(b);
411 if (r <= 0) return((long)r);
412 ctx->obuf_off+=r;
413 }
414 else
415 {
416 ctx->obuf_len=0;
417 ctx->obuf_off=0;
418 ret=1;
419 break;
420 }
421 }
422 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
423 break;
424 case BIO_CTRL_DUP:
425 dbio=(BIO *)ptr;
426 if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) ||
427 !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
428 ret=0;
429 break;
430 default:
431 if (b->next_bio == NULL) return(0);
432 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
433 break;
434 }
435 return(ret);
436malloc_error:
437 BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE);
438 return(0);
439 }
440
441static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
442 {
443 long ret=1;
444
445 if (b->next_bio == NULL) return(0);
446 switch (cmd)
447 {
448 default:
449 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
450 break;
451 }
452 return(ret);
453 }
454
455static int buffer_gets(BIO *b, char *buf, int size)
456 {
457 BIO_F_BUFFER_CTX *ctx;
458 int num=0,i,flag;
459 char *p;
460
461 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
462 size--; /* reserve space for a '\0' */
463 BIO_clear_retry_flags(b);
464
465 for (;;)
466 {
467 if (ctx->ibuf_len > 0)
468 {
469 p= &(ctx->ibuf[ctx->ibuf_off]);
470 flag=0;
471 for (i=0; (i<ctx->ibuf_len) && (i<size); i++)
472 {
473 *(buf++)=p[i];
474 if (p[i] == '\n')
475 {
476 flag=1;
477 i++;
478 break;
479 }
480 }
481 num+=i;
482 size-=i;
483 ctx->ibuf_len-=i;
484 ctx->ibuf_off+=i;
485 if (flag || size == 0)
486 {
487 *buf='\0';
488 return(num);
489 }
490 }
491 else /* read another chunk */
492 {
493 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
494 if (i <= 0)
495 {
496 BIO_copy_next_retry(b);
497 *buf='\0';
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, const char *str)
508 {
509 return(buffer_write(b,str,strlen(str)));
510 }
511
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c
deleted file mode 100644
index ec0f7eb0b7..0000000000
--- a/src/lib/libcrypto/bio/bf_lbuf.c
+++ /dev/null
@@ -1,397 +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 linebuffer_write(BIO *h, const char *buf,int num);
66static int linebuffer_read(BIO *h, char *buf, int size);
67static int linebuffer_puts(BIO *h, const char *str);
68static int linebuffer_gets(BIO *h, char *str, int size);
69static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int linebuffer_new(BIO *h);
71static int linebuffer_free(BIO *data);
72static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
73
74/* A 10k maximum should be enough for most purposes */
75#define DEFAULT_LINEBUFFER_SIZE 1024*10
76
77/* #define DEBUG */
78
79static BIO_METHOD methods_linebuffer=
80 {
81 BIO_TYPE_LINEBUFFER,
82 "linebuffer",
83 linebuffer_write,
84 linebuffer_read,
85 linebuffer_puts,
86 linebuffer_gets,
87 linebuffer_ctrl,
88 linebuffer_new,
89 linebuffer_free,
90 linebuffer_callback_ctrl,
91 };
92
93BIO_METHOD *BIO_f_linebuffer(void)
94 {
95 return(&methods_linebuffer);
96 }
97
98typedef struct bio_linebuffer_ctx_struct
99 {
100 char *obuf; /* the output char array */
101 int obuf_size; /* how big is the output buffer */
102 int obuf_len; /* how many bytes are in it */
103 } BIO_LINEBUFFER_CTX;
104
105static int linebuffer_new(BIO *bi)
106 {
107 BIO_LINEBUFFER_CTX *ctx;
108
109 ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
110 if (ctx == NULL) return(0);
111 ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
112 if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); }
113 ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE;
114 ctx->obuf_len=0;
115
116 bi->init=1;
117 bi->ptr=(char *)ctx;
118 bi->flags=0;
119 return(1);
120 }
121
122static int linebuffer_free(BIO *a)
123 {
124 BIO_LINEBUFFER_CTX *b;
125
126 if (a == NULL) return(0);
127 b=(BIO_LINEBUFFER_CTX *)a->ptr;
128 if (b->obuf != NULL) OPENSSL_free(b->obuf);
129 OPENSSL_free(a->ptr);
130 a->ptr=NULL;
131 a->init=0;
132 a->flags=0;
133 return(1);
134 }
135
136static int linebuffer_read(BIO *b, char *out, int outl)
137 {
138 int ret=0;
139
140 if (out == NULL) return(0);
141 if (b->next_bio == NULL) return(0);
142 ret=BIO_read(b->next_bio,out,outl);
143 BIO_clear_retry_flags(b);
144 BIO_copy_next_retry(b);
145 return(ret);
146 }
147
148static int linebuffer_write(BIO *b, const char *in, int inl)
149 {
150 int i,num=0,foundnl;
151 BIO_LINEBUFFER_CTX *ctx;
152
153 if ((in == NULL) || (inl <= 0)) return(0);
154 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
155 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
156
157 BIO_clear_retry_flags(b);
158
159 do
160 {
161 const char *p;
162
163 for(p = in; p < in + inl && *p != '\n'; p++)
164 ;
165 if (*p == '\n')
166 {
167 p++;
168 foundnl = 1;
169 }
170 else
171 foundnl = 0;
172
173 /* If a NL was found and we already have text in the save
174 buffer, concatenate them and write */
175 while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
176 && ctx->obuf_len > 0)
177 {
178 int orig_olen = ctx->obuf_len;
179
180 i = ctx->obuf_size - ctx->obuf_len;
181 if (p - in > 0)
182 {
183 if (i >= p - in)
184 {
185 memcpy(&(ctx->obuf[ctx->obuf_len]),
186 in,p - in);
187 ctx->obuf_len += p - in;
188 inl -= p - in;
189 num += p - in;
190 in = p;
191 }
192 else
193 {
194 memcpy(&(ctx->obuf[ctx->obuf_len]),
195 in,i);
196 ctx->obuf_len += i;
197 inl -= i;
198 in += i;
199 num += i;
200 }
201 }
202
203#if 0
204BIO_write(b->next_bio, "<*<", 3);
205#endif
206 i=BIO_write(b->next_bio,
207 ctx->obuf, ctx->obuf_len);
208 if (i <= 0)
209 {
210 ctx->obuf_len = orig_olen;
211 BIO_copy_next_retry(b);
212
213#if 0
214BIO_write(b->next_bio, ">*>", 3);
215#endif
216 if (i < 0) return((num > 0)?num:i);
217 if (i == 0) return(num);
218 }
219#if 0
220BIO_write(b->next_bio, ">*>", 3);
221#endif
222 if (i < ctx->obuf_len)
223 memmove(ctx->obuf, ctx->obuf + i,
224 ctx->obuf_len - i);
225 ctx->obuf_len-=i;
226 }
227
228 /* Now that the save buffer is emptied, let's write the input
229 buffer if a NL was found and there is anything to write. */
230 if ((foundnl || p - in > ctx->obuf_size) && p - in > 0)
231 {
232#if 0
233BIO_write(b->next_bio, "<*<", 3);
234#endif
235 i=BIO_write(b->next_bio,in,p - in);
236 if (i <= 0)
237 {
238 BIO_copy_next_retry(b);
239#if 0
240BIO_write(b->next_bio, ">*>", 3);
241#endif
242 if (i < 0) return((num > 0)?num:i);
243 if (i == 0) return(num);
244 }
245#if 0
246BIO_write(b->next_bio, ">*>", 3);
247#endif
248 num+=i;
249 in+=i;
250 inl-=i;
251 }
252 }
253 while(foundnl && inl > 0);
254 /* We've written as much as we can. The rest of the input buffer, if
255 any, is text that doesn't and with a NL and therefore needs to be
256 saved for the next trip. */
257 if (inl > 0)
258 {
259 memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
260 ctx->obuf_len += inl;
261 num += inl;
262 }
263 return num;
264 }
265
266static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
267 {
268 BIO *dbio;
269 BIO_LINEBUFFER_CTX *ctx;
270 long ret=1;
271 char *p;
272 int r;
273 int obs;
274
275 ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
276
277 switch (cmd)
278 {
279 case BIO_CTRL_RESET:
280 ctx->obuf_len=0;
281 if (b->next_bio == NULL) return(0);
282 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
283 break;
284 case BIO_CTRL_INFO:
285 ret=(long)ctx->obuf_len;
286 break;
287 case BIO_CTRL_WPENDING:
288 ret=(long)ctx->obuf_len;
289 if (ret == 0)
290 {
291 if (b->next_bio == NULL) return(0);
292 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
293 }
294 break;
295 case BIO_C_SET_BUFF_SIZE:
296 obs=(int)num;
297 p=ctx->obuf;
298 if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size))
299 {
300 p=(char *)OPENSSL_malloc((int)num);
301 if (p == NULL)
302 goto malloc_error;
303 }
304 if (ctx->obuf != p)
305 {
306 if (ctx->obuf_len > obs)
307 {
308 ctx->obuf_len = obs;
309 }
310 memcpy(p, ctx->obuf, ctx->obuf_len);
311 OPENSSL_free(ctx->obuf);
312 ctx->obuf=p;
313 ctx->obuf_size=obs;
314 }
315 break;
316 case BIO_C_DO_STATE_MACHINE:
317 if (b->next_bio == NULL) return(0);
318 BIO_clear_retry_flags(b);
319 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
320 BIO_copy_next_retry(b);
321 break;
322
323 case BIO_CTRL_FLUSH:
324 if (b->next_bio == NULL) return(0);
325 if (ctx->obuf_len <= 0)
326 {
327 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
328 break;
329 }
330
331 for (;;)
332 {
333 BIO_clear_retry_flags(b);
334 if (ctx->obuf_len > 0)
335 {
336 r=BIO_write(b->next_bio,
337 ctx->obuf, ctx->obuf_len);
338#if 0
339fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r);
340#endif
341 BIO_copy_next_retry(b);
342 if (r <= 0) return((long)r);
343 if (r < ctx->obuf_len)
344 memmove(ctx->obuf, ctx->obuf + r,
345 ctx->obuf_len - r);
346 ctx->obuf_len-=r;
347 }
348 else
349 {
350 ctx->obuf_len=0;
351 ret=1;
352 break;
353 }
354 }
355 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
356 break;
357 case BIO_CTRL_DUP:
358 dbio=(BIO *)ptr;
359 if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
360 ret=0;
361 break;
362 default:
363 if (b->next_bio == NULL) return(0);
364 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
365 break;
366 }
367 return(ret);
368malloc_error:
369 BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE);
370 return(0);
371 }
372
373static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
374 {
375 long ret=1;
376
377 if (b->next_bio == NULL) return(0);
378 switch (cmd)
379 {
380 default:
381 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
382 break;
383 }
384 return(ret);
385 }
386
387static int linebuffer_gets(BIO *b, char *buf, int size)
388 {
389 if (b->next_bio == NULL) return(0);
390 return(BIO_gets(b->next_bio,buf,size));
391 }
392
393static int linebuffer_puts(BIO *b, const char *str)
394 {
395 return(linebuffer_write(b,str,strlen(str)));
396 }
397
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
deleted file mode 100644
index 1ce2bfacc0..0000000000
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ /dev/null
@@ -1,255 +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
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68static int nbiof_write(BIO *h,const char *buf,int num);
69static int nbiof_read(BIO *h,char *buf,int size);
70static int nbiof_puts(BIO *h,const char *str);
71static int nbiof_gets(BIO *h,char *str,int size);
72static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2);
73static int nbiof_new(BIO *h);
74static int nbiof_free(BIO *data);
75static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
76typedef struct nbio_test_st
77 {
78 /* only set if we sent a 'should retry' error */
79 int lrn;
80 int lwn;
81 } NBIO_TEST;
82
83static BIO_METHOD methods_nbiof=
84 {
85 BIO_TYPE_NBIO_TEST,
86 "non-blocking IO test filter",
87 nbiof_write,
88 nbiof_read,
89 nbiof_puts,
90 nbiof_gets,
91 nbiof_ctrl,
92 nbiof_new,
93 nbiof_free,
94 nbiof_callback_ctrl,
95 };
96
97BIO_METHOD *BIO_f_nbio_test(void)
98 {
99 return(&methods_nbiof);
100 }
101
102static int nbiof_new(BIO *bi)
103 {
104 NBIO_TEST *nt;
105
106 if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0);
107 nt->lrn= -1;
108 nt->lwn= -1;
109 bi->ptr=(char *)nt;
110 bi->init=1;
111 bi->flags=0;
112 return(1);
113 }
114
115static int nbiof_free(BIO *a)
116 {
117 if (a == NULL) return(0);
118 if (a->ptr != NULL)
119 OPENSSL_free(a->ptr);
120 a->ptr=NULL;
121 a->init=0;
122 a->flags=0;
123 return(1);
124 }
125
126static int nbiof_read(BIO *b, char *out, int outl)
127 {
128 NBIO_TEST *nt;
129 int ret=0;
130#if 0
131 int num;
132 unsigned char n;
133#endif
134
135 if (out == NULL) return(0);
136 if (b->next_bio == NULL) return(0);
137 nt=(NBIO_TEST *)b->ptr;
138
139 BIO_clear_retry_flags(b);
140#if 0
141 RAND_pseudo_bytes(&n,1);
142 num=(n&0x07);
143
144 if (outl > num) outl=num;
145
146 if (num == 0)
147 {
148 ret= -1;
149 BIO_set_retry_read(b);
150 }
151 else
152#endif
153 {
154 ret=BIO_read(b->next_bio,out,outl);
155 if (ret < 0)
156 BIO_copy_next_retry(b);
157 }
158 return(ret);
159 }
160
161static int nbiof_write(BIO *b, const char *in, int inl)
162 {
163 NBIO_TEST *nt;
164 int ret=0;
165 int num;
166 unsigned char n;
167
168 if ((in == NULL) || (inl <= 0)) return(0);
169 if (b->next_bio == NULL) return(0);
170 nt=(NBIO_TEST *)b->ptr;
171
172 BIO_clear_retry_flags(b);
173
174#if 1
175 if (nt->lwn > 0)
176 {
177 num=nt->lwn;
178 nt->lwn=0;
179 }
180 else
181 {
182 RAND_pseudo_bytes(&n,1);
183 num=(n&7);
184 }
185
186 if (inl > num) inl=num;
187
188 if (num == 0)
189 {
190 ret= -1;
191 BIO_set_retry_write(b);
192 }
193 else
194#endif
195 {
196 ret=BIO_write(b->next_bio,in,inl);
197 if (ret < 0)
198 {
199 BIO_copy_next_retry(b);
200 nt->lwn=inl;
201 }
202 }
203 return(ret);
204 }
205
206static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
207 {
208 long ret;
209
210 if (b->next_bio == NULL) return(0);
211 switch (cmd)
212 {
213 case BIO_C_DO_STATE_MACHINE:
214 BIO_clear_retry_flags(b);
215 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
216 BIO_copy_next_retry(b);
217 break;
218 case BIO_CTRL_DUP:
219 ret=0L;
220 break;
221 default:
222 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
223 break;
224 }
225 return(ret);
226 }
227
228static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
229 {
230 long ret=1;
231
232 if (b->next_bio == NULL) return(0);
233 switch (cmd)
234 {
235 default:
236 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
237 break;
238 }
239 return(ret);
240 }
241
242static int nbiof_gets(BIO *bp, char *buf, int size)
243 {
244 if (bp->next_bio == NULL) return(0);
245 return(BIO_gets(bp->next_bio,buf,size));
246 }
247
248
249static int nbiof_puts(BIO *bp, const char *str)
250 {
251 if (bp->next_bio == NULL) return(0);
252 return(BIO_puts(bp->next_bio,str));
253 }
254
255
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c
deleted file mode 100644
index c1bf39a904..0000000000
--- a/src/lib/libcrypto/bio/bf_null.c
+++ /dev/null
@@ -1,183 +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
64/* BIO_put and BIO_get both add to the digest,
65 * BIO_gets returns the digest */
66
67static int nullf_write(BIO *h, const char *buf, int num);
68static int nullf_read(BIO *h, char *buf, int size);
69static int nullf_puts(BIO *h, const char *str);
70static int nullf_gets(BIO *h, char *str, int size);
71static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
72static int nullf_new(BIO *h);
73static int nullf_free(BIO *data);
74static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
75static BIO_METHOD methods_nullf=
76 {
77 BIO_TYPE_NULL_FILTER,
78 "NULL filter",
79 nullf_write,
80 nullf_read,
81 nullf_puts,
82 nullf_gets,
83 nullf_ctrl,
84 nullf_new,
85 nullf_free,
86 nullf_callback_ctrl,
87 };
88
89BIO_METHOD *BIO_f_null(void)
90 {
91 return(&methods_nullf);
92 }
93
94static int nullf_new(BIO *bi)
95 {
96 bi->init=1;
97 bi->ptr=NULL;
98 bi->flags=0;
99 return(1);
100 }
101
102static int nullf_free(BIO *a)
103 {
104 if (a == NULL) return(0);
105/* a->ptr=NULL;
106 a->init=0;
107 a->flags=0;*/
108 return(1);
109 }
110
111static int nullf_read(BIO *b, char *out, int outl)
112 {
113 int ret=0;
114
115 if (out == NULL) return(0);
116 if (b->next_bio == NULL) return(0);
117 ret=BIO_read(b->next_bio,out,outl);
118 BIO_clear_retry_flags(b);
119 BIO_copy_next_retry(b);
120 return(ret);
121 }
122
123static int nullf_write(BIO *b, const char *in, int inl)
124 {
125 int ret=0;
126
127 if ((in == NULL) || (inl <= 0)) return(0);
128 if (b->next_bio == NULL) return(0);
129 ret=BIO_write(b->next_bio,in,inl);
130 BIO_clear_retry_flags(b);
131 BIO_copy_next_retry(b);
132 return(ret);
133 }
134
135static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
136 {
137 long ret;
138
139 if (b->next_bio == NULL) return(0);
140 switch(cmd)
141 {
142 case BIO_C_DO_STATE_MACHINE:
143 BIO_clear_retry_flags(b);
144 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
145 BIO_copy_next_retry(b);
146 break;
147 case BIO_CTRL_DUP:
148 ret=0L;
149 break;
150 default:
151 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
152 }
153 return(ret);
154 }
155
156static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
157 {
158 long ret=1;
159
160 if (b->next_bio == NULL) return(0);
161 switch (cmd)
162 {
163 default:
164 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
165 break;
166 }
167 return(ret);
168 }
169
170static int nullf_gets(BIO *bp, char *buf, int size)
171 {
172 if (bp->next_bio == NULL) return(0);
173 return(BIO_gets(bp->next_bio,buf,size));
174 }
175
176
177static int nullf_puts(BIO *bp, const char *str)
178 {
179 if (bp->next_bio == NULL) return(0);
180 return(BIO_puts(bp->next_bio,str));
181 }
182
183
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
deleted file mode 100644
index 2eb703830f..0000000000
--- a/src/lib/libcrypto/bio/bio.h
+++ /dev/null
@@ -1,695 +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#ifndef OPENSSL_NO_FP_API
63# include <stdio.h>
64#endif
65#include <stdarg.h>
66
67#include <openssl/crypto.h>
68#include <openssl/e_os2.h>
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74/* These are the 'types' of BIOs */
75#define BIO_TYPE_NONE 0
76#define BIO_TYPE_MEM (1|0x0400)
77#define BIO_TYPE_FILE (2|0x0400)
78
79#define BIO_TYPE_FD (4|0x0400|0x0100)
80#define BIO_TYPE_SOCKET (5|0x0400|0x0100)
81#define BIO_TYPE_NULL (6|0x0400)
82#define BIO_TYPE_SSL (7|0x0200)
83#define BIO_TYPE_MD (8|0x0200) /* passive filter */
84#define BIO_TYPE_BUFFER (9|0x0200) /* filter */
85#define BIO_TYPE_CIPHER (10|0x0200) /* filter */
86#define BIO_TYPE_BASE64 (11|0x0200) /* filter */
87#define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */
88#define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */
89#define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */
90#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */
91#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */
92#define BIO_TYPE_NULL_FILTER (17|0x0200)
93#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */
94#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
95#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */
96
97#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
98#define BIO_TYPE_FILTER 0x0200
99#define BIO_TYPE_SOURCE_SINK 0x0400
100
101/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
102 * BIO_set_fp(in,stdin,BIO_NOCLOSE); */
103#define BIO_NOCLOSE 0x00
104#define BIO_CLOSE 0x01
105
106/* These are used in the following macros and are passed to
107 * BIO_ctrl() */
108#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */
109#define BIO_CTRL_EOF 2 /* opt - are we at the eof */
110#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */
111#define BIO_CTRL_SET 4 /* man - set the 'IO' type */
112#define BIO_CTRL_GET 5 /* man - get the 'IO' type */
113#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */
114#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */
115#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */
116#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */
117#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */
118#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */
119#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */
120#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */
121/* callback is int cb(BIO *bio,state,ret); */
122#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */
123#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */
124
125#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */
126
127/* modifiers */
128#define BIO_FP_READ 0x02
129#define BIO_FP_WRITE 0x04
130#define BIO_FP_APPEND 0x08
131#define BIO_FP_TEXT 0x10
132
133#define BIO_FLAGS_READ 0x01
134#define BIO_FLAGS_WRITE 0x02
135#define BIO_FLAGS_IO_SPECIAL 0x04
136#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
137#define BIO_FLAGS_SHOULD_RETRY 0x08
138
139/* Used in BIO_gethostbyname() */
140#define BIO_GHBN_CTRL_HITS 1
141#define BIO_GHBN_CTRL_MISSES 2
142#define BIO_GHBN_CTRL_CACHE_SIZE 3
143#define BIO_GHBN_CTRL_GET_ENTRY 4
144#define BIO_GHBN_CTRL_FLUSH 5
145
146/* Mostly used in the SSL BIO */
147/* Not used anymore
148 * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10
149 * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20
150 * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40
151 */
152
153#define BIO_FLAGS_BASE64_NO_NL 0x100
154
155/* This is used with memory BIOs: it means we shouldn't free up or change the
156 * data in any way.
157 */
158#define BIO_FLAGS_MEM_RDONLY 0x200
159
160#define BIO_set_flags(b,f) ((b)->flags|=(f))
161#define BIO_get_flags(b) ((b)->flags)
162#define BIO_set_retry_special(b) \
163 ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
164#define BIO_set_retry_read(b) \
165 ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
166#define BIO_set_retry_write(b) \
167 ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
168
169/* These are normally used internally in BIOs */
170#define BIO_clear_flags(b,f) ((b)->flags&= ~(f))
171#define BIO_clear_retry_flags(b) \
172 ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
173#define BIO_get_retry_flags(b) \
174 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
175
176/* These should be used by the application to tell why we should retry */
177#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
178#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
179#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
180#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
181#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
182
183/* The next three are used in conjunction with the
184 * BIO_should_io_special() condition. After this returns true,
185 * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO
186 * stack and return the 'reason' for the special and the offending BIO.
187 * Given a BIO, BIO_get_retry_reason(bio) will return the code. */
188/* Returned from the SSL bio when the certificate retrieval code had an error */
189#define BIO_RR_SSL_X509_LOOKUP 0x01
190/* Returned from the connect BIO when a connect would have blocked */
191#define BIO_RR_CONNECT 0x02
192/* Returned from the accept BIO when an accept would have blocked */
193#define BIO_RR_ACCEPT 0x03
194
195/* These are passed by the BIO callback */
196#define BIO_CB_FREE 0x01
197#define BIO_CB_READ 0x02
198#define BIO_CB_WRITE 0x03
199#define BIO_CB_PUTS 0x04
200#define BIO_CB_GETS 0x05
201#define BIO_CB_CTRL 0x06
202
203/* The callback is called before and after the underling operation,
204 * The BIO_CB_RETURN flag indicates if it is after the call */
205#define BIO_CB_RETURN 0x80
206#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
207#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
208#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
209
210#define BIO_set_callback(b,cb) ((b)->callback=(cb))
211#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg))
212#define BIO_get_callback_arg(b) ((b)->cb_arg)
213#define BIO_get_callback(b) ((b)->callback)
214#define BIO_method_name(b) ((b)->method->name)
215#define BIO_method_type(b) ((b)->method->type)
216
217typedef struct bio_st BIO;
218
219typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
220
221#ifndef OPENSSL_SYS_WIN16
222typedef struct bio_method_st
223 {
224 int type;
225 const char *name;
226 int (*bwrite)(BIO *, const char *, int);
227 int (*bread)(BIO *, char *, int);
228 int (*bputs)(BIO *, const char *);
229 int (*bgets)(BIO *, char *, int);
230 long (*ctrl)(BIO *, int, long, void *);
231 int (*create)(BIO *);
232 int (*destroy)(BIO *);
233 long (*callback_ctrl)(BIO *, int, bio_info_cb *);
234 } BIO_METHOD;
235#else
236typedef struct bio_method_st
237 {
238 int type;
239 const char *name;
240 int (_far *bwrite)();
241 int (_far *bread)();
242 int (_far *bputs)();
243 int (_far *bgets)();
244 long (_far *ctrl)();
245 int (_far *create)();
246 int (_far *destroy)();
247 long (_far *callback_ctrl)();
248 } BIO_METHOD;
249#endif
250
251struct bio_st
252 {
253 BIO_METHOD *method;
254 /* bio, mode, argp, argi, argl, ret */
255 long (*callback)(struct bio_st *,int,const char *,int, long,long);
256 char *cb_arg; /* first argument for the callback */
257
258 int init;
259 int shutdown;
260 int flags; /* extra storage */
261 int retry_reason;
262 int num;
263 void *ptr;
264 struct bio_st *next_bio; /* used by filter BIOs */
265 struct bio_st *prev_bio; /* used by filter BIOs */
266 int references;
267 unsigned long num_read;
268 unsigned long num_write;
269
270 CRYPTO_EX_DATA ex_data;
271 };
272
273DECLARE_STACK_OF(BIO)
274
275typedef struct bio_f_buffer_ctx_struct
276 {
277 /* BIO *bio; */ /* this is now in the BIO struct */
278 int ibuf_size; /* how big is the input buffer */
279 int obuf_size; /* how big is the output buffer */
280
281 char *ibuf; /* the char array */
282 int ibuf_len; /* how many bytes are in it */
283 int ibuf_off; /* write/read offset */
284
285 char *obuf; /* the char array */
286 int obuf_len; /* how many bytes are in it */
287 int obuf_off; /* write/read offset */
288 } BIO_F_BUFFER_CTX;
289
290/* connect BIO stuff */
291#define BIO_CONN_S_BEFORE 1
292#define BIO_CONN_S_GET_IP 2
293#define BIO_CONN_S_GET_PORT 3
294#define BIO_CONN_S_CREATE_SOCKET 4
295#define BIO_CONN_S_CONNECT 5
296#define BIO_CONN_S_OK 6
297#define BIO_CONN_S_BLOCKED_CONNECT 7
298#define BIO_CONN_S_NBIO 8
299/*#define BIO_CONN_get_param_hostname BIO_ctrl */
300
301#define BIO_C_SET_CONNECT 100
302#define BIO_C_DO_STATE_MACHINE 101
303#define BIO_C_SET_NBIO 102
304#define BIO_C_SET_PROXY_PARAM 103
305#define BIO_C_SET_FD 104
306#define BIO_C_GET_FD 105
307#define BIO_C_SET_FILE_PTR 106
308#define BIO_C_GET_FILE_PTR 107
309#define BIO_C_SET_FILENAME 108
310#define BIO_C_SET_SSL 109
311#define BIO_C_GET_SSL 110
312#define BIO_C_SET_MD 111
313#define BIO_C_GET_MD 112
314#define BIO_C_GET_CIPHER_STATUS 113
315#define BIO_C_SET_BUF_MEM 114
316#define BIO_C_GET_BUF_MEM_PTR 115
317#define BIO_C_GET_BUFF_NUM_LINES 116
318#define BIO_C_SET_BUFF_SIZE 117
319#define BIO_C_SET_ACCEPT 118
320#define BIO_C_SSL_MODE 119
321#define BIO_C_GET_MD_CTX 120
322#define BIO_C_GET_PROXY_PARAM 121
323#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */
324#define BIO_C_GET_CONNECT 123
325#define BIO_C_GET_ACCEPT 124
326#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125
327#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126
328#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127
329#define BIO_C_FILE_SEEK 128
330#define BIO_C_GET_CIPHER_CTX 129
331#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/
332#define BIO_C_SET_BIND_MODE 131
333#define BIO_C_GET_BIND_MODE 132
334#define BIO_C_FILE_TELL 133
335#define BIO_C_GET_SOCKS 134
336#define BIO_C_SET_SOCKS 135
337
338#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */
339#define BIO_C_GET_WRITE_BUF_SIZE 137
340#define BIO_C_MAKE_BIO_PAIR 138
341#define BIO_C_DESTROY_BIO_PAIR 139
342#define BIO_C_GET_WRITE_GUARANTEE 140
343#define BIO_C_GET_READ_REQUEST 141
344#define BIO_C_SHUTDOWN_WR 142
345#define BIO_C_NREAD0 143
346#define BIO_C_NREAD 144
347#define BIO_C_NWRITE0 145
348#define BIO_C_NWRITE 146
349#define BIO_C_RESET_READ_REQUEST 147
350#define BIO_C_SET_MD_CTX 148
351
352
353#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg)
354#define BIO_get_app_data(s) BIO_get_ex_data(s,0)
355
356/* BIO_s_connect() and BIO_s_socks4a_connect() */
357#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
358#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
359#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)
360#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)
361#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
362#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
363#define BIO_get_conn_ip(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2)
364#define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3)
365
366
367#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
368
369/* BIO_s_accept_socket() */
370#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
371#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)
372/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
373#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)
374#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
375
376#define BIO_BIND_NORMAL 0
377#define BIO_BIND_REUSEADDR_IF_UNUSED 1
378#define BIO_BIND_REUSEADDR 2
379#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
380#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
381
382#define BIO_do_connect(b) BIO_do_handshake(b)
383#define BIO_do_accept(b) BIO_do_handshake(b)
384#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
385
386/* BIO_s_proxy_client() */
387#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url))
388#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p))
389/* BIO_set_nbio(b,n) */
390#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))
391/* BIO *BIO_get_filter_bio(BIO *bio); */
392#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)()))
393#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)
394#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)
395
396#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp)
397#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p))
398#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url))
399#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL)
400
401#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
402#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
403
404#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
405#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
406
407#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
408#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
409
410/* name is cast to lose const, but might be better to route through a function
411 so we can do it safely */
412#ifdef CONST_STRICT
413/* If you are wondering why this isn't defined, its because CONST_STRICT is
414 * purely a compile-time kludge to allow const to be checked.
415 */
416int BIO_read_filename(BIO *b,const char *name);
417#else
418#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
419 BIO_CLOSE|BIO_FP_READ,(char *)name)
420#endif
421#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
422 BIO_CLOSE|BIO_FP_WRITE,name)
423#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
424 BIO_CLOSE|BIO_FP_APPEND,name)
425#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
426 BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
427
428/* WARNING WARNING, this ups the reference count on the read bio of the
429 * SSL structure. This is because the ssl read BIO is now pointed to by
430 * the next_bio field in the bio. So when you free the BIO, make sure
431 * you are doing a BIO_free_all() to catch the underlying BIO. */
432#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
433#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
434#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
435#define BIO_set_ssl_renegotiate_bytes(b,num) \
436 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);
437#define BIO_get_num_renegotiates(b) \
438 BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL);
439#define BIO_set_ssl_renegotiate_timeout(b,seconds) \
440 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);
441
442/* defined in evp.h */
443/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
444
445#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
446#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
447#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
448#define BIO_set_mem_eof_return(b,v) \
449 BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
450
451/* For the BIO_f_buffer() type */
452#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
453#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
454#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
455#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
456#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
457
458/* Don't use the next one unless you know what you are doing :-) */
459#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
460
461#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
462#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
463#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
464#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
465#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
466#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
467/* ...pending macros have inappropriate return type */
468size_t BIO_ctrl_pending(BIO *b);
469size_t BIO_ctrl_wpending(BIO *b);
470#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
471#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \
472 cbp)
473#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb)
474
475/* For the BIO_f_buffer() type */
476#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
477
478/* For BIO_s_bio() */
479#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
480#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
481#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
482#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
483#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
484/* macros with inappropriate type -- but ...pending macros use int too: */
485#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
486#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
487size_t BIO_ctrl_get_write_guarantee(BIO *b);
488size_t BIO_ctrl_get_read_request(BIO *b);
489int BIO_ctrl_reset_read_request(BIO *b);
490
491/* These two aren't currently implemented */
492/* int BIO_get_ex_num(BIO *bio); */
493/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
494int BIO_set_ex_data(BIO *bio,int idx,void *data);
495void *BIO_get_ex_data(BIO *bio,int idx);
496int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
497 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
498unsigned long BIO_number_read(BIO *bio);
499unsigned long BIO_number_written(BIO *bio);
500
501# ifndef OPENSSL_NO_FP_API
502# if defined(OPENSSL_SYS_WIN16) && defined(_WINDLL)
503BIO_METHOD *BIO_s_file_internal(void);
504BIO *BIO_new_file_internal(char *filename, char *mode);
505BIO *BIO_new_fp_internal(FILE *stream, int close_flag);
506# define BIO_s_file BIO_s_file_internal
507# define BIO_new_file BIO_new_file_internal
508# define BIO_new_fp BIO_new_fp_internal
509# else /* FP_API */
510BIO_METHOD *BIO_s_file(void );
511BIO *BIO_new_file(const char *filename, const char *mode);
512BIO *BIO_new_fp(FILE *stream, int close_flag);
513# define BIO_s_file_internal BIO_s_file
514# define BIO_new_file_internal BIO_new_file
515# define BIO_new_fp_internal BIO_s_file
516# endif /* FP_API */
517# endif
518BIO * BIO_new(BIO_METHOD *type);
519int BIO_set(BIO *a,BIO_METHOD *type);
520int BIO_free(BIO *a);
521void BIO_vfree(BIO *a);
522int BIO_read(BIO *b, void *data, int len);
523int BIO_gets(BIO *bp,char *buf, int size);
524int BIO_write(BIO *b, const void *data, int len);
525int BIO_puts(BIO *bp,const char *buf);
526int BIO_indent(BIO *b,int indent,int max);
527long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
528long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
529char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
530long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
531BIO * BIO_push(BIO *b,BIO *append);
532BIO * BIO_pop(BIO *b);
533void BIO_free_all(BIO *a);
534BIO * BIO_find_type(BIO *b,int bio_type);
535BIO * BIO_next(BIO *b);
536BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
537int BIO_get_retry_reason(BIO *bio);
538BIO * BIO_dup_chain(BIO *in);
539
540int BIO_nread0(BIO *bio, char **buf);
541int BIO_nread(BIO *bio, char **buf, int num);
542int BIO_nwrite0(BIO *bio, char **buf);
543int BIO_nwrite(BIO *bio, char **buf, int num);
544
545#ifndef OPENSSL_SYS_WIN16
546long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
547 long argl,long ret);
548#else
549long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
550 long argl,long ret);
551#endif
552
553BIO_METHOD *BIO_s_mem(void);
554BIO *BIO_new_mem_buf(void *buf, int len);
555BIO_METHOD *BIO_s_socket(void);
556BIO_METHOD *BIO_s_connect(void);
557BIO_METHOD *BIO_s_accept(void);
558BIO_METHOD *BIO_s_fd(void);
559#ifndef OPENSSL_SYS_OS2
560BIO_METHOD *BIO_s_log(void);
561#endif
562BIO_METHOD *BIO_s_bio(void);
563BIO_METHOD *BIO_s_null(void);
564BIO_METHOD *BIO_f_null(void);
565BIO_METHOD *BIO_f_buffer(void);
566#ifdef OPENSSL_SYS_VMS
567BIO_METHOD *BIO_f_linebuffer(void);
568#endif
569BIO_METHOD *BIO_f_nbio_test(void);
570/* BIO_METHOD *BIO_f_ber(void); */
571
572int BIO_sock_should_retry(int i);
573int BIO_sock_non_fatal_error(int error);
574int BIO_fd_should_retry(int i);
575int BIO_fd_non_fatal_error(int error);
576int BIO_dump(BIO *b,const char *bytes,int len);
577int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
578
579struct hostent *BIO_gethostbyname(const char *name);
580/* We might want a thread-safe interface too:
581 * struct hostent *BIO_gethostbyname_r(const char *name,
582 * struct hostent *result, void *buffer, size_t buflen);
583 * or something similar (caller allocates a struct hostent,
584 * pointed to by "result", and additional buffer space for the various
585 * substructures; if the buffer does not suffice, NULL is returned
586 * and an appropriate error code is set).
587 */
588int BIO_sock_error(int sock);
589int BIO_socket_ioctl(int fd, long type, void *arg);
590int BIO_socket_nbio(int fd,int mode);
591int BIO_get_port(const char *str, unsigned short *port_ptr);
592int BIO_get_host_ip(const char *str, unsigned char *ip);
593int BIO_get_accept_socket(char *host_port,int mode);
594int BIO_accept(int sock,char **ip_port);
595int BIO_sock_init(void );
596void BIO_sock_cleanup(void);
597int BIO_set_tcp_ndelay(int sock,int turn_on);
598
599BIO *BIO_new_socket(int sock, int close_flag);
600BIO *BIO_new_fd(int fd, int close_flag);
601BIO *BIO_new_connect(char *host_port);
602BIO *BIO_new_accept(char *host_port);
603
604int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
605 BIO **bio2, size_t writebuf2);
606/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
607 * Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
608 * Size 0 uses default value.
609 */
610
611void BIO_copy_next_retry(BIO *b);
612
613/*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/
614
615int BIO_printf(BIO *bio, const char *format, ...);
616int BIO_vprintf(BIO *bio, const char *format, va_list args);
617int BIO_snprintf(char *buf, size_t n, const char *format, ...);
618int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args);
619
620/* BEGIN ERROR CODES */
621/* The following lines are auto generated by the script mkerr.pl. Any changes
622 * made after this point may be overwritten when the script is next run.
623 */
624void ERR_load_BIO_strings(void);
625
626/* Error codes for the BIO functions. */
627
628/* Function codes. */
629#define BIO_F_ACPT_STATE 100
630#define BIO_F_BIO_ACCEPT 101
631#define BIO_F_BIO_BER_GET_HEADER 102
632#define BIO_F_BIO_CTRL 103
633#define BIO_F_BIO_GETHOSTBYNAME 120
634#define BIO_F_BIO_GETS 104
635#define BIO_F_BIO_GET_ACCEPT_SOCKET 105
636#define BIO_F_BIO_GET_HOST_IP 106
637#define BIO_F_BIO_GET_PORT 107
638#define BIO_F_BIO_MAKE_PAIR 121
639#define BIO_F_BIO_NEW 108
640#define BIO_F_BIO_NEW_FILE 109
641#define BIO_F_BIO_NEW_MEM_BUF 126
642#define BIO_F_BIO_NREAD 123
643#define BIO_F_BIO_NREAD0 124
644#define BIO_F_BIO_NWRITE 125
645#define BIO_F_BIO_NWRITE0 122
646#define BIO_F_BIO_PUTS 110
647#define BIO_F_BIO_READ 111
648#define BIO_F_BIO_SOCK_INIT 112
649#define BIO_F_BIO_WRITE 113
650#define BIO_F_BUFFER_CTRL 114
651#define BIO_F_CONN_CTRL 127
652#define BIO_F_CONN_STATE 115
653#define BIO_F_FILE_CTRL 116
654#define BIO_F_FILE_READ 130
655#define BIO_F_LINEBUFFER_CTRL 129
656#define BIO_F_MEM_READ 128
657#define BIO_F_MEM_WRITE 117
658#define BIO_F_SSL_NEW 118
659#define BIO_F_WSASTARTUP 119
660
661/* Reason codes. */
662#define BIO_R_ACCEPT_ERROR 100
663#define BIO_R_BAD_FOPEN_MODE 101
664#define BIO_R_BAD_HOSTNAME_LOOKUP 102
665#define BIO_R_BROKEN_PIPE 124
666#define BIO_R_CONNECT_ERROR 103
667#define BIO_R_EOF_ON_MEMORY_BIO 127
668#define BIO_R_ERROR_SETTING_NBIO 104
669#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
670#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
671#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
672#define BIO_R_INVALID_ARGUMENT 125
673#define BIO_R_INVALID_IP_ADDRESS 108
674#define BIO_R_IN_USE 123
675#define BIO_R_KEEPALIVE 109
676#define BIO_R_NBIO_CONNECT_ERROR 110
677#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
678#define BIO_R_NO_HOSTNAME_SPECIFIED 112
679#define BIO_R_NO_PORT_DEFINED 113
680#define BIO_R_NO_PORT_SPECIFIED 114
681#define BIO_R_NO_SUCH_FILE 128
682#define BIO_R_NULL_PARAMETER 115
683#define BIO_R_TAG_MISMATCH 116
684#define BIO_R_UNABLE_TO_BIND_SOCKET 117
685#define BIO_R_UNABLE_TO_CREATE_SOCKET 118
686#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119
687#define BIO_R_UNINITIALIZED 120
688#define BIO_R_UNSUPPORTED_METHOD 121
689#define BIO_R_WRITE_TO_READ_ONLY_BIO 126
690#define BIO_R_WSASTARTUP 122
691
692#ifdef __cplusplus
693}
694#endif
695#endif
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c
deleted file mode 100644
index 6f4254a114..0000000000
--- a/src/lib/libcrypto/bio/bio_cb.c
+++ /dev/null
@@ -1,139 +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 size_t p_maxlen;
74
75 if (BIO_CB_RETURN & cmd)
76 r=ret;
77
78 BIO_snprintf(buf,sizeof buf,"BIO[%08lX]:",(unsigned long)bio);
79 p= &(buf[14]);
80 p_maxlen = sizeof buf - 14;
81 switch (cmd)
82 {
83 case BIO_CB_FREE:
84 BIO_snprintf(p,p_maxlen,"Free - %s\n",bio->method->name);
85 break;
86 case BIO_CB_READ:
87 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
88 BIO_snprintf(p,p_maxlen,"read(%d,%d) - %s fd=%d\n",
89 bio->num,argi,bio->method->name,bio->num);
90 else
91 BIO_snprintf(p,p_maxlen,"read(%d,%d) - %s\n",
92 bio->num,argi,bio->method->name);
93 break;
94 case BIO_CB_WRITE:
95 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
96 BIO_snprintf(p,p_maxlen,"write(%d,%d) - %s fd=%d\n",
97 bio->num,argi,bio->method->name,bio->num);
98 else
99 BIO_snprintf(p,p_maxlen,"write(%d,%d) - %s\n",
100 bio->num,argi,bio->method->name);
101 break;
102 case BIO_CB_PUTS:
103 BIO_snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name);
104 break;
105 case BIO_CB_GETS:
106 BIO_snprintf(p,p_maxlen,"gets(%d) - %s\n",argi,bio->method->name);
107 break;
108 case BIO_CB_CTRL:
109 BIO_snprintf(p,p_maxlen,"ctrl(%d) - %s\n",argi,bio->method->name);
110 break;
111 case BIO_CB_RETURN|BIO_CB_READ:
112 BIO_snprintf(p,p_maxlen,"read return %ld\n",ret);
113 break;
114 case BIO_CB_RETURN|BIO_CB_WRITE:
115 BIO_snprintf(p,p_maxlen,"write return %ld\n",ret);
116 break;
117 case BIO_CB_RETURN|BIO_CB_GETS:
118 BIO_snprintf(p,p_maxlen,"gets return %ld\n",ret);
119 break;
120 case BIO_CB_RETURN|BIO_CB_PUTS:
121 BIO_snprintf(p,p_maxlen,"puts return %ld\n",ret);
122 break;
123 case BIO_CB_RETURN|BIO_CB_CTRL:
124 BIO_snprintf(p,p_maxlen,"ctrl return %ld\n",ret);
125 break;
126 default:
127 BIO_snprintf(p,p_maxlen,"bio callback - unknown type (%d)\n",cmd);
128 break;
129 }
130
131 b=(BIO *)bio->cb_arg;
132 if (b != NULL)
133 BIO_write(b,buf,strlen(buf));
134#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
135 else
136 fputs(buf,stderr);
137#endif
138 return(r);
139 }
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
deleted file mode 100644
index 8859a58ae4..0000000000
--- a/src/lib/libcrypto/bio/bio_err.c
+++ /dev/null
@@ -1,156 +0,0 @@
1/* crypto/bio/bio_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_BIO,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason)
70
71static ERR_STRING_DATA BIO_str_functs[]=
72 {
73{ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"},
74{ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
75{ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
76{ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"},
77{ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"},
78{ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"},
79{ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"},
80{ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"},
81{ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"},
82{ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"},
83{ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"},
84{ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"},
85{ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"},
86{ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"},
87{ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"},
88{ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"},
89{ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"},
90{ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
91{ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
92{ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
93{ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
94{ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"},
95{ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"},
96{ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"},
97{ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"},
98{ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"},
99{ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"},
100{ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"},
101{ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"},
102{ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"},
103{ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"},
104{0,NULL}
105 };
106
107static ERR_STRING_DATA BIO_str_reasons[]=
108 {
109{ERR_REASON(BIO_R_ACCEPT_ERROR) ,"accept error"},
110{ERR_REASON(BIO_R_BAD_FOPEN_MODE) ,"bad fopen mode"},
111{ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) ,"bad hostname lookup"},
112{ERR_REASON(BIO_R_BROKEN_PIPE) ,"broken pipe"},
113{ERR_REASON(BIO_R_CONNECT_ERROR) ,"connect error"},
114{ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) ,"EOF on memory BIO"},
115{ERR_REASON(BIO_R_ERROR_SETTING_NBIO) ,"error setting nbio"},
116{ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET),"error setting nbio on accepted socket"},
117{ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET),"error setting nbio on accept socket"},
118{ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET),"gethostbyname addr is not af inet"},
119{ERR_REASON(BIO_R_INVALID_ARGUMENT) ,"invalid argument"},
120{ERR_REASON(BIO_R_INVALID_IP_ADDRESS) ,"invalid ip address"},
121{ERR_REASON(BIO_R_IN_USE) ,"in use"},
122{ERR_REASON(BIO_R_KEEPALIVE) ,"keepalive"},
123{ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) ,"nbio connect error"},
124{ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED),"no accept port specified"},
125{ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) ,"no hostname specified"},
126{ERR_REASON(BIO_R_NO_PORT_DEFINED) ,"no port defined"},
127{ERR_REASON(BIO_R_NO_PORT_SPECIFIED) ,"no port specified"},
128{ERR_REASON(BIO_R_NO_SUCH_FILE) ,"no such file"},
129{ERR_REASON(BIO_R_NULL_PARAMETER) ,"null parameter"},
130{ERR_REASON(BIO_R_TAG_MISMATCH) ,"tag mismatch"},
131{ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) ,"unable to bind socket"},
132{ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET),"unable to create socket"},
133{ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET),"unable to listen socket"},
134{ERR_REASON(BIO_R_UNINITIALIZED) ,"uninitialized"},
135{ERR_REASON(BIO_R_UNSUPPORTED_METHOD) ,"unsupported method"},
136{ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO),"write to read only BIO"},
137{ERR_REASON(BIO_R_WSASTARTUP) ,"WSAStartup"},
138{0,NULL}
139 };
140
141#endif
142
143void ERR_load_BIO_strings(void)
144 {
145 static int init=1;
146
147 if (init)
148 {
149 init=0;
150#ifndef OPENSSL_NO_ERR
151 ERR_load_strings(0,BIO_str_functs);
152 ERR_load_strings(0,BIO_str_reasons);
153#endif
154
155 }
156 }
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
deleted file mode 100644
index 692c8fb5c6..0000000000
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ /dev/null
@@ -1,556 +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
66BIO *BIO_new(BIO_METHOD *method)
67 {
68 BIO *ret=NULL;
69
70 ret=(BIO *)OPENSSL_malloc(sizeof(BIO));
71 if (ret == NULL)
72 {
73 BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
74 return(NULL);
75 }
76 if (!BIO_set(ret,method))
77 {
78 OPENSSL_free(ret);
79 ret=NULL;
80 }
81 return(ret);
82 }
83
84int BIO_set(BIO *bio, BIO_METHOD *method)
85 {
86 bio->method=method;
87 bio->callback=NULL;
88 bio->cb_arg=NULL;
89 bio->init=0;
90 bio->shutdown=1;
91 bio->flags=0;
92 bio->retry_reason=0;
93 bio->num=0;
94 bio->ptr=NULL;
95 bio->prev_bio=NULL;
96 bio->next_bio=NULL;
97 bio->references=1;
98 bio->num_read=0L;
99 bio->num_write=0L;
100 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
101 if (method->create != NULL)
102 if (!method->create(bio))
103 {
104 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio,
105 &bio->ex_data);
106 return(0);
107 }
108 return(1);
109 }
110
111int BIO_free(BIO *a)
112 {
113 int ret=0,i;
114
115 if (a == NULL) return(0);
116
117 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO);
118#ifdef REF_PRINT
119 REF_PRINT("BIO",a);
120#endif
121 if (i > 0) return(1);
122#ifdef REF_CHECK
123 if (i < 0)
124 {
125 fprintf(stderr,"BIO_free, bad reference count\n");
126 abort();
127 }
128#endif
129 if ((a->callback != NULL) &&
130 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
131 return(i);
132
133 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
134
135 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
136 ret=a->method->destroy(a);
137 OPENSSL_free(a);
138 return(1);
139 }
140
141void BIO_vfree(BIO *a)
142 { BIO_free(a); }
143
144int BIO_read(BIO *b, void *out, int outl)
145 {
146 int i;
147 long (*cb)();
148
149 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
150 {
151 BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD);
152 return(-2);
153 }
154
155 cb=b->callback;
156 if ((cb != NULL) &&
157 ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0))
158 return(i);
159
160 if (!b->init)
161 {
162 BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED);
163 return(-2);
164 }
165
166 i=b->method->bread(b,out,outl);
167
168 if (i > 0) b->num_read+=(unsigned long)i;
169
170 if (cb != NULL)
171 i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl,
172 0L,(long)i);
173 return(i);
174 }
175
176int BIO_write(BIO *b, const void *in, int inl)
177 {
178 int i;
179 long (*cb)();
180
181 if (b == NULL)
182 return(0);
183
184 cb=b->callback;
185 if ((b->method == NULL) || (b->method->bwrite == NULL))
186 {
187 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);
188 return(-2);
189 }
190
191 if ((cb != NULL) &&
192 ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))
193 return(i);
194
195 if (!b->init)
196 {
197 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED);
198 return(-2);
199 }
200
201 i=b->method->bwrite(b,in,inl);
202
203 if (i > 0) b->num_write+=(unsigned long)i;
204
205 if (cb != NULL)
206 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
207 0L,(long)i);
208 return(i);
209 }
210
211int BIO_puts(BIO *b, const char *in)
212 {
213 int i;
214 long (*cb)();
215
216 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
217 {
218 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);
219 return(-2);
220 }
221
222 cb=b->callback;
223
224 if ((cb != NULL) &&
225 ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))
226 return(i);
227
228 if (!b->init)
229 {
230 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED);
231 return(-2);
232 }
233
234 i=b->method->bputs(b,in);
235
236 if (i > 0) b->num_write+=(unsigned long)i;
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
275int BIO_indent(BIO *b,int indent,int max)
276 {
277 if(indent < 0)
278 indent=0;
279 if(indent > max)
280 indent=max;
281 while(indent--)
282 if(BIO_puts(b," ") != 1)
283 return 0;
284 return 1;
285 }
286
287long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
288 {
289 int i;
290
291 i=iarg;
292 return(BIO_ctrl(b,cmd,larg,(char *)&i));
293 }
294
295char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
296 {
297 char *p=NULL;
298
299 if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0)
300 return(NULL);
301 else
302 return(p);
303 }
304
305long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
306 {
307 long ret;
308 long (*cb)();
309
310 if (b == NULL) return(0);
311
312 if ((b->method == NULL) || (b->method->ctrl == NULL))
313 {
314 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
315 return(-2);
316 }
317
318 cb=b->callback;
319
320 if ((cb != NULL) &&
321 ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0))
322 return(ret);
323
324 ret=b->method->ctrl(b,cmd,larg,parg);
325
326 if (cb != NULL)
327 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,
328 larg,ret);
329 return(ret);
330 }
331
332long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long))
333 {
334 long ret;
335 long (*cb)();
336
337 if (b == NULL) return(0);
338
339 if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
340 {
341 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
342 return(-2);
343 }
344
345 cb=b->callback;
346
347 if ((cb != NULL) &&
348 ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0))
349 return(ret);
350
351 ret=b->method->callback_ctrl(b,cmd,fp);
352
353 if (cb != NULL)
354 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd,
355 0,ret);
356 return(ret);
357 }
358
359/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
360 * do; but those macros have inappropriate return type, and for interfacing
361 * from other programming languages, C macros aren't much of a help anyway. */
362size_t BIO_ctrl_pending(BIO *bio)
363 {
364 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
365 }
366
367size_t BIO_ctrl_wpending(BIO *bio)
368 {
369 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
370 }
371
372
373/* put the 'bio' on the end of b's list of operators */
374BIO *BIO_push(BIO *b, BIO *bio)
375 {
376 BIO *lb;
377
378 if (b == NULL) return(bio);
379 lb=b;
380 while (lb->next_bio != NULL)
381 lb=lb->next_bio;
382 lb->next_bio=bio;
383 if (bio != NULL)
384 bio->prev_bio=lb;
385 /* called to do internal processing */
386 BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL);
387 return(b);
388 }
389
390/* Remove the first and return the rest */
391BIO *BIO_pop(BIO *b)
392 {
393 BIO *ret;
394
395 if (b == NULL) return(NULL);
396 ret=b->next_bio;
397
398 BIO_ctrl(b,BIO_CTRL_POP,0,NULL);
399
400 if (b->prev_bio != NULL)
401 b->prev_bio->next_bio=b->next_bio;
402 if (b->next_bio != NULL)
403 b->next_bio->prev_bio=b->prev_bio;
404
405 b->next_bio=NULL;
406 b->prev_bio=NULL;
407 return(ret);
408 }
409
410BIO *BIO_get_retry_BIO(BIO *bio, int *reason)
411 {
412 BIO *b,*last;
413
414 b=last=bio;
415 for (;;)
416 {
417 if (!BIO_should_retry(b)) break;
418 last=b;
419 b=b->next_bio;
420 if (b == NULL) break;
421 }
422 if (reason != NULL) *reason=last->retry_reason;
423 return(last);
424 }
425
426int BIO_get_retry_reason(BIO *bio)
427 {
428 return(bio->retry_reason);
429 }
430
431BIO *BIO_find_type(BIO *bio, int type)
432 {
433 int mt,mask;
434
435 if(!bio) return NULL;
436 mask=type&0xff;
437 do {
438 if (bio->method != NULL)
439 {
440 mt=bio->method->type;
441
442 if (!mask)
443 {
444 if (mt & type) return(bio);
445 }
446 else if (mt == type)
447 return(bio);
448 }
449 bio=bio->next_bio;
450 } while (bio != NULL);
451 return(NULL);
452 }
453
454BIO *BIO_next(BIO *b)
455 {
456 if(!b) return NULL;
457 return b->next_bio;
458 }
459
460void BIO_free_all(BIO *bio)
461 {
462 BIO *b;
463 int ref;
464
465 while (bio != NULL)
466 {
467 b=bio;
468 ref=b->references;
469 bio=bio->next_bio;
470 BIO_free(b);
471 /* Since ref count > 1, don't free anyone else. */
472 if (ref > 1) break;
473 }
474 }
475
476BIO *BIO_dup_chain(BIO *in)
477 {
478 BIO *ret=NULL,*eoc=NULL,*bio,*new;
479
480 for (bio=in; bio != NULL; bio=bio->next_bio)
481 {
482 if ((new=BIO_new(bio->method)) == NULL) goto err;
483 new->callback=bio->callback;
484 new->cb_arg=bio->cb_arg;
485 new->init=bio->init;
486 new->shutdown=bio->shutdown;
487 new->flags=bio->flags;
488
489 /* This will let SSL_s_sock() work with stdin/stdout */
490 new->num=bio->num;
491
492 if (!BIO_dup_state(bio,(char *)new))
493 {
494 BIO_free(new);
495 goto err;
496 }
497
498 /* copy app data */
499 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new->ex_data,
500 &bio->ex_data))
501 goto err;
502
503 if (ret == NULL)
504 {
505 eoc=new;
506 ret=eoc;
507 }
508 else
509 {
510 BIO_push(eoc,new);
511 eoc=new;
512 }
513 }
514 return(ret);
515err:
516 if (ret != NULL)
517 BIO_free(ret);
518 return(NULL);
519 }
520
521void BIO_copy_next_retry(BIO *b)
522 {
523 BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
524 b->retry_reason=b->next_bio->retry_reason;
525 }
526
527int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
528 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
529 {
530 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp,
531 new_func, dup_func, free_func);
532 }
533
534int BIO_set_ex_data(BIO *bio, int idx, void *data)
535 {
536 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
537 }
538
539void *BIO_get_ex_data(BIO *bio, int idx)
540 {
541 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
542 }
543
544unsigned long BIO_number_read(BIO *bio)
545{
546 if(bio) return bio->num_read;
547 return 0;
548}
549
550unsigned long BIO_number_written(BIO *bio)
551{
552 if(bio) return bio->num_write;
553 return 0;
554}
555
556IMPLEMENT_STACK_OF(BIO)
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
deleted file mode 100644
index 8ea1db158b..0000000000
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ /dev/null
@@ -1,479 +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 OPENSSL_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 OPENSSL_SYS_WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else
70#define SOCKET_PROTOCOL IPPROTO_TCP
71#endif
72
73#if (defined(OPENSSL_SYS_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, const char *buf, int num);
96static int acpt_read(BIO *h, char *buf, int size);
97static int acpt_puts(BIO *h, const char *str);
98static long acpt_ctrl(BIO *h, int cmd, long arg1, void *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 *)OPENSSL_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) OPENSSL_free(a->param_addr);
163 if (a->addr != NULL) OPENSSL_free(a->addr);
164 if (a->bio_chain != NULL) BIO_free(a->bio_chain);
165 OPENSSL_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 BIO_clear_retry_flags(b);
240 b->retry_reason=0;
241 i=BIO_accept(c->accept_sock,&(c->addr));
242
243 /* -2 return means we should retry */
244 if(i == -2)
245 {
246 BIO_set_retry_special(b);
247 b->retry_reason=BIO_RR_ACCEPT;
248 return -1;
249 }
250
251 if (i < 0) return(i);
252
253 bio=BIO_new_socket(i,BIO_CLOSE);
254 if (bio == NULL) goto err;
255
256 BIO_set_callback(bio,BIO_get_callback(b));
257 BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
258
259 if (c->nbio)
260 {
261 if (!BIO_socket_nbio(i,1))
262 {
263 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
264 goto err;
265 }
266 }
267
268 /* If the accept BIO has an bio_chain, we dup it and
269 * put the new socket at the end. */
270 if (c->bio_chain != NULL)
271 {
272 if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
273 goto err;
274 if (!BIO_push(dbio,bio)) goto err;
275 bio=dbio;
276 }
277 if (BIO_push(b,bio) == NULL) goto err;
278
279 c->state=ACPT_S_OK;
280 return(1);
281err:
282 if (bio != NULL)
283 BIO_free(bio);
284 else if (s >= 0)
285 closesocket(s);
286 return(0);
287 /* break; */
288 case ACPT_S_OK:
289 if (b->next_bio == NULL)
290 {
291 c->state=ACPT_S_GET_ACCEPT_SOCKET;
292 goto again;
293 }
294 return(1);
295 /* break; */
296 default:
297 return(0);
298 /* break; */
299 }
300
301 }
302
303static int acpt_read(BIO *b, char *out, int outl)
304 {
305 int ret=0;
306 BIO_ACCEPT *data;
307
308 BIO_clear_retry_flags(b);
309 data=(BIO_ACCEPT *)b->ptr;
310
311 while (b->next_bio == NULL)
312 {
313 ret=acpt_state(b,data);
314 if (ret <= 0) return(ret);
315 }
316
317 ret=BIO_read(b->next_bio,out,outl);
318 BIO_copy_next_retry(b);
319 return(ret);
320 }
321
322static int acpt_write(BIO *b, const char *in, int inl)
323 {
324 int ret;
325 BIO_ACCEPT *data;
326
327 BIO_clear_retry_flags(b);
328 data=(BIO_ACCEPT *)b->ptr;
329
330 while (b->next_bio == NULL)
331 {
332 ret=acpt_state(b,data);
333 if (ret <= 0) return(ret);
334 }
335
336 ret=BIO_write(b->next_bio,in,inl);
337 BIO_copy_next_retry(b);
338 return(ret);
339 }
340
341static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
342 {
343 BIO *dbio;
344 int *ip;
345 long ret=1;
346 BIO_ACCEPT *data;
347 char **pp;
348
349 data=(BIO_ACCEPT *)b->ptr;
350
351 switch (cmd)
352 {
353 case BIO_CTRL_RESET:
354 ret=0;
355 data->state=ACPT_S_BEFORE;
356 acpt_close_socket(b);
357 b->flags=0;
358 break;
359 case BIO_C_DO_STATE_MACHINE:
360 /* use this one to start the connection */
361 ret=(long)acpt_state(b,data);
362 break;
363 case BIO_C_SET_ACCEPT:
364 if (ptr != NULL)
365 {
366 if (num == 0)
367 {
368 b->init=1;
369 if (data->param_addr != NULL)
370 OPENSSL_free(data->param_addr);
371 data->param_addr=BUF_strdup(ptr);
372 }
373 else if (num == 1)
374 {
375 data->accept_nbio=(ptr != NULL);
376 }
377 else if (num == 2)
378 {
379 if (data->bio_chain != NULL)
380 BIO_free(data->bio_chain);
381 data->bio_chain=(BIO *)ptr;
382 }
383 }
384 break;
385 case BIO_C_SET_NBIO:
386 data->nbio=(int)num;
387 break;
388 case BIO_C_SET_FD:
389 b->init=1;
390 b->num= *((int *)ptr);
391 data->accept_sock=b->num;
392 data->state=ACPT_S_GET_ACCEPT_SOCKET;
393 b->shutdown=(int)num;
394 b->init=1;
395 break;
396 case BIO_C_GET_FD:
397 if (b->init)
398 {
399 ip=(int *)ptr;
400 if (ip != NULL)
401 *ip=data->accept_sock;
402 ret=data->accept_sock;
403 }
404 else
405 ret= -1;
406 break;
407 case BIO_C_GET_ACCEPT:
408 if (b->init)
409 {
410 if (ptr != NULL)
411 {
412 pp=(char **)ptr;
413 *pp=data->param_addr;
414 }
415 else
416 ret= -1;
417 }
418 else
419 ret= -1;
420 break;
421 case BIO_CTRL_GET_CLOSE:
422 ret=b->shutdown;
423 break;
424 case BIO_CTRL_SET_CLOSE:
425 b->shutdown=(int)num;
426 break;
427 case BIO_CTRL_PENDING:
428 case BIO_CTRL_WPENDING:
429 ret=0;
430 break;
431 case BIO_CTRL_FLUSH:
432 break;
433 case BIO_C_SET_BIND_MODE:
434 data->bind_mode=(int)num;
435 break;
436 case BIO_C_GET_BIND_MODE:
437 ret=(long)data->bind_mode;
438 break;
439 case BIO_CTRL_DUP:
440 dbio=(BIO *)ptr;
441/* if (data->param_port) EAY EAY
442 BIO_set_port(dbio,data->param_port);
443 if (data->param_hostname)
444 BIO_set_hostname(dbio,data->param_hostname);
445 BIO_set_nbio(dbio,data->nbio); */
446 break;
447
448 default:
449 ret=0;
450 break;
451 }
452 return(ret);
453 }
454
455static int acpt_puts(BIO *bp, const char *str)
456 {
457 int n,ret;
458
459 n=strlen(str);
460 ret=acpt_write(bp,str,n);
461 return(ret);
462 }
463
464BIO *BIO_new_accept(char *str)
465 {
466 BIO *ret;
467
468 ret=BIO_new(BIO_s_accept());
469 if (ret == NULL) return(NULL);
470 if (BIO_set_accept_port(ret,str))
471 return(ret);
472 else
473 {
474 BIO_free(ret);
475 return(NULL);
476 }
477 }
478
479#endif
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
deleted file mode 100644
index 0f9f0955b4..0000000000
--- a/src/lib/libcrypto/bio/bss_bio.c
+++ /dev/null
@@ -1,924 +0,0 @@
1/* crypto/bio/bss_bio.c -*- Mode: C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2003 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/* Special method for a BIO where the other endpoint is also a BIO
57 * of this kind, handled by the same thread (i.e. the "peer" is actually
58 * ourselves, wearing a different hat).
59 * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces
60 * for which no specific BIO method is available.
61 * See ssl/ssltest.c for some hints on how this can be used. */
62
63/* BIO_DEBUG implies BIO_PAIR_DEBUG */
64#ifdef BIO_DEBUG
65# ifndef BIO_PAIR_DEBUG
66# define BIO_PAIR_DEBUG
67# endif
68#endif
69
70/* disable assert() unless BIO_PAIR_DEBUG has been defined */
71#ifndef BIO_PAIR_DEBUG
72# ifndef NDEBUG
73# define NDEBUG
74# endif
75#endif
76
77#include <assert.h>
78#include <limits.h>
79#include <stdlib.h>
80#include <string.h>
81
82#include <openssl/bio.h>
83#include <openssl/err.h>
84#include <openssl/crypto.h>
85
86#include "e_os.h"
87
88/* VxWorks defines SSIZE_MAX with an empty value causing compile errors */
89#if defined(OPENSSL_SYS_VXWORKS)
90# undef SSIZE_MAX
91#endif
92#ifndef SSIZE_MAX
93# define SSIZE_MAX INT_MAX
94#endif
95
96static int bio_new(BIO *bio);
97static int bio_free(BIO *bio);
98static int bio_read(BIO *bio, char *buf, int size);
99static int bio_write(BIO *bio, const char *buf, int num);
100static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
101static int bio_puts(BIO *bio, const char *str);
102
103static int bio_make_pair(BIO *bio1, BIO *bio2);
104static void bio_destroy_pair(BIO *bio);
105
106static BIO_METHOD methods_biop =
107{
108 BIO_TYPE_BIO,
109 "BIO pair",
110 bio_write,
111 bio_read,
112 bio_puts,
113 NULL /* no bio_gets */,
114 bio_ctrl,
115 bio_new,
116 bio_free,
117 NULL /* no bio_callback_ctrl */
118};
119
120BIO_METHOD *BIO_s_bio(void)
121 {
122 return &methods_biop;
123 }
124
125struct bio_bio_st
126{
127 BIO *peer; /* NULL if buf == NULL.
128 * If peer != NULL, then peer->ptr is also a bio_bio_st,
129 * and its "peer" member points back to us.
130 * peer != NULL iff init != 0 in the BIO. */
131
132 /* This is for what we write (i.e. reading uses peer's struct): */
133 int closed; /* valid iff peer != NULL */
134 size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
135 size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
136 size_t size;
137 char *buf; /* "size" elements (if != NULL) */
138
139 size_t request; /* valid iff peer != NULL; 0 if len != 0,
140 * otherwise set by peer to number of bytes
141 * it (unsuccessfully) tried to read,
142 * never more than buffer space (size-len) warrants. */
143};
144
145static int bio_new(BIO *bio)
146 {
147 struct bio_bio_st *b;
148
149 b = OPENSSL_malloc(sizeof *b);
150 if (b == NULL)
151 return 0;
152
153 b->peer = NULL;
154 b->size = 17*1024; /* enough for one TLS record (just a default) */
155 b->buf = NULL;
156
157 bio->ptr = b;
158 return 1;
159 }
160
161
162static int bio_free(BIO *bio)
163 {
164 struct bio_bio_st *b;
165
166 if (bio == NULL)
167 return 0;
168 b = bio->ptr;
169
170 assert(b != NULL);
171
172 if (b->peer)
173 bio_destroy_pair(bio);
174
175 if (b->buf != NULL)
176 {
177 OPENSSL_free(b->buf);
178 }
179
180 OPENSSL_free(b);
181
182 return 1;
183 }
184
185
186
187static int bio_read(BIO *bio, char *buf, int size_)
188 {
189 size_t size = size_;
190 size_t rest;
191 struct bio_bio_st *b, *peer_b;
192
193 BIO_clear_retry_flags(bio);
194
195 if (!bio->init)
196 return 0;
197
198 b = bio->ptr;
199 assert(b != NULL);
200 assert(b->peer != NULL);
201 peer_b = b->peer->ptr;
202 assert(peer_b != NULL);
203 assert(peer_b->buf != NULL);
204
205 peer_b->request = 0; /* will be set in "retry_read" situation */
206
207 if (buf == NULL || size == 0)
208 return 0;
209
210 if (peer_b->len == 0)
211 {
212 if (peer_b->closed)
213 return 0; /* writer has closed, and no data is left */
214 else
215 {
216 BIO_set_retry_read(bio); /* buffer is empty */
217 if (size <= peer_b->size)
218 peer_b->request = size;
219 else
220 /* don't ask for more than the peer can
221 * deliver in one write */
222 peer_b->request = peer_b->size;
223 return -1;
224 }
225 }
226
227 /* we can read */
228 if (peer_b->len < size)
229 size = peer_b->len;
230
231 /* now read "size" bytes */
232
233 rest = size;
234
235 assert(rest > 0);
236 do /* one or two iterations */
237 {
238 size_t chunk;
239
240 assert(rest <= peer_b->len);
241 if (peer_b->offset + rest <= peer_b->size)
242 chunk = rest;
243 else
244 /* wrap around ring buffer */
245 chunk = peer_b->size - peer_b->offset;
246 assert(peer_b->offset + chunk <= peer_b->size);
247
248 memcpy(buf, peer_b->buf + peer_b->offset, chunk);
249
250 peer_b->len -= chunk;
251 if (peer_b->len)
252 {
253 peer_b->offset += chunk;
254 assert(peer_b->offset <= peer_b->size);
255 if (peer_b->offset == peer_b->size)
256 peer_b->offset = 0;
257 buf += chunk;
258 }
259 else
260 {
261 /* buffer now empty, no need to advance "buf" */
262 assert(chunk == rest);
263 peer_b->offset = 0;
264 }
265 rest -= chunk;
266 }
267 while (rest);
268
269 return size;
270 }
271
272/* non-copying interface: provide pointer to available data in buffer
273 * bio_nread0: return number of available bytes
274 * bio_nread: also advance index
275 * (example usage: bio_nread0(), read from buffer, bio_nread()
276 * or just bio_nread(), read from buffer)
277 */
278/* WARNING: The non-copying interface is largely untested as of yet
279 * and may contain bugs. */
280static ssize_t bio_nread0(BIO *bio, char **buf)
281 {
282 struct bio_bio_st *b, *peer_b;
283 ssize_t num;
284
285 BIO_clear_retry_flags(bio);
286
287 if (!bio->init)
288 return 0;
289
290 b = bio->ptr;
291 assert(b != NULL);
292 assert(b->peer != NULL);
293 peer_b = b->peer->ptr;
294 assert(peer_b != NULL);
295 assert(peer_b->buf != NULL);
296
297 peer_b->request = 0;
298
299 if (peer_b->len == 0)
300 {
301 char dummy;
302
303 /* avoid code duplication -- nothing available for reading */
304 return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
305 }
306
307 num = peer_b->len;
308 if (peer_b->size < peer_b->offset + num)
309 /* no ring buffer wrap-around for non-copying interface */
310 num = peer_b->size - peer_b->offset;
311 assert(num > 0);
312
313 if (buf != NULL)
314 *buf = peer_b->buf + peer_b->offset;
315 return num;
316 }
317
318static ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
319 {
320 struct bio_bio_st *b, *peer_b;
321 ssize_t num, available;
322
323 if (num_ > SSIZE_MAX)
324 num = SSIZE_MAX;
325 else
326 num = (ssize_t)num_;
327
328 available = bio_nread0(bio, buf);
329 if (num > available)
330 num = available;
331 if (num <= 0)
332 return num;
333
334 b = bio->ptr;
335 peer_b = b->peer->ptr;
336
337 peer_b->len -= num;
338 if (peer_b->len)
339 {
340 peer_b->offset += num;
341 assert(peer_b->offset <= peer_b->size);
342 if (peer_b->offset == peer_b->size)
343 peer_b->offset = 0;
344 }
345 else
346 peer_b->offset = 0;
347
348 return num;
349 }
350
351
352static int bio_write(BIO *bio, const char *buf, int num_)
353 {
354 size_t num = num_;
355 size_t rest;
356 struct bio_bio_st *b;
357
358 BIO_clear_retry_flags(bio);
359
360 if (!bio->init || buf == NULL || num == 0)
361 return 0;
362
363 b = bio->ptr;
364 assert(b != NULL);
365 assert(b->peer != NULL);
366 assert(b->buf != NULL);
367
368 b->request = 0;
369 if (b->closed)
370 {
371 /* we already closed */
372 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
373 return -1;
374 }
375
376 assert(b->len <= b->size);
377
378 if (b->len == b->size)
379 {
380 BIO_set_retry_write(bio); /* buffer is full */
381 return -1;
382 }
383
384 /* we can write */
385 if (num > b->size - b->len)
386 num = b->size - b->len;
387
388 /* now write "num" bytes */
389
390 rest = num;
391
392 assert(rest > 0);
393 do /* one or two iterations */
394 {
395 size_t write_offset;
396 size_t chunk;
397
398 assert(b->len + rest <= b->size);
399
400 write_offset = b->offset + b->len;
401 if (write_offset >= b->size)
402 write_offset -= b->size;
403 /* b->buf[write_offset] is the first byte we can write to. */
404
405 if (write_offset + rest <= b->size)
406 chunk = rest;
407 else
408 /* wrap around ring buffer */
409 chunk = b->size - write_offset;
410
411 memcpy(b->buf + write_offset, buf, chunk);
412
413 b->len += chunk;
414
415 assert(b->len <= b->size);
416
417 rest -= chunk;
418 buf += chunk;
419 }
420 while (rest);
421
422 return num;
423 }
424
425/* non-copying interface: provide pointer to region to write to
426 * bio_nwrite0: check how much space is available
427 * bio_nwrite: also increase length
428 * (example usage: bio_nwrite0(), write to buffer, bio_nwrite()
429 * or just bio_nwrite(), write to buffer)
430 */
431static ssize_t bio_nwrite0(BIO *bio, char **buf)
432 {
433 struct bio_bio_st *b;
434 size_t num;
435 size_t write_offset;
436
437 BIO_clear_retry_flags(bio);
438
439 if (!bio->init)
440 return 0;
441
442 b = bio->ptr;
443 assert(b != NULL);
444 assert(b->peer != NULL);
445 assert(b->buf != NULL);
446
447 b->request = 0;
448 if (b->closed)
449 {
450 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE);
451 return -1;
452 }
453
454 assert(b->len <= b->size);
455
456 if (b->len == b->size)
457 {
458 BIO_set_retry_write(bio);
459 return -1;
460 }
461
462 num = b->size - b->len;
463 write_offset = b->offset + b->len;
464 if (write_offset >= b->size)
465 write_offset -= b->size;
466 if (write_offset + num > b->size)
467 /* no ring buffer wrap-around for non-copying interface
468 * (to fulfil the promise by BIO_ctrl_get_write_guarantee,
469 * BIO_nwrite may have to be called twice) */
470 num = b->size - write_offset;
471
472 if (buf != NULL)
473 *buf = b->buf + write_offset;
474 assert(write_offset + num <= b->size);
475
476 return num;
477 }
478
479static ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_)
480 {
481 struct bio_bio_st *b;
482 ssize_t num, space;
483
484 if (num_ > SSIZE_MAX)
485 num = SSIZE_MAX;
486 else
487 num = (ssize_t)num_;
488
489 space = bio_nwrite0(bio, buf);
490 if (num > space)
491 num = space;
492 if (num <= 0)
493 return num;
494 b = bio->ptr;
495 assert(b != NULL);
496 b->len += num;
497 assert(b->len <= b->size);
498
499 return num;
500 }
501
502
503static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
504 {
505 long ret;
506 struct bio_bio_st *b = bio->ptr;
507
508 assert(b != NULL);
509
510 switch (cmd)
511 {
512 /* specific CTRL codes */
513
514 case BIO_C_SET_WRITE_BUF_SIZE:
515 if (b->peer)
516 {
517 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
518 ret = 0;
519 }
520 else if (num == 0)
521 {
522 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
523 ret = 0;
524 }
525 else
526 {
527 size_t new_size = num;
528
529 if (b->size != new_size)
530 {
531 if (b->buf)
532 {
533 OPENSSL_free(b->buf);
534 b->buf = NULL;
535 }
536 b->size = new_size;
537 }
538 ret = 1;
539 }
540 break;
541
542 case BIO_C_GET_WRITE_BUF_SIZE:
543 ret = (long) b->size;
544 break;
545
546 case BIO_C_MAKE_BIO_PAIR:
547 {
548 BIO *other_bio = ptr;
549
550 if (bio_make_pair(bio, other_bio))
551 ret = 1;
552 else
553 ret = 0;
554 }
555 break;
556
557 case BIO_C_DESTROY_BIO_PAIR:
558 /* Affects both BIOs in the pair -- call just once!
559 * Or let BIO_free(bio1); BIO_free(bio2); do the job. */
560 bio_destroy_pair(bio);
561 ret = 1;
562 break;
563
564 case BIO_C_GET_WRITE_GUARANTEE:
565 /* How many bytes can the caller feed to the next write
566 * without having to keep any? */
567 if (b->peer == NULL || b->closed)
568 ret = 0;
569 else
570 ret = (long) b->size - b->len;
571 break;
572
573 case BIO_C_GET_READ_REQUEST:
574 /* If the peer unsuccessfully tried to read, how many bytes
575 * were requested? (As with BIO_CTRL_PENDING, that number
576 * can usually be treated as boolean.) */
577 ret = (long) b->request;
578 break;
579
580 case BIO_C_RESET_READ_REQUEST:
581 /* Reset request. (Can be useful after read attempts
582 * at the other side that are meant to be non-blocking,
583 * e.g. when probing SSL_read to see if any data is
584 * available.) */
585 b->request = 0;
586 ret = 1;
587 break;
588
589 case BIO_C_SHUTDOWN_WR:
590 /* similar to shutdown(..., SHUT_WR) */
591 b->closed = 1;
592 ret = 1;
593 break;
594
595 case BIO_C_NREAD0:
596 /* prepare for non-copying read */
597 ret = (long) bio_nread0(bio, ptr);
598 break;
599
600 case BIO_C_NREAD:
601 /* non-copying read */
602 ret = (long) bio_nread(bio, ptr, (size_t) num);
603 break;
604
605 case BIO_C_NWRITE0:
606 /* prepare for non-copying write */
607 ret = (long) bio_nwrite0(bio, ptr);
608 break;
609
610 case BIO_C_NWRITE:
611 /* non-copying write */
612 ret = (long) bio_nwrite(bio, ptr, (size_t) num);
613 break;
614
615
616 /* standard CTRL codes follow */
617
618 case BIO_CTRL_RESET:
619 if (b->buf != NULL)
620 {
621 b->len = 0;
622 b->offset = 0;
623 }
624 ret = 0;
625 break;
626
627 case BIO_CTRL_GET_CLOSE:
628 ret = bio->shutdown;
629 break;
630
631 case BIO_CTRL_SET_CLOSE:
632 bio->shutdown = (int) num;
633 ret = 1;
634 break;
635
636 case BIO_CTRL_PENDING:
637 if (b->peer != NULL)
638 {
639 struct bio_bio_st *peer_b = b->peer->ptr;
640
641 ret = (long) peer_b->len;
642 }
643 else
644 ret = 0;
645 break;
646
647 case BIO_CTRL_WPENDING:
648 if (b->buf != NULL)
649 ret = (long) b->len;
650 else
651 ret = 0;
652 break;
653
654 case BIO_CTRL_DUP:
655 /* See BIO_dup_chain for circumstances we have to expect. */
656 {
657 BIO *other_bio = ptr;
658 struct bio_bio_st *other_b;
659
660 assert(other_bio != NULL);
661 other_b = other_bio->ptr;
662 assert(other_b != NULL);
663
664 assert(other_b->buf == NULL); /* other_bio is always fresh */
665
666 other_b->size = b->size;
667 }
668
669 ret = 1;
670 break;
671
672 case BIO_CTRL_FLUSH:
673 ret = 1;
674 break;
675
676 case BIO_CTRL_EOF:
677 {
678 BIO *other_bio = ptr;
679
680 if (other_bio)
681 {
682 struct bio_bio_st *other_b = other_bio->ptr;
683
684 assert(other_b != NULL);
685 ret = other_b->len == 0 && other_b->closed;
686 }
687 else
688 ret = 1;
689 }
690 break;
691
692 default:
693 ret = 0;
694 }
695 return ret;
696 }
697
698static int bio_puts(BIO *bio, const char *str)
699 {
700 return bio_write(bio, str, strlen(str));
701 }
702
703
704static int bio_make_pair(BIO *bio1, BIO *bio2)
705 {
706 struct bio_bio_st *b1, *b2;
707
708 assert(bio1 != NULL);
709 assert(bio2 != NULL);
710
711 b1 = bio1->ptr;
712 b2 = bio2->ptr;
713
714 if (b1->peer != NULL || b2->peer != NULL)
715 {
716 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
717 return 0;
718 }
719
720 if (b1->buf == NULL)
721 {
722 b1->buf = OPENSSL_malloc(b1->size);
723 if (b1->buf == NULL)
724 {
725 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
726 return 0;
727 }
728 b1->len = 0;
729 b1->offset = 0;
730 }
731
732 if (b2->buf == NULL)
733 {
734 b2->buf = OPENSSL_malloc(b2->size);
735 if (b2->buf == NULL)
736 {
737 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
738 return 0;
739 }
740 b2->len = 0;
741 b2->offset = 0;
742 }
743
744 b1->peer = bio2;
745 b1->closed = 0;
746 b1->request = 0;
747 b2->peer = bio1;
748 b2->closed = 0;
749 b2->request = 0;
750
751 bio1->init = 1;
752 bio2->init = 1;
753
754 return 1;
755 }
756
757static void bio_destroy_pair(BIO *bio)
758 {
759 struct bio_bio_st *b = bio->ptr;
760
761 if (b != NULL)
762 {
763 BIO *peer_bio = b->peer;
764
765 if (peer_bio != NULL)
766 {
767 struct bio_bio_st *peer_b = peer_bio->ptr;
768
769 assert(peer_b != NULL);
770 assert(peer_b->peer == bio);
771
772 peer_b->peer = NULL;
773 peer_bio->init = 0;
774 assert(peer_b->buf != NULL);
775 peer_b->len = 0;
776 peer_b->offset = 0;
777
778 b->peer = NULL;
779 bio->init = 0;
780 assert(b->buf != NULL);
781 b->len = 0;
782 b->offset = 0;
783 }
784 }
785 }
786
787
788/* Exported convenience functions */
789int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
790 BIO **bio2_p, size_t writebuf2)
791 {
792 BIO *bio1 = NULL, *bio2 = NULL;
793 long r;
794 int ret = 0;
795
796 bio1 = BIO_new(BIO_s_bio());
797 if (bio1 == NULL)
798 goto err;
799 bio2 = BIO_new(BIO_s_bio());
800 if (bio2 == NULL)
801 goto err;
802
803 if (writebuf1)
804 {
805 r = BIO_set_write_buf_size(bio1, writebuf1);
806 if (!r)
807 goto err;
808 }
809 if (writebuf2)
810 {
811 r = BIO_set_write_buf_size(bio2, writebuf2);
812 if (!r)
813 goto err;
814 }
815
816 r = BIO_make_bio_pair(bio1, bio2);
817 if (!r)
818 goto err;
819 ret = 1;
820
821 err:
822 if (ret == 0)
823 {
824 if (bio1)
825 {
826 BIO_free(bio1);
827 bio1 = NULL;
828 }
829 if (bio2)
830 {
831 BIO_free(bio2);
832 bio2 = NULL;
833 }
834 }
835
836 *bio1_p = bio1;
837 *bio2_p = bio2;
838 return ret;
839 }
840
841size_t BIO_ctrl_get_write_guarantee(BIO *bio)
842 {
843 return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
844 }
845
846size_t BIO_ctrl_get_read_request(BIO *bio)
847 {
848 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
849 }
850
851int BIO_ctrl_reset_read_request(BIO *bio)
852 {
853 return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
854 }
855
856
857/* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now
858 * (conceivably some other BIOs could allow non-copying reads and writes too.)
859 */
860int BIO_nread0(BIO *bio, char **buf)
861 {
862 long ret;
863
864 if (!bio->init)
865 {
866 BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED);
867 return -2;
868 }
869
870 ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf);
871 if (ret > INT_MAX)
872 return INT_MAX;
873 else
874 return (int) ret;
875 }
876
877int BIO_nread(BIO *bio, char **buf, int num)
878 {
879 int ret;
880
881 if (!bio->init)
882 {
883 BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED);
884 return -2;
885 }
886
887 ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf);
888 if (ret > 0)
889 bio->num_read += ret;
890 return ret;
891 }
892
893int BIO_nwrite0(BIO *bio, char **buf)
894 {
895 long ret;
896
897 if (!bio->init)
898 {
899 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED);
900 return -2;
901 }
902
903 ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf);
904 if (ret > INT_MAX)
905 return INT_MAX;
906 else
907 return (int) ret;
908 }
909
910int BIO_nwrite(BIO *bio, char **buf, int num)
911 {
912 int ret;
913
914 if (!bio->init)
915 {
916 BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED);
917 return -2;
918 }
919
920 ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf);
921 if (ret > 0)
922 bio->num_read += ret;
923 return ret;
924 }
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
deleted file mode 100644
index 216780ed5e..0000000000
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ /dev/null
@@ -1,652 +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 OPENSSL_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 OPENSSL_SYS_WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else
70#define SOCKET_PROTOCOL IPPROTO_TCP
71#endif
72
73#if (defined(OPENSSL_SYS_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)(const BIO *bio,int state,int ret);
99 } BIO_CONNECT;
100
101static int conn_write(BIO *h, const char *buf, int num);
102static int conn_read(BIO *h, char *buf, int size);
103static int conn_puts(BIO *h, const char *str);
104static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2);
105static int conn_new(BIO *h);
106static int conn_free(BIO *data);
107static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *);
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 OPENSSL_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#if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
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 *)OPENSSL_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 OPENSSL_free(a->param_hostname);
348 if (a->param_port != NULL)
349 OPENSSL_free(a->param_port);
350 OPENSSL_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, const 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, void *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 OPENSSL_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 OPENSSL_free(data->param_port);
517 data->param_port=BUF_strdup(ptr);
518 }
519 else if (num == 2)
520 {
521 char buf[16];
522 unsigned char *p = ptr;
523
524 BIO_snprintf(buf,sizeof buf,"%d.%d.%d.%d",
525 p[0],p[1],p[2],p[3]);
526 if (data->param_hostname != NULL)
527 OPENSSL_free(data->param_hostname);
528 data->param_hostname=BUF_strdup(buf);
529 memcpy(&(data->ip[0]),ptr,4);
530 }
531 else if (num == 3)
532 {
533 char buf[DECIMAL_SIZE(int)+1];
534
535 BIO_snprintf(buf,sizeof buf,"%d",*(int *)ptr);
536 if (data->param_port != NULL)
537 OPENSSL_free(data->param_port);
538 data->param_port=BUF_strdup(buf);
539 data->port= *(int *)ptr;
540 }
541 }
542 break;
543 case BIO_C_SET_NBIO:
544 data->nbio=(int)num;
545 break;
546 case BIO_C_GET_FD:
547 if (b->init)
548 {
549 ip=(int *)ptr;
550 if (ip != NULL)
551 *ip=b->num;
552 ret=b->num;
553 }
554 else
555 ret= -1;
556 break;
557 case BIO_CTRL_GET_CLOSE:
558 ret=b->shutdown;
559 break;
560 case BIO_CTRL_SET_CLOSE:
561 b->shutdown=(int)num;
562 break;
563 case BIO_CTRL_PENDING:
564 case BIO_CTRL_WPENDING:
565 ret=0;
566 break;
567 case BIO_CTRL_FLUSH:
568 break;
569 case BIO_CTRL_DUP:
570 {
571 dbio=(BIO *)ptr;
572 if (data->param_port)
573 BIO_set_conn_port(dbio,data->param_port);
574 if (data->param_hostname)
575 BIO_set_conn_hostname(dbio,data->param_hostname);
576 BIO_set_nbio(dbio,data->nbio);
577 /* FIXME: the cast of the function seems unlikely to be a good idea */
578 (void)BIO_set_info_callback(dbio,(bio_info_cb *)data->info_callback);
579 }
580 break;
581 case BIO_CTRL_SET_CALLBACK:
582 {
583#if 0 /* FIXME: Should this be used? -- Richard Levitte */
584 BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
585 ret = -1;
586#else
587 ret=0;
588#endif
589 }
590 break;
591 case BIO_CTRL_GET_CALLBACK:
592 {
593 int (**fptr)();
594
595 fptr=(int (**)())ptr;
596 *fptr=data->info_callback;
597 }
598 break;
599 default:
600 ret=0;
601 break;
602 }
603 return(ret);
604 }
605
606static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
607 {
608 long ret=1;
609 BIO_CONNECT *data;
610
611 data=(BIO_CONNECT *)b->ptr;
612
613 switch (cmd)
614 {
615 case BIO_CTRL_SET_CALLBACK:
616 {
617 data->info_callback=(int (*)(const struct bio_st *, int, int))fp;
618 }
619 break;
620 default:
621 ret=0;
622 break;
623 }
624 return(ret);
625 }
626
627static int conn_puts(BIO *bp, const char *str)
628 {
629 int n,ret;
630
631 n=strlen(str);
632 ret=conn_write(bp,str,n);
633 return(ret);
634 }
635
636BIO *BIO_new_connect(char *str)
637 {
638 BIO *ret;
639
640 ret=BIO_new(BIO_s_connect());
641 if (ret == NULL) return(NULL);
642 if (BIO_set_conn_hostname(ret,str))
643 return(ret);
644 else
645 {
646 BIO_free(ret);
647 return(NULL);
648 }
649 }
650
651#endif
652
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c
deleted file mode 100644
index 5e3e187de6..0000000000
--- a/src/lib/libcrypto/bio/bss_fd.c
+++ /dev/null
@@ -1,282 +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#include <stdio.h>
60#include <errno.h>
61#define USE_SOCKETS
62#include "cryptlib.h"
63#include <openssl/bio.h>
64
65static int fd_write(BIO *h, const char *buf, int num);
66static int fd_read(BIO *h, char *buf, int size);
67static int fd_puts(BIO *h, const char *str);
68static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2);
69static int fd_new(BIO *h);
70static int fd_free(BIO *data);
71int BIO_fd_should_retry(int s);
72
73static BIO_METHOD methods_fdp=
74 {
75 BIO_TYPE_FD,"file descriptor",
76 fd_write,
77 fd_read,
78 fd_puts,
79 NULL, /* fd_gets, */
80 fd_ctrl,
81 fd_new,
82 fd_free,
83 NULL,
84 };
85
86BIO_METHOD *BIO_s_fd(void)
87 {
88 return(&methods_fdp);
89 }
90
91BIO *BIO_new_fd(int fd,int close_flag)
92 {
93 BIO *ret;
94 ret=BIO_new(BIO_s_fd());
95 if (ret == NULL) return(NULL);
96 BIO_set_fd(ret,fd,close_flag);
97 return(ret);
98 }
99
100static int fd_new(BIO *bi)
101 {
102 bi->init=0;
103 bi->num=0;
104 bi->ptr=NULL;
105 bi->flags=0;
106 return(1);
107 }
108
109static int fd_free(BIO *a)
110 {
111 if (a == NULL) return(0);
112 if (a->shutdown)
113 {
114 if (a->init)
115 {
116 close(a->num);
117 }
118 a->init=0;
119 a->flags=0;
120 }
121 return(1);
122 }
123
124static int fd_read(BIO *b, char *out,int outl)
125 {
126 int ret=0;
127
128 if (out != NULL)
129 {
130 clear_sys_error();
131 ret=read(b->num,out,outl);
132 BIO_clear_retry_flags(b);
133 if (ret <= 0)
134 {
135 if (BIO_fd_should_retry(ret))
136 BIO_set_retry_read(b);
137 }
138 }
139 return(ret);
140 }
141
142static int fd_write(BIO *b, const char *in, int inl)
143 {
144 int ret;
145 clear_sys_error();
146 ret=write(b->num,in,inl);
147 BIO_clear_retry_flags(b);
148 if (ret <= 0)
149 {
150 if (BIO_fd_should_retry(ret))
151 BIO_set_retry_write(b);
152 }
153 return(ret);
154 }
155
156static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
157 {
158 long ret=1;
159 int *ip;
160
161 switch (cmd)
162 {
163 case BIO_CTRL_RESET:
164 num=0;
165 case BIO_C_FILE_SEEK:
166 ret=(long)lseek(b->num,num,0);
167 break;
168 case BIO_C_FILE_TELL:
169 case BIO_CTRL_INFO:
170 ret=(long)lseek(b->num,0,1);
171 break;
172 case BIO_C_SET_FD:
173 fd_free(b);
174 b->num= *((int *)ptr);
175 b->shutdown=(int)num;
176 b->init=1;
177 break;
178 case BIO_C_GET_FD:
179 if (b->init)
180 {
181 ip=(int *)ptr;
182 if (ip != NULL) *ip=b->num;
183 ret=b->num;
184 }
185 else
186 ret= -1;
187 break;
188 case BIO_CTRL_GET_CLOSE:
189 ret=b->shutdown;
190 break;
191 case BIO_CTRL_SET_CLOSE:
192 b->shutdown=(int)num;
193 break;
194 case BIO_CTRL_PENDING:
195 case BIO_CTRL_WPENDING:
196 ret=0;
197 break;
198 case BIO_CTRL_DUP:
199 case BIO_CTRL_FLUSH:
200 ret=1;
201 break;
202 default:
203 ret=0;
204 break;
205 }
206 return(ret);
207 }
208
209static int fd_puts(BIO *bp, const char *str)
210 {
211 int n,ret;
212
213 n=strlen(str);
214 ret=fd_write(bp,str,n);
215 return(ret);
216 }
217
218int BIO_fd_should_retry(int i)
219 {
220 int err;
221
222 if ((i == 0) || (i == -1))
223 {
224 err=get_last_sys_error();
225
226#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
227 if ((i == -1) && (err == 0))
228 return(1);
229#endif
230
231 return(BIO_fd_non_fatal_error(err));
232 }
233 return(0);
234 }
235
236int BIO_fd_non_fatal_error(int err)
237 {
238 switch (err)
239 {
240
241#ifdef EWOULDBLOCK
242# ifdef WSAEWOULDBLOCK
243# if WSAEWOULDBLOCK != EWOULDBLOCK
244 case EWOULDBLOCK:
245# endif
246# else
247 case EWOULDBLOCK:
248# endif
249#endif
250
251#if defined(ENOTCONN)
252 case ENOTCONN:
253#endif
254
255#ifdef EINTR
256 case EINTR:
257#endif
258
259#ifdef EAGAIN
260#if EWOULDBLOCK != EAGAIN
261 case EAGAIN:
262# endif
263#endif
264
265#ifdef EPROTO
266 case EPROTO:
267#endif
268
269#ifdef EINPROGRESS
270 case EINPROGRESS:
271#endif
272
273#ifdef EALREADY
274 case EALREADY:
275#endif
276 return(1);
277 /* break; */
278 default:
279 break;
280 }
281 return(0);
282 }
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
deleted file mode 100644
index 58fade9f29..0000000000
--- a/src/lib/libcrypto/bio/bss_file.c
+++ /dev/null
@@ -1,343 +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(OPENSSL_NO_STDIO)
75
76static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
77static int MS_CALLBACK file_read(BIO *h, char *buf, int size);
78static int MS_CALLBACK file_puts(BIO *h, const 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, void *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 if (errno == ENOENT)
107 BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);
108 else
109 BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
110 return(NULL);
111 }
112 if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
113 return(NULL);
114
115 BIO_set_fp(ret,file,BIO_CLOSE);
116 return(ret);
117 }
118
119BIO *BIO_new_fp(FILE *stream, int close_flag)
120 {
121 BIO *ret;
122
123 if ((ret=BIO_new(BIO_s_file())) == NULL)
124 return(NULL);
125
126 BIO_set_fp(ret,stream,close_flag);
127 return(ret);
128 }
129
130BIO_METHOD *BIO_s_file(void)
131 {
132 return(&methods_filep);
133 }
134
135static int MS_CALLBACK file_new(BIO *bi)
136 {
137 bi->init=0;
138 bi->num=0;
139 bi->ptr=NULL;
140 return(1);
141 }
142
143static int MS_CALLBACK file_free(BIO *a)
144 {
145 if (a == NULL) return(0);
146 if (a->shutdown)
147 {
148 if ((a->init) && (a->ptr != NULL))
149 {
150 fclose((FILE *)a->ptr);
151 a->ptr=NULL;
152 }
153 a->init=0;
154 }
155 return(1);
156 }
157
158static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
159 {
160 int ret=0;
161
162 if (b->init && (out != NULL))
163 {
164 ret=fread(out,1,(int)outl,(FILE *)b->ptr);
165 if(ret == 0 && ferror((FILE *)b->ptr))
166 {
167 SYSerr(SYS_F_FREAD,get_last_sys_error());
168 BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB);
169 ret=-1;
170 }
171 }
172 return(ret);
173 }
174
175static int MS_CALLBACK file_write(BIO *b, const char *in, int inl)
176 {
177 int ret=0;
178
179 if (b->init && (in != NULL))
180 {
181 if (fwrite(in,(int)inl,1,(FILE *)b->ptr))
182 ret=inl;
183 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
184 /* according to Tim Hudson <tjh@cryptsoft.com>, the commented
185 * out version above can cause 'inl' write calls under
186 * some stupid stdio implementations (VMS) */
187 }
188 return(ret);
189 }
190
191static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
192 {
193 long ret=1;
194 FILE *fp=(FILE *)b->ptr;
195 FILE **fpp;
196 char p[4];
197
198 switch (cmd)
199 {
200 case BIO_C_FILE_SEEK:
201 case BIO_CTRL_RESET:
202 ret=(long)fseek(fp,num,SEEK_SET);
203 break;
204 case BIO_CTRL_EOF:
205 ret=(long)feof(fp);
206 break;
207 case BIO_C_FILE_TELL:
208 case BIO_CTRL_INFO:
209 ret=ftell(fp);
210 break;
211 case BIO_C_SET_FILE_PTR:
212 file_free(b);
213 b->shutdown=(int)num&BIO_CLOSE;
214 b->ptr=(char *)ptr;
215 b->init=1;
216 {
217#if defined(OPENSSL_SYS_WINDOWS)
218 int fd = fileno((FILE*)ptr);
219 if (num & BIO_FP_TEXT)
220 _setmode(fd,_O_TEXT);
221 else
222 _setmode(fd,_O_BINARY);
223#elif defined(OPENSSL_SYS_MSDOS)
224 int fd = fileno((FILE*)ptr);
225 /* Set correct text/binary mode */
226 if (num & BIO_FP_TEXT)
227 _setmode(fd,_O_TEXT);
228 /* Dangerous to set stdin/stdout to raw (unless redirected) */
229 else
230 {
231 if (fd == STDIN_FILENO || fd == STDOUT_FILENO)
232 {
233 if (isatty(fd) <= 0)
234 _setmode(fd,_O_BINARY);
235 }
236 else
237 _setmode(fd,_O_BINARY);
238 }
239#elif defined(OPENSSL_SYS_OS2)
240 int fd = fileno((FILE*)ptr);
241 if (num & BIO_FP_TEXT)
242 setmode(fd, O_TEXT);
243 else
244 setmode(fd, O_BINARY);
245#endif
246 }
247 break;
248 case BIO_C_SET_FILENAME:
249 file_free(b);
250 b->shutdown=(int)num&BIO_CLOSE;
251 if (num & BIO_FP_APPEND)
252 {
253 if (num & BIO_FP_READ)
254 BUF_strlcpy(p,"a+",sizeof p);
255 else BUF_strlcpy(p,"a",sizeof p);
256 }
257 else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
258 BUF_strlcpy(p,"r+",sizeof p);
259 else if (num & BIO_FP_WRITE)
260 BUF_strlcpy(p,"w",sizeof p);
261 else if (num & BIO_FP_READ)
262 BUF_strlcpy(p,"r",sizeof p);
263 else
264 {
265 BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE);
266 ret=0;
267 break;
268 }
269#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
270 if (!(num & BIO_FP_TEXT))
271 strcat(p,"b");
272 else
273 strcat(p,"t");
274#endif
275 fp=fopen(ptr,p);
276 if (fp == NULL)
277 {
278 SYSerr(SYS_F_FOPEN,get_last_sys_error());
279 ERR_add_error_data(5,"fopen('",ptr,"','",p,"')");
280 BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB);
281 ret=0;
282 break;
283 }
284 b->ptr=(char *)fp;
285 b->init=1;
286 break;
287 case BIO_C_GET_FILE_PTR:
288 /* the ptr parameter is actually a FILE ** in this case. */
289 if (ptr != NULL)
290 {
291 fpp=(FILE **)ptr;
292 *fpp=(FILE *)b->ptr;
293 }
294 break;
295 case BIO_CTRL_GET_CLOSE:
296 ret=(long)b->shutdown;
297 break;
298 case BIO_CTRL_SET_CLOSE:
299 b->shutdown=(int)num;
300 break;
301 case BIO_CTRL_FLUSH:
302 fflush((FILE *)b->ptr);
303 break;
304 case BIO_CTRL_DUP:
305 ret=1;
306 break;
307
308 case BIO_CTRL_WPENDING:
309 case BIO_CTRL_PENDING:
310 case BIO_CTRL_PUSH:
311 case BIO_CTRL_POP:
312 default:
313 ret=0;
314 break;
315 }
316 return(ret);
317 }
318
319static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
320 {
321 int ret=0;
322
323 buf[0]='\0';
324 fgets(buf,size,(FILE *)bp->ptr);
325 if (buf[0] != '\0')
326 ret=strlen(buf);
327 return(ret);
328 }
329
330static int MS_CALLBACK file_puts(BIO *bp, const char *str)
331 {
332 int n,ret;
333
334 n=strlen(str);
335 ret=file_write(bp,str,n);
336 return(ret);
337 }
338
339#endif /* OPENSSL_NO_STDIO */
340
341#endif /* HEADER_BSS_FILE_C */
342
343
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
deleted file mode 100644
index 1eb678cac0..0000000000
--- a/src/lib/libcrypto/bio/bss_log.c
+++ /dev/null
@@ -1,400 +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#include "cryptlib.h"
70
71#if defined(OPENSSL_SYS_WINCE)
72#elif defined(OPENSSL_SYS_WIN32)
73# include <process.h>
74#elif defined(OPENSSL_SYS_VMS)
75# include <opcdef.h>
76# include <descrip.h>
77# include <lib$routines.h>
78# include <starlet.h>
79#elif defined(__ultrix)
80# include <sys/syslog.h>
81#elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG)
82# include <syslog.h>
83#endif
84
85#include <openssl/buffer.h>
86#include <openssl/err.h>
87
88#ifndef NO_SYSLOG
89
90#if defined(OPENSSL_SYS_WIN32)
91#define LOG_EMERG 0
92#define LOG_ALERT 1
93#define LOG_CRIT 2
94#define LOG_ERR 3
95#define LOG_WARNING 4
96#define LOG_NOTICE 5
97#define LOG_INFO 6
98#define LOG_DEBUG 7
99
100#define LOG_DAEMON (3<<3)
101#elif defined(OPENSSL_SYS_VMS)
102/* On VMS, we don't really care about these, but we need them to compile */
103#define LOG_EMERG 0
104#define LOG_ALERT 1
105#define LOG_CRIT 2
106#define LOG_ERR 3
107#define LOG_WARNING 4
108#define LOG_NOTICE 5
109#define LOG_INFO 6
110#define LOG_DEBUG 7
111
112#define LOG_DAEMON OPC$M_NM_NTWORK
113#endif
114
115static int MS_CALLBACK slg_write(BIO *h, const char *buf, int num);
116static int MS_CALLBACK slg_puts(BIO *h, const char *str);
117static long MS_CALLBACK slg_ctrl(BIO *h, int cmd, long arg1, void *arg2);
118static int MS_CALLBACK slg_new(BIO *h);
119static int MS_CALLBACK slg_free(BIO *data);
120static void xopenlog(BIO* bp, char* name, int level);
121static void xsyslog(BIO* bp, int priority, const char* string);
122static void xcloselog(BIO* bp);
123#ifdef OPENSSL_SYS_WIN32
124LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx;
125HANDLE (WINAPI *register_event_source)() = NULL;
126BOOL (WINAPI *deregister_event_source)() = NULL;
127BOOL (WINAPI *report_event)() = NULL;
128#define DL_PROC(m,f) (GetProcAddress( m, f ))
129#ifdef UNICODE
130#define DL_PROC_X(m,f) DL_PROC( m, f "W" )
131#else
132#define DL_PROC_X(m,f) DL_PROC( m, f "A" )
133#endif
134#endif
135
136static BIO_METHOD methods_slg=
137 {
138 BIO_TYPE_MEM,"syslog",
139 slg_write,
140 NULL,
141 slg_puts,
142 NULL,
143 slg_ctrl,
144 slg_new,
145 slg_free,
146 NULL,
147 };
148
149BIO_METHOD *BIO_s_log(void)
150 {
151 return(&methods_slg);
152 }
153
154static int MS_CALLBACK slg_new(BIO *bi)
155 {
156 bi->init=1;
157 bi->num=0;
158 bi->ptr=NULL;
159 xopenlog(bi, "application", LOG_DAEMON);
160 return(1);
161 }
162
163static int MS_CALLBACK slg_free(BIO *a)
164 {
165 if (a == NULL) return(0);
166 xcloselog(a);
167 return(1);
168 }
169
170static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
171 {
172 int ret= inl;
173 char* buf;
174 char* pp;
175 int priority, i;
176 static struct
177 {
178 int strl;
179 char str[10];
180 int log_level;
181 }
182 mapping[] =
183 {
184 { 6, "PANIC ", LOG_EMERG },
185 { 6, "EMERG ", LOG_EMERG },
186 { 4, "EMR ", LOG_EMERG },
187 { 6, "ALERT ", LOG_ALERT },
188 { 4, "ALR ", LOG_ALERT },
189 { 5, "CRIT ", LOG_CRIT },
190 { 4, "CRI ", LOG_CRIT },
191 { 6, "ERROR ", LOG_ERR },
192 { 4, "ERR ", LOG_ERR },
193 { 8, "WARNING ", LOG_WARNING },
194 { 5, "WARN ", LOG_WARNING },
195 { 4, "WAR ", LOG_WARNING },
196 { 7, "NOTICE ", LOG_NOTICE },
197 { 5, "NOTE ", LOG_NOTICE },
198 { 4, "NOT ", LOG_NOTICE },
199 { 5, "INFO ", LOG_INFO },
200 { 4, "INF ", LOG_INFO },
201 { 6, "DEBUG ", LOG_DEBUG },
202 { 4, "DBG ", LOG_DEBUG },
203 { 0, "", LOG_ERR } /* The default */
204 };
205
206 if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){
207 return(0);
208 }
209 strncpy(buf, in, inl);
210 buf[inl]= '\0';
211
212 i = 0;
213 while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++;
214 priority = mapping[i].log_level;
215 pp = buf + mapping[i].strl;
216
217 xsyslog(b, priority, pp);
218
219 OPENSSL_free(buf);
220 return(ret);
221 }
222
223static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, void *ptr)
224 {
225 switch (cmd)
226 {
227 case BIO_CTRL_SET:
228 xcloselog(b);
229 xopenlog(b, ptr, num);
230 break;
231 default:
232 break;
233 }
234 return(0);
235 }
236
237static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
238 {
239 int n,ret;
240
241 n=strlen(str);
242 ret=slg_write(bp,str,n);
243 return(ret);
244 }
245
246#if defined(OPENSSL_SYS_WIN32)
247
248static void xopenlog(BIO* bp, char* name, int level)
249{
250 if ( !register_event_source )
251 {
252 HANDLE advapi;
253 if ( !(advapi = GetModuleHandle("advapi32")) )
254 return;
255 register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi,
256 "RegisterEventSource" );
257 deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi,
258 "DeregisterEventSource");
259 report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi,
260 "ReportEvent" );
261 if ( !(register_event_source && deregister_event_source &&
262 report_event) )
263 {
264 register_event_source = NULL;
265 deregister_event_source = NULL;
266 report_event = NULL;
267 return;
268 }
269 }
270 bp->ptr= (char *)register_event_source(NULL, name);
271}
272
273static void xsyslog(BIO *bp, int priority, const char *string)
274{
275 LPCSTR lpszStrings[2];
276 WORD evtype= EVENTLOG_ERROR_TYPE;
277 int pid = _getpid();
278 char pidbuf[DECIMAL_SIZE(pid)+4];
279
280 switch (priority)
281 {
282 case LOG_EMERG:
283 case LOG_ALERT:
284 case LOG_CRIT:
285 case LOG_ERR:
286 evtype = EVENTLOG_ERROR_TYPE;
287 break;
288 case LOG_WARNING:
289 evtype = EVENTLOG_WARNING_TYPE;
290 break;
291 case LOG_NOTICE:
292 case LOG_INFO:
293 case LOG_DEBUG:
294 evtype = EVENTLOG_INFORMATION_TYPE;
295 break;
296 default: /* Should never happen, but set it
297 as error anyway. */
298 evtype = EVENTLOG_ERROR_TYPE;
299 break;
300 }
301
302 sprintf(pidbuf, "[%d] ", pid);
303 lpszStrings[0] = pidbuf;
304 lpszStrings[1] = string;
305
306 if(report_event && bp->ptr)
307 report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
308 lpszStrings, NULL);
309}
310
311static void xcloselog(BIO* bp)
312{
313 if(deregister_event_source && bp->ptr)
314 deregister_event_source((HANDLE)(bp->ptr));
315 bp->ptr= NULL;
316}
317
318#elif defined(OPENSSL_SYS_VMS)
319
320static int VMS_OPC_target = LOG_DAEMON;
321
322static void xopenlog(BIO* bp, char* name, int level)
323{
324 VMS_OPC_target = level;
325}
326
327static void xsyslog(BIO *bp, int priority, const char *string)
328{
329 struct dsc$descriptor_s opc_dsc;
330 struct opcdef *opcdef_p;
331 char buf[10240];
332 unsigned int len;
333 struct dsc$descriptor_s buf_dsc;
334 $DESCRIPTOR(fao_cmd, "!AZ: !AZ");
335 char *priority_tag;
336
337 switch (priority)
338 {
339 case LOG_EMERG: priority_tag = "Emergency"; break;
340 case LOG_ALERT: priority_tag = "Alert"; break;
341 case LOG_CRIT: priority_tag = "Critical"; break;
342 case LOG_ERR: priority_tag = "Error"; break;
343 case LOG_WARNING: priority_tag = "Warning"; break;
344 case LOG_NOTICE: priority_tag = "Notice"; break;
345 case LOG_INFO: priority_tag = "Info"; break;
346 case LOG_DEBUG: priority_tag = "DEBUG"; break;
347 }
348
349 buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
350 buf_dsc.dsc$b_class = DSC$K_CLASS_S;
351 buf_dsc.dsc$a_pointer = buf;
352 buf_dsc.dsc$w_length = sizeof(buf) - 1;
353
354 lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
355
356 /* we know there's an 8 byte header. That's documented */
357 opcdef_p = (struct opcdef *) OPENSSL_malloc(8 + len);
358 opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
359 memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
360 opcdef_p->opc$l_ms_rqstid = 0;
361 memcpy(&opcdef_p->opc$l_ms_text, buf, len);
362
363 opc_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
364 opc_dsc.dsc$b_class = DSC$K_CLASS_S;
365 opc_dsc.dsc$a_pointer = (char *)opcdef_p;
366 opc_dsc.dsc$w_length = len + 8;
367
368 sys$sndopr(opc_dsc, 0);
369
370 OPENSSL_free(opcdef_p);
371}
372
373static void xcloselog(BIO* bp)
374{
375}
376
377#else /* Unix/Watt32 */
378
379static void xopenlog(BIO* bp, char* name, int level)
380{
381#ifdef WATT32 /* djgpp/DOS */
382 openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level);
383#else
384 openlog(name, LOG_PID|LOG_CONS, level);
385#endif
386}
387
388static void xsyslog(BIO *bp, int priority, const char *string)
389{
390 syslog(priority, "%s", string);
391}
392
393static void xcloselog(BIO* bp)
394{
395 closelog();
396}
397
398#endif /* Unix */
399
400#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 a4edb711ae..0000000000
--- a/src/lib/libcrypto/bio/bss_mem.c
+++ /dev/null
@@ -1,321 +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, const char *buf, int num);
65static int mem_read(BIO *h, char *buf, int size);
66static int mem_puts(BIO *h, const char *str);
67static int mem_gets(BIO *h, char *str, int size);
68static long mem_ctrl(BIO *h, int cmd, long arg1, void *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 ret = b->num;
167 if (ret != 0)
168 BIO_set_retry_read(b);
169 }
170 return(ret);
171 }
172
173static int mem_write(BIO *b, const 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_clean(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, void *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 {
213 /* For read only case reset to the start again */
214 if(b->flags & BIO_FLAGS_MEM_RDONLY)
215 {
216 bm->data -= bm->max - bm->length;
217 bm->length = bm->max;
218 }
219 else
220 {
221 memset(bm->data,0,bm->max);
222 bm->length=0;
223 }
224 }
225 break;
226 case BIO_CTRL_EOF:
227 ret=(long)(bm->length == 0);
228 break;
229 case BIO_C_SET_BUF_MEM_EOF_RETURN:
230 b->num=(int)num;
231 break;
232 case BIO_CTRL_INFO:
233 ret=(long)bm->length;
234 if (ptr != NULL)
235 {
236 pptr=(char **)ptr;
237 *pptr=(char *)&(bm->data[0]);
238 }
239 break;
240 case BIO_C_SET_BUF_MEM:
241 mem_free(b);
242 b->shutdown=(int)num;
243 b->ptr=ptr;
244 break;
245 case BIO_C_GET_BUF_MEM_PTR:
246 if (ptr != NULL)
247 {
248 pptr=(char **)ptr;
249 *pptr=(char *)bm;
250 }
251 break;
252 case BIO_CTRL_GET_CLOSE:
253 ret=(long)b->shutdown;
254 break;
255 case BIO_CTRL_SET_CLOSE:
256 b->shutdown=(int)num;
257 break;
258
259 case BIO_CTRL_WPENDING:
260 ret=0L;
261 break;
262 case BIO_CTRL_PENDING:
263 ret=(long)bm->length;
264 break;
265 case BIO_CTRL_DUP:
266 case BIO_CTRL_FLUSH:
267 ret=1;
268 break;
269 case BIO_CTRL_PUSH:
270 case BIO_CTRL_POP:
271 default:
272 ret=0;
273 break;
274 }
275 return(ret);
276 }
277
278static int mem_gets(BIO *bp, char *buf, int size)
279 {
280 int i,j;
281 int ret= -1;
282 char *p;
283 BUF_MEM *bm=(BUF_MEM *)bp->ptr;
284
285 BIO_clear_retry_flags(bp);
286 j=bm->length;
287 if (j <= 0)
288 {
289 *buf='\0';
290 return 0;
291 }
292 p=bm->data;
293 for (i=0; i<j; i++)
294 {
295 if (p[i] == '\n') break;
296 }
297 if (i == j)
298 {
299 BIO_set_retry_read(bp);
300 /* return(-1); change the semantics 0.6.6a */
301 }
302 else
303 i++;
304 /* i is the max to copy */
305 if ((size-1) < i) i=size-1;
306 i=mem_read(bp,buf,i);
307 if (i > 0) buf[i]='\0';
308 ret=i;
309 return(ret);
310 }
311
312static int mem_puts(BIO *bp, const char *str)
313 {
314 int n,ret;
315
316 n=strlen(str);
317 ret=mem_write(bp,str,n);
318 /* memory semantics is that it will always work */
319 return(ret);
320 }
321
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c
deleted file mode 100644
index 46b73339df..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, const char *buf, int num);
65static int null_read(BIO *h, char *buf, int size);
66static int null_puts(BIO *h, const char *str);
67static int null_gets(BIO *h, char *str, int size);
68static long null_ctrl(BIO *h, int cmd, long arg1, void *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, const char *in, int inl)
110 {
111 return(inl);
112 }
113
114static long null_ctrl(BIO *b, int cmd, long num, void *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, const 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 2c1c405ec7..0000000000
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ /dev/null
@@ -1,305 +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#ifndef OPENSSL_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 WATT32
68#define sock_write SockWrite /* Watt-32 uses same names */
69#define sock_read SockRead
70#define sock_puts SockPuts
71#endif
72
73static int sock_write(BIO *h, const char *buf, int num);
74static int sock_read(BIO *h, char *buf, int size);
75static int sock_puts(BIO *h, const char *str);
76static long sock_ctrl(BIO *h, int cmd, long arg1, void *arg2);
77static int sock_new(BIO *h);
78static int sock_free(BIO *data);
79int BIO_sock_should_retry(int s);
80
81static BIO_METHOD methods_sockp=
82 {
83 BIO_TYPE_SOCKET,
84 "socket",
85 sock_write,
86 sock_read,
87 sock_puts,
88 NULL, /* sock_gets, */
89 sock_ctrl,
90 sock_new,
91 sock_free,
92 NULL,
93 };
94
95BIO_METHOD *BIO_s_socket(void)
96 {
97 return(&methods_sockp);
98 }
99
100BIO *BIO_new_socket(int fd, int close_flag)
101 {
102 BIO *ret;
103
104 ret=BIO_new(BIO_s_socket());
105 if (ret == NULL) return(NULL);
106 BIO_set_fd(ret,fd,close_flag);
107 return(ret);
108 }
109
110static int sock_new(BIO *bi)
111 {
112 bi->init=0;
113 bi->num=0;
114 bi->ptr=NULL;
115 bi->flags=0;
116 return(1);
117 }
118
119static int sock_free(BIO *a)
120 {
121 if (a == NULL) return(0);
122 if (a->shutdown)
123 {
124 if (a->init)
125 {
126 SHUTDOWN2(a->num);
127 }
128 a->init=0;
129 a->flags=0;
130 }
131 return(1);
132 }
133
134static int sock_read(BIO *b, char *out, int outl)
135 {
136 int ret=0;
137
138 if (out != NULL)
139 {
140 clear_socket_error();
141 ret=readsocket(b->num,out,outl);
142 BIO_clear_retry_flags(b);
143 if (ret <= 0)
144 {
145 if (BIO_sock_should_retry(ret))
146 BIO_set_retry_read(b);
147 }
148 }
149 return(ret);
150 }
151
152static int sock_write(BIO *b, const char *in, int inl)
153 {
154 int ret;
155
156 clear_socket_error();
157 ret=writesocket(b->num,in,inl);
158 BIO_clear_retry_flags(b);
159 if (ret <= 0)
160 {
161 if (BIO_sock_should_retry(ret))
162 BIO_set_retry_write(b);
163 }
164 return(ret);
165 }
166
167static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
168 {
169 long ret=1;
170 int *ip;
171
172 switch (cmd)
173 {
174 case BIO_CTRL_RESET:
175 num=0;
176 case BIO_C_FILE_SEEK:
177 ret=0;
178 break;
179 case BIO_C_FILE_TELL:
180 case BIO_CTRL_INFO:
181 ret=0;
182 break;
183 case BIO_C_SET_FD:
184 sock_free(b);
185 b->num= *((int *)ptr);
186 b->shutdown=(int)num;
187 b->init=1;
188 break;
189 case BIO_C_GET_FD:
190 if (b->init)
191 {
192 ip=(int *)ptr;
193 if (ip != NULL) *ip=b->num;
194 ret=b->num;
195 }
196 else
197 ret= -1;
198 break;
199 case BIO_CTRL_GET_CLOSE:
200 ret=b->shutdown;
201 break;
202 case BIO_CTRL_SET_CLOSE:
203 b->shutdown=(int)num;
204 break;
205 case BIO_CTRL_PENDING:
206 case BIO_CTRL_WPENDING:
207 ret=0;
208 break;
209 case BIO_CTRL_DUP:
210 case BIO_CTRL_FLUSH:
211 ret=1;
212 break;
213 default:
214 ret=0;
215 break;
216 }
217 return(ret);
218 }
219
220static int sock_puts(BIO *bp, const char *str)
221 {
222 int n,ret;
223
224 n=strlen(str);
225 ret=sock_write(bp,str,n);
226 return(ret);
227 }
228
229int BIO_sock_should_retry(int i)
230 {
231 int err;
232
233 if ((i == 0) || (i == -1))
234 {
235 err=get_last_socket_error();
236
237#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
238 if ((i == -1) && (err == 0))
239 return(1);
240#endif
241
242 return(BIO_sock_non_fatal_error(err));
243 }
244 return(0);
245 }
246
247int BIO_sock_non_fatal_error(int err)
248 {
249 switch (err)
250 {
251#if defined(OPENSSL_SYS_WINDOWS)
252# if defined(WSAEWOULDBLOCK)
253 case WSAEWOULDBLOCK:
254# endif
255
256# if 0 /* This appears to always be an error */
257# if defined(WSAENOTCONN)
258 case WSAENOTCONN:
259# endif
260# endif
261#endif
262
263#ifdef EWOULDBLOCK
264# ifdef WSAEWOULDBLOCK
265# if WSAEWOULDBLOCK != EWOULDBLOCK
266 case EWOULDBLOCK:
267# endif
268# else
269 case EWOULDBLOCK:
270# endif
271#endif
272
273#if defined(ENOTCONN)
274 case ENOTCONN:
275#endif
276
277#ifdef EINTR
278 case EINTR:
279#endif
280
281#ifdef EAGAIN
282#if EWOULDBLOCK != EAGAIN
283 case EAGAIN:
284# endif
285#endif
286
287#ifdef EPROTO
288 case EPROTO:
289#endif
290
291#ifdef EINPROGRESS
292 case EINPROGRESS:
293#endif
294
295#ifdef EALREADY
296 case EALREADY:
297#endif
298 return(1);
299 /* break; */
300 default:
301 break;
302 }
303 return(0);
304 }
305#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 c4de4a2bee..0000000000
--- a/src/lib/libcrypto/bn/asm/bn-586.pl
+++ /dev/null
@@ -1,593 +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#&bn_sub_part_words("bn_sub_part_words");
15
16&asm_finish();
17
18sub bn_mul_add_words
19 {
20 local($name)=@_;
21
22 &function_begin($name,"");
23
24 &comment("");
25 $Low="eax";
26 $High="edx";
27 $a="ebx";
28 $w="ebp";
29 $r="edi";
30 $c="esi";
31
32 &xor($c,$c); # clear carry
33 &mov($r,&wparam(0)); #
34
35 &mov("ecx",&wparam(2)); #
36 &mov($a,&wparam(1)); #
37
38 &and("ecx",0xfffffff8); # num / 8
39 &mov($w,&wparam(3)); #
40
41 &push("ecx"); # Up the stack for a tmp variable
42
43 &jz(&label("maw_finish"));
44
45 &set_label("maw_loop",0);
46
47 &mov(&swtmp(0),"ecx"); #
48
49 for ($i=0; $i<32; $i+=4)
50 {
51 &comment("Round $i");
52
53 &mov("eax",&DWP($i,$a,"",0)); # *a
54 &mul($w); # *a * w
55 &add("eax",$c); # L(t)+= *r
56 &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r
57 &adc("edx",0); # H(t)+=carry
58 &add("eax",$c); # L(t)+=c
59 &adc("edx",0); # H(t)+=carry
60 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
61 &mov($c,"edx"); # c= H(t);
62 }
63
64 &comment("");
65 &mov("ecx",&swtmp(0)); #
66 &add($a,32);
67 &add($r,32);
68 &sub("ecx",8);
69 &jnz(&label("maw_loop"));
70
71 &set_label("maw_finish",0);
72 &mov("ecx",&wparam(2)); # get num
73 &and("ecx",7);
74 &jnz(&label("maw_finish2")); # helps branch prediction
75 &jmp(&label("maw_end"));
76
77 &set_label("maw_finish2",1);
78 for ($i=0; $i<7; $i++)
79 {
80 &comment("Tail Round $i");
81 &mov("eax",&DWP($i*4,$a,"",0));# *a
82 &mul($w); # *a * w
83 &add("eax",$c); # L(t)+=c
84 &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r
85 &adc("edx",0); # H(t)+=carry
86 &add("eax",$c);
87 &adc("edx",0); # H(t)+=carry
88 &dec("ecx") if ($i != 7-1);
89 &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t);
90 &mov($c,"edx"); # c= H(t);
91 &jz(&label("maw_end")) if ($i != 7-1);
92 }
93 &set_label("maw_end",0);
94 &mov("eax",$c);
95
96 &pop("ecx"); # clear variable from
97
98 &function_end($name);
99 }
100
101sub bn_mul_words
102 {
103 local($name)=@_;
104
105 &function_begin($name,"");
106
107 &comment("");
108 $Low="eax";
109 $High="edx";
110 $a="ebx";
111 $w="ecx";
112 $r="edi";
113 $c="esi";
114 $num="ebp";
115
116 &xor($c,$c); # clear carry
117 &mov($r,&wparam(0)); #
118 &mov($a,&wparam(1)); #
119 &mov($num,&wparam(2)); #
120 &mov($w,&wparam(3)); #
121
122 &and($num,0xfffffff8); # num / 8
123 &jz(&label("mw_finish"));
124
125 &set_label("mw_loop",0);
126 for ($i=0; $i<32; $i+=4)
127 {
128 &comment("Round $i");
129
130 &mov("eax",&DWP($i,$a,"",0)); # *a
131 &mul($w); # *a * w
132 &add("eax",$c); # L(t)+=c
133 # XXX
134
135 &adc("edx",0); # H(t)+=carry
136 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
137
138 &mov($c,"edx"); # c= H(t);
139 }
140
141 &comment("");
142 &add($a,32);
143 &add($r,32);
144 &sub($num,8);
145 &jz(&label("mw_finish"));
146 &jmp(&label("mw_loop"));
147
148 &set_label("mw_finish",0);
149 &mov($num,&wparam(2)); # get num
150 &and($num,7);
151 &jnz(&label("mw_finish2"));
152 &jmp(&label("mw_end"));
153
154 &set_label("mw_finish2",1);
155 for ($i=0; $i<7; $i++)
156 {
157 &comment("Tail Round $i");
158 &mov("eax",&DWP($i*4,$a,"",0));# *a
159 &mul($w); # *a * w
160 &add("eax",$c); # L(t)+=c
161 # XXX
162 &adc("edx",0); # H(t)+=carry
163 &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t);
164 &mov($c,"edx"); # c= H(t);
165 &dec($num) if ($i != 7-1);
166 &jz(&label("mw_end")) if ($i != 7-1);
167 }
168 &set_label("mw_end",0);
169 &mov("eax",$c);
170
171 &function_end($name);
172 }
173
174sub bn_sqr_words
175 {
176 local($name)=@_;
177
178 &function_begin($name,"");
179
180 &comment("");
181 $r="esi";
182 $a="edi";
183 $num="ebx";
184
185 &mov($r,&wparam(0)); #
186 &mov($a,&wparam(1)); #
187 &mov($num,&wparam(2)); #
188
189 &and($num,0xfffffff8); # num / 8
190 &jz(&label("sw_finish"));
191
192 &set_label("sw_loop",0);
193 for ($i=0; $i<32; $i+=4)
194 {
195 &comment("Round $i");
196 &mov("eax",&DWP($i,$a,"",0)); # *a
197 # XXX
198 &mul("eax"); # *a * *a
199 &mov(&DWP($i*2,$r,"",0),"eax"); #
200 &mov(&DWP($i*2+4,$r,"",0),"edx");#
201 }
202
203 &comment("");
204 &add($a,32);
205 &add($r,64);
206 &sub($num,8);
207 &jnz(&label("sw_loop"));
208
209 &set_label("sw_finish",0);
210 &mov($num,&wparam(2)); # get num
211 &and($num,7);
212 &jz(&label("sw_end"));
213
214 for ($i=0; $i<7; $i++)
215 {
216 &comment("Tail Round $i");
217 &mov("eax",&DWP($i*4,$a,"",0)); # *a
218 # XXX
219 &mul("eax"); # *a * *a
220 &mov(&DWP($i*8,$r,"",0),"eax"); #
221 &dec($num) if ($i != 7-1);
222 &mov(&DWP($i*8+4,$r,"",0),"edx");
223 &jz(&label("sw_end")) if ($i != 7-1);
224 }
225 &set_label("sw_end",0);
226
227 &function_end($name);
228 }
229
230sub bn_div_words
231 {
232 local($name)=@_;
233
234 &function_begin($name,"");
235 &mov("edx",&wparam(0)); #
236 &mov("eax",&wparam(1)); #
237 &mov("ebx",&wparam(2)); #
238 &div("ebx");
239 &function_end($name);
240 }
241
242sub bn_add_words
243 {
244 local($name)=@_;
245
246 &function_begin($name,"");
247
248 &comment("");
249 $a="esi";
250 $b="edi";
251 $c="eax";
252 $r="ebx";
253 $tmp1="ecx";
254 $tmp2="edx";
255 $num="ebp";
256
257 &mov($r,&wparam(0)); # get r
258 &mov($a,&wparam(1)); # get a
259 &mov($b,&wparam(2)); # get b
260 &mov($num,&wparam(3)); # get num
261 &xor($c,$c); # clear carry
262 &and($num,0xfffffff8); # num / 8
263
264 &jz(&label("aw_finish"));
265
266 &set_label("aw_loop",0);
267 for ($i=0; $i<8; $i++)
268 {
269 &comment("Round $i");
270
271 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
272 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
273 &add($tmp1,$c);
274 &mov($c,0);
275 &adc($c,$c);
276 &add($tmp1,$tmp2);
277 &adc($c,0);
278 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
279 }
280
281 &comment("");
282 &add($a,32);
283 &add($b,32);
284 &add($r,32);
285 &sub($num,8);
286 &jnz(&label("aw_loop"));
287
288 &set_label("aw_finish",0);
289 &mov($num,&wparam(3)); # get num
290 &and($num,7);
291 &jz(&label("aw_end"));
292
293 for ($i=0; $i<7; $i++)
294 {
295 &comment("Tail Round $i");
296 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
297 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
298 &add($tmp1,$c);
299 &mov($c,0);
300 &adc($c,$c);
301 &add($tmp1,$tmp2);
302 &adc($c,0);
303 &dec($num) if ($i != 6);
304 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
305 &jz(&label("aw_end")) if ($i != 6);
306 }
307 &set_label("aw_end",0);
308
309# &mov("eax",$c); # $c is "eax"
310
311 &function_end($name);
312 }
313
314sub bn_sub_words
315 {
316 local($name)=@_;
317
318 &function_begin($name,"");
319
320 &comment("");
321 $a="esi";
322 $b="edi";
323 $c="eax";
324 $r="ebx";
325 $tmp1="ecx";
326 $tmp2="edx";
327 $num="ebp";
328
329 &mov($r,&wparam(0)); # get r
330 &mov($a,&wparam(1)); # get a
331 &mov($b,&wparam(2)); # get b
332 &mov($num,&wparam(3)); # get num
333 &xor($c,$c); # clear carry
334 &and($num,0xfffffff8); # num / 8
335
336 &jz(&label("aw_finish"));
337
338 &set_label("aw_loop",0);
339 for ($i=0; $i<8; $i++)
340 {
341 &comment("Round $i");
342
343 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
344 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
345 &sub($tmp1,$c);
346 &mov($c,0);
347 &adc($c,$c);
348 &sub($tmp1,$tmp2);
349 &adc($c,0);
350 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
351 }
352
353 &comment("");
354 &add($a,32);
355 &add($b,32);
356 &add($r,32);
357 &sub($num,8);
358 &jnz(&label("aw_loop"));
359
360 &set_label("aw_finish",0);
361 &mov($num,&wparam(3)); # get num
362 &and($num,7);
363 &jz(&label("aw_end"));
364
365 for ($i=0; $i<7; $i++)
366 {
367 &comment("Tail Round $i");
368 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
369 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
370 &sub($tmp1,$c);
371 &mov($c,0);
372 &adc($c,$c);
373 &sub($tmp1,$tmp2);
374 &adc($c,0);
375 &dec($num) if ($i != 6);
376 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
377 &jz(&label("aw_end")) if ($i != 6);
378 }
379 &set_label("aw_end",0);
380
381# &mov("eax",$c); # $c is "eax"
382
383 &function_end($name);
384 }
385
386sub bn_sub_part_words
387 {
388 local($name)=@_;
389
390 &function_begin($name,"");
391
392 &comment("");
393 $a="esi";
394 $b="edi";
395 $c="eax";
396 $r="ebx";
397 $tmp1="ecx";
398 $tmp2="edx";
399 $num="ebp";
400
401 &mov($r,&wparam(0)); # get r
402 &mov($a,&wparam(1)); # get a
403 &mov($b,&wparam(2)); # get b
404 &mov($num,&wparam(3)); # get num
405 &xor($c,$c); # clear carry
406 &and($num,0xfffffff8); # num / 8
407
408 &jz(&label("aw_finish"));
409
410 &set_label("aw_loop",0);
411 for ($i=0; $i<8; $i++)
412 {
413 &comment("Round $i");
414
415 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
416 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
417 &sub($tmp1,$c);
418 &mov($c,0);
419 &adc($c,$c);
420 &sub($tmp1,$tmp2);
421 &adc($c,0);
422 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
423 }
424
425 &comment("");
426 &add($a,32);
427 &add($b,32);
428 &add($r,32);
429 &sub($num,8);
430 &jnz(&label("aw_loop"));
431
432 &set_label("aw_finish",0);
433 &mov($num,&wparam(3)); # get num
434 &and($num,7);
435 &jz(&label("aw_end"));
436
437 for ($i=0; $i<7; $i++)
438 {
439 &comment("Tail Round $i");
440 &mov($tmp1,&DWP(0,$a,"",0)); # *a
441 &mov($tmp2,&DWP(0,$b,"",0));# *b
442 &sub($tmp1,$c);
443 &mov($c,0);
444 &adc($c,$c);
445 &sub($tmp1,$tmp2);
446 &adc($c,0);
447 &mov(&DWP(0,$r,"",0),$tmp1); # *r
448 &add($a, 4);
449 &add($b, 4);
450 &add($r, 4);
451 &dec($num) if ($i != 6);
452 &jz(&label("aw_end")) if ($i != 6);
453 }
454 &set_label("aw_end",0);
455
456 &cmp(&wparam(4),0);
457 &je(&label("pw_end"));
458
459 &mov($num,&wparam(4)); # get dl
460 &cmp($num,0);
461 &je(&label("pw_end"));
462 &jge(&label("pw_pos"));
463
464 &comment("pw_neg");
465 &mov($tmp2,0);
466 &sub($tmp2,$num);
467 &mov($num,$tmp2);
468 &and($num,0xfffffff8); # num / 8
469 &jz(&label("pw_neg_finish"));
470
471 &set_label("pw_neg_loop",0);
472 for ($i=0; $i<8; $i++)
473 {
474 &comment("dl<0 Round $i");
475
476 &mov($tmp1,0);
477 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
478 &sub($tmp1,$c);
479 &mov($c,0);
480 &adc($c,$c);
481 &sub($tmp1,$tmp2);
482 &adc($c,0);
483 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
484 }
485
486 &comment("");
487 &add($b,32);
488 &add($r,32);
489 &sub($num,8);
490 &jnz(&label("pw_neg_loop"));
491
492 &set_label("pw_neg_finish",0);
493 &mov($tmp2,&wparam(4)); # get dl
494 &mov($num,0);
495 &sub($num,$tmp2);
496 &and($num,7);
497 &jz(&label("pw_end"));
498
499 for ($i=0; $i<7; $i++)
500 {
501 &comment("dl<0 Tail Round $i");
502 &mov($tmp1,0);
503 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
504 &sub($tmp1,$c);
505 &mov($c,0);
506 &adc($c,$c);
507 &sub($tmp1,$tmp2);
508 &adc($c,0);
509 &dec($num) if ($i != 6);
510 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
511 &jz(&label("pw_end")) if ($i != 6);
512 }
513
514 &jmp(&label("pw_end"));
515
516 &set_label("pw_pos",0);
517
518 &and($num,0xfffffff8); # num / 8
519 &jz(&label("pw_pos_finish"));
520
521 &set_label("pw_pos_loop",0);
522
523 for ($i=0; $i<8; $i++)
524 {
525 &comment("dl>0 Round $i");
526
527 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
528 &sub($tmp1,$c);
529 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
530 &jnc(&label("pw_nc".$i));
531 }
532
533 &comment("");
534 &add($a,32);
535 &add($r,32);
536 &sub($num,8);
537 &jnz(&label("pw_pos_loop"));
538
539 &set_label("pw_pos_finish",0);
540 &mov($num,&wparam(4)); # get dl
541 &and($num,7);
542 &jz(&label("pw_end"));
543
544 for ($i=0; $i<7; $i++)
545 {
546 &comment("dl>0 Tail Round $i");
547 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
548 &sub($tmp1,$c);
549 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
550 &jnc(&label("pw_tail_nc".$i));
551 &dec($num) if ($i != 6);
552 &jz(&label("pw_end")) if ($i != 6);
553 }
554 &mov($c,1);
555 &jmp(&label("pw_end"));
556
557 &set_label("pw_nc_loop",0);
558 for ($i=0; $i<8; $i++)
559 {
560 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
561 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
562 &set_label("pw_nc".$i,0);
563 }
564
565 &comment("");
566 &add($a,32);
567 &add($r,32);
568 &sub($num,8);
569 &jnz(&label("pw_nc_loop"));
570
571 &mov($num,&wparam(4)); # get dl
572 &and($num,7);
573 &jz(&label("pw_nc_end"));
574
575 for ($i=0; $i<7; $i++)
576 {
577 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
578 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
579 &set_label("pw_tail_nc".$i,0);
580 &dec($num) if ($i != 6);
581 &jz(&label("pw_nc_end")) if ($i != 6);
582 }
583
584 &set_label("pw_nc_end",0);
585 &mov($c,0);
586
587 &set_label("pw_end",0);
588
589# &mov("eax",$c); # $c is "eax"
590
591 &function_end($name);
592 }
593
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/ia64.S b/src/lib/libcrypto/bn/asm/ia64.S
deleted file mode 100644
index 7b82b820e6..0000000000
--- a/src/lib/libcrypto/bn/asm/ia64.S
+++ /dev/null
@@ -1,1560 +0,0 @@
1.explicit
2.text
3.ident "ia64.S, Version 2.1"
4.ident "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
5
6//
7// ====================================================================
8// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
9// project.
10//
11// Rights for redistribution and usage in source and binary forms are
12// granted according to the OpenSSL license. Warranty of any kind is
13// disclaimed.
14// ====================================================================
15//
16// Version 2.x is Itanium2 re-tune. Few words about how Itanum2 is
17// different from Itanium to this module viewpoint. Most notably, is it
18// "wider" than Itanium? Can you experience loop scalability as
19// discussed in commentary sections? Not really:-( Itanium2 has 6
20// integer ALU ports, i.e. it's 2 ports wider, but it's not enough to
21// spin twice as fast, as I need 8 IALU ports. Amount of floating point
22// ports is the same, i.e. 2, while I need 4. In other words, to this
23// module Itanium2 remains effectively as "wide" as Itanium. Yet it's
24// essentially different in respect to this module, and a re-tune was
25// required. Well, because some intruction latencies has changed. Most
26// noticeably those intensively used:
27//
28// Itanium Itanium2
29// ldf8 9 6 L2 hit
30// ld8 2 1 L1 hit
31// getf 2 5
32// xma[->getf] 7[+1] 4[+0]
33// add[->st8] 1[+1] 1[+0]
34//
35// What does it mean? You might ratiocinate that the original code
36// should run just faster... Because sum of latencies is smaller...
37// Wrong! Note that getf latency increased. This means that if a loop is
38// scheduled for lower latency (as they were), then it will suffer from
39// stall condition and the code will therefore turn anti-scalable, e.g.
40// original bn_mul_words spun at 5*n or 2.5 times slower than expected
41// on Itanium2! What to do? Reschedule loops for Itanium2? But then
42// Itanium would exhibit anti-scalability. So I've chosen to reschedule
43// for worst latency for every instruction aiming for best *all-round*
44// performance.
45
46// Q. How much faster does it get?
47// A. Here is the output from 'openssl speed rsa dsa' for vanilla
48// 0.9.6a compiled with gcc version 2.96 20000731 (Red Hat
49// Linux 7.1 2.96-81):
50//
51// sign verify sign/s verify/s
52// rsa 512 bits 0.0036s 0.0003s 275.3 2999.2
53// rsa 1024 bits 0.0203s 0.0011s 49.3 894.1
54// rsa 2048 bits 0.1331s 0.0040s 7.5 250.9
55// rsa 4096 bits 0.9270s 0.0147s 1.1 68.1
56// sign verify sign/s verify/s
57// dsa 512 bits 0.0035s 0.0043s 288.3 234.8
58// dsa 1024 bits 0.0111s 0.0135s 90.0 74.2
59//
60// And here is similar output but for this assembler
61// implementation:-)
62//
63// sign verify sign/s verify/s
64// rsa 512 bits 0.0021s 0.0001s 549.4 9638.5
65// rsa 1024 bits 0.0055s 0.0002s 183.8 4481.1
66// rsa 2048 bits 0.0244s 0.0006s 41.4 1726.3
67// rsa 4096 bits 0.1295s 0.0018s 7.7 561.5
68// sign verify sign/s verify/s
69// dsa 512 bits 0.0012s 0.0013s 891.9 756.6
70// dsa 1024 bits 0.0023s 0.0028s 440.4 376.2
71//
72// Yes, you may argue that it's not fair comparison as it's
73// possible to craft the C implementation with BN_UMULT_HIGH
74// inline assembler macro. But of course! Here is the output
75// with the macro:
76//
77// sign verify sign/s verify/s
78// rsa 512 bits 0.0020s 0.0002s 495.0 6561.0
79// rsa 1024 bits 0.0086s 0.0004s 116.2 2235.7
80// rsa 2048 bits 0.0519s 0.0015s 19.3 667.3
81// rsa 4096 bits 0.3464s 0.0053s 2.9 187.7
82// sign verify sign/s verify/s
83// dsa 512 bits 0.0016s 0.0020s 613.1 510.5
84// dsa 1024 bits 0.0045s 0.0054s 221.0 183.9
85//
86// My code is still way faster, huh:-) And I believe that even
87// higher performance can be achieved. Note that as keys get
88// longer, performance gain is larger. Why? According to the
89// profiler there is another player in the field, namely
90// BN_from_montgomery consuming larger and larger portion of CPU
91// time as keysize decreases. I therefore consider putting effort
92// to assembler implementation of the following routine:
93//
94// void bn_mul_add_mont (BN_ULONG *rp,BN_ULONG *np,int nl,BN_ULONG n0)
95// {
96// int i,j;
97// BN_ULONG v;
98//
99// for (i=0; i<nl; i++)
100// {
101// v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
102// nrp++;
103// rp++;
104// if (((nrp[-1]+=v)&BN_MASK2) < v)
105// for (j=0; ((++nrp[j])&BN_MASK2) == 0; j++) ;
106// }
107// }
108//
109// It might as well be beneficial to implement even combaX
110// variants, as it appears as it can literally unleash the
111// performance (see comment section to bn_mul_comba8 below).
112//
113// And finally for your reference the output for 0.9.6a compiled
114// with SGIcc version 0.01.0-12 (keep in mind that for the moment
115// of this writing it's not possible to convince SGIcc to use
116// BN_UMULT_HIGH inline assembler macro, yet the code is fast,
117// i.e. for a compiler generated one:-):
118//
119// sign verify sign/s verify/s
120// rsa 512 bits 0.0022s 0.0002s 452.7 5894.3
121// rsa 1024 bits 0.0097s 0.0005s 102.7 2002.9
122// rsa 2048 bits 0.0578s 0.0017s 17.3 600.2
123// rsa 4096 bits 0.3838s 0.0061s 2.6 164.5
124// sign verify sign/s verify/s
125// dsa 512 bits 0.0018s 0.0022s 547.3 459.6
126// dsa 1024 bits 0.0051s 0.0062s 196.6 161.3
127//
128// Oh! Benchmarks were performed on 733MHz Lion-class Itanium
129// system running Redhat Linux 7.1 (very special thanks to Ray
130// McCaffity of Williams Communications for providing an account).
131//
132// Q. What's the heck with 'rum 1<<5' at the end of every function?
133// A. Well, by clearing the "upper FP registers written" bit of the
134// User Mask I want to excuse the kernel from preserving upper
135// (f32-f128) FP register bank over process context switch, thus
136// minimizing bus bandwidth consumption during the switch (i.e.
137// after PKI opration completes and the program is off doing
138// something else like bulk symmetric encryption). Having said
139// this, I also want to point out that it might be good idea
140// to compile the whole toolkit (as well as majority of the
141// programs for that matter) with -mfixed-range=f32-f127 command
142// line option. No, it doesn't prevent the compiler from writing
143// to upper bank, but at least discourages to do so. If you don't
144// like the idea you have the option to compile the module with
145// -Drum=nop.m in command line.
146//
147
148#if defined(_HPUX_SOURCE) && !defined(_LP64)
149#define ADDP addp4
150#else
151#define ADDP add
152#endif
153
154#if 1
155//
156// bn_[add|sub]_words routines.
157//
158// Loops are spinning in 2*(n+5) ticks on Itanuim (provided that the
159// data reside in L1 cache, i.e. 2 ticks away). It's possible to
160// compress the epilogue and get down to 2*n+6, but at the cost of
161// scalability (the neat feature of this implementation is that it
162// shall automagically spin in n+5 on "wider" IA-64 implementations:-)
163// I consider that the epilogue is short enough as it is to trade tiny
164// performance loss on Itanium for scalability.
165//
166// BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num)
167//
168.global bn_add_words#
169.proc bn_add_words#
170.align 64
171.skip 32 // makes the loop body aligned at 64-byte boundary
172bn_add_words:
173 .prologue
174 .fframe 0
175 .save ar.pfs,r2
176{ .mii; alloc r2=ar.pfs,4,12,0,16
177 cmp4.le p6,p0=r35,r0 };;
178{ .mfb; mov r8=r0 // return value
179(p6) br.ret.spnt.many b0 };;
180
181 .save ar.lc,r3
182{ .mib; sub r10=r35,r0,1
183 mov r3=ar.lc
184 brp.loop.imp .L_bn_add_words_ctop,.L_bn_add_words_cend-16
185 }
186 .body
187{ .mib; ADDP r14=0,r32 // rp
188 mov r9=pr };;
189{ .mii; ADDP r15=0,r33 // ap
190 mov ar.lc=r10
191 mov ar.ec=6 }
192{ .mib; ADDP r16=0,r34 // bp
193 mov pr.rot=1<<16 };;
194
195.L_bn_add_words_ctop:
196{ .mii; (p16) ld8 r32=[r16],8 // b=*(bp++)
197 (p18) add r39=r37,r34
198 (p19) cmp.ltu.unc p56,p0=r40,r38 }
199{ .mfb; (p0) nop.m 0x0
200 (p0) nop.f 0x0
201 (p0) nop.b 0x0 }
202{ .mii; (p16) ld8 r35=[r15],8 // a=*(ap++)
203 (p58) cmp.eq.or p57,p0=-1,r41 // (p20)
204 (p58) add r41=1,r41 } // (p20)
205{ .mfb; (p21) st8 [r14]=r42,8 // *(rp++)=r
206 (p0) nop.f 0x0
207 br.ctop.sptk .L_bn_add_words_ctop };;
208.L_bn_add_words_cend:
209
210{ .mii;
211(p59) add r8=1,r8 // return value
212 mov pr=r9,0x1ffff
213 mov ar.lc=r3 }
214{ .mbb; nop.b 0x0
215 br.ret.sptk.many b0 };;
216.endp bn_add_words#
217
218//
219// BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num)
220//
221.global bn_sub_words#
222.proc bn_sub_words#
223.align 64
224.skip 32 // makes the loop body aligned at 64-byte boundary
225bn_sub_words:
226 .prologue
227 .fframe 0
228 .save ar.pfs,r2
229{ .mii; alloc r2=ar.pfs,4,12,0,16
230 cmp4.le p6,p0=r35,r0 };;
231{ .mfb; mov r8=r0 // return value
232(p6) br.ret.spnt.many b0 };;
233
234 .save ar.lc,r3
235{ .mib; sub r10=r35,r0,1
236 mov r3=ar.lc
237 brp.loop.imp .L_bn_sub_words_ctop,.L_bn_sub_words_cend-16
238 }
239 .body
240{ .mib; ADDP r14=0,r32 // rp
241 mov r9=pr };;
242{ .mii; ADDP r15=0,r33 // ap
243 mov ar.lc=r10
244 mov ar.ec=6 }
245{ .mib; ADDP r16=0,r34 // bp
246 mov pr.rot=1<<16 };;
247
248.L_bn_sub_words_ctop:
249{ .mii; (p16) ld8 r32=[r16],8 // b=*(bp++)
250 (p18) sub r39=r37,r34
251 (p19) cmp.gtu.unc p56,p0=r40,r38 }
252{ .mfb; (p0) nop.m 0x0
253 (p0) nop.f 0x0
254 (p0) nop.b 0x0 }
255{ .mii; (p16) ld8 r35=[r15],8 // a=*(ap++)
256 (p58) cmp.eq.or p57,p0=0,r41 // (p20)
257 (p58) add r41=-1,r41 } // (p20)
258{ .mbb; (p21) st8 [r14]=r42,8 // *(rp++)=r
259 (p0) nop.b 0x0
260 br.ctop.sptk .L_bn_sub_words_ctop };;
261.L_bn_sub_words_cend:
262
263{ .mii;
264(p59) add r8=1,r8 // return value
265 mov pr=r9,0x1ffff
266 mov ar.lc=r3 }
267{ .mbb; nop.b 0x0
268 br.ret.sptk.many b0 };;
269.endp bn_sub_words#
270#endif
271
272#if 0
273#define XMA_TEMPTATION
274#endif
275
276#if 1
277//
278// BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
279//
280.global bn_mul_words#
281.proc bn_mul_words#
282.align 64
283.skip 32 // makes the loop body aligned at 64-byte boundary
284bn_mul_words:
285 .prologue
286 .fframe 0
287 .save ar.pfs,r2
288#ifdef XMA_TEMPTATION
289{ .mfi; alloc r2=ar.pfs,4,0,0,0 };;
290#else
291{ .mfi; alloc r2=ar.pfs,4,12,0,16 };;
292#endif
293{ .mib; mov r8=r0 // return value
294 cmp4.le p6,p0=r34,r0
295(p6) br.ret.spnt.many b0 };;
296
297 .save ar.lc,r3
298{ .mii; sub r10=r34,r0,1
299 mov r3=ar.lc
300 mov r9=pr };;
301
302 .body
303{ .mib; setf.sig f8=r35 // w
304 mov pr.rot=0x800001<<16
305 // ------^----- serves as (p50) at first (p27)
306 brp.loop.imp .L_bn_mul_words_ctop,.L_bn_mul_words_cend-16
307 }
308
309#ifndef XMA_TEMPTATION
310
311{ .mmi; ADDP r14=0,r32 // rp
312 ADDP r15=0,r33 // ap
313 mov ar.lc=r10 }
314{ .mmi; mov r40=0 // serves as r35 at first (p27)
315 mov ar.ec=13 };;
316
317// This loop spins in 2*(n+12) ticks. It's scheduled for data in Itanium
318// L2 cache (i.e. 9 ticks away) as floating point load/store instructions
319// bypass L1 cache and L2 latency is actually best-case scenario for
320// ldf8. The loop is not scalable and shall run in 2*(n+12) even on
321// "wider" IA-64 implementations. It's a trade-off here. n+24 loop
322// would give us ~5% in *overall* performance improvement on "wider"
323// IA-64, but would hurt Itanium for about same because of longer
324// epilogue. As it's a matter of few percents in either case I've
325// chosen to trade the scalability for development time (you can see
326// this very instruction sequence in bn_mul_add_words loop which in
327// turn is scalable).
328.L_bn_mul_words_ctop:
329{ .mfi; (p25) getf.sig r36=f52 // low
330 (p21) xmpy.lu f48=f37,f8
331 (p28) cmp.ltu p54,p50=r41,r39 }
332{ .mfi; (p16) ldf8 f32=[r15],8
333 (p21) xmpy.hu f40=f37,f8
334 (p0) nop.i 0x0 };;
335{ .mii; (p25) getf.sig r32=f44 // high
336 .pred.rel "mutex",p50,p54
337 (p50) add r40=r38,r35 // (p27)
338 (p54) add r40=r38,r35,1 } // (p27)
339{ .mfb; (p28) st8 [r14]=r41,8
340 (p0) nop.f 0x0
341 br.ctop.sptk .L_bn_mul_words_ctop };;
342.L_bn_mul_words_cend:
343
344{ .mii; nop.m 0x0
345.pred.rel "mutex",p51,p55
346(p51) add r8=r36,r0
347(p55) add r8=r36,r0,1 }
348{ .mfb; nop.m 0x0
349 nop.f 0x0
350 nop.b 0x0 }
351
352#else // XMA_TEMPTATION
353
354 setf.sig f37=r0 // serves as carry at (p18) tick
355 mov ar.lc=r10
356 mov ar.ec=5;;
357
358// Most of you examining this code very likely wonder why in the name
359// of Intel the following loop is commented out? Indeed, it looks so
360// neat that you find it hard to believe that it's something wrong
361// with it, right? The catch is that every iteration depends on the
362// result from previous one and the latter isn't available instantly.
363// The loop therefore spins at the latency of xma minus 1, or in other
364// words at 6*(n+4) ticks:-( Compare to the "production" loop above
365// that runs in 2*(n+11) where the low latency problem is worked around
366// by moving the dependency to one-tick latent interger ALU. Note that
367// "distance" between ldf8 and xma is not latency of ldf8, but the
368// *difference* between xma and ldf8 latencies.
369.L_bn_mul_words_ctop:
370{ .mfi; (p16) ldf8 f32=[r33],8
371 (p18) xma.hu f38=f34,f8,f39 }
372{ .mfb; (p20) stf8 [r32]=f37,8
373 (p18) xma.lu f35=f34,f8,f39
374 br.ctop.sptk .L_bn_mul_words_ctop };;
375.L_bn_mul_words_cend:
376
377 getf.sig r8=f41 // the return value
378
379#endif // XMA_TEMPTATION
380
381{ .mii; nop.m 0x0
382 mov pr=r9,0x1ffff
383 mov ar.lc=r3 }
384{ .mfb; rum 1<<5 // clear um.mfh
385 nop.f 0x0
386 br.ret.sptk.many b0 };;
387.endp bn_mul_words#
388#endif
389
390#if 1
391//
392// BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
393//
394.global bn_mul_add_words#
395.proc bn_mul_add_words#
396.align 64
397.skip 48 // makes the loop body aligned at 64-byte boundary
398bn_mul_add_words:
399 .prologue
400 .fframe 0
401 .save ar.pfs,r2
402 .save ar.lc,r3
403 .save pr,r9
404{ .mmi; alloc r2=ar.pfs,4,4,0,8
405 cmp4.le p6,p0=r34,r0
406 mov r3=ar.lc };;
407{ .mib; mov r8=r0 // return value
408 sub r10=r34,r0,1
409(p6) br.ret.spnt.many b0 };;
410
411 .body
412{ .mib; setf.sig f8=r35 // w
413 mov r9=pr
414 brp.loop.imp .L_bn_mul_add_words_ctop,.L_bn_mul_add_words_cend-16
415 }
416{ .mmi; ADDP r14=0,r32 // rp
417 ADDP r15=0,r33 // ap
418 mov ar.lc=r10 }
419{ .mii; ADDP r16=0,r32 // rp copy
420 mov pr.rot=0x2001<<16
421 // ------^----- serves as (p40) at first (p27)
422 mov ar.ec=11 };;
423
424// This loop spins in 3*(n+10) ticks on Itanium and in 2*(n+10) on
425// Itanium 2. Yes, unlike previous versions it scales:-) Previous
426// version was peforming *all* additions in IALU and was starving
427// for those even on Itanium 2. In this version one addition is
428// moved to FPU and is folded with multiplication. This is at cost
429// of propogating the result from previous call to this subroutine
430// to L2 cache... In other words negligible even for shorter keys.
431// *Overall* performance improvement [over previous version] varies
432// from 11 to 22 percent depending on key length.
433.L_bn_mul_add_words_ctop:
434.pred.rel "mutex",p40,p42
435{ .mfi; (p23) getf.sig r36=f45 // low
436 (p20) xma.lu f42=f36,f8,f50 // low
437 (p40) add r39=r39,r35 } // (p27)
438{ .mfi; (p16) ldf8 f32=[r15],8 // *(ap++)
439 (p20) xma.hu f36=f36,f8,f50 // high
440 (p42) add r39=r39,r35,1 };; // (p27)
441{ .mmi; (p24) getf.sig r32=f40 // high
442 (p16) ldf8 f46=[r16],8 // *(rp1++)
443 (p40) cmp.ltu p41,p39=r39,r35 } // (p27)
444{ .mib; (p26) st8 [r14]=r39,8 // *(rp2++)
445 (p42) cmp.leu p41,p39=r39,r35 // (p27)
446 br.ctop.sptk .L_bn_mul_add_words_ctop};;
447.L_bn_mul_add_words_cend:
448
449{ .mmi; .pred.rel "mutex",p40,p42
450(p40) add r8=r35,r0
451(p42) add r8=r35,r0,1
452 mov pr=r9,0x1ffff }
453{ .mib; rum 1<<5 // clear um.mfh
454 mov ar.lc=r3
455 br.ret.sptk.many b0 };;
456.endp bn_mul_add_words#
457#endif
458
459#if 1
460//
461// void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num)
462//
463.global bn_sqr_words#
464.proc bn_sqr_words#
465.align 64
466.skip 32 // makes the loop body aligned at 64-byte boundary
467bn_sqr_words:
468 .prologue
469 .fframe 0
470 .save ar.pfs,r2
471{ .mii; alloc r2=ar.pfs,3,0,0,0
472 sxt4 r34=r34 };;
473{ .mii; cmp.le p6,p0=r34,r0
474 mov r8=r0 } // return value
475{ .mfb; ADDP r32=0,r32
476 nop.f 0x0
477(p6) br.ret.spnt.many b0 };;
478
479 .save ar.lc,r3
480{ .mii; sub r10=r34,r0,1
481 mov r3=ar.lc
482 mov r9=pr };;
483
484 .body
485{ .mib; ADDP r33=0,r33
486 mov pr.rot=1<<16
487 brp.loop.imp .L_bn_sqr_words_ctop,.L_bn_sqr_words_cend-16
488 }
489{ .mii; add r34=8,r32
490 mov ar.lc=r10
491 mov ar.ec=18 };;
492
493// 2*(n+17) on Itanium, (n+17) on "wider" IA-64 implementations. It's
494// possible to compress the epilogue (I'm getting tired to write this
495// comment over and over) and get down to 2*n+16 at the cost of
496// scalability. The decision will very likely be reconsidered after the
497// benchmark program is profiled. I.e. if perfomance gain on Itanium
498// will appear larger than loss on "wider" IA-64, then the loop should
499// be explicitely split and the epilogue compressed.
500.L_bn_sqr_words_ctop:
501{ .mfi; (p16) ldf8 f32=[r33],8
502 (p25) xmpy.lu f42=f41,f41
503 (p0) nop.i 0x0 }
504{ .mib; (p33) stf8 [r32]=f50,16
505 (p0) nop.i 0x0
506 (p0) nop.b 0x0 }
507{ .mfi; (p0) nop.m 0x0
508 (p25) xmpy.hu f52=f41,f41
509 (p0) nop.i 0x0 }
510{ .mib; (p33) stf8 [r34]=f60,16
511 (p0) nop.i 0x0
512 br.ctop.sptk .L_bn_sqr_words_ctop };;
513.L_bn_sqr_words_cend:
514
515{ .mii; nop.m 0x0
516 mov pr=r9,0x1ffff
517 mov ar.lc=r3 }
518{ .mfb; rum 1<<5 // clear um.mfh
519 nop.f 0x0
520 br.ret.sptk.many b0 };;
521.endp bn_sqr_words#
522#endif
523
524#if 1
525// Apparently we win nothing by implementing special bn_sqr_comba8.
526// Yes, it is possible to reduce the number of multiplications by
527// almost factor of two, but then the amount of additions would
528// increase by factor of two (as we would have to perform those
529// otherwise performed by xma ourselves). Normally we would trade
530// anyway as multiplications are way more expensive, but not this
531// time... Multiplication kernel is fully pipelined and as we drain
532// one 128-bit multiplication result per clock cycle multiplications
533// are effectively as inexpensive as additions. Special implementation
534// might become of interest for "wider" IA-64 implementation as you'll
535// be able to get through the multiplication phase faster (there won't
536// be any stall issues as discussed in the commentary section below and
537// you therefore will be able to employ all 4 FP units)... But these
538// Itanium days it's simply too hard to justify the effort so I just
539// drop down to bn_mul_comba8 code:-)
540//
541// void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
542//
543.global bn_sqr_comba8#
544.proc bn_sqr_comba8#
545.align 64
546bn_sqr_comba8:
547 .prologue
548 .fframe 0
549 .save ar.pfs,r2
550#if defined(_HPUX_SOURCE) && !defined(_LP64)
551{ .mii; alloc r2=ar.pfs,2,1,0,0
552 addp4 r33=0,r33
553 addp4 r32=0,r32 };;
554{ .mii;
555#else
556{ .mii; alloc r2=ar.pfs,2,1,0,0
557#endif
558 mov r34=r33
559 add r14=8,r33 };;
560 .body
561{ .mii; add r17=8,r34
562 add r15=16,r33
563 add r18=16,r34 }
564{ .mfb; add r16=24,r33
565 br .L_cheat_entry_point8 };;
566.endp bn_sqr_comba8#
567#endif
568
569#if 1
570// I've estimated this routine to run in ~120 ticks, but in reality
571// (i.e. according to ar.itc) it takes ~160 ticks. Are those extra
572// cycles consumed for instructions fetch? Or did I misinterpret some
573// clause in Itanium µ-architecture manual? Comments are welcomed and
574// highly appreciated.
575//
576// On Itanium 2 it takes ~190 ticks. This is because of stalls on
577// result from getf.sig. I do nothing about it at this point for
578// reasons depicted below.
579//
580// However! It should be noted that even 160 ticks is darn good result
581// as it's over 10 (yes, ten, spelled as t-e-n) times faster than the
582// C version (compiled with gcc with inline assembler). I really
583// kicked compiler's butt here, didn't I? Yeah! This brings us to the
584// following statement. It's damn shame that this routine isn't called
585// very often nowadays! According to the profiler most CPU time is
586// consumed by bn_mul_add_words called from BN_from_montgomery. In
587// order to estimate what we're missing, I've compared the performance
588// of this routine against "traditional" implementation, i.e. against
589// following routine:
590//
591// void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
592// { r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
593// r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
594// r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
595// r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
596// r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
597// r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
598// r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
599// r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
600// }
601//
602// The one below is over 8 times faster than the one above:-( Even
603// more reasons to "combafy" bn_mul_add_mont...
604//
605// And yes, this routine really made me wish there were an optimizing
606// assembler! It also feels like it deserves a dedication.
607//
608// To my wife for being there and to my kids...
609//
610// void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
611//
612#define carry1 r14
613#define carry2 r15
614#define carry3 r34
615.global bn_mul_comba8#
616.proc bn_mul_comba8#
617.align 64
618bn_mul_comba8:
619 .prologue
620 .fframe 0
621 .save ar.pfs,r2
622#if defined(_HPUX_SOURCE) && !defined(_LP64)
623{ .mii; alloc r2=ar.pfs,3,0,0,0
624 addp4 r33=0,r33
625 addp4 r34=0,r34 };;
626{ .mii; addp4 r32=0,r32
627#else
628{ .mii; alloc r2=ar.pfs,3,0,0,0
629#endif
630 add r14=8,r33
631 add r17=8,r34 }
632 .body
633{ .mii; add r15=16,r33
634 add r18=16,r34
635 add r16=24,r33 }
636.L_cheat_entry_point8:
637{ .mmi; add r19=24,r34
638
639 ldf8 f32=[r33],32 };;
640
641{ .mmi; ldf8 f120=[r34],32
642 ldf8 f121=[r17],32 }
643{ .mmi; ldf8 f122=[r18],32
644 ldf8 f123=[r19],32 };;
645{ .mmi; ldf8 f124=[r34]
646 ldf8 f125=[r17] }
647{ .mmi; ldf8 f126=[r18]
648 ldf8 f127=[r19] }
649
650{ .mmi; ldf8 f33=[r14],32
651 ldf8 f34=[r15],32 }
652{ .mmi; ldf8 f35=[r16],32;;
653 ldf8 f36=[r33] }
654{ .mmi; ldf8 f37=[r14]
655 ldf8 f38=[r15] }
656{ .mfi; ldf8 f39=[r16]
657// -------\ Entering multiplier's heaven /-------
658// ------------\ /------------
659// -----------------\ /-----------------
660// ----------------------\/----------------------
661 xma.hu f41=f32,f120,f0 }
662{ .mfi; xma.lu f40=f32,f120,f0 };; // (*)
663{ .mfi; xma.hu f51=f32,f121,f0 }
664{ .mfi; xma.lu f50=f32,f121,f0 };;
665{ .mfi; xma.hu f61=f32,f122,f0 }
666{ .mfi; xma.lu f60=f32,f122,f0 };;
667{ .mfi; xma.hu f71=f32,f123,f0 }
668{ .mfi; xma.lu f70=f32,f123,f0 };;
669{ .mfi; xma.hu f81=f32,f124,f0 }
670{ .mfi; xma.lu f80=f32,f124,f0 };;
671{ .mfi; xma.hu f91=f32,f125,f0 }
672{ .mfi; xma.lu f90=f32,f125,f0 };;
673{ .mfi; xma.hu f101=f32,f126,f0 }
674{ .mfi; xma.lu f100=f32,f126,f0 };;
675{ .mfi; xma.hu f111=f32,f127,f0 }
676{ .mfi; xma.lu f110=f32,f127,f0 };;//
677// (*) You can argue that splitting at every second bundle would
678// prevent "wider" IA-64 implementations from achieving the peak
679// performance. Well, not really... The catch is that if you
680// intend to keep 4 FP units busy by splitting at every fourth
681// bundle and thus perform these 16 multiplications in 4 ticks,
682// the first bundle *below* would stall because the result from
683// the first xma bundle *above* won't be available for another 3
684// ticks (if not more, being an optimist, I assume that "wider"
685// implementation will have same latency:-). This stall will hold
686// you back and the performance would be as if every second bundle
687// were split *anyway*...
688{ .mfi; getf.sig r16=f40
689 xma.hu f42=f33,f120,f41
690 add r33=8,r32 }
691{ .mfi; xma.lu f41=f33,f120,f41 };;
692{ .mfi; getf.sig r24=f50
693 xma.hu f52=f33,f121,f51 }
694{ .mfi; xma.lu f51=f33,f121,f51 };;
695{ .mfi; st8 [r32]=r16,16
696 xma.hu f62=f33,f122,f61 }
697{ .mfi; xma.lu f61=f33,f122,f61 };;
698{ .mfi; xma.hu f72=f33,f123,f71 }
699{ .mfi; xma.lu f71=f33,f123,f71 };;
700{ .mfi; xma.hu f82=f33,f124,f81 }
701{ .mfi; xma.lu f81=f33,f124,f81 };;
702{ .mfi; xma.hu f92=f33,f125,f91 }
703{ .mfi; xma.lu f91=f33,f125,f91 };;
704{ .mfi; xma.hu f102=f33,f126,f101 }
705{ .mfi; xma.lu f101=f33,f126,f101 };;
706{ .mfi; xma.hu f112=f33,f127,f111 }
707{ .mfi; xma.lu f111=f33,f127,f111 };;//
708//-------------------------------------------------//
709{ .mfi; getf.sig r25=f41
710 xma.hu f43=f34,f120,f42 }
711{ .mfi; xma.lu f42=f34,f120,f42 };;
712{ .mfi; getf.sig r16=f60
713 xma.hu f53=f34,f121,f52 }
714{ .mfi; xma.lu f52=f34,f121,f52 };;
715{ .mfi; getf.sig r17=f51
716 xma.hu f63=f34,f122,f62
717 add r25=r25,r24 }
718{ .mfi; xma.lu f62=f34,f122,f62
719 mov carry1=0 };;
720{ .mfi; cmp.ltu p6,p0=r25,r24
721 xma.hu f73=f34,f123,f72 }
722{ .mfi; xma.lu f72=f34,f123,f72 };;
723{ .mfi; st8 [r33]=r25,16
724 xma.hu f83=f34,f124,f82
725(p6) add carry1=1,carry1 }
726{ .mfi; xma.lu f82=f34,f124,f82 };;
727{ .mfi; xma.hu f93=f34,f125,f92 }
728{ .mfi; xma.lu f92=f34,f125,f92 };;
729{ .mfi; xma.hu f103=f34,f126,f102 }
730{ .mfi; xma.lu f102=f34,f126,f102 };;
731{ .mfi; xma.hu f113=f34,f127,f112 }
732{ .mfi; xma.lu f112=f34,f127,f112 };;//
733//-------------------------------------------------//
734{ .mfi; getf.sig r18=f42
735 xma.hu f44=f35,f120,f43
736 add r17=r17,r16 }
737{ .mfi; xma.lu f43=f35,f120,f43 };;
738{ .mfi; getf.sig r24=f70
739 xma.hu f54=f35,f121,f53 }
740{ .mfi; mov carry2=0
741 xma.lu f53=f35,f121,f53 };;
742{ .mfi; getf.sig r25=f61
743 xma.hu f64=f35,f122,f63
744 cmp.ltu p7,p0=r17,r16 }
745{ .mfi; add r18=r18,r17
746 xma.lu f63=f35,f122,f63 };;
747{ .mfi; getf.sig r26=f52
748 xma.hu f74=f35,f123,f73
749(p7) add carry2=1,carry2 }
750{ .mfi; cmp.ltu p7,p0=r18,r17
751 xma.lu f73=f35,f123,f73
752 add r18=r18,carry1 };;
753{ .mfi;
754 xma.hu f84=f35,f124,f83
755(p7) add carry2=1,carry2 }
756{ .mfi; cmp.ltu p7,p0=r18,carry1
757 xma.lu f83=f35,f124,f83 };;
758{ .mfi; st8 [r32]=r18,16
759 xma.hu f94=f35,f125,f93
760(p7) add carry2=1,carry2 }
761{ .mfi; xma.lu f93=f35,f125,f93 };;
762{ .mfi; xma.hu f104=f35,f126,f103 }
763{ .mfi; xma.lu f103=f35,f126,f103 };;
764{ .mfi; xma.hu f114=f35,f127,f113 }
765{ .mfi; mov carry1=0
766 xma.lu f113=f35,f127,f113
767 add r25=r25,r24 };;//
768//-------------------------------------------------//
769{ .mfi; getf.sig r27=f43
770 xma.hu f45=f36,f120,f44
771 cmp.ltu p6,p0=r25,r24 }
772{ .mfi; xma.lu f44=f36,f120,f44
773 add r26=r26,r25 };;
774{ .mfi; getf.sig r16=f80
775 xma.hu f55=f36,f121,f54
776(p6) add carry1=1,carry1 }
777{ .mfi; xma.lu f54=f36,f121,f54 };;
778{ .mfi; getf.sig r17=f71
779 xma.hu f65=f36,f122,f64
780 cmp.ltu p6,p0=r26,r25 }
781{ .mfi; xma.lu f64=f36,f122,f64
782 add r27=r27,r26 };;
783{ .mfi; getf.sig r18=f62
784 xma.hu f75=f36,f123,f74
785(p6) add carry1=1,carry1 }
786{ .mfi; cmp.ltu p6,p0=r27,r26
787 xma.lu f74=f36,f123,f74
788 add r27=r27,carry2 };;
789{ .mfi; getf.sig r19=f53
790 xma.hu f85=f36,f124,f84
791(p6) add carry1=1,carry1 }
792{ .mfi; xma.lu f84=f36,f124,f84
793 cmp.ltu p6,p0=r27,carry2 };;
794{ .mfi; st8 [r33]=r27,16
795 xma.hu f95=f36,f125,f94
796(p6) add carry1=1,carry1 }
797{ .mfi; xma.lu f94=f36,f125,f94 };;
798{ .mfi; xma.hu f105=f36,f126,f104 }
799{ .mfi; mov carry2=0
800 xma.lu f104=f36,f126,f104
801 add r17=r17,r16 };;
802{ .mfi; xma.hu f115=f36,f127,f114
803 cmp.ltu p7,p0=r17,r16 }
804{ .mfi; xma.lu f114=f36,f127,f114
805 add r18=r18,r17 };;//
806//-------------------------------------------------//
807{ .mfi; getf.sig r20=f44
808 xma.hu f46=f37,f120,f45
809(p7) add carry2=1,carry2 }
810{ .mfi; cmp.ltu p7,p0=r18,r17
811 xma.lu f45=f37,f120,f45
812 add r19=r19,r18 };;
813{ .mfi; getf.sig r24=f90
814 xma.hu f56=f37,f121,f55 }
815{ .mfi; xma.lu f55=f37,f121,f55 };;
816{ .mfi; getf.sig r25=f81
817 xma.hu f66=f37,f122,f65
818(p7) add carry2=1,carry2 }
819{ .mfi; cmp.ltu p7,p0=r19,r18
820 xma.lu f65=f37,f122,f65
821 add r20=r20,r19 };;
822{ .mfi; getf.sig r26=f72
823 xma.hu f76=f37,f123,f75
824(p7) add carry2=1,carry2 }
825{ .mfi; cmp.ltu p7,p0=r20,r19
826 xma.lu f75=f37,f123,f75
827 add r20=r20,carry1 };;
828{ .mfi; getf.sig r27=f63
829 xma.hu f86=f37,f124,f85
830(p7) add carry2=1,carry2 }
831{ .mfi; xma.lu f85=f37,f124,f85
832 cmp.ltu p7,p0=r20,carry1 };;
833{ .mfi; getf.sig r28=f54
834 xma.hu f96=f37,f125,f95
835(p7) add carry2=1,carry2 }
836{ .mfi; st8 [r32]=r20,16
837 xma.lu f95=f37,f125,f95 };;
838{ .mfi; xma.hu f106=f37,f126,f105 }
839{ .mfi; mov carry1=0
840 xma.lu f105=f37,f126,f105
841 add r25=r25,r24 };;
842{ .mfi; xma.hu f116=f37,f127,f115
843 cmp.ltu p6,p0=r25,r24 }
844{ .mfi; xma.lu f115=f37,f127,f115
845 add r26=r26,r25 };;//
846//-------------------------------------------------//
847{ .mfi; getf.sig r29=f45
848 xma.hu f47=f38,f120,f46
849(p6) add carry1=1,carry1 }
850{ .mfi; cmp.ltu p6,p0=r26,r25
851 xma.lu f46=f38,f120,f46
852 add r27=r27,r26 };;
853{ .mfi; getf.sig r16=f100
854 xma.hu f57=f38,f121,f56
855(p6) add carry1=1,carry1 }
856{ .mfi; cmp.ltu p6,p0=r27,r26
857 xma.lu f56=f38,f121,f56
858 add r28=r28,r27 };;
859{ .mfi; getf.sig r17=f91
860 xma.hu f67=f38,f122,f66
861(p6) add carry1=1,carry1 }
862{ .mfi; cmp.ltu p6,p0=r28,r27
863 xma.lu f66=f38,f122,f66
864 add r29=r29,r28 };;
865{ .mfi; getf.sig r18=f82
866 xma.hu f77=f38,f123,f76
867(p6) add carry1=1,carry1 }
868{ .mfi; cmp.ltu p6,p0=r29,r28
869 xma.lu f76=f38,f123,f76
870 add r29=r29,carry2 };;
871{ .mfi; getf.sig r19=f73
872 xma.hu f87=f38,f124,f86
873(p6) add carry1=1,carry1 }
874{ .mfi; xma.lu f86=f38,f124,f86
875 cmp.ltu p6,p0=r29,carry2 };;
876{ .mfi; getf.sig r20=f64
877 xma.hu f97=f38,f125,f96
878(p6) add carry1=1,carry1 }
879{ .mfi; st8 [r33]=r29,16
880 xma.lu f96=f38,f125,f96 };;
881{ .mfi; getf.sig r21=f55
882 xma.hu f107=f38,f126,f106 }
883{ .mfi; mov carry2=0
884 xma.lu f106=f38,f126,f106
885 add r17=r17,r16 };;
886{ .mfi; xma.hu f117=f38,f127,f116
887 cmp.ltu p7,p0=r17,r16 }
888{ .mfi; xma.lu f116=f38,f127,f116
889 add r18=r18,r17 };;//
890//-------------------------------------------------//
891{ .mfi; getf.sig r22=f46
892 xma.hu f48=f39,f120,f47
893(p7) add carry2=1,carry2 }
894{ .mfi; cmp.ltu p7,p0=r18,r17
895 xma.lu f47=f39,f120,f47
896 add r19=r19,r18 };;
897{ .mfi; getf.sig r24=f110
898 xma.hu f58=f39,f121,f57
899(p7) add carry2=1,carry2 }
900{ .mfi; cmp.ltu p7,p0=r19,r18
901 xma.lu f57=f39,f121,f57
902 add r20=r20,r19 };;
903{ .mfi; getf.sig r25=f101
904 xma.hu f68=f39,f122,f67
905(p7) add carry2=1,carry2 }
906{ .mfi; cmp.ltu p7,p0=r20,r19
907 xma.lu f67=f39,f122,f67
908 add r21=r21,r20 };;
909{ .mfi; getf.sig r26=f92
910 xma.hu f78=f39,f123,f77
911(p7) add carry2=1,carry2 }
912{ .mfi; cmp.ltu p7,p0=r21,r20
913 xma.lu f77=f39,f123,f77
914 add r22=r22,r21 };;
915{ .mfi; getf.sig r27=f83
916 xma.hu f88=f39,f124,f87
917(p7) add carry2=1,carry2 }
918{ .mfi; cmp.ltu p7,p0=r22,r21
919 xma.lu f87=f39,f124,f87
920 add r22=r22,carry1 };;
921{ .mfi; getf.sig r28=f74
922 xma.hu f98=f39,f125,f97
923(p7) add carry2=1,carry2 }
924{ .mfi; xma.lu f97=f39,f125,f97
925 cmp.ltu p7,p0=r22,carry1 };;
926{ .mfi; getf.sig r29=f65
927 xma.hu f108=f39,f126,f107
928(p7) add carry2=1,carry2 }
929{ .mfi; st8 [r32]=r22,16
930 xma.lu f107=f39,f126,f107 };;
931{ .mfi; getf.sig r30=f56
932 xma.hu f118=f39,f127,f117 }
933{ .mfi; xma.lu f117=f39,f127,f117 };;//
934//-------------------------------------------------//
935// Leaving muliplier's heaven... Quite a ride, huh?
936
937{ .mii; getf.sig r31=f47
938 add r25=r25,r24
939 mov carry1=0 };;
940{ .mii; getf.sig r16=f111
941 cmp.ltu p6,p0=r25,r24
942 add r26=r26,r25 };;
943{ .mfb; getf.sig r17=f102 }
944{ .mii;
945(p6) add carry1=1,carry1
946 cmp.ltu p6,p0=r26,r25
947 add r27=r27,r26 };;
948{ .mfb; nop.m 0x0 }
949{ .mii;
950(p6) add carry1=1,carry1
951 cmp.ltu p6,p0=r27,r26
952 add r28=r28,r27 };;
953{ .mii; getf.sig r18=f93
954 add r17=r17,r16
955 mov carry3=0 }
956{ .mii;
957(p6) add carry1=1,carry1
958 cmp.ltu p6,p0=r28,r27
959 add r29=r29,r28 };;
960{ .mii; getf.sig r19=f84
961 cmp.ltu p7,p0=r17,r16 }
962{ .mii;
963(p6) add carry1=1,carry1
964 cmp.ltu p6,p0=r29,r28
965 add r30=r30,r29 };;
966{ .mii; getf.sig r20=f75
967 add r18=r18,r17 }
968{ .mii;
969(p6) add carry1=1,carry1
970 cmp.ltu p6,p0=r30,r29
971 add r31=r31,r30 };;
972{ .mfb; getf.sig r21=f66 }
973{ .mii; (p7) add carry3=1,carry3
974 cmp.ltu p7,p0=r18,r17
975 add r19=r19,r18 }
976{ .mfb; nop.m 0x0 }
977{ .mii;
978(p6) add carry1=1,carry1
979 cmp.ltu p6,p0=r31,r30
980 add r31=r31,carry2 };;
981{ .mfb; getf.sig r22=f57 }
982{ .mii; (p7) add carry3=1,carry3
983 cmp.ltu p7,p0=r19,r18
984 add r20=r20,r19 }
985{ .mfb; nop.m 0x0 }
986{ .mii;
987(p6) add carry1=1,carry1
988 cmp.ltu p6,p0=r31,carry2 };;
989{ .mfb; getf.sig r23=f48 }
990{ .mii; (p7) add carry3=1,carry3
991 cmp.ltu p7,p0=r20,r19
992 add r21=r21,r20 }
993{ .mii;
994(p6) add carry1=1,carry1 }
995{ .mfb; st8 [r33]=r31,16 };;
996
997{ .mfb; getf.sig r24=f112 }
998{ .mii; (p7) add carry3=1,carry3
999 cmp.ltu p7,p0=r21,r20
1000 add r22=r22,r21 };;
1001{ .mfb; getf.sig r25=f103 }
1002{ .mii; (p7) add carry3=1,carry3
1003 cmp.ltu p7,p0=r22,r21
1004 add r23=r23,r22 };;
1005{ .mfb; getf.sig r26=f94 }
1006{ .mii; (p7) add carry3=1,carry3
1007 cmp.ltu p7,p0=r23,r22
1008 add r23=r23,carry1 };;
1009{ .mfb; getf.sig r27=f85 }
1010{ .mii; (p7) add carry3=1,carry3
1011 cmp.ltu p7,p8=r23,carry1};;
1012{ .mii; getf.sig r28=f76
1013 add r25=r25,r24
1014 mov carry1=0 }
1015{ .mii; st8 [r32]=r23,16
1016 (p7) add carry2=1,carry3
1017 (p8) add carry2=0,carry3 };;
1018
1019{ .mfb; nop.m 0x0 }
1020{ .mii; getf.sig r29=f67
1021 cmp.ltu p6,p0=r25,r24
1022 add r26=r26,r25 };;
1023{ .mfb; getf.sig r30=f58 }
1024{ .mii;
1025(p6) add carry1=1,carry1
1026 cmp.ltu p6,p0=r26,r25
1027 add r27=r27,r26 };;
1028{ .mfb; getf.sig r16=f113 }
1029{ .mii;
1030(p6) add carry1=1,carry1
1031 cmp.ltu p6,p0=r27,r26
1032 add r28=r28,r27 };;
1033{ .mfb; getf.sig r17=f104 }
1034{ .mii;
1035(p6) add carry1=1,carry1
1036 cmp.ltu p6,p0=r28,r27
1037 add r29=r29,r28 };;
1038{ .mfb; getf.sig r18=f95 }
1039{ .mii;
1040(p6) add carry1=1,carry1
1041 cmp.ltu p6,p0=r29,r28
1042 add r30=r30,r29 };;
1043{ .mii; getf.sig r19=f86
1044 add r17=r17,r16
1045 mov carry3=0 }
1046{ .mii;
1047(p6) add carry1=1,carry1
1048 cmp.ltu p6,p0=r30,r29
1049 add r30=r30,carry2 };;
1050{ .mii; getf.sig r20=f77
1051 cmp.ltu p7,p0=r17,r16
1052 add r18=r18,r17 }
1053{ .mii;
1054(p6) add carry1=1,carry1
1055 cmp.ltu p6,p0=r30,carry2 };;
1056{ .mfb; getf.sig r21=f68 }
1057{ .mii; st8 [r33]=r30,16
1058(p6) add carry1=1,carry1 };;
1059
1060{ .mfb; getf.sig r24=f114 }
1061{ .mii; (p7) add carry3=1,carry3
1062 cmp.ltu p7,p0=r18,r17
1063 add r19=r19,r18 };;
1064{ .mfb; getf.sig r25=f105 }
1065{ .mii; (p7) add carry3=1,carry3
1066 cmp.ltu p7,p0=r19,r18
1067 add r20=r20,r19 };;
1068{ .mfb; getf.sig r26=f96 }
1069{ .mii; (p7) add carry3=1,carry3
1070 cmp.ltu p7,p0=r20,r19
1071 add r21=r21,r20 };;
1072{ .mfb; getf.sig r27=f87 }
1073{ .mii; (p7) add carry3=1,carry3
1074 cmp.ltu p7,p0=r21,r20
1075 add r21=r21,carry1 };;
1076{ .mib; getf.sig r28=f78
1077 add r25=r25,r24 }
1078{ .mib; (p7) add carry3=1,carry3
1079 cmp.ltu p7,p8=r21,carry1};;
1080{ .mii; st8 [r32]=r21,16
1081 (p7) add carry2=1,carry3
1082 (p8) add carry2=0,carry3 }
1083
1084{ .mii; mov carry1=0
1085 cmp.ltu p6,p0=r25,r24
1086 add r26=r26,r25 };;
1087{ .mfb; getf.sig r16=f115 }
1088{ .mii;
1089(p6) add carry1=1,carry1
1090 cmp.ltu p6,p0=r26,r25
1091 add r27=r27,r26 };;
1092{ .mfb; getf.sig r17=f106 }
1093{ .mii;
1094(p6) add carry1=1,carry1
1095 cmp.ltu p6,p0=r27,r26
1096 add r28=r28,r27 };;
1097{ .mfb; getf.sig r18=f97 }
1098{ .mii;
1099(p6) add carry1=1,carry1
1100 cmp.ltu p6,p0=r28,r27
1101 add r28=r28,carry2 };;
1102{ .mib; getf.sig r19=f88
1103 add r17=r17,r16 }
1104{ .mib;
1105(p6) add carry1=1,carry1
1106 cmp.ltu p6,p0=r28,carry2 };;
1107{ .mii; st8 [r33]=r28,16
1108(p6) add carry1=1,carry1 }
1109
1110{ .mii; mov carry2=0
1111 cmp.ltu p7,p0=r17,r16
1112 add r18=r18,r17 };;
1113{ .mfb; getf.sig r24=f116 }
1114{ .mii; (p7) add carry2=1,carry2
1115 cmp.ltu p7,p0=r18,r17
1116 add r19=r19,r18 };;
1117{ .mfb; getf.sig r25=f107 }
1118{ .mii; (p7) add carry2=1,carry2
1119 cmp.ltu p7,p0=r19,r18
1120 add r19=r19,carry1 };;
1121{ .mfb; getf.sig r26=f98 }
1122{ .mii; (p7) add carry2=1,carry2
1123 cmp.ltu p7,p0=r19,carry1};;
1124{ .mii; st8 [r32]=r19,16
1125 (p7) add carry2=1,carry2 }
1126
1127{ .mfb; add r25=r25,r24 };;
1128
1129{ .mfb; getf.sig r16=f117 }
1130{ .mii; mov carry1=0
1131 cmp.ltu p6,p0=r25,r24
1132 add r26=r26,r25 };;
1133{ .mfb; getf.sig r17=f108 }
1134{ .mii;
1135(p6) add carry1=1,carry1
1136 cmp.ltu p6,p0=r26,r25
1137 add r26=r26,carry2 };;
1138{ .mfb; nop.m 0x0 }
1139{ .mii;
1140(p6) add carry1=1,carry1
1141 cmp.ltu p6,p0=r26,carry2 };;
1142{ .mii; st8 [r33]=r26,16
1143(p6) add carry1=1,carry1 }
1144
1145{ .mfb; add r17=r17,r16 };;
1146{ .mfb; getf.sig r24=f118 }
1147{ .mii; mov carry2=0
1148 cmp.ltu p7,p0=r17,r16
1149 add r17=r17,carry1 };;
1150{ .mii; (p7) add carry2=1,carry2
1151 cmp.ltu p7,p0=r17,carry1};;
1152{ .mii; st8 [r32]=r17
1153 (p7) add carry2=1,carry2 };;
1154{ .mfb; add r24=r24,carry2 };;
1155{ .mib; st8 [r33]=r24 }
1156
1157{ .mib; rum 1<<5 // clear um.mfh
1158 br.ret.sptk.many b0 };;
1159.endp bn_mul_comba8#
1160#undef carry3
1161#undef carry2
1162#undef carry1
1163#endif
1164
1165#if 1
1166// It's possible to make it faster (see comment to bn_sqr_comba8), but
1167// I reckon it doesn't worth the effort. Basically because the routine
1168// (actually both of them) practically never called... So I just play
1169// same trick as with bn_sqr_comba8.
1170//
1171// void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
1172//
1173.global bn_sqr_comba4#
1174.proc bn_sqr_comba4#
1175.align 64
1176bn_sqr_comba4:
1177 .prologue
1178 .fframe 0
1179 .save ar.pfs,r2
1180#if defined(_HPUX_SOURCE) && !defined(_LP64)
1181{ .mii; alloc r2=ar.pfs,2,1,0,0
1182 addp4 r32=0,r32
1183 addp4 r33=0,r33 };;
1184{ .mii;
1185#else
1186{ .mii; alloc r2=ar.pfs,2,1,0,0
1187#endif
1188 mov r34=r33
1189 add r14=8,r33 };;
1190 .body
1191{ .mii; add r17=8,r34
1192 add r15=16,r33
1193 add r18=16,r34 }
1194{ .mfb; add r16=24,r33
1195 br .L_cheat_entry_point4 };;
1196.endp bn_sqr_comba4#
1197#endif
1198
1199#if 1
1200// Runs in ~115 cycles and ~4.5 times faster than C. Well, whatever...
1201//
1202// void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1203//
1204#define carry1 r14
1205#define carry2 r15
1206.global bn_mul_comba4#
1207.proc bn_mul_comba4#
1208.align 64
1209bn_mul_comba4:
1210 .prologue
1211 .fframe 0
1212 .save ar.pfs,r2
1213#if defined(_HPUX_SOURCE) && !defined(_LP64)
1214{ .mii; alloc r2=ar.pfs,3,0,0,0
1215 addp4 r33=0,r33
1216 addp4 r34=0,r34 };;
1217{ .mii; addp4 r32=0,r32
1218#else
1219{ .mii; alloc r2=ar.pfs,3,0,0,0
1220#endif
1221 add r14=8,r33
1222 add r17=8,r34 }
1223 .body
1224{ .mii; add r15=16,r33
1225 add r18=16,r34
1226 add r16=24,r33 };;
1227.L_cheat_entry_point4:
1228{ .mmi; add r19=24,r34
1229
1230 ldf8 f32=[r33] }
1231
1232{ .mmi; ldf8 f120=[r34]
1233 ldf8 f121=[r17] };;
1234{ .mmi; ldf8 f122=[r18]
1235 ldf8 f123=[r19] }
1236
1237{ .mmi; ldf8 f33=[r14]
1238 ldf8 f34=[r15] }
1239{ .mfi; ldf8 f35=[r16]
1240
1241 xma.hu f41=f32,f120,f0 }
1242{ .mfi; xma.lu f40=f32,f120,f0 };;
1243{ .mfi; xma.hu f51=f32,f121,f0 }
1244{ .mfi; xma.lu f50=f32,f121,f0 };;
1245{ .mfi; xma.hu f61=f32,f122,f0 }
1246{ .mfi; xma.lu f60=f32,f122,f0 };;
1247{ .mfi; xma.hu f71=f32,f123,f0 }
1248{ .mfi; xma.lu f70=f32,f123,f0 };;//
1249// Major stall takes place here, and 3 more places below. Result from
1250// first xma is not available for another 3 ticks.
1251{ .mfi; getf.sig r16=f40
1252 xma.hu f42=f33,f120,f41
1253 add r33=8,r32 }
1254{ .mfi; xma.lu f41=f33,f120,f41 };;
1255{ .mfi; getf.sig r24=f50
1256 xma.hu f52=f33,f121,f51 }
1257{ .mfi; xma.lu f51=f33,f121,f51 };;
1258{ .mfi; st8 [r32]=r16,16
1259 xma.hu f62=f33,f122,f61 }
1260{ .mfi; xma.lu f61=f33,f122,f61 };;
1261{ .mfi; xma.hu f72=f33,f123,f71 }
1262{ .mfi; xma.lu f71=f33,f123,f71 };;//
1263//-------------------------------------------------//
1264{ .mfi; getf.sig r25=f41
1265 xma.hu f43=f34,f120,f42 }
1266{ .mfi; xma.lu f42=f34,f120,f42 };;
1267{ .mfi; getf.sig r16=f60
1268 xma.hu f53=f34,f121,f52 }
1269{ .mfi; xma.lu f52=f34,f121,f52 };;
1270{ .mfi; getf.sig r17=f51
1271 xma.hu f63=f34,f122,f62
1272 add r25=r25,r24 }
1273{ .mfi; mov carry1=0
1274 xma.lu f62=f34,f122,f62 };;
1275{ .mfi; st8 [r33]=r25,16
1276 xma.hu f73=f34,f123,f72
1277 cmp.ltu p6,p0=r25,r24 }
1278{ .mfi; xma.lu f72=f34,f123,f72 };;//
1279//-------------------------------------------------//
1280{ .mfi; getf.sig r18=f42
1281 xma.hu f44=f35,f120,f43
1282(p6) add carry1=1,carry1 }
1283{ .mfi; add r17=r17,r16
1284 xma.lu f43=f35,f120,f43
1285 mov carry2=0 };;
1286{ .mfi; getf.sig r24=f70
1287 xma.hu f54=f35,f121,f53
1288 cmp.ltu p7,p0=r17,r16 }
1289{ .mfi; xma.lu f53=f35,f121,f53 };;
1290{ .mfi; getf.sig r25=f61
1291 xma.hu f64=f35,f122,f63
1292 add r18=r18,r17 }
1293{ .mfi; xma.lu f63=f35,f122,f63
1294(p7) add carry2=1,carry2 };;
1295{ .mfi; getf.sig r26=f52
1296 xma.hu f74=f35,f123,f73
1297 cmp.ltu p7,p0=r18,r17 }
1298{ .mfi; xma.lu f73=f35,f123,f73
1299 add r18=r18,carry1 };;
1300//-------------------------------------------------//
1301{ .mii; st8 [r32]=r18,16
1302(p7) add carry2=1,carry2
1303 cmp.ltu p7,p0=r18,carry1 };;
1304
1305{ .mfi; getf.sig r27=f43 // last major stall
1306(p7) add carry2=1,carry2 };;
1307{ .mii; getf.sig r16=f71
1308 add r25=r25,r24
1309 mov carry1=0 };;
1310{ .mii; getf.sig r17=f62
1311 cmp.ltu p6,p0=r25,r24
1312 add r26=r26,r25 };;
1313{ .mii;
1314(p6) add carry1=1,carry1
1315 cmp.ltu p6,p0=r26,r25
1316 add r27=r27,r26 };;
1317{ .mii;
1318(p6) add carry1=1,carry1
1319 cmp.ltu p6,p0=r27,r26
1320 add r27=r27,carry2 };;
1321{ .mii; getf.sig r18=f53
1322(p6) add carry1=1,carry1
1323 cmp.ltu p6,p0=r27,carry2 };;
1324{ .mfi; st8 [r33]=r27,16
1325(p6) add carry1=1,carry1 }
1326
1327{ .mii; getf.sig r19=f44
1328 add r17=r17,r16
1329 mov carry2=0 };;
1330{ .mii; getf.sig r24=f72
1331 cmp.ltu p7,p0=r17,r16
1332 add r18=r18,r17 };;
1333{ .mii; (p7) add carry2=1,carry2
1334 cmp.ltu p7,p0=r18,r17
1335 add r19=r19,r18 };;
1336{ .mii; (p7) add carry2=1,carry2
1337 cmp.ltu p7,p0=r19,r18
1338 add r19=r19,carry1 };;
1339{ .mii; getf.sig r25=f63
1340 (p7) add carry2=1,carry2
1341 cmp.ltu p7,p0=r19,carry1};;
1342{ .mii; st8 [r32]=r19,16
1343 (p7) add carry2=1,carry2 }
1344
1345{ .mii; getf.sig r26=f54
1346 add r25=r25,r24
1347 mov carry1=0 };;
1348{ .mii; getf.sig r16=f73
1349 cmp.ltu p6,p0=r25,r24
1350 add r26=r26,r25 };;
1351{ .mii;
1352(p6) add carry1=1,carry1
1353 cmp.ltu p6,p0=r26,r25
1354 add r26=r26,carry2 };;
1355{ .mii; getf.sig r17=f64
1356(p6) add carry1=1,carry1
1357 cmp.ltu p6,p0=r26,carry2 };;
1358{ .mii; st8 [r33]=r26,16
1359(p6) add carry1=1,carry1 }
1360
1361{ .mii; getf.sig r24=f74
1362 add r17=r17,r16
1363 mov carry2=0 };;
1364{ .mii; cmp.ltu p7,p0=r17,r16
1365 add r17=r17,carry1 };;
1366
1367{ .mii; (p7) add carry2=1,carry2
1368 cmp.ltu p7,p0=r17,carry1};;
1369{ .mii; st8 [r32]=r17,16
1370 (p7) add carry2=1,carry2 };;
1371
1372{ .mii; add r24=r24,carry2 };;
1373{ .mii; st8 [r33]=r24 }
1374
1375{ .mib; rum 1<<5 // clear um.mfh
1376 br.ret.sptk.many b0 };;
1377.endp bn_mul_comba4#
1378#undef carry2
1379#undef carry1
1380#endif
1381
1382#if 1
1383//
1384// BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
1385//
1386// In the nutshell it's a port of my MIPS III/IV implementation.
1387//
1388#define AT r14
1389#define H r16
1390#define HH r20
1391#define L r17
1392#define D r18
1393#define DH r22
1394#define I r21
1395
1396#if 0
1397// Some preprocessors (most notably HP-UX) appear to be allergic to
1398// macros enclosed to parenthesis [as these three were].
1399#define cont p16
1400#define break p0 // p20
1401#define equ p24
1402#else
1403cont=p16
1404break=p0
1405equ=p24
1406#endif
1407
1408.global abort#
1409.global bn_div_words#
1410.proc bn_div_words#
1411.align 64
1412bn_div_words:
1413 .prologue
1414 .fframe 0
1415 .save ar.pfs,r2
1416 .save b0,r3
1417{ .mii; alloc r2=ar.pfs,3,5,0,8
1418 mov r3=b0
1419 mov r10=pr };;
1420{ .mmb; cmp.eq p6,p0=r34,r0
1421 mov r8=-1
1422(p6) br.ret.spnt.many b0 };;
1423
1424 .body
1425{ .mii; mov H=r32 // save h
1426 mov ar.ec=0 // don't rotate at exit
1427 mov pr.rot=0 }
1428{ .mii; mov L=r33 // save l
1429 mov r36=r0 };;
1430
1431.L_divw_shift: // -vv- note signed comparison
1432{ .mfi; (p0) cmp.lt p16,p0=r0,r34 // d
1433 (p0) shladd r33=r34,1,r0 }
1434{ .mfb; (p0) add r35=1,r36
1435 (p0) nop.f 0x0
1436(p16) br.wtop.dpnt .L_divw_shift };;
1437
1438{ .mii; mov D=r34
1439 shr.u DH=r34,32
1440 sub r35=64,r36 };;
1441{ .mii; setf.sig f7=DH
1442 shr.u AT=H,r35
1443 mov I=r36 };;
1444{ .mib; cmp.ne p6,p0=r0,AT
1445 shl H=H,r36
1446(p6) br.call.spnt.clr b0=abort };; // overflow, die...
1447
1448{ .mfi; fcvt.xuf.s1 f7=f7
1449 shr.u AT=L,r35 };;
1450{ .mii; shl L=L,r36
1451 or H=H,AT };;
1452
1453{ .mii; nop.m 0x0
1454 cmp.leu p6,p0=D,H;;
1455(p6) sub H=H,D }
1456
1457{ .mlx; setf.sig f14=D
1458 movl AT=0xffffffff };;
1459///////////////////////////////////////////////////////////
1460{ .mii; setf.sig f6=H
1461 shr.u HH=H,32;;
1462 cmp.eq p6,p7=HH,DH };;
1463{ .mfb;
1464(p6) setf.sig f8=AT
1465(p7) fcvt.xuf.s1 f6=f6
1466(p7) br.call.sptk b6=.L_udiv64_32_b6 };;
1467
1468{ .mfi; getf.sig r33=f8 // q
1469 xmpy.lu f9=f8,f14 }
1470{ .mfi; xmpy.hu f10=f8,f14
1471 shrp H=H,L,32 };;
1472
1473{ .mmi; getf.sig r35=f9 // tl
1474 getf.sig r31=f10 };; // th
1475
1476.L_divw_1st_iter:
1477{ .mii; (p0) add r32=-1,r33
1478 (p0) cmp.eq equ,cont=HH,r31 };;
1479{ .mii; (p0) cmp.ltu p8,p0=r35,D
1480 (p0) sub r34=r35,D
1481 (equ) cmp.leu break,cont=r35,H };;
1482{ .mib; (cont) cmp.leu cont,break=HH,r31
1483 (p8) add r31=-1,r31
1484(cont) br.wtop.spnt .L_divw_1st_iter };;
1485///////////////////////////////////////////////////////////
1486{ .mii; sub H=H,r35
1487 shl r8=r33,32
1488 shl L=L,32 };;
1489///////////////////////////////////////////////////////////
1490{ .mii; setf.sig f6=H
1491 shr.u HH=H,32;;
1492 cmp.eq p6,p7=HH,DH };;
1493{ .mfb;
1494(p6) setf.sig f8=AT
1495(p7) fcvt.xuf.s1 f6=f6
1496(p7) br.call.sptk b6=.L_udiv64_32_b6 };;
1497
1498{ .mfi; getf.sig r33=f8 // q
1499 xmpy.lu f9=f8,f14 }
1500{ .mfi; xmpy.hu f10=f8,f14
1501 shrp H=H,L,32 };;
1502
1503{ .mmi; getf.sig r35=f9 // tl
1504 getf.sig r31=f10 };; // th
1505
1506.L_divw_2nd_iter:
1507{ .mii; (p0) add r32=-1,r33
1508 (p0) cmp.eq equ,cont=HH,r31 };;
1509{ .mii; (p0) cmp.ltu p8,p0=r35,D
1510 (p0) sub r34=r35,D
1511 (equ) cmp.leu break,cont=r35,H };;
1512{ .mib; (cont) cmp.leu cont,break=HH,r31
1513 (p8) add r31=-1,r31
1514(cont) br.wtop.spnt .L_divw_2nd_iter };;
1515///////////////////////////////////////////////////////////
1516{ .mii; sub H=H,r35
1517 or r8=r8,r33
1518 mov ar.pfs=r2 };;
1519{ .mii; shr.u r9=H,I // remainder if anybody wants it
1520 mov pr=r10,0x1ffff }
1521{ .mfb; br.ret.sptk.many b0 };;
1522
1523// Unsigned 64 by 32 (well, by 64 for the moment) bit integer division
1524// procedure.
1525//
1526// inputs: f6 = (double)a, f7 = (double)b
1527// output: f8 = (int)(a/b)
1528// clobbered: f8,f9,f10,f11,pred
1529pred=p15
1530// One can argue that this snippet is copyrighted to Intel
1531// Corporation, as it's essentially identical to one of those
1532// found in "Divide, Square Root and Remainder" section at
1533// http://www.intel.com/software/products/opensource/libraries/num.htm.
1534// Yes, I admit that the referred code was used as template,
1535// but after I realized that there hardly is any other instruction
1536// sequence which would perform this operation. I mean I figure that
1537// any independent attempt to implement high-performance division
1538// will result in code virtually identical to the Intel code. It
1539// should be noted though that below division kernel is 1 cycle
1540// faster than Intel one (note commented splits:-), not to mention
1541// original prologue (rather lack of one) and epilogue.
1542.align 32
1543.skip 16
1544.L_udiv64_32_b6:
1545 frcpa.s1 f8,pred=f6,f7;; // [0] y0 = 1 / b
1546
1547(pred) fnma.s1 f9=f7,f8,f1 // [5] e0 = 1 - b * y0
1548(pred) fmpy.s1 f10=f6,f8;; // [5] q0 = a * y0
1549(pred) fmpy.s1 f11=f9,f9 // [10] e1 = e0 * e0
1550(pred) fma.s1 f10=f9,f10,f10;; // [10] q1 = q0 + e0 * q0
1551(pred) fma.s1 f8=f9,f8,f8 //;; // [15] y1 = y0 + e0 * y0
1552(pred) fma.s1 f9=f11,f10,f10;; // [15] q2 = q1 + e1 * q1
1553(pred) fma.s1 f8=f11,f8,f8 //;; // [20] y2 = y1 + e1 * y1
1554(pred) fnma.s1 f10=f7,f9,f6;; // [20] r2 = a - b * q2
1555(pred) fma.s1 f8=f10,f8,f9;; // [25] q3 = q2 + r2 * y2
1556
1557 fcvt.fxu.trunc.s1 f8=f8 // [30] q = trunc(q3)
1558 br.ret.sptk.many b6;;
1559.endp bn_div_words#
1560#endif
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 f3b16290eb..0000000000
--- a/src/lib/libcrypto/bn/asm/pa-risc2.s
+++ /dev/null
@@ -1,1618 +0,0 @@
1;
2; PA-RISC 2.0 implementation of bn_asm code, based on the
3; 64-bit version of the code. This code is effectively the
4; same as the 64-bit version except the register model is
5; slightly different given all values must be 32-bit between
6; function calls. Thus the 64-bit return values are returned
7; in %ret0 and %ret1 vs just %ret0 as is done in 64-bit
8;
9;
10; This code is approximately 2x faster than the C version
11; for RSA/DSA.
12;
13; See http://devresource.hp.com/ for more details on the PA-RISC
14; architecture. Also see the book "PA-RISC 2.0 Architecture"
15; by Gerry Kane for information on the instruction set architecture.
16;
17; Code written by Chris Ruemmler (with some help from the HP C
18; compiler).
19;
20; The code compiles with HP's assembler
21;
22
23 .level 2.0N
24 .space $TEXT$
25 .subspa $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY
26
27;
28; Global Register definitions used for the routines.
29;
30; Some information about HP's runtime architecture for 32-bits.
31;
32; "Caller save" means the calling function must save the register
33; if it wants the register to be preserved.
34; "Callee save" means if a function uses the register, it must save
35; the value before using it.
36;
37; For the floating point registers
38;
39; "caller save" registers: fr4-fr11, fr22-fr31
40; "callee save" registers: fr12-fr21
41; "special" registers: fr0-fr3 (status and exception registers)
42;
43; For the integer registers
44; value zero : r0
45; "caller save" registers: r1,r19-r26
46; "callee save" registers: r3-r18
47; return register : r2 (rp)
48; return values ; r28,r29 (ret0,ret1)
49; Stack pointer ; r30 (sp)
50; millicode return ptr ; r31 (also a caller save register)
51
52
53;
54; Arguments to the routines
55;
56r_ptr .reg %r26
57a_ptr .reg %r25
58b_ptr .reg %r24
59num .reg %r24
60n .reg %r23
61
62;
63; Note that the "w" argument for bn_mul_add_words and bn_mul_words
64; is passed on the stack at a delta of -56 from the top of stack
65; as the routine is entered.
66;
67
68;
69; Globals used in some routines
70;
71
72top_overflow .reg %r23
73high_mask .reg %r22 ; value 0xffffffff80000000L
74
75
76;------------------------------------------------------------------------------
77;
78; bn_mul_add_words
79;
80;BN_ULONG bn_mul_add_words(BN_ULONG *r_ptr, BN_ULONG *a_ptr,
81; int num, BN_ULONG w)
82;
83; arg0 = r_ptr
84; arg1 = a_ptr
85; arg3 = num
86; -56(sp) = w
87;
88; Local register definitions
89;
90
91fm1 .reg %fr22
92fm .reg %fr23
93ht_temp .reg %fr24
94ht_temp_1 .reg %fr25
95lt_temp .reg %fr26
96lt_temp_1 .reg %fr27
97fm1_1 .reg %fr28
98fm_1 .reg %fr29
99
100fw_h .reg %fr7L
101fw_l .reg %fr7R
102fw .reg %fr7
103
104fht_0 .reg %fr8L
105flt_0 .reg %fr8R
106t_float_0 .reg %fr8
107
108fht_1 .reg %fr9L
109flt_1 .reg %fr9R
110t_float_1 .reg %fr9
111
112tmp_0 .reg %r31
113tmp_1 .reg %r21
114m_0 .reg %r20
115m_1 .reg %r19
116ht_0 .reg %r1
117ht_1 .reg %r3
118lt_0 .reg %r4
119lt_1 .reg %r5
120m1_0 .reg %r6
121m1_1 .reg %r7
122rp_val .reg %r8
123rp_val_1 .reg %r9
124
125bn_mul_add_words
126 .export bn_mul_add_words,entry,NO_RELOCATION,LONG_RETURN
127 .proc
128 .callinfo frame=128
129 .entry
130 .align 64
131
132 STD %r3,0(%sp) ; save r3
133 STD %r4,8(%sp) ; save r4
134 NOP ; Needed to make the loop 16-byte aligned
135 NOP ; needed to make the loop 16-byte aligned
136
137 STD %r5,16(%sp) ; save r5
138 NOP
139 STD %r6,24(%sp) ; save r6
140 STD %r7,32(%sp) ; save r7
141
142 STD %r8,40(%sp) ; save r8
143 STD %r9,48(%sp) ; save r9
144 COPY %r0,%ret1 ; return 0 by default
145 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
146
147 CMPIB,>= 0,num,bn_mul_add_words_exit ; if (num <= 0) then exit
148 LDO 128(%sp),%sp ; bump stack
149
150 ;
151 ; The loop is unrolled twice, so if there is only 1 number
152 ; then go straight to the cleanup code.
153 ;
154 CMPIB,= 1,num,bn_mul_add_words_single_top
155 FLDD -184(%sp),fw ; (-56-128) load up w into fw (fw_h/fw_l)
156
157 ;
158 ; This loop is unrolled 2 times (64-byte aligned as well)
159 ;
160 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
161 ; two 32-bit mutiplies can be issued per cycle.
162 ;
163bn_mul_add_words_unroll2
164
165 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
166 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
167 LDD 0(r_ptr),rp_val ; rp[0]
168 LDD 8(r_ptr),rp_val_1 ; rp[1]
169
170 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
171 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = fht_1*fw_l
172 FSTD fm1,-16(%sp) ; -16(sp) = m1[0]
173 FSTD fm1_1,-48(%sp) ; -48(sp) = m1[1]
174
175 XMPYU flt_0,fw_h,fm ; m[0] = flt_0*fw_h
176 XMPYU flt_1,fw_h,fm_1 ; m[1] = flt_1*fw_h
177 FSTD fm,-8(%sp) ; -8(sp) = m[0]
178 FSTD fm_1,-40(%sp) ; -40(sp) = m[1]
179
180 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
181 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp_1 = fht_1*fw_h
182 FSTD ht_temp,-24(%sp) ; -24(sp) = ht_temp
183 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht_temp_1
184
185 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
186 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
187 FSTD lt_temp,-32(%sp) ; -32(sp) = lt_temp
188 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt_temp_1
189
190 LDD -8(%sp),m_0 ; m[0]
191 LDD -40(%sp),m_1 ; m[1]
192 LDD -16(%sp),m1_0 ; m1[0]
193 LDD -48(%sp),m1_1 ; m1[1]
194
195 LDD -24(%sp),ht_0 ; ht[0]
196 LDD -56(%sp),ht_1 ; ht[1]
197 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m[0] + m1[0];
198 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m[1] + m1[1];
199
200 LDD -32(%sp),lt_0
201 LDD -64(%sp),lt_1
202 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m[0] < m1[0])
203 ADD,L ht_0,top_overflow,ht_0 ; ht[0] += (1<<32)
204
205 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m[1] < m1[1])
206 ADD,L ht_1,top_overflow,ht_1 ; ht[1] += (1<<32)
207 EXTRD,U tmp_0,31,32,m_0 ; m[0]>>32
208 DEPD,Z tmp_0,31,32,m1_0 ; m1[0] = m[0]<<32
209
210 EXTRD,U tmp_1,31,32,m_1 ; m[1]>>32
211 DEPD,Z tmp_1,31,32,m1_1 ; m1[1] = m[1]<<32
212 ADD,L ht_0,m_0,ht_0 ; ht[0]+= (m[0]>>32)
213 ADD,L ht_1,m_1,ht_1 ; ht[1]+= (m[1]>>32)
214
215 ADD lt_0,m1_0,lt_0 ; lt[0] = lt[0]+m1[0];
216 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
217 ADD lt_1,m1_1,lt_1 ; lt[1] = lt[1]+m1[1];
218 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
219
220 ADD %ret1,lt_0,lt_0 ; lt[0] = lt[0] + c;
221 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
222 ADD lt_0,rp_val,lt_0 ; lt[0] = lt[0]+rp[0]
223 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
224
225 LDO -2(num),num ; num = num - 2;
226 ADD ht_0,lt_1,lt_1 ; lt[1] = lt[1] + ht_0 (c);
227 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
228 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
229
230 ADD lt_1,rp_val_1,lt_1 ; lt[1] = lt[1]+rp[1]
231 ADD,DC ht_1,%r0,%ret1 ; ht[1]++
232 LDO 16(a_ptr),a_ptr ; a_ptr += 2
233
234 STD lt_1,8(r_ptr) ; rp[1] = lt[1]
235 CMPIB,<= 2,num,bn_mul_add_words_unroll2 ; go again if more to do
236 LDO 16(r_ptr),r_ptr ; r_ptr += 2
237
238 CMPIB,=,N 0,num,bn_mul_add_words_exit ; are we done, or cleanup last one
239
240 ;
241 ; Top of loop aligned on 64-byte boundary
242 ;
243bn_mul_add_words_single_top
244 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
245 LDD 0(r_ptr),rp_val ; rp[0]
246 LDO 8(a_ptr),a_ptr ; a_ptr++
247 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
248 FSTD fm1,-16(%sp) ; -16(sp) = m1
249 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
250 FSTD fm,-8(%sp) ; -8(sp) = m
251 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
252 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
253 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
254 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
255
256 LDD -8(%sp),m_0
257 LDD -16(%sp),m1_0 ; m1 = temp1
258 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
259 LDD -24(%sp),ht_0
260 LDD -32(%sp),lt_0
261
262 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
263 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
264
265 EXTRD,U tmp_0,31,32,m_0 ; m>>32
266 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
267
268 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
269 ADD lt_0,m1_0,tmp_0 ; tmp_0 = lt+m1;
270 ADD,DC ht_0,%r0,ht_0 ; ht++
271 ADD %ret1,tmp_0,lt_0 ; lt = lt + c;
272 ADD,DC ht_0,%r0,ht_0 ; ht++
273 ADD lt_0,rp_val,lt_0 ; lt = lt+rp[0]
274 ADD,DC ht_0,%r0,%ret1 ; ht++
275 STD lt_0,0(r_ptr) ; rp[0] = lt
276
277bn_mul_add_words_exit
278 .EXIT
279
280 EXTRD,U %ret1,31,32,%ret0 ; for 32-bit, return in ret0/ret1
281 LDD -80(%sp),%r9 ; restore r9
282 LDD -88(%sp),%r8 ; restore r8
283 LDD -96(%sp),%r7 ; restore r7
284 LDD -104(%sp),%r6 ; restore r6
285 LDD -112(%sp),%r5 ; restore r5
286 LDD -120(%sp),%r4 ; restore r4
287 BVE (%rp)
288 LDD,MB -128(%sp),%r3 ; restore r3
289 .PROCEND ;in=23,24,25,26,29;out=28;
290
291;----------------------------------------------------------------------------
292;
293;BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
294;
295; arg0 = rp
296; arg1 = ap
297; arg3 = num
298; w on stack at -56(sp)
299
300bn_mul_words
301 .proc
302 .callinfo frame=128
303 .entry
304 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
305 .align 64
306
307 STD %r3,0(%sp) ; save r3
308 STD %r4,8(%sp) ; save r4
309 NOP
310 STD %r5,16(%sp) ; save r5
311
312 STD %r6,24(%sp) ; save r6
313 STD %r7,32(%sp) ; save r7
314 COPY %r0,%ret1 ; return 0 by default
315 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
316
317 CMPIB,>= 0,num,bn_mul_words_exit
318 LDO 128(%sp),%sp ; bump stack
319
320 ;
321 ; See if only 1 word to do, thus just do cleanup
322 ;
323 CMPIB,= 1,num,bn_mul_words_single_top
324 FLDD -184(%sp),fw ; (-56-128) load up w into fw (fw_h/fw_l)
325
326 ;
327 ; This loop is unrolled 2 times (64-byte aligned as well)
328 ;
329 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
330 ; two 32-bit mutiplies can be issued per cycle.
331 ;
332bn_mul_words_unroll2
333
334 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
335 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
336 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
337 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = ht*fw_l
338
339 FSTD fm1,-16(%sp) ; -16(sp) = m1
340 FSTD fm1_1,-48(%sp) ; -48(sp) = m1
341 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
342 XMPYU flt_1,fw_h,fm_1 ; m = lt*fw_h
343
344 FSTD fm,-8(%sp) ; -8(sp) = m
345 FSTD fm_1,-40(%sp) ; -40(sp) = m
346 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
347 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp = ht*fw_h
348
349 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
350 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht
351 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
352 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
353
354 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
355 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt
356 LDD -8(%sp),m_0
357 LDD -40(%sp),m_1
358
359 LDD -16(%sp),m1_0
360 LDD -48(%sp),m1_1
361 LDD -24(%sp),ht_0
362 LDD -56(%sp),ht_1
363
364 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m + m1;
365 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m + m1;
366 LDD -32(%sp),lt_0
367 LDD -64(%sp),lt_1
368
369 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m < m1)
370 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
371 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m < m1)
372 ADD,L ht_1,top_overflow,ht_1 ; ht += (1<<32)
373
374 EXTRD,U tmp_0,31,32,m_0 ; m>>32
375 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
376 EXTRD,U tmp_1,31,32,m_1 ; m>>32
377 DEPD,Z tmp_1,31,32,m1_1 ; m1 = m<<32
378
379 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
380 ADD,L ht_1,m_1,ht_1 ; ht+= (m>>32)
381 ADD lt_0,m1_0,lt_0 ; lt = lt+m1;
382 ADD,DC ht_0,%r0,ht_0 ; ht++
383
384 ADD lt_1,m1_1,lt_1 ; lt = lt+m1;
385 ADD,DC ht_1,%r0,ht_1 ; ht++
386 ADD %ret1,lt_0,lt_0 ; lt = lt + c (ret1);
387 ADD,DC ht_0,%r0,ht_0 ; ht++
388
389 ADD ht_0,lt_1,lt_1 ; lt = lt + c (ht_0)
390 ADD,DC ht_1,%r0,ht_1 ; ht++
391 STD lt_0,0(r_ptr) ; rp[0] = lt
392 STD lt_1,8(r_ptr) ; rp[1] = lt
393
394 COPY ht_1,%ret1 ; carry = ht
395 LDO -2(num),num ; num = num - 2;
396 LDO 16(a_ptr),a_ptr ; ap += 2
397 CMPIB,<= 2,num,bn_mul_words_unroll2
398 LDO 16(r_ptr),r_ptr ; rp++
399
400 CMPIB,=,N 0,num,bn_mul_words_exit ; are we done?
401
402 ;
403 ; Top of loop aligned on 64-byte boundary
404 ;
405bn_mul_words_single_top
406 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
407
408 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
409 FSTD fm1,-16(%sp) ; -16(sp) = m1
410 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
411 FSTD fm,-8(%sp) ; -8(sp) = m
412 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
413 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
414 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
415 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
416
417 LDD -8(%sp),m_0
418 LDD -16(%sp),m1_0
419 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
420 LDD -24(%sp),ht_0
421 LDD -32(%sp),lt_0
422
423 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
424 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
425
426 EXTRD,U tmp_0,31,32,m_0 ; m>>32
427 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
428
429 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
430 ADD lt_0,m1_0,lt_0 ; lt= lt+m1;
431 ADD,DC ht_0,%r0,ht_0 ; ht++
432
433 ADD %ret1,lt_0,lt_0 ; lt = lt + c;
434 ADD,DC ht_0,%r0,ht_0 ; ht++
435
436 COPY ht_0,%ret1 ; copy carry
437 STD lt_0,0(r_ptr) ; rp[0] = lt
438
439bn_mul_words_exit
440 .EXIT
441 EXTRD,U %ret1,31,32,%ret0 ; for 32-bit, return in ret0/ret1
442 LDD -96(%sp),%r7 ; restore r7
443 LDD -104(%sp),%r6 ; restore r6
444 LDD -112(%sp),%r5 ; restore r5
445 LDD -120(%sp),%r4 ; restore r4
446 BVE (%rp)
447 LDD,MB -128(%sp),%r3 ; restore r3
448 .PROCEND
449
450;----------------------------------------------------------------------------
451;
452;void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num)
453;
454; arg0 = rp
455; arg1 = ap
456; arg2 = num
457;
458
459bn_sqr_words
460 .proc
461 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
462 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
463 .entry
464 .align 64
465
466 STD %r3,0(%sp) ; save r3
467 STD %r4,8(%sp) ; save r4
468 NOP
469 STD %r5,16(%sp) ; save r5
470
471 CMPIB,>= 0,num,bn_sqr_words_exit
472 LDO 128(%sp),%sp ; bump stack
473
474 ;
475 ; If only 1, the goto straight to cleanup
476 ;
477 CMPIB,= 1,num,bn_sqr_words_single_top
478 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
479
480 ;
481 ; This loop is unrolled 2 times (64-byte aligned as well)
482 ;
483
484bn_sqr_words_unroll2
485 FLDD 0(a_ptr),t_float_0 ; a[0]
486 FLDD 8(a_ptr),t_float_1 ; a[1]
487 XMPYU fht_0,flt_0,fm ; m[0]
488 XMPYU fht_1,flt_1,fm_1 ; m[1]
489
490 FSTD fm,-24(%sp) ; store m[0]
491 FSTD fm_1,-56(%sp) ; store m[1]
492 XMPYU flt_0,flt_0,lt_temp ; lt[0]
493 XMPYU flt_1,flt_1,lt_temp_1 ; lt[1]
494
495 FSTD lt_temp,-16(%sp) ; store lt[0]
496 FSTD lt_temp_1,-48(%sp) ; store lt[1]
497 XMPYU fht_0,fht_0,ht_temp ; ht[0]
498 XMPYU fht_1,fht_1,ht_temp_1 ; ht[1]
499
500 FSTD ht_temp,-8(%sp) ; store ht[0]
501 FSTD ht_temp_1,-40(%sp) ; store ht[1]
502 LDD -24(%sp),m_0
503 LDD -56(%sp),m_1
504
505 AND m_0,high_mask,tmp_0 ; m[0] & Mask
506 AND m_1,high_mask,tmp_1 ; m[1] & Mask
507 DEPD,Z m_0,30,31,m_0 ; m[0] << 32+1
508 DEPD,Z m_1,30,31,m_1 ; m[1] << 32+1
509
510 LDD -16(%sp),lt_0
511 LDD -48(%sp),lt_1
512 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m[0]&Mask >> 32-1
513 EXTRD,U tmp_1,32,33,tmp_1 ; tmp_1 = m[1]&Mask >> 32-1
514
515 LDD -8(%sp),ht_0
516 LDD -40(%sp),ht_1
517 ADD,L ht_0,tmp_0,ht_0 ; ht[0] += tmp_0
518 ADD,L ht_1,tmp_1,ht_1 ; ht[1] += tmp_1
519
520 ADD lt_0,m_0,lt_0 ; lt = lt+m
521 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
522 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
523 STD ht_0,8(r_ptr) ; rp[1] = ht[1]
524
525 ADD lt_1,m_1,lt_1 ; lt = lt+m
526 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
527 STD lt_1,16(r_ptr) ; rp[2] = lt[1]
528 STD ht_1,24(r_ptr) ; rp[3] = ht[1]
529
530 LDO -2(num),num ; num = num - 2;
531 LDO 16(a_ptr),a_ptr ; ap += 2
532 CMPIB,<= 2,num,bn_sqr_words_unroll2
533 LDO 32(r_ptr),r_ptr ; rp += 4
534
535 CMPIB,=,N 0,num,bn_sqr_words_exit ; are we done?
536
537 ;
538 ; Top of loop aligned on 64-byte boundary
539 ;
540bn_sqr_words_single_top
541 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
542
543 XMPYU fht_0,flt_0,fm ; m
544 FSTD fm,-24(%sp) ; store m
545
546 XMPYU flt_0,flt_0,lt_temp ; lt
547 FSTD lt_temp,-16(%sp) ; store lt
548
549 XMPYU fht_0,fht_0,ht_temp ; ht
550 FSTD ht_temp,-8(%sp) ; store ht
551
552 LDD -24(%sp),m_0 ; load m
553 AND m_0,high_mask,tmp_0 ; m & Mask
554 DEPD,Z m_0,30,31,m_0 ; m << 32+1
555 LDD -16(%sp),lt_0 ; lt
556
557 LDD -8(%sp),ht_0 ; ht
558 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m&Mask >> 32-1
559 ADD m_0,lt_0,lt_0 ; lt = lt+m
560 ADD,L ht_0,tmp_0,ht_0 ; ht += tmp_0
561 ADD,DC ht_0,%r0,ht_0 ; ht++
562
563 STD lt_0,0(r_ptr) ; rp[0] = lt
564 STD ht_0,8(r_ptr) ; rp[1] = ht
565
566bn_sqr_words_exit
567 .EXIT
568 LDD -112(%sp),%r5 ; restore r5
569 LDD -120(%sp),%r4 ; restore r4
570 BVE (%rp)
571 LDD,MB -128(%sp),%r3
572 .PROCEND ;in=23,24,25,26,29;out=28;
573
574
575;----------------------------------------------------------------------------
576;
577;BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
578;
579; arg0 = rp
580; arg1 = ap
581; arg2 = bp
582; arg3 = n
583
584t .reg %r22
585b .reg %r21
586l .reg %r20
587
588bn_add_words
589 .proc
590 .entry
591 .callinfo
592 .EXPORT bn_add_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
593 .align 64
594
595 CMPIB,>= 0,n,bn_add_words_exit
596 COPY %r0,%ret1 ; return 0 by default
597
598 ;
599 ; If 2 or more numbers do the loop
600 ;
601 CMPIB,= 1,n,bn_add_words_single_top
602 NOP
603
604 ;
605 ; This loop is unrolled 2 times (64-byte aligned as well)
606 ;
607bn_add_words_unroll2
608 LDD 0(a_ptr),t
609 LDD 0(b_ptr),b
610 ADD t,%ret1,t ; t = t+c;
611 ADD,DC %r0,%r0,%ret1 ; set c to carry
612 ADD t,b,l ; l = t + b[0]
613 ADD,DC %ret1,%r0,%ret1 ; c+= carry
614 STD l,0(r_ptr)
615
616 LDD 8(a_ptr),t
617 LDD 8(b_ptr),b
618 ADD t,%ret1,t ; t = t+c;
619 ADD,DC %r0,%r0,%ret1 ; set c to carry
620 ADD t,b,l ; l = t + b[0]
621 ADD,DC %ret1,%r0,%ret1 ; c+= carry
622 STD l,8(r_ptr)
623
624 LDO -2(n),n
625 LDO 16(a_ptr),a_ptr
626 LDO 16(b_ptr),b_ptr
627
628 CMPIB,<= 2,n,bn_add_words_unroll2
629 LDO 16(r_ptr),r_ptr
630
631 CMPIB,=,N 0,n,bn_add_words_exit ; are we done?
632
633bn_add_words_single_top
634 LDD 0(a_ptr),t
635 LDD 0(b_ptr),b
636
637 ADD t,%ret1,t ; t = t+c;
638 ADD,DC %r0,%r0,%ret1 ; set c to carry (could use CMPCLR??)
639 ADD t,b,l ; l = t + b[0]
640 ADD,DC %ret1,%r0,%ret1 ; c+= carry
641 STD l,0(r_ptr)
642
643bn_add_words_exit
644 .EXIT
645 BVE (%rp)
646 EXTRD,U %ret1,31,32,%ret0 ; for 32-bit, return in ret0/ret1
647 .PROCEND ;in=23,24,25,26,29;out=28;
648
649;----------------------------------------------------------------------------
650;
651;BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
652;
653; arg0 = rp
654; arg1 = ap
655; arg2 = bp
656; arg3 = n
657
658t1 .reg %r22
659t2 .reg %r21
660sub_tmp1 .reg %r20
661sub_tmp2 .reg %r19
662
663
664bn_sub_words
665 .proc
666 .callinfo
667 .EXPORT bn_sub_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
668 .entry
669 .align 64
670
671 CMPIB,>= 0,n,bn_sub_words_exit
672 COPY %r0,%ret1 ; return 0 by default
673
674 ;
675 ; If 2 or more numbers do the loop
676 ;
677 CMPIB,= 1,n,bn_sub_words_single_top
678 NOP
679
680 ;
681 ; This loop is unrolled 2 times (64-byte aligned as well)
682 ;
683bn_sub_words_unroll2
684 LDD 0(a_ptr),t1
685 LDD 0(b_ptr),t2
686 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
687 SUB sub_tmp1,%ret1,sub_tmp1 ; t3 = t3- c;
688
689 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
690 LDO 1(%r0),sub_tmp2
691
692 CMPCLR,*= t1,t2,%r0
693 COPY sub_tmp2,%ret1
694 STD sub_tmp1,0(r_ptr)
695
696 LDD 8(a_ptr),t1
697 LDD 8(b_ptr),t2
698 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
699 SUB sub_tmp1,%ret1,sub_tmp1 ; t3 = t3- c;
700 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
701 LDO 1(%r0),sub_tmp2
702
703 CMPCLR,*= t1,t2,%r0
704 COPY sub_tmp2,%ret1
705 STD sub_tmp1,8(r_ptr)
706
707 LDO -2(n),n
708 LDO 16(a_ptr),a_ptr
709 LDO 16(b_ptr),b_ptr
710
711 CMPIB,<= 2,n,bn_sub_words_unroll2
712 LDO 16(r_ptr),r_ptr
713
714 CMPIB,=,N 0,n,bn_sub_words_exit ; are we done?
715
716bn_sub_words_single_top
717 LDD 0(a_ptr),t1
718 LDD 0(b_ptr),t2
719 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
720 SUB sub_tmp1,%ret1,sub_tmp1 ; t3 = t3- c;
721 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
722 LDO 1(%r0),sub_tmp2
723
724 CMPCLR,*= t1,t2,%r0
725 COPY sub_tmp2,%ret1
726
727 STD sub_tmp1,0(r_ptr)
728
729bn_sub_words_exit
730 .EXIT
731 BVE (%rp)
732 EXTRD,U %ret1,31,32,%ret0 ; for 32-bit, return in ret0/ret1
733 .PROCEND ;in=23,24,25,26,29;out=28;
734
735;------------------------------------------------------------------------------
736;
737; unsigned long bn_div_words(unsigned long h, unsigned long l, unsigned long d)
738;
739; arg0 = h
740; arg1 = l
741; arg2 = d
742;
743; This is mainly just output from the HP C compiler.
744;
745;------------------------------------------------------------------------------
746bn_div_words
747 .PROC
748 .EXPORT bn_div_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR,LONG_RETURN
749 .IMPORT BN_num_bits_word,CODE
750 ;--- not PIC .IMPORT __iob,DATA
751 ;--- not PIC .IMPORT fprintf,CODE
752 .IMPORT abort,CODE
753 .IMPORT $$div2U,MILLICODE
754 .CALLINFO CALLER,FRAME=144,ENTRY_GR=%r9,SAVE_RP,ARGS_SAVED,ORDERING_AWARE
755 .ENTRY
756 STW %r2,-20(%r30) ;offset 0x8ec
757 STW,MA %r3,192(%r30) ;offset 0x8f0
758 STW %r4,-188(%r30) ;offset 0x8f4
759 DEPD %r5,31,32,%r6 ;offset 0x8f8
760 STD %r6,-184(%r30) ;offset 0x8fc
761 DEPD %r7,31,32,%r8 ;offset 0x900
762 STD %r8,-176(%r30) ;offset 0x904
763 STW %r9,-168(%r30) ;offset 0x908
764 LDD -248(%r30),%r3 ;offset 0x90c
765 COPY %r26,%r4 ;offset 0x910
766 COPY %r24,%r5 ;offset 0x914
767 DEPD %r25,31,32,%r4 ;offset 0x918
768 CMPB,*<> %r3,%r0,$0006000C ;offset 0x91c
769 DEPD %r23,31,32,%r5 ;offset 0x920
770 MOVIB,TR -1,%r29,$00060002 ;offset 0x924
771 EXTRD,U %r29,31,32,%r28 ;offset 0x928
772$0006002A
773 LDO -1(%r29),%r29 ;offset 0x92c
774 SUB %r23,%r7,%r23 ;offset 0x930
775$00060024
776 SUB %r4,%r31,%r25 ;offset 0x934
777 AND %r25,%r19,%r26 ;offset 0x938
778 CMPB,*<>,N %r0,%r26,$00060046 ;offset 0x93c
779 DEPD,Z %r25,31,32,%r20 ;offset 0x940
780 OR %r20,%r24,%r21 ;offset 0x944
781 CMPB,*<<,N %r21,%r23,$0006002A ;offset 0x948
782 SUB %r31,%r2,%r31 ;offset 0x94c
783$00060046
784$0006002E
785 DEPD,Z %r23,31,32,%r25 ;offset 0x950
786 EXTRD,U %r23,31,32,%r26 ;offset 0x954
787 AND %r25,%r19,%r24 ;offset 0x958
788 ADD,L %r31,%r26,%r31 ;offset 0x95c
789 CMPCLR,*>>= %r5,%r24,%r0 ;offset 0x960
790 LDO 1(%r31),%r31 ;offset 0x964
791$00060032
792 CMPB,*<<=,N %r31,%r4,$00060036 ;offset 0x968
793 LDO -1(%r29),%r29 ;offset 0x96c
794 ADD,L %r4,%r3,%r4 ;offset 0x970
795$00060036
796 ADDIB,=,N -1,%r8,$D0 ;offset 0x974
797 SUB %r5,%r24,%r28 ;offset 0x978
798$0006003A
799 SUB %r4,%r31,%r24 ;offset 0x97c
800 SHRPD %r24,%r28,32,%r4 ;offset 0x980
801 DEPD,Z %r29,31,32,%r9 ;offset 0x984
802 DEPD,Z %r28,31,32,%r5 ;offset 0x988
803$0006001C
804 EXTRD,U %r4,31,32,%r31 ;offset 0x98c
805 CMPB,*<>,N %r31,%r2,$00060020 ;offset 0x990
806 MOVB,TR %r6,%r29,$D1 ;offset 0x994
807 STD %r29,-152(%r30) ;offset 0x998
808$0006000C
809 EXTRD,U %r3,31,32,%r25 ;offset 0x99c
810 COPY %r3,%r26 ;offset 0x9a0
811 EXTRD,U %r3,31,32,%r9 ;offset 0x9a4
812 EXTRD,U %r4,31,32,%r8 ;offset 0x9a8
813 .CALL ARGW0=GR,ARGW1=GR,RTNVAL=GR ;in=25,26;out=28;
814 B,L BN_num_bits_word,%r2 ;offset 0x9ac
815 EXTRD,U %r5,31,32,%r7 ;offset 0x9b0
816 LDI 64,%r20 ;offset 0x9b4
817 DEPD %r7,31,32,%r5 ;offset 0x9b8
818 DEPD %r8,31,32,%r4 ;offset 0x9bc
819 DEPD %r9,31,32,%r3 ;offset 0x9c0
820 CMPB,= %r28,%r20,$00060012 ;offset 0x9c4
821 COPY %r28,%r24 ;offset 0x9c8
822 MTSARCM %r24 ;offset 0x9cc
823 DEPDI,Z -1,%sar,1,%r19 ;offset 0x9d0
824 CMPB,*>>,N %r4,%r19,$D2 ;offset 0x9d4
825$00060012
826 SUBI 64,%r24,%r31 ;offset 0x9d8
827 CMPCLR,*<< %r4,%r3,%r0 ;offset 0x9dc
828 SUB %r4,%r3,%r4 ;offset 0x9e0
829$00060016
830 CMPB,= %r31,%r0,$0006001A ;offset 0x9e4
831 COPY %r0,%r9 ;offset 0x9e8
832 MTSARCM %r31 ;offset 0x9ec
833 DEPD,Z %r3,%sar,64,%r3 ;offset 0x9f0
834 SUBI 64,%r31,%r26 ;offset 0x9f4
835 MTSAR %r26 ;offset 0x9f8
836 SHRPD %r4,%r5,%sar,%r4 ;offset 0x9fc
837 MTSARCM %r31 ;offset 0xa00
838 DEPD,Z %r5,%sar,64,%r5 ;offset 0xa04
839$0006001A
840 DEPDI,Z -1,31,32,%r19 ;offset 0xa08
841 AND %r3,%r19,%r29 ;offset 0xa0c
842 EXTRD,U %r29,31,32,%r2 ;offset 0xa10
843 DEPDI,Z -1,63,32,%r6 ;offset 0xa14
844 MOVIB,TR 2,%r8,$0006001C ;offset 0xa18
845 EXTRD,U %r3,63,32,%r7 ;offset 0xa1c
846$D2
847 ;--- not PIC ADDIL LR'__iob-$global$,%r27,%r1 ;offset 0xa20
848 ;--- not PIC LDIL LR'C$7,%r21 ;offset 0xa24
849 ;--- not PIC LDO RR'__iob-$global$+32(%r1),%r26 ;offset 0xa28
850 ;--- not PIC .CALL ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR ;in=24,25,26;out=28;
851 ;--- not PIC B,L fprintf,%r2 ;offset 0xa2c
852 ;--- not PIC LDO RR'C$7(%r21),%r25 ;offset 0xa30
853 .CALL ;
854 B,L abort,%r2 ;offset 0xa34
855 NOP ;offset 0xa38
856 B $D3 ;offset 0xa3c
857 LDW -212(%r30),%r2 ;offset 0xa40
858$00060020
859 COPY %r4,%r26 ;offset 0xa44
860 EXTRD,U %r4,31,32,%r25 ;offset 0xa48
861 COPY %r2,%r24 ;offset 0xa4c
862 .CALL ;in=23,24,25,26;out=20,21,22,28,29; (MILLICALL)
863 B,L $$div2U,%r31 ;offset 0xa50
864 EXTRD,U %r2,31,32,%r23 ;offset 0xa54
865 DEPD %r28,31,32,%r29 ;offset 0xa58
866$00060022
867 STD %r29,-152(%r30) ;offset 0xa5c
868$D1
869 AND %r5,%r19,%r24 ;offset 0xa60
870 EXTRD,U %r24,31,32,%r24 ;offset 0xa64
871 STW %r2,-160(%r30) ;offset 0xa68
872 STW %r7,-128(%r30) ;offset 0xa6c
873 FLDD -152(%r30),%fr4 ;offset 0xa70
874 FLDD -152(%r30),%fr7 ;offset 0xa74
875 FLDW -160(%r30),%fr8L ;offset 0xa78
876 FLDW -128(%r30),%fr5L ;offset 0xa7c
877 XMPYU %fr8L,%fr7L,%fr10 ;offset 0xa80
878 FSTD %fr10,-136(%r30) ;offset 0xa84
879 XMPYU %fr8L,%fr7R,%fr22 ;offset 0xa88
880 FSTD %fr22,-144(%r30) ;offset 0xa8c
881 XMPYU %fr5L,%fr4L,%fr11 ;offset 0xa90
882 XMPYU %fr5L,%fr4R,%fr23 ;offset 0xa94
883 FSTD %fr11,-112(%r30) ;offset 0xa98
884 FSTD %fr23,-120(%r30) ;offset 0xa9c
885 LDD -136(%r30),%r28 ;offset 0xaa0
886 DEPD,Z %r28,31,32,%r31 ;offset 0xaa4
887 LDD -144(%r30),%r20 ;offset 0xaa8
888 ADD,L %r20,%r31,%r31 ;offset 0xaac
889 LDD -112(%r30),%r22 ;offset 0xab0
890 DEPD,Z %r22,31,32,%r22 ;offset 0xab4
891 LDD -120(%r30),%r21 ;offset 0xab8
892 B $00060024 ;offset 0xabc
893 ADD,L %r21,%r22,%r23 ;offset 0xac0
894$D0
895 OR %r9,%r29,%r29 ;offset 0xac4
896$00060040
897 EXTRD,U %r29,31,32,%r28 ;offset 0xac8
898$00060002
899$L2
900 LDW -212(%r30),%r2 ;offset 0xacc
901$D3
902 LDW -168(%r30),%r9 ;offset 0xad0
903 LDD -176(%r30),%r8 ;offset 0xad4
904 EXTRD,U %r8,31,32,%r7 ;offset 0xad8
905 LDD -184(%r30),%r6 ;offset 0xadc
906 EXTRD,U %r6,31,32,%r5 ;offset 0xae0
907 LDW -188(%r30),%r4 ;offset 0xae4
908 BVE (%r2) ;offset 0xae8
909 .EXIT
910 LDW,MB -192(%r30),%r3 ;offset 0xaec
911 .PROCEND ;in=23,25;out=28,29;fpin=105,107;
912
913
914
915
916;----------------------------------------------------------------------------
917;
918; Registers to hold 64-bit values to manipulate. The "L" part
919; of the register corresponds to the upper 32-bits, while the "R"
920; part corresponds to the lower 32-bits
921;
922; Note, that when using b6 and b7, the code must save these before
923; using them because they are callee save registers
924;
925;
926; Floating point registers to use to save values that
927; are manipulated. These don't collide with ftemp1-6 and
928; are all caller save registers
929;
930a0 .reg %fr22
931a0L .reg %fr22L
932a0R .reg %fr22R
933
934a1 .reg %fr23
935a1L .reg %fr23L
936a1R .reg %fr23R
937
938a2 .reg %fr24
939a2L .reg %fr24L
940a2R .reg %fr24R
941
942a3 .reg %fr25
943a3L .reg %fr25L
944a3R .reg %fr25R
945
946a4 .reg %fr26
947a4L .reg %fr26L
948a4R .reg %fr26R
949
950a5 .reg %fr27
951a5L .reg %fr27L
952a5R .reg %fr27R
953
954a6 .reg %fr28
955a6L .reg %fr28L
956a6R .reg %fr28R
957
958a7 .reg %fr29
959a7L .reg %fr29L
960a7R .reg %fr29R
961
962b0 .reg %fr30
963b0L .reg %fr30L
964b0R .reg %fr30R
965
966b1 .reg %fr31
967b1L .reg %fr31L
968b1R .reg %fr31R
969
970;
971; Temporary floating point variables, these are all caller save
972; registers
973;
974ftemp1 .reg %fr4
975ftemp2 .reg %fr5
976ftemp3 .reg %fr6
977ftemp4 .reg %fr7
978
979;
980; The B set of registers when used.
981;
982
983b2 .reg %fr8
984b2L .reg %fr8L
985b2R .reg %fr8R
986
987b3 .reg %fr9
988b3L .reg %fr9L
989b3R .reg %fr9R
990
991b4 .reg %fr10
992b4L .reg %fr10L
993b4R .reg %fr10R
994
995b5 .reg %fr11
996b5L .reg %fr11L
997b5R .reg %fr11R
998
999b6 .reg %fr12
1000b6L .reg %fr12L
1001b6R .reg %fr12R
1002
1003b7 .reg %fr13
1004b7L .reg %fr13L
1005b7R .reg %fr13R
1006
1007c1 .reg %r21 ; only reg
1008temp1 .reg %r20 ; only reg
1009temp2 .reg %r19 ; only reg
1010temp3 .reg %r31 ; only reg
1011
1012m1 .reg %r28
1013c2 .reg %r23
1014high_one .reg %r1
1015ht .reg %r6
1016lt .reg %r5
1017m .reg %r4
1018c3 .reg %r3
1019
1020SQR_ADD_C .macro A0L,A0R,C1,C2,C3
1021 XMPYU A0L,A0R,ftemp1 ; m
1022 FSTD ftemp1,-24(%sp) ; store m
1023
1024 XMPYU A0R,A0R,ftemp2 ; lt
1025 FSTD ftemp2,-16(%sp) ; store lt
1026
1027 XMPYU A0L,A0L,ftemp3 ; ht
1028 FSTD ftemp3,-8(%sp) ; store ht
1029
1030 LDD -24(%sp),m ; load m
1031 AND m,high_mask,temp2 ; m & Mask
1032 DEPD,Z m,30,31,temp3 ; m << 32+1
1033 LDD -16(%sp),lt ; lt
1034
1035 LDD -8(%sp),ht ; ht
1036 EXTRD,U temp2,32,33,temp1 ; temp1 = m&Mask >> 32-1
1037 ADD temp3,lt,lt ; lt = lt+m
1038 ADD,L ht,temp1,ht ; ht += temp1
1039 ADD,DC ht,%r0,ht ; ht++
1040
1041 ADD C1,lt,C1 ; c1=c1+lt
1042 ADD,DC ht,%r0,ht ; ht++
1043
1044 ADD C2,ht,C2 ; c2=c2+ht
1045 ADD,DC C3,%r0,C3 ; c3++
1046.endm
1047
1048SQR_ADD_C2 .macro A0L,A0R,A1L,A1R,C1,C2,C3
1049 XMPYU A0L,A1R,ftemp1 ; m1 = bl*ht
1050 FSTD ftemp1,-16(%sp) ;
1051 XMPYU A0R,A1L,ftemp2 ; m = bh*lt
1052 FSTD ftemp2,-8(%sp) ;
1053 XMPYU A0R,A1R,ftemp3 ; lt = bl*lt
1054 FSTD ftemp3,-32(%sp)
1055 XMPYU A0L,A1L,ftemp4 ; ht = bh*ht
1056 FSTD ftemp4,-24(%sp) ;
1057
1058 LDD -8(%sp),m ; r21 = m
1059 LDD -16(%sp),m1 ; r19 = m1
1060 ADD,L m,m1,m ; m+m1
1061
1062 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1063 LDD -24(%sp),ht ; r24 = ht
1064
1065 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1066 ADD,L ht,high_one,ht ; ht+=high_one
1067
1068 EXTRD,U m,31,32,temp1 ; m >> 32
1069 LDD -32(%sp),lt ; lt
1070 ADD,L ht,temp1,ht ; ht+= m>>32
1071 ADD lt,temp3,lt ; lt = lt+m1
1072 ADD,DC ht,%r0,ht ; ht++
1073
1074 ADD ht,ht,ht ; ht=ht+ht;
1075 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1076
1077 ADD lt,lt,lt ; lt=lt+lt;
1078 ADD,DC ht,%r0,ht ; add in carry (ht++)
1079
1080 ADD C1,lt,C1 ; c1=c1+lt
1081 ADD,DC,*NUV ht,%r0,ht ; add in carry (ht++)
1082 LDO 1(C3),C3 ; bump c3 if overflow,nullify otherwise
1083
1084 ADD C2,ht,C2 ; c2 = c2 + ht
1085 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1086.endm
1087
1088;
1089;void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
1090; arg0 = r_ptr
1091; arg1 = a_ptr
1092;
1093
1094bn_sqr_comba8
1095 .PROC
1096 .CALLINFO FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1097 .EXPORT bn_sqr_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1098 .ENTRY
1099 .align 64
1100
1101 STD %r3,0(%sp) ; save r3
1102 STD %r4,8(%sp) ; save r4
1103 STD %r5,16(%sp) ; save r5
1104 STD %r6,24(%sp) ; save r6
1105
1106 ;
1107 ; Zero out carries
1108 ;
1109 COPY %r0,c1
1110 COPY %r0,c2
1111 COPY %r0,c3
1112
1113 LDO 128(%sp),%sp ; bump stack
1114 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1115 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1116
1117 ;
1118 ; Load up all of the values we are going to use
1119 ;
1120 FLDD 0(a_ptr),a0
1121 FLDD 8(a_ptr),a1
1122 FLDD 16(a_ptr),a2
1123 FLDD 24(a_ptr),a3
1124 FLDD 32(a_ptr),a4
1125 FLDD 40(a_ptr),a5
1126 FLDD 48(a_ptr),a6
1127 FLDD 56(a_ptr),a7
1128
1129 SQR_ADD_C a0L,a0R,c1,c2,c3
1130 STD c1,0(r_ptr) ; r[0] = c1;
1131 COPY %r0,c1
1132
1133 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1134 STD c2,8(r_ptr) ; r[1] = c2;
1135 COPY %r0,c2
1136
1137 SQR_ADD_C a1L,a1R,c3,c1,c2
1138 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1139 STD c3,16(r_ptr) ; r[2] = c3;
1140 COPY %r0,c3
1141
1142 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1143 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1144 STD c1,24(r_ptr) ; r[3] = c1;
1145 COPY %r0,c1
1146
1147 SQR_ADD_C a2L,a2R,c2,c3,c1
1148 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1149 SQR_ADD_C2 a4L,a4R,a0L,a0R,c2,c3,c1
1150 STD c2,32(r_ptr) ; r[4] = c2;
1151 COPY %r0,c2
1152
1153 SQR_ADD_C2 a5L,a5R,a0L,a0R,c3,c1,c2
1154 SQR_ADD_C2 a4L,a4R,a1L,a1R,c3,c1,c2
1155 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1156 STD c3,40(r_ptr) ; r[5] = c3;
1157 COPY %r0,c3
1158
1159 SQR_ADD_C a3L,a3R,c1,c2,c3
1160 SQR_ADD_C2 a4L,a4R,a2L,a2R,c1,c2,c3
1161 SQR_ADD_C2 a5L,a5R,a1L,a1R,c1,c2,c3
1162 SQR_ADD_C2 a6L,a6R,a0L,a0R,c1,c2,c3
1163 STD c1,48(r_ptr) ; r[6] = c1;
1164 COPY %r0,c1
1165
1166 SQR_ADD_C2 a7L,a7R,a0L,a0R,c2,c3,c1
1167 SQR_ADD_C2 a6L,a6R,a1L,a1R,c2,c3,c1
1168 SQR_ADD_C2 a5L,a5R,a2L,a2R,c2,c3,c1
1169 SQR_ADD_C2 a4L,a4R,a3L,a3R,c2,c3,c1
1170 STD c2,56(r_ptr) ; r[7] = c2;
1171 COPY %r0,c2
1172
1173 SQR_ADD_C a4L,a4R,c3,c1,c2
1174 SQR_ADD_C2 a5L,a5R,a3L,a3R,c3,c1,c2
1175 SQR_ADD_C2 a6L,a6R,a2L,a2R,c3,c1,c2
1176 SQR_ADD_C2 a7L,a7R,a1L,a1R,c3,c1,c2
1177 STD c3,64(r_ptr) ; r[8] = c3;
1178 COPY %r0,c3
1179
1180 SQR_ADD_C2 a7L,a7R,a2L,a2R,c1,c2,c3
1181 SQR_ADD_C2 a6L,a6R,a3L,a3R,c1,c2,c3
1182 SQR_ADD_C2 a5L,a5R,a4L,a4R,c1,c2,c3
1183 STD c1,72(r_ptr) ; r[9] = c1;
1184 COPY %r0,c1
1185
1186 SQR_ADD_C a5L,a5R,c2,c3,c1
1187 SQR_ADD_C2 a6L,a6R,a4L,a4R,c2,c3,c1
1188 SQR_ADD_C2 a7L,a7R,a3L,a3R,c2,c3,c1
1189 STD c2,80(r_ptr) ; r[10] = c2;
1190 COPY %r0,c2
1191
1192 SQR_ADD_C2 a7L,a7R,a4L,a4R,c3,c1,c2
1193 SQR_ADD_C2 a6L,a6R,a5L,a5R,c3,c1,c2
1194 STD c3,88(r_ptr) ; r[11] = c3;
1195 COPY %r0,c3
1196
1197 SQR_ADD_C a6L,a6R,c1,c2,c3
1198 SQR_ADD_C2 a7L,a7R,a5L,a5R,c1,c2,c3
1199 STD c1,96(r_ptr) ; r[12] = c1;
1200 COPY %r0,c1
1201
1202 SQR_ADD_C2 a7L,a7R,a6L,a6R,c2,c3,c1
1203 STD c2,104(r_ptr) ; r[13] = c2;
1204 COPY %r0,c2
1205
1206 SQR_ADD_C a7L,a7R,c3,c1,c2
1207 STD c3, 112(r_ptr) ; r[14] = c3
1208 STD c1, 120(r_ptr) ; r[15] = c1
1209
1210 .EXIT
1211 LDD -104(%sp),%r6 ; restore r6
1212 LDD -112(%sp),%r5 ; restore r5
1213 LDD -120(%sp),%r4 ; restore r4
1214 BVE (%rp)
1215 LDD,MB -128(%sp),%r3
1216
1217 .PROCEND
1218
1219;-----------------------------------------------------------------------------
1220;
1221;void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
1222; arg0 = r_ptr
1223; arg1 = a_ptr
1224;
1225
1226bn_sqr_comba4
1227 .proc
1228 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1229 .EXPORT bn_sqr_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1230 .entry
1231 .align 64
1232 STD %r3,0(%sp) ; save r3
1233 STD %r4,8(%sp) ; save r4
1234 STD %r5,16(%sp) ; save r5
1235 STD %r6,24(%sp) ; save r6
1236
1237 ;
1238 ; Zero out carries
1239 ;
1240 COPY %r0,c1
1241 COPY %r0,c2
1242 COPY %r0,c3
1243
1244 LDO 128(%sp),%sp ; bump stack
1245 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1246 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1247
1248 ;
1249 ; Load up all of the values we are going to use
1250 ;
1251 FLDD 0(a_ptr),a0
1252 FLDD 8(a_ptr),a1
1253 FLDD 16(a_ptr),a2
1254 FLDD 24(a_ptr),a3
1255 FLDD 32(a_ptr),a4
1256 FLDD 40(a_ptr),a5
1257 FLDD 48(a_ptr),a6
1258 FLDD 56(a_ptr),a7
1259
1260 SQR_ADD_C a0L,a0R,c1,c2,c3
1261
1262 STD c1,0(r_ptr) ; r[0] = c1;
1263 COPY %r0,c1
1264
1265 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1266
1267 STD c2,8(r_ptr) ; r[1] = c2;
1268 COPY %r0,c2
1269
1270 SQR_ADD_C a1L,a1R,c3,c1,c2
1271 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1272
1273 STD c3,16(r_ptr) ; r[2] = c3;
1274 COPY %r0,c3
1275
1276 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1277 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1278
1279 STD c1,24(r_ptr) ; r[3] = c1;
1280 COPY %r0,c1
1281
1282 SQR_ADD_C a2L,a2R,c2,c3,c1
1283 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1284
1285 STD c2,32(r_ptr) ; r[4] = c2;
1286 COPY %r0,c2
1287
1288 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1289 STD c3,40(r_ptr) ; r[5] = c3;
1290 COPY %r0,c3
1291
1292 SQR_ADD_C a3L,a3R,c1,c2,c3
1293 STD c1,48(r_ptr) ; r[6] = c1;
1294 STD c2,56(r_ptr) ; r[7] = c2;
1295
1296 .EXIT
1297 LDD -104(%sp),%r6 ; restore r6
1298 LDD -112(%sp),%r5 ; restore r5
1299 LDD -120(%sp),%r4 ; restore r4
1300 BVE (%rp)
1301 LDD,MB -128(%sp),%r3
1302
1303 .PROCEND
1304
1305
1306;---------------------------------------------------------------------------
1307
1308MUL_ADD_C .macro A0L,A0R,B0L,B0R,C1,C2,C3
1309 XMPYU A0L,B0R,ftemp1 ; m1 = bl*ht
1310 FSTD ftemp1,-16(%sp) ;
1311 XMPYU A0R,B0L,ftemp2 ; m = bh*lt
1312 FSTD ftemp2,-8(%sp) ;
1313 XMPYU A0R,B0R,ftemp3 ; lt = bl*lt
1314 FSTD ftemp3,-32(%sp)
1315 XMPYU A0L,B0L,ftemp4 ; ht = bh*ht
1316 FSTD ftemp4,-24(%sp) ;
1317
1318 LDD -8(%sp),m ; r21 = m
1319 LDD -16(%sp),m1 ; r19 = m1
1320 ADD,L m,m1,m ; m+m1
1321
1322 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1323 LDD -24(%sp),ht ; r24 = ht
1324
1325 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1326 ADD,L ht,high_one,ht ; ht+=high_one
1327
1328 EXTRD,U m,31,32,temp1 ; m >> 32
1329 LDD -32(%sp),lt ; lt
1330 ADD,L ht,temp1,ht ; ht+= m>>32
1331 ADD lt,temp3,lt ; lt = lt+m1
1332 ADD,DC ht,%r0,ht ; ht++
1333
1334 ADD C1,lt,C1 ; c1=c1+lt
1335 ADD,DC ht,%r0,ht ; bump c3 if overflow,nullify otherwise
1336
1337 ADD C2,ht,C2 ; c2 = c2 + ht
1338 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1339.endm
1340
1341
1342;
1343;void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1344; arg0 = r_ptr
1345; arg1 = a_ptr
1346; arg2 = b_ptr
1347;
1348
1349bn_mul_comba8
1350 .proc
1351 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1352 .EXPORT bn_mul_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1353 .entry
1354 .align 64
1355
1356 STD %r3,0(%sp) ; save r3
1357 STD %r4,8(%sp) ; save r4
1358 STD %r5,16(%sp) ; save r5
1359 STD %r6,24(%sp) ; save r6
1360 FSTD %fr12,32(%sp) ; save r6
1361 FSTD %fr13,40(%sp) ; save r7
1362
1363 ;
1364 ; Zero out carries
1365 ;
1366 COPY %r0,c1
1367 COPY %r0,c2
1368 COPY %r0,c3
1369
1370 LDO 128(%sp),%sp ; bump stack
1371 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1372
1373 ;
1374 ; Load up all of the values we are going to use
1375 ;
1376 FLDD 0(a_ptr),a0
1377 FLDD 8(a_ptr),a1
1378 FLDD 16(a_ptr),a2
1379 FLDD 24(a_ptr),a3
1380 FLDD 32(a_ptr),a4
1381 FLDD 40(a_ptr),a5
1382 FLDD 48(a_ptr),a6
1383 FLDD 56(a_ptr),a7
1384
1385 FLDD 0(b_ptr),b0
1386 FLDD 8(b_ptr),b1
1387 FLDD 16(b_ptr),b2
1388 FLDD 24(b_ptr),b3
1389 FLDD 32(b_ptr),b4
1390 FLDD 40(b_ptr),b5
1391 FLDD 48(b_ptr),b6
1392 FLDD 56(b_ptr),b7
1393
1394 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1395 STD c1,0(r_ptr)
1396 COPY %r0,c1
1397
1398 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1399 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1400 STD c2,8(r_ptr)
1401 COPY %r0,c2
1402
1403 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1404 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1405 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1406 STD c3,16(r_ptr)
1407 COPY %r0,c3
1408
1409 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1410 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1411 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1412 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1413 STD c1,24(r_ptr)
1414 COPY %r0,c1
1415
1416 MUL_ADD_C a4L,a4R,b0L,b0R,c2,c3,c1
1417 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1418 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1419 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1420 MUL_ADD_C a0L,a0R,b4L,b4R,c2,c3,c1
1421 STD c2,32(r_ptr)
1422 COPY %r0,c2
1423
1424 MUL_ADD_C a0L,a0R,b5L,b5R,c3,c1,c2
1425 MUL_ADD_C a1L,a1R,b4L,b4R,c3,c1,c2
1426 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1427 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1428 MUL_ADD_C a4L,a4R,b1L,b1R,c3,c1,c2
1429 MUL_ADD_C a5L,a5R,b0L,b0R,c3,c1,c2
1430 STD c3,40(r_ptr)
1431 COPY %r0,c3
1432
1433 MUL_ADD_C a6L,a6R,b0L,b0R,c1,c2,c3
1434 MUL_ADD_C a5L,a5R,b1L,b1R,c1,c2,c3
1435 MUL_ADD_C a4L,a4R,b2L,b2R,c1,c2,c3
1436 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1437 MUL_ADD_C a2L,a2R,b4L,b4R,c1,c2,c3
1438 MUL_ADD_C a1L,a1R,b5L,b5R,c1,c2,c3
1439 MUL_ADD_C a0L,a0R,b6L,b6R,c1,c2,c3
1440 STD c1,48(r_ptr)
1441 COPY %r0,c1
1442
1443 MUL_ADD_C a0L,a0R,b7L,b7R,c2,c3,c1
1444 MUL_ADD_C a1L,a1R,b6L,b6R,c2,c3,c1
1445 MUL_ADD_C a2L,a2R,b5L,b5R,c2,c3,c1
1446 MUL_ADD_C a3L,a3R,b4L,b4R,c2,c3,c1
1447 MUL_ADD_C a4L,a4R,b3L,b3R,c2,c3,c1
1448 MUL_ADD_C a5L,a5R,b2L,b2R,c2,c3,c1
1449 MUL_ADD_C a6L,a6R,b1L,b1R,c2,c3,c1
1450 MUL_ADD_C a7L,a7R,b0L,b0R,c2,c3,c1
1451 STD c2,56(r_ptr)
1452 COPY %r0,c2
1453
1454 MUL_ADD_C a7L,a7R,b1L,b1R,c3,c1,c2
1455 MUL_ADD_C a6L,a6R,b2L,b2R,c3,c1,c2
1456 MUL_ADD_C a5L,a5R,b3L,b3R,c3,c1,c2
1457 MUL_ADD_C a4L,a4R,b4L,b4R,c3,c1,c2
1458 MUL_ADD_C a3L,a3R,b5L,b5R,c3,c1,c2
1459 MUL_ADD_C a2L,a2R,b6L,b6R,c3,c1,c2
1460 MUL_ADD_C a1L,a1R,b7L,b7R,c3,c1,c2
1461 STD c3,64(r_ptr)
1462 COPY %r0,c3
1463
1464 MUL_ADD_C a2L,a2R,b7L,b7R,c1,c2,c3
1465 MUL_ADD_C a3L,a3R,b6L,b6R,c1,c2,c3
1466 MUL_ADD_C a4L,a4R,b5L,b5R,c1,c2,c3
1467 MUL_ADD_C a5L,a5R,b4L,b4R,c1,c2,c3
1468 MUL_ADD_C a6L,a6R,b3L,b3R,c1,c2,c3
1469 MUL_ADD_C a7L,a7R,b2L,b2R,c1,c2,c3
1470 STD c1,72(r_ptr)
1471 COPY %r0,c1
1472
1473 MUL_ADD_C a7L,a7R,b3L,b3R,c2,c3,c1
1474 MUL_ADD_C a6L,a6R,b4L,b4R,c2,c3,c1
1475 MUL_ADD_C a5L,a5R,b5L,b5R,c2,c3,c1
1476 MUL_ADD_C a4L,a4R,b6L,b6R,c2,c3,c1
1477 MUL_ADD_C a3L,a3R,b7L,b7R,c2,c3,c1
1478 STD c2,80(r_ptr)
1479 COPY %r0,c2
1480
1481 MUL_ADD_C a4L,a4R,b7L,b7R,c3,c1,c2
1482 MUL_ADD_C a5L,a5R,b6L,b6R,c3,c1,c2
1483 MUL_ADD_C a6L,a6R,b5L,b5R,c3,c1,c2
1484 MUL_ADD_C a7L,a7R,b4L,b4R,c3,c1,c2
1485 STD c3,88(r_ptr)
1486 COPY %r0,c3
1487
1488 MUL_ADD_C a7L,a7R,b5L,b5R,c1,c2,c3
1489 MUL_ADD_C a6L,a6R,b6L,b6R,c1,c2,c3
1490 MUL_ADD_C a5L,a5R,b7L,b7R,c1,c2,c3
1491 STD c1,96(r_ptr)
1492 COPY %r0,c1
1493
1494 MUL_ADD_C a6L,a6R,b7L,b7R,c2,c3,c1
1495 MUL_ADD_C a7L,a7R,b6L,b6R,c2,c3,c1
1496 STD c2,104(r_ptr)
1497 COPY %r0,c2
1498
1499 MUL_ADD_C a7L,a7R,b7L,b7R,c3,c1,c2
1500 STD c3,112(r_ptr)
1501 STD c1,120(r_ptr)
1502
1503 .EXIT
1504 FLDD -88(%sp),%fr13
1505 FLDD -96(%sp),%fr12
1506 LDD -104(%sp),%r6 ; restore r6
1507 LDD -112(%sp),%r5 ; restore r5
1508 LDD -120(%sp),%r4 ; restore r4
1509 BVE (%rp)
1510 LDD,MB -128(%sp),%r3
1511
1512 .PROCEND
1513
1514;-----------------------------------------------------------------------------
1515;
1516;void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1517; arg0 = r_ptr
1518; arg1 = a_ptr
1519; arg2 = b_ptr
1520;
1521
1522bn_mul_comba4
1523 .proc
1524 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1525 .EXPORT bn_mul_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1526 .entry
1527 .align 64
1528
1529 STD %r3,0(%sp) ; save r3
1530 STD %r4,8(%sp) ; save r4
1531 STD %r5,16(%sp) ; save r5
1532 STD %r6,24(%sp) ; save r6
1533 FSTD %fr12,32(%sp) ; save r6
1534 FSTD %fr13,40(%sp) ; save r7
1535
1536 ;
1537 ; Zero out carries
1538 ;
1539 COPY %r0,c1
1540 COPY %r0,c2
1541 COPY %r0,c3
1542
1543 LDO 128(%sp),%sp ; bump stack
1544 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1545
1546 ;
1547 ; Load up all of the values we are going to use
1548 ;
1549 FLDD 0(a_ptr),a0
1550 FLDD 8(a_ptr),a1
1551 FLDD 16(a_ptr),a2
1552 FLDD 24(a_ptr),a3
1553
1554 FLDD 0(b_ptr),b0
1555 FLDD 8(b_ptr),b1
1556 FLDD 16(b_ptr),b2
1557 FLDD 24(b_ptr),b3
1558
1559 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1560 STD c1,0(r_ptr)
1561 COPY %r0,c1
1562
1563 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1564 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1565 STD c2,8(r_ptr)
1566 COPY %r0,c2
1567
1568 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1569 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1570 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1571 STD c3,16(r_ptr)
1572 COPY %r0,c3
1573
1574 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1575 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1576 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1577 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1578 STD c1,24(r_ptr)
1579 COPY %r0,c1
1580
1581 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1582 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1583 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1584 STD c2,32(r_ptr)
1585 COPY %r0,c2
1586
1587 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1588 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1589 STD c3,40(r_ptr)
1590 COPY %r0,c3
1591
1592 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1593 STD c1,48(r_ptr)
1594 STD c2,56(r_ptr)
1595
1596 .EXIT
1597 FLDD -88(%sp),%fr13
1598 FLDD -96(%sp),%fr12
1599 LDD -104(%sp),%r6 ; restore r6
1600 LDD -112(%sp),%r5 ; restore r5
1601 LDD -120(%sp),%r4 ; restore r4
1602 BVE (%rp)
1603 LDD,MB -128(%sp),%r3
1604
1605 .PROCEND
1606
1607
1608;--- not PIC .SPACE $TEXT$
1609;--- not PIC .SUBSPA $CODE$
1610;--- not PIC .SPACE $PRIVATE$,SORT=16
1611;--- not PIC .IMPORT $global$,DATA
1612;--- not PIC .SPACE $TEXT$
1613;--- not PIC .SUBSPA $CODE$
1614;--- not PIC .SUBSPA $LIT$,ACCESS=0x2c
1615;--- not PIC C$7
1616;--- not PIC .ALIGN 8
1617;--- not PIC .STRINGZ "Division would overflow (%d)\n"
1618 .END
diff --git a/src/lib/libcrypto/bn/asm/pa-risc2W.s b/src/lib/libcrypto/bn/asm/pa-risc2W.s
deleted file mode 100644
index a99545754d..0000000000
--- a/src/lib/libcrypto/bn/asm/pa-risc2W.s
+++ /dev/null
@@ -1,1605 +0,0 @@
1;
2; PA-RISC 64-bit implementation of bn_asm code
3;
4; This code is approximately 2x faster than the C version
5; for RSA/DSA.
6;
7; See http://devresource.hp.com/ for more details on the PA-RISC
8; architecture. Also see the book "PA-RISC 2.0 Architecture"
9; by Gerry Kane for information on the instruction set architecture.
10;
11; Code written by Chris Ruemmler (with some help from the HP C
12; compiler).
13;
14; The code compiles with HP's assembler
15;
16
17 .level 2.0W
18 .space $TEXT$
19 .subspa $CODE$,QUAD=0,ALIGN=8,ACCESS=0x2c,CODE_ONLY
20
21;
22; Global Register definitions used for the routines.
23;
24; Some information about HP's runtime architecture for 64-bits.
25;
26; "Caller save" means the calling function must save the register
27; if it wants the register to be preserved.
28; "Callee save" means if a function uses the register, it must save
29; the value before using it.
30;
31; For the floating point registers
32;
33; "caller save" registers: fr4-fr11, fr22-fr31
34; "callee save" registers: fr12-fr21
35; "special" registers: fr0-fr3 (status and exception registers)
36;
37; For the integer registers
38; value zero : r0
39; "caller save" registers: r1,r19-r26
40; "callee save" registers: r3-r18
41; return register : r2 (rp)
42; return values ; r28 (ret0,ret1)
43; Stack pointer ; r30 (sp)
44; global data pointer ; r27 (dp)
45; argument pointer ; r29 (ap)
46; millicode return ptr ; r31 (also a caller save register)
47
48
49;
50; Arguments to the routines
51;
52r_ptr .reg %r26
53a_ptr .reg %r25
54b_ptr .reg %r24
55num .reg %r24
56w .reg %r23
57n .reg %r23
58
59
60;
61; Globals used in some routines
62;
63
64top_overflow .reg %r29
65high_mask .reg %r22 ; value 0xffffffff80000000L
66
67
68;------------------------------------------------------------------------------
69;
70; bn_mul_add_words
71;
72;BN_ULONG bn_mul_add_words(BN_ULONG *r_ptr, BN_ULONG *a_ptr,
73; int num, BN_ULONG w)
74;
75; arg0 = r_ptr
76; arg1 = a_ptr
77; arg2 = num
78; arg3 = w
79;
80; Local register definitions
81;
82
83fm1 .reg %fr22
84fm .reg %fr23
85ht_temp .reg %fr24
86ht_temp_1 .reg %fr25
87lt_temp .reg %fr26
88lt_temp_1 .reg %fr27
89fm1_1 .reg %fr28
90fm_1 .reg %fr29
91
92fw_h .reg %fr7L
93fw_l .reg %fr7R
94fw .reg %fr7
95
96fht_0 .reg %fr8L
97flt_0 .reg %fr8R
98t_float_0 .reg %fr8
99
100fht_1 .reg %fr9L
101flt_1 .reg %fr9R
102t_float_1 .reg %fr9
103
104tmp_0 .reg %r31
105tmp_1 .reg %r21
106m_0 .reg %r20
107m_1 .reg %r19
108ht_0 .reg %r1
109ht_1 .reg %r3
110lt_0 .reg %r4
111lt_1 .reg %r5
112m1_0 .reg %r6
113m1_1 .reg %r7
114rp_val .reg %r8
115rp_val_1 .reg %r9
116
117bn_mul_add_words
118 .export bn_mul_add_words,entry,NO_RELOCATION,LONG_RETURN
119 .proc
120 .callinfo frame=128
121 .entry
122 .align 64
123
124 STD %r3,0(%sp) ; save r3
125 STD %r4,8(%sp) ; save r4
126 NOP ; Needed to make the loop 16-byte aligned
127 NOP ; Needed to make the loop 16-byte aligned
128
129 STD %r5,16(%sp) ; save r5
130 STD %r6,24(%sp) ; save r6
131 STD %r7,32(%sp) ; save r7
132 STD %r8,40(%sp) ; save r8
133
134 STD %r9,48(%sp) ; save r9
135 COPY %r0,%ret0 ; return 0 by default
136 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
137 STD w,56(%sp) ; store w on stack
138
139 CMPIB,>= 0,num,bn_mul_add_words_exit ; if (num <= 0) then exit
140 LDO 128(%sp),%sp ; bump stack
141
142 ;
143 ; The loop is unrolled twice, so if there is only 1 number
144 ; then go straight to the cleanup code.
145 ;
146 CMPIB,= 1,num,bn_mul_add_words_single_top
147 FLDD -72(%sp),fw ; load up w into fp register fw (fw_h/fw_l)
148
149 ;
150 ; This loop is unrolled 2 times (64-byte aligned as well)
151 ;
152 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
153 ; two 32-bit mutiplies can be issued per cycle.
154 ;
155bn_mul_add_words_unroll2
156
157 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
158 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
159 LDD 0(r_ptr),rp_val ; rp[0]
160 LDD 8(r_ptr),rp_val_1 ; rp[1]
161
162 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
163 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = fht_1*fw_l
164 FSTD fm1,-16(%sp) ; -16(sp) = m1[0]
165 FSTD fm1_1,-48(%sp) ; -48(sp) = m1[1]
166
167 XMPYU flt_0,fw_h,fm ; m[0] = flt_0*fw_h
168 XMPYU flt_1,fw_h,fm_1 ; m[1] = flt_1*fw_h
169 FSTD fm,-8(%sp) ; -8(sp) = m[0]
170 FSTD fm_1,-40(%sp) ; -40(sp) = m[1]
171
172 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
173 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp_1 = fht_1*fw_h
174 FSTD ht_temp,-24(%sp) ; -24(sp) = ht_temp
175 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht_temp_1
176
177 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
178 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
179 FSTD lt_temp,-32(%sp) ; -32(sp) = lt_temp
180 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt_temp_1
181
182 LDD -8(%sp),m_0 ; m[0]
183 LDD -40(%sp),m_1 ; m[1]
184 LDD -16(%sp),m1_0 ; m1[0]
185 LDD -48(%sp),m1_1 ; m1[1]
186
187 LDD -24(%sp),ht_0 ; ht[0]
188 LDD -56(%sp),ht_1 ; ht[1]
189 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m[0] + m1[0];
190 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m[1] + m1[1];
191
192 LDD -32(%sp),lt_0
193 LDD -64(%sp),lt_1
194 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m[0] < m1[0])
195 ADD,L ht_0,top_overflow,ht_0 ; ht[0] += (1<<32)
196
197 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m[1] < m1[1])
198 ADD,L ht_1,top_overflow,ht_1 ; ht[1] += (1<<32)
199 EXTRD,U tmp_0,31,32,m_0 ; m[0]>>32
200 DEPD,Z tmp_0,31,32,m1_0 ; m1[0] = m[0]<<32
201
202 EXTRD,U tmp_1,31,32,m_1 ; m[1]>>32
203 DEPD,Z tmp_1,31,32,m1_1 ; m1[1] = m[1]<<32
204 ADD,L ht_0,m_0,ht_0 ; ht[0]+= (m[0]>>32)
205 ADD,L ht_1,m_1,ht_1 ; ht[1]+= (m[1]>>32)
206
207 ADD lt_0,m1_0,lt_0 ; lt[0] = lt[0]+m1[0];
208 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
209 ADD lt_1,m1_1,lt_1 ; lt[1] = lt[1]+m1[1];
210 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
211
212 ADD %ret0,lt_0,lt_0 ; lt[0] = lt[0] + c;
213 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
214 ADD lt_0,rp_val,lt_0 ; lt[0] = lt[0]+rp[0]
215 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
216
217 LDO -2(num),num ; num = num - 2;
218 ADD ht_0,lt_1,lt_1 ; lt[1] = lt[1] + ht_0 (c);
219 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
220 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
221
222 ADD lt_1,rp_val_1,lt_1 ; lt[1] = lt[1]+rp[1]
223 ADD,DC ht_1,%r0,%ret0 ; ht[1]++
224 LDO 16(a_ptr),a_ptr ; a_ptr += 2
225
226 STD lt_1,8(r_ptr) ; rp[1] = lt[1]
227 CMPIB,<= 2,num,bn_mul_add_words_unroll2 ; go again if more to do
228 LDO 16(r_ptr),r_ptr ; r_ptr += 2
229
230 CMPIB,=,N 0,num,bn_mul_add_words_exit ; are we done, or cleanup last one
231
232 ;
233 ; Top of loop aligned on 64-byte boundary
234 ;
235bn_mul_add_words_single_top
236 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
237 LDD 0(r_ptr),rp_val ; rp[0]
238 LDO 8(a_ptr),a_ptr ; a_ptr++
239 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
240 FSTD fm1,-16(%sp) ; -16(sp) = m1
241 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
242 FSTD fm,-8(%sp) ; -8(sp) = m
243 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
244 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
245 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
246 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
247
248 LDD -8(%sp),m_0
249 LDD -16(%sp),m1_0 ; m1 = temp1
250 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
251 LDD -24(%sp),ht_0
252 LDD -32(%sp),lt_0
253
254 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
255 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
256
257 EXTRD,U tmp_0,31,32,m_0 ; m>>32
258 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
259
260 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
261 ADD lt_0,m1_0,tmp_0 ; tmp_0 = lt+m1;
262 ADD,DC ht_0,%r0,ht_0 ; ht++
263 ADD %ret0,tmp_0,lt_0 ; lt = lt + c;
264 ADD,DC ht_0,%r0,ht_0 ; ht++
265 ADD lt_0,rp_val,lt_0 ; lt = lt+rp[0]
266 ADD,DC ht_0,%r0,%ret0 ; ht++
267 STD lt_0,0(r_ptr) ; rp[0] = lt
268
269bn_mul_add_words_exit
270 .EXIT
271 LDD -80(%sp),%r9 ; restore r9
272 LDD -88(%sp),%r8 ; restore r8
273 LDD -96(%sp),%r7 ; restore r7
274 LDD -104(%sp),%r6 ; restore r6
275 LDD -112(%sp),%r5 ; restore r5
276 LDD -120(%sp),%r4 ; restore r4
277 BVE (%rp)
278 LDD,MB -128(%sp),%r3 ; restore r3
279 .PROCEND ;in=23,24,25,26,29;out=28;
280
281;----------------------------------------------------------------------------
282;
283;BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
284;
285; arg0 = rp
286; arg1 = ap
287; arg2 = num
288; arg3 = w
289
290bn_mul_words
291 .proc
292 .callinfo frame=128
293 .entry
294 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
295 .align 64
296
297 STD %r3,0(%sp) ; save r3
298 STD %r4,8(%sp) ; save r4
299 STD %r5,16(%sp) ; save r5
300 STD %r6,24(%sp) ; save r6
301
302 STD %r7,32(%sp) ; save r7
303 COPY %r0,%ret0 ; return 0 by default
304 DEPDI,Z 1,31,1,top_overflow ; top_overflow = 1 << 32
305 STD w,56(%sp) ; w on stack
306
307 CMPIB,>= 0,num,bn_mul_words_exit
308 LDO 128(%sp),%sp ; bump stack
309
310 ;
311 ; See if only 1 word to do, thus just do cleanup
312 ;
313 CMPIB,= 1,num,bn_mul_words_single_top
314 FLDD -72(%sp),fw ; load up w into fp register fw (fw_h/fw_l)
315
316 ;
317 ; This loop is unrolled 2 times (64-byte aligned as well)
318 ;
319 ; PA-RISC 2.0 chips have two fully pipelined multipliers, thus
320 ; two 32-bit mutiplies can be issued per cycle.
321 ;
322bn_mul_words_unroll2
323
324 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
325 FLDD 8(a_ptr),t_float_1 ; load up 64-bit value (fr8L) ht(L)/lt(R)
326 XMPYU fht_0,fw_l,fm1 ; m1[0] = fht_0*fw_l
327 XMPYU fht_1,fw_l,fm1_1 ; m1[1] = ht*fw_l
328
329 FSTD fm1,-16(%sp) ; -16(sp) = m1
330 FSTD fm1_1,-48(%sp) ; -48(sp) = m1
331 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
332 XMPYU flt_1,fw_h,fm_1 ; m = lt*fw_h
333
334 FSTD fm,-8(%sp) ; -8(sp) = m
335 FSTD fm_1,-40(%sp) ; -40(sp) = m
336 XMPYU fht_0,fw_h,ht_temp ; ht_temp = fht_0*fw_h
337 XMPYU fht_1,fw_h,ht_temp_1 ; ht_temp = ht*fw_h
338
339 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
340 FSTD ht_temp_1,-56(%sp) ; -56(sp) = ht
341 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
342 XMPYU flt_1,fw_l,lt_temp_1 ; lt_temp = lt*fw_l
343
344 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
345 FSTD lt_temp_1,-64(%sp) ; -64(sp) = lt
346 LDD -8(%sp),m_0
347 LDD -40(%sp),m_1
348
349 LDD -16(%sp),m1_0
350 LDD -48(%sp),m1_1
351 LDD -24(%sp),ht_0
352 LDD -56(%sp),ht_1
353
354 ADD,L m1_0,m_0,tmp_0 ; tmp_0 = m + m1;
355 ADD,L m1_1,m_1,tmp_1 ; tmp_1 = m + m1;
356 LDD -32(%sp),lt_0
357 LDD -64(%sp),lt_1
358
359 CMPCLR,*>>= tmp_0,m1_0, %r0 ; if (m < m1)
360 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
361 CMPCLR,*>>= tmp_1,m1_1,%r0 ; if (m < m1)
362 ADD,L ht_1,top_overflow,ht_1 ; ht += (1<<32)
363
364 EXTRD,U tmp_0,31,32,m_0 ; m>>32
365 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
366 EXTRD,U tmp_1,31,32,m_1 ; m>>32
367 DEPD,Z tmp_1,31,32,m1_1 ; m1 = m<<32
368
369 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
370 ADD,L ht_1,m_1,ht_1 ; ht+= (m>>32)
371 ADD lt_0,m1_0,lt_0 ; lt = lt+m1;
372 ADD,DC ht_0,%r0,ht_0 ; ht++
373
374 ADD lt_1,m1_1,lt_1 ; lt = lt+m1;
375 ADD,DC ht_1,%r0,ht_1 ; ht++
376 ADD %ret0,lt_0,lt_0 ; lt = lt + c (ret0);
377 ADD,DC ht_0,%r0,ht_0 ; ht++
378
379 ADD ht_0,lt_1,lt_1 ; lt = lt + c (ht_0)
380 ADD,DC ht_1,%r0,ht_1 ; ht++
381 STD lt_0,0(r_ptr) ; rp[0] = lt
382 STD lt_1,8(r_ptr) ; rp[1] = lt
383
384 COPY ht_1,%ret0 ; carry = ht
385 LDO -2(num),num ; num = num - 2;
386 LDO 16(a_ptr),a_ptr ; ap += 2
387 CMPIB,<= 2,num,bn_mul_words_unroll2
388 LDO 16(r_ptr),r_ptr ; rp++
389
390 CMPIB,=,N 0,num,bn_mul_words_exit ; are we done?
391
392 ;
393 ; Top of loop aligned on 64-byte boundary
394 ;
395bn_mul_words_single_top
396 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
397
398 XMPYU fht_0,fw_l,fm1 ; m1 = ht*fw_l
399 FSTD fm1,-16(%sp) ; -16(sp) = m1
400 XMPYU flt_0,fw_h,fm ; m = lt*fw_h
401 FSTD fm,-8(%sp) ; -8(sp) = m
402 XMPYU fht_0,fw_h,ht_temp ; ht_temp = ht*fw_h
403 FSTD ht_temp,-24(%sp) ; -24(sp) = ht
404 XMPYU flt_0,fw_l,lt_temp ; lt_temp = lt*fw_l
405 FSTD lt_temp,-32(%sp) ; -32(sp) = lt
406
407 LDD -8(%sp),m_0
408 LDD -16(%sp),m1_0
409 ADD,L m_0,m1_0,tmp_0 ; tmp_0 = m + m1;
410 LDD -24(%sp),ht_0
411 LDD -32(%sp),lt_0
412
413 CMPCLR,*>>= tmp_0,m1_0,%r0 ; if (m < m1)
414 ADD,L ht_0,top_overflow,ht_0 ; ht += (1<<32)
415
416 EXTRD,U tmp_0,31,32,m_0 ; m>>32
417 DEPD,Z tmp_0,31,32,m1_0 ; m1 = m<<32
418
419 ADD,L ht_0,m_0,ht_0 ; ht+= (m>>32)
420 ADD lt_0,m1_0,lt_0 ; lt= lt+m1;
421 ADD,DC ht_0,%r0,ht_0 ; ht++
422
423 ADD %ret0,lt_0,lt_0 ; lt = lt + c;
424 ADD,DC ht_0,%r0,ht_0 ; ht++
425
426 COPY ht_0,%ret0 ; copy carry
427 STD lt_0,0(r_ptr) ; rp[0] = lt
428
429bn_mul_words_exit
430 .EXIT
431 LDD -96(%sp),%r7 ; restore r7
432 LDD -104(%sp),%r6 ; restore r6
433 LDD -112(%sp),%r5 ; restore r5
434 LDD -120(%sp),%r4 ; restore r4
435 BVE (%rp)
436 LDD,MB -128(%sp),%r3 ; restore r3
437 .PROCEND ;in=23,24,25,26,29;out=28;
438
439;----------------------------------------------------------------------------
440;
441;void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num)
442;
443; arg0 = rp
444; arg1 = ap
445; arg2 = num
446;
447
448bn_sqr_words
449 .proc
450 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
451 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
452 .entry
453 .align 64
454
455 STD %r3,0(%sp) ; save r3
456 STD %r4,8(%sp) ; save r4
457 NOP
458 STD %r5,16(%sp) ; save r5
459
460 CMPIB,>= 0,num,bn_sqr_words_exit
461 LDO 128(%sp),%sp ; bump stack
462
463 ;
464 ; If only 1, the goto straight to cleanup
465 ;
466 CMPIB,= 1,num,bn_sqr_words_single_top
467 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
468
469 ;
470 ; This loop is unrolled 2 times (64-byte aligned as well)
471 ;
472
473bn_sqr_words_unroll2
474 FLDD 0(a_ptr),t_float_0 ; a[0]
475 FLDD 8(a_ptr),t_float_1 ; a[1]
476 XMPYU fht_0,flt_0,fm ; m[0]
477 XMPYU fht_1,flt_1,fm_1 ; m[1]
478
479 FSTD fm,-24(%sp) ; store m[0]
480 FSTD fm_1,-56(%sp) ; store m[1]
481 XMPYU flt_0,flt_0,lt_temp ; lt[0]
482 XMPYU flt_1,flt_1,lt_temp_1 ; lt[1]
483
484 FSTD lt_temp,-16(%sp) ; store lt[0]
485 FSTD lt_temp_1,-48(%sp) ; store lt[1]
486 XMPYU fht_0,fht_0,ht_temp ; ht[0]
487 XMPYU fht_1,fht_1,ht_temp_1 ; ht[1]
488
489 FSTD ht_temp,-8(%sp) ; store ht[0]
490 FSTD ht_temp_1,-40(%sp) ; store ht[1]
491 LDD -24(%sp),m_0
492 LDD -56(%sp),m_1
493
494 AND m_0,high_mask,tmp_0 ; m[0] & Mask
495 AND m_1,high_mask,tmp_1 ; m[1] & Mask
496 DEPD,Z m_0,30,31,m_0 ; m[0] << 32+1
497 DEPD,Z m_1,30,31,m_1 ; m[1] << 32+1
498
499 LDD -16(%sp),lt_0
500 LDD -48(%sp),lt_1
501 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m[0]&Mask >> 32-1
502 EXTRD,U tmp_1,32,33,tmp_1 ; tmp_1 = m[1]&Mask >> 32-1
503
504 LDD -8(%sp),ht_0
505 LDD -40(%sp),ht_1
506 ADD,L ht_0,tmp_0,ht_0 ; ht[0] += tmp_0
507 ADD,L ht_1,tmp_1,ht_1 ; ht[1] += tmp_1
508
509 ADD lt_0,m_0,lt_0 ; lt = lt+m
510 ADD,DC ht_0,%r0,ht_0 ; ht[0]++
511 STD lt_0,0(r_ptr) ; rp[0] = lt[0]
512 STD ht_0,8(r_ptr) ; rp[1] = ht[1]
513
514 ADD lt_1,m_1,lt_1 ; lt = lt+m
515 ADD,DC ht_1,%r0,ht_1 ; ht[1]++
516 STD lt_1,16(r_ptr) ; rp[2] = lt[1]
517 STD ht_1,24(r_ptr) ; rp[3] = ht[1]
518
519 LDO -2(num),num ; num = num - 2;
520 LDO 16(a_ptr),a_ptr ; ap += 2
521 CMPIB,<= 2,num,bn_sqr_words_unroll2
522 LDO 32(r_ptr),r_ptr ; rp += 4
523
524 CMPIB,=,N 0,num,bn_sqr_words_exit ; are we done?
525
526 ;
527 ; Top of loop aligned on 64-byte boundary
528 ;
529bn_sqr_words_single_top
530 FLDD 0(a_ptr),t_float_0 ; load up 64-bit value (fr8L) ht(L)/lt(R)
531
532 XMPYU fht_0,flt_0,fm ; m
533 FSTD fm,-24(%sp) ; store m
534
535 XMPYU flt_0,flt_0,lt_temp ; lt
536 FSTD lt_temp,-16(%sp) ; store lt
537
538 XMPYU fht_0,fht_0,ht_temp ; ht
539 FSTD ht_temp,-8(%sp) ; store ht
540
541 LDD -24(%sp),m_0 ; load m
542 AND m_0,high_mask,tmp_0 ; m & Mask
543 DEPD,Z m_0,30,31,m_0 ; m << 32+1
544 LDD -16(%sp),lt_0 ; lt
545
546 LDD -8(%sp),ht_0 ; ht
547 EXTRD,U tmp_0,32,33,tmp_0 ; tmp_0 = m&Mask >> 32-1
548 ADD m_0,lt_0,lt_0 ; lt = lt+m
549 ADD,L ht_0,tmp_0,ht_0 ; ht += tmp_0
550 ADD,DC ht_0,%r0,ht_0 ; ht++
551
552 STD lt_0,0(r_ptr) ; rp[0] = lt
553 STD ht_0,8(r_ptr) ; rp[1] = ht
554
555bn_sqr_words_exit
556 .EXIT
557 LDD -112(%sp),%r5 ; restore r5
558 LDD -120(%sp),%r4 ; restore r4
559 BVE (%rp)
560 LDD,MB -128(%sp),%r3
561 .PROCEND ;in=23,24,25,26,29;out=28;
562
563
564;----------------------------------------------------------------------------
565;
566;BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
567;
568; arg0 = rp
569; arg1 = ap
570; arg2 = bp
571; arg3 = n
572
573t .reg %r22
574b .reg %r21
575l .reg %r20
576
577bn_add_words
578 .proc
579 .entry
580 .callinfo
581 .EXPORT bn_add_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
582 .align 64
583
584 CMPIB,>= 0,n,bn_add_words_exit
585 COPY %r0,%ret0 ; return 0 by default
586
587 ;
588 ; If 2 or more numbers do the loop
589 ;
590 CMPIB,= 1,n,bn_add_words_single_top
591 NOP
592
593 ;
594 ; This loop is unrolled 2 times (64-byte aligned as well)
595 ;
596bn_add_words_unroll2
597 LDD 0(a_ptr),t
598 LDD 0(b_ptr),b
599 ADD t,%ret0,t ; t = t+c;
600 ADD,DC %r0,%r0,%ret0 ; set c to carry
601 ADD t,b,l ; l = t + b[0]
602 ADD,DC %ret0,%r0,%ret0 ; c+= carry
603 STD l,0(r_ptr)
604
605 LDD 8(a_ptr),t
606 LDD 8(b_ptr),b
607 ADD t,%ret0,t ; t = t+c;
608 ADD,DC %r0,%r0,%ret0 ; set c to carry
609 ADD t,b,l ; l = t + b[0]
610 ADD,DC %ret0,%r0,%ret0 ; c+= carry
611 STD l,8(r_ptr)
612
613 LDO -2(n),n
614 LDO 16(a_ptr),a_ptr
615 LDO 16(b_ptr),b_ptr
616
617 CMPIB,<= 2,n,bn_add_words_unroll2
618 LDO 16(r_ptr),r_ptr
619
620 CMPIB,=,N 0,n,bn_add_words_exit ; are we done?
621
622bn_add_words_single_top
623 LDD 0(a_ptr),t
624 LDD 0(b_ptr),b
625
626 ADD t,%ret0,t ; t = t+c;
627 ADD,DC %r0,%r0,%ret0 ; set c to carry (could use CMPCLR??)
628 ADD t,b,l ; l = t + b[0]
629 ADD,DC %ret0,%r0,%ret0 ; c+= carry
630 STD l,0(r_ptr)
631
632bn_add_words_exit
633 .EXIT
634 BVE (%rp)
635 NOP
636 .PROCEND ;in=23,24,25,26,29;out=28;
637
638;----------------------------------------------------------------------------
639;
640;BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
641;
642; arg0 = rp
643; arg1 = ap
644; arg2 = bp
645; arg3 = n
646
647t1 .reg %r22
648t2 .reg %r21
649sub_tmp1 .reg %r20
650sub_tmp2 .reg %r19
651
652
653bn_sub_words
654 .proc
655 .callinfo
656 .EXPORT bn_sub_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
657 .entry
658 .align 64
659
660 CMPIB,>= 0,n,bn_sub_words_exit
661 COPY %r0,%ret0 ; return 0 by default
662
663 ;
664 ; If 2 or more numbers do the loop
665 ;
666 CMPIB,= 1,n,bn_sub_words_single_top
667 NOP
668
669 ;
670 ; This loop is unrolled 2 times (64-byte aligned as well)
671 ;
672bn_sub_words_unroll2
673 LDD 0(a_ptr),t1
674 LDD 0(b_ptr),t2
675 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
676 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
677
678 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
679 LDO 1(%r0),sub_tmp2
680
681 CMPCLR,*= t1,t2,%r0
682 COPY sub_tmp2,%ret0
683 STD sub_tmp1,0(r_ptr)
684
685 LDD 8(a_ptr),t1
686 LDD 8(b_ptr),t2
687 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
688 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
689 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
690 LDO 1(%r0),sub_tmp2
691
692 CMPCLR,*= t1,t2,%r0
693 COPY sub_tmp2,%ret0
694 STD sub_tmp1,8(r_ptr)
695
696 LDO -2(n),n
697 LDO 16(a_ptr),a_ptr
698 LDO 16(b_ptr),b_ptr
699
700 CMPIB,<= 2,n,bn_sub_words_unroll2
701 LDO 16(r_ptr),r_ptr
702
703 CMPIB,=,N 0,n,bn_sub_words_exit ; are we done?
704
705bn_sub_words_single_top
706 LDD 0(a_ptr),t1
707 LDD 0(b_ptr),t2
708 SUB t1,t2,sub_tmp1 ; t3 = t1-t2;
709 SUB sub_tmp1,%ret0,sub_tmp1 ; t3 = t3- c;
710 CMPCLR,*>> t1,t2,sub_tmp2 ; clear if t1 > t2
711 LDO 1(%r0),sub_tmp2
712
713 CMPCLR,*= t1,t2,%r0
714 COPY sub_tmp2,%ret0
715
716 STD sub_tmp1,0(r_ptr)
717
718bn_sub_words_exit
719 .EXIT
720 BVE (%rp)
721 NOP
722 .PROCEND ;in=23,24,25,26,29;out=28;
723
724;------------------------------------------------------------------------------
725;
726; unsigned long bn_div_words(unsigned long h, unsigned long l, unsigned long d)
727;
728; arg0 = h
729; arg1 = l
730; arg2 = d
731;
732; This is mainly just modified assembly from the compiler, thus the
733; lack of variable names.
734;
735;------------------------------------------------------------------------------
736bn_div_words
737 .proc
738 .callinfo CALLER,FRAME=272,ENTRY_GR=%r10,SAVE_RP,ARGS_SAVED,ORDERING_AWARE
739 .EXPORT bn_div_words,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
740 .IMPORT BN_num_bits_word,CODE,NO_RELOCATION
741 .IMPORT __iob,DATA
742 .IMPORT fprintf,CODE,NO_RELOCATION
743 .IMPORT abort,CODE,NO_RELOCATION
744 .IMPORT $$div2U,MILLICODE
745 .entry
746 STD %r2,-16(%r30)
747 STD,MA %r3,352(%r30)
748 STD %r4,-344(%r30)
749 STD %r5,-336(%r30)
750 STD %r6,-328(%r30)
751 STD %r7,-320(%r30)
752 STD %r8,-312(%r30)
753 STD %r9,-304(%r30)
754 STD %r10,-296(%r30)
755
756 STD %r27,-288(%r30) ; save gp
757
758 COPY %r24,%r3 ; save d
759 COPY %r26,%r4 ; save h (high 64-bits)
760 LDO -1(%r0),%ret0 ; return -1 by default
761
762 CMPB,*= %r0,%arg2,$D3 ; if (d == 0)
763 COPY %r25,%r5 ; save l (low 64-bits)
764
765 LDO -48(%r30),%r29 ; create ap
766 .CALL ;in=26,29;out=28;
767 B,L BN_num_bits_word,%r2
768 COPY %r3,%r26
769 LDD -288(%r30),%r27 ; restore gp
770 LDI 64,%r21
771
772 CMPB,= %r21,%ret0,$00000012 ;if (i == 64) (forward)
773 COPY %ret0,%r24 ; i
774 MTSARCM %r24
775 DEPDI,Z -1,%sar,1,%r29
776 CMPB,*<<,N %r29,%r4,bn_div_err_case ; if (h > 1<<i) (forward)
777
778$00000012
779 SUBI 64,%r24,%r31 ; i = 64 - i;
780 CMPCLR,*<< %r4,%r3,%r0 ; if (h >= d)
781 SUB %r4,%r3,%r4 ; h -= d
782 CMPB,= %r31,%r0,$0000001A ; if (i)
783 COPY %r0,%r10 ; ret = 0
784 MTSARCM %r31 ; i to shift
785 DEPD,Z %r3,%sar,64,%r3 ; d <<= i;
786 SUBI 64,%r31,%r19 ; 64 - i; redundent
787 MTSAR %r19 ; (64 -i) to shift
788 SHRPD %r4,%r5,%sar,%r4 ; l>> (64-i)
789 MTSARCM %r31 ; i to shift
790 DEPD,Z %r5,%sar,64,%r5 ; l <<= i;
791
792$0000001A
793 DEPDI,Z -1,31,32,%r19
794 EXTRD,U %r3,31,32,%r6 ; dh=(d&0xfff)>>32
795 EXTRD,U %r3,63,32,%r8 ; dl = d&0xffffff
796 LDO 2(%r0),%r9
797 STD %r3,-280(%r30) ; "d" to stack
798
799$0000001C
800 DEPDI,Z -1,63,32,%r29 ;
801 EXTRD,U %r4,31,32,%r31 ; h >> 32
802 CMPB,*=,N %r31,%r6,$D2 ; if ((h>>32) != dh)(forward) div
803 COPY %r4,%r26
804 EXTRD,U %r4,31,32,%r25
805 COPY %r6,%r24
806 .CALL ;in=23,24,25,26;out=20,21,22,28,29; (MILLICALL)
807 B,L $$div2U,%r2
808 EXTRD,U %r6,31,32,%r23
809 DEPD %r28,31,32,%r29
810$D2
811 STD %r29,-272(%r30) ; q
812 AND %r5,%r19,%r24 ; t & 0xffffffff00000000;
813 EXTRD,U %r24,31,32,%r24 ; ???
814 FLDD -272(%r30),%fr7 ; q
815 FLDD -280(%r30),%fr8 ; d
816 XMPYU %fr8L,%fr7L,%fr10
817 FSTD %fr10,-256(%r30)
818 XMPYU %fr8L,%fr7R,%fr22
819 FSTD %fr22,-264(%r30)
820 XMPYU %fr8R,%fr7L,%fr11
821 XMPYU %fr8R,%fr7R,%fr23
822 FSTD %fr11,-232(%r30)
823 FSTD %fr23,-240(%r30)
824 LDD -256(%r30),%r28
825 DEPD,Z %r28,31,32,%r2
826 LDD -264(%r30),%r20
827 ADD,L %r20,%r2,%r31
828 LDD -232(%r30),%r22
829 DEPD,Z %r22,31,32,%r22
830 LDD -240(%r30),%r21
831 B $00000024 ; enter loop
832 ADD,L %r21,%r22,%r23
833
834$0000002A
835 LDO -1(%r29),%r29
836 SUB %r23,%r8,%r23
837$00000024
838 SUB %r4,%r31,%r25
839 AND %r25,%r19,%r26
840 CMPB,*<>,N %r0,%r26,$00000046 ; (forward)
841 DEPD,Z %r25,31,32,%r20
842 OR %r20,%r24,%r21
843 CMPB,*<<,N %r21,%r23,$0000002A ;(backward)
844 SUB %r31,%r6,%r31
845;-------------Break path---------------------
846
847$00000046
848 DEPD,Z %r23,31,32,%r25 ;tl
849 EXTRD,U %r23,31,32,%r26 ;t
850 AND %r25,%r19,%r24 ;tl = (tl<<32)&0xfffffff0000000L
851 ADD,L %r31,%r26,%r31 ;th += t;
852 CMPCLR,*>>= %r5,%r24,%r0 ;if (l<tl)
853 LDO 1(%r31),%r31 ; th++;
854 CMPB,*<<=,N %r31,%r4,$00000036 ;if (n < th) (forward)
855 LDO -1(%r29),%r29 ;q--;
856 ADD,L %r4,%r3,%r4 ;h += d;
857$00000036
858 ADDIB,=,N -1,%r9,$D1 ;if (--count == 0) break (forward)
859 SUB %r5,%r24,%r28 ; l -= tl;
860 SUB %r4,%r31,%r24 ; h -= th;
861 SHRPD %r24,%r28,32,%r4 ; h = ((h<<32)|(l>>32));
862 DEPD,Z %r29,31,32,%r10 ; ret = q<<32
863 b $0000001C
864 DEPD,Z %r28,31,32,%r5 ; l = l << 32
865
866$D1
867 OR %r10,%r29,%r28 ; ret |= q
868$D3
869 LDD -368(%r30),%r2
870$D0
871 LDD -296(%r30),%r10
872 LDD -304(%r30),%r9
873 LDD -312(%r30),%r8
874 LDD -320(%r30),%r7
875 LDD -328(%r30),%r6
876 LDD -336(%r30),%r5
877 LDD -344(%r30),%r4
878 BVE (%r2)
879 .EXIT
880 LDD,MB -352(%r30),%r3
881
882bn_div_err_case
883 MFIA %r6
884 ADDIL L'bn_div_words-bn_div_err_case,%r6,%r1
885 LDO R'bn_div_words-bn_div_err_case(%r1),%r6
886 ADDIL LT'__iob,%r27,%r1
887 LDD RT'__iob(%r1),%r26
888 ADDIL L'C$4-bn_div_words,%r6,%r1
889 LDO R'C$4-bn_div_words(%r1),%r25
890 LDO 64(%r26),%r26
891 .CALL ;in=24,25,26,29;out=28;
892 B,L fprintf,%r2
893 LDO -48(%r30),%r29
894 LDD -288(%r30),%r27
895 .CALL ;in=29;
896 B,L abort,%r2
897 LDO -48(%r30),%r29
898 LDD -288(%r30),%r27
899 B $D0
900 LDD -368(%r30),%r2
901 .PROCEND ;in=24,25,26,29;out=28;
902
903;----------------------------------------------------------------------------
904;
905; Registers to hold 64-bit values to manipulate. The "L" part
906; of the register corresponds to the upper 32-bits, while the "R"
907; part corresponds to the lower 32-bits
908;
909; Note, that when using b6 and b7, the code must save these before
910; using them because they are callee save registers
911;
912;
913; Floating point registers to use to save values that
914; are manipulated. These don't collide with ftemp1-6 and
915; are all caller save registers
916;
917a0 .reg %fr22
918a0L .reg %fr22L
919a0R .reg %fr22R
920
921a1 .reg %fr23
922a1L .reg %fr23L
923a1R .reg %fr23R
924
925a2 .reg %fr24
926a2L .reg %fr24L
927a2R .reg %fr24R
928
929a3 .reg %fr25
930a3L .reg %fr25L
931a3R .reg %fr25R
932
933a4 .reg %fr26
934a4L .reg %fr26L
935a4R .reg %fr26R
936
937a5 .reg %fr27
938a5L .reg %fr27L
939a5R .reg %fr27R
940
941a6 .reg %fr28
942a6L .reg %fr28L
943a6R .reg %fr28R
944
945a7 .reg %fr29
946a7L .reg %fr29L
947a7R .reg %fr29R
948
949b0 .reg %fr30
950b0L .reg %fr30L
951b0R .reg %fr30R
952
953b1 .reg %fr31
954b1L .reg %fr31L
955b1R .reg %fr31R
956
957;
958; Temporary floating point variables, these are all caller save
959; registers
960;
961ftemp1 .reg %fr4
962ftemp2 .reg %fr5
963ftemp3 .reg %fr6
964ftemp4 .reg %fr7
965
966;
967; The B set of registers when used.
968;
969
970b2 .reg %fr8
971b2L .reg %fr8L
972b2R .reg %fr8R
973
974b3 .reg %fr9
975b3L .reg %fr9L
976b3R .reg %fr9R
977
978b4 .reg %fr10
979b4L .reg %fr10L
980b4R .reg %fr10R
981
982b5 .reg %fr11
983b5L .reg %fr11L
984b5R .reg %fr11R
985
986b6 .reg %fr12
987b6L .reg %fr12L
988b6R .reg %fr12R
989
990b7 .reg %fr13
991b7L .reg %fr13L
992b7R .reg %fr13R
993
994c1 .reg %r21 ; only reg
995temp1 .reg %r20 ; only reg
996temp2 .reg %r19 ; only reg
997temp3 .reg %r31 ; only reg
998
999m1 .reg %r28
1000c2 .reg %r23
1001high_one .reg %r1
1002ht .reg %r6
1003lt .reg %r5
1004m .reg %r4
1005c3 .reg %r3
1006
1007SQR_ADD_C .macro A0L,A0R,C1,C2,C3
1008 XMPYU A0L,A0R,ftemp1 ; m
1009 FSTD ftemp1,-24(%sp) ; store m
1010
1011 XMPYU A0R,A0R,ftemp2 ; lt
1012 FSTD ftemp2,-16(%sp) ; store lt
1013
1014 XMPYU A0L,A0L,ftemp3 ; ht
1015 FSTD ftemp3,-8(%sp) ; store ht
1016
1017 LDD -24(%sp),m ; load m
1018 AND m,high_mask,temp2 ; m & Mask
1019 DEPD,Z m,30,31,temp3 ; m << 32+1
1020 LDD -16(%sp),lt ; lt
1021
1022 LDD -8(%sp),ht ; ht
1023 EXTRD,U temp2,32,33,temp1 ; temp1 = m&Mask >> 32-1
1024 ADD temp3,lt,lt ; lt = lt+m
1025 ADD,L ht,temp1,ht ; ht += temp1
1026 ADD,DC ht,%r0,ht ; ht++
1027
1028 ADD C1,lt,C1 ; c1=c1+lt
1029 ADD,DC ht,%r0,ht ; ht++
1030
1031 ADD C2,ht,C2 ; c2=c2+ht
1032 ADD,DC C3,%r0,C3 ; c3++
1033.endm
1034
1035SQR_ADD_C2 .macro A0L,A0R,A1L,A1R,C1,C2,C3
1036 XMPYU A0L,A1R,ftemp1 ; m1 = bl*ht
1037 FSTD ftemp1,-16(%sp) ;
1038 XMPYU A0R,A1L,ftemp2 ; m = bh*lt
1039 FSTD ftemp2,-8(%sp) ;
1040 XMPYU A0R,A1R,ftemp3 ; lt = bl*lt
1041 FSTD ftemp3,-32(%sp)
1042 XMPYU A0L,A1L,ftemp4 ; ht = bh*ht
1043 FSTD ftemp4,-24(%sp) ;
1044
1045 LDD -8(%sp),m ; r21 = m
1046 LDD -16(%sp),m1 ; r19 = m1
1047 ADD,L m,m1,m ; m+m1
1048
1049 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1050 LDD -24(%sp),ht ; r24 = ht
1051
1052 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1053 ADD,L ht,high_one,ht ; ht+=high_one
1054
1055 EXTRD,U m,31,32,temp1 ; m >> 32
1056 LDD -32(%sp),lt ; lt
1057 ADD,L ht,temp1,ht ; ht+= m>>32
1058 ADD lt,temp3,lt ; lt = lt+m1
1059 ADD,DC ht,%r0,ht ; ht++
1060
1061 ADD ht,ht,ht ; ht=ht+ht;
1062 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1063
1064 ADD lt,lt,lt ; lt=lt+lt;
1065 ADD,DC ht,%r0,ht ; add in carry (ht++)
1066
1067 ADD C1,lt,C1 ; c1=c1+lt
1068 ADD,DC,*NUV ht,%r0,ht ; add in carry (ht++)
1069 LDO 1(C3),C3 ; bump c3 if overflow,nullify otherwise
1070
1071 ADD C2,ht,C2 ; c2 = c2 + ht
1072 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1073.endm
1074
1075;
1076;void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
1077; arg0 = r_ptr
1078; arg1 = a_ptr
1079;
1080
1081bn_sqr_comba8
1082 .PROC
1083 .CALLINFO FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1084 .EXPORT bn_sqr_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1085 .ENTRY
1086 .align 64
1087
1088 STD %r3,0(%sp) ; save r3
1089 STD %r4,8(%sp) ; save r4
1090 STD %r5,16(%sp) ; save r5
1091 STD %r6,24(%sp) ; save r6
1092
1093 ;
1094 ; Zero out carries
1095 ;
1096 COPY %r0,c1
1097 COPY %r0,c2
1098 COPY %r0,c3
1099
1100 LDO 128(%sp),%sp ; bump stack
1101 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1102 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1103
1104 ;
1105 ; Load up all of the values we are going to use
1106 ;
1107 FLDD 0(a_ptr),a0
1108 FLDD 8(a_ptr),a1
1109 FLDD 16(a_ptr),a2
1110 FLDD 24(a_ptr),a3
1111 FLDD 32(a_ptr),a4
1112 FLDD 40(a_ptr),a5
1113 FLDD 48(a_ptr),a6
1114 FLDD 56(a_ptr),a7
1115
1116 SQR_ADD_C a0L,a0R,c1,c2,c3
1117 STD c1,0(r_ptr) ; r[0] = c1;
1118 COPY %r0,c1
1119
1120 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1121 STD c2,8(r_ptr) ; r[1] = c2;
1122 COPY %r0,c2
1123
1124 SQR_ADD_C a1L,a1R,c3,c1,c2
1125 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1126 STD c3,16(r_ptr) ; r[2] = c3;
1127 COPY %r0,c3
1128
1129 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1130 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1131 STD c1,24(r_ptr) ; r[3] = c1;
1132 COPY %r0,c1
1133
1134 SQR_ADD_C a2L,a2R,c2,c3,c1
1135 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1136 SQR_ADD_C2 a4L,a4R,a0L,a0R,c2,c3,c1
1137 STD c2,32(r_ptr) ; r[4] = c2;
1138 COPY %r0,c2
1139
1140 SQR_ADD_C2 a5L,a5R,a0L,a0R,c3,c1,c2
1141 SQR_ADD_C2 a4L,a4R,a1L,a1R,c3,c1,c2
1142 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1143 STD c3,40(r_ptr) ; r[5] = c3;
1144 COPY %r0,c3
1145
1146 SQR_ADD_C a3L,a3R,c1,c2,c3
1147 SQR_ADD_C2 a4L,a4R,a2L,a2R,c1,c2,c3
1148 SQR_ADD_C2 a5L,a5R,a1L,a1R,c1,c2,c3
1149 SQR_ADD_C2 a6L,a6R,a0L,a0R,c1,c2,c3
1150 STD c1,48(r_ptr) ; r[6] = c1;
1151 COPY %r0,c1
1152
1153 SQR_ADD_C2 a7L,a7R,a0L,a0R,c2,c3,c1
1154 SQR_ADD_C2 a6L,a6R,a1L,a1R,c2,c3,c1
1155 SQR_ADD_C2 a5L,a5R,a2L,a2R,c2,c3,c1
1156 SQR_ADD_C2 a4L,a4R,a3L,a3R,c2,c3,c1
1157 STD c2,56(r_ptr) ; r[7] = c2;
1158 COPY %r0,c2
1159
1160 SQR_ADD_C a4L,a4R,c3,c1,c2
1161 SQR_ADD_C2 a5L,a5R,a3L,a3R,c3,c1,c2
1162 SQR_ADD_C2 a6L,a6R,a2L,a2R,c3,c1,c2
1163 SQR_ADD_C2 a7L,a7R,a1L,a1R,c3,c1,c2
1164 STD c3,64(r_ptr) ; r[8] = c3;
1165 COPY %r0,c3
1166
1167 SQR_ADD_C2 a7L,a7R,a2L,a2R,c1,c2,c3
1168 SQR_ADD_C2 a6L,a6R,a3L,a3R,c1,c2,c3
1169 SQR_ADD_C2 a5L,a5R,a4L,a4R,c1,c2,c3
1170 STD c1,72(r_ptr) ; r[9] = c1;
1171 COPY %r0,c1
1172
1173 SQR_ADD_C a5L,a5R,c2,c3,c1
1174 SQR_ADD_C2 a6L,a6R,a4L,a4R,c2,c3,c1
1175 SQR_ADD_C2 a7L,a7R,a3L,a3R,c2,c3,c1
1176 STD c2,80(r_ptr) ; r[10] = c2;
1177 COPY %r0,c2
1178
1179 SQR_ADD_C2 a7L,a7R,a4L,a4R,c3,c1,c2
1180 SQR_ADD_C2 a6L,a6R,a5L,a5R,c3,c1,c2
1181 STD c3,88(r_ptr) ; r[11] = c3;
1182 COPY %r0,c3
1183
1184 SQR_ADD_C a6L,a6R,c1,c2,c3
1185 SQR_ADD_C2 a7L,a7R,a5L,a5R,c1,c2,c3
1186 STD c1,96(r_ptr) ; r[12] = c1;
1187 COPY %r0,c1
1188
1189 SQR_ADD_C2 a7L,a7R,a6L,a6R,c2,c3,c1
1190 STD c2,104(r_ptr) ; r[13] = c2;
1191 COPY %r0,c2
1192
1193 SQR_ADD_C a7L,a7R,c3,c1,c2
1194 STD c3, 112(r_ptr) ; r[14] = c3
1195 STD c1, 120(r_ptr) ; r[15] = c1
1196
1197 .EXIT
1198 LDD -104(%sp),%r6 ; restore r6
1199 LDD -112(%sp),%r5 ; restore r5
1200 LDD -120(%sp),%r4 ; restore r4
1201 BVE (%rp)
1202 LDD,MB -128(%sp),%r3
1203
1204 .PROCEND
1205
1206;-----------------------------------------------------------------------------
1207;
1208;void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
1209; arg0 = r_ptr
1210; arg1 = a_ptr
1211;
1212
1213bn_sqr_comba4
1214 .proc
1215 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1216 .EXPORT bn_sqr_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1217 .entry
1218 .align 64
1219 STD %r3,0(%sp) ; save r3
1220 STD %r4,8(%sp) ; save r4
1221 STD %r5,16(%sp) ; save r5
1222 STD %r6,24(%sp) ; save r6
1223
1224 ;
1225 ; Zero out carries
1226 ;
1227 COPY %r0,c1
1228 COPY %r0,c2
1229 COPY %r0,c3
1230
1231 LDO 128(%sp),%sp ; bump stack
1232 DEPDI,Z -1,32,33,high_mask ; Create Mask 0xffffffff80000000L
1233 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1234
1235 ;
1236 ; Load up all of the values we are going to use
1237 ;
1238 FLDD 0(a_ptr),a0
1239 FLDD 8(a_ptr),a1
1240 FLDD 16(a_ptr),a2
1241 FLDD 24(a_ptr),a3
1242 FLDD 32(a_ptr),a4
1243 FLDD 40(a_ptr),a5
1244 FLDD 48(a_ptr),a6
1245 FLDD 56(a_ptr),a7
1246
1247 SQR_ADD_C a0L,a0R,c1,c2,c3
1248
1249 STD c1,0(r_ptr) ; r[0] = c1;
1250 COPY %r0,c1
1251
1252 SQR_ADD_C2 a1L,a1R,a0L,a0R,c2,c3,c1
1253
1254 STD c2,8(r_ptr) ; r[1] = c2;
1255 COPY %r0,c2
1256
1257 SQR_ADD_C a1L,a1R,c3,c1,c2
1258 SQR_ADD_C2 a2L,a2R,a0L,a0R,c3,c1,c2
1259
1260 STD c3,16(r_ptr) ; r[2] = c3;
1261 COPY %r0,c3
1262
1263 SQR_ADD_C2 a3L,a3R,a0L,a0R,c1,c2,c3
1264 SQR_ADD_C2 a2L,a2R,a1L,a1R,c1,c2,c3
1265
1266 STD c1,24(r_ptr) ; r[3] = c1;
1267 COPY %r0,c1
1268
1269 SQR_ADD_C a2L,a2R,c2,c3,c1
1270 SQR_ADD_C2 a3L,a3R,a1L,a1R,c2,c3,c1
1271
1272 STD c2,32(r_ptr) ; r[4] = c2;
1273 COPY %r0,c2
1274
1275 SQR_ADD_C2 a3L,a3R,a2L,a2R,c3,c1,c2
1276 STD c3,40(r_ptr) ; r[5] = c3;
1277 COPY %r0,c3
1278
1279 SQR_ADD_C a3L,a3R,c1,c2,c3
1280 STD c1,48(r_ptr) ; r[6] = c1;
1281 STD c2,56(r_ptr) ; r[7] = c2;
1282
1283 .EXIT
1284 LDD -104(%sp),%r6 ; restore r6
1285 LDD -112(%sp),%r5 ; restore r5
1286 LDD -120(%sp),%r4 ; restore r4
1287 BVE (%rp)
1288 LDD,MB -128(%sp),%r3
1289
1290 .PROCEND
1291
1292
1293;---------------------------------------------------------------------------
1294
1295MUL_ADD_C .macro A0L,A0R,B0L,B0R,C1,C2,C3
1296 XMPYU A0L,B0R,ftemp1 ; m1 = bl*ht
1297 FSTD ftemp1,-16(%sp) ;
1298 XMPYU A0R,B0L,ftemp2 ; m = bh*lt
1299 FSTD ftemp2,-8(%sp) ;
1300 XMPYU A0R,B0R,ftemp3 ; lt = bl*lt
1301 FSTD ftemp3,-32(%sp)
1302 XMPYU A0L,B0L,ftemp4 ; ht = bh*ht
1303 FSTD ftemp4,-24(%sp) ;
1304
1305 LDD -8(%sp),m ; r21 = m
1306 LDD -16(%sp),m1 ; r19 = m1
1307 ADD,L m,m1,m ; m+m1
1308
1309 DEPD,Z m,31,32,temp3 ; (m+m1<<32)
1310 LDD -24(%sp),ht ; r24 = ht
1311
1312 CMPCLR,*>>= m,m1,%r0 ; if (m < m1)
1313 ADD,L ht,high_one,ht ; ht+=high_one
1314
1315 EXTRD,U m,31,32,temp1 ; m >> 32
1316 LDD -32(%sp),lt ; lt
1317 ADD,L ht,temp1,ht ; ht+= m>>32
1318 ADD lt,temp3,lt ; lt = lt+m1
1319 ADD,DC ht,%r0,ht ; ht++
1320
1321 ADD C1,lt,C1 ; c1=c1+lt
1322 ADD,DC ht,%r0,ht ; bump c3 if overflow,nullify otherwise
1323
1324 ADD C2,ht,C2 ; c2 = c2 + ht
1325 ADD,DC C3,%r0,C3 ; add in carry (c3++)
1326.endm
1327
1328
1329;
1330;void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1331; arg0 = r_ptr
1332; arg1 = a_ptr
1333; arg2 = b_ptr
1334;
1335
1336bn_mul_comba8
1337 .proc
1338 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1339 .EXPORT bn_mul_comba8,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1340 .entry
1341 .align 64
1342
1343 STD %r3,0(%sp) ; save r3
1344 STD %r4,8(%sp) ; save r4
1345 STD %r5,16(%sp) ; save r5
1346 STD %r6,24(%sp) ; save r6
1347 FSTD %fr12,32(%sp) ; save r6
1348 FSTD %fr13,40(%sp) ; save r7
1349
1350 ;
1351 ; Zero out carries
1352 ;
1353 COPY %r0,c1
1354 COPY %r0,c2
1355 COPY %r0,c3
1356
1357 LDO 128(%sp),%sp ; bump stack
1358 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1359
1360 ;
1361 ; Load up all of the values we are going to use
1362 ;
1363 FLDD 0(a_ptr),a0
1364 FLDD 8(a_ptr),a1
1365 FLDD 16(a_ptr),a2
1366 FLDD 24(a_ptr),a3
1367 FLDD 32(a_ptr),a4
1368 FLDD 40(a_ptr),a5
1369 FLDD 48(a_ptr),a6
1370 FLDD 56(a_ptr),a7
1371
1372 FLDD 0(b_ptr),b0
1373 FLDD 8(b_ptr),b1
1374 FLDD 16(b_ptr),b2
1375 FLDD 24(b_ptr),b3
1376 FLDD 32(b_ptr),b4
1377 FLDD 40(b_ptr),b5
1378 FLDD 48(b_ptr),b6
1379 FLDD 56(b_ptr),b7
1380
1381 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1382 STD c1,0(r_ptr)
1383 COPY %r0,c1
1384
1385 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1386 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1387 STD c2,8(r_ptr)
1388 COPY %r0,c2
1389
1390 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1391 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1392 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1393 STD c3,16(r_ptr)
1394 COPY %r0,c3
1395
1396 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1397 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1398 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1399 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1400 STD c1,24(r_ptr)
1401 COPY %r0,c1
1402
1403 MUL_ADD_C a4L,a4R,b0L,b0R,c2,c3,c1
1404 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1405 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1406 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1407 MUL_ADD_C a0L,a0R,b4L,b4R,c2,c3,c1
1408 STD c2,32(r_ptr)
1409 COPY %r0,c2
1410
1411 MUL_ADD_C a0L,a0R,b5L,b5R,c3,c1,c2
1412 MUL_ADD_C a1L,a1R,b4L,b4R,c3,c1,c2
1413 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1414 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1415 MUL_ADD_C a4L,a4R,b1L,b1R,c3,c1,c2
1416 MUL_ADD_C a5L,a5R,b0L,b0R,c3,c1,c2
1417 STD c3,40(r_ptr)
1418 COPY %r0,c3
1419
1420 MUL_ADD_C a6L,a6R,b0L,b0R,c1,c2,c3
1421 MUL_ADD_C a5L,a5R,b1L,b1R,c1,c2,c3
1422 MUL_ADD_C a4L,a4R,b2L,b2R,c1,c2,c3
1423 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1424 MUL_ADD_C a2L,a2R,b4L,b4R,c1,c2,c3
1425 MUL_ADD_C a1L,a1R,b5L,b5R,c1,c2,c3
1426 MUL_ADD_C a0L,a0R,b6L,b6R,c1,c2,c3
1427 STD c1,48(r_ptr)
1428 COPY %r0,c1
1429
1430 MUL_ADD_C a0L,a0R,b7L,b7R,c2,c3,c1
1431 MUL_ADD_C a1L,a1R,b6L,b6R,c2,c3,c1
1432 MUL_ADD_C a2L,a2R,b5L,b5R,c2,c3,c1
1433 MUL_ADD_C a3L,a3R,b4L,b4R,c2,c3,c1
1434 MUL_ADD_C a4L,a4R,b3L,b3R,c2,c3,c1
1435 MUL_ADD_C a5L,a5R,b2L,b2R,c2,c3,c1
1436 MUL_ADD_C a6L,a6R,b1L,b1R,c2,c3,c1
1437 MUL_ADD_C a7L,a7R,b0L,b0R,c2,c3,c1
1438 STD c2,56(r_ptr)
1439 COPY %r0,c2
1440
1441 MUL_ADD_C a7L,a7R,b1L,b1R,c3,c1,c2
1442 MUL_ADD_C a6L,a6R,b2L,b2R,c3,c1,c2
1443 MUL_ADD_C a5L,a5R,b3L,b3R,c3,c1,c2
1444 MUL_ADD_C a4L,a4R,b4L,b4R,c3,c1,c2
1445 MUL_ADD_C a3L,a3R,b5L,b5R,c3,c1,c2
1446 MUL_ADD_C a2L,a2R,b6L,b6R,c3,c1,c2
1447 MUL_ADD_C a1L,a1R,b7L,b7R,c3,c1,c2
1448 STD c3,64(r_ptr)
1449 COPY %r0,c3
1450
1451 MUL_ADD_C a2L,a2R,b7L,b7R,c1,c2,c3
1452 MUL_ADD_C a3L,a3R,b6L,b6R,c1,c2,c3
1453 MUL_ADD_C a4L,a4R,b5L,b5R,c1,c2,c3
1454 MUL_ADD_C a5L,a5R,b4L,b4R,c1,c2,c3
1455 MUL_ADD_C a6L,a6R,b3L,b3R,c1,c2,c3
1456 MUL_ADD_C a7L,a7R,b2L,b2R,c1,c2,c3
1457 STD c1,72(r_ptr)
1458 COPY %r0,c1
1459
1460 MUL_ADD_C a7L,a7R,b3L,b3R,c2,c3,c1
1461 MUL_ADD_C a6L,a6R,b4L,b4R,c2,c3,c1
1462 MUL_ADD_C a5L,a5R,b5L,b5R,c2,c3,c1
1463 MUL_ADD_C a4L,a4R,b6L,b6R,c2,c3,c1
1464 MUL_ADD_C a3L,a3R,b7L,b7R,c2,c3,c1
1465 STD c2,80(r_ptr)
1466 COPY %r0,c2
1467
1468 MUL_ADD_C a4L,a4R,b7L,b7R,c3,c1,c2
1469 MUL_ADD_C a5L,a5R,b6L,b6R,c3,c1,c2
1470 MUL_ADD_C a6L,a6R,b5L,b5R,c3,c1,c2
1471 MUL_ADD_C a7L,a7R,b4L,b4R,c3,c1,c2
1472 STD c3,88(r_ptr)
1473 COPY %r0,c3
1474
1475 MUL_ADD_C a7L,a7R,b5L,b5R,c1,c2,c3
1476 MUL_ADD_C a6L,a6R,b6L,b6R,c1,c2,c3
1477 MUL_ADD_C a5L,a5R,b7L,b7R,c1,c2,c3
1478 STD c1,96(r_ptr)
1479 COPY %r0,c1
1480
1481 MUL_ADD_C a6L,a6R,b7L,b7R,c2,c3,c1
1482 MUL_ADD_C a7L,a7R,b6L,b6R,c2,c3,c1
1483 STD c2,104(r_ptr)
1484 COPY %r0,c2
1485
1486 MUL_ADD_C a7L,a7R,b7L,b7R,c3,c1,c2
1487 STD c3,112(r_ptr)
1488 STD c1,120(r_ptr)
1489
1490 .EXIT
1491 FLDD -88(%sp),%fr13
1492 FLDD -96(%sp),%fr12
1493 LDD -104(%sp),%r6 ; restore r6
1494 LDD -112(%sp),%r5 ; restore r5
1495 LDD -120(%sp),%r4 ; restore r4
1496 BVE (%rp)
1497 LDD,MB -128(%sp),%r3
1498
1499 .PROCEND
1500
1501;-----------------------------------------------------------------------------
1502;
1503;void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1504; arg0 = r_ptr
1505; arg1 = a_ptr
1506; arg2 = b_ptr
1507;
1508
1509bn_mul_comba4
1510 .proc
1511 .callinfo FRAME=128,ENTRY_GR=%r3,ARGS_SAVED,ORDERING_AWARE
1512 .EXPORT bn_mul_comba4,ENTRY,PRIV_LEV=3,NO_RELOCATION,LONG_RETURN
1513 .entry
1514 .align 64
1515
1516 STD %r3,0(%sp) ; save r3
1517 STD %r4,8(%sp) ; save r4
1518 STD %r5,16(%sp) ; save r5
1519 STD %r6,24(%sp) ; save r6
1520 FSTD %fr12,32(%sp) ; save r6
1521 FSTD %fr13,40(%sp) ; save r7
1522
1523 ;
1524 ; Zero out carries
1525 ;
1526 COPY %r0,c1
1527 COPY %r0,c2
1528 COPY %r0,c3
1529
1530 LDO 128(%sp),%sp ; bump stack
1531 DEPDI,Z 1,31,1,high_one ; Create Value 1 << 32
1532
1533 ;
1534 ; Load up all of the values we are going to use
1535 ;
1536 FLDD 0(a_ptr),a0
1537 FLDD 8(a_ptr),a1
1538 FLDD 16(a_ptr),a2
1539 FLDD 24(a_ptr),a3
1540
1541 FLDD 0(b_ptr),b0
1542 FLDD 8(b_ptr),b1
1543 FLDD 16(b_ptr),b2
1544 FLDD 24(b_ptr),b3
1545
1546 MUL_ADD_C a0L,a0R,b0L,b0R,c1,c2,c3
1547 STD c1,0(r_ptr)
1548 COPY %r0,c1
1549
1550 MUL_ADD_C a0L,a0R,b1L,b1R,c2,c3,c1
1551 MUL_ADD_C a1L,a1R,b0L,b0R,c2,c3,c1
1552 STD c2,8(r_ptr)
1553 COPY %r0,c2
1554
1555 MUL_ADD_C a2L,a2R,b0L,b0R,c3,c1,c2
1556 MUL_ADD_C a1L,a1R,b1L,b1R,c3,c1,c2
1557 MUL_ADD_C a0L,a0R,b2L,b2R,c3,c1,c2
1558 STD c3,16(r_ptr)
1559 COPY %r0,c3
1560
1561 MUL_ADD_C a0L,a0R,b3L,b3R,c1,c2,c3
1562 MUL_ADD_C a1L,a1R,b2L,b2R,c1,c2,c3
1563 MUL_ADD_C a2L,a2R,b1L,b1R,c1,c2,c3
1564 MUL_ADD_C a3L,a3R,b0L,b0R,c1,c2,c3
1565 STD c1,24(r_ptr)
1566 COPY %r0,c1
1567
1568 MUL_ADD_C a3L,a3R,b1L,b1R,c2,c3,c1
1569 MUL_ADD_C a2L,a2R,b2L,b2R,c2,c3,c1
1570 MUL_ADD_C a1L,a1R,b3L,b3R,c2,c3,c1
1571 STD c2,32(r_ptr)
1572 COPY %r0,c2
1573
1574 MUL_ADD_C a2L,a2R,b3L,b3R,c3,c1,c2
1575 MUL_ADD_C a3L,a3R,b2L,b2R,c3,c1,c2
1576 STD c3,40(r_ptr)
1577 COPY %r0,c3
1578
1579 MUL_ADD_C a3L,a3R,b3L,b3R,c1,c2,c3
1580 STD c1,48(r_ptr)
1581 STD c2,56(r_ptr)
1582
1583 .EXIT
1584 FLDD -88(%sp),%fr13
1585 FLDD -96(%sp),%fr12
1586 LDD -104(%sp),%r6 ; restore r6
1587 LDD -112(%sp),%r5 ; restore r5
1588 LDD -120(%sp),%r4 ; restore r4
1589 BVE (%rp)
1590 LDD,MB -128(%sp),%r3
1591
1592 .PROCEND
1593
1594
1595 .SPACE $TEXT$
1596 .SUBSPA $CODE$
1597 .SPACE $PRIVATE$,SORT=16
1598 .IMPORT $global$,DATA
1599 .SPACE $TEXT$
1600 .SUBSPA $CODE$
1601 .SUBSPA $LIT$,ACCESS=0x2c
1602C$4
1603 .ALIGN 8
1604 .STRINGZ "Division would overflow (%d)\n"
1605 .END
diff --git a/src/lib/libcrypto/bn/asm/ppc.pl b/src/lib/libcrypto/bn/asm/ppc.pl
deleted file mode 100644
index 08e0053473..0000000000
--- a/src/lib/libcrypto/bn/asm/ppc.pl
+++ /dev/null
@@ -1,2078 +0,0 @@
1#!/usr/bin/env perl
2#
3# Implemented as a Perl wrapper as we want to support several different
4# architectures with single file. We pick up the target based on the
5# file name we are asked to generate.
6#
7# It should be noted though that this perl code is nothing like
8# <openssl>/crypto/perlasm/x86*. In this case perl is used pretty much
9# as pre-processor to cover for platform differences in name decoration,
10# linker tables, 32-/64-bit instruction sets...
11#
12# As you might know there're several PowerPC ABI in use. Most notably
13# Linux and AIX use different 32-bit ABIs. Good news are that these ABIs
14# are similar enough to implement leaf(!) functions, which would be ABI
15# neutral. And that's what you find here: ABI neutral leaf functions.
16# In case you wonder what that is...
17#
18# AIX performance
19#
20# MEASUREMENTS WITH cc ON a 200 MhZ PowerPC 604e.
21#
22# The following is the performance of 32-bit compiler
23# generated code:
24#
25# OpenSSL 0.9.6c 21 dec 2001
26# built on: Tue Jun 11 11:06:51 EDT 2002
27# options:bn(64,32) ...
28#compiler: cc -DTHREADS -DAIX -DB_ENDIAN -DBN_LLONG -O3
29# sign verify sign/s verify/s
30#rsa 512 bits 0.0098s 0.0009s 102.0 1170.6
31#rsa 1024 bits 0.0507s 0.0026s 19.7 387.5
32#rsa 2048 bits 0.3036s 0.0085s 3.3 117.1
33#rsa 4096 bits 2.0040s 0.0299s 0.5 33.4
34#dsa 512 bits 0.0087s 0.0106s 114.3 94.5
35#dsa 1024 bits 0.0256s 0.0313s 39.0 32.0
36#
37# Same bechmark with this assembler code:
38#
39#rsa 512 bits 0.0056s 0.0005s 178.6 2049.2
40#rsa 1024 bits 0.0283s 0.0015s 35.3 674.1
41#rsa 2048 bits 0.1744s 0.0050s 5.7 201.2
42#rsa 4096 bits 1.1644s 0.0179s 0.9 55.7
43#dsa 512 bits 0.0052s 0.0062s 191.6 162.0
44#dsa 1024 bits 0.0149s 0.0180s 67.0 55.5
45#
46# Number of operations increases by at almost 75%
47#
48# Here are performance numbers for 64-bit compiler
49# generated code:
50#
51# OpenSSL 0.9.6g [engine] 9 Aug 2002
52# built on: Fri Apr 18 16:59:20 EDT 2003
53# options:bn(64,64) ...
54# compiler: cc -DTHREADS -D_REENTRANT -q64 -DB_ENDIAN -O3
55# sign verify sign/s verify/s
56#rsa 512 bits 0.0028s 0.0003s 357.1 3844.4
57#rsa 1024 bits 0.0148s 0.0008s 67.5 1239.7
58#rsa 2048 bits 0.0963s 0.0028s 10.4 353.0
59#rsa 4096 bits 0.6538s 0.0102s 1.5 98.1
60#dsa 512 bits 0.0026s 0.0032s 382.5 313.7
61#dsa 1024 bits 0.0081s 0.0099s 122.8 100.6
62#
63# Same benchmark with this assembler code:
64#
65#rsa 512 bits 0.0020s 0.0002s 510.4 6273.7
66#rsa 1024 bits 0.0088s 0.0005s 114.1 2128.3
67#rsa 2048 bits 0.0540s 0.0016s 18.5 622.5
68#rsa 4096 bits 0.3700s 0.0058s 2.7 171.0
69#dsa 512 bits 0.0016s 0.0020s 610.7 507.1
70#dsa 1024 bits 0.0047s 0.0058s 212.5 173.2
71#
72# Again, performance increases by at about 75%
73#
74# Mac OS X, Apple G5 1.8GHz (Note this is 32 bit code)
75# OpenSSL 0.9.7c 30 Sep 2003
76#
77# Original code.
78#
79#rsa 512 bits 0.0011s 0.0001s 906.1 11012.5
80#rsa 1024 bits 0.0060s 0.0003s 166.6 3363.1
81#rsa 2048 bits 0.0370s 0.0010s 27.1 982.4
82#rsa 4096 bits 0.2426s 0.0036s 4.1 280.4
83#dsa 512 bits 0.0010s 0.0012s 1038.1 841.5
84#dsa 1024 bits 0.0030s 0.0037s 329.6 269.7
85#dsa 2048 bits 0.0101s 0.0127s 98.9 78.6
86#
87# Same benchmark with this assembler code:
88#
89#rsa 512 bits 0.0007s 0.0001s 1416.2 16645.9
90#rsa 1024 bits 0.0036s 0.0002s 274.4 5380.6
91#rsa 2048 bits 0.0222s 0.0006s 45.1 1589.5
92#rsa 4096 bits 0.1469s 0.0022s 6.8 449.6
93#dsa 512 bits 0.0006s 0.0007s 1664.2 1376.2
94#dsa 1024 bits 0.0018s 0.0023s 545.0 442.2
95#dsa 2048 bits 0.0061s 0.0075s 163.5 132.8
96#
97# Performance increase of ~60%
98#
99# If you have comments or suggestions to improve code send
100# me a note at schari@us.ibm.com
101#
102
103$opf = shift;
104
105if ($opf =~ /32\.s/) {
106 $BITS= 32;
107 $BNSZ= $BITS/8;
108 $ISA= "\"ppc\"";
109
110 $LD= "lwz"; # load
111 $LDU= "lwzu"; # load and update
112 $ST= "stw"; # store
113 $STU= "stwu"; # store and update
114 $UMULL= "mullw"; # unsigned multiply low
115 $UMULH= "mulhwu"; # unsigned multiply high
116 $UDIV= "divwu"; # unsigned divide
117 $UCMPI= "cmplwi"; # unsigned compare with immediate
118 $UCMP= "cmplw"; # unsigned compare
119 $CNTLZ= "cntlzw"; # count leading zeros
120 $SHL= "slw"; # shift left
121 $SHR= "srw"; # unsigned shift right
122 $SHRI= "srwi"; # unsigned shift right by immediate
123 $SHLI= "slwi"; # shift left by immediate
124 $CLRU= "clrlwi"; # clear upper bits
125 $INSR= "insrwi"; # insert right
126 $ROTL= "rotlwi"; # rotate left by immediate
127 $TR= "tw"; # conditional trap
128} elsif ($opf =~ /64\.s/) {
129 $BITS= 64;
130 $BNSZ= $BITS/8;
131 $ISA= "\"ppc64\"";
132
133 # same as above, but 64-bit mnemonics...
134 $LD= "ld"; # load
135 $LDU= "ldu"; # load and update
136 $ST= "std"; # store
137 $STU= "stdu"; # store and update
138 $UMULL= "mulld"; # unsigned multiply low
139 $UMULH= "mulhdu"; # unsigned multiply high
140 $UDIV= "divdu"; # unsigned divide
141 $UCMPI= "cmpldi"; # unsigned compare with immediate
142 $UCMP= "cmpld"; # unsigned compare
143 $CNTLZ= "cntlzd"; # count leading zeros
144 $SHL= "sld"; # shift left
145 $SHR= "srd"; # unsigned shift right
146 $SHRI= "srdi"; # unsigned shift right by immediate
147 $SHLI= "sldi"; # shift left by immediate
148 $CLRU= "clrldi"; # clear upper bits
149 $INSR= "insrdi"; # insert right
150 $ROTL= "rotldi"; # rotate left by immediate
151 $TR= "td"; # conditional trap
152} else { die "nonsense $opf"; }
153
154( defined shift || open STDOUT,">$opf" ) || die "can't open $opf: $!";
155
156# function entry points from the AIX code
157#
158# There are other, more elegant, ways to handle this. We (IBM) chose
159# this approach as it plays well with scripts we run to 'namespace'
160# OpenSSL .i.e. we add a prefix to all the public symbols so we can
161# co-exist in the same process with other implementations of OpenSSL.
162# 'cleverer' ways of doing these substitutions tend to hide data we
163# need to be obvious.
164#
165my @items = ("bn_sqr_comba4",
166 "bn_sqr_comba8",
167 "bn_mul_comba4",
168 "bn_mul_comba8",
169 "bn_sub_words",
170 "bn_add_words",
171 "bn_div_words",
172 "bn_sqr_words",
173 "bn_mul_words",
174 "bn_mul_add_words");
175
176if ($opf =~ /linux/) { do_linux(); }
177elsif ($opf =~ /aix/) { do_aix(); }
178elsif ($opf =~ /osx/) { do_osx(); }
179else { do_bsd(); }
180
181sub do_linux {
182 $d=&data();
183
184 if ($BITS==64) {
185 foreach $t (@items) {
186 $d =~ s/\.$t:/\
187\t.section\t".opd","aw"\
188\t.align\t3\
189\t.globl\t$t\
190$t:\
191\t.quad\t.$t,.TOC.\@tocbase,0\
192\t.size\t$t,24\
193\t.previous\n\
194\t.type\t.$t,\@function\
195\t.globl\t.$t\
196.$t:/g;
197 }
198 }
199 else {
200 foreach $t (@items) {
201 $d=~s/\.$t/$t/g;
202 }
203 }
204 # hide internal labels to avoid pollution of name table...
205 $d=~s/Lppcasm_/.Lppcasm_/gm;
206 print $d;
207}
208
209sub do_aix {
210 # AIX assembler is smart enough to please the linker without
211 # making us do something special...
212 print &data();
213}
214
215# MacOSX 32 bit
216sub do_osx {
217 $d=&data();
218 # Change the bn symbol prefix from '.' to '_'
219 foreach $t (@items) {
220 $d=~s/\.$t/_$t/g;
221 }
222 # Change .machine to something OS X asm will accept
223 $d=~s/\.machine.*/.text/g;
224 $d=~s/\#/;/g; # change comment from '#' to ';'
225 print $d;
226}
227
228# BSD (Untested)
229sub do_bsd {
230 $d=&data();
231 foreach $t (@items) {
232 $d=~s/\.$t/_$t/g;
233 }
234 print $d;
235}
236
237sub data {
238 local($data)=<<EOF;
239#--------------------------------------------------------------------
240#
241#
242#
243#
244# File: ppc32.s
245#
246# Created by: Suresh Chari
247# IBM Thomas J. Watson Research Library
248# Hawthorne, NY
249#
250#
251# Description: Optimized assembly routines for OpenSSL crypto
252# on the 32 bitPowerPC platform.
253#
254#
255# Version History
256#
257# 2. Fixed bn_add,bn_sub and bn_div_words, added comments,
258# cleaned up code. Also made a single version which can
259# be used for both the AIX and Linux compilers. See NOTE
260# below.
261# 12/05/03 Suresh Chari
262# (with lots of help from) Andy Polyakov
263##
264# 1. Initial version 10/20/02 Suresh Chari
265#
266#
267# The following file works for the xlc,cc
268# and gcc compilers.
269#
270# NOTE: To get the file to link correctly with the gcc compiler
271# you have to change the names of the routines and remove
272# the first .(dot) character. This should automatically
273# be done in the build process.
274#
275# Hand optimized assembly code for the following routines
276#
277# bn_sqr_comba4
278# bn_sqr_comba8
279# bn_mul_comba4
280# bn_mul_comba8
281# bn_sub_words
282# bn_add_words
283# bn_div_words
284# bn_sqr_words
285# bn_mul_words
286# bn_mul_add_words
287#
288# NOTE: It is possible to optimize this code more for
289# specific PowerPC or Power architectures. On the Northstar
290# architecture the optimizations in this file do
291# NOT provide much improvement.
292#
293# If you have comments or suggestions to improve code send
294# me a note at schari\@us.ibm.com
295#
296#--------------------------------------------------------------------------
297#
298# Defines to be used in the assembly code.
299#
300.set r0,0 # we use it as storage for value of 0
301.set SP,1 # preserved
302.set RTOC,2 # preserved
303.set r3,3 # 1st argument/return value
304.set r4,4 # 2nd argument/volatile register
305.set r5,5 # 3rd argument/volatile register
306.set r6,6 # ...
307.set r7,7
308.set r8,8
309.set r9,9
310.set r10,10
311.set r11,11
312.set r12,12
313.set r13,13 # not used, nor any other "below" it...
314
315.set BO_IF_NOT,4
316.set BO_IF,12
317.set BO_dCTR_NZERO,16
318.set BO_dCTR_ZERO,18
319.set BO_ALWAYS,20
320.set CR0_LT,0;
321.set CR0_GT,1;
322.set CR0_EQ,2
323.set CR1_FX,4;
324.set CR1_FEX,5;
325.set CR1_VX,6
326.set LR,8
327
328# Declare function names to be global
329# NOTE: For gcc these names MUST be changed to remove
330# the first . i.e. for example change ".bn_sqr_comba4"
331# to "bn_sqr_comba4". This should be automatically done
332# in the build.
333
334 .globl .bn_sqr_comba4
335 .globl .bn_sqr_comba8
336 .globl .bn_mul_comba4
337 .globl .bn_mul_comba8
338 .globl .bn_sub_words
339 .globl .bn_add_words
340 .globl .bn_div_words
341 .globl .bn_sqr_words
342 .globl .bn_mul_words
343 .globl .bn_mul_add_words
344
345# .text section
346
347 .machine $ISA
348
349#
350# NOTE: The following label name should be changed to
351# "bn_sqr_comba4" i.e. remove the first dot
352# for the gcc compiler. This should be automatically
353# done in the build
354#
355
356.align 4
357.bn_sqr_comba4:
358#
359# Optimized version of bn_sqr_comba4.
360#
361# void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
362# r3 contains r
363# r4 contains a
364#
365# Freely use registers r5,r6,r7,r8,r9,r10,r11 as follows:
366#
367# r5,r6 are the two BN_ULONGs being multiplied.
368# r7,r8 are the results of the 32x32 giving 64 bit multiply.
369# r9,r10, r11 are the equivalents of c1,c2, c3.
370# Here's the assembly
371#
372#
373 xor r0,r0,r0 # set r0 = 0. Used in the addze
374 # instructions below
375
376 #sqr_add_c(a,0,c1,c2,c3)
377 $LD r5,`0*$BNSZ`(r4)
378 $UMULL r9,r5,r5
379 $UMULH r10,r5,r5 #in first iteration. No need
380 #to add since c1=c2=c3=0.
381 # Note c3(r11) is NOT set to 0
382 # but will be.
383
384 $ST r9,`0*$BNSZ`(r3) # r[0]=c1;
385 # sqr_add_c2(a,1,0,c2,c3,c1);
386 $LD r6,`1*$BNSZ`(r4)
387 $UMULL r7,r5,r6
388 $UMULH r8,r5,r6
389
390 addc r7,r7,r7 # compute (r7,r8)=2*(r7,r8)
391 adde r8,r8,r8
392 addze r9,r0 # catch carry if any.
393 # r9= r0(=0) and carry
394
395 addc r10,r7,r10 # now add to temp result.
396 addze r11,r8 # r8 added to r11 which is 0
397 addze r9,r9
398
399 $ST r10,`1*$BNSZ`(r3) #r[1]=c2;
400 #sqr_add_c(a,1,c3,c1,c2)
401 $UMULL r7,r6,r6
402 $UMULH r8,r6,r6
403 addc r11,r7,r11
404 adde r9,r8,r9
405 addze r10,r0
406 #sqr_add_c2(a,2,0,c3,c1,c2)
407 $LD r6,`2*$BNSZ`(r4)
408 $UMULL r7,r5,r6
409 $UMULH r8,r5,r6
410
411 addc r7,r7,r7
412 adde r8,r8,r8
413 addze r10,r10
414
415 addc r11,r7,r11
416 adde r9,r8,r9
417 addze r10,r10
418 $ST r11,`2*$BNSZ`(r3) #r[2]=c3
419 #sqr_add_c2(a,3,0,c1,c2,c3);
420 $LD r6,`3*$BNSZ`(r4)
421 $UMULL r7,r5,r6
422 $UMULH r8,r5,r6
423 addc r7,r7,r7
424 adde r8,r8,r8
425 addze r11,r0
426
427 addc r9,r7,r9
428 adde r10,r8,r10
429 addze r11,r11
430 #sqr_add_c2(a,2,1,c1,c2,c3);
431 $LD r5,`1*$BNSZ`(r4)
432 $LD r6,`2*$BNSZ`(r4)
433 $UMULL r7,r5,r6
434 $UMULH r8,r5,r6
435
436 addc r7,r7,r7
437 adde r8,r8,r8
438 addze r11,r11
439 addc r9,r7,r9
440 adde r10,r8,r10
441 addze r11,r11
442 $ST r9,`3*$BNSZ`(r3) #r[3]=c1
443 #sqr_add_c(a,2,c2,c3,c1);
444 $UMULL r7,r6,r6
445 $UMULH r8,r6,r6
446 addc r10,r7,r10
447 adde r11,r8,r11
448 addze r9,r0
449 #sqr_add_c2(a,3,1,c2,c3,c1);
450 $LD r6,`3*$BNSZ`(r4)
451 $UMULL r7,r5,r6
452 $UMULH r8,r5,r6
453 addc r7,r7,r7
454 adde r8,r8,r8
455 addze r9,r9
456
457 addc r10,r7,r10
458 adde r11,r8,r11
459 addze r9,r9
460 $ST r10,`4*$BNSZ`(r3) #r[4]=c2
461 #sqr_add_c2(a,3,2,c3,c1,c2);
462 $LD r5,`2*$BNSZ`(r4)
463 $UMULL r7,r5,r6
464 $UMULH r8,r5,r6
465 addc r7,r7,r7
466 adde r8,r8,r8
467 addze r10,r0
468
469 addc r11,r7,r11
470 adde r9,r8,r9
471 addze r10,r10
472 $ST r11,`5*$BNSZ`(r3) #r[5] = c3
473 #sqr_add_c(a,3,c1,c2,c3);
474 $UMULL r7,r6,r6
475 $UMULH r8,r6,r6
476 addc r9,r7,r9
477 adde r10,r8,r10
478
479 $ST r9,`6*$BNSZ`(r3) #r[6]=c1
480 $ST r10,`7*$BNSZ`(r3) #r[7]=c2
481 bclr BO_ALWAYS,CR0_LT
482 .long 0x00000000
483
484#
485# NOTE: The following label name should be changed to
486# "bn_sqr_comba8" i.e. remove the first dot
487# for the gcc compiler. This should be automatically
488# done in the build
489#
490
491.align 4
492.bn_sqr_comba8:
493#
494# This is an optimized version of the bn_sqr_comba8 routine.
495# Tightly uses the adde instruction
496#
497#
498# void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
499# r3 contains r
500# r4 contains a
501#
502# Freely use registers r5,r6,r7,r8,r9,r10,r11 as follows:
503#
504# r5,r6 are the two BN_ULONGs being multiplied.
505# r7,r8 are the results of the 32x32 giving 64 bit multiply.
506# r9,r10, r11 are the equivalents of c1,c2, c3.
507#
508# Possible optimization of loading all 8 longs of a into registers
509# doesnt provide any speedup
510#
511
512 xor r0,r0,r0 #set r0 = 0.Used in addze
513 #instructions below.
514
515 #sqr_add_c(a,0,c1,c2,c3);
516 $LD r5,`0*$BNSZ`(r4)
517 $UMULL r9,r5,r5 #1st iteration: no carries.
518 $UMULH r10,r5,r5
519 $ST r9,`0*$BNSZ`(r3) # r[0]=c1;
520 #sqr_add_c2(a,1,0,c2,c3,c1);
521 $LD r6,`1*$BNSZ`(r4)
522 $UMULL r7,r5,r6
523 $UMULH r8,r5,r6
524
525 addc r10,r7,r10 #add the two register number
526 adde r11,r8,r0 # (r8,r7) to the three register
527 addze r9,r0 # number (r9,r11,r10).NOTE:r0=0
528
529 addc r10,r7,r10 #add the two register number
530 adde r11,r8,r11 # (r8,r7) to the three register
531 addze r9,r9 # number (r9,r11,r10).
532
533 $ST r10,`1*$BNSZ`(r3) # r[1]=c2
534
535 #sqr_add_c(a,1,c3,c1,c2);
536 $UMULL r7,r6,r6
537 $UMULH r8,r6,r6
538 addc r11,r7,r11
539 adde r9,r8,r9
540 addze r10,r0
541 #sqr_add_c2(a,2,0,c3,c1,c2);
542 $LD r6,`2*$BNSZ`(r4)
543 $UMULL r7,r5,r6
544 $UMULH r8,r5,r6
545
546 addc r11,r7,r11
547 adde r9,r8,r9
548 addze r10,r10
549
550 addc r11,r7,r11
551 adde r9,r8,r9
552 addze r10,r10
553
554 $ST r11,`2*$BNSZ`(r3) #r[2]=c3
555 #sqr_add_c2(a,3,0,c1,c2,c3);
556 $LD r6,`3*$BNSZ`(r4) #r6 = a[3]. r5 is already a[0].
557 $UMULL r7,r5,r6
558 $UMULH r8,r5,r6
559
560 addc r9,r7,r9
561 adde r10,r8,r10
562 addze r11,r0
563
564 addc r9,r7,r9
565 adde r10,r8,r10
566 addze r11,r11
567 #sqr_add_c2(a,2,1,c1,c2,c3);
568 $LD r5,`1*$BNSZ`(r4)
569 $LD r6,`2*$BNSZ`(r4)
570 $UMULL r7,r5,r6
571 $UMULH r8,r5,r6
572
573 addc r9,r7,r9
574 adde r10,r8,r10
575 addze r11,r11
576
577 addc r9,r7,r9
578 adde r10,r8,r10
579 addze r11,r11
580
581 $ST r9,`3*$BNSZ`(r3) #r[3]=c1;
582 #sqr_add_c(a,2,c2,c3,c1);
583 $UMULL r7,r6,r6
584 $UMULH r8,r6,r6
585
586 addc r10,r7,r10
587 adde r11,r8,r11
588 addze r9,r0
589 #sqr_add_c2(a,3,1,c2,c3,c1);
590 $LD r6,`3*$BNSZ`(r4)
591 $UMULL r7,r5,r6
592 $UMULH r8,r5,r6
593
594 addc r10,r7,r10
595 adde r11,r8,r11
596 addze r9,r9
597
598 addc r10,r7,r10
599 adde r11,r8,r11
600 addze r9,r9
601 #sqr_add_c2(a,4,0,c2,c3,c1);
602 $LD r5,`0*$BNSZ`(r4)
603 $LD r6,`4*$BNSZ`(r4)
604 $UMULL r7,r5,r6
605 $UMULH r8,r5,r6
606
607 addc r10,r7,r10
608 adde r11,r8,r11
609 addze r9,r9
610
611 addc r10,r7,r10
612 adde r11,r8,r11
613 addze r9,r9
614 $ST r10,`4*$BNSZ`(r3) #r[4]=c2;
615 #sqr_add_c2(a,5,0,c3,c1,c2);
616 $LD r6,`5*$BNSZ`(r4)
617 $UMULL r7,r5,r6
618 $UMULH r8,r5,r6
619
620 addc r11,r7,r11
621 adde r9,r8,r9
622 addze r10,r0
623
624 addc r11,r7,r11
625 adde r9,r8,r9
626 addze r10,r10
627 #sqr_add_c2(a,4,1,c3,c1,c2);
628 $LD r5,`1*$BNSZ`(r4)
629 $LD r6,`4*$BNSZ`(r4)
630 $UMULL r7,r5,r6
631 $UMULH r8,r5,r6
632
633 addc r11,r7,r11
634 adde r9,r8,r9
635 addze r10,r10
636
637 addc r11,r7,r11
638 adde r9,r8,r9
639 addze r10,r10
640 #sqr_add_c2(a,3,2,c3,c1,c2);
641 $LD r5,`2*$BNSZ`(r4)
642 $LD r6,`3*$BNSZ`(r4)
643 $UMULL r7,r5,r6
644 $UMULH r8,r5,r6
645
646 addc r11,r7,r11
647 adde r9,r8,r9
648 addze r10,r10
649
650 addc r11,r7,r11
651 adde r9,r8,r9
652 addze r10,r10
653 $ST r11,`5*$BNSZ`(r3) #r[5]=c3;
654 #sqr_add_c(a,3,c1,c2,c3);
655 $UMULL r7,r6,r6
656 $UMULH r8,r6,r6
657 addc r9,r7,r9
658 adde r10,r8,r10
659 addze r11,r0
660 #sqr_add_c2(a,4,2,c1,c2,c3);
661 $LD r6,`4*$BNSZ`(r4)
662 $UMULL r7,r5,r6
663 $UMULH r8,r5,r6
664
665 addc r9,r7,r9
666 adde r10,r8,r10
667 addze r11,r11
668
669 addc r9,r7,r9
670 adde r10,r8,r10
671 addze r11,r11
672 #sqr_add_c2(a,5,1,c1,c2,c3);
673 $LD r5,`1*$BNSZ`(r4)
674 $LD r6,`5*$BNSZ`(r4)
675 $UMULL r7,r5,r6
676 $UMULH r8,r5,r6
677
678 addc r9,r7,r9
679 adde r10,r8,r10
680 addze r11,r11
681
682 addc r9,r7,r9
683 adde r10,r8,r10
684 addze r11,r11
685 #sqr_add_c2(a,6,0,c1,c2,c3);
686 $LD r5,`0*$BNSZ`(r4)
687 $LD r6,`6*$BNSZ`(r4)
688 $UMULL r7,r5,r6
689 $UMULH r8,r5,r6
690 addc r9,r7,r9
691 adde r10,r8,r10
692 addze r11,r11
693 addc r9,r7,r9
694 adde r10,r8,r10
695 addze r11,r11
696 $ST r9,`6*$BNSZ`(r3) #r[6]=c1;
697 #sqr_add_c2(a,7,0,c2,c3,c1);
698 $LD r6,`7*$BNSZ`(r4)
699 $UMULL r7,r5,r6
700 $UMULH r8,r5,r6
701
702 addc r10,r7,r10
703 adde r11,r8,r11
704 addze r9,r0
705 addc r10,r7,r10
706 adde r11,r8,r11
707 addze r9,r9
708 #sqr_add_c2(a,6,1,c2,c3,c1);
709 $LD r5,`1*$BNSZ`(r4)
710 $LD r6,`6*$BNSZ`(r4)
711 $UMULL r7,r5,r6
712 $UMULH r8,r5,r6
713
714 addc r10,r7,r10
715 adde r11,r8,r11
716 addze r9,r9
717 addc r10,r7,r10
718 adde r11,r8,r11
719 addze r9,r9
720 #sqr_add_c2(a,5,2,c2,c3,c1);
721 $LD r5,`2*$BNSZ`(r4)
722 $LD r6,`5*$BNSZ`(r4)
723 $UMULL r7,r5,r6
724 $UMULH r8,r5,r6
725 addc r10,r7,r10
726 adde r11,r8,r11
727 addze r9,r9
728 addc r10,r7,r10
729 adde r11,r8,r11
730 addze r9,r9
731 #sqr_add_c2(a,4,3,c2,c3,c1);
732 $LD r5,`3*$BNSZ`(r4)
733 $LD r6,`4*$BNSZ`(r4)
734 $UMULL r7,r5,r6
735 $UMULH r8,r5,r6
736
737 addc r10,r7,r10
738 adde r11,r8,r11
739 addze r9,r9
740 addc r10,r7,r10
741 adde r11,r8,r11
742 addze r9,r9
743 $ST r10,`7*$BNSZ`(r3) #r[7]=c2;
744 #sqr_add_c(a,4,c3,c1,c2);
745 $UMULL r7,r6,r6
746 $UMULH r8,r6,r6
747 addc r11,r7,r11
748 adde r9,r8,r9
749 addze r10,r0
750 #sqr_add_c2(a,5,3,c3,c1,c2);
751 $LD r6,`5*$BNSZ`(r4)
752 $UMULL r7,r5,r6
753 $UMULH r8,r5,r6
754 addc r11,r7,r11
755 adde r9,r8,r9
756 addze r10,r10
757 addc r11,r7,r11
758 adde r9,r8,r9
759 addze r10,r10
760 #sqr_add_c2(a,6,2,c3,c1,c2);
761 $LD r5,`2*$BNSZ`(r4)
762 $LD r6,`6*$BNSZ`(r4)
763 $UMULL r7,r5,r6
764 $UMULH r8,r5,r6
765 addc r11,r7,r11
766 adde r9,r8,r9
767 addze r10,r10
768
769 addc r11,r7,r11
770 adde r9,r8,r9
771 addze r10,r10
772 #sqr_add_c2(a,7,1,c3,c1,c2);
773 $LD r5,`1*$BNSZ`(r4)
774 $LD r6,`7*$BNSZ`(r4)
775 $UMULL r7,r5,r6
776 $UMULH r8,r5,r6
777 addc r11,r7,r11
778 adde r9,r8,r9
779 addze r10,r10
780 addc r11,r7,r11
781 adde r9,r8,r9
782 addze r10,r10
783 $ST r11,`8*$BNSZ`(r3) #r[8]=c3;
784 #sqr_add_c2(a,7,2,c1,c2,c3);
785 $LD r5,`2*$BNSZ`(r4)
786 $UMULL r7,r5,r6
787 $UMULH r8,r5,r6
788
789 addc r9,r7,r9
790 adde r10,r8,r10
791 addze r11,r0
792 addc r9,r7,r9
793 adde r10,r8,r10
794 addze r11,r11
795 #sqr_add_c2(a,6,3,c1,c2,c3);
796 $LD r5,`3*$BNSZ`(r4)
797 $LD r6,`6*$BNSZ`(r4)
798 $UMULL r7,r5,r6
799 $UMULH r8,r5,r6
800 addc r9,r7,r9
801 adde r10,r8,r10
802 addze r11,r11
803 addc r9,r7,r9
804 adde r10,r8,r10
805 addze r11,r11
806 #sqr_add_c2(a,5,4,c1,c2,c3);
807 $LD r5,`4*$BNSZ`(r4)
808 $LD r6,`5*$BNSZ`(r4)
809 $UMULL r7,r5,r6
810 $UMULH r8,r5,r6
811 addc r9,r7,r9
812 adde r10,r8,r10
813 addze r11,r11
814 addc r9,r7,r9
815 adde r10,r8,r10
816 addze r11,r11
817 $ST r9,`9*$BNSZ`(r3) #r[9]=c1;
818 #sqr_add_c(a,5,c2,c3,c1);
819 $UMULL r7,r6,r6
820 $UMULH r8,r6,r6
821 addc r10,r7,r10
822 adde r11,r8,r11
823 addze r9,r0
824 #sqr_add_c2(a,6,4,c2,c3,c1);
825 $LD r6,`6*$BNSZ`(r4)
826 $UMULL r7,r5,r6
827 $UMULH r8,r5,r6
828 addc r10,r7,r10
829 adde r11,r8,r11
830 addze r9,r9
831 addc r10,r7,r10
832 adde r11,r8,r11
833 addze r9,r9
834 #sqr_add_c2(a,7,3,c2,c3,c1);
835 $LD r5,`3*$BNSZ`(r4)
836 $LD r6,`7*$BNSZ`(r4)
837 $UMULL r7,r5,r6
838 $UMULH r8,r5,r6
839 addc r10,r7,r10
840 adde r11,r8,r11
841 addze r9,r9
842 addc r10,r7,r10
843 adde r11,r8,r11
844 addze r9,r9
845 $ST r10,`10*$BNSZ`(r3) #r[10]=c2;
846 #sqr_add_c2(a,7,4,c3,c1,c2);
847 $LD r5,`4*$BNSZ`(r4)
848 $UMULL r7,r5,r6
849 $UMULH r8,r5,r6
850 addc r11,r7,r11
851 adde r9,r8,r9
852 addze r10,r0
853 addc r11,r7,r11
854 adde r9,r8,r9
855 addze r10,r10
856 #sqr_add_c2(a,6,5,c3,c1,c2);
857 $LD r5,`5*$BNSZ`(r4)
858 $LD r6,`6*$BNSZ`(r4)
859 $UMULL r7,r5,r6
860 $UMULH r8,r5,r6
861 addc r11,r7,r11
862 adde r9,r8,r9
863 addze r10,r10
864 addc r11,r7,r11
865 adde r9,r8,r9
866 addze r10,r10
867 $ST r11,`11*$BNSZ`(r3) #r[11]=c3;
868 #sqr_add_c(a,6,c1,c2,c3);
869 $UMULL r7,r6,r6
870 $UMULH r8,r6,r6
871 addc r9,r7,r9
872 adde r10,r8,r10
873 addze r11,r0
874 #sqr_add_c2(a,7,5,c1,c2,c3)
875 $LD r6,`7*$BNSZ`(r4)
876 $UMULL r7,r5,r6
877 $UMULH r8,r5,r6
878 addc r9,r7,r9
879 adde r10,r8,r10
880 addze r11,r11
881 addc r9,r7,r9
882 adde r10,r8,r10
883 addze r11,r11
884 $ST r9,`12*$BNSZ`(r3) #r[12]=c1;
885
886 #sqr_add_c2(a,7,6,c2,c3,c1)
887 $LD r5,`6*$BNSZ`(r4)
888 $UMULL r7,r5,r6
889 $UMULH r8,r5,r6
890 addc r10,r7,r10
891 adde r11,r8,r11
892 addze r9,r0
893 addc r10,r7,r10
894 adde r11,r8,r11
895 addze r9,r9
896 $ST r10,`13*$BNSZ`(r3) #r[13]=c2;
897 #sqr_add_c(a,7,c3,c1,c2);
898 $UMULL r7,r6,r6
899 $UMULH r8,r6,r6
900 addc r11,r7,r11
901 adde r9,r8,r9
902 $ST r11,`14*$BNSZ`(r3) #r[14]=c3;
903 $ST r9, `15*$BNSZ`(r3) #r[15]=c1;
904
905
906 bclr BO_ALWAYS,CR0_LT
907
908 .long 0x00000000
909
910#
911# NOTE: The following label name should be changed to
912# "bn_mul_comba4" i.e. remove the first dot
913# for the gcc compiler. This should be automatically
914# done in the build
915#
916
917.align 4
918.bn_mul_comba4:
919#
920# This is an optimized version of the bn_mul_comba4 routine.
921#
922# void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
923# r3 contains r
924# r4 contains a
925# r5 contains b
926# r6, r7 are the 2 BN_ULONGs being multiplied.
927# r8, r9 are the results of the 32x32 giving 64 multiply.
928# r10, r11, r12 are the equivalents of c1, c2, and c3.
929#
930 xor r0,r0,r0 #r0=0. Used in addze below.
931 #mul_add_c(a[0],b[0],c1,c2,c3);
932 $LD r6,`0*$BNSZ`(r4)
933 $LD r7,`0*$BNSZ`(r5)
934 $UMULL r10,r6,r7
935 $UMULH r11,r6,r7
936 $ST r10,`0*$BNSZ`(r3) #r[0]=c1
937 #mul_add_c(a[0],b[1],c2,c3,c1);
938 $LD r7,`1*$BNSZ`(r5)
939 $UMULL r8,r6,r7
940 $UMULH r9,r6,r7
941 addc r11,r8,r11
942 adde r12,r9,r0
943 addze r10,r0
944 #mul_add_c(a[1],b[0],c2,c3,c1);
945 $LD r6, `1*$BNSZ`(r4)
946 $LD r7, `0*$BNSZ`(r5)
947 $UMULL r8,r6,r7
948 $UMULH r9,r6,r7
949 addc r11,r8,r11
950 adde r12,r9,r12
951 addze r10,r10
952 $ST r11,`1*$BNSZ`(r3) #r[1]=c2
953 #mul_add_c(a[2],b[0],c3,c1,c2);
954 $LD r6,`2*$BNSZ`(r4)
955 $UMULL r8,r6,r7
956 $UMULH r9,r6,r7
957 addc r12,r8,r12
958 adde r10,r9,r10
959 addze r11,r0
960 #mul_add_c(a[1],b[1],c3,c1,c2);
961 $LD r6,`1*$BNSZ`(r4)
962 $LD r7,`1*$BNSZ`(r5)
963 $UMULL r8,r6,r7
964 $UMULH r9,r6,r7
965 addc r12,r8,r12
966 adde r10,r9,r10
967 addze r11,r11
968 #mul_add_c(a[0],b[2],c3,c1,c2);
969 $LD r6,`0*$BNSZ`(r4)
970 $LD r7,`2*$BNSZ`(r5)
971 $UMULL r8,r6,r7
972 $UMULH r9,r6,r7
973 addc r12,r8,r12
974 adde r10,r9,r10
975 addze r11,r11
976 $ST r12,`2*$BNSZ`(r3) #r[2]=c3
977 #mul_add_c(a[0],b[3],c1,c2,c3);
978 $LD r7,`3*$BNSZ`(r5)
979 $UMULL r8,r6,r7
980 $UMULH r9,r6,r7
981 addc r10,r8,r10
982 adde r11,r9,r11
983 addze r12,r0
984 #mul_add_c(a[1],b[2],c1,c2,c3);
985 $LD r6,`1*$BNSZ`(r4)
986 $LD r7,`2*$BNSZ`(r5)
987 $UMULL r8,r6,r7
988 $UMULH r9,r6,r7
989 addc r10,r8,r10
990 adde r11,r9,r11
991 addze r12,r12
992 #mul_add_c(a[2],b[1],c1,c2,c3);
993 $LD r6,`2*$BNSZ`(r4)
994 $LD r7,`1*$BNSZ`(r5)
995 $UMULL r8,r6,r7
996 $UMULH r9,r6,r7
997 addc r10,r8,r10
998 adde r11,r9,r11
999 addze r12,r12
1000 #mul_add_c(a[3],b[0],c1,c2,c3);
1001 $LD r6,`3*$BNSZ`(r4)
1002 $LD r7,`0*$BNSZ`(r5)
1003 $UMULL r8,r6,r7
1004 $UMULH r9,r6,r7
1005 addc r10,r8,r10
1006 adde r11,r9,r11
1007 addze r12,r12
1008 $ST r10,`3*$BNSZ`(r3) #r[3]=c1
1009 #mul_add_c(a[3],b[1],c2,c3,c1);
1010 $LD r7,`1*$BNSZ`(r5)
1011 $UMULL r8,r6,r7
1012 $UMULH r9,r6,r7
1013 addc r11,r8,r11
1014 adde r12,r9,r12
1015 addze r10,r0
1016 #mul_add_c(a[2],b[2],c2,c3,c1);
1017 $LD r6,`2*$BNSZ`(r4)
1018 $LD r7,`2*$BNSZ`(r5)
1019 $UMULL r8,r6,r7
1020 $UMULH r9,r6,r7
1021 addc r11,r8,r11
1022 adde r12,r9,r12
1023 addze r10,r10
1024 #mul_add_c(a[1],b[3],c2,c3,c1);
1025 $LD r6,`1*$BNSZ`(r4)
1026 $LD r7,`3*$BNSZ`(r5)
1027 $UMULL r8,r6,r7
1028 $UMULH r9,r6,r7
1029 addc r11,r8,r11
1030 adde r12,r9,r12
1031 addze r10,r10
1032 $ST r11,`4*$BNSZ`(r3) #r[4]=c2
1033 #mul_add_c(a[2],b[3],c3,c1,c2);
1034 $LD r6,`2*$BNSZ`(r4)
1035 $UMULL r8,r6,r7
1036 $UMULH r9,r6,r7
1037 addc r12,r8,r12
1038 adde r10,r9,r10
1039 addze r11,r0
1040 #mul_add_c(a[3],b[2],c3,c1,c2);
1041 $LD r6,`3*$BNSZ`(r4)
1042 $LD r7,`2*$BNSZ`(r4)
1043 $UMULL r8,r6,r7
1044 $UMULH r9,r6,r7
1045 addc r12,r8,r12
1046 adde r10,r9,r10
1047 addze r11,r11
1048 $ST r12,`5*$BNSZ`(r3) #r[5]=c3
1049 #mul_add_c(a[3],b[3],c1,c2,c3);
1050 $LD r7,`3*$BNSZ`(r5)
1051 $UMULL r8,r6,r7
1052 $UMULH r9,r6,r7
1053 addc r10,r8,r10
1054 adde r11,r9,r11
1055
1056 $ST r10,`6*$BNSZ`(r3) #r[6]=c1
1057 $ST r11,`7*$BNSZ`(r3) #r[7]=c2
1058 bclr BO_ALWAYS,CR0_LT
1059 .long 0x00000000
1060
1061#
1062# NOTE: The following label name should be changed to
1063# "bn_mul_comba8" i.e. remove the first dot
1064# for the gcc compiler. This should be automatically
1065# done in the build
1066#
1067
1068.align 4
1069.bn_mul_comba8:
1070#
1071# Optimized version of the bn_mul_comba8 routine.
1072#
1073# void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1074# r3 contains r
1075# r4 contains a
1076# r5 contains b
1077# r6, r7 are the 2 BN_ULONGs being multiplied.
1078# r8, r9 are the results of the 32x32 giving 64 multiply.
1079# r10, r11, r12 are the equivalents of c1, c2, and c3.
1080#
1081 xor r0,r0,r0 #r0=0. Used in addze below.
1082
1083 #mul_add_c(a[0],b[0],c1,c2,c3);
1084 $LD r6,`0*$BNSZ`(r4) #a[0]
1085 $LD r7,`0*$BNSZ`(r5) #b[0]
1086 $UMULL r10,r6,r7
1087 $UMULH r11,r6,r7
1088 $ST r10,`0*$BNSZ`(r3) #r[0]=c1;
1089 #mul_add_c(a[0],b[1],c2,c3,c1);
1090 $LD r7,`1*$BNSZ`(r5)
1091 $UMULL r8,r6,r7
1092 $UMULH r9,r6,r7
1093 addc r11,r11,r8
1094 addze r12,r9 # since we didnt set r12 to zero before.
1095 addze r10,r0
1096 #mul_add_c(a[1],b[0],c2,c3,c1);
1097 $LD r6,`1*$BNSZ`(r4)
1098 $LD r7,`0*$BNSZ`(r5)
1099 $UMULL r8,r6,r7
1100 $UMULH r9,r6,r7
1101 addc r11,r11,r8
1102 adde r12,r12,r9
1103 addze r10,r10
1104 $ST r11,`1*$BNSZ`(r3) #r[1]=c2;
1105 #mul_add_c(a[2],b[0],c3,c1,c2);
1106 $LD r6,`2*$BNSZ`(r4)
1107 $UMULL r8,r6,r7
1108 $UMULH r9,r6,r7
1109 addc r12,r12,r8
1110 adde r10,r10,r9
1111 addze r11,r0
1112 #mul_add_c(a[1],b[1],c3,c1,c2);
1113 $LD r6,`1*$BNSZ`(r4)
1114 $LD r7,`1*$BNSZ`(r5)
1115 $UMULL r8,r6,r7
1116 $UMULH r9,r6,r7
1117 addc r12,r12,r8
1118 adde r10,r10,r9
1119 addze r11,r11
1120 #mul_add_c(a[0],b[2],c3,c1,c2);
1121 $LD r6,`0*$BNSZ`(r4)
1122 $LD r7,`2*$BNSZ`(r5)
1123 $UMULL r8,r6,r7
1124 $UMULH r9,r6,r7
1125 addc r12,r12,r8
1126 adde r10,r10,r9
1127 addze r11,r11
1128 $ST r12,`2*$BNSZ`(r3) #r[2]=c3;
1129 #mul_add_c(a[0],b[3],c1,c2,c3);
1130 $LD r7,`3*$BNSZ`(r5)
1131 $UMULL r8,r6,r7
1132 $UMULH r9,r6,r7
1133 addc r10,r10,r8
1134 adde r11,r11,r9
1135 addze r12,r0
1136 #mul_add_c(a[1],b[2],c1,c2,c3);
1137 $LD r6,`1*$BNSZ`(r4)
1138 $LD r7,`2*$BNSZ`(r5)
1139 $UMULL r8,r6,r7
1140 $UMULH r9,r6,r7
1141 addc r10,r10,r8
1142 adde r11,r11,r9
1143 addze r12,r12
1144
1145 #mul_add_c(a[2],b[1],c1,c2,c3);
1146 $LD r6,`2*$BNSZ`(r4)
1147 $LD r7,`1*$BNSZ`(r5)
1148 $UMULL r8,r6,r7
1149 $UMULH r9,r6,r7
1150 addc r10,r10,r8
1151 adde r11,r11,r9
1152 addze r12,r12
1153 #mul_add_c(a[3],b[0],c1,c2,c3);
1154 $LD r6,`3*$BNSZ`(r4)
1155 $LD r7,`0*$BNSZ`(r5)
1156 $UMULL r8,r6,r7
1157 $UMULH r9,r6,r7
1158 addc r10,r10,r8
1159 adde r11,r11,r9
1160 addze r12,r12
1161 $ST r10,`3*$BNSZ`(r3) #r[3]=c1;
1162 #mul_add_c(a[4],b[0],c2,c3,c1);
1163 $LD r6,`4*$BNSZ`(r4)
1164 $UMULL r8,r6,r7
1165 $UMULH r9,r6,r7
1166 addc r11,r11,r8
1167 adde r12,r12,r9
1168 addze r10,r0
1169 #mul_add_c(a[3],b[1],c2,c3,c1);
1170 $LD r6,`3*$BNSZ`(r4)
1171 $LD r7,`1*$BNSZ`(r5)
1172 $UMULL r8,r6,r7
1173 $UMULH r9,r6,r7
1174 addc r11,r11,r8
1175 adde r12,r12,r9
1176 addze r10,r10
1177 #mul_add_c(a[2],b[2],c2,c3,c1);
1178 $LD r6,`2*$BNSZ`(r4)
1179 $LD r7,`2*$BNSZ`(r5)
1180 $UMULL r8,r6,r7
1181 $UMULH r9,r6,r7
1182 addc r11,r11,r8
1183 adde r12,r12,r9
1184 addze r10,r10
1185 #mul_add_c(a[1],b[3],c2,c3,c1);
1186 $LD r6,`1*$BNSZ`(r4)
1187 $LD r7,`3*$BNSZ`(r5)
1188 $UMULL r8,r6,r7
1189 $UMULH r9,r6,r7
1190 addc r11,r11,r8
1191 adde r12,r12,r9
1192 addze r10,r10
1193 #mul_add_c(a[0],b[4],c2,c3,c1);
1194 $LD r6,`0*$BNSZ`(r4)
1195 $LD r7,`4*$BNSZ`(r5)
1196 $UMULL r8,r6,r7
1197 $UMULH r9,r6,r7
1198 addc r11,r11,r8
1199 adde r12,r12,r9
1200 addze r10,r10
1201 $ST r11,`4*$BNSZ`(r3) #r[4]=c2;
1202 #mul_add_c(a[0],b[5],c3,c1,c2);
1203 $LD r7,`5*$BNSZ`(r5)
1204 $UMULL r8,r6,r7
1205 $UMULH r9,r6,r7
1206 addc r12,r12,r8
1207 adde r10,r10,r9
1208 addze r11,r0
1209 #mul_add_c(a[1],b[4],c3,c1,c2);
1210 $LD r6,`1*$BNSZ`(r4)
1211 $LD r7,`4*$BNSZ`(r5)
1212 $UMULL r8,r6,r7
1213 $UMULH r9,r6,r7
1214 addc r12,r12,r8
1215 adde r10,r10,r9
1216 addze r11,r11
1217 #mul_add_c(a[2],b[3],c3,c1,c2);
1218 $LD r6,`2*$BNSZ`(r4)
1219 $LD r7,`3*$BNSZ`(r5)
1220 $UMULL r8,r6,r7
1221 $UMULH r9,r6,r7
1222 addc r12,r12,r8
1223 adde r10,r10,r9
1224 addze r11,r11
1225 #mul_add_c(a[3],b[2],c3,c1,c2);
1226 $LD r6,`3*$BNSZ`(r4)
1227 $LD r7,`2*$BNSZ`(r5)
1228 $UMULL r8,r6,r7
1229 $UMULH r9,r6,r7
1230 addc r12,r12,r8
1231 adde r10,r10,r9
1232 addze r11,r11
1233 #mul_add_c(a[4],b[1],c3,c1,c2);
1234 $LD r6,`4*$BNSZ`(r4)
1235 $LD r7,`1*$BNSZ`(r5)
1236 $UMULL r8,r6,r7
1237 $UMULH r9,r6,r7
1238 addc r12,r12,r8
1239 adde r10,r10,r9
1240 addze r11,r11
1241 #mul_add_c(a[5],b[0],c3,c1,c2);
1242 $LD r6,`5*$BNSZ`(r4)
1243 $LD r7,`0*$BNSZ`(r5)
1244 $UMULL r8,r6,r7
1245 $UMULH r9,r6,r7
1246 addc r12,r12,r8
1247 adde r10,r10,r9
1248 addze r11,r11
1249 $ST r12,`5*$BNSZ`(r3) #r[5]=c3;
1250 #mul_add_c(a[6],b[0],c1,c2,c3);
1251 $LD r6,`6*$BNSZ`(r4)
1252 $UMULL r8,r6,r7
1253 $UMULH r9,r6,r7
1254 addc r10,r10,r8
1255 adde r11,r11,r9
1256 addze r12,r0
1257 #mul_add_c(a[5],b[1],c1,c2,c3);
1258 $LD r6,`5*$BNSZ`(r4)
1259 $LD r7,`1*$BNSZ`(r5)
1260 $UMULL r8,r6,r7
1261 $UMULH r9,r6,r7
1262 addc r10,r10,r8
1263 adde r11,r11,r9
1264 addze r12,r12
1265 #mul_add_c(a[4],b[2],c1,c2,c3);
1266 $LD r6,`4*$BNSZ`(r4)
1267 $LD r7,`2*$BNSZ`(r5)
1268 $UMULL r8,r6,r7
1269 $UMULH r9,r6,r7
1270 addc r10,r10,r8
1271 adde r11,r11,r9
1272 addze r12,r12
1273 #mul_add_c(a[3],b[3],c1,c2,c3);
1274 $LD r6,`3*$BNSZ`(r4)
1275 $LD r7,`3*$BNSZ`(r5)
1276 $UMULL r8,r6,r7
1277 $UMULH r9,r6,r7
1278 addc r10,r10,r8
1279 adde r11,r11,r9
1280 addze r12,r12
1281 #mul_add_c(a[2],b[4],c1,c2,c3);
1282 $LD r6,`2*$BNSZ`(r4)
1283 $LD r7,`4*$BNSZ`(r5)
1284 $UMULL r8,r6,r7
1285 $UMULH r9,r6,r7
1286 addc r10,r10,r8
1287 adde r11,r11,r9
1288 addze r12,r12
1289 #mul_add_c(a[1],b[5],c1,c2,c3);
1290 $LD r6,`1*$BNSZ`(r4)
1291 $LD r7,`5*$BNSZ`(r5)
1292 $UMULL r8,r6,r7
1293 $UMULH r9,r6,r7
1294 addc r10,r10,r8
1295 adde r11,r11,r9
1296 addze r12,r12
1297 #mul_add_c(a[0],b[6],c1,c2,c3);
1298 $LD r6,`0*$BNSZ`(r4)
1299 $LD r7,`6*$BNSZ`(r5)
1300 $UMULL r8,r6,r7
1301 $UMULH r9,r6,r7
1302 addc r10,r10,r8
1303 adde r11,r11,r9
1304 addze r12,r12
1305 $ST r10,`6*$BNSZ`(r3) #r[6]=c1;
1306 #mul_add_c(a[0],b[7],c2,c3,c1);
1307 $LD r7,`7*$BNSZ`(r5)
1308 $UMULL r8,r6,r7
1309 $UMULH r9,r6,r7
1310 addc r11,r11,r8
1311 adde r12,r12,r9
1312 addze r10,r0
1313 #mul_add_c(a[1],b[6],c2,c3,c1);
1314 $LD r6,`1*$BNSZ`(r4)
1315 $LD r7,`6*$BNSZ`(r5)
1316 $UMULL r8,r6,r7
1317 $UMULH r9,r6,r7
1318 addc r11,r11,r8
1319 adde r12,r12,r9
1320 addze r10,r10
1321 #mul_add_c(a[2],b[5],c2,c3,c1);
1322 $LD r6,`2*$BNSZ`(r4)
1323 $LD r7,`5*$BNSZ`(r5)
1324 $UMULL r8,r6,r7
1325 $UMULH r9,r6,r7
1326 addc r11,r11,r8
1327 adde r12,r12,r9
1328 addze r10,r10
1329 #mul_add_c(a[3],b[4],c2,c3,c1);
1330 $LD r6,`3*$BNSZ`(r4)
1331 $LD r7,`4*$BNSZ`(r5)
1332 $UMULL r8,r6,r7
1333 $UMULH r9,r6,r7
1334 addc r11,r11,r8
1335 adde r12,r12,r9
1336 addze r10,r10
1337 #mul_add_c(a[4],b[3],c2,c3,c1);
1338 $LD r6,`4*$BNSZ`(r4)
1339 $LD r7,`3*$BNSZ`(r5)
1340 $UMULL r8,r6,r7
1341 $UMULH r9,r6,r7
1342 addc r11,r11,r8
1343 adde r12,r12,r9
1344 addze r10,r10
1345 #mul_add_c(a[5],b[2],c2,c3,c1);
1346 $LD r6,`5*$BNSZ`(r4)
1347 $LD r7,`2*$BNSZ`(r5)
1348 $UMULL r8,r6,r7
1349 $UMULH r9,r6,r7
1350 addc r11,r11,r8
1351 adde r12,r12,r9
1352 addze r10,r10
1353 #mul_add_c(a[6],b[1],c2,c3,c1);
1354 $LD r6,`6*$BNSZ`(r4)
1355 $LD r7,`1*$BNSZ`(r5)
1356 $UMULL r8,r6,r7
1357 $UMULH r9,r6,r7
1358 addc r11,r11,r8
1359 adde r12,r12,r9
1360 addze r10,r10
1361 #mul_add_c(a[7],b[0],c2,c3,c1);
1362 $LD r6,`7*$BNSZ`(r4)
1363 $LD r7,`0*$BNSZ`(r5)
1364 $UMULL r8,r6,r7
1365 $UMULH r9,r6,r7
1366 addc r11,r11,r8
1367 adde r12,r12,r9
1368 addze r10,r10
1369 $ST r11,`7*$BNSZ`(r3) #r[7]=c2;
1370 #mul_add_c(a[7],b[1],c3,c1,c2);
1371 $LD r7,`1*$BNSZ`(r5)
1372 $UMULL r8,r6,r7
1373 $UMULH r9,r6,r7
1374 addc r12,r12,r8
1375 adde r10,r10,r9
1376 addze r11,r0
1377 #mul_add_c(a[6],b[2],c3,c1,c2);
1378 $LD r6,`6*$BNSZ`(r4)
1379 $LD r7,`2*$BNSZ`(r5)
1380 $UMULL r8,r6,r7
1381 $UMULH r9,r6,r7
1382 addc r12,r12,r8
1383 adde r10,r10,r9
1384 addze r11,r11
1385 #mul_add_c(a[5],b[3],c3,c1,c2);
1386 $LD r6,`5*$BNSZ`(r4)
1387 $LD r7,`3*$BNSZ`(r5)
1388 $UMULL r8,r6,r7
1389 $UMULH r9,r6,r7
1390 addc r12,r12,r8
1391 adde r10,r10,r9
1392 addze r11,r11
1393 #mul_add_c(a[4],b[4],c3,c1,c2);
1394 $LD r6,`4*$BNSZ`(r4)
1395 $LD r7,`4*$BNSZ`(r5)
1396 $UMULL r8,r6,r7
1397 $UMULH r9,r6,r7
1398 addc r12,r12,r8
1399 adde r10,r10,r9
1400 addze r11,r11
1401 #mul_add_c(a[3],b[5],c3,c1,c2);
1402 $LD r6,`3*$BNSZ`(r4)
1403 $LD r7,`5*$BNSZ`(r5)
1404 $UMULL r8,r6,r7
1405 $UMULH r9,r6,r7
1406 addc r12,r12,r8
1407 adde r10,r10,r9
1408 addze r11,r11
1409 #mul_add_c(a[2],b[6],c3,c1,c2);
1410 $LD r6,`2*$BNSZ`(r4)
1411 $LD r7,`6*$BNSZ`(r5)
1412 $UMULL r8,r6,r7
1413 $UMULH r9,r6,r7
1414 addc r12,r12,r8
1415 adde r10,r10,r9
1416 addze r11,r11
1417 #mul_add_c(a[1],b[7],c3,c1,c2);
1418 $LD r6,`1*$BNSZ`(r4)
1419 $LD r7,`7*$BNSZ`(r5)
1420 $UMULL r8,r6,r7
1421 $UMULH r9,r6,r7
1422 addc r12,r12,r8
1423 adde r10,r10,r9
1424 addze r11,r11
1425 $ST r12,`8*$BNSZ`(r3) #r[8]=c3;
1426 #mul_add_c(a[2],b[7],c1,c2,c3);
1427 $LD r6,`2*$BNSZ`(r4)
1428 $UMULL r8,r6,r7
1429 $UMULH r9,r6,r7
1430 addc r10,r10,r8
1431 adde r11,r11,r9
1432 addze r12,r0
1433 #mul_add_c(a[3],b[6],c1,c2,c3);
1434 $LD r6,`3*$BNSZ`(r4)
1435 $LD r7,`6*$BNSZ`(r5)
1436 $UMULL r8,r6,r7
1437 $UMULH r9,r6,r7
1438 addc r10,r10,r8
1439 adde r11,r11,r9
1440 addze r12,r12
1441 #mul_add_c(a[4],b[5],c1,c2,c3);
1442 $LD r6,`4*$BNSZ`(r4)
1443 $LD r7,`5*$BNSZ`(r5)
1444 $UMULL r8,r6,r7
1445 $UMULH r9,r6,r7
1446 addc r10,r10,r8
1447 adde r11,r11,r9
1448 addze r12,r12
1449 #mul_add_c(a[5],b[4],c1,c2,c3);
1450 $LD r6,`5*$BNSZ`(r4)
1451 $LD r7,`4*$BNSZ`(r5)
1452 $UMULL r8,r6,r7
1453 $UMULH r9,r6,r7
1454 addc r10,r10,r8
1455 adde r11,r11,r9
1456 addze r12,r12
1457 #mul_add_c(a[6],b[3],c1,c2,c3);
1458 $LD r6,`6*$BNSZ`(r4)
1459 $LD r7,`3*$BNSZ`(r5)
1460 $UMULL r8,r6,r7
1461 $UMULH r9,r6,r7
1462 addc r10,r10,r8
1463 adde r11,r11,r9
1464 addze r12,r12
1465 #mul_add_c(a[7],b[2],c1,c2,c3);
1466 $LD r6,`7*$BNSZ`(r4)
1467 $LD r7,`2*$BNSZ`(r5)
1468 $UMULL r8,r6,r7
1469 $UMULH r9,r6,r7
1470 addc r10,r10,r8
1471 adde r11,r11,r9
1472 addze r12,r12
1473 $ST r10,`9*$BNSZ`(r3) #r[9]=c1;
1474 #mul_add_c(a[7],b[3],c2,c3,c1);
1475 $LD r7,`3*$BNSZ`(r5)
1476 $UMULL r8,r6,r7
1477 $UMULH r9,r6,r7
1478 addc r11,r11,r8
1479 adde r12,r12,r9
1480 addze r10,r0
1481 #mul_add_c(a[6],b[4],c2,c3,c1);
1482 $LD r6,`6*$BNSZ`(r4)
1483 $LD r7,`4*$BNSZ`(r5)
1484 $UMULL r8,r6,r7
1485 $UMULH r9,r6,r7
1486 addc r11,r11,r8
1487 adde r12,r12,r9
1488 addze r10,r10
1489 #mul_add_c(a[5],b[5],c2,c3,c1);
1490 $LD r6,`5*$BNSZ`(r4)
1491 $LD r7,`5*$BNSZ`(r5)
1492 $UMULL r8,r6,r7
1493 $UMULH r9,r6,r7
1494 addc r11,r11,r8
1495 adde r12,r12,r9
1496 addze r10,r10
1497 #mul_add_c(a[4],b[6],c2,c3,c1);
1498 $LD r6,`4*$BNSZ`(r4)
1499 $LD r7,`6*$BNSZ`(r5)
1500 $UMULL r8,r6,r7
1501 $UMULH r9,r6,r7
1502 addc r11,r11,r8
1503 adde r12,r12,r9
1504 addze r10,r10
1505 #mul_add_c(a[3],b[7],c2,c3,c1);
1506 $LD r6,`3*$BNSZ`(r4)
1507 $LD r7,`7*$BNSZ`(r5)
1508 $UMULL r8,r6,r7
1509 $UMULH r9,r6,r7
1510 addc r11,r11,r8
1511 adde r12,r12,r9
1512 addze r10,r10
1513 $ST r11,`10*$BNSZ`(r3) #r[10]=c2;
1514 #mul_add_c(a[4],b[7],c3,c1,c2);
1515 $LD r6,`4*$BNSZ`(r4)
1516 $UMULL r8,r6,r7
1517 $UMULH r9,r6,r7
1518 addc r12,r12,r8
1519 adde r10,r10,r9
1520 addze r11,r0
1521 #mul_add_c(a[5],b[6],c3,c1,c2);
1522 $LD r6,`5*$BNSZ`(r4)
1523 $LD r7,`6*$BNSZ`(r5)
1524 $UMULL r8,r6,r7
1525 $UMULH r9,r6,r7
1526 addc r12,r12,r8
1527 adde r10,r10,r9
1528 addze r11,r11
1529 #mul_add_c(a[6],b[5],c3,c1,c2);
1530 $LD r6,`6*$BNSZ`(r4)
1531 $LD r7,`5*$BNSZ`(r5)
1532 $UMULL r8,r6,r7
1533 $UMULH r9,r6,r7
1534 addc r12,r12,r8
1535 adde r10,r10,r9
1536 addze r11,r11
1537 #mul_add_c(a[7],b[4],c3,c1,c2);
1538 $LD r6,`7*$BNSZ`(r4)
1539 $LD r7,`4*$BNSZ`(r5)
1540 $UMULL r8,r6,r7
1541 $UMULH r9,r6,r7
1542 addc r12,r12,r8
1543 adde r10,r10,r9
1544 addze r11,r11
1545 $ST r12,`11*$BNSZ`(r3) #r[11]=c3;
1546 #mul_add_c(a[7],b[5],c1,c2,c3);
1547 $LD r7,`5*$BNSZ`(r5)
1548 $UMULL r8,r6,r7
1549 $UMULH r9,r6,r7
1550 addc r10,r10,r8
1551 adde r11,r11,r9
1552 addze r12,r0
1553 #mul_add_c(a[6],b[6],c1,c2,c3);
1554 $LD r6,`6*$BNSZ`(r4)
1555 $LD r7,`6*$BNSZ`(r5)
1556 $UMULL r8,r6,r7
1557 $UMULH r9,r6,r7
1558 addc r10,r10,r8
1559 adde r11,r11,r9
1560 addze r12,r12
1561 #mul_add_c(a[5],b[7],c1,c2,c3);
1562 $LD r6,`5*$BNSZ`(r4)
1563 $LD r7,`7*$BNSZ`(r5)
1564 $UMULL r8,r6,r7
1565 $UMULH r9,r6,r7
1566 addc r10,r10,r8
1567 adde r11,r11,r9
1568 addze r12,r12
1569 $ST r10,`12*$BNSZ`(r3) #r[12]=c1;
1570 #mul_add_c(a[6],b[7],c2,c3,c1);
1571 $LD r6,`6*$BNSZ`(r4)
1572 $UMULL r8,r6,r7
1573 $UMULH r9,r6,r7
1574 addc r11,r11,r8
1575 adde r12,r12,r9
1576 addze r10,r0
1577 #mul_add_c(a[7],b[6],c2,c3,c1);
1578 $LD r6,`7*$BNSZ`(r4)
1579 $LD r7,`6*$BNSZ`(r5)
1580 $UMULL r8,r6,r7
1581 $UMULH r9,r6,r7
1582 addc r11,r11,r8
1583 adde r12,r12,r9
1584 addze r10,r10
1585 $ST r11,`13*$BNSZ`(r3) #r[13]=c2;
1586 #mul_add_c(a[7],b[7],c3,c1,c2);
1587 $LD r7,`7*$BNSZ`(r5)
1588 $UMULL r8,r6,r7
1589 $UMULH r9,r6,r7
1590 addc r12,r12,r8
1591 adde r10,r10,r9
1592 $ST r12,`14*$BNSZ`(r3) #r[14]=c3;
1593 $ST r10,`15*$BNSZ`(r3) #r[15]=c1;
1594 bclr BO_ALWAYS,CR0_LT
1595 .long 0x00000000
1596
1597#
1598# NOTE: The following label name should be changed to
1599# "bn_sub_words" i.e. remove the first dot
1600# for the gcc compiler. This should be automatically
1601# done in the build
1602#
1603#
1604.align 4
1605.bn_sub_words:
1606#
1607# Handcoded version of bn_sub_words
1608#
1609#BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
1610#
1611# r3 = r
1612# r4 = a
1613# r5 = b
1614# r6 = n
1615#
1616# Note: No loop unrolling done since this is not a performance
1617# critical loop.
1618
1619 xor r0,r0,r0 #set r0 = 0
1620#
1621# check for r6 = 0 AND set carry bit.
1622#
1623 subfc. r7,r0,r6 # If r6 is 0 then result is 0.
1624 # if r6 > 0 then result !=0
1625 # In either case carry bit is set.
1626 bc BO_IF,CR0_EQ,Lppcasm_sub_adios
1627 addi r4,r4,-$BNSZ
1628 addi r3,r3,-$BNSZ
1629 addi r5,r5,-$BNSZ
1630 mtctr r6
1631Lppcasm_sub_mainloop:
1632 $LDU r7,$BNSZ(r4)
1633 $LDU r8,$BNSZ(r5)
1634 subfe r6,r8,r7 # r6 = r7+carry bit + onescomplement(r8)
1635 # if carry = 1 this is r7-r8. Else it
1636 # is r7-r8 -1 as we need.
1637 $STU r6,$BNSZ(r3)
1638 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_sub_mainloop
1639Lppcasm_sub_adios:
1640 subfze r3,r0 # if carry bit is set then r3 = 0 else -1
1641 andi. r3,r3,1 # keep only last bit.
1642 bclr BO_ALWAYS,CR0_LT
1643 .long 0x00000000
1644
1645
1646#
1647# NOTE: The following label name should be changed to
1648# "bn_add_words" i.e. remove the first dot
1649# for the gcc compiler. This should be automatically
1650# done in the build
1651#
1652
1653.align 4
1654.bn_add_words:
1655#
1656# Handcoded version of bn_add_words
1657#
1658#BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
1659#
1660# r3 = r
1661# r4 = a
1662# r5 = b
1663# r6 = n
1664#
1665# Note: No loop unrolling done since this is not a performance
1666# critical loop.
1667
1668 xor r0,r0,r0
1669#
1670# check for r6 = 0. Is this needed?
1671#
1672 addic. r6,r6,0 #test r6 and clear carry bit.
1673 bc BO_IF,CR0_EQ,Lppcasm_add_adios
1674 addi r4,r4,-$BNSZ
1675 addi r3,r3,-$BNSZ
1676 addi r5,r5,-$BNSZ
1677 mtctr r6
1678Lppcasm_add_mainloop:
1679 $LDU r7,$BNSZ(r4)
1680 $LDU r8,$BNSZ(r5)
1681 adde r8,r7,r8
1682 $STU r8,$BNSZ(r3)
1683 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_add_mainloop
1684Lppcasm_add_adios:
1685 addze r3,r0 #return carry bit.
1686 bclr BO_ALWAYS,CR0_LT
1687 .long 0x00000000
1688
1689#
1690# NOTE: The following label name should be changed to
1691# "bn_div_words" i.e. remove the first dot
1692# for the gcc compiler. This should be automatically
1693# done in the build
1694#
1695
1696.align 4
1697.bn_div_words:
1698#
1699# This is a cleaned up version of code generated by
1700# the AIX compiler. The only optimization is to use
1701# the PPC instruction to count leading zeros instead
1702# of call to num_bits_word. Since this was compiled
1703# only at level -O2 we can possibly squeeze it more?
1704#
1705# r3 = h
1706# r4 = l
1707# r5 = d
1708
1709 $UCMPI 0,r5,0 # compare r5 and 0
1710 bc BO_IF_NOT,CR0_EQ,Lppcasm_div1 # proceed if d!=0
1711 li r3,-1 # d=0 return -1
1712 bclr BO_ALWAYS,CR0_LT
1713Lppcasm_div1:
1714 xor r0,r0,r0 #r0=0
1715 li r8,$BITS
1716 $CNTLZ. r7,r5 #r7 = num leading 0s in d.
1717 bc BO_IF,CR0_EQ,Lppcasm_div2 #proceed if no leading zeros
1718 subf r8,r7,r8 #r8 = BN_num_bits_word(d)
1719 $SHR. r9,r3,r8 #are there any bits above r8'th?
1720 $TR 16,r9,r0 #if there're, signal to dump core...
1721Lppcasm_div2:
1722 $UCMP 0,r3,r5 #h>=d?
1723 bc BO_IF,CR0_LT,Lppcasm_div3 #goto Lppcasm_div3 if not
1724 subf r3,r5,r3 #h-=d ;
1725Lppcasm_div3: #r7 = BN_BITS2-i. so r7=i
1726 cmpi 0,0,r7,0 # is (i == 0)?
1727 bc BO_IF,CR0_EQ,Lppcasm_div4
1728 $SHL r3,r3,r7 # h = (h<< i)
1729 $SHR r8,r4,r8 # r8 = (l >> BN_BITS2 -i)
1730 $SHL r5,r5,r7 # d<<=i
1731 or r3,r3,r8 # h = (h<<i)|(l>>(BN_BITS2-i))
1732 $SHL r4,r4,r7 # l <<=i
1733Lppcasm_div4:
1734 $SHRI r9,r5,`$BITS/2` # r9 = dh
1735 # dl will be computed when needed
1736 # as it saves registers.
1737 li r6,2 #r6=2
1738 mtctr r6 #counter will be in count.
1739Lppcasm_divouterloop:
1740 $SHRI r8,r3,`$BITS/2` #r8 = (h>>BN_BITS4)
1741 $SHRI r11,r4,`$BITS/2` #r11= (l&BN_MASK2h)>>BN_BITS4
1742 # compute here for innerloop.
1743 $UCMP 0,r8,r9 # is (h>>BN_BITS4)==dh
1744 bc BO_IF_NOT,CR0_EQ,Lppcasm_div5 # goto Lppcasm_div5 if not
1745
1746 li r8,-1
1747 $CLRU r8,r8,`$BITS/2` #q = BN_MASK2l
1748 b Lppcasm_div6
1749Lppcasm_div5:
1750 $UDIV r8,r3,r9 #q = h/dh
1751Lppcasm_div6:
1752 $UMULL r12,r9,r8 #th = q*dh
1753 $CLRU r10,r5,`$BITS/2` #r10=dl
1754 $UMULL r6,r8,r10 #tl = q*dl
1755
1756Lppcasm_divinnerloop:
1757 subf r10,r12,r3 #t = h -th
1758 $SHRI r7,r10,`$BITS/2` #r7= (t &BN_MASK2H), sort of...
1759 addic. r7,r7,0 #test if r7 == 0. used below.
1760 # now want to compute
1761 # r7 = (t<<BN_BITS4)|((l&BN_MASK2h)>>BN_BITS4)
1762 # the following 2 instructions do that
1763 $SHLI r7,r10,`$BITS/2` # r7 = (t<<BN_BITS4)
1764 or r7,r7,r11 # r7|=((l&BN_MASK2h)>>BN_BITS4)
1765 $UCMP 1,r6,r7 # compare (tl <= r7)
1766 bc BO_IF_NOT,CR0_EQ,Lppcasm_divinnerexit
1767 bc BO_IF_NOT,CR1_FEX,Lppcasm_divinnerexit
1768 addi r8,r8,-1 #q--
1769 subf r12,r9,r12 #th -=dh
1770 $CLRU r10,r5,`$BITS/2` #r10=dl. t is no longer needed in loop.
1771 subf r6,r10,r6 #tl -=dl
1772 b Lppcasm_divinnerloop
1773Lppcasm_divinnerexit:
1774 $SHRI r10,r6,`$BITS/2` #t=(tl>>BN_BITS4)
1775 $SHLI r11,r6,`$BITS/2` #tl=(tl<<BN_BITS4)&BN_MASK2h;
1776 $UCMP 1,r4,r11 # compare l and tl
1777 add r12,r12,r10 # th+=t
1778 bc BO_IF_NOT,CR1_FX,Lppcasm_div7 # if (l>=tl) goto Lppcasm_div7
1779 addi r12,r12,1 # th++
1780Lppcasm_div7:
1781 subf r11,r11,r4 #r11=l-tl
1782 $UCMP 1,r3,r12 #compare h and th
1783 bc BO_IF_NOT,CR1_FX,Lppcasm_div8 #if (h>=th) goto Lppcasm_div8
1784 addi r8,r8,-1 # q--
1785 add r3,r5,r3 # h+=d
1786Lppcasm_div8:
1787 subf r12,r12,r3 #r12 = h-th
1788 $SHLI r4,r11,`$BITS/2` #l=(l&BN_MASK2l)<<BN_BITS4
1789 # want to compute
1790 # h = ((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2
1791 # the following 2 instructions will do this.
1792 $INSR r11,r12,`$BITS/2`,`$BITS/2` # r11 is the value we want rotated $BITS/2.
1793 $ROTL r3,r11,`$BITS/2` # rotate by $BITS/2 and store in r3
1794 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_div9#if (count==0) break ;
1795 $SHLI r0,r8,`$BITS/2` #ret =q<<BN_BITS4
1796 b Lppcasm_divouterloop
1797Lppcasm_div9:
1798 or r3,r8,r0
1799 bclr BO_ALWAYS,CR0_LT
1800 .long 0x00000000
1801
1802#
1803# NOTE: The following label name should be changed to
1804# "bn_sqr_words" i.e. remove the first dot
1805# for the gcc compiler. This should be automatically
1806# done in the build
1807#
1808.align 4
1809.bn_sqr_words:
1810#
1811# Optimized version of bn_sqr_words
1812#
1813# void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
1814#
1815# r3 = r
1816# r4 = a
1817# r5 = n
1818#
1819# r6 = a[i].
1820# r7,r8 = product.
1821#
1822# No unrolling done here. Not performance critical.
1823
1824 addic. r5,r5,0 #test r5.
1825 bc BO_IF,CR0_EQ,Lppcasm_sqr_adios
1826 addi r4,r4,-$BNSZ
1827 addi r3,r3,-$BNSZ
1828 mtctr r5
1829Lppcasm_sqr_mainloop:
1830 #sqr(r[0],r[1],a[0]);
1831 $LDU r6,$BNSZ(r4)
1832 $UMULL r7,r6,r6
1833 $UMULH r8,r6,r6
1834 $STU r7,$BNSZ(r3)
1835 $STU r8,$BNSZ(r3)
1836 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_sqr_mainloop
1837Lppcasm_sqr_adios:
1838 bclr BO_ALWAYS,CR0_LT
1839 .long 0x00000000
1840
1841
1842#
1843# NOTE: The following label name should be changed to
1844# "bn_mul_words" i.e. remove the first dot
1845# for the gcc compiler. This should be automatically
1846# done in the build
1847#
1848
1849.align 4
1850.bn_mul_words:
1851#
1852# BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
1853#
1854# r3 = rp
1855# r4 = ap
1856# r5 = num
1857# r6 = w
1858 xor r0,r0,r0
1859 xor r12,r12,r12 # used for carry
1860 rlwinm. r7,r5,30,2,31 # num >> 2
1861 bc BO_IF,CR0_EQ,Lppcasm_mw_REM
1862 mtctr r7
1863Lppcasm_mw_LOOP:
1864 #mul(rp[0],ap[0],w,c1);
1865 $LD r8,`0*$BNSZ`(r4)
1866 $UMULL r9,r6,r8
1867 $UMULH r10,r6,r8
1868 addc r9,r9,r12
1869 #addze r10,r10 #carry is NOT ignored.
1870 #will be taken care of
1871 #in second spin below
1872 #using adde.
1873 $ST r9,`0*$BNSZ`(r3)
1874 #mul(rp[1],ap[1],w,c1);
1875 $LD r8,`1*$BNSZ`(r4)
1876 $UMULL r11,r6,r8
1877 $UMULH r12,r6,r8
1878 adde r11,r11,r10
1879 #addze r12,r12
1880 $ST r11,`1*$BNSZ`(r3)
1881 #mul(rp[2],ap[2],w,c1);
1882 $LD r8,`2*$BNSZ`(r4)
1883 $UMULL r9,r6,r8
1884 $UMULH r10,r6,r8
1885 adde r9,r9,r12
1886 #addze r10,r10
1887 $ST r9,`2*$BNSZ`(r3)
1888 #mul_add(rp[3],ap[3],w,c1);
1889 $LD r8,`3*$BNSZ`(r4)
1890 $UMULL r11,r6,r8
1891 $UMULH r12,r6,r8
1892 adde r11,r11,r10
1893 addze r12,r12 #this spin we collect carry into
1894 #r12
1895 $ST r11,`3*$BNSZ`(r3)
1896
1897 addi r3,r3,`4*$BNSZ`
1898 addi r4,r4,`4*$BNSZ`
1899 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_mw_LOOP
1900
1901Lppcasm_mw_REM:
1902 andi. r5,r5,0x3
1903 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1904 #mul(rp[0],ap[0],w,c1);
1905 $LD r8,`0*$BNSZ`(r4)
1906 $UMULL r9,r6,r8
1907 $UMULH r10,r6,r8
1908 addc r9,r9,r12
1909 addze r10,r10
1910 $ST r9,`0*$BNSZ`(r3)
1911 addi r12,r10,0
1912
1913 addi r5,r5,-1
1914 cmpli 0,0,r5,0
1915 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1916
1917
1918 #mul(rp[1],ap[1],w,c1);
1919 $LD r8,`1*$BNSZ`(r4)
1920 $UMULL r9,r6,r8
1921 $UMULH r10,r6,r8
1922 addc r9,r9,r12
1923 addze r10,r10
1924 $ST r9,`1*$BNSZ`(r3)
1925 addi r12,r10,0
1926
1927 addi r5,r5,-1
1928 cmpli 0,0,r5,0
1929 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1930
1931 #mul_add(rp[2],ap[2],w,c1);
1932 $LD r8,`2*$BNSZ`(r4)
1933 $UMULL r9,r6,r8
1934 $UMULH r10,r6,r8
1935 addc r9,r9,r12
1936 addze r10,r10
1937 $ST r9,`2*$BNSZ`(r3)
1938 addi r12,r10,0
1939
1940Lppcasm_mw_OVER:
1941 addi r3,r12,0
1942 bclr BO_ALWAYS,CR0_LT
1943 .long 0x00000000
1944
1945#
1946# NOTE: The following label name should be changed to
1947# "bn_mul_add_words" i.e. remove the first dot
1948# for the gcc compiler. This should be automatically
1949# done in the build
1950#
1951
1952.align 4
1953.bn_mul_add_words:
1954#
1955# BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
1956#
1957# r3 = rp
1958# r4 = ap
1959# r5 = num
1960# r6 = w
1961#
1962# empirical evidence suggests that unrolled version performs best!!
1963#
1964 xor r0,r0,r0 #r0 = 0
1965 xor r12,r12,r12 #r12 = 0 . used for carry
1966 rlwinm. r7,r5,30,2,31 # num >> 2
1967 bc BO_IF,CR0_EQ,Lppcasm_maw_leftover # if (num < 4) go LPPCASM_maw_leftover
1968 mtctr r7
1969Lppcasm_maw_mainloop:
1970 #mul_add(rp[0],ap[0],w,c1);
1971 $LD r8,`0*$BNSZ`(r4)
1972 $LD r11,`0*$BNSZ`(r3)
1973 $UMULL r9,r6,r8
1974 $UMULH r10,r6,r8
1975 addc r9,r9,r12 #r12 is carry.
1976 addze r10,r10
1977 addc r9,r9,r11
1978 #addze r10,r10
1979 #the above instruction addze
1980 #is NOT needed. Carry will NOT
1981 #be ignored. It's not affected
1982 #by multiply and will be collected
1983 #in the next spin
1984 $ST r9,`0*$BNSZ`(r3)
1985
1986 #mul_add(rp[1],ap[1],w,c1);
1987 $LD r8,`1*$BNSZ`(r4)
1988 $LD r9,`1*$BNSZ`(r3)
1989 $UMULL r11,r6,r8
1990 $UMULH r12,r6,r8
1991 adde r11,r11,r10 #r10 is carry.
1992 addze r12,r12
1993 addc r11,r11,r9
1994 #addze r12,r12
1995 $ST r11,`1*$BNSZ`(r3)
1996
1997 #mul_add(rp[2],ap[2],w,c1);
1998 $LD r8,`2*$BNSZ`(r4)
1999 $UMULL r9,r6,r8
2000 $LD r11,`2*$BNSZ`(r3)
2001 $UMULH r10,r6,r8
2002 adde r9,r9,r12
2003 addze r10,r10
2004 addc r9,r9,r11
2005 #addze r10,r10
2006 $ST r9,`2*$BNSZ`(r3)
2007
2008 #mul_add(rp[3],ap[3],w,c1);
2009 $LD r8,`3*$BNSZ`(r4)
2010 $UMULL r11,r6,r8
2011 $LD r9,`3*$BNSZ`(r3)
2012 $UMULH r12,r6,r8
2013 adde r11,r11,r10
2014 addze r12,r12
2015 addc r11,r11,r9
2016 addze r12,r12
2017 $ST r11,`3*$BNSZ`(r3)
2018 addi r3,r3,`4*$BNSZ`
2019 addi r4,r4,`4*$BNSZ`
2020 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_maw_mainloop
2021
2022Lppcasm_maw_leftover:
2023 andi. r5,r5,0x3
2024 bc BO_IF,CR0_EQ,Lppcasm_maw_adios
2025 addi r3,r3,-$BNSZ
2026 addi r4,r4,-$BNSZ
2027 #mul_add(rp[0],ap[0],w,c1);
2028 mtctr r5
2029 $LDU r8,$BNSZ(r4)
2030 $UMULL r9,r6,r8
2031 $UMULH r10,r6,r8
2032 $LDU r11,$BNSZ(r3)
2033 addc r9,r9,r11
2034 addze r10,r10
2035 addc r9,r9,r12
2036 addze r12,r10
2037 $ST r9,0(r3)
2038
2039 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_maw_adios
2040 #mul_add(rp[1],ap[1],w,c1);
2041 $LDU r8,$BNSZ(r4)
2042 $UMULL r9,r6,r8
2043 $UMULH r10,r6,r8
2044 $LDU r11,$BNSZ(r3)
2045 addc r9,r9,r11
2046 addze r10,r10
2047 addc r9,r9,r12
2048 addze r12,r10
2049 $ST r9,0(r3)
2050
2051 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_maw_adios
2052 #mul_add(rp[2],ap[2],w,c1);
2053 $LDU r8,$BNSZ(r4)
2054 $UMULL r9,r6,r8
2055 $UMULH r10,r6,r8
2056 $LDU r11,$BNSZ(r3)
2057 addc r9,r9,r11
2058 addze r10,r10
2059 addc r9,r9,r12
2060 addze r12,r10
2061 $ST r9,0(r3)
2062
2063Lppcasm_maw_adios:
2064 addi r3,r12,0
2065 bclr BO_ALWAYS,CR0_LT
2066 .long 0x00000000
2067 .align 4
2068EOF
2069 $data =~ s/\`([^\`]*)\`/eval $1/gem;
2070
2071 # if some assembler chokes on some simplified mnemonic,
2072 # this is the spot to fix it up, e.g.:
2073 # GNU as doesn't seem to accept cmplw, 32-bit unsigned compare
2074 $data =~ s/^(\s*)cmplw(\s+)([^,]+),(.*)/$1cmpl$2$3,0,$4/gm;
2075 # assembler X doesn't accept li, load immediate value
2076 #$data =~ s/^(\s*)li(\s+)([^,]+),(.*)/$1addi$2$3,0,$4/gm;
2077 return($data);
2078}
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 8c56e2e7e7..0000000000
--- a/src/lib/libcrypto/bn/asm/sparcv8plus.S
+++ /dev/null
@@ -1,1547 +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 sra %o2,%g0,%o2 ! signx %o2
166 brgz,a %o2,.L_bn_mul_add_words_proceed
167 lduw [%o1],%g2
168 retl
169 clr %o0
170 nop
171 nop
172 nop
173
174.L_bn_mul_add_words_proceed:
175 srl %o3,%g0,%o3 ! clruw %o3
176 andcc %o2,-4,%g0
177 bz,pn %icc,.L_bn_mul_add_words_tail
178 clr %o5
179
180.L_bn_mul_add_words_loop: ! wow! 32 aligned!
181 lduw [%o0],%g1
182 lduw [%o1+4],%g3
183 mulx %o3,%g2,%g2
184 add %g1,%o5,%o4
185 nop
186 add %o4,%g2,%o4
187 stuw %o4,[%o0]
188 srlx %o4,32,%o5
189
190 lduw [%o0+4],%g1
191 lduw [%o1+8],%g2
192 mulx %o3,%g3,%g3
193 add %g1,%o5,%o4
194 dec 4,%o2
195 add %o4,%g3,%o4
196 stuw %o4,[%o0+4]
197 srlx %o4,32,%o5
198
199 lduw [%o0+8],%g1
200 lduw [%o1+12],%g3
201 mulx %o3,%g2,%g2
202 add %g1,%o5,%o4
203 inc 16,%o1
204 add %o4,%g2,%o4
205 stuw %o4,[%o0+8]
206 srlx %o4,32,%o5
207
208 lduw [%o0+12],%g1
209 mulx %o3,%g3,%g3
210 add %g1,%o5,%o4
211 inc 16,%o0
212 add %o4,%g3,%o4
213 andcc %o2,-4,%g0
214 stuw %o4,[%o0-4]
215 srlx %o4,32,%o5
216 bnz,a,pt %icc,.L_bn_mul_add_words_loop
217 lduw [%o1],%g2
218
219 brnz,a,pn %o2,.L_bn_mul_add_words_tail
220 lduw [%o1],%g2
221.L_bn_mul_add_words_return:
222 retl
223 mov %o5,%o0
224
225.L_bn_mul_add_words_tail:
226 lduw [%o0],%g1
227 mulx %o3,%g2,%g2
228 add %g1,%o5,%o4
229 dec %o2
230 add %o4,%g2,%o4
231 srlx %o4,32,%o5
232 brz,pt %o2,.L_bn_mul_add_words_return
233 stuw %o4,[%o0]
234
235 lduw [%o1+4],%g2
236 lduw [%o0+4],%g1
237 mulx %o3,%g2,%g2
238 add %g1,%o5,%o4
239 dec %o2
240 add %o4,%g2,%o4
241 srlx %o4,32,%o5
242 brz,pt %o2,.L_bn_mul_add_words_return
243 stuw %o4,[%o0+4]
244
245 lduw [%o1+8],%g2
246 lduw [%o0+8],%g1
247 mulx %o3,%g2,%g2
248 add %g1,%o5,%o4
249 add %o4,%g2,%o4
250 stuw %o4,[%o0+8]
251 retl
252 srlx %o4,32,%o0
253
254.type bn_mul_add_words,#function
255.size bn_mul_add_words,(.-bn_mul_add_words)
256
257.align 32
258
259.global bn_mul_words
260/*
261 * BN_ULONG bn_mul_words(rp,ap,num,w)
262 * BN_ULONG *rp,*ap;
263 * int num;
264 * BN_ULONG w;
265 */
266bn_mul_words:
267 sra %o2,%g0,%o2 ! signx %o2
268 brgz,a %o2,.L_bn_mul_words_proceeed
269 lduw [%o1],%g2
270 retl
271 clr %o0
272 nop
273 nop
274 nop
275
276.L_bn_mul_words_proceeed:
277 srl %o3,%g0,%o3 ! clruw %o3
278 andcc %o2,-4,%g0
279 bz,pn %icc,.L_bn_mul_words_tail
280 clr %o5
281
282.L_bn_mul_words_loop: ! wow! 32 aligned!
283 lduw [%o1+4],%g3
284 mulx %o3,%g2,%g2
285 add %g2,%o5,%o4
286 nop
287 stuw %o4,[%o0]
288 srlx %o4,32,%o5
289
290 lduw [%o1+8],%g2
291 mulx %o3,%g3,%g3
292 add %g3,%o5,%o4
293 dec 4,%o2
294 stuw %o4,[%o0+4]
295 srlx %o4,32,%o5
296
297 lduw [%o1+12],%g3
298 mulx %o3,%g2,%g2
299 add %g2,%o5,%o4
300 inc 16,%o1
301 stuw %o4,[%o0+8]
302 srlx %o4,32,%o5
303
304 mulx %o3,%g3,%g3
305 add %g3,%o5,%o4
306 inc 16,%o0
307 stuw %o4,[%o0-4]
308 srlx %o4,32,%o5
309 andcc %o2,-4,%g0
310 bnz,a,pt %icc,.L_bn_mul_words_loop
311 lduw [%o1],%g2
312 nop
313 nop
314
315 brnz,a,pn %o2,.L_bn_mul_words_tail
316 lduw [%o1],%g2
317.L_bn_mul_words_return:
318 retl
319 mov %o5,%o0
320
321.L_bn_mul_words_tail:
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]
328
329 lduw [%o1+4],%g2
330 mulx %o3,%g2,%g2
331 add %g2,%o5,%o4
332 dec %o2
333 srlx %o4,32,%o5
334 brz,pt %o2,.L_bn_mul_words_return
335 stuw %o4,[%o0+4]
336
337 lduw [%o1+8],%g2
338 mulx %o3,%g2,%g2
339 add %g2,%o5,%o4
340 stuw %o4,[%o0+8]
341 retl
342 srlx %o4,32,%o0
343
344.type bn_mul_words,#function
345.size bn_mul_words,(.-bn_mul_words)
346
347.align 32
348.global bn_sqr_words
349/*
350 * void bn_sqr_words(r,a,n)
351 * BN_ULONG *r,*a;
352 * int n;
353 */
354bn_sqr_words:
355 sra %o2,%g0,%o2 ! signx %o2
356 brgz,a %o2,.L_bn_sqr_words_proceeed
357 lduw [%o1],%g2
358 retl
359 clr %o0
360 nop
361 nop
362 nop
363
364.L_bn_sqr_words_proceeed:
365 andcc %o2,-4,%g0
366 nop
367 bz,pn %icc,.L_bn_sqr_words_tail
368 nop
369
370.L_bn_sqr_words_loop: ! wow! 32 aligned!
371 lduw [%o1+4],%g3
372 mulx %g2,%g2,%o4
373 stuw %o4,[%o0]
374 srlx %o4,32,%o5
375 stuw %o5,[%o0+4]
376 nop
377
378 lduw [%o1+8],%g2
379 mulx %g3,%g3,%o4
380 dec 4,%o2
381 stuw %o4,[%o0+8]
382 srlx %o4,32,%o5
383 stuw %o5,[%o0+12]
384
385 lduw [%o1+12],%g3
386 mulx %g2,%g2,%o4
387 srlx %o4,32,%o5
388 stuw %o4,[%o0+16]
389 inc 16,%o1
390 stuw %o5,[%o0+20]
391
392 mulx %g3,%g3,%o4
393 inc 32,%o0
394 stuw %o4,[%o0-8]
395 srlx %o4,32,%o5
396 andcc %o2,-4,%g2
397 stuw %o5,[%o0-4]
398 bnz,a,pt %icc,.L_bn_sqr_words_loop
399 lduw [%o1],%g2
400 nop
401
402 brnz,a,pn %o2,.L_bn_sqr_words_tail
403 lduw [%o1],%g2
404.L_bn_sqr_words_return:
405 retl
406 clr %o0
407
408.L_bn_sqr_words_tail:
409 mulx %g2,%g2,%o4
410 dec %o2
411 stuw %o4,[%o0]
412 srlx %o4,32,%o5
413 brz,pt %o2,.L_bn_sqr_words_return
414 stuw %o5,[%o0+4]
415
416 lduw [%o1+4],%g2
417 mulx %g2,%g2,%o4
418 dec %o2
419 stuw %o4,[%o0+8]
420 srlx %o4,32,%o5
421 brz,pt %o2,.L_bn_sqr_words_return
422 stuw %o5,[%o0+12]
423
424 lduw [%o1+8],%g2
425 mulx %g2,%g2,%o4
426 srlx %o4,32,%o5
427 stuw %o4,[%o0+16]
428 stuw %o5,[%o0+20]
429 retl
430 clr %o0
431
432.type bn_sqr_words,#function
433.size bn_sqr_words,(.-bn_sqr_words)
434
435.align 32
436.global bn_div_words
437/*
438 * BN_ULONG bn_div_words(h,l,d)
439 * BN_ULONG h,l,d;
440 */
441bn_div_words:
442 sllx %o0,32,%o0
443 or %o0,%o1,%o0
444 udivx %o0,%o2,%o0
445 retl
446 srl %o0,%g0,%o0 ! clruw %o0
447
448.type bn_div_words,#function
449.size bn_div_words,(.-bn_div_words)
450
451.align 32
452
453.global bn_add_words
454/*
455 * BN_ULONG bn_add_words(rp,ap,bp,n)
456 * BN_ULONG *rp,*ap,*bp;
457 * int n;
458 */
459bn_add_words:
460 sra %o3,%g0,%o3 ! signx %o3
461 brgz,a %o3,.L_bn_add_words_proceed
462 lduw [%o1],%o4
463 retl
464 clr %o0
465
466.L_bn_add_words_proceed:
467 andcc %o3,-4,%g0
468 bz,pn %icc,.L_bn_add_words_tail
469 addcc %g0,0,%g0 ! clear carry flag
470
471.L_bn_add_words_loop: ! wow! 32 aligned!
472 dec 4,%o3
473 lduw [%o2],%o5
474 lduw [%o1+4],%g1
475 lduw [%o2+4],%g2
476 lduw [%o1+8],%g3
477 lduw [%o2+8],%g4
478 addccc %o5,%o4,%o5
479 stuw %o5,[%o0]
480
481 lduw [%o1+12],%o4
482 lduw [%o2+12],%o5
483 inc 16,%o1
484 addccc %g1,%g2,%g1
485 stuw %g1,[%o0+4]
486
487 inc 16,%o2
488 addccc %g3,%g4,%g3
489 stuw %g3,[%o0+8]
490
491 inc 16,%o0
492 addccc %o5,%o4,%o5
493 stuw %o5,[%o0-4]
494 and %o3,-4,%g1
495 brnz,a,pt %g1,.L_bn_add_words_loop
496 lduw [%o1],%o4
497
498 brnz,a,pn %o3,.L_bn_add_words_tail
499 lduw [%o1],%o4
500.L_bn_add_words_return:
501 clr %o0
502 retl
503 movcs %icc,1,%o0
504 nop
505
506.L_bn_add_words_tail:
507 lduw [%o2],%o5
508 dec %o3
509 addccc %o5,%o4,%o5
510 brz,pt %o3,.L_bn_add_words_return
511 stuw %o5,[%o0]
512
513 lduw [%o1+4],%o4
514 lduw [%o2+4],%o5
515 dec %o3
516 addccc %o5,%o4,%o5
517 brz,pt %o3,.L_bn_add_words_return
518 stuw %o5,[%o0+4]
519
520 lduw [%o1+8],%o4
521 lduw [%o2+8],%o5
522 addccc %o5,%o4,%o5
523 stuw %o5,[%o0+8]
524 clr %o0
525 retl
526 movcs %icc,1,%o0
527
528.type bn_add_words,#function
529.size bn_add_words,(.-bn_add_words)
530
531.global bn_sub_words
532/*
533 * BN_ULONG bn_sub_words(rp,ap,bp,n)
534 * BN_ULONG *rp,*ap,*bp;
535 * int n;
536 */
537bn_sub_words:
538 sra %o3,%g0,%o3 ! signx %o3
539 brgz,a %o3,.L_bn_sub_words_proceed
540 lduw [%o1],%o4
541 retl
542 clr %o0
543
544.L_bn_sub_words_proceed:
545 andcc %o3,-4,%g0
546 bz,pn %icc,.L_bn_sub_words_tail
547 addcc %g0,0,%g0 ! clear carry flag
548
549.L_bn_sub_words_loop: ! wow! 32 aligned!
550 dec 4,%o3
551 lduw [%o2],%o5
552 lduw [%o1+4],%g1
553 lduw [%o2+4],%g2
554 lduw [%o1+8],%g3
555 lduw [%o2+8],%g4
556 subccc %o4,%o5,%o5
557 stuw %o5,[%o0]
558
559 lduw [%o1+12],%o4
560 lduw [%o2+12],%o5
561 inc 16,%o1
562 subccc %g1,%g2,%g2
563 stuw %g2,[%o0+4]
564
565 inc 16,%o2
566 subccc %g3,%g4,%g4
567 stuw %g4,[%o0+8]
568
569 inc 16,%o0
570 subccc %o4,%o5,%o5
571 stuw %o5,[%o0-4]
572 and %o3,-4,%g1
573 brnz,a,pt %g1,.L_bn_sub_words_loop
574 lduw [%o1],%o4
575
576 brnz,a,pn %o3,.L_bn_sub_words_tail
577 lduw [%o1],%o4
578.L_bn_sub_words_return:
579 clr %o0
580 retl
581 movcs %icc,1,%o0
582 nop
583
584.L_bn_sub_words_tail: ! wow! 32 aligned!
585 lduw [%o2],%o5
586 dec %o3
587 subccc %o4,%o5,%o5
588 brz,pt %o3,.L_bn_sub_words_return
589 stuw %o5,[%o0]
590
591 lduw [%o1+4],%o4
592 lduw [%o2+4],%o5
593 dec %o3
594 subccc %o4,%o5,%o5
595 brz,pt %o3,.L_bn_sub_words_return
596 stuw %o5,[%o0+4]
597
598 lduw [%o1+8],%o4
599 lduw [%o2+8],%o5
600 subccc %o4,%o5,%o5
601 stuw %o5,[%o0+8]
602 clr %o0
603 retl
604 movcs %icc,1,%o0
605
606.type bn_sub_words,#function
607.size bn_sub_words,(.-bn_sub_words)
608
609/*
610 * Code below depends on the fact that upper parts of the %l0-%l7
611 * and %i0-%i7 are zeroed by kernel after context switch. In
612 * previous versions this comment stated that "the trouble is that
613 * it's not feasible to implement the mumbo-jumbo in less V9
614 * instructions:-(" which apparently isn't true thanks to
615 * 'bcs,a %xcc,.+8; inc %rd' pair. But the performance improvement
616 * results not from the shorter code, but from elimination of
617 * multicycle none-pairable 'rd %y,%rd' instructions.
618 *
619 * Andy.
620 */
621
622#define FRAME_SIZE -96
623
624/*
625 * Here is register usage map for *all* routines below.
626 */
627#define t_1 %o0
628#define t_2 %o1
629#define c_12 %o2
630#define c_3 %o3
631
632#define ap(I) [%i1+4*I]
633#define bp(I) [%i2+4*I]
634#define rp(I) [%i0+4*I]
635
636#define a_0 %l0
637#define a_1 %l1
638#define a_2 %l2
639#define a_3 %l3
640#define a_4 %l4
641#define a_5 %l5
642#define a_6 %l6
643#define a_7 %l7
644
645#define b_0 %i3
646#define b_1 %i4
647#define b_2 %i5
648#define b_3 %o4
649#define b_4 %o5
650#define b_5 %o7
651#define b_6 %g1
652#define b_7 %g4
653
654.align 32
655.global bn_mul_comba8
656/*
657 * void bn_mul_comba8(r,a,b)
658 * BN_ULONG *r,*a,*b;
659 */
660bn_mul_comba8:
661 save %sp,FRAME_SIZE,%sp
662 mov 1,t_2
663 lduw ap(0),a_0
664 sllx t_2,32,t_2
665 lduw bp(0),b_0 !=
666 lduw bp(1),b_1
667 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
668 srlx t_1,32,c_12
669 stuw t_1,rp(0) !=!r[0]=c1;
670
671 lduw ap(1),a_1
672 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
673 addcc c_12,t_1,c_12
674 clr c_3 !=
675 bcs,a %xcc,.+8
676 add c_3,t_2,c_3
677 lduw ap(2),a_2
678 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
679 addcc c_12,t_1,t_1
680 bcs,a %xcc,.+8
681 add c_3,t_2,c_3
682 srlx t_1,32,c_12 !=
683 stuw t_1,rp(1) !r[1]=c2;
684 or c_12,c_3,c_12
685
686 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
687 addcc c_12,t_1,c_12 !=
688 clr c_3
689 bcs,a %xcc,.+8
690 add c_3,t_2,c_3
691 lduw bp(2),b_2 !=
692 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
693 addcc c_12,t_1,c_12
694 bcs,a %xcc,.+8
695 add c_3,t_2,c_3 !=
696 lduw bp(3),b_3
697 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
698 addcc c_12,t_1,t_1
699 bcs,a %xcc,.+8 !=
700 add c_3,t_2,c_3
701 srlx t_1,32,c_12
702 stuw t_1,rp(2) !r[2]=c3;
703 or c_12,c_3,c_12 !=
704
705 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
706 addcc c_12,t_1,c_12
707 clr c_3
708 bcs,a %xcc,.+8 !=
709 add c_3,t_2,c_3
710 mulx a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
711 addcc c_12,t_1,c_12
712 bcs,a %xcc,.+8 !=
713 add c_3,t_2,c_3
714 lduw ap(3),a_3
715 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
716 addcc c_12,t_1,c_12 !=
717 bcs,a %xcc,.+8
718 add c_3,t_2,c_3
719 lduw ap(4),a_4
720 mulx a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);!=
721 addcc c_12,t_1,t_1
722 bcs,a %xcc,.+8
723 add c_3,t_2,c_3
724 srlx t_1,32,c_12 !=
725 stuw t_1,rp(3) !r[3]=c1;
726 or c_12,c_3,c_12
727
728 mulx a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
729 addcc c_12,t_1,c_12 !=
730 clr c_3
731 bcs,a %xcc,.+8
732 add c_3,t_2,c_3
733 mulx a_3,b_1,t_1 !=!mul_add_c(a[3],b[1],c2,c3,c1);
734 addcc c_12,t_1,c_12
735 bcs,a %xcc,.+8
736 add c_3,t_2,c_3
737 mulx a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
738 addcc c_12,t_1,c_12
739 bcs,a %xcc,.+8
740 add c_3,t_2,c_3
741 lduw bp(4),b_4 !=
742 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
743 addcc c_12,t_1,c_12
744 bcs,a %xcc,.+8
745 add c_3,t_2,c_3 !=
746 lduw bp(5),b_5
747 mulx a_0,b_4,t_1 !mul_add_c(a[0],b[4],c2,c3,c1);
748 addcc c_12,t_1,t_1
749 bcs,a %xcc,.+8 !=
750 add c_3,t_2,c_3
751 srlx t_1,32,c_12
752 stuw t_1,rp(4) !r[4]=c2;
753 or c_12,c_3,c_12 !=
754
755 mulx a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
756 addcc c_12,t_1,c_12
757 clr c_3
758 bcs,a %xcc,.+8 !=
759 add c_3,t_2,c_3
760 mulx a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
761 addcc c_12,t_1,c_12
762 bcs,a %xcc,.+8 !=
763 add c_3,t_2,c_3
764 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
765 addcc c_12,t_1,c_12
766 bcs,a %xcc,.+8 !=
767 add c_3,t_2,c_3
768 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
769 addcc c_12,t_1,c_12
770 bcs,a %xcc,.+8 !=
771 add c_3,t_2,c_3
772 lduw ap(5),a_5
773 mulx a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
774 addcc c_12,t_1,c_12 !=
775 bcs,a %xcc,.+8
776 add c_3,t_2,c_3
777 lduw ap(6),a_6
778 mulx a_5,b_0,t_1 !=!mul_add_c(a[5],b[0],c3,c1,c2);
779 addcc c_12,t_1,t_1
780 bcs,a %xcc,.+8
781 add c_3,t_2,c_3
782 srlx t_1,32,c_12 !=
783 stuw t_1,rp(5) !r[5]=c3;
784 or c_12,c_3,c_12
785
786 mulx a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
787 addcc c_12,t_1,c_12 !=
788 clr c_3
789 bcs,a %xcc,.+8
790 add c_3,t_2,c_3
791 mulx a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],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 mulx a_4,b_2,t_1 !=!mul_add_c(a[4],b[2],c1,c2,c3);
796 addcc c_12,t_1,c_12
797 bcs,a %xcc,.+8
798 add c_3,t_2,c_3
799 mulx a_3,b_3,t_1 !=!mul_add_c(a[3],b[3],c1,c2,c3);
800 addcc c_12,t_1,c_12
801 bcs,a %xcc,.+8
802 add c_3,t_2,c_3
803 mulx a_2,b_4,t_1 !=!mul_add_c(a[2],b[4],c1,c2,c3);
804 addcc c_12,t_1,c_12
805 bcs,a %xcc,.+8
806 add c_3,t_2,c_3
807 lduw bp(6),b_6 !=
808 mulx a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
809 addcc c_12,t_1,c_12
810 bcs,a %xcc,.+8
811 add c_3,t_2,c_3 !=
812 lduw bp(7),b_7
813 mulx a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
814 addcc c_12,t_1,t_1
815 bcs,a %xcc,.+8 !=
816 add c_3,t_2,c_3
817 srlx t_1,32,c_12
818 stuw t_1,rp(6) !r[6]=c1;
819 or c_12,c_3,c_12 !=
820
821 mulx a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
822 addcc c_12,t_1,c_12
823 clr c_3
824 bcs,a %xcc,.+8 !=
825 add c_3,t_2,c_3
826 mulx a_1,b_6,t_1 !mul_add_c(a[1],b[6],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_2,b_5,t_1 !mul_add_c(a[2],b[5],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 mulx a_3,b_4,t_1 !mul_add_c(a[3],b[4],c2,c3,c1);
835 addcc c_12,t_1,c_12
836 bcs,a %xcc,.+8 !=
837 add c_3,t_2,c_3
838 mulx a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
839 addcc c_12,t_1,c_12
840 bcs,a %xcc,.+8 !=
841 add c_3,t_2,c_3
842 mulx a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
843 addcc c_12,t_1,c_12
844 bcs,a %xcc,.+8 !=
845 add c_3,t_2,c_3
846 lduw ap(7),a_7
847 mulx a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
848 addcc c_12,t_1,c_12
849 bcs,a %xcc,.+8
850 add c_3,t_2,c_3
851 mulx a_7,b_0,t_1 !=!mul_add_c(a[7],b[0],c2,c3,c1);
852 addcc c_12,t_1,t_1
853 bcs,a %xcc,.+8
854 add c_3,t_2,c_3
855 srlx t_1,32,c_12 !=
856 stuw t_1,rp(7) !r[7]=c2;
857 or c_12,c_3,c_12
858
859 mulx a_7,b_1,t_1 !=!mul_add_c(a[7],b[1],c3,c1,c2);
860 addcc c_12,t_1,c_12
861 clr c_3
862 bcs,a %xcc,.+8
863 add c_3,t_2,c_3 !=
864 mulx a_6,b_2,t_1 !mul_add_c(a[6],b[2],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_5,b_3,t_1 !mul_add_c(a[5],b[3],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_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
873 addcc c_12,t_1,c_12
874 bcs,a %xcc,.+8
875 add c_3,t_2,c_3 !=
876 mulx a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
877 addcc c_12,t_1,c_12
878 bcs,a %xcc,.+8
879 add c_3,t_2,c_3 !=
880 mulx a_2,b_6,t_1 !mul_add_c(a[2],b[6],c3,c1,c2);
881 addcc c_12,t_1,c_12
882 bcs,a %xcc,.+8
883 add c_3,t_2,c_3 !=
884 mulx a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
885 addcc c_12,t_1,t_1
886 bcs,a %xcc,.+8
887 add c_3,t_2,c_3 !=
888 srlx t_1,32,c_12
889 stuw t_1,rp(8) !r[8]=c3;
890 or c_12,c_3,c_12
891
892 mulx a_2,b_7,t_1 !=!mul_add_c(a[2],b[7],c1,c2,c3);
893 addcc c_12,t_1,c_12
894 clr c_3
895 bcs,a %xcc,.+8
896 add c_3,t_2,c_3 !=
897 mulx a_3,b_6,t_1 !mul_add_c(a[3],b[6],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_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
902 addcc c_12,t_1,c_12
903 bcs,a %xcc,.+8 !=
904 add c_3,t_2,c_3
905 mulx a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
906 addcc c_12,t_1,c_12
907 bcs,a %xcc,.+8 !=
908 add c_3,t_2,c_3
909 mulx a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
910 addcc c_12,t_1,c_12
911 bcs,a %xcc,.+8 !=
912 add c_3,t_2,c_3
913 mulx a_7,b_2,t_1 !mul_add_c(a[7],b[2],c1,c2,c3);
914 addcc c_12,t_1,t_1
915 bcs,a %xcc,.+8 !=
916 add c_3,t_2,c_3
917 srlx t_1,32,c_12
918 stuw t_1,rp(9) !r[9]=c1;
919 or c_12,c_3,c_12 !=
920
921 mulx a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
922 addcc c_12,t_1,c_12
923 clr c_3
924 bcs,a %xcc,.+8 !=
925 add c_3,t_2,c_3
926 mulx a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
927 addcc c_12,t_1,c_12
928 bcs,a %xcc,.+8 !=
929 add c_3,t_2,c_3
930 mulx a_5,b_5,t_1 !mul_add_c(a[5],b[5],c2,c3,c1);
931 addcc c_12,t_1,c_12
932 bcs,a %xcc,.+8 !=
933 add c_3,t_2,c_3
934 mulx a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
935 addcc c_12,t_1,c_12
936 bcs,a %xcc,.+8 !=
937 add c_3,t_2,c_3
938 mulx a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
939 addcc c_12,t_1,t_1
940 bcs,a %xcc,.+8 !=
941 add c_3,t_2,c_3
942 srlx t_1,32,c_12
943 stuw t_1,rp(10) !r[10]=c2;
944 or c_12,c_3,c_12 !=
945
946 mulx a_4,b_7,t_1 !mul_add_c(a[4],b[7],c3,c1,c2);
947 addcc c_12,t_1,c_12
948 clr c_3
949 bcs,a %xcc,.+8 !=
950 add c_3,t_2,c_3
951 mulx a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
952 addcc c_12,t_1,c_12
953 bcs,a %xcc,.+8 !=
954 add c_3,t_2,c_3
955 mulx a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
956 addcc c_12,t_1,c_12
957 bcs,a %xcc,.+8 !=
958 add c_3,t_2,c_3
959 mulx a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
960 addcc c_12,t_1,t_1
961 bcs,a %xcc,.+8 !=
962 add c_3,t_2,c_3
963 srlx t_1,32,c_12
964 stuw t_1,rp(11) !r[11]=c3;
965 or c_12,c_3,c_12 !=
966
967 mulx a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
968 addcc c_12,t_1,c_12
969 clr c_3
970 bcs,a %xcc,.+8 !=
971 add c_3,t_2,c_3
972 mulx a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
973 addcc c_12,t_1,c_12
974 bcs,a %xcc,.+8 !=
975 add c_3,t_2,c_3
976 mulx a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
977 addcc c_12,t_1,t_1
978 bcs,a %xcc,.+8 !=
979 add c_3,t_2,c_3
980 srlx t_1,32,c_12
981 stuw t_1,rp(12) !r[12]=c1;
982 or c_12,c_3,c_12 !=
983
984 mulx a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
985 addcc c_12,t_1,c_12
986 clr c_3
987 bcs,a %xcc,.+8 !=
988 add c_3,t_2,c_3
989 mulx a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
990 addcc c_12,t_1,t_1
991 bcs,a %xcc,.+8 !=
992 add c_3,t_2,c_3
993 srlx t_1,32,c_12
994 st t_1,rp(13) !r[13]=c2;
995 or c_12,c_3,c_12 !=
996
997 mulx a_7,b_7,t_1 !mul_add_c(a[7],b[7],c3,c1,c2);
998 addcc c_12,t_1,t_1
999 srlx t_1,32,c_12 !=
1000 stuw t_1,rp(14) !r[14]=c3;
1001 stuw c_12,rp(15) !r[15]=c1;
1002
1003 ret
1004 restore %g0,%g0,%o0 !=
1005
1006.type bn_mul_comba8,#function
1007.size bn_mul_comba8,(.-bn_mul_comba8)
1008
1009.align 32
1010
1011.global bn_mul_comba4
1012/*
1013 * void bn_mul_comba4(r,a,b)
1014 * BN_ULONG *r,*a,*b;
1015 */
1016bn_mul_comba4:
1017 save %sp,FRAME_SIZE,%sp
1018 lduw ap(0),a_0
1019 mov 1,t_2
1020 lduw bp(0),b_0
1021 sllx t_2,32,t_2 !=
1022 lduw bp(1),b_1
1023 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
1024 srlx t_1,32,c_12
1025 stuw t_1,rp(0) !=!r[0]=c1;
1026
1027 lduw ap(1),a_1
1028 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
1029 addcc c_12,t_1,c_12
1030 clr c_3 !=
1031 bcs,a %xcc,.+8
1032 add c_3,t_2,c_3
1033 lduw ap(2),a_2
1034 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
1035 addcc c_12,t_1,t_1
1036 bcs,a %xcc,.+8
1037 add c_3,t_2,c_3
1038 srlx t_1,32,c_12 !=
1039 stuw t_1,rp(1) !r[1]=c2;
1040 or c_12,c_3,c_12
1041
1042 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
1043 addcc c_12,t_1,c_12 !=
1044 clr c_3
1045 bcs,a %xcc,.+8
1046 add c_3,t_2,c_3
1047 lduw bp(2),b_2 !=
1048 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
1049 addcc c_12,t_1,c_12
1050 bcs,a %xcc,.+8
1051 add c_3,t_2,c_3 !=
1052 lduw bp(3),b_3
1053 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
1054 addcc c_12,t_1,t_1
1055 bcs,a %xcc,.+8 !=
1056 add c_3,t_2,c_3
1057 srlx t_1,32,c_12
1058 stuw t_1,rp(2) !r[2]=c3;
1059 or c_12,c_3,c_12 !=
1060
1061 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
1062 addcc c_12,t_1,c_12
1063 clr c_3
1064 bcs,a %xcc,.+8 !=
1065 add c_3,t_2,c_3
1066 mulx a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
1067 addcc c_12,t_1,c_12
1068 bcs,a %xcc,.+8 !=
1069 add c_3,t_2,c_3
1070 lduw ap(3),a_3
1071 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
1072 addcc c_12,t_1,c_12 !=
1073 bcs,a %xcc,.+8
1074 add c_3,t_2,c_3
1075 mulx a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
1076 addcc c_12,t_1,t_1 !=
1077 bcs,a %xcc,.+8
1078 add c_3,t_2,c_3
1079 srlx t_1,32,c_12
1080 stuw t_1,rp(3) !=!r[3]=c1;
1081 or c_12,c_3,c_12
1082
1083 mulx a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1084 addcc c_12,t_1,c_12
1085 clr c_3 !=
1086 bcs,a %xcc,.+8
1087 add c_3,t_2,c_3
1088 mulx a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1089 addcc c_12,t_1,c_12 !=
1090 bcs,a %xcc,.+8
1091 add c_3,t_2,c_3
1092 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
1093 addcc c_12,t_1,t_1 !=
1094 bcs,a %xcc,.+8
1095 add c_3,t_2,c_3
1096 srlx t_1,32,c_12
1097 stuw t_1,rp(4) !=!r[4]=c2;
1098 or c_12,c_3,c_12
1099
1100 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1101 addcc c_12,t_1,c_12
1102 clr c_3 !=
1103 bcs,a %xcc,.+8
1104 add c_3,t_2,c_3
1105 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1106 addcc c_12,t_1,t_1 !=
1107 bcs,a %xcc,.+8
1108 add c_3,t_2,c_3
1109 srlx t_1,32,c_12
1110 stuw t_1,rp(5) !=!r[5]=c3;
1111 or c_12,c_3,c_12
1112
1113 mulx a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1114 addcc c_12,t_1,t_1
1115 srlx t_1,32,c_12 !=
1116 stuw t_1,rp(6) !r[6]=c1;
1117 stuw c_12,rp(7) !r[7]=c2;
1118
1119 ret
1120 restore %g0,%g0,%o0
1121
1122.type bn_mul_comba4,#function
1123.size bn_mul_comba4,(.-bn_mul_comba4)
1124
1125.align 32
1126
1127.global bn_sqr_comba8
1128bn_sqr_comba8:
1129 save %sp,FRAME_SIZE,%sp
1130 mov 1,t_2
1131 lduw ap(0),a_0
1132 sllx t_2,32,t_2
1133 lduw ap(1),a_1
1134 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1135 srlx t_1,32,c_12
1136 stuw t_1,rp(0) !r[0]=c1;
1137
1138 lduw ap(2),a_2
1139 mulx a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
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,t_1
1145 bcs,a %xcc,.+8
1146 add c_3,t_2,c_3
1147 srlx t_1,32,c_12
1148 stuw t_1,rp(1) !r[1]=c2;
1149 or c_12,c_3,c_12
1150
1151 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1152 addcc c_12,t_1,c_12
1153 clr c_3
1154 bcs,a %xcc,.+8
1155 add c_3,t_2,c_3
1156 addcc c_12,t_1,c_12
1157 bcs,a %xcc,.+8
1158 add c_3,t_2,c_3
1159 lduw ap(3),a_3
1160 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1161 addcc c_12,t_1,t_1
1162 bcs,a %xcc,.+8
1163 add c_3,t_2,c_3
1164 srlx t_1,32,c_12
1165 stuw t_1,rp(2) !r[2]=c3;
1166 or c_12,c_3,c_12
1167
1168 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1169 addcc c_12,t_1,c_12
1170 clr c_3
1171 bcs,a %xcc,.+8
1172 add c_3,t_2,c_3
1173 addcc c_12,t_1,c_12
1174 bcs,a %xcc,.+8
1175 add c_3,t_2,c_3
1176 lduw ap(4),a_4
1177 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1178 addcc c_12,t_1,c_12
1179 bcs,a %xcc,.+8
1180 add c_3,t_2,c_3
1181 addcc c_12,t_1,t_1
1182 bcs,a %xcc,.+8
1183 add c_3,t_2,c_3
1184 srlx t_1,32,c_12
1185 st t_1,rp(3) !r[3]=c1;
1186 or c_12,c_3,c_12
1187
1188 mulx a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1189 addcc c_12,t_1,c_12
1190 clr c_3
1191 bcs,a %xcc,.+8
1192 add c_3,t_2,c_3
1193 addcc c_12,t_1,c_12
1194 bcs,a %xcc,.+8
1195 add c_3,t_2,c_3
1196 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1197 addcc c_12,t_1,c_12
1198 bcs,a %xcc,.+8
1199 add c_3,t_2,c_3
1200 addcc c_12,t_1,c_12
1201 bcs,a %xcc,.+8
1202 add c_3,t_2,c_3
1203 lduw ap(5),a_5
1204 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1205 addcc c_12,t_1,t_1
1206 bcs,a %xcc,.+8
1207 add c_3,t_2,c_3
1208 srlx t_1,32,c_12
1209 stuw t_1,rp(4) !r[4]=c2;
1210 or c_12,c_3,c_12
1211
1212 mulx a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1213 addcc c_12,t_1,c_12
1214 clr c_3
1215 bcs,a %xcc,.+8
1216 add c_3,t_2,c_3
1217 addcc c_12,t_1,c_12
1218 bcs,a %xcc,.+8
1219 add c_3,t_2,c_3
1220 mulx a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1221 addcc c_12,t_1,c_12
1222 bcs,a %xcc,.+8
1223 add c_3,t_2,c_3
1224 addcc c_12,t_1,c_12
1225 bcs,a %xcc,.+8
1226 add c_3,t_2,c_3
1227 lduw ap(6),a_6
1228 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1229 addcc c_12,t_1,c_12
1230 bcs,a %xcc,.+8
1231 add c_3,t_2,c_3
1232 addcc c_12,t_1,t_1
1233 bcs,a %xcc,.+8
1234 add c_3,t_2,c_3
1235 srlx t_1,32,c_12
1236 stuw t_1,rp(5) !r[5]=c3;
1237 or c_12,c_3,c_12
1238
1239 mulx a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1240 addcc c_12,t_1,c_12
1241 clr c_3
1242 bcs,a %xcc,.+8
1243 add c_3,t_2,c_3
1244 addcc c_12,t_1,c_12
1245 bcs,a %xcc,.+8
1246 add c_3,t_2,c_3
1247 mulx a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1248 addcc c_12,t_1,c_12
1249 bcs,a %xcc,.+8
1250 add c_3,t_2,c_3
1251 addcc c_12,t_1,c_12
1252 bcs,a %xcc,.+8
1253 add c_3,t_2,c_3
1254 mulx a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1255 addcc c_12,t_1,c_12
1256 bcs,a %xcc,.+8
1257 add c_3,t_2,c_3
1258 addcc c_12,t_1,c_12
1259 bcs,a %xcc,.+8
1260 add c_3,t_2,c_3
1261 lduw ap(7),a_7
1262 mulx a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1263 addcc c_12,t_1,t_1
1264 bcs,a %xcc,.+8
1265 add c_3,t_2,c_3
1266 srlx t_1,32,c_12
1267 stuw t_1,rp(6) !r[6]=c1;
1268 or c_12,c_3,c_12
1269
1270 mulx a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1271 addcc c_12,t_1,c_12
1272 clr c_3
1273 bcs,a %xcc,.+8
1274 add c_3,t_2,c_3
1275 addcc c_12,t_1,c_12
1276 bcs,a %xcc,.+8
1277 add c_3,t_2,c_3
1278 mulx a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1279 addcc c_12,t_1,c_12
1280 bcs,a %xcc,.+8
1281 add c_3,t_2,c_3
1282 addcc c_12,t_1,c_12
1283 bcs,a %xcc,.+8
1284 add c_3,t_2,c_3
1285 mulx a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1286 addcc c_12,t_1,c_12
1287 bcs,a %xcc,.+8
1288 add c_3,t_2,c_3
1289 addcc c_12,t_1,c_12
1290 bcs,a %xcc,.+8
1291 add c_3,t_2,c_3
1292 mulx a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1293 addcc c_12,t_1,c_12
1294 bcs,a %xcc,.+8
1295 add c_3,t_2,c_3
1296 addcc c_12,t_1,t_1
1297 bcs,a %xcc,.+8
1298 add c_3,t_2,c_3
1299 srlx t_1,32,c_12
1300 stuw t_1,rp(7) !r[7]=c2;
1301 or c_12,c_3,c_12
1302
1303 mulx a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1304 addcc c_12,t_1,c_12
1305 clr c_3
1306 bcs,a %xcc,.+8
1307 add c_3,t_2,c_3
1308 addcc c_12,t_1,c_12
1309 bcs,a %xcc,.+8
1310 add c_3,t_2,c_3
1311 mulx a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1312 addcc c_12,t_1,c_12
1313 bcs,a %xcc,.+8
1314 add c_3,t_2,c_3
1315 addcc c_12,t_1,c_12
1316 bcs,a %xcc,.+8
1317 add c_3,t_2,c_3
1318 mulx a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1319 addcc c_12,t_1,c_12
1320 bcs,a %xcc,.+8
1321 add c_3,t_2,c_3
1322 addcc c_12,t_1,c_12
1323 bcs,a %xcc,.+8
1324 add c_3,t_2,c_3
1325 mulx a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1326 addcc c_12,t_1,t_1
1327 bcs,a %xcc,.+8
1328 add c_3,t_2,c_3
1329 srlx t_1,32,c_12
1330 stuw t_1,rp(8) !r[8]=c3;
1331 or c_12,c_3,c_12
1332
1333 mulx a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1334 addcc c_12,t_1,c_12
1335 clr c_3
1336 bcs,a %xcc,.+8
1337 add c_3,t_2,c_3
1338 addcc c_12,t_1,c_12
1339 bcs,a %xcc,.+8
1340 add c_3,t_2,c_3
1341 mulx a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1342 addcc c_12,t_1,c_12
1343 bcs,a %xcc,.+8
1344 add c_3,t_2,c_3
1345 addcc c_12,t_1,c_12
1346 bcs,a %xcc,.+8
1347 add c_3,t_2,c_3
1348 mulx a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1349 addcc c_12,t_1,c_12
1350 bcs,a %xcc,.+8
1351 add c_3,t_2,c_3
1352 addcc c_12,t_1,t_1
1353 bcs,a %xcc,.+8
1354 add c_3,t_2,c_3
1355 srlx t_1,32,c_12
1356 stuw t_1,rp(9) !r[9]=c1;
1357 or c_12,c_3,c_12
1358
1359 mulx a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1360 addcc c_12,t_1,c_12
1361 clr c_3
1362 bcs,a %xcc,.+8
1363 add c_3,t_2,c_3
1364 addcc c_12,t_1,c_12
1365 bcs,a %xcc,.+8
1366 add c_3,t_2,c_3
1367 mulx a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1368 addcc c_12,t_1,c_12
1369 bcs,a %xcc,.+8
1370 add c_3,t_2,c_3
1371 addcc c_12,t_1,c_12
1372 bcs,a %xcc,.+8
1373 add c_3,t_2,c_3
1374 mulx a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1375 addcc c_12,t_1,t_1
1376 bcs,a %xcc,.+8
1377 add c_3,t_2,c_3
1378 srlx t_1,32,c_12
1379 stuw t_1,rp(10) !r[10]=c2;
1380 or c_12,c_3,c_12
1381
1382 mulx a_4,a_7,t_1 !sqr_add_c2(a,7,4,c3,c1,c2);
1383 addcc c_12,t_1,c_12
1384 clr c_3
1385 bcs,a %xcc,.+8
1386 add c_3,t_2,c_3
1387 addcc c_12,t_1,c_12
1388 bcs,a %xcc,.+8
1389 add c_3,t_2,c_3
1390 mulx a_5,a_6,t_1 !sqr_add_c2(a,6,5,c3,c1,c2);
1391 addcc c_12,t_1,c_12
1392 bcs,a %xcc,.+8
1393 add c_3,t_2,c_3
1394 addcc c_12,t_1,t_1
1395 bcs,a %xcc,.+8
1396 add c_3,t_2,c_3
1397 srlx t_1,32,c_12
1398 stuw t_1,rp(11) !r[11]=c3;
1399 or c_12,c_3,c_12
1400
1401 mulx a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1402 addcc c_12,t_1,c_12
1403 clr c_3
1404 bcs,a %xcc,.+8
1405 add c_3,t_2,c_3
1406 addcc c_12,t_1,c_12
1407 bcs,a %xcc,.+8
1408 add c_3,t_2,c_3
1409 mulx a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
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(12) !r[12]=c1;
1415 or c_12,c_3,c_12
1416
1417 mulx a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1418 addcc c_12,t_1,c_12
1419 clr c_3
1420 bcs,a %xcc,.+8
1421 add c_3,t_2,c_3
1422 addcc c_12,t_1,t_1
1423 bcs,a %xcc,.+8
1424 add c_3,t_2,c_3
1425 srlx t_1,32,c_12
1426 stuw t_1,rp(13) !r[13]=c2;
1427 or c_12,c_3,c_12
1428
1429 mulx a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1430 addcc c_12,t_1,t_1
1431 srlx t_1,32,c_12
1432 stuw t_1,rp(14) !r[14]=c3;
1433 stuw c_12,rp(15) !r[15]=c1;
1434
1435 ret
1436 restore %g0,%g0,%o0
1437
1438.type bn_sqr_comba8,#function
1439.size bn_sqr_comba8,(.-bn_sqr_comba8)
1440
1441.align 32
1442
1443.global bn_sqr_comba4
1444/*
1445 * void bn_sqr_comba4(r,a)
1446 * BN_ULONG *r,*a;
1447 */
1448bn_sqr_comba4:
1449 save %sp,FRAME_SIZE,%sp
1450 mov 1,t_2
1451 lduw ap(0),a_0
1452 sllx t_2,32,t_2
1453 lduw ap(1),a_1
1454 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1455 srlx t_1,32,c_12
1456 stuw t_1,rp(0) !r[0]=c1;
1457
1458 lduw ap(2),a_2
1459 mulx a_0,a_1,t_1 !sqr_add_c2(a,1,0,c2,c3,c1);
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,t_1
1465 bcs,a %xcc,.+8
1466 add c_3,t_2,c_3
1467 srlx t_1,32,c_12
1468 stuw t_1,rp(1) !r[1]=c2;
1469 or c_12,c_3,c_12
1470
1471 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1472 addcc c_12,t_1,c_12
1473 clr c_3
1474 bcs,a %xcc,.+8
1475 add c_3,t_2,c_3
1476 addcc c_12,t_1,c_12
1477 bcs,a %xcc,.+8
1478 add c_3,t_2,c_3
1479 lduw ap(3),a_3
1480 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1481 addcc c_12,t_1,t_1
1482 bcs,a %xcc,.+8
1483 add c_3,t_2,c_3
1484 srlx t_1,32,c_12
1485 stuw t_1,rp(2) !r[2]=c3;
1486 or c_12,c_3,c_12
1487
1488 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1489 addcc c_12,t_1,c_12
1490 clr c_3
1491 bcs,a %xcc,.+8
1492 add c_3,t_2,c_3
1493 addcc c_12,t_1,c_12
1494 bcs,a %xcc,.+8
1495 add c_3,t_2,c_3
1496 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1497 addcc c_12,t_1,c_12
1498 bcs,a %xcc,.+8
1499 add c_3,t_2,c_3
1500 addcc c_12,t_1,t_1
1501 bcs,a %xcc,.+8
1502 add c_3,t_2,c_3
1503 srlx t_1,32,c_12
1504 stuw t_1,rp(3) !r[3]=c1;
1505 or c_12,c_3,c_12
1506
1507 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1508 addcc c_12,t_1,c_12
1509 clr c_3
1510 bcs,a %xcc,.+8
1511 add c_3,t_2,c_3
1512 addcc c_12,t_1,c_12
1513 bcs,a %xcc,.+8
1514 add c_3,t_2,c_3
1515 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
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(4) !r[4]=c2;
1521 or c_12,c_3,c_12
1522
1523 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1524 addcc c_12,t_1,c_12
1525 clr c_3
1526 bcs,a %xcc,.+8
1527 add c_3,t_2,c_3
1528 addcc c_12,t_1,t_1
1529 bcs,a %xcc,.+8
1530 add c_3,t_2,c_3
1531 srlx t_1,32,c_12
1532 stuw t_1,rp(5) !r[5]=c3;
1533 or c_12,c_3,c_12
1534
1535 mulx a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1536 addcc c_12,t_1,t_1
1537 srlx t_1,32,c_12
1538 stuw t_1,rp(6) !r[6]=c1;
1539 stuw c_12,rp(7) !r[7]=c2;
1540
1541 ret
1542 restore %g0,%g0,%o0
1543
1544.type bn_sqr_comba4,#function
1545.size bn_sqr_comba4,(.-bn_sqr_comba4)
1546
1547.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/asm/x86_64-gcc.c b/src/lib/libcrypto/bn/asm/x86_64-gcc.c
deleted file mode 100644
index 7378344251..0000000000
--- a/src/lib/libcrypto/bn/asm/x86_64-gcc.c
+++ /dev/null
@@ -1,593 +0,0 @@
1/*
2 * x86_64 BIGNUM accelerator version 0.1, December 2002.
3 *
4 * Implemented by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5 * project.
6 *
7 * Rights for redistribution and usage in source and binary forms are
8 * granted according to the OpenSSL license. Warranty of any kind is
9 * disclaimed.
10 *
11 * Q. Version 0.1? It doesn't sound like Andy, he used to assign real
12 * versions, like 1.0...
13 * A. Well, that's because this code is basically a quick-n-dirty
14 * proof-of-concept hack. As you can see it's implemented with
15 * inline assembler, which means that you're bound to GCC and that
16 * there might be enough room for further improvement.
17 *
18 * Q. Why inline assembler?
19 * A. x86_64 features own ABI which I'm not familiar with. This is
20 * why I decided to let the compiler take care of subroutine
21 * prologue/epilogue as well as register allocation. For reference.
22 * Win64 implements different ABI for AMD64, different from Linux.
23 *
24 * Q. How much faster does it get?
25 * A. 'apps/openssl speed rsa dsa' output with no-asm:
26 *
27 * sign verify sign/s verify/s
28 * rsa 512 bits 0.0006s 0.0001s 1683.8 18456.2
29 * rsa 1024 bits 0.0028s 0.0002s 356.0 6407.0
30 * rsa 2048 bits 0.0172s 0.0005s 58.0 1957.8
31 * rsa 4096 bits 0.1155s 0.0018s 8.7 555.6
32 * sign verify sign/s verify/s
33 * dsa 512 bits 0.0005s 0.0006s 2100.8 1768.3
34 * dsa 1024 bits 0.0014s 0.0018s 692.3 559.2
35 * dsa 2048 bits 0.0049s 0.0061s 204.7 165.0
36 *
37 * 'apps/openssl speed rsa dsa' output with this module:
38 *
39 * sign verify sign/s verify/s
40 * rsa 512 bits 0.0004s 0.0000s 2767.1 33297.9
41 * rsa 1024 bits 0.0012s 0.0001s 867.4 14674.7
42 * rsa 2048 bits 0.0061s 0.0002s 164.0 5270.0
43 * rsa 4096 bits 0.0384s 0.0006s 26.1 1650.8
44 * sign verify sign/s verify/s
45 * dsa 512 bits 0.0002s 0.0003s 4442.2 3786.3
46 * dsa 1024 bits 0.0005s 0.0007s 1835.1 1497.4
47 * dsa 2048 bits 0.0016s 0.0020s 620.4 504.6
48 *
49 * For the reference. IA-32 assembler implementation performs
50 * very much like 64-bit code compiled with no-asm on the same
51 * machine.
52 */
53
54#define BN_ULONG unsigned long
55
56/*
57 * "m"(a), "+m"(r) is the way to favor DirectPath µ-code;
58 * "g"(0) let the compiler to decide where does it
59 * want to keep the value of zero;
60 */
61#define mul_add(r,a,word,carry) do { \
62 register BN_ULONG high,low; \
63 asm ("mulq %3" \
64 : "=a"(low),"=d"(high) \
65 : "a"(word),"m"(a) \
66 : "cc"); \
67 asm ("addq %2,%0; adcq %3,%1" \
68 : "+r"(carry),"+d"(high)\
69 : "a"(low),"g"(0) \
70 : "cc"); \
71 asm ("addq %2,%0; adcq %3,%1" \
72 : "+m"(r),"+d"(high) \
73 : "r"(carry),"g"(0) \
74 : "cc"); \
75 carry=high; \
76 } while (0)
77
78#define mul(r,a,word,carry) do { \
79 register BN_ULONG high,low; \
80 asm ("mulq %3" \
81 : "=a"(low),"=d"(high) \
82 : "a"(word),"g"(a) \
83 : "cc"); \
84 asm ("addq %2,%0; adcq %3,%1" \
85 : "+r"(carry),"+d"(high)\
86 : "a"(low),"g"(0) \
87 : "cc"); \
88 (r)=carry, carry=high; \
89 } while (0)
90
91#define sqr(r0,r1,a) \
92 asm ("mulq %2" \
93 : "=a"(r0),"=d"(r1) \
94 : "a"(a) \
95 : "cc");
96
97BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
98 {
99 BN_ULONG c1=0;
100
101 if (num <= 0) return(c1);
102
103 while (num&~3)
104 {
105 mul_add(rp[0],ap[0],w,c1);
106 mul_add(rp[1],ap[1],w,c1);
107 mul_add(rp[2],ap[2],w,c1);
108 mul_add(rp[3],ap[3],w,c1);
109 ap+=4; rp+=4; num-=4;
110 }
111 if (num)
112 {
113 mul_add(rp[0],ap[0],w,c1); if (--num==0) return c1;
114 mul_add(rp[1],ap[1],w,c1); if (--num==0) return c1;
115 mul_add(rp[2],ap[2],w,c1); return c1;
116 }
117
118 return(c1);
119 }
120
121BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
122 {
123 BN_ULONG c1=0;
124
125 if (num <= 0) return(c1);
126
127 while (num&~3)
128 {
129 mul(rp[0],ap[0],w,c1);
130 mul(rp[1],ap[1],w,c1);
131 mul(rp[2],ap[2],w,c1);
132 mul(rp[3],ap[3],w,c1);
133 ap+=4; rp+=4; num-=4;
134 }
135 if (num)
136 {
137 mul(rp[0],ap[0],w,c1); if (--num == 0) return c1;
138 mul(rp[1],ap[1],w,c1); if (--num == 0) return c1;
139 mul(rp[2],ap[2],w,c1);
140 }
141 return(c1);
142 }
143
144void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
145 {
146 if (n <= 0) return;
147
148 while (n&~3)
149 {
150 sqr(r[0],r[1],a[0]);
151 sqr(r[2],r[3],a[1]);
152 sqr(r[4],r[5],a[2]);
153 sqr(r[6],r[7],a[3]);
154 a+=4; r+=8; n-=4;
155 }
156 if (n)
157 {
158 sqr(r[0],r[1],a[0]); if (--n == 0) return;
159 sqr(r[2],r[3],a[1]); if (--n == 0) return;
160 sqr(r[4],r[5],a[2]);
161 }
162 }
163
164BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
165{ BN_ULONG ret,waste;
166
167 asm ("divq %4"
168 : "=a"(ret),"=d"(waste)
169 : "a"(l),"d"(h),"g"(d)
170 : "cc");
171
172 return ret;
173}
174
175BN_ULONG bn_add_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
176{ BN_ULONG ret=0,i=0;
177
178 if (n <= 0) return 0;
179
180 asm (
181 " subq %2,%2 \n"
182 ".align 16 \n"
183 "1: movq (%4,%2,8),%0 \n"
184 " adcq (%5,%2,8),%0 \n"
185 " movq %0,(%3,%2,8) \n"
186 " leaq 1(%2),%2 \n"
187 " loop 1b \n"
188 " sbbq %0,%0 \n"
189 : "=&a"(ret),"+c"(n),"=&r"(i)
190 : "r"(rp),"r"(ap),"r"(bp)
191 : "cc"
192 );
193
194 return ret&1;
195}
196
197#ifndef SIMICS
198BN_ULONG bn_sub_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
199{ BN_ULONG ret=0,i=0;
200
201 if (n <= 0) return 0;
202
203 asm (
204 " subq %2,%2 \n"
205 ".align 16 \n"
206 "1: movq (%4,%2,8),%0 \n"
207 " sbbq (%5,%2,8),%0 \n"
208 " movq %0,(%3,%2,8) \n"
209 " leaq 1(%2),%2 \n"
210 " loop 1b \n"
211 " sbbq %0,%0 \n"
212 : "=&a"(ret),"+c"(n),"=&r"(i)
213 : "r"(rp),"r"(ap),"r"(bp)
214 : "cc"
215 );
216
217 return ret&1;
218}
219#else
220/* Simics 1.4<7 has buggy sbbq:-( */
221#define BN_MASK2 0xffffffffffffffffL
222BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
223 {
224 BN_ULONG t1,t2;
225 int c=0;
226
227 if (n <= 0) return((BN_ULONG)0);
228
229 for (;;)
230 {
231 t1=a[0]; t2=b[0];
232 r[0]=(t1-t2-c)&BN_MASK2;
233 if (t1 != t2) c=(t1 < t2);
234 if (--n <= 0) break;
235
236 t1=a[1]; t2=b[1];
237 r[1]=(t1-t2-c)&BN_MASK2;
238 if (t1 != t2) c=(t1 < t2);
239 if (--n <= 0) break;
240
241 t1=a[2]; t2=b[2];
242 r[2]=(t1-t2-c)&BN_MASK2;
243 if (t1 != t2) c=(t1 < t2);
244 if (--n <= 0) break;
245
246 t1=a[3]; t2=b[3];
247 r[3]=(t1-t2-c)&BN_MASK2;
248 if (t1 != t2) c=(t1 < t2);
249 if (--n <= 0) break;
250
251 a+=4;
252 b+=4;
253 r+=4;
254 }
255 return(c);
256 }
257#endif
258
259/* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */
260/* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */
261/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
262/* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
263
264#if 0
265/* original macros are kept for reference purposes */
266#define mul_add_c(a,b,c0,c1,c2) { \
267 BN_ULONG ta=(a),tb=(b); \
268 t1 = ta * tb; \
269 t2 = BN_UMULT_HIGH(ta,tb); \
270 c0 += t1; t2 += (c0<t1)?1:0; \
271 c1 += t2; c2 += (c1<t2)?1:0; \
272 }
273
274#define mul_add_c2(a,b,c0,c1,c2) { \
275 BN_ULONG ta=(a),tb=(b),t0; \
276 t1 = BN_UMULT_HIGH(ta,tb); \
277 t0 = ta * tb; \
278 t2 = t1+t1; c2 += (t2<t1)?1:0; \
279 t1 = t0+t0; t2 += (t1<t0)?1:0; \
280 c0 += t1; t2 += (c0<t1)?1:0; \
281 c1 += t2; c2 += (c1<t2)?1:0; \
282 }
283#else
284#define mul_add_c(a,b,c0,c1,c2) do { \
285 asm ("mulq %3" \
286 : "=a"(t1),"=d"(t2) \
287 : "a"(a),"m"(b) \
288 : "cc"); \
289 asm ("addq %2,%0; adcq %3,%1" \
290 : "+r"(c0),"+d"(t2) \
291 : "a"(t1),"g"(0) \
292 : "cc"); \
293 asm ("addq %2,%0; adcq %3,%1" \
294 : "+r"(c1),"+r"(c2) \
295 : "d"(t2),"g"(0) \
296 : "cc"); \
297 } while (0)
298
299#define sqr_add_c(a,i,c0,c1,c2) do { \
300 asm ("mulq %2" \
301 : "=a"(t1),"=d"(t2) \
302 : "a"(a[i]) \
303 : "cc"); \
304 asm ("addq %2,%0; adcq %3,%1" \
305 : "+r"(c0),"+d"(t2) \
306 : "a"(t1),"g"(0) \
307 : "cc"); \
308 asm ("addq %2,%0; adcq %3,%1" \
309 : "+r"(c1),"+r"(c2) \
310 : "d"(t2),"g"(0) \
311 : "cc"); \
312 } while (0)
313
314#define mul_add_c2(a,b,c0,c1,c2) do { \
315 asm ("mulq %3" \
316 : "=a"(t1),"=d"(t2) \
317 : "a"(a),"m"(b) \
318 : "cc"); \
319 asm ("addq %0,%0; adcq %2,%1" \
320 : "+d"(t2),"+r"(c2) \
321 : "g"(0) \
322 : "cc"); \
323 asm ("addq %0,%0; adcq %2,%1" \
324 : "+a"(t1),"+d"(t2) \
325 : "g"(0) \
326 : "cc"); \
327 asm ("addq %2,%0; adcq %3,%1" \
328 : "+r"(c0),"+d"(t2) \
329 : "a"(t1),"g"(0) \
330 : "cc"); \
331 asm ("addq %2,%0; adcq %3,%1" \
332 : "+r"(c1),"+r"(c2) \
333 : "d"(t2),"g"(0) \
334 : "cc"); \
335 } while (0)
336#endif
337
338#define sqr_add_c2(a,i,j,c0,c1,c2) \
339 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
340
341void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
342 {
343 BN_ULONG t1,t2;
344 BN_ULONG c1,c2,c3;
345
346 c1=0;
347 c2=0;
348 c3=0;
349 mul_add_c(a[0],b[0],c1,c2,c3);
350 r[0]=c1;
351 c1=0;
352 mul_add_c(a[0],b[1],c2,c3,c1);
353 mul_add_c(a[1],b[0],c2,c3,c1);
354 r[1]=c2;
355 c2=0;
356 mul_add_c(a[2],b[0],c3,c1,c2);
357 mul_add_c(a[1],b[1],c3,c1,c2);
358 mul_add_c(a[0],b[2],c3,c1,c2);
359 r[2]=c3;
360 c3=0;
361 mul_add_c(a[0],b[3],c1,c2,c3);
362 mul_add_c(a[1],b[2],c1,c2,c3);
363 mul_add_c(a[2],b[1],c1,c2,c3);
364 mul_add_c(a[3],b[0],c1,c2,c3);
365 r[3]=c1;
366 c1=0;
367 mul_add_c(a[4],b[0],c2,c3,c1);
368 mul_add_c(a[3],b[1],c2,c3,c1);
369 mul_add_c(a[2],b[2],c2,c3,c1);
370 mul_add_c(a[1],b[3],c2,c3,c1);
371 mul_add_c(a[0],b[4],c2,c3,c1);
372 r[4]=c2;
373 c2=0;
374 mul_add_c(a[0],b[5],c3,c1,c2);
375 mul_add_c(a[1],b[4],c3,c1,c2);
376 mul_add_c(a[2],b[3],c3,c1,c2);
377 mul_add_c(a[3],b[2],c3,c1,c2);
378 mul_add_c(a[4],b[1],c3,c1,c2);
379 mul_add_c(a[5],b[0],c3,c1,c2);
380 r[5]=c3;
381 c3=0;
382 mul_add_c(a[6],b[0],c1,c2,c3);
383 mul_add_c(a[5],b[1],c1,c2,c3);
384 mul_add_c(a[4],b[2],c1,c2,c3);
385 mul_add_c(a[3],b[3],c1,c2,c3);
386 mul_add_c(a[2],b[4],c1,c2,c3);
387 mul_add_c(a[1],b[5],c1,c2,c3);
388 mul_add_c(a[0],b[6],c1,c2,c3);
389 r[6]=c1;
390 c1=0;
391 mul_add_c(a[0],b[7],c2,c3,c1);
392 mul_add_c(a[1],b[6],c2,c3,c1);
393 mul_add_c(a[2],b[5],c2,c3,c1);
394 mul_add_c(a[3],b[4],c2,c3,c1);
395 mul_add_c(a[4],b[3],c2,c3,c1);
396 mul_add_c(a[5],b[2],c2,c3,c1);
397 mul_add_c(a[6],b[1],c2,c3,c1);
398 mul_add_c(a[7],b[0],c2,c3,c1);
399 r[7]=c2;
400 c2=0;
401 mul_add_c(a[7],b[1],c3,c1,c2);
402 mul_add_c(a[6],b[2],c3,c1,c2);
403 mul_add_c(a[5],b[3],c3,c1,c2);
404 mul_add_c(a[4],b[4],c3,c1,c2);
405 mul_add_c(a[3],b[5],c3,c1,c2);
406 mul_add_c(a[2],b[6],c3,c1,c2);
407 mul_add_c(a[1],b[7],c3,c1,c2);
408 r[8]=c3;
409 c3=0;
410 mul_add_c(a[2],b[7],c1,c2,c3);
411 mul_add_c(a[3],b[6],c1,c2,c3);
412 mul_add_c(a[4],b[5],c1,c2,c3);
413 mul_add_c(a[5],b[4],c1,c2,c3);
414 mul_add_c(a[6],b[3],c1,c2,c3);
415 mul_add_c(a[7],b[2],c1,c2,c3);
416 r[9]=c1;
417 c1=0;
418 mul_add_c(a[7],b[3],c2,c3,c1);
419 mul_add_c(a[6],b[4],c2,c3,c1);
420 mul_add_c(a[5],b[5],c2,c3,c1);
421 mul_add_c(a[4],b[6],c2,c3,c1);
422 mul_add_c(a[3],b[7],c2,c3,c1);
423 r[10]=c2;
424 c2=0;
425 mul_add_c(a[4],b[7],c3,c1,c2);
426 mul_add_c(a[5],b[6],c3,c1,c2);
427 mul_add_c(a[6],b[5],c3,c1,c2);
428 mul_add_c(a[7],b[4],c3,c1,c2);
429 r[11]=c3;
430 c3=0;
431 mul_add_c(a[7],b[5],c1,c2,c3);
432 mul_add_c(a[6],b[6],c1,c2,c3);
433 mul_add_c(a[5],b[7],c1,c2,c3);
434 r[12]=c1;
435 c1=0;
436 mul_add_c(a[6],b[7],c2,c3,c1);
437 mul_add_c(a[7],b[6],c2,c3,c1);
438 r[13]=c2;
439 c2=0;
440 mul_add_c(a[7],b[7],c3,c1,c2);
441 r[14]=c3;
442 r[15]=c1;
443 }
444
445void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
446 {
447 BN_ULONG t1,t2;
448 BN_ULONG c1,c2,c3;
449
450 c1=0;
451 c2=0;
452 c3=0;
453 mul_add_c(a[0],b[0],c1,c2,c3);
454 r[0]=c1;
455 c1=0;
456 mul_add_c(a[0],b[1],c2,c3,c1);
457 mul_add_c(a[1],b[0],c2,c3,c1);
458 r[1]=c2;
459 c2=0;
460 mul_add_c(a[2],b[0],c3,c1,c2);
461 mul_add_c(a[1],b[1],c3,c1,c2);
462 mul_add_c(a[0],b[2],c3,c1,c2);
463 r[2]=c3;
464 c3=0;
465 mul_add_c(a[0],b[3],c1,c2,c3);
466 mul_add_c(a[1],b[2],c1,c2,c3);
467 mul_add_c(a[2],b[1],c1,c2,c3);
468 mul_add_c(a[3],b[0],c1,c2,c3);
469 r[3]=c1;
470 c1=0;
471 mul_add_c(a[3],b[1],c2,c3,c1);
472 mul_add_c(a[2],b[2],c2,c3,c1);
473 mul_add_c(a[1],b[3],c2,c3,c1);
474 r[4]=c2;
475 c2=0;
476 mul_add_c(a[2],b[3],c3,c1,c2);
477 mul_add_c(a[3],b[2],c3,c1,c2);
478 r[5]=c3;
479 c3=0;
480 mul_add_c(a[3],b[3],c1,c2,c3);
481 r[6]=c1;
482 r[7]=c2;
483 }
484
485void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
486 {
487 BN_ULONG t1,t2;
488 BN_ULONG c1,c2,c3;
489
490 c1=0;
491 c2=0;
492 c3=0;
493 sqr_add_c(a,0,c1,c2,c3);
494 r[0]=c1;
495 c1=0;
496 sqr_add_c2(a,1,0,c2,c3,c1);
497 r[1]=c2;
498 c2=0;
499 sqr_add_c(a,1,c3,c1,c2);
500 sqr_add_c2(a,2,0,c3,c1,c2);
501 r[2]=c3;
502 c3=0;
503 sqr_add_c2(a,3,0,c1,c2,c3);
504 sqr_add_c2(a,2,1,c1,c2,c3);
505 r[3]=c1;
506 c1=0;
507 sqr_add_c(a,2,c2,c3,c1);
508 sqr_add_c2(a,3,1,c2,c3,c1);
509 sqr_add_c2(a,4,0,c2,c3,c1);
510 r[4]=c2;
511 c2=0;
512 sqr_add_c2(a,5,0,c3,c1,c2);
513 sqr_add_c2(a,4,1,c3,c1,c2);
514 sqr_add_c2(a,3,2,c3,c1,c2);
515 r[5]=c3;
516 c3=0;
517 sqr_add_c(a,3,c1,c2,c3);
518 sqr_add_c2(a,4,2,c1,c2,c3);
519 sqr_add_c2(a,5,1,c1,c2,c3);
520 sqr_add_c2(a,6,0,c1,c2,c3);
521 r[6]=c1;
522 c1=0;
523 sqr_add_c2(a,7,0,c2,c3,c1);
524 sqr_add_c2(a,6,1,c2,c3,c1);
525 sqr_add_c2(a,5,2,c2,c3,c1);
526 sqr_add_c2(a,4,3,c2,c3,c1);
527 r[7]=c2;
528 c2=0;
529 sqr_add_c(a,4,c3,c1,c2);
530 sqr_add_c2(a,5,3,c3,c1,c2);
531 sqr_add_c2(a,6,2,c3,c1,c2);
532 sqr_add_c2(a,7,1,c3,c1,c2);
533 r[8]=c3;
534 c3=0;
535 sqr_add_c2(a,7,2,c1,c2,c3);
536 sqr_add_c2(a,6,3,c1,c2,c3);
537 sqr_add_c2(a,5,4,c1,c2,c3);
538 r[9]=c1;
539 c1=0;
540 sqr_add_c(a,5,c2,c3,c1);
541 sqr_add_c2(a,6,4,c2,c3,c1);
542 sqr_add_c2(a,7,3,c2,c3,c1);
543 r[10]=c2;
544 c2=0;
545 sqr_add_c2(a,7,4,c3,c1,c2);
546 sqr_add_c2(a,6,5,c3,c1,c2);
547 r[11]=c3;
548 c3=0;
549 sqr_add_c(a,6,c1,c2,c3);
550 sqr_add_c2(a,7,5,c1,c2,c3);
551 r[12]=c1;
552 c1=0;
553 sqr_add_c2(a,7,6,c2,c3,c1);
554 r[13]=c2;
555 c2=0;
556 sqr_add_c(a,7,c3,c1,c2);
557 r[14]=c3;
558 r[15]=c1;
559 }
560
561void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
562 {
563 BN_ULONG t1,t2;
564 BN_ULONG c1,c2,c3;
565
566 c1=0;
567 c2=0;
568 c3=0;
569 sqr_add_c(a,0,c1,c2,c3);
570 r[0]=c1;
571 c1=0;
572 sqr_add_c2(a,1,0,c2,c3,c1);
573 r[1]=c2;
574 c2=0;
575 sqr_add_c(a,1,c3,c1,c2);
576 sqr_add_c2(a,2,0,c3,c1,c2);
577 r[2]=c3;
578 c3=0;
579 sqr_add_c2(a,3,0,c1,c2,c3);
580 sqr_add_c2(a,2,1,c1,c2,c3);
581 r[3]=c1;
582 c1=0;
583 sqr_add_c(a,2,c2,c3,c1);
584 sqr_add_c2(a,3,1,c2,c3,c1);
585 r[4]=c2;
586 c2=0;
587 sqr_add_c2(a,3,2,c3,c1,c2);
588 r[5]=c3;
589 c3=0;
590 sqr_add_c(a,3,c1,c2,c3);
591 r[6]=c1;
592 r[7]=c2;
593 }
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
deleted file mode 100644
index 1251521c54..0000000000
--- a/src/lib/libcrypto/bn/bn.h
+++ /dev/null
@@ -1,583 +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#include <openssl/e_os2.h>
63#ifndef OPENSSL_NO_FP_API
64#include <stdio.h> /* FILE */
65#endif
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71#ifdef OPENSSL_SYS_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
79/* This next option uses the C libraries (2 word)/(1 word) function.
80 * If it is not defined, I use my C version (which is slower).
81 * The reason for this flag is that when the particular C compiler
82 * library routine is used, and the library is linked with a different
83 * compiler, the library is missing. This mostly happens when the
84 * library is built with gcc and then linked using normal cc. This would
85 * be a common occurrence because gcc normally produces code that is
86 * 2 times faster than system compilers for the big number stuff.
87 * For machines with only one compiler (or shared libraries), this should
88 * be on. Again this in only really a problem on machines
89 * using "long long's", are 32bit, and are not using my assembler code. */
90#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || \
91 defined(OPENSSL_SYS_WIN32) || defined(linux)
92# ifndef BN_DIV2W
93# define BN_DIV2W
94# endif
95#endif
96
97/* assuming long is 64bit - this is the DEC Alpha
98 * unsigned long long is only 64 bits :-(, don't define
99 * BN_LLONG for the DEC Alpha */
100#ifdef SIXTY_FOUR_BIT_LONG
101#define BN_ULLONG unsigned long long
102#define BN_ULONG unsigned long
103#define BN_LONG long
104#define BN_BITS 128
105#define BN_BYTES 8
106#define BN_BITS2 64
107#define BN_BITS4 32
108#define BN_MASK (0xffffffffffffffffffffffffffffffffLL)
109#define BN_MASK2 (0xffffffffffffffffL)
110#define BN_MASK2l (0xffffffffL)
111#define BN_MASK2h (0xffffffff00000000L)
112#define BN_MASK2h1 (0xffffffff80000000L)
113#define BN_TBIT (0x8000000000000000L)
114#define BN_DEC_CONV (10000000000000000000UL)
115#define BN_DEC_FMT1 "%lu"
116#define BN_DEC_FMT2 "%019lu"
117#define BN_DEC_NUM 19
118#endif
119
120/* This is where the long long data type is 64 bits, but long is 32.
121 * For machines where there are 64bit registers, this is the mode to use.
122 * IRIX, on R4000 and above should use this mode, along with the relevant
123 * assembler code :-). Do NOT define BN_LLONG.
124 */
125#ifdef SIXTY_FOUR_BIT
126#undef BN_LLONG
127#undef BN_ULLONG
128#define BN_ULONG unsigned long long
129#define BN_LONG long long
130#define BN_BITS 128
131#define BN_BYTES 8
132#define BN_BITS2 64
133#define BN_BITS4 32
134#define BN_MASK2 (0xffffffffffffffffLL)
135#define BN_MASK2l (0xffffffffL)
136#define BN_MASK2h (0xffffffff00000000LL)
137#define BN_MASK2h1 (0xffffffff80000000LL)
138#define BN_TBIT (0x8000000000000000LL)
139#define BN_DEC_CONV (10000000000000000000ULL)
140#define BN_DEC_FMT1 "%llu"
141#define BN_DEC_FMT2 "%019llu"
142#define BN_DEC_NUM 19
143#endif
144
145#ifdef THIRTY_TWO_BIT
146#if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
147#define BN_ULLONG unsigned _int64
148#else
149#define BN_ULLONG unsigned long long
150#endif
151#define BN_ULONG unsigned long
152#define BN_LONG long
153#define BN_BITS 64
154#define BN_BYTES 4
155#define BN_BITS2 32
156#define BN_BITS4 16
157#ifdef OPENSSL_SYS_WIN32
158/* VC++ doesn't like the LL suffix */
159#define BN_MASK (0xffffffffffffffffL)
160#else
161#define BN_MASK (0xffffffffffffffffLL)
162#endif
163#define BN_MASK2 (0xffffffffL)
164#define BN_MASK2l (0xffff)
165#define BN_MASK2h1 (0xffff8000L)
166#define BN_MASK2h (0xffff0000L)
167#define BN_TBIT (0x80000000L)
168#define BN_DEC_CONV (1000000000L)
169#define BN_DEC_FMT1 "%lu"
170#define BN_DEC_FMT2 "%09lu"
171#define BN_DEC_NUM 9
172#endif
173
174#ifdef SIXTEEN_BIT
175#ifndef BN_DIV2W
176#define BN_DIV2W
177#endif
178#define BN_ULLONG unsigned long
179#define BN_ULONG unsigned short
180#define BN_LONG short
181#define BN_BITS 32
182#define BN_BYTES 2
183#define BN_BITS2 16
184#define BN_BITS4 8
185#define BN_MASK (0xffffffff)
186#define BN_MASK2 (0xffff)
187#define BN_MASK2l (0xff)
188#define BN_MASK2h1 (0xff80)
189#define BN_MASK2h (0xff00)
190#define BN_TBIT (0x8000)
191#define BN_DEC_CONV (100000)
192#define BN_DEC_FMT1 "%u"
193#define BN_DEC_FMT2 "%05u"
194#define BN_DEC_NUM 5
195#endif
196
197#ifdef EIGHT_BIT
198#ifndef BN_DIV2W
199#define BN_DIV2W
200#endif
201#define BN_ULLONG unsigned short
202#define BN_ULONG unsigned char
203#define BN_LONG char
204#define BN_BITS 16
205#define BN_BYTES 1
206#define BN_BITS2 8
207#define BN_BITS4 4
208#define BN_MASK (0xffff)
209#define BN_MASK2 (0xff)
210#define BN_MASK2l (0xf)
211#define BN_MASK2h1 (0xf8)
212#define BN_MASK2h (0xf0)
213#define BN_TBIT (0x80)
214#define BN_DEC_CONV (100)
215#define BN_DEC_FMT1 "%u"
216#define BN_DEC_FMT2 "%02u"
217#define BN_DEC_NUM 2
218#endif
219
220#define BN_DEFAULT_BITS 1280
221
222#ifdef BIGNUM
223#undef BIGNUM
224#endif
225
226#define BN_FLG_MALLOCED 0x01
227#define BN_FLG_STATIC_DATA 0x02
228#define BN_FLG_EXP_CONSTTIME 0x04 /* avoid leaking exponent information through timings
229 * (BN_mod_exp_mont() will call BN_mod_exp_mont_consttime) */
230#define BN_FLG_FREE 0x8000 /* used for debuging */
231#define BN_set_flags(b,n) ((b)->flags|=(n))
232#define BN_get_flags(b,n) ((b)->flags&(n))
233
234/* get a clone of a BIGNUM with changed flags, for *temporary* use only
235 * (the two BIGNUMs cannot not be used in parallel!) */
236#define BN_with_flags(dest,b,n) ((dest)->d=(b)->d, \
237 (dest)->top=(b)->top, \
238 (dest)->dmax=(b)->dmax, \
239 (dest)->neg=(b)->neg, \
240 (dest)->flags=(((dest)->flags & BN_FLG_MALLOCED) \
241 | ((b)->flags & ~BN_FLG_MALLOCED) \
242 | BN_FLG_STATIC_DATA \
243 | (n)))
244
245typedef struct bignum_st
246 {
247 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
248 int top; /* Index of last used d +1. */
249 /* The next are internal book keeping for bn_expand. */
250 int dmax; /* Size of the d array. */
251 int neg; /* one if the number is negative */
252 int flags;
253 } BIGNUM;
254
255/* Used for temp variables (declaration hidden in bn_lcl.h) */
256typedef struct bignum_ctx BN_CTX;
257
258typedef struct bn_blinding_st
259 {
260 int init;
261 BIGNUM *A;
262 BIGNUM *Ai;
263 BIGNUM *mod; /* just a reference */
264 unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b;
265 * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
266 } BN_BLINDING;
267
268/* Used for montgomery multiplication */
269typedef struct bn_mont_ctx_st
270 {
271 int ri; /* number of bits in R */
272 BIGNUM RR; /* used to convert to montgomery form */
273 BIGNUM N; /* The modulus */
274 BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
275 * (Ni is only stored for bignum algorithm) */
276 BN_ULONG n0; /* least significant word of Ni */
277 int flags;
278 } BN_MONT_CTX;
279
280/* Used for reciprocal division/mod functions
281 * It cannot be shared between threads
282 */
283typedef struct bn_recp_ctx_st
284 {
285 BIGNUM N; /* the divisor */
286 BIGNUM Nr; /* the reciprocal */
287 int num_bits;
288 int shift;
289 int flags;
290 } BN_RECP_CTX;
291
292#define BN_prime_checks 0 /* default: select number of iterations
293 based on the size of the number */
294
295/* number of Miller-Rabin iterations for an error rate of less than 2^-80
296 * for random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook
297 * of Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996];
298 * original paper: Damgaard, Landrock, Pomerance: Average case error estimates
299 * for the strong probable prime test. -- Math. Comp. 61 (1993) 177-194) */
300#define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \
301 (b) >= 850 ? 3 : \
302 (b) >= 650 ? 4 : \
303 (b) >= 550 ? 5 : \
304 (b) >= 450 ? 6 : \
305 (b) >= 400 ? 7 : \
306 (b) >= 350 ? 8 : \
307 (b) >= 300 ? 9 : \
308 (b) >= 250 ? 12 : \
309 (b) >= 200 ? 15 : \
310 (b) >= 150 ? 18 : \
311 /* b >= 100 */ 27)
312
313#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
314
315/* Note that BN_abs_is_word does not work reliably for w == 0 */
316#define BN_abs_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
317#define BN_is_zero(a) (((a)->top == 0) || BN_abs_is_word(a,0))
318#define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg)
319#define BN_is_word(a,w) ((w) ? BN_abs_is_word((a),(w)) && !(a)->neg : \
320 BN_is_zero((a)))
321#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))
322
323#define BN_one(a) (BN_set_word((a),1))
324#define BN_zero(a) (BN_set_word((a),0))
325
326/*#define BN_ascii2bn(a) BN_hex2bn(a) */
327/*#define BN_bn2ascii(a) BN_bn2hex(a) */
328
329const BIGNUM *BN_value_one(void);
330char * BN_options(void);
331BN_CTX *BN_CTX_new(void);
332void BN_CTX_init(BN_CTX *c);
333void BN_CTX_free(BN_CTX *c);
334void BN_CTX_start(BN_CTX *ctx);
335BIGNUM *BN_CTX_get(BN_CTX *ctx);
336void BN_CTX_end(BN_CTX *ctx);
337int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
338int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom);
339int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
340int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
341int BN_num_bits(const BIGNUM *a);
342int BN_num_bits_word(BN_ULONG);
343BIGNUM *BN_new(void);
344void BN_init(BIGNUM *);
345void BN_clear_free(BIGNUM *a);
346BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
347void BN_swap(BIGNUM *a, BIGNUM *b);
348BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
349int BN_bn2bin(const BIGNUM *a, unsigned char *to);
350BIGNUM *BN_mpi2bn(const unsigned char *s,int len,BIGNUM *ret);
351int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
352int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
353int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
354int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
355int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
356int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
357int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);
358
359int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
360 BN_CTX *ctx);
361#define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx))
362int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
363int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
364int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
365int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
366int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
367int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
368 const BIGNUM *m, BN_CTX *ctx);
369int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
370int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
371int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m);
372int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx);
373int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m);
374
375BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
376BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
377int BN_mul_word(BIGNUM *a, BN_ULONG w);
378int BN_add_word(BIGNUM *a, BN_ULONG w);
379int BN_sub_word(BIGNUM *a, BN_ULONG w);
380int BN_set_word(BIGNUM *a, BN_ULONG w);
381BN_ULONG BN_get_word(const BIGNUM *a);
382
383int BN_cmp(const BIGNUM *a, const BIGNUM *b);
384void BN_free(BIGNUM *a);
385int BN_is_bit_set(const BIGNUM *a, int n);
386int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
387int BN_lshift1(BIGNUM *r, const BIGNUM *a);
388int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,BN_CTX *ctx);
389
390int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
391 const BIGNUM *m,BN_CTX *ctx);
392int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
393 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
394int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
395 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont);
396int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p,
397 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
398int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1,
399 const BIGNUM *a2, const BIGNUM *p2,const BIGNUM *m,
400 BN_CTX *ctx,BN_MONT_CTX *m_ctx);
401int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
402 const BIGNUM *m,BN_CTX *ctx);
403
404int BN_mask_bits(BIGNUM *a,int n);
405#ifndef OPENSSL_NO_FP_API
406int BN_print_fp(FILE *fp, const BIGNUM *a);
407#endif
408#ifdef HEADER_BIO_H
409int BN_print(BIO *fp, const BIGNUM *a);
410#else
411int BN_print(void *fp, const BIGNUM *a);
412#endif
413int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx);
414int BN_rshift(BIGNUM *r, const BIGNUM *a, int n);
415int BN_rshift1(BIGNUM *r, const BIGNUM *a);
416void BN_clear(BIGNUM *a);
417BIGNUM *BN_dup(const BIGNUM *a);
418int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
419int BN_set_bit(BIGNUM *a, int n);
420int BN_clear_bit(BIGNUM *a, int n);
421char * BN_bn2hex(const BIGNUM *a);
422char * BN_bn2dec(const BIGNUM *a);
423int BN_hex2bn(BIGNUM **a, const char *str);
424int BN_dec2bn(BIGNUM **a, const char *str);
425int BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx);
426int BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */
427BIGNUM *BN_mod_inverse(BIGNUM *ret,
428 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
429BIGNUM *BN_mod_sqrt(BIGNUM *ret,
430 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
431BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,
432 const BIGNUM *add, const BIGNUM *rem,
433 void (*callback)(int,int,void *),void *cb_arg);
434int BN_is_prime(const BIGNUM *p,int nchecks,
435 void (*callback)(int,int,void *),
436 BN_CTX *ctx,void *cb_arg);
437int BN_is_prime_fasttest(const BIGNUM *p,int nchecks,
438 void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg,
439 int do_trial_division);
440
441#ifdef OPENSSL_FIPS
442int BN_X931_derive_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
443 void (*cb)(int, int, void *), void *cb_arg,
444 const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2,
445 const BIGNUM *e, BN_CTX *ctx);
446int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx);
447int BN_X931_generate_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
448 BIGNUM *Xp1, BIGNUM *Xp2,
449 const BIGNUM *Xp,
450 const BIGNUM *e, BN_CTX *ctx,
451 void (*cb)(int, int, void *), void *cb_arg);
452#endif
453
454BN_MONT_CTX *BN_MONT_CTX_new(void );
455void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
456int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,
457 BN_MONT_CTX *mont, BN_CTX *ctx);
458#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
459 (r),(a),&((mont)->RR),(mont),(ctx))
460int BN_from_montgomery(BIGNUM *r,const BIGNUM *a,
461 BN_MONT_CTX *mont, BN_CTX *ctx);
462void BN_MONT_CTX_free(BN_MONT_CTX *mont);
463int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *mod,BN_CTX *ctx);
464BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);
465BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
466 const BIGNUM *mod, BN_CTX *ctx);
467
468BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod);
469void BN_BLINDING_free(BN_BLINDING *b);
470int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
471int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx);
472int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
473
474void BN_set_params(int mul,int high,int low,int mont);
475int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */
476
477void BN_RECP_CTX_init(BN_RECP_CTX *recp);
478BN_RECP_CTX *BN_RECP_CTX_new(void);
479void BN_RECP_CTX_free(BN_RECP_CTX *recp);
480int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx);
481int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
482 BN_RECP_CTX *recp,BN_CTX *ctx);
483int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
484 const BIGNUM *m, BN_CTX *ctx);
485int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
486 BN_RECP_CTX *recp, BN_CTX *ctx);
487
488/* library internal functions */
489
490#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
491 (a):bn_expand2((a),(bits)/BN_BITS2+1))
492#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))
493BIGNUM *bn_expand2(BIGNUM *a, int words);
494BIGNUM *bn_dup_expand(const BIGNUM *a, int words);
495
496#define bn_fix_top(a) \
497 { \
498 BN_ULONG *ftl; \
499 if ((a)->top > 0) \
500 { \
501 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
502 if (*(ftl--)) break; \
503 } \
504 }
505
506BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
507BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
508void bn_sqr_words(BN_ULONG *rp, const BN_ULONG *ap, int num);
509BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
510BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
511BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
512
513#ifdef BN_DEBUG
514void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n);
515# define bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \
516 fprintf(stderr,"\n");}
517# define bn_dump(a,n) bn_dump1(stderr,#a,a,n);
518#else
519# define bn_print(a)
520# define bn_dump(a,b)
521#endif
522
523int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom);
524
525/* BEGIN ERROR CODES */
526/* The following lines are auto generated by the script mkerr.pl. Any changes
527 * made after this point may be overwritten when the script is next run.
528 */
529void ERR_load_BN_strings(void);
530
531/* Error codes for the BN functions. */
532
533/* Function codes. */
534#define BN_F_BN_BLINDING_CONVERT 100
535#define BN_F_BN_BLINDING_INVERT 101
536#define BN_F_BN_BLINDING_NEW 102
537#define BN_F_BN_BLINDING_UPDATE 103
538#define BN_F_BN_BN2DEC 104
539#define BN_F_BN_BN2HEX 105
540#define BN_F_BN_CTX_GET 116
541#define BN_F_BN_CTX_NEW 106
542#define BN_F_BN_DIV 107
543#define BN_F_BN_EXP 123
544#define BN_F_BN_EXPAND2 108
545#define BN_F_BN_EXPAND_INTERNAL 120
546#define BN_F_BN_MOD_EXP2_MONT 118
547#define BN_F_BN_MOD_EXP_MONT 109
548#define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124
549#define BN_F_BN_MOD_EXP_MONT_WORD 117
550#define BN_F_BN_MOD_EXP_RECP 125
551#define BN_F_BN_MOD_EXP_SIMPLE 126
552#define BN_F_BN_MOD_INVERSE 110
553#define BN_F_BN_MOD_LSHIFT_QUICK 119
554#define BN_F_BN_MOD_MUL_RECIPROCAL 111
555#define BN_F_BN_MOD_SQRT 121
556#define BN_F_BN_MPI2BN 112
557#define BN_F_BN_NEW 113
558#define BN_F_BN_RAND 114
559#define BN_F_BN_RAND_RANGE 122
560#define BN_F_BN_USUB 115
561
562/* Reason codes. */
563#define BN_R_ARG2_LT_ARG3 100
564#define BN_R_BAD_RECIPROCAL 101
565#define BN_R_BIGNUM_TOO_LONG 114
566#define BN_R_CALLED_WITH_EVEN_MODULUS 102
567#define BN_R_DIV_BY_ZERO 103
568#define BN_R_ENCODING_ERROR 104
569#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105
570#define BN_R_INPUT_NOT_REDUCED 110
571#define BN_R_INVALID_LENGTH 106
572#define BN_R_INVALID_RANGE 115
573#define BN_R_NOT_A_SQUARE 111
574#define BN_R_NOT_INITIALIZED 107
575#define BN_R_NO_INVERSE 108
576#define BN_R_P_IS_NOT_PRIME 112
577#define BN_R_TOO_MANY_ITERATIONS 113
578#define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109
579
580#ifdef __cplusplus
581}
582#endif
583#endif
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
deleted file mode 100644
index 6cba07e9f6..0000000000
--- a/src/lib/libcrypto/bn/bn_add.c
+++ /dev/null
@@ -1,309 +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 int a_neg = a->neg;
68
69 bn_check_top(a);
70 bn_check_top(b);
71
72 /* a + b a+b
73 * a + -b a-b
74 * -a + b b-a
75 * -a + -b -(a+b)
76 */
77 if (a_neg ^ b->neg)
78 {
79 /* only one is negative */
80 if (a_neg)
81 { tmp=a; a=b; b=tmp; }
82
83 /* we are now a - b */
84
85 if (BN_ucmp(a,b) < 0)
86 {
87 if (!BN_usub(r,b,a)) return(0);
88 r->neg=1;
89 }
90 else
91 {
92 if (!BN_usub(r,a,b)) return(0);
93 r->neg=0;
94 }
95 return(1);
96 }
97
98 if (!BN_uadd(r,a,b)) return(0);
99 if (a_neg) /* both are neg */
100 r->neg=1;
101 else
102 r->neg=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 r->neg = 0;
164 return(1);
165 }
166
167/* unsigned subtraction of b from a, a must be larger than b. */
168int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
169 {
170 int max,min;
171 register BN_ULONG t1,t2,*ap,*bp,*rp;
172 int i,carry;
173#if defined(IRIX_CC_BUG) && !defined(LINT)
174 int dummy;
175#endif
176
177 bn_check_top(a);
178 bn_check_top(b);
179
180 if (a->top < b->top) /* hmm... should not be happening */
181 {
182 BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);
183 return(0);
184 }
185
186 max=a->top;
187 min=b->top;
188 if (bn_wexpand(r,max) == NULL) return(0);
189
190 ap=a->d;
191 bp=b->d;
192 rp=r->d;
193
194#if 1
195 carry=0;
196 for (i=0; i<min; i++)
197 {
198 t1= *(ap++);
199 t2= *(bp++);
200 if (carry)
201 {
202 carry=(t1 <= t2);
203 t1=(t1-t2-1)&BN_MASK2;
204 }
205 else
206 {
207 carry=(t1 < t2);
208 t1=(t1-t2)&BN_MASK2;
209 }
210#if defined(IRIX_CC_BUG) && !defined(LINT)
211 dummy=t1;
212#endif
213 *(rp++)=t1&BN_MASK2;
214 }
215#else
216 carry=bn_sub_words(rp,ap,bp,min);
217 ap+=min;
218 bp+=min;
219 rp+=min;
220 i=min;
221#endif
222 if (carry) /* subtracted */
223 {
224 while (i < max)
225 {
226 i++;
227 t1= *(ap++);
228 t2=(t1-1)&BN_MASK2;
229 *(rp++)=t2;
230 if (t1 > t2) break;
231 }
232 }
233#if 0
234 memcpy(rp,ap,sizeof(*rp)*(max-i));
235#else
236 if (rp != ap)
237 {
238 for (;;)
239 {
240 if (i++ >= max) break;
241 rp[0]=ap[0];
242 if (i++ >= max) break;
243 rp[1]=ap[1];
244 if (i++ >= max) break;
245 rp[2]=ap[2];
246 if (i++ >= max) break;
247 rp[3]=ap[3];
248 rp+=4;
249 ap+=4;
250 }
251 }
252#endif
253
254 r->top=max;
255 r->neg=0;
256 bn_fix_top(r);
257 return(1);
258 }
259
260int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
261 {
262 int max;
263 int add=0,neg=0;
264 const BIGNUM *tmp;
265
266 bn_check_top(a);
267 bn_check_top(b);
268
269 /* a - b a-b
270 * a - -b a+b
271 * -a - b -(a+b)
272 * -a - -b b-a
273 */
274 if (a->neg)
275 {
276 if (b->neg)
277 { tmp=a; a=b; b=tmp; }
278 else
279 { add=1; neg=1; }
280 }
281 else
282 {
283 if (b->neg) { add=1; neg=0; }
284 }
285
286 if (add)
287 {
288 if (!BN_uadd(r,a,b)) return(0);
289 r->neg=neg;
290 return(1);
291 }
292
293 /* We are actually doing a - b :-) */
294
295 max=(a->top > b->top)?a->top:b->top;
296 if (bn_wexpand(r,max) == NULL) return(0);
297 if (BN_ucmp(a,b) < 0)
298 {
299 if (!BN_usub(r,b,a)) return(0);
300 r->neg=1;
301 }
302 else
303 {
304 if (!BN_usub(r,a,b)) return(0);
305 r->neg=0;
306 }
307 return(1);
308 }
309
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c
deleted file mode 100644
index 19978085b2..0000000000
--- a/src/lib/libcrypto/bn/bn_asm.c
+++ /dev/null
@@ -1,832 +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, const 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, const 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, const 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, const 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, const 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, const 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 assert((i == BN_BITS2) || (h <= (BN_ULONG)1<<i));
241
242 i=BN_BITS2-i;
243 if (h >= d) h-=d;
244
245 if (i)
246 {
247 d<<=i;
248 h=(h<<i)|(l>>(BN_BITS2-i));
249 l<<=i;
250 }
251 dh=(d&BN_MASK2h)>>BN_BITS4;
252 dl=(d&BN_MASK2l);
253 for (;;)
254 {
255 if ((h>>BN_BITS4) == dh)
256 q=BN_MASK2l;
257 else
258 q=h/dh;
259
260 th=q*dh;
261 tl=dl*q;
262 for (;;)
263 {
264 t=h-th;
265 if ((t&BN_MASK2h) ||
266 ((tl) <= (
267 (t<<BN_BITS4)|
268 ((l&BN_MASK2h)>>BN_BITS4))))
269 break;
270 q--;
271 th-=dh;
272 tl-=dl;
273 }
274 t=(tl>>BN_BITS4);
275 tl=(tl<<BN_BITS4)&BN_MASK2h;
276 th+=t;
277
278 if (l < tl) th++;
279 l-=tl;
280 if (h < th)
281 {
282 h+=d;
283 q--;
284 }
285 h-=th;
286
287 if (--count == 0) break;
288
289 ret=q<<BN_BITS4;
290 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
291 l=(l&BN_MASK2l)<<BN_BITS4;
292 }
293 ret|=q;
294 return(ret);
295 }
296#endif /* !defined(BN_LLONG) && defined(BN_DIV2W) */
297
298#ifdef BN_LLONG
299BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
300 {
301 BN_ULLONG ll=0;
302
303 assert(n >= 0);
304 if (n <= 0) return((BN_ULONG)0);
305
306 for (;;)
307 {
308 ll+=(BN_ULLONG)a[0]+b[0];
309 r[0]=(BN_ULONG)ll&BN_MASK2;
310 ll>>=BN_BITS2;
311 if (--n <= 0) break;
312
313 ll+=(BN_ULLONG)a[1]+b[1];
314 r[1]=(BN_ULONG)ll&BN_MASK2;
315 ll>>=BN_BITS2;
316 if (--n <= 0) break;
317
318 ll+=(BN_ULLONG)a[2]+b[2];
319 r[2]=(BN_ULONG)ll&BN_MASK2;
320 ll>>=BN_BITS2;
321 if (--n <= 0) break;
322
323 ll+=(BN_ULLONG)a[3]+b[3];
324 r[3]=(BN_ULONG)ll&BN_MASK2;
325 ll>>=BN_BITS2;
326 if (--n <= 0) break;
327
328 a+=4;
329 b+=4;
330 r+=4;
331 }
332 return((BN_ULONG)ll);
333 }
334#else /* !BN_LLONG */
335BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
336 {
337 BN_ULONG c,l,t;
338
339 assert(n >= 0);
340 if (n <= 0) return((BN_ULONG)0);
341
342 c=0;
343 for (;;)
344 {
345 t=a[0];
346 t=(t+c)&BN_MASK2;
347 c=(t < c);
348 l=(t+b[0])&BN_MASK2;
349 c+=(l < t);
350 r[0]=l;
351 if (--n <= 0) break;
352
353 t=a[1];
354 t=(t+c)&BN_MASK2;
355 c=(t < c);
356 l=(t+b[1])&BN_MASK2;
357 c+=(l < t);
358 r[1]=l;
359 if (--n <= 0) break;
360
361 t=a[2];
362 t=(t+c)&BN_MASK2;
363 c=(t < c);
364 l=(t+b[2])&BN_MASK2;
365 c+=(l < t);
366 r[2]=l;
367 if (--n <= 0) break;
368
369 t=a[3];
370 t=(t+c)&BN_MASK2;
371 c=(t < c);
372 l=(t+b[3])&BN_MASK2;
373 c+=(l < t);
374 r[3]=l;
375 if (--n <= 0) break;
376
377 a+=4;
378 b+=4;
379 r+=4;
380 }
381 return((BN_ULONG)c);
382 }
383#endif /* !BN_LLONG */
384
385BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
386 {
387 BN_ULONG t1,t2;
388 int c=0;
389
390 assert(n >= 0);
391 if (n <= 0) return((BN_ULONG)0);
392
393 for (;;)
394 {
395 t1=a[0]; t2=b[0];
396 r[0]=(t1-t2-c)&BN_MASK2;
397 if (t1 != t2) c=(t1 < t2);
398 if (--n <= 0) break;
399
400 t1=a[1]; t2=b[1];
401 r[1]=(t1-t2-c)&BN_MASK2;
402 if (t1 != t2) c=(t1 < t2);
403 if (--n <= 0) break;
404
405 t1=a[2]; t2=b[2];
406 r[2]=(t1-t2-c)&BN_MASK2;
407 if (t1 != t2) c=(t1 < t2);
408 if (--n <= 0) break;
409
410 t1=a[3]; t2=b[3];
411 r[3]=(t1-t2-c)&BN_MASK2;
412 if (t1 != t2) c=(t1 < t2);
413 if (--n <= 0) break;
414
415 a+=4;
416 b+=4;
417 r+=4;
418 }
419 return(c);
420 }
421
422#ifdef BN_MUL_COMBA
423
424#undef bn_mul_comba8
425#undef bn_mul_comba4
426#undef bn_sqr_comba8
427#undef bn_sqr_comba4
428
429/* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */
430/* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */
431/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
432/* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
433
434#ifdef BN_LLONG
435#define mul_add_c(a,b,c0,c1,c2) \
436 t=(BN_ULLONG)a*b; \
437 t1=(BN_ULONG)Lw(t); \
438 t2=(BN_ULONG)Hw(t); \
439 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
440 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
441
442#define mul_add_c2(a,b,c0,c1,c2) \
443 t=(BN_ULLONG)a*b; \
444 tt=(t+t)&BN_MASK; \
445 if (tt < t) c2++; \
446 t1=(BN_ULONG)Lw(tt); \
447 t2=(BN_ULONG)Hw(tt); \
448 c0=(c0+t1)&BN_MASK2; \
449 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
450 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
451
452#define sqr_add_c(a,i,c0,c1,c2) \
453 t=(BN_ULLONG)a[i]*a[i]; \
454 t1=(BN_ULONG)Lw(t); \
455 t2=(BN_ULONG)Hw(t); \
456 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
457 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
458
459#define sqr_add_c2(a,i,j,c0,c1,c2) \
460 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
461
462#elif defined(BN_UMULT_HIGH)
463
464#define mul_add_c(a,b,c0,c1,c2) { \
465 BN_ULONG ta=(a),tb=(b); \
466 t1 = ta * tb; \
467 t2 = BN_UMULT_HIGH(ta,tb); \
468 c0 += t1; t2 += (c0<t1)?1:0; \
469 c1 += t2; c2 += (c1<t2)?1:0; \
470 }
471
472#define mul_add_c2(a,b,c0,c1,c2) { \
473 BN_ULONG ta=(a),tb=(b),t0; \
474 t1 = BN_UMULT_HIGH(ta,tb); \
475 t0 = ta * tb; \
476 t2 = t1+t1; c2 += (t2<t1)?1:0; \
477 t1 = t0+t0; t2 += (t1<t0)?1:0; \
478 c0 += t1; t2 += (c0<t1)?1:0; \
479 c1 += t2; c2 += (c1<t2)?1:0; \
480 }
481
482#define sqr_add_c(a,i,c0,c1,c2) { \
483 BN_ULONG ta=(a)[i]; \
484 t1 = ta * ta; \
485 t2 = BN_UMULT_HIGH(ta,ta); \
486 c0 += t1; t2 += (c0<t1)?1:0; \
487 c1 += t2; c2 += (c1<t2)?1:0; \
488 }
489
490#define sqr_add_c2(a,i,j,c0,c1,c2) \
491 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
492
493#else /* !BN_LLONG */
494#define mul_add_c(a,b,c0,c1,c2) \
495 t1=LBITS(a); t2=HBITS(a); \
496 bl=LBITS(b); bh=HBITS(b); \
497 mul64(t1,t2,bl,bh); \
498 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
499 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
500
501#define mul_add_c2(a,b,c0,c1,c2) \
502 t1=LBITS(a); t2=HBITS(a); \
503 bl=LBITS(b); bh=HBITS(b); \
504 mul64(t1,t2,bl,bh); \
505 if (t2 & BN_TBIT) c2++; \
506 t2=(t2+t2)&BN_MASK2; \
507 if (t1 & BN_TBIT) t2++; \
508 t1=(t1+t1)&BN_MASK2; \
509 c0=(c0+t1)&BN_MASK2; \
510 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
511 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
512
513#define sqr_add_c(a,i,c0,c1,c2) \
514 sqr64(t1,t2,(a)[i]); \
515 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
516 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
517
518#define sqr_add_c2(a,i,j,c0,c1,c2) \
519 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
520#endif /* !BN_LLONG */
521
522void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
523 {
524#ifdef BN_LLONG
525 BN_ULLONG t;
526#else
527 BN_ULONG bl,bh;
528#endif
529 BN_ULONG t1,t2;
530 BN_ULONG c1,c2,c3;
531
532 c1=0;
533 c2=0;
534 c3=0;
535 mul_add_c(a[0],b[0],c1,c2,c3);
536 r[0]=c1;
537 c1=0;
538 mul_add_c(a[0],b[1],c2,c3,c1);
539 mul_add_c(a[1],b[0],c2,c3,c1);
540 r[1]=c2;
541 c2=0;
542 mul_add_c(a[2],b[0],c3,c1,c2);
543 mul_add_c(a[1],b[1],c3,c1,c2);
544 mul_add_c(a[0],b[2],c3,c1,c2);
545 r[2]=c3;
546 c3=0;
547 mul_add_c(a[0],b[3],c1,c2,c3);
548 mul_add_c(a[1],b[2],c1,c2,c3);
549 mul_add_c(a[2],b[1],c1,c2,c3);
550 mul_add_c(a[3],b[0],c1,c2,c3);
551 r[3]=c1;
552 c1=0;
553 mul_add_c(a[4],b[0],c2,c3,c1);
554 mul_add_c(a[3],b[1],c2,c3,c1);
555 mul_add_c(a[2],b[2],c2,c3,c1);
556 mul_add_c(a[1],b[3],c2,c3,c1);
557 mul_add_c(a[0],b[4],c2,c3,c1);
558 r[4]=c2;
559 c2=0;
560 mul_add_c(a[0],b[5],c3,c1,c2);
561 mul_add_c(a[1],b[4],c3,c1,c2);
562 mul_add_c(a[2],b[3],c3,c1,c2);
563 mul_add_c(a[3],b[2],c3,c1,c2);
564 mul_add_c(a[4],b[1],c3,c1,c2);
565 mul_add_c(a[5],b[0],c3,c1,c2);
566 r[5]=c3;
567 c3=0;
568 mul_add_c(a[6],b[0],c1,c2,c3);
569 mul_add_c(a[5],b[1],c1,c2,c3);
570 mul_add_c(a[4],b[2],c1,c2,c3);
571 mul_add_c(a[3],b[3],c1,c2,c3);
572 mul_add_c(a[2],b[4],c1,c2,c3);
573 mul_add_c(a[1],b[5],c1,c2,c3);
574 mul_add_c(a[0],b[6],c1,c2,c3);
575 r[6]=c1;
576 c1=0;
577 mul_add_c(a[0],b[7],c2,c3,c1);
578 mul_add_c(a[1],b[6],c2,c3,c1);
579 mul_add_c(a[2],b[5],c2,c3,c1);
580 mul_add_c(a[3],b[4],c2,c3,c1);
581 mul_add_c(a[4],b[3],c2,c3,c1);
582 mul_add_c(a[5],b[2],c2,c3,c1);
583 mul_add_c(a[6],b[1],c2,c3,c1);
584 mul_add_c(a[7],b[0],c2,c3,c1);
585 r[7]=c2;
586 c2=0;
587 mul_add_c(a[7],b[1],c3,c1,c2);
588 mul_add_c(a[6],b[2],c3,c1,c2);
589 mul_add_c(a[5],b[3],c3,c1,c2);
590 mul_add_c(a[4],b[4],c3,c1,c2);
591 mul_add_c(a[3],b[5],c3,c1,c2);
592 mul_add_c(a[2],b[6],c3,c1,c2);
593 mul_add_c(a[1],b[7],c3,c1,c2);
594 r[8]=c3;
595 c3=0;
596 mul_add_c(a[2],b[7],c1,c2,c3);
597 mul_add_c(a[3],b[6],c1,c2,c3);
598 mul_add_c(a[4],b[5],c1,c2,c3);
599 mul_add_c(a[5],b[4],c1,c2,c3);
600 mul_add_c(a[6],b[3],c1,c2,c3);
601 mul_add_c(a[7],b[2],c1,c2,c3);
602 r[9]=c1;
603 c1=0;
604 mul_add_c(a[7],b[3],c2,c3,c1);
605 mul_add_c(a[6],b[4],c2,c3,c1);
606 mul_add_c(a[5],b[5],c2,c3,c1);
607 mul_add_c(a[4],b[6],c2,c3,c1);
608 mul_add_c(a[3],b[7],c2,c3,c1);
609 r[10]=c2;
610 c2=0;
611 mul_add_c(a[4],b[7],c3,c1,c2);
612 mul_add_c(a[5],b[6],c3,c1,c2);
613 mul_add_c(a[6],b[5],c3,c1,c2);
614 mul_add_c(a[7],b[4],c3,c1,c2);
615 r[11]=c3;
616 c3=0;
617 mul_add_c(a[7],b[5],c1,c2,c3);
618 mul_add_c(a[6],b[6],c1,c2,c3);
619 mul_add_c(a[5],b[7],c1,c2,c3);
620 r[12]=c1;
621 c1=0;
622 mul_add_c(a[6],b[7],c2,c3,c1);
623 mul_add_c(a[7],b[6],c2,c3,c1);
624 r[13]=c2;
625 c2=0;
626 mul_add_c(a[7],b[7],c3,c1,c2);
627 r[14]=c3;
628 r[15]=c1;
629 }
630
631void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
632 {
633#ifdef BN_LLONG
634 BN_ULLONG t;
635#else
636 BN_ULONG bl,bh;
637#endif
638 BN_ULONG t1,t2;
639 BN_ULONG c1,c2,c3;
640
641 c1=0;
642 c2=0;
643 c3=0;
644 mul_add_c(a[0],b[0],c1,c2,c3);
645 r[0]=c1;
646 c1=0;
647 mul_add_c(a[0],b[1],c2,c3,c1);
648 mul_add_c(a[1],b[0],c2,c3,c1);
649 r[1]=c2;
650 c2=0;
651 mul_add_c(a[2],b[0],c3,c1,c2);
652 mul_add_c(a[1],b[1],c3,c1,c2);
653 mul_add_c(a[0],b[2],c3,c1,c2);
654 r[2]=c3;
655 c3=0;
656 mul_add_c(a[0],b[3],c1,c2,c3);
657 mul_add_c(a[1],b[2],c1,c2,c3);
658 mul_add_c(a[2],b[1],c1,c2,c3);
659 mul_add_c(a[3],b[0],c1,c2,c3);
660 r[3]=c1;
661 c1=0;
662 mul_add_c(a[3],b[1],c2,c3,c1);
663 mul_add_c(a[2],b[2],c2,c3,c1);
664 mul_add_c(a[1],b[3],c2,c3,c1);
665 r[4]=c2;
666 c2=0;
667 mul_add_c(a[2],b[3],c3,c1,c2);
668 mul_add_c(a[3],b[2],c3,c1,c2);
669 r[5]=c3;
670 c3=0;
671 mul_add_c(a[3],b[3],c1,c2,c3);
672 r[6]=c1;
673 r[7]=c2;
674 }
675
676void bn_sqr_comba8(BN_ULONG *r, const BN_ULONG *a)
677 {
678#ifdef BN_LLONG
679 BN_ULLONG t,tt;
680#else
681 BN_ULONG bl,bh;
682#endif
683 BN_ULONG t1,t2;
684 BN_ULONG c1,c2,c3;
685
686 c1=0;
687 c2=0;
688 c3=0;
689 sqr_add_c(a,0,c1,c2,c3);
690 r[0]=c1;
691 c1=0;
692 sqr_add_c2(a,1,0,c2,c3,c1);
693 r[1]=c2;
694 c2=0;
695 sqr_add_c(a,1,c3,c1,c2);
696 sqr_add_c2(a,2,0,c3,c1,c2);
697 r[2]=c3;
698 c3=0;
699 sqr_add_c2(a,3,0,c1,c2,c3);
700 sqr_add_c2(a,2,1,c1,c2,c3);
701 r[3]=c1;
702 c1=0;
703 sqr_add_c(a,2,c2,c3,c1);
704 sqr_add_c2(a,3,1,c2,c3,c1);
705 sqr_add_c2(a,4,0,c2,c3,c1);
706 r[4]=c2;
707 c2=0;
708 sqr_add_c2(a,5,0,c3,c1,c2);
709 sqr_add_c2(a,4,1,c3,c1,c2);
710 sqr_add_c2(a,3,2,c3,c1,c2);
711 r[5]=c3;
712 c3=0;
713 sqr_add_c(a,3,c1,c2,c3);
714 sqr_add_c2(a,4,2,c1,c2,c3);
715 sqr_add_c2(a,5,1,c1,c2,c3);
716 sqr_add_c2(a,6,0,c1,c2,c3);
717 r[6]=c1;
718 c1=0;
719 sqr_add_c2(a,7,0,c2,c3,c1);
720 sqr_add_c2(a,6,1,c2,c3,c1);
721 sqr_add_c2(a,5,2,c2,c3,c1);
722 sqr_add_c2(a,4,3,c2,c3,c1);
723 r[7]=c2;
724 c2=0;
725 sqr_add_c(a,4,c3,c1,c2);
726 sqr_add_c2(a,5,3,c3,c1,c2);
727 sqr_add_c2(a,6,2,c3,c1,c2);
728 sqr_add_c2(a,7,1,c3,c1,c2);
729 r[8]=c3;
730 c3=0;
731 sqr_add_c2(a,7,2,c1,c2,c3);
732 sqr_add_c2(a,6,3,c1,c2,c3);
733 sqr_add_c2(a,5,4,c1,c2,c3);
734 r[9]=c1;
735 c1=0;
736 sqr_add_c(a,5,c2,c3,c1);
737 sqr_add_c2(a,6,4,c2,c3,c1);
738 sqr_add_c2(a,7,3,c2,c3,c1);
739 r[10]=c2;
740 c2=0;
741 sqr_add_c2(a,7,4,c3,c1,c2);
742 sqr_add_c2(a,6,5,c3,c1,c2);
743 r[11]=c3;
744 c3=0;
745 sqr_add_c(a,6,c1,c2,c3);
746 sqr_add_c2(a,7,5,c1,c2,c3);
747 r[12]=c1;
748 c1=0;
749 sqr_add_c2(a,7,6,c2,c3,c1);
750 r[13]=c2;
751 c2=0;
752 sqr_add_c(a,7,c3,c1,c2);
753 r[14]=c3;
754 r[15]=c1;
755 }
756
757void bn_sqr_comba4(BN_ULONG *r, const BN_ULONG *a)
758 {
759#ifdef BN_LLONG
760 BN_ULLONG t,tt;
761#else
762 BN_ULONG bl,bh;
763#endif
764 BN_ULONG t1,t2;
765 BN_ULONG c1,c2,c3;
766
767 c1=0;
768 c2=0;
769 c3=0;
770 sqr_add_c(a,0,c1,c2,c3);
771 r[0]=c1;
772 c1=0;
773 sqr_add_c2(a,1,0,c2,c3,c1);
774 r[1]=c2;
775 c2=0;
776 sqr_add_c(a,1,c3,c1,c2);
777 sqr_add_c2(a,2,0,c3,c1,c2);
778 r[2]=c3;
779 c3=0;
780 sqr_add_c2(a,3,0,c1,c2,c3);
781 sqr_add_c2(a,2,1,c1,c2,c3);
782 r[3]=c1;
783 c1=0;
784 sqr_add_c(a,2,c2,c3,c1);
785 sqr_add_c2(a,3,1,c2,c3,c1);
786 r[4]=c2;
787 c2=0;
788 sqr_add_c2(a,3,2,c3,c1,c2);
789 r[5]=c3;
790 c3=0;
791 sqr_add_c(a,3,c1,c2,c3);
792 r[6]=c1;
793 r[7]=c2;
794 }
795#else /* !BN_MUL_COMBA */
796
797/* hmm... is it faster just to do a multiply? */
798#undef bn_sqr_comba4
799void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
800 {
801 BN_ULONG t[8];
802 bn_sqr_normal(r,a,4,t);
803 }
804
805#undef bn_sqr_comba8
806void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
807 {
808 BN_ULONG t[16];
809 bn_sqr_normal(r,a,8,t);
810 }
811
812void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
813 {
814 r[4]=bn_mul_words( &(r[0]),a,4,b[0]);
815 r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]);
816 r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]);
817 r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]);
818 }
819
820void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
821 {
822 r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
823 r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
824 r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
825 r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
826 r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
827 r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
828 r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
829 r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
830 }
831
832#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 2d287e6d1b..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 *)OPENSSL_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 OPENSSL_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 7daf19eb84..0000000000
--- a/src/lib/libcrypto/bn/bn_ctx.c
+++ /dev/null
@@ -1,155 +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
65#include "cryptlib.h"
66#include "bn_lcl.h"
67
68
69BN_CTX *BN_CTX_new(void)
70 {
71 BN_CTX *ret;
72
73 ret=(BN_CTX *)OPENSSL_malloc(sizeof(BN_CTX));
74 if (ret == NULL)
75 {
76 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
77 return(NULL);
78 }
79
80 BN_CTX_init(ret);
81 ret->flags=BN_FLG_MALLOCED;
82 return(ret);
83 }
84
85void BN_CTX_init(BN_CTX *ctx)
86 {
87#if 0 /* explicit version */
88 int i;
89 ctx->tos = 0;
90 ctx->flags = 0;
91 ctx->depth = 0;
92 ctx->too_many = 0;
93 for (i = 0; i < BN_CTX_NUM; i++)
94 BN_init(&(ctx->bn[i]));
95#else
96 memset(ctx, 0, sizeof *ctx);
97#endif
98 }
99
100void BN_CTX_free(BN_CTX *ctx)
101 {
102 int i;
103
104 if (ctx == NULL) return;
105 assert(ctx->depth == 0);
106
107 for (i=0; i < BN_CTX_NUM; i++)
108 BN_clear_free(&(ctx->bn[i]));
109 if (ctx->flags & BN_FLG_MALLOCED)
110 OPENSSL_free(ctx);
111 }
112
113void BN_CTX_start(BN_CTX *ctx)
114 {
115 if (ctx->depth < BN_CTX_NUM_POS)
116 ctx->pos[ctx->depth] = ctx->tos;
117 ctx->depth++;
118 }
119
120
121BIGNUM *BN_CTX_get(BN_CTX *ctx)
122 {
123 /* Note: If BN_CTX_get is ever changed to allocate BIGNUMs dynamically,
124 * make sure that if BN_CTX_get fails once it will return NULL again
125 * until BN_CTX_end is called. (This is so that callers have to check
126 * only the last return value.)
127 */
128 if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
129 {
130 if (!ctx->too_many)
131 {
132 BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
133 /* disable error code until BN_CTX_end is called: */
134 ctx->too_many = 1;
135 }
136 return NULL;
137 }
138 return (&(ctx->bn[ctx->tos++]));
139 }
140
141void BN_CTX_end(BN_CTX *ctx)
142 {
143 if (ctx == NULL) return;
144 assert(ctx->depth > 0);
145 if (ctx->depth == 0)
146 /* should never happen, but we can tolerate it if not in
147 * debug mode (could be a 'goto err' in the calling function
148 * before BN_CTX_start was reached) */
149 BN_CTX_start(ctx);
150
151 ctx->too_many = 0;
152 ctx->depth--;
153 if (ctx->depth < BN_CTX_NUM_POS)
154 ctx->tos = ctx->pos[ctx->depth];
155 }
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
deleted file mode 100644
index 580d1201bc..0000000000
--- a/src/lib/libcrypto/bn/bn_div.c
+++ /dev/null
@@ -1,387 +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
65/* The old slow way */
66#if 0
67int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
68 BN_CTX *ctx)
69 {
70 int i,nm,nd;
71 int ret = 0;
72 BIGNUM *D;
73
74 bn_check_top(m);
75 bn_check_top(d);
76 if (BN_is_zero(d))
77 {
78 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
79 return(0);
80 }
81
82 if (BN_ucmp(m,d) < 0)
83 {
84 if (rem != NULL)
85 { if (BN_copy(rem,m) == NULL) return(0); }
86 if (dv != NULL) BN_zero(dv);
87 return(1);
88 }
89
90 BN_CTX_start(ctx);
91 D = BN_CTX_get(ctx);
92 if (dv == NULL) dv = BN_CTX_get(ctx);
93 if (rem == NULL) rem = BN_CTX_get(ctx);
94 if (D == NULL || dv == NULL || rem == NULL)
95 goto end;
96
97 nd=BN_num_bits(d);
98 nm=BN_num_bits(m);
99 if (BN_copy(D,d) == NULL) goto end;
100 if (BN_copy(rem,m) == NULL) goto end;
101
102 /* The next 2 are needed so we can do a dv->d[0]|=1 later
103 * since BN_lshift1 will only work once there is a value :-) */
104 BN_zero(dv);
105 bn_wexpand(dv,1);
106 dv->top=1;
107
108 if (!BN_lshift(D,D,nm-nd)) goto end;
109 for (i=nm-nd; i>=0; i--)
110 {
111 if (!BN_lshift1(dv,dv)) goto end;
112 if (BN_ucmp(rem,D) >= 0)
113 {
114 dv->d[0]|=1;
115 if (!BN_usub(rem,rem,D)) goto end;
116 }
117/* CAN IMPROVE (and have now :=) */
118 if (!BN_rshift1(D,D)) goto end;
119 }
120 rem->neg=BN_is_zero(rem)?0:m->neg;
121 dv->neg=m->neg^d->neg;
122 ret = 1;
123 end:
124 BN_CTX_end(ctx);
125 return(ret);
126 }
127
128#else
129
130#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \
131 && !defined(PEDANTIC) && !defined(BN_DIV3W)
132# if defined(__GNUC__) && __GNUC__>=2
133# if defined(__i386) || defined (__i386__)
134 /*
135 * There were two reasons for implementing this template:
136 * - GNU C generates a call to a function (__udivdi3 to be exact)
137 * in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to
138 * understand why...);
139 * - divl doesn't only calculate quotient, but also leaves
140 * remainder in %edx which we can definitely use here:-)
141 *
142 * <appro@fy.chalmers.se>
143 */
144# define bn_div_words(n0,n1,d0) \
145 ({ asm volatile ( \
146 "divl %4" \
147 : "=a"(q), "=d"(rem) \
148 : "a"(n1), "d"(n0), "g"(d0) \
149 : "cc"); \
150 q; \
151 })
152# define REMAINDER_IS_ALREADY_CALCULATED
153# elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG)
154 /*
155 * Same story here, but it's 128-bit by 64-bit division. Wow!
156 * <appro@fy.chalmers.se>
157 */
158# define bn_div_words(n0,n1,d0) \
159 ({ asm volatile ( \
160 "divq %4" \
161 : "=a"(q), "=d"(rem) \
162 : "a"(n1), "d"(n0), "g"(d0) \
163 : "cc"); \
164 q; \
165 })
166# define REMAINDER_IS_ALREADY_CALCULATED
167# endif /* __<cpu> */
168# endif /* __GNUC__ */
169#endif /* OPENSSL_NO_ASM */
170
171
172/* BN_div computes dv := num / divisor, rounding towards zero, and sets up
173 * rm such that dv*divisor + rm = num holds.
174 * Thus:
175 * dv->neg == num->neg ^ divisor->neg (unless the result is zero)
176 * rm->neg == num->neg (unless the remainder is zero)
177 * If 'dv' or 'rm' is NULL, the respective value is not returned.
178 */
179int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
180 BN_CTX *ctx)
181 {
182 int norm_shift,i,j,loop;
183 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
184 BN_ULONG *resp,*wnump;
185 BN_ULONG d0,d1;
186 int num_n,div_n;
187
188 bn_check_top(num);
189 bn_check_top(divisor);
190
191 if (BN_is_zero(divisor))
192 {
193 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
194 return(0);
195 }
196
197 if (BN_ucmp(num,divisor) < 0)
198 {
199 if (rm != NULL)
200 { if (BN_copy(rm,num) == NULL) return(0); }
201 if (dv != NULL) BN_zero(dv);
202 return(1);
203 }
204
205 BN_CTX_start(ctx);
206 tmp=BN_CTX_get(ctx);
207 snum=BN_CTX_get(ctx);
208 sdiv=BN_CTX_get(ctx);
209 if (dv == NULL)
210 res=BN_CTX_get(ctx);
211 else res=dv;
212 if (sdiv == NULL || res == NULL) goto err;
213 tmp->neg=0;
214
215 /* First we normalise the numbers */
216 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
217 if (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;
218 sdiv->neg=0;
219 norm_shift+=BN_BITS2;
220 if (!(BN_lshift(snum,num,norm_shift))) goto err;
221 snum->neg=0;
222 div_n=sdiv->top;
223 num_n=snum->top;
224 loop=num_n-div_n;
225
226 /* Lets setup a 'window' into snum
227 * This is the part that corresponds to the current
228 * 'area' being divided */
229 BN_init(&wnum);
230 wnum.d= &(snum->d[loop]);
231 wnum.top= div_n;
232 wnum.dmax= snum->dmax+1; /* a bit of a lie */
233
234 /* Get the top 2 words of sdiv */
235 /* i=sdiv->top; */
236 d0=sdiv->d[div_n-1];
237 d1=(div_n == 1)?0:sdiv->d[div_n-2];
238
239 /* pointer to the 'top' of snum */
240 wnump= &(snum->d[num_n-1]);
241
242 /* Setup to 'res' */
243 res->neg= (num->neg^divisor->neg);
244 if (!bn_wexpand(res,(loop+1))) goto err;
245 res->top=loop;
246 resp= &(res->d[loop-1]);
247
248 /* space for temp */
249 if (!bn_wexpand(tmp,(div_n+1))) goto err;
250
251 if (BN_ucmp(&wnum,sdiv) >= 0)
252 {
253 if (!BN_usub(&wnum,&wnum,sdiv)) goto err;
254 *resp=1;
255 res->d[res->top-1]=1;
256 }
257 else
258 res->top--;
259 if (res->top == 0)
260 res->neg = 0;
261 resp--;
262
263 for (i=0; i<loop-1; i++)
264 {
265 BN_ULONG q,l0;
266#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)
267 BN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);
268 q=bn_div_3_words(wnump,d1,d0);
269#else
270 BN_ULONG n0,n1,rem=0;
271
272 n0=wnump[0];
273 n1=wnump[-1];
274 if (n0 == d0)
275 q=BN_MASK2;
276 else /* n0 < d0 */
277 {
278#ifdef BN_LLONG
279 BN_ULLONG t2;
280
281#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
282 q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);
283#else
284 q=bn_div_words(n0,n1,d0);
285#ifdef BN_DEBUG_LEVITTE
286 fprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\
287X) -> 0x%08X\n",
288 n0, n1, d0, q);
289#endif
290#endif
291
292#ifndef REMAINDER_IS_ALREADY_CALCULATED
293 /*
294 * rem doesn't have to be BN_ULLONG. The least we
295 * know it's less that d0, isn't it?
296 */
297 rem=(n1-q*d0)&BN_MASK2;
298#endif
299 t2=(BN_ULLONG)d1*q;
300
301 for (;;)
302 {
303 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
304 break;
305 q--;
306 rem += d0;
307 if (rem < d0) break; /* don't let rem overflow */
308 t2 -= d1;
309 }
310#else /* !BN_LLONG */
311 BN_ULONG t2l,t2h,ql,qh;
312
313 q=bn_div_words(n0,n1,d0);
314#ifdef BN_DEBUG_LEVITTE
315 fprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\
316X) -> 0x%08X\n",
317 n0, n1, d0, q);
318#endif
319#ifndef REMAINDER_IS_ALREADY_CALCULATED
320 rem=(n1-q*d0)&BN_MASK2;
321#endif
322
323#if defined(BN_UMULT_LOHI)
324 BN_UMULT_LOHI(t2l,t2h,d1,q);
325#elif defined(BN_UMULT_HIGH)
326 t2l = d1 * q;
327 t2h = BN_UMULT_HIGH(d1,q);
328#else
329 t2l=LBITS(d1); t2h=HBITS(d1);
330 ql =LBITS(q); qh =HBITS(q);
331 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
332#endif
333
334 for (;;)
335 {
336 if ((t2h < rem) ||
337 ((t2h == rem) && (t2l <= wnump[-2])))
338 break;
339 q--;
340 rem += d0;
341 if (rem < d0) break; /* don't let rem overflow */
342 if (t2l < d1) t2h--; t2l -= d1;
343 }
344#endif /* !BN_LLONG */
345 }
346#endif /* !BN_DIV3W */
347
348 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
349 wnum.d--; wnum.top++;
350 tmp->d[div_n]=l0;
351 for (j=div_n+1; j>0; j--)
352 if (tmp->d[j-1]) break;
353 tmp->top=j;
354
355 j=wnum.top;
356 if (!BN_sub(&wnum,&wnum,tmp)) goto err;
357
358 snum->top=snum->top+wnum.top-j;
359
360 if (wnum.neg)
361 {
362 q--;
363 j=wnum.top;
364 if (!BN_add(&wnum,&wnum,sdiv)) goto err;
365 snum->top+=wnum.top-j;
366 }
367 *(resp--)=q;
368 wnump--;
369 }
370 if (rm != NULL)
371 {
372 /* Keep a copy of the neg flag in num because if rm==num
373 * BN_rshift() will overwrite it.
374 */
375 int neg = num->neg;
376 BN_rshift(rm,snum,norm_shift);
377 if (!BN_is_zero(rm))
378 rm->neg = neg;
379 }
380 BN_CTX_end(ctx);
381 return(1);
382err:
383 BN_CTX_end(ctx);
384 return(0);
385 }
386
387#endif
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c
deleted file mode 100644
index 5dfac00c88..0000000000
--- a/src/lib/libcrypto/bn/bn_err.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/* crypto/bn/bn_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_BN,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BN,0,reason)
70
71static ERR_STRING_DATA BN_str_functs[]=
72 {
73{ERR_FUNC(BN_F_BN_BLINDING_CONVERT), "BN_BLINDING_convert"},
74{ERR_FUNC(BN_F_BN_BLINDING_INVERT), "BN_BLINDING_invert"},
75{ERR_FUNC(BN_F_BN_BLINDING_NEW), "BN_BLINDING_new"},
76{ERR_FUNC(BN_F_BN_BLINDING_UPDATE), "BN_BLINDING_update"},
77{ERR_FUNC(BN_F_BN_BN2DEC), "BN_bn2dec"},
78{ERR_FUNC(BN_F_BN_BN2HEX), "BN_bn2hex"},
79{ERR_FUNC(BN_F_BN_CTX_GET), "BN_CTX_get"},
80{ERR_FUNC(BN_F_BN_CTX_NEW), "BN_CTX_new"},
81{ERR_FUNC(BN_F_BN_DIV), "BN_div"},
82{ERR_FUNC(BN_F_BN_EXP), "BN_exp"},
83{ERR_FUNC(BN_F_BN_EXPAND2), "bn_expand2"},
84{ERR_FUNC(BN_F_BN_EXPAND_INTERNAL), "BN_EXPAND_INTERNAL"},
85{ERR_FUNC(BN_F_BN_MOD_EXP2_MONT), "BN_mod_exp2_mont"},
86{ERR_FUNC(BN_F_BN_MOD_EXP_MONT), "BN_mod_exp_mont"},
87{ERR_FUNC(BN_F_BN_MOD_EXP_MONT_CONSTTIME), "BN_mod_exp_mont_consttime"},
88{ERR_FUNC(BN_F_BN_MOD_EXP_MONT_WORD), "BN_mod_exp_mont_word"},
89{ERR_FUNC(BN_F_BN_MOD_EXP_RECP), "BN_mod_exp_recp"},
90{ERR_FUNC(BN_F_BN_MOD_EXP_SIMPLE), "BN_mod_exp_simple"},
91{ERR_FUNC(BN_F_BN_MOD_INVERSE), "BN_mod_inverse"},
92{ERR_FUNC(BN_F_BN_MOD_LSHIFT_QUICK), "BN_mod_lshift_quick"},
93{ERR_FUNC(BN_F_BN_MOD_MUL_RECIPROCAL), "BN_mod_mul_reciprocal"},
94{ERR_FUNC(BN_F_BN_MOD_SQRT), "BN_mod_sqrt"},
95{ERR_FUNC(BN_F_BN_MPI2BN), "BN_mpi2bn"},
96{ERR_FUNC(BN_F_BN_NEW), "BN_new"},
97{ERR_FUNC(BN_F_BN_RAND), "BN_rand"},
98{ERR_FUNC(BN_F_BN_RAND_RANGE), "BN_rand_range"},
99{ERR_FUNC(BN_F_BN_USUB), "BN_usub"},
100{0,NULL}
101 };
102
103static ERR_STRING_DATA BN_str_reasons[]=
104 {
105{ERR_REASON(BN_R_ARG2_LT_ARG3) ,"arg2 lt arg3"},
106{ERR_REASON(BN_R_BAD_RECIPROCAL) ,"bad reciprocal"},
107{ERR_REASON(BN_R_BIGNUM_TOO_LONG) ,"bignum too long"},
108{ERR_REASON(BN_R_CALLED_WITH_EVEN_MODULUS),"called with even modulus"},
109{ERR_REASON(BN_R_DIV_BY_ZERO) ,"div by zero"},
110{ERR_REASON(BN_R_ENCODING_ERROR) ,"encoding error"},
111{ERR_REASON(BN_R_EXPAND_ON_STATIC_BIGNUM_DATA),"expand on static bignum data"},
112{ERR_REASON(BN_R_INPUT_NOT_REDUCED) ,"input not reduced"},
113{ERR_REASON(BN_R_INVALID_LENGTH) ,"invalid length"},
114{ERR_REASON(BN_R_INVALID_RANGE) ,"invalid range"},
115{ERR_REASON(BN_R_NOT_A_SQUARE) ,"not a square"},
116{ERR_REASON(BN_R_NOT_INITIALIZED) ,"not initialized"},
117{ERR_REASON(BN_R_NO_INVERSE) ,"no inverse"},
118{ERR_REASON(BN_R_P_IS_NOT_PRIME) ,"p is not prime"},
119{ERR_REASON(BN_R_TOO_MANY_ITERATIONS) ,"too many iterations"},
120{ERR_REASON(BN_R_TOO_MANY_TEMPORARY_VARIABLES),"too many temporary variables"},
121{0,NULL}
122 };
123
124#endif
125
126void ERR_load_BN_strings(void)
127 {
128 static int init=1;
129
130 if (init)
131 {
132 init=0;
133#ifndef OPENSSL_NO_ERR
134 ERR_load_strings(0,BN_str_functs);
135 ERR_load_strings(0,BN_str_reasons);
136#endif
137
138 }
139 }
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
deleted file mode 100644
index 9e1e88abe8..0000000000
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ /dev/null
@@ -1,987 +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 * Copyright (c) 1998-2005 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
113#include "cryptlib.h"
114#include "bn_lcl.h"
115
116/* maximum precomputation table size for *variable* sliding windows */
117#define TABLE_SIZE 32
118
119/* this one works - simple but works */
120int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
121 {
122 int i,bits,ret=0;
123 BIGNUM *v,*rr;
124
125 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
126 {
127 /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
128 BNerr(BN_F_BN_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
129 return -1;
130 }
131
132 BN_CTX_start(ctx);
133 if ((r == a) || (r == p))
134 rr = BN_CTX_get(ctx);
135 else
136 rr = r;
137 if ((v = BN_CTX_get(ctx)) == NULL) goto err;
138
139 if (BN_copy(v,a) == NULL) goto err;
140 bits=BN_num_bits(p);
141
142 if (BN_is_odd(p))
143 { if (BN_copy(rr,a) == NULL) goto err; }
144 else { if (!BN_one(rr)) goto err; }
145
146 for (i=1; i<bits; i++)
147 {
148 if (!BN_sqr(v,v,ctx)) goto err;
149 if (BN_is_bit_set(p,i))
150 {
151 if (!BN_mul(rr,rr,v,ctx)) goto err;
152 }
153 }
154 ret=1;
155err:
156 if (r != rr) BN_copy(r,rr);
157 BN_CTX_end(ctx);
158 return(ret);
159 }
160
161
162int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
163 BN_CTX *ctx)
164 {
165 int ret;
166
167 bn_check_top(a);
168 bn_check_top(p);
169 bn_check_top(m);
170
171 /* For even modulus m = 2^k*m_odd, it might make sense to compute
172 * a^p mod m_odd and a^p mod 2^k separately (with Montgomery
173 * exponentiation for the odd part), using appropriate exponent
174 * reductions, and combine the results using the CRT.
175 *
176 * For now, we use Montgomery only if the modulus is odd; otherwise,
177 * exponentiation using the reciprocal-based quick remaindering
178 * algorithm is used.
179 *
180 * (Timing obtained with expspeed.c [computations a^p mod m
181 * where a, p, m are of the same length: 256, 512, 1024, 2048,
182 * 4096, 8192 bits], compared to the running time of the
183 * standard algorithm:
184 *
185 * BN_mod_exp_mont 33 .. 40 % [AMD K6-2, Linux, debug configuration]
186 * 55 .. 77 % [UltraSparc processor, but
187 * debug-solaris-sparcv8-gcc conf.]
188 *
189 * BN_mod_exp_recp 50 .. 70 % [AMD K6-2, Linux, debug configuration]
190 * 62 .. 118 % [UltraSparc, debug-solaris-sparcv8-gcc]
191 *
192 * On the Sparc, BN_mod_exp_recp was faster than BN_mod_exp_mont
193 * at 2048 and more bits, but at 512 and 1024 bits, it was
194 * slower even than the standard algorithm!
195 *
196 * "Real" timings [linux-elf, solaris-sparcv9-gcc configurations]
197 * should be obtained when the new Montgomery reduction code
198 * has been integrated into OpenSSL.)
199 */
200
201#define MONT_MUL_MOD
202#define MONT_EXP_WORD
203#define RECP_MUL_MOD
204
205#ifdef MONT_MUL_MOD
206 /* I have finally been able to take out this pre-condition of
207 * the top bit being set. It was caused by an error in BN_div
208 * with negatives. There was also another problem when for a^b%m
209 * a >= m. eay 07-May-97 */
210/* if ((m->d[m->top-1]&BN_TBIT) && BN_is_odd(m)) */
211
212 if (BN_is_odd(m))
213 {
214# ifdef MONT_EXP_WORD
215 if (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) == 0))
216 {
217 BN_ULONG A = a->d[0];
218 ret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);
219 }
220 else
221# endif
222 ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);
223 }
224 else
225#endif
226#ifdef RECP_MUL_MOD
227 { ret=BN_mod_exp_recp(r,a,p,m,ctx); }
228#else
229 { ret=BN_mod_exp_simple(r,a,p,m,ctx); }
230#endif
231
232 return(ret);
233 }
234
235
236int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
237 const BIGNUM *m, BN_CTX *ctx)
238 {
239 int i,j,bits,ret=0,wstart,wend,window,wvalue;
240 int start=1,ts=0;
241 BIGNUM *aa;
242 BIGNUM val[TABLE_SIZE];
243 BN_RECP_CTX recp;
244
245 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
246 {
247 /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
248 BNerr(BN_F_BN_MOD_EXP_RECP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
249 return -1;
250 }
251
252 bits=BN_num_bits(p);
253
254 if (bits == 0)
255 {
256 ret = BN_one(r);
257 return ret;
258 }
259
260 BN_CTX_start(ctx);
261 if ((aa = BN_CTX_get(ctx)) == NULL) goto err;
262
263 BN_RECP_CTX_init(&recp);
264 if (m->neg)
265 {
266 /* ignore sign of 'm' */
267 if (!BN_copy(aa, m)) goto err;
268 aa->neg = 0;
269 if (BN_RECP_CTX_set(&recp,aa,ctx) <= 0) goto err;
270 }
271 else
272 {
273 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;
274 }
275
276 BN_init(&(val[0]));
277 ts=1;
278
279 if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err; /* 1 */
280 if (BN_is_zero(&(val[0])))
281 {
282 ret = BN_zero(r);
283 goto err;
284 }
285
286 window = BN_window_bits_for_exponent_size(bits);
287 if (window > 1)
288 {
289 if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))
290 goto err; /* 2 */
291 j=1<<(window-1);
292 for (i=1; i<j; i++)
293 {
294 BN_init(&val[i]);
295 if (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))
296 goto err;
297 }
298 ts=i;
299 }
300
301 start=1; /* This is used to avoid multiplication etc
302 * when there is only the value '1' in the
303 * buffer. */
304 wvalue=0; /* The 'value' of the window */
305 wstart=bits-1; /* The top bit of the window */
306 wend=0; /* The bottom bit of the window */
307
308 if (!BN_one(r)) goto err;
309
310 for (;;)
311 {
312 if (BN_is_bit_set(p,wstart) == 0)
313 {
314 if (!start)
315 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
316 goto err;
317 if (wstart == 0) break;
318 wstart--;
319 continue;
320 }
321 /* We now have wstart on a 'set' bit, we now need to work out
322 * how bit a window to do. To do this we need to scan
323 * forward until the last set bit before the end of the
324 * window */
325 j=wstart;
326 wvalue=1;
327 wend=0;
328 for (i=1; i<window; i++)
329 {
330 if (wstart-i < 0) break;
331 if (BN_is_bit_set(p,wstart-i))
332 {
333 wvalue<<=(i-wend);
334 wvalue|=1;
335 wend=i;
336 }
337 }
338
339 /* wend is the size of the current window */
340 j=wend+1;
341 /* add the 'bytes above' */
342 if (!start)
343 for (i=0; i<j; i++)
344 {
345 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
346 goto err;
347 }
348
349 /* wvalue will be an odd number < 2^window */
350 if (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))
351 goto err;
352
353 /* move the 'window' down further */
354 wstart-=wend+1;
355 wvalue=0;
356 start=0;
357 if (wstart < 0) break;
358 }
359 ret=1;
360err:
361 BN_CTX_end(ctx);
362 for (i=0; i<ts; i++)
363 BN_clear_free(&(val[i]));
364 BN_RECP_CTX_free(&recp);
365 return(ret);
366 }
367
368
369int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
370 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
371 {
372 int i,j,bits,ret=0,wstart,wend,window,wvalue;
373 int start=1,ts=0;
374 BIGNUM *d,*r;
375 const BIGNUM *aa;
376 BIGNUM val[TABLE_SIZE];
377 BN_MONT_CTX *mont=NULL;
378
379 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
380 {
381 return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);
382 }
383
384 bn_check_top(a);
385 bn_check_top(p);
386 bn_check_top(m);
387
388 if (!(m->d[0] & 1))
389 {
390 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
391 return(0);
392 }
393 bits=BN_num_bits(p);
394 if (bits == 0)
395 {
396 ret = BN_one(rr);
397 return ret;
398 }
399
400 BN_CTX_start(ctx);
401 d = BN_CTX_get(ctx);
402 r = BN_CTX_get(ctx);
403 if (d == NULL || r == NULL) goto err;
404
405 /* If this is not done, things will break in the montgomery
406 * part */
407
408 if (in_mont != NULL)
409 mont=in_mont;
410 else
411 {
412 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
413 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
414 }
415
416 BN_init(&val[0]);
417 ts=1;
418 if (a->neg || BN_ucmp(a,m) >= 0)
419 {
420 if (!BN_nnmod(&(val[0]),a,m,ctx))
421 goto err;
422 aa= &(val[0]);
423 }
424 else
425 aa=a;
426 if (BN_is_zero(aa))
427 {
428 ret = BN_zero(rr);
429 goto err;
430 }
431 if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */
432
433 window = BN_window_bits_for_exponent_size(bits);
434 if (window > 1)
435 {
436 if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */
437 j=1<<(window-1);
438 for (i=1; i<j; i++)
439 {
440 BN_init(&(val[i]));
441 if (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))
442 goto err;
443 }
444 ts=i;
445 }
446
447 start=1; /* This is used to avoid multiplication etc
448 * when there is only the value '1' in the
449 * buffer. */
450 wvalue=0; /* The 'value' of the window */
451 wstart=bits-1; /* The top bit of the window */
452 wend=0; /* The bottom bit of the window */
453
454 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
455 for (;;)
456 {
457 if (BN_is_bit_set(p,wstart) == 0)
458 {
459 if (!start)
460 {
461 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
462 goto err;
463 }
464 if (wstart == 0) break;
465 wstart--;
466 continue;
467 }
468 /* We now have wstart on a 'set' bit, we now need to work out
469 * how bit a window to do. To do this we need to scan
470 * forward until the last set bit before the end of the
471 * window */
472 j=wstart;
473 wvalue=1;
474 wend=0;
475 for (i=1; i<window; i++)
476 {
477 if (wstart-i < 0) break;
478 if (BN_is_bit_set(p,wstart-i))
479 {
480 wvalue<<=(i-wend);
481 wvalue|=1;
482 wend=i;
483 }
484 }
485
486 /* wend is the size of the current window */
487 j=wend+1;
488 /* add the 'bytes above' */
489 if (!start)
490 for (i=0; i<j; i++)
491 {
492 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
493 goto err;
494 }
495
496 /* wvalue will be an odd number < 2^window */
497 if (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))
498 goto err;
499
500 /* move the 'window' down further */
501 wstart-=wend+1;
502 wvalue=0;
503 start=0;
504 if (wstart < 0) break;
505 }
506 if (!BN_from_montgomery(rr,r,mont,ctx)) goto err;
507 ret=1;
508err:
509 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
510 BN_CTX_end(ctx);
511 for (i=0; i<ts; i++)
512 BN_clear_free(&(val[i]));
513 return(ret);
514 }
515
516
517/* BN_mod_exp_mont_consttime() stores the precomputed powers in a specific layout
518 * so that accessing any of these table values shows the same access pattern as far
519 * as cache lines are concerned. The following functions are used to transfer a BIGNUM
520 * from/to that table. */
521
522static int MOD_EXP_CTIME_COPY_TO_PREBUF(BIGNUM *b, int top, unsigned char *buf, int idx, int width)
523 {
524 size_t i, j;
525
526 if (bn_wexpand(b, top) == NULL)
527 return 0;
528 while (b->top < top)
529 {
530 b->d[b->top++] = 0;
531 }
532
533 for (i = 0, j=idx; i < top * sizeof b->d[0]; i++, j+=width)
534 {
535 buf[j] = ((unsigned char*)b->d)[i];
536 }
537
538 bn_fix_top(b);
539 return 1;
540 }
541
542static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top, unsigned char *buf, int idx, int width)
543 {
544 size_t i, j;
545
546 if (bn_wexpand(b, top) == NULL)
547 return 0;
548
549 for (i=0, j=idx; i < top * sizeof b->d[0]; i++, j+=width)
550 {
551 ((unsigned char*)b->d)[i] = buf[j];
552 }
553
554 b->top = top;
555 bn_fix_top(b);
556 return 1;
557 }
558
559/* Given a pointer value, compute the next address that is a cache line multiple. */
560#define MOD_EXP_CTIME_ALIGN(x_) \
561 ((unsigned char*)(x_) + (MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH - (((BN_ULONG)(x_)) & (MOD_EXP_CTIME_MIN_CACHE_LINE_MASK))))
562
563/* This variant of BN_mod_exp_mont() uses fixed windows and the special
564 * precomputation memory layout to limit data-dependency to a minimum
565 * to protect secret exponents (cf. the hyper-threading timing attacks
566 * pointed out by Colin Percival,
567 * http://www.daemonology.net/hyperthreading-considered-harmful/)
568 */
569int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
570 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
571 {
572 int i,bits,ret=0,idx,window,wvalue;
573 int top;
574 BIGNUM *r;
575 const BIGNUM *aa;
576 BN_MONT_CTX *mont=NULL;
577
578 int numPowers;
579 unsigned char *powerbufFree=NULL;
580 int powerbufLen = 0;
581 unsigned char *powerbuf=NULL;
582 BIGNUM *computeTemp=NULL, *am=NULL;
583
584 bn_check_top(a);
585 bn_check_top(p);
586 bn_check_top(m);
587
588 top = m->top;
589
590 if (!(m->d[0] & 1))
591 {
592 BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME,BN_R_CALLED_WITH_EVEN_MODULUS);
593 return(0);
594 }
595 bits=BN_num_bits(p);
596 if (bits == 0)
597 {
598 ret = BN_one(rr);
599 return ret;
600 }
601
602 /* Initialize BIGNUM context and allocate intermediate result */
603 BN_CTX_start(ctx);
604 r = BN_CTX_get(ctx);
605 if (r == NULL) goto err;
606
607 /* Allocate a montgomery context if it was not supplied by the caller.
608 * If this is not done, things will break in the montgomery part.
609 */
610 if (in_mont != NULL)
611 mont=in_mont;
612 else
613 {
614 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
615 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
616 }
617
618 /* Get the window size to use with size of p. */
619 window = BN_window_bits_for_ctime_exponent_size(bits);
620
621 /* Allocate a buffer large enough to hold all of the pre-computed
622 * powers of a.
623 */
624 numPowers = 1 << window;
625 powerbufLen = sizeof(m->d[0])*top*numPowers;
626 if ((powerbufFree=(unsigned char*)OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)
627 goto err;
628
629 powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);
630 memset(powerbuf, 0, powerbufLen);
631
632 /* Initialize the intermediate result. Do this early to save double conversion,
633 * once each for a^0 and intermediate result.
634 */
635 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
636 if (!MOD_EXP_CTIME_COPY_TO_PREBUF(r, top, powerbuf, 0, numPowers)) goto err;
637
638 /* Initialize computeTemp as a^1 with montgomery precalcs */
639 computeTemp = BN_CTX_get(ctx);
640 am = BN_CTX_get(ctx);
641 if (computeTemp==NULL || am==NULL) goto err;
642
643 if (a->neg || BN_ucmp(a,m) >= 0)
644 {
645 if (!BN_mod(am,a,m,ctx))
646 goto err;
647 aa= am;
648 }
649 else
650 aa=a;
651 if (!BN_to_montgomery(am,aa,mont,ctx)) goto err;
652 if (!BN_copy(computeTemp, am)) goto err;
653 if (!MOD_EXP_CTIME_COPY_TO_PREBUF(am, top, powerbuf, 1, numPowers)) goto err;
654
655 /* If the window size is greater than 1, then calculate
656 * val[i=2..2^winsize-1]. Powers are computed as a*a^(i-1)
657 * (even powers could instead be computed as (a^(i/2))^2
658 * to use the slight performance advantage of sqr over mul).
659 */
660 if (window > 1)
661 {
662 for (i=2; i<numPowers; i++)
663 {
664 /* Calculate a^i = a^(i-1) * a */
665 if (!BN_mod_mul_montgomery(computeTemp,am,computeTemp,mont,ctx))
666 goto err;
667 if (!MOD_EXP_CTIME_COPY_TO_PREBUF(computeTemp, top, powerbuf, i, numPowers)) goto err;
668 }
669 }
670
671 /* Adjust the number of bits up to a multiple of the window size.
672 * If the exponent length is not a multiple of the window size, then
673 * this pads the most significant bits with zeros to normalize the
674 * scanning loop to there's no special cases.
675 *
676 * * NOTE: Making the window size a power of two less than the native
677 * * word size ensures that the padded bits won't go past the last
678 * * word in the internal BIGNUM structure. Going past the end will
679 * * still produce the correct result, but causes a different branch
680 * * to be taken in the BN_is_bit_set function.
681 */
682 bits = ((bits+window-1)/window)*window;
683 idx=bits-1; /* The top bit of the window */
684
685 /* Scan the exponent one window at a time starting from the most
686 * significant bits.
687 */
688 while (idx >= 0)
689 {
690 wvalue=0; /* The 'value' of the window */
691
692 /* Scan the window, squaring the result as we go */
693 for (i=0; i<window; i++,idx--)
694 {
695 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx)) goto err;
696 wvalue = (wvalue<<1)+BN_is_bit_set(p,idx);
697 }
698
699 /* Fetch the appropriate pre-computed value from the pre-buf */
700 if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(computeTemp, top, powerbuf, wvalue, numPowers)) goto err;
701
702 /* Multiply the result into the intermediate result */
703 if (!BN_mod_mul_montgomery(r,r,computeTemp,mont,ctx)) goto err;
704 }
705
706 /* Convert the final result from montgomery to standard format */
707 if (!BN_from_montgomery(rr,r,mont,ctx)) goto err;
708 ret=1;
709err:
710 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
711 if (powerbuf!=NULL)
712 {
713 OPENSSL_cleanse(powerbuf,powerbufLen);
714 OPENSSL_free(powerbufFree);
715 }
716 if (am!=NULL) BN_clear(am);
717 if (computeTemp!=NULL) BN_clear(computeTemp);
718 BN_CTX_end(ctx);
719 return(ret);
720 }
721
722int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
723 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
724 {
725 BN_MONT_CTX *mont = NULL;
726 int b, bits, ret=0;
727 int r_is_one;
728 BN_ULONG w, next_w;
729 BIGNUM *d, *r, *t;
730 BIGNUM *swap_tmp;
731#define BN_MOD_MUL_WORD(r, w, m) \
732 (BN_mul_word(r, (w)) && \
733 (/* BN_ucmp(r, (m)) < 0 ? 1 :*/ \
734 (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))
735 /* BN_MOD_MUL_WORD is only used with 'w' large,
736 * so the BN_ucmp test is probably more overhead
737 * than always using BN_mod (which uses BN_copy if
738 * a similar test returns true). */
739 /* We can use BN_mod and do not need BN_nnmod because our
740 * accumulator is never negative (the result of BN_mod does
741 * not depend on the sign of the modulus).
742 */
743#define BN_TO_MONTGOMERY_WORD(r, w, mont) \
744 (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))
745
746 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
747 {
748 /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
749 BNerr(BN_F_BN_MOD_EXP_MONT_WORD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
750 return -1;
751 }
752
753 bn_check_top(p);
754 bn_check_top(m);
755
756 if (m->top == 0 || !(m->d[0] & 1))
757 {
758 BNerr(BN_F_BN_MOD_EXP_MONT_WORD,BN_R_CALLED_WITH_EVEN_MODULUS);
759 return(0);
760 }
761 if (m->top == 1)
762 a %= m->d[0]; /* make sure that 'a' is reduced */
763
764 bits = BN_num_bits(p);
765 if (bits == 0)
766 {
767 ret = BN_one(rr);
768 return ret;
769 }
770 if (a == 0)
771 {
772 ret = BN_zero(rr);
773 return ret;
774 }
775
776 BN_CTX_start(ctx);
777 d = BN_CTX_get(ctx);
778 r = BN_CTX_get(ctx);
779 t = BN_CTX_get(ctx);
780 if (d == NULL || r == NULL || t == NULL) goto err;
781
782 if (in_mont != NULL)
783 mont=in_mont;
784 else
785 {
786 if ((mont = BN_MONT_CTX_new()) == NULL) goto err;
787 if (!BN_MONT_CTX_set(mont, m, ctx)) goto err;
788 }
789
790 r_is_one = 1; /* except for Montgomery factor */
791
792 /* bits-1 >= 0 */
793
794 /* The result is accumulated in the product r*w. */
795 w = a; /* bit 'bits-1' of 'p' is always set */
796 for (b = bits-2; b >= 0; b--)
797 {
798 /* First, square r*w. */
799 next_w = w*w;
800 if ((next_w/w) != w) /* overflow */
801 {
802 if (r_is_one)
803 {
804 if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;
805 r_is_one = 0;
806 }
807 else
808 {
809 if (!BN_MOD_MUL_WORD(r, w, m)) goto err;
810 }
811 next_w = 1;
812 }
813 w = next_w;
814 if (!r_is_one)
815 {
816 if (!BN_mod_mul_montgomery(r, r, r, mont, ctx)) goto err;
817 }
818
819 /* Second, multiply r*w by 'a' if exponent bit is set. */
820 if (BN_is_bit_set(p, b))
821 {
822 next_w = w*a;
823 if ((next_w/a) != w) /* overflow */
824 {
825 if (r_is_one)
826 {
827 if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;
828 r_is_one = 0;
829 }
830 else
831 {
832 if (!BN_MOD_MUL_WORD(r, w, m)) goto err;
833 }
834 next_w = a;
835 }
836 w = next_w;
837 }
838 }
839
840 /* Finally, set r:=r*w. */
841 if (w != 1)
842 {
843 if (r_is_one)
844 {
845 if (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;
846 r_is_one = 0;
847 }
848 else
849 {
850 if (!BN_MOD_MUL_WORD(r, w, m)) goto err;
851 }
852 }
853
854 if (r_is_one) /* can happen only if a == 1*/
855 {
856 if (!BN_one(rr)) goto err;
857 }
858 else
859 {
860 if (!BN_from_montgomery(rr, r, mont, ctx)) goto err;
861 }
862 ret = 1;
863err:
864 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
865 BN_CTX_end(ctx);
866 return(ret);
867 }
868
869
870/* The old fallback, simple version :-) */
871int BN_mod_exp_simple(BIGNUM *r,
872 const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
873 BN_CTX *ctx)
874 {
875 int i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;
876 int start=1;
877 BIGNUM *d;
878 BIGNUM val[TABLE_SIZE];
879
880 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
881 {
882 /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
883 BNerr(BN_F_BN_MOD_EXP_SIMPLE,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
884 return -1;
885 }
886
887 bits=BN_num_bits(p);
888
889 if (bits == 0)
890 {
891 ret = BN_one(r);
892 return ret;
893 }
894
895 BN_CTX_start(ctx);
896 if ((d = BN_CTX_get(ctx)) == NULL) goto err;
897
898 BN_init(&(val[0]));
899 ts=1;
900 if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err; /* 1 */
901 if (BN_is_zero(&(val[0])))
902 {
903 ret = BN_zero(r);
904 goto err;
905 }
906
907 window = BN_window_bits_for_exponent_size(bits);
908 if (window > 1)
909 {
910 if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))
911 goto err; /* 2 */
912 j=1<<(window-1);
913 for (i=1; i<j; i++)
914 {
915 BN_init(&(val[i]));
916 if (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))
917 goto err;
918 }
919 ts=i;
920 }
921
922 start=1; /* This is used to avoid multiplication etc
923 * when there is only the value '1' in the
924 * buffer. */
925 wvalue=0; /* The 'value' of the window */
926 wstart=bits-1; /* The top bit of the window */
927 wend=0; /* The bottom bit of the window */
928
929 if (!BN_one(r)) goto err;
930
931 for (;;)
932 {
933 if (BN_is_bit_set(p,wstart) == 0)
934 {
935 if (!start)
936 if (!BN_mod_mul(r,r,r,m,ctx))
937 goto err;
938 if (wstart == 0) break;
939 wstart--;
940 continue;
941 }
942 /* We now have wstart on a 'set' bit, we now need to work out
943 * how bit a window to do. To do this we need to scan
944 * forward until the last set bit before the end of the
945 * window */
946 j=wstart;
947 wvalue=1;
948 wend=0;
949 for (i=1; i<window; i++)
950 {
951 if (wstart-i < 0) break;
952 if (BN_is_bit_set(p,wstart-i))
953 {
954 wvalue<<=(i-wend);
955 wvalue|=1;
956 wend=i;
957 }
958 }
959
960 /* wend is the size of the current window */
961 j=wend+1;
962 /* add the 'bytes above' */
963 if (!start)
964 for (i=0; i<j; i++)
965 {
966 if (!BN_mod_mul(r,r,r,m,ctx))
967 goto err;
968 }
969
970 /* wvalue will be an odd number < 2^window */
971 if (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx))
972 goto err;
973
974 /* move the 'window' down further */
975 wstart-=wend+1;
976 wvalue=0;
977 start=0;
978 if (wstart < 0) break;
979 }
980 ret=1;
981err:
982 BN_CTX_end(ctx);
983 for (i=0; i<ts; i++)
984 BN_clear_free(&(val[i]));
985 return(ret);
986 }
987
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c
deleted file mode 100644
index 73ccd58a83..0000000000
--- a/src/lib/libcrypto/bn/bn_exp2.c
+++ /dev/null
@@ -1,313 +0,0 @@
1/* crypto/bn/bn_exp2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. 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 "cryptlib.h"
114#include "bn_lcl.h"
115
116#define TABLE_SIZE 32
117
118int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
119 const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,
120 BN_CTX *ctx, BN_MONT_CTX *in_mont)
121 {
122 int i,j,bits,b,bits1,bits2,ret=0,wpos1,wpos2,window1,window2,wvalue1,wvalue2;
123 int r_is_one=1,ts1=0,ts2=0;
124 BIGNUM *d,*r;
125 const BIGNUM *a_mod_m;
126 BIGNUM val1[TABLE_SIZE], val2[TABLE_SIZE];
127 BN_MONT_CTX *mont=NULL;
128
129 bn_check_top(a1);
130 bn_check_top(p1);
131 bn_check_top(a2);
132 bn_check_top(p2);
133 bn_check_top(m);
134
135 if (!(m->d[0] & 1))
136 {
137 BNerr(BN_F_BN_MOD_EXP2_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
138 return(0);
139 }
140 bits1=BN_num_bits(p1);
141 bits2=BN_num_bits(p2);
142 if ((bits1 == 0) && (bits2 == 0))
143 {
144 ret = BN_one(rr);
145 return ret;
146 }
147
148 bits=(bits1 > bits2)?bits1:bits2;
149
150 BN_CTX_start(ctx);
151 d = BN_CTX_get(ctx);
152 r = BN_CTX_get(ctx);
153 if (d == NULL || r == NULL) goto err;
154
155 if (in_mont != NULL)
156 mont=in_mont;
157 else
158 {
159 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
160 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
161 }
162
163 window1 = BN_window_bits_for_exponent_size(bits1);
164 window2 = BN_window_bits_for_exponent_size(bits2);
165
166 /*
167 * Build table for a1: val1[i] := a1^(2*i + 1) mod m for i = 0 .. 2^(window1-1)
168 */
169 BN_init(&val1[0]);
170 ts1=1;
171 if (a1->neg || BN_ucmp(a1,m) >= 0)
172 {
173 if (!BN_mod(&(val1[0]),a1,m,ctx))
174 goto err;
175 a_mod_m = &(val1[0]);
176 }
177 else
178 a_mod_m = a1;
179 if (BN_is_zero(a_mod_m))
180 {
181 ret = BN_zero(rr);
182 goto err;
183 }
184
185 if (!BN_to_montgomery(&(val1[0]),a_mod_m,mont,ctx)) goto err;
186 if (window1 > 1)
187 {
188 if (!BN_mod_mul_montgomery(d,&(val1[0]),&(val1[0]),mont,ctx)) goto err;
189
190 j=1<<(window1-1);
191 for (i=1; i<j; i++)
192 {
193 BN_init(&(val1[i]));
194 if (!BN_mod_mul_montgomery(&(val1[i]),&(val1[i-1]),d,mont,ctx))
195 goto err;
196 }
197 ts1=i;
198 }
199
200
201 /*
202 * Build table for a2: val2[i] := a2^(2*i + 1) mod m for i = 0 .. 2^(window2-1)
203 */
204 BN_init(&val2[0]);
205 ts2=1;
206 if (a2->neg || BN_ucmp(a2,m) >= 0)
207 {
208 if (!BN_mod(&(val2[0]),a2,m,ctx))
209 goto err;
210 a_mod_m = &(val2[0]);
211 }
212 else
213 a_mod_m = a2;
214 if (BN_is_zero(a_mod_m))
215 {
216 ret = BN_zero(rr);
217 goto err;
218 }
219 if (!BN_to_montgomery(&(val2[0]),a_mod_m,mont,ctx)) goto err;
220 if (window2 > 1)
221 {
222 if (!BN_mod_mul_montgomery(d,&(val2[0]),&(val2[0]),mont,ctx)) goto err;
223
224 j=1<<(window2-1);
225 for (i=1; i<j; i++)
226 {
227 BN_init(&(val2[i]));
228 if (!BN_mod_mul_montgomery(&(val2[i]),&(val2[i-1]),d,mont,ctx))
229 goto err;
230 }
231 ts2=i;
232 }
233
234
235 /* Now compute the power product, using independent windows. */
236 r_is_one=1;
237 wvalue1=0; /* The 'value' of the first window */
238 wvalue2=0; /* The 'value' of the second window */
239 wpos1=0; /* If wvalue1 > 0, the bottom bit of the first window */
240 wpos2=0; /* If wvalue2 > 0, the bottom bit of the second window */
241
242 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
243 for (b=bits-1; b>=0; b--)
244 {
245 if (!r_is_one)
246 {
247 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
248 goto err;
249 }
250
251 if (!wvalue1)
252 if (BN_is_bit_set(p1, b))
253 {
254 /* consider bits b-window1+1 .. b for this window */
255 i = b-window1+1;
256 while (!BN_is_bit_set(p1, i)) /* works for i<0 */
257 i++;
258 wpos1 = i;
259 wvalue1 = 1;
260 for (i = b-1; i >= wpos1; i--)
261 {
262 wvalue1 <<= 1;
263 if (BN_is_bit_set(p1, i))
264 wvalue1++;
265 }
266 }
267
268 if (!wvalue2)
269 if (BN_is_bit_set(p2, b))
270 {
271 /* consider bits b-window2+1 .. b for this window */
272 i = b-window2+1;
273 while (!BN_is_bit_set(p2, i))
274 i++;
275 wpos2 = i;
276 wvalue2 = 1;
277 for (i = b-1; i >= wpos2; i--)
278 {
279 wvalue2 <<= 1;
280 if (BN_is_bit_set(p2, i))
281 wvalue2++;
282 }
283 }
284
285 if (wvalue1 && b == wpos1)
286 {
287 /* wvalue1 is odd and < 2^window1 */
288 if (!BN_mod_mul_montgomery(r,r,&(val1[wvalue1>>1]),mont,ctx))
289 goto err;
290 wvalue1 = 0;
291 r_is_one = 0;
292 }
293
294 if (wvalue2 && b == wpos2)
295 {
296 /* wvalue2 is odd and < 2^window2 */
297 if (!BN_mod_mul_montgomery(r,r,&(val2[wvalue2>>1]),mont,ctx))
298 goto err;
299 wvalue2 = 0;
300 r_is_one = 0;
301 }
302 }
303 BN_from_montgomery(rr,r,mont,ctx);
304 ret=1;
305err:
306 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
307 BN_CTX_end(ctx);
308 for (i=0; i<ts1; i++)
309 BN_clear_free(&(val1[i]));
310 for (i=0; i<ts2; i++)
311 BN_clear_free(&(val2[i]));
312 return(ret);
313 }
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c
deleted file mode 100644
index 7649f63fd2..0000000000
--- a/src/lib/libcrypto/bn/bn_gcd.c
+++ /dev/null
@@ -1,490 +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 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "cryptlib.h"
113#include "bn_lcl.h"
114
115static BIGNUM *euclid(BIGNUM *a, BIGNUM *b);
116
117int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
118 {
119 BIGNUM *a,*b,*t;
120 int ret=0;
121
122 bn_check_top(in_a);
123 bn_check_top(in_b);
124
125 BN_CTX_start(ctx);
126 a = BN_CTX_get(ctx);
127 b = BN_CTX_get(ctx);
128 if (a == NULL || b == NULL) goto err;
129
130 if (BN_copy(a,in_a) == NULL) goto err;
131 if (BN_copy(b,in_b) == NULL) goto err;
132 a->neg = 0;
133 b->neg = 0;
134
135 if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; }
136 t=euclid(a,b);
137 if (t == NULL) goto err;
138
139 if (BN_copy(r,t) == NULL) goto err;
140 ret=1;
141err:
142 BN_CTX_end(ctx);
143 return(ret);
144 }
145
146static BIGNUM *euclid(BIGNUM *a, BIGNUM *b)
147 {
148 BIGNUM *t;
149 int shifts=0;
150
151 bn_check_top(a);
152 bn_check_top(b);
153
154 /* 0 <= b <= a */
155 while (!BN_is_zero(b))
156 {
157 /* 0 < b <= a */
158
159 if (BN_is_odd(a))
160 {
161 if (BN_is_odd(b))
162 {
163 if (!BN_sub(a,a,b)) goto err;
164 if (!BN_rshift1(a,a)) goto err;
165 if (BN_cmp(a,b) < 0)
166 { t=a; a=b; b=t; }
167 }
168 else /* a odd - b even */
169 {
170 if (!BN_rshift1(b,b)) goto err;
171 if (BN_cmp(a,b) < 0)
172 { t=a; a=b; b=t; }
173 }
174 }
175 else /* a is even */
176 {
177 if (BN_is_odd(b))
178 {
179 if (!BN_rshift1(a,a)) goto err;
180 if (BN_cmp(a,b) < 0)
181 { t=a; a=b; b=t; }
182 }
183 else /* a even - b even */
184 {
185 if (!BN_rshift1(a,a)) goto err;
186 if (!BN_rshift1(b,b)) goto err;
187 shifts++;
188 }
189 }
190 /* 0 <= b <= a */
191 }
192
193 if (shifts)
194 {
195 if (!BN_lshift(a,a,shifts)) goto err;
196 }
197 return(a);
198err:
199 return(NULL);
200 }
201
202
203/* solves ax == 1 (mod n) */
204BIGNUM *BN_mod_inverse(BIGNUM *in,
205 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
206 {
207 BIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;
208 BIGNUM *ret=NULL;
209 int sign;
210
211 bn_check_top(a);
212 bn_check_top(n);
213
214 BN_CTX_start(ctx);
215 A = BN_CTX_get(ctx);
216 B = BN_CTX_get(ctx);
217 X = BN_CTX_get(ctx);
218 D = BN_CTX_get(ctx);
219 M = BN_CTX_get(ctx);
220 Y = BN_CTX_get(ctx);
221 T = BN_CTX_get(ctx);
222 if (T == NULL) goto err;
223
224 if (in == NULL)
225 R=BN_new();
226 else
227 R=in;
228 if (R == NULL) goto err;
229
230 BN_one(X);
231 BN_zero(Y);
232 if (BN_copy(B,a) == NULL) goto err;
233 if (BN_copy(A,n) == NULL) goto err;
234 A->neg = 0;
235 if (B->neg || (BN_ucmp(B, A) >= 0))
236 {
237 if (!BN_nnmod(B, B, A, ctx)) goto err;
238 }
239 sign = -1;
240 /* From B = a mod |n|, A = |n| it follows that
241 *
242 * 0 <= B < A,
243 * -sign*X*a == B (mod |n|),
244 * sign*Y*a == A (mod |n|).
245 */
246
247 if (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))
248 {
249 /* Binary inversion algorithm; requires odd modulus.
250 * This is faster than the general algorithm if the modulus
251 * is sufficiently small (about 400 .. 500 bits on 32-bit
252 * sytems, but much more on 64-bit systems) */
253 int shift;
254
255 while (!BN_is_zero(B))
256 {
257 /*
258 * 0 < B < |n|,
259 * 0 < A <= |n|,
260 * (1) -sign*X*a == B (mod |n|),
261 * (2) sign*Y*a == A (mod |n|)
262 */
263
264 /* Now divide B by the maximum possible power of two in the integers,
265 * and divide X by the same value mod |n|.
266 * When we're done, (1) still holds. */
267 shift = 0;
268 while (!BN_is_bit_set(B, shift)) /* note that 0 < B */
269 {
270 shift++;
271
272 if (BN_is_odd(X))
273 {
274 if (!BN_uadd(X, X, n)) goto err;
275 }
276 /* now X is even, so we can easily divide it by two */
277 if (!BN_rshift1(X, X)) goto err;
278 }
279 if (shift > 0)
280 {
281 if (!BN_rshift(B, B, shift)) goto err;
282 }
283
284
285 /* Same for A and Y. Afterwards, (2) still holds. */
286 shift = 0;
287 while (!BN_is_bit_set(A, shift)) /* note that 0 < A */
288 {
289 shift++;
290
291 if (BN_is_odd(Y))
292 {
293 if (!BN_uadd(Y, Y, n)) goto err;
294 }
295 /* now Y is even */
296 if (!BN_rshift1(Y, Y)) goto err;
297 }
298 if (shift > 0)
299 {
300 if (!BN_rshift(A, A, shift)) goto err;
301 }
302
303
304 /* We still have (1) and (2).
305 * Both A and B are odd.
306 * The following computations ensure that
307 *
308 * 0 <= B < |n|,
309 * 0 < A < |n|,
310 * (1) -sign*X*a == B (mod |n|),
311 * (2) sign*Y*a == A (mod |n|),
312 *
313 * and that either A or B is even in the next iteration.
314 */
315 if (BN_ucmp(B, A) >= 0)
316 {
317 /* -sign*(X + Y)*a == B - A (mod |n|) */
318 if (!BN_uadd(X, X, Y)) goto err;
319 /* NB: we could use BN_mod_add_quick(X, X, Y, n), but that
320 * actually makes the algorithm slower */
321 if (!BN_usub(B, B, A)) goto err;
322 }
323 else
324 {
325 /* sign*(X + Y)*a == A - B (mod |n|) */
326 if (!BN_uadd(Y, Y, X)) goto err;
327 /* as above, BN_mod_add_quick(Y, Y, X, n) would slow things down */
328 if (!BN_usub(A, A, B)) goto err;
329 }
330 }
331 }
332 else
333 {
334 /* general inversion algorithm */
335
336 while (!BN_is_zero(B))
337 {
338 BIGNUM *tmp;
339
340 /*
341 * 0 < B < A,
342 * (*) -sign*X*a == B (mod |n|),
343 * sign*Y*a == A (mod |n|)
344 */
345
346 /* (D, M) := (A/B, A%B) ... */
347 if (BN_num_bits(A) == BN_num_bits(B))
348 {
349 if (!BN_one(D)) goto err;
350 if (!BN_sub(M,A,B)) goto err;
351 }
352 else if (BN_num_bits(A) == BN_num_bits(B) + 1)
353 {
354 /* A/B is 1, 2, or 3 */
355 if (!BN_lshift1(T,B)) goto err;
356 if (BN_ucmp(A,T) < 0)
357 {
358 /* A < 2*B, so D=1 */
359 if (!BN_one(D)) goto err;
360 if (!BN_sub(M,A,B)) goto err;
361 }
362 else
363 {
364 /* A >= 2*B, so D=2 or D=3 */
365 if (!BN_sub(M,A,T)) goto err;
366 if (!BN_add(D,T,B)) goto err; /* use D (:= 3*B) as temp */
367 if (BN_ucmp(A,D) < 0)
368 {
369 /* A < 3*B, so D=2 */
370 if (!BN_set_word(D,2)) goto err;
371 /* M (= A - 2*B) already has the correct value */
372 }
373 else
374 {
375 /* only D=3 remains */
376 if (!BN_set_word(D,3)) goto err;
377 /* currently M = A - 2*B, but we need M = A - 3*B */
378 if (!BN_sub(M,M,B)) goto err;
379 }
380 }
381 }
382 else
383 {
384 if (!BN_div(D,M,A,B,ctx)) goto err;
385 }
386
387 /* Now
388 * A = D*B + M;
389 * thus we have
390 * (**) sign*Y*a == D*B + M (mod |n|).
391 */
392
393 tmp=A; /* keep the BIGNUM object, the value does not matter */
394
395 /* (A, B) := (B, A mod B) ... */
396 A=B;
397 B=M;
398 /* ... so we have 0 <= B < A again */
399
400 /* Since the former M is now B and the former B is now A,
401 * (**) translates into
402 * sign*Y*a == D*A + B (mod |n|),
403 * i.e.
404 * sign*Y*a - D*A == B (mod |n|).
405 * Similarly, (*) translates into
406 * -sign*X*a == A (mod |n|).
407 *
408 * Thus,
409 * sign*Y*a + D*sign*X*a == B (mod |n|),
410 * i.e.
411 * sign*(Y + D*X)*a == B (mod |n|).
412 *
413 * So if we set (X, Y, sign) := (Y + D*X, X, -sign), we arrive back at
414 * -sign*X*a == B (mod |n|),
415 * sign*Y*a == A (mod |n|).
416 * Note that X and Y stay non-negative all the time.
417 */
418
419 /* most of the time D is very small, so we can optimize tmp := D*X+Y */
420 if (BN_is_one(D))
421 {
422 if (!BN_add(tmp,X,Y)) goto err;
423 }
424 else
425 {
426 if (BN_is_word(D,2))
427 {
428 if (!BN_lshift1(tmp,X)) goto err;
429 }
430 else if (BN_is_word(D,4))
431 {
432 if (!BN_lshift(tmp,X,2)) goto err;
433 }
434 else if (D->top == 1)
435 {
436 if (!BN_copy(tmp,X)) goto err;
437 if (!BN_mul_word(tmp,D->d[0])) goto err;
438 }
439 else
440 {
441 if (!BN_mul(tmp,D,X,ctx)) goto err;
442 }
443 if (!BN_add(tmp,tmp,Y)) goto err;
444 }
445
446 M=Y; /* keep the BIGNUM object, the value does not matter */
447 Y=X;
448 X=tmp;
449 sign = -sign;
450 }
451 }
452
453 /*
454 * The while loop (Euclid's algorithm) ends when
455 * A == gcd(a,n);
456 * we have
457 * sign*Y*a == A (mod |n|),
458 * where Y is non-negative.
459 */
460
461 if (sign < 0)
462 {
463 if (!BN_sub(Y,n,Y)) goto err;
464 }
465 /* Now Y*a == A (mod |n|). */
466
467
468 if (BN_is_one(A))
469 {
470 /* Y*a == 1 (mod |n|) */
471 if (!Y->neg && BN_ucmp(Y,n) < 0)
472 {
473 if (!BN_copy(R,Y)) goto err;
474 }
475 else
476 {
477 if (!BN_nnmod(R,Y,n,ctx)) goto err;
478 }
479 }
480 else
481 {
482 BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);
483 goto err;
484 }
485 ret=R;
486err:
487 if ((ret == NULL) && (in == NULL)) BN_free(R);
488 BN_CTX_end(ctx);
489 return(ret);
490 }
diff --git a/src/lib/libcrypto/bn/bn_kron.c b/src/lib/libcrypto/bn/bn_kron.c
deleted file mode 100644
index 49f75594ae..0000000000
--- a/src/lib/libcrypto/bn/bn_kron.c
+++ /dev/null
@@ -1,182 +0,0 @@
1/* crypto/bn/bn_kron.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "bn_lcl.h"
57
58
59/* least significant word */
60#define BN_lsw(n) (((n)->top == 0) ? (BN_ULONG) 0 : (n)->d[0])
61
62/* Returns -2 for errors because both -1 and 0 are valid results. */
63int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
64 {
65 int i;
66 int ret = -2; /* avoid 'uninitialized' warning */
67 int err = 0;
68 BIGNUM *A, *B, *tmp;
69 /* In 'tab', only odd-indexed entries are relevant:
70 * For any odd BIGNUM n,
71 * tab[BN_lsw(n) & 7]
72 * is $(-1)^{(n^2-1)/8}$ (using TeX notation).
73 * Note that the sign of n does not matter.
74 */
75 static const int tab[8] = {0, 1, 0, -1, 0, -1, 0, 1};
76
77 BN_CTX_start(ctx);
78 A = BN_CTX_get(ctx);
79 B = BN_CTX_get(ctx);
80 if (B == NULL) goto end;
81
82 err = !BN_copy(A, a);
83 if (err) goto end;
84 err = !BN_copy(B, b);
85 if (err) goto end;
86
87 /*
88 * Kronecker symbol, imlemented according to Henri Cohen,
89 * "A Course in Computational Algebraic Number Theory"
90 * (algorithm 1.4.10).
91 */
92
93 /* Cohen's step 1: */
94
95 if (BN_is_zero(B))
96 {
97 ret = BN_abs_is_word(A, 1);
98 goto end;
99 }
100
101 /* Cohen's step 2: */
102
103 if (!BN_is_odd(A) && !BN_is_odd(B))
104 {
105 ret = 0;
106 goto end;
107 }
108
109 /* now B is non-zero */
110 i = 0;
111 while (!BN_is_bit_set(B, i))
112 i++;
113 err = !BN_rshift(B, B, i);
114 if (err) goto end;
115 if (i & 1)
116 {
117 /* i is odd */
118 /* (thus B was even, thus A must be odd!) */
119
120 /* set 'ret' to $(-1)^{(A^2-1)/8}$ */
121 ret = tab[BN_lsw(A) & 7];
122 }
123 else
124 {
125 /* i is even */
126 ret = 1;
127 }
128
129 if (B->neg)
130 {
131 B->neg = 0;
132 if (A->neg)
133 ret = -ret;
134 }
135
136 /* now B is positive and odd, so what remains to be done is
137 * to compute the Jacobi symbol (A/B) and multiply it by 'ret' */
138
139 while (1)
140 {
141 /* Cohen's step 3: */
142
143 /* B is positive and odd */
144
145 if (BN_is_zero(A))
146 {
147 ret = BN_is_one(B) ? ret : 0;
148 goto end;
149 }
150
151 /* now A is non-zero */
152 i = 0;
153 while (!BN_is_bit_set(A, i))
154 i++;
155 err = !BN_rshift(A, A, i);
156 if (err) goto end;
157 if (i & 1)
158 {
159 /* i is odd */
160 /* multiply 'ret' by $(-1)^{(B^2-1)/8}$ */
161 ret = ret * tab[BN_lsw(B) & 7];
162 }
163
164 /* Cohen's step 4: */
165 /* multiply 'ret' by $(-1)^{(A-1)(B-1)/4}$ */
166 if ((A->neg ? ~BN_lsw(A) : BN_lsw(A)) & BN_lsw(B) & 2)
167 ret = -ret;
168
169 /* (A, B) := (B mod |A|, |A|) */
170 err = !BN_nnmod(B, B, A, ctx);
171 if (err) goto end;
172 tmp = A; A = B; B = tmp;
173 tmp->neg = 0;
174 }
175
176 end:
177 BN_CTX_end(ctx);
178 if (err)
179 return -2;
180 else
181 return ret;
182 }
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h
deleted file mode 100644
index a84998f2bd..0000000000
--- a/src/lib/libcrypto/bn/bn_lcl.h
+++ /dev/null
@@ -1,492 +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 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_BN_LCL_H
113#define HEADER_BN_LCL_H
114
115#include <openssl/bn.h>
116
117#ifdef __cplusplus
118extern "C" {
119#endif
120
121
122/* Used for temp variables */
123#define BN_CTX_NUM 32
124#define BN_CTX_NUM_POS 12
125struct bignum_ctx
126 {
127 int tos;
128 BIGNUM bn[BN_CTX_NUM];
129 int flags;
130 int depth;
131 int pos[BN_CTX_NUM_POS];
132 int too_many;
133 } /* BN_CTX */;
134
135
136/*
137 * BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions
138 *
139 *
140 * For window size 'w' (w >= 2) and a random 'b' bits exponent,
141 * the number of multiplications is a constant plus on average
142 *
143 * 2^(w-1) + (b-w)/(w+1);
144 *
145 * here 2^(w-1) is for precomputing the table (we actually need
146 * entries only for windows that have the lowest bit set), and
147 * (b-w)/(w+1) is an approximation for the expected number of
148 * w-bit windows, not counting the first one.
149 *
150 * Thus we should use
151 *
152 * w >= 6 if b > 671
153 * w = 5 if 671 > b > 239
154 * w = 4 if 239 > b > 79
155 * w = 3 if 79 > b > 23
156 * w <= 2 if 23 > b
157 *
158 * (with draws in between). Very small exponents are often selected
159 * with low Hamming weight, so we use w = 1 for b <= 23.
160 */
161#if 1
162#define BN_window_bits_for_exponent_size(b) \
163 ((b) > 671 ? 6 : \
164 (b) > 239 ? 5 : \
165 (b) > 79 ? 4 : \
166 (b) > 23 ? 3 : 1)
167#else
168/* Old SSLeay/OpenSSL table.
169 * Maximum window size was 5, so this table differs for b==1024;
170 * but it coincides for other interesting values (b==160, b==512).
171 */
172#define BN_window_bits_for_exponent_size(b) \
173 ((b) > 255 ? 5 : \
174 (b) > 127 ? 4 : \
175 (b) > 17 ? 3 : 1)
176#endif
177
178
179
180/* BN_mod_exp_mont_conttime is based on the assumption that the
181 * L1 data cache line width of the target processor is at least
182 * the following value.
183 */
184#define MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH ( 64 )
185#define MOD_EXP_CTIME_MIN_CACHE_LINE_MASK (MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH - 1)
186
187/* Window sizes optimized for fixed window size modular exponentiation
188 * algorithm (BN_mod_exp_mont_consttime).
189 *
190 * To achieve the security goals of BN_mode_exp_mont_consttime, the
191 * maximum size of the window must not exceed
192 * log_2(MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH).
193 *
194 * Window size thresholds are defined for cache line sizes of 32 and 64,
195 * cache line sizes where log_2(32)=5 and log_2(64)=6 respectively. A
196 * window size of 7 should only be used on processors that have a 128
197 * byte or greater cache line size.
198 */
199#if MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH == 64
200
201# define BN_window_bits_for_ctime_exponent_size(b) \
202 ((b) > 937 ? 6 : \
203 (b) > 306 ? 5 : \
204 (b) > 89 ? 4 : \
205 (b) > 22 ? 3 : 1)
206# define BN_MAX_WINDOW_BITS_FOR_CTIME_EXPONENT_SIZE (6)
207
208#elif MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH == 32
209
210# define BN_window_bits_for_ctime_exponent_size(b) \
211 ((b) > 306 ? 5 : \
212 (b) > 89 ? 4 : \
213 (b) > 22 ? 3 : 1)
214# define BN_MAX_WINDOW_BITS_FOR_CTIME_EXPONENT_SIZE (5)
215
216#endif
217
218
219/* Pentium pro 16,16,16,32,64 */
220/* Alpha 16,16,16,16.64 */
221#define BN_MULL_SIZE_NORMAL (16) /* 32 */
222#define BN_MUL_RECURSIVE_SIZE_NORMAL (16) /* 32 less than */
223#define BN_SQR_RECURSIVE_SIZE_NORMAL (16) /* 32 */
224#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */
225#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */
226
227#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
228/*
229 * BN_UMULT_HIGH section.
230 *
231 * No, I'm not trying to overwhelm you when stating that the
232 * product of N-bit numbers is 2*N bits wide:-) No, I don't expect
233 * you to be impressed when I say that if the compiler doesn't
234 * support 2*N integer type, then you have to replace every N*N
235 * multiplication with 4 (N/2)*(N/2) accompanied by some shifts
236 * and additions which unavoidably results in severe performance
237 * penalties. Of course provided that the hardware is capable of
238 * producing 2*N result... That's when you normally start
239 * considering assembler implementation. However! It should be
240 * pointed out that some CPUs (most notably Alpha, PowerPC and
241 * upcoming IA-64 family:-) provide *separate* instruction
242 * calculating the upper half of the product placing the result
243 * into a general purpose register. Now *if* the compiler supports
244 * inline assembler, then it's not impossible to implement the
245 * "bignum" routines (and have the compiler optimize 'em)
246 * exhibiting "native" performance in C. That's what BN_UMULT_HIGH
247 * macro is about:-)
248 *
249 * <appro@fy.chalmers.se>
250 */
251# if defined(__alpha) && (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT))
252# if defined(__DECC)
253# include <c_asm.h>
254# define BN_UMULT_HIGH(a,b) (BN_ULONG)asm("umulh %a0,%a1,%v0",(a),(b))
255# elif defined(__GNUC__)
256# define BN_UMULT_HIGH(a,b) ({ \
257 register BN_ULONG ret; \
258 asm ("umulh %1,%2,%0" \
259 : "=r"(ret) \
260 : "r"(a), "r"(b)); \
261 ret; })
262# endif /* compiler */
263# elif defined(_ARCH_PPC) && defined(__64BIT__) && defined(SIXTY_FOUR_BIT_LONG)
264# if defined(__GNUC__)
265# define BN_UMULT_HIGH(a,b) ({ \
266 register BN_ULONG ret; \
267 asm ("mulhdu %0,%1,%2" \
268 : "=r"(ret) \
269 : "r"(a), "r"(b)); \
270 ret; })
271# endif /* compiler */
272# elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG)
273# if defined(__GNUC__)
274# define BN_UMULT_HIGH(a,b) ({ \
275 register BN_ULONG ret,discard; \
276 asm ("mulq %3" \
277 : "=a"(discard),"=d"(ret) \
278 : "a"(a), "g"(b) \
279 : "cc"); \
280 ret; })
281# define BN_UMULT_LOHI(low,high,a,b) \
282 asm ("mulq %3" \
283 : "=a"(low),"=d"(high) \
284 : "a"(a),"g"(b) \
285 : "cc");
286# endif
287# endif /* cpu */
288#endif /* OPENSSL_NO_ASM */
289
290/*************************************************************
291 * Using the long long type
292 */
293#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
294#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
295
296/* This is used for internal error checking and is not normally used */
297#ifdef BN_DEBUG
298# include <assert.h>
299# define bn_check_top(a) assert ((a)->top >= 0 && (a)->top <= (a)->dmax);
300#else
301# define bn_check_top(a)
302#endif
303
304/* This macro is to add extra stuff for development checking */
305#ifdef BN_DEBUG
306#define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA))
307#else
308#define bn_set_max(r)
309#endif
310
311/* These macros are used to 'take' a section of a bignum for read only use */
312#define bn_set_low(r,a,n) \
313 { \
314 (r)->top=((a)->top > (n))?(n):(a)->top; \
315 (r)->d=(a)->d; \
316 (r)->neg=(a)->neg; \
317 (r)->flags|=BN_FLG_STATIC_DATA; \
318 bn_set_max(r); \
319 }
320
321#define bn_set_high(r,a,n) \
322 { \
323 if ((a)->top > (n)) \
324 { \
325 (r)->top=(a)->top-n; \
326 (r)->d= &((a)->d[n]); \
327 } \
328 else \
329 (r)->top=0; \
330 (r)->neg=(a)->neg; \
331 (r)->flags|=BN_FLG_STATIC_DATA; \
332 bn_set_max(r); \
333 }
334
335#ifdef BN_LLONG
336#define mul_add(r,a,w,c) { \
337 BN_ULLONG t; \
338 t=(BN_ULLONG)w * (a) + (r) + (c); \
339 (r)= Lw(t); \
340 (c)= Hw(t); \
341 }
342
343#define mul(r,a,w,c) { \
344 BN_ULLONG t; \
345 t=(BN_ULLONG)w * (a) + (c); \
346 (r)= Lw(t); \
347 (c)= Hw(t); \
348 }
349
350#define sqr(r0,r1,a) { \
351 BN_ULLONG t; \
352 t=(BN_ULLONG)(a)*(a); \
353 (r0)=Lw(t); \
354 (r1)=Hw(t); \
355 }
356
357#elif defined(BN_UMULT_HIGH)
358#define mul_add(r,a,w,c) { \
359 BN_ULONG high,low,ret,tmp=(a); \
360 ret = (r); \
361 high= BN_UMULT_HIGH(w,tmp); \
362 ret += (c); \
363 low = (w) * tmp; \
364 (c) = (ret<(c))?1:0; \
365 (c) += high; \
366 ret += low; \
367 (c) += (ret<low)?1:0; \
368 (r) = ret; \
369 }
370
371#define mul(r,a,w,c) { \
372 BN_ULONG high,low,ret,ta=(a); \
373 low = (w) * ta; \
374 high= BN_UMULT_HIGH(w,ta); \
375 ret = low + (c); \
376 (c) = high; \
377 (c) += (ret<low)?1:0; \
378 (r) = ret; \
379 }
380
381#define sqr(r0,r1,a) { \
382 BN_ULONG tmp=(a); \
383 (r0) = tmp * tmp; \
384 (r1) = BN_UMULT_HIGH(tmp,tmp); \
385 }
386
387#else
388/*************************************************************
389 * No long long type
390 */
391
392#define LBITS(a) ((a)&BN_MASK2l)
393#define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l)
394#define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2)
395
396#define LLBITS(a) ((a)&BN_MASKl)
397#define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl)
398#define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2)
399
400#define mul64(l,h,bl,bh) \
401 { \
402 BN_ULONG m,m1,lt,ht; \
403 \
404 lt=l; \
405 ht=h; \
406 m =(bh)*(lt); \
407 lt=(bl)*(lt); \
408 m1=(bl)*(ht); \
409 ht =(bh)*(ht); \
410 m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS((BN_ULONG)1); \
411 ht+=HBITS(m); \
412 m1=L2HBITS(m); \
413 lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \
414 (l)=lt; \
415 (h)=ht; \
416 }
417
418#define sqr64(lo,ho,in) \
419 { \
420 BN_ULONG l,h,m; \
421 \
422 h=(in); \
423 l=LBITS(h); \
424 h=HBITS(h); \
425 m =(l)*(h); \
426 l*=l; \
427 h*=h; \
428 h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \
429 m =(m&BN_MASK2l)<<(BN_BITS4+1); \
430 l=(l+m)&BN_MASK2; if (l < m) h++; \
431 (lo)=l; \
432 (ho)=h; \
433 }
434
435#define mul_add(r,a,bl,bh,c) { \
436 BN_ULONG l,h; \
437 \
438 h= (a); \
439 l=LBITS(h); \
440 h=HBITS(h); \
441 mul64(l,h,(bl),(bh)); \
442 \
443 /* non-multiply part */ \
444 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
445 (c)=(r); \
446 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
447 (c)=h&BN_MASK2; \
448 (r)=l; \
449 }
450
451#define mul(r,a,bl,bh,c) { \
452 BN_ULONG l,h; \
453 \
454 h= (a); \
455 l=LBITS(h); \
456 h=HBITS(h); \
457 mul64(l,h,(bl),(bh)); \
458 \
459 /* non-multiply part */ \
460 l+=(c); if ((l&BN_MASK2) < (c)) h++; \
461 (c)=h&BN_MASK2; \
462 (r)=l&BN_MASK2; \
463 }
464#endif /* !BN_LLONG */
465
466void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb);
467void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
468void bn_mul_comba4(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
469void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp);
470void bn_sqr_comba8(BN_ULONG *r,const BN_ULONG *a);
471void bn_sqr_comba4(BN_ULONG *r,const BN_ULONG *a);
472int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n);
473int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
474 int cl, int dl);
475#ifdef BN_RECURSION
476void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
477 BN_ULONG *t);
478void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
479 int n, BN_ULONG *t);
480void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,
481 BN_ULONG *t);
482void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2,
483 BN_ULONG *t);
484void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t);
485#endif
486void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n);
487
488#ifdef __cplusplus
489}
490#endif
491
492#endif
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
deleted file mode 100644
index e1660450bc..0000000000
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ /dev/null
@@ -1,824 +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#ifndef BN_DEBUG
60# undef NDEBUG /* avoid conflicting definitions */
61# define NDEBUG
62#endif
63
64#include <assert.h>
65#include <limits.h>
66#include <stdio.h>
67#include "cryptlib.h"
68#include "bn_lcl.h"
69
70const char *BN_version="Big Number" OPENSSL_VERSION_PTEXT;
71
72/* For a 32 bit machine
73 * 2 - 4 == 128
74 * 3 - 8 == 256
75 * 4 - 16 == 512
76 * 5 - 32 == 1024
77 * 6 - 64 == 2048
78 * 7 - 128 == 4096
79 * 8 - 256 == 8192
80 */
81static int bn_limit_bits=0;
82static int bn_limit_num=8; /* (1<<bn_limit_bits) */
83static int bn_limit_bits_low=0;
84static int bn_limit_num_low=8; /* (1<<bn_limit_bits_low) */
85static int bn_limit_bits_high=0;
86static int bn_limit_num_high=8; /* (1<<bn_limit_bits_high) */
87static int bn_limit_bits_mont=0;
88static int bn_limit_num_mont=8; /* (1<<bn_limit_bits_mont) */
89
90void BN_set_params(int mult, int high, int low, int mont)
91 {
92 if (mult >= 0)
93 {
94 if (mult > (sizeof(int)*8)-1)
95 mult=sizeof(int)*8-1;
96 bn_limit_bits=mult;
97 bn_limit_num=1<<mult;
98 }
99 if (high >= 0)
100 {
101 if (high > (sizeof(int)*8)-1)
102 high=sizeof(int)*8-1;
103 bn_limit_bits_high=high;
104 bn_limit_num_high=1<<high;
105 }
106 if (low >= 0)
107 {
108 if (low > (sizeof(int)*8)-1)
109 low=sizeof(int)*8-1;
110 bn_limit_bits_low=low;
111 bn_limit_num_low=1<<low;
112 }
113 if (mont >= 0)
114 {
115 if (mont > (sizeof(int)*8)-1)
116 mont=sizeof(int)*8-1;
117 bn_limit_bits_mont=mont;
118 bn_limit_num_mont=1<<mont;
119 }
120 }
121
122int BN_get_params(int which)
123 {
124 if (which == 0) return(bn_limit_bits);
125 else if (which == 1) return(bn_limit_bits_high);
126 else if (which == 2) return(bn_limit_bits_low);
127 else if (which == 3) return(bn_limit_bits_mont);
128 else return(0);
129 }
130
131const BIGNUM *BN_value_one(void)
132 {
133 static BN_ULONG data_one=1L;
134 static BIGNUM const_one={&data_one,1,1,0};
135
136 return(&const_one);
137 }
138
139char *BN_options(void)
140 {
141 static int init=0;
142 static char data[16];
143
144 if (!init)
145 {
146 init++;
147#ifdef BN_LLONG
148 BIO_snprintf(data,sizeof data,"bn(%d,%d)",
149 (int)sizeof(BN_ULLONG)*8,(int)sizeof(BN_ULONG)*8);
150#else
151 BIO_snprintf(data,sizeof data,"bn(%d,%d)",
152 (int)sizeof(BN_ULONG)*8,(int)sizeof(BN_ULONG)*8);
153#endif
154 }
155 return(data);
156 }
157
158int BN_num_bits_word(BN_ULONG l)
159 {
160 static const char bits[256]={
161 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
162 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
163 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
164 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
165 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
166 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
167 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
168 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
169 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
170 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
171 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
172 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
173 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
174 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
175 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
176 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
177 };
178
179#if defined(SIXTY_FOUR_BIT_LONG)
180 if (l & 0xffffffff00000000L)
181 {
182 if (l & 0xffff000000000000L)
183 {
184 if (l & 0xff00000000000000L)
185 {
186 return(bits[(int)(l>>56)]+56);
187 }
188 else return(bits[(int)(l>>48)]+48);
189 }
190 else
191 {
192 if (l & 0x0000ff0000000000L)
193 {
194 return(bits[(int)(l>>40)]+40);
195 }
196 else return(bits[(int)(l>>32)]+32);
197 }
198 }
199 else
200#else
201#ifdef SIXTY_FOUR_BIT
202 if (l & 0xffffffff00000000LL)
203 {
204 if (l & 0xffff000000000000LL)
205 {
206 if (l & 0xff00000000000000LL)
207 {
208 return(bits[(int)(l>>56)]+56);
209 }
210 else return(bits[(int)(l>>48)]+48);
211 }
212 else
213 {
214 if (l & 0x0000ff0000000000LL)
215 {
216 return(bits[(int)(l>>40)]+40);
217 }
218 else return(bits[(int)(l>>32)]+32);
219 }
220 }
221 else
222#endif
223#endif
224 {
225#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
226 if (l & 0xffff0000L)
227 {
228 if (l & 0xff000000L)
229 return(bits[(int)(l>>24L)]+24);
230 else return(bits[(int)(l>>16L)]+16);
231 }
232 else
233#endif
234 {
235#if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
236 if (l & 0xff00L)
237 return(bits[(int)(l>>8)]+8);
238 else
239#endif
240 return(bits[(int)(l )] );
241 }
242 }
243 }
244
245int BN_num_bits(const BIGNUM *a)
246 {
247 BN_ULONG l;
248 int i;
249
250 bn_check_top(a);
251
252 if (a->top == 0) return(0);
253 l=a->d[a->top-1];
254 assert(l != 0);
255 i=(a->top-1)*BN_BITS2;
256 return(i+BN_num_bits_word(l));
257 }
258
259void BN_clear_free(BIGNUM *a)
260 {
261 int i;
262
263 if (a == NULL) return;
264 if (a->d != NULL)
265 {
266 OPENSSL_cleanse(a->d,a->dmax*sizeof(a->d[0]));
267 if (!(BN_get_flags(a,BN_FLG_STATIC_DATA)))
268 OPENSSL_free(a->d);
269 }
270 i=BN_get_flags(a,BN_FLG_MALLOCED);
271 OPENSSL_cleanse(a,sizeof(BIGNUM));
272 if (i)
273 OPENSSL_free(a);
274 }
275
276void BN_free(BIGNUM *a)
277 {
278 if (a == NULL) return;
279 if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA)))
280 OPENSSL_free(a->d);
281 a->flags|=BN_FLG_FREE; /* REMOVE? */
282 if (a->flags & BN_FLG_MALLOCED)
283 OPENSSL_free(a);
284 }
285
286void BN_init(BIGNUM *a)
287 {
288 memset(a,0,sizeof(BIGNUM));
289 }
290
291BIGNUM *BN_new(void)
292 {
293 BIGNUM *ret;
294
295 if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)
296 {
297 BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
298 return(NULL);
299 }
300 ret->flags=BN_FLG_MALLOCED;
301 ret->top=0;
302 ret->neg=0;
303 ret->dmax=0;
304 ret->d=NULL;
305 return(ret);
306 }
307
308/* This is used both by bn_expand2() and bn_dup_expand() */
309/* The caller MUST check that words > b->dmax before calling this */
310static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
311 {
312 BN_ULONG *A,*a = NULL;
313 const BN_ULONG *B;
314 int i;
315
316 if (words > (INT_MAX/(4*BN_BITS2)))
317 {
318 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_BIGNUM_TOO_LONG);
319 return NULL;
320 }
321
322 bn_check_top(b);
323 if (BN_get_flags(b,BN_FLG_STATIC_DATA))
324 {
325 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
326 return(NULL);
327 }
328 a=A=(BN_ULONG *)OPENSSL_malloc(sizeof(BN_ULONG)*(words+1));
329 if (A == NULL)
330 {
331 BNerr(BN_F_BN_EXPAND_INTERNAL,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 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
340 {
341 /*
342 * The fact that the loop is unrolled
343 * 4-wise is a tribute to Intel. It's
344 * the one that doesn't have enough
345 * registers to accomodate more data.
346 * I'd unroll it 8-wise otherwise:-)
347 *
348 * <appro@fy.chalmers.se>
349 */
350 BN_ULONG a0,a1,a2,a3;
351 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
352 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
353 }
354 switch (b->top&3)
355 {
356 case 3: A[2]=B[2];
357 case 2: A[1]=B[1];
358 case 1: A[0]=B[0];
359 case 0: /* workaround for ultrix cc: without 'case 0', the optimizer does
360 * the switch table by doing a=top&3; a--; goto jump_table[a];
361 * which fails for top== 0 */
362 ;
363 }
364 }
365
366 /* Now need to zero any data between b->top and b->max */
367 /* XXX Why? */
368
369 A= &(a[b->top]);
370 for (i=(words - b->top)>>3; i>0; i--,A+=8)
371 {
372 A[0]=0; A[1]=0; A[2]=0; A[3]=0;
373 A[4]=0; A[5]=0; A[6]=0; A[7]=0;
374 }
375 for (i=(words - b->top)&7; i>0; i--,A++)
376 A[0]=0;
377#else
378 memset(A,0,sizeof(BN_ULONG)*(words+1));
379 memcpy(A,b->d,sizeof(b->d[0])*b->top);
380#endif
381
382 return(a);
383 }
384
385/* This is an internal function that can be used instead of bn_expand2()
386 * when there is a need to copy BIGNUMs instead of only expanding the
387 * data part, while still expanding them.
388 * Especially useful when needing to expand BIGNUMs that are declared
389 * 'const' and should therefore not be changed.
390 * The reason to use this instead of a BN_dup() followed by a bn_expand2()
391 * is memory allocation overhead. A BN_dup() followed by a bn_expand2()
392 * will allocate new memory for the BIGNUM data twice, and free it once,
393 * while bn_dup_expand() makes sure allocation is made only once.
394 */
395
396BIGNUM *bn_dup_expand(const BIGNUM *b, int words)
397 {
398 BIGNUM *r = NULL;
399
400 /* This function does not work if
401 * words <= b->dmax && top < words
402 * because BN_dup() does not preserve 'dmax'!
403 * (But bn_dup_expand() is not used anywhere yet.)
404 */
405
406 if (words > b->dmax)
407 {
408 BN_ULONG *a = bn_expand_internal(b, words);
409
410 if (a)
411 {
412 r = BN_new();
413 if (r)
414 {
415 r->top = b->top;
416 r->dmax = words;
417 r->neg = b->neg;
418 r->d = a;
419 }
420 else
421 {
422 /* r == NULL, BN_new failure */
423 OPENSSL_free(a);
424 }
425 }
426 /* If a == NULL, there was an error in allocation in
427 bn_expand_internal(), and NULL should be returned */
428 }
429 else
430 {
431 r = BN_dup(b);
432 }
433
434 return r;
435 }
436
437/* This is an internal function that should not be used in applications.
438 * It ensures that 'b' has enough room for a 'words' word number number.
439 * It is mostly used by the various BIGNUM routines. If there is an error,
440 * NULL is returned. If not, 'b' is returned. */
441
442BIGNUM *bn_expand2(BIGNUM *b, int words)
443 {
444 if (words > b->dmax)
445 {
446 BN_ULONG *a = bn_expand_internal(b, words);
447
448 if (a)
449 {
450 if (b->d)
451 OPENSSL_free(b->d);
452 b->d=a;
453 b->dmax=words;
454 }
455 else
456 b = NULL;
457 }
458 return b;
459 }
460
461BIGNUM *BN_dup(const BIGNUM *a)
462 {
463 BIGNUM *r, *t;
464
465 if (a == NULL) return NULL;
466
467 bn_check_top(a);
468
469 t = BN_new();
470 if (t == NULL) return(NULL);
471 r = BN_copy(t, a);
472 /* now r == t || r == NULL */
473 if (r == NULL)
474 BN_free(t);
475 return r;
476 }
477
478BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
479 {
480 int i;
481 BN_ULONG *A;
482 const BN_ULONG *B;
483
484 bn_check_top(b);
485
486 if (a == b) return(a);
487 if (bn_wexpand(a,b->top) == NULL) return(NULL);
488
489#if 1
490 A=a->d;
491 B=b->d;
492 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
493 {
494 BN_ULONG a0,a1,a2,a3;
495 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
496 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
497 }
498 switch (b->top&3)
499 {
500 case 3: A[2]=B[2];
501 case 2: A[1]=B[1];
502 case 1: A[0]=B[0];
503 case 0: ; /* ultrix cc workaround, see comments in bn_expand_internal */
504 }
505#else
506 memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
507#endif
508
509/* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/
510 a->top=b->top;
511 if ((a->top == 0) && (a->d != NULL))
512 a->d[0]=0;
513 a->neg=b->neg;
514 return(a);
515 }
516
517void BN_swap(BIGNUM *a, BIGNUM *b)
518 {
519 int flags_old_a, flags_old_b;
520 BN_ULONG *tmp_d;
521 int tmp_top, tmp_dmax, tmp_neg;
522
523 flags_old_a = a->flags;
524 flags_old_b = b->flags;
525
526 tmp_d = a->d;
527 tmp_top = a->top;
528 tmp_dmax = a->dmax;
529 tmp_neg = a->neg;
530
531 a->d = b->d;
532 a->top = b->top;
533 a->dmax = b->dmax;
534 a->neg = b->neg;
535
536 b->d = tmp_d;
537 b->top = tmp_top;
538 b->dmax = tmp_dmax;
539 b->neg = tmp_neg;
540
541 a->flags = (flags_old_a & BN_FLG_MALLOCED) | (flags_old_b & BN_FLG_STATIC_DATA);
542 b->flags = (flags_old_b & BN_FLG_MALLOCED) | (flags_old_a & BN_FLG_STATIC_DATA);
543 }
544
545
546void BN_clear(BIGNUM *a)
547 {
548 if (a->d != NULL)
549 memset(a->d,0,a->dmax*sizeof(a->d[0]));
550 a->top=0;
551 a->neg=0;
552 }
553
554BN_ULONG BN_get_word(const BIGNUM *a)
555 {
556 int i,n;
557 BN_ULONG ret=0;
558
559 n=BN_num_bytes(a);
560 if (n > sizeof(BN_ULONG))
561 return(BN_MASK2);
562 for (i=a->top-1; i>=0; i--)
563 {
564#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
565 ret<<=BN_BITS4; /* stops the compiler complaining */
566 ret<<=BN_BITS4;
567#else
568 ret=0;
569#endif
570 ret|=a->d[i];
571 }
572 return(ret);
573 }
574
575int BN_set_word(BIGNUM *a, BN_ULONG w)
576 {
577 int i,n;
578 if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);
579
580 n=sizeof(BN_ULONG)/BN_BYTES;
581 a->neg=0;
582 a->top=0;
583 a->d[0]=(BN_ULONG)w&BN_MASK2;
584 if (a->d[0] != 0) a->top=1;
585 for (i=1; i<n; i++)
586 {
587 /* the following is done instead of
588 * w>>=BN_BITS2 so compilers don't complain
589 * on builds where sizeof(long) == BN_TYPES */
590#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
591 w>>=BN_BITS4;
592 w>>=BN_BITS4;
593#else
594 w=0;
595#endif
596 a->d[i]=(BN_ULONG)w&BN_MASK2;
597 if (a->d[i] != 0) a->top=i+1;
598 }
599 return(1);
600 }
601
602BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
603 {
604 unsigned int i,m;
605 unsigned int n;
606 BN_ULONG l;
607
608 if (ret == NULL) ret=BN_new();
609 if (ret == NULL) return(NULL);
610 l=0;
611 n=len;
612 if (n == 0)
613 {
614 ret->top=0;
615 return(ret);
616 }
617 if (bn_expand(ret,(int)(n+2)*8) == NULL)
618 return(NULL);
619 i=((n-1)/BN_BYTES)+1;
620 m=((n-1)%(BN_BYTES));
621 ret->top=i;
622 ret->neg=0;
623 while (n-- > 0)
624 {
625 l=(l<<8L)| *(s++);
626 if (m-- == 0)
627 {
628 ret->d[--i]=l;
629 l=0;
630 m=BN_BYTES-1;
631 }
632 }
633 /* need to call this due to clear byte at top if avoiding
634 * having the top bit set (-ve number) */
635 bn_fix_top(ret);
636 return(ret);
637 }
638
639/* ignore negative */
640int BN_bn2bin(const BIGNUM *a, unsigned char *to)
641 {
642 int n,i;
643 BN_ULONG l;
644
645 n=i=BN_num_bytes(a);
646 while (i-- > 0)
647 {
648 l=a->d[i/BN_BYTES];
649 *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
650 }
651 return(n);
652 }
653
654int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
655 {
656 int i;
657 BN_ULONG t1,t2,*ap,*bp;
658
659 bn_check_top(a);
660 bn_check_top(b);
661
662 i=a->top-b->top;
663 if (i != 0) return(i);
664 ap=a->d;
665 bp=b->d;
666 for (i=a->top-1; i>=0; i--)
667 {
668 t1= ap[i];
669 t2= bp[i];
670 if (t1 != t2)
671 return(t1 > t2?1:-1);
672 }
673 return(0);
674 }
675
676int BN_cmp(const BIGNUM *a, const BIGNUM *b)
677 {
678 int i;
679 int gt,lt;
680 BN_ULONG t1,t2;
681
682 if ((a == NULL) || (b == NULL))
683 {
684 if (a != NULL)
685 return(-1);
686 else if (b != NULL)
687 return(1);
688 else
689 return(0);
690 }
691
692 bn_check_top(a);
693 bn_check_top(b);
694
695 if (a->neg != b->neg)
696 {
697 if (a->neg)
698 return(-1);
699 else return(1);
700 }
701 if (a->neg == 0)
702 { gt=1; lt= -1; }
703 else { gt= -1; lt=1; }
704
705 if (a->top > b->top) return(gt);
706 if (a->top < b->top) return(lt);
707 for (i=a->top-1; i>=0; i--)
708 {
709 t1=a->d[i];
710 t2=b->d[i];
711 if (t1 > t2) return(gt);
712 if (t1 < t2) return(lt);
713 }
714 return(0);
715 }
716
717int BN_set_bit(BIGNUM *a, int n)
718 {
719 int i,j,k;
720
721 i=n/BN_BITS2;
722 j=n%BN_BITS2;
723 if (a->top <= i)
724 {
725 if (bn_wexpand(a,i+1) == NULL) return(0);
726 for(k=a->top; k<i+1; k++)
727 a->d[k]=0;
728 a->top=i+1;
729 }
730
731 a->d[i]|=(((BN_ULONG)1)<<j);
732 return(1);
733 }
734
735int BN_clear_bit(BIGNUM *a, int n)
736 {
737 int i,j;
738
739 i=n/BN_BITS2;
740 j=n%BN_BITS2;
741 if (a->top <= i) return(0);
742
743 a->d[i]&=(~(((BN_ULONG)1)<<j));
744 bn_fix_top(a);
745 return(1);
746 }
747
748int BN_is_bit_set(const BIGNUM *a, int n)
749 {
750 int i,j;
751
752 if (n < 0) return(0);
753 i=n/BN_BITS2;
754 j=n%BN_BITS2;
755 if (a->top <= i) return(0);
756 return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
757 }
758
759int BN_mask_bits(BIGNUM *a, int n)
760 {
761 int b,w;
762
763 w=n/BN_BITS2;
764 b=n%BN_BITS2;
765 if (w >= a->top) return(0);
766 if (b == 0)
767 a->top=w;
768 else
769 {
770 a->top=w+1;
771 a->d[w]&= ~(BN_MASK2<<b);
772 }
773 bn_fix_top(a);
774 return(1);
775 }
776
777int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
778 {
779 int i;
780 BN_ULONG aa,bb;
781
782 aa=a[n-1];
783 bb=b[n-1];
784 if (aa != bb) return((aa > bb)?1:-1);
785 for (i=n-2; i>=0; i--)
786 {
787 aa=a[i];
788 bb=b[i];
789 if (aa != bb) return((aa > bb)?1:-1);
790 }
791 return(0);
792 }
793
794/* Here follows a specialised variants of bn_cmp_words(). It has the
795 property of performing the operation on arrays of different sizes.
796 The sizes of those arrays is expressed through cl, which is the
797 common length ( basicall, min(len(a),len(b)) ), and dl, which is the
798 delta between the two lengths, calculated as len(a)-len(b).
799 All lengths are the number of BN_ULONGs... */
800
801int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
802 int cl, int dl)
803 {
804 int n,i;
805 n = cl-1;
806
807 if (dl < 0)
808 {
809 for (i=dl; i<0; i++)
810 {
811 if (b[n-i] != 0)
812 return -1; /* a < b */
813 }
814 }
815 if (dl > 0)
816 {
817 for (i=dl; i>0; i--)
818 {
819 if (a[n+i] != 0)
820 return 1; /* a > b */
821 }
822 }
823 return bn_cmp_words(a,b,cl);
824 }
diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/bn/bn_mod.c
deleted file mode 100644
index 5cf82480d7..0000000000
--- a/src/lib/libcrypto/bn/bn_mod.c
+++ /dev/null
@@ -1,296 +0,0 @@
1/* crypto/bn/bn_mod.c */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. */
4/* ====================================================================
5 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
58 * All rights reserved.
59 *
60 * This package is an SSL implementation written
61 * by Eric Young (eay@cryptsoft.com).
62 * The implementation was written so as to conform with Netscapes SSL.
63 *
64 * This library is free for commercial and non-commercial use as long as
65 * the following conditions are aheared to. The following conditions
66 * apply to all code found in this distribution, be it the RC4, RSA,
67 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
68 * included with this distribution is covered by the same copyright terms
69 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
70 *
71 * Copyright remains Eric Young's, and as such any Copyright notices in
72 * the code are not to be removed.
73 * If this package is used in a product, Eric Young should be given attribution
74 * as the author of the parts of the library used.
75 * This can be in the form of a textual message at program startup or
76 * in documentation (online or textual) provided with the package.
77 *
78 * Redistribution and use in source and binary forms, with or without
79 * modification, are permitted provided that the following conditions
80 * are met:
81 * 1. Redistributions of source code must retain the copyright
82 * notice, this list of conditions and the following disclaimer.
83 * 2. Redistributions in binary form must reproduce the above copyright
84 * notice, this list of conditions and the following disclaimer in the
85 * documentation and/or other materials provided with the distribution.
86 * 3. All advertising materials mentioning features or use of this software
87 * must display the following acknowledgement:
88 * "This product includes cryptographic software written by
89 * Eric Young (eay@cryptsoft.com)"
90 * The word 'cryptographic' can be left out if the rouines from the library
91 * being used are not cryptographic related :-).
92 * 4. If you include any Windows specific code (or a derivative thereof) from
93 * the apps directory (application code) you must include an acknowledgement:
94 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
95 *
96 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
97 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
99 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
100 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
101 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
102 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
103 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
104 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
105 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
106 * SUCH DAMAGE.
107 *
108 * The licence and distribution terms for any publically available version or
109 * derivative of this code cannot be changed. i.e. this code cannot simply be
110 * copied and put under another distribution licence
111 * [including the GNU Public Licence.]
112 */
113
114#include "cryptlib.h"
115#include "bn_lcl.h"
116
117
118#if 0 /* now just a #define */
119int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
120 {
121 return(BN_div(NULL,rem,m,d,ctx));
122 /* note that rem->neg == m->neg (unless the remainder is zero) */
123 }
124#endif
125
126
127int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
128 {
129 /* like BN_mod, but returns non-negative remainder
130 * (i.e., 0 <= r < |d| always holds) */
131
132 if (!(BN_mod(r,m,d,ctx)))
133 return 0;
134 if (!r->neg)
135 return 1;
136 /* now -|d| < r < 0, so we have to set r := r + |d| */
137 return (d->neg ? BN_sub : BN_add)(r, r, d);
138}
139
140
141int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
142 {
143 if (!BN_add(r, a, b)) return 0;
144 return BN_nnmod(r, r, m, ctx);
145 }
146
147
148/* BN_mod_add variant that may be used if both a and b are non-negative
149 * and less than m */
150int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
151 {
152 if (!BN_add(r, a, b)) return 0;
153 if (BN_ucmp(r, m) >= 0)
154 return BN_usub(r, r, m);
155 return 1;
156 }
157
158
159int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
160 {
161 if (!BN_sub(r, a, b)) return 0;
162 return BN_nnmod(r, r, m, ctx);
163 }
164
165
166/* BN_mod_sub variant that may be used if both a and b are non-negative
167 * and less than m */
168int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
169 {
170 if (!BN_sub(r, a, b)) return 0;
171 if (r->neg)
172 return BN_add(r, r, m);
173 return 1;
174 }
175
176
177/* slow but works */
178int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
179 BN_CTX *ctx)
180 {
181 BIGNUM *t;
182 int ret=0;
183
184 bn_check_top(a);
185 bn_check_top(b);
186 bn_check_top(m);
187
188 BN_CTX_start(ctx);
189 if ((t = BN_CTX_get(ctx)) == NULL) goto err;
190 if (a == b)
191 { if (!BN_sqr(t,a,ctx)) goto err; }
192 else
193 { if (!BN_mul(t,a,b,ctx)) goto err; }
194 if (!BN_nnmod(r,t,m,ctx)) goto err;
195 ret=1;
196err:
197 BN_CTX_end(ctx);
198 return(ret);
199 }
200
201
202int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
203 {
204 if (!BN_sqr(r, a, ctx)) return 0;
205 /* r->neg == 0, thus we don't need BN_nnmod */
206 return BN_mod(r, r, m, ctx);
207 }
208
209
210int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
211 {
212 if (!BN_lshift1(r, a)) return 0;
213 return BN_nnmod(r, r, m, ctx);
214 }
215
216
217/* BN_mod_lshift1 variant that may be used if a is non-negative
218 * and less than m */
219int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)
220 {
221 if (!BN_lshift1(r, a)) return 0;
222 if (BN_cmp(r, m) >= 0)
223 return BN_sub(r, r, m);
224 return 1;
225 }
226
227
228int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx)
229 {
230 BIGNUM *abs_m = NULL;
231 int ret;
232
233 if (!BN_nnmod(r, a, m, ctx)) return 0;
234
235 if (m->neg)
236 {
237 abs_m = BN_dup(m);
238 if (abs_m == NULL) return 0;
239 abs_m->neg = 0;
240 }
241
242 ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m));
243
244 if (abs_m)
245 BN_free(abs_m);
246 return ret;
247 }
248
249
250/* BN_mod_lshift variant that may be used if a is non-negative
251 * and less than m */
252int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m)
253 {
254 if (r != a)
255 {
256 if (BN_copy(r, a) == NULL) return 0;
257 }
258
259 while (n > 0)
260 {
261 int max_shift;
262
263 /* 0 < r < m */
264 max_shift = BN_num_bits(m) - BN_num_bits(r);
265 /* max_shift >= 0 */
266
267 if (max_shift < 0)
268 {
269 BNerr(BN_F_BN_MOD_LSHIFT_QUICK, BN_R_INPUT_NOT_REDUCED);
270 return 0;
271 }
272
273 if (max_shift > n)
274 max_shift = n;
275
276 if (max_shift)
277 {
278 if (!BN_lshift(r, r, max_shift)) return 0;
279 n -= max_shift;
280 }
281 else
282 {
283 if (!BN_lshift1(r, r)) return 0;
284 --n;
285 }
286
287 /* BN_num_bits(r) <= BN_num_bits(m) */
288
289 if (BN_cmp(r, m) >= 0)
290 {
291 if (!BN_sub(r, r, m)) return 0;
292 }
293 }
294
295 return 1;
296 }
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
deleted file mode 100644
index 726d5f2b1b..0000000000
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ /dev/null
@@ -1,421 +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, const BIGNUM *a, const BIGNUM *b,
73 BN_MONT_CTX *mont, BN_CTX *ctx)
74 {
75 BIGNUM *tmp;
76 int ret=0;
77
78 BN_CTX_start(ctx);
79 tmp = BN_CTX_get(ctx);
80 if (tmp == NULL) goto err;
81
82 bn_check_top(tmp);
83 if (a == b)
84 {
85 if (!BN_sqr(tmp,a,ctx)) goto err;
86 }
87 else
88 {
89 if (!BN_mul(tmp,a,b,ctx)) goto err;
90 }
91 /* reduce from aRR to aR */
92 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
93 ret=1;
94err:
95 BN_CTX_end(ctx);
96 return(ret);
97 }
98
99int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
100 BN_CTX *ctx)
101 {
102 int retn=0;
103
104#ifdef MONT_WORD
105 BIGNUM *n,*r;
106 BN_ULONG *ap,*np,*rp,n0,v,*nrp;
107 int al,nl,max,i,x,ri;
108
109 BN_CTX_start(ctx);
110 if ((r = BN_CTX_get(ctx)) == NULL) goto err;
111
112 if (!BN_copy(r,a)) goto err;
113 n= &(mont->N);
114
115 ap=a->d;
116 /* mont->ri is the size of mont->N in bits (rounded up
117 to the word size) */
118 al=ri=mont->ri/BN_BITS2;
119
120 nl=n->top;
121 if ((al == 0) || (nl == 0)) { r->top=0; return(1); }
122
123 max=(nl+al+1); /* allow for overflow (no?) XXX */
124 if (bn_wexpand(r,max) == NULL) goto err;
125
126 r->neg=a->neg^n->neg;
127 np=n->d;
128 rp=r->d;
129 nrp= &(r->d[nl]);
130
131 /* clear the top words of T */
132#if 1
133 for (i=r->top; i<max; i++) /* memset? XXX */
134 r->d[i]=0;
135#else
136 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
137#endif
138
139 r->top=max;
140 n0=mont->n0;
141
142#ifdef BN_COUNT
143 fprintf(stderr,"word BN_from_montgomery %d * %d\n",nl,nl);
144#endif
145 for (i=0; i<nl; i++)
146 {
147#ifdef __TANDEM
148 {
149 long long t1;
150 long long t2;
151 long long t3;
152 t1 = rp[0] * (n0 & 0177777);
153 t2 = 037777600000l;
154 t2 = n0 & t2;
155 t3 = rp[0] & 0177777;
156 t2 = (t3 * t2) & BN_MASK2;
157 t1 = t1 + t2;
158 v=bn_mul_add_words(rp,np,nl,(BN_ULONG) t1);
159 }
160#else
161 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
162#endif
163 nrp++;
164 rp++;
165 if (((nrp[-1]+=v)&BN_MASK2) >= v)
166 continue;
167 else
168 {
169 if (((++nrp[0])&BN_MASK2) != 0) continue;
170 if (((++nrp[1])&BN_MASK2) != 0) continue;
171 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
172 }
173 }
174 bn_fix_top(r);
175
176 /* mont->ri will be a multiple of the word size and below code
177 * is kind of BN_rshift(ret,r,mont->ri) equivalent */
178 if (r->top <= ri)
179 {
180 ret->top=0;
181 retn=1;
182 goto err;
183 }
184 al=r->top-ri;
185
186# define BRANCH_FREE 1
187# if BRANCH_FREE
188 if (bn_wexpand(ret,ri) == NULL) goto err;
189 x=0-(((al-ri)>>(sizeof(al)*8-1))&1);
190 ret->top=x=(ri&~x)|(al&x); /* min(ri,al) */
191 ret->neg=r->neg;
192
193 rp=ret->d;
194 ap=&(r->d[ri]);
195
196 {
197 size_t m1,m2;
198
199 v=bn_sub_words(rp,ap,np,ri);
200 /* this ----------------^^ works even in al<ri case
201 * thanks to zealous zeroing of top of the vector in the
202 * beginning. */
203
204 /* if (al==ri && !v) || al>ri) nrp=rp; else nrp=ap; */
205 /* in other words if subtraction result is real, then
206 * trick unconditional memcpy below to perform in-place
207 * "refresh" instead of actual copy. */
208 m1=0-(size_t)(((al-ri)>>(sizeof(al)*8-1))&1); /* al<ri */
209 m2=0-(size_t)(((ri-al)>>(sizeof(al)*8-1))&1); /* al>ri */
210 m1|=m2; /* (al!=ri) */
211 m1|=(0-(size_t)v); /* (al!=ri || v) */
212 m1&=~m2; /* (al!=ri || v) && !al>ri */
213 nrp=(BN_ULONG *)(((size_t)rp&~m1)|((size_t)ap&m1));
214 }
215
216 /* 'i<ri' is chosen to eliminate dependency on input data, even
217 * though it results in redundant copy in al<ri case. */
218 for (i=0,ri-=4; i<ri; i+=4)
219 {
220 BN_ULONG t1,t2,t3,t4;
221
222 t1=nrp[i+0];
223 t2=nrp[i+1];
224 t3=nrp[i+2]; ap[i+0]=0;
225 t4=nrp[i+3]; ap[i+1]=0;
226 rp[i+0]=t1; ap[i+2]=0;
227 rp[i+1]=t2; ap[i+3]=0;
228 rp[i+2]=t3;
229 rp[i+3]=t4;
230 }
231 for (ri+=4; i<ri; i++)
232 rp[i]=nrp[i], ap[i]=0;
233# else
234 if (bn_wexpand(ret,al) == NULL) goto err;
235 ret->top=al;
236 ret->neg=r->neg;
237
238 rp=ret->d;
239 ap=&(r->d[ri]);
240 al-=4;
241 for (i=0; i<al; i+=4)
242 {
243 BN_ULONG t1,t2,t3,t4;
244
245 t1=ap[i+0];
246 t2=ap[i+1];
247 t3=ap[i+2];
248 t4=ap[i+3];
249 rp[i+0]=t1;
250 rp[i+1]=t2;
251 rp[i+2]=t3;
252 rp[i+3]=t4;
253 }
254 al+=4;
255 for (; i<al; i++)
256 rp[i]=ap[i];
257# endif
258#else /* !MONT_WORD */
259 BIGNUM *t1,*t2;
260
261 BN_CTX_start(ctx);
262 t1 = BN_CTX_get(ctx);
263 t2 = BN_CTX_get(ctx);
264 if (t1 == NULL || t2 == NULL) goto err;
265
266 if (!BN_copy(t1,a)) goto err;
267 BN_mask_bits(t1,mont->ri);
268
269 if (!BN_mul(t2,t1,&mont->Ni,ctx)) goto err;
270 BN_mask_bits(t2,mont->ri);
271
272 if (!BN_mul(t1,t2,&mont->N,ctx)) goto err;
273 if (!BN_add(t2,a,t1)) goto err;
274 if (!BN_rshift(ret,t2,mont->ri)) goto err;
275#endif /* MONT_WORD */
276
277#if !defined(BRANCH_FREE) || BRANCH_FREE==0
278 if (BN_ucmp(ret, &(mont->N)) >= 0)
279 {
280 if (!BN_usub(ret,ret,&(mont->N))) goto err;
281 }
282#endif
283 retn=1;
284 err:
285 BN_CTX_end(ctx);
286 return(retn);
287 }
288
289BN_MONT_CTX *BN_MONT_CTX_new(void)
290 {
291 BN_MONT_CTX *ret;
292
293 if ((ret=(BN_MONT_CTX *)OPENSSL_malloc(sizeof(BN_MONT_CTX))) == NULL)
294 return(NULL);
295
296 BN_MONT_CTX_init(ret);
297 ret->flags=BN_FLG_MALLOCED;
298 return(ret);
299 }
300
301void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
302 {
303 ctx->ri=0;
304 BN_init(&(ctx->RR));
305 BN_init(&(ctx->N));
306 BN_init(&(ctx->Ni));
307 ctx->flags=0;
308 }
309
310void BN_MONT_CTX_free(BN_MONT_CTX *mont)
311 {
312 if(mont == NULL)
313 return;
314
315 BN_free(&(mont->RR));
316 BN_free(&(mont->N));
317 BN_free(&(mont->Ni));
318 if (mont->flags & BN_FLG_MALLOCED)
319 OPENSSL_free(mont);
320 }
321
322int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
323 {
324 BIGNUM Ri,*R;
325
326 BN_init(&Ri);
327 R= &(mont->RR); /* grab RR as a temp */
328 if (!BN_copy(&(mont->N),mod)) goto err; /* Set N */
329 mont->N.neg = 0;
330
331#ifdef MONT_WORD
332 {
333 BIGNUM tmod;
334 BN_ULONG buf[2];
335
336 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
337 if (!(BN_zero(R))) goto err;
338 if (!(BN_set_bit(R,BN_BITS2))) goto err; /* R */
339
340 buf[0]=mod->d[0]; /* tmod = N mod word size */
341 buf[1]=0;
342 tmod.d=buf;
343 tmod.top=1;
344 tmod.dmax=2;
345 tmod.neg=0;
346 /* Ri = R^-1 mod N*/
347 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)
348 goto err;
349 if (!BN_lshift(&Ri,&Ri,BN_BITS2)) goto err; /* R*Ri */
350 if (!BN_is_zero(&Ri))
351 {
352 if (!BN_sub_word(&Ri,1)) goto err;
353 }
354 else /* if N mod word size == 1 */
355 {
356 if (!BN_set_word(&Ri,BN_MASK2)) goto err; /* Ri-- (mod word size) */
357 }
358 if (!BN_div(&Ri,NULL,&Ri,&tmod,ctx)) goto err;
359 /* Ni = (R*Ri-1)/N,
360 * keep only least significant word: */
361 mont->n0 = (Ri.top > 0) ? Ri.d[0] : 0;
362 BN_free(&Ri);
363 }
364#else /* !MONT_WORD */
365 { /* bignum version */
366 mont->ri=BN_num_bits(&mont->N);
367 if (!BN_zero(R)) goto err;
368 if (!BN_set_bit(R,mont->ri)) goto err; /* R = 2^ri */
369 /* Ri = R^-1 mod N*/
370 if ((BN_mod_inverse(&Ri,R,&mont->N,ctx)) == NULL)
371 goto err;
372 if (!BN_lshift(&Ri,&Ri,mont->ri)) goto err; /* R*Ri */
373 if (!BN_sub_word(&Ri,1)) goto err;
374 /* Ni = (R*Ri-1) / N */
375 if (!BN_div(&(mont->Ni),NULL,&Ri,&mont->N,ctx)) goto err;
376 BN_free(&Ri);
377 }
378#endif
379
380 /* setup RR for conversions */
381 if (!BN_zero(&(mont->RR))) goto err;
382 if (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;
383 if (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;
384
385 return(1);
386err:
387 return(0);
388 }
389
390BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
391 {
392 if (to == from) return(to);
393
394 if (!BN_copy(&(to->RR),&(from->RR))) return NULL;
395 if (!BN_copy(&(to->N),&(from->N))) return NULL;
396 if (!BN_copy(&(to->Ni),&(from->Ni))) return NULL;
397 to->ri=from->ri;
398 to->n0=from->n0;
399 return(to);
400 }
401
402BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
403 const BIGNUM *mod, BN_CTX *ctx)
404 {
405 if (*pmont)
406 return *pmont;
407 CRYPTO_w_lock(lock);
408 if (!*pmont)
409 {
410 *pmont = BN_MONT_CTX_new();
411 if (*pmont && !BN_MONT_CTX_set(*pmont, mod, ctx))
412 {
413 BN_MONT_CTX_free(*pmont);
414 *pmont = NULL;
415 }
416 }
417 CRYPTO_w_unlock(lock);
418 return *pmont;
419 }
420
421
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c
deleted file mode 100644
index 05fa9d1e9a..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(const 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 3ae3822bc2..0000000000
--- a/src/lib/libcrypto/bn/bn_mul.c
+++ /dev/null
@@ -1,802 +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 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 < (BN_ULONG)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, const BIGNUM *a, const 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
635 if ((al == 0) || (bl == 0))
636 {
637 if (!BN_zero(r)) goto err;
638 return(1);
639 }
640 top=al+bl;
641
642 BN_CTX_start(ctx);
643 if ((r == a) || (r == b))
644 {
645 if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
646 }
647 else
648 rr = r;
649 rr->neg=a->neg^b->neg;
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) && bl<b->dmax)
679 {
680#if 0 /* tribute to const-ification, bl<b->dmax above covers for this */
681 if (bn_wexpand(b,al) == NULL) goto err;
682#endif
683 b->d[bl]=0;
684 bl++;
685 i--;
686 }
687 else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA) && al<a->dmax)
688 {
689#if 0 /* tribute to const-ification, al<a->dmax above covers for this */
690 if (bn_wexpand(a,bl) == NULL) goto err;
691#endif
692 a->d[al]=0;
693 al++;
694 i++;
695 }
696 if (i == 0)
697 {
698 /* symmetric and > 4 */
699 /* 16 or larger */
700 j=BN_num_bits_word((BN_ULONG)al);
701 j=1<<(j-1);
702 k=j+j;
703 t = BN_CTX_get(ctx);
704 if (al == j) /* exact multiple */
705 {
706 if (bn_wexpand(t,k*2) == NULL) goto err;
707 if (bn_wexpand(rr,k*2) == NULL) goto err;
708 bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
709 rr->top=top;
710 goto end;
711 }
712#if 0 /* tribute to const-ification, rsa/dsa performance is not affected */
713 else
714 {
715 if (bn_wexpand(a,k) == NULL ) goto err;
716 if (bn_wexpand(b,k) == NULL ) goto err;
717 if (bn_wexpand(t,k*4) == NULL ) goto err;
718 if (bn_wexpand(rr,k*4) == NULL ) goto err;
719 for (i=a->top; i<k; i++)
720 a->d[i]=0;
721 for (i=b->top; i<k; i++)
722 b->d[i]=0;
723 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
724 }
725 rr->top=top;
726 goto end;
727#endif
728 }
729 }
730#endif /* BN_RECURSION */
731 if (bn_wexpand(rr,top) == NULL) goto err;
732 rr->top=top;
733 bn_mul_normal(rr->d,a->d,al,b->d,bl);
734
735#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
736end:
737#endif
738 bn_fix_top(rr);
739 if (r != rr) BN_copy(r,rr);
740 ret=1;
741err:
742 BN_CTX_end(ctx);
743 return(ret);
744 }
745
746void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
747 {
748 BN_ULONG *rr;
749
750#ifdef BN_COUNT
751 printf(" bn_mul_normal %d * %d\n",na,nb);
752#endif
753
754 if (na < nb)
755 {
756 int itmp;
757 BN_ULONG *ltmp;
758
759 itmp=na; na=nb; nb=itmp;
760 ltmp=a; a=b; b=ltmp;
761
762 }
763 rr= &(r[na]);
764 rr[0]=bn_mul_words(r,a,na,b[0]);
765
766 for (;;)
767 {
768 if (--nb <= 0) return;
769 rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
770 if (--nb <= 0) return;
771 rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
772 if (--nb <= 0) return;
773 rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
774 if (--nb <= 0) return;
775 rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
776 rr+=4;
777 r+=4;
778 b+=4;
779 }
780 }
781
782void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
783 {
784#ifdef BN_COUNT
785 printf(" bn_mul_low_normal %d * %d\n",n,n);
786#endif
787 bn_mul_words(r,a,n,b[0]);
788
789 for (;;)
790 {
791 if (--n <= 0) return;
792 bn_mul_add_words(&(r[1]),a,n,b[1]);
793 if (--n <= 0) return;
794 bn_mul_add_words(&(r[2]),a,n,b[2]);
795 if (--n <= 0) return;
796 bn_mul_add_words(&(r[3]),a,n,b[3]);
797 if (--n <= 0) return;
798 bn_mul_add_words(&(r[4]),a,n,b[4]);
799 r+=4;
800 b+=4;
801 }
802 }
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
deleted file mode 100644
index f422172f16..0000000000
--- a/src/lib/libcrypto/bn/bn_prime.c
+++ /dev/null
@@ -1,468 +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-2001 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 const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
129static int probable_prime_dh_safe(BIGNUM *rnd, int bits,
130 const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
131
132BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
133 const BIGNUM *add, const BIGNUM *rem,
134 void (*callback)(int,int,void *), void *cb_arg)
135 {
136 BIGNUM *rnd=NULL;
137 BIGNUM t;
138 int found=0;
139 int i,j,c1=0;
140 BN_CTX *ctx;
141 int checks = BN_prime_checks_for_size(bits);
142
143 BN_init(&t);
144 ctx=BN_CTX_new();
145 if (ctx == NULL) goto err;
146 if (ret == NULL)
147 {
148 if ((rnd=BN_new()) == NULL) goto err;
149 }
150 else
151 rnd=ret;
152loop:
153 /* make a random number and set the top and bottom bits */
154 if (add == NULL)
155 {
156 if (!probable_prime(rnd,bits)) goto err;
157 }
158 else
159 {
160 if (safe)
161 {
162 if (!probable_prime_dh_safe(rnd,bits,add,rem,ctx))
163 goto err;
164 }
165 else
166 {
167 if (!probable_prime_dh(rnd,bits,add,rem,ctx))
168 goto err;
169 }
170 }
171 /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */
172 if (callback != NULL) callback(0,c1++,cb_arg);
173
174 if (!safe)
175 {
176 i=BN_is_prime_fasttest(rnd,checks,callback,ctx,cb_arg,0);
177 if (i == -1) goto err;
178 if (i == 0) goto loop;
179 }
180 else
181 {
182 /* for "safe prime" generation,
183 * check that (p-1)/2 is prime.
184 * Since a prime is odd, We just
185 * need to divide by 2 */
186 if (!BN_rshift1(&t,rnd)) goto err;
187
188 for (i=0; i<checks; i++)
189 {
190 j=BN_is_prime_fasttest(rnd,1,callback,ctx,cb_arg,0);
191 if (j == -1) goto err;
192 if (j == 0) goto loop;
193
194 j=BN_is_prime_fasttest(&t,1,callback,ctx,cb_arg,0);
195 if (j == -1) goto err;
196 if (j == 0) goto loop;
197
198 if (callback != NULL) callback(2,c1-1,cb_arg);
199 /* We have a safe prime test pass */
200 }
201 }
202 /* we have a prime :-) */
203 found = 1;
204err:
205 if (!found && (ret == NULL) && (rnd != NULL)) BN_free(rnd);
206 BN_free(&t);
207 if (ctx != NULL) BN_CTX_free(ctx);
208 return(found ? rnd : NULL);
209 }
210
211int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
212 BN_CTX *ctx_passed, void *cb_arg)
213 {
214 return BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);
215 }
216
217int BN_is_prime_fasttest(const BIGNUM *a, int checks,
218 void (*callback)(int,int,void *),
219 BN_CTX *ctx_passed, void *cb_arg,
220 int do_trial_division)
221 {
222 int i, j, ret = -1;
223 int k;
224 BN_CTX *ctx = NULL;
225 BIGNUM *A1, *A1_odd, *check; /* taken from ctx */
226 BN_MONT_CTX *mont = NULL;
227 const BIGNUM *A = NULL;
228
229 if (BN_cmp(a, BN_value_one()) <= 0)
230 return 0;
231
232 if (checks == BN_prime_checks)
233 checks = BN_prime_checks_for_size(BN_num_bits(a));
234
235 /* first look for small factors */
236 if (!BN_is_odd(a))
237 /* a is even => a is prime if and only if a == 2 */
238 return BN_is_word(a, 2);
239
240 if (do_trial_division)
241 {
242 for (i = 1; i < NUMPRIMES; i++)
243 if (BN_mod_word(a, primes[i]) == 0)
244 return 0;
245 if (callback != NULL) callback(1, -1, cb_arg);
246 }
247
248 if (ctx_passed != NULL)
249 ctx = ctx_passed;
250 else
251 if ((ctx=BN_CTX_new()) == NULL)
252 goto err;
253 BN_CTX_start(ctx);
254
255 /* A := abs(a) */
256 if (a->neg)
257 {
258 BIGNUM *t;
259 if ((t = BN_CTX_get(ctx)) == NULL) goto err;
260 BN_copy(t, a);
261 t->neg = 0;
262 A = t;
263 }
264 else
265 A = a;
266 A1 = BN_CTX_get(ctx);
267 A1_odd = BN_CTX_get(ctx);
268 check = BN_CTX_get(ctx);
269 if (check == NULL) goto err;
270
271 /* compute A1 := A - 1 */
272 if (!BN_copy(A1, A))
273 goto err;
274 if (!BN_sub_word(A1, 1))
275 goto err;
276 if (BN_is_zero(A1))
277 {
278 ret = 0;
279 goto err;
280 }
281
282 /* write A1 as A1_odd * 2^k */
283 k = 1;
284 while (!BN_is_bit_set(A1, k))
285 k++;
286 if (!BN_rshift(A1_odd, A1, k))
287 goto err;
288
289 /* Montgomery setup for computations mod A */
290 mont = BN_MONT_CTX_new();
291 if (mont == NULL)
292 goto err;
293 if (!BN_MONT_CTX_set(mont, A, ctx))
294 goto err;
295
296 for (i = 0; i < checks; i++)
297 {
298 if (!BN_pseudo_rand_range(check, A1))
299 goto err;
300 if (!BN_add_word(check, 1))
301 goto err;
302 /* now 1 <= check < A */
303
304 j = witness(check, A, A1, A1_odd, k, ctx, mont);
305 if (j == -1) goto err;
306 if (j)
307 {
308 ret=0;
309 goto err;
310 }
311 if (callback != NULL) callback(1,i,cb_arg);
312 }
313 ret=1;
314err:
315 if (ctx != NULL)
316 {
317 BN_CTX_end(ctx);
318 if (ctx_passed == NULL)
319 BN_CTX_free(ctx);
320 }
321 if (mont != NULL)
322 BN_MONT_CTX_free(mont);
323
324 return(ret);
325 }
326
327static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
328 const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont)
329 {
330 if (!BN_mod_exp_mont(w, w, a1_odd, a, ctx, mont)) /* w := w^a1_odd mod a */
331 return -1;
332 if (BN_is_one(w))
333 return 0; /* probably prime */
334 if (BN_cmp(w, a1) == 0)
335 return 0; /* w == -1 (mod a), 'a' is probably prime */
336 while (--k)
337 {
338 if (!BN_mod_mul(w, w, w, a, ctx)) /* w := w^2 mod a */
339 return -1;
340 if (BN_is_one(w))
341 return 1; /* 'a' is composite, otherwise a previous 'w' would
342 * have been == -1 (mod 'a') */
343 if (BN_cmp(w, a1) == 0)
344 return 0; /* w == -1 (mod a), 'a' is probably prime */
345 }
346 /* If we get here, 'w' is the (a-1)/2-th power of the original 'w',
347 * and it is neither -1 nor +1 -- so 'a' cannot be prime */
348 return 1;
349 }
350
351static int probable_prime(BIGNUM *rnd, int bits)
352 {
353 int i;
354 BN_ULONG mods[NUMPRIMES];
355 BN_ULONG delta,d;
356
357again:
358 if (!BN_rand(rnd,bits,1,1)) return(0);
359 /* we now have a random number 'rand' to test. */
360 for (i=1; i<NUMPRIMES; i++)
361 mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);
362 delta=0;
363 loop: for (i=1; i<NUMPRIMES; i++)
364 {
365 /* check that rnd is not a prime and also
366 * that gcd(rnd-1,primes) == 1 (except for 2) */
367 if (((mods[i]+delta)%primes[i]) <= 1)
368 {
369 d=delta;
370 delta+=2;
371 /* perhaps need to check for overflow of
372 * delta (but delta can be up to 2^32)
373 * 21-May-98 eay - added overflow check */
374 if (delta < d) goto again;
375 goto loop;
376 }
377 }
378 if (!BN_add_word(rnd,delta)) return(0);
379 return(1);
380 }
381
382static int probable_prime_dh(BIGNUM *rnd, int bits,
383 const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx)
384 {
385 int i,ret=0;
386 BIGNUM *t1;
387
388 BN_CTX_start(ctx);
389 if ((t1 = BN_CTX_get(ctx)) == NULL) goto err;
390
391 if (!BN_rand(rnd,bits,0,1)) goto err;
392
393 /* we need ((rnd-rem) % add) == 0 */
394
395 if (!BN_mod(t1,rnd,add,ctx)) goto err;
396 if (!BN_sub(rnd,rnd,t1)) goto err;
397 if (rem == NULL)
398 { if (!BN_add_word(rnd,1)) goto err; }
399 else
400 { if (!BN_add(rnd,rnd,rem)) goto err; }
401
402 /* we now have a random number 'rand' to test. */
403
404 loop: for (i=1; i<NUMPRIMES; i++)
405 {
406 /* check that rnd is a prime */
407 if (BN_mod_word(rnd,(BN_ULONG)primes[i]) <= 1)
408 {
409 if (!BN_add(rnd,rnd,add)) goto err;
410 goto loop;
411 }
412 }
413 ret=1;
414err:
415 BN_CTX_end(ctx);
416 return(ret);
417 }
418
419static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,
420 const BIGNUM *rem, BN_CTX *ctx)
421 {
422 int i,ret=0;
423 BIGNUM *t1,*qadd,*q;
424
425 bits--;
426 BN_CTX_start(ctx);
427 t1 = BN_CTX_get(ctx);
428 q = BN_CTX_get(ctx);
429 qadd = BN_CTX_get(ctx);
430 if (qadd == NULL) goto err;
431
432 if (!BN_rshift1(qadd,padd)) goto err;
433
434 if (!BN_rand(q,bits,0,1)) goto err;
435
436 /* we need ((rnd-rem) % add) == 0 */
437 if (!BN_mod(t1,q,qadd,ctx)) goto err;
438 if (!BN_sub(q,q,t1)) goto err;
439 if (rem == NULL)
440 { if (!BN_add_word(q,1)) goto err; }
441 else
442 {
443 if (!BN_rshift1(t1,rem)) goto err;
444 if (!BN_add(q,q,t1)) goto err;
445 }
446
447 /* we now have a random number 'rand' to test. */
448 if (!BN_lshift1(p,q)) goto err;
449 if (!BN_add_word(p,1)) goto err;
450
451 loop: for (i=1; i<NUMPRIMES; i++)
452 {
453 /* check that p and q are prime */
454 /* check that for p and q
455 * gcd(p-1,primes) == 1 (except for 2) */
456 if ( (BN_mod_word(p,(BN_ULONG)primes[i]) == 0) ||
457 (BN_mod_word(q,(BN_ULONG)primes[i]) == 0))
458 {
459 if (!BN_add(p,p,padd)) goto err;
460 if (!BN_add(q,q,qadd)) goto err;
461 goto loop;
462 }
463 }
464 ret=1;
465err:
466 BN_CTX_end(ctx);
467 return(ret);
468 }
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 acba7ed7ee..0000000000
--- a/src/lib/libcrypto/bn/bn_print.c
+++ /dev/null
@@ -1,333 +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 'OPENSSL_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 *)OPENSSL_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 (BN_is_zero(a)) *(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 'OPENSSL_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 *)OPENSSL_malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG));
114 buf=(char *)OPENSSL_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#define BUF_REMAIN (num+3 - (size_t)(p - buf))
123 p=buf;
124 lp=bn_data;
125 if (t->neg) *(p++)='-';
126 if (BN_is_zero(t))
127 {
128 *(p++)='0';
129 *(p++)='\0';
130 }
131 else
132 {
133 i=0;
134 while (!BN_is_zero(t))
135 {
136 *lp=BN_div_word(t,BN_DEC_CONV);
137 lp++;
138 }
139 lp--;
140 /* We now have a series of blocks, BN_DEC_NUM chars
141 * in length, where the last one needs truncation.
142 * The blocks need to be reversed in order. */
143 BIO_snprintf(p,BUF_REMAIN,BN_DEC_FMT1,*lp);
144 while (*p) p++;
145 while (lp != bn_data)
146 {
147 lp--;
148 BIO_snprintf(p,BUF_REMAIN,BN_DEC_FMT2,*lp);
149 while (*p) p++;
150 }
151 }
152err:
153 if (bn_data != NULL) OPENSSL_free(bn_data);
154 if (t != NULL) BN_free(t);
155 return(buf);
156 }
157
158int BN_hex2bn(BIGNUM **bn, const char *a)
159 {
160 BIGNUM *ret=NULL;
161 BN_ULONG l=0;
162 int neg=0,h,m,i,j,k,c;
163 int num;
164
165 if ((a == NULL) || (*a == '\0')) return(0);
166
167 if (*a == '-') { neg=1; a++; }
168
169 for (i=0; isxdigit((unsigned char) a[i]); i++)
170 ;
171
172 num=i+neg;
173 if (bn == NULL) return(num);
174
175 /* a is the start of the hex digits, and it is 'i' long */
176 if (*bn == NULL)
177 {
178 if ((ret=BN_new()) == NULL) return(0);
179 }
180 else
181 {
182 ret= *bn;
183 BN_zero(ret);
184 }
185
186 /* i is the number of hex digests; */
187 if (bn_expand(ret,i*4) == NULL) goto err;
188
189 j=i; /* least significant 'hex' */
190 m=0;
191 h=0;
192 while (j > 0)
193 {
194 m=((BN_BYTES*2) <= j)?(BN_BYTES*2):j;
195 l=0;
196 for (;;)
197 {
198 c=a[j-m];
199 if ((c >= '0') && (c <= '9')) k=c-'0';
200 else if ((c >= 'a') && (c <= 'f')) k=c-'a'+10;
201 else if ((c >= 'A') && (c <= 'F')) k=c-'A'+10;
202 else k=0; /* paranoia */
203 l=(l<<4)|k;
204
205 if (--m <= 0)
206 {
207 ret->d[h++]=l;
208 break;
209 }
210 }
211 j-=(BN_BYTES*2);
212 }
213 ret->top=h;
214 bn_fix_top(ret);
215 ret->neg=neg;
216
217 *bn=ret;
218 return(num);
219err:
220 if (*bn == NULL) BN_free(ret);
221 return(0);
222 }
223
224int BN_dec2bn(BIGNUM **bn, const char *a)
225 {
226 BIGNUM *ret=NULL;
227 BN_ULONG l=0;
228 int neg=0,i,j;
229 int num;
230
231 if ((a == NULL) || (*a == '\0')) return(0);
232 if (*a == '-') { neg=1; a++; }
233
234 for (i=0; isdigit((unsigned char) a[i]); i++)
235 ;
236
237 num=i+neg;
238 if (bn == NULL) return(num);
239
240 /* a is the start of the digits, and it is 'i' long.
241 * We chop it into BN_DEC_NUM digits at a time */
242 if (*bn == NULL)
243 {
244 if ((ret=BN_new()) == NULL) return(0);
245 }
246 else
247 {
248 ret= *bn;
249 BN_zero(ret);
250 }
251
252 /* i is the number of digests, a bit of an over expand; */
253 if (bn_expand(ret,i*4) == NULL) goto err;
254
255 j=BN_DEC_NUM-(i%BN_DEC_NUM);
256 if (j == BN_DEC_NUM) j=0;
257 l=0;
258 while (*a)
259 {
260 l*=10;
261 l+= *a-'0';
262 a++;
263 if (++j == BN_DEC_NUM)
264 {
265 BN_mul_word(ret,BN_DEC_CONV);
266 BN_add_word(ret,l);
267 l=0;
268 j=0;
269 }
270 }
271 ret->neg=neg;
272
273 bn_fix_top(ret);
274 *bn=ret;
275 return(num);
276err:
277 if (*bn == NULL) BN_free(ret);
278 return(0);
279 }
280
281#ifndef OPENSSL_NO_BIO
282#ifndef OPENSSL_NO_FP_API
283int BN_print_fp(FILE *fp, const BIGNUM *a)
284 {
285 BIO *b;
286 int ret;
287
288 if ((b=BIO_new(BIO_s_file())) == NULL)
289 return(0);
290 BIO_set_fp(b,fp,BIO_NOCLOSE);
291 ret=BN_print(b,a);
292 BIO_free(b);
293 return(ret);
294 }
295#endif
296
297int BN_print(BIO *bp, const BIGNUM *a)
298 {
299 int i,j,v,z=0;
300 int ret=0;
301
302 if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end;
303 if ((BN_is_zero(a)) && (BIO_write(bp,"0",1) != 1)) goto end;
304 for (i=a->top-1; i >=0; i--)
305 {
306 for (j=BN_BITS2-4; j >= 0; j-=4)
307 {
308 /* strip leading zeros */
309 v=((int)(a->d[i]>>(long)j))&0x0f;
310 if (z || (v != 0))
311 {
312 if (BIO_write(bp,&(Hex[v]),1) != 1)
313 goto end;
314 z=1;
315 }
316 }
317 }
318 ret=1;
319end:
320 return(ret);
321 }
322#endif
323
324#ifdef BN_DEBUG
325void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n)
326 {
327 int i;
328 fprintf(o, "%s=", a);
329 for (i=n-1;i>=0;i--)
330 fprintf(o, "%08lX", b[i]); /* assumes 32-bit BN_ULONG */
331 fprintf(o, "\n");
332 }
333#endif
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
deleted file mode 100644
index 893c9d2af9..0000000000
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ /dev/null
@@ -1,291 +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 * Copyright (c) 1998-2001 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
118static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
119 {
120 unsigned char *buf=NULL;
121 int ret=0,bit,bytes,mask;
122 time_t tim;
123
124 if (bits == 0)
125 {
126 BN_zero(rnd);
127 return 1;
128 }
129
130 bytes=(bits+7)/8;
131 bit=(bits-1)%8;
132 mask=0xff<<(bit+1);
133
134 buf=(unsigned char *)OPENSSL_malloc(bytes);
135 if (buf == NULL)
136 {
137 BNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);
138 goto err;
139 }
140
141 /* make a random number and set the top and bottom bits */
142 time(&tim);
143 RAND_add(&tim,sizeof(tim),0);
144
145 if (pseudorand)
146 {
147 if (RAND_pseudo_bytes(buf, bytes) == -1)
148 goto err;
149 }
150 else
151 {
152 if (RAND_bytes(buf, bytes) <= 0)
153 goto err;
154 }
155
156#if 1
157 if (pseudorand == 2)
158 {
159 /* generate patterns that are more likely to trigger BN
160 library bugs */
161 int i;
162 unsigned char c;
163
164 for (i = 0; i < bytes; i++)
165 {
166 RAND_pseudo_bytes(&c, 1);
167 if (c >= 128 && i > 0)
168 buf[i] = buf[i-1];
169 else if (c < 42)
170 buf[i] = 0;
171 else if (c < 84)
172 buf[i] = 255;
173 }
174 }
175#endif
176
177 if (top != -1)
178 {
179 if (top)
180 {
181 if (bit == 0)
182 {
183 buf[0]=1;
184 buf[1]|=0x80;
185 }
186 else
187 {
188 buf[0]|=(3<<(bit-1));
189 }
190 }
191 else
192 {
193 buf[0]|=(1<<bit);
194 }
195 }
196 buf[0] &= ~mask;
197 if (bottom) /* set bottom bit if requested */
198 buf[bytes-1]|=1;
199 if (!BN_bin2bn(buf,bytes,rnd)) goto err;
200 ret=1;
201err:
202 if (buf != NULL)
203 {
204 OPENSSL_cleanse(buf,bytes);
205 OPENSSL_free(buf);
206 }
207 return(ret);
208 }
209
210int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
211 {
212 return bnrand(0, rnd, bits, top, bottom);
213 }
214
215int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
216 {
217 return bnrand(1, rnd, bits, top, bottom);
218 }
219
220#if 1
221int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
222 {
223 return bnrand(2, rnd, bits, top, bottom);
224 }
225#endif
226
227
228/* random number r: 0 <= r < range */
229static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
230 {
231 int (*bn_rand)(BIGNUM *, int, int, int) = pseudo ? BN_pseudo_rand : BN_rand;
232 int n;
233
234 if (range->neg || BN_is_zero(range))
235 {
236 BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE);
237 return 0;
238 }
239
240 n = BN_num_bits(range); /* n > 0 */
241
242 /* BN_is_bit_set(range, n - 1) always holds */
243
244 if (n == 1)
245 {
246 if (!BN_zero(r)) return 0;
247 }
248 else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3))
249 {
250 /* range = 100..._2,
251 * so 3*range (= 11..._2) is exactly one bit longer than range */
252 do
253 {
254 if (!bn_rand(r, n + 1, -1, 0)) return 0;
255 /* If r < 3*range, use r := r MOD range
256 * (which is either r, r - range, or r - 2*range).
257 * Otherwise, iterate once more.
258 * Since 3*range = 11..._2, each iteration succeeds with
259 * probability >= .75. */
260 if (BN_cmp(r ,range) >= 0)
261 {
262 if (!BN_sub(r, r, range)) return 0;
263 if (BN_cmp(r, range) >= 0)
264 if (!BN_sub(r, r, range)) return 0;
265 }
266 }
267 while (BN_cmp(r, range) >= 0);
268 }
269 else
270 {
271 do
272 {
273 /* range = 11..._2 or range = 101..._2 */
274 if (!bn_rand(r, n, -1, 0)) return 0;
275 }
276 while (BN_cmp(r, range) >= 0);
277 }
278
279 return 1;
280 }
281
282
283int BN_rand_range(BIGNUM *r, BIGNUM *range)
284 {
285 return bn_rand_range(0, r, range);
286 }
287
288int BN_pseudo_rand_range(BIGNUM *r, BIGNUM *range)
289 {
290 return bn_rand_range(1, r, range);
291 }
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
deleted file mode 100644
index ef5fdd4708..0000000000
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ /dev/null
@@ -1,230 +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 *)OPENSSL_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 OPENSSL_free(recp);
92 }
93
94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
95 {
96 if (!BN_copy(&(recp->N),d)) return 0;
97 if (!BN_zero(&(recp->Nr))) return 0;
98 recp->num_bits=BN_num_bits(d);
99 recp->shift=0;
100 return(1);
101 }
102
103int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
104 BN_RECP_CTX *recp, BN_CTX *ctx)
105 {
106 int ret=0;
107 BIGNUM *a;
108 const BIGNUM *ca;
109
110 BN_CTX_start(ctx);
111 if ((a = BN_CTX_get(ctx)) == NULL) goto err;
112 if (y != NULL)
113 {
114 if (x == y)
115 { if (!BN_sqr(a,x,ctx)) goto err; }
116 else
117 { if (!BN_mul(a,x,y,ctx)) goto err; }
118 ca = a;
119 }
120 else
121 ca=x; /* Just do the mod */
122
123 ret = BN_div_recp(NULL,r,ca,recp,ctx);
124err:
125 BN_CTX_end(ctx);
126 return(ret);
127 }
128
129int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
130 BN_RECP_CTX *recp, BN_CTX *ctx)
131 {
132 int i,j,ret=0;
133 BIGNUM *a,*b,*d,*r;
134
135 BN_CTX_start(ctx);
136 a=BN_CTX_get(ctx);
137 b=BN_CTX_get(ctx);
138 if (dv != NULL)
139 d=dv;
140 else
141 d=BN_CTX_get(ctx);
142 if (rem != NULL)
143 r=rem;
144 else
145 r=BN_CTX_get(ctx);
146 if (a == NULL || b == NULL || d == NULL || r == NULL) goto err;
147
148 if (BN_ucmp(m,&(recp->N)) < 0)
149 {
150 if (!BN_zero(d)) return 0;
151 if (!BN_copy(r,m)) return 0;
152 BN_CTX_end(ctx);
153 return(1);
154 }
155
156 /* We want the remainder
157 * Given input of ABCDEF / ab
158 * we need multiply ABCDEF by 3 digests of the reciprocal of ab
159 *
160 */
161
162 /* i := max(BN_num_bits(m), 2*BN_num_bits(N)) */
163 i=BN_num_bits(m);
164 j=recp->num_bits<<1;
165 if (j>i) i=j;
166
167 /* Nr := round(2^i / N) */
168 if (i != recp->shift)
169 recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
170 i,ctx); /* BN_reciprocal returns i, or -1 for an error */
171 if (recp->shift == -1) goto err;
172
173 /* d := |round(round(m / 2^BN_num_bits(N)) * recp->Nr / 2^(i - BN_num_bits(N)))|
174 * = |round(round(m / 2^BN_num_bits(N)) * round(2^i / N) / 2^(i - BN_num_bits(N)))|
175 * <= |(m / 2^BN_num_bits(N)) * (2^i / N) * (2^BN_num_bits(N) / 2^i)|
176 * = |m/N|
177 */
178 if (!BN_rshift(a,m,recp->num_bits)) goto err;
179 if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;
180 if (!BN_rshift(d,b,i-recp->num_bits)) goto err;
181 d->neg=0;
182
183 if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
184 if (!BN_usub(r,m,b)) goto err;
185 r->neg=0;
186
187#if 1
188 j=0;
189 while (BN_ucmp(r,&(recp->N)) >= 0)
190 {
191 if (j++ > 2)
192 {
193 BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);
194 goto err;
195 }
196 if (!BN_usub(r,r,&(recp->N))) goto err;
197 if (!BN_add_word(d,1)) goto err;
198 }
199#endif
200
201 r->neg=BN_is_zero(r)?0:m->neg;
202 d->neg=m->neg^recp->N.neg;
203 ret=1;
204err:
205 BN_CTX_end(ctx);
206 return(ret);
207 }
208
209/* len is the expected size of the result
210 * We actually calculate with an extra word of precision, so
211 * we can do faster division if the remainder is not required.
212 */
213/* r := 2^len / m */
214int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx)
215 {
216 int ret= -1;
217 BIGNUM t;
218
219 BN_init(&t);
220
221 if (!BN_zero(&t)) goto err;
222 if (!BN_set_bit(&t,len)) goto err;
223
224 if (!BN_div(r,NULL,&t,m,ctx)) goto err;
225
226 ret=len;
227err:
228 BN_free(&t);
229 return(ret);
230 }
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c
deleted file mode 100644
index 70f785ea18..0000000000
--- a/src/lib/libcrypto/bn/bn_shift.c
+++ /dev/null
@@ -1,205 +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, const 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, const 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 nw=n/BN_BITS2;
132 if (bn_wexpand(r,a->top+nw+1) == NULL) return(0);
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, const 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 || a->top == 0)
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 else
176 {
177 if (n == 0)
178 return 1; /* or the copying loop will go berserk */
179 }
180
181 f= &(a->d[nw]);
182 t=r->d;
183 j=a->top-nw;
184 r->top=j;
185
186 if (rb == 0)
187 {
188 for (i=j+1; i > 0; i--)
189 *(t++)= *(f++);
190 }
191 else
192 {
193 l= *(f++);
194 for (i=1; i<j; i++)
195 {
196 tmp =(l>>rb)&BN_MASK2;
197 l= *(f++);
198 *(t++) =(tmp|(l<<lb))&BN_MASK2;
199 }
200 *(t++) =(l>>rb)&BN_MASK2;
201 }
202 *t=0;
203 bn_fix_top(r);
204 return(1);
205 }
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
deleted file mode 100644
index c1d0cca438..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, const BIGNUM *a, BN_CTX *ctx)
66 {
67 int max,al;
68 int ret = 0;
69 BIGNUM *tmp,*rr;
70
71#ifdef BN_COUNT
72 fprintf(stderr,"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 if (al == 4)
92 {
93#ifndef BN_SQR_COMBA
94 BN_ULONG t[8];
95 bn_sqr_normal(rr->d,a->d,4,t);
96#else
97 bn_sqr_comba4(rr->d,a->d);
98#endif
99 }
100 else if (al == 8)
101 {
102#ifndef BN_SQR_COMBA
103 BN_ULONG t[16];
104 bn_sqr_normal(rr->d,a->d,8,t);
105#else
106 bn_sqr_comba8(rr->d,a->d);
107#endif
108 }
109 else
110 {
111#if defined(BN_RECURSION)
112 if (al < BN_SQR_RECURSIVE_SIZE_NORMAL)
113 {
114 BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];
115 bn_sqr_normal(rr->d,a->d,al,t);
116 }
117 else
118 {
119 int j,k;
120
121 j=BN_num_bits_word((BN_ULONG)al);
122 j=1<<(j-1);
123 k=j+j;
124 if (al == j)
125 {
126 if (bn_wexpand(tmp,k*2) == NULL) goto err;
127 bn_sqr_recursive(rr->d,a->d,al,tmp->d);
128 }
129 else
130 {
131 if (bn_wexpand(tmp,max) == NULL) goto err;
132 bn_sqr_normal(rr->d,a->d,al,tmp->d);
133 }
134 }
135#else
136 if (bn_wexpand(tmp,max) == NULL) goto err;
137 bn_sqr_normal(rr->d,a->d,al,tmp->d);
138#endif
139 }
140
141 rr->top=max;
142 rr->neg=0;
143 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
144 if (rr != r) BN_copy(r,rr);
145 ret = 1;
146 err:
147 BN_CTX_end(ctx);
148 return(ret);
149 }
150
151/* tmp must have 2*n words */
152void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
153 {
154 int i,j,max;
155 const BN_ULONG *ap;
156 BN_ULONG *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. (There's not actually a 'b' here ...)
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, const 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
207 fprintf(stderr," 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,n2*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_sqrt.c b/src/lib/libcrypto/bn/bn_sqrt.c
deleted file mode 100644
index e2a1105dc8..0000000000
--- a/src/lib/libcrypto/bn/bn_sqrt.c
+++ /dev/null
@@ -1,387 +0,0 @@
1/* crypto/bn/bn_mod.c */
2/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * and Bodo Moeller for the OpenSSL project. */
4/* ====================================================================
5 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include "cryptlib.h"
59#include "bn_lcl.h"
60
61
62BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
63/* Returns 'ret' such that
64 * ret^2 == a (mod p),
65 * using the Tonelli/Shanks algorithm (cf. Henri Cohen, "A Course
66 * in Algebraic Computational Number Theory", algorithm 1.5.1).
67 * 'p' must be prime!
68 * If 'a' is not a square, this is not necessarily detected by
69 * the algorithms; a bogus result must be expected in this case.
70 */
71 {
72 BIGNUM *ret = in;
73 int err = 1;
74 int r;
75 BIGNUM *b, *q, *t, *x, *y;
76 int e, i, j;
77
78 if (!BN_is_odd(p) || BN_abs_is_word(p, 1))
79 {
80 if (BN_abs_is_word(p, 2))
81 {
82 if (ret == NULL)
83 ret = BN_new();
84 if (ret == NULL)
85 goto end;
86 if (!BN_set_word(ret, BN_is_bit_set(a, 0)))
87 {
88 BN_free(ret);
89 return NULL;
90 }
91 return ret;
92 }
93
94 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
95 return(NULL);
96 }
97
98 if (BN_is_zero(a) || BN_is_one(a))
99 {
100 if (ret == NULL)
101 ret = BN_new();
102 if (ret == NULL)
103 goto end;
104 if (!BN_set_word(ret, BN_is_one(a)))
105 {
106 BN_free(ret);
107 return NULL;
108 }
109 return ret;
110 }
111
112#if 0 /* if BN_mod_sqrt is used with correct input, this just wastes time */
113 r = BN_kronecker(a, p, ctx);
114 if (r < -1) return NULL;
115 if (r == -1)
116 {
117 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
118 return(NULL);
119 }
120#endif
121
122 BN_CTX_start(ctx);
123 b = BN_CTX_get(ctx);
124 q = BN_CTX_get(ctx);
125 t = BN_CTX_get(ctx);
126 x = BN_CTX_get(ctx);
127 y = BN_CTX_get(ctx);
128 if (y == NULL) goto end;
129
130 if (ret == NULL)
131 ret = BN_new();
132 if (ret == NULL) goto end;
133
134 /* now write |p| - 1 as 2^e*q where q is odd */
135 e = 1;
136 while (!BN_is_bit_set(p, e))
137 e++;
138 /* we'll set q later (if needed) */
139
140 if (e == 1)
141 {
142 /* The easy case: (|p|-1)/2 is odd, so 2 has an inverse
143 * modulo (|p|-1)/2, and square roots can be computed
144 * directly by modular exponentiation.
145 * We have
146 * 2 * (|p|+1)/4 == 1 (mod (|p|-1)/2),
147 * so we can use exponent (|p|+1)/4, i.e. (|p|-3)/4 + 1.
148 */
149 if (!BN_rshift(q, p, 2)) goto end;
150 q->neg = 0;
151 if (!BN_add_word(q, 1)) goto end;
152 if (!BN_mod_exp(ret, a, q, p, ctx)) goto end;
153 err = 0;
154 goto end;
155 }
156
157 if (e == 2)
158 {
159 /* |p| == 5 (mod 8)
160 *
161 * In this case 2 is always a non-square since
162 * Legendre(2,p) = (-1)^((p^2-1)/8) for any odd prime.
163 * So if a really is a square, then 2*a is a non-square.
164 * Thus for
165 * b := (2*a)^((|p|-5)/8),
166 * i := (2*a)*b^2
167 * we have
168 * i^2 = (2*a)^((1 + (|p|-5)/4)*2)
169 * = (2*a)^((p-1)/2)
170 * = -1;
171 * so if we set
172 * x := a*b*(i-1),
173 * then
174 * x^2 = a^2 * b^2 * (i^2 - 2*i + 1)
175 * = a^2 * b^2 * (-2*i)
176 * = a*(-i)*(2*a*b^2)
177 * = a*(-i)*i
178 * = a.
179 *
180 * (This is due to A.O.L. Atkin,
181 * <URL: http://listserv.nodak.edu/scripts/wa.exe?A2=ind9211&L=nmbrthry&O=T&P=562>,
182 * November 1992.)
183 */
184
185 /* make sure that a is reduced modulo p */
186 if (a->neg || BN_ucmp(a, p) >= 0)
187 {
188 if (!BN_nnmod(x, a, p, ctx)) goto end;
189 a = x; /* use x as temporary variable */
190 }
191
192 /* t := 2*a */
193 if (!BN_mod_lshift1_quick(t, a, p)) goto end;
194
195 /* b := (2*a)^((|p|-5)/8) */
196 if (!BN_rshift(q, p, 3)) goto end;
197 q->neg = 0;
198 if (!BN_mod_exp(b, t, q, p, ctx)) goto end;
199
200 /* y := b^2 */
201 if (!BN_mod_sqr(y, b, p, ctx)) goto end;
202
203 /* t := (2*a)*b^2 - 1*/
204 if (!BN_mod_mul(t, t, y, p, ctx)) goto end;
205 if (!BN_sub_word(t, 1)) goto end;
206
207 /* x = a*b*t */
208 if (!BN_mod_mul(x, a, b, p, ctx)) goto end;
209 if (!BN_mod_mul(x, x, t, p, ctx)) goto end;
210
211 if (!BN_copy(ret, x)) goto end;
212 err = 0;
213 goto end;
214 }
215
216 /* e > 2, so we really have to use the Tonelli/Shanks algorithm.
217 * First, find some y that is not a square. */
218 if (!BN_copy(q, p)) goto end; /* use 'q' as temp */
219 q->neg = 0;
220 i = 2;
221 do
222 {
223 /* For efficiency, try small numbers first;
224 * if this fails, try random numbers.
225 */
226 if (i < 22)
227 {
228 if (!BN_set_word(y, i)) goto end;
229 }
230 else
231 {
232 if (!BN_pseudo_rand(y, BN_num_bits(p), 0, 0)) goto end;
233 if (BN_ucmp(y, p) >= 0)
234 {
235 if (!(p->neg ? BN_add : BN_sub)(y, y, p)) goto end;
236 }
237 /* now 0 <= y < |p| */
238 if (BN_is_zero(y))
239 if (!BN_set_word(y, i)) goto end;
240 }
241
242 r = BN_kronecker(y, q, ctx); /* here 'q' is |p| */
243 if (r < -1) goto end;
244 if (r == 0)
245 {
246 /* m divides p */
247 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
248 goto end;
249 }
250 }
251 while (r == 1 && ++i < 82);
252
253 if (r != -1)
254 {
255 /* Many rounds and still no non-square -- this is more likely
256 * a bug than just bad luck.
257 * Even if p is not prime, we should have found some y
258 * such that r == -1.
259 */
260 BNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);
261 goto end;
262 }
263
264 /* Here's our actual 'q': */
265 if (!BN_rshift(q, q, e)) goto end;
266
267 /* Now that we have some non-square, we can find an element
268 * of order 2^e by computing its q'th power. */
269 if (!BN_mod_exp(y, y, q, p, ctx)) goto end;
270 if (BN_is_one(y))
271 {
272 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);
273 goto end;
274 }
275
276 /* Now we know that (if p is indeed prime) there is an integer
277 * k, 0 <= k < 2^e, such that
278 *
279 * a^q * y^k == 1 (mod p).
280 *
281 * As a^q is a square and y is not, k must be even.
282 * q+1 is even, too, so there is an element
283 *
284 * X := a^((q+1)/2) * y^(k/2),
285 *
286 * and it satisfies
287 *
288 * X^2 = a^q * a * y^k
289 * = a,
290 *
291 * so it is the square root that we are looking for.
292 */
293
294 /* t := (q-1)/2 (note that q is odd) */
295 if (!BN_rshift1(t, q)) goto end;
296
297 /* x := a^((q-1)/2) */
298 if (BN_is_zero(t)) /* special case: p = 2^e + 1 */
299 {
300 if (!BN_nnmod(t, a, p, ctx)) goto end;
301 if (BN_is_zero(t))
302 {
303 /* special case: a == 0 (mod p) */
304 if (!BN_zero(ret)) goto end;
305 err = 0;
306 goto end;
307 }
308 else
309 if (!BN_one(x)) goto end;
310 }
311 else
312 {
313 if (!BN_mod_exp(x, a, t, p, ctx)) goto end;
314 if (BN_is_zero(x))
315 {
316 /* special case: a == 0 (mod p) */
317 if (!BN_zero(ret)) goto end;
318 err = 0;
319 goto end;
320 }
321 }
322
323 /* b := a*x^2 (= a^q) */
324 if (!BN_mod_sqr(b, x, p, ctx)) goto end;
325 if (!BN_mod_mul(b, b, a, p, ctx)) goto end;
326
327 /* x := a*x (= a^((q+1)/2)) */
328 if (!BN_mod_mul(x, x, a, p, ctx)) goto end;
329
330 while (1)
331 {
332 /* Now b is a^q * y^k for some even k (0 <= k < 2^E
333 * where E refers to the original value of e, which we
334 * don't keep in a variable), and x is a^((q+1)/2) * y^(k/2).
335 *
336 * We have a*b = x^2,
337 * y^2^(e-1) = -1,
338 * b^2^(e-1) = 1.
339 */
340
341 if (BN_is_one(b))
342 {
343 if (!BN_copy(ret, x)) goto end;
344 err = 0;
345 goto end;
346 }
347
348
349 /* find smallest i such that b^(2^i) = 1 */
350 i = 1;
351 if (!BN_mod_sqr(t, b, p, ctx)) goto end;
352 while (!BN_is_one(t))
353 {
354 i++;
355 if (i == e)
356 {
357 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
358 goto end;
359 }
360 if (!BN_mod_mul(t, t, t, p, ctx)) goto end;
361 }
362
363
364 /* t := y^2^(e - i - 1) */
365 if (!BN_copy(t, y)) goto end;
366 for (j = e - i - 1; j > 0; j--)
367 {
368 if (!BN_mod_sqr(t, t, p, ctx)) goto end;
369 }
370 if (!BN_mod_mul(y, t, t, p, ctx)) goto end;
371 if (!BN_mod_mul(x, x, t, p, ctx)) goto end;
372 if (!BN_mod_mul(b, b, y, p, ctx)) goto end;
373 e = i;
374 }
375
376 end:
377 if (err)
378 {
379 if (ret != NULL && ret != in)
380 {
381 BN_clear_free(ret);
382 }
383 ret = NULL;
384 }
385 BN_CTX_end(ctx);
386 return ret;
387 }
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
deleted file mode 100644
index de610ce54c..0000000000
--- a/src/lib/libcrypto/bn/bn_word.c
+++ /dev/null
@@ -1,208 +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 ((w & BN_MASK2) == 0)
114 return(1);
115
116 if (a->neg)
117 {
118 a->neg=0;
119 i=BN_sub_word(a,w);
120 if (!BN_is_zero(a))
121 a->neg=!(a->neg);
122 return(i);
123 }
124 w&=BN_MASK2;
125 if (bn_wexpand(a,a->top+1) == NULL) return(0);
126 i=0;
127 for (;;)
128 {
129 if (i >= a->top)
130 l=w;
131 else
132 l=(a->d[i]+(BN_ULONG)w)&BN_MASK2;
133 a->d[i]=l;
134 if (w > l)
135 w=1;
136 else
137 break;
138 i++;
139 }
140 if (i >= a->top)
141 a->top++;
142 return(1);
143 }
144
145int BN_sub_word(BIGNUM *a, BN_ULONG w)
146 {
147 int i;
148
149 if ((w & BN_MASK2) == 0)
150 return(1);
151
152 if (BN_is_zero(a) || a->neg)
153 {
154 a->neg=0;
155 i=BN_add_word(a,w);
156 a->neg=1;
157 return(i);
158 }
159
160 w&=BN_MASK2;
161 if ((a->top == 1) && (a->d[0] < w))
162 {
163 a->d[0]=w-a->d[0];
164 a->neg=1;
165 return(1);
166 }
167 i=0;
168 for (;;)
169 {
170 if (a->d[i] >= w)
171 {
172 a->d[i]-=w;
173 break;
174 }
175 else
176 {
177 a->d[i]=(a->d[i]-w)&BN_MASK2;
178 i++;
179 w=1;
180 }
181 }
182 if ((a->d[i] == 0) && (i == (a->top-1)))
183 a->top--;
184 return(1);
185 }
186
187int BN_mul_word(BIGNUM *a, BN_ULONG w)
188 {
189 BN_ULONG ll;
190
191 w&=BN_MASK2;
192 if (a->top)
193 {
194 if (w == 0)
195 BN_zero(a);
196 else
197 {
198 ll=bn_mul_words(a->d,a->d,a->top,w);
199 if (ll)
200 {
201 if (bn_wexpand(a,a->top+1) == NULL) return(0);
202 a->d[a->top++]=ll;
203 }
204 }
205 }
206 return(1);
207 }
208
diff --git a/src/lib/libcrypto/bn/bn_x931p.c b/src/lib/libcrypto/bn/bn_x931p.c
deleted file mode 100644
index c64410dd3a..0000000000
--- a/src/lib/libcrypto/bn/bn_x931p.c
+++ /dev/null
@@ -1,282 +0,0 @@
1/* bn_x931p.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2005.
4 */
5/* ====================================================================
6 * Copyright (c) 2005 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/bn.h>
61
62#ifdef OPENSSL_FIPS
63
64/* X9.31 routines for prime derivation */
65
66
67/* X9.31 prime derivation. This is used to generate the primes pi
68 * (p1, p2, q1, q2) from a parameter Xpi by checking successive odd
69 * integers.
70 */
71
72static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx,
73 void (*cb)(int, int, void *), void *cb_arg)
74 {
75 int i = 0;
76 if (!BN_copy(pi, Xpi))
77 return 0;
78 if (!BN_is_odd(pi) && !BN_add_word(pi, 1))
79 return 0;
80 for(;;)
81 {
82 i++;
83 if (cb)
84 cb(0, i, cb_arg);
85 /* NB 27 MR is specificed in X9.31 */
86 if (BN_is_prime_fasttest(pi, 27, cb, ctx, cb_arg, 1))
87 break;
88 if (!BN_add_word(pi, 2))
89 return 0;
90 }
91 if (cb)
92 cb(2, i, cb_arg);
93 return 1;
94 }
95
96/* This is the main X9.31 prime derivation function. From parameters
97 * Xp1, Xp2 and Xp derive the prime p. If the parameters p1 or p2 are
98 * not NULL they will be returned too: this is needed for testing.
99 */
100
101int BN_X931_derive_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
102 void (*cb)(int, int, void *), void *cb_arg,
103 const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2,
104 const BIGNUM *e, BN_CTX *ctx)
105 {
106 int ret = 0;
107
108 BIGNUM *t, *p1p2, *pm1;
109
110 /* Only even e supported */
111 if (!BN_is_odd(e))
112 return 0;
113
114 BN_CTX_start(ctx);
115 if (!p1)
116 p1 = BN_CTX_get(ctx);
117
118 if (!p2)
119 p2 = BN_CTX_get(ctx);
120
121 t = BN_CTX_get(ctx);
122
123 p1p2 = BN_CTX_get(ctx);
124
125 pm1 = BN_CTX_get(ctx);
126
127 if (!bn_x931_derive_pi(p1, Xp1, ctx, cb, cb_arg))
128 goto err;
129
130 if (!bn_x931_derive_pi(p2, Xp2, ctx, cb, cb_arg))
131 goto err;
132
133 if (!BN_mul(p1p2, p1, p2, ctx))
134 goto err;
135
136 /* First set p to value of Rp */
137
138 if (!BN_mod_inverse(p, p2, p1, ctx))
139 goto err;
140
141 if (!BN_mul(p, p, p2, ctx))
142 goto err;
143
144 if (!BN_mod_inverse(t, p1, p2, ctx))
145 goto err;
146
147 if (!BN_mul(t, t, p1, ctx))
148 goto err;
149
150 if (!BN_sub(p, p, t))
151 goto err;
152
153 if (p->neg && !BN_add(p, p, p1p2))
154 goto err;
155
156 /* p now equals Rp */
157
158 if (!BN_mod_sub(p, p, Xp, p1p2, ctx))
159 goto err;
160
161 if (!BN_add(p, p, Xp))
162 goto err;
163
164 /* p now equals Yp0 */
165
166 for (;;)
167 {
168 int i = 1;
169 if (cb)
170 cb(0, i++, cb_arg);
171 if (!BN_copy(pm1, p))
172 goto err;
173 if (!BN_sub_word(pm1, 1))
174 goto err;
175 if (!BN_gcd(t, pm1, e, ctx))
176 goto err;
177 if (BN_is_one(t)
178 /* X9.31 specifies 8 MR and 1 Lucas test or any prime test
179 * offering similar or better guarantees 50 MR is considerably
180 * better.
181 */
182 && BN_is_prime_fasttest(p, 50, cb, ctx, cb_arg, 1))
183 break;
184 if (!BN_add(p, p, p1p2))
185 goto err;
186 }
187
188 if (cb)
189 cb(3, 0, cb_arg);
190
191 ret = 1;
192
193 err:
194
195 BN_CTX_end(ctx);
196
197 return ret;
198 }
199
200/* Generate pair of paramters Xp, Xq for X9.31 prime generation.
201 * Note: nbits paramter is sum of number of bits in both.
202 */
203
204int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)
205 {
206 BIGNUM *t;
207 int i;
208 /* Number of bits for each prime is of the form
209 * 512+128s for s = 0, 1, ...
210 */
211 if ((nbits < 1024) || (nbits & 0xff))
212 return 0;
213 nbits >>= 1;
214 /* The random value Xp must be between sqrt(2) * 2^(nbits-1) and
215 * 2^nbits - 1. By setting the top two bits we ensure that the lower
216 * bound is exceeded.
217 */
218 if (!BN_rand(Xp, nbits, 1, 0))
219 return 0;
220
221 BN_CTX_start(ctx);
222 t = BN_CTX_get(ctx);
223
224 for (i = 0; i < 1000; i++)
225 {
226 if (!BN_rand(Xq, nbits, 1, 0))
227 return 0;
228 /* Check that |Xp - Xq| > 2^(nbits - 100) */
229 BN_sub(t, Xp, Xq);
230 if (BN_num_bits(t) > (nbits - 100))
231 break;
232 }
233
234 BN_CTX_end(ctx);
235
236 if (i < 1000)
237 return 1;
238
239 return 0;
240
241 }
242
243/* Generate primes using X9.31 algorithm. Of the values p, p1, p2, Xp1
244 * and Xp2 only 'p' needs to be non-NULL. If any of the others are not NULL
245 * the relevant parameter will be stored in it.
246 *
247 * Due to the fact that |Xp - Xq| > 2^(nbits - 100) must be satisfied Xp and Xq
248 * are generated using the previous function and supplied as input.
249 */
250
251int BN_X931_generate_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
252 BIGNUM *Xp1, BIGNUM *Xp2,
253 const BIGNUM *Xp,
254 const BIGNUM *e, BN_CTX *ctx,
255 void (*cb)(int, int, void *), void *cb_arg)
256 {
257 int ret = 0;
258
259 BN_CTX_start(ctx);
260 if (!Xp1)
261 Xp1 = BN_CTX_get(ctx);
262 if (!Xp2)
263 Xp2 = BN_CTX_get(ctx);
264
265 if (!BN_rand(Xp1, 101, 0, 0))
266 goto error;
267 if (!BN_rand(Xp2, 101, 0, 0))
268 goto error;
269 if (!BN_X931_derive_prime(p, p1, p2, cb, cb_arg,
270 Xp, Xp1, Xp2, e, ctx))
271 goto error;
272
273 ret = 1;
274
275 error:
276 BN_CTX_end(ctx);
277
278 return ret;
279
280 }
281
282#endif
diff --git a/src/lib/libcrypto/buffer/buf_err.c b/src/lib/libcrypto/buffer/buf_err.c
deleted file mode 100644
index 1fc32a6861..0000000000
--- a/src/lib/libcrypto/buffer/buf_err.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/* crypto/buffer/buf_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_BUF,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BUF,0,reason)
70
71static ERR_STRING_DATA BUF_str_functs[]=
72 {
73{ERR_FUNC(BUF_F_BUF_MEM_GROW), "BUF_MEM_grow"},
74{ERR_FUNC(BUF_F_BUF_MEM_NEW), "BUF_MEM_new"},
75{ERR_FUNC(BUF_F_BUF_STRDUP), "BUF_strdup"},
76{0,NULL}
77 };
78
79static ERR_STRING_DATA BUF_str_reasons[]=
80 {
81{0,NULL}
82 };
83
84#endif
85
86void ERR_load_BUF_strings(void)
87 {
88 static int init=1;
89
90 if (init)
91 {
92 init=0;
93#ifndef OPENSSL_NO_ERR
94 ERR_load_strings(0,BUF_str_functs);
95 ERR_load_strings(0,BUF_str_reasons);
96#endif
97
98 }
99 }
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c
deleted file mode 100644
index d96487e7db..0000000000
--- a/src/lib/libcrypto/buffer/buffer.c
+++ /dev/null
@@ -1,202 +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=OPENSSL_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 OPENSSL_free(a->data);
88 }
89 OPENSSL_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=OPENSSL_malloc(n);
111 else
112 ret=OPENSSL_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->max=n;
122 memset(&str->data[str->length],0,len-str->length);
123 str->length=len;
124 }
125 return(len);
126 }
127
128int BUF_MEM_grow_clean(BUF_MEM *str, int len)
129 {
130 char *ret;
131 unsigned int n;
132
133 if (str->length >= len)
134 {
135 memset(&str->data[len],0,str->length-len);
136 str->length=len;
137 return(len);
138 }
139 if (str->max >= len)
140 {
141 memset(&str->data[str->length],0,len-str->length);
142 str->length=len;
143 return(len);
144 }
145 n=(len+3)/3*4;
146 if (str->data == NULL)
147 ret=OPENSSL_malloc(n);
148 else
149 ret=OPENSSL_realloc_clean(str->data,str->max,n);
150 if (ret == NULL)
151 {
152 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
153 len=0;
154 }
155 else
156 {
157 str->data=ret;
158 str->max=n;
159 memset(&str->data[str->length],0,len-str->length);
160 str->length=len;
161 }
162 return(len);
163 }
164
165char *BUF_strdup(const char *str)
166 {
167 char *ret;
168 int n;
169
170 if (str == NULL) return(NULL);
171
172 n=strlen(str);
173 ret=OPENSSL_malloc(n+1);
174 if (ret == NULL)
175 {
176 BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);
177 return(NULL);
178 }
179 memcpy(ret,str,n+1);
180 return(ret);
181 }
182
183size_t BUF_strlcpy(char *dst, const char *src, size_t size)
184 {
185 size_t l = 0;
186 for(; size > 1 && *src; size--)
187 {
188 *dst++ = *src++;
189 l++;
190 }
191 if (size)
192 *dst = '\0';
193 return l + strlen(src);
194 }
195
196size_t BUF_strlcat(char *dst, const char *src, size_t size)
197 {
198 size_t l = 0;
199 for(; size > 0 && *dst; size--, dst++)
200 l++;
201 return l + BUF_strlcpy(dst, src, size);
202 }
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h
deleted file mode 100644
index 465dc34f3f..0000000000
--- a/src/lib/libcrypto/buffer/buffer.h
+++ /dev/null
@@ -1,105 +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
66#include <stddef.h>
67#include <sys/types.h>
68
69typedef struct buf_mem_st
70 {
71 int length; /* current number of bytes */
72 char *data;
73 int max; /* size of buffer */
74 } BUF_MEM;
75
76BUF_MEM *BUF_MEM_new(void);
77void BUF_MEM_free(BUF_MEM *a);
78int BUF_MEM_grow(BUF_MEM *str, int len);
79int BUF_MEM_grow_clean(BUF_MEM *str, int len);
80char * BUF_strdup(const char *str);
81
82/* safe string functions */
83size_t BUF_strlcpy(char *dst,const char *src,size_t siz);
84size_t BUF_strlcat(char *dst,const char *src,size_t siz);
85
86
87/* BEGIN ERROR CODES */
88/* The following lines are auto generated by the script mkerr.pl. Any changes
89 * made after this point may be overwritten when the script is next run.
90 */
91void ERR_load_BUF_strings(void);
92
93/* Error codes for the BUF functions. */
94
95/* Function codes. */
96#define BUF_F_BUF_MEM_GROW 100
97#define BUF_F_BUF_MEM_NEW 101
98#define BUF_F_BUF_STRDUP 102
99
100/* Reason codes. */
101
102#ifdef __cplusplus
103}
104#endif
105#endif
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 0ed55d1905..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) unless $main'openbsd;
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 e80f65b698..0000000000
--- a/src/lib/libcrypto/cast/c_enc.c
+++ /dev/null
@@ -1,209 +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
62#ifndef OPENBSD_CAST_ASM
63void CAST_encrypt(CAST_LONG *data, CAST_KEY *key)
64 {
65 register CAST_LONG l,r,*k,t;
66
67 k= &(key->data[0]);
68 l=data[0];
69 r=data[1];
70
71 E_CAST( 0,k,l,r,+,^,-);
72 E_CAST( 1,k,r,l,^,-,+);
73 E_CAST( 2,k,l,r,-,+,^);
74 E_CAST( 3,k,r,l,+,^,-);
75 E_CAST( 4,k,l,r,^,-,+);
76 E_CAST( 5,k,r,l,-,+,^);
77 E_CAST( 6,k,l,r,+,^,-);
78 E_CAST( 7,k,r,l,^,-,+);
79 E_CAST( 8,k,l,r,-,+,^);
80 E_CAST( 9,k,r,l,+,^,-);
81 E_CAST(10,k,l,r,^,-,+);
82 E_CAST(11,k,r,l,-,+,^);
83 if(!key->short_key)
84 {
85 E_CAST(12,k,l,r,+,^,-);
86 E_CAST(13,k,r,l,^,-,+);
87 E_CAST(14,k,l,r,-,+,^);
88 E_CAST(15,k,r,l,+,^,-);
89 }
90
91 data[1]=l&0xffffffffL;
92 data[0]=r&0xffffffffL;
93 }
94
95void CAST_decrypt(CAST_LONG *data, CAST_KEY *key)
96 {
97 register CAST_LONG l,r,*k,t;
98
99 k= &(key->data[0]);
100 l=data[0];
101 r=data[1];
102
103 if(!key->short_key)
104 {
105 E_CAST(15,k,l,r,+,^,-);
106 E_CAST(14,k,r,l,-,+,^);
107 E_CAST(13,k,l,r,^,-,+);
108 E_CAST(12,k,r,l,+,^,-);
109 }
110 E_CAST(11,k,l,r,-,+,^);
111 E_CAST(10,k,r,l,^,-,+);
112 E_CAST( 9,k,l,r,+,^,-);
113 E_CAST( 8,k,r,l,-,+,^);
114 E_CAST( 7,k,l,r,^,-,+);
115 E_CAST( 6,k,r,l,+,^,-);
116 E_CAST( 5,k,l,r,-,+,^);
117 E_CAST( 4,k,r,l,^,-,+);
118 E_CAST( 3,k,l,r,+,^,-);
119 E_CAST( 2,k,r,l,-,+,^);
120 E_CAST( 1,k,l,r,^,-,+);
121 E_CAST( 0,k,r,l,+,^,-);
122
123 data[1]=l&0xffffffffL;
124 data[0]=r&0xffffffffL;
125 }
126#endif
127
128void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
129 CAST_KEY *ks, unsigned char *iv, int enc)
130 {
131 register CAST_LONG tin0,tin1;
132 register CAST_LONG tout0,tout1,xor0,xor1;
133 register long l=length;
134 CAST_LONG tin[2];
135
136 if (enc)
137 {
138 n2l(iv,tout0);
139 n2l(iv,tout1);
140 iv-=8;
141 for (l-=8; l>=0; l-=8)
142 {
143 n2l(in,tin0);
144 n2l(in,tin1);
145 tin0^=tout0;
146 tin1^=tout1;
147 tin[0]=tin0;
148 tin[1]=tin1;
149 CAST_encrypt(tin,ks);
150 tout0=tin[0];
151 tout1=tin[1];
152 l2n(tout0,out);
153 l2n(tout1,out);
154 }
155 if (l != -8)
156 {
157 n2ln(in,tin0,tin1,l+8);
158 tin0^=tout0;
159 tin1^=tout1;
160 tin[0]=tin0;
161 tin[1]=tin1;
162 CAST_encrypt(tin,ks);
163 tout0=tin[0];
164 tout1=tin[1];
165 l2n(tout0,out);
166 l2n(tout1,out);
167 }
168 l2n(tout0,iv);
169 l2n(tout1,iv);
170 }
171 else
172 {
173 n2l(iv,xor0);
174 n2l(iv,xor1);
175 iv-=8;
176 for (l-=8; l>=0; l-=8)
177 {
178 n2l(in,tin0);
179 n2l(in,tin1);
180 tin[0]=tin0;
181 tin[1]=tin1;
182 CAST_decrypt(tin,ks);
183 tout0=tin[0]^xor0;
184 tout1=tin[1]^xor1;
185 l2n(tout0,out);
186 l2n(tout1,out);
187 xor0=tin0;
188 xor1=tin1;
189 }
190 if (l != -8)
191 {
192 n2l(in,tin0);
193 n2l(in,tin1);
194 tin[0]=tin0;
195 tin[1]=tin1;
196 CAST_decrypt(tin,ks);
197 tout0=tin[0]^xor0;
198 tout1=tin[1]^xor1;
199 l2nn(tout0,tout1,out,l+8);
200 xor0=tin0;
201 xor1=tin1;
202 }
203 l2n(xor0,iv);
204 l2n(xor1,iv);
205 }
206 tin0=tin1=tout0=tout1=xor0=xor1=0;
207 tin[0]=tin[1]=0;
208 }
209
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 db9b7573e0..0000000000
--- a/src/lib/libcrypto/cast/c_skey.c
+++ /dev/null
@@ -1,169 +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/crypto.h>
60#include <openssl/fips.h>
61#include <openssl/cast.h>
62
63#include "cast_lcl.h"
64#include "cast_s.h"
65
66#define CAST_exp(l,A,a,n) \
67 A[n/4]=l; \
68 a[n+3]=(l )&0xff; \
69 a[n+2]=(l>> 8)&0xff; \
70 a[n+1]=(l>>16)&0xff; \
71 a[n+0]=(l>>24)&0xff;
72
73#define S4 CAST_S_table4
74#define S5 CAST_S_table5
75#define S6 CAST_S_table6
76#define S7 CAST_S_table7
77
78FIPS_NON_FIPS_VCIPHER_Init(CAST)
79 {
80 CAST_LONG x[16];
81 CAST_LONG z[16];
82 CAST_LONG k[32];
83 CAST_LONG X[4],Z[4];
84 CAST_LONG l,*K;
85 int i;
86
87 for (i=0; i<16; i++) x[i]=0;
88 if (len > 16) len=16;
89 for (i=0; i<len; i++)
90 x[i]=data[i];
91 if(len <= 10)
92 key->short_key=1;
93 else
94 key->short_key=0;
95
96 K= &k[0];
97 X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL;
98 X[1]=((x[ 4]<<24)|(x[ 5]<<16)|(x[ 6]<<8)|x[ 7])&0xffffffffL;
99 X[2]=((x[ 8]<<24)|(x[ 9]<<16)|(x[10]<<8)|x[11])&0xffffffffL;
100 X[3]=((x[12]<<24)|(x[13]<<16)|(x[14]<<8)|x[15])&0xffffffffL;
101
102 for (;;)
103 {
104 l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
105 CAST_exp(l,Z,z, 0);
106 l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
107 CAST_exp(l,Z,z, 4);
108 l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
109 CAST_exp(l,Z,z, 8);
110 l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
111 CAST_exp(l,Z,z,12);
112
113 K[ 0]= S4[z[ 8]]^S5[z[ 9]]^S6[z[ 7]]^S7[z[ 6]]^S4[z[ 2]];
114 K[ 1]= S4[z[10]]^S5[z[11]]^S6[z[ 5]]^S7[z[ 4]]^S5[z[ 6]];
115 K[ 2]= S4[z[12]]^S5[z[13]]^S6[z[ 3]]^S7[z[ 2]]^S6[z[ 9]];
116 K[ 3]= S4[z[14]]^S5[z[15]]^S6[z[ 1]]^S7[z[ 0]]^S7[z[12]];
117
118 l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
119 CAST_exp(l,X,x, 0);
120 l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
121 CAST_exp(l,X,x, 4);
122 l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
123 CAST_exp(l,X,x, 8);
124 l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
125 CAST_exp(l,X,x,12);
126
127 K[ 4]= S4[x[ 3]]^S5[x[ 2]]^S6[x[12]]^S7[x[13]]^S4[x[ 8]];
128 K[ 5]= S4[x[ 1]]^S5[x[ 0]]^S6[x[14]]^S7[x[15]]^S5[x[13]];
129 K[ 6]= S4[x[ 7]]^S5[x[ 6]]^S6[x[ 8]]^S7[x[ 9]]^S6[x[ 3]];
130 K[ 7]= S4[x[ 5]]^S5[x[ 4]]^S6[x[10]]^S7[x[11]]^S7[x[ 7]];
131
132 l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
133 CAST_exp(l,Z,z, 0);
134 l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
135 CAST_exp(l,Z,z, 4);
136 l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
137 CAST_exp(l,Z,z, 8);
138 l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
139 CAST_exp(l,Z,z,12);
140
141 K[ 8]= S4[z[ 3]]^S5[z[ 2]]^S6[z[12]]^S7[z[13]]^S4[z[ 9]];
142 K[ 9]= S4[z[ 1]]^S5[z[ 0]]^S6[z[14]]^S7[z[15]]^S5[z[12]];
143 K[10]= S4[z[ 7]]^S5[z[ 6]]^S6[z[ 8]]^S7[z[ 9]]^S6[z[ 2]];
144 K[11]= S4[z[ 5]]^S5[z[ 4]]^S6[z[10]]^S7[z[11]]^S7[z[ 6]];
145
146 l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
147 CAST_exp(l,X,x, 0);
148 l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
149 CAST_exp(l,X,x, 4);
150 l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
151 CAST_exp(l,X,x, 8);
152 l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
153 CAST_exp(l,X,x,12);
154
155 K[12]= S4[x[ 8]]^S5[x[ 9]]^S6[x[ 7]]^S7[x[ 6]]^S4[x[ 3]];
156 K[13]= S4[x[10]]^S5[x[11]]^S6[x[ 5]]^S7[x[ 4]]^S5[x[ 7]];
157 K[14]= S4[x[12]]^S5[x[13]]^S6[x[ 3]]^S7[x[ 2]]^S6[x[ 8]];
158 K[15]= S4[x[14]]^S5[x[15]]^S6[x[ 1]]^S7[x[ 0]]^S7[x[13]];
159 if (K != k) break;
160 K+=16;
161 }
162
163 for (i=0; i<16; i++)
164 {
165 key->data[i*2]=k[i];
166 key->data[i*2+1]=((k[i+16])+16)&0x1f;
167 }
168 }
169
diff --git a/src/lib/libcrypto/cast/cast.h b/src/lib/libcrypto/cast/cast.h
deleted file mode 100644
index 9e300178d9..0000000000
--- a/src/lib/libcrypto/cast/cast.h
+++ /dev/null
@@ -1,106 +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 OPENSSL_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
85#ifdef OPENSSL_FIPS
86void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
87#endif
88void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
89void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key,
90 int enc);
91void CAST_encrypt(CAST_LONG *data,CAST_KEY *key);
92void CAST_decrypt(CAST_LONG *data,CAST_KEY *key);
93void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
94 CAST_KEY *ks, unsigned char *iv, int enc);
95void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
96 long length, CAST_KEY *schedule, unsigned char *ivec,
97 int *num, int enc);
98void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
99 long length, CAST_KEY *schedule, unsigned char *ivec,
100 int *num);
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif
diff --git a/src/lib/libcrypto/cast/cast_lcl.h b/src/lib/libcrypto/cast/cast_lcl.h
deleted file mode 100644
index e756021a33..0000000000
--- a/src/lib/libcrypto/cast/cast_lcl.h
+++ /dev/null
@@ -1,227 +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
60#include "e_os.h"
61
62#ifdef OPENSSL_SYS_WIN32
63#include <stdlib.h>
64#endif
65
66
67#undef c2l
68#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
69 l|=((unsigned long)(*((c)++)))<< 8L, \
70 l|=((unsigned long)(*((c)++)))<<16L, \
71 l|=((unsigned long)(*((c)++)))<<24L)
72
73/* NOTE - c is not incremented as per c2l */
74#undef c2ln
75#define c2ln(c,l1,l2,n) { \
76 c+=n; \
77 l1=l2=0; \
78 switch (n) { \
79 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
80 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
81 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
82 case 5: l2|=((unsigned long)(*(--(c)))); \
83 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
84 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
85 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
86 case 1: l1|=((unsigned long)(*(--(c)))); \
87 } \
88 }
89
90#undef l2c
91#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
92 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
93 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
94 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
95
96/* NOTE - c is not incremented as per l2c */
97#undef l2cn
98#define l2cn(l1,l2,c,n) { \
99 c+=n; \
100 switch (n) { \
101 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
102 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
103 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
104 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
105 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
106 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
107 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
108 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
109 } \
110 }
111
112/* NOTE - c is not incremented as per n2l */
113#define n2ln(c,l1,l2,n) { \
114 c+=n; \
115 l1=l2=0; \
116 switch (n) { \
117 case 8: l2 =((unsigned long)(*(--(c)))) ; \
118 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
119 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
120 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
121 case 4: l1 =((unsigned long)(*(--(c)))) ; \
122 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
123 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
124 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
125 } \
126 }
127
128/* NOTE - c is not incremented as per l2n */
129#define l2nn(l1,l2,c,n) { \
130 c+=n; \
131 switch (n) { \
132 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
133 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
134 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
135 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
136 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
137 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
138 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
139 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
140 } \
141 }
142
143#undef n2l
144#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
145 l|=((unsigned long)(*((c)++)))<<16L, \
146 l|=((unsigned long)(*((c)++)))<< 8L, \
147 l|=((unsigned long)(*((c)++))))
148
149#undef l2n
150#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
151 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
152 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
153 *((c)++)=(unsigned char)(((l) )&0xff))
154
155#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
156#define ROTL(a,n) (_lrotl(a,n))
157#else
158#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
159#endif
160
161#define C_M 0x3fc
162#define C_0 22L
163#define C_1 14L
164#define C_2 6L
165#define C_3 2L /* left shift */
166
167/* The rotate has an extra 16 added to it to help the x86 asm */
168#if defined(CAST_PTR)
169#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
170 { \
171 int i; \
172 t=(key[n*2] OP1 R)&0xffffffffL; \
173 i=key[n*2+1]; \
174 t=ROTL(t,i); \
175 L^= (((((*(CAST_LONG *)((unsigned char *) \
176 CAST_S_table0+((t>>C_2)&C_M)) OP2 \
177 *(CAST_LONG *)((unsigned char *) \
178 CAST_S_table1+((t<<C_3)&C_M)))&0xffffffffL) OP3 \
179 *(CAST_LONG *)((unsigned char *) \
180 CAST_S_table2+((t>>C_0)&C_M)))&0xffffffffL) OP1 \
181 *(CAST_LONG *)((unsigned char *) \
182 CAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \
183 }
184#elif defined(CAST_PTR2)
185#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
186 { \
187 int i; \
188 CAST_LONG u,v,w; \
189 w=(key[n*2] OP1 R)&0xffffffffL; \
190 i=key[n*2+1]; \
191 w=ROTL(w,i); \
192 u=w>>C_2; \
193 v=w<<C_3; \
194 u&=C_M; \
195 v&=C_M; \
196 t= *(CAST_LONG *)((unsigned char *)CAST_S_table0+u); \
197 u=w>>C_0; \
198 t=(t OP2 *(CAST_LONG *)((unsigned char *)CAST_S_table1+v))&0xffffffffL;\
199 v=w>>C_1; \
200 u&=C_M; \
201 v&=C_M; \
202 t=(t OP3 *(CAST_LONG *)((unsigned char *)CAST_S_table2+u)&0xffffffffL);\
203 t=(t OP1 *(CAST_LONG *)((unsigned char *)CAST_S_table3+v)&0xffffffffL);\
204 L^=(t&0xffffffff); \
205 }
206#else
207#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
208 { \
209 CAST_LONG a,b,c,d; \
210 t=(key[n*2] OP1 R)&0xffffffff; \
211 t=ROTL(t,(key[n*2+1])); \
212 a=CAST_S_table0[(t>> 8)&0xff]; \
213 b=CAST_S_table1[(t )&0xff]; \
214 c=CAST_S_table2[(t>>24)&0xff]; \
215 d=CAST_S_table3[(t>>16)&0xff]; \
216 L^=(((((a OP2 b)&0xffffffffL) OP3 c)&0xffffffffL) OP1 d)&0xffffffffL; \
217 }
218#endif
219
220extern const CAST_LONG CAST_S_table0[256];
221extern const CAST_LONG CAST_S_table1[256];
222extern const CAST_LONG CAST_S_table2[256];
223extern const CAST_LONG CAST_S_table3[256];
224extern const CAST_LONG CAST_S_table4[256];
225extern const CAST_LONG CAST_S_table5[256];
226extern const CAST_LONG CAST_S_table6[256];
227extern 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 efd366fa22..0000000000
--- a/src/lib/libcrypto/comp/c_rle.c
+++ /dev/null
@@ -1,62 +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 NULL,
21 };
22
23COMP_METHOD *COMP_rle(void)
24 {
25 return(&rle_method);
26 }
27
28static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
29 unsigned int olen, unsigned char *in, unsigned int ilen)
30 {
31 /* int i; */
32
33 if (olen < (ilen+1))
34 {
35 /* ZZZZZZZZZZZZZZZZZZZZZZ */
36 return(-1);
37 }
38
39 *(out++)=0;
40 memcpy(out,in,ilen);
41 return(ilen+1);
42 }
43
44static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
45 unsigned int olen, unsigned char *in, unsigned int ilen)
46 {
47 int i;
48
49 if (olen < (ilen-1))
50 {
51 /* ZZZZZZZZZZZZZZZZZZZZZZ */
52 return(-1);
53 }
54
55 i= *(in++);
56 if (i == 0)
57 {
58 memcpy(out,in,ilen-1);
59 }
60 return(ilen-1);
61 }
62
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
deleted file mode 100644
index 5fcb521ffb..0000000000
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ /dev/null
@@ -1,215 +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#include <openssl/err.h>
7
8COMP_METHOD *COMP_zlib(void );
9
10static COMP_METHOD zlib_method_nozlib={
11 NID_undef,
12 "(undef)",
13 NULL,
14 NULL,
15 NULL,
16 NULL,
17 NULL,
18 NULL,
19 };
20
21#ifndef ZLIB
22#undef ZLIB_SHARED
23#else
24
25#include <zlib.h>
26
27static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
28 unsigned int olen, unsigned char *in, unsigned int ilen);
29static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
30 unsigned int olen, unsigned char *in, unsigned int ilen);
31
32static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
33 uLong sourceLen);
34
35static COMP_METHOD zlib_method={
36 NID_zlib_compression,
37 LN_zlib_compression,
38 NULL,
39 NULL,
40 zlib_compress_block,
41 zlib_expand_block,
42 NULL,
43 NULL,
44 };
45
46/*
47 * When OpenSSL is built on Windows, we do not want to require that
48 * the ZLIB.DLL be available in order for the OpenSSL DLLs to
49 * work. Therefore, all ZLIB routines are loaded at run time
50 * and we do not link to a .LIB file.
51 */
52#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
53# include <windows.h>
54#endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */
55
56#ifdef ZLIB_SHARED
57#include <openssl/dso.h>
58
59/* Function pointers */
60typedef int (*compress_ft)(Bytef *dest,uLongf *destLen,
61 const Bytef *source, uLong sourceLen);
62typedef int (*inflateEnd_ft)(z_streamp strm);
63typedef int (*inflate_ft)(z_streamp strm, int flush);
64typedef int (*inflateInit__ft)(z_streamp strm,
65 const char * version, int stream_size);
66static compress_ft p_compress=NULL;
67static inflateEnd_ft p_inflateEnd=NULL;
68static inflate_ft p_inflate=NULL;
69static inflateInit__ft p_inflateInit_=NULL;
70
71static int zlib_loaded = 0; /* only attempt to init func pts once */
72static DSO *zlib_dso = NULL;
73
74#define compress p_compress
75#define inflateEnd p_inflateEnd
76#define inflate p_inflate
77#define inflateInit_ p_inflateInit_
78#endif /* ZLIB_SHARED */
79
80static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
81 unsigned int olen, unsigned char *in, unsigned int ilen)
82 {
83 unsigned long l;
84 int i;
85 int clear=1;
86
87 if (ilen > 128)
88 {
89 out[0]=1;
90 l=olen-1;
91 i=compress(&(out[1]),&l,in,(unsigned long)ilen);
92 if (i != Z_OK)
93 return(-1);
94 if (ilen > l)
95 {
96 clear=0;
97 l++;
98 }
99 }
100 if (clear)
101 {
102 out[0]=0;
103 memcpy(&(out[1]),in,ilen);
104 l=ilen+1;
105 }
106#ifdef DEBUG_ZLIB
107 fprintf(stderr,"compress(%4d)->%4d %s\n",
108 ilen,(int)l,(clear)?"clear":"zlib");
109#endif
110 return((int)l);
111 }
112
113static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
114 unsigned int olen, unsigned char *in, unsigned int ilen)
115 {
116 unsigned long l;
117 int i;
118
119 if (in[0])
120 {
121 l=olen;
122 i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
123 if (i != Z_OK)
124 return(-1);
125 }
126 else
127 {
128 memcpy(out,&(in[1]),ilen-1);
129 l=ilen-1;
130 }
131#ifdef DEBUG_ZLIB
132 fprintf(stderr,"expand (%4d)->%4d %s\n",
133 ilen,(int)l,in[0]?"zlib":"clear");
134#endif
135 return((int)l);
136 }
137
138static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
139 uLong sourceLen)
140{
141 z_stream stream;
142 int err;
143
144 stream.next_in = (Bytef*)source;
145 stream.avail_in = (uInt)sourceLen;
146 /* Check for source > 64K on 16-bit machine: */
147 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
148
149 stream.next_out = dest;
150 stream.avail_out = (uInt)*destLen;
151 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
152
153 stream.zalloc = (alloc_func)0;
154 stream.zfree = (free_func)0;
155
156 err = inflateInit(&stream);
157 if (err != Z_OK) return err;
158
159 err = inflate(&stream, Z_FINISH);
160 if (err != Z_STREAM_END) {
161 inflateEnd(&stream);
162 return err;
163 }
164 *destLen = stream.total_out;
165
166 err = inflateEnd(&stream);
167 return err;
168}
169
170#endif
171
172COMP_METHOD *COMP_zlib(void)
173 {
174 COMP_METHOD *meth = &zlib_method_nozlib;
175
176#ifdef ZLIB_SHARED
177 if (!zlib_loaded)
178 {
179#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
180 zlib_dso = DSO_load(NULL, "ZLIB1", NULL, 0);
181#else
182 zlib_dso = DSO_load(NULL, "z", NULL, 0);
183#endif
184 if (zlib_dso != NULL)
185 {
186 p_compress
187 = (compress_ft) DSO_bind_func(zlib_dso,
188 "compress");
189 p_inflateEnd
190 = (inflateEnd_ft) DSO_bind_func(zlib_dso,
191 "inflateEnd");
192 p_inflate
193 = (inflate_ft) DSO_bind_func(zlib_dso,
194 "inflate");
195 p_inflateInit_
196 = (inflateInit__ft) DSO_bind_func(zlib_dso,
197 "inflateInit_");
198
199 if (p_compress && p_inflateEnd && p_inflate
200 && p_inflateInit_)
201 zlib_loaded++;
202 }
203 }
204
205#endif
206#ifdef ZLIB_SHARED
207 if (zlib_loaded)
208#endif
209#if defined(ZLIB) || defined(ZLIB_SHARED)
210 meth = &zlib_method;
211#endif
212
213 return(meth);
214 }
215
diff --git a/src/lib/libcrypto/comp/comp.h b/src/lib/libcrypto/comp/comp.h
deleted file mode 100644
index ab48b78ae9..0000000000
--- a/src/lib/libcrypto/comp/comp.h
+++ /dev/null
@@ -1,59 +0,0 @@
1
2#ifndef HEADER_COMP_H
3#define HEADER_COMP_H
4
5#include <openssl/crypto.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
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 );
42COMP_METHOD *COMP_zlib(void );
43
44/* BEGIN ERROR CODES */
45/* The following lines are auto generated by the script mkerr.pl. Any changes
46 * made after this point may be overwritten when the script is next run.
47 */
48void ERR_load_COMP_strings(void);
49
50/* Error codes for the COMP functions. */
51
52/* Function codes. */
53
54/* Reason codes. */
55
56#ifdef __cplusplus
57}
58#endif
59#endif
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
deleted file mode 100644
index 1652b8c2c4..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 OPENSSL_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 OPENSSL_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 beb98ce8cc..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 *)OPENSSL_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 OPENSSL_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 OPENSSL_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/README b/src/lib/libcrypto/conf/README
deleted file mode 100644
index ca58d0240f..0000000000
--- a/src/lib/libcrypto/conf/README
+++ /dev/null
@@ -1,78 +0,0 @@
1WARNING WARNING WARNING!!!
2
3This stuff is experimental, may change radically or be deleted altogether
4before OpenSSL 0.9.7 release. You have been warned!
5
6Configuration modules. These are a set of modules which can perform
7various configuration functions.
8
9Currently the routines should be called at most once when an application
10starts up: that is before it starts any threads.
11
12The routines read a configuration file set up like this:
13
14-----
15#default section
16openssl_init=init_section
17
18[init_section]
19
20module1=value1
21#Second instance of module1
22module1.1=valueX
23module2=value2
24module3=dso_literal
25module4=dso_section
26
27[dso_section]
28
29path=/some/path/to/some/dso.so
30other_stuff=other_value
31----
32
33When this file is loaded a configuration module with the specified
34string (module* in the above example) is looked up and its init
35function called as:
36
37int conf_init_func(CONF_IMODULE *md, CONF *cnf);
38
39The function can then take whatever action is appropriate, for example
40further lookups based on the value. Multiple instances of the same
41config module can be loaded.
42
43When the application closes down the modules are cleaned up by calling
44an optional finish function:
45
46void conf_finish_func(CONF_IMODULE *md);
47
48The finish functions are called in reverse order: that is the last module
49loaded is the first one cleaned up.
50
51If no module exists with a given name then an attempt is made to load
52a DSO with the supplied name. This might mean that "module3" attempts
53to load a DSO called libmodule3.so or module3.dll for example. An explicit
54DSO name can be given by including a separate section as in the module4 example
55above.
56
57The DSO is expected to at least contain an initialization function:
58
59int OPENSSL_init(CONF_IMODULE *md, CONF *cnf);
60
61and may also include a finish function:
62
63void OPENSSL_finish(CONF_IMODULE *md);
64
65Static modules can also be added using,
66
67int CONF_module_add(char *name, dso_mod_init_func *ifunc, dso_mod_finish_func *ffunc);
68
69where "name" is the name in the configuration file this function corresponds to.
70
71A set of builtin modules (currently only an ASN1 non functional test module) can be
72added by calling OPENSSL_load_builtin_modules().
73
74The function OPENSSL_config() is intended as a simple configuration function that
75any application can call to perform various default configuration tasks. It uses the
76file openssl.cnf in the usual locations.
77
78
diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h
deleted file mode 100644
index f4671442ab..0000000000
--- a/src/lib/libcrypto/conf/conf.h
+++ /dev/null
@@ -1,250 +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#include <openssl/bio.h>
63#include <openssl/lhash.h>
64#include <openssl/stack.h>
65#include <openssl/safestack.h>
66#include <openssl/e_os2.h>
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72typedef struct
73 {
74 char *section;
75 char *name;
76 char *value;
77 } CONF_VALUE;
78
79DECLARE_STACK_OF(CONF_VALUE)
80DECLARE_STACK_OF(CONF_MODULE)
81DECLARE_STACK_OF(CONF_IMODULE)
82
83struct conf_st;
84typedef struct conf_st CONF;
85struct conf_method_st;
86typedef struct conf_method_st CONF_METHOD;
87
88struct conf_method_st
89 {
90 const char *name;
91 CONF *(*create)(CONF_METHOD *meth);
92 int (*init)(CONF *conf);
93 int (*destroy)(CONF *conf);
94 int (*destroy_data)(CONF *conf);
95 int (*load_bio)(CONF *conf, BIO *bp, long *eline);
96 int (*dump)(const CONF *conf, BIO *bp);
97 int (*is_number)(const CONF *conf, char c);
98 int (*to_int)(const CONF *conf, char c);
99 int (*load)(CONF *conf, const char *name, long *eline);
100 };
101
102/* Module definitions */
103
104typedef struct conf_imodule_st CONF_IMODULE;
105typedef struct conf_module_st CONF_MODULE;
106
107/* DSO module function typedefs */
108typedef int conf_init_func(CONF_IMODULE *md, const CONF *cnf);
109typedef void conf_finish_func(CONF_IMODULE *md);
110
111#define CONF_MFLAGS_IGNORE_ERRORS 0x1
112#define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2
113#define CONF_MFLAGS_SILENT 0x4
114#define CONF_MFLAGS_NO_DSO 0x8
115#define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
116
117int CONF_set_default_method(CONF_METHOD *meth);
118void CONF_set_nconf(CONF *conf,LHASH *hash);
119LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
120#ifndef OPENSSL_NO_FP_API
121LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
122#endif
123LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
124STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section);
125char *CONF_get_string(LHASH *conf,const char *group,const char *name);
126long CONF_get_number(LHASH *conf,const char *group,const char *name);
127void CONF_free(LHASH *conf);
128int CONF_dump_fp(LHASH *conf, FILE *out);
129int CONF_dump_bio(LHASH *conf, BIO *out);
130
131void OPENSSL_config(const char *config_name);
132void OPENSSL_no_config(void);
133
134/* New conf code. The semantics are different from the functions above.
135 If that wasn't the case, the above functions would have been replaced */
136
137struct conf_st
138 {
139 CONF_METHOD *meth;
140 void *meth_data;
141 LHASH *data;
142 };
143
144CONF *NCONF_new(CONF_METHOD *meth);
145CONF_METHOD *NCONF_default(void);
146CONF_METHOD *NCONF_WIN32(void);
147#if 0 /* Just to give you an idea of what I have in mind */
148CONF_METHOD *NCONF_XML(void);
149#endif
150void NCONF_free(CONF *conf);
151void NCONF_free_data(CONF *conf);
152
153int NCONF_load(CONF *conf,const char *file,long *eline);
154#ifndef OPENSSL_NO_FP_API
155int NCONF_load_fp(CONF *conf, FILE *fp,long *eline);
156#endif
157int NCONF_load_bio(CONF *conf, BIO *bp,long *eline);
158STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section);
159char *NCONF_get_string(const CONF *conf,const char *group,const char *name);
160int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,
161 long *result);
162int NCONF_dump_fp(const CONF *conf, FILE *out);
163int NCONF_dump_bio(const CONF *conf, BIO *out);
164
165#if 0 /* The following function has no error checking,
166 and should therefore be avoided */
167long NCONF_get_number(CONF *conf,char *group,char *name);
168#else
169#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
170#endif
171
172/* Module functions */
173
174int CONF_modules_load(const CONF *cnf, const char *appname,
175 unsigned long flags);
176int CONF_modules_load_file(const char *filename, const char *appname,
177 unsigned long flags);
178void CONF_modules_unload(int all);
179void CONF_modules_finish(void);
180void CONF_modules_free(void);
181int CONF_module_add(const char *name, conf_init_func *ifunc,
182 conf_finish_func *ffunc);
183
184const char *CONF_imodule_get_name(const CONF_IMODULE *md);
185const char *CONF_imodule_get_value(const CONF_IMODULE *md);
186void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
187void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
188CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
189unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
190void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
191void *CONF_module_get_usr_data(CONF_MODULE *pmod);
192void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
193
194char *CONF_get1_default_config_file(void);
195
196int CONF_parse_list(const char *list, int sep, int nospc,
197 int (*list_cb)(const char *elem, int len, void *usr), void *arg);
198
199void OPENSSL_load_builtin_modules(void);
200
201/* BEGIN ERROR CODES */
202/* The following lines are auto generated by the script mkerr.pl. Any changes
203 * made after this point may be overwritten when the script is next run.
204 */
205void ERR_load_CONF_strings(void);
206
207/* Error codes for the CONF functions. */
208
209/* Function codes. */
210#define CONF_F_CONF_DUMP_FP 104
211#define CONF_F_CONF_LOAD 100
212#define CONF_F_CONF_LOAD_BIO 102
213#define CONF_F_CONF_LOAD_FP 103
214#define CONF_F_CONF_MODULES_LOAD 116
215#define CONF_F_MODULE_INIT 115
216#define CONF_F_MODULE_LOAD_DSO 117
217#define CONF_F_MODULE_RUN 118
218#define CONF_F_NCONF_DUMP_BIO 105
219#define CONF_F_NCONF_DUMP_FP 106
220#define CONF_F_NCONF_GET_NUMBER 107
221#define CONF_F_NCONF_GET_NUMBER_E 112
222#define CONF_F_NCONF_GET_SECTION 108
223#define CONF_F_NCONF_GET_STRING 109
224#define CONF_F_NCONF_LOAD 113
225#define CONF_F_NCONF_LOAD_BIO 110
226#define CONF_F_NCONF_LOAD_FP 114
227#define CONF_F_NCONF_NEW 111
228#define CONF_F_STR_COPY 101
229
230/* Reason codes. */
231#define CONF_R_ERROR_LOADING_DSO 110
232#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
233#define CONF_R_MISSING_EQUAL_SIGN 101
234#define CONF_R_MISSING_FINISH_FUNCTION 111
235#define CONF_R_MISSING_INIT_FUNCTION 112
236#define CONF_R_MODULE_INITIALIZATION_ERROR 109
237#define CONF_R_NO_CLOSE_BRACE 102
238#define CONF_R_NO_CONF 105
239#define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106
240#define CONF_R_NO_SECTION 107
241#define CONF_R_NO_SUCH_FILE 114
242#define CONF_R_NO_VALUE 108
243#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
244#define CONF_R_UNKNOWN_MODULE_NAME 113
245#define CONF_R_VARIABLE_HAS_NO_VALUE 104
246
247#ifdef __cplusplus
248}
249#endif
250#endif
diff --git a/src/lib/libcrypto/conf/conf_api.c b/src/lib/libcrypto/conf/conf_api.c
deleted file mode 100644
index 0032baa711..0000000000
--- a/src/lib/libcrypto/conf/conf_api.c
+++ /dev/null
@@ -1,308 +0,0 @@
1/* conf_api.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Part of the code in here was originally in conf.c, which is now removed */
60
61#ifndef CONF_DEBUG
62# undef NDEBUG /* avoid conflicting definitions */
63# define NDEBUG
64#endif
65
66#include <assert.h>
67#include <string.h>
68#include <openssl/conf.h>
69#include <openssl/conf_api.h>
70#include "e_os.h"
71
72static void value_free_hash(CONF_VALUE *a, LHASH *conf);
73static void value_free_stack(CONF_VALUE *a,LHASH *conf);
74static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE *, LHASH *)
75static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE *, LHASH *)
76/* We don't use function pointer casting or wrapper functions - but cast each
77 * callback parameter inside the callback functions. */
78/* static unsigned long hash(CONF_VALUE *v); */
79static unsigned long hash(const void *v_void);
80/* static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); */
81static int cmp_conf(const void *a_void,const void *b_void);
82
83/* Up until OpenSSL 0.9.5a, this was get_section */
84CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section)
85 {
86 CONF_VALUE *v,vv;
87
88 if ((conf == NULL) || (section == NULL)) return(NULL);
89 vv.name=NULL;
90 vv.section=(char *)section;
91 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
92 return(v);
93 }
94
95/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
96STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
97 const char *section)
98 {
99 CONF_VALUE *v;
100
101 v=_CONF_get_section(conf,section);
102 if (v != NULL)
103 return((STACK_OF(CONF_VALUE) *)v->value);
104 else
105 return(NULL);
106 }
107
108int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
109 {
110 CONF_VALUE *v = NULL;
111 STACK_OF(CONF_VALUE) *ts;
112
113 ts = (STACK_OF(CONF_VALUE) *)section->value;
114
115 value->section=section->section;
116 if (!sk_CONF_VALUE_push(ts,value))
117 {
118 return 0;
119 }
120
121 v = (CONF_VALUE *)lh_insert(conf->data, value);
122 if (v != NULL)
123 {
124 sk_CONF_VALUE_delete_ptr(ts,v);
125 OPENSSL_free(v->name);
126 OPENSSL_free(v->value);
127 OPENSSL_free(v);
128 }
129 return 1;
130 }
131
132char *_CONF_get_string(const CONF *conf, const char *section, const char *name)
133 {
134 CONF_VALUE *v,vv;
135 char *p;
136
137 if (name == NULL) return(NULL);
138 if (conf != NULL)
139 {
140 if (section != NULL)
141 {
142 vv.name=(char *)name;
143 vv.section=(char *)section;
144 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
145 if (v != NULL) return(v->value);
146 if (strcmp(section,"ENV") == 0)
147 {
148 p=Getenv(name);
149 if (p != NULL) return(p);
150 }
151 }
152 vv.section="default";
153 vv.name=(char *)name;
154 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv);
155 if (v != NULL)
156 return(v->value);
157 else
158 return(NULL);
159 }
160 else
161 return(Getenv(name));
162 }
163
164#if 0 /* There's no way to provide error checking with this function, so
165 force implementors of the higher levels to get a string and read
166 the number themselves. */
167long _CONF_get_number(CONF *conf, char *section, char *name)
168 {
169 char *str;
170 long ret=0;
171
172 str=_CONF_get_string(conf,section,name);
173 if (str == NULL) return(0);
174 for (;;)
175 {
176 if (conf->meth->is_number(conf, *str))
177 ret=ret*10+conf->meth->to_int(conf, *str);
178 else
179 return(ret);
180 str++;
181 }
182 }
183#endif
184
185int _CONF_new_data(CONF *conf)
186 {
187 if (conf == NULL)
188 {
189 return 0;
190 }
191 if (conf->data == NULL)
192 if ((conf->data = lh_new(hash, cmp_conf)) == NULL)
193 {
194 return 0;
195 }
196 return 1;
197 }
198
199void _CONF_free_data(CONF *conf)
200 {
201 if (conf == NULL || conf->data == NULL) return;
202
203 conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()'
204 * works as expected */
205 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash),
206 conf->data);
207
208 /* We now have only 'section' entries in the hash table.
209 * Due to problems with */
210
211 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_stack),
212 conf->data);
213 lh_free(conf->data);
214 }
215
216static void value_free_hash(CONF_VALUE *a, LHASH *conf)
217 {
218 if (a->name != NULL)
219 {
220 a=(CONF_VALUE *)lh_delete(conf,a);
221 }
222 }
223
224static void value_free_stack(CONF_VALUE *a, LHASH *conf)
225 {
226 CONF_VALUE *vv;
227 STACK *sk;
228 int i;
229
230 if (a->name != NULL) return;
231
232 sk=(STACK *)a->value;
233 for (i=sk_num(sk)-1; i>=0; i--)
234 {
235 vv=(CONF_VALUE *)sk_value(sk,i);
236 OPENSSL_free(vv->value);
237 OPENSSL_free(vv->name);
238 OPENSSL_free(vv);
239 }
240 if (sk != NULL) sk_free(sk);
241 OPENSSL_free(a->section);
242 OPENSSL_free(a);
243 }
244
245/* static unsigned long hash(CONF_VALUE *v) */
246static unsigned long hash(const void *v_void)
247 {
248 CONF_VALUE *v = (CONF_VALUE *)v_void;
249 return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
250 }
251
252/* static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) */
253static int cmp_conf(const void *a_void,const void *b_void)
254 {
255 int i;
256 CONF_VALUE *a = (CONF_VALUE *)a_void;
257 CONF_VALUE *b = (CONF_VALUE *)b_void;
258
259 if (a->section != b->section)
260 {
261 i=strcmp(a->section,b->section);
262 if (i) return(i);
263 }
264
265 if ((a->name != NULL) && (b->name != NULL))
266 {
267 i=strcmp(a->name,b->name);
268 return(i);
269 }
270 else if (a->name == b->name)
271 return(0);
272 else
273 return((a->name == NULL)?-1:1);
274 }
275
276/* Up until OpenSSL 0.9.5a, this was new_section */
277CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
278 {
279 STACK *sk=NULL;
280 int ok=0,i;
281 CONF_VALUE *v=NULL,*vv;
282
283 if ((sk=sk_new_null()) == NULL)
284 goto err;
285 if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL)
286 goto err;
287 i=strlen(section)+1;
288 if ((v->section=(char *)OPENSSL_malloc(i)) == NULL)
289 goto err;
290
291 memcpy(v->section,section,i);
292 v->name=NULL;
293 v->value=(char *)sk;
294
295 vv=(CONF_VALUE *)lh_insert(conf->data,v);
296 assert(vv == NULL);
297 ok=1;
298err:
299 if (!ok)
300 {
301 if (sk != NULL) sk_free(sk);
302 if (v != NULL) OPENSSL_free(v);
303 v=NULL;
304 }
305 return(v);
306 }
307
308IMPLEMENT_STACK_OF(CONF_VALUE)
diff --git a/src/lib/libcrypto/conf/conf_api.h b/src/lib/libcrypto/conf/conf_api.h
deleted file mode 100644
index 87a954aff6..0000000000
--- a/src/lib/libcrypto/conf/conf_api.h
+++ /dev/null
@@ -1,89 +0,0 @@
1/* conf_api.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_CONF_API_H
60#define HEADER_CONF_API_H
61
62#include <openssl/lhash.h>
63#include <openssl/conf.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* Up until OpenSSL 0.9.5a, this was new_section */
70CONF_VALUE *_CONF_new_section(CONF *conf, const char *section);
71/* Up until OpenSSL 0.9.5a, this was get_section */
72CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section);
73/* Up until OpenSSL 0.9.5a, this was CONF_get_section */
74STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf,
75 const char *section);
76
77int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value);
78char *_CONF_get_string(const CONF *conf, const char *section,
79 const char *name);
80long _CONF_get_number(const CONF *conf, const char *section, const char *name);
81
82int _CONF_new_data(CONF *conf);
83void _CONF_free_data(CONF *conf);
84
85#ifdef __cplusplus
86}
87#endif
88#endif
89
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c
deleted file mode 100644
index 2464f8ed90..0000000000
--- a/src/lib/libcrypto/conf/conf_def.c
+++ /dev/null
@@ -1,750 +0,0 @@
1/* crypto/conf/conf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Part of the code in here was originally in conf.c, which is now removed */
60
61#include <stdio.h>
62#include <string.h>
63#include <openssl/stack.h>
64#include <openssl/lhash.h>
65#include <openssl/conf.h>
66#include <openssl/conf_api.h>
67#include "conf_def.h"
68#include <openssl/buffer.h>
69#include <openssl/err.h>
70#include "cryptlib.h"
71
72static char *eat_ws(CONF *conf, char *p);
73static char *eat_alpha_numeric(CONF *conf, char *p);
74static void clear_comments(CONF *conf, char *p);
75static int str_copy(CONF *conf,char *section,char **to, char *from);
76static char *scan_quote(CONF *conf, char *p);
77static char *scan_dquote(CONF *conf, char *p);
78#define scan_esc(conf,p) (((IS_EOF((conf),(p)[1]))?((p)+1):((p)+2)))
79
80static CONF *def_create(CONF_METHOD *meth);
81static int def_init_default(CONF *conf);
82static int def_init_WIN32(CONF *conf);
83static int def_destroy(CONF *conf);
84static int def_destroy_data(CONF *conf);
85static int def_load(CONF *conf, const char *name, long *eline);
86static int def_load_bio(CONF *conf, BIO *bp, long *eline);
87static int def_dump(const CONF *conf, BIO *bp);
88static int def_is_number(const CONF *conf, char c);
89static int def_to_int(const CONF *conf, char c);
90
91const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT;
92
93static CONF_METHOD default_method = {
94 "OpenSSL default",
95 def_create,
96 def_init_default,
97 def_destroy,
98 def_destroy_data,
99 def_load_bio,
100 def_dump,
101 def_is_number,
102 def_to_int,
103 def_load
104 };
105
106static CONF_METHOD WIN32_method = {
107 "WIN32",
108 def_create,
109 def_init_WIN32,
110 def_destroy,
111 def_destroy_data,
112 def_load_bio,
113 def_dump,
114 def_is_number,
115 def_to_int,
116 def_load
117 };
118
119CONF_METHOD *NCONF_default()
120 {
121 return &default_method;
122 }
123CONF_METHOD *NCONF_WIN32()
124 {
125 return &WIN32_method;
126 }
127
128static CONF *def_create(CONF_METHOD *meth)
129 {
130 CONF *ret;
131
132 ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
133 if (ret)
134 if (meth->init(ret) == 0)
135 {
136 OPENSSL_free(ret);
137 ret = NULL;
138 }
139 return ret;
140 }
141
142static int def_init_default(CONF *conf)
143 {
144 if (conf == NULL)
145 return 0;
146
147 conf->meth = &default_method;
148 conf->meth_data = (void *)CONF_type_default;
149 conf->data = NULL;
150
151 return 1;
152 }
153
154static int def_init_WIN32(CONF *conf)
155 {
156 if (conf == NULL)
157 return 0;
158
159 conf->meth = &WIN32_method;
160 conf->meth_data = (void *)CONF_type_win32;
161 conf->data = NULL;
162
163 return 1;
164 }
165
166static int def_destroy(CONF *conf)
167 {
168 if (def_destroy_data(conf))
169 {
170 OPENSSL_free(conf);
171 return 1;
172 }
173 return 0;
174 }
175
176static int def_destroy_data(CONF *conf)
177 {
178 if (conf == NULL)
179 return 0;
180 _CONF_free_data(conf);
181 return 1;
182 }
183
184static int def_load(CONF *conf, const char *name, long *line)
185 {
186 int ret;
187 BIO *in=NULL;
188
189#ifdef OPENSSL_SYS_VMS
190 in=BIO_new_file(name, "r");
191#else
192 in=BIO_new_file(name, "rb");
193#endif
194 if (in == NULL)
195 {
196 if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE)
197 CONFerr(CONF_F_CONF_LOAD,CONF_R_NO_SUCH_FILE);
198 else
199 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
200 return 0;
201 }
202
203 ret = def_load_bio(conf, in, line);
204 BIO_free(in);
205
206 return ret;
207 }
208
209static int def_load_bio(CONF *conf, BIO *in, long *line)
210 {
211/* The macro BUFSIZE conflicts with a system macro in VxWorks */
212#define CONFBUFSIZE 512
213 int bufnum=0,i,ii;
214 BUF_MEM *buff=NULL;
215 char *s,*p,*end;
216 int again,n;
217 long eline=0;
218 char btmp[DECIMAL_SIZE(eline)+1];
219 CONF_VALUE *v=NULL,*tv;
220 CONF_VALUE *sv=NULL;
221 char *section=NULL,*buf;
222 STACK_OF(CONF_VALUE) *section_sk=NULL,*ts;
223 char *start,*psection,*pname;
224 void *h = (void *)(conf->data);
225
226 if ((buff=BUF_MEM_new()) == NULL)
227 {
228 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
229 goto err;
230 }
231
232 section=(char *)OPENSSL_malloc(10);
233 if (section == NULL)
234 {
235 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
236 goto err;
237 }
238 BUF_strlcpy(section,"default",10);
239
240 if (_CONF_new_data(conf) == 0)
241 {
242 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
243 goto err;
244 }
245
246 sv=_CONF_new_section(conf,section);
247 if (sv == NULL)
248 {
249 CONFerr(CONF_F_CONF_LOAD_BIO,
250 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
251 goto err;
252 }
253 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
254
255 bufnum=0;
256 again=0;
257 for (;;)
258 {
259 if (!BUF_MEM_grow(buff,bufnum+CONFBUFSIZE))
260 {
261 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
262 goto err;
263 }
264 p= &(buff->data[bufnum]);
265 *p='\0';
266 BIO_gets(in, p, CONFBUFSIZE-1);
267 p[CONFBUFSIZE-1]='\0';
268 ii=i=strlen(p);
269 if (i == 0 && !again) break;
270 again=0;
271 while (i > 0)
272 {
273 if ((p[i-1] != '\r') && (p[i-1] != '\n'))
274 break;
275 else
276 i--;
277 }
278 /* we removed some trailing stuff so there is a new
279 * line on the end. */
280 if (ii && i == ii)
281 again=1; /* long line */
282 else
283 {
284 p[i]='\0';
285 eline++; /* another input line */
286 }
287
288 /* we now have a line with trailing \r\n removed */
289
290 /* i is the number of bytes */
291 bufnum+=i;
292
293 v=NULL;
294 /* check for line continuation */
295 if (bufnum >= 1)
296 {
297 /* If we have bytes and the last char '\\' and
298 * second last char is not '\\' */
299 p= &(buff->data[bufnum-1]);
300 if (IS_ESC(conf,p[0]) &&
301 ((bufnum <= 1) || !IS_ESC(conf,p[-1])))
302 {
303 bufnum--;
304 again=1;
305 }
306 }
307 if (again) continue;
308 bufnum=0;
309 buf=buff->data;
310
311 clear_comments(conf, buf);
312 n=strlen(buf);
313 s=eat_ws(conf, buf);
314 if (IS_EOF(conf,*s)) continue; /* blank line */
315 if (*s == '[')
316 {
317 char *ss;
318
319 s++;
320 start=eat_ws(conf, s);
321 ss=start;
322again:
323 end=eat_alpha_numeric(conf, ss);
324 p=eat_ws(conf, end);
325 if (*p != ']')
326 {
327 if (*p != '\0')
328 {
329 ss=p;
330 goto again;
331 }
332 CONFerr(CONF_F_CONF_LOAD_BIO,
333 CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
334 goto err;
335 }
336 *end='\0';
337 if (!str_copy(conf,NULL,&section,start)) goto err;
338 if ((sv=_CONF_get_section(conf,section)) == NULL)
339 sv=_CONF_new_section(conf,section);
340 if (sv == NULL)
341 {
342 CONFerr(CONF_F_CONF_LOAD_BIO,
343 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
344 goto err;
345 }
346 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
347 continue;
348 }
349 else
350 {
351 pname=s;
352 psection=NULL;
353 end=eat_alpha_numeric(conf, s);
354 if ((end[0] == ':') && (end[1] == ':'))
355 {
356 *end='\0';
357 end+=2;
358 psection=pname;
359 pname=end;
360 end=eat_alpha_numeric(conf, end);
361 }
362 p=eat_ws(conf, end);
363 if (*p != '=')
364 {
365 CONFerr(CONF_F_CONF_LOAD_BIO,
366 CONF_R_MISSING_EQUAL_SIGN);
367 goto err;
368 }
369 *end='\0';
370 p++;
371 start=eat_ws(conf, p);
372 while (!IS_EOF(conf,*p))
373 p++;
374 p--;
375 while ((p != start) && (IS_WS(conf,*p)))
376 p--;
377 p++;
378 *p='\0';
379
380 if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))))
381 {
382 CONFerr(CONF_F_CONF_LOAD_BIO,
383 ERR_R_MALLOC_FAILURE);
384 goto err;
385 }
386 if (psection == NULL) psection=section;
387 v->name=(char *)OPENSSL_malloc(strlen(pname)+1);
388 v->value=NULL;
389 if (v->name == NULL)
390 {
391 CONFerr(CONF_F_CONF_LOAD_BIO,
392 ERR_R_MALLOC_FAILURE);
393 goto err;
394 }
395 BUF_strlcpy(v->name,pname,strlen(pname)+1);
396 if (!str_copy(conf,psection,&(v->value),start)) goto err;
397
398 if (strcmp(psection,section) != 0)
399 {
400 if ((tv=_CONF_get_section(conf,psection))
401 == NULL)
402 tv=_CONF_new_section(conf,psection);
403 if (tv == NULL)
404 {
405 CONFerr(CONF_F_CONF_LOAD_BIO,
406 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
407 goto err;
408 }
409 ts=(STACK_OF(CONF_VALUE) *)tv->value;
410 }
411 else
412 {
413 tv=sv;
414 ts=section_sk;
415 }
416#if 1
417 if (_CONF_add_string(conf, tv, v) == 0)
418 {
419 CONFerr(CONF_F_CONF_LOAD_BIO,
420 ERR_R_MALLOC_FAILURE);
421 goto err;
422 }
423#else
424 v->section=tv->section;
425 if (!sk_CONF_VALUE_push(ts,v))
426 {
427 CONFerr(CONF_F_CONF_LOAD_BIO,
428 ERR_R_MALLOC_FAILURE);
429 goto err;
430 }
431 vv=(CONF_VALUE *)lh_insert(conf->data,v);
432 if (vv != NULL)
433 {
434 sk_CONF_VALUE_delete_ptr(ts,vv);
435 OPENSSL_free(vv->name);
436 OPENSSL_free(vv->value);
437 OPENSSL_free(vv);
438 }
439#endif
440 v=NULL;
441 }
442 }
443 if (buff != NULL) BUF_MEM_free(buff);
444 if (section != NULL) OPENSSL_free(section);
445 return(1);
446err:
447 if (buff != NULL) BUF_MEM_free(buff);
448 if (section != NULL) OPENSSL_free(section);
449 if (line != NULL) *line=eline;
450 BIO_snprintf(btmp,sizeof btmp,"%ld",eline);
451 ERR_add_error_data(2,"line ",btmp);
452 if ((h != conf->data) && (conf->data != NULL))
453 {
454 CONF_free(conf->data);
455 conf->data=NULL;
456 }
457 if (v != NULL)
458 {
459 if (v->name != NULL) OPENSSL_free(v->name);
460 if (v->value != NULL) OPENSSL_free(v->value);
461 if (v != NULL) OPENSSL_free(v);
462 }
463 return(0);
464 }
465
466static void clear_comments(CONF *conf, char *p)
467 {
468 char *to;
469
470 to=p;
471 for (;;)
472 {
473 if (IS_FCOMMENT(conf,*p))
474 {
475 *p='\0';
476 return;
477 }
478 if (!IS_WS(conf,*p))
479 {
480 break;
481 }
482 p++;
483 }
484
485 for (;;)
486 {
487 if (IS_COMMENT(conf,*p))
488 {
489 *p='\0';
490 return;
491 }
492 if (IS_DQUOTE(conf,*p))
493 {
494 p=scan_dquote(conf, p);
495 continue;
496 }
497 if (IS_QUOTE(conf,*p))
498 {
499 p=scan_quote(conf, p);
500 continue;
501 }
502 if (IS_ESC(conf,*p))
503 {
504 p=scan_esc(conf,p);
505 continue;
506 }
507 if (IS_EOF(conf,*p))
508 return;
509 else
510 p++;
511 }
512 }
513
514static int str_copy(CONF *conf, char *section, char **pto, char *from)
515 {
516 int q,r,rr=0,to=0,len=0;
517 char *s,*e,*rp,*p,*rrp,*np,*cp,v;
518 BUF_MEM *buf;
519
520 if ((buf=BUF_MEM_new()) == NULL) return(0);
521
522 len=strlen(from)+1;
523 if (!BUF_MEM_grow(buf,len)) goto err;
524
525 for (;;)
526 {
527 if (IS_QUOTE(conf,*from))
528 {
529 q= *from;
530 from++;
531 while (!IS_EOF(conf,*from) && (*from != q))
532 {
533 if (IS_ESC(conf,*from))
534 {
535 from++;
536 if (IS_EOF(conf,*from)) break;
537 }
538 buf->data[to++]= *(from++);
539 }
540 if (*from == q) from++;
541 }
542 else if (IS_DQUOTE(conf,*from))
543 {
544 q= *from;
545 from++;
546 while (!IS_EOF(conf,*from))
547 {
548 if (*from == q)
549 {
550 if (*(from+1) == q)
551 {
552 from++;
553 }
554 else
555 {
556 break;
557 }
558 }
559 buf->data[to++]= *(from++);
560 }
561 if (*from == q) from++;
562 }
563 else if (IS_ESC(conf,*from))
564 {
565 from++;
566 v= *(from++);
567 if (IS_EOF(conf,v)) break;
568 else if (v == 'r') v='\r';
569 else if (v == 'n') v='\n';
570 else if (v == 'b') v='\b';
571 else if (v == 't') v='\t';
572 buf->data[to++]= v;
573 }
574 else if (IS_EOF(conf,*from))
575 break;
576 else if (*from == '$')
577 {
578 /* try to expand it */
579 rrp=NULL;
580 s= &(from[1]);
581 if (*s == '{')
582 q='}';
583 else if (*s == '(')
584 q=')';
585 else q=0;
586
587 if (q) s++;
588 cp=section;
589 e=np=s;
590 while (IS_ALPHA_NUMERIC(conf,*e))
591 e++;
592 if ((e[0] == ':') && (e[1] == ':'))
593 {
594 cp=np;
595 rrp=e;
596 rr= *e;
597 *rrp='\0';
598 e+=2;
599 np=e;
600 while (IS_ALPHA_NUMERIC(conf,*e))
601 e++;
602 }
603 r= *e;
604 *e='\0';
605 rp=e;
606 if (q)
607 {
608 if (r != q)
609 {
610 CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE);
611 goto err;
612 }
613 e++;
614 }
615 /* So at this point we have
616 * np which is the start of the name string which is
617 * '\0' terminated.
618 * cp which is the start of the section string which is
619 * '\0' terminated.
620 * e is the 'next point after'.
621 * r and rr are the chars replaced by the '\0'
622 * rp and rrp is where 'r' and 'rr' came from.
623 */
624 p=_CONF_get_string(conf,cp,np);
625 if (rrp != NULL) *rrp=rr;
626 *rp=r;
627 if (p == NULL)
628 {
629 CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);
630 goto err;
631 }
632 BUF_MEM_grow_clean(buf,(strlen(p)+len-(e-from)));
633 while (*p)
634 buf->data[to++]= *(p++);
635
636 /* Since we change the pointer 'from', we also have
637 to change the perceived length of the string it
638 points at. /RL */
639 len -= e-from;
640 from=e;
641
642 /* In case there were no braces or parenthesis around
643 the variable reference, we have to put back the
644 character that was replaced with a '\0'. /RL */
645 *rp = r;
646 }
647 else
648 buf->data[to++]= *(from++);
649 }
650 buf->data[to]='\0';
651 if (*pto != NULL) OPENSSL_free(*pto);
652 *pto=buf->data;
653 OPENSSL_free(buf);
654 return(1);
655err:
656 if (buf != NULL) BUF_MEM_free(buf);
657 return(0);
658 }
659
660static char *eat_ws(CONF *conf, char *p)
661 {
662 while (IS_WS(conf,*p) && (!IS_EOF(conf,*p)))
663 p++;
664 return(p);
665 }
666
667static char *eat_alpha_numeric(CONF *conf, char *p)
668 {
669 for (;;)
670 {
671 if (IS_ESC(conf,*p))
672 {
673 p=scan_esc(conf,p);
674 continue;
675 }
676 if (!IS_ALPHA_NUMERIC_PUNCT(conf,*p))
677 return(p);
678 p++;
679 }
680 }
681
682static char *scan_quote(CONF *conf, char *p)
683 {
684 int q= *p;
685
686 p++;
687 while (!(IS_EOF(conf,*p)) && (*p != q))
688 {
689 if (IS_ESC(conf,*p))
690 {
691 p++;
692 if (IS_EOF(conf,*p)) return(p);
693 }
694 p++;
695 }
696 if (*p == q) p++;
697 return(p);
698 }
699
700
701static char *scan_dquote(CONF *conf, char *p)
702 {
703 int q= *p;
704
705 p++;
706 while (!(IS_EOF(conf,*p)))
707 {
708 if (*p == q)
709 {
710 if (*(p+1) == q)
711 {
712 p++;
713 }
714 else
715 {
716 break;
717 }
718 }
719 p++;
720 }
721 if (*p == q) p++;
722 return(p);
723 }
724
725static void dump_value(CONF_VALUE *a, BIO *out)
726 {
727 if (a->name)
728 BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value);
729 else
730 BIO_printf(out, "[[%s]]\n", a->section);
731 }
732
733static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE *, BIO *)
734
735static int def_dump(const CONF *conf, BIO *out)
736 {
737 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), out);
738 return 1;
739 }
740
741static int def_is_number(const CONF *conf, char c)
742 {
743 return IS_NUMBER(conf,c);
744 }
745
746static int def_to_int(const CONF *conf, char c)
747 {
748 return c - '0';
749 }
750
diff --git a/src/lib/libcrypto/conf/conf_def.h b/src/lib/libcrypto/conf/conf_def.h
deleted file mode 100644
index 92a7d8ad77..0000000000
--- a/src/lib/libcrypto/conf/conf_def.h
+++ /dev/null
@@ -1,180 +0,0 @@
1/* crypto/conf/conf_def.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* THIS FILE WAS AUTOMAGICALLY GENERATED!
60 Please modify and use keysets.pl to regenerate it. */
61
62#define CONF_NUMBER 1
63#define CONF_UPPER 2
64#define CONF_LOWER 4
65#define CONF_UNDER 256
66#define CONF_PUNCTUATION 512
67#define CONF_WS 16
68#define CONF_ESC 32
69#define CONF_QUOTE 64
70#define CONF_DQUOTE 1024
71#define CONF_COMMENT 128
72#define CONF_FCOMMENT 2048
73#define CONF_EOF 8
74#define CONF_HIGHBIT 4096
75#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
76#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
77#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \
78 CONF_PUNCTUATION)
79
80#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
81#ifndef CHARSET_EBCDIC
82#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
83#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
84#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
85#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
86#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
87#define IS_WS(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_WS)
88#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
89#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
90 (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
91#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
92#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
93#define IS_HIGHBIT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
94
95#else /*CHARSET_EBCDIC*/
96
97#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_COMMENT)
98#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_FCOMMENT)
99#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_EOF)
100#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ESC)
101#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_NUMBER)
102#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_WS)
103#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC)
104#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
105 (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
106#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_QUOTE)
107#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_DQUOTE)
108#define IS_HIGHBIT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_HIGHBIT)
109#endif /*CHARSET_EBCDIC*/
110
111static unsigned short CONF_type_default[256]={
112 0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
113 0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000,
114 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
115 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
116 0x0010,0x0200,0x0040,0x0080,0x0000,0x0200,0x0200,0x0040,
117 0x0000,0x0000,0x0200,0x0200,0x0200,0x0200,0x0200,0x0200,
118 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
119 0x0001,0x0001,0x0000,0x0200,0x0000,0x0000,0x0000,0x0200,
120 0x0200,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
121 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
122 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
123 0x0002,0x0002,0x0002,0x0000,0x0020,0x0000,0x0200,0x0100,
124 0x0040,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
125 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
126 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
127 0x0004,0x0004,0x0004,0x0000,0x0200,0x0000,0x0200,0x0000,
128 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
129 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
130 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
131 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
132 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
133 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
134 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
135 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
136 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
137 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
138 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
139 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
140 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
141 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
142 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
143 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
144 };
145
146static unsigned short CONF_type_win32[256]={
147 0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
148 0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000,
149 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
150 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
151 0x0010,0x0200,0x0400,0x0000,0x0000,0x0200,0x0200,0x0000,
152 0x0000,0x0000,0x0200,0x0200,0x0200,0x0200,0x0200,0x0200,
153 0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
154 0x0001,0x0001,0x0000,0x0A00,0x0000,0x0000,0x0000,0x0200,
155 0x0200,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
156 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
157 0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
158 0x0002,0x0002,0x0002,0x0000,0x0000,0x0000,0x0200,0x0100,
159 0x0000,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
160 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
161 0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
162 0x0004,0x0004,0x0004,0x0000,0x0200,0x0000,0x0200,0x0000,
163 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
164 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
165 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
166 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
167 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
168 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
169 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
170 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
171 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
172 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
173 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
174 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
175 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
176 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
177 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
178 0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
179 };
180
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
deleted file mode 100644
index f5e2ca4bf0..0000000000
--- a/src/lib/libcrypto/conf/conf_err.c
+++ /dev/null
@@ -1,130 +0,0 @@
1/* crypto/conf/conf_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_CONF,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_CONF,0,reason)
70
71static ERR_STRING_DATA CONF_str_functs[]=
72 {
73{ERR_FUNC(CONF_F_CONF_DUMP_FP), "CONF_dump_fp"},
74{ERR_FUNC(CONF_F_CONF_LOAD), "CONF_load"},
75{ERR_FUNC(CONF_F_CONF_LOAD_BIO), "CONF_load_bio"},
76{ERR_FUNC(CONF_F_CONF_LOAD_FP), "CONF_load_fp"},
77{ERR_FUNC(CONF_F_CONF_MODULES_LOAD), "CONF_modules_load"},
78{ERR_FUNC(CONF_F_MODULE_INIT), "MODULE_INIT"},
79{ERR_FUNC(CONF_F_MODULE_LOAD_DSO), "MODULE_LOAD_DSO"},
80{ERR_FUNC(CONF_F_MODULE_RUN), "MODULE_RUN"},
81{ERR_FUNC(CONF_F_NCONF_DUMP_BIO), "NCONF_dump_bio"},
82{ERR_FUNC(CONF_F_NCONF_DUMP_FP), "NCONF_dump_fp"},
83{ERR_FUNC(CONF_F_NCONF_GET_NUMBER), "NCONF_get_number"},
84{ERR_FUNC(CONF_F_NCONF_GET_NUMBER_E), "NCONF_get_number_e"},
85{ERR_FUNC(CONF_F_NCONF_GET_SECTION), "NCONF_get_section"},
86{ERR_FUNC(CONF_F_NCONF_GET_STRING), "NCONF_get_string"},
87{ERR_FUNC(CONF_F_NCONF_LOAD), "NCONF_load"},
88{ERR_FUNC(CONF_F_NCONF_LOAD_BIO), "NCONF_load_bio"},
89{ERR_FUNC(CONF_F_NCONF_LOAD_FP), "NCONF_load_fp"},
90{ERR_FUNC(CONF_F_NCONF_NEW), "NCONF_new"},
91{ERR_FUNC(CONF_F_STR_COPY), "STR_COPY"},
92{0,NULL}
93 };
94
95static ERR_STRING_DATA CONF_str_reasons[]=
96 {
97{ERR_REASON(CONF_R_ERROR_LOADING_DSO) ,"error loading dso"},
98{ERR_REASON(CONF_R_MISSING_CLOSE_SQUARE_BRACKET),"missing close square bracket"},
99{ERR_REASON(CONF_R_MISSING_EQUAL_SIGN) ,"missing equal sign"},
100{ERR_REASON(CONF_R_MISSING_FINISH_FUNCTION),"missing finish function"},
101{ERR_REASON(CONF_R_MISSING_INIT_FUNCTION),"missing init function"},
102{ERR_REASON(CONF_R_MODULE_INITIALIZATION_ERROR),"module initialization error"},
103{ERR_REASON(CONF_R_NO_CLOSE_BRACE) ,"no close brace"},
104{ERR_REASON(CONF_R_NO_CONF) ,"no conf"},
105{ERR_REASON(CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE),"no conf or environment variable"},
106{ERR_REASON(CONF_R_NO_SECTION) ,"no section"},
107{ERR_REASON(CONF_R_NO_SUCH_FILE) ,"no such file"},
108{ERR_REASON(CONF_R_NO_VALUE) ,"no value"},
109{ERR_REASON(CONF_R_UNABLE_TO_CREATE_NEW_SECTION),"unable to create new section"},
110{ERR_REASON(CONF_R_UNKNOWN_MODULE_NAME) ,"unknown module name"},
111{ERR_REASON(CONF_R_VARIABLE_HAS_NO_VALUE),"variable has no value"},
112{0,NULL}
113 };
114
115#endif
116
117void ERR_load_CONF_strings(void)
118 {
119 static int init=1;
120
121 if (init)
122 {
123 init=0;
124#ifndef OPENSSL_NO_ERR
125 ERR_load_strings(0,CONF_str_functs);
126 ERR_load_strings(0,CONF_str_reasons);
127#endif
128
129 }
130 }
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c
deleted file mode 100644
index 6a3cf109dd..0000000000
--- a/src/lib/libcrypto/conf/conf_lib.c
+++ /dev/null
@@ -1,401 +0,0 @@
1/* conf_lib.c */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include <openssl/err.h>
62#include <openssl/conf.h>
63#include <openssl/conf_api.h>
64#include <openssl/lhash.h>
65
66const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
67
68static CONF_METHOD *default_CONF_method=NULL;
69
70/* Init a 'CONF' structure from an old LHASH */
71
72void CONF_set_nconf(CONF *conf, LHASH *hash)
73 {
74 if (default_CONF_method == NULL)
75 default_CONF_method = NCONF_default();
76
77 default_CONF_method->init(conf);
78 conf->data = hash;
79 }
80
81/* The following section contains the "CONF classic" functions,
82 rewritten in terms of the new CONF interface. */
83
84int CONF_set_default_method(CONF_METHOD *meth)
85 {
86 default_CONF_method = meth;
87 return 1;
88 }
89
90LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
91 {
92 LHASH *ltmp;
93 BIO *in=NULL;
94
95#ifdef OPENSSL_SYS_VMS
96 in=BIO_new_file(file, "r");
97#else
98 in=BIO_new_file(file, "rb");
99#endif
100 if (in == NULL)
101 {
102 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
103 return NULL;
104 }
105
106 ltmp = CONF_load_bio(conf, in, eline);
107 BIO_free(in);
108
109 return ltmp;
110 }
111
112#ifndef OPENSSL_NO_FP_API
113LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
114 {
115 BIO *btmp;
116 LHASH *ltmp;
117 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
118 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
119 return NULL;
120 }
121 ltmp = CONF_load_bio(conf, btmp, eline);
122 BIO_free(btmp);
123 return ltmp;
124 }
125#endif
126
127LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
128 {
129 CONF ctmp;
130 int ret;
131
132 CONF_set_nconf(&ctmp, conf);
133
134 ret = NCONF_load_bio(&ctmp, bp, eline);
135 if (ret)
136 return ctmp.data;
137 return NULL;
138 }
139
140STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section)
141 {
142 if (conf == NULL)
143 {
144 return NULL;
145 }
146 else
147 {
148 CONF ctmp;
149 CONF_set_nconf(&ctmp, conf);
150 return NCONF_get_section(&ctmp, section);
151 }
152 }
153
154char *CONF_get_string(LHASH *conf,const char *group,const char *name)
155 {
156 if (conf == NULL)
157 {
158 return NCONF_get_string(NULL, group, name);
159 }
160 else
161 {
162 CONF ctmp;
163 CONF_set_nconf(&ctmp, conf);
164 return NCONF_get_string(&ctmp, group, name);
165 }
166 }
167
168long CONF_get_number(LHASH *conf,const char *group,const char *name)
169 {
170 int status;
171 long result = 0;
172
173 if (conf == NULL)
174 {
175 status = NCONF_get_number_e(NULL, group, name, &result);
176 }
177 else
178 {
179 CONF ctmp;
180 CONF_set_nconf(&ctmp, conf);
181 status = NCONF_get_number_e(&ctmp, group, name, &result);
182 }
183
184 if (status == 0)
185 {
186 /* This function does not believe in errors... */
187 ERR_get_error();
188 }
189 return result;
190 }
191
192void CONF_free(LHASH *conf)
193 {
194 CONF ctmp;
195 CONF_set_nconf(&ctmp, conf);
196 NCONF_free_data(&ctmp);
197 }
198
199#ifndef OPENSSL_NO_FP_API
200int CONF_dump_fp(LHASH *conf, FILE *out)
201 {
202 BIO *btmp;
203 int ret;
204
205 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
206 CONFerr(CONF_F_CONF_DUMP_FP,ERR_R_BUF_LIB);
207 return 0;
208 }
209 ret = CONF_dump_bio(conf, btmp);
210 BIO_free(btmp);
211 return ret;
212 }
213#endif
214
215int CONF_dump_bio(LHASH *conf, BIO *out)
216 {
217 CONF ctmp;
218 CONF_set_nconf(&ctmp, conf);
219 return NCONF_dump_bio(&ctmp, out);
220 }
221
222/* The following section contains the "New CONF" functions. They are
223 completely centralised around a new CONF structure that may contain
224 basically anything, but at least a method pointer and a table of data.
225 These functions are also written in terms of the bridge functions used
226 by the "CONF classic" functions, for consistency. */
227
228CONF *NCONF_new(CONF_METHOD *meth)
229 {
230 CONF *ret;
231
232 if (meth == NULL)
233 meth = NCONF_default();
234
235 ret = meth->create(meth);
236 if (ret == NULL)
237 {
238 CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE);
239 return(NULL);
240 }
241
242 return ret;
243 }
244
245void NCONF_free(CONF *conf)
246 {
247 if (conf == NULL)
248 return;
249 conf->meth->destroy(conf);
250 }
251
252void NCONF_free_data(CONF *conf)
253 {
254 if (conf == NULL)
255 return;
256 conf->meth->destroy_data(conf);
257 }
258
259int NCONF_load(CONF *conf, const char *file, long *eline)
260 {
261 if (conf == NULL)
262 {
263 CONFerr(CONF_F_NCONF_LOAD,CONF_R_NO_CONF);
264 return 0;
265 }
266
267 return conf->meth->load(conf, file, eline);
268 }
269
270#ifndef OPENSSL_NO_FP_API
271int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
272 {
273 BIO *btmp;
274 int ret;
275 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE)))
276 {
277 CONFerr(CONF_F_NCONF_LOAD_FP,ERR_R_BUF_LIB);
278 return 0;
279 }
280 ret = NCONF_load_bio(conf, btmp, eline);
281 BIO_free(btmp);
282 return ret;
283 }
284#endif
285
286int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
287 {
288 if (conf == NULL)
289 {
290 CONFerr(CONF_F_NCONF_LOAD_BIO,CONF_R_NO_CONF);
291 return 0;
292 }
293
294 return conf->meth->load_bio(conf, bp, eline);
295 }
296
297STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section)
298 {
299 if (conf == NULL)
300 {
301 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_CONF);
302 return NULL;
303 }
304
305 if (section == NULL)
306 {
307 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_SECTION);
308 return NULL;
309 }
310
311 return _CONF_get_section_values(conf, section);
312 }
313
314char *NCONF_get_string(const CONF *conf,const char *group,const char *name)
315 {
316 char *s = _CONF_get_string(conf, group, name);
317
318 /* Since we may get a value from an environment variable even
319 if conf is NULL, let's check the value first */
320 if (s) return s;
321
322 if (conf == NULL)
323 {
324 CONFerr(CONF_F_NCONF_GET_STRING,
325 CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
326 return NULL;
327 }
328 CONFerr(CONF_F_NCONF_GET_STRING,
329 CONF_R_NO_VALUE);
330 ERR_add_error_data(4,"group=",group," name=",name);
331 return NULL;
332 }
333
334int NCONF_get_number_e(const CONF *conf,const char *group,const char *name,
335 long *result)
336 {
337 char *str;
338
339 if (result == NULL)
340 {
341 CONFerr(CONF_F_NCONF_GET_NUMBER_E,ERR_R_PASSED_NULL_PARAMETER);
342 return 0;
343 }
344
345 str = NCONF_get_string(conf,group,name);
346
347 if (str == NULL)
348 return 0;
349
350 for (*result = 0;conf->meth->is_number(conf, *str);)
351 {
352 *result = (*result)*10 + conf->meth->to_int(conf, *str);
353 str++;
354 }
355
356 return 1;
357 }
358
359#ifndef OPENSSL_NO_FP_API
360int NCONF_dump_fp(const CONF *conf, FILE *out)
361 {
362 BIO *btmp;
363 int ret;
364 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
365 CONFerr(CONF_F_NCONF_DUMP_FP,ERR_R_BUF_LIB);
366 return 0;
367 }
368 ret = NCONF_dump_bio(conf, btmp);
369 BIO_free(btmp);
370 return ret;
371 }
372#endif
373
374int NCONF_dump_bio(const CONF *conf, BIO *out)
375 {
376 if (conf == NULL)
377 {
378 CONFerr(CONF_F_NCONF_DUMP_BIO,CONF_R_NO_CONF);
379 return 0;
380 }
381
382 return conf->meth->dump(conf, out);
383 }
384
385
386/* This function should be avoided */
387#if 0
388long NCONF_get_number(CONF *conf,char *group,char *name)
389 {
390 int status;
391 long ret=0;
392
393 status = NCONF_get_number_e(conf, group, name, &ret);
394 if (status == 0)
395 {
396 /* This function does not believe in errors... */
397 ERR_get_error();
398 }
399 return ret;
400 }
401#endif
diff --git a/src/lib/libcrypto/conf/conf_mall.c b/src/lib/libcrypto/conf/conf_mall.c
deleted file mode 100644
index 4ba40cf44c..0000000000
--- a/src/lib/libcrypto/conf/conf_mall.c
+++ /dev/null
@@ -1,80 +0,0 @@
1/* conf_mall.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65#include <openssl/asn1.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70/* Load all OpenSSL builtin modules */
71
72void OPENSSL_load_builtin_modules(void)
73 {
74 /* Add builtin modules here */
75 ASN1_add_oid_module();
76#ifndef OPENSSL_NO_ENGINE
77 ENGINE_add_conf_module();
78#endif
79 }
80
diff --git a/src/lib/libcrypto/conf/conf_mod.c b/src/lib/libcrypto/conf/conf_mod.c
deleted file mode 100644
index 812e60dc70..0000000000
--- a/src/lib/libcrypto/conf/conf_mod.c
+++ /dev/null
@@ -1,616 +0,0 @@
1/* conf_mod.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/conf.h>
64#include <openssl/dso.h>
65#include <openssl/x509.h>
66
67
68#define DSO_mod_init_name "OPENSSL_init"
69#define DSO_mod_finish_name "OPENSSL_finish"
70
71
72/* This structure contains a data about supported modules.
73 * entries in this table correspond to either dynamic or
74 * static modules.
75 */
76
77struct conf_module_st
78 {
79 /* DSO of this module or NULL if static */
80 DSO *dso;
81 /* Name of the module */
82 char *name;
83 /* Init function */
84 conf_init_func *init;
85 /* Finish function */
86 conf_finish_func *finish;
87 /* Number of successfully initialized modules */
88 int links;
89 void *usr_data;
90 };
91
92
93/* This structure contains information about modules that have been
94 * successfully initialized. There may be more than one entry for a
95 * given module.
96 */
97
98struct conf_imodule_st
99 {
100 CONF_MODULE *pmod;
101 char *name;
102 char *value;
103 unsigned long flags;
104 void *usr_data;
105 };
106
107static STACK_OF(CONF_MODULE) *supported_modules = NULL;
108static STACK_OF(CONF_IMODULE) *initialized_modules = NULL;
109
110static void module_free(CONF_MODULE *md);
111static void module_finish(CONF_IMODULE *imod);
112static int module_run(const CONF *cnf, char *name, char *value,
113 unsigned long flags);
114static CONF_MODULE *module_add(DSO *dso, const char *name,
115 conf_init_func *ifunc, conf_finish_func *ffunc);
116static CONF_MODULE *module_find(char *name);
117static int module_init(CONF_MODULE *pmod, char *name, char *value,
118 const CONF *cnf);
119static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
120 unsigned long flags);
121
122/* Main function: load modules from a CONF structure */
123
124int CONF_modules_load(const CONF *cnf, const char *appname,
125 unsigned long flags)
126 {
127 STACK_OF(CONF_VALUE) *values;
128 CONF_VALUE *vl;
129 char *vsection;
130
131 int ret, i;
132
133 if (!cnf)
134 return 1;
135
136 if (appname == NULL)
137 appname = "openssl_conf";
138
139 vsection = NCONF_get_string(cnf, NULL, appname);
140
141 if (!vsection)
142 {
143 ERR_clear_error();
144 return 1;
145 }
146
147 values = NCONF_get_section(cnf, vsection);
148
149 if (!values)
150 return 0;
151
152 for (i = 0; i < sk_CONF_VALUE_num(values); i++)
153 {
154 vl = sk_CONF_VALUE_value(values, i);
155 ret = module_run(cnf, vl->name, vl->value, flags);
156 if (ret <= 0)
157 if(!(flags & CONF_MFLAGS_IGNORE_ERRORS))
158 return ret;
159 }
160
161 return 1;
162
163 }
164
165int CONF_modules_load_file(const char *filename, const char *appname,
166 unsigned long flags)
167 {
168 char *file = NULL;
169 CONF *conf = NULL;
170 int ret = 0;
171 conf = NCONF_new(NULL);
172 if (!conf)
173 goto err;
174
175 if (filename == NULL)
176 {
177 file = CONF_get1_default_config_file();
178 if (!file)
179 goto err;
180 }
181 else
182 file = (char *)filename;
183
184 if (NCONF_load(conf, file, NULL) <= 0)
185 {
186 if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) &&
187 (ERR_GET_REASON(ERR_peek_last_error()) == CONF_R_NO_SUCH_FILE))
188 {
189 ERR_clear_error();
190 ret = 1;
191 }
192 goto err;
193 }
194
195 ret = CONF_modules_load(conf, appname, flags);
196
197 err:
198 if (filename == NULL)
199 OPENSSL_free(file);
200 NCONF_free(conf);
201
202 return ret;
203 }
204
205static int module_run(const CONF *cnf, char *name, char *value,
206 unsigned long flags)
207 {
208 CONF_MODULE *md;
209 int ret;
210
211 md = module_find(name);
212
213 /* Module not found: try to load DSO */
214 if (!md && !(flags & CONF_MFLAGS_NO_DSO))
215 md = module_load_dso(cnf, name, value, flags);
216
217 if (!md)
218 {
219 if (!(flags & CONF_MFLAGS_SILENT))
220 {
221 CONFerr(CONF_F_MODULE_RUN, CONF_R_UNKNOWN_MODULE_NAME);
222 ERR_add_error_data(2, "module=", name);
223 }
224 return -1;
225 }
226
227 ret = module_init(md, name, value, cnf);
228
229 if (ret <= 0)
230 {
231 if (!(flags & CONF_MFLAGS_SILENT))
232 {
233 char rcode[DECIMAL_SIZE(ret)+1];
234 CONFerr(CONF_F_CONF_MODULES_LOAD, CONF_R_MODULE_INITIALIZATION_ERROR);
235 BIO_snprintf(rcode, sizeof rcode, "%-8d", ret);
236 ERR_add_error_data(6, "module=", name, ", value=", value, ", retcode=", rcode);
237 }
238 }
239
240 return ret;
241 }
242
243/* Load a module from a DSO */
244static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
245 unsigned long flags)
246 {
247 DSO *dso = NULL;
248 conf_init_func *ifunc;
249 conf_finish_func *ffunc;
250 char *path = NULL;
251 int errcode = 0;
252 CONF_MODULE *md;
253 /* Look for alternative path in module section */
254 path = NCONF_get_string(cnf, value, "path");
255 if (!path)
256 {
257 ERR_get_error();
258 path = name;
259 }
260 dso = DSO_load(NULL, path, NULL, 0);
261 if (!dso)
262 {
263 errcode = CONF_R_ERROR_LOADING_DSO;
264 goto err;
265 }
266 ifunc = (conf_init_func *)DSO_bind_func(dso, DSO_mod_init_name);
267 if (!ifunc)
268 {
269 errcode = CONF_R_MISSING_INIT_FUNCTION;
270 goto err;
271 }
272 ffunc = (conf_finish_func *)DSO_bind_func(dso, DSO_mod_finish_name);
273 /* All OK, add module */
274 md = module_add(dso, name, ifunc, ffunc);
275
276 if (!md)
277 goto err;
278
279 return md;
280
281 err:
282 if (dso)
283 DSO_free(dso);
284 CONFerr(CONF_F_MODULE_LOAD_DSO, errcode);
285 ERR_add_error_data(4, "module=", name, ", path=", path);
286 return NULL;
287 }
288
289/* add module to list */
290static CONF_MODULE *module_add(DSO *dso, const char *name,
291 conf_init_func *ifunc, conf_finish_func *ffunc)
292 {
293 CONF_MODULE *tmod = NULL;
294 if (supported_modules == NULL)
295 supported_modules = sk_CONF_MODULE_new_null();
296 if (supported_modules == NULL)
297 return NULL;
298 tmod = OPENSSL_malloc(sizeof(CONF_MODULE));
299 if (tmod == NULL)
300 return NULL;
301
302 tmod->dso = dso;
303 tmod->name = BUF_strdup(name);
304 tmod->init = ifunc;
305 tmod->finish = ffunc;
306 tmod->links = 0;
307
308 if (!sk_CONF_MODULE_push(supported_modules, tmod))
309 {
310 OPENSSL_free(tmod);
311 return NULL;
312 }
313
314 return tmod;
315 }
316
317/* Find a module from the list. We allow module names of the
318 * form modname.XXXX to just search for modname to allow the
319 * same module to be initialized more than once.
320 */
321
322static CONF_MODULE *module_find(char *name)
323 {
324 CONF_MODULE *tmod;
325 int i, nchar;
326 char *p;
327 p = strrchr(name, '.');
328
329 if (p)
330 nchar = p - name;
331 else
332 nchar = strlen(name);
333
334 for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++)
335 {
336 tmod = sk_CONF_MODULE_value(supported_modules, i);
337 if (!strncmp(tmod->name, name, nchar))
338 return tmod;
339 }
340
341 return NULL;
342
343 }
344
345/* initialize a module */
346static int module_init(CONF_MODULE *pmod, char *name, char *value,
347 const CONF *cnf)
348 {
349 int ret = 1;
350 int init_called = 0;
351 CONF_IMODULE *imod = NULL;
352
353 /* Otherwise add initialized module to list */
354 imod = OPENSSL_malloc(sizeof(CONF_IMODULE));
355 if (!imod)
356 goto err;
357
358 imod->pmod = pmod;
359 imod->name = BUF_strdup(name);
360 imod->value = BUF_strdup(value);
361 imod->usr_data = NULL;
362
363 if (!imod->name || !imod->value)
364 goto memerr;
365
366 /* Try to initialize module */
367 if(pmod->init)
368 {
369 ret = pmod->init(imod, cnf);
370 init_called = 1;
371 /* Error occurred, exit */
372 if (ret <= 0)
373 goto err;
374 }
375
376 if (initialized_modules == NULL)
377 {
378 initialized_modules = sk_CONF_IMODULE_new_null();
379 if (!initialized_modules)
380 {
381 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);
382 goto err;
383 }
384 }
385
386 if (!sk_CONF_IMODULE_push(initialized_modules, imod))
387 {
388 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);
389 goto err;
390 }
391
392 pmod->links++;
393
394 return ret;
395
396 err:
397
398 /* We've started the module so we'd better finish it */
399 if (pmod->finish && init_called)
400 pmod->finish(imod);
401
402 memerr:
403 if (imod)
404 {
405 if (imod->name)
406 OPENSSL_free(imod->name);
407 if (imod->value)
408 OPENSSL_free(imod->value);
409 OPENSSL_free(imod);
410 }
411
412 return -1;
413
414 }
415
416/* Unload any dynamic modules that have a link count of zero:
417 * i.e. have no active initialized modules. If 'all' is set
418 * then all modules are unloaded including static ones.
419 */
420
421void CONF_modules_unload(int all)
422 {
423 int i;
424 CONF_MODULE *md;
425 CONF_modules_finish();
426 /* unload modules in reverse order */
427 for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--)
428 {
429 md = sk_CONF_MODULE_value(supported_modules, i);
430 /* If static or in use and 'all' not set ignore it */
431 if (((md->links > 0) || !md->dso) && !all)
432 continue;
433 /* Since we're working in reverse this is OK */
434 sk_CONF_MODULE_delete(supported_modules, i);
435 module_free(md);
436 }
437 if (sk_CONF_MODULE_num(supported_modules) == 0)
438 {
439 sk_CONF_MODULE_free(supported_modules);
440 supported_modules = NULL;
441 }
442 }
443
444/* unload a single module */
445static void module_free(CONF_MODULE *md)
446 {
447 if (md->dso)
448 DSO_free(md->dso);
449 OPENSSL_free(md->name);
450 OPENSSL_free(md);
451 }
452
453/* finish and free up all modules instances */
454
455void CONF_modules_finish(void)
456 {
457 CONF_IMODULE *imod;
458 while (sk_CONF_IMODULE_num(initialized_modules) > 0)
459 {
460 imod = sk_CONF_IMODULE_pop(initialized_modules);
461 module_finish(imod);
462 }
463 sk_CONF_IMODULE_free(initialized_modules);
464 initialized_modules = NULL;
465 }
466
467/* finish a module instance */
468
469static void module_finish(CONF_IMODULE *imod)
470 {
471 if (imod->pmod->finish)
472 imod->pmod->finish(imod);
473 imod->pmod->links--;
474 OPENSSL_free(imod->name);
475 OPENSSL_free(imod->value);
476 OPENSSL_free(imod);
477 }
478
479/* Add a static module to OpenSSL */
480
481int CONF_module_add(const char *name, conf_init_func *ifunc,
482 conf_finish_func *ffunc)
483 {
484 if (module_add(NULL, name, ifunc, ffunc))
485 return 1;
486 else
487 return 0;
488 }
489
490void CONF_modules_free(void)
491 {
492 CONF_modules_finish();
493 CONF_modules_unload(1);
494 }
495
496/* Utility functions */
497
498const char *CONF_imodule_get_name(const CONF_IMODULE *md)
499 {
500 return md->name;
501 }
502
503const char *CONF_imodule_get_value(const CONF_IMODULE *md)
504 {
505 return md->value;
506 }
507
508void *CONF_imodule_get_usr_data(const CONF_IMODULE *md)
509 {
510 return md->usr_data;
511 }
512
513void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data)
514 {
515 md->usr_data = usr_data;
516 }
517
518CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md)
519 {
520 return md->pmod;
521 }
522
523unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md)
524 {
525 return md->flags;
526 }
527
528void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags)
529 {
530 md->flags = flags;
531 }
532
533void *CONF_module_get_usr_data(CONF_MODULE *pmod)
534 {
535 return pmod->usr_data;
536 }
537
538void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data)
539 {
540 pmod->usr_data = usr_data;
541 }
542
543/* Return default config file name */
544
545char *CONF_get1_default_config_file(void)
546 {
547 char *file;
548 int len;
549
550 file = getenv("OPENSSL_CONF");
551 if (file)
552 return BUF_strdup(file);
553
554 len = strlen(X509_get_default_cert_area());
555#ifndef OPENSSL_SYS_VMS
556 len++;
557#endif
558 len += strlen(OPENSSL_CONF);
559
560 file = OPENSSL_malloc(len + 1);
561
562 if (!file)
563 return NULL;
564 BUF_strlcpy(file,X509_get_default_cert_area(),len + 1);
565#ifndef OPENSSL_SYS_VMS
566 BUF_strlcat(file,"/",len + 1);
567#endif
568 BUF_strlcat(file,OPENSSL_CONF,len + 1);
569
570 return file;
571 }
572
573/* This function takes a list separated by 'sep' and calls the
574 * callback function giving the start and length of each member
575 * optionally stripping leading and trailing whitespace. This can
576 * be used to parse comma separated lists for example.
577 */
578
579int CONF_parse_list(const char *list_, int sep, int nospc,
580 int (*list_cb)(const char *elem, int len, void *usr), void *arg)
581 {
582 int ret;
583 const char *lstart, *tmpend, *p;
584 lstart = list_;
585
586 for(;;)
587 {
588 if (nospc)
589 {
590 while(isspace((unsigned char)*lstart))
591 lstart++;
592 }
593 p = strchr(lstart, sep);
594 if (p == lstart || !*lstart)
595 ret = list_cb(NULL, 0, arg);
596 else
597 {
598 if (p)
599 tmpend = p - 1;
600 else
601 tmpend = lstart + strlen(lstart) - 1;
602 if (nospc)
603 {
604 while(isspace((unsigned char)*tmpend))
605 tmpend--;
606 }
607 ret = list_cb(lstart, tmpend - lstart + 1, arg);
608 }
609 if (ret <= 0)
610 return ret;
611 if (p == NULL)
612 return 1;
613 lstart = p + 1;
614 }
615 }
616
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c
deleted file mode 100644
index e15c2e5546..0000000000
--- a/src/lib/libcrypto/conf/conf_sap.c
+++ /dev/null
@@ -1,111 +0,0 @@
1/* conf_sap.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/dso.h>
64#include <openssl/x509.h>
65#include <openssl/asn1.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70/* This is the automatic configuration loader: it is called automatically by
71 * OpenSSL when any of a number of standard initialisation functions are called,
72 * unless this is overridden by calling OPENSSL_no_config()
73 */
74
75static int openssl_configured = 0;
76
77void OPENSSL_config(const char *config_name)
78 {
79 if (openssl_configured)
80 return;
81
82 OPENSSL_load_builtin_modules();
83#ifndef OPENSSL_NO_ENGINE
84 /* Need to load ENGINEs */
85 ENGINE_load_builtin_engines();
86#endif
87 /* Add others here? */
88
89
90 ERR_clear_error();
91 if (CONF_modules_load_file(NULL, NULL,
92 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)
93 {
94 BIO *bio_err;
95 ERR_load_crypto_strings();
96 if ((bio_err=BIO_new_fp(stderr, BIO_NOCLOSE)) != NULL)
97 {
98 BIO_printf(bio_err,"Auto configuration failed\n");
99 ERR_print_errors(bio_err);
100 BIO_free(bio_err);
101 }
102 exit(1);
103 }
104
105 return;
106 }
107
108void OPENSSL_no_config()
109 {
110 openssl_configured = 1;
111 }
diff --git a/src/lib/libcrypto/conf/keysets.pl b/src/lib/libcrypto/conf/keysets.pl
deleted file mode 100644
index 50ed67fa52..0000000000
--- a/src/lib/libcrypto/conf/keysets.pl
+++ /dev/null
@@ -1,185 +0,0 @@
1#!/usr/local/bin/perl
2
3$NUMBER=0x01;
4$UPPER=0x02;
5$LOWER=0x04;
6$UNDER=0x100;
7$PUNCTUATION=0x200;
8$WS=0x10;
9$ESC=0x20;
10$QUOTE=0x40;
11$DQUOTE=0x400;
12$COMMENT=0x80;
13$FCOMMENT=0x800;
14$EOF=0x08;
15$HIGHBIT=0x1000;
16
17foreach (0 .. 255)
18 {
19 $v=0;
20 $c=sprintf("%c",$_);
21 $v|=$NUMBER if ($c =~ /[0-9]/);
22 $v|=$UPPER if ($c =~ /[A-Z]/);
23 $v|=$LOWER if ($c =~ /[a-z]/);
24 $v|=$UNDER if ($c =~ /_/);
25 $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
26 $v|=$WS if ($c =~ /[ \t\r\n]/);
27 $v|=$ESC if ($c =~ /\\/);
28 $v|=$QUOTE if ($c =~ /['`"]/); # for emacs: "`'}/)
29 $v|=$COMMENT if ($c =~ /\#/);
30 $v|=$EOF if ($c =~ /\0/);
31 $v|=$HIGHBIT if ($c =~/[\x80-\xff]/);
32
33 push(@V_def,$v);
34 }
35
36foreach (0 .. 255)
37 {
38 $v=0;
39 $c=sprintf("%c",$_);
40 $v|=$NUMBER if ($c =~ /[0-9]/);
41 $v|=$UPPER if ($c =~ /[A-Z]/);
42 $v|=$LOWER if ($c =~ /[a-z]/);
43 $v|=$UNDER if ($c =~ /_/);
44 $v|=$PUNCTUATION if ($c =~ /[!\.%&\*\+,\/;\?\@\^\~\|-]/);
45 $v|=$WS if ($c =~ /[ \t\r\n]/);
46 $v|=$DQUOTE if ($c =~ /["]/); # for emacs: "}/)
47 $v|=$FCOMMENT if ($c =~ /;/);
48 $v|=$EOF if ($c =~ /\0/);
49 $v|=$HIGHBIT if ($c =~/[\x80-\xff]/);
50
51 push(@V_w32,$v);
52 }
53
54print <<"EOF";
55/* crypto/conf/conf_def.h */
56/* Copyright (C) 1995-1998 Eric Young (eay\@cryptsoft.com)
57 * All rights reserved.
58 *
59 * This package is an SSL implementation written
60 * by Eric Young (eay\@cryptsoft.com).
61 * The implementation was written so as to conform with Netscapes SSL.
62 *
63 * This library is free for commercial and non-commercial use as long as
64 * the following conditions are aheared to. The following conditions
65 * apply to all code found in this distribution, be it the RC4, RSA,
66 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
67 * included with this distribution is covered by the same copyright terms
68 * except that the holder is Tim Hudson (tjh\@cryptsoft.com).
69 *
70 * Copyright remains Eric Young's, and as such any Copyright notices in
71 * the code are not to be removed.
72 * If this package is used in a product, Eric Young should be given attribution
73 * as the author of the parts of the library used.
74 * This can be in the form of a textual message at program startup or
75 * in documentation (online or textual) provided with the package.
76 *
77 * Redistribution and use in source and binary forms, with or without
78 * modification, are permitted provided that the following conditions
79 * are met:
80 * 1. Redistributions of source code must retain the copyright
81 * notice, this list of conditions and the following disclaimer.
82 * 2. Redistributions in binary form must reproduce the above copyright
83 * notice, this list of conditions and the following disclaimer in the
84 * documentation and/or other materials provided with the distribution.
85 * 3. All advertising materials mentioning features or use of this software
86 * must display the following acknowledgement:
87 * "This product includes cryptographic software written by
88 * Eric Young (eay\@cryptsoft.com)"
89 * The word 'cryptographic' can be left out if the rouines from the library
90 * being used are not cryptographic related :-).
91 * 4. If you include any Windows specific code (or a derivative thereof) from
92 * the apps directory (application code) you must include an acknowledgement:
93 * "This product includes software written by Tim Hudson (tjh\@cryptsoft.com)"
94 *
95 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
96 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
97 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
99 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
100 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
101 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
102 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
103 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
104 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
105 * SUCH DAMAGE.
106 *
107 * The licence and distribution terms for any publically available version or
108 * derivative of this code cannot be changed. i.e. this code cannot simply be
109 * copied and put under another distribution licence
110 * [including the GNU Public Licence.]
111 */
112
113/* THIS FILE WAS AUTOMAGICALLY GENERATED!
114 Please modify and use keysets.pl to regenerate it. */
115
116#define CONF_NUMBER $NUMBER
117#define CONF_UPPER $UPPER
118#define CONF_LOWER $LOWER
119#define CONF_UNDER $UNDER
120#define CONF_PUNCTUATION $PUNCTUATION
121#define CONF_WS $WS
122#define CONF_ESC $ESC
123#define CONF_QUOTE $QUOTE
124#define CONF_DQUOTE $DQUOTE
125#define CONF_COMMENT $COMMENT
126#define CONF_FCOMMENT $FCOMMENT
127#define CONF_EOF $EOF
128#define CONF_HIGHBIT $HIGHBIT
129#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
130#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
131#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \\
132 CONF_PUNCTUATION)
133
134#define KEYTYPES(c) ((unsigned short *)((c)->meth_data))
135#ifndef CHARSET_EBCDIC
136#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
137#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
138#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
139#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
140#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
141#define IS_WS(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_WS)
142#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
143#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
144 (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
145#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
146#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
147#define IS_HIGHBIT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
148
149#else /*CHARSET_EBCDIC*/
150
151#define IS_COMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_COMMENT)
152#define IS_FCOMMENT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_FCOMMENT)
153#define IS_EOF(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_EOF)
154#define IS_ESC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ESC)
155#define IS_NUMBER(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_NUMBER)
156#define IS_WS(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_WS)
157#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC)
158#define IS_ALPHA_NUMERIC_PUNCT(c,a) \\
159 (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
160#define IS_QUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_QUOTE)
161#define IS_DQUOTE(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_DQUOTE)
162#define IS_HIGHBIT(c,a) (KEYTYPES(c)[os_toascii[a]&0xff]&CONF_HIGHBIT)
163#endif /*CHARSET_EBCDIC*/
164
165EOF
166
167print "static unsigned short CONF_type_default[256]={";
168
169for ($i=0; $i<256; $i++)
170 {
171 print "\n\t" if ($i % 8) == 0;
172 printf "0x%04X,",$V_def[$i];
173 }
174
175print "\n\t};\n\n";
176
177print "static unsigned short CONF_type_win32[256]={";
178
179for ($i=0; $i<256; $i++)
180 {
181 print "\n\t" if ($i % 8) == 0;
182 printf "0x%04X,",$V_w32[$i];
183 }
184
185print "\n\t};\n\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 06a6109cce..0000000000
--- a/src/lib/libcrypto/cpt_err.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/* crypto/cpt_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_CRYPTO,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_CRYPTO,0,reason)
70
71static ERR_STRING_DATA CRYPTO_str_functs[]=
72 {
73{ERR_FUNC(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX), "CRYPTO_get_ex_new_index"},
74{ERR_FUNC(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID), "CRYPTO_get_new_dynlockid"},
75{ERR_FUNC(CRYPTO_F_CRYPTO_GET_NEW_LOCKID), "CRYPTO_get_new_lockid"},
76{ERR_FUNC(CRYPTO_F_CRYPTO_SET_EX_DATA), "CRYPTO_set_ex_data"},
77{ERR_FUNC(CRYPTO_F_DEF_ADD_INDEX), "DEF_ADD_INDEX"},
78{ERR_FUNC(CRYPTO_F_DEF_GET_CLASS), "DEF_GET_CLASS"},
79{ERR_FUNC(CRYPTO_F_INT_DUP_EX_DATA), "INT_DUP_EX_DATA"},
80{ERR_FUNC(CRYPTO_F_INT_FREE_EX_DATA), "INT_FREE_EX_DATA"},
81{ERR_FUNC(CRYPTO_F_INT_NEW_EX_DATA), "INT_NEW_EX_DATA"},
82{0,NULL}
83 };
84
85static ERR_STRING_DATA CRYPTO_str_reasons[]=
86 {
87{ERR_REASON(CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK),"no dynlock create callback"},
88{0,NULL}
89 };
90
91#endif
92
93void ERR_load_CRYPTO_strings(void)
94 {
95 static int init=1;
96
97 if (init)
98 {
99 init=0;
100#ifndef OPENSSL_NO_ERR
101 ERR_load_strings(0,CRYPTO_str_functs);
102 ERR_load_strings(0,CRYPTO_str_reasons);
103#endif
104
105 }
106 }
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
deleted file mode 100644
index e63bbe8dba..0000000000
--- a/src/lib/libcrypto/cryptlib.c
+++ /dev/null
@@ -1,744 +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#include <openssl/safestack.h>
64
65#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
66static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
67#endif
68
69DECLARE_STACK_OF(CRYPTO_dynlock)
70IMPLEMENT_STACK_OF(CRYPTO_dynlock)
71
72/* real #defines in crypto.h, keep these upto date */
73static const char* lock_names[CRYPTO_NUM_LOCKS] =
74 {
75 "<<ERROR>>",
76 "err",
77 "ex_data",
78 "x509",
79 "x509_info",
80 "x509_pkey",
81 "x509_crl",
82 "x509_req",
83 "dsa",
84 "rsa",
85 "evp_pkey",
86 "x509_store",
87 "ssl_ctx",
88 "ssl_cert",
89 "ssl_session",
90 "ssl_sess_cert",
91 "ssl",
92 "ssl_method",
93 "rand",
94 "rand2",
95 "debug_malloc",
96 "BIO",
97 "gethostbyname",
98 "getservbyname",
99 "readdir",
100 "RSA_blinding",
101 "dh",
102 "debug_malloc2",
103 "dso",
104 "dynlock",
105 "engine",
106 "ui",
107 "hwcrhk", /* This is a HACK which will disappear in 0.9.8 */
108 "fips",
109 "fips2",
110#if CRYPTO_NUM_LOCKS != 35
111# error "Inconsistency between crypto.h and cryptlib.c"
112#endif
113 };
114
115/* This is for applications to allocate new type names in the non-dynamic
116 array of lock names. These are numbered with positive numbers. */
117static STACK *app_locks=NULL;
118
119/* For applications that want a more dynamic way of handling threads, the
120 following stack is used. These are externally numbered with negative
121 numbers. */
122static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;
123
124
125static void (MS_FAR *locking_callback)(int mode,int type,
126 const char *file,int line)=NULL;
127static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
128 int type,const char *file,int line)=NULL;
129static unsigned long (MS_FAR *id_callback)(void)=NULL;
130static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
131 (const char *file,int line)=NULL;
132static void (MS_FAR *dynlock_lock_callback)(int mode,
133 struct CRYPTO_dynlock_value *l, const char *file,int line)=NULL;
134static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l,
135 const char *file,int line)=NULL;
136
137int CRYPTO_get_new_lockid(char *name)
138 {
139 char *str;
140 int i;
141
142#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
143 /* A hack to make Visual C++ 5.0 work correctly when linking as
144 * a DLL using /MT. Without this, the application cannot use
145 * and floating point printf's.
146 * It also seems to be needed for Visual C 1.5 (win16) */
147 SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
148#endif
149
150 if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL))
151 {
152 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
153 return(0);
154 }
155 if ((str=BUF_strdup(name)) == NULL)
156 {
157 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
158 return(0);
159 }
160 i=sk_push(app_locks,str);
161 if (!i)
162 OPENSSL_free(str);
163 else
164 i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */
165 return(i);
166 }
167
168int CRYPTO_num_locks(void)
169 {
170 return CRYPTO_NUM_LOCKS;
171 }
172
173int CRYPTO_get_new_dynlockid(void)
174 {
175 int i = 0;
176 CRYPTO_dynlock *pointer = NULL;
177
178 if (dynlock_create_callback == NULL)
179 {
180 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK);
181 return(0);
182 }
183 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
184 if ((dyn_locks == NULL)
185 && ((dyn_locks=sk_CRYPTO_dynlock_new_null()) == NULL))
186 {
187 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
188 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
189 return(0);
190 }
191 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
192
193 pointer = (CRYPTO_dynlock *)OPENSSL_malloc(sizeof(CRYPTO_dynlock));
194 if (pointer == NULL)
195 {
196 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
197 return(0);
198 }
199 pointer->references = 1;
200 pointer->data = dynlock_create_callback(__FILE__,__LINE__);
201 if (pointer->data == NULL)
202 {
203 OPENSSL_free(pointer);
204 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE);
205 return(0);
206 }
207
208 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
209 /* First, try to find an existing empty slot */
210 i=sk_CRYPTO_dynlock_find(dyn_locks,NULL);
211 /* If there was none, push, thereby creating a new one */
212 if (i == -1)
213 /* Since sk_push() returns the number of items on the
214 stack, not the location of the pushed item, we need
215 to transform the returned number into a position,
216 by decreasing it. */
217 i=sk_CRYPTO_dynlock_push(dyn_locks,pointer) - 1;
218 else
219 /* If we found a place with a NULL pointer, put our pointer
220 in it. */
221 sk_CRYPTO_dynlock_set(dyn_locks,i,pointer);
222 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
223
224 if (i == -1)
225 {
226 dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
227 OPENSSL_free(pointer);
228 }
229 else
230 i += 1; /* to avoid 0 */
231 return -i;
232 }
233
234void CRYPTO_destroy_dynlockid(int i)
235 {
236 CRYPTO_dynlock *pointer = NULL;
237 if (i)
238 i = -i-1;
239 if (dynlock_destroy_callback == NULL)
240 return;
241
242 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
243
244 if (dyn_locks == NULL || i >= sk_CRYPTO_dynlock_num(dyn_locks))
245 {
246 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
247 return;
248 }
249 pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
250 if (pointer != NULL)
251 {
252 --pointer->references;
253#ifdef REF_CHECK
254 if (pointer->references < 0)
255 {
256 fprintf(stderr,"CRYPTO_destroy_dynlockid, bad reference count\n");
257 abort();
258 }
259 else
260#endif
261 if (pointer->references <= 0)
262 {
263 sk_CRYPTO_dynlock_set(dyn_locks, i, NULL);
264 }
265 else
266 pointer = NULL;
267 }
268 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
269
270 if (pointer)
271 {
272 dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
273 OPENSSL_free(pointer);
274 }
275 }
276
277struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i)
278 {
279 CRYPTO_dynlock *pointer = NULL;
280 if (i)
281 i = -i-1;
282
283 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
284
285 if (dyn_locks != NULL && i < sk_CRYPTO_dynlock_num(dyn_locks))
286 pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
287 if (pointer)
288 pointer->references++;
289
290 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
291
292 if (pointer)
293 return pointer->data;
294 return NULL;
295 }
296
297struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))
298 (const char *file,int line)
299 {
300 return(dynlock_create_callback);
301 }
302
303void (*CRYPTO_get_dynlock_lock_callback(void))(int mode,
304 struct CRYPTO_dynlock_value *l, const char *file,int line)
305 {
306 return(dynlock_lock_callback);
307 }
308
309void (*CRYPTO_get_dynlock_destroy_callback(void))
310 (struct CRYPTO_dynlock_value *l, const char *file,int line)
311 {
312 return(dynlock_destroy_callback);
313 }
314
315void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*func)
316 (const char *file, int line))
317 {
318 dynlock_create_callback=func;
319 }
320
321void CRYPTO_set_dynlock_lock_callback(void (*func)(int mode,
322 struct CRYPTO_dynlock_value *l, const char *file, int line))
323 {
324 dynlock_lock_callback=func;
325 }
326
327void CRYPTO_set_dynlock_destroy_callback(void (*func)
328 (struct CRYPTO_dynlock_value *l, const char *file, int line))
329 {
330 dynlock_destroy_callback=func;
331 }
332
333
334void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
335 int line)
336 {
337 return(locking_callback);
338 }
339
340int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
341 const char *file,int line)
342 {
343 return(add_lock_callback);
344 }
345
346void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
347 const char *file,int line))
348 {
349 locking_callback=func;
350 }
351
352void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
353 const char *file,int line))
354 {
355 add_lock_callback=func;
356 }
357
358unsigned long (*CRYPTO_get_id_callback(void))(void)
359 {
360 return(id_callback);
361 }
362
363void CRYPTO_set_id_callback(unsigned long (*func)(void))
364 {
365 id_callback=func;
366 }
367
368unsigned long CRYPTO_thread_id(void)
369 {
370 unsigned long ret=0;
371
372 if (id_callback == NULL)
373 {
374#ifdef OPENSSL_SYS_WIN16
375 ret=(unsigned long)GetCurrentTask();
376#elif defined(OPENSSL_SYS_WIN32)
377 ret=(unsigned long)GetCurrentThreadId();
378#elif defined(GETPID_IS_MEANINGLESS)
379 ret=1L;
380#else
381 ret=(unsigned long)getpid();
382#endif
383 }
384 else
385 ret=id_callback();
386 return(ret);
387 }
388
389void CRYPTO_lock(int mode, int type, const char *file, int line)
390 {
391#ifdef LOCK_DEBUG
392 {
393 char *rw_text,*operation_text;
394
395 if (mode & CRYPTO_LOCK)
396 operation_text="lock ";
397 else if (mode & CRYPTO_UNLOCK)
398 operation_text="unlock";
399 else
400 operation_text="ERROR ";
401
402 if (mode & CRYPTO_READ)
403 rw_text="r";
404 else if (mode & CRYPTO_WRITE)
405 rw_text="w";
406 else
407 rw_text="ERROR";
408
409 fprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\n",
410 CRYPTO_thread_id(), rw_text, operation_text,
411 CRYPTO_get_lock_name(type), file, line);
412 }
413#endif
414 if (type < 0)
415 {
416 if (dynlock_lock_callback != NULL)
417 {
418 struct CRYPTO_dynlock_value *pointer
419 = CRYPTO_get_dynlock_value(type);
420
421 OPENSSL_assert(pointer != NULL);
422
423 dynlock_lock_callback(mode, pointer, file, line);
424
425 CRYPTO_destroy_dynlockid(type);
426 }
427 }
428 else
429 if (locking_callback != NULL)
430 locking_callback(mode,type,file,line);
431 }
432
433int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
434 int line)
435 {
436 int ret = 0;
437
438 if (add_lock_callback != NULL)
439 {
440#ifdef LOCK_DEBUG
441 int before= *pointer;
442#endif
443
444 ret=add_lock_callback(pointer,amount,type,file,line);
445#ifdef LOCK_DEBUG
446 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
447 CRYPTO_thread_id(),
448 before,amount,ret,
449 CRYPTO_get_lock_name(type),
450 file,line);
451#endif
452 }
453 else
454 {
455 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);
456
457 ret= *pointer+amount;
458#ifdef LOCK_DEBUG
459 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
460 CRYPTO_thread_id(),
461 *pointer,amount,ret,
462 CRYPTO_get_lock_name(type),
463 file,line);
464#endif
465 *pointer=ret;
466 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
467 }
468 return(ret);
469 }
470
471const char *CRYPTO_get_lock_name(int type)
472 {
473 if (type < 0)
474 return("dynamic");
475 else if (type < CRYPTO_NUM_LOCKS)
476 return(lock_names[type]);
477 else if (type-CRYPTO_NUM_LOCKS > sk_num(app_locks))
478 return("ERROR");
479 else
480 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
481 }
482
483int OPENSSL_NONPIC_relocated=0;
484
485#if defined(_WIN32) && defined(_WINDLL)
486
487/* All we really need to do is remove the 'error' state when a thread
488 * detaches */
489
490BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
491 LPVOID lpvReserved)
492 {
493 switch(fdwReason)
494 {
495 case DLL_PROCESS_ATTACH:
496#if defined(_WIN32_WINNT)
497 {
498 IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)hinstDLL;
499 IMAGE_NT_HEADERS *nt_headers;
500
501 if (dos_header->e_magic==IMAGE_DOS_SIGNATURE)
502 {
503 nt_headers = (IMAGE_NT_HEADERS *)((char *)dos_header
504 + dos_header->e_lfanew);
505 if (nt_headers->Signature==IMAGE_NT_SIGNATURE &&
506 hinstDLL!=(HINSTANCE)(nt_headers->OptionalHeader.ImageBase))
507 OPENSSL_NONPIC_relocated=1;
508 }
509 }
510#endif
511 break;
512 case DLL_THREAD_ATTACH:
513 break;
514 case DLL_THREAD_DETACH:
515 ERR_remove_state(0);
516 break;
517 case DLL_PROCESS_DETACH:
518 break;
519 }
520 return(TRUE);
521 }
522#endif
523
524#if defined(_WIN32)
525#include <tchar.h>
526
527#if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
528static int IsService(void)
529{ HWINSTA h;
530 DWORD len;
531 WCHAR *name;
532
533 (void)GetDesktopWindow(); /* return value is ignored */
534
535 h = GetProcessWindowStation();
536 if (h==NULL) return -1;
537
538 if (GetUserObjectInformationW (h,UOI_NAME,NULL,0,&len) ||
539 GetLastError() != ERROR_INSUFFICIENT_BUFFER)
540 return -1;
541
542 if (len>512) return -1; /* paranoia */
543 len++,len&=~1; /* paranoia */
544#ifdef _MSC_VER
545 name=(WCHAR *)_alloca(len+sizeof(WCHAR));
546#else
547 name=(WCHAR *)alloca(len+sizeof(WCHAR));
548#endif
549 if (!GetUserObjectInformationW (h,UOI_NAME,name,len,&len))
550 return -1;
551
552 len++,len&=~1; /* paranoia */
553 name[len/sizeof(WCHAR)]=L'\0'; /* paranoia */
554#if 1
555 /* This doesn't cover "interactive" services [working with real
556 * WinSta0's] nor programs started non-interactively by Task
557 * Scheduler [those are working with SAWinSta]. */
558 if (wcsstr(name,L"Service-0x")) return 1;
559#else
560 /* This covers all non-interactive programs such as services. */
561 if (!wcsstr(name,L"WinSta0")) return 1;
562#endif
563 else return 0;
564}
565#endif
566
567void OPENSSL_showfatal (const char *fmta,...)
568{ va_list ap;
569 TCHAR buf[256];
570 const TCHAR *fmt;
571 HANDLE h;
572
573 if ((h=GetStdHandle(STD_ERROR_HANDLE)) != NULL &&
574 GetFileType(h)!=FILE_TYPE_UNKNOWN)
575 { /* must be console application */
576 va_start (ap,fmta);
577 vfprintf (stderr,fmta,ap);
578 va_end (ap);
579 return;
580 }
581
582 if (sizeof(TCHAR)==sizeof(char))
583 fmt=(const TCHAR *)fmta;
584 else do
585 { int keepgoing;
586 size_t len_0=strlen(fmta)+1,i;
587 WCHAR *fmtw;
588
589#ifdef _MSC_VER
590 fmtw = (WCHAR *)_alloca (len_0*sizeof(WCHAR));
591#else
592 fmtw = (WCHAR *)alloca (len_0*sizeof(WCHAR));
593#endif
594 if (fmtw == NULL) { fmt=(const TCHAR *)L"no stack?"; break; }
595
596#ifndef OPENSSL_NO_MULTIBYTE
597 if (!MultiByteToWideChar(CP_ACP,0,fmta,len_0,fmtw,len_0))
598#endif
599 for (i=0;i<len_0;i++) fmtw[i]=(WCHAR)fmta[i];
600
601 for (i=0;i<len_0;i++)
602 { if (fmtw[i]==L'%') do
603 { keepgoing=0;
604 switch (fmtw[i+1])
605 { case L'0': case L'1': case L'2': case L'3': case L'4':
606 case L'5': case L'6': case L'7': case L'8': case L'9':
607 case L'.': case L'*':
608 case L'-': i++; keepgoing=1; break;
609 case L's': fmtw[i+1]=L'S'; break;
610 case L'S': fmtw[i+1]=L's'; break;
611 case L'c': fmtw[i+1]=L'C'; break;
612 case L'C': fmtw[i+1]=L'c'; break;
613 }
614 } while (keepgoing);
615 }
616 fmt = (const TCHAR *)fmtw;
617 } while (0);
618
619 va_start (ap,fmta);
620 _vsntprintf (buf,sizeof(buf)/sizeof(TCHAR)-1,fmt,ap);
621 buf [sizeof(buf)/sizeof(TCHAR)-1] = _T('\0');
622 va_end (ap);
623
624#if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
625 /* this -------------v--- guards NT-specific calls */
626 if (GetVersion() < 0x80000000 && IsService())
627 { HANDLE h = RegisterEventSource(0,_T("OPENSSL"));
628 const TCHAR *pmsg=buf;
629 ReportEvent(h,EVENTLOG_ERROR_TYPE,0,0,0,1,0,&pmsg,0);
630 DeregisterEventSource(h);
631 }
632 else
633#endif
634 { MSGBOXPARAMS m;
635
636 m.cbSize = sizeof(m);
637 m.hwndOwner = NULL;
638 m.lpszCaption = _T("OpenSSL: FATAL");
639 m.dwStyle = MB_OK;
640 m.hInstance = NULL;
641 m.lpszIcon = IDI_ERROR;
642 m.dwContextHelpId = 0;
643 m.lpfnMsgBoxCallback = NULL;
644 m.dwLanguageId = MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US);
645 m.lpszText = buf;
646
647 MessageBoxIndirect (&m);
648 }
649}
650#else
651void OPENSSL_showfatal (const char *fmta,...)
652{ va_list ap;
653
654 va_start (ap,fmta);
655 vfprintf (stderr,fmta,ap);
656 va_end (ap);
657}
658#endif
659
660void OpenSSLDie(const char *file,int line,const char *assertion)
661 {
662 OPENSSL_showfatal(
663 "%s(%d): OpenSSL internal error, assertion failed: %s\n",
664 file,line,assertion);
665 abort();
666 }
667
668void *OPENSSL_stderr(void) { return stderr; }
669
670#ifdef OPENSSL_FIPS
671
672void fips_w_lock(void) { CRYPTO_w_lock(CRYPTO_LOCK_FIPS); }
673void fips_w_unlock(void) { CRYPTO_w_unlock(CRYPTO_LOCK_FIPS); }
674void fips_r_lock(void) { CRYPTO_r_lock(CRYPTO_LOCK_FIPS); }
675void fips_r_unlock(void) { CRYPTO_r_unlock(CRYPTO_LOCK_FIPS); }
676
677static int fips_started = 0;
678static unsigned long fips_thread = 0;
679
680void fips_set_started(void)
681 {
682 fips_started = 1;
683 }
684
685int fips_is_started(void)
686 {
687 return fips_started;
688 }
689
690int fips_is_owning_thread(void)
691 {
692 int ret = 0;
693
694 if (fips_is_started())
695 {
696 CRYPTO_r_lock(CRYPTO_LOCK_FIPS2);
697 if (fips_thread != 0 && fips_thread == CRYPTO_thread_id())
698 ret = 1;
699 CRYPTO_r_unlock(CRYPTO_LOCK_FIPS2);
700 }
701 return ret;
702 }
703
704int fips_set_owning_thread(void)
705 {
706 int ret = 0;
707
708 if (fips_is_started())
709 {
710 CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
711 if (fips_thread == 0)
712 {
713 fips_thread = CRYPTO_thread_id();
714 ret = 1;
715 }
716 CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
717 }
718 return ret;
719 }
720
721int fips_clear_owning_thread(void)
722 {
723 int ret = 0;
724
725 if (fips_is_started())
726 {
727 CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
728 if (fips_thread == CRYPTO_thread_id())
729 {
730 fips_thread = 0;
731 ret = 1;
732 }
733 CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
734 }
735 return ret;
736 }
737
738unsigned char *fips_signature_witness(void)
739 {
740 extern unsigned char FIPS_signature[];
741 return FIPS_signature;
742 }
743#endif /* OPENSSL_FIPS */
744
diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h
deleted file mode 100644
index 6f59e08ca6..0000000000
--- a/src/lib/libcrypto/cryptlib.h
+++ /dev/null
@@ -1,104 +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#include "e_os.h"
66
67#include <openssl/crypto.h>
68#include <openssl/buffer.h>
69#include <openssl/bio.h>
70#include <openssl/err.h>
71#include <openssl/opensslconf.h>
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77#ifndef OPENSSL_SYS_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/* size of string representations */
93#define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
94#define HEX_SIZE(type) (sizeof(type)*2)
95
96void OPENSSL_showfatal(const char *,...);
97void *OPENSSL_stderr(void);
98extern int OPENSSL_NONPIC_relocated;
99
100#ifdef __cplusplus
101}
102#endif
103
104#endif
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h
deleted file mode 100644
index 22fd939e65..0000000000
--- a/src/lib/libcrypto/crypto.h
+++ /dev/null
@@ -1,518 +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#include <stdlib.h>
63
64#ifndef OPENSSL_NO_FP_API
65#include <stdio.h>
66#endif
67
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
70#include <openssl/opensslv.h>
71
72#ifdef CHARSET_EBCDIC
73#include <openssl/ebcdic.h>
74#endif
75
76/* Resolve problems on some operating systems with symbol names that clash
77 one way or another */
78#include <openssl/symhacks.h>
79
80#ifdef __cplusplus
81extern "C" {
82#endif
83
84/* Backward compatibility to SSLeay */
85/* This is more to be used to check the correct DLL is being used
86 * in the MS world. */
87#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
88#define SSLEAY_VERSION 0
89/* #define SSLEAY_OPTIONS 1 no longer supported */
90#define SSLEAY_CFLAGS 2
91#define SSLEAY_BUILT_ON 3
92#define SSLEAY_PLATFORM 4
93#define SSLEAY_DIR 5
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_EX_DATA 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_SSL_METHOD 17
116#define CRYPTO_LOCK_RAND 18
117#define CRYPTO_LOCK_RAND2 19
118#define CRYPTO_LOCK_MALLOC 20
119#define CRYPTO_LOCK_BIO 21
120#define CRYPTO_LOCK_GETHOSTBYNAME 22
121#define CRYPTO_LOCK_GETSERVBYNAME 23
122#define CRYPTO_LOCK_READDIR 24
123#define CRYPTO_LOCK_RSA_BLINDING 25
124#define CRYPTO_LOCK_DH 26
125#define CRYPTO_LOCK_MALLOC2 27
126#define CRYPTO_LOCK_DSO 28
127#define CRYPTO_LOCK_DYNLOCK 29
128#define CRYPTO_LOCK_ENGINE 30
129#define CRYPTO_LOCK_UI 31
130#define CRYPTO_LOCK_HWCRHK 32 /* This is a HACK which will disappear in 0.9.8 */
131#define CRYPTO_LOCK_FIPS 33
132#define CRYPTO_LOCK_FIPS2 34
133#define CRYPTO_NUM_LOCKS 35
134
135#define CRYPTO_LOCK 1
136#define CRYPTO_UNLOCK 2
137#define CRYPTO_READ 4
138#define CRYPTO_WRITE 8
139
140#ifndef OPENSSL_NO_LOCKING
141#ifndef CRYPTO_w_lock
142#define CRYPTO_w_lock(type) \
143 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
144#define CRYPTO_w_unlock(type) \
145 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
146#define CRYPTO_r_lock(type) \
147 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
148#define CRYPTO_r_unlock(type) \
149 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
150#define CRYPTO_add(addr,amount,type) \
151 CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
152#endif
153#else
154#define CRYPTO_w_lock(a)
155#define CRYPTO_w_unlock(a)
156#define CRYPTO_r_lock(a)
157#define CRYPTO_r_unlock(a)
158#define CRYPTO_add(a,b,c) ((*(a))+=(b))
159#endif
160
161/* Some applications as well as some parts of OpenSSL need to allocate
162 and deallocate locks in a dynamic fashion. The following typedef
163 makes this possible in a type-safe manner. */
164/* struct CRYPTO_dynlock_value has to be defined by the application. */
165typedef struct
166 {
167 int references;
168 struct CRYPTO_dynlock_value *data;
169 } CRYPTO_dynlock;
170
171
172/* The following can be used to detect memory leaks in the SSLeay library.
173 * It used, it turns on malloc checking */
174
175#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */
176#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */
177#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */
178#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */
179
180/* The following are bit values to turn on or off options connected to the
181 * malloc checking functionality */
182
183/* Adds time to the memory checking information */
184#define V_CRYPTO_MDEBUG_TIME 0x1 /* a bit */
185/* Adds thread number to the memory checking information */
186#define V_CRYPTO_MDEBUG_THREAD 0x2 /* a bit */
187
188#define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)
189
190
191/* predec of the BIO type */
192typedef struct bio_st BIO_dummy;
193
194typedef struct crypto_ex_data_st
195 {
196 STACK *sk;
197 int dummy; /* gcc is screwing up this data structure :-( */
198 } CRYPTO_EX_DATA;
199
200/* Called when a new object is created */
201typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
202 int idx, long argl, void *argp);
203/* Called when an object is free()ed */
204typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
205 int idx, long argl, void *argp);
206/* Called when we need to dup an object */
207typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
208 int idx, long argl, void *argp);
209
210/* This stuff is basically class callback functions
211 * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */
212
213typedef struct crypto_ex_data_func_st
214 {
215 long argl; /* Arbitary long */
216 void *argp; /* Arbitary void * */
217 CRYPTO_EX_new *new_func;
218 CRYPTO_EX_free *free_func;
219 CRYPTO_EX_dup *dup_func;
220 } CRYPTO_EX_DATA_FUNCS;
221
222DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
223
224/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
225 * entry.
226 */
227
228#define CRYPTO_EX_INDEX_BIO 0
229#define CRYPTO_EX_INDEX_SSL 1
230#define CRYPTO_EX_INDEX_SSL_CTX 2
231#define CRYPTO_EX_INDEX_SSL_SESSION 3
232#define CRYPTO_EX_INDEX_X509_STORE 4
233#define CRYPTO_EX_INDEX_X509_STORE_CTX 5
234#define CRYPTO_EX_INDEX_RSA 6
235#define CRYPTO_EX_INDEX_DSA 7
236#define CRYPTO_EX_INDEX_DH 8
237#define CRYPTO_EX_INDEX_ENGINE 9
238#define CRYPTO_EX_INDEX_X509 10
239#define CRYPTO_EX_INDEX_UI 11
240
241/* Dynamically assigned indexes start from this value (don't use directly, use
242 * via CRYPTO_ex_data_new_class). */
243#define CRYPTO_EX_INDEX_USER 100
244
245
246/* This is the default callbacks, but we can have others as well:
247 * this is needed in Win32 where the application malloc and the
248 * library malloc may not be the same.
249 */
250#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
251 malloc, realloc, free)
252
253#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
254# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
255# define CRYPTO_MDEBUG
256# endif
257#endif
258
259/* Set standard debugging functions (not done by default
260 * unless CRYPTO_MDEBUG is defined) */
261#define CRYPTO_malloc_debug_init() do {\
262 CRYPTO_set_mem_debug_functions(\
263 CRYPTO_dbg_malloc,\
264 CRYPTO_dbg_realloc,\
265 CRYPTO_dbg_free,\
266 CRYPTO_dbg_set_options,\
267 CRYPTO_dbg_get_options);\
268 } while(0)
269
270int CRYPTO_mem_ctrl(int mode);
271int CRYPTO_is_mem_check_on(void);
272
273/* for applications */
274#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
275#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
276
277/* for library-internal use */
278#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
279#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
280#define is_MemCheck_on() CRYPTO_is_mem_check_on()
281
282#define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__)
283#define OPENSSL_realloc(addr,num) \
284 CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__)
285#define OPENSSL_realloc_clean(addr,old_num,num) \
286 CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__)
287#define OPENSSL_remalloc(addr,num) \
288 CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
289#define OPENSSL_freeFunc CRYPTO_free
290#define OPENSSL_free(addr) CRYPTO_free(addr)
291
292#define OPENSSL_malloc_locked(num) \
293 CRYPTO_malloc_locked((int)num,__FILE__,__LINE__)
294#define OPENSSL_free_locked(addr) CRYPTO_free_locked(addr)
295
296
297const char *SSLeay_version(int type);
298unsigned long SSLeay(void);
299
300int OPENSSL_issetugid(void);
301
302/* An opaque type representing an implementation of "ex_data" support */
303typedef struct st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL;
304/* Return an opaque pointer to the current "ex_data" implementation */
305const CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void);
306/* Sets the "ex_data" implementation to be used (if it's not too late) */
307int CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i);
308/* Get a new "ex_data" class, and return the corresponding "class_index" */
309int CRYPTO_ex_data_new_class(void);
310/* Within a given class, get/register a new index */
311int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp,
312 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
313 CRYPTO_EX_free *free_func);
314/* Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a given
315 * class (invokes whatever per-class callbacks are applicable) */
316int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
317int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
318 CRYPTO_EX_DATA *from);
319void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
320/* Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular index
321 * (relative to the class type involved) */
322int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);
323void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad,int idx);
324/* This function cleans up all "ex_data" state. It mustn't be called under
325 * potential race-conditions. */
326void CRYPTO_cleanup_all_ex_data(void);
327
328int CRYPTO_get_new_lockid(char *name);
329
330int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
331void CRYPTO_lock(int mode, int type,const char *file,int line);
332void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
333 const char *file,int line));
334void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
335 int line);
336void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
337 const char *file, int line));
338int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
339 const char *file,int line);
340void CRYPTO_set_id_callback(unsigned long (*func)(void));
341unsigned long (*CRYPTO_get_id_callback(void))(void);
342unsigned long CRYPTO_thread_id(void);
343const char *CRYPTO_get_lock_name(int type);
344int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
345 int line);
346
347int CRYPTO_get_new_dynlockid(void);
348void CRYPTO_destroy_dynlockid(int i);
349struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i);
350void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*dyn_create_function)(const char *file, int line));
351void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line));
352void CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l, const char *file, int line));
353struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file,int line);
354void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file,int line);
355void (*CRYPTO_get_dynlock_destroy_callback(void))(struct CRYPTO_dynlock_value *l, const char *file,int line);
356
357/* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions --
358 * call the latter last if you need different functions */
359int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *));
360int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *));
361int CRYPTO_set_mem_ex_functions(void *(*m)(size_t,const char *,int),
362 void *(*r)(void *,size_t,const char *,int),
363 void (*f)(void *));
364int CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t,const char *,int),
365 void (*free_func)(void *));
366int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
367 void (*r)(void *,void *,int,const char *,int,int),
368 void (*f)(void *,int),
369 void (*so)(long),
370 long (*go)(void));
371void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));
372void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));
373void CRYPTO_get_mem_ex_functions(void *(**m)(size_t,const char *,int),
374 void *(**r)(void *, size_t,const char *,int),
375 void (**f)(void *));
376void CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t,const char *,int),
377 void (**f)(void *));
378void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
379 void (**r)(void *,void *,int,const char *,int,int),
380 void (**f)(void *,int),
381 void (**so)(long),
382 long (**go)(void));
383
384void *CRYPTO_malloc_locked(int num, const char *file, int line);
385void CRYPTO_free_locked(void *);
386void *CRYPTO_malloc(int num, const char *file, int line);
387void CRYPTO_free(void *);
388void *CRYPTO_realloc(void *addr,int num, const char *file, int line);
389void *CRYPTO_realloc_clean(void *addr,int old_num,int num,const char *file,
390 int line);
391void *CRYPTO_remalloc(void *addr,int num, const char *file, int line);
392
393void OPENSSL_cleanse(void *ptr, size_t len);
394
395void CRYPTO_set_mem_debug_options(long bits);
396long CRYPTO_get_mem_debug_options(void);
397
398#define CRYPTO_push_info(info) \
399 CRYPTO_push_info_(info, __FILE__, __LINE__);
400int CRYPTO_push_info_(const char *info, const char *file, int line);
401int CRYPTO_pop_info(void);
402int CRYPTO_remove_all_info(void);
403
404
405/* Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro;
406 * used as default in CRYPTO_MDEBUG compilations): */
407/* The last argument has the following significance:
408 *
409 * 0: called before the actual memory allocation has taken place
410 * 1: called after the actual memory allocation has taken place
411 */
412void CRYPTO_dbg_malloc(void *addr,int num,const char *file,int line,int before_p);
413void CRYPTO_dbg_realloc(void *addr1,void *addr2,int num,const char *file,int line,int before_p);
414void CRYPTO_dbg_free(void *addr,int before_p);
415/* Tell the debugging code about options. By default, the following values
416 * apply:
417 *
418 * 0: Clear all options.
419 * V_CRYPTO_MDEBUG_TIME (1): Set the "Show Time" option.
420 * V_CRYPTO_MDEBUG_THREAD (2): Set the "Show Thread Number" option.
421 * V_CRYPTO_MDEBUG_ALL (3): 1 + 2
422 */
423void CRYPTO_dbg_set_options(long bits);
424long CRYPTO_dbg_get_options(void);
425
426
427#ifndef OPENSSL_NO_FP_API
428void CRYPTO_mem_leaks_fp(FILE *);
429#endif
430void CRYPTO_mem_leaks(struct bio_st *bio);
431/* unsigned long order, char *file, int line, int num_bytes, char *addr */
432typedef void *CRYPTO_MEM_LEAK_CB(unsigned long, const char *, int, int, void *);
433void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb);
434
435/* die if we have to */
436void OpenSSLDie(const char *file,int line,const char *assertion);
437#define OPENSSL_assert(e) (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1))
438
439#ifdef OPENSSL_FIPS
440#define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \
441 alg " previous FIPS forbidden algorithm error ignored");
442
443#define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \
444 #alg " Algorithm forbidden in FIPS mode");
445
446#ifdef OPENSSL_FIPS_STRICT
447#define FIPS_BAD_ALGORITHM(alg) FIPS_BAD_ABORT(alg)
448#else
449#define FIPS_BAD_ALGORITHM(alg) \
450 { \
451 FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD); \
452 ERR_add_error_data(2, "Algorithm=", #alg); \
453 return 0; \
454 }
455#endif
456
457/* Low level digest API blocking macro */
458
459#define FIPS_NON_FIPS_MD_Init(alg) \
460 int alg##_Init(alg##_CTX *c) \
461 { \
462 if (FIPS_mode()) \
463 FIPS_BAD_ALGORITHM(alg) \
464 return private_##alg##_Init(c); \
465 } \
466 int private_##alg##_Init(alg##_CTX *c)
467
468/* For ciphers the API often varies from cipher to cipher and each needs to
469 * be treated as a special case. Variable key length ciphers (Blowfish, RC4,
470 * CAST) however are very similar and can use a blocking macro.
471 */
472
473#define FIPS_NON_FIPS_VCIPHER_Init(alg) \
474 void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) \
475 { \
476 if (FIPS_mode()) \
477 FIPS_BAD_ABORT(alg) \
478 private_##alg##_set_key(key, len, data); \
479 } \
480 void private_##alg##_set_key(alg##_KEY *key, int len, \
481 const unsigned char *data)
482
483#else
484
485#define FIPS_NON_FIPS_VCIPHER_Init(alg) \
486 void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data)
487
488#define FIPS_NON_FIPS_MD_Init(alg) \
489 int alg##_Init(alg##_CTX *c)
490
491#endif /* def OPENSSL_FIPS */
492
493/* BEGIN ERROR CODES */
494/* The following lines are auto generated by the script mkerr.pl. Any changes
495 * made after this point may be overwritten when the script is next run.
496 */
497void ERR_load_CRYPTO_strings(void);
498
499/* Error codes for the CRYPTO functions. */
500
501/* Function codes. */
502#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
503#define CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID 103
504#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101
505#define CRYPTO_F_CRYPTO_SET_EX_DATA 102
506#define CRYPTO_F_DEF_ADD_INDEX 104
507#define CRYPTO_F_DEF_GET_CLASS 105
508#define CRYPTO_F_INT_DUP_EX_DATA 106
509#define CRYPTO_F_INT_FREE_EX_DATA 107
510#define CRYPTO_F_INT_NEW_EX_DATA 108
511
512/* Reason codes. */
513#define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK 100
514
515#ifdef __cplusplus
516}
517#endif
518#endif
diff --git a/src/lib/libcrypto/cversion.c b/src/lib/libcrypto/cversion.c
deleted file mode 100644
index beeeb14013..0000000000
--- a/src/lib/libcrypto/cversion.c
+++ /dev/null
@@ -1,120 +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 BIO_snprintf(buf,sizeof 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 BIO_snprintf(buf,sizeof 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 BIO_snprintf(buf,sizeof buf,"platform: %s", PLATFORM);
100 return(buf);
101#else
102 return("platform: information not available");
103#endif
104 }
105 if (t == SSLEAY_DIR)
106 {
107#ifdef OPENSSLDIR
108 return "OPENSSLDIR: \"" OPENSSLDIR "\"";
109#else
110 return "OPENSSLDIR: N/A";
111#endif
112 }
113 return("not available");
114 }
115
116unsigned long SSLeay(void)
117 {
118 return(SSLEAY_VERSION_NUMBER);
119 }
120
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 1d04ed6def..0000000000
--- a/src/lib/libcrypto/des/asm/crypt586.pl
+++ /dev/null
@@ -1,208 +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 $trans="ebp";
30
31 &xor( $L, $L);
32 &xor( $R, $R);
33
34 # PIC-ification:-)
35 &picmeup("edx","DES_SPtrans");
36 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
37 #else { &lea("edx",&DWP("DES_SPtrans")); }
38 &push("edx"); # becomes &swtmp(1)
39 #
40 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
41
42 &push(&DWC(25)); # add a variable
43
44 &set_label("start");
45 for ($i=0; $i<16; $i+=2)
46 {
47 &comment("");
48 &comment("Round $i");
49 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
50
51 &comment("");
52 &comment("Round ".sprintf("%d",$i+1));
53 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
54 }
55 &mov("ebx", &swtmp(0));
56 &mov("eax", $L);
57 &dec("ebx");
58 &mov($L, $R);
59 &mov($R, "eax");
60 &mov(&swtmp(0), "ebx");
61 &jnz(&label("start"));
62
63 &comment("");
64 &comment("FP");
65 &mov("edx",&wparam(0));
66
67 &FP_new($R,$L,"eax",3);
68 &mov(&DWP(0,"edx","",0),"eax");
69 &mov(&DWP(4,"edx","",0),$L);
70
71 &add("esp",8); # remove variables
72
73 &function_end($name);
74 }
75
76sub D_ENCRYPT
77 {
78 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
79
80 &mov( $u, &wparam(2)); # 2
81 &mov( $t, $R);
82 &shr( $t, 16); # 1
83 &mov( $tmp2, &wparam(3)); # 2
84 &xor( $t, $R); # 1
85
86 &and( $u, $t); # 2
87 &and( $t, $tmp2); # 2
88
89 &mov( $tmp1, $u);
90 &shl( $tmp1, 16); # 1
91 &mov( $tmp2, $t);
92 &shl( $tmp2, 16); # 1
93 &xor( $u, $tmp1); # 2
94 &xor( $t, $tmp2); # 2
95 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
96 &xor( $u, $tmp1);
97 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
98 &xor( $u, $R);
99 &xor( $t, $R);
100 &xor( $t, $tmp2);
101
102 &and( $u, "0xfcfcfcfc" ); # 2
103 &xor( $tmp1, $tmp1); # 1
104 &and( $t, "0xcfcfcfcf" ); # 2
105 &xor( $tmp2, $tmp2);
106 &movb( &LB($tmp1), &LB($u) );
107 &movb( &LB($tmp2), &HB($u) );
108 &rotr( $t, 4 );
109 &mov( $trans, &swtmp(1));
110 &xor( $L, &DWP(" ",$trans,$tmp1,0));
111 &movb( &LB($tmp1), &LB($t) );
112 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
113 &movb( &LB($tmp2), &HB($t) );
114 &shr( $u, 16);
115 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
116 &movb( &LB($tmp1), &HB($u) );
117 &shr( $t, 16);
118 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
119 &movb( &LB($tmp2), &HB($t) );
120 &and( $u, "0xff" );
121 &and( $t, "0xff" );
122 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
123 &xor( $L, $tmp1);
124 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
125 &xor( $L, $tmp1);
126 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
127 &xor( $L, $tmp1);
128 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
129 &xor( $L, $tmp1);
130 &mov( $trans, &wparam(1));
131 }
132
133sub n2a
134 {
135 sprintf("%d",$_[0]);
136 }
137
138# now has a side affect of rotating $a by $shift
139sub R_PERM_OP
140 {
141 local($a,$b,$tt,$shift,$mask,$last)=@_;
142
143 &rotl( $a, $shift ) if ($shift != 0);
144 &mov( $tt, $a );
145 &xor( $a, $b );
146 &and( $a, $mask );
147 if ($notlast eq $b)
148 {
149 &xor( $b, $a );
150 &xor( $tt, $a );
151 }
152 else
153 {
154 &xor( $tt, $a );
155 &xor( $b, $a );
156 }
157 &comment("");
158 }
159
160sub IP_new
161 {
162 local($l,$r,$tt,$lr)=@_;
163
164 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
165 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
166 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
167 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
168 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
169
170 if ($lr != 3)
171 {
172 if (($lr-3) < 0)
173 { &rotr($tt, 3-$lr); }
174 else { &rotl($tt, $lr-3); }
175 }
176 if ($lr != 2)
177 {
178 if (($lr-2) < 0)
179 { &rotr($r, 2-$lr); }
180 else { &rotl($r, $lr-2); }
181 }
182 }
183
184sub FP_new
185 {
186 local($l,$r,$tt,$lr)=@_;
187
188 if ($lr != 2)
189 {
190 if (($lr-2) < 0)
191 { &rotl($r, 2-$lr); }
192 else { &rotr($r, $lr-2); }
193 }
194 if ($lr != 3)
195 {
196 if (($lr-3) < 0)
197 { &rotl($l, 3-$lr); }
198 else { &rotr($l, $lr-3); }
199 }
200
201 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
202 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
203 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
204 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
205 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
206 &rotr($tt , 4);
207 }
208
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 60d577cc8d..0000000000
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ /dev/null
@@ -1,255 +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_encrypt1",1);
24&DES_encrypt("DES_encrypt2",0);
25
26if (!$main'openbsd)
27 {
28 &DES_encrypt3("DES_encrypt3",1);
29 &DES_encrypt3("DES_decrypt3",0);
30 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
31 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
32 }
33
34&asm_finish();
35
36sub DES_encrypt
37 {
38 local($name,$do_ip)=@_;
39
40 &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD");
41
42 &push("esi");
43 &push("edi");
44
45 &comment("");
46 &comment("Load the 2 words");
47 $trans="ebp";
48
49 if ($do_ip)
50 {
51 &mov($R,&wparam(0));
52 &xor( "ecx", "ecx" );
53
54 &push("ebx");
55 &push("ebp");
56
57 &mov("eax",&DWP(0,$R,"",0));
58 &mov("ebx",&wparam(2)); # get encrypt flag
59 &mov($L,&DWP(4,$R,"",0));
60 &comment("");
61 &comment("IP");
62 &IP_new("eax",$L,$R,3);
63 }
64 else
65 {
66 &mov("eax",&wparam(0));
67 &xor( "ecx", "ecx" );
68
69 &push("ebx");
70 &push("ebp");
71
72 &mov($R,&DWP(0,"eax","",0));
73 &mov("ebx",&wparam(2)); # get encrypt flag
74 &rotl($R,3);
75 &mov($L,&DWP(4,"eax","",0));
76 &rotl($L,3);
77 }
78
79 # PIC-ification:-)
80 &picmeup($trans,"DES_SPtrans");
81 #if ($cpp) { &picmeup($trans,"DES_SPtrans"); }
82 #else { &lea($trans,&DWP("DES_SPtrans")); }
83
84 &mov( "ecx", &wparam(1) );
85 &cmp("ebx","0");
86 &je(&label("start_decrypt"));
87
88 for ($i=0; $i<16; $i+=2)
89 {
90 &comment("");
91 &comment("Round $i");
92 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
93
94 &comment("");
95 &comment("Round ".sprintf("%d",$i+1));
96 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
97 }
98 &jmp(&label("end"));
99
100 &set_label("start_decrypt");
101
102 for ($i=15; $i>0; $i-=2)
103 {
104 &comment("");
105 &comment("Round $i");
106 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
107 &comment("");
108 &comment("Round ".sprintf("%d",$i-1));
109 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx");
110 }
111
112 &set_label("end");
113
114 if ($do_ip)
115 {
116 &comment("");
117 &comment("FP");
118 &mov("edx",&wparam(0));
119 &FP_new($L,$R,"eax",3);
120
121 &mov(&DWP(0,"edx","",0),"eax");
122 &mov(&DWP(4,"edx","",0),$R);
123 }
124 else
125 {
126 &comment("");
127 &comment("Fixup");
128 &rotr($L,3); # r
129 &mov("eax",&wparam(0));
130 &rotr($R,3); # l
131 &mov(&DWP(0,"eax","",0),$L);
132 &mov(&DWP(4,"eax","",0),$R);
133 }
134
135 &pop("ebp");
136 &pop("ebx");
137 &pop("edi");
138 &pop("esi");
139 &ret();
140
141 &function_end_B($name);
142 }
143
144sub D_ENCRYPT
145 {
146 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
147
148 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0));
149 &xor( $tmp1, $tmp1);
150 &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0));
151 &xor( $u, $R);
152 &xor( $tmp2, $tmp2);
153 &xor( $t, $R);
154 &and( $u, "0xfcfcfcfc" );
155 &and( $t, "0xcfcfcfcf" );
156 &movb( &LB($tmp1), &LB($u) );
157 &movb( &LB($tmp2), &HB($u) );
158 &rotr( $t, 4 );
159 &xor( $L, &DWP(" ",$trans,$tmp1,0));
160 &movb( &LB($tmp1), &LB($t) );
161 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
162 &movb( &LB($tmp2), &HB($t) );
163 &shr( $u, 16);
164 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
165 &movb( &LB($tmp1), &HB($u) );
166 &shr( $t, 16);
167 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
168 &movb( &LB($tmp2), &HB($t) );
169 &and( $u, "0xff" );
170 &and( $t, "0xff" );
171 &xor( $L, &DWP("0x600",$trans,$tmp1,0));
172 &xor( $L, &DWP("0x700",$trans,$tmp2,0));
173 &mov( $tmp2, &wparam(1) );
174 &xor( $L, &DWP("0x400",$trans,$u,0));
175 &xor( $L, &DWP("0x500",$trans,$t,0));
176 }
177
178sub n2a
179 {
180 sprintf("%d",$_[0]);
181 }
182
183# now has a side affect of rotating $a by $shift
184sub R_PERM_OP
185 {
186 local($a,$b,$tt,$shift,$mask,$last)=@_;
187
188 &rotl( $a, $shift ) if ($shift != 0);
189 &mov( $tt, $a );
190 &xor( $a, $b );
191 &and( $a, $mask );
192 # This can never succeed, and besides it is difficult to see what the
193 # idea was - Ben 13 Feb 99
194 if (!$last eq $b)
195 {
196 &xor( $b, $a );
197 &xor( $tt, $a );
198 }
199 else
200 {
201 &xor( $tt, $a );
202 &xor( $b, $a );
203 }
204 &comment("");
205 }
206
207sub IP_new
208 {
209 local($l,$r,$tt,$lr)=@_;
210
211 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
212 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
213 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
214 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
215 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
216
217 if ($lr != 3)
218 {
219 if (($lr-3) < 0)
220 { &rotr($tt, 3-$lr); }
221 else { &rotl($tt, $lr-3); }
222 }
223 if ($lr != 2)
224 {
225 if (($lr-2) < 0)
226 { &rotr($r, 2-$lr); }
227 else { &rotl($r, $lr-2); }
228 }
229 }
230
231sub FP_new
232 {
233 local($l,$r,$tt,$lr)=@_;
234
235 if ($lr != 2)
236 {
237 if (($lr-2) < 0)
238 { &rotl($r, 2-$lr); }
239 else { &rotr($r, $lr-2); }
240 }
241 if ($lr != 3)
242 {
243 if (($lr-3) < 0)
244 { &rotl($l, 3-$lr); }
245 else { &rotr($l, $lr-3); }
246 }
247
248 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
249 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
250 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
251 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
252 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
253 &rotr($tt , 4);
254 }
255
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl
deleted file mode 100644
index eec00886e4..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 09a7ba56aa..0000000000
--- a/src/lib/libcrypto/des/cbc_cksm.c
+++ /dev/null
@@ -1,106 +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, DES_key_schedule *schedule,
63 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_encrypt1((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 /*
97 Transform the data in tout1 so that it will
98 match the return value that the MIT Kerberos
99 mit_des_cbc_cksum API returns.
100 */
101 tout1 = ((tout1 >> 24L) & 0x000000FF)
102 | ((tout1 >> 8L) & 0x0000FF00)
103 | ((tout1 << 8L) & 0x00FF0000)
104 | ((tout1 << 24L) & 0xFF000000);
105 return(tout1);
106 }
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 f3c6018528..0000000000
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ /dev/null
@@ -1,254 +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#include "e_os.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 DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68 long length, DES_key_schedule *ks1,
69 DES_key_schedule *ks2, DES_key_schedule *ks3,
70 DES_cblock *ivec, int *num, int enc)
71 {
72 register DES_LONG v0,v1;
73 register long l=length;
74 register int n= *num;
75 DES_LONG ti[2];
76 unsigned char *iv,c,cc;
77
78 iv=&(*ivec)[0];
79 if (enc)
80 {
81 while (l--)
82 {
83 if (n == 0)
84 {
85 c2l(iv,v0);
86 c2l(iv,v1);
87
88 ti[0]=v0;
89 ti[1]=v1;
90 DES_encrypt3(ti,ks1,ks2,ks3);
91 v0=ti[0];
92 v1=ti[1];
93
94 iv = &(*ivec)[0];
95 l2c(v0,iv);
96 l2c(v1,iv);
97 iv = &(*ivec)[0];
98 }
99 c= *(in++)^iv[n];
100 *(out++)=c;
101 iv[n]=c;
102 n=(n+1)&0x07;
103 }
104 }
105 else
106 {
107 while (l--)
108 {
109 if (n == 0)
110 {
111 c2l(iv,v0);
112 c2l(iv,v1);
113
114 ti[0]=v0;
115 ti[1]=v1;
116 DES_encrypt3(ti,ks1,ks2,ks3);
117 v0=ti[0];
118 v1=ti[1];
119
120 iv = &(*ivec)[0];
121 l2c(v0,iv);
122 l2c(v1,iv);
123 iv = &(*ivec)[0];
124 }
125 cc= *(in++);
126 c=iv[n];
127 iv[n]=cc;
128 *(out++)=c^cc;
129 n=(n+1)&0x07;
130 }
131 }
132 v0=v1=ti[0]=ti[1]=c=cc=0;
133 *num=n;
134 }
135
136#ifdef undef /* MACRO */
137void DES_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
138 DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock (*ivec),
139 int *num, int enc)
140 {
141 DES_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
142 }
143#endif
144
145/* This is compatible with the single key CFB-r for DES, even thought that's
146 * not what EVP needs.
147 */
148
149void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
150 int numbits,long length,DES_key_schedule *ks1,
151 DES_key_schedule *ks2,DES_key_schedule *ks3,
152 DES_cblock *ivec,int enc)
153 {
154 register DES_LONG d0,d1,v0,v1;
155 register long l=length;
156 register int num=numbits,n=(numbits+7)/8,i;
157 DES_LONG ti[2];
158 unsigned char *iv;
159 unsigned char ovec[16];
160
161 if (num > 64) return;
162 iv = &(*ivec)[0];
163 c2l(iv,v0);
164 c2l(iv,v1);
165 if (enc)
166 {
167 while (l >= n)
168 {
169 l-=n;
170 ti[0]=v0;
171 ti[1]=v1;
172 DES_encrypt3(ti,ks1,ks2,ks3);
173 c2ln(in,d0,d1,n);
174 in+=n;
175 d0^=ti[0];
176 d1^=ti[1];
177 l2cn(d0,d1,out,n);
178 out+=n;
179 /* 30-08-94 - eay - changed because l>>32 and
180 * l<<32 are bad under gcc :-( */
181 if (num == 32)
182 { v0=v1; v1=d0; }
183 else if (num == 64)
184 { v0=d0; v1=d1; }
185 else
186 {
187 iv=&ovec[0];
188 l2c(v0,iv);
189 l2c(v1,iv);
190 l2c(d0,iv);
191 l2c(d1,iv);
192 /* shift ovec left most of the bits... */
193 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
194 /* now the remaining bits */
195 if(num%8 != 0)
196 for(i=0 ; i < 8 ; ++i)
197 {
198 ovec[i]<<=num%8;
199 ovec[i]|=ovec[i+1]>>(8-num%8);
200 }
201 iv=&ovec[0];
202 c2l(iv,v0);
203 c2l(iv,v1);
204 }
205 }
206 }
207 else
208 {
209 while (l >= n)
210 {
211 l-=n;
212 ti[0]=v0;
213 ti[1]=v1;
214 DES_encrypt3(ti,ks1,ks2,ks3);
215 c2ln(in,d0,d1,n);
216 in+=n;
217 /* 30-08-94 - eay - changed because l>>32 and
218 * l<<32 are bad under gcc :-( */
219 if (num == 32)
220 { v0=v1; v1=d0; }
221 else if (num == 64)
222 { v0=d0; v1=d1; }
223 else
224 {
225 iv=&ovec[0];
226 l2c(v0,iv);
227 l2c(v1,iv);
228 l2c(d0,iv);
229 l2c(d1,iv);
230 /* shift ovec left most of the bits... */
231 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
232 /* now the remaining bits */
233 if(num%8 != 0)
234 for(i=0 ; i < 8 ; ++i)
235 {
236 ovec[i]<<=num%8;
237 ovec[i]|=ovec[i+1]>>(8-num%8);
238 }
239 iv=&ovec[0];
240 c2l(iv,v0);
241 c2l(iv,v1);
242 }
243 d0^=ti[0];
244 d1^=ti[1];
245 l2cn(d0,d1,out,n);
246 out+=n;
247 }
248 }
249 iv = &(*ivec)[0];
250 l2c(v0,iv);
251 l2c(v1,iv);
252 v0=v1=d0=d1=ti[0]=ti[1]=0;
253 }
254
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c
deleted file mode 100644
index 5ec8683e40..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,
68 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); ti[0]=v0;
84 c2l(iv,v1); ti[1]=v1;
85 DES_encrypt1(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_encrypt1(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 03cabb223c..0000000000
--- a/src/lib/libcrypto/des/cfb_enc.c
+++ /dev/null
@@ -1,174 +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 "e_os.h"
60#include "des_locl.h"
61
62/* The input and output are loaded in multiples of 8 bits.
63 * What this means is that if you hame numbits=12 and length=2
64 * the first 12 bits will be retrieved from the first byte and half
65 * the second. The second 12 bits will come from the 3rd and half the 4th
66 * byte.
67 */
68/* Until Aug 1 2003 this function did not correctly implement CFB-r, so it
69 * will not be compatible with any encryption prior to that date. Ben. */
70void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
71 long length, DES_key_schedule *schedule, DES_cblock *ivec,
72 int enc)
73 {
74 register DES_LONG d0,d1,v0,v1;
75 register unsigned long l=length,n=(numbits+7)/8;
76 register int num=numbits,i;
77 DES_LONG ti[2];
78 unsigned char *iv;
79 unsigned char ovec[16];
80
81 if (num > 64) return;
82 iv = &(*ivec)[0];
83 c2l(iv,v0);
84 c2l(iv,v1);
85 if (enc)
86 {
87 while (l >= n)
88 {
89 l-=n;
90 ti[0]=v0;
91 ti[1]=v1;
92 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
93 c2ln(in,d0,d1,n);
94 in+=n;
95 d0^=ti[0];
96 d1^=ti[1];
97 l2cn(d0,d1,out,n);
98 out+=n;
99 /* 30-08-94 - eay - changed because l>>32 and
100 * l<<32 are bad under gcc :-( */
101 if (num == 32)
102 { v0=v1; v1=d0; }
103 else if (num == 64)
104 { v0=d0; v1=d1; }
105 else
106 {
107 iv=&ovec[0];
108 l2c(v0,iv);
109 l2c(v1,iv);
110 l2c(d0,iv);
111 l2c(d1,iv);
112 /* shift ovec left most of the bits... */
113 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
114 /* now the remaining bits */
115 if(num%8 != 0)
116 for(i=0 ; i < 8 ; ++i)
117 {
118 ovec[i]<<=num%8;
119 ovec[i]|=ovec[i+1]>>(8-num%8);
120 }
121 iv=&ovec[0];
122 c2l(iv,v0);
123 c2l(iv,v1);
124 }
125 }
126 }
127 else
128 {
129 while (l >= n)
130 {
131 l-=n;
132 ti[0]=v0;
133 ti[1]=v1;
134 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
135 c2ln(in,d0,d1,n);
136 in+=n;
137 /* 30-08-94 - eay - changed because l>>32 and
138 * l<<32 are bad under gcc :-( */
139 if (num == 32)
140 { v0=v1; v1=d0; }
141 else if (num == 64)
142 { v0=d0; v1=d1; }
143 else
144 {
145 iv=&ovec[0];
146 l2c(v0,iv);
147 l2c(v1,iv);
148 l2c(d0,iv);
149 l2c(d1,iv);
150 /* shift ovec left most of the bits... */
151 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
152 /* now the remaining bits */
153 if(num%8 != 0)
154 for(i=0 ; i < 8 ; ++i)
155 {
156 ovec[i]<<=num%8;
157 ovec[i]|=ovec[i+1]>>(8-num%8);
158 }
159 iv=&ovec[0];
160 c2l(iv,v0);
161 c2l(iv,v1);
162 }
163 d0^=ti[0];
164 d1^=ti[1];
165 l2cn(d0,d1,out,n);
166 out+=n;
167 }
168 }
169 iv = &(*ivec)[0];
170 l2c(v0,iv);
171 l2c(v1,iv);
172 v0=v1=d0=d1=ti[0]=ti[1]=0;
173 }
174
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
deleted file mode 100644
index 81bd874edd..0000000000
--- a/src/lib/libcrypto/des/des.h
+++ /dev/null
@@ -1,246 +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 OPENSSL_NO_DES
63#error DES is disabled.
64#endif
65
66#include <openssl/opensslconf.h> /* DES_LONG */
67#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
68
69#ifdef OPENSSL_BUILD_SHLIBCRYPTO
70# undef OPENSSL_EXTERN
71# define OPENSSL_EXTERN OPENSSL_EXPORT
72#endif
73
74#define des_SPtrans DES_SPtrans
75
76#ifdef __cplusplus
77extern "C" {
78#endif
79
80typedef unsigned char DES_cblock[8];
81typedef /* const */ unsigned char const_DES_cblock[8];
82/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
83 * and const_DES_cblock * are incompatible pointer types. */
84
85typedef struct DES_ks
86 {
87 union
88 {
89 DES_cblock cblock;
90 /* make sure things are correct size on machines with
91 * 8 byte longs */
92 DES_LONG deslong[2];
93 } ks[16];
94 } DES_key_schedule;
95
96#ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
97# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT
98# define OPENSSL_ENABLE_OLD_DES_SUPPORT
99# endif
100#endif
101
102#ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT
103# include <openssl/des_old.h>
104#endif
105
106#define DES_KEY_SZ (sizeof(DES_cblock))
107#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
108
109#define DES_ENCRYPT 1
110#define DES_DECRYPT 0
111
112#define DES_CBC_MODE 0
113#define DES_PCBC_MODE 1
114
115#define DES_ecb2_encrypt(i,o,k1,k2,e) \
116 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
117
118#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
119 DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
120
121#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
122 DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
123
124#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
125 DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
126
127OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */
128#define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
129OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */
130#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)
131
132const char *DES_options(void);
133void DES_ecb3_encrypt(const unsigned char *input, unsigned char *output,
134 DES_key_schedule *ks1,DES_key_schedule *ks2,
135 DES_key_schedule *ks3, int enc);
136DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
137 long length,DES_key_schedule *schedule,
138 const_DES_cblock *ivec);
139/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
140void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,
141 long length,DES_key_schedule *schedule,DES_cblock *ivec,
142 int enc);
143void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,
144 long length,DES_key_schedule *schedule,DES_cblock *ivec,
145 int enc);
146void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,
147 long length,DES_key_schedule *schedule,DES_cblock *ivec,
148 const_DES_cblock *inw,const_DES_cblock *outw,int enc);
149void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
150 long length,DES_key_schedule *schedule,DES_cblock *ivec,
151 int enc);
152void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
153 DES_key_schedule *ks,int enc);
154
155/* This is the DES encryption function that gets called by just about
156 every other DES routine in the library. You should not use this
157 function except to implement 'modes' of DES. I say this because the
158 functions that call this routine do the conversion from 'char *' to
159 long, and this needs to be done to make sure 'non-aligned' memory
160 access do not occur. The characters are loaded 'little endian'.
161 Data is a pointer to 2 unsigned long's and ks is the
162 DES_key_schedule to use. enc, is non zero specifies encryption,
163 zero if decryption. */
164void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
165
166/* This functions is the same as DES_encrypt1() except that the DES
167 initial permutation (IP) and final permutation (FP) have been left
168 out. As for DES_encrypt1(), you should not use this function.
169 It is used by the routines in the library that implement triple DES.
170 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
171 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
172void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);
173
174void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
175 DES_key_schedule *ks2, DES_key_schedule *ks3);
176void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
177 DES_key_schedule *ks2, DES_key_schedule *ks3);
178void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
179 long length,
180 DES_key_schedule *ks1,DES_key_schedule *ks2,
181 DES_key_schedule *ks3,DES_cblock *ivec,int enc);
182void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
183 long length,
184 DES_key_schedule *ks1,DES_key_schedule *ks2,
185 DES_key_schedule *ks3,
186 DES_cblock *ivec1,DES_cblock *ivec2,
187 int enc);
188void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
189 long length,DES_key_schedule *ks1,
190 DES_key_schedule *ks2,DES_key_schedule *ks3,
191 DES_cblock *ivec,int *num,int enc);
192void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
193 int numbits,long length,DES_key_schedule *ks1,
194 DES_key_schedule *ks2,DES_key_schedule *ks3,
195 DES_cblock *ivec,int enc);
196void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
197 long length,DES_key_schedule *ks1,
198 DES_key_schedule *ks2,DES_key_schedule *ks3,
199 DES_cblock *ivec,int *num);
200
201void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
202 DES_cblock *out_white);
203
204int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
205 DES_cblock *iv);
206int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,
207 DES_cblock *iv);
208char *DES_fcrypt(const char *buf,const char *salt, char *ret);
209char *DES_crypt(const char *buf,const char *salt);
210void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
211 long length,DES_key_schedule *schedule,DES_cblock *ivec);
212void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,
213 long length,DES_key_schedule *schedule,DES_cblock *ivec,
214 int enc);
215DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],
216 long length,int out_count,DES_cblock *seed);
217int DES_random_key(DES_cblock *ret);
218void DES_set_odd_parity(DES_cblock *key);
219int DES_check_key_parity(const_DES_cblock *key);
220int DES_is_weak_key(const_DES_cblock *key);
221/* DES_set_key (= set_key = DES_key_sched = key_sched) calls
222 * DES_set_key_checked if global variable DES_check_key is set,
223 * DES_set_key_unchecked otherwise. */
224int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);
225int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);
226int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);
227void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
228void DES_string_to_key(const char *str,DES_cblock *key);
229void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
230void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
231 DES_key_schedule *schedule,DES_cblock *ivec,int *num,
232 int enc);
233void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
234 DES_key_schedule *schedule,DES_cblock *ivec,int *num);
235
236int DES_read_password(DES_cblock *key, const char *prompt, int verify);
237int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
238 int verify);
239
240#define DES_fixup_key_parity DES_set_odd_parity
241
242#ifdef __cplusplus
243}
244#endif
245
246#endif
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
deleted file mode 100644
index 6a49ec4a55..0000000000
--- a/src/lib/libcrypto/des/des_enc.c
+++ /dev/null
@@ -1,417 +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
61#ifndef OPENSSL_FIPS
62#ifndef OPENBSD_DES_ASM
63
64void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
65 {
66 register DES_LONG l,r,t,u;
67#ifdef DES_PTR
68 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
69#endif
70#ifndef DES_UNROLL
71 register int i;
72#endif
73 register DES_LONG *s;
74
75 r=data[0];
76 l=data[1];
77
78 IP(r,l);
79 /* Things have been modified so that the initial rotate is
80 * done outside the loop. This required the
81 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
82 * One perl script later and things have a 5% speed up on a sparc2.
83 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
84 * for pointing this out. */
85 /* clear the top bits on machines with 8byte longs */
86 /* shift left by 2 */
87 r=ROTATE(r,29)&0xffffffffL;
88 l=ROTATE(l,29)&0xffffffffL;
89
90 s=ks->ks->deslong;
91 /* I don't know if it is worth the effort of loop unrolling the
92 * inner loop */
93 if (enc)
94 {
95#ifdef DES_UNROLL
96 D_ENCRYPT(l,r, 0); /* 1 */
97 D_ENCRYPT(r,l, 2); /* 2 */
98 D_ENCRYPT(l,r, 4); /* 3 */
99 D_ENCRYPT(r,l, 6); /* 4 */
100 D_ENCRYPT(l,r, 8); /* 5 */
101 D_ENCRYPT(r,l,10); /* 6 */
102 D_ENCRYPT(l,r,12); /* 7 */
103 D_ENCRYPT(r,l,14); /* 8 */
104 D_ENCRYPT(l,r,16); /* 9 */
105 D_ENCRYPT(r,l,18); /* 10 */
106 D_ENCRYPT(l,r,20); /* 11 */
107 D_ENCRYPT(r,l,22); /* 12 */
108 D_ENCRYPT(l,r,24); /* 13 */
109 D_ENCRYPT(r,l,26); /* 14 */
110 D_ENCRYPT(l,r,28); /* 15 */
111 D_ENCRYPT(r,l,30); /* 16 */
112#else
113 for (i=0; i<32; i+=8)
114 {
115 D_ENCRYPT(l,r,i+0); /* 1 */
116 D_ENCRYPT(r,l,i+2); /* 2 */
117 D_ENCRYPT(l,r,i+4); /* 3 */
118 D_ENCRYPT(r,l,i+6); /* 4 */
119 }
120#endif
121 }
122 else
123 {
124#ifdef DES_UNROLL
125 D_ENCRYPT(l,r,30); /* 16 */
126 D_ENCRYPT(r,l,28); /* 15 */
127 D_ENCRYPT(l,r,26); /* 14 */
128 D_ENCRYPT(r,l,24); /* 13 */
129 D_ENCRYPT(l,r,22); /* 12 */
130 D_ENCRYPT(r,l,20); /* 11 */
131 D_ENCRYPT(l,r,18); /* 10 */
132 D_ENCRYPT(r,l,16); /* 9 */
133 D_ENCRYPT(l,r,14); /* 8 */
134 D_ENCRYPT(r,l,12); /* 7 */
135 D_ENCRYPT(l,r,10); /* 6 */
136 D_ENCRYPT(r,l, 8); /* 5 */
137 D_ENCRYPT(l,r, 6); /* 4 */
138 D_ENCRYPT(r,l, 4); /* 3 */
139 D_ENCRYPT(l,r, 2); /* 2 */
140 D_ENCRYPT(r,l, 0); /* 1 */
141#else
142 for (i=30; i>0; i-=8)
143 {
144 D_ENCRYPT(l,r,i-0); /* 16 */
145 D_ENCRYPT(r,l,i-2); /* 15 */
146 D_ENCRYPT(l,r,i-4); /* 14 */
147 D_ENCRYPT(r,l,i-6); /* 13 */
148 }
149#endif
150 }
151
152 /* rotate and clear the top bits on machines with 8byte longs */
153 l=ROTATE(l,3)&0xffffffffL;
154 r=ROTATE(r,3)&0xffffffffL;
155
156 FP(r,l);
157 data[0]=l;
158 data[1]=r;
159 l=r=t=u=0;
160 }
161
162void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
163 {
164 register DES_LONG l,r,t,u;
165#ifdef DES_PTR
166 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
167#endif
168#ifndef DES_UNROLL
169 register int i;
170#endif
171 register DES_LONG *s;
172
173 r=data[0];
174 l=data[1];
175
176 /* Things have been modified so that the initial rotate is
177 * done outside the loop. This required the
178 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
179 * One perl script later and things have a 5% speed up on a sparc2.
180 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
181 * for pointing this out. */
182 /* clear the top bits on machines with 8byte longs */
183 r=ROTATE(r,29)&0xffffffffL;
184 l=ROTATE(l,29)&0xffffffffL;
185
186 s=ks->ks->deslong;
187 /* I don't know if it is worth the effort of loop unrolling the
188 * inner loop */
189 if (enc)
190 {
191#ifdef DES_UNROLL
192 D_ENCRYPT(l,r, 0); /* 1 */
193 D_ENCRYPT(r,l, 2); /* 2 */
194 D_ENCRYPT(l,r, 4); /* 3 */
195 D_ENCRYPT(r,l, 6); /* 4 */
196 D_ENCRYPT(l,r, 8); /* 5 */
197 D_ENCRYPT(r,l,10); /* 6 */
198 D_ENCRYPT(l,r,12); /* 7 */
199 D_ENCRYPT(r,l,14); /* 8 */
200 D_ENCRYPT(l,r,16); /* 9 */
201 D_ENCRYPT(r,l,18); /* 10 */
202 D_ENCRYPT(l,r,20); /* 11 */
203 D_ENCRYPT(r,l,22); /* 12 */
204 D_ENCRYPT(l,r,24); /* 13 */
205 D_ENCRYPT(r,l,26); /* 14 */
206 D_ENCRYPT(l,r,28); /* 15 */
207 D_ENCRYPT(r,l,30); /* 16 */
208#else
209 for (i=0; i<32; i+=8)
210 {
211 D_ENCRYPT(l,r,i+0); /* 1 */
212 D_ENCRYPT(r,l,i+2); /* 2 */
213 D_ENCRYPT(l,r,i+4); /* 3 */
214 D_ENCRYPT(r,l,i+6); /* 4 */
215 }
216#endif
217 }
218 else
219 {
220#ifdef DES_UNROLL
221 D_ENCRYPT(l,r,30); /* 16 */
222 D_ENCRYPT(r,l,28); /* 15 */
223 D_ENCRYPT(l,r,26); /* 14 */
224 D_ENCRYPT(r,l,24); /* 13 */
225 D_ENCRYPT(l,r,22); /* 12 */
226 D_ENCRYPT(r,l,20); /* 11 */
227 D_ENCRYPT(l,r,18); /* 10 */
228 D_ENCRYPT(r,l,16); /* 9 */
229 D_ENCRYPT(l,r,14); /* 8 */
230 D_ENCRYPT(r,l,12); /* 7 */
231 D_ENCRYPT(l,r,10); /* 6 */
232 D_ENCRYPT(r,l, 8); /* 5 */
233 D_ENCRYPT(l,r, 6); /* 4 */
234 D_ENCRYPT(r,l, 4); /* 3 */
235 D_ENCRYPT(l,r, 2); /* 2 */
236 D_ENCRYPT(r,l, 0); /* 1 */
237#else
238 for (i=30; i>0; i-=8)
239 {
240 D_ENCRYPT(l,r,i-0); /* 16 */
241 D_ENCRYPT(r,l,i-2); /* 15 */
242 D_ENCRYPT(l,r,i-4); /* 14 */
243 D_ENCRYPT(r,l,i-6); /* 13 */
244 }
245#endif
246 }
247 /* rotate and clear the top bits on machines with 8byte longs */
248 data[0]=ROTATE(l,3)&0xffffffffL;
249 data[1]=ROTATE(r,3)&0xffffffffL;
250 l=r=t=u=0;
251 }
252#endif
253
254void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
255 DES_key_schedule *ks2, DES_key_schedule *ks3)
256 {
257 register DES_LONG l,r;
258
259 l=data[0];
260 r=data[1];
261 IP(l,r);
262 data[0]=l;
263 data[1]=r;
264 DES_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
265 DES_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
266 DES_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
267 l=data[0];
268 r=data[1];
269 FP(r,l);
270 data[0]=l;
271 data[1]=r;
272 }
273
274void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
275 DES_key_schedule *ks2, DES_key_schedule *ks3)
276 {
277 register DES_LONG l,r;
278
279 l=data[0];
280 r=data[1];
281 IP(l,r);
282 data[0]=l;
283 data[1]=r;
284 DES_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
285 DES_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
286 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
287 l=data[0];
288 r=data[1];
289 FP(r,l);
290 data[0]=l;
291 data[1]=r;
292 }
293
294#endif /* ndef OPENSSL_FIPS */
295
296#ifndef DES_DEFAULT_OPTIONS
297
298#if !defined(OPENSSL_FIPS_DES_ASM)
299
300#undef CBC_ENC_C__DONT_UPDATE_IV
301#include "ncbc_enc.c" /* DES_ncbc_encrypt */
302
303void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
304 long length, DES_key_schedule *ks1,
305 DES_key_schedule *ks2, DES_key_schedule *ks3,
306 DES_cblock *ivec, int enc)
307 {
308 register DES_LONG tin0,tin1;
309 register DES_LONG tout0,tout1,xor0,xor1;
310 register const unsigned char *in;
311 unsigned char *out;
312 register long l=length;
313 DES_LONG tin[2];
314 unsigned char *iv;
315
316 in=input;
317 out=output;
318 iv = &(*ivec)[0];
319
320 if (enc)
321 {
322 c2l(iv,tout0);
323 c2l(iv,tout1);
324 for (l-=8; l>=0; l-=8)
325 {
326 c2l(in,tin0);
327 c2l(in,tin1);
328 tin0^=tout0;
329 tin1^=tout1;
330
331 tin[0]=tin0;
332 tin[1]=tin1;
333 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
334 tout0=tin[0];
335 tout1=tin[1];
336
337 l2c(tout0,out);
338 l2c(tout1,out);
339 }
340 if (l != -8)
341 {
342 c2ln(in,tin0,tin1,l+8);
343 tin0^=tout0;
344 tin1^=tout1;
345
346 tin[0]=tin0;
347 tin[1]=tin1;
348 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
349 tout0=tin[0];
350 tout1=tin[1];
351
352 l2c(tout0,out);
353 l2c(tout1,out);
354 }
355 iv = &(*ivec)[0];
356 l2c(tout0,iv);
357 l2c(tout1,iv);
358 }
359 else
360 {
361 register DES_LONG t0,t1;
362
363 c2l(iv,xor0);
364 c2l(iv,xor1);
365 for (l-=8; l>=0; l-=8)
366 {
367 c2l(in,tin0);
368 c2l(in,tin1);
369
370 t0=tin0;
371 t1=tin1;
372
373 tin[0]=tin0;
374 tin[1]=tin1;
375 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
376 tout0=tin[0];
377 tout1=tin[1];
378
379 tout0^=xor0;
380 tout1^=xor1;
381 l2c(tout0,out);
382 l2c(tout1,out);
383 xor0=t0;
384 xor1=t1;
385 }
386 if (l != -8)
387 {
388 c2l(in,tin0);
389 c2l(in,tin1);
390
391 t0=tin0;
392 t1=tin1;
393
394 tin[0]=tin0;
395 tin[1]=tin1;
396 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
397 tout0=tin[0];
398 tout1=tin[1];
399
400 tout0^=xor0;
401 tout1^=xor1;
402 l2cn(tout0,tout1,out,l+8);
403 xor0=t0;
404 xor1=t1;
405 }
406
407 iv = &(*ivec)[0];
408 l2c(xor0,iv);
409 l2c(xor1,iv);
410 }
411 tin0=tin1=tout0=tout1=xor0=xor1=0;
412 tin[0]=tin[1]=0;
413 }
414
415#endif /* !defined(OPENSSL_FIPS_DES_ASM) */
416
417#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 8f04b18c50..0000000000
--- a/src/lib/libcrypto/des/des_locl.h
+++ /dev/null
@@ -1,428 +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#include <openssl/e_os2.h>
63
64#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
65#ifndef OPENSSL_SYS_MSDOS
66#define OPENSSL_SYS_MSDOS
67#endif
68#endif
69
70#include <stdio.h>
71#include <stdlib.h>
72
73#ifndef OPENSSL_SYS_MSDOS
74#if !defined(OPENSSL_SYS_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 OPENSSL_SYS_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(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS)
93#include <string.h>
94#endif
95
96#ifdef OPENSSL_BUILD_SHLIBCRYPTO
97# undef OPENSSL_EXTERN
98# define OPENSSL_EXTERN OPENSSL_EXPORT
99#endif
100
101#define ITERATIONS 16
102#define HALF_ITERATIONS 8
103
104/* used in des_read and des_write */
105#define MAXWRITE (1024*16)
106#define BSIZE (MAXWRITE+4)
107
108#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
109 l|=((DES_LONG)(*((c)++)))<< 8L, \
110 l|=((DES_LONG)(*((c)++)))<<16L, \
111 l|=((DES_LONG)(*((c)++)))<<24L)
112
113/* NOTE - c is not incremented as per c2l */
114#define c2ln(c,l1,l2,n) { \
115 c+=n; \
116 l1=l2=0; \
117 switch (n) { \
118 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
119 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
120 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
121 case 5: l2|=((DES_LONG)(*(--(c)))); \
122 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
123 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
124 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
125 case 1: l1|=((DES_LONG)(*(--(c)))); \
126 } \
127 }
128
129#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
130 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
131 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
132 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
133
134/* replacements for htonl and ntohl since I have no idea what to do
135 * when faced with machines with 8 byte longs. */
136#define HDRSIZE 4
137
138#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
139 l|=((DES_LONG)(*((c)++)))<<16L, \
140 l|=((DES_LONG)(*((c)++)))<< 8L, \
141 l|=((DES_LONG)(*((c)++))))
142
143#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
144 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
145 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
146 *((c)++)=(unsigned char)(((l) )&0xff))
147
148/* NOTE - c is not incremented as per l2c */
149#define l2cn(l1,l2,c,n) { \
150 c+=n; \
151 switch (n) { \
152 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
153 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
154 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
155 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
156 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
157 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
158 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
159 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
160 } \
161 }
162
163#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
164#define ROTATE(a,n) (_lrotr(a,n))
165#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
166# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
167# define ROTATE(a,n) ({ register unsigned int ret; \
168 asm ("rorl %1,%0" \
169 : "=r"(ret) \
170 : "I"(n),"0"(a) \
171 : "cc"); \
172 ret; \
173 })
174# endif
175#endif
176#ifndef ROTATE
177#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
178#endif
179
180/* Don't worry about the LOAD_DATA() stuff, that is used by
181 * fcrypt() to add it's little bit to the front */
182
183#ifdef DES_FCRYPT
184
185#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
186 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
187
188#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
189 t=R^(R>>16L); \
190 u=t&E0; t&=E1; \
191 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
192 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
193#else
194#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
195#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
196 u=R^s[S ]; \
197 t=R^s[S+1]
198#endif
199
200/* The changes to this macro may help or hinder, depending on the
201 * compiler and the architecture. gcc2 always seems to do well :-).
202 * Inspired by Dana How <how@isl.stanford.edu>
203 * DO NOT use the alternative version on machines with 8 byte longs.
204 * It does not seem to work on the Alpha, even when DES_LONG is 4
205 * bytes, probably an issue of accessing non-word aligned objects :-( */
206#ifdef DES_PTR
207
208/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
209 * is no reason to not xor all the sub items together. This potentially
210 * saves a register since things can be xored directly into L */
211
212#if defined(DES_RISC1) || defined(DES_RISC2)
213#ifdef DES_RISC1
214#define D_ENCRYPT(LL,R,S) { \
215 unsigned int u1,u2,u3; \
216 LOAD_DATA(R,S,u,t,E0,E1,u1); \
217 u2=(int)u>>8L; \
218 u1=(int)u&0xfc; \
219 u2&=0xfc; \
220 t=ROTATE(t,4); \
221 u>>=16L; \
222 LL^= *(const DES_LONG *)(des_SP +u1); \
223 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
224 u3=(int)(u>>8L); \
225 u1=(int)u&0xfc; \
226 u3&=0xfc; \
227 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
228 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
229 u2=(int)t>>8L; \
230 u1=(int)t&0xfc; \
231 u2&=0xfc; \
232 t>>=16L; \
233 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
234 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
235 u3=(int)t>>8L; \
236 u1=(int)t&0xfc; \
237 u3&=0xfc; \
238 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
239 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
240#endif
241#ifdef DES_RISC2
242#define D_ENCRYPT(LL,R,S) { \
243 unsigned int u1,u2,s1,s2; \
244 LOAD_DATA(R,S,u,t,E0,E1,u1); \
245 u2=(int)u>>8L; \
246 u1=(int)u&0xfc; \
247 u2&=0xfc; \
248 t=ROTATE(t,4); \
249 LL^= *(const DES_LONG *)(des_SP +u1); \
250 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
251 s1=(int)(u>>16L); \
252 s2=(int)(u>>24L); \
253 s1&=0xfc; \
254 s2&=0xfc; \
255 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
256 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
257 u2=(int)t>>8L; \
258 u1=(int)t&0xfc; \
259 u2&=0xfc; \
260 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
261 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
262 s1=(int)(t>>16L); \
263 s2=(int)(t>>24L); \
264 s1&=0xfc; \
265 s2&=0xfc; \
266 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
267 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
268#endif
269#else
270#define D_ENCRYPT(LL,R,S) { \
271 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
272 t=ROTATE(t,4); \
273 LL^= \
274 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
275 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
276 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
277 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
278 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
279 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
280 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
281 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
282#endif
283
284#else /* original version */
285
286#if defined(DES_RISC1) || defined(DES_RISC2)
287#ifdef DES_RISC1
288#define D_ENCRYPT(LL,R,S) {\
289 unsigned int u1,u2,u3; \
290 LOAD_DATA(R,S,u,t,E0,E1,u1); \
291 u>>=2L; \
292 t=ROTATE(t,6); \
293 u2=(int)u>>8L; \
294 u1=(int)u&0x3f; \
295 u2&=0x3f; \
296 u>>=16L; \
297 LL^=DES_SPtrans[0][u1]; \
298 LL^=DES_SPtrans[2][u2]; \
299 u3=(int)u>>8L; \
300 u1=(int)u&0x3f; \
301 u3&=0x3f; \
302 LL^=DES_SPtrans[4][u1]; \
303 LL^=DES_SPtrans[6][u3]; \
304 u2=(int)t>>8L; \
305 u1=(int)t&0x3f; \
306 u2&=0x3f; \
307 t>>=16L; \
308 LL^=DES_SPtrans[1][u1]; \
309 LL^=DES_SPtrans[3][u2]; \
310 u3=(int)t>>8L; \
311 u1=(int)t&0x3f; \
312 u3&=0x3f; \
313 LL^=DES_SPtrans[5][u1]; \
314 LL^=DES_SPtrans[7][u3]; }
315#endif
316#ifdef DES_RISC2
317#define D_ENCRYPT(LL,R,S) {\
318 unsigned int u1,u2,s1,s2; \
319 LOAD_DATA(R,S,u,t,E0,E1,u1); \
320 u>>=2L; \
321 t=ROTATE(t,6); \
322 u2=(int)u>>8L; \
323 u1=(int)u&0x3f; \
324 u2&=0x3f; \
325 LL^=DES_SPtrans[0][u1]; \
326 LL^=DES_SPtrans[2][u2]; \
327 s1=(int)u>>16L; \
328 s2=(int)u>>24L; \
329 s1&=0x3f; \
330 s2&=0x3f; \
331 LL^=DES_SPtrans[4][s1]; \
332 LL^=DES_SPtrans[6][s2]; \
333 u2=(int)t>>8L; \
334 u1=(int)t&0x3f; \
335 u2&=0x3f; \
336 LL^=DES_SPtrans[1][u1]; \
337 LL^=DES_SPtrans[3][u2]; \
338 s1=(int)t>>16; \
339 s2=(int)t>>24L; \
340 s1&=0x3f; \
341 s2&=0x3f; \
342 LL^=DES_SPtrans[5][s1]; \
343 LL^=DES_SPtrans[7][s2]; }
344#endif
345
346#else
347
348#define D_ENCRYPT(LL,R,S) {\
349 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
350 t=ROTATE(t,4); \
351 LL^=\
352 DES_SPtrans[0][(u>> 2L)&0x3f]^ \
353 DES_SPtrans[2][(u>>10L)&0x3f]^ \
354 DES_SPtrans[4][(u>>18L)&0x3f]^ \
355 DES_SPtrans[6][(u>>26L)&0x3f]^ \
356 DES_SPtrans[1][(t>> 2L)&0x3f]^ \
357 DES_SPtrans[3][(t>>10L)&0x3f]^ \
358 DES_SPtrans[5][(t>>18L)&0x3f]^ \
359 DES_SPtrans[7][(t>>26L)&0x3f]; }
360#endif
361#endif
362
363 /* IP and FP
364 * The problem is more of a geometric problem that random bit fiddling.
365 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
366 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
367 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
368 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
369
370 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
371 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
372 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
373 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
374
375 The output has been subject to swaps of the form
376 0 1 -> 3 1 but the odd and even bits have been put into
377 2 3 2 0
378 different words. The main trick is to remember that
379 t=((l>>size)^r)&(mask);
380 r^=t;
381 l^=(t<<size);
382 can be used to swap and move bits between words.
383
384 So l = 0 1 2 3 r = 16 17 18 19
385 4 5 6 7 20 21 22 23
386 8 9 10 11 24 25 26 27
387 12 13 14 15 28 29 30 31
388 becomes (for size == 2 and mask == 0x3333)
389 t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
390 6^20 7^21 -- -- 4 5 20 21 6 7 22 23
391 10^24 11^25 -- -- 8 9 24 25 10 11 24 25
392 14^28 15^29 -- -- 12 13 28 29 14 15 28 29
393
394 Thanks for hints from Richard Outerbridge - he told me IP&FP
395 could be done in 15 xor, 10 shifts and 5 ands.
396 When I finally started to think of the problem in 2D
397 I first got ~42 operations without xors. When I remembered
398 how to use xors :-) I got it to its final state.
399 */
400#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
401 (b)^=(t),\
402 (a)^=((t)<<(n)))
403
404#define IP(l,r) \
405 { \
406 register DES_LONG tt; \
407 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
408 PERM_OP(l,r,tt,16,0x0000ffffL); \
409 PERM_OP(r,l,tt, 2,0x33333333L); \
410 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
411 PERM_OP(r,l,tt, 1,0x55555555L); \
412 }
413
414#define FP(l,r) \
415 { \
416 register DES_LONG tt; \
417 PERM_OP(l,r,tt, 1,0x55555555L); \
418 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
419 PERM_OP(l,r,tt, 2,0x33333333L); \
420 PERM_OP(r,l,tt,16,0x0000ffffL); \
421 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
422 }
423
424extern const DES_LONG DES_SPtrans[8][64];
425
426void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
427 DES_LONG Eswap0, DES_LONG Eswap1);
428#endif
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
deleted file mode 100644
index fa0c9c4d4f..0000000000
--- a/src/lib/libcrypto/des/ecb3_enc.c
+++ /dev/null
@@ -1,81 +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 unsigned char *in, unsigned char *out,
62 DES_key_schedule *ks1, DES_key_schedule *ks2,
63 DES_key_schedule *ks3,
64 int enc)
65 {
66 register DES_LONG l0,l1;
67 DES_LONG ll[2];
68
69 c2l(in,l0);
70 c2l(in,l1);
71 ll[0]=l0;
72 ll[1]=l1;
73 if (enc)
74 DES_encrypt3(ll,ks1,ks2,ks3);
75 else
76 DES_decrypt3(ll,ks1,ks2,ks3);
77 l0=ll[0];
78 l1=ll[1];
79 l2c(l0,out);
80 l2c(l1,out);
81 }
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
deleted file mode 100644
index 784aa5ba23..0000000000
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ /dev/null
@@ -1,123 +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 "des_ver.h"
61#include "spr.h"
62#include <openssl/opensslv.h>
63#include <openssl/bio.h>
64
65OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT;
66OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT;
67
68const char *DES_options(void)
69 {
70 static int init=1;
71 static char buf[32];
72
73 if (init)
74 {
75 const char *ptr,*unroll,*risc,*size;
76
77#ifdef DES_PTR
78 ptr="ptr";
79#else
80 ptr="idx";
81#endif
82#if defined(DES_RISC1) || defined(DES_RISC2)
83#ifdef DES_RISC1
84 risc="risc1";
85#endif
86#ifdef DES_RISC2
87 risc="risc2";
88#endif
89#else
90 risc="cisc";
91#endif
92#ifdef DES_UNROLL
93 unroll="16";
94#else
95 unroll="4";
96#endif
97 if (sizeof(DES_LONG) != sizeof(long))
98 size="int";
99 else
100 size="long";
101 BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
102 size);
103 init=0;
104 }
105 return(buf);
106 }
107
108
109void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
110 DES_key_schedule *ks, int enc)
111 {
112 register DES_LONG l;
113 DES_LONG ll[2];
114 const unsigned char *in = &(*input)[0];
115 unsigned char *out = &(*output)[0];
116
117 c2l(in,l); ll[0]=l;
118 c2l(in,l); ll[1]=l;
119 DES_encrypt1(ll,ks,enc);
120 l=ll[0]; l2c(l,out);
121 l=ll[1]; l2c(l,out);
122 l=ll[0]=ll[1]=0;
123 }
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 fa45aa272b..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 OPENSSL_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_encrypt1(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_encrypt1(tin,ks1,1);
117 tin[0]^=m0;
118 tin[1]^=m1;
119 DES_encrypt1(tin,ks2,0);
120 tin[0]^=m0;
121 tin[1]^=m1;
122 DES_encrypt1(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_encrypt1(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_encrypt1(tin,ks1,0);
162 tin[0]^=m0;
163 tin[1]^=m1;
164 DES_encrypt1(tin,ks2,1);
165 tin[0]^=m0;
166 tin[1]^=m1;
167 DES_encrypt1(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 c70fb686b8..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_IMPLEMENT_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=OPENSSL_malloc(BSIZE);
107 if (tmpbuf == NULL) return(-1);
108 }
109 if (net == NULL)
110 {
111 net=OPENSSL_malloc(BSIZE);
112 if (net == NULL) return(-1);
113 }
114 if (unnet == NULL)
115 {
116 unnet=OPENSSL_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 af5b8c2349..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=OPENSSL_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 2758c32656..0000000000
--- a/src/lib/libcrypto/des/fcrypt.c
+++ /dev/null
@@ -1,173 +0,0 @@
1/* NOCW */
2#include <stdio.h>
3#ifdef _OSD_POSIX
4#ifndef CHARSET_EBCDIC
5#define CHARSET_EBCDIC 1
6#endif
7#endif
8#ifdef CHARSET_EBCDIC
9#include <openssl/ebcdic.h>
10#endif
11
12/* This version of crypt has been developed from my MIT compatible
13 * DES library.
14 * Eric Young (eay@cryptsoft.com)
15 */
16
17/* Modification by Jens Kupferschmidt (Cu)
18 * I have included directive PARA for shared memory computers.
19 * I have included a directive LONGCRYPT to using this routine to cipher
20 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
21 * definition is the maximum of length of password and can changed. I have
22 * defined 24.
23 */
24
25#include "des_locl.h"
26
27/* Added more values to handle illegal salt values the way normal
28 * crypt() implementations do. The patch was sent by
29 * Bjorn Gronvall <bg@sics.se>
30 */
31static unsigned const char con_salt[128]={
320xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,
330xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,
340xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,
350xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,
360xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
370xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01,
380x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
390x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
400x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
410x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
420x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
430x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
440x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
450x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
460x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
470x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,
48};
49
50static unsigned const char cov_2char[64]={
510x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
520x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
530x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
540x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
550x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
560x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
570x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
580x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
59};
60
61void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
62 DES_LONG Eswap0, DES_LONG Eswap1);
63
64char *DES_crypt(const char *buf, const char *salt)
65 {
66 static char buff[14];
67
68#ifndef CHARSET_EBCDIC
69 return(DES_fcrypt(buf,salt,buff));
70#else
71 char e_salt[2+1];
72 char e_buf[32+1]; /* replace 32 by 8 ? */
73 char *ret;
74
75 /* Copy at most 2 chars of salt */
76 if ((e_salt[0] = salt[0]) != '\0')
77 e_salt[1] = salt[1];
78
79 /* Copy at most 32 chars of password */
80 strncpy (e_buf, buf, sizeof(e_buf));
81
82 /* Make sure we have a delimiter */
83 e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0';
84
85 /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */
86 ebcdic2ascii(e_salt, e_salt, sizeof e_salt);
87
88 /* Convert the cleartext password to ASCII */
89 ebcdic2ascii(e_buf, e_buf, sizeof e_buf);
90
91 /* Encrypt it (from/to ASCII) */
92 ret = DES_fcrypt(e_buf,e_salt,buff);
93
94 /* Convert the result back to EBCDIC */
95 ascii2ebcdic(ret, ret, strlen(ret));
96
97 return ret;
98#endif
99 }
100
101
102char *DES_fcrypt(const char *buf, const char *salt, char *ret)
103 {
104 unsigned int i,j,x,y;
105 DES_LONG Eswap0,Eswap1;
106 DES_LONG out[2],ll;
107 DES_cblock key;
108 DES_key_schedule ks;
109 unsigned char bb[9];
110 unsigned char *b=bb;
111 unsigned char c,u;
112
113 /* eay 25/08/92
114 * If you call crypt("pwd","*") as often happens when you
115 * have * as the pwd field in /etc/passwd, the function
116 * returns *\0XXXXXXXXX
117 * The \0 makes the string look like * so the pwd "*" would
118 * crypt to "*". This was found when replacing the crypt in
119 * our shared libraries. People found that the disabled
120 * accounts effectively had no passwd :-(. */
121#ifndef CHARSET_EBCDIC
122 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
123 Eswap0=con_salt[x]<<2;
124 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
125 Eswap1=con_salt[x]<<6;
126#else
127 x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]);
128 Eswap0=con_salt[x]<<2;
129 x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]);
130 Eswap1=con_salt[x]<<6;
131#endif
132
133/* EAY
134r=strlen(buf);
135r=(r+7)/8;
136*/
137 for (i=0; i<8; i++)
138 {
139 c= *(buf++);
140 if (!c) break;
141 key[i]=(c<<1);
142 }
143 for (; i<8; i++)
144 key[i]=0;
145
146 DES_set_key_unchecked(&key,&ks);
147 fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1);
148
149 ll=out[0]; l2c(ll,b);
150 ll=out[1]; l2c(ll,b);
151 y=0;
152 u=0x80;
153 bb[8]=0;
154 for (i=2; i<13; i++)
155 {
156 c=0;
157 for (j=0; j<6; j++)
158 {
159 c<<=1;
160 if (bb[y] & u) c|=1;
161 u>>=1;
162 if (!u)
163 {
164 y++;
165 u=0x80;
166 }
167 }
168 ret[i]=cov_2char[c];
169 }
170 ret[13]='\0';
171 return(ret);
172 }
173
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
deleted file mode 100644
index 1390138787..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 fda23d522f..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_encrypt1((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_encrypt1((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_encrypt1((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_encrypt1((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 26bbf9a6a7..0000000000
--- a/src/lib/libcrypto/des/ofb64ede.c
+++ /dev/null
@@ -1,125 +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,
67 DES_key_schedule *k1, DES_key_schedule *k2,
68 DES_key_schedule *k3, DES_cblock *ivec,
69 int *num)
70 {
71 register DES_LONG v0,v1;
72 register int n= *num;
73 register long l=length;
74 DES_cblock d;
75 register char *dp;
76 DES_LONG ti[2];
77 unsigned char *iv;
78 int save=0;
79
80 iv = &(*ivec)[0];
81 c2l(iv,v0);
82 c2l(iv,v1);
83 ti[0]=v0;
84 ti[1]=v1;
85 dp=(char *)d;
86 l2c(v0,dp);
87 l2c(v1,dp);
88 while (l--)
89 {
90 if (n == 0)
91 {
92 /* ti[0]=v0; */
93 /* ti[1]=v1; */
94 DES_encrypt3(ti,k1,k2,k3);
95 v0=ti[0];
96 v1=ti[1];
97
98 dp=(char *)d;
99 l2c(v0,dp);
100 l2c(v1,dp);
101 save++;
102 }
103 *(out++)= *(in++)^d[n];
104 n=(n+1)&0x07;
105 }
106 if (save)
107 {
108/* v0=ti[0];
109 v1=ti[1];*/
110 iv = &(*ivec)[0];
111 l2c(v0,iv);
112 l2c(v1,iv);
113 }
114 v0=v1=ti[0]=ti[1]=0;
115 *num=n;
116 }
117
118#ifdef undef /* MACRO */
119void DES_ede2_ofb64_encrypt(register unsigned char *in,
120 register unsigned char *out, long length, DES_key_schedule k1,
121 DES_key_schedule k2, DES_cblock (*ivec), int *num)
122 {
123 DES_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num);
124 }
125#endif
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c
deleted file mode 100644
index 8ca3d49dea..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,
67 DES_key_schedule *schedule, 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_encrypt1(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 e887a3c6f4..0000000000
--- a/src/lib/libcrypto/des/ofb_enc.c
+++ /dev/null
@@ -1,135 +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,
69 DES_cblock *ivec)
70 {
71 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
72 register DES_LONG mask0,mask1;
73 register long l=length;
74 register int num=numbits;
75 DES_LONG ti[2];
76 unsigned char *iv;
77
78 if (num > 64) return;
79 if (num > 32)
80 {
81 mask0=0xffffffffL;
82 if (num >= 64)
83 mask1=mask0;
84 else
85 mask1=(1L<<(num-32))-1;
86 }
87 else
88 {
89 if (num == 32)
90 mask0=0xffffffffL;
91 else
92 mask0=(1L<<num)-1;
93 mask1=0x00000000L;
94 }
95
96 iv = &(*ivec)[0];
97 c2l(iv,v0);
98 c2l(iv,v1);
99 ti[0]=v0;
100 ti[1]=v1;
101 while (l-- > 0)
102 {
103 ti[0]=v0;
104 ti[1]=v1;
105 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
106 vv0=ti[0];
107 vv1=ti[1];
108 c2ln(in,d0,d1,n);
109 in+=n;
110 d0=(d0^vv0)&mask0;
111 d1=(d1^vv1)&mask1;
112 l2cn(d0,d1,out,n);
113 out+=n;
114
115 if (num == 32)
116 { v0=v1; v1=vv0; }
117 else if (num == 64)
118 { v0=vv0; v1=vv1; }
119 else if (num > 32) /* && num != 64 */
120 {
121 v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL;
122 v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL;
123 }
124 else /* num < 32 */
125 {
126 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
127 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
128 }
129 }
130 iv = &(*ivec)[0];
131 l2c(v0,iv);
132 l2c(v1,iv);
133 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
134 }
135
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c
deleted file mode 100644
index 17a40f9520..0000000000
--- a/src/lib/libcrypto/des/pcbc_enc.c
+++ /dev/null
@@ -1,123 +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,
63 DES_cblock *ivec, int enc)
64 {
65 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
66 DES_LONG tin[2];
67 const unsigned char *in;
68 unsigned char *out,*iv;
69
70 in=input;
71 out=output;
72 iv = &(*ivec)[0];
73
74 if (enc)
75 {
76 c2l(iv,xor0);
77 c2l(iv,xor1);
78 for (; length>0; length-=8)
79 {
80 if (length >= 8)
81 {
82 c2l(in,sin0);
83 c2l(in,sin1);
84 }
85 else
86 c2ln(in,sin0,sin1,length);
87 tin[0]=sin0^xor0;
88 tin[1]=sin1^xor1;
89 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
90 tout0=tin[0];
91 tout1=tin[1];
92 xor0=sin0^tout0;
93 xor1=sin1^tout1;
94 l2c(tout0,out);
95 l2c(tout1,out);
96 }
97 }
98 else
99 {
100 c2l(iv,xor0); c2l(iv,xor1);
101 for (; length>0; length-=8)
102 {
103 c2l(in,sin0);
104 c2l(in,sin1);
105 tin[0]=sin0;
106 tin[1]=sin1;
107 DES_encrypt1((DES_LONG *)tin,schedule,DES_DECRYPT);
108 tout0=tin[0]^xor0;
109 tout1=tin[1]^xor1;
110 if (length >= 8)
111 {
112 l2c(tout0,out);
113 l2c(tout1,out);
114 }
115 else
116 l2cn(tout0,tout1,out,length);
117 xor0=tout0^sin0;
118 xor1=tout1^sin1;
119 }
120 }
121 tin[0]=tin[1]=0;
122 sin0=sin1=xor0=xor1=tout0=tout1=0;
123 }
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c
deleted file mode 100644
index dac201227e..0000000000
--- a/src/lib/libcrypto/des/qud_cksm.c
+++ /dev/null
@@ -1,139 +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 struct lp_st { int a:32; int b:32; } *lp;
85#else
86 DES_LONG *lp;
87#endif
88
89 if (out_count < 1) out_count=1;
90#ifdef _CRAY
91 lp = (struct lp_st *) &(output[0])[0];
92#else
93 lp = (DES_LONG *) &(output[0])[0];
94#endif
95
96 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
97 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
98
99 for (i=0; ((i<4)&&(i<out_count)); i++)
100 {
101 cp=input;
102 l=length;
103 while (l > 0)
104 {
105 if (l > 1)
106 {
107 t0= (DES_LONG)(*(cp++));
108 t0|=(DES_LONG)Q_B1(*(cp++));
109 l--;
110 }
111 else
112 t0= (DES_LONG)(*(cp++));
113 l--;
114 /* add */
115 t0+=z0;
116 t0&=0xffffffffL;
117 t1=z1;
118 /* square, well sort of square */
119 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL))
120 &0xffffffffL)%0x7fffffffL;
121 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL;
122 }
123 if (lp != NULL)
124 {
125 /* The MIT library assumes that the checksum is
126 * composed of 2*out_count 32 bit ints */
127#ifdef _CRAY
128 (*lp).a = z0;
129 (*lp).b = z1;
130 lp++;
131#else
132 *lp++ = z0;
133 *lp++ = z1;
134#endif
135 }
136 }
137 return(z0);
138 }
139
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
deleted file mode 100644
index 2398165568..0000000000
--- a/src/lib/libcrypto/des/rand_key.c
+++ /dev/null
@@ -1,68 +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
59int DES_random_key(DES_cblock *ret)
60 {
61 do
62 {
63 if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1)
64 return (0);
65 } while (DES_is_weak_key(ret));
66 DES_set_odd_parity(ret);
67 return (1);
68 }
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
deleted file mode 100644
index 8881d46a7a..0000000000
--- a/src/lib/libcrypto/des/set_key.c
+++ /dev/null
@@ -1,411 +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
68#ifndef OPENSSL_FIPS
69
70OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */
71
72static const unsigned char odd_parity[256]={
73 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
74 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
75 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
76 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
77 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
78 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
79 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
80112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
81128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
82145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
83161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
84176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
85193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
86208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
87224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
88241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
89
90void DES_set_odd_parity(DES_cblock *key)
91 {
92 int i;
93
94 for (i=0; i<DES_KEY_SZ; i++)
95 (*key)[i]=odd_parity[(*key)[i]];
96 }
97
98int DES_check_key_parity(const_DES_cblock *key)
99 {
100 int i;
101
102 for (i=0; i<DES_KEY_SZ; i++)
103 {
104 if ((*key)[i] != odd_parity[(*key)[i]])
105 return(0);
106 }
107 return(1);
108 }
109
110/* Weak and semi week keys as take from
111 * %A D.W. Davies
112 * %A W.L. Price
113 * %T Security for Computer Networks
114 * %I John Wiley & Sons
115 * %D 1984
116 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
117 * (and actual cblock values).
118 */
119#define NUM_WEAK_KEY 16
120static DES_cblock weak_keys[NUM_WEAK_KEY]={
121 /* weak keys */
122 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
123 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
124 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
125 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
126 /* semi-weak keys */
127 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
128 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
129 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
130 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
131 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
132 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
133 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
134 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
135 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
136 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
137 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
138 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
139
140int DES_is_weak_key(const_DES_cblock *key)
141 {
142 int i;
143
144 for (i=0; i<NUM_WEAK_KEY; i++)
145 /* Added == 0 to comparison, I obviously don't run
146 * this section very often :-(, thanks to
147 * engineering@MorningStar.Com for the fix
148 * eay 93/06/29
149 * Another problem, I was comparing only the first 4
150 * bytes, 97/03/18 */
151 if (memcmp(weak_keys[i],key,sizeof(DES_cblock)) == 0) return(1);
152 return(0);
153 }
154
155/* NOW DEFINED IN des_local.h
156 * See ecb_encrypt.c for a pseudo description of these macros.
157 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
158 * (b)^=(t),\
159 * (a)=((a)^((t)<<(n))))
160 */
161
162#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
163 (a)=(a)^(t)^(t>>(16-(n))))
164
165static const DES_LONG des_skb[8][64]={
166 {
167 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
168 0x00000000L,0x00000010L,0x20000000L,0x20000010L,
169 0x00010000L,0x00010010L,0x20010000L,0x20010010L,
170 0x00000800L,0x00000810L,0x20000800L,0x20000810L,
171 0x00010800L,0x00010810L,0x20010800L,0x20010810L,
172 0x00000020L,0x00000030L,0x20000020L,0x20000030L,
173 0x00010020L,0x00010030L,0x20010020L,0x20010030L,
174 0x00000820L,0x00000830L,0x20000820L,0x20000830L,
175 0x00010820L,0x00010830L,0x20010820L,0x20010830L,
176 0x00080000L,0x00080010L,0x20080000L,0x20080010L,
177 0x00090000L,0x00090010L,0x20090000L,0x20090010L,
178 0x00080800L,0x00080810L,0x20080800L,0x20080810L,
179 0x00090800L,0x00090810L,0x20090800L,0x20090810L,
180 0x00080020L,0x00080030L,0x20080020L,0x20080030L,
181 0x00090020L,0x00090030L,0x20090020L,0x20090030L,
182 0x00080820L,0x00080830L,0x20080820L,0x20080830L,
183 0x00090820L,0x00090830L,0x20090820L,0x20090830L,
184 },{
185 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
186 0x00000000L,0x02000000L,0x00002000L,0x02002000L,
187 0x00200000L,0x02200000L,0x00202000L,0x02202000L,
188 0x00000004L,0x02000004L,0x00002004L,0x02002004L,
189 0x00200004L,0x02200004L,0x00202004L,0x02202004L,
190 0x00000400L,0x02000400L,0x00002400L,0x02002400L,
191 0x00200400L,0x02200400L,0x00202400L,0x02202400L,
192 0x00000404L,0x02000404L,0x00002404L,0x02002404L,
193 0x00200404L,0x02200404L,0x00202404L,0x02202404L,
194 0x10000000L,0x12000000L,0x10002000L,0x12002000L,
195 0x10200000L,0x12200000L,0x10202000L,0x12202000L,
196 0x10000004L,0x12000004L,0x10002004L,0x12002004L,
197 0x10200004L,0x12200004L,0x10202004L,0x12202004L,
198 0x10000400L,0x12000400L,0x10002400L,0x12002400L,
199 0x10200400L,0x12200400L,0x10202400L,0x12202400L,
200 0x10000404L,0x12000404L,0x10002404L,0x12002404L,
201 0x10200404L,0x12200404L,0x10202404L,0x12202404L,
202 },{
203 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
204 0x00000000L,0x00000001L,0x00040000L,0x00040001L,
205 0x01000000L,0x01000001L,0x01040000L,0x01040001L,
206 0x00000002L,0x00000003L,0x00040002L,0x00040003L,
207 0x01000002L,0x01000003L,0x01040002L,0x01040003L,
208 0x00000200L,0x00000201L,0x00040200L,0x00040201L,
209 0x01000200L,0x01000201L,0x01040200L,0x01040201L,
210 0x00000202L,0x00000203L,0x00040202L,0x00040203L,
211 0x01000202L,0x01000203L,0x01040202L,0x01040203L,
212 0x08000000L,0x08000001L,0x08040000L,0x08040001L,
213 0x09000000L,0x09000001L,0x09040000L,0x09040001L,
214 0x08000002L,0x08000003L,0x08040002L,0x08040003L,
215 0x09000002L,0x09000003L,0x09040002L,0x09040003L,
216 0x08000200L,0x08000201L,0x08040200L,0x08040201L,
217 0x09000200L,0x09000201L,0x09040200L,0x09040201L,
218 0x08000202L,0x08000203L,0x08040202L,0x08040203L,
219 0x09000202L,0x09000203L,0x09040202L,0x09040203L,
220 },{
221 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
222 0x00000000L,0x00100000L,0x00000100L,0x00100100L,
223 0x00000008L,0x00100008L,0x00000108L,0x00100108L,
224 0x00001000L,0x00101000L,0x00001100L,0x00101100L,
225 0x00001008L,0x00101008L,0x00001108L,0x00101108L,
226 0x04000000L,0x04100000L,0x04000100L,0x04100100L,
227 0x04000008L,0x04100008L,0x04000108L,0x04100108L,
228 0x04001000L,0x04101000L,0x04001100L,0x04101100L,
229 0x04001008L,0x04101008L,0x04001108L,0x04101108L,
230 0x00020000L,0x00120000L,0x00020100L,0x00120100L,
231 0x00020008L,0x00120008L,0x00020108L,0x00120108L,
232 0x00021000L,0x00121000L,0x00021100L,0x00121100L,
233 0x00021008L,0x00121008L,0x00021108L,0x00121108L,
234 0x04020000L,0x04120000L,0x04020100L,0x04120100L,
235 0x04020008L,0x04120008L,0x04020108L,0x04120108L,
236 0x04021000L,0x04121000L,0x04021100L,0x04121100L,
237 0x04021008L,0x04121008L,0x04021108L,0x04121108L,
238 },{
239 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
240 0x00000000L,0x10000000L,0x00010000L,0x10010000L,
241 0x00000004L,0x10000004L,0x00010004L,0x10010004L,
242 0x20000000L,0x30000000L,0x20010000L,0x30010000L,
243 0x20000004L,0x30000004L,0x20010004L,0x30010004L,
244 0x00100000L,0x10100000L,0x00110000L,0x10110000L,
245 0x00100004L,0x10100004L,0x00110004L,0x10110004L,
246 0x20100000L,0x30100000L,0x20110000L,0x30110000L,
247 0x20100004L,0x30100004L,0x20110004L,0x30110004L,
248 0x00001000L,0x10001000L,0x00011000L,0x10011000L,
249 0x00001004L,0x10001004L,0x00011004L,0x10011004L,
250 0x20001000L,0x30001000L,0x20011000L,0x30011000L,
251 0x20001004L,0x30001004L,0x20011004L,0x30011004L,
252 0x00101000L,0x10101000L,0x00111000L,0x10111000L,
253 0x00101004L,0x10101004L,0x00111004L,0x10111004L,
254 0x20101000L,0x30101000L,0x20111000L,0x30111000L,
255 0x20101004L,0x30101004L,0x20111004L,0x30111004L,
256 },{
257 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
258 0x00000000L,0x08000000L,0x00000008L,0x08000008L,
259 0x00000400L,0x08000400L,0x00000408L,0x08000408L,
260 0x00020000L,0x08020000L,0x00020008L,0x08020008L,
261 0x00020400L,0x08020400L,0x00020408L,0x08020408L,
262 0x00000001L,0x08000001L,0x00000009L,0x08000009L,
263 0x00000401L,0x08000401L,0x00000409L,0x08000409L,
264 0x00020001L,0x08020001L,0x00020009L,0x08020009L,
265 0x00020401L,0x08020401L,0x00020409L,0x08020409L,
266 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
267 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
268 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
269 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
270 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
271 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
272 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
273 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
274 },{
275 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
276 0x00000000L,0x00000100L,0x00080000L,0x00080100L,
277 0x01000000L,0x01000100L,0x01080000L,0x01080100L,
278 0x00000010L,0x00000110L,0x00080010L,0x00080110L,
279 0x01000010L,0x01000110L,0x01080010L,0x01080110L,
280 0x00200000L,0x00200100L,0x00280000L,0x00280100L,
281 0x01200000L,0x01200100L,0x01280000L,0x01280100L,
282 0x00200010L,0x00200110L,0x00280010L,0x00280110L,
283 0x01200010L,0x01200110L,0x01280010L,0x01280110L,
284 0x00000200L,0x00000300L,0x00080200L,0x00080300L,
285 0x01000200L,0x01000300L,0x01080200L,0x01080300L,
286 0x00000210L,0x00000310L,0x00080210L,0x00080310L,
287 0x01000210L,0x01000310L,0x01080210L,0x01080310L,
288 0x00200200L,0x00200300L,0x00280200L,0x00280300L,
289 0x01200200L,0x01200300L,0x01280200L,0x01280300L,
290 0x00200210L,0x00200310L,0x00280210L,0x00280310L,
291 0x01200210L,0x01200310L,0x01280210L,0x01280310L,
292 },{
293 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
294 0x00000000L,0x04000000L,0x00040000L,0x04040000L,
295 0x00000002L,0x04000002L,0x00040002L,0x04040002L,
296 0x00002000L,0x04002000L,0x00042000L,0x04042000L,
297 0x00002002L,0x04002002L,0x00042002L,0x04042002L,
298 0x00000020L,0x04000020L,0x00040020L,0x04040020L,
299 0x00000022L,0x04000022L,0x00040022L,0x04040022L,
300 0x00002020L,0x04002020L,0x00042020L,0x04042020L,
301 0x00002022L,0x04002022L,0x00042022L,0x04042022L,
302 0x00000800L,0x04000800L,0x00040800L,0x04040800L,
303 0x00000802L,0x04000802L,0x00040802L,0x04040802L,
304 0x00002800L,0x04002800L,0x00042800L,0x04042800L,
305 0x00002802L,0x04002802L,0x00042802L,0x04042802L,
306 0x00000820L,0x04000820L,0x00040820L,0x04040820L,
307 0x00000822L,0x04000822L,0x00040822L,0x04040822L,
308 0x00002820L,0x04002820L,0x00042820L,0x04042820L,
309 0x00002822L,0x04002822L,0x00042822L,0x04042822L,
310 }};
311
312int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
313 {
314 if (DES_check_key)
315 {
316 return DES_set_key_checked(key, schedule);
317 }
318 else
319 {
320 DES_set_key_unchecked(key, schedule);
321 return 0;
322 }
323 }
324
325/* return 0 if key parity is odd (correct),
326 * return -1 if key parity error,
327 * return -2 if illegal weak key.
328 */
329int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
330 {
331 if (!DES_check_key_parity(key))
332 return(-1);
333 if (DES_is_weak_key(key))
334 return(-2);
335 DES_set_key_unchecked(key, schedule);
336 return 0;
337 }
338
339void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
340 {
341 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
342 register DES_LONG c,d,t,s,t2;
343 register const unsigned char *in;
344 register DES_LONG *k;
345 register int i;
346
347#ifdef OPENBSD_DEV_CRYPTO
348 memcpy(schedule->key,key,sizeof schedule->key);
349 schedule->session=NULL;
350#endif
351 k = &schedule->ks->deslong[0];
352 in = &(*key)[0];
353
354 c2l(in,c);
355 c2l(in,d);
356
357 /* do PC1 in 47 simple operations :-)
358 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
359 * for the inspiration. :-) */
360 PERM_OP (d,c,t,4,0x0f0f0f0fL);
361 HPERM_OP(c,t,-2,0xcccc0000L);
362 HPERM_OP(d,t,-2,0xcccc0000L);
363 PERM_OP (d,c,t,1,0x55555555L);
364 PERM_OP (c,d,t,8,0x00ff00ffL);
365 PERM_OP (d,c,t,1,0x55555555L);
366 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
367 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
368 c&=0x0fffffffL;
369
370 for (i=0; i<ITERATIONS; i++)
371 {
372 if (shifts2[i])
373 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
374 else
375 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
376 c&=0x0fffffffL;
377 d&=0x0fffffffL;
378 /* could be a few less shifts but I am to lazy at this
379 * point in time to investigate */
380 s= des_skb[0][ (c )&0x3f ]|
381 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
382 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
383 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
384 ((c>>22L)&0x38)];
385 t= des_skb[4][ (d )&0x3f ]|
386 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
387 des_skb[6][ (d>>15L)&0x3f ]|
388 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
389
390 /* table contained 0213 4657 */
391 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
392 *(k++)=ROTATE(t2,30)&0xffffffffL;
393
394 t2=((s>>16L)|(t&0xffff0000L));
395 *(k++)=ROTATE(t2,26)&0xffffffffL;
396 }
397 }
398
399int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
400 {
401 return(DES_set_key(key,schedule));
402 }
403/*
404#undef des_fixup_key_parity
405void des_fixup_key_parity(des_cblock *key)
406 {
407 des_set_odd_parity(key);
408 }
409*/
410
411#endif /* ndef OPENSSL_FIPS */
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
deleted file mode 100644
index b91936a5a5..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 0373db469c..0000000000
--- a/src/lib/libcrypto/des/str2key.c
+++ /dev/null
@@ -1,173 +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#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
90 if(DES_is_weak_key(key))
91 (*key)[7] ^= 0xF0;
92 DES_set_key(key,&ks);
93#else
94 DES_set_key_unchecked(key,&ks);
95#endif
96 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key);
97 OPENSSL_cleanse(&ks,sizeof(ks));
98 DES_set_odd_parity(key);
99 }
100
101void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
102 {
103 DES_key_schedule ks;
104 int i,length;
105 register unsigned char j;
106
107 memset(key1,0,8);
108 memset(key2,0,8);
109 length=strlen(str);
110#ifdef OLD_STR_TO_KEY
111 if (length <= 8)
112 {
113 for (i=0; i<length; i++)
114 {
115 (*key2)[i]=(*key1)[i]=(str[i]<<1);
116 }
117 }
118 else
119 {
120 for (i=0; i<length; i++)
121 {
122 if ((i/8)&1)
123 (*key2)[i%8]^=(str[i]<<1);
124 else
125 (*key1)[i%8]^=(str[i]<<1);
126 }
127 }
128#else /* MIT COMPATIBLE */
129 for (i=0; i<length; i++)
130 {
131 j=str[i];
132 if ((i%32) < 16)
133 {
134 if ((i%16) < 8)
135 (*key1)[i%8]^=(j<<1);
136 else
137 (*key2)[i%8]^=(j<<1);
138 }
139 else
140 {
141 j=((j<<4)&0xf0)|((j>>4)&0x0f);
142 j=((j<<2)&0xcc)|((j>>2)&0x33);
143 j=((j<<1)&0xaa)|((j>>1)&0x55);
144 if ((i%16) < 8)
145 (*key1)[7-(i%8)]^=j;
146 else
147 (*key2)[7-(i%8)]^=j;
148 }
149 }
150 if (length <= 8) memcpy(key2,key1,8);
151#endif
152 DES_set_odd_parity(key1);
153 DES_set_odd_parity(key2);
154#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
155 if(DES_is_weak_key(key1))
156 (*key1)[7] ^= 0xF0;
157 DES_set_key(key1,&ks);
158#else
159 DES_set_key_unchecked(key1,&ks);
160#endif
161 DES_cbc_cksum((const unsigned char*)str,key1,length,&ks,key1);
162#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
163 if(DES_is_weak_key(key2))
164 (*key2)[7] ^= 0xF0;
165 DES_set_key(key2,&ks);
166#else
167 DES_set_key_unchecked(key2,&ks);
168#endif
169 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2);
170 OPENSSL_cleanse(&ks,sizeof(ks));
171 DES_set_odd_parity(key1);
172 DES_set_odd_parity(key2);
173 }
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
deleted file mode 100644
index 47246eb466..0000000000
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ /dev/null
@@ -1,195 +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,
112 DES_cblock *ivec, const_DES_cblock *inw,
113 const_DES_cblock *outw, int enc)
114 {
115 register DES_LONG tin0,tin1;
116 register DES_LONG tout0,tout1,xor0,xor1;
117 register DES_LONG inW0,inW1,outW0,outW1;
118 register const unsigned char *in2;
119 register long l=length;
120 DES_LONG tin[2];
121 unsigned char *iv;
122
123 in2 = &(*inw)[0];
124 c2l(in2,inW0);
125 c2l(in2,inW1);
126 in2 = &(*outw)[0];
127 c2l(in2,outW0);
128 c2l(in2,outW1);
129
130 iv = &(*ivec)[0];
131
132 if (enc)
133 {
134 c2l(iv,tout0);
135 c2l(iv,tout1);
136 for (l-=8; l>=0; l-=8)
137 {
138 c2l(in,tin0);
139 c2l(in,tin1);
140 tin0^=tout0^inW0; tin[0]=tin0;
141 tin1^=tout1^inW1; tin[1]=tin1;
142 DES_encrypt1(tin,schedule,DES_ENCRYPT);
143 tout0=tin[0]^outW0; l2c(tout0,out);
144 tout1=tin[1]^outW1; l2c(tout1,out);
145 }
146 if (l != -8)
147 {
148 c2ln(in,tin0,tin1,l+8);
149 tin0^=tout0^inW0; tin[0]=tin0;
150 tin1^=tout1^inW1; tin[1]=tin1;
151 DES_encrypt1(tin,schedule,DES_ENCRYPT);
152 tout0=tin[0]^outW0; l2c(tout0,out);
153 tout1=tin[1]^outW1; l2c(tout1,out);
154 }
155 iv = &(*ivec)[0];
156 l2c(tout0,iv);
157 l2c(tout1,iv);
158 }
159 else
160 {
161 c2l(iv,xor0);
162 c2l(iv,xor1);
163 for (l-=8; l>0; l-=8)
164 {
165 c2l(in,tin0); tin[0]=tin0^outW0;
166 c2l(in,tin1); tin[1]=tin1^outW1;
167 DES_encrypt1(tin,schedule,DES_DECRYPT);
168 tout0=tin[0]^xor0^inW0;
169 tout1=tin[1]^xor1^inW1;
170 l2c(tout0,out);
171 l2c(tout1,out);
172 xor0=tin0;
173 xor1=tin1;
174 }
175 if (l != -8)
176 {
177 c2l(in,tin0); tin[0]=tin0^outW0;
178 c2l(in,tin1); tin[1]=tin1^outW1;
179 DES_encrypt1(tin,schedule,DES_DECRYPT);
180 tout0=tin[0]^xor0^inW0;
181 tout1=tin[1]^xor1^inW1;
182 l2cn(tout0,tout1,out,l+8);
183 xor0=tin0;
184 xor1=tin1;
185 }
186
187 iv = &(*ivec)[0];
188 l2c(xor0,iv);
189 l2c(xor1,iv);
190 }
191 tin0=tin1=tout0=tout1=xor0=xor1=0;
192 inW0=inW1=outW0=outW1=0;
193 tin[0]=tin[1]=0;
194 }
195
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h
deleted file mode 100644
index 582b34329f..0000000000
--- a/src/lib/libcrypto/dh/dh.h
+++ /dev/null
@@ -1,223 +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 OPENSSL_NO_DH
63#error DH is disabled.
64#endif
65
66#ifndef OPENSSL_NO_BIO
67#include <openssl/bio.h>
68#endif
69#include <openssl/bn.h>
70#include <openssl/crypto.h>
71#include <openssl/ossl_typ.h>
72
73#define OPENSSL_DH_MAX_MODULUS_BITS 10000
74
75#define DH_FLAG_CACHE_MONT_P 0x01
76#define DH_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DH
77 * implementation now uses constant time
78 * modular exponentiation for secret exponents
79 * by default. This flag causes the
80 * faster variable sliding window method to
81 * be used for all exponents.
82 */
83
84#ifdef __cplusplus
85extern "C" {
86#endif
87
88typedef struct dh_st DH;
89
90typedef struct dh_method {
91 const char *name;
92 /* Methods here */
93 int (*generate_key)(DH *dh);
94 int (*compute_key)(unsigned char *key,const BIGNUM *pub_key,DH *dh);
95 int (*bn_mod_exp)(const DH *dh, BIGNUM *r, const BIGNUM *a,
96 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
97 BN_MONT_CTX *m_ctx); /* Can be null */
98
99 int (*init)(DH *dh);
100 int (*finish)(DH *dh);
101 int flags;
102 char *app_data;
103} DH_METHOD;
104
105struct dh_st
106 {
107 /* This first argument is used to pick up errors when
108 * a DH is passed instead of a EVP_PKEY */
109 int pad;
110 int version;
111 BIGNUM *p;
112 BIGNUM *g;
113 int length; /* optional */
114 BIGNUM *pub_key; /* g^x */
115 BIGNUM *priv_key; /* x */
116
117 int flags;
118 char *method_mont_p;
119 /* Place holders if we want to do X9.42 DH */
120 BIGNUM *q;
121 BIGNUM *j;
122 unsigned char *seed;
123 int seedlen;
124 BIGNUM *counter;
125
126 int references;
127 CRYPTO_EX_DATA ex_data;
128 const DH_METHOD *meth;
129 ENGINE *engine;
130 };
131
132#define DH_GENERATOR_2 2
133/* #define DH_GENERATOR_3 3 */
134#define DH_GENERATOR_5 5
135
136/* DH_check error codes */
137#define DH_CHECK_P_NOT_PRIME 0x01
138#define DH_CHECK_P_NOT_SAFE_PRIME 0x02
139#define DH_UNABLE_TO_CHECK_GENERATOR 0x04
140#define DH_NOT_SUITABLE_GENERATOR 0x08
141
142/* DH_check_pub_key error codes */
143#define DH_CHECK_PUBKEY_TOO_SMALL 0x01
144#define DH_CHECK_PUBKEY_TOO_LARGE 0x02
145
146/* primes p where (p-1)/2 is prime too are called "safe"; we define
147 this for backward compatibility: */
148#define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME
149
150#define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \
151 (char *(*)())d2i_DHparams,(char *)(x))
152#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \
153 (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x))
154#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \
155 (unsigned char *)(x))
156#define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \
157 (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x))
158#ifdef __cplusplus
159#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \
160 (unsigned char *)(x))
161#else
162#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \
163 (unsigned char *)(x))
164#endif
165
166const DH_METHOD *DH_OpenSSL(void);
167
168void DH_set_default_method(const DH_METHOD *meth);
169const DH_METHOD *DH_get_default_method(void);
170int DH_set_method(DH *dh, const DH_METHOD *meth);
171DH *DH_new_method(ENGINE *engine);
172
173DH * DH_new(void);
174void DH_free(DH *dh);
175int DH_up_ref(DH *dh);
176int DH_size(const DH *dh);
177int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
178 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
179int DH_set_ex_data(DH *d, int idx, void *arg);
180void *DH_get_ex_data(DH *d, int idx);
181DH * DH_generate_parameters(int prime_len,int generator,
182 void (*callback)(int,int,void *),void *cb_arg);
183int DH_check(const DH *dh,int *codes);
184int DH_check_pub_key(const DH *dh,const BIGNUM *pub_key, int *codes);
185int DH_generate_key(DH *dh);
186int DH_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh);
187DH * d2i_DHparams(DH **a,const unsigned char **pp, long length);
188int i2d_DHparams(const DH *a,unsigned char **pp);
189#ifndef OPENSSL_NO_FP_API
190int DHparams_print_fp(FILE *fp, const DH *x);
191#endif
192#ifndef OPENSSL_NO_BIO
193int DHparams_print(BIO *bp, const DH *x);
194#else
195int DHparams_print(char *bp, const DH *x);
196#endif
197
198/* BEGIN ERROR CODES */
199/* The following lines are auto generated by the script mkerr.pl. Any changes
200 * made after this point may be overwritten when the script is next run.
201 */
202void ERR_load_DH_strings(void);
203
204/* Error codes for the DH functions. */
205
206/* Function codes. */
207#define DH_F_DHPARAMS_PRINT 100
208#define DH_F_DHPARAMS_PRINT_FP 101
209#define DH_F_DH_COMPUTE_KEY 102
210#define DH_F_DH_GENERATE_KEY 103
211#define DH_F_DH_GENERATE_PARAMETERS 104
212#define DH_F_DH_NEW_METHOD 105
213
214/* Reason codes. */
215#define DH_R_BAD_GENERATOR 101
216#define DH_R_NO_PRIVATE_VALUE 100
217#define DH_R_INVALID_PUBKEY 102
218#define DH_R_MODULUS_TOO_LARGE 103
219
220#ifdef __cplusplus
221}
222#endif
223#endif
diff --git a/src/lib/libcrypto/dh/dh_asn1.c b/src/lib/libcrypto/dh/dh_asn1.c
deleted file mode 100644
index 769b5b68c5..0000000000
--- a/src/lib/libcrypto/dh/dh_asn1.c
+++ /dev/null
@@ -1,87 +0,0 @@
1/* dh_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/dh.h>
63#include <openssl/objects.h>
64#include <openssl/asn1t.h>
65
66/* Override the default free and new methods */
67static int dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
68{
69 if(operation == ASN1_OP_NEW_PRE) {
70 *pval = (ASN1_VALUE *)DH_new();
71 if(*pval) return 2;
72 return 0;
73 } else if(operation == ASN1_OP_FREE_PRE) {
74 DH_free((DH *)*pval);
75 *pval = NULL;
76 return 2;
77 }
78 return 1;
79}
80
81ASN1_SEQUENCE_cb(DHparams, dh_cb) = {
82 ASN1_SIMPLE(DH, p, BIGNUM),
83 ASN1_SIMPLE(DH, g, BIGNUM),
84 ASN1_OPT(DH, length, ZLONG),
85} ASN1_SEQUENCE_END_cb(DH, DHparams)
86
87IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DH, DHparams, DHparams)
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c
deleted file mode 100644
index 17debff62d..0000000000
--- a/src/lib/libcrypto/dh/dh_check.c
+++ /dev/null
@@ -1,146 +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
73#ifndef OPENSSL_FIPS
74
75int DH_check(const DH *dh, int *ret)
76 {
77 int ok=0;
78 BN_CTX *ctx=NULL;
79 BN_ULONG l;
80 BIGNUM *q=NULL;
81
82 *ret=0;
83 ctx=BN_CTX_new();
84 if (ctx == NULL) goto err;
85 q=BN_new();
86 if (q == NULL) goto err;
87
88 if (BN_is_word(dh->g,DH_GENERATOR_2))
89 {
90 l=BN_mod_word(dh->p,24);
91 if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;
92 }
93#if 0
94 else if (BN_is_word(dh->g,DH_GENERATOR_3))
95 {
96 l=BN_mod_word(dh->p,12);
97 if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;
98 }
99#endif
100 else if (BN_is_word(dh->g,DH_GENERATOR_5))
101 {
102 l=BN_mod_word(dh->p,10);
103 if ((l != 3) && (l != 7))
104 *ret|=DH_NOT_SUITABLE_GENERATOR;
105 }
106 else
107 *ret|=DH_UNABLE_TO_CHECK_GENERATOR;
108
109 if (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL))
110 *ret|=DH_CHECK_P_NOT_PRIME;
111 else
112 {
113 if (!BN_rshift1(q,dh->p)) goto err;
114 if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))
115 *ret|=DH_CHECK_P_NOT_SAFE_PRIME;
116 }
117 ok=1;
118err:
119 if (ctx != NULL) BN_CTX_free(ctx);
120 if (q != NULL) BN_free(q);
121 return(ok);
122 }
123
124int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
125 {
126 int ok=0;
127 BIGNUM *q=NULL;
128
129 *ret=0;
130 q=BN_new();
131 if (q == NULL) goto err;
132 BN_set_word(q,1);
133 if (BN_cmp(pub_key,q) <= 0)
134 *ret|=DH_CHECK_PUBKEY_TOO_SMALL;
135 BN_copy(q,dh->p);
136 BN_sub_word(q,1);
137 if (BN_cmp(pub_key,q) >= 0)
138 *ret|=DH_CHECK_PUBKEY_TOO_LARGE;
139
140 ok = 1;
141err:
142 if (q != NULL) BN_free(q);
143 return(ok);
144 }
145
146#endif
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c
deleted file mode 100644
index 611067ef4a..0000000000
--- a/src/lib/libcrypto/dh/dh_err.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/* crypto/dh/dh_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DH,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DH,0,reason)
70
71static ERR_STRING_DATA DH_str_functs[]=
72 {
73{ERR_FUNC(DH_F_DHPARAMS_PRINT), "DHparams_print"},
74{ERR_FUNC(DH_F_DHPARAMS_PRINT_FP), "DHparams_print_fp"},
75{ERR_FUNC(DH_F_DH_COMPUTE_KEY), "DH_compute_key"},
76{ERR_FUNC(DH_F_DH_GENERATE_KEY), "DH_generate_key"},
77{ERR_FUNC(DH_F_DH_GENERATE_PARAMETERS), "DH_generate_parameters"},
78{ERR_FUNC(DH_F_DH_NEW_METHOD), "DH_new_method"},
79{0,NULL}
80 };
81
82static ERR_STRING_DATA DH_str_reasons[]=
83 {
84{ERR_REASON(DH_R_BAD_GENERATOR) ,"bad generator"},
85{ERR_REASON(DH_R_NO_PRIVATE_VALUE) ,"no private value"},
86{ERR_REASON(DH_R_INVALID_PUBKEY) ,"invalid public key"},
87{ERR_REASON(DH_R_MODULUS_TOO_LARGE) ,"modulus too large"},
88{0,NULL}
89 };
90
91#endif
92
93void ERR_load_DH_strings(void)
94 {
95 static int init=1;
96
97 if (init)
98 {
99 init=0;
100#ifndef OPENSSL_NO_ERR
101 ERR_load_strings(0,DH_str_functs);
102 ERR_load_strings(0,DH_str_reasons);
103#endif
104
105 }
106 }
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c
deleted file mode 100644
index 23777f5a16..0000000000
--- a/src/lib/libcrypto/dh/dh_gen.c
+++ /dev/null
@@ -1,175 +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/* Actually there is no reason to insist that 'generator' be a generator.
86 * It's just as OK (and in some sense better) to use a generator of the
87 * order-q subgroup.
88 */
89
90#ifndef OPENSSL_FIPS
91
92DH *DH_generate_parameters(int prime_len, int generator,
93 void (*callback)(int,int,void *), void *cb_arg)
94 {
95 BIGNUM *p=NULL,*t1,*t2;
96 DH *ret=NULL;
97 int g,ok= -1;
98 BN_CTX *ctx=NULL;
99
100 ret=DH_new();
101 if (ret == NULL) goto err;
102 ctx=BN_CTX_new();
103 if (ctx == NULL) goto err;
104 BN_CTX_start(ctx);
105 t1 = BN_CTX_get(ctx);
106 t2 = BN_CTX_get(ctx);
107 if (t1 == NULL || t2 == NULL) goto err;
108
109 if (generator <= 1)
110 {
111 DHerr(DH_F_DH_GENERATE_PARAMETERS, DH_R_BAD_GENERATOR);
112 goto err;
113 }
114 if (generator == DH_GENERATOR_2)
115 {
116 if (!BN_set_word(t1,24)) goto err;
117 if (!BN_set_word(t2,11)) goto err;
118 g=2;
119 }
120#if 0 /* does not work for safe primes */
121 else if (generator == DH_GENERATOR_3)
122 {
123 if (!BN_set_word(t1,12)) goto err;
124 if (!BN_set_word(t2,5)) goto err;
125 g=3;
126 }
127#endif
128 else if (generator == DH_GENERATOR_5)
129 {
130 if (!BN_set_word(t1,10)) goto err;
131 if (!BN_set_word(t2,3)) goto err;
132 /* BN_set_word(t3,7); just have to miss
133 * out on these ones :-( */
134 g=5;
135 }
136 else
137 {
138 /* in the general case, don't worry if 'generator' is a
139 * generator or not: since we are using safe primes,
140 * it will generate either an order-q or an order-2q group,
141 * which both is OK */
142 if (!BN_set_word(t1,2)) goto err;
143 if (!BN_set_word(t2,1)) goto err;
144 g=generator;
145 }
146
147 p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg);
148 if (p == NULL) goto err;
149 if (callback != NULL) callback(3,0,cb_arg);
150 ret->p=p;
151 ret->g=BN_new();
152 if (ret->g == NULL) goto err;
153 if (!BN_set_word(ret->g,g)) goto err;
154 ok=1;
155err:
156 if (ok == -1)
157 {
158 DHerr(DH_F_DH_GENERATE_PARAMETERS,ERR_R_BN_LIB);
159 ok=0;
160 }
161
162 if (ctx != NULL)
163 {
164 BN_CTX_end(ctx);
165 BN_CTX_free(ctx);
166 }
167 if (!ok && (ret != NULL))
168 {
169 DH_free(ret);
170 ret=NULL;
171 }
172 return(ret);
173 }
174
175#endif
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
deleted file mode 100644
index 74de589204..0000000000
--- a/src/lib/libcrypto/dh/dh_key.c
+++ /dev/null
@@ -1,266 +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
65#ifndef OPENSSL_FIPS
66
67static int generate_key(DH *dh);
68static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
69static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
70 const BIGNUM *a, const BIGNUM *p,
71 const BIGNUM *m, BN_CTX *ctx,
72 BN_MONT_CTX *m_ctx);
73static int dh_init(DH *dh);
74static int dh_finish(DH *dh);
75
76int DH_generate_key(DH *dh)
77 {
78 return dh->meth->generate_key(dh);
79 }
80
81int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
82 {
83 return dh->meth->compute_key(key, pub_key, dh);
84 }
85
86static DH_METHOD dh_ossl = {
87"OpenSSL DH Method",
88generate_key,
89compute_key,
90dh_bn_mod_exp,
91dh_init,
92dh_finish,
930,
94NULL
95};
96
97const DH_METHOD *DH_OpenSSL(void)
98{
99 return &dh_ossl;
100}
101
102static int generate_key(DH *dh)
103 {
104 int ok=0;
105 int generate_new_key=0;
106 unsigned l;
107 BN_CTX *ctx;
108 BN_MONT_CTX *mont=NULL;
109 BIGNUM *pub_key=NULL,*priv_key=NULL;
110
111 ctx = BN_CTX_new();
112 if (ctx == NULL) goto err;
113
114 if (dh->priv_key == NULL)
115 {
116 priv_key=BN_new();
117 if (priv_key == NULL) goto err;
118 generate_new_key=1;
119 }
120 else
121 priv_key=dh->priv_key;
122
123 if (dh->pub_key == NULL)
124 {
125 pub_key=BN_new();
126 if (pub_key == NULL) goto err;
127 }
128 else
129 pub_key=dh->pub_key;
130
131
132 if (dh->flags & DH_FLAG_CACHE_MONT_P)
133 {
134 mont = BN_MONT_CTX_set_locked(
135 (BN_MONT_CTX **)&dh->method_mont_p,
136 CRYPTO_LOCK_DH, dh->p, ctx);
137 if (!mont)
138 goto err;
139 }
140
141 if (generate_new_key)
142 {
143 l = dh->length ? dh->length : BN_num_bits(dh->p)-1; /* secret exponent length */
144 if (!BN_rand(priv_key, l, 0, 0)) goto err;
145 }
146
147 {
148 BIGNUM local_prk;
149 BIGNUM *prk;
150
151 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
152 {
153 BN_init(&local_prk);
154 prk = &local_prk;
155 BN_with_flags(prk, priv_key, BN_FLG_EXP_CONSTTIME);
156 }
157 else
158 prk = priv_key;
159
160 if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) goto err;
161 }
162
163 dh->pub_key=pub_key;
164 dh->priv_key=priv_key;
165 ok=1;
166err:
167 if (ok != 1)
168 DHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB);
169
170 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
171 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
172 BN_CTX_free(ctx);
173 return(ok);
174 }
175
176static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
177 {
178 BN_CTX *ctx;
179 BN_MONT_CTX *mont=NULL;
180 BIGNUM *tmp;
181 int ret= -1;
182 int check_result;
183
184 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS)
185 {
186 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE);
187 return -1;
188 }
189
190 ctx = BN_CTX_new();
191 if (ctx == NULL) goto err;
192 BN_CTX_start(ctx);
193 tmp = BN_CTX_get(ctx);
194
195 if (dh->priv_key == NULL)
196 {
197 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
198 goto err;
199 }
200
201 if (dh->flags & DH_FLAG_CACHE_MONT_P)
202 {
203 mont = BN_MONT_CTX_set_locked(
204 (BN_MONT_CTX **)&dh->method_mont_p,
205 CRYPTO_LOCK_DH, dh->p, ctx);
206 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
207 {
208 /* XXX */
209 BN_set_flags(dh->priv_key, BN_FLG_EXP_CONSTTIME);
210 }
211 if (!mont)
212 goto err;
213 }
214 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result)
215 {
216 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_INVALID_PUBKEY);
217 goto err;
218 }
219 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont))
220 {
221 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
222 goto err;
223 }
224
225 ret=BN_bn2bin(tmp,key);
226err:
227 if (ctx != NULL)
228 {
229 BN_CTX_end(ctx);
230 BN_CTX_free(ctx);
231 }
232 return(ret);
233 }
234
235static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
236 const BIGNUM *a, const BIGNUM *p,
237 const BIGNUM *m, BN_CTX *ctx,
238 BN_MONT_CTX *m_ctx)
239 {
240 /* If a is only one word long and constant time is false, use the faster
241 * exponenentiation function.
242 */
243 if (a->top == 1 && ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) != 0))
244 {
245 BN_ULONG A = a->d[0];
246 return BN_mod_exp_mont_word(r,A,p,m,ctx,m_ctx);
247 }
248 else
249 return BN_mod_exp_mont(r,a,p,m,ctx,m_ctx);
250 }
251
252
253static int dh_init(DH *dh)
254 {
255 dh->flags |= DH_FLAG_CACHE_MONT_P;
256 return(1);
257 }
258
259static int dh_finish(DH *dh)
260 {
261 if(dh->method_mont_p)
262 BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
263 return(1);
264 }
265
266#endif
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
deleted file mode 100644
index 09965ee2ea..0000000000
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ /dev/null
@@ -1,247 +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#ifndef OPENSSL_NO_ENGINE
64#include <openssl/engine.h>
65#endif
66
67const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
68
69static const DH_METHOD *default_DH_method = NULL;
70
71void DH_set_default_method(const DH_METHOD *meth)
72 {
73 default_DH_method = meth;
74 }
75
76const DH_METHOD *DH_get_default_method(void)
77 {
78 if(!default_DH_method)
79 default_DH_method = DH_OpenSSL();
80 return default_DH_method;
81 }
82
83int DH_set_method(DH *dh, const DH_METHOD *meth)
84 {
85 /* NB: The caller is specifically setting a method, so it's not up to us
86 * to deal with which ENGINE it comes from. */
87 const DH_METHOD *mtmp;
88 mtmp = dh->meth;
89 if (mtmp->finish) mtmp->finish(dh);
90#ifndef OPENSSL_NO_ENGINE
91 if (dh->engine)
92 {
93 ENGINE_finish(dh->engine);
94 dh->engine = NULL;
95 }
96#endif
97 dh->meth = meth;
98 if (meth->init) meth->init(dh);
99 return 1;
100 }
101
102DH *DH_new(void)
103 {
104 return DH_new_method(NULL);
105 }
106
107DH *DH_new_method(ENGINE *engine)
108 {
109 DH *ret;
110
111 ret=(DH *)OPENSSL_malloc(sizeof(DH));
112 if (ret == NULL)
113 {
114 DHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);
115 return(NULL);
116 }
117
118 ret->meth = DH_get_default_method();
119#ifndef OPENSSL_NO_ENGINE
120 if (engine)
121 {
122 if (!ENGINE_init(engine))
123 {
124 DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);
125 OPENSSL_free(ret);
126 return NULL;
127 }
128 ret->engine = engine;
129 }
130 else
131 ret->engine = ENGINE_get_default_DH();
132 if(ret->engine)
133 {
134 ret->meth = ENGINE_get_DH(ret->engine);
135 if(!ret->meth)
136 {
137 DHerr(DH_F_DH_NEW_METHOD,ERR_R_ENGINE_LIB);
138 ENGINE_finish(ret->engine);
139 OPENSSL_free(ret);
140 return NULL;
141 }
142 }
143#endif
144
145 ret->pad=0;
146 ret->version=0;
147 ret->p=NULL;
148 ret->g=NULL;
149 ret->length=0;
150 ret->pub_key=NULL;
151 ret->priv_key=NULL;
152 ret->q=NULL;
153 ret->j=NULL;
154 ret->seed = NULL;
155 ret->seedlen = 0;
156 ret->counter = NULL;
157 ret->method_mont_p=NULL;
158 ret->references = 1;
159 ret->flags=ret->meth->flags;
160 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
161 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
162 {
163#ifndef OPENSSL_NO_ENGINE
164 if (ret->engine)
165 ENGINE_finish(ret->engine);
166#endif
167 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
168 OPENSSL_free(ret);
169 ret=NULL;
170 }
171 return(ret);
172 }
173
174void DH_free(DH *r)
175 {
176 int i;
177 if(r == NULL) return;
178 i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
179#ifdef REF_PRINT
180 REF_PRINT("DH",r);
181#endif
182 if (i > 0) return;
183#ifdef REF_CHECK
184 if (i < 0)
185 {
186 fprintf(stderr,"DH_free, bad reference count\n");
187 abort();
188 }
189#endif
190
191 if (r->meth->finish)
192 r->meth->finish(r);
193#ifndef OPENSSL_NO_ENGINE
194 if (r->engine)
195 ENGINE_finish(r->engine);
196#endif
197
198 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data);
199
200 if (r->p != NULL) BN_clear_free(r->p);
201 if (r->g != NULL) BN_clear_free(r->g);
202 if (r->q != NULL) BN_clear_free(r->q);
203 if (r->j != NULL) BN_clear_free(r->j);
204 if (r->seed) OPENSSL_free(r->seed);
205 if (r->counter != NULL) BN_clear_free(r->counter);
206 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
207 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
208 OPENSSL_free(r);
209 }
210
211int DH_up_ref(DH *r)
212 {
213 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DH);
214#ifdef REF_PRINT
215 REF_PRINT("DH",r);
216#endif
217#ifdef REF_CHECK
218 if (i < 2)
219 {
220 fprintf(stderr, "DH_up, bad reference count\n");
221 abort();
222 }
223#endif
224 return ((i > 1) ? 1 : 0);
225 }
226
227int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
228 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
229 {
230 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DH, argl, argp,
231 new_func, dup_func, free_func);
232 }
233
234int DH_set_ex_data(DH *d, int idx, void *arg)
235 {
236 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
237 }
238
239void *DH_get_ex_data(DH *d, int idx)
240 {
241 return(CRYPTO_get_ex_data(&d->ex_data,idx));
242 }
243
244int DH_size(const DH *dh)
245 {
246 return(BN_num_bytes(dh->p));
247 }
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 9081e9ea7c..0000000000
--- a/src/lib/libcrypto/doc/DH_generate_parameters.pod
+++ /dev/null
@@ -1,73 +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)>,
63L<DH_free(3)|DH_free(3)>
64
65=head1 HISTORY
66
67DH_check() is available in all versions of SSLeay and OpenSSL.
68The B<cb_arg> argument to DH_generate_parameters() was added in SSLeay 0.9.0.
69
70In versions before OpenSSL 0.9.5, DH_CHECK_P_NOT_STRONG_PRIME is used
71instead of DH_CHECK_P_NOT_SAFE_PRIME.
72
73=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 fa5eab2650..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(3)|RSA_get_ex_new_index(3)>, 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 73261fc467..0000000000
--- a/src/lib/libcrypto/doc/DH_set_method.pod
+++ /dev/null
@@ -1,129 +0,0 @@
1=pod
2
3=head1 NAME
4
5DH_set_default_method, DH_get_default_method,
6DH_set_method, DH_new_method, DH_OpenSSL - select DH method
7
8=head1 SYNOPSIS
9
10 #include <openssl/dh.h>
11 #include <openssl/engine.h>
12
13 void DH_set_default_method(const DH_METHOD *meth);
14
15 const DH_METHOD *DH_get_default_method(void);
16
17 int DH_set_method(DH *dh, const DH_METHOD *meth);
18
19 DH *DH_new_method(ENGINE *engine);
20
21 const DH_METHOD *DH_OpenSSL(void);
22
23=head1 DESCRIPTION
24
25A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman
26operations. By modifying the method, alternative implementations
27such as hardware accelerators may be used. IMPORTANT: See the NOTES section for
28important information about how these DH API functions are affected by the use
29of B<ENGINE> API calls.
30
31Initially, the default DH_METHOD is the OpenSSL internal implementation, as
32returned by DH_OpenSSL().
33
34DH_set_default_method() makes B<meth> the default method for all DH
35structures created later. B<NB>: This is true only whilst no ENGINE has been set
36as a default for DH, so this function is no longer recommended.
37
38DH_get_default_method() returns a pointer to the current default DH_METHOD.
39However, the meaningfulness of this result is dependant on whether the ENGINE
40API is being used, so this function is no longer recommended.
41
42DH_set_method() selects B<meth> to perform all operations using the key B<dh>.
43This will replace the DH_METHOD used by the DH key and if the previous method
44was supplied by an ENGINE, the handle to that ENGINE will be released during the
45change. It is possible to have DH keys that only work with certain DH_METHOD
46implementations (eg. from an ENGINE module that supports embedded
47hardware-protected keys), and in such cases attempting to change the DH_METHOD
48for the key can have unexpected results.
49
50DH_new_method() allocates and initializes a DH structure so that B<engine> will
51be used for the DH operations. If B<engine> is NULL, the default ENGINE for DH
52operations is used, and if no default ENGINE is set, the DH_METHOD controlled by
53DH_set_default_method() is used.
54
55=head1 THE DH_METHOD STRUCTURE
56
57 typedef struct dh_meth_st
58 {
59 /* name of the implementation */
60 const char *name;
61
62 /* generate private and public DH values for key agreement */
63 int (*generate_key)(DH *dh);
64
65 /* compute shared secret */
66 int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
67
68 /* compute r = a ^ p mod m (May be NULL for some implementations) */
69 int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
70 const BIGNUM *m, BN_CTX *ctx,
71 BN_MONT_CTX *m_ctx);
72
73 /* called at DH_new */
74 int (*init)(DH *dh);
75
76 /* called at DH_free */
77 int (*finish)(DH *dh);
78
79 int flags;
80
81 char *app_data; /* ?? */
82
83 } DH_METHOD;
84
85=head1 RETURN VALUES
86
87DH_OpenSSL() and DH_get_default_method() return pointers to the respective
88B<DH_METHOD>s.
89
90DH_set_default_method() returns no value.
91
92DH_set_method() returns non-zero if the provided B<meth> was successfully set as
93the method for B<dh> (including unloading the ENGINE handle if the previous
94method was supplied by an ENGINE).
95
96DH_new_method() returns NULL and sets an error code that can be obtained by
97L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
98returns a pointer to the newly allocated structure.
99
100=head1 NOTES
101
102As of version 0.9.7, DH_METHOD implementations are grouped together with other
103algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
104default ENGINE is specified for DH functionality using an ENGINE API function,
105that will override any DH defaults set using the DH API (ie.
106DH_set_default_method()). For this reason, the ENGINE API is the recommended way
107to control default implementations for use in DH and other cryptographic
108algorithms.
109
110=head1 SEE ALSO
111
112L<dh(3)|dh(3)>, L<DH_new(3)|DH_new(3)>
113
114=head1 HISTORY
115
116DH_set_default_method(), DH_get_default_method(), DH_set_method(),
117DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4.
118
119DH_set_default_openssl_method() and DH_get_default_openssl_method() replaced
120DH_set_default_method() and DH_get_default_method() respectively, and
121DH_set_method() and DH_new_method() were altered to use B<ENGINE>s rather than
122B<DH_METHOD>s during development of the engine version of OpenSSL 0.9.6. For
1230.9.7, the handling of defaults in the ENGINE API was restructured so that this
124change was reversed, and behaviour of the other functions resembled more closely
125the previous behaviour. The behaviour of defaults in the ENGINE API now
126transparently overrides the behaviour of defaults in the DH API without
127requiring changing these function prototypes.
128
129=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 3ac6140038..0000000000
--- a/src/lib/libcrypto/doc/DSA_SIG_new.pod
+++ /dev/null
@@ -1,40 +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)>,
34L<DSA_do_sign(3)|DSA_do_sign(3)>
35
36=head1 HISTORY
37
38DSA_SIG_new() and DSA_SIG_free() were added in OpenSSL 0.9.3.
39
40=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 7f6f0d1115..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(const 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 af83ccfaa1..0000000000
--- a/src/lib/libcrypto/doc/DSA_generate_key.pod
+++ /dev/null
@@ -1,34 +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)>,
28L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>
29
30=head1 HISTORY
31
32DSA_generate_key() is available since SSLeay 0.8.
33
34=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 48e9b82a09..0000000000
--- a/src/lib/libcrypto/doc/DSA_new.pod
+++ /dev/null
@@ -1,42 +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. It is equivalent to
18calling DSA_new_method(NULL).
19
20DSA_free() frees the B<DSA> structure and its components. The values are
21erased before the memory is returned to the system.
22
23=head1 RETURN VALUES
24
25If the allocation fails, DSA_new() returns B<NULL> and sets an error
26code that can be obtained by
27L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
28to the newly allocated structure.
29
30DSA_free() returns no value.
31
32=head1 SEE ALSO
33
34L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
35L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
36L<DSA_generate_key(3)|DSA_generate_key(3)>
37
38=head1 HISTORY
39
40DSA_new() and DSA_free() are available in all versions of SSLeay and OpenSSL.
41
42=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 bc3cfb1f0a..0000000000
--- a/src/lib/libcrypto/doc/DSA_set_method.pod
+++ /dev/null
@@ -1,143 +0,0 @@
1=pod
2
3=head1 NAME
4
5DSA_set_default_method, DSA_get_default_method,
6DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method
7
8=head1 SYNOPSIS
9
10 #include <openssl/dsa.h>
11 #include <openssl/engine.h>
12
13 void DSA_set_default_method(const DSA_METHOD *meth);
14
15 const DSA_METHOD *DSA_get_default_method(void);
16
17 int DSA_set_method(DSA *dsa, const DSA_METHOD *meth);
18
19 DSA *DSA_new_method(ENGINE *engine);
20
21 DSA_METHOD *DSA_OpenSSL(void);
22
23=head1 DESCRIPTION
24
25A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA
26operations. By modifying the method, alternative implementations
27such as hardware accelerators may be used. IMPORTANT: See the NOTES section for
28important information about how these DSA API functions are affected by the use
29of B<ENGINE> API calls.
30
31Initially, the default DSA_METHOD is the OpenSSL internal implementation,
32as returned by DSA_OpenSSL().
33
34DSA_set_default_method() makes B<meth> the default method for all DSA
35structures created later. B<NB>: This is true only whilst no ENGINE has
36been set as a default for DSA, so this function is no longer recommended.
37
38DSA_get_default_method() returns a pointer to the current default
39DSA_METHOD. However, the meaningfulness of this result is dependant on
40whether the ENGINE API is being used, so this function is no longer
41recommended.
42
43DSA_set_method() selects B<meth> to perform all operations using the key
44B<rsa>. This will replace the DSA_METHOD used by the DSA key and if the
45previous method was supplied by an ENGINE, the handle to that ENGINE will
46be released during the change. It is possible to have DSA keys that only
47work with certain DSA_METHOD implementations (eg. from an ENGINE module
48that supports embedded hardware-protected keys), and in such cases
49attempting to change the DSA_METHOD for the key can have unexpected
50results.
51
52DSA_new_method() allocates and initializes a DSA structure so that B<engine>
53will be used for the DSA operations. If B<engine> is NULL, the default engine
54for DSA operations is used, and if no default ENGINE is set, the DSA_METHOD
55controlled by DSA_set_default_method() is used.
56
57=head1 THE DSA_METHOD STRUCTURE
58
59struct
60 {
61 /* name of the implementation */
62 const char *name;
63
64 /* sign */
65 DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen,
66 DSA *dsa);
67
68 /* pre-compute k^-1 and r */
69 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
70 BIGNUM **rp);
71
72 /* verify */
73 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
74 DSA_SIG *sig, DSA *dsa);
75
76 /* compute rr = a1^p1 * a2^p2 mod m (May be NULL for some
77 implementations) */
78 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
79 BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
80 BN_CTX *ctx, BN_MONT_CTX *in_mont);
81
82 /* compute r = a ^ p mod m (May be NULL for some implementations) */
83 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a,
84 const BIGNUM *p, const BIGNUM *m,
85 BN_CTX *ctx, BN_MONT_CTX *m_ctx);
86
87 /* called at DSA_new */
88 int (*init)(DSA *DSA);
89
90 /* called at DSA_free */
91 int (*finish)(DSA *DSA);
92
93 int flags;
94
95 char *app_data; /* ?? */
96
97 } DSA_METHOD;
98
99=head1 RETURN VALUES
100
101DSA_OpenSSL() and DSA_get_default_method() return pointers to the respective
102B<DSA_METHOD>s.
103
104DSA_set_default_method() returns no value.
105
106DSA_set_method() returns non-zero if the provided B<meth> was successfully set as
107the method for B<dsa> (including unloading the ENGINE handle if the previous
108method was supplied by an ENGINE).
109
110DSA_new_method() returns NULL and sets an error code that can be
111obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation
112fails. Otherwise it returns a pointer to the newly allocated structure.
113
114=head1 NOTES
115
116As of version 0.9.7, DSA_METHOD implementations are grouped together with other
117algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
118default ENGINE is specified for DSA functionality using an ENGINE API function,
119that will override any DSA defaults set using the DSA API (ie.
120DSA_set_default_method()). For this reason, the ENGINE API is the recommended way
121to control default implementations for use in DSA and other cryptographic
122algorithms.
123
124=head1 SEE ALSO
125
126L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)>
127
128=head1 HISTORY
129
130DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(),
131DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4.
132
133DSA_set_default_openssl_method() and DSA_get_default_openssl_method() replaced
134DSA_set_default_method() and DSA_get_default_method() respectively, and
135DSA_set_method() and DSA_new_method() were altered to use B<ENGINE>s rather than
136B<DSA_METHOD>s during development of the engine version of OpenSSL 0.9.6. For
1370.9.7, the handling of defaults in the ENGINE API was restructured so that this
138change was reversed, and behaviour of the other functions resembled more closely
139the previous behaviour. The behaviour of defaults in the ENGINE API now
140transparently overrides the behaviour of defaults in the DSA API without
141requiring changing these function prototypes.
142
143=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 ba4f650361..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(const 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 cdfa7fe1fe..0000000000
--- a/src/lib/libcrypto/doc/ERR_error_string.pod
+++ /dev/null
@@ -1,73 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_error_string, ERR_error_string_n, ERR_lib_error_string,
6ERR_func_error_string, ERR_reason_error_string - obtain human-readable
7error message
8
9=head1 SYNOPSIS
10
11 #include <openssl/err.h>
12
13 char *ERR_error_string(unsigned long e, char *buf);
14 void ERR_error_string_n(unsigned long e, char *buf, size_t len);
15
16 const char *ERR_lib_error_string(unsigned long e);
17 const char *ERR_func_error_string(unsigned long e);
18 const char *ERR_reason_error_string(unsigned long e);
19
20=head1 DESCRIPTION
21
22ERR_error_string() generates a human-readable string representing the
23error code I<e>, and places it at I<buf>. I<buf> must be at least 120
24bytes long. If I<buf> is B<NULL>, the error string is placed in a
25static buffer.
26ERR_error_string_n() is a variant of ERR_error_string() that writes
27at most I<len> characters (including the terminating 0)
28and truncates the string if necessary.
29For ERR_error_string_n(), I<buf> may not be B<NULL>.
30
31The string will have the following format:
32
33 error:[error code]:[library name]:[function name]:[reason string]
34
35I<error code> is an 8 digit hexadecimal number, I<library name>,
36I<function name> and I<reason string> are ASCII text.
37
38ERR_lib_error_string(), ERR_func_error_string() and
39ERR_reason_error_string() return the library name, function
40name and reason string respectively.
41
42The OpenSSL error strings should be loaded by calling
43L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)> or, for SSL
44applications, L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
45first.
46If there is no text string registered for the given error code,
47the error string will contain the numeric code.
48
49L<ERR_print_errors(3)|ERR_print_errors(3)> can be used to print
50all error codes currently in the queue.
51
52=head1 RETURN VALUES
53
54ERR_error_string() returns a pointer to a static buffer containing the
55string if I<buf> B<== NULL>, I<buf> otherwise.
56
57ERR_lib_error_string(), ERR_func_error_string() and
58ERR_reason_error_string() return the strings, and B<NULL> if
59none is registered for the error code.
60
61=head1 SEE ALSO
62
63L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
64L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
65L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
66L<ERR_print_errors(3)|ERR_print_errors(3)>
67
68=head1 HISTORY
69
70ERR_error_string() is available in all versions of SSLeay and OpenSSL.
71ERR_error_string_n() was added in OpenSSL 0.9.6.
72
73=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 34443045fc..0000000000
--- a/src/lib/libcrypto/doc/ERR_get_error.pod
+++ /dev/null
@@ -1,76 +0,0 @@
1=pod
2
3=head1 NAME
4
5ERR_get_error, ERR_peek_error, ERR_peek_last_error,
6ERR_get_error_line, ERR_peek_error_line, ERR_peek_last_error_line,
7ERR_get_error_line_data, ERR_peek_error_line_data,
8ERR_peek_last_error_line_data - obtain error code and data
9
10=head1 SYNOPSIS
11
12 #include <openssl/err.h>
13
14 unsigned long ERR_get_error(void);
15 unsigned long ERR_peek_error(void);
16 unsigned long ERR_peek_last_error(void);
17
18 unsigned long ERR_get_error_line(const char **file, int *line);
19 unsigned long ERR_peek_error_line(const char **file, int *line);
20 unsigned long ERR_peek_last_error_line(const char **file, int *line);
21
22 unsigned long ERR_get_error_line_data(const char **file, int *line,
23 const char **data, int *flags);
24 unsigned long ERR_peek_error_line_data(const char **file, int *line,
25 const char **data, int *flags);
26 unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
27 const char **data, int *flags);
28
29=head1 DESCRIPTION
30
31ERR_get_error() returns the earliest error code from the thread's error
32queue and removes the entry. This function can be called repeatedly
33until there are no more error codes to return.
34
35ERR_peek_error() returns the earliest error code from the thread's
36error queue without modifying it.
37
38ERR_peek_last_error() returns the latest error code from the thread's
39error queue without modifying it.
40
41See L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> for obtaining information about
42location and reason of the error, and
43L<ERR_error_string(3)|ERR_error_string(3)> for human-readable error
44messages.
45
46ERR_get_error_line(), ERR_peek_error_line() and
47ERR_peek_last_error_line() are the same as the above, but they
48additionally store the file name and line number where
49the error occurred in *B<file> and *B<line>, unless these are B<NULL>.
50
51ERR_get_error_line_data(), ERR_peek_error_line_data() and
52ERR_get_last_error_line_data() store additional data and flags
53associated with the error code in *B<data>
54and *B<flags>, unless these are B<NULL>. *B<data> contains a string
55if *B<flags>&B<ERR_TXT_STRING>. If it has been allocated by OPENSSL_malloc(),
56*B<flags>&B<ERR_TXT_MALLOCED> is true.
57
58=head1 RETURN VALUES
59
60The error code, or 0 if there is no error in the queue.
61
62=head1 SEE ALSO
63
64L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
65L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>
66
67=head1 HISTORY
68
69ERR_get_error(), ERR_peek_error(), ERR_get_error_line() and
70ERR_peek_error_line() are available in all versions of SSLeay and
71OpenSSL. ERR_get_error_line_data() and ERR_peek_error_line_data()
72were added in SSLeay 0.9.0.
73ERR_peek_last_error(), ERR_peek_last_error_line() and
74ERR_peek_last_error_line_data() were added in OpenSSL 0.9.7.
75
76=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 72925fb9f4..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 order 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_BytesToKey.pod b/src/lib/libcrypto/doc/EVP_BytesToKey.pod
deleted file mode 100644
index 016381f3e9..0000000000
--- a/src/lib/libcrypto/doc/EVP_BytesToKey.pod
+++ /dev/null
@@ -1,67 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_BytesToKey - password based encryption routine
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
12 const unsigned char *salt,
13 const unsigned char *data, int datal, int count,
14 unsigned char *key,unsigned char *iv);
15
16=head1 DESCRIPTION
17
18EVP_BytesToKey() derives a key and IV from various parameters. B<type> is
19the cipher to derive the key and IV for. B<md> is the message digest to use.
20The B<salt> paramter is used as a salt in the derivation: it should point to
21an 8 byte buffer or NULL if no salt is used. B<data> is a buffer containing
22B<datal> bytes which is used to derive the keying data. B<count> is the
23iteration count to use. The derived key and IV will be written to B<key>
24and B<iv> respectively.
25
26=head1 NOTES
27
28A typical application of this function is to derive keying material for an
29encryption algorithm from a password in the B<data> parameter.
30
31Increasing the B<count> parameter slows down the algorithm which makes it
32harder for an attacker to peform a brute force attack using a large number
33of candidate passwords.
34
35If the total key and IV length is less than the digest length and
36B<MD5> is used then the derivation algorithm is compatible with PKCS#5 v1.5
37otherwise a non standard extension is used to derive the extra data.
38
39Newer applications should use more standard algorithms such as PKCS#5
40v2.0 for key derivation.
41
42=head1 KEY DERIVATION ALGORITHM
43
44The key and IV is derived by concatenating D_1, D_2, etc until
45enough data is available for the key and IV. D_i is defined as:
46
47 D_i = HASH^count(D_(i-1) || data || salt)
48
49where || denotes concatentaion, D_0 is empty, HASH is the digest
50algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data)
51is HASH(HASH(data)) and so on.
52
53The initial bytes are used for the key and the subsequent bytes for
54the IV.
55
56=head1 RETURN VALUES
57
58EVP_BytesToKey() returns the size of the derived key in bytes.
59
60=head1 SEE ALSO
61
62L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
63L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
64
65=head1 HISTORY
66
67=cut
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod
deleted file mode 100644
index faa992286b..0000000000
--- a/src/lib/libcrypto/doc/EVP_DigestInit.pod
+++ /dev/null
@@ -1,256 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_MD_CTX_init, EVP_MD_CTX_create, EVP_DigestInit_ex, EVP_DigestUpdate,
6EVP_DigestFinal_ex, EVP_MD_CTX_cleanup, EVP_MD_CTX_destroy, EVP_MAX_MD_SIZE,
7EVP_MD_CTX_copy_ex, EVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size,
8EVP_MD_block_size, EVP_MD_CTX_md, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_type,
9EVP_md_null, EVP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_dss, EVP_dss1, EVP_mdc2,
10EVP_ripemd160, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj -
11EVP digest routines
12
13=head1 SYNOPSIS
14
15 #include <openssl/evp.h>
16
17 void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
18 EVP_MD_CTX *EVP_MD_CTX_create(void);
19
20 int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
21 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
22 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md,
23 unsigned int *s);
24
25 int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
26 void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
27
28 int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);
29
30 int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
31 int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
32 unsigned int *s);
33
34 int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
35
36 #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
37
38
39 #define EVP_MD_type(e) ((e)->type)
40 #define EVP_MD_pkey_type(e) ((e)->pkey_type)
41 #define EVP_MD_size(e) ((e)->md_size)
42 #define EVP_MD_block_size(e) ((e)->block_size)
43
44 #define EVP_MD_CTX_md(e) (e)->digest)
45 #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
46 #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
47 #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
48
49 const EVP_MD *EVP_md_null(void);
50 const EVP_MD *EVP_md2(void);
51 const EVP_MD *EVP_md5(void);
52 const EVP_MD *EVP_sha(void);
53 const EVP_MD *EVP_sha1(void);
54 const EVP_MD *EVP_dss(void);
55 const EVP_MD *EVP_dss1(void);
56 const EVP_MD *EVP_mdc2(void);
57 const EVP_MD *EVP_ripemd160(void);
58
59 const EVP_MD *EVP_get_digestbyname(const char *name);
60 #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
61 #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
62
63=head1 DESCRIPTION
64
65The EVP digest routines are a high level interface to message digests.
66
67EVP_MD_CTX_init() initializes digest contet B<ctx>.
68
69EVP_MD_CTX_create() allocates, initializes and returns a digest contet.
70
71EVP_DigestInit_ex() sets up digest context B<ctx> to use a digest
72B<type> from ENGINE B<impl>. B<ctx> must be initialized before calling this
73function. B<type> will typically be supplied by a functionsuch as EVP_sha1().
74If B<impl> is NULL then the default implementation of digest B<type> is used.
75
76EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the
77digest context B<ctx>. This function can be called several times on the
78same B<ctx> to hash additional data.
79
80EVP_DigestFinal_ex() retrieves the digest value from B<ctx> and places
81it in B<md>. If the B<s> parameter is not NULL then the number of
82bytes of data written (i.e. the length of the digest) will be written
83to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written.
84After calling EVP_DigestFinal_ex() no additional calls to EVP_DigestUpdate()
85can be made, but EVP_DigestInit_ex() can be called to initialize a new
86digest operation.
87
88EVP_MD_CTX_cleanup() cleans up digest context B<ctx>, it should be called
89after a digest context is no longer needed.
90
91EVP_MD_CTX_destroy() cleans up digest context B<ctx> and frees up the
92space allocated to it, it should be called only on a context created
93using EVP_MD_CTX_create().
94
95EVP_MD_CTX_copy_ex() can be used to copy the message digest state from
96B<in> to B<out>. This is useful if large amounts of data are to be
97hashed which only differ in the last few bytes. B<out> must be initialized
98before calling this function.
99
100EVP_DigestInit() behaves in the same way as EVP_DigestInit_ex() except
101the passed context B<ctx> does not have to be initialized, and it always
102uses the default digest implementation.
103
104EVP_DigestFinal() is similar to EVP_DigestFinal_ex() except the digest
105contet B<ctx> is automatically cleaned up.
106
107EVP_MD_CTX_copy() is similar to EVP_MD_CTX_copy_ex() except the destination
108B<out> does not have to be initialized.
109
110EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest
111when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the
112hash.
113
114EVP_MD_block_size() and EVP_MD_CTX_block_size() return the block size of the
115message digest when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure.
116
117EVP_MD_type() and EVP_MD_CTX_type() return the NID of the OBJECT IDENTIFIER
118representing the given message digest when passed an B<EVP_MD> structure.
119For example EVP_MD_type(EVP_sha1()) returns B<NID_sha1>. This function is
120normally used when setting ASN1 OIDs.
121
122EVP_MD_CTX_md() returns the B<EVP_MD> structure corresponding to the passed
123B<EVP_MD_CTX>.
124
125EVP_MD_pkey_type() returns the NID of the public key signing algorithm associated
126with this digest. For example EVP_sha1() is associated with RSA so this will
127return B<NID_sha1WithRSAEncryption>. This "link" between digests and signature
128algorithms may not be retained in future versions of OpenSSL.
129
130EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_mdc2() and EVP_ripemd160()
131return B<EVP_MD> structures for the MD2, MD5, SHA, SHA1, MDC2 and RIPEMD160 digest
132algorithms respectively. The associated signature algorithm is RSA in each case.
133
134EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA and SHA1 digest
135algorithms but using DSS (DSA) for the signature algorithm.
136
137EVP_md_null() is a "null" message digest that does nothing: i.e. the hash it
138returns is of zero length.
139
140EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
141return an B<EVP_MD> structure when passed a digest name, a digest NID or
142an ASN1_OBJECT structure respectively. The digest table must be initialized
143using, for example, OpenSSL_add_all_digests() for these functions to work.
144
145=head1 RETURN VALUES
146
147EVP_DigestInit_ex(), EVP_DigestUpdate() and EVP_DigestFinal_ex() return 1 for
148success and 0 for failure.
149
150EVP_MD_CTX_copy_ex() returns 1 if successful or 0 for failure.
151
152EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the
153corresponding OBJECT IDENTIFIER or NID_undef if none exists.
154
155EVP_MD_size(), EVP_MD_block_size(), EVP_MD_CTX_size(e), EVP_MD_size(),
156EVP_MD_CTX_block_size() and EVP_MD_block_size() return the digest or block
157size in bytes.
158
159EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_dss(),
160EVP_dss1(), EVP_mdc2() and EVP_ripemd160() return pointers to the
161corresponding EVP_MD structures.
162
163EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
164return either an B<EVP_MD> structure or NULL if an error occurs.
165
166=head1 NOTES
167
168The B<EVP> interface to message digests should almost always be used in
169preference to the low level interfaces. This is because the code then becomes
170transparent to the digest used and much more flexible.
171
172SHA1 is the digest of choice for new applications. The other digest algorithms
173are still in common use.
174
175For most applications the B<impl> parameter to EVP_DigestInit_ex() will be
176set to NULL to use the default digest implementation.
177
178The functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are
179obsolete but are retained to maintain compatibility with existing code. New
180applications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and
181EVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context
182instead of initializing and cleaning it up on each call and allow non default
183implementations of digests to be specified.
184
185In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after use
186memory leaks will occur.
187
188=head1 EXAMPLE
189
190This example digests the data "Test Message\n" and "Hello World\n", using the
191digest name passed on the command line.
192
193 #include <stdio.h>
194 #include <openssl/evp.h>
195
196 main(int argc, char *argv[])
197 {
198 EVP_MD_CTX mdctx;
199 const EVP_MD *md;
200 char mess1[] = "Test Message\n";
201 char mess2[] = "Hello World\n";
202 unsigned char md_value[EVP_MAX_MD_SIZE];
203 int md_len, i;
204
205 OpenSSL_add_all_digests();
206
207 if(!argv[1]) {
208 printf("Usage: mdtest digestname\n");
209 exit(1);
210 }
211
212 md = EVP_get_digestbyname(argv[1]);
213
214 if(!md) {
215 printf("Unknown message digest %s\n", argv[1]);
216 exit(1);
217 }
218
219 EVP_MD_CTX_init(&mdctx);
220 EVP_DigestInit_ex(&mdctx, md, NULL);
221 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
222 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
223 EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
224 EVP_MD_CTX_cleanup(&mdctx);
225
226 printf("Digest is: ");
227 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
228 printf("\n");
229 }
230
231=head1 BUGS
232
233The link between digests and signing algorithms results in a situation where
234EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS
235even though they are identical digests.
236
237=head1 SEE ALSO
238
239L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
240L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD160(3)|RIPEMD160(3)>,
241L<SHA1(3)|SHA1(3)>
242
243=head1 HISTORY
244
245EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are
246available in all versions of SSLeay and OpenSSL.
247
248EVP_MD_CTX_init(), EVP_MD_CTX_create(), EVP_MD_CTX_copy_ex(),
249EVP_MD_CTX_cleanup(), EVP_MD_CTX_destroy(), EVP_DigestInit_ex()
250and EVP_DigestFinal_ex() were added in OpenSSL 0.9.7.
251
252EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(),
253EVP_dss(), EVP_dss1(), EVP_mdc2() and EVP_ripemd160() were
254changed to return truely const EVP_MD * in OpenSSL 0.9.7.
255
256=cut
diff --git a/src/lib/libcrypto/doc/EVP_EncryptInit.pod b/src/lib/libcrypto/doc/EVP_EncryptInit.pod
deleted file mode 100644
index 8271d3dfc4..0000000000
--- a/src/lib/libcrypto/doc/EVP_EncryptInit.pod
+++ /dev/null
@@ -1,511 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_CIPHER_CTX_init, EVP_EncryptInit_ex, EVP_EncryptUpdate,
6EVP_EncryptFinal_ex, EVP_DecryptInit_ex, EVP_DecryptUpdate,
7EVP_DecryptFinal_ex, EVP_CipherInit_ex, EVP_CipherUpdate,
8EVP_CipherFinal_ex, EVP_CIPHER_CTX_set_key_length,
9EVP_CIPHER_CTX_ctrl, EVP_CIPHER_CTX_cleanup, EVP_EncryptInit,
10EVP_EncryptFinal, EVP_DecryptInit, EVP_DecryptFinal,
11EVP_CipherInit, EVP_CipherFinal, EVP_get_cipherbyname,
12EVP_get_cipherbynid, EVP_get_cipherbyobj, EVP_CIPHER_nid,
13EVP_CIPHER_block_size, EVP_CIPHER_key_length, EVP_CIPHER_iv_length,
14EVP_CIPHER_flags, EVP_CIPHER_mode, EVP_CIPHER_type, EVP_CIPHER_CTX_cipher,
15EVP_CIPHER_CTX_nid, EVP_CIPHER_CTX_block_size, EVP_CIPHER_CTX_key_length,
16EVP_CIPHER_CTX_iv_length, EVP_CIPHER_CTX_get_app_data,
17EVP_CIPHER_CTX_set_app_data, EVP_CIPHER_CTX_type, EVP_CIPHER_CTX_flags,
18EVP_CIPHER_CTX_mode, EVP_CIPHER_param_to_asn1, EVP_CIPHER_asn1_to_param,
19EVP_CIPHER_CTX_set_padding - EVP cipher routines
20
21=head1 SYNOPSIS
22
23 #include <openssl/evp.h>
24
25 void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
26
27 int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
28 ENGINE *impl, unsigned char *key, unsigned char *iv);
29 int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
30 int *outl, unsigned char *in, int inl);
31 int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out,
32 int *outl);
33
34 int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
35 ENGINE *impl, unsigned char *key, unsigned char *iv);
36 int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
37 int *outl, unsigned char *in, int inl);
38 int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
39 int *outl);
40
41 int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
42 ENGINE *impl, unsigned char *key, unsigned char *iv, int enc);
43 int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
44 int *outl, unsigned char *in, int inl);
45 int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
46 int *outl);
47
48 int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
49 unsigned char *key, unsigned char *iv);
50 int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
51 int *outl);
52
53 int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
54 unsigned char *key, unsigned char *iv);
55 int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
56 int *outl);
57
58 int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
59 unsigned char *key, unsigned char *iv, int enc);
60 int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
61 int *outl);
62
63 int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *x, int padding);
64 int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
65 int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
66 int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
67
68 const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
69 #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
70 #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
71
72 #define EVP_CIPHER_nid(e) ((e)->nid)
73 #define EVP_CIPHER_block_size(e) ((e)->block_size)
74 #define EVP_CIPHER_key_length(e) ((e)->key_len)
75 #define EVP_CIPHER_iv_length(e) ((e)->iv_len)
76 #define EVP_CIPHER_flags(e) ((e)->flags)
77 #define EVP_CIPHER_mode(e) ((e)->flags) & EVP_CIPH_MODE)
78 int EVP_CIPHER_type(const EVP_CIPHER *ctx);
79
80 #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
81 #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
82 #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
83 #define EVP_CIPHER_CTX_key_length(e) ((e)->key_len)
84 #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
85 #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
86 #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
87 #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
88 #define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags)
89 #define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE)
90
91 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
92 int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
93
94=head1 DESCRIPTION
95
96The EVP cipher routines are a high level interface to certain
97symmetric ciphers.
98
99EVP_CIPHER_CTX_init() initializes cipher contex B<ctx>.
100
101EVP_EncryptInit_ex() sets up cipher context B<ctx> for encryption
102with cipher B<type> from ENGINE B<impl>. B<ctx> must be initialized
103before calling this function. B<type> is normally supplied
104by a function such as EVP_des_cbc(). If B<impl> is NULL then the
105default implementation is used. B<key> is the symmetric key to use
106and B<iv> is the IV to use (if necessary), the actual number of bytes
107used for the key and IV depends on the cipher. It is possible to set
108all parameters to NULL except B<type> in an initial call and supply
109the remaining parameters in subsequent calls, all of which have B<type>
110set to NULL. This is done when the default cipher parameters are not
111appropriate.
112
113EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and
114writes the encrypted version to B<out>. This function can be called
115multiple times to encrypt successive blocks of data. The amount
116of data written depends on the block alignment of the encrypted data:
117as a result the amount of data written may be anything from zero bytes
118to (inl + cipher_block_size - 1) so B<outl> should contain sufficient
119room. The actual number of bytes written is placed in B<outl>.
120
121If padding is enabled (the default) then EVP_EncryptFinal_ex() encrypts
122the "final" data, that is any data that remains in a partial block.
123It uses L<standard block padding|/NOTES> (aka PKCS padding). The encrypted
124final data is written to B<out> which should have sufficient space for
125one cipher block. The number of bytes written is placed in B<outl>. After
126this function is called the encryption operation is finished and no further
127calls to EVP_EncryptUpdate() should be made.
128
129If padding is disabled then EVP_EncryptFinal_ex() will not encrypt any more
130data and it will return an error if any data remains in a partial block:
131that is if the total data length is not a multiple of the block size.
132
133EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex() are the
134corresponding decryption operations. EVP_DecryptFinal() will return an
135error code if padding is enabled and the final block is not correctly
136formatted. The parameters and restrictions are identical to the encryption
137operations except that if padding is enabled the decrypted data buffer B<out>
138passed to EVP_DecryptUpdate() should have sufficient room for
139(B<inl> + cipher_block_size) bytes unless the cipher block size is 1 in
140which case B<inl> bytes is sufficient.
141
142EVP_CipherInit_ex(), EVP_CipherUpdate() and EVP_CipherFinal_ex() are
143functions that can be used for decryption or encryption. The operation
144performed depends on the value of the B<enc> parameter. It should be set
145to 1 for encryption, 0 for decryption and -1 to leave the value unchanged
146(the actual value of 'enc' being supplied in a previous call).
147
148EVP_CIPHER_CTX_cleanup() clears all information from a cipher context
149and free up any allocated memory associate with it. It should be called
150after all operations using a cipher are complete so sensitive information
151does not remain in memory.
152
153EVP_EncryptInit(), EVP_DecryptInit() and EVP_CipherInit() behave in a
154similar way to EVP_EncryptInit_ex(), EVP_DecryptInit_ex and
155EVP_CipherInit_ex() except the B<ctx> paramter does not need to be
156initialized and they always use the default cipher implementation.
157
158EVP_EncryptFinal(), EVP_DecryptFinal() and EVP_CipherFinal() behave in a
159similar way to EVP_EncryptFinal_ex(), EVP_DecryptFinal_ex() and
160EVP_CipherFinal_ex() except B<ctx> is automatically cleaned up
161after the call.
162
163EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
164return an EVP_CIPHER structure when passed a cipher name, a NID or an
165ASN1_OBJECT structure.
166
167EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return the NID of a cipher when
168passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> structure. The actual NID
169value is an internal value which may not have a corresponding OBJECT
170IDENTIFIER.
171
172EVP_CIPHER_CTX_set_padding() enables or disables padding. By default
173encryption operations are padded using standard block padding and the
174padding is checked and removed when decrypting. If the B<pad> parameter
175is zero then no padding is performed, the total amount of data encrypted
176or decrypted must then be a multiple of the block size or an error will
177occur.
178
179EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
180length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
181structure. The constant B<EVP_MAX_KEY_LENGTH> is the maximum key length
182for all ciphers. Note: although EVP_CIPHER_key_length() is fixed for a
183given cipher, the value of EVP_CIPHER_CTX_key_length() may be different
184for variable key length ciphers.
185
186EVP_CIPHER_CTX_set_key_length() sets the key length of the cipher ctx.
187If the cipher is a fixed length cipher then attempting to set the key
188length to any value other than the fixed value is an error.
189
190EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
191length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>.
192It will return zero if the cipher does not use an IV. The constant
193B<EVP_MAX_IV_LENGTH> is the maximum IV length for all ciphers.
194
195EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
196size of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
197structure. The constant B<EVP_MAX_IV_LENGTH> is also the maximum block
198length for all ciphers.
199
200EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the type of the passed
201cipher or context. This "type" is the actual NID of the cipher OBJECT
202IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and
203128 bit RC2 have the same NID. If the cipher does not have an object
204identifier or does not have ASN1 support this function will return
205B<NID_undef>.
206
207EVP_CIPHER_CTX_cipher() returns the B<EVP_CIPHER> structure when passed
208an B<EVP_CIPHER_CTX> structure.
209
210EVP_CIPHER_mode() and EVP_CIPHER_CTX_mode() return the block cipher mode:
211EVP_CIPH_ECB_MODE, EVP_CIPH_CBC_MODE, EVP_CIPH_CFB_MODE or
212EVP_CIPH_OFB_MODE. If the cipher is a stream cipher then
213EVP_CIPH_STREAM_CIPHER is returned.
214
215EVP_CIPHER_param_to_asn1() sets the AlgorithmIdentifier "parameter" based
216on the passed cipher. This will typically include any parameters and an
217IV. The cipher IV (if any) must be set when this call is made. This call
218should be made before the cipher is actually "used" (before any
219EVP_EncryptUpdate(), EVP_DecryptUpdate() calls for example). This function
220may fail if the cipher does not have any ASN1 support.
221
222EVP_CIPHER_asn1_to_param() sets the cipher parameters based on an ASN1
223AlgorithmIdentifier "parameter". The precise effect depends on the cipher
224In the case of RC2, for example, it will set the IV and effective key length.
225This function should be called after the base cipher type is set but before
226the key is set. For example EVP_CipherInit() will be called with the IV and
227key set to NULL, EVP_CIPHER_asn1_to_param() will be called and finally
228EVP_CipherInit() again with all parameters except the key set to NULL. It is
229possible for this function to fail if the cipher does not have any ASN1 support
230or the parameters cannot be set (for example the RC2 effective key length
231is not supported.
232
233EVP_CIPHER_CTX_ctrl() allows various cipher specific parameters to be determined
234and set. Currently only the RC2 effective key length and the number of rounds of
235RC5 can be set.
236
237=head1 RETURN VALUES
238
239EVP_EncryptInit_ex(), EVP_EncryptUpdate() and EVP_EncryptFinal_ex()
240return 1 for success and 0 for failure.
241
242EVP_DecryptInit_ex() and EVP_DecryptUpdate() return 1 for success and 0 for failure.
243EVP_DecryptFinal_ex() returns 0 if the decrypt failed or 1 for success.
244
245EVP_CipherInit_ex() and EVP_CipherUpdate() return 1 for success and 0 for failure.
246EVP_CipherFinal_ex() returns 0 for a decryption failure or 1 for success.
247
248EVP_CIPHER_CTX_cleanup() returns 1 for success and 0 for failure.
249
250EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
251return an B<EVP_CIPHER> structure or NULL on error.
252
253EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return a NID.
254
255EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
256size.
257
258EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
259length.
260
261EVP_CIPHER_CTX_set_padding() always returns 1.
262
263EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
264length or zero if the cipher does not use an IV.
265
266EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the NID of the cipher's
267OBJECT IDENTIFIER or NID_undef if it has no defined OBJECT IDENTIFIER.
268
269EVP_CIPHER_CTX_cipher() returns an B<EVP_CIPHER> structure.
270
271EVP_CIPHER_param_to_asn1() and EVP_CIPHER_asn1_to_param() return 1 for
272success or zero for failure.
273
274=head1 CIPHER LISTING
275
276All algorithms have a fixed key length unless otherwise stated.
277
278=over 4
279
280=item EVP_enc_null()
281
282Null cipher: does nothing.
283
284=item EVP_des_cbc(void), EVP_des_ecb(void), EVP_des_cfb(void), EVP_des_ofb(void)
285
286DES in CBC, ECB, CFB and OFB modes respectively.
287
288=item EVP_des_ede_cbc(void), EVP_des_ede(), EVP_des_ede_ofb(void), EVP_des_ede_cfb(void)
289
290Two key triple DES in CBC, ECB, CFB and OFB modes respectively.
291
292=item EVP_des_ede3_cbc(void), EVP_des_ede3(), EVP_des_ede3_ofb(void), EVP_des_ede3_cfb(void)
293
294Three key triple DES in CBC, ECB, CFB and OFB modes respectively.
295
296=item EVP_desx_cbc(void)
297
298DESX algorithm in CBC mode.
299
300=item EVP_rc4(void)
301
302RC4 stream cipher. This is a variable key length cipher with default key length 128 bits.
303
304=item EVP_rc4_40(void)
305
306RC4 stream cipher with 40 bit key length. This is obsolete and new code should use EVP_rc4()
307and the EVP_CIPHER_CTX_set_key_length() function.
308
309=item EVP_idea_cbc() EVP_idea_ecb(void), EVP_idea_cfb(void), EVP_idea_ofb(void), EVP_idea_cbc(void)
310
311IDEA encryption algorithm in CBC, ECB, CFB and OFB modes respectively.
312
313=item EVP_rc2_cbc(void), EVP_rc2_ecb(void), EVP_rc2_cfb(void), EVP_rc2_ofb(void)
314
315RC2 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
316length cipher with an additional parameter called "effective key bits" or "effective key length".
317By default both are set to 128 bits.
318
319=item EVP_rc2_40_cbc(void), EVP_rc2_64_cbc(void)
320
321RC2 algorithm in CBC mode with a default key length and effective key length of 40 and 64 bits.
322These are obsolete and new code should use EVP_rc2_cbc(), EVP_CIPHER_CTX_set_key_length() and
323EVP_CIPHER_CTX_ctrl() to set the key length and effective key length.
324
325=item EVP_bf_cbc(void), EVP_bf_ecb(void), EVP_bf_cfb(void), EVP_bf_ofb(void);
326
327Blowfish encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
328length cipher.
329
330=item EVP_cast5_cbc(void), EVP_cast5_ecb(void), EVP_cast5_cfb(void), EVP_cast5_ofb(void)
331
332CAST encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key
333length cipher.
334
335=item EVP_rc5_32_12_16_cbc(void), EVP_rc5_32_12_16_ecb(void), EVP_rc5_32_12_16_cfb(void), EVP_rc5_32_12_16_ofb(void)
336
337RC5 encryption algorithm in CBC, ECB, CFB and OFB modes respectively. This is a variable key length
338cipher with an additional "number of rounds" parameter. By default the key length is set to 128
339bits and 12 rounds.
340
341=back
342
343=head1 NOTES
344
345Where possible the B<EVP> interface to symmetric ciphers should be used in
346preference to the low level interfaces. This is because the code then becomes
347transparent to the cipher used and much more flexible.
348
349PKCS padding works by adding B<n> padding bytes of value B<n> to make the total
350length of the encrypted data a multiple of the block size. Padding is always
351added so if the data is already a multiple of the block size B<n> will equal
352the block size. For example if the block size is 8 and 11 bytes are to be
353encrypted then 5 padding bytes of value 5 will be added.
354
355When decrypting the final block is checked to see if it has the correct form.
356
357Although the decryption operation can produce an error if padding is enabled,
358it is not a strong test that the input data or key is correct. A random block
359has better than 1 in 256 chance of being of the correct format and problems with
360the input data earlier on will not produce a final decrypt error.
361
362If padding is disabled then the decryption operation will always succeed if
363the total amount of data decrypted is a multiple of the block size.
364
365The functions EVP_EncryptInit(), EVP_EncryptFinal(), EVP_DecryptInit(),
366EVP_CipherInit() and EVP_CipherFinal() are obsolete but are retained for
367compatibility with existing code. New code should use EVP_EncryptInit_ex(),
368EVP_EncryptFinal_ex(), EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(),
369EVP_CipherInit_ex() and EVP_CipherFinal_ex() because they can reuse an
370existing context without allocating and freeing it up on each call.
371
372=head1 BUGS
373
374For RC5 the number of rounds can currently only be set to 8, 12 or 16. This is
375a limitation of the current RC5 code rather than the EVP interface.
376
377EVP_MAX_KEY_LENGTH and EVP_MAX_IV_LENGTH only refer to the internal ciphers with
378default key lengths. If custom ciphers exceed these values the results are
379unpredictable. This is because it has become standard practice to define a
380generic key as a fixed unsigned char array containing EVP_MAX_KEY_LENGTH bytes.
381
382The ASN1 code is incomplete (and sometimes inaccurate) it has only been tested
383for certain common S/MIME ciphers (RC2, DES, triple DES) in CBC mode.
384
385=head1 EXAMPLES
386
387Get the number of rounds used in RC5:
388
389 int nrounds;
390 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &nrounds);
391
392Get the RC2 effective key length:
393
394 int key_bits;
395 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC2_KEY_BITS, 0, &key_bits);
396
397Set the number of rounds used in RC5:
398
399 int nrounds;
400 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC5_ROUNDS, nrounds, NULL);
401
402Set the effective key length used in RC2:
403
404 int key_bits;
405 EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL);
406
407Encrypt a string using blowfish:
408
409 int do_crypt(char *outfile)
410 {
411 unsigned char outbuf[1024];
412 int outlen, tmplen;
413 /* Bogus key and IV: we'd normally set these from
414 * another source.
415 */
416 unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
417 unsigned char iv[] = {1,2,3,4,5,6,7,8};
418 char intext[] = "Some Crypto Text";
419 EVP_CIPHER_CTX ctx;
420 FILE *out;
421 EVP_CIPHER_CTX_init(&ctx);
422 EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv);
423
424 if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, strlen(intext)))
425 {
426 /* Error */
427 return 0;
428 }
429 /* Buffer passed to EVP_EncryptFinal() must be after data just
430 * encrypted to avoid overwriting it.
431 */
432 if(!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen))
433 {
434 /* Error */
435 return 0;
436 }
437 outlen += tmplen;
438 EVP_CIPHER_CTX_cleanup(&ctx);
439 /* Need binary mode for fopen because encrypted data is
440 * binary data. Also cannot use strlen() on it because
441 * it wont be null terminated and may contain embedded
442 * nulls.
443 */
444 out = fopen(outfile, "wb");
445 fwrite(outbuf, 1, outlen, out);
446 fclose(out);
447 return 1;
448 }
449
450The ciphertext from the above example can be decrypted using the B<openssl>
451utility with the command line:
452
453 S<openssl bf -in cipher.bin -K 000102030405060708090A0B0C0D0E0F -iv 0102030405060708 -d>
454
455General encryption, decryption function example using FILE I/O and RC2 with an
45680 bit key:
457
458 int do_crypt(FILE *in, FILE *out, int do_encrypt)
459 {
460 /* Allow enough space in output buffer for additional block */
461 inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];
462 int inlen, outlen;
463 /* Bogus key and IV: we'd normally set these from
464 * another source.
465 */
466 unsigned char key[] = "0123456789";
467 unsigned char iv[] = "12345678";
468 /* Don't set key or IV because we will modify the parameters */
469 EVP_CIPHER_CTX_init(&ctx);
470 EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt);
471 EVP_CIPHER_CTX_set_key_length(&ctx, 10);
472 /* We finished modifying parameters so now we can set key and IV */
473 EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt);
474
475 for(;;)
476 {
477 inlen = fread(inbuf, 1, 1024, in);
478 if(inlen <= 0) break;
479 if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen))
480 {
481 /* Error */
482 EVP_CIPHER_CTX_cleanup(&ctx);
483 return 0;
484 }
485 fwrite(outbuf, 1, outlen, out);
486 }
487 if(!EVP_CipherFinal_ex(&ctx, outbuf, &outlen))
488 {
489 /* Error */
490 EVP_CIPHER_CTX_cleanup(&ctx);
491 return 0;
492 }
493 fwrite(outbuf, 1, outlen, out);
494
495 EVP_CIPHER_CTX_cleanup(&ctx);
496 return 1;
497 }
498
499
500=head1 SEE ALSO
501
502L<evp(3)|evp(3)>
503
504=head1 HISTORY
505
506EVP_CIPHER_CTX_init(), EVP_EncryptInit_ex(), EVP_EncryptFinal_ex(),
507EVP_DecryptInit_ex(), EVP_DecryptFinal_ex(), EVP_CipherInit_ex(),
508EVP_CipherFinal_ex() and EVP_CIPHER_CTX_set_padding() appeared in
509OpenSSL 0.9.7.
510
511=cut
diff --git a/src/lib/libcrypto/doc/EVP_OpenInit.pod b/src/lib/libcrypto/doc/EVP_OpenInit.pod
deleted file mode 100644
index 2e710da945..0000000000
--- a/src/lib/libcrypto/doc/EVP_OpenInit.pod
+++ /dev/null
@@ -1,63 +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 int EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 int 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() initializes 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 NOTES
35
36It is possible to call EVP_OpenInit() twice in the same way as
37EVP_DecryptInit(). The first call should have B<priv> set to NULL
38and (after setting any cipher parameters) it should be called again
39with B<type> set to NULL.
40
41If the cipher passed in the B<type> parameter is a variable length
42cipher then the key length will be set to the value of the recovered
43key length. If the cipher is a fixed length cipher then the recovered
44key length must match the fixed cipher length.
45
46=head1 RETURN VALUES
47
48EVP_OpenInit() returns 0 on error or a non zero integer (actually the
49recovered secret key size) if successful.
50
51EVP_OpenUpdate() returns 1 for success or 0 for failure.
52
53EVP_OpenFinal() returns 0 if the decrypt failed or 1 for success.
54
55=head1 SEE ALSO
56
57L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
58L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
59L<EVP_SealInit(3)|EVP_SealInit(3)>
60
61=head1 HISTORY
62
63=cut
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_new.pod b/src/lib/libcrypto/doc/EVP_PKEY_new.pod
deleted file mode 100644
index 10687e458d..0000000000
--- a/src/lib/libcrypto/doc/EVP_PKEY_new.pod
+++ /dev/null
@@ -1,47 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_PKEY_new, EVP_PKEY_free - private key allocation functions.
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 EVP_PKEY *EVP_PKEY_new(void);
12 void EVP_PKEY_free(EVP_PKEY *key);
13
14
15=head1 DESCRIPTION
16
17The EVP_PKEY_new() function allocates an empty B<EVP_PKEY>
18structure which is used by OpenSSL to store private keys.
19
20EVP_PKEY_free() frees up the private key B<key>.
21
22=head1 NOTES
23
24The B<EVP_PKEY> structure is used by various OpenSSL functions
25which require a general private key without reference to any
26particular algorithm.
27
28The structure returned by EVP_PKEY_new() is empty. To add a
29private key to this empty structure the functions described in
30L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)> should be used.
31
32=head1 RETURN VALUES
33
34EVP_PKEY_new() returns either the newly allocated B<EVP_PKEY>
35structure of B<NULL> if an error occurred.
36
37EVP_PKEY_free() does not return a value.
38
39=head1 SEE ALSO
40
41L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)>
42
43=head1 HISTORY
44
45TBA
46
47=cut
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod b/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod
deleted file mode 100644
index 2db692e271..0000000000
--- a/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod
+++ /dev/null
@@ -1,80 +0,0 @@
1=pod
2
3=head1 NAME
4
5EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY,
6EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY,
7EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, EVP_PKEY_assign_EC_KEY,
8EVP_PKEY_type - EVP_PKEY assignment functions.
9
10=head1 SYNOPSIS
11
12 #include <openssl/evp.h>
13
14 int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key);
15 int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key);
16 int EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key);
17 int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,EC_KEY *key);
18
19 RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
20 DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
21 DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
22 EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
23
24 int EVP_PKEY_assign_RSA(EVP_PKEY *pkey,RSA *key);
25 int EVP_PKEY_assign_DSA(EVP_PKEY *pkey,DSA *key);
26 int EVP_PKEY_assign_DH(EVP_PKEY *pkey,DH *key);
27 int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey,EC_KEY *key);
28
29 int EVP_PKEY_type(int type);
30
31=head1 DESCRIPTION
32
33EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
34EVP_PKEY_set1_EC_KEY() set the key referenced by B<pkey> to B<key>.
35
36EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
37EVP_PKEY_get1_EC_KEY() return the referenced key in B<pkey> or
38B<NULL> if the key is not of the correct type.
39
40EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
41and EVP_PKEY_assign_EC_KEY() also set the referenced key to B<key>
42however these use the supplied B<key> internally and so B<key>
43will be freed when the parent B<pkey> is freed.
44
45EVP_PKEY_type() returns the type of key corresponding to the value
46B<type>. The type of a key can be obtained with
47EVP_PKEY_type(pkey->type). The return value will be EVP_PKEY_RSA,
48EVP_PKEY_DSA, EVP_PKEY_DH or EVP_PKEY_EC for the corresponding
49key types or NID_undef if the key type is unassigned.
50
51=head1 NOTES
52
53In accordance with the OpenSSL naming convention the key obtained
54from or assigned to the B<pkey> using the B<1> functions must be
55freed as well as B<pkey>.
56
57EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
58EVP_PKEY_assign_EC_KEY() are implemented as macros.
59
60=head1 RETURN VALUES
61
62EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
63EVP_PKEY_set1_EC_KEY() return 1 for success or 0 for failure.
64
65EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
66EVP_PKEY_get1_EC_KEY() return the referenced key or B<NULL> if
67an error occurred.
68
69EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
70and EVP_PKEY_assign_EC_KEY() return 1 for success and 0 for failure.
71
72=head1 SEE ALSO
73
74L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>
75
76=head1 HISTORY
77
78TBA
79
80=cut
diff --git a/src/lib/libcrypto/doc/EVP_SealInit.pod b/src/lib/libcrypto/doc/EVP_SealInit.pod
deleted file mode 100644
index 48a0e29954..0000000000
--- a/src/lib/libcrypto/doc/EVP_SealInit.pod
+++ /dev/null
@@ -1,85 +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, const EVP_CIPHER *type,
12 unsigned char **ek, int *ekl, unsigned char *iv,
13 EVP_PKEY **pubk, int npubk);
14 int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
15 int *outl, unsigned char *in, int inl);
16 int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
17 int *outl);
18
19=head1 DESCRIPTION
20
21The EVP envelope routines are a high level interface to envelope
22encryption. They generate a random key and IV (if required) then
23"envelope" it by using public key encryption. Data can then be
24encrypted using this key.
25
26EVP_SealInit() initializes a cipher context B<ctx> for encryption
27with cipher B<type> using a random secret key and IV. B<type> is normally
28supplied by a function such as EVP_des_cbc(). The secret key is encrypted
29using one or more public keys, this allows the same encrypted data to be
30decrypted using any of the corresponding private keys. B<ek> is an array of
31buffers where the public key encrypted secret key will be written, each buffer
32must contain 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
37The B<iv> parameter is a buffer where the generated IV is written to. It must
38contain enough room for the corresponding cipher's IV, as determined by (for
39example) EVP_CIPHER_iv_length(type).
40
41If the cipher does not require an IV then the B<iv> parameter is ignored
42and can be B<NULL>.
43
44EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties
45as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as
46documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual
47page.
48
49=head1 RETURN VALUES
50
51EVP_SealInit() returns 0 on error or B<npubk> if successful.
52
53EVP_SealUpdate() and EVP_SealFinal() return 1 for success and 0 for
54failure.
55
56=head1 NOTES
57
58Because a random secret key is generated the random number generator
59must be seeded before calling EVP_SealInit().
60
61The public key must be RSA because it is the only OpenSSL public key
62algorithm that supports key transport.
63
64Envelope encryption is the usual method of using public key encryption
65on large amounts of data, this is because public key encryption is slow
66but symmetric encryption is fast. So symmetric encryption is used for
67bulk encryption and the small random symmetric key used is transferred
68using public key encryption.
69
70It is possible to call EVP_SealInit() twice in the same way as
71EVP_EncryptInit(). The first call should have B<npubk> set to 0
72and (after setting any cipher parameters) it should be called again
73with B<type> set to NULL.
74
75=head1 SEE ALSO
76
77L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
78L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
79L<EVP_OpenInit(3)|EVP_OpenInit(3)>
80
81=head1 HISTORY
82
83EVP_SealFinal() did not return a value before OpenSSL 0.9.7.
84
85=cut
diff --git a/src/lib/libcrypto/doc/EVP_SignInit.pod b/src/lib/libcrypto/doc/EVP_SignInit.pod
deleted file mode 100644
index 0bace24938..0000000000
--- a/src/lib/libcrypto/doc/EVP_SignInit.pod
+++ /dev/null
@@ -1,95 +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 int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
12 int 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 void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
16
17 int EVP_PKEY_size(EVP_PKEY *pkey);
18
19=head1 DESCRIPTION
20
21The EVP signature routines are a high level interface to digital
22signatures.
23
24EVP_SignInit_ex() sets up signing context B<ctx> to use digest
25B<type> from ENGINE B<impl>. B<ctx> must be initialized with
26EVP_MD_CTX_init() before calling this function.
27
28EVP_SignUpdate() hashes B<cnt> bytes of data at B<d> into the
29signature context B<ctx>. This function can be called several times on the
30same B<ctx> to include additional data.
31
32EVP_SignFinal() signs the data in B<ctx> using the private key B<pkey> and
33places the signature in B<sig>. The number of bytes of data written (i.e. the
34length of the signature) will be written to the integer at B<s>, at most
35EVP_PKEY_size(pkey) bytes will be written.
36
37EVP_SignInit() initializes a signing context B<ctx> to use the default
38implementation of digest B<type>.
39
40EVP_PKEY_size() returns the maximum size of a signature in bytes. The actual
41signature returned by EVP_SignFinal() may be smaller.
42
43=head1 RETURN VALUES
44
45EVP_SignInit_ex(), EVP_SignUpdate() and EVP_SignFinal() return 1
46for success and 0 for failure.
47
48EVP_PKEY_size() returns the maximum size of a signature in bytes.
49
50The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
51
52=head1 NOTES
53
54The B<EVP> interface to digital signatures should almost always be used in
55preference to the low level interfaces. This is because the code then becomes
56transparent to the algorithm used and much more flexible.
57
58Due to the link between message digests and public key algorithms the correct
59digest algorithm must be used with the correct public key type. A list of
60algorithms and associated public key algorithms appears in
61L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
62
63When signing with DSA private keys the random number generator must be seeded
64or the operation will fail. The random number generator does not need to be
65seeded for RSA signatures.
66
67The call to EVP_SignFinal() internally finalizes a copy of the digest context.
68This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
69later to digest and sign additional data.
70
71Since only a copy of the digest context is ever finalized the context must
72be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
73will occur.
74
75=head1 BUGS
76
77Older versions of this documentation wrongly stated that calls to
78EVP_SignUpdate() could not be made after calling EVP_SignFinal().
79
80=head1 SEE ALSO
81
82L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
83L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
84L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
85L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD(3)|RIPEMD(3)>,
86L<SHA1(3)|SHA1(3)>, L<digest(1)|digest(1)>
87
88=head1 HISTORY
89
90EVP_SignInit(), EVP_SignUpdate() and EVP_SignFinal() are
91available in all versions of SSLeay and OpenSSL.
92
93EVP_SignInit_ex() was added in OpenSSL 0.9.7.
94
95=cut
diff --git a/src/lib/libcrypto/doc/EVP_VerifyInit.pod b/src/lib/libcrypto/doc/EVP_VerifyInit.pod
deleted file mode 100644
index b6afaedee5..0000000000
--- a/src/lib/libcrypto/doc/EVP_VerifyInit.pod
+++ /dev/null
@@ -1,86 +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 int EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
12 int 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 int EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type);
16
17=head1 DESCRIPTION
18
19The EVP signature verification routines are a high level interface to digital
20signatures.
21
22EVP_VerifyInit_ex() sets up verification context B<ctx> to use digest
23B<type> from ENGINE B<impl>. B<ctx> must be initialized by calling
24EVP_MD_CTX_init() before calling this function.
25
26EVP_VerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
27verification context B<ctx>. This function can be called several times on the
28same B<ctx> to include additional data.
29
30EVP_VerifyFinal() verifies the data in B<ctx> using the public key B<pkey>
31and against the B<siglen> bytes at B<sigbuf>.
32
33EVP_VerifyInit() initializes verification context B<ctx> to use the default
34implementation of digest B<type>.
35
36=head1 RETURN VALUES
37
38EVP_VerifyInit_ex() and EVP_VerifyUpdate() return 1 for success and 0 for
39failure.
40
41EVP_VerifyFinal() returns 1 for a correct signature, 0 for failure and -1 if some
42other error occurred.
43
44The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
45
46=head1 NOTES
47
48The B<EVP> interface to digital signatures should almost always be used in
49preference to the low level interfaces. This is because the code then becomes
50transparent to the algorithm used and much more flexible.
51
52Due to the link between message digests and public key algorithms the correct
53digest algorithm must be used with the correct public key type. A list of
54algorithms and associated public key algorithms appears in
55L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
56
57The call to EVP_VerifyFinal() internally finalizes a copy of the digest context.
58This means that calls to EVP_VerifyUpdate() and EVP_VerifyFinal() can be called
59later to digest and verify additional data.
60
61Since only a copy of the digest context is ever finalized the context must
62be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
63will occur.
64
65=head1 BUGS
66
67Older versions of this documentation wrongly stated that calls to
68EVP_VerifyUpdate() could not be made after calling EVP_VerifyFinal().
69
70=head1 SEE ALSO
71
72L<evp(3)|evp(3)>,
73L<EVP_SignInit(3)|EVP_SignInit(3)>,
74L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
75L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
76L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
77L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
78
79=head1 HISTORY
80
81EVP_VerifyInit(), EVP_VerifyUpdate() and EVP_VerifyFinal() are
82available in all versions of SSLeay and OpenSSL.
83
84EVP_VerifyInit_ex() was added in OpenSSL 0.9.7
85
86=cut
diff --git a/src/lib/libcrypto/doc/OBJ_nid2obj.pod b/src/lib/libcrypto/doc/OBJ_nid2obj.pod
deleted file mode 100644
index 7dcc07923f..0000000000
--- a/src/lib/libcrypto/doc/OBJ_nid2obj.pod
+++ /dev/null
@@ -1,149 +0,0 @@
1=pod
2
3=head1 NAME
4
5OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid,
6OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup - ASN1 object utility
7functions
8
9=head1 SYNOPSIS
10
11 ASN1_OBJECT * OBJ_nid2obj(int n);
12 const char * OBJ_nid2ln(int n);
13 const char * OBJ_nid2sn(int n);
14
15 int OBJ_obj2nid(const ASN1_OBJECT *o);
16 int OBJ_ln2nid(const char *ln);
17 int OBJ_sn2nid(const char *sn);
18
19 int OBJ_txt2nid(const char *s);
20
21 ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
22 int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
23
24 int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
25 ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
26
27 int OBJ_create(const char *oid,const char *sn,const char *ln);
28 void OBJ_cleanup(void);
29
30=head1 DESCRIPTION
31
32The ASN1 object utility functions process ASN1_OBJECT structures which are
33a representation of the ASN1 OBJECT IDENTIFIER (OID) type.
34
35OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID B<n> to
36an ASN1_OBJECT structure, its long name and its short name respectively,
37or B<NULL> is an error occurred.
38
39OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
40for the object B<o>, the long name <ln> or the short name <sn> respectively
41or NID_undef if an error occurred.
42
43OBJ_txt2nid() returns NID corresponding to text string <s>. B<s> can be
44a long name, a short name or the numerical respresentation of an object.
45
46OBJ_txt2obj() converts the text string B<s> into an ASN1_OBJECT structure.
47If B<no_name> is 0 then long names and short names will be interpreted
48as well as numerical forms. If B<no_name> is 1 only the numerical form
49is acceptable.
50
51OBJ_obj2txt() converts the B<ASN1_OBJECT> B<a> into a textual representation.
52The representation is written as a null terminated string to B<buf>
53at most B<buf_len> bytes are written, truncating the result if necessary.
54The total amount of space required is returned. If B<no_name> is 0 then
55if the object has a long or short name then that will be used, otherwise
56the numerical form will be used. If B<no_name> is 1 then the numerical
57form will always be used.
58
59OBJ_cmp() compares B<a> to B<b>. If the two are identical 0 is returned.
60
61OBJ_dup() returns a copy of B<o>.
62
63OBJ_create() adds a new object to the internal table. B<oid> is the
64numerical form of the object, B<sn> the short name and B<ln> the
65long name. A new NID is returned for the created object.
66
67OBJ_cleanup() cleans up OpenSSLs internal object table: this should
68be called before an application exits if any new objects were added
69using OBJ_create().
70
71=head1 NOTES
72
73Objects in OpenSSL can have a short name, a long name and a numerical
74identifier (NID) associated with them. A standard set of objects is
75represented in an internal table. The appropriate values are defined
76in the header file B<objects.h>.
77
78For example the OID for commonName has the following definitions:
79
80 #define SN_commonName "CN"
81 #define LN_commonName "commonName"
82 #define NID_commonName 13
83
84New objects can be added by calling OBJ_create().
85
86Table objects have certain advantages over other objects: for example
87their NIDs can be used in a C language switch statement. They are
88also static constant structures which are shared: that is there
89is only a single constant structure for each table object.
90
91Objects which are not in the table have the NID value NID_undef.
92
93Objects do not need to be in the internal tables to be processed,
94the functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
95form of an OID.
96
97=head1 EXAMPLES
98
99Create an object for B<commonName>:
100
101 ASN1_OBJECT *o;
102 o = OBJ_nid2obj(NID_commonName);
103
104Check if an object is B<commonName>
105
106 if (OBJ_obj2nid(obj) == NID_commonName)
107 /* Do something */
108
109Create a new NID and initialize an object from it:
110
111 int new_nid;
112 ASN1_OBJECT *obj;
113 new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
114
115 obj = OBJ_nid2obj(new_nid);
116
117Create a new object directly:
118
119 obj = OBJ_txt2obj("1.2.3.4", 1);
120
121=head1 BUGS
122
123OBJ_obj2txt() is awkward and messy to use: it doesn't follow the
124convention of other OpenSSL functions where the buffer can be set
125to B<NULL> to determine the amount of data that should be written.
126Instead B<buf> must point to a valid buffer and B<buf_len> should
127be set to a positive value. A buffer length of 80 should be more
128than enough to handle any OID encountered in practice.
129
130=head1 RETURN VALUES
131
132OBJ_nid2obj() returns an B<ASN1_OBJECT> structure or B<NULL> is an
133error occurred.
134
135OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or B<NULL>
136on error.
137
138OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return
139a NID or B<NID_undef> on error.
140
141=head1 SEE ALSO
142
143L<ERR_get_error(3)|ERR_get_error(3)>
144
145=head1 HISTORY
146
147TBA
148
149=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 c39ac35e78..0000000000
--- a/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod
+++ /dev/null
@@ -1,101 +0,0 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_VERSION_NUMBER, SSLeay, SSLeay_version - 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 const char *SSLeay_version(int t);
15
16=head1 DESCRIPTION
17
18OPENSSL_VERSION_NUMBER is a numeric release version identifier:
19
20 MMNNFFPPS: major minor fix patch status
21
22The status nibble has one of the values 0 for development, 1 to e for betas
231 to 14, and f for release.
24
25for example
26
27 0x000906000 == 0.9.6 dev
28 0x000906023 == 0.9.6b beta 3
29 0x00090605f == 0.9.6e release
30
31Versions prior to 0.9.3 have identifiers E<lt> 0x0930.
32Versions between 0.9.3 and 0.9.5 had a version identifier with this
33interpretation:
34
35 MMNNFFRBB major minor fix final beta/patch
36
37for example
38
39 0x000904100 == 0.9.4 release
40 0x000905000 == 0.9.5 dev
41
42Version 0.9.5a had an interim interpretation that is like the current one,
43except the patch level got the highest bit set, to keep continuity. The
44number was therefore 0x0090581f.
45
46
47For backward compatibility, SSLEAY_VERSION_NUMBER is also defined.
48
49SSLeay() returns this number. The return value can be compared to the
50macro to make sure that the correct version of the library has been
51loaded, especially when using DLLs on Windows systems.
52
53SSLeay_version() returns different strings depending on B<t>:
54
55=over 4
56
57=item SSLEAY_VERSION
58
59The text variant of the version number and the release date. For example,
60"OpenSSL 0.9.5a 1 Apr 2000".
61
62=item SSLEAY_CFLAGS
63
64The compiler flags set for the compilation process in the form
65"compiler: ..." if available or "compiler: information not available"
66otherwise.
67
68=item SSLEAY_BUILT_ON
69
70The date of the build process in the form "built on: ..." if available
71or "built on: date not available" otherwise.
72
73=item SSLEAY_PLATFORM
74
75The "Configure" target of the library build in the form "platform: ..."
76if available or "platform: information not available" otherwise.
77
78=item SSLEAY_DIR
79
80The "OPENSSLDIR" setting of the library build in the form "OPENSSLDIR: "...""
81if available or "OPENSSLDIR: N/A" otherwise.
82
83=back
84
85For an unknown B<t>, the text "not available" is returned.
86
87=head1 RETURN VALUE
88
89The version number.
90
91=head1 SEE ALSO
92
93L<crypto(3)|crypto(3)>
94
95=head1 HISTORY
96
97SSLeay() and SSLEAY_VERSION_NUMBER are available in all versions of SSLeay and OpenSSL.
98OPENSSL_VERSION_NUMBER is available in all versions of OpenSSL.
99B<SSLEAY_DIR> was added in OpenSSL 0.9.7.
100
101=cut
diff --git a/src/lib/libcrypto/doc/OPENSSL_config.pod b/src/lib/libcrypto/doc/OPENSSL_config.pod
deleted file mode 100644
index e7bba2aaca..0000000000
--- a/src/lib/libcrypto/doc/OPENSSL_config.pod
+++ /dev/null
@@ -1,82 +0,0 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_config, OPENSSL_no_config - simple OpenSSL configuration functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/conf.h>
10
11 void OPENSSL_config(const char *config_name);
12 void OPENSSL_no_config(void);
13
14=head1 DESCRIPTION
15
16OPENSSL_config() configures OpenSSL using the standard B<openssl.cnf>
17configuration file name using B<config_name>. If B<config_name> is NULL then
18the default name B<openssl_conf> will be used. Any errors are ignored. Further
19calls to OPENSSL_config() will have no effect. The configuration file format
20is documented in the L<conf(5)|conf(5)> manual page.
21
22OPENSSL_no_config() disables configuration. If called before OPENSSL_config()
23no configuration takes place.
24
25=head1 NOTES
26
27It is B<strongly> recommended that B<all> new applications call OPENSSL_config()
28or the more sophisticated functions such as CONF_modules_load() during
29initialization (that is before starting any threads). By doing this
30an application does not need to keep track of all configuration options
31and some new functionality can be supported automatically.
32
33It is also possible to automatically call OPENSSL_config() when an application
34calls OPENSSL_add_all_algorithms() by compiling an application with the
35preprocessor symbol B<OPENSSL_LOAD_CONF> #define'd. In this way configuration
36can be added without source changes.
37
38The environment variable B<OPENSSL_CONF> can be set to specify the location
39of the configuration file.
40
41Currently ASN1 OBJECTs and ENGINE configuration can be performed future
42versions of OpenSSL will add new configuration options.
43
44There are several reasons why calling the OpenSSL configuration routines is
45advisable. For example new ENGINE functionality was added to OpenSSL 0.9.7.
46In OpenSSL 0.9.7 control functions can be supported by ENGINEs, this can be
47used (among other things) to load dynamic ENGINEs from shared libraries (DSOs).
48However very few applications currently support the control interface and so
49very few can load and use dynamic ENGINEs. Equally in future more sophisticated
50ENGINEs will require certain control operations to customize them. If an
51application calls OPENSSL_config() it doesn't need to know or care about
52ENGINE control operations because they can be performed by editing a
53configuration file.
54
55Applications should free up configuration at application closedown by calling
56CONF_modules_free().
57
58=head1 RESTRICTIONS
59
60The OPENSSL_config() function is designed to be a very simple "call it and
61forget it" function. As a result its behaviour is somewhat limited. It ignores
62all errors silently and it can only load from the standard configuration file
63location for example.
64
65It is however B<much> better than nothing. Applications which need finer
66control over their configuration functionality should use the configuration
67functions such as CONF_load_modules() directly.
68
69=head1 RETURN VALUES
70
71Neither OPENSSL_config() nor OPENSSL_no_config() return a value.
72
73=head1 SEE ALSO
74
75L<conf(5)|conf(5)>, L<CONF_load_modules_file(3)|CONF_load_modules_file(3)>,
76L<CONF_modules_free(3),CONF_modules_free(3)>
77
78=head1 HISTORY
79
80OPENSSL_config() and OPENSSL_no_config() first appeared in OpenSSL 0.9.7
81
82=cut
diff --git a/src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod b/src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod
deleted file mode 100644
index f14dfaf005..0000000000
--- a/src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod
+++ /dev/null
@@ -1,51 +0,0 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_load_builtin_modules - add standard configuration modules
6
7=head1 SYNOPSIS
8
9 #include <openssl/conf.h>
10
11 void OPENSSL_load_builtin_modules(void);
12 void ASN1_add_oid_module(void);
13 ENGINE_add_conf_module();
14
15=head1 DESCRIPTION
16
17The function OPENSSL_load_builtin_modules() adds all the standard OpenSSL
18configuration modules to the internal list. They can then be used by the
19OpenSSL configuration code.
20
21ASN1_add_oid_module() adds just the ASN1 OBJECT module.
22
23ENGINE_add_conf_module() adds just the ENGINE configuration module.
24
25=head1 NOTES
26
27If the simple configuration function OPENSSL_config() is called then
28OPENSSL_load_builtin_modules() is called automatically.
29
30Applications which use the configuration functions directly will need to
31call OPENSSL_load_builtin_modules() themselves I<before> any other
32configuration code.
33
34Applications should call OPENSSL_load_builtin_modules() to load all
35configuration modules instead of adding modules selectively: otherwise
36functionality may be missing from the application if an when new
37modules are added.
38
39=head1 RETURN VALUE
40
41None of the functions return a value.
42
43=head1 SEE ALSO
44
45L<conf(3)|conf(3)>, L<OPENSSL_config(3)|OPENSSL_config(3)>
46
47=head1 HISTORY
48
49These functions first appeared in OpenSSL 0.9.7.
50
51=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 e63411b5bb..0000000000
--- a/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod
+++ /dev/null
@@ -1,66 +0,0 @@
1=pod
2
3=head1 NAME
4
5OpenSSL_add_all_algorithms, OpenSSL_add_all_ciphers, OpenSSL_add_all_digests -
6add algorithms to internal table
7
8=head1 SYNOPSIS
9
10 #include <openssl/evp.h>
11
12 void OpenSSL_add_all_algorithms(void);
13 void OpenSSL_add_all_ciphers(void);
14 void OpenSSL_add_all_digests(void);
15
16 void EVP_cleanup(void);
17
18=head1 DESCRIPTION
19
20OpenSSL keeps an internal table of digest algorithms and ciphers. It uses
21this table to lookup ciphers via functions such as EVP_get_cipher_byname().
22
23OpenSSL_add_all_digests() adds all digest algorithms to the table.
24
25OpenSSL_add_all_algorithms() adds all algorithms to the table (digests and
26ciphers).
27
28OpenSSL_add_all_ciphers() adds all encryption algorithms to the table including
29password based encryption algorithms.
30
31EVP_cleanup() removes all ciphers and digests from the table.
32
33=head1 RETURN VALUES
34
35None of the functions return a value.
36
37=head1 NOTES
38
39A typical application will call OpenSSL_add_all_algorithms() initially and
40EVP_cleanup() before exiting.
41
42An application does not need to add algorithms to use them explicitly, for example
43by EVP_sha1(). It just needs to add them if it (or any of the functions it calls)
44needs to lookup algorithms.
45
46The cipher and digest lookup functions are used in many parts of the library. If
47the table is not initialized several functions will misbehave and complain they
48cannot find algorithms. This includes the PEM, PKCS#12, SSL and S/MIME libraries.
49This is a common query in the OpenSSL mailing lists.
50
51Calling OpenSSL_add_all_algorithms() links in all algorithms: as a result a
52statically linked executable can be quite large. If this is important it is possible
53to just add the required ciphers and digests.
54
55=head1 BUGS
56
57Although the functions do not return error codes it is possible for them to fail.
58This will only happen as a result of a memory allocation failure so this is not
59too much of a problem in practice.
60
61=head1 SEE ALSO
62
63L<evp(3)|evp(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
64L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
65
66=cut
diff --git a/src/lib/libcrypto/doc/PKCS12_create.pod b/src/lib/libcrypto/doc/PKCS12_create.pod
deleted file mode 100644
index 48f3bb8cb8..0000000000
--- a/src/lib/libcrypto/doc/PKCS12_create.pod
+++ /dev/null
@@ -1,57 +0,0 @@
1=pod
2
3=head1 NAME
4
5PKCS12_create - create a PKCS#12 structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/pkcs12.h>
10
11 PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, STACK_OF(X509) *ca,
12 int nid_key, int nid_cert, int iter, int mac_iter, int keytype);
13
14=head1 DESCRIPTION
15
16PKCS12_create() creates a PKCS#12 structure.
17
18B<pass> is the passphrase to use. B<name> is the B<friendlyName> to use for
19the supplied certifictate and key. B<pkey> is the private key to include in
20the structure and B<cert> its corresponding certificates. B<ca>, if not B<NULL>
21is an optional set of certificates to also include in the structure.
22
23B<nid_key> and B<nid_cert> are the encryption algorithms that should be used
24for the key and certificate respectively. B<iter> is the encryption algorithm
25iteration count to use and B<mac_iter> is the MAC iteration count to use.
26B<keytype> is the type of key.
27
28=head1 NOTES
29
30The parameters B<nid_key>, B<nid_cert>, B<iter>, B<mac_iter> and B<keytype>
31can all be set to zero and sensible defaults will be used.
32
33These defaults are: 40 bit RC2 encryption for certificates, triple DES
34encryption for private keys, a key iteration count of PKCS12_DEFAULT_ITER
35(currently 2048) and a MAC iteration count of 1.
36
37The default MAC iteration count is 1 in order to retain compatibility with
38old software which did not interpret MAC iteration counts. If such compatibility
39is not required then B<mac_iter> should be set to PKCS12_DEFAULT_ITER.
40
41B<keytype> adds a flag to the store private key. This is a non standard extension
42that is only currently interpreted by MSIE. If set to zero the flag is omitted,
43if set to B<KEY_SIG> the key can be used for signing only, if set to B<KEY_EX>
44it can be used for signing and encryption. This option was useful for old
45export grade software which could use signing only keys of arbitrary size but
46had restrictions on the permissible sizes of keys which could be used for
47encryption.
48
49=head1 SEE ALSO
50
51L<d2i_PKCS12(3)|d2i_PKCS12(3)>
52
53=head1 HISTORY
54
55PKCS12_create was added in OpenSSL 0.9.3
56
57=cut
diff --git a/src/lib/libcrypto/doc/PKCS12_parse.pod b/src/lib/libcrypto/doc/PKCS12_parse.pod
deleted file mode 100644
index 51344f883a..0000000000
--- a/src/lib/libcrypto/doc/PKCS12_parse.pod
+++ /dev/null
@@ -1,50 +0,0 @@
1=pod
2
3=head1 NAME
4
5PKCS12_parse - parse a PKCS#12 structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/pkcs12.h>
10
11int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca);
12
13=head1 DESCRIPTION
14
15PKCS12_parse() parses a PKCS12 structure.
16
17B<p12> is the B<PKCS12> structure to parse. B<pass> is the passphrase to use.
18If successful the private key will be written to B<*pkey>, the corresponding
19certificate to B<*cert> and any additional certificates to B<*ca>.
20
21=head1 NOTES
22
23The parameters B<pkey> and B<cert> cannot be B<NULL>. B<ca> can be <NULL>
24in which case additional certificates will be discarded. B<*ca> can also
25be a valid STACK in which case additional certificates are appended to
26B<*ca>. If B<*ca> is B<NULL> a new STACK will be allocated.
27
28The B<friendlyName> and B<localKeyID> attributes (if present) on each certificate
29will be stored in the B<alias> and B<keyid> attributes of the B<X509> structure.
30
31=head1 BUGS
32
33Only a single private key and corresponding certificate is returned by this function.
34More complex PKCS#12 files with multiple private keys will only return the first
35match.
36
37Only B<friendlyName> and B<localKeyID> attributes are currently stored in certificates.
38Other attributes are discarded.
39
40Attributes currently cannot be store in the private key B<EVP_PKEY> structure.
41
42=head1 SEE ALSO
43
44L<d2i_PKCS12(3)|d2i_PKCS12(3)>
45
46=head1 HISTORY
47
48PKCS12_parse was added in OpenSSL 0.9.3
49
50=cut
diff --git a/src/lib/libcrypto/doc/PKCS7_decrypt.pod b/src/lib/libcrypto/doc/PKCS7_decrypt.pod
deleted file mode 100644
index b0ca067b89..0000000000
--- a/src/lib/libcrypto/doc/PKCS7_decrypt.pod
+++ /dev/null
@@ -1,53 +0,0 @@
1=pod
2
3=head1 NAME
4
5PKCS7_decrypt - decrypt content from a PKCS#7 envelopedData structure
6
7=head1 SYNOPSIS
8
9int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
10
11=head1 DESCRIPTION
12
13PKCS7_decrypt() extracts and decrypts the content from a PKCS#7 envelopedData
14structure. B<pkey> is the private key of the recipient, B<cert> is the
15recipients certificate, B<data> is a BIO to write the content to and
16B<flags> is an optional set of flags.
17
18=head1 NOTES
19
20OpenSSL_add_all_algorithms() (or equivalent) should be called before using this
21function or errors about unknown algorithms will occur.
22
23Although the recipients certificate is not needed to decrypt the data it is needed
24to locate the appropriate (of possible several) recipients in the PKCS#7 structure.
25
26The following flags can be passed in the B<flags> parameter.
27
28If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted
29from the content. If the content is not of type B<text/plain> then an error is
30returned.
31
32=head1 RETURN VALUES
33
34PKCS7_decrypt() returns either 1 for success or 0 for failure.
35The error can be obtained from ERR_get_error(3)
36
37=head1 BUGS
38
39PKCS7_decrypt() must be passed the correct recipient key and certificate. It would
40be better if it could look up the correct key and certificate from a database.
41
42The lack of single pass processing and need to hold all data in memory as
43mentioned in PKCS7_sign() also applies to PKCS7_verify().
44
45=head1 SEE ALSO
46
47L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
48
49=head1 HISTORY
50
51PKCS7_decrypt() was added to OpenSSL 0.9.5
52
53=cut
diff --git a/src/lib/libcrypto/doc/PKCS7_encrypt.pod b/src/lib/libcrypto/doc/PKCS7_encrypt.pod
deleted file mode 100644
index 1a507b22a2..0000000000
--- a/src/lib/libcrypto/doc/PKCS7_encrypt.pod
+++ /dev/null
@@ -1,65 +0,0 @@
1=pod
2
3=head1 NAME
4
5PKCS7_encrypt - create a PKCS#7 envelopedData structure
6
7=head1 SYNOPSIS
8
9PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, int flags);
10
11=head1 DESCRIPTION
12
13PKCS7_encrypt() creates and returns a PKCS#7 envelopedData structure. B<certs>
14is a list of recipient certificates. B<in> is the content to be encrypted.
15B<cipher> is the symmetric cipher to use. B<flags> is an optional set of flags.
16
17=head1 NOTES
18
19Only RSA keys are supported in PKCS#7 and envelopedData so the recipient certificates
20supplied to this function must all contain RSA public keys, though they do not have to
21be signed using the RSA algorithm.
22
23EVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use because
24most clients will support it.
25
26Some old "export grade" clients may only support weak encryption using 40 or 64 bit
27RC2. These can be used by passing EVP_rc2_40_cbc() and EVP_rc2_64_cbc() respectively.
28
29The algorithm passed in the B<cipher> parameter must support ASN1 encoding of its
30parameters.
31
32Many browsers implement a "sign and encrypt" option which is simply an S/MIME
33envelopedData containing an S/MIME signed message. This can be readily produced
34by storing the S/MIME signed message in a memory BIO and passing it to
35PKCS7_encrypt().
36
37The following flags can be passed in the B<flags> parameter.
38
39If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are prepended
40to the data.
41
42Normally the supplied content is translated into MIME canonical format (as required
43by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation occurs. This
44option should be used if the supplied data is in binary format otherwise the translation
45will corrupt it. If B<PKCS7_BINARY> is set then B<PKCS7_TEXT> is ignored.
46
47=head1 RETURN VALUES
48
49PKCS7_encrypt() returns either a valid PKCS7 structure or NULL if an error occurred.
50The error can be obtained from ERR_get_error(3).
51
52=head1 BUGS
53
54The lack of single pass processing and need to hold all data in memory as
55mentioned in PKCS7_sign() also applies to PKCS7_verify().
56
57=head1 SEE ALSO
58
59L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
60
61=head1 HISTORY
62
63PKCS7_decrypt() was added to OpenSSL 0.9.5
64
65=cut
diff --git a/src/lib/libcrypto/doc/PKCS7_sign.pod b/src/lib/libcrypto/doc/PKCS7_sign.pod
deleted file mode 100644
index fc7e649b34..0000000000
--- a/src/lib/libcrypto/doc/PKCS7_sign.pod
+++ /dev/null
@@ -1,85 +0,0 @@
1=pod
2
3=head1 NAME
4
5PKCS7_sign - create a PKCS#7 signedData structure
6
7=head1 SYNOPSIS
8
9PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags);
10
11=head1 DESCRIPTION
12
13PKCS7_sign() creates and returns a PKCS#7 signedData structure. B<signcert>
14is the certificate to sign with, B<pkey> is the corresponsding private key.
15B<certs> is an optional additional set of certificates to include in the
16PKCS#7 structure (for example any intermediate CAs in the chain).
17
18The data to be signed is read from BIO B<data>.
19
20B<flags> is an optional set of flags.
21
22=head1 NOTES
23
24Any of the following flags (ored together) can be passed in the B<flags> parameter.
25
26Many S/MIME clients expect the signed content to include valid MIME headers. If
27the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are prepended
28to the data.
29
30If B<PKCS7_NOCERTS> is set the signer's certificate will not be included in the
31PKCS7 structure, the signer's certificate must still be supplied in the B<signcert>
32parameter though. This can reduce the size of the signature if the signers certificate
33can be obtained by other means: for example a previously signed message.
34
35The data being signed is included in the PKCS7 structure, unless B<PKCS7_DETACHED>
36is set in which case it is omitted. This is used for PKCS7 detached signatures
37which are used in S/MIME plaintext signed messages for example.
38
39Normally the supplied content is translated into MIME canonical format (as required
40by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation occurs. This
41option should be used if the supplied data is in binary format otherwise the translation
42will corrupt it.
43
44The signedData structure includes several PKCS#7 autenticatedAttributes including
45the signing time, the PKCS#7 content type and the supported list of ciphers in
46an SMIMECapabilities attribute. If B<PKCS7_NOATTR> is set then no authenticatedAttributes
47will be used. If B<PKCS7_NOSMIMECAP> is set then just the SMIMECapabilities are
48omitted.
49
50If present the SMIMECapabilities attribute indicates support for the following
51algorithms: triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any
52of these algorithms is disabled then it will not be included.
53
54=head1 BUGS
55
56PKCS7_sign() is somewhat limited. It does not support multiple signers, some
57advanced attributes such as counter signatures are not supported.
58
59The SHA1 digest algorithm is currently always used.
60
61When the signed data is not detached it will be stored in memory within the
62B<PKCS7> structure. This effectively limits the size of messages which can be
63signed due to memory restraints. There should be a way to sign data without
64having to hold it all in memory, this would however require fairly major
65revisions of the OpenSSL ASN1 code.
66
67Clear text signing does not store the content in memory but the way PKCS7_sign()
68operates means that two passes of the data must typically be made: one to compute
69the signatures and a second to output the data along with the signature. There
70should be a way to process the data with only a single pass.
71
72=head1 RETURN VALUES
73
74PKCS7_sign() returns either a valid PKCS7 structure or NULL if an error occurred.
75The error can be obtained from ERR_get_error(3).
76
77=head1 SEE ALSO
78
79L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_verify(3)|PKCS7_verify(3)>
80
81=head1 HISTORY
82
83PKCS7_sign() was added to OpenSSL 0.9.5
84
85=cut
diff --git a/src/lib/libcrypto/doc/PKCS7_verify.pod b/src/lib/libcrypto/doc/PKCS7_verify.pod
deleted file mode 100644
index 3490b5dc82..0000000000
--- a/src/lib/libcrypto/doc/PKCS7_verify.pod
+++ /dev/null
@@ -1,116 +0,0 @@
1=pod
2
3=head1 NAME
4
5PKCS7_verify - verify a PKCS#7 signedData structure
6
7=head1 SYNOPSIS
8
9int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata, BIO *out, int flags);
10
11STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
12
13=head1 DESCRIPTION
14
15PKCS7_verify() verifies a PKCS#7 signedData structure. B<p7> is the PKCS7
16structure to verify. B<certs> is a set of certificates in which to search for
17the signer's certificate. B<store> is a trusted certficate store (used for
18chain verification). B<indata> is the signed data if the content is not
19present in B<p7> (that is it is detached). The content is written to B<out>
20if it is not NULL.
21
22B<flags> is an optional set of flags, which can be used to modify the verify
23operation.
24
25PKCS7_get0_signers() retrieves the signer's certificates from B<p7>, it does
26B<not> check their validity or whether any signatures are valid. The B<certs>
27and B<flags> parameters have the same meanings as in PKCS7_verify().
28
29=head1 VERIFY PROCESS
30
31Normally the verify process proceeds as follows.
32
33Initially some sanity checks are performed on B<p7>. The type of B<p7> must
34be signedData. There must be at least one signature on the data and if
35the content is detached B<indata> cannot be B<NULL>.
36
37An attempt is made to locate all the signer's certificates, first looking in
38the B<certs> parameter (if it is not B<NULL>) and then looking in any certificates
39contained in the B<p7> structure itself. If any signer's certificates cannot be
40located the operation fails.
41
42Each signer's certificate is chain verified using the B<smimesign> purpose and
43the supplied trusted certificate store. Any internal certificates in the message
44are used as untrusted CAs. If any chain verify fails an error code is returned.
45
46Finally the signed content is read (and written to B<out> is it is not NULL) and
47the signature's checked.
48
49If all signature's verify correctly then the function is successful.
50
51Any of the following flags (ored together) can be passed in the B<flags> parameter
52to change the default verify behaviour. Only the flag B<PKCS7_NOINTERN> is
53meaningful to PKCS7_get0_signers().
54
55If B<PKCS7_NOINTERN> is set the certificates in the message itself are not
56searched when locating the signer's certificate. This means that all the signers
57certificates must be in the B<certs> parameter.
58
59If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted
60from the content. If the content is not of type B<text/plain> then an error is
61returned.
62
63If B<PKCS7_NOVERIFY> is set the signer's certificates are not chain verified.
64
65If B<PKCS7_NOCHAIN> is set then the certificates contained in the message are
66not used as untrusted CAs. This means that the whole verify chain (apart from
67the signer's certificate) must be contained in the trusted store.
68
69If B<PKCS7_NOSIGS> is set then the signatures on the data are not checked.
70
71=head1 NOTES
72
73One application of B<PKCS7_NOINTERN> is to only accept messages signed by
74a small number of certificates. The acceptable certificates would be passed
75in the B<certs> parameter. In this case if the signer is not one of the
76certificates supplied in B<certs> then the verify will fail because the
77signer cannot be found.
78
79Care should be taken when modifying the default verify behaviour, for example
80setting B<PKCS7_NOVERIFY|PKCS7_NOSIGS> will totally disable all verification
81and any signed message will be considered valid. This combination is however
82useful if one merely wishes to write the content to B<out> and its validity
83is not considered important.
84
85Chain verification should arguably be performed using the signing time rather
86than the current time. However since the signing time is supplied by the
87signer it cannot be trusted without additional evidence (such as a trusted
88timestamp).
89
90=head1 RETURN VALUES
91
92PKCS7_verify() returns 1 for a successful verification and zero or a negative
93value if an error occurs.
94
95PKCS7_get0_signers() returns all signers or B<NULL> if an error occurred.
96
97The error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>
98
99=head1 BUGS
100
101The trusted certificate store is not searched for the signers certificate,
102this is primarily due to the inadequacies of the current B<X509_STORE>
103functionality.
104
105The lack of single pass processing and need to hold all data in memory as
106mentioned in PKCS7_sign() also applies to PKCS7_verify().
107
108=head1 SEE ALSO
109
110L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>
111
112=head1 HISTORY
113
114PKCS7_verify() was added to OpenSSL 0.9.5
115
116=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 ce6329ce54..0000000000
--- a/src/lib/libcrypto/doc/RAND_bytes.pod
+++ /dev/null
@@ -1,47 +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)>,
39L<RAND_add(3)|RAND_add(3)>
40
41=head1 HISTORY
42
43RAND_bytes() is available in all versions of SSLeay and OpenSSL. It
44has a return value since OpenSSL 0.9.5. RAND_pseudo_bytes() was added
45in OpenSSL 0.9.5.
46
47=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 d8c134e621..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, size_t 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 c9bb6d9f27..0000000000
--- a/src/lib/libcrypto/doc/RAND_set_rand_method.pod
+++ /dev/null
@@ -1,83 +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(const RAND_METHOD *meth);
12
13 const 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 number
20generation. By modifying the method, alternative implementations such as
21hardware RNGs may be used. IMPORTANT: See the NOTES section for important
22information about how these RAND API functions are affected by the use of
23B<ENGINE> API calls.
24
25Initially, the default RAND_METHOD is the OpenSSL internal implementation, as
26returned by RAND_SSLeay().
27
28RAND_set_default_method() makes B<meth> the method for PRNG use. B<NB>: This is
29true only whilst no ENGINE has been set as a default for RAND, so this function
30is no longer recommended.
31
32RAND_get_default_method() returns a pointer to the current RAND_METHOD.
33However, the meaningfulness of this result is dependant on whether the ENGINE
34API is being used, so this function is no longer recommended.
35
36=head1 THE RAND_METHOD STRUCTURE
37
38 typedef struct rand_meth_st
39 {
40 void (*seed)(const void *buf, int num);
41 int (*bytes)(unsigned char *buf, int num);
42 void (*cleanup)(void);
43 void (*add)(const void *buf, int num, int entropy);
44 int (*pseudorand)(unsigned char *buf, int num);
45 int (*status)(void);
46 } RAND_METHOD;
47
48The components point to the implementation of RAND_seed(),
49RAND_bytes(), RAND_cleanup(), RAND_add(), RAND_pseudo_rand()
50and RAND_status().
51Each component may be NULL if the function is not implemented.
52
53=head1 RETURN VALUES
54
55RAND_set_rand_method() returns no value. RAND_get_rand_method() and
56RAND_SSLeay() return pointers to the respective methods.
57
58=head1 NOTES
59
60As of version 0.9.7, RAND_METHOD implementations are grouped together with other
61algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a
62default ENGINE is specified for RAND functionality using an ENGINE API function,
63that will override any RAND defaults set using the RAND API (ie.
64RAND_set_rand_method()). For this reason, the ENGINE API is the recommended way
65to control default implementations for use in RAND and other cryptographic
66algorithms.
67
68=head1 SEE ALSO
69
70L<rand(3)|rand(3)>, L<engine(3)|engine(3)>
71
72=head1 HISTORY
73
74RAND_set_rand_method(), RAND_get_rand_method() and RAND_SSLeay() are
75available in all versions of OpenSSL.
76
77In the engine version of version 0.9.6, RAND_set_rand_method() was altered to
78take an ENGINE pointer as its argument. As of version 0.9.7, that has been
79reverted as the ENGINE API transparently overrides RAND defaults if used,
80otherwise RAND API functions work as before. RAND_set_rand_engine() was also
81introduced in version 0.9.7.
82
83=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 a5198f3db5..0000000000
--- a/src/lib/libcrypto/doc/RSA_check_key.pod
+++ /dev/null
@@ -1,67 +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
21As such, this function can not be used with any arbitrary RSA key object,
22even if it is otherwise fit for regular RSA operation. See B<NOTES> for more
23information.
24
25=head1 RETURN VALUE
26
27RSA_check_key() returns 1 if B<rsa> is a valid RSA key, and 0 otherwise.
28-1 is returned if an error occurs while checking the key.
29
30If the key is invalid or an error occurred, the reason code can be
31obtained using L<ERR_get_error(3)|ERR_get_error(3)>.
32
33=head1 NOTES
34
35This function does not work on RSA public keys that have only the modulus
36and public exponent elements populated. It performs integrity checks on all
37the RSA key material, so the RSA key structure must contain all the private
38key data too.
39
40Unlike most other RSA functions, this function does B<not> work
41transparently with any underlying ENGINE implementation because it uses the
42key data in the RSA structure directly. An ENGINE implementation can
43override the way key data is stored and handled, and can even provide
44support for HSM keys - in which case the RSA structure may contain B<no>
45key data at all! If the ENGINE in question is only being used for
46acceleration or analysis purposes, then in all likelihood the RSA key data
47is complete and untouched, but this can't be assumed in the general case.
48
49=head1 BUGS
50
51A method of verifying the RSA key using opaque RSA API functions might need
52to be considered. Right now RSA_check_key() simply uses the RSA structure
53elements directly, bypassing the RSA_METHOD table altogether (and
54completely violating encapsulation and object-orientation in the process).
55The best fix will probably be to introduce a "check_key()" handler to the
56RSA_METHOD function table so that alternative implementations can also
57provide their own verifiers.
58
59=head1 SEE ALSO
60
61L<rsa(3)|rsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
62
63=head1 HISTORY
64
65RSA_check_key() appeared in OpenSSL 0.9.4.
66
67=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 52dbb14a53..0000000000
--- a/src/lib/libcrypto/doc/RSA_generate_key.pod
+++ /dev/null
@@ -1,69 +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, 17 or 65537.
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)>,
63L<RSA_free(3)|RSA_free(3)>
64
65=head1 HISTORY
66
67The B<cb_arg> argument was added in SSLeay 0.9.0.
68
69=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 46cc8f5359..0000000000
--- a/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
+++ /dev/null
@@ -1,120 +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 typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22 typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
23 int idx, long argl, void *argp);
24 typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
25 int idx, long argl, void *argp);
26
27=head1 DESCRIPTION
28
29Several OpenSSL structures can have application specific data attached to them.
30This has several potential uses, it can be used to cache data associated with
31a structure (for example the hash of some part of the structure) or some
32additional data (for example a handle to the data in an external library).
33
34Since the application data can be anything at all it is passed and retrieved
35as a B<void *> type.
36
37The B<RSA_get_ex_new_index()> function is initially called to "register" some
38new application specific data. It takes three optional function pointers which
39are called when the parent structure (in this case an RSA structure) is
40initially created, when it is copied and when it is freed up. If any or all of
41these function pointer arguments are not used they should be set to NULL. The
42precise manner in which these function pointers are called is described in more
43detail below. B<RSA_get_ex_new_index()> also takes additional long and pointer
44parameters which will be passed to the supplied functions but which otherwise
45have no special meaning. It returns an B<index> which should be stored
46(typically in a static variable) and passed used in the B<idx> parameter in
47the remaining functions. Each successful call to B<RSA_get_ex_new_index()>
48will return an index greater than any previously returned, this is important
49because the optional functions are called in order of increasing index value.
50
51B<RSA_set_ex_data()> is used to set application specific data, the data is
52supplied in the B<arg> parameter and its precise meaning is up to the
53application.
54
55B<RSA_get_ex_data()> is used to retrieve application specific data. The data
56is returned to the application, this will be the same value as supplied to
57a previous B<RSA_set_ex_data()> call.
58
59B<new_func()> is called when a structure is initially allocated (for example
60with B<RSA_new()>. The parent structure members will not have any meaningful
61values at this point. This function will typically be used to allocate any
62application specific structure.
63
64B<free_func()> is called when a structure is being freed up. The dynamic parent
65structure members should not be accessed because they will be freed up when
66this function is called.
67
68B<new_func()> and B<free_func()> take the same parameters. B<parent> is a
69pointer to the parent RSA structure. B<ptr> is a the application specific data
70(this wont be of much use in B<new_func()>. B<ad> is a pointer to the
71B<CRYPTO_EX_DATA> structure from the parent RSA structure: the functions
72B<CRYPTO_get_ex_data()> and B<CRYPTO_set_ex_data()> can be called to manipulate
73it. The B<idx> parameter is the index: this will be the same value returned by
74B<RSA_get_ex_new_index()> when the functions were initially registered. Finally
75the B<argl> and B<argp> parameters are the values originally passed to the same
76corresponding parameters when B<RSA_get_ex_new_index()> was called.
77
78B<dup_func()> is called when a structure is being copied. Pointers to the
79destination and source B<CRYPTO_EX_DATA> structures are passed in the B<to> and
80B<from> parameters respectively. The B<from_d> parameter is passed a pointer to
81the source application data when the function is called, when the function returns
82the value is copied to the destination: the application can thus modify the data
83pointed to by B<from_d> and have different values in the source and destination.
84The B<idx>, B<argl> and B<argp> parameters are the same as those in B<new_func()>
85and B<free_func()>.
86
87=head1 RETURN VALUES
88
89B<RSA_get_ex_new_index()> returns a new index or -1 on failure (note 0 is a valid
90index value).
91
92B<RSA_set_ex_data()> returns 1 on success or 0 on failure.
93
94B<RSA_get_ex_data()> returns the application data or 0 on failure. 0 may also
95be valid application data but currently it can only fail if given an invalid B<idx>
96parameter.
97
98B<new_func()> and B<dup_func()> should return 0 for failure and 1 for success.
99
100On failure an error code can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
101
102=head1 BUGS
103
104B<dup_func()> is currently never called.
105
106The return value of B<new_func()> is ignored.
107
108The B<new_func()> function isn't very useful because no meaningful values are
109present in the parent RSA structure when it is called.
110
111=head1 SEE ALSO
112
113L<rsa(3)|rsa(3)>, L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
114
115=head1 HISTORY
116
117RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data() are
118available since SSLeay 0.9.0.
119
120=cut
diff --git a/src/lib/libcrypto/doc/RSA_new.pod b/src/lib/libcrypto/doc/RSA_new.pod
deleted file mode 100644
index 3d15b92824..0000000000
--- a/src/lib/libcrypto/doc/RSA_new.pod
+++ /dev/null
@@ -1,41 +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. It is equivalent to
18calling RSA_new_method(NULL).
19
20RSA_free() frees the B<RSA> structure and its components. The key is
21erased before the memory is returned to the system.
22
23=head1 RETURN VALUES
24
25If the allocation fails, RSA_new() returns B<NULL> and sets an error
26code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
27a pointer to the newly allocated structure.
28
29RSA_free() returns no value.
30
31=head1 SEE ALSO
32
33L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>,
34L<RSA_generate_key(3)|RSA_generate_key(3)>,
35L<RSA_new_method(3)|RSA_new_method(3)>
36
37=head1 HISTORY
38
39RSA_new() and RSA_free() are available in all versions of SSLeay and OpenSSL.
40
41=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 c971e91f4d..0000000000
--- a/src/lib/libcrypto/doc/RSA_print.pod
+++ /dev/null
@@ -1,49 +0,0 @@
1=pod
2
3=head1 NAME
4
5RSA_print, RSA_print_fp,
6DSAparams_print, DSAparams_print_fp, DSA_print, DSA_print_fp,
7DHparams_print, DHparams_print_fp - print cryptographic parameters
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12
13 int RSA_print(BIO *bp, RSA *x, int offset);
14 int RSA_print_fp(FILE *fp, RSA *x, int offset);
15
16 #include <openssl/dsa.h>
17
18 int DSAparams_print(BIO *bp, DSA *x);
19 int DSAparams_print_fp(FILE *fp, DSA *x);
20 int DSA_print(BIO *bp, DSA *x, int offset);
21 int DSA_print_fp(FILE *fp, DSA *x, int offset);
22
23 #include <openssl/dh.h>
24
25 int DHparams_print(BIO *bp, DH *x);
26 int DHparams_print_fp(FILE *fp, DH *x);
27
28=head1 DESCRIPTION
29
30A human-readable hexadecimal output of the components of the RSA
31key, DSA parameters or key or DH parameters is printed to B<bp> or B<fp>.
32
33The output lines are indented by B<offset> spaces.
34
35=head1 RETURN VALUES
36
37These functions return 1 on success, 0 on error.
38
39=head1 SEE ALSO
40
41L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<rsa(3)|rsa(3)>, L<BN_bn2bin(3)|BN_bn2bin(3)>
42
43=head1 HISTORY
44
45RSA_print(), RSA_print_fp(), DSA_print(), DSA_print_fp(), DH_print(),
46DH_print_fp() are available in all versions of SSLeay and OpenSSL.
47DSAparams_print() and DSAparams_print_fp() were added in SSLeay 0.8.
48
49=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 746a80c79e..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)>,
63L<RSA_sign(3)|RSA_sign(3)>, L<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 ab0fe3b2cd..0000000000
--- a/src/lib/libcrypto/doc/RSA_public_encrypt.pod
+++ /dev/null
@@ -1,84 +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, less than RSA_size(B<rsa>) - 41 for
51RSA_PKCS1_OAEP_PADDING and exactly RSA_size(B<rsa>) for RSA_NO_PADDING.
52The random number generator must be seeded prior to calling
53RSA_public_encrypt().
54
55RSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the
56private key B<rsa> and stores the plaintext in B<to>. B<to> must point
57to a memory section large enough to hold the decrypted data (which is
58smaller than RSA_size(B<rsa>)). B<padding> is the padding mode that
59was used to encrypt the data.
60
61=head1 RETURN VALUES
62
63RSA_public_encrypt() returns the size of the encrypted data (i.e.,
64RSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the
65recovered plaintext.
66
67On error, -1 is returned; the error codes can be
68obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
69
70=head1 CONFORMING TO
71
72SSL, PKCS #1 v2.0
73
74=head1 SEE ALSO
75
76L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
77L<RSA_size(3)|RSA_size(3)>
78
79=head1 HISTORY
80
81The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
82available since SSLeay 0.9.0, OAEP was added in OpenSSL 0.9.2b.
83
84=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 0a305f6b14..0000000000
--- a/src/lib/libcrypto/doc/RSA_set_method.pod
+++ /dev/null
@@ -1,202 +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_null_method, RSA_flags,
7RSA_new_method - select RSA method
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12
13 void RSA_set_default_method(const RSA_METHOD *meth);
14
15 RSA_METHOD *RSA_get_default_method(void);
16
17 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
18
19 RSA_METHOD *RSA_get_method(const RSA *rsa);
20
21 RSA_METHOD *RSA_PKCS1_SSLeay(void);
22
23 RSA_METHOD *RSA_null_method(void);
24
25 int RSA_flags(const RSA *rsa);
26
27 RSA *RSA_new_method(RSA_METHOD *method);
28
29=head1 DESCRIPTION
30
31An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
32operations. By modifying the method, alternative implementations such as
33hardware accelerators may be used. IMPORTANT: See the NOTES section for
34important information about how these RSA API functions are affected by the
35use of B<ENGINE> API calls.
36
37Initially, the default RSA_METHOD is the OpenSSL internal implementation,
38as returned by RSA_PKCS1_SSLeay().
39
40RSA_set_default_method() makes B<meth> the default method for all RSA
41structures created later. B<NB>: This is true only whilst no ENGINE has
42been set as a default for RSA, so this function is no longer recommended.
43
44RSA_get_default_method() returns a pointer to the current default
45RSA_METHOD. However, the meaningfulness of this result is dependant on
46whether the ENGINE API is being used, so this function is no longer
47recommended.
48
49RSA_set_method() selects B<meth> to perform all operations using the key
50B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
51previous method was supplied by an ENGINE, the handle to that ENGINE will
52be released during the change. It is possible to have RSA keys that only
53work with certain RSA_METHOD implementations (eg. from an ENGINE module
54that supports embedded hardware-protected keys), and in such cases
55attempting to change the RSA_METHOD for the key can have unexpected
56results.
57
58RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
59This method may or may not be supplied by an ENGINE implementation, but if
60it is, the return value can only be guaranteed to be valid as long as the
61RSA key itself is valid and does not have its implementation changed by
62RSA_set_method().
63
64RSA_flags() returns the B<flags> that are set for B<rsa>'s current
65RSA_METHOD. See the BUGS section.
66
67RSA_new_method() allocates and initializes an RSA structure so that
68B<engine> will be used for the RSA operations. If B<engine> is NULL, the
69default ENGINE for RSA operations is used, and if no default ENGINE is set,
70the RSA_METHOD controlled by RSA_set_default_method() is used.
71
72RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
73
74RSA_new_method() allocates and initializes an B<RSA> structure so that
75B<method> will be used for the RSA operations. If B<method> is B<NULL>,
76the default method is used.
77
78=head1 THE RSA_METHOD STRUCTURE
79
80 typedef struct rsa_meth_st
81 {
82 /* name of the implementation */
83 const char *name;
84
85 /* encrypt */
86 int (*rsa_pub_enc)(int flen, unsigned char *from,
87 unsigned char *to, RSA *rsa, int padding);
88
89 /* verify arbitrary data */
90 int (*rsa_pub_dec)(int flen, unsigned char *from,
91 unsigned char *to, RSA *rsa, int padding);
92
93 /* sign arbitrary data */
94 int (*rsa_priv_enc)(int flen, unsigned char *from,
95 unsigned char *to, RSA *rsa, int padding);
96
97 /* decrypt */
98 int (*rsa_priv_dec)(int flen, unsigned char *from,
99 unsigned char *to, RSA *rsa, int padding);
100
101 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
102 implementations) */
103 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
104
105 /* compute r = a ^ p mod m (May be NULL for some implementations) */
106 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
107 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
108
109 /* called at RSA_new */
110 int (*init)(RSA *rsa);
111
112 /* called at RSA_free */
113 int (*finish)(RSA *rsa);
114
115 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
116 * operations, even if p,q,dmp1,dmq1,iqmp
117 * are NULL
118 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
119 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
120 */
121 int flags;
122
123 char *app_data; /* ?? */
124
125 /* sign. For backward compatibility, this is used only
126 * if (flags & RSA_FLAG_SIGN_VER)
127 */
128 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
129 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
130
131 /* verify. For backward compatibility, this is used only
132 * if (flags & RSA_FLAG_SIGN_VER)
133 */
134 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
135 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
136
137 } RSA_METHOD;
138
139=head1 RETURN VALUES
140
141RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method()
142and RSA_get_method() return pointers to the respective RSA_METHODs.
143
144RSA_set_default_method() returns no value.
145
146RSA_set_method() returns a pointer to the old RSA_METHOD implementation
147that was replaced. However, this return value should probably be ignored
148because if it was supplied by an ENGINE, the pointer could be invalidated
149at any time if the ENGINE is unloaded (in fact it could be unloaded as a
150result of the RSA_set_method() function releasing its handle to the
151ENGINE). For this reason, the return type may be replaced with a B<void>
152declaration in a future release.
153
154RSA_new_method() returns NULL and sets an error code that can be obtained
155by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise
156it returns a pointer to the newly allocated structure.
157
158=head1 NOTES
159
160As of version 0.9.7, RSA_METHOD implementations are grouped together with
161other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE>
162modules. If a default ENGINE is specified for RSA functionality using an
163ENGINE API function, that will override any RSA defaults set using the RSA
164API (ie. RSA_set_default_method()). For this reason, the ENGINE API is the
165recommended way to control default implementations for use in RSA and other
166cryptographic algorithms.
167
168=head1 BUGS
169
170The behaviour of RSA_flags() is a mis-feature that is left as-is for now
171to avoid creating compatibility problems. RSA functionality, such as the
172encryption functions, are controlled by the B<flags> value in the RSA key
173itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
174(which is what this function returns). If the flags element of an RSA key
175is changed, the changes will be honoured by RSA functionality but will not
176be reflected in the return value of the RSA_flags() function - in effect
177RSA_flags() behaves more like an RSA_default_flags() function (which does
178not currently exist).
179
180=head1 SEE ALSO
181
182L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
183
184=head1 HISTORY
185
186RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
187RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
188well as the rsa_sign and rsa_verify components of RSA_METHOD were
189added in OpenSSL 0.9.4.
190
191RSA_set_default_openssl_method() and RSA_get_default_openssl_method()
192replaced RSA_set_default_method() and RSA_get_default_method()
193respectively, and RSA_set_method() and RSA_new_method() were altered to use
194B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine
195version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE
196API was restructured so that this change was reversed, and behaviour of the
197other functions resembled more closely the previous behaviour. The
198behaviour of defaults in the ENGINE API now transparently overrides the
199behaviour of defaults in the RSA API without requiring changing these
200function prototypes.
201
202=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 e70380bbfc..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)>,
51L<rand(3)|rand(3)>, L<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 5b7f835f95..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(const 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/SMIME_read_PKCS7.pod b/src/lib/libcrypto/doc/SMIME_read_PKCS7.pod
deleted file mode 100644
index ffafa37887..0000000000
--- a/src/lib/libcrypto/doc/SMIME_read_PKCS7.pod
+++ /dev/null
@@ -1,71 +0,0 @@
1=pod
2
3=head1 NAME
4
5SMIME_read_PKCS7 - parse S/MIME message.
6
7=head1 SYNOPSIS
8
9PKCS7 *SMIME_read_PKCS7(BIO *in, BIO **bcont);
10
11=head1 DESCRIPTION
12
13SMIME_read_PKCS7() parses a message in S/MIME format.
14
15B<in> is a BIO to read the message from.
16
17If cleartext signing is used then the content is saved in
18a memory bio which is written to B<*bcont>, otherwise
19B<*bcont> is set to B<NULL>.
20
21The parsed PKCS#7 structure is returned or B<NULL> if an
22error occurred.
23
24=head1 NOTES
25
26If B<*bcont> is not B<NULL> then the message is clear text
27signed. B<*bcont> can then be passed to PKCS7_verify() with
28the B<PKCS7_DETACHED> flag set.
29
30Otherwise the type of the returned structure can be determined
31using PKCS7_type().
32
33To support future functionality if B<bcont> is not B<NULL>
34B<*bcont> should be initialized to B<NULL>. For example:
35
36 BIO *cont = NULL;
37 PKCS7 *p7;
38
39 p7 = SMIME_read_PKCS7(in, &cont);
40
41=head1 BUGS
42
43The MIME parser used by SMIME_read_PKCS7() is somewhat primitive.
44While it will handle most S/MIME messages more complex compound
45formats may not work.
46
47The parser assumes that the PKCS7 structure is always base64
48encoded and will not handle the case where it is in binary format
49or uses quoted printable format.
50
51The use of a memory BIO to hold the signed content limits the size
52of message which can be processed due to memory restraints: a
53streaming single pass option should be available.
54
55=head1 RETURN VALUES
56
57SMIME_read_PKCS7() returns a valid B<PKCS7> structure or B<NULL>
58is an error occurred. The error can be obtained from ERR_get_error(3).
59
60=head1 SEE ALSO
61
62L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_type(3)|PKCS7_type(3)>
63L<SMIME_read_PKCS7(3)|SMIME_read_PKCS7(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
64L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
65L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
66
67=head1 HISTORY
68
69SMIME_read_PKCS7() was added to OpenSSL 0.9.5
70
71=cut
diff --git a/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod b/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod
deleted file mode 100644
index 2cfad2e049..0000000000
--- a/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod
+++ /dev/null
@@ -1,59 +0,0 @@
1=pod
2
3=head1 NAME
4
5SMIME_write_PKCS7 - convert PKCS#7 structure to S/MIME format.
6
7=head1 SYNOPSIS
8
9int SMIME_write_PKCS7(BIO *out, PKCS7 *p7, BIO *data, int flags);
10
11=head1 DESCRIPTION
12
13SMIME_write_PKCS7() adds the appropriate MIME headers to a PKCS#7
14structure to produce an S/MIME message.
15
16B<out> is the BIO to write the data to. B<p7> is the appropriate
17B<PKCS7> structure. If cleartext signing (B<multipart/signed>) is
18being used then the signed data must be supplied in the B<data>
19argument. B<flags> is an optional set of flags.
20
21=head1 NOTES
22
23The following flags can be passed in the B<flags> parameter.
24
25If B<PKCS7_DETACHED> is set then cleartext signing will be used,
26this option only makes sense for signedData where B<PKCS7_DETACHED>
27is also set when PKCS7_sign() is also called.
28
29If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain>
30are added to the content, this only makes sense if B<PKCS7_DETACHED>
31is also set.
32
33If cleartext signing is being used then the data must be read twice:
34once to compute the signature in PKCS7_sign() and once to output the
35S/MIME message.
36
37=head1 BUGS
38
39SMIME_write_PKCS7() always base64 encodes PKCS#7 structures, there
40should be an option to disable this.
41
42There should really be a way to produce cleartext signing using only
43a single pass of the data.
44
45=head1 RETURN VALUES
46
47SMIME_write_PKCS7() returns 1 for success or 0 for failure.
48
49=head1 SEE ALSO
50
51L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>,
52L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)>
53L<PKCS7_decrypt(3)|PKCS7_decrypt(3)>
54
55=head1 HISTORY
56
57SMIME_write_PKCS7() was added to OpenSSL 0.9.5
58
59=cut
diff --git a/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod b/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod
deleted file mode 100644
index 11b35f6fd3..0000000000
--- a/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod
+++ /dev/null
@@ -1,72 +0,0 @@
1=pod
2
3=head1 NAME
4
5X509_NAME_ENTRY_get_object, X509_NAME_ENTRY_get_data,
6X509_NAME_ENTRY_set_object, X509_NAME_ENTRY_set_data,
7X509_NAME_ENTRY_create_by_txt, X509_NAME_ENTRY_create_by_NID,
8X509_NAME_ENTRY_create_by_OBJ - X509_NAME_ENTRY utility functions
9
10=head1 SYNOPSIS
11
12ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
13ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
14
15int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj);
16int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, const unsigned char *bytes, int len);
17
18X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, const char *field, int type, const unsigned char *bytes, int len);
19X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type,unsigned char *bytes, int len);
20X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len);
21
22=head1 DESCRIPTION
23
24X509_NAME_ENTRY_get_object() retrieves the field name of B<ne> in
25and B<ASN1_OBJECT> structure.
26
27X509_NAME_ENTRY_get_data() retrieves the field value of B<ne> in
28and B<ASN1_STRING> structure.
29
30X509_NAME_ENTRY_set_object() sets the field name of B<ne> to B<obj>.
31
32X509_NAME_ENTRY_set_data() sets the field value of B<ne> to string type
33B<type> and value determined by B<bytes> and B<len>.
34
35X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_NID()
36and X509_NAME_ENTRY_create_by_OBJ() create and return an
37B<X509_NAME_ENTRY> structure.
38
39=head1 NOTES
40
41X509_NAME_ENTRY_get_object() and X509_NAME_ENTRY_get_data() can be
42used to examine an B<X509_NAME_ENTRY> function as returned by
43X509_NAME_get_entry() for example.
44
45X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_NID(),
46and X509_NAME_ENTRY_create_by_OBJ() create and return an
47
48X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_OBJ(),
49X509_NAME_ENTRY_create_by_NID() and X509_NAME_ENTRY_set_data()
50are seldom used in practice because B<X509_NAME_ENTRY> structures
51are almost always part of B<X509_NAME> structures and the
52corresponding B<X509_NAME> functions are typically used to
53create and add new entries in a single operation.
54
55The arguments of these functions support similar options to the similarly
56named ones of the corresponding B<X509_NAME> functions such as
57X509_NAME_add_entry_by_txt(). So for example B<type> can be set to
58B<MBSTRING_ASC> but in the case of X509_set_data() the field name must be
59set first so the relevant field information can be looked up internally.
60
61=head1 RETURN VALUES
62
63=head1 SEE ALSO
64
65L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>,
66L<OBJ_nid2obj(3),OBJ_nid2obj(3)>
67
68=head1 HISTORY
69
70TBA
71
72=cut
diff --git a/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod b/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod
deleted file mode 100644
index e2ab4b0d2b..0000000000
--- a/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod
+++ /dev/null
@@ -1,114 +0,0 @@
1=pod
2
3=head1 NAME
4
5X509_NAME_add_entry_by_txt, X509_NAME_add_entry_by_OBJ, X509_NAME_add_entry_by_NID,
6X509_NAME_add_entry, X509_NAME_delete_entry - X509_NAME modification functions
7
8=head1 SYNOPSIS
9
10int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, const unsigned char *bytes, int len, int loc, int set);
11
12int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, unsigned char *bytes, int len, int loc, int set);
13
14int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, unsigned char *bytes, int len, int loc, int set);
15
16int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, int loc, int set);
17
18X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
19
20=head1 DESCRIPTION
21
22X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ() and
23X509_NAME_add_entry_by_NID() add a field whose name is defined
24by a string B<field>, an object B<obj> or a NID B<nid> respectively.
25The field value to be added is in B<bytes> of length B<len>. If
26B<len> is -1 then the field length is calculated internally using
27strlen(bytes).
28
29The type of field is determined by B<type> which can either be a
30definition of the type of B<bytes> (such as B<MBSTRING_ASC>) or a
31standard ASN1 type (such as B<V_ASN1_IA5STRING>). The new entry is
32added to a position determined by B<loc> and B<set>.
33
34X509_NAME_add_entry() adds a copy of B<X509_NAME_ENTRY> structure B<ne>
35to B<name>. The new entry is added to a position determined by B<loc>
36and B<set>. Since a copy of B<ne> is added B<ne> must be freed up after
37the call.
38
39X509_NAME_delete_entry() deletes an entry from B<name> at position
40B<loc>. The deleted entry is returned and must be freed up.
41
42=head1 NOTES
43
44The use of string types such as B<MBSTRING_ASC> or B<MBSTRING_UTF8>
45is strongly recommened for the B<type> parameter. This allows the
46internal code to correctly determine the type of the field and to
47apply length checks according to the relevant standards. This is
48done using ASN1_STRING_set_by_NID().
49
50If instead an ASN1 type is used no checks are performed and the
51supplied data in B<bytes> is used directly.
52
53In X509_NAME_add_entry_by_txt() the B<field> string represents
54the field name using OBJ_txt2obj(field, 0).
55
56The B<loc> and B<set> parameters determine where a new entry should
57be added. For almost all applications B<loc> can be set to -1 and B<set>
58to 0. This adds a new entry to the end of B<name> as a single valued
59RelativeDistinguishedName (RDN).
60
61B<loc> actually determines the index where the new entry is inserted:
62if it is -1 it is appended.
63
64B<set> determines how the new type is added. If it is zero a
65new RDN is created.
66
67If B<set> is -1 or 1 it is added to the previous or next RDN
68structure respectively. This will then be a multivalued RDN:
69since multivalues RDNs are very seldom used B<set> is almost
70always set to zero.
71
72=head1 EXAMPLES
73
74Create an B<X509_NAME> structure:
75
76"C=UK, O=Disorganized Organization, CN=Joe Bloggs"
77
78 X509_NAME *nm;
79 nm = X509_NAME_new();
80 if (nm == NULL)
81 /* Some error */
82 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
83 "C", "UK", -1, -1, 0))
84 /* Error */
85 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
86 "O", "Disorganized Organization", -1, -1, 0))
87 /* Error */
88 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
89 "CN", "Joe Bloggs", -1, -1, 0))
90 /* Error */
91
92=head1 RETURN VALUES
93
94X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ(),
95X509_NAME_add_entry_by_NID() and X509_NAME_add_entry() return 1 for
96success of 0 if an error occurred.
97
98X509_NAME_delete_entry() returns either the deleted B<X509_NAME_ENTRY>
99structure of B<NULL> if an error occurred.
100
101=head1 BUGS
102
103B<type> can still be set to B<V_ASN1_APP_CHOOSE> to use a
104different algorithm to determine field types. Since this form does
105not understand multicharacter types, performs no length checks and
106can result in invalid field types its use is strongly discouraged.
107
108=head1 SEE ALSO
109
110L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>
111
112=head1 HISTORY
113
114=cut
diff --git a/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod b/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod
deleted file mode 100644
index 333323d734..0000000000
--- a/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod
+++ /dev/null
@@ -1,106 +0,0 @@
1=pod
2
3=head1 NAME
4
5X509_NAME_get_index_by_NID, X509_NAME_get_index_by_OBJ, X509_NAME_get_entry,
6X509_NAME_entry_count, X509_NAME_get_text_by_NID, X509_NAME_get_text_by_OBJ -
7X509_NAME lookup and enumeration functions
8
9=head1 SYNOPSIS
10
11int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
12int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj, int lastpos);
13
14int X509_NAME_entry_count(X509_NAME *name);
15X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
16
17int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf,int len);
18int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf,int len);
19
20=head1 DESCRIPTION
21
22These functions allow an B<X509_NAME> structure to be examined. The
23B<X509_NAME> structure is the same as the B<Name> type defined in
24RFC2459 (and elsewhere) and used for example in certificate subject
25and issuer names.
26
27X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ() retrieve
28the next index matching B<nid> or B<obj> after B<lastpos>. B<lastpos>
29should initially be set to -1. If there are no more entries -1 is returned.
30
31X509_NAME_entry_count() returns the total number of entries in B<name>.
32
33X509_NAME_get_entry() retrieves the B<X509_NAME_ENTRY> from B<name>
34corresponding to index B<loc>. Acceptable values for B<loc> run from
350 to (X509_NAME_entry_count(name) - 1). The value returned is an
36internal pointer which must not be freed.
37
38X509_NAME_get_text_by_NID(), X509_NAME_get_text_by_OBJ() retrieve
39the "text" from the first entry in B<name> which matches B<nid> or
40B<obj>, if no such entry exists -1 is returned. At most B<len> bytes
41will be written and the text written to B<buf> will be null
42terminated. The length of the output string written is returned
43excluding the terminating null. If B<buf> is <NULL> then the amount
44of space needed in B<buf> (excluding the final null) is returned.
45
46=head1 NOTES
47
48X509_NAME_get_text_by_NID() and X509_NAME_get_text_by_OBJ() are
49legacy functions which have various limitations which make them
50of minimal use in practice. They can only find the first matching
51entry and will copy the contents of the field verbatim: this can
52be highly confusing if the target is a muticharacter string type
53like a BMPString or a UTF8String.
54
55For a more general solution X509_NAME_get_index_by_NID() or
56X509_NAME_get_index_by_OBJ() should be used followed by
57X509_NAME_get_entry() on any matching indices and then the
58various B<X509_NAME_ENTRY> utility functions on the result.
59
60=head1 EXAMPLES
61
62Process all entries:
63
64 int i;
65 X509_NAME_ENTRY *e;
66
67 for (i = 0; i < X509_NAME_entry_count(nm); i++)
68 {
69 e = X509_NAME_get_entry(nm, i);
70 /* Do something with e */
71 }
72
73Process all commonName entries:
74
75 int loc;
76 X509_NAME_ENTRY *e;
77
78 loc = -1;
79 for (;;)
80 {
81 lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos);
82 if (lastpos == -1)
83 break;
84 e = X509_NAME_get_entry(nm, lastpos);
85 /* Do something with e */
86 }
87
88=head1 RETURN VALUES
89
90X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ()
91return the index of the next matching entry or -1 if not found.
92
93X509_NAME_entry_count() returns the total number of entries.
94
95X509_NAME_get_entry() returns an B<X509_NAME> pointer to the
96requested entry or B<NULL> if the index is invalid.
97
98=head1 SEE ALSO
99
100L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>
101
102=head1 HISTORY
103
104TBA
105
106=cut
diff --git a/src/lib/libcrypto/doc/X509_NAME_print_ex.pod b/src/lib/libcrypto/doc/X509_NAME_print_ex.pod
deleted file mode 100644
index 919b908919..0000000000
--- a/src/lib/libcrypto/doc/X509_NAME_print_ex.pod
+++ /dev/null
@@ -1,105 +0,0 @@
1=pod
2
3=head1 NAME
4
5X509_NAME_print_ex, X509_NAME_print_ex_fp, X509_NAME_print,
6X509_NAME_oneline - X509_NAME printing routines.
7
8=head1 SYNOPSIS
9
10 #include <openssl/x509.h>
11
12 int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags);
13 int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags);
14 char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
15 int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
16
17=head1 DESCRIPTION
18
19X509_NAME_print_ex() prints a human readable version of B<nm> to BIO B<out>. Each
20line (for multiline formats) is indented by B<indent> spaces. The output format
21can be extensively customised by use of the B<flags> parameter.
22
23X509_NAME_print_ex_fp() is identical to X509_NAME_print_ex() except the output is
24written to FILE pointer B<fp>.
25
26X509_NAME_oneline() prints an ASCII version of B<a> to B<buf>. At most B<size>
27bytes will be written. If B<buf> is B<NULL> then a buffer is dynamically allocated
28and returned, otherwise B<buf> is returned.
29
30X509_NAME_print() prints out B<name> to B<bp> indenting each line by B<obase>
31characters. Multiple lines are used if the output (including indent) exceeds
3280 characters.
33
34=head1 NOTES
35
36The functions X509_NAME_oneline() and X509_NAME_print() are legacy functions which
37produce a non standard output form, they don't handle multi character fields and
38have various quirks and inconsistencies. Their use is strongly discouraged in new
39applications.
40
41Although there are a large number of possible flags for most purposes
42B<XN_FLAG_ONELINE>, B<XN_FLAG_MULTILINE> or B<XN_FLAG_RFC2253> will suffice.
43As noted on the L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)> manual page
44for UTF8 terminals the B<ASN1_STRFLGS_ESC_MSB> should be unset: so for example
45B<XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB> would be used.
46
47The complete set of the flags supported by X509_NAME_print_ex() is listed below.
48
49Several options can be ored together.
50
51The options B<XN_FLAG_SEP_COMMA_PLUS>, B<XN_FLAG_SEP_CPLUS_SPC>,
52B<XN_FLAG_SEP_SPLUS_SPC> and B<XN_FLAG_SEP_MULTILINE> determine the field separators
53to use. Two distinct separators are used between distinct RelativeDistinguishedName
54components and separate values in the same RDN for a multi-valued RDN. Multi-valued
55RDNs are currently very rare so the second separator will hardly ever be used.
56
57B<XN_FLAG_SEP_COMMA_PLUS> uses comma and plus as separators. B<XN_FLAG_SEP_CPLUS_SPC>
58uses comma and plus with spaces: this is more readable that plain comma and plus.
59B<XN_FLAG_SEP_SPLUS_SPC> uses spaced semicolon and plus. B<XN_FLAG_SEP_MULTILINE> uses
60spaced newline and plus respectively.
61
62If B<XN_FLAG_DN_REV> is set the whole DN is printed in reversed order.
63
64The fields B<XN_FLAG_FN_SN>, B<XN_FLAG_FN_LN>, B<XN_FLAG_FN_OID>,
65B<XN_FLAG_FN_NONE> determine how a field name is displayed. It will
66use the short name (e.g. CN) the long name (e.g. commonName) always
67use OID numerical form (normally OIDs are only used if the field name is not
68recognised) and no field name respectively.
69
70If B<XN_FLAG_SPC_EQ> is set then spaces will be placed around the '=' character
71separating field names and values.
72
73If B<XN_FLAG_DUMP_UNKNOWN_FIELDS> is set then the encoding of unknown fields is
74printed instead of the values.
75
76If B<XN_FLAG_FN_ALIGN> is set then field names are padded to 20 characters: this
77is only of use for multiline format.
78
79Additionally all the options supported by ASN1_STRING_print_ex() can be used to
80control how each field value is displayed.
81
82In addition a number options can be set for commonly used formats.
83
84B<XN_FLAG_RFC2253> sets options which produce an output compatible with RFC2253 it
85is equivalent to:
86 B<ASN1_STRFLGS_RFC2253 | XN_FLAG_SEP_COMMA_PLUS | XN_FLAG_DN_REV | XN_FLAG_FN_SN | XN_FLAG_DUMP_UNKNOWN_FIELDS>
87
88
89B<XN_FLAG_ONELINE> is a more readable one line format it is the same as:
90 B<ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE | XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_SPC_EQ | XN_FLAG_FN_SN>
91
92B<XN_FLAG_MULTILINE> is a multiline format is is the same as:
93 B<ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | XN_FLAG_SEP_MULTILINE | XN_FLAG_SPC_EQ | XN_FLAG_FN_LN | XN_FLAG_FN_ALIGN>
94
95B<XN_FLAG_COMPAT> uses a format identical to X509_NAME_print(): in fact it calls X509_NAME_print() internally.
96
97=head1 SEE ALSO
98
99L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)>
100
101=head1 HISTORY
102
103TBA
104
105=cut
diff --git a/src/lib/libcrypto/doc/X509_new.pod b/src/lib/libcrypto/doc/X509_new.pod
deleted file mode 100644
index fd5fc65ce1..0000000000
--- a/src/lib/libcrypto/doc/X509_new.pod
+++ /dev/null
@@ -1,37 +0,0 @@
1=pod
2
3=head1 NAME
4
5X509_new, X509_free - X509 certificate ASN1 allocation functions
6
7=head1 SYNOPSIS
8
9 X509 *X509_new(void);
10 void X509_free(X509 *a);
11
12=head1 DESCRIPTION
13
14The X509 ASN1 allocation routines, allocate and free an
15X509 structure, which represents an X509 certificate.
16
17X509_new() allocates and initializes a X509 structure.
18
19X509_free() frees up the B<X509> structure B<a>.
20
21=head1 RETURN VALUES
22
23If the allocation fails, X509_new() returns B<NULL> and sets an error
24code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
25Otherwise it returns a pointer to the newly allocated structure.
26
27X509_free() returns no value.
28
29=head1 SEE ALSO
30
31L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509(3)|d2i_X509(3)>
32
33=head1 HISTORY
34
35X509_new() and X509_free() are available in all versions of SSLeay and OpenSSL.
36
37=cut
diff --git a/src/lib/libcrypto/doc/bn.pod b/src/lib/libcrypto/doc/bn.pod
deleted file mode 100644
index 210dfeac08..0000000000
--- a/src/lib/libcrypto/doc/bn.pod
+++ /dev/null
@@ -1,158 +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 BIGNUM *BN_swap(BIGNUM *a, BIGNUM *b);
25
26 int BN_num_bytes(const BIGNUM *a);
27 int BN_num_bits(const BIGNUM *a);
28 int BN_num_bits_word(BN_ULONG w);
29
30 int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
31 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
32 int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
33 int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
34 int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
35 BN_CTX *ctx);
36 int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
37 int BN_nnmod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
38 int BN_mod_add(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
39 BN_CTX *ctx);
40 int BN_mod_sub(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
41 BN_CTX *ctx);
42 int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
43 BN_CTX *ctx);
44 int BN_mod_sqr(BIGNUM *ret, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
45 int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
46 int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
47 const BIGNUM *m, BN_CTX *ctx);
48 int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
49
50 int BN_add_word(BIGNUM *a, BN_ULONG w);
51 int BN_sub_word(BIGNUM *a, BN_ULONG w);
52 int BN_mul_word(BIGNUM *a, BN_ULONG w);
53 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
54 BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
55
56 int BN_cmp(BIGNUM *a, BIGNUM *b);
57 int BN_ucmp(BIGNUM *a, BIGNUM *b);
58 int BN_is_zero(BIGNUM *a);
59 int BN_is_one(BIGNUM *a);
60 int BN_is_word(BIGNUM *a, BN_ULONG w);
61 int BN_is_odd(BIGNUM *a);
62
63 int BN_zero(BIGNUM *a);
64 int BN_one(BIGNUM *a);
65 const BIGNUM *BN_value_one(void);
66 int BN_set_word(BIGNUM *a, unsigned long w);
67 unsigned long BN_get_word(BIGNUM *a);
68
69 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
70 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
71 int BN_rand_range(BIGNUM *rnd, BIGNUM *range);
72 int BN_pseudo_rand_range(BIGNUM *rnd, BIGNUM *range);
73
74 BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
75 BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
76 int BN_is_prime(const BIGNUM *p, int nchecks,
77 void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
78
79 int BN_set_bit(BIGNUM *a, int n);
80 int BN_clear_bit(BIGNUM *a, int n);
81 int BN_is_bit_set(const BIGNUM *a, int n);
82 int BN_mask_bits(BIGNUM *a, int n);
83 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
84 int BN_lshift1(BIGNUM *r, BIGNUM *a);
85 int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
86 int BN_rshift1(BIGNUM *r, BIGNUM *a);
87
88 int BN_bn2bin(const BIGNUM *a, unsigned char *to);
89 BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
90 char *BN_bn2hex(const BIGNUM *a);
91 char *BN_bn2dec(const BIGNUM *a);
92 int BN_hex2bn(BIGNUM **a, const char *str);
93 int BN_dec2bn(BIGNUM **a, const char *str);
94 int BN_print(BIO *fp, const BIGNUM *a);
95 int BN_print_fp(FILE *fp, const BIGNUM *a);
96 int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
97 BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
98
99 BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
100 BN_CTX *ctx);
101
102 BN_RECP_CTX *BN_RECP_CTX_new(void);
103 void BN_RECP_CTX_init(BN_RECP_CTX *recp);
104 void BN_RECP_CTX_free(BN_RECP_CTX *recp);
105 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
106 int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
107 BN_RECP_CTX *recp, BN_CTX *ctx);
108
109 BN_MONT_CTX *BN_MONT_CTX_new(void);
110 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
111 void BN_MONT_CTX_free(BN_MONT_CTX *mont);
112 int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
113 BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
114 int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
115 BN_MONT_CTX *mont, BN_CTX *ctx);
116 int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
117 BN_CTX *ctx);
118 int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
119 BN_CTX *ctx);
120
121
122=head1 DESCRIPTION
123
124This library performs arithmetic operations on integers of arbitrary
125size. It was written for use in public key cryptography, such as RSA
126and Diffie-Hellman.
127
128It uses dynamic memory allocation for storing its data structures.
129That means that there is no limit on the size of the numbers
130manipulated by these functions, but return values must always be
131checked in case a memory allocation error has occurred.
132
133The basic object in this library is a B<BIGNUM>. It is used to hold a
134single large integer. This type should be considered opaque and fields
135should not be modified or accessed directly.
136
137The creation of B<BIGNUM> objects is described in L<BN_new(3)|BN_new(3)>;
138L<BN_add(3)|BN_add(3)> describes most of the arithmetic operations.
139Comparison is described in L<BN_cmp(3)|BN_cmp(3)>; L<BN_zero(3)|BN_zero(3)>
140describes certain assignments, L<BN_rand(3)|BN_rand(3)> the generation of
141random numbers, L<BN_generate_prime(3)|BN_generate_prime(3)> deals with prime
142numbers and L<BN_set_bit(3)|BN_set_bit(3)> with bit operations. The conversion
143of B<BIGNUM>s to external formats is described in L<BN_bn2bin(3)|BN_bn2bin(3)>.
144
145=head1 SEE ALSO
146
147L<bn_internal(3)|bn_internal(3)>,
148L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
149L<BN_new(3)|BN_new(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
150L<BN_copy(3)|BN_copy(3)>, L<BN_swap(3)|BN_swap(3)>, L<BN_num_bytes(3)|BN_num_bytes(3)>,
151L<BN_add(3)|BN_add(3)>, L<BN_add_word(3)|BN_add_word(3)>,
152L<BN_cmp(3)|BN_cmp(3)>, L<BN_zero(3)|BN_zero(3)>, L<BN_rand(3)|BN_rand(3)>,
153L<BN_generate_prime(3)|BN_generate_prime(3)>, L<BN_set_bit(3)|BN_set_bit(3)>,
154L<BN_bn2bin(3)|BN_bn2bin(3)>, L<BN_mod_inverse(3)|BN_mod_inverse(3)>,
155L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>,
156L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>
157
158=cut
diff --git a/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod b/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod
deleted file mode 100644
index 45bb18492c..0000000000
--- a/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod
+++ /dev/null
@@ -1,29 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_ASN1_OBJECT, i2d_ASN1_OBJECT - ASN1 OBJECT IDENTIFIER functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/objects.h>
10
11 ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, long length);
12 int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode an ASN1 OBJECT IDENTIFIER.
17
18Othewise these behave in a similar way to d2i_X509() and i2d_X509()
19described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
20
21=head1 SEE ALSO
22
23L<d2i_X509(3)|d2i_X509(3)>
24
25=head1 HISTORY
26
27TBA
28
29=cut
diff --git a/src/lib/libcrypto/doc/d2i_DHparams.pod b/src/lib/libcrypto/doc/d2i_DHparams.pod
deleted file mode 100644
index 1e98aebeca..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 - PKCS#3 DH parameter functions.
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
16These functions decode and encode PKCS#3 DH parameters using the
17DHparameter structure described in PKCS#3.
18
19Othewise these behave in a similar way to d2i_X509() and i2d_X509()
20described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
21
22=head1 SEE ALSO
23
24L<d2i_X509(3)|d2i_X509(3)>
25
26=head1 HISTORY
27
28TBA
29
30=cut
diff --git a/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod b/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod
deleted file mode 100644
index 22c1b50f22..0000000000
--- a/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod
+++ /dev/null
@@ -1,83 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_DSAPublicKey, i2d_DSAPublicKey, d2i_DSAPrivateKey, i2d_DSAPrivateKey,
6d2i_DSA_PUBKEY, i2d_DSA_PUBKEY, d2i_DSA_SIG, i2d_DSA_SIG - DSA key encoding
7and parsing functions.
8
9=head1 SYNOPSIS
10
11 #include <openssl/dsa.h>
12 #include <openssl/x509.h>
13
14 DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
15
16 int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
17
18 DSA * d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length);
19
20 int i2d_DSA_PUBKEY(const DSA *a, unsigned char **pp);
21
22 DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
23
24 int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
25
26 DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
27
28 int i2d_DSAparams(const DSA *a, unsigned char **pp);
29
30 DSA * d2i_DSA_SIG(DSA_SIG **a, const unsigned char **pp, long length);
31
32 int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
33
34=head1 DESCRIPTION
35
36d2i_DSAPublicKey() and i2d_DSAPublicKey() decode and encode the DSA public key
37components structure.
38
39d2i_DSA_PUBKEY() and i2d_DSA_PUBKEY() decode and encode an DSA public key using
40a SubjectPublicKeyInfo (certificate public key) structure.
41
42d2i_DSAPrivateKey(), i2d_DSAPrivateKey() decode and encode the DSA private key
43components.
44
45d2i_DSAparams(), i2d_DSAparams() decode and encode the DSA parameters using
46a B<Dss-Parms> structure as defined in RFC2459.
47
48d2i_DSA_SIG(), i2d_DSA_SIG() decode and encode a DSA signature using a
49B<Dss-Sig-Value> structure as defined in RFC2459.
50
51The usage of all of these functions is similar to the d2i_X509() and
52i2d_X509() described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
53
54=head1 NOTES
55
56The B<DSA> structure passed to the private key encoding functions should have
57all the private key components present.
58
59The data encoded by the private key functions is unencrypted and therefore
60offers no private key security.
61
62The B<DSA_PUBKEY> functions should be used in preference to the B<DSAPublicKey>
63functions when encoding public keys because they use a standard format.
64
65The B<DSAPublicKey> functions use an non standard format the actual data encoded
66depends on the value of the B<write_params> field of the B<a> key parameter.
67If B<write_params> is zero then only the B<pub_key> field is encoded as an
68B<INTEGER>. If B<write_params> is 1 then a B<SEQUENCE> consisting of the
69B<p>, B<q>, B<g> and B<pub_key> respectively fields are encoded.
70
71The B<DSAPrivateKey> functions also use a non standard structure consiting
72consisting of a SEQUENCE containing the B<p>, B<q>, B<g> and B<pub_key> and
73B<priv_key> fields respectively.
74
75=head1 SEE ALSO
76
77L<d2i_X509(3)|d2i_X509(3)>
78
79=head1 HISTORY
80
81TBA
82
83=cut
diff --git a/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod b/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod
deleted file mode 100644
index 279b29c873..0000000000
--- a/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod
+++ /dev/null
@@ -1,67 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey,
6d2i_RSA_PUBKEY, i2d_RSA_PUBKEY, i2d_Netscape_RSA,
7d2i_Netscape_RSA - RSA public and private key encoding functions.
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12 #include <openssl/x509.h>
13
14 RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
15
16 int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
17
18 RSA * d2i_RSA_PUBKEY(RSA **a, unsigned char **pp, long length);
19
20 int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp);
21
22 RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
23
24 int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
25
26 int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
27
28 RSA * d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
29
30=head1 DESCRIPTION
31
32d2i_RSAPublicKey() and i2d_RSAPublicKey() decode and encode a PKCS#1 RSAPublicKey
33structure.
34
35d2i_RSA_PUBKEY() and i2d_RSA_PUBKEY() decode and encode an RSA public key using
36a SubjectPublicKeyInfo (certificate public key) structure.
37
38d2i_RSAPrivateKey(), i2d_RSAPrivateKey() decode and encode a PKCS#1 RSAPrivateKey
39structure.
40
41d2i_Netscape_RSA(), i2d_Netscape_RSA() decode and encode an RSA private key in
42NET format.
43
44The usage of all of these functions is similar to the d2i_X509() and
45i2d_X509() described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
46
47=head1 NOTES
48
49The B<RSA> structure passed to the private key encoding functions should have
50all the PKCS#1 private key components present.
51
52The data encoded by the private key functions is unencrypted and therefore
53offers no private key security.
54
55The NET format functions are present to provide compatibility with certain very
56old software. This format has some severe security weaknesses and should be
57avoided if possible.
58
59=head1 SEE ALSO
60
61L<d2i_X509(3)|d2i_X509(3)>
62
63=head1 HISTORY
64
65TBA
66
67=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509.pod b/src/lib/libcrypto/doc/d2i_X509.pod
deleted file mode 100644
index 5e3c3d0985..0000000000
--- a/src/lib/libcrypto/doc/d2i_X509.pod
+++ /dev/null
@@ -1,231 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio,
6i2d_X509_fp - X509 encode and decode functions
7
8=head1 SYNOPSIS
9
10 #include <openssl/x509.h>
11
12 X509 *d2i_X509(X509 **px, unsigned char **in, int len);
13 int i2d_X509(X509 *x, unsigned char **out);
14
15 X509 *d2i_X509_bio(BIO *bp, X509 **x);
16 X509 *d2i_X509_fp(FILE *fp, X509 **x);
17
18 int i2d_X509_bio(X509 *x, BIO *bp);
19 int i2d_X509_fp(X509 *x, FILE *fp);
20
21=head1 DESCRIPTION
22
23The X509 encode and decode routines encode and parse an
24B<X509> structure, which represents an X509 certificate.
25
26d2i_X509() attempts to decode B<len> bytes at B<*out>. If
27successful a pointer to the B<X509> structure is returned. If an error
28occurred then B<NULL> is returned. If B<px> is not B<NULL> then the
29returned structure is written to B<*px>. If B<*px> is not B<NULL>
30then it is assumed that B<*px> contains a valid B<X509>
31structure and an attempt is made to reuse it. If the call is
32successful B<*out> is incremented to the byte following the
33parsed data.
34
35i2d_X509() encodes the structure pointed to by B<x> into DER format.
36If B<out> is not B<NULL> is writes the DER encoded data to the buffer
37at B<*out>, and increments it to point after the data just written.
38If the return value is negative an error occurred, otherwise it
39returns the length of the encoded data.
40
41For OpenSSL 0.9.7 and later if B<*out> is B<NULL> memory will be
42allocated for a buffer and the encoded data written to it. In this
43case B<*out> is not incremented and it points to the start of the
44data just written.
45
46d2i_X509_bio() is similar to d2i_X509() except it attempts
47to parse data from BIO B<bp>.
48
49d2i_X509_fp() is similar to d2i_X509() except it attempts
50to parse data from FILE pointer B<fp>.
51
52i2d_X509_bio() is similar to i2d_X509() except it writes
53the encoding of the structure B<x> to BIO B<bp> and it
54returns 1 for success and 0 for failure.
55
56i2d_X509_fp() is similar to i2d_X509() except it writes
57the encoding of the structure B<x> to BIO B<bp> and it
58returns 1 for success and 0 for failure.
59
60=head1 NOTES
61
62The letters B<i> and B<d> in for example B<i2d_X509> stand for
63"internal" (that is an internal C structure) and "DER". So that
64B<i2d_X509> converts from internal to DER.
65
66The functions can also understand B<BER> forms.
67
68The actual X509 structure passed to i2d_X509() must be a valid
69populated B<X509> structure it can B<not> simply be fed with an
70empty structure such as that returned by X509_new().
71
72The encoded data is in binary form and may contain embedded zeroes.
73Therefore any FILE pointers or BIOs should be opened in binary mode.
74Functions such as B<strlen()> will B<not> return the correct length
75of the encoded structure.
76
77The ways that B<*in> and B<*out> are incremented after the operation
78can trap the unwary. See the B<WARNINGS> section for some common
79errors.
80
81The reason for the auto increment behaviour is to reflect a typical
82usage of ASN1 functions: after one structure is encoded or decoded
83another will processed after it.
84
85=head1 EXAMPLES
86
87Allocate and encode the DER encoding of an X509 structure:
88
89 int len;
90 unsigned char *buf, *p;
91
92 len = i2d_X509(x, NULL);
93
94 buf = OPENSSL_malloc(len);
95
96 if (buf == NULL)
97 /* error */
98
99 p = buf;
100
101 i2d_X509(x, &p);
102
103If you are using OpenSSL 0.9.7 or later then this can be
104simplified to:
105
106
107 int len;
108 unsigned char *buf;
109
110 buf = NULL;
111
112 len = i2d_X509(x, &buf);
113
114 if (len < 0)
115 /* error */
116
117Attempt to decode a buffer:
118
119 X509 *x;
120
121 unsigned char *buf, *p;
122
123 int len;
124
125 /* Something to setup buf and len */
126
127 p = buf;
128
129 x = d2i_X509(NULL, &p, len);
130
131 if (x == NULL)
132 /* Some error */
133
134Alternative technique:
135
136 X509 *x;
137
138 unsigned char *buf, *p;
139
140 int len;
141
142 /* Something to setup buf and len */
143
144 p = buf;
145
146 x = NULL;
147
148 if(!d2i_X509(&x, &p, len))
149 /* Some error */
150
151
152=head1 WARNINGS
153
154The use of temporary variable is mandatory. A common
155mistake is to attempt to use a buffer directly as follows:
156
157 int len;
158 unsigned char *buf;
159
160 len = i2d_X509(x, NULL);
161
162 buf = OPENSSL_malloc(len);
163
164 if (buf == NULL)
165 /* error */
166
167 i2d_X509(x, &buf);
168
169 /* Other stuff ... */
170
171 OPENSSL_free(buf);
172
173This code will result in B<buf> apparently containing garbage because
174it was incremented after the call to point after the data just written.
175Also B<buf> will no longer contain the pointer allocated by B<OPENSSL_malloc()>
176and the subsequent call to B<OPENSSL_free()> may well crash.
177
178The auto allocation feature (setting buf to NULL) only works on OpenSSL
1790.9.7 and later. Attempts to use it on earlier versions will typically
180cause a segmentation violation.
181
182Another trap to avoid is misuse of the B<xp> argument to B<d2i_X509()>:
183
184 X509 *x;
185
186 if (!d2i_X509(&x, &p, len))
187 /* Some error */
188
189This will probably crash somewhere in B<d2i_X509()>. The reason for this
190is that the variable B<x> is uninitialized and an attempt will be made to
191interpret its (invalid) value as an B<X509> structure, typically causing
192a segmentation violation. If B<x> is set to NULL first then this will not
193happen.
194
195=head1 BUGS
196
197In some versions of OpenSSL the "reuse" behaviour of d2i_X509() when
198B<*px> is valid is broken and some parts of the reused structure may
199persist if they are not present in the new one. As a result the use
200of this "reuse" behaviour is strongly discouraged.
201
202i2d_X509() will not return an error in many versions of OpenSSL,
203if mandatory fields are not initialized due to a programming error
204then the encoded structure may contain invalid data or omit the
205fields entirely and will not be parsed by d2i_X509(). This may be
206fixed in future so code should not assume that i2d_X509() will
207always succeed.
208
209=head1 RETURN VALUES
210
211d2i_X509(), d2i_X509_bio() and d2i_X509_fp() return a valid B<X509> structure
212or B<NULL> if an error occurs. The error code that can be obtained by
213L<ERR_get_error(3)|ERR_get_error(3)>.
214
215i2d_X509(), i2d_X509_bio() and i2d_X509_fp() return a the number of bytes
216successfully encoded or a negative value if an error occurs. The error code
217can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
218
219i2d_X509_bio() and i2d_X509_fp() returns 1 for success and 0 if an error
220occurs The error code can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
221
222=head1 SEE ALSO
223
224L<ERR_get_error(3)|ERR_get_error(3)>
225
226=head1 HISTORY
227
228d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio and i2d_X509_fp
229are available in all versions of SSLeay and OpenSSL.
230
231=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod b/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod
deleted file mode 100644
index 9e5cd92ca7..0000000000
--- a/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod
+++ /dev/null
@@ -1,30 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_ALGOR, i2d_X509_ALGOR - AlgorithmIdentifier functions.
6
7=head1 SYNOPSIS
8
9 #include <openssl/x509.h>
10
11 X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length);
12 int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode an B<X509_ALGOR> structure which is
17equivalent to the B<AlgorithmIdentifier> structure.
18
19Othewise these behave in a similar way to d2i_X509() and i2d_X509()
20described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
21
22=head1 SEE ALSO
23
24L<d2i_X509(3)|d2i_X509(3)>
25
26=head1 HISTORY
27
28TBA
29
30=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_CRL.pod b/src/lib/libcrypto/doc/d2i_X509_CRL.pod
deleted file mode 100644
index 06c5b23c09..0000000000
--- a/src/lib/libcrypto/doc/d2i_X509_CRL.pod
+++ /dev/null
@@ -1,37 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_CRL, i2d_X509_CRL, d2i_X509_CRL_bio, d2i_509_CRL_fp,
6i2d_X509_CRL_bio, i2d_X509_CRL_fp - PKCS#10 certificate request functions.
7
8=head1 SYNOPSIS
9
10 #include <openssl/x509.h>
11
12 X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length);
13 int i2d_X509_CRL(X509_CRL *a, unsigned char **pp);
14
15 X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **x);
16 X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **x);
17
18 int i2d_X509_CRL_bio(X509_CRL *x, BIO *bp);
19 int i2d_X509_CRL_fp(X509_CRL *x, FILE *fp);
20
21=head1 DESCRIPTION
22
23These functions decode and encode an X509 CRL (certificate revocation
24list).
25
26Othewise the functions behave in a similar way to d2i_X509() and i2d_X509()
27described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
28
29=head1 SEE ALSO
30
31L<d2i_X509(3)|d2i_X509(3)>
32
33=head1 HISTORY
34
35TBA
36
37=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_NAME.pod b/src/lib/libcrypto/doc/d2i_X509_NAME.pod
deleted file mode 100644
index 343ffe1519..0000000000
--- a/src/lib/libcrypto/doc/d2i_X509_NAME.pod
+++ /dev/null
@@ -1,31 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_NAME, i2d_X509_NAME - X509_NAME encoding functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/x509.h>
10
11 X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length);
12 int i2d_X509_NAME(X509_NAME *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode an B<X509_NAME> structure which is the
17the same as the B<Name> type defined in RFC2459 (and elsewhere) and used
18for example in certificate subject and issuer names.
19
20Othewise the functions behave in a similar way to d2i_X509() and i2d_X509()
21described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
22
23=head1 SEE ALSO
24
25L<d2i_X509(3)|d2i_X509(3)>
26
27=head1 HISTORY
28
29TBA
30
31=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_REQ.pod b/src/lib/libcrypto/doc/d2i_X509_REQ.pod
deleted file mode 100644
index be4ad68257..0000000000
--- a/src/lib/libcrypto/doc/d2i_X509_REQ.pod
+++ /dev/null
@@ -1,36 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_REQ, i2d_X509_REQ, d2i_X509_REQ_bio, d2i_X509_REQ_fp,
6i2d_X509_REQ_bio, i2d_X509_REQ_fp - PKCS#10 certificate request functions.
7
8=head1 SYNOPSIS
9
10 #include <openssl/x509.h>
11
12 X509_REQ *d2i_X509_REQ(X509_REQ **a, unsigned char **pp, long length);
13 int i2d_X509_REQ(X509_REQ *a, unsigned char **pp);
14
15 X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **x);
16 X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **x);
17
18 int i2d_X509_REQ_bio(X509_REQ *x, BIO *bp);
19 int i2d_X509_REQ_fp(X509_REQ *x, FILE *fp);
20
21=head1 DESCRIPTION
22
23These functions decode and encode a PKCS#10 certificate request.
24
25Othewise these behave in a similar way to d2i_X509() and i2d_X509()
26described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
27
28=head1 SEE ALSO
29
30L<d2i_X509(3)|d2i_X509(3)>
31
32=head1 HISTORY
33
34TBA
35
36=cut
diff --git a/src/lib/libcrypto/doc/d2i_X509_SIG.pod b/src/lib/libcrypto/doc/d2i_X509_SIG.pod
deleted file mode 100644
index e48fd79a51..0000000000
--- a/src/lib/libcrypto/doc/d2i_X509_SIG.pod
+++ /dev/null
@@ -1,30 +0,0 @@
1=pod
2
3=head1 NAME
4
5d2i_X509_SIG, i2d_X509_SIG - DigestInfo functions.
6
7=head1 SYNOPSIS
8
9 #include <openssl/x509.h>
10
11 X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length);
12 int i2d_X509_SIG(X509_SIG *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16These functions decode and encode an X509_SIG structure which is
17equivalent to the B<DigestInfo> structure defined in PKCS#1 and PKCS#7.
18
19Othewise these behave in a similar way to d2i_X509() and i2d_X509()
20described in the L<d2i_X509(3)|d2i_X509(3)> manual page.
21
22=head1 SEE ALSO
23
24L<d2i_X509(3)|d2i_X509(3)>
25
26=head1 HISTORY
27
28TBA
29
30=cut
diff --git a/src/lib/libcrypto/doc/dh.pod b/src/lib/libcrypto/doc/dh.pod
deleted file mode 100644
index c3ccd06207..0000000000
--- a/src/lib/libcrypto/doc/dh.pod
+++ /dev/null
@@ -1,78 +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 #include <openssl/engine.h>
11
12 DH * DH_new(void);
13 void DH_free(DH *dh);
14
15 int DH_size(const DH *dh);
16
17 DH * DH_generate_parameters(int prime_len, int generator,
18 void (*callback)(int, int, void *), void *cb_arg);
19 int DH_check(const DH *dh, int *codes);
20
21 int DH_generate_key(DH *dh);
22 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
23
24 void DH_set_default_method(const DH_METHOD *meth);
25 const DH_METHOD *DH_get_default_method(void);
26 int DH_set_method(DH *dh, const DH_METHOD *meth);
27 DH *DH_new_method(ENGINE *engine);
28 const DH_METHOD *DH_OpenSSL(void);
29
30 int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(),
31 int (*dup_func)(), void (*free_func)());
32 int DH_set_ex_data(DH *d, int idx, char *arg);
33 char *DH_get_ex_data(DH *d, int idx);
34
35 DH * d2i_DHparams(DH **a, unsigned char **pp, long length);
36 int i2d_DHparams(const DH *a, unsigned char **pp);
37
38 int DHparams_print_fp(FILE *fp, const DH *x);
39 int DHparams_print(BIO *bp, const DH *x);
40
41=head1 DESCRIPTION
42
43These functions implement the Diffie-Hellman key agreement protocol.
44The generation of shared DH parameters is described in
45L<DH_generate_parameters(3)|DH_generate_parameters(3)>; L<DH_generate_key(3)|DH_generate_key(3)> describes how
46to perform a key agreement.
47
48The B<DH> structure consists of several BIGNUM components.
49
50 struct
51 {
52 BIGNUM *p; // prime number (shared)
53 BIGNUM *g; // generator of Z_p (shared)
54 BIGNUM *priv_key; // private DH value x
55 BIGNUM *pub_key; // public DH value g^x
56 // ...
57 };
58 DH
59
60Note that DH keys may use non-standard B<DH_METHOD> implementations,
61either directly or by the use of B<ENGINE> modules. In some cases (eg. an
62ENGINE providing support for hardware-embedded keys), these BIGNUM values
63will not be used by the implementation or may be used for alternative data
64storage. For this reason, applications should generally avoid using DH
65structure elements directly and instead use API functions to query or
66modify keys.
67
68=head1 SEE ALSO
69
70L<dhparam(1)|dhparam(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>,
71L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<engine(3)|engine(3)>,
72L<DH_set_method(3)|DH_set_method(3)>, L<DH_new(3)|DH_new(3)>,
73L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>,
74L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
75L<DH_compute_key(3)|DH_compute_key(3)>, L<d2i_DHparams(3)|d2i_DHparams(3)>,
76L<RSA_print(3)|RSA_print(3)>
77
78=cut
diff --git a/src/lib/libcrypto/doc/dsa.pod b/src/lib/libcrypto/doc/dsa.pod
deleted file mode 100644
index ae2e5d81f9..0000000000
--- a/src/lib/libcrypto/doc/dsa.pod
+++ /dev/null
@@ -1,113 +0,0 @@
1=pod
2
3=head1 NAME
4
5dsa - Digital Signature Algorithm
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10 #include <openssl/engine.h>
11
12 DSA * DSA_new(void);
13 void DSA_free(DSA *dsa);
14
15 int DSA_size(const DSA *dsa);
16
17 DSA * DSA_generate_parameters(int bits, unsigned char *seed,
18 int seed_len, int *counter_ret, unsigned long *h_ret,
19 void (*callback)(int, int, void *), void *cb_arg);
20
21 DH * DSA_dup_DH(const DSA *r);
22
23 int DSA_generate_key(DSA *dsa);
24
25 int DSA_sign(int dummy, const unsigned char *dgst, int len,
26 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
27 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
28 BIGNUM **rp);
29 int DSA_verify(int dummy, const unsigned char *dgst, int len,
30 const unsigned char *sigbuf, int siglen, DSA *dsa);
31
32 void DSA_set_default_method(const DSA_METHOD *meth);
33 const DSA_METHOD *DSA_get_default_method(void);
34 int DSA_set_method(DSA *dsa, const DSA_METHOD *meth);
35 DSA *DSA_new_method(ENGINE *engine);
36 const DSA_METHOD *DSA_OpenSSL(void);
37
38 int DSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
39 int (*dup_func)(), void (*free_func)());
40 int DSA_set_ex_data(DSA *d, int idx, char *arg);
41 char *DSA_get_ex_data(DSA *d, int idx);
42
43 DSA_SIG *DSA_SIG_new(void);
44 void DSA_SIG_free(DSA_SIG *a);
45 int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
46 DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
47
48 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
49 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
50 DSA_SIG *sig, DSA *dsa);
51
52 DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
53 DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
54 DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
55 int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
56 int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
57 int i2d_DSAparams(const DSA *a,unsigned char **pp);
58
59 int DSAparams_print(BIO *bp, const DSA *x);
60 int DSAparams_print_fp(FILE *fp, const DSA *x);
61 int DSA_print(BIO *bp, const DSA *x, int off);
62 int DSA_print_fp(FILE *bp, const DSA *x, int off);
63
64=head1 DESCRIPTION
65
66These functions implement the Digital Signature Algorithm (DSA). The
67generation of shared DSA parameters is described in
68L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>;
69L<DSA_generate_key(3)|DSA_generate_key(3)> describes how to
70generate a signature key. Signature generation and verification are
71described in L<DSA_sign(3)|DSA_sign(3)>.
72
73The B<DSA> structure consists of several BIGNUM components.
74
75 struct
76 {
77 BIGNUM *p; // prime number (public)
78 BIGNUM *q; // 160-bit subprime, q | p-1 (public)
79 BIGNUM *g; // generator of subgroup (public)
80 BIGNUM *priv_key; // private key x
81 BIGNUM *pub_key; // public key y = g^x
82 // ...
83 }
84 DSA;
85
86In public keys, B<priv_key> is NULL.
87
88Note that DSA keys may use non-standard B<DSA_METHOD> implementations,
89either directly or by the use of B<ENGINE> modules. In some cases (eg. an
90ENGINE providing support for hardware-embedded keys), these BIGNUM values
91will not be used by the implementation or may be used for alternative data
92storage. For this reason, applications should generally avoid using DSA
93structure elements directly and instead use API functions to query or
94modify keys.
95
96=head1 CONFORMING TO
97
98US Federal Information Processing Standard FIPS 186 (Digital Signature
99Standard, DSS), ANSI X9.30
100
101=head1 SEE ALSO
102
103L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
104L<rsa(3)|rsa(3)>, L<SHA1(3)|SHA1(3)>, L<DSA_new(3)|DSA_new(3)>,
105L<DSA_size(3)|DSA_size(3)>,
106L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
107L<DSA_dup_DH(3)|DSA_dup_DH(3)>,
108L<DSA_generate_key(3)|DSA_generate_key(3)>,
109L<DSA_sign(3)|DSA_sign(3)>, L<DSA_set_method(3)|DSA_set_method(3)>,
110L<DSA_get_ex_new_index(3)|DSA_get_ex_new_index(3)>,
111L<RSA_print(3)|RSA_print(3)>
112
113=cut
diff --git a/src/lib/libcrypto/doc/engine.pod b/src/lib/libcrypto/doc/engine.pod
deleted file mode 100644
index c77dad5562..0000000000
--- a/src/lib/libcrypto/doc/engine.pod
+++ /dev/null
@@ -1,621 +0,0 @@
1=pod
2
3=head1 NAME
4
5engine - ENGINE cryptographic module support
6
7=head1 SYNOPSIS
8
9 #include <openssl/engine.h>
10
11 ENGINE *ENGINE_get_first(void);
12 ENGINE *ENGINE_get_last(void);
13 ENGINE *ENGINE_get_next(ENGINE *e);
14 ENGINE *ENGINE_get_prev(ENGINE *e);
15
16 int ENGINE_add(ENGINE *e);
17 int ENGINE_remove(ENGINE *e);
18
19 ENGINE *ENGINE_by_id(const char *id);
20
21 int ENGINE_init(ENGINE *e);
22 int ENGINE_finish(ENGINE *e);
23
24 void ENGINE_load_openssl(void);
25 void ENGINE_load_dynamic(void);
26 void ENGINE_load_cswift(void);
27 void ENGINE_load_chil(void);
28 void ENGINE_load_atalla(void);
29 void ENGINE_load_nuron(void);
30 void ENGINE_load_ubsec(void);
31 void ENGINE_load_aep(void);
32 void ENGINE_load_sureware(void);
33 void ENGINE_load_4758cca(void);
34 void ENGINE_load_openbsd_dev_crypto(void);
35 void ENGINE_load_builtin_engines(void);
36
37 void ENGINE_cleanup(void);
38
39 ENGINE *ENGINE_get_default_RSA(void);
40 ENGINE *ENGINE_get_default_DSA(void);
41 ENGINE *ENGINE_get_default_DH(void);
42 ENGINE *ENGINE_get_default_RAND(void);
43 ENGINE *ENGINE_get_cipher_engine(int nid);
44 ENGINE *ENGINE_get_digest_engine(int nid);
45
46 int ENGINE_set_default_RSA(ENGINE *e);
47 int ENGINE_set_default_DSA(ENGINE *e);
48 int ENGINE_set_default_DH(ENGINE *e);
49 int ENGINE_set_default_RAND(ENGINE *e);
50 int ENGINE_set_default_ciphers(ENGINE *e);
51 int ENGINE_set_default_digests(ENGINE *e);
52 int ENGINE_set_default_string(ENGINE *e, const char *list);
53
54 int ENGINE_set_default(ENGINE *e, unsigned int flags);
55
56 unsigned int ENGINE_get_table_flags(void);
57 void ENGINE_set_table_flags(unsigned int flags);
58
59 int ENGINE_register_RSA(ENGINE *e);
60 void ENGINE_unregister_RSA(ENGINE *e);
61 void ENGINE_register_all_RSA(void);
62 int ENGINE_register_DSA(ENGINE *e);
63 void ENGINE_unregister_DSA(ENGINE *e);
64 void ENGINE_register_all_DSA(void);
65 int ENGINE_register_DH(ENGINE *e);
66 void ENGINE_unregister_DH(ENGINE *e);
67 void ENGINE_register_all_DH(void);
68 int ENGINE_register_RAND(ENGINE *e);
69 void ENGINE_unregister_RAND(ENGINE *e);
70 void ENGINE_register_all_RAND(void);
71 int ENGINE_register_ciphers(ENGINE *e);
72 void ENGINE_unregister_ciphers(ENGINE *e);
73 void ENGINE_register_all_ciphers(void);
74 int ENGINE_register_digests(ENGINE *e);
75 void ENGINE_unregister_digests(ENGINE *e);
76 void ENGINE_register_all_digests(void);
77 int ENGINE_register_complete(ENGINE *e);
78 int ENGINE_register_all_complete(void);
79
80 int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
81 int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
82 int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
83 long i, void *p, void (*f)(), int cmd_optional);
84 int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
85 int cmd_optional);
86
87 int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
88 void *ENGINE_get_ex_data(const ENGINE *e, int idx);
89
90 int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
91 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
92
93 ENGINE *ENGINE_new(void);
94 int ENGINE_free(ENGINE *e);
95
96 int ENGINE_set_id(ENGINE *e, const char *id);
97 int ENGINE_set_name(ENGINE *e, const char *name);
98 int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
99 int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
100 int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
101 int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
102 int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
103 int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
104 int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
105 int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
106 int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
107 int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
108 int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
109 int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
110 int ENGINE_set_flags(ENGINE *e, int flags);
111 int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
112
113 const char *ENGINE_get_id(const ENGINE *e);
114 const char *ENGINE_get_name(const ENGINE *e);
115 const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
116 const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
117 const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
118 const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
119 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
120 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
121 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
122 ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
123 ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
124 ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
125 ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
126 ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
127 const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
128 const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
129 int ENGINE_get_flags(const ENGINE *e);
130 const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
131
132 EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
133 UI_METHOD *ui_method, void *callback_data);
134 EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
135 UI_METHOD *ui_method, void *callback_data);
136
137 void ENGINE_add_conf_module(void);
138
139=head1 DESCRIPTION
140
141These functions create, manipulate, and use cryptographic modules in the
142form of B<ENGINE> objects. These objects act as containers for
143implementations of cryptographic algorithms, and support a
144reference-counted mechanism to allow them to be dynamically loaded in and
145out of the running application.
146
147The cryptographic functionality that can be provided by an B<ENGINE>
148implementation includes the following abstractions;
149
150 RSA_METHOD - for providing alternative RSA implementations
151 DSA_METHOD, DH_METHOD, RAND_METHOD - alternative DSA, DH, and RAND
152 EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
153 EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
154 key-loading - loading public and/or private EVP_PKEY keys
155
156=head2 Reference counting and handles
157
158Due to the modular nature of the ENGINE API, pointers to ENGINEs need to be
159treated as handles - ie. not only as pointers, but also as references to
160the underlying ENGINE object. Ie. you should obtain a new reference when
161making copies of an ENGINE pointer if the copies will be used (and
162released) independantly.
163
164ENGINE objects have two levels of reference-counting to match the way in
165which the objects are used. At the most basic level, each ENGINE pointer is
166inherently a B<structural> reference - you need a structural reference
167simply to refer to the pointer value at all, as this kind of reference is
168your guarantee that the structure can not be deallocated until you release
169your reference.
170
171However, a structural reference provides no guarantee that the ENGINE has
172been initiliased to be usable to perform any of its cryptographic
173implementations - and indeed it's quite possible that most ENGINEs will not
174initialised at all on standard setups, as ENGINEs are typically used to
175support specialised hardware. To use an ENGINE's functionality, you need a
176B<functional> reference. This kind of reference can be considered a
177specialised form of structural reference, because each functional reference
178implicitly contains a structural reference as well - however to avoid
179difficult-to-find programming bugs, it is recommended to treat the two
180kinds of reference independantly. If you have a functional reference to an
181ENGINE, you have a guarantee that the ENGINE has been initialised ready to
182perform cryptographic operations and will not be uninitialised or cleaned
183up until after you have released your reference.
184
185We will discuss the two kinds of reference separately, including how to
186tell which one you are dealing with at any given point in time (after all
187they are both simply (ENGINE *) pointers, the difference is in the way they
188are used).
189
190I<Structural references>
191
192This basic type of reference is typically used for creating new ENGINEs
193dynamically, iterating across OpenSSL's internal linked-list of loaded
194ENGINEs, reading information about an ENGINE, etc. Essentially a structural
195reference is sufficient if you only need to query or manipulate the data of
196an ENGINE implementation rather than use its functionality.
197
198The ENGINE_new() function returns a structural reference to a new (empty)
199ENGINE object. Other than that, structural references come from return
200values to various ENGINE API functions such as; ENGINE_by_id(),
201ENGINE_get_first(), ENGINE_get_last(), ENGINE_get_next(),
202ENGINE_get_prev(). All structural references should be released by a
203corresponding to call to the ENGINE_free() function - the ENGINE object
204itself will only actually be cleaned up and deallocated when the last
205structural reference is released.
206
207It should also be noted that many ENGINE API function calls that accept a
208structural reference will internally obtain another reference - typically
209this happens whenever the supplied ENGINE will be needed by OpenSSL after
210the function has returned. Eg. the function to add a new ENGINE to
211OpenSSL's internal list is ENGINE_add() - if this function returns success,
212then OpenSSL will have stored a new structural reference internally so the
213caller is still responsible for freeing their own reference with
214ENGINE_free() when they are finished with it. In a similar way, some
215functions will automatically release the structural reference passed to it
216if part of the function's job is to do so. Eg. the ENGINE_get_next() and
217ENGINE_get_prev() functions are used for iterating across the internal
218ENGINE list - they will return a new structural reference to the next (or
219previous) ENGINE in the list or NULL if at the end (or beginning) of the
220list, but in either case the structural reference passed to the function is
221released on behalf of the caller.
222
223To clarify a particular function's handling of references, one should
224always consult that function's documentation "man" page, or failing that
225the openssl/engine.h header file includes some hints.
226
227I<Functional references>
228
229As mentioned, functional references exist when the cryptographic
230functionality of an ENGINE is required to be available. A functional
231reference can be obtained in one of two ways; from an existing structural
232reference to the required ENGINE, or by asking OpenSSL for the default
233operational ENGINE for a given cryptographic purpose.
234
235To obtain a functional reference from an existing structural reference,
236call the ENGINE_init() function. This returns zero if the ENGINE was not
237already operational and couldn't be successfully initialised (eg. lack of
238system drivers, no special hardware attached, etc), otherwise it will
239return non-zero to indicate that the ENGINE is now operational and will
240have allocated a new B<functional> reference to the ENGINE. In this case,
241the supplied ENGINE pointer is, from the point of the view of the caller,
242both a structural reference and a functional reference - so if the caller
243intends to use it as a functional reference it should free the structural
244reference with ENGINE_free() first. If the caller wishes to use it only as
245a structural reference (eg. if the ENGINE_init() call was simply to test if
246the ENGINE seems available/online), then it should free the functional
247reference; all functional references are released by the ENGINE_finish()
248function.
249
250The second way to get a functional reference is by asking OpenSSL for a
251default implementation for a given task, eg. by ENGINE_get_default_RSA(),
252ENGINE_get_default_cipher_engine(), etc. These are discussed in the next
253section, though they are not usually required by application programmers as
254they are used automatically when creating and using the relevant
255algorithm-specific types in OpenSSL, such as RSA, DSA, EVP_CIPHER_CTX, etc.
256
257=head2 Default implementations
258
259For each supported abstraction, the ENGINE code maintains an internal table
260of state to control which implementations are available for a given
261abstraction and which should be used by default. These implementations are
262registered in the tables separated-out by an 'nid' index, because
263abstractions like EVP_CIPHER and EVP_DIGEST support many distinct
264algorithms and modes - ENGINEs will support different numbers and
265combinations of these. In the case of other abstractions like RSA, DSA,
266etc, there is only one "algorithm" so all implementations implicitly
267register using the same 'nid' index. ENGINEs can be B<registered> into
268these tables to make themselves available for use automatically by the
269various abstractions, eg. RSA. For illustrative purposes, we continue with
270the RSA example, though all comments apply similarly to the other
271abstractions (they each get their own table and linkage to the
272corresponding section of openssl code).
273
274When a new RSA key is being created, ie. in RSA_new_method(), a
275"get_default" call will be made to the ENGINE subsystem to process the RSA
276state table and return a functional reference to an initialised ENGINE
277whose RSA_METHOD should be used. If no ENGINE should (or can) be used, it
278will return NULL and the RSA key will operate with a NULL ENGINE handle by
279using the conventional RSA implementation in OpenSSL (and will from then on
280behave the way it used to before the ENGINE API existed - for details see
281L<RSA_new_method(3)|RSA_new_method(3)>).
282
283Each state table has a flag to note whether it has processed this
284"get_default" query since the table was last modified, because to process
285this question it must iterate across all the registered ENGINEs in the
286table trying to initialise each of them in turn, in case one of them is
287operational. If it returns a functional reference to an ENGINE, it will
288also cache another reference to speed up processing future queries (without
289needing to iterate across the table). Likewise, it will cache a NULL
290response if no ENGINE was available so that future queries won't repeat the
291same iteration unless the state table changes. This behaviour can also be
292changed; if the ENGINE_TABLE_FLAG_NOINIT flag is set (using
293ENGINE_set_table_flags()), no attempted initialisations will take place,
294instead the only way for the state table to return a non-NULL ENGINE to the
295"get_default" query will be if one is expressly set in the table. Eg.
296ENGINE_set_default_RSA() does the same job as ENGINE_register_RSA() except
297that it also sets the state table's cached response for the "get_default"
298query.
299
300In the case of abstractions like EVP_CIPHER, where implementations are
301indexed by 'nid', these flags and cached-responses are distinct for each
302'nid' value.
303
304It is worth illustrating the difference between "registration" of ENGINEs
305into these per-algorithm state tables and using the alternative
306"set_default" functions. The latter handles both "registration" and also
307setting the cached "default" ENGINE in each relevant state table - so
308registered ENGINEs will only have a chance to be initialised for use as a
309default if a default ENGINE wasn't already set for the same state table.
310Eg. if ENGINE X supports cipher nids {A,B} and RSA, ENGINE Y supports
311ciphers {A} and DSA, and the following code is executed;
312
313 ENGINE_register_complete(X);
314 ENGINE_set_default(Y, ENGINE_METHOD_ALL);
315 e1 = ENGINE_get_default_RSA();
316 e2 = ENGINE_get_cipher_engine(A);
317 e3 = ENGINE_get_cipher_engine(B);
318 e4 = ENGINE_get_default_DSA();
319 e5 = ENGINE_get_cipher_engine(C);
320
321The results would be as follows;
322
323 assert(e1 == X);
324 assert(e2 == Y);
325 assert(e3 == X);
326 assert(e4 == Y);
327 assert(e5 == NULL);
328
329=head2 Application requirements
330
331This section will explain the basic things an application programmer should
332support to make the most useful elements of the ENGINE functionality
333available to the user. The first thing to consider is whether the
334programmer wishes to make alternative ENGINE modules available to the
335application and user. OpenSSL maintains an internal linked list of
336"visible" ENGINEs from which it has to operate - at start-up, this list is
337empty and in fact if an application does not call any ENGINE API calls and
338it uses static linking against openssl, then the resulting application
339binary will not contain any alternative ENGINE code at all. So the first
340consideration is whether any/all available ENGINE implementations should be
341made visible to OpenSSL - this is controlled by calling the various "load"
342functions, eg.
343
344 /* Make the "dynamic" ENGINE available */
345 void ENGINE_load_dynamic(void);
346 /* Make the CryptoSwift hardware acceleration support available */
347 void ENGINE_load_cswift(void);
348 /* Make support for nCipher's "CHIL" hardware available */
349 void ENGINE_load_chil(void);
350 ...
351 /* Make ALL ENGINE implementations bundled with OpenSSL available */
352 void ENGINE_load_builtin_engines(void);
353
354Having called any of these functions, ENGINE objects would have been
355dynamically allocated and populated with these implementations and linked
356into OpenSSL's internal linked list. At this point it is important to
357mention an important API function;
358
359 void ENGINE_cleanup(void);
360
361If no ENGINE API functions are called at all in an application, then there
362are no inherent memory leaks to worry about from the ENGINE functionality,
363however if any ENGINEs are "load"ed, even if they are never registered or
364used, it is necessary to use the ENGINE_cleanup() function to
365correspondingly cleanup before program exit, if the caller wishes to avoid
366memory leaks. This mechanism uses an internal callback registration table
367so that any ENGINE API functionality that knows it requires cleanup can
368register its cleanup details to be called during ENGINE_cleanup(). This
369approach allows ENGINE_cleanup() to clean up after any ENGINE functionality
370at all that your program uses, yet doesn't automatically create linker
371dependencies to all possible ENGINE functionality - only the cleanup
372callbacks required by the functionality you do use will be required by the
373linker.
374
375The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
376the program and loaded into memory at run-time) does not mean they are
377"registered" or called into use by OpenSSL automatically - that behaviour
378is something for the application to have control over. Some applications
379will want to allow the user to specify exactly which ENGINE they want used
380if any is to be used at all. Others may prefer to load all support and have
381OpenSSL automatically use at run-time any ENGINE that is able to
382successfully initialise - ie. to assume that this corresponds to
383acceleration hardware attached to the machine or some such thing. There are
384probably numerous other ways in which applications may prefer to handle
385things, so we will simply illustrate the consequences as they apply to a
386couple of simple cases and leave developers to consider these and the
387source code to openssl's builtin utilities as guides.
388
389I<Using a specific ENGINE implementation>
390
391Here we'll assume an application has been configured by its user or admin
392to want to use the "ACME" ENGINE if it is available in the version of
393OpenSSL the application was compiled with. If it is available, it should be
394used by default for all RSA, DSA, and symmetric cipher operation, otherwise
395OpenSSL should use its builtin software as per usual. The following code
396illustrates how to approach this;
397
398 ENGINE *e;
399 const char *engine_id = "ACME";
400 ENGINE_load_builtin_engines();
401 e = ENGINE_by_id(engine_id);
402 if(!e)
403 /* the engine isn't available */
404 return;
405 if(!ENGINE_init(e)) {
406 /* the engine couldn't initialise, release 'e' */
407 ENGINE_free(e);
408 return;
409 }
410 if(!ENGINE_set_default_RSA(e))
411 /* This should only happen when 'e' can't initialise, but the previous
412 * statement suggests it did. */
413 abort();
414 ENGINE_set_default_DSA(e);
415 ENGINE_set_default_ciphers(e);
416 /* Release the functional reference from ENGINE_init() */
417 ENGINE_finish(e);
418 /* Release the structural reference from ENGINE_by_id() */
419 ENGINE_free(e);
420
421I<Automatically using builtin ENGINE implementations>
422
423Here we'll assume we want to load and register all ENGINE implementations
424bundled with OpenSSL, such that for any cryptographic algorithm required by
425OpenSSL - if there is an ENGINE that implements it and can be initialise,
426it should be used. The following code illustrates how this can work;
427
428 /* Load all bundled ENGINEs into memory and make them visible */
429 ENGINE_load_builtin_engines();
430 /* Register all of them for every algorithm they collectively implement */
431 ENGINE_register_all_complete();
432
433That's all that's required. Eg. the next time OpenSSL tries to set up an
434RSA key, any bundled ENGINEs that implement RSA_METHOD will be passed to
435ENGINE_init() and if any of those succeed, that ENGINE will be set as the
436default for use with RSA from then on.
437
438=head2 Advanced configuration support
439
440There is a mechanism supported by the ENGINE framework that allows each
441ENGINE implementation to define an arbitrary set of configuration
442"commands" and expose them to OpenSSL and any applications based on
443OpenSSL. This mechanism is entirely based on the use of name-value pairs
444and and assumes ASCII input (no unicode or UTF for now!), so it is ideal if
445applications want to provide a transparent way for users to provide
446arbitrary configuration "directives" directly to such ENGINEs. It is also
447possible for the application to dynamically interrogate the loaded ENGINE
448implementations for the names, descriptions, and input flags of their
449available "control commands", providing a more flexible configuration
450scheme. However, if the user is expected to know which ENGINE device he/she
451is using (in the case of specialised hardware, this goes without saying)
452then applications may not need to concern themselves with discovering the
453supported control commands and simply prefer to allow settings to passed
454into ENGINEs exactly as they are provided by the user.
455
456Before illustrating how control commands work, it is worth mentioning what
457they are typically used for. Broadly speaking there are two uses for
458control commands; the first is to provide the necessary details to the
459implementation (which may know nothing at all specific to the host system)
460so that it can be initialised for use. This could include the path to any
461driver or config files it needs to load, required network addresses,
462smart-card identifiers, passwords to initialise password-protected devices,
463logging information, etc etc. This class of commands typically needs to be
464passed to an ENGINE B<before> attempting to initialise it, ie. before
465calling ENGINE_init(). The other class of commands consist of settings or
466operations that tweak certain behaviour or cause certain operations to take
467place, and these commands may work either before or after ENGINE_init(), or
468in same cases both. ENGINE implementations should provide indications of
469this in the descriptions attached to builtin control commands and/or in
470external product documentation.
471
472I<Issuing control commands to an ENGINE>
473
474Let's illustrate by example; a function for which the caller supplies the
475name of the ENGINE it wishes to use, a table of string-pairs for use before
476initialisation, and another table for use after initialisation. Note that
477the string-pairs used for control commands consist of a command "name"
478followed by the command "parameter" - the parameter could be NULL in some
479cases but the name can not. This function should initialise the ENGINE
480(issuing the "pre" commands beforehand and the "post" commands afterwards)
481and set it as the default for everything except RAND and then return a
482boolean success or failure.
483
484 int generic_load_engine_fn(const char *engine_id,
485 const char **pre_cmds, int pre_num,
486 const char **post_cmds, int post_num)
487 {
488 ENGINE *e = ENGINE_by_id(engine_id);
489 if(!e) return 0;
490 while(pre_num--) {
491 if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
492 fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
493 pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
494 ENGINE_free(e);
495 return 0;
496 }
497 pre_cmds += 2;
498 }
499 if(!ENGINE_init(e)) {
500 fprintf(stderr, "Failed initialisation\n");
501 ENGINE_free(e);
502 return 0;
503 }
504 /* ENGINE_init() returned a functional reference, so free the structural
505 * reference from ENGINE_by_id(). */
506 ENGINE_free(e);
507 while(post_num--) {
508 if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
509 fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
510 post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
511 ENGINE_finish(e);
512 return 0;
513 }
514 post_cmds += 2;
515 }
516 ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
517 /* Success */
518 return 1;
519 }
520
521Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
522relax the semantics of the function - if set non-zero it will only return
523failure if the ENGINE supported the given command name but failed while
524executing it, if the ENGINE doesn't support the command name it will simply
525return success without doing anything. In this case we assume the user is
526only supplying commands specific to the given ENGINE so we set this to
527FALSE.
528
529I<Discovering supported control commands>
530
531It is possible to discover at run-time the names, numerical-ids, descriptions
532and input parameters of the control commands supported from a structural
533reference to any ENGINE. It is first important to note that some control
534commands are defined by OpenSSL itself and it will intercept and handle these
535control commands on behalf of the ENGINE, ie. the ENGINE's ctrl() handler is not
536used for the control command. openssl/engine.h defines a symbol,
537ENGINE_CMD_BASE, that all control commands implemented by ENGINEs from. Any
538command value lower than this symbol is considered a "generic" command is
539handled directly by the OpenSSL core routines.
540
541It is using these "core" control commands that one can discover the the control
542commands implemented by a given ENGINE, specifically the commands;
543
544 #define ENGINE_HAS_CTRL_FUNCTION 10
545 #define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11
546 #define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12
547 #define ENGINE_CTRL_GET_CMD_FROM_NAME 13
548 #define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14
549 #define ENGINE_CTRL_GET_NAME_FROM_CMD 15
550 #define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16
551 #define ENGINE_CTRL_GET_DESC_FROM_CMD 17
552 #define ENGINE_CTRL_GET_CMD_FLAGS 18
553
554Whilst these commands are automatically processed by the OpenSSL framework code,
555they use various properties exposed by each ENGINE by which to process these
556queries. An ENGINE has 3 properties it exposes that can affect this behaviour;
557it can supply a ctrl() handler, it can specify ENGINE_FLAGS_MANUAL_CMD_CTRL in
558the ENGINE's flags, and it can expose an array of control command descriptions.
559If an ENGINE specifies the ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will
560simply pass all these "core" control commands directly to the ENGINE's ctrl()
561handler (and thus, it must have supplied one), so it is up to the ENGINE to
562reply to these "discovery" commands itself. If that flag is not set, then the
563OpenSSL framework code will work with the following rules;
564
565 if no ctrl() handler supplied;
566 ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
567 all other commands fail.
568 if a ctrl() handler was supplied but no array of control commands;
569 ENGINE_HAS_CTRL_FUNCTION returns TRUE,
570 all other commands fail.
571 if a ctrl() handler and array of control commands was supplied;
572 ENGINE_HAS_CTRL_FUNCTION returns TRUE,
573 all other commands proceed processing ...
574
575If the ENGINE's array of control commands is empty then all other commands will
576fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns the identifier of
577the first command supported by the ENGINE, ENGINE_GET_NEXT_CMD_TYPE takes the
578identifier of a command supported by the ENGINE and returns the next command
579identifier or fails if there are no more, ENGINE_CMD_FROM_NAME takes a string
580name for a command and returns the corresponding identifier or fails if no such
581command name exists, and the remaining commands take a command identifier and
582return properties of the corresponding commands. All except
583ENGINE_CTRL_GET_FLAGS return the string length of a command name or description,
584or populate a supplied character buffer with a copy of the command name or
585description. ENGINE_CTRL_GET_FLAGS returns a bitwise-OR'd mask of the following
586possible values;
587
588 #define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001
589 #define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002
590 #define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004
591 #define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008
592
593If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are purely
594informational to the caller - this flag will prevent the command being usable
595for any higher-level ENGINE functions such as ENGINE_ctrl_cmd_string().
596"INTERNAL" commands are not intended to be exposed to text-based configuration
597by applications, administrations, users, etc. These can support arbitrary
598operations via ENGINE_ctrl(), including passing to and/or from the control
599commands data of any arbitrary type. These commands are supported in the
600discovery mechanisms simply to allow applications determinie if an ENGINE
601supports certain specific commands it might want to use (eg. application "foo"
602might query various ENGINEs to see if they implement "FOO_GET_VENDOR_LOGO_GIF" -
603and ENGINE could therefore decide whether or not to support this "foo"-specific
604extension).
605
606=head2 Future developments
607
608The ENGINE API and internal architecture is currently being reviewed. Slated for
609possible release in 0.9.8 is support for transparent loading of "dynamic"
610ENGINEs (built as self-contained shared-libraries). This would allow ENGINE
611implementations to be provided independantly of OpenSSL libraries and/or
612OpenSSL-based applications, and would also remove any requirement for
613applications to explicitly use the "dynamic" ENGINE to bind to shared-library
614implementations.
615
616=head1 SEE ALSO
617
618L<rsa(3)|rsa(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, L<rand(3)|rand(3)>,
619L<RSA_new_method(3)|RSA_new_method(3)>
620
621=cut
diff --git a/src/lib/libcrypto/doc/evp.pod b/src/lib/libcrypto/doc/evp.pod
deleted file mode 100644
index b3ca14314f..0000000000
--- a/src/lib/libcrypto/doc/evp.pod
+++ /dev/null
@@ -1,45 +0,0 @@
1=pod
2
3=head1 NAME
4
5evp - high-level cryptographic functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11=head1 DESCRIPTION
12
13The EVP library provides a high-level interface to cryptographic
14functions.
15
16B<EVP_Seal>I<...> and B<EVP_Open>I<...> provide public key encryption
17and decryption to implement digital "envelopes".
18
19The B<EVP_Sign>I<...> and B<EVP_Verify>I<...> functions implement
20digital signatures.
21
22Symmetric encryption is available with the B<EVP_Encrypt>I<...>
23functions. The B<EVP_Digest>I<...> functions provide message digests.
24
25Algorithms are loaded with OpenSSL_add_all_algorithms(3).
26
27All the symmetric algorithms (ciphers) and digests can be replaced by ENGINE
28modules providing alternative implementations. If ENGINE implementations of
29ciphers or digests are registered as defaults, then the various EVP functions
30will automatically use those implementations automatically in preference to
31built in software implementations. For more information, consult the engine(3)
32man page.
33
34=head1 SEE ALSO
35
36L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
37L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
38L<EVP_OpenInit(3)|EVP_OpenInit(3)>,
39L<EVP_SealInit(3)|EVP_SealInit(3)>,
40L<EVP_SignInit(3)|EVP_SignInit(3)>,
41L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
42L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>,
43L<engine(3)|engine(3)>
44
45=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 45ac53ffc1..0000000000
--- a/src/lib/libcrypto/doc/rsa.pod
+++ /dev/null
@@ -1,123 +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 #include <openssl/engine.h>
11
12 RSA * RSA_new(void);
13 void RSA_free(RSA *rsa);
14
15 int RSA_public_encrypt(int flen, unsigned char *from,
16 unsigned char *to, RSA *rsa, int padding);
17 int RSA_private_decrypt(int flen, unsigned char *from,
18 unsigned char *to, RSA *rsa, int padding);
19 int RSA_private_encrypt(int flen, unsigned char *from,
20 unsigned char *to, RSA *rsa,int padding);
21 int RSA_public_decrypt(int flen, unsigned char *from,
22 unsigned char *to, RSA *rsa,int padding);
23
24 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
25 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
26 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
27 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
28
29 int RSA_size(const RSA *rsa);
30
31 RSA *RSA_generate_key(int num, unsigned long e,
32 void (*callback)(int,int,void *), void *cb_arg);
33
34 int RSA_check_key(RSA *rsa);
35
36 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
37 void RSA_blinding_off(RSA *rsa);
38
39 void RSA_set_default_method(const RSA_METHOD *meth);
40 const RSA_METHOD *RSA_get_default_method(void);
41 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
42 const RSA_METHOD *RSA_get_method(const RSA *rsa);
43 RSA_METHOD *RSA_PKCS1_SSLeay(void);
44 RSA_METHOD *RSA_null_method(void);
45 int RSA_flags(const RSA *rsa);
46 RSA *RSA_new_method(ENGINE *engine);
47
48 int RSA_print(BIO *bp, RSA *x, int offset);
49 int RSA_print_fp(FILE *fp, RSA *x, int offset);
50
51 int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
52 int (*dup_func)(), void (*free_func)());
53 int RSA_set_ex_data(RSA *r,int idx,char *arg);
54 char *RSA_get_ex_data(RSA *r, int idx);
55
56 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
57 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
58 RSA *rsa);
59 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
60 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
61 RSA *rsa);
62
63=head1 DESCRIPTION
64
65These functions implement RSA public key encryption and signatures
66as defined in PKCS #1 v2.0 [RFC 2437].
67
68The B<RSA> structure consists of several BIGNUM components. It can
69contain public as well as private RSA keys:
70
71 struct
72 {
73 BIGNUM *n; // public modulus
74 BIGNUM *e; // public exponent
75 BIGNUM *d; // private exponent
76 BIGNUM *p; // secret prime factor
77 BIGNUM *q; // secret prime factor
78 BIGNUM *dmp1; // d mod (p-1)
79 BIGNUM *dmq1; // d mod (q-1)
80 BIGNUM *iqmp; // q^-1 mod p
81 // ...
82 };
83 RSA
84
85In public keys, the private exponent and the related secret values are
86B<NULL>.
87
88B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private
89keys, but the RSA operations are much faster when these values are
90available.
91
92Note that RSA keys may use non-standard B<RSA_METHOD> implementations,
93either directly or by the use of B<ENGINE> modules. In some cases (eg. an
94ENGINE providing support for hardware-embedded keys), these BIGNUM values
95will not be used by the implementation or may be used for alternative data
96storage. For this reason, applications should generally avoid using RSA
97structure elements directly and instead use API functions to query or
98modify keys.
99
100=head1 CONFORMING TO
101
102SSL, PKCS #1 v2.0
103
104=head1 PATENTS
105
106RSA was covered by a US patent which expired in September 2000.
107
108=head1 SEE ALSO
109
110L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>,
111L<rand(3)|rand(3)>, L<engine(3)|engine(3)>, L<RSA_new(3)|RSA_new(3)>,
112L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
113L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>,
114L<RSA_generate_key(3)|RSA_generate_key(3)>,
115L<RSA_check_key(3)|RSA_check_key(3)>,
116L<RSA_blinding_on(3)|RSA_blinding_on(3)>,
117L<RSA_set_method(3)|RSA_set_method(3)>, L<RSA_print(3)|RSA_print(3)>,
118L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
119L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
120L<RSA_sign_ASN1_OCTET_STRING(3)|RSA_sign_ASN1_OCTET_STRING(3)>,
121L<RSA_padding_add_PKCS1_type_1(3)|RSA_padding_add_PKCS1_type_1(3)>
122
123=cut
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
deleted file mode 100644
index aa0669eb7a..0000000000
--- a/src/lib/libcrypto/dsa/dsa.h
+++ /dev/null
@@ -1,272 +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 OPENSSL_NO_DSA
69#error DSA is disabled.
70#endif
71
72#ifndef OPENSSL_NO_BIO
73#include <openssl/bio.h>
74#endif
75#include <openssl/bn.h>
76#include <openssl/crypto.h>
77#include <openssl/ossl_typ.h>
78#ifndef OPENSSL_NO_DH
79# include <openssl/dh.h>
80#endif
81
82#define OPENSSL_DSA_MAX_MODULUS_BITS 3072
83
84#define DSA_FLAG_CACHE_MONT_P 0x01
85#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA
86 * implementation now uses constant time
87 * modular exponentiation for secret exponents
88 * by default. This flag causes the
89 * faster variable sliding window method to
90 * be used for all exponents.
91 */
92
93/* If this flag is set external DSA_METHOD callbacks are allowed in FIPS mode
94 * it is then the applications responsibility to ensure the external method
95 * is compliant.
96 */
97
98#define DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW 0x04
99
100#if defined(OPENSSL_FIPS)
101#define FIPS_DSA_SIZE_T int
102#endif
103
104#ifdef __cplusplus
105extern "C" {
106#endif
107
108typedef struct dsa_st DSA;
109
110typedef struct DSA_SIG_st
111 {
112 BIGNUM *r;
113 BIGNUM *s;
114 } DSA_SIG;
115
116typedef struct dsa_method {
117 const char *name;
118 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
119 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
120 BIGNUM **rp);
121 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
122 DSA_SIG *sig, DSA *dsa);
123 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
124 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
125 BN_MONT_CTX *in_mont);
126 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
127 const BIGNUM *m, BN_CTX *ctx,
128 BN_MONT_CTX *m_ctx); /* Can be null */
129 int (*init)(DSA *dsa);
130 int (*finish)(DSA *dsa);
131 int flags;
132 char *app_data;
133} DSA_METHOD;
134
135struct dsa_st
136 {
137 /* This first variable is used to pick up errors where
138 * a DSA is passed instead of of a EVP_PKEY */
139 int pad;
140 long version;
141 int write_params;
142 BIGNUM *p;
143 BIGNUM *q; /* == 20 */
144 BIGNUM *g;
145
146 BIGNUM *pub_key; /* y public key */
147 BIGNUM *priv_key; /* x private key */
148
149 BIGNUM *kinv; /* Signing pre-calc */
150 BIGNUM *r; /* Signing pre-calc */
151
152 int flags;
153 /* Normally used to cache montgomery values */
154 char *method_mont_p;
155 int references;
156 CRYPTO_EX_DATA ex_data;
157 const DSA_METHOD *meth;
158 /* functional reference if 'meth' is ENGINE-provided */
159 ENGINE *engine;
160 };
161
162#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
163 (char *(*)())d2i_DSAparams,(char *)(x))
164#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
165 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
166#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
167 (unsigned char *)(x))
168#define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \
169 (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x))
170#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \
171 (unsigned char *)(x))
172
173
174DSA_SIG * DSA_SIG_new(void);
175void DSA_SIG_free(DSA_SIG *a);
176int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
177DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length);
178
179DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
180int DSA_do_verify(const unsigned char *dgst,int dgst_len,
181 DSA_SIG *sig,DSA *dsa);
182
183const DSA_METHOD *DSA_OpenSSL(void);
184
185void DSA_set_default_method(const DSA_METHOD *);
186const DSA_METHOD *DSA_get_default_method(void);
187int DSA_set_method(DSA *dsa, const DSA_METHOD *);
188
189DSA * DSA_new(void);
190DSA * DSA_new_method(ENGINE *engine);
191void DSA_free (DSA *r);
192/* "up" the DSA object's reference count */
193int DSA_up_ref(DSA *r);
194int DSA_size(const DSA *);
195 /* next 4 return -1 on error */
196int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
197int DSA_sign(int type,const unsigned char *dgst,int dlen,
198 unsigned char *sig, unsigned int *siglen, DSA *dsa);
199int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
200 const unsigned char *sigbuf, int siglen, DSA *dsa);
201int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
202 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
203int DSA_set_ex_data(DSA *d, int idx, void *arg);
204void *DSA_get_ex_data(DSA *d, int idx);
205
206DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
207DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
208DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
209DSA * DSA_generate_parameters(int bits,
210 unsigned char *seed,int seed_len,
211 int *counter_ret, unsigned long *h_ret,void
212 (*callback)(int, int, void *),void *cb_arg);
213int DSA_generate_key(DSA *a);
214int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
215int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
216int i2d_DSAparams(const DSA *a,unsigned char **pp);
217
218#ifndef OPENSSL_NO_BIO
219int DSAparams_print(BIO *bp, const DSA *x);
220int DSA_print(BIO *bp, const DSA *x, int off);
221#endif
222#ifndef OPENSSL_NO_FP_API
223int DSAparams_print_fp(FILE *fp, const DSA *x);
224int DSA_print_fp(FILE *bp, const DSA *x, int off);
225#endif
226
227#define DSS_prime_checks 50
228/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:
229 * 50 rounds of Rabin-Miller */
230#define DSA_is_prime(n, callback, cb_arg) \
231 BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
232
233#ifndef OPENSSL_NO_DH
234/* Convert DSA structure (key or just parameters) into DH structure
235 * (be careful to avoid small subgroup attacks when using this!) */
236DH *DSA_dup_DH(const DSA *r);
237#endif
238
239/* BEGIN ERROR CODES */
240/* The following lines are auto generated by the script mkerr.pl. Any changes
241 * made after this point may be overwritten when the script is next run.
242 */
243void ERR_load_DSA_strings(void);
244
245/* Error codes for the DSA functions. */
246
247/* Function codes. */
248#define DSA_F_D2I_DSA_SIG 110
249#define DSA_F_DSAPARAMS_PRINT 100
250#define DSA_F_DSAPARAMS_PRINT_FP 101
251#define DSA_F_DSA_DO_SIGN 112
252#define DSA_F_DSA_DO_VERIFY 113
253#define DSA_F_DSA_NEW_METHOD 103
254#define DSA_F_DSA_PRINT 104
255#define DSA_F_DSA_PRINT_FP 105
256#define DSA_F_DSA_SIGN 106
257#define DSA_F_DSA_SIGN_SETUP 107
258#define DSA_F_DSA_SIG_NEW 109
259#define DSA_F_DSA_VERIFY 108
260#define DSA_F_I2D_DSA_SIG 111
261#define DSA_F_SIG_CB 114
262
263/* Reason codes. */
264#define DSA_R_BAD_Q_VALUE 102
265#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
266#define DSA_R_MISSING_PARAMETERS 101
267#define DSA_R_MODULUS_TOO_LARGE 103
268
269#ifdef __cplusplus
270}
271#endif
272#endif
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
deleted file mode 100644
index 23fce555aa..0000000000
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ /dev/null
@@ -1,140 +0,0 @@
1/* dsa_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dsa.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64
65/* Override the default new methods */
66static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
67{
68 if(operation == ASN1_OP_NEW_PRE) {
69 DSA_SIG *sig;
70 sig = OPENSSL_malloc(sizeof(DSA_SIG));
71 sig->r = NULL;
72 sig->s = NULL;
73 *pval = (ASN1_VALUE *)sig;
74 if(sig) return 2;
75 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
76 return 0;
77 }
78 return 1;
79}
80
81ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
82 ASN1_SIMPLE(DSA_SIG, r, CBIGNUM),
83 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
84} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)
85
86IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG)
87
88/* Override the default free and new methods */
89static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
90{
91 if(operation == ASN1_OP_NEW_PRE) {
92 *pval = (ASN1_VALUE *)DSA_new();
93 if(*pval) return 2;
94 return 0;
95 } else if(operation == ASN1_OP_FREE_PRE) {
96 DSA_free((DSA *)*pval);
97 *pval = NULL;
98 return 2;
99 }
100 return 1;
101}
102
103ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
104 ASN1_SIMPLE(DSA, version, LONG),
105 ASN1_SIMPLE(DSA, p, BIGNUM),
106 ASN1_SIMPLE(DSA, q, BIGNUM),
107 ASN1_SIMPLE(DSA, g, BIGNUM),
108 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
109 ASN1_SIMPLE(DSA, priv_key, BIGNUM)
110} ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)
111
112IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPrivateKey, DSAPrivateKey)
113
114ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
115 ASN1_SIMPLE(DSA, p, BIGNUM),
116 ASN1_SIMPLE(DSA, q, BIGNUM),
117 ASN1_SIMPLE(DSA, g, BIGNUM),
118} ASN1_SEQUENCE_END_cb(DSA, DSAparams)
119
120IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams)
121
122/* DSA public key is a bit trickier... its effectively a CHOICE type
123 * decided by a field called write_params which can either write out
124 * just the public key as an INTEGER or the parameters and public key
125 * in a SEQUENCE
126 */
127
128ASN1_SEQUENCE(dsa_pub_internal) = {
129 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
130 ASN1_SIMPLE(DSA, p, BIGNUM),
131 ASN1_SIMPLE(DSA, q, BIGNUM),
132 ASN1_SIMPLE(DSA, g, BIGNUM)
133} ASN1_SEQUENCE_END_name(DSA, dsa_pub_internal)
134
135ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
136 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
137 ASN1_EX_COMBINE(0, 0, dsa_pub_internal)
138} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params)
139
140IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
deleted file mode 100644
index d7fac69154..0000000000
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ /dev/null
@@ -1,114 +0,0 @@
1/* crypto/dsa/dsa_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DSA,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSA,0,reason)
70
71static ERR_STRING_DATA DSA_str_functs[]=
72 {
73{ERR_FUNC(DSA_F_D2I_DSA_SIG), "d2i_DSA_SIG"},
74{ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"},
75{ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"},
76{ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"},
77{ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"},
78{ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"},
79{ERR_FUNC(DSA_F_DSA_PRINT), "DSA_print"},
80{ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"},
81{ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"},
82{ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"},
83{ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"},
84{ERR_FUNC(DSA_F_DSA_VERIFY), "DSA_verify"},
85{ERR_FUNC(DSA_F_I2D_DSA_SIG), "i2d_DSA_SIG"},
86{ERR_FUNC(DSA_F_SIG_CB), "SIG_CB"},
87{0,NULL}
88 };
89
90static ERR_STRING_DATA DSA_str_reasons[]=
91 {
92{ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"},
93{ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"},
94{ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"},
95{ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"},
96{0,NULL}
97 };
98
99#endif
100
101void ERR_load_DSA_strings(void)
102 {
103 static int init=1;
104
105 if (init)
106 {
107 init=0;
108#ifndef OPENSSL_NO_ERR
109 ERR_load_strings(0,DSA_str_functs);
110 ERR_load_strings(0,DSA_str_reasons);
111#endif
112
113 }
114 }
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
deleted file mode 100644
index e40afeea51..0000000000
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ /dev/null
@@ -1,305 +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 EVP_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 EVP_sha1()
70#endif
71
72#ifndef OPENSSL_NO_SHA
73
74#include <stdio.h>
75#include <time.h>
76#include "cryptlib.h"
77#include <openssl/evp.h>
78#include <openssl/bn.h>
79#include <openssl/dsa.h>
80#include <openssl/rand.h>
81#include <openssl/sha.h>
82
83#ifndef OPENSSL_FIPS
84DSA *DSA_generate_parameters(int bits,
85 unsigned char *seed_in, int seed_len,
86 int *counter_ret, unsigned long *h_ret,
87 void (*callback)(int, int, void *),
88 void *cb_arg)
89 {
90 int ok=0;
91 unsigned char seed[SHA_DIGEST_LENGTH];
92 unsigned char md[SHA_DIGEST_LENGTH];
93 unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
94 BIGNUM *r0,*W,*X,*c,*test;
95 BIGNUM *g=NULL,*q=NULL,*p=NULL;
96 BN_MONT_CTX *mont=NULL;
97 int k,n=0,i,b,m=0;
98 int counter=0;
99 int r=0;
100 BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL;
101 unsigned int h=2;
102 DSA *ret=NULL;
103
104 if (bits < 512) bits=512;
105 bits=(bits+63)/64*64;
106
107 if (seed_len < 20)
108 seed_in = NULL; /* seed buffer too small -- ignore */
109 if (seed_len > 20)
110 seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
111 * but our internal buffers are restricted to 160 bits*/
112 if ((seed_in != NULL) && (seed_len == 20))
113 memcpy(seed,seed_in,seed_len);
114
115 if ((ctx=BN_CTX_new()) == NULL) goto err;
116 if ((ctx2=BN_CTX_new()) == NULL) goto err;
117 if ((ctx3=BN_CTX_new()) == NULL) goto err;
118 if ((ret=DSA_new()) == NULL) goto err;
119
120 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
121
122 BN_CTX_start(ctx2);
123 r0 = BN_CTX_get(ctx2);
124 g = BN_CTX_get(ctx2);
125 W = BN_CTX_get(ctx2);
126 q = BN_CTX_get(ctx2);
127 X = BN_CTX_get(ctx2);
128 c = BN_CTX_get(ctx2);
129 p = BN_CTX_get(ctx2);
130 test = BN_CTX_get(ctx2);
131 if (test == NULL) goto err;
132
133 if (!BN_lshift(test,BN_value_one(),bits-1)) goto err;
134
135 for (;;)
136 {
137 for (;;) /* find q */
138 {
139 int seed_is_random;
140
141 /* step 1 */
142 if (callback != NULL) callback(0,m++,cb_arg);
143
144 if (!seed_len)
145 {
146 RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH);
147 seed_is_random = 1;
148 }
149 else
150 {
151 seed_is_random = 0;
152 seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
153 }
154 memcpy(buf,seed,SHA_DIGEST_LENGTH);
155 memcpy(buf2,seed,SHA_DIGEST_LENGTH);
156 /* precompute "SEED + 1" for step 7: */
157 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
158 {
159 buf[i]++;
160 if (buf[i] != 0) break;
161 }
162
163 /* step 2 */
164 EVP_Digest(seed,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
165 EVP_Digest(buf,SHA_DIGEST_LENGTH,buf2,NULL,HASH, NULL);
166 for (i=0; i<SHA_DIGEST_LENGTH; i++)
167 md[i]^=buf2[i];
168
169 /* step 3 */
170 md[0]|=0x80;
171 md[SHA_DIGEST_LENGTH-1]|=0x01;
172 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
173
174 /* step 4 */
175 r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, cb_arg, seed_is_random);
176 if (r > 0)
177 break;
178 if (r != 0)
179 goto err;
180
181 /* do a callback call */
182 /* step 5 */
183 }
184
185 if (callback != NULL) callback(2,0,cb_arg);
186 if (callback != NULL) callback(3,0,cb_arg);
187
188 /* step 6 */
189 counter=0;
190 /* "offset = 2" */
191
192 n=(bits-1)/160;
193 b=(bits-1)-n*160;
194
195 for (;;)
196 {
197 if (callback != NULL && counter != 0)
198 callback(0,counter,cb_arg);
199
200 /* step 7 */
201 if (!BN_zero(W)) goto err;
202 /* now 'buf' contains "SEED + offset - 1" */
203 for (k=0; k<=n; k++)
204 {
205 /* obtain "SEED + offset + k" by incrementing: */
206 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
207 {
208 buf[i]++;
209 if (buf[i] != 0) break;
210 }
211
212 EVP_Digest(buf,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
213
214 /* step 8 */
215 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
216 goto err;
217 if (!BN_lshift(r0,r0,160*k)) goto err;
218 if (!BN_add(W,W,r0)) goto err;
219 }
220
221 /* more of step 8 */
222 if (!BN_mask_bits(W,bits-1)) goto err;
223 if (!BN_copy(X,W)) goto err;
224 if (!BN_add(X,X,test)) goto err;
225
226 /* step 9 */
227 if (!BN_lshift1(r0,q)) goto err;
228 if (!BN_mod(c,X,r0,ctx)) goto err;
229 if (!BN_sub(r0,c,BN_value_one())) goto err;
230 if (!BN_sub(p,X,r0)) goto err;
231
232 /* step 10 */
233 if (BN_cmp(p,test) >= 0)
234 {
235 /* step 11 */
236 r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, cb_arg, 1);
237 if (r > 0)
238 goto end; /* found it */
239 if (r != 0)
240 goto err;
241 }
242
243 /* step 13 */
244 counter++;
245 /* "offset = offset + n + 1" */
246
247 /* step 14 */
248 if (counter >= 4096) break;
249 }
250 }
251end:
252 if (callback != NULL) callback(2,1,cb_arg);
253
254 /* We now need to generate g */
255 /* Set r0=(p-1)/q */
256 if (!BN_sub(test,p,BN_value_one())) goto err;
257 if (!BN_div(r0,NULL,test,q,ctx)) goto err;
258
259 if (!BN_set_word(test,h)) goto err;
260 if (!BN_MONT_CTX_set(mont,p,ctx)) goto err;
261
262 for (;;)
263 {
264 /* g=test^r0%p */
265 if (!BN_mod_exp_mont(g,test,r0,p,ctx,mont)) goto err;
266 if (!BN_is_one(g)) break;
267 if (!BN_add(test,test,BN_value_one())) goto err;
268 h++;
269 }
270
271 if (callback != NULL) callback(3,1,cb_arg);
272
273 ok=1;
274err:
275 if (!ok)
276 {
277 if (ret != NULL) DSA_free(ret);
278 }
279 else
280 {
281 ret->p=BN_dup(p);
282 ret->q=BN_dup(q);
283 ret->g=BN_dup(g);
284 if (ret->p == NULL || ret->q == NULL || ret->g == NULL)
285 {
286 ok=0;
287 goto err;
288 }
289 if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);
290 if (counter_ret != NULL) *counter_ret=counter;
291 if (h_ret != NULL) *h_ret=h;
292 }
293 if (ctx != NULL) BN_CTX_free(ctx);
294 if (ctx2 != NULL)
295 {
296 BN_CTX_end(ctx2);
297 BN_CTX_free(ctx2);
298 }
299 if (ctx3 != NULL) BN_CTX_free(ctx3);
300 if (mont != NULL) BN_MONT_CTX_free(mont);
301 return(ok?ret:NULL);
302 }
303#endif /* ndef OPENSSL_FIPS */
304#endif /* ndef OPENSSL_NO_SHA */
305
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
deleted file mode 100644
index 980b6dc2d3..0000000000
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ /dev/null
@@ -1,121 +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 OPENSSL_NO_SHA
60#include <stdio.h>
61#include <time.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66
67#ifndef OPENSSL_FIPS
68int DSA_generate_key(DSA *dsa)
69 {
70 int ok=0;
71 BN_CTX *ctx=NULL;
72 BIGNUM *pub_key=NULL,*priv_key=NULL;
73
74 if ((ctx=BN_CTX_new()) == NULL) goto err;
75
76 if (dsa->priv_key == NULL)
77 {
78 if ((priv_key=BN_new()) == NULL) goto err;
79 }
80 else
81 priv_key=dsa->priv_key;
82
83 do
84 if (!BN_rand_range(priv_key,dsa->q)) goto err;
85 while (BN_is_zero(priv_key));
86
87 if (dsa->pub_key == NULL)
88 {
89 if ((pub_key=BN_new()) == NULL) goto err;
90 }
91 else
92 pub_key=dsa->pub_key;
93
94 {
95 BIGNUM local_prk;
96 BIGNUM *prk;
97
98 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
99 {
100 BN_init(&local_prk);
101 prk = &local_prk;
102 BN_with_flags(prk, priv_key, BN_FLG_EXP_CONSTTIME);
103 }
104 else
105 prk = priv_key;
106
107 if (!BN_mod_exp(pub_key,dsa->g,prk,dsa->p,ctx)) goto err;
108 }
109
110 dsa->priv_key=priv_key;
111 dsa->pub_key=pub_key;
112 ok=1;
113
114err:
115 if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);
116 if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);
117 if (ctx != NULL) BN_CTX_free(ctx);
118 return(ok);
119 }
120#endif
121#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
deleted file mode 100644
index 4171af24c6..0000000000
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ /dev/null
@@ -1,308 +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#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT;
71
72static const DSA_METHOD *default_DSA_method = NULL;
73
74void DSA_set_default_method(const DSA_METHOD *meth)
75 {
76 default_DSA_method = meth;
77 }
78
79const DSA_METHOD *DSA_get_default_method(void)
80 {
81 if(!default_DSA_method)
82 default_DSA_method = DSA_OpenSSL();
83 return default_DSA_method;
84 }
85
86DSA *DSA_new(void)
87 {
88 return DSA_new_method(NULL);
89 }
90
91int DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
92 {
93 /* NB: The caller is specifically setting a method, so it's not up to us
94 * to deal with which ENGINE it comes from. */
95 const DSA_METHOD *mtmp;
96 mtmp = dsa->meth;
97 if (mtmp->finish) mtmp->finish(dsa);
98#ifndef OPENSSL_NO_ENGINE
99 if (dsa->engine)
100 {
101 ENGINE_finish(dsa->engine);
102 dsa->engine = NULL;
103 }
104#endif
105 dsa->meth = meth;
106 if (meth->init) meth->init(dsa);
107 return 1;
108 }
109
110DSA *DSA_new_method(ENGINE *engine)
111 {
112 DSA *ret;
113
114 ret=(DSA *)OPENSSL_malloc(sizeof(DSA));
115 if (ret == NULL)
116 {
117 DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
118 return(NULL);
119 }
120 ret->meth = DSA_get_default_method();
121#ifndef OPENSSL_NO_ENGINE
122 if (engine)
123 {
124 if (!ENGINE_init(engine))
125 {
126 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
127 OPENSSL_free(ret);
128 return NULL;
129 }
130 ret->engine = engine;
131 }
132 else
133 ret->engine = ENGINE_get_default_DSA();
134 if(ret->engine)
135 {
136 ret->meth = ENGINE_get_DSA(ret->engine);
137 if(!ret->meth)
138 {
139 DSAerr(DSA_F_DSA_NEW_METHOD,
140 ERR_R_ENGINE_LIB);
141 ENGINE_finish(ret->engine);
142 OPENSSL_free(ret);
143 return NULL;
144 }
145 }
146#endif
147
148 ret->pad=0;
149 ret->version=0;
150 ret->write_params=1;
151 ret->p=NULL;
152 ret->q=NULL;
153 ret->g=NULL;
154
155 ret->pub_key=NULL;
156 ret->priv_key=NULL;
157
158 ret->kinv=NULL;
159 ret->r=NULL;
160 ret->method_mont_p=NULL;
161
162 ret->references=1;
163 ret->flags=ret->meth->flags;
164 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
165 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
166 {
167#ifndef OPENSSL_NO_ENGINE
168 if (ret->engine)
169 ENGINE_finish(ret->engine);
170#endif
171 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
172 OPENSSL_free(ret);
173 ret=NULL;
174 }
175
176 return(ret);
177 }
178
179void DSA_free(DSA *r)
180 {
181 int i;
182
183 if (r == NULL) return;
184
185 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA);
186#ifdef REF_PRINT
187 REF_PRINT("DSA",r);
188#endif
189 if (i > 0) return;
190#ifdef REF_CHECK
191 if (i < 0)
192 {
193 fprintf(stderr,"DSA_free, bad reference count\n");
194 abort();
195 }
196#endif
197
198 if(r->meth->finish)
199 r->meth->finish(r);
200#ifndef OPENSSL_NO_ENGINE
201 if(r->engine)
202 ENGINE_finish(r->engine);
203#endif
204
205 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);
206
207 if (r->p != NULL) BN_clear_free(r->p);
208 if (r->q != NULL) BN_clear_free(r->q);
209 if (r->g != NULL) BN_clear_free(r->g);
210 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
211 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
212 if (r->kinv != NULL) BN_clear_free(r->kinv);
213 if (r->r != NULL) BN_clear_free(r->r);
214 OPENSSL_free(r);
215 }
216
217int DSA_up_ref(DSA *r)
218 {
219 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA);
220#ifdef REF_PRINT
221 REF_PRINT("DSA",r);
222#endif
223#ifdef REF_CHECK
224 if (i < 2)
225 {
226 fprintf(stderr, "DSA_up_ref, bad reference count\n");
227 abort();
228 }
229#endif
230 return ((i > 1) ? 1 : 0);
231 }
232
233int DSA_size(const DSA *r)
234 {
235 int ret,i;
236 ASN1_INTEGER bs;
237 unsigned char buf[4]; /* 4 bytes looks really small.
238 However, i2d_ASN1_INTEGER() will not look
239 beyond the first byte, as long as the second
240 parameter is NULL. */
241
242 i=BN_num_bits(r->q);
243 bs.length=(i+7)/8;
244 bs.data=buf;
245 bs.type=V_ASN1_INTEGER;
246 /* If the top bit is set the asn1 encoding is 1 larger. */
247 buf[0]=0xff;
248
249 i=i2d_ASN1_INTEGER(&bs,NULL);
250 i+=i; /* r and s */
251 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
252 return(ret);
253 }
254
255int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
256 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
257 {
258 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, argl, argp,
259 new_func, dup_func, free_func);
260 }
261
262int DSA_set_ex_data(DSA *d, int idx, void *arg)
263 {
264 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
265 }
266
267void *DSA_get_ex_data(DSA *d, int idx)
268 {
269 return(CRYPTO_get_ex_data(&d->ex_data,idx));
270 }
271
272#ifndef OPENSSL_NO_DH
273DH *DSA_dup_DH(const DSA *r)
274 {
275 /* DSA has p, q, g, optional pub_key, optional priv_key.
276 * DH has p, optional length, g, optional pub_key, optional priv_key.
277 */
278
279 DH *ret = NULL;
280
281 if (r == NULL)
282 goto err;
283 ret = DH_new();
284 if (ret == NULL)
285 goto err;
286 if (r->p != NULL)
287 if ((ret->p = BN_dup(r->p)) == NULL)
288 goto err;
289 if (r->q != NULL)
290 ret->length = BN_num_bits(r->q);
291 if (r->g != NULL)
292 if ((ret->g = BN_dup(r->g)) == NULL)
293 goto err;
294 if (r->pub_key != NULL)
295 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
296 goto err;
297 if (r->priv_key != NULL)
298 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
299 goto err;
300
301 return ret;
302
303 err:
304 if (ret != NULL)
305 DH_free(ret);
306 return NULL;
307 }
308#endif
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
deleted file mode 100644
index 5de5fc7e91..0000000000
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ /dev/null
@@ -1,393 +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
68#ifndef OPENSSL_FIPS
69static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
70static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
71static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
72 DSA *dsa);
73static int dsa_init(DSA *dsa);
74static int dsa_finish(DSA *dsa);
75static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
76 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
77 BN_MONT_CTX *in_mont);
78static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
79 const BIGNUM *m, BN_CTX *ctx,
80 BN_MONT_CTX *m_ctx);
81
82static DSA_METHOD openssl_dsa_meth = {
83"OpenSSL DSA method",
84dsa_do_sign,
85dsa_sign_setup,
86dsa_do_verify,
87dsa_mod_exp,
88dsa_bn_mod_exp,
89dsa_init,
90dsa_finish,
910,
92NULL
93};
94
95const DSA_METHOD *DSA_OpenSSL(void)
96{
97 return &openssl_dsa_meth;
98}
99
100static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
101 {
102 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
103 BIGNUM m;
104 BIGNUM xr;
105 BN_CTX *ctx=NULL;
106 int i,reason=ERR_R_BN_LIB;
107 DSA_SIG *ret=NULL;
108
109 BN_init(&m);
110 BN_init(&xr);
111
112 if (!dsa->p || !dsa->q || !dsa->g)
113 {
114 reason=DSA_R_MISSING_PARAMETERS;
115 goto err;
116 }
117
118 s=BN_new();
119 if (s == NULL) goto err;
120
121 i=BN_num_bytes(dsa->q); /* should be 20 */
122 if ((dlen > i) || (dlen > 50))
123 {
124 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
125 goto err;
126 }
127
128 ctx=BN_CTX_new();
129 if (ctx == NULL) goto err;
130
131 if ((dsa->kinv == NULL) || (dsa->r == NULL))
132 {
133 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
134 }
135 else
136 {
137 kinv=dsa->kinv;
138 dsa->kinv=NULL;
139 r=dsa->r;
140 dsa->r=NULL;
141 }
142
143 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
144
145 /* Compute s = inv(k) (m + xr) mod q */
146 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
147 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
148 if (BN_cmp(s,dsa->q) > 0)
149 BN_sub(s,s,dsa->q);
150 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
151
152 ret=DSA_SIG_new();
153 if (ret == NULL) goto err;
154 ret->r = r;
155 ret->s = s;
156
157err:
158 if (!ret)
159 {
160 DSAerr(DSA_F_DSA_DO_SIGN,reason);
161 BN_free(r);
162 BN_free(s);
163 }
164 if (ctx != NULL) BN_CTX_free(ctx);
165 BN_clear_free(&m);
166 BN_clear_free(&xr);
167 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
168 BN_clear_free(kinv);
169 return(ret);
170 }
171
172static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
173 {
174 BN_CTX *ctx;
175 BIGNUM k,kq,*K,*kinv=NULL,*r=NULL;
176 int ret=0;
177
178 if (!dsa->p || !dsa->q || !dsa->g)
179 {
180 DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);
181 return 0;
182 }
183
184 BN_init(&k);
185 BN_init(&kq);
186
187 if (ctx_in == NULL)
188 {
189 if ((ctx=BN_CTX_new()) == NULL) goto err;
190 }
191 else
192 ctx=ctx_in;
193
194 if ((r=BN_new()) == NULL) goto err;
195
196 /* Get random k */
197 do
198 if (!BN_rand_range(&k, dsa->q)) goto err;
199 while (BN_is_zero(&k));
200 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
201 {
202 BN_set_flags(&k, BN_FLG_EXP_CONSTTIME);
203 }
204
205 if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
206 {
207 if (!BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p,
208 CRYPTO_LOCK_DSA,
209 dsa->p, ctx))
210 goto err;
211 }
212
213 /* Compute r = (g^k mod p) mod q */
214
215 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
216 {
217 if (!BN_copy(&kq, &k)) goto err;
218
219 /* We do not want timing information to leak the length of k,
220 * so we compute g^k using an equivalent exponent of fixed length.
221 *
222 * (This is a kludge that we need because the BN_mod_exp_mont()
223 * does not let us specify the desired timing behaviour.) */
224
225 if (!BN_add(&kq, &kq, dsa->q)) goto err;
226 if (BN_num_bits(&kq) <= BN_num_bits(dsa->q))
227 {
228 if (!BN_add(&kq, &kq, dsa->q)) goto err;
229 }
230
231 K = &kq;
232 }
233 else
234 {
235 K = &k;
236 }
237 if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,K,dsa->p,ctx,
238 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
239 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
240
241 /* Compute part of 's = inv(k) (m + xr) mod q' */
242 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
243
244 if (*kinvp != NULL) BN_clear_free(*kinvp);
245 *kinvp=kinv;
246 kinv=NULL;
247 if (*rp != NULL) BN_clear_free(*rp);
248 *rp=r;
249 ret=1;
250err:
251 if (!ret)
252 {
253 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
254 if (kinv != NULL) BN_clear_free(kinv);
255 if (r != NULL) BN_clear_free(r);
256 }
257 if (ctx_in == NULL) BN_CTX_free(ctx);
258 if (kinv != NULL) BN_clear_free(kinv);
259 BN_clear_free(&k);
260 BN_clear_free(&kq);
261 return(ret);
262 }
263
264static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
265 DSA *dsa)
266 {
267 BN_CTX *ctx;
268 BIGNUM u1,u2,t1;
269 BN_MONT_CTX *mont=NULL;
270 int ret = -1;
271 if (!dsa->p || !dsa->q || !dsa->g)
272 {
273 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MISSING_PARAMETERS);
274 return -1;
275 }
276
277 if (BN_num_bits(dsa->q) != 160)
278 {
279 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE);
280 return -1;
281 }
282
283 if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS)
284 {
285 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE);
286 return -1;
287 }
288
289 BN_init(&u1);
290 BN_init(&u2);
291 BN_init(&t1);
292
293 if ((ctx=BN_CTX_new()) == NULL) goto err;
294
295 if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0)
296 {
297 ret = 0;
298 goto err;
299 }
300 if (BN_is_zero(sig->s) || sig->s->neg || BN_ucmp(sig->s, dsa->q) >= 0)
301 {
302 ret = 0;
303 goto err;
304 }
305
306 /* Calculate W = inv(S) mod Q
307 * save W in u2 */
308 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
309
310 /* save M in u1 */
311 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
312
313 /* u1 = M * w mod q */
314 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
315
316 /* u2 = r * w mod q */
317 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
318
319
320 if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
321 {
322 mont = BN_MONT_CTX_set_locked(
323 (BN_MONT_CTX **)&dsa->method_mont_p,
324 CRYPTO_LOCK_DSA, dsa->p, ctx);
325 if (!mont)
326 goto err;
327 }
328
329#if 0
330 {
331 BIGNUM t2;
332
333 BN_init(&t2);
334 /* v = ( g^u1 * y^u2 mod p ) mod q */
335 /* let t1 = g ^ u1 mod p */
336 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
337 /* let t2 = y ^ u2 mod p */
338 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
339 /* let u1 = t1 * t2 mod p */
340 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
341 BN_free(&t2);
342 }
343 /* let u1 = u1 mod q */
344 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
345#else
346 {
347 if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
348 dsa->p,ctx,mont)) goto err;
349 /* BN_copy(&u1,&t1); */
350 /* let u1 = u1 mod q */
351 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
352 }
353#endif
354 /* V is now in u1. If the signature is correct, it will be
355 * equal to R. */
356 ret=(BN_ucmp(&u1, sig->r) == 0);
357
358 err:
359 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
360 if (ctx != NULL) BN_CTX_free(ctx);
361 BN_free(&u1);
362 BN_free(&u2);
363 BN_free(&t1);
364 return(ret);
365 }
366
367static int dsa_init(DSA *dsa)
368{
369 dsa->flags|=DSA_FLAG_CACHE_MONT_P;
370 return(1);
371}
372
373static int dsa_finish(DSA *dsa)
374{
375 if(dsa->method_mont_p)
376 BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
377 return(1);
378}
379
380static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
381 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
382 BN_MONT_CTX *in_mont)
383{
384 return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
385}
386
387static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
388 const BIGNUM *m, BN_CTX *ctx,
389 BN_MONT_CTX *m_ctx)
390{
391 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
392}
393#endif
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
deleted file mode 100644
index 37c65efb20..0000000000
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ /dev/null
@@ -1,106 +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#ifndef OPENSSL_NO_ENGINE
68#include <openssl/engine.h>
69#endif
70#include <openssl/fips.h>
71
72DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
73 {
74#ifdef OPENSSL_FIPS
75 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
76 && !FIPS_dsa_check(dsa))
77 return NULL;
78#endif
79 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
80 }
81
82int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
83 unsigned int *siglen, DSA *dsa)
84 {
85 DSA_SIG *s;
86 s=DSA_do_sign(dgst,dlen,dsa);
87 if (s == NULL)
88 {
89 *siglen=0;
90 return(0);
91 }
92 *siglen=i2d_DSA_SIG(s,&sig);
93 DSA_SIG_free(s);
94 return(1);
95 }
96
97int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
98 {
99#ifdef OPENSSL_FIPS
100 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
101 && !FIPS_dsa_check(dsa))
102 return 0;
103#endif
104 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
105 }
106
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
deleted file mode 100644
index c9784bed48..0000000000
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ /dev/null
@@ -1,103 +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#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71#include <openssl/fips.h>
72
73int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
74 DSA *dsa)
75 {
76#ifdef OPENSSL_FIPS
77 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
78 && !FIPS_dsa_check(dsa))
79 return -1;
80#endif
81 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
82 }
83
84/* data has already been hashed (probably with SHA or SHA-1). */
85/* returns
86 * 1: correct signature
87 * 0: incorrect signature
88 * -1: error
89 */
90int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
91 const unsigned char *sigbuf, int siglen, DSA *dsa)
92 {
93 DSA_SIG *s;
94 int ret=-1;
95
96 s = DSA_SIG_new();
97 if (s == NULL) return(ret);
98 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
99 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
100err:
101 DSA_SIG_free(s);
102 return(ret);
103 }
diff --git a/src/lib/libcrypto/dso/dso.h b/src/lib/libcrypto/dso/dso.h
deleted file mode 100644
index aa721f7feb..0000000000
--- a/src/lib/libcrypto/dso/dso.h
+++ /dev/null
@@ -1,322 +0,0 @@
1/* dso.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_DSO_H
60#define HEADER_DSO_H
61
62#include <openssl/crypto.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68/* These values are used as commands to DSO_ctrl() */
69#define DSO_CTRL_GET_FLAGS 1
70#define DSO_CTRL_SET_FLAGS 2
71#define DSO_CTRL_OR_FLAGS 3
72
73/* By default, DSO_load() will translate the provided filename into a form
74 * typical for the platform (more specifically the DSO_METHOD) using the
75 * dso_name_converter function of the method. Eg. win32 will transform "blah"
76 * into "blah.dll", and dlfcn will transform it into "libblah.so". The
77 * behaviour can be overriden by setting the name_converter callback in the DSO
78 * object (using DSO_set_name_converter()). This callback could even utilise
79 * the DSO_METHOD's converter too if it only wants to override behaviour for
80 * one or two possible DSO methods. However, the following flag can be set in a
81 * DSO to prevent *any* native name-translation at all - eg. if the caller has
82 * prompted the user for a path to a driver library so the filename should be
83 * interpreted as-is. */
84#define DSO_FLAG_NO_NAME_TRANSLATION 0x01
85/* An extra flag to give if only the extension should be added as
86 * translation. This is obviously only of importance on Unix and
87 * other operating systems where the translation also may prefix
88 * the name with something, like 'lib', and ignored everywhere else.
89 * This flag is also ignored if DSO_FLAG_NO_NAME_TRANSLATION is used
90 * at the same time. */
91#define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY 0x02
92
93/* The following flag controls the translation of symbol names to upper
94 * case. This is currently only being implemented for OpenVMS.
95 */
96#define DSO_FLAG_UPCASE_SYMBOL 0x10
97
98
99typedef void (*DSO_FUNC_TYPE)(void);
100
101typedef struct dso_st DSO;
102
103/* The function prototype used for method functions (or caller-provided
104 * callbacks) that transform filenames. They are passed a DSO structure pointer
105 * (or NULL if they are to be used independantly of a DSO object) and a
106 * filename to transform. They should either return NULL (if there is an error
107 * condition) or a newly allocated string containing the transformed form that
108 * the caller will need to free with OPENSSL_free() when done. */
109typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);
110
111typedef struct dso_meth_st
112 {
113 const char *name;
114 /* Loads a shared library, NB: new DSO_METHODs must ensure that a
115 * successful load populates the loaded_filename field, and likewise a
116 * successful unload OPENSSL_frees and NULLs it out. */
117 int (*dso_load)(DSO *dso);
118 /* Unloads a shared library */
119 int (*dso_unload)(DSO *dso);
120 /* Binds a variable */
121 void *(*dso_bind_var)(DSO *dso, const char *symname);
122 /* Binds a function - assumes a return type of DSO_FUNC_TYPE.
123 * This should be cast to the real function prototype by the
124 * caller. Platforms that don't have compatible representations
125 * for different prototypes (this is possible within ANSI C)
126 * are highly unlikely to have shared libraries at all, let
127 * alone a DSO_METHOD implemented for them. */
128 DSO_FUNC_TYPE (*dso_bind_func)(DSO *dso, const char *symname);
129
130/* I don't think this would actually be used in any circumstances. */
131#if 0
132 /* Unbinds a variable */
133 int (*dso_unbind_var)(DSO *dso, char *symname, void *symptr);
134 /* Unbinds a function */
135 int (*dso_unbind_func)(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
136#endif
137 /* The generic (yuck) "ctrl()" function. NB: Negative return
138 * values (rather than zero) indicate errors. */
139 long (*dso_ctrl)(DSO *dso, int cmd, long larg, void *parg);
140 /* The default DSO_METHOD-specific function for converting filenames to
141 * a canonical native form. */
142 DSO_NAME_CONVERTER_FUNC dso_name_converter;
143
144 /* [De]Initialisation handlers. */
145 int (*init)(DSO *dso);
146 int (*finish)(DSO *dso);
147 } DSO_METHOD;
148
149/**********************************************************************/
150/* The low-level handle type used to refer to a loaded shared library */
151
152struct dso_st
153 {
154 DSO_METHOD *meth;
155 /* Standard dlopen uses a (void *). Win32 uses a HANDLE. VMS
156 * doesn't use anything but will need to cache the filename
157 * for use in the dso_bind handler. All in all, let each
158 * method control its own destiny. "Handles" and such go in
159 * a STACK. */
160 STACK *meth_data;
161 int references;
162 int flags;
163 /* For use by applications etc ... use this for your bits'n'pieces,
164 * don't touch meth_data! */
165 CRYPTO_EX_DATA ex_data;
166 /* If this callback function pointer is set to non-NULL, then it will
167 * be used on DSO_load() in place of meth->dso_name_converter. NB: This
168 * should normally set using DSO_set_name_converter(). */
169 DSO_NAME_CONVERTER_FUNC name_converter;
170 /* This is populated with (a copy of) the platform-independant
171 * filename used for this DSO. */
172 char *filename;
173 /* This is populated with (a copy of) the translated filename by which
174 * the DSO was actually loaded. It is NULL iff the DSO is not currently
175 * loaded. NB: This is here because the filename translation process
176 * may involve a callback being invoked more than once not only to
177 * convert to a platform-specific form, but also to try different
178 * filenames in the process of trying to perform a load. As such, this
179 * variable can be used to indicate (a) whether this DSO structure
180 * corresponds to a loaded library or not, and (b) the filename with
181 * which it was actually loaded. */
182 char *loaded_filename;
183 };
184
185
186DSO * DSO_new(void);
187DSO * DSO_new_method(DSO_METHOD *method);
188int DSO_free(DSO *dso);
189int DSO_flags(DSO *dso);
190int DSO_up_ref(DSO *dso);
191long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg);
192
193/* This function sets the DSO's name_converter callback. If it is non-NULL,
194 * then it will be used instead of the associated DSO_METHOD's function. If
195 * oldcb is non-NULL then it is set to the function pointer value being
196 * replaced. Return value is non-zero for success. */
197int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
198 DSO_NAME_CONVERTER_FUNC *oldcb);
199/* These functions can be used to get/set the platform-independant filename
200 * used for a DSO. NB: set will fail if the DSO is already loaded. */
201const char *DSO_get_filename(DSO *dso);
202int DSO_set_filename(DSO *dso, const char *filename);
203/* This function will invoke the DSO's name_converter callback to translate a
204 * filename, or if the callback isn't set it will instead use the DSO_METHOD's
205 * converter. If "filename" is NULL, the "filename" in the DSO itself will be
206 * used. If the DSO_FLAG_NO_NAME_TRANSLATION flag is set, then the filename is
207 * simply duplicated. NB: This function is usually called from within a
208 * DSO_METHOD during the processing of a DSO_load() call, and is exposed so that
209 * caller-created DSO_METHODs can do the same thing. A non-NULL return value
210 * will need to be OPENSSL_free()'d. */
211char *DSO_convert_filename(DSO *dso, const char *filename);
212/* If the DSO is currently loaded, this returns the filename that it was loaded
213 * under, otherwise it returns NULL. So it is also useful as a test as to
214 * whether the DSO is currently loaded. NB: This will not necessarily return
215 * the same value as DSO_convert_filename(dso, dso->filename), because the
216 * DSO_METHOD's load function may have tried a variety of filenames (with
217 * and/or without the aid of the converters) before settling on the one it
218 * actually loaded. */
219const char *DSO_get_loaded_filename(DSO *dso);
220
221void DSO_set_default_method(DSO_METHOD *meth);
222DSO_METHOD *DSO_get_default_method(void);
223DSO_METHOD *DSO_get_method(DSO *dso);
224DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth);
225
226/* The all-singing all-dancing load function, you normally pass NULL
227 * for the first and third parameters. Use DSO_up and DSO_free for
228 * subsequent reference count handling. Any flags passed in will be set
229 * in the constructed DSO after its init() function but before the
230 * load operation. If 'dso' is non-NULL, 'flags' is ignored. */
231DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags);
232
233/* This function binds to a variable inside a shared library. */
234void *DSO_bind_var(DSO *dso, const char *symname);
235
236/* This function binds to a function inside a shared library. */
237DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname);
238
239/* This method is the default, but will beg, borrow, or steal whatever
240 * method should be the default on any particular platform (including
241 * DSO_METH_null() if necessary). */
242DSO_METHOD *DSO_METHOD_openssl(void);
243
244/* This method is defined for all platforms - if a platform has no
245 * DSO support then this will be the only method! */
246DSO_METHOD *DSO_METHOD_null(void);
247
248/* If DSO_DLFCN is defined, the standard dlfcn.h-style functions
249 * (dlopen, dlclose, dlsym, etc) will be used and incorporated into
250 * this method. If not, this method will return NULL. */
251DSO_METHOD *DSO_METHOD_dlfcn(void);
252
253/* If DSO_DL is defined, the standard dl.h-style functions (shl_load,
254 * shl_unload, shl_findsym, etc) will be used and incorporated into
255 * this method. If not, this method will return NULL. */
256DSO_METHOD *DSO_METHOD_dl(void);
257
258/* If WIN32 is defined, use DLLs. If not, return NULL. */
259DSO_METHOD *DSO_METHOD_win32(void);
260
261/* If VMS is defined, use shared images. If not, return NULL. */
262DSO_METHOD *DSO_METHOD_vms(void);
263
264/* BEGIN ERROR CODES */
265/* The following lines are auto generated by the script mkerr.pl. Any changes
266 * made after this point may be overwritten when the script is next run.
267 */
268void ERR_load_DSO_strings(void);
269
270/* Error codes for the DSO functions. */
271
272/* Function codes. */
273#define DSO_F_DLFCN_BIND_FUNC 100
274#define DSO_F_DLFCN_BIND_VAR 101
275#define DSO_F_DLFCN_LOAD 102
276#define DSO_F_DLFCN_NAME_CONVERTER 123
277#define DSO_F_DLFCN_UNLOAD 103
278#define DSO_F_DL_BIND_FUNC 104
279#define DSO_F_DL_BIND_VAR 105
280#define DSO_F_DL_LOAD 106
281#define DSO_F_DL_NAME_CONVERTER 124
282#define DSO_F_DL_UNLOAD 107
283#define DSO_F_DSO_BIND_FUNC 108
284#define DSO_F_DSO_BIND_VAR 109
285#define DSO_F_DSO_CONVERT_FILENAME 126
286#define DSO_F_DSO_CTRL 110
287#define DSO_F_DSO_FREE 111
288#define DSO_F_DSO_GET_FILENAME 127
289#define DSO_F_DSO_GET_LOADED_FILENAME 128
290#define DSO_F_DSO_LOAD 112
291#define DSO_F_DSO_NEW_METHOD 113
292#define DSO_F_DSO_SET_FILENAME 129
293#define DSO_F_DSO_SET_NAME_CONVERTER 122
294#define DSO_F_DSO_UP_REF 114
295#define DSO_F_VMS_BIND_VAR 115
296#define DSO_F_VMS_LOAD 116
297#define DSO_F_VMS_UNLOAD 117
298#define DSO_F_WIN32_BIND_FUNC 118
299#define DSO_F_WIN32_BIND_VAR 119
300#define DSO_F_WIN32_LOAD 120
301#define DSO_F_WIN32_NAME_CONVERTER 125
302#define DSO_F_WIN32_UNLOAD 121
303
304/* Reason codes. */
305#define DSO_R_CTRL_FAILED 100
306#define DSO_R_DSO_ALREADY_LOADED 110
307#define DSO_R_FILENAME_TOO_BIG 101
308#define DSO_R_FINISH_FAILED 102
309#define DSO_R_LOAD_FAILED 103
310#define DSO_R_NAME_TRANSLATION_FAILED 109
311#define DSO_R_NO_FILENAME 111
312#define DSO_R_NULL_HANDLE 104
313#define DSO_R_SET_FILENAME_FAILED 112
314#define DSO_R_STACK_ERROR 105
315#define DSO_R_SYM_FAILURE 106
316#define DSO_R_UNLOAD_FAILED 107
317#define DSO_R_UNSUPPORTED 108
318
319#ifdef __cplusplus
320}
321#endif
322#endif
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c
deleted file mode 100644
index d48b4202f2..0000000000
--- a/src/lib/libcrypto/dso/dso_dlfcn.c
+++ /dev/null
@@ -1,325 +0,0 @@
1/* dso_dlfcn.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifdef __linux
60#define _GNU_SOURCE
61#endif
62
63#include <stdio.h>
64#include "cryptlib.h"
65#include <openssl/dso.h>
66
67#ifndef DSO_DLFCN
68DSO_METHOD *DSO_METHOD_dlfcn(void)
69 {
70 return NULL;
71 }
72#else
73
74#ifdef HAVE_DLFCN_H
75#include <dlfcn.h>
76#endif
77
78/* Part of the hack in "dlfcn_load" ... */
79#define DSO_MAX_TRANSLATED_SIZE 256
80
81static int dlfcn_load(DSO *dso);
82static int dlfcn_unload(DSO *dso);
83static void *dlfcn_bind_var(DSO *dso, const char *symname);
84static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname);
85#if 0
86static int dlfcn_unbind(DSO *dso, char *symname, void *symptr);
87static int dlfcn_init(DSO *dso);
88static int dlfcn_finish(DSO *dso);
89static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg);
90#endif
91static char *dlfcn_name_converter(DSO *dso, const char *filename);
92
93static DSO_METHOD dso_meth_dlfcn = {
94 "OpenSSL 'dlfcn' shared library method",
95 dlfcn_load,
96 dlfcn_unload,
97 dlfcn_bind_var,
98 dlfcn_bind_func,
99/* For now, "unbind" doesn't exist */
100#if 0
101 NULL, /* unbind_var */
102 NULL, /* unbind_func */
103#endif
104 NULL, /* ctrl */
105 dlfcn_name_converter,
106 NULL, /* init */
107 NULL /* finish */
108 };
109
110DSO_METHOD *DSO_METHOD_dlfcn(void)
111 {
112 return(&dso_meth_dlfcn);
113 }
114
115/* Prior to using the dlopen() function, we should decide on the flag
116 * we send. There's a few different ways of doing this and it's a
117 * messy venn-diagram to match up which platforms support what. So
118 * as we don't have autoconf yet, I'm implementing a hack that could
119 * be hacked further relatively easily to deal with cases as we find
120 * them. Initially this is to cope with OpenBSD. */
121#if defined(__OpenBSD__) || defined(__NetBSD__)
122# ifdef DL_LAZY
123# define DLOPEN_FLAG DL_LAZY
124# else
125# ifdef RTLD_NOW
126# define DLOPEN_FLAG RTLD_NOW
127# else
128# define DLOPEN_FLAG 0
129# endif
130# endif
131#else
132# ifdef OPENSSL_SYS_SUNOS
133# define DLOPEN_FLAG 1
134# else
135# define DLOPEN_FLAG RTLD_NOW /* Hope this works everywhere else */
136# endif
137#endif
138
139/* For this DSO_METHOD, our meth_data STACK will contain;
140 * (i) the handle (void*) returned from dlopen().
141 */
142
143static int dlfcn_load(DSO *dso)
144 {
145 void *ptr = NULL;
146 /* See applicable comments in dso_dl.c */
147 char *filename = DSO_convert_filename(dso, NULL);
148
149 if(filename == NULL)
150 {
151 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME);
152 goto err;
153 }
154 ptr = dlopen(filename, DLOPEN_FLAG);
155 if(ptr == NULL)
156 {
157 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED);
158 ERR_add_error_data(4, "filename(", filename, "): ", dlerror());
159 goto err;
160 }
161 if(!sk_push(dso->meth_data, (char *)ptr))
162 {
163 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR);
164 goto err;
165 }
166 /* Success */
167 dso->loaded_filename = filename;
168 return(1);
169err:
170 /* Cleanup! */
171 if(filename != NULL)
172 OPENSSL_free(filename);
173 if(ptr != NULL)
174 dlclose(ptr);
175 return(0);
176}
177
178static int dlfcn_unload(DSO *dso)
179 {
180 void *ptr;
181 if(dso == NULL)
182 {
183 DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
184 return(0);
185 }
186 if(sk_num(dso->meth_data) < 1)
187 return(1);
188 ptr = (void *)sk_pop(dso->meth_data);
189 if(ptr == NULL)
190 {
191 DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE);
192 /* Should push the value back onto the stack in
193 * case of a retry. */
194 sk_push(dso->meth_data, (char *)ptr);
195 return(0);
196 }
197 /* For now I'm not aware of any errors associated with dlclose() */
198 dlclose(ptr);
199 return(1);
200 }
201
202static void *dlfcn_bind_var(DSO *dso, const char *symname)
203 {
204 void *ptr, *sym;
205
206 if((dso == NULL) || (symname == NULL))
207 {
208 DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
209 return(NULL);
210 }
211 if(sk_num(dso->meth_data) < 1)
212 {
213 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR);
214 return(NULL);
215 }
216 ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
217 if(ptr == NULL)
218 {
219 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE);
220 return(NULL);
221 }
222 sym = dlsym(ptr, symname);
223 if(sym == NULL)
224 {
225 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE);
226 ERR_add_error_data(4, "symname(", symname, "): ", dlerror());
227 return(NULL);
228 }
229 return(sym);
230 }
231
232static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
233 {
234 void *ptr;
235 DSO_FUNC_TYPE sym, *tsym = &sym;
236
237 if((dso == NULL) || (symname == NULL))
238 {
239 DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
240 return(NULL);
241 }
242 if(sk_num(dso->meth_data) < 1)
243 {
244 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR);
245 return(NULL);
246 }
247 ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
248 if(ptr == NULL)
249 {
250 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE);
251 return(NULL);
252 }
253 *(void**)(tsym) = dlsym(ptr, symname);
254 if(sym == NULL)
255 {
256 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE);
257 ERR_add_error_data(4, "symname(", symname, "): ", dlerror());
258 return(NULL);
259 }
260 return(sym);
261 }
262
263static char *dlfcn_name_converter(DSO *dso, const char *filename)
264 {
265 char *translated;
266 int len, rsize, transform;
267
268 len = strlen(filename);
269 rsize = len + 1;
270 transform = (strstr(filename, "/") == NULL);
271 if(transform)
272 {
273 /* We will convert this to "%s.so" or "lib%s.so" */
274 rsize += 3; /* The length of ".so" */
275 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
276 rsize += 3; /* The length of "lib" */
277 }
278 translated = OPENSSL_malloc(rsize);
279 if(translated == NULL)
280 {
281 DSOerr(DSO_F_DLFCN_NAME_CONVERTER,
282 DSO_R_NAME_TRANSLATION_FAILED);
283 return(NULL);
284 }
285 if(transform)
286 {
287 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
288 snprintf(translated, rsize, "lib%s.so", filename);
289 else
290 snprintf(translated, rsize, "%s.so", filename);
291 }
292 else
293 snprintf(translated, rsize, "%s", filename);
294 return(translated);
295 }
296
297#ifdef OPENSSL_FIPS
298static void dlfcn_ref_point(){}
299
300int DSO_pathbyaddr(void *addr,char *path,int sz)
301 {
302 Dl_info dli;
303 int len;
304
305 if (addr == NULL)
306 {
307 union { void(*f)(void); void *p; } t = { dlfcn_ref_point };
308 addr = t.p;
309 }
310
311 if (dladdr(addr,&dli))
312 {
313 len = (int)strlen(dli.dli_fname);
314 if (sz <= 0) return len+1;
315 if (len >= sz) len=sz-1;
316 memcpy(path,dli.dli_fname,len);
317 path[len++]=0;
318 return len;
319 }
320
321 ERR_add_error_data(4, "dlfcn_pathbyaddr(): ", dlerror());
322 return -1;
323 }
324#endif
325#endif /* DSO_DLFCN */
diff --git a/src/lib/libcrypto/dso/dso_err.c b/src/lib/libcrypto/dso/dso_err.c
deleted file mode 100644
index 581677cc36..0000000000
--- a/src/lib/libcrypto/dso/dso_err.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/* crypto/dso/dso_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/dso.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DSO,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSO,0,reason)
70
71static ERR_STRING_DATA DSO_str_functs[]=
72 {
73{ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"},
74{ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"},
75{ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"},
76{ERR_FUNC(DSO_F_DLFCN_NAME_CONVERTER), "DLFCN_NAME_CONVERTER"},
77{ERR_FUNC(DSO_F_DLFCN_UNLOAD), "DLFCN_UNLOAD"},
78{ERR_FUNC(DSO_F_DL_BIND_FUNC), "DL_BIND_FUNC"},
79{ERR_FUNC(DSO_F_DL_BIND_VAR), "DL_BIND_VAR"},
80{ERR_FUNC(DSO_F_DL_LOAD), "DL_LOAD"},
81{ERR_FUNC(DSO_F_DL_NAME_CONVERTER), "DL_NAME_CONVERTER"},
82{ERR_FUNC(DSO_F_DL_UNLOAD), "DL_UNLOAD"},
83{ERR_FUNC(DSO_F_DSO_BIND_FUNC), "DSO_bind_func"},
84{ERR_FUNC(DSO_F_DSO_BIND_VAR), "DSO_bind_var"},
85{ERR_FUNC(DSO_F_DSO_CONVERT_FILENAME), "DSO_convert_filename"},
86{ERR_FUNC(DSO_F_DSO_CTRL), "DSO_ctrl"},
87{ERR_FUNC(DSO_F_DSO_FREE), "DSO_free"},
88{ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"},
89{ERR_FUNC(DSO_F_DSO_GET_LOADED_FILENAME), "DSO_get_loaded_filename"},
90{ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"},
91{ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"},
92{ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"},
93{ERR_FUNC(DSO_F_DSO_SET_NAME_CONVERTER), "DSO_set_name_converter"},
94{ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"},
95{ERR_FUNC(DSO_F_VMS_BIND_VAR), "VMS_BIND_VAR"},
96{ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"},
97{ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"},
98{ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"},
99{ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"},
100{ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"},
101{ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"},
102{ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"},
103{0,NULL}
104 };
105
106static ERR_STRING_DATA DSO_str_reasons[]=
107 {
108{ERR_REASON(DSO_R_CTRL_FAILED) ,"control command failed"},
109{ERR_REASON(DSO_R_DSO_ALREADY_LOADED) ,"dso already loaded"},
110{ERR_REASON(DSO_R_FILENAME_TOO_BIG) ,"filename too big"},
111{ERR_REASON(DSO_R_FINISH_FAILED) ,"cleanup method function failed"},
112{ERR_REASON(DSO_R_LOAD_FAILED) ,"could not load the shared library"},
113{ERR_REASON(DSO_R_NAME_TRANSLATION_FAILED),"name translation failed"},
114{ERR_REASON(DSO_R_NO_FILENAME) ,"no filename"},
115{ERR_REASON(DSO_R_NULL_HANDLE) ,"a null shared library handle was used"},
116{ERR_REASON(DSO_R_SET_FILENAME_FAILED) ,"set filename failed"},
117{ERR_REASON(DSO_R_STACK_ERROR) ,"the meth_data stack is corrupt"},
118{ERR_REASON(DSO_R_SYM_FAILURE) ,"could not bind to the requested symbol name"},
119{ERR_REASON(DSO_R_UNLOAD_FAILED) ,"could not unload the shared library"},
120{ERR_REASON(DSO_R_UNSUPPORTED) ,"functionality not supported"},
121{0,NULL}
122 };
123
124#endif
125
126void ERR_load_DSO_strings(void)
127 {
128 static int init=1;
129
130 if (init)
131 {
132 init=0;
133#ifndef OPENSSL_NO_ERR
134 ERR_load_strings(0,DSO_str_functs);
135 ERR_load_strings(0,DSO_str_reasons);
136#endif
137
138 }
139 }
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c
deleted file mode 100644
index 48d9fdb25e..0000000000
--- a/src/lib/libcrypto/dso/dso_lib.c
+++ /dev/null
@@ -1,439 +0,0 @@
1/* dso_lib.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63
64static DSO_METHOD *default_DSO_meth = NULL;
65
66DSO *DSO_new(void)
67 {
68 return(DSO_new_method(NULL));
69 }
70
71void DSO_set_default_method(DSO_METHOD *meth)
72 {
73 default_DSO_meth = meth;
74 }
75
76DSO_METHOD *DSO_get_default_method(void)
77 {
78 return(default_DSO_meth);
79 }
80
81DSO_METHOD *DSO_get_method(DSO *dso)
82 {
83 return(dso->meth);
84 }
85
86DSO_METHOD *DSO_set_method(DSO *dso, DSO_METHOD *meth)
87 {
88 DSO_METHOD *mtmp;
89 mtmp = dso->meth;
90 dso->meth = meth;
91 return(mtmp);
92 }
93
94DSO *DSO_new_method(DSO_METHOD *meth)
95 {
96 DSO *ret;
97
98 if(default_DSO_meth == NULL)
99 /* We default to DSO_METH_openssl() which in turn defaults
100 * to stealing the "best available" method. Will fallback
101 * to DSO_METH_null() in the worst case. */
102 default_DSO_meth = DSO_METHOD_openssl();
103 ret = (DSO *)OPENSSL_malloc(sizeof(DSO));
104 if(ret == NULL)
105 {
106 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
107 return(NULL);
108 }
109 memset(ret, 0, sizeof(DSO));
110 ret->meth_data = sk_new_null();
111 if(ret->meth_data == NULL)
112 {
113 /* sk_new doesn't generate any errors so we do */
114 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
115 OPENSSL_free(ret);
116 return(NULL);
117 }
118 if(meth == NULL)
119 ret->meth = default_DSO_meth;
120 else
121 ret->meth = meth;
122 ret->references = 1;
123 if((ret->meth->init != NULL) && !ret->meth->init(ret))
124 {
125 OPENSSL_free(ret);
126 ret=NULL;
127 }
128 return(ret);
129 }
130
131int DSO_free(DSO *dso)
132 {
133 int i;
134
135 if(dso == NULL)
136 {
137 DSOerr(DSO_F_DSO_FREE,ERR_R_PASSED_NULL_PARAMETER);
138 return(0);
139 }
140
141 i=CRYPTO_add(&dso->references,-1,CRYPTO_LOCK_DSO);
142#ifdef REF_PRINT
143 REF_PRINT("DSO",dso);
144#endif
145 if(i > 0) return(1);
146#ifdef REF_CHECK
147 if(i < 0)
148 {
149 fprintf(stderr,"DSO_free, bad reference count\n");
150 abort();
151 }
152#endif
153
154 if((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso))
155 {
156 DSOerr(DSO_F_DSO_FREE,DSO_R_UNLOAD_FAILED);
157 return(0);
158 }
159
160 if((dso->meth->finish != NULL) && !dso->meth->finish(dso))
161 {
162 DSOerr(DSO_F_DSO_FREE,DSO_R_FINISH_FAILED);
163 return(0);
164 }
165
166 sk_free(dso->meth_data);
167 if(dso->filename != NULL)
168 OPENSSL_free(dso->filename);
169 if(dso->loaded_filename != NULL)
170 OPENSSL_free(dso->loaded_filename);
171
172 OPENSSL_free(dso);
173 return(1);
174 }
175
176int DSO_flags(DSO *dso)
177 {
178 return((dso == NULL) ? 0 : dso->flags);
179 }
180
181
182int DSO_up_ref(DSO *dso)
183 {
184 if (dso == NULL)
185 {
186 DSOerr(DSO_F_DSO_UP_REF,ERR_R_PASSED_NULL_PARAMETER);
187 return(0);
188 }
189
190 CRYPTO_add(&dso->references,1,CRYPTO_LOCK_DSO);
191 return(1);
192 }
193
194DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
195 {
196 DSO *ret;
197 int allocated = 0;
198
199 if(dso == NULL)
200 {
201 ret = DSO_new_method(meth);
202 if(ret == NULL)
203 {
204 DSOerr(DSO_F_DSO_LOAD,ERR_R_MALLOC_FAILURE);
205 goto err;
206 }
207 allocated = 1;
208 /* Pass the provided flags to the new DSO object */
209 if(DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0)
210 {
211 DSOerr(DSO_F_DSO_LOAD,DSO_R_CTRL_FAILED);
212 goto err;
213 }
214 }
215 else
216 ret = dso;
217 /* Don't load if we're currently already loaded */
218 if(ret->filename != NULL)
219 {
220 DSOerr(DSO_F_DSO_LOAD,DSO_R_DSO_ALREADY_LOADED);
221 goto err;
222 }
223 /* filename can only be NULL if we were passed a dso that already has
224 * one set. */
225 if(filename != NULL)
226 if(!DSO_set_filename(ret, filename))
227 {
228 DSOerr(DSO_F_DSO_LOAD,DSO_R_SET_FILENAME_FAILED);
229 goto err;
230 }
231 filename = ret->filename;
232 if(filename == NULL)
233 {
234 DSOerr(DSO_F_DSO_LOAD,DSO_R_NO_FILENAME);
235 goto err;
236 }
237 if(ret->meth->dso_load == NULL)
238 {
239 DSOerr(DSO_F_DSO_LOAD,DSO_R_UNSUPPORTED);
240 goto err;
241 }
242 if(!ret->meth->dso_load(ret))
243 {
244 DSOerr(DSO_F_DSO_LOAD,DSO_R_LOAD_FAILED);
245 goto err;
246 }
247 /* Load succeeded */
248 return(ret);
249err:
250 if(allocated)
251 DSO_free(ret);
252 return(NULL);
253 }
254
255void *DSO_bind_var(DSO *dso, const char *symname)
256 {
257 void *ret = NULL;
258
259 if((dso == NULL) || (symname == NULL))
260 {
261 DSOerr(DSO_F_DSO_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
262 return(NULL);
263 }
264 if(dso->meth->dso_bind_var == NULL)
265 {
266 DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_UNSUPPORTED);
267 return(NULL);
268 }
269 if((ret = dso->meth->dso_bind_var(dso, symname)) == NULL)
270 {
271 DSOerr(DSO_F_DSO_BIND_VAR,DSO_R_SYM_FAILURE);
272 return(NULL);
273 }
274 /* Success */
275 return(ret);
276 }
277
278DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname)
279 {
280 DSO_FUNC_TYPE ret = NULL;
281
282 if((dso == NULL) || (symname == NULL))
283 {
284 DSOerr(DSO_F_DSO_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
285 return(NULL);
286 }
287 if(dso->meth->dso_bind_func == NULL)
288 {
289 DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_UNSUPPORTED);
290 return(NULL);
291 }
292 if((ret = dso->meth->dso_bind_func(dso, symname)) == NULL)
293 {
294 DSOerr(DSO_F_DSO_BIND_FUNC,DSO_R_SYM_FAILURE);
295 return(NULL);
296 }
297 /* Success */
298 return(ret);
299 }
300
301/* I don't really like these *_ctrl functions very much to be perfectly
302 * honest. For one thing, I think I have to return a negative value for
303 * any error because possible DSO_ctrl() commands may return values
304 * such as "size"s that can legitimately be zero (making the standard
305 * "if(DSO_cmd(...))" form that works almost everywhere else fail at
306 * odd times. I'd prefer "output" values to be passed by reference and
307 * the return value as success/failure like usual ... but we conform
308 * when we must... :-) */
309long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
310 {
311 if(dso == NULL)
312 {
313 DSOerr(DSO_F_DSO_CTRL,ERR_R_PASSED_NULL_PARAMETER);
314 return(-1);
315 }
316 /* We should intercept certain generic commands and only pass control
317 * to the method-specific ctrl() function if it's something we don't
318 * handle. */
319 switch(cmd)
320 {
321 case DSO_CTRL_GET_FLAGS:
322 return dso->flags;
323 case DSO_CTRL_SET_FLAGS:
324 dso->flags = (int)larg;
325 return(0);
326 case DSO_CTRL_OR_FLAGS:
327 dso->flags |= (int)larg;
328 return(0);
329 default:
330 break;
331 }
332 if((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL))
333 {
334 DSOerr(DSO_F_DSO_CTRL,DSO_R_UNSUPPORTED);
335 return(-1);
336 }
337 return(dso->meth->dso_ctrl(dso,cmd,larg,parg));
338 }
339
340int DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
341 DSO_NAME_CONVERTER_FUNC *oldcb)
342 {
343 if(dso == NULL)
344 {
345 DSOerr(DSO_F_DSO_SET_NAME_CONVERTER,
346 ERR_R_PASSED_NULL_PARAMETER);
347 return(0);
348 }
349 if(oldcb)
350 *oldcb = dso->name_converter;
351 dso->name_converter = cb;
352 return(1);
353 }
354
355const char *DSO_get_filename(DSO *dso)
356 {
357 if(dso == NULL)
358 {
359 DSOerr(DSO_F_DSO_GET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
360 return(NULL);
361 }
362 return(dso->filename);
363 }
364
365int DSO_set_filename(DSO *dso, const char *filename)
366 {
367 char *copied;
368
369 if((dso == NULL) || (filename == NULL))
370 {
371 DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
372 return(0);
373 }
374 if(dso->loaded_filename)
375 {
376 DSOerr(DSO_F_DSO_SET_FILENAME,DSO_R_DSO_ALREADY_LOADED);
377 return(0);
378 }
379 /* We'll duplicate filename */
380 copied = OPENSSL_malloc(strlen(filename) + 1);
381 if(copied == NULL)
382 {
383 DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE);
384 return(0);
385 }
386 BUF_strlcpy(copied, filename, strlen(filename) + 1);
387 if(dso->filename)
388 OPENSSL_free(dso->filename);
389 dso->filename = copied;
390 return(1);
391 }
392
393char *DSO_convert_filename(DSO *dso, const char *filename)
394 {
395 char *result = NULL;
396
397 if(dso == NULL)
398 {
399 DSOerr(DSO_F_DSO_CONVERT_FILENAME,ERR_R_PASSED_NULL_PARAMETER);
400 return(NULL);
401 }
402 if(filename == NULL)
403 filename = dso->filename;
404 if(filename == NULL)
405 {
406 DSOerr(DSO_F_DSO_CONVERT_FILENAME,DSO_R_NO_FILENAME);
407 return(NULL);
408 }
409 if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
410 {
411 if(dso->name_converter != NULL)
412 result = dso->name_converter(dso, filename);
413 else if(dso->meth->dso_name_converter != NULL)
414 result = dso->meth->dso_name_converter(dso, filename);
415 }
416 if(result == NULL)
417 {
418 result = OPENSSL_malloc(strlen(filename) + 1);
419 if(result == NULL)
420 {
421 DSOerr(DSO_F_DSO_CONVERT_FILENAME,
422 ERR_R_MALLOC_FAILURE);
423 return(NULL);
424 }
425 BUF_strlcpy(result, filename, strlen(filename) + 1);
426 }
427 return(result);
428 }
429
430const char *DSO_get_loaded_filename(DSO *dso)
431 {
432 if(dso == NULL)
433 {
434 DSOerr(DSO_F_DSO_GET_LOADED_FILENAME,
435 ERR_R_PASSED_NULL_PARAMETER);
436 return(NULL);
437 }
438 return(dso->loaded_filename);
439 }
diff --git a/src/lib/libcrypto/dso/dso_null.c b/src/lib/libcrypto/dso/dso_null.c
deleted file mode 100644
index fa13a7cb0f..0000000000
--- a/src/lib/libcrypto/dso/dso_null.c
+++ /dev/null
@@ -1,86 +0,0 @@
1/* dso_null.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* This "NULL" method is provided as the fallback for systems that have
60 * no appropriate support for "shared-libraries". */
61
62#include <stdio.h>
63#include "cryptlib.h"
64#include <openssl/dso.h>
65
66static DSO_METHOD dso_meth_null = {
67 "NULL shared library method",
68 NULL, /* load */
69 NULL, /* unload */
70 NULL, /* bind_var */
71 NULL, /* bind_func */
72/* For now, "unbind" doesn't exist */
73#if 0
74 NULL, /* unbind_var */
75 NULL, /* unbind_func */
76#endif
77 NULL, /* ctrl */
78 NULL, /* init */
79 NULL /* finish */
80 };
81
82DSO_METHOD *DSO_METHOD_null(void)
83 {
84 return(&dso_meth_null);
85 }
86
diff --git a/src/lib/libcrypto/dso/dso_openssl.c b/src/lib/libcrypto/dso/dso_openssl.c
deleted file mode 100644
index a4395ebffe..0000000000
--- a/src/lib/libcrypto/dso/dso_openssl.c
+++ /dev/null
@@ -1,81 +0,0 @@
1/* dso_openssl.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dso.h>
62
63/* We just pinch the method from an appropriate "default" method. */
64
65DSO_METHOD *DSO_METHOD_openssl(void)
66 {
67#ifdef DEF_DSO_METHOD
68 return(DEF_DSO_METHOD());
69#elif defined(DSO_DLFCN)
70 return(DSO_METHOD_dlfcn());
71#elif defined(DSO_DL)
72 return(DSO_METHOD_dl());
73#elif defined(DSO_WIN32)
74 return(DSO_METHOD_win32());
75#elif defined(DSO_VMS)
76 return(DSO_METHOD_vms());
77#else
78 return(DSO_METHOD_null());
79#endif
80 }
81
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h
deleted file mode 100644
index 6d6a9b7127..0000000000
--- a/src/lib/libcrypto/ec/ec.h
+++ /dev/null
@@ -1,243 +0,0 @@
1/* crypto/ec/ec.h */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#ifndef HEADER_EC_H
57#define HEADER_EC_H
58
59#ifdef OPENSSL_NO_EC
60#error EC is disabled.
61#endif
62
63#include <openssl/bn.h>
64#include <openssl/symhacks.h>
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70
71typedef enum {
72 /* values as defined in X9.62 (ECDSA) and elsewhere */
73 POINT_CONVERSION_COMPRESSED = 2,
74 POINT_CONVERSION_UNCOMPRESSED = 4,
75 POINT_CONVERSION_HYBRID = 6
76} point_conversion_form_t;
77
78
79typedef struct ec_method_st EC_METHOD;
80
81typedef struct ec_group_st
82 /*
83 EC_METHOD *meth;
84 -- field definition
85 -- curve coefficients
86 -- optional generator with associated information (order, cofactor)
87 -- optional extra data (TODO: precomputed table for fast computation of multiples of generator)
88 */
89 EC_GROUP;
90
91typedef struct ec_point_st EC_POINT;
92
93
94/* EC_METHODs for curves over GF(p).
95 * EC_GFp_simple_method provides the basis for the optimized methods.
96 */
97const EC_METHOD *EC_GFp_simple_method(void);
98const EC_METHOD *EC_GFp_mont_method(void);
99#if 0
100const EC_METHOD *EC_GFp_recp_method(void); /* TODO */
101const EC_METHOD *EC_GFp_nist_method(void); /* TODO */
102#endif
103
104
105EC_GROUP *EC_GROUP_new(const EC_METHOD *);
106void EC_GROUP_free(EC_GROUP *);
107void EC_GROUP_clear_free(EC_GROUP *);
108int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
109
110const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
111
112
113/* We don't have types for field specifications and field elements in general.
114 * Otherwise we could declare
115 * int EC_GROUP_set_curve(EC_GROUP *, .....);
116 */
117int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
118int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
119
120/* EC_GROUP_new_GFp() calls EC_GROUP_new() and EC_GROUP_set_GFp()
121 * after choosing an appropriate EC_METHOD */
122EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
123
124int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
125EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
126int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
127int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
128
129EC_POINT *EC_POINT_new(const EC_GROUP *);
130void EC_POINT_free(EC_POINT *);
131void EC_POINT_clear_free(EC_POINT *);
132int EC_POINT_copy(EC_POINT *, const EC_POINT *);
133
134const EC_METHOD *EC_POINT_method_of(const EC_POINT *);
135
136int EC_POINT_set_to_infinity(const EC_GROUP *, EC_POINT *);
137int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
138 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
139int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
140 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
141int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
142 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
143int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
144 BIGNUM *x, BIGNUM *y, BN_CTX *);
145int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
146 const BIGNUM *x, int y_bit, BN_CTX *);
147
148size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
149 unsigned char *buf, size_t len, BN_CTX *);
150int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
151 const unsigned char *buf, size_t len, BN_CTX *);
152
153int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
154int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
155int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
156
157int EC_POINT_is_at_infinity(const EC_GROUP *, const EC_POINT *);
158int EC_POINT_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
159int EC_POINT_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
160
161int EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
162int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
163
164
165int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *);
166int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *);
167int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
168
169
170
171/* BEGIN ERROR CODES */
172/* The following lines are auto generated by the script mkerr.pl. Any changes
173 * made after this point may be overwritten when the script is next run.
174 */
175void ERR_load_EC_strings(void);
176
177/* Error codes for the EC functions. */
178
179/* Function codes. */
180#define EC_F_COMPUTE_WNAF 143
181#define EC_F_EC_GFP_MONT_FIELD_DECODE 133
182#define EC_F_EC_GFP_MONT_FIELD_ENCODE 134
183#define EC_F_EC_GFP_MONT_FIELD_MUL 131
184#define EC_F_EC_GFP_MONT_FIELD_SQR 132
185#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100
186#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101
187#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102
188#define EC_F_EC_GFP_SIMPLE_OCT2POINT 103
189#define EC_F_EC_GFP_SIMPLE_POINT2OCT 104
190#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137
191#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
192#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
193#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
194#define EC_F_EC_GROUP_COPY 106
195#define EC_F_EC_GROUP_GET0_GENERATOR 139
196#define EC_F_EC_GROUP_GET_COFACTOR 140
197#define EC_F_EC_GROUP_GET_CURVE_GFP 130
198#define EC_F_EC_GROUP_GET_ORDER 141
199#define EC_F_EC_GROUP_NEW 108
200#define EC_F_EC_GROUP_PRECOMPUTE_MULT 142
201#define EC_F_EC_GROUP_SET_CURVE_GFP 109
202#define EC_F_EC_GROUP_SET_EXTRA_DATA 110
203#define EC_F_EC_GROUP_SET_GENERATOR 111
204#define EC_F_EC_POINTS_MAKE_AFFINE 136
205#define EC_F_EC_POINTS_MUL 138
206#define EC_F_EC_POINT_ADD 112
207#define EC_F_EC_POINT_CMP 113
208#define EC_F_EC_POINT_COPY 114
209#define EC_F_EC_POINT_DBL 115
210#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116
211#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117
212#define EC_F_EC_POINT_IS_AT_INFINITY 118
213#define EC_F_EC_POINT_IS_ON_CURVE 119
214#define EC_F_EC_POINT_MAKE_AFFINE 120
215#define EC_F_EC_POINT_NEW 121
216#define EC_F_EC_POINT_OCT2POINT 122
217#define EC_F_EC_POINT_POINT2OCT 123
218#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124
219#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125
220#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126
221#define EC_F_EC_POINT_SET_TO_INFINITY 127
222#define EC_F_GFP_MONT_GROUP_SET_CURVE_GFP 135
223
224/* Reason codes. */
225#define EC_R_BUFFER_TOO_SMALL 100
226#define EC_R_INCOMPATIBLE_OBJECTS 101
227#define EC_R_INVALID_ARGUMENT 112
228#define EC_R_INVALID_COMPRESSED_POINT 110
229#define EC_R_INVALID_COMPRESSION_BIT 109
230#define EC_R_INVALID_ENCODING 102
231#define EC_R_INVALID_FIELD 103
232#define EC_R_INVALID_FORM 104
233#define EC_R_NOT_INITIALIZED 111
234#define EC_R_POINT_AT_INFINITY 106
235#define EC_R_POINT_IS_NOT_ON_CURVE 107
236#define EC_R_SLOT_FULL 108
237#define EC_R_UNDEFINED_GENERATOR 113
238#define EC_R_UNKNOWN_ORDER 114
239
240#ifdef __cplusplus
241}
242#endif
243#endif
diff --git a/src/lib/libcrypto/ec/ec_cvt.c b/src/lib/libcrypto/ec/ec_cvt.c
deleted file mode 100644
index 45b0ec33a0..0000000000
--- a/src/lib/libcrypto/ec/ec_cvt.c
+++ /dev/null
@@ -1,80 +0,0 @@
1/* crypto/ec/ec_cvt.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58
59EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
60 {
61 const EC_METHOD *meth;
62 EC_GROUP *ret;
63
64 /* Finally, this will use EC_GFp_nist_method if 'p' is a special
65 * prime with optimized modular arithmetics (for NIST curves)
66 */
67 meth = EC_GFp_mont_method();
68
69 ret = EC_GROUP_new(meth);
70 if (ret == NULL)
71 return NULL;
72
73 if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
74 {
75 EC_GROUP_clear_free(ret);
76 return NULL;
77 }
78
79 return ret;
80 }
diff --git a/src/lib/libcrypto/ec/ec_err.c b/src/lib/libcrypto/ec/ec_err.c
deleted file mode 100644
index 5b70f94382..0000000000
--- a/src/lib/libcrypto/ec/ec_err.c
+++ /dev/null
@@ -1,153 +0,0 @@
1/* crypto/ec/ec_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ec.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_EC,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_EC,0,reason)
70
71static ERR_STRING_DATA EC_str_functs[]=
72 {
73{ERR_FUNC(EC_F_COMPUTE_WNAF), "COMPUTE_WNAF"},
74{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_DECODE), "ec_GFp_mont_field_decode"},
75{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_ENCODE), "ec_GFp_mont_field_encode"},
76{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_MUL), "ec_GFp_mont_field_mul"},
77{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_SQR), "ec_GFp_mont_field_sqr"},
78{ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP), "ec_GFp_simple_group_set_curve_GFp"},
79{ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR), "ec_GFp_simple_group_set_generator"},
80{ERR_FUNC(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE), "ec_GFp_simple_make_affine"},
81{ERR_FUNC(EC_F_EC_GFP_SIMPLE_OCT2POINT), "ec_GFp_simple_oct2point"},
82{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT2OCT), "ec_GFp_simple_point2oct"},
83{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE), "ec_GFp_simple_points_make_affine"},
84{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP), "ec_GFp_simple_point_get_affine_coordinates_GFp"},
85{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP), "ec_GFp_simple_point_set_affine_coordinates_GFp"},
86{ERR_FUNC(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP), "ec_GFp_simple_set_compressed_coordinates_GFp"},
87{ERR_FUNC(EC_F_EC_GROUP_COPY), "EC_GROUP_copy"},
88{ERR_FUNC(EC_F_EC_GROUP_GET0_GENERATOR), "EC_GROUP_get0_generator"},
89{ERR_FUNC(EC_F_EC_GROUP_GET_COFACTOR), "EC_GROUP_get_cofactor"},
90{ERR_FUNC(EC_F_EC_GROUP_GET_CURVE_GFP), "EC_GROUP_get_curve_GFp"},
91{ERR_FUNC(EC_F_EC_GROUP_GET_ORDER), "EC_GROUP_get_order"},
92{ERR_FUNC(EC_F_EC_GROUP_NEW), "EC_GROUP_new"},
93{ERR_FUNC(EC_F_EC_GROUP_PRECOMPUTE_MULT), "EC_GROUP_precompute_mult"},
94{ERR_FUNC(EC_F_EC_GROUP_SET_CURVE_GFP), "EC_GROUP_set_curve_GFp"},
95{ERR_FUNC(EC_F_EC_GROUP_SET_EXTRA_DATA), "EC_GROUP_set_extra_data"},
96{ERR_FUNC(EC_F_EC_GROUP_SET_GENERATOR), "EC_GROUP_set_generator"},
97{ERR_FUNC(EC_F_EC_POINTS_MAKE_AFFINE), "EC_POINTs_make_affine"},
98{ERR_FUNC(EC_F_EC_POINTS_MUL), "EC_POINTs_mul"},
99{ERR_FUNC(EC_F_EC_POINT_ADD), "EC_POINT_add"},
100{ERR_FUNC(EC_F_EC_POINT_CMP), "EC_POINT_cmp"},
101{ERR_FUNC(EC_F_EC_POINT_COPY), "EC_POINT_copy"},
102{ERR_FUNC(EC_F_EC_POINT_DBL), "EC_POINT_dbl"},
103{ERR_FUNC(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP), "EC_POINT_get_affine_coordinates_GFp"},
104{ERR_FUNC(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP), "EC_POINT_get_Jprojective_coordinates_GFp"},
105{ERR_FUNC(EC_F_EC_POINT_IS_AT_INFINITY), "EC_POINT_is_at_infinity"},
106{ERR_FUNC(EC_F_EC_POINT_IS_ON_CURVE), "EC_POINT_is_on_curve"},
107{ERR_FUNC(EC_F_EC_POINT_MAKE_AFFINE), "EC_POINT_make_affine"},
108{ERR_FUNC(EC_F_EC_POINT_NEW), "EC_POINT_new"},
109{ERR_FUNC(EC_F_EC_POINT_OCT2POINT), "EC_POINT_oct2point"},
110{ERR_FUNC(EC_F_EC_POINT_POINT2OCT), "EC_POINT_point2oct"},
111{ERR_FUNC(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP), "EC_POINT_set_affine_coordinates_GFp"},
112{ERR_FUNC(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP), "EC_POINT_set_compressed_coordinates_GFp"},
113{ERR_FUNC(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP), "EC_POINT_set_Jprojective_coordinates_GFp"},
114{ERR_FUNC(EC_F_EC_POINT_SET_TO_INFINITY), "EC_POINT_set_to_infinity"},
115{ERR_FUNC(EC_F_GFP_MONT_GROUP_SET_CURVE_GFP), "GFP_MONT_GROUP_SET_CURVE_GFP"},
116{0,NULL}
117 };
118
119static ERR_STRING_DATA EC_str_reasons[]=
120 {
121{ERR_REASON(EC_R_BUFFER_TOO_SMALL) ,"buffer too small"},
122{ERR_REASON(EC_R_INCOMPATIBLE_OBJECTS) ,"incompatible objects"},
123{ERR_REASON(EC_R_INVALID_ARGUMENT) ,"invalid argument"},
124{ERR_REASON(EC_R_INVALID_COMPRESSED_POINT),"invalid compressed point"},
125{ERR_REASON(EC_R_INVALID_COMPRESSION_BIT),"invalid compression bit"},
126{ERR_REASON(EC_R_INVALID_ENCODING) ,"invalid encoding"},
127{ERR_REASON(EC_R_INVALID_FIELD) ,"invalid field"},
128{ERR_REASON(EC_R_INVALID_FORM) ,"invalid form"},
129{ERR_REASON(EC_R_NOT_INITIALIZED) ,"not initialized"},
130{ERR_REASON(EC_R_POINT_AT_INFINITY) ,"point at infinity"},
131{ERR_REASON(EC_R_POINT_IS_NOT_ON_CURVE) ,"point is not on curve"},
132{ERR_REASON(EC_R_SLOT_FULL) ,"slot full"},
133{ERR_REASON(EC_R_UNDEFINED_GENERATOR) ,"undefined generator"},
134{ERR_REASON(EC_R_UNKNOWN_ORDER) ,"unknown order"},
135{0,NULL}
136 };
137
138#endif
139
140void ERR_load_EC_strings(void)
141 {
142 static int init=1;
143
144 if (init)
145 {
146 init=0;
147#ifndef OPENSSL_NO_ERR
148 ERR_load_strings(0,EC_str_functs);
149 ERR_load_strings(0,EC_str_reasons);
150#endif
151
152 }
153 }
diff --git a/src/lib/libcrypto/ec/ec_lcl.h b/src/lib/libcrypto/ec/ec_lcl.h
deleted file mode 100644
index cc4cf27755..0000000000
--- a/src/lib/libcrypto/ec/ec_lcl.h
+++ /dev/null
@@ -1,277 +0,0 @@
1/* crypto/ec/ec_lcl.h */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56
57#include <stdlib.h>
58
59#include <openssl/ec.h>
60
61
62/* Structure details are not part of the exported interface,
63 * so all this may change in future versions. */
64
65struct ec_method_st {
66 /* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */
67 int (*group_init)(EC_GROUP *);
68 void (*group_finish)(EC_GROUP *);
69 void (*group_clear_finish)(EC_GROUP *);
70 int (*group_copy)(EC_GROUP *, const EC_GROUP *);
71
72 /* used by EC_GROUP_set_curve_GFp and EC_GROUP_get_curve_GFp: */
73 int (*group_set_curve_GFp)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
74 int (*group_get_curve_GFp)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
75
76 /* used by EC_GROUP_set_generator, EC_GROUP_get0_generator,
77 * EC_GROUP_get_order, EC_GROUP_get_cofactor:
78 */
79 int (*group_set_generator)(EC_GROUP *, const EC_POINT *generator,
80 const BIGNUM *order, const BIGNUM *cofactor);
81 EC_POINT *(*group_get0_generator)(const EC_GROUP *);
82 int (*group_get_order)(const EC_GROUP *, BIGNUM *order, BN_CTX *);
83 int (*group_get_cofactor)(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
84
85 /* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */
86 int (*point_init)(EC_POINT *);
87 void (*point_finish)(EC_POINT *);
88 void (*point_clear_finish)(EC_POINT *);
89 int (*point_copy)(EC_POINT *, const EC_POINT *);
90
91 /* used by EC_POINT_set_to_infinity,
92 * EC_POINT_set_Jprojective_coordinates_GFp, EC_POINT_get_Jprojective_coordinates_GFp,
93 * EC_POINT_set_affine_coordinates_GFp, EC_POINT_get_affine_coordinates_GFp,
94 * EC_POINT_set_compressed_coordinates_GFp:
95 */
96 int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *);
97 int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
98 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
99 int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
100 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
101 int (*point_set_affine_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
102 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
103 int (*point_get_affine_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
104 BIGNUM *x, BIGNUM *y, BN_CTX *);
105 int (*point_set_compressed_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
106 const BIGNUM *x, int y_bit, BN_CTX *);
107
108 /* used by EC_POINT_point2oct, EC_POINT_oct2point: */
109 size_t (*point2oct)(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
110 unsigned char *buf, size_t len, BN_CTX *);
111 int (*oct2point)(const EC_GROUP *, EC_POINT *,
112 const unsigned char *buf, size_t len, BN_CTX *);
113
114 /* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */
115 int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
116 int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
117 int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *);
118
119 /* used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: */
120 int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *);
121 int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *);
122 int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
123
124 /* used by EC_POINT_make_affine, EC_POINTs_make_affine: */
125 int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *);
126 int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
127
128
129 /* internal functions */
130
131 /* 'field_mul' and 'field_sqr' can be used by 'add' and 'dbl' so that
132 * the same implementations of point operations can be used with different
133 * optimized implementations of expensive field operations: */
134 int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
135 int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
136
137 int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */
138 int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */
139 int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *);
140} /* EC_METHOD */;
141
142
143struct ec_group_st {
144 const EC_METHOD *meth;
145
146 void *extra_data;
147 void *(*extra_data_dup_func)(void *);
148 void (*extra_data_free_func)(void *);
149 void (*extra_data_clear_free_func)(void *);
150
151 /* All members except 'meth' and 'extra_data...' are handled by
152 * the method functions, even if they appear generic */
153
154 BIGNUM field; /* Field specification.
155 * For curves over GF(p), this is the modulus. */
156
157 BIGNUM a, b; /* Curve coefficients.
158 * (Here the assumption is that BIGNUMs can be used
159 * or abused for all kinds of fields, not just GF(p).)
160 * For characteristic > 3, the curve is defined
161 * by a Weierstrass equation of the form
162 * y^2 = x^3 + a*x + b.
163 */
164 int a_is_minus3; /* enable optimized point arithmetics for special case */
165
166 EC_POINT *generator; /* optional */
167 BIGNUM order, cofactor;
168
169 void *field_data1; /* method-specific (e.g., Montgomery structure) */
170 void *field_data2; /* method-specific */
171} /* EC_GROUP */;
172
173
174/* Basically a 'mixin' for extra data, but available for EC_GROUPs only
175 * (with visibility limited to 'package' level for now).
176 * We use the function pointers as index for retrieval; this obviates
177 * global ex_data-style index tables.
178 * (Currently, we have one slot only, but is is possible to extend this
179 * if necessary.) */
180int EC_GROUP_set_extra_data(EC_GROUP *, void *extra_data, void *(*extra_data_dup_func)(void *),
181 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *));
182void *EC_GROUP_get_extra_data(const EC_GROUP *, void *(*extra_data_dup_func)(void *),
183 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *));
184void EC_GROUP_free_extra_data(EC_GROUP *);
185void EC_GROUP_clear_free_extra_data(EC_GROUP *);
186
187
188
189struct ec_point_st {
190 const EC_METHOD *meth;
191
192 /* All members except 'meth' are handled by the method functions,
193 * even if they appear generic */
194
195 BIGNUM X;
196 BIGNUM Y;
197 BIGNUM Z; /* Jacobian projective coordinates:
198 * (X, Y, Z) represents (X/Z^2, Y/Z^3) if Z != 0 */
199 int Z_is_one; /* enable optimized point arithmetics for special case */
200} /* EC_POINT */;
201
202
203
204/* method functions in ecp_smpl.c */
205int ec_GFp_simple_group_init(EC_GROUP *);
206void ec_GFp_simple_group_finish(EC_GROUP *);
207void ec_GFp_simple_group_clear_finish(EC_GROUP *);
208int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *);
209int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
210int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
211int ec_GFp_simple_group_set_generator(EC_GROUP *, const EC_POINT *generator,
212 const BIGNUM *order, const BIGNUM *cofactor);
213EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *);
214int ec_GFp_simple_group_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
215int ec_GFp_simple_group_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
216int ec_GFp_simple_point_init(EC_POINT *);
217void ec_GFp_simple_point_finish(EC_POINT *);
218void ec_GFp_simple_point_clear_finish(EC_POINT *);
219int ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *);
220int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
221int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
222 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
223int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
224 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
225int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
226 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
227int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
228 BIGNUM *x, BIGNUM *y, BN_CTX *);
229int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
230 const BIGNUM *x, int y_bit, BN_CTX *);
231size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
232 unsigned char *buf, size_t len, BN_CTX *);
233int ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *,
234 const unsigned char *buf, size_t len, BN_CTX *);
235int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
236int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
237int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
238int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
239int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
240int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
241int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
242int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
243int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
244int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
245
246
247/* method functions in ecp_mont.c */
248int ec_GFp_mont_group_init(EC_GROUP *);
249int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
250void ec_GFp_mont_group_finish(EC_GROUP *);
251void ec_GFp_mont_group_clear_finish(EC_GROUP *);
252int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *);
253int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
254int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
255int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
256int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
257int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *);
258
259
260/* method functions in ecp_recp.c */
261int ec_GFp_recp_group_init(EC_GROUP *);
262int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
263void ec_GFp_recp_group_finish(EC_GROUP *);
264void ec_GFp_recp_group_clear_finish(EC_GROUP *);
265int ec_GFp_recp_group_copy(EC_GROUP *, const EC_GROUP *);
266int ec_GFp_recp_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
267int ec_GFp_recp_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
268
269
270/* method functions in ecp_nist.c */
271int ec_GFp_nist_group_init(EC_GROUP *);
272int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
273void ec_GFp_nist_group_finish(EC_GROUP *);
274void ec_GFp_nist_group_clear_finish(EC_GROUP *);
275int ec_GFp_nist_group_copy(EC_GROUP *, const EC_GROUP *);
276int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
277int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
deleted file mode 100644
index deb522060f..0000000000
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ /dev/null
@@ -1,656 +0,0 @@
1/* crypto/ec/ec_lib.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57
58#include <openssl/err.h>
59#include <openssl/opensslv.h>
60
61#include "ec_lcl.h"
62
63static const char EC_version[] = "EC" OPENSSL_VERSION_PTEXT;
64
65
66/* functions for EC_GROUP objects */
67
68EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
69 {
70 EC_GROUP *ret;
71
72 if (meth == NULL)
73 {
74 ECerr(EC_F_EC_GROUP_NEW, ERR_R_PASSED_NULL_PARAMETER);
75 return NULL;
76 }
77 if (meth->group_init == 0)
78 {
79 ECerr(EC_F_EC_GROUP_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
80 return NULL;
81 }
82
83 ret = OPENSSL_malloc(sizeof *ret);
84 if (ret == NULL)
85 {
86 ECerr(EC_F_EC_GROUP_NEW, ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89
90 ret->meth = meth;
91
92 ret->extra_data = NULL;
93 ret->extra_data_dup_func = 0;
94 ret->extra_data_free_func = 0;
95 ret->extra_data_clear_free_func = 0;
96
97 if (!meth->group_init(ret))
98 {
99 OPENSSL_free(ret);
100 return NULL;
101 }
102
103 return ret;
104 }
105
106
107void EC_GROUP_free(EC_GROUP *group)
108 {
109 if (!group) return;
110
111 if (group->meth->group_finish != 0)
112 group->meth->group_finish(group);
113
114 EC_GROUP_free_extra_data(group);
115
116 OPENSSL_free(group);
117 }
118
119
120void EC_GROUP_clear_free(EC_GROUP *group)
121 {
122 if (!group) return;
123
124 if (group->meth->group_clear_finish != 0)
125 group->meth->group_clear_finish(group);
126 else if (group->meth != NULL && group->meth->group_finish != 0)
127 group->meth->group_finish(group);
128
129 EC_GROUP_clear_free_extra_data(group);
130
131 OPENSSL_cleanse(group, sizeof *group);
132 OPENSSL_free(group);
133 }
134
135
136int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
137 {
138 if (dest->meth->group_copy == 0)
139 {
140 ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
141 return 0;
142 }
143 if (dest->meth != src->meth)
144 {
145 ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS);
146 return 0;
147 }
148 if (dest == src)
149 return 1;
150
151 EC_GROUP_clear_free_extra_data(dest);
152 if (src->extra_data_dup_func)
153 {
154 if (src->extra_data != NULL)
155 {
156 dest->extra_data = src->extra_data_dup_func(src->extra_data);
157 if (dest->extra_data == NULL)
158 return 0;
159 }
160
161 dest->extra_data_dup_func = src->extra_data_dup_func;
162 dest->extra_data_free_func = src->extra_data_free_func;
163 dest->extra_data_clear_free_func = src->extra_data_clear_free_func;
164 }
165
166 return dest->meth->group_copy(dest, src);
167 }
168
169
170const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group)
171 {
172 return group->meth;
173 }
174
175
176int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
177 {
178 if (group->meth->group_set_curve_GFp == 0)
179 {
180 ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
181 return 0;
182 }
183 return group->meth->group_set_curve_GFp(group, p, a, b, ctx);
184 }
185
186
187int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
188 {
189 if (group->meth->group_get_curve_GFp == 0)
190 {
191 ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
192 return 0;
193 }
194 return group->meth->group_get_curve_GFp(group, p, a, b, ctx);
195 }
196
197
198int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor)
199 {
200 if (group->meth->group_set_generator == 0)
201 {
202 ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
203 return 0;
204 }
205 return group->meth->group_set_generator(group, generator, order, cofactor);
206 }
207
208
209EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group)
210 {
211 if (group->meth->group_get0_generator == 0)
212 {
213 ECerr(EC_F_EC_GROUP_GET0_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
214 return 0;
215 }
216 return group->meth->group_get0_generator(group);
217 }
218
219
220int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
221 {
222 if (group->meth->group_get_order == 0)
223 {
224 ECerr(EC_F_EC_GROUP_GET_ORDER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
225 return 0;
226 }
227 return group->meth->group_get_order(group, order, ctx);
228 }
229
230
231int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
232 {
233 if (group->meth->group_get_cofactor == 0)
234 {
235 ECerr(EC_F_EC_GROUP_GET_COFACTOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
236 return 0;
237 }
238 return group->meth->group_get_cofactor(group, cofactor, ctx);
239 }
240
241
242/* this has 'package' visibility */
243int EC_GROUP_set_extra_data(EC_GROUP *group, void *extra_data, void *(*extra_data_dup_func)(void *),
244 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
245 {
246 if ((group->extra_data != NULL)
247 || (group->extra_data_dup_func != 0)
248 || (group->extra_data_free_func != 0)
249 || (group->extra_data_clear_free_func != 0))
250 {
251 ECerr(EC_F_EC_GROUP_SET_EXTRA_DATA, EC_R_SLOT_FULL);
252 return 0;
253 }
254
255 group->extra_data = extra_data;
256 group->extra_data_dup_func = extra_data_dup_func;
257 group->extra_data_free_func = extra_data_free_func;
258 group->extra_data_clear_free_func = extra_data_clear_free_func;
259 return 1;
260 }
261
262
263/* this has 'package' visibility */
264void *EC_GROUP_get_extra_data(const EC_GROUP *group, void *(*extra_data_dup_func)(void *),
265 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
266 {
267 if ((group->extra_data_dup_func != extra_data_dup_func)
268 || (group->extra_data_free_func != extra_data_free_func)
269 || (group->extra_data_clear_free_func != extra_data_clear_free_func))
270 {
271#if 0 /* this was an error in 0.9.7, but that does not make a lot of sense */
272 ECerr(..._F_EC_GROUP_GET_EXTRA_DATA, ..._R_NO_SUCH_EXTRA_DATA);
273#endif
274 return NULL;
275 }
276
277 return group->extra_data;
278 }
279
280
281/* this has 'package' visibility */
282void EC_GROUP_free_extra_data(EC_GROUP *group)
283 {
284 if (group->extra_data_free_func)
285 group->extra_data_free_func(group->extra_data);
286 group->extra_data = NULL;
287 group->extra_data_dup_func = 0;
288 group->extra_data_free_func = 0;
289 group->extra_data_clear_free_func = 0;
290 }
291
292
293/* this has 'package' visibility */
294void EC_GROUP_clear_free_extra_data(EC_GROUP *group)
295 {
296 if (group->extra_data_clear_free_func)
297 group->extra_data_clear_free_func(group->extra_data);
298 else if (group->extra_data_free_func)
299 group->extra_data_free_func(group->extra_data);
300 group->extra_data = NULL;
301 group->extra_data_dup_func = 0;
302 group->extra_data_free_func = 0;
303 group->extra_data_clear_free_func = 0;
304 }
305
306
307
308/* functions for EC_POINT objects */
309
310EC_POINT *EC_POINT_new(const EC_GROUP *group)
311 {
312 EC_POINT *ret;
313
314 if (group == NULL)
315 {
316 ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER);
317 return NULL;
318 }
319 if (group->meth->point_init == 0)
320 {
321 ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
322 return NULL;
323 }
324
325 ret = OPENSSL_malloc(sizeof *ret);
326 if (ret == NULL)
327 {
328 ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE);
329 return NULL;
330 }
331
332 ret->meth = group->meth;
333
334 if (!ret->meth->point_init(ret))
335 {
336 OPENSSL_free(ret);
337 return NULL;
338 }
339
340 return ret;
341 }
342
343
344void EC_POINT_free(EC_POINT *point)
345 {
346 if (!point) return;
347
348 if (point->meth->point_finish != 0)
349 point->meth->point_finish(point);
350 OPENSSL_free(point);
351 }
352
353
354void EC_POINT_clear_free(EC_POINT *point)
355 {
356 if (!point) return;
357
358 if (point->meth->point_clear_finish != 0)
359 point->meth->point_clear_finish(point);
360 else if (point->meth != NULL && point->meth->point_finish != 0)
361 point->meth->point_finish(point);
362 OPENSSL_cleanse(point, sizeof *point);
363 OPENSSL_free(point);
364 }
365
366
367int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)
368 {
369 if (dest->meth->point_copy == 0)
370 {
371 ECerr(EC_F_EC_POINT_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
372 return 0;
373 }
374 if (dest->meth != src->meth)
375 {
376 ECerr(EC_F_EC_POINT_COPY, EC_R_INCOMPATIBLE_OBJECTS);
377 return 0;
378 }
379 if (dest == src)
380 return 1;
381 return dest->meth->point_copy(dest, src);
382 }
383
384
385const EC_METHOD *EC_POINT_method_of(const EC_POINT *point)
386 {
387 return point->meth;
388 }
389
390
391int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
392 {
393 if (group->meth->point_set_to_infinity == 0)
394 {
395 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
396 return 0;
397 }
398 if (group->meth != point->meth)
399 {
400 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, EC_R_INCOMPATIBLE_OBJECTS);
401 return 0;
402 }
403 return group->meth->point_set_to_infinity(group, point);
404 }
405
406
407int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
408 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
409 {
410 if (group->meth->point_set_Jprojective_coordinates_GFp == 0)
411 {
412 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
413 return 0;
414 }
415 if (group->meth != point->meth)
416 {
417 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
418 return 0;
419 }
420 return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
421 }
422
423
424int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
425 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
426 {
427 if (group->meth->point_get_Jprojective_coordinates_GFp == 0)
428 {
429 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
430 return 0;
431 }
432 if (group->meth != point->meth)
433 {
434 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
435 return 0;
436 }
437 return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
438 }
439
440
441int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
442 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
443 {
444 if (group->meth->point_set_affine_coordinates_GFp == 0)
445 {
446 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
447 return 0;
448 }
449 if (group->meth != point->meth)
450 {
451 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
452 return 0;
453 }
454 return group->meth->point_set_affine_coordinates_GFp(group, point, x, y, ctx);
455 }
456
457
458int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
459 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
460 {
461 if (group->meth->point_get_affine_coordinates_GFp == 0)
462 {
463 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
464 return 0;
465 }
466 if (group->meth != point->meth)
467 {
468 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
469 return 0;
470 }
471 return group->meth->point_get_affine_coordinates_GFp(group, point, x, y, ctx);
472 }
473
474
475int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
476 const BIGNUM *x, int y_bit, BN_CTX *ctx)
477 {
478 if (group->meth->point_set_compressed_coordinates_GFp == 0)
479 {
480 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
481 return 0;
482 }
483 if (group->meth != point->meth)
484 {
485 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
486 return 0;
487 }
488 return group->meth->point_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx);
489 }
490
491
492size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
493 unsigned char *buf, size_t len, BN_CTX *ctx)
494 {
495 if (group->meth->point2oct == 0)
496 {
497 ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
498 return 0;
499 }
500 if (group->meth != point->meth)
501 {
502 ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS);
503 return 0;
504 }
505 return group->meth->point2oct(group, point, form, buf, len, ctx);
506 }
507
508
509int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
510 const unsigned char *buf, size_t len, BN_CTX *ctx)
511 {
512 if (group->meth->oct2point == 0)
513 {
514 ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
515 return 0;
516 }
517 if (group->meth != point->meth)
518 {
519 ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS);
520 return 0;
521 }
522 return group->meth->oct2point(group, point, buf, len, ctx);
523 }
524
525
526int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
527 {
528 if (group->meth->add == 0)
529 {
530 ECerr(EC_F_EC_POINT_ADD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
531 return 0;
532 }
533 if ((group->meth != r->meth) || (r->meth != a->meth) || (a->meth != b->meth))
534 {
535 ECerr(EC_F_EC_POINT_ADD, EC_R_INCOMPATIBLE_OBJECTS);
536 return 0;
537 }
538 return group->meth->add(group, r, a, b, ctx);
539 }
540
541
542int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
543 {
544 if (group->meth->dbl == 0)
545 {
546 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
547 return 0;
548 }
549 if ((group->meth != r->meth) || (r->meth != a->meth))
550 {
551 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
552 return 0;
553 }
554 return group->meth->dbl(group, r, a, ctx);
555 }
556
557
558int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
559 {
560 if (group->meth->dbl == 0)
561 {
562 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
563 return 0;
564 }
565 if (group->meth != a->meth)
566 {
567 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
568 return 0;
569 }
570 return group->meth->invert(group, a, ctx);
571 }
572
573
574int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
575 {
576 if (group->meth->is_at_infinity == 0)
577 {
578 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
579 return 0;
580 }
581 if (group->meth != point->meth)
582 {
583 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, EC_R_INCOMPATIBLE_OBJECTS);
584 return 0;
585 }
586 return group->meth->is_at_infinity(group, point);
587 }
588
589
590int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
591 {
592 if (group->meth->is_on_curve == 0)
593 {
594 ECerr(EC_F_EC_POINT_IS_ON_CURVE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
595 return 0;
596 }
597 if (group->meth != point->meth)
598 {
599 ECerr(EC_F_EC_POINT_IS_ON_CURVE, EC_R_INCOMPATIBLE_OBJECTS);
600 return 0;
601 }
602 return group->meth->is_on_curve(group, point, ctx);
603 }
604
605
606int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
607 {
608 if (group->meth->point_cmp == 0)
609 {
610 ECerr(EC_F_EC_POINT_CMP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
611 return 0;
612 }
613 if ((group->meth != a->meth) || (a->meth != b->meth))
614 {
615 ECerr(EC_F_EC_POINT_CMP, EC_R_INCOMPATIBLE_OBJECTS);
616 return 0;
617 }
618 return group->meth->point_cmp(group, a, b, ctx);
619 }
620
621
622int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
623 {
624 if (group->meth->make_affine == 0)
625 {
626 ECerr(EC_F_EC_POINT_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
627 return 0;
628 }
629 if (group->meth != point->meth)
630 {
631 ECerr(EC_F_EC_POINT_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS);
632 return 0;
633 }
634 return group->meth->make_affine(group, point, ctx);
635 }
636
637
638int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
639 {
640 size_t i;
641
642 if (group->meth->points_make_affine == 0)
643 {
644 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
645 return 0;
646 }
647 for (i = 0; i < num; i++)
648 {
649 if (group->meth != points[i]->meth)
650 {
651 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS);
652 return 0;
653 }
654 }
655 return group->meth->points_make_affine(group, num, points, ctx);
656 }
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
deleted file mode 100644
index 16822a73cf..0000000000
--- a/src/lib/libcrypto/ec/ec_mult.c
+++ /dev/null
@@ -1,485 +0,0 @@
1/* crypto/ec/ec_mult.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/err.h>
57
58#include "ec_lcl.h"
59
60
61/* TODO: optional precomputation of multiples of the generator */
62
63
64
65/*
66 * wNAF-based interleaving multi-exponentation method
67 * (<URL:http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/moeller.html#multiexp>)
68 */
69
70
71/* Determine the width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'.
72 * This is an array r[] of values that are either zero or odd with an
73 * absolute value less than 2^w satisfying
74 * scalar = \sum_j r[j]*2^j
75 * where at most one of any w+1 consecutive digits is non-zero.
76 */
77static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len, BN_CTX *ctx)
78 {
79 BIGNUM *c;
80 int ok = 0;
81 signed char *r = NULL;
82 int sign = 1;
83 int bit, next_bit, mask;
84 size_t len = 0, j;
85
86 BN_CTX_start(ctx);
87 c = BN_CTX_get(ctx);
88 if (c == NULL) goto err;
89
90 if (w <= 0 || w > 7) /* 'signed char' can represent integers with absolute values less than 2^7 */
91 {
92 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
93 goto err;
94 }
95 bit = 1 << w; /* at most 128 */
96 next_bit = bit << 1; /* at most 256 */
97 mask = next_bit - 1; /* at most 255 */
98
99 if (!BN_copy(c, scalar)) goto err;
100 if (c->neg)
101 {
102 sign = -1;
103 c->neg = 0;
104 }
105
106 len = BN_num_bits(c) + 1; /* wNAF may be one digit longer than binary representation */
107 r = OPENSSL_malloc(len);
108 if (r == NULL) goto err;
109
110 j = 0;
111 while (!BN_is_zero(c))
112 {
113 int u = 0;
114
115 if (BN_is_odd(c))
116 {
117 if (c->d == NULL || c->top == 0)
118 {
119 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
120 goto err;
121 }
122 u = c->d[0] & mask;
123 if (u & bit)
124 {
125 u -= next_bit;
126 /* u < 0 */
127 if (!BN_add_word(c, -u)) goto err;
128 }
129 else
130 {
131 /* u > 0 */
132 if (!BN_sub_word(c, u)) goto err;
133 }
134
135 if (u <= -bit || u >= bit || !(u & 1) || c->neg)
136 {
137 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
138 goto err;
139 }
140 }
141
142 r[j++] = sign * u;
143
144 if (BN_is_odd(c))
145 {
146 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
147 goto err;
148 }
149 if (!BN_rshift1(c, c)) goto err;
150 }
151
152 if (j > len)
153 {
154 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
155 goto err;
156 }
157 len = j;
158 ok = 1;
159
160 err:
161 BN_CTX_end(ctx);
162 if (!ok)
163 {
164 OPENSSL_free(r);
165 r = NULL;
166 }
167 if (ok)
168 *ret_len = len;
169 return r;
170 }
171
172
173/* TODO: table should be optimised for the wNAF-based implementation,
174 * sometimes smaller windows will give better performance
175 * (thus the boundaries should be increased)
176 */
177#define EC_window_bits_for_scalar_size(b) \
178 ((size_t) \
179 ((b) >= 2000 ? 6 : \
180 (b) >= 800 ? 5 : \
181 (b) >= 300 ? 4 : \
182 (b) >= 70 ? 3 : \
183 (b) >= 20 ? 2 : \
184 1))
185
186/* Compute
187 * \sum scalars[i]*points[i],
188 * also including
189 * scalar*generator
190 * in the addition if scalar != NULL
191 */
192int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
193 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
194 {
195 BN_CTX *new_ctx = NULL;
196 EC_POINT *generator = NULL;
197 EC_POINT *tmp = NULL;
198 size_t totalnum;
199 size_t i, j;
200 int k;
201 int r_is_inverted = 0;
202 int r_is_at_infinity = 1;
203 size_t *wsize = NULL; /* individual window sizes */
204 signed char **wNAF = NULL; /* individual wNAFs */
205 size_t *wNAF_len = NULL;
206 size_t max_len = 0;
207 size_t num_val;
208 EC_POINT **val = NULL; /* precomputation */
209 EC_POINT **v;
210 EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' */
211 int ret = 0;
212
213 if (group->meth != r->meth)
214 {
215 ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
216 return 0;
217 }
218
219 if ((scalar == NULL) && (num == 0))
220 {
221 return EC_POINT_set_to_infinity(group, r);
222 }
223
224 if (scalar != NULL)
225 {
226 generator = EC_GROUP_get0_generator(group);
227 if (generator == NULL)
228 {
229 ECerr(EC_F_EC_POINTS_MUL, EC_R_UNDEFINED_GENERATOR);
230 return 0;
231 }
232 }
233
234 for (i = 0; i < num; i++)
235 {
236 if (group->meth != points[i]->meth)
237 {
238 ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
239 return 0;
240 }
241 }
242
243 totalnum = num + (scalar != NULL);
244
245 wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]);
246 wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);
247 wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]);
248 if (wNAF != NULL)
249 {
250 wNAF[0] = NULL; /* preliminary pivot */
251 }
252 if (wsize == NULL || wNAF_len == NULL || wNAF == NULL) goto err;
253
254 /* num_val := total number of points to precompute */
255 num_val = 0;
256 for (i = 0; i < totalnum; i++)
257 {
258 size_t bits;
259
260 bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);
261 wsize[i] = EC_window_bits_for_scalar_size(bits);
262 num_val += 1u << (wsize[i] - 1);
263 }
264
265 /* all precomputed points go into a single array 'val',
266 * 'val_sub[i]' is a pointer to the subarray for the i-th point */
267 val = OPENSSL_malloc((num_val + 1) * sizeof val[0]);
268 if (val == NULL) goto err;
269 val[num_val] = NULL; /* pivot element */
270
271 val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]);
272 if (val_sub == NULL) goto err;
273
274 /* allocate points for precomputation */
275 v = val;
276 for (i = 0; i < totalnum; i++)
277 {
278 val_sub[i] = v;
279 for (j = 0; j < (1u << (wsize[i] - 1)); j++)
280 {
281 *v = EC_POINT_new(group);
282 if (*v == NULL) goto err;
283 v++;
284 }
285 }
286 if (!(v == val + num_val))
287 {
288 ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR);
289 goto err;
290 }
291
292 if (ctx == NULL)
293 {
294 ctx = new_ctx = BN_CTX_new();
295 if (ctx == NULL)
296 goto err;
297 }
298
299 tmp = EC_POINT_new(group);
300 if (tmp == NULL) goto err;
301
302 /* prepare precomputed values:
303 * val_sub[i][0] := points[i]
304 * val_sub[i][1] := 3 * points[i]
305 * val_sub[i][2] := 5 * points[i]
306 * ...
307 */
308 for (i = 0; i < totalnum; i++)
309 {
310 if (i < num)
311 {
312 if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err;
313 }
314 else
315 {
316 if (!EC_POINT_copy(val_sub[i][0], generator)) goto err;
317 }
318
319 if (wsize[i] > 1)
320 {
321 if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err;
322 for (j = 1; j < (1u << (wsize[i] - 1)); j++)
323 {
324 if (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err;
325 }
326 }
327
328 wNAF[i + 1] = NULL; /* make sure we always have a pivot */
329 wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i], ctx);
330 if (wNAF[i] == NULL) goto err;
331 if (wNAF_len[i] > max_len)
332 max_len = wNAF_len[i];
333 }
334
335#if 1 /* optional; EC_window_bits_for_scalar_size assumes we do this step */
336 if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err;
337#endif
338
339 r_is_at_infinity = 1;
340
341 for (k = max_len - 1; k >= 0; k--)
342 {
343 if (!r_is_at_infinity)
344 {
345 if (!EC_POINT_dbl(group, r, r, ctx)) goto err;
346 }
347
348 for (i = 0; i < totalnum; i++)
349 {
350 if (wNAF_len[i] > (size_t)k)
351 {
352 int digit = wNAF[i][k];
353 int is_neg;
354
355 if (digit)
356 {
357 is_neg = digit < 0;
358
359 if (is_neg)
360 digit = -digit;
361
362 if (is_neg != r_is_inverted)
363 {
364 if (!r_is_at_infinity)
365 {
366 if (!EC_POINT_invert(group, r, ctx)) goto err;
367 }
368 r_is_inverted = !r_is_inverted;
369 }
370
371 /* digit > 0 */
372
373 if (r_is_at_infinity)
374 {
375 if (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err;
376 r_is_at_infinity = 0;
377 }
378 else
379 {
380 if (!EC_POINT_add(group, r, r, val_sub[i][digit >> 1], ctx)) goto err;
381 }
382 }
383 }
384 }
385 }
386
387 if (r_is_at_infinity)
388 {
389 if (!EC_POINT_set_to_infinity(group, r)) goto err;
390 }
391 else
392 {
393 if (r_is_inverted)
394 if (!EC_POINT_invert(group, r, ctx)) goto err;
395 }
396
397 ret = 1;
398
399 err:
400 if (new_ctx != NULL)
401 BN_CTX_free(new_ctx);
402 if (tmp != NULL)
403 EC_POINT_free(tmp);
404 if (wsize != NULL)
405 OPENSSL_free(wsize);
406 if (wNAF_len != NULL)
407 OPENSSL_free(wNAF_len);
408 if (wNAF != NULL)
409 {
410 signed char **w;
411
412 for (w = wNAF; *w != NULL; w++)
413 OPENSSL_free(*w);
414
415 OPENSSL_free(wNAF);
416 }
417 if (val != NULL)
418 {
419 for (v = val; *v != NULL; v++)
420 EC_POINT_clear_free(*v);
421
422 OPENSSL_free(val);
423 }
424 if (val_sub != NULL)
425 {
426 OPENSSL_free(val_sub);
427 }
428 return ret;
429 }
430
431
432int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
433 {
434 const EC_POINT *points[1];
435 const BIGNUM *scalars[1];
436
437 points[0] = point;
438 scalars[0] = p_scalar;
439
440 return EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);
441 }
442
443
444int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
445 {
446 const EC_POINT *generator;
447 BN_CTX *new_ctx = NULL;
448 BIGNUM *order;
449 int ret = 0;
450
451 generator = EC_GROUP_get0_generator(group);
452 if (generator == NULL)
453 {
454 ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR);
455 return 0;
456 }
457
458 if (ctx == NULL)
459 {
460 ctx = new_ctx = BN_CTX_new();
461 if (ctx == NULL)
462 return 0;
463 }
464
465 BN_CTX_start(ctx);
466 order = BN_CTX_get(ctx);
467 if (order == NULL) goto err;
468
469 if (!EC_GROUP_get_order(group, order, ctx)) return 0;
470 if (BN_is_zero(order))
471 {
472 ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER);
473 goto err;
474 }
475
476 /* TODO */
477
478 ret = 1;
479
480 err:
481 BN_CTX_end(ctx);
482 if (new_ctx != NULL)
483 BN_CTX_free(new_ctx);
484 return ret;
485 }
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
deleted file mode 100644
index 7b30d4c38a..0000000000
--- a/src/lib/libcrypto/ec/ecp_mont.c
+++ /dev/null
@@ -1,304 +0,0 @@
1/* crypto/ec/ecp_mont.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/err.h>
57
58#include "ec_lcl.h"
59
60
61const EC_METHOD *EC_GFp_mont_method(void)
62 {
63 static const EC_METHOD ret = {
64 ec_GFp_mont_group_init,
65 ec_GFp_mont_group_finish,
66 ec_GFp_mont_group_clear_finish,
67 ec_GFp_mont_group_copy,
68 ec_GFp_mont_group_set_curve_GFp,
69 ec_GFp_simple_group_get_curve_GFp,
70 ec_GFp_simple_group_set_generator,
71 ec_GFp_simple_group_get0_generator,
72 ec_GFp_simple_group_get_order,
73 ec_GFp_simple_group_get_cofactor,
74 ec_GFp_simple_point_init,
75 ec_GFp_simple_point_finish,
76 ec_GFp_simple_point_clear_finish,
77 ec_GFp_simple_point_copy,
78 ec_GFp_simple_point_set_to_infinity,
79 ec_GFp_simple_set_Jprojective_coordinates_GFp,
80 ec_GFp_simple_get_Jprojective_coordinates_GFp,
81 ec_GFp_simple_point_set_affine_coordinates_GFp,
82 ec_GFp_simple_point_get_affine_coordinates_GFp,
83 ec_GFp_simple_set_compressed_coordinates_GFp,
84 ec_GFp_simple_point2oct,
85 ec_GFp_simple_oct2point,
86 ec_GFp_simple_add,
87 ec_GFp_simple_dbl,
88 ec_GFp_simple_invert,
89 ec_GFp_simple_is_at_infinity,
90 ec_GFp_simple_is_on_curve,
91 ec_GFp_simple_cmp,
92 ec_GFp_simple_make_affine,
93 ec_GFp_simple_points_make_affine,
94 ec_GFp_mont_field_mul,
95 ec_GFp_mont_field_sqr,
96 ec_GFp_mont_field_encode,
97 ec_GFp_mont_field_decode,
98 ec_GFp_mont_field_set_to_one };
99
100 return &ret;
101 }
102
103
104int ec_GFp_mont_group_init(EC_GROUP *group)
105 {
106 int ok;
107
108 ok = ec_GFp_simple_group_init(group);
109 group->field_data1 = NULL;
110 group->field_data2 = NULL;
111 return ok;
112 }
113
114
115int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
116 {
117 BN_CTX *new_ctx = NULL;
118 BN_MONT_CTX *mont = NULL;
119 BIGNUM *one = NULL;
120 int ret = 0;
121
122 if (group->field_data1 != NULL)
123 {
124 BN_MONT_CTX_free(group->field_data1);
125 group->field_data1 = NULL;
126 }
127 if (group->field_data2 != NULL)
128 {
129 BN_free(group->field_data2);
130 group->field_data2 = NULL;
131 }
132
133 if (ctx == NULL)
134 {
135 ctx = new_ctx = BN_CTX_new();
136 if (ctx == NULL)
137 return 0;
138 }
139
140 mont = BN_MONT_CTX_new();
141 if (mont == NULL) goto err;
142 if (!BN_MONT_CTX_set(mont, p, ctx))
143 {
144 ECerr(EC_F_GFP_MONT_GROUP_SET_CURVE_GFP, ERR_R_BN_LIB);
145 goto err;
146 }
147 one = BN_new();
148 if (one == NULL) goto err;
149 if (!BN_to_montgomery(one, BN_value_one(), mont, ctx)) goto err;
150
151 group->field_data1 = mont;
152 mont = NULL;
153 group->field_data2 = one;
154 one = NULL;
155
156 ret = ec_GFp_simple_group_set_curve_GFp(group, p, a, b, ctx);
157
158 if (!ret)
159 {
160 BN_MONT_CTX_free(group->field_data1);
161 group->field_data1 = NULL;
162 BN_free(group->field_data2);
163 group->field_data2 = NULL;
164 }
165
166 err:
167 if (new_ctx != NULL)
168 BN_CTX_free(new_ctx);
169 if (mont != NULL)
170 BN_MONT_CTX_free(mont);
171 return ret;
172 }
173
174
175void ec_GFp_mont_group_finish(EC_GROUP *group)
176 {
177 if (group->field_data1 != NULL)
178 {
179 BN_MONT_CTX_free(group->field_data1);
180 group->field_data1 = NULL;
181 }
182 if (group->field_data2 != NULL)
183 {
184 BN_free(group->field_data2);
185 group->field_data2 = NULL;
186 }
187 ec_GFp_simple_group_finish(group);
188 }
189
190
191void ec_GFp_mont_group_clear_finish(EC_GROUP *group)
192 {
193 if (group->field_data1 != NULL)
194 {
195 BN_MONT_CTX_free(group->field_data1);
196 group->field_data1 = NULL;
197 }
198 if (group->field_data2 != NULL)
199 {
200 BN_clear_free(group->field_data2);
201 group->field_data2 = NULL;
202 }
203 ec_GFp_simple_group_clear_finish(group);
204 }
205
206
207int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
208 {
209 if (dest->field_data1 != NULL)
210 {
211 BN_MONT_CTX_free(dest->field_data1);
212 dest->field_data1 = NULL;
213 }
214 if (dest->field_data2 != NULL)
215 {
216 BN_clear_free(dest->field_data2);
217 dest->field_data2 = NULL;
218 }
219
220 if (!ec_GFp_simple_group_copy(dest, src)) return 0;
221
222 if (src->field_data1 != NULL)
223 {
224 dest->field_data1 = BN_MONT_CTX_new();
225 if (dest->field_data1 == NULL) return 0;
226 if (!BN_MONT_CTX_copy(dest->field_data1, src->field_data1)) goto err;
227 }
228 if (src->field_data2 != NULL)
229 {
230 dest->field_data2 = BN_dup(src->field_data2);
231 if (dest->field_data2 == NULL) goto err;
232 }
233
234 return 1;
235
236 err:
237 if (dest->field_data1 != NULL)
238 {
239 BN_MONT_CTX_free(dest->field_data1);
240 dest->field_data1 = NULL;
241 }
242 return 0;
243 }
244
245
246int ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
247 {
248 if (group->field_data1 == NULL)
249 {
250 ECerr(EC_F_EC_GFP_MONT_FIELD_MUL, EC_R_NOT_INITIALIZED);
251 return 0;
252 }
253
254 return BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx);
255 }
256
257
258int ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
259 {
260 if (group->field_data1 == NULL)
261 {
262 ECerr(EC_F_EC_GFP_MONT_FIELD_SQR, EC_R_NOT_INITIALIZED);
263 return 0;
264 }
265
266 return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx);
267 }
268
269
270int ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
271 {
272 if (group->field_data1 == NULL)
273 {
274 ECerr(EC_F_EC_GFP_MONT_FIELD_ENCODE, EC_R_NOT_INITIALIZED);
275 return 0;
276 }
277
278 return BN_to_montgomery(r, a, (BN_MONT_CTX *)group->field_data1, ctx);
279 }
280
281
282int ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
283 {
284 if (group->field_data1 == NULL)
285 {
286 ECerr(EC_F_EC_GFP_MONT_FIELD_DECODE, EC_R_NOT_INITIALIZED);
287 return 0;
288 }
289
290 return BN_from_montgomery(r, a, group->field_data1, ctx);
291 }
292
293
294int ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx)
295 {
296 if (group->field_data2 == NULL)
297 {
298 ECerr(EC_F_EC_GFP_MONT_FIELD_DECODE, EC_R_NOT_INITIALIZED);
299 return 0;
300 }
301
302 if (!BN_copy(r, group->field_data2)) return 0;
303 return 1;
304 }
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c
deleted file mode 100644
index ed07748675..0000000000
--- a/src/lib/libcrypto/ec/ecp_nist.c
+++ /dev/null
@@ -1,134 +0,0 @@
1/* crypto/ec/ecp_nist.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58#if 0
59const EC_METHOD *EC_GFp_nist_method(void)
60 {
61 static const EC_METHOD ret = {
62 ec_GFp_nist_group_init,
63 ec_GFp_nist_group_finish,
64 ec_GFp_nist_group_clear_finish,
65 ec_GFp_nist_group_copy,
66 ec_GFp_nist_group_set_curve_GFp,
67 ec_GFp_simple_group_get_curve_GFp,
68 ec_GFp_simple_group_set_generator,
69 ec_GFp_simple_group_get0_generator,
70 ec_GFp_simple_group_get_order,
71 ec_GFp_simple_group_get_cofactor,
72 ec_GFp_simple_point_init,
73 ec_GFp_simple_point_finish,
74 ec_GFp_simple_point_clear_finish,
75 ec_GFp_simple_point_copy,
76 ec_GFp_simple_point_set_to_infinity,
77 ec_GFp_simple_set_Jprojective_coordinates_GFp,
78 ec_GFp_simple_get_Jprojective_coordinates_GFp,
79 ec_GFp_simple_point_set_affine_coordinates_GFp,
80 ec_GFp_simple_point_get_affine_coordinates_GFp,
81 ec_GFp_simple_set_compressed_coordinates_GFp,
82 ec_GFp_simple_point2oct,
83 ec_GFp_simple_oct2point,
84 ec_GFp_simple_add,
85 ec_GFp_simple_dbl,
86 ec_GFp_simple_invert,
87 ec_GFp_simple_is_at_infinity,
88 ec_GFp_simple_is_on_curve,
89 ec_GFp_simple_cmp,
90 ec_GFp_simple_make_affine,
91 ec_GFp_simple_points_make_affine,
92 ec_GFp_nist_field_mul,
93 ec_GFp_nist_field_sqr,
94 0 /* field_encode */,
95 0 /* field_decode */,
96 0 /* field_set_to_one */ };
97
98 return &ret;
99 }
100#endif
101
102
103int ec_GFp_nist_group_init(EC_GROUP *group)
104 {
105 int ok;
106
107 ok = ec_GFp_simple_group_init(group);
108 group->field_data1 = NULL;
109 return ok;
110 }
111
112
113int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
114/* TODO */
115
116
117void ec_GFp_nist_group_finish(EC_GROUP *group);
118/* TODO */
119
120
121void ec_GFp_nist_group_clear_finish(EC_GROUP *group);
122/* TODO */
123
124
125int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src);
126/* TODO */
127
128
129int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
130/* TODO */
131
132
133int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
134/* TODO */
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
deleted file mode 100644
index e9a51fb87a..0000000000
--- a/src/lib/libcrypto/ec/ecp_smpl.c
+++ /dev/null
@@ -1,1717 +0,0 @@
1/* crypto/ec/ecp_smpl.c */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. */
4/* ====================================================================
5 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * openssl-core@openssl.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include <openssl/err.h>
59
60#include "ec_lcl.h"
61
62
63const EC_METHOD *EC_GFp_simple_method(void)
64 {
65 static const EC_METHOD ret = {
66 ec_GFp_simple_group_init,
67 ec_GFp_simple_group_finish,
68 ec_GFp_simple_group_clear_finish,
69 ec_GFp_simple_group_copy,
70 ec_GFp_simple_group_set_curve_GFp,
71 ec_GFp_simple_group_get_curve_GFp,
72 ec_GFp_simple_group_set_generator,
73 ec_GFp_simple_group_get0_generator,
74 ec_GFp_simple_group_get_order,
75 ec_GFp_simple_group_get_cofactor,
76 ec_GFp_simple_point_init,
77 ec_GFp_simple_point_finish,
78 ec_GFp_simple_point_clear_finish,
79 ec_GFp_simple_point_copy,
80 ec_GFp_simple_point_set_to_infinity,
81 ec_GFp_simple_set_Jprojective_coordinates_GFp,
82 ec_GFp_simple_get_Jprojective_coordinates_GFp,
83 ec_GFp_simple_point_set_affine_coordinates_GFp,
84 ec_GFp_simple_point_get_affine_coordinates_GFp,
85 ec_GFp_simple_set_compressed_coordinates_GFp,
86 ec_GFp_simple_point2oct,
87 ec_GFp_simple_oct2point,
88 ec_GFp_simple_add,
89 ec_GFp_simple_dbl,
90 ec_GFp_simple_invert,
91 ec_GFp_simple_is_at_infinity,
92 ec_GFp_simple_is_on_curve,
93 ec_GFp_simple_cmp,
94 ec_GFp_simple_make_affine,
95 ec_GFp_simple_points_make_affine,
96 ec_GFp_simple_field_mul,
97 ec_GFp_simple_field_sqr,
98 0 /* field_encode */,
99 0 /* field_decode */,
100 0 /* field_set_to_one */ };
101
102 return &ret;
103 }
104
105
106int ec_GFp_simple_group_init(EC_GROUP *group)
107 {
108 BN_init(&group->field);
109 BN_init(&group->a);
110 BN_init(&group->b);
111 group->a_is_minus3 = 0;
112 group->generator = NULL;
113 BN_init(&group->order);
114 BN_init(&group->cofactor);
115 return 1;
116 }
117
118
119void ec_GFp_simple_group_finish(EC_GROUP *group)
120 {
121 BN_free(&group->field);
122 BN_free(&group->a);
123 BN_free(&group->b);
124 if (group->generator != NULL)
125 EC_POINT_free(group->generator);
126 BN_free(&group->order);
127 BN_free(&group->cofactor);
128 }
129
130
131void ec_GFp_simple_group_clear_finish(EC_GROUP *group)
132 {
133 BN_clear_free(&group->field);
134 BN_clear_free(&group->a);
135 BN_clear_free(&group->b);
136 if (group->generator != NULL)
137 {
138 EC_POINT_clear_free(group->generator);
139 group->generator = NULL;
140 }
141 BN_clear_free(&group->order);
142 BN_clear_free(&group->cofactor);
143 }
144
145
146int ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
147 {
148 if (!BN_copy(&dest->field, &src->field)) return 0;
149 if (!BN_copy(&dest->a, &src->a)) return 0;
150 if (!BN_copy(&dest->b, &src->b)) return 0;
151
152 dest->a_is_minus3 = src->a_is_minus3;
153
154 if (src->generator != NULL)
155 {
156 if (dest->generator == NULL)
157 {
158 dest->generator = EC_POINT_new(dest);
159 if (dest->generator == NULL) return 0;
160 }
161 if (!EC_POINT_copy(dest->generator, src->generator)) return 0;
162 }
163 else
164 {
165 /* src->generator == NULL */
166 if (dest->generator != NULL)
167 {
168 EC_POINT_clear_free(dest->generator);
169 dest->generator = NULL;
170 }
171 }
172
173 if (!BN_copy(&dest->order, &src->order)) return 0;
174 if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0;
175
176 return 1;
177 }
178
179
180int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *group,
181 const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
182 {
183 int ret = 0;
184 BN_CTX *new_ctx = NULL;
185 BIGNUM *tmp_a;
186
187 /* p must be a prime > 3 */
188 if (BN_num_bits(p) <= 2 || !BN_is_odd(p))
189 {
190 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP, EC_R_INVALID_FIELD);
191 return 0;
192 }
193
194 if (ctx == NULL)
195 {
196 ctx = new_ctx = BN_CTX_new();
197 if (ctx == NULL)
198 return 0;
199 }
200
201 BN_CTX_start(ctx);
202 tmp_a = BN_CTX_get(ctx);
203 if (tmp_a == NULL) goto err;
204
205 /* group->field */
206 if (!BN_copy(&group->field, p)) goto err;
207 group->field.neg = 0;
208
209 /* group->a */
210 if (!BN_nnmod(tmp_a, a, p, ctx)) goto err;
211 if (group->meth->field_encode)
212 { if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) goto err; }
213 else
214 if (!BN_copy(&group->a, tmp_a)) goto err;
215
216 /* group->b */
217 if (!BN_nnmod(&group->b, b, p, ctx)) goto err;
218 if (group->meth->field_encode)
219 if (!group->meth->field_encode(group, &group->b, &group->b, ctx)) goto err;
220
221 /* group->a_is_minus3 */
222 if (!BN_add_word(tmp_a, 3)) goto err;
223 group->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field));
224
225 ret = 1;
226
227 err:
228 BN_CTX_end(ctx);
229 if (new_ctx != NULL)
230 BN_CTX_free(new_ctx);
231 return ret;
232 }
233
234
235int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
236 {
237 int ret = 0;
238 BN_CTX *new_ctx = NULL;
239
240 if (p != NULL)
241 {
242 if (!BN_copy(p, &group->field)) return 0;
243 }
244
245 if (a != NULL || b != NULL)
246 {
247 if (group->meth->field_decode)
248 {
249 if (ctx == NULL)
250 {
251 ctx = new_ctx = BN_CTX_new();
252 if (ctx == NULL)
253 return 0;
254 }
255 if (a != NULL)
256 {
257 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
258 }
259 if (b != NULL)
260 {
261 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
262 }
263 }
264 else
265 {
266 if (a != NULL)
267 {
268 if (!BN_copy(a, &group->a)) goto err;
269 }
270 if (b != NULL)
271 {
272 if (!BN_copy(b, &group->b)) goto err;
273 }
274 }
275 }
276
277 ret = 1;
278
279 err:
280 if (new_ctx)
281 BN_CTX_free(new_ctx);
282 return ret;
283 }
284
285
286
287int ec_GFp_simple_group_set_generator(EC_GROUP *group, const EC_POINT *generator,
288 const BIGNUM *order, const BIGNUM *cofactor)
289 {
290 if (generator == NULL)
291 {
292 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);
293 return 0 ;
294 }
295
296 if (group->generator == NULL)
297 {
298 group->generator = EC_POINT_new(group);
299 if (group->generator == NULL) return 0;
300 }
301 if (!EC_POINT_copy(group->generator, generator)) return 0;
302
303 if (order != NULL)
304 { if (!BN_copy(&group->order, order)) return 0; }
305 else
306 { if (!BN_zero(&group->order)) return 0; }
307
308 if (cofactor != NULL)
309 { if (!BN_copy(&group->cofactor, cofactor)) return 0; }
310 else
311 { if (!BN_zero(&group->cofactor)) return 0; }
312
313 return 1;
314 }
315
316
317EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *group)
318 {
319 return group->generator;
320 }
321
322
323int ec_GFp_simple_group_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
324 {
325 if (!BN_copy(order, &group->order))
326 return 0;
327
328 return !BN_is_zero(&group->order);
329 }
330
331
332int ec_GFp_simple_group_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
333 {
334 if (!BN_copy(cofactor, &group->cofactor))
335 return 0;
336
337 return !BN_is_zero(&group->cofactor);
338 }
339
340
341int ec_GFp_simple_point_init(EC_POINT *point)
342 {
343 BN_init(&point->X);
344 BN_init(&point->Y);
345 BN_init(&point->Z);
346 point->Z_is_one = 0;
347
348 return 1;
349 }
350
351
352void ec_GFp_simple_point_finish(EC_POINT *point)
353 {
354 BN_free(&point->X);
355 BN_free(&point->Y);
356 BN_free(&point->Z);
357 }
358
359
360void ec_GFp_simple_point_clear_finish(EC_POINT *point)
361 {
362 BN_clear_free(&point->X);
363 BN_clear_free(&point->Y);
364 BN_clear_free(&point->Z);
365 point->Z_is_one = 0;
366 }
367
368
369int ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
370 {
371 if (!BN_copy(&dest->X, &src->X)) return 0;
372 if (!BN_copy(&dest->Y, &src->Y)) return 0;
373 if (!BN_copy(&dest->Z, &src->Z)) return 0;
374 dest->Z_is_one = src->Z_is_one;
375
376 return 1;
377 }
378
379
380int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
381 {
382 point->Z_is_one = 0;
383 return (BN_zero(&point->Z));
384 }
385
386
387int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
388 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
389 {
390 BN_CTX *new_ctx = NULL;
391 int ret = 0;
392
393 if (ctx == NULL)
394 {
395 ctx = new_ctx = BN_CTX_new();
396 if (ctx == NULL)
397 return 0;
398 }
399
400 if (x != NULL)
401 {
402 if (!BN_nnmod(&point->X, x, &group->field, ctx)) goto err;
403 if (group->meth->field_encode)
404 {
405 if (!group->meth->field_encode(group, &point->X, &point->X, ctx)) goto err;
406 }
407 }
408
409 if (y != NULL)
410 {
411 if (!BN_nnmod(&point->Y, y, &group->field, ctx)) goto err;
412 if (group->meth->field_encode)
413 {
414 if (!group->meth->field_encode(group, &point->Y, &point->Y, ctx)) goto err;
415 }
416 }
417
418 if (z != NULL)
419 {
420 int Z_is_one;
421
422 if (!BN_nnmod(&point->Z, z, &group->field, ctx)) goto err;
423 Z_is_one = BN_is_one(&point->Z);
424 if (group->meth->field_encode)
425 {
426 if (Z_is_one && (group->meth->field_set_to_one != 0))
427 {
428 if (!group->meth->field_set_to_one(group, &point->Z, ctx)) goto err;
429 }
430 else
431 {
432 if (!group->meth->field_encode(group, &point->Z, &point->Z, ctx)) goto err;
433 }
434 }
435 point->Z_is_one = Z_is_one;
436 }
437
438 ret = 1;
439
440 err:
441 if (new_ctx != NULL)
442 BN_CTX_free(new_ctx);
443 return ret;
444 }
445
446
447int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
448 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
449 {
450 BN_CTX *new_ctx = NULL;
451 int ret = 0;
452
453 if (group->meth->field_decode != 0)
454 {
455 if (ctx == NULL)
456 {
457 ctx = new_ctx = BN_CTX_new();
458 if (ctx == NULL)
459 return 0;
460 }
461
462 if (x != NULL)
463 {
464 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
465 }
466 if (y != NULL)
467 {
468 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
469 }
470 if (z != NULL)
471 {
472 if (!group->meth->field_decode(group, z, &point->Z, ctx)) goto err;
473 }
474 }
475 else
476 {
477 if (x != NULL)
478 {
479 if (!BN_copy(x, &point->X)) goto err;
480 }
481 if (y != NULL)
482 {
483 if (!BN_copy(y, &point->Y)) goto err;
484 }
485 if (z != NULL)
486 {
487 if (!BN_copy(z, &point->Z)) goto err;
488 }
489 }
490
491 ret = 1;
492
493 err:
494 if (new_ctx != NULL)
495 BN_CTX_free(new_ctx);
496 return ret;
497 }
498
499
500int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
501 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
502 {
503 if (x == NULL || y == NULL)
504 {
505 /* unlike for projective coordinates, we do not tolerate this */
506 ECerr(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_PASSED_NULL_PARAMETER);
507 return 0;
508 }
509
510 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y, BN_value_one(), ctx);
511 }
512
513
514int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
515 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
516 {
517 BN_CTX *new_ctx = NULL;
518 BIGNUM *X, *Y, *Z, *Z_1, *Z_2, *Z_3;
519 const BIGNUM *X_, *Y_, *Z_;
520 int ret = 0;
521
522 if (EC_POINT_is_at_infinity(group, point))
523 {
524 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_POINT_AT_INFINITY);
525 return 0;
526 }
527
528 if (ctx == NULL)
529 {
530 ctx = new_ctx = BN_CTX_new();
531 if (ctx == NULL)
532 return 0;
533 }
534
535 BN_CTX_start(ctx);
536 X = BN_CTX_get(ctx);
537 Y = BN_CTX_get(ctx);
538 Z = BN_CTX_get(ctx);
539 Z_1 = BN_CTX_get(ctx);
540 Z_2 = BN_CTX_get(ctx);
541 Z_3 = BN_CTX_get(ctx);
542 if (Z_3 == NULL) goto err;
543
544 /* transform (X, Y, Z) into (x, y) := (X/Z^2, Y/Z^3) */
545
546 if (group->meth->field_decode)
547 {
548 if (!group->meth->field_decode(group, X, &point->X, ctx)) goto err;
549 if (!group->meth->field_decode(group, Y, &point->Y, ctx)) goto err;
550 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err;
551 X_ = X; Y_ = Y; Z_ = Z;
552 }
553 else
554 {
555 X_ = &point->X;
556 Y_ = &point->Y;
557 Z_ = &point->Z;
558 }
559
560 if (BN_is_one(Z_))
561 {
562 if (x != NULL)
563 {
564 if (!BN_copy(x, X_)) goto err;
565 }
566 if (y != NULL)
567 {
568 if (!BN_copy(y, Y_)) goto err;
569 }
570 }
571 else
572 {
573 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))
574 {
575 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_BN_LIB);
576 goto err;
577 }
578
579 if (group->meth->field_encode == 0)
580 {
581 /* field_sqr works on standard representation */
582 if (!group->meth->field_sqr(group, Z_2, Z_1, ctx)) goto err;
583 }
584 else
585 {
586 if (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx)) goto err;
587 }
588
589 if (x != NULL)
590 {
591 if (group->meth->field_encode == 0)
592 {
593 /* field_mul works on standard representation */
594 if (!group->meth->field_mul(group, x, X_, Z_2, ctx)) goto err;
595 }
596 else
597 {
598 if (!BN_mod_mul(x, X_, Z_2, &group->field, ctx)) goto err;
599 }
600 }
601
602 if (y != NULL)
603 {
604 if (group->meth->field_encode == 0)
605 {
606 /* field_mul works on standard representation */
607 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) goto err;
608 if (!group->meth->field_mul(group, y, Y_, Z_3, ctx)) goto err;
609
610 }
611 else
612 {
613 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err;
614 if (!BN_mod_mul(y, Y_, Z_3, &group->field, ctx)) goto err;
615 }
616 }
617 }
618
619 ret = 1;
620
621 err:
622 BN_CTX_end(ctx);
623 if (new_ctx != NULL)
624 BN_CTX_free(new_ctx);
625 return ret;
626 }
627
628
629int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
630 const BIGNUM *x_, int y_bit, BN_CTX *ctx)
631 {
632 BN_CTX *new_ctx = NULL;
633 BIGNUM *tmp1, *tmp2, *x, *y;
634 int ret = 0;
635
636 if (ctx == NULL)
637 {
638 ctx = new_ctx = BN_CTX_new();
639 if (ctx == NULL)
640 return 0;
641 }
642
643 y_bit = (y_bit != 0);
644
645 BN_CTX_start(ctx);
646 tmp1 = BN_CTX_get(ctx);
647 tmp2 = BN_CTX_get(ctx);
648 x = BN_CTX_get(ctx);
649 y = BN_CTX_get(ctx);
650 if (y == NULL) goto err;
651
652 /* Recover y. We have a Weierstrass equation
653 * y^2 = x^3 + a*x + b,
654 * so y is one of the square roots of x^3 + a*x + b.
655 */
656
657 /* tmp1 := x^3 */
658 if (!BN_nnmod(x, x_, &group->field,ctx)) goto err;
659 if (group->meth->field_decode == 0)
660 {
661 /* field_{sqr,mul} work on standard representation */
662 if (!group->meth->field_sqr(group, tmp2, x_, ctx)) goto err;
663 if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx)) goto err;
664 }
665 else
666 {
667 if (!BN_mod_sqr(tmp2, x_, &group->field, ctx)) goto err;
668 if (!BN_mod_mul(tmp1, tmp2, x_, &group->field, ctx)) goto err;
669 }
670
671 /* tmp1 := tmp1 + a*x */
672 if (group->a_is_minus3)
673 {
674 if (!BN_mod_lshift1_quick(tmp2, x, &group->field)) goto err;
675 if (!BN_mod_add_quick(tmp2, tmp2, x, &group->field)) goto err;
676 if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
677 }
678 else
679 {
680 if (group->meth->field_decode)
681 {
682 if (!group->meth->field_decode(group, tmp2, &group->a, ctx)) goto err;
683 if (!BN_mod_mul(tmp2, tmp2, x, &group->field, ctx)) goto err;
684 }
685 else
686 {
687 /* field_mul works on standard representation */
688 if (!group->meth->field_mul(group, tmp2, &group->a, x, ctx)) goto err;
689 }
690
691 if (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
692 }
693
694 /* tmp1 := tmp1 + b */
695 if (group->meth->field_decode)
696 {
697 if (!group->meth->field_decode(group, tmp2, &group->b, ctx)) goto err;
698 if (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;
699 }
700 else
701 {
702 if (!BN_mod_add_quick(tmp1, tmp1, &group->b, &group->field)) goto err;
703 }
704
705 if (!BN_mod_sqrt(y, tmp1, &group->field, ctx))
706 {
707 unsigned long err = ERR_peek_error();
708
709 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE)
710 {
711 (void)ERR_get_error();
712 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
713 }
714 else
715 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_BN_LIB);
716 goto err;
717 }
718 /* If tmp1 is not a square (i.e. there is no point on the curve with
719 * our x), then y now is a nonsense value too */
720
721 if (y_bit != BN_is_odd(y))
722 {
723 if (BN_is_zero(y))
724 {
725 int kron;
726
727 kron = BN_kronecker(x, &group->field, ctx);
728 if (kron == -2) goto err;
729
730 if (kron == 1)
731 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSION_BIT);
732 else
733 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
734 goto err;
735 }
736 if (!BN_usub(y, &group->field, y)) goto err;
737 }
738 if (y_bit != BN_is_odd(y))
739 {
740 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_INTERNAL_ERROR);
741 goto err;
742 }
743
744 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
745
746 ret = 1;
747
748 err:
749 BN_CTX_end(ctx);
750 if (new_ctx != NULL)
751 BN_CTX_free(new_ctx);
752 return ret;
753 }
754
755
756size_t ec_GFp_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
757 unsigned char *buf, size_t len, BN_CTX *ctx)
758 {
759 size_t ret;
760 BN_CTX *new_ctx = NULL;
761 int used_ctx = 0;
762 BIGNUM *x, *y;
763 size_t field_len, i, skip;
764
765 if ((form != POINT_CONVERSION_COMPRESSED)
766 && (form != POINT_CONVERSION_UNCOMPRESSED)
767 && (form != POINT_CONVERSION_HYBRID))
768 {
769 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_INVALID_FORM);
770 goto err;
771 }
772
773 if (EC_POINT_is_at_infinity(group, point))
774 {
775 /* encodes to a single 0 octet */
776 if (buf != NULL)
777 {
778 if (len < 1)
779 {
780 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
781 return 0;
782 }
783 buf[0] = 0;
784 }
785 return 1;
786 }
787
788
789 /* ret := required output buffer length */
790 field_len = BN_num_bytes(&group->field);
791 ret = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
792
793 /* if 'buf' is NULL, just return required length */
794 if (buf != NULL)
795 {
796 if (len < ret)
797 {
798 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
799 goto err;
800 }
801
802 if (ctx == NULL)
803 {
804 ctx = new_ctx = BN_CTX_new();
805 if (ctx == NULL)
806 return 0;
807 }
808
809 BN_CTX_start(ctx);
810 used_ctx = 1;
811 x = BN_CTX_get(ctx);
812 y = BN_CTX_get(ctx);
813 if (y == NULL) goto err;
814
815 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
816
817 if ((form == POINT_CONVERSION_COMPRESSED || form == POINT_CONVERSION_HYBRID) && BN_is_odd(y))
818 buf[0] = form + 1;
819 else
820 buf[0] = form;
821
822 i = 1;
823
824 skip = field_len - BN_num_bytes(x);
825 if (skip > field_len)
826 {
827 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
828 goto err;
829 }
830 while (skip > 0)
831 {
832 buf[i++] = 0;
833 skip--;
834 }
835 skip = BN_bn2bin(x, buf + i);
836 i += skip;
837 if (i != 1 + field_len)
838 {
839 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
840 goto err;
841 }
842
843 if (form == POINT_CONVERSION_UNCOMPRESSED || form == POINT_CONVERSION_HYBRID)
844 {
845 skip = field_len - BN_num_bytes(y);
846 if (skip > field_len)
847 {
848 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
849 goto err;
850 }
851 while (skip > 0)
852 {
853 buf[i++] = 0;
854 skip--;
855 }
856 skip = BN_bn2bin(y, buf + i);
857 i += skip;
858 }
859
860 if (i != ret)
861 {
862 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
863 goto err;
864 }
865 }
866
867 if (used_ctx)
868 BN_CTX_end(ctx);
869 if (new_ctx != NULL)
870 BN_CTX_free(new_ctx);
871 return ret;
872
873 err:
874 if (used_ctx)
875 BN_CTX_end(ctx);
876 if (new_ctx != NULL)
877 BN_CTX_free(new_ctx);
878 return 0;
879 }
880
881
882int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
883 const unsigned char *buf, size_t len, BN_CTX *ctx)
884 {
885 point_conversion_form_t form;
886 int y_bit;
887 BN_CTX *new_ctx = NULL;
888 BIGNUM *x, *y;
889 size_t field_len, enc_len;
890 int ret = 0;
891
892 if (len == 0)
893 {
894 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL);
895 return 0;
896 }
897 form = buf[0];
898 y_bit = form & 1;
899 form = form & ~1U;
900 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)
901 && (form != POINT_CONVERSION_UNCOMPRESSED)
902 && (form != POINT_CONVERSION_HYBRID))
903 {
904 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
905 return 0;
906 }
907 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit)
908 {
909 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
910 return 0;
911 }
912
913 if (form == 0)
914 {
915 if (len != 1)
916 {
917 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
918 return 0;
919 }
920
921 return EC_POINT_set_to_infinity(group, point);
922 }
923
924 field_len = BN_num_bytes(&group->field);
925 enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
926
927 if (len != enc_len)
928 {
929 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
930 return 0;
931 }
932
933 if (ctx == NULL)
934 {
935 ctx = new_ctx = BN_CTX_new();
936 if (ctx == NULL)
937 return 0;
938 }
939
940 BN_CTX_start(ctx);
941 x = BN_CTX_get(ctx);
942 y = BN_CTX_get(ctx);
943 if (y == NULL) goto err;
944
945 if (!BN_bin2bn(buf + 1, field_len, x)) goto err;
946 if (BN_ucmp(x, &group->field) >= 0)
947 {
948 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
949 goto err;
950 }
951
952 if (form == POINT_CONVERSION_COMPRESSED)
953 {
954 if (!EC_POINT_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx)) goto err;
955 }
956 else
957 {
958 if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) goto err;
959 if (BN_ucmp(y, &group->field) >= 0)
960 {
961 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
962 goto err;
963 }
964 if (form == POINT_CONVERSION_HYBRID)
965 {
966 if (y_bit != BN_is_odd(y))
967 {
968 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
969 goto err;
970 }
971 }
972
973 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
974 }
975
976 if (!EC_POINT_is_on_curve(group, point, ctx)) /* test required by X9.62 */
977 {
978 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE);
979 goto err;
980 }
981
982 ret = 1;
983
984 err:
985 BN_CTX_end(ctx);
986 if (new_ctx != NULL)
987 BN_CTX_free(new_ctx);
988 return ret;
989 }
990
991
992int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
993 {
994 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
995 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
996 const BIGNUM *p;
997 BN_CTX *new_ctx = NULL;
998 BIGNUM *n0, *n1, *n2, *n3, *n4, *n5, *n6;
999 int ret = 0;
1000
1001 if (a == b)
1002 return EC_POINT_dbl(group, r, a, ctx);
1003 if (EC_POINT_is_at_infinity(group, a))
1004 return EC_POINT_copy(r, b);
1005 if (EC_POINT_is_at_infinity(group, b))
1006 return EC_POINT_copy(r, a);
1007
1008 field_mul = group->meth->field_mul;
1009 field_sqr = group->meth->field_sqr;
1010 p = &group->field;
1011
1012 if (ctx == NULL)
1013 {
1014 ctx = new_ctx = BN_CTX_new();
1015 if (ctx == NULL)
1016 return 0;
1017 }
1018
1019 BN_CTX_start(ctx);
1020 n0 = BN_CTX_get(ctx);
1021 n1 = BN_CTX_get(ctx);
1022 n2 = BN_CTX_get(ctx);
1023 n3 = BN_CTX_get(ctx);
1024 n4 = BN_CTX_get(ctx);
1025 n5 = BN_CTX_get(ctx);
1026 n6 = BN_CTX_get(ctx);
1027 if (n6 == NULL) goto end;
1028
1029 /* Note that in this function we must not read components of 'a' or 'b'
1030 * once we have written the corresponding components of 'r'.
1031 * ('r' might be one of 'a' or 'b'.)
1032 */
1033
1034 /* n1, n2 */
1035 if (b->Z_is_one)
1036 {
1037 if (!BN_copy(n1, &a->X)) goto end;
1038 if (!BN_copy(n2, &a->Y)) goto end;
1039 /* n1 = X_a */
1040 /* n2 = Y_a */
1041 }
1042 else
1043 {
1044 if (!field_sqr(group, n0, &b->Z, ctx)) goto end;
1045 if (!field_mul(group, n1, &a->X, n0, ctx)) goto end;
1046 /* n1 = X_a * Z_b^2 */
1047
1048 if (!field_mul(group, n0, n0, &b->Z, ctx)) goto end;
1049 if (!field_mul(group, n2, &a->Y, n0, ctx)) goto end;
1050 /* n2 = Y_a * Z_b^3 */
1051 }
1052
1053 /* n3, n4 */
1054 if (a->Z_is_one)
1055 {
1056 if (!BN_copy(n3, &b->X)) goto end;
1057 if (!BN_copy(n4, &b->Y)) goto end;
1058 /* n3 = X_b */
1059 /* n4 = Y_b */
1060 }
1061 else
1062 {
1063 if (!field_sqr(group, n0, &a->Z, ctx)) goto end;
1064 if (!field_mul(group, n3, &b->X, n0, ctx)) goto end;
1065 /* n3 = X_b * Z_a^2 */
1066
1067 if (!field_mul(group, n0, n0, &a->Z, ctx)) goto end;
1068 if (!field_mul(group, n4, &b->Y, n0, ctx)) goto end;
1069 /* n4 = Y_b * Z_a^3 */
1070 }
1071
1072 /* n5, n6 */
1073 if (!BN_mod_sub_quick(n5, n1, n3, p)) goto end;
1074 if (!BN_mod_sub_quick(n6, n2, n4, p)) goto end;
1075 /* n5 = n1 - n3 */
1076 /* n6 = n2 - n4 */
1077
1078 if (BN_is_zero(n5))
1079 {
1080 if (BN_is_zero(n6))
1081 {
1082 /* a is the same point as b */
1083 BN_CTX_end(ctx);
1084 ret = EC_POINT_dbl(group, r, a, ctx);
1085 ctx = NULL;
1086 goto end;
1087 }
1088 else
1089 {
1090 /* a is the inverse of b */
1091 if (!BN_zero(&r->Z)) goto end;
1092 r->Z_is_one = 0;
1093 ret = 1;
1094 goto end;
1095 }
1096 }
1097
1098 /* 'n7', 'n8' */
1099 if (!BN_mod_add_quick(n1, n1, n3, p)) goto end;
1100 if (!BN_mod_add_quick(n2, n2, n4, p)) goto end;
1101 /* 'n7' = n1 + n3 */
1102 /* 'n8' = n2 + n4 */
1103
1104 /* Z_r */
1105 if (a->Z_is_one && b->Z_is_one)
1106 {
1107 if (!BN_copy(&r->Z, n5)) goto end;
1108 }
1109 else
1110 {
1111 if (a->Z_is_one)
1112 { if (!BN_copy(n0, &b->Z)) goto end; }
1113 else if (b->Z_is_one)
1114 { if (!BN_copy(n0, &a->Z)) goto end; }
1115 else
1116 { if (!field_mul(group, n0, &a->Z, &b->Z, ctx)) goto end; }
1117 if (!field_mul(group, &r->Z, n0, n5, ctx)) goto end;
1118 }
1119 r->Z_is_one = 0;
1120 /* Z_r = Z_a * Z_b * n5 */
1121
1122 /* X_r */
1123 if (!field_sqr(group, n0, n6, ctx)) goto end;
1124 if (!field_sqr(group, n4, n5, ctx)) goto end;
1125 if (!field_mul(group, n3, n1, n4, ctx)) goto end;
1126 if (!BN_mod_sub_quick(&r->X, n0, n3, p)) goto end;
1127 /* X_r = n6^2 - n5^2 * 'n7' */
1128
1129 /* 'n9' */
1130 if (!BN_mod_lshift1_quick(n0, &r->X, p)) goto end;
1131 if (!BN_mod_sub_quick(n0, n3, n0, p)) goto end;
1132 /* n9 = n5^2 * 'n7' - 2 * X_r */
1133
1134 /* Y_r */
1135 if (!field_mul(group, n0, n0, n6, ctx)) goto end;
1136 if (!field_mul(group, n5, n4, n5, ctx)) goto end; /* now n5 is n5^3 */
1137 if (!field_mul(group, n1, n2, n5, ctx)) goto end;
1138 if (!BN_mod_sub_quick(n0, n0, n1, p)) goto end;
1139 if (BN_is_odd(n0))
1140 if (!BN_add(n0, n0, p)) goto end;
1141 /* now 0 <= n0 < 2*p, and n0 is even */
1142 if (!BN_rshift1(&r->Y, n0)) goto end;
1143 /* Y_r = (n6 * 'n9' - 'n8' * 'n5^3') / 2 */
1144
1145 ret = 1;
1146
1147 end:
1148 if (ctx) /* otherwise we already called BN_CTX_end */
1149 BN_CTX_end(ctx);
1150 if (new_ctx != NULL)
1151 BN_CTX_free(new_ctx);
1152 return ret;
1153 }
1154
1155
1156int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
1157 {
1158 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1159 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1160 const BIGNUM *p;
1161 BN_CTX *new_ctx = NULL;
1162 BIGNUM *n0, *n1, *n2, *n3;
1163 int ret = 0;
1164
1165 if (EC_POINT_is_at_infinity(group, a))
1166 {
1167 if (!BN_zero(&r->Z)) return 0;
1168 r->Z_is_one = 0;
1169 return 1;
1170 }
1171
1172 field_mul = group->meth->field_mul;
1173 field_sqr = group->meth->field_sqr;
1174 p = &group->field;
1175
1176 if (ctx == NULL)
1177 {
1178 ctx = new_ctx = BN_CTX_new();
1179 if (ctx == NULL)
1180 return 0;
1181 }
1182
1183 BN_CTX_start(ctx);
1184 n0 = BN_CTX_get(ctx);
1185 n1 = BN_CTX_get(ctx);
1186 n2 = BN_CTX_get(ctx);
1187 n3 = BN_CTX_get(ctx);
1188 if (n3 == NULL) goto err;
1189
1190 /* Note that in this function we must not read components of 'a'
1191 * once we have written the corresponding components of 'r'.
1192 * ('r' might the same as 'a'.)
1193 */
1194
1195 /* n1 */
1196 if (a->Z_is_one)
1197 {
1198 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
1199 if (!BN_mod_lshift1_quick(n1, n0, p)) goto err;
1200 if (!BN_mod_add_quick(n0, n0, n1, p)) goto err;
1201 if (!BN_mod_add_quick(n1, n0, &group->a, p)) goto err;
1202 /* n1 = 3 * X_a^2 + a_curve */
1203 }
1204 else if (group->a_is_minus3)
1205 {
1206 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
1207 if (!BN_mod_add_quick(n0, &a->X, n1, p)) goto err;
1208 if (!BN_mod_sub_quick(n2, &a->X, n1, p)) goto err;
1209 if (!field_mul(group, n1, n0, n2, ctx)) goto err;
1210 if (!BN_mod_lshift1_quick(n0, n1, p)) goto err;
1211 if (!BN_mod_add_quick(n1, n0, n1, p)) goto err;
1212 /* n1 = 3 * (X_a + Z_a^2) * (X_a - Z_a^2)
1213 * = 3 * X_a^2 - 3 * Z_a^4 */
1214 }
1215 else
1216 {
1217 if (!field_sqr(group, n0, &a->X, ctx)) goto err;
1218 if (!BN_mod_lshift1_quick(n1, n0, p)) goto err;
1219 if (!BN_mod_add_quick(n0, n0, n1, p)) goto err;
1220 if (!field_sqr(group, n1, &a->Z, ctx)) goto err;
1221 if (!field_sqr(group, n1, n1, ctx)) goto err;
1222 if (!field_mul(group, n1, n1, &group->a, ctx)) goto err;
1223 if (!BN_mod_add_quick(n1, n1, n0, p)) goto err;
1224 /* n1 = 3 * X_a^2 + a_curve * Z_a^4 */
1225 }
1226
1227 /* Z_r */
1228 if (a->Z_is_one)
1229 {
1230 if (!BN_copy(n0, &a->Y)) goto err;
1231 }
1232 else
1233 {
1234 if (!field_mul(group, n0, &a->Y, &a->Z, ctx)) goto err;
1235 }
1236 if (!BN_mod_lshift1_quick(&r->Z, n0, p)) goto err;
1237 r->Z_is_one = 0;
1238 /* Z_r = 2 * Y_a * Z_a */
1239
1240 /* n2 */
1241 if (!field_sqr(group, n3, &a->Y, ctx)) goto err;
1242 if (!field_mul(group, n2, &a->X, n3, ctx)) goto err;
1243 if (!BN_mod_lshift_quick(n2, n2, 2, p)) goto err;
1244 /* n2 = 4 * X_a * Y_a^2 */
1245
1246 /* X_r */
1247 if (!BN_mod_lshift1_quick(n0, n2, p)) goto err;
1248 if (!field_sqr(group, &r->X, n1, ctx)) goto err;
1249 if (!BN_mod_sub_quick(&r->X, &r->X, n0, p)) goto err;
1250 /* X_r = n1^2 - 2 * n2 */
1251
1252 /* n3 */
1253 if (!field_sqr(group, n0, n3, ctx)) goto err;
1254 if (!BN_mod_lshift_quick(n3, n0, 3, p)) goto err;
1255 /* n3 = 8 * Y_a^4 */
1256
1257 /* Y_r */
1258 if (!BN_mod_sub_quick(n0, n2, &r->X, p)) goto err;
1259 if (!field_mul(group, n0, n1, n0, ctx)) goto err;
1260 if (!BN_mod_sub_quick(&r->Y, n0, n3, p)) goto err;
1261 /* Y_r = n1 * (n2 - X_r) - n3 */
1262
1263 ret = 1;
1264
1265 err:
1266 BN_CTX_end(ctx);
1267 if (new_ctx != NULL)
1268 BN_CTX_free(new_ctx);
1269 return ret;
1270 }
1271
1272
1273int ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1274 {
1275 if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y))
1276 /* point is its own inverse */
1277 return 1;
1278
1279 return BN_usub(&point->Y, &group->field, &point->Y);
1280 }
1281
1282
1283int ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
1284 {
1285 return BN_is_zero(&point->Z);
1286 }
1287
1288
1289int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
1290 {
1291 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1292 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1293 const BIGNUM *p;
1294 BN_CTX *new_ctx = NULL;
1295 BIGNUM *rh, *tmp1, *tmp2, *Z4, *Z6;
1296 int ret = -1;
1297
1298 if (EC_POINT_is_at_infinity(group, point))
1299 return 1;
1300
1301 field_mul = group->meth->field_mul;
1302 field_sqr = group->meth->field_sqr;
1303 p = &group->field;
1304
1305 if (ctx == NULL)
1306 {
1307 ctx = new_ctx = BN_CTX_new();
1308 if (ctx == NULL)
1309 return -1;
1310 }
1311
1312 BN_CTX_start(ctx);
1313 rh = BN_CTX_get(ctx);
1314 tmp1 = BN_CTX_get(ctx);
1315 tmp2 = BN_CTX_get(ctx);
1316 Z4 = BN_CTX_get(ctx);
1317 Z6 = BN_CTX_get(ctx);
1318 if (Z6 == NULL) goto err;
1319
1320 /* We have a curve defined by a Weierstrass equation
1321 * y^2 = x^3 + a*x + b.
1322 * The point to consider is given in Jacobian projective coordinates
1323 * where (X, Y, Z) represents (x, y) = (X/Z^2, Y/Z^3).
1324 * Substituting this and multiplying by Z^6 transforms the above equation into
1325 * Y^2 = X^3 + a*X*Z^4 + b*Z^6.
1326 * To test this, we add up the right-hand side in 'rh'.
1327 */
1328
1329 /* rh := X^3 */
1330 if (!field_sqr(group, rh, &point->X, ctx)) goto err;
1331 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1332
1333 if (!point->Z_is_one)
1334 {
1335 if (!field_sqr(group, tmp1, &point->Z, ctx)) goto err;
1336 if (!field_sqr(group, Z4, tmp1, ctx)) goto err;
1337 if (!field_mul(group, Z6, Z4, tmp1, ctx)) goto err;
1338
1339 /* rh := rh + a*X*Z^4 */
1340 if (!field_mul(group, tmp1, &point->X, Z4, ctx)) goto err;
1341 if (group->a_is_minus3)
1342 {
1343 if (!BN_mod_lshift1_quick(tmp2, tmp1, p)) goto err;
1344 if (!BN_mod_add_quick(tmp2, tmp2, tmp1, p)) goto err;
1345 if (!BN_mod_sub_quick(rh, rh, tmp2, p)) goto err;
1346 }
1347 else
1348 {
1349 if (!field_mul(group, tmp2, tmp1, &group->a, ctx)) goto err;
1350 if (!BN_mod_add_quick(rh, rh, tmp2, p)) goto err;
1351 }
1352
1353 /* rh := rh + b*Z^6 */
1354 if (!field_mul(group, tmp1, &group->b, Z6, ctx)) goto err;
1355 if (!BN_mod_add_quick(rh, rh, tmp1, p)) goto err;
1356 }
1357 else
1358 {
1359 /* point->Z_is_one */
1360
1361 /* rh := rh + a*X */
1362 if (group->a_is_minus3)
1363 {
1364 if (!BN_mod_lshift1_quick(tmp2, &point->X, p)) goto err;
1365 if (!BN_mod_add_quick(tmp2, tmp2, &point->X, p)) goto err;
1366 if (!BN_mod_sub_quick(rh, rh, tmp2, p)) goto err;
1367 }
1368 else
1369 {
1370 if (!field_mul(group, tmp2, &point->X, &group->a, ctx)) goto err;
1371 if (!BN_mod_add_quick(rh, rh, tmp2, p)) goto err;
1372 }
1373
1374 /* rh := rh + b */
1375 if (!BN_mod_add_quick(rh, rh, &group->b, p)) goto err;
1376 }
1377
1378 /* 'lh' := Y^2 */
1379 if (!field_sqr(group, tmp1, &point->Y, ctx)) goto err;
1380
1381 ret = (0 == BN_cmp(tmp1, rh));
1382
1383 err:
1384 BN_CTX_end(ctx);
1385 if (new_ctx != NULL)
1386 BN_CTX_free(new_ctx);
1387 return ret;
1388 }
1389
1390
1391int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
1392 {
1393 /* return values:
1394 * -1 error
1395 * 0 equal (in affine coordinates)
1396 * 1 not equal
1397 */
1398
1399 int (*field_mul)(const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
1400 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1401 BN_CTX *new_ctx = NULL;
1402 BIGNUM *tmp1, *tmp2, *Za23, *Zb23;
1403 const BIGNUM *tmp1_, *tmp2_;
1404 int ret = -1;
1405
1406 if (EC_POINT_is_at_infinity(group, a))
1407 {
1408 return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
1409 }
1410
1411 if (a->Z_is_one && b->Z_is_one)
1412 {
1413 return ((BN_cmp(&a->X, &b->X) == 0) && BN_cmp(&a->Y, &b->Y) == 0) ? 0 : 1;
1414 }
1415
1416 field_mul = group->meth->field_mul;
1417 field_sqr = group->meth->field_sqr;
1418
1419 if (ctx == NULL)
1420 {
1421 ctx = new_ctx = BN_CTX_new();
1422 if (ctx == NULL)
1423 return -1;
1424 }
1425
1426 BN_CTX_start(ctx);
1427 tmp1 = BN_CTX_get(ctx);
1428 tmp2 = BN_CTX_get(ctx);
1429 Za23 = BN_CTX_get(ctx);
1430 Zb23 = BN_CTX_get(ctx);
1431 if (Zb23 == NULL) goto end;
1432
1433 /* We have to decide whether
1434 * (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2, Y_b/Z_b^3),
1435 * or equivalently, whether
1436 * (X_a*Z_b^2, Y_a*Z_b^3) = (X_b*Z_a^2, Y_b*Z_a^3).
1437 */
1438
1439 if (!b->Z_is_one)
1440 {
1441 if (!field_sqr(group, Zb23, &b->Z, ctx)) goto end;
1442 if (!field_mul(group, tmp1, &a->X, Zb23, ctx)) goto end;
1443 tmp1_ = tmp1;
1444 }
1445 else
1446 tmp1_ = &a->X;
1447 if (!a->Z_is_one)
1448 {
1449 if (!field_sqr(group, Za23, &a->Z, ctx)) goto end;
1450 if (!field_mul(group, tmp2, &b->X, Za23, ctx)) goto end;
1451 tmp2_ = tmp2;
1452 }
1453 else
1454 tmp2_ = &b->X;
1455
1456 /* compare X_a*Z_b^2 with X_b*Z_a^2 */
1457 if (BN_cmp(tmp1_, tmp2_) != 0)
1458 {
1459 ret = 1; /* points differ */
1460 goto end;
1461 }
1462
1463
1464 if (!b->Z_is_one)
1465 {
1466 if (!field_mul(group, Zb23, Zb23, &b->Z, ctx)) goto end;
1467 if (!field_mul(group, tmp1, &a->Y, Zb23, ctx)) goto end;
1468 /* tmp1_ = tmp1 */
1469 }
1470 else
1471 tmp1_ = &a->Y;
1472 if (!a->Z_is_one)
1473 {
1474 if (!field_mul(group, Za23, Za23, &a->Z, ctx)) goto end;
1475 if (!field_mul(group, tmp2, &b->Y, Za23, ctx)) goto end;
1476 /* tmp2_ = tmp2 */
1477 }
1478 else
1479 tmp2_ = &b->Y;
1480
1481 /* compare Y_a*Z_b^3 with Y_b*Z_a^3 */
1482 if (BN_cmp(tmp1_, tmp2_) != 0)
1483 {
1484 ret = 1; /* points differ */
1485 goto end;
1486 }
1487
1488 /* points are equal */
1489 ret = 0;
1490
1491 end:
1492 BN_CTX_end(ctx);
1493 if (new_ctx != NULL)
1494 BN_CTX_free(new_ctx);
1495 return ret;
1496 }
1497
1498
1499int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1500 {
1501 BN_CTX *new_ctx = NULL;
1502 BIGNUM *x, *y;
1503 int ret = 0;
1504
1505 if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
1506 return 1;
1507
1508 if (ctx == NULL)
1509 {
1510 ctx = new_ctx = BN_CTX_new();
1511 if (ctx == NULL)
1512 return 0;
1513 }
1514
1515 BN_CTX_start(ctx);
1516 x = BN_CTX_get(ctx);
1517 y = BN_CTX_get(ctx);
1518 if (y == NULL) goto err;
1519
1520 if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1521 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;
1522 if (!point->Z_is_one)
1523 {
1524 ECerr(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE, ERR_R_INTERNAL_ERROR);
1525 goto err;
1526 }
1527
1528 ret = 1;
1529
1530 err:
1531 BN_CTX_end(ctx);
1532 if (new_ctx != NULL)
1533 BN_CTX_free(new_ctx);
1534 return ret;
1535 }
1536
1537
1538int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
1539 {
1540 BN_CTX *new_ctx = NULL;
1541 BIGNUM *tmp0, *tmp1;
1542 size_t pow2 = 0;
1543 BIGNUM **heap = NULL;
1544 size_t i;
1545 int ret = 0;
1546
1547 if (num == 0)
1548 return 1;
1549
1550 if (ctx == NULL)
1551 {
1552 ctx = new_ctx = BN_CTX_new();
1553 if (ctx == NULL)
1554 return 0;
1555 }
1556
1557 BN_CTX_start(ctx);
1558 tmp0 = BN_CTX_get(ctx);
1559 tmp1 = BN_CTX_get(ctx);
1560 if (tmp0 == NULL || tmp1 == NULL) goto err;
1561
1562 /* Before converting the individual points, compute inverses of all Z values.
1563 * Modular inversion is rather slow, but luckily we can do with a single
1564 * explicit inversion, plus about 3 multiplications per input value.
1565 */
1566
1567 pow2 = 1;
1568 while (num > pow2)
1569 pow2 <<= 1;
1570 /* Now pow2 is the smallest power of 2 satifsying pow2 >= num.
1571 * We need twice that. */
1572 pow2 <<= 1;
1573
1574 heap = OPENSSL_malloc(pow2 * sizeof heap[0]);
1575 if (heap == NULL) goto err;
1576
1577 /* The array is used as a binary tree, exactly as in heapsort:
1578 *
1579 * heap[1]
1580 * heap[2] heap[3]
1581 * heap[4] heap[5] heap[6] heap[7]
1582 * heap[8]heap[9] heap[10]heap[11] heap[12]heap[13] heap[14] heap[15]
1583 *
1584 * We put the Z's in the last line;
1585 * then we set each other node to the product of its two child-nodes (where
1586 * empty or 0 entries are treated as ones);
1587 * then we invert heap[1];
1588 * then we invert each other node by replacing it by the product of its
1589 * parent (after inversion) and its sibling (before inversion).
1590 */
1591 heap[0] = NULL;
1592 for (i = pow2/2 - 1; i > 0; i--)
1593 heap[i] = NULL;
1594 for (i = 0; i < num; i++)
1595 heap[pow2/2 + i] = &points[i]->Z;
1596 for (i = pow2/2 + num; i < pow2; i++)
1597 heap[i] = NULL;
1598
1599 /* set each node to the product of its children */
1600 for (i = pow2/2 - 1; i > 0; i--)
1601 {
1602 heap[i] = BN_new();
1603 if (heap[i] == NULL) goto err;
1604
1605 if (heap[2*i] != NULL)
1606 {
1607 if ((heap[2*i + 1] == NULL) || BN_is_zero(heap[2*i + 1]))
1608 {
1609 if (!BN_copy(heap[i], heap[2*i])) goto err;
1610 }
1611 else
1612 {
1613 if (BN_is_zero(heap[2*i]))
1614 {
1615 if (!BN_copy(heap[i], heap[2*i + 1])) goto err;
1616 }
1617 else
1618 {
1619 if (!group->meth->field_mul(group, heap[i],
1620 heap[2*i], heap[2*i + 1], ctx)) goto err;
1621 }
1622 }
1623 }
1624 }
1625
1626 /* invert heap[1] */
1627 if (!BN_is_zero(heap[1]))
1628 {
1629 if (!BN_mod_inverse(heap[1], heap[1], &group->field, ctx))
1630 {
1631 ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);
1632 goto err;
1633 }
1634 }
1635 if (group->meth->field_encode != 0)
1636 {
1637 /* in the Montgomery case, we just turned R*H (representing H)
1638 * into 1/(R*H), but we need R*(1/H) (representing 1/H);
1639 * i.e. we have need to multiply by the Montgomery factor twice */
1640 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1641 if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
1642 }
1643
1644 /* set other heap[i]'s to their inverses */
1645 for (i = 2; i < pow2/2 + num; i += 2)
1646 {
1647 /* i is even */
1648 if ((heap[i + 1] != NULL) && !BN_is_zero(heap[i + 1]))
1649 {
1650 if (!group->meth->field_mul(group, tmp0, heap[i/2], heap[i + 1], ctx)) goto err;
1651 if (!group->meth->field_mul(group, tmp1, heap[i/2], heap[i], ctx)) goto err;
1652 if (!BN_copy(heap[i], tmp0)) goto err;
1653 if (!BN_copy(heap[i + 1], tmp1)) goto err;
1654 }
1655 else
1656 {
1657 if (!BN_copy(heap[i], heap[i/2])) goto err;
1658 }
1659 }
1660
1661 /* we have replaced all non-zero Z's by their inverses, now fix up all the points */
1662 for (i = 0; i < num; i++)
1663 {
1664 EC_POINT *p = points[i];
1665
1666 if (!BN_is_zero(&p->Z))
1667 {
1668 /* turn (X, Y, 1/Z) into (X/Z^2, Y/Z^3, 1) */
1669
1670 if (!group->meth->field_sqr(group, tmp1, &p->Z, ctx)) goto err;
1671 if (!group->meth->field_mul(group, &p->X, &p->X, tmp1, ctx)) goto err;
1672
1673 if (!group->meth->field_mul(group, tmp1, tmp1, &p->Z, ctx)) goto err;
1674 if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp1, ctx)) goto err;
1675
1676 if (group->meth->field_set_to_one != 0)
1677 {
1678 if (!group->meth->field_set_to_one(group, &p->Z, ctx)) goto err;
1679 }
1680 else
1681 {
1682 if (!BN_one(&p->Z)) goto err;
1683 }
1684 p->Z_is_one = 1;
1685 }
1686 }
1687
1688 ret = 1;
1689
1690 err:
1691 BN_CTX_end(ctx);
1692 if (new_ctx != NULL)
1693 BN_CTX_free(new_ctx);
1694 if (heap != NULL)
1695 {
1696 /* heap[pow2/2] .. heap[pow2-1] have not been allocated locally! */
1697 for (i = pow2/2 - 1; i > 0; i--)
1698 {
1699 if (heap[i] != NULL)
1700 BN_clear_free(heap[i]);
1701 }
1702 OPENSSL_free(heap);
1703 }
1704 return ret;
1705 }
1706
1707
1708int ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1709 {
1710 return BN_mod_mul(r, a, b, &group->field, ctx);
1711 }
1712
1713
1714int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
1715 {
1716 return BN_mod_sqr(r, a, &group->field, ctx);
1717 }
diff --git a/src/lib/libcrypto/engine/README b/src/lib/libcrypto/engine/README
deleted file mode 100644
index 6b69b70f57..0000000000
--- a/src/lib/libcrypto/engine/README
+++ /dev/null
@@ -1,211 +0,0 @@
1Notes: 2001-09-24
2-----------------
3
4This "description" (if one chooses to call it that) needed some major updating
5so here goes. This update addresses a change being made at the same time to
6OpenSSL, and it pretty much completely restructures the underlying mechanics of
7the "ENGINE" code. So it serves a double purpose of being a "ENGINE internals
8for masochists" document *and* a rather extensive commit log message. (I'd get
9lynched for sticking all this in CHANGES or the commit mails :-).
10
11ENGINE_TABLE underlies this restructuring, as described in the internal header
12"eng_int.h", implemented in eng_table.c, and used in each of the "class" files;
13tb_rsa.c, tb_dsa.c, etc.
14
15However, "EVP_CIPHER" underlies the motivation and design of ENGINE_TABLE so
16I'll mention a bit about that first. EVP_CIPHER (and most of this applies
17equally to EVP_MD for digests) is both a "method" and a algorithm/mode
18identifier that, in the current API, "lingers". These cipher description +
19implementation structures can be defined or obtained directly by applications,
20or can be loaded "en masse" into EVP storage so that they can be catalogued and
21searched in various ways, ie. two ways of encrypting with the "des_cbc"
22algorithm/mode pair are;
23
24(i) directly;
25 const EVP_CIPHER *cipher = EVP_des_cbc();
26 EVP_EncryptInit(&ctx, cipher, key, iv);
27 [ ... use EVP_EncryptUpdate() and EVP_EncryptFinal() ...]
28
29(ii) indirectly;
30 OpenSSL_add_all_ciphers();
31 cipher = EVP_get_cipherbyname("des_cbc");
32 EVP_EncryptInit(&ctx, cipher, key, iv);
33 [ ... etc ... ]
34
35The latter is more generally used because it also allows ciphers/digests to be
36looked up based on other identifiers which can be useful for automatic cipher
37selection, eg. in SSL/TLS, or by user-controllable configuration.
38
39The important point about this is that EVP_CIPHER definitions and structures are
40passed around with impunity and there is no safe way, without requiring massive
41rewrites of many applications, to assume that EVP_CIPHERs can be reference
42counted. One an EVP_CIPHER is exposed to the caller, neither it nor anything it
43comes from can "safely" be destroyed. Unless of course the way of getting to
44such ciphers is via entirely distinct API calls that didn't exist before.
45However existing API usage cannot be made to understand when an EVP_CIPHER
46pointer, that has been passed to the caller, is no longer being used.
47
48The other problem with the existing API w.r.t. to hooking EVP_CIPHER support
49into ENGINE is storage - the OBJ_NAME-based storage used by EVP to register
50ciphers simultaneously registers cipher *types* and cipher *implementations* -
51they are effectively the same thing, an "EVP_CIPHER" pointer. The problem with
52hooking in ENGINEs is that multiple ENGINEs may implement the same ciphers. The
53solution is necessarily that ENGINE-provided ciphers simply are not registered,
54stored, or exposed to the caller in the same manner as existing ciphers. This is
55especially necessary considering the fact ENGINE uses reference counts to allow
56for cleanup, modularity, and DSO support - yet EVP_CIPHERs, as exposed to
57callers in the current API, support no such controls.
58
59Another sticking point for integrating cipher support into ENGINE is linkage.
60Already there is a problem with the way ENGINE supports RSA, DSA, etc whereby
61they are available *because* they're part of a giant ENGINE called "openssl".
62Ie. all implementations *have* to come from an ENGINE, but we get round that by
63having a giant ENGINE with all the software support encapsulated. This creates
64linker hassles if nothing else - linking a 1-line application that calls 2 basic
65RSA functions (eg. "RSA_free(RSA_new());") will result in large quantities of
66ENGINE code being linked in *and* because of that DSA, DH, and RAND also. If we
67continue with this approach for EVP_CIPHER support (even if it *was* possible)
68we would lose our ability to link selectively by selectively loading certain
69implementations of certain functionality. Touching any part of any kind of
70crypto would result in massive static linkage of everything else. So the
71solution is to change the way ENGINE feeds existing "classes", ie. how the
72hooking to ENGINE works from RSA, DSA, DH, RAND, as well as adding new hooking
73for EVP_CIPHER, and EVP_MD.
74
75The way this is now being done is by mostly reverting back to how things used to
76work prior to ENGINE :-). Ie. RSA now has a "RSA_METHOD" pointer again - this
77was previously replaced by an "ENGINE" pointer and all RSA code that required
78the RSA_METHOD would call ENGINE_get_RSA() each time on its ENGINE handle to
79temporarily get and use the ENGINE's RSA implementation. Apart from being more
80efficient, switching back to each RSA having an RSA_METHOD pointer also allows
81us to conceivably operate with *no* ENGINE. As we'll see, this removes any need
82for a fallback ENGINE that encapsulates default implementations - we can simply
83have our RSA structure pointing its RSA_METHOD pointer to the software
84implementation and have its ENGINE pointer set to NULL.
85
86A look at the EVP_CIPHER hooking is most explanatory, the RSA, DSA (etc) cases
87turn out to be degenerate forms of the same thing. The EVP storage of ciphers,
88and the existing EVP API functions that return "software" implementations and
89descriptions remain untouched. However, the storage takes more meaning in terms
90of "cipher description" and less meaning in terms of "implementation". When an
91EVP_CIPHER_CTX is actually initialised with an EVP_CIPHER method and is about to
92begin en/decryption, the hooking to ENGINE comes into play. What happens is that
93cipher-specific ENGINE code is asked for an ENGINE pointer (a functional
94reference) for any ENGINE that is registered to perform the algo/mode that the
95provided EVP_CIPHER structure represents. Under normal circumstances, that
96ENGINE code will return NULL because no ENGINEs will have had any cipher
97implementations *registered*. As such, a NULL ENGINE pointer is stored in the
98EVP_CIPHER_CTX context, and the EVP_CIPHER structure is left hooked into the
99context and so is used as the implementation. Pretty much how things work now
100except we'd have a redundant ENGINE pointer set to NULL and doing nothing.
101
102Conversely, if an ENGINE *has* been registered to perform the algorithm/mode
103combination represented by the provided EVP_CIPHER, then a functional reference
104to that ENGINE will be returned to the EVP_CIPHER_CTX during initialisation.
105That functional reference will be stored in the context (and released on
106cleanup) - and having that reference provides a *safe* way to use an EVP_CIPHER
107definition that is private to the ENGINE. Ie. the EVP_CIPHER provided by the
108application will actually be replaced by an EVP_CIPHER from the registered
109ENGINE - it will support the same algorithm/mode as the original but will be a
110completely different implementation. Because this EVP_CIPHER isn't stored in the
111EVP storage, nor is it returned to applications from traditional API functions,
112there is no associated problem with it not having reference counts. And of
113course, when one of these "private" cipher implementations is hooked into
114EVP_CIPHER_CTX, it is done whilst the EVP_CIPHER_CTX holds a functional
115reference to the ENGINE that owns it, thus the use of the ENGINE's EVP_CIPHER is
116safe.
117
118The "cipher-specific ENGINE code" I mentioned is implemented in tb_cipher.c but
119in essence it is simply an instantiation of "ENGINE_TABLE" code for use by
120EVP_CIPHER code. tb_digest.c is virtually identical but, of course, it is for
121use by EVP_MD code. Ditto for tb_rsa.c, tb_dsa.c, etc. These instantiations of
122ENGINE_TABLE essentially provide linker-separation of the classes so that even
123if ENGINEs implement *all* possible algorithms, an application using only
124EVP_CIPHER code will link at most code relating to EVP_CIPHER, tb_cipher.c, core
125ENGINE code that is independant of class, and of course the ENGINE
126implementation that the application loaded. It will *not* however link any
127class-specific ENGINE code for digests, RSA, etc nor will it bleed over into
128other APIs, such as the RSA/DSA/etc library code.
129
130ENGINE_TABLE is a little more complicated than may seem necessary but this is
131mostly to avoid a lot of "init()"-thrashing on ENGINEs (that may have to load
132DSOs, and other expensive setup that shouldn't be thrashed unnecessarily) *and*
133to duplicate "default" behaviour. Basically an ENGINE_TABLE instantiation, for
134example tb_cipher.c, implements a hash-table keyed by integer "nid" values.
135These nids provide the uniquenness of an algorithm/mode - and each nid will hash
136to a potentially NULL "ENGINE_PILE". An ENGINE_PILE is essentially a list of
137pointers to ENGINEs that implement that particular 'nid'. Each "pile" uses some
138caching tricks such that requests on that 'nid' will be cached and all future
139requests will return immediately (well, at least with minimal operation) unless
140a change is made to the pile, eg. perhaps an ENGINE was unloaded. The reason is
141that an application could have support for 10 ENGINEs statically linked
142in, and the machine in question may not have any of the hardware those 10
143ENGINEs support. If each of those ENGINEs has a "des_cbc" implementation, we
144want to avoid every EVP_CIPHER_CTX setup from trying (and failing) to initialise
145each of those 10 ENGINEs. Instead, the first such request will try to do that
146and will either return (and cache) a NULL ENGINE pointer or will return a
147functional reference to the first that successfully initialised. In the latter
148case it will also cache an extra functional reference to the ENGINE as a
149"default" for that 'nid'. The caching is acknowledged by a 'uptodate' variable
150that is unset only if un/registration takes place on that pile. Ie. if
151implementations of "des_cbc" are added or removed. This behaviour can be
152tweaked; the ENGINE_TABLE_FLAG_NOINIT value can be passed to
153ENGINE_set_table_flags(), in which case the only ENGINEs that tb_cipher.c will
154try to initialise from the "pile" will be those that are already initialised
155(ie. it's simply an increment of the functional reference count, and no real
156"initialisation" will take place).
157
158RSA, DSA, DH, and RAND all have their own ENGINE_TABLE code as well, and the
159difference is that they all use an implicit 'nid' of 1. Whereas EVP_CIPHERs are
160actually qualitatively different depending on 'nid' (the "des_cbc" EVP_CIPHER is
161not an interoperable implementation of "aes_256_cbc"), RSA_METHODs are
162necessarily interoperable and don't have different flavours, only different
163implementations. In other words, the ENGINE_TABLE for RSA will either be empty,
164or will have a single ENGING_PILE hashed to by the 'nid' 1 and that pile
165represents ENGINEs that implement the single "type" of RSA there is.
166
167Cleanup - the registration and unregistration may pose questions about how
168cleanup works with the ENGINE_PILE doing all this caching nonsense (ie. when the
169application or EVP_CIPHER code releases its last reference to an ENGINE, the
170ENGINE_PILE code may still have references and thus those ENGINEs will stay
171hooked in forever). The way this is handled is via "unregistration". With these
172new ENGINE changes, an abstract ENGINE can be loaded and initialised, but that
173is an algorithm-agnostic process. Even if initialised, it will not have
174registered any of its implementations (to do so would link all class "table"
175code despite the fact the application may use only ciphers, for example). This
176is deliberately a distinct step. Moreover, registration and unregistration has
177nothing to do with whether an ENGINE is *functional* or not (ie. you can even
178register an ENGINE and its implementations without it being operational, you may
179not even have the drivers to make it operate). What actually happens with
180respect to cleanup is managed inside eng_lib.c with the "engine_cleanup_***"
181functions. These functions are internal-only and each part of ENGINE code that
182could require cleanup will, upon performing its first allocation, register a
183callback with the "engine_cleanup" code. The other part of this that makes it
184tick is that the ENGINE_TABLE instantiations (tb_***.c) use NULL as their
185initialised state. So if RSA code asks for an ENGINE and no ENGINE has
186registered an implementation, the code will simply return NULL and the tb_rsa.c
187state will be unchanged. Thus, no cleanup is required unless registration takes
188place. ENGINE_cleanup() will simply iterate across a list of registered cleanup
189callbacks calling each in turn, and will then internally delete its own storage
190(a STACK). When a cleanup callback is next registered (eg. if the cleanup() is
191part of a gracefull restart and the application wants to cleanup all state then
192start again), the internal STACK storage will be freshly allocated. This is much
193the same as the situation in the ENGINE_TABLE instantiations ... NULL is the
194initialised state, so only modification operations (not queries) will cause that
195code to have to register a cleanup.
196
197What else? The bignum callbacks and associated ENGINE functions have been
198removed for two obvious reasons; (i) there was no way to generalise them to the
199mechanism now used by RSA/DSA/..., because there's no such thing as a BIGNUM
200method, and (ii) because of (i), there was no meaningful way for library or
201application code to automatically hook and use ENGINE supplied bignum functions
202anyway. Also, ENGINE_cpy() has been removed (although an internal-only version
203exists) - the idea of providing an ENGINE_cpy() function probably wasn't a good
204one and now certainly doesn't make sense in any generalised way. Some of the
205RSA, DSA, DH, and RAND functions that were fiddled during the original ENGINE
206changes have now, as a consequence, been reverted back. This is because the
207hooking of ENGINE is now automatic (and passive, it can interally use a NULL
208ENGINE pointer to simply ignore ENGINE from then on).
209
210Hell, that should be enough for now ... comments welcome: geoff@openssl.org
211
diff --git a/src/lib/libcrypto/engine/eng_all.c b/src/lib/libcrypto/engine/eng_all.c
deleted file mode 100644
index 0f6992a40d..0000000000
--- a/src/lib/libcrypto/engine/eng_all.c
+++ /dev/null
@@ -1,113 +0,0 @@
1/* crypto/engine/eng_all.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/err.h>
60#include <openssl/engine.h>
61#include "eng_int.h"
62
63void ENGINE_load_builtin_engines(void)
64 {
65 /* There's no longer any need for an "openssl" ENGINE unless, one day,
66 * it is the *only* way for standard builtin implementations to be be
67 * accessed (ie. it would be possible to statically link binaries with
68 * *no* builtin implementations). */
69#if 0
70 ENGINE_load_openssl();
71#endif
72 ENGINE_load_dynamic();
73#ifndef OPENSSL_NO_HW
74#ifndef OPENSSL_NO_HW_CSWIFT
75 ENGINE_load_cswift();
76#endif
77#ifndef OPENSSL_NO_HW_NCIPHER
78 ENGINE_load_chil();
79#endif
80#ifndef OPENSSL_NO_HW_ATALLA
81 ENGINE_load_atalla();
82#endif
83#ifndef OPENSSL_NO_HW_NURON
84 ENGINE_load_nuron();
85#endif
86#ifndef OPENSSL_NO_HW_UBSEC
87 ENGINE_load_ubsec();
88#endif
89#ifndef OPENSSL_NO_HW_AEP
90 ENGINE_load_aep();
91#endif
92#ifndef OPENSSL_NO_HW_SUREWARE
93 ENGINE_load_sureware();
94#endif
95#ifndef OPENSSL_NO_HW_4758_CCA
96 ENGINE_load_4758cca();
97#endif
98#if defined(__OpenBSD__) || defined(__FreeBSD__)
99 ENGINE_load_cryptodev();
100#endif
101#endif
102 }
103
104#if defined(__OpenBSD__) || defined(__FreeBSD__)
105void ENGINE_setup_bsd_cryptodev(void) {
106 static int bsd_cryptodev_default_loaded = 0;
107 if (!bsd_cryptodev_default_loaded) {
108 ENGINE_load_cryptodev();
109 ENGINE_register_all_complete();
110 }
111 bsd_cryptodev_default_loaded=1;
112}
113#endif
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c
deleted file mode 100644
index 4225760af1..0000000000
--- a/src/lib/libcrypto/engine/eng_cnf.c
+++ /dev/null
@@ -1,242 +0,0 @@
1/* eng_cnf.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/engine.h>
64
65/* #define ENGINE_CONF_DEBUG */
66
67/* ENGINE config module */
68
69static char *skip_dot(char *name)
70 {
71 char *p;
72 p = strchr(name, '.');
73 if (p)
74 return p + 1;
75 return name;
76 }
77
78static STACK_OF(ENGINE) *initialized_engines = NULL;
79
80static int int_engine_init(ENGINE *e)
81 {
82 if (!ENGINE_init(e))
83 return 0;
84 if (!initialized_engines)
85 initialized_engines = sk_ENGINE_new_null();
86 if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e))
87 {
88 ENGINE_finish(e);
89 return 0;
90 }
91 return 1;
92 }
93
94
95static int int_engine_configure(char *name, char *value, const CONF *cnf)
96 {
97 int i;
98 int ret = 0;
99 long do_init = -1;
100 STACK_OF(CONF_VALUE) *ecmds;
101 CONF_VALUE *ecmd;
102 char *ctrlname, *ctrlvalue;
103 ENGINE *e = NULL;
104 name = skip_dot(name);
105#ifdef ENGINE_CONF_DEBUG
106 fprintf(stderr, "Configuring engine %s\n", name);
107#endif
108 /* Value is a section containing ENGINE commands */
109 ecmds = NCONF_get_section(cnf, value);
110
111 if (!ecmds)
112 {
113 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR);
114 return 0;
115 }
116
117 for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++)
118 {
119 ecmd = sk_CONF_VALUE_value(ecmds, i);
120 ctrlname = skip_dot(ecmd->name);
121 ctrlvalue = ecmd->value;
122#ifdef ENGINE_CONF_DEBUG
123 fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue);
124#endif
125
126 /* First handle some special pseudo ctrls */
127
128 /* Override engine name to use */
129 if (!strcmp(ctrlname, "engine_id"))
130 name = ctrlvalue;
131 /* Load a dynamic ENGINE */
132 else if (!strcmp(ctrlname, "dynamic_path"))
133 {
134 e = ENGINE_by_id("dynamic");
135 if (!e)
136 goto err;
137 if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", ctrlvalue, 0))
138 goto err;
139 if (!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "2", 0))
140 goto err;
141 if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
142 goto err;
143 }
144 /* ... add other pseudos here ... */
145 else
146 {
147 /* At this point we need an ENGINE structural reference
148 * if we don't already have one.
149 */
150 if (!e)
151 {
152 e = ENGINE_by_id(name);
153 if (!e)
154 return 0;
155 }
156 /* Allow "EMPTY" to mean no value: this allows a valid
157 * "value" to be passed to ctrls of type NO_INPUT
158 */
159 if (!strcmp(ctrlvalue, "EMPTY"))
160 ctrlvalue = NULL;
161 if (!strcmp(ctrlname, "init"))
162 {
163 if (!NCONF_get_number_e(cnf, value, "init", &do_init))
164 goto err;
165 if (do_init == 1)
166 {
167 if (!int_engine_init(e))
168 goto err;
169 }
170 else if (do_init != 0)
171 {
172 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE);
173 goto err;
174 }
175 }
176 else if (!strcmp(ctrlname, "default_algorithms"))
177 {
178 if (!ENGINE_set_default_string(e, ctrlvalue))
179 goto err;
180 }
181 else if (!ENGINE_ctrl_cmd_string(e,
182 ctrlname, ctrlvalue, 0))
183 return 0;
184 }
185
186
187
188 }
189 if (e && (do_init == -1) && !int_engine_init(e))
190 goto err;
191 ret = 1;
192 err:
193 if (e)
194 ENGINE_free(e);
195 return ret;
196 }
197
198
199static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf)
200 {
201 STACK_OF(CONF_VALUE) *elist;
202 CONF_VALUE *cval;
203 int i;
204#ifdef ENGINE_CONF_DEBUG
205 fprintf(stderr, "Called engine module: name %s, value %s\n",
206 CONF_imodule_get_name(md), CONF_imodule_get_value(md));
207#endif
208 /* Value is a section containing ENGINEs to configure */
209 elist = NCONF_get_section(cnf, CONF_imodule_get_value(md));
210
211 if (!elist)
212 {
213 ENGINEerr(ENGINE_F_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR);
214 return 0;
215 }
216
217 for (i = 0; i < sk_CONF_VALUE_num(elist); i++)
218 {
219 cval = sk_CONF_VALUE_value(elist, i);
220 if (!int_engine_configure(cval->name, cval->value, cnf))
221 return 0;
222 }
223
224 return 1;
225 }
226
227static void int_engine_module_finish(CONF_IMODULE *md)
228 {
229 ENGINE *e;
230 while ((e = sk_ENGINE_pop(initialized_engines)))
231 ENGINE_finish(e);
232 sk_ENGINE_free(initialized_engines);
233 initialized_engines = NULL;
234 }
235
236
237void ENGINE_add_conf_module(void)
238 {
239 CONF_module_add("engines",
240 int_engine_module_init,
241 int_engine_module_finish);
242 }
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c
deleted file mode 100644
index 412c73fb0f..0000000000
--- a/src/lib/libcrypto/engine/eng_ctrl.c
+++ /dev/null
@@ -1,391 +0,0 @@
1/* crypto/engine/eng_ctrl.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* When querying a ENGINE-specific control command's 'description', this string
62 * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
63static const char *int_no_description = "";
64
65/* These internal functions handle 'CMD'-related control commands when the
66 * ENGINE in question has asked us to take care of it (ie. the ENGINE did not
67 * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */
68
69static int int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn)
70 {
71 if((defn->cmd_num == 0) || (defn->cmd_name == NULL))
72 return 1;
73 return 0;
74 }
75
76static int int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s)
77 {
78 int idx = 0;
79 while(!int_ctrl_cmd_is_null(defn) && (strcmp(defn->cmd_name, s) != 0))
80 {
81 idx++;
82 defn++;
83 }
84 if(int_ctrl_cmd_is_null(defn))
85 /* The given name wasn't found */
86 return -1;
87 return idx;
88 }
89
90static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
91 {
92 int idx = 0;
93 /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So
94 * our searches don't need to take any longer than necessary. */
95 while(!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num))
96 {
97 idx++;
98 defn++;
99 }
100 if(defn->cmd_num == num)
101 return idx;
102 /* The given cmd_num wasn't found */
103 return -1;
104 }
105
106static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)())
107 {
108 int idx;
109 char *s = (char *)p;
110 /* Take care of the easy one first (eg. it requires no searches) */
111 if(cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE)
112 {
113 if((e->cmd_defns == NULL) || int_ctrl_cmd_is_null(e->cmd_defns))
114 return 0;
115 return e->cmd_defns->cmd_num;
116 }
117 /* One or two commands require that "p" be a valid string buffer */
118 if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) ||
119 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
120 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD))
121 {
122 if(s == NULL)
123 {
124 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
125 ERR_R_PASSED_NULL_PARAMETER);
126 return -1;
127 }
128 }
129 /* Now handle cmd_name -> cmd_num conversion */
130 if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME)
131 {
132 if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_name(
133 e->cmd_defns, s)) < 0))
134 {
135 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
136 ENGINE_R_INVALID_CMD_NAME);
137 return -1;
138 }
139 return e->cmd_defns[idx].cmd_num;
140 }
141 /* For the rest of the commands, the 'long' argument must specify a
142 * valie command number - so we need to conduct a search. */
143 if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_num(e->cmd_defns,
144 (unsigned int)i)) < 0))
145 {
146 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
147 ENGINE_R_INVALID_CMD_NUMBER);
148 return -1;
149 }
150 /* Now the logic splits depending on command type */
151 switch(cmd)
152 {
153 case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
154 idx++;
155 if(int_ctrl_cmd_is_null(e->cmd_defns + idx))
156 /* end-of-list */
157 return 0;
158 else
159 return e->cmd_defns[idx].cmd_num;
160 case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
161 return strlen(e->cmd_defns[idx].cmd_name);
162 case ENGINE_CTRL_GET_NAME_FROM_CMD:
163 return BIO_snprintf(s,strlen(e->cmd_defns[idx].cmd_name) + 1,
164 "%s", e->cmd_defns[idx].cmd_name);
165 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
166 if(e->cmd_defns[idx].cmd_desc)
167 return strlen(e->cmd_defns[idx].cmd_desc);
168 return strlen(int_no_description);
169 case ENGINE_CTRL_GET_DESC_FROM_CMD:
170 if(e->cmd_defns[idx].cmd_desc)
171 return BIO_snprintf(s,
172 strlen(e->cmd_defns[idx].cmd_desc) + 1,
173 "%s", e->cmd_defns[idx].cmd_desc);
174 return BIO_snprintf(s, strlen(int_no_description) + 1,"%s",
175 int_no_description);
176 case ENGINE_CTRL_GET_CMD_FLAGS:
177 return e->cmd_defns[idx].cmd_flags;
178 }
179 /* Shouldn't really be here ... */
180 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,ENGINE_R_INTERNAL_LIST_ERROR);
181 return -1;
182 }
183
184int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
185 {
186 int ctrl_exists, ref_exists;
187 if(e == NULL)
188 {
189 ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
190 return 0;
191 }
192 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
193 ref_exists = ((e->struct_ref > 0) ? 1 : 0);
194 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
195 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
196 if(!ref_exists)
197 {
198 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE);
199 return 0;
200 }
201 /* Intercept any "root-level" commands before trying to hand them on to
202 * ctrl() handlers. */
203 switch(cmd)
204 {
205 case ENGINE_CTRL_HAS_CTRL_FUNCTION:
206 return ctrl_exists;
207 case ENGINE_CTRL_GET_FIRST_CMD_TYPE:
208 case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
209 case ENGINE_CTRL_GET_CMD_FROM_NAME:
210 case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
211 case ENGINE_CTRL_GET_NAME_FROM_CMD:
212 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
213 case ENGINE_CTRL_GET_DESC_FROM_CMD:
214 case ENGINE_CTRL_GET_CMD_FLAGS:
215 if(ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
216 return int_ctrl_helper(e,cmd,i,p,f);
217 if(!ctrl_exists)
218 {
219 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
220 /* For these cmd-related functions, failure is indicated
221 * by a -1 return value (because 0 is used as a valid
222 * return in some places). */
223 return -1;
224 }
225 default:
226 break;
227 }
228 /* Anything else requires a ctrl() handler to exist. */
229 if(!ctrl_exists)
230 {
231 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
232 return 0;
233 }
234 return e->ctrl(e, cmd, i, p, f);
235 }
236
237int ENGINE_cmd_is_executable(ENGINE *e, int cmd)
238 {
239 int flags;
240 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, NULL, NULL)) < 0)
241 {
242 ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,
243 ENGINE_R_INVALID_CMD_NUMBER);
244 return 0;
245 }
246 if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
247 !(flags & ENGINE_CMD_FLAG_NUMERIC) &&
248 !(flags & ENGINE_CMD_FLAG_STRING))
249 return 0;
250 return 1;
251 }
252
253int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
254 long i, void *p, void (*f)(), int cmd_optional)
255 {
256 int num;
257
258 if((e == NULL) || (cmd_name == NULL))
259 {
260 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
261 ERR_R_PASSED_NULL_PARAMETER);
262 return 0;
263 }
264 if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
265 ENGINE_CTRL_GET_CMD_FROM_NAME,
266 0, (void *)cmd_name, NULL)) <= 0))
267 {
268 /* If the command didn't *have* to be supported, we fake
269 * success. This allows certain settings to be specified for
270 * multiple ENGINEs and only require a change of ENGINE id
271 * (without having to selectively apply settings). Eg. changing
272 * from a hardware device back to the regular software ENGINE
273 * without editing the config file, etc. */
274 if(cmd_optional)
275 {
276 ERR_clear_error();
277 return 1;
278 }
279 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
280 ENGINE_R_INVALID_CMD_NAME);
281 return 0;
282 }
283 /* Force the result of the control command to 0 or 1, for the reasons
284 * mentioned before. */
285 if (ENGINE_ctrl(e, num, i, p, f))
286 return 1;
287 return 0;
288 }
289
290int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
291 int cmd_optional)
292 {
293 int num, flags;
294 long l;
295 char *ptr;
296 if((e == NULL) || (cmd_name == NULL))
297 {
298 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
299 ERR_R_PASSED_NULL_PARAMETER);
300 return 0;
301 }
302 if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
303 ENGINE_CTRL_GET_CMD_FROM_NAME,
304 0, (void *)cmd_name, NULL)) <= 0))
305 {
306 /* If the command didn't *have* to be supported, we fake
307 * success. This allows certain settings to be specified for
308 * multiple ENGINEs and only require a change of ENGINE id
309 * (without having to selectively apply settings). Eg. changing
310 * from a hardware device back to the regular software ENGINE
311 * without editing the config file, etc. */
312 if(cmd_optional)
313 {
314 ERR_clear_error();
315 return 1;
316 }
317 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
318 ENGINE_R_INVALID_CMD_NAME);
319 return 0;
320 }
321 if(!ENGINE_cmd_is_executable(e, num))
322 {
323 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
324 ENGINE_R_CMD_NOT_EXECUTABLE);
325 return 0;
326 }
327 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0)
328 {
329 /* Shouldn't happen, given that ENGINE_cmd_is_executable()
330 * returned success. */
331 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
332 ENGINE_R_INTERNAL_LIST_ERROR);
333 return 0;
334 }
335 /* If the command takes no input, there must be no input. And vice
336 * versa. */
337 if(flags & ENGINE_CMD_FLAG_NO_INPUT)
338 {
339 if(arg != NULL)
340 {
341 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
342 ENGINE_R_COMMAND_TAKES_NO_INPUT);
343 return 0;
344 }
345 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1
346 * rather than returning it as "return data". This is to ensure
347 * usage of these commands is consistent across applications and
348 * that certain applications don't understand it one way, and
349 * others another. */
350 if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
351 return 1;
352 return 0;
353 }
354 /* So, we require input */
355 if(arg == NULL)
356 {
357 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
358 ENGINE_R_COMMAND_TAKES_INPUT);
359 return 0;
360 }
361 /* If it takes string input, that's easy */
362 if(flags & ENGINE_CMD_FLAG_STRING)
363 {
364 /* Same explanation as above */
365 if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
366 return 1;
367 return 0;
368 }
369 /* If it doesn't take numeric either, then it is unsupported for use in
370 * a config-setting situation, which is what this function is for. This
371 * should never happen though, because ENGINE_cmd_is_executable() was
372 * used. */
373 if(!(flags & ENGINE_CMD_FLAG_NUMERIC))
374 {
375 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
376 ENGINE_R_INTERNAL_LIST_ERROR);
377 return 0;
378 }
379 l = strtol(arg, &ptr, 10);
380 if((arg == ptr) || (*ptr != '\0'))
381 {
382 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
383 ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
384 return 0;
385 }
386 /* Force the result of the control command to 0 or 1, for the reasons
387 * mentioned before. */
388 if(ENGINE_ctrl(e, num, l, NULL, NULL))
389 return 1;
390 return 0;
391 }
diff --git a/src/lib/libcrypto/engine/eng_dyn.c b/src/lib/libcrypto/engine/eng_dyn.c
deleted file mode 100644
index 4139a16e76..0000000000
--- a/src/lib/libcrypto/engine/eng_dyn.c
+++ /dev/null
@@ -1,460 +0,0 @@
1/* crypto/engine/eng_dyn.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include "eng_int.h"
64#include <openssl/engine.h>
65#include <openssl/dso.h>
66
67/* Shared libraries implementing ENGINEs for use by the "dynamic" ENGINE loader
68 * should implement the hook-up functions with the following prototypes. */
69
70/* Our ENGINE handlers */
71static int dynamic_init(ENGINE *e);
72static int dynamic_finish(ENGINE *e);
73static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
74/* Predeclare our context type */
75typedef struct st_dynamic_data_ctx dynamic_data_ctx;
76/* The implementation for the important control command */
77static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx);
78
79#define DYNAMIC_CMD_SO_PATH ENGINE_CMD_BASE
80#define DYNAMIC_CMD_NO_VCHECK (ENGINE_CMD_BASE + 1)
81#define DYNAMIC_CMD_ID (ENGINE_CMD_BASE + 2)
82#define DYNAMIC_CMD_LIST_ADD (ENGINE_CMD_BASE + 3)
83#define DYNAMIC_CMD_LOAD (ENGINE_CMD_BASE + 4)
84
85/* The constants used when creating the ENGINE */
86static const char *engine_dynamic_id = "dynamic";
87static const char *engine_dynamic_name = "Dynamic engine loading support";
88static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = {
89 {DYNAMIC_CMD_SO_PATH,
90 "SO_PATH",
91 "Specifies the path to the new ENGINE shared library",
92 ENGINE_CMD_FLAG_STRING},
93 {DYNAMIC_CMD_NO_VCHECK,
94 "NO_VCHECK",
95 "Specifies to continue even if version checking fails (boolean)",
96 ENGINE_CMD_FLAG_NUMERIC},
97 {DYNAMIC_CMD_ID,
98 "ID",
99 "Specifies an ENGINE id name for loading",
100 ENGINE_CMD_FLAG_STRING},
101 {DYNAMIC_CMD_LIST_ADD,
102 "LIST_ADD",
103 "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)",
104 ENGINE_CMD_FLAG_NUMERIC},
105 {DYNAMIC_CMD_LOAD,
106 "LOAD",
107 "Load up the ENGINE specified by other settings",
108 ENGINE_CMD_FLAG_NO_INPUT},
109 {0, NULL, NULL, 0}
110 };
111static const ENGINE_CMD_DEFN dynamic_cmd_defns_empty[] = {
112 {0, NULL, NULL, 0}
113 };
114
115/* Loading code stores state inside the ENGINE structure via the "ex_data"
116 * element. We load all our state into a single structure and use that as a
117 * single context in the "ex_data" stack. */
118struct st_dynamic_data_ctx
119 {
120 /* The DSO object we load that supplies the ENGINE code */
121 DSO *dynamic_dso;
122 /* The function pointer to the version checking shared library function */
123 dynamic_v_check_fn v_check;
124 /* The function pointer to the engine-binding shared library function */
125 dynamic_bind_engine bind_engine;
126 /* The default name/path for loading the shared library */
127 const char *DYNAMIC_LIBNAME;
128 /* Whether to continue loading on a version check failure */
129 int no_vcheck;
130 /* If non-NULL, stipulates the 'id' of the ENGINE to be loaded */
131 const char *engine_id;
132 /* If non-zero, a successfully loaded ENGINE should be added to the internal
133 * ENGINE list. If 2, the add must succeed or the entire load should fail. */
134 int list_add_value;
135 /* The symbol name for the version checking function */
136 const char *DYNAMIC_F1;
137 /* The symbol name for the "initialise ENGINE structure" function */
138 const char *DYNAMIC_F2;
139 };
140
141/* This is the "ex_data" index we obtain and reserve for use with our context
142 * structure. */
143static int dynamic_ex_data_idx = -1;
144
145/* Because our ex_data element may or may not get allocated depending on whether
146 * a "first-use" occurs before the ENGINE is freed, we have a memory leak
147 * problem to solve. We can't declare a "new" handler for the ex_data as we
148 * don't want a dynamic_data_ctx in *all* ENGINE structures of all types (this
149 * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free"
150 * handler and that will get called if an ENGINE is being destroyed and there
151 * was an ex_data element corresponding to our context type. */
152static void dynamic_data_ctx_free_func(void *parent, void *ptr,
153 CRYPTO_EX_DATA *ad, int idx, long argl, void *argp)
154 {
155 if(ptr)
156 {
157 dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr;
158 if(ctx->dynamic_dso)
159 DSO_free(ctx->dynamic_dso);
160 if(ctx->DYNAMIC_LIBNAME)
161 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
162 if(ctx->engine_id)
163 OPENSSL_free((void*)ctx->engine_id);
164 OPENSSL_free(ctx);
165 }
166 }
167
168/* Construct the per-ENGINE context. We create it blindly and then use a lock to
169 * check for a race - if so, all but one of the threads "racing" will have
170 * wasted their time. The alternative involves creating everything inside the
171 * lock which is far worse. */
172static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
173 {
174 dynamic_data_ctx *c;
175 c = OPENSSL_malloc(sizeof(dynamic_data_ctx));
176 if(!c)
177 {
178 ENGINEerr(ENGINE_F_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
179 return 0;
180 }
181 memset(c, 0, sizeof(dynamic_data_ctx));
182 c->dynamic_dso = NULL;
183 c->v_check = NULL;
184 c->bind_engine = NULL;
185 c->DYNAMIC_LIBNAME = NULL;
186 c->no_vcheck = 0;
187 c->engine_id = NULL;
188 c->list_add_value = 0;
189 c->DYNAMIC_F1 = "v_check";
190 c->DYNAMIC_F2 = "bind_engine";
191 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
192 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
193 dynamic_ex_data_idx)) == NULL)
194 {
195 /* Good, we're the first */
196 ENGINE_set_ex_data(e, dynamic_ex_data_idx, c);
197 *ctx = c;
198 c = NULL;
199 }
200 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
201 /* If we lost the race to set the context, c is non-NULL and *ctx is the
202 * context of the thread that won. */
203 if(c)
204 OPENSSL_free(c);
205 return 1;
206 }
207
208/* This function retrieves the context structure from an ENGINE's "ex_data", or
209 * if it doesn't exist yet, sets it up. */
210static dynamic_data_ctx *dynamic_get_data_ctx(ENGINE *e)
211 {
212 dynamic_data_ctx *ctx;
213 if(dynamic_ex_data_idx < 0)
214 {
215 /* Create and register the ENGINE ex_data, and associate our
216 * "free" function with it to ensure any allocated contexts get
217 * freed when an ENGINE goes underground. */
218 int new_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL,
219 dynamic_data_ctx_free_func);
220 if(new_idx == -1)
221 {
222 ENGINEerr(ENGINE_F_DYNAMIC_GET_DATA_CTX,ENGINE_R_NO_INDEX);
223 return NULL;
224 }
225 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
226 /* Avoid a race by checking again inside this lock */
227 if(dynamic_ex_data_idx < 0)
228 {
229 /* Good, someone didn't beat us to it */
230 dynamic_ex_data_idx = new_idx;
231 new_idx = -1;
232 }
233 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
234 /* In theory we could "give back" the index here if
235 * (new_idx>-1), but it's not possible and wouldn't gain us much
236 * if it were. */
237 }
238 ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, dynamic_ex_data_idx);
239 /* Check if the context needs to be created */
240 if((ctx == NULL) && !dynamic_set_data_ctx(e, &ctx))
241 /* "set_data" will set errors if necessary */
242 return NULL;
243 return ctx;
244 }
245
246static ENGINE *engine_dynamic(void)
247 {
248 ENGINE *ret = ENGINE_new();
249 if(!ret)
250 return NULL;
251 if(!ENGINE_set_id(ret, engine_dynamic_id) ||
252 !ENGINE_set_name(ret, engine_dynamic_name) ||
253 !ENGINE_set_init_function(ret, dynamic_init) ||
254 !ENGINE_set_finish_function(ret, dynamic_finish) ||
255 !ENGINE_set_ctrl_function(ret, dynamic_ctrl) ||
256 !ENGINE_set_flags(ret, ENGINE_FLAGS_BY_ID_COPY) ||
257 !ENGINE_set_cmd_defns(ret, dynamic_cmd_defns))
258 {
259 ENGINE_free(ret);
260 return NULL;
261 }
262 return ret;
263 }
264
265void ENGINE_load_dynamic(void)
266 {
267 ENGINE *toadd = engine_dynamic();
268 if(!toadd) return;
269 ENGINE_add(toadd);
270 /* If the "add" worked, it gets a structural reference. So either way,
271 * we release our just-created reference. */
272 ENGINE_free(toadd);
273 /* If the "add" didn't work, it was probably a conflict because it was
274 * already added (eg. someone calling ENGINE_load_blah then calling
275 * ENGINE_load_builtin_engines() perhaps). */
276 ERR_clear_error();
277 }
278
279static int dynamic_init(ENGINE *e)
280 {
281 /* We always return failure - the "dyanamic" engine itself can't be used
282 * for anything. */
283 return 0;
284 }
285
286static int dynamic_finish(ENGINE *e)
287 {
288 /* This should never be called on account of "dynamic_init" always
289 * failing. */
290 return 0;
291 }
292
293static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
294 {
295 dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);
296 int initialised;
297
298 if(!ctx)
299 {
300 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_NOT_LOADED);
301 return 0;
302 }
303 initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1);
304 /* All our control commands require the ENGINE to be uninitialised */
305 if(initialised)
306 {
307 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
308 ENGINE_R_ALREADY_LOADED);
309 return 0;
310 }
311 switch(cmd)
312 {
313 case DYNAMIC_CMD_SO_PATH:
314 /* a NULL 'p' or a string of zero-length is the same thing */
315 if(p && (strlen((const char *)p) < 1))
316 p = NULL;
317 if(ctx->DYNAMIC_LIBNAME)
318 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
319 if(p)
320 ctx->DYNAMIC_LIBNAME = BUF_strdup(p);
321 else
322 ctx->DYNAMIC_LIBNAME = NULL;
323 return (ctx->DYNAMIC_LIBNAME ? 1 : 0);
324 case DYNAMIC_CMD_NO_VCHECK:
325 ctx->no_vcheck = ((i == 0) ? 0 : 1);
326 return 1;
327 case DYNAMIC_CMD_ID:
328 /* a NULL 'p' or a string of zero-length is the same thing */
329 if(p && (strlen((const char *)p) < 1))
330 p = NULL;
331 if(ctx->engine_id)
332 OPENSSL_free((void*)ctx->engine_id);
333 if(p)
334 ctx->engine_id = BUF_strdup(p);
335 else
336 ctx->engine_id = NULL;
337 return (ctx->engine_id ? 1 : 0);
338 case DYNAMIC_CMD_LIST_ADD:
339 if((i < 0) || (i > 2))
340 {
341 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
342 ENGINE_R_INVALID_ARGUMENT);
343 return 0;
344 }
345 ctx->list_add_value = (int)i;
346 return 1;
347 case DYNAMIC_CMD_LOAD:
348 return dynamic_load(e, ctx);
349 default:
350 break;
351 }
352 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
353 return 0;
354 }
355
356static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
357 {
358 ENGINE cpy;
359 dynamic_fns fns;
360
361 if(!ctx->DYNAMIC_LIBNAME || ((ctx->dynamic_dso = DSO_load(NULL,
362 ctx->DYNAMIC_LIBNAME, NULL, 0)) == NULL))
363 {
364 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
365 ENGINE_R_DSO_NOT_FOUND);
366 return 0;
367 }
368 /* We have to find a bind function otherwise it'll always end badly */
369 if(!(ctx->bind_engine = (dynamic_bind_engine)DSO_bind_func(
370 ctx->dynamic_dso, ctx->DYNAMIC_F2)))
371 {
372 ctx->bind_engine = NULL;
373 DSO_free(ctx->dynamic_dso);
374 ctx->dynamic_dso = NULL;
375 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
376 ENGINE_R_DSO_FAILURE);
377 return 0;
378 }
379 /* Do we perform version checking? */
380 if(!ctx->no_vcheck)
381 {
382 unsigned long vcheck_res = 0;
383 /* Now we try to find a version checking function and decide how
384 * to cope with failure if/when it fails. */
385 ctx->v_check = (dynamic_v_check_fn)DSO_bind_func(
386 ctx->dynamic_dso, ctx->DYNAMIC_F1);
387 if(ctx->v_check)
388 vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION);
389 /* We fail if the version checker veto'd the load *or* if it is
390 * deferring to us (by returning its version) and we think it is
391 * too old. */
392 if(vcheck_res < OSSL_DYNAMIC_OLDEST)
393 {
394 /* Fail */
395 ctx->bind_engine = NULL;
396 ctx->v_check = NULL;
397 DSO_free(ctx->dynamic_dso);
398 ctx->dynamic_dso = NULL;
399 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
400 ENGINE_R_VERSION_INCOMPATIBILITY);
401 return 0;
402 }
403 }
404 /* First binary copy the ENGINE structure so that we can roll back if
405 * the hand-over fails */
406 memcpy(&cpy, e, sizeof(ENGINE));
407 /* Provide the ERR, "ex_data", memory, and locking callbacks so the
408 * loaded library uses our state rather than its own. FIXME: As noted in
409 * engine.h, much of this would be simplified if each area of code
410 * provided its own "summary" structure of all related callbacks. It
411 * would also increase opaqueness. */
412 fns.err_fns = ERR_get_implementation();
413 fns.ex_data_fns = CRYPTO_get_ex_data_implementation();
414 CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
415 &fns.mem_fns.realloc_cb,
416 &fns.mem_fns.free_cb);
417 fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback();
418 fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback();
419 fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback();
420 fns.lock_fns.dynlock_lock_cb = CRYPTO_get_dynlock_lock_callback();
421 fns.lock_fns.dynlock_destroy_cb = CRYPTO_get_dynlock_destroy_callback();
422 /* Now that we've loaded the dynamic engine, make sure no "dynamic"
423 * ENGINE elements will show through. */
424 engine_set_all_null(e);
425
426 /* Try to bind the ENGINE onto our own ENGINE structure */
427 if(!ctx->bind_engine(e, ctx->engine_id, &fns))
428 {
429 ctx->bind_engine = NULL;
430 ctx->v_check = NULL;
431 DSO_free(ctx->dynamic_dso);
432 ctx->dynamic_dso = NULL;
433 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,ENGINE_R_INIT_FAILED);
434 /* Copy the original ENGINE structure back */
435 memcpy(e, &cpy, sizeof(ENGINE));
436 return 0;
437 }
438 /* Do we try to add this ENGINE to the internal list too? */
439 if(ctx->list_add_value > 0)
440 {
441 if(!ENGINE_add(e))
442 {
443 /* Do we tolerate this or fail? */
444 if(ctx->list_add_value > 1)
445 {
446 /* Fail - NB: By this time, it's too late to
447 * rollback, and trying to do so allows the
448 * bind_engine() code to have created leaks. We
449 * just have to fail where we are, after the
450 * ENGINE has changed. */
451 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
452 ENGINE_R_CONFLICTING_ENGINE_ID);
453 return 0;
454 }
455 /* Tolerate */
456 ERR_clear_error();
457 }
458 }
459 return 1;
460 }
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c
deleted file mode 100644
index fdc0e7be0f..0000000000
--- a/src/lib/libcrypto/engine/eng_err.c
+++ /dev/null
@@ -1,170 +0,0 @@
1/* crypto/engine/eng_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/engine.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_ENGINE,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason)
70
71static ERR_STRING_DATA ENGINE_str_functs[]=
72 {
73{ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"},
74{ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"},
75{ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"},
76{ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"},
77{ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"},
78{ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"},
79{ERR_FUNC(ENGINE_F_ENGINE_CTRL), "ENGINE_ctrl"},
80{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"},
81{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"},
82{ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"},
83{ERR_FUNC(ENGINE_F_ENGINE_FREE), "ENGINE_free"},
84{ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"},
85{ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"},
86{ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"},
87{ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"},
88{ERR_FUNC(ENGINE_F_ENGINE_GET_PREV), "ENGINE_get_prev"},
89{ERR_FUNC(ENGINE_F_ENGINE_INIT), "ENGINE_init"},
90{ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD), "ENGINE_LIST_ADD"},
91{ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"},
92{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"},
93{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"},
94{ERR_FUNC(ENGINE_F_ENGINE_MODULE_INIT), "ENGINE_MODULE_INIT"},
95{ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"},
96{ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"},
97{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"},
98{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_TYPE), "ENGINE_SET_DEFAULT_TYPE"},
99{ERR_FUNC(ENGINE_F_ENGINE_SET_ID), "ENGINE_set_id"},
100{ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"},
101{ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"},
102{ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"},
103{ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"},
104{ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"},
105{ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"},
106{ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"},
107{ERR_FUNC(ENGINE_F_SET_DATA_CTX), "SET_DATA_CTX"},
108{0,NULL}
109 };
110
111static ERR_STRING_DATA ENGINE_str_reasons[]=
112 {
113{ERR_REASON(ENGINE_R_ALREADY_LOADED) ,"already loaded"},
114{ERR_REASON(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER),"argument is not a number"},
115{ERR_REASON(ENGINE_R_CMD_NOT_EXECUTABLE) ,"cmd not executable"},
116{ERR_REASON(ENGINE_R_COMMAND_TAKES_INPUT),"command takes input"},
117{ERR_REASON(ENGINE_R_COMMAND_TAKES_NO_INPUT),"command takes no input"},
118{ERR_REASON(ENGINE_R_CONFLICTING_ENGINE_ID),"conflicting engine id"},
119{ERR_REASON(ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED),"ctrl command not implemented"},
120{ERR_REASON(ENGINE_R_DH_NOT_IMPLEMENTED) ,"dh not implemented"},
121{ERR_REASON(ENGINE_R_DSA_NOT_IMPLEMENTED),"dsa not implemented"},
122{ERR_REASON(ENGINE_R_DSO_FAILURE) ,"DSO failure"},
123{ERR_REASON(ENGINE_R_DSO_NOT_FOUND) ,"dso not found"},
124{ERR_REASON(ENGINE_R_ENGINES_SECTION_ERROR),"engines section error"},
125{ERR_REASON(ENGINE_R_ENGINE_IS_NOT_IN_LIST),"engine is not in the list"},
126{ERR_REASON(ENGINE_R_ENGINE_SECTION_ERROR),"engine section error"},
127{ERR_REASON(ENGINE_R_FAILED_LOADING_PRIVATE_KEY),"failed loading private key"},
128{ERR_REASON(ENGINE_R_FAILED_LOADING_PUBLIC_KEY),"failed loading public key"},
129{ERR_REASON(ENGINE_R_FINISH_FAILED) ,"finish failed"},
130{ERR_REASON(ENGINE_R_GET_HANDLE_FAILED) ,"could not obtain hardware handle"},
131{ERR_REASON(ENGINE_R_ID_OR_NAME_MISSING) ,"'id' or 'name' missing"},
132{ERR_REASON(ENGINE_R_INIT_FAILED) ,"init failed"},
133{ERR_REASON(ENGINE_R_INTERNAL_LIST_ERROR),"internal list error"},
134{ERR_REASON(ENGINE_R_INVALID_ARGUMENT) ,"invalid argument"},
135{ERR_REASON(ENGINE_R_INVALID_CMD_NAME) ,"invalid cmd name"},
136{ERR_REASON(ENGINE_R_INVALID_CMD_NUMBER) ,"invalid cmd number"},
137{ERR_REASON(ENGINE_R_INVALID_INIT_VALUE) ,"invalid init value"},
138{ERR_REASON(ENGINE_R_INVALID_STRING) ,"invalid string"},
139{ERR_REASON(ENGINE_R_NOT_INITIALISED) ,"not initialised"},
140{ERR_REASON(ENGINE_R_NOT_LOADED) ,"not loaded"},
141{ERR_REASON(ENGINE_R_NO_CONTROL_FUNCTION),"no control function"},
142{ERR_REASON(ENGINE_R_NO_INDEX) ,"no index"},
143{ERR_REASON(ENGINE_R_NO_LOAD_FUNCTION) ,"no load function"},
144{ERR_REASON(ENGINE_R_NO_REFERENCE) ,"no reference"},
145{ERR_REASON(ENGINE_R_NO_SUCH_ENGINE) ,"no such engine"},
146{ERR_REASON(ENGINE_R_NO_UNLOAD_FUNCTION) ,"no unload function"},
147{ERR_REASON(ENGINE_R_PROVIDE_PARAMETERS) ,"provide parameters"},
148{ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED),"rsa not implemented"},
149{ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER),"unimplemented cipher"},
150{ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST),"unimplemented digest"},
151{ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY),"version incompatibility"},
152{0,NULL}
153 };
154
155#endif
156
157void ERR_load_ENGINE_strings(void)
158 {
159 static int init=1;
160
161 if (init)
162 {
163 init=0;
164#ifndef OPENSSL_NO_ERR
165 ERR_load_strings(0,ENGINE_str_functs);
166 ERR_load_strings(0,ENGINE_str_reasons);
167#endif
168
169 }
170 }
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c
deleted file mode 100644
index 7ccf7022ee..0000000000
--- a/src/lib/libcrypto/engine/eng_fat.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/* crypto/engine/eng_fat.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60#include <openssl/conf.h>
61
62int ENGINE_set_default(ENGINE *e, unsigned int flags)
63 {
64 if((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e))
65 return 0;
66 if((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e))
67 return 0;
68#ifndef OPENSSL_NO_RSA
69 if((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e))
70 return 0;
71#endif
72#ifndef OPENSSL_NO_DSA
73 if((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e))
74 return 0;
75#endif
76#ifndef OPENSSL_NO_DH
77 if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e))
78 return 0;
79#endif
80 if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
81 return 0;
82 return 1;
83 }
84
85/* Set default algorithms using a string */
86
87static int int_def_cb(const char *alg, int len, void *arg)
88 {
89 unsigned int *pflags = arg;
90 if (!strncmp(alg, "ALL", len))
91 *pflags |= ENGINE_METHOD_ALL;
92 else if (!strncmp(alg, "RSA", len))
93 *pflags |= ENGINE_METHOD_RSA;
94 else if (!strncmp(alg, "DSA", len))
95 *pflags |= ENGINE_METHOD_DSA;
96 else if (!strncmp(alg, "DH", len))
97 *pflags |= ENGINE_METHOD_DH;
98 else if (!strncmp(alg, "RAND", len))
99 *pflags |= ENGINE_METHOD_RAND;
100 else if (!strncmp(alg, "CIPHERS", len))
101 *pflags |= ENGINE_METHOD_CIPHERS;
102 else if (!strncmp(alg, "DIGESTS", len))
103 *pflags |= ENGINE_METHOD_DIGESTS;
104 else
105 return 0;
106 return 1;
107 }
108
109
110int ENGINE_set_default_string(ENGINE *e, const char *def_list)
111 {
112 unsigned int flags = 0;
113 if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags))
114 {
115 ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING,
116 ENGINE_R_INVALID_STRING);
117 ERR_add_error_data(2, "str=",def_list);
118 return 0;
119 }
120 return ENGINE_set_default(e, flags);
121 }
122
123int ENGINE_register_complete(ENGINE *e)
124 {
125 ENGINE_register_ciphers(e);
126 ENGINE_register_digests(e);
127#ifndef OPENSSL_NO_RSA
128 ENGINE_register_RSA(e);
129#endif
130#ifndef OPENSSL_NO_DSA
131 ENGINE_register_DSA(e);
132#endif
133#ifndef OPENSSL_NO_DH
134 ENGINE_register_DH(e);
135#endif
136 ENGINE_register_RAND(e);
137 return 1;
138 }
139
140int ENGINE_register_all_complete(void)
141 {
142 ENGINE *e;
143
144 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
145 ENGINE_register_complete(e);
146 return 1;
147 }
diff --git a/src/lib/libcrypto/engine/eng_init.c b/src/lib/libcrypto/engine/eng_init.c
deleted file mode 100644
index 170c1791b3..0000000000
--- a/src/lib/libcrypto/engine/eng_init.c
+++ /dev/null
@@ -1,157 +0,0 @@
1/* crypto/engine/eng_init.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* Initialise a engine type for use (or up its functional reference count
62 * if it's already in use). This version is only used internally. */
63int engine_unlocked_init(ENGINE *e)
64 {
65 int to_return = 1;
66
67 if((e->funct_ref == 0) && e->init)
68 /* This is the first functional reference and the engine
69 * requires initialisation so we do it now. */
70 to_return = e->init(e);
71 if(to_return)
72 {
73 /* OK, we return a functional reference which is also a
74 * structural reference. */
75 e->struct_ref++;
76 e->funct_ref++;
77 engine_ref_debug(e, 0, 1)
78 engine_ref_debug(e, 1, 1)
79 }
80 return to_return;
81 }
82
83/* Free a functional reference to a engine type. This version is only used
84 * internally. */
85int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
86 {
87 int to_return = 1;
88
89 /* Reduce the functional reference count here so if it's the terminating
90 * case, we can release the lock safely and call the finish() handler
91 * without risk of a race. We get a race if we leave the count until
92 * after and something else is calling "finish" at the same time -
93 * there's a chance that both threads will together take the count from
94 * 2 to 0 without either calling finish(). */
95 e->funct_ref--;
96 engine_ref_debug(e, 1, -1);
97 if((e->funct_ref == 0) && e->finish)
98 {
99 if(unlock_for_handlers)
100 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
101 to_return = e->finish(e);
102 if(unlock_for_handlers)
103 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
104 if(!to_return)
105 return 0;
106 }
107#ifdef REF_CHECK
108 if(e->funct_ref < 0)
109 {
110 fprintf(stderr,"ENGINE_finish, bad functional reference count\n");
111 abort();
112 }
113#endif
114 /* Release the structural reference too */
115 if(!engine_free_util(e, 0))
116 {
117 ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED);
118 return 0;
119 }
120 return to_return;
121 }
122
123/* The API (locked) version of "init" */
124int ENGINE_init(ENGINE *e)
125 {
126 int ret;
127 if(e == NULL)
128 {
129 ENGINEerr(ENGINE_F_ENGINE_INIT,ERR_R_PASSED_NULL_PARAMETER);
130 return 0;
131 }
132 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
133 ret = engine_unlocked_init(e);
134 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
135 return ret;
136 }
137
138/* The API (locked) version of "finish" */
139int ENGINE_finish(ENGINE *e)
140 {
141 int to_return = 1;
142
143 if(e == NULL)
144 {
145 ENGINEerr(ENGINE_F_ENGINE_FINISH,ERR_R_PASSED_NULL_PARAMETER);
146 return 0;
147 }
148 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
149 to_return = engine_unlocked_finish(e, 1);
150 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
151 if(!to_return)
152 {
153 ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED);
154 return 0;
155 }
156 return to_return;
157 }
diff --git a/src/lib/libcrypto/engine/eng_int.h b/src/lib/libcrypto/engine/eng_int.h
deleted file mode 100644
index 38335f99cd..0000000000
--- a/src/lib/libcrypto/engine/eng_int.h
+++ /dev/null
@@ -1,185 +0,0 @@
1/* crypto/engine/eng_int.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_ENGINE_INT_H
60#define HEADER_ENGINE_INT_H
61
62/* Take public definitions from engine.h */
63#include <openssl/engine.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* If we compile with this symbol defined, then both reference counts in the
70 * ENGINE structure will be monitored with a line of output on stderr for each
71 * change. This prints the engine's pointer address (truncated to unsigned int),
72 * "struct" or "funct" to indicate the reference type, the before and after
73 * reference count, and the file:line-number pair. The "engine_ref_debug"
74 * statements must come *after* the change. */
75#ifdef ENGINE_REF_COUNT_DEBUG
76
77#define engine_ref_debug(e, isfunct, diff) \
78 fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \
79 (unsigned int)(e), (isfunct ? "funct" : "struct"), \
80 ((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \
81 ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \
82 (__FILE__), (__LINE__));
83
84#else
85
86#define engine_ref_debug(e, isfunct, diff)
87
88#endif
89
90/* Any code that will need cleanup operations should use these functions to
91 * register callbacks. ENGINE_cleanup() will call all registered callbacks in
92 * order. NB: both the "add" functions assume CRYPTO_LOCK_ENGINE to already be
93 * held (in "write" mode). */
94typedef void (ENGINE_CLEANUP_CB)(void);
95typedef struct st_engine_cleanup_item
96 {
97 ENGINE_CLEANUP_CB *cb;
98 } ENGINE_CLEANUP_ITEM;
99DECLARE_STACK_OF(ENGINE_CLEANUP_ITEM)
100void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb);
101void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);
102
103/* We need stacks of ENGINEs for use in eng_table.c */
104DECLARE_STACK_OF(ENGINE)
105
106/* If this symbol is defined then engine_table_select(), the function that is
107 * used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults and
108 * functional references (etc), will display debugging summaries to stderr. */
109/* #define ENGINE_TABLE_DEBUG */
110
111/* This represents an implementation table. Dependent code should instantiate it
112 * as a (ENGINE_TABLE *) pointer value set initially to NULL. */
113typedef struct st_engine_table ENGINE_TABLE;
114int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
115 ENGINE *e, const int *nids, int num_nids, int setdefault);
116void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e);
117void engine_table_cleanup(ENGINE_TABLE **table);
118#ifndef ENGINE_TABLE_DEBUG
119ENGINE *engine_table_select(ENGINE_TABLE **table, int nid);
120#else
121ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l);
122#define engine_table_select(t,n) engine_table_select_tmp(t,n,__FILE__,__LINE__)
123#endif
124
125/* Internal versions of API functions that have control over locking. These are
126 * used between C files when functionality needs to be shared but the caller may
127 * already be controlling of the CRYPTO_LOCK_ENGINE lock. */
128int engine_unlocked_init(ENGINE *e);
129int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers);
130int engine_free_util(ENGINE *e, int locked);
131
132/* This function will reset all "set"able values in an ENGINE to NULL. This
133 * won't touch reference counts or ex_data, but is equivalent to calling all the
134 * ENGINE_set_***() functions with a NULL value. */
135void engine_set_all_null(ENGINE *e);
136
137/* NB: Bitwise OR-able values for the "flags" variable in ENGINE are now exposed
138 * in engine.h. */
139
140/* This is a structure for storing implementations of various crypto
141 * algorithms and functions. */
142struct engine_st
143 {
144 const char *id;
145 const char *name;
146 const RSA_METHOD *rsa_meth;
147 const DSA_METHOD *dsa_meth;
148 const DH_METHOD *dh_meth;
149 const RAND_METHOD *rand_meth;
150 /* Cipher handling is via this callback */
151 ENGINE_CIPHERS_PTR ciphers;
152 /* Digest handling is via this callback */
153 ENGINE_DIGESTS_PTR digests;
154
155
156 ENGINE_GEN_INT_FUNC_PTR destroy;
157
158 ENGINE_GEN_INT_FUNC_PTR init;
159 ENGINE_GEN_INT_FUNC_PTR finish;
160 ENGINE_CTRL_FUNC_PTR ctrl;
161 ENGINE_LOAD_KEY_PTR load_privkey;
162 ENGINE_LOAD_KEY_PTR load_pubkey;
163
164 const ENGINE_CMD_DEFN *cmd_defns;
165 int flags;
166 /* reference count on the structure itself */
167 int struct_ref;
168 /* reference count on usability of the engine type. NB: This
169 * controls the loading and initialisation of any functionlity
170 * required by this engine, whereas the previous count is
171 * simply to cope with (de)allocation of this structure. Hence,
172 * running_ref <= struct_ref at all times. */
173 int funct_ref;
174 /* A place to store per-ENGINE data */
175 CRYPTO_EX_DATA ex_data;
176 /* Used to maintain the linked-list of engines. */
177 struct engine_st *prev;
178 struct engine_st *next;
179 };
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif /* HEADER_ENGINE_INT_H */
diff --git a/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c
deleted file mode 100644
index a66d0f08af..0000000000
--- a/src/lib/libcrypto/engine/eng_lib.c
+++ /dev/null
@@ -1,321 +0,0 @@
1/* crypto/engine/eng_lib.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
61#include "eng_int.h"
62#include <openssl/rand.h> /* FIXME: This shouldn't be needed */
63#include <openssl/engine.h>
64
65/* The "new"/"free" stuff first */
66
67ENGINE *ENGINE_new(void)
68 {
69 ENGINE *ret;
70
71 ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE));
72 if(ret == NULL)
73 {
74 ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
75 return NULL;
76 }
77 memset(ret, 0, sizeof(ENGINE));
78 ret->struct_ref = 1;
79 engine_ref_debug(ret, 0, 1)
80 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data);
81 return ret;
82 }
83
84/* Placed here (close proximity to ENGINE_new) so that modifications to the
85 * elements of the ENGINE structure are more likely to be caught and changed
86 * here. */
87void engine_set_all_null(ENGINE *e)
88 {
89 e->id = NULL;
90 e->name = NULL;
91 e->rsa_meth = NULL;
92 e->dsa_meth = NULL;
93 e->dh_meth = NULL;
94 e->rand_meth = NULL;
95 e->ciphers = NULL;
96 e->digests = NULL;
97 e->destroy = NULL;
98 e->init = NULL;
99 e->finish = NULL;
100 e->ctrl = NULL;
101 e->load_privkey = NULL;
102 e->load_pubkey = NULL;
103 e->cmd_defns = NULL;
104 e->flags = 0;
105 }
106
107int engine_free_util(ENGINE *e, int locked)
108 {
109 int i;
110
111 if(e == NULL)
112 {
113 ENGINEerr(ENGINE_F_ENGINE_FREE,
114 ERR_R_PASSED_NULL_PARAMETER);
115 return 0;
116 }
117 if(locked)
118 i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE);
119 else
120 i = --e->struct_ref;
121 engine_ref_debug(e, 0, -1)
122 if (i > 0) return 1;
123#ifdef REF_CHECK
124 if (i < 0)
125 {
126 fprintf(stderr,"ENGINE_free, bad structural reference count\n");
127 abort();
128 }
129#endif
130 /* Give the ENGINE a chance to do any structural cleanup corresponding
131 * to allocation it did in its constructor (eg. unload error strings) */
132 if(e->destroy)
133 e->destroy(e);
134 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
135 OPENSSL_free(e);
136 return 1;
137 }
138
139int ENGINE_free(ENGINE *e)
140 {
141 return engine_free_util(e, 1);
142 }
143
144/* Cleanup stuff */
145
146/* ENGINE_cleanup() is coded such that anything that does work that will need
147 * cleanup can register a "cleanup" callback here. That way we don't get linker
148 * bloat by referring to all *possible* cleanups, but any linker bloat into code
149 * "X" will cause X's cleanup function to end up here. */
150static STACK_OF(ENGINE_CLEANUP_ITEM) *cleanup_stack = NULL;
151static int int_cleanup_check(int create)
152 {
153 if(cleanup_stack) return 1;
154 if(!create) return 0;
155 cleanup_stack = sk_ENGINE_CLEANUP_ITEM_new_null();
156 return (cleanup_stack ? 1 : 0);
157 }
158static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb)
159 {
160 ENGINE_CLEANUP_ITEM *item = OPENSSL_malloc(sizeof(
161 ENGINE_CLEANUP_ITEM));
162 if(!item) return NULL;
163 item->cb = cb;
164 return item;
165 }
166void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb)
167 {
168 ENGINE_CLEANUP_ITEM *item;
169 if(!int_cleanup_check(1)) return;
170 item = int_cleanup_item(cb);
171 if(item)
172 sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0);
173 }
174void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)
175 {
176 ENGINE_CLEANUP_ITEM *item;
177 if(!int_cleanup_check(1)) return;
178 item = int_cleanup_item(cb);
179 if(item)
180 sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item);
181 }
182/* The API function that performs all cleanup */
183static void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item)
184 {
185 (*(item->cb))();
186 OPENSSL_free(item);
187 }
188void ENGINE_cleanup(void)
189 {
190 if(int_cleanup_check(0))
191 {
192 sk_ENGINE_CLEANUP_ITEM_pop_free(cleanup_stack,
193 engine_cleanup_cb_free);
194 cleanup_stack = NULL;
195 }
196 /* FIXME: This should be handled (somehow) through RAND, eg. by it
197 * registering a cleanup callback. */
198 RAND_set_rand_method(NULL);
199 }
200
201/* Now the "ex_data" support */
202
203int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
204 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
205 {
206 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, argl, argp,
207 new_func, dup_func, free_func);
208 }
209
210int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg)
211 {
212 return(CRYPTO_set_ex_data(&e->ex_data, idx, arg));
213 }
214
215void *ENGINE_get_ex_data(const ENGINE *e, int idx)
216 {
217 return(CRYPTO_get_ex_data(&e->ex_data, idx));
218 }
219
220/* Functions to get/set an ENGINE's elements - mainly to avoid exposing the
221 * ENGINE structure itself. */
222
223int ENGINE_set_id(ENGINE *e, const char *id)
224 {
225 if(id == NULL)
226 {
227 ENGINEerr(ENGINE_F_ENGINE_SET_ID,
228 ERR_R_PASSED_NULL_PARAMETER);
229 return 0;
230 }
231 e->id = id;
232 return 1;
233 }
234
235int ENGINE_set_name(ENGINE *e, const char *name)
236 {
237 if(name == NULL)
238 {
239 ENGINEerr(ENGINE_F_ENGINE_SET_NAME,
240 ERR_R_PASSED_NULL_PARAMETER);
241 return 0;
242 }
243 e->name = name;
244 return 1;
245 }
246
247int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f)
248 {
249 e->destroy = destroy_f;
250 return 1;
251 }
252
253int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f)
254 {
255 e->init = init_f;
256 return 1;
257 }
258
259int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f)
260 {
261 e->finish = finish_f;
262 return 1;
263 }
264
265int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f)
266 {
267 e->ctrl = ctrl_f;
268 return 1;
269 }
270
271int ENGINE_set_flags(ENGINE *e, int flags)
272 {
273 e->flags = flags;
274 return 1;
275 }
276
277int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns)
278 {
279 e->cmd_defns = defns;
280 return 1;
281 }
282
283const char *ENGINE_get_id(const ENGINE *e)
284 {
285 return e->id;
286 }
287
288const char *ENGINE_get_name(const ENGINE *e)
289 {
290 return e->name;
291 }
292
293ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e)
294 {
295 return e->destroy;
296 }
297
298ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e)
299 {
300 return e->init;
301 }
302
303ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e)
304 {
305 return e->finish;
306 }
307
308ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e)
309 {
310 return e->ctrl;
311 }
312
313int ENGINE_get_flags(const ENGINE *e)
314 {
315 return e->flags;
316 }
317
318const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e)
319 {
320 return e->cmd_defns;
321 }
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c
deleted file mode 100644
index 1cc3217f4c..0000000000
--- a/src/lib/libcrypto/engine/eng_list.c
+++ /dev/null
@@ -1,394 +0,0 @@
1/* crypto/engine/eng_list.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
61#include "eng_int.h"
62#include <openssl/engine.h>
63
64/* The linked-list of pointers to engine types. engine_list_head
65 * incorporates an implicit structural reference but engine_list_tail
66 * does not - the latter is a computational niceity and only points
67 * to something that is already pointed to by its predecessor in the
68 * list (or engine_list_head itself). In the same way, the use of the
69 * "prev" pointer in each ENGINE is to save excessive list iteration,
70 * it doesn't correspond to an extra structural reference. Hence,
71 * engine_list_head, and each non-null "next" pointer account for
72 * the list itself assuming exactly 1 structural reference on each
73 * list member. */
74static ENGINE *engine_list_head = NULL;
75static ENGINE *engine_list_tail = NULL;
76
77/* This cleanup function is only needed internally. If it should be called, we
78 * register it with the "ENGINE_cleanup()" stack to be called during cleanup. */
79
80static void engine_list_cleanup(void)
81 {
82 ENGINE *iterator = engine_list_head;
83
84 while(iterator != NULL)
85 {
86 ENGINE_remove(iterator);
87 iterator = engine_list_head;
88 }
89 return;
90 }
91
92/* These static functions starting with a lower case "engine_" always
93 * take place when CRYPTO_LOCK_ENGINE has been locked up. */
94static int engine_list_add(ENGINE *e)
95 {
96 int conflict = 0;
97 ENGINE *iterator = NULL;
98
99 if(e == NULL)
100 {
101 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
102 ERR_R_PASSED_NULL_PARAMETER);
103 return 0;
104 }
105 iterator = engine_list_head;
106 while(iterator && !conflict)
107 {
108 conflict = (strcmp(iterator->id, e->id) == 0);
109 iterator = iterator->next;
110 }
111 if(conflict)
112 {
113 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
114 ENGINE_R_CONFLICTING_ENGINE_ID);
115 return 0;
116 }
117 if(engine_list_head == NULL)
118 {
119 /* We are adding to an empty list. */
120 if(engine_list_tail)
121 {
122 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
123 ENGINE_R_INTERNAL_LIST_ERROR);
124 return 0;
125 }
126 engine_list_head = e;
127 e->prev = NULL;
128 /* The first time the list allocates, we should register the
129 * cleanup. */
130 engine_cleanup_add_last(engine_list_cleanup);
131 }
132 else
133 {
134 /* We are adding to the tail of an existing list. */
135 if((engine_list_tail == NULL) ||
136 (engine_list_tail->next != NULL))
137 {
138 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
139 ENGINE_R_INTERNAL_LIST_ERROR);
140 return 0;
141 }
142 engine_list_tail->next = e;
143 e->prev = engine_list_tail;
144 }
145 /* Having the engine in the list assumes a structural
146 * reference. */
147 e->struct_ref++;
148 engine_ref_debug(e, 0, 1)
149 /* However it came to be, e is the last item in the list. */
150 engine_list_tail = e;
151 e->next = NULL;
152 return 1;
153 }
154
155static int engine_list_remove(ENGINE *e)
156 {
157 ENGINE *iterator;
158
159 if(e == NULL)
160 {
161 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE,
162 ERR_R_PASSED_NULL_PARAMETER);
163 return 0;
164 }
165 /* We need to check that e is in our linked list! */
166 iterator = engine_list_head;
167 while(iterator && (iterator != e))
168 iterator = iterator->next;
169 if(iterator == NULL)
170 {
171 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE,
172 ENGINE_R_ENGINE_IS_NOT_IN_LIST);
173 return 0;
174 }
175 /* un-link e from the chain. */
176 if(e->next)
177 e->next->prev = e->prev;
178 if(e->prev)
179 e->prev->next = e->next;
180 /* Correct our head/tail if necessary. */
181 if(engine_list_head == e)
182 engine_list_head = e->next;
183 if(engine_list_tail == e)
184 engine_list_tail = e->prev;
185 engine_free_util(e, 0);
186 return 1;
187 }
188
189/* Get the first/last "ENGINE" type available. */
190ENGINE *ENGINE_get_first(void)
191 {
192 ENGINE *ret;
193
194 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
195 ret = engine_list_head;
196 if(ret)
197 {
198 ret->struct_ref++;
199 engine_ref_debug(ret, 0, 1)
200 }
201 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
202 return ret;
203 }
204
205ENGINE *ENGINE_get_last(void)
206 {
207 ENGINE *ret;
208
209 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
210 ret = engine_list_tail;
211 if(ret)
212 {
213 ret->struct_ref++;
214 engine_ref_debug(ret, 0, 1)
215 }
216 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
217 return ret;
218 }
219
220/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
221ENGINE *ENGINE_get_next(ENGINE *e)
222 {
223 ENGINE *ret = NULL;
224 if(e == NULL)
225 {
226 ENGINEerr(ENGINE_F_ENGINE_GET_NEXT,
227 ERR_R_PASSED_NULL_PARAMETER);
228 return 0;
229 }
230 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
231 ret = e->next;
232 if(ret)
233 {
234 /* Return a valid structural refernce to the next ENGINE */
235 ret->struct_ref++;
236 engine_ref_debug(ret, 0, 1)
237 }
238 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
239 /* Release the structural reference to the previous ENGINE */
240 ENGINE_free(e);
241 return ret;
242 }
243
244ENGINE *ENGINE_get_prev(ENGINE *e)
245 {
246 ENGINE *ret = NULL;
247 if(e == NULL)
248 {
249 ENGINEerr(ENGINE_F_ENGINE_GET_PREV,
250 ERR_R_PASSED_NULL_PARAMETER);
251 return 0;
252 }
253 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
254 ret = e->prev;
255 if(ret)
256 {
257 /* Return a valid structural reference to the next ENGINE */
258 ret->struct_ref++;
259 engine_ref_debug(ret, 0, 1)
260 }
261 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
262 /* Release the structural reference to the previous ENGINE */
263 ENGINE_free(e);
264 return ret;
265 }
266
267/* Add another "ENGINE" type into the list. */
268int ENGINE_add(ENGINE *e)
269 {
270 int to_return = 1;
271 if(e == NULL)
272 {
273 ENGINEerr(ENGINE_F_ENGINE_ADD,
274 ERR_R_PASSED_NULL_PARAMETER);
275 return 0;
276 }
277 if((e->id == NULL) || (e->name == NULL))
278 {
279 ENGINEerr(ENGINE_F_ENGINE_ADD,
280 ENGINE_R_ID_OR_NAME_MISSING);
281 }
282 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
283 if(!engine_list_add(e))
284 {
285 ENGINEerr(ENGINE_F_ENGINE_ADD,
286 ENGINE_R_INTERNAL_LIST_ERROR);
287 to_return = 0;
288 }
289 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
290 return to_return;
291 }
292
293/* Remove an existing "ENGINE" type from the array. */
294int ENGINE_remove(ENGINE *e)
295 {
296 int to_return = 1;
297 if(e == NULL)
298 {
299 ENGINEerr(ENGINE_F_ENGINE_REMOVE,
300 ERR_R_PASSED_NULL_PARAMETER);
301 return 0;
302 }
303 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
304 if(!engine_list_remove(e))
305 {
306 ENGINEerr(ENGINE_F_ENGINE_REMOVE,
307 ENGINE_R_INTERNAL_LIST_ERROR);
308 to_return = 0;
309 }
310 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
311 return to_return;
312 }
313
314static void engine_cpy(ENGINE *dest, const ENGINE *src)
315 {
316 dest->id = src->id;
317 dest->name = src->name;
318#ifndef OPENSSL_NO_RSA
319 dest->rsa_meth = src->rsa_meth;
320#endif
321#ifndef OPENSSL_NO_DSA
322 dest->dsa_meth = src->dsa_meth;
323#endif
324#ifndef OPENSSL_NO_DH
325 dest->dh_meth = src->dh_meth;
326#endif
327 dest->rand_meth = src->rand_meth;
328 dest->ciphers = src->ciphers;
329 dest->digests = src->digests;
330 dest->destroy = src->destroy;
331 dest->init = src->init;
332 dest->finish = src->finish;
333 dest->ctrl = src->ctrl;
334 dest->load_privkey = src->load_privkey;
335 dest->load_pubkey = src->load_pubkey;
336 dest->cmd_defns = src->cmd_defns;
337 dest->flags = src->flags;
338 }
339
340ENGINE *ENGINE_by_id(const char *id)
341 {
342 ENGINE *iterator;
343 if(id == NULL)
344 {
345 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
346 ERR_R_PASSED_NULL_PARAMETER);
347 return NULL;
348 }
349 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
350 iterator = engine_list_head;
351 while(iterator && (strcmp(id, iterator->id) != 0))
352 iterator = iterator->next;
353 if(iterator)
354 {
355 /* We need to return a structural reference. If this is an
356 * ENGINE type that returns copies, make a duplicate - otherwise
357 * increment the existing ENGINE's reference count. */
358 if(iterator->flags & ENGINE_FLAGS_BY_ID_COPY)
359 {
360 ENGINE *cp = ENGINE_new();
361 if(!cp)
362 iterator = NULL;
363 else
364 {
365 engine_cpy(cp, iterator);
366 iterator = cp;
367 }
368 }
369 else
370 {
371 iterator->struct_ref++;
372 engine_ref_debug(iterator, 0, 1)
373 }
374 }
375 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
376 if(iterator == NULL)
377 {
378 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
379 ENGINE_R_NO_SUCH_ENGINE);
380 ERR_add_error_data(2, "id=", id);
381 }
382 return iterator;
383 }
384
385int ENGINE_up_ref(ENGINE *e)
386 {
387 if (e == NULL)
388 {
389 ENGINEerr(ENGINE_F_ENGINE_UP_REF,ERR_R_PASSED_NULL_PARAMETER);
390 return 0;
391 }
392 CRYPTO_add(&e->struct_ref,1,CRYPTO_LOCK_ENGINE);
393 return 1;
394 }
diff --git a/src/lib/libcrypto/engine/eng_openssl.c b/src/lib/libcrypto/engine/eng_openssl.c
deleted file mode 100644
index 54579eea2e..0000000000
--- a/src/lib/libcrypto/engine/eng_openssl.c
+++ /dev/null
@@ -1,361 +0,0 @@
1/* crypto/engine/eng_openssl.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/engine.h>
64#include <openssl/dso.h>
65#include <openssl/pem.h>
66#include <openssl/evp.h>
67
68/* This testing gunk is implemented (and explained) lower down. It also assumes
69 * the application explicitly calls "ENGINE_load_openssl()" because this is no
70 * longer automatic in ENGINE_load_builtin_engines(). */
71#define TEST_ENG_OPENSSL_RC4
72#define TEST_ENG_OPENSSL_PKEY
73/* #define TEST_ENG_OPENSSL_RC4_OTHERS */
74#define TEST_ENG_OPENSSL_RC4_P_INIT
75/* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */
76#define TEST_ENG_OPENSSL_SHA
77/* #define TEST_ENG_OPENSSL_SHA_OTHERS */
78/* #define TEST_ENG_OPENSSL_SHA_P_INIT */
79/* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */
80/* #define TEST_ENG_OPENSSL_SHA_P_FINAL */
81
82/* Now check what of those algorithms are actually enabled */
83#ifdef OPENSSL_NO_RC4
84#undef TEST_ENG_OPENSSL_RC4
85#undef TEST_ENG_OPENSSL_RC4_OTHERS
86#undef TEST_ENG_OPENSSL_RC4_P_INIT
87#undef TEST_ENG_OPENSSL_RC4_P_CIPHER
88#endif
89#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0) || defined(OPENSSL_NO_SHA1)
90#undef TEST_ENG_OPENSSL_SHA
91#undef TEST_ENG_OPENSSL_SHA_OTHERS
92#undef TEST_ENG_OPENSSL_SHA_P_INIT
93#undef TEST_ENG_OPENSSL_SHA_P_UPDATE
94#undef TEST_ENG_OPENSSL_SHA_P_FINAL
95#endif
96
97#ifdef TEST_ENG_OPENSSL_RC4
98static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
99 const int **nids, int nid);
100#endif
101#ifdef TEST_ENG_OPENSSL_SHA
102static int openssl_digests(ENGINE *e, const EVP_MD **digest,
103 const int **nids, int nid);
104#endif
105
106#ifdef TEST_ENG_OPENSSL_PKEY
107static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
108 UI_METHOD *ui_method, void *callback_data);
109#endif
110
111/* The constants used when creating the ENGINE */
112static const char *engine_openssl_id = "openssl";
113static const char *engine_openssl_name = "Software engine support";
114
115/* This internal function is used by ENGINE_openssl() and possibly by the
116 * "dynamic" ENGINE support too */
117static int bind_helper(ENGINE *e)
118 {
119 if(!ENGINE_set_id(e, engine_openssl_id)
120 || !ENGINE_set_name(e, engine_openssl_name)
121#ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS
122#ifndef OPENSSL_NO_RSA
123 || !ENGINE_set_RSA(e, RSA_get_default_method())
124#endif
125#ifndef OPENSSL_NO_DSA
126 || !ENGINE_set_DSA(e, DSA_get_default_method())
127#endif
128#ifndef OPENSSL_NO_DH
129 || !ENGINE_set_DH(e, DH_get_default_method())
130#endif
131 || !ENGINE_set_RAND(e, RAND_SSLeay())
132#ifdef TEST_ENG_OPENSSL_RC4
133 || !ENGINE_set_ciphers(e, openssl_ciphers)
134#endif
135#ifdef TEST_ENG_OPENSSL_SHA
136 || !ENGINE_set_digests(e, openssl_digests)
137#endif
138#endif
139#ifdef TEST_ENG_OPENSSL_PKEY
140 || !ENGINE_set_load_privkey_function(e, openssl_load_privkey)
141#endif
142 )
143 return 0;
144 /* If we add errors to this ENGINE, ensure the error handling is setup here */
145 /* openssl_load_error_strings(); */
146 return 1;
147 }
148
149static ENGINE *engine_openssl(void)
150 {
151 ENGINE *ret = ENGINE_new();
152 if(!ret)
153 return NULL;
154 if(!bind_helper(ret))
155 {
156 ENGINE_free(ret);
157 return NULL;
158 }
159 return ret;
160 }
161
162void ENGINE_load_openssl(void)
163 {
164 ENGINE *toadd = engine_openssl();
165 if(!toadd) return;
166 ENGINE_add(toadd);
167 /* If the "add" worked, it gets a structural reference. So either way,
168 * we release our just-created reference. */
169 ENGINE_free(toadd);
170 ERR_clear_error();
171 }
172
173/* This stuff is needed if this ENGINE is being compiled into a self-contained
174 * shared-library. */
175#ifdef ENGINE_DYNAMIC_SUPPORT
176static int bind_fn(ENGINE *e, const char *id)
177 {
178 if(id && (strcmp(id, engine_openssl_id) != 0))
179 return 0;
180 if(!bind_helper(e))
181 return 0;
182 return 1;
183 }
184IMPLEMENT_DYNAMIC_CHECK_FN()
185IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
186#endif /* ENGINE_DYNAMIC_SUPPORT */
187
188#ifdef TEST_ENG_OPENSSL_RC4
189/* This section of code compiles an "alternative implementation" of two modes of
190 * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4"
191 * should under normal circumstances go via this support rather than the default
192 * EVP support. There are other symbols to tweak the testing;
193 * TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time
194 * we're asked for a cipher we don't support (should not happen).
195 * TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time
196 * the "init_key" handler is called.
197 * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler.
198 */
199#include <openssl/rc4.h>
200#define TEST_RC4_KEY_SIZE 16
201static int test_cipher_nids[] = {NID_rc4,NID_rc4_40};
202static int test_cipher_nids_number = 2;
203typedef struct {
204 unsigned char key[TEST_RC4_KEY_SIZE];
205 RC4_KEY ks;
206 } TEST_RC4_KEY;
207#define test(ctx) ((TEST_RC4_KEY *)(ctx)->cipher_data)
208static int test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
209 const unsigned char *iv, int enc)
210 {
211#ifdef TEST_ENG_OPENSSL_RC4_P_INIT
212 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n");
213#endif
214 memcpy(&test(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx));
215 RC4_set_key(&test(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
216 test(ctx)->key);
217 return 1;
218 }
219static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
220 const unsigned char *in, unsigned int inl)
221 {
222#ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER
223 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n");
224#endif
225 RC4(&test(ctx)->ks,inl,in,out);
226 return 1;
227 }
228static const EVP_CIPHER test_r4_cipher=
229 {
230 NID_rc4,
231 1,TEST_RC4_KEY_SIZE,0,
232 EVP_CIPH_VARIABLE_LENGTH,
233 test_rc4_init_key,
234 test_rc4_cipher,
235 NULL,
236 sizeof(TEST_RC4_KEY),
237 NULL,
238 NULL,
239 NULL
240 };
241static const EVP_CIPHER test_r4_40_cipher=
242 {
243 NID_rc4_40,
244 1,5 /* 40 bit */,0,
245 EVP_CIPH_VARIABLE_LENGTH,
246 test_rc4_init_key,
247 test_rc4_cipher,
248 NULL,
249 sizeof(TEST_RC4_KEY),
250 NULL,
251 NULL,
252 NULL
253 };
254static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
255 const int **nids, int nid)
256 {
257 if(!cipher)
258 {
259 /* We are returning a list of supported nids */
260 *nids = test_cipher_nids;
261 return test_cipher_nids_number;
262 }
263 /* We are being asked for a specific cipher */
264 if(nid == NID_rc4)
265 *cipher = &test_r4_cipher;
266 else if(nid == NID_rc4_40)
267 *cipher = &test_r4_40_cipher;
268 else
269 {
270#ifdef TEST_ENG_OPENSSL_RC4_OTHERS
271 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for "
272 "nid %d\n", nid);
273#endif
274 *cipher = NULL;
275 return 0;
276 }
277 return 1;
278 }
279#endif
280
281#ifdef TEST_ENG_OPENSSL_SHA
282/* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */
283#include <openssl/sha.h>
284static int test_digest_nids[] = {NID_sha1};
285static int test_digest_nids_number = 1;
286static int test_sha1_init(EVP_MD_CTX *ctx)
287 {
288#ifdef TEST_ENG_OPENSSL_SHA_P_INIT
289 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n");
290#endif
291 return SHA1_Init(ctx->md_data);
292 }
293static int test_sha1_update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
294 {
295#ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
296 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
297#endif
298 return SHA1_Update(ctx->md_data,data,count);
299 }
300static int test_sha1_final(EVP_MD_CTX *ctx,unsigned char *md)
301 {
302#ifdef TEST_ENG_OPENSSL_SHA_P_FINAL
303 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n");
304#endif
305 return SHA1_Final(md,ctx->md_data);
306 }
307static const EVP_MD test_sha_md=
308 {
309 NID_sha1,
310 NID_sha1WithRSAEncryption,
311 SHA_DIGEST_LENGTH,
312 0,
313 test_sha1_init,
314 test_sha1_update,
315 test_sha1_final,
316 NULL,
317 NULL,
318 EVP_PKEY_RSA_method,
319 SHA_CBLOCK,
320 sizeof(EVP_MD *)+sizeof(SHA_CTX),
321 };
322static int openssl_digests(ENGINE *e, const EVP_MD **digest,
323 const int **nids, int nid)
324 {
325 if(!digest)
326 {
327 /* We are returning a list of supported nids */
328 *nids = test_digest_nids;
329 return test_digest_nids_number;
330 }
331 /* We are being asked for a specific digest */
332 if(nid == NID_sha1)
333 *digest = &test_sha_md;
334 else
335 {
336#ifdef TEST_ENG_OPENSSL_SHA_OTHERS
337 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for "
338 "nid %d\n", nid);
339#endif
340 *digest = NULL;
341 return 0;
342 }
343 return 1;
344 }
345#endif
346
347#ifdef TEST_ENG_OPENSSL_PKEY
348static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
349 UI_METHOD *ui_method, void *callback_data)
350 {
351 BIO *in;
352 EVP_PKEY *key;
353 fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", key_id);
354 in = BIO_new_file(key_id, "r");
355 if (!in)
356 return NULL;
357 key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL);
358 BIO_free(in);
359 return key;
360 }
361#endif
diff --git a/src/lib/libcrypto/engine/eng_pkey.c b/src/lib/libcrypto/engine/eng_pkey.c
deleted file mode 100644
index 8c69171511..0000000000
--- a/src/lib/libcrypto/engine/eng_pkey.c
+++ /dev/null
@@ -1,157 +0,0 @@
1/* crypto/engine/eng_pkey.c */
2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
58#include "eng_int.h"
59#include <openssl/engine.h>
60
61/* Basic get/set stuff */
62
63int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f)
64 {
65 e->load_privkey = loadpriv_f;
66 return 1;
67 }
68
69int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
70 {
71 e->load_pubkey = loadpub_f;
72 return 1;
73 }
74
75ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
76 {
77 return e->load_privkey;
78 }
79
80ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
81 {
82 return e->load_pubkey;
83 }
84
85/* API functions to load public/private keys */
86
87EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
88 UI_METHOD *ui_method, void *callback_data)
89 {
90 EVP_PKEY *pkey;
91
92 if(e == NULL)
93 {
94 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
95 ERR_R_PASSED_NULL_PARAMETER);
96 return 0;
97 }
98 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
99 if(e->funct_ref == 0)
100 {
101 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
102 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
103 ENGINE_R_NOT_INITIALISED);
104 return 0;
105 }
106 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
107 if (!e->load_privkey)
108 {
109 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
110 ENGINE_R_NO_LOAD_FUNCTION);
111 return 0;
112 }
113 pkey = e->load_privkey(e, key_id, ui_method, callback_data);
114 if (!pkey)
115 {
116 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
117 ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
118 return 0;
119 }
120 return pkey;
121 }
122
123EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
124 UI_METHOD *ui_method, void *callback_data)
125 {
126 EVP_PKEY *pkey;
127
128 if(e == NULL)
129 {
130 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
131 ERR_R_PASSED_NULL_PARAMETER);
132 return 0;
133 }
134 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
135 if(e->funct_ref == 0)
136 {
137 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
138 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
139 ENGINE_R_NOT_INITIALISED);
140 return 0;
141 }
142 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
143 if (!e->load_pubkey)
144 {
145 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
146 ENGINE_R_NO_LOAD_FUNCTION);
147 return 0;
148 }
149 pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
150 if (!pkey)
151 {
152 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
153 ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
154 return 0;
155 }
156 return pkey;
157 }
diff --git a/src/lib/libcrypto/engine/eng_table.c b/src/lib/libcrypto/engine/eng_table.c
deleted file mode 100644
index c69a84a8bf..0000000000
--- a/src/lib/libcrypto/engine/eng_table.c
+++ /dev/null
@@ -1,361 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* This is the type of item in the 'implementation' table. Each 'nid' hashes to
60 * a (potentially NULL) ENGINE_PILE structure which contains a stack of ENGINE*
61 * pointers. These pointers aren't references, because they're inserted and
62 * removed during ENGINE creation and ENGINE destruction. They point to ENGINEs
63 * that *exist* (ie. have a structural reference count greater than zero) rather
64 * than ENGINEs that are *functional*. Each pointer in those stacks are to
65 * ENGINEs that implements the algorithm corresponding to each 'nid'. */
66
67/* The type of the items in the table */
68typedef struct st_engine_pile
69 {
70 /* The 'nid' of the algorithm/mode this ENGINE_PILE structure represents
71 * */
72 int nid;
73 /* A stack of ENGINE pointers for ENGINEs that support this
74 * algorithm/mode. In the event that 'funct' is NULL, the first entry in
75 * this stack that initialises will be set as 'funct' and assumed as the
76 * default for operations of this type. */
77 STACK_OF(ENGINE) *sk;
78 /* The default ENGINE to perform this algorithm/mode. */
79 ENGINE *funct;
80 /* This value optimises engine_table_select(). If it is called it sets
81 * this value to 1. Any changes to this ENGINE_PILE resets it to zero.
82 * As such, no ENGINE_init() thrashing is done unless ENGINEs
83 * continually register (and/or unregister). */
84 int uptodate;
85 } ENGINE_PILE;
86
87/* The type of the hash table of ENGINE_PILE structures such that each are
88 * unique and keyed by the 'nid' value. */
89struct st_engine_table
90 {
91 LHASH piles;
92 }; /* ENGINE_TABLE */
93
94/* This value stores global options controlling behaviour of (mostly) the
95 * engine_table_select() function. It's a bitmask of flag values of the form
96 * ENGINE_TABLE_FLAG_*** (as defined in engine.h) and is controlled by the
97 * ENGINE_[get|set]_table_flags() function. */
98static unsigned int table_flags = 0;
99
100/* API function manipulating 'table_flags' */
101unsigned int ENGINE_get_table_flags(void)
102 {
103 return table_flags;
104 }
105void ENGINE_set_table_flags(unsigned int flags)
106 {
107 table_flags = flags;
108 }
109
110/* Internal functions for the "piles" hash table */
111static unsigned long engine_pile_hash(const ENGINE_PILE *c)
112 {
113 return c->nid;
114 }
115static int engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b)
116 {
117 return a->nid - b->nid;
118 }
119static IMPLEMENT_LHASH_HASH_FN(engine_pile_hash, const ENGINE_PILE *)
120static IMPLEMENT_LHASH_COMP_FN(engine_pile_cmp, const ENGINE_PILE *)
121static int int_table_check(ENGINE_TABLE **t, int create)
122 {
123 LHASH *lh;
124 if(*t)
125 return 1;
126 if(!create)
127 return 0;
128 if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash),
129 LHASH_COMP_FN(engine_pile_cmp))) == NULL)
130 return 0;
131 *t = (ENGINE_TABLE *)lh;
132 return 1;
133 }
134
135/* Privately exposed (via eng_int.h) functions for adding and/or removing
136 * ENGINEs from the implementation table */
137int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
138 ENGINE *e, const int *nids, int num_nids, int setdefault)
139 {
140 int ret = 0, added = 0;
141 ENGINE_PILE tmplate, *fnd;
142 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
143 if(!(*table))
144 added = 1;
145 if(!int_table_check(table, 1))
146 goto end;
147 if(added)
148 /* The cleanup callback needs to be added */
149 engine_cleanup_add_first(cleanup);
150 while(num_nids--)
151 {
152 tmplate.nid = *nids;
153 fnd = lh_retrieve(&(*table)->piles, &tmplate);
154 if(!fnd)
155 {
156 fnd = OPENSSL_malloc(sizeof(ENGINE_PILE));
157 if(!fnd)
158 goto end;
159 fnd->uptodate = 1;
160 fnd->nid = *nids;
161 fnd->sk = sk_ENGINE_new_null();
162 if(!fnd->sk)
163 {
164 OPENSSL_free(fnd);
165 goto end;
166 }
167 fnd->funct= NULL;
168 lh_insert(&(*table)->piles, fnd);
169 }
170 /* A registration shouldn't add duplciate entries */
171 sk_ENGINE_delete_ptr(fnd->sk, e);
172 /* if 'setdefault', this ENGINE goes to the head of the list */
173 if(!sk_ENGINE_push(fnd->sk, e))
174 goto end;
175 /* "touch" this ENGINE_PILE */
176 fnd->uptodate = 0;
177 if(setdefault)
178 {
179 if(!engine_unlocked_init(e))
180 {
181 ENGINEerr(ENGINE_F_ENGINE_TABLE_REGISTER,
182 ENGINE_R_INIT_FAILED);
183 goto end;
184 }
185 if(fnd->funct)
186 engine_unlocked_finish(fnd->funct, 0);
187 fnd->funct = e;
188 }
189 nids++;
190 }
191 ret = 1;
192end:
193 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
194 return ret;
195 }
196static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
197 {
198 int n;
199 /* Iterate the 'c->sk' stack removing any occurance of 'e' */
200 while((n = sk_ENGINE_find(pile->sk, e)) >= 0)
201 {
202 sk_ENGINE_delete(pile->sk, n);
203 /* "touch" this ENGINE_CIPHER */
204 pile->uptodate = 0;
205 }
206 if(pile->funct == e)
207 {
208 engine_unlocked_finish(e, 0);
209 pile->funct = NULL;
210 }
211 }
212static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb,ENGINE_PILE *,ENGINE *)
213void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e)
214 {
215 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
216 if(int_table_check(table, 0))
217 lh_doall_arg(&(*table)->piles,
218 LHASH_DOALL_ARG_FN(int_unregister_cb), e);
219 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
220 }
221
222static void int_cleanup_cb(ENGINE_PILE *p)
223 {
224 sk_ENGINE_free(p->sk);
225 if(p->funct)
226 engine_unlocked_finish(p->funct, 0);
227 OPENSSL_free(p);
228 }
229static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb,ENGINE_PILE *)
230void engine_table_cleanup(ENGINE_TABLE **table)
231 {
232 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
233 if(*table)
234 {
235 lh_doall(&(*table)->piles, LHASH_DOALL_FN(int_cleanup_cb));
236 lh_free(&(*table)->piles);
237 *table = NULL;
238 }
239 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
240 }
241
242/* Exposed API function to get a functional reference from the implementation
243 * table (ie. try to get a functional reference from the tabled structural
244 * references) for a given cipher 'nid' */
245#ifndef ENGINE_TABLE_DEBUG
246ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)
247#else
248ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l)
249#endif
250 {
251 ENGINE *ret = NULL;
252 ENGINE_PILE tmplate, *fnd=NULL;
253 int initres, loop = 0;
254
255 /* If 'engine_ciphers' is NULL, then it's absolutely *sure* that no
256 * ENGINEs have registered any implementations! */
257 if(!(*table))
258 {
259#ifdef ENGINE_TABLE_DEBUG
260 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "
261 "registered for anything!\n", f, l, nid);
262#endif
263 return NULL;
264 }
265 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
266 /* Check again inside the lock otherwise we could race against cleanup
267 * operations. But don't worry about a fprintf(stderr). */
268 if(!int_table_check(table, 0))
269 goto end;
270 tmplate.nid = nid;
271 fnd = lh_retrieve(&(*table)->piles, &tmplate);
272 if(!fnd)
273 goto end;
274 if(fnd->funct && engine_unlocked_init(fnd->funct))
275 {
276#ifdef ENGINE_TABLE_DEBUG
277 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "
278 "ENGINE '%s' cached\n", f, l, nid, fnd->funct->id);
279#endif
280 ret = fnd->funct;
281 goto end;
282 }
283 if(fnd->uptodate)
284 {
285 ret = fnd->funct;
286 goto end;
287 }
288trynext:
289 ret = sk_ENGINE_value(fnd->sk, loop++);
290 if(!ret)
291 {
292#ifdef ENGINE_TABLE_DEBUG
293 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "
294 "registered implementations would initialise\n",
295 f, l, nid);
296#endif
297 goto end;
298 }
299#if 0
300 /* Don't need to get a reference if we hold the lock. If the locking has
301 * to change in future, that would be different ... */
302 ret->struct_ref++; engine_ref_debug(ret, 0, 1)
303#endif
304 /* Try and initialise the ENGINE if it's already functional *or* if the
305 * ENGINE_TABLE_FLAG_NOINIT flag is not set. */
306 if((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))
307 initres = engine_unlocked_init(ret);
308 else
309 initres = 0;
310#if 0
311 /* Release the structural reference */
312 ret->struct_ref--; engine_ref_debug(ret, 0, -1);
313#endif
314 if(initres)
315 {
316 /* If we didn't have a default (functional reference) for this
317 * 'nid' (or we had one but for whatever reason we're now
318 * initialising a different one), use this opportunity to set
319 * 'funct'. */
320 if((fnd->funct != ret) && engine_unlocked_init(ret))
321 {
322 /* If there was a previous default we release it. */
323 if(fnd->funct)
324 engine_unlocked_finish(fnd->funct, 0);
325 /* We got an extra functional reference for the
326 * per-'nid' default */
327 fnd->funct = ret;
328#ifdef ENGINE_TABLE_DEBUG
329 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "
330 "setting default to '%s'\n", f, l, nid, ret->id);
331#endif
332 }
333#ifdef ENGINE_TABLE_DEBUG
334 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "
335 "newly initialised '%s'\n", f, l, nid, ret->id);
336#endif
337 goto end;
338 }
339 goto trynext;
340end:
341 /* Whatever happened - we should "untouch" our uptodate file seeing as
342 * we have tried our best to find a functional reference for 'nid'. If
343 * it failed, it is unlikely to succeed again until some future
344 * registrations (or unregistrations) have taken place that affect that
345 * 'nid'. */
346 if(fnd)
347 fnd->uptodate = 1;
348#ifdef ENGINE_TABLE_DEBUG
349 if(ret)
350 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
351 "ENGINE '%s'\n", f, l, nid, ret->id);
352 else
353 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
354 "'no matching ENGINE'\n", f, l, nid);
355#endif
356 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
357 /* Whatever happened, any failed init()s are not failures in this
358 * context, so clear our error state. */
359 ERR_clear_error();
360 return ret;
361 }
diff --git a/src/lib/libcrypto/engine/engine.h b/src/lib/libcrypto/engine/engine.h
deleted file mode 100644
index 900f75ce8d..0000000000
--- a/src/lib/libcrypto/engine/engine.h
+++ /dev/null
@@ -1,729 +0,0 @@
1/* openssl/engine.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_ENGINE_H
60#define HEADER_ENGINE_H
61
62#include <openssl/opensslconf.h>
63
64#ifdef OPENSSL_NO_ENGINE
65#error ENGINE is disabled.
66#endif
67
68#include <openssl/ossl_typ.h>
69#include <openssl/bn.h>
70#ifndef OPENSSL_NO_RSA
71#include <openssl/rsa.h>
72#endif
73#ifndef OPENSSL_NO_DSA
74#include <openssl/dsa.h>
75#endif
76#ifndef OPENSSL_NO_DH
77#include <openssl/dh.h>
78#endif
79#include <openssl/rand.h>
80#include <openssl/ui.h>
81#include <openssl/symhacks.h>
82#include <openssl/err.h>
83
84#ifdef __cplusplus
85extern "C" {
86#endif
87
88/* Fixups for missing algorithms */
89#ifdef OPENSSL_NO_RSA
90typedef void RSA_METHOD;
91#endif
92#ifdef OPENSSL_NO_DSA
93typedef void DSA_METHOD;
94#endif
95#ifdef OPENSSL_NO_DH
96typedef void DH_METHOD;
97#endif
98
99/* These flags are used to control combinations of algorithm (methods)
100 * by bitwise "OR"ing. */
101#define ENGINE_METHOD_RSA (unsigned int)0x0001
102#define ENGINE_METHOD_DSA (unsigned int)0x0002
103#define ENGINE_METHOD_DH (unsigned int)0x0004
104#define ENGINE_METHOD_RAND (unsigned int)0x0008
105#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040
106#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080
107/* Obvious all-or-nothing cases. */
108#define ENGINE_METHOD_ALL (unsigned int)0xFFFF
109#define ENGINE_METHOD_NONE (unsigned int)0x0000
110
111/* This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used
112 * internally to control registration of ENGINE implementations, and can be set
113 * by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to
114 * initialise registered ENGINEs if they are not already initialised. */
115#define ENGINE_TABLE_FLAG_NOINIT (unsigned int)0x0001
116
117/* ENGINE flags that can be set by ENGINE_set_flags(). */
118/* #define ENGINE_FLAGS_MALLOCED 0x0001 */ /* Not used */
119
120/* This flag is for ENGINEs that wish to handle the various 'CMD'-related
121 * control commands on their own. Without this flag, ENGINE_ctrl() handles these
122 * control commands on behalf of the ENGINE using their "cmd_defns" data. */
123#define ENGINE_FLAGS_MANUAL_CMD_CTRL (int)0x0002
124
125/* This flag is for ENGINEs who return new duplicate structures when found via
126 * "ENGINE_by_id()". When an ENGINE must store state (eg. if ENGINE_ctrl()
127 * commands are called in sequence as part of some stateful process like
128 * key-generation setup and execution), it can set this flag - then each attempt
129 * to obtain the ENGINE will result in it being copied into a new structure.
130 * Normally, ENGINEs don't declare this flag so ENGINE_by_id() just increments
131 * the existing ENGINE's structural reference count. */
132#define ENGINE_FLAGS_BY_ID_COPY (int)0x0004
133
134/* ENGINEs can support their own command types, and these flags are used in
135 * ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input each
136 * command expects. Currently only numeric and string input is supported. If a
137 * control command supports none of the _NUMERIC, _STRING, or _NO_INPUT options,
138 * then it is regarded as an "internal" control command - and not for use in
139 * config setting situations. As such, they're not available to the
140 * ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl() access. Changes to
141 * this list of 'command types' should be reflected carefully in
142 * ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string(). */
143
144/* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */
145#define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001
146/* accepts string input (cast from 'void*' to 'const char *', 4th parameter to
147 * ENGINE_ctrl) */
148#define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002
149/* Indicates that the control command takes *no* input. Ie. the control command
150 * is unparameterised. */
151#define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004
152/* Indicates that the control command is internal. This control command won't
153 * be shown in any output, and is only usable through the ENGINE_ctrl_cmd()
154 * function. */
155#define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008
156
157/* NB: These 3 control commands are deprecated and should not be used. ENGINEs
158 * relying on these commands should compile conditional support for
159 * compatibility (eg. if these symbols are defined) but should also migrate the
160 * same functionality to their own ENGINE-specific control functions that can be
161 * "discovered" by calling applications. The fact these control commands
162 * wouldn't be "executable" (ie. usable by text-based config) doesn't change the
163 * fact that application code can find and use them without requiring per-ENGINE
164 * hacking. */
165
166/* These flags are used to tell the ctrl function what should be done.
167 * All command numbers are shared between all engines, even if some don't
168 * make sense to some engines. In such a case, they do nothing but return
169 * the error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED. */
170#define ENGINE_CTRL_SET_LOGSTREAM 1
171#define ENGINE_CTRL_SET_PASSWORD_CALLBACK 2
172#define ENGINE_CTRL_HUP 3 /* Close and reinitialise any
173 handles/connections etc. */
174#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */
175#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used
176 when calling the password
177 callback and the user
178 interface */
179
180/* These control commands allow an application to deal with an arbitrary engine
181 * in a dynamic way. Warn: Negative return values indicate errors FOR THESE
182 * COMMANDS because zero is used to indicate 'end-of-list'. Other commands,
183 * including ENGINE-specific command types, return zero for an error.
184 *
185 * An ENGINE can choose to implement these ctrl functions, and can internally
186 * manage things however it chooses - it does so by setting the
187 * ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise the
188 * ENGINE_ctrl() code handles this on the ENGINE's behalf using the cmd_defns
189 * data (set using ENGINE_set_cmd_defns()). This means an ENGINE's ctrl()
190 * handler need only implement its own commands - the above "meta" commands will
191 * be taken care of. */
192
193/* Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not", then
194 * all the remaining control commands will return failure, so it is worth
195 * checking this first if the caller is trying to "discover" the engine's
196 * capabilities and doesn't want errors generated unnecessarily. */
197#define ENGINE_CTRL_HAS_CTRL_FUNCTION 10
198/* Returns a positive command number for the first command supported by the
199 * engine. Returns zero if no ctrl commands are supported. */
200#define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11
201/* The 'long' argument specifies a command implemented by the engine, and the
202 * return value is the next command supported, or zero if there are no more. */
203#define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12
204/* The 'void*' argument is a command name (cast from 'const char *'), and the
205 * return value is the command that corresponds to it. */
206#define ENGINE_CTRL_GET_CMD_FROM_NAME 13
207/* The next two allow a command to be converted into its corresponding string
208 * form. In each case, the 'long' argument supplies the command. In the NAME_LEN
209 * case, the return value is the length of the command name (not counting a
210 * trailing EOL). In the NAME case, the 'void*' argument must be a string buffer
211 * large enough, and it will be populated with the name of the command (WITH a
212 * trailing EOL). */
213#define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14
214#define ENGINE_CTRL_GET_NAME_FROM_CMD 15
215/* The next two are similar but give a "short description" of a command. */
216#define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16
217#define ENGINE_CTRL_GET_DESC_FROM_CMD 17
218/* With this command, the return value is the OR'd combination of
219 * ENGINE_CMD_FLAG_*** values that indicate what kind of input a given
220 * engine-specific ctrl command expects. */
221#define ENGINE_CTRL_GET_CMD_FLAGS 18
222
223/* ENGINE implementations should start the numbering of their own control
224 * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */
225#define ENGINE_CMD_BASE 200
226
227/* NB: These 2 nCipher "chil" control commands are deprecated, and their
228 * functionality is now available through ENGINE-specific control commands
229 * (exposed through the above-mentioned 'CMD'-handling). Code using these 2
230 * commands should be migrated to the more general command handling before these
231 * are removed. */
232
233/* Flags specific to the nCipher "chil" engine */
234#define ENGINE_CTRL_CHIL_SET_FORKCHECK 100
235 /* Depending on the value of the (long)i argument, this sets or
236 * unsets the SimpleForkCheck flag in the CHIL API to enable or
237 * disable checking and workarounds for applications that fork().
238 */
239#define ENGINE_CTRL_CHIL_NO_LOCKING 101
240 /* This prevents the initialisation function from providing mutex
241 * callbacks to the nCipher library. */
242
243/* If an ENGINE supports its own specific control commands and wishes the
244 * framework to handle the above 'ENGINE_CMD_***'-manipulation commands on its
245 * behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN entries
246 * to ENGINE_set_cmd_defns(). It should also implement a ctrl() handler that
247 * supports the stated commands (ie. the "cmd_num" entries as described by the
248 * array). NB: The array must be ordered in increasing order of cmd_num.
249 * "null-terminated" means that the last ENGINE_CMD_DEFN element has cmd_num set
250 * to zero and/or cmd_name set to NULL. */
251typedef struct ENGINE_CMD_DEFN_st
252 {
253 unsigned int cmd_num; /* The command number */
254 const char *cmd_name; /* The command name itself */
255 const char *cmd_desc; /* A short description of the command */
256 unsigned int cmd_flags; /* The input the command expects */
257 } ENGINE_CMD_DEFN;
258
259/* Generic function pointer */
260typedef int (*ENGINE_GEN_FUNC_PTR)();
261/* Generic function pointer taking no arguments */
262typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *);
263/* Specific control function pointer */
264typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)());
265/* Generic load_key function pointer */
266typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,
267 UI_METHOD *ui_method, void *callback_data);
268/* These callback types are for an ENGINE's handler for cipher and digest logic.
269 * These handlers have these prototypes;
270 * int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid);
271 * int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid);
272 * Looking at how to implement these handlers in the case of cipher support, if
273 * the framework wants the EVP_CIPHER for 'nid', it will call;
274 * foo(e, &p_evp_cipher, NULL, nid); (return zero for failure)
275 * If the framework wants a list of supported 'nid's, it will call;
276 * foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error)
277 */
278/* Returns to a pointer to the array of supported cipher 'nid's. If the second
279 * parameter is non-NULL it is set to the size of the returned array. */
280typedef int (*ENGINE_CIPHERS_PTR)(ENGINE *, const EVP_CIPHER **, const int **, int);
281typedef int (*ENGINE_DIGESTS_PTR)(ENGINE *, const EVP_MD **, const int **, int);
282
283/* STRUCTURE functions ... all of these functions deal with pointers to ENGINE
284 * structures where the pointers have a "structural reference". This means that
285 * their reference is to allowed access to the structure but it does not imply
286 * that the structure is functional. To simply increment or decrement the
287 * structural reference count, use ENGINE_by_id and ENGINE_free. NB: This is not
288 * required when iterating using ENGINE_get_next as it will automatically
289 * decrement the structural reference count of the "current" ENGINE and
290 * increment the structural reference count of the ENGINE it returns (unless it
291 * is NULL). */
292
293/* Get the first/last "ENGINE" type available. */
294ENGINE *ENGINE_get_first(void);
295ENGINE *ENGINE_get_last(void);
296/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
297ENGINE *ENGINE_get_next(ENGINE *e);
298ENGINE *ENGINE_get_prev(ENGINE *e);
299/* Add another "ENGINE" type into the array. */
300int ENGINE_add(ENGINE *e);
301/* Remove an existing "ENGINE" type from the array. */
302int ENGINE_remove(ENGINE *e);
303/* Retrieve an engine from the list by its unique "id" value. */
304ENGINE *ENGINE_by_id(const char *id);
305/* Add all the built-in engines. */
306void ENGINE_load_openssl(void);
307void ENGINE_load_dynamic(void);
308void ENGINE_load_cswift(void);
309void ENGINE_load_chil(void);
310void ENGINE_load_atalla(void);
311void ENGINE_load_nuron(void);
312void ENGINE_load_ubsec(void);
313void ENGINE_load_aep(void);
314void ENGINE_load_sureware(void);
315void ENGINE_load_4758cca(void);
316void ENGINE_load_cryptodev(void);
317void ENGINE_load_builtin_engines(void);
318
319/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
320 * "registry" handling. */
321unsigned int ENGINE_get_table_flags(void);
322void ENGINE_set_table_flags(unsigned int flags);
323
324/* Manage registration of ENGINEs per "table". For each type, there are 3
325 * functions;
326 * ENGINE_register_***(e) - registers the implementation from 'e' (if it has one)
327 * ENGINE_unregister_***(e) - unregister the implementation from 'e'
328 * ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list
329 * Cleanup is automatically registered from each table when required, so
330 * ENGINE_cleanup() will reverse any "register" operations. */
331
332int ENGINE_register_RSA(ENGINE *e);
333void ENGINE_unregister_RSA(ENGINE *e);
334void ENGINE_register_all_RSA(void);
335
336int ENGINE_register_DSA(ENGINE *e);
337void ENGINE_unregister_DSA(ENGINE *e);
338void ENGINE_register_all_DSA(void);
339
340int ENGINE_register_DH(ENGINE *e);
341void ENGINE_unregister_DH(ENGINE *e);
342void ENGINE_register_all_DH(void);
343
344int ENGINE_register_RAND(ENGINE *e);
345void ENGINE_unregister_RAND(ENGINE *e);
346void ENGINE_register_all_RAND(void);
347
348int ENGINE_register_ciphers(ENGINE *e);
349void ENGINE_unregister_ciphers(ENGINE *e);
350void ENGINE_register_all_ciphers(void);
351
352int ENGINE_register_digests(ENGINE *e);
353void ENGINE_unregister_digests(ENGINE *e);
354void ENGINE_register_all_digests(void);
355
356/* These functions register all support from the above categories. Note, use of
357 * these functions can result in static linkage of code your application may not
358 * need. If you only need a subset of functionality, consider using more
359 * selective initialisation. */
360int ENGINE_register_complete(ENGINE *e);
361int ENGINE_register_all_complete(void);
362
363/* Send parametrised control commands to the engine. The possibilities to send
364 * down an integer, a pointer to data or a function pointer are provided. Any of
365 * the parameters may or may not be NULL, depending on the command number. In
366 * actuality, this function only requires a structural (rather than functional)
367 * reference to an engine, but many control commands may require the engine be
368 * functional. The caller should be aware of trying commands that require an
369 * operational ENGINE, and only use functional references in such situations. */
370int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
371
372/* This function tests if an ENGINE-specific command is usable as a "setting".
373 * Eg. in an application's config file that gets processed through
374 * ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to
375 * ENGINE_ctrl_cmd_string(), only ENGINE_ctrl(). */
376int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
377
378/* This function works like ENGINE_ctrl() with the exception of taking a
379 * command name instead of a command number, and can handle optional commands.
380 * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to
381 * use the cmd_name and cmd_optional. */
382int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
383 long i, void *p, void (*f)(), int cmd_optional);
384
385/* This function passes a command-name and argument to an ENGINE. The cmd_name
386 * is converted to a command number and the control command is called using
387 * 'arg' as an argument (unless the ENGINE doesn't support such a command, in
388 * which case no control command is called). The command is checked for input
389 * flags, and if necessary the argument will be converted to a numeric value. If
390 * cmd_optional is non-zero, then if the ENGINE doesn't support the given
391 * cmd_name the return value will be success anyway. This function is intended
392 * for applications to use so that users (or config files) can supply
393 * engine-specific config data to the ENGINE at run-time to control behaviour of
394 * specific engines. As such, it shouldn't be used for calling ENGINE_ctrl()
395 * functions that return data, deal with binary data, or that are otherwise
396 * supposed to be used directly through ENGINE_ctrl() in application code. Any
397 * "return" data from an ENGINE_ctrl() operation in this function will be lost -
398 * the return value is interpreted as failure if the return value is zero,
399 * success otherwise, and this function returns a boolean value as a result. In
400 * other words, vendors of 'ENGINE'-enabled devices should write ENGINE
401 * implementations with parameterisations that work in this scheme, so that
402 * compliant ENGINE-based applications can work consistently with the same
403 * configuration for the same ENGINE-enabled devices, across applications. */
404int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
405 int cmd_optional);
406
407/* These functions are useful for manufacturing new ENGINE structures. They
408 * don't address reference counting at all - one uses them to populate an ENGINE
409 * structure with personalised implementations of things prior to using it
410 * directly or adding it to the builtin ENGINE list in OpenSSL. These are also
411 * here so that the ENGINE structure doesn't have to be exposed and break binary
412 * compatibility! */
413ENGINE *ENGINE_new(void);
414int ENGINE_free(ENGINE *e);
415int ENGINE_up_ref(ENGINE *e);
416int ENGINE_set_id(ENGINE *e, const char *id);
417int ENGINE_set_name(ENGINE *e, const char *name);
418int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
419int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
420int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
421int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
422int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
423int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
424int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
425int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
426int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
427int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
428int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
429int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
430int ENGINE_set_flags(ENGINE *e, int flags);
431int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
432/* These functions (and the "get" function lower down) allow control over any
433 * per-structure ENGINE data. */
434int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
435 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
436int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
437
438/* This function cleans up anything that needs it. Eg. the ENGINE_add() function
439 * automatically ensures the list cleanup function is registered to be called
440 * from ENGINE_cleanup(). Similarly, all ENGINE_register_*** functions ensure
441 * ENGINE_cleanup() will clean up after them. */
442void ENGINE_cleanup(void);
443
444/* These return values from within the ENGINE structure. These can be useful
445 * with functional references as well as structural references - it depends
446 * which you obtained. Using the result for functional purposes if you only
447 * obtained a structural reference may be problematic! */
448const char *ENGINE_get_id(const ENGINE *e);
449const char *ENGINE_get_name(const ENGINE *e);
450const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
451const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
452const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
453const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
454ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
455ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
456ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
457ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
458ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
459ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
460ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
461ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
462const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
463const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
464const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
465int ENGINE_get_flags(const ENGINE *e);
466void *ENGINE_get_ex_data(const ENGINE *e, int idx);
467
468/* FUNCTIONAL functions. These functions deal with ENGINE structures
469 * that have (or will) be initialised for use. Broadly speaking, the
470 * structural functions are useful for iterating the list of available
471 * engine types, creating new engine types, and other "list" operations.
472 * These functions actually deal with ENGINEs that are to be used. As
473 * such these functions can fail (if applicable) when particular
474 * engines are unavailable - eg. if a hardware accelerator is not
475 * attached or not functioning correctly. Each ENGINE has 2 reference
476 * counts; structural and functional. Every time a functional reference
477 * is obtained or released, a corresponding structural reference is
478 * automatically obtained or released too. */
479
480/* Initialise a engine type for use (or up its reference count if it's
481 * already in use). This will fail if the engine is not currently
482 * operational and cannot initialise. */
483int ENGINE_init(ENGINE *e);
484/* Free a functional reference to a engine type. This does not require
485 * a corresponding call to ENGINE_free as it also releases a structural
486 * reference. */
487int ENGINE_finish(ENGINE *e);
488
489/* The following functions handle keys that are stored in some secondary
490 * location, handled by the engine. The storage may be on a card or
491 * whatever. */
492EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
493 UI_METHOD *ui_method, void *callback_data);
494EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
495 UI_METHOD *ui_method, void *callback_data);
496
497/* This returns a pointer for the current ENGINE structure that
498 * is (by default) performing any RSA operations. The value returned
499 * is an incremented reference, so it should be free'd (ENGINE_finish)
500 * before it is discarded. */
501ENGINE *ENGINE_get_default_RSA(void);
502/* Same for the other "methods" */
503ENGINE *ENGINE_get_default_DSA(void);
504ENGINE *ENGINE_get_default_DH(void);
505ENGINE *ENGINE_get_default_RAND(void);
506/* These functions can be used to get a functional reference to perform
507 * ciphering or digesting corresponding to "nid". */
508ENGINE *ENGINE_get_cipher_engine(int nid);
509ENGINE *ENGINE_get_digest_engine(int nid);
510
511/* This sets a new default ENGINE structure for performing RSA
512 * operations. If the result is non-zero (success) then the ENGINE
513 * structure will have had its reference count up'd so the caller
514 * should still free their own reference 'e'. */
515int ENGINE_set_default_RSA(ENGINE *e);
516int ENGINE_set_default_string(ENGINE *e, const char *def_list);
517/* Same for the other "methods" */
518int ENGINE_set_default_DSA(ENGINE *e);
519int ENGINE_set_default_DH(ENGINE *e);
520int ENGINE_set_default_RAND(ENGINE *e);
521int ENGINE_set_default_ciphers(ENGINE *e);
522int ENGINE_set_default_digests(ENGINE *e);
523
524/* The combination "set" - the flags are bitwise "OR"d from the
525 * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()"
526 * function, this function can result in unnecessary static linkage. If your
527 * application requires only specific functionality, consider using more
528 * selective functions. */
529int ENGINE_set_default(ENGINE *e, unsigned int flags);
530
531void ENGINE_add_conf_module(void);
532
533/* Deprecated functions ... */
534/* int ENGINE_clear_defaults(void); */
535
536/**************************/
537/* DYNAMIC ENGINE SUPPORT */
538/**************************/
539
540/* Binary/behaviour compatibility levels */
541#define OSSL_DYNAMIC_VERSION (unsigned long)0x00010200
542/* Binary versions older than this are too old for us (whether we're a loader or
543 * a loadee) */
544#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00010200
545
546/* When compiling an ENGINE entirely as an external shared library, loadable by
547 * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure
548 * type provides the calling application's (or library's) error functionality
549 * and memory management function pointers to the loaded library. These should
550 * be used/set in the loaded library code so that the loading application's
551 * 'state' will be used/changed in all operations. */
552typedef void *(*dyn_MEM_malloc_cb)(size_t);
553typedef void *(*dyn_MEM_realloc_cb)(void *, size_t);
554typedef void (*dyn_MEM_free_cb)(void *);
555typedef struct st_dynamic_MEM_fns {
556 dyn_MEM_malloc_cb malloc_cb;
557 dyn_MEM_realloc_cb realloc_cb;
558 dyn_MEM_free_cb free_cb;
559 } dynamic_MEM_fns;
560/* FIXME: Perhaps the memory and locking code (crypto.h) should declare and use
561 * these types so we (and any other dependant code) can simplify a bit?? */
562typedef void (*dyn_lock_locking_cb)(int,int,const char *,int);
563typedef int (*dyn_lock_add_lock_cb)(int*,int,int,const char *,int);
564typedef struct CRYPTO_dynlock_value *(*dyn_dynlock_create_cb)(
565 const char *,int);
566typedef void (*dyn_dynlock_lock_cb)(int,struct CRYPTO_dynlock_value *,
567 const char *,int);
568typedef void (*dyn_dynlock_destroy_cb)(struct CRYPTO_dynlock_value *,
569 const char *,int);
570typedef struct st_dynamic_LOCK_fns {
571 dyn_lock_locking_cb lock_locking_cb;
572 dyn_lock_add_lock_cb lock_add_lock_cb;
573 dyn_dynlock_create_cb dynlock_create_cb;
574 dyn_dynlock_lock_cb dynlock_lock_cb;
575 dyn_dynlock_destroy_cb dynlock_destroy_cb;
576 } dynamic_LOCK_fns;
577/* The top-level structure */
578typedef struct st_dynamic_fns {
579 const ERR_FNS *err_fns;
580 const CRYPTO_EX_DATA_IMPL *ex_data_fns;
581 dynamic_MEM_fns mem_fns;
582 dynamic_LOCK_fns lock_fns;
583 } dynamic_fns;
584
585/* The version checking function should be of this prototype. NB: The
586 * ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading code.
587 * If this function returns zero, it indicates a (potential) version
588 * incompatibility and the loaded library doesn't believe it can proceed.
589 * Otherwise, the returned value is the (latest) version supported by the
590 * loading library. The loader may still decide that the loaded code's version
591 * is unsatisfactory and could veto the load. The function is expected to
592 * be implemented with the symbol name "v_check", and a default implementation
593 * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */
594typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
595#define IMPLEMENT_DYNAMIC_CHECK_FN() \
596 unsigned long v_check(unsigned long v) { \
597 if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \
598 return 0; }
599
600/* This function is passed the ENGINE structure to initialise with its own
601 * function and command settings. It should not adjust the structural or
602 * functional reference counts. If this function returns zero, (a) the load will
603 * be aborted, (b) the previous ENGINE state will be memcpy'd back onto the
604 * structure, and (c) the shared library will be unloaded. So implementations
605 * should do their own internal cleanup in failure circumstances otherwise they
606 * could leak. The 'id' parameter, if non-NULL, represents the ENGINE id that
607 * the loader is looking for. If this is NULL, the shared library can choose to
608 * return failure or to initialise a 'default' ENGINE. If non-NULL, the shared
609 * library must initialise only an ENGINE matching the passed 'id'. The function
610 * is expected to be implemented with the symbol name "bind_engine". A standard
611 * implementation can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where
612 * the parameter 'fn' is a callback function that populates the ENGINE structure
613 * and returns an int value (zero for failure). 'fn' should have prototype;
614 * [static] int fn(ENGINE *e, const char *id); */
615typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
616 const dynamic_fns *fns);
617#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \
618 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
619 if (ERR_get_implementation() != fns->err_fns) \
620 { \
621 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
622 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \
623 return 0; \
624 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \
625 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \
626 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
627 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \
628 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \
629 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \
630 return 0; \
631 if(!ERR_set_implementation(fns->err_fns)) return 0; \
632 } \
633 if(!fn(e,id)) return 0; \
634 return 1; }
635
636#if defined(__OpenBSD__) || defined(__FreeBSD__)
637void ENGINE_setup_bsd_cryptodev(void);
638#endif
639
640/* BEGIN ERROR CODES */
641/* The following lines are auto generated by the script mkerr.pl. Any changes
642 * made after this point may be overwritten when the script is next run.
643 */
644void ERR_load_ENGINE_strings(void);
645
646/* Error codes for the ENGINE functions. */
647
648/* Function codes. */
649#define ENGINE_F_DYNAMIC_CTRL 180
650#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181
651#define ENGINE_F_DYNAMIC_LOAD 182
652#define ENGINE_F_ENGINE_ADD 105
653#define ENGINE_F_ENGINE_BY_ID 106
654#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170
655#define ENGINE_F_ENGINE_CTRL 142
656#define ENGINE_F_ENGINE_CTRL_CMD 178
657#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171
658#define ENGINE_F_ENGINE_FINISH 107
659#define ENGINE_F_ENGINE_FREE 108
660#define ENGINE_F_ENGINE_GET_CIPHER 185
661#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177
662#define ENGINE_F_ENGINE_GET_DIGEST 186
663#define ENGINE_F_ENGINE_GET_NEXT 115
664#define ENGINE_F_ENGINE_GET_PREV 116
665#define ENGINE_F_ENGINE_INIT 119
666#define ENGINE_F_ENGINE_LIST_ADD 120
667#define ENGINE_F_ENGINE_LIST_REMOVE 121
668#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150
669#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
670#define ENGINE_F_ENGINE_MODULE_INIT 187
671#define ENGINE_F_ENGINE_NEW 122
672#define ENGINE_F_ENGINE_REMOVE 123
673#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189
674#define ENGINE_F_ENGINE_SET_DEFAULT_TYPE 126
675#define ENGINE_F_ENGINE_SET_ID 129
676#define ENGINE_F_ENGINE_SET_NAME 130
677#define ENGINE_F_ENGINE_TABLE_REGISTER 184
678#define ENGINE_F_ENGINE_UNLOAD_KEY 152
679#define ENGINE_F_ENGINE_UP_REF 190
680#define ENGINE_F_INT_CTRL_HELPER 172
681#define ENGINE_F_INT_ENGINE_CONFIGURE 188
682#define ENGINE_F_LOG_MESSAGE 141
683#define ENGINE_F_SET_DATA_CTX 183
684
685/* Reason codes. */
686#define ENGINE_R_ALREADY_LOADED 100
687#define ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER 133
688#define ENGINE_R_CMD_NOT_EXECUTABLE 134
689#define ENGINE_R_COMMAND_TAKES_INPUT 135
690#define ENGINE_R_COMMAND_TAKES_NO_INPUT 136
691#define ENGINE_R_CONFLICTING_ENGINE_ID 103
692#define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119
693#define ENGINE_R_DH_NOT_IMPLEMENTED 139
694#define ENGINE_R_DSA_NOT_IMPLEMENTED 140
695#define ENGINE_R_DSO_FAILURE 104
696#define ENGINE_R_DSO_NOT_FOUND 132
697#define ENGINE_R_ENGINES_SECTION_ERROR 148
698#define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105
699#define ENGINE_R_ENGINE_SECTION_ERROR 149
700#define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128
701#define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129
702#define ENGINE_R_FINISH_FAILED 106
703#define ENGINE_R_GET_HANDLE_FAILED 107
704#define ENGINE_R_ID_OR_NAME_MISSING 108
705#define ENGINE_R_INIT_FAILED 109
706#define ENGINE_R_INTERNAL_LIST_ERROR 110
707#define ENGINE_R_INVALID_ARGUMENT 143
708#define ENGINE_R_INVALID_CMD_NAME 137
709#define ENGINE_R_INVALID_CMD_NUMBER 138
710#define ENGINE_R_INVALID_INIT_VALUE 151
711#define ENGINE_R_INVALID_STRING 150
712#define ENGINE_R_NOT_INITIALISED 117
713#define ENGINE_R_NOT_LOADED 112
714#define ENGINE_R_NO_CONTROL_FUNCTION 120
715#define ENGINE_R_NO_INDEX 144
716#define ENGINE_R_NO_LOAD_FUNCTION 125
717#define ENGINE_R_NO_REFERENCE 130
718#define ENGINE_R_NO_SUCH_ENGINE 116
719#define ENGINE_R_NO_UNLOAD_FUNCTION 126
720#define ENGINE_R_PROVIDE_PARAMETERS 113
721#define ENGINE_R_RSA_NOT_IMPLEMENTED 141
722#define ENGINE_R_UNIMPLEMENTED_CIPHER 146
723#define ENGINE_R_UNIMPLEMENTED_DIGEST 147
724#define ENGINE_R_VERSION_INCOMPATIBILITY 145
725
726#ifdef __cplusplus
727}
728#endif
729#endif
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c
deleted file mode 100644
index 50b3cec1fa..0000000000
--- a/src/lib/libcrypto/engine/tb_cipher.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_cipher_engine(), the function that
60 * is used by EVP to hook in cipher code and cache defaults (etc), will display
61 * brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_CIPHER_DEBUG */
63
64static ENGINE_TABLE *cipher_table = NULL;
65
66void ENGINE_unregister_ciphers(ENGINE *e)
67 {
68 engine_table_unregister(&cipher_table, e);
69 }
70
71static void engine_unregister_all_ciphers(void)
72 {
73 engine_table_cleanup(&cipher_table);
74 }
75
76int ENGINE_register_ciphers(ENGINE *e)
77 {
78 if(e->ciphers)
79 {
80 const int *nids;
81 int num_nids = e->ciphers(e, NULL, &nids, 0);
82 if(num_nids > 0)
83 return engine_table_register(&cipher_table,
84 engine_unregister_all_ciphers, e, nids,
85 num_nids, 0);
86 }
87 return 1;
88 }
89
90void ENGINE_register_all_ciphers()
91 {
92 ENGINE *e;
93
94 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
95 ENGINE_register_ciphers(e);
96 }
97
98int ENGINE_set_default_ciphers(ENGINE *e)
99 {
100 if(e->ciphers)
101 {
102 const int *nids;
103 int num_nids = e->ciphers(e, NULL, &nids, 0);
104 if(num_nids > 0)
105 return engine_table_register(&cipher_table,
106 engine_unregister_all_ciphers, e, nids,
107 num_nids, 1);
108 }
109 return 1;
110 }
111
112/* Exposed API function to get a functional reference from the implementation
113 * table (ie. try to get a functional reference from the tabled structural
114 * references) for a given cipher 'nid' */
115ENGINE *ENGINE_get_cipher_engine(int nid)
116 {
117 return engine_table_select(&cipher_table, nid);
118 }
119
120/* Obtains a cipher implementation from an ENGINE functional reference */
121const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid)
122 {
123 const EVP_CIPHER *ret;
124 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e);
125 if(!fn || !fn(e, &ret, NULL, nid))
126 {
127 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER,
128 ENGINE_R_UNIMPLEMENTED_CIPHER);
129 return NULL;
130 }
131 return ret;
132 }
133
134/* Gets the cipher callback from an ENGINE structure */
135ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e)
136 {
137 return e->ciphers;
138 }
139
140/* Sets the cipher callback in an ENGINE structure */
141int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f)
142 {
143 e->ciphers = f;
144 return 1;
145 }
diff --git a/src/lib/libcrypto/engine/tb_dh.c b/src/lib/libcrypto/engine/tb_dh.c
deleted file mode 100644
index e290e1702b..0000000000
--- a/src/lib/libcrypto/engine/tb_dh.c
+++ /dev/null
@@ -1,120 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_DH(), the function that is
60 * used by DH to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DH_DEBUG */
63
64static ENGINE_TABLE *dh_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_DH(ENGINE *e)
68 {
69 engine_table_unregister(&dh_table, e);
70 }
71
72static void engine_unregister_all_DH(void)
73 {
74 engine_table_cleanup(&dh_table);
75 }
76
77int ENGINE_register_DH(ENGINE *e)
78 {
79 if(e->dh_meth)
80 return engine_table_register(&dh_table,
81 engine_unregister_all_DH, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_DH()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_DH(e);
91 }
92
93int ENGINE_set_default_DH(ENGINE *e)
94 {
95 if(e->dh_meth)
96 return engine_table_register(&dh_table,
97 engine_unregister_all_DH, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_DH(void)
105 {
106 return engine_table_select(&dh_table, dummy_nid);
107 }
108
109/* Obtains an DH implementation from an ENGINE functional reference */
110const DH_METHOD *ENGINE_get_DH(const ENGINE *e)
111 {
112 return e->dh_meth;
113 }
114
115/* Sets an DH implementation in an ENGINE structure */
116int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth)
117 {
118 e->dh_meth = dh_meth;
119 return 1;
120 }
diff --git a/src/lib/libcrypto/engine/tb_digest.c b/src/lib/libcrypto/engine/tb_digest.c
deleted file mode 100644
index e82d2a17c9..0000000000
--- a/src/lib/libcrypto/engine/tb_digest.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_digest_engine(), the function that
60 * is used by EVP to hook in digest code and cache defaults (etc), will display
61 * brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DIGEST_DEBUG */
63
64static ENGINE_TABLE *digest_table = NULL;
65
66void ENGINE_unregister_digests(ENGINE *e)
67 {
68 engine_table_unregister(&digest_table, e);
69 }
70
71static void engine_unregister_all_digests(void)
72 {
73 engine_table_cleanup(&digest_table);
74 }
75
76int ENGINE_register_digests(ENGINE *e)
77 {
78 if(e->digests)
79 {
80 const int *nids;
81 int num_nids = e->digests(e, NULL, &nids, 0);
82 if(num_nids > 0)
83 return engine_table_register(&digest_table,
84 engine_unregister_all_digests, e, nids,
85 num_nids, 0);
86 }
87 return 1;
88 }
89
90void ENGINE_register_all_digests()
91 {
92 ENGINE *e;
93
94 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
95 ENGINE_register_digests(e);
96 }
97
98int ENGINE_set_default_digests(ENGINE *e)
99 {
100 if(e->digests)
101 {
102 const int *nids;
103 int num_nids = e->digests(e, NULL, &nids, 0);
104 if(num_nids > 0)
105 return engine_table_register(&digest_table,
106 engine_unregister_all_digests, e, nids,
107 num_nids, 1);
108 }
109 return 1;
110 }
111
112/* Exposed API function to get a functional reference from the implementation
113 * table (ie. try to get a functional reference from the tabled structural
114 * references) for a given digest 'nid' */
115ENGINE *ENGINE_get_digest_engine(int nid)
116 {
117 return engine_table_select(&digest_table, nid);
118 }
119
120/* Obtains a digest implementation from an ENGINE functional reference */
121const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid)
122 {
123 const EVP_MD *ret;
124 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e);
125 if(!fn || !fn(e, &ret, NULL, nid))
126 {
127 ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST,
128 ENGINE_R_UNIMPLEMENTED_DIGEST);
129 return NULL;
130 }
131 return ret;
132 }
133
134/* Gets the digest callback from an ENGINE structure */
135ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e)
136 {
137 return e->digests;
138 }
139
140/* Sets the digest callback in an ENGINE structure */
141int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f)
142 {
143 e->digests = f;
144 return 1;
145 }
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c
deleted file mode 100644
index 7efe181927..0000000000
--- a/src/lib/libcrypto/engine/tb_dsa.c
+++ /dev/null
@@ -1,120 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_DSA(), the function that is
60 * used by DSA to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_DSA_DEBUG */
63
64static ENGINE_TABLE *dsa_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_DSA(ENGINE *e)
68 {
69 engine_table_unregister(&dsa_table, e);
70 }
71
72static void engine_unregister_all_DSA(void)
73 {
74 engine_table_cleanup(&dsa_table);
75 }
76
77int ENGINE_register_DSA(ENGINE *e)
78 {
79 if(e->dsa_meth)
80 return engine_table_register(&dsa_table,
81 engine_unregister_all_DSA, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_DSA()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_DSA(e);
91 }
92
93int ENGINE_set_default_DSA(ENGINE *e)
94 {
95 if(e->dsa_meth)
96 return engine_table_register(&dsa_table,
97 engine_unregister_all_DSA, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_DSA(void)
105 {
106 return engine_table_select(&dsa_table, dummy_nid);
107 }
108
109/* Obtains an DSA implementation from an ENGINE functional reference */
110const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e)
111 {
112 return e->dsa_meth;
113 }
114
115/* Sets an DSA implementation in an ENGINE structure */
116int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
117 {
118 e->dsa_meth = dsa_meth;
119 return 1;
120 }
diff --git a/src/lib/libcrypto/engine/tb_rand.c b/src/lib/libcrypto/engine/tb_rand.c
deleted file mode 100644
index 69b67111bc..0000000000
--- a/src/lib/libcrypto/engine/tb_rand.c
+++ /dev/null
@@ -1,120 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_RAND(), the function that is
60 * used by RAND to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_RAND_DEBUG */
63
64static ENGINE_TABLE *rand_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_RAND(ENGINE *e)
68 {
69 engine_table_unregister(&rand_table, e);
70 }
71
72static void engine_unregister_all_RAND(void)
73 {
74 engine_table_cleanup(&rand_table);
75 }
76
77int ENGINE_register_RAND(ENGINE *e)
78 {
79 if(e->rand_meth)
80 return engine_table_register(&rand_table,
81 engine_unregister_all_RAND, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_RAND()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_RAND(e);
91 }
92
93int ENGINE_set_default_RAND(ENGINE *e)
94 {
95 if(e->rand_meth)
96 return engine_table_register(&rand_table,
97 engine_unregister_all_RAND, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_RAND(void)
105 {
106 return engine_table_select(&rand_table, dummy_nid);
107 }
108
109/* Obtains an RAND implementation from an ENGINE functional reference */
110const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e)
111 {
112 return e->rand_meth;
113 }
114
115/* Sets an RAND implementation in an ENGINE structure */
116int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth)
117 {
118 e->rand_meth = rand_meth;
119 return 1;
120 }
diff --git a/src/lib/libcrypto/engine/tb_rsa.c b/src/lib/libcrypto/engine/tb_rsa.c
deleted file mode 100644
index fee4867f52..0000000000
--- a/src/lib/libcrypto/engine/tb_rsa.c
+++ /dev/null
@@ -1,120 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
57#include "eng_int.h"
58
59/* If this symbol is defined then ENGINE_get_default_RSA(), the function that is
60 * used by RSA to hook in implementation code and cache defaults (etc), will
61 * display brief debugging summaries to stderr with the 'nid'. */
62/* #define ENGINE_RSA_DEBUG */
63
64static ENGINE_TABLE *rsa_table = NULL;
65static const int dummy_nid = 1;
66
67void ENGINE_unregister_RSA(ENGINE *e)
68 {
69 engine_table_unregister(&rsa_table, e);
70 }
71
72static void engine_unregister_all_RSA(void)
73 {
74 engine_table_cleanup(&rsa_table);
75 }
76
77int ENGINE_register_RSA(ENGINE *e)
78 {
79 if(e->rsa_meth)
80 return engine_table_register(&rsa_table,
81 engine_unregister_all_RSA, e, &dummy_nid, 1, 0);
82 return 1;
83 }
84
85void ENGINE_register_all_RSA()
86 {
87 ENGINE *e;
88
89 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
90 ENGINE_register_RSA(e);
91 }
92
93int ENGINE_set_default_RSA(ENGINE *e)
94 {
95 if(e->rsa_meth)
96 return engine_table_register(&rsa_table,
97 engine_unregister_all_RSA, e, &dummy_nid, 1, 1);
98 return 1;
99 }
100
101/* Exposed API function to get a functional reference from the implementation
102 * table (ie. try to get a functional reference from the tabled structural
103 * references). */
104ENGINE *ENGINE_get_default_RSA(void)
105 {
106 return engine_table_select(&rsa_table, dummy_nid);
107 }
108
109/* Obtains an RSA implementation from an ENGINE functional reference */
110const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)
111 {
112 return e->rsa_meth;
113 }
114
115/* Sets an RSA implementation in an ENGINE structure */
116int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
117 {
118 e->rsa_meth = rsa_meth;
119 return 1;
120 }
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
deleted file mode 100644
index 53687d79ab..0000000000
--- a/src/lib/libcrypto/err/err.c
+++ /dev/null
@@ -1,1079 +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-2001 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/bio.h>
120#include <openssl/err.h>
121
122static void err_load_strings(int lib, ERR_STRING_DATA *str);
123
124static void ERR_STATE_free(ERR_STATE *s);
125#ifndef OPENSSL_NO_ERR
126static ERR_STRING_DATA ERR_str_libraries[]=
127 {
128{ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"},
129{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"},
130{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"},
131{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"},
132{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"},
133{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"},
134{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"},
135{ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"},
136{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"},
137{ERR_PACK(ERR_LIB_DSA,0,0) ,"dsa routines"},
138{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"},
139{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"},
140{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuration file routines"},
141{ERR_PACK(ERR_LIB_CRYPTO,0,0) ,"common libcrypto routines"},
142{ERR_PACK(ERR_LIB_EC,0,0) ,"elliptic curve routines"},
143{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"},
144{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
145{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
146{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
147{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
148{ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"},
149{ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"},
150{ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"},
151{ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"},
152{ERR_PACK(ERR_LIB_FIPS,0,0) ,"FIPS routines"},
153{0,NULL},
154 };
155
156static ERR_STRING_DATA ERR_str_functs[]=
157 {
158 {ERR_PACK(0,SYS_F_FOPEN,0), "fopen"},
159 {ERR_PACK(0,SYS_F_CONNECT,0), "connect"},
160 {ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"},
161 {ERR_PACK(0,SYS_F_SOCKET,0), "socket"},
162 {ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"},
163 {ERR_PACK(0,SYS_F_BIND,0), "bind"},
164 {ERR_PACK(0,SYS_F_LISTEN,0), "listen"},
165 {ERR_PACK(0,SYS_F_ACCEPT,0), "accept"},
166#ifdef OPENSSL_SYS_WINDOWS
167 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
168#endif
169 {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
170 {ERR_PACK(0,SYS_F_FREAD,0), "fread"},
171 {ERR_PACK(0,SYS_F_GETADDRINFO,0), "getaddrinfo"},
172 {0,NULL},
173 };
174
175static ERR_STRING_DATA ERR_str_reasons[]=
176 {
177{ERR_R_SYS_LIB ,"system lib"},
178{ERR_R_BN_LIB ,"BN lib"},
179{ERR_R_RSA_LIB ,"RSA lib"},
180{ERR_R_DH_LIB ,"DH lib"},
181{ERR_R_EVP_LIB ,"EVP lib"},
182{ERR_R_BUF_LIB ,"BUF lib"},
183{ERR_R_OBJ_LIB ,"OBJ lib"},
184{ERR_R_PEM_LIB ,"PEM lib"},
185{ERR_R_DSA_LIB ,"DSA lib"},
186{ERR_R_X509_LIB ,"X509 lib"},
187{ERR_R_ASN1_LIB ,"ASN1 lib"},
188{ERR_R_CONF_LIB ,"CONF lib"},
189{ERR_R_CRYPTO_LIB ,"CRYPTO lib"},
190{ERR_R_EC_LIB ,"EC lib"},
191{ERR_R_SSL_LIB ,"SSL lib"},
192{ERR_R_BIO_LIB ,"BIO lib"},
193{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
194{ERR_R_X509V3_LIB ,"X509V3 lib"},
195{ERR_R_PKCS12_LIB ,"PKCS12 lib"},
196{ERR_R_RAND_LIB ,"RAND lib"},
197{ERR_R_DSO_LIB ,"DSO lib"},
198{ERR_R_ENGINE_LIB ,"ENGINE lib"},
199{ERR_R_OCSP_LIB ,"OCSP lib"},
200
201{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"},
202{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"},
203{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"},
204{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
205{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
206{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
207
208{ERR_R_FATAL ,"fatal"},
209{ERR_R_MALLOC_FAILURE ,"malloc failure"},
210{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
211{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
212{ERR_R_INTERNAL_ERROR ,"internal error"},
213
214{0,NULL},
215 };
216#endif
217
218
219/* Define the predeclared (but externally opaque) "ERR_FNS" type */
220struct st_ERR_FNS
221 {
222 /* Works on the "error_hash" string table */
223 LHASH *(*cb_err_get)(int create);
224 void (*cb_err_del)(void);
225 ERR_STRING_DATA *(*cb_err_get_item)(const ERR_STRING_DATA *);
226 ERR_STRING_DATA *(*cb_err_set_item)(ERR_STRING_DATA *);
227 ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *);
228 /* Works on the "thread_hash" error-state table */
229 LHASH *(*cb_thread_get)(int create);
230 void (*cb_thread_release)(LHASH **hash);
231 ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *);
232 ERR_STATE *(*cb_thread_set_item)(ERR_STATE *);
233 void (*cb_thread_del_item)(const ERR_STATE *);
234 /* Returns the next available error "library" numbers */
235 int (*cb_get_next_lib)(void);
236 };
237
238/* Predeclarations of the "err_defaults" functions */
239static LHASH *int_err_get(int create);
240static void int_err_del(void);
241static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *);
242static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *);
243static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *);
244static LHASH *int_thread_get(int create);
245static void int_thread_release(LHASH **hash);
246static ERR_STATE *int_thread_get_item(const ERR_STATE *);
247static ERR_STATE *int_thread_set_item(ERR_STATE *);
248static void int_thread_del_item(const ERR_STATE *);
249static int int_err_get_next_lib(void);
250/* The static ERR_FNS table using these defaults functions */
251static const ERR_FNS err_defaults =
252 {
253 int_err_get,
254 int_err_del,
255 int_err_get_item,
256 int_err_set_item,
257 int_err_del_item,
258 int_thread_get,
259 int_thread_release,
260 int_thread_get_item,
261 int_thread_set_item,
262 int_thread_del_item,
263 int_err_get_next_lib
264 };
265
266/* The replacable table of ERR_FNS functions we use at run-time */
267static const ERR_FNS *err_fns = NULL;
268
269/* Eg. rather than using "err_get()", use "ERRFN(err_get)()". */
270#define ERRFN(a) err_fns->cb_##a
271
272/* The internal state used by "err_defaults" - as such, the setting, reading,
273 * creating, and deleting of this data should only be permitted via the
274 * "err_defaults" functions. This way, a linked module can completely defer all
275 * ERR state operation (together with requisite locking) to the implementations
276 * and state in the loading application. */
277static LHASH *int_error_hash = NULL;
278static LHASH *int_thread_hash = NULL;
279static int int_thread_hash_references = 0;
280static int int_err_library_number= ERR_LIB_USER;
281
282/* Internal function that checks whether "err_fns" is set and if not, sets it to
283 * the defaults. */
284static void err_fns_check(void)
285 {
286 if (err_fns) return;
287
288 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
289 if (!err_fns)
290 err_fns = &err_defaults;
291 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
292 }
293
294/* API functions to get or set the underlying ERR functions. */
295
296const ERR_FNS *ERR_get_implementation(void)
297 {
298 err_fns_check();
299 return err_fns;
300 }
301
302int ERR_set_implementation(const ERR_FNS *fns)
303 {
304 int ret = 0;
305
306 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
307 /* It's too late if 'err_fns' is non-NULL. BTW: not much point setting
308 * an error is there?! */
309 if (!err_fns)
310 {
311 err_fns = fns;
312 ret = 1;
313 }
314 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
315 return ret;
316 }
317
318/* These are the callbacks provided to "lh_new()" when creating the LHASH tables
319 * internal to the "err_defaults" implementation. */
320
321/* static unsigned long err_hash(ERR_STRING_DATA *a); */
322static unsigned long err_hash(const void *a_void);
323/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); */
324static int err_cmp(const void *a_void, const void *b_void);
325/* static unsigned long pid_hash(ERR_STATE *pid); */
326static unsigned long pid_hash(const void *pid_void);
327/* static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); */
328static int pid_cmp(const void *a_void,const void *pid_void);
329static unsigned long get_error_values(int inc,int top,const char **file,int *line,
330 const char **data,int *flags);
331
332/* The internal functions used in the "err_defaults" implementation */
333
334static LHASH *int_err_get(int create)
335 {
336 LHASH *ret = NULL;
337
338 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
339 if (!int_error_hash && create)
340 {
341 CRYPTO_push_info("int_err_get (err.c)");
342 int_error_hash = lh_new(err_hash, err_cmp);
343 CRYPTO_pop_info();
344 }
345 if (int_error_hash)
346 ret = int_error_hash;
347 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
348
349 return ret;
350 }
351
352static void int_err_del(void)
353 {
354 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
355 if (int_error_hash)
356 {
357 lh_free(int_error_hash);
358 int_error_hash = NULL;
359 }
360 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
361 }
362
363static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
364 {
365 ERR_STRING_DATA *p;
366 LHASH *hash;
367
368 err_fns_check();
369 hash = ERRFN(err_get)(0);
370 if (!hash)
371 return NULL;
372
373 CRYPTO_r_lock(CRYPTO_LOCK_ERR);
374 p = (ERR_STRING_DATA *)lh_retrieve(hash, d);
375 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
376
377 return p;
378 }
379
380static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d)
381 {
382 ERR_STRING_DATA *p;
383 LHASH *hash;
384
385 err_fns_check();
386 hash = ERRFN(err_get)(1);
387 if (!hash)
388 return NULL;
389
390 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
391 p = (ERR_STRING_DATA *)lh_insert(hash, d);
392 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
393
394 return p;
395 }
396
397static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d)
398 {
399 ERR_STRING_DATA *p;
400 LHASH *hash;
401
402 err_fns_check();
403 hash = ERRFN(err_get)(0);
404 if (!hash)
405 return NULL;
406
407 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
408 p = (ERR_STRING_DATA *)lh_delete(hash, d);
409 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
410
411 return p;
412 }
413
414static LHASH *int_thread_get(int create)
415 {
416 LHASH *ret = NULL;
417
418 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
419 if (!int_thread_hash && create)
420 {
421 CRYPTO_push_info("int_thread_get (err.c)");
422 int_thread_hash = lh_new(pid_hash, pid_cmp);
423 CRYPTO_pop_info();
424 }
425 if (int_thread_hash)
426 {
427 int_thread_hash_references++;
428 ret = int_thread_hash;
429 }
430 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
431 return ret;
432 }
433
434static void int_thread_release(LHASH **hash)
435 {
436 int i;
437
438 if (hash == NULL || *hash == NULL)
439 return;
440
441 i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR);
442
443#ifdef REF_PRINT
444 fprintf(stderr,"%4d:%s\n",int_thread_hash_references,"ERR");
445#endif
446 if (i > 0) return;
447#ifdef REF_CHECK
448 if (i < 0)
449 {
450 fprintf(stderr,"int_thread_release, bad reference count\n");
451 abort(); /* ok */
452 }
453#endif
454 *hash = NULL;
455 }
456
457static ERR_STATE *int_thread_get_item(const ERR_STATE *d)
458 {
459 ERR_STATE *p;
460 LHASH *hash;
461
462 err_fns_check();
463 hash = ERRFN(thread_get)(0);
464 if (!hash)
465 return NULL;
466
467 CRYPTO_r_lock(CRYPTO_LOCK_ERR);
468 p = (ERR_STATE *)lh_retrieve(hash, d);
469 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
470
471 ERRFN(thread_release)(&hash);
472 return p;
473 }
474
475static ERR_STATE *int_thread_set_item(ERR_STATE *d)
476 {
477 ERR_STATE *p;
478 LHASH *hash;
479
480 err_fns_check();
481 hash = ERRFN(thread_get)(1);
482 if (!hash)
483 return NULL;
484
485 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
486 p = (ERR_STATE *)lh_insert(hash, d);
487 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
488
489 ERRFN(thread_release)(&hash);
490 return p;
491 }
492
493static void int_thread_del_item(const ERR_STATE *d)
494 {
495 ERR_STATE *p;
496 LHASH *hash;
497
498 err_fns_check();
499 hash = ERRFN(thread_get)(0);
500 if (!hash)
501 return;
502
503 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
504 p = (ERR_STATE *)lh_delete(hash, d);
505 /* make sure we don't leak memory */
506 if (int_thread_hash_references == 1
507 && int_thread_hash && (lh_num_items(int_thread_hash) == 0))
508 {
509 lh_free(int_thread_hash);
510 int_thread_hash = NULL;
511 }
512 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
513
514 ERRFN(thread_release)(&hash);
515 if (p)
516 ERR_STATE_free(p);
517 }
518
519static int int_err_get_next_lib(void)
520 {
521 int ret;
522
523 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
524 ret = int_err_library_number++;
525 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
526
527 return ret;
528 }
529
530
531#ifndef OPENSSL_NO_ERR
532#define NUM_SYS_STR_REASONS 127
533#define LEN_SYS_STR_REASON 32
534
535static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
536/* SYS_str_reasons is filled with copies of strerror() results at
537 * initialization.
538 * 'errno' values up to 127 should cover all usual errors,
539 * others will be displayed numerically by ERR_error_string.
540 * It is crucial that we have something for each reason code
541 * that occurs in ERR_str_reasons, or bogus reason strings
542 * will be returned for SYSerr(), which always gets an errno
543 * value and never one of those 'standard' reason codes. */
544
545static void build_SYS_str_reasons()
546 {
547 /* OPENSSL_malloc cannot be used here, use static storage instead */
548 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
549 int i;
550 static int init = 1;
551
552 if (!init) return;
553
554 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
555
556 for (i = 1; i <= NUM_SYS_STR_REASONS; i++)
557 {
558 ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
559
560 str->error = (unsigned long)i;
561 if (str->string == NULL)
562 {
563 char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]);
564 char *src = strerror(i);
565 if (src != NULL)
566 {
567 strncpy(*dest, src, sizeof *dest);
568 (*dest)[sizeof *dest - 1] = '\0';
569 str->string = *dest;
570 }
571 }
572 if (str->string == NULL)
573 str->string = "unknown";
574 }
575
576 /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
577 * as required by ERR_load_strings. */
578
579 init = 0;
580
581 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
582 }
583#endif
584
585#define err_clear_data(p,i) \
586 if (((p)->err_data[i] != NULL) && \
587 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
588 { \
589 OPENSSL_free((p)->err_data[i]); \
590 (p)->err_data[i]=NULL; \
591 } \
592 (p)->err_data_flags[i]=0;
593
594static void ERR_STATE_free(ERR_STATE *s)
595 {
596 int i;
597
598 if (s == NULL)
599 return;
600
601 for (i=0; i<ERR_NUM_ERRORS; i++)
602 {
603 err_clear_data(s,i);
604 }
605 OPENSSL_free(s);
606 }
607
608void ERR_load_ERR_strings(void)
609 {
610 err_fns_check();
611#ifndef OPENSSL_NO_ERR
612 err_load_strings(0,ERR_str_libraries);
613 err_load_strings(0,ERR_str_reasons);
614 err_load_strings(ERR_LIB_SYS,ERR_str_functs);
615 build_SYS_str_reasons();
616 err_load_strings(ERR_LIB_SYS,SYS_str_reasons);
617#endif
618 }
619
620static void err_load_strings(int lib, ERR_STRING_DATA *str)
621 {
622 while (str->error)
623 {
624 if (lib)
625 str->error|=ERR_PACK(lib,0,0);
626 ERRFN(err_set_item)(str);
627 str++;
628 }
629 }
630
631void ERR_load_strings(int lib, ERR_STRING_DATA *str)
632 {
633 ERR_load_ERR_strings();
634 err_load_strings(lib, str);
635 }
636
637void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
638 {
639 while (str->error)
640 {
641 if (lib)
642 str->error|=ERR_PACK(lib,0,0);
643 ERRFN(err_del_item)(str);
644 str++;
645 }
646 }
647
648void ERR_free_strings(void)
649 {
650 err_fns_check();
651 ERRFN(err_del)();
652 }
653
654/********************************************************/
655
656void ERR_put_error(int lib, int func, int reason, const char *file,
657 int line)
658 {
659 ERR_STATE *es;
660
661#ifdef _OSD_POSIX
662 /* In the BS2000-OSD POSIX subsystem, the compiler generates
663 * path names in the form "*POSIX(/etc/passwd)".
664 * This dirty hack strips them to something sensible.
665 * @@@ We shouldn't modify a const string, though.
666 */
667 if (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
668 char *end;
669
670 /* Skip the "*POSIX(" prefix */
671 file += sizeof("*POSIX(")-1;
672 end = &file[strlen(file)-1];
673 if (*end == ')')
674 *end = '\0';
675 /* Optional: use the basename of the path only. */
676 if ((end = strrchr(file, '/')) != NULL)
677 file = &end[1];
678 }
679#endif
680 es=ERR_get_state();
681
682 es->top=(es->top+1)%ERR_NUM_ERRORS;
683 if (es->top == es->bottom)
684 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
685 es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
686 es->err_file[es->top]=file;
687 es->err_line[es->top]=line;
688 err_clear_data(es,es->top);
689 }
690
691void ERR_clear_error(void)
692 {
693 int i;
694 ERR_STATE *es;
695
696 es=ERR_get_state();
697
698 for (i=0; i<ERR_NUM_ERRORS; i++)
699 {
700 es->err_buffer[i]=0;
701 err_clear_data(es,i);
702 es->err_file[i]=NULL;
703 es->err_line[i]= -1;
704 }
705 es->top=es->bottom=0;
706 }
707
708
709unsigned long ERR_get_error(void)
710 { return(get_error_values(1,0,NULL,NULL,NULL,NULL)); }
711
712unsigned long ERR_get_error_line(const char **file,
713 int *line)
714 { return(get_error_values(1,0,file,line,NULL,NULL)); }
715
716unsigned long ERR_get_error_line_data(const char **file, int *line,
717 const char **data, int *flags)
718 { return(get_error_values(1,0,file,line,data,flags)); }
719
720
721unsigned long ERR_peek_error(void)
722 { return(get_error_values(0,0,NULL,NULL,NULL,NULL)); }
723
724unsigned long ERR_peek_error_line(const char **file, int *line)
725 { return(get_error_values(0,0,file,line,NULL,NULL)); }
726
727unsigned long ERR_peek_error_line_data(const char **file, int *line,
728 const char **data, int *flags)
729 { return(get_error_values(0,0,file,line,data,flags)); }
730
731
732unsigned long ERR_peek_last_error(void)
733 { return(get_error_values(0,1,NULL,NULL,NULL,NULL)); }
734
735unsigned long ERR_peek_last_error_line(const char **file, int *line)
736 { return(get_error_values(0,1,file,line,NULL,NULL)); }
737
738unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
739 const char **data, int *flags)
740 { return(get_error_values(0,1,file,line,data,flags)); }
741
742
743static unsigned long get_error_values(int inc, int top, const char **file, int *line,
744 const char **data, int *flags)
745 {
746 int i=0;
747 ERR_STATE *es;
748 unsigned long ret;
749
750 es=ERR_get_state();
751
752 if (inc && top)
753 {
754 if (file) *file = "";
755 if (line) *line = 0;
756 if (data) *data = "";
757 if (flags) *flags = 0;
758
759 return ERR_R_INTERNAL_ERROR;
760 }
761
762 if (es->bottom == es->top) return 0;
763 if (top)
764 i=es->top; /* last error */
765 else
766 i=(es->bottom+1)%ERR_NUM_ERRORS; /* first error */
767
768 ret=es->err_buffer[i];
769 if (inc)
770 {
771 es->bottom=i;
772 es->err_buffer[i]=0;
773 }
774
775 if ((file != NULL) && (line != NULL))
776 {
777 if (es->err_file[i] == NULL)
778 {
779 *file="NA";
780 if (line != NULL) *line=0;
781 }
782 else
783 {
784 *file=es->err_file[i];
785 if (line != NULL) *line=es->err_line[i];
786 }
787 }
788
789 if (data == NULL)
790 {
791 if (inc)
792 {
793 err_clear_data(es, i);
794 }
795 }
796 else
797 {
798 if (es->err_data[i] == NULL)
799 {
800 *data="";
801 if (flags != NULL) *flags=0;
802 }
803 else
804 {
805 *data=es->err_data[i];
806 if (flags != NULL) *flags=es->err_data_flags[i];
807 }
808 }
809 return ret;
810 }
811
812void ERR_error_string_n(unsigned long e, char *buf, size_t len)
813 {
814 char lsbuf[64], fsbuf[64], rsbuf[64];
815 const char *ls,*fs,*rs;
816 unsigned long l,f,r;
817
818 l=ERR_GET_LIB(e);
819 f=ERR_GET_FUNC(e);
820 r=ERR_GET_REASON(e);
821
822 ls=ERR_lib_error_string(e);
823 fs=ERR_func_error_string(e);
824 rs=ERR_reason_error_string(e);
825
826 if (ls == NULL)
827 BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l);
828 if (fs == NULL)
829 BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f);
830 if (rs == NULL)
831 BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
832
833 BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf,
834 fs?fs:fsbuf, rs?rs:rsbuf);
835 if (strlen(buf) == len-1)
836 {
837 /* output may be truncated; make sure we always have 5
838 * colon-separated fields, i.e. 4 colons ... */
839#define NUM_COLONS 4
840 if (len > NUM_COLONS) /* ... if possible */
841 {
842 int i;
843 char *s = buf;
844
845 for (i = 0; i < NUM_COLONS; i++)
846 {
847 char *colon = strchr(s, ':');
848 if (colon == NULL || colon > &buf[len-1] - NUM_COLONS + i)
849 {
850 /* set colon no. i at last possible position
851 * (buf[len-1] is the terminating 0)*/
852 colon = &buf[len-1] - NUM_COLONS + i;
853 *colon = ':';
854 }
855 s = colon + 1;
856 }
857 }
858 }
859 }
860
861/* BAD for multi-threading: uses a local buffer if ret == NULL */
862/* ERR_error_string_n should be used instead for ret != NULL
863 * as ERR_error_string cannot know how large the buffer is */
864char *ERR_error_string(unsigned long e, char *ret)
865 {
866 static char buf[256];
867
868 if (ret == NULL) ret=buf;
869 ERR_error_string_n(e, ret, 256);
870
871 return ret;
872 }
873
874LHASH *ERR_get_string_table(void)
875 {
876 err_fns_check();
877 return ERRFN(err_get)(0);
878 }
879
880LHASH *ERR_get_err_state_table(void)
881 {
882 err_fns_check();
883 return ERRFN(thread_get)(0);
884 }
885
886void ERR_release_err_state_table(LHASH **hash)
887 {
888 err_fns_check();
889 ERRFN(thread_release)(hash);
890 }
891
892const char *ERR_lib_error_string(unsigned long e)
893 {
894 ERR_STRING_DATA d,*p;
895 unsigned long l;
896
897 err_fns_check();
898 l=ERR_GET_LIB(e);
899 d.error=ERR_PACK(l,0,0);
900 p=ERRFN(err_get_item)(&d);
901 return((p == NULL)?NULL:p->string);
902 }
903
904const char *ERR_func_error_string(unsigned long e)
905 {
906 ERR_STRING_DATA d,*p;
907 unsigned long l,f;
908
909 err_fns_check();
910 l=ERR_GET_LIB(e);
911 f=ERR_GET_FUNC(e);
912 d.error=ERR_PACK(l,f,0);
913 p=ERRFN(err_get_item)(&d);
914 return((p == NULL)?NULL:p->string);
915 }
916
917const char *ERR_reason_error_string(unsigned long e)
918 {
919 ERR_STRING_DATA d,*p=NULL;
920 unsigned long l,r;
921
922 err_fns_check();
923 l=ERR_GET_LIB(e);
924 r=ERR_GET_REASON(e);
925 d.error=ERR_PACK(l,0,r);
926 p=ERRFN(err_get_item)(&d);
927 if (!p)
928 {
929 d.error=ERR_PACK(0,0,r);
930 p=ERRFN(err_get_item)(&d);
931 }
932 return((p == NULL)?NULL:p->string);
933 }
934
935/* static unsigned long err_hash(ERR_STRING_DATA *a) */
936static unsigned long err_hash(const void *a_void)
937 {
938 unsigned long ret,l;
939
940 l=((ERR_STRING_DATA *)a_void)->error;
941 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
942 return(ret^ret%19*13);
943 }
944
945/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */
946static int err_cmp(const void *a_void, const void *b_void)
947 {
948 return((int)(((ERR_STRING_DATA *)a_void)->error -
949 ((ERR_STRING_DATA *)b_void)->error));
950 }
951
952/* static unsigned long pid_hash(ERR_STATE *a) */
953static unsigned long pid_hash(const void *a_void)
954 {
955 return(((ERR_STATE *)a_void)->pid*13);
956 }
957
958/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */
959static int pid_cmp(const void *a_void, const void *b_void)
960 {
961 return((int)((long)((ERR_STATE *)a_void)->pid -
962 (long)((ERR_STATE *)b_void)->pid));
963 }
964
965void ERR_remove_state(unsigned long pid)
966 {
967 ERR_STATE tmp;
968
969 err_fns_check();
970 if (pid == 0)
971 pid=(unsigned long)CRYPTO_thread_id();
972 tmp.pid=pid;
973 /* thread_del_item automatically destroys the LHASH if the number of
974 * items reaches zero. */
975 ERRFN(thread_del_item)(&tmp);
976 }
977
978ERR_STATE *ERR_get_state(void)
979 {
980 static ERR_STATE fallback;
981 ERR_STATE *ret,tmp,*tmpp=NULL;
982 int i;
983 unsigned long pid;
984
985 err_fns_check();
986 pid=(unsigned long)CRYPTO_thread_id();
987 tmp.pid=pid;
988 ret=ERRFN(thread_get_item)(&tmp);
989
990 /* ret == the error state, if NULL, make a new one */
991 if (ret == NULL)
992 {
993 ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
994 if (ret == NULL) return(&fallback);
995 ret->pid=pid;
996 ret->top=0;
997 ret->bottom=0;
998 for (i=0; i<ERR_NUM_ERRORS; i++)
999 {
1000 ret->err_data[i]=NULL;
1001 ret->err_data_flags[i]=0;
1002 }
1003 tmpp = ERRFN(thread_set_item)(ret);
1004 /* To check if insertion failed, do a get. */
1005 if (ERRFN(thread_get_item)(ret) != ret)
1006 {
1007 ERR_STATE_free(ret); /* could not insert it */
1008 return(&fallback);
1009 }
1010 /* If a race occured in this function and we came second, tmpp
1011 * is the first one that we just replaced. */
1012 if (tmpp)
1013 ERR_STATE_free(tmpp);
1014 }
1015 return ret;
1016 }
1017
1018int ERR_get_next_error_library(void)
1019 {
1020 err_fns_check();
1021 return ERRFN(get_next_lib)();
1022 }
1023
1024void ERR_set_error_data(char *data, int flags)
1025 {
1026 ERR_STATE *es;
1027 int i;
1028
1029 es=ERR_get_state();
1030
1031 i=es->top;
1032 if (i == 0)
1033 i=ERR_NUM_ERRORS-1;
1034
1035 err_clear_data(es,i);
1036 es->err_data[i]=data;
1037 es->err_data_flags[i]=flags;
1038 }
1039
1040void ERR_add_error_data(int num, ...)
1041 {
1042 va_list args;
1043 int i,n,s;
1044 char *str,*p,*a;
1045
1046 s=80;
1047 str=OPENSSL_malloc(s+1);
1048 if (str == NULL) return;
1049 str[0]='\0';
1050
1051 va_start(args, num);
1052 n=0;
1053 for (i=0; i<num; i++)
1054 {
1055 a=va_arg(args, char*);
1056 /* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
1057 if (a != NULL)
1058 {
1059 n+=strlen(a);
1060 if (n > s)
1061 {
1062 s=n+20;
1063 p=OPENSSL_realloc(str,s+1);
1064 if (p == NULL)
1065 {
1066 OPENSSL_free(str);
1067 goto err;
1068 }
1069 else
1070 str=p;
1071 }
1072 BUF_strlcat(str,a,s+1);
1073 }
1074 }
1075 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
1076
1077err:
1078 va_end(args);
1079 }
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h
deleted file mode 100644
index 2efa18866a..0000000000
--- a/src/lib/libcrypto/err/err.h
+++ /dev/null
@@ -1,302 +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#ifndef OPENSSL_NO_FP_API
63#include <stdio.h>
64#include <stdlib.h>
65#endif
66
67#ifndef OPENSSL_NO_BIO
68#include <openssl/bio.h>
69#endif
70#ifndef OPENSSL_NO_LHASH
71#include <openssl/lhash.h>
72#endif
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78#ifndef OPENSSL_NO_ERR
79#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e)
80#else
81#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0)
82#endif
83
84#include <errno.h>
85
86#define ERR_TXT_MALLOCED 0x01
87#define ERR_TXT_STRING 0x02
88
89#define ERR_NUM_ERRORS 16
90typedef struct err_state_st
91 {
92 unsigned long pid;
93 unsigned long err_buffer[ERR_NUM_ERRORS];
94 char *err_data[ERR_NUM_ERRORS];
95 int err_data_flags[ERR_NUM_ERRORS];
96 const char *err_file[ERR_NUM_ERRORS];
97 int err_line[ERR_NUM_ERRORS];
98 int top,bottom;
99 } ERR_STATE;
100
101/* library */
102#define ERR_LIB_NONE 1
103#define ERR_LIB_SYS 2
104#define ERR_LIB_BN 3
105#define ERR_LIB_RSA 4
106#define ERR_LIB_DH 5
107#define ERR_LIB_EVP 6
108#define ERR_LIB_BUF 7
109#define ERR_LIB_OBJ 8
110#define ERR_LIB_PEM 9
111#define ERR_LIB_DSA 10
112#define ERR_LIB_X509 11
113/* #define ERR_LIB_METH 12 */
114#define ERR_LIB_ASN1 13
115#define ERR_LIB_CONF 14
116#define ERR_LIB_CRYPTO 15
117#define ERR_LIB_EC 16
118#define ERR_LIB_SSL 20
119/* #define ERR_LIB_SSL23 21 */
120/* #define ERR_LIB_SSL2 22 */
121/* #define ERR_LIB_SSL3 23 */
122/* #define ERR_LIB_RSAREF 30 */
123/* #define ERR_LIB_PROXY 31 */
124#define ERR_LIB_BIO 32
125#define ERR_LIB_PKCS7 33
126#define ERR_LIB_X509V3 34
127#define ERR_LIB_PKCS12 35
128#define ERR_LIB_RAND 36
129#define ERR_LIB_DSO 37
130#define ERR_LIB_ENGINE 38
131#define ERR_LIB_OCSP 39
132#define ERR_LIB_UI 40
133#define ERR_LIB_COMP 41
134#define ERR_LIB_FIPS 42
135
136#define ERR_LIB_USER 128
137
138#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),__FILE__,__LINE__)
139#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),__FILE__,__LINE__)
140#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),__FILE__,__LINE__)
141#define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),__FILE__,__LINE__)
142#define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),__FILE__,__LINE__)
143#define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),__FILE__,__LINE__)
144#define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),__FILE__,__LINE__)
145#define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),__FILE__,__LINE__)
146#define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),__FILE__,__LINE__)
147#define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),__FILE__,__LINE__)
148#define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),__FILE__,__LINE__)
149#define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),__FILE__,__LINE__)
150#define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),__FILE__,__LINE__)
151#define ECerr(f,r) ERR_PUT_error(ERR_LIB_EC,(f),(r),__FILE__,__LINE__)
152#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),__FILE__,__LINE__)
153#define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),__FILE__,__LINE__)
154#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),__FILE__,__LINE__)
155#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),__FILE__,__LINE__)
156#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),__FILE__,__LINE__)
157#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),__FILE__,__LINE__)
158#define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),__FILE__,__LINE__)
159#define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),__FILE__,__LINE__)
160#define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),__FILE__,__LINE__)
161#define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),__FILE__,__LINE__)
162#define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),__FILE__,__LINE__)
163#define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),__FILE__,__LINE__)
164
165/* Borland C seems too stupid to be able to shift and do longs in
166 * the pre-processor :-( */
167#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)*0x1000000)| \
168 ((((unsigned long)f)&0xfffL)*0x1000)| \
169 ((((unsigned long)r)&0xfffL)))
170#define ERR_GET_LIB(l) (int)((((unsigned long)l)>>24L)&0xffL)
171#define ERR_GET_FUNC(l) (int)((((unsigned long)l)>>12L)&0xfffL)
172#define ERR_GET_REASON(l) (int)((l)&0xfffL)
173#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL)
174
175
176/* OS functions */
177#define SYS_F_FOPEN 1
178#define SYS_F_CONNECT 2
179#define SYS_F_GETSERVBYNAME 3
180#define SYS_F_SOCKET 4
181#define SYS_F_IOCTLSOCKET 5
182#define SYS_F_BIND 6
183#define SYS_F_LISTEN 7
184#define SYS_F_ACCEPT 8
185#define SYS_F_WSASTARTUP 9 /* Winsock stuff */
186#define SYS_F_OPENDIR 10
187#define SYS_F_FREAD 11
188#define SYS_F_GETADDRINFO 12
189
190
191/* reasons */
192#define ERR_R_SYS_LIB ERR_LIB_SYS /* 2 */
193#define ERR_R_BN_LIB ERR_LIB_BN /* 3 */
194#define ERR_R_RSA_LIB ERR_LIB_RSA /* 4 */
195#define ERR_R_DH_LIB ERR_LIB_DH /* 5 */
196#define ERR_R_EVP_LIB ERR_LIB_EVP /* 6 */
197#define ERR_R_BUF_LIB ERR_LIB_BUF /* 7 */
198#define ERR_R_OBJ_LIB ERR_LIB_OBJ /* 8 */
199#define ERR_R_PEM_LIB ERR_LIB_PEM /* 9 */
200#define ERR_R_DSA_LIB ERR_LIB_DSA /* 10 */
201#define ERR_R_X509_LIB ERR_LIB_X509 /* 11 */
202#define ERR_R_ASN1_LIB ERR_LIB_ASN1 /* 13 */
203#define ERR_R_CONF_LIB ERR_LIB_CONF /* 14 */
204#define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO /* 15 */
205#define ERR_R_EC_LIB ERR_LIB_EC /* 16 */
206#define ERR_R_SSL_LIB ERR_LIB_SSL /* 20 */
207#define ERR_R_BIO_LIB ERR_LIB_BIO /* 32 */
208#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 /* 33 */
209#define ERR_R_X509V3_LIB ERR_LIB_X509V3 /* 34 */
210#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12 /* 35 */
211#define ERR_R_RAND_LIB ERR_LIB_RAND /* 36 */
212#define ERR_R_DSO_LIB ERR_LIB_DSO /* 37 */
213#define ERR_R_ENGINE_LIB ERR_LIB_ENGINE /* 38 */
214#define ERR_R_OCSP_LIB ERR_LIB_OCSP /* 39 */
215#define ERR_R_UI_LIB ERR_LIB_UI /* 40 */
216#define ERR_R_COMP_LIB ERR_LIB_COMP /* 41 */
217
218#define ERR_R_NESTED_ASN1_ERROR 58
219#define ERR_R_BAD_ASN1_OBJECT_HEADER 59
220#define ERR_R_BAD_GET_ASN1_OBJECT_CALL 60
221#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE 61
222#define ERR_R_ASN1_LENGTH_MISMATCH 62
223#define ERR_R_MISSING_ASN1_EOS 63
224
225/* fatal error */
226#define ERR_R_FATAL 64
227#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
228#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
229#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
230#define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL)
231
232/* 99 is the maximum possible ERR_R_... code, higher values
233 * are reserved for the individual libraries */
234
235
236typedef struct ERR_string_data_st
237 {
238 unsigned long error;
239 const char *string;
240 } ERR_STRING_DATA;
241
242void ERR_put_error(int lib, int func,int reason,const char *file,int line);
243void ERR_set_error_data(char *data,int flags);
244
245unsigned long ERR_get_error(void);
246unsigned long ERR_get_error_line(const char **file,int *line);
247unsigned long ERR_get_error_line_data(const char **file,int *line,
248 const char **data, int *flags);
249unsigned long ERR_peek_error(void);
250unsigned long ERR_peek_error_line(const char **file,int *line);
251unsigned long ERR_peek_error_line_data(const char **file,int *line,
252 const char **data,int *flags);
253unsigned long ERR_peek_last_error(void);
254unsigned long ERR_peek_last_error_line(const char **file,int *line);
255unsigned long ERR_peek_last_error_line_data(const char **file,int *line,
256 const char **data,int *flags);
257void ERR_clear_error(void );
258char *ERR_error_string(unsigned long e,char *buf);
259void ERR_error_string_n(unsigned long e, char *buf, size_t len);
260const char *ERR_lib_error_string(unsigned long e);
261const char *ERR_func_error_string(unsigned long e);
262const char *ERR_reason_error_string(unsigned long e);
263void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
264 void *u);
265#ifndef OPENSSL_NO_FP_API
266void ERR_print_errors_fp(FILE *fp);
267#endif
268#ifndef OPENSSL_NO_BIO
269void ERR_print_errors(BIO *bp);
270void ERR_add_error_data(int num, ...);
271#endif
272void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
273void ERR_unload_strings(int lib,ERR_STRING_DATA str[]);
274void ERR_load_ERR_strings(void);
275void ERR_load_crypto_strings(void);
276void ERR_free_strings(void);
277
278void ERR_remove_state(unsigned long pid); /* if zero we look it up */
279ERR_STATE *ERR_get_state(void);
280
281#ifndef OPENSSL_NO_LHASH
282LHASH *ERR_get_string_table(void);
283LHASH *ERR_get_err_state_table(void);
284void ERR_release_err_state_table(LHASH **hash);
285#endif
286
287int ERR_get_next_error_library(void);
288
289/* This opaque type encapsulates the low-level error-state functions */
290typedef struct st_ERR_FNS ERR_FNS;
291/* An application can use this function and provide the return value to loaded
292 * modules that should use the application's ERR state/functionality */
293const ERR_FNS *ERR_get_implementation(void);
294/* A loaded module should call this function prior to any ERR operations using
295 * the application's "ERR_FNS". */
296int ERR_set_implementation(const ERR_FNS *fns);
297
298#ifdef __cplusplus
299}
300#endif
301
302#endif
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
deleted file mode 100644
index 4dc9300892..0000000000
--- a/src/lib/libcrypto/err/err_all.c
+++ /dev/null
@@ -1,137 +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#ifndef OPENSSL_NO_EC
63#include <openssl/ec.h>
64#endif
65#include <openssl/buffer.h>
66#include <openssl/bio.h>
67#ifndef OPENSSL_NO_RSA
68#include <openssl/rsa.h>
69#endif
70#ifndef OPENSSL_NO_DH
71#include <openssl/dh.h>
72#endif
73#ifndef OPENSSL_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/dso.h>
85#ifndef OPENSSL_NO_ENGINE
86#include <openssl/engine.h>
87#endif
88#include <openssl/ocsp.h>
89#include <openssl/err.h>
90#include <openssl/fips.h>
91
92void ERR_load_crypto_strings(void)
93 {
94 static int done=0;
95
96 if (done) return;
97 done=1;
98#ifndef OPENSSL_NO_ERR
99 ERR_load_ERR_strings(); /* include error strings for SYSerr */
100 ERR_load_BN_strings();
101#ifndef OPENSSL_NO_RSA
102 ERR_load_RSA_strings();
103#endif
104#ifndef OPENSSL_NO_DH
105 ERR_load_DH_strings();
106#endif
107 ERR_load_EVP_strings();
108 ERR_load_BUF_strings();
109 ERR_load_OBJ_strings();
110 ERR_load_PEM_strings();
111#ifndef OPENSSL_NO_DSA
112 ERR_load_DSA_strings();
113#endif
114 ERR_load_X509_strings();
115 ERR_load_ASN1_strings();
116 ERR_load_CONF_strings();
117 ERR_load_CRYPTO_strings();
118#ifndef OPENSSL_NO_EC
119 ERR_load_EC_strings();
120#endif
121 /* skip ERR_load_SSL_strings() because it is not in this library */
122 ERR_load_BIO_strings();
123 ERR_load_PKCS7_strings();
124 ERR_load_X509V3_strings();
125 ERR_load_PKCS12_strings();
126 ERR_load_RAND_strings();
127 ERR_load_DSO_strings();
128#ifndef OPENSSL_NO_ENGINE
129 ERR_load_ENGINE_strings();
130#endif
131 ERR_load_OCSP_strings();
132 ERR_load_UI_strings();
133#endif
134#ifdef OPENSSL_FIPS
135 ERR_load_FIPS_strings();
136#endif
137 }
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c
deleted file mode 100644
index 81e34bd6ce..0000000000
--- a/src/lib/libcrypto/err/err_prn.c
+++ /dev/null
@@ -1,106 +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
66void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
67 void *u)
68 {
69 unsigned long l;
70 char buf[256];
71 char buf2[4096];
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 ERR_error_string_n(l, buf, sizeof buf);
80 BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf,
81 file, line, (flags & ERR_TXT_STRING) ? data : "");
82 cb(buf2, strlen(buf2), u);
83 }
84 }
85
86#ifndef OPENSSL_NO_FP_API
87static int print_fp(const char *str, size_t len, void *fp)
88 {
89 return fprintf((FILE *)fp, "%s", str);
90 }
91void ERR_print_errors_fp(FILE *fp)
92 {
93 ERR_print_errors_cb(print_fp, fp);
94 }
95#endif
96
97static int print_bio(const char *str, size_t len, void *bp)
98 {
99 return BIO_write((BIO *)bp, str, len);
100 }
101void ERR_print_errors(BIO *bp)
102 {
103 ERR_print_errors_cb(print_bio, bp);
104 }
105
106
diff --git a/src/lib/libcrypto/err/openssl.ec b/src/lib/libcrypto/err/openssl.ec
deleted file mode 100644
index f8cd6937e7..0000000000
--- a/src/lib/libcrypto/err/openssl.ec
+++ /dev/null
@@ -1,82 +0,0 @@
1# crypto/err/openssl.ec
2
3# configuration file for util/mkerr.pl
4
5# files that may have to be rewritten by util/mkerr.pl
6L ERR NONE NONE
7L BN crypto/bn/bn.h crypto/bn/bn_err.c
8L RSA crypto/rsa/rsa.h crypto/rsa/rsa_err.c
9L DH crypto/dh/dh.h crypto/dh/dh_err.c
10L EVP crypto/evp/evp.h crypto/evp/evp_err.c
11L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c
12L OBJ crypto/objects/objects.h crypto/objects/obj_err.c
13L PEM crypto/pem/pem.h crypto/pem/pem_err.c
14L DSA crypto/dsa/dsa.h crypto/dsa/dsa_err.c
15L X509 crypto/x509/x509.h crypto/x509/x509_err.c
16L ASN1 crypto/asn1/asn1.h crypto/asn1/asn1_err.c
17L CONF crypto/conf/conf.h crypto/conf/conf_err.c
18L CRYPTO crypto/crypto.h crypto/cpt_err.c
19L EC crypto/ec/ec.h crypto/ec/ec_err.c
20L SSL ssl/ssl.h ssl/ssl_err.c
21L BIO crypto/bio/bio.h crypto/bio/bio_err.c
22L PKCS7 crypto/pkcs7/pkcs7.h crypto/pkcs7/pkcs7err.c
23L X509V3 crypto/x509v3/x509v3.h crypto/x509v3/v3err.c
24L PKCS12 crypto/pkcs12/pkcs12.h crypto/pkcs12/pk12err.c
25L RAND crypto/rand/rand.h crypto/rand/rand_err.c
26L DSO crypto/dso/dso.h crypto/dso/dso_err.c
27L ENGINE crypto/engine/engine.h crypto/engine/eng_err.c
28L OCSP crypto/ocsp/ocsp.h crypto/ocsp/ocsp_err.c
29L UI crypto/ui/ui.h crypto/ui/ui_err.c
30L FIPS fips-1.0/fips.h fips-1.0/fips_err.h
31
32# additional header files to be scanned for function names
33L NONE crypto/x509/x509_vfy.h NONE
34L NONE crypto/ec/ec_lcl.h NONE
35
36
37F RSAREF_F_RSA_BN2BIN
38F RSAREF_F_RSA_PRIVATE_DECRYPT
39F RSAREF_F_RSA_PRIVATE_ENCRYPT
40F RSAREF_F_RSA_PUBLIC_DECRYPT
41F RSAREF_F_RSA_PUBLIC_ENCRYPT
42#F SSL_F_CLIENT_CERTIFICATE
43
44R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
45R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
46R SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
47R SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
48R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
49R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
50R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
51R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
52R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
53R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
54R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
55R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
56R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
57R SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
58R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
59R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
60R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
61R SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
62R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
63R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
64R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
65R SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
66R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
67
68R RSAREF_R_CONTENT_ENCODING 0x0400
69R RSAREF_R_DATA 0x0401
70R RSAREF_R_DIGEST_ALGORITHM 0x0402
71R RSAREF_R_ENCODING 0x0403
72R RSAREF_R_KEY 0x0404
73R RSAREF_R_KEY_ENCODING 0x0405
74R RSAREF_R_LEN 0x0406
75R RSAREF_R_MODULUS_LEN 0x0407
76R RSAREF_R_NEED_RANDOM 0x0408
77R RSAREF_R_PRIVATE_KEY 0x0409
78R RSAREF_R_PUBLIC_KEY 0x040a
79R RSAREF_R_SIGNATURE 0x040b
80R RSAREF_R_SIGNATURE_ENCODING 0x040c
81R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d
82
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
deleted file mode 100644
index 33349c2f98..0000000000
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ /dev/null
@@ -1,567 +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, const char *buf, int num);
66static int b64_read(BIO *h, char *buf, int size);
67/*static int b64_puts(BIO *h, const char *str); */
68/*static int b64_gets(BIO *h, char *str, int size); */
69static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int b64_new(BIO *h);
71static int b64_free(BIO *data);
72static long b64_callback_ctrl(BIO *h,int cmd,bio_info_cb *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 *)OPENSSL_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 OPENSSL_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 OPENSSL_assert(ctx->buf_off+i < sizeof ctx->buf);
169 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
170 ret=i;
171 out+=i;
172 outl-=i;
173 ctx->buf_off+=i;
174 if (ctx->buf_len == ctx->buf_off)
175 {
176 ctx->buf_len=0;
177 ctx->buf_off=0;
178 }
179 }
180
181 /* At this point, we have room of outl bytes and an empty
182 * buffer, so we should read in some more. */
183
184 ret_code=0;
185 while (outl > 0)
186 {
187
188 if (ctx->cont <= 0)
189 break;
190
191 i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]),
192 B64_BLOCK_SIZE-ctx->tmp_len);
193
194 if (i <= 0)
195 {
196 ret_code=i;
197
198 /* Should be continue next time we are called? */
199 if (!BIO_should_retry(b->next_bio))
200 {
201 ctx->cont=i;
202 /* If buffer empty break */
203 if(ctx->tmp_len == 0)
204 break;
205 /* Fall through and process what we have */
206 else
207 i = 0;
208 }
209 /* else we retry and add more data to buffer */
210 else
211 break;
212 }
213 i+=ctx->tmp_len;
214 ctx->tmp_len = i;
215
216 /* We need to scan, a line at a time until we
217 * have a valid line if we are starting. */
218 if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL))
219 {
220 /* ctx->start=1; */
221 ctx->tmp_len=0;
222 }
223 else if (ctx->start)
224 {
225 q=p=(unsigned char *)ctx->tmp;
226 for (j=0; j<i; j++)
227 {
228 if (*(q++) != '\n') continue;
229
230 /* due to a previous very long line,
231 * we need to keep on scanning for a '\n'
232 * before we even start looking for
233 * base64 encoded stuff. */
234 if (ctx->tmp_nl)
235 {
236 p=q;
237 ctx->tmp_nl=0;
238 continue;
239 }
240
241 k=EVP_DecodeUpdate(&(ctx->base64),
242 (unsigned char *)ctx->buf,
243 &num,p,q-p);
244 if ((k <= 0) && (num == 0) && (ctx->start))
245 EVP_DecodeInit(&ctx->base64);
246 else
247 {
248 if (p != (unsigned char *)
249 &(ctx->tmp[0]))
250 {
251 i-=(p- (unsigned char *)
252 &(ctx->tmp[0]));
253 for (x=0; x < i; x++)
254 ctx->tmp[x]=p[x];
255 }
256 EVP_DecodeInit(&ctx->base64);
257 ctx->start=0;
258 break;
259 }
260 p=q;
261 }
262
263 /* we fell off the end without starting */
264 if (j == i)
265 {
266 /* Is this is one long chunk?, if so, keep on
267 * reading until a new line. */
268 if (p == (unsigned char *)&(ctx->tmp[0]))
269 {
270 /* Check buffer full */
271 if (i == B64_BLOCK_SIZE)
272 {
273 ctx->tmp_nl=1;
274 ctx->tmp_len=0;
275 }
276 }
277 else if (p != q) /* finished on a '\n' */
278 {
279 n=q-p;
280 for (ii=0; ii<n; ii++)
281 ctx->tmp[ii]=p[ii];
282 ctx->tmp_len=n;
283 }
284 /* else finished on a '\n' */
285 continue;
286 }
287 else
288 ctx->tmp_len=0;
289 }
290 /* If buffer isn't full and we can retry then
291 * restart to read in more data.
292 */
293 else if ((i < B64_BLOCK_SIZE) && (ctx->cont > 0))
294 continue;
295
296 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
297 {
298 int z,jj;
299
300 jj=(i>>2)<<2;
301 z=EVP_DecodeBlock((unsigned char *)ctx->buf,
302 (unsigned char *)ctx->tmp,jj);
303 if (jj > 2)
304 {
305 if (ctx->tmp[jj-1] == '=')
306 {
307 z--;
308 if (ctx->tmp[jj-2] == '=')
309 z--;
310 }
311 }
312 /* z is now number of output bytes and jj is the
313 * number consumed */
314 if (jj != i)
315 {
316 memcpy((unsigned char *)ctx->tmp,
317 (unsigned char *)&(ctx->tmp[jj]),i-jj);
318 ctx->tmp_len=i-jj;
319 }
320 ctx->buf_len=0;
321 if (z > 0)
322 {
323 ctx->buf_len=z;
324 i=1;
325 }
326 else
327 i=z;
328 }
329 else
330 {
331 i=EVP_DecodeUpdate(&(ctx->base64),
332 (unsigned char *)ctx->buf,&ctx->buf_len,
333 (unsigned char *)ctx->tmp,i);
334 ctx->tmp_len = 0;
335 }
336 ctx->buf_off=0;
337 if (i < 0)
338 {
339 ret_code=0;
340 ctx->buf_len=0;
341 break;
342 }
343
344 if (ctx->buf_len <= outl)
345 i=ctx->buf_len;
346 else
347 i=outl;
348
349 memcpy(out,ctx->buf,i);
350 ret+=i;
351 ctx->buf_off=i;
352 if (ctx->buf_off == ctx->buf_len)
353 {
354 ctx->buf_len=0;
355 ctx->buf_off=0;
356 }
357 outl-=i;
358 out+=i;
359 }
360 BIO_clear_retry_flags(b);
361 BIO_copy_next_retry(b);
362 return((ret == 0)?ret_code:ret);
363 }
364
365static int b64_write(BIO *b, const char *in, int inl)
366 {
367 int ret=inl,n,i;
368 BIO_B64_CTX *ctx;
369
370 ctx=(BIO_B64_CTX *)b->ptr;
371 BIO_clear_retry_flags(b);
372
373 if (ctx->encode != B64_ENCODE)
374 {
375 ctx->encode=B64_ENCODE;
376 ctx->buf_len=0;
377 ctx->buf_off=0;
378 ctx->tmp_len=0;
379 EVP_EncodeInit(&(ctx->base64));
380 }
381
382 n=ctx->buf_len-ctx->buf_off;
383 while (n > 0)
384 {
385 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
386 if (i <= 0)
387 {
388 BIO_copy_next_retry(b);
389 return(i);
390 }
391 ctx->buf_off+=i;
392 n-=i;
393 }
394 /* at this point all pending data has been written */
395 ctx->buf_off=0;
396 ctx->buf_len=0;
397
398 if ((in == NULL) || (inl <= 0)) return(0);
399
400 while (inl > 0)
401 {
402 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
403
404 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
405 {
406 if (ctx->tmp_len > 0)
407 {
408 n=3-ctx->tmp_len;
409 /* There's a teoretical possibility for this */
410 if (n > inl)
411 n=inl;
412 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
413 ctx->tmp_len+=n;
414 if (ctx->tmp_len < 3)
415 break;
416 ctx->buf_len=EVP_EncodeBlock(
417 (unsigned char *)ctx->buf,
418 (unsigned char *)ctx->tmp,
419 ctx->tmp_len);
420 /* Since we're now done using the temporary
421 buffer, the length should be 0'd */
422 ctx->tmp_len=0;
423 }
424 else
425 {
426 if (n < 3)
427 {
428 memcpy(&(ctx->tmp[0]),in,n);
429 ctx->tmp_len=n;
430 break;
431 }
432 n-=n%3;
433 ctx->buf_len=EVP_EncodeBlock(
434 (unsigned char *)ctx->buf,
435 (unsigned char *)in,n);
436 }
437 }
438 else
439 {
440 EVP_EncodeUpdate(&(ctx->base64),
441 (unsigned char *)ctx->buf,&ctx->buf_len,
442 (unsigned char *)in,n);
443 }
444 inl-=n;
445 in+=n;
446
447 ctx->buf_off=0;
448 n=ctx->buf_len;
449 while (n > 0)
450 {
451 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
452 if (i <= 0)
453 {
454 BIO_copy_next_retry(b);
455 return((ret == 0)?i:ret);
456 }
457 n-=i;
458 ctx->buf_off+=i;
459 }
460 ctx->buf_len=0;
461 ctx->buf_off=0;
462 }
463 return(ret);
464 }
465
466static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
467 {
468 BIO_B64_CTX *ctx;
469 long ret=1;
470 int i;
471
472 ctx=(BIO_B64_CTX *)b->ptr;
473
474 switch (cmd)
475 {
476 case BIO_CTRL_RESET:
477 ctx->cont=1;
478 ctx->start=1;
479 ctx->encode=B64_NONE;
480 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
481 break;
482 case BIO_CTRL_EOF: /* More to read */
483 if (ctx->cont <= 0)
484 ret=1;
485 else
486 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
487 break;
488 case BIO_CTRL_WPENDING: /* More to write in buffer */
489 ret=ctx->buf_len-ctx->buf_off;
490 if ((ret == 0) && (ctx->encode != B64_NONE)
491 && (ctx->base64.num != 0))
492 ret=1;
493 else if (ret <= 0)
494 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
495 break;
496 case BIO_CTRL_PENDING: /* More to read in buffer */
497 ret=ctx->buf_len-ctx->buf_off;
498 if (ret <= 0)
499 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
500 break;
501 case BIO_CTRL_FLUSH:
502 /* do a final write */
503again:
504 while (ctx->buf_len != ctx->buf_off)
505 {
506 i=b64_write(b,NULL,0);
507 if (i < 0)
508 return i;
509 }
510 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
511 {
512 if (ctx->tmp_len != 0)
513 {
514 ctx->buf_len=EVP_EncodeBlock(
515 (unsigned char *)ctx->buf,
516 (unsigned char *)ctx->tmp,
517 ctx->tmp_len);
518 ctx->buf_off=0;
519 ctx->tmp_len=0;
520 goto again;
521 }
522 }
523 else if (ctx->encode != B64_NONE && ctx->base64.num != 0)
524 {
525 ctx->buf_off=0;
526 EVP_EncodeFinal(&(ctx->base64),
527 (unsigned char *)ctx->buf,
528 &(ctx->buf_len));
529 /* push out the bytes */
530 goto again;
531 }
532 /* Finally flush the underlying BIO */
533 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
534 break;
535
536 case BIO_C_DO_STATE_MACHINE:
537 BIO_clear_retry_flags(b);
538 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
539 BIO_copy_next_retry(b);
540 break;
541
542 case BIO_CTRL_DUP:
543 break;
544 case BIO_CTRL_INFO:
545 case BIO_CTRL_GET:
546 case BIO_CTRL_SET:
547 default:
548 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
549 break;
550 }
551 return(ret);
552 }
553
554static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
555 {
556 long ret=1;
557
558 if (b->next_bio == NULL) return(0);
559 switch (cmd)
560 {
561 default:
562 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
563 break;
564 }
565 return(ret);
566 }
567
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
deleted file mode 100644
index b8cda1a9f0..0000000000
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ /dev/null
@@ -1,426 +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, const char *buf, int num);
66static int enc_read(BIO *h, char *buf, int size);
67/*static int enc_puts(BIO *h, const char *str); */
68/*static int enc_gets(BIO *h, char *str, int size); */
69static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int enc_new(BIO *h);
71static int enc_free(BIO *data);
72static long enc_callback_ctrl(BIO *h, int cmd, bio_info_cb *fps);
73#define ENC_BLOCK_SIZE (1024*4)
74#define BUF_OFFSET (EVP_MAX_BLOCK_LENGTH*2)
75
76typedef struct enc_struct
77 {
78 int buf_len;
79 int buf_off;
80 int cont; /* <= 0 when finished */
81 int finished;
82 int ok; /* bad decrypt */
83 EVP_CIPHER_CTX cipher;
84 /* buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate
85 * can return up to a block more data than is presented to it
86 */
87 char buf[ENC_BLOCK_SIZE+BUF_OFFSET+2];
88 } BIO_ENC_CTX;
89
90static BIO_METHOD methods_enc=
91 {
92 BIO_TYPE_CIPHER,"cipher",
93 enc_write,
94 enc_read,
95 NULL, /* enc_puts, */
96 NULL, /* enc_gets, */
97 enc_ctrl,
98 enc_new,
99 enc_free,
100 enc_callback_ctrl,
101 };
102
103BIO_METHOD *BIO_f_cipher(void)
104 {
105 return(&methods_enc);
106 }
107
108static int enc_new(BIO *bi)
109 {
110 BIO_ENC_CTX *ctx;
111
112 ctx=(BIO_ENC_CTX *)OPENSSL_malloc(sizeof(BIO_ENC_CTX));
113 if (ctx == NULL) return(0);
114 EVP_CIPHER_CTX_init(&ctx->cipher);
115
116 ctx->buf_len=0;
117 ctx->buf_off=0;
118 ctx->cont=1;
119 ctx->finished=0;
120 ctx->ok=1;
121
122 bi->init=0;
123 bi->ptr=(char *)ctx;
124 bi->flags=0;
125 return(1);
126 }
127
128static int enc_free(BIO *a)
129 {
130 BIO_ENC_CTX *b;
131
132 if (a == NULL) return(0);
133 b=(BIO_ENC_CTX *)a->ptr;
134 EVP_CIPHER_CTX_cleanup(&(b->cipher));
135 OPENSSL_cleanse(a->ptr,sizeof(BIO_ENC_CTX));
136 OPENSSL_free(a->ptr);
137 a->ptr=NULL;
138 a->init=0;
139 a->flags=0;
140 return(1);
141 }
142
143static int enc_read(BIO *b, char *out, int outl)
144 {
145 int ret=0,i;
146 BIO_ENC_CTX *ctx;
147
148 if (out == NULL) return(0);
149 ctx=(BIO_ENC_CTX *)b->ptr;
150
151 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
152
153 /* First check if there are bytes decoded/encoded */
154 if (ctx->buf_len > 0)
155 {
156 i=ctx->buf_len-ctx->buf_off;
157 if (i > outl) i=outl;
158 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
159 ret=i;
160 out+=i;
161 outl-=i;
162 ctx->buf_off+=i;
163 if (ctx->buf_len == ctx->buf_off)
164 {
165 ctx->buf_len=0;
166 ctx->buf_off=0;
167 }
168 }
169
170 /* At this point, we have room of outl bytes and an empty
171 * buffer, so we should read in some more. */
172
173 while (outl > 0)
174 {
175 if (ctx->cont <= 0) break;
176
177 /* read in at IV offset, read the EVP_Cipher
178 * documentation about why */
179 i=BIO_read(b->next_bio,&(ctx->buf[BUF_OFFSET]),ENC_BLOCK_SIZE);
180
181 if (i <= 0)
182 {
183 /* Should be continue next time we are called? */
184 if (!BIO_should_retry(b->next_bio))
185 {
186 ctx->cont=i;
187 i=EVP_CipherFinal_ex(&(ctx->cipher),
188 (unsigned char *)ctx->buf,
189 &(ctx->buf_len));
190 ctx->ok=i;
191 ctx->buf_off=0;
192 }
193 else
194 {
195 ret=(ret == 0)?i:ret;
196 break;
197 }
198 }
199 else
200 {
201 EVP_CipherUpdate(&(ctx->cipher),
202 (unsigned char *)ctx->buf,&ctx->buf_len,
203 (unsigned char *)&(ctx->buf[BUF_OFFSET]),i);
204 ctx->cont=1;
205 /* Note: it is possible for EVP_CipherUpdate to
206 * decrypt zero bytes because this is or looks like
207 * the final block: if this happens we should retry
208 * and either read more data or decrypt the final
209 * block
210 */
211 if(ctx->buf_len == 0) continue;
212 }
213
214 if (ctx->buf_len <= outl)
215 i=ctx->buf_len;
216 else
217 i=outl;
218 if (i <= 0) break;
219 memcpy(out,ctx->buf,i);
220 ret+=i;
221 ctx->buf_off=i;
222 outl-=i;
223 out+=i;
224 }
225
226 BIO_clear_retry_flags(b);
227 BIO_copy_next_retry(b);
228 return((ret == 0)?ctx->cont:ret);
229 }
230
231static int enc_write(BIO *b, const char *in, int inl)
232 {
233 int ret=0,n,i;
234 BIO_ENC_CTX *ctx;
235
236 ctx=(BIO_ENC_CTX *)b->ptr;
237 ret=inl;
238
239 BIO_clear_retry_flags(b);
240 n=ctx->buf_len-ctx->buf_off;
241 while (n > 0)
242 {
243 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
244 if (i <= 0)
245 {
246 BIO_copy_next_retry(b);
247 return(i);
248 }
249 ctx->buf_off+=i;
250 n-=i;
251 }
252 /* at this point all pending data has been written */
253
254 if ((in == NULL) || (inl <= 0)) return(0);
255
256 ctx->buf_off=0;
257 while (inl > 0)
258 {
259 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
260 EVP_CipherUpdate(&(ctx->cipher),
261 (unsigned char *)ctx->buf,&ctx->buf_len,
262 (unsigned char *)in,n);
263 inl-=n;
264 in+=n;
265
266 ctx->buf_off=0;
267 n=ctx->buf_len;
268 while (n > 0)
269 {
270 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
271 if (i <= 0)
272 {
273 BIO_copy_next_retry(b);
274 return (ret == inl) ? i : ret - inl;
275 }
276 n-=i;
277 ctx->buf_off+=i;
278 }
279 ctx->buf_len=0;
280 ctx->buf_off=0;
281 }
282 BIO_copy_next_retry(b);
283 return(ret);
284 }
285
286static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
287 {
288 BIO *dbio;
289 BIO_ENC_CTX *ctx,*dctx;
290 long ret=1;
291 int i;
292 EVP_CIPHER_CTX **c_ctx;
293
294 ctx=(BIO_ENC_CTX *)b->ptr;
295
296 switch (cmd)
297 {
298 case BIO_CTRL_RESET:
299 ctx->ok=1;
300 ctx->finished=0;
301 EVP_CipherInit_ex(&(ctx->cipher),NULL,NULL,NULL,NULL,
302 ctx->cipher.encrypt);
303 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
304 break;
305 case BIO_CTRL_EOF: /* More to read */
306 if (ctx->cont <= 0)
307 ret=1;
308 else
309 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
310 break;
311 case BIO_CTRL_WPENDING:
312 ret=ctx->buf_len-ctx->buf_off;
313 if (ret <= 0)
314 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
315 break;
316 case BIO_CTRL_PENDING: /* More to read in buffer */
317 ret=ctx->buf_len-ctx->buf_off;
318 if (ret <= 0)
319 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
320 break;
321 case BIO_CTRL_FLUSH:
322 /* do a final write */
323again:
324 while (ctx->buf_len != ctx->buf_off)
325 {
326 i=enc_write(b,NULL,0);
327 if (i < 0)
328 return i;
329 }
330
331 if (!ctx->finished)
332 {
333 ctx->finished=1;
334 ctx->buf_off=0;
335 ret=EVP_CipherFinal_ex(&(ctx->cipher),
336 (unsigned char *)ctx->buf,
337 &(ctx->buf_len));
338 ctx->ok=(int)ret;
339 if (ret <= 0) break;
340
341 /* push out the bytes */
342 goto again;
343 }
344
345 /* Finally flush the underlying BIO */
346 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
347 break;
348 case BIO_C_GET_CIPHER_STATUS:
349 ret=(long)ctx->ok;
350 break;
351 case BIO_C_DO_STATE_MACHINE:
352 BIO_clear_retry_flags(b);
353 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
354 BIO_copy_next_retry(b);
355 break;
356 case BIO_C_GET_CIPHER_CTX:
357 c_ctx=(EVP_CIPHER_CTX **)ptr;
358 (*c_ctx)= &(ctx->cipher);
359 b->init=1;
360 break;
361 case BIO_CTRL_DUP:
362 dbio=(BIO *)ptr;
363 dctx=(BIO_ENC_CTX *)dbio->ptr;
364 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
365 dbio->init=1;
366 break;
367 default:
368 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
369 break;
370 }
371 return(ret);
372 }
373
374static long enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
375 {
376 long ret=1;
377
378 if (b->next_bio == NULL) return(0);
379 switch (cmd)
380 {
381 default:
382 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
383 break;
384 }
385 return(ret);
386 }
387
388/*
389void BIO_set_cipher_ctx(b,c)
390BIO *b;
391EVP_CIPHER_ctx *c;
392 {
393 if (b == NULL) return;
394
395 if ((b->callback != NULL) &&
396 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
397 return;
398
399 b->init=1;
400 ctx=(BIO_ENC_CTX *)b->ptr;
401 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
402
403 if (b->callback != NULL)
404 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
405 }
406*/
407
408void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
409 unsigned char *i, int e)
410 {
411 BIO_ENC_CTX *ctx;
412
413 if (b == NULL) return;
414
415 if ((b->callback != NULL) &&
416 (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0))
417 return;
418
419 b->init=1;
420 ctx=(BIO_ENC_CTX *)b->ptr;
421 EVP_CipherInit_ex(&(ctx->cipher),c,NULL, k,i,e);
422
423 if (b->callback != NULL)
424 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);
425 }
426
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
deleted file mode 100644
index f4aa41ac4b..0000000000
--- a/src/lib/libcrypto/evp/bio_md.c
+++ /dev/null
@@ -1,264 +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 const *buf, int num);
69static int md_read(BIO *h, char *buf, int size);
70/*static int md_puts(BIO *h, const char *str); */
71static int md_gets(BIO *h, char *str, int size);
72static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2);
73static int md_new(BIO *h);
74static int md_free(BIO *data);
75static long md_callback_ctrl(BIO *h,int cmd,bio_info_cb *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_create();
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 EVP_MD_CTX_destroy(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=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, const 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=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, void *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=b->ptr;
174
175 switch (cmd)
176 {
177 case BIO_CTRL_RESET:
178 if (b->init)
179 ret = EVP_DigestInit_ex(ctx,ctx->digest, NULL);
180 else
181 ret=0;
182 if (ret > 0)
183 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
184 break;
185 case BIO_C_GET_MD:
186 if (b->init)
187 {
188 ppmd=ptr;
189 *ppmd=ctx->digest;
190 }
191 else
192 ret=0;
193 break;
194 case BIO_C_GET_MD_CTX:
195 pctx=ptr;
196 *pctx=ctx;
197 break;
198 case BIO_C_SET_MD_CTX:
199 if (b->init)
200 b->ptr=ptr;
201 else
202 ret=0;
203 break;
204 case BIO_C_DO_STATE_MACHINE:
205 BIO_clear_retry_flags(b);
206 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
207 BIO_copy_next_retry(b);
208 break;
209
210 case BIO_C_SET_MD:
211 md=ptr;
212 ret = EVP_DigestInit_ex(ctx,md, NULL);
213 if (ret > 0)
214 b->init=1;
215 break;
216 case BIO_CTRL_DUP:
217 dbio=ptr;
218 dctx=dbio->ptr;
219 EVP_MD_CTX_copy_ex(dctx,ctx);
220 b->init=1;
221 break;
222 default:
223 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
224 break;
225 }
226 return(ret);
227 }
228
229static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *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 md_gets(BIO *bp, char *buf, int size)
244 {
245 EVP_MD_CTX *ctx;
246 unsigned int ret;
247
248
249 ctx=bp->ptr;
250 if (size < ctx->digest->md_size)
251 return(0);
252 EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret);
253 return((int)ret);
254 }
255
256/*
257static int md_puts(bp,str)
258BIO *bp;
259char *str;
260 {
261 return(-1);
262 }
263*/
264
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
deleted file mode 100644
index fa60a73ead..0000000000
--- a/src/lib/libcrypto/evp/c_all.c
+++ /dev/null
@@ -1,84 +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#ifndef OPENSSL_NO_ENGINE
63#include <openssl/engine.h>
64#endif
65
66#if 0
67#undef OpenSSL_add_all_algorithms
68
69void OpenSSL_add_all_algorithms(void)
70 {
71 OPENSSL_add_all_algorithms_noconf();
72 }
73#endif
74
75void OPENSSL_add_all_algorithms_noconf(void)
76 {
77 OpenSSL_add_all_ciphers();
78 OpenSSL_add_all_digests();
79#ifndef OPENSSL_NO_ENGINE
80# if defined(__OpenBSD__) || defined(__FreeBSD__)
81 ENGINE_setup_bsd_cryptodev();
82# endif
83#endif
84 }
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
deleted file mode 100644
index f21c63842c..0000000000
--- a/src/lib/libcrypto/evp/digest.c
+++ /dev/null
@@ -1,379 +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 * Copyright (c) 1998-2001 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 "cryptlib.h"
114#include <openssl/objects.h>
115#include <openssl/evp.h>
116#ifndef OPENSSL_NO_ENGINE
117#include <openssl/engine.h>
118#endif
119
120void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
121 {
122 memset(ctx,'\0',sizeof *ctx);
123 }
124
125EVP_MD_CTX *EVP_MD_CTX_create(void)
126 {
127 EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
128
129 EVP_MD_CTX_init(ctx);
130
131 return ctx;
132 }
133
134int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
135 {
136 EVP_MD_CTX_init(ctx);
137 return EVP_DigestInit_ex(ctx, type, NULL);
138 }
139
140#ifdef OPENSSL_FIPS
141
142/* The purpose of these is to trap programs that attempt to use non FIPS
143 * algorithms in FIPS mode and ignore the errors.
144 */
145
146static int bad_init(EVP_MD_CTX *ctx)
147 { FIPS_ERROR_IGNORED("Digest init"); return 0;}
148
149static int bad_update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
150 { FIPS_ERROR_IGNORED("Digest update"); return 0;}
151
152static int bad_final(EVP_MD_CTX *ctx,unsigned char *md)
153 { FIPS_ERROR_IGNORED("Digest Final"); return 0;}
154
155static const EVP_MD bad_md =
156 {
157 0,
158 0,
159 0,
160 0,
161 bad_init,
162 bad_update,
163 bad_final,
164 NULL,
165 NULL,
166 NULL,
167 0,
168 {0,0,0,0},
169 };
170
171#endif
172
173int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
174 {
175 EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
176#ifndef OPENSSL_NO_ENGINE
177 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
178 * so this context may already have an ENGINE! Try to avoid releasing
179 * the previous handle, re-querying for an ENGINE, and having a
180 * reinitialisation, when it may all be unecessary. */
181 if (ctx->engine && ctx->digest && (!type ||
182 (type && (type->type == ctx->digest->type))))
183 goto skip_to_init;
184 if (type)
185 {
186 /* Ensure an ENGINE left lying around from last time is cleared
187 * (the previous check attempted to avoid this if the same
188 * ENGINE and EVP_MD could be used). */
189 if(ctx->engine)
190 ENGINE_finish(ctx->engine);
191 if(impl)
192 {
193 if (!ENGINE_init(impl))
194 {
195 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_INITIALIZATION_ERROR);
196 return 0;
197 }
198 }
199 else
200 /* Ask if an ENGINE is reserved for this job */
201 impl = ENGINE_get_digest_engine(type->type);
202 if(impl)
203 {
204 /* There's an ENGINE for this job ... (apparently) */
205 const EVP_MD *d = ENGINE_get_digest(impl, type->type);
206 if(!d)
207 {
208 /* Same comment from evp_enc.c */
209 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_INITIALIZATION_ERROR);
210 return 0;
211 }
212 /* We'll use the ENGINE's private digest definition */
213 type = d;
214 /* Store the ENGINE functional reference so we know
215 * 'type' came from an ENGINE and we need to release
216 * it when done. */
217 ctx->engine = impl;
218 }
219 else
220 ctx->engine = NULL;
221 }
222 else
223 if(!ctx->digest)
224 {
225 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET);
226 return 0;
227 }
228#endif
229 if (ctx->digest != type)
230 {
231#ifdef OPENSSL_FIPS
232 if (FIPS_mode())
233 {
234 if (!(type->flags & EVP_MD_FLAG_FIPS)
235 && !(ctx->flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW))
236 {
237 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_DISABLED_FOR_FIPS);
238 ctx->digest = &bad_md;
239 return 0;
240 }
241 }
242#endif
243 if (ctx->digest && ctx->digest->ctx_size)
244 OPENSSL_free(ctx->md_data);
245 ctx->digest=type;
246 if (type->ctx_size)
247 ctx->md_data=OPENSSL_malloc(type->ctx_size);
248 }
249#ifndef OPENSSL_NO_ENGINE
250skip_to_init:
251#endif
252 return ctx->digest->init(ctx);
253 }
254
255int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
256 unsigned int count)
257 {
258 return ctx->digest->update(ctx,data,(unsigned long)count);
259 }
260
261/* The caller can assume that this removes any secret data from the context */
262int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
263 {
264 int ret;
265 ret = EVP_DigestFinal_ex(ctx, md, size);
266 EVP_MD_CTX_cleanup(ctx);
267 return ret;
268 }
269
270/* The caller can assume that this removes any secret data from the context */
271int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
272 {
273 int ret;
274
275 OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);
276 ret=ctx->digest->final(ctx,md);
277 if (size != NULL)
278 *size=ctx->digest->md_size;
279 if (ctx->digest->cleanup)
280 {
281 ctx->digest->cleanup(ctx);
282 EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
283 }
284 memset(ctx->md_data,0,ctx->digest->ctx_size);
285 return ret;
286 }
287
288int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in)
289 {
290 EVP_MD_CTX_init(out);
291 return EVP_MD_CTX_copy_ex(out, in);
292 }
293
294int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
295 {
296 unsigned char *tmp_buf;
297 if ((in == NULL) || (in->digest == NULL))
298 {
299 EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
300 return 0;
301 }
302#ifndef OPENSSL_NO_ENGINE
303 /* Make sure it's safe to copy a digest context using an ENGINE */
304 if (in->engine && !ENGINE_init(in->engine))
305 {
306 EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB);
307 return 0;
308 }
309#endif
310
311 if (out->digest == in->digest)
312 {
313 tmp_buf = out->md_data;
314 EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE);
315 }
316 else tmp_buf = NULL;
317 EVP_MD_CTX_cleanup(out);
318 memcpy(out,in,sizeof *out);
319
320 if (out->digest->ctx_size)
321 {
322 if (tmp_buf) out->md_data = tmp_buf;
323 else out->md_data=OPENSSL_malloc(out->digest->ctx_size);
324 memcpy(out->md_data,in->md_data,out->digest->ctx_size);
325 }
326
327 if (out->digest->copy)
328 return out->digest->copy(out,in);
329
330 return 1;
331 }
332
333int EVP_Digest(void *data, unsigned int count,
334 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl)
335 {
336 EVP_MD_CTX ctx;
337 int ret;
338
339 EVP_MD_CTX_init(&ctx);
340 EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT);
341 ret=EVP_DigestInit_ex(&ctx, type, impl)
342 && EVP_DigestUpdate(&ctx, data, count)
343 && EVP_DigestFinal_ex(&ctx, md, size);
344 EVP_MD_CTX_cleanup(&ctx);
345
346 return ret;
347 }
348
349void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
350 {
351 EVP_MD_CTX_cleanup(ctx);
352 OPENSSL_free(ctx);
353 }
354
355/* This call frees resources associated with the context */
356int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
357 {
358 /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
359 * because sometimes only copies of the context are ever finalised.
360 */
361 if (ctx->digest && ctx->digest->cleanup
362 && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED))
363 ctx->digest->cleanup(ctx);
364 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
365 && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
366 {
367 OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size);
368 OPENSSL_free(ctx->md_data);
369 }
370#ifndef OPENSSL_NO_ENGINE
371 if(ctx->engine)
372 /* The EVP_MD we used belongs to an ENGINE, release the
373 * functional reference we held for this reason. */
374 ENGINE_finish(ctx->engine);
375#endif
376 memset(ctx,'\0',sizeof *ctx);
377
378 return 1;
379 }
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
deleted file mode 100644
index 7b67984fa1..0000000000
--- a/src/lib/libcrypto/evp/e_aes.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 */
50
51#ifndef OPENSSL_NO_AES
52#include <openssl/evp.h>
53#include <openssl/err.h>
54#include <string.h>
55#include <openssl/aes.h>
56#include "evp_locl.h"
57
58static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
59 const unsigned char *iv, int enc);
60
61typedef struct
62 {
63 AES_KEY ks;
64 } EVP_AES_KEY;
65
66#define data(ctx) EVP_C_DATA(EVP_AES_KEY,ctx)
67
68IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
69 NID_aes_128, 16, 16, 16, 128,
70 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
71 EVP_CIPHER_set_asn1_iv,
72 EVP_CIPHER_get_asn1_iv,
73 NULL)
74IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
75 NID_aes_192, 16, 24, 16, 128,
76 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
77 EVP_CIPHER_set_asn1_iv,
78 EVP_CIPHER_get_asn1_iv,
79 NULL)
80IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
81 NID_aes_256, 16, 32, 16, 128,
82 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
83 EVP_CIPHER_set_asn1_iv,
84 EVP_CIPHER_get_asn1_iv,
85 NULL)
86
87#define IMPLEMENT_AES_CFBR(ksize,cbits,flags) IMPLEMENT_CFBR(aes,AES,EVP_AES_KEY,ks,ksize,cbits,16,flags)
88
89IMPLEMENT_AES_CFBR(128,1,EVP_CIPH_FLAG_FIPS)
90IMPLEMENT_AES_CFBR(192,1,EVP_CIPH_FLAG_FIPS)
91IMPLEMENT_AES_CFBR(256,1,EVP_CIPH_FLAG_FIPS)
92
93IMPLEMENT_AES_CFBR(128,8,EVP_CIPH_FLAG_FIPS)
94IMPLEMENT_AES_CFBR(192,8,EVP_CIPH_FLAG_FIPS)
95IMPLEMENT_AES_CFBR(256,8,EVP_CIPH_FLAG_FIPS)
96
97static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
98 const unsigned char *iv, int enc)
99 {
100 int ret;
101
102 if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE
103 || (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE
104 || enc)
105 ret=AES_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
106 else
107 ret=AES_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
108
109 if(ret < 0)
110 {
111 EVPerr(EVP_F_AES_INIT_KEY,EVP_R_AES_KEY_SETUP_FAILED);
112 return 0;
113 }
114
115 return 1;
116 }
117
118#endif
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c
deleted file mode 100644
index e74337567b..0000000000
--- a/src/lib/libcrypto/evp/e_bf.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/* crypto/evp/e_bf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_BF
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/blowfish.h>
66
67static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv, int enc);
69
70typedef struct
71 {
72 BF_KEY ks;
73 } EVP_BF_KEY;
74
75#define data(ctx) EVP_C_DATA(EVP_BF_KEY,ctx)
76
77IMPLEMENT_BLOCK_CIPHER(bf, ks, BF, EVP_BF_KEY, NID_bf, 8, 16, 8, 64,
78 EVP_CIPH_VARIABLE_LENGTH, bf_init_key, NULL,
79 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
80
81static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
82 const unsigned char *iv, int enc)
83 {
84 BF_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),key);
85 return 1;
86 }
87
88#endif
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c
deleted file mode 100644
index 3400fef187..0000000000
--- a/src/lib/libcrypto/evp/e_cast.c
+++ /dev/null
@@ -1,90 +0,0 @@
1/* crypto/evp/e_cast.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_CAST
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/cast.h>
67
68static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70
71typedef struct
72 {
73 CAST_KEY ks;
74 } EVP_CAST_KEY;
75
76#define data(ctx) EVP_C_DATA(EVP_CAST_KEY,ctx)
77
78IMPLEMENT_BLOCK_CIPHER(cast5, ks, CAST, EVP_CAST_KEY,
79 NID_cast5, 8, CAST_KEY_LENGTH, 8, 64,
80 EVP_CIPH_VARIABLE_LENGTH, cast_init_key, NULL,
81 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
82
83static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
84 const unsigned char *iv, int enc)
85 {
86 CAST_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),key);
87 return 1;
88 }
89
90#endif
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c
deleted file mode 100644
index 46e2899825..0000000000
--- a/src/lib/libcrypto/evp/e_des.c
+++ /dev/null
@@ -1,154 +0,0 @@
1/* crypto/evp/e_des.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#ifndef OPENSSL_NO_DES
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65#include <openssl/des.h>
66
67static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv, int enc);
69
70/* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */
71
72static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
73 const unsigned char *in, unsigned int inl)
74{
75 BLOCK_CIPHER_ecb_loop()
76 DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), ctx->cipher_data, ctx->encrypt);
77 return 1;
78}
79
80static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
81 const unsigned char *in, unsigned int inl)
82{
83 DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num);
84 return 1;
85}
86
87static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
88 const unsigned char *in, unsigned int inl)
89{
90 DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data,
91 (DES_cblock *)ctx->iv, ctx->encrypt);
92 return 1;
93}
94
95static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97{
98 DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data,
99 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
100 return 1;
101}
102
103/* Although we have a CFB-r implementation for DES, it doesn't pack the right
104 way, so wrap it here */
105static int des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
106 const unsigned char *in, unsigned int inl)
107 {
108 unsigned int n;
109 unsigned char c[1],d[1];
110
111 for(n=0 ; n < inl ; ++n)
112 {
113 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
114 DES_cfb_encrypt(c,d,1,1,ctx->cipher_data,(DES_cblock *)ctx->iv,
115 ctx->encrypt);
116 out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
117 }
118 return 1;
119 }
120
121static int des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
122 const unsigned char *in, unsigned int inl)
123 {
124 DES_cfb_encrypt(in,out,8,inl,ctx->cipher_data,(DES_cblock *)ctx->iv,
125 ctx->encrypt);
126 return 1;
127 }
128
129BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64,
130 EVP_CIPH_FLAG_FIPS, des_init_key, NULL,
131 EVP_CIPHER_set_asn1_iv,
132 EVP_CIPHER_get_asn1_iv,
133 NULL)
134
135BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1,
136 EVP_CIPH_FLAG_FIPS,des_init_key,NULL,
137 EVP_CIPHER_set_asn1_iv,
138 EVP_CIPHER_get_asn1_iv,NULL)
139
140BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8,
141 EVP_CIPH_FLAG_FIPS,des_init_key,NULL,
142 EVP_CIPHER_set_asn1_iv,
143 EVP_CIPHER_get_asn1_iv,NULL)
144
145static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
146 const unsigned char *iv, int enc)
147 {
148 DES_cblock *deskey = (DES_cblock *)key;
149
150 DES_set_key_unchecked(deskey,ctx->cipher_data);
151 return 1;
152 }
153
154#endif
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c
deleted file mode 100644
index 677322bf02..0000000000
--- a/src/lib/libcrypto/evp/e_des3.c
+++ /dev/null
@@ -1,232 +0,0 @@
1/* crypto/evp/e_des3.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#ifndef OPENSSL_NO_DES
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65#include <openssl/des.h>
66
67static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc);
69
70static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
71 const unsigned char *iv,int enc);
72
73typedef struct
74 {
75 DES_key_schedule ks1;/* key schedule */
76 DES_key_schedule ks2;/* key schedule (for ede) */
77 DES_key_schedule ks3;/* key schedule (for ede3) */
78 } DES_EDE_KEY;
79
80#define data(ctx) ((DES_EDE_KEY *)(ctx)->cipher_data)
81
82/* Because of various casts and different args can't use IMPLEMENT_BLOCK_CIPHER */
83
84static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
85 const unsigned char *in, unsigned int inl)
86{
87 BLOCK_CIPHER_ecb_loop()
88 DES_ecb3_encrypt(in + i,out + i,
89 &data(ctx)->ks1, &data(ctx)->ks2,
90 &data(ctx)->ks3,
91 ctx->encrypt);
92 return 1;
93}
94
95static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97{
98 DES_ede3_ofb64_encrypt(in, out, (long)inl,
99 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
100 (DES_cblock *)ctx->iv, &ctx->num);
101 return 1;
102}
103
104static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
105 const unsigned char *in, unsigned int inl)
106{
107#ifdef KSSL_DEBUG
108 {
109 int i;
110 char *cp;
111 printf("des_ede_cbc_cipher(ctx=%lx, buflen=%d)\n", ctx, ctx->buf_len);
112 printf("\t iv= ");
113 for(i=0;i<8;i++)
114 printf("%02X",ctx->iv[i]);
115 printf("\n");
116 }
117#endif /* KSSL_DEBUG */
118 DES_ede3_cbc_encrypt(in, out, (long)inl,
119 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
120 (DES_cblock *)ctx->iv, ctx->encrypt);
121 return 1;
122}
123
124static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
125 const unsigned char *in, unsigned int inl)
126{
127 DES_ede3_cfb64_encrypt(in, out, (long)inl,
128 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
129 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
130 return 1;
131}
132
133/* Although we have a CFB-r implementation for 3-DES, it doesn't pack the right
134 way, so wrap it here */
135static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
136 const unsigned char *in, unsigned int inl)
137 {
138 unsigned int n;
139 unsigned char c[1],d[1];
140
141 for(n=0 ; n < inl ; ++n)
142 {
143 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
144 DES_ede3_cfb_encrypt(c,d,1,1,
145 &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
146 (DES_cblock *)ctx->iv,ctx->encrypt);
147 out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
148 }
149
150 return 1;
151 }
152
153static int des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
154 const unsigned char *in, unsigned int inl)
155 {
156 DES_ede3_cfb_encrypt(in,out,8,inl,
157 &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
158 (DES_cblock *)ctx->iv,ctx->encrypt);
159 return 1;
160 }
161
162BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
163 EVP_CIPH_FLAG_FIPS, des_ede_init_key, NULL,
164 EVP_CIPHER_set_asn1_iv,
165 EVP_CIPHER_get_asn1_iv,
166 NULL)
167
168#define des_ede3_cfb64_cipher des_ede_cfb64_cipher
169#define des_ede3_ofb_cipher des_ede_ofb_cipher
170#define des_ede3_cbc_cipher des_ede_cbc_cipher
171#define des_ede3_ecb_cipher des_ede_ecb_cipher
172
173BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 64,
174 EVP_CIPH_FLAG_FIPS, des_ede3_init_key, NULL,
175 EVP_CIPHER_set_asn1_iv,
176 EVP_CIPHER_get_asn1_iv,
177 NULL)
178
179BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,1,
180 EVP_CIPH_FLAG_FIPS, des_ede3_init_key,NULL,
181 EVP_CIPHER_set_asn1_iv,
182 EVP_CIPHER_get_asn1_iv,NULL)
183
184BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,8,
185 EVP_CIPH_FLAG_FIPS, des_ede3_init_key,NULL,
186 EVP_CIPHER_set_asn1_iv,
187 EVP_CIPHER_get_asn1_iv,NULL)
188
189static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
190 const unsigned char *iv, int enc)
191 {
192 DES_cblock *deskey = (DES_cblock *)key;
193
194 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
195 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
196 memcpy(&data(ctx)->ks3,&data(ctx)->ks1,
197 sizeof(data(ctx)->ks1));
198 return 1;
199 }
200
201static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
202 const unsigned char *iv, int enc)
203 {
204 DES_cblock *deskey = (DES_cblock *)key;
205#ifdef KSSL_DEBUG
206 {
207 int i;
208 printf("des_ede3_init_key(ctx=%lx)\n", ctx);
209 printf("\tKEY= ");
210 for(i=0;i<24;i++) printf("%02X",key[i]); printf("\n");
211 printf("\t IV= ");
212 for(i=0;i<8;i++) printf("%02X",iv[i]); printf("\n");
213 }
214#endif /* KSSL_DEBUG */
215
216 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
217 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
218 DES_set_key_unchecked(&deskey[2],&data(ctx)->ks3);
219
220 return 1;
221 }
222
223const EVP_CIPHER *EVP_des_ede(void)
224{
225 return &des_ede_ecb;
226}
227
228const EVP_CIPHER *EVP_des_ede3(void)
229{
230 return &des_ede3_ecb;
231}
232#endif
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c
deleted file mode 100644
index b9efa75ae7..0000000000
--- a/src/lib/libcrypto/evp/e_idea.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* crypto/evp/e_idea.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_IDEA
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/idea.h>
67
68static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70
71/* NB idea_ecb_encrypt doesn't take an 'encrypt' argument so we treat it as a special
72 * case
73 */
74
75static int idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
76 const unsigned char *in, unsigned int inl)
77{
78 BLOCK_CIPHER_ecb_loop()
79 idea_ecb_encrypt(in + i, out + i, ctx->cipher_data);
80 return 1;
81}
82
83/* Can't use IMPLEMENT_BLOCK_CIPHER because idea_ecb_encrypt is different */
84
85typedef struct
86 {
87 IDEA_KEY_SCHEDULE ks;
88 } EVP_IDEA_KEY;
89
90BLOCK_CIPHER_func_cbc(idea, idea, EVP_IDEA_KEY, ks)
91BLOCK_CIPHER_func_ofb(idea, idea, 64, EVP_IDEA_KEY, ks)
92BLOCK_CIPHER_func_cfb(idea, idea, 64, EVP_IDEA_KEY, ks)
93
94BLOCK_CIPHER_defs(idea, IDEA_KEY_SCHEDULE, NID_idea, 8, 16, 8, 64,
95 0, idea_init_key, NULL,
96 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
97
98static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
99 const unsigned char *iv, int enc)
100 {
101 if(!enc) {
102 if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE) enc = 1;
103 else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE) enc = 1;
104 }
105 if (enc) idea_set_encrypt_key(key,ctx->cipher_data);
106 else
107 {
108 IDEA_KEY_SCHEDULE tmp;
109
110 idea_set_encrypt_key(key,&tmp);
111 idea_set_decrypt_key(&tmp,ctx->cipher_data);
112 OPENSSL_cleanse((unsigned char *)&tmp,
113 sizeof(IDEA_KEY_SCHEDULE));
114 }
115 return 1;
116 }
117
118#endif
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c
deleted file mode 100644
index a84b0f14b1..0000000000
--- a/src/lib/libcrypto/evp/e_null.c
+++ /dev/null
@@ -1,101 +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 int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
65 const unsigned char *iv,int enc);
66static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
67 const unsigned char *in, unsigned int inl);
68static const EVP_CIPHER n_cipher=
69 {
70 NID_undef,
71 1,0,0,
72 EVP_CIPH_FLAG_FIPS,
73 null_init_key,
74 null_cipher,
75 NULL,
76 0,
77 NULL,
78 NULL,
79 NULL
80 };
81
82const EVP_CIPHER *EVP_enc_null(void)
83 {
84 return(&n_cipher);
85 }
86
87static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
88 const unsigned char *iv, int enc)
89 {
90 /* memset(&(ctx->c),0,sizeof(ctx->c));*/
91 return 1;
92 }
93
94static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
95 const unsigned char *in, unsigned int inl)
96 {
97 if (in != out)
98 memcpy((char *)out,(char *)in,(int)inl);
99 return 1;
100 }
101
diff --git a/src/lib/libcrypto/evp/e_old.c b/src/lib/libcrypto/evp/e_old.c
deleted file mode 100644
index 92dc498945..0000000000
--- a/src/lib/libcrypto/evp/e_old.c
+++ /dev/null
@@ -1,108 +0,0 @@
1/* crypto/evp/e_old.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2004.
4 */
5/* ====================================================================
6 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/evp.h>
60
61/* Define some deprecated functions, so older programs
62 don't crash and burn too quickly. On Windows and VMS,
63 these will never be used, since functions and variables
64 in shared libraries are selected by entry point location,
65 not by name. */
66
67#ifndef OPENSSL_NO_BF
68#undef EVP_bf_cfb
69const EVP_CIPHER *EVP_bf_cfb(void) { return EVP_bf_cfb64(); }
70#endif
71
72#ifndef OPENSSL_NO_DES
73#undef EVP_des_cfb
74const EVP_CIPHER *EVP_des_cfb(void) { return EVP_des_cfb64(); }
75#undef EVP_des_ede3_cfb
76const EVP_CIPHER *EVP_des_ede3_cfb(void) { return EVP_des_ede3_cfb64(); }
77#undef EVP_des_ede_cfb
78const EVP_CIPHER *EVP_des_ede_cfb(void) { return EVP_des_ede_cfb64(); }
79#endif
80
81#ifndef OPENSSL_NO_IDEA
82#undef EVP_idea_cfb
83const EVP_CIPHER *EVP_idea_cfb(void) { return EVP_idea_cfb64(); }
84#endif
85
86#ifndef OPENSSL_NO_RC2
87#undef EVP_rc2_cfb
88const EVP_CIPHER *EVP_rc2_cfb(void) { return EVP_rc2_cfb64(); }
89#endif
90
91#ifndef OPENSSL_NO_CAST
92#undef EVP_cast5_cfb
93const EVP_CIPHER *EVP_cast5_cfb(void) { return EVP_cast5_cfb64(); }
94#endif
95
96#ifndef OPENSSL_NO_RC5
97#undef EVP_rc5_32_12_16_cfb
98const EVP_CIPHER *EVP_rc5_32_12_16_cfb(void) { return EVP_rc5_32_12_16_cfb64(); }
99#endif
100
101#ifndef OPENSSL_NO_AES
102#undef EVP_aes_128_cfb
103const EVP_CIPHER *EVP_aes_128_cfb(void) { return EVP_aes_128_cfb128(); }
104#undef EVP_aes_192_cfb
105const EVP_CIPHER *EVP_aes_192_cfb(void) { return EVP_aes_192_cfb128(); }
106#undef EVP_aes_256_cfb
107const EVP_CIPHER *EVP_aes_256_cfb(void) { return EVP_aes_256_cfb128(); }
108#endif
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c
deleted file mode 100644
index d42cbfd17e..0000000000
--- a/src/lib/libcrypto/evp/e_rc2.c
+++ /dev/null
@@ -1,230 +0,0 @@
1/* crypto/evp/e_rc2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RC2
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/rc2.h>
67
68static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70static int rc2_meth_to_magic(EVP_CIPHER_CTX *ctx);
71static int rc2_magic_to_meth(int i);
72static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
73static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
74static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
75
76typedef struct
77 {
78 int key_bits; /* effective key bits */
79 RC2_KEY ks; /* key schedule */
80 } EVP_RC2_KEY;
81
82#define data(ctx) ((EVP_RC2_KEY *)(ctx)->cipher_data)
83
84IMPLEMENT_BLOCK_CIPHER(rc2, ks, RC2, EVP_RC2_KEY, NID_rc2,
85 8,
86 RC2_KEY_LENGTH, 8, 64,
87 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
88 rc2_init_key, NULL,
89 rc2_set_asn1_type_and_iv, rc2_get_asn1_type_and_iv,
90 rc2_ctrl)
91
92#define RC2_40_MAGIC 0xa0
93#define RC2_64_MAGIC 0x78
94#define RC2_128_MAGIC 0x3a
95
96static const EVP_CIPHER r2_64_cbc_cipher=
97 {
98 NID_rc2_64_cbc,
99 8,8 /* 64 bit */,8,
100 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
101 rc2_init_key,
102 rc2_cbc_cipher,
103 NULL,
104 sizeof(EVP_RC2_KEY),
105 rc2_set_asn1_type_and_iv,
106 rc2_get_asn1_type_and_iv,
107 rc2_ctrl,
108 NULL
109 };
110
111static const EVP_CIPHER r2_40_cbc_cipher=
112 {
113 NID_rc2_40_cbc,
114 8,5 /* 40 bit */,8,
115 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
116 rc2_init_key,
117 rc2_cbc_cipher,
118 NULL,
119 sizeof(EVP_RC2_KEY),
120 rc2_set_asn1_type_and_iv,
121 rc2_get_asn1_type_and_iv,
122 rc2_ctrl,
123 NULL
124 };
125
126const EVP_CIPHER *EVP_rc2_64_cbc(void)
127 {
128 return(&r2_64_cbc_cipher);
129 }
130
131const EVP_CIPHER *EVP_rc2_40_cbc(void)
132 {
133 return(&r2_40_cbc_cipher);
134 }
135
136static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
137 const unsigned char *iv, int enc)
138 {
139 RC2_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
140 key,data(ctx)->key_bits);
141 return 1;
142 }
143
144static int rc2_meth_to_magic(EVP_CIPHER_CTX *e)
145 {
146 int i;
147
148 EVP_CIPHER_CTX_ctrl(e, EVP_CTRL_GET_RC2_KEY_BITS, 0, &i);
149 if (i == 128) return(RC2_128_MAGIC);
150 else if (i == 64) return(RC2_64_MAGIC);
151 else if (i == 40) return(RC2_40_MAGIC);
152 else return(0);
153 }
154
155static int rc2_magic_to_meth(int i)
156 {
157 if (i == RC2_128_MAGIC) return 128;
158 else if (i == RC2_64_MAGIC) return 64;
159 else if (i == RC2_40_MAGIC) return 40;
160 else
161 {
162 EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE);
163 return(0);
164 }
165 }
166
167static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
168 {
169 long num=0;
170 int i=0,l;
171 int key_bits;
172 unsigned char iv[EVP_MAX_IV_LENGTH];
173
174 if (type != NULL)
175 {
176 l=EVP_CIPHER_CTX_iv_length(c);
177 OPENSSL_assert(l <= sizeof iv);
178 i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l);
179 if (i != l)
180 return(-1);
181 key_bits =rc2_magic_to_meth((int)num);
182 if (!key_bits)
183 return(-1);
184 if(i > 0) EVP_CipherInit_ex(c, NULL, NULL, NULL, iv, -1);
185 EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL);
186 EVP_CIPHER_CTX_set_key_length(c, key_bits / 8);
187 }
188 return(i);
189 }
190
191static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
192 {
193 long num;
194 int i=0,j;
195
196 if (type != NULL)
197 {
198 num=rc2_meth_to_magic(c);
199 j=EVP_CIPHER_CTX_iv_length(c);
200 i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j);
201 }
202 return(i);
203 }
204
205static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
206 {
207 switch(type)
208 {
209 case EVP_CTRL_INIT:
210 data(c)->key_bits = EVP_CIPHER_CTX_key_length(c) * 8;
211 return 1;
212
213 case EVP_CTRL_GET_RC2_KEY_BITS:
214 *(int *)ptr = data(c)->key_bits;
215 return 1;
216
217 case EVP_CTRL_SET_RC2_KEY_BITS:
218 if(arg > 0)
219 {
220 data(c)->key_bits = arg;
221 return 1;
222 }
223 return 0;
224
225 default:
226 return -1;
227 }
228 }
229
230#endif
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c
deleted file mode 100644
index 8aa70585b9..0000000000
--- a/src/lib/libcrypto/evp/e_rc4.c
+++ /dev/null
@@ -1,134 +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 OPENSSL_NO_RC4
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/rc4.h>
67
68/* FIXME: surely this is available elsewhere? */
69#define EVP_RC4_KEY_SIZE 16
70
71typedef struct
72 {
73 RC4_KEY ks; /* working key */
74 } EVP_RC4_KEY;
75
76#define data(ctx) ((EVP_RC4_KEY *)(ctx)->cipher_data)
77
78static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
79 const unsigned char *iv,int enc);
80static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
81 const unsigned char *in, unsigned int inl);
82static const EVP_CIPHER r4_cipher=
83 {
84 NID_rc4,
85 1,EVP_RC4_KEY_SIZE,0,
86 EVP_CIPH_VARIABLE_LENGTH,
87 rc4_init_key,
88 rc4_cipher,
89 NULL,
90 sizeof(EVP_RC4_KEY),
91 NULL,
92 NULL,
93 NULL
94 };
95
96static const EVP_CIPHER r4_40_cipher=
97 {
98 NID_rc4_40,
99 1,5 /* 40 bit */,0,
100 EVP_CIPH_VARIABLE_LENGTH,
101 rc4_init_key,
102 rc4_cipher,
103 NULL,
104 sizeof(EVP_RC4_KEY),
105 NULL,
106 NULL,
107 NULL
108 };
109
110const EVP_CIPHER *EVP_rc4(void)
111 {
112 return(&r4_cipher);
113 }
114
115const EVP_CIPHER *EVP_rc4_40(void)
116 {
117 return(&r4_40_cipher);
118 }
119
120static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
121 const unsigned char *iv, int enc)
122 {
123 RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
124 key);
125 return 1;
126 }
127
128static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
129 const unsigned char *in, unsigned int inl)
130 {
131 RC4(&data(ctx)->ks,inl,in,out);
132 return 1;
133 }
134#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 a6f849e93d..0000000000
--- a/src/lib/libcrypto/evp/e_xcbc_d.c
+++ /dev/null
@@ -1,122 +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 OPENSSL_NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/des.h>
65
66static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
67 const unsigned char *iv,int enc);
68static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
69 const unsigned char *in, unsigned int inl);
70
71
72typedef struct
73 {
74 DES_key_schedule ks;/* key schedule */
75 DES_cblock inw;
76 DES_cblock outw;
77 } DESX_CBC_KEY;
78
79#define data(ctx) ((DESX_CBC_KEY *)(ctx)->cipher_data)
80
81static const EVP_CIPHER d_xcbc_cipher=
82 {
83 NID_desx_cbc,
84 8,24,8,
85 EVP_CIPH_CBC_MODE,
86 desx_cbc_init_key,
87 desx_cbc_cipher,
88 NULL,
89 sizeof(DESX_CBC_KEY),
90 EVP_CIPHER_set_asn1_iv,
91 EVP_CIPHER_get_asn1_iv,
92 NULL
93 };
94
95const EVP_CIPHER *EVP_desx_cbc(void)
96 {
97 return(&d_xcbc_cipher);
98 }
99
100static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
101 const unsigned char *iv, int enc)
102 {
103 DES_cblock *deskey = (DES_cblock *)key;
104
105 DES_set_key_unchecked(deskey,&data(ctx)->ks);
106 memcpy(&data(ctx)->inw[0],&key[8],8);
107 memcpy(&data(ctx)->outw[0],&key[16],8);
108
109 return 1;
110 }
111
112static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
113 const unsigned char *in, unsigned int inl)
114 {
115 DES_xcbc_encrypt(in,out,inl,&data(ctx)->ks,
116 (DES_cblock *)&(ctx->iv[0]),
117 &data(ctx)->inw,
118 &data(ctx)->outw,
119 ctx->encrypt);
120 return 1;
121 }
122#endif
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c
deleted file mode 100644
index 33e540087d..0000000000
--- a/src/lib/libcrypto/evp/encode.c
+++ /dev/null
@@ -1,446 +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 OPENSSL_assert(ctx->length <= sizeof ctx->enc_data);
140 if ((ctx->num+inl) < ctx->length)
141 {
142 memcpy(&(ctx->enc_data[ctx->num]),in,inl);
143 ctx->num+=inl;
144 return;
145 }
146 if (ctx->num != 0)
147 {
148 i=ctx->length-ctx->num;
149 memcpy(&(ctx->enc_data[ctx->num]),in,i);
150 in+=i;
151 inl-=i;
152 j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
153 ctx->num=0;
154 out+=j;
155 *(out++)='\n';
156 *out='\0';
157 total=j+1;
158 }
159 while (inl >= ctx->length)
160 {
161 j=EVP_EncodeBlock(out,in,ctx->length);
162 in+=ctx->length;
163 inl-=ctx->length;
164 out+=j;
165 *(out++)='\n';
166 *out='\0';
167 total+=j+1;
168 }
169 if (inl != 0)
170 memcpy(&(ctx->enc_data[0]),in,inl);
171 ctx->num=inl;
172 *outl=total;
173 }
174
175void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
176 {
177 unsigned int ret=0;
178
179 if (ctx->num != 0)
180 {
181 ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num);
182 out[ret++]='\n';
183 out[ret]='\0';
184 ctx->num=0;
185 }
186 *outl=ret;
187 }
188
189int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen)
190 {
191 int i,ret=0;
192 unsigned long l;
193
194 for (i=dlen; i > 0; i-=3)
195 {
196 if (i >= 3)
197 {
198 l= (((unsigned long)f[0])<<16L)|
199 (((unsigned long)f[1])<< 8L)|f[2];
200 *(t++)=conv_bin2ascii(l>>18L);
201 *(t++)=conv_bin2ascii(l>>12L);
202 *(t++)=conv_bin2ascii(l>> 6L);
203 *(t++)=conv_bin2ascii(l );
204 }
205 else
206 {
207 l=((unsigned long)f[0])<<16L;
208 if (i == 2) l|=((unsigned long)f[1]<<8L);
209
210 *(t++)=conv_bin2ascii(l>>18L);
211 *(t++)=conv_bin2ascii(l>>12L);
212 *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L);
213 *(t++)='=';
214 }
215 ret+=4;
216 f+=3;
217 }
218
219 *t='\0';
220 return(ret);
221 }
222
223void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
224 {
225 ctx->length=30;
226 ctx->num=0;
227 ctx->line_num=0;
228 ctx->expect_nl=0;
229 }
230
231/* -1 for error
232 * 0 for last line
233 * 1 for full line
234 */
235int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
236 unsigned char *in, int inl)
237 {
238 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
239 unsigned char *d;
240
241 n=ctx->num;
242 d=ctx->enc_data;
243 ln=ctx->line_num;
244 exp_nl=ctx->expect_nl;
245
246 /* last line of input. */
247 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF)))
248 { rv=0; goto end; }
249
250 /* We parse the input data */
251 for (i=0; i<inl; i++)
252 {
253 /* If the current line is > 80 characters, scream alot */
254 if (ln >= 80) { rv= -1; goto end; }
255
256 /* Get char and put it into the buffer */
257 tmp= *(in++);
258 v=conv_ascii2bin(tmp);
259 /* only save the good data :-) */
260 if (!B64_NOT_BASE64(v))
261 {
262 OPENSSL_assert(n < sizeof ctx->enc_data);
263 d[n++]=tmp;
264 ln++;
265 }
266 else if (v == B64_ERROR)
267 {
268 rv= -1;
269 goto end;
270 }
271
272 /* have we seen a '=' which is 'definitly' the last
273 * input line. seof will point to the character that
274 * holds it. and eof will hold how many characters to
275 * chop off. */
276 if (tmp == '=')
277 {
278 if (seof == -1) seof=n;
279 eof++;
280 }
281
282 if (v == B64_CR)
283 {
284 ln = 0;
285 if (exp_nl)
286 continue;
287 }
288
289 /* eoln */
290 if (v == B64_EOLN)
291 {
292 ln=0;
293 if (exp_nl)
294 {
295 exp_nl=0;
296 continue;
297 }
298 }
299 exp_nl=0;
300
301 /* If we are at the end of input and it looks like a
302 * line, process it. */
303 if (((i+1) == inl) && (((n&3) == 0) || eof))
304 {
305 v=B64_EOF;
306 /* In case things were given us in really small
307 records (so two '=' were given in separate
308 updates), eof may contain the incorrect number
309 of ending bytes to skip, so let's redo the count */
310 eof = 0;
311 if (d[n-1] == '=') eof++;
312 if (d[n-2] == '=') eof++;
313 /* There will never be more than two '=' */
314 }
315
316 if ((v == B64_EOF && (n&3) == 0) || (n >= 64))
317 {
318 /* This is needed to work correctly on 64 byte input
319 * lines. We process the line and then need to
320 * accept the '\n' */
321 if ((v != B64_EOF) && (n >= 64)) exp_nl=1;
322 tmp2=v;
323 if (n > 0)
324 {
325 v=EVP_DecodeBlock(out,d,n);
326 if (v < 0) { rv=0; goto end; }
327 n=0;
328 ret+=(v-eof);
329 }
330 else
331 {
332 eof=1;
333 v=0;
334 }
335
336 /* This is the case where we have had a short
337 * but valid input line */
338 if ((v < ctx->length) && eof)
339 {
340 rv=0;
341 goto end;
342 }
343 else
344 ctx->length=v;
345
346 if (seof >= 0) { rv=0; goto end; }
347 out+=v;
348 }
349 }
350 rv=1;
351end:
352 *outl=ret;
353 ctx->num=n;
354 ctx->line_num=ln;
355 ctx->expect_nl=exp_nl;
356 return(rv);
357 }
358
359int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n)
360 {
361 int i,ret=0,a,b,c,d;
362 unsigned long l;
363
364 /* trim white space from the start of the line. */
365 while ((conv_ascii2bin(*f) == B64_WS) && (n > 0))
366 {
367 f++;
368 n--;
369 }
370
371 /* strip off stuff at the end of the line
372 * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */
373 while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1]))))
374 n--;
375
376 if (n%4 != 0) return(-1);
377
378 for (i=0; i<n; i+=4)
379 {
380 a=conv_ascii2bin(*(f++));
381 b=conv_ascii2bin(*(f++));
382 c=conv_ascii2bin(*(f++));
383 d=conv_ascii2bin(*(f++));
384 if ( (a & 0x80) || (b & 0x80) ||
385 (c & 0x80) || (d & 0x80))
386 return(-1);
387 l=( (((unsigned long)a)<<18L)|
388 (((unsigned long)b)<<12L)|
389 (((unsigned long)c)<< 6L)|
390 (((unsigned long)d) ));
391 *(t++)=(unsigned char)(l>>16L)&0xff;
392 *(t++)=(unsigned char)(l>> 8L)&0xff;
393 *(t++)=(unsigned char)(l )&0xff;
394 ret+=3;
395 }
396 return(ret);
397 }
398
399int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
400 {
401 int i;
402
403 *outl=0;
404 if (ctx->num != 0)
405 {
406 i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num);
407 if (i < 0) return(-1);
408 ctx->num=0;
409 *outl=i;
410 return(1);
411 }
412 else
413 return(1);
414 }
415
416#ifdef undef
417int EVP_DecodeValid(unsigned char *buf, int len)
418 {
419 int i,num=0,bad=0;
420
421 if (len == 0) return(-1);
422 while (conv_ascii2bin(*buf) == B64_WS)
423 {
424 buf++;
425 len--;
426 if (len == 0) return(-1);
427 }
428
429 for (i=len; i >= 4; i-=4)
430 {
431 if ( (conv_ascii2bin(buf[0]) >= 0x40) ||
432 (conv_ascii2bin(buf[1]) >= 0x40) ||
433 (conv_ascii2bin(buf[2]) >= 0x40) ||
434 (conv_ascii2bin(buf[3]) >= 0x40))
435 return(-1);
436 buf+=4;
437 num+=1+(buf[2] != '=')+(buf[3] != '=');
438 }
439 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN))
440 return(num);
441 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) &&
442 (conv_ascii2bin(buf[0]) == B64_EOLN))
443 return(num);
444 return(1);
445 }
446#endif
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
deleted file mode 100644
index f29e0ba8f0..0000000000
--- a/src/lib/libcrypto/evp/evp.h
+++ /dev/null
@@ -1,910 +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 OPENSSL_ALGORITHM_DEFINES
63# include <openssl/opensslconf.h>
64#else
65# define OPENSSL_ALGORITHM_DEFINES
66# include <openssl/opensslconf.h>
67# undef OPENSSL_ALGORITHM_DEFINES
68#endif
69
70#include <openssl/ossl_typ.h>
71
72#include <openssl/symhacks.h>
73
74#ifndef OPENSSL_NO_BIO
75#include <openssl/bio.h>
76#endif
77
78#ifdef OPENSSL_FIPS
79#include <openssl/fips.h>
80#endif
81
82/*
83#define EVP_RC2_KEY_SIZE 16
84#define EVP_RC4_KEY_SIZE 16
85#define EVP_BLOWFISH_KEY_SIZE 16
86#define EVP_CAST5_KEY_SIZE 16
87#define EVP_RC5_32_12_16_KEY_SIZE 16
88*/
89#define EVP_MAX_MD_SIZE 64 /* longest known SHA512 */
90#define EVP_MAX_KEY_LENGTH 32
91#define EVP_MAX_IV_LENGTH 16
92#define EVP_MAX_BLOCK_LENGTH 32
93
94#define PKCS5_SALT_LEN 8
95/* Default PKCS#5 iteration count */
96#define PKCS5_DEFAULT_ITER 2048
97
98#include <openssl/objects.h>
99
100#define EVP_PK_RSA 0x0001
101#define EVP_PK_DSA 0x0002
102#define EVP_PK_DH 0x0004
103#define EVP_PKT_SIGN 0x0010
104#define EVP_PKT_ENC 0x0020
105#define EVP_PKT_EXCH 0x0040
106#define EVP_PKS_RSA 0x0100
107#define EVP_PKS_DSA 0x0200
108#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */
109
110#define EVP_PKEY_NONE NID_undef
111#define EVP_PKEY_RSA NID_rsaEncryption
112#define EVP_PKEY_RSA2 NID_rsa
113#define EVP_PKEY_DSA NID_dsa
114#define EVP_PKEY_DSA1 NID_dsa_2
115#define EVP_PKEY_DSA2 NID_dsaWithSHA
116#define EVP_PKEY_DSA3 NID_dsaWithSHA1
117#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
118#define EVP_PKEY_DH NID_dhKeyAgreement
119
120#ifdef __cplusplus
121extern "C" {
122#endif
123
124/* Type needs to be a bit field
125 * Sub-type needs to be for variations on the method, as in, can it do
126 * arbitrary encryption.... */
127struct evp_pkey_st
128 {
129 int type;
130 int save_type;
131 int references;
132 union {
133 char *ptr;
134#ifndef OPENSSL_NO_RSA
135 struct rsa_st *rsa; /* RSA */
136#endif
137#ifndef OPENSSL_NO_DSA
138 struct dsa_st *dsa; /* DSA */
139#endif
140#ifndef OPENSSL_NO_DH
141 struct dh_st *dh; /* DH */
142#endif
143 } pkey;
144 int save_parameters;
145 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
146 } /* EVP_PKEY */;
147
148#define EVP_PKEY_MO_SIGN 0x0001
149#define EVP_PKEY_MO_VERIFY 0x0002
150#define EVP_PKEY_MO_ENCRYPT 0x0004
151#define EVP_PKEY_MO_DECRYPT 0x0008
152
153#if 0
154/* This structure is required to tie the message digest and signing together.
155 * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or
156 * oid, md and pkey.
157 * This is required because for various smart-card perform the digest and
158 * signing/verification on-board. To handle this case, the specific
159 * EVP_MD and EVP_PKEY_METHODs need to be closely associated.
160 * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it.
161 * This can either be software or a token to provide the required low level
162 * routines.
163 */
164typedef struct evp_pkey_md_st
165 {
166 int oid;
167 EVP_MD *md;
168 EVP_PKEY_METHOD *pkey;
169 } EVP_PKEY_MD;
170
171#define EVP_rsa_md2() \
172 EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\
173 EVP_rsa_pkcs1(),EVP_md2())
174#define EVP_rsa_md5() \
175 EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\
176 EVP_rsa_pkcs1(),EVP_md5())
177#define EVP_rsa_sha0() \
178 EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\
179 EVP_rsa_pkcs1(),EVP_sha())
180#define EVP_rsa_sha1() \
181 EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\
182 EVP_rsa_pkcs1(),EVP_sha1())
183#define EVP_rsa_ripemd160() \
184 EVP_PKEY_MD_add(NID_ripemd160WithRSA,\
185 EVP_rsa_pkcs1(),EVP_ripemd160())
186#define EVP_rsa_mdc2() \
187 EVP_PKEY_MD_add(NID_mdc2WithRSA,\
188 EVP_rsa_octet_string(),EVP_mdc2())
189#define EVP_dsa_sha() \
190 EVP_PKEY_MD_add(NID_dsaWithSHA,\
191 EVP_dsa(),EVP_sha())
192#define EVP_dsa_sha1() \
193 EVP_PKEY_MD_add(NID_dsaWithSHA1,\
194 EVP_dsa(),EVP_sha1())
195
196typedef struct evp_pkey_method_st
197 {
198 char *name;
199 int flags;
200 int type; /* RSA, DSA, an SSLeay specific constant */
201 int oid; /* For the pub-key type */
202 int encrypt_oid; /* pub/priv key encryption */
203
204 int (*sign)();
205 int (*verify)();
206 struct {
207 int (*set)(); /* get and/or set the underlying type */
208 int (*get)();
209 int (*encrypt)();
210 int (*decrypt)();
211 int (*i2d)();
212 int (*d2i)();
213 int (*dup)();
214 } pub,priv;
215 int (*set_asn1_parameters)();
216 int (*get_asn1_parameters)();
217 } EVP_PKEY_METHOD;
218#endif
219
220#ifndef EVP_MD
221struct env_md_st
222 {
223 int type;
224 int pkey_type;
225 int md_size;
226 unsigned long flags;
227 int (*init)(EVP_MD_CTX *ctx);
228 int (*update)(EVP_MD_CTX *ctx,const void *data,unsigned long count);
229 int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
230 int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
231 int (*cleanup)(EVP_MD_CTX *ctx);
232
233 /* FIXME: prototype these some day */
234 int (*sign)();
235 int (*verify)();
236 int required_pkey_type[5]; /*EVP_PKEY_xxx */
237 int block_size;
238 int ctx_size; /* how big does the ctx->md_data need to be */
239 } /* EVP_MD */;
240
241#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single
242 * block */
243#define EVP_MD_FLAG_FIPS 0x0400 /* Note if suitable for use in FIPS mode */
244
245#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
246
247#ifndef OPENSSL_NO_DSA
248#define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \
249 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \
250 EVP_PKEY_DSA4,0}
251#else
252#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method
253#endif
254
255#ifndef OPENSSL_NO_RSA
256#define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \
257 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
258#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \
259 RSA_sign_ASN1_OCTET_STRING, \
260 RSA_verify_ASN1_OCTET_STRING, \
261 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
262#else
263#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method
264#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method
265#endif
266
267#endif /* !EVP_MD */
268
269struct env_md_ctx_st
270 {
271 const EVP_MD *digest;
272 ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
273 unsigned long flags;
274 void *md_data;
275 } /* EVP_MD_CTX */;
276
277/* values for EVP_MD_CTX flags */
278
279#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called
280 * once only */
281#define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been
282 * cleaned */
283#define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data
284 * in EVP_MD_CTX_cleanup */
285
286#define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008 /* Allow use of non FIPS digest
287 * in FIPS mode */
288
289struct evp_cipher_st
290 {
291 int nid;
292 int block_size;
293 int key_len; /* Default value for variable length ciphers */
294 int iv_len;
295 unsigned long flags; /* Various flags */
296 int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
297 const unsigned char *iv, int enc); /* init key */
298 int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
299 const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */
300 int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
301 int ctx_size; /* how big ctx->cipher_data needs to be */
302 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
303 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
304 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
305 void *app_data; /* Application data */
306 } /* EVP_CIPHER */;
307
308/* Values for cipher flags */
309
310/* Modes for ciphers */
311
312#define EVP_CIPH_STREAM_CIPHER 0x0
313#define EVP_CIPH_ECB_MODE 0x1
314#define EVP_CIPH_CBC_MODE 0x2
315#define EVP_CIPH_CFB_MODE 0x3
316#define EVP_CIPH_OFB_MODE 0x4
317#define EVP_CIPH_MODE 0x7
318/* Set if variable length cipher */
319#define EVP_CIPH_VARIABLE_LENGTH 0x8
320/* Set if the iv handling should be done by the cipher itself */
321#define EVP_CIPH_CUSTOM_IV 0x10
322/* Set if the cipher's init() function should be called if key is NULL */
323#define EVP_CIPH_ALWAYS_CALL_INIT 0x20
324/* Call ctrl() to init cipher parameters */
325#define EVP_CIPH_CTRL_INIT 0x40
326/* Don't use standard key length function */
327#define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80
328/* Don't use standard block padding */
329#define EVP_CIPH_NO_PADDING 0x100
330/* Note if suitable for use in FIPS mode */
331#define EVP_CIPH_FLAG_FIPS 0x400
332/* Allow non FIPS cipher in FIPS mode */
333#define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x800
334
335/* ctrl() values */
336
337#define EVP_CTRL_INIT 0x0
338#define EVP_CTRL_SET_KEY_LENGTH 0x1
339#define EVP_CTRL_GET_RC2_KEY_BITS 0x2
340#define EVP_CTRL_SET_RC2_KEY_BITS 0x3
341#define EVP_CTRL_GET_RC5_ROUNDS 0x4
342#define EVP_CTRL_SET_RC5_ROUNDS 0x5
343#define EVP_CTRL_SET_ACSS_MODE 0x6
344
345typedef struct evp_cipher_info_st
346 {
347 const EVP_CIPHER *cipher;
348 unsigned char iv[EVP_MAX_IV_LENGTH];
349 } EVP_CIPHER_INFO;
350
351struct evp_cipher_ctx_st
352 {
353 const EVP_CIPHER *cipher;
354 ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
355 int encrypt; /* encrypt or decrypt */
356 int buf_len; /* number we have left */
357
358 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
359 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
360 unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
361 int num; /* used by cfb/ofb mode */
362
363 void *app_data; /* application stuff */
364 int key_len; /* May change for variable length cipher */
365 unsigned long flags; /* Various flags */
366 void *cipher_data; /* per EVP data */
367 int final_used;
368 int block_mask;
369 unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
370 } /* EVP_CIPHER_CTX */;
371
372typedef struct evp_Encode_Ctx_st
373 {
374 int num; /* number saved in a partial encode/decode */
375 int length; /* The length is either the output line length
376 * (in input bytes) or the shortest input line
377 * length that is ok. Once decoding begins,
378 * the length is adjusted up each time a longer
379 * line is decoded */
380 unsigned char enc_data[80]; /* data to encode */
381 int line_num; /* number read on current line */
382 int expect_nl;
383 } EVP_ENCODE_CTX;
384
385/* Password based encryption function */
386typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
387 ASN1_TYPE *param, const EVP_CIPHER *cipher,
388 const EVP_MD *md, int en_de);
389
390#ifndef OPENSSL_NO_RSA
391#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
392 (char *)(rsa))
393#endif
394
395#ifndef OPENSSL_NO_DSA
396#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
397 (char *)(dsa))
398#endif
399
400#ifndef OPENSSL_NO_DH
401#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\
402 (char *)(dh))
403#endif
404
405/* Add some extra combinations */
406#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
407#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
408#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
409#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
410
411#define EVP_MD_type(e) ((e)->type)
412#define EVP_MD_nid(e) EVP_MD_type(e)
413#define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e))
414#define EVP_MD_pkey_type(e) ((e)->pkey_type)
415#define EVP_MD_size(e) ((e)->md_size)
416#define EVP_MD_block_size(e) ((e)->block_size)
417
418#define EVP_MD_CTX_md(e) ((e)->digest)
419#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
420#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
421#define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
422
423#define EVP_CIPHER_nid(e) ((e)->nid)
424#define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e))
425#define EVP_CIPHER_block_size(e) ((e)->block_size)
426#define EVP_CIPHER_key_length(e) ((e)->key_len)
427#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
428#define EVP_CIPHER_flags(e) ((e)->flags)
429#define EVP_CIPHER_mode(e) (((e)->flags) & EVP_CIPH_MODE)
430
431#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
432#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
433#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
434#define EVP_CIPHER_CTX_key_length(e) ((e)->key_len)
435#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
436#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
437#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
438#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
439#define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags)
440#define EVP_CIPHER_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
441#define EVP_CIPHER_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
442#define EVP_CIPHER_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
443#define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE)
444
445#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
446#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
447
448#define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
449#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
450#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
451#define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
452#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
453#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
454#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
455#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
456
457#ifdef CONST_STRICT
458void BIO_set_md(BIO *,const EVP_MD *md);
459#else
460# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
461#endif
462#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
463#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
464#define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(char *)mdcp)
465#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
466#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
467
468#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
469
470#define EVP_add_cipher_alias(n,alias) \
471 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
472#define EVP_add_digest_alias(n,alias) \
473 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
474#define EVP_delete_cipher_alias(alias) \
475 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
476#define EVP_delete_digest_alias(alias) \
477 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
478
479void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
480int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
481EVP_MD_CTX *EVP_MD_CTX_create(void);
482void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
483int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);
484#define EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
485#define EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
486#define EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
487int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
488int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
489 unsigned int cnt);
490int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
491int EVP_Digest(void *data, unsigned int count,
492 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl);
493
494int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);
495int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
496int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
497
498int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
499void EVP_set_pw_prompt(char *prompt);
500char * EVP_get_pw_prompt(void);
501
502int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
503 const unsigned char *salt, const unsigned char *data,
504 int datal, int count, unsigned char *key,unsigned char *iv);
505
506int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
507 const unsigned char *key, const unsigned char *iv);
508int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
509 const unsigned char *key, const unsigned char *iv);
510int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
511 int *outl, const unsigned char *in, int inl);
512int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
513int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
514
515int EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
516 const unsigned char *key, const unsigned char *iv);
517int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
518 const unsigned char *key, const unsigned char *iv);
519int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
520 int *outl, const unsigned char *in, int inl);
521int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
522int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
523
524int EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
525 const unsigned char *key,const unsigned char *iv,
526 int enc);
527int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
528 const unsigned char *key,const unsigned char *iv,
529 int enc);
530int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
531 int *outl, const unsigned char *in, int inl);
532int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
533int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
534
535int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
536 EVP_PKEY *pkey);
537
538int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
539 unsigned int siglen,EVP_PKEY *pkey);
540
541int EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,unsigned char *ek,
542 int ekl,unsigned char *iv,EVP_PKEY *priv);
543int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
544
545int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek,
546 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
547int EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
548
549void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
550void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
551 int *outl,unsigned char *in,int inl);
552void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
553int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
554
555void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
556int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
557 unsigned char *in, int inl);
558int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
559 char *out, int *outl);
560int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
561
562void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
563int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
564int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
565int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
566int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
567
568#ifndef OPENSSL_NO_BIO
569BIO_METHOD *BIO_f_md(void);
570BIO_METHOD *BIO_f_base64(void);
571BIO_METHOD *BIO_f_cipher(void);
572BIO_METHOD *BIO_f_reliable(void);
573void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k,
574 unsigned char *i, int enc);
575#endif
576
577const EVP_MD *EVP_md_null(void);
578#ifndef OPENSSL_NO_MD2
579const EVP_MD *EVP_md2(void);
580#endif
581#ifndef OPENSSL_NO_MD4
582const EVP_MD *EVP_md4(void);
583#endif
584#ifndef OPENSSL_NO_MD5
585const EVP_MD *EVP_md5(void);
586#endif
587#ifndef OPENSSL_NO_SHA
588const EVP_MD *EVP_sha(void);
589const EVP_MD *EVP_sha1(void);
590const EVP_MD *EVP_dss(void);
591const EVP_MD *EVP_dss1(void);
592#ifdef OPENSSL_FIPS
593#ifndef OPENSSL_NO_SHA256
594const EVP_MD *EVP_sha224(void);
595const EVP_MD *EVP_sha256(void);
596#endif
597#ifndef OPENSSL_NO_SHA512
598const EVP_MD *EVP_sha384(void);
599const EVP_MD *EVP_sha512(void);
600#endif
601#endif
602#endif
603#ifndef OPENSSL_NO_MDC2
604const EVP_MD *EVP_mdc2(void);
605#endif
606#ifndef OPENSSL_NO_RIPEMD
607const EVP_MD *EVP_ripemd160(void);
608#endif
609const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
610#ifndef OPENSSL_NO_DES
611const EVP_CIPHER *EVP_des_ecb(void);
612const EVP_CIPHER *EVP_des_ede(void);
613const EVP_CIPHER *EVP_des_ede3(void);
614const EVP_CIPHER *EVP_des_ede_ecb(void);
615const EVP_CIPHER *EVP_des_ede3_ecb(void);
616const EVP_CIPHER *EVP_des_cfb64(void);
617# define EVP_des_cfb EVP_des_cfb64
618const EVP_CIPHER *EVP_des_cfb1(void);
619const EVP_CIPHER *EVP_des_cfb8(void);
620const EVP_CIPHER *EVP_des_ede_cfb64(void);
621# define EVP_des_ede_cfb EVP_des_ede_cfb64
622#if 0
623const EVP_CIPHER *EVP_des_ede_cfb1(void);
624const EVP_CIPHER *EVP_des_ede_cfb8(void);
625#endif
626const EVP_CIPHER *EVP_des_ede3_cfb64(void);
627# define EVP_des_ede3_cfb EVP_des_ede3_cfb64
628const EVP_CIPHER *EVP_des_ede3_cfb1(void);
629const EVP_CIPHER *EVP_des_ede3_cfb8(void);
630const EVP_CIPHER *EVP_des_ofb(void);
631const EVP_CIPHER *EVP_des_ede_ofb(void);
632const EVP_CIPHER *EVP_des_ede3_ofb(void);
633const EVP_CIPHER *EVP_des_cbc(void);
634const EVP_CIPHER *EVP_des_ede_cbc(void);
635const EVP_CIPHER *EVP_des_ede3_cbc(void);
636const EVP_CIPHER *EVP_desx_cbc(void);
637/* This should now be supported through the dev_crypto ENGINE. But also, why are
638 * rc4 and md5 declarations made here inside a "NO_DES" precompiler branch? */
639#if 0
640# ifdef OPENSSL_OPENBSD_DEV_CRYPTO
641const EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void);
642const EVP_CIPHER *EVP_dev_crypto_rc4(void);
643const EVP_MD *EVP_dev_crypto_md5(void);
644# endif
645#endif
646#endif
647#ifndef OPENSSL_NO_RC4
648const EVP_CIPHER *EVP_rc4(void);
649const EVP_CIPHER *EVP_rc4_40(void);
650#endif
651#ifndef OPENSSL_NO_IDEA
652const EVP_CIPHER *EVP_idea_ecb(void);
653const EVP_CIPHER *EVP_idea_cfb64(void);
654# define EVP_idea_cfb EVP_idea_cfb64
655const EVP_CIPHER *EVP_idea_ofb(void);
656const EVP_CIPHER *EVP_idea_cbc(void);
657#endif
658#ifndef OPENSSL_NO_RC2
659const EVP_CIPHER *EVP_rc2_ecb(void);
660const EVP_CIPHER *EVP_rc2_cbc(void);
661const EVP_CIPHER *EVP_rc2_40_cbc(void);
662const EVP_CIPHER *EVP_rc2_64_cbc(void);
663const EVP_CIPHER *EVP_rc2_cfb64(void);
664# define EVP_rc2_cfb EVP_rc2_cfb64
665const EVP_CIPHER *EVP_rc2_ofb(void);
666#endif
667#ifndef OPENSSL_NO_BF
668const EVP_CIPHER *EVP_bf_ecb(void);
669const EVP_CIPHER *EVP_bf_cbc(void);
670const EVP_CIPHER *EVP_bf_cfb64(void);
671# define EVP_bf_cfb EVP_bf_cfb64
672const EVP_CIPHER *EVP_bf_ofb(void);
673#endif
674#ifndef OPENSSL_NO_CAST
675const EVP_CIPHER *EVP_cast5_ecb(void);
676const EVP_CIPHER *EVP_cast5_cbc(void);
677const EVP_CIPHER *EVP_cast5_cfb64(void);
678# define EVP_cast5_cfb EVP_cast5_cfb64
679const EVP_CIPHER *EVP_cast5_ofb(void);
680#endif
681#ifndef OPENSSL_NO_RC5
682const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
683const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
684const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void);
685# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64
686const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
687#endif
688#ifndef OPENSSL_NO_AES
689const EVP_CIPHER *EVP_aes_128_ecb(void);
690const EVP_CIPHER *EVP_aes_128_cbc(void);
691const EVP_CIPHER *EVP_aes_128_cfb1(void);
692const EVP_CIPHER *EVP_aes_128_cfb8(void);
693const EVP_CIPHER *EVP_aes_128_cfb128(void);
694# define EVP_aes_128_cfb EVP_aes_128_cfb128
695const EVP_CIPHER *EVP_aes_128_ofb(void);
696#if 0
697const EVP_CIPHER *EVP_aes_128_ctr(void);
698#endif
699const EVP_CIPHER *EVP_aes_192_ecb(void);
700const EVP_CIPHER *EVP_aes_192_cbc(void);
701const EVP_CIPHER *EVP_aes_192_cfb1(void);
702const EVP_CIPHER *EVP_aes_192_cfb8(void);
703const EVP_CIPHER *EVP_aes_192_cfb128(void);
704# define EVP_aes_192_cfb EVP_aes_192_cfb128
705const EVP_CIPHER *EVP_aes_192_ofb(void);
706#if 0
707const EVP_CIPHER *EVP_aes_192_ctr(void);
708#endif
709const EVP_CIPHER *EVP_aes_256_ecb(void);
710const EVP_CIPHER *EVP_aes_256_cbc(void);
711const EVP_CIPHER *EVP_aes_256_cfb1(void);
712const EVP_CIPHER *EVP_aes_256_cfb8(void);
713const EVP_CIPHER *EVP_aes_256_cfb128(void);
714# define EVP_aes_256_cfb EVP_aes_256_cfb128
715const EVP_CIPHER *EVP_aes_256_ofb(void);
716#if 0
717const EVP_CIPHER *EVP_aes_256_ctr(void);
718#endif
719#endif
720#ifndef OPENSSL_NO_ACSS
721const EVP_CIPHER *EVP_acss(void);
722#endif
723
724void OPENSSL_add_all_algorithms_noconf(void);
725void OPENSSL_add_all_algorithms_conf(void);
726
727#ifdef OPENSSL_LOAD_CONF
728#define OpenSSL_add_all_algorithms() \
729 OPENSSL_add_all_algorithms_conf()
730#else
731#define OpenSSL_add_all_algorithms() \
732 OPENSSL_add_all_algorithms_noconf()
733#endif
734
735void OpenSSL_add_all_ciphers(void);
736void OpenSSL_add_all_digests(void);
737#define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms()
738#define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers()
739#define SSLeay_add_all_digests() OpenSSL_add_all_digests()
740
741int EVP_add_cipher(const EVP_CIPHER *cipher);
742int EVP_add_digest(const EVP_MD *digest);
743
744const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
745const EVP_MD *EVP_get_digestbyname(const char *name);
746void EVP_cleanup(void);
747
748int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
749 int enc_key_len,EVP_PKEY *private_key);
750int EVP_PKEY_encrypt(unsigned char *enc_key,
751 unsigned char *key,int key_len,EVP_PKEY *pub_key);
752int EVP_PKEY_type(int type);
753int EVP_PKEY_bits(EVP_PKEY *pkey);
754int EVP_PKEY_size(EVP_PKEY *pkey);
755int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
756
757#ifndef OPENSSL_NO_RSA
758struct rsa_st;
759int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,struct rsa_st *key);
760struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
761#endif
762#ifndef OPENSSL_NO_DSA
763struct dsa_st;
764int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,struct dsa_st *key);
765struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
766#endif
767#ifndef OPENSSL_NO_DH
768struct dh_st;
769int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key);
770struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
771#endif
772
773
774EVP_PKEY * EVP_PKEY_new(void);
775void EVP_PKEY_free(EVP_PKEY *pkey);
776EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
777 long length);
778int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
779
780EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
781 long length);
782EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
783 long length);
784int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
785
786int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
787int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
788int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
789int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
790
791int EVP_CIPHER_type(const EVP_CIPHER *ctx);
792
793/* calls methods */
794int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
795int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
796
797/* These are used by EVP_CIPHER methods */
798int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
799int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
800
801/* PKCS5 password based encryption */
802int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
803 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
804 int en_de);
805int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
806 unsigned char *salt, int saltlen, int iter,
807 int keylen, unsigned char *out);
808int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
809 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
810 int en_de);
811
812void PKCS5_PBE_add(void);
813
814int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
815 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
816int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
817 EVP_PBE_KEYGEN *keygen);
818void EVP_PBE_cleanup(void);
819
820/* BEGIN ERROR CODES */
821/* The following lines are auto generated by the script mkerr.pl. Any changes
822 * made after this point may be overwritten when the script is next run.
823 */
824void ERR_load_EVP_strings(void);
825
826/* Error codes for the EVP functions. */
827
828/* Function codes. */
829#define EVP_F_AES_INIT_KEY 129
830#define EVP_F_D2I_PKEY 100
831#define EVP_F_EVP_ADD_CIPHER 130
832#define EVP_F_EVP_ADD_DIGEST 131
833#define EVP_F_EVP_CIPHERINIT 123
834#define EVP_F_EVP_CIPHER_CTX_CTRL 124
835#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122
836#define EVP_F_EVP_DECRYPTFINAL 101
837#define EVP_F_EVP_DIGESTINIT 128
838#define EVP_F_EVP_ENCRYPTFINAL 127
839#define EVP_F_EVP_GET_CIPHERBYNAME 132
840#define EVP_F_EVP_GET_DIGESTBYNAME 133
841#define EVP_F_EVP_MD_CTX_COPY 110
842#define EVP_F_EVP_OPENINIT 102
843#define EVP_F_EVP_PBE_ALG_ADD 115
844#define EVP_F_EVP_PBE_CIPHERINIT 116
845#define EVP_F_EVP_PKCS82PKEY 111
846#define EVP_F_EVP_PKCS8_SET_BROKEN 112
847#define EVP_F_EVP_PKEY2PKCS8 113
848#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
849#define EVP_F_EVP_PKEY_DECRYPT 104
850#define EVP_F_EVP_PKEY_ENCRYPT 105
851#define EVP_F_EVP_PKEY_GET1_DH 119
852#define EVP_F_EVP_PKEY_GET1_DSA 120
853#define EVP_F_EVP_PKEY_GET1_RSA 121
854#define EVP_F_EVP_PKEY_NEW 106
855#define EVP_F_EVP_RIJNDAEL 126
856#define EVP_F_EVP_SIGNFINAL 107
857#define EVP_F_EVP_VERIFYFINAL 108
858#define EVP_F_PKCS5_PBE_KEYIVGEN 117
859#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
860#define EVP_F_RC2_MAGIC_TO_METH 109
861#define EVP_F_RC5_CTRL 125
862
863/* Reason codes. */
864#define EVP_R_AES_KEY_SETUP_FAILED 140
865#define EVP_R_BAD_BLOCK_LENGTH 136
866#define EVP_R_BAD_DECRYPT 100
867#define EVP_R_BAD_KEY_LENGTH 137
868#define EVP_R_BN_DECODE_ERROR 112
869#define EVP_R_BN_PUBKEY_ERROR 113
870#define EVP_R_CIPHER_PARAMETER_ERROR 122
871#define EVP_R_CTRL_NOT_IMPLEMENTED 132
872#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133
873#define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138
874#define EVP_R_DECODE_ERROR 114
875#define EVP_R_DIFFERENT_KEY_TYPES 101
876#define EVP_R_DISABLED_FOR_FIPS 141
877#define EVP_R_ENCODE_ERROR 115
878#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
879#define EVP_R_EXPECTING_AN_RSA_KEY 127
880#define EVP_R_EXPECTING_A_DH_KEY 128
881#define EVP_R_EXPECTING_A_DSA_KEY 129
882#define EVP_R_INITIALIZATION_ERROR 134
883#define EVP_R_INPUT_NOT_INITIALIZED 111
884#define EVP_R_INVALID_KEY_LENGTH 130
885#define EVP_R_IV_TOO_LARGE 102
886#define EVP_R_KEYGEN_FAILURE 120
887#define EVP_R_MISSING_PARAMETERS 103
888#define EVP_R_NO_CIPHER_SET 131
889#define EVP_R_NO_DIGEST_SET 139
890#define EVP_R_NO_DSA_PARAMETERS 116
891#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
892#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
893#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
894#define EVP_R_PUBLIC_KEY_NOT_RSA 106
895#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
896#define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135
897#define EVP_R_UNSUPPORTED_CIPHER 107
898#define EVP_R_UNSUPPORTED_KEYLENGTH 123
899#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124
900#define EVP_R_UNSUPPORTED_KEY_SIZE 108
901#define EVP_R_UNSUPPORTED_PRF 125
902#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118
903#define EVP_R_UNSUPPORTED_SALT_TYPE 126
904#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
905#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
906
907#ifdef __cplusplus
908}
909#endif
910#endif
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
deleted file mode 100644
index f549eeb437..0000000000
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ /dev/null
@@ -1,592 +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#include <openssl/err.h>
63#ifndef OPENSSL_NO_ENGINE
64#include <openssl/engine.h>
65#endif
66#include "evp_locl.h"
67
68const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
69
70void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
71 {
72 memset(ctx,0,sizeof(EVP_CIPHER_CTX));
73 /* ctx->cipher=NULL; */
74 }
75
76
77int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
78 const unsigned char *key, const unsigned char *iv, int enc)
79 {
80 if (cipher)
81 EVP_CIPHER_CTX_init(ctx);
82 return EVP_CipherInit_ex(ctx,cipher,NULL,key,iv,enc);
83 }
84
85#ifdef OPENSSL_FIPS
86
87/* The purpose of these is to trap programs that attempt to use non FIPS
88 * algorithms in FIPS mode and ignore the errors.
89 */
90
91int bad_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
92 const unsigned char *iv, int enc)
93 { FIPS_ERROR_IGNORED("Cipher init"); return 0;}
94
95int bad_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97 { FIPS_ERROR_IGNORED("Cipher update"); return 0;}
98
99/* NB: no cleanup because it is allowed after failed init */
100
101int bad_set_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
102 { FIPS_ERROR_IGNORED("Cipher set_asn1"); return 0;}
103int bad_get_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
104 { FIPS_ERROR_IGNORED("Cipher get_asn1"); return 0;}
105int bad_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
106 { FIPS_ERROR_IGNORED("Cipher ctrl"); return 0;}
107
108static const EVP_CIPHER bad_cipher =
109 {
110 0,
111 0,
112 0,
113 0,
114 0,
115 bad_init,
116 bad_do_cipher,
117 NULL,
118 0,
119 bad_set_asn1,
120 bad_get_asn1,
121 bad_ctrl,
122 NULL
123 };
124
125#endif
126
127int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
128 const unsigned char *key, const unsigned char *iv, int enc)
129 {
130 if (enc == -1)
131 enc = ctx->encrypt;
132 else
133 {
134 if (enc)
135 enc = 1;
136 ctx->encrypt = enc;
137 }
138#ifndef OPENSSL_NO_ENGINE
139 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
140 * so this context may already have an ENGINE! Try to avoid releasing
141 * the previous handle, re-querying for an ENGINE, and having a
142 * reinitialisation, when it may all be unecessary. */
143 if (ctx->engine && ctx->cipher && (!cipher ||
144 (cipher && (cipher->nid == ctx->cipher->nid))))
145 goto skip_to_init;
146#endif
147 if (cipher)
148 {
149 /* Ensure a context left lying around from last time is cleared
150 * (the previous check attempted to avoid this if the same
151 * ENGINE and EVP_CIPHER could be used). */
152 EVP_CIPHER_CTX_cleanup(ctx);
153
154 /* Restore encrypt field: it is zeroed by cleanup */
155 ctx->encrypt = enc;
156#ifndef OPENSSL_NO_ENGINE
157 if(impl)
158 {
159 if (!ENGINE_init(impl))
160 {
161 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
162 return 0;
163 }
164 }
165 else
166 /* Ask if an ENGINE is reserved for this job */
167 impl = ENGINE_get_cipher_engine(cipher->nid);
168 if(impl)
169 {
170 /* There's an ENGINE for this job ... (apparently) */
171 const EVP_CIPHER *c = ENGINE_get_cipher(impl, cipher->nid);
172 if(!c)
173 {
174 /* One positive side-effect of US's export
175 * control history, is that we should at least
176 * be able to avoid using US mispellings of
177 * "initialisation"? */
178 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
179 return 0;
180 }
181 /* We'll use the ENGINE's private cipher definition */
182 cipher = c;
183 /* Store the ENGINE functional reference so we know
184 * 'cipher' came from an ENGINE and we need to release
185 * it when done. */
186 ctx->engine = impl;
187 }
188 else
189 ctx->engine = NULL;
190#endif
191 ctx->cipher=cipher;
192 if (ctx->cipher->ctx_size)
193 {
194 ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size);
195 if (!ctx->cipher_data)
196 {
197 EVPerr(EVP_F_EVP_CIPHERINIT, ERR_R_MALLOC_FAILURE);
198 return 0;
199 }
200 }
201 else
202 {
203 ctx->cipher_data = NULL;
204 }
205 ctx->key_len = cipher->key_len;
206 ctx->flags = 0;
207 if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT)
208 {
209 if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL))
210 {
211 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
212 return 0;
213 }
214 }
215 }
216 else if(!ctx->cipher)
217 {
218 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET);
219 return 0;
220 }
221#ifndef OPENSSL_NO_ENGINE
222skip_to_init:
223#endif
224 /* we assume block size is a power of 2 in *cryptUpdate */
225 OPENSSL_assert(ctx->cipher->block_size == 1
226 || ctx->cipher->block_size == 8
227 || ctx->cipher->block_size == 16);
228
229 if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
230 switch(EVP_CIPHER_CTX_mode(ctx)) {
231
232 case EVP_CIPH_STREAM_CIPHER:
233 case EVP_CIPH_ECB_MODE:
234 break;
235
236 case EVP_CIPH_CFB_MODE:
237 case EVP_CIPH_OFB_MODE:
238
239 ctx->num = 0;
240
241 case EVP_CIPH_CBC_MODE:
242
243 OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof ctx->iv);
244 if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
245 memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
246 break;
247
248 default:
249 return 0;
250 break;
251 }
252 }
253
254#ifdef OPENSSL_FIPS
255 /* After 'key' is set no further parameters changes are permissible.
256 * So only check for non FIPS enabling at this point.
257 */
258 if (key && FIPS_mode())
259 {
260 if (!(ctx->cipher->flags & EVP_CIPH_FLAG_FIPS)
261 & !(ctx->flags & EVP_CIPH_FLAG_NON_FIPS_ALLOW))
262 {
263 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_DISABLED_FOR_FIPS);
264 ERR_add_error_data(2, "cipher=",
265 EVP_CIPHER_name(ctx->cipher));
266 ctx->cipher = &bad_cipher;
267 return 0;
268 }
269 }
270#endif
271
272 if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
273 if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;
274 }
275 ctx->buf_len=0;
276 ctx->final_used=0;
277 ctx->block_mask=ctx->cipher->block_size-1;
278 return 1;
279 }
280
281int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
282 const unsigned char *in, int inl)
283 {
284 if (ctx->encrypt)
285 return EVP_EncryptUpdate(ctx,out,outl,in,inl);
286 else return EVP_DecryptUpdate(ctx,out,outl,in,inl);
287 }
288
289int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
290 {
291 if (ctx->encrypt)
292 return EVP_EncryptFinal_ex(ctx,out,outl);
293 else return EVP_DecryptFinal_ex(ctx,out,outl);
294 }
295
296int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
297 {
298 if (ctx->encrypt)
299 return EVP_EncryptFinal(ctx,out,outl);
300 else return EVP_DecryptFinal(ctx,out,outl);
301 }
302
303int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
304 const unsigned char *key, const unsigned char *iv)
305 {
306 return EVP_CipherInit(ctx, cipher, key, iv, 1);
307 }
308
309int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
310 const unsigned char *key, const unsigned char *iv)
311 {
312 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
313 }
314
315int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
316 const unsigned char *key, const unsigned char *iv)
317 {
318 return EVP_CipherInit(ctx, cipher, key, iv, 0);
319 }
320
321int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
322 const unsigned char *key, const unsigned char *iv)
323 {
324 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
325 }
326
327int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
328 const unsigned char *in, int inl)
329 {
330 int i,j,bl;
331
332 OPENSSL_assert(inl > 0);
333 if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0)
334 {
335 if(ctx->cipher->do_cipher(ctx,out,in,inl))
336 {
337 *outl=inl;
338 return 1;
339 }
340 else
341 {
342 *outl=0;
343 return 0;
344 }
345 }
346 i=ctx->buf_len;
347 bl=ctx->cipher->block_size;
348 OPENSSL_assert(bl <= sizeof ctx->buf);
349 if (i != 0)
350 {
351 if (i+inl < bl)
352 {
353 memcpy(&(ctx->buf[i]),in,inl);
354 ctx->buf_len+=inl;
355 *outl=0;
356 return 1;
357 }
358 else
359 {
360 j=bl-i;
361 memcpy(&(ctx->buf[i]),in,j);
362 if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0;
363 inl-=j;
364 in+=j;
365 out+=bl;
366 *outl=bl;
367 }
368 }
369 else
370 *outl = 0;
371 i=inl&(bl-1);
372 inl-=i;
373 if (inl > 0)
374 {
375 if(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0;
376 *outl+=inl;
377 }
378
379 if (i != 0)
380 memcpy(ctx->buf,&(in[inl]),i);
381 ctx->buf_len=i;
382 return 1;
383 }
384
385int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
386 {
387 int ret;
388 ret = EVP_EncryptFinal_ex(ctx, out, outl);
389 return ret;
390 }
391
392int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
393 {
394 int i,n,b,bl,ret;
395
396 b=ctx->cipher->block_size;
397 OPENSSL_assert(b <= sizeof ctx->buf);
398 if (b == 1)
399 {
400 *outl=0;
401 return 1;
402 }
403 bl=ctx->buf_len;
404 if (ctx->flags & EVP_CIPH_NO_PADDING)
405 {
406 if(bl)
407 {
408 EVPerr(EVP_F_EVP_ENCRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
409 return 0;
410 }
411 *outl = 0;
412 return 1;
413 }
414
415 n=b-bl;
416 for (i=bl; i<b; i++)
417 ctx->buf[i]=n;
418 ret=ctx->cipher->do_cipher(ctx,out,ctx->buf,b);
419
420
421 if(ret)
422 *outl=b;
423
424 return ret;
425 }
426
427int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
428 const unsigned char *in, int inl)
429 {
430 int b, fix_len;
431
432 if (inl == 0)
433 {
434 *outl=0;
435 return 1;
436 }
437
438 if (ctx->flags & EVP_CIPH_NO_PADDING)
439 return EVP_EncryptUpdate(ctx, out, outl, in, inl);
440
441 b=ctx->cipher->block_size;
442 OPENSSL_assert(b <= sizeof ctx->final);
443
444 if(ctx->final_used)
445 {
446 memcpy(out,ctx->final,b);
447 out+=b;
448 fix_len = 1;
449 }
450 else
451 fix_len = 0;
452
453
454 if(!EVP_EncryptUpdate(ctx,out,outl,in,inl))
455 return 0;
456
457 /* if we have 'decrypted' a multiple of block size, make sure
458 * we have a copy of this last block */
459 if (b > 1 && !ctx->buf_len)
460 {
461 *outl-=b;
462 ctx->final_used=1;
463 memcpy(ctx->final,&out[*outl],b);
464 }
465 else
466 ctx->final_used = 0;
467
468 if (fix_len)
469 *outl += b;
470
471 return 1;
472 }
473
474int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
475 {
476 int ret;
477 ret = EVP_DecryptFinal_ex(ctx, out, outl);
478 return ret;
479 }
480
481int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
482 {
483 int i,b;
484 int n;
485
486 *outl=0;
487 b=ctx->cipher->block_size;
488 if (ctx->flags & EVP_CIPH_NO_PADDING)
489 {
490 if(ctx->buf_len)
491 {
492 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
493 return 0;
494 }
495 *outl = 0;
496 return 1;
497 }
498 if (b > 1)
499 {
500 if (ctx->buf_len || !ctx->final_used)
501 {
502 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
503 return(0);
504 }
505 OPENSSL_assert(b <= sizeof ctx->final);
506 n=ctx->final[b-1];
507 if (n > b)
508 {
509 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
510 return(0);
511 }
512 for (i=0; i<n; i++)
513 {
514 if (ctx->final[--b] != n)
515 {
516 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
517 return(0);
518 }
519 }
520 n=ctx->cipher->block_size-n;
521 for (i=0; i<n; i++)
522 out[i]=ctx->final[i];
523 *outl=n;
524 }
525 else
526 *outl=0;
527 return(1);
528 }
529
530int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
531 {
532 if (c->cipher != NULL)
533 {
534 if(c->cipher->cleanup && !c->cipher->cleanup(c))
535 return 0;
536 /* Cleanse cipher context data */
537 if (c->cipher_data)
538 OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
539 }
540 if (c->cipher_data)
541 OPENSSL_free(c->cipher_data);
542#ifndef OPENSSL_NO_ENGINE
543 if (c->engine)
544 /* The EVP_CIPHER we used belongs to an ENGINE, release the
545 * functional reference we held for this reason. */
546 ENGINE_finish(c->engine);
547#endif
548 memset(c,0,sizeof(EVP_CIPHER_CTX));
549 return 1;
550 }
551
552int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
553 {
554 if(c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
555 return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, keylen, NULL);
556 if(c->key_len == keylen) return 1;
557 if((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH))
558 {
559 c->key_len = keylen;
560 return 1;
561 }
562 EVPerr(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH,EVP_R_INVALID_KEY_LENGTH);
563 return 0;
564 }
565
566int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
567 {
568 if (pad) ctx->flags &= ~EVP_CIPH_NO_PADDING;
569 else ctx->flags |= EVP_CIPH_NO_PADDING;
570 return 1;
571 }
572
573int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
574{
575 int ret;
576 if(!ctx->cipher) {
577 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET);
578 return 0;
579 }
580
581 if(!ctx->cipher->ctrl) {
582 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED);
583 return 0;
584 }
585
586 ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
587 if(ret == -1) {
588 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
589 return 0;
590 }
591 return ret;
592}
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
deleted file mode 100644
index 77eee070d3..0000000000
--- a/src/lib/libcrypto/evp/evp_err.c
+++ /dev/null
@@ -1,171 +0,0 @@
1/* crypto/evp/evp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_EVP,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_EVP,0,reason)
70
71static ERR_STRING_DATA EVP_str_functs[]=
72 {
73{ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"},
74{ERR_FUNC(EVP_F_D2I_PKEY), "D2I_PKEY"},
75{ERR_FUNC(EVP_F_EVP_ADD_CIPHER), "EVP_add_cipher"},
76{ERR_FUNC(EVP_F_EVP_ADD_DIGEST), "EVP_add_digest"},
77{ERR_FUNC(EVP_F_EVP_CIPHERINIT), "EVP_CipherInit"},
78{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_CTRL), "EVP_CIPHER_CTX_ctrl"},
79{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH), "EVP_CIPHER_CTX_set_key_length"},
80{ERR_FUNC(EVP_F_EVP_DECRYPTFINAL), "EVP_DecryptFinal"},
81{ERR_FUNC(EVP_F_EVP_DIGESTINIT), "EVP_DigestInit"},
82{ERR_FUNC(EVP_F_EVP_ENCRYPTFINAL), "EVP_EncryptFinal"},
83{ERR_FUNC(EVP_F_EVP_GET_CIPHERBYNAME), "EVP_get_cipherbyname"},
84{ERR_FUNC(EVP_F_EVP_GET_DIGESTBYNAME), "EVP_get_digestbyname"},
85{ERR_FUNC(EVP_F_EVP_MD_CTX_COPY), "EVP_MD_CTX_copy"},
86{ERR_FUNC(EVP_F_EVP_OPENINIT), "EVP_OpenInit"},
87{ERR_FUNC(EVP_F_EVP_PBE_ALG_ADD), "EVP_PBE_alg_add"},
88{ERR_FUNC(EVP_F_EVP_PBE_CIPHERINIT), "EVP_PBE_CipherInit"},
89{ERR_FUNC(EVP_F_EVP_PKCS82PKEY), "EVP_PKCS82PKEY"},
90{ERR_FUNC(EVP_F_EVP_PKCS8_SET_BROKEN), "EVP_PKCS8_SET_BROKEN"},
91{ERR_FUNC(EVP_F_EVP_PKEY2PKCS8), "EVP_PKEY2PKCS8"},
92{ERR_FUNC(EVP_F_EVP_PKEY_COPY_PARAMETERS), "EVP_PKEY_copy_parameters"},
93{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT), "EVP_PKEY_decrypt"},
94{ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT), "EVP_PKEY_encrypt"},
95{ERR_FUNC(EVP_F_EVP_PKEY_GET1_DH), "EVP_PKEY_get1_DH"},
96{ERR_FUNC(EVP_F_EVP_PKEY_GET1_DSA), "EVP_PKEY_get1_DSA"},
97{ERR_FUNC(EVP_F_EVP_PKEY_GET1_RSA), "EVP_PKEY_get1_RSA"},
98{ERR_FUNC(EVP_F_EVP_PKEY_NEW), "EVP_PKEY_new"},
99{ERR_FUNC(EVP_F_EVP_RIJNDAEL), "EVP_RIJNDAEL"},
100{ERR_FUNC(EVP_F_EVP_SIGNFINAL), "EVP_SignFinal"},
101{ERR_FUNC(EVP_F_EVP_VERIFYFINAL), "EVP_VerifyFinal"},
102{ERR_FUNC(EVP_F_PKCS5_PBE_KEYIVGEN), "PKCS5_PBE_keyivgen"},
103{ERR_FUNC(EVP_F_PKCS5_V2_PBE_KEYIVGEN), "PKCS5_v2_PBE_keyivgen"},
104{ERR_FUNC(EVP_F_RC2_MAGIC_TO_METH), "RC2_MAGIC_TO_METH"},
105{ERR_FUNC(EVP_F_RC5_CTRL), "RC5_CTRL"},
106{0,NULL}
107 };
108
109static ERR_STRING_DATA EVP_str_reasons[]=
110 {
111{ERR_REASON(EVP_R_AES_KEY_SETUP_FAILED) ,"aes key setup failed"},
112{ERR_REASON(EVP_R_BAD_BLOCK_LENGTH) ,"bad block length"},
113{ERR_REASON(EVP_R_BAD_DECRYPT) ,"bad decrypt"},
114{ERR_REASON(EVP_R_BAD_KEY_LENGTH) ,"bad key length"},
115{ERR_REASON(EVP_R_BN_DECODE_ERROR) ,"bn decode error"},
116{ERR_REASON(EVP_R_BN_PUBKEY_ERROR) ,"bn pubkey error"},
117{ERR_REASON(EVP_R_CIPHER_PARAMETER_ERROR),"cipher parameter error"},
118{ERR_REASON(EVP_R_CTRL_NOT_IMPLEMENTED) ,"ctrl not implemented"},
119{ERR_REASON(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED),"ctrl operation not implemented"},
120{ERR_REASON(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH),"data not multiple of block length"},
121{ERR_REASON(EVP_R_DECODE_ERROR) ,"decode error"},
122{ERR_REASON(EVP_R_DIFFERENT_KEY_TYPES) ,"different key types"},
123{ERR_REASON(EVP_R_DISABLED_FOR_FIPS) ,"disabled for fips"},
124{ERR_REASON(EVP_R_ENCODE_ERROR) ,"encode error"},
125{ERR_REASON(EVP_R_EVP_PBE_CIPHERINIT_ERROR),"evp pbe cipherinit error"},
126{ERR_REASON(EVP_R_EXPECTING_AN_RSA_KEY) ,"expecting an rsa key"},
127{ERR_REASON(EVP_R_EXPECTING_A_DH_KEY) ,"expecting a dh key"},
128{ERR_REASON(EVP_R_EXPECTING_A_DSA_KEY) ,"expecting a dsa key"},
129{ERR_REASON(EVP_R_INITIALIZATION_ERROR) ,"initialization error"},
130{ERR_REASON(EVP_R_INPUT_NOT_INITIALIZED) ,"input not initialized"},
131{ERR_REASON(EVP_R_INVALID_KEY_LENGTH) ,"invalid key length"},
132{ERR_REASON(EVP_R_IV_TOO_LARGE) ,"iv too large"},
133{ERR_REASON(EVP_R_KEYGEN_FAILURE) ,"keygen failure"},
134{ERR_REASON(EVP_R_MISSING_PARAMETERS) ,"missing parameters"},
135{ERR_REASON(EVP_R_NO_CIPHER_SET) ,"no cipher set"},
136{ERR_REASON(EVP_R_NO_DIGEST_SET) ,"no digest set"},
137{ERR_REASON(EVP_R_NO_DSA_PARAMETERS) ,"no dsa parameters"},
138{ERR_REASON(EVP_R_NO_SIGN_FUNCTION_CONFIGURED),"no sign function configured"},
139{ERR_REASON(EVP_R_NO_VERIFY_FUNCTION_CONFIGURED),"no verify function configured"},
140{ERR_REASON(EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE),"pkcs8 unknown broken type"},
141{ERR_REASON(EVP_R_PUBLIC_KEY_NOT_RSA) ,"public key not rsa"},
142{ERR_REASON(EVP_R_UNKNOWN_PBE_ALGORITHM) ,"unknown pbe algorithm"},
143{ERR_REASON(EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS),"unsuported number of rounds"},
144{ERR_REASON(EVP_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"},
145{ERR_REASON(EVP_R_UNSUPPORTED_KEYLENGTH) ,"unsupported keylength"},
146{ERR_REASON(EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION),"unsupported key derivation function"},
147{ERR_REASON(EVP_R_UNSUPPORTED_KEY_SIZE) ,"unsupported key size"},
148{ERR_REASON(EVP_R_UNSUPPORTED_PRF) ,"unsupported prf"},
149{ERR_REASON(EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM),"unsupported private key algorithm"},
150{ERR_REASON(EVP_R_UNSUPPORTED_SALT_TYPE) ,"unsupported salt type"},
151{ERR_REASON(EVP_R_WRONG_FINAL_BLOCK_LENGTH),"wrong final block length"},
152{ERR_REASON(EVP_R_WRONG_PUBLIC_KEY_TYPE) ,"wrong public key type"},
153{0,NULL}
154 };
155
156#endif
157
158void ERR_load_EVP_strings(void)
159 {
160 static int init=1;
161
162 if (init)
163 {
164 init=0;
165#ifndef OPENSSL_NO_ERR
166 ERR_load_strings(0,EVP_str_functs);
167 ERR_load_strings(0,EVP_str_reasons);
168#endif
169
170 }
171 }
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
deleted file mode 100644
index f8650d5df6..0000000000
--- a/src/lib/libcrypto/evp/evp_key.c
+++ /dev/null
@@ -1,175 +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#include <openssl/ui.h>
65
66/* should be init to zeros. */
67static char prompt_string[80];
68
69void EVP_set_pw_prompt(char *prompt)
70 {
71 if (prompt == NULL)
72 prompt_string[0]='\0';
73 else
74 {
75 strncpy(prompt_string,prompt,79);
76 prompt_string[79]='\0';
77 }
78 }
79
80char *EVP_get_pw_prompt(void)
81 {
82 if (prompt_string[0] == '\0')
83 return(NULL);
84 else
85 return(prompt_string);
86 }
87
88/* For historical reasons, the standard function for reading passwords is
89 * in the DES library -- if someone ever wants to disable DES,
90 * this function will fail */
91int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
92 {
93 int ret;
94 char buff[BUFSIZ];
95 UI *ui;
96
97 if ((prompt == NULL) && (prompt_string[0] != '\0'))
98 prompt=prompt_string;
99 ui = UI_new();
100 UI_add_input_string(ui,prompt,0,buf,0,(len>=BUFSIZ)?BUFSIZ-1:len);
101 if (verify)
102 UI_add_verify_string(ui,prompt,0,
103 buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf);
104 ret = UI_process(ui);
105 UI_free(ui);
106 OPENSSL_cleanse(buff,BUFSIZ);
107 return ret;
108 }
109
110int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
111 const unsigned char *salt, const unsigned char *data, int datal,
112 int count, unsigned char *key, unsigned char *iv)
113 {
114 EVP_MD_CTX c;
115 unsigned char md_buf[EVP_MAX_MD_SIZE];
116 int niv,nkey,addmd=0;
117 unsigned int mds=0,i;
118
119 nkey=type->key_len;
120 niv=type->iv_len;
121 OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
122 OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
123
124 if (data == NULL) return(nkey);
125
126 EVP_MD_CTX_init(&c);
127 for (;;)
128 {
129 if (!EVP_DigestInit_ex(&c,md, NULL))
130 return 0;
131 if (addmd++)
132 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
133 EVP_DigestUpdate(&c,data,datal);
134 if (salt != NULL)
135 EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN);
136 EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
137
138 for (i=1; i<(unsigned int)count; i++)
139 {
140 EVP_DigestInit_ex(&c,md, NULL);
141 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
142 EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
143 }
144 i=0;
145 if (nkey)
146 {
147 for (;;)
148 {
149 if (nkey == 0) break;
150 if (i == mds) break;
151 if (key != NULL)
152 *(key++)=md_buf[i];
153 nkey--;
154 i++;
155 }
156 }
157 if (niv && (i != mds))
158 {
159 for (;;)
160 {
161 if (niv == 0) break;
162 if (i == mds) break;
163 if (iv != NULL)
164 *(iv++)=md_buf[i];
165 niv--;
166 i++;
167 }
168 }
169 if ((nkey == 0) && (niv == 0)) break;
170 }
171 EVP_MD_CTX_cleanup(&c);
172 OPENSSL_cleanse(&(md_buf[0]),EVP_MAX_MD_SIZE);
173 return(type->key_len);
174 }
175
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
deleted file mode 100644
index a63ba19317..0000000000
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ /dev/null
@@ -1,168 +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 return -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 return -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 OPENSSL_assert(l <= sizeof c->iv);
94 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
95 if (i != l)
96 return(-1);
97 else if (i > 0)
98 memcpy(c->iv,c->oiv,l);
99 }
100 return(i);
101 }
102
103int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
104 {
105 int i=0,j;
106
107 if (type != NULL)
108 {
109 j=EVP_CIPHER_CTX_iv_length(c);
110 OPENSSL_assert(j <= sizeof c->iv);
111 i=ASN1_TYPE_set_octetstring(type,c->oiv,j);
112 }
113 return(i);
114 }
115
116/* Convert the various cipher NIDs and dummies to a proper OID NID */
117int EVP_CIPHER_type(const EVP_CIPHER *ctx)
118{
119 int nid;
120 ASN1_OBJECT *otmp;
121 nid = EVP_CIPHER_nid(ctx);
122
123 switch(nid) {
124
125 case NID_rc2_cbc:
126 case NID_rc2_64_cbc:
127 case NID_rc2_40_cbc:
128
129 return NID_rc2_cbc;
130
131 case NID_rc4:
132 case NID_rc4_40:
133
134 return NID_rc4;
135
136 case NID_aes_128_cfb128:
137 case NID_aes_128_cfb8:
138 case NID_aes_128_cfb1:
139
140 return NID_aes_128_cfb128;
141
142 case NID_aes_192_cfb128:
143 case NID_aes_192_cfb8:
144 case NID_aes_192_cfb1:
145
146 return NID_aes_192_cfb128;
147
148 case NID_aes_256_cfb128:
149 case NID_aes_256_cfb8:
150 case NID_aes_256_cfb1:
151
152 return NID_aes_256_cfb128;
153
154 case NID_des_cfb64:
155 case NID_des_cfb8:
156 case NID_des_cfb1:
157
158 return NID_des_cfb64;
159
160 default:
161 /* Check it has an OID and it is valid */
162 otmp = OBJ_nid2obj(nid);
163 if(!otmp || !otmp->data) nid = NID_undef;
164 ASN1_OBJECT_free(otmp);
165 return nid;
166 }
167}
168
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h
deleted file mode 100644
index f8c5343620..0000000000
--- a/src/lib/libcrypto/evp/evp_locl.h
+++ /dev/null
@@ -1,252 +0,0 @@
1/* evp_locl.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Macros to code block cipher wrappers */
60
61/* Wrapper functions for each cipher mode */
62
63#define BLOCK_CIPHER_ecb_loop() \
64 unsigned int i, bl; \
65 bl = ctx->cipher->block_size;\
66 if(inl < bl) return 1;\
67 inl -= bl; \
68 for(i=0; i <= inl; i+=bl) \
69
70#define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
71static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
72{\
73 BLOCK_CIPHER_ecb_loop() \
74 cprefix##_ecb_encrypt(in + i, out + i, &((kstruct *)ctx->cipher_data)->ksched, ctx->encrypt);\
75 return 1;\
76}
77
78#define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
79static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
80{\
81 cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num);\
82 return 1;\
83}
84
85#define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
86static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
87{\
88 cprefix##_cbc_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);\
89 return 1;\
90}
91
92#define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
93static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
94{\
95 cprefix##_cfb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\
96 return 1;\
97}
98
99#define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
100 BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
101 BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
102 BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
103 BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
104
105#define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \
106 key_len, iv_len, flags, init_key, cleanup, \
107 set_asn1, get_asn1, ctrl) \
108static const EVP_CIPHER cname##_##mode = { \
109 nid##_##nmode, block_size, key_len, iv_len, \
110 flags | EVP_CIPH_##MODE##_MODE, \
111 init_key, \
112 cname##_##mode##_cipher, \
113 cleanup, \
114 sizeof(kstruct), \
115 set_asn1, get_asn1,\
116 ctrl, \
117 NULL \
118}; \
119const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }
120
121#define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \
122 iv_len, flags, init_key, cleanup, set_asn1, \
123 get_asn1, ctrl) \
124BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \
125 iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
126
127#define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \
128 iv_len, cbits, flags, init_key, cleanup, \
129 set_asn1, get_asn1, ctrl) \
130BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \
131 key_len, iv_len, flags, init_key, cleanup, set_asn1, \
132 get_asn1, ctrl)
133
134#define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \
135 iv_len, cbits, flags, init_key, cleanup, \
136 set_asn1, get_asn1, ctrl) \
137BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \
138 key_len, iv_len, flags, init_key, cleanup, set_asn1, \
139 get_asn1, ctrl)
140
141#define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \
142 iv_len, flags, init_key, cleanup, set_asn1, \
143 get_asn1, ctrl) \
144BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \
145 iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
146
147#define BLOCK_CIPHER_defs(cname, kstruct, \
148 nid, block_size, key_len, iv_len, cbits, flags, \
149 init_key, cleanup, set_asn1, get_asn1, ctrl) \
150BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
151 init_key, cleanup, set_asn1, get_asn1, ctrl) \
152BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \
153 flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
154BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \
155 flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
156BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
157 init_key, cleanup, set_asn1, get_asn1, ctrl)
158
159
160/*
161#define BLOCK_CIPHER_defs(cname, kstruct, \
162 nid, block_size, key_len, iv_len, flags,\
163 init_key, cleanup, set_asn1, get_asn1, ctrl)\
164static const EVP_CIPHER cname##_cbc = {\
165 nid##_cbc, block_size, key_len, iv_len, \
166 flags | EVP_CIPH_CBC_MODE,\
167 init_key,\
168 cname##_cbc_cipher,\
169 cleanup,\
170 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
171 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
172 set_asn1, get_asn1,\
173 ctrl, \
174 NULL \
175};\
176const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
177static const EVP_CIPHER cname##_cfb = {\
178 nid##_cfb64, 1, key_len, iv_len, \
179 flags | EVP_CIPH_CFB_MODE,\
180 init_key,\
181 cname##_cfb_cipher,\
182 cleanup,\
183 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
184 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
185 set_asn1, get_asn1,\
186 ctrl,\
187 NULL \
188};\
189const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
190static const EVP_CIPHER cname##_ofb = {\
191 nid##_ofb64, 1, key_len, iv_len, \
192 flags | EVP_CIPH_OFB_MODE,\
193 init_key,\
194 cname##_ofb_cipher,\
195 cleanup,\
196 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
197 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
198 set_asn1, get_asn1,\
199 ctrl,\
200 NULL \
201};\
202const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
203static const EVP_CIPHER cname##_ecb = {\
204 nid##_ecb, block_size, key_len, iv_len, \
205 flags | EVP_CIPH_ECB_MODE,\
206 init_key,\
207 cname##_ecb_cipher,\
208 cleanup,\
209 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
210 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
211 set_asn1, get_asn1,\
212 ctrl,\
213 NULL \
214};\
215const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
216*/
217
218#define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \
219 block_size, key_len, iv_len, cbits, \
220 flags, init_key, \
221 cleanup, set_asn1, get_asn1, ctrl) \
222 BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
223 BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \
224 cbits, flags, init_key, cleanup, set_asn1, \
225 get_asn1, ctrl)
226
227#define EVP_C_DATA(kstruct, ctx) ((kstruct *)(ctx)->cipher_data)
228
229#define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,flags) \
230 BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
231 BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
232 NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
233 flags, cipher##_init_key, NULL, \
234 EVP_CIPHER_set_asn1_iv, \
235 EVP_CIPHER_get_asn1_iv, \
236 NULL)
237
238#ifdef OPENSSL_FIPS
239#define RC2_set_key private_RC2_set_key
240#define RC4_set_key private_RC4_set_key
241#define CAST_set_key private_CAST_set_key
242#define RC5_32_set_key private_RC5_32_set_key
243#define BF_set_key private_BF_set_key
244#define idea_set_encrypt_key private_idea_set_encrypt_key
245
246#define MD5_Init private_MD5_Init
247#define MD4_Init private_MD4_Init
248#define MD2_Init private_MD2_Init
249#define MDC2_Init private_MDC2_Init
250#define SHA_Init private_SHA_Init
251
252#endif
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
deleted file mode 100644
index 91e545a141..0000000000
--- a/src/lib/libcrypto/evp/evp_pbe.c
+++ /dev/null
@@ -1,136 +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 "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/x509.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;
72const EVP_CIPHER *cipher;
73const EVP_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) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
91 else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj);
92 ERR_add_error_data(2, "TYPE=", obj_tmp);
93 return 0;
94 }
95 if(!pass) passlen = 0;
96 else if (passlen == -1) passlen = strlen(pass);
97 pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
98 i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,
99 pbetmp->md, en_de);
100 if (!i) {
101 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
102 return 0;
103 }
104 return 1;
105}
106
107static int pbe_cmp(const char * const *a, const char * const *b)
108{
109 EVP_PBE_CTL **pbe1 = (EVP_PBE_CTL **) a, **pbe2 = (EVP_PBE_CTL **)b;
110 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
111}
112
113/* Add a PBE algorithm */
114
115int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
116 EVP_PBE_KEYGEN *keygen)
117{
118 EVP_PBE_CTL *pbe_tmp;
119 if (!pbe_algs) pbe_algs = sk_new(pbe_cmp);
120 if (!(pbe_tmp = (EVP_PBE_CTL*) OPENSSL_malloc (sizeof(EVP_PBE_CTL)))) {
121 EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
122 return 0;
123 }
124 pbe_tmp->pbe_nid = nid;
125 pbe_tmp->cipher = cipher;
126 pbe_tmp->md = md;
127 pbe_tmp->keygen = keygen;
128 sk_push (pbe_algs, (char *)pbe_tmp);
129 return 1;
130}
131
132void EVP_PBE_cleanup(void)
133{
134 sk_pop_free(pbe_algs, OPENSSL_freeFunc);
135 pbe_algs = NULL;
136}
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
deleted file mode 100644
index 47a69932a5..0000000000
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ /dev/null
@@ -1,468 +0,0 @@
1/* evp_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65#ifndef OPENSSL_NO_DSA
66static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
67#endif
68
69/* Extract a private key from a PKCS8 structure */
70
71EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
72{
73 EVP_PKEY *pkey = NULL;
74#ifndef OPENSSL_NO_RSA
75 RSA *rsa = NULL;
76#endif
77#ifndef OPENSSL_NO_DSA
78 DSA *dsa = NULL;
79 ASN1_INTEGER *privkey;
80 ASN1_TYPE *t1, *t2, *param = NULL;
81 STACK_OF(ASN1_TYPE) *ndsa = NULL;
82 BN_CTX *ctx = NULL;
83 int plen;
84#endif
85 X509_ALGOR *a;
86 unsigned char *p;
87 const unsigned char *cp;
88 int pkeylen;
89 char obj_tmp[80];
90
91 if(p8->pkey->type == V_ASN1_OCTET_STRING) {
92 p8->broken = PKCS8_OK;
93 p = p8->pkey->value.octet_string->data;
94 pkeylen = p8->pkey->value.octet_string->length;
95 } else {
96 p8->broken = PKCS8_NO_OCTET;
97 p = p8->pkey->value.sequence->data;
98 pkeylen = p8->pkey->value.sequence->length;
99 }
100 if (!(pkey = EVP_PKEY_new())) {
101 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104 a = p8->pkeyalg;
105 switch (OBJ_obj2nid(a->algorithm))
106 {
107#ifndef OPENSSL_NO_RSA
108 case NID_rsaEncryption:
109 cp = p;
110 if (!(rsa = d2i_RSAPrivateKey (NULL,&cp, pkeylen))) {
111 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
112 return NULL;
113 }
114 EVP_PKEY_assign_RSA (pkey, rsa);
115 break;
116#endif
117#ifndef OPENSSL_NO_DSA
118 case NID_dsa:
119 /* PKCS#8 DSA is weird: you just get a private key integer
120 * and parameters in the AlgorithmIdentifier the pubkey must
121 * be recalculated.
122 */
123
124 /* Check for broken DSA PKCS#8, UGH! */
125 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
126 if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen,
127 d2i_ASN1_TYPE,
128 ASN1_TYPE_free))) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 goto dsaerr;
131 }
132 if(sk_ASN1_TYPE_num(ndsa) != 2 ) {
133 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
134 goto dsaerr;
135 }
136 /* Handle Two broken types:
137 * SEQUENCE {parameters, priv_key}
138 * SEQUENCE {pub_key, priv_key}
139 */
140
141 t1 = sk_ASN1_TYPE_value(ndsa, 0);
142 t2 = sk_ASN1_TYPE_value(ndsa, 1);
143 if(t1->type == V_ASN1_SEQUENCE) {
144 p8->broken = PKCS8_EMBEDDED_PARAM;
145 param = t1;
146 } else if(a->parameter->type == V_ASN1_SEQUENCE) {
147 p8->broken = PKCS8_NS_DB;
148 param = a->parameter;
149 } else {
150 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
151 goto dsaerr;
152 }
153
154 if(t2->type != V_ASN1_INTEGER) {
155 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
156 goto dsaerr;
157 }
158 privkey = t2->value.integer;
159 } else {
160 if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
161 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
162 goto dsaerr;
163 }
164 param = p8->pkeyalg->parameter;
165 }
166 if (!param || (param->type != V_ASN1_SEQUENCE)) {
167 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
168 goto dsaerr;
169 }
170 cp = p = param->value.sequence->data;
171 plen = param->value.sequence->length;
172 if (!(dsa = d2i_DSAparams (NULL, &cp, plen))) {
173 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
174 goto dsaerr;
175 }
176 /* We have parameters now set private key */
177 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
178 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
179 goto dsaerr;
180 }
181 /* Calculate public key (ouch!) */
182 if (!(dsa->pub_key = BN_new())) {
183 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
184 goto dsaerr;
185 }
186 if (!(ctx = BN_CTX_new())) {
187 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
188 goto dsaerr;
189 }
190
191 if (!BN_mod_exp(dsa->pub_key, dsa->g,
192 dsa->priv_key, dsa->p, ctx)) {
193
194 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
195 goto dsaerr;
196 }
197
198 EVP_PKEY_assign_DSA(pkey, dsa);
199 BN_CTX_free (ctx);
200 if(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
201 else ASN1_INTEGER_free(privkey);
202 break;
203 dsaerr:
204 BN_CTX_free (ctx);
205 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
206 DSA_free(dsa);
207 EVP_PKEY_free(pkey);
208 return NULL;
209 break;
210#endif
211 default:
212 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
213 if (!a->algorithm) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
214 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
215 ERR_add_error_data(2, "TYPE=", obj_tmp);
216 EVP_PKEY_free (pkey);
217 return NULL;
218 }
219 return pkey;
220}
221
222PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
223{
224 return EVP_PKEY2PKCS8_broken(pkey, PKCS8_OK);
225}
226
227/* Turn a private key into a PKCS8 structure */
228
229PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
230{
231 PKCS8_PRIV_KEY_INFO *p8;
232
233 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
234 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
235 return NULL;
236 }
237 p8->broken = broken;
238 if (!ASN1_INTEGER_set(p8->version, 0)) {
239 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
240 PKCS8_PRIV_KEY_INFO_free (p8);
241 return NULL;
242 }
243 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
244 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
245 PKCS8_PRIV_KEY_INFO_free (p8);
246 return NULL;
247 }
248 p8->pkey->type = V_ASN1_OCTET_STRING;
249 switch (EVP_PKEY_type(pkey->type)) {
250#ifndef OPENSSL_NO_RSA
251 case EVP_PKEY_RSA:
252
253 if(p8->broken == PKCS8_NO_OCTET) p8->pkey->type = V_ASN1_SEQUENCE;
254
255 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
256 p8->pkeyalg->parameter->type = V_ASN1_NULL;
257 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
258 &p8->pkey->value.octet_string)) {
259 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
260 PKCS8_PRIV_KEY_INFO_free (p8);
261 return NULL;
262 }
263 break;
264#endif
265#ifndef OPENSSL_NO_DSA
266 case EVP_PKEY_DSA:
267 if(!dsa_pkey2pkcs8(p8, pkey)) {
268 PKCS8_PRIV_KEY_INFO_free (p8);
269 return NULL;
270 }
271
272 break;
273#endif
274 default:
275 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
276 PKCS8_PRIV_KEY_INFO_free (p8);
277 return NULL;
278 }
279 RAND_add(p8->pkey->value.octet_string->data,
280 p8->pkey->value.octet_string->length, 0);
281 return p8;
282}
283
284PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
285{
286 switch (broken) {
287
288 case PKCS8_OK:
289 p8->broken = PKCS8_OK;
290 return p8;
291 break;
292
293 case PKCS8_NO_OCTET:
294 p8->broken = PKCS8_NO_OCTET;
295 p8->pkey->type = V_ASN1_SEQUENCE;
296 return p8;
297 break;
298
299 default:
300 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
301 return NULL;
302 break;
303
304 }
305}
306
307#ifndef OPENSSL_NO_DSA
308static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
309{
310 ASN1_STRING *params = NULL;
311 ASN1_INTEGER *prkey = NULL;
312 ASN1_TYPE *ttmp = NULL;
313 STACK_OF(ASN1_TYPE) *ndsa = NULL;
314 unsigned char *p = NULL, *q;
315 int len;
316
317 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
318 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
319 if (!(p = OPENSSL_malloc(len))) {
320 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
321 goto err;
322 }
323 q = p;
324 i2d_DSAparams (pkey->pkey.dsa, &q);
325 if (!(params = ASN1_STRING_new())) {
326 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
327 goto err;
328 }
329 if (!ASN1_STRING_set(params, p, len)) {
330 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
331 goto err;
332 }
333 OPENSSL_free(p);
334 p = NULL;
335 /* Get private key into integer */
336 if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
337 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
338 goto err;
339 }
340
341 switch(p8->broken) {
342
343 case PKCS8_OK:
344 case PKCS8_NO_OCTET:
345
346 if (!ASN1_pack_string((char *)prkey, i2d_ASN1_INTEGER,
347 &p8->pkey->value.octet_string)) {
348 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
349 goto err;
350 }
351
352 M_ASN1_INTEGER_free (prkey);
353 prkey = NULL;
354 p8->pkeyalg->parameter->value.sequence = params;
355 params = NULL;
356 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
357
358 break;
359
360 case PKCS8_NS_DB:
361
362 p8->pkeyalg->parameter->value.sequence = params;
363 params = NULL;
364 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
365 if (!(ndsa = sk_ASN1_TYPE_new_null())) {
366 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
367 goto err;
368 }
369 if (!(ttmp = ASN1_TYPE_new())) {
370 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
371 goto err;
372 }
373 if (!(ttmp->value.integer =
374 BN_to_ASN1_INTEGER(pkey->pkey.dsa->pub_key, NULL))) {
375 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
376 goto err;
377 }
378 ttmp->type = V_ASN1_INTEGER;
379 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
380 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
381 goto err;
382 }
383
384 if (!(ttmp = ASN1_TYPE_new())) {
385 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
386 goto err;
387 }
388 ttmp->value.integer = prkey;
389 prkey = NULL;
390 ttmp->type = V_ASN1_INTEGER;
391 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
392 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
393 goto err;
394 }
395 ttmp = NULL;
396
397 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
398 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
399 goto err;
400 }
401
402 if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
403 &p8->pkey->value.octet_string->data,
404 &p8->pkey->value.octet_string->length)) {
405
406 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
407 goto err;
408 }
409 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
410 break;
411
412 case PKCS8_EMBEDDED_PARAM:
413
414 p8->pkeyalg->parameter->type = V_ASN1_NULL;
415 if (!(ndsa = sk_ASN1_TYPE_new_null())) {
416 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
417 goto err;
418 }
419 if (!(ttmp = ASN1_TYPE_new())) {
420 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
421 goto err;
422 }
423 ttmp->value.sequence = params;
424 params = NULL;
425 ttmp->type = V_ASN1_SEQUENCE;
426 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
427 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
428 goto err;
429 }
430
431 if (!(ttmp = ASN1_TYPE_new())) {
432 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
433 goto err;
434 }
435 ttmp->value.integer = prkey;
436 prkey = NULL;
437 ttmp->type = V_ASN1_INTEGER;
438 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
439 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
440 goto err;
441 }
442 ttmp = NULL;
443
444 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
445 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
446 goto err;
447 }
448
449 if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
450 &p8->pkey->value.octet_string->data,
451 &p8->pkey->value.octet_string->length)) {
452
453 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
454 goto err;
455 }
456 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
457 break;
458 }
459 return 1;
460err:
461 if (p != NULL) OPENSSL_free(p);
462 if (params != NULL) ASN1_STRING_free(params);
463 if (prkey != NULL) M_ASN1_INTEGER_free(prkey);
464 if (ttmp != NULL) ASN1_TYPE_free(ttmp);
465 if (ndsa != NULL) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
466 return 0;
467}
468#endif
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c
deleted file mode 100644
index d393eb3400..0000000000
--- a/src/lib/libcrypto/evp/m_dss.c
+++ /dev/null
@@ -1,95 +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 OPENSSL_NO_SHA
66static int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70 { return SHA1_Update(ctx->md_data,data,count); }
71
72static int final(EVP_MD_CTX *ctx,unsigned char *md)
73 { return SHA1_Final(md,ctx->md_data); }
74
75static const EVP_MD dsa_md=
76 {
77 NID_dsaWithSHA,
78 NID_dsaWithSHA,
79 SHA_DIGEST_LENGTH,
80 EVP_MD_FLAG_FIPS,
81 init,
82 update,
83 final,
84 NULL,
85 NULL,
86 EVP_PKEY_DSA_method,
87 SHA_CBLOCK,
88 sizeof(EVP_MD *)+sizeof(SHA_CTX),
89 };
90
91const EVP_MD *EVP_dss(void)
92 {
93 return(&dsa_md);
94 }
95#endif
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c
deleted file mode 100644
index 23b90d0538..0000000000
--- a/src/lib/libcrypto/evp/m_dss1.c
+++ /dev/null
@@ -1,102 +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 OPENSSL_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 int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70#ifndef OPENSSL_FIPS
71 { return SHA1_Update(ctx->md_data,data,count); }
72#else
73 {
74 OPENSSL_assert(sizeof(count)<=sizeof(size_t));
75 return SHA1_Update(ctx->md_data,data,count);
76 }
77#endif
78
79static int final(EVP_MD_CTX *ctx,unsigned char *md)
80 { return SHA1_Final(md,ctx->md_data); }
81
82static const EVP_MD dss1_md=
83 {
84 NID_dsa,
85 NID_dsaWithSHA1,
86 SHA_DIGEST_LENGTH,
87 EVP_MD_FLAG_FIPS,
88 init,
89 update,
90 final,
91 NULL,
92 NULL,
93 EVP_PKEY_DSA_method,
94 SHA_CBLOCK,
95 sizeof(EVP_MD *)+sizeof(SHA_CTX),
96 };
97
98const EVP_MD *EVP_dss1(void)
99 {
100 return(&dss1_md);
101 }
102#endif
diff --git a/src/lib/libcrypto/evp/m_md4.c b/src/lib/libcrypto/evp/m_md4.c
deleted file mode 100644
index 0605e4b707..0000000000
--- a/src/lib/libcrypto/evp/m_md4.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/* crypto/evp/m_md4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_MD4
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/md4.h>
67
68static int init(EVP_MD_CTX *ctx)
69 { return MD4_Init(ctx->md_data); }
70
71static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
72 { return MD4_Update(ctx->md_data,data,count); }
73
74static int final(EVP_MD_CTX *ctx,unsigned char *md)
75 { return MD4_Final(md,ctx->md_data); }
76
77static const EVP_MD md4_md=
78 {
79 NID_md4,
80 NID_md4WithRSAEncryption,
81 MD4_DIGEST_LENGTH,
82 0,
83 init,
84 update,
85 final,
86 NULL,
87 NULL,
88 EVP_PKEY_RSA_method,
89 MD4_CBLOCK,
90 sizeof(EVP_MD *)+sizeof(MD4_CTX),
91 };
92
93const EVP_MD *EVP_md4(void)
94 {
95 return(&md4_md);
96 }
97#endif
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c
deleted file mode 100644
index 752615d473..0000000000
--- a/src/lib/libcrypto/evp/m_md5.c
+++ /dev/null
@@ -1,97 +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 OPENSSL_NO_MD5
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/md5.h>
67
68static int init(EVP_MD_CTX *ctx)
69 { return MD5_Init(ctx->md_data); }
70
71static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
72 { return MD5_Update(ctx->md_data,data,count); }
73
74static int final(EVP_MD_CTX *ctx,unsigned char *md)
75 { return MD5_Final(md,ctx->md_data); }
76
77static const EVP_MD md5_md=
78 {
79 NID_md5,
80 NID_md5WithRSAEncryption,
81 MD5_DIGEST_LENGTH,
82 0,
83 init,
84 update,
85 final,
86 NULL,
87 NULL,
88 EVP_PKEY_RSA_method,
89 MD5_CBLOCK,
90 sizeof(EVP_MD *)+sizeof(MD5_CTX),
91 };
92
93const EVP_MD *EVP_md5(void)
94 {
95 return(&md5_md);
96 }
97#endif
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c
deleted file mode 100644
index f6f0a1d2c0..0000000000
--- a/src/lib/libcrypto/evp/m_null.c
+++ /dev/null
@@ -1,95 +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 int init(EVP_MD_CTX *ctx)
66 { return 1; }
67
68static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
69 { return 1; }
70
71static int final(EVP_MD_CTX *ctx,unsigned char *md)
72 { return 1; }
73
74static const EVP_MD null_md=
75 {
76 NID_undef,
77 NID_undef,
78 0,
79 0,
80 init,
81 update,
82 final,
83 NULL,
84 NULL,
85 EVP_PKEY_NULL_method,
86 0,
87 sizeof(EVP_MD *),
88 };
89
90const EVP_MD *EVP_md_null(void)
91 {
92 return(&null_md);
93 }
94
95
diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c
deleted file mode 100644
index 64725528dc..0000000000
--- a/src/lib/libcrypto/evp/m_ripemd.c
+++ /dev/null
@@ -1,96 +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 OPENSSL_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 int init(EVP_MD_CTX *ctx)
68 { return RIPEMD160_Init(ctx->md_data); }
69
70static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
71 { return RIPEMD160_Update(ctx->md_data,data,count); }
72
73static int final(EVP_MD_CTX *ctx,unsigned char *md)
74 { return RIPEMD160_Final(md,ctx->md_data); }
75
76static const EVP_MD ripemd160_md=
77 {
78 NID_ripemd160,
79 NID_ripemd160WithRSA,
80 RIPEMD160_DIGEST_LENGTH,
81 0,
82 init,
83 update,
84 final,
85 NULL,
86 NULL,
87 EVP_PKEY_RSA_method,
88 RIPEMD160_CBLOCK,
89 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
90 };
91
92const EVP_MD *EVP_ripemd160(void)
93 {
94 return(&ripemd160_md);
95 }
96#endif
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c
deleted file mode 100644
index 60da93873c..0000000000
--- a/src/lib/libcrypto/evp/m_sha1.c
+++ /dev/null
@@ -1,214 +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 OPENSSL_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 int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70#ifndef OPENSSL_FIPS
71 { return SHA1_Update(ctx->md_data,data,count); }
72#else
73 {
74 OPENSSL_assert(sizeof(count)<=sizeof(size_t));
75 return SHA1_Update(ctx->md_data,data,count);
76 }
77#endif
78
79static int final(EVP_MD_CTX *ctx,unsigned char *md)
80 { return SHA1_Final(md,ctx->md_data); }
81
82static const EVP_MD sha1_md=
83 {
84 NID_sha1,
85 NID_sha1WithRSAEncryption,
86 SHA_DIGEST_LENGTH,
87 EVP_MD_FLAG_FIPS,
88 init,
89 update,
90 final,
91 NULL,
92 NULL,
93 EVP_PKEY_RSA_method,
94 SHA_CBLOCK,
95 sizeof(EVP_MD *)+sizeof(SHA_CTX),
96 };
97
98const EVP_MD *EVP_sha1(void)
99 {
100 return(&sha1_md);
101 }
102#endif
103
104#ifdef OPENSSL_FIPS
105#ifndef OPENSSL_NO_SHA256
106static int init224(EVP_MD_CTX *ctx)
107 { return SHA224_Init(ctx->md_data); }
108static int init256(EVP_MD_CTX *ctx)
109 { return SHA256_Init(ctx->md_data); }
110/*
111 * Even though there're separate SHA224_[Update|Final], we call
112 * SHA256 functions even in SHA224 context. This is what happens
113 * there anyway, so we can spare few CPU cycles:-)
114 */
115static int update256(EVP_MD_CTX *ctx,const void *data,unsigned long count)
116 {
117 OPENSSL_assert(sizeof(count)<=sizeof(size_t));
118 return SHA256_Update(ctx->md_data,data,count);
119 }
120static int final256(EVP_MD_CTX *ctx,unsigned char *md)
121 { return SHA256_Final(md,ctx->md_data); }
122
123static const EVP_MD sha224_md=
124 {
125 NID_sha224,
126 NID_sha224WithRSAEncryption,
127 SHA224_DIGEST_LENGTH,
128 EVP_MD_FLAG_FIPS,
129 init224,
130 update256,
131 final256,
132 NULL,
133 NULL,
134 EVP_PKEY_RSA_method,
135 SHA256_CBLOCK,
136 sizeof(EVP_MD *)+sizeof(SHA256_CTX),
137 };
138
139const EVP_MD *EVP_sha224(void)
140 { return(&sha224_md); }
141
142static const EVP_MD sha256_md=
143 {
144 NID_sha256,
145 NID_sha256WithRSAEncryption,
146 SHA256_DIGEST_LENGTH,
147 EVP_MD_FLAG_FIPS,
148 init256,
149 update256,
150 final256,
151 NULL,
152 NULL,
153 EVP_PKEY_RSA_method,
154 SHA256_CBLOCK,
155 sizeof(EVP_MD *)+sizeof(SHA256_CTX),
156 };
157
158const EVP_MD *EVP_sha256(void)
159 { return(&sha256_md); }
160#endif /* ifndef OPENSSL_NO_SHA256 */
161
162#ifndef OPENSSL_NO_SHA512
163static int init384(EVP_MD_CTX *ctx)
164 { return SHA384_Init(ctx->md_data); }
165static int init512(EVP_MD_CTX *ctx)
166 { return SHA512_Init(ctx->md_data); }
167/* See comment in SHA224/256 section */
168static int update512(EVP_MD_CTX *ctx,const void *data,unsigned long count)
169 {
170 OPENSSL_assert(sizeof(count)<=sizeof(size_t));
171 return SHA512_Update(ctx->md_data,data,count);
172 }
173static int final512(EVP_MD_CTX *ctx,unsigned char *md)
174 { return SHA512_Final(md,ctx->md_data); }
175
176static const EVP_MD sha384_md=
177 {
178 NID_sha384,
179 NID_sha384WithRSAEncryption,
180 SHA384_DIGEST_LENGTH,
181 EVP_MD_FLAG_FIPS,
182 init384,
183 update512,
184 final512,
185 NULL,
186 NULL,
187 EVP_PKEY_RSA_method,
188 SHA512_CBLOCK,
189 sizeof(EVP_MD *)+sizeof(SHA512_CTX),
190 };
191
192const EVP_MD *EVP_sha384(void)
193 { return(&sha384_md); }
194
195static const EVP_MD sha512_md=
196 {
197 NID_sha512,
198 NID_sha512WithRSAEncryption,
199 SHA512_DIGEST_LENGTH,
200 EVP_MD_FLAG_FIPS,
201 init512,
202 update512,
203 final512,
204 NULL,
205 NULL,
206 EVP_PKEY_RSA_method,
207 SHA512_CBLOCK,
208 sizeof(EVP_MD *)+sizeof(SHA512_CTX),
209 };
210
211const EVP_MD *EVP_sha512(void)
212 { return(&sha512_md); }
213#endif /* ifndef OPENSSL_NO_SHA512 */
214#endif /* ifdef OPENSSL_FIPS */
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c
deleted file mode 100644
index 7712453046..0000000000
--- a/src/lib/libcrypto/evp/names.c
+++ /dev/null
@@ -1,126 +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#ifdef OPENSSL_FIPS
65#include <openssl/fips.h>
66#endif
67
68int EVP_add_cipher(const EVP_CIPHER *c)
69 {
70 int r;
71
72 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
73 if (r == 0) return(0);
74 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
75 return(r);
76 }
77
78int EVP_add_digest(const EVP_MD *md)
79 {
80 int r;
81 const char *name;
82
83 name=OBJ_nid2sn(md->type);
84 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md);
85 if (r == 0) return(0);
86 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md);
87 if (r == 0) return(0);
88
89 if (md->type != md->pkey_type)
90 {
91 r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
92 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
93 if (r == 0) return(0);
94 r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
95 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
96 }
97 return(r);
98 }
99
100const EVP_CIPHER *EVP_get_cipherbyname(const char *name)
101 {
102 const EVP_CIPHER *cp;
103
104 cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH);
105 return(cp);
106 }
107
108const EVP_MD *EVP_get_digestbyname(const char *name)
109 {
110 const EVP_MD *cp;
111
112 cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH);
113 return(cp);
114 }
115
116void EVP_cleanup(void)
117 {
118 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH);
119 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH);
120 /* The above calls will only clean out the contents of the name
121 hash table, but not the hash table itself. The following line
122 does that part. -- Richard Levitte */
123 OBJ_NAME_cleanup(-1);
124
125 EVP_PBE_cleanup();
126 }
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
deleted file mode 100644
index a1874e83b2..0000000000
--- a/src/lib/libcrypto/evp/p5_crpt.c
+++ /dev/null
@@ -1,153 +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 "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/evp.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 OPENSSL_NO_DES
71# ifndef OPENSSL_NO_MD5
72EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(),
73 PKCS5_PBE_keyivgen);
74# endif
75# ifndef OPENSSL_NO_MD2
76EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(),
77 PKCS5_PBE_keyivgen);
78# endif
79# ifndef OPENSSL_NO_SHA
80EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(),
81 PKCS5_PBE_keyivgen);
82# endif
83#endif
84#ifndef OPENSSL_NO_RC2
85# ifndef OPENSSL_NO_MD5
86EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(),
87 PKCS5_PBE_keyivgen);
88# endif
89# ifndef OPENSSL_NO_MD2
90EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(),
91 PKCS5_PBE_keyivgen);
92# endif
93# ifndef OPENSSL_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 OPENSSL_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, const EVP_CIPHER *cipher, const 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 if(!pass) passlen = 0;
129 else if(passlen == -1) passlen = strlen(pass);
130
131 EVP_MD_CTX_init(&ctx);
132 EVP_DigestInit_ex(&ctx, md, NULL);
133 EVP_DigestUpdate(&ctx, pass, passlen);
134 EVP_DigestUpdate(&ctx, salt, saltlen);
135 PBEPARAM_free(pbe);
136 EVP_DigestFinal_ex(&ctx, md_tmp, NULL);
137 for (i = 1; i < iter; i++) {
138 EVP_DigestInit_ex(&ctx, md, NULL);
139 EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
140 EVP_DigestFinal_ex (&ctx, md_tmp, NULL);
141 }
142 EVP_MD_CTX_cleanup(&ctx);
143 OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= sizeof md_tmp);
144 memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher));
145 OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16);
146 memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
147 EVP_CIPHER_iv_length(cipher));
148 EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de);
149 OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE);
150 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
151 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH);
152 return 1;
153}
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
deleted file mode 100644
index 1d5fabc4b2..0000000000
--- a/src/lib/libcrypto/evp/p5_crpt2.c
+++ /dev/null
@@ -1,256 +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(OPENSSL_NO_HMAC) && !defined(OPENSSL_NO_SHA)
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/evp.h>
64#include <openssl/hmac.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
88 HMAC_CTX_init(&hctx);
89 p = out;
90 tkeylen = keylen;
91 if(!pass) passlen = 0;
92 else if(passlen == -1) passlen = strlen(pass);
93 while(tkeylen) {
94 if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH;
95 else cplen = tkeylen;
96 /* We are unlikely to ever use more than 256 blocks (5120 bits!)
97 * but just in case...
98 */
99 itmp[0] = (unsigned char)((i >> 24) & 0xff);
100 itmp[1] = (unsigned char)((i >> 16) & 0xff);
101 itmp[2] = (unsigned char)((i >> 8) & 0xff);
102 itmp[3] = (unsigned char)(i & 0xff);
103 HMAC_Init_ex(&hctx, pass, passlen, EVP_sha1(), NULL);
104 HMAC_Update(&hctx, salt, saltlen);
105 HMAC_Update(&hctx, itmp, 4);
106 HMAC_Final(&hctx, digtmp, NULL);
107 memcpy(p, digtmp, cplen);
108 for(j = 1; j < iter; j++) {
109 HMAC(EVP_sha1(), pass, passlen,
110 digtmp, SHA_DIGEST_LENGTH, digtmp, NULL);
111 for(k = 0; k < cplen; k++) p[k] ^= digtmp[k];
112 }
113 tkeylen-= cplen;
114 i++;
115 p+= cplen;
116 }
117 HMAC_CTX_cleanup(&hctx);
118#ifdef DEBUG_PKCS5V2
119 fprintf(stderr, "Password:\n");
120 h__dump (pass, passlen);
121 fprintf(stderr, "Salt:\n");
122 h__dump (salt, saltlen);
123 fprintf(stderr, "Iteration count %d\n", iter);
124 fprintf(stderr, "Key:\n");
125 h__dump (out, keylen);
126#endif
127 return 1;
128}
129
130#ifdef DO_TEST
131main()
132{
133 unsigned char out[4];
134 unsigned char salt[] = {0x12, 0x34, 0x56, 0x78};
135 PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out);
136 fprintf(stderr, "Out %02X %02X %02X %02X\n",
137 out[0], out[1], out[2], out[3]);
138}
139
140#endif
141
142/* Now the key derivation function itself. This is a bit evil because
143 * it has to check the ASN1 parameters are valid: and there are quite a
144 * few of them...
145 */
146
147int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
148 ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md,
149 int en_de)
150{
151 unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH];
152 int saltlen, keylen, iter, plen;
153 PBE2PARAM *pbe2 = NULL;
154 const EVP_CIPHER *cipher;
155 PBKDF2PARAM *kdf = NULL;
156
157 pbuf = param->value.sequence->data;
158 plen = param->value.sequence->length;
159 if(!param || (param->type != V_ASN1_SEQUENCE) ||
160 !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
161 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
162 return 0;
163 }
164
165 /* See if we recognise the key derivation function */
166
167 if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
168 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
169 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
170 goto err;
171 }
172
173 /* lets see if we recognise the encryption algorithm.
174 */
175
176 cipher = EVP_get_cipherbyname(
177 OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
178
179 if(!cipher) {
180 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
181 EVP_R_UNSUPPORTED_CIPHER);
182 goto err;
183 }
184
185 /* Fixup cipher based on AlgorithmIdentifier */
186 EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, en_de);
187 if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
188 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
189 EVP_R_CIPHER_PARAMETER_ERROR);
190 goto err;
191 }
192 keylen = EVP_CIPHER_CTX_key_length(ctx);
193 OPENSSL_assert(keylen <= sizeof key);
194
195 /* Now decode key derivation function */
196
197 if(!pbe2->keyfunc->parameter ||
198 (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE))
199 {
200 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
201 goto err;
202 }
203
204 pbuf = pbe2->keyfunc->parameter->value.sequence->data;
205 plen = pbe2->keyfunc->parameter->value.sequence->length;
206 if(!(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
207 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
208 goto err;
209 }
210
211 PBE2PARAM_free(pbe2);
212 pbe2 = NULL;
213
214 /* Now check the parameters of the kdf */
215
216 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){
217 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
218 EVP_R_UNSUPPORTED_KEYLENGTH);
219 goto err;
220 }
221
222 if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
223 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
224 goto err;
225 }
226
227 if(kdf->salt->type != V_ASN1_OCTET_STRING) {
228 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
229 EVP_R_UNSUPPORTED_SALT_TYPE);
230 goto err;
231 }
232
233 /* it seems that its all OK */
234 salt = kdf->salt->value.octet_string->data;
235 saltlen = kdf->salt->value.octet_string->length;
236 iter = ASN1_INTEGER_get(kdf->iter);
237 PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
238 EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
239 OPENSSL_cleanse(key, keylen);
240 PBKDF2PARAM_free(kdf);
241 return 1;
242
243 err:
244 PBE2PARAM_free(pbe2);
245 PBKDF2PARAM_free(kdf);
246 return 0;
247}
248
249#ifdef DEBUG_PKCS5V2
250static void h__dump (const unsigned char *p, int len)
251{
252 for (; len --; p++) fprintf(stderr, "%02X ", *p);
253 fprintf(stderr, "\n");
254}
255#endif
256#endif
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c
deleted file mode 100644
index 8af620400e..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 OPENSSL_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 OPENSSL_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 OPENSSL_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 656883b996..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 OPENSSL_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 OPENSSL_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 OPENSSL_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 215b94292a..0000000000
--- a/src/lib/libcrypto/evp/p_lib.c
+++ /dev/null
@@ -1,337 +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);
67
68int EVP_PKEY_bits(EVP_PKEY *pkey)
69 {
70#ifndef OPENSSL_NO_RSA
71 if (pkey->type == EVP_PKEY_RSA)
72 return(BN_num_bits(pkey->pkey.rsa->n));
73 else
74#endif
75#ifndef OPENSSL_NO_DSA
76 if (pkey->type == EVP_PKEY_DSA)
77 return(BN_num_bits(pkey->pkey.dsa->p));
78#endif
79 return(0);
80 }
81
82int EVP_PKEY_size(EVP_PKEY *pkey)
83 {
84 if (pkey == NULL)
85 return(0);
86#ifndef OPENSSL_NO_RSA
87 if (pkey->type == EVP_PKEY_RSA)
88 return(RSA_size(pkey->pkey.rsa));
89 else
90#endif
91#ifndef OPENSSL_NO_DSA
92 if (pkey->type == EVP_PKEY_DSA)
93 return(DSA_size(pkey->pkey.dsa));
94#endif
95 return(0);
96 }
97
98int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
99 {
100#ifndef OPENSSL_NO_DSA
101 if (pkey->type == EVP_PKEY_DSA)
102 {
103 int ret=pkey->save_parameters;
104
105 if (mode >= 0)
106 pkey->save_parameters=mode;
107 return(ret);
108 }
109#endif
110 return(0);
111 }
112
113int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
114 {
115 if (to->type != from->type)
116 {
117 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
118 goto err;
119 }
120
121 if (EVP_PKEY_missing_parameters(from))
122 {
123 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
124 goto err;
125 }
126#ifndef OPENSSL_NO_DSA
127 if (to->type == EVP_PKEY_DSA)
128 {
129 BIGNUM *a;
130
131 if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
132 if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
133 to->pkey.dsa->p=a;
134
135 if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
136 if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
137 to->pkey.dsa->q=a;
138
139 if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
140 if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
141 to->pkey.dsa->g=a;
142 }
143#endif
144 return(1);
145err:
146 return(0);
147 }
148
149int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
150 {
151#ifndef OPENSSL_NO_DSA
152 if (pkey->type == EVP_PKEY_DSA)
153 {
154 DSA *dsa;
155
156 dsa=pkey->pkey.dsa;
157 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
158 return(1);
159 }
160#endif
161 return(0);
162 }
163
164int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
165 {
166#ifndef OPENSSL_NO_DSA
167 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
168 {
169 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
170 BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
171 BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
172 return(0);
173 else
174 return(1);
175 }
176#endif
177 return(-1);
178 }
179
180EVP_PKEY *EVP_PKEY_new(void)
181 {
182 EVP_PKEY *ret;
183
184 ret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));
185 if (ret == NULL)
186 {
187 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
188 return(NULL);
189 }
190 ret->type=EVP_PKEY_NONE;
191 ret->references=1;
192 ret->pkey.ptr=NULL;
193 ret->attributes=NULL;
194 ret->save_parameters=1;
195 return(ret);
196 }
197
198int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
199 {
200 if (pkey == NULL) return(0);
201 if (pkey->pkey.ptr != NULL)
202 EVP_PKEY_free_it(pkey);
203 pkey->type=EVP_PKEY_type(type);
204 pkey->save_type=type;
205 pkey->pkey.ptr=key;
206 return(key != NULL);
207 }
208
209#ifndef OPENSSL_NO_RSA
210int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
211{
212 int ret = EVP_PKEY_assign_RSA(pkey, key);
213 if(ret)
214 RSA_up_ref(key);
215 return ret;
216}
217
218RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
219 {
220 if(pkey->type != EVP_PKEY_RSA) {
221 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
222 return NULL;
223 }
224 RSA_up_ref(pkey->pkey.rsa);
225 return pkey->pkey.rsa;
226}
227#endif
228
229#ifndef OPENSSL_NO_DSA
230int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
231{
232 int ret = EVP_PKEY_assign_DSA(pkey, key);
233 if(ret)
234 DSA_up_ref(key);
235 return ret;
236}
237
238DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
239 {
240 if(pkey->type != EVP_PKEY_DSA) {
241 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
242 return NULL;
243 }
244 DSA_up_ref(pkey->pkey.dsa);
245 return pkey->pkey.dsa;
246}
247#endif
248
249#ifndef OPENSSL_NO_DH
250
251int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
252{
253 int ret = EVP_PKEY_assign_DH(pkey, key);
254 if(ret)
255 DH_up_ref(key);
256 return ret;
257}
258
259DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
260 {
261 if(pkey->type != EVP_PKEY_DH) {
262 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
263 return NULL;
264 }
265 DH_up_ref(pkey->pkey.dh);
266 return pkey->pkey.dh;
267}
268#endif
269
270int EVP_PKEY_type(int type)
271 {
272 switch (type)
273 {
274 case EVP_PKEY_RSA:
275 case EVP_PKEY_RSA2:
276 return(EVP_PKEY_RSA);
277 case EVP_PKEY_DSA:
278 case EVP_PKEY_DSA1:
279 case EVP_PKEY_DSA2:
280 case EVP_PKEY_DSA3:
281 case EVP_PKEY_DSA4:
282 return(EVP_PKEY_DSA);
283 case EVP_PKEY_DH:
284 return(EVP_PKEY_DH);
285 default:
286 return(NID_undef);
287 }
288 }
289
290void EVP_PKEY_free(EVP_PKEY *x)
291 {
292 int i;
293
294 if (x == NULL) return;
295
296 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
297#ifdef REF_PRINT
298 REF_PRINT("EVP_PKEY",x);
299#endif
300 if (i > 0) return;
301#ifdef REF_CHECK
302 if (i < 0)
303 {
304 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
305 abort();
306 }
307#endif
308 EVP_PKEY_free_it(x);
309 OPENSSL_free(x);
310 }
311
312static void EVP_PKEY_free_it(EVP_PKEY *x)
313 {
314 switch (x->type)
315 {
316#ifndef OPENSSL_NO_RSA
317 case EVP_PKEY_RSA:
318 case EVP_PKEY_RSA2:
319 RSA_free(x->pkey.rsa);
320 break;
321#endif
322#ifndef OPENSSL_NO_DSA
323 case EVP_PKEY_DSA:
324 case EVP_PKEY_DSA2:
325 case EVP_PKEY_DSA3:
326 case EVP_PKEY_DSA4:
327 DSA_free(x->pkey.dsa);
328 break;
329#endif
330#ifndef OPENSSL_NO_DH
331 case EVP_PKEY_DH:
332 DH_free(x->pkey.dh);
333 break;
334#endif
335 }
336 }
337
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
deleted file mode 100644
index 5a933d1cda..0000000000
--- a/src/lib/libcrypto/evp/p_open.c
+++ /dev/null
@@ -1,123 +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 OPENSSL_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, const 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(type) {
73 EVP_CIPHER_CTX_init(ctx);
74 if(!EVP_DecryptInit_ex(ctx,type,NULL, NULL,NULL)) return 0;
75 }
76
77 if(!priv) return 1;
78
79 if (priv->type != EVP_PKEY_RSA)
80 {
81 EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
82 goto err;
83 }
84
85 size=RSA_size(priv->pkey.rsa);
86 key=(unsigned char *)OPENSSL_malloc(size+2);
87 if (key == NULL)
88 {
89 /* ERROR */
90 EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE);
91 goto err;
92 }
93
94 i=EVP_PKEY_decrypt(key,ek,ekl,priv);
95 if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i))
96 {
97 /* ERROR */
98 goto err;
99 }
100 if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv)) goto err;
101
102 ret=1;
103err:
104 if (key != NULL) OPENSSL_cleanse(key,size);
105 OPENSSL_free(key);
106 return(ret);
107 }
108
109int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
110 {
111 int i;
112
113 i=EVP_DecryptFinal_ex(ctx,out,outl);
114 EVP_DecryptInit_ex(ctx,NULL,NULL,NULL,NULL);
115 return(i);
116 }
117#else /* !OPENSSL_NO_RSA */
118
119# ifdef PEDANTIC
120static void *dummy=&dummy;
121# endif
122
123#endif
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c
deleted file mode 100644
index 37e547fe72..0000000000
--- a/src/lib/libcrypto/evp/p_seal.c
+++ /dev/null
@@ -1,115 +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 OPENSSL_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, const 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(type) {
76 EVP_CIPHER_CTX_init(ctx);
77 if(!EVP_EncryptInit_ex(ctx,type,NULL,NULL,NULL)) return 0;
78 }
79 if ((npubk <= 0) || !pubk)
80 return 1;
81 if (RAND_bytes(key,EVP_MAX_KEY_LENGTH) <= 0)
82 return 0;
83 if (EVP_CIPHER_CTX_iv_length(ctx))
84 RAND_pseudo_bytes(iv,EVP_CIPHER_CTX_iv_length(ctx));
85
86 if(!EVP_EncryptInit_ex(ctx,NULL,NULL,key,iv)) return 0;
87
88 for (i=0; i<npubk; i++)
89 {
90 ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_CTX_key_length(ctx),
91 pubk[i]);
92 if (ekl[i] <= 0) return(-1);
93 }
94 return(npubk);
95 }
96
97/* MACRO
98void EVP_SealUpdate(ctx,out,outl,in,inl)
99EVP_CIPHER_CTX *ctx;
100unsigned char *out;
101int *outl;
102unsigned char *in;
103int inl;
104 {
105 EVP_EncryptUpdate(ctx,out,outl,in,inl);
106 }
107*/
108
109int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
110 {
111 int i;
112 i = EVP_EncryptFinal_ex(ctx,out,outl);
113 EVP_EncryptInit_ex(ctx,NULL,NULL,NULL,NULL);
114 return i;
115 }
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c
deleted file mode 100644
index e4ae5906f5..0000000000
--- a/src/lib/libcrypto/evp/p_sign.c
+++ /dev/null
@@ -1,114 +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_ex(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_init(&tmp_ctx);
88 EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
89 EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
90 EVP_MD_CTX_cleanup(&tmp_ctx);
91 for (i=0; i<4; i++)
92 {
93 v=ctx->digest->required_pkey_type[i];
94 if (v == 0) break;
95 if (pkey->type == v)
96 {
97 ok=1;
98 break;
99 }
100 }
101 if (!ok)
102 {
103 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
104 return(0);
105 }
106 if (ctx->digest->sign == NULL)
107 {
108 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
109 return(0);
110 }
111 return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
112 pkey->pkey.ptr));
113 }
114
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
deleted file mode 100644
index d854d743a5..0000000000
--- a/src/lib/libcrypto/evp/p_verify.c
+++ /dev/null
@@ -1,101 +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_init(&tmp_ctx);
89 EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
90 EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
91 EVP_MD_CTX_cleanup(&tmp_ctx);
92 if (ctx->digest->verify == NULL)
93 {
94 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
95 return(0);
96 }
97
98 return(ctx->digest->verify(ctx->digest->type,m,m_len,
99 sigbuf,siglen,pkey->pkey.ptr));
100 }
101
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c
deleted file mode 100644
index 5b2e345c27..0000000000
--- a/src/lib/libcrypto/ex_data.c
+++ /dev/null
@@ -1,636 +0,0 @@
1/* crypto/ex_data.c */
2
3/*
4 * Overhaul notes;
5 *
6 * This code is now *mostly* thread-safe. It is now easier to understand in what
7 * ways it is safe and in what ways it is not, which is an improvement. Firstly,
8 * all per-class stacks and index-counters for ex_data are stored in the same
9 * global LHASH table (keyed by class). This hash table uses locking for all
10 * access with the exception of CRYPTO_cleanup_all_ex_data(), which must only be
11 * called when no other threads can possibly race against it (even if it was
12 * locked, the race would mean it's possible the hash table might have been
13 * recreated after the cleanup). As classes can only be added to the hash table,
14 * and within each class, the stack of methods can only be incremented, the
15 * locking mechanics are simpler than they would otherwise be. For example, the
16 * new/dup/free ex_data functions will lock the hash table, copy the method
17 * pointers it needs from the relevant class, then unlock the hash table before
18 * actually applying those method pointers to the task of the new/dup/free
19 * operations. As they can't be removed from the method-stack, only
20 * supplemented, there's no race conditions associated with using them outside
21 * the lock. The get/set_ex_data functions are not locked because they do not
22 * involve this global state at all - they operate directly with a previously
23 * obtained per-class method index and a particular "ex_data" variable. These
24 * variables are usually instantiated per-context (eg. each RSA structure has
25 * one) so locking on read/write access to that variable can be locked locally
26 * if required (eg. using the "RSA" lock to synchronise access to a
27 * per-RSA-structure ex_data variable if required).
28 * [Geoff]
29 */
30
31/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
32 * All rights reserved.
33 *
34 * This package is an SSL implementation written
35 * by Eric Young (eay@cryptsoft.com).
36 * The implementation was written so as to conform with Netscapes SSL.
37 *
38 * This library is free for commercial and non-commercial use as long as
39 * the following conditions are aheared to. The following conditions
40 * apply to all code found in this distribution, be it the RC4, RSA,
41 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
42 * included with this distribution is covered by the same copyright terms
43 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
44 *
45 * Copyright remains Eric Young's, and as such any Copyright notices in
46 * the code are not to be removed.
47 * If this package is used in a product, Eric Young should be given attribution
48 * as the author of the parts of the library used.
49 * This can be in the form of a textual message at program startup or
50 * in documentation (online or textual) provided with the package.
51 *
52 * Redistribution and use in source and binary forms, with or without
53 * modification, are permitted provided that the following conditions
54 * are met:
55 * 1. Redistributions of source code must retain the copyright
56 * notice, this list of conditions and the following disclaimer.
57 * 2. Redistributions in binary form must reproduce the above copyright
58 * notice, this list of conditions and the following disclaimer in the
59 * documentation and/or other materials provided with the distribution.
60 * 3. All advertising materials mentioning features or use of this software
61 * must display the following acknowledgement:
62 * "This product includes cryptographic software written by
63 * Eric Young (eay@cryptsoft.com)"
64 * The word 'cryptographic' can be left out if the rouines from the library
65 * being used are not cryptographic related :-).
66 * 4. If you include any Windows specific code (or a derivative thereof) from
67 * the apps directory (application code) you must include an acknowledgement:
68 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
69 *
70 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
71 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
74 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
75 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
76 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
77 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
78 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
79 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
80 * SUCH DAMAGE.
81 *
82 * The licence and distribution terms for any publically available version or
83 * derivative of this code cannot be changed. i.e. this code cannot simply be
84 * copied and put under another distribution licence
85 * [including the GNU Public Licence.]
86 */
87/* ====================================================================
88 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
89 *
90 * Redistribution and use in source and binary forms, with or without
91 * modification, are permitted provided that the following conditions
92 * are met:
93 *
94 * 1. Redistributions of source code must retain the above copyright
95 * notice, this list of conditions and the following disclaimer.
96 *
97 * 2. Redistributions in binary form must reproduce the above copyright
98 * notice, this list of conditions and the following disclaimer in
99 * the documentation and/or other materials provided with the
100 * distribution.
101 *
102 * 3. All advertising materials mentioning features or use of this
103 * software must display the following acknowledgment:
104 * "This product includes software developed by the OpenSSL Project
105 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
106 *
107 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
108 * endorse or promote products derived from this software without
109 * prior written permission. For written permission, please contact
110 * openssl-core@openssl.org.
111 *
112 * 5. Products derived from this software may not be called "OpenSSL"
113 * nor may "OpenSSL" appear in their names without prior written
114 * permission of the OpenSSL Project.
115 *
116 * 6. Redistributions of any form whatsoever must retain the following
117 * acknowledgment:
118 * "This product includes software developed by the OpenSSL Project
119 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
120 *
121 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
122 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
123 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
124 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
125 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
126 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
127 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
128 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
129 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
130 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
131 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
132 * OF THE POSSIBILITY OF SUCH DAMAGE.
133 * ====================================================================
134 *
135 * This product includes cryptographic software written by Eric Young
136 * (eay@cryptsoft.com). This product includes software written by Tim
137 * Hudson (tjh@cryptsoft.com).
138 *
139 */
140
141#include <stdio.h>
142#include <stdlib.h>
143#include <openssl/buffer.h>
144#include <openssl/bio.h>
145#include <openssl/lhash.h>
146#include "cryptlib.h"
147
148/* What an "implementation of ex_data functionality" looks like */
149struct st_CRYPTO_EX_DATA_IMPL
150 {
151 /*********************/
152 /* GLOBAL OPERATIONS */
153 /* Return a new class index */
154 int (*cb_new_class)(void);
155 /* Cleanup all state used by the implementation */
156 void (*cb_cleanup)(void);
157 /************************/
158 /* PER-CLASS OPERATIONS */
159 /* Get a new method index within a class */
160 int (*cb_get_new_index)(int class_index, long argl, void *argp,
161 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
162 CRYPTO_EX_free *free_func);
163 /* Initialise a new CRYPTO_EX_DATA of a given class */
164 int (*cb_new_ex_data)(int class_index, void *obj,
165 CRYPTO_EX_DATA *ad);
166 /* Duplicate a CRYPTO_EX_DATA of a given class onto a copy */
167 int (*cb_dup_ex_data)(int class_index, CRYPTO_EX_DATA *to,
168 CRYPTO_EX_DATA *from);
169 /* Cleanup a CRYPTO_EX_DATA of a given class */
170 void (*cb_free_ex_data)(int class_index, void *obj,
171 CRYPTO_EX_DATA *ad);
172 };
173
174/* The implementation we use at run-time */
175static const CRYPTO_EX_DATA_IMPL *impl = NULL;
176
177/* To call "impl" functions, use this macro rather than referring to 'impl' directly, eg.
178 * EX_IMPL(get_new_index)(...); */
179#define EX_IMPL(a) impl->cb_##a
180
181/* Predeclare the "default" ex_data implementation */
182static int int_new_class(void);
183static void int_cleanup(void);
184static int int_get_new_index(int class_index, long argl, void *argp,
185 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
186 CRYPTO_EX_free *free_func);
187static int int_new_ex_data(int class_index, void *obj,
188 CRYPTO_EX_DATA *ad);
189static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
190 CRYPTO_EX_DATA *from);
191static void int_free_ex_data(int class_index, void *obj,
192 CRYPTO_EX_DATA *ad);
193static CRYPTO_EX_DATA_IMPL impl_default =
194 {
195 int_new_class,
196 int_cleanup,
197 int_get_new_index,
198 int_new_ex_data,
199 int_dup_ex_data,
200 int_free_ex_data
201 };
202
203/* Internal function that checks whether "impl" is set and if not, sets it to
204 * the default. */
205static void impl_check(void)
206 {
207 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
208 if(!impl)
209 impl = &impl_default;
210 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
211 }
212/* A macro wrapper for impl_check that first uses a non-locked test before
213 * invoking the function (which checks again inside a lock). */
214#define IMPL_CHECK if(!impl) impl_check();
215
216/* API functions to get/set the "ex_data" implementation */
217const CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void)
218 {
219 IMPL_CHECK
220 return impl;
221 }
222int CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i)
223 {
224 int toret = 0;
225 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
226 if(!impl)
227 {
228 impl = i;
229 toret = 1;
230 }
231 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
232 return toret;
233 }
234
235/****************************************************************************/
236/* Interal (default) implementation of "ex_data" support. API functions are
237 * further down. */
238
239/* The type that represents what each "class" used to implement locally. A STACK
240 * of CRYPTO_EX_DATA_FUNCS plus a index-counter. The 'class_index' is the global
241 * value representing the class that is used to distinguish these items. */
242typedef struct st_ex_class_item {
243 int class_index;
244 STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth;
245 int meth_num;
246} EX_CLASS_ITEM;
247
248/* When assigning new class indexes, this is our counter */
249static int ex_class = CRYPTO_EX_INDEX_USER;
250
251/* The global hash table of EX_CLASS_ITEM items */
252static LHASH *ex_data = NULL;
253
254/* The callbacks required in the "ex_data" hash table */
255static unsigned long ex_hash_cb(const void *a_void)
256 {
257 return ((const EX_CLASS_ITEM *)a_void)->class_index;
258 }
259static int ex_cmp_cb(const void *a_void, const void *b_void)
260 {
261 return (((const EX_CLASS_ITEM *)a_void)->class_index -
262 ((const EX_CLASS_ITEM *)b_void)->class_index);
263 }
264
265/* Internal functions used by the "impl_default" implementation to access the
266 * state */
267
268static int ex_data_check(void)
269 {
270 int toret = 1;
271 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
272 if(!ex_data && ((ex_data = lh_new(ex_hash_cb, ex_cmp_cb)) == NULL))
273 toret = 0;
274 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
275 return toret;
276 }
277/* This macros helps reduce the locking from repeated checks because the
278 * ex_data_check() function checks ex_data again inside a lock. */
279#define EX_DATA_CHECK(iffail) if(!ex_data && !ex_data_check()) {iffail}
280
281/* This "inner" callback is used by the callback function that follows it */
282static void def_cleanup_util_cb(CRYPTO_EX_DATA_FUNCS *funcs)
283 {
284 OPENSSL_free(funcs);
285 }
286
287/* This callback is used in lh_doall to destroy all EX_CLASS_ITEM values from
288 * "ex_data" prior to the ex_data hash table being itself destroyed. Doesn't do
289 * any locking. */
290static void def_cleanup_cb(const void *a_void)
291 {
292 EX_CLASS_ITEM *item = (EX_CLASS_ITEM *)a_void;
293 sk_CRYPTO_EX_DATA_FUNCS_pop_free(item->meth, def_cleanup_util_cb);
294 OPENSSL_free(item);
295 }
296
297/* Return the EX_CLASS_ITEM from the "ex_data" hash table that corresponds to a
298 * given class. Handles locking. */
299static EX_CLASS_ITEM *def_get_class(int class_index)
300 {
301 EX_CLASS_ITEM d, *p, *gen;
302 EX_DATA_CHECK(return NULL;)
303 d.class_index = class_index;
304 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
305 p = lh_retrieve(ex_data, &d);
306 if(!p)
307 {
308 gen = OPENSSL_malloc(sizeof(EX_CLASS_ITEM));
309 if(gen)
310 {
311 gen->class_index = class_index;
312 gen->meth_num = 0;
313 gen->meth = sk_CRYPTO_EX_DATA_FUNCS_new_null();
314 if(!gen->meth)
315 OPENSSL_free(gen);
316 else
317 {
318 /* Because we're inside the ex_data lock, the
319 * return value from the insert will be NULL */
320 lh_insert(ex_data, gen);
321 p = gen;
322 }
323 }
324 }
325 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
326 if(!p)
327 CRYPTOerr(CRYPTO_F_DEF_GET_CLASS,ERR_R_MALLOC_FAILURE);
328 return p;
329 }
330
331/* Add a new method to the given EX_CLASS_ITEM and return the corresponding
332 * index (or -1 for error). Handles locking. */
333static int def_add_index(EX_CLASS_ITEM *item, long argl, void *argp,
334 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
335 CRYPTO_EX_free *free_func)
336 {
337 int toret = -1;
338 CRYPTO_EX_DATA_FUNCS *a = (CRYPTO_EX_DATA_FUNCS *)OPENSSL_malloc(
339 sizeof(CRYPTO_EX_DATA_FUNCS));
340 if(!a)
341 {
342 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX,ERR_R_MALLOC_FAILURE);
343 return -1;
344 }
345 a->argl=argl;
346 a->argp=argp;
347 a->new_func=new_func;
348 a->dup_func=dup_func;
349 a->free_func=free_func;
350 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
351 while (sk_CRYPTO_EX_DATA_FUNCS_num(item->meth) <= item->meth_num)
352 {
353 if (!sk_CRYPTO_EX_DATA_FUNCS_push(item->meth, NULL))
354 {
355 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX,ERR_R_MALLOC_FAILURE);
356 OPENSSL_free(a);
357 goto err;
358 }
359 }
360 toret = item->meth_num++;
361 sk_CRYPTO_EX_DATA_FUNCS_set(item->meth, toret, a);
362err:
363 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
364 return toret;
365 }
366
367/**************************************************************/
368/* The functions in the default CRYPTO_EX_DATA_IMPL structure */
369
370static int int_new_class(void)
371 {
372 int toret;
373 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
374 toret = ex_class++;
375 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
376 return toret;
377 }
378
379static void int_cleanup(void)
380 {
381 EX_DATA_CHECK(return;)
382 lh_doall(ex_data, def_cleanup_cb);
383 lh_free(ex_data);
384 ex_data = NULL;
385 impl = NULL;
386 }
387
388static int int_get_new_index(int class_index, long argl, void *argp,
389 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
390 CRYPTO_EX_free *free_func)
391 {
392 EX_CLASS_ITEM *item = def_get_class(class_index);
393 if(!item)
394 return -1;
395 return def_add_index(item, argl, argp, new_func, dup_func, free_func);
396 }
397
398/* Thread-safe by copying a class's array of "CRYPTO_EX_DATA_FUNCS" entries in
399 * the lock, then using them outside the lock. NB: Thread-safety only applies to
400 * the global "ex_data" state (ie. class definitions), not thread-safe on 'ad'
401 * itself. */
402static int int_new_ex_data(int class_index, void *obj,
403 CRYPTO_EX_DATA *ad)
404 {
405 int mx,i;
406 void *ptr;
407 CRYPTO_EX_DATA_FUNCS **storage = NULL;
408 EX_CLASS_ITEM *item = def_get_class(class_index);
409 if(!item)
410 /* error is already set */
411 return 0;
412 ad->sk = NULL;
413 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
414 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
415 if(mx > 0)
416 {
417 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
418 if(!storage)
419 goto skip;
420 for(i = 0; i < mx; i++)
421 storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i);
422 }
423skip:
424 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
425 if((mx > 0) && !storage)
426 {
427 CRYPTOerr(CRYPTO_F_INT_NEW_EX_DATA,ERR_R_MALLOC_FAILURE);
428 return 0;
429 }
430 for(i = 0; i < mx; i++)
431 {
432 if(storage[i] && storage[i]->new_func)
433 {
434 ptr = CRYPTO_get_ex_data(ad, i);
435 storage[i]->new_func(obj,ptr,ad,i,
436 storage[i]->argl,storage[i]->argp);
437 }
438 }
439 if(storage)
440 OPENSSL_free(storage);
441 return 1;
442 }
443
444/* Same thread-safety notes as for "int_new_ex_data" */
445static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
446 CRYPTO_EX_DATA *from)
447 {
448 int mx, j, i;
449 char *ptr;
450 CRYPTO_EX_DATA_FUNCS **storage = NULL;
451 EX_CLASS_ITEM *item;
452 if(!from->sk)
453 /* 'to' should be "blank" which *is* just like 'from' */
454 return 1;
455 if((item = def_get_class(class_index)) == NULL)
456 return 0;
457 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
458 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
459 j = sk_num(from->sk);
460 if(j < mx)
461 mx = j;
462 if(mx > 0)
463 {
464 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
465 if(!storage)
466 goto skip;
467 for(i = 0; i < mx; i++)
468 storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i);
469 }
470skip:
471 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
472 if((mx > 0) && !storage)
473 {
474 CRYPTOerr(CRYPTO_F_INT_DUP_EX_DATA,ERR_R_MALLOC_FAILURE);
475 return 0;
476 }
477 for(i = 0; i < mx; i++)
478 {
479 ptr = CRYPTO_get_ex_data(from, i);
480 if(storage[i] && storage[i]->dup_func)
481 storage[i]->dup_func(to,from,&ptr,i,
482 storage[i]->argl,storage[i]->argp);
483 CRYPTO_set_ex_data(to,i,ptr);
484 }
485 if(storage)
486 OPENSSL_free(storage);
487 return 1;
488 }
489
490/* Same thread-safety notes as for "int_new_ex_data" */
491static void int_free_ex_data(int class_index, void *obj,
492 CRYPTO_EX_DATA *ad)
493 {
494 int mx,i;
495 EX_CLASS_ITEM *item;
496 void *ptr;
497 CRYPTO_EX_DATA_FUNCS **storage = NULL;
498 if((item = def_get_class(class_index)) == NULL)
499 return;
500 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
501 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
502 if(mx > 0)
503 {
504 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
505 if(!storage)
506 goto skip;
507 for(i = 0; i < mx; i++)
508 storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i);
509 }
510skip:
511 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
512 if((mx > 0) && !storage)
513 {
514 CRYPTOerr(CRYPTO_F_INT_FREE_EX_DATA,ERR_R_MALLOC_FAILURE);
515 return;
516 }
517 for(i = 0; i < mx; i++)
518 {
519 if(storage[i] && storage[i]->free_func)
520 {
521 ptr = CRYPTO_get_ex_data(ad,i);
522 storage[i]->free_func(obj,ptr,ad,i,
523 storage[i]->argl,storage[i]->argp);
524 }
525 }
526 if(storage)
527 OPENSSL_free(storage);
528 if(ad->sk)
529 {
530 sk_free(ad->sk);
531 ad->sk=NULL;
532 }
533 }
534
535/********************************************************************/
536/* API functions that defer all "state" operations to the "ex_data"
537 * implementation we have set. */
538
539/* Obtain an index for a new class (not the same as getting a new index within
540 * an existing class - this is actually getting a new *class*) */
541int CRYPTO_ex_data_new_class(void)
542 {
543 IMPL_CHECK
544 return EX_IMPL(new_class)();
545 }
546
547/* Release all "ex_data" state to prevent memory leaks. This can't be made
548 * thread-safe without overhauling a lot of stuff, and shouldn't really be
549 * called under potential race-conditions anyway (it's for program shutdown
550 * after all). */
551void CRYPTO_cleanup_all_ex_data(void)
552 {
553 IMPL_CHECK
554 EX_IMPL(cleanup)();
555 }
556
557/* Inside an existing class, get/register a new index. */
558int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp,
559 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
560 CRYPTO_EX_free *free_func)
561 {
562 int ret = -1;
563
564 IMPL_CHECK
565 ret = EX_IMPL(get_new_index)(class_index,
566 argl, argp, new_func, dup_func, free_func);
567 return ret;
568 }
569
570/* Initialise a new CRYPTO_EX_DATA for use in a particular class - including
571 * calling new() callbacks for each index in the class used by this variable */
572int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
573 {
574 IMPL_CHECK
575 return EX_IMPL(new_ex_data)(class_index, obj, ad);
576 }
577
578/* Duplicate a CRYPTO_EX_DATA variable - including calling dup() callbacks for
579 * each index in the class used by this variable */
580int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
581 CRYPTO_EX_DATA *from)
582 {
583 IMPL_CHECK
584 return EX_IMPL(dup_ex_data)(class_index, to, from);
585 }
586
587/* Cleanup a CRYPTO_EX_DATA variable - including calling free() callbacks for
588 * each index in the class used by this variable */
589void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
590 {
591 IMPL_CHECK
592 EX_IMPL(free_ex_data)(class_index, obj, ad);
593 }
594
595/* For a given CRYPTO_EX_DATA variable, set the value corresponding to a
596 * particular index in the class used by this variable */
597int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val)
598 {
599 int i;
600
601 if (ad->sk == NULL)
602 {
603 if ((ad->sk=sk_new_null()) == NULL)
604 {
605 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
606 return(0);
607 }
608 }
609 i=sk_num(ad->sk);
610
611 while (i <= idx)
612 {
613 if (!sk_push(ad->sk,NULL))
614 {
615 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
616 return(0);
617 }
618 i++;
619 }
620 sk_set(ad->sk,idx,val);
621 return(1);
622 }
623
624/* For a given CRYPTO_EX_DATA_ variable, get the value corresponding to a
625 * particular index in the class used by this variable */
626void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
627 {
628 if (ad->sk == NULL)
629 return(0);
630 else if (idx >= sk_num(ad->sk))
631 return(0);
632 else
633 return(sk_value(ad->sk,idx));
634 }
635
636IMPLEMENT_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 6c110bd52b..0000000000
--- a/src/lib/libcrypto/hmac/hmac.c
+++ /dev/null
@@ -1,183 +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#include "cryptlib.h"
63
64#ifndef OPENSSL_FIPS
65
66void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
67 const EVP_MD *md, ENGINE *impl)
68 {
69 int i,j,reset=0;
70 unsigned char pad[HMAC_MAX_MD_CBLOCK];
71
72 if (md != NULL)
73 {
74 reset=1;
75 ctx->md=md;
76 }
77 else
78 md=ctx->md;
79
80 if (key != NULL)
81 {
82 reset=1;
83 j=EVP_MD_block_size(md);
84 OPENSSL_assert(j <= sizeof ctx->key);
85 if (j < len)
86 {
87 EVP_DigestInit_ex(&ctx->md_ctx,md, impl);
88 EVP_DigestUpdate(&ctx->md_ctx,key,len);
89 EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key,
90 &ctx->key_length);
91 }
92 else
93 {
94 OPENSSL_assert(len <= sizeof ctx->key);
95 memcpy(ctx->key,key,len);
96 ctx->key_length=len;
97 }
98 if(ctx->key_length != HMAC_MAX_MD_CBLOCK)
99 memset(&ctx->key[ctx->key_length], 0,
100 HMAC_MAX_MD_CBLOCK - ctx->key_length);
101 }
102
103 if (reset)
104 {
105 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
106 pad[i]=0x36^ctx->key[i];
107 EVP_DigestInit_ex(&ctx->i_ctx,md, impl);
108 EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md));
109
110 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
111 pad[i]=0x5c^ctx->key[i];
112 EVP_DigestInit_ex(&ctx->o_ctx,md, impl);
113 EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md));
114 }
115 EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx);
116 }
117
118void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
119 const EVP_MD *md)
120 {
121 if(key && md)
122 HMAC_CTX_init(ctx);
123 HMAC_Init_ex(ctx,key,len,md, NULL);
124 }
125
126void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len)
127 {
128 EVP_DigestUpdate(&ctx->md_ctx,data,len);
129 }
130
131void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
132 {
133 int j;
134 unsigned int i;
135 unsigned char buf[EVP_MAX_MD_SIZE];
136
137 j=EVP_MD_block_size(ctx->md);
138
139 EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i);
140 EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx);
141 EVP_DigestUpdate(&ctx->md_ctx,buf,i);
142 EVP_DigestFinal_ex(&ctx->md_ctx,md,len);
143 }
144
145void HMAC_CTX_init(HMAC_CTX *ctx)
146 {
147 EVP_MD_CTX_init(&ctx->i_ctx);
148 EVP_MD_CTX_init(&ctx->o_ctx);
149 EVP_MD_CTX_init(&ctx->md_ctx);
150 }
151
152void HMAC_CTX_cleanup(HMAC_CTX *ctx)
153 {
154 EVP_MD_CTX_cleanup(&ctx->i_ctx);
155 EVP_MD_CTX_cleanup(&ctx->o_ctx);
156 EVP_MD_CTX_cleanup(&ctx->md_ctx);
157 memset(ctx,0,sizeof *ctx);
158 }
159
160unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
161 const unsigned char *d, int n, unsigned char *md,
162 unsigned int *md_len)
163 {
164 HMAC_CTX c;
165 static unsigned char m[EVP_MAX_MD_SIZE];
166
167 if (md == NULL) md=m;
168 HMAC_CTX_init(&c);
169 HMAC_Init(&c,key,key_len,evp_md);
170 HMAC_Update(&c,d,n);
171 HMAC_Final(&c,md,md_len);
172 HMAC_CTX_cleanup(&c);
173 return(md);
174 }
175
176void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
177 {
178 EVP_MD_CTX_set_flags(&ctx->i_ctx, flags);
179 EVP_MD_CTX_set_flags(&ctx->o_ctx, flags);
180 EVP_MD_CTX_set_flags(&ctx->md_ctx, flags);
181 }
182
183#endif
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
deleted file mode 100644
index c6489c04c8..0000000000
--- a/src/lib/libcrypto/hmac/hmac.h
+++ /dev/null
@@ -1,111 +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 OPENSSL_NO_HMAC
62#error HMAC is disabled.
63#endif
64
65#include <openssl/evp.h>
66
67#ifdef OPENSSL_FIPS
68#define HMAC_MAX_MD_CBLOCK 128
69#else
70#define HMAC_MAX_MD_CBLOCK 64
71#endif
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77typedef struct hmac_ctx_st
78 {
79 const EVP_MD *md;
80 EVP_MD_CTX md_ctx;
81 EVP_MD_CTX i_ctx;
82 EVP_MD_CTX o_ctx;
83 unsigned int key_length;
84 unsigned char key[HMAC_MAX_MD_CBLOCK];
85 } HMAC_CTX;
86
87#define HMAC_size(e) (EVP_MD_size((e)->md))
88
89
90void HMAC_CTX_init(HMAC_CTX *ctx);
91void HMAC_CTX_cleanup(HMAC_CTX *ctx);
92
93#define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */
94
95void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
96 const EVP_MD *md); /* deprecated */
97void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
98 const EVP_MD *md, ENGINE *impl);
99void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
100void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
101unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
102 const unsigned char *d, int n, unsigned char *md,
103 unsigned int *md_len);
104
105void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif
diff --git a/src/lib/libcrypto/idea/idea.h b/src/lib/libcrypto/idea/idea.h
deleted file mode 100644
index bf41844fd7..0000000000
--- a/src/lib/libcrypto/idea/idea.h
+++ /dev/null
@@ -1,103 +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 OPENSSL_NO_IDEA
63#error IDEA is disabled.
64#endif
65
66#define IDEA_ENCRYPT 1
67#define IDEA_DECRYPT 0
68
69#include <openssl/opensslconf.h> /* IDEA_INT */
70#define IDEA_BLOCK 8
71#define IDEA_KEY_LENGTH 16
72
73#ifdef __cplusplus
74extern "C" {
75#endif
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(const unsigned char *in, unsigned char *out,
84 IDEA_KEY_SCHEDULE *ks);
85#ifdef OPENSSL_FIPS
86void private_idea_set_encrypt_key(const unsigned char *key,
87 IDEA_KEY_SCHEDULE *ks);
88#endif
89void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks);
90void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
91void idea_cbc_encrypt(const unsigned char *in, unsigned char *out,
92 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc);
93void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out,
94 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,
95 int *num,int enc);
96void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out,
97 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num);
98void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks);
99#ifdef __cplusplus
100}
101#endif
102
103#endif
diff --git a/src/lib/libcrypto/krb5/krb5_asn.c b/src/lib/libcrypto/krb5/krb5_asn.c
deleted file mode 100644
index 1fb741d2a0..0000000000
--- a/src/lib/libcrypto/krb5/krb5_asn.c
+++ /dev/null
@@ -1,167 +0,0 @@
1/* krb5_asn.c */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project,
3** using ocsp/{*.h,*asn*.c} as a starting point
4*/
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <openssl/asn1.h>
59#include <openssl/asn1t.h>
60#include <openssl/krb5_asn.h>
61
62
63ASN1_SEQUENCE(KRB5_ENCDATA) = {
64 ASN1_EXP(KRB5_ENCDATA, etype, ASN1_INTEGER, 0),
65 ASN1_EXP_OPT(KRB5_ENCDATA, kvno, ASN1_INTEGER, 1),
66 ASN1_EXP(KRB5_ENCDATA, cipher, ASN1_OCTET_STRING,2)
67} ASN1_SEQUENCE_END(KRB5_ENCDATA)
68
69IMPLEMENT_ASN1_FUNCTIONS(KRB5_ENCDATA)
70
71
72ASN1_SEQUENCE(KRB5_PRINCNAME) = {
73 ASN1_EXP(KRB5_PRINCNAME, nametype, ASN1_INTEGER, 0),
74 ASN1_EXP_SEQUENCE_OF(KRB5_PRINCNAME, namestring, ASN1_GENERALSTRING, 1)
75} ASN1_SEQUENCE_END(KRB5_PRINCNAME)
76
77IMPLEMENT_ASN1_FUNCTIONS(KRB5_PRINCNAME)
78
79
80/* [APPLICATION 1] = 0x61 */
81ASN1_SEQUENCE(KRB5_TKTBODY) = {
82 ASN1_EXP(KRB5_TKTBODY, tktvno, ASN1_INTEGER, 0),
83 ASN1_EXP(KRB5_TKTBODY, realm, ASN1_GENERALSTRING, 1),
84 ASN1_EXP(KRB5_TKTBODY, sname, KRB5_PRINCNAME, 2),
85 ASN1_EXP(KRB5_TKTBODY, encdata, KRB5_ENCDATA, 3)
86} ASN1_SEQUENCE_END(KRB5_TKTBODY)
87
88IMPLEMENT_ASN1_FUNCTIONS(KRB5_TKTBODY)
89
90
91ASN1_ITEM_TEMPLATE(KRB5_TICKET) =
92 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 1,
93 KRB5_TICKET, KRB5_TKTBODY)
94ASN1_ITEM_TEMPLATE_END(KRB5_TICKET)
95
96IMPLEMENT_ASN1_FUNCTIONS(KRB5_TICKET)
97
98
99/* [APPLICATION 14] = 0x6e */
100ASN1_SEQUENCE(KRB5_APREQBODY) = {
101 ASN1_EXP(KRB5_APREQBODY, pvno, ASN1_INTEGER, 0),
102 ASN1_EXP(KRB5_APREQBODY, msgtype, ASN1_INTEGER, 1),
103 ASN1_EXP(KRB5_APREQBODY, apoptions, ASN1_BIT_STRING, 2),
104 ASN1_EXP(KRB5_APREQBODY, ticket, KRB5_TICKET, 3),
105 ASN1_EXP(KRB5_APREQBODY, authenticator, KRB5_ENCDATA, 4),
106} ASN1_SEQUENCE_END(KRB5_APREQBODY)
107
108IMPLEMENT_ASN1_FUNCTIONS(KRB5_APREQBODY)
109
110ASN1_ITEM_TEMPLATE(KRB5_APREQ) =
111 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 14,
112 KRB5_APREQ, KRB5_APREQBODY)
113ASN1_ITEM_TEMPLATE_END(KRB5_APREQ)
114
115IMPLEMENT_ASN1_FUNCTIONS(KRB5_APREQ)
116
117
118/* Authenticator stuff */
119
120ASN1_SEQUENCE(KRB5_CHECKSUM) = {
121 ASN1_EXP(KRB5_CHECKSUM, ctype, ASN1_INTEGER, 0),
122 ASN1_EXP(KRB5_CHECKSUM, checksum, ASN1_OCTET_STRING,1)
123} ASN1_SEQUENCE_END(KRB5_CHECKSUM)
124
125IMPLEMENT_ASN1_FUNCTIONS(KRB5_CHECKSUM)
126
127
128ASN1_SEQUENCE(KRB5_ENCKEY) = {
129 ASN1_EXP(KRB5_ENCKEY, ktype, ASN1_INTEGER, 0),
130 ASN1_EXP(KRB5_ENCKEY, keyvalue, ASN1_OCTET_STRING,1)
131} ASN1_SEQUENCE_END(KRB5_ENCKEY)
132
133IMPLEMENT_ASN1_FUNCTIONS(KRB5_ENCKEY)
134
135
136/* SEQ OF SEQ; see ASN1_EXP_SEQUENCE_OF_OPT() below */
137ASN1_SEQUENCE(KRB5_AUTHDATA) = {
138 ASN1_EXP(KRB5_AUTHDATA, adtype, ASN1_INTEGER, 0),
139 ASN1_EXP(KRB5_AUTHDATA, addata, ASN1_OCTET_STRING,1)
140} ASN1_SEQUENCE_END(KRB5_AUTHDATA)
141
142IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHDATA)
143
144
145/* [APPLICATION 2] = 0x62 */
146ASN1_SEQUENCE(KRB5_AUTHENTBODY) = {
147 ASN1_EXP(KRB5_AUTHENTBODY, avno, ASN1_INTEGER, 0),
148 ASN1_EXP(KRB5_AUTHENTBODY, crealm, ASN1_GENERALSTRING, 1),
149 ASN1_EXP(KRB5_AUTHENTBODY, cname, KRB5_PRINCNAME, 2),
150 ASN1_EXP_OPT(KRB5_AUTHENTBODY, cksum, KRB5_CHECKSUM, 3),
151 ASN1_EXP(KRB5_AUTHENTBODY, cusec, ASN1_INTEGER, 4),
152 ASN1_EXP(KRB5_AUTHENTBODY, ctime, ASN1_GENERALIZEDTIME, 5),
153 ASN1_EXP_OPT(KRB5_AUTHENTBODY, subkey, KRB5_ENCKEY, 6),
154 ASN1_EXP_OPT(KRB5_AUTHENTBODY, seqnum, ASN1_INTEGER, 7),
155 ASN1_EXP_SEQUENCE_OF_OPT
156 (KRB5_AUTHENTBODY, authorization, KRB5_AUTHDATA, 8),
157} ASN1_SEQUENCE_END(KRB5_AUTHENTBODY)
158
159IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHENTBODY)
160
161ASN1_ITEM_TEMPLATE(KRB5_AUTHENT) =
162 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_EXPTAG|ASN1_TFLG_APPLICATION, 2,
163 KRB5_AUTHENT, KRB5_AUTHENTBODY)
164ASN1_ITEM_TEMPLATE_END(KRB5_AUTHENT)
165
166IMPLEMENT_ASN1_FUNCTIONS(KRB5_AUTHENT)
167
diff --git a/src/lib/libcrypto/krb5/krb5_asn.h b/src/lib/libcrypto/krb5/krb5_asn.h
deleted file mode 100644
index 3329477b07..0000000000
--- a/src/lib/libcrypto/krb5/krb5_asn.h
+++ /dev/null
@@ -1,256 +0,0 @@
1/* krb5_asn.h */
2/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project,
3** using ocsp/{*.h,*asn*.c} as a starting point
4*/
5
6/* ====================================================================
7 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@openssl.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#ifndef HEADER_KRB5_ASN_H
61#define HEADER_KRB5_ASN_H
62
63/*
64#include <krb5.h>
65*/
66#include <openssl/safestack.h>
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72
73/* ASN.1 from Kerberos RFC 1510
74*/
75
76/* EncryptedData ::= SEQUENCE {
77** etype[0] INTEGER, -- EncryptionType
78** kvno[1] INTEGER OPTIONAL,
79** cipher[2] OCTET STRING -- ciphertext
80** }
81*/
82typedef struct krb5_encdata_st
83 {
84 ASN1_INTEGER *etype;
85 ASN1_INTEGER *kvno;
86 ASN1_OCTET_STRING *cipher;
87 } KRB5_ENCDATA;
88
89DECLARE_STACK_OF(KRB5_ENCDATA)
90
91/* PrincipalName ::= SEQUENCE {
92** name-type[0] INTEGER,
93** name-string[1] SEQUENCE OF GeneralString
94** }
95*/
96typedef struct krb5_princname_st
97 {
98 ASN1_INTEGER *nametype;
99 STACK_OF(ASN1_GENERALSTRING) *namestring;
100 } KRB5_PRINCNAME;
101
102DECLARE_STACK_OF(KRB5_PRINCNAME)
103
104
105/* Ticket ::= [APPLICATION 1] SEQUENCE {
106** tkt-vno[0] INTEGER,
107** realm[1] Realm,
108** sname[2] PrincipalName,
109** enc-part[3] EncryptedData
110** }
111*/
112typedef struct krb5_tktbody_st
113 {
114 ASN1_INTEGER *tktvno;
115 ASN1_GENERALSTRING *realm;
116 KRB5_PRINCNAME *sname;
117 KRB5_ENCDATA *encdata;
118 } KRB5_TKTBODY;
119
120typedef STACK_OF(KRB5_TKTBODY) KRB5_TICKET;
121DECLARE_STACK_OF(KRB5_TKTBODY)
122
123
124/* AP-REQ ::= [APPLICATION 14] SEQUENCE {
125** pvno[0] INTEGER,
126** msg-type[1] INTEGER,
127** ap-options[2] APOptions,
128** ticket[3] Ticket,
129** authenticator[4] EncryptedData
130** }
131**
132** APOptions ::= BIT STRING {
133** reserved(0), use-session-key(1), mutual-required(2) }
134*/
135typedef struct krb5_ap_req_st
136 {
137 ASN1_INTEGER *pvno;
138 ASN1_INTEGER *msgtype;
139 ASN1_BIT_STRING *apoptions;
140 KRB5_TICKET *ticket;
141 KRB5_ENCDATA *authenticator;
142 } KRB5_APREQBODY;
143
144typedef STACK_OF(KRB5_APREQBODY) KRB5_APREQ;
145DECLARE_STACK_OF(KRB5_APREQBODY)
146
147
148/* Authenticator Stuff */
149
150
151/* Checksum ::= SEQUENCE {
152** cksumtype[0] INTEGER,
153** checksum[1] OCTET STRING
154** }
155*/
156typedef struct krb5_checksum_st
157 {
158 ASN1_INTEGER *ctype;
159 ASN1_OCTET_STRING *checksum;
160 } KRB5_CHECKSUM;
161
162DECLARE_STACK_OF(KRB5_CHECKSUM)
163
164
165/* EncryptionKey ::= SEQUENCE {
166** keytype[0] INTEGER,
167** keyvalue[1] OCTET STRING
168** }
169*/
170typedef struct krb5_encryptionkey_st
171 {
172 ASN1_INTEGER *ktype;
173 ASN1_OCTET_STRING *keyvalue;
174 } KRB5_ENCKEY;
175
176DECLARE_STACK_OF(KRB5_ENCKEY)
177
178
179/* AuthorizationData ::= SEQUENCE OF SEQUENCE {
180** ad-type[0] INTEGER,
181** ad-data[1] OCTET STRING
182** }
183*/
184typedef struct krb5_authorization_st
185 {
186 ASN1_INTEGER *adtype;
187 ASN1_OCTET_STRING *addata;
188 } KRB5_AUTHDATA;
189
190DECLARE_STACK_OF(KRB5_AUTHDATA)
191
192
193/* -- Unencrypted authenticator
194** Authenticator ::= [APPLICATION 2] SEQUENCE {
195** authenticator-vno[0] INTEGER,
196** crealm[1] Realm,
197** cname[2] PrincipalName,
198** cksum[3] Checksum OPTIONAL,
199** cusec[4] INTEGER,
200** ctime[5] KerberosTime,
201** subkey[6] EncryptionKey OPTIONAL,
202** seq-number[7] INTEGER OPTIONAL,
203** authorization-data[8] AuthorizationData OPTIONAL
204** }
205*/
206typedef struct krb5_authenticator_st
207 {
208 ASN1_INTEGER *avno;
209 ASN1_GENERALSTRING *crealm;
210 KRB5_PRINCNAME *cname;
211 KRB5_CHECKSUM *cksum;
212 ASN1_INTEGER *cusec;
213 ASN1_GENERALIZEDTIME *ctime;
214 KRB5_ENCKEY *subkey;
215 ASN1_INTEGER *seqnum;
216 KRB5_AUTHDATA *authorization;
217 } KRB5_AUTHENTBODY;
218
219typedef STACK_OF(KRB5_AUTHENTBODY) KRB5_AUTHENT;
220DECLARE_STACK_OF(KRB5_AUTHENTBODY)
221
222
223/* DECLARE_ASN1_FUNCTIONS(type) = DECLARE_ASN1_FUNCTIONS_name(type, type) =
224** type *name##_new(void);
225** void name##_free(type *a);
226** DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) =
227** DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) =
228** type *d2i_##name(type **a, unsigned char **in, long len);
229** int i2d_##name(type *a, unsigned char **out);
230** DECLARE_ASN1_ITEM(itname) = OPENSSL_EXTERN const ASN1_ITEM itname##_it
231*/
232
233DECLARE_ASN1_FUNCTIONS(KRB5_ENCDATA)
234DECLARE_ASN1_FUNCTIONS(KRB5_PRINCNAME)
235DECLARE_ASN1_FUNCTIONS(KRB5_TKTBODY)
236DECLARE_ASN1_FUNCTIONS(KRB5_APREQBODY)
237DECLARE_ASN1_FUNCTIONS(KRB5_TICKET)
238DECLARE_ASN1_FUNCTIONS(KRB5_APREQ)
239
240DECLARE_ASN1_FUNCTIONS(KRB5_CHECKSUM)
241DECLARE_ASN1_FUNCTIONS(KRB5_ENCKEY)
242DECLARE_ASN1_FUNCTIONS(KRB5_AUTHDATA)
243DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENTBODY)
244DECLARE_ASN1_FUNCTIONS(KRB5_AUTHENT)
245
246
247/* BEGIN ERROR CODES */
248/* The following lines are auto generated by the script mkerr.pl. Any changes
249 * made after this point may be overwritten when the script is next run.
250 */
251
252#ifdef __cplusplus
253}
254#endif
255#endif
256
diff --git a/src/lib/libcrypto/lhash/lh_stats.c b/src/lib/libcrypto/lhash/lh_stats.c
deleted file mode 100644
index 5aa7766aa6..0000000000
--- a/src/lib/libcrypto/lhash/lh_stats.c
+++ /dev/null
@@ -1,248 +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#ifndef OPENSSL_NO_BIO
67#include <openssl/bio.h>
68#endif
69#include <openssl/lhash.h>
70
71#ifdef OPENSSL_NO_BIO
72
73void lh_stats(LHASH *lh, FILE *out)
74 {
75 fprintf(out,"num_items = %lu\n",lh->num_items);
76 fprintf(out,"num_nodes = %u\n",lh->num_nodes);
77 fprintf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
78 fprintf(out,"num_expands = %lu\n",lh->num_expands);
79 fprintf(out,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
80 fprintf(out,"num_contracts = %lu\n",lh->num_contracts);
81 fprintf(out,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
82 fprintf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
83 fprintf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
84 fprintf(out,"num_insert = %lu\n",lh->num_insert);
85 fprintf(out,"num_replace = %lu\n",lh->num_replace);
86 fprintf(out,"num_delete = %lu\n",lh->num_delete);
87 fprintf(out,"num_no_delete = %lu\n",lh->num_no_delete);
88 fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve);
89 fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
90 fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
91#if 0
92 fprintf(out,"p = %u\n",lh->p);
93 fprintf(out,"pmax = %u\n",lh->pmax);
94 fprintf(out,"up_load = %lu\n",lh->up_load);
95 fprintf(out,"down_load = %lu\n",lh->down_load);
96#endif
97 }
98
99void lh_node_stats(LHASH *lh, FILE *out)
100 {
101 LHASH_NODE *n;
102 unsigned int i,num;
103
104 for (i=0; i<lh->num_nodes; i++)
105 {
106 for (n=lh->b[i],num=0; n != NULL; n=n->next)
107 num++;
108 fprintf(out,"node %6u -> %3u\n",i,num);
109 }
110 }
111
112void lh_node_usage_stats(LHASH *lh, FILE *out)
113 {
114 LHASH_NODE *n;
115 unsigned long num;
116 unsigned int i;
117 unsigned long total=0,n_used=0;
118
119 for (i=0; i<lh->num_nodes; i++)
120 {
121 for (n=lh->b[i],num=0; n != NULL; n=n->next)
122 num++;
123 if (num != 0)
124 {
125 n_used++;
126 total+=num;
127 }
128 }
129 fprintf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
130 fprintf(out,"%lu items\n",total);
131 if (n_used == 0) return;
132 fprintf(out,"load %d.%02d actual load %d.%02d\n",
133 (int)(total/lh->num_nodes),
134 (int)((total%lh->num_nodes)*100/lh->num_nodes),
135 (int)(total/n_used),
136 (int)((total%n_used)*100/n_used));
137 }
138
139#else
140
141#ifndef OPENSSL_NO_FP_API
142void lh_stats(const LHASH *lh, FILE *fp)
143 {
144 BIO *bp;
145
146 bp=BIO_new(BIO_s_file());
147 if (bp == NULL) goto end;
148 BIO_set_fp(bp,fp,BIO_NOCLOSE);
149 lh_stats_bio(lh,bp);
150 BIO_free(bp);
151end:;
152 }
153
154void lh_node_stats(const LHASH *lh, FILE *fp)
155 {
156 BIO *bp;
157
158 bp=BIO_new(BIO_s_file());
159 if (bp == NULL) goto end;
160 BIO_set_fp(bp,fp,BIO_NOCLOSE);
161 lh_node_stats_bio(lh,bp);
162 BIO_free(bp);
163end:;
164 }
165
166void lh_node_usage_stats(const LHASH *lh, FILE *fp)
167 {
168 BIO *bp;
169
170 bp=BIO_new(BIO_s_file());
171 if (bp == NULL) goto end;
172 BIO_set_fp(bp,fp,BIO_NOCLOSE);
173 lh_node_usage_stats_bio(lh,bp);
174 BIO_free(bp);
175end:;
176 }
177
178#endif
179
180void lh_stats_bio(const LHASH *lh, BIO *out)
181 {
182 BIO_printf(out,"num_items = %lu\n",lh->num_items);
183 BIO_printf(out,"num_nodes = %u\n",lh->num_nodes);
184 BIO_printf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
185 BIO_printf(out,"num_expands = %lu\n",lh->num_expands);
186 BIO_printf(out,"num_expand_reallocs = %lu\n",
187 lh->num_expand_reallocs);
188 BIO_printf(out,"num_contracts = %lu\n",lh->num_contracts);
189 BIO_printf(out,"num_contract_reallocs = %lu\n",
190 lh->num_contract_reallocs);
191 BIO_printf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
192 BIO_printf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
193 BIO_printf(out,"num_insert = %lu\n",lh->num_insert);
194 BIO_printf(out,"num_replace = %lu\n",lh->num_replace);
195 BIO_printf(out,"num_delete = %lu\n",lh->num_delete);
196 BIO_printf(out,"num_no_delete = %lu\n",lh->num_no_delete);
197 BIO_printf(out,"num_retrieve = %lu\n",lh->num_retrieve);
198 BIO_printf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
199 BIO_printf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
200#if 0
201 BIO_printf(out,"p = %u\n",lh->p);
202 BIO_printf(out,"pmax = %u\n",lh->pmax);
203 BIO_printf(out,"up_load = %lu\n",lh->up_load);
204 BIO_printf(out,"down_load = %lu\n",lh->down_load);
205#endif
206 }
207
208void lh_node_stats_bio(const LHASH *lh, BIO *out)
209 {
210 LHASH_NODE *n;
211 unsigned int i,num;
212
213 for (i=0; i<lh->num_nodes; i++)
214 {
215 for (n=lh->b[i],num=0; n != NULL; n=n->next)
216 num++;
217 BIO_printf(out,"node %6u -> %3u\n",i,num);
218 }
219 }
220
221void lh_node_usage_stats_bio(const LHASH *lh, BIO *out)
222 {
223 LHASH_NODE *n;
224 unsigned long num;
225 unsigned int i;
226 unsigned long total=0,n_used=0;
227
228 for (i=0; i<lh->num_nodes; i++)
229 {
230 for (n=lh->b[i],num=0; n != NULL; n=n->next)
231 num++;
232 if (num != 0)
233 {
234 n_used++;
235 total+=num;
236 }
237 }
238 BIO_printf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
239 BIO_printf(out,"%lu items\n",total);
240 if (n_used == 0) return;
241 BIO_printf(out,"load %d.%02d actual load %d.%02d\n",
242 (int)(total/lh->num_nodes),
243 (int)((total%lh->num_nodes)*100/lh->num_nodes),
244 (int)(total/n_used),
245 (int)((total%n_used)*100/n_used));
246 }
247
248#endif
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
deleted file mode 100644
index 0a16fcf27d..0000000000
--- a/src/lib/libcrypto/lhash/lhash.c
+++ /dev/null
@@ -1,470 +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, const void *data, unsigned long *rhash);
113
114LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)
115 {
116 LHASH *ret;
117 int i;
118
119 if ((ret=(LHASH *)OPENSSL_malloc(sizeof(LHASH))) == NULL)
120 goto err0;
121 if ((ret->b=(LHASH_NODE **)OPENSSL_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)?(LHASH_COMP_FN_TYPE)strcmp:c);
126 ret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)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 OPENSSL_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 OPENSSL_free(n);
172 n=nn;
173 }
174 }
175 OPENSSL_free(lh->b);
176 OPENSSL_free(lh);
177 }
178
179void *lh_insert(LHASH *lh, const void *data)
180 {
181 unsigned long hash;
182 LHASH_NODE *nn,**rn;
183 const 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 *)OPENSSL_malloc(sizeof(LHASH_NODE))) == NULL)
194 {
195 lh->error++;
196 return(NULL);
197 }
198 nn->data=data;
199 nn->next=NULL;
200#ifndef OPENSSL_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((void *)ret);
215 }
216
217void *lh_delete(LHASH *lh, const void *data)
218 {
219 unsigned long hash;
220 LHASH_NODE *nn,**rn;
221 const 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 OPENSSL_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((void *)ret);
246 }
247
248void *lh_retrieve(LHASH *lh, const void *data)
249 {
250 unsigned long hash;
251 LHASH_NODE **rn;
252 const 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((void *)ret);
268 }
269
270static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
271 LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)
272 {
273 int i;
274 LHASH_NODE *a,*n;
275
276 /* reverse the order so we search from 'top to bottom'
277 * We were having memory leaks otherwise */
278 for (i=lh->num_nodes-1; i>=0; i--)
279 {
280 a=lh->b[i];
281 while (a != NULL)
282 {
283 /* 28/05/91 - eay - n added so items can be deleted
284 * via lh_doall */
285 n=a->next;
286 if(use_arg)
287 func_arg(a->data,arg);
288 else
289 func(a->data);
290 a=n;
291 }
292 }
293 }
294
295void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func)
296 {
297 doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL);
298 }
299
300void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
301 {
302 doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);
303 }
304
305static void expand(LHASH *lh)
306 {
307 LHASH_NODE **n,**n1,**n2,*np;
308 unsigned int p,i,j;
309 unsigned long hash,nni;
310
311 lh->num_nodes++;
312 lh->num_expands++;
313 p=(int)lh->p++;
314 n1= &(lh->b[p]);
315 n2= &(lh->b[p+(int)lh->pmax]);
316 *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
317 nni=lh->num_alloc_nodes;
318
319 for (np= *n1; np != NULL; )
320 {
321#ifndef OPENSSL_NO_HASH_COMP
322 hash=np->hash;
323#else
324 hash=lh->hash(np->data);
325 lh->num_hash_calls++;
326#endif
327 if ((hash%nni) != p)
328 { /* move it */
329 *n1= (*n1)->next;
330 np->next= *n2;
331 *n2=np;
332 }
333 else
334 n1= &((*n1)->next);
335 np= *n1;
336 }
337
338 if ((lh->p) >= lh->pmax)
339 {
340 j=(int)lh->num_alloc_nodes*2;
341 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
342 (unsigned int)sizeof(LHASH_NODE *)*j);
343 if (n == NULL)
344 {
345/* fputs("realloc error in lhash",stderr); */
346 lh->error++;
347 lh->p=0;
348 return;
349 }
350 /* else */
351 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
352 n[i]=NULL; /* 02/03/92 eay */
353 lh->pmax=lh->num_alloc_nodes;
354 lh->num_alloc_nodes=j;
355 lh->num_expand_reallocs++;
356 lh->p=0;
357 lh->b=n;
358 }
359 }
360
361static void contract(LHASH *lh)
362 {
363 LHASH_NODE **n,*n1,*np;
364
365 np=lh->b[lh->p+lh->pmax-1];
366 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
367 if (lh->p == 0)
368 {
369 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
370 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
371 if (n == NULL)
372 {
373/* fputs("realloc error in lhash",stderr); */
374 lh->error++;
375 return;
376 }
377 lh->num_contract_reallocs++;
378 lh->num_alloc_nodes/=2;
379 lh->pmax/=2;
380 lh->p=lh->pmax-1;
381 lh->b=n;
382 }
383 else
384 lh->p--;
385
386 lh->num_nodes--;
387 lh->num_contracts++;
388
389 n1=lh->b[(int)lh->p];
390 if (n1 == NULL)
391 lh->b[(int)lh->p]=np;
392 else
393 {
394 while (n1->next != NULL)
395 n1=n1->next;
396 n1->next=np;
397 }
398 }
399
400static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash)
401 {
402 LHASH_NODE **ret,*n1;
403 unsigned long hash,nn;
404 int (*cf)();
405
406 hash=(*(lh->hash))(data);
407 lh->num_hash_calls++;
408 *rhash=hash;
409
410 nn=hash%lh->pmax;
411 if (nn < lh->p)
412 nn=hash%lh->num_alloc_nodes;
413
414 cf=lh->comp;
415 ret= &(lh->b[(int)nn]);
416 for (n1= *ret; n1 != NULL; n1=n1->next)
417 {
418#ifndef OPENSSL_NO_HASH_COMP
419 lh->num_hash_comps++;
420 if (n1->hash != hash)
421 {
422 ret= &(n1->next);
423 continue;
424 }
425#endif
426 lh->num_comp_calls++;
427 if(cf(n1->data,data) == 0)
428 break;
429 ret= &(n1->next);
430 }
431 return(ret);
432 }
433
434/* The following hash seems to work very well on normal text strings
435 * no collisions on /usr/dict/words and it distributes on %2^n quite
436 * well, not as good as MD5, but still good.
437 */
438unsigned long lh_strhash(const char *c)
439 {
440 unsigned long ret=0;
441 long n;
442 unsigned long v;
443 int r;
444
445 if ((c == NULL) || (*c == '\0'))
446 return(ret);
447/*
448 unsigned char b[16];
449 MD5(c,strlen(c),b);
450 return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24));
451*/
452
453 n=0x100;
454 while (*c)
455 {
456 v=n|(*c);
457 n+=0x100;
458 r= (int)((v>>2)^v)&0x0f;
459 ret=(ret<<r)|(ret>>(32-r));
460 ret&=0xFFFFFFFFL;
461 ret^=v*v;
462 c++;
463 }
464 return((ret>>16)^ret);
465 }
466
467unsigned long lh_num_items(const LHASH *lh)
468 {
469 return lh ? lh->num_items : 0;
470 }
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h
deleted file mode 100644
index dee8207333..0000000000
--- a/src/lib/libcrypto/lhash/lhash.h
+++ /dev/null
@@ -1,199 +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#ifndef OPENSSL_NO_FP_API
67#include <stdio.h>
68#endif
69
70#ifndef OPENSSL_NO_BIO
71#include <openssl/bio.h>
72#endif
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78typedef struct lhash_node_st
79 {
80 const void *data;
81 struct lhash_node_st *next;
82#ifndef OPENSSL_NO_HASH_COMP
83 unsigned long hash;
84#endif
85 } LHASH_NODE;
86
87typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
88typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
89typedef void (*LHASH_DOALL_FN_TYPE)(const void *);
90typedef void (*LHASH_DOALL_ARG_FN_TYPE)(const void *, void *);
91
92/* Macros for declaring and implementing type-safe wrappers for LHASH callbacks.
93 * This way, callbacks can be provided to LHASH structures without function
94 * pointer casting and the macro-defined callbacks provide per-variable casting
95 * before deferring to the underlying type-specific callbacks. NB: It is
96 * possible to place a "static" in front of both the DECLARE and IMPLEMENT
97 * macros if the functions are strictly internal. */
98
99/* First: "hash" functions */
100#define DECLARE_LHASH_HASH_FN(f_name,o_type) \
101 unsigned long f_name##_LHASH_HASH(const void *);
102#define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \
103 unsigned long f_name##_LHASH_HASH(const void *arg) { \
104 o_type a = (o_type)arg; \
105 return f_name(a); }
106#define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH
107
108/* Second: "compare" functions */
109#define DECLARE_LHASH_COMP_FN(f_name,o_type) \
110 int f_name##_LHASH_COMP(const void *, const void *);
111#define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \
112 int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \
113 o_type a = (o_type)arg1; \
114 o_type b = (o_type)arg2; \
115 return f_name(a,b); }
116#define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP
117
118/* Third: "doall" functions */
119#define DECLARE_LHASH_DOALL_FN(f_name,o_type) \
120 void f_name##_LHASH_DOALL(const void *);
121#define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \
122 void f_name##_LHASH_DOALL(const void *arg) { \
123 o_type a = (o_type)arg; \
124 f_name(a); }
125#define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL
126
127/* Fourth: "doall_arg" functions */
128#define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
129 void f_name##_LHASH_DOALL_ARG(const void *, void *);
130#define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
131 void f_name##_LHASH_DOALL_ARG(const void *arg1, void *arg2) { \
132 o_type a = (o_type)arg1; \
133 a_type b = (a_type)arg2; \
134 f_name(a,b); }
135#define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG
136
137typedef struct lhash_st
138 {
139 LHASH_NODE **b;
140 LHASH_COMP_FN_TYPE comp;
141 LHASH_HASH_FN_TYPE hash;
142 unsigned int num_nodes;
143 unsigned int num_alloc_nodes;
144 unsigned int p;
145 unsigned int pmax;
146 unsigned long up_load; /* load times 256 */
147 unsigned long down_load; /* load times 256 */
148 unsigned long num_items;
149
150 unsigned long num_expands;
151 unsigned long num_expand_reallocs;
152 unsigned long num_contracts;
153 unsigned long num_contract_reallocs;
154 unsigned long num_hash_calls;
155 unsigned long num_comp_calls;
156 unsigned long num_insert;
157 unsigned long num_replace;
158 unsigned long num_delete;
159 unsigned long num_no_delete;
160 unsigned long num_retrieve;
161 unsigned long num_retrieve_miss;
162 unsigned long num_hash_comps;
163
164 int error;
165 } LHASH;
166
167#define LH_LOAD_MULT 256
168
169/* Indicates a malloc() error in the last call, this is only bad
170 * in lh_insert(). */
171#define lh_error(lh) ((lh)->error)
172
173LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
174void lh_free(LHASH *lh);
175void *lh_insert(LHASH *lh, const void *data);
176void *lh_delete(LHASH *lh, const void *data);
177void *lh_retrieve(LHASH *lh, const void *data);
178void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
179void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
180unsigned long lh_strhash(const char *c);
181unsigned long lh_num_items(const LHASH *lh);
182
183#ifndef OPENSSL_NO_FP_API
184void lh_stats(const LHASH *lh, FILE *out);
185void lh_node_stats(const LHASH *lh, FILE *out);
186void lh_node_usage_stats(const LHASH *lh, FILE *out);
187#endif
188
189#ifndef OPENSSL_NO_BIO
190void lh_stats_bio(const LHASH *lh, BIO *out);
191void lh_node_stats_bio(const LHASH *lh, BIO *out);
192void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);
193#endif
194#ifdef __cplusplus
195}
196#endif
197
198#endif
199
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h
deleted file mode 100644
index 733da6acaf..0000000000
--- a/src/lib/libcrypto/md32_common.h
+++ /dev/null
@@ -1,649 +0,0 @@
1/* crypto/md32_common.h */
2/* ====================================================================
3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * 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#include <openssl/crypto.h>
132#include <openssl/fips.h>
133#include <openssl/err.h>
134
135#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
136#error "DATA_ORDER must be defined!"
137#endif
138
139#ifndef HASH_CBLOCK
140#error "HASH_CBLOCK must be defined!"
141#endif
142#ifndef HASH_LONG
143#error "HASH_LONG must be defined!"
144#endif
145#ifndef HASH_CTX
146#error "HASH_CTX must be defined!"
147#endif
148
149#ifndef HASH_UPDATE
150#error "HASH_UPDATE must be defined!"
151#endif
152#ifndef HASH_TRANSFORM
153#error "HASH_TRANSFORM must be defined!"
154#endif
155#ifndef HASH_FINAL
156#error "HASH_FINAL must be defined!"
157#endif
158
159#ifndef HASH_BLOCK_HOST_ORDER
160#error "HASH_BLOCK_HOST_ORDER must be defined!"
161#endif
162
163#if 0
164/*
165 * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
166 * isn't defined.
167 */
168#ifndef HASH_BLOCK_DATA_ORDER
169#error "HASH_BLOCK_DATA_ORDER must be defined!"
170#endif
171#endif
172
173#ifndef HASH_LBLOCK
174#define HASH_LBLOCK (HASH_CBLOCK/4)
175#endif
176
177#ifndef HASH_LONG_LOG2
178#define HASH_LONG_LOG2 2
179#endif
180
181/*
182 * Engage compiler specific rotate intrinsic function if available.
183 */
184#undef ROTATE
185#ifndef PEDANTIC
186# if 0 /* defined(_MSC_VER) */
187# define ROTATE(a,n) _lrotl(a,n)
188# elif defined(__MWERKS__)
189# if defined(__POWERPC__)
190# define ROTATE(a,n) __rlwinm(a,n,0,31)
191# elif defined(__MC68K__)
192 /* Motorola specific tweak. <appro@fy.chalmers.se> */
193# define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) )
194# else
195# define ROTATE(a,n) __rol(a,n)
196# endif
197# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
198 /*
199 * Some GNU C inline assembler templates. Note that these are
200 * rotates by *constant* number of bits! But that's exactly
201 * what we need here...
202 *
203 * <appro@fy.chalmers.se>
204 */
205# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
206# define ROTATE(a,n) ({ register unsigned int ret; \
207 asm ( \
208 "roll %1,%0" \
209 : "=r"(ret) \
210 : "I"(n), "0"(a) \
211 : "cc"); \
212 ret; \
213 })
214# elif defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__)
215# define ROTATE(a,n) ({ register unsigned int ret; \
216 asm ( \
217 "rlwinm %0,%1,%2,0,31" \
218 : "=r"(ret) \
219 : "r"(a), "I"(n)); \
220 ret; \
221 })
222# endif
223# endif
224
225/*
226 * Engage compiler specific "fetch in reverse byte order"
227 * intrinsic function if available.
228 */
229# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
230 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
231# if (defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)) && !defined(I386_ONLY)
232# define BE_FETCH32(a) ({ register unsigned int l=(a);\
233 asm ( \
234 "bswapl %0" \
235 : "=r"(l) : "0"(l)); \
236 l; \
237 })
238# elif defined(__powerpc)
239# define LE_FETCH32(a) ({ register unsigned int l; \
240 asm ( \
241 "lwbrx %0,0,%1" \
242 : "=r"(l) \
243 : "r"(a)); \
244 l; \
245 })
246
247# elif defined(__sparc) && defined(OPENSSL_SYS_ULTRASPARC)
248# define LE_FETCH32(a) ({ register unsigned int l; \
249 asm ( \
250 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
251 : "=r"(l) \
252 : "r"(a)); \
253 l; \
254 })
255# endif
256# endif
257#endif /* PEDANTIC */
258
259#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */
260/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
261#ifdef ROTATE
262/* 5 instructions with rotate instruction, else 9 */
263#define REVERSE_FETCH32(a,l) ( \
264 l=*(const HASH_LONG *)(a), \
265 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
266 )
267#else
268/* 6 instructions with rotate instruction, else 8 */
269#define REVERSE_FETCH32(a,l) ( \
270 l=*(const HASH_LONG *)(a), \
271 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
272 ROTATE(l,16) \
273 )
274/*
275 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
276 * It's rewritten as above for two reasons:
277 * - RISCs aren't good at long constants and have to explicitely
278 * compose 'em with several (well, usually 2) instructions in a
279 * register before performing the actual operation and (as you
280 * already realized:-) having same constant should inspire the
281 * compiler to permanently allocate the only register for it;
282 * - most modern CPUs have two ALUs, but usually only one has
283 * circuitry for shifts:-( this minor tweak inspires compiler
284 * to schedule shift instructions in a better way...
285 *
286 * <appro@fy.chalmers.se>
287 */
288#endif
289#endif
290
291#ifndef ROTATE
292#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
293#endif
294
295/*
296 * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
297 * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
298 * and host are of the same "endianess". It's possible to mask
299 * this with blank #define HASH_BLOCK_DATA_ORDER though...
300 *
301 * <appro@fy.chalmers.se>
302 */
303#if defined(B_ENDIAN)
304# if defined(DATA_ORDER_IS_BIG_ENDIAN)
305# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
306# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
307# endif
308# elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
309# ifndef HOST_FETCH32
310# ifdef LE_FETCH32
311# define HOST_FETCH32(p,l) LE_FETCH32(p)
312# elif defined(REVERSE_FETCH32)
313# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
314# endif
315# endif
316# endif
317#elif defined(L_ENDIAN)
318# if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
319# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
320# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
321# endif
322# elif defined(DATA_ORDER_IS_BIG_ENDIAN)
323# ifndef HOST_FETCH32
324# ifdef BE_FETCH32
325# define HOST_FETCH32(p,l) BE_FETCH32(p)
326# elif defined(REVERSE_FETCH32)
327# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
328# endif
329# endif
330# endif
331#endif
332
333#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
334#ifndef HASH_BLOCK_DATA_ORDER
335#error "HASH_BLOCK_DATA_ORDER must be defined!"
336#endif
337#endif
338
339#if defined(DATA_ORDER_IS_BIG_ENDIAN)
340
341#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
342 l|=(((unsigned long)(*((c)++)))<<16), \
343 l|=(((unsigned long)(*((c)++)))<< 8), \
344 l|=(((unsigned long)(*((c)++))) ), \
345 l)
346#define HOST_p_c2l(c,l,n) { \
347 switch (n) { \
348 case 0: l =((unsigned long)(*((c)++)))<<24; \
349 case 1: l|=((unsigned long)(*((c)++)))<<16; \
350 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
351 case 3: l|=((unsigned long)(*((c)++))); \
352 } }
353#define HOST_p_c2l_p(c,l,sc,len) { \
354 switch (sc) { \
355 case 0: l =((unsigned long)(*((c)++)))<<24; \
356 if (--len == 0) break; \
357 case 1: l|=((unsigned long)(*((c)++)))<<16; \
358 if (--len == 0) break; \
359 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
360 } }
361/* NOTE the pointer is not incremented at the end of this */
362#define HOST_c2l_p(c,l,n) { \
363 l=0; (c)+=n; \
364 switch (n) { \
365 case 3: l =((unsigned long)(*(--(c))))<< 8; \
366 case 2: l|=((unsigned long)(*(--(c))))<<16; \
367 case 1: l|=((unsigned long)(*(--(c))))<<24; \
368 } }
369#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
370 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
371 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
372 *((c)++)=(unsigned char)(((l) )&0xff), \
373 l)
374
375#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
376
377#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
378 l|=(((unsigned long)(*((c)++)))<< 8), \
379 l|=(((unsigned long)(*((c)++)))<<16), \
380 l|=(((unsigned long)(*((c)++)))<<24), \
381 l)
382#define HOST_p_c2l(c,l,n) { \
383 switch (n) { \
384 case 0: l =((unsigned long)(*((c)++))); \
385 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
386 case 2: l|=((unsigned long)(*((c)++)))<<16; \
387 case 3: l|=((unsigned long)(*((c)++)))<<24; \
388 } }
389#define HOST_p_c2l_p(c,l,sc,len) { \
390 switch (sc) { \
391 case 0: l =((unsigned long)(*((c)++))); \
392 if (--len == 0) break; \
393 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
394 if (--len == 0) break; \
395 case 2: l|=((unsigned long)(*((c)++)))<<16; \
396 } }
397/* NOTE the pointer is not incremented at the end of this */
398#define HOST_c2l_p(c,l,n) { \
399 l=0; (c)+=n; \
400 switch (n) { \
401 case 3: l =((unsigned long)(*(--(c))))<<16; \
402 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
403 case 1: l|=((unsigned long)(*(--(c)))); \
404 } }
405#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
406 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
407 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
408 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
409 l)
410
411#endif
412
413/*
414 * Time for some action:-)
415 */
416
417int HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
418 {
419 const unsigned char *data=data_;
420 register HASH_LONG * p;
421 register unsigned long l;
422 int sw,sc,ew,ec;
423
424 if (len==0) return 1;
425
426 l=(c->Nl+(len<<3))&0xffffffffL;
427 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
428 * Wei Dai <weidai@eskimo.com> for pointing it out. */
429 if (l < c->Nl) /* overflow */
430 c->Nh++;
431 c->Nh+=(len>>29);
432 c->Nl=l;
433
434 if (c->num != 0)
435 {
436 p=c->data;
437 sw=c->num>>2;
438 sc=c->num&0x03;
439
440 if ((c->num+len) >= HASH_CBLOCK)
441 {
442 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
443 for (; sw<HASH_LBLOCK; sw++)
444 {
445 HOST_c2l(data,l); p[sw]=l;
446 }
447 HASH_BLOCK_HOST_ORDER (c,p,1);
448 len-=(HASH_CBLOCK-c->num);
449 c->num=0;
450 /* drop through and do the rest */
451 }
452 else
453 {
454 c->num+=len;
455 if ((sc+len) < 4) /* ugly, add char's to a word */
456 {
457 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
458 }
459 else
460 {
461 ew=(c->num>>2);
462 ec=(c->num&0x03);
463 if (sc)
464 l=p[sw];
465 HOST_p_c2l(data,l,sc);
466 p[sw++]=l;
467 for (; sw < ew; sw++)
468 {
469 HOST_c2l(data,l); p[sw]=l;
470 }
471 if (ec)
472 {
473 HOST_c2l_p(data,l,ec); p[sw]=l;
474 }
475 }
476 return 1;
477 }
478 }
479
480 sw=len/HASH_CBLOCK;
481 if (sw > 0)
482 {
483#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
484 /*
485 * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
486 * only if sizeof(HASH_LONG)==4.
487 */
488 if ((((unsigned long)data)%4) == 0)
489 {
490 /* data is properly aligned so that we can cast it: */
491 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
492 sw*=HASH_CBLOCK;
493 data+=sw;
494 len-=sw;
495 }
496 else
497#if !defined(HASH_BLOCK_DATA_ORDER)
498 while (sw--)
499 {
500 memcpy (p=c->data,data,HASH_CBLOCK);
501 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
502 data+=HASH_CBLOCK;
503 len-=HASH_CBLOCK;
504 }
505#endif
506#endif
507#if defined(HASH_BLOCK_DATA_ORDER)
508 {
509 HASH_BLOCK_DATA_ORDER(c,data,sw);
510 sw*=HASH_CBLOCK;
511 data+=sw;
512 len-=sw;
513 }
514#endif
515 }
516
517 if (len!=0)
518 {
519 p = c->data;
520 c->num = len;
521 ew=len>>2; /* words to copy */
522 ec=len&0x03;
523 for (; ew; ew--,p++)
524 {
525 HOST_c2l(data,l); *p=l;
526 }
527 HOST_c2l_p(data,l,ec);
528 *p=l;
529 }
530 return 1;
531 }
532
533
534void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
535 {
536#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
537 if ((((unsigned long)data)%4) == 0)
538 /* data is properly aligned so that we can cast it: */
539 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
540 else
541#if !defined(HASH_BLOCK_DATA_ORDER)
542 {
543 memcpy (c->data,data,HASH_CBLOCK);
544 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
545 }
546#endif
547#endif
548#if defined(HASH_BLOCK_DATA_ORDER)
549 HASH_BLOCK_DATA_ORDER (c,data,1);
550#endif
551 }
552
553
554int HASH_FINAL (unsigned char *md, HASH_CTX *c)
555 {
556 register HASH_LONG *p;
557 register unsigned long l;
558 register int i,j;
559 static const unsigned char end[4]={0x80,0x00,0x00,0x00};
560 const unsigned char *cp=end;
561
562#if 0
563 if(FIPS_mode() && !FIPS_md5_allowed())
564 {
565 FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD);
566 return 0;
567 }
568#endif
569
570 /* c->num should definitly have room for at least one more byte. */
571 p=c->data;
572 i=c->num>>2;
573 j=c->num&0x03;
574
575#if 0
576 /* purify often complains about the following line as an
577 * Uninitialized Memory Read. While this can be true, the
578 * following p_c2l macro will reset l when that case is true.
579 * This is because j&0x03 contains the number of 'valid' bytes
580 * already in p[i]. If and only if j&0x03 == 0, the UMR will
581 * occur but this is also the only time p_c2l will do
582 * l= *(cp++) instead of l|= *(cp++)
583 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
584 * 'potential bug' */
585#ifdef PURIFY
586 if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
587#endif
588 l=p[i];
589#else
590 l = (j==0) ? 0 : p[i];
591#endif
592 HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
593
594 if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
595 {
596 if (i<HASH_LBLOCK) p[i]=0;
597 HASH_BLOCK_HOST_ORDER (c,p,1);
598 i=0;
599 }
600 for (; i<(HASH_LBLOCK-2); i++)
601 p[i]=0;
602
603#if defined(DATA_ORDER_IS_BIG_ENDIAN)
604 p[HASH_LBLOCK-2]=c->Nh;
605 p[HASH_LBLOCK-1]=c->Nl;
606#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
607 p[HASH_LBLOCK-2]=c->Nl;
608 p[HASH_LBLOCK-1]=c->Nh;
609#endif
610 HASH_BLOCK_HOST_ORDER (c,p,1);
611
612#ifndef HASH_MAKE_STRING
613#error "HASH_MAKE_STRING must be defined!"
614#else
615 HASH_MAKE_STRING(c,md);
616#endif
617
618 c->num=0;
619 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
620 * but I'm not worried :-)
621 OPENSSL_cleanse((void *)c,sizeof(HASH_CTX));
622 */
623 return 1;
624 }
625
626#ifndef MD32_REG_T
627#define MD32_REG_T long
628/*
629 * This comment was originaly written for MD5, which is why it
630 * discusses A-D. But it basically applies to all 32-bit digests,
631 * which is why it was moved to common header file.
632 *
633 * In case you wonder why A-D are declared as long and not
634 * as MD5_LONG. Doing so results in slight performance
635 * boost on LP64 architectures. The catch is we don't
636 * really care if 32 MSBs of a 64-bit register get polluted
637 * with eventual overflows as we *save* only 32 LSBs in
638 * *either* case. Now declaring 'em long excuses the compiler
639 * from keeping 32 MSBs zeroed resulting in 13% performance
640 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
641 * Well, to be honest it should say that this *prevents*
642 * performance degradation.
643 * <appro@fy.chalmers.se>
644 * Apparently there're LP64 compilers that generate better
645 * code if A-D are declared int. Most notably GCC-x86_64
646 * generates better code.
647 * <appro@fy.chalmers.se>
648 */
649#endif
diff --git a/src/lib/libcrypto/md4/md4.h b/src/lib/libcrypto/md4/md4.h
deleted file mode 100644
index 7e761efb62..0000000000
--- a/src/lib/libcrypto/md4/md4.h
+++ /dev/null
@@ -1,119 +0,0 @@
1/* crypto/md4/md4.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_MD4_H
60#define HEADER_MD4_H
61
62#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_MD4
69#error MD4 is disabled.
70#endif
71
72/*
73 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
74 * ! MD4_LONG has to be at least 32 bits wide. If it's wider, then !
75 * ! MD4_LONG_LOG2 has to be defined along. !
76 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 */
78
79#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
80#define MD4_LONG unsigned long
81#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
82#define MD4_LONG unsigned long
83#define MD4_LONG_LOG2 3
84/*
85 * _CRAY note. I could declare short, but I have no idea what impact
86 * does it have on performance on none-T3E machines. I could declare
87 * int, but at least on C90 sizeof(int) can be chosen at compile time.
88 * So I've chosen long...
89 * <appro@fy.chalmers.se>
90 */
91#else
92#define MD4_LONG unsigned int
93#endif
94
95#define MD4_CBLOCK 64
96#define MD4_LBLOCK (MD4_CBLOCK/4)
97#define MD4_DIGEST_LENGTH 16
98
99typedef struct MD4state_st
100 {
101 MD4_LONG A,B,C,D;
102 MD4_LONG Nl,Nh;
103 MD4_LONG data[MD4_LBLOCK];
104 int num;
105 } MD4_CTX;
106
107#ifdef OPENSSL_FIPS
108int private_MD4_Init(MD4_CTX *c);
109#endif
110int MD4_Init(MD4_CTX *c);
111int MD4_Update(MD4_CTX *c, const void *data, unsigned long len);
112int MD4_Final(unsigned char *md, MD4_CTX *c);
113unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md);
114void MD4_Transform(MD4_CTX *c, const unsigned char *b);
115#ifdef __cplusplus
116}
117#endif
118
119#endif
diff --git a/src/lib/libcrypto/md4/md4_dgst.c b/src/lib/libcrypto/md4/md4_dgst.c
deleted file mode 100644
index ee7cc72262..0000000000
--- a/src/lib/libcrypto/md4/md4_dgst.c
+++ /dev/null
@@ -1,258 +0,0 @@
1/* crypto/md4/md4_dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "md4_locl.h"
61#include <openssl/opensslv.h>
62
63const char *MD4_version="MD4" OPENSSL_VERSION_PTEXT;
64
65/* Implemented from RFC1186 The MD4 Message-Digest Algorithm
66 */
67
68#define INIT_DATA_A (unsigned long)0x67452301L
69#define INIT_DATA_B (unsigned long)0xefcdab89L
70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L
72
73FIPS_NON_FIPS_MD_Init(MD4)
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 return 1;
83 }
84
85#ifndef md4_block_host_order
86void md4_block_host_order (MD4_CTX *c, const void *data, int num)
87 {
88 const MD4_LONG *X=data;
89 register unsigned MD32_REG_T A,B,C,D;
90
91 A=c->A;
92 B=c->B;
93 C=c->C;
94 D=c->D;
95
96 for (;num--;X+=HASH_LBLOCK)
97 {
98 /* Round 0 */
99 R0(A,B,C,D,X[ 0], 3,0);
100 R0(D,A,B,C,X[ 1], 7,0);
101 R0(C,D,A,B,X[ 2],11,0);
102 R0(B,C,D,A,X[ 3],19,0);
103 R0(A,B,C,D,X[ 4], 3,0);
104 R0(D,A,B,C,X[ 5], 7,0);
105 R0(C,D,A,B,X[ 6],11,0);
106 R0(B,C,D,A,X[ 7],19,0);
107 R0(A,B,C,D,X[ 8], 3,0);
108 R0(D,A,B,C,X[ 9], 7,0);
109 R0(C,D,A,B,X[10],11,0);
110 R0(B,C,D,A,X[11],19,0);
111 R0(A,B,C,D,X[12], 3,0);
112 R0(D,A,B,C,X[13], 7,0);
113 R0(C,D,A,B,X[14],11,0);
114 R0(B,C,D,A,X[15],19,0);
115 /* Round 1 */
116 R1(A,B,C,D,X[ 0], 3,0x5A827999L);
117 R1(D,A,B,C,X[ 4], 5,0x5A827999L);
118 R1(C,D,A,B,X[ 8], 9,0x5A827999L);
119 R1(B,C,D,A,X[12],13,0x5A827999L);
120 R1(A,B,C,D,X[ 1], 3,0x5A827999L);
121 R1(D,A,B,C,X[ 5], 5,0x5A827999L);
122 R1(C,D,A,B,X[ 9], 9,0x5A827999L);
123 R1(B,C,D,A,X[13],13,0x5A827999L);
124 R1(A,B,C,D,X[ 2], 3,0x5A827999L);
125 R1(D,A,B,C,X[ 6], 5,0x5A827999L);
126 R1(C,D,A,B,X[10], 9,0x5A827999L);
127 R1(B,C,D,A,X[14],13,0x5A827999L);
128 R1(A,B,C,D,X[ 3], 3,0x5A827999L);
129 R1(D,A,B,C,X[ 7], 5,0x5A827999L);
130 R1(C,D,A,B,X[11], 9,0x5A827999L);
131 R1(B,C,D,A,X[15],13,0x5A827999L);
132 /* Round 2 */
133 R2(A,B,C,D,X[ 0], 3,0x6ED9EBA1);
134 R2(D,A,B,C,X[ 8], 9,0x6ED9EBA1);
135 R2(C,D,A,B,X[ 4],11,0x6ED9EBA1);
136 R2(B,C,D,A,X[12],15,0x6ED9EBA1);
137 R2(A,B,C,D,X[ 2], 3,0x6ED9EBA1);
138 R2(D,A,B,C,X[10], 9,0x6ED9EBA1);
139 R2(C,D,A,B,X[ 6],11,0x6ED9EBA1);
140 R2(B,C,D,A,X[14],15,0x6ED9EBA1);
141 R2(A,B,C,D,X[ 1], 3,0x6ED9EBA1);
142 R2(D,A,B,C,X[ 9], 9,0x6ED9EBA1);
143 R2(C,D,A,B,X[ 5],11,0x6ED9EBA1);
144 R2(B,C,D,A,X[13],15,0x6ED9EBA1);
145 R2(A,B,C,D,X[ 3], 3,0x6ED9EBA1);
146 R2(D,A,B,C,X[11], 9,0x6ED9EBA1);
147 R2(C,D,A,B,X[ 7],11,0x6ED9EBA1);
148 R2(B,C,D,A,X[15],15,0x6ED9EBA1);
149
150 A = c->A += A;
151 B = c->B += B;
152 C = c->C += C;
153 D = c->D += D;
154 }
155 }
156#endif
157
158#ifndef md4_block_data_order
159#ifdef X
160#undef X
161#endif
162void md4_block_data_order (MD4_CTX *c, const void *data_, int num)
163 {
164 const unsigned char *data=data_;
165 register unsigned MD32_REG_T A,B,C,D,l;
166#ifndef MD32_XARRAY
167 /* See comment in crypto/sha/sha_locl.h for details. */
168 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
169 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
170# define X(i) XX##i
171#else
172 MD4_LONG XX[MD4_LBLOCK];
173# define X(i) XX[i]
174#endif
175
176 A=c->A;
177 B=c->B;
178 C=c->C;
179 D=c->D;
180
181 for (;num--;)
182 {
183 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
184 /* Round 0 */
185 R0(A,B,C,D,X( 0), 3,0); HOST_c2l(data,l); X( 2)=l;
186 R0(D,A,B,C,X( 1), 7,0); HOST_c2l(data,l); X( 3)=l;
187 R0(C,D,A,B,X( 2),11,0); HOST_c2l(data,l); X( 4)=l;
188 R0(B,C,D,A,X( 3),19,0); HOST_c2l(data,l); X( 5)=l;
189 R0(A,B,C,D,X( 4), 3,0); HOST_c2l(data,l); X( 6)=l;
190 R0(D,A,B,C,X( 5), 7,0); HOST_c2l(data,l); X( 7)=l;
191 R0(C,D,A,B,X( 6),11,0); HOST_c2l(data,l); X( 8)=l;
192 R0(B,C,D,A,X( 7),19,0); HOST_c2l(data,l); X( 9)=l;
193 R0(A,B,C,D,X( 8), 3,0); HOST_c2l(data,l); X(10)=l;
194 R0(D,A,B,C,X( 9), 7,0); HOST_c2l(data,l); X(11)=l;
195 R0(C,D,A,B,X(10),11,0); HOST_c2l(data,l); X(12)=l;
196 R0(B,C,D,A,X(11),19,0); HOST_c2l(data,l); X(13)=l;
197 R0(A,B,C,D,X(12), 3,0); HOST_c2l(data,l); X(14)=l;
198 R0(D,A,B,C,X(13), 7,0); HOST_c2l(data,l); X(15)=l;
199 R0(C,D,A,B,X(14),11,0);
200 R0(B,C,D,A,X(15),19,0);
201 /* Round 1 */
202 R1(A,B,C,D,X( 0), 3,0x5A827999L);
203 R1(D,A,B,C,X( 4), 5,0x5A827999L);
204 R1(C,D,A,B,X( 8), 9,0x5A827999L);
205 R1(B,C,D,A,X(12),13,0x5A827999L);
206 R1(A,B,C,D,X( 1), 3,0x5A827999L);
207 R1(D,A,B,C,X( 5), 5,0x5A827999L);
208 R1(C,D,A,B,X( 9), 9,0x5A827999L);
209 R1(B,C,D,A,X(13),13,0x5A827999L);
210 R1(A,B,C,D,X( 2), 3,0x5A827999L);
211 R1(D,A,B,C,X( 6), 5,0x5A827999L);
212 R1(C,D,A,B,X(10), 9,0x5A827999L);
213 R1(B,C,D,A,X(14),13,0x5A827999L);
214 R1(A,B,C,D,X( 3), 3,0x5A827999L);
215 R1(D,A,B,C,X( 7), 5,0x5A827999L);
216 R1(C,D,A,B,X(11), 9,0x5A827999L);
217 R1(B,C,D,A,X(15),13,0x5A827999L);
218 /* Round 2 */
219 R2(A,B,C,D,X( 0), 3,0x6ED9EBA1L);
220 R2(D,A,B,C,X( 8), 9,0x6ED9EBA1L);
221 R2(C,D,A,B,X( 4),11,0x6ED9EBA1L);
222 R2(B,C,D,A,X(12),15,0x6ED9EBA1L);
223 R2(A,B,C,D,X( 2), 3,0x6ED9EBA1L);
224 R2(D,A,B,C,X(10), 9,0x6ED9EBA1L);
225 R2(C,D,A,B,X( 6),11,0x6ED9EBA1L);
226 R2(B,C,D,A,X(14),15,0x6ED9EBA1L);
227 R2(A,B,C,D,X( 1), 3,0x6ED9EBA1L);
228 R2(D,A,B,C,X( 9), 9,0x6ED9EBA1L);
229 R2(C,D,A,B,X( 5),11,0x6ED9EBA1L);
230 R2(B,C,D,A,X(13),15,0x6ED9EBA1L);
231 R2(A,B,C,D,X( 3), 3,0x6ED9EBA1L);
232 R2(D,A,B,C,X(11), 9,0x6ED9EBA1L);
233 R2(C,D,A,B,X( 7),11,0x6ED9EBA1L);
234 R2(B,C,D,A,X(15),15,0x6ED9EBA1L);
235
236 A = c->A += A;
237 B = c->B += B;
238 C = c->C += C;
239 D = c->D += D;
240 }
241 }
242#endif
243
244#ifdef undef
245int printit(unsigned long *l)
246 {
247 int i,ii;
248
249 for (i=0; i<2; i++)
250 {
251 for (ii=0; ii<8; ii++)
252 {
253 fprintf(stderr,"%08lx ",l[i*8+ii]);
254 }
255 fprintf(stderr,"\n");
256 }
257 }
258#endif
diff --git a/src/lib/libcrypto/md4/md4_locl.h b/src/lib/libcrypto/md4/md4_locl.h
deleted file mode 100644
index a8d31d7a73..0000000000
--- a/src/lib/libcrypto/md4/md4_locl.h
+++ /dev/null
@@ -1,154 +0,0 @@
1/* crypto/md4/md4_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60#include <string.h>
61#include <openssl/opensslconf.h>
62#include <openssl/md4.h>
63
64#ifndef MD4_LONG_LOG2
65#define MD4_LONG_LOG2 2 /* default to 32 bits */
66#endif
67
68void md4_block_host_order (MD4_CTX *c, const void *p,int num);
69void md4_block_data_order (MD4_CTX *c, const void *p,int num);
70
71#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
72/*
73 * *_block_host_order is expected to handle aligned data while
74 * *_block_data_order - unaligned. As algorithm and host (x86)
75 * are in this case of the same "endianness" these two are
76 * otherwise indistinguishable. But normally you don't want to
77 * call the same function because unaligned access in places
78 * where alignment is expected is usually a "Bad Thing". Indeed,
79 * on RISCs you get punished with BUS ERROR signal or *severe*
80 * performance degradation. Intel CPUs are in turn perfectly
81 * capable of loading unaligned data without such drastic side
82 * effect. Yes, they say it's slower than aligned load, but no
83 * exception is generated and therefore performance degradation
84 * is *incomparable* with RISCs. What we should weight here is
85 * costs of unaligned access against costs of aligning data.
86 * According to my measurements allowing unaligned access results
87 * in ~9% performance improvement on Pentium II operating at
88 * 266MHz. I won't be surprised if the difference will be higher
89 * on faster systems:-)
90 *
91 * <appro@fy.chalmers.se>
92 */
93#define md4_block_data_order md4_block_host_order
94#endif
95
96#define DATA_ORDER_IS_LITTLE_ENDIAN
97
98#define HASH_LONG MD4_LONG
99#define HASH_LONG_LOG2 MD4_LONG_LOG2
100#define HASH_CTX MD4_CTX
101#define HASH_CBLOCK MD4_CBLOCK
102#define HASH_LBLOCK MD4_LBLOCK
103#define HASH_UPDATE MD4_Update
104#define HASH_TRANSFORM MD4_Transform
105#define HASH_FINAL MD4_Final
106#define HASH_MAKE_STRING(c,s) do { \
107 unsigned long ll; \
108 ll=(c)->A; HOST_l2c(ll,(s)); \
109 ll=(c)->B; HOST_l2c(ll,(s)); \
110 ll=(c)->C; HOST_l2c(ll,(s)); \
111 ll=(c)->D; HOST_l2c(ll,(s)); \
112 } while (0)
113#define HASH_BLOCK_HOST_ORDER md4_block_host_order
114#if !defined(L_ENDIAN) || defined(md4_block_data_order)
115#define HASH_BLOCK_DATA_ORDER md4_block_data_order
116/*
117 * Little-endians (Intel and Alpha) feel better without this.
118 * It looks like memcpy does better job than generic
119 * md4_block_data_order on copying-n-aligning input data.
120 * But frankly speaking I didn't expect such result on Alpha.
121 * On the other hand I've got this with egcs-1.0.2 and if
122 * program is compiled with another (better?) compiler it
123 * might turn out other way around.
124 *
125 * <appro@fy.chalmers.se>
126 */
127#endif
128
129#include "md32_common.h"
130
131/*
132#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
133#define G(x,y,z) (((x) & (y)) | ((x) & ((z))) | ((y) & ((z))))
134*/
135
136/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
137 * simplified to the code below. Wei attributes these optimizations
138 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
139 */
140#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
141#define G(b,c,d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
142#define H(b,c,d) ((b) ^ (c) ^ (d))
143
144#define R0(a,b,c,d,k,s,t) { \
145 a+=((k)+(t)+F((b),(c),(d))); \
146 a=ROTATE(a,s); };
147
148#define R1(a,b,c,d,k,s,t) { \
149 a+=((k)+(t)+G((b),(c),(d))); \
150 a=ROTATE(a,s); };\
151
152#define R2(a,b,c,d,k,s,t) { \
153 a+=((k)+(t)+H((b),(c),(d))); \
154 a=ROTATE(a,s); };
diff --git a/src/lib/libcrypto/md4/md4_one.c b/src/lib/libcrypto/md4/md4_one.c
deleted file mode 100644
index 50f79352f6..0000000000
--- a/src/lib/libcrypto/md4/md4_one.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/* crypto/md4/md4_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/md4.h>
62#include <openssl/crypto.h>
63
64#ifdef CHARSET_EBCDIC
65#include <openssl/ebcdic.h>
66#endif
67
68unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md)
69 {
70 MD4_CTX c;
71 static unsigned char m[MD4_DIGEST_LENGTH];
72
73 if (md == NULL) md=m;
74 if (!MD4_Init(&c))
75 return NULL;
76#ifndef CHARSET_EBCDIC
77 MD4_Update(&c,d,n);
78#else
79 {
80 char temp[1024];
81 unsigned long chunk;
82
83 while (n > 0)
84 {
85 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
86 ebcdic2ascii(temp, d, chunk);
87 MD4_Update(&c,temp,chunk);
88 n -= chunk;
89 d += chunk;
90 }
91 }
92#endif
93 MD4_Final(md,&c);
94 OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
95 return(md);
96 }
97
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 fa3fa3bed5..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 &jae(&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 c663dd1816..0000000000
--- a/src/lib/libcrypto/md5/md5.h
+++ /dev/null
@@ -1,119 +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#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_MD5
69#error MD5 is disabled.
70#endif
71
72/*
73 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
74 * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !
75 * ! MD5_LONG_LOG2 has to be defined along. !
76 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 */
78
79#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
80#define MD5_LONG unsigned long
81#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
82#define MD5_LONG unsigned long
83#define MD5_LONG_LOG2 3
84/*
85 * _CRAY note. I could declare short, but I have no idea what impact
86 * does it have on performance on none-T3E machines. I could declare
87 * int, but at least on C90 sizeof(int) can be chosen at compile time.
88 * So I've chosen long...
89 * <appro@fy.chalmers.se>
90 */
91#else
92#define MD5_LONG unsigned int
93#endif
94
95#define MD5_CBLOCK 64
96#define MD5_LBLOCK (MD5_CBLOCK/4)
97#define MD5_DIGEST_LENGTH 16
98
99typedef struct MD5state_st
100 {
101 MD5_LONG A,B,C,D;
102 MD5_LONG Nl,Nh;
103 MD5_LONG data[MD5_LBLOCK];
104 int num;
105 } MD5_CTX;
106
107#ifdef OPENSSL_FIPS
108int private_MD5_Init(MD5_CTX *c);
109#endif
110int MD5_Init(MD5_CTX *c);
111int MD5_Update(MD5_CTX *c, const void *data, unsigned long len);
112int MD5_Final(unsigned char *md, MD5_CTX *c);
113unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md);
114void MD5_Transform(MD5_CTX *c, const unsigned char *b);
115#ifdef __cplusplus
116}
117#endif
118
119#endif
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c
deleted file mode 100644
index 54b33c6509..0000000000
--- a/src/lib/libcrypto/md5/md5_dgst.c
+++ /dev/null
@@ -1,292 +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
73FIPS_NON_FIPS_MD_Init(MD5)
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 return 1;
83 }
84
85#ifndef md5_block_host_order
86void md5_block_host_order (MD5_CTX *c, const void *data, int num)
87 {
88 const MD5_LONG *X=data;
89 register unsigned MD32_REG_T A,B,C,D;
90
91 A=c->A;
92 B=c->B;
93 C=c->C;
94 D=c->D;
95
96 for (;num--;X+=HASH_LBLOCK)
97 {
98 /* Round 0 */
99 R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
100 R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
101 R0(C,D,A,B,X[ 2],17,0x242070dbL);
102 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
103 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
104 R0(D,A,B,C,X[ 5],12,0x4787c62aL);
105 R0(C,D,A,B,X[ 6],17,0xa8304613L);
106 R0(B,C,D,A,X[ 7],22,0xfd469501L);
107 R0(A,B,C,D,X[ 8], 7,0x698098d8L);
108 R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
109 R0(C,D,A,B,X[10],17,0xffff5bb1L);
110 R0(B,C,D,A,X[11],22,0x895cd7beL);
111 R0(A,B,C,D,X[12], 7,0x6b901122L);
112 R0(D,A,B,C,X[13],12,0xfd987193L);
113 R0(C,D,A,B,X[14],17,0xa679438eL);
114 R0(B,C,D,A,X[15],22,0x49b40821L);
115 /* Round 1 */
116 R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
117 R1(D,A,B,C,X[ 6], 9,0xc040b340L);
118 R1(C,D,A,B,X[11],14,0x265e5a51L);
119 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
120 R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
121 R1(D,A,B,C,X[10], 9,0x02441453L);
122 R1(C,D,A,B,X[15],14,0xd8a1e681L);
123 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
124 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
125 R1(D,A,B,C,X[14], 9,0xc33707d6L);
126 R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
127 R1(B,C,D,A,X[ 8],20,0x455a14edL);
128 R1(A,B,C,D,X[13], 5,0xa9e3e905L);
129 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
130 R1(C,D,A,B,X[ 7],14,0x676f02d9L);
131 R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
132 /* Round 2 */
133 R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
134 R2(D,A,B,C,X[ 8],11,0x8771f681L);
135 R2(C,D,A,B,X[11],16,0x6d9d6122L);
136 R2(B,C,D,A,X[14],23,0xfde5380cL);
137 R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
138 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
139 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
140 R2(B,C,D,A,X[10],23,0xbebfbc70L);
141 R2(A,B,C,D,X[13], 4,0x289b7ec6L);
142 R2(D,A,B,C,X[ 0],11,0xeaa127faL);
143 R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
144 R2(B,C,D,A,X[ 6],23,0x04881d05L);
145 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
146 R2(D,A,B,C,X[12],11,0xe6db99e5L);
147 R2(C,D,A,B,X[15],16,0x1fa27cf8L);
148 R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
149 /* Round 3 */
150 R3(A,B,C,D,X[ 0], 6,0xf4292244L);
151 R3(D,A,B,C,X[ 7],10,0x432aff97L);
152 R3(C,D,A,B,X[14],15,0xab9423a7L);
153 R3(B,C,D,A,X[ 5],21,0xfc93a039L);
154 R3(A,B,C,D,X[12], 6,0x655b59c3L);
155 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
156 R3(C,D,A,B,X[10],15,0xffeff47dL);
157 R3(B,C,D,A,X[ 1],21,0x85845dd1L);
158 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
159 R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
160 R3(C,D,A,B,X[ 6],15,0xa3014314L);
161 R3(B,C,D,A,X[13],21,0x4e0811a1L);
162 R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
163 R3(D,A,B,C,X[11],10,0xbd3af235L);
164 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
165 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
166
167 A = c->A += A;
168 B = c->B += B;
169 C = c->C += C;
170 D = c->D += D;
171 }
172 }
173#endif
174
175#ifndef md5_block_data_order
176#ifdef X
177#undef X
178#endif
179void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
180 {
181 const unsigned char *data=data_;
182 register unsigned MD32_REG_T A,B,C,D,l;
183#ifndef MD32_XARRAY
184 /* See comment in crypto/sha/sha_locl.h for details. */
185 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
186 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
187# define X(i) XX##i
188#else
189 MD5_LONG XX[MD5_LBLOCK];
190# define X(i) XX[i]
191#endif
192
193 A=c->A;
194 B=c->B;
195 C=c->C;
196 D=c->D;
197
198 for (;num--;)
199 {
200 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
201 /* Round 0 */
202 R0(A,B,C,D,X( 0), 7,0xd76aa478L); HOST_c2l(data,l); X( 2)=l;
203 R0(D,A,B,C,X( 1),12,0xe8c7b756L); HOST_c2l(data,l); X( 3)=l;
204 R0(C,D,A,B,X( 2),17,0x242070dbL); HOST_c2l(data,l); X( 4)=l;
205 R0(B,C,D,A,X( 3),22,0xc1bdceeeL); HOST_c2l(data,l); X( 5)=l;
206 R0(A,B,C,D,X( 4), 7,0xf57c0fafL); HOST_c2l(data,l); X( 6)=l;
207 R0(D,A,B,C,X( 5),12,0x4787c62aL); HOST_c2l(data,l); X( 7)=l;
208 R0(C,D,A,B,X( 6),17,0xa8304613L); HOST_c2l(data,l); X( 8)=l;
209 R0(B,C,D,A,X( 7),22,0xfd469501L); HOST_c2l(data,l); X( 9)=l;
210 R0(A,B,C,D,X( 8), 7,0x698098d8L); HOST_c2l(data,l); X(10)=l;
211 R0(D,A,B,C,X( 9),12,0x8b44f7afL); HOST_c2l(data,l); X(11)=l;
212 R0(C,D,A,B,X(10),17,0xffff5bb1L); HOST_c2l(data,l); X(12)=l;
213 R0(B,C,D,A,X(11),22,0x895cd7beL); HOST_c2l(data,l); X(13)=l;
214 R0(A,B,C,D,X(12), 7,0x6b901122L); HOST_c2l(data,l); X(14)=l;
215 R0(D,A,B,C,X(13),12,0xfd987193L); HOST_c2l(data,l); X(15)=l;
216 R0(C,D,A,B,X(14),17,0xa679438eL);
217 R0(B,C,D,A,X(15),22,0x49b40821L);
218 /* Round 1 */
219 R1(A,B,C,D,X( 1), 5,0xf61e2562L);
220 R1(D,A,B,C,X( 6), 9,0xc040b340L);
221 R1(C,D,A,B,X(11),14,0x265e5a51L);
222 R1(B,C,D,A,X( 0),20,0xe9b6c7aaL);
223 R1(A,B,C,D,X( 5), 5,0xd62f105dL);
224 R1(D,A,B,C,X(10), 9,0x02441453L);
225 R1(C,D,A,B,X(15),14,0xd8a1e681L);
226 R1(B,C,D,A,X( 4),20,0xe7d3fbc8L);
227 R1(A,B,C,D,X( 9), 5,0x21e1cde6L);
228 R1(D,A,B,C,X(14), 9,0xc33707d6L);
229 R1(C,D,A,B,X( 3),14,0xf4d50d87L);
230 R1(B,C,D,A,X( 8),20,0x455a14edL);
231 R1(A,B,C,D,X(13), 5,0xa9e3e905L);
232 R1(D,A,B,C,X( 2), 9,0xfcefa3f8L);
233 R1(C,D,A,B,X( 7),14,0x676f02d9L);
234 R1(B,C,D,A,X(12),20,0x8d2a4c8aL);
235 /* Round 2 */
236 R2(A,B,C,D,X( 5), 4,0xfffa3942L);
237 R2(D,A,B,C,X( 8),11,0x8771f681L);
238 R2(C,D,A,B,X(11),16,0x6d9d6122L);
239 R2(B,C,D,A,X(14),23,0xfde5380cL);
240 R2(A,B,C,D,X( 1), 4,0xa4beea44L);
241 R2(D,A,B,C,X( 4),11,0x4bdecfa9L);
242 R2(C,D,A,B,X( 7),16,0xf6bb4b60L);
243 R2(B,C,D,A,X(10),23,0xbebfbc70L);
244 R2(A,B,C,D,X(13), 4,0x289b7ec6L);
245 R2(D,A,B,C,X( 0),11,0xeaa127faL);
246 R2(C,D,A,B,X( 3),16,0xd4ef3085L);
247 R2(B,C,D,A,X( 6),23,0x04881d05L);
248 R2(A,B,C,D,X( 9), 4,0xd9d4d039L);
249 R2(D,A,B,C,X(12),11,0xe6db99e5L);
250 R2(C,D,A,B,X(15),16,0x1fa27cf8L);
251 R2(B,C,D,A,X( 2),23,0xc4ac5665L);
252 /* Round 3 */
253 R3(A,B,C,D,X( 0), 6,0xf4292244L);
254 R3(D,A,B,C,X( 7),10,0x432aff97L);
255 R3(C,D,A,B,X(14),15,0xab9423a7L);
256 R3(B,C,D,A,X( 5),21,0xfc93a039L);
257 R3(A,B,C,D,X(12), 6,0x655b59c3L);
258 R3(D,A,B,C,X( 3),10,0x8f0ccc92L);
259 R3(C,D,A,B,X(10),15,0xffeff47dL);
260 R3(B,C,D,A,X( 1),21,0x85845dd1L);
261 R3(A,B,C,D,X( 8), 6,0x6fa87e4fL);
262 R3(D,A,B,C,X(15),10,0xfe2ce6e0L);
263 R3(C,D,A,B,X( 6),15,0xa3014314L);
264 R3(B,C,D,A,X(13),21,0x4e0811a1L);
265 R3(A,B,C,D,X( 4), 6,0xf7537e82L);
266 R3(D,A,B,C,X(11),10,0xbd3af235L);
267 R3(C,D,A,B,X( 2),15,0x2ad7d2bbL);
268 R3(B,C,D,A,X( 9),21,0xeb86d391L);
269
270 A = c->A += A;
271 B = c->B += B;
272 C = c->C += C;
273 D = c->D += D;
274 }
275 }
276#endif
277
278#ifdef undef
279int printit(unsigned long *l)
280 {
281 int i,ii;
282
283 for (i=0; i<2; i++)
284 {
285 for (ii=0; ii<8; ii++)
286 {
287 fprintf(stderr,"%08lx ",l[i*8+ii]);
288 }
289 fprintf(stderr,"\n");
290 }
291 }
292#endif
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h
deleted file mode 100644
index 9e360da732..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/e_os2.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(__i386__) || defined(_M_IX86) || defined(__INTEL__)
70# define md5_block_host_order md5_block_asm_host_order
71# elif defined(__sparc) && defined(OPENSSL_SYS_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(__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 44c6c455d1..0000000000
--- a/src/lib/libcrypto/md5/md5_one.c
+++ /dev/null
@@ -1,97 +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#include <openssl/crypto.h>
63
64#ifdef CHARSET_EBCDIC
65#include <openssl/ebcdic.h>
66#endif
67
68unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md)
69 {
70 MD5_CTX c;
71 static unsigned char m[MD5_DIGEST_LENGTH];
72
73 if (md == NULL) md=m;
74 if (!MD5_Init(&c))
75 return NULL;
76#ifndef CHARSET_EBCDIC
77 MD5_Update(&c,d,n);
78#else
79 {
80 char temp[1024];
81 unsigned long chunk;
82
83 while (n > 0)
84 {
85 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
86 ebcdic2ascii(temp, d, chunk);
87 MD5_Update(&c,temp,chunk);
88 n -= chunk;
89 d += chunk;
90 }
91 }
92#endif
93 MD5_Final(md,&c);
94 OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
95 return(md);
96 }
97
diff --git a/src/lib/libcrypto/mem_clr.c b/src/lib/libcrypto/mem_clr.c
deleted file mode 100644
index e4b7f540b0..0000000000
--- a/src/lib/libcrypto/mem_clr.c
+++ /dev/null
@@ -1,75 +0,0 @@
1/* crypto/mem_clr.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2002.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/crypto.h>
61
62unsigned char cleanse_ctr = 0;
63
64void OPENSSL_cleanse(void *ptr, size_t len)
65 {
66 unsigned char *p = ptr;
67 size_t loop = len;
68 while(loop--)
69 {
70 *(p++) = cleanse_ctr;
71 cleanse_ctr += (17 + (unsigned char)((int)p & 0xF));
72 }
73 if(memchr(ptr, cleanse_ctr, len))
74 cleanse_ctr += 63;
75 }
diff --git a/src/lib/libcrypto/mem_dbg.c b/src/lib/libcrypto/mem_dbg.c
deleted file mode 100644
index e212de27e4..0000000000
--- a/src/lib/libcrypto/mem_dbg.c
+++ /dev/null
@@ -1,787 +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 * access requires MALLOC2 lock */
86
87
88typedef struct app_mem_info_st
89/* For application-defined information (static C-string `info')
90 * to be displayed in memory leak list.
91 * Each thread has its own stack. For applications, there is
92 * CRYPTO_push_info("...") to push an entry,
93 * CRYPTO_pop_info() to pop an entry,
94 * CRYPTO_remove_all_info() to pop all entries.
95 */
96 {
97 unsigned long thread;
98 const char *file;
99 int line;
100 const char *info;
101 struct app_mem_info_st *next; /* tail of thread's stack */
102 int references;
103 } APP_INFO;
104
105static void app_info_free(APP_INFO *);
106
107static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's
108 * that are at the top of their thread's stack
109 * (with `thread' as key);
110 * access requires MALLOC2 lock */
111
112typedef struct mem_st
113/* memory-block description */
114 {
115 void *addr;
116 int num;
117 const char *file;
118 int line;
119 unsigned long thread;
120 unsigned long order;
121 time_t time;
122 APP_INFO *app_info;
123 } MEM;
124
125static long options = /* extra information to be recorded */
126#if defined(CRYPTO_MDEBUG_TIME) || defined(CRYPTO_MDEBUG_ALL)
127 V_CRYPTO_MDEBUG_TIME |
128#endif
129#if defined(CRYPTO_MDEBUG_THREAD) || defined(CRYPTO_MDEBUG_ALL)
130 V_CRYPTO_MDEBUG_THREAD |
131#endif
132 0;
133
134
135static unsigned int num_disable = 0; /* num_disable > 0
136 * iff
137 * mh_mode == CRYPTO_MEM_CHECK_ON (w/o ..._ENABLE)
138 */
139static unsigned long disabling_thread = 0; /* Valid iff num_disable > 0.
140 * CRYPTO_LOCK_MALLOC2 is locked
141 * exactly in this case (by the
142 * thread named in disabling_thread).
143 */
144
145static void app_info_free(APP_INFO *inf)
146 {
147 if (--(inf->references) <= 0)
148 {
149 if (inf->next != NULL)
150 {
151 app_info_free(inf->next);
152 }
153 OPENSSL_free(inf);
154 }
155 }
156
157int CRYPTO_mem_ctrl(int mode)
158 {
159 int ret=mh_mode;
160
161 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
162 switch (mode)
163 {
164 /* for applications (not to be called while multiple threads
165 * use the library): */
166 case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */
167 mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE;
168 num_disable = 0;
169 break;
170 case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
171 mh_mode = 0;
172 num_disable = 0; /* should be true *before* MemCheck_stop is used,
173 or there'll be a lot of confusion */
174 break;
175
176 /* switch off temporarily (for library-internal use): */
177 case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
178 if (mh_mode & CRYPTO_MEM_CHECK_ON)
179 {
180 if (!num_disable || (disabling_thread != CRYPTO_thread_id())) /* otherwise we already have the MALLOC2 lock */
181 {
182 /* Long-time lock CRYPTO_LOCK_MALLOC2 must not be claimed while
183 * we're holding CRYPTO_LOCK_MALLOC, or we'll deadlock if
184 * somebody else holds CRYPTO_LOCK_MALLOC2 (and cannot release
185 * it because we block entry to this function).
186 * Give them a chance, first, and then claim the locks in
187 * appropriate order (long-time lock first).
188 */
189 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
190 /* Note that after we have waited for CRYPTO_LOCK_MALLOC2
191 * and CRYPTO_LOCK_MALLOC, we'll still be in the right
192 * "case" and "if" branch because MemCheck_start and
193 * MemCheck_stop may never be used while there are multiple
194 * OpenSSL threads. */
195 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
196 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
197 mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;
198 disabling_thread=CRYPTO_thread_id();
199 }
200 num_disable++;
201 }
202 break;
203 case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
204 if (mh_mode & CRYPTO_MEM_CHECK_ON)
205 {
206 if (num_disable) /* always true, or something is going wrong */
207 {
208 num_disable--;
209 if (num_disable == 0)
210 {
211 mh_mode|=CRYPTO_MEM_CHECK_ENABLE;
212 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
213 }
214 }
215 }
216 break;
217
218 default:
219 break;
220 }
221 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
222 return(ret);
223 }
224
225int CRYPTO_is_mem_check_on(void)
226 {
227 int ret = 0;
228
229 if (mh_mode & CRYPTO_MEM_CHECK_ON)
230 {
231 CRYPTO_r_lock(CRYPTO_LOCK_MALLOC);
232
233 ret = (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
234 || (disabling_thread != CRYPTO_thread_id());
235
236 CRYPTO_r_unlock(CRYPTO_LOCK_MALLOC);
237 }
238 return(ret);
239 }
240
241
242void CRYPTO_dbg_set_options(long bits)
243 {
244 options = bits;
245 }
246
247long CRYPTO_dbg_get_options(void)
248 {
249 return options;
250 }
251
252/* static int mem_cmp(MEM *a, MEM *b) */
253static int mem_cmp(const void *a_void, const void *b_void)
254 {
255 return((const char *)((const MEM *)a_void)->addr
256 - (const char *)((const MEM *)b_void)->addr);
257 }
258
259/* static unsigned long mem_hash(MEM *a) */
260static unsigned long mem_hash(const void *a_void)
261 {
262 unsigned long ret;
263
264 ret=(unsigned long)((const MEM *)a_void)->addr;
265
266 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
267 return(ret);
268 }
269
270/* static int app_info_cmp(APP_INFO *a, APP_INFO *b) */
271static int app_info_cmp(const void *a_void, const void *b_void)
272 {
273 return(((const APP_INFO *)a_void)->thread
274 != ((const APP_INFO *)b_void)->thread);
275 }
276
277/* static unsigned long app_info_hash(APP_INFO *a) */
278static unsigned long app_info_hash(const void *a_void)
279 {
280 unsigned long ret;
281
282 ret=(unsigned long)((const APP_INFO *)a_void)->thread;
283
284 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
285 return(ret);
286 }
287
288static APP_INFO *pop_info(void)
289 {
290 APP_INFO tmp;
291 APP_INFO *ret = NULL;
292
293 if (amih != NULL)
294 {
295 tmp.thread=CRYPTO_thread_id();
296 if ((ret=(APP_INFO *)lh_delete(amih,&tmp)) != NULL)
297 {
298 APP_INFO *next=ret->next;
299
300 if (next != NULL)
301 {
302 next->references++;
303 lh_insert(amih,(char *)next);
304 }
305#ifdef LEVITTE_DEBUG_MEM
306 if (ret->thread != tmp.thread)
307 {
308 fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
309 ret->thread, tmp.thread);
310 abort();
311 }
312#endif
313 if (--(ret->references) <= 0)
314 {
315 ret->next = NULL;
316 if (next != NULL)
317 next->references--;
318 OPENSSL_free(ret);
319 }
320 }
321 }
322 return(ret);
323 }
324
325int CRYPTO_push_info_(const char *info, const char *file, int line)
326 {
327 APP_INFO *ami, *amim;
328 int ret=0;
329
330 if (is_MemCheck_on())
331 {
332 MemCheck_off(); /* obtain MALLOC2 lock */
333
334 if ((ami = (APP_INFO *)OPENSSL_malloc(sizeof(APP_INFO))) == NULL)
335 {
336 ret=0;
337 goto err;
338 }
339 if (amih == NULL)
340 {
341 if ((amih=lh_new(app_info_hash, app_info_cmp)) == NULL)
342 {
343 OPENSSL_free(ami);
344 ret=0;
345 goto err;
346 }
347 }
348
349 ami->thread=CRYPTO_thread_id();
350 ami->file=file;
351 ami->line=line;
352 ami->info=info;
353 ami->references=1;
354 ami->next=NULL;
355
356 if ((amim=(APP_INFO *)lh_insert(amih,(char *)ami)) != NULL)
357 {
358#ifdef LEVITTE_DEBUG_MEM
359 if (ami->thread != amim->thread)
360 {
361 fprintf(stderr, "CRYPTO_push_info(): previous info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
362 amim->thread, ami->thread);
363 abort();
364 }
365#endif
366 ami->next=amim;
367 }
368 err:
369 MemCheck_on(); /* release MALLOC2 lock */
370 }
371
372 return(ret);
373 }
374
375int CRYPTO_pop_info(void)
376 {
377 int ret=0;
378
379 if (is_MemCheck_on()) /* _must_ be true, or something went severely wrong */
380 {
381 MemCheck_off(); /* obtain MALLOC2 lock */
382
383 ret=(pop_info() != NULL);
384
385 MemCheck_on(); /* release MALLOC2 lock */
386 }
387 return(ret);
388 }
389
390int CRYPTO_remove_all_info(void)
391 {
392 int ret=0;
393
394 if (is_MemCheck_on()) /* _must_ be true */
395 {
396 MemCheck_off(); /* obtain MALLOC2 lock */
397
398 while(pop_info() != NULL)
399 ret++;
400
401 MemCheck_on(); /* release MALLOC2 lock */
402 }
403 return(ret);
404 }
405
406
407static unsigned long break_order_num=0;
408void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
409 int before_p)
410 {
411 MEM *m,*mm;
412 APP_INFO tmp,*amim;
413
414 switch(before_p & 127)
415 {
416 case 0:
417 break;
418 case 1:
419 if (addr == NULL)
420 break;
421
422 if (is_MemCheck_on())
423 {
424 MemCheck_off(); /* make sure we hold MALLOC2 lock */
425 if ((m=(MEM *)OPENSSL_malloc(sizeof(MEM))) == NULL)
426 {
427 OPENSSL_free(addr);
428 MemCheck_on(); /* release MALLOC2 lock
429 * if num_disabled drops to 0 */
430 return;
431 }
432 if (mh == NULL)
433 {
434 if ((mh=lh_new(mem_hash, mem_cmp)) == NULL)
435 {
436 OPENSSL_free(addr);
437 OPENSSL_free(m);
438 addr=NULL;
439 goto err;
440 }
441 }
442
443 m->addr=addr;
444 m->file=file;
445 m->line=line;
446 m->num=num;
447 if (options & V_CRYPTO_MDEBUG_THREAD)
448 m->thread=CRYPTO_thread_id();
449 else
450 m->thread=0;
451
452 if (order == break_order_num)
453 {
454 /* BREAK HERE */
455 m->order=order;
456 }
457 m->order=order++;
458#ifdef LEVITTE_DEBUG_MEM
459 fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] %c 0x%p (%d)\n",
460 m->order,
461 (before_p & 128) ? '*' : '+',
462 m->addr, m->num);
463#endif
464 if (options & V_CRYPTO_MDEBUG_TIME)
465 m->time=time(NULL);
466 else
467 m->time=0;
468
469 tmp.thread=CRYPTO_thread_id();
470 m->app_info=NULL;
471 if (amih != NULL
472 && (amim=(APP_INFO *)lh_retrieve(amih,(char *)&tmp)) != NULL)
473 {
474 m->app_info = amim;
475 amim->references++;
476 }
477
478 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
479 {
480 /* Not good, but don't sweat it */
481 if (mm->app_info != NULL)
482 {
483 mm->app_info->references--;
484 }
485 OPENSSL_free(mm);
486 }
487 err:
488 MemCheck_on(); /* release MALLOC2 lock
489 * if num_disabled drops to 0 */
490 }
491 break;
492 }
493 return;
494 }
495
496void CRYPTO_dbg_free(void *addr, int before_p)
497 {
498 MEM m,*mp;
499
500 switch(before_p)
501 {
502 case 0:
503 if (addr == NULL)
504 break;
505
506 if (is_MemCheck_on() && (mh != NULL))
507 {
508 MemCheck_off(); /* make sure we hold MALLOC2 lock */
509
510 m.addr=addr;
511 mp=(MEM *)lh_delete(mh,(char *)&m);
512 if (mp != NULL)
513 {
514#ifdef LEVITTE_DEBUG_MEM
515 fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] - 0x%p (%d)\n",
516 mp->order, mp->addr, mp->num);
517#endif
518 if (mp->app_info != NULL)
519 app_info_free(mp->app_info);
520 OPENSSL_free(mp);
521 }
522
523 MemCheck_on(); /* release MALLOC2 lock
524 * if num_disabled drops to 0 */
525 }
526 break;
527 case 1:
528 break;
529 }
530 }
531
532void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,
533 const char *file, int line, int before_p)
534 {
535 MEM m,*mp;
536
537#ifdef LEVITTE_DEBUG_MEM
538 fprintf(stderr, "LEVITTE_DEBUG_MEM: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \"%s\", line = %d, before_p = %d)\n",
539 addr1, addr2, num, file, line, before_p);
540#endif
541
542 switch(before_p)
543 {
544 case 0:
545 break;
546 case 1:
547 if (addr2 == NULL)
548 break;
549
550 if (addr1 == NULL)
551 {
552 CRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);
553 break;
554 }
555
556 if (is_MemCheck_on())
557 {
558 MemCheck_off(); /* make sure we hold MALLOC2 lock */
559
560 m.addr=addr1;
561 mp=(MEM *)lh_delete(mh,(char *)&m);
562 if (mp != NULL)
563 {
564#ifdef LEVITTE_DEBUG_MEM
565 fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] * 0x%p (%d) -> 0x%p (%d)\n",
566 mp->order,
567 mp->addr, mp->num,
568 addr2, num);
569#endif
570 mp->addr=addr2;
571 mp->num=num;
572 lh_insert(mh,(char *)mp);
573 }
574
575 MemCheck_on(); /* release MALLOC2 lock
576 * if num_disabled drops to 0 */
577 }
578 break;
579 }
580 return;
581 }
582
583
584typedef struct mem_leak_st
585 {
586 BIO *bio;
587 int chunks;
588 long bytes;
589 } MEM_LEAK;
590
591static void print_leak(const MEM *m, MEM_LEAK *l)
592 {
593 char buf[1024];
594 char *bufp = buf;
595 APP_INFO *amip;
596 int ami_cnt;
597 struct tm *lcl = NULL;
598 unsigned long ti;
599
600#define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))
601
602 if(m->addr == (char *)l->bio)
603 return;
604
605 if (options & V_CRYPTO_MDEBUG_TIME)
606 {
607 lcl = localtime(&m->time);
608
609 BIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ",
610 lcl->tm_hour,lcl->tm_min,lcl->tm_sec);
611 bufp += strlen(bufp);
612 }
613
614 BIO_snprintf(bufp, BUF_REMAIN, "%5lu file=%s, line=%d, ",
615 m->order,m->file,m->line);
616 bufp += strlen(bufp);
617
618 if (options & V_CRYPTO_MDEBUG_THREAD)
619 {
620 BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ", m->thread);
621 bufp += strlen(bufp);
622 }
623
624 BIO_snprintf(bufp, BUF_REMAIN, "number=%d, address=%08lX\n",
625 m->num,(unsigned long)m->addr);
626 bufp += strlen(bufp);
627
628 BIO_puts(l->bio,buf);
629
630 l->chunks++;
631 l->bytes+=m->num;
632
633 amip=m->app_info;
634 ami_cnt=0;
635 if (!amip)
636 return;
637 ti=amip->thread;
638
639 do
640 {
641 int buf_len;
642 int info_len;
643
644 ami_cnt++;
645 memset(buf,'>',ami_cnt);
646 BIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt,
647 " thread=%lu, file=%s, line=%d, info=\"",
648 amip->thread, amip->file, amip->line);
649 buf_len=strlen(buf);
650 info_len=strlen(amip->info);
651 if (128 - buf_len - 3 < info_len)
652 {
653 memcpy(buf + buf_len, amip->info, 128 - buf_len - 3);
654 buf_len = 128 - 3;
655 }
656 else
657 {
658 BUF_strlcpy(buf + buf_len, amip->info,
659 sizeof buf - buf_len);
660 buf_len = strlen(buf);
661 }
662 BIO_snprintf(buf + buf_len, sizeof buf - buf_len, "\"\n");
663
664 BIO_puts(l->bio,buf);
665
666 amip = amip->next;
667 }
668 while(amip && amip->thread == ti);
669
670#ifdef LEVITTE_DEBUG_MEM
671 if (amip)
672 {
673 fprintf(stderr, "Thread switch detected in backtrace!!!!\n");
674 abort();
675 }
676#endif
677 }
678
679static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM *, MEM_LEAK *)
680
681void CRYPTO_mem_leaks(BIO *b)
682 {
683 MEM_LEAK ml;
684
685 if (mh == NULL && amih == NULL)
686 return;
687
688 MemCheck_off(); /* obtain MALLOC2 lock */
689
690 ml.bio=b;
691 ml.bytes=0;
692 ml.chunks=0;
693 if (mh != NULL)
694 lh_doall_arg(mh, LHASH_DOALL_ARG_FN(print_leak),
695 (char *)&ml);
696 if (ml.chunks != 0)
697 {
698 BIO_printf(b,"%ld bytes leaked in %d chunks\n",
699 ml.bytes,ml.chunks);
700 }
701 else
702 {
703 /* Make sure that, if we found no leaks, memory-leak debugging itself
704 * does not introduce memory leaks (which might irritate
705 * external debugging tools).
706 * (When someone enables leak checking, but does not call
707 * this function, we declare it to be their fault.)
708 *
709 * XXX This should be in CRYPTO_mem_leaks_cb,
710 * and CRYPTO_mem_leaks should be implemented by
711 * using CRYPTO_mem_leaks_cb.
712 * (Also their should be a variant of lh_doall_arg
713 * that takes a function pointer instead of a void *;
714 * this would obviate the ugly and illegal
715 * void_fn_to_char kludge in CRYPTO_mem_leaks_cb.
716 * Otherwise the code police will come and get us.)
717 */
718 int old_mh_mode;
719
720 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
721
722 /* avoid deadlock when lh_free() uses CRYPTO_dbg_free(),
723 * which uses CRYPTO_is_mem_check_on */
724 old_mh_mode = mh_mode;
725 mh_mode = CRYPTO_MEM_CHECK_OFF;
726
727 if (mh != NULL)
728 {
729 lh_free(mh);
730 mh = NULL;
731 }
732 if (amih != NULL)
733 {
734 if (lh_num_items(amih) == 0)
735 {
736 lh_free(amih);
737 amih = NULL;
738 }
739 }
740
741 mh_mode = old_mh_mode;
742 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
743 }
744 MemCheck_on(); /* release MALLOC2 lock */
745 }
746
747#ifndef OPENSSL_NO_FP_API
748void CRYPTO_mem_leaks_fp(FILE *fp)
749 {
750 BIO *b;
751
752 if (mh == NULL) return;
753 /* Need to turn off memory checking when allocated BIOs ... especially
754 * as we're creating them at a time when we're trying to check we've not
755 * left anything un-free()'d!! */
756 MemCheck_off();
757 b = BIO_new(BIO_s_file());
758 MemCheck_on();
759 if(!b) return;
760 BIO_set_fp(b,fp,BIO_NOCLOSE);
761 CRYPTO_mem_leaks(b);
762 BIO_free(b);
763 }
764#endif
765
766
767
768/* FIXME: We really don't allow much to the callback. For example, it has
769 no chance of reaching the info stack for the item it processes. Should
770 it really be this way? -- Richard Levitte */
771/* NB: The prototypes have been typedef'd to CRYPTO_MEM_LEAK_CB inside crypto.h
772 * If this code is restructured, remove the callback type if it is no longer
773 * needed. -- Geoff Thorpe */
774static void cb_leak(const MEM *m, CRYPTO_MEM_LEAK_CB **cb)
775 {
776 (**cb)(m->order,m->file,m->line,m->num,m->addr);
777 }
778
779static IMPLEMENT_LHASH_DOALL_ARG_FN(cb_leak, const MEM *, CRYPTO_MEM_LEAK_CB **)
780
781void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb)
782 {
783 if (mh == NULL) return;
784 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
785 lh_doall_arg(mh, LHASH_DOALL_ARG_FN(cb_leak), &cb);
786 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
787 }
diff --git a/src/lib/libcrypto/o_str.c b/src/lib/libcrypto/o_str.c
deleted file mode 100644
index da8860491d..0000000000
--- a/src/lib/libcrypto/o_str.c
+++ /dev/null
@@ -1,96 +0,0 @@
1/* crypto/o_str.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <ctype.h>
60#include <e_os.h>
61#include "o_str.h"
62
63int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n)
64 {
65#if defined(OPENSSL_IMPLEMENTS_strncasecmp)
66 while (*str1 && *str2 && n)
67 {
68 int res = toupper(*str1) - toupper(*str2);
69 if (res) return res < 0 ? -1 : 1;
70 str1++;
71 str2++;
72 n--;
73 }
74 if (n == 0)
75 return 0;
76 if (*str1)
77 return 1;
78 if (*str2)
79 return -1;
80 return 0;
81#else
82 /* Recursion hazard warning! Whenever strncasecmp is #defined as
83 * OPENSSL_strncasecmp, OPENSSL_IMPLEMENTS_strncasecmp must be
84 * defined as well. */
85 return strncasecmp(str1, str2, n);
86#endif
87 }
88int OPENSSL_strcasecmp(const char *str1, const char *str2)
89 {
90#if defined(OPENSSL_IMPLEMENTS_strncasecmp)
91 return OPENSSL_strncasecmp(str1, str2, (size_t)-1);
92#else
93 return strcasecmp(str1, str2);
94#endif
95 }
96
diff --git a/src/lib/libcrypto/o_time.c b/src/lib/libcrypto/o_time.c
deleted file mode 100644
index e29091d650..0000000000
--- a/src/lib/libcrypto/o_time.c
+++ /dev/null
@@ -1,217 +0,0 @@
1/* crypto/o_time.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/e_os2.h>
60#include <string.h>
61#include "o_time.h"
62
63#ifdef OPENSSL_SYS_VMS
64# include <libdtdef.h>
65# include <lib$routines.h>
66# include <lnmdef.h>
67# include <starlet.h>
68# include <descrip.h>
69# include <stdlib.h>
70#endif
71
72struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
73 {
74 struct tm *ts = NULL;
75
76#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_OS2) && !defined(__CYGWIN32__) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_SUNOS)
77 /* should return &data, but doesn't on some systems,
78 so we don't even look at the return value */
79 gmtime_r(timer,result);
80 ts = result;
81#elif !defined(OPENSSL_SYS_VMS)
82 ts = gmtime(timer);
83 if (ts == NULL)
84 return NULL;
85
86 memcpy(result, ts, sizeof(struct tm));
87 ts = result;
88#endif
89#ifdef OPENSSL_SYS_VMS
90 if (ts == NULL)
91 {
92 static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL");
93 static $DESCRIPTOR(lognam,"SYS$TIMEZONE_DIFFERENTIAL");
94 char logvalue[256];
95 unsigned int reslen = 0;
96 struct {
97 short buflen;
98 short code;
99 void *bufaddr;
100 unsigned int *reslen;
101 } itemlist[] = {
102 { 0, LNM$_STRING, 0, 0 },
103 { 0, 0, 0, 0 },
104 };
105 int status;
106 time_t t;
107
108 /* Get the value for SYS$TIMEZONE_DIFFERENTIAL */
109 itemlist[0].buflen = sizeof(logvalue);
110 itemlist[0].bufaddr = logvalue;
111 itemlist[0].reslen = &reslen;
112 status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist);
113 if (!(status & 1))
114 return NULL;
115 logvalue[reslen] = '\0';
116
117 t = *timer;
118
119/* The following is extracted from the DEC C header time.h */
120/*
121** Beginning in OpenVMS Version 7.0 mktime, time, ctime, strftime
122** have two implementations. One implementation is provided
123** for compatibility and deals with time in terms of local time,
124** the other __utc_* deals with time in terms of UTC.
125*/
126/* We use the same conditions as in said time.h to check if we should
127 assume that t contains local time (and should therefore be adjusted)
128 or UTC (and should therefore be left untouched). */
129#if __CRTL_VER < 70000000 || defined _VMS_V6_SOURCE
130 /* Get the numerical value of the equivalence string */
131 status = atoi(logvalue);
132
133 /* and use it to move time to GMT */
134 t -= status;
135#endif
136
137 /* then convert the result to the time structure */
138
139 /* Since there was no gmtime_r() to do this stuff for us,
140 we have to do it the hard way. */
141 {
142 /* The VMS epoch is the astronomical Smithsonian date,
143 if I remember correctly, which is November 17, 1858.
144 Furthermore, time is measure in thenths of microseconds
145 and stored in quadwords (64 bit integers). unix_epoch
146 below is January 1st 1970 expressed as a VMS time. The
147 following code was used to get this number:
148
149 #include <stdio.h>
150 #include <stdlib.h>
151 #include <lib$routines.h>
152 #include <starlet.h>
153
154 main()
155 {
156 unsigned long systime[2];
157 unsigned short epoch_values[7] =
158 { 1970, 1, 1, 0, 0, 0, 0 };
159
160 lib$cvt_vectim(epoch_values, systime);
161
162 printf("%u %u", systime[0], systime[1]);
163 }
164 */
165 unsigned long unix_epoch[2] = { 1273708544, 8164711 };
166 unsigned long deltatime[2];
167 unsigned long systime[2];
168 struct vms_vectime
169 {
170 short year, month, day, hour, minute, second,
171 centi_second;
172 } time_values;
173 long operation;
174
175 /* Turn the number of seconds since January 1st 1970 to
176 an internal delta time.
177 Note that lib$cvt_to_internal_time() will assume
178 that t is signed, and will therefore break on 32-bit
179 systems some time in 2038.
180 */
181 operation = LIB$K_DELTA_SECONDS;
182 status = lib$cvt_to_internal_time(&operation,
183 &t, deltatime);
184
185 /* Add the delta time with the Unix epoch and we have
186 the current UTC time in internal format */
187 status = lib$add_times(unix_epoch, deltatime, systime);
188
189 /* Turn the internal time into a time vector */
190 status = sys$numtim(&time_values, systime);
191
192 /* Fill in the struct tm with the result */
193 result->tm_sec = time_values.second;
194 result->tm_min = time_values.minute;
195 result->tm_hour = time_values.hour;
196 result->tm_mday = time_values.day;
197 result->tm_mon = time_values.month - 1;
198 result->tm_year = time_values.year - 1900;
199
200 operation = LIB$K_DAY_OF_WEEK;
201 status = lib$cvt_from_internal_time(&operation,
202 &result->tm_wday, systime);
203 result->tm_wday %= 7;
204
205 operation = LIB$K_DAY_OF_YEAR;
206 status = lib$cvt_from_internal_time(&operation,
207 &result->tm_yday, systime);
208 result->tm_yday--;
209
210 result->tm_isdst = 0; /* There's no way to know... */
211
212 ts = result;
213 }
214 }
215#endif
216 return ts;
217 }
diff --git a/src/lib/libcrypto/o_time.h b/src/lib/libcrypto/o_time.h
deleted file mode 100644
index e66044626d..0000000000
--- a/src/lib/libcrypto/o_time.h
+++ /dev/null
@@ -1,66 +0,0 @@
1/* crypto/o_time.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_O_TIME_H
60#define HEADER_O_TIME_H
61
62#include <time.h>
63
64struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);
65
66#endif
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
deleted file mode 100644
index 28c9370ca3..0000000000
--- a/src/lib/libcrypto/objects/o_names.c
+++ /dev/null
@@ -1,369 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include <openssl/err.h>
6#include <openssl/lhash.h>
7#include <openssl/objects.h>
8#include <openssl/safestack.h>
9#include <openssl/e_os2.h>
10
11/* Later versions of DEC C has started to add lnkage information to certain
12 * functions, which makes it tricky to use them as values to regular function
13 * pointers. One way is to define a macro that takes care of casting them
14 * correctly.
15 */
16#ifdef OPENSSL_SYS_VMS_DECC
17# define OPENSSL_strcmp (int (*)(const char *,const char *))strcmp
18#else
19# define OPENSSL_strcmp strcmp
20#endif
21
22/* I use the ex_data stuff to manage the identifiers for the obj_name_types
23 * that applications may define. I only really use the free function field.
24 */
25static LHASH *names_lh=NULL;
26static int names_type_num=OBJ_NAME_TYPE_NUM;
27
28typedef struct name_funcs_st
29 {
30 unsigned long (*hash_func)(const char *name);
31 int (*cmp_func)(const char *a,const char *b);
32 void (*free_func)(const char *, int, const char *);
33 } NAME_FUNCS;
34
35DECLARE_STACK_OF(NAME_FUNCS)
36IMPLEMENT_STACK_OF(NAME_FUNCS)
37
38static STACK_OF(NAME_FUNCS) *name_funcs_stack;
39
40/* The LHASH callbacks now use the raw "void *" prototypes and do per-variable
41 * casting in the functions. This prevents function pointer casting without the
42 * need for macro-generated wrapper functions. */
43
44/* static unsigned long obj_name_hash(OBJ_NAME *a); */
45static unsigned long obj_name_hash(const void *a_void);
46/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */
47static int obj_name_cmp(const void *a_void,const void *b_void);
48
49int OBJ_NAME_init(void)
50 {
51 if (names_lh != NULL) return(1);
52 MemCheck_off();
53 names_lh=lh_new(obj_name_hash, obj_name_cmp);
54 MemCheck_on();
55 return(names_lh != NULL);
56 }
57
58int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
59 int (*cmp_func)(const char *, const char *),
60 void (*free_func)(const char *, int, const char *))
61 {
62 int ret;
63 int i;
64 NAME_FUNCS *name_funcs;
65
66 if (name_funcs_stack == NULL)
67 {
68 MemCheck_off();
69 name_funcs_stack=sk_NAME_FUNCS_new_null();
70 MemCheck_on();
71 }
72 if ((name_funcs_stack == NULL))
73 {
74 /* ERROR */
75 return(0);
76 }
77 ret=names_type_num;
78 names_type_num++;
79 for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++)
80 {
81 MemCheck_off();
82 name_funcs = OPENSSL_malloc(sizeof(NAME_FUNCS));
83 MemCheck_on();
84 if (!name_funcs)
85 {
86 OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX,ERR_R_MALLOC_FAILURE);
87 return(0);
88 }
89 name_funcs->hash_func = lh_strhash;
90 name_funcs->cmp_func = OPENSSL_strcmp;
91 name_funcs->free_func = 0; /* NULL is often declared to
92 * ((void *)0), which according
93 * to Compaq C is not really
94 * compatible with a function
95 * pointer. -- Richard Levitte*/
96 MemCheck_off();
97 sk_NAME_FUNCS_push(name_funcs_stack,name_funcs);
98 MemCheck_on();
99 }
100 name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
101 if (hash_func != NULL)
102 name_funcs->hash_func = hash_func;
103 if (cmp_func != NULL)
104 name_funcs->cmp_func = cmp_func;
105 if (free_func != NULL)
106 name_funcs->free_func = free_func;
107 return(ret);
108 }
109
110/* static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b) */
111static int obj_name_cmp(const void *a_void, const void *b_void)
112 {
113 int ret;
114 OBJ_NAME *a = (OBJ_NAME *)a_void;
115 OBJ_NAME *b = (OBJ_NAME *)b_void;
116
117 ret=a->type-b->type;
118 if (ret == 0)
119 {
120 if ((name_funcs_stack != NULL)
121 && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
122 {
123 ret=sk_NAME_FUNCS_value(name_funcs_stack,
124 a->type)->cmp_func(a->name,b->name);
125 }
126 else
127 ret=strcmp(a->name,b->name);
128 }
129 return(ret);
130 }
131
132/* static unsigned long obj_name_hash(OBJ_NAME *a) */
133static unsigned long obj_name_hash(const void *a_void)
134 {
135 unsigned long ret;
136 OBJ_NAME *a = (OBJ_NAME *)a_void;
137
138 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
139 {
140 ret=sk_NAME_FUNCS_value(name_funcs_stack,
141 a->type)->hash_func(a->name);
142 }
143 else
144 {
145 ret=lh_strhash(a->name);
146 }
147 ret^=a->type;
148 return(ret);
149 }
150
151const char *OBJ_NAME_get(const char *name, int type)
152 {
153 OBJ_NAME on,*ret;
154 int num=0,alias;
155
156 if (name == NULL) return(NULL);
157 if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL);
158
159 alias=type&OBJ_NAME_ALIAS;
160 type&= ~OBJ_NAME_ALIAS;
161
162 on.name=name;
163 on.type=type;
164
165 for (;;)
166 {
167 ret=(OBJ_NAME *)lh_retrieve(names_lh,&on);
168 if (ret == NULL) return(NULL);
169 if ((ret->alias) && !alias)
170 {
171 if (++num > 10) return(NULL);
172 on.name=ret->data;
173 }
174 else
175 {
176 return(ret->data);
177 }
178 }
179 }
180
181int OBJ_NAME_add(const char *name, int type, const char *data)
182 {
183 OBJ_NAME *onp,*ret;
184 int alias;
185
186 if ((names_lh == NULL) && !OBJ_NAME_init()) return(0);
187
188 alias=type&OBJ_NAME_ALIAS;
189 type&= ~OBJ_NAME_ALIAS;
190
191 onp=(OBJ_NAME *)OPENSSL_malloc(sizeof(OBJ_NAME));
192 if (onp == NULL)
193 {
194 /* ERROR */
195 return(0);
196 }
197
198 onp->name=name;
199 onp->alias=alias;
200 onp->type=type;
201 onp->data=data;
202
203 ret=(OBJ_NAME *)lh_insert(names_lh,onp);
204 if (ret != NULL)
205 {
206 /* free things */
207 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
208 {
209 /* XXX: I'm not sure I understand why the free
210 * function should get three arguments...
211 * -- Richard Levitte
212 */
213 sk_NAME_FUNCS_value(name_funcs_stack,
214 ret->type)->free_func(ret->name,ret->type,ret->data);
215 }
216 OPENSSL_free(ret);
217 }
218 else
219 {
220 if (lh_error(names_lh))
221 {
222 /* ERROR */
223 return(0);
224 }
225 }
226 return(1);
227 }
228
229int OBJ_NAME_remove(const char *name, int type)
230 {
231 OBJ_NAME on,*ret;
232
233 if (names_lh == NULL) return(0);
234
235 type&= ~OBJ_NAME_ALIAS;
236 on.name=name;
237 on.type=type;
238 ret=(OBJ_NAME *)lh_delete(names_lh,&on);
239 if (ret != NULL)
240 {
241 /* free things */
242 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
243 {
244 /* XXX: I'm not sure I understand why the free
245 * function should get three arguments...
246 * -- Richard Levitte
247 */
248 sk_NAME_FUNCS_value(name_funcs_stack,
249 ret->type)->free_func(ret->name,ret->type,ret->data);
250 }
251 OPENSSL_free(ret);
252 return(1);
253 }
254 else
255 return(0);
256 }
257
258struct doall
259 {
260 int type;
261 void (*fn)(const OBJ_NAME *,void *arg);
262 void *arg;
263 };
264
265static void do_all_fn(const OBJ_NAME *name,struct doall *d)
266 {
267 if(name->type == d->type)
268 d->fn(name,d->arg);
269 }
270
271static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME *, struct doall *)
272
273void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg)
274 {
275 struct doall d;
276
277 d.type=type;
278 d.fn=fn;
279 d.arg=arg;
280
281 lh_doall_arg(names_lh,LHASH_DOALL_ARG_FN(do_all_fn),&d);
282 }
283
284struct doall_sorted
285 {
286 int type;
287 int n;
288 const OBJ_NAME **names;
289 };
290
291static void do_all_sorted_fn(const OBJ_NAME *name,void *d_)
292 {
293 struct doall_sorted *d=d_;
294
295 if(name->type != d->type)
296 return;
297
298 d->names[d->n++]=name;
299 }
300
301static int do_all_sorted_cmp(const void *n1_,const void *n2_)
302 {
303 const OBJ_NAME * const *n1=n1_;
304 const OBJ_NAME * const *n2=n2_;
305
306 return strcmp((*n1)->name,(*n2)->name);
307 }
308
309void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
310 void *arg)
311 {
312 struct doall_sorted d;
313 int n;
314
315 d.type=type;
316 d.names=OPENSSL_malloc(lh_num_items(names_lh)*sizeof *d.names);
317 d.n=0;
318 OBJ_NAME_do_all(type,do_all_sorted_fn,&d);
319
320 qsort((void *)d.names,d.n,sizeof *d.names,do_all_sorted_cmp);
321
322 for(n=0 ; n < d.n ; ++n)
323 fn(d.names[n],arg);
324
325 OPENSSL_free((void *)d.names);
326 }
327
328static int free_type;
329
330static void names_lh_free(OBJ_NAME *onp)
331{
332 if(onp == NULL)
333 return;
334
335 if ((free_type < 0) || (free_type == onp->type))
336 {
337 OBJ_NAME_remove(onp->name,onp->type);
338 }
339 }
340
341static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME *)
342
343static void name_funcs_free(NAME_FUNCS *ptr)
344 {
345 OPENSSL_free(ptr);
346 }
347
348void OBJ_NAME_cleanup(int type)
349 {
350 unsigned long down_load;
351
352 if (names_lh == NULL) return;
353
354 free_type=type;
355 down_load=names_lh->down_load;
356 names_lh->down_load=0;
357
358 lh_doall(names_lh,LHASH_DOALL_FN(names_lh_free));
359 if (type < 0)
360 {
361 lh_free(names_lh);
362 sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free);
363 names_lh=NULL;
364 name_funcs_stack = NULL;
365 }
366 else
367 names_lh->down_load=down_load;
368 }
369
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
deleted file mode 100644
index f549d078ef..0000000000
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ /dev/null
@@ -1,668 +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 OPENSSL_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(const void *a, const void *b);
83static int ln_cmp(const void *a, const void *b);
84static int obj_cmp(const void *a, const void *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(const void *a, const void *b)
100 {
101 const ASN1_OBJECT * const *ap = a, * const *bp = b;
102 return(strcmp((*ap)->sn,(*bp)->sn));
103 }
104
105static int ln_cmp(const void *a, const void *b)
106 {
107 const ASN1_OBJECT * const *ap = a, * const *bp = b;
108 return(strcmp((*ap)->ln,(*bp)->ln));
109 }
110
111/* static unsigned long add_hash(ADDED_OBJ *ca) */
112static unsigned long add_hash(const void *ca_void)
113 {
114 const ASN1_OBJECT *a;
115 int i;
116 unsigned long ret=0;
117 unsigned char *p;
118 ADDED_OBJ *ca = (ADDED_OBJ *)ca_void;
119
120 a=ca->obj;
121 switch (ca->type)
122 {
123 case ADDED_DATA:
124 ret=a->length<<20L;
125 p=(unsigned char *)a->data;
126 for (i=0; i<a->length; i++)
127 ret^=p[i]<<((i*3)%24);
128 break;
129 case ADDED_SNAME:
130 ret=lh_strhash(a->sn);
131 break;
132 case ADDED_LNAME:
133 ret=lh_strhash(a->ln);
134 break;
135 case ADDED_NID:
136 ret=a->nid;
137 break;
138 default:
139 /* abort(); */
140 return 0;
141 }
142 ret&=0x3fffffffL;
143 ret|=ca->type<<30L;
144 return(ret);
145 }
146
147/* static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb) */
148static int add_cmp(const void *ca_void, const void *cb_void)
149 {
150 ASN1_OBJECT *a,*b;
151 int i;
152 ADDED_OBJ *ca = (ADDED_OBJ *)ca_void;
153 ADDED_OBJ *cb = (ADDED_OBJ *)cb_void;
154
155 i=ca->type-cb->type;
156 if (i) return(i);
157 a=ca->obj;
158 b=cb->obj;
159 switch (ca->type)
160 {
161 case ADDED_DATA:
162 i=(a->length - b->length);
163 if (i) return(i);
164 return(memcmp(a->data,b->data,a->length));
165 case ADDED_SNAME:
166 if (a->sn == NULL) return(-1);
167 else if (b->sn == NULL) return(1);
168 else return(strcmp(a->sn,b->sn));
169 case ADDED_LNAME:
170 if (a->ln == NULL) return(-1);
171 else if (b->ln == NULL) return(1);
172 else return(strcmp(a->ln,b->ln));
173 case ADDED_NID:
174 return(a->nid-b->nid);
175 default:
176 /* abort(); */
177 return 0;
178 }
179 }
180
181static int init_added(void)
182 {
183 if (added != NULL) return(1);
184 added=lh_new(add_hash,add_cmp);
185 return(added != NULL);
186 }
187
188static void cleanup1(ADDED_OBJ *a)
189 {
190 a->obj->nid=0;
191 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
192 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
193 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
194 }
195
196static void cleanup2(ADDED_OBJ *a)
197 { a->obj->nid++; }
198
199static void cleanup3(ADDED_OBJ *a)
200 {
201 if (--a->obj->nid == 0)
202 ASN1_OBJECT_free(a->obj);
203 OPENSSL_free(a);
204 }
205
206static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ *)
207static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ *)
208static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ *)
209
210void OBJ_cleanup(void)
211 {
212 if (added == NULL) return;
213 added->down_load=0;
214 lh_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */
215 lh_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */
216 lh_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */
217 lh_free(added);
218 added=NULL;
219 }
220
221int OBJ_new_nid(int num)
222 {
223 int i;
224
225 i=new_nid;
226 new_nid+=num;
227 return(i);
228 }
229
230int OBJ_add_object(const ASN1_OBJECT *obj)
231 {
232 ASN1_OBJECT *o;
233 ADDED_OBJ *ao[4]={NULL,NULL,NULL,NULL},*aop;
234 int i;
235
236 if (added == NULL)
237 if (!init_added()) return(0);
238 if ((o=OBJ_dup(obj)) == NULL) goto err;
239 if (!(ao[ADDED_NID]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2;
240 if ((o->length != 0) && (obj->data != NULL))
241 if (!(ao[ADDED_DATA]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2;
242 if (o->sn != NULL)
243 if (!(ao[ADDED_SNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2;
244 if (o->ln != NULL)
245 if (!(ao[ADDED_LNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2;
246
247 for (i=ADDED_DATA; i<=ADDED_NID; i++)
248 {
249 if (ao[i] != NULL)
250 {
251 ao[i]->type=i;
252 ao[i]->obj=o;
253 aop=(ADDED_OBJ *)lh_insert(added,ao[i]);
254 /* memory leak, buit should not normally matter */
255 if (aop != NULL)
256 OPENSSL_free(aop);
257 }
258 }
259 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
260 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
261
262 return(o->nid);
263err2:
264 OBJerr(OBJ_F_OBJ_ADD_OBJECT,ERR_R_MALLOC_FAILURE);
265err:
266 for (i=ADDED_DATA; i<=ADDED_NID; i++)
267 if (ao[i] != NULL) OPENSSL_free(ao[i]);
268 if (o != NULL) OPENSSL_free(o);
269 return(NID_undef);
270 }
271
272ASN1_OBJECT *OBJ_nid2obj(int n)
273 {
274 ADDED_OBJ ad,*adp;
275 ASN1_OBJECT ob;
276
277 if ((n >= 0) && (n < NUM_NID))
278 {
279 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
280 {
281 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
282 return(NULL);
283 }
284 return((ASN1_OBJECT *)&(nid_objs[n]));
285 }
286 else if (added == NULL)
287 return(NULL);
288 else
289 {
290 ad.type=ADDED_NID;
291 ad.obj= &ob;
292 ob.nid=n;
293 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
294 if (adp != NULL)
295 return(adp->obj);
296 else
297 {
298 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
299 return(NULL);
300 }
301 }
302 }
303
304const char *OBJ_nid2sn(int n)
305 {
306 ADDED_OBJ ad,*adp;
307 ASN1_OBJECT ob;
308
309 if ((n >= 0) && (n < NUM_NID))
310 {
311 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
312 {
313 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
314 return(NULL);
315 }
316 return(nid_objs[n].sn);
317 }
318 else if (added == NULL)
319 return(NULL);
320 else
321 {
322 ad.type=ADDED_NID;
323 ad.obj= &ob;
324 ob.nid=n;
325 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
326 if (adp != NULL)
327 return(adp->obj->sn);
328 else
329 {
330 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
331 return(NULL);
332 }
333 }
334 }
335
336const char *OBJ_nid2ln(int n)
337 {
338 ADDED_OBJ ad,*adp;
339 ASN1_OBJECT ob;
340
341 if ((n >= 0) && (n < NUM_NID))
342 {
343 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
344 {
345 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
346 return(NULL);
347 }
348 return(nid_objs[n].ln);
349 }
350 else if (added == NULL)
351 return(NULL);
352 else
353 {
354 ad.type=ADDED_NID;
355 ad.obj= &ob;
356 ob.nid=n;
357 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
358 if (adp != NULL)
359 return(adp->obj->ln);
360 else
361 {
362 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
363 return(NULL);
364 }
365 }
366 }
367
368int OBJ_obj2nid(const ASN1_OBJECT *a)
369 {
370 ASN1_OBJECT **op;
371 ADDED_OBJ ad,*adp;
372
373 if (a == NULL)
374 return(NID_undef);
375 if (a->nid != 0)
376 return(a->nid);
377
378 if (added != NULL)
379 {
380 ad.type=ADDED_DATA;
381 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */
382 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
383 if (adp != NULL) return (adp->obj->nid);
384 }
385 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,
386 sizeof(ASN1_OBJECT *),obj_cmp);
387 if (op == NULL)
388 return(NID_undef);
389 return((*op)->nid);
390 }
391
392/* Convert an object name into an ASN1_OBJECT
393 * if "noname" is not set then search for short and long names first.
394 * This will convert the "dotted" form into an object: unlike OBJ_txt2nid
395 * it can be used with any objects, not just registered ones.
396 */
397
398ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
399 {
400 int nid = NID_undef;
401 ASN1_OBJECT *op=NULL;
402 unsigned char *buf,*p;
403 int i, j;
404
405 if(!no_name) {
406 if( ((nid = OBJ_sn2nid(s)) != NID_undef) ||
407 ((nid = OBJ_ln2nid(s)) != NID_undef) )
408 return OBJ_nid2obj(nid);
409 }
410
411 /* Work out size of content octets */
412 i=a2d_ASN1_OBJECT(NULL,0,s,-1);
413 if (i <= 0) {
414 /* Clear the error */
415 ERR_get_error();
416 return NULL;
417 }
418 /* Work out total size */
419 j = ASN1_object_size(0,i,V_ASN1_OBJECT);
420
421 if((buf=(unsigned char *)OPENSSL_malloc(j)) == NULL) return NULL;
422
423 p = buf;
424 /* Write out tag+length */
425 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
426 /* Write out contents */
427 a2d_ASN1_OBJECT(p,i,s,-1);
428
429 p=buf;
430 op=d2i_ASN1_OBJECT(NULL,&p,j);
431 OPENSSL_free(buf);
432 return op;
433 }
434
435int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
436{
437 int i,idx=0,n=0,len,nid;
438 unsigned long l;
439 unsigned char *p;
440 const char *s;
441 char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
442
443 if (buf_len <= 0) return(0);
444
445 if ((a == NULL) || (a->data == NULL)) {
446 buf[0]='\0';
447 return(0);
448 }
449
450 if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {
451 len=a->length;
452 p=a->data;
453
454 idx=0;
455 l=0;
456 while (idx < a->length) {
457 l|=(p[idx]&0x7f);
458 if (!(p[idx] & 0x80)) break;
459 l<<=7L;
460 idx++;
461 }
462 idx++;
463 i=(int)(l/40);
464 if (i > 2) i=2;
465 l-=(long)(i*40);
466
467 BIO_snprintf(tbuf,sizeof tbuf,"%d.%lu",i,l);
468 i=strlen(tbuf);
469 BUF_strlcpy(buf,tbuf,buf_len);
470 buf_len-=i;
471 buf+=i;
472 n+=i;
473
474 l=0;
475 for (; idx<len; idx++) {
476 l|=p[idx]&0x7f;
477 if (!(p[idx] & 0x80)) {
478 BIO_snprintf(tbuf,sizeof tbuf,".%lu",l);
479 i=strlen(tbuf);
480 if (buf_len > 0)
481 BUF_strlcpy(buf,tbuf,buf_len);
482 buf_len-=i;
483 buf+=i;
484 n+=i;
485 l=0;
486 }
487 l<<=7L;
488 }
489 } else {
490 s=OBJ_nid2ln(nid);
491 if (s == NULL)
492 s=OBJ_nid2sn(nid);
493 BUF_strlcpy(buf,s,buf_len);
494 n=strlen(s);
495 }
496 return(n);
497}
498
499int OBJ_txt2nid(const char *s)
500{
501 ASN1_OBJECT *obj;
502 int nid;
503 obj = OBJ_txt2obj(s, 0);
504 nid = OBJ_obj2nid(obj);
505 ASN1_OBJECT_free(obj);
506 return nid;
507}
508
509int OBJ_ln2nid(const char *s)
510 {
511 ASN1_OBJECT o,*oo= &o,**op;
512 ADDED_OBJ ad,*adp;
513
514 o.ln=s;
515 if (added != NULL)
516 {
517 ad.type=ADDED_LNAME;
518 ad.obj= &o;
519 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
520 if (adp != NULL) return (adp->obj->nid);
521 }
522 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN,
523 sizeof(ASN1_OBJECT *),ln_cmp);
524 if (op == NULL) return(NID_undef);
525 return((*op)->nid);
526 }
527
528int OBJ_sn2nid(const char *s)
529 {
530 ASN1_OBJECT o,*oo= &o,**op;
531 ADDED_OBJ ad,*adp;
532
533 o.sn=s;
534 if (added != NULL)
535 {
536 ad.type=ADDED_SNAME;
537 ad.obj= &o;
538 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
539 if (adp != NULL) return (adp->obj->nid);
540 }
541 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
542 sizeof(ASN1_OBJECT *),sn_cmp);
543 if (op == NULL) return(NID_undef);
544 return((*op)->nid);
545 }
546
547static int obj_cmp(const void *ap, const void *bp)
548 {
549 int j;
550 ASN1_OBJECT *a= *(ASN1_OBJECT **)ap;
551 ASN1_OBJECT *b= *(ASN1_OBJECT **)bp;
552
553 j=(a->length - b->length);
554 if (j) return(j);
555 return(memcmp(a->data,b->data,a->length));
556 }
557
558const char *OBJ_bsearch(const char *key, const char *base, int num, int size,
559 int (*cmp)(const void *, const void *))
560 {
561 int l,h,i,c;
562 const char *p;
563
564 if (num == 0) return(NULL);
565 l=0;
566 h=num;
567 while (l < h)
568 {
569 i=(l+h)/2;
570 p= &(base[i*size]);
571 c=(*cmp)(key,p);
572 if (c < 0)
573 h=i;
574 else if (c > 0)
575 l=i+1;
576 else
577 return(p);
578 }
579#ifdef CHARSET_EBCDIC
580/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and
581 * I don't have perl (yet), we revert to a *LINEAR* search
582 * when the object wasn't found in the binary search.
583 */
584 for (i=0; i<num; ++i) {
585 p= &(base[i*size]);
586 if ((*cmp)(key,p) == 0)
587 return p;
588 }
589#endif
590 return(NULL);
591 }
592
593int OBJ_create_objects(BIO *in)
594 {
595 MS_STATIC char buf[512];
596 int i,num=0;
597 char *o,*s,*l=NULL;
598
599 for (;;)
600 {
601 s=o=NULL;
602 i=BIO_gets(in,buf,512);
603 if (i <= 0) return(num);
604 buf[i-1]='\0';
605 if (!isalnum((unsigned char)buf[0])) return(num);
606 o=s=buf;
607 while (isdigit((unsigned char)*s) || (*s == '.'))
608 s++;
609 if (*s != '\0')
610 {
611 *(s++)='\0';
612 while (isspace((unsigned char)*s))
613 s++;
614 if (*s == '\0')
615 s=NULL;
616 else
617 {
618 l=s;
619 while ((*l != '\0') && !isspace((unsigned char)*l))
620 l++;
621 if (*l != '\0')
622 {
623 *(l++)='\0';
624 while (isspace((unsigned char)*l))
625 l++;
626 if (*l == '\0') l=NULL;
627 }
628 else
629 l=NULL;
630 }
631 }
632 else
633 s=NULL;
634 if ((o == NULL) || (*o == '\0')) return(num);
635 if (!OBJ_create(o,s,l)) return(num);
636 num++;
637 }
638 /* return(num); */
639 }
640
641int OBJ_create(const char *oid, const char *sn, const char *ln)
642 {
643 int ok=0;
644 ASN1_OBJECT *op=NULL;
645 unsigned char *buf;
646 int i;
647
648 i=a2d_ASN1_OBJECT(NULL,0,oid,-1);
649 if (i <= 0) return(0);
650
651 if ((buf=(unsigned char *)OPENSSL_malloc(i)) == NULL)
652 {
653 OBJerr(OBJ_F_OBJ_CREATE,ERR_R_MALLOC_FAILURE);
654 return(0);
655 }
656 i=a2d_ASN1_OBJECT(buf,i,oid,-1);
657 if (i == 0)
658 goto err;
659 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
660 if (op == NULL)
661 goto err;
662 ok=OBJ_add_object(op);
663err:
664 ASN1_OBJECT_free(op);
665 OPENSSL_free(buf);
666 return(ok);
667 }
668
diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl
deleted file mode 100644
index d0371661f9..0000000000
--- a/src/lib/libcrypto/objects/obj_dat.pl
+++ /dev/null
@@ -1,307 +0,0 @@
1#!/usr/local/bin/perl
2
3# fixes bug in floating point emulation on sparc64 when
4# this script produces off-by-one output on sparc64
5use integer;
6
7sub obj_cmp
8 {
9 local(@a,@b,$_,$r);
10
11 $A=$obj_len{$obj{$nid{$a}}};
12 $B=$obj_len{$obj{$nid{$b}}};
13
14 $r=($A-$B);
15 return($r) if $r != 0;
16
17 $A=$obj_der{$obj{$nid{$a}}};
18 $B=$obj_der{$obj{$nid{$b}}};
19
20 return($A cmp $B);
21 }
22
23sub expand_obj
24 {
25 local(*v)=@_;
26 local($k,$d);
27 local($i);
28
29 do {
30 $i=0;
31 foreach $k (keys %v)
32 {
33 if (($v{$k} =~ s/(OBJ_[^,]+),/$v{$1},/))
34 { $i++; }
35 }
36 } while($i);
37 foreach $k (keys %v)
38 {
39 @a=split(/,/,$v{$k});
40 $objn{$k}=$#a+1;
41 }
42 return(%objn);
43 }
44
45open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
46open (OUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
47
48while (<IN>)
49 {
50 next unless /^\#define\s+(\S+)\s+(.*)$/;
51 $v=$1;
52 $d=$2;
53 $d =~ s/^\"//;
54 $d =~ s/\"$//;
55 if ($v =~ /^SN_(.*)$/)
56 {
57 if(defined $snames{$d})
58 {
59 print "WARNING: Duplicate short name \"$d\"\n";
60 }
61 else
62 { $snames{$d} = "X"; }
63 $sn{$1}=$d;
64 }
65 elsif ($v =~ /^LN_(.*)$/)
66 {
67 if(defined $lnames{$d})
68 {
69 print "WARNING: Duplicate long name \"$d\"\n";
70 }
71 else
72 { $lnames{$d} = "X"; }
73 $ln{$1}=$d;
74 }
75 elsif ($v =~ /^NID_(.*)$/)
76 { $nid{$d}=$1; }
77 elsif ($v =~ /^OBJ_(.*)$/)
78 {
79 $obj{$1}=$v;
80 $objd{$v}=$d;
81 }
82 }
83close IN;
84
85%ob=&expand_obj(*objd);
86
87@a=sort { $a <=> $b } keys %nid;
88$n=$a[$#a]+1;
89
90@lvalues=();
91$lvalues=0;
92
93for ($i=0; $i<$n; $i++)
94 {
95 if (!defined($nid{$i}))
96 {
97 push(@out,"{NULL,NULL,NID_undef,0,NULL},\n");
98 }
99 else
100 {
101 $sn=defined($sn{$nid{$i}})?"$sn{$nid{$i}}":"NULL";
102 $ln=defined($ln{$nid{$i}})?"$ln{$nid{$i}}":"NULL";
103
104 if ($sn eq "NULL") {
105 $sn=$ln;
106 $sn{$nid{$i}} = $ln;
107 }
108
109 if ($ln eq "NULL") {
110 $ln=$sn;
111 $ln{$nid{$i}} = $sn;
112 }
113
114 $out ="{";
115 $out.="\"$sn\"";
116 $out.=","."\"$ln\"";
117 $out.=",NID_$nid{$i},";
118 if (defined($obj{$nid{$i}}))
119 {
120 $v=$objd{$obj{$nid{$i}}};
121 $v =~ s/L//g;
122 $v =~ s/,/ /g;
123 $r=&der_it($v);
124 $z="";
125 $length=0;
126 foreach (unpack("C*",$r))
127 {
128 $z.=sprintf("0x%02X,",$_);
129 $length++;
130 }
131 $obj_der{$obj{$nid{$i}}}=$z;
132 $obj_len{$obj{$nid{$i}}}=$length;
133
134 push(@lvalues,sprintf("%-45s/* [%3d] %s */\n",
135 $z,$lvalues,$obj{$nid{$i}}));
136 $out.="$length,&(lvalues[$lvalues]),0";
137 $lvalues+=$length;
138 }
139 else
140 {
141 $out.="0,NULL";
142 }
143 $out.="},\n";
144 push(@out,$out);
145 }
146 }
147
148@a=grep(defined($sn{$nid{$_}}),0 .. $n);
149foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a)
150 {
151 push(@sn,sprintf("&(nid_objs[%2d]),/* \"$sn{$nid{$_}}\" */\n",$_));
152 }
153
154@a=grep(defined($ln{$nid{$_}}),0 .. $n);
155foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a)
156 {
157 push(@ln,sprintf("&(nid_objs[%2d]),/* \"$ln{$nid{$_}}\" */\n",$_));
158 }
159
160@a=grep(defined($obj{$nid{$_}}),0 .. $n);
161foreach (sort obj_cmp @a)
162 {
163 $m=$obj{$nid{$_}};
164 $v=$objd{$m};
165 $v =~ s/L//g;
166 $v =~ s/,/ /g;
167 push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v));
168 }
169
170print OUT <<'EOF';
171/* crypto/objects/obj_dat.h */
172
173/* THIS FILE IS GENERATED FROM objects.h by obj_dat.pl via the
174 * following command:
175 * perl obj_dat.pl obj_mac.h obj_dat.h
176 */
177
178/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
179 * All rights reserved.
180 *
181 * This package is an SSL implementation written
182 * by Eric Young (eay@cryptsoft.com).
183 * The implementation was written so as to conform with Netscapes SSL.
184 *
185 * This library is free for commercial and non-commercial use as long as
186 * the following conditions are aheared to. The following conditions
187 * apply to all code found in this distribution, be it the RC4, RSA,
188 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
189 * included with this distribution is covered by the same copyright terms
190 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
191 *
192 * Copyright remains Eric Young's, and as such any Copyright notices in
193 * the code are not to be removed.
194 * If this package is used in a product, Eric Young should be given attribution
195 * as the author of the parts of the library used.
196 * This can be in the form of a textual message at program startup or
197 * in documentation (online or textual) provided with the package.
198 *
199 * Redistribution and use in source and binary forms, with or without
200 * modification, are permitted provided that the following conditions
201 * are met:
202 * 1. Redistributions of source code must retain the copyright
203 * notice, this list of conditions and the following disclaimer.
204 * 2. Redistributions in binary form must reproduce the above copyright
205 * notice, this list of conditions and the following disclaimer in the
206 * documentation and/or other materials provided with the distribution.
207 * 3. All advertising materials mentioning features or use of this software
208 * must display the following acknowledgement:
209 * "This product includes cryptographic software written by
210 * Eric Young (eay@cryptsoft.com)"
211 * The word 'cryptographic' can be left out if the rouines from the library
212 * being used are not cryptographic related :-).
213 * 4. If you include any Windows specific code (or a derivative thereof) from
214 * the apps directory (application code) you must include an acknowledgement:
215 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
216 *
217 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
218 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
220 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
221 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
224 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
225 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
226 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
227 * SUCH DAMAGE.
228 *
229 * The licence and distribution terms for any publically available version or
230 * derivative of this code cannot be changed. i.e. this code cannot simply be
231 * copied and put under another distribution licence
232 * [including the GNU Public Licence.]
233 */
234
235EOF
236
237printf OUT "#define NUM_NID %d\n",$n;
238printf OUT "#define NUM_SN %d\n",$#sn+1;
239printf OUT "#define NUM_LN %d\n",$#ln+1;
240printf OUT "#define NUM_OBJ %d\n\n",$#ob+1;
241
242printf OUT "static unsigned char lvalues[%d]={\n",$lvalues+1;
243print OUT @lvalues;
244print OUT "};\n\n";
245
246printf OUT "static ASN1_OBJECT nid_objs[NUM_NID]={\n";
247foreach (@out)
248 {
249 if (length($_) > 75)
250 {
251 $out="";
252 foreach (split(/,/))
253 {
254 $t=$out.$_.",";
255 if (length($t) > 70)
256 {
257 print OUT "$out\n";
258 $t="\t$_,";
259 }
260 $out=$t;
261 }
262 chop $out;
263 print OUT "$out";
264 }
265 else
266 { print OUT $_; }
267 }
268print OUT "};\n\n";
269
270printf OUT "static ASN1_OBJECT *sn_objs[NUM_SN]={\n";
271print OUT @sn;
272print OUT "};\n\n";
273
274printf OUT "static ASN1_OBJECT *ln_objs[NUM_LN]={\n";
275print OUT @ln;
276print OUT "};\n\n";
277
278printf OUT "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n";
279print OUT @ob;
280print OUT "};\n\n";
281
282close OUT;
283
284sub der_it
285 {
286 local($v)=@_;
287 local(@a,$i,$ret,@r);
288
289 @a=split(/\s+/,$v);
290 $ret.=pack("C*",$a[0]*40+$a[1]);
291 shift @a;
292 shift @a;
293 foreach (@a)
294 {
295 @r=();
296 $t=0;
297 while ($_ >= 128)
298 {
299 $x=$_%128;
300 $_/=128;
301 push(@r,((($t++)?0x80:0)|$x));
302 }
303 push(@r,((($t++)?0x80:0)|$_));
304 $ret.=pack("C*",reverse(@r));
305 }
306 return($ret);
307 }
diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c
deleted file mode 100644
index 0682979b38..0000000000
--- a/src/lib/libcrypto/objects/obj_err.c
+++ /dev/null
@@ -1,105 +0,0 @@
1/* crypto/objects/obj_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_OBJ,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OBJ,0,reason)
70
71static ERR_STRING_DATA OBJ_str_functs[]=
72 {
73{ERR_FUNC(OBJ_F_OBJ_ADD_OBJECT), "OBJ_add_object"},
74{ERR_FUNC(OBJ_F_OBJ_CREATE), "OBJ_create"},
75{ERR_FUNC(OBJ_F_OBJ_DUP), "OBJ_dup"},
76{ERR_FUNC(OBJ_F_OBJ_NAME_NEW_INDEX), "OBJ_NAME_new_index"},
77{ERR_FUNC(OBJ_F_OBJ_NID2LN), "OBJ_nid2ln"},
78{ERR_FUNC(OBJ_F_OBJ_NID2OBJ), "OBJ_nid2obj"},
79{ERR_FUNC(OBJ_F_OBJ_NID2SN), "OBJ_nid2sn"},
80{0,NULL}
81 };
82
83static ERR_STRING_DATA OBJ_str_reasons[]=
84 {
85{ERR_REASON(OBJ_R_MALLOC_FAILURE) ,"malloc failure"},
86{ERR_REASON(OBJ_R_UNKNOWN_NID) ,"unknown nid"},
87{0,NULL}
88 };
89
90#endif
91
92void ERR_load_OBJ_strings(void)
93 {
94 static int init=1;
95
96 if (init)
97 {
98 init=0;
99#ifndef OPENSSL_NO_ERR
100 ERR_load_strings(0,OBJ_str_functs);
101 ERR_load_strings(0,OBJ_str_reasons);
102#endif
103
104 }
105 }
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
deleted file mode 100644
index b0b0f2ff24..0000000000
--- a/src/lib/libcrypto/objects/obj_lib.c
+++ /dev/null
@@ -1,127 +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(const 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((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of
74 duplication is this??? */
75
76 r=ASN1_OBJECT_new();
77 if (r == NULL)
78 {
79 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB);
80 return(NULL);
81 }
82 r->data=OPENSSL_malloc(o->length);
83 if (r->data == NULL)
84 goto err;
85 memcpy(r->data,o->data,o->length);
86 r->length=o->length;
87 r->nid=o->nid;
88 r->ln=r->sn=NULL;
89 if (o->ln != NULL)
90 {
91 i=strlen(o->ln)+1;
92 r->ln=ln=OPENSSL_malloc(i);
93 if (r->ln == NULL) goto err;
94 memcpy(ln,o->ln,i);
95 }
96
97 if (o->sn != NULL)
98 {
99 char *s;
100
101 i=strlen(o->sn)+1;
102 r->sn=s=OPENSSL_malloc(i);
103 if (r->sn == NULL) goto err;
104 memcpy(s,o->sn,i);
105 }
106 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
107 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
108 return(r);
109err:
110 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
111 if (r != NULL)
112 {
113 if (ln != NULL) OPENSSL_free(ln);
114 if (r->data != NULL) OPENSSL_free(r->data);
115 OPENSSL_free(r);
116 }
117 return(NULL);
118 }
119
120int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
121 {
122 int ret;
123
124 ret=(a->length-b->length);
125 if (ret) return(ret);
126 return(memcmp(a->data,b->data,a->length));
127 }
diff --git a/src/lib/libcrypto/objects/obj_mac.num b/src/lib/libcrypto/objects/obj_mac.num
deleted file mode 100644
index 84555d936e..0000000000
--- a/src/lib/libcrypto/objects/obj_mac.num
+++ /dev/null
@@ -1,675 +0,0 @@
1undef 0
2rsadsi 1
3pkcs 2
4md2 3
5md5 4
6rc4 5
7rsaEncryption 6
8md2WithRSAEncryption 7
9md5WithRSAEncryption 8
10pbeWithMD2AndDES_CBC 9
11pbeWithMD5AndDES_CBC 10
12X500 11
13X509 12
14commonName 13
15countryName 14
16localityName 15
17stateOrProvinceName 16
18organizationName 17
19organizationalUnitName 18
20rsa 19
21pkcs7 20
22pkcs7_data 21
23pkcs7_signed 22
24pkcs7_enveloped 23
25pkcs7_signedAndEnveloped 24
26pkcs7_digest 25
27pkcs7_encrypted 26
28pkcs3 27
29dhKeyAgreement 28
30des_ecb 29
31des_cfb64 30
32des_cbc 31
33des_ede_ecb 32
34des_ede3_ecb 33
35idea_cbc 34
36idea_cfb64 35
37idea_ecb 36
38rc2_cbc 37
39rc2_ecb 38
40rc2_cfb64 39
41rc2_ofb64 40
42sha 41
43shaWithRSAEncryption 42
44des_ede_cbc 43
45des_ede3_cbc 44
46des_ofb64 45
47idea_ofb64 46
48pkcs9 47
49pkcs9_emailAddress 48
50pkcs9_unstructuredName 49
51pkcs9_contentType 50
52pkcs9_messageDigest 51
53pkcs9_signingTime 52
54pkcs9_countersignature 53
55pkcs9_challengePassword 54
56pkcs9_unstructuredAddress 55
57pkcs9_extCertAttributes 56
58netscape 57
59netscape_cert_extension 58
60netscape_data_type 59
61des_ede_cfb64 60
62des_ede3_cfb64 61
63des_ede_ofb64 62
64des_ede3_ofb64 63
65sha1 64
66sha1WithRSAEncryption 65
67dsaWithSHA 66
68dsa_2 67
69pbeWithSHA1AndRC2_CBC 68
70id_pbkdf2 69
71dsaWithSHA1_2 70
72netscape_cert_type 71
73netscape_base_url 72
74netscape_revocation_url 73
75netscape_ca_revocation_url 74
76netscape_renewal_url 75
77netscape_ca_policy_url 76
78netscape_ssl_server_name 77
79netscape_comment 78
80netscape_cert_sequence 79
81desx_cbc 80
82id_ce 81
83subject_key_identifier 82
84key_usage 83
85private_key_usage_period 84
86subject_alt_name 85
87issuer_alt_name 86
88basic_constraints 87
89crl_number 88
90certificate_policies 89
91authority_key_identifier 90
92bf_cbc 91
93bf_ecb 92
94bf_cfb64 93
95bf_ofb64 94
96mdc2 95
97mdc2WithRSA 96
98rc4_40 97
99rc2_40_cbc 98
100givenName 99
101surname 100
102initials 101
103uniqueIdentifier 102
104crl_distribution_points 103
105md5WithRSA 104
106serialNumber 105
107title 106
108description 107
109cast5_cbc 108
110cast5_ecb 109
111cast5_cfb64 110
112cast5_ofb64 111
113pbeWithMD5AndCast5_CBC 112
114dsaWithSHA1 113
115md5_sha1 114
116sha1WithRSA 115
117dsa 116
118ripemd160 117
119ripemd160WithRSA 119
120rc5_cbc 120
121rc5_ecb 121
122rc5_cfb64 122
123rc5_ofb64 123
124rle_compression 124
125zlib_compression 125
126ext_key_usage 126
127id_pkix 127
128id_kp 128
129server_auth 129
130client_auth 130
131code_sign 131
132email_protect 132
133time_stamp 133
134ms_code_ind 134
135ms_code_com 135
136ms_ctl_sign 136
137ms_sgc 137
138ms_efs 138
139ns_sgc 139
140delta_crl 140
141crl_reason 141
142invalidity_date 142
143sxnet 143
144pbe_WithSHA1And128BitRC4 144
145pbe_WithSHA1And40BitRC4 145
146pbe_WithSHA1And3_Key_TripleDES_CBC 146
147pbe_WithSHA1And2_Key_TripleDES_CBC 147
148pbe_WithSHA1And128BitRC2_CBC 148
149pbe_WithSHA1And40BitRC2_CBC 149
150keyBag 150
151pkcs8ShroudedKeyBag 151
152certBag 152
153crlBag 153
154secretBag 154
155safeContentsBag 155
156friendlyName 156
157localKeyID 157
158x509Certificate 158
159sdsiCertificate 159
160x509Crl 160
161pbes2 161
162pbmac1 162
163hmacWithSHA1 163
164id_qt_cps 164
165id_qt_unotice 165
166rc2_64_cbc 166
167SMIMECapabilities 167
168pbeWithMD2AndRC2_CBC 168
169pbeWithMD5AndRC2_CBC 169
170pbeWithSHA1AndDES_CBC 170
171ms_ext_req 171
172ext_req 172
173name 173
174dnQualifier 174
175id_pe 175
176id_ad 176
177info_access 177
178ad_OCSP 178
179ad_ca_issuers 179
180OCSP_sign 180
181iso 181
182member_body 182
183ISO_US 183
184X9_57 184
185X9cm 185
186pkcs1 186
187pkcs5 187
188SMIME 188
189id_smime_mod 189
190id_smime_ct 190
191id_smime_aa 191
192id_smime_alg 192
193id_smime_cd 193
194id_smime_spq 194
195id_smime_cti 195
196id_smime_mod_cms 196
197id_smime_mod_ess 197
198id_smime_mod_oid 198
199id_smime_mod_msg_v3 199
200id_smime_mod_ets_eSignature_88 200
201id_smime_mod_ets_eSignature_97 201
202id_smime_mod_ets_eSigPolicy_88 202
203id_smime_mod_ets_eSigPolicy_97 203
204id_smime_ct_receipt 204
205id_smime_ct_authData 205
206id_smime_ct_publishCert 206
207id_smime_ct_TSTInfo 207
208id_smime_ct_TDTInfo 208
209id_smime_ct_contentInfo 209
210id_smime_ct_DVCSRequestData 210
211id_smime_ct_DVCSResponseData 211
212id_smime_aa_receiptRequest 212
213id_smime_aa_securityLabel 213
214id_smime_aa_mlExpandHistory 214
215id_smime_aa_contentHint 215
216id_smime_aa_msgSigDigest 216
217id_smime_aa_encapContentType 217
218id_smime_aa_contentIdentifier 218
219id_smime_aa_macValue 219
220id_smime_aa_equivalentLabels 220
221id_smime_aa_contentReference 221
222id_smime_aa_encrypKeyPref 222
223id_smime_aa_signingCertificate 223
224id_smime_aa_smimeEncryptCerts 224
225id_smime_aa_timeStampToken 225
226id_smime_aa_ets_sigPolicyId 226
227id_smime_aa_ets_commitmentType 227
228id_smime_aa_ets_signerLocation 228
229id_smime_aa_ets_signerAttr 229
230id_smime_aa_ets_otherSigCert 230
231id_smime_aa_ets_contentTimestamp 231
232id_smime_aa_ets_CertificateRefs 232
233id_smime_aa_ets_RevocationRefs 233
234id_smime_aa_ets_certValues 234
235id_smime_aa_ets_revocationValues 235
236id_smime_aa_ets_escTimeStamp 236
237id_smime_aa_ets_certCRLTimestamp 237
238id_smime_aa_ets_archiveTimeStamp 238
239id_smime_aa_signatureType 239
240id_smime_aa_dvcs_dvc 240
241id_smime_alg_ESDHwith3DES 241
242id_smime_alg_ESDHwithRC2 242
243id_smime_alg_3DESwrap 243
244id_smime_alg_RC2wrap 244
245id_smime_alg_ESDH 245
246id_smime_alg_CMS3DESwrap 246
247id_smime_alg_CMSRC2wrap 247
248id_smime_cd_ldap 248
249id_smime_spq_ets_sqt_uri 249
250id_smime_spq_ets_sqt_unotice 250
251id_smime_cti_ets_proofOfOrigin 251
252id_smime_cti_ets_proofOfReceipt 252
253id_smime_cti_ets_proofOfDelivery 253
254id_smime_cti_ets_proofOfSender 254
255id_smime_cti_ets_proofOfApproval 255
256id_smime_cti_ets_proofOfCreation 256
257md4 257
258id_pkix_mod 258
259id_qt 259
260id_it 260
261id_pkip 261
262id_alg 262
263id_cmc 263
264id_on 264
265id_pda 265
266id_aca 266
267id_qcs 267
268id_cct 268
269id_pkix1_explicit_88 269
270id_pkix1_implicit_88 270
271id_pkix1_explicit_93 271
272id_pkix1_implicit_93 272
273id_mod_crmf 273
274id_mod_cmc 274
275id_mod_kea_profile_88 275
276id_mod_kea_profile_93 276
277id_mod_cmp 277
278id_mod_qualified_cert_88 278
279id_mod_qualified_cert_93 279
280id_mod_attribute_cert 280
281id_mod_timestamp_protocol 281
282id_mod_ocsp 282
283id_mod_dvcs 283
284id_mod_cmp2000 284
285biometricInfo 285
286qcStatements 286
287ac_auditEntity 287
288ac_targeting 288
289aaControls 289
290sbgp_ipAddrBlock 290
291sbgp_autonomousSysNum 291
292sbgp_routerIdentifier 292
293textNotice 293
294ipsecEndSystem 294
295ipsecTunnel 295
296ipsecUser 296
297dvcs 297
298id_it_caProtEncCert 298
299id_it_signKeyPairTypes 299
300id_it_encKeyPairTypes 300
301id_it_preferredSymmAlg 301
302id_it_caKeyUpdateInfo 302
303id_it_currentCRL 303
304id_it_unsupportedOIDs 304
305id_it_subscriptionRequest 305
306id_it_subscriptionResponse 306
307id_it_keyPairParamReq 307
308id_it_keyPairParamRep 308
309id_it_revPassphrase 309
310id_it_implicitConfirm 310
311id_it_confirmWaitTime 311
312id_it_origPKIMessage 312
313id_regCtrl 313
314id_regInfo 314
315id_regCtrl_regToken 315
316id_regCtrl_authenticator 316
317id_regCtrl_pkiPublicationInfo 317
318id_regCtrl_pkiArchiveOptions 318
319id_regCtrl_oldCertID 319
320id_regCtrl_protocolEncrKey 320
321id_regInfo_utf8Pairs 321
322id_regInfo_certReq 322
323id_alg_des40 323
324id_alg_noSignature 324
325id_alg_dh_sig_hmac_sha1 325
326id_alg_dh_pop 326
327id_cmc_statusInfo 327
328id_cmc_identification 328
329id_cmc_identityProof 329
330id_cmc_dataReturn 330
331id_cmc_transactionId 331
332id_cmc_senderNonce 332
333id_cmc_recipientNonce 333
334id_cmc_addExtensions 334
335id_cmc_encryptedPOP 335
336id_cmc_decryptedPOP 336
337id_cmc_lraPOPWitness 337
338id_cmc_getCert 338
339id_cmc_getCRL 339
340id_cmc_revokeRequest 340
341id_cmc_regInfo 341
342id_cmc_responseInfo 342
343id_cmc_queryPending 343
344id_cmc_popLinkRandom 344
345id_cmc_popLinkWitness 345
346id_cmc_confirmCertAcceptance 346
347id_on_personalData 347
348id_pda_dateOfBirth 348
349id_pda_placeOfBirth 349
350id_pda_pseudonym 350
351id_pda_gender 351
352id_pda_countryOfCitizenship 352
353id_pda_countryOfResidence 353
354id_aca_authenticationInfo 354
355id_aca_accessIdentity 355
356id_aca_chargingIdentity 356
357id_aca_group 357
358id_aca_role 358
359id_qcs_pkixQCSyntax_v1 359
360id_cct_crs 360
361id_cct_PKIData 361
362id_cct_PKIResponse 362
363ad_timeStamping 363
364ad_dvcs 364
365id_pkix_OCSP_basic 365
366id_pkix_OCSP_Nonce 366
367id_pkix_OCSP_CrlID 367
368id_pkix_OCSP_acceptableResponses 368
369id_pkix_OCSP_noCheck 369
370id_pkix_OCSP_archiveCutoff 370
371id_pkix_OCSP_serviceLocator 371
372id_pkix_OCSP_extendedStatus 372
373id_pkix_OCSP_valid 373
374id_pkix_OCSP_path 374
375id_pkix_OCSP_trustRoot 375
376algorithm 376
377rsaSignature 377
378X500algorithms 378
379org 379
380dod 380
381iana 381
382Directory 382
383Management 383
384Experimental 384
385Private 385
386Security 386
387SNMPv2 387
388Mail 388
389Enterprises 389
390dcObject 390
391domainComponent 391
392Domain 392
393joint_iso_ccitt 393
394selected_attribute_types 394
395clearance 395
396md4WithRSAEncryption 396
397ac_proxying 397
398sinfo_access 398
399id_aca_encAttrs 399
400role 400
401policy_constraints 401
402target_information 402
403no_rev_avail 403
404ccitt 404
405ansi_X9_62 405
406X9_62_prime_field 406
407X9_62_characteristic_two_field 407
408X9_62_id_ecPublicKey 408
409X9_62_prime192v1 409
410X9_62_prime192v2 410
411X9_62_prime192v3 411
412X9_62_prime239v1 412
413X9_62_prime239v2 413
414X9_62_prime239v3 414
415X9_62_prime256v1 415
416ecdsa_with_SHA1 416
417ms_csp_name 417
418aes_128_ecb 418
419aes_128_cbc 419
420aes_128_ofb128 420
421aes_128_cfb128 421
422aes_192_ecb 422
423aes_192_cbc 423
424aes_192_ofb128 424
425aes_192_cfb128 425
426aes_256_ecb 426
427aes_256_cbc 427
428aes_256_ofb128 428
429aes_256_cfb128 429
430hold_instruction_code 430
431hold_instruction_none 431
432hold_instruction_call_issuer 432
433hold_instruction_reject 433
434data 434
435pss 435
436ucl 436
437pilot 437
438pilotAttributeType 438
439pilotAttributeSyntax 439
440pilotObjectClass 440
441pilotGroups 441
442iA5StringSyntax 442
443caseIgnoreIA5StringSyntax 443
444pilotObject 444
445pilotPerson 445
446account 446
447document 447
448room 448
449documentSeries 449
450rFC822localPart 450
451dNSDomain 451
452domainRelatedObject 452
453friendlyCountry 453
454simpleSecurityObject 454
455pilotOrganization 455
456pilotDSA 456
457qualityLabelledData 457
458userId 458
459textEncodedORAddress 459
460rfc822Mailbox 460
461info 461
462favouriteDrink 462
463roomNumber 463
464photo 464
465userClass 465
466host 466
467manager 467
468documentIdentifier 468
469documentTitle 469
470documentVersion 470
471documentAuthor 471
472documentLocation 472
473homeTelephoneNumber 473
474secretary 474
475otherMailbox 475
476lastModifiedTime 476
477lastModifiedBy 477
478aRecord 478
479pilotAttributeType27 479
480mXRecord 480
481nSRecord 481
482sOARecord 482
483cNAMERecord 483
484associatedDomain 484
485associatedName 485
486homePostalAddress 486
487personalTitle 487
488mobileTelephoneNumber 488
489pagerTelephoneNumber 489
490friendlyCountryName 490
491organizationalStatus 491
492janetMailbox 492
493mailPreferenceOption 493
494buildingName 494
495dSAQuality 495
496singleLevelQuality 496
497subtreeMinimumQuality 497
498subtreeMaximumQuality 498
499personalSignature 499
500dITRedirect 500
501audio 501
502documentPublisher 502
503x500UniqueIdentifier 503
504mime_mhs 504
505mime_mhs_headings 505
506mime_mhs_bodies 506
507id_hex_partial_message 507
508id_hex_multipart_message 508
509generationQualifier 509
510pseudonym 510
511InternationalRA 511
512id_set 512
513set_ctype 513
514set_msgExt 514
515set_attr 515
516set_policy 516
517set_certExt 517
518set_brand 518
519setct_PANData 519
520setct_PANToken 520
521setct_PANOnly 521
522setct_OIData 522
523setct_PI 523
524setct_PIData 524
525setct_PIDataUnsigned 525
526setct_HODInput 526
527setct_AuthResBaggage 527
528setct_AuthRevReqBaggage 528
529setct_AuthRevResBaggage 529
530setct_CapTokenSeq 530
531setct_PInitResData 531
532setct_PI_TBS 532
533setct_PResData 533
534setct_AuthReqTBS 534
535setct_AuthResTBS 535
536setct_AuthResTBSX 536
537setct_AuthTokenTBS 537
538setct_CapTokenData 538
539setct_CapTokenTBS 539
540setct_AcqCardCodeMsg 540
541setct_AuthRevReqTBS 541
542setct_AuthRevResData 542
543setct_AuthRevResTBS 543
544setct_CapReqTBS 544
545setct_CapReqTBSX 545
546setct_CapResData 546
547setct_CapRevReqTBS 547
548setct_CapRevReqTBSX 548
549setct_CapRevResData 549
550setct_CredReqTBS 550
551setct_CredReqTBSX 551
552setct_CredResData 552
553setct_CredRevReqTBS 553
554setct_CredRevReqTBSX 554
555setct_CredRevResData 555
556setct_PCertReqData 556
557setct_PCertResTBS 557
558setct_BatchAdminReqData 558
559setct_BatchAdminResData 559
560setct_CardCInitResTBS 560
561setct_MeAqCInitResTBS 561
562setct_RegFormResTBS 562
563setct_CertReqData 563
564setct_CertReqTBS 564
565setct_CertResData 565
566setct_CertInqReqTBS 566
567setct_ErrorTBS 567
568setct_PIDualSignedTBE 568
569setct_PIUnsignedTBE 569
570setct_AuthReqTBE 570
571setct_AuthResTBE 571
572setct_AuthResTBEX 572
573setct_AuthTokenTBE 573
574setct_CapTokenTBE 574
575setct_CapTokenTBEX 575
576setct_AcqCardCodeMsgTBE 576
577setct_AuthRevReqTBE 577
578setct_AuthRevResTBE 578
579setct_AuthRevResTBEB 579
580setct_CapReqTBE 580
581setct_CapReqTBEX 581
582setct_CapResTBE 582
583setct_CapRevReqTBE 583
584setct_CapRevReqTBEX 584
585setct_CapRevResTBE 585
586setct_CredReqTBE 586
587setct_CredReqTBEX 587
588setct_CredResTBE 588
589setct_CredRevReqTBE 589
590setct_CredRevReqTBEX 590
591setct_CredRevResTBE 591
592setct_BatchAdminReqTBE 592
593setct_BatchAdminResTBE 593
594setct_RegFormReqTBE 594
595setct_CertReqTBE 595
596setct_CertReqTBEX 596
597setct_CertResTBE 597
598setct_CRLNotificationTBS 598
599setct_CRLNotificationResTBS 599
600setct_BCIDistributionTBS 600
601setext_genCrypt 601
602setext_miAuth 602
603setext_pinSecure 603
604setext_pinAny 604
605setext_track2 605
606setext_cv 606
607set_policy_root 607
608setCext_hashedRoot 608
609setCext_certType 609
610setCext_merchData 610
611setCext_cCertRequired 611
612setCext_tunneling 612
613setCext_setExt 613
614setCext_setQualf 614
615setCext_PGWYcapabilities 615
616setCext_TokenIdentifier 616
617setCext_Track2Data 617
618setCext_TokenType 618
619setCext_IssuerCapabilities 619
620setAttr_Cert 620
621setAttr_PGWYcap 621
622setAttr_TokenType 622
623setAttr_IssCap 623
624set_rootKeyThumb 624
625set_addPolicy 625
626setAttr_Token_EMV 626
627setAttr_Token_B0Prime 627
628setAttr_IssCap_CVM 628
629setAttr_IssCap_T2 629
630setAttr_IssCap_Sig 630
631setAttr_GenCryptgrm 631
632setAttr_T2Enc 632
633setAttr_T2cleartxt 633
634setAttr_TokICCsig 634
635setAttr_SecDevSig 635
636set_brand_IATA_ATA 636
637set_brand_Diners 637
638set_brand_AmericanExpress 638
639set_brand_JCB 639
640set_brand_Visa 640
641set_brand_MasterCard 641
642set_brand_Novus 642
643des_cdmf 643
644rsaOAEPEncryptionSET 644
645itu_t 645
646joint_iso_itu_t 646
647international_organizations 647
648ms_smartcard_login 648
649ms_upn 649
650aes_128_cfb1 650
651aes_192_cfb1 651
652aes_256_cfb1 652
653aes_128_cfb8 653
654aes_192_cfb8 654
655aes_256_cfb8 655
656des_cfb1 656
657des_cfb8 657
658des_ede3_cfb1 658
659des_ede3_cfb8 659
660streetAddress 660
661postalCode 661
662id_ppl 662
663proxyCertInfo 663
664id_ppl_anyLanguage 664
665id_ppl_inheritAll 665
666name_constraints 666
667Independent 667
668sha256WithRSAEncryption 668
669sha384WithRSAEncryption 669
670sha512WithRSAEncryption 670
671sha224WithRSAEncryption 671
672sha256 672
673sha384 673
674sha512 674
675sha224 675
diff --git a/src/lib/libcrypto/objects/objects.README b/src/lib/libcrypto/objects/objects.README
deleted file mode 100644
index 4d745508d8..0000000000
--- a/src/lib/libcrypto/objects/objects.README
+++ /dev/null
@@ -1,44 +0,0 @@
1objects.txt syntax
2------------------
3
4To cover all the naming hacks that were previously in objects.h needed some
5kind of hacks in objects.txt.
6
7The basic syntax for adding an object is as follows:
8
9 1 2 3 4 : shortName : Long Name
10
11 If the long name doesn't contain spaces, or no short name
12 exists, the long name is used as basis for the base name
13 in C. Otherwise, the short name is used.
14
15 The base name (let's call it 'base') will then be used to
16 create the C macros SN_base, LN_base, NID_base and OBJ_base.
17
18 Note that if the base name contains spaces, dashes or periods,
19 those will be converte to underscore.
20
21Then there are some extra commands:
22
23 !Alias foo 1 2 3 4
24
25 This juts makes a name foo for an OID. The C macro
26 OBJ_foo will be created as a result.
27
28 !Cname foo
29
30 This makes sure that the name foo will be used as base name
31 in C.
32
33 !module foo
34 1 2 3 4 : shortName : Long Name
35 !global
36
37 The !module command was meant to define a kind of modularity.
38 What it does is to make sure the module name is prepended
39 to the base name. !global turns this off. This construction
40 is not recursive.
41
42Lines starting with # are treated as comments, as well as any line starting
43with ! and not matching the commands above.
44
diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h
deleted file mode 100644
index f859d859b8..0000000000
--- a/src/lib/libcrypto/objects/objects.h
+++ /dev/null
@@ -1,1044 +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#define USE_OBJ_MAC
63
64#ifdef USE_OBJ_MAC
65#include <openssl/obj_mac.h>
66#else
67#define SN_undef "UNDEF"
68#define LN_undef "undefined"
69#define NID_undef 0
70#define OBJ_undef 0L
71
72#define SN_Algorithm "Algorithm"
73#define LN_algorithm "algorithm"
74#define NID_algorithm 38
75#define OBJ_algorithm 1L,3L,14L,3L,2L
76
77#define LN_rsadsi "rsadsi"
78#define NID_rsadsi 1
79#define OBJ_rsadsi 1L,2L,840L,113549L
80
81#define LN_pkcs "pkcs"
82#define NID_pkcs 2
83#define OBJ_pkcs OBJ_rsadsi,1L
84
85#define SN_md2 "MD2"
86#define LN_md2 "md2"
87#define NID_md2 3
88#define OBJ_md2 OBJ_rsadsi,2L,2L
89
90#define SN_md5 "MD5"
91#define LN_md5 "md5"
92#define NID_md5 4
93#define OBJ_md5 OBJ_rsadsi,2L,5L
94
95#define SN_rc4 "RC4"
96#define LN_rc4 "rc4"
97#define NID_rc4 5
98#define OBJ_rc4 OBJ_rsadsi,3L,4L
99
100#define LN_rsaEncryption "rsaEncryption"
101#define NID_rsaEncryption 6
102#define OBJ_rsaEncryption OBJ_pkcs,1L,1L
103
104#define SN_md2WithRSAEncryption "RSA-MD2"
105#define LN_md2WithRSAEncryption "md2WithRSAEncryption"
106#define NID_md2WithRSAEncryption 7
107#define OBJ_md2WithRSAEncryption OBJ_pkcs,1L,2L
108
109#define SN_md5WithRSAEncryption "RSA-MD5"
110#define LN_md5WithRSAEncryption "md5WithRSAEncryption"
111#define NID_md5WithRSAEncryption 8
112#define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L
113
114#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES"
115#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
116#define NID_pbeWithMD2AndDES_CBC 9
117#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L
118
119#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES"
120#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
121#define NID_pbeWithMD5AndDES_CBC 10
122#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L
123
124#define LN_X500 "X500"
125#define NID_X500 11
126#define OBJ_X500 2L,5L
127
128#define LN_X509 "X509"
129#define NID_X509 12
130#define OBJ_X509 OBJ_X500,4L
131
132#define SN_commonName "CN"
133#define LN_commonName "commonName"
134#define NID_commonName 13
135#define OBJ_commonName OBJ_X509,3L
136
137#define SN_countryName "C"
138#define LN_countryName "countryName"
139#define NID_countryName 14
140#define OBJ_countryName OBJ_X509,6L
141
142#define SN_localityName "L"
143#define LN_localityName "localityName"
144#define NID_localityName 15
145#define OBJ_localityName OBJ_X509,7L
146
147/* Postal Address? PA */
148
149/* should be "ST" (rfc1327) but MS uses 'S' */
150#define SN_stateOrProvinceName "ST"
151#define LN_stateOrProvinceName "stateOrProvinceName"
152#define NID_stateOrProvinceName 16
153#define OBJ_stateOrProvinceName OBJ_X509,8L
154
155#define SN_organizationName "O"
156#define LN_organizationName "organizationName"
157#define NID_organizationName 17
158#define OBJ_organizationName OBJ_X509,10L
159
160#define SN_organizationalUnitName "OU"
161#define LN_organizationalUnitName "organizationalUnitName"
162#define NID_organizationalUnitName 18
163#define OBJ_organizationalUnitName OBJ_X509,11L
164
165#define SN_rsa "RSA"
166#define LN_rsa "rsa"
167#define NID_rsa 19
168#define OBJ_rsa OBJ_X500,8L,1L,1L
169
170#define LN_pkcs7 "pkcs7"
171#define NID_pkcs7 20
172#define OBJ_pkcs7 OBJ_pkcs,7L
173
174#define LN_pkcs7_data "pkcs7-data"
175#define NID_pkcs7_data 21
176#define OBJ_pkcs7_data OBJ_pkcs7,1L
177
178#define LN_pkcs7_signed "pkcs7-signedData"
179#define NID_pkcs7_signed 22
180#define OBJ_pkcs7_signed OBJ_pkcs7,2L
181
182#define LN_pkcs7_enveloped "pkcs7-envelopedData"
183#define NID_pkcs7_enveloped 23
184#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L
185
186#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData"
187#define NID_pkcs7_signedAndEnveloped 24
188#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L
189
190#define LN_pkcs7_digest "pkcs7-digestData"
191#define NID_pkcs7_digest 25
192#define OBJ_pkcs7_digest OBJ_pkcs7,5L
193
194#define LN_pkcs7_encrypted "pkcs7-encryptedData"
195#define NID_pkcs7_encrypted 26
196#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L
197
198#define LN_pkcs3 "pkcs3"
199#define NID_pkcs3 27
200#define OBJ_pkcs3 OBJ_pkcs,3L
201
202#define LN_dhKeyAgreement "dhKeyAgreement"
203#define NID_dhKeyAgreement 28
204#define OBJ_dhKeyAgreement OBJ_pkcs3,1L
205
206#define SN_des_ecb "DES-ECB"
207#define LN_des_ecb "des-ecb"
208#define NID_des_ecb 29
209#define OBJ_des_ecb OBJ_algorithm,6L
210
211#define SN_des_cfb64 "DES-CFB"
212#define LN_des_cfb64 "des-cfb"
213#define NID_des_cfb64 30
214/* IV + num */
215#define OBJ_des_cfb64 OBJ_algorithm,9L
216
217#define SN_des_cbc "DES-CBC"
218#define LN_des_cbc "des-cbc"
219#define NID_des_cbc 31
220/* IV */
221#define OBJ_des_cbc OBJ_algorithm,7L
222
223#define SN_des_ede "DES-EDE"
224#define LN_des_ede "des-ede"
225#define NID_des_ede 32
226/* ?? */
227#define OBJ_des_ede OBJ_algorithm,17L
228
229#define SN_des_ede3 "DES-EDE3"
230#define LN_des_ede3 "des-ede3"
231#define NID_des_ede3 33
232
233#define SN_idea_cbc "IDEA-CBC"
234#define LN_idea_cbc "idea-cbc"
235#define NID_idea_cbc 34
236#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L
237
238#define SN_idea_cfb64 "IDEA-CFB"
239#define LN_idea_cfb64 "idea-cfb"
240#define NID_idea_cfb64 35
241
242#define SN_idea_ecb "IDEA-ECB"
243#define LN_idea_ecb "idea-ecb"
244#define NID_idea_ecb 36
245
246#define SN_rc2_cbc "RC2-CBC"
247#define LN_rc2_cbc "rc2-cbc"
248#define NID_rc2_cbc 37
249#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L
250
251#define SN_rc2_ecb "RC2-ECB"
252#define LN_rc2_ecb "rc2-ecb"
253#define NID_rc2_ecb 38
254
255#define SN_rc2_cfb64 "RC2-CFB"
256#define LN_rc2_cfb64 "rc2-cfb"
257#define NID_rc2_cfb64 39
258
259#define SN_rc2_ofb64 "RC2-OFB"
260#define LN_rc2_ofb64 "rc2-ofb"
261#define NID_rc2_ofb64 40
262
263#define SN_sha "SHA"
264#define LN_sha "sha"
265#define NID_sha 41
266#define OBJ_sha OBJ_algorithm,18L
267
268#define SN_shaWithRSAEncryption "RSA-SHA"
269#define LN_shaWithRSAEncryption "shaWithRSAEncryption"
270#define NID_shaWithRSAEncryption 42
271#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L
272
273#define SN_des_ede_cbc "DES-EDE-CBC"
274#define LN_des_ede_cbc "des-ede-cbc"
275#define NID_des_ede_cbc 43
276
277#define SN_des_ede3_cbc "DES-EDE3-CBC"
278#define LN_des_ede3_cbc "des-ede3-cbc"
279#define NID_des_ede3_cbc 44
280#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L
281
282#define SN_des_ofb64 "DES-OFB"
283#define LN_des_ofb64 "des-ofb"
284#define NID_des_ofb64 45
285#define OBJ_des_ofb64 OBJ_algorithm,8L
286
287#define SN_idea_ofb64 "IDEA-OFB"
288#define LN_idea_ofb64 "idea-ofb"
289#define NID_idea_ofb64 46
290
291#define LN_pkcs9 "pkcs9"
292#define NID_pkcs9 47
293#define OBJ_pkcs9 OBJ_pkcs,9L
294
295#define SN_pkcs9_emailAddress "Email"
296#define LN_pkcs9_emailAddress "emailAddress"
297#define NID_pkcs9_emailAddress 48
298#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L
299
300#define LN_pkcs9_unstructuredName "unstructuredName"
301#define NID_pkcs9_unstructuredName 49
302#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L
303
304#define LN_pkcs9_contentType "contentType"
305#define NID_pkcs9_contentType 50
306#define OBJ_pkcs9_contentType OBJ_pkcs9,3L
307
308#define LN_pkcs9_messageDigest "messageDigest"
309#define NID_pkcs9_messageDigest 51
310#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L
311
312#define LN_pkcs9_signingTime "signingTime"
313#define NID_pkcs9_signingTime 52
314#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L
315
316#define LN_pkcs9_countersignature "countersignature"
317#define NID_pkcs9_countersignature 53
318#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L
319
320#define LN_pkcs9_challengePassword "challengePassword"
321#define NID_pkcs9_challengePassword 54
322#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L
323
324#define LN_pkcs9_unstructuredAddress "unstructuredAddress"
325#define NID_pkcs9_unstructuredAddress 55
326#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L
327
328#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes"
329#define NID_pkcs9_extCertAttributes 56
330#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L
331
332#define SN_netscape "Netscape"
333#define LN_netscape "Netscape Communications Corp."
334#define NID_netscape 57
335#define OBJ_netscape 2L,16L,840L,1L,113730L
336
337#define SN_netscape_cert_extension "nsCertExt"
338#define LN_netscape_cert_extension "Netscape Certificate Extension"
339#define NID_netscape_cert_extension 58
340#define OBJ_netscape_cert_extension OBJ_netscape,1L
341
342#define SN_netscape_data_type "nsDataType"
343#define LN_netscape_data_type "Netscape Data Type"
344#define NID_netscape_data_type 59
345#define OBJ_netscape_data_type OBJ_netscape,2L
346
347#define SN_des_ede_cfb64 "DES-EDE-CFB"
348#define LN_des_ede_cfb64 "des-ede-cfb"
349#define NID_des_ede_cfb64 60
350
351#define SN_des_ede3_cfb64 "DES-EDE3-CFB"
352#define LN_des_ede3_cfb64 "des-ede3-cfb"
353#define NID_des_ede3_cfb64 61
354
355#define SN_des_ede_ofb64 "DES-EDE-OFB"
356#define LN_des_ede_ofb64 "des-ede-ofb"
357#define NID_des_ede_ofb64 62
358
359#define SN_des_ede3_ofb64 "DES-EDE3-OFB"
360#define LN_des_ede3_ofb64 "des-ede3-ofb"
361#define NID_des_ede3_ofb64 63
362
363/* I'm not sure about the object ID */
364#define SN_sha1 "SHA1"
365#define LN_sha1 "sha1"
366#define NID_sha1 64
367#define OBJ_sha1 OBJ_algorithm,26L
368/* 28 Jun 1996 - eay */
369/* #define OBJ_sha1 1L,3L,14L,2L,26L,05L <- wrong */
370
371#define SN_sha1WithRSAEncryption "RSA-SHA1"
372#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption"
373#define NID_sha1WithRSAEncryption 65
374#define OBJ_sha1WithRSAEncryption OBJ_pkcs,1L,5L
375
376#define SN_dsaWithSHA "DSA-SHA"
377#define LN_dsaWithSHA "dsaWithSHA"
378#define NID_dsaWithSHA 66
379#define OBJ_dsaWithSHA OBJ_algorithm,13L
380
381#define SN_dsa_2 "DSA-old"
382#define LN_dsa_2 "dsaEncryption-old"
383#define NID_dsa_2 67
384#define OBJ_dsa_2 OBJ_algorithm,12L
385
386/* proposed by microsoft to RSA */
387#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
388#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
389#define NID_pbeWithSHA1AndRC2_CBC 68
390#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
391
392/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now
393 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something
394 * completely different.
395 */
396#define LN_id_pbkdf2 "PBKDF2"
397#define NID_id_pbkdf2 69
398#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L
399
400#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
401#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
402#define NID_dsaWithSHA1_2 70
403/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */
404#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
405
406#define SN_netscape_cert_type "nsCertType"
407#define LN_netscape_cert_type "Netscape Cert Type"
408#define NID_netscape_cert_type 71
409#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L
410
411#define SN_netscape_base_url "nsBaseUrl"
412#define LN_netscape_base_url "Netscape Base Url"
413#define NID_netscape_base_url 72
414#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L
415
416#define SN_netscape_revocation_url "nsRevocationUrl"
417#define LN_netscape_revocation_url "Netscape Revocation Url"
418#define NID_netscape_revocation_url 73
419#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L
420
421#define SN_netscape_ca_revocation_url "nsCaRevocationUrl"
422#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url"
423#define NID_netscape_ca_revocation_url 74
424#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L
425
426#define SN_netscape_renewal_url "nsRenewalUrl"
427#define LN_netscape_renewal_url "Netscape Renewal Url"
428#define NID_netscape_renewal_url 75
429#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L
430
431#define SN_netscape_ca_policy_url "nsCaPolicyUrl"
432#define LN_netscape_ca_policy_url "Netscape CA Policy Url"
433#define NID_netscape_ca_policy_url 76
434#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L
435
436#define SN_netscape_ssl_server_name "nsSslServerName"
437#define LN_netscape_ssl_server_name "Netscape SSL Server Name"
438#define NID_netscape_ssl_server_name 77
439#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L
440
441#define SN_netscape_comment "nsComment"
442#define LN_netscape_comment "Netscape Comment"
443#define NID_netscape_comment 78
444#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L
445
446#define SN_netscape_cert_sequence "nsCertSequence"
447#define LN_netscape_cert_sequence "Netscape Certificate Sequence"
448#define NID_netscape_cert_sequence 79
449#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L
450
451#define SN_desx_cbc "DESX-CBC"
452#define LN_desx_cbc "desx-cbc"
453#define NID_desx_cbc 80
454
455#define SN_id_ce "id-ce"
456#define NID_id_ce 81
457#define OBJ_id_ce 2L,5L,29L
458
459#define SN_subject_key_identifier "subjectKeyIdentifier"
460#define LN_subject_key_identifier "X509v3 Subject Key Identifier"
461#define NID_subject_key_identifier 82
462#define OBJ_subject_key_identifier OBJ_id_ce,14L
463
464#define SN_key_usage "keyUsage"
465#define LN_key_usage "X509v3 Key Usage"
466#define NID_key_usage 83
467#define OBJ_key_usage OBJ_id_ce,15L
468
469#define SN_private_key_usage_period "privateKeyUsagePeriod"
470#define LN_private_key_usage_period "X509v3 Private Key Usage Period"
471#define NID_private_key_usage_period 84
472#define OBJ_private_key_usage_period OBJ_id_ce,16L
473
474#define SN_subject_alt_name "subjectAltName"
475#define LN_subject_alt_name "X509v3 Subject Alternative Name"
476#define NID_subject_alt_name 85
477#define OBJ_subject_alt_name OBJ_id_ce,17L
478
479#define SN_issuer_alt_name "issuerAltName"
480#define LN_issuer_alt_name "X509v3 Issuer Alternative Name"
481#define NID_issuer_alt_name 86
482#define OBJ_issuer_alt_name OBJ_id_ce,18L
483
484#define SN_basic_constraints "basicConstraints"
485#define LN_basic_constraints "X509v3 Basic Constraints"
486#define NID_basic_constraints 87
487#define OBJ_basic_constraints OBJ_id_ce,19L
488
489#define SN_crl_number "crlNumber"
490#define LN_crl_number "X509v3 CRL Number"
491#define NID_crl_number 88
492#define OBJ_crl_number OBJ_id_ce,20L
493
494#define SN_certificate_policies "certificatePolicies"
495#define LN_certificate_policies "X509v3 Certificate Policies"
496#define NID_certificate_policies 89
497#define OBJ_certificate_policies OBJ_id_ce,32L
498
499#define SN_authority_key_identifier "authorityKeyIdentifier"
500#define LN_authority_key_identifier "X509v3 Authority Key Identifier"
501#define NID_authority_key_identifier 90
502#define OBJ_authority_key_identifier OBJ_id_ce,35L
503
504#define SN_bf_cbc "BF-CBC"
505#define LN_bf_cbc "bf-cbc"
506#define NID_bf_cbc 91
507#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L
508
509#define SN_bf_ecb "BF-ECB"
510#define LN_bf_ecb "bf-ecb"
511#define NID_bf_ecb 92
512
513#define SN_bf_cfb64 "BF-CFB"
514#define LN_bf_cfb64 "bf-cfb"
515#define NID_bf_cfb64 93
516
517#define SN_bf_ofb64 "BF-OFB"
518#define LN_bf_ofb64 "bf-ofb"
519#define NID_bf_ofb64 94
520
521#define SN_mdc2 "MDC2"
522#define LN_mdc2 "mdc2"
523#define NID_mdc2 95
524#define OBJ_mdc2 2L,5L,8L,3L,101L
525/* An alternative? 1L,3L,14L,3L,2L,19L */
526
527#define SN_mdc2WithRSA "RSA-MDC2"
528#define LN_mdc2WithRSA "mdc2withRSA"
529#define NID_mdc2WithRSA 96
530#define OBJ_mdc2WithRSA 2L,5L,8L,3L,100L
531
532#define SN_rc4_40 "RC4-40"
533#define LN_rc4_40 "rc4-40"
534#define NID_rc4_40 97
535
536#define SN_rc2_40_cbc "RC2-40-CBC"
537#define LN_rc2_40_cbc "rc2-40-cbc"
538#define NID_rc2_40_cbc 98
539
540#define SN_givenName "G"
541#define LN_givenName "givenName"
542#define NID_givenName 99
543#define OBJ_givenName OBJ_X509,42L
544
545#define SN_surname "S"
546#define LN_surname "surname"
547#define NID_surname 100
548#define OBJ_surname OBJ_X509,4L
549
550#define SN_initials "I"
551#define LN_initials "initials"
552#define NID_initials 101
553#define OBJ_initials OBJ_X509,43L
554
555#define SN_uniqueIdentifier "UID"
556#define LN_uniqueIdentifier "uniqueIdentifier"
557#define NID_uniqueIdentifier 102
558#define OBJ_uniqueIdentifier OBJ_X509,45L
559
560#define SN_crl_distribution_points "crlDistributionPoints"
561#define LN_crl_distribution_points "X509v3 CRL Distribution Points"
562#define NID_crl_distribution_points 103
563#define OBJ_crl_distribution_points OBJ_id_ce,31L
564
565#define SN_md5WithRSA "RSA-NP-MD5"
566#define LN_md5WithRSA "md5WithRSA"
567#define NID_md5WithRSA 104
568#define OBJ_md5WithRSA OBJ_algorithm,3L
569
570#define SN_serialNumber "SN"
571#define LN_serialNumber "serialNumber"
572#define NID_serialNumber 105
573#define OBJ_serialNumber OBJ_X509,5L
574
575#define SN_title "T"
576#define LN_title "title"
577#define NID_title 106
578#define OBJ_title OBJ_X509,12L
579
580#define SN_description "D"
581#define LN_description "description"
582#define NID_description 107
583#define OBJ_description OBJ_X509,13L
584
585/* CAST5 is CAST-128, I'm just sticking with the documentation */
586#define SN_cast5_cbc "CAST5-CBC"
587#define LN_cast5_cbc "cast5-cbc"
588#define NID_cast5_cbc 108
589#define OBJ_cast5_cbc 1L,2L,840L,113533L,7L,66L,10L
590
591#define SN_cast5_ecb "CAST5-ECB"
592#define LN_cast5_ecb "cast5-ecb"
593#define NID_cast5_ecb 109
594
595#define SN_cast5_cfb64 "CAST5-CFB"
596#define LN_cast5_cfb64 "cast5-cfb"
597#define NID_cast5_cfb64 110
598
599#define SN_cast5_ofb64 "CAST5-OFB"
600#define LN_cast5_ofb64 "cast5-ofb"
601#define NID_cast5_ofb64 111
602
603#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC"
604#define NID_pbeWithMD5AndCast5_CBC 112
605#define OBJ_pbeWithMD5AndCast5_CBC 1L,2L,840L,113533L,7L,66L,12L
606
607/* This is one sun will soon be using :-(
608 * id-dsa-with-sha1 ID ::= {
609 * iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 }
610 */
611#define SN_dsaWithSHA1 "DSA-SHA1"
612#define LN_dsaWithSHA1 "dsaWithSHA1"
613#define NID_dsaWithSHA1 113
614#define OBJ_dsaWithSHA1 1L,2L,840L,10040L,4L,3L
615
616#define NID_md5_sha1 114
617#define SN_md5_sha1 "MD5-SHA1"
618#define LN_md5_sha1 "md5-sha1"
619
620#define SN_sha1WithRSA "RSA-SHA1-2"
621#define LN_sha1WithRSA "sha1WithRSA"
622#define NID_sha1WithRSA 115
623#define OBJ_sha1WithRSA OBJ_algorithm,29L
624
625#define SN_dsa "DSA"
626#define LN_dsa "dsaEncryption"
627#define NID_dsa 116
628#define OBJ_dsa 1L,2L,840L,10040L,4L,1L
629
630#define SN_ripemd160 "RIPEMD160"
631#define LN_ripemd160 "ripemd160"
632#define NID_ripemd160 117
633#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
634
635/* The name should actually be rsaSignatureWithripemd160, but I'm going
636 * to continue using the convention I'm using with the other ciphers */
637#define SN_ripemd160WithRSA "RSA-RIPEMD160"
638#define LN_ripemd160WithRSA "ripemd160WithRSA"
639#define NID_ripemd160WithRSA 119
640#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L
641
642/* Taken from rfc2040
643 * RC5_CBC_Parameters ::= SEQUENCE {
644 * version INTEGER (v1_0(16)),
645 * rounds INTEGER (8..127),
646 * blockSizeInBits INTEGER (64, 128),
647 * iv OCTET STRING OPTIONAL
648 * }
649 */
650#define SN_rc5_cbc "RC5-CBC"
651#define LN_rc5_cbc "rc5-cbc"
652#define NID_rc5_cbc 120
653#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L
654
655#define SN_rc5_ecb "RC5-ECB"
656#define LN_rc5_ecb "rc5-ecb"
657#define NID_rc5_ecb 121
658
659#define SN_rc5_cfb64 "RC5-CFB"
660#define LN_rc5_cfb64 "rc5-cfb"
661#define NID_rc5_cfb64 122
662
663#define SN_rc5_ofb64 "RC5-OFB"
664#define LN_rc5_ofb64 "rc5-ofb"
665#define NID_rc5_ofb64 123
666
667#define SN_rle_compression "RLE"
668#define LN_rle_compression "run length compression"
669#define NID_rle_compression 124
670#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L
671
672#define SN_zlib_compression "ZLIB"
673#define LN_zlib_compression "zlib compression"
674#define NID_zlib_compression 125
675#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L
676
677#define SN_ext_key_usage "extendedKeyUsage"
678#define LN_ext_key_usage "X509v3 Extended Key Usage"
679#define NID_ext_key_usage 126
680#define OBJ_ext_key_usage OBJ_id_ce,37
681
682#define SN_id_pkix "PKIX"
683#define NID_id_pkix 127
684#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L
685
686#define SN_id_kp "id-kp"
687#define NID_id_kp 128
688#define OBJ_id_kp OBJ_id_pkix,3L
689
690/* PKIX extended key usage OIDs */
691
692#define SN_server_auth "serverAuth"
693#define LN_server_auth "TLS Web Server Authentication"
694#define NID_server_auth 129
695#define OBJ_server_auth OBJ_id_kp,1L
696
697#define SN_client_auth "clientAuth"
698#define LN_client_auth "TLS Web Client Authentication"
699#define NID_client_auth 130
700#define OBJ_client_auth OBJ_id_kp,2L
701
702#define SN_code_sign "codeSigning"
703#define LN_code_sign "Code Signing"
704#define NID_code_sign 131
705#define OBJ_code_sign OBJ_id_kp,3L
706
707#define SN_email_protect "emailProtection"
708#define LN_email_protect "E-mail Protection"
709#define NID_email_protect 132
710#define OBJ_email_protect OBJ_id_kp,4L
711
712#define SN_time_stamp "timeStamping"
713#define LN_time_stamp "Time Stamping"
714#define NID_time_stamp 133
715#define OBJ_time_stamp OBJ_id_kp,8L
716
717/* Additional extended key usage OIDs: Microsoft */
718
719#define SN_ms_code_ind "msCodeInd"
720#define LN_ms_code_ind "Microsoft Individual Code Signing"
721#define NID_ms_code_ind 134
722#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
723
724#define SN_ms_code_com "msCodeCom"
725#define LN_ms_code_com "Microsoft Commercial Code Signing"
726#define NID_ms_code_com 135
727#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
728
729#define SN_ms_ctl_sign "msCTLSign"
730#define LN_ms_ctl_sign "Microsoft Trust List Signing"
731#define NID_ms_ctl_sign 136
732#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
733
734#define SN_ms_sgc "msSGC"
735#define LN_ms_sgc "Microsoft Server Gated Crypto"
736#define NID_ms_sgc 137
737#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
738
739#define SN_ms_efs "msEFS"
740#define LN_ms_efs "Microsoft Encrypted File System"
741#define NID_ms_efs 138
742#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
743
744/* Additional usage: Netscape */
745
746#define SN_ns_sgc "nsSGC"
747#define LN_ns_sgc "Netscape Server Gated Crypto"
748#define NID_ns_sgc 139
749#define OBJ_ns_sgc OBJ_netscape,4L,1L
750
751#define SN_delta_crl "deltaCRL"
752#define LN_delta_crl "X509v3 Delta CRL Indicator"
753#define NID_delta_crl 140
754#define OBJ_delta_crl OBJ_id_ce,27L
755
756#define SN_crl_reason "CRLReason"
757#define LN_crl_reason "CRL Reason Code"
758#define NID_crl_reason 141
759#define OBJ_crl_reason OBJ_id_ce,21L
760
761#define SN_invalidity_date "invalidityDate"
762#define LN_invalidity_date "Invalidity Date"
763#define NID_invalidity_date 142
764#define OBJ_invalidity_date OBJ_id_ce,24L
765
766#define SN_sxnet "SXNetID"
767#define LN_sxnet "Strong Extranet ID"
768#define NID_sxnet 143
769#define OBJ_sxnet 1L,3L,101L,1L,4L,1L
770
771/* PKCS12 and related OBJECT IDENTIFIERS */
772
773#define OBJ_pkcs12 OBJ_pkcs,12L
774#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1
775
776#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128"
777#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
778#define NID_pbe_WithSHA1And128BitRC4 144
779#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L
780
781#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40"
782#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
783#define NID_pbe_WithSHA1And40BitRC4 145
784#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L
785
786#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES"
787#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
788#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
789#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L
790
791#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES"
792#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
793#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
794#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L
795
796#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128"
797#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
798#define NID_pbe_WithSHA1And128BitRC2_CBC 148
799#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L
800
801#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40"
802#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
803#define NID_pbe_WithSHA1And40BitRC2_CBC 149
804#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L
805
806#define OBJ_pkcs12_Version1 OBJ_pkcs12, 10L
807
808#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1, 1L
809
810#define LN_keyBag "keyBag"
811#define NID_keyBag 150
812#define OBJ_keyBag OBJ_pkcs12_BagIds, 1L
813
814#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"
815#define NID_pkcs8ShroudedKeyBag 151
816#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds, 2L
817
818#define LN_certBag "certBag"
819#define NID_certBag 152
820#define OBJ_certBag OBJ_pkcs12_BagIds, 3L
821
822#define LN_crlBag "crlBag"
823#define NID_crlBag 153
824#define OBJ_crlBag OBJ_pkcs12_BagIds, 4L
825
826#define LN_secretBag "secretBag"
827#define NID_secretBag 154
828#define OBJ_secretBag OBJ_pkcs12_BagIds, 5L
829
830#define LN_safeContentsBag "safeContentsBag"
831#define NID_safeContentsBag 155
832#define OBJ_safeContentsBag OBJ_pkcs12_BagIds, 6L
833
834#define LN_friendlyName "friendlyName"
835#define NID_friendlyName 156
836#define OBJ_friendlyName OBJ_pkcs9, 20L
837
838#define LN_localKeyID "localKeyID"
839#define NID_localKeyID 157
840#define OBJ_localKeyID OBJ_pkcs9, 21L
841
842#define OBJ_certTypes OBJ_pkcs9, 22L
843
844#define LN_x509Certificate "x509Certificate"
845#define NID_x509Certificate 158
846#define OBJ_x509Certificate OBJ_certTypes, 1L
847
848#define LN_sdsiCertificate "sdsiCertificate"
849#define NID_sdsiCertificate 159
850#define OBJ_sdsiCertificate OBJ_certTypes, 2L
851
852#define OBJ_crlTypes OBJ_pkcs9, 23L
853
854#define LN_x509Crl "x509Crl"
855#define NID_x509Crl 160
856#define OBJ_x509Crl OBJ_crlTypes, 1L
857
858/* PKCS#5 v2 OIDs */
859
860#define LN_pbes2 "PBES2"
861#define NID_pbes2 161
862#define OBJ_pbes2 OBJ_pkcs,5L,13L
863
864#define LN_pbmac1 "PBMAC1"
865#define NID_pbmac1 162
866#define OBJ_pbmac1 OBJ_pkcs,5L,14L
867
868#define LN_hmacWithSHA1 "hmacWithSHA1"
869#define NID_hmacWithSHA1 163
870#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L
871
872/* Policy Qualifier Ids */
873
874#define LN_id_qt_cps "Policy Qualifier CPS"
875#define SN_id_qt_cps "id-qt-cps"
876#define NID_id_qt_cps 164
877#define OBJ_id_qt_cps OBJ_id_pkix,2L,1L
878
879#define LN_id_qt_unotice "Policy Qualifier User Notice"
880#define SN_id_qt_unotice "id-qt-unotice"
881#define NID_id_qt_unotice 165
882#define OBJ_id_qt_unotice OBJ_id_pkix,2L,2L
883
884#define SN_rc2_64_cbc "RC2-64-CBC"
885#define LN_rc2_64_cbc "rc2-64-cbc"
886#define NID_rc2_64_cbc 166
887
888#define SN_SMIMECapabilities "SMIME-CAPS"
889#define LN_SMIMECapabilities "S/MIME Capabilities"
890#define NID_SMIMECapabilities 167
891#define OBJ_SMIMECapabilities OBJ_pkcs9,15L
892
893#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64"
894#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
895#define NID_pbeWithMD2AndRC2_CBC 168
896#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L
897
898#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64"
899#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
900#define NID_pbeWithMD5AndRC2_CBC 169
901#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L
902
903#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES"
904#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
905#define NID_pbeWithSHA1AndDES_CBC 170
906#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L
907
908/* Extension request OIDs */
909
910#define LN_ms_ext_req "Microsoft Extension Request"
911#define SN_ms_ext_req "msExtReq"
912#define NID_ms_ext_req 171
913#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L
914
915#define LN_ext_req "Extension Request"
916#define SN_ext_req "extReq"
917#define NID_ext_req 172
918#define OBJ_ext_req OBJ_pkcs9,14L
919
920#define SN_name "name"
921#define LN_name "name"
922#define NID_name 173
923#define OBJ_name OBJ_X509,41L
924
925#define SN_dnQualifier "dnQualifier"
926#define LN_dnQualifier "dnQualifier"
927#define NID_dnQualifier 174
928#define OBJ_dnQualifier OBJ_X509,46L
929
930#define SN_id_pe "id-pe"
931#define NID_id_pe 175
932#define OBJ_id_pe OBJ_id_pkix,1L
933
934#define SN_id_ad "id-ad"
935#define NID_id_ad 176
936#define OBJ_id_ad OBJ_id_pkix,48L
937
938#define SN_info_access "authorityInfoAccess"
939#define LN_info_access "Authority Information Access"
940#define NID_info_access 177
941#define OBJ_info_access OBJ_id_pe,1L
942
943#define SN_ad_OCSP "OCSP"
944#define LN_ad_OCSP "OCSP"
945#define NID_ad_OCSP 178
946#define OBJ_ad_OCSP OBJ_id_ad,1L
947
948#define SN_ad_ca_issuers "caIssuers"
949#define LN_ad_ca_issuers "CA Issuers"
950#define NID_ad_ca_issuers 179
951#define OBJ_ad_ca_issuers OBJ_id_ad,2L
952
953#define SN_OCSP_sign "OCSPSigning"
954#define LN_OCSP_sign "OCSP Signing"
955#define NID_OCSP_sign 180
956#define OBJ_OCSP_sign OBJ_id_kp,9L
957#endif /* USE_OBJ_MAC */
958
959#include <openssl/bio.h>
960#include <openssl/asn1.h>
961
962#define OBJ_NAME_TYPE_UNDEF 0x00
963#define OBJ_NAME_TYPE_MD_METH 0x01
964#define OBJ_NAME_TYPE_CIPHER_METH 0x02
965#define OBJ_NAME_TYPE_PKEY_METH 0x03
966#define OBJ_NAME_TYPE_COMP_METH 0x04
967#define OBJ_NAME_TYPE_NUM 0x05
968
969#define OBJ_NAME_ALIAS 0x8000
970
971
972#ifdef __cplusplus
973extern "C" {
974#endif
975
976typedef struct obj_name_st
977 {
978 int type;
979 int alias;
980 const char *name;
981 const char *data;
982 } OBJ_NAME;
983
984#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
985
986
987int OBJ_NAME_init(void);
988int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
989 int (*cmp_func)(const char *, const char *),
990 void (*free_func)(const char *, int, const char *));
991const char *OBJ_NAME_get(const char *name,int type);
992int OBJ_NAME_add(const char *name,int type,const char *data);
993int OBJ_NAME_remove(const char *name,int type);
994void OBJ_NAME_cleanup(int type); /* -1 for everything */
995void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),
996 void *arg);
997void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
998 void *arg);
999
1000ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
1001ASN1_OBJECT * OBJ_nid2obj(int n);
1002const char * OBJ_nid2ln(int n);
1003const char * OBJ_nid2sn(int n);
1004int OBJ_obj2nid(const ASN1_OBJECT *o);
1005ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
1006int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
1007int OBJ_txt2nid(const char *s);
1008int OBJ_ln2nid(const char *s);
1009int OBJ_sn2nid(const char *s);
1010int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
1011const char * OBJ_bsearch(const char *key,const char *base,int num,int size,
1012 int (*cmp)(const void *, const void *));
1013
1014int OBJ_new_nid(int num);
1015int OBJ_add_object(const ASN1_OBJECT *obj);
1016int OBJ_create(const char *oid,const char *sn,const char *ln);
1017void OBJ_cleanup(void );
1018int OBJ_create_objects(BIO *in);
1019
1020/* BEGIN ERROR CODES */
1021/* The following lines are auto generated by the script mkerr.pl. Any changes
1022 * made after this point may be overwritten when the script is next run.
1023 */
1024void ERR_load_OBJ_strings(void);
1025
1026/* Error codes for the OBJ functions. */
1027
1028/* Function codes. */
1029#define OBJ_F_OBJ_ADD_OBJECT 105
1030#define OBJ_F_OBJ_CREATE 100
1031#define OBJ_F_OBJ_DUP 101
1032#define OBJ_F_OBJ_NAME_NEW_INDEX 106
1033#define OBJ_F_OBJ_NID2LN 102
1034#define OBJ_F_OBJ_NID2OBJ 103
1035#define OBJ_F_OBJ_NID2SN 104
1036
1037/* Reason codes. */
1038#define OBJ_R_MALLOC_FAILURE 100
1039#define OBJ_R_UNKNOWN_NID 101
1040
1041#ifdef __cplusplus
1042}
1043#endif
1044#endif
diff --git a/src/lib/libcrypto/objects/objects.pl b/src/lib/libcrypto/objects/objects.pl
deleted file mode 100644
index 76bb8da677..0000000000
--- a/src/lib/libcrypto/objects/objects.pl
+++ /dev/null
@@ -1,230 +0,0 @@
1#!/usr/local/bin/perl
2
3open (NUMIN,"$ARGV[1]") || die "Can't open number file $ARGV[1]";
4$max_nid=0;
5$o=0;
6while(<NUMIN>)
7 {
8 chop;
9 $o++;
10 s/#.*$//;
11 next if /^\s*$/;
12 $_ = 'X'.$_;
13 ($Cname,$mynum) = split;
14 $Cname =~ s/^X//;
15 if (defined($nidn{$mynum}))
16 { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
17 $nid{$Cname} = $mynum;
18 $nidn{$mynum} = $Cname;
19 $order{$mynum} = $o;
20 $max_nid = $mynum if $mynum > $max_nid;
21 }
22close NUMIN;
23
24open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
25$Cname="";
26$o=0;
27while (<IN>)
28 {
29 chop;
30 $o++;
31 if (/^!module\s+(.*)$/)
32 {
33 $module = $1."-";
34 $module =~ s/\./_/g;
35 $module =~ s/-/_/g;
36 }
37 if (/^!global$/)
38 { $module = ""; }
39 if (/^!Cname\s+(.*)$/)
40 { $Cname = $1; }
41 if (/^!Alias\s+(.+?)\s+(.*)$/)
42 {
43 $Cname = $module.$1;
44 $myoid = $2;
45 $myoid = &process_oid($myoid);
46 $Cname =~ s/-/_/g;
47 $ordern{$o} = $Cname;
48 $order{$Cname} = $o;
49 $obj{$Cname} = $myoid;
50 $_ = "";
51 $Cname = "";
52 }
53 s/!.*$//;
54 s/#.*$//;
55 next if /^\s*$/;
56 ($myoid,$mysn,$myln) = split ':';
57 $mysn =~ s/^\s*//;
58 $mysn =~ s/\s*$//;
59 $myln =~ s/^\s*//;
60 $myln =~ s/\s*$//;
61 $myoid =~ s/^\s*//;
62 $myoid =~ s/\s*$//;
63 if ($myoid ne "")
64 {
65 $myoid = &process_oid($myoid);
66 }
67
68 if ($Cname eq "" && !($myln =~ / /))
69 {
70 $Cname = $myln;
71 $Cname =~ s/\./_/g;
72 $Cname =~ s/-/_/g;
73 if ($Cname ne "" && defined($ln{$module.$Cname}))
74 { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
75 }
76 if ($Cname eq "")
77 {
78 $Cname = $mysn;
79 $Cname =~ s/-/_/g;
80 if ($Cname ne "" && defined($sn{$module.$Cname}))
81 { die "objects.txt:$o:There's already an object with short name ",$sn{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
82 }
83 if ($Cname eq "")
84 {
85 $Cname = $myln;
86 $Cname =~ s/-/_/g;
87 $Cname =~ s/\./_/g;
88 $Cname =~ s/ /_/g;
89 if ($Cname ne "" && defined($ln{$module.$Cname}))
90 { die "objects.txt:$o:There's already an object with long name ",$ln{$module.$Cname}," on line ",$order{$module.$Cname},"\n"; }
91 }
92 $Cname =~ s/\./_/g;
93 $Cname =~ s/-/_/g;
94 $Cname = $module.$Cname;
95 $ordern{$o} = $Cname;
96 $order{$Cname} = $o;
97 $sn{$Cname} = $mysn;
98 $ln{$Cname} = $myln;
99 $obj{$Cname} = $myoid;
100 if (!defined($nid{$Cname}))
101 {
102 $max_nid++;
103 $nid{$Cname} = $max_nid;
104 $nidn{$max_nid} = $Cname;
105 }
106 $Cname="";
107 }
108close IN;
109
110#XXX don't modify input files
111#open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
112#foreach (sort { $a <=> $b } keys %nidn)
113# {
114# print NUMOUT $nidn{$_},"\t\t",$_,"\n";
115# }
116#close NUMOUT;
117
118open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]";
119print OUT <<'EOF';
120/* crypto/objects/obj_mac.h */
121
122/* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
123 * following command:
124 * perl objects.pl objects.txt obj_mac.num obj_mac.h
125 */
126
127/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
128 * All rights reserved.
129 *
130 * This package is an SSL implementation written
131 * by Eric Young (eay@cryptsoft.com).
132 * The implementation was written so as to conform with Netscapes SSL.
133 *
134 * This library is free for commercial and non-commercial use as long as
135 * the following conditions are aheared to. The following conditions
136 * apply to all code found in this distribution, be it the RC4, RSA,
137 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
138 * included with this distribution is covered by the same copyright terms
139 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
140 *
141 * Copyright remains Eric Young's, and as such any Copyright notices in
142 * the code are not to be removed.
143 * If this package is used in a product, Eric Young should be given attribution
144 * as the author of the parts of the library used.
145 * This can be in the form of a textual message at program startup or
146 * in documentation (online or textual) provided with the package.
147 *
148 * Redistribution and use in source and binary forms, with or without
149 * modification, are permitted provided that the following conditions
150 * are met:
151 * 1. Redistributions of source code must retain the copyright
152 * notice, this list of conditions and the following disclaimer.
153 * 2. Redistributions in binary form must reproduce the above copyright
154 * notice, this list of conditions and the following disclaimer in the
155 * documentation and/or other materials provided with the distribution.
156 * 3. All advertising materials mentioning features or use of this software
157 * must display the following acknowledgement:
158 * "This product includes cryptographic software written by
159 * Eric Young (eay@cryptsoft.com)"
160 * The word 'cryptographic' can be left out if the rouines from the library
161 * being used are not cryptographic related :-).
162 * 4. If you include any Windows specific code (or a derivative thereof) from
163 * the apps directory (application code) you must include an acknowledgement:
164 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
165 *
166 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
167 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
168 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
169 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
170 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
171 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
172 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
173 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
174 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
175 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
176 * SUCH DAMAGE.
177 *
178 * The licence and distribution terms for any publically available version or
179 * derivative of this code cannot be changed. i.e. this code cannot simply be
180 * copied and put under another distribution licence
181 * [including the GNU Public Licence.]
182 */
183
184#define SN_undef "UNDEF"
185#define LN_undef "undefined"
186#define NID_undef 0
187#define OBJ_undef 0L
188
189EOF
190
191foreach (sort { $a <=> $b } keys %ordern)
192 {
193 $Cname=$ordern{$_};
194 print OUT "#define SN_",$Cname,"\t\t\"",$sn{$Cname},"\"\n" if $sn{$Cname} ne "";
195 print OUT "#define LN_",$Cname,"\t\t\"",$ln{$Cname},"\"\n" if $ln{$Cname} ne "";
196 print OUT "#define NID_",$Cname,"\t\t",$nid{$Cname},"\n" if $nid{$Cname} ne "";
197 print OUT "#define OBJ_",$Cname,"\t\t",$obj{$Cname},"\n" if $obj{$Cname} ne "";
198 print OUT "\n";
199 }
200
201close OUT;
202
203sub process_oid
204 {
205 local($oid)=@_;
206 local(@a,$oid_pref);
207
208 @a = split(/\s+/,$myoid);
209 $pref_oid = "";
210 $pref_sep = "";
211 if (!($a[0] =~ /^[0-9]+$/))
212 {
213 $a[0] =~ s/-/_/g;
214 if (!defined($obj{$a[0]}))
215 { die "$ARGV[0]:$o:Undefined identifier ",$a[0],"\n"; }
216 $pref_oid = "OBJ_" . $a[0];
217 $pref_sep = ",";
218 shift @a;
219 }
220 $oids = join('L,',@a) . "L";
221 if ($oids ne "L")
222 {
223 $oids = $pref_oid . $pref_sep . $oids;
224 }
225 else
226 {
227 $oids = $pref_oid;
228 }
229 return($oids);
230 }
diff --git a/src/lib/libcrypto/objects/objects.txt b/src/lib/libcrypto/objects/objects.txt
deleted file mode 100644
index 2635c4e667..0000000000
--- a/src/lib/libcrypto/objects/objects.txt
+++ /dev/null
@@ -1,952 +0,0 @@
10 : CCITT : ccitt
2
31 : ISO : iso
4
52 : JOINT-ISO-CCITT : joint-iso-ccitt
6
7iso 2 : member-body : ISO Member Body
8
9joint-iso-ccitt 5 1 5 : selected-attribute-types : Selected Attribute Types
10
11selected-attribute-types 55 : clearance
12
13member-body 840 : ISO-US : ISO US Member Body
14ISO-US 10040 : X9-57 : X9.57
15X9-57 4 : X9cm : X9.57 CM ?
16
17!Cname dsa
18X9cm 1 : DSA : dsaEncryption
19X9cm 3 : DSA-SHA1 : dsaWithSHA1
20
21
22ISO-US 10045 : ansi-X9-62 : ANSI X9.62
23!module X9-62
24!Alias id-fieldType ansi-X9-62 1
25X9-62_id-fieldType 1 : prime-field
26X9-62_id-fieldType 2 : characteristic-two-field
27# ... characteristic-two-field OID subtree
28!Alias id-publicKeyType ansi-X9-62 2
29X9-62_id-publicKeyType 1 : id-ecPublicKey
30!Alias ellipticCurve ansi-X9-62 3
31!Alias c-TwoCurve X9-62_ellipticCurve 0
32# ... characteristic 2 curve OIDs
33!Alias primeCurve X9-62_ellipticCurve 1
34X9-62_primeCurve 1 : prime192v1
35X9-62_primeCurve 2 : prime192v2
36X9-62_primeCurve 3 : prime192v3
37X9-62_primeCurve 4 : prime239v1
38X9-62_primeCurve 5 : prime239v2
39X9-62_primeCurve 6 : prime239v3
40X9-62_primeCurve 7 : prime256v1
41!Alias id-ecSigType ansi-X9-62 4
42!global
43X9-62_id-ecSigType 1 : ecdsa-with-SHA1
44
45
46
47ISO-US 113533 7 66 10 : CAST5-CBC : cast5-cbc
48 : CAST5-ECB : cast5-ecb
49!Cname cast5-cfb64
50 : CAST5-CFB : cast5-cfb
51!Cname cast5-ofb64
52 : CAST5-OFB : cast5-ofb
53!Cname pbeWithMD5AndCast5-CBC
54ISO-US 113533 7 66 12 : : pbeWithMD5AndCast5CBC
55
56ISO-US 113549 : rsadsi : RSA Data Security, Inc.
57
58rsadsi 1 : pkcs : RSA Data Security, Inc. PKCS
59
60pkcs 1 : pkcs1
61pkcs1 1 : : rsaEncryption
62pkcs1 2 : RSA-MD2 : md2WithRSAEncryption
63pkcs1 3 : RSA-MD4 : md4WithRSAEncryption
64pkcs1 4 : RSA-MD5 : md5WithRSAEncryption
65pkcs1 5 : RSA-SHA1 : sha1WithRSAEncryption
66# According to PKCS #1 version 2.1
67pkcs1 11 : RSA-SHA256 : sha256WithRSAEncryption
68pkcs1 12 : RSA-SHA384 : sha384WithRSAEncryption
69pkcs1 13 : RSA-SHA512 : sha512WithRSAEncryption
70pkcs1 14 : RSA-SHA224 : sha224WithRSAEncryption
71
72pkcs 3 : pkcs3
73pkcs3 1 : : dhKeyAgreement
74
75pkcs 5 : pkcs5
76pkcs5 1 : PBE-MD2-DES : pbeWithMD2AndDES-CBC
77pkcs5 3 : PBE-MD5-DES : pbeWithMD5AndDES-CBC
78pkcs5 4 : PBE-MD2-RC2-64 : pbeWithMD2AndRC2-CBC
79pkcs5 6 : PBE-MD5-RC2-64 : pbeWithMD5AndRC2-CBC
80pkcs5 10 : PBE-SHA1-DES : pbeWithSHA1AndDES-CBC
81pkcs5 11 : PBE-SHA1-RC2-64 : pbeWithSHA1AndRC2-CBC
82!Cname id_pbkdf2
83pkcs5 12 : : PBKDF2
84!Cname pbes2
85pkcs5 13 : : PBES2
86!Cname pbmac1
87pkcs5 14 : : PBMAC1
88
89pkcs 7 : pkcs7
90pkcs7 1 : : pkcs7-data
91!Cname pkcs7-signed
92pkcs7 2 : : pkcs7-signedData
93!Cname pkcs7-enveloped
94pkcs7 3 : : pkcs7-envelopedData
95!Cname pkcs7-signedAndEnveloped
96pkcs7 4 : : pkcs7-signedAndEnvelopedData
97!Cname pkcs7-digest
98pkcs7 5 : : pkcs7-digestData
99!Cname pkcs7-encrypted
100pkcs7 6 : : pkcs7-encryptedData
101
102pkcs 9 : pkcs9
103!module pkcs9
104pkcs9 1 : : emailAddress
105pkcs9 2 : : unstructuredName
106pkcs9 3 : : contentType
107pkcs9 4 : : messageDigest
108pkcs9 5 : : signingTime
109pkcs9 6 : : countersignature
110pkcs9 7 : : challengePassword
111pkcs9 8 : : unstructuredAddress
112!Cname extCertAttributes
113pkcs9 9 : : extendedCertificateAttributes
114!global
115
116!Cname ext-req
117pkcs9 14 : extReq : Extension Request
118
119!Cname SMIMECapabilities
120pkcs9 15 : SMIME-CAPS : S/MIME Capabilities
121
122# S/MIME
123!Cname SMIME
124pkcs9 16 : SMIME : S/MIME
125SMIME 0 : id-smime-mod
126SMIME 1 : id-smime-ct
127SMIME 2 : id-smime-aa
128SMIME 3 : id-smime-alg
129SMIME 4 : id-smime-cd
130SMIME 5 : id-smime-spq
131SMIME 6 : id-smime-cti
132
133# S/MIME Modules
134id-smime-mod 1 : id-smime-mod-cms
135id-smime-mod 2 : id-smime-mod-ess
136id-smime-mod 3 : id-smime-mod-oid
137id-smime-mod 4 : id-smime-mod-msg-v3
138id-smime-mod 5 : id-smime-mod-ets-eSignature-88
139id-smime-mod 6 : id-smime-mod-ets-eSignature-97
140id-smime-mod 7 : id-smime-mod-ets-eSigPolicy-88
141id-smime-mod 8 : id-smime-mod-ets-eSigPolicy-97
142
143# S/MIME Content Types
144id-smime-ct 1 : id-smime-ct-receipt
145id-smime-ct 2 : id-smime-ct-authData
146id-smime-ct 3 : id-smime-ct-publishCert
147id-smime-ct 4 : id-smime-ct-TSTInfo
148id-smime-ct 5 : id-smime-ct-TDTInfo
149id-smime-ct 6 : id-smime-ct-contentInfo
150id-smime-ct 7 : id-smime-ct-DVCSRequestData
151id-smime-ct 8 : id-smime-ct-DVCSResponseData
152
153# S/MIME Attributes
154id-smime-aa 1 : id-smime-aa-receiptRequest
155id-smime-aa 2 : id-smime-aa-securityLabel
156id-smime-aa 3 : id-smime-aa-mlExpandHistory
157id-smime-aa 4 : id-smime-aa-contentHint
158id-smime-aa 5 : id-smime-aa-msgSigDigest
159# obsolete
160id-smime-aa 6 : id-smime-aa-encapContentType
161id-smime-aa 7 : id-smime-aa-contentIdentifier
162# obsolete
163id-smime-aa 8 : id-smime-aa-macValue
164id-smime-aa 9 : id-smime-aa-equivalentLabels
165id-smime-aa 10 : id-smime-aa-contentReference
166id-smime-aa 11 : id-smime-aa-encrypKeyPref
167id-smime-aa 12 : id-smime-aa-signingCertificate
168id-smime-aa 13 : id-smime-aa-smimeEncryptCerts
169id-smime-aa 14 : id-smime-aa-timeStampToken
170id-smime-aa 15 : id-smime-aa-ets-sigPolicyId
171id-smime-aa 16 : id-smime-aa-ets-commitmentType
172id-smime-aa 17 : id-smime-aa-ets-signerLocation
173id-smime-aa 18 : id-smime-aa-ets-signerAttr
174id-smime-aa 19 : id-smime-aa-ets-otherSigCert
175id-smime-aa 20 : id-smime-aa-ets-contentTimestamp
176id-smime-aa 21 : id-smime-aa-ets-CertificateRefs
177id-smime-aa 22 : id-smime-aa-ets-RevocationRefs
178id-smime-aa 23 : id-smime-aa-ets-certValues
179id-smime-aa 24 : id-smime-aa-ets-revocationValues
180id-smime-aa 25 : id-smime-aa-ets-escTimeStamp
181id-smime-aa 26 : id-smime-aa-ets-certCRLTimestamp
182id-smime-aa 27 : id-smime-aa-ets-archiveTimeStamp
183id-smime-aa 28 : id-smime-aa-signatureType
184id-smime-aa 29 : id-smime-aa-dvcs-dvc
185
186# S/MIME Algorithm Identifiers
187# obsolete
188id-smime-alg 1 : id-smime-alg-ESDHwith3DES
189# obsolete
190id-smime-alg 2 : id-smime-alg-ESDHwithRC2
191# obsolete
192id-smime-alg 3 : id-smime-alg-3DESwrap
193# obsolete
194id-smime-alg 4 : id-smime-alg-RC2wrap
195id-smime-alg 5 : id-smime-alg-ESDH
196id-smime-alg 6 : id-smime-alg-CMS3DESwrap
197id-smime-alg 7 : id-smime-alg-CMSRC2wrap
198
199# S/MIME Certificate Distribution
200id-smime-cd 1 : id-smime-cd-ldap
201
202# S/MIME Signature Policy Qualifier
203id-smime-spq 1 : id-smime-spq-ets-sqt-uri
204id-smime-spq 2 : id-smime-spq-ets-sqt-unotice
205
206# S/MIME Commitment Type Identifier
207id-smime-cti 1 : id-smime-cti-ets-proofOfOrigin
208id-smime-cti 2 : id-smime-cti-ets-proofOfReceipt
209id-smime-cti 3 : id-smime-cti-ets-proofOfDelivery
210id-smime-cti 4 : id-smime-cti-ets-proofOfSender
211id-smime-cti 5 : id-smime-cti-ets-proofOfApproval
212id-smime-cti 6 : id-smime-cti-ets-proofOfCreation
213
214pkcs9 20 : : friendlyName
215pkcs9 21 : : localKeyID
216!Cname ms-csp-name
2171 3 6 1 4 1 311 17 1 : CSPName : Microsoft CSP Name
218!Alias certTypes pkcs9 22
219certTypes 1 : : x509Certificate
220certTypes 2 : : sdsiCertificate
221!Alias crlTypes pkcs9 23
222crlTypes 1 : : x509Crl
223
224!Alias pkcs12 pkcs 12
225!Alias pkcs12-pbeids pkcs12 1
226
227!Cname pbe-WithSHA1And128BitRC4
228pkcs12-pbeids 1 : PBE-SHA1-RC4-128 : pbeWithSHA1And128BitRC4
229!Cname pbe-WithSHA1And40BitRC4
230pkcs12-pbeids 2 : PBE-SHA1-RC4-40 : pbeWithSHA1And40BitRC4
231!Cname pbe-WithSHA1And3_Key_TripleDES-CBC
232pkcs12-pbeids 3 : PBE-SHA1-3DES : pbeWithSHA1And3-KeyTripleDES-CBC
233!Cname pbe-WithSHA1And2_Key_TripleDES-CBC
234pkcs12-pbeids 4 : PBE-SHA1-2DES : pbeWithSHA1And2-KeyTripleDES-CBC
235!Cname pbe-WithSHA1And128BitRC2-CBC
236pkcs12-pbeids 5 : PBE-SHA1-RC2-128 : pbeWithSHA1And128BitRC2-CBC
237!Cname pbe-WithSHA1And40BitRC2-CBC
238pkcs12-pbeids 6 : PBE-SHA1-RC2-40 : pbeWithSHA1And40BitRC2-CBC
239
240!Alias pkcs12-Version1 pkcs12 10
241!Alias pkcs12-BagIds pkcs12-Version1 1
242pkcs12-BagIds 1 : : keyBag
243pkcs12-BagIds 2 : : pkcs8ShroudedKeyBag
244pkcs12-BagIds 3 : : certBag
245pkcs12-BagIds 4 : : crlBag
246pkcs12-BagIds 5 : : secretBag
247pkcs12-BagIds 6 : : safeContentsBag
248
249rsadsi 2 2 : MD2 : md2
250rsadsi 2 4 : MD4 : md4
251rsadsi 2 5 : MD5 : md5
252 : MD5-SHA1 : md5-sha1
253rsadsi 2 7 : : hmacWithSHA1
254rsadsi 3 2 : RC2-CBC : rc2-cbc
255 : RC2-ECB : rc2-ecb
256!Cname rc2-cfb64
257 : RC2-CFB : rc2-cfb
258!Cname rc2-ofb64
259 : RC2-OFB : rc2-ofb
260 : RC2-40-CBC : rc2-40-cbc
261 : RC2-64-CBC : rc2-64-cbc
262rsadsi 3 4 : RC4 : rc4
263 : RC4-40 : rc4-40
264rsadsi 3 7 : DES-EDE3-CBC : des-ede3-cbc
265rsadsi 3 8 : RC5-CBC : rc5-cbc
266 : RC5-ECB : rc5-ecb
267!Cname rc5-cfb64
268 : RC5-CFB : rc5-cfb
269!Cname rc5-ofb64
270 : RC5-OFB : rc5-ofb
271
272!Cname ms-ext-req
2731 3 6 1 4 1 311 2 1 14 : msExtReq : Microsoft Extension Request
274!Cname ms-code-ind
2751 3 6 1 4 1 311 2 1 21 : msCodeInd : Microsoft Individual Code Signing
276!Cname ms-code-com
2771 3 6 1 4 1 311 2 1 22 : msCodeCom : Microsoft Commercial Code Signing
278!Cname ms-ctl-sign
2791 3 6 1 4 1 311 10 3 1 : msCTLSign : Microsoft Trust List Signing
280!Cname ms-sgc
2811 3 6 1 4 1 311 10 3 3 : msSGC : Microsoft Server Gated Crypto
282!Cname ms-efs
2831 3 6 1 4 1 311 10 3 4 : msEFS : Microsoft Encrypted File System
284!Cname ms-smartcard-login
2851 3 6 1 4 1 311 20 2 2 : msSmartcardLogin : Microsoft Smartcardlogin
286!Cname ms-upn
2871 3 6 1 4 1 311 20 2 3 : msUPN : Microsoft Universal Principal Name
288
2891 3 6 1 4 1 188 7 1 1 2 : IDEA-CBC : idea-cbc
290 : IDEA-ECB : idea-ecb
291!Cname idea-cfb64
292 : IDEA-CFB : idea-cfb
293!Cname idea-ofb64
294 : IDEA-OFB : idea-ofb
295
2961 3 6 1 4 1 3029 1 2 : BF-CBC : bf-cbc
297 : BF-ECB : bf-ecb
298!Cname bf-cfb64
299 : BF-CFB : bf-cfb
300!Cname bf-ofb64
301 : BF-OFB : bf-ofb
302
303!Cname id-pkix
3041 3 6 1 5 5 7 : PKIX
305
306# PKIX Arcs
307id-pkix 0 : id-pkix-mod
308id-pkix 1 : id-pe
309id-pkix 2 : id-qt
310id-pkix 3 : id-kp
311id-pkix 4 : id-it
312id-pkix 5 : id-pkip
313id-pkix 6 : id-alg
314id-pkix 7 : id-cmc
315id-pkix 8 : id-on
316id-pkix 9 : id-pda
317id-pkix 10 : id-aca
318id-pkix 11 : id-qcs
319id-pkix 12 : id-cct
320id-pkix 21 : id-ppl
321id-pkix 48 : id-ad
322
323# PKIX Modules
324id-pkix-mod 1 : id-pkix1-explicit-88
325id-pkix-mod 2 : id-pkix1-implicit-88
326id-pkix-mod 3 : id-pkix1-explicit-93
327id-pkix-mod 4 : id-pkix1-implicit-93
328id-pkix-mod 5 : id-mod-crmf
329id-pkix-mod 6 : id-mod-cmc
330id-pkix-mod 7 : id-mod-kea-profile-88
331id-pkix-mod 8 : id-mod-kea-profile-93
332id-pkix-mod 9 : id-mod-cmp
333id-pkix-mod 10 : id-mod-qualified-cert-88
334id-pkix-mod 11 : id-mod-qualified-cert-93
335id-pkix-mod 12 : id-mod-attribute-cert
336id-pkix-mod 13 : id-mod-timestamp-protocol
337id-pkix-mod 14 : id-mod-ocsp
338id-pkix-mod 15 : id-mod-dvcs
339id-pkix-mod 16 : id-mod-cmp2000
340
341# PKIX Private Extensions
342!Cname info-access
343id-pe 1 : authorityInfoAccess : Authority Information Access
344id-pe 2 : biometricInfo : Biometric Info
345id-pe 3 : qcStatements
346id-pe 4 : ac-auditEntity
347id-pe 5 : ac-targeting
348id-pe 6 : aaControls
349id-pe 7 : sbgp-ipAddrBlock
350id-pe 8 : sbgp-autonomousSysNum
351id-pe 9 : sbgp-routerIdentifier
352id-pe 10 : ac-proxying
353!Cname sinfo-access
354id-pe 11 : subjectInfoAccess : Subject Information Access
355id-pe 14 : proxyCertInfo : Proxy Certificate Information
356
357# PKIX policyQualifiers for Internet policy qualifiers
358id-qt 1 : id-qt-cps : Policy Qualifier CPS
359id-qt 2 : id-qt-unotice : Policy Qualifier User Notice
360id-qt 3 : textNotice
361
362# PKIX key purpose identifiers
363!Cname server-auth
364id-kp 1 : serverAuth : TLS Web Server Authentication
365!Cname client-auth
366id-kp 2 : clientAuth : TLS Web Client Authentication
367!Cname code-sign
368id-kp 3 : codeSigning : Code Signing
369!Cname email-protect
370id-kp 4 : emailProtection : E-mail Protection
371id-kp 5 : ipsecEndSystem : IPSec End System
372id-kp 6 : ipsecTunnel : IPSec Tunnel
373id-kp 7 : ipsecUser : IPSec User
374!Cname time-stamp
375id-kp 8 : timeStamping : Time Stamping
376# From OCSP spec RFC2560
377!Cname OCSP-sign
378id-kp 9 : OCSPSigning : OCSP Signing
379id-kp 10 : DVCS : dvcs
380
381# CMP information types
382id-it 1 : id-it-caProtEncCert
383id-it 2 : id-it-signKeyPairTypes
384id-it 3 : id-it-encKeyPairTypes
385id-it 4 : id-it-preferredSymmAlg
386id-it 5 : id-it-caKeyUpdateInfo
387id-it 6 : id-it-currentCRL
388id-it 7 : id-it-unsupportedOIDs
389# obsolete
390id-it 8 : id-it-subscriptionRequest
391# obsolete
392id-it 9 : id-it-subscriptionResponse
393id-it 10 : id-it-keyPairParamReq
394id-it 11 : id-it-keyPairParamRep
395id-it 12 : id-it-revPassphrase
396id-it 13 : id-it-implicitConfirm
397id-it 14 : id-it-confirmWaitTime
398id-it 15 : id-it-origPKIMessage
399
400# CRMF registration
401id-pkip 1 : id-regCtrl
402id-pkip 2 : id-regInfo
403
404# CRMF registration controls
405id-regCtrl 1 : id-regCtrl-regToken
406id-regCtrl 2 : id-regCtrl-authenticator
407id-regCtrl 3 : id-regCtrl-pkiPublicationInfo
408id-regCtrl 4 : id-regCtrl-pkiArchiveOptions
409id-regCtrl 5 : id-regCtrl-oldCertID
410id-regCtrl 6 : id-regCtrl-protocolEncrKey
411
412# CRMF registration information
413id-regInfo 1 : id-regInfo-utf8Pairs
414id-regInfo 2 : id-regInfo-certReq
415
416# algorithms
417id-alg 1 : id-alg-des40
418id-alg 2 : id-alg-noSignature
419id-alg 3 : id-alg-dh-sig-hmac-sha1
420id-alg 4 : id-alg-dh-pop
421
422# CMC controls
423id-cmc 1 : id-cmc-statusInfo
424id-cmc 2 : id-cmc-identification
425id-cmc 3 : id-cmc-identityProof
426id-cmc 4 : id-cmc-dataReturn
427id-cmc 5 : id-cmc-transactionId
428id-cmc 6 : id-cmc-senderNonce
429id-cmc 7 : id-cmc-recipientNonce
430id-cmc 8 : id-cmc-addExtensions
431id-cmc 9 : id-cmc-encryptedPOP
432id-cmc 10 : id-cmc-decryptedPOP
433id-cmc 11 : id-cmc-lraPOPWitness
434id-cmc 15 : id-cmc-getCert
435id-cmc 16 : id-cmc-getCRL
436id-cmc 17 : id-cmc-revokeRequest
437id-cmc 18 : id-cmc-regInfo
438id-cmc 19 : id-cmc-responseInfo
439id-cmc 21 : id-cmc-queryPending
440id-cmc 22 : id-cmc-popLinkRandom
441id-cmc 23 : id-cmc-popLinkWitness
442id-cmc 24 : id-cmc-confirmCertAcceptance
443
444# other names
445id-on 1 : id-on-personalData
446
447# personal data attributes
448id-pda 1 : id-pda-dateOfBirth
449id-pda 2 : id-pda-placeOfBirth
450id-pda 3 : id-pda-gender
451id-pda 4 : id-pda-countryOfCitizenship
452id-pda 5 : id-pda-countryOfResidence
453
454# attribute certificate attributes
455id-aca 1 : id-aca-authenticationInfo
456id-aca 2 : id-aca-accessIdentity
457id-aca 3 : id-aca-chargingIdentity
458id-aca 4 : id-aca-group
459# attention : the following seems to be obsolete, replace by 'role'
460id-aca 5 : id-aca-role
461id-aca 6 : id-aca-encAttrs
462
463# qualified certificate statements
464id-qcs 1 : id-qcs-pkixQCSyntax-v1
465
466# CMC content types
467id-cct 1 : id-cct-crs
468id-cct 2 : id-cct-PKIData
469id-cct 3 : id-cct-PKIResponse
470
471# Predefined Proxy Certificate policy languages
472id-ppl 0 : id-ppl-anyLanguage : Any language
473id-ppl 1 : id-ppl-inheritAll : Inherit all
474id-ppl 2 : id-ppl-independent : Independent
475
476# access descriptors for authority info access extension
477!Cname ad-OCSP
478id-ad 1 : OCSP : OCSP
479!Cname ad-ca-issuers
480id-ad 2 : caIssuers : CA Issuers
481!Cname ad-timeStamping
482id-ad 3 : ad_timestamping : AD Time Stamping
483!Cname ad-dvcs
484id-ad 4 : AD_DVCS : ad dvcs
485
486
487!Alias id-pkix-OCSP ad-OCSP
488!module id-pkix-OCSP
489!Cname basic
490id-pkix-OCSP 1 : basicOCSPResponse : Basic OCSP Response
491id-pkix-OCSP 2 : Nonce : OCSP Nonce
492id-pkix-OCSP 3 : CrlID : OCSP CRL ID
493id-pkix-OCSP 4 : acceptableResponses : Acceptable OCSP Responses
494id-pkix-OCSP 5 : noCheck : OCSP No Check
495id-pkix-OCSP 6 : archiveCutoff : OCSP Archive Cutoff
496id-pkix-OCSP 7 : serviceLocator : OCSP Service Locator
497id-pkix-OCSP 8 : extendedStatus : Extended OCSP Status
498id-pkix-OCSP 9 : valid
499id-pkix-OCSP 10 : path
500id-pkix-OCSP 11 : trustRoot : Trust Root
501!global
502
5031 3 14 3 2 : algorithm : algorithm
504algorithm 3 : RSA-NP-MD5 : md5WithRSA
505algorithm 6 : DES-ECB : des-ecb
506algorithm 7 : DES-CBC : des-cbc
507!Cname des-ofb64
508algorithm 8 : DES-OFB : des-ofb
509!Cname des-cfb64
510algorithm 9 : DES-CFB : des-cfb
511algorithm 11 : rsaSignature
512!Cname dsa-2
513algorithm 12 : DSA-old : dsaEncryption-old
514algorithm 13 : DSA-SHA : dsaWithSHA
515algorithm 15 : RSA-SHA : shaWithRSAEncryption
516!Cname des-ede-ecb
517algorithm 17 : DES-EDE : des-ede
518!Cname des-ede3-ecb
519 : DES-EDE3 : des-ede3
520 : DES-EDE-CBC : des-ede-cbc
521!Cname des-ede-cfb64
522 : DES-EDE-CFB : des-ede-cfb
523!Cname des-ede3-cfb64
524 : DES-EDE3-CFB : des-ede3-cfb
525!Cname des-ede-ofb64
526 : DES-EDE-OFB : des-ede-ofb
527!Cname des-ede3-ofb64
528 : DES-EDE3-OFB : des-ede3-ofb
529 : DESX-CBC : desx-cbc
530algorithm 18 : SHA : sha
531algorithm 26 : SHA1 : sha1
532!Cname dsaWithSHA1-2
533algorithm 27 : DSA-SHA1-old : dsaWithSHA1-old
534algorithm 29 : RSA-SHA1-2 : sha1WithRSA
535
5361 3 36 3 2 1 : RIPEMD160 : ripemd160
5371 3 36 3 3 1 2 : RSA-RIPEMD160 : ripemd160WithRSA
538
539!Cname sxnet
5401 3 101 1 4 1 : SXNetID : Strong Extranet ID
541
5422 5 : X500 : directory services (X.500)
543
544X500 4 : X509
545X509 3 : CN : commonName
546X509 4 : SN : surname
547X509 5 : : serialNumber
548X509 6 : C : countryName
549X509 7 : L : localityName
550X509 8 : ST : stateOrProvinceName
551X509 9 : : streetAddress
552X509 10 : O : organizationName
553X509 11 : OU : organizationalUnitName
554X509 12 : : title
555X509 13 : : description
556X509 17 : : postalCode
557X509 41 : name : name
558X509 42 : GN : givenName
559X509 43 : : initials
560X509 44 : : generationQualifier
561X509 45 : : x500UniqueIdentifier
562X509 46 : dnQualifier : dnQualifier
563X509 65 : : pseudonym
564X509 72 : role : role
565
566X500 8 : X500algorithms : directory services - algorithms
567X500algorithms 1 1 : RSA : rsa
568X500algorithms 3 100 : RSA-MDC2 : mdc2WithRSA
569X500algorithms 3 101 : MDC2 : mdc2
570
571X500 29 : id-ce
572!Cname subject-key-identifier
573id-ce 14 : subjectKeyIdentifier : X509v3 Subject Key Identifier
574!Cname key-usage
575id-ce 15 : keyUsage : X509v3 Key Usage
576!Cname private-key-usage-period
577id-ce 16 : privateKeyUsagePeriod : X509v3 Private Key Usage Period
578!Cname subject-alt-name
579id-ce 17 : subjectAltName : X509v3 Subject Alternative Name
580!Cname issuer-alt-name
581id-ce 18 : issuerAltName : X509v3 Issuer Alternative Name
582!Cname basic-constraints
583id-ce 19 : basicConstraints : X509v3 Basic Constraints
584!Cname crl-number
585id-ce 20 : crlNumber : X509v3 CRL Number
586!Cname crl-reason
587id-ce 21 : CRLReason : X509v3 CRL Reason Code
588!Cname invalidity-date
589id-ce 24 : invalidityDate : Invalidity Date
590!Cname delta-crl
591id-ce 27 : deltaCRL : X509v3 Delta CRL Indicator
592!Cname name-constraints
593id-ce 30 : nameConstraints : X509v3 Name Constraints
594!Cname crl-distribution-points
595id-ce 31 : crlDistributionPoints : X509v3 CRL Distribution Points
596!Cname certificate-policies
597id-ce 32 : certificatePolicies : X509v3 Certificate Policies
598!Cname authority-key-identifier
599id-ce 35 : authorityKeyIdentifier : X509v3 Authority Key Identifier
600!Cname policy-constraints
601id-ce 36 : policyConstraints : X509v3 Policy Constraints
602!Cname ext-key-usage
603id-ce 37 : extendedKeyUsage : X509v3 Extended Key Usage
604!Cname target-information
605id-ce 55 : targetInformation : X509v3 AC Targeting
606!Cname no-rev-avail
607id-ce 56 : noRevAvail : X509v3 No Revocation Available
608
609!Cname netscape
6102 16 840 1 113730 : Netscape : Netscape Communications Corp.
611!Cname netscape-cert-extension
612netscape 1 : nsCertExt : Netscape Certificate Extension
613!Cname netscape-data-type
614netscape 2 : nsDataType : Netscape Data Type
615!Cname netscape-cert-type
616netscape-cert-extension 1 : nsCertType : Netscape Cert Type
617!Cname netscape-base-url
618netscape-cert-extension 2 : nsBaseUrl : Netscape Base Url
619!Cname netscape-revocation-url
620netscape-cert-extension 3 : nsRevocationUrl : Netscape Revocation Url
621!Cname netscape-ca-revocation-url
622netscape-cert-extension 4 : nsCaRevocationUrl : Netscape CA Revocation Url
623!Cname netscape-renewal-url
624netscape-cert-extension 7 : nsRenewalUrl : Netscape Renewal Url
625!Cname netscape-ca-policy-url
626netscape-cert-extension 8 : nsCaPolicyUrl : Netscape CA Policy Url
627!Cname netscape-ssl-server-name
628netscape-cert-extension 12 : nsSslServerName : Netscape SSL Server Name
629!Cname netscape-comment
630netscape-cert-extension 13 : nsComment : Netscape Comment
631!Cname netscape-cert-sequence
632netscape-data-type 5 : nsCertSequence : Netscape Certificate Sequence
633!Cname ns-sgc
634netscape 4 1 : nsSGC : Netscape Server Gated Crypto
635
636# iso(1)
637iso 3 : ORG : org
638org 6 : DOD : dod
639dod 1 : IANA : iana
640!Alias internet iana
641
642internet 1 : directory : Directory
643internet 2 : mgmt : Management
644internet 3 : experimental : Experimental
645internet 4 : private : Private
646internet 5 : security : Security
647internet 6 : snmpv2 : SNMPv2
648# Documents refer to "internet 7" as "mail". This however leads to ambiguities
649# with RFC2798, Section 9.1.3, where "mail" is defined as the short name for
650# rfc822Mailbox. The short name is therefore here left out for a reason.
651# Subclasses of "mail", e.g. "MIME MHS" don't consitute a problem, as
652# references are realized via long name "Mail" (with capital M).
653internet 7 : : Mail
654
655Private 1 : enterprises : Enterprises
656
657# RFC 2247
658Enterprises 1466 344 : dcobject : dcObject
659
660# RFC 1495
661Mail 1 : mime-mhs : MIME MHS
662mime-mhs 1 : mime-mhs-headings : mime-mhs-headings
663mime-mhs 2 : mime-mhs-bodies : mime-mhs-bodies
664mime-mhs-headings 1 : id-hex-partial-message : id-hex-partial-message
665mime-mhs-headings 2 : id-hex-multipart-message : id-hex-multipart-message
666
667# What the hell are these OIDs, really?
668!Cname rle-compression
6691 1 1 1 666 1 : RLE : run length compression
670!Cname zlib-compression
6711 1 1 1 666 2 : ZLIB : zlib compression
672
673# AES aka Rijndael
674
675!Alias csor 2 16 840 1 101 3
676!Alias nistAlgorithms csor 4
677!Alias aes nistAlgorithms 1
678
679aes 1 : AES-128-ECB : aes-128-ecb
680aes 2 : AES-128-CBC : aes-128-cbc
681!Cname aes-128-ofb128
682aes 3 : AES-128-OFB : aes-128-ofb
683!Cname aes-128-cfb128
684aes 4 : AES-128-CFB : aes-128-cfb
685
686aes 21 : AES-192-ECB : aes-192-ecb
687aes 22 : AES-192-CBC : aes-192-cbc
688!Cname aes-192-ofb128
689aes 23 : AES-192-OFB : aes-192-ofb
690!Cname aes-192-cfb128
691aes 24 : AES-192-CFB : aes-192-cfb
692
693aes 41 : AES-256-ECB : aes-256-ecb
694aes 42 : AES-256-CBC : aes-256-cbc
695!Cname aes-256-ofb128
696aes 43 : AES-256-OFB : aes-256-ofb
697!Cname aes-256-cfb128
698aes 44 : AES-256-CFB : aes-256-cfb
699
700# There are no OIDs for these modes...
701
702 : AES-128-CFB1 : aes-128-cfb1
703 : AES-192-CFB1 : aes-192-cfb1
704 : AES-256-CFB1 : aes-256-cfb1
705 : AES-128-CFB8 : aes-128-cfb8
706 : AES-192-CFB8 : aes-192-cfb8
707 : AES-256-CFB8 : aes-256-cfb8
708 : DES-CFB1 : des-cfb1
709 : DES-CFB8 : des-cfb8
710 : DES-EDE3-CFB1 : des-ede3-cfb1
711 : DES-EDE3-CFB8 : des-ede3-cfb8
712
713# OIDs for SHA224, SHA256, SHA385 and SHA512, according to x9.84.
714!Alias nist_hashalgs nistAlgorithms 2
715nist_hashalgs 1 : SHA256 : sha256
716nist_hashalgs 2 : SHA384 : sha384
717nist_hashalgs 3 : SHA512 : sha512
718nist_hashalgs 4 : SHA224 : sha224
719
720# Hold instruction CRL entry extension
721!Cname hold-instruction-code
722id-ce 23 : holdInstructionCode : Hold Instruction Code
723!Alias holdInstruction X9-57 2
724!Cname hold-instruction-none
725holdInstruction 1 : holdInstructionNone : Hold Instruction None
726!Cname hold-instruction-call-issuer
727holdInstruction 2 : holdInstructionCallIssuer : Hold Instruction Call Issuer
728!Cname hold-instruction-reject
729holdInstruction 3 : holdInstructionReject : Hold Instruction Reject
730
731# OID's from CCITT. Most of this is defined in RFC 1274. A couple of
732# them are also mentioned in RFC 2247
733ccitt 9 : data
734data 2342 : pss
735pss 19200300 : ucl
736ucl 100 : pilot
737pilot 1 : : pilotAttributeType
738pilot 3 : : pilotAttributeSyntax
739pilot 4 : : pilotObjectClass
740pilot 10 : : pilotGroups
741pilotAttributeSyntax 4 : : iA5StringSyntax
742pilotAttributeSyntax 5 : : caseIgnoreIA5StringSyntax
743pilotObjectClass 3 : : pilotObject
744pilotObjectClass 4 : : pilotPerson
745pilotObjectClass 5 : account
746pilotObjectClass 6 : document
747pilotObjectClass 7 : room
748pilotObjectClass 9 : : documentSeries
749pilotObjectClass 13 : domain : Domain
750pilotObjectClass 14 : : rFC822localPart
751pilotObjectClass 15 : : dNSDomain
752pilotObjectClass 17 : : domainRelatedObject
753pilotObjectClass 18 : : friendlyCountry
754pilotObjectClass 19 : : simpleSecurityObject
755pilotObjectClass 20 : : pilotOrganization
756pilotObjectClass 21 : : pilotDSA
757pilotObjectClass 22 : : qualityLabelledData
758pilotAttributeType 1 : UID : userId
759pilotAttributeType 2 : : textEncodedORAddress
760pilotAttributeType 3 : mail : rfc822Mailbox
761pilotAttributeType 4 : info
762pilotAttributeType 5 : : favouriteDrink
763pilotAttributeType 6 : : roomNumber
764pilotAttributeType 7 : photo
765pilotAttributeType 8 : : userClass
766pilotAttributeType 9 : host
767pilotAttributeType 10 : manager
768pilotAttributeType 11 : : documentIdentifier
769pilotAttributeType 12 : : documentTitle
770pilotAttributeType 13 : : documentVersion
771pilotAttributeType 14 : : documentAuthor
772pilotAttributeType 15 : : documentLocation
773pilotAttributeType 20 : : homeTelephoneNumber
774pilotAttributeType 21 : secretary
775pilotAttributeType 22 : : otherMailbox
776pilotAttributeType 23 : : lastModifiedTime
777pilotAttributeType 24 : : lastModifiedBy
778pilotAttributeType 25 : DC : domainComponent
779pilotAttributeType 26 : : aRecord
780pilotAttributeType 27 : : pilotAttributeType27
781pilotAttributeType 28 : : mXRecord
782pilotAttributeType 29 : : nSRecord
783pilotAttributeType 30 : : sOARecord
784pilotAttributeType 31 : : cNAMERecord
785pilotAttributeType 37 : : associatedDomain
786pilotAttributeType 38 : : associatedName
787pilotAttributeType 39 : : homePostalAddress
788pilotAttributeType 40 : : personalTitle
789pilotAttributeType 41 : : mobileTelephoneNumber
790pilotAttributeType 42 : : pagerTelephoneNumber
791pilotAttributeType 43 : : friendlyCountryName
792# The following clashes with 2.5.4.45, so commented away
793#pilotAttributeType 44 : uid : uniqueIdentifier
794pilotAttributeType 45 : : organizationalStatus
795pilotAttributeType 46 : : janetMailbox
796pilotAttributeType 47 : : mailPreferenceOption
797pilotAttributeType 48 : : buildingName
798pilotAttributeType 49 : : dSAQuality
799pilotAttributeType 50 : : singleLevelQuality
800pilotAttributeType 51 : : subtreeMinimumQuality
801pilotAttributeType 52 : : subtreeMaximumQuality
802pilotAttributeType 53 : : personalSignature
803pilotAttributeType 54 : : dITRedirect
804pilotAttributeType 55 : audio
805pilotAttributeType 56 : : documentPublisher
806
8072 23 42 : id-set : Secure Electronic Transactions
808
809id-set 0 : set-ctype : content types
810id-set 1 : set-msgExt : message extensions
811id-set 3 : set-attr
812id-set 5 : set-policy
813id-set 7 : set-certExt : certificate extensions
814id-set 8 : set-brand
815
816set-ctype 0 : setct-PANData
817set-ctype 1 : setct-PANToken
818set-ctype 2 : setct-PANOnly
819set-ctype 3 : setct-OIData
820set-ctype 4 : setct-PI
821set-ctype 5 : setct-PIData
822set-ctype 6 : setct-PIDataUnsigned
823set-ctype 7 : setct-HODInput
824set-ctype 8 : setct-AuthResBaggage
825set-ctype 9 : setct-AuthRevReqBaggage
826set-ctype 10 : setct-AuthRevResBaggage
827set-ctype 11 : setct-CapTokenSeq
828set-ctype 12 : setct-PInitResData
829set-ctype 13 : setct-PI-TBS
830set-ctype 14 : setct-PResData
831set-ctype 16 : setct-AuthReqTBS
832set-ctype 17 : setct-AuthResTBS
833set-ctype 18 : setct-AuthResTBSX
834set-ctype 19 : setct-AuthTokenTBS
835set-ctype 20 : setct-CapTokenData
836set-ctype 21 : setct-CapTokenTBS
837set-ctype 22 : setct-AcqCardCodeMsg
838set-ctype 23 : setct-AuthRevReqTBS
839set-ctype 24 : setct-AuthRevResData
840set-ctype 25 : setct-AuthRevResTBS
841set-ctype 26 : setct-CapReqTBS
842set-ctype 27 : setct-CapReqTBSX
843set-ctype 28 : setct-CapResData
844set-ctype 29 : setct-CapRevReqTBS
845set-ctype 30 : setct-CapRevReqTBSX
846set-ctype 31 : setct-CapRevResData
847set-ctype 32 : setct-CredReqTBS
848set-ctype 33 : setct-CredReqTBSX
849set-ctype 34 : setct-CredResData
850set-ctype 35 : setct-CredRevReqTBS
851set-ctype 36 : setct-CredRevReqTBSX
852set-ctype 37 : setct-CredRevResData
853set-ctype 38 : setct-PCertReqData
854set-ctype 39 : setct-PCertResTBS
855set-ctype 40 : setct-BatchAdminReqData
856set-ctype 41 : setct-BatchAdminResData
857set-ctype 42 : setct-CardCInitResTBS
858set-ctype 43 : setct-MeAqCInitResTBS
859set-ctype 44 : setct-RegFormResTBS
860set-ctype 45 : setct-CertReqData
861set-ctype 46 : setct-CertReqTBS
862set-ctype 47 : setct-CertResData
863set-ctype 48 : setct-CertInqReqTBS
864set-ctype 49 : setct-ErrorTBS
865set-ctype 50 : setct-PIDualSignedTBE
866set-ctype 51 : setct-PIUnsignedTBE
867set-ctype 52 : setct-AuthReqTBE
868set-ctype 53 : setct-AuthResTBE
869set-ctype 54 : setct-AuthResTBEX
870set-ctype 55 : setct-AuthTokenTBE
871set-ctype 56 : setct-CapTokenTBE
872set-ctype 57 : setct-CapTokenTBEX
873set-ctype 58 : setct-AcqCardCodeMsgTBE
874set-ctype 59 : setct-AuthRevReqTBE
875set-ctype 60 : setct-AuthRevResTBE
876set-ctype 61 : setct-AuthRevResTBEB
877set-ctype 62 : setct-CapReqTBE
878set-ctype 63 : setct-CapReqTBEX
879set-ctype 64 : setct-CapResTBE
880set-ctype 65 : setct-CapRevReqTBE
881set-ctype 66 : setct-CapRevReqTBEX
882set-ctype 67 : setct-CapRevResTBE
883set-ctype 68 : setct-CredReqTBE
884set-ctype 69 : setct-CredReqTBEX
885set-ctype 70 : setct-CredResTBE
886set-ctype 71 : setct-CredRevReqTBE
887set-ctype 72 : setct-CredRevReqTBEX
888set-ctype 73 : setct-CredRevResTBE
889set-ctype 74 : setct-BatchAdminReqTBE
890set-ctype 75 : setct-BatchAdminResTBE
891set-ctype 76 : setct-RegFormReqTBE
892set-ctype 77 : setct-CertReqTBE
893set-ctype 78 : setct-CertReqTBEX
894set-ctype 79 : setct-CertResTBE
895set-ctype 80 : setct-CRLNotificationTBS
896set-ctype 81 : setct-CRLNotificationResTBS
897set-ctype 82 : setct-BCIDistributionTBS
898
899set-msgExt 1 : setext-genCrypt : generic cryptogram
900set-msgExt 3 : setext-miAuth : merchant initiated auth
901set-msgExt 4 : setext-pinSecure
902set-msgExt 5 : setext-pinAny
903set-msgExt 7 : setext-track2
904set-msgExt 8 : setext-cv : additional verification
905
906set-policy 0 : set-policy-root
907
908set-certExt 0 : setCext-hashedRoot
909set-certExt 1 : setCext-certType
910set-certExt 2 : setCext-merchData
911set-certExt 3 : setCext-cCertRequired
912set-certExt 4 : setCext-tunneling
913set-certExt 5 : setCext-setExt
914set-certExt 6 : setCext-setQualf
915set-certExt 7 : setCext-PGWYcapabilities
916set-certExt 8 : setCext-TokenIdentifier
917set-certExt 9 : setCext-Track2Data
918set-certExt 10 : setCext-TokenType
919set-certExt 11 : setCext-IssuerCapabilities
920
921set-attr 0 : setAttr-Cert
922set-attr 1 : setAttr-PGWYcap : payment gateway capabilities
923set-attr 2 : setAttr-TokenType
924set-attr 3 : setAttr-IssCap : issuer capabilities
925
926setAttr-Cert 0 : set-rootKeyThumb
927setAttr-Cert 1 : set-addPolicy
928
929setAttr-TokenType 1 : setAttr-Token-EMV
930setAttr-TokenType 2 : setAttr-Token-B0Prime
931
932setAttr-IssCap 3 : setAttr-IssCap-CVM
933setAttr-IssCap 4 : setAttr-IssCap-T2
934setAttr-IssCap 5 : setAttr-IssCap-Sig
935
936setAttr-IssCap-CVM 1 : setAttr-GenCryptgrm : generate cryptogram
937setAttr-IssCap-T2 1 : setAttr-T2Enc : encrypted track 2
938setAttr-IssCap-T2 2 : setAttr-T2cleartxt : cleartext track 2
939
940setAttr-IssCap-Sig 1 : setAttr-TokICCsig : ICC or token signature
941setAttr-IssCap-Sig 2 : setAttr-SecDevSig : secure device signature
942
943set-brand 1 : set-brand-IATA-ATA
944set-brand 30 : set-brand-Diners
945set-brand 34 : set-brand-AmericanExpress
946set-brand 35 : set-brand-JCB
947set-brand 4 : set-brand-Visa
948set-brand 5 : set-brand-MasterCard
949set-brand 6011 : set-brand-Novus
950
951rsadsi 3 10 : DES-CDMF : des-cdmf
952rsadsi 1 1 6 : rsaOAEPEncryptionSET
diff --git a/src/lib/libcrypto/ocsp/ocsp.h b/src/lib/libcrypto/ocsp/ocsp.h
deleted file mode 100644
index fab3c03182..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp.h
+++ /dev/null
@@ -1,619 +0,0 @@
1/* ocsp.h */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#ifndef HEADER_OCSP_H
65#define HEADER_OCSP_H
66
67#include <openssl/x509.h>
68#include <openssl/x509v3.h>
69#include <openssl/safestack.h>
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75/* Various flags and values */
76
77#define OCSP_DEFAULT_NONCE_LENGTH 16
78
79#define OCSP_NOCERTS 0x1
80#define OCSP_NOINTERN 0x2
81#define OCSP_NOSIGS 0x4
82#define OCSP_NOCHAIN 0x8
83#define OCSP_NOVERIFY 0x10
84#define OCSP_NOEXPLICIT 0x20
85#define OCSP_NOCASIGN 0x40
86#define OCSP_NODELEGATED 0x80
87#define OCSP_NOCHECKS 0x100
88#define OCSP_TRUSTOTHER 0x200
89#define OCSP_RESPID_KEY 0x400
90#define OCSP_NOTIME 0x800
91
92/* CertID ::= SEQUENCE {
93 * hashAlgorithm AlgorithmIdentifier,
94 * issuerNameHash OCTET STRING, -- Hash of Issuer's DN
95 * issuerKeyHash OCTET STRING, -- Hash of Issuers public key (excluding the tag & length fields)
96 * serialNumber CertificateSerialNumber }
97 */
98typedef struct ocsp_cert_id_st
99 {
100 X509_ALGOR *hashAlgorithm;
101 ASN1_OCTET_STRING *issuerNameHash;
102 ASN1_OCTET_STRING *issuerKeyHash;
103 ASN1_INTEGER *serialNumber;
104 } OCSP_CERTID;
105
106DECLARE_STACK_OF(OCSP_CERTID)
107
108/* Request ::= SEQUENCE {
109 * reqCert CertID,
110 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL }
111 */
112typedef struct ocsp_one_request_st
113 {
114 OCSP_CERTID *reqCert;
115 STACK_OF(X509_EXTENSION) *singleRequestExtensions;
116 } OCSP_ONEREQ;
117
118DECLARE_STACK_OF(OCSP_ONEREQ)
119DECLARE_ASN1_SET_OF(OCSP_ONEREQ)
120
121
122/* TBSRequest ::= SEQUENCE {
123 * version [0] EXPLICIT Version DEFAULT v1,
124 * requestorName [1] EXPLICIT GeneralName OPTIONAL,
125 * requestList SEQUENCE OF Request,
126 * requestExtensions [2] EXPLICIT Extensions OPTIONAL }
127 */
128typedef struct ocsp_req_info_st
129 {
130 ASN1_INTEGER *version;
131 GENERAL_NAME *requestorName;
132 STACK_OF(OCSP_ONEREQ) *requestList;
133 STACK_OF(X509_EXTENSION) *requestExtensions;
134 } OCSP_REQINFO;
135
136/* Signature ::= SEQUENCE {
137 * signatureAlgorithm AlgorithmIdentifier,
138 * signature BIT STRING,
139 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
140 */
141typedef struct ocsp_signature_st
142 {
143 X509_ALGOR *signatureAlgorithm;
144 ASN1_BIT_STRING *signature;
145 STACK_OF(X509) *certs;
146 } OCSP_SIGNATURE;
147
148/* OCSPRequest ::= SEQUENCE {
149 * tbsRequest TBSRequest,
150 * optionalSignature [0] EXPLICIT Signature OPTIONAL }
151 */
152typedef struct ocsp_request_st
153 {
154 OCSP_REQINFO *tbsRequest;
155 OCSP_SIGNATURE *optionalSignature; /* OPTIONAL */
156 } OCSP_REQUEST;
157
158/* OCSPResponseStatus ::= ENUMERATED {
159 * successful (0), --Response has valid confirmations
160 * malformedRequest (1), --Illegal confirmation request
161 * internalError (2), --Internal error in issuer
162 * tryLater (3), --Try again later
163 * --(4) is not used
164 * sigRequired (5), --Must sign the request
165 * unauthorized (6) --Request unauthorized
166 * }
167 */
168#define OCSP_RESPONSE_STATUS_SUCCESSFUL 0
169#define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1
170#define OCSP_RESPONSE_STATUS_INTERNALERROR 2
171#define OCSP_RESPONSE_STATUS_TRYLATER 3
172#define OCSP_RESPONSE_STATUS_SIGREQUIRED 5
173#define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6
174
175/* ResponseBytes ::= SEQUENCE {
176 * responseType OBJECT IDENTIFIER,
177 * response OCTET STRING }
178 */
179typedef struct ocsp_resp_bytes_st
180 {
181 ASN1_OBJECT *responseType;
182 ASN1_OCTET_STRING *response;
183 } OCSP_RESPBYTES;
184
185/* OCSPResponse ::= SEQUENCE {
186 * responseStatus OCSPResponseStatus,
187 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
188 */
189typedef struct ocsp_response_st
190 {
191 ASN1_ENUMERATED *responseStatus;
192 OCSP_RESPBYTES *responseBytes;
193 } OCSP_RESPONSE;
194
195/* ResponderID ::= CHOICE {
196 * byName [1] Name,
197 * byKey [2] KeyHash }
198 */
199#define V_OCSP_RESPID_NAME 0
200#define V_OCSP_RESPID_KEY 1
201typedef struct ocsp_responder_id_st
202 {
203 int type;
204 union {
205 X509_NAME* byName;
206 ASN1_OCTET_STRING *byKey;
207 } value;
208 } OCSP_RESPID;
209/* KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key
210 * --(excluding the tag and length fields)
211 */
212
213/* RevokedInfo ::= SEQUENCE {
214 * revocationTime GeneralizedTime,
215 * revocationReason [0] EXPLICIT CRLReason OPTIONAL }
216 */
217typedef struct ocsp_revoked_info_st
218 {
219 ASN1_GENERALIZEDTIME *revocationTime;
220 ASN1_ENUMERATED *revocationReason;
221 } OCSP_REVOKEDINFO;
222
223/* CertStatus ::= CHOICE {
224 * good [0] IMPLICIT NULL,
225 * revoked [1] IMPLICIT RevokedInfo,
226 * unknown [2] IMPLICIT UnknownInfo }
227 */
228#define V_OCSP_CERTSTATUS_GOOD 0
229#define V_OCSP_CERTSTATUS_REVOKED 1
230#define V_OCSP_CERTSTATUS_UNKNOWN 2
231typedef struct ocsp_cert_status_st
232 {
233 int type;
234 union {
235 ASN1_NULL *good;
236 OCSP_REVOKEDINFO *revoked;
237 ASN1_NULL *unknown;
238 } value;
239 } OCSP_CERTSTATUS;
240
241/* SingleResponse ::= SEQUENCE {
242 * certID CertID,
243 * certStatus CertStatus,
244 * thisUpdate GeneralizedTime,
245 * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
246 * singleExtensions [1] EXPLICIT Extensions OPTIONAL }
247 */
248typedef struct ocsp_single_response_st
249 {
250 OCSP_CERTID *certId;
251 OCSP_CERTSTATUS *certStatus;
252 ASN1_GENERALIZEDTIME *thisUpdate;
253 ASN1_GENERALIZEDTIME *nextUpdate;
254 STACK_OF(X509_EXTENSION) *singleExtensions;
255 } OCSP_SINGLERESP;
256
257DECLARE_STACK_OF(OCSP_SINGLERESP)
258DECLARE_ASN1_SET_OF(OCSP_SINGLERESP)
259
260/* ResponseData ::= SEQUENCE {
261 * version [0] EXPLICIT Version DEFAULT v1,
262 * responderID ResponderID,
263 * producedAt GeneralizedTime,
264 * responses SEQUENCE OF SingleResponse,
265 * responseExtensions [1] EXPLICIT Extensions OPTIONAL }
266 */
267typedef struct ocsp_response_data_st
268 {
269 ASN1_INTEGER *version;
270 OCSP_RESPID *responderId;
271 ASN1_GENERALIZEDTIME *producedAt;
272 STACK_OF(OCSP_SINGLERESP) *responses;
273 STACK_OF(X509_EXTENSION) *responseExtensions;
274 } OCSP_RESPDATA;
275
276/* BasicOCSPResponse ::= SEQUENCE {
277 * tbsResponseData ResponseData,
278 * signatureAlgorithm AlgorithmIdentifier,
279 * signature BIT STRING,
280 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
281 */
282 /* Note 1:
283 The value for "signature" is specified in the OCSP rfc2560 as follows:
284 "The value for the signature SHALL be computed on the hash of the DER
285 encoding ResponseData." This means that you must hash the DER-encoded
286 tbsResponseData, and then run it through a crypto-signing function, which
287 will (at least w/RSA) do a hash-'n'-private-encrypt operation. This seems
288 a bit odd, but that's the spec. Also note that the data structures do not
289 leave anywhere to independently specify the algorithm used for the initial
290 hash. So, we look at the signature-specification algorithm, and try to do
291 something intelligent. -- Kathy Weinhold, CertCo */
292 /* Note 2:
293 It seems that the mentioned passage from RFC 2560 (section 4.2.1) is open
294 for interpretation. I've done tests against another responder, and found
295 that it doesn't do the double hashing that the RFC seems to say one
296 should. Therefore, all relevant functions take a flag saying which
297 variant should be used. -- Richard Levitte, OpenSSL team and CeloCom */
298typedef struct ocsp_basic_response_st
299 {
300 OCSP_RESPDATA *tbsResponseData;
301 X509_ALGOR *signatureAlgorithm;
302 ASN1_BIT_STRING *signature;
303 STACK_OF(X509) *certs;
304 } OCSP_BASICRESP;
305
306/*
307 * CRLReason ::= ENUMERATED {
308 * unspecified (0),
309 * keyCompromise (1),
310 * cACompromise (2),
311 * affiliationChanged (3),
312 * superseded (4),
313 * cessationOfOperation (5),
314 * certificateHold (6),
315 * removeFromCRL (8) }
316 */
317#define OCSP_REVOKED_STATUS_NOSTATUS -1
318#define OCSP_REVOKED_STATUS_UNSPECIFIED 0
319#define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1
320#define OCSP_REVOKED_STATUS_CACOMPROMISE 2
321#define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3
322#define OCSP_REVOKED_STATUS_SUPERSEDED 4
323#define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5
324#define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6
325#define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8
326
327/* CrlID ::= SEQUENCE {
328 * crlUrl [0] EXPLICIT IA5String OPTIONAL,
329 * crlNum [1] EXPLICIT INTEGER OPTIONAL,
330 * crlTime [2] EXPLICIT GeneralizedTime OPTIONAL }
331 */
332typedef struct ocsp_crl_id_st
333 {
334 ASN1_IA5STRING *crlUrl;
335 ASN1_INTEGER *crlNum;
336 ASN1_GENERALIZEDTIME *crlTime;
337 } OCSP_CRLID;
338
339/* ServiceLocator ::= SEQUENCE {
340 * issuer Name,
341 * locator AuthorityInfoAccessSyntax OPTIONAL }
342 */
343typedef struct ocsp_service_locator_st
344 {
345 X509_NAME* issuer;
346 STACK_OF(ACCESS_DESCRIPTION) *locator;
347 } OCSP_SERVICELOC;
348
349#define PEM_STRING_OCSP_REQUEST "OCSP REQUEST"
350#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE"
351
352#define d2i_OCSP_REQUEST_bio(bp,p) (OCSP_REQUEST*)ASN1_d2i_bio((char*(*)()) \
353 OCSP_REQUEST_new,(char *(*)())d2i_OCSP_REQUEST, (bp),\
354 (unsigned char **)(p))
355
356#define d2i_OCSP_RESPONSE_bio(bp,p) (OCSP_RESPONSE*)ASN1_d2i_bio((char*(*)())\
357 OCSP_REQUEST_new,(char *(*)())d2i_OCSP_RESPONSE, (bp),\
358 (unsigned char **)(p))
359
360#define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \
361 (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL)
362
363#define PEM_read_bio_OCSP_RESPONSE(bp,x,cb)(OCSP_RESPONSE *)PEM_ASN1_read_bio(\
364 (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,bp,(char **)x,cb,NULL)
365
366#define PEM_write_bio_OCSP_REQUEST(bp,o) \
367 PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\
368 bp,(char *)o, NULL,NULL,0,NULL,NULL)
369
370#define PEM_write_bio_OCSP_RESPONSE(bp,o) \
371 PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\
372 bp,(char *)o, NULL,NULL,0,NULL,NULL)
373
374#define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_RESPONSE,bp,\
375 (unsigned char *)o)
376
377#define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_REQUEST,bp,\
378 (unsigned char *)o)
379
380#define OCSP_REQUEST_sign(o,pkey,md) \
381 ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\
382 o->optionalSignature->signatureAlgorithm,NULL,\
383 o->optionalSignature->signature,o->tbsRequest,pkey,md)
384
385#define OCSP_BASICRESP_sign(o,pkey,md,d) \
386 ASN1_item_sign(ASN1_ITEM_rptr(OCSP_RESPDATA),o->signatureAlgorithm,NULL,\
387 o->signature,o->tbsResponseData,pkey,md)
388
389#define OCSP_REQUEST_verify(a,r) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_REQINFO),\
390 a->optionalSignature->signatureAlgorithm,\
391 a->optionalSignature->signature,a->tbsRequest,r)
392
393#define OCSP_BASICRESP_verify(a,r,d) ASN1_item_verify(ASN1_ITEM_rptr(OCSP_RESPDATA),\
394 a->signatureAlgorithm,a->signature,a->tbsResponseData,r)
395
396#define ASN1_BIT_STRING_digest(data,type,md,len) \
397 ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len)
398
399#define OCSP_CERTID_dup(cid) (OCSP_CERTID*)ASN1_dup((int(*)())i2d_OCSP_CERTID,\
400 (char *(*)())d2i_OCSP_CERTID,(char *)(cid))
401
402#define OCSP_CERTSTATUS_dup(cs)\
403 (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\
404 (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs))
405
406OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req);
407
408OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer);
409
410OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
411 X509_NAME *issuerName,
412 ASN1_BIT_STRING* issuerKey,
413 ASN1_INTEGER *serialNumber);
414
415OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid);
416
417int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len);
418int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len);
419int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs);
420int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req);
421
422int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm);
423int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert);
424
425int OCSP_request_sign(OCSP_REQUEST *req,
426 X509 *signer,
427 EVP_PKEY *key,
428 const EVP_MD *dgst,
429 STACK_OF(X509) *certs,
430 unsigned long flags);
431
432int OCSP_response_status(OCSP_RESPONSE *resp);
433OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp);
434
435int OCSP_resp_count(OCSP_BASICRESP *bs);
436OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);
437int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);
438int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
439 ASN1_GENERALIZEDTIME **revtime,
440 ASN1_GENERALIZEDTIME **thisupd,
441 ASN1_GENERALIZEDTIME **nextupd);
442int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
443 int *reason,
444 ASN1_GENERALIZEDTIME **revtime,
445 ASN1_GENERALIZEDTIME **thisupd,
446 ASN1_GENERALIZEDTIME **nextupd);
447int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
448 ASN1_GENERALIZEDTIME *nextupd,
449 long sec, long maxsec);
450
451int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags);
452
453int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl);
454
455int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b);
456int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b);
457
458int OCSP_request_onereq_count(OCSP_REQUEST *req);
459OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i);
460OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one);
461int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
462 ASN1_OCTET_STRING **pikeyHash,
463 ASN1_INTEGER **pserial, OCSP_CERTID *cid);
464int OCSP_request_is_signed(OCSP_REQUEST *req);
465OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs);
466OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,
467 OCSP_CERTID *cid,
468 int status, int reason,
469 ASN1_TIME *revtime,
470 ASN1_TIME *thisupd, ASN1_TIME *nextupd);
471int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert);
472int OCSP_basic_sign(OCSP_BASICRESP *brsp,
473 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
474 STACK_OF(X509) *certs, unsigned long flags);
475
476ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(),
477 char *data, STACK_OF(ASN1_OBJECT) *sk);
478
479X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim);
480
481X509_EXTENSION *OCSP_accept_responses_new(char **oids);
482
483X509_EXTENSION *OCSP_archive_cutoff_new(char* tim);
484
485X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls);
486
487int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x);
488int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos);
489int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos);
490int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos);
491X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc);
492X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc);
493void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx);
494int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
495 unsigned long flags);
496int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc);
497
498int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x);
499int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos);
500int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos);
501int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos);
502X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc);
503X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc);
504void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx);
505int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
506 unsigned long flags);
507int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc);
508
509int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x);
510int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos);
511int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos);
512int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos);
513X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc);
514X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc);
515void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx);
516int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,
517 unsigned long flags);
518int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc);
519
520int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x);
521int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos);
522int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos);
523int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos);
524X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc);
525X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc);
526void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx);
527int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,
528 unsigned long flags);
529int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc);
530
531DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP)
532DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS)
533DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)
534DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP)
535DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA)
536DECLARE_ASN1_FUNCTIONS(OCSP_RESPID)
537DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE)
538DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES)
539DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ)
540DECLARE_ASN1_FUNCTIONS(OCSP_CERTID)
541DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST)
542DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE)
543DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO)
544DECLARE_ASN1_FUNCTIONS(OCSP_CRLID)
545DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC)
546
547char *OCSP_response_status_str(long s);
548char *OCSP_cert_status_str(long s);
549char *OCSP_crl_reason_str(long s);
550
551int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* a, unsigned long flags);
552int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags);
553
554int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
555 X509_STORE *st, unsigned long flags);
556
557/* BEGIN ERROR CODES */
558/* The following lines are auto generated by the script mkerr.pl. Any changes
559 * made after this point may be overwritten when the script is next run.
560 */
561void ERR_load_OCSP_strings(void);
562
563/* Error codes for the OCSP functions. */
564
565/* Function codes. */
566#define OCSP_F_ASN1_STRING_ENCODE 100
567#define OCSP_F_CERT_ID_NEW 101
568#define OCSP_F_D2I_OCSP_NONCE 102
569#define OCSP_F_OCSP_BASIC_ADD1_STATUS 103
570#define OCSP_F_OCSP_BASIC_SIGN 104
571#define OCSP_F_OCSP_BASIC_VERIFY 105
572#define OCSP_F_OCSP_CHECK_DELEGATED 106
573#define OCSP_F_OCSP_CHECK_IDS 107
574#define OCSP_F_OCSP_CHECK_ISSUER 108
575#define OCSP_F_OCSP_CHECK_VALIDITY 115
576#define OCSP_F_OCSP_MATCH_ISSUERID 109
577#define OCSP_F_OCSP_PARSE_URL 114
578#define OCSP_F_OCSP_REQUEST_SIGN 110
579#define OCSP_F_OCSP_REQUEST_VERIFY 116
580#define OCSP_F_OCSP_RESPONSE_GET1_BASIC 111
581#define OCSP_F_OCSP_SENDREQ_BIO 112
582#define OCSP_F_REQUEST_VERIFY 113
583
584/* Reason codes. */
585#define OCSP_R_BAD_DATA 100
586#define OCSP_R_CERTIFICATE_VERIFY_ERROR 101
587#define OCSP_R_DIGEST_ERR 102
588#define OCSP_R_ERROR_IN_NEXTUPDATE_FIELD 122
589#define OCSP_R_ERROR_IN_THISUPDATE_FIELD 123
590#define OCSP_R_ERROR_PARSING_URL 121
591#define OCSP_R_MISSING_OCSPSIGNING_USAGE 103
592#define OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE 124
593#define OCSP_R_NOT_BASIC_RESPONSE 104
594#define OCSP_R_NO_CERTIFICATES_IN_CHAIN 105
595#define OCSP_R_NO_CONTENT 106
596#define OCSP_R_NO_PUBLIC_KEY 107
597#define OCSP_R_NO_RESPONSE_DATA 108
598#define OCSP_R_NO_REVOKED_TIME 109
599#define OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 110
600#define OCSP_R_REQUEST_NOT_SIGNED 128
601#define OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA 111
602#define OCSP_R_ROOT_CA_NOT_TRUSTED 112
603#define OCSP_R_SERVER_READ_ERROR 113
604#define OCSP_R_SERVER_RESPONSE_ERROR 114
605#define OCSP_R_SERVER_RESPONSE_PARSE_ERROR 115
606#define OCSP_R_SERVER_WRITE_ERROR 116
607#define OCSP_R_SIGNATURE_FAILURE 117
608#define OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND 118
609#define OCSP_R_STATUS_EXPIRED 125
610#define OCSP_R_STATUS_NOT_YET_VALID 126
611#define OCSP_R_STATUS_TOO_OLD 127
612#define OCSP_R_UNKNOWN_MESSAGE_DIGEST 119
613#define OCSP_R_UNKNOWN_NID 120
614#define OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE 129
615
616#ifdef __cplusplus
617}
618#endif
619#endif
diff --git a/src/lib/libcrypto/ocsp/ocsp_asn.c b/src/lib/libcrypto/ocsp/ocsp_asn.c
deleted file mode 100644
index 6a3a360d54..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_asn.c
+++ /dev/null
@@ -1,182 +0,0 @@
1/* ocsp_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#include <openssl/asn1.h>
59#include <openssl/asn1t.h>
60#include <openssl/ocsp.h>
61
62ASN1_SEQUENCE(OCSP_SIGNATURE) = {
63 ASN1_SIMPLE(OCSP_SIGNATURE, signatureAlgorithm, X509_ALGOR),
64 ASN1_SIMPLE(OCSP_SIGNATURE, signature, ASN1_BIT_STRING),
65 ASN1_EXP_SEQUENCE_OF(OCSP_SIGNATURE, certs, X509, 0)
66} ASN1_SEQUENCE_END(OCSP_SIGNATURE)
67
68IMPLEMENT_ASN1_FUNCTIONS(OCSP_SIGNATURE)
69
70ASN1_SEQUENCE(OCSP_CERTID) = {
71 ASN1_SIMPLE(OCSP_CERTID, hashAlgorithm, X509_ALGOR),
72 ASN1_SIMPLE(OCSP_CERTID, issuerNameHash, ASN1_OCTET_STRING),
73 ASN1_SIMPLE(OCSP_CERTID, issuerKeyHash, ASN1_OCTET_STRING),
74 ASN1_SIMPLE(OCSP_CERTID, serialNumber, ASN1_INTEGER)
75} ASN1_SEQUENCE_END(OCSP_CERTID)
76
77IMPLEMENT_ASN1_FUNCTIONS(OCSP_CERTID)
78
79ASN1_SEQUENCE(OCSP_ONEREQ) = {
80 ASN1_SIMPLE(OCSP_ONEREQ, reqCert, OCSP_CERTID),
81 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_ONEREQ, singleRequestExtensions, X509_EXTENSION, 0)
82} ASN1_SEQUENCE_END(OCSP_ONEREQ)
83
84IMPLEMENT_ASN1_FUNCTIONS(OCSP_ONEREQ)
85
86ASN1_SEQUENCE(OCSP_REQINFO) = {
87 ASN1_EXP_OPT(OCSP_REQINFO, version, ASN1_INTEGER, 0),
88 ASN1_EXP_OPT(OCSP_REQINFO, requestorName, GENERAL_NAME, 1),
89 ASN1_SEQUENCE_OF(OCSP_REQINFO, requestList, OCSP_ONEREQ),
90 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_REQINFO, requestExtensions, X509_EXTENSION, 2)
91} ASN1_SEQUENCE_END(OCSP_REQINFO)
92
93IMPLEMENT_ASN1_FUNCTIONS(OCSP_REQINFO)
94
95ASN1_SEQUENCE(OCSP_REQUEST) = {
96 ASN1_SIMPLE(OCSP_REQUEST, tbsRequest, OCSP_REQINFO),
97 ASN1_EXP_OPT(OCSP_REQUEST, optionalSignature, OCSP_SIGNATURE, 0)
98} ASN1_SEQUENCE_END(OCSP_REQUEST)
99
100IMPLEMENT_ASN1_FUNCTIONS(OCSP_REQUEST)
101
102/* OCSP_RESPONSE templates */
103
104ASN1_SEQUENCE(OCSP_RESPBYTES) = {
105 ASN1_SIMPLE(OCSP_RESPBYTES, responseType, ASN1_OBJECT),
106 ASN1_SIMPLE(OCSP_RESPBYTES, response, ASN1_OCTET_STRING)
107} ASN1_SEQUENCE_END(OCSP_RESPBYTES)
108
109IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPBYTES)
110
111ASN1_SEQUENCE(OCSP_RESPONSE) = {
112 ASN1_SIMPLE(OCSP_RESPONSE, responseStatus, ASN1_ENUMERATED),
113 ASN1_EXP_OPT(OCSP_RESPONSE, responseBytes, OCSP_RESPBYTES, 0)
114} ASN1_SEQUENCE_END(OCSP_RESPONSE)
115
116IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPONSE)
117
118ASN1_CHOICE(OCSP_RESPID) = {
119 ASN1_EXP(OCSP_RESPID, value.byName, X509_NAME, 1),
120 ASN1_EXP(OCSP_RESPID, value.byKey, ASN1_OCTET_STRING, 2)
121} ASN1_CHOICE_END(OCSP_RESPID)
122
123IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPID)
124
125ASN1_SEQUENCE(OCSP_REVOKEDINFO) = {
126 ASN1_SIMPLE(OCSP_REVOKEDINFO, revocationTime, ASN1_GENERALIZEDTIME),
127 ASN1_EXP_OPT(OCSP_REVOKEDINFO, revocationReason, ASN1_ENUMERATED, 0)
128} ASN1_SEQUENCE_END(OCSP_REVOKEDINFO)
129
130IMPLEMENT_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)
131
132ASN1_CHOICE(OCSP_CERTSTATUS) = {
133 ASN1_IMP(OCSP_CERTSTATUS, value.good, ASN1_NULL, 0),
134 ASN1_IMP(OCSP_CERTSTATUS, value.revoked, OCSP_REVOKEDINFO, 1),
135 ASN1_IMP(OCSP_CERTSTATUS, value.unknown, ASN1_NULL, 2)
136} ASN1_CHOICE_END(OCSP_CERTSTATUS)
137
138IMPLEMENT_ASN1_FUNCTIONS(OCSP_CERTSTATUS)
139
140ASN1_SEQUENCE(OCSP_SINGLERESP) = {
141 ASN1_SIMPLE(OCSP_SINGLERESP, certId, OCSP_CERTID),
142 ASN1_SIMPLE(OCSP_SINGLERESP, certStatus, OCSP_CERTSTATUS),
143 ASN1_SIMPLE(OCSP_SINGLERESP, thisUpdate, ASN1_GENERALIZEDTIME),
144 ASN1_EXP_OPT(OCSP_SINGLERESP, nextUpdate, ASN1_GENERALIZEDTIME, 0),
145 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_SINGLERESP, singleExtensions, X509_EXTENSION, 1)
146} ASN1_SEQUENCE_END(OCSP_SINGLERESP)
147
148IMPLEMENT_ASN1_FUNCTIONS(OCSP_SINGLERESP)
149
150ASN1_SEQUENCE(OCSP_RESPDATA) = {
151 ASN1_EXP_OPT(OCSP_RESPDATA, version, ASN1_INTEGER, 0),
152 ASN1_SIMPLE(OCSP_RESPDATA, responderId, OCSP_RESPID),
153 ASN1_SIMPLE(OCSP_RESPDATA, producedAt, ASN1_GENERALIZEDTIME),
154 ASN1_SEQUENCE_OF(OCSP_RESPDATA, responses, OCSP_SINGLERESP),
155 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_RESPDATA, responseExtensions, X509_EXTENSION, 1)
156} ASN1_SEQUENCE_END(OCSP_RESPDATA)
157
158IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPDATA)
159
160ASN1_SEQUENCE(OCSP_BASICRESP) = {
161 ASN1_SIMPLE(OCSP_BASICRESP, tbsResponseData, OCSP_RESPDATA),
162 ASN1_SIMPLE(OCSP_BASICRESP, signatureAlgorithm, X509_ALGOR),
163 ASN1_SIMPLE(OCSP_BASICRESP, signature, ASN1_BIT_STRING),
164 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_BASICRESP, certs, X509, 0)
165} ASN1_SEQUENCE_END(OCSP_BASICRESP)
166
167IMPLEMENT_ASN1_FUNCTIONS(OCSP_BASICRESP)
168
169ASN1_SEQUENCE(OCSP_CRLID) = {
170 ASN1_EXP_OPT(OCSP_CRLID, crlUrl, ASN1_IA5STRING, 0),
171 ASN1_EXP_OPT(OCSP_CRLID, crlNum, ASN1_INTEGER, 1),
172 ASN1_EXP_OPT(OCSP_CRLID, crlTime, ASN1_GENERALIZEDTIME, 2)
173} ASN1_SEQUENCE_END(OCSP_CRLID)
174
175IMPLEMENT_ASN1_FUNCTIONS(OCSP_CRLID)
176
177ASN1_SEQUENCE(OCSP_SERVICELOC) = {
178 ASN1_SIMPLE(OCSP_SERVICELOC, issuer, X509_NAME),
179 ASN1_SEQUENCE_OF_OPT(OCSP_SERVICELOC, locator, ACCESS_DESCRIPTION)
180} ASN1_SEQUENCE_END(OCSP_SERVICELOC)
181
182IMPLEMENT_ASN1_FUNCTIONS(OCSP_SERVICELOC)
diff --git a/src/lib/libcrypto/ocsp/ocsp_cl.c b/src/lib/libcrypto/ocsp/ocsp_cl.c
deleted file mode 100644
index 9b3e6dd8ca..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_cl.c
+++ /dev/null
@@ -1,370 +0,0 @@
1/* ocsp_cl.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <time.h>
66#include <cryptlib.h>
67#include <openssl/objects.h>
68#include <openssl/rand.h>
69#include <openssl/x509.h>
70#include <openssl/pem.h>
71#include <openssl/x509v3.h>
72#include <openssl/ocsp.h>
73
74/* Utility functions related to sending OCSP requests and extracting
75 * relevant information from the response.
76 */
77
78/* Add an OCSP_CERTID to an OCSP request. Return new OCSP_ONEREQ
79 * pointer: useful if we want to add extensions.
80 */
81
82OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid)
83 {
84 OCSP_ONEREQ *one = NULL;
85
86 if (!(one = OCSP_ONEREQ_new())) goto err;
87 if (one->reqCert) OCSP_CERTID_free(one->reqCert);
88 one->reqCert = cid;
89 if (req &&
90 !sk_OCSP_ONEREQ_push(req->tbsRequest->requestList, one))
91 goto err;
92 return one;
93err:
94 OCSP_ONEREQ_free(one);
95 return NULL;
96 }
97
98/* Set requestorName from an X509_NAME structure */
99
100int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm)
101 {
102 GENERAL_NAME *gen;
103 gen = GENERAL_NAME_new();
104 if (!X509_NAME_set(&gen->d.directoryName, nm))
105 {
106 GENERAL_NAME_free(gen);
107 return 0;
108 }
109 gen->type = GEN_DIRNAME;
110 if (req->tbsRequest->requestorName)
111 GENERAL_NAME_free(req->tbsRequest->requestorName);
112 req->tbsRequest->requestorName = gen;
113 return 1;
114 }
115
116
117/* Add a certificate to an OCSP request */
118
119int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert)
120 {
121 OCSP_SIGNATURE *sig;
122 if (!req->optionalSignature)
123 req->optionalSignature = OCSP_SIGNATURE_new();
124 sig = req->optionalSignature;
125 if (!sig) return 0;
126 if (!cert) return 1;
127 if (!sig->certs && !(sig->certs = sk_X509_new_null()))
128 return 0;
129
130 if(!sk_X509_push(sig->certs, cert)) return 0;
131 CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
132 return 1;
133 }
134
135/* Sign an OCSP request set the requestorName to the subjec
136 * name of an optional signers certificate and include one
137 * or more optional certificates in the request. Behaves
138 * like PKCS7_sign().
139 */
140
141int OCSP_request_sign(OCSP_REQUEST *req,
142 X509 *signer,
143 EVP_PKEY *key,
144 const EVP_MD *dgst,
145 STACK_OF(X509) *certs,
146 unsigned long flags)
147 {
148 int i;
149 OCSP_SIGNATURE *sig;
150 X509 *x;
151
152 if (!OCSP_request_set1_name(req, X509_get_subject_name(signer)))
153 goto err;
154
155 if (!(req->optionalSignature = sig = OCSP_SIGNATURE_new())) goto err;
156 if (!dgst) dgst = EVP_sha1();
157 if (key)
158 {
159 if (!X509_check_private_key(signer, key))
160 {
161 OCSPerr(OCSP_F_OCSP_REQUEST_SIGN, OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
162 goto err;
163 }
164 if (!OCSP_REQUEST_sign(req, key, dgst)) goto err;
165 }
166
167 if (!(flags & OCSP_NOCERTS))
168 {
169 if(!OCSP_request_add1_cert(req, signer)) goto err;
170 for (i = 0; i < sk_X509_num(certs); i++)
171 {
172 x = sk_X509_value(certs, i);
173 if (!OCSP_request_add1_cert(req, x)) goto err;
174 }
175 }
176
177 return 1;
178err:
179 OCSP_SIGNATURE_free(req->optionalSignature);
180 req->optionalSignature = NULL;
181 return 0;
182 }
183
184/* Get response status */
185
186int OCSP_response_status(OCSP_RESPONSE *resp)
187 {
188 return ASN1_ENUMERATED_get(resp->responseStatus);
189 }
190
191/* Extract basic response from OCSP_RESPONSE or NULL if
192 * no basic response present.
193 */
194
195
196OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp)
197 {
198 OCSP_RESPBYTES *rb;
199 rb = resp->responseBytes;
200 if (!rb)
201 {
202 OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, OCSP_R_NO_RESPONSE_DATA);
203 return NULL;
204 }
205 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic)
206 {
207 OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, OCSP_R_NOT_BASIC_RESPONSE);
208 return NULL;
209 }
210
211 return ASN1_item_unpack(rb->response, ASN1_ITEM_rptr(OCSP_BASICRESP));
212 }
213
214/* Return number of OCSP_SINGLERESP reponses present in
215 * a basic response.
216 */
217
218int OCSP_resp_count(OCSP_BASICRESP *bs)
219 {
220 if (!bs) return -1;
221 return sk_OCSP_SINGLERESP_num(bs->tbsResponseData->responses);
222 }
223
224/* Extract an OCSP_SINGLERESP response with a given index */
225
226OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx)
227 {
228 if (!bs) return NULL;
229 return sk_OCSP_SINGLERESP_value(bs->tbsResponseData->responses, idx);
230 }
231
232/* Look single response matching a given certificate ID */
233
234int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last)
235 {
236 int i;
237 STACK_OF(OCSP_SINGLERESP) *sresp;
238 OCSP_SINGLERESP *single;
239 if (!bs) return -1;
240 if (last < 0) last = 0;
241 else last++;
242 sresp = bs->tbsResponseData->responses;
243 for (i = last; i < sk_OCSP_SINGLERESP_num(sresp); i++)
244 {
245 single = sk_OCSP_SINGLERESP_value(sresp, i);
246 if (!OCSP_id_cmp(id, single->certId)) return i;
247 }
248 return -1;
249 }
250
251/* Extract status information from an OCSP_SINGLERESP structure.
252 * Note: the revtime and reason values are only set if the
253 * certificate status is revoked. Returns numerical value of
254 * status.
255 */
256
257int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
258 ASN1_GENERALIZEDTIME **revtime,
259 ASN1_GENERALIZEDTIME **thisupd,
260 ASN1_GENERALIZEDTIME **nextupd)
261 {
262 int ret;
263 OCSP_CERTSTATUS *cst;
264 if(!single) return -1;
265 cst = single->certStatus;
266 ret = cst->type;
267 if (ret == V_OCSP_CERTSTATUS_REVOKED)
268 {
269 OCSP_REVOKEDINFO *rev = cst->value.revoked;
270 if (revtime) *revtime = rev->revocationTime;
271 if (reason)
272 {
273 if(rev->revocationReason)
274 *reason = ASN1_ENUMERATED_get(rev->revocationReason);
275 else *reason = -1;
276 }
277 }
278 if(thisupd) *thisupd = single->thisUpdate;
279 if(nextupd) *nextupd = single->nextUpdate;
280 return ret;
281 }
282
283/* This function combines the previous ones: look up a certificate ID and
284 * if found extract status information. Return 0 is successful.
285 */
286
287int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
288 int *reason,
289 ASN1_GENERALIZEDTIME **revtime,
290 ASN1_GENERALIZEDTIME **thisupd,
291 ASN1_GENERALIZEDTIME **nextupd)
292 {
293 int i;
294 OCSP_SINGLERESP *single;
295 i = OCSP_resp_find(bs, id, -1);
296 /* Maybe check for multiple responses and give an error? */
297 if(i < 0) return 0;
298 single = OCSP_resp_get0(bs, i);
299 i = OCSP_single_get0_status(single, reason, revtime, thisupd, nextupd);
300 if(status) *status = i;
301 return 1;
302 }
303
304/* Check validity of thisUpdate and nextUpdate fields. It is possible that the request will
305 * take a few seconds to process and/or the time wont be totally accurate. Therefore to avoid
306 * rejecting otherwise valid time we allow the times to be within 'nsec' of the current time.
307 * Also to avoid accepting very old responses without a nextUpdate field an optional maxage
308 * parameter specifies the maximum age the thisUpdate field can be.
309 */
310
311int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, ASN1_GENERALIZEDTIME *nextupd, long nsec, long maxsec)
312 {
313 int ret = 1;
314 time_t t_now, t_tmp;
315 time(&t_now);
316 /* Check thisUpdate is valid and not more than nsec in the future */
317 if (!ASN1_GENERALIZEDTIME_check(thisupd))
318 {
319 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_THISUPDATE_FIELD);
320 ret = 0;
321 }
322 else
323 {
324 t_tmp = t_now + nsec;
325 if (X509_cmp_time(thisupd, &t_tmp) > 0)
326 {
327 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_NOT_YET_VALID);
328 ret = 0;
329 }
330
331 /* If maxsec specified check thisUpdate is not more than maxsec in the past */
332 if (maxsec >= 0)
333 {
334 t_tmp = t_now - maxsec;
335 if (X509_cmp_time(thisupd, &t_tmp) < 0)
336 {
337 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_TOO_OLD);
338 ret = 0;
339 }
340 }
341 }
342
343
344 if (!nextupd) return ret;
345
346 /* Check nextUpdate is valid and not more than nsec in the past */
347 if (!ASN1_GENERALIZEDTIME_check(nextupd))
348 {
349 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_NEXTUPDATE_FIELD);
350 ret = 0;
351 }
352 else
353 {
354 t_tmp = t_now - nsec;
355 if (X509_cmp_time(nextupd, &t_tmp) < 0)
356 {
357 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_EXPIRED);
358 ret = 0;
359 }
360 }
361
362 /* Also don't allow nextUpdate to precede thisUpdate */
363 if (ASN1_STRING_cmp(nextupd, thisupd) < 0)
364 {
365 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE);
366 ret = 0;
367 }
368
369 return ret;
370 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_err.c b/src/lib/libcrypto/ocsp/ocsp_err.c
deleted file mode 100644
index 65e6093fbc..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_err.c
+++ /dev/null
@@ -1,143 +0,0 @@
1/* crypto/ocsp/ocsp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ocsp.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_OCSP,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OCSP,0,reason)
70
71static ERR_STRING_DATA OCSP_str_functs[]=
72 {
73{ERR_FUNC(OCSP_F_ASN1_STRING_ENCODE), "ASN1_STRING_encode"},
74{ERR_FUNC(OCSP_F_CERT_ID_NEW), "CERT_ID_NEW"},
75{ERR_FUNC(OCSP_F_D2I_OCSP_NONCE), "D2I_OCSP_NONCE"},
76{ERR_FUNC(OCSP_F_OCSP_BASIC_ADD1_STATUS), "OCSP_basic_add1_status"},
77{ERR_FUNC(OCSP_F_OCSP_BASIC_SIGN), "OCSP_basic_sign"},
78{ERR_FUNC(OCSP_F_OCSP_BASIC_VERIFY), "OCSP_basic_verify"},
79{ERR_FUNC(OCSP_F_OCSP_CHECK_DELEGATED), "OCSP_CHECK_DELEGATED"},
80{ERR_FUNC(OCSP_F_OCSP_CHECK_IDS), "OCSP_CHECK_IDS"},
81{ERR_FUNC(OCSP_F_OCSP_CHECK_ISSUER), "OCSP_CHECK_ISSUER"},
82{ERR_FUNC(OCSP_F_OCSP_CHECK_VALIDITY), "OCSP_check_validity"},
83{ERR_FUNC(OCSP_F_OCSP_MATCH_ISSUERID), "OCSP_MATCH_ISSUERID"},
84{ERR_FUNC(OCSP_F_OCSP_PARSE_URL), "OCSP_parse_url"},
85{ERR_FUNC(OCSP_F_OCSP_REQUEST_SIGN), "OCSP_request_sign"},
86{ERR_FUNC(OCSP_F_OCSP_REQUEST_VERIFY), "OCSP_request_verify"},
87{ERR_FUNC(OCSP_F_OCSP_RESPONSE_GET1_BASIC), "OCSP_response_get1_basic"},
88{ERR_FUNC(OCSP_F_OCSP_SENDREQ_BIO), "OCSP_sendreq_bio"},
89{ERR_FUNC(OCSP_F_REQUEST_VERIFY), "REQUEST_VERIFY"},
90{0,NULL}
91 };
92
93static ERR_STRING_DATA OCSP_str_reasons[]=
94 {
95{ERR_REASON(OCSP_R_BAD_DATA) ,"bad data"},
96{ERR_REASON(OCSP_R_CERTIFICATE_VERIFY_ERROR),"certificate verify error"},
97{ERR_REASON(OCSP_R_DIGEST_ERR) ,"digest err"},
98{ERR_REASON(OCSP_R_ERROR_IN_NEXTUPDATE_FIELD),"error in nextupdate field"},
99{ERR_REASON(OCSP_R_ERROR_IN_THISUPDATE_FIELD),"error in thisupdate field"},
100{ERR_REASON(OCSP_R_ERROR_PARSING_URL) ,"error parsing url"},
101{ERR_REASON(OCSP_R_MISSING_OCSPSIGNING_USAGE),"missing ocspsigning usage"},
102{ERR_REASON(OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE),"nextupdate before thisupdate"},
103{ERR_REASON(OCSP_R_NOT_BASIC_RESPONSE) ,"not basic response"},
104{ERR_REASON(OCSP_R_NO_CERTIFICATES_IN_CHAIN),"no certificates in chain"},
105{ERR_REASON(OCSP_R_NO_CONTENT) ,"no content"},
106{ERR_REASON(OCSP_R_NO_PUBLIC_KEY) ,"no public key"},
107{ERR_REASON(OCSP_R_NO_RESPONSE_DATA) ,"no response data"},
108{ERR_REASON(OCSP_R_NO_REVOKED_TIME) ,"no revoked time"},
109{ERR_REASON(OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE),"private key does not match certificate"},
110{ERR_REASON(OCSP_R_REQUEST_NOT_SIGNED) ,"request not signed"},
111{ERR_REASON(OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA),"response contains no revocation data"},
112{ERR_REASON(OCSP_R_ROOT_CA_NOT_TRUSTED) ,"root ca not trusted"},
113{ERR_REASON(OCSP_R_SERVER_READ_ERROR) ,"server read error"},
114{ERR_REASON(OCSP_R_SERVER_RESPONSE_ERROR),"server response error"},
115{ERR_REASON(OCSP_R_SERVER_RESPONSE_PARSE_ERROR),"server response parse error"},
116{ERR_REASON(OCSP_R_SERVER_WRITE_ERROR) ,"server write error"},
117{ERR_REASON(OCSP_R_SIGNATURE_FAILURE) ,"signature failure"},
118{ERR_REASON(OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND),"signer certificate not found"},
119{ERR_REASON(OCSP_R_STATUS_EXPIRED) ,"status expired"},
120{ERR_REASON(OCSP_R_STATUS_NOT_YET_VALID) ,"status not yet valid"},
121{ERR_REASON(OCSP_R_STATUS_TOO_OLD) ,"status too old"},
122{ERR_REASON(OCSP_R_UNKNOWN_MESSAGE_DIGEST),"unknown message digest"},
123{ERR_REASON(OCSP_R_UNKNOWN_NID) ,"unknown nid"},
124{ERR_REASON(OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE),"unsupported requestorname type"},
125{0,NULL}
126 };
127
128#endif
129
130void ERR_load_OCSP_strings(void)
131 {
132 static int init=1;
133
134 if (init)
135 {
136 init=0;
137#ifndef OPENSSL_NO_ERR
138 ERR_load_strings(0,OCSP_str_functs);
139 ERR_load_strings(0,OCSP_str_reasons);
140#endif
141
142 }
143 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_ext.c b/src/lib/libcrypto/ocsp/ocsp_ext.c
deleted file mode 100644
index 57399433fc..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_ext.c
+++ /dev/null
@@ -1,538 +0,0 @@
1/* ocsp_ext.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <cryptlib.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#include <openssl/ocsp.h>
69#include <openssl/rand.h>
70#include <openssl/x509v3.h>
71
72/* Standard wrapper functions for extensions */
73
74/* OCSP request extensions */
75
76int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x)
77 {
78 return(X509v3_get_ext_count(x->tbsRequest->requestExtensions));
79 }
80
81int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos)
82 {
83 return(X509v3_get_ext_by_NID(x->tbsRequest->requestExtensions,nid,lastpos));
84 }
85
86int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, ASN1_OBJECT *obj, int lastpos)
87 {
88 return(X509v3_get_ext_by_OBJ(x->tbsRequest->requestExtensions,obj,lastpos));
89 }
90
91int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos)
92 {
93 return(X509v3_get_ext_by_critical(x->tbsRequest->requestExtensions,crit,lastpos));
94 }
95
96X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc)
97 {
98 return(X509v3_get_ext(x->tbsRequest->requestExtensions,loc));
99 }
100
101X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc)
102 {
103 return(X509v3_delete_ext(x->tbsRequest->requestExtensions,loc));
104 }
105
106void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, int *idx)
107 {
108 return X509V3_get_d2i(x->tbsRequest->requestExtensions, nid, crit, idx);
109 }
110
111int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
112 unsigned long flags)
113 {
114 return X509V3_add1_i2d(&x->tbsRequest->requestExtensions, nid, value, crit, flags);
115 }
116
117int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc)
118 {
119 return(X509v3_add_ext(&(x->tbsRequest->requestExtensions),ex,loc) != NULL);
120 }
121
122/* Single extensions */
123
124int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x)
125 {
126 return(X509v3_get_ext_count(x->singleRequestExtensions));
127 }
128
129int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos)
130 {
131 return(X509v3_get_ext_by_NID(x->singleRequestExtensions,nid,lastpos));
132 }
133
134int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, ASN1_OBJECT *obj, int lastpos)
135 {
136 return(X509v3_get_ext_by_OBJ(x->singleRequestExtensions,obj,lastpos));
137 }
138
139int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos)
140 {
141 return(X509v3_get_ext_by_critical(x->singleRequestExtensions,crit,lastpos));
142 }
143
144X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc)
145 {
146 return(X509v3_get_ext(x->singleRequestExtensions,loc));
147 }
148
149X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc)
150 {
151 return(X509v3_delete_ext(x->singleRequestExtensions,loc));
152 }
153
154void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx)
155 {
156 return X509V3_get_d2i(x->singleRequestExtensions, nid, crit, idx);
157 }
158
159int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
160 unsigned long flags)
161 {
162 return X509V3_add1_i2d(&x->singleRequestExtensions, nid, value, crit, flags);
163 }
164
165int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc)
166 {
167 return(X509v3_add_ext(&(x->singleRequestExtensions),ex,loc) != NULL);
168 }
169
170/* OCSP Basic response */
171
172int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x)
173 {
174 return(X509v3_get_ext_count(x->tbsResponseData->responseExtensions));
175 }
176
177int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos)
178 {
179 return(X509v3_get_ext_by_NID(x->tbsResponseData->responseExtensions,nid,lastpos));
180 }
181
182int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, ASN1_OBJECT *obj, int lastpos)
183 {
184 return(X509v3_get_ext_by_OBJ(x->tbsResponseData->responseExtensions,obj,lastpos));
185 }
186
187int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, int lastpos)
188 {
189 return(X509v3_get_ext_by_critical(x->tbsResponseData->responseExtensions,crit,lastpos));
190 }
191
192X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc)
193 {
194 return(X509v3_get_ext(x->tbsResponseData->responseExtensions,loc));
195 }
196
197X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc)
198 {
199 return(X509v3_delete_ext(x->tbsResponseData->responseExtensions,loc));
200 }
201
202void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, int *idx)
203 {
204 return X509V3_get_d2i(x->tbsResponseData->responseExtensions, nid, crit, idx);
205 }
206
207int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, int crit,
208 unsigned long flags)
209 {
210 return X509V3_add1_i2d(&x->tbsResponseData->responseExtensions, nid, value, crit, flags);
211 }
212
213int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc)
214 {
215 return(X509v3_add_ext(&(x->tbsResponseData->responseExtensions),ex,loc) != NULL);
216 }
217
218/* OCSP single response extensions */
219
220int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x)
221 {
222 return(X509v3_get_ext_count(x->singleExtensions));
223 }
224
225int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos)
226 {
227 return(X509v3_get_ext_by_NID(x->singleExtensions,nid,lastpos));
228 }
229
230int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, ASN1_OBJECT *obj, int lastpos)
231 {
232 return(X509v3_get_ext_by_OBJ(x->singleExtensions,obj,lastpos));
233 }
234
235int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, int lastpos)
236 {
237 return(X509v3_get_ext_by_critical(x->singleExtensions,crit,lastpos));
238 }
239
240X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc)
241 {
242 return(X509v3_get_ext(x->singleExtensions,loc));
243 }
244
245X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc)
246 {
247 return(X509v3_delete_ext(x->singleExtensions,loc));
248 }
249
250void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, int *idx)
251 {
252 return X509V3_get_d2i(x->singleExtensions, nid, crit, idx);
253 }
254
255int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, int crit,
256 unsigned long flags)
257 {
258 return X509V3_add1_i2d(&x->singleExtensions, nid, value, crit, flags);
259 }
260
261int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc)
262 {
263 return(X509v3_add_ext(&(x->singleExtensions),ex,loc) != NULL);
264 }
265
266/* also CRL Entry Extensions */
267
268ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(),
269 char *data, STACK_OF(ASN1_OBJECT) *sk)
270 {
271 int i;
272 unsigned char *p, *b = NULL;
273
274 if (data)
275 {
276 if ((i=i2d(data,NULL)) <= 0) goto err;
277 if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
278 goto err;
279 if (i2d(data, &p) <= 0) goto err;
280 }
281 else if (sk)
282 {
283 if ((i=i2d_ASN1_SET_OF_ASN1_OBJECT(sk,NULL,i2d,V_ASN1_SEQUENCE,
284 V_ASN1_UNIVERSAL,IS_SEQUENCE))<=0) goto err;
285 if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
286 goto err;
287 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,i2d,V_ASN1_SEQUENCE,
288 V_ASN1_UNIVERSAL,IS_SEQUENCE)<=0) goto err;
289 }
290 else
291 {
292 OCSPerr(OCSP_F_ASN1_STRING_ENCODE,OCSP_R_BAD_DATA);
293 goto err;
294 }
295 if (!s && !(s = ASN1_STRING_new())) goto err;
296 if (!(ASN1_STRING_set(s, b, i))) goto err;
297 OPENSSL_free(b);
298 return s;
299err:
300 if (b) OPENSSL_free(b);
301 return NULL;
302 }
303
304/* Nonce handling functions */
305
306/* Add a nonce to an extension stack. A nonce can be specificed or if NULL
307 * a random nonce will be generated.
308 * Note: OpenSSL 0.9.7d and later create an OCTET STRING containing the
309 * nonce, previous versions used the raw nonce.
310 */
311
312static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len)
313 {
314 unsigned char *tmpval;
315 ASN1_OCTET_STRING os;
316 int ret = 0;
317 if (len <= 0) len = OCSP_DEFAULT_NONCE_LENGTH;
318 /* Create the OCTET STRING manually by writing out the header and
319 * appending the content octets. This avoids an extra memory allocation
320 * operation in some cases. Applications should *NOT* do this because
321 * it relies on library internals.
322 */
323 os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);
324 os.data = OPENSSL_malloc(os.length);
325 if (os.data == NULL)
326 goto err;
327 tmpval = os.data;
328 ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL);
329 if (val)
330 memcpy(tmpval, val, len);
331 else
332 RAND_pseudo_bytes(tmpval, len);
333 if(!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce,
334 &os, 0, X509V3_ADD_REPLACE))
335 goto err;
336 ret = 1;
337 err:
338 if (os.data)
339 OPENSSL_free(os.data);
340 return ret;
341 }
342
343
344/* Add nonce to an OCSP request */
345
346int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len)
347 {
348 return ocsp_add1_nonce(&req->tbsRequest->requestExtensions, val, len);
349 }
350
351/* Same as above but for a response */
352
353int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len)
354 {
355 return ocsp_add1_nonce(&resp->tbsResponseData->responseExtensions, val, len);
356 }
357
358/* Check nonce validity in a request and response.
359 * Return value reflects result:
360 * 1: nonces present and equal.
361 * 2: nonces both absent.
362 * 3: nonce present in response only.
363 * 0: nonces both present and not equal.
364 * -1: nonce in request only.
365 *
366 * For most responders clients can check return > 0.
367 * If responder doesn't handle nonces return != 0 may be
368 * necessary. return == 0 is always an error.
369 */
370
371int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs)
372 {
373 /*
374 * Since we are only interested in the presence or absence of
375 * the nonce and comparing its value there is no need to use
376 * the X509V3 routines: this way we can avoid them allocating an
377 * ASN1_OCTET_STRING structure for the value which would be
378 * freed immediately anyway.
379 */
380
381 int req_idx, resp_idx;
382 X509_EXTENSION *req_ext, *resp_ext;
383 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
384 resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1);
385 /* Check both absent */
386 if((req_idx < 0) && (resp_idx < 0))
387 return 2;
388 /* Check in request only */
389 if((req_idx >= 0) && (resp_idx < 0))
390 return -1;
391 /* Check in response but not request */
392 if((req_idx < 0) && (resp_idx >= 0))
393 return 3;
394 /* Otherwise nonce in request and response so retrieve the extensions */
395 req_ext = OCSP_REQUEST_get_ext(req, req_idx);
396 resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx);
397 if(ASN1_OCTET_STRING_cmp(req_ext->value, resp_ext->value))
398 return 0;
399 return 1;
400 }
401
402/* Copy the nonce value (if any) from an OCSP request to
403 * a response.
404 */
405
406int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req)
407 {
408 X509_EXTENSION *req_ext;
409 int req_idx;
410 /* Check for nonce in request */
411 req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
412 /* If no nonce that's OK */
413 if (req_idx < 0) return 2;
414 req_ext = OCSP_REQUEST_get_ext(req, req_idx);
415 return OCSP_BASICRESP_add_ext(resp, req_ext, -1);
416 }
417
418X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim)
419 {
420 X509_EXTENSION *x = NULL;
421 OCSP_CRLID *cid = NULL;
422
423 if (!(cid = OCSP_CRLID_new())) goto err;
424 if (url)
425 {
426 if (!(cid->crlUrl = ASN1_IA5STRING_new())) goto err;
427 if (!(ASN1_STRING_set(cid->crlUrl, url, -1))) goto err;
428 }
429 if (n)
430 {
431 if (!(cid->crlNum = ASN1_INTEGER_new())) goto err;
432 if (!(ASN1_INTEGER_set(cid->crlNum, *n))) goto err;
433 }
434 if (tim)
435 {
436 if (!(cid->crlTime = ASN1_GENERALIZEDTIME_new())) goto err;
437 if (!(ASN1_GENERALIZEDTIME_set_string(cid->crlTime, tim)))
438 goto err;
439 }
440 if (!(x = X509_EXTENSION_new())) goto err;
441 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_CrlID))) goto err;
442 if (!(ASN1_STRING_encode(x->value,i2d_OCSP_CRLID,(char*)cid,NULL)))
443 goto err;
444 OCSP_CRLID_free(cid);
445 return x;
446err:
447 if (x) X509_EXTENSION_free(x);
448 if (cid) OCSP_CRLID_free(cid);
449 return NULL;
450 }
451
452/* AcceptableResponses ::= SEQUENCE OF OBJECT IDENTIFIER */
453X509_EXTENSION *OCSP_accept_responses_new(char **oids)
454 {
455 int nid;
456 STACK_OF(ASN1_OBJECT) *sk = NULL;
457 ASN1_OBJECT *o = NULL;
458 X509_EXTENSION *x = NULL;
459
460 if (!(sk = sk_ASN1_OBJECT_new_null())) goto err;
461 while (oids && *oids)
462 {
463 if ((nid=OBJ_txt2nid(*oids))!=NID_undef&&(o=OBJ_nid2obj(nid)))
464 sk_ASN1_OBJECT_push(sk, o);
465 oids++;
466 }
467 if (!(x = X509_EXTENSION_new())) goto err;
468 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_acceptableResponses)))
469 goto err;
470 if (!(ASN1_STRING_encode(x->value,i2d_ASN1_OBJECT,NULL,sk)))
471 goto err;
472 sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
473 return x;
474err:
475 if (x) X509_EXTENSION_free(x);
476 if (sk) sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
477 return NULL;
478 }
479
480/* ArchiveCutoff ::= GeneralizedTime */
481X509_EXTENSION *OCSP_archive_cutoff_new(char* tim)
482 {
483 X509_EXTENSION *x=NULL;
484 ASN1_GENERALIZEDTIME *gt = NULL;
485
486 if (!(gt = ASN1_GENERALIZEDTIME_new())) goto err;
487 if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err;
488 if (!(x = X509_EXTENSION_new())) goto err;
489 if (!(x->object=OBJ_nid2obj(NID_id_pkix_OCSP_archiveCutoff)))goto err;
490 if (!(ASN1_STRING_encode(x->value,i2d_ASN1_GENERALIZEDTIME,
491 (char*)gt,NULL))) goto err;
492 ASN1_GENERALIZEDTIME_free(gt);
493 return x;
494err:
495 if (gt) ASN1_GENERALIZEDTIME_free(gt);
496 if (x) X509_EXTENSION_free(x);
497 return NULL;
498 }
499
500/* per ACCESS_DESCRIPTION parameter are oids, of which there are currently
501 * two--NID_ad_ocsp, NID_id_ad_caIssuers--and GeneralName value. This
502 * method forces NID_ad_ocsp and uniformResourceLocator [6] IA5String.
503 */
504X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls)
505 {
506 X509_EXTENSION *x = NULL;
507 ASN1_IA5STRING *ia5 = NULL;
508 OCSP_SERVICELOC *sloc = NULL;
509 ACCESS_DESCRIPTION *ad = NULL;
510
511 if (!(sloc = OCSP_SERVICELOC_new())) goto err;
512 if (!(sloc->issuer = X509_NAME_dup(issuer))) goto err;
513 if (urls && *urls && !(sloc->locator = sk_ACCESS_DESCRIPTION_new_null())) goto err;
514 while (urls && *urls)
515 {
516 if (!(ad = ACCESS_DESCRIPTION_new())) goto err;
517 if (!(ad->method=OBJ_nid2obj(NID_ad_OCSP))) goto err;
518 if (!(ad->location = GENERAL_NAME_new())) goto err;
519 if (!(ia5 = ASN1_IA5STRING_new())) goto err;
520 if (!ASN1_STRING_set((ASN1_STRING*)ia5, *urls, -1)) goto err;
521 ad->location->type = GEN_URI;
522 ad->location->d.ia5 = ia5;
523 if (!sk_ACCESS_DESCRIPTION_push(sloc->locator, ad)) goto err;
524 urls++;
525 }
526 if (!(x = X509_EXTENSION_new())) goto err;
527 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_serviceLocator)))
528 goto err;
529 if (!(ASN1_STRING_encode(x->value, i2d_OCSP_SERVICELOC,
530 (char*)sloc, NULL))) goto err;
531 OCSP_SERVICELOC_free(sloc);
532 return x;
533err:
534 if (x) X509_EXTENSION_free(x);
535 if (sloc) OCSP_SERVICELOC_free(sloc);
536 return NULL;
537 }
538
diff --git a/src/lib/libcrypto/ocsp/ocsp_ht.c b/src/lib/libcrypto/ocsp/ocsp_ht.c
deleted file mode 100644
index 2c48171883..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_ht.c
+++ /dev/null
@@ -1,173 +0,0 @@
1/* ocsp_ht.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/asn1.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <ctype.h>
63#include <string.h>
64#include <openssl/ocsp.h>
65#include <openssl/err.h>
66#include <openssl/buffer.h>
67#ifdef OPENSSL_SYS_SUNOS
68#define strtoul (unsigned long)strtol
69#endif /* OPENSSL_SYS_SUNOS */
70
71/* Quick and dirty HTTP OCSP request handler.
72 * Could make this a bit cleverer by adding
73 * support for non blocking BIOs and a few
74 * other refinements.
75 */
76
77OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req)
78{
79 BIO *mem = NULL;
80 char tmpbuf[1024];
81 OCSP_RESPONSE *resp = NULL;
82 char *p, *q, *r;
83 int len, retcode;
84 static char req_txt[] =
85"POST %s HTTP/1.0\r\n\
86Content-Type: application/ocsp-request\r\n\
87Content-Length: %d\r\n\r\n";
88
89 len = i2d_OCSP_REQUEST(req, NULL);
90 if(BIO_printf(b, req_txt, path, len) < 0) {
91 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
92 goto err;
93 }
94 if(i2d_OCSP_REQUEST_bio(b, req) <= 0) {
95 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
96 goto err;
97 }
98 if(!(mem = BIO_new(BIO_s_mem()))) goto err;
99 /* Copy response to a memory BIO: socket bios can't do gets! */
100 while ((len = BIO_read(b, tmpbuf, sizeof tmpbuf))) {
101 if(len < 0) {
102 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_READ_ERROR);
103 goto err;
104 }
105 BIO_write(mem, tmpbuf, len);
106 }
107 if(BIO_gets(mem, tmpbuf, 512) <= 0) {
108 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
109 goto err;
110 }
111 /* Parse the HTTP response. This will look like this:
112 * "HTTP/1.0 200 OK". We need to obtain the numeric code and
113 * (optional) informational message.
114 */
115
116 /* Skip to first white space (passed protocol info) */
117 for(p = tmpbuf; *p && !isspace((unsigned char)*p); p++) continue;
118 if(!*p) {
119 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
120 goto err;
121 }
122 /* Skip past white space to start of response code */
123 while(isspace((unsigned char)*p)) p++;
124 if(!*p) {
125 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
126 goto err;
127 }
128 /* Find end of response code: first whitespace after start of code */
129 for(q = p; *q && !isspace((unsigned char)*q); q++) continue;
130 if(!*q) {
131 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
132 goto err;
133 }
134 /* Set end of response code and start of message */
135 *q++ = 0;
136 /* Attempt to parse numeric code */
137 retcode = strtoul(p, &r, 10);
138 if(*r) goto err;
139 /* Skip over any leading white space in message */
140 while(isspace((unsigned char)*q)) q++;
141 if(*q) {
142 /* Finally zap any trailing white space in message (include CRLF) */
143 /* We know q has a non white space character so this is OK */
144 for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--) *r = 0;
145 }
146 if(retcode != 200) {
147 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_ERROR);
148 if(!*q) {
149 ERR_add_error_data(2, "Code=", p);
150 }
151 else {
152 ERR_add_error_data(4, "Code=", p, ",Reason=", q);
153 }
154 goto err;
155 }
156 /* Find blank line marking beginning of content */
157 while(BIO_gets(mem, tmpbuf, 512) > 0)
158 {
159 for(p = tmpbuf; isspace((unsigned char)*p); p++) continue;
160 if(!*p) break;
161 }
162 if(*p) {
163 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_NO_CONTENT);
164 goto err;
165 }
166 if(!(resp = d2i_OCSP_RESPONSE_bio(mem, NULL))) {
167 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,ERR_R_NESTED_ASN1_ERROR);
168 goto err;
169 }
170 err:
171 BIO_free(mem);
172 return resp;
173}
diff --git a/src/lib/libcrypto/ocsp/ocsp_lib.c b/src/lib/libcrypto/ocsp/ocsp_lib.c
deleted file mode 100644
index 9e87fc7895..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_lib.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/* ocsp_lib.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was transfered to Richard Levitte from CertCo by Kathy
7 Weinhold in mid-spring 2000 to be included in OpenSSL or released
8 as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <stdio.h>
65#include <cryptlib.h>
66#include <openssl/objects.h>
67#include <openssl/rand.h>
68#include <openssl/x509.h>
69#include <openssl/pem.h>
70#include <openssl/x509v3.h>
71#include <openssl/ocsp.h>
72
73/* Convert a certificate and its issuer to an OCSP_CERTID */
74
75OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer)
76{
77 X509_NAME *iname;
78 ASN1_INTEGER *serial;
79 ASN1_BIT_STRING *ikey;
80#ifndef OPENSSL_NO_SHA1
81 if(!dgst) dgst = EVP_sha1();
82#endif
83 if (subject)
84 {
85 iname = X509_get_issuer_name(subject);
86 serial = X509_get_serialNumber(subject);
87 }
88 else
89 {
90 iname = X509_get_subject_name(issuer);
91 serial = NULL;
92 }
93 ikey = X509_get0_pubkey_bitstr(issuer);
94 return OCSP_cert_id_new(dgst, iname, ikey, serial);
95}
96
97
98OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
99 X509_NAME *issuerName,
100 ASN1_BIT_STRING* issuerKey,
101 ASN1_INTEGER *serialNumber)
102 {
103 int nid;
104 unsigned int i;
105 X509_ALGOR *alg;
106 OCSP_CERTID *cid = NULL;
107 unsigned char md[EVP_MAX_MD_SIZE];
108
109 if (!(cid = OCSP_CERTID_new())) goto err;
110
111 alg = cid->hashAlgorithm;
112 if (alg->algorithm != NULL) ASN1_OBJECT_free(alg->algorithm);
113 if ((nid = EVP_MD_type(dgst)) == NID_undef)
114 {
115 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_UNKNOWN_NID);
116 goto err;
117 }
118 if (!(alg->algorithm=OBJ_nid2obj(nid))) goto err;
119 if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err;
120 alg->parameter->type=V_ASN1_NULL;
121
122 if (!X509_NAME_digest(issuerName, dgst, md, &i)) goto digerr;
123 if (!(ASN1_OCTET_STRING_set(cid->issuerNameHash, md, i))) goto err;
124
125 /* Calculate the issuerKey hash, excluding tag and length */
126 EVP_Digest(issuerKey->data, issuerKey->length, md, &i, dgst, NULL);
127
128 if (!(ASN1_OCTET_STRING_set(cid->issuerKeyHash, md, i))) goto err;
129
130 if (serialNumber)
131 {
132 ASN1_INTEGER_free(cid->serialNumber);
133 if (!(cid->serialNumber = ASN1_INTEGER_dup(serialNumber))) goto err;
134 }
135 return cid;
136digerr:
137 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_DIGEST_ERR);
138err:
139 if (cid) OCSP_CERTID_free(cid);
140 return NULL;
141 }
142
143int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b)
144 {
145 int ret;
146 ret = OBJ_cmp(a->hashAlgorithm->algorithm, b->hashAlgorithm->algorithm);
147 if (ret) return ret;
148 ret = ASN1_OCTET_STRING_cmp(a->issuerNameHash, b->issuerNameHash);
149 if (ret) return ret;
150 return ASN1_OCTET_STRING_cmp(a->issuerKeyHash, b->issuerKeyHash);
151 }
152
153int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b)
154 {
155 int ret;
156 ret = OCSP_id_issuer_cmp(a, b);
157 if (ret) return ret;
158 return ASN1_INTEGER_cmp(a->serialNumber, b->serialNumber);
159 }
160
161
162/* Parse a URL and split it up into host, port and path components and whether
163 * it is SSL.
164 */
165
166int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl)
167 {
168 char *p, *buf;
169
170 char *host, *port;
171
172 /* dup the buffer since we are going to mess with it */
173 buf = BUF_strdup(url);
174 if (!buf) goto mem_err;
175
176 *phost = NULL;
177 *pport = NULL;
178 *ppath = NULL;
179
180 /* Check for initial colon */
181 p = strchr(buf, ':');
182
183 if (!p) goto parse_err;
184
185 *(p++) = '\0';
186
187 if (!strcmp(buf, "http"))
188 {
189 *pssl = 0;
190 port = "80";
191 }
192 else if (!strcmp(buf, "https"))
193 {
194 *pssl = 1;
195 port = "443";
196 }
197 else
198 goto parse_err;
199
200 /* Check for double slash */
201 if ((p[0] != '/') || (p[1] != '/'))
202 goto parse_err;
203
204 p += 2;
205
206 host = p;
207
208 /* Check for trailing part of path */
209
210 p = strchr(p, '/');
211
212 if (!p)
213 *ppath = BUF_strdup("/");
214 else
215 {
216 *ppath = BUF_strdup(p);
217 /* Set start of path to 0 so hostname is valid */
218 *p = '\0';
219 }
220
221 if (!*ppath) goto mem_err;
222
223 /* Look for optional ':' for port number */
224 if ((p = strchr(host, ':')))
225 {
226 *p = 0;
227 port = p + 1;
228 }
229 else
230 {
231 /* Not found: set default port */
232 if (*pssl) port = "443";
233 else port = "80";
234 }
235
236 *pport = BUF_strdup(port);
237 if (!*pport) goto mem_err;
238
239 *phost = BUF_strdup(host);
240
241 if (!*phost) goto mem_err;
242
243 OPENSSL_free(buf);
244
245 return 1;
246
247 mem_err:
248 OCSPerr(OCSP_F_OCSP_PARSE_URL, ERR_R_MALLOC_FAILURE);
249 goto err;
250
251 parse_err:
252 OCSPerr(OCSP_F_OCSP_PARSE_URL, OCSP_R_ERROR_PARSING_URL);
253
254
255 err:
256 if (buf) OPENSSL_free(buf);
257 if (*ppath) OPENSSL_free(*ppath);
258 if (*pport) OPENSSL_free(*pport);
259 if (*phost) OPENSSL_free(*phost);
260 return 0;
261
262 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_prn.c b/src/lib/libcrypto/ocsp/ocsp_prn.c
deleted file mode 100644
index 4b7bc28769..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_prn.c
+++ /dev/null
@@ -1,291 +0,0 @@
1/* ocsp_prn.c */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */
4
5/* History:
6 This file was originally part of ocsp.c and was transfered to Richard
7 Levitte from CertCo by Kathy Weinhold in mid-spring 2000 to be included
8 in OpenSSL or released as a patch kit. */
9
10/* ====================================================================
11 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. All advertising materials mentioning features or use of this
26 * software must display the following acknowledgment:
27 * "This product includes software developed by the OpenSSL Project
28 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
29 *
30 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
31 * endorse or promote products derived from this software without
32 * prior written permission. For written permission, please contact
33 * openssl-core@openssl.org.
34 *
35 * 5. Products derived from this software may not be called "OpenSSL"
36 * nor may "OpenSSL" appear in their names without prior written
37 * permission of the OpenSSL Project.
38 *
39 * 6. Redistributions of any form whatsoever must retain the following
40 * acknowledgment:
41 * "This product includes software developed by the OpenSSL Project
42 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
45 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
48 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 * ====================================================================
57 *
58 * This product includes cryptographic software written by Eric Young
59 * (eay@cryptsoft.com). This product includes software written by Tim
60 * Hudson (tjh@cryptsoft.com).
61 *
62 */
63
64#include <openssl/bio.h>
65#include <openssl/err.h>
66#include <openssl/ocsp.h>
67#include <openssl/pem.h>
68
69static int ocsp_certid_print(BIO *bp, OCSP_CERTID* a, int indent)
70 {
71 BIO_printf(bp, "%*sCertificate ID:\n", indent, "");
72 indent += 2;
73 BIO_printf(bp, "%*sHash Algorithm: ", indent, "");
74 i2a_ASN1_OBJECT(bp, a->hashAlgorithm->algorithm);
75 BIO_printf(bp, "\n%*sIssuer Name Hash: ", indent, "");
76 i2a_ASN1_STRING(bp, a->issuerNameHash, V_ASN1_OCTET_STRING);
77 BIO_printf(bp, "\n%*sIssuer Key Hash: ", indent, "");
78 i2a_ASN1_STRING(bp, a->issuerKeyHash, V_ASN1_OCTET_STRING);
79 BIO_printf(bp, "\n%*sSerial Number: ", indent, "");
80 i2a_ASN1_INTEGER(bp, a->serialNumber);
81 BIO_printf(bp, "\n");
82 return 1;
83 }
84
85typedef struct
86 {
87 long t;
88 char *m;
89 } OCSP_TBLSTR;
90
91static char *table2string(long s, OCSP_TBLSTR *ts, int len)
92{
93 OCSP_TBLSTR *p;
94 for (p=ts; p < ts + len; p++)
95 if (p->t == s)
96 return p->m;
97 return "(UNKNOWN)";
98}
99
100char *OCSP_response_status_str(long s)
101 {
102 static OCSP_TBLSTR rstat_tbl[] = {
103 { OCSP_RESPONSE_STATUS_SUCCESSFUL, "successful" },
104 { OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, "malformedrequest" },
105 { OCSP_RESPONSE_STATUS_INTERNALERROR, "internalerror" },
106 { OCSP_RESPONSE_STATUS_TRYLATER, "trylater" },
107 { OCSP_RESPONSE_STATUS_SIGREQUIRED, "sigrequired" },
108 { OCSP_RESPONSE_STATUS_UNAUTHORIZED, "unauthorized" } };
109 return table2string(s, rstat_tbl, 6);
110 }
111
112char *OCSP_cert_status_str(long s)
113 {
114 static OCSP_TBLSTR cstat_tbl[] = {
115 { V_OCSP_CERTSTATUS_GOOD, "good" },
116 { V_OCSP_CERTSTATUS_REVOKED, "revoked" },
117 { V_OCSP_CERTSTATUS_UNKNOWN, "unknown" } };
118 return table2string(s, cstat_tbl, 3);
119 }
120
121char *OCSP_crl_reason_str(long s)
122 {
123 OCSP_TBLSTR reason_tbl[] = {
124 { OCSP_REVOKED_STATUS_UNSPECIFIED, "unspecified" },
125 { OCSP_REVOKED_STATUS_KEYCOMPROMISE, "keyCompromise" },
126 { OCSP_REVOKED_STATUS_CACOMPROMISE, "cACompromise" },
127 { OCSP_REVOKED_STATUS_AFFILIATIONCHANGED, "affiliationChanged" },
128 { OCSP_REVOKED_STATUS_SUPERSEDED, "superseded" },
129 { OCSP_REVOKED_STATUS_CESSATIONOFOPERATION, "cessationOfOperation" },
130 { OCSP_REVOKED_STATUS_CERTIFICATEHOLD, "certificateHold" },
131 { OCSP_REVOKED_STATUS_REMOVEFROMCRL, "removeFromCRL" } };
132 return table2string(s, reason_tbl, 8);
133 }
134
135int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST* o, unsigned long flags)
136 {
137 int i;
138 long l;
139 OCSP_CERTID* cid = NULL;
140 OCSP_ONEREQ *one = NULL;
141 OCSP_REQINFO *inf = o->tbsRequest;
142 OCSP_SIGNATURE *sig = o->optionalSignature;
143
144 if (BIO_write(bp,"OCSP Request Data:\n",19) <= 0) goto err;
145 l=ASN1_INTEGER_get(inf->version);
146 if (BIO_printf(bp," Version: %lu (0x%lx)",l+1,l) <= 0) goto err;
147 if (inf->requestorName != NULL)
148 {
149 if (BIO_write(bp,"\n Requestor Name: ",21) <= 0)
150 goto err;
151 GENERAL_NAME_print(bp, inf->requestorName);
152 }
153 if (BIO_write(bp,"\n Requestor List:\n",21) <= 0) goto err;
154 for (i = 0; i < sk_OCSP_ONEREQ_num(inf->requestList); i++)
155 {
156 one = sk_OCSP_ONEREQ_value(inf->requestList, i);
157 cid = one->reqCert;
158 ocsp_certid_print(bp, cid, 8);
159 if (!X509V3_extensions_print(bp,
160 "Request Single Extensions",
161 one->singleRequestExtensions, flags, 8))
162 goto err;
163 }
164 if (!X509V3_extensions_print(bp, "Request Extensions",
165 inf->requestExtensions, flags, 4))
166 goto err;
167 if (sig)
168 {
169 X509_signature_print(bp, sig->signatureAlgorithm, sig->signature);
170 for (i=0; i<sk_X509_num(sig->certs); i++)
171 {
172 X509_print(bp, sk_X509_value(sig->certs,i));
173 PEM_write_bio_X509(bp,sk_X509_value(sig->certs,i));
174 }
175 }
176 return 1;
177err:
178 return 0;
179 }
180
181int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags)
182 {
183 int i, ret = 0;
184 long l;
185 unsigned char *p;
186 OCSP_CERTID *cid = NULL;
187 OCSP_BASICRESP *br = NULL;
188 OCSP_RESPID *rid = NULL;
189 OCSP_RESPDATA *rd = NULL;
190 OCSP_CERTSTATUS *cst = NULL;
191 OCSP_REVOKEDINFO *rev = NULL;
192 OCSP_SINGLERESP *single = NULL;
193 OCSP_RESPBYTES *rb = o->responseBytes;
194
195 if (BIO_puts(bp,"OCSP Response Data:\n") <= 0) goto err;
196 l=ASN1_ENUMERATED_get(o->responseStatus);
197 if (BIO_printf(bp," OCSP Response Status: %s (0x%x)\n",
198 OCSP_response_status_str(l), l) <= 0) goto err;
199 if (rb == NULL) return 1;
200 if (BIO_puts(bp," Response Type: ") <= 0)
201 goto err;
202 if(i2a_ASN1_OBJECT(bp, rb->responseType) <= 0)
203 goto err;
204 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic)
205 {
206 BIO_puts(bp," (unknown response type)\n");
207 return 1;
208 }
209
210 p = ASN1_STRING_data(rb->response);
211 i = ASN1_STRING_length(rb->response);
212 if (!(br = OCSP_response_get1_basic(o))) goto err;
213 rd = br->tbsResponseData;
214 l=ASN1_INTEGER_get(rd->version);
215 if (BIO_printf(bp,"\n Version: %lu (0x%lx)\n",
216 l+1,l) <= 0) goto err;
217 if (BIO_puts(bp," Responder Id: ") <= 0) goto err;
218
219 rid = rd->responderId;
220 switch (rid->type)
221 {
222 case V_OCSP_RESPID_NAME:
223 X509_NAME_print_ex(bp, rid->value.byName, 0, XN_FLAG_ONELINE);
224 break;
225 case V_OCSP_RESPID_KEY:
226 i2a_ASN1_STRING(bp, rid->value.byKey, V_ASN1_OCTET_STRING);
227 break;
228 }
229
230 if (BIO_printf(bp,"\n Produced At: ")<=0) goto err;
231 if (!ASN1_GENERALIZEDTIME_print(bp, rd->producedAt)) goto err;
232 if (BIO_printf(bp,"\n Responses:\n") <= 0) goto err;
233 for (i = 0; i < sk_OCSP_SINGLERESP_num(rd->responses); i++)
234 {
235 if (! sk_OCSP_SINGLERESP_value(rd->responses, i)) continue;
236 single = sk_OCSP_SINGLERESP_value(rd->responses, i);
237 cid = single->certId;
238 if(ocsp_certid_print(bp, cid, 4) <= 0) goto err;
239 cst = single->certStatus;
240 if (BIO_printf(bp," Cert Status: %s",
241 OCSP_cert_status_str(cst->type)) <= 0)
242 goto err;
243 if (cst->type == V_OCSP_CERTSTATUS_REVOKED)
244 {
245 rev = cst->value.revoked;
246 if (BIO_printf(bp, "\n Revocation Time: ") <= 0)
247 goto err;
248 if (!ASN1_GENERALIZEDTIME_print(bp,
249 rev->revocationTime))
250 goto err;
251 if (rev->revocationReason)
252 {
253 l=ASN1_ENUMERATED_get(rev->revocationReason);
254 if (BIO_printf(bp,
255 "\n Revocation Reason: %s (0x%x)",
256 OCSP_crl_reason_str(l), l) <= 0)
257 goto err;
258 }
259 }
260 if (BIO_printf(bp,"\n This Update: ") <= 0) goto err;
261 if (!ASN1_GENERALIZEDTIME_print(bp, single->thisUpdate))
262 goto err;
263 if (single->nextUpdate)
264 {
265 if (BIO_printf(bp,"\n Next Update: ") <= 0)goto err;
266 if (!ASN1_GENERALIZEDTIME_print(bp,single->nextUpdate))
267 goto err;
268 }
269 if (!BIO_write(bp,"\n",1)) goto err;
270 if (!X509V3_extensions_print(bp,
271 "Response Single Extensions",
272 single->singleExtensions, flags, 8))
273 goto err;
274 if (!BIO_write(bp,"\n",1)) goto err;
275 }
276 if (!X509V3_extensions_print(bp, "Response Extensions",
277 rd->responseExtensions, flags, 4))
278 if(X509_signature_print(bp, br->signatureAlgorithm, br->signature) <= 0)
279 goto err;
280
281 for (i=0; i<sk_X509_num(br->certs); i++)
282 {
283 X509_print(bp, sk_X509_value(br->certs,i));
284 PEM_write_bio_X509(bp,sk_X509_value(br->certs,i));
285 }
286
287 ret = 1;
288err:
289 OCSP_BASICRESP_free(br);
290 return ret;
291 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_srv.c b/src/lib/libcrypto/ocsp/ocsp_srv.c
deleted file mode 100644
index fffa134e75..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_srv.c
+++ /dev/null
@@ -1,264 +0,0 @@
1/* ocsp_srv.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <cryptlib.h>
61#include <openssl/objects.h>
62#include <openssl/rand.h>
63#include <openssl/x509.h>
64#include <openssl/pem.h>
65#include <openssl/x509v3.h>
66#include <openssl/ocsp.h>
67
68/* Utility functions related to sending OCSP responses and extracting
69 * relevant information from the request.
70 */
71
72int OCSP_request_onereq_count(OCSP_REQUEST *req)
73 {
74 return sk_OCSP_ONEREQ_num(req->tbsRequest->requestList);
75 }
76
77OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i)
78 {
79 return sk_OCSP_ONEREQ_value(req->tbsRequest->requestList, i);
80 }
81
82OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one)
83 {
84 return one->reqCert;
85 }
86
87int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
88 ASN1_OCTET_STRING **pikeyHash,
89 ASN1_INTEGER **pserial, OCSP_CERTID *cid)
90 {
91 if (!cid) return 0;
92 if (pmd) *pmd = cid->hashAlgorithm->algorithm;
93 if(piNameHash) *piNameHash = cid->issuerNameHash;
94 if (pikeyHash) *pikeyHash = cid->issuerKeyHash;
95 if (pserial) *pserial = cid->serialNumber;
96 return 1;
97 }
98
99int OCSP_request_is_signed(OCSP_REQUEST *req)
100 {
101 if(req->optionalSignature) return 1;
102 return 0;
103 }
104
105/* Create an OCSP response and encode an optional basic response */
106OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs)
107 {
108 OCSP_RESPONSE *rsp = NULL;
109
110 if (!(rsp = OCSP_RESPONSE_new())) goto err;
111 if (!(ASN1_ENUMERATED_set(rsp->responseStatus, status))) goto err;
112 if (!bs) return rsp;
113 if (!(rsp->responseBytes = OCSP_RESPBYTES_new())) goto err;
114 rsp->responseBytes->responseType = OBJ_nid2obj(NID_id_pkix_OCSP_basic);
115 if (!ASN1_item_pack(bs, ASN1_ITEM_rptr(OCSP_BASICRESP), &rsp->responseBytes->response))
116 goto err;
117 return rsp;
118err:
119 if (rsp) OCSP_RESPONSE_free(rsp);
120 return NULL;
121 }
122
123
124OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,
125 OCSP_CERTID *cid,
126 int status, int reason,
127 ASN1_TIME *revtime,
128 ASN1_TIME *thisupd, ASN1_TIME *nextupd)
129 {
130 OCSP_SINGLERESP *single = NULL;
131 OCSP_CERTSTATUS *cs;
132 OCSP_REVOKEDINFO *ri;
133
134 if(!rsp->tbsResponseData->responses &&
135 !(rsp->tbsResponseData->responses = sk_OCSP_SINGLERESP_new_null()))
136 goto err;
137
138 if (!(single = OCSP_SINGLERESP_new()))
139 goto err;
140
141
142
143 if (!ASN1_TIME_to_generalizedtime(thisupd, &single->thisUpdate))
144 goto err;
145 if (nextupd &&
146 !ASN1_TIME_to_generalizedtime(nextupd, &single->nextUpdate))
147 goto err;
148
149 OCSP_CERTID_free(single->certId);
150
151 if(!(single->certId = OCSP_CERTID_dup(cid)))
152 goto err;
153
154 cs = single->certStatus;
155 switch(cs->type = status)
156 {
157 case V_OCSP_CERTSTATUS_REVOKED:
158 if (!revtime)
159 {
160 OCSPerr(OCSP_F_OCSP_BASIC_ADD1_STATUS,OCSP_R_NO_REVOKED_TIME);
161 goto err;
162 }
163 if (!(cs->value.revoked = ri = OCSP_REVOKEDINFO_new())) goto err;
164 if (!ASN1_TIME_to_generalizedtime(revtime, &ri->revocationTime))
165 goto err;
166 if (reason != OCSP_REVOKED_STATUS_NOSTATUS)
167 {
168 if (!(ri->revocationReason = ASN1_ENUMERATED_new()))
169 goto err;
170 if (!(ASN1_ENUMERATED_set(ri->revocationReason,
171 reason)))
172 goto err;
173 }
174 break;
175
176 case V_OCSP_CERTSTATUS_GOOD:
177 cs->value.good = ASN1_NULL_new();
178 break;
179
180 case V_OCSP_CERTSTATUS_UNKNOWN:
181 cs->value.unknown = ASN1_NULL_new();
182 break;
183
184 default:
185 goto err;
186
187 }
188 if (!(sk_OCSP_SINGLERESP_push(rsp->tbsResponseData->responses, single)))
189 goto err;
190 return single;
191err:
192 OCSP_SINGLERESP_free(single);
193 return NULL;
194 }
195
196/* Add a certificate to an OCSP request */
197
198int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert)
199 {
200 if (!resp->certs && !(resp->certs = sk_X509_new_null()))
201 return 0;
202
203 if(!sk_X509_push(resp->certs, cert)) return 0;
204 CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
205 return 1;
206 }
207
208int OCSP_basic_sign(OCSP_BASICRESP *brsp,
209 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
210 STACK_OF(X509) *certs, unsigned long flags)
211 {
212 int i;
213 OCSP_RESPID *rid;
214
215 if (!X509_check_private_key(signer, key))
216 {
217 OCSPerr(OCSP_F_OCSP_BASIC_SIGN, OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
218 goto err;
219 }
220
221 if(!(flags & OCSP_NOCERTS))
222 {
223 if(!OCSP_basic_add1_cert(brsp, signer))
224 goto err;
225 for (i = 0; i < sk_X509_num(certs); i++)
226 {
227 X509 *tmpcert = sk_X509_value(certs, i);
228 if(!OCSP_basic_add1_cert(brsp, tmpcert))
229 goto err;
230 }
231 }
232
233 rid = brsp->tbsResponseData->responderId;
234 if (flags & OCSP_RESPID_KEY)
235 {
236 unsigned char md[SHA_DIGEST_LENGTH];
237 X509_pubkey_digest(signer, EVP_sha1(), md, NULL);
238 if (!(rid->value.byKey = ASN1_OCTET_STRING_new()))
239 goto err;
240 if (!(ASN1_OCTET_STRING_set(rid->value.byKey, md, SHA_DIGEST_LENGTH)))
241 goto err;
242 rid->type = V_OCSP_RESPID_KEY;
243 }
244 else
245 {
246 if (!X509_NAME_set(&rid->value.byName,
247 X509_get_subject_name(signer)))
248 goto err;
249 rid->type = V_OCSP_RESPID_NAME;
250 }
251
252 if (!(flags & OCSP_NOTIME) &&
253 !X509_gmtime_adj(brsp->tbsResponseData->producedAt, 0))
254 goto err;
255
256 /* Right now, I think that not doing double hashing is the right
257 thing. -- Richard Levitte */
258
259 if (!OCSP_BASICRESP_sign(brsp, key, dgst, 0)) goto err;
260
261 return 1;
262err:
263 return 0;
264 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_vfy.c b/src/lib/libcrypto/ocsp/ocsp_vfy.c
deleted file mode 100644
index 3d58dfb06c..0000000000
--- a/src/lib/libcrypto/ocsp/ocsp_vfy.c
+++ /dev/null
@@ -1,444 +0,0 @@
1/* ocsp_vfy.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/ocsp.h>
60#include <openssl/err.h>
61#include <string.h>
62
63static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
64 X509_STORE *st, unsigned long flags);
65static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id);
66static int ocsp_check_issuer(OCSP_BASICRESP *bs, STACK_OF(X509) *chain, unsigned long flags);
67static int ocsp_check_ids(STACK_OF(OCSP_SINGLERESP) *sresp, OCSP_CERTID **ret);
68static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid, STACK_OF(OCSP_SINGLERESP) *sresp);
69static int ocsp_check_delegated(X509 *x, int flags);
70static int ocsp_req_find_signer(X509 **psigner, OCSP_REQUEST *req, X509_NAME *nm, STACK_OF(X509) *certs,
71 X509_STORE *st, unsigned long flags);
72
73/* Verify a basic response message */
74
75int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
76 X509_STORE *st, unsigned long flags)
77 {
78 X509 *signer, *x;
79 STACK_OF(X509) *chain = NULL;
80 X509_STORE_CTX ctx;
81 int i, ret = 0;
82 ret = ocsp_find_signer(&signer, bs, certs, st, flags);
83 if (!ret)
84 {
85 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
86 goto end;
87 }
88 if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
89 flags |= OCSP_NOVERIFY;
90 if (!(flags & OCSP_NOSIGS))
91 {
92 EVP_PKEY *skey;
93 skey = X509_get_pubkey(signer);
94 ret = OCSP_BASICRESP_verify(bs, skey, 0);
95 EVP_PKEY_free(skey);
96 if(ret <= 0)
97 {
98 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, OCSP_R_SIGNATURE_FAILURE);
99 goto end;
100 }
101 }
102 if (!(flags & OCSP_NOVERIFY))
103 {
104 int init_res;
105 if(flags & OCSP_NOCHAIN)
106 init_res = X509_STORE_CTX_init(&ctx, st, signer, NULL);
107 else
108 init_res = X509_STORE_CTX_init(&ctx, st, signer, bs->certs);
109 if(!init_res)
110 {
111 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,ERR_R_X509_LIB);
112 goto end;
113 }
114
115 X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_OCSP_HELPER);
116 ret = X509_verify_cert(&ctx);
117 chain = X509_STORE_CTX_get1_chain(&ctx);
118 X509_STORE_CTX_cleanup(&ctx);
119 if (ret <= 0)
120 {
121 i = X509_STORE_CTX_get_error(&ctx);
122 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,OCSP_R_CERTIFICATE_VERIFY_ERROR);
123 ERR_add_error_data(2, "Verify error:",
124 X509_verify_cert_error_string(i));
125 goto end;
126 }
127 if(flags & OCSP_NOCHECKS)
128 {
129 ret = 1;
130 goto end;
131 }
132 /* At this point we have a valid certificate chain
133 * need to verify it against the OCSP issuer criteria.
134 */
135 ret = ocsp_check_issuer(bs, chain, flags);
136
137 /* If fatal error or valid match then finish */
138 if (ret != 0) goto end;
139
140 /* Easy case: explicitly trusted. Get root CA and
141 * check for explicit trust
142 */
143 if(flags & OCSP_NOEXPLICIT) goto end;
144
145 x = sk_X509_value(chain, sk_X509_num(chain) - 1);
146 if(X509_check_trust(x, NID_OCSP_sign, 0) != X509_TRUST_TRUSTED)
147 {
148 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,OCSP_R_ROOT_CA_NOT_TRUSTED);
149 goto end;
150 }
151 ret = 1;
152 }
153
154
155
156 end:
157 if(chain) sk_X509_pop_free(chain, X509_free);
158 return ret;
159 }
160
161
162static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
163 X509_STORE *st, unsigned long flags)
164 {
165 X509 *signer;
166 OCSP_RESPID *rid = bs->tbsResponseData->responderId;
167 if ((signer = ocsp_find_signer_sk(certs, rid)))
168 {
169 *psigner = signer;
170 return 2;
171 }
172 if(!(flags & OCSP_NOINTERN) &&
173 (signer = ocsp_find_signer_sk(bs->certs, rid)))
174 {
175 *psigner = signer;
176 return 1;
177 }
178 /* Maybe lookup from store if by subject name */
179
180 *psigner = NULL;
181 return 0;
182 }
183
184
185static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id)
186 {
187 int i;
188 unsigned char tmphash[SHA_DIGEST_LENGTH], *keyhash;
189 X509 *x;
190
191 /* Easy if lookup by name */
192 if (id->type == V_OCSP_RESPID_NAME)
193 return X509_find_by_subject(certs, id->value.byName);
194
195 /* Lookup by key hash */
196
197 /* If key hash isn't SHA1 length then forget it */
198 if (id->value.byKey->length != SHA_DIGEST_LENGTH) return NULL;
199 keyhash = id->value.byKey->data;
200 /* Calculate hash of each key and compare */
201 for (i = 0; i < sk_X509_num(certs); i++)
202 {
203 x = sk_X509_value(certs, i);
204 X509_pubkey_digest(x, EVP_sha1(), tmphash, NULL);
205 if(!memcmp(keyhash, tmphash, SHA_DIGEST_LENGTH))
206 return x;
207 }
208 return NULL;
209 }
210
211
212static int ocsp_check_issuer(OCSP_BASICRESP *bs, STACK_OF(X509) *chain, unsigned long flags)
213 {
214 STACK_OF(OCSP_SINGLERESP) *sresp;
215 X509 *signer, *sca;
216 OCSP_CERTID *caid = NULL;
217 int i;
218 sresp = bs->tbsResponseData->responses;
219
220 if (sk_X509_num(chain) <= 0)
221 {
222 OCSPerr(OCSP_F_OCSP_CHECK_ISSUER, OCSP_R_NO_CERTIFICATES_IN_CHAIN);
223 return -1;
224 }
225
226 /* See if the issuer IDs match. */
227 i = ocsp_check_ids(sresp, &caid);
228
229 /* If ID mismatch or other error then return */
230 if (i <= 0) return i;
231
232 signer = sk_X509_value(chain, 0);
233 /* Check to see if OCSP responder CA matches request CA */
234 if (sk_X509_num(chain) > 1)
235 {
236 sca = sk_X509_value(chain, 1);
237 i = ocsp_match_issuerid(sca, caid, sresp);
238 if (i < 0) return i;
239 if (i)
240 {
241 /* We have a match, if extensions OK then success */
242 if (ocsp_check_delegated(signer, flags)) return 1;
243 return 0;
244 }
245 }
246
247 /* Otherwise check if OCSP request signed directly by request CA */
248 return ocsp_match_issuerid(signer, caid, sresp);
249 }
250
251
252/* Check the issuer certificate IDs for equality. If there is a mismatch with the same
253 * algorithm then there's no point trying to match any certificates against the issuer.
254 * If the issuer IDs all match then we just need to check equality against one of them.
255 */
256
257static int ocsp_check_ids(STACK_OF(OCSP_SINGLERESP) *sresp, OCSP_CERTID **ret)
258 {
259 OCSP_CERTID *tmpid, *cid;
260 int i, idcount;
261
262 idcount = sk_OCSP_SINGLERESP_num(sresp);
263 if (idcount <= 0)
264 {
265 OCSPerr(OCSP_F_OCSP_CHECK_IDS, OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA);
266 return -1;
267 }
268
269 cid = sk_OCSP_SINGLERESP_value(sresp, 0)->certId;
270
271 *ret = NULL;
272
273 for (i = 1; i < idcount; i++)
274 {
275 tmpid = sk_OCSP_SINGLERESP_value(sresp, i)->certId;
276 /* Check to see if IDs match */
277 if (OCSP_id_issuer_cmp(cid, tmpid))
278 {
279 /* If algoritm mismatch let caller deal with it */
280 if (OBJ_cmp(tmpid->hashAlgorithm->algorithm,
281 cid->hashAlgorithm->algorithm))
282 return 2;
283 /* Else mismatch */
284 return 0;
285 }
286 }
287
288 /* All IDs match: only need to check one ID */
289 *ret = cid;
290 return 1;
291 }
292
293
294static int ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid,
295 STACK_OF(OCSP_SINGLERESP) *sresp)
296 {
297 /* If only one ID to match then do it */
298 if(cid)
299 {
300 const EVP_MD *dgst;
301 X509_NAME *iname;
302 int mdlen;
303 unsigned char md[EVP_MAX_MD_SIZE];
304 if (!(dgst = EVP_get_digestbyobj(cid->hashAlgorithm->algorithm)))
305 {
306 OCSPerr(OCSP_F_OCSP_MATCH_ISSUERID, OCSP_R_UNKNOWN_MESSAGE_DIGEST);
307 return -1;
308 }
309
310 mdlen = EVP_MD_size(dgst);
311 if ((cid->issuerNameHash->length != mdlen) ||
312 (cid->issuerKeyHash->length != mdlen))
313 return 0;
314 iname = X509_get_subject_name(cert);
315 if (!X509_NAME_digest(iname, dgst, md, NULL))
316 return -1;
317 if (memcmp(md, cid->issuerNameHash->data, mdlen))
318 return 0;
319 X509_pubkey_digest(cert, EVP_sha1(), md, NULL);
320 if (memcmp(md, cid->issuerKeyHash->data, mdlen))
321 return 0;
322
323 return 1;
324
325 }
326 else
327 {
328 /* We have to match the whole lot */
329 int i, ret;
330 OCSP_CERTID *tmpid;
331 for (i = 0; i < sk_OCSP_SINGLERESP_num(sresp); i++)
332 {
333 tmpid = sk_OCSP_SINGLERESP_value(sresp, i)->certId;
334 ret = ocsp_match_issuerid(cert, tmpid, NULL);
335 if (ret <= 0) return ret;
336 }
337 return 1;
338 }
339
340 }
341
342static int ocsp_check_delegated(X509 *x, int flags)
343 {
344 X509_check_purpose(x, -1, 0);
345 if ((x->ex_flags & EXFLAG_XKUSAGE) &&
346 (x->ex_xkusage & XKU_OCSP_SIGN))
347 return 1;
348 OCSPerr(OCSP_F_OCSP_CHECK_DELEGATED, OCSP_R_MISSING_OCSPSIGNING_USAGE);
349 return 0;
350 }
351
352/* Verify an OCSP request. This is fortunately much easier than OCSP
353 * response verify. Just find the signers certificate and verify it
354 * against a given trust value.
355 */
356
357int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags)
358 {
359 X509 *signer;
360 X509_NAME *nm;
361 GENERAL_NAME *gen;
362 int ret;
363 X509_STORE_CTX ctx;
364 if (!req->optionalSignature)
365 {
366 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_REQUEST_NOT_SIGNED);
367 return 0;
368 }
369 gen = req->tbsRequest->requestorName;
370 if (gen->type != GEN_DIRNAME)
371 {
372 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE);
373 return 0;
374 }
375 nm = gen->d.directoryName;
376 ret = ocsp_req_find_signer(&signer, req, nm, certs, store, flags);
377 if (ret <= 0)
378 {
379 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
380 return 0;
381 }
382 if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
383 flags |= OCSP_NOVERIFY;
384 if (!(flags & OCSP_NOSIGS))
385 {
386 EVP_PKEY *skey;
387 skey = X509_get_pubkey(signer);
388 ret = OCSP_REQUEST_verify(req, skey);
389 EVP_PKEY_free(skey);
390 if(ret <= 0)
391 {
392 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_SIGNATURE_FAILURE);
393 return 0;
394 }
395 }
396 if (!(flags & OCSP_NOVERIFY))
397 {
398 int init_res;
399 if(flags & OCSP_NOCHAIN)
400 init_res = X509_STORE_CTX_init(&ctx, store, signer, NULL);
401 else
402 init_res = X509_STORE_CTX_init(&ctx, store, signer,
403 req->optionalSignature->certs);
404 if(!init_res)
405 {
406 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY,ERR_R_X509_LIB);
407 return 0;
408 }
409
410 X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_OCSP_HELPER);
411 X509_STORE_CTX_set_trust(&ctx, X509_TRUST_OCSP_REQUEST);
412 ret = X509_verify_cert(&ctx);
413 X509_STORE_CTX_cleanup(&ctx);
414 if (ret <= 0)
415 {
416 ret = X509_STORE_CTX_get_error(&ctx);
417 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY,OCSP_R_CERTIFICATE_VERIFY_ERROR);
418 ERR_add_error_data(2, "Verify error:",
419 X509_verify_cert_error_string(ret));
420 return 0;
421 }
422 }
423 return 1;
424 }
425
426static int ocsp_req_find_signer(X509 **psigner, OCSP_REQUEST *req, X509_NAME *nm, STACK_OF(X509) *certs,
427 X509_STORE *st, unsigned long flags)
428 {
429 X509 *signer;
430 if(!(flags & OCSP_NOINTERN))
431 {
432 signer = X509_find_by_subject(req->optionalSignature->certs, nm);
433 *psigner = signer;
434 return 1;
435 }
436
437 signer = X509_find_by_subject(certs, nm);
438 if (signer)
439 {
440 *psigner = signer;
441 return 2;
442 }
443 return 0;
444 }
diff --git a/src/lib/libcrypto/opensslv.h b/src/lib/libcrypto/opensslv.h
deleted file mode 100644
index e50c1baf00..0000000000
--- a/src/lib/libcrypto/opensslv.h
+++ /dev/null
@@ -1,89 +0,0 @@
1#ifndef HEADER_OPENSSLV_H
2#define HEADER_OPENSSLV_H
3
4/* Numeric release version identifier:
5 * MNNFFPPS: 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 0x009070afL
29#ifdef OPENSSL_FIPS
30#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.7j-fips 04 May 2006"
31#else
32#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.7j 04 May 2006"
33#endif
34#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
35
36
37/* The macros below are to be used for shared library (.so, .dll, ...)
38 * versioning. That kind of versioning works a bit differently between
39 * operating systems. The most usual scheme is to set a major and a minor
40 * number, and have the runtime loader check that the major number is equal
41 * to what it was at application link time, while the minor number has to
42 * be greater or equal to what it was at application link time. With this
43 * scheme, the version number is usually part of the file name, like this:
44 *
45 * libcrypto.so.0.9
46 *
47 * Some unixen also make a softlink with the major verson number only:
48 *
49 * libcrypto.so.0
50 *
51 * On Tru64 and IRIX 6.x it works a little bit differently. There, the
52 * shared library version is stored in the file, and is actually a series
53 * of versions, separated by colons. The rightmost version present in the
54 * library when linking an application is stored in the application to be
55 * matched at run time. When the application is run, a check is done to
56 * see if the library version stored in the application matches any of the
57 * versions in the version string of the library itself.
58 * This version string can be constructed in any way, depending on what
59 * kind of matching is desired. However, to implement the same scheme as
60 * the one used in the other unixen, all compatible versions, from lowest
61 * to highest, should be part of the string. Consecutive builds would
62 * give the following versions strings:
63 *
64 * 3.0
65 * 3.0:3.1
66 * 3.0:3.1:3.2
67 * 4.0
68 * 4.0:4.1
69 *
70 * Notice how version 4 is completely incompatible with version, and
71 * therefore give the breach you can see.
72 *
73 * There may be other schemes as well that I haven't yet discovered.
74 *
75 * So, here's the way it works here: first of all, the library version
76 * number doesn't need at all to match the overall OpenSSL version.
77 * However, it's nice and more understandable if it actually does.
78 * The current library version is stored in the macro SHLIB_VERSION_NUMBER,
79 * which is just a piece of text in the format "M.m.e" (Major, minor, edit).
80 * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways,
81 * we need to keep a history of version numbers, which is done in the
82 * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and
83 * should only keep the versions that are binary compatible with the current.
84 */
85#define SHLIB_VERSION_HISTORY ""
86#define SHLIB_VERSION_NUMBER "0.9.7"
87
88
89#endif /* HEADER_OPENSSLV_H */
diff --git a/src/lib/libcrypto/ossl_typ.h b/src/lib/libcrypto/ossl_typ.h
deleted file mode 100644
index 285fd0b1d9..0000000000
--- a/src/lib/libcrypto/ossl_typ.h
+++ /dev/null
@@ -1,122 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_OPENSSL_TYPES_H
56#define HEADER_OPENSSL_TYPES_H
57
58#include <openssl/e_os2.h>
59
60#ifdef NO_ASN1_TYPEDEFS
61#define ASN1_INTEGER ASN1_STRING
62#define ASN1_ENUMERATED ASN1_STRING
63#define ASN1_BIT_STRING ASN1_STRING
64#define ASN1_OCTET_STRING ASN1_STRING
65#define ASN1_PRINTABLESTRING ASN1_STRING
66#define ASN1_T61STRING ASN1_STRING
67#define ASN1_IA5STRING ASN1_STRING
68#define ASN1_UTCTIME ASN1_STRING
69#define ASN1_GENERALIZEDTIME ASN1_STRING
70#define ASN1_TIME ASN1_STRING
71#define ASN1_GENERALSTRING ASN1_STRING
72#define ASN1_UNIVERSALSTRING ASN1_STRING
73#define ASN1_BMPSTRING ASN1_STRING
74#define ASN1_VISIBLESTRING ASN1_STRING
75#define ASN1_UTF8STRING ASN1_STRING
76#define ASN1_BOOLEAN int
77#define ASN1_NULL int
78#else
79typedef struct asn1_string_st ASN1_INTEGER;
80typedef struct asn1_string_st ASN1_ENUMERATED;
81typedef struct asn1_string_st ASN1_BIT_STRING;
82typedef struct asn1_string_st ASN1_OCTET_STRING;
83typedef struct asn1_string_st ASN1_PRINTABLESTRING;
84typedef struct asn1_string_st ASN1_T61STRING;
85typedef struct asn1_string_st ASN1_IA5STRING;
86typedef struct asn1_string_st ASN1_GENERALSTRING;
87typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
88typedef struct asn1_string_st ASN1_BMPSTRING;
89typedef struct asn1_string_st ASN1_UTCTIME;
90typedef struct asn1_string_st ASN1_TIME;
91typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
92typedef struct asn1_string_st ASN1_VISIBLESTRING;
93typedef struct asn1_string_st ASN1_UTF8STRING;
94typedef int ASN1_BOOLEAN;
95typedef int ASN1_NULL;
96#endif
97
98#ifdef OPENSSL_SYS_WIN32
99#undef X509_NAME
100#undef PKCS7_ISSUER_AND_SERIAL
101#endif
102
103typedef struct evp_cipher_st EVP_CIPHER;
104typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
105typedef struct env_md_st EVP_MD;
106typedef struct env_md_ctx_st EVP_MD_CTX;
107typedef struct evp_pkey_st EVP_PKEY;
108
109typedef struct x509_st X509;
110typedef struct X509_algor_st X509_ALGOR;
111typedef struct X509_crl_st X509_CRL;
112typedef struct X509_name_st X509_NAME;
113typedef struct x509_store_st X509_STORE;
114typedef struct x509_store_ctx_st X509_STORE_CTX;
115
116typedef struct engine_st ENGINE;
117
118 /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */
119#define DECLARE_PKCS12_STACK_OF(type) /* Nothing */
120#define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */
121
122#endif /* def HEADER_OPENSSL_TYPES_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 d330cbf9a3..0000000000
--- a/src/lib/libcrypto/pem/pem.h
+++ /dev/null
@@ -1,672 +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#ifndef OPENSSL_NO_BIO
63#include <openssl/bio.h>
64#endif
65#ifndef OPENSSL_NO_STACK
66#include <openssl/stack.h>
67#endif
68#include <openssl/evp.h>
69#include <openssl/x509.h>
70#include <openssl/pem2.h>
71#include <openssl/e_os2.h>
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77#define PEM_BUFSIZE 1024
78
79#define PEM_OBJ_UNDEF 0
80#define PEM_OBJ_X509 1
81#define PEM_OBJ_X509_REQ 2
82#define PEM_OBJ_CRL 3
83#define PEM_OBJ_SSL_SESSION 4
84#define PEM_OBJ_PRIV_KEY 10
85#define PEM_OBJ_PRIV_RSA 11
86#define PEM_OBJ_PRIV_DSA 12
87#define PEM_OBJ_PRIV_DH 13
88#define PEM_OBJ_PUB_RSA 14
89#define PEM_OBJ_PUB_DSA 15
90#define PEM_OBJ_PUB_DH 16
91#define PEM_OBJ_DHPARAMS 17
92#define PEM_OBJ_DSAPARAMS 18
93#define PEM_OBJ_PRIV_RSA_PUBLIC 19
94
95#define PEM_ERROR 30
96#define PEM_DEK_DES_CBC 40
97#define PEM_DEK_IDEA_CBC 45
98#define PEM_DEK_DES_EDE 50
99#define PEM_DEK_DES_ECB 60
100#define PEM_DEK_RSA 70
101#define PEM_DEK_RSA_MD2 80
102#define PEM_DEK_RSA_MD5 90
103
104#define PEM_MD_MD2 NID_md2
105#define PEM_MD_MD5 NID_md5
106#define PEM_MD_SHA NID_sha
107#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
108#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
109#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
110
111#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
112#define PEM_STRING_X509 "CERTIFICATE"
113#define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
114#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
115#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
116#define PEM_STRING_X509_CRL "X509 CRL"
117#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
118#define PEM_STRING_PUBLIC "PUBLIC KEY"
119#define PEM_STRING_RSA "RSA PRIVATE KEY"
120#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
121#define PEM_STRING_DSA "DSA PRIVATE KEY"
122#define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
123#define PEM_STRING_PKCS7 "PKCS7"
124#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
125#define PEM_STRING_PKCS8INF "PRIVATE KEY"
126#define PEM_STRING_DHPARAMS "DH PARAMETERS"
127#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
128#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
129
130 /* Note that this structure is initialised by PEM_SealInit and cleaned up
131 by PEM_SealFinal (at least for now) */
132typedef struct PEM_Encode_Seal_st
133 {
134 EVP_ENCODE_CTX encode;
135 EVP_MD_CTX md;
136 EVP_CIPHER_CTX cipher;
137 } PEM_ENCODE_SEAL_CTX;
138
139/* enc_type is one off */
140#define PEM_TYPE_ENCRYPTED 10
141#define PEM_TYPE_MIC_ONLY 20
142#define PEM_TYPE_MIC_CLEAR 30
143#define PEM_TYPE_CLEAR 40
144
145typedef struct pem_recip_st
146 {
147 char *name;
148 X509_NAME *dn;
149
150 int cipher;
151 int key_enc;
152 /* char iv[8]; unused and wrong size */
153 } PEM_USER;
154
155typedef struct pem_ctx_st
156 {
157 int type; /* what type of object */
158
159 struct {
160 int version;
161 int mode;
162 } proc_type;
163
164 char *domain;
165
166 struct {
167 int cipher;
168 /* unused, and wrong size
169 unsigned char iv[8]; */
170 } DEK_info;
171
172 PEM_USER *originator;
173
174 int num_recipient;
175 PEM_USER **recipient;
176
177#ifndef OPENSSL_NO_STACK
178 STACK *x509_chain; /* certificate chain */
179#else
180 char *x509_chain; /* certificate chain */
181#endif
182 EVP_MD *md; /* signature type */
183
184 int md_enc; /* is the md encrypted or not? */
185 int md_len; /* length of md_data */
186 char *md_data; /* message digest, could be pkey encrypted */
187
188 EVP_CIPHER *dec; /* date encryption cipher */
189 int key_len; /* key length */
190 unsigned char *key; /* key */
191 /* unused, and wrong size
192 unsigned char iv[8]; */
193
194
195 int data_enc; /* is the data encrypted */
196 int data_len;
197 unsigned char *data;
198 } PEM_CTX;
199
200/* These macros make the PEM_read/PEM_write functions easier to maintain and
201 * write. Now they are all implemented with either:
202 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
203 */
204
205#ifdef OPENSSL_NO_FP_API
206
207#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
208#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
209#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
210
211#else
212
213#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
214type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
215{ \
216return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
217 cb,u)); \
218} \
219
220#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
221int PEM_write_##name(FILE *fp, type *x) \
222{ \
223return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
224 NULL,NULL,0,NULL,NULL)); \
225}
226
227#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
228int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
229 unsigned char *kstr, int klen, pem_password_cb *cb, \
230 void *u) \
231 { \
232 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
233 (char *)x,enc,kstr,klen,cb,u)); \
234 }
235
236#endif
237
238#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
239type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
240{ \
241return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
242 (char **)x,cb,u)); \
243}
244
245#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
246int PEM_write_bio_##name(BIO *bp, type *x) \
247{ \
248return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
249 NULL,NULL,0,NULL,NULL)); \
250}
251
252#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
253int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
254 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
255 { \
256 return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \
257 (char *)x,enc,kstr,klen,cb,u)); \
258 }
259
260#define IMPLEMENT_PEM_write(name, type, str, asn1) \
261 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
262 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
263
264#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
265 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
266 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
267
268#define IMPLEMENT_PEM_read(name, type, str, asn1) \
269 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
270 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
271
272#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
273 IMPLEMENT_PEM_read(name, type, str, asn1) \
274 IMPLEMENT_PEM_write(name, type, str, asn1)
275
276#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
277 IMPLEMENT_PEM_read(name, type, str, asn1) \
278 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
279
280/* These are the same except they are for the declarations */
281
282#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API)
283
284#define DECLARE_PEM_read_fp(name, type) /**/
285#define DECLARE_PEM_write_fp(name, type) /**/
286#define DECLARE_PEM_write_cb_fp(name, type) /**/
287
288#else
289
290#define DECLARE_PEM_read_fp(name, type) \
291 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
292
293#define DECLARE_PEM_write_fp(name, type) \
294 int PEM_write_##name(FILE *fp, type *x);
295
296#define DECLARE_PEM_write_cb_fp(name, type) \
297 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
298 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
299
300#endif
301
302#ifndef OPENSSL_NO_BIO
303#define DECLARE_PEM_read_bio(name, type) \
304 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
305
306#define DECLARE_PEM_write_bio(name, type) \
307 int PEM_write_bio_##name(BIO *bp, type *x);
308
309#define DECLARE_PEM_write_cb_bio(name, type) \
310 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
311 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
312
313#else
314
315#define DECLARE_PEM_read_bio(name, type) /**/
316#define DECLARE_PEM_write_bio(name, type) /**/
317#define DECLARE_PEM_write_cb_bio(name, type) /**/
318
319#endif
320
321#define DECLARE_PEM_write(name, type) \
322 DECLARE_PEM_write_bio(name, type) \
323 DECLARE_PEM_write_fp(name, type)
324
325#define DECLARE_PEM_write_cb(name, type) \
326 DECLARE_PEM_write_cb_bio(name, type) \
327 DECLARE_PEM_write_cb_fp(name, type)
328
329#define DECLARE_PEM_read(name, type) \
330 DECLARE_PEM_read_bio(name, type) \
331 DECLARE_PEM_read_fp(name, type)
332
333#define DECLARE_PEM_rw(name, type) \
334 DECLARE_PEM_read(name, type) \
335 DECLARE_PEM_write(name, type)
336
337#define DECLARE_PEM_rw_cb(name, type) \
338 DECLARE_PEM_read(name, type) \
339 DECLARE_PEM_write_cb(name, type)
340
341#ifdef SSLEAY_MACROS
342
343#define PEM_write_SSL_SESSION(fp,x) \
344 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
345 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
346#define PEM_write_X509(fp,x) \
347 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
348 (char *)x, NULL,NULL,0,NULL,NULL)
349#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
350 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
351 NULL,NULL,0,NULL,NULL)
352#define PEM_write_X509_CRL(fp,x) \
353 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
354 fp,(char *)x, NULL,NULL,0,NULL,NULL)
355#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
356 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
357 (char *)x,enc,kstr,klen,cb,u)
358#define PEM_write_RSAPublicKey(fp,x) \
359 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
360 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
361#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
362 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
363 (char *)x,enc,kstr,klen,cb,u)
364#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
365 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
366 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
367 bp,(char *)x,enc,kstr,klen,cb,u)
368#define PEM_write_PKCS7(fp,x) \
369 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
370 (char *)x, NULL,NULL,0,NULL,NULL)
371#define PEM_write_DHparams(fp,x) \
372 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
373 (char *)x,NULL,NULL,0,NULL,NULL)
374
375#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
376 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
377 PEM_STRING_X509,fp, \
378 (char *)x, NULL,NULL,0,NULL,NULL)
379
380#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
381 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
382#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
383 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
384#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
385 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
386#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
387 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
388#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
389 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
390#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
391 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
392#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
393 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
394#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
395 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
396#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
397 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
398#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
399 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
400
401#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
402 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
403 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
404 (char **)x,cb,u)
405
406#define PEM_write_bio_SSL_SESSION(bp,x) \
407 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
408 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
409#define PEM_write_bio_X509(bp,x) \
410 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
411 (char *)x, NULL,NULL,0,NULL,NULL)
412#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
413 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
414 NULL,NULL,0,NULL,NULL)
415#define PEM_write_bio_X509_CRL(bp,x) \
416 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
417 bp,(char *)x, NULL,NULL,0,NULL,NULL)
418#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
419 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
420 bp,(char *)x,enc,kstr,klen,cb,u)
421#define PEM_write_bio_RSAPublicKey(bp,x) \
422 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
423 PEM_STRING_RSA_PUBLIC,\
424 bp,(char *)x,NULL,NULL,0,NULL,NULL)
425#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
426 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
427 bp,(char *)x,enc,kstr,klen,cb,u)
428#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
429 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
430 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
431 bp,(char *)x,enc,kstr,klen,cb,u)
432#define PEM_write_bio_PKCS7(bp,x) \
433 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
434 (char *)x, NULL,NULL,0,NULL,NULL)
435#define PEM_write_bio_DHparams(bp,x) \
436 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
437 bp,(char *)x,NULL,NULL,0,NULL,NULL)
438#define PEM_write_bio_DSAparams(bp,x) \
439 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
440 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
441
442#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
443 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
444 PEM_STRING_X509,bp, \
445 (char *)x, NULL,NULL,0,NULL,NULL)
446
447#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
448 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
449#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
450 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
451#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
452 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
453#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
454 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
455#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
456 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
457#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
458 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
459#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
460 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
461#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
462 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
463
464#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
465 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
466#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
467 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
468#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
469 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
470
471#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
472 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
473 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
474 (char **)x,cb,u)
475
476#endif
477
478#if 1
479/* "userdata": new with OpenSSL 0.9.4 */
480typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
481#else
482/* OpenSSL 0.9.3, 0.9.3a */
483typedef int pem_password_cb(char *buf, int size, int rwflag);
484#endif
485
486int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
487int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
488 pem_password_cb *callback,void *u);
489
490#ifndef OPENSSL_NO_BIO
491int PEM_read_bio(BIO *bp, char **name, char **header,
492 unsigned char **data,long *len);
493int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
494 long len);
495int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
496 pem_password_cb *cb, void *u);
497char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
498 pem_password_cb *cb, void *u);
499int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
500 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
501 pem_password_cb *cb, void *u);
502STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
503int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
504 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
505#endif
506
507#ifndef OPENSSL_SYS_WIN16
508int PEM_read(FILE *fp, char **name, char **header,
509 unsigned char **data,long *len);
510int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
511char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
512 pem_password_cb *cb, void *u);
513int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
514 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
515 pem_password_cb *callback, void *u);
516STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
517 pem_password_cb *cb, void *u);
518#endif
519
520int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
521 EVP_MD *md_type, unsigned char **ek, int *ekl,
522 unsigned char *iv, EVP_PKEY **pubk, int npubk);
523void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
524 unsigned char *in, int inl);
525int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
526 unsigned char *out, int *outl, EVP_PKEY *priv);
527
528void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
529void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
530int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
531 unsigned int *siglen, EVP_PKEY *pkey);
532
533int PEM_def_callback(char *buf, int num, int w, void *key);
534void PEM_proc_type(char *buf, int type);
535void PEM_dek_info(char *buf, const char *type, int len, char *str);
536
537#ifndef SSLEAY_MACROS
538
539#include <openssl/symhacks.h>
540
541DECLARE_PEM_rw(X509, X509)
542
543DECLARE_PEM_rw(X509_AUX, X509)
544
545DECLARE_PEM_rw(X509_REQ, X509_REQ)
546DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
547
548DECLARE_PEM_rw(X509_CRL, X509_CRL)
549
550DECLARE_PEM_rw(PKCS7, PKCS7)
551
552DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
553
554DECLARE_PEM_rw(PKCS8, X509_SIG)
555
556DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
557
558#ifndef OPENSSL_NO_RSA
559
560DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
561
562DECLARE_PEM_rw(RSAPublicKey, RSA)
563DECLARE_PEM_rw(RSA_PUBKEY, RSA)
564
565#endif
566
567#ifndef OPENSSL_NO_DSA
568
569DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
570
571DECLARE_PEM_rw(DSA_PUBKEY, DSA)
572
573DECLARE_PEM_rw(DSAparams, DSA)
574
575#endif
576
577#ifndef OPENSSL_NO_DH
578
579DECLARE_PEM_rw(DHparams, DH)
580
581#endif
582
583DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
584
585DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
586
587int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
588 char *kstr, int klen,
589 pem_password_cb *cb, void *u);
590int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
591 char *, int, pem_password_cb *, void *);
592int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
593 char *kstr, int klen,
594 pem_password_cb *cb, void *u);
595int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
596 char *kstr, int klen,
597 pem_password_cb *cb, void *u);
598EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
599
600int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
601 char *kstr, int klen,
602 pem_password_cb *cb, void *u);
603int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
604 char *kstr, int klen,
605 pem_password_cb *cb, void *u);
606int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
607 char *kstr, int klen,
608 pem_password_cb *cb, void *u);
609
610EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
611
612int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
613 char *kstr,int klen, pem_password_cb *cd, void *u);
614
615#endif /* SSLEAY_MACROS */
616
617
618/* BEGIN ERROR CODES */
619/* The following lines are auto generated by the script mkerr.pl. Any changes
620 * made after this point may be overwritten when the script is next run.
621 */
622void ERR_load_PEM_strings(void);
623
624/* Error codes for the PEM functions. */
625
626/* Function codes. */
627#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
628#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
629#define PEM_F_DEF_CALLBACK 100
630#define PEM_F_LOAD_IV 101
631#define PEM_F_PEM_ASN1_READ 102
632#define PEM_F_PEM_ASN1_READ_BIO 103
633#define PEM_F_PEM_ASN1_WRITE 104
634#define PEM_F_PEM_ASN1_WRITE_BIO 105
635#define PEM_F_PEM_DO_HEADER 106
636#define PEM_F_PEM_F_DO_PK8KEY_FP 122
637#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
638#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
639#define PEM_F_PEM_READ 108
640#define PEM_F_PEM_READ_BIO 109
641#define PEM_F_PEM_SEALFINAL 110
642#define PEM_F_PEM_SEALINIT 111
643#define PEM_F_PEM_SIGNFINAL 112
644#define PEM_F_PEM_WRITE 113
645#define PEM_F_PEM_WRITE_BIO 114
646#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
647#define PEM_F_PEM_X509_INFO_READ 115
648#define PEM_F_PEM_X509_INFO_READ_BIO 116
649#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
650
651/* Reason codes. */
652#define PEM_R_BAD_BASE64_DECODE 100
653#define PEM_R_BAD_DECRYPT 101
654#define PEM_R_BAD_END_LINE 102
655#define PEM_R_BAD_IV_CHARS 103
656#define PEM_R_BAD_PASSWORD_READ 104
657#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
658#define PEM_R_NOT_DEK_INFO 105
659#define PEM_R_NOT_ENCRYPTED 106
660#define PEM_R_NOT_PROC_TYPE 107
661#define PEM_R_NO_START_LINE 108
662#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
663#define PEM_R_PUBLIC_KEY_NO_RSA 110
664#define PEM_R_READ_KEY 111
665#define PEM_R_SHORT_HEADER 112
666#define PEM_R_UNSUPPORTED_CIPHER 113
667#define PEM_R_UNSUPPORTED_ENCRYPTION 114
668
669#ifdef __cplusplus
670}
671#endif
672#endif
diff --git a/src/lib/libcrypto/pem/pem2.h b/src/lib/libcrypto/pem/pem2.h
deleted file mode 100644
index f31790d69c..0000000000
--- a/src/lib/libcrypto/pem/pem2.h
+++ /dev/null
@@ -1,70 +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
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64#ifndef HEADER_PEM_H
65void ERR_load_PEM_strings(void);
66#endif
67
68#ifdef __cplusplus
69}
70#endif
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
deleted file mode 100644
index 07963314c9..0000000000
--- a/src/lib/libcrypto/pem/pem_all.c
+++ /dev/null
@@ -1,315 +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#include <openssl/fips.h>
68
69#ifndef OPENSSL_NO_RSA
70static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa);
71#endif
72#ifndef OPENSSL_NO_DSA
73static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa);
74#endif
75
76IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
77
78IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ)
79
80IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
81
82IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
83
84IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
85 PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
86
87
88#ifndef OPENSSL_NO_RSA
89
90/* We treat RSA or DSA private keys as a special case.
91 *
92 * For private keys we read in an EVP_PKEY structure with
93 * PEM_read_bio_PrivateKey() and extract the relevant private
94 * key: this means can handle "traditional" and PKCS#8 formats
95 * transparently.
96 */
97
98static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa)
99{
100 RSA *rtmp;
101 if(!key) return NULL;
102 rtmp = EVP_PKEY_get1_RSA(key);
103 EVP_PKEY_free(key);
104 if(!rtmp) return NULL;
105 if(rsa) {
106 RSA_free(*rsa);
107 *rsa = rtmp;
108 }
109 return rtmp;
110}
111
112RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb,
113 void *u)
114{
115 EVP_PKEY *pktmp;
116 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
117 return pkey_get_rsa(pktmp, rsa);
118}
119
120#ifndef OPENSSL_NO_FP_API
121
122RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
123 void *u)
124{
125 EVP_PKEY *pktmp;
126 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
127 return pkey_get_rsa(pktmp, rsa);
128}
129
130#endif
131
132#ifdef OPENSSL_FIPS
133
134int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
135 unsigned char *kstr, int klen,
136 pem_password_cb *cb, void *u)
137{
138 EVP_PKEY *k;
139 int ret;
140 k = EVP_PKEY_new();
141 if (!k)
142 return 0;
143 EVP_PKEY_set1_RSA(k, x);
144
145 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
146 EVP_PKEY_free(k);
147 return ret;
148}
149
150#ifndef OPENSSL_NO_FP_API
151int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
152 unsigned char *kstr, int klen,
153 pem_password_cb *cb, void *u)
154{
155 EVP_PKEY *k;
156 int ret;
157 k = EVP_PKEY_new();
158 if (!k)
159 return 0;
160
161 EVP_PKEY_set1_RSA(k, x);
162
163 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
164 EVP_PKEY_free(k);
165 return ret;
166}
167#endif
168
169#else
170
171IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
172
173#endif
174
175IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
176IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
177
178#endif
179
180#ifndef OPENSSL_NO_DSA
181
182static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa)
183{
184 DSA *dtmp;
185 if(!key) return NULL;
186 dtmp = EVP_PKEY_get1_DSA(key);
187 EVP_PKEY_free(key);
188 if(!dtmp) return NULL;
189 if(dsa) {
190 DSA_free(*dsa);
191 *dsa = dtmp;
192 }
193 return dtmp;
194}
195
196DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
197 void *u)
198{
199 EVP_PKEY *pktmp;
200 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
201 return pkey_get_dsa(pktmp, dsa);
202}
203
204
205#ifdef OPENSSL_FIPS
206
207int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
208 unsigned char *kstr, int klen,
209 pem_password_cb *cb, void *u)
210{
211 EVP_PKEY *k;
212 int ret;
213 k = EVP_PKEY_new();
214 if (!k)
215 return 0;
216 EVP_PKEY_set1_DSA(k, x);
217
218 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
219 EVP_PKEY_free(k);
220 return ret;
221}
222
223#ifndef OPENSSL_NO_FP_API
224int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
225 unsigned char *kstr, int klen,
226 pem_password_cb *cb, void *u)
227{
228 EVP_PKEY *k;
229 int ret;
230 k = EVP_PKEY_new();
231 if (!k)
232 return 0;
233 EVP_PKEY_set1_DSA(k, x);
234 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
235 EVP_PKEY_free(k);
236 return ret;
237}
238#endif
239
240#else
241
242IMPLEMENT_PEM_write_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
243
244#endif
245
246IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
247
248#ifndef OPENSSL_NO_FP_API
249
250DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
251 void *u)
252{
253 EVP_PKEY *pktmp;
254 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
255 return pkey_get_dsa(pktmp, dsa);
256}
257
258#endif
259
260IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
261
262#endif
263
264#ifndef OPENSSL_NO_DH
265
266IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
267
268#endif
269
270
271/* The PrivateKey case is not that straightforward.
272 * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
273 * does not work, RSA and DSA keys have specific strings.
274 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
275 * appropriate.)
276 */
277
278#ifdef OPENSSL_FIPS
279
280int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
281 unsigned char *kstr, int klen,
282 pem_password_cb *cb, void *u)
283 {
284 if (FIPS_mode())
285 return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
286 (char *)kstr, klen, cb, u);
287 else
288 return PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
289 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
290 bp,(char *)x,enc,kstr,klen,cb,u);
291 }
292
293#ifndef OPENSSL_NO_FP_API
294int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
295 unsigned char *kstr, int klen,
296 pem_password_cb *cb, void *u)
297 {
298 if (FIPS_mode())
299 return PEM_write_PKCS8PrivateKey(fp, x, enc,
300 (char *)kstr, klen, cb, u);
301 else
302 return PEM_ASN1_write((int (*)())i2d_PrivateKey,
303 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
304 fp,(char *)x,enc,kstr,klen,cb,u);
305 }
306#endif
307
308#else
309
310IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
311
312#endif
313
314IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
315
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
deleted file mode 100644
index 8527028ebc..0000000000
--- a/src/lib/libcrypto/pem/pem_err.c
+++ /dev/null
@@ -1,135 +0,0 @@
1/* crypto/pem/pem_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_PEM,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_PEM,0,reason)
70
71static ERR_STRING_DATA PEM_str_functs[]=
72 {
73{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"},
74{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"},
75{ERR_FUNC(PEM_F_DEF_CALLBACK), "DEF_CALLBACK"},
76{ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"},
77{ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"},
78{ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"},
79{ERR_FUNC(PEM_F_PEM_ASN1_WRITE), "PEM_ASN1_write"},
80{ERR_FUNC(PEM_F_PEM_ASN1_WRITE_BIO), "PEM_ASN1_write_bio"},
81{ERR_FUNC(PEM_F_PEM_DO_HEADER), "PEM_do_header"},
82{ERR_FUNC(PEM_F_PEM_F_DO_PK8KEY_FP), "PEM_F_DO_PK8KEY_FP"},
83{ERR_FUNC(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
84{ERR_FUNC(PEM_F_PEM_GET_EVP_CIPHER_INFO), "PEM_get_EVP_CIPHER_INFO"},
85{ERR_FUNC(PEM_F_PEM_READ), "PEM_read"},
86{ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"},
87{ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"},
88{ERR_FUNC(PEM_F_PEM_SEALINIT), "PEM_SealInit"},
89{ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"},
90{ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"},
91{ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"},
92{ERR_FUNC(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY), "PEM_write_bio_PKCS8PrivateKey"},
93{ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"},
94{ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"},
95{ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"},
96{0,NULL}
97 };
98
99static ERR_STRING_DATA PEM_str_reasons[]=
100 {
101{ERR_REASON(PEM_R_BAD_BASE64_DECODE) ,"bad base64 decode"},
102{ERR_REASON(PEM_R_BAD_DECRYPT) ,"bad decrypt"},
103{ERR_REASON(PEM_R_BAD_END_LINE) ,"bad end line"},
104{ERR_REASON(PEM_R_BAD_IV_CHARS) ,"bad iv chars"},
105{ERR_REASON(PEM_R_BAD_PASSWORD_READ) ,"bad password read"},
106{ERR_REASON(PEM_R_ERROR_CONVERTING_PRIVATE_KEY),"error converting private key"},
107{ERR_REASON(PEM_R_NOT_DEK_INFO) ,"not dek info"},
108{ERR_REASON(PEM_R_NOT_ENCRYPTED) ,"not encrypted"},
109{ERR_REASON(PEM_R_NOT_PROC_TYPE) ,"not proc type"},
110{ERR_REASON(PEM_R_NO_START_LINE) ,"no start line"},
111{ERR_REASON(PEM_R_PROBLEMS_GETTING_PASSWORD),"problems getting password"},
112{ERR_REASON(PEM_R_PUBLIC_KEY_NO_RSA) ,"public key no rsa"},
113{ERR_REASON(PEM_R_READ_KEY) ,"read key"},
114{ERR_REASON(PEM_R_SHORT_HEADER) ,"short header"},
115{ERR_REASON(PEM_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"},
116{ERR_REASON(PEM_R_UNSUPPORTED_ENCRYPTION),"unsupported encryption"},
117{0,NULL}
118 };
119
120#endif
121
122void ERR_load_PEM_strings(void)
123 {
124 static int init=1;
125
126 if (init)
127 {
128 init=0;
129#ifndef OPENSSL_NO_ERR
130 ERR_load_strings(0,PEM_str_functs);
131 ERR_load_strings(0,PEM_str_reasons);
132#endif
133
134 }
135 }
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
deleted file mode 100644
index 9e4af29c95..0000000000
--- a/src/lib/libcrypto/pem/pem_info.c
+++ /dev/null
@@ -1,365 +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 OPENSSL_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_last_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 OPENSSL_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 OPENSSL_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) OPENSSL_free(name);
241 if (header != NULL) OPENSSL_free(header);
242 if (data != NULL) OPENSSL_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) OPENSSL_free(name);
272 if (header != NULL) OPENSSL_free(header);
273 if (data != NULL) OPENSSL_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 weirdo 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 OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
328 buf[0]='\0';
329 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
330 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
331
332 /* use the normal code to write things out */
333 i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
334 if (i <= 0) goto err;
335 }
336 else
337 {
338 /* Add DSA/DH */
339#ifndef OPENSSL_NO_RSA
340 /* normal optionally encrypted stuff */
341 if (PEM_write_bio_RSAPrivateKey(bp,
342 xi->x_pkey->dec_pkey->pkey.rsa,
343 enc,kstr,klen,cb,u)<=0)
344 goto err;
345#endif
346 }
347 }
348
349 /* if we have a certificate then write it out now */
350 if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp,xi->x509) <= 0))
351 goto err;
352
353 /* we are ignoring anything else that is loaded into the X509_INFO
354 * structure for the moment ... as I don't need it so I'm not
355 * coding it here and Eric can do it when this makes it into the
356 * base library --tjh
357 */
358
359 ret=1;
360
361err:
362 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
363 OPENSSL_cleanse(buf,PEM_BUFSIZE);
364 return(ret);
365 }
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
deleted file mode 100644
index 82815067b3..0000000000
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ /dev/null
@@ -1,776 +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 OPENSSL_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 load_iv(char **fromp,unsigned char *to, int num);
77static int check_pem(const char *nm, const char *name);
78
79int PEM_def_callback(char *buf, int num, int w, void *key)
80 {
81#ifdef OPENSSL_NO_FP_API
82 /* We should not ever call the default callback routine from
83 * windows. */
84 PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
85 return(-1);
86#else
87 int i,j;
88 const char *prompt;
89 if(key) {
90 i=strlen(key);
91 i=(i > num)?num:i;
92 memcpy(buf,key,i);
93 return(i);
94 }
95
96 prompt=EVP_get_pw_prompt();
97 if (prompt == NULL)
98 prompt="Enter PEM pass phrase:";
99
100 for (;;)
101 {
102 i=EVP_read_pw_string(buf,num,prompt,w);
103 if (i != 0)
104 {
105 PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
106 memset(buf,0,(unsigned int)num);
107 return(-1);
108 }
109 j=strlen(buf);
110 if (j < MIN_LENGTH)
111 {
112 fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH);
113 }
114 else
115 break;
116 }
117 return(j);
118#endif
119 }
120
121void PEM_proc_type(char *buf, int type)
122 {
123 const char *str;
124
125 if (type == PEM_TYPE_ENCRYPTED)
126 str="ENCRYPTED";
127 else if (type == PEM_TYPE_MIC_CLEAR)
128 str="MIC-CLEAR";
129 else if (type == PEM_TYPE_MIC_ONLY)
130 str="MIC-ONLY";
131 else
132 str="BAD-TYPE";
133
134 BUF_strlcat(buf,"Proc-Type: 4,",PEM_BUFSIZE);
135 BUF_strlcat(buf,str,PEM_BUFSIZE);
136 BUF_strlcat(buf,"\n",PEM_BUFSIZE);
137 }
138
139void PEM_dek_info(char *buf, const char *type, int len, char *str)
140 {
141 static const unsigned char map[17]="0123456789ABCDEF";
142 long i;
143 int j;
144
145 BUF_strlcat(buf,"DEK-Info: ",PEM_BUFSIZE);
146 BUF_strlcat(buf,type,PEM_BUFSIZE);
147 BUF_strlcat(buf,",",PEM_BUFSIZE);
148 j=strlen(buf);
149 if (j + (len * 2) + 1 > PEM_BUFSIZE)
150 return;
151 for (i=0; i<len; i++)
152 {
153 buf[j+i*2] =map[(str[i]>>4)&0x0f];
154 buf[j+i*2+1]=map[(str[i] )&0x0f];
155 }
156 buf[j+i*2]='\n';
157 buf[j+i*2+1]='\0';
158 }
159
160#ifndef OPENSSL_NO_FP_API
161char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
162 pem_password_cb *cb, void *u)
163 {
164 BIO *b;
165 char *ret;
166
167 if ((b=BIO_new(BIO_s_file())) == NULL)
168 {
169 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
170 return(0);
171 }
172 BIO_set_fp(b,fp,BIO_NOCLOSE);
173 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u);
174 BIO_free(b);
175 return(ret);
176 }
177#endif
178
179static int check_pem(const char *nm, const char *name)
180{
181 /* Normal matching nm and name */
182 if (!strcmp(nm,name)) return 1;
183
184 /* Make PEM_STRING_EVP_PKEY match any private key */
185
186 if(!strcmp(nm,PEM_STRING_PKCS8) &&
187 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
188
189 if(!strcmp(nm,PEM_STRING_PKCS8INF) &&
190 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
191
192 if(!strcmp(nm,PEM_STRING_RSA) &&
193 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
194
195 if(!strcmp(nm,PEM_STRING_DSA) &&
196 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
197
198 /* Permit older strings */
199
200 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
201 !strcmp(name,PEM_STRING_X509)) return 1;
202
203 if(!strcmp(nm,PEM_STRING_X509_REQ_OLD) &&
204 !strcmp(name,PEM_STRING_X509_REQ)) return 1;
205
206 /* Allow normal certs to be read as trusted certs */
207 if(!strcmp(nm,PEM_STRING_X509) &&
208 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
209
210 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
211 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
212
213 /* Some CAs use PKCS#7 with CERTIFICATE headers */
214 if(!strcmp(nm, PEM_STRING_X509) &&
215 !strcmp(name, PEM_STRING_PKCS7)) return 1;
216
217 return 0;
218}
219
220int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
221 pem_password_cb *cb, void *u)
222 {
223 EVP_CIPHER_INFO cipher;
224 char *nm=NULL,*header=NULL;
225 unsigned char *data=NULL;
226 long len;
227 int ret = 0;
228
229 for (;;)
230 {
231 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) {
232 if(ERR_GET_REASON(ERR_peek_error()) ==
233 PEM_R_NO_START_LINE)
234 ERR_add_error_data(2, "Expecting: ", name);
235 return 0;
236 }
237 if(check_pem(nm, name)) break;
238 OPENSSL_free(nm);
239 OPENSSL_free(header);
240 OPENSSL_free(data);
241 }
242 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
243 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
244
245 *pdata = data;
246 *plen = len;
247
248 if (pnm)
249 *pnm = nm;
250
251 ret = 1;
252
253err:
254 if (!ret || !pnm) OPENSSL_free(nm);
255 OPENSSL_free(header);
256 if (!ret) OPENSSL_free(data);
257 return ret;
258 }
259
260#ifndef OPENSSL_NO_FP_API
261int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
262 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
263 pem_password_cb *callback, void *u)
264 {
265 BIO *b;
266 int ret;
267
268 if ((b=BIO_new(BIO_s_file())) == NULL)
269 {
270 PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB);
271 return(0);
272 }
273 BIO_set_fp(b,fp,BIO_NOCLOSE);
274 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u);
275 BIO_free(b);
276 return(ret);
277 }
278#endif
279
280int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
281 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
282 pem_password_cb *callback, void *u)
283 {
284 EVP_CIPHER_CTX ctx;
285 int dsize=0,i,j,ret=0;
286 unsigned char *p,*data=NULL;
287 const char *objstr=NULL;
288 char buf[PEM_BUFSIZE];
289 unsigned char key[EVP_MAX_KEY_LENGTH];
290 unsigned char iv[EVP_MAX_IV_LENGTH];
291
292 if (enc != NULL)
293 {
294 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
295 if (objstr == NULL)
296 {
297 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
298 goto err;
299 }
300 }
301
302 if ((dsize=i2d(x,NULL)) < 0)
303 {
304 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_ASN1_LIB);
305 dsize=0;
306 goto err;
307 }
308 /* dzise + 8 bytes are needed */
309 /* actually it needs the cipher block size extra... */
310 data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20);
311 if (data == NULL)
312 {
313 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
314 goto err;
315 }
316 p=data;
317 i=i2d(x,&p);
318
319 if (enc != NULL)
320 {
321 if (kstr == NULL)
322 {
323 if (callback == NULL)
324 klen=PEM_def_callback(buf,PEM_BUFSIZE,1,u);
325 else
326 klen=(*callback)(buf,PEM_BUFSIZE,1,u);
327 if (klen <= 0)
328 {
329 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
330 goto err;
331 }
332#ifdef CHARSET_EBCDIC
333 /* Convert the pass phrase from EBCDIC */
334 ebcdic2ascii(buf, buf, klen);
335#endif
336 kstr=(unsigned char *)buf;
337 }
338 RAND_add(data,i,0);/* put in the RSA key. */
339 OPENSSL_assert(enc->iv_len <= sizeof iv);
340 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */
341 goto err;
342 /* The 'iv' is used as the iv and as a salt. It is
343 * NOT taken from the BytesToKey function */
344 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
345
346 if (kstr == (unsigned char *)buf) OPENSSL_cleanse(buf,PEM_BUFSIZE);
347
348 OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
349
350 buf[0]='\0';
351 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
352 PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
353 /* k=strlen(buf); */
354
355 EVP_CIPHER_CTX_init(&ctx);
356 EVP_EncryptInit_ex(&ctx,enc,NULL,key,iv);
357 EVP_EncryptUpdate(&ctx,data,&j,data,i);
358 EVP_EncryptFinal_ex(&ctx,&(data[j]),&i);
359 EVP_CIPHER_CTX_cleanup(&ctx);
360 i+=j;
361 ret=1;
362 }
363 else
364 {
365 ret=1;
366 buf[0]='\0';
367 }
368 i=PEM_write_bio(bp,name,buf,data,i);
369 if (i <= 0) ret=0;
370err:
371 OPENSSL_cleanse(key,sizeof(key));
372 OPENSSL_cleanse(iv,sizeof(iv));
373 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
374 OPENSSL_cleanse(buf,PEM_BUFSIZE);
375 if (data != NULL)
376 {
377 OPENSSL_cleanse(data,(unsigned int)dsize);
378 OPENSSL_free(data);
379 }
380 return(ret);
381 }
382
383int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
384 pem_password_cb *callback,void *u)
385 {
386 int i,j,o,klen;
387 long len;
388 EVP_CIPHER_CTX ctx;
389 unsigned char key[EVP_MAX_KEY_LENGTH];
390 char buf[PEM_BUFSIZE];
391
392 len= *plen;
393
394 if (cipher->cipher == NULL) return(1);
395 if (callback == NULL)
396 klen=PEM_def_callback(buf,PEM_BUFSIZE,0,u);
397 else
398 klen=callback(buf,PEM_BUFSIZE,0,u);
399 if (klen <= 0)
400 {
401 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
402 return(0);
403 }
404#ifdef CHARSET_EBCDIC
405 /* Convert the pass phrase from EBCDIC */
406 ebcdic2ascii(buf, buf, klen);
407#endif
408
409 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
410 (unsigned char *)buf,klen,1,key,NULL);
411
412 j=(int)len;
413 EVP_CIPHER_CTX_init(&ctx);
414 EVP_DecryptInit_ex(&ctx,cipher->cipher,NULL, key,&(cipher->iv[0]));
415 EVP_DecryptUpdate(&ctx,data,&i,data,j);
416 o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j);
417 EVP_CIPHER_CTX_cleanup(&ctx);
418 OPENSSL_cleanse((char *)buf,sizeof(buf));
419 OPENSSL_cleanse((char *)key,sizeof(key));
420 j+=i;
421 if (!o)
422 {
423 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT);
424 return(0);
425 }
426 *plen=j;
427 return(1);
428 }
429
430int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
431 {
432 int o;
433 const EVP_CIPHER *enc=NULL;
434 char *p,c;
435 char **header_pp = &header;
436
437 cipher->cipher=NULL;
438 if ((header == NULL) || (*header == '\0') || (*header == '\n'))
439 return(1);
440 if (strncmp(header,"Proc-Type: ",11) != 0)
441 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); }
442 header+=11;
443 if (*header != '4') return(0); header++;
444 if (*header != ',') return(0); header++;
445 if (strncmp(header,"ENCRYPTED",9) != 0)
446 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); }
447 for (; (*header != '\n') && (*header != '\0'); header++)
448 ;
449 if (*header == '\0')
450 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); }
451 header++;
452 if (strncmp(header,"DEK-Info: ",10) != 0)
453 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); }
454 header+=10;
455
456 p=header;
457 for (;;)
458 {
459 c= *header;
460#ifndef CHARSET_EBCDIC
461 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
462 ((c >= '0') && (c <= '9'))))
463 break;
464#else
465 if (!( isupper(c) || (c == '-') ||
466 isdigit(c)))
467 break;
468#endif
469 header++;
470 }
471 *header='\0';
472 o=OBJ_sn2nid(p);
473 cipher->cipher=enc=EVP_get_cipherbyname(p);
474 *header=c;
475 header++;
476
477 if (enc == NULL)
478 {
479 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION);
480 return(0);
481 }
482 if (!load_iv(header_pp,&(cipher->iv[0]),enc->iv_len))
483 return(0);
484
485 return(1);
486 }
487
488static int load_iv(char **fromp, unsigned char *to, int num)
489 {
490 int v,i;
491 char *from;
492
493 from= *fromp;
494 for (i=0; i<num; i++) to[i]=0;
495 num*=2;
496 for (i=0; i<num; i++)
497 {
498 if ((*from >= '0') && (*from <= '9'))
499 v= *from-'0';
500 else if ((*from >= 'A') && (*from <= 'F'))
501 v= *from-'A'+10;
502 else if ((*from >= 'a') && (*from <= 'f'))
503 v= *from-'a'+10;
504 else
505 {
506 PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS);
507 return(0);
508 }
509 from++;
510 to[i/2]|=v<<(long)((!(i&1))*4);
511 }
512
513 *fromp=from;
514 return(1);
515 }
516
517#ifndef OPENSSL_NO_FP_API
518int PEM_write(FILE *fp, char *name, char *header, unsigned char *data,
519 long len)
520 {
521 BIO *b;
522 int ret;
523
524 if ((b=BIO_new(BIO_s_file())) == NULL)
525 {
526 PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB);
527 return(0);
528 }
529 BIO_set_fp(b,fp,BIO_NOCLOSE);
530 ret=PEM_write_bio(b, name, header, data,len);
531 BIO_free(b);
532 return(ret);
533 }
534#endif
535
536int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
537 long len)
538 {
539 int nlen,n,i,j,outl;
540 unsigned char *buf = NULL;
541 EVP_ENCODE_CTX ctx;
542 int reason=ERR_R_BUF_LIB;
543
544 EVP_EncodeInit(&ctx);
545 nlen=strlen(name);
546
547 if ( (BIO_write(bp,"-----BEGIN ",11) != 11) ||
548 (BIO_write(bp,name,nlen) != nlen) ||
549 (BIO_write(bp,"-----\n",6) != 6))
550 goto err;
551
552 i=strlen(header);
553 if (i > 0)
554 {
555 if ( (BIO_write(bp,header,i) != i) ||
556 (BIO_write(bp,"\n",1) != 1))
557 goto err;
558 }
559
560 buf = OPENSSL_malloc(PEM_BUFSIZE*8);
561 if (buf == NULL)
562 {
563 reason=ERR_R_MALLOC_FAILURE;
564 goto err;
565 }
566
567 i=j=0;
568 while (len > 0)
569 {
570 n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len);
571 EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n);
572 if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl))
573 goto err;
574 i+=outl;
575 len-=n;
576 j+=n;
577 }
578 EVP_EncodeFinal(&ctx,buf,&outl);
579 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
580 OPENSSL_free(buf);
581 buf = NULL;
582 if ( (BIO_write(bp,"-----END ",9) != 9) ||
583 (BIO_write(bp,name,nlen) != nlen) ||
584 (BIO_write(bp,"-----\n",6) != 6))
585 goto err;
586 return(i+outl);
587err:
588 if (buf)
589 OPENSSL_free(buf);
590 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
591 return(0);
592 }
593
594#ifndef OPENSSL_NO_FP_API
595int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
596 long *len)
597 {
598 BIO *b;
599 int ret;
600
601 if ((b=BIO_new(BIO_s_file())) == NULL)
602 {
603 PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB);
604 return(0);
605 }
606 BIO_set_fp(b,fp,BIO_NOCLOSE);
607 ret=PEM_read_bio(b, name, header, data,len);
608 BIO_free(b);
609 return(ret);
610 }
611#endif
612
613int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
614 long *len)
615 {
616 EVP_ENCODE_CTX ctx;
617 int end=0,i,k,bl=0,hl=0,nohead=0;
618 char buf[256];
619 BUF_MEM *nameB;
620 BUF_MEM *headerB;
621 BUF_MEM *dataB,*tmpB;
622
623 nameB=BUF_MEM_new();
624 headerB=BUF_MEM_new();
625 dataB=BUF_MEM_new();
626 if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))
627 {
628 BUF_MEM_free(nameB);
629 BUF_MEM_free(headerB);
630 BUF_MEM_free(dataB);
631 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
632 return(0);
633 }
634
635 buf[254]='\0';
636 for (;;)
637 {
638 i=BIO_gets(bp,buf,254);
639
640 if (i <= 0)
641 {
642 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);
643 goto err;
644 }
645
646 while ((i >= 0) && (buf[i] <= ' ')) i--;
647 buf[++i]='\n'; buf[++i]='\0';
648
649 if (strncmp(buf,"-----BEGIN ",11) == 0)
650 {
651 i=strlen(&(buf[11]));
652
653 if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0)
654 continue;
655 if (!BUF_MEM_grow(nameB,i+9))
656 {
657 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
658 goto err;
659 }
660 memcpy(nameB->data,&(buf[11]),i-6);
661 nameB->data[i-6]='\0';
662 break;
663 }
664 }
665 hl=0;
666 if (!BUF_MEM_grow(headerB,256))
667 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
668 headerB->data[0]='\0';
669 for (;;)
670 {
671 i=BIO_gets(bp,buf,254);
672 if (i <= 0) break;
673
674 while ((i >= 0) && (buf[i] <= ' ')) i--;
675 buf[++i]='\n'; buf[++i]='\0';
676
677 if (buf[0] == '\n') break;
678 if (!BUF_MEM_grow(headerB,hl+i+9))
679 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
680 if (strncmp(buf,"-----END ",9) == 0)
681 {
682 nohead=1;
683 break;
684 }
685 memcpy(&(headerB->data[hl]),buf,i);
686 headerB->data[hl+i]='\0';
687 hl+=i;
688 }
689
690 bl=0;
691 if (!BUF_MEM_grow(dataB,1024))
692 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
693 dataB->data[0]='\0';
694 if (!nohead)
695 {
696 for (;;)
697 {
698 i=BIO_gets(bp,buf,254);
699 if (i <= 0) break;
700
701 while ((i >= 0) && (buf[i] <= ' ')) i--;
702 buf[++i]='\n'; buf[++i]='\0';
703
704 if (i != 65) end=1;
705 if (strncmp(buf,"-----END ",9) == 0)
706 break;
707 if (i > 65) break;
708 if (!BUF_MEM_grow_clean(dataB,i+bl+9))
709 {
710 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
711 goto err;
712 }
713 memcpy(&(dataB->data[bl]),buf,i);
714 dataB->data[bl+i]='\0';
715 bl+=i;
716 if (end)
717 {
718 buf[0]='\0';
719 i=BIO_gets(bp,buf,254);
720 if (i <= 0) break;
721
722 while ((i >= 0) && (buf[i] <= ' ')) i--;
723 buf[++i]='\n'; buf[++i]='\0';
724
725 break;
726 }
727 }
728 }
729 else
730 {
731 tmpB=headerB;
732 headerB=dataB;
733 dataB=tmpB;
734 bl=hl;
735 }
736 i=strlen(nameB->data);
737 if ( (strncmp(buf,"-----END ",9) != 0) ||
738 (strncmp(nameB->data,&(buf[9]),i) != 0) ||
739 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
740 {
741 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
742 goto err;
743 }
744
745 EVP_DecodeInit(&ctx);
746 i=EVP_DecodeUpdate(&ctx,
747 (unsigned char *)dataB->data,&bl,
748 (unsigned char *)dataB->data,bl);
749 if (i < 0)
750 {
751 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
752 goto err;
753 }
754 i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);
755 if (i < 0)
756 {
757 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
758 goto err;
759 }
760 bl+=k;
761
762 if (bl == 0) goto err;
763 *name=nameB->data;
764 *header=headerB->data;
765 *data=(unsigned char *)dataB->data;
766 *len=bl;
767 OPENSSL_free(nameB);
768 OPENSSL_free(headerB);
769 OPENSSL_free(dataB);
770 return(1);
771err:
772 BUF_MEM_free(nameB);
773 BUF_MEM_free(headerB);
774 BUF_MEM_free(dataB);
775 return(0);
776 }
diff --git a/src/lib/libcrypto/pem/pem_oth.c b/src/lib/libcrypto/pem/pem_oth.c
deleted file mode 100644
index 8d9064ea7c..0000000000
--- a/src/lib/libcrypto/pem/pem_oth.c
+++ /dev/null
@@ -1,85 +0,0 @@
1/* crypto/pem/pem_oth.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67
68/* Handle 'other' PEMs: not private keys */
69
70char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
71 pem_password_cb *cb, void *u)
72 {
73 unsigned char *p=NULL,*data=NULL;
74 long len;
75 char *ret=NULL;
76
77 if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
78 return NULL;
79 p = data;
80 ret=d2i(x,&p,len);
81 if (ret == NULL)
82 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
83 OPENSSL_free(data);
84 return(ret);
85 }
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c
deleted file mode 100644
index db38a2a79d..0000000000
--- a/src/lib/libcrypto/pem/pem_pk8.c
+++ /dev/null
@@ -1,243 +0,0 @@
1/* crypto/pem/pem_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pkcs12.h>
67#include <openssl/pem.h>
68
69static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder,
70 int nid, const EVP_CIPHER *enc,
71 char *kstr, int klen,
72 pem_password_cb *cb, void *u);
73static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder,
74 int nid, const EVP_CIPHER *enc,
75 char *kstr, int klen,
76 pem_password_cb *cb, void *u);
77
78/* These functions write a private key in PKCS#8 format: it is a "drop in"
79 * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
80 * is NULL then it uses the unencrypted private key form. The 'nid' versions
81 * uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
82 */
83
84int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
85 char *kstr, int klen,
86 pem_password_cb *cb, void *u)
87{
88 return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
89}
90
91int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
92 char *kstr, int klen,
93 pem_password_cb *cb, void *u)
94{
95 return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
96}
97
98int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
99 char *kstr, int klen,
100 pem_password_cb *cb, void *u)
101{
102 return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
103}
104
105int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
106 char *kstr, int klen,
107 pem_password_cb *cb, void *u)
108{
109 return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
110}
111
112static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
113 char *kstr, int klen,
114 pem_password_cb *cb, void *u)
115{
116 X509_SIG *p8;
117 PKCS8_PRIV_KEY_INFO *p8inf;
118 char buf[PEM_BUFSIZE];
119 int ret;
120 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
121 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
122 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
123 return 0;
124 }
125 if(enc || (nid != -1)) {
126 if(!kstr) {
127 if(!cb) klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u);
128 else klen = cb(buf, PEM_BUFSIZE, 1, u);
129 if(klen <= 0) {
130 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
131 PEM_R_READ_KEY);
132 PKCS8_PRIV_KEY_INFO_free(p8inf);
133 return 0;
134 }
135
136 kstr = buf;
137 }
138 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
139 if(kstr == buf) OPENSSL_cleanse(buf, klen);
140 PKCS8_PRIV_KEY_INFO_free(p8inf);
141 if(isder) ret = i2d_PKCS8_bio(bp, p8);
142 else ret = PEM_write_bio_PKCS8(bp, p8);
143 X509_SIG_free(p8);
144 return ret;
145 } else {
146 if(isder) ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
147 else ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
148 PKCS8_PRIV_KEY_INFO_free(p8inf);
149 return ret;
150 }
151}
152
153EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
154{
155 PKCS8_PRIV_KEY_INFO *p8inf = NULL;
156 X509_SIG *p8 = NULL;
157 int klen;
158 EVP_PKEY *ret;
159 char psbuf[PEM_BUFSIZE];
160 p8 = d2i_PKCS8_bio(bp, NULL);
161 if(!p8) return NULL;
162 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
163 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
164 if (klen <= 0) {
165 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
166 X509_SIG_free(p8);
167 return NULL;
168 }
169 p8inf = PKCS8_decrypt(p8, psbuf, klen);
170 X509_SIG_free(p8);
171 if(!p8inf) return NULL;
172 ret = EVP_PKCS82PKEY(p8inf);
173 PKCS8_PRIV_KEY_INFO_free(p8inf);
174 if(!ret) return NULL;
175 if(x) {
176 if(*x) EVP_PKEY_free(*x);
177 *x = ret;
178 }
179 return ret;
180}
181
182#ifndef OPENSSL_NO_FP_API
183
184int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
185 char *kstr, int klen,
186 pem_password_cb *cb, void *u)
187{
188 return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
189}
190
191int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
192 char *kstr, int klen,
193 pem_password_cb *cb, void *u)
194{
195 return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
196}
197
198int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
199 char *kstr, int klen,
200 pem_password_cb *cb, void *u)
201{
202 return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
203}
204
205int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
206 char *kstr, int klen, pem_password_cb *cb, void *u)
207{
208 return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
209}
210
211static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
212 char *kstr, int klen,
213 pem_password_cb *cb, void *u)
214{
215 BIO *bp;
216 int ret;
217 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
218 PEMerr(PEM_F_PEM_F_DO_PK8KEY_FP,ERR_R_BUF_LIB);
219 return(0);
220 }
221 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
222 BIO_free(bp);
223 return ret;
224}
225
226EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
227{
228 BIO *bp;
229 EVP_PKEY *ret;
230 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
231 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP,ERR_R_BUF_LIB);
232 return NULL;
233 }
234 ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
235 BIO_free(bp);
236 return ret;
237}
238
239#endif
240
241IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
242IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
243 PKCS8_PRIV_KEY_INFO)
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
deleted file mode 100644
index 9ecdbd5419..0000000000
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/* crypto/pem/pem_pkey.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pkcs12.h>
67#include <openssl/pem.h>
68
69
70EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
71 {
72 char *nm=NULL;
73 unsigned char *p=NULL,*data=NULL;
74 long len;
75 EVP_PKEY *ret=NULL;
76
77 if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))
78 return NULL;
79 p = data;
80
81 if (strcmp(nm,PEM_STRING_RSA) == 0)
82 ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len);
83 else if (strcmp(nm,PEM_STRING_DSA) == 0)
84 ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len);
85 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
86 PKCS8_PRIV_KEY_INFO *p8inf;
87 p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
88 if(!p8inf) goto p8err;
89 ret = EVP_PKCS82PKEY(p8inf);
90 if(x) {
91 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
92 *x = ret;
93 }
94 PKCS8_PRIV_KEY_INFO_free(p8inf);
95 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
96 PKCS8_PRIV_KEY_INFO *p8inf;
97 X509_SIG *p8;
98 int klen;
99 char psbuf[PEM_BUFSIZE];
100 p8 = d2i_X509_SIG(NULL, &p, len);
101 if(!p8) goto p8err;
102 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
103 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
104 if (klen <= 0) {
105 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
106 PEM_R_BAD_PASSWORD_READ);
107 X509_SIG_free(p8);
108 goto err;
109 }
110 p8inf = PKCS8_decrypt(p8, psbuf, klen);
111 X509_SIG_free(p8);
112 if(!p8inf) goto p8err;
113 ret = EVP_PKCS82PKEY(p8inf);
114 if(x) {
115 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
116 *x = ret;
117 }
118 PKCS8_PRIV_KEY_INFO_free(p8inf);
119 }
120p8err:
121 if (ret == NULL)
122 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
123err:
124 OPENSSL_free(nm);
125 OPENSSL_free(data);
126 return(ret);
127 }
128
129#ifndef OPENSSL_NO_FP_API
130EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
131 {
132 BIO *b;
133 EVP_PKEY *ret;
134
135 if ((b=BIO_new(BIO_s_file())) == NULL)
136 {
137 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
138 return(0);
139 }
140 BIO_set_fp(b,fp,BIO_NOCLOSE);
141 ret=PEM_read_bio_PrivateKey(b,x,cb,u);
142 BIO_free(b);
143 return(ret);
144 }
145#endif
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
deleted file mode 100644
index 56e08abd70..0000000000
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ /dev/null
@@ -1,187 +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 OPENSSL_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 *)OPENSSL_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
96 EVP_MD_CTX_init(&ctx->md);
97 EVP_SignInit(&ctx->md,md_type);
98
99 EVP_CIPHER_CTX_init(&ctx->cipher);
100 ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk);
101 if (!ret) goto err;
102
103 /* base64 encode the keys */
104 for (i=0; i<npubk; i++)
105 {
106 j=EVP_EncodeBlock((unsigned char *)s,ek[i],
107 RSA_size(pubk[i]->pkey.rsa));
108 ekl[i]=j;
109 memcpy(ek[i],s,j+1);
110 }
111
112 ret=npubk;
113err:
114 if (s != NULL) OPENSSL_free(s);
115 OPENSSL_cleanse(key,EVP_MAX_KEY_LENGTH);
116 return(ret);
117 }
118
119void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
120 unsigned char *in, int inl)
121 {
122 unsigned char buffer[1600];
123 int i,j;
124
125 *outl=0;
126 EVP_SignUpdate(&ctx->md,in,inl);
127 for (;;)
128 {
129 if (inl <= 0) break;
130 if (inl > 1200)
131 i=1200;
132 else
133 i=inl;
134 EVP_EncryptUpdate(&ctx->cipher,buffer,&j,in,i);
135 EVP_EncodeUpdate(&ctx->encode,out,&j,buffer,j);
136 *outl+=j;
137 out+=j;
138 in+=i;
139 inl-=i;
140 }
141 }
142
143int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
144 unsigned char *out, int *outl, EVP_PKEY *priv)
145 {
146 unsigned char *s=NULL;
147 int ret=0,j;
148 unsigned int i;
149
150 if (priv->type != EVP_PKEY_RSA)
151 {
152 PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA);
153 goto err;
154 }
155 i=RSA_size(priv->pkey.rsa);
156 if (i < 100) i=100;
157 s=(unsigned char *)OPENSSL_malloc(i*2);
158 if (s == NULL)
159 {
160 PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE);
161 goto err;
162 }
163
164 EVP_EncryptFinal_ex(&ctx->cipher,s,(int *)&i);
165 EVP_EncodeUpdate(&ctx->encode,out,&j,s,i);
166 *outl=j;
167 out+=j;
168 EVP_EncodeFinal(&ctx->encode,out,&j);
169 *outl+=j;
170
171 if (!EVP_SignFinal(&ctx->md,s,&i,priv)) goto err;
172 *sigl=EVP_EncodeBlock(sig,s,i);
173
174 ret=1;
175err:
176 EVP_MD_CTX_cleanup(&ctx->md);
177 EVP_CIPHER_CTX_cleanup(&ctx->cipher);
178 if (s != NULL) OPENSSL_free(s);
179 return(ret);
180 }
181#else /* !OPENSSL_NO_RSA */
182
183# if PEDANTIC
184static void *dummy=&dummy;
185# endif
186
187#endif
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c
deleted file mode 100644
index c3b9808cb2..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_ex(ctx, type, NULL);
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 *)OPENSSL_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) OPENSSL_free(m);
100 return(ret);
101 }
102
diff --git a/src/lib/libcrypto/pem/pem_x509.c b/src/lib/libcrypto/pem/pem_x509.c
deleted file mode 100644
index 19f88d8d3a..0000000000
--- a/src/lib/libcrypto/pem/pem_x509.c
+++ /dev/null
@@ -1,69 +0,0 @@
1/* pem_x509.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
69
diff --git a/src/lib/libcrypto/pem/pem_xaux.c b/src/lib/libcrypto/pem/pem_xaux.c
deleted file mode 100644
index 2f579b5421..0000000000
--- a/src/lib/libcrypto/pem/pem_xaux.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/* pem_xaux.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)
diff --git a/src/lib/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 22149c680e..0000000000
--- a/src/lib/libcrypto/perlasm/cbc.pl
+++ /dev/null
@@ -1,349 +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 &call(&label("PIC_point"));
150&set_label("PIC_point");
151 &blindpop("edx");
152 &lea("ecx",&DWP(&label("cbc_enc_jmp_table")."-".&label("PIC_point"),"edx"));
153 &mov($count,&DWP(0,"ecx",$count,4))
154 &add($count,"edx");
155 &xor("ecx","ecx");
156 &xor("edx","edx");
157 #&mov($count,&DWP(&label("cbc_enc_jmp_table"),"",$count,4));
158 &jmp_ptr($count);
159
160&set_label("ej7");
161 &xor("edx", "edx") if $ppro; # ppro friendly
162 &movb(&HB("edx"), &BP(6,$in,"",0));
163 &shl("edx",8);
164&set_label("ej6");
165 &movb(&HB("edx"), &BP(5,$in,"",0));
166&set_label("ej5");
167 &movb(&LB("edx"), &BP(4,$in,"",0));
168&set_label("ej4");
169 &mov("ecx", &DWP(0,$in,"",0));
170 &jmp(&label("ejend"));
171&set_label("ej3");
172 &movb(&HB("ecx"), &BP(2,$in,"",0));
173 &xor("ecx", "ecx") if $ppro; # ppro friendly
174 &shl("ecx",8);
175&set_label("ej2");
176 &movb(&HB("ecx"), &BP(1,$in,"",0));
177&set_label("ej1");
178 &movb(&LB("ecx"), &BP(0,$in,"",0));
179&set_label("ejend");
180
181 &xor("eax", "ecx");
182 &xor("ebx", "edx");
183
184 &bswap("eax") if $swap;
185 &bswap("ebx") if $swap;
186
187 &mov(&DWP($data_off,"esp","",0), "eax"); # put in array for call
188 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
189
190 &call($enc_func);
191
192 &mov("eax", &DWP($data_off,"esp","",0));
193 &mov("ebx", &DWP($data_off+4,"esp","",0));
194
195 &bswap("eax") if $swap;
196 &bswap("ebx") if $swap;
197
198 &mov(&DWP(0,$out,"",0),"eax");
199 &mov(&DWP(4,$out,"",0),"ebx");
200
201 &jmp(&label("finish"));
202
203 #############################################################
204 #############################################################
205 &set_label("decrypt",1);
206 # decrypt start
207 &and($count,0xfffffff8);
208 # The next 2 instructions are only for if the jz is taken
209 &mov("eax", &DWP($data_off+8,"esp","",0)); # get iv[0]
210 &mov("ebx", &DWP($data_off+12,"esp","",0)); # get iv[1]
211 &jz(&label("decrypt_finish"));
212
213 &set_label("decrypt_loop");
214 &mov("eax", &DWP(0,$in,"",0)); # load first 4 bytes
215 &mov("ebx", &DWP(4,$in,"",0)); # second 4 bytes
216
217 &bswap("eax") if $swap;
218 &bswap("ebx") if $swap;
219
220 &mov(&DWP($data_off,"esp","",0), "eax"); # put back
221 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
222
223 &call($dec_func);
224
225 &mov("eax", &DWP($data_off,"esp","",0)); # get return
226 &mov("ebx", &DWP($data_off+4,"esp","",0)); #
227
228 &bswap("eax") if $swap;
229 &bswap("ebx") if $swap;
230
231 &mov("ecx", &DWP($data_off+8,"esp","",0)); # get iv[0]
232 &mov("edx", &DWP($data_off+12,"esp","",0)); # get iv[1]
233
234 &xor("ecx", "eax");
235 &xor("edx", "ebx");
236
237 &mov("eax", &DWP(0,$in,"",0)); # get old cipher text,
238 &mov("ebx", &DWP(4,$in,"",0)); # next iv actually
239
240 &mov(&DWP(0,$out,"",0),"ecx");
241 &mov(&DWP(4,$out,"",0),"edx");
242
243 &mov(&DWP($data_off+8,"esp","",0), "eax"); # save iv
244 &mov(&DWP($data_off+12,"esp","",0), "ebx"); #
245
246 &add($in, 8);
247 &add($out, 8);
248
249 &sub($count, 8);
250 &jnz(&label("decrypt_loop"));
251############################ ENDIT #######################3
252 &set_label("decrypt_finish");
253 &mov($count, &wparam(2)); # length
254 &and($count, 7);
255 &jz(&label("finish"));
256
257 &mov("eax", &DWP(0,$in,"",0)); # load first 4 bytes
258 &mov("ebx", &DWP(4,$in,"",0)); # second 4 bytes
259
260 &bswap("eax") if $swap;
261 &bswap("ebx") if $swap;
262
263 &mov(&DWP($data_off,"esp","",0), "eax"); # put back
264 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
265
266 &call($dec_func);
267
268 &mov("eax", &DWP($data_off,"esp","",0)); # get return
269 &mov("ebx", &DWP($data_off+4,"esp","",0)); #
270
271 &bswap("eax") if $swap;
272 &bswap("ebx") if $swap;
273
274 &mov("ecx", &DWP($data_off+8,"esp","",0)); # get iv[0]
275 &mov("edx", &DWP($data_off+12,"esp","",0)); # get iv[1]
276
277 &xor("ecx", "eax");
278 &xor("edx", "ebx");
279
280 # this is for when we exit
281 &mov("eax", &DWP(0,$in,"",0)); # get old cipher text,
282 &mov("ebx", &DWP(4,$in,"",0)); # next iv actually
283
284&set_label("dj7");
285 &rotr("edx", 16);
286 &movb(&BP(6,$out,"",0), &LB("edx"));
287 &shr("edx",16);
288&set_label("dj6");
289 &movb(&BP(5,$out,"",0), &HB("edx"));
290&set_label("dj5");
291 &movb(&BP(4,$out,"",0), &LB("edx"));
292&set_label("dj4");
293 &mov(&DWP(0,$out,"",0), "ecx");
294 &jmp(&label("djend"));
295&set_label("dj3");
296 &rotr("ecx", 16);
297 &movb(&BP(2,$out,"",0), &LB("ecx"));
298 &shl("ecx",16);
299&set_label("dj2");
300 &movb(&BP(1,$in,"",0), &HB("ecx"));
301&set_label("dj1");
302 &movb(&BP(0,$in,"",0), &LB("ecx"));
303&set_label("djend");
304
305 # final iv is still in eax:ebx
306 &jmp(&label("finish"));
307
308
309############################ FINISH #######################3
310 &set_label("finish",1);
311 &mov("ecx", &wparam($iv_off)); # Get iv ptr
312
313 #################################################
314 $total=16+4;
315 $total+=4 if ($p1 > 0);
316 $total+=4 if ($p2 > 0);
317 $total+=4 if ($p3 > 0);
318 &add("esp",$total);
319
320 &mov(&DWP(0,"ecx","",0), "eax"); # save iv
321 &mov(&DWP(4,"ecx","",0), "ebx"); # save iv
322
323 &function_end_A($name);
324
325 &set_label("cbc_enc_jmp_table",1);
326 &data_word("0");
327 &data_word(&label("ej1")."-".&label("PIC_point"));
328 &data_word(&label("ej2")."-".&label("PIC_point"));
329 &data_word(&label("ej3")."-".&label("PIC_point"));
330 &data_word(&label("ej4")."-".&label("PIC_point"));
331 &data_word(&label("ej5")."-".&label("PIC_point"));
332 &data_word(&label("ej6")."-".&label("PIC_point"));
333 &data_word(&label("ej7")."-".&label("PIC_point"));
334 # not used
335 #&set_label("cbc_dec_jmp_table",1);
336 #&data_word("0");
337 #&data_word(&label("dj1")."-".&label("PIC_point"));
338 #&data_word(&label("dj2")."-".&label("PIC_point"));
339 #&data_word(&label("dj3")."-".&label("PIC_point"));
340 #&data_word(&label("dj4")."-".&label("PIC_point"));
341 #&data_word(&label("dj5")."-".&label("PIC_point"));
342 #&data_word(&label("dj6")."-".&label("PIC_point"));
343 #&data_word(&label("dj7")."-".&label("PIC_point"));
344
345 &function_end_B($name);
346
347 }
348
3491;
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 c3de90c65d..0000000000
--- a/src/lib/libcrypto/perlasm/x86asm.pl
+++ /dev/null
@@ -1,135 +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 $elf=$cpp=$sol=$aout=$win32=$gaswin=$openbsd=0;
22 if ( ($type eq "elf"))
23 { $elf=1; require "x86unix.pl"; }
24 elsif ( ($type eq "openbsd-elf"))
25 { $openbsd=$elf=1; require "x86unix.pl"; }
26 elsif ( ($type eq "openbsd-a.out"))
27 { $openbsd=1; require "x86unix.pl"; }
28 elsif ( ($type eq "a.out"))
29 { $aout=1; require "x86unix.pl"; }
30 elsif ( ($type eq "gaswin"))
31 { $gaswin=1; $aout=1; require "x86unix.pl"; }
32 elsif ( ($type eq "sol"))
33 { $sol=1; require "x86unix.pl"; }
34 elsif ( ($type eq "cpp"))
35 { $cpp=1; require "x86unix.pl"; }
36 elsif ( ($type eq "win32"))
37 { $win32=1; require "x86ms.pl"; }
38 elsif ( ($type eq "win32n"))
39 { $win32=1; require "x86nasm.pl"; }
40 else
41 {
42 print STDERR <<"EOF";
43Pick one target type from
44 elf - linux, FreeBSD etc
45 a.out - old linux
46 sol - x86 solaris
47 cpp - format so x86unix.cpp can be used
48 win32 - Windows 95/Windows NT
49 win32n - Windows 95/Windows NT NASM format
50 openbsd-elf - OpenBSD elf
51 openbsd-a.out - OpenBSD a.out
52EOF
53 exit(1);
54 }
55
56 $pic=0;
57 for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); }
58
59 &asm_init_output();
60
61&comment("Don't even think of reading this code");
62&comment("It was automatically generated by $filename");
63&comment("Which is a perl program used to generate the x86 assember for");
64&comment("any of elf, a.out, BSDI, Win32, gaswin (for GNU as on Win32) or Solaris");
65&comment("eric <eay\@cryptsoft.com>");
66&comment("");
67
68 $filename =~ s/\.pl$//;
69 &file($filename);
70 }
71
72sub asm_finish_cpp
73 {
74 return unless $cpp;
75
76 local($tmp,$i);
77 foreach $i (&get_labels())
78 {
79 $tmp.="#define $i _$i\n";
80 }
81 print <<"EOF";
82/* Run the C pre-processor over this file with one of the following defined
83 * ELF - elf object files,
84 * OUT - a.out object files,
85 * BSDI - BSDI style a.out object files
86 * SOL - Solaris style elf
87 */
88
89#define TYPE(a,b) .type a,b
90#define SIZE(a,b) .size a,b
91
92#if defined(OUT) || (defined(BSDI) && !defined(ELF))
93$tmp
94#endif
95
96#ifdef OUT
97#define OK 1
98#define ALIGN 4
99#if defined(__CYGWIN__) || defined(__DJGPP__) || defined(__MINGW32__)
100#undef SIZE
101#undef TYPE
102#define SIZE(a,b)
103#define TYPE(a,b) .def a; .scl 2; .type 32; .endef
104#endif /* __CYGWIN || __DJGPP */
105#endif
106
107#if defined(BSDI) && !defined(ELF)
108#define OK 1
109#define ALIGN 4
110#undef SIZE
111#undef TYPE
112#define SIZE(a,b)
113#define TYPE(a,b)
114#endif
115
116#if defined(ELF) || defined(SOL)
117#define OK 1
118#define ALIGN 16
119#endif
120
121#ifndef OK
122You need to define one of
123ELF - elf systems - linux-elf, NetBSD and DG-UX
124OUT - a.out systems - linux-a.out and FreeBSD
125SOL - solaris systems, which are elf with strange comment lines
126BSDI - a.out with a very primative version of as.
127#endif
128
129/* Let the Assembler begin :-) */
130EOF
131 }
132
133sub main'align() {} # swallow align statements in 0.9.7 context
134
1351;
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c
deleted file mode 100644
index 27015dd8c3..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_add.c
+++ /dev/null
@@ -1,224 +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_item_pack_safebag(void *obj, const ASN1_ITEM *it, 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_item_pack(obj, it, &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_OF(PKCS12_SAFEBAG) *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_item_pack(sk, ASN1_ITEM_rptr(PKCS12_SAFEBAGS), &p7->d.data)) {
142 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, PKCS12_R_CANT_PACK_STRUCTURE);
143 return NULL;
144 }
145 return p7;
146}
147
148/* Unpack SAFEBAGS from PKCS#7 data ContentInfo */
149STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7)
150{
151 if(!PKCS7_type_is_data(p7))
152 {
153 PKCS12err(PKCS12_F_PKCS12_UNPACK_P7DATA,PKCS12_R_CONTENT_TYPE_NOT_DATA);
154 return NULL;
155 }
156 return ASN1_item_unpack(p7->d.data, ASN1_ITEM_rptr(PKCS12_SAFEBAGS));
157}
158
159/* Turn a stack of SAFEBAGS into a PKCS#7 encrypted data ContentInfo */
160
161PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
162 unsigned char *salt, int saltlen, int iter,
163 STACK_OF(PKCS12_SAFEBAG) *bags)
164{
165 PKCS7 *p7;
166 X509_ALGOR *pbe;
167 if (!(p7 = PKCS7_new())) {
168 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
169 return NULL;
170 }
171 if(!PKCS7_set_type(p7, NID_pkcs7_encrypted)) {
172 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA,
173 PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE);
174 return NULL;
175 }
176 if (!(pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen))) {
177 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
178 return NULL;
179 }
180 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm);
181 p7->d.encrypted->enc_data->algorithm = pbe;
182 M_ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data);
183 if (!(p7->d.encrypted->enc_data->enc_data =
184 PKCS12_item_i2d_encrypt(pbe, ASN1_ITEM_rptr(PKCS12_SAFEBAGS), pass, passlen,
185 bags, 1))) {
186 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, PKCS12_R_ENCRYPT_ERROR);
187 return NULL;
188 }
189
190 return p7;
191}
192
193STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen)
194{
195 if(!PKCS7_type_is_encrypted(p7)) return NULL;
196 return PKCS12_item_decrypt_d2i(p7->d.encrypted->enc_data->algorithm,
197 ASN1_ITEM_rptr(PKCS12_SAFEBAGS),
198 pass, passlen,
199 p7->d.encrypted->enc_data->enc_data, 1);
200}
201
202PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass,
203 int passlen)
204{
205 return PKCS8_decrypt(bag->value.shkeybag, pass, passlen);
206}
207
208int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes)
209{
210 if(ASN1_item_pack(safes, ASN1_ITEM_rptr(PKCS12_AUTHSAFES),
211 &p12->authsafes->d.data))
212 return 1;
213 return 0;
214}
215
216STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12)
217{
218 if (!PKCS7_type_is_data(p12->authsafes))
219 {
220 PKCS12err(PKCS12_F_PKCS12_UNPACK_AUTHSAFES,PKCS12_R_CONTENT_TYPE_NOT_DATA);
221 return NULL;
222 }
223 return ASN1_item_unpack(p12->authsafes->d.data, ASN1_ITEM_rptr(PKCS12_AUTHSAFES));
224}
diff --git a/src/lib/libcrypto/pkcs12/p12_asn.c b/src/lib/libcrypto/pkcs12/p12_asn.c
deleted file mode 100644
index a3739fee1a..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_asn.c
+++ /dev/null
@@ -1,125 +0,0 @@
1/* p12_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/pkcs12.h>
63
64/* PKCS#12 ASN1 module */
65
66ASN1_SEQUENCE(PKCS12) = {
67 ASN1_SIMPLE(PKCS12, version, ASN1_INTEGER),
68 ASN1_SIMPLE(PKCS12, authsafes, PKCS7),
69 ASN1_OPT(PKCS12, mac, PKCS12_MAC_DATA)
70} ASN1_SEQUENCE_END(PKCS12)
71
72IMPLEMENT_ASN1_FUNCTIONS(PKCS12)
73
74ASN1_SEQUENCE(PKCS12_MAC_DATA) = {
75 ASN1_SIMPLE(PKCS12_MAC_DATA, dinfo, X509_SIG),
76 ASN1_SIMPLE(PKCS12_MAC_DATA, salt, ASN1_OCTET_STRING),
77 ASN1_OPT(PKCS12_MAC_DATA, iter, ASN1_INTEGER)
78} ASN1_SEQUENCE_END(PKCS12_MAC_DATA)
79
80IMPLEMENT_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
81
82ASN1_ADB_TEMPLATE(bag_default) = ASN1_EXP(PKCS12_BAGS, value.other, ASN1_ANY, 0);
83
84ASN1_ADB(PKCS12_BAGS) = {
85 ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.x509cert, ASN1_OCTET_STRING, 0)),
86 ADB_ENTRY(NID_x509Crl, ASN1_EXP(PKCS12_BAGS, value.x509crl, ASN1_OCTET_STRING, 0)),
87 ADB_ENTRY(NID_sdsiCertificate, ASN1_EXP(PKCS12_BAGS, value.sdsicert, ASN1_IA5STRING, 0)),
88} ASN1_ADB_END(PKCS12_BAGS, 0, type, 0, &bag_default_tt, NULL);
89
90ASN1_SEQUENCE(PKCS12_BAGS) = {
91 ASN1_SIMPLE(PKCS12_BAGS, type, ASN1_OBJECT),
92 ASN1_ADB_OBJECT(PKCS12_BAGS),
93} ASN1_SEQUENCE_END(PKCS12_BAGS)
94
95IMPLEMENT_ASN1_FUNCTIONS(PKCS12_BAGS)
96
97ASN1_ADB_TEMPLATE(safebag_default) = ASN1_EXP(PKCS12_SAFEBAG, value.other, ASN1_ANY, 0);
98
99ASN1_ADB(PKCS12_SAFEBAG) = {
100 ADB_ENTRY(NID_keyBag, ASN1_EXP(PKCS12_SAFEBAG, value.keybag, PKCS8_PRIV_KEY_INFO, 0)),
101 ADB_ENTRY(NID_pkcs8ShroudedKeyBag, ASN1_EXP(PKCS12_SAFEBAG, value.shkeybag, X509_SIG, 0)),
102 ADB_ENTRY(NID_safeContentsBag, ASN1_EXP_SET_OF(PKCS12_SAFEBAG, value.safes, PKCS12_SAFEBAG, 0)),
103 ADB_ENTRY(NID_certBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)),
104 ADB_ENTRY(NID_crlBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)),
105 ADB_ENTRY(NID_secretBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0))
106} ASN1_ADB_END(PKCS12_SAFEBAG, 0, type, 0, &safebag_default_tt, NULL);
107
108ASN1_SEQUENCE(PKCS12_SAFEBAG) = {
109 ASN1_SIMPLE(PKCS12_SAFEBAG, type, ASN1_OBJECT),
110 ASN1_ADB_OBJECT(PKCS12_SAFEBAG),
111 ASN1_SET_OF_OPT(PKCS12_SAFEBAG, attrib, X509_ATTRIBUTE)
112} ASN1_SEQUENCE_END(PKCS12_SAFEBAG)
113
114IMPLEMENT_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
115
116/* SEQUENCE OF SafeBag */
117ASN1_ITEM_TEMPLATE(PKCS12_SAFEBAGS) =
118 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, PKCS12_SAFEBAGS, PKCS12_SAFEBAG)
119ASN1_ITEM_TEMPLATE_END(PKCS12_SAFEBAGS)
120
121/* Authsafes: SEQUENCE OF PKCS7 */
122ASN1_ITEM_TEMPLATE(PKCS12_AUTHSAFES) =
123 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, PKCS12_AUTHSAFES, PKCS7)
124ASN1_ITEM_TEMPLATE_END(PKCS12_AUTHSAFES)
125
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c
deleted file mode 100644
index 026cf3826a..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_attr.c
+++ /dev/null
@@ -1,145 +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 if (X509at_add1_attr_by_NID(&bag->attrib, NID_localKeyID,
69 V_ASN1_OCTET_STRING, name, namelen))
70 return 1;
71 else
72 return 0;
73}
74
75/* Add key usage to PKCS#8 structure */
76
77int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
78{
79 unsigned char us_val;
80 us_val = (unsigned char) usage;
81 if (X509at_add1_attr_by_NID(&p8->attributes, NID_key_usage,
82 V_ASN1_BIT_STRING, &us_val, 1))
83 return 1;
84 else
85 return 0;
86}
87
88/* Add a friendlyname to a safebag */
89
90int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
91 int namelen)
92{
93 if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
94 MBSTRING_ASC, (unsigned char *)name, namelen))
95 return 1;
96 else
97 return 0;
98}
99
100
101int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
102 const unsigned char *name, int namelen)
103{
104 if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
105 MBSTRING_BMP, name, namelen))
106 return 1;
107 else
108 return 0;
109}
110
111int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
112 int namelen)
113{
114 if (X509at_add1_attr_by_NID(&bag->attrib, NID_ms_csp_name,
115 MBSTRING_ASC, (unsigned char *)name, namelen))
116 return 1;
117 else
118 return 0;
119}
120
121ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid)
122{
123 X509_ATTRIBUTE *attrib;
124 int i;
125 if (!attrs) return NULL;
126 for (i = 0; i < sk_X509_ATTRIBUTE_num (attrs); i++) {
127 attrib = sk_X509_ATTRIBUTE_value (attrs, i);
128 if (OBJ_obj2nid (attrib->object) == attr_nid) {
129 if (sk_ASN1_TYPE_num (attrib->value.set))
130 return sk_ASN1_TYPE_value(attrib->value.set, 0);
131 else return NULL;
132 }
133 }
134 return NULL;
135}
136
137char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag)
138{
139 ASN1_TYPE *atype;
140 if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) return NULL;
141 if (atype->type != V_ASN1_BMPSTRING) return NULL;
142 return uni2asc(atype->value.bmpstring->data,
143 atype->value.bmpstring->length);
144}
145
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c
deleted file mode 100644
index 003ec7a33e..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 OPENSSL_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 OPENSSL_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 OPENSSL_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, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de)
89{
90 PBEPARAM *pbe;
91 int saltlen, iter, ret;
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 ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de);
121 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
122 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH);
123 return ret;
124}
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c
deleted file mode 100644
index 40340a7bef..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_crt.c
+++ /dev/null
@@ -1,172 +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_OF(PKCS12_SAFEBAG) *bags;
69 STACK_OF(PKCS7) *safes;
70 PKCS12_SAFEBAG *bag;
71 PKCS8_PRIV_KEY_INFO *p8;
72 PKCS7 *authsafe;
73 X509 *tcert;
74 int i;
75 unsigned char keyid[EVP_MAX_MD_SIZE];
76 unsigned int keyidlen;
77
78 /* Set defaults */
79 if(!nid_cert)
80 {
81#ifdef OPENSSL_FIPS
82 if (FIPS_mode())
83 nid_cert = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
84 else
85#endif
86 nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
87 }
88 if(!nid_key) nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
89 if(!iter) iter = PKCS12_DEFAULT_ITER;
90 if(!mac_iter) mac_iter = 1;
91
92 if(!pkey || !cert) {
93 PKCS12err(PKCS12_F_PKCS12_CREATE,PKCS12_R_INVALID_NULL_ARGUMENT);
94 return NULL;
95 }
96
97 if(!X509_check_private_key(cert, pkey)) return NULL;
98
99 if(!(bags = sk_PKCS12_SAFEBAG_new_null ())) {
100 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
101 return NULL;
102 }
103
104 /* Add user certificate */
105 if(!(bag = PKCS12_x5092certbag(cert))) return NULL;
106 if(name && !PKCS12_add_friendlyname(bag, name, -1)) return NULL;
107 X509_digest(cert, EVP_sha1(), keyid, &keyidlen);
108 if(!PKCS12_add_localkeyid(bag, keyid, keyidlen)) return NULL;
109
110 if(!sk_PKCS12_SAFEBAG_push(bags, bag)) {
111 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
112 return NULL;
113 }
114
115 /* Add all other certificates */
116 if(ca) {
117 for(i = 0; i < sk_X509_num(ca); i++) {
118 tcert = sk_X509_value(ca, i);
119 if(!(bag = PKCS12_x5092certbag(tcert))) return NULL;
120 if(!sk_PKCS12_SAFEBAG_push(bags, bag)) {
121 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
122 return NULL;
123 }
124 }
125 }
126
127 /* Turn certbags into encrypted authsafe */
128 authsafe = PKCS12_pack_p7encdata (nid_cert, pass, -1, NULL, 0,
129 iter, bags);
130 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
131
132 if (!authsafe) return NULL;
133
134 if(!(safes = sk_PKCS7_new_null ())
135 || !sk_PKCS7_push(safes, authsafe)) {
136 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
137 return NULL;
138 }
139
140 /* Make a shrouded key bag */
141 if(!(p8 = EVP_PKEY2PKCS8 (pkey))) return NULL;
142 if(keytype && !PKCS8_add_keyusage(p8, keytype)) return NULL;
143 bag = PKCS12_MAKE_SHKEYBAG (nid_key, pass, -1, NULL, 0, iter, p8);
144 if(!bag) return NULL;
145 PKCS8_PRIV_KEY_INFO_free(p8);
146 if (name && !PKCS12_add_friendlyname (bag, name, -1)) return NULL;
147 if(!PKCS12_add_localkeyid (bag, keyid, keyidlen)) return NULL;
148 if(!(bags = sk_PKCS12_SAFEBAG_new_null())
149 || !sk_PKCS12_SAFEBAG_push (bags, bag)) {
150 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
151 return NULL;
152 }
153 /* Turn it into unencrypted safe bag */
154 if(!(authsafe = PKCS12_pack_p7data (bags))) return NULL;
155 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
156 if(!sk_PKCS7_push(safes, authsafe)) {
157 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
158 return NULL;
159 }
160
161 if(!(p12 = PKCS12_init (NID_pkcs7_data))) return NULL;
162
163 if(!PKCS12_pack_authsafes (p12, safes)) return NULL;
164
165 sk_PKCS7_pop_free(safes, PKCS7_free);
166
167 if(!PKCS12_set_mac (p12, pass, -1, NULL, 0, mac_iter, NULL))
168 return NULL;
169
170 return p12;
171
172}
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c
deleted file mode 100644
index b5684a83ba..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_decr.c
+++ /dev/null
@@ -1,176 +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 * OPENSSL_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 EVP_CIPHER_CTX_init(&ctx);
80 /* Decrypt data */
81 if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen,
82 algor->parameter, &ctx, en_de)) {
83 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);
84 return NULL;
85 }
86
87 if(!(out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) {
88 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE);
89 goto err;
90 }
91
92 EVP_CipherUpdate(&ctx, out, &i, in, inlen);
93 outlen = i;
94 if(!EVP_CipherFinal_ex(&ctx, out + i, &i)) {
95 OPENSSL_free(out);
96 out = NULL;
97 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR);
98 goto err;
99 }
100 outlen += i;
101 if (datalen) *datalen = outlen;
102 if (data) *data = out;
103 err:
104 EVP_CIPHER_CTX_cleanup(&ctx);
105 return out;
106
107}
108
109/* Decrypt an OCTET STRING and decode ASN1 structure
110 * if zbuf set zero buffer after use.
111 */
112
113void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
114 const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf)
115{
116 unsigned char *out, *p;
117 void *ret;
118 int outlen;
119
120 if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length,
121 &out, &outlen, 0)) {
122 PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR);
123 return NULL;
124 }
125 p = out;
126#ifdef DEBUG_DECRYPT
127 {
128 FILE *op;
129
130 char fname[30];
131 static int fnm = 1;
132 sprintf(fname, "DER%d", fnm++);
133 op = fopen(fname, "wb");
134 fwrite (p, 1, outlen, op);
135 fclose(op);
136 }
137#endif
138 ret = ASN1_item_d2i(NULL, &p, outlen, it);
139 if (zbuf) OPENSSL_cleanse(out, outlen);
140 if(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR);
141 OPENSSL_free(out);
142 return ret;
143}
144
145/* Encode ASN1 structure and encrypt, return OCTET STRING
146 * if zbuf set zero encoding.
147 */
148
149ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it,
150 const char *pass, int passlen,
151 void *obj, int zbuf)
152{
153 ASN1_OCTET_STRING *oct;
154 unsigned char *in = NULL;
155 int inlen;
156 if (!(oct = M_ASN1_OCTET_STRING_new ())) {
157 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE);
158 return NULL;
159 }
160 inlen = ASN1_item_i2d(obj, &in, it);
161 if (!in) {
162 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCODE_ERROR);
163 return NULL;
164 }
165 if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data,
166 &oct->length, 1)) {
167 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR);
168 OPENSSL_free(in);
169 return NULL;
170 }
171 if (zbuf) OPENSSL_cleanse(in, inlen);
172 OPENSSL_free(in);
173 return oct;
174}
175
176IMPLEMENT_PKCS12_STACK_OF(PKCS7)
diff --git a/src/lib/libcrypto/pkcs12/p12_init.c b/src/lib/libcrypto/pkcs12/p12_init.c
deleted file mode 100644
index 5276b12669..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_init.c
+++ /dev/null
@@ -1,92 +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 ASN1_INTEGER_set(pkcs12->version, 3);
73 pkcs12->authsafes->type = OBJ_nid2obj(mode);
74 switch (mode) {
75 case NID_pkcs7_data:
76 if (!(pkcs12->authsafes->d.data =
77 M_ASN1_OCTET_STRING_new())) {
78 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
79 goto err;
80 }
81 break;
82 default:
83 PKCS12err(PKCS12_F_PKCS12_INIT,
84 PKCS12_R_UNSUPPORTED_PKCS12_MODE);
85 goto err;
86 }
87
88 return pkcs12;
89err:
90 if (pkcs12 != NULL) PKCS12_free(pkcs12);
91 return NULL;
92}
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
deleted file mode 100644
index 9196a34b4a..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ /dev/null
@@ -1,206 +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(!pass) {
85 unipass = NULL;
86 uniplen = 0;
87 } else if (!asc2uni(pass, passlen, &unipass, &uniplen)) {
88 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE);
89 return 0;
90 }
91 ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen,
92 id, iter, n, out, md_type);
93 if(unipass) {
94 OPENSSL_cleanse(unipass, uniplen); /* Clear password from memory */
95 OPENSSL_free(unipass);
96 }
97 return ret;
98}
99
100int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
101 int saltlen, int id, int iter, int n, unsigned char *out,
102 const EVP_MD *md_type)
103{
104 unsigned char *B, *D, *I, *p, *Ai;
105 int Slen, Plen, Ilen, Ijlen;
106 int i, j, u, v;
107 BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */
108 EVP_MD_CTX ctx;
109#ifdef DEBUG_KEYGEN
110 unsigned char *tmpout = out;
111 int tmpn = n;
112#endif
113
114#if 0
115 if (!pass) {
116 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_PASSED_NULL_PARAMETER);
117 return 0;
118 }
119#endif
120
121 EVP_MD_CTX_init(&ctx);
122#ifdef DEBUG_KEYGEN
123 fprintf(stderr, "KEYGEN DEBUG\n");
124 fprintf(stderr, "ID %d, ITER %d\n", id, iter);
125 fprintf(stderr, "Password (length %d):\n", passlen);
126 h__dump(pass, passlen);
127 fprintf(stderr, "Salt (length %d):\n", saltlen);
128 h__dump(salt, saltlen);
129#endif
130 v = EVP_MD_block_size (md_type);
131 u = EVP_MD_size (md_type);
132 D = OPENSSL_malloc (v);
133 Ai = OPENSSL_malloc (u);
134 B = OPENSSL_malloc (v + 1);
135 Slen = v * ((saltlen+v-1)/v);
136 if(passlen) Plen = v * ((passlen+v-1)/v);
137 else Plen = 0;
138 Ilen = Slen + Plen;
139 I = OPENSSL_malloc (Ilen);
140 Ij = BN_new();
141 Bpl1 = BN_new();
142 if (!D || !Ai || !B || !I || !Ij || !Bpl1) {
143 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE);
144 return 0;
145 }
146 for (i = 0; i < v; i++) D[i] = id;
147 p = I;
148 for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen];
149 for (i = 0; i < Plen; i++) *p++ = pass[i % passlen];
150 for (;;) {
151 EVP_DigestInit_ex(&ctx, md_type, NULL);
152 EVP_DigestUpdate(&ctx, D, v);
153 EVP_DigestUpdate(&ctx, I, Ilen);
154 EVP_DigestFinal_ex(&ctx, Ai, NULL);
155 for (j = 1; j < iter; j++) {
156 EVP_DigestInit_ex(&ctx, md_type, NULL);
157 EVP_DigestUpdate(&ctx, Ai, u);
158 EVP_DigestFinal_ex(&ctx, Ai, NULL);
159 }
160 memcpy (out, Ai, min (n, u));
161 if (u >= n) {
162 OPENSSL_free (Ai);
163 OPENSSL_free (B);
164 OPENSSL_free (D);
165 OPENSSL_free (I);
166 BN_free (Ij);
167 BN_free (Bpl1);
168 EVP_MD_CTX_cleanup(&ctx);
169#ifdef DEBUG_KEYGEN
170 fprintf(stderr, "Output KEY (length %d)\n", tmpn);
171 h__dump(tmpout, tmpn);
172#endif
173 return 1;
174 }
175 n -= u;
176 out += u;
177 for (j = 0; j < v; j++) B[j] = Ai[j % u];
178 /* Work out B + 1 first then can use B as tmp space */
179 BN_bin2bn (B, v, Bpl1);
180 BN_add_word (Bpl1, 1);
181 for (j = 0; j < Ilen ; j+=v) {
182 BN_bin2bn (I + j, v, Ij);
183 BN_add (Ij, Ij, Bpl1);
184 BN_bn2bin (Ij, B);
185 Ijlen = BN_num_bytes (Ij);
186 /* If more than 2^(v*8) - 1 cut off MSB */
187 if (Ijlen > v) {
188 BN_bn2bin (Ij, B);
189 memcpy (I + j, B + 1, v);
190#ifndef PKCS12_BROKEN_KEYGEN
191 /* If less than v bytes pad with zeroes */
192 } else if (Ijlen < v) {
193 memset(I + j, 0, v - Ijlen);
194 BN_bn2bin(Ij, I + j + v - Ijlen);
195#endif
196 } else BN_bn2bin (Ij, I + j);
197 }
198 }
199}
200#ifdef DEBUG_KEYGEN
201void h__dump (unsigned char *p, int len)
202{
203 for (; len --; p++) fprintf(stderr, "%02X", *p);
204 fprintf(stderr, "\n");
205}
206#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c
deleted file mode 100644
index 2b31999e11..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_kiss.c
+++ /dev/null
@@ -1,297 +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_OF(PKCS12_SAFEBAG) *bags, const char *pass,
69 int passlen, EVP_PKEY **pkey, X509 **cert,
70 STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid,
71 char *keymatch);
72
73static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen,
74 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
75 ASN1_OCTET_STRING **keyid, char *keymatch);
76
77/* Parse and decrypt a PKCS#12 structure returning user key, user cert
78 * and other (CA) certs. Note either ca should be NULL, *ca should be NULL,
79 * or it should point to a valid STACK structure. pkey and cert can be
80 * passed unitialised.
81 */
82
83int PKCS12_parse (PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
84 STACK_OF(X509) **ca)
85{
86
87 /* Check for NULL PKCS12 structure */
88
89 if(!p12) {
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 if (!(*ca = sk_X509_new_null())) {
97 PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE);
98 return 0;
99 }
100 }
101
102 if(pkey) *pkey = NULL;
103 if(cert) *cert = NULL;
104
105 /* Check the mac */
106
107 /* If password is zero length or NULL then try verifying both cases
108 * to determine which password is correct. The reason for this is that
109 * under PKCS#12 password based encryption no password and a zero length
110 * password are two different things...
111 */
112
113 if(!pass || !*pass) {
114 if(PKCS12_verify_mac(p12, NULL, 0)) pass = NULL;
115 else if(PKCS12_verify_mac(p12, "", 0)) pass = "";
116 else {
117 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
118 goto err;
119 }
120 } else if (!PKCS12_verify_mac(p12, pass, -1)) {
121 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
122 goto err;
123 }
124
125 if (!parse_pk12 (p12, pass, -1, pkey, cert, ca))
126 {
127 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_PARSE_ERROR);
128 goto err;
129 }
130
131 return 1;
132
133 err:
134
135 if (pkey && *pkey) EVP_PKEY_free(*pkey);
136 if (cert && *cert) X509_free(*cert);
137 if (ca) sk_X509_pop_free(*ca, X509_free);
138 return 0;
139
140}
141
142/* Parse the outer PKCS#12 structure */
143
144static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen,
145 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
146{
147 STACK_OF(PKCS7) *asafes;
148 STACK_OF(PKCS12_SAFEBAG) *bags;
149 int i, bagnid;
150 PKCS7 *p7;
151 ASN1_OCTET_STRING *keyid = NULL;
152
153 char keymatch = 0;
154 if (!(asafes = PKCS12_unpack_authsafes (p12))) return 0;
155 for (i = 0; i < sk_PKCS7_num (asafes); i++) {
156 p7 = sk_PKCS7_value (asafes, i);
157 bagnid = OBJ_obj2nid (p7->type);
158 if (bagnid == NID_pkcs7_data) {
159 bags = PKCS12_unpack_p7data(p7);
160 } else if (bagnid == NID_pkcs7_encrypted) {
161 bags = PKCS12_unpack_p7encdata(p7, pass, passlen);
162 } else continue;
163 if (!bags) {
164 sk_PKCS7_pop_free(asafes, PKCS7_free);
165 return 0;
166 }
167 if (!parse_bags(bags, pass, passlen, pkey, cert, ca,
168 &keyid, &keymatch)) {
169 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
170 sk_PKCS7_pop_free(asafes, PKCS7_free);
171 return 0;
172 }
173 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
174 }
175 sk_PKCS7_pop_free(asafes, PKCS7_free);
176 if (keyid) M_ASN1_OCTET_STRING_free(keyid);
177 return 1;
178}
179
180
181static int parse_bags (STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass,
182 int passlen, EVP_PKEY **pkey, X509 **cert,
183 STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid,
184 char *keymatch)
185{
186 int i;
187 for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) {
188 if (!parse_bag(sk_PKCS12_SAFEBAG_value (bags, i),
189 pass, passlen, pkey, cert, ca, keyid,
190 keymatch)) return 0;
191 }
192 return 1;
193}
194
195#define MATCH_KEY 0x1
196#define MATCH_CERT 0x2
197#define MATCH_ALL 0x3
198
199static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
200 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
201 ASN1_OCTET_STRING **keyid,
202 char *keymatch)
203{
204 PKCS8_PRIV_KEY_INFO *p8;
205 X509 *x509;
206 ASN1_OCTET_STRING *lkey = NULL, *ckid = NULL;
207 ASN1_TYPE *attrib;
208 ASN1_BMPSTRING *fname = NULL;
209
210 if ((attrib = PKCS12_get_attr (bag, NID_friendlyName)))
211 fname = attrib->value.bmpstring;
212
213 if ((attrib = PKCS12_get_attr (bag, NID_localKeyID))) {
214 lkey = attrib->value.octet_string;
215 ckid = lkey;
216 }
217
218 /* Check for any local key id matching (if needed) */
219 if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) {
220 if (*keyid) {
221 if (M_ASN1_OCTET_STRING_cmp(*keyid, lkey)) lkey = NULL;
222 } else {
223 if (!(*keyid = M_ASN1_OCTET_STRING_dup(lkey))) {
224 PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE);
225 return 0;
226 }
227 }
228 }
229
230 switch (M_PKCS12_bag_type(bag))
231 {
232 case NID_keyBag:
233 if (!lkey || !pkey) return 1;
234 if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag))) return 0;
235 *keymatch |= MATCH_KEY;
236 break;
237
238 case NID_pkcs8ShroudedKeyBag:
239 if (!lkey || !pkey) return 1;
240 if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen)))
241 return 0;
242 *pkey = EVP_PKCS82PKEY(p8);
243 PKCS8_PRIV_KEY_INFO_free(p8);
244 if (!(*pkey)) return 0;
245 *keymatch |= MATCH_KEY;
246 break;
247
248 case NID_certBag:
249 if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate )
250 return 1;
251 if (!(x509 = PKCS12_certbag2x509(bag))) return 0;
252 if(ckid)
253 {
254 if (!X509_keyid_set1(x509, ckid->data, ckid->length))
255 {
256 X509_free(x509);
257 return 0;
258 }
259 }
260 if(fname) {
261 int len, r;
262 unsigned char *data;
263 len = ASN1_STRING_to_UTF8(&data, fname);
264 if(len > 0) {
265 r = X509_alias_set1(x509, data, len);
266 OPENSSL_free(data);
267 if (!r)
268 {
269 X509_free(x509);
270 return 0;
271 }
272 }
273 }
274
275
276 if (lkey) {
277 *keymatch |= MATCH_CERT;
278 if (cert) *cert = x509;
279 else X509_free(x509);
280 } else {
281 if(ca) sk_X509_push (*ca, x509);
282 else X509_free(x509);
283 }
284 break;
285
286 case NID_safeContentsBag:
287 return parse_bags(bag->value.safes, pass, passlen,
288 pkey, cert, ca, keyid, keymatch);
289 break;
290
291 default:
292 return 1;
293 break;
294 }
295 return 1;
296}
297
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
deleted file mode 100644
index 140d21155e..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_mutl.c
+++ /dev/null
@@ -1,182 +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 OPENSSL_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
75 if (!PKCS7_type_is_data(p12->authsafes))
76 {
77 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_CONTENT_TYPE_NOT_DATA);
78 return 0;
79 }
80
81 salt = p12->mac->salt->data;
82 saltlen = p12->mac->salt->length;
83 if (!p12->mac->iter) iter = 1;
84 else iter = ASN1_INTEGER_get (p12->mac->iter);
85 if(!(md_type =
86 EVP_get_digestbyobj (p12->mac->dinfo->algor->algorithm))) {
87 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
88 return 0;
89 }
90 if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
91 PKCS12_MAC_KEY_LENGTH, key, md_type)) {
92 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR);
93 return 0;
94 }
95 HMAC_CTX_init(&hmac);
96 HMAC_Init_ex(&hmac, key, PKCS12_MAC_KEY_LENGTH, md_type, NULL);
97 HMAC_Update(&hmac, p12->authsafes->d.data->data,
98 p12->authsafes->d.data->length);
99 HMAC_Final(&hmac, mac, maclen);
100 HMAC_CTX_cleanup(&hmac);
101 return 1;
102}
103
104/* Verify the mac */
105int PKCS12_verify_mac (PKCS12 *p12, const char *pass, int passlen)
106{
107 unsigned char mac[EVP_MAX_MD_SIZE];
108 unsigned int maclen;
109 if(p12->mac == NULL) {
110 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_ABSENT);
111 return 0;
112 }
113 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
114 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_GENERATION_ERROR);
115 return 0;
116 }
117 if ((maclen != (unsigned int)p12->mac->dinfo->digest->length)
118 || memcmp (mac, p12->mac->dinfo->digest->data, maclen)) return 0;
119 return 1;
120}
121
122/* Set a mac */
123
124int PKCS12_set_mac (PKCS12 *p12, const char *pass, int passlen,
125 unsigned char *salt, int saltlen, int iter, const EVP_MD *md_type)
126{
127 unsigned char mac[EVP_MAX_MD_SIZE];
128 unsigned int maclen;
129
130 if (!md_type) md_type = EVP_sha1();
131 if (PKCS12_setup_mac (p12, iter, salt, saltlen, md_type) ==
132 PKCS12_ERROR) {
133 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_SETUP_ERROR);
134 return 0;
135 }
136 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
137 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR);
138 return 0;
139 }
140 if (!(M_ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) {
141 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR);
142 return 0;
143 }
144 return 1;
145}
146
147/* Set up a mac structure */
148int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
149 const EVP_MD *md_type)
150{
151 if (!(p12->mac = PKCS12_MAC_DATA_new())) return PKCS12_ERROR;
152 if (iter > 1) {
153 if(!(p12->mac->iter = M_ASN1_INTEGER_new())) {
154 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
155 return 0;
156 }
157 if (!ASN1_INTEGER_set(p12->mac->iter, iter)) {
158 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
159 return 0;
160 }
161 }
162 if (!saltlen) saltlen = PKCS12_SALT_LEN;
163 p12->mac->salt->length = saltlen;
164 if (!(p12->mac->salt->data = OPENSSL_malloc (saltlen))) {
165 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
166 return 0;
167 }
168 if (!salt) {
169 if (RAND_pseudo_bytes (p12->mac->salt->data, saltlen) < 0)
170 return 0;
171 }
172 else memcpy (p12->mac->salt->data, salt, saltlen);
173 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type));
174 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) {
175 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
176 return 0;
177 }
178 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL;
179
180 return 1;
181}
182#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c
deleted file mode 100644
index af708a2743..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_npas.c
+++ /dev/null
@@ -1,217 +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_OF(PKCS12_SAFEBAG) *bags, char *oldpass,
70 char *newpass);
71static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass);
72static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen);
73
74/*
75 * Change the password on a PKCS#12 structure.
76 */
77
78int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
79{
80
81/* Check for NULL PKCS12 structure */
82
83if(!p12) {
84 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
85 return 0;
86}
87
88/* Check the mac */
89
90if (!PKCS12_verify_mac(p12, oldpass, -1)) {
91 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE);
92 return 0;
93}
94
95if (!newpass_p12(p12, oldpass, newpass)) {
96 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR);
97 return 0;
98}
99
100return 1;
101
102}
103
104/* Parse the outer PKCS#12 structure */
105
106static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass)
107{
108 STACK_OF(PKCS7) *asafes, *newsafes;
109 STACK_OF(PKCS12_SAFEBAG) *bags;
110 int i, bagnid, pbe_nid = 0, pbe_iter = 0, pbe_saltlen = 0;
111 PKCS7 *p7, *p7new;
112 ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL;
113 unsigned char mac[EVP_MAX_MD_SIZE];
114 unsigned int maclen;
115
116 if (!(asafes = PKCS12_unpack_authsafes(p12))) return 0;
117 if(!(newsafes = sk_PKCS7_new_null())) return 0;
118 for (i = 0; i < sk_PKCS7_num (asafes); i++) {
119 p7 = sk_PKCS7_value(asafes, i);
120 bagnid = OBJ_obj2nid(p7->type);
121 if (bagnid == NID_pkcs7_data) {
122 bags = PKCS12_unpack_p7data(p7);
123 } else if (bagnid == NID_pkcs7_encrypted) {
124 bags = PKCS12_unpack_p7encdata(p7, oldpass, -1);
125 alg_get(p7->d.encrypted->enc_data->algorithm,
126 &pbe_nid, &pbe_iter, &pbe_saltlen);
127 } else continue;
128 if (!bags) {
129 sk_PKCS7_pop_free(asafes, PKCS7_free);
130 return 0;
131 }
132 if (!newpass_bags(bags, oldpass, newpass)) {
133 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
134 sk_PKCS7_pop_free(asafes, PKCS7_free);
135 return 0;
136 }
137 /* Repack bag in same form with new password */
138 if (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags);
139 else p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL,
140 pbe_saltlen, pbe_iter, bags);
141 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
142 if(!p7new) {
143 sk_PKCS7_pop_free(asafes, PKCS7_free);
144 return 0;
145 }
146 sk_PKCS7_push(newsafes, p7new);
147 }
148 sk_PKCS7_pop_free(asafes, PKCS7_free);
149
150 /* Repack safe: save old safe in case of error */
151
152 p12_data_tmp = p12->authsafes->d.data;
153 if(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr;
154 if(!PKCS12_pack_authsafes(p12, newsafes)) goto saferr;
155
156 if(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr;
157 if(!(macnew = ASN1_OCTET_STRING_new())) goto saferr;
158 if(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr;
159 ASN1_OCTET_STRING_free(p12->mac->dinfo->digest);
160 p12->mac->dinfo->digest = macnew;
161 ASN1_OCTET_STRING_free(p12_data_tmp);
162
163 return 1;
164
165 saferr:
166 /* Restore old safe */
167 ASN1_OCTET_STRING_free(p12->authsafes->d.data);
168 ASN1_OCTET_STRING_free(macnew);
169 p12->authsafes->d.data = p12_data_tmp;
170 return 0;
171
172}
173
174
175static int newpass_bags(STACK_OF(PKCS12_SAFEBAG) *bags, char *oldpass,
176 char *newpass)
177{
178 int i;
179 for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) {
180 if (!newpass_bag(sk_PKCS12_SAFEBAG_value(bags, i),
181 oldpass, newpass))
182 return 0;
183 }
184 return 1;
185}
186
187/* Change password of safebag: only needs handle shrouded keybags */
188
189static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass)
190{
191 PKCS8_PRIV_KEY_INFO *p8;
192 X509_SIG *p8new;
193 int p8_nid, p8_saltlen, p8_iter;
194
195 if(M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) return 1;
196
197 if (!(p8 = PKCS8_decrypt(bag->value.shkeybag, oldpass, -1))) return 0;
198 alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter, &p8_saltlen);
199 if(!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen,
200 p8_iter, p8))) return 0;
201 X509_SIG_free(bag->value.shkeybag);
202 bag->value.shkeybag = p8new;
203 return 1;
204}
205
206static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen)
207{
208 PBEPARAM *pbe;
209 unsigned char *p;
210 p = alg->parameter->value.sequence->data;
211 pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length);
212 *pnid = OBJ_obj2nid(alg->algorithm);
213 *piter = ASN1_INTEGER_get(pbe->iter);
214 *psaltlen = pbe->salt->length;
215 PBEPARAM_free(pbe);
216 return 0;
217}
diff --git a/src/lib/libcrypto/pkcs12/p12_p8d.c b/src/lib/libcrypto/pkcs12/p12_p8d.c
deleted file mode 100644
index 3c6f377933..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_p8d.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/* p12_p8d.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen)
64{
65 return PKCS12_item_decrypt_d2i(p8->algor, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), pass,
66 passlen, p8->digest, 1);
67}
68
diff --git a/src/lib/libcrypto/pkcs12/p12_p8e.c b/src/lib/libcrypto/pkcs12/p12_p8e.c
deleted file mode 100644
index 3d47956652..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_p8e.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/* p12_p8e.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
64 const char *pass, int passlen,
65 unsigned char *salt, int saltlen, int iter,
66 PKCS8_PRIV_KEY_INFO *p8inf)
67{
68 X509_SIG *p8 = NULL;
69 X509_ALGOR *pbe;
70
71 if (!(p8 = X509_SIG_new())) {
72 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
73 goto err;
74 }
75
76 if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
77 else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
78 if(!pbe) {
79 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB);
80 goto err;
81 }
82 X509_ALGOR_free(p8->algor);
83 p8->algor = pbe;
84 M_ASN1_OCTET_STRING_free(p8->digest);
85 p8->digest = PKCS12_item_i2d_encrypt(pbe, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO),
86 pass, passlen, p8inf, 1);
87 if(!p8->digest) {
88 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR);
89 goto err;
90 }
91
92 return p8;
93
94 err:
95 X509_SIG_free(p8);
96 return NULL;
97}
diff --git a/src/lib/libcrypto/pkcs12/p12_utl.c b/src/lib/libcrypto/pkcs12/p12_utl.c
deleted file mode 100644
index 243ec76be9..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_utl.c
+++ /dev/null
@@ -1,146 +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, int asclen, unsigned char **uni, int *unilen)
66{
67 int ulen, i;
68 unsigned char *unitmp;
69 if (asclen == -1) asclen = strlen(asc);
70 ulen = asclen*2 + 2;
71 if (!(unitmp = OPENSSL_malloc(ulen))) return NULL;
72 for (i = 0; i < ulen - 2; i+=2) {
73 unitmp[i] = 0;
74 unitmp[i + 1] = asc[i>>1];
75 }
76 /* Make result double null terminated */
77 unitmp[ulen - 2] = 0;
78 unitmp[ulen - 1] = 0;
79 if (unilen) *unilen = ulen;
80 if (uni) *uni = unitmp;
81 return unitmp;
82}
83
84char *uni2asc(unsigned char *uni, int unilen)
85{
86 int asclen, i;
87 char *asctmp;
88 asclen = unilen / 2;
89 /* If no terminating zero allow for one */
90 if (!unilen || uni[unilen - 1]) asclen++;
91 uni++;
92 if (!(asctmp = OPENSSL_malloc(asclen))) return NULL;
93 for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i];
94 asctmp[asclen - 1] = 0;
95 return asctmp;
96}
97
98int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12)
99{
100 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS12), bp, p12);
101}
102
103#ifndef OPENSSL_NO_FP_API
104int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12)
105{
106 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS12), fp, p12);
107}
108#endif
109
110PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12)
111{
112 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS12), bp, p12);
113}
114#ifndef OPENSSL_NO_FP_API
115PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12)
116{
117 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS12), fp, p12);
118}
119#endif
120
121PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509)
122{
123 return PKCS12_item_pack_safebag(x509, ASN1_ITEM_rptr(X509),
124 NID_x509Certificate, NID_certBag);
125}
126
127PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl)
128{
129 return PKCS12_item_pack_safebag(crl, ASN1_ITEM_rptr(X509_CRL),
130 NID_x509Crl, NID_crlBag);
131}
132
133X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag)
134{
135 if(M_PKCS12_bag_type(bag) != NID_certBag) return NULL;
136 if(M_PKCS12_cert_bag_type(bag) != NID_x509Certificate) return NULL;
137 return ASN1_item_unpack(bag->value.bag->value.octet, ASN1_ITEM_rptr(X509));
138}
139
140X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag)
141{
142 if(M_PKCS12_bag_type(bag) != NID_crlBag) return NULL;
143 if(M_PKCS12_cert_bag_type(bag) != NID_x509Crl) return NULL;
144 return ASN1_item_unpack(bag->value.bag->value.octet,
145 ASN1_ITEM_rptr(X509_CRL));
146}
diff --git a/src/lib/libcrypto/pkcs12/pk12err.c b/src/lib/libcrypto/pkcs12/pk12err.c
deleted file mode 100644
index a33b37b1c7..0000000000
--- a/src/lib/libcrypto/pkcs12/pk12err.c
+++ /dev/null
@@ -1,146 +0,0 @@
1/* crypto/pkcs12/pk12err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_PKCS12,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_PKCS12,0,reason)
70
71static ERR_STRING_DATA PKCS12_str_functs[]=
72 {
73{ERR_FUNC(PKCS12_F_PARSE_BAGS), "PARSE_BAGS"},
74{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME), "PKCS12_ADD_FRIENDLYNAME"},
75{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC), "PKCS12_add_friendlyname_asc"},
76{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI), "PKCS12_add_friendlyname_uni"},
77{ERR_FUNC(PKCS12_F_PKCS12_ADD_LOCALKEYID), "PKCS12_add_localkeyid"},
78{ERR_FUNC(PKCS12_F_PKCS12_CREATE), "PKCS12_create"},
79{ERR_FUNC(PKCS12_F_PKCS12_DECRYPT_D2I), "PKCS12_DECRYPT_D2I"},
80{ERR_FUNC(PKCS12_F_PKCS12_GEN_MAC), "PKCS12_gen_mac"},
81{ERR_FUNC(PKCS12_F_PKCS12_I2D_ENCRYPT), "PKCS12_I2D_ENCRYPT"},
82{ERR_FUNC(PKCS12_F_PKCS12_INIT), "PKCS12_init"},
83{ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_ASC), "PKCS12_key_gen_asc"},
84{ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_UNI), "PKCS12_key_gen_uni"},
85{ERR_FUNC(PKCS12_F_PKCS12_MAKE_KEYBAG), "PKCS12_MAKE_KEYBAG"},
86{ERR_FUNC(PKCS12_F_PKCS12_MAKE_SHKEYBAG), "PKCS12_MAKE_SHKEYBAG"},
87{ERR_FUNC(PKCS12_F_PKCS12_NEWPASS), "PKCS12_newpass"},
88{ERR_FUNC(PKCS12_F_PKCS12_PACK_P7DATA), "PKCS12_pack_p7data"},
89{ERR_FUNC(PKCS12_F_PKCS12_PACK_P7ENCDATA), "PKCS12_pack_p7encdata"},
90{ERR_FUNC(PKCS12_F_PKCS12_PACK_SAFEBAG), "PKCS12_PACK_SAFEBAG"},
91{ERR_FUNC(PKCS12_F_PKCS12_PARSE), "PKCS12_parse"},
92{ERR_FUNC(PKCS12_F_PKCS12_PBE_CRYPT), "PKCS12_pbe_crypt"},
93{ERR_FUNC(PKCS12_F_PKCS12_PBE_KEYIVGEN), "PKCS12_PBE_keyivgen"},
94{ERR_FUNC(PKCS12_F_PKCS12_SETUP_MAC), "PKCS12_setup_mac"},
95{ERR_FUNC(PKCS12_F_PKCS12_SET_MAC), "PKCS12_set_mac"},
96{ERR_FUNC(PKCS12_F_PKCS12_UNPACK_AUTHSAFES), "PKCS12_unpack_authsafes"},
97{ERR_FUNC(PKCS12_F_PKCS12_UNPACK_P7DATA), "PKCS12_unpack_p7data"},
98{ERR_FUNC(PKCS12_F_PKCS8_ADD_KEYUSAGE), "PKCS8_add_keyusage"},
99{ERR_FUNC(PKCS12_F_PKCS8_ENCRYPT), "PKCS8_encrypt"},
100{ERR_FUNC(PKCS12_F_VERIFY_MAC), "VERIFY_MAC"},
101{0,NULL}
102 };
103
104static ERR_STRING_DATA PKCS12_str_reasons[]=
105 {
106{ERR_REASON(PKCS12_R_CANT_PACK_STRUCTURE),"cant pack structure"},
107{ERR_REASON(PKCS12_R_CONTENT_TYPE_NOT_DATA),"content type not data"},
108{ERR_REASON(PKCS12_R_DECODE_ERROR) ,"decode error"},
109{ERR_REASON(PKCS12_R_ENCODE_ERROR) ,"encode error"},
110{ERR_REASON(PKCS12_R_ENCRYPT_ERROR) ,"encrypt error"},
111{ERR_REASON(PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE),"error setting encrypted data type"},
112{ERR_REASON(PKCS12_R_INVALID_NULL_ARGUMENT),"invalid null argument"},
113{ERR_REASON(PKCS12_R_INVALID_NULL_PKCS12_POINTER),"invalid null pkcs12 pointer"},
114{ERR_REASON(PKCS12_R_IV_GEN_ERROR) ,"iv gen error"},
115{ERR_REASON(PKCS12_R_KEY_GEN_ERROR) ,"key gen error"},
116{ERR_REASON(PKCS12_R_MAC_ABSENT) ,"mac absent"},
117{ERR_REASON(PKCS12_R_MAC_GENERATION_ERROR),"mac generation error"},
118{ERR_REASON(PKCS12_R_MAC_SETUP_ERROR) ,"mac setup error"},
119{ERR_REASON(PKCS12_R_MAC_STRING_SET_ERROR),"mac string set error"},
120{ERR_REASON(PKCS12_R_MAC_VERIFY_ERROR) ,"mac verify error"},
121{ERR_REASON(PKCS12_R_MAC_VERIFY_FAILURE) ,"mac verify failure"},
122{ERR_REASON(PKCS12_R_PARSE_ERROR) ,"parse error"},
123{ERR_REASON(PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR),"pkcs12 algor cipherinit error"},
124{ERR_REASON(PKCS12_R_PKCS12_CIPHERFINAL_ERROR),"pkcs12 cipherfinal error"},
125{ERR_REASON(PKCS12_R_PKCS12_PBE_CRYPT_ERROR),"pkcs12 pbe crypt error"},
126{ERR_REASON(PKCS12_R_UNKNOWN_DIGEST_ALGORITHM),"unknown digest algorithm"},
127{ERR_REASON(PKCS12_R_UNSUPPORTED_PKCS12_MODE),"unsupported pkcs12 mode"},
128{0,NULL}
129 };
130
131#endif
132
133void ERR_load_PKCS12_strings(void)
134 {
135 static int init=1;
136
137 if (init)
138 {
139 init=0;
140#ifndef OPENSSL_NO_ERR
141 ERR_load_strings(0,PKCS12_str_functs);
142 ERR_load_strings(0,PKCS12_str_reasons);
143#endif
144
145 }
146 }
diff --git a/src/lib/libcrypto/pkcs12/pkcs12.h b/src/lib/libcrypto/pkcs12/pkcs12.h
deleted file mode 100644
index fb8af82d4f..0000000000
--- a/src/lib/libcrypto/pkcs12/pkcs12.h
+++ /dev/null
@@ -1,323 +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#include <openssl/bio.h>
63#include <openssl/x509.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
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
111PREDECLARE_STACK_OF(PKCS12_SAFEBAG)
112
113typedef struct {
114ASN1_OBJECT *type;
115union {
116 struct pkcs12_bag_st *bag; /* secret, crl and certbag */
117 struct pkcs8_priv_key_info_st *keybag; /* keybag */
118 X509_SIG *shkeybag; /* shrouded key bag */
119 STACK_OF(PKCS12_SAFEBAG) *safes;
120 ASN1_TYPE *other;
121}value;
122STACK_OF(X509_ATTRIBUTE) *attrib;
123} PKCS12_SAFEBAG;
124
125DECLARE_STACK_OF(PKCS12_SAFEBAG)
126DECLARE_ASN1_SET_OF(PKCS12_SAFEBAG)
127DECLARE_PKCS12_STACK_OF(PKCS12_SAFEBAG)
128
129typedef struct pkcs12_bag_st {
130ASN1_OBJECT *type;
131union {
132 ASN1_OCTET_STRING *x509cert;
133 ASN1_OCTET_STRING *x509crl;
134 ASN1_OCTET_STRING *octet;
135 ASN1_IA5STRING *sdsicert;
136 ASN1_TYPE *other; /* Secret or other bag */
137}value;
138} PKCS12_BAGS;
139
140#define PKCS12_ERROR 0
141#define PKCS12_OK 1
142
143/* Compatibility macros */
144
145#define M_PKCS12_x5092certbag PKCS12_x5092certbag
146#define M_PKCS12_x509crl2certbag PKCS12_x509crl2certbag
147
148#define M_PKCS12_certbag2x509 PKCS12_certbag2x509
149#define M_PKCS12_certbag2x509crl PKCS12_certbag2x509crl
150
151#define M_PKCS12_unpack_p7data PKCS12_unpack_p7data
152#define M_PKCS12_pack_authsafes PKCS12_pack_authsafes
153#define M_PKCS12_unpack_authsafes PKCS12_unpack_authsafes
154#define M_PKCS12_unpack_p7encdata PKCS12_unpack_p7encdata
155
156#define M_PKCS12_decrypt_skey PKCS12_decrypt_skey
157#define M_PKCS8_decrypt PKCS8_decrypt
158
159#define M_PKCS12_bag_type(bg) OBJ_obj2nid((bg)->type)
160#define M_PKCS12_cert_bag_type(bg) OBJ_obj2nid((bg)->value.bag->type)
161#define M_PKCS12_crl_bag_type M_PKCS12_cert_bag_type
162
163#define PKCS12_get_attr(bag, attr_nid) \
164 PKCS12_get_attr_gen(bag->attrib, attr_nid)
165
166#define PKCS8_get_attr(p8, attr_nid) \
167 PKCS12_get_attr_gen(p8->attributes, attr_nid)
168
169#define PKCS12_mac_present(p12) ((p12)->mac ? 1 : 0)
170
171
172PKCS12_SAFEBAG *PKCS12_x5092certbag(X509 *x509);
173PKCS12_SAFEBAG *PKCS12_x509crl2certbag(X509_CRL *crl);
174X509 *PKCS12_certbag2x509(PKCS12_SAFEBAG *bag);
175X509_CRL *PKCS12_certbag2x509crl(PKCS12_SAFEBAG *bag);
176
177PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1,
178 int nid2);
179PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8);
180PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(X509_SIG *p8, const char *pass, int passlen);
181PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(PKCS12_SAFEBAG *bag, const char *pass,
182 int passlen);
183X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
184 const char *pass, int passlen,
185 unsigned char *salt, int saltlen, int iter,
186 PKCS8_PRIV_KEY_INFO *p8);
187PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
188 int passlen, unsigned char *salt,
189 int saltlen, int iter,
190 PKCS8_PRIV_KEY_INFO *p8);
191PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk);
192STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7);
193PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
194 unsigned char *salt, int saltlen, int iter,
195 STACK_OF(PKCS12_SAFEBAG) *bags);
196STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, int passlen);
197
198int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes);
199STACK_OF(PKCS7) *PKCS12_unpack_authsafes(PKCS12 *p12);
200
201int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen);
202int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
203 int namelen);
204int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
205 int namelen);
206int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name,
207 int namelen);
208int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
209ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid);
210char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
211unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
212 int passlen, unsigned char *in, int inlen,
213 unsigned char **data, int *datalen, int en_de);
214void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
215 const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf);
216ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it,
217 const char *pass, int passlen,
218 void *obj, int zbuf);
219PKCS12 *PKCS12_init(int mode);
220int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
221 int saltlen, int id, int iter, int n,
222 unsigned char *out, const EVP_MD *md_type);
223int 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);
224int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
225 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md_type,
226 int en_de);
227int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
228 unsigned char *mac, unsigned int *maclen);
229int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
230int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
231 unsigned char *salt, int saltlen, int iter,
232 const EVP_MD *md_type);
233int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
234 int saltlen, const EVP_MD *md_type);
235unsigned char *asc2uni(const char *asc, int asclen, unsigned char **uni, int *unilen);
236char *uni2asc(unsigned char *uni, int unilen);
237
238DECLARE_ASN1_FUNCTIONS(PKCS12)
239DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA)
240DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG)
241DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS)
242
243DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS)
244DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES)
245
246void PKCS12_PBE_add(void);
247int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
248 STACK_OF(X509) **ca);
249PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
250 STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter,
251 int mac_iter, int keytype);
252int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
253int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
254PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
255PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
256int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
257
258/* BEGIN ERROR CODES */
259/* The following lines are auto generated by the script mkerr.pl. Any changes
260 * made after this point may be overwritten when the script is next run.
261 */
262void ERR_load_PKCS12_strings(void);
263
264/* Error codes for the PKCS12 functions. */
265
266/* Function codes. */
267#define PKCS12_F_PARSE_BAGS 103
268#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100
269#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127
270#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102
271#define PKCS12_F_PKCS12_ADD_LOCALKEYID 104
272#define PKCS12_F_PKCS12_CREATE 105
273#define PKCS12_F_PKCS12_DECRYPT_D2I 106
274#define PKCS12_F_PKCS12_GEN_MAC 107
275#define PKCS12_F_PKCS12_I2D_ENCRYPT 108
276#define PKCS12_F_PKCS12_INIT 109
277#define PKCS12_F_PKCS12_KEY_GEN_ASC 110
278#define PKCS12_F_PKCS12_KEY_GEN_UNI 111
279#define PKCS12_F_PKCS12_MAKE_KEYBAG 112
280#define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113
281#define PKCS12_F_PKCS12_NEWPASS 128
282#define PKCS12_F_PKCS12_PACK_P7DATA 114
283#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115
284#define PKCS12_F_PKCS12_PACK_SAFEBAG 117
285#define PKCS12_F_PKCS12_PARSE 118
286#define PKCS12_F_PKCS12_PBE_CRYPT 119
287#define PKCS12_F_PKCS12_PBE_KEYIVGEN 120
288#define PKCS12_F_PKCS12_SETUP_MAC 122
289#define PKCS12_F_PKCS12_SET_MAC 123
290#define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 129
291#define PKCS12_F_PKCS12_UNPACK_P7DATA 130
292#define PKCS12_F_PKCS8_ADD_KEYUSAGE 124
293#define PKCS12_F_PKCS8_ENCRYPT 125
294#define PKCS12_F_VERIFY_MAC 126
295
296/* Reason codes. */
297#define PKCS12_R_CANT_PACK_STRUCTURE 100
298#define PKCS12_R_CONTENT_TYPE_NOT_DATA 121
299#define PKCS12_R_DECODE_ERROR 101
300#define PKCS12_R_ENCODE_ERROR 102
301#define PKCS12_R_ENCRYPT_ERROR 103
302#define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120
303#define PKCS12_R_INVALID_NULL_ARGUMENT 104
304#define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105
305#define PKCS12_R_IV_GEN_ERROR 106
306#define PKCS12_R_KEY_GEN_ERROR 107
307#define PKCS12_R_MAC_ABSENT 108
308#define PKCS12_R_MAC_GENERATION_ERROR 109
309#define PKCS12_R_MAC_SETUP_ERROR 110
310#define PKCS12_R_MAC_STRING_SET_ERROR 111
311#define PKCS12_R_MAC_VERIFY_ERROR 112
312#define PKCS12_R_MAC_VERIFY_FAILURE 113
313#define PKCS12_R_PARSE_ERROR 114
314#define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115
315#define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116
316#define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117
317#define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118
318#define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119
319
320#ifdef __cplusplus
321}
322#endif
323#endif
diff --git a/src/lib/libcrypto/pkcs7/pk7_asn1.c b/src/lib/libcrypto/pkcs7/pk7_asn1.c
deleted file mode 100644
index 46f0fc9375..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_asn1.c
+++ /dev/null
@@ -1,213 +0,0 @@
1/* pk7_asn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/pkcs7.h>
63#include <openssl/x509.h>
64
65/* PKCS#7 ASN1 module */
66
67/* This is the ANY DEFINED BY table for the top level PKCS#7 structure */
68
69ASN1_ADB_TEMPLATE(p7default) = ASN1_EXP_OPT(PKCS7, d.other, ASN1_ANY, 0);
70
71ASN1_ADB(PKCS7) = {
72 ADB_ENTRY(NID_pkcs7_data, ASN1_EXP_OPT(PKCS7, d.data, ASN1_OCTET_STRING, 0)),
73 ADB_ENTRY(NID_pkcs7_signed, ASN1_EXP_OPT(PKCS7, d.sign, PKCS7_SIGNED, 0)),
74 ADB_ENTRY(NID_pkcs7_enveloped, ASN1_EXP_OPT(PKCS7, d.enveloped, PKCS7_ENVELOPE, 0)),
75 ADB_ENTRY(NID_pkcs7_signedAndEnveloped, ASN1_EXP_OPT(PKCS7, d.signed_and_enveloped, PKCS7_SIGN_ENVELOPE, 0)),
76 ADB_ENTRY(NID_pkcs7_digest, ASN1_EXP_OPT(PKCS7, d.digest, PKCS7_DIGEST, 0)),
77 ADB_ENTRY(NID_pkcs7_encrypted, ASN1_EXP_OPT(PKCS7, d.encrypted, PKCS7_ENCRYPT, 0))
78} ASN1_ADB_END(PKCS7, 0, type, 0, &p7default_tt, NULL);
79
80ASN1_SEQUENCE(PKCS7) = {
81 ASN1_SIMPLE(PKCS7, type, ASN1_OBJECT),
82 ASN1_ADB_OBJECT(PKCS7)
83}ASN1_SEQUENCE_END(PKCS7)
84
85IMPLEMENT_ASN1_FUNCTIONS(PKCS7)
86IMPLEMENT_ASN1_DUP_FUNCTION(PKCS7)
87
88ASN1_SEQUENCE(PKCS7_SIGNED) = {
89 ASN1_SIMPLE(PKCS7_SIGNED, version, ASN1_INTEGER),
90 ASN1_SET_OF(PKCS7_SIGNED, md_algs, X509_ALGOR),
91 ASN1_SIMPLE(PKCS7_SIGNED, contents, PKCS7),
92 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNED, cert, X509, 0),
93 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNED, crl, X509_CRL, 1),
94 ASN1_SET_OF(PKCS7_SIGNED, signer_info, PKCS7_SIGNER_INFO)
95} ASN1_SEQUENCE_END(PKCS7_SIGNED)
96
97IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNED)
98
99/* Minor tweak to operation: free up EVP_PKEY */
100static int si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
101{
102 if(operation == ASN1_OP_FREE_POST) {
103 PKCS7_SIGNER_INFO *si = (PKCS7_SIGNER_INFO *)*pval;
104 EVP_PKEY_free(si->pkey);
105 }
106 return 1;
107}
108
109ASN1_SEQUENCE_cb(PKCS7_SIGNER_INFO, si_cb) = {
110 ASN1_SIMPLE(PKCS7_SIGNER_INFO, version, ASN1_INTEGER),
111 ASN1_SIMPLE(PKCS7_SIGNER_INFO, issuer_and_serial, PKCS7_ISSUER_AND_SERIAL),
112 ASN1_SIMPLE(PKCS7_SIGNER_INFO, digest_alg, X509_ALGOR),
113 /* NB this should be a SET OF but we use a SEQUENCE OF so the
114 * original order * is retained when the structure is reencoded.
115 * Since the attributes are implicitly tagged this will not affect
116 * the encoding.
117 */
118 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNER_INFO, auth_attr, X509_ATTRIBUTE, 0),
119 ASN1_SIMPLE(PKCS7_SIGNER_INFO, digest_enc_alg, X509_ALGOR),
120 ASN1_SIMPLE(PKCS7_SIGNER_INFO, enc_digest, ASN1_OCTET_STRING),
121 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNER_INFO, unauth_attr, X509_ATTRIBUTE, 1)
122} ASN1_SEQUENCE_END_cb(PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO)
123
124IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
125
126ASN1_SEQUENCE(PKCS7_ISSUER_AND_SERIAL) = {
127 ASN1_SIMPLE(PKCS7_ISSUER_AND_SERIAL, issuer, X509_NAME),
128 ASN1_SIMPLE(PKCS7_ISSUER_AND_SERIAL, serial, ASN1_INTEGER)
129} ASN1_SEQUENCE_END(PKCS7_ISSUER_AND_SERIAL)
130
131IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
132
133ASN1_SEQUENCE(PKCS7_ENVELOPE) = {
134 ASN1_SIMPLE(PKCS7_ENVELOPE, version, ASN1_INTEGER),
135 ASN1_SET_OF(PKCS7_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
136 ASN1_SIMPLE(PKCS7_ENVELOPE, enc_data, PKCS7_ENC_CONTENT)
137} ASN1_SEQUENCE_END(PKCS7_ENVELOPE)
138
139IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
140
141/* Minor tweak to operation: free up X509 */
142static int ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
143{
144 if(operation == ASN1_OP_FREE_POST) {
145 PKCS7_RECIP_INFO *ri = (PKCS7_RECIP_INFO *)*pval;
146 X509_free(ri->cert);
147 }
148 return 1;
149}
150
151ASN1_SEQUENCE_cb(PKCS7_RECIP_INFO, ri_cb) = {
152 ASN1_SIMPLE(PKCS7_RECIP_INFO, version, ASN1_INTEGER),
153 ASN1_SIMPLE(PKCS7_RECIP_INFO, issuer_and_serial, PKCS7_ISSUER_AND_SERIAL),
154 ASN1_SIMPLE(PKCS7_RECIP_INFO, key_enc_algor, X509_ALGOR),
155 ASN1_SIMPLE(PKCS7_RECIP_INFO, enc_key, ASN1_OCTET_STRING)
156} ASN1_SEQUENCE_END_cb(PKCS7_RECIP_INFO, PKCS7_RECIP_INFO)
157
158IMPLEMENT_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
159
160ASN1_SEQUENCE(PKCS7_ENC_CONTENT) = {
161 ASN1_SIMPLE(PKCS7_ENC_CONTENT, content_type, ASN1_OBJECT),
162 ASN1_SIMPLE(PKCS7_ENC_CONTENT, algorithm, X509_ALGOR),
163 ASN1_IMP_OPT(PKCS7_ENC_CONTENT, enc_data, ASN1_OCTET_STRING, 0)
164} ASN1_SEQUENCE_END(PKCS7_ENC_CONTENT)
165
166IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
167
168ASN1_SEQUENCE(PKCS7_SIGN_ENVELOPE) = {
169 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, version, ASN1_INTEGER),
170 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
171 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, md_algs, X509_ALGOR),
172 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, enc_data, PKCS7_ENC_CONTENT),
173 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, cert, X509, 0),
174 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, crl, X509_CRL, 1),
175 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, signer_info, PKCS7_SIGNER_INFO)
176} ASN1_SEQUENCE_END(PKCS7_SIGN_ENVELOPE)
177
178IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
179
180ASN1_SEQUENCE(PKCS7_ENCRYPT) = {
181 ASN1_SIMPLE(PKCS7_ENCRYPT, version, ASN1_INTEGER),
182 ASN1_SIMPLE(PKCS7_ENCRYPT, enc_data, PKCS7_ENC_CONTENT)
183} ASN1_SEQUENCE_END(PKCS7_ENCRYPT)
184
185IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
186
187ASN1_SEQUENCE(PKCS7_DIGEST) = {
188 ASN1_SIMPLE(PKCS7_DIGEST, version, ASN1_INTEGER),
189 ASN1_SIMPLE(PKCS7_DIGEST, md, X509_ALGOR),
190 ASN1_SIMPLE(PKCS7_DIGEST, contents, PKCS7),
191 ASN1_SIMPLE(PKCS7_DIGEST, digest, ASN1_OCTET_STRING)
192} ASN1_SEQUENCE_END(PKCS7_DIGEST)
193
194IMPLEMENT_ASN1_FUNCTIONS(PKCS7_DIGEST)
195
196/* Specials for authenticated attributes */
197
198/* When signing attributes we want to reorder them to match the sorted
199 * encoding.
200 */
201
202ASN1_ITEM_TEMPLATE(PKCS7_ATTR_SIGN) =
203 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_ORDER, 0, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
204ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_SIGN)
205
206/* When verifying attributes we need to use the received order. So
207 * we use SEQUENCE OF and tag it to SET OF
208 */
209
210ASN1_ITEM_TEMPLATE(PKCS7_ATTR_VERIFY) =
211 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_IMPTAG | ASN1_TFLG_UNIVERSAL,
212 V_ASN1_SET, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
213ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_VERIFY)
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
deleted file mode 100644
index 039141027a..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_attr.c
+++ /dev/null
@@ -1,140 +0,0 @@
1/* pk7_attr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001-2004 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/bio.h>
62#include <openssl/asn1.h>
63#include <openssl/pem.h>
64#include <openssl/pkcs7.h>
65#include <openssl/x509.h>
66#include <openssl/err.h>
67
68int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap)
69{
70 ASN1_STRING *seq;
71 unsigned char *p, *pp;
72 int len;
73 len=i2d_ASN1_SET_OF_X509_ALGOR(cap,NULL,i2d_X509_ALGOR,
74 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL,
75 IS_SEQUENCE);
76 if(!(pp=(unsigned char *)OPENSSL_malloc(len))) {
77 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 p=pp;
81 i2d_ASN1_SET_OF_X509_ALGOR(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
82 V_ASN1_UNIVERSAL, IS_SEQUENCE);
83 if(!(seq = ASN1_STRING_new())) {
84 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
85 return 0;
86 }
87 if(!ASN1_STRING_set (seq, pp, len)) {
88 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
89 return 0;
90 }
91 OPENSSL_free (pp);
92 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
93 V_ASN1_SEQUENCE, seq);
94}
95
96STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
97 {
98 ASN1_TYPE *cap;
99 unsigned char *p;
100 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities);
101 if (!cap || (cap->type != V_ASN1_SEQUENCE))
102 return NULL;
103 p = cap->value.sequence->data;
104 return d2i_ASN1_SET_OF_X509_ALGOR(NULL, &p,
105 cap->value.sequence->length,
106 d2i_X509_ALGOR, X509_ALGOR_free,
107 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
108 }
109
110/* Basic smime-capabilities OID and optional integer arg */
111int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
112{
113 X509_ALGOR *alg;
114
115 if(!(alg = X509_ALGOR_new())) {
116 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
117 return 0;
118 }
119 ASN1_OBJECT_free(alg->algorithm);
120 alg->algorithm = OBJ_nid2obj (nid);
121 if (arg > 0) {
122 ASN1_INTEGER *nbit;
123 if(!(alg->parameter = ASN1_TYPE_new())) {
124 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
125 return 0;
126 }
127 if(!(nbit = ASN1_INTEGER_new())) {
128 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
129 return 0;
130 }
131 if(!ASN1_INTEGER_set (nbit, arg)) {
132 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
133 return 0;
134 }
135 alg->parameter->value.integer = nbit;
136 alg->parameter->type = V_ASN1_INTEGER;
137 }
138 sk_X509_ALGOR_push (sk, alg);
139 return 1;
140}
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
deleted file mode 100644
index 4ac29ae14d..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ /dev/null
@@ -1,1013 +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
70static int PKCS7_type_is_other(PKCS7* p7)
71 {
72 int isOther=1;
73
74 int nid=OBJ_obj2nid(p7->type);
75
76 switch( nid )
77 {
78 case NID_pkcs7_data:
79 case NID_pkcs7_signed:
80 case NID_pkcs7_enveloped:
81 case NID_pkcs7_signedAndEnveloped:
82 case NID_pkcs7_digest:
83 case NID_pkcs7_encrypted:
84 isOther=0;
85 break;
86 default:
87 isOther=1;
88 }
89
90 return isOther;
91
92 }
93
94static ASN1_OCTET_STRING *PKCS7_get_octet_string(PKCS7 *p7)
95 {
96 if ( PKCS7_type_is_data(p7))
97 return p7->d.data;
98 if ( PKCS7_type_is_other(p7) && p7->d.other
99 && (p7->d.other->type == V_ASN1_OCTET_STRING))
100 return p7->d.other->value.octet_string;
101 return NULL;
102 }
103
104BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
105 {
106 int i;
107 BIO *out=NULL,*btmp=NULL;
108 X509_ALGOR *xa;
109 const EVP_MD *evp_md;
110 const EVP_CIPHER *evp_cipher=NULL;
111 STACK_OF(X509_ALGOR) *md_sk=NULL;
112 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
113 X509_ALGOR *xalg=NULL;
114 PKCS7_RECIP_INFO *ri=NULL;
115 EVP_PKEY *pkey;
116
117 i=OBJ_obj2nid(p7->type);
118 p7->state=PKCS7_S_HEADER;
119
120 switch (i)
121 {
122 case NID_pkcs7_signed:
123 md_sk=p7->d.sign->md_algs;
124 break;
125 case NID_pkcs7_signedAndEnveloped:
126 rsk=p7->d.signed_and_enveloped->recipientinfo;
127 md_sk=p7->d.signed_and_enveloped->md_algs;
128 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
129 evp_cipher=p7->d.signed_and_enveloped->enc_data->cipher;
130 if (evp_cipher == NULL)
131 {
132 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
133 PKCS7_R_CIPHER_NOT_INITIALIZED);
134 goto err;
135 }
136 break;
137 case NID_pkcs7_enveloped:
138 rsk=p7->d.enveloped->recipientinfo;
139 xalg=p7->d.enveloped->enc_data->algorithm;
140 evp_cipher=p7->d.enveloped->enc_data->cipher;
141 if (evp_cipher == NULL)
142 {
143 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
144 PKCS7_R_CIPHER_NOT_INITIALIZED);
145 goto err;
146 }
147 break;
148 default:
149 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
150 goto err;
151 }
152
153 if (md_sk != NULL)
154 {
155 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
156 {
157 xa=sk_X509_ALGOR_value(md_sk,i);
158 if ((btmp=BIO_new(BIO_f_md())) == NULL)
159 {
160 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
161 goto err;
162 }
163
164 evp_md=EVP_get_digestbyobj(xa->algorithm);
165 if (evp_md == NULL)
166 {
167 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNKNOWN_DIGEST_TYPE);
168 goto err;
169 }
170
171 BIO_set_md(btmp,evp_md);
172 if (out == NULL)
173 out=btmp;
174 else
175 BIO_push(out,btmp);
176 btmp=NULL;
177 }
178 }
179
180 if (evp_cipher != NULL)
181 {
182 unsigned char key[EVP_MAX_KEY_LENGTH];
183 unsigned char iv[EVP_MAX_IV_LENGTH];
184 int keylen,ivlen;
185 int jj,max;
186 unsigned char *tmp;
187 EVP_CIPHER_CTX *ctx;
188
189 if ((btmp=BIO_new(BIO_f_cipher())) == NULL)
190 {
191 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
192 goto err;
193 }
194 BIO_get_cipher_ctx(btmp, &ctx);
195 keylen=EVP_CIPHER_key_length(evp_cipher);
196 ivlen=EVP_CIPHER_iv_length(evp_cipher);
197 if (RAND_bytes(key,keylen) <= 0)
198 goto err;
199 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
200 if (ivlen > 0) RAND_pseudo_bytes(iv,ivlen);
201 EVP_CipherInit_ex(ctx, evp_cipher, NULL, key, iv, 1);
202
203 if (ivlen > 0) {
204 if (xalg->parameter == NULL)
205 xalg->parameter=ASN1_TYPE_new();
206 if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0)
207 goto err;
208 }
209
210 /* Lets do the pub key stuff :-) */
211 max=0;
212 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
213 {
214 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
215 if (ri->cert == NULL)
216 {
217 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO);
218 goto err;
219 }
220 pkey=X509_get_pubkey(ri->cert);
221 jj=EVP_PKEY_size(pkey);
222 EVP_PKEY_free(pkey);
223 if (max < jj) max=jj;
224 }
225 if ((tmp=(unsigned char *)OPENSSL_malloc(max)) == NULL)
226 {
227 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_MALLOC_FAILURE);
228 goto err;
229 }
230 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
231 {
232 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
233 pkey=X509_get_pubkey(ri->cert);
234 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
235 EVP_PKEY_free(pkey);
236 if (jj <= 0)
237 {
238 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB);
239 OPENSSL_free(tmp);
240 goto err;
241 }
242 if (!M_ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj))
243 {
244 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
245 ERR_R_MALLOC_FAILURE);
246 OPENSSL_free(tmp);
247 goto err;
248 }
249 }
250 OPENSSL_free(tmp);
251 OPENSSL_cleanse(key, keylen);
252
253 if (out == NULL)
254 out=btmp;
255 else
256 BIO_push(out,btmp);
257 btmp=NULL;
258 }
259
260 if (bio == NULL)
261 {
262 if (PKCS7_is_detached(p7))
263 bio=BIO_new(BIO_s_null());
264 else
265 {
266 if (PKCS7_type_is_signed(p7))
267 {
268 ASN1_OCTET_STRING *os;
269 os = PKCS7_get_octet_string(
270 p7->d.sign->contents);
271 if (os && os->length > 0)
272 bio = BIO_new_mem_buf(os->data,
273 os->length);
274 }
275 if(bio == NULL)
276 {
277 bio=BIO_new(BIO_s_mem());
278 BIO_set_mem_eof_return(bio,0);
279 }
280 }
281 }
282 BIO_push(out,bio);
283 bio=NULL;
284 if (0)
285 {
286err:
287 if (out != NULL)
288 BIO_free_all(out);
289 if (btmp != NULL)
290 BIO_free_all(btmp);
291 out=NULL;
292 }
293 return(out);
294 }
295
296/* int */
297BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
298 {
299 int i,j;
300 BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
301 unsigned char *tmp=NULL;
302 X509_ALGOR *xa;
303 ASN1_OCTET_STRING *data_body=NULL;
304 const EVP_MD *evp_md;
305 const EVP_CIPHER *evp_cipher=NULL;
306 EVP_CIPHER_CTX *evp_ctx=NULL;
307 X509_ALGOR *enc_alg=NULL;
308 STACK_OF(X509_ALGOR) *md_sk=NULL;
309 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
310 X509_ALGOR *xalg=NULL;
311 PKCS7_RECIP_INFO *ri=NULL;
312
313 i=OBJ_obj2nid(p7->type);
314 p7->state=PKCS7_S_HEADER;
315
316 switch (i)
317 {
318 case NID_pkcs7_signed:
319 data_body=PKCS7_get_octet_string(p7->d.sign->contents);
320 md_sk=p7->d.sign->md_algs;
321 break;
322 case NID_pkcs7_signedAndEnveloped:
323 rsk=p7->d.signed_and_enveloped->recipientinfo;
324 md_sk=p7->d.signed_and_enveloped->md_algs;
325 data_body=p7->d.signed_and_enveloped->enc_data->enc_data;
326 enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;
327 evp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);
328 if (evp_cipher == NULL)
329 {
330 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
331 goto err;
332 }
333 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
334 break;
335 case NID_pkcs7_enveloped:
336 rsk=p7->d.enveloped->recipientinfo;
337 enc_alg=p7->d.enveloped->enc_data->algorithm;
338 data_body=p7->d.enveloped->enc_data->enc_data;
339 evp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);
340 if (evp_cipher == NULL)
341 {
342 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
343 goto err;
344 }
345 xalg=p7->d.enveloped->enc_data->algorithm;
346 break;
347 default:
348 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
349 goto err;
350 }
351
352 /* We will be checking the signature */
353 if (md_sk != NULL)
354 {
355 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
356 {
357 xa=sk_X509_ALGOR_value(md_sk,i);
358 if ((btmp=BIO_new(BIO_f_md())) == NULL)
359 {
360 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
361 goto err;
362 }
363
364 j=OBJ_obj2nid(xa->algorithm);
365 evp_md=EVP_get_digestbynid(j);
366 if (evp_md == NULL)
367 {
368 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);
369 goto err;
370 }
371
372 BIO_set_md(btmp,evp_md);
373 if (out == NULL)
374 out=btmp;
375 else
376 BIO_push(out,btmp);
377 btmp=NULL;
378 }
379 }
380
381 if (evp_cipher != NULL)
382 {
383#if 0
384 unsigned char key[EVP_MAX_KEY_LENGTH];
385 unsigned char iv[EVP_MAX_IV_LENGTH];
386 unsigned char *p;
387 int keylen,ivlen;
388 int max;
389 X509_OBJECT ret;
390#endif
391 int jj;
392
393 if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
394 {
395 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
396 goto err;
397 }
398
399 /* It was encrypted, we need to decrypt the secret key
400 * with the private key */
401
402 /* Find the recipientInfo which matches the passed certificate
403 * (if any)
404 */
405
406 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
407 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
408 if(!X509_NAME_cmp(ri->issuer_and_serial->issuer,
409 pcert->cert_info->issuer) &&
410 !M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
411 ri->issuer_and_serial->serial)) break;
412 ri=NULL;
413 }
414 if (ri == NULL) {
415 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
416 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
417 goto err;
418 }
419
420 jj=EVP_PKEY_size(pkey);
421 tmp=(unsigned char *)OPENSSL_malloc(jj+10);
422 if (tmp == NULL)
423 {
424 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
425 goto err;
426 }
427
428 jj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key),
429 M_ASN1_STRING_length(ri->enc_key), pkey);
430 if (jj <= 0)
431 {
432 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);
433 goto err;
434 }
435
436 evp_ctx=NULL;
437 BIO_get_cipher_ctx(etmp,&evp_ctx);
438 EVP_CipherInit_ex(evp_ctx,evp_cipher,NULL,NULL,NULL,0);
439 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
440 goto err;
441
442 if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) {
443 /* Some S/MIME clients don't use the same key
444 * and effective key length. The key length is
445 * determined by the size of the decrypted RSA key.
446 */
447 if(!EVP_CIPHER_CTX_set_key_length(evp_ctx, jj))
448 {
449 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
450 PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
451 goto err;
452 }
453 }
454 EVP_CipherInit_ex(evp_ctx,NULL,NULL,tmp,NULL,0);
455
456 OPENSSL_cleanse(tmp,jj);
457
458 if (out == NULL)
459 out=etmp;
460 else
461 BIO_push(out,etmp);
462 etmp=NULL;
463 }
464
465#if 1
466 if (PKCS7_is_detached(p7) || (in_bio != NULL))
467 {
468 bio=in_bio;
469 }
470 else
471 {
472#if 0
473 bio=BIO_new(BIO_s_mem());
474 /* We need to set this so that when we have read all
475 * the data, the encrypt BIO, if present, will read
476 * EOF and encode the last few bytes */
477 BIO_set_mem_eof_return(bio,0);
478
479 if (data_body->length > 0)
480 BIO_write(bio,(char *)data_body->data,data_body->length);
481#else
482 if (data_body->length > 0)
483 bio = BIO_new_mem_buf(data_body->data,data_body->length);
484 else {
485 bio=BIO_new(BIO_s_mem());
486 BIO_set_mem_eof_return(bio,0);
487 }
488#endif
489 }
490 BIO_push(out,bio);
491 bio=NULL;
492#endif
493 if (0)
494 {
495err:
496 if (out != NULL) BIO_free_all(out);
497 if (btmp != NULL) BIO_free_all(btmp);
498 if (etmp != NULL) BIO_free_all(etmp);
499 if (bio != NULL) BIO_free_all(bio);
500 out=NULL;
501 }
502 if (tmp != NULL)
503 OPENSSL_free(tmp);
504 return(out);
505 }
506
507int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
508 {
509 int ret=0;
510 int i,j;
511 BIO *btmp;
512 BUF_MEM *buf_mem=NULL;
513 BUF_MEM *buf=NULL;
514 PKCS7_SIGNER_INFO *si;
515 EVP_MD_CTX *mdc,ctx_tmp;
516 STACK_OF(X509_ATTRIBUTE) *sk;
517 STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL;
518 ASN1_OCTET_STRING *os=NULL;
519
520 EVP_MD_CTX_init(&ctx_tmp);
521 i=OBJ_obj2nid(p7->type);
522 p7->state=PKCS7_S_HEADER;
523
524 switch (i)
525 {
526 case NID_pkcs7_signedAndEnveloped:
527 /* XXXXXXXXXXXXXXXX */
528 si_sk=p7->d.signed_and_enveloped->signer_info;
529 if (!(os=M_ASN1_OCTET_STRING_new()))
530 {
531 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_MALLOC_FAILURE);
532 goto err;
533 }
534 p7->d.signed_and_enveloped->enc_data->enc_data=os;
535 break;
536 case NID_pkcs7_enveloped:
537 /* XXXXXXXXXXXXXXXX */
538 if (!(os=M_ASN1_OCTET_STRING_new()))
539 {
540 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_MALLOC_FAILURE);
541 goto err;
542 }
543 p7->d.enveloped->enc_data->enc_data=os;
544 break;
545 case NID_pkcs7_signed:
546 si_sk=p7->d.sign->signer_info;
547 os=PKCS7_get_octet_string(p7->d.sign->contents);
548 /* If detached data then the content is excluded */
549 if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) {
550 M_ASN1_OCTET_STRING_free(os);
551 p7->d.sign->contents->d.data = NULL;
552 }
553 break;
554 }
555
556 if (si_sk != NULL)
557 {
558 if ((buf=BUF_MEM_new()) == NULL)
559 {
560 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
561 goto err;
562 }
563 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
564 {
565 si=sk_PKCS7_SIGNER_INFO_value(si_sk,i);
566 if (si->pkey == NULL) continue;
567
568 j=OBJ_obj2nid(si->digest_alg->algorithm);
569
570 btmp=bio;
571 for (;;)
572 {
573 if ((btmp=BIO_find_type(btmp,BIO_TYPE_MD))
574 == NULL)
575 {
576 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
577 goto err;
578 }
579 BIO_get_md_ctx(btmp,&mdc);
580 if (mdc == NULL)
581 {
582 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_INTERNAL_ERROR);
583 goto err;
584 }
585 if (EVP_MD_CTX_type(mdc) == j)
586 break;
587 else
588 btmp=BIO_next(btmp);
589 }
590
591 /* We now have the EVP_MD_CTX, lets do the
592 * signing. */
593 EVP_MD_CTX_copy_ex(&ctx_tmp,mdc);
594 if (!BUF_MEM_grow_clean(buf,EVP_PKEY_size(si->pkey)))
595 {
596 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
597 goto err;
598 }
599
600 sk=si->auth_attr;
601
602 /* If there are attributes, we add the digest
603 * attribute and only sign the attributes */
604 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
605 {
606 unsigned char md_data[EVP_MAX_MD_SIZE], *abuf=NULL;
607 unsigned int md_len, alen;
608 ASN1_OCTET_STRING *digest;
609 ASN1_UTCTIME *sign_time;
610 const EVP_MD *md_tmp;
611
612 /* Add signing time if not already present */
613 if (!PKCS7_get_signed_attribute(si,
614 NID_pkcs9_signingTime))
615 {
616 if (!(sign_time=X509_gmtime_adj(NULL,0)))
617 {
618 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
619 ERR_R_MALLOC_FAILURE);
620 goto err;
621 }
622 PKCS7_add_signed_attribute(si,
623 NID_pkcs9_signingTime,
624 V_ASN1_UTCTIME,sign_time);
625 }
626
627 /* Add digest */
628 md_tmp=EVP_MD_CTX_md(&ctx_tmp);
629 EVP_DigestFinal_ex(&ctx_tmp,md_data,&md_len);
630 if (!(digest=M_ASN1_OCTET_STRING_new()))
631 {
632 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
633 ERR_R_MALLOC_FAILURE);
634 goto err;
635 }
636 if (!M_ASN1_OCTET_STRING_set(digest,md_data,
637 md_len))
638 {
639 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
640 ERR_R_MALLOC_FAILURE);
641 goto err;
642 }
643 PKCS7_add_signed_attribute(si,
644 NID_pkcs9_messageDigest,
645 V_ASN1_OCTET_STRING,digest);
646
647 /* Now sign the attributes */
648 EVP_SignInit_ex(&ctx_tmp,md_tmp,NULL);
649 alen = ASN1_item_i2d((ASN1_VALUE *)sk,&abuf,
650 ASN1_ITEM_rptr(PKCS7_ATTR_SIGN));
651 if(!abuf) goto err;
652 EVP_SignUpdate(&ctx_tmp,abuf,alen);
653 OPENSSL_free(abuf);
654 }
655
656#ifndef OPENSSL_NO_DSA
657 if (si->pkey->type == EVP_PKEY_DSA)
658 ctx_tmp.digest=EVP_dss1();
659#endif
660
661 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data,
662 (unsigned int *)&buf->length,si->pkey))
663 {
664 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_EVP_LIB);
665 goto err;
666 }
667 if (!ASN1_STRING_set(si->enc_digest,
668 (unsigned char *)buf->data,buf->length))
669 {
670 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_ASN1_LIB);
671 goto err;
672 }
673 }
674 }
675
676 if (!PKCS7_is_detached(p7))
677 {
678 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
679 if (btmp == NULL)
680 {
681 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
682 goto err;
683 }
684 BIO_get_mem_ptr(btmp,&buf_mem);
685 /* Mark the BIO read only then we can use its copy of the data
686 * instead of making an extra copy.
687 */
688 BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
689 BIO_set_mem_eof_return(btmp, 0);
690 os->data = (unsigned char *)buf_mem->data;
691 os->length = buf_mem->length;
692#if 0
693 M_ASN1_OCTET_STRING_set(os,
694 (unsigned char *)buf_mem->data,buf_mem->length);
695#endif
696 }
697 ret=1;
698err:
699 EVP_MD_CTX_cleanup(&ctx_tmp);
700 if (buf != NULL) BUF_MEM_free(buf);
701 return(ret);
702 }
703
704int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
705 PKCS7 *p7, PKCS7_SIGNER_INFO *si)
706 {
707 PKCS7_ISSUER_AND_SERIAL *ias;
708 int ret=0,i;
709 STACK_OF(X509) *cert;
710 X509 *x509;
711
712 if (PKCS7_type_is_signed(p7))
713 {
714 cert=p7->d.sign->cert;
715 }
716 else if (PKCS7_type_is_signedAndEnveloped(p7))
717 {
718 cert=p7->d.signed_and_enveloped->cert;
719 }
720 else
721 {
722 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE);
723 goto err;
724 }
725 /* XXXXXXXXXXXXXXXXXXXXXXX */
726 ias=si->issuer_and_serial;
727
728 x509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial);
729
730 /* were we able to find the cert in passed to us */
731 if (x509 == NULL)
732 {
733 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
734 goto err;
735 }
736
737 /* Lets verify */
738 if(!X509_STORE_CTX_init(ctx,cert_store,x509,cert))
739 {
740 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
741 goto err;
742 }
743 X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN);
744 i=X509_verify_cert(ctx);
745 if (i <= 0)
746 {
747 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
748 X509_STORE_CTX_cleanup(ctx);
749 goto err;
750 }
751 X509_STORE_CTX_cleanup(ctx);
752
753 return PKCS7_signatureVerify(bio, p7, si, x509);
754 err:
755 return ret;
756 }
757
758int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
759 X509 *x509)
760 {
761 ASN1_OCTET_STRING *os;
762 EVP_MD_CTX mdc_tmp,*mdc;
763 int ret=0,i;
764 int md_type;
765 STACK_OF(X509_ATTRIBUTE) *sk;
766 BIO *btmp;
767 EVP_PKEY *pkey;
768
769 EVP_MD_CTX_init(&mdc_tmp);
770
771 if (!PKCS7_type_is_signed(p7) &&
772 !PKCS7_type_is_signedAndEnveloped(p7)) {
773 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
774 PKCS7_R_WRONG_PKCS7_TYPE);
775 goto err;
776 }
777
778 md_type=OBJ_obj2nid(si->digest_alg->algorithm);
779
780 btmp=bio;
781 for (;;)
782 {
783 if ((btmp == NULL) ||
784 ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))
785 {
786 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
787 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
788 goto err;
789 }
790 BIO_get_md_ctx(btmp,&mdc);
791 if (mdc == NULL)
792 {
793 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
794 ERR_R_INTERNAL_ERROR);
795 goto err;
796 }
797 if (EVP_MD_CTX_type(mdc) == md_type)
798 break;
799 /* Workaround for some broken clients that put the signature
800 * OID instead of the digest OID in digest_alg->algorithm
801 */
802 if (EVP_MD_pkey_type(EVP_MD_CTX_md(mdc)) == md_type)
803 break;
804 btmp=BIO_next(btmp);
805 }
806
807 /* mdc is the digest ctx that we want, unless there are attributes,
808 * in which case the digest is the signed attributes */
809 EVP_MD_CTX_copy_ex(&mdc_tmp,mdc);
810
811 sk=si->auth_attr;
812 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
813 {
814 unsigned char md_dat[EVP_MAX_MD_SIZE], *abuf = NULL;
815 unsigned int md_len, alen;
816 ASN1_OCTET_STRING *message_digest;
817
818 EVP_DigestFinal_ex(&mdc_tmp,md_dat,&md_len);
819 message_digest=PKCS7_digest_from_attributes(sk);
820 if (!message_digest)
821 {
822 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
823 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
824 goto err;
825 }
826 if ((message_digest->length != (int)md_len) ||
827 (memcmp(message_digest->data,md_dat,md_len)))
828 {
829#if 0
830{
831int ii;
832for (ii=0; ii<message_digest->length; ii++)
833 printf("%02X",message_digest->data[ii]); printf(" sent\n");
834for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
835}
836#endif
837 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
838 PKCS7_R_DIGEST_FAILURE);
839 ret= -1;
840 goto err;
841 }
842
843 EVP_VerifyInit_ex(&mdc_tmp,EVP_get_digestbynid(md_type), NULL);
844
845 alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
846 ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));
847 EVP_VerifyUpdate(&mdc_tmp, abuf, alen);
848
849 OPENSSL_free(abuf);
850 }
851
852 os=si->enc_digest;
853 pkey = X509_get_pubkey(x509);
854 if (!pkey)
855 {
856 ret = -1;
857 goto err;
858 }
859#ifndef OPENSSL_NO_DSA
860 if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();
861#endif
862
863 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);
864 EVP_PKEY_free(pkey);
865 if (i <= 0)
866 {
867 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
868 PKCS7_R_SIGNATURE_FAILURE);
869 ret= -1;
870 goto err;
871 }
872 else
873 ret=1;
874err:
875 EVP_MD_CTX_cleanup(&mdc_tmp);
876 return(ret);
877 }
878
879PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx)
880 {
881 STACK_OF(PKCS7_RECIP_INFO) *rsk;
882 PKCS7_RECIP_INFO *ri;
883 int i;
884
885 i=OBJ_obj2nid(p7->type);
886 if (i != NID_pkcs7_signedAndEnveloped) return(NULL);
887 rsk=p7->d.signed_and_enveloped->recipientinfo;
888 ri=sk_PKCS7_RECIP_INFO_value(rsk,0);
889 if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL);
890 ri=sk_PKCS7_RECIP_INFO_value(rsk,idx);
891 return(ri->issuer_and_serial);
892 }
893
894ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid)
895 {
896 return(get_attribute(si->auth_attr,nid));
897 }
898
899ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
900 {
901 return(get_attribute(si->unauth_attr,nid));
902 }
903
904static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid)
905 {
906 int i;
907 X509_ATTRIBUTE *xa;
908 ASN1_OBJECT *o;
909
910 o=OBJ_nid2obj(nid);
911 if (!o || !sk) return(NULL);
912 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
913 {
914 xa=sk_X509_ATTRIBUTE_value(sk,i);
915 if (OBJ_cmp(xa->object,o) == 0)
916 {
917 if (!xa->single && sk_ASN1_TYPE_num(xa->value.set))
918 return(sk_ASN1_TYPE_value(xa->value.set,0));
919 else
920 return(NULL);
921 }
922 }
923 return(NULL);
924 }
925
926ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
927{
928 ASN1_TYPE *astype;
929 if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL;
930 return astype->value.octet_string;
931}
932
933int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
934 STACK_OF(X509_ATTRIBUTE) *sk)
935 {
936 int i;
937
938 if (p7si->auth_attr != NULL)
939 sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
940 p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk);
941 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
942 {
943 if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i,
944 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
945 == NULL)
946 return(0);
947 }
948 return(1);
949 }
950
951int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk)
952 {
953 int i;
954
955 if (p7si->unauth_attr != NULL)
956 sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr,
957 X509_ATTRIBUTE_free);
958 p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk);
959 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
960 {
961 if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i,
962 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
963 == NULL)
964 return(0);
965 }
966 return(1);
967 }
968
969int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
970 void *value)
971 {
972 return(add_attribute(&(p7si->auth_attr),nid,atrtype,value));
973 }
974
975int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
976 void *value)
977 {
978 return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value));
979 }
980
981static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
982 void *value)
983 {
984 X509_ATTRIBUTE *attr=NULL;
985
986 if (*sk == NULL)
987 {
988 *sk = sk_X509_ATTRIBUTE_new_null();
989new_attrib:
990 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
991 sk_X509_ATTRIBUTE_push(*sk,attr);
992 }
993 else
994 {
995 int i;
996
997 for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++)
998 {
999 attr=sk_X509_ATTRIBUTE_value(*sk,i);
1000 if (OBJ_obj2nid(attr->object) == nid)
1001 {
1002 X509_ATTRIBUTE_free(attr);
1003 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
1004 sk_X509_ATTRIBUTE_set(*sk,i,attr);
1005 goto end;
1006 }
1007 }
1008 goto new_attrib;
1009 }
1010end:
1011 return(1);
1012 }
1013
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
deleted file mode 100644
index ee1817c7af..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ /dev/null
@@ -1,500 +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 if (ret && PKCS7_type_is_data(p7->d.sign->contents))
78 {
79 ASN1_OCTET_STRING *os;
80 os=p7->d.sign->contents->d.data;
81 ASN1_OCTET_STRING_free(os);
82 p7->d.sign->contents->d.data = NULL;
83 }
84 }
85 else
86 {
87 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
88 ret=0;
89 }
90 break;
91 case PKCS7_OP_GET_DETACHED_SIGNATURE:
92 if (nid == NID_pkcs7_signed)
93 {
94 if(!p7->d.sign || !p7->d.sign->contents->d.ptr)
95 ret = 1;
96 else ret = 0;
97
98 p7->detached = ret;
99 }
100 else
101 {
102 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
103 ret=0;
104 }
105
106 break;
107 default:
108 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_UNKNOWN_OPERATION);
109 ret=0;
110 }
111 return(ret);
112 }
113
114int PKCS7_content_new(PKCS7 *p7, int type)
115 {
116 PKCS7 *ret=NULL;
117
118 if ((ret=PKCS7_new()) == NULL) goto err;
119 if (!PKCS7_set_type(ret,type)) goto err;
120 if (!PKCS7_set_content(p7,ret)) goto err;
121
122 return(1);
123err:
124 if (ret != NULL) PKCS7_free(ret);
125 return(0);
126 }
127
128int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data)
129 {
130 int i;
131
132 i=OBJ_obj2nid(p7->type);
133 switch (i)
134 {
135 case NID_pkcs7_signed:
136 if (p7->d.sign->contents != NULL)
137 PKCS7_free(p7->d.sign->contents);
138 p7->d.sign->contents=p7_data;
139 break;
140 case NID_pkcs7_digest:
141 case NID_pkcs7_data:
142 case NID_pkcs7_enveloped:
143 case NID_pkcs7_signedAndEnveloped:
144 case NID_pkcs7_encrypted:
145 default:
146 PKCS7err(PKCS7_F_PKCS7_SET_CONTENT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
147 goto err;
148 }
149 return(1);
150err:
151 return(0);
152 }
153
154int PKCS7_set_type(PKCS7 *p7, int type)
155 {
156 ASN1_OBJECT *obj;
157
158 /*PKCS7_content_free(p7);*/
159 obj=OBJ_nid2obj(type); /* will not fail */
160
161 switch (type)
162 {
163 case NID_pkcs7_signed:
164 p7->type=obj;
165 if ((p7->d.sign=PKCS7_SIGNED_new()) == NULL)
166 goto err;
167 if (!ASN1_INTEGER_set(p7->d.sign->version,1))
168 {
169 PKCS7_SIGNED_free(p7->d.sign);
170 p7->d.sign=NULL;
171 goto err;
172 }
173 break;
174 case NID_pkcs7_data:
175 p7->type=obj;
176 if ((p7->d.data=M_ASN1_OCTET_STRING_new()) == NULL)
177 goto err;
178 break;
179 case NID_pkcs7_signedAndEnveloped:
180 p7->type=obj;
181 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new())
182 == NULL) goto err;
183 ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1);
184 if (!ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1))
185 goto err;
186 p7->d.signed_and_enveloped->enc_data->content_type
187 = OBJ_nid2obj(NID_pkcs7_data);
188 break;
189 case NID_pkcs7_enveloped:
190 p7->type=obj;
191 if ((p7->d.enveloped=PKCS7_ENVELOPE_new())
192 == NULL) goto err;
193 if (!ASN1_INTEGER_set(p7->d.enveloped->version,0))
194 goto err;
195 p7->d.enveloped->enc_data->content_type
196 = OBJ_nid2obj(NID_pkcs7_data);
197 break;
198 case NID_pkcs7_encrypted:
199 p7->type=obj;
200 if ((p7->d.encrypted=PKCS7_ENCRYPT_new())
201 == NULL) goto err;
202 if (!ASN1_INTEGER_set(p7->d.encrypted->version,0))
203 goto err;
204 p7->d.encrypted->enc_data->content_type
205 = OBJ_nid2obj(NID_pkcs7_data);
206 break;
207
208 case NID_pkcs7_digest:
209 default:
210 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
211 goto err;
212 }
213 return(1);
214err:
215 return(0);
216 }
217
218int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
219 {
220 int i,j,nid;
221 X509_ALGOR *alg;
222 STACK_OF(PKCS7_SIGNER_INFO) *signer_sk;
223 STACK_OF(X509_ALGOR) *md_sk;
224
225 i=OBJ_obj2nid(p7->type);
226 switch (i)
227 {
228 case NID_pkcs7_signed:
229 signer_sk= p7->d.sign->signer_info;
230 md_sk= p7->d.sign->md_algs;
231 break;
232 case NID_pkcs7_signedAndEnveloped:
233 signer_sk= p7->d.signed_and_enveloped->signer_info;
234 md_sk= p7->d.signed_and_enveloped->md_algs;
235 break;
236 default:
237 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,PKCS7_R_WRONG_CONTENT_TYPE);
238 return(0);
239 }
240
241 nid=OBJ_obj2nid(psi->digest_alg->algorithm);
242
243 /* If the digest is not currently listed, add it */
244 j=0;
245 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
246 {
247 alg=sk_X509_ALGOR_value(md_sk,i);
248 if (OBJ_obj2nid(alg->algorithm) == nid)
249 {
250 j=1;
251 break;
252 }
253 }
254 if (!j) /* we need to add another algorithm */
255 {
256 if(!(alg=X509_ALGOR_new())
257 || !(alg->parameter = ASN1_TYPE_new())) {
258 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE);
259 return(0);
260 }
261 alg->algorithm=OBJ_nid2obj(nid);
262 alg->parameter->type = V_ASN1_NULL;
263 sk_X509_ALGOR_push(md_sk,alg);
264 }
265
266 sk_PKCS7_SIGNER_INFO_push(signer_sk,psi);
267 return(1);
268 }
269
270int PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
271 {
272 int i;
273 STACK_OF(X509) **sk;
274
275 i=OBJ_obj2nid(p7->type);
276 switch (i)
277 {
278 case NID_pkcs7_signed:
279 sk= &(p7->d.sign->cert);
280 break;
281 case NID_pkcs7_signedAndEnveloped:
282 sk= &(p7->d.signed_and_enveloped->cert);
283 break;
284 default:
285 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,PKCS7_R_WRONG_CONTENT_TYPE);
286 return(0);
287 }
288
289 if (*sk == NULL)
290 *sk=sk_X509_new_null();
291 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
292 sk_X509_push(*sk,x509);
293 return(1);
294 }
295
296int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
297 {
298 int i;
299 STACK_OF(X509_CRL) **sk;
300
301 i=OBJ_obj2nid(p7->type);
302 switch (i)
303 {
304 case NID_pkcs7_signed:
305 sk= &(p7->d.sign->crl);
306 break;
307 case NID_pkcs7_signedAndEnveloped:
308 sk= &(p7->d.signed_and_enveloped->crl);
309 break;
310 default:
311 PKCS7err(PKCS7_F_PKCS7_ADD_CRL,PKCS7_R_WRONG_CONTENT_TYPE);
312 return(0);
313 }
314
315 if (*sk == NULL)
316 *sk=sk_X509_CRL_new_null();
317
318 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL);
319 sk_X509_CRL_push(*sk,crl);
320 return(1);
321 }
322
323int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
324 const EVP_MD *dgst)
325 {
326 char is_dsa;
327 if (pkey->type == EVP_PKEY_DSA) is_dsa = 1;
328 else is_dsa = 0;
329 /* We now need to add another PKCS7_SIGNER_INFO entry */
330 if (!ASN1_INTEGER_set(p7i->version,1))
331 goto err;
332 if (!X509_NAME_set(&p7i->issuer_and_serial->issuer,
333 X509_get_issuer_name(x509)))
334 goto err;
335
336 /* because ASN1_INTEGER_set is used to set a 'long' we will do
337 * things the ugly way. */
338 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
339 if (!(p7i->issuer_and_serial->serial=
340 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509))))
341 goto err;
342
343 /* lets keep the pkey around for a while */
344 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
345 p7i->pkey=pkey;
346
347 /* Set the algorithms */
348 if (is_dsa) p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1);
349 else
350 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst));
351
352 if (p7i->digest_alg->parameter != NULL)
353 ASN1_TYPE_free(p7i->digest_alg->parameter);
354 if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL)
355 goto err;
356 p7i->digest_alg->parameter->type=V_ASN1_NULL;
357
358 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type));
359
360 if (p7i->digest_enc_alg->parameter != NULL)
361 ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
362 if(is_dsa) p7i->digest_enc_alg->parameter = NULL;
363 else {
364 if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new()))
365 goto err;
366 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
367 }
368
369 return(1);
370err:
371 return(0);
372 }
373
374PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
375 const EVP_MD *dgst)
376 {
377 PKCS7_SIGNER_INFO *si;
378
379 if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err;
380 if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err;
381 if (!PKCS7_add_signer(p7,si)) goto err;
382 return(si);
383err:
384 return(NULL);
385 }
386
387STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
388 {
389 if (PKCS7_type_is_signed(p7))
390 {
391 return(p7->d.sign->signer_info);
392 }
393 else if (PKCS7_type_is_signedAndEnveloped(p7))
394 {
395 return(p7->d.signed_and_enveloped->signer_info);
396 }
397 else
398 return(NULL);
399 }
400
401PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
402 {
403 PKCS7_RECIP_INFO *ri;
404
405 if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err;
406 if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err;
407 if (!PKCS7_add_recipient_info(p7,ri)) goto err;
408 return(ri);
409err:
410 return(NULL);
411 }
412
413int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
414 {
415 int i;
416 STACK_OF(PKCS7_RECIP_INFO) *sk;
417
418 i=OBJ_obj2nid(p7->type);
419 switch (i)
420 {
421 case NID_pkcs7_signedAndEnveloped:
422 sk= p7->d.signed_and_enveloped->recipientinfo;
423 break;
424 case NID_pkcs7_enveloped:
425 sk= p7->d.enveloped->recipientinfo;
426 break;
427 default:
428 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE);
429 return(0);
430 }
431
432 sk_PKCS7_RECIP_INFO_push(sk,ri);
433 return(1);
434 }
435
436int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
437 {
438 if (!ASN1_INTEGER_set(p7i->version,0))
439 return 0;
440 if (!X509_NAME_set(&p7i->issuer_and_serial->issuer,
441 X509_get_issuer_name(x509)))
442 return 0;
443
444 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
445 if (!(p7i->issuer_and_serial->serial=
446 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509))))
447 return 0;
448
449 X509_ALGOR_free(p7i->key_enc_algor);
450 if (!(p7i->key_enc_algor= X509_ALGOR_dup(x509->cert_info->key->algor)))
451 return 0;
452
453 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
454 p7i->cert=x509;
455
456 return(1);
457 }
458
459X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
460 {
461 if (PKCS7_type_is_signed(p7))
462 return(X509_find_by_issuer_and_serial(p7->d.sign->cert,
463 si->issuer_and_serial->issuer,
464 si->issuer_and_serial->serial));
465 else
466 return(NULL);
467 }
468
469int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
470 {
471 int i;
472 ASN1_OBJECT *objtmp;
473 PKCS7_ENC_CONTENT *ec;
474
475 i=OBJ_obj2nid(p7->type);
476 switch (i)
477 {
478 case NID_pkcs7_signedAndEnveloped:
479 ec=p7->d.signed_and_enveloped->enc_data;
480 break;
481 case NID_pkcs7_enveloped:
482 ec=p7->d.enveloped->enc_data;
483 break;
484 default:
485 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE);
486 return(0);
487 }
488
489 /* Check cipher OID exists and has data in it*/
490 i = EVP_CIPHER_type(cipher);
491 if(i == NID_undef) {
492 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
493 return(0);
494 }
495 objtmp = OBJ_nid2obj(i);
496
497 ec->cipher = cipher;
498 return 1;
499 }
500
diff --git a/src/lib/libcrypto/pkcs7/pk7_mime.c b/src/lib/libcrypto/pkcs7/pk7_mime.c
deleted file mode 100644
index 927b88c3e7..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_mime.c
+++ /dev/null
@@ -1,734 +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-2005 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 *param_name; /* Param name e.g. "micalg" */
74char *param_value; /* Param value e.g. "sha1" */
75} MIME_PARAM;
76
77DECLARE_STACK_OF(MIME_PARAM)
78IMPLEMENT_STACK_OF(MIME_PARAM)
79
80typedef struct {
81char *name; /* Name of line e.g. "content-type" */
82char *value; /* Value of line e.g. "text/plain" */
83STACK_OF(MIME_PARAM) *params; /* Zero or more parameters */
84} MIME_HEADER;
85
86DECLARE_STACK_OF(MIME_HEADER)
87IMPLEMENT_STACK_OF(MIME_HEADER)
88
89static int B64_write_PKCS7(BIO *bio, PKCS7 *p7);
90static PKCS7 *B64_read_PKCS7(BIO *bio);
91static char * strip_ends(char *name);
92static char * strip_start(char *name);
93static char * strip_end(char *name);
94static MIME_HEADER *mime_hdr_new(char *name, char *value);
95static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value);
96static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio);
97static int mime_hdr_cmp(const MIME_HEADER * const *a,
98 const MIME_HEADER * const *b);
99static int mime_param_cmp(const MIME_PARAM * const *a,
100 const MIME_PARAM * const *b);
101static void mime_param_free(MIME_PARAM *param);
102static int mime_bound_check(char *line, int linelen, char *bound, int blen);
103static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret);
104static int strip_eol(char *linebuf, int *plen);
105static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name);
106static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name);
107static void mime_hdr_free(MIME_HEADER *hdr);
108
109#define MAX_SMLEN 1024
110#define mime_debug(x) /* x */
111
112
113typedef void (*stkfree)();
114
115/* Base 64 read and write of PKCS#7 structure */
116
117static int B64_write_PKCS7(BIO *bio, PKCS7 *p7)
118{
119 BIO *b64;
120 if(!(b64 = BIO_new(BIO_f_base64()))) {
121 PKCS7err(PKCS7_F_B64_WRITE_PKCS7,ERR_R_MALLOC_FAILURE);
122 return 0;
123 }
124 bio = BIO_push(b64, bio);
125 i2d_PKCS7_bio(bio, p7);
126 BIO_flush(bio);
127 bio = BIO_pop(bio);
128 BIO_free(b64);
129 return 1;
130}
131
132static PKCS7 *B64_read_PKCS7(BIO *bio)
133{
134 BIO *b64;
135 PKCS7 *p7;
136 if(!(b64 = BIO_new(BIO_f_base64()))) {
137 PKCS7err(PKCS7_F_B64_READ_PKCS7,ERR_R_MALLOC_FAILURE);
138 return 0;
139 }
140 bio = BIO_push(b64, bio);
141 if(!(p7 = d2i_PKCS7_bio(bio, NULL)))
142 PKCS7err(PKCS7_F_B64_READ_PKCS7,PKCS7_R_DECODE_ERROR);
143 BIO_flush(bio);
144 bio = BIO_pop(bio);
145 BIO_free(b64);
146 return p7;
147}
148
149/* SMIME sender */
150
151int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
152{
153 char bound[33], c;
154 int i;
155 char *mime_prefix, *mime_eol, *msg_type=NULL;
156 if (flags & PKCS7_NOOLDMIMETYPE)
157 mime_prefix = "application/pkcs7-";
158 else
159 mime_prefix = "application/x-pkcs7-";
160
161 if (flags & PKCS7_CRLFEOL)
162 mime_eol = "\r\n";
163 else
164 mime_eol = "\n";
165 if((flags & PKCS7_DETACHED) && data) {
166 /* We want multipart/signed */
167 /* Generate a random boundary */
168 RAND_pseudo_bytes((unsigned char *)bound, 32);
169 for(i = 0; i < 32; i++) {
170 c = bound[i] & 0xf;
171 if(c < 10) c += '0';
172 else c += 'A' - 10;
173 bound[i] = c;
174 }
175 bound[32] = 0;
176 BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol);
177 BIO_printf(bio, "Content-Type: multipart/signed;");
178 BIO_printf(bio, " protocol=\"%ssignature\";", mime_prefix);
179 BIO_printf(bio, " micalg=sha1; boundary=\"----%s\"%s%s",
180 bound, mime_eol, mime_eol);
181 BIO_printf(bio, "This is an S/MIME signed message%s%s",
182 mime_eol, mime_eol);
183 /* Now write out the first part */
184 BIO_printf(bio, "------%s%s", bound, mime_eol);
185 SMIME_crlf_copy(data, bio, flags);
186 BIO_printf(bio, "%s------%s%s", mime_eol, bound, mime_eol);
187
188 /* Headers for signature */
189
190 BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix);
191 BIO_printf(bio, " name=\"smime.p7s\"%s", mime_eol);
192 BIO_printf(bio, "Content-Transfer-Encoding: base64%s",
193 mime_eol);
194 BIO_printf(bio, "Content-Disposition: attachment;");
195 BIO_printf(bio, " filename=\"smime.p7s\"%s%s",
196 mime_eol, mime_eol);
197 B64_write_PKCS7(bio, p7);
198 BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound,
199 mime_eol, mime_eol);
200 return 1;
201 }
202
203 /* Determine smime-type header */
204
205 if (PKCS7_type_is_enveloped(p7))
206 msg_type = "enveloped-data";
207 else if (PKCS7_type_is_signed(p7))
208 {
209 /* If we have any signers it is signed-data othewise
210 * certs-only.
211 */
212 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
213 sinfos = PKCS7_get_signer_info(p7);
214 if (sk_PKCS7_SIGNER_INFO_num(sinfos) > 0)
215 msg_type = "signed-data";
216 else
217 msg_type = "certs-only";
218 }
219 /* MIME headers */
220 BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol);
221 BIO_printf(bio, "Content-Disposition: attachment;");
222 BIO_printf(bio, " filename=\"smime.p7m\"%s", mime_eol);
223 BIO_printf(bio, "Content-Type: %smime;", mime_prefix);
224 if (msg_type)
225 BIO_printf(bio, " smime-type=%s;", msg_type);
226 BIO_printf(bio, " name=\"smime.p7m\"%s", mime_eol);
227 BIO_printf(bio, "Content-Transfer-Encoding: base64%s%s",
228 mime_eol, mime_eol);
229 B64_write_PKCS7(bio, p7);
230 BIO_printf(bio, "%s", mime_eol);
231 return 1;
232}
233
234/* SMIME reader: handle multipart/signed and opaque signing.
235 * in multipart case the content is placed in a memory BIO
236 * pointed to by "bcont". In opaque this is set to NULL
237 */
238
239PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
240{
241 BIO *p7in;
242 STACK_OF(MIME_HEADER) *headers = NULL;
243 STACK_OF(BIO) *parts = NULL;
244 MIME_HEADER *hdr;
245 MIME_PARAM *prm;
246 PKCS7 *p7;
247 int ret;
248
249 if(bcont) *bcont = NULL;
250
251 if (!(headers = mime_parse_hdr(bio))) {
252 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_PARSE_ERROR);
253 return NULL;
254 }
255
256 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
257 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
258 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_CONTENT_TYPE);
259 return NULL;
260 }
261
262 /* Handle multipart/signed */
263
264 if(!strcmp(hdr->value, "multipart/signed")) {
265 /* Split into two parts */
266 prm = mime_param_find(hdr, "boundary");
267 if(!prm || !prm->param_value) {
268 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
269 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BOUNDARY);
270 return NULL;
271 }
272 ret = multi_split(bio, prm->param_value, &parts);
273 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
274 if(!ret || (sk_BIO_num(parts) != 2) ) {
275 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BODY_FAILURE);
276 sk_BIO_pop_free(parts, BIO_vfree);
277 return NULL;
278 }
279
280 /* Parse the signature piece */
281 p7in = sk_BIO_value(parts, 1);
282
283 if (!(headers = mime_parse_hdr(p7in))) {
284 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_SIG_PARSE_ERROR);
285 sk_BIO_pop_free(parts, BIO_vfree);
286 return NULL;
287 }
288
289 /* Get content type */
290
291 if(!(hdr = mime_hdr_find(headers, "content-type")) ||
292 !hdr->value) {
293 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
294 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_SIG_CONTENT_TYPE);
295 return NULL;
296 }
297
298 if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
299 strcmp(hdr->value, "application/pkcs7-signature")) {
300 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
301 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_SIG_INVALID_MIME_TYPE);
302 ERR_add_error_data(2, "type: ", hdr->value);
303 sk_BIO_pop_free(parts, BIO_vfree);
304 return NULL;
305 }
306 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
307 /* Read in PKCS#7 */
308 if(!(p7 = B64_read_PKCS7(p7in))) {
309 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_PKCS7_SIG_PARSE_ERROR);
310 sk_BIO_pop_free(parts, BIO_vfree);
311 return NULL;
312 }
313
314 if(bcont) {
315 *bcont = sk_BIO_value(parts, 0);
316 BIO_free(p7in);
317 sk_BIO_free(parts);
318 } else sk_BIO_pop_free(parts, BIO_vfree);
319 return p7;
320 }
321
322 /* OK, if not multipart/signed try opaque signature */
323
324 if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
325 strcmp (hdr->value, "application/pkcs7-mime")) {
326 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_INVALID_MIME_TYPE);
327 ERR_add_error_data(2, "type: ", hdr->value);
328 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
329 return NULL;
330 }
331
332 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
333
334 if(!(p7 = B64_read_PKCS7(bio))) {
335 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_PKCS7_PARSE_ERROR);
336 return NULL;
337 }
338 return p7;
339
340}
341
342/* Copy text from one BIO to another making the output CRLF at EOL */
343int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
344{
345 char eol;
346 int len;
347 char linebuf[MAX_SMLEN];
348 if(flags & PKCS7_BINARY) {
349 while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
350 BIO_write(out, linebuf, len);
351 return 1;
352 }
353 if(flags & PKCS7_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
354 while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
355 eol = strip_eol(linebuf, &len);
356 if (len)
357 BIO_write(out, linebuf, len);
358 if(eol) BIO_write(out, "\r\n", 2);
359 }
360 return 1;
361}
362
363/* Strip off headers if they are text/plain */
364int SMIME_text(BIO *in, BIO *out)
365{
366 char iobuf[4096];
367 int len;
368 STACK_OF(MIME_HEADER) *headers;
369 MIME_HEADER *hdr;
370
371 if (!(headers = mime_parse_hdr(in))) {
372 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_PARSE_ERROR);
373 return 0;
374 }
375 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
376 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_NO_CONTENT_TYPE);
377 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
378 return 0;
379 }
380 if (strcmp (hdr->value, "text/plain")) {
381 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_INVALID_MIME_TYPE);
382 ERR_add_error_data(2, "type: ", hdr->value);
383 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
384 return 0;
385 }
386 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
387 while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
388 BIO_write(out, iobuf, len);
389 return 1;
390}
391
392/* Split a multipart/XXX message body into component parts: result is
393 * canonical parts in a STACK of bios
394 */
395
396static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
397{
398 char linebuf[MAX_SMLEN];
399 int len, blen;
400 int eol = 0, next_eol = 0;
401 BIO *bpart = NULL;
402 STACK_OF(BIO) *parts;
403 char state, part, first;
404
405 blen = strlen(bound);
406 part = 0;
407 state = 0;
408 first = 1;
409 parts = sk_BIO_new_null();
410 *ret = parts;
411 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
412 state = mime_bound_check(linebuf, len, bound, blen);
413 if(state == 1) {
414 first = 1;
415 part++;
416 } else if(state == 2) {
417 sk_BIO_push(parts, bpart);
418 return 1;
419 } else if(part) {
420 /* Strip CR+LF from linebuf */
421 next_eol = strip_eol(linebuf, &len);
422 if(first) {
423 first = 0;
424 if(bpart) sk_BIO_push(parts, bpart);
425 bpart = BIO_new(BIO_s_mem());
426 BIO_set_mem_eof_return(bpart, 0);
427 } else if (eol)
428 BIO_write(bpart, "\r\n", 2);
429 eol = next_eol;
430 if (len)
431 BIO_write(bpart, linebuf, len);
432 }
433 }
434 return 0;
435}
436
437/* This is the big one: parse MIME header lines up to message body */
438
439#define MIME_INVALID 0
440#define MIME_START 1
441#define MIME_TYPE 2
442#define MIME_NAME 3
443#define MIME_VALUE 4
444#define MIME_QUOTE 5
445#define MIME_COMMENT 6
446
447
448static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
449{
450 char *p, *q, c;
451 char *ntmp;
452 char linebuf[MAX_SMLEN];
453 MIME_HEADER *mhdr = NULL;
454 STACK_OF(MIME_HEADER) *headers;
455 int len, state, save_state = 0;
456
457 headers = sk_MIME_HEADER_new(mime_hdr_cmp);
458 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
459 /* If whitespace at line start then continuation line */
460 if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
461 else state = MIME_START;
462 ntmp = NULL;
463 /* Go through all characters */
464 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
465
466 /* State machine to handle MIME headers
467 * if this looks horrible that's because it *is*
468 */
469
470 switch(state) {
471 case MIME_START:
472 if(c == ':') {
473 state = MIME_TYPE;
474 *p = 0;
475 ntmp = strip_ends(q);
476 q = p + 1;
477 }
478 break;
479
480 case MIME_TYPE:
481 if(c == ';') {
482 mime_debug("Found End Value\n");
483 *p = 0;
484 mhdr = mime_hdr_new(ntmp, strip_ends(q));
485 sk_MIME_HEADER_push(headers, mhdr);
486 ntmp = NULL;
487 q = p + 1;
488 state = MIME_NAME;
489 } else if(c == '(') {
490 save_state = state;
491 state = MIME_COMMENT;
492 }
493 break;
494
495 case MIME_COMMENT:
496 if(c == ')') {
497 state = save_state;
498 }
499 break;
500
501 case MIME_NAME:
502 if(c == '=') {
503 state = MIME_VALUE;
504 *p = 0;
505 ntmp = strip_ends(q);
506 q = p + 1;
507 }
508 break ;
509
510 case MIME_VALUE:
511 if(c == ';') {
512 state = MIME_NAME;
513 *p = 0;
514 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
515 ntmp = NULL;
516 q = p + 1;
517 } else if (c == '"') {
518 mime_debug("Found Quote\n");
519 state = MIME_QUOTE;
520 } else if(c == '(') {
521 save_state = state;
522 state = MIME_COMMENT;
523 }
524 break;
525
526 case MIME_QUOTE:
527 if(c == '"') {
528 mime_debug("Found Match Quote\n");
529 state = MIME_VALUE;
530 }
531 break;
532 }
533 }
534
535 if(state == MIME_TYPE) {
536 mhdr = mime_hdr_new(ntmp, strip_ends(q));
537 sk_MIME_HEADER_push(headers, mhdr);
538 } else if(state == MIME_VALUE)
539 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
540 if(p == linebuf) break; /* Blank line means end of headers */
541}
542
543return headers;
544
545}
546
547static char *strip_ends(char *name)
548{
549 return strip_end(strip_start(name));
550}
551
552/* Strip a parameter of whitespace from start of param */
553static char *strip_start(char *name)
554{
555 char *p, c;
556 /* Look for first non white space or quote */
557 for(p = name; (c = *p) ;p++) {
558 if(c == '"') {
559 /* Next char is start of string if non null */
560 if(p[1]) return p + 1;
561 /* Else null string */
562 return NULL;
563 }
564 if(!isspace((unsigned char)c)) return p;
565 }
566 return NULL;
567}
568
569/* As above but strip from end of string : maybe should handle brackets? */
570static char *strip_end(char *name)
571{
572 char *p, c;
573 if(!name) return NULL;
574 /* Look for first non white space or quote */
575 for(p = name + strlen(name) - 1; p >= name ;p--) {
576 c = *p;
577 if(c == '"') {
578 if(p - 1 == name) return NULL;
579 *p = 0;
580 return name;
581 }
582 if(isspace((unsigned char)c)) *p = 0;
583 else return name;
584 }
585 return NULL;
586}
587
588static MIME_HEADER *mime_hdr_new(char *name, char *value)
589{
590 MIME_HEADER *mhdr;
591 char *tmpname, *tmpval, *p;
592 int c;
593 if(name) {
594 if(!(tmpname = BUF_strdup(name))) return NULL;
595 for(p = tmpname ; *p; p++) {
596 c = *p;
597 if(isupper(c)) {
598 c = tolower(c);
599 *p = c;
600 }
601 }
602 } else tmpname = NULL;
603 if(value) {
604 if(!(tmpval = BUF_strdup(value))) return NULL;
605 for(p = tmpval ; *p; p++) {
606 c = *p;
607 if(isupper(c)) {
608 c = tolower(c);
609 *p = c;
610 }
611 }
612 } else tmpval = NULL;
613 mhdr = (MIME_HEADER *) OPENSSL_malloc(sizeof(MIME_HEADER));
614 if(!mhdr) return NULL;
615 mhdr->name = tmpname;
616 mhdr->value = tmpval;
617 if(!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) return NULL;
618 return mhdr;
619}
620
621static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
622{
623 char *tmpname, *tmpval, *p;
624 int c;
625 MIME_PARAM *mparam;
626 if(name) {
627 tmpname = BUF_strdup(name);
628 if(!tmpname) return 0;
629 for(p = tmpname ; *p; p++) {
630 c = *p;
631 if(isupper(c)) {
632 c = tolower(c);
633 *p = c;
634 }
635 }
636 } else tmpname = NULL;
637 if(value) {
638 tmpval = BUF_strdup(value);
639 if(!tmpval) return 0;
640 } else tmpval = NULL;
641 /* Parameter values are case sensitive so leave as is */
642 mparam = (MIME_PARAM *) OPENSSL_malloc(sizeof(MIME_PARAM));
643 if(!mparam) return 0;
644 mparam->param_name = tmpname;
645 mparam->param_value = tmpval;
646 sk_MIME_PARAM_push(mhdr->params, mparam);
647 return 1;
648}
649
650static int mime_hdr_cmp(const MIME_HEADER * const *a,
651 const MIME_HEADER * const *b)
652{
653 return(strcmp((*a)->name, (*b)->name));
654}
655
656static int mime_param_cmp(const MIME_PARAM * const *a,
657 const MIME_PARAM * const *b)
658{
659 return(strcmp((*a)->param_name, (*b)->param_name));
660}
661
662/* Find a header with a given name (if possible) */
663
664static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)
665{
666 MIME_HEADER htmp;
667 int idx;
668 htmp.name = name;
669 idx = sk_MIME_HEADER_find(hdrs, &htmp);
670 if(idx < 0) return NULL;
671 return sk_MIME_HEADER_value(hdrs, idx);
672}
673
674static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
675{
676 MIME_PARAM param;
677 int idx;
678 param.param_name = name;
679 idx = sk_MIME_PARAM_find(hdr->params, &param);
680 if(idx < 0) return NULL;
681 return sk_MIME_PARAM_value(hdr->params, idx);
682}
683
684static void mime_hdr_free(MIME_HEADER *hdr)
685{
686 if(hdr->name) OPENSSL_free(hdr->name);
687 if(hdr->value) OPENSSL_free(hdr->value);
688 if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
689 OPENSSL_free(hdr);
690}
691
692static void mime_param_free(MIME_PARAM *param)
693{
694 if(param->param_name) OPENSSL_free(param->param_name);
695 if(param->param_value) OPENSSL_free(param->param_value);
696 OPENSSL_free(param);
697}
698
699/* Check for a multipart boundary. Returns:
700 * 0 : no boundary
701 * 1 : part boundary
702 * 2 : final boundary
703 */
704static int mime_bound_check(char *line, int linelen, char *bound, int blen)
705{
706 if(linelen == -1) linelen = strlen(line);
707 if(blen == -1) blen = strlen(bound);
708 /* Quickly eliminate if line length too short */
709 if(blen + 2 > linelen) return 0;
710 /* Check for part boundary */
711 if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
712 if(!strncmp(line + blen + 2, "--", 2)) return 2;
713 else return 1;
714 }
715 return 0;
716}
717
718static int strip_eol(char *linebuf, int *plen)
719 {
720 int len = *plen;
721 char *p, c;
722 int is_eol = 0;
723 p = linebuf + len - 1;
724 for (p = linebuf + len - 1; len > 0; len--, p--)
725 {
726 c = *p;
727 if (c == '\n')
728 is_eol = 1;
729 else if (c != '\r')
730 break;
731 }
732 *plen = len;
733 return is_eol;
734 }
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
deleted file mode 100644
index 99a0d63f38..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_smime.c
+++ /dev/null
@@ -1,469 +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-2003 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_OF(X509_ALGOR) *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(!(flags & PKCS7_NOSMIMECAP))
113 {
114 if(!(smcap = sk_X509_ALGOR_new_null())) {
115 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
116 return NULL;
117 }
118#ifndef OPENSSL_NO_DES
119 PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1);
120#endif
121#ifndef OPENSSL_NO_RC2
122 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128);
123 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64);
124#endif
125#ifndef OPENSSL_NO_DES
126 PKCS7_simple_smimecap (smcap, NID_des_cbc, -1);
127#endif
128#ifndef OPENSSL_NO_RC2
129 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40);
130#endif
131 PKCS7_add_attrib_smimecap (si, smcap);
132 sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
133 }
134 }
135
136 if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1);
137
138 if (!PKCS7_dataFinal(p7,p7bio)) {
139 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN);
140 return NULL;
141 }
142
143 BIO_free_all(p7bio);
144 return p7;
145}
146
147int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
148 BIO *indata, BIO *out, int flags)
149{
150 STACK_OF(X509) *signers;
151 X509 *signer;
152 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
153 PKCS7_SIGNER_INFO *si;
154 X509_STORE_CTX cert_ctx;
155 char buf[4096];
156 int i, j=0, k, ret = 0;
157 BIO *p7bio;
158 BIO *tmpin, *tmpout;
159
160 if(!p7) {
161 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER);
162 return 0;
163 }
164
165 if(!PKCS7_type_is_signed(p7)) {
166 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_WRONG_CONTENT_TYPE);
167 return 0;
168 }
169
170 /* Check for no data and no content: no data to verify signature */
171 if(PKCS7_get_detached(p7) && !indata) {
172 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_CONTENT);
173 return 0;
174 }
175#if 0
176 /* NB: this test commented out because some versions of Netscape
177 * illegally include zero length content when signing data.
178 */
179
180 /* Check for data and content: two sets of data */
181 if(!PKCS7_get_detached(p7) && indata) {
182 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CONTENT_AND_DATA_PRESENT);
183 return 0;
184 }
185#endif
186
187 sinfos = PKCS7_get_signer_info(p7);
188
189 if(!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) {
190 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_SIGNATURES_ON_DATA);
191 return 0;
192 }
193
194
195 signers = PKCS7_get0_signers(p7, certs, flags);
196
197 if(!signers) return 0;
198
199 /* Now verify the certificates */
200
201 if (!(flags & PKCS7_NOVERIFY)) for (k = 0; k < sk_X509_num(signers); k++) {
202 signer = sk_X509_value (signers, k);
203 if (!(flags & PKCS7_NOCHAIN)) {
204 if(!X509_STORE_CTX_init(&cert_ctx, store, signer,
205 p7->d.sign->cert))
206 {
207 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_X509_LIB);
208 sk_X509_free(signers);
209 return 0;
210 }
211 X509_STORE_CTX_set_purpose(&cert_ctx,
212 X509_PURPOSE_SMIME_SIGN);
213 } else if(!X509_STORE_CTX_init (&cert_ctx, store, signer, NULL)) {
214 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_X509_LIB);
215 sk_X509_free(signers);
216 return 0;
217 }
218 i = X509_verify_cert(&cert_ctx);
219 if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx);
220 X509_STORE_CTX_cleanup(&cert_ctx);
221 if (i <= 0) {
222 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CERTIFICATE_VERIFY_ERROR);
223 ERR_add_error_data(2, "Verify error:",
224 X509_verify_cert_error_string(j));
225 sk_X509_free(signers);
226 return 0;
227 }
228 /* Check for revocation status here */
229 }
230
231 /* Performance optimization: if the content is a memory BIO then
232 * store its contents in a temporary read only memory BIO. This
233 * avoids potentially large numbers of slow copies of data which will
234 * occur when reading from a read write memory BIO when signatures
235 * are calculated.
236 */
237
238 if (indata && (BIO_method_type(indata) == BIO_TYPE_MEM))
239 {
240 char *ptr;
241 long len;
242 len = BIO_get_mem_data(indata, &ptr);
243 tmpin = BIO_new_mem_buf(ptr, len);
244 if (tmpin == NULL)
245 {
246 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
247 return 0;
248 }
249 }
250 else
251 tmpin = indata;
252
253
254 p7bio=PKCS7_dataInit(p7,tmpin);
255
256 if(flags & PKCS7_TEXT) {
257 if(!(tmpout = BIO_new(BIO_s_mem()))) {
258 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
259 goto err;
260 }
261 } else tmpout = out;
262
263 /* We now have to 'read' from p7bio to calculate digests etc. */
264 for (;;)
265 {
266 i=BIO_read(p7bio,buf,sizeof(buf));
267 if (i <= 0) break;
268 if (tmpout) BIO_write(tmpout, buf, i);
269 }
270
271 if(flags & PKCS7_TEXT) {
272 if(!SMIME_text(tmpout, out)) {
273 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SMIME_TEXT_ERROR);
274 BIO_free(tmpout);
275 goto err;
276 }
277 BIO_free(tmpout);
278 }
279
280 /* Now Verify All Signatures */
281 if (!(flags & PKCS7_NOSIGS))
282 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
283 {
284 si=sk_PKCS7_SIGNER_INFO_value(sinfos,i);
285 signer = sk_X509_value (signers, i);
286 j=PKCS7_signatureVerify(p7bio,p7,si, signer);
287 if (j <= 0) {
288 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SIGNATURE_FAILURE);
289 goto err;
290 }
291 }
292
293 ret = 1;
294
295 err:
296
297 if (tmpin == indata)
298 {
299 if (indata) BIO_pop(p7bio);
300 }
301 BIO_free_all(p7bio);
302
303 sk_X509_free(signers);
304
305 return ret;
306}
307
308STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
309{
310 STACK_OF(X509) *signers;
311 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
312 PKCS7_SIGNER_INFO *si;
313 PKCS7_ISSUER_AND_SERIAL *ias;
314 X509 *signer;
315 int i;
316
317 if(!p7) {
318 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_INVALID_NULL_POINTER);
319 return NULL;
320 }
321
322 if(!PKCS7_type_is_signed(p7)) {
323 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE);
324 return NULL;
325 }
326
327 /* Collect all the signers together */
328
329 sinfos = PKCS7_get_signer_info(p7);
330
331 if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
332 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
333 return 0;
334 }
335
336 if(!(signers = sk_X509_new_null())) {
337 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE);
338 return NULL;
339 }
340
341 for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
342 {
343 si = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
344 ias = si->issuer_and_serial;
345 signer = NULL;
346 /* If any certificates passed they take priority */
347 if (certs) signer = X509_find_by_issuer_and_serial (certs,
348 ias->issuer, ias->serial);
349 if (!signer && !(flags & PKCS7_NOINTERN)
350 && p7->d.sign->cert) signer =
351 X509_find_by_issuer_and_serial (p7->d.sign->cert,
352 ias->issuer, ias->serial);
353 if (!signer) {
354 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
355 sk_X509_free(signers);
356 return 0;
357 }
358
359 sk_X509_push(signers, signer);
360 }
361 return signers;
362}
363
364
365/* Build a complete PKCS#7 enveloped data */
366
367PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
368 int flags)
369{
370 PKCS7 *p7;
371 BIO *p7bio = NULL;
372 int i;
373 X509 *x509;
374 if(!(p7 = PKCS7_new())) {
375 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
376 return NULL;
377 }
378
379 PKCS7_set_type(p7, NID_pkcs7_enveloped);
380 if(!PKCS7_set_cipher(p7, cipher)) {
381 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER);
382 goto err;
383 }
384
385 for(i = 0; i < sk_X509_num(certs); i++) {
386 x509 = sk_X509_value(certs, i);
387 if(!PKCS7_add_recipient(p7, x509)) {
388 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,
389 PKCS7_R_ERROR_ADDING_RECIPIENT);
390 goto err;
391 }
392 }
393
394 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
395 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
396 goto err;
397 }
398
399 SMIME_crlf_copy(in, p7bio, flags);
400
401 BIO_flush(p7bio);
402
403 if (!PKCS7_dataFinal(p7,p7bio)) {
404 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR);
405 goto err;
406 }
407 BIO_free_all(p7bio);
408
409 return p7;
410
411 err:
412
413 BIO_free(p7bio);
414 PKCS7_free(p7);
415 return NULL;
416
417}
418
419int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
420{
421 BIO *tmpmem;
422 int ret, i;
423 char buf[4096];
424
425 if(!p7) {
426 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_INVALID_NULL_POINTER);
427 return 0;
428 }
429
430 if(!PKCS7_type_is_enveloped(p7)) {
431 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_WRONG_CONTENT_TYPE);
432 return 0;
433 }
434
435 if(!X509_check_private_key(cert, pkey)) {
436 PKCS7err(PKCS7_F_PKCS7_DECRYPT,
437 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
438 return 0;
439 }
440
441 if(!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) {
442 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR);
443 return 0;
444 }
445
446 if (flags & PKCS7_TEXT) {
447 BIO *tmpbuf, *bread;
448 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
449 if(!(tmpbuf = BIO_new(BIO_f_buffer()))) {
450 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
451 return 0;
452 }
453 if(!(bread = BIO_push(tmpbuf, tmpmem))) {
454 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
455 return 0;
456 }
457 ret = SMIME_text(bread, data);
458 BIO_free_all(bread);
459 return ret;
460 } else {
461 for(;;) {
462 i = BIO_read(tmpmem, buf, sizeof(buf));
463 if(i <= 0) break;
464 BIO_write(data, buf, i);
465 }
466 BIO_free_all(tmpmem);
467 return 1;
468 }
469}
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h
deleted file mode 100644
index 15372e18f8..0000000000
--- a/src/lib/libcrypto/pkcs7/pkcs7.h
+++ /dev/null
@@ -1,451 +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#include <openssl/asn1.h>
63#include <openssl/bio.h>
64#include <openssl/e_os2.h>
65
66#include <openssl/symhacks.h>
67#include <openssl/ossl_typ.h>
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73#ifdef OPENSSL_SYS_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
214 /* Anything else */
215 ASN1_TYPE *other;
216 } d;
217 } PKCS7;
218
219DECLARE_STACK_OF(PKCS7)
220DECLARE_ASN1_SET_OF(PKCS7)
221DECLARE_PKCS12_STACK_OF(PKCS7)
222
223#define PKCS7_OP_SET_DETACHED_SIGNATURE 1
224#define PKCS7_OP_GET_DETACHED_SIGNATURE 2
225
226#define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
227#define PKCS7_get_attributes(si) ((si)->unauth_attr)
228
229#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
230#define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)
231#define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped)
232#define PKCS7_type_is_signedAndEnveloped(a) \
233 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
234#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
235
236#define PKCS7_set_detached(p,v) \
237 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
238#define PKCS7_get_detached(p) \
239 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
240
241#define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7))
242
243#ifdef SSLEAY_MACROS
244#ifndef PKCS7_ISSUER_AND_SERIAL_digest
245#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
246 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
247 (char *)data,md,len)
248#endif
249#endif
250
251/* S/MIME related flags */
252
253#define PKCS7_TEXT 0x1
254#define PKCS7_NOCERTS 0x2
255#define PKCS7_NOSIGS 0x4
256#define PKCS7_NOCHAIN 0x8
257#define PKCS7_NOINTERN 0x10
258#define PKCS7_NOVERIFY 0x20
259#define PKCS7_DETACHED 0x40
260#define PKCS7_BINARY 0x80
261#define PKCS7_NOATTR 0x100
262#define PKCS7_NOSMIMECAP 0x200
263#define PKCS7_NOOLDMIMETYPE 0x400
264#define PKCS7_CRLFEOL 0x800
265
266/* Flags: for compatibility with older code */
267
268#define SMIME_TEXT PKCS7_TEXT
269#define SMIME_NOCERTS PKCS7_NOCERTS
270#define SMIME_NOSIGS PKCS7_NOSIGS
271#define SMIME_NOCHAIN PKCS7_NOCHAIN
272#define SMIME_NOINTERN PKCS7_NOINTERN
273#define SMIME_NOVERIFY PKCS7_NOVERIFY
274#define SMIME_DETACHED PKCS7_DETACHED
275#define SMIME_BINARY PKCS7_BINARY
276#define SMIME_NOATTR PKCS7_NOATTR
277
278DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
279
280#ifndef SSLEAY_MACROS
281int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type,
282 unsigned char *md,unsigned int *len);
283#ifndef OPENSSL_NO_FP_API
284PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
285int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
286#endif
287PKCS7 *PKCS7_dup(PKCS7 *p7);
288PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
289int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
290#endif
291
292DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
293DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
294DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED)
295DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
296DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
297DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
298DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST)
299DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
300DECLARE_ASN1_FUNCTIONS(PKCS7)
301
302DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
303DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
304
305
306long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
307
308int PKCS7_set_type(PKCS7 *p7, int type);
309int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
310int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
311 const EVP_MD *dgst);
312int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
313int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
314int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
315int PKCS7_content_new(PKCS7 *p7, int nid);
316int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
317 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
318int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
319 X509 *x509);
320
321BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
322int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
323BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
324
325
326PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
327 EVP_PKEY *pkey, const EVP_MD *dgst);
328X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
329STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
330
331PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
332int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
333int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
334int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
335
336PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
337ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
338int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,
339 void *data);
340int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
341 void *value);
342ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
343ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
344int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
345 STACK_OF(X509_ATTRIBUTE) *sk);
346int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
347
348
349PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
350 BIO *data, int flags);
351int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
352 BIO *indata, BIO *out, int flags);
353STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
354PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
355 int flags);
356int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
357
358int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
359 STACK_OF(X509_ALGOR) *cap);
360STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
361int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg);
362
363int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
364PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
365int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
366int SMIME_text(BIO *in, BIO *out);
367
368/* BEGIN ERROR CODES */
369/* The following lines are auto generated by the script mkerr.pl. Any changes
370 * made after this point may be overwritten when the script is next run.
371 */
372void ERR_load_PKCS7_strings(void);
373
374/* Error codes for the PKCS7 functions. */
375
376/* Function codes. */
377#define PKCS7_F_B64_READ_PKCS7 120
378#define PKCS7_F_B64_WRITE_PKCS7 121
379#define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118
380#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
381#define PKCS7_F_PKCS7_ADD_CRL 101
382#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
383#define PKCS7_F_PKCS7_ADD_SIGNER 103
384#define PKCS7_F_PKCS7_CTRL 104
385#define PKCS7_F_PKCS7_DATADECODE 112
386#define PKCS7_F_PKCS7_DATAINIT 105
387#define PKCS7_F_PKCS7_DATASIGN 106
388#define PKCS7_F_PKCS7_DATAVERIFY 107
389#define PKCS7_F_PKCS7_DECRYPT 114
390#define PKCS7_F_PKCS7_ENCRYPT 115
391#define PKCS7_F_PKCS7_GET0_SIGNERS 124
392#define PKCS7_F_PKCS7_SET_CIPHER 108
393#define PKCS7_F_PKCS7_SET_CONTENT 109
394#define PKCS7_F_PKCS7_SET_TYPE 110
395#define PKCS7_F_PKCS7_SIGN 116
396#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
397#define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119
398#define PKCS7_F_PKCS7_VERIFY 117
399#define PKCS7_F_SMIME_READ_PKCS7 122
400#define PKCS7_F_SMIME_TEXT 123
401
402/* Reason codes. */
403#define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117
404#define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144
405#define PKCS7_R_CIPHER_NOT_INITIALIZED 116
406#define PKCS7_R_CONTENT_AND_DATA_PRESENT 118
407#define PKCS7_R_DECODE_ERROR 130
408#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100
409#define PKCS7_R_DECRYPT_ERROR 119
410#define PKCS7_R_DIGEST_FAILURE 101
411#define PKCS7_R_ERROR_ADDING_RECIPIENT 120
412#define PKCS7_R_ERROR_SETTING_CIPHER 121
413#define PKCS7_R_INVALID_MIME_TYPE 131
414#define PKCS7_R_INVALID_NULL_POINTER 143
415#define PKCS7_R_MIME_NO_CONTENT_TYPE 132
416#define PKCS7_R_MIME_PARSE_ERROR 133
417#define PKCS7_R_MIME_SIG_PARSE_ERROR 134
418#define PKCS7_R_MISSING_CERIPEND_INFO 103
419#define PKCS7_R_NO_CONTENT 122
420#define PKCS7_R_NO_CONTENT_TYPE 135
421#define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136
422#define PKCS7_R_NO_MULTIPART_BOUNDARY 137
423#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
424#define PKCS7_R_NO_SIGNATURES_ON_DATA 123
425#define PKCS7_R_NO_SIGNERS 142
426#define PKCS7_R_NO_SIG_CONTENT_TYPE 138
427#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
428#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124
429#define PKCS7_R_PKCS7_DATAFINAL_ERROR 125
430#define PKCS7_R_PKCS7_DATASIGN 126
431#define PKCS7_R_PKCS7_PARSE_ERROR 139
432#define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140
433#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127
434#define PKCS7_R_SIGNATURE_FAILURE 105
435#define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128
436#define PKCS7_R_SIG_INVALID_MIME_TYPE 141
437#define PKCS7_R_SMIME_TEXT_ERROR 129
438#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106
439#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107
440#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108
441#define PKCS7_R_UNKNOWN_DIGEST_TYPE 109
442#define PKCS7_R_UNKNOWN_OPERATION 110
443#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111
444#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112
445#define PKCS7_R_WRONG_CONTENT_TYPE 113
446#define PKCS7_R_WRONG_PKCS7_TYPE 114
447
448#ifdef __cplusplus
449}
450#endif
451#endif
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c
deleted file mode 100644
index 19894c80a4..0000000000
--- a/src/lib/libcrypto/pkcs7/pkcs7err.c
+++ /dev/null
@@ -1,164 +0,0 @@
1/* crypto/pkcs7/pkcs7err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_PKCS7,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_PKCS7,0,reason)
70
71static ERR_STRING_DATA PKCS7_str_functs[]=
72 {
73{ERR_FUNC(PKCS7_F_B64_READ_PKCS7), "B64_READ_PKCS7"},
74{ERR_FUNC(PKCS7_F_B64_WRITE_PKCS7), "B64_WRITE_PKCS7"},
75{ERR_FUNC(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP), "PKCS7_add_attrib_smimecap"},
76{ERR_FUNC(PKCS7_F_PKCS7_ADD_CERTIFICATE), "PKCS7_add_certificate"},
77{ERR_FUNC(PKCS7_F_PKCS7_ADD_CRL), "PKCS7_add_crl"},
78{ERR_FUNC(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO), "PKCS7_add_recipient_info"},
79{ERR_FUNC(PKCS7_F_PKCS7_ADD_SIGNER), "PKCS7_add_signer"},
80{ERR_FUNC(PKCS7_F_PKCS7_CTRL), "PKCS7_ctrl"},
81{ERR_FUNC(PKCS7_F_PKCS7_DATADECODE), "PKCS7_dataDecode"},
82{ERR_FUNC(PKCS7_F_PKCS7_DATAINIT), "PKCS7_dataInit"},
83{ERR_FUNC(PKCS7_F_PKCS7_DATASIGN), "PKCS7_DATASIGN"},
84{ERR_FUNC(PKCS7_F_PKCS7_DATAVERIFY), "PKCS7_dataVerify"},
85{ERR_FUNC(PKCS7_F_PKCS7_DECRYPT), "PKCS7_decrypt"},
86{ERR_FUNC(PKCS7_F_PKCS7_ENCRYPT), "PKCS7_encrypt"},
87{ERR_FUNC(PKCS7_F_PKCS7_GET0_SIGNERS), "PKCS7_get0_signers"},
88{ERR_FUNC(PKCS7_F_PKCS7_SET_CIPHER), "PKCS7_set_cipher"},
89{ERR_FUNC(PKCS7_F_PKCS7_SET_CONTENT), "PKCS7_set_content"},
90{ERR_FUNC(PKCS7_F_PKCS7_SET_TYPE), "PKCS7_set_type"},
91{ERR_FUNC(PKCS7_F_PKCS7_SIGN), "PKCS7_sign"},
92{ERR_FUNC(PKCS7_F_PKCS7_SIGNATUREVERIFY), "PKCS7_signatureVerify"},
93{ERR_FUNC(PKCS7_F_PKCS7_SIMPLE_SMIMECAP), "PKCS7_simple_smimecap"},
94{ERR_FUNC(PKCS7_F_PKCS7_VERIFY), "PKCS7_verify"},
95{ERR_FUNC(PKCS7_F_SMIME_READ_PKCS7), "SMIME_read_PKCS7"},
96{ERR_FUNC(PKCS7_F_SMIME_TEXT), "SMIME_text"},
97{0,NULL}
98 };
99
100static ERR_STRING_DATA PKCS7_str_reasons[]=
101 {
102{ERR_REASON(PKCS7_R_CERTIFICATE_VERIFY_ERROR),"certificate verify error"},
103{ERR_REASON(PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER),"cipher has no object identifier"},
104{ERR_REASON(PKCS7_R_CIPHER_NOT_INITIALIZED),"cipher not initialized"},
105{ERR_REASON(PKCS7_R_CONTENT_AND_DATA_PRESENT),"content and data present"},
106{ERR_REASON(PKCS7_R_DECODE_ERROR) ,"decode error"},
107{ERR_REASON(PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH),"decrypted key is wrong length"},
108{ERR_REASON(PKCS7_R_DECRYPT_ERROR) ,"decrypt error"},
109{ERR_REASON(PKCS7_R_DIGEST_FAILURE) ,"digest failure"},
110{ERR_REASON(PKCS7_R_ERROR_ADDING_RECIPIENT),"error adding recipient"},
111{ERR_REASON(PKCS7_R_ERROR_SETTING_CIPHER),"error setting cipher"},
112{ERR_REASON(PKCS7_R_INVALID_MIME_TYPE) ,"invalid mime type"},
113{ERR_REASON(PKCS7_R_INVALID_NULL_POINTER),"invalid null pointer"},
114{ERR_REASON(PKCS7_R_MIME_NO_CONTENT_TYPE),"mime no content type"},
115{ERR_REASON(PKCS7_R_MIME_PARSE_ERROR) ,"mime parse error"},
116{ERR_REASON(PKCS7_R_MIME_SIG_PARSE_ERROR),"mime sig parse error"},
117{ERR_REASON(PKCS7_R_MISSING_CERIPEND_INFO),"missing ceripend info"},
118{ERR_REASON(PKCS7_R_NO_CONTENT) ,"no content"},
119{ERR_REASON(PKCS7_R_NO_CONTENT_TYPE) ,"no content type"},
120{ERR_REASON(PKCS7_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"},
121{ERR_REASON(PKCS7_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"},
122{ERR_REASON(PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE),"no recipient matches certificate"},
123{ERR_REASON(PKCS7_R_NO_SIGNATURES_ON_DATA),"no signatures on data"},
124{ERR_REASON(PKCS7_R_NO_SIGNERS) ,"no signers"},
125{ERR_REASON(PKCS7_R_NO_SIG_CONTENT_TYPE) ,"no sig content type"},
126{ERR_REASON(PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE),"operation not supported on this type"},
127{ERR_REASON(PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR),"pkcs7 add signature error"},
128{ERR_REASON(PKCS7_R_PKCS7_DATAFINAL_ERROR),"pkcs7 datafinal error"},
129{ERR_REASON(PKCS7_R_PKCS7_DATASIGN) ,"pkcs7 datasign"},
130{ERR_REASON(PKCS7_R_PKCS7_PARSE_ERROR) ,"pkcs7 parse error"},
131{ERR_REASON(PKCS7_R_PKCS7_SIG_PARSE_ERROR),"pkcs7 sig parse error"},
132{ERR_REASON(PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE),"private key does not match certificate"},
133{ERR_REASON(PKCS7_R_SIGNATURE_FAILURE) ,"signature failure"},
134{ERR_REASON(PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND),"signer certificate not found"},
135{ERR_REASON(PKCS7_R_SIG_INVALID_MIME_TYPE),"sig invalid mime type"},
136{ERR_REASON(PKCS7_R_SMIME_TEXT_ERROR) ,"smime text error"},
137{ERR_REASON(PKCS7_R_UNABLE_TO_FIND_CERTIFICATE),"unable to find certificate"},
138{ERR_REASON(PKCS7_R_UNABLE_TO_FIND_MEM_BIO),"unable to find mem bio"},
139{ERR_REASON(PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST),"unable to find message digest"},
140{ERR_REASON(PKCS7_R_UNKNOWN_DIGEST_TYPE) ,"unknown digest type"},
141{ERR_REASON(PKCS7_R_UNKNOWN_OPERATION) ,"unknown operation"},
142{ERR_REASON(PKCS7_R_UNSUPPORTED_CIPHER_TYPE),"unsupported cipher type"},
143{ERR_REASON(PKCS7_R_UNSUPPORTED_CONTENT_TYPE),"unsupported content type"},
144{ERR_REASON(PKCS7_R_WRONG_CONTENT_TYPE) ,"wrong content type"},
145{ERR_REASON(PKCS7_R_WRONG_PKCS7_TYPE) ,"wrong pkcs7 type"},
146{0,NULL}
147 };
148
149#endif
150
151void ERR_load_PKCS7_strings(void)
152 {
153 static int init=1;
154
155 if (init)
156 {
157 init=0;
158#ifndef OPENSSL_NO_ERR
159 ERR_load_strings(0,PKCS7_str_functs);
160 ERR_load_strings(0,PKCS7_str_reasons);
161#endif
162
163 }
164 }
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h
deleted file mode 100644
index 604df9be6c..0000000000
--- a/src/lib/libcrypto/rand/rand.h
+++ /dev/null
@@ -1,143 +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#include <stdlib.h>
63#include <openssl/ossl_typ.h>
64#include <openssl/e_os2.h>
65
66#if defined(OPENSSL_SYS_WINDOWS)
67#include <windows.h>
68#endif
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74#if defined(OPENSSL_FIPS)
75#define FIPS_RAND_SIZE_T int
76#endif
77
78typedef struct rand_meth_st
79 {
80 void (*seed)(const void *buf, int num);
81 int (*bytes)(unsigned char *buf, int num);
82 void (*cleanup)(void);
83 void (*add)(const void *buf, int num, double entropy);
84 int (*pseudorand)(unsigned char *buf, int num);
85 int (*status)(void);
86 } RAND_METHOD;
87
88#ifdef BN_DEBUG
89extern int rand_predictable;
90#endif
91
92int RAND_set_rand_method(const RAND_METHOD *meth);
93const RAND_METHOD *RAND_get_rand_method(void);
94#ifndef OPENSSL_NO_ENGINE
95int RAND_set_rand_engine(ENGINE *engine);
96#endif
97RAND_METHOD *RAND_SSLeay(void);
98void RAND_cleanup(void );
99int RAND_bytes(unsigned char *buf,int num);
100int RAND_pseudo_bytes(unsigned char *buf,int num);
101void RAND_seed(const void *buf,int num);
102void RAND_add(const void *buf,int num,double entropy);
103int RAND_load_file(const char *file,long max_bytes);
104int RAND_write_file(const char *file);
105const char *RAND_file_name(char *file,size_t num);
106int RAND_status(void);
107int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
108int RAND_egd(const char *path);
109int RAND_egd_bytes(const char *path,int bytes);
110int RAND_poll(void);
111
112#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
113
114void RAND_screen(void);
115int RAND_event(UINT, WPARAM, LPARAM);
116
117#endif
118
119/* BEGIN ERROR CODES */
120/* The following lines are auto generated by the script mkerr.pl. Any changes
121 * made after this point may be overwritten when the script is next run.
122 */
123void ERR_load_RAND_strings(void);
124
125/* Error codes for the RAND functions. */
126
127/* Function codes. */
128#define RAND_F_FIPS_RAND_BYTES 102
129#define RAND_F_RAND_GET_RAND_METHOD 101
130#define RAND_F_SSLEAY_RAND_BYTES 100
131
132/* Reason codes. */
133#define RAND_R_NON_FIPS_METHOD 101
134#define RAND_R_PRNG_ASKING_FOR_TOO_MUCH 105
135#define RAND_R_PRNG_NOT_REKEYED 103
136#define RAND_R_PRNG_NOT_RESEEDED 104
137#define RAND_R_PRNG_NOT_SEEDED 100
138#define RAND_R_PRNG_STUCK 102
139
140#ifdef __cplusplus
141}
142#endif
143#endif
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c
deleted file mode 100644
index 97f96e1aee..0000000000
--- a/src/lib/libcrypto/rand/rand_err.c
+++ /dev/null
@@ -1,105 +0,0 @@
1/* crypto/rand/rand_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_RAND,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason)
70
71static ERR_STRING_DATA RAND_str_functs[]=
72 {
73{ERR_FUNC(RAND_F_FIPS_RAND_BYTES), "FIPS_RAND_BYTES"},
74{ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"},
75{ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"},
76{0,NULL}
77 };
78
79static ERR_STRING_DATA RAND_str_reasons[]=
80 {
81{ERR_REASON(RAND_R_NON_FIPS_METHOD) ,"non fips method"},
82{ERR_REASON(RAND_R_PRNG_ASKING_FOR_TOO_MUCH),"prng asking for too much"},
83{ERR_REASON(RAND_R_PRNG_NOT_REKEYED) ,"prng not rekeyed"},
84{ERR_REASON(RAND_R_PRNG_NOT_RESEEDED) ,"prng not reseeded"},
85{ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"},
86{ERR_REASON(RAND_R_PRNG_STUCK) ,"prng stuck"},
87{0,NULL}
88 };
89
90#endif
91
92void ERR_load_RAND_strings(void)
93 {
94 static int init=1;
95
96 if (init)
97 {
98 init=0;
99#ifndef OPENSSL_NO_ERR
100 ERR_load_strings(0,RAND_str_functs);
101 ERR_load_strings(0,RAND_str_reasons);
102#endif
103
104 }
105 }
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
deleted file mode 100644
index a21bde79de..0000000000
--- a/src/lib/libcrypto/rand/rand_lib.c
+++ /dev/null
@@ -1,192 +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 "cryptlib.h"
62#include <openssl/rand.h>
63#ifndef OPENSSL_NO_ENGINE
64#include <openssl/engine.h>
65#endif
66#include <openssl/fips.h>
67#include <openssl/fips_rand.h>
68
69#ifndef OPENSSL_NO_ENGINE
70/* non-NULL if default_RAND_meth is ENGINE-provided */
71static ENGINE *funct_ref =NULL;
72#endif
73static const RAND_METHOD *default_RAND_meth = NULL;
74
75int RAND_set_rand_method(const RAND_METHOD *meth)
76 {
77#ifndef OPENSSL_NO_ENGINE
78 if(funct_ref)
79 {
80 ENGINE_finish(funct_ref);
81 funct_ref = NULL;
82 }
83#endif
84 default_RAND_meth = meth;
85 return 1;
86 }
87
88const RAND_METHOD *RAND_get_rand_method(void)
89 {
90 if (!default_RAND_meth)
91 {
92#ifndef OPENSSL_NO_ENGINE
93 ENGINE *e = ENGINE_get_default_RAND();
94 if(e)
95 {
96 default_RAND_meth = ENGINE_get_RAND(e);
97 if(!default_RAND_meth)
98 {
99 ENGINE_finish(e);
100 e = NULL;
101 }
102 }
103 if(e)
104 funct_ref = e;
105 else
106#endif
107#ifdef OPENSSL_FIPS
108 if(FIPS_mode())
109 default_RAND_meth=FIPS_rand_method();
110 else
111#endif
112 default_RAND_meth = RAND_SSLeay();
113 }
114
115#ifdef OPENSSL_FIPS
116 if(FIPS_mode()
117 && default_RAND_meth != FIPS_rand_check())
118 {
119 RANDerr(RAND_F_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD);
120 return 0;
121 }
122#endif
123 return default_RAND_meth;
124 }
125
126#ifndef OPENSSL_NO_ENGINE
127int RAND_set_rand_engine(ENGINE *engine)
128 {
129 const RAND_METHOD *tmp_meth = NULL;
130 if(engine)
131 {
132 if(!ENGINE_init(engine))
133 return 0;
134 tmp_meth = ENGINE_get_RAND(engine);
135 if(!tmp_meth)
136 {
137 ENGINE_finish(engine);
138 return 0;
139 }
140 }
141 /* This function releases any prior ENGINE so call it first */
142 RAND_set_rand_method(tmp_meth);
143 funct_ref = engine;
144 return 1;
145 }
146#endif
147
148void RAND_cleanup(void)
149 {
150 const RAND_METHOD *meth = RAND_get_rand_method();
151 if (meth && meth->cleanup)
152 meth->cleanup();
153 RAND_set_rand_method(NULL);
154 }
155
156void RAND_seed(const void *buf, int num)
157 {
158 const RAND_METHOD *meth = RAND_get_rand_method();
159 if (meth && meth->seed)
160 meth->seed(buf,num);
161 }
162
163void RAND_add(const void *buf, int num, double entropy)
164 {
165 const RAND_METHOD *meth = RAND_get_rand_method();
166 if (meth && meth->add)
167 meth->add(buf,num,entropy);
168 }
169
170int RAND_bytes(unsigned char *buf, int num)
171 {
172 const RAND_METHOD *meth = RAND_get_rand_method();
173 if (meth && meth->bytes)
174 return meth->bytes(buf,num);
175 return(-1);
176 }
177
178int RAND_pseudo_bytes(unsigned char *buf, int num)
179 {
180 const RAND_METHOD *meth = RAND_get_rand_method();
181 if (meth && meth->pseudorand)
182 return meth->pseudorand(buf,num);
183 return(-1);
184 }
185
186int RAND_status(void)
187 {
188 const RAND_METHOD *meth = RAND_get_rand_method();
189 if (meth && meth->status)
190 return meth->status();
191 return 0;
192 }
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
deleted file mode 100644
index d847d8ebdf..0000000000
--- a/src/lib/libcrypto/rand/randfile.c
+++ /dev/null
@@ -1,285 +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/* We need to define this to get macros like S_IFBLK and S_IFCHR */
60#define _XOPEN_SOURCE 500
61
62#include <errno.h>
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66
67#include "e_os.h"
68#include <openssl/crypto.h>
69#include <openssl/rand.h>
70#include <openssl/buffer.h>
71
72#ifdef OPENSSL_SYS_VMS
73#include <unixio.h>
74#endif
75#ifndef NO_SYS_TYPES_H
76# include <sys/types.h>
77#endif
78#ifdef MAC_OS_pre_X
79# include <stat.h>
80#else
81# include <sys/stat.h>
82#endif
83
84#undef BUFSIZE
85#define BUFSIZE 1024
86#define RAND_DATA 1024
87
88/* #define RFILE ".rnd" - defined in ../../e_os.h */
89
90/* Note that these functions are intended for seed files only.
91 * Entropy devices and EGD sockets are handled in rand_unix.c */
92
93int RAND_load_file(const char *file, long bytes)
94 {
95 /* If bytes >= 0, read up to 'bytes' bytes.
96 * if bytes == -1, read complete file. */
97
98 MS_STATIC unsigned char buf[BUFSIZE];
99 struct stat sb;
100 int i,ret=0,n;
101 FILE *in;
102
103 if (file == NULL) return(0);
104
105 i=stat(file,&sb);
106 /* If the state fails, put some crap in anyway */
107 RAND_add(&sb,sizeof(sb),0);
108 if (i < 0) return(0);
109 if (bytes == 0) return(ret);
110
111 in=fopen(file,"rb");
112 if (in == NULL) goto err;
113#if defined(S_IFBLK) && defined(S_IFCHR)
114 if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
115 /* this file is a device. we don't want read an infinite number
116 * of bytes from a random device, nor do we want to use buffered
117 * I/O because we will waste system entropy.
118 */
119 bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */
120 setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */
121 }
122#endif
123 for (;;)
124 {
125 if (bytes > 0)
126 n = (bytes < BUFSIZE)?(int)bytes:BUFSIZE;
127 else
128 n = BUFSIZE;
129 i=fread(buf,1,n,in);
130 if (i <= 0) break;
131 /* even if n != i, use the full array */
132 RAND_add(buf,n,i);
133 ret+=i;
134 if (bytes > 0)
135 {
136 bytes-=n;
137 if (bytes <= 0) break;
138 }
139 }
140 fclose(in);
141 OPENSSL_cleanse(buf,BUFSIZE);
142err:
143 return(ret);
144 }
145
146int RAND_write_file(const char *file)
147 {
148 unsigned char buf[BUFSIZE];
149 int i,ret=0,rand_err=0;
150 FILE *out = NULL;
151 int n;
152 struct stat sb;
153
154 i=stat(file,&sb);
155 if (i != -1) {
156#if defined(S_IFBLK) && defined(S_IFCHR)
157 if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
158 /* this file is a device. we don't write back to it.
159 * we "succeed" on the assumption this is some sort
160 * of random device. Otherwise attempting to write to
161 * and chmod the device causes problems.
162 */
163 return(1);
164 }
165#endif
166 }
167
168#if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32)
169 {
170 /* For some reason Win32 can't write to files created this way */
171
172 /* chmod(..., 0600) is too late to protect the file,
173 * permissions should be restrictive from the start */
174 int fd = open(file, O_CREAT, 0600);
175 if (fd != -1)
176 out = fdopen(fd, "wb");
177 }
178#endif
179 if (out == NULL)
180 out = fopen(file,"wb");
181 if (out == NULL) goto err;
182
183#ifndef NO_CHMOD
184 chmod(file,0600);
185#endif
186 n=RAND_DATA;
187 for (;;)
188 {
189 i=(n > BUFSIZE)?BUFSIZE:n;
190 n-=BUFSIZE;
191 if (RAND_bytes(buf,i) <= 0)
192 rand_err=1;
193 i=fwrite(buf,1,i,out);
194 if (i <= 0)
195 {
196 ret=0;
197 break;
198 }
199 ret+=i;
200 if (n <= 0) break;
201 }
202#ifdef OPENSSL_SYS_VMS
203 /* Try to delete older versions of the file, until there aren't
204 any */
205 {
206 char *tmpf;
207
208 tmpf = OPENSSL_malloc(strlen(file) + 4); /* to add ";-1" and a nul */
209 if (tmpf)
210 {
211 strcpy(tmpf, file);
212 strcat(tmpf, ";-1");
213 while(delete(tmpf) == 0)
214 ;
215 rename(file,";1"); /* Make sure it's version 1, or we
216 will reach the limit (32767) at
217 some point... */
218 }
219 }
220#endif /* OPENSSL_SYS_VMS */
221
222 fclose(out);
223 OPENSSL_cleanse(buf,BUFSIZE);
224err:
225 return (rand_err ? -1 : ret);
226 }
227
228const char *RAND_file_name(char *buf, size_t size)
229 {
230 char *s=NULL;
231 int ok = 0;
232#ifdef __OpenBSD__
233 struct stat sb;
234#endif
235
236 if (issetugid() == 0)
237 s=getenv("RANDFILE");
238 if (s != NULL && *s && strlen(s) + 1 < size)
239 {
240 if (BUF_strlcpy(buf,s,size) >= size)
241 return NULL;
242 }
243 else
244 {
245 if (issetugid() == 0)
246 s=getenv("HOME");
247#ifdef DEFAULT_HOME
248 if (s == NULL)
249 {
250 s = DEFAULT_HOME;
251 }
252#endif
253 if (s && *s && strlen(s)+strlen(RFILE)+2 < size)
254 {
255 BUF_strlcpy(buf,s,size);
256#ifndef OPENSSL_SYS_VMS
257 BUF_strlcat(buf,"/",size);
258#endif
259 BUF_strlcat(buf,RFILE,size);
260 ok = 1;
261 }
262 else
263 buf[0] = '\0'; /* no file name */
264 }
265
266#ifdef __OpenBSD__
267 /* given that all random loads just fail if the file can't be
268 * seen on a stat, we stat the file we're returning, if it
269 * fails, use /dev/arandom instead. this allows the user to
270 * use their own source for good random data, but defaults
271 * to something hopefully decent if that isn't available.
272 */
273
274 if (!ok)
275 if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) {
276 return(NULL);
277 }
278 if (stat(buf,&sb) == -1)
279 if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) {
280 return(NULL);
281 }
282
283#endif
284 return(buf);
285 }
diff --git a/src/lib/libcrypto/rc2/rc2.h b/src/lib/libcrypto/rc2/rc2.h
deleted file mode 100644
index 71788158d8..0000000000
--- a/src/lib/libcrypto/rc2/rc2.h
+++ /dev/null
@@ -1,104 +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 OPENSSL_NO_RC2
63#error RC2 is disabled.
64#endif
65
66#define RC2_ENCRYPT 1
67#define RC2_DECRYPT 0
68
69#include <openssl/opensslconf.h> /* RC2_INT */
70#define RC2_BLOCK 8
71#define RC2_KEY_LENGTH 16
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77typedef struct rc2_key_st
78 {
79 RC2_INT data[64];
80 } RC2_KEY;
81
82#ifdef OPENSSL_FIPS
83void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,
84 int bits);
85#endif
86void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits);
87void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key,
88 int enc);
89void RC2_encrypt(unsigned long *data,RC2_KEY *key);
90void RC2_decrypt(unsigned long *data,RC2_KEY *key);
91void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
92 RC2_KEY *ks, unsigned char *iv, int enc);
93void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
94 long length, RC2_KEY *schedule, unsigned char *ivec,
95 int *num, int enc);
96void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
97 long length, RC2_KEY *schedule, unsigned char *ivec,
98 int *num);
99
100#ifdef __cplusplus
101}
102#endif
103
104#endif
diff --git a/src/lib/libcrypto/rc2/rc2_cbc.c b/src/lib/libcrypto/rc2/rc2_cbc.c
deleted file mode 100644
index 74f48d3d87..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(const 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 d3e8c2718a..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(const 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 9652865188..0000000000
--- a/src/lib/libcrypto/rc2/rc2_skey.c
+++ /dev/null
@@ -1,152 +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 <openssl/crypto.h>
61#include <openssl/fips.h>
62#include "rc2_locl.h"
63
64static unsigned char key_table[256]={
65 0xd9,0x78,0xf9,0xc4,0x19,0xdd,0xb5,0xed,0x28,0xe9,0xfd,0x79,
66 0x4a,0xa0,0xd8,0x9d,0xc6,0x7e,0x37,0x83,0x2b,0x76,0x53,0x8e,
67 0x62,0x4c,0x64,0x88,0x44,0x8b,0xfb,0xa2,0x17,0x9a,0x59,0xf5,
68 0x87,0xb3,0x4f,0x13,0x61,0x45,0x6d,0x8d,0x09,0x81,0x7d,0x32,
69 0xbd,0x8f,0x40,0xeb,0x86,0xb7,0x7b,0x0b,0xf0,0x95,0x21,0x22,
70 0x5c,0x6b,0x4e,0x82,0x54,0xd6,0x65,0x93,0xce,0x60,0xb2,0x1c,
71 0x73,0x56,0xc0,0x14,0xa7,0x8c,0xf1,0xdc,0x12,0x75,0xca,0x1f,
72 0x3b,0xbe,0xe4,0xd1,0x42,0x3d,0xd4,0x30,0xa3,0x3c,0xb6,0x26,
73 0x6f,0xbf,0x0e,0xda,0x46,0x69,0x07,0x57,0x27,0xf2,0x1d,0x9b,
74 0xbc,0x94,0x43,0x03,0xf8,0x11,0xc7,0xf6,0x90,0xef,0x3e,0xe7,
75 0x06,0xc3,0xd5,0x2f,0xc8,0x66,0x1e,0xd7,0x08,0xe8,0xea,0xde,
76 0x80,0x52,0xee,0xf7,0x84,0xaa,0x72,0xac,0x35,0x4d,0x6a,0x2a,
77 0x96,0x1a,0xd2,0x71,0x5a,0x15,0x49,0x74,0x4b,0x9f,0xd0,0x5e,
78 0x04,0x18,0xa4,0xec,0xc2,0xe0,0x41,0x6e,0x0f,0x51,0xcb,0xcc,
79 0x24,0x91,0xaf,0x50,0xa1,0xf4,0x70,0x39,0x99,0x7c,0x3a,0x85,
80 0x23,0xb8,0xb4,0x7a,0xfc,0x02,0x36,0x5b,0x25,0x55,0x97,0x31,
81 0x2d,0x5d,0xfa,0x98,0xe3,0x8a,0x92,0xae,0x05,0xdf,0x29,0x10,
82 0x67,0x6c,0xba,0xc9,0xd3,0x00,0xe6,0xcf,0xe1,0x9e,0xa8,0x2c,
83 0x63,0x16,0x01,0x3f,0x58,0xe2,0x89,0xa9,0x0d,0x38,0x34,0x1b,
84 0xab,0x33,0xff,0xb0,0xbb,0x48,0x0c,0x5f,0xb9,0xb1,0xcd,0x2e,
85 0xc5,0xf3,0xdb,0x47,0xe5,0xa5,0x9c,0x77,0x0a,0xa6,0x20,0x68,
86 0xfe,0x7f,0xc1,0xad,
87 };
88
89/* It has come to my attention that there are 2 versions of the RC2
90 * key schedule. One which is normal, and anther which has a hook to
91 * use a reduced key length.
92 * BSAFE uses the 'retarded' version. What I previously shipped is
93 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses
94 * a version where the bits parameter is the same as len*8 */
95
96#ifdef OPENSSL_FIPS
97void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
98 {
99 if (FIPS_mode())
100 FIPS_BAD_ABORT(RC2)
101 private_RC2_set_key(key, len, data, bits);
102 }
103void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,
104 int bits)
105#else
106void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
107#endif
108 {
109 int i,j;
110 unsigned char *k;
111 RC2_INT *ki;
112 unsigned int c,d;
113
114 k= (unsigned char *)&(key->data[0]);
115 *k=0; /* for if there is a zero length key */
116
117 if (len > 128) len=128;
118 if (bits <= 0) bits=1024;
119 if (bits > 1024) bits=1024;
120
121 for (i=0; i<len; i++)
122 k[i]=data[i];
123
124 /* expand table */
125 d=k[len-1];
126 j=0;
127 for (i=len; i < 128; i++,j++)
128 {
129 d=key_table[(k[j]+d)&0xff];
130 k[i]=d;
131 }
132
133 /* hmm.... key reduction to 'bits' bits */
134
135 j=(bits+7)>>3;
136 i=128-j;
137 c= (0xff>>(-bits & 0x07));
138
139 d=key_table[k[i]&c];
140 k[i]=d;
141 while (i--)
142 {
143 d=key_table[k[i+j]^d];
144 k[i]=d;
145 }
146
147 /* copy from bytes into RC2_INT's */
148 ki= &(key->data[63]);
149 for (i=127; i>=0; i-=2)
150 *(ki--)=((k[i]<<8)|k[i-1])&0xffff;
151 }
152
diff --git a/src/lib/libcrypto/rc2/rc2cfb64.c b/src/lib/libcrypto/rc2/rc2cfb64.c
deleted file mode 100644
index b3a0158a6e..0000000000
--- a/src/lib/libcrypto/rc2/rc2cfb64.c
+++ /dev/null
@@ -1,122 +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(const unsigned char *in, unsigned char *out,
68 long length, RC2_KEY *schedule, unsigned char *ivec,
69 int *num, int encrypt)
70 {
71 register unsigned long v0,v1,t;
72 register int n= *num;
73 register long l=length;
74 unsigned long ti[2];
75 unsigned char *iv,c,cc;
76
77 iv=(unsigned char *)ivec;
78 if (encrypt)
79 {
80 while (l--)
81 {
82 if (n == 0)
83 {
84 c2l(iv,v0); ti[0]=v0;
85 c2l(iv,v1); ti[1]=v1;
86 RC2_encrypt((unsigned long *)ti,schedule);
87 iv=(unsigned char *)ivec;
88 t=ti[0]; l2c(t,iv);
89 t=ti[1]; l2c(t,iv);
90 iv=(unsigned char *)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 c2l(iv,v0); ti[0]=v0;
105 c2l(iv,v1); ti[1]=v1;
106 RC2_encrypt((unsigned long *)ti,schedule);
107 iv=(unsigned char *)ivec;
108 t=ti[0]; l2c(t,iv);
109 t=ti[1]; l2c(t,iv);
110 iv=(unsigned char *)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/rc2/rc2ofb64.c b/src/lib/libcrypto/rc2/rc2ofb64.c
deleted file mode 100644
index 9e297867ed..0000000000
--- a/src/lib/libcrypto/rc2/rc2ofb64.c
+++ /dev/null
@@ -1,111 +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(const unsigned char *in, unsigned char *out,
67 long length, RC2_KEY *schedule, unsigned char *ivec,
68 int *num)
69 {
70 register unsigned long v0,v1,t;
71 register int n= *num;
72 register long l=length;
73 unsigned char d[8];
74 register char *dp;
75 unsigned long ti[2];
76 unsigned char *iv;
77 int save=0;
78
79 iv=(unsigned char *)ivec;
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 RC2_encrypt((unsigned long *)ti,schedule);
92 dp=(char *)d;
93 t=ti[0]; l2c(t,dp);
94 t=ti[1]; l2c(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=(unsigned char *)ivec;
105 l2c(v0,iv);
106 l2c(v1,iv);
107 }
108 t=v0=v1=ti[0]=ti[1]=0;
109 *num=n;
110 }
111
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 d6e98f0811..0000000000
--- a/src/lib/libcrypto/rc4/asm/rc4-586.pl
+++ /dev/null
@@ -1,229 +0,0 @@
1#!/usr/local/bin/perl
2
3# At some point it became apparent that the original SSLeay RC4
4# assembler implementation performs suboptimaly on latest IA-32
5# microarchitectures. After re-tuning performance has changed as
6# following:
7#
8# Pentium +0%
9# Pentium III +17%
10# AMD +52%(*)
11# P4 +180%(**)
12#
13# (*) This number is actually a trade-off:-) It's possible to
14# achieve +72%, but at the cost of -48% off PIII performance.
15# In other words code performing further 13% faster on AMD
16# would perform almost 2 times slower on Intel PIII...
17# For reference! This code delivers ~80% of rc4-amd64.pl
18# performance on the same Opteron machine.
19# (**) This number requires compressed key schedule set up by
20# RC4_set_key and therefore doesn't apply to 0.9.7 [option for
21# compressed key schedule is implemented in 0.9.8 and later,
22# see commentary section in rc4_skey.c for further details].
23#
24# <appro@fy.chalmers.se>
25
26push(@INC,"perlasm","../../perlasm");
27require "x86asm.pl";
28
29&asm_init($ARGV[0],"rc4-586.pl");
30
31$x="eax";
32$y="ebx";
33$tx="ecx";
34$ty="edx";
35$in="esi";
36$out="edi";
37$d="ebp";
38
39&RC4("RC4");
40
41&asm_finish();
42
43sub RC4_loop
44 {
45 local($n,$p,$char)=@_;
46
47 &comment("Round $n");
48
49 if ($char)
50 {
51 if ($p >= 0)
52 {
53 &mov($ty, &swtmp(2));
54 &cmp($ty, $in);
55 &jbe(&label("finished"));
56 &inc($in);
57 }
58 else
59 {
60 &add($ty, 8);
61 &inc($in);
62 &cmp($ty, $in);
63 &jb(&label("finished"));
64 &mov(&swtmp(2), $ty);
65 }
66 }
67 # Moved out
68 # &mov( $tx, &DWP(0,$d,$x,4)) if $p < 0;
69
70 &add( &LB($y), &LB($tx));
71 &mov( $ty, &DWP(0,$d,$y,4));
72 # XXX
73 &mov( &DWP(0,$d,$x,4),$ty);
74 &add( $ty, $tx);
75 &mov( &DWP(0,$d,$y,4),$tx);
76 &and( $ty, 0xff);
77 &inc( &LB($x)); # NEXT ROUND
78 &mov( $tx, &DWP(0,$d,$x,4)) if $p < 1; # NEXT ROUND
79 &mov( $ty, &DWP(0,$d,$ty,4));
80
81 if (!$char)
82 {
83 #moved up into last round
84 if ($p >= 1)
85 {
86 &add( $out, 8)
87 }
88 &movb( &BP($n,"esp","",0), &LB($ty));
89 }
90 else
91 {
92 # Note in+=8 has occured
93 &movb( &HB($ty), &BP(-1,$in,"",0));
94 # XXX
95 &xorb(&LB($ty), &HB($ty));
96 # XXX
97 &movb(&BP($n,$out,"",0),&LB($ty));
98 }
99 }
100
101
102sub RC4
103 {
104 local($name)=@_;
105
106 &function_begin_B($name,"");
107
108 &mov($ty,&wparam(1)); # len
109 &cmp($ty,0);
110 &jne(&label("proceed"));
111 &ret();
112 &set_label("proceed");
113
114 &comment("");
115
116 &push("ebp");
117 &push("ebx");
118 &push("esi");
119 &xor( $x, $x); # avoid partial register stalls
120 &push("edi");
121 &xor( $y, $y); # avoid partial register stalls
122 &mov( $d, &wparam(0)); # key
123 &mov( $in, &wparam(2));
124
125 &movb( &LB($x), &BP(0,$d,"",1));
126 &movb( &LB($y), &BP(4,$d,"",1));
127
128 &mov( $out, &wparam(3));
129 &inc( &LB($x));
130
131 &stack_push(3); # 3 temp variables
132 &add( $d, 8);
133
134 # detect compressed schedule, see commentary section in rc4_skey.c...
135 # in 0.9.7 context ~50 bytes below RC4_CHAR label remain redundant,
136 # as compressed key schedule is set up in 0.9.8 and later.
137 &cmp(&DWP(256,$d),-1);
138 &je(&label("RC4_CHAR"));
139
140 &lea( $ty, &DWP(-8,$ty,$in));
141
142 # check for 0 length input
143
144 &mov( &swtmp(2), $ty); # this is now address to exit at
145 &mov( $tx, &DWP(0,$d,$x,4));
146
147 &cmp( $ty, $in);
148 &jb( &label("end")); # less than 8 bytes
149
150 &set_label("start");
151
152 # filling DELAY SLOT
153 &add( $in, 8);
154
155 &RC4_loop(0,-1,0);
156 &RC4_loop(1,0,0);
157 &RC4_loop(2,0,0);
158 &RC4_loop(3,0,0);
159 &RC4_loop(4,0,0);
160 &RC4_loop(5,0,0);
161 &RC4_loop(6,0,0);
162 &RC4_loop(7,1,0);
163
164 &comment("apply the cipher text");
165 # xor the cipher data with input
166
167 #&add( $out, 8); #moved up into last round
168
169 &mov( $tx, &swtmp(0));
170 &mov( $ty, &DWP(-8,$in,"",0));
171 &xor( $tx, $ty);
172 &mov( $ty, &DWP(-4,$in,"",0));
173 &mov( &DWP(-8,$out,"",0), $tx);
174 &mov( $tx, &swtmp(1));
175 &xor( $tx, $ty);
176 &mov( $ty, &swtmp(2)); # load end ptr;
177 &mov( &DWP(-4,$out,"",0), $tx);
178 &mov( $tx, &DWP(0,$d,$x,4));
179 &cmp($in, $ty);
180 &jbe(&label("start"));
181
182 &set_label("end");
183
184 # There is quite a bit of extra crap in RC4_loop() for this
185 # first round
186 &RC4_loop(0,-1,1);
187 &RC4_loop(1,0,1);
188 &RC4_loop(2,0,1);
189 &RC4_loop(3,0,1);
190 &RC4_loop(4,0,1);
191 &RC4_loop(5,0,1);
192 &RC4_loop(6,1,1);
193
194 &jmp(&label("finished"));
195
196 &align(16);
197 # this is essentially Intel P4 specific codepath, see rc4_skey.c,
198 # and is engaged in 0.9.8 and later context...
199 &set_label("RC4_CHAR");
200
201 &lea ($ty,&DWP(0,$in,$ty));
202 &mov (&swtmp(2),$ty);
203
204 # strangely enough unrolled loop performs over 20% slower...
205 &set_label("RC4_CHAR_loop");
206 &movz ($tx,&BP(0,$d,$x));
207 &add (&LB($y),&LB($tx));
208 &movz ($ty,&BP(0,$d,$y));
209 &movb (&BP(0,$d,$y),&LB($tx));
210 &movb (&BP(0,$d,$x),&LB($ty));
211 &add (&LB($ty),&LB($tx));
212 &movz ($ty,&BP(0,$d,$ty));
213 &xorb (&LB($ty),&BP(0,$in));
214 &movb (&BP(0,$out),&LB($ty));
215 &inc (&LB($x));
216 &inc ($in);
217 &inc ($out);
218 &cmp ($in,&swtmp(2));
219 &jb (&label("RC4_CHAR_loop"));
220
221 &set_label("finished");
222 &dec( $x);
223 &stack_pop(3);
224 &movb( &BP(-4,$d,"",0),&LB($y));
225 &movb( &BP(-8,$d,"",0),&LB($x));
226
227 &function_end($name);
228 }
229
diff --git a/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl b/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl
deleted file mode 100755
index b628daca70..0000000000
--- a/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl
+++ /dev/null
@@ -1,150 +0,0 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. Rights for redistribution and usage in source and binary
6# forms are granted according to the OpenSSL license.
7# ====================================================================
8#
9# Unlike 0.9.7f this code expects RC4_CHAR back in config line! See
10# commentary section in corresponding script in development branch
11# for background information about this option carousel. For those
12# who don't have energy to figure out these gory details, here is
13# basis in form of performance matrix relative to the original
14# 0.9.7e C code-base:
15#
16# 0.9.7e 0.9.7f this
17# AMD64 1x 3.3x 2.4x
18# EM64T 1x 0.8x 1.5x
19#
20# In other words idea is to trade -25% AMD64 performance to compensate
21# for deterioration and gain +90% on EM64T core. Development branch
22# maintains best performance for either target, i.e. 3.3x for AMD64
23# and 1.5x for EM64T.
24
25$output=shift;
26
27open STDOUT,">$output" || die "can't open $output: $!";
28
29$dat="%rdi"; # arg1
30$len="%rsi"; # arg2
31$inp="%rdx"; # arg3
32$out="%rcx"; # arg4
33
34@XX=("%r8","%r10");
35@TX=("%r9","%r11");
36$YY="%r12";
37$TY="%r13";
38
39$code=<<___;;
40.text
41
42.globl RC4
43.type RC4,\@function
44.align 16
45RC4: or $len,$len
46 jne .Lentry
47 repret
48.Lentry:
49 push %r12
50 push %r13
51
52 add \$2,$dat
53 movzb -2($dat),$XX[0]#d
54 movzb -1($dat),$YY#d
55
56 add \$1,$XX[0]#b
57 movzb ($dat,$XX[0]),$TX[0]#d
58 test \$-8,$len
59 jz .Lcloop1
60 push %rbx
61.align 16 # incidentally aligned already
62.Lcloop8:
63 mov ($inp),%eax
64 mov 4($inp),%ebx
65___
66# unroll 2x4-wise, because 64-bit rotates kill Intel P4...
67for ($i=0;$i<4;$i++) {
68$code.=<<___;
69 add $TX[0]#b,$YY#b
70 lea 1($XX[0]),$XX[1]
71 movzb ($dat,$YY),$TY#d
72 movzb $XX[1]#b,$XX[1]#d
73 movzb ($dat,$XX[1]),$TX[1]#d
74 movb $TX[0]#b,($dat,$YY)
75 cmp $XX[1],$YY
76 movb $TY#b,($dat,$XX[0])
77 jne .Lcmov$i # Intel cmov is sloooow...
78 mov $TX[0],$TX[1]
79.Lcmov$i:
80 add $TX[0]#b,$TY#b
81 xor ($dat,$TY),%al
82 ror \$8,%eax
83___
84push(@TX,shift(@TX)); push(@XX,shift(@XX)); # "rotate" registers
85}
86for ($i=4;$i<8;$i++) {
87$code.=<<___;
88 add $TX[0]#b,$YY#b
89 lea 1($XX[0]),$XX[1]
90 movzb ($dat,$YY),$TY#d
91 movzb $XX[1]#b,$XX[1]#d
92 movzb ($dat,$XX[1]),$TX[1]#d
93 movb $TX[0]#b,($dat,$YY)
94 cmp $XX[1],$YY
95 movb $TY#b,($dat,$XX[0])
96 jne .Lcmov$i # Intel cmov is sloooow...
97 mov $TX[0],$TX[1]
98.Lcmov$i:
99 add $TX[0]#b,$TY#b
100 xor ($dat,$TY),%bl
101 ror \$8,%ebx
102___
103push(@TX,shift(@TX)); push(@XX,shift(@XX)); # "rotate" registers
104}
105$code.=<<___;
106 lea -8($len),$len
107 mov %eax,($out)
108 lea 8($inp),$inp
109 mov %ebx,4($out)
110 lea 8($out),$out
111
112 test \$-8,$len
113 jnz .Lcloop8
114 pop %rbx
115 cmp \$0,$len
116 jne .Lcloop1
117.Lexit:
118 sub \$1,$XX[0]#b
119 movb $XX[0]#b,-2($dat)
120 movb $YY#b,-1($dat)
121
122 pop %r13
123 pop %r12
124 repret
125
126.align 16
127.Lcloop1:
128 add $TX[0]#b,$YY#b
129 movzb ($dat,$YY),$TY#d
130 movb $TX[0]#b,($dat,$YY)
131 movb $TY#b,($dat,$XX[0])
132 add $TX[0]#b,$TY#b
133 add \$1,$XX[0]#b
134 movzb ($dat,$TY),$TY#d
135 movzb ($dat,$XX[0]),$TX[0]#d
136 xorb ($inp),$TY#b
137 lea 1($inp),$inp
138 movb $TY#b,($out)
139 lea 1($out),$out
140 sub \$1,$len
141 jnz .Lcloop1
142 jmp .Lexit
143.size RC4,.-RC4
144___
145
146$code =~ s/#([bwd])/$1/gm;
147
148$code =~ s/repret/.byte\t0xF3,0xC3/gm;
149
150print $code;
diff --git a/src/lib/libcrypto/rc4/rc4.h b/src/lib/libcrypto/rc4/rc4.h
deleted file mode 100644
index ae0cea75b8..0000000000
--- a/src/lib/libcrypto/rc4/rc4.h
+++ /dev/null
@@ -1,91 +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 OPENSSL_NO_RC4
63#error RC4 is disabled.
64#endif
65
66#include <openssl/opensslconf.h> /* RC4_INT */
67
68#ifdef __cplusplus
69extern "C" {
70#endif
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);
80#ifdef OPENSSL_FIPS
81void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
82#endif
83void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
84void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
85 unsigned char *outdata);
86
87#ifdef __cplusplus
88}
89#endif
90
91#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 c712e1632e..0000000000
--- a/src/lib/libcrypto/rc4/rc4_locl.h
+++ /dev/null
@@ -1,5 +0,0 @@
1#ifndef HEADER_RC4_LOCL_H
2#define HEADER_RC4_LOCL_H
3#include <openssl/opensslconf.h>
4#include <cryptlib.h>
5#endif
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c
deleted file mode 100644
index 60510624fd..0000000000
--- a/src/lib/libcrypto/rc4/rc4_skey.c
+++ /dev/null
@@ -1,120 +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 <openssl/crypto.h>
61#include <openssl/fips.h>
62#include "rc4_locl.h"
63#include <openssl/opensslv.h>
64
65const char *RC4_version="RC4" OPENSSL_VERSION_PTEXT;
66
67const char *RC4_options(void)
68 {
69#ifdef RC4_INDEX
70 if (sizeof(RC4_INT) == 1)
71 return("rc4(idx,char)");
72 else
73 return("rc4(idx,int)");
74#else
75 if (sizeof(RC4_INT) == 1)
76 return("rc4(ptr,char)");
77 else
78 return("rc4(ptr,int)");
79#endif
80 }
81
82/* RC4 as implemented from a posting from
83 * Newsgroups: sci.crypt
84 * From: sterndark@netcom.com (David Sterndark)
85 * Subject: RC4 Algorithm revealed.
86 * Message-ID: <sternCvKL4B.Hyy@netcom.com>
87 * Date: Wed, 14 Sep 1994 06:35:31 GMT
88 */
89
90FIPS_NON_FIPS_VCIPHER_Init(RC4)
91 {
92 register RC4_INT tmp;
93 register int id1,id2;
94 register RC4_INT *d;
95 unsigned int i;
96
97 d= &(key->data[0]);
98
99 for (i=0; i<256; i++)
100 d[i]=i;
101 key->x = 0;
102 key->y = 0;
103 id1=id2=0;
104
105#define SK_LOOP(n) { \
106 tmp=d[(n)]; \
107 id2 = (data[id1] + tmp + id2) & 0xff; \
108 if (++id1 == len) id1=0; \
109 d[(n)]=d[id2]; \
110 d[id2]=tmp; }
111
112 for (i=0; i < 256; i+=4)
113 {
114 SK_LOOP(i+0);
115 SK_LOOP(i+1);
116 SK_LOOP(i+2);
117 SK_LOOP(i+3);
118 }
119 }
120
diff --git a/src/lib/libcrypto/ripemd/README b/src/lib/libcrypto/ripemd/README
deleted file mode 100644
index f1ffc8b134..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 believe 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 7d0d998189..0000000000
--- a/src/lib/libcrypto/ripemd/ripemd.h
+++ /dev/null
@@ -1,106 +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#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_RIPEMD
69#error RIPEMD is disabled.
70#endif
71
72#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
73#define RIPEMD160_LONG unsigned long
74#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
75#define RIPEMD160_LONG unsigned long
76#define RIPEMD160_LONG_LOG2 3
77#else
78#define RIPEMD160_LONG unsigned int
79#endif
80
81#define RIPEMD160_CBLOCK 64
82#define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4)
83#define RIPEMD160_DIGEST_LENGTH 20
84
85typedef struct RIPEMD160state_st
86 {
87 RIPEMD160_LONG A,B,C,D,E;
88 RIPEMD160_LONG Nl,Nh;
89 RIPEMD160_LONG data[RIPEMD160_LBLOCK];
90 int num;
91 } RIPEMD160_CTX;
92
93#ifdef OPENSSL_FIPS
94int private_RIPEMD160_Init(RIPEMD160_CTX *c);
95#endif
96int RIPEMD160_Init(RIPEMD160_CTX *c);
97int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, unsigned long len);
98int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
99unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
100 unsigned char *md);
101void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);
102#ifdef __cplusplus
103}
104#endif
105
106#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c
deleted file mode 100644
index 58ff010d11..0000000000
--- a/src/lib/libcrypto/ripemd/rmd_dgst.c
+++ /dev/null
@@ -1,495 +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/fips.h>
62#include <openssl/opensslv.h>
63
64const char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
65
66# ifdef RMD160_ASM
67 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num);
68# define ripemd160_block ripemd160_block_x86
69# else
70 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num);
71# endif
72
73FIPS_NON_FIPS_MD_Init(RIPEMD160)
74 {
75 c->A=RIPEMD160_A;
76 c->B=RIPEMD160_B;
77 c->C=RIPEMD160_C;
78 c->D=RIPEMD160_D;
79 c->E=RIPEMD160_E;
80 c->Nl=0;
81 c->Nh=0;
82 c->num=0;
83 return 1;
84 }
85
86#ifndef ripemd160_block_host_order
87#ifdef X
88#undef X
89#endif
90#define X(i) XX[i]
91void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num)
92 {
93 const RIPEMD160_LONG *XX=p;
94 register volatile unsigned MD32_REG_T A,B,C,D,E;
95 register unsigned MD32_REG_T a,b,c,d,e;
96
97 for (;num--;XX+=HASH_LBLOCK)
98 {
99
100 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
101
102 RIP1(A,B,C,D,E,WL00,SL00);
103 RIP1(E,A,B,C,D,WL01,SL01);
104 RIP1(D,E,A,B,C,WL02,SL02);
105 RIP1(C,D,E,A,B,WL03,SL03);
106 RIP1(B,C,D,E,A,WL04,SL04);
107 RIP1(A,B,C,D,E,WL05,SL05);
108 RIP1(E,A,B,C,D,WL06,SL06);
109 RIP1(D,E,A,B,C,WL07,SL07);
110 RIP1(C,D,E,A,B,WL08,SL08);
111 RIP1(B,C,D,E,A,WL09,SL09);
112 RIP1(A,B,C,D,E,WL10,SL10);
113 RIP1(E,A,B,C,D,WL11,SL11);
114 RIP1(D,E,A,B,C,WL12,SL12);
115 RIP1(C,D,E,A,B,WL13,SL13);
116 RIP1(B,C,D,E,A,WL14,SL14);
117 RIP1(A,B,C,D,E,WL15,SL15);
118
119 RIP2(E,A,B,C,D,WL16,SL16,KL1);
120 RIP2(D,E,A,B,C,WL17,SL17,KL1);
121 RIP2(C,D,E,A,B,WL18,SL18,KL1);
122 RIP2(B,C,D,E,A,WL19,SL19,KL1);
123 RIP2(A,B,C,D,E,WL20,SL20,KL1);
124 RIP2(E,A,B,C,D,WL21,SL21,KL1);
125 RIP2(D,E,A,B,C,WL22,SL22,KL1);
126 RIP2(C,D,E,A,B,WL23,SL23,KL1);
127 RIP2(B,C,D,E,A,WL24,SL24,KL1);
128 RIP2(A,B,C,D,E,WL25,SL25,KL1);
129 RIP2(E,A,B,C,D,WL26,SL26,KL1);
130 RIP2(D,E,A,B,C,WL27,SL27,KL1);
131 RIP2(C,D,E,A,B,WL28,SL28,KL1);
132 RIP2(B,C,D,E,A,WL29,SL29,KL1);
133 RIP2(A,B,C,D,E,WL30,SL30,KL1);
134 RIP2(E,A,B,C,D,WL31,SL31,KL1);
135
136 RIP3(D,E,A,B,C,WL32,SL32,KL2);
137 RIP3(C,D,E,A,B,WL33,SL33,KL2);
138 RIP3(B,C,D,E,A,WL34,SL34,KL2);
139 RIP3(A,B,C,D,E,WL35,SL35,KL2);
140 RIP3(E,A,B,C,D,WL36,SL36,KL2);
141 RIP3(D,E,A,B,C,WL37,SL37,KL2);
142 RIP3(C,D,E,A,B,WL38,SL38,KL2);
143 RIP3(B,C,D,E,A,WL39,SL39,KL2);
144 RIP3(A,B,C,D,E,WL40,SL40,KL2);
145 RIP3(E,A,B,C,D,WL41,SL41,KL2);
146 RIP3(D,E,A,B,C,WL42,SL42,KL2);
147 RIP3(C,D,E,A,B,WL43,SL43,KL2);
148 RIP3(B,C,D,E,A,WL44,SL44,KL2);
149 RIP3(A,B,C,D,E,WL45,SL45,KL2);
150 RIP3(E,A,B,C,D,WL46,SL46,KL2);
151 RIP3(D,E,A,B,C,WL47,SL47,KL2);
152
153 RIP4(C,D,E,A,B,WL48,SL48,KL3);
154 RIP4(B,C,D,E,A,WL49,SL49,KL3);
155 RIP4(A,B,C,D,E,WL50,SL50,KL3);
156 RIP4(E,A,B,C,D,WL51,SL51,KL3);
157 RIP4(D,E,A,B,C,WL52,SL52,KL3);
158 RIP4(C,D,E,A,B,WL53,SL53,KL3);
159 RIP4(B,C,D,E,A,WL54,SL54,KL3);
160 RIP4(A,B,C,D,E,WL55,SL55,KL3);
161 RIP4(E,A,B,C,D,WL56,SL56,KL3);
162 RIP4(D,E,A,B,C,WL57,SL57,KL3);
163 RIP4(C,D,E,A,B,WL58,SL58,KL3);
164 RIP4(B,C,D,E,A,WL59,SL59,KL3);
165 RIP4(A,B,C,D,E,WL60,SL60,KL3);
166 RIP4(E,A,B,C,D,WL61,SL61,KL3);
167 RIP4(D,E,A,B,C,WL62,SL62,KL3);
168 RIP4(C,D,E,A,B,WL63,SL63,KL3);
169
170 RIP5(B,C,D,E,A,WL64,SL64,KL4);
171 RIP5(A,B,C,D,E,WL65,SL65,KL4);
172 RIP5(E,A,B,C,D,WL66,SL66,KL4);
173 RIP5(D,E,A,B,C,WL67,SL67,KL4);
174 RIP5(C,D,E,A,B,WL68,SL68,KL4);
175 RIP5(B,C,D,E,A,WL69,SL69,KL4);
176 RIP5(A,B,C,D,E,WL70,SL70,KL4);
177 RIP5(E,A,B,C,D,WL71,SL71,KL4);
178 RIP5(D,E,A,B,C,WL72,SL72,KL4);
179 RIP5(C,D,E,A,B,WL73,SL73,KL4);
180 RIP5(B,C,D,E,A,WL74,SL74,KL4);
181 RIP5(A,B,C,D,E,WL75,SL75,KL4);
182 RIP5(E,A,B,C,D,WL76,SL76,KL4);
183 RIP5(D,E,A,B,C,WL77,SL77,KL4);
184 RIP5(C,D,E,A,B,WL78,SL78,KL4);
185 RIP5(B,C,D,E,A,WL79,SL79,KL4);
186
187 a=A; b=B; c=C; d=D; e=E;
188 /* Do other half */
189 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
190
191 RIP5(A,B,C,D,E,WR00,SR00,KR0);
192 RIP5(E,A,B,C,D,WR01,SR01,KR0);
193 RIP5(D,E,A,B,C,WR02,SR02,KR0);
194 RIP5(C,D,E,A,B,WR03,SR03,KR0);
195 RIP5(B,C,D,E,A,WR04,SR04,KR0);
196 RIP5(A,B,C,D,E,WR05,SR05,KR0);
197 RIP5(E,A,B,C,D,WR06,SR06,KR0);
198 RIP5(D,E,A,B,C,WR07,SR07,KR0);
199 RIP5(C,D,E,A,B,WR08,SR08,KR0);
200 RIP5(B,C,D,E,A,WR09,SR09,KR0);
201 RIP5(A,B,C,D,E,WR10,SR10,KR0);
202 RIP5(E,A,B,C,D,WR11,SR11,KR0);
203 RIP5(D,E,A,B,C,WR12,SR12,KR0);
204 RIP5(C,D,E,A,B,WR13,SR13,KR0);
205 RIP5(B,C,D,E,A,WR14,SR14,KR0);
206 RIP5(A,B,C,D,E,WR15,SR15,KR0);
207
208 RIP4(E,A,B,C,D,WR16,SR16,KR1);
209 RIP4(D,E,A,B,C,WR17,SR17,KR1);
210 RIP4(C,D,E,A,B,WR18,SR18,KR1);
211 RIP4(B,C,D,E,A,WR19,SR19,KR1);
212 RIP4(A,B,C,D,E,WR20,SR20,KR1);
213 RIP4(E,A,B,C,D,WR21,SR21,KR1);
214 RIP4(D,E,A,B,C,WR22,SR22,KR1);
215 RIP4(C,D,E,A,B,WR23,SR23,KR1);
216 RIP4(B,C,D,E,A,WR24,SR24,KR1);
217 RIP4(A,B,C,D,E,WR25,SR25,KR1);
218 RIP4(E,A,B,C,D,WR26,SR26,KR1);
219 RIP4(D,E,A,B,C,WR27,SR27,KR1);
220 RIP4(C,D,E,A,B,WR28,SR28,KR1);
221 RIP4(B,C,D,E,A,WR29,SR29,KR1);
222 RIP4(A,B,C,D,E,WR30,SR30,KR1);
223 RIP4(E,A,B,C,D,WR31,SR31,KR1);
224
225 RIP3(D,E,A,B,C,WR32,SR32,KR2);
226 RIP3(C,D,E,A,B,WR33,SR33,KR2);
227 RIP3(B,C,D,E,A,WR34,SR34,KR2);
228 RIP3(A,B,C,D,E,WR35,SR35,KR2);
229 RIP3(E,A,B,C,D,WR36,SR36,KR2);
230 RIP3(D,E,A,B,C,WR37,SR37,KR2);
231 RIP3(C,D,E,A,B,WR38,SR38,KR2);
232 RIP3(B,C,D,E,A,WR39,SR39,KR2);
233 RIP3(A,B,C,D,E,WR40,SR40,KR2);
234 RIP3(E,A,B,C,D,WR41,SR41,KR2);
235 RIP3(D,E,A,B,C,WR42,SR42,KR2);
236 RIP3(C,D,E,A,B,WR43,SR43,KR2);
237 RIP3(B,C,D,E,A,WR44,SR44,KR2);
238 RIP3(A,B,C,D,E,WR45,SR45,KR2);
239 RIP3(E,A,B,C,D,WR46,SR46,KR2);
240 RIP3(D,E,A,B,C,WR47,SR47,KR2);
241
242 RIP2(C,D,E,A,B,WR48,SR48,KR3);
243 RIP2(B,C,D,E,A,WR49,SR49,KR3);
244 RIP2(A,B,C,D,E,WR50,SR50,KR3);
245 RIP2(E,A,B,C,D,WR51,SR51,KR3);
246 RIP2(D,E,A,B,C,WR52,SR52,KR3);
247 RIP2(C,D,E,A,B,WR53,SR53,KR3);
248 RIP2(B,C,D,E,A,WR54,SR54,KR3);
249 RIP2(A,B,C,D,E,WR55,SR55,KR3);
250 RIP2(E,A,B,C,D,WR56,SR56,KR3);
251 RIP2(D,E,A,B,C,WR57,SR57,KR3);
252 RIP2(C,D,E,A,B,WR58,SR58,KR3);
253 RIP2(B,C,D,E,A,WR59,SR59,KR3);
254 RIP2(A,B,C,D,E,WR60,SR60,KR3);
255 RIP2(E,A,B,C,D,WR61,SR61,KR3);
256 RIP2(D,E,A,B,C,WR62,SR62,KR3);
257 RIP2(C,D,E,A,B,WR63,SR63,KR3);
258
259 RIP1(B,C,D,E,A,WR64,SR64);
260 RIP1(A,B,C,D,E,WR65,SR65);
261 RIP1(E,A,B,C,D,WR66,SR66);
262 RIP1(D,E,A,B,C,WR67,SR67);
263 RIP1(C,D,E,A,B,WR68,SR68);
264 RIP1(B,C,D,E,A,WR69,SR69);
265 RIP1(A,B,C,D,E,WR70,SR70);
266 RIP1(E,A,B,C,D,WR71,SR71);
267 RIP1(D,E,A,B,C,WR72,SR72);
268 RIP1(C,D,E,A,B,WR73,SR73);
269 RIP1(B,C,D,E,A,WR74,SR74);
270 RIP1(A,B,C,D,E,WR75,SR75);
271 RIP1(E,A,B,C,D,WR76,SR76);
272 RIP1(D,E,A,B,C,WR77,SR77);
273 RIP1(C,D,E,A,B,WR78,SR78);
274 RIP1(B,C,D,E,A,WR79,SR79);
275
276 D =ctx->B+c+D;
277 ctx->B=ctx->C+d+E;
278 ctx->C=ctx->D+e+A;
279 ctx->D=ctx->E+a+B;
280 ctx->E=ctx->A+b+C;
281 ctx->A=D;
282
283 }
284 }
285#endif
286
287#ifndef ripemd160_block_data_order
288#ifdef X
289#undef X
290#endif
291void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, int num)
292 {
293 const unsigned char *data=p;
294 register volatile unsigned MD32_REG_T A,B,C,D,E;
295 unsigned MD32_REG_T a,b,c,d,e,l;
296#ifndef MD32_XARRAY
297 /* See comment in crypto/sha/sha_locl.h for details. */
298 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
299 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
300# define X(i) XX##i
301#else
302 RIPEMD160_LONG XX[16];
303# define X(i) XX[i]
304#endif
305
306 for (;num--;)
307 {
308
309 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
310
311 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
312 RIP1(A,B,C,D,E,WL00,SL00); HOST_c2l(data,l); X( 2)=l;
313 RIP1(E,A,B,C,D,WL01,SL01); HOST_c2l(data,l); X( 3)=l;
314 RIP1(D,E,A,B,C,WL02,SL02); HOST_c2l(data,l); X( 4)=l;
315 RIP1(C,D,E,A,B,WL03,SL03); HOST_c2l(data,l); X( 5)=l;
316 RIP1(B,C,D,E,A,WL04,SL04); HOST_c2l(data,l); X( 6)=l;
317 RIP1(A,B,C,D,E,WL05,SL05); HOST_c2l(data,l); X( 7)=l;
318 RIP1(E,A,B,C,D,WL06,SL06); HOST_c2l(data,l); X( 8)=l;
319 RIP1(D,E,A,B,C,WL07,SL07); HOST_c2l(data,l); X( 9)=l;
320 RIP1(C,D,E,A,B,WL08,SL08); HOST_c2l(data,l); X(10)=l;
321 RIP1(B,C,D,E,A,WL09,SL09); HOST_c2l(data,l); X(11)=l;
322 RIP1(A,B,C,D,E,WL10,SL10); HOST_c2l(data,l); X(12)=l;
323 RIP1(E,A,B,C,D,WL11,SL11); HOST_c2l(data,l); X(13)=l;
324 RIP1(D,E,A,B,C,WL12,SL12); HOST_c2l(data,l); X(14)=l;
325 RIP1(C,D,E,A,B,WL13,SL13); HOST_c2l(data,l); X(15)=l;
326 RIP1(B,C,D,E,A,WL14,SL14);
327 RIP1(A,B,C,D,E,WL15,SL15);
328
329 RIP2(E,A,B,C,D,WL16,SL16,KL1);
330 RIP2(D,E,A,B,C,WL17,SL17,KL1);
331 RIP2(C,D,E,A,B,WL18,SL18,KL1);
332 RIP2(B,C,D,E,A,WL19,SL19,KL1);
333 RIP2(A,B,C,D,E,WL20,SL20,KL1);
334 RIP2(E,A,B,C,D,WL21,SL21,KL1);
335 RIP2(D,E,A,B,C,WL22,SL22,KL1);
336 RIP2(C,D,E,A,B,WL23,SL23,KL1);
337 RIP2(B,C,D,E,A,WL24,SL24,KL1);
338 RIP2(A,B,C,D,E,WL25,SL25,KL1);
339 RIP2(E,A,B,C,D,WL26,SL26,KL1);
340 RIP2(D,E,A,B,C,WL27,SL27,KL1);
341 RIP2(C,D,E,A,B,WL28,SL28,KL1);
342 RIP2(B,C,D,E,A,WL29,SL29,KL1);
343 RIP2(A,B,C,D,E,WL30,SL30,KL1);
344 RIP2(E,A,B,C,D,WL31,SL31,KL1);
345
346 RIP3(D,E,A,B,C,WL32,SL32,KL2);
347 RIP3(C,D,E,A,B,WL33,SL33,KL2);
348 RIP3(B,C,D,E,A,WL34,SL34,KL2);
349 RIP3(A,B,C,D,E,WL35,SL35,KL2);
350 RIP3(E,A,B,C,D,WL36,SL36,KL2);
351 RIP3(D,E,A,B,C,WL37,SL37,KL2);
352 RIP3(C,D,E,A,B,WL38,SL38,KL2);
353 RIP3(B,C,D,E,A,WL39,SL39,KL2);
354 RIP3(A,B,C,D,E,WL40,SL40,KL2);
355 RIP3(E,A,B,C,D,WL41,SL41,KL2);
356 RIP3(D,E,A,B,C,WL42,SL42,KL2);
357 RIP3(C,D,E,A,B,WL43,SL43,KL2);
358 RIP3(B,C,D,E,A,WL44,SL44,KL2);
359 RIP3(A,B,C,D,E,WL45,SL45,KL2);
360 RIP3(E,A,B,C,D,WL46,SL46,KL2);
361 RIP3(D,E,A,B,C,WL47,SL47,KL2);
362
363 RIP4(C,D,E,A,B,WL48,SL48,KL3);
364 RIP4(B,C,D,E,A,WL49,SL49,KL3);
365 RIP4(A,B,C,D,E,WL50,SL50,KL3);
366 RIP4(E,A,B,C,D,WL51,SL51,KL3);
367 RIP4(D,E,A,B,C,WL52,SL52,KL3);
368 RIP4(C,D,E,A,B,WL53,SL53,KL3);
369 RIP4(B,C,D,E,A,WL54,SL54,KL3);
370 RIP4(A,B,C,D,E,WL55,SL55,KL3);
371 RIP4(E,A,B,C,D,WL56,SL56,KL3);
372 RIP4(D,E,A,B,C,WL57,SL57,KL3);
373 RIP4(C,D,E,A,B,WL58,SL58,KL3);
374 RIP4(B,C,D,E,A,WL59,SL59,KL3);
375 RIP4(A,B,C,D,E,WL60,SL60,KL3);
376 RIP4(E,A,B,C,D,WL61,SL61,KL3);
377 RIP4(D,E,A,B,C,WL62,SL62,KL3);
378 RIP4(C,D,E,A,B,WL63,SL63,KL3);
379
380 RIP5(B,C,D,E,A,WL64,SL64,KL4);
381 RIP5(A,B,C,D,E,WL65,SL65,KL4);
382 RIP5(E,A,B,C,D,WL66,SL66,KL4);
383 RIP5(D,E,A,B,C,WL67,SL67,KL4);
384 RIP5(C,D,E,A,B,WL68,SL68,KL4);
385 RIP5(B,C,D,E,A,WL69,SL69,KL4);
386 RIP5(A,B,C,D,E,WL70,SL70,KL4);
387 RIP5(E,A,B,C,D,WL71,SL71,KL4);
388 RIP5(D,E,A,B,C,WL72,SL72,KL4);
389 RIP5(C,D,E,A,B,WL73,SL73,KL4);
390 RIP5(B,C,D,E,A,WL74,SL74,KL4);
391 RIP5(A,B,C,D,E,WL75,SL75,KL4);
392 RIP5(E,A,B,C,D,WL76,SL76,KL4);
393 RIP5(D,E,A,B,C,WL77,SL77,KL4);
394 RIP5(C,D,E,A,B,WL78,SL78,KL4);
395 RIP5(B,C,D,E,A,WL79,SL79,KL4);
396
397 a=A; b=B; c=C; d=D; e=E;
398 /* Do other half */
399 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
400
401 RIP5(A,B,C,D,E,WR00,SR00,KR0);
402 RIP5(E,A,B,C,D,WR01,SR01,KR0);
403 RIP5(D,E,A,B,C,WR02,SR02,KR0);
404 RIP5(C,D,E,A,B,WR03,SR03,KR0);
405 RIP5(B,C,D,E,A,WR04,SR04,KR0);
406 RIP5(A,B,C,D,E,WR05,SR05,KR0);
407 RIP5(E,A,B,C,D,WR06,SR06,KR0);
408 RIP5(D,E,A,B,C,WR07,SR07,KR0);
409 RIP5(C,D,E,A,B,WR08,SR08,KR0);
410 RIP5(B,C,D,E,A,WR09,SR09,KR0);
411 RIP5(A,B,C,D,E,WR10,SR10,KR0);
412 RIP5(E,A,B,C,D,WR11,SR11,KR0);
413 RIP5(D,E,A,B,C,WR12,SR12,KR0);
414 RIP5(C,D,E,A,B,WR13,SR13,KR0);
415 RIP5(B,C,D,E,A,WR14,SR14,KR0);
416 RIP5(A,B,C,D,E,WR15,SR15,KR0);
417
418 RIP4(E,A,B,C,D,WR16,SR16,KR1);
419 RIP4(D,E,A,B,C,WR17,SR17,KR1);
420 RIP4(C,D,E,A,B,WR18,SR18,KR1);
421 RIP4(B,C,D,E,A,WR19,SR19,KR1);
422 RIP4(A,B,C,D,E,WR20,SR20,KR1);
423 RIP4(E,A,B,C,D,WR21,SR21,KR1);
424 RIP4(D,E,A,B,C,WR22,SR22,KR1);
425 RIP4(C,D,E,A,B,WR23,SR23,KR1);
426 RIP4(B,C,D,E,A,WR24,SR24,KR1);
427 RIP4(A,B,C,D,E,WR25,SR25,KR1);
428 RIP4(E,A,B,C,D,WR26,SR26,KR1);
429 RIP4(D,E,A,B,C,WR27,SR27,KR1);
430 RIP4(C,D,E,A,B,WR28,SR28,KR1);
431 RIP4(B,C,D,E,A,WR29,SR29,KR1);
432 RIP4(A,B,C,D,E,WR30,SR30,KR1);
433 RIP4(E,A,B,C,D,WR31,SR31,KR1);
434
435 RIP3(D,E,A,B,C,WR32,SR32,KR2);
436 RIP3(C,D,E,A,B,WR33,SR33,KR2);
437 RIP3(B,C,D,E,A,WR34,SR34,KR2);
438 RIP3(A,B,C,D,E,WR35,SR35,KR2);
439 RIP3(E,A,B,C,D,WR36,SR36,KR2);
440 RIP3(D,E,A,B,C,WR37,SR37,KR2);
441 RIP3(C,D,E,A,B,WR38,SR38,KR2);
442 RIP3(B,C,D,E,A,WR39,SR39,KR2);
443 RIP3(A,B,C,D,E,WR40,SR40,KR2);
444 RIP3(E,A,B,C,D,WR41,SR41,KR2);
445 RIP3(D,E,A,B,C,WR42,SR42,KR2);
446 RIP3(C,D,E,A,B,WR43,SR43,KR2);
447 RIP3(B,C,D,E,A,WR44,SR44,KR2);
448 RIP3(A,B,C,D,E,WR45,SR45,KR2);
449 RIP3(E,A,B,C,D,WR46,SR46,KR2);
450 RIP3(D,E,A,B,C,WR47,SR47,KR2);
451
452 RIP2(C,D,E,A,B,WR48,SR48,KR3);
453 RIP2(B,C,D,E,A,WR49,SR49,KR3);
454 RIP2(A,B,C,D,E,WR50,SR50,KR3);
455 RIP2(E,A,B,C,D,WR51,SR51,KR3);
456 RIP2(D,E,A,B,C,WR52,SR52,KR3);
457 RIP2(C,D,E,A,B,WR53,SR53,KR3);
458 RIP2(B,C,D,E,A,WR54,SR54,KR3);
459 RIP2(A,B,C,D,E,WR55,SR55,KR3);
460 RIP2(E,A,B,C,D,WR56,SR56,KR3);
461 RIP2(D,E,A,B,C,WR57,SR57,KR3);
462 RIP2(C,D,E,A,B,WR58,SR58,KR3);
463 RIP2(B,C,D,E,A,WR59,SR59,KR3);
464 RIP2(A,B,C,D,E,WR60,SR60,KR3);
465 RIP2(E,A,B,C,D,WR61,SR61,KR3);
466 RIP2(D,E,A,B,C,WR62,SR62,KR3);
467 RIP2(C,D,E,A,B,WR63,SR63,KR3);
468
469 RIP1(B,C,D,E,A,WR64,SR64);
470 RIP1(A,B,C,D,E,WR65,SR65);
471 RIP1(E,A,B,C,D,WR66,SR66);
472 RIP1(D,E,A,B,C,WR67,SR67);
473 RIP1(C,D,E,A,B,WR68,SR68);
474 RIP1(B,C,D,E,A,WR69,SR69);
475 RIP1(A,B,C,D,E,WR70,SR70);
476 RIP1(E,A,B,C,D,WR71,SR71);
477 RIP1(D,E,A,B,C,WR72,SR72);
478 RIP1(C,D,E,A,B,WR73,SR73);
479 RIP1(B,C,D,E,A,WR74,SR74);
480 RIP1(A,B,C,D,E,WR75,SR75);
481 RIP1(E,A,B,C,D,WR76,SR76);
482 RIP1(D,E,A,B,C,WR77,SR77);
483 RIP1(C,D,E,A,B,WR78,SR78);
484 RIP1(B,C,D,E,A,WR79,SR79);
485
486 D =ctx->B+c+D;
487 ctx->B=ctx->C+d+E;
488 ctx->C=ctx->D+e+A;
489 ctx->D=ctx->E+a+B;
490 ctx->E=ctx->A+b+C;
491 ctx->A=D;
492
493 }
494 }
495#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h
deleted file mode 100644
index 7b835dfbd4..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(__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(__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 b88446b267..0000000000
--- a/src/lib/libcrypto/ripemd/rmd_one.c
+++ /dev/null
@@ -1,78 +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#include <openssl/crypto.h>
63
64unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
65 unsigned char *md)
66 {
67 RIPEMD160_CTX c;
68 static unsigned char m[RIPEMD160_DIGEST_LENGTH];
69
70 if (md == NULL) md=m;
71 if (!RIPEMD160_Init(&c))
72 return NULL;
73 RIPEMD160_Update(&c,d,n);
74 RIPEMD160_Final(md,&c);
75 OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
76 return(md);
77 }
78
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 dbed701e89..0000000000
--- a/src/lib/libcrypto/rsa/rsa.h
+++ /dev/null
@@ -1,413 +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#include <openssl/asn1.h>
63
64#ifndef OPENSSL_NO_BIO
65#include <openssl/bio.h>
66#endif
67#include <openssl/bn.h>
68#include <openssl/crypto.h>
69#include <openssl/ossl_typ.h>
70
71#ifdef OPENSSL_NO_RSA
72#error RSA is disabled.
73#endif
74
75#if defined(OPENSSL_FIPS)
76#define FIPS_RSA_SIZE_T int
77#endif
78
79#ifdef __cplusplus
80extern "C" {
81#endif
82
83typedef struct rsa_st RSA;
84
85typedef struct rsa_meth_st
86 {
87 const char *name;
88 int (*rsa_pub_enc)(int flen,const unsigned char *from,
89 unsigned char *to,
90 RSA *rsa,int padding);
91 int (*rsa_pub_dec)(int flen,const unsigned char *from,
92 unsigned char *to,
93 RSA *rsa,int padding);
94 int (*rsa_priv_enc)(int flen,const unsigned char *from,
95 unsigned char *to,
96 RSA *rsa,int padding);
97 int (*rsa_priv_dec)(int flen,const unsigned char *from,
98 unsigned char *to,
99 RSA *rsa,int padding);
100 int (*rsa_mod_exp)(BIGNUM *r0,const BIGNUM *I,RSA *rsa); /* Can be null */
101 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
102 const BIGNUM *m, BN_CTX *ctx,
103 BN_MONT_CTX *m_ctx); /* Can be null */
104 int (*init)(RSA *rsa); /* called at new */
105 int (*finish)(RSA *rsa); /* called at free */
106 int flags; /* RSA_METHOD_FLAG_* things */
107 char *app_data; /* may be needed! */
108/* New sign and verify functions: some libraries don't allow arbitrary data
109 * to be signed/verified: this allows them to be used. Note: for this to work
110 * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used
111 * RSA_sign(), RSA_verify() should be used instead. Note: for backwards
112 * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER
113 * option is set in 'flags'.
114 */
115 int (*rsa_sign)(int type,
116 const unsigned char *m, unsigned int m_length,
117 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
118 int (*rsa_verify)(int dtype,
119 const unsigned char *m, unsigned int m_length,
120 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
121
122 } RSA_METHOD;
123
124struct rsa_st
125 {
126 /* The first parameter is used to pickup errors where
127 * this is passed instead of aEVP_PKEY, it is set to 0 */
128 int pad;
129 long version;
130 const RSA_METHOD *meth;
131 /* functional reference if 'meth' is ENGINE-provided */
132 ENGINE *engine;
133 BIGNUM *n;
134 BIGNUM *e;
135 BIGNUM *d;
136 BIGNUM *p;
137 BIGNUM *q;
138 BIGNUM *dmp1;
139 BIGNUM *dmq1;
140 BIGNUM *iqmp;
141 /* be careful using this if the RSA structure is shared */
142 CRYPTO_EX_DATA ex_data;
143 int references;
144 int flags;
145
146 /* Used to cache montgomery values */
147 BN_MONT_CTX *_method_mod_n;
148 BN_MONT_CTX *_method_mod_p;
149 BN_MONT_CTX *_method_mod_q;
150
151 /* all BIGNUM values are actually in the following data, if it is not
152 * NULL */
153 char *bignum_data;
154 BN_BLINDING *blinding;
155 };
156
157#define OPENSSL_RSA_MAX_MODULUS_BITS 16384
158
159#define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
160#define OPENSSL_RSA_MAX_PUBEXP_BITS 64 /* exponent limit enforced for "small" modulus only */
161
162#define RSA_3 0x3L
163#define RSA_F4 0x10001L
164
165#define RSA_METHOD_FLAG_NO_CHECK 0x0001 /* don't check pub/private match */
166
167#define RSA_FLAG_CACHE_PUBLIC 0x0002
168#define RSA_FLAG_CACHE_PRIVATE 0x0004
169#define RSA_FLAG_BLINDING 0x0008
170#define RSA_FLAG_THREAD_SAFE 0x0010
171/* This flag means the private key operations will be handled by rsa_mod_exp
172 * and that they do not depend on the private key components being present:
173 * for example a key stored in external hardware. Without this flag bn_mod_exp
174 * gets called when private key components are absent.
175 */
176#define RSA_FLAG_EXT_PKEY 0x0020
177
178/* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions.
179 */
180#define RSA_FLAG_SIGN_VER 0x0040
181
182#define RSA_FLAG_NO_BLINDING 0x0080 /* new with 0.9.6j and 0.9.7b; the built-in
183 * RSA implementation now uses blinding by
184 * default (ignoring RSA_FLAG_BLINDING),
185 * but other engines might not need it
186 */
187#define RSA_FLAG_NO_EXP_CONSTTIME 0x0100 /* new with 0.9.7h; the built-in RSA
188 * implementation now uses constant time
189 * modular exponentiation for secret exponents
190 * by default. This flag causes the
191 * faster variable sliding window method to
192 * be used for all exponents.
193 */
194
195#define RSA_PKCS1_PADDING 1
196#define RSA_SSLV23_PADDING 2
197#define RSA_NO_PADDING 3
198#define RSA_PKCS1_OAEP_PADDING 4
199#define RSA_X931_PADDING 5
200
201#define RSA_PKCS1_PADDING_SIZE 11
202
203#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg)
204#define RSA_get_app_data(s) RSA_get_ex_data(s,0)
205
206RSA * RSA_new(void);
207RSA * RSA_new_method(ENGINE *engine);
208int RSA_size(const RSA *);
209RSA * RSA_generate_key(int bits, unsigned long e,void
210 (*callback)(int,int,void *),void *cb_arg);
211int RSA_check_key(const RSA *);
212#ifdef OPENSSL_FIPS
213int RSA_X931_derive(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2,
214 void (*cb)(int, int, void *), void *cb_arg,
215 const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp,
216 const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq,
217 const BIGNUM *e);
218RSA *RSA_X931_generate_key(int bits, const BIGNUM *e,
219 void (*cb)(int,int,void *), void *cb_arg);
220#endif
221 /* next 4 return -1 on error */
222int RSA_public_encrypt(int flen, const unsigned char *from,
223 unsigned char *to, RSA *rsa,int padding);
224int RSA_private_encrypt(int flen, const unsigned char *from,
225 unsigned char *to, RSA *rsa,int padding);
226int RSA_public_decrypt(int flen, const unsigned char *from,
227 unsigned char *to, RSA *rsa,int padding);
228int RSA_private_decrypt(int flen, const unsigned char *from,
229 unsigned char *to, RSA *rsa,int padding);
230void RSA_free (RSA *r);
231/* "up" the RSA object's reference count */
232int RSA_up_ref(RSA *r);
233
234int RSA_flags(const RSA *r);
235
236void RSA_set_default_method(const RSA_METHOD *meth);
237const RSA_METHOD *RSA_get_default_method(void);
238const RSA_METHOD *RSA_get_method(const RSA *rsa);
239int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
240
241/* This function needs the memory locking malloc callbacks to be installed */
242int RSA_memory_lock(RSA *r);
243
244/* these are the actual SSLeay RSA functions */
245const RSA_METHOD *RSA_PKCS1_SSLeay(void);
246
247const RSA_METHOD *RSA_null_method(void);
248
249DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
250DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
251
252#ifndef OPENSSL_NO_FP_API
253int RSA_print_fp(FILE *fp, const RSA *r,int offset);
254#endif
255
256#ifndef OPENSSL_NO_BIO
257int RSA_print(BIO *bp, const RSA *r,int offset);
258#endif
259
260int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey);
261RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey);
262
263int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)());
264RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)());
265
266/* The following 2 functions sign and verify a X509_SIG ASN1 object
267 * inside PKCS#1 padded RSA encryption */
268int RSA_sign(int type, const unsigned char *m, unsigned int m_length,
269 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
270int RSA_verify(int type, const unsigned char *m, unsigned int m_length,
271 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
272
273/* The following 2 function sign and verify a ASN1_OCTET_STRING
274 * object inside PKCS#1 padded RSA encryption */
275int RSA_sign_ASN1_OCTET_STRING(int type,
276 const unsigned char *m, unsigned int m_length,
277 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
278int RSA_verify_ASN1_OCTET_STRING(int type,
279 const unsigned char *m, unsigned int m_length,
280 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
281
282int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
283void RSA_blinding_off(RSA *rsa);
284
285int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,
286 const unsigned char *f,int fl);
287int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen,
288 const unsigned char *f,int fl,int rsa_len);
289int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen,
290 const unsigned char *f,int fl);
291int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen,
292 const unsigned char *f,int fl,int rsa_len);
293int PKCS1_MGF1(unsigned char *mask, long len,
294 const unsigned char *seed, long seedlen, const EVP_MD *dgst);
295int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen,
296 const unsigned char *f,int fl,
297 const unsigned char *p,int pl);
298int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen,
299 const unsigned char *f,int fl,int rsa_len,
300 const unsigned char *p,int pl);
301int RSA_padding_add_SSLv23(unsigned char *to,int tlen,
302 const unsigned char *f,int fl);
303int RSA_padding_check_SSLv23(unsigned char *to,int tlen,
304 const unsigned char *f,int fl,int rsa_len);
305int RSA_padding_add_none(unsigned char *to,int tlen,
306 const unsigned char *f,int fl);
307int RSA_padding_check_none(unsigned char *to,int tlen,
308 const unsigned char *f,int fl,int rsa_len);
309int RSA_padding_add_X931(unsigned char *to,int tlen,
310 const unsigned char *f,int fl);
311int RSA_padding_check_X931(unsigned char *to,int tlen,
312 const unsigned char *f,int fl,int rsa_len);
313int RSA_X931_hash_id(int nid);
314
315int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
316 const EVP_MD *Hash, const unsigned char *EM, int sLen);
317int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
318 const unsigned char *mHash,
319 const EVP_MD *Hash, int sLen);
320
321int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
322 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
323int RSA_set_ex_data(RSA *r,int idx,void *arg);
324void *RSA_get_ex_data(const RSA *r, int idx);
325
326RSA *RSAPublicKey_dup(RSA *rsa);
327RSA *RSAPrivateKey_dup(RSA *rsa);
328
329/* BEGIN ERROR CODES */
330/* The following lines are auto generated by the script mkerr.pl. Any changes
331 * made after this point may be overwritten when the script is next run.
332 */
333void ERR_load_RSA_strings(void);
334
335/* Error codes for the RSA functions. */
336
337/* Function codes. */
338#define RSA_F_MEMORY_LOCK 100
339#define RSA_F_RSA_CHECK_KEY 123
340#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101
341#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102
342#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103
343#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104
344#define RSA_F_RSA_GENERATE_KEY 105
345#define RSA_F_RSA_NEW_METHOD 106
346#define RSA_F_RSA_NULL 124
347#define RSA_F_RSA_PADDING_ADD_NONE 107
348#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
349#define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125
350#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
351#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109
352#define RSA_F_RSA_PADDING_ADD_SSLV23 110
353#define RSA_F_RSA_PADDING_ADD_X931 127
354#define RSA_F_RSA_PADDING_CHECK_NONE 111
355#define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122
356#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112
357#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113
358#define RSA_F_RSA_PADDING_CHECK_SSLV23 114
359#define RSA_F_RSA_PADDING_CHECK_X931 128
360#define RSA_F_RSA_PRINT 115
361#define RSA_F_RSA_PRINT_FP 116
362#define RSA_F_RSA_SIGN 117
363#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
364#define RSA_F_RSA_VERIFY 119
365#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120
366#define RSA_F_RSA_VERIFY_PKCS1_PSS 126
367
368/* Reason codes. */
369#define RSA_R_ALGORITHM_MISMATCH 100
370#define RSA_R_BAD_E_VALUE 101
371#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
372#define RSA_R_BAD_PAD_BYTE_COUNT 103
373#define RSA_R_BAD_SIGNATURE 104
374#define RSA_R_BLOCK_TYPE_IS_NOT_01 106
375#define RSA_R_BLOCK_TYPE_IS_NOT_02 107
376#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
377#define RSA_R_DATA_TOO_LARGE 109
378#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
379#define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132
380#define RSA_R_DATA_TOO_SMALL 111
381#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
382#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
383#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
384#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
385#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
386#define RSA_R_FIRST_OCTET_INVALID 133
387#define RSA_R_INVALID_HEADER 137
388#define RSA_R_INVALID_MESSAGE_LENGTH 131
389#define RSA_R_INVALID_PADDING 138
390#define RSA_R_INVALID_TRAILER 139
391#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
392#define RSA_R_KEY_SIZE_TOO_SMALL 120
393#define RSA_R_LAST_OCTET_INVALID 134
394#define RSA_R_MODULUS_TOO_LARGE 105
395#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
396#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
397#define RSA_R_OAEP_DECODING_ERROR 121
398#define RSA_R_PADDING_CHECK_FAILED 114
399#define RSA_R_P_NOT_PRIME 128
400#define RSA_R_Q_NOT_PRIME 129
401#define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130
402#define RSA_R_SLEN_CHECK_FAILED 136
403#define RSA_R_SLEN_RECOVERY_FAILED 135
404#define RSA_R_SSLV3_ROLLBACK_ATTACK 115
405#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
406#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
407#define RSA_R_UNKNOWN_PADDING_TYPE 118
408#define RSA_R_WRONG_SIGNATURE_LENGTH 119
409
410#ifdef __cplusplus
411}
412#endif
413#endif
diff --git a/src/lib/libcrypto/rsa/rsa_asn1.c b/src/lib/libcrypto/rsa/rsa_asn1.c
deleted file mode 100644
index 1455a7e0e4..0000000000
--- a/src/lib/libcrypto/rsa/rsa_asn1.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/* rsa_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/asn1t.h>
64
65static ASN1_METHOD method={
66 (int (*)()) i2d_RSAPrivateKey,
67 (char *(*)())d2i_RSAPrivateKey,
68 (char *(*)())RSA_new,
69 (void (*)()) RSA_free};
70
71ASN1_METHOD *RSAPrivateKey_asn1_meth(void)
72 {
73 return(&method);
74 }
75
76/* Override the default free and new methods */
77static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
78{
79 if(operation == ASN1_OP_NEW_PRE) {
80 *pval = (ASN1_VALUE *)RSA_new();
81 if(*pval) return 2;
82 return 0;
83 } else if(operation == ASN1_OP_FREE_PRE) {
84 RSA_free((RSA *)*pval);
85 *pval = NULL;
86 return 2;
87 }
88 return 1;
89}
90
91ASN1_SEQUENCE_cb(RSAPrivateKey, rsa_cb) = {
92 ASN1_SIMPLE(RSA, version, LONG),
93 ASN1_SIMPLE(RSA, n, BIGNUM),
94 ASN1_SIMPLE(RSA, e, BIGNUM),
95 ASN1_SIMPLE(RSA, d, BIGNUM),
96 ASN1_SIMPLE(RSA, p, BIGNUM),
97 ASN1_SIMPLE(RSA, q, BIGNUM),
98 ASN1_SIMPLE(RSA, dmp1, BIGNUM),
99 ASN1_SIMPLE(RSA, dmq1, BIGNUM),
100 ASN1_SIMPLE(RSA, iqmp, BIGNUM)
101} ASN1_SEQUENCE_END_cb(RSA, RSAPrivateKey)
102
103
104ASN1_SEQUENCE_cb(RSAPublicKey, rsa_cb) = {
105 ASN1_SIMPLE(RSA, n, BIGNUM),
106 ASN1_SIMPLE(RSA, e, BIGNUM),
107} ASN1_SEQUENCE_END_cb(RSA, RSAPublicKey)
108
109IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPrivateKey, RSAPrivateKey)
110
111IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPublicKey, RSAPublicKey)
112
113RSA *RSAPublicKey_dup(RSA *rsa)
114 {
115 return ASN1_item_dup(ASN1_ITEM_rptr(RSAPublicKey), rsa);
116 }
117
118RSA *RSAPrivateKey_dup(RSA *rsa)
119 {
120 return ASN1_item_dup(ASN1_ITEM_rptr(RSAPrivateKey), rsa);
121 }
diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c
deleted file mode 100644
index 002f2cb487..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(const 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 610889dc80..0000000000
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ /dev/null
@@ -1,818 +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 * Copyright (c) 1998-2005 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 "cryptlib.h"
114#include <openssl/bn.h>
115#include <openssl/rsa.h>
116#include <openssl/rand.h>
117
118#if !defined(RSA_NULL) && !defined(OPENSSL_FIPS)
119
120static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
121 unsigned char *to, RSA *rsa,int padding);
122static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
123 unsigned char *to, RSA *rsa,int padding);
124static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
125 unsigned char *to, RSA *rsa,int padding);
126static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
127 unsigned char *to, RSA *rsa,int padding);
128static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa);
129static int RSA_eay_init(RSA *rsa);
130static int RSA_eay_finish(RSA *rsa);
131static RSA_METHOD rsa_pkcs1_eay_meth={
132 "Eric Young's PKCS#1 RSA",
133 RSA_eay_public_encrypt,
134 RSA_eay_public_decrypt, /* signature verification */
135 RSA_eay_private_encrypt, /* signing */
136 RSA_eay_private_decrypt,
137 RSA_eay_mod_exp,
138 BN_mod_exp_mont, /* XXX probably we should not use Montgomery if e == 3 */
139 RSA_eay_init,
140 RSA_eay_finish,
141 0, /* flags */
142 NULL,
143 0, /* rsa_sign */
144 0 /* rsa_verify */
145 };
146
147const RSA_METHOD *RSA_PKCS1_SSLeay(void)
148 {
149 return(&rsa_pkcs1_eay_meth);
150 }
151
152static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
153 unsigned char *to, RSA *rsa, int padding)
154 {
155 BIGNUM f,ret;
156 int i,j,k,num=0,r= -1;
157 unsigned char *buf=NULL;
158 BN_CTX *ctx=NULL;
159
160 BN_init(&f);
161 BN_init(&ret);
162 if ((ctx=BN_CTX_new()) == NULL) goto err;
163 num=BN_num_bytes(rsa->n);
164 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
165 {
166 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
167 goto err;
168 }
169
170 switch (padding)
171 {
172 case RSA_PKCS1_PADDING:
173 i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);
174 break;
175#ifndef OPENSSL_NO_SHA
176 case RSA_PKCS1_OAEP_PADDING:
177 i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);
178 break;
179#endif
180 case RSA_SSLV23_PADDING:
181 i=RSA_padding_add_SSLv23(buf,num,from,flen);
182 break;
183 case RSA_NO_PADDING:
184 i=RSA_padding_add_none(buf,num,from,flen);
185 break;
186 default:
187 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
188 goto err;
189 }
190 if (i <= 0) goto err;
191
192 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
193
194 if (BN_ucmp(&f, rsa->n) >= 0)
195 {
196 /* usually the padding functions would catch this */
197 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
198 goto err;
199 }
200
201 if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
202 {
203 if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
204 CRYPTO_LOCK_RSA, rsa->n, ctx))
205 goto err;
206 }
207
208 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
209 rsa->_method_mod_n)) goto err;
210
211 /* put in leading 0 bytes if the number is less than the
212 * length of the modulus */
213 j=BN_num_bytes(&ret);
214 i=BN_bn2bin(&ret,&(to[num-j]));
215 for (k=0; k<(num-i); k++)
216 to[k]=0;
217
218 r=num;
219err:
220 if (ctx != NULL) BN_CTX_free(ctx);
221 BN_clear_free(&f);
222 BN_clear_free(&ret);
223 if (buf != NULL)
224 {
225 OPENSSL_cleanse(buf,num);
226 OPENSSL_free(buf);
227 }
228 return(r);
229 }
230
231static int rsa_eay_blinding(RSA *rsa, BN_CTX *ctx)
232 {
233 int ret = 1;
234 CRYPTO_w_lock(CRYPTO_LOCK_RSA);
235 /* Check again inside the lock - the macro's check is racey */
236 if(rsa->blinding == NULL)
237 ret = RSA_blinding_on(rsa, ctx);
238 CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
239 return ret;
240 }
241
242#define BLINDING_HELPER(rsa, ctx, err_instr) \
243 do { \
244 if((!((rsa)->flags & RSA_FLAG_NO_BLINDING)) && \
245 ((rsa)->blinding == NULL) && \
246 !rsa_eay_blinding(rsa, ctx)) \
247 err_instr \
248 } while(0)
249
250static BN_BLINDING *setup_blinding(RSA *rsa, BN_CTX *ctx)
251 {
252 BIGNUM *A, *Ai;
253 BN_BLINDING *ret = NULL;
254
255 /* added in OpenSSL 0.9.6j and 0.9.7b */
256
257 /* NB: similar code appears in RSA_blinding_on (rsa_lib.c);
258 * this should be placed in a new function of its own, but for reasons
259 * of binary compatibility can't */
260
261 BN_CTX_start(ctx);
262 A = BN_CTX_get(ctx);
263 if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL)
264 {
265 /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */
266 RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0);
267 if (!BN_pseudo_rand_range(A,rsa->n)) goto err;
268 }
269 else
270 {
271 if (!BN_rand_range(A,rsa->n)) goto err;
272 }
273 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
274
275 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
276 goto err;
277 ret = BN_BLINDING_new(A,Ai,rsa->n);
278 BN_free(Ai);
279err:
280 BN_CTX_end(ctx);
281 return ret;
282 }
283
284/* signing */
285static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
286 unsigned char *to, RSA *rsa, int padding)
287 {
288 BIGNUM f,ret, *res;
289 int i,j,k,num=0,r= -1;
290 unsigned char *buf=NULL;
291 BN_CTX *ctx=NULL;
292 int local_blinding = 0;
293 BN_BLINDING *blinding = NULL;
294
295 BN_init(&f);
296 BN_init(&ret);
297
298 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
299 {
300 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);
301 return -1;
302 }
303
304 if (BN_ucmp(rsa->n, rsa->e) <= 0)
305 {
306 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
307 return -1;
308 }
309
310 /* for large moduli, enforce exponent limit */
311 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
312 {
313 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
314 {
315 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
316 return -1;
317 }
318 }
319
320 if ((ctx=BN_CTX_new()) == NULL) goto err;
321 num=BN_num_bytes(rsa->n);
322 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
323 {
324 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
325 goto err;
326 }
327
328 switch (padding)
329 {
330 case RSA_PKCS1_PADDING:
331 i=RSA_padding_add_PKCS1_type_1(buf,num,from,flen);
332 break;
333 case RSA_NO_PADDING:
334 i=RSA_padding_add_none(buf,num,from,flen);
335 break;
336 case RSA_SSLV23_PADDING:
337 default:
338 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
339 goto err;
340 }
341 if (i <= 0) goto err;
342
343 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
344
345 if (BN_ucmp(&f, rsa->n) >= 0)
346 {
347 /* usually the padding functions would catch this */
348 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
349 goto err;
350 }
351
352 BLINDING_HELPER(rsa, ctx, goto err;);
353 blinding = rsa->blinding;
354
355 /* Now unless blinding is disabled, 'blinding' is non-NULL.
356 * But the BN_BLINDING object may be owned by some other thread
357 * (we don't want to keep it constant and we don't want to use
358 * lots of locking to avoid race conditions, so only a single
359 * thread can use it; other threads have to use local blinding
360 * factors) */
361 if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
362 {
363 if (blinding == NULL)
364 {
365 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);
366 goto err;
367 }
368 }
369
370 if (blinding != NULL)
371 {
372 if (blinding->thread_id != CRYPTO_thread_id())
373 {
374 /* we need a local one-time blinding factor */
375
376 blinding = setup_blinding(rsa, ctx);
377 if (blinding == NULL)
378 goto err;
379 local_blinding = 1;
380 }
381 }
382
383 if (blinding)
384 if (!BN_BLINDING_convert(&f, blinding, ctx)) goto err;
385
386 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
387 ((rsa->p != NULL) &&
388 (rsa->q != NULL) &&
389 (rsa->dmp1 != NULL) &&
390 (rsa->dmq1 != NULL) &&
391 (rsa->iqmp != NULL)) )
392 {
393 if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err;
394 }
395 else
396 {
397 BIGNUM local_d;
398 BIGNUM *d = NULL;
399
400 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
401 {
402 BN_init(&local_d);
403 d = &local_d;
404 BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME);
405 }
406 else
407 d = rsa->d;
408 if (!rsa->meth->bn_mod_exp(&ret,&f,d,rsa->n,ctx,NULL)) goto err;
409 }
410
411 if (blinding)
412 if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err;
413
414 if (padding == RSA_X931_PADDING)
415 {
416 BN_sub(&f, rsa->n, &ret);
417 if (BN_cmp(&ret, &f))
418 res = &f;
419 else
420 res = &ret;
421 }
422 else
423 res = &ret;
424
425 /* put in leading 0 bytes if the number is less than the
426 * length of the modulus */
427 j=BN_num_bytes(res);
428 i=BN_bn2bin(res,&(to[num-j]));
429 for (k=0; k<(num-i); k++)
430 to[k]=0;
431
432 r=num;
433err:
434 if (ctx != NULL) BN_CTX_free(ctx);
435 BN_clear_free(&ret);
436 BN_clear_free(&f);
437 if (local_blinding)
438 BN_BLINDING_free(blinding);
439 if (buf != NULL)
440 {
441 OPENSSL_cleanse(buf,num);
442 OPENSSL_free(buf);
443 }
444 return(r);
445 }
446
447static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
448 unsigned char *to, RSA *rsa, int padding)
449 {
450 BIGNUM f,ret;
451 int j,num=0,r= -1;
452 unsigned char *p;
453 unsigned char *buf=NULL;
454 BN_CTX *ctx=NULL;
455 int local_blinding = 0;
456 BN_BLINDING *blinding = NULL;
457
458 BN_init(&f);
459 BN_init(&ret);
460 ctx=BN_CTX_new();
461 if (ctx == NULL) goto err;
462
463 num=BN_num_bytes(rsa->n);
464
465 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
466 {
467 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);
468 goto err;
469 }
470
471 /* This check was for equality but PGP does evil things
472 * and chops off the top '0' bytes */
473 if (flen > num)
474 {
475 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
476 goto err;
477 }
478
479 /* make data into a big number */
480 if (BN_bin2bn(from,(int)flen,&f) == NULL) goto err;
481
482 if (BN_ucmp(&f, rsa->n) >= 0)
483 {
484 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
485 goto err;
486 }
487
488 BLINDING_HELPER(rsa, ctx, goto err;);
489 blinding = rsa->blinding;
490
491 /* Now unless blinding is disabled, 'blinding' is non-NULL.
492 * But the BN_BLINDING object may be owned by some other thread
493 * (we don't want to keep it constant and we don't want to use
494 * lots of locking to avoid race conditions, so only a single
495 * thread can use it; other threads have to use local blinding
496 * factors) */
497 if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
498 {
499 if (blinding == NULL)
500 {
501 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);
502 goto err;
503 }
504 }
505
506 if (blinding != NULL)
507 {
508 if (blinding->thread_id != CRYPTO_thread_id())
509 {
510 /* we need a local one-time blinding factor */
511
512 blinding = setup_blinding(rsa, ctx);
513 if (blinding == NULL)
514 goto err;
515 local_blinding = 1;
516 }
517 }
518
519 if (blinding)
520 if (!BN_BLINDING_convert(&f, blinding, ctx)) goto err;
521
522 /* do the decrypt */
523 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
524 ((rsa->p != NULL) &&
525 (rsa->q != NULL) &&
526 (rsa->dmp1 != NULL) &&
527 (rsa->dmq1 != NULL) &&
528 (rsa->iqmp != NULL)) )
529 {
530 if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err;
531 }
532 else
533 {
534 BIGNUM local_d;
535 BIGNUM *d = NULL;
536
537 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
538 {
539 d = &local_d;
540 BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME);
541 }
542 else
543 d = rsa->d;
544 if (!rsa->meth->bn_mod_exp(&ret,&f,d,rsa->n,ctx,NULL))
545 goto err;
546 }
547
548 if (blinding)
549 if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err;
550
551 p=buf;
552 j=BN_bn2bin(&ret,p); /* j is only used with no-padding mode */
553
554 switch (padding)
555 {
556 case RSA_PKCS1_PADDING:
557 r=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);
558 break;
559#ifndef OPENSSL_NO_SHA
560 case RSA_PKCS1_OAEP_PADDING:
561 r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);
562 break;
563#endif
564 case RSA_SSLV23_PADDING:
565 r=RSA_padding_check_SSLv23(to,num,buf,j,num);
566 break;
567 case RSA_NO_PADDING:
568 r=RSA_padding_check_none(to,num,buf,j,num);
569 break;
570 default:
571 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
572 goto err;
573 }
574 if (r < 0)
575 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
576
577err:
578 if (ctx != NULL) BN_CTX_free(ctx);
579 BN_clear_free(&f);
580 BN_clear_free(&ret);
581 if (local_blinding)
582 BN_BLINDING_free(blinding);
583 if (buf != NULL)
584 {
585 OPENSSL_cleanse(buf,num);
586 OPENSSL_free(buf);
587 }
588 return(r);
589 }
590
591/* signature verification */
592static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
593 unsigned char *to, RSA *rsa, int padding)
594 {
595 BIGNUM f,ret;
596 int i,num=0,r= -1;
597 unsigned char *p;
598 unsigned char *buf=NULL;
599 BN_CTX *ctx=NULL;
600
601 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
602 {
603 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_MODULUS_TOO_LARGE);
604 return -1;
605 }
606
607 if (BN_ucmp(rsa->n, rsa->e) <= 0)
608 {
609 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);
610 return -1;
611 }
612
613 /* for large moduli, enforce exponent limit */
614 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
615 {
616 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
617 {
618 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);
619 return -1;
620 }
621 }
622
623 BN_init(&f);
624 BN_init(&ret);
625 ctx=BN_CTX_new();
626 if (ctx == NULL) goto err;
627
628 num=BN_num_bytes(rsa->n);
629 buf=(unsigned char *)OPENSSL_malloc(num);
630 if (buf == NULL)
631 {
632 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
633 goto err;
634 }
635
636 /* This check was for equality but PGP does evil things
637 * and chops off the top '0' bytes */
638 if (flen > num)
639 {
640 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
641 goto err;
642 }
643
644 if (BN_bin2bn(from,flen,&f) == NULL) goto err;
645
646 if (BN_ucmp(&f, rsa->n) >= 0)
647 {
648 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
649 goto err;
650 }
651
652 /* do the decrypt */
653
654 if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
655 {
656 if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
657 CRYPTO_LOCK_RSA, rsa->n, ctx))
658 goto err;
659 }
660
661 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
662 rsa->_method_mod_n)) goto err;
663
664 if ((padding == RSA_X931_PADDING) && ((ret.d[0] & 0xf) != 12))
665 BN_sub(&ret, rsa->n, &ret);
666
667 p=buf;
668 i=BN_bn2bin(&ret,p);
669
670 switch (padding)
671 {
672 case RSA_PKCS1_PADDING:
673 r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
674 break;
675 case RSA_NO_PADDING:
676 r=RSA_padding_check_none(to,num,buf,i,num);
677 break;
678 default:
679 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
680 goto err;
681 }
682 if (r < 0)
683 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
684
685err:
686 if (ctx != NULL) BN_CTX_free(ctx);
687 BN_clear_free(&f);
688 BN_clear_free(&ret);
689 if (buf != NULL)
690 {
691 OPENSSL_cleanse(buf,num);
692 OPENSSL_free(buf);
693 }
694 return(r);
695 }
696
697static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
698 {
699 BIGNUM r1,m1,vrfy;
700 BIGNUM local_dmp1, local_dmq1;
701 BIGNUM *dmp1, *dmq1;
702 int ret=0;
703 BN_CTX *ctx;
704
705 BN_init(&m1);
706 BN_init(&r1);
707 BN_init(&vrfy);
708 if ((ctx=BN_CTX_new()) == NULL) goto err;
709
710 if (rsa->flags & RSA_FLAG_CACHE_PRIVATE)
711 {
712 if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_p,
713 CRYPTO_LOCK_RSA, rsa->p, ctx))
714 goto err;
715 if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_q,
716 CRYPTO_LOCK_RSA, rsa->q, ctx))
717 goto err;
718 }
719
720 if (!BN_mod(&r1,I,rsa->q,ctx)) goto err;
721 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
722 {
723 dmq1 = &local_dmq1;
724 BN_with_flags(dmq1, rsa->dmq1, BN_FLG_EXP_CONSTTIME);
725 }
726 else
727 dmq1 = rsa->dmq1;
728 if (!rsa->meth->bn_mod_exp(&m1,&r1,dmq1,rsa->q,ctx,
729 rsa->_method_mod_q)) goto err;
730
731 if (!BN_mod(&r1,I,rsa->p,ctx)) goto err;
732 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
733 {
734 dmp1 = &local_dmp1;
735 BN_with_flags(dmp1, rsa->dmp1, BN_FLG_EXP_CONSTTIME);
736 }
737 else
738 dmp1 = rsa->dmp1;
739 if (!rsa->meth->bn_mod_exp(r0,&r1,dmp1,rsa->p,ctx,
740 rsa->_method_mod_p)) goto err;
741
742 if (!BN_sub(r0,r0,&m1)) goto err;
743 /* This will help stop the size of r0 increasing, which does
744 * affect the multiply if it optimised for a power of 2 size */
745 if (r0->neg)
746 if (!BN_add(r0,r0,rsa->p)) goto err;
747
748 if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;
749 if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;
750 /* If p < q it is occasionally possible for the correction of
751 * adding 'p' if r0 is negative above to leave the result still
752 * negative. This can break the private key operations: the following
753 * second correction should *always* correct this rare occurrence.
754 * This will *never* happen with OpenSSL generated keys because
755 * they ensure p > q [steve]
756 */
757 if (r0->neg)
758 if (!BN_add(r0,r0,rsa->p)) goto err;
759 if (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;
760 if (!BN_add(r0,&r1,&m1)) goto err;
761
762 if (rsa->e && rsa->n)
763 {
764 if (!rsa->meth->bn_mod_exp(&vrfy,r0,rsa->e,rsa->n,ctx,NULL)) goto err;
765 /* If 'I' was greater than (or equal to) rsa->n, the operation
766 * will be equivalent to using 'I mod n'. However, the result of
767 * the verify will *always* be less than 'n' so we don't check
768 * for absolute equality, just congruency. */
769 if (!BN_sub(&vrfy, &vrfy, I)) goto err;
770 if (!BN_mod(&vrfy, &vrfy, rsa->n, ctx)) goto err;
771 if (vrfy.neg)
772 if (!BN_add(&vrfy, &vrfy, rsa->n)) goto err;
773 if (!BN_is_zero(&vrfy))
774 {
775 /* 'I' and 'vrfy' aren't congruent mod n. Don't leak
776 * miscalculated CRT output, just do a raw (slower)
777 * mod_exp and return that instead. */
778
779 BIGNUM local_d;
780 BIGNUM *d = NULL;
781
782 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
783 {
784 d = &local_d;
785 BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME);
786 }
787 else
788 d = rsa->d;
789 if (!rsa->meth->bn_mod_exp(r0,I,d,rsa->n,ctx,NULL)) goto err;
790 }
791 }
792 ret=1;
793err:
794 BN_clear_free(&m1);
795 BN_clear_free(&r1);
796 BN_clear_free(&vrfy);
797 BN_CTX_free(ctx);
798 return(ret);
799 }
800
801static int RSA_eay_init(RSA *rsa)
802 {
803 rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
804 return(1);
805 }
806
807static int RSA_eay_finish(RSA *rsa)
808 {
809 if (rsa->_method_mod_n != NULL)
810 BN_MONT_CTX_free(rsa->_method_mod_n);
811 if (rsa->_method_mod_p != NULL)
812 BN_MONT_CTX_free(rsa->_method_mod_p);
813 if (rsa->_method_mod_q != NULL)
814 BN_MONT_CTX_free(rsa->_method_mod_q);
815 return(1);
816 }
817
818#endif
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c
deleted file mode 100644
index ddcb28e663..0000000000
--- a/src/lib/libcrypto/rsa/rsa_err.c
+++ /dev/null
@@ -1,165 +0,0 @@
1/* crypto/rsa/rsa_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_RSA,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_RSA,0,reason)
70
71static ERR_STRING_DATA RSA_str_functs[]=
72 {
73{ERR_FUNC(RSA_F_MEMORY_LOCK), "MEMORY_LOCK"},
74{ERR_FUNC(RSA_F_RSA_CHECK_KEY), "RSA_check_key"},
75{ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_DECRYPT), "RSA_EAY_PRIVATE_DECRYPT"},
76{ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_ENCRYPT), "RSA_EAY_PRIVATE_ENCRYPT"},
77{ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_DECRYPT), "RSA_EAY_PUBLIC_DECRYPT"},
78{ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_ENCRYPT), "RSA_EAY_PUBLIC_ENCRYPT"},
79{ERR_FUNC(RSA_F_RSA_GENERATE_KEY), "RSA_generate_key"},
80{ERR_FUNC(RSA_F_RSA_NEW_METHOD), "RSA_new_method"},
81{ERR_FUNC(RSA_F_RSA_NULL), "RSA_NULL"},
82{ERR_FUNC(RSA_F_RSA_PADDING_ADD_NONE), "RSA_padding_add_none"},
83{ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP), "RSA_padding_add_PKCS1_OAEP"},
84{ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_PSS), "RSA_padding_add_PKCS1_PSS"},
85{ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1), "RSA_padding_add_PKCS1_type_1"},
86{ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2), "RSA_padding_add_PKCS1_type_2"},
87{ERR_FUNC(RSA_F_RSA_PADDING_ADD_SSLV23), "RSA_padding_add_SSLv23"},
88{ERR_FUNC(RSA_F_RSA_PADDING_ADD_X931), "RSA_padding_add_X931"},
89{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_NONE), "RSA_padding_check_none"},
90{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP), "RSA_padding_check_PKCS1_OAEP"},
91{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1), "RSA_padding_check_PKCS1_type_1"},
92{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2), "RSA_padding_check_PKCS1_type_2"},
93{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_SSLV23), "RSA_padding_check_SSLv23"},
94{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_X931), "RSA_padding_check_X931"},
95{ERR_FUNC(RSA_F_RSA_PRINT), "RSA_print"},
96{ERR_FUNC(RSA_F_RSA_PRINT_FP), "RSA_print_fp"},
97{ERR_FUNC(RSA_F_RSA_SIGN), "RSA_sign"},
98{ERR_FUNC(RSA_F_RSA_SIGN_ASN1_OCTET_STRING), "RSA_sign_ASN1_OCTET_STRING"},
99{ERR_FUNC(RSA_F_RSA_VERIFY), "RSA_verify"},
100{ERR_FUNC(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING), "RSA_verify_ASN1_OCTET_STRING"},
101{ERR_FUNC(RSA_F_RSA_VERIFY_PKCS1_PSS), "RSA_verify_PKCS1_PSS"},
102{0,NULL}
103 };
104
105static ERR_STRING_DATA RSA_str_reasons[]=
106 {
107{ERR_REASON(RSA_R_ALGORITHM_MISMATCH) ,"algorithm mismatch"},
108{ERR_REASON(RSA_R_BAD_E_VALUE) ,"bad e value"},
109{ERR_REASON(RSA_R_BAD_FIXED_HEADER_DECRYPT),"bad fixed header decrypt"},
110{ERR_REASON(RSA_R_BAD_PAD_BYTE_COUNT) ,"bad pad byte count"},
111{ERR_REASON(RSA_R_BAD_SIGNATURE) ,"bad signature"},
112{ERR_REASON(RSA_R_BLOCK_TYPE_IS_NOT_01) ,"block type is not 01"},
113{ERR_REASON(RSA_R_BLOCK_TYPE_IS_NOT_02) ,"block type is not 02"},
114{ERR_REASON(RSA_R_DATA_GREATER_THAN_MOD_LEN),"data greater than mod len"},
115{ERR_REASON(RSA_R_DATA_TOO_LARGE) ,"data too large"},
116{ERR_REASON(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"},
117{ERR_REASON(RSA_R_DATA_TOO_LARGE_FOR_MODULUS),"data too large for modulus"},
118{ERR_REASON(RSA_R_DATA_TOO_SMALL) ,"data too small"},
119{ERR_REASON(RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE),"data too small for key size"},
120{ERR_REASON(RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY),"digest too big for rsa key"},
121{ERR_REASON(RSA_R_DMP1_NOT_CONGRUENT_TO_D),"dmp1 not congruent to d"},
122{ERR_REASON(RSA_R_DMQ1_NOT_CONGRUENT_TO_D),"dmq1 not congruent to d"},
123{ERR_REASON(RSA_R_D_E_NOT_CONGRUENT_TO_1),"d e not congruent to 1"},
124{ERR_REASON(RSA_R_FIRST_OCTET_INVALID) ,"first octet invalid"},
125{ERR_REASON(RSA_R_INVALID_HEADER) ,"invalid header"},
126{ERR_REASON(RSA_R_INVALID_MESSAGE_LENGTH),"invalid message length"},
127{ERR_REASON(RSA_R_INVALID_PADDING) ,"invalid padding"},
128{ERR_REASON(RSA_R_INVALID_TRAILER) ,"invalid trailer"},
129{ERR_REASON(RSA_R_IQMP_NOT_INVERSE_OF_Q) ,"iqmp not inverse of q"},
130{ERR_REASON(RSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"},
131{ERR_REASON(RSA_R_LAST_OCTET_INVALID) ,"last octet invalid"},
132{ERR_REASON(RSA_R_MODULUS_TOO_LARGE) ,"modulus too large"},
133{ERR_REASON(RSA_R_NULL_BEFORE_BLOCK_MISSING),"null before block missing"},
134{ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q) ,"n does not equal p q"},
135{ERR_REASON(RSA_R_OAEP_DECODING_ERROR) ,"oaep decoding error"},
136{ERR_REASON(RSA_R_SLEN_RECOVERY_FAILED) ,"salt length recovery failed"},
137{ERR_REASON(RSA_R_PADDING_CHECK_FAILED) ,"padding check failed"},
138{ERR_REASON(RSA_R_P_NOT_PRIME) ,"p not prime"},
139{ERR_REASON(RSA_R_Q_NOT_PRIME) ,"q not prime"},
140{ERR_REASON(RSA_R_RSA_OPERATIONS_NOT_SUPPORTED),"rsa operations not supported"},
141{ERR_REASON(RSA_R_SSLV3_ROLLBACK_ATTACK) ,"sslv3 rollback attack"},
142{ERR_REASON(RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"},
143{ERR_REASON(RSA_R_UNKNOWN_ALGORITHM_TYPE),"unknown algorithm type"},
144{ERR_REASON(RSA_R_UNKNOWN_PADDING_TYPE) ,"unknown padding type"},
145{ERR_REASON(RSA_R_WRONG_SIGNATURE_LENGTH),"wrong signature length"},
146{ERR_REASON(RSA_R_SLEN_CHECK_FAILED) ,"salt length check failed"},
147{0,NULL}
148 };
149
150#endif
151
152void ERR_load_RSA_strings(void)
153 {
154 static int init=1;
155
156 if (init)
157 {
158 init=0;
159#ifndef OPENSSL_NO_ERR
160 ERR_load_strings(0,RSA_str_functs);
161 ERR_load_strings(0,RSA_str_reasons);
162#endif
163
164 }
165 }
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
deleted file mode 100644
index dd1422cc98..0000000000
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ /dev/null
@@ -1,201 +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
65#ifndef OPENSSL_FIPS
66
67RSA *RSA_generate_key(int bits, unsigned long e_value,
68 void (*callback)(int,int,void *), void *cb_arg)
69 {
70 RSA *rsa=NULL;
71 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;
72 int bitsp,bitsq,ok= -1,n=0,i;
73 BN_CTX *ctx=NULL,*ctx2=NULL;
74
75 ctx=BN_CTX_new();
76 if (ctx == NULL) goto err;
77 ctx2=BN_CTX_new();
78 if (ctx2 == NULL) goto err;
79 BN_CTX_start(ctx);
80 r0 = BN_CTX_get(ctx);
81 r1 = BN_CTX_get(ctx);
82 r2 = BN_CTX_get(ctx);
83 r3 = BN_CTX_get(ctx);
84 if (r3 == NULL) goto err;
85
86 bitsp=(bits+1)/2;
87 bitsq=bits-bitsp;
88 rsa=RSA_new();
89 if (rsa == NULL) goto err;
90
91 /* set e */
92 rsa->e=BN_new();
93 if (rsa->e == NULL) goto err;
94
95#if 1
96 /* The problem is when building with 8, 16, or 32 BN_ULONG,
97 * unsigned long can be larger */
98 for (i=0; i<sizeof(unsigned long)*8; i++)
99 {
100 if (e_value & (1UL<<i))
101 BN_set_bit(rsa->e,i);
102 }
103#else
104 if (!BN_set_word(rsa->e,e_value)) goto err;
105#endif
106
107 /* generate p and q */
108 for (;;)
109 {
110 rsa->p=BN_generate_prime(NULL,bitsp,0,NULL,NULL,callback,cb_arg);
111 if (rsa->p == NULL) goto err;
112 if (!BN_sub(r2,rsa->p,BN_value_one())) goto err;
113 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
114 if (BN_is_one(r1)) break;
115 if (callback != NULL) callback(2,n++,cb_arg);
116 BN_free(rsa->p);
117 }
118 if (callback != NULL) callback(3,0,cb_arg);
119 for (;;)
120 {
121 rsa->q=BN_generate_prime(NULL,bitsq,0,NULL,NULL,callback,cb_arg);
122 if (rsa->q == NULL) goto err;
123 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err;
124 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
125 if (BN_is_one(r1) && (BN_cmp(rsa->p,rsa->q) != 0))
126 break;
127 if (callback != NULL) callback(2,n++,cb_arg);
128 BN_free(rsa->q);
129 }
130 if (callback != NULL) callback(3,1,cb_arg);
131 if (BN_cmp(rsa->p,rsa->q) < 0)
132 {
133 tmp=rsa->p;
134 rsa->p=rsa->q;
135 rsa->q=tmp;
136 }
137
138 /* calculate n */
139 rsa->n=BN_new();
140 if (rsa->n == NULL) goto err;
141 if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err;
142
143 /* calculate d */
144 if (!BN_sub(r1,rsa->p,BN_value_one())) goto err; /* p-1 */
145 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; /* q-1 */
146 if (!BN_mul(r0,r1,r2,ctx)) goto err; /* (p-1)(q-1) */
147
148/* should not be needed, since gcd(p-1,e) == 1 and gcd(q-1,e) == 1 */
149/* for (;;)
150 {
151 if (!BN_gcd(r3,r0,rsa->e,ctx)) goto err;
152 if (BN_is_one(r3)) break;
153
154 if (1)
155 {
156 if (!BN_add_word(rsa->e,2L)) goto err;
157 continue;
158 }
159 RSAerr(RSA_F_RSA_GENERATE_KEY,RSA_R_BAD_E_VALUE);
160 goto err;
161 }
162*/
163 rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2); /* d */
164 if (rsa->d == NULL) goto err;
165
166 /* calculate d mod (p-1) */
167 rsa->dmp1=BN_new();
168 if (rsa->dmp1 == NULL) goto err;
169 if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx)) goto err;
170
171 /* calculate d mod (q-1) */
172 rsa->dmq1=BN_new();
173 if (rsa->dmq1 == NULL) goto err;
174 if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx)) goto err;
175
176 /* calculate inverse of q mod p */
177 rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);
178 if (rsa->iqmp == NULL) goto err;
179
180 ok=1;
181err:
182 if (ok == -1)
183 {
184 RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
185 ok=0;
186 }
187 if (ctx != NULL)
188 BN_CTX_end(ctx);
189 BN_CTX_free(ctx);
190 BN_CTX_free(ctx2);
191
192 if (!ok)
193 {
194 if (rsa != NULL) RSA_free(rsa);
195 return(NULL);
196 }
197 else
198 return(rsa);
199 }
200
201#endif
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
deleted file mode 100644
index e4d622851e..0000000000
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ /dev/null
@@ -1,414 +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#include <openssl/rand.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT;
71
72static const RSA_METHOD *default_RSA_meth=NULL;
73
74RSA *RSA_new(void)
75 {
76 RSA *r=RSA_new_method(NULL);
77
78 return r;
79 }
80
81void RSA_set_default_method(const RSA_METHOD *meth)
82 {
83 default_RSA_meth = meth;
84 }
85
86const RSA_METHOD *RSA_get_default_method(void)
87 {
88 if (default_RSA_meth == NULL)
89 {
90#ifdef RSA_NULL
91 default_RSA_meth=RSA_null_method();
92#else
93#if 0 /* was: #ifdef RSAref */
94 default_RSA_meth=RSA_PKCS1_RSAref();
95#else
96 default_RSA_meth=RSA_PKCS1_SSLeay();
97#endif
98#endif
99 }
100
101 return default_RSA_meth;
102 }
103
104const RSA_METHOD *RSA_get_method(const RSA *rsa)
105 {
106 return rsa->meth;
107 }
108
109int RSA_set_method(RSA *rsa, const RSA_METHOD *meth)
110 {
111 /* NB: The caller is specifically setting a method, so it's not up to us
112 * to deal with which ENGINE it comes from. */
113 const RSA_METHOD *mtmp;
114 mtmp = rsa->meth;
115 if (mtmp->finish) mtmp->finish(rsa);
116#ifndef OPENSSL_NO_ENGINE
117 if (rsa->engine)
118 {
119 ENGINE_finish(rsa->engine);
120 rsa->engine = NULL;
121 }
122#endif
123 rsa->meth = meth;
124 if (meth->init) meth->init(rsa);
125 return 1;
126 }
127
128RSA *RSA_new_method(ENGINE *engine)
129 {
130 RSA *ret;
131
132 ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
133 if (ret == NULL)
134 {
135 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
136 return NULL;
137 }
138
139 ret->meth = RSA_get_default_method();
140#ifndef OPENSSL_NO_ENGINE
141 if (engine)
142 {
143 if (!ENGINE_init(engine))
144 {
145 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);
146 OPENSSL_free(ret);
147 return NULL;
148 }
149 ret->engine = engine;
150 }
151 else
152 ret->engine = ENGINE_get_default_RSA();
153 if(ret->engine)
154 {
155 ret->meth = ENGINE_get_RSA(ret->engine);
156 if(!ret->meth)
157 {
158 RSAerr(RSA_F_RSA_NEW_METHOD,
159 ERR_R_ENGINE_LIB);
160 ENGINE_finish(ret->engine);
161 OPENSSL_free(ret);
162 return NULL;
163 }
164 }
165#endif
166
167 ret->pad=0;
168 ret->version=0;
169 ret->n=NULL;
170 ret->e=NULL;
171 ret->d=NULL;
172 ret->p=NULL;
173 ret->q=NULL;
174 ret->dmp1=NULL;
175 ret->dmq1=NULL;
176 ret->iqmp=NULL;
177 ret->references=1;
178 ret->_method_mod_n=NULL;
179 ret->_method_mod_p=NULL;
180 ret->_method_mod_q=NULL;
181 ret->blinding=NULL;
182 ret->bignum_data=NULL;
183 ret->flags=ret->meth->flags;
184 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
185 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
186 {
187#ifndef OPENSSL_NO_ENGINE
188 if (ret->engine)
189 ENGINE_finish(ret->engine);
190#endif
191 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
192 OPENSSL_free(ret);
193 ret=NULL;
194 }
195 return(ret);
196 }
197
198void RSA_free(RSA *r)
199 {
200 int i;
201
202 if (r == NULL) return;
203
204 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
205#ifdef REF_PRINT
206 REF_PRINT("RSA",r);
207#endif
208 if (i > 0) return;
209#ifdef REF_CHECK
210 if (i < 0)
211 {
212 fprintf(stderr,"RSA_free, bad reference count\n");
213 abort();
214 }
215#endif
216
217 if (r->meth->finish)
218 r->meth->finish(r);
219#ifndef OPENSSL_NO_ENGINE
220 if (r->engine)
221 ENGINE_finish(r->engine);
222#endif
223
224 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
225
226 if (r->n != NULL) BN_clear_free(r->n);
227 if (r->e != NULL) BN_clear_free(r->e);
228 if (r->d != NULL) BN_clear_free(r->d);
229 if (r->p != NULL) BN_clear_free(r->p);
230 if (r->q != NULL) BN_clear_free(r->q);
231 if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
232 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
233 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
234 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
235 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
236 OPENSSL_free(r);
237 }
238
239int RSA_up_ref(RSA *r)
240 {
241 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
242#ifdef REF_PRINT
243 REF_PRINT("RSA",r);
244#endif
245#ifdef REF_CHECK
246 if (i < 2)
247 {
248 fprintf(stderr, "RSA_up_ref, bad reference count\n");
249 abort();
250 }
251#endif
252 return ((i > 1) ? 1 : 0);
253 }
254
255int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
256 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
257 {
258 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, argl, argp,
259 new_func, dup_func, free_func);
260 }
261
262int RSA_set_ex_data(RSA *r, int idx, void *arg)
263 {
264 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
265 }
266
267void *RSA_get_ex_data(const RSA *r, int idx)
268 {
269 return(CRYPTO_get_ex_data(&r->ex_data,idx));
270 }
271
272int RSA_size(const RSA *r)
273 {
274 return(BN_num_bytes(r->n));
275 }
276
277int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
278 RSA *rsa, int padding)
279 {
280 return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding));
281 }
282
283int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
284 RSA *rsa, int padding)
285 {
286 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding));
287 }
288
289int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
290 RSA *rsa, int padding)
291 {
292 return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding));
293 }
294
295int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
296 RSA *rsa, int padding)
297 {
298 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));
299 }
300
301int RSA_flags(const RSA *r)
302 {
303 return((r == NULL)?0:r->meth->flags);
304 }
305
306void RSA_blinding_off(RSA *rsa)
307 {
308 if (rsa->blinding != NULL)
309 {
310 BN_BLINDING_free(rsa->blinding);
311 rsa->blinding=NULL;
312 }
313 rsa->flags &= ~RSA_FLAG_BLINDING;
314 rsa->flags |= RSA_FLAG_NO_BLINDING;
315 }
316
317int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
318 {
319 BIGNUM *A,*Ai = NULL;
320 BN_CTX *ctx;
321 int ret=0;
322
323 if (p_ctx == NULL)
324 {
325 if ((ctx=BN_CTX_new()) == NULL) goto err;
326 }
327 else
328 ctx=p_ctx;
329
330 /* XXXXX: Shouldn't this be RSA_blinding_off(rsa)? */
331 if (rsa->blinding != NULL)
332 {
333 BN_BLINDING_free(rsa->blinding);
334 rsa->blinding = NULL;
335 }
336
337 /* NB: similar code appears in setup_blinding (rsa_eay.c);
338 * this should be placed in a new function of its own, but for reasons
339 * of binary compatibility can't */
340
341 BN_CTX_start(ctx);
342 A = BN_CTX_get(ctx);
343 if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL)
344 {
345 /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */
346 RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0);
347 if (!BN_pseudo_rand_range(A,rsa->n)) goto err;
348 }
349 else
350 {
351 if (!BN_rand_range(A,rsa->n)) goto err;
352 }
353 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
354
355 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
356 goto err;
357 if ((rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n)) == NULL) goto err;
358 /* to make things thread-safe without excessive locking,
359 * rsa->blinding will be used just by the current thread: */
360 rsa->blinding->thread_id = CRYPTO_thread_id();
361 rsa->flags |= RSA_FLAG_BLINDING;
362 rsa->flags &= ~RSA_FLAG_NO_BLINDING;
363 ret=1;
364err:
365 if (Ai != NULL) BN_free(Ai);
366 BN_CTX_end(ctx);
367 if (ctx != p_ctx) BN_CTX_free(ctx);
368 return(ret);
369 }
370
371int RSA_memory_lock(RSA *r)
372 {
373 int i,j,k,off;
374 char *p;
375 BIGNUM *bn,**t[6],*b;
376 BN_ULONG *ul;
377
378 if (r->d == NULL) return(1);
379 t[0]= &r->d;
380 t[1]= &r->p;
381 t[2]= &r->q;
382 t[3]= &r->dmp1;
383 t[4]= &r->dmq1;
384 t[5]= &r->iqmp;
385 k=sizeof(BIGNUM)*6;
386 off=k/sizeof(BN_ULONG)+1;
387 j=1;
388 for (i=0; i<6; i++)
389 j+= (*t[i])->top;
390 if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
391 {
392 RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
393 return(0);
394 }
395 bn=(BIGNUM *)p;
396 ul=(BN_ULONG *)&(p[off]);
397 for (i=0; i<6; i++)
398 {
399 b= *(t[i]);
400 *(t[i])= &(bn[i]);
401 memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
402 bn[i].flags=BN_FLG_STATIC_DATA;
403 bn[i].d=ul;
404 memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
405 ul+=b->top;
406 BN_clear_free(b);
407 }
408
409 /* I should fix this so it can still be done */
410 r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
411
412 r->bignum_data=p;
413 return(1);
414 }
diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c
deleted file mode 100644
index e6f3e627ca..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,
66 const unsigned char *from, 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,
85 const unsigned char *from, 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 d43ecaca63..0000000000
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ /dev/null
@@ -1,212 +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/* See Victor Shoup, "OAEP reconsidered," Nov. 2000,
8 * <URL: http://www.shoup.net/papers/oaep.ps.Z>
9 * for problems with the security proof for the
10 * original OAEP scheme, which EME-OAEP is based on.
11 *
12 * A new proof can be found in E. Fujisaki, T. Okamoto,
13 * D. Pointcheval, J. Stern, "RSA-OEAP is Still Alive!",
14 * Dec. 2000, <URL: http://eprint.iacr.org/2000/061/>.
15 * The new proof has stronger requirements for the
16 * underlying permutation: "partial-one-wayness" instead
17 * of one-wayness. For the RSA function, this is
18 * an equivalent notion.
19 */
20
21
22#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
23#include <stdio.h>
24#include "cryptlib.h"
25#include <openssl/bn.h>
26#include <openssl/rsa.h>
27#include <openssl/evp.h>
28#include <openssl/rand.h>
29#include <openssl/sha.h>
30
31int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
32 const unsigned char *from, int flen,
33 const unsigned char *param, int plen)
34 {
35 int i, emlen = tlen - 1;
36 unsigned char *db, *seed;
37 unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH];
38
39 if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1)
40 {
41 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,
42 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
43 return 0;
44 }
45
46 if (emlen < 2 * SHA_DIGEST_LENGTH + 1)
47 {
48 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL);
49 return 0;
50 }
51
52 dbmask = OPENSSL_malloc(emlen - SHA_DIGEST_LENGTH);
53 if (dbmask == NULL)
54 {
55 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
56 return 0;
57 }
58
59 to[0] = 0;
60 seed = to + 1;
61 db = to + SHA_DIGEST_LENGTH + 1;
62
63 EVP_Digest((void *)param, plen, db, NULL, EVP_sha1(), NULL);
64 memset(db + SHA_DIGEST_LENGTH, 0,
65 emlen - flen - 2 * SHA_DIGEST_LENGTH - 1);
66 db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01;
67 memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen);
68 if (RAND_bytes(seed, SHA_DIGEST_LENGTH) <= 0)
69 return 0;
70#ifdef PKCS_TESTVECT
71 memcpy(seed,
72 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f",
73 20);
74#endif
75
76 PKCS1_MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH,
77 EVP_sha1());
78 for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)
79 db[i] ^= dbmask[i];
80
81 PKCS1_MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH,
82 EVP_sha1());
83 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
84 seed[i] ^= seedmask[i];
85
86 OPENSSL_free(dbmask);
87 return 1;
88 }
89
90int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
91 const unsigned char *from, int flen, int num,
92 const unsigned char *param, int plen)
93 {
94 int i, dblen, mlen = -1;
95 const unsigned char *maskeddb;
96 int lzero;
97 unsigned char *db = NULL, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH];
98 int bad = 0;
99
100 if (--num < 2 * SHA_DIGEST_LENGTH + 1)
101 /* 'num' is the length of the modulus, i.e. does not depend on the
102 * particular ciphertext. */
103 goto decoding_err;
104
105 lzero = num - flen;
106 if (lzero < 0)
107 {
108 /* lzero == -1 */
109
110 /* signalling this error immediately after detection might allow
111 * for side-channel attacks (e.g. timing if 'plen' is huge
112 * -- cf. James H. Manger, "A Chosen Ciphertext Attack on RSA Optimal
113 * Asymmetric Encryption Padding (OAEP) [...]", CRYPTO 2001),
114 * so we use a 'bad' flag */
115 bad = 1;
116 lzero = 0;
117 }
118 maskeddb = from - lzero + SHA_DIGEST_LENGTH;
119
120 dblen = num - SHA_DIGEST_LENGTH;
121 db = OPENSSL_malloc(dblen);
122 if (db == NULL)
123 {
124 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
125 return -1;
126 }
127
128 PKCS1_MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen, EVP_sha1());
129 for (i = lzero; i < SHA_DIGEST_LENGTH; i++)
130 seed[i] ^= from[i - lzero];
131
132 PKCS1_MGF1(db, dblen, seed, SHA_DIGEST_LENGTH, EVP_sha1());
133 for (i = 0; i < dblen; i++)
134 db[i] ^= maskeddb[i];
135
136 EVP_Digest((void *)param, plen, phash, NULL, EVP_sha1(), NULL);
137
138 if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0 || bad)
139 goto decoding_err;
140 else
141 {
142 for (i = SHA_DIGEST_LENGTH; i < dblen; i++)
143 if (db[i] != 0x00)
144 break;
145 if (db[i] != 0x01 || i++ >= dblen)
146 goto decoding_err;
147 else
148 {
149 /* everything looks OK */
150
151 mlen = dblen - i;
152 if (tlen < mlen)
153 {
154 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE);
155 mlen = -1;
156 }
157 else
158 memcpy(to, db + i, mlen);
159 }
160 }
161 OPENSSL_free(db);
162 return mlen;
163
164decoding_err:
165 /* to avoid chosen ciphertext attacks, the error message should not reveal
166 * which kind of decoding error happened */
167 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
168 if (db != NULL) OPENSSL_free(db);
169 return -1;
170 }
171
172int PKCS1_MGF1(unsigned char *mask, long len,
173 const unsigned char *seed, long seedlen, const EVP_MD *dgst)
174 {
175 long i, outlen = 0;
176 unsigned char cnt[4];
177 EVP_MD_CTX c;
178 unsigned char md[EVP_MAX_MD_SIZE];
179 int mdlen;
180
181 EVP_MD_CTX_init(&c);
182 mdlen = EVP_MD_size(dgst);
183 for (i = 0; outlen < len; i++)
184 {
185 cnt[0] = (unsigned char)((i >> 24) & 255);
186 cnt[1] = (unsigned char)((i >> 16) & 255);
187 cnt[2] = (unsigned char)((i >> 8)) & 255;
188 cnt[3] = (unsigned char)(i & 255);
189 EVP_DigestInit_ex(&c,dgst, NULL);
190 EVP_DigestUpdate(&c, seed, seedlen);
191 EVP_DigestUpdate(&c, cnt, 4);
192 if (outlen + mdlen <= len)
193 {
194 EVP_DigestFinal_ex(&c, mask + outlen, NULL);
195 outlen += mdlen;
196 }
197 else
198 {
199 EVP_DigestFinal_ex(&c, md, NULL);
200 memcpy(mask + outlen, md, len - outlen);
201 outlen = len;
202 }
203 }
204 EVP_MD_CTX_cleanup(&c);
205 return 0;
206 }
207
208int MGF1(unsigned char *mask, long len, const unsigned char *seed, long seedlen)
209 {
210 return PKCS1_MGF1(mask, len, seed, seedlen, EVP_sha1());
211 }
212#endif
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c
deleted file mode 100644
index 8560755f1d..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 const unsigned char *from, int flen)
67 {
68 int j;
69 unsigned char *p;
70
71 if (flen > (tlen-RSA_PKCS1_PADDING_SIZE))
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 const unsigned char *from, int flen, int num)
93 {
94 int i,j;
95 const 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 const 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 const unsigned char *from, int flen, int num)
183 {
184 int i,j;
185 const 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_pss.c b/src/lib/libcrypto/rsa/rsa_pss.c
deleted file mode 100644
index 2815628f5f..0000000000
--- a/src/lib/libcrypto/rsa/rsa_pss.c
+++ /dev/null
@@ -1,261 +0,0 @@
1/* rsa_pss.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2005.
4 */
5/* ====================================================================
6 * Copyright (c) 2005 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/sha.h>
66
67const static unsigned char zeroes[] = {0,0,0,0,0,0,0,0};
68
69int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
70 const EVP_MD *Hash, const unsigned char *EM, int sLen)
71 {
72 int i;
73 int ret = 0;
74 int hLen, maskedDBLen, MSBits, emLen;
75 const unsigned char *H;
76 unsigned char *DB = NULL;
77 EVP_MD_CTX ctx;
78 unsigned char H_[EVP_MAX_MD_SIZE];
79
80 hLen = EVP_MD_size(Hash);
81 /*
82 * Negative sLen has special meanings:
83 * -1 sLen == hLen
84 * -2 salt length is autorecovered from signature
85 * -N reserved
86 */
87 if (sLen == -1) sLen = hLen;
88 else if (sLen == -2) sLen = -2;
89 else if (sLen < -2)
90 {
91 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, RSA_R_SLEN_CHECK_FAILED);
92 goto err;
93 }
94
95 MSBits = (BN_num_bits(rsa->n) - 1) & 0x7;
96 emLen = RSA_size(rsa);
97 if (EM[0] & (0xFF << MSBits))
98 {
99 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, RSA_R_FIRST_OCTET_INVALID);
100 goto err;
101 }
102 if (MSBits == 0)
103 {
104 EM++;
105 emLen--;
106 }
107 if (emLen < (hLen + sLen + 2)) /* sLen can be small negative */
108 {
109 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, RSA_R_DATA_TOO_LARGE);
110 goto err;
111 }
112 if (EM[emLen - 1] != 0xbc)
113 {
114 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, RSA_R_LAST_OCTET_INVALID);
115 goto err;
116 }
117 maskedDBLen = emLen - hLen - 1;
118 H = EM + maskedDBLen;
119 DB = OPENSSL_malloc(maskedDBLen);
120 if (!DB)
121 {
122 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, ERR_R_MALLOC_FAILURE);
123 goto err;
124 }
125 PKCS1_MGF1(DB, maskedDBLen, H, hLen, Hash);
126 for (i = 0; i < maskedDBLen; i++)
127 DB[i] ^= EM[i];
128 if (MSBits)
129 DB[0] &= 0xFF >> (8 - MSBits);
130 for (i = 0; DB[i] == 0 && i < (maskedDBLen-1); i++) ;
131 if (DB[i++] != 0x1)
132 {
133 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, RSA_R_SLEN_RECOVERY_FAILED);
134 goto err;
135 }
136 if (sLen >= 0 && (maskedDBLen - i) != sLen)
137 {
138 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, RSA_R_SLEN_CHECK_FAILED);
139 goto err;
140 }
141 EVP_MD_CTX_init(&ctx);
142 EVP_DigestInit_ex(&ctx, Hash, NULL);
143 EVP_DigestUpdate(&ctx, zeroes, sizeof zeroes);
144 EVP_DigestUpdate(&ctx, mHash, hLen);
145 if (maskedDBLen - i)
146 EVP_DigestUpdate(&ctx, DB + i, maskedDBLen - i);
147 EVP_DigestFinal(&ctx, H_, NULL);
148 EVP_MD_CTX_cleanup(&ctx);
149 if (memcmp(H_, H, hLen))
150 {
151 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS, RSA_R_BAD_SIGNATURE);
152 ret = 0;
153 }
154 else
155 ret = 1;
156
157 err:
158 if (DB)
159 OPENSSL_free(DB);
160
161 return ret;
162
163 }
164
165int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
166 const unsigned char *mHash,
167 const EVP_MD *Hash, int sLen)
168 {
169 int i;
170 int ret = 0;
171 int hLen, maskedDBLen, MSBits, emLen;
172 unsigned char *H, *salt = NULL, *p;
173 EVP_MD_CTX ctx;
174
175 hLen = EVP_MD_size(Hash);
176 /*
177 * Negative sLen has special meanings:
178 * -1 sLen == hLen
179 * -2 salt length is maximized
180 * -N reserved
181 */
182 if (sLen == -1) sLen = hLen;
183 else if (sLen == -2) sLen = -2;
184 else if (sLen < -2)
185 {
186 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS, RSA_R_SLEN_CHECK_FAILED);
187 goto err;
188 }
189
190 MSBits = (BN_num_bits(rsa->n) - 1) & 0x7;
191 emLen = RSA_size(rsa);
192 if (MSBits == 0)
193 {
194 *EM++ = 0;
195 emLen--;
196 }
197 if (sLen == -2)
198 {
199 sLen = emLen - hLen - 2;
200 }
201 else if (emLen < (hLen + sLen + 2))
202 {
203 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS,
204 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
205 goto err;
206 }
207 if (sLen > 0)
208 {
209 salt = OPENSSL_malloc(sLen);
210 if (!salt)
211 {
212 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS,
213 ERR_R_MALLOC_FAILURE);
214 goto err;
215 }
216 if (!RAND_bytes(salt, sLen))
217 goto err;
218 }
219 maskedDBLen = emLen - hLen - 1;
220 H = EM + maskedDBLen;
221 EVP_MD_CTX_init(&ctx);
222 EVP_DigestInit_ex(&ctx, Hash, NULL);
223 EVP_DigestUpdate(&ctx, zeroes, sizeof zeroes);
224 EVP_DigestUpdate(&ctx, mHash, hLen);
225 if (sLen)
226 EVP_DigestUpdate(&ctx, salt, sLen);
227 EVP_DigestFinal(&ctx, H, NULL);
228 EVP_MD_CTX_cleanup(&ctx);
229
230 /* Generate dbMask in place then perform XOR on it */
231 PKCS1_MGF1(EM, maskedDBLen, H, hLen, Hash);
232
233 p = EM;
234
235 /* Initial PS XORs with all zeroes which is a NOP so just update
236 * pointer. Note from a test above this value is guaranteed to
237 * be non-negative.
238 */
239 p += emLen - sLen - hLen - 2;
240 *p++ ^= 0x1;
241 if (sLen > 0)
242 {
243 for (i = 0; i < sLen; i++)
244 *p++ ^= salt[i];
245 }
246 if (MSBits)
247 EM[0] &= 0xFF >> (8 - MSBits);
248
249 /* H is already in place so just set final 0xbc */
250
251 EM[emLen - 1] = 0xbc;
252
253 ret = 1;
254
255 err:
256 if (salt)
257 OPENSSL_free(salt);
258
259 return ret;
260
261 }
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
deleted file mode 100644
index 24fc94835e..0000000000
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ /dev/null
@@ -1,149 +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,
67 const unsigned char *m, unsigned int m_len,
68 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
69 {
70 ASN1_OCTET_STRING sig;
71 int i,j,ret=1;
72 unsigned char *p,*s;
73
74 sig.type=V_ASN1_OCTET_STRING;
75 sig.length=m_len;
76 sig.data=(unsigned char *)m;
77
78 i=i2d_ASN1_OCTET_STRING(&sig,NULL);
79 j=RSA_size(rsa);
80 if (i > (j-RSA_PKCS1_PADDING_SIZE))
81 {
82 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
83 return(0);
84 }
85 s=(unsigned char *)OPENSSL_malloc((unsigned int)j+1);
86 if (s == NULL)
87 {
88 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
89 return(0);
90 }
91 p=s;
92 i2d_ASN1_OCTET_STRING(&sig,&p);
93 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
94 if (i <= 0)
95 ret=0;
96 else
97 *siglen=i;
98
99 OPENSSL_cleanse(s,(unsigned int)j+1);
100 OPENSSL_free(s);
101 return(ret);
102 }
103
104int RSA_verify_ASN1_OCTET_STRING(int dtype,
105 const unsigned char *m,
106 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
107 RSA *rsa)
108 {
109 int i,ret=0;
110 unsigned char *p,*s;
111 ASN1_OCTET_STRING *sig=NULL;
112
113 if (siglen != (unsigned int)RSA_size(rsa))
114 {
115 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_WRONG_SIGNATURE_LENGTH);
116 return(0);
117 }
118
119 s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
120 if (s == NULL)
121 {
122 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
123 goto err;
124 }
125 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
126
127 if (i <= 0) goto err;
128
129 p=s;
130 sig=d2i_ASN1_OCTET_STRING(NULL,&p,(long)i);
131 if (sig == NULL) goto err;
132
133 if ( ((unsigned int)sig->length != m_len) ||
134 (memcmp(m,sig->data,m_len) != 0))
135 {
136 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_BAD_SIGNATURE);
137 }
138 else
139 ret=1;
140err:
141 if (sig != NULL) M_ASN1_OCTET_STRING_free(sig);
142 if (s != NULL)
143 {
144 OPENSSL_cleanse(s,(unsigned int)siglen);
145 OPENSSL_free(s);
146 }
147 return(ret);
148 }
149
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
deleted file mode 100644
index db86f1ac58..0000000000
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ /dev/null
@@ -1,249 +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, const 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, *tmps = NULL;
76 const unsigned char *s = NULL;
77 X509_ALGOR algor;
78 ASN1_OCTET_STRING digest;
79 if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_sign)
80 {
81 return rsa->meth->rsa_sign(type, m, m_len,
82 sigret, siglen, rsa);
83 }
84 /* Special case: SSL signature, just check the length */
85 if(type == NID_md5_sha1) {
86 if(m_len != SSL_SIG_LENGTH) {
87 RSAerr(RSA_F_RSA_SIGN,RSA_R_INVALID_MESSAGE_LENGTH);
88 return(0);
89 }
90 i = SSL_SIG_LENGTH;
91 s = m;
92 } else {
93 sig.algor= &algor;
94 sig.algor->algorithm=OBJ_nid2obj(type);
95 if (sig.algor->algorithm == NULL)
96 {
97 RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE);
98 return(0);
99 }
100 if (sig.algor->algorithm->length == 0)
101 {
102 RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
103 return(0);
104 }
105 parameter.type=V_ASN1_NULL;
106 parameter.value.ptr=NULL;
107 sig.algor->parameter= &parameter;
108
109 sig.digest= &digest;
110 sig.digest->data=(unsigned char *)m; /* TMP UGLY CAST */
111 sig.digest->length=m_len;
112
113 i=i2d_X509_SIG(&sig,NULL);
114 }
115 j=RSA_size(rsa);
116 if (i > (j-RSA_PKCS1_PADDING_SIZE))
117 {
118 RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
119 return(0);
120 }
121 if(type != NID_md5_sha1) {
122 tmps=(unsigned char *)OPENSSL_malloc((unsigned int)j+1);
123 if (tmps == NULL)
124 {
125 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE);
126 return(0);
127 }
128 p=tmps;
129 i2d_X509_SIG(&sig,&p);
130 s=tmps;
131 }
132 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
133 if (i <= 0)
134 ret=0;
135 else
136 *siglen=i;
137
138 if(type != NID_md5_sha1) {
139 OPENSSL_cleanse(tmps,(unsigned int)j+1);
140 OPENSSL_free(tmps);
141 }
142 return(ret);
143 }
144
145int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
146 unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
147 {
148 int i,ret=0,sigtype;
149 unsigned char *p,*s;
150 X509_SIG *sig=NULL;
151
152 if (siglen != (unsigned int)RSA_size(rsa))
153 {
154 RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
155 return(0);
156 }
157
158 if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify)
159 {
160 return rsa->meth->rsa_verify(dtype, m, m_len,
161 sigbuf, siglen, rsa);
162 }
163
164 s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
165 if (s == NULL)
166 {
167 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
168 goto err;
169 }
170 if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {
171 RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
172 goto err;
173 }
174 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
175
176 if (i <= 0) goto err;
177
178 /* Special case: SSL signature */
179 if(dtype == NID_md5_sha1) {
180 if((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))
181 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
182 else ret = 1;
183 } else {
184 p=s;
185 sig=d2i_X509_SIG(NULL,&p,(long)i);
186
187 if (sig == NULL) goto err;
188
189 /* Excess data can be used to create forgeries */
190 if(p != s+i)
191 {
192 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
193 goto err;
194 }
195
196 /* Parameters to the signature algorithm can also be used to
197 create forgeries */
198 if(sig->algor->parameter
199 && ASN1_TYPE_get(sig->algor->parameter) != V_ASN1_NULL)
200 {
201 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
202 goto err;
203 }
204
205 sigtype=OBJ_obj2nid(sig->algor->algorithm);
206
207
208 #ifdef RSA_DEBUG
209 /* put a backward compatibility flag in EAY */
210 fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype),
211 OBJ_nid2ln(dtype));
212 #endif
213 if (sigtype != dtype)
214 {
215 if (((dtype == NID_md5) &&
216 (sigtype == NID_md5WithRSAEncryption)) ||
217 ((dtype == NID_md2) &&
218 (sigtype == NID_md2WithRSAEncryption)))
219 {
220 /* ok, we will let it through */
221#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
222 fprintf(stderr,"signature has problems, re-make with post SSLeay045\n");
223#endif
224 }
225 else
226 {
227 RSAerr(RSA_F_RSA_VERIFY,
228 RSA_R_ALGORITHM_MISMATCH);
229 goto err;
230 }
231 }
232 if ( ((unsigned int)sig->digest->length != m_len) ||
233 (memcmp(m,sig->digest->data,m_len) != 0))
234 {
235 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
236 }
237 else
238 ret=1;
239 }
240err:
241 if (sig != NULL) X509_SIG_free(sig);
242 if (s != NULL)
243 {
244 OPENSSL_cleanse(s,(unsigned int)siglen);
245 OPENSSL_free(s);
246 }
247 return(ret);
248 }
249
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c
deleted file mode 100644
index ea72629494..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,
66 const unsigned char *from, 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,
106 const unsigned char *from, int flen, int num)
107 {
108 int i,j,k;
109 const 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 == -1)
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/rsa/rsa_x931.c b/src/lib/libcrypto/rsa/rsa_x931.c
deleted file mode 100644
index df3c45f802..0000000000
--- a/src/lib/libcrypto/rsa/rsa_x931.c
+++ /dev/null
@@ -1,177 +0,0 @@
1/* rsa_x931.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2005.
4 */
5/* ====================================================================
6 * Copyright (c) 2005 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64#include <openssl/objects.h>
65
66int RSA_padding_add_X931(unsigned char *to, int tlen,
67 const unsigned char *from, int flen)
68 {
69 int j;
70 unsigned char *p;
71
72 /* Absolute minimum amount of padding is 1 header nibble, 1 padding
73 * nibble and 2 trailer bytes: but 1 hash if is already in 'from'.
74 */
75
76 j = tlen - flen - 2;
77
78 if (j < 0)
79 {
80 RSAerr(RSA_F_RSA_PADDING_ADD_X931,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
81 return -1;
82 }
83
84 p=(unsigned char *)to;
85
86 /* If no padding start and end nibbles are in one byte */
87 if (j == 0)
88 *p++ = 0x6A;
89 else
90 {
91 *p++ = 0x6B;
92 if (j > 1)
93 {
94 memset(p, 0xBB, j - 1);
95 p += j - 1;
96 }
97 *p++ = 0xBA;
98 }
99 memcpy(p,from,(unsigned int)flen);
100 p += flen;
101 *p = 0xCC;
102 return(1);
103 }
104
105int RSA_padding_check_X931(unsigned char *to, int tlen,
106 const unsigned char *from, int flen, int num)
107 {
108 int i,j;
109 const unsigned char *p;
110
111 p=from;
112 if ((num != flen) || ((*p != 0x6A) && (*p != 0x6B)))
113 {
114 RSAerr(RSA_F_RSA_PADDING_CHECK_X931,RSA_R_INVALID_HEADER);
115 return -1;
116 }
117
118 if (*p++ == 0x6B)
119 {
120 j=flen-3;
121 for (i = 0; i < j; i++)
122 {
123 unsigned char c = *p++;
124 if (c == 0xBA)
125 break;
126 if (c != 0xBB)
127 {
128 RSAerr(RSA_F_RSA_PADDING_CHECK_X931,
129 RSA_R_INVALID_PADDING);
130 return -1;
131 }
132 }
133
134 j -= i;
135
136 if (i == 0)
137 {
138 RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_PADDING);
139 return -1;
140 }
141
142 }
143 else j = flen - 2;
144
145 if (p[j] != 0xCC)
146 {
147 RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_TRAILER);
148 return -1;
149 }
150
151 memcpy(to,p,(unsigned int)j);
152
153 return(j);
154 }
155
156/* Translate between X931 hash ids and NIDs */
157
158int RSA_X931_hash_id(int nid)
159 {
160 switch (nid)
161 {
162 case NID_sha1:
163 return 0x33;
164
165 case NID_sha256:
166 return 0x34;
167
168 case NID_sha384:
169 return 0x36;
170
171 case NID_sha512:
172 return 0x35;
173
174 }
175 return -1;
176 }
177
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 041acc0348..0000000000
--- a/src/lib/libcrypto/sha/asm/sha1-586.pl
+++ /dev/null
@@ -1,425 +0,0 @@
1#!/usr/local/bin/perl
2
3# It was noted that Intel IA-32 C compiler generates code which
4# performs ~30% *faster* on P4 CPU than original *hand-coded*
5# SHA1 assembler implementation. To address this problem (and
6# prove that humans are still better than machines:-), the
7# original code was overhauled, which resulted in following
8# performance changes:
9#
10# compared with original compared with Intel cc
11# assembler impl. generated code
12# Pentium -25% +37%
13# PIII/AMD +8% +16%
14# P4 +85%(!) +45%
15#
16# As you can see Pentium came out as looser:-( Yet I reckoned that
17# improvement on P4 outweights the loss and incorporate this
18# re-tuned code to 0.9.7 and later.
19# ----------------------------------------------------------------
20# Those who for any particular reason absolutely must score on
21# Pentium can replace this module with one from 0.9.6 distribution.
22# This "offer" shall be revoked the moment programming interface to
23# this module is changed, in which case this paragraph should be
24# removed.
25# ----------------------------------------------------------------
26# <appro@fy.chalmers.se>
27
28$normal=0;
29
30push(@INC,"perlasm","../../perlasm");
31require "x86asm.pl";
32
33&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386");
34
35$A="eax";
36$B="ecx";
37$C="ebx";
38$D="edx";
39$E="edi";
40$T="esi";
41$tmp1="ebp";
42
43$off=9*4;
44
45@K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6);
46
47&sha1_block_data("sha1_block_asm_data_order");
48
49&asm_finish();
50
51sub Nn
52 {
53 local($p)=@_;
54 local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E);
55 return($n{$p});
56 }
57
58sub Np
59 {
60 local($p)=@_;
61 local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E);
62 local(%n)=($A,$B,$B,$C,$C,$D,$D,$E,$E,$T,$T,$A);
63 return($n{$p});
64 }
65
66sub Na
67 {
68 local($n)=@_;
69 return( (($n )&0x0f),
70 (($n+ 2)&0x0f),
71 (($n+ 8)&0x0f),
72 (($n+13)&0x0f),
73 (($n+ 1)&0x0f));
74 }
75
76sub X_expand
77 {
78 local($in)=@_;
79
80 &comment("First, load the words onto the stack in network byte order");
81 for ($i=0; $i<16; $i+=2)
82 {
83 &mov($A,&DWP(($i+0)*4,$in,"",0));# unless $i == 0;
84 &mov($B,&DWP(($i+1)*4,$in,"",0));
85 &bswap($A);
86 &bswap($B);
87 &mov(&swtmp($i+0),$A);
88 &mov(&swtmp($i+1),$B);
89 }
90
91 &comment("We now have the X array on the stack");
92 &comment("starting at sp-4");
93 }
94
95# Rules of engagement
96# F is always trashable at the start, the running total.
97# E becomes the next F so it can be trashed after it has been 'accumulated'
98# F becomes A in the next round. We don't need to access it much.
99# During the X update part, the result ends up in $X[$n0].
100
101sub BODY_00_15
102 {
103 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
104
105 &comment("00_15 $n");
106
107 &mov($tmp1,$a);
108 &mov($f,$c); # f to hold F_00_19(b,c,d)
109 &rotl($tmp1,5); # tmp1=ROTATE(a,5)
110 &xor($f,$d);
111 &and($f,$b);
112 &rotr($b,2); # b=ROTATE(b,30)
113 &add($tmp1,$e); # tmp1+=e;
114 &mov($e,&swtmp($n)); # e becomes volatile and
115 # is loaded with xi
116 &xor($f,$d); # f holds F_00_19(b,c,d)
117 &lea($tmp1,&DWP($K,$tmp1,$e,1));# tmp1+=K_00_19+xi
118
119 &add($f,$tmp1); # f+=tmp1
120 }
121
122sub BODY_16_19
123 {
124 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
125 local($n0,$n1,$n2,$n3,$np)=&Na($n);
126
127 &comment("16_19 $n");
128
129 &mov($f,&swtmp($n1)); # f to hold Xupdate(xi,xa,xb,xc,xd)
130 &mov($tmp1,$c); # tmp1 to hold F_00_19(b,c,d)
131 &xor($f,&swtmp($n0));
132 &xor($tmp1,$d);
133 &xor($f,&swtmp($n2));
134 &and($tmp1,$b); # tmp1 holds F_00_19(b,c,d)
135 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
136 &rotr($b,2); # b=ROTATE(b,30)
137 &xor($tmp1,$d); # tmp1=F_00_19(b,c,d)
138 &rotl($f,1); # f=ROATE(f,1)
139 &mov(&swtmp($n0),$f); # xi=f
140 &lea($f,&DWP($K,$f,$e,1)); # f+=K_00_19+e
141 &mov($e,$a); # e becomes volatile
142 &add($f,$tmp1); # f+=F_00_19(b,c,d)
143 &rotl($e,5); # e=ROTATE(a,5)
144 &add($f,$e); # f+=ROTATE(a,5)
145 }
146
147sub BODY_20_39
148 {
149 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
150
151 &comment("20_39 $n");
152 local($n0,$n1,$n2,$n3,$np)=&Na($n);
153
154 &mov($f,&swtmp($n0)); # f to hold Xupdate(xi,xa,xb,xc,xd)
155 &mov($tmp1,$b); # tmp1 to hold F_20_39(b,c,d)
156 &xor($f,&swtmp($n1));
157 &rotr($b,2); # b=ROTATE(b,30)
158 &xor($f,&swtmp($n2));
159 &xor($tmp1,$c);
160 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
161 &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d)
162 &rotl($f,1); # f=ROTATE(f,1)
163 &mov(&swtmp($n0),$f); # xi=f
164 &lea($f,&DWP($K,$f,$e,1)); # f+=K_20_39+e
165 &mov($e,$a); # e becomes volatile
166 &rotl($e,5); # e=ROTATE(a,5)
167 &add($f,$tmp1); # f+=F_20_39(b,c,d)
168 &add($f,$e); # f+=ROTATE(a,5)
169 }
170
171sub BODY_40_59
172 {
173 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
174
175 &comment("40_59 $n");
176 local($n0,$n1,$n2,$n3,$np)=&Na($n);
177
178 &mov($f,&swtmp($n0)); # f to hold Xupdate(xi,xa,xb,xc,xd)
179 &mov($tmp1,$b); # tmp1 to hold F_40_59(b,c,d)
180 &xor($f,&swtmp($n1));
181 &or($tmp1,$c);
182 &xor($f,&swtmp($n2));
183 &and($tmp1,$d);
184 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
185 &rotl($f,1); # f=ROTATE(f,1)
186 &mov(&swtmp($n0),$f); # xi=f
187 &lea($f,&DWP($K,$f,$e,1)); # f+=K_40_59+e
188 &mov($e,$b); # e becomes volatile and is used
189 # to calculate F_40_59(b,c,d)
190 &rotr($b,2); # b=ROTATE(b,30)
191 &and($e,$c);
192 &or($tmp1,$e); # tmp1 holds F_40_59(b,c,d)
193 &mov($e,$a);
194 &rotl($e,5); # e=ROTATE(a,5)
195 &add($tmp1,$e); # tmp1+=ROTATE(a,5)
196 &add($f,$tmp1); # f+=tmp1;
197 }
198
199sub BODY_60_79
200 {
201 &BODY_20_39(@_);
202 }
203
204sub sha1_block_host
205 {
206 local($name, $sclabel)=@_;
207
208 &function_begin_B($name,"");
209
210 # parameter 1 is the MD5_CTX structure.
211 # A 0
212 # B 4
213 # C 8
214 # D 12
215 # E 16
216
217 &mov("ecx", &wparam(2));
218 &push("esi");
219 &shl("ecx",6);
220 &mov("esi", &wparam(1));
221 &push("ebp");
222 &add("ecx","esi"); # offset to leave on
223 &push("ebx");
224 &mov("ebp", &wparam(0));
225 &push("edi");
226 &mov($D, &DWP(12,"ebp","",0));
227 &stack_push(18+9);
228 &mov($E, &DWP(16,"ebp","",0));
229 &mov($C, &DWP( 8,"ebp","",0));
230 &mov(&swtmp(17),"ecx");
231
232 &comment("First we need to setup the X array");
233
234 for ($i=0; $i<16; $i+=2)
235 {
236 &mov($A,&DWP(($i+0)*4,"esi","",0));# unless $i == 0;
237 &mov($B,&DWP(($i+1)*4,"esi","",0));
238 &mov(&swtmp($i+0),$A);
239 &mov(&swtmp($i+1),$B);
240 }
241 &jmp($sclabel);
242 &function_end_B($name);
243 }
244
245
246sub sha1_block_data
247 {
248 local($name)=@_;
249
250 &function_begin_B($name,"");
251
252 # parameter 1 is the MD5_CTX structure.
253 # A 0
254 # B 4
255 # C 8
256 # D 12
257 # E 16
258
259 &mov("ecx", &wparam(2));
260 &push("esi");
261 &shl("ecx",6);
262 &mov("esi", &wparam(1));
263 &push("ebp");
264 &add("ecx","esi"); # offset to leave on
265 &push("ebx");
266 &mov("ebp", &wparam(0));
267 &push("edi");
268 &mov($D, &DWP(12,"ebp","",0));
269 &stack_push(18+9);
270 &mov($E, &DWP(16,"ebp","",0));
271 &mov($C, &DWP( 8,"ebp","",0));
272 &mov(&swtmp(17),"ecx");
273
274 &comment("First we need to setup the X array");
275
276 &set_label("start") unless $normal;
277
278 &X_expand("esi");
279 &mov(&wparam(1),"esi");
280
281 &set_label("shortcut", 0, 1);
282 &comment("");
283 &comment("Start processing");
284
285 # odd start
286 &mov($A, &DWP( 0,"ebp","",0));
287 &mov($B, &DWP( 4,"ebp","",0));
288 $X="esp";
289 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T);
290 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E);
291 &BODY_00_15( 0,$K[0],$X, 2,$E,$T,$A,$B,$C,$D);
292 &BODY_00_15( 0,$K[0],$X, 3,$D,$E,$T,$A,$B,$C);
293 &BODY_00_15( 0,$K[0],$X, 4,$C,$D,$E,$T,$A,$B);
294 &BODY_00_15( 0,$K[0],$X, 5,$B,$C,$D,$E,$T,$A);
295 &BODY_00_15( 0,$K[0],$X, 6,$A,$B,$C,$D,$E,$T);
296 &BODY_00_15( 0,$K[0],$X, 7,$T,$A,$B,$C,$D,$E);
297 &BODY_00_15( 0,$K[0],$X, 8,$E,$T,$A,$B,$C,$D);
298 &BODY_00_15( 0,$K[0],$X, 9,$D,$E,$T,$A,$B,$C);
299 &BODY_00_15( 0,$K[0],$X,10,$C,$D,$E,$T,$A,$B);
300 &BODY_00_15( 0,$K[0],$X,11,$B,$C,$D,$E,$T,$A);
301 &BODY_00_15( 0,$K[0],$X,12,$A,$B,$C,$D,$E,$T);
302 &BODY_00_15( 0,$K[0],$X,13,$T,$A,$B,$C,$D,$E);
303 &BODY_00_15( 0,$K[0],$X,14,$E,$T,$A,$B,$C,$D);
304 &BODY_00_15( 1,$K[0],$X,15,$D,$E,$T,$A,$B,$C);
305 &BODY_16_19(-1,$K[0],$X,16,$C,$D,$E,$T,$A,$B);
306 &BODY_16_19( 0,$K[0],$X,17,$B,$C,$D,$E,$T,$A);
307 &BODY_16_19( 0,$K[0],$X,18,$A,$B,$C,$D,$E,$T);
308 &BODY_16_19( 1,$K[0],$X,19,$T,$A,$B,$C,$D,$E);
309
310 &BODY_20_39(-1,$K[1],$X,20,$E,$T,$A,$B,$C,$D);
311 &BODY_20_39( 0,$K[1],$X,21,$D,$E,$T,$A,$B,$C);
312 &BODY_20_39( 0,$K[1],$X,22,$C,$D,$E,$T,$A,$B);
313 &BODY_20_39( 0,$K[1],$X,23,$B,$C,$D,$E,$T,$A);
314 &BODY_20_39( 0,$K[1],$X,24,$A,$B,$C,$D,$E,$T);
315 &BODY_20_39( 0,$K[1],$X,25,$T,$A,$B,$C,$D,$E);
316 &BODY_20_39( 0,$K[1],$X,26,$E,$T,$A,$B,$C,$D);
317 &BODY_20_39( 0,$K[1],$X,27,$D,$E,$T,$A,$B,$C);
318 &BODY_20_39( 0,$K[1],$X,28,$C,$D,$E,$T,$A,$B);
319 &BODY_20_39( 0,$K[1],$X,29,$B,$C,$D,$E,$T,$A);
320 &BODY_20_39( 0,$K[1],$X,30,$A,$B,$C,$D,$E,$T);
321 &BODY_20_39( 0,$K[1],$X,31,$T,$A,$B,$C,$D,$E);
322 &BODY_20_39( 0,$K[1],$X,32,$E,$T,$A,$B,$C,$D);
323 &BODY_20_39( 0,$K[1],$X,33,$D,$E,$T,$A,$B,$C);
324 &BODY_20_39( 0,$K[1],$X,34,$C,$D,$E,$T,$A,$B);
325 &BODY_20_39( 0,$K[1],$X,35,$B,$C,$D,$E,$T,$A);
326 &BODY_20_39( 0,$K[1],$X,36,$A,$B,$C,$D,$E,$T);
327 &BODY_20_39( 0,$K[1],$X,37,$T,$A,$B,$C,$D,$E);
328 &BODY_20_39( 0,$K[1],$X,38,$E,$T,$A,$B,$C,$D);
329 &BODY_20_39( 1,$K[1],$X,39,$D,$E,$T,$A,$B,$C);
330
331 &BODY_40_59(-1,$K[2],$X,40,$C,$D,$E,$T,$A,$B);
332 &BODY_40_59( 0,$K[2],$X,41,$B,$C,$D,$E,$T,$A);
333 &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
334 &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
335 &BODY_40_59( 0,$K[2],$X,44,$E,$T,$A,$B,$C,$D);
336 &BODY_40_59( 0,$K[2],$X,45,$D,$E,$T,$A,$B,$C);
337 &BODY_40_59( 0,$K[2],$X,46,$C,$D,$E,$T,$A,$B);
338 &BODY_40_59( 0,$K[2],$X,47,$B,$C,$D,$E,$T,$A);
339 &BODY_40_59( 0,$K[2],$X,48,$A,$B,$C,$D,$E,$T);
340 &BODY_40_59( 0,$K[2],$X,49,$T,$A,$B,$C,$D,$E);
341 &BODY_40_59( 0,$K[2],$X,50,$E,$T,$A,$B,$C,$D);
342 &BODY_40_59( 0,$K[2],$X,51,$D,$E,$T,$A,$B,$C);
343 &BODY_40_59( 0,$K[2],$X,52,$C,$D,$E,$T,$A,$B);
344 &BODY_40_59( 0,$K[2],$X,53,$B,$C,$D,$E,$T,$A);
345 &BODY_40_59( 0,$K[2],$X,54,$A,$B,$C,$D,$E,$T);
346 &BODY_40_59( 0,$K[2],$X,55,$T,$A,$B,$C,$D,$E);
347 &BODY_40_59( 0,$K[2],$X,56,$E,$T,$A,$B,$C,$D);
348 &BODY_40_59( 0,$K[2],$X,57,$D,$E,$T,$A,$B,$C);
349 &BODY_40_59( 0,$K[2],$X,58,$C,$D,$E,$T,$A,$B);
350 &BODY_40_59( 1,$K[2],$X,59,$B,$C,$D,$E,$T,$A);
351
352 &BODY_60_79(-1,$K[3],$X,60,$A,$B,$C,$D,$E,$T);
353 &BODY_60_79( 0,$K[3],$X,61,$T,$A,$B,$C,$D,$E);
354 &BODY_60_79( 0,$K[3],$X,62,$E,$T,$A,$B,$C,$D);
355 &BODY_60_79( 0,$K[3],$X,63,$D,$E,$T,$A,$B,$C);
356 &BODY_60_79( 0,$K[3],$X,64,$C,$D,$E,$T,$A,$B);
357 &BODY_60_79( 0,$K[3],$X,65,$B,$C,$D,$E,$T,$A);
358 &BODY_60_79( 0,$K[3],$X,66,$A,$B,$C,$D,$E,$T);
359 &BODY_60_79( 0,$K[3],$X,67,$T,$A,$B,$C,$D,$E);
360 &BODY_60_79( 0,$K[3],$X,68,$E,$T,$A,$B,$C,$D);
361 &BODY_60_79( 0,$K[3],$X,69,$D,$E,$T,$A,$B,$C);
362 &BODY_60_79( 0,$K[3],$X,70,$C,$D,$E,$T,$A,$B);
363 &BODY_60_79( 0,$K[3],$X,71,$B,$C,$D,$E,$T,$A);
364 &BODY_60_79( 0,$K[3],$X,72,$A,$B,$C,$D,$E,$T);
365 &BODY_60_79( 0,$K[3],$X,73,$T,$A,$B,$C,$D,$E);
366 &BODY_60_79( 0,$K[3],$X,74,$E,$T,$A,$B,$C,$D);
367 &BODY_60_79( 0,$K[3],$X,75,$D,$E,$T,$A,$B,$C);
368 &BODY_60_79( 0,$K[3],$X,76,$C,$D,$E,$T,$A,$B);
369 &BODY_60_79( 0,$K[3],$X,77,$B,$C,$D,$E,$T,$A);
370 &BODY_60_79( 0,$K[3],$X,78,$A,$B,$C,$D,$E,$T);
371 &BODY_60_79( 2,$K[3],$X,79,$T,$A,$B,$C,$D,$E);
372
373 &comment("End processing");
374 &comment("");
375 # D is the tmp value
376
377 # E -> A
378 # T -> B
379 # A -> C
380 # B -> D
381 # C -> E
382 # D -> T
383
384 &mov($tmp1,&wparam(0));
385
386 &mov($D, &DWP(12,$tmp1,"",0));
387 &add($D,$B);
388 &mov($B, &DWP( 4,$tmp1,"",0));
389 &add($B,$T);
390 &mov($T, $A);
391 &mov($A, &DWP( 0,$tmp1,"",0));
392 &mov(&DWP(12,$tmp1,"",0),$D);
393
394 &add($A,$E);
395 &mov($E, &DWP(16,$tmp1,"",0));
396 &add($E,$C);
397 &mov($C, &DWP( 8,$tmp1,"",0));
398 &add($C,$T);
399
400 &mov(&DWP( 0,$tmp1,"",0),$A);
401 &mov("esi",&wparam(1));
402 &mov(&DWP( 8,$tmp1,"",0),$C);
403 &add("esi",64);
404 &mov("eax",&swtmp(17));
405 &mov(&DWP(16,$tmp1,"",0),$E);
406 &cmp("esi","eax");
407 &mov(&DWP( 4,$tmp1,"",0),$B);
408 &jb(&label("start"));
409
410 &stack_pop(18+9);
411 &pop("edi");
412 &pop("ebx");
413 &pop("ebp");
414 &pop("esi");
415 &ret();
416
417 # keep a note of shortcut label so it can be used outside
418 # block.
419 my $sclabel = &label("shortcut");
420
421 &function_end_B($name);
422 # Putting this here avoids problems with MASM in debugging mode
423 &sha1_block_host("sha1_block_asm_host_order", $sclabel);
424 }
425
diff --git a/src/lib/libcrypto/sha/asm/sha1-ia64.pl b/src/lib/libcrypto/sha/asm/sha1-ia64.pl
deleted file mode 100644
index cb9dfad124..0000000000
--- a/src/lib/libcrypto/sha/asm/sha1-ia64.pl
+++ /dev/null
@@ -1,549 +0,0 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. Rights for redistribution and usage in source and binary
6# forms are granted according to the OpenSSL license.
7# ====================================================================
8#
9# Eternal question is what's wrong with compiler generated code? The
10# trick is that it's possible to reduce the number of shifts required
11# to perform rotations by maintaining copy of 32-bit value in upper
12# bits of 64-bit register. Just follow mux2 and shrp instructions...
13# Performance under big-endian OS such as HP-UX is 179MBps*1GHz, which
14# is >50% better than HP C and >2x better than gcc. As of this moment
15# performance under little-endian OS such as Linux and Windows will be
16# a bit lower, because data has to be picked in reverse byte-order.
17# It's possible to resolve this issue by implementing third function,
18# sha1_block_asm_data_order_aligned, which would temporarily flip
19# BE field in User Mask register...
20
21$code=<<___;
22.ident \"sha1-ia64.s, version 1.0\"
23.ident \"IA-64 ISA artwork by Andy Polyakov <appro\@fy.chalmers.se>\"
24.explicit
25
26___
27
28
29if ($^O eq "hpux") {
30 $ADDP="addp4";
31 for (@ARGV) { $ADDP="add" if (/[\+DD|\-mlp]64/); }
32} else { $ADDP="add"; }
33for (@ARGV) { $big_endian=1 if (/\-DB_ENDIAN/);
34 $big_endian=0 if (/\-DL_ENDIAN/); }
35if (!defined($big_endian))
36 { $big_endian=(unpack('L',pack('N',1))==1); }
37
38#$human=1;
39if ($human) { # useful for visual code auditing...
40 ($A,$B,$C,$D,$E,$T) = ("A","B","C","D","E","T");
41 ($h0,$h1,$h2,$h3,$h4) = ("h0","h1","h2","h3","h4");
42 ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
43 ( "K_00_19","K_20_39","K_40_59","K_60_79" );
44 @X= ( "X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7",
45 "X8", "X9","X10","X11","X12","X13","X14","X15" );
46}
47else {
48 ($A,$B,$C,$D,$E,$T) = ("loc0","loc1","loc2","loc3","loc4","loc5");
49 ($h0,$h1,$h2,$h3,$h4) = ("loc6","loc7","loc8","loc9","loc10");
50 ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
51 ( "r14", "r15", "loc11", "loc12" );
52 @X= ( "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
53 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" );
54}
55
56sub BODY_00_15 {
57local *code=shift;
58local ($i,$a,$b,$c,$d,$e,$f,$unaligned)=@_;
59
60if ($unaligned) {
61 $code.=<<___;
62{ .mmi; ld1 tmp0=[inp],2 // MSB
63 ld1 tmp1=[tmp3],2 };;
64{ .mmi; ld1 tmp2=[inp],2
65 ld1 $X[$i&0xf]=[tmp3],2 // LSB
66 dep tmp1=tmp0,tmp1,8,8 };;
67{ .mii; cmp.ne p16,p0=r0,r0 // no misaligned prefetch
68 dep $X[$i&0xf]=tmp2,$X[$i&0xf],8,8;;
69 dep $X[$i&0xf]=tmp1,$X[$i&0xf],16,16 };;
70{ .mmi; nop.m 0
71___
72 }
73elsif ($i<15) {
74 $code.=<<___;
75{ .mmi; ld4 $X[($i+1)&0xf]=[inp],4 // prefetch
76___
77 }
78else {
79 $code.=<<___;
80{ .mmi; nop.m 0
81___
82 }
83if ($i<15) {
84 $code.=<<___;
85 and tmp0=$c,$b
86 dep.z tmp5=$a,5,27 } // a<<5
87{ .mmi; andcm tmp1=$d,$b
88 add tmp4=$e,$K_00_19 };;
89{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
90 add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19
91 extr.u tmp1=$a,27,5 };; // a>>27
92{ .mib; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
93 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
94{ .mib; or tmp1=tmp1,tmp5 // ROTATE(a,5)
95 mux2 tmp6=$a,0x44 };; // see b in next iteration
96{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
97 mux2 $X[$i&0xf]=$X[$i&0xf],0x44
98 nop.i 0 };;
99
100___
101 }
102else {
103 $code.=<<___;
104 and tmp0=$c,$b
105 dep.z tmp5=$a,5,27 } // a<<5 ;;?
106{ .mmi; andcm tmp1=$d,$b
107 add tmp4=$e,$K_00_19 };;
108{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
109 add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19
110 extr.u tmp1=$a,27,5 } // a>>27
111{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
112 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
113 nop.i 0 };;
114{ .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
115 xor tmp2=tmp2,tmp3 // +1
116 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
117{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
118 mux2 tmp6=$a,0x44 };; // see b in next iteration
119{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
120 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
121 mux2 $X[$i&0xf]=$X[$i&0xf],0x44 };;
122
123___
124 }
125}
126
127sub BODY_16_19 {
128local *code=shift;
129local ($i,$a,$b,$c,$d,$e,$f)=@_;
130
131$code.=<<___;
132{ .mmi; mov $X[$i&0xf]=$f // Xupdate
133 and tmp0=$c,$b
134 dep.z tmp5=$a,5,27 } // a<<5
135{ .mmi; andcm tmp1=$d,$b
136 add tmp4=$e,$K_00_19 };;
137{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
138 add $f=$f,tmp4 // f+=e+K_00_19
139 extr.u tmp1=$a,27,5 } // a>>27
140{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
141 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
142 nop.i 0 };;
143{ .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
144 xor tmp2=tmp2,tmp3 // +1
145 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
146{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
147 mux2 tmp6=$a,0x44 };; // see b in next iteration
148{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
149 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
150 nop.i 0 };;
151
152___
153}
154
155sub BODY_20_39 {
156local *code=shift;
157local ($i,$a,$b,$c,$d,$e,$f,$Konst)=@_;
158 $Konst = $K_20_39 if (!defined($Konst));
159
160if ($i<79) {
161$code.=<<___;
162{ .mib; mov $X[$i&0xf]=$f // Xupdate
163 dep.z tmp5=$a,5,27 } // a<<5
164{ .mib; xor tmp0=$c,$b
165 add tmp4=$e,$Konst };;
166{ .mmi; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d
167 add $f=$f,tmp4 // f+=e+K_20_39
168 extr.u tmp1=$a,27,5 } // a>>27
169{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
170 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
171 nop.i 0 };;
172{ .mmi; add $f=$f,tmp0 // f+=F_20_39(b,c,d)
173 xor tmp2=tmp2,tmp3 // +1
174 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
175{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
176 mux2 tmp6=$a,0x44 };; // see b in next iteration
177{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
178 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
179 nop.i 0 };;
180
181___
182}
183else {
184$code.=<<___;
185{ .mib; mov $X[$i&0xf]=$f // Xupdate
186 dep.z tmp5=$a,5,27 } // a<<5
187{ .mib; xor tmp0=$c,$b
188 add tmp4=$e,$Konst };;
189{ .mib; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d
190 extr.u tmp1=$a,27,5 } // a>>27
191{ .mib; add $f=$f,tmp4 // f+=e+K_20_39
192 add $h1=$h1,$a };; // wrap up
193{ .mmi;
194(p16) ld4.s $X[0]=[inp],4 // non-faulting prefetch
195 add $f=$f,tmp0 // f+=F_20_39(b,c,d)
196 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) ;;?
197{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
198 add $h3=$h3,$c };; // wrap up
199{ .mib; add tmp3=1,inp // used in unaligned codepath
200 add $f=$f,tmp1 } // f+=ROTATE(a,5)
201{ .mib; add $h2=$h2,$b // wrap up
202 add $h4=$h4,$d };; // wrap up
203
204___
205}
206}
207
208sub BODY_40_59 {
209local *code=shift;
210local ($i,$a,$b,$c,$d,$e,$f)=@_;
211
212$code.=<<___;
213{ .mmi; mov $X[$i&0xf]=$f // Xupdate
214 and tmp0=$c,$b
215 dep.z tmp5=$a,5,27 } // a<<5
216{ .mmi; and tmp1=$d,$b
217 add tmp4=$e,$K_40_59 };;
218{ .mmi; or tmp0=tmp0,tmp1 // (b&c)|(b&d)
219 add $f=$f,tmp4 // f+=e+K_40_59
220 extr.u tmp1=$a,27,5 } // a>>27
221{ .mmi; and tmp4=$c,$d
222 xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
223 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
224 };;
225{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
226 xor tmp2=tmp2,tmp3 // +1
227 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
228{ .mmi; or tmp0=tmp0,tmp4 // F_40_59(b,c,d)=(b&c)|(b&d)|(c&d)
229 mux2 tmp6=$a,0x44 };; // see b in next iteration
230{ .mii; add $f=$f,tmp0 // f+=F_40_59(b,c,d)
231 shrp $e=tmp2,tmp2,31;; // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
232 add $f=$f,tmp1 };; // f+=ROTATE(a,5)
233
234___
235}
236sub BODY_60_79 { &BODY_20_39(@_,$K_60_79); }
237
238$code.=<<___;
239.text
240
241tmp0=r8;
242tmp1=r9;
243tmp2=r10;
244tmp3=r11;
245ctx=r32; // in0
246inp=r33; // in1
247
248// void sha1_block_asm_host_order(SHA_CTX *c,const void *p,size_t num);
249.global sha1_block_asm_host_order#
250.proc sha1_block_asm_host_order#
251.align 32
252sha1_block_asm_host_order:
253 .prologue
254 .fframe 0
255 .save ar.pfs,r0
256 .save ar.lc,r3
257{ .mmi; alloc tmp1=ar.pfs,3,15,0,0
258 $ADDP tmp0=4,ctx
259 mov r3=ar.lc }
260{ .mmi; $ADDP ctx=0,ctx
261 $ADDP inp=0,inp
262 mov r2=pr };;
263tmp4=in2;
264tmp5=loc13;
265tmp6=loc14;
266 .body
267{ .mlx; ld4 $h0=[ctx],8
268 movl $K_00_19=0x5a827999 }
269{ .mlx; ld4 $h1=[tmp0],8
270 movl $K_20_39=0x6ed9eba1 };;
271{ .mlx; ld4 $h2=[ctx],8
272 movl $K_40_59=0x8f1bbcdc }
273{ .mlx; ld4 $h3=[tmp0]
274 movl $K_60_79=0xca62c1d6 };;
275{ .mmi; ld4 $h4=[ctx],-16
276 add in2=-1,in2 // adjust num for ar.lc
277 mov ar.ec=1 };;
278{ .mmi; ld4 $X[0]=[inp],4 // prefetch
279 cmp.ne p16,p0=r0,in2 // prefecth at loop end
280 mov ar.lc=in2 };; // brp.loop.imp: too far
281
282.Lhtop:
283{ .mmi; mov $A=$h0
284 mov $B=$h1
285 mux2 tmp6=$h1,0x44 }
286{ .mmi; mov $C=$h2
287 mov $D=$h3
288 mov $E=$h4 };;
289
290___
291
292 &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T);
293 &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E);
294 &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D);
295 &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C);
296 &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B);
297 &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A);
298 &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T);
299 &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E);
300 &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D);
301 &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C);
302 &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B);
303 &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A);
304 &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T);
305 &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E);
306 &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D);
307 &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C);
308
309 &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
310 &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
311 &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
312 &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
313
314 &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
315 &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
316 &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
317 &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
318 &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
319 &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
320 &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
321 &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
322 &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
323 &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
324 &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
325 &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
326 &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
327 &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
328 &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
329 &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
330 &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
331 &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
332 &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
333 &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
334
335 &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
336 &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
337 &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
338 &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
339 &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
340 &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
341 &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
342 &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
343 &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
344 &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
345 &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
346 &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
347 &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
348 &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
349 &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
350 &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
351 &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
352 &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
353 &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
354 &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
355
356 &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
357 &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
358 &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
359 &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
360 &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
361 &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
362 &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
363 &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
364 &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
365 &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
366 &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
367 &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
368 &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
369 &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
370 &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
371 &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
372 &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
373 &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
374 &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
375 &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
376
377$code.=<<___;
378{ .mmb; add $h0=$h0,$E
379 nop.m 0
380 br.ctop.dptk.many .Lhtop };;
381.Lhend:
382{ .mmi; add tmp0=4,ctx
383 mov ar.lc=r3 };;
384{ .mmi; st4 [ctx]=$h0,8
385 st4 [tmp0]=$h1,8 };;
386{ .mmi; st4 [ctx]=$h2,8
387 st4 [tmp0]=$h3 };;
388{ .mib; st4 [ctx]=$h4,-16
389 mov pr=r2,0x1ffff
390 br.ret.sptk.many b0 };;
391.endp sha1_block_asm_host_order#
392___
393
394
395$code.=<<___;
396// void sha1_block_asm_data_order(SHA_CTX *c,const void *p,size_t num);
397.global sha1_block_asm_data_order#
398.proc sha1_block_asm_data_order#
399.align 32
400sha1_block_asm_data_order:
401___
402$code.=<<___ if ($big_endian);
403{ .mmi; and r2=3,inp };;
404{ .mib; cmp.eq p6,p0=r0,r2
405(p6) br.dptk.many sha1_block_asm_host_order };;
406___
407$code.=<<___;
408 .prologue
409 .fframe 0
410 .save ar.pfs,r0
411 .save ar.lc,r3
412{ .mmi; alloc tmp1=ar.pfs,3,15,0,0
413 $ADDP tmp0=4,ctx
414 mov r3=ar.lc }
415{ .mmi; $ADDP ctx=0,ctx
416 $ADDP inp=0,inp
417 mov r2=pr };;
418tmp4=in2;
419tmp5=loc13;
420tmp6=loc14;
421 .body
422{ .mlx; ld4 $h0=[ctx],8
423 movl $K_00_19=0x5a827999 }
424{ .mlx; ld4 $h1=[tmp0],8
425 movl $K_20_39=0x6ed9eba1 };;
426{ .mlx; ld4 $h2=[ctx],8
427 movl $K_40_59=0x8f1bbcdc }
428{ .mlx; ld4 $h3=[tmp0]
429 movl $K_60_79=0xca62c1d6 };;
430{ .mmi; ld4 $h4=[ctx],-16
431 add in2=-1,in2 // adjust num for ar.lc
432 mov ar.ec=1 };;
433{ .mmi; nop.m 0
434 add tmp3=1,inp
435 mov ar.lc=in2 };; // brp.loop.imp: too far
436
437.Ldtop:
438{ .mmi; mov $A=$h0
439 mov $B=$h1
440 mux2 tmp6=$h1,0x44 }
441{ .mmi; mov $C=$h2
442 mov $D=$h3
443 mov $E=$h4 };;
444
445___
446
447 &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T,1);
448 &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E,1);
449 &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D,1);
450 &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C,1);
451 &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B,1);
452 &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A,1);
453 &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T,1);
454 &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E,1);
455 &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D,1);
456 &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C,1);
457 &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B,1);
458 &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A,1);
459 &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T,1);
460 &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E,1);
461 &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D,1);
462 &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C,1);
463
464 &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
465 &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
466 &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
467 &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
468
469 &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
470 &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
471 &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
472 &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
473 &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
474 &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
475 &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
476 &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
477 &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
478 &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
479 &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
480 &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
481 &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
482 &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
483 &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
484 &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
485 &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
486 &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
487 &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
488 &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
489
490 &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
491 &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
492 &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
493 &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
494 &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
495 &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
496 &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
497 &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
498 &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
499 &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
500 &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
501 &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
502 &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
503 &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
504 &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
505 &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
506 &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
507 &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
508 &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
509 &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
510
511 &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
512 &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
513 &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
514 &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
515 &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
516 &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
517 &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
518 &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
519 &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
520 &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
521 &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
522 &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
523 &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
524 &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
525 &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
526 &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
527 &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
528 &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
529 &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
530 &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
531
532$code.=<<___;
533{ .mmb; add $h0=$h0,$E
534 nop.m 0
535 br.ctop.dptk.many .Ldtop };;
536.Ldend:
537{ .mmi; add tmp0=4,ctx
538 mov ar.lc=r3 };;
539{ .mmi; st4 [ctx]=$h0,8
540 st4 [tmp0]=$h1,8 };;
541{ .mmi; st4 [ctx]=$h2,8
542 st4 [tmp0]=$h3 };;
543{ .mib; st4 [ctx]=$h4,-16
544 mov pr=r2,0x1ffff
545 br.ret.sptk.many b0 };;
546.endp sha1_block_asm_data_order#
547___
548
549print $code;
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h
deleted file mode 100644
index 79c07b0fd1..0000000000
--- a/src/lib/libcrypto/sha/sha.h
+++ /dev/null
@@ -1,128 +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#include <openssl/e_os2.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))
69#error SHA is disabled.
70#endif
71
72#if defined(OPENSSL_FIPS)
73#define FIPS_SHA_SIZE_T unsigned long
74#endif
75
76/*
77 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
79 * ! SHA_LONG_LOG2 has to be defined along. !
80 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
81 */
82
83#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
84#define SHA_LONG unsigned long
85#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
86#define SHA_LONG unsigned long
87#define SHA_LONG_LOG2 3
88#else
89#define SHA_LONG unsigned int
90#endif
91
92#define SHA_LBLOCK 16
93#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a
94 * contiguous array of 32 bit
95 * wide big-endian values. */
96#define SHA_LAST_BLOCK (SHA_CBLOCK-8)
97#define SHA_DIGEST_LENGTH 20
98
99typedef struct SHAstate_st
100 {
101 SHA_LONG h0,h1,h2,h3,h4;
102 SHA_LONG Nl,Nh;
103 SHA_LONG data[SHA_LBLOCK];
104 int num;
105 } SHA_CTX;
106
107#ifndef OPENSSL_NO_SHA0
108#ifdef OPENSSL_FIPS
109int private_SHA_Init(SHA_CTX *c);
110#endif
111int SHA_Init(SHA_CTX *c);
112int SHA_Update(SHA_CTX *c, const void *data, unsigned long len);
113int SHA_Final(unsigned char *md, SHA_CTX *c);
114unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md);
115void SHA_Transform(SHA_CTX *c, const unsigned char *data);
116#endif
117#ifndef OPENSSL_NO_SHA1
118int SHA1_Init(SHA_CTX *c);
119int SHA1_Update(SHA_CTX *c, const void *data, unsigned long len);
120int SHA1_Final(unsigned char *md, SHA_CTX *c);
121unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md);
122void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
123#endif
124#ifdef __cplusplus
125}
126#endif
127
128#endif
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c
deleted file mode 100644
index f4694b701b..0000000000
--- a/src/lib/libcrypto/sha/sha1_one.c
+++ /dev/null
@@ -1,78 +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#include <openssl/crypto.h>
63
64#if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_FIPS)
65unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md)
66 {
67 SHA_CTX c;
68 static unsigned char m[SHA_DIGEST_LENGTH];
69
70 if (md == NULL) md=m;
71 if (!SHA1_Init(&c))
72 return NULL;
73 SHA1_Update(&c,d,n);
74 SHA1_Final(md,&c);
75 OPENSSL_cleanse(&c,sizeof(c));
76 return(md);
77 }
78#endif
diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c
deleted file mode 100644
index 1e2009b760..0000000000
--- a/src/lib/libcrypto/sha/sha1dgst.c
+++ /dev/null
@@ -1,81 +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(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA)
60
61#undef SHA_0
62#define SHA_1
63
64#include <openssl/opensslv.h>
65#include <openssl/opensslconf.h>
66
67#ifndef OPENSSL_FIPS
68const char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
69
70/* The implementation is in ../md32_common.h */
71
72#include "sha_locl.h"
73
74#else /* ndef OPENSSL_FIPS */
75
76static void *dummy=&dummy;
77
78#endif /* ndef OPENSSL_FIPS */
79
80#endif
81
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h
deleted file mode 100644
index a3623f72da..0000000000
--- a/src/lib/libcrypto/sha/sha_locl.h
+++ /dev/null
@@ -1,481 +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(__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# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
125# define sha1_block_host_order sha1_block_asm_host_order
126# define DONT_IMPLEMENT_BLOCK_HOST_ORDER
127# define sha1_block_data_order sha1_block_asm_data_order
128# define DONT_IMPLEMENT_BLOCK_DATA_ORDER
129# endif
130# endif
131 void sha1_block_host_order (SHA_CTX *c, const void *p,int num);
132 void sha1_block_data_order (SHA_CTX *c, const void *p,int num);
133
134#else
135# error "Either SHA_0 or SHA_1 must be defined."
136#endif
137
138#include "md32_common.h"
139
140#define INIT_DATA_h0 0x67452301UL
141#define INIT_DATA_h1 0xefcdab89UL
142#define INIT_DATA_h2 0x98badcfeUL
143#define INIT_DATA_h3 0x10325476UL
144#define INIT_DATA_h4 0xc3d2e1f0UL
145
146#if defined(SHA_0) && defined(OPENSSL_FIPS)
147FIPS_NON_FIPS_MD_Init(SHA)
148#else
149int HASH_INIT (SHA_CTX *c)
150#endif
151 {
152 c->h0=INIT_DATA_h0;
153 c->h1=INIT_DATA_h1;
154 c->h2=INIT_DATA_h2;
155 c->h3=INIT_DATA_h3;
156 c->h4=INIT_DATA_h4;
157 c->Nl=0;
158 c->Nh=0;
159 c->num=0;
160 return 1;
161 }
162
163#define K_00_19 0x5a827999UL
164#define K_20_39 0x6ed9eba1UL
165#define K_40_59 0x8f1bbcdcUL
166#define K_60_79 0xca62c1d6UL
167
168/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
169 * simplified to the code in F_00_19. Wei attributes these optimisations
170 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
171 * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
172 * I've just become aware of another tweak to be made, again from Wei Dai,
173 * in F_40_59, (x&a)|(y&a) -> (x|y)&a
174 */
175#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
176#define F_20_39(b,c,d) ((b) ^ (c) ^ (d))
177#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
178#define F_60_79(b,c,d) F_20_39(b,c,d)
179
180#define BODY_00_15(i,a,b,c,d,e,f,xi) \
181 (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
182 (b)=ROTATE((b),30);
183
184#define BODY_16_19(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
185 Xupdate(f,xi,xa,xb,xc,xd); \
186 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
187 (b)=ROTATE((b),30);
188
189#define BODY_20_31(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
190 Xupdate(f,xi,xa,xb,xc,xd); \
191 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
192 (b)=ROTATE((b),30);
193
194#define BODY_32_39(i,a,b,c,d,e,f,xa,xb,xc,xd) \
195 Xupdate(f,xa,xa,xb,xc,xd); \
196 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
197 (b)=ROTATE((b),30);
198
199#define BODY_40_59(i,a,b,c,d,e,f,xa,xb,xc,xd) \
200 Xupdate(f,xa,xa,xb,xc,xd); \
201 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
202 (b)=ROTATE((b),30);
203
204#define BODY_60_79(i,a,b,c,d,e,f,xa,xb,xc,xd) \
205 Xupdate(f,xa,xa,xb,xc,xd); \
206 (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
207 (b)=ROTATE((b),30);
208
209#ifdef X
210#undef X
211#endif
212#ifndef MD32_XARRAY
213 /*
214 * Originally X was an array. As it's automatic it's natural
215 * to expect RISC compiler to accomodate at least part of it in
216 * the register bank, isn't it? Unfortunately not all compilers
217 * "find" this expectation reasonable:-( On order to make such
218 * compilers generate better code I replace X[] with a bunch of
219 * X0, X1, etc. See the function body below...
220 * <appro@fy.chalmers.se>
221 */
222# define X(i) XX##i
223#else
224 /*
225 * However! Some compilers (most notably HP C) get overwhelmed by
226 * that many local variables so that we have to have the way to
227 * fall down to the original behavior.
228 */
229# define X(i) XX[i]
230#endif
231
232#ifndef DONT_IMPLEMENT_BLOCK_HOST_ORDER
233void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num)
234 {
235 const SHA_LONG *W=d;
236 register unsigned MD32_REG_T A,B,C,D,E,T;
237#ifndef MD32_XARRAY
238 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
239 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
240#else
241 SHA_LONG XX[16];
242#endif
243
244 A=c->h0;
245 B=c->h1;
246 C=c->h2;
247 D=c->h3;
248 E=c->h4;
249
250 for (;;)
251 {
252 BODY_00_15( 0,A,B,C,D,E,T,W[ 0]);
253 BODY_00_15( 1,T,A,B,C,D,E,W[ 1]);
254 BODY_00_15( 2,E,T,A,B,C,D,W[ 2]);
255 BODY_00_15( 3,D,E,T,A,B,C,W[ 3]);
256 BODY_00_15( 4,C,D,E,T,A,B,W[ 4]);
257 BODY_00_15( 5,B,C,D,E,T,A,W[ 5]);
258 BODY_00_15( 6,A,B,C,D,E,T,W[ 6]);
259 BODY_00_15( 7,T,A,B,C,D,E,W[ 7]);
260 BODY_00_15( 8,E,T,A,B,C,D,W[ 8]);
261 BODY_00_15( 9,D,E,T,A,B,C,W[ 9]);
262 BODY_00_15(10,C,D,E,T,A,B,W[10]);
263 BODY_00_15(11,B,C,D,E,T,A,W[11]);
264 BODY_00_15(12,A,B,C,D,E,T,W[12]);
265 BODY_00_15(13,T,A,B,C,D,E,W[13]);
266 BODY_00_15(14,E,T,A,B,C,D,W[14]);
267 BODY_00_15(15,D,E,T,A,B,C,W[15]);
268
269 BODY_16_19(16,C,D,E,T,A,B,X( 0),W[ 0],W[ 2],W[ 8],W[13]);
270 BODY_16_19(17,B,C,D,E,T,A,X( 1),W[ 1],W[ 3],W[ 9],W[14]);
271 BODY_16_19(18,A,B,C,D,E,T,X( 2),W[ 2],W[ 4],W[10],W[15]);
272 BODY_16_19(19,T,A,B,C,D,E,X( 3),W[ 3],W[ 5],W[11],X( 0));
273
274 BODY_20_31(20,E,T,A,B,C,D,X( 4),W[ 4],W[ 6],W[12],X( 1));
275 BODY_20_31(21,D,E,T,A,B,C,X( 5),W[ 5],W[ 7],W[13],X( 2));
276 BODY_20_31(22,C,D,E,T,A,B,X( 6),W[ 6],W[ 8],W[14],X( 3));
277 BODY_20_31(23,B,C,D,E,T,A,X( 7),W[ 7],W[ 9],W[15],X( 4));
278 BODY_20_31(24,A,B,C,D,E,T,X( 8),W[ 8],W[10],X( 0),X( 5));
279 BODY_20_31(25,T,A,B,C,D,E,X( 9),W[ 9],W[11],X( 1),X( 6));
280 BODY_20_31(26,E,T,A,B,C,D,X(10),W[10],W[12],X( 2),X( 7));
281 BODY_20_31(27,D,E,T,A,B,C,X(11),W[11],W[13],X( 3),X( 8));
282 BODY_20_31(28,C,D,E,T,A,B,X(12),W[12],W[14],X( 4),X( 9));
283 BODY_20_31(29,B,C,D,E,T,A,X(13),W[13],W[15],X( 5),X(10));
284 BODY_20_31(30,A,B,C,D,E,T,X(14),W[14],X( 0),X( 6),X(11));
285 BODY_20_31(31,T,A,B,C,D,E,X(15),W[15],X( 1),X( 7),X(12));
286
287 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
288 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
289 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
290 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
291 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
292 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
293 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
294 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
295
296 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
297 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
298 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
299 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
300 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
301 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
302 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
303 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
304 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
305 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
306 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
307 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
308 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
309 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
310 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
311 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
312 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
313 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
314 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
315 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
316
317 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
318 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
319 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
320 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
321 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
322 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
323 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
324 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
325 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
326 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
327 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
328 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
329 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
330 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
331 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
332 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
333 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
334 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
335 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
336 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
337
338 c->h0=(c->h0+E)&0xffffffffL;
339 c->h1=(c->h1+T)&0xffffffffL;
340 c->h2=(c->h2+A)&0xffffffffL;
341 c->h3=(c->h3+B)&0xffffffffL;
342 c->h4=(c->h4+C)&0xffffffffL;
343
344 if (--num <= 0) break;
345
346 A=c->h0;
347 B=c->h1;
348 C=c->h2;
349 D=c->h3;
350 E=c->h4;
351
352 W+=SHA_LBLOCK;
353 }
354 }
355#endif
356
357#ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER
358void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num)
359 {
360 const unsigned char *data=p;
361 register unsigned MD32_REG_T A,B,C,D,E,T,l;
362#ifndef MD32_XARRAY
363 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
364 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
365#else
366 SHA_LONG XX[16];
367#endif
368
369 A=c->h0;
370 B=c->h1;
371 C=c->h2;
372 D=c->h3;
373 E=c->h4;
374
375 for (;;)
376 {
377
378 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
379 BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l;
380 BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l;
381 BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l;
382 BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l;
383 BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l;
384 BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l;
385 BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l;
386 BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l;
387 BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l;
388 BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l;
389 BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l;
390 BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l;
391 BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l;
392 BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l;
393 BODY_00_15(14,E,T,A,B,C,D,X(14));
394 BODY_00_15(15,D,E,T,A,B,C,X(15));
395
396 BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13));
397 BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14));
398 BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15));
399 BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0));
400
401 BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1));
402 BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2));
403 BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3));
404 BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4));
405 BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5));
406 BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6));
407 BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7));
408 BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8));
409 BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9));
410 BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10));
411 BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11));
412 BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12));
413
414 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
415 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
416 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
417 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
418 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
419 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
420 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
421 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
422
423 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
424 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
425 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
426 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
427 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
428 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
429 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
430 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
431 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
432 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
433 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
434 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
435 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
436 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
437 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
438 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
439 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
440 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
441 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
442 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
443
444 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
445 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
446 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
447 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
448 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
449 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
450 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
451 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
452 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
453 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
454 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
455 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
456 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
457 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
458 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
459 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
460 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
461 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
462 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
463 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
464
465 c->h0=(c->h0+E)&0xffffffffL;
466 c->h1=(c->h1+T)&0xffffffffL;
467 c->h2=(c->h2+A)&0xffffffffL;
468 c->h3=(c->h3+B)&0xffffffffL;
469 c->h4=(c->h4+C)&0xffffffffL;
470
471 if (--num <= 0) break;
472
473 A=c->h0;
474 B=c->h1;
475 C=c->h2;
476 D=c->h3;
477 E=c->h4;
478
479 }
480 }
481#endif
diff --git a/src/lib/libcrypto/stack/safestack.h b/src/lib/libcrypto/stack/safestack.h
deleted file mode 100644
index 6010b7f122..0000000000
--- a/src/lib/libcrypto/stack/safestack.h
+++ /dev/null
@@ -1,1574 +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
58typedef void (*openssl_fptr)(void);
59#define openssl_fcast(f) ((openssl_fptr)f)
60
61#include <openssl/stack.h>
62
63#ifdef DEBUG_SAFESTACK
64
65#define STACK_OF(type) struct stack_st_##type
66#define PREDECLARE_STACK_OF(type) STACK_OF(type);
67
68#define DECLARE_STACK_OF(type) \
69STACK_OF(type) \
70 { \
71 STACK stack; \
72 };
73
74#define IMPLEMENT_STACK_OF(type) /* nada (obsolete in new safestack approach)*/
75
76/* SKM_sk_... stack macros are internal to safestack.h:
77 * never use them directly, use sk_<type>_... instead */
78#define SKM_sk_new(type, cmp) \
79 ((STACK_OF(type) * (*)(int (*)(const type * const *, const type * const *)))openssl_fcast(sk_new))(cmp)
80#define SKM_sk_new_null(type) \
81 ((STACK_OF(type) * (*)(void))openssl_fcast(sk_new_null))()
82#define SKM_sk_free(type, st) \
83 ((void (*)(STACK_OF(type) *))openssl_fcast(sk_free))(st)
84#define SKM_sk_num(type, st) \
85 ((int (*)(const STACK_OF(type) *))openssl_fcast(sk_num))(st)
86#define SKM_sk_value(type, st,i) \
87 ((type * (*)(const STACK_OF(type) *, int))openssl_fcast(sk_value))(st, i)
88#define SKM_sk_set(type, st,i,val) \
89 ((type * (*)(STACK_OF(type) *, int, type *))openssl_fcast(sk_set))(st, i, val)
90#define SKM_sk_zero(type, st) \
91 ((void (*)(STACK_OF(type) *))openssl_fcast(sk_zero))(st)
92#define SKM_sk_push(type, st,val) \
93 ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_push))(st, val)
94#define SKM_sk_unshift(type, st,val) \
95 ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_unshift))(st, val)
96#define SKM_sk_find(type, st,val) \
97 ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_find))(st, val)
98#define SKM_sk_delete(type, st,i) \
99 ((type * (*)(STACK_OF(type) *, int))openssl_fcast(sk_delete))(st, i)
100#define SKM_sk_delete_ptr(type, st,ptr) \
101 ((type * (*)(STACK_OF(type) *, type *))openssl_fcast(sk_delete_ptr))(st, ptr)
102#define SKM_sk_insert(type, st,val,i) \
103 ((int (*)(STACK_OF(type) *, type *, int))openssl_fcast(sk_insert))(st, val, i)
104#define SKM_sk_set_cmp_func(type, st,cmp) \
105 ((int (*(*)(STACK_OF(type) *, int (*)(const type * const *, const type * const *))) \
106 (const type * const *, const type * const *))openssl_fcast(sk_set_cmp_func))\
107 (st, cmp)
108#define SKM_sk_dup(type, st) \
109 ((STACK_OF(type) *(*)(STACK_OF(type) *))openssl_fcast(sk_dup))(st)
110#define SKM_sk_pop_free(type, st,free_func) \
111 ((void (*)(STACK_OF(type) *, void (*)(type *)))openssl_fcast(sk_pop_free))\
112 (st, free_func)
113#define SKM_sk_shift(type, st) \
114 ((type * (*)(STACK_OF(type) *))openssl_fcast(sk_shift))(st)
115#define SKM_sk_pop(type, st) \
116 ((type * (*)(STACK_OF(type) *))openssl_fcast(sk_pop))(st)
117#define SKM_sk_sort(type, st) \
118 ((void (*)(STACK_OF(type) *))openssl_fcast(sk_sort))(st)
119#define SKM_sk_is_sorted(type, st) \
120 ((int (*)(const STACK_OF(type) *))openssl_fcast(sk_is_sorted))(st)
121
122#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
123 ((STACK_OF(type) * (*) (STACK_OF(type) **,unsigned char **, long , \
124 type *(*)(type **, unsigned char **,long), \
125 void (*)(type *), int ,int )) openssl_fcast(d2i_ASN1_SET)) \
126 (st,pp,length, d2i_func, free_func, ex_tag,ex_class)
127#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
128 ((int (*)(STACK_OF(type) *,unsigned char **, \
129 int (*)(type *,unsigned char **), int , int , int)) openssl_fcast(i2d_ASN1_SET)) \
130 (st,pp,i2d_func,ex_tag,ex_class,is_set)
131
132#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \
133 ((unsigned char *(*)(STACK_OF(type) *, \
134 int (*)(type *,unsigned char **), unsigned char **,int *)) openssl_fcast(ASN1_seq_pack)) \
135 (st, i2d_func, buf, len)
136#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \
137 ((STACK_OF(type) * (*)(unsigned char *,int, \
138 type *(*)(type **,unsigned char **, long), \
139 void (*)(type *)))openssl_fcast(ASN1_seq_unpack)) \
140 (buf,len,d2i_func, free_func)
141
142#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \
143 ((STACK_OF(type) * (*)(X509_ALGOR *, \
144 type *(*)(type **, unsigned char **, long), void (*)(type *), \
145 const char *, int, \
146 ASN1_STRING *, int))openssl_fcast(PKCS12_decrypt_d2i)) \
147 (algor,d2i_func,free_func,pass,passlen,oct,seq)
148
149#else
150
151#define STACK_OF(type) STACK
152#define PREDECLARE_STACK_OF(type) /* nada */
153#define DECLARE_STACK_OF(type) /* nada */
154#define IMPLEMENT_STACK_OF(type) /* nada */
155
156#define SKM_sk_new(type, cmp) \
157 sk_new((int (*)(const char * const *, const char * const *))(cmp))
158#define SKM_sk_new_null(type) \
159 sk_new_null()
160#define SKM_sk_free(type, st) \
161 sk_free(st)
162#define SKM_sk_num(type, st) \
163 sk_num(st)
164#define SKM_sk_value(type, st,i) \
165 ((type *)sk_value(st, i))
166#define SKM_sk_set(type, st,i,val) \
167 ((type *)sk_set(st, i,(char *)val))
168#define SKM_sk_zero(type, st) \
169 sk_zero(st)
170#define SKM_sk_push(type, st,val) \
171 sk_push(st, (char *)val)
172#define SKM_sk_unshift(type, st,val) \
173 sk_unshift(st, val)
174#define SKM_sk_find(type, st,val) \
175 sk_find(st, (char *)val)
176#define SKM_sk_delete(type, st,i) \
177 ((type *)sk_delete(st, i))
178#define SKM_sk_delete_ptr(type, st,ptr) \
179 ((type *)sk_delete_ptr(st,(char *)ptr))
180#define SKM_sk_insert(type, st,val,i) \
181 sk_insert(st, (char *)val, i)
182#define SKM_sk_set_cmp_func(type, st,cmp) \
183 ((int (*)(const type * const *,const type * const *)) \
184 sk_set_cmp_func(st, (int (*)(const char * const *, const char * const *))(cmp)))
185#define SKM_sk_dup(type, st) \
186 sk_dup(st)
187#define SKM_sk_pop_free(type, st,free_func) \
188 sk_pop_free(st, (void (*)(void *))free_func)
189#define SKM_sk_shift(type, st) \
190 ((type *)sk_shift(st))
191#define SKM_sk_pop(type, st) \
192 ((type *)sk_pop(st))
193#define SKM_sk_sort(type, st) \
194 sk_sort(st)
195#define SKM_sk_is_sorted(type, st) \
196 sk_is_sorted(st)
197
198#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
199 d2i_ASN1_SET(st,pp,length, (char *(*)())d2i_func, (void (*)(void *))free_func, ex_tag,ex_class)
200#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
201 i2d_ASN1_SET(st,pp,i2d_func,ex_tag,ex_class,is_set)
202
203#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \
204 ASN1_seq_pack(st, i2d_func, buf, len)
205#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \
206 ASN1_seq_unpack(buf,len,(char *(*)())d2i_func, (void(*)(void *))free_func)
207
208#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \
209 ((STACK *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i_func, (void(*)(void *))free_func,pass,passlen,oct,seq))
210
211#endif
212
213/* This block of defines is updated by util/mkstack.pl, please do not touch! */
214#define sk_ACCESS_DESCRIPTION_new(st) SKM_sk_new(ACCESS_DESCRIPTION, (st))
215#define sk_ACCESS_DESCRIPTION_new_null() SKM_sk_new_null(ACCESS_DESCRIPTION)
216#define sk_ACCESS_DESCRIPTION_free(st) SKM_sk_free(ACCESS_DESCRIPTION, (st))
217#define sk_ACCESS_DESCRIPTION_num(st) SKM_sk_num(ACCESS_DESCRIPTION, (st))
218#define sk_ACCESS_DESCRIPTION_value(st, i) SKM_sk_value(ACCESS_DESCRIPTION, (st), (i))
219#define sk_ACCESS_DESCRIPTION_set(st, i, val) SKM_sk_set(ACCESS_DESCRIPTION, (st), (i), (val))
220#define sk_ACCESS_DESCRIPTION_zero(st) SKM_sk_zero(ACCESS_DESCRIPTION, (st))
221#define sk_ACCESS_DESCRIPTION_push(st, val) SKM_sk_push(ACCESS_DESCRIPTION, (st), (val))
222#define sk_ACCESS_DESCRIPTION_unshift(st, val) SKM_sk_unshift(ACCESS_DESCRIPTION, (st), (val))
223#define sk_ACCESS_DESCRIPTION_find(st, val) SKM_sk_find(ACCESS_DESCRIPTION, (st), (val))
224#define sk_ACCESS_DESCRIPTION_delete(st, i) SKM_sk_delete(ACCESS_DESCRIPTION, (st), (i))
225#define sk_ACCESS_DESCRIPTION_delete_ptr(st, ptr) SKM_sk_delete_ptr(ACCESS_DESCRIPTION, (st), (ptr))
226#define sk_ACCESS_DESCRIPTION_insert(st, val, i) SKM_sk_insert(ACCESS_DESCRIPTION, (st), (val), (i))
227#define sk_ACCESS_DESCRIPTION_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ACCESS_DESCRIPTION, (st), (cmp))
228#define sk_ACCESS_DESCRIPTION_dup(st) SKM_sk_dup(ACCESS_DESCRIPTION, st)
229#define sk_ACCESS_DESCRIPTION_pop_free(st, free_func) SKM_sk_pop_free(ACCESS_DESCRIPTION, (st), (free_func))
230#define sk_ACCESS_DESCRIPTION_shift(st) SKM_sk_shift(ACCESS_DESCRIPTION, (st))
231#define sk_ACCESS_DESCRIPTION_pop(st) SKM_sk_pop(ACCESS_DESCRIPTION, (st))
232#define sk_ACCESS_DESCRIPTION_sort(st) SKM_sk_sort(ACCESS_DESCRIPTION, (st))
233#define sk_ACCESS_DESCRIPTION_is_sorted(st) SKM_sk_is_sorted(ACCESS_DESCRIPTION, (st))
234
235#define sk_ASN1_GENERALSTRING_new(st) SKM_sk_new(ASN1_GENERALSTRING, (st))
236#define sk_ASN1_GENERALSTRING_new_null() SKM_sk_new_null(ASN1_GENERALSTRING)
237#define sk_ASN1_GENERALSTRING_free(st) SKM_sk_free(ASN1_GENERALSTRING, (st))
238#define sk_ASN1_GENERALSTRING_num(st) SKM_sk_num(ASN1_GENERALSTRING, (st))
239#define sk_ASN1_GENERALSTRING_value(st, i) SKM_sk_value(ASN1_GENERALSTRING, (st), (i))
240#define sk_ASN1_GENERALSTRING_set(st, i, val) SKM_sk_set(ASN1_GENERALSTRING, (st), (i), (val))
241#define sk_ASN1_GENERALSTRING_zero(st) SKM_sk_zero(ASN1_GENERALSTRING, (st))
242#define sk_ASN1_GENERALSTRING_push(st, val) SKM_sk_push(ASN1_GENERALSTRING, (st), (val))
243#define sk_ASN1_GENERALSTRING_unshift(st, val) SKM_sk_unshift(ASN1_GENERALSTRING, (st), (val))
244#define sk_ASN1_GENERALSTRING_find(st, val) SKM_sk_find(ASN1_GENERALSTRING, (st), (val))
245#define sk_ASN1_GENERALSTRING_delete(st, i) SKM_sk_delete(ASN1_GENERALSTRING, (st), (i))
246#define sk_ASN1_GENERALSTRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_GENERALSTRING, (st), (ptr))
247#define sk_ASN1_GENERALSTRING_insert(st, val, i) SKM_sk_insert(ASN1_GENERALSTRING, (st), (val), (i))
248#define sk_ASN1_GENERALSTRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_GENERALSTRING, (st), (cmp))
249#define sk_ASN1_GENERALSTRING_dup(st) SKM_sk_dup(ASN1_GENERALSTRING, st)
250#define sk_ASN1_GENERALSTRING_pop_free(st, free_func) SKM_sk_pop_free(ASN1_GENERALSTRING, (st), (free_func))
251#define sk_ASN1_GENERALSTRING_shift(st) SKM_sk_shift(ASN1_GENERALSTRING, (st))
252#define sk_ASN1_GENERALSTRING_pop(st) SKM_sk_pop(ASN1_GENERALSTRING, (st))
253#define sk_ASN1_GENERALSTRING_sort(st) SKM_sk_sort(ASN1_GENERALSTRING, (st))
254#define sk_ASN1_GENERALSTRING_is_sorted(st) SKM_sk_is_sorted(ASN1_GENERALSTRING, (st))
255
256#define sk_ASN1_INTEGER_new(st) SKM_sk_new(ASN1_INTEGER, (st))
257#define sk_ASN1_INTEGER_new_null() SKM_sk_new_null(ASN1_INTEGER)
258#define sk_ASN1_INTEGER_free(st) SKM_sk_free(ASN1_INTEGER, (st))
259#define sk_ASN1_INTEGER_num(st) SKM_sk_num(ASN1_INTEGER, (st))
260#define sk_ASN1_INTEGER_value(st, i) SKM_sk_value(ASN1_INTEGER, (st), (i))
261#define sk_ASN1_INTEGER_set(st, i, val) SKM_sk_set(ASN1_INTEGER, (st), (i), (val))
262#define sk_ASN1_INTEGER_zero(st) SKM_sk_zero(ASN1_INTEGER, (st))
263#define sk_ASN1_INTEGER_push(st, val) SKM_sk_push(ASN1_INTEGER, (st), (val))
264#define sk_ASN1_INTEGER_unshift(st, val) SKM_sk_unshift(ASN1_INTEGER, (st), (val))
265#define sk_ASN1_INTEGER_find(st, val) SKM_sk_find(ASN1_INTEGER, (st), (val))
266#define sk_ASN1_INTEGER_delete(st, i) SKM_sk_delete(ASN1_INTEGER, (st), (i))
267#define sk_ASN1_INTEGER_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_INTEGER, (st), (ptr))
268#define sk_ASN1_INTEGER_insert(st, val, i) SKM_sk_insert(ASN1_INTEGER, (st), (val), (i))
269#define sk_ASN1_INTEGER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_INTEGER, (st), (cmp))
270#define sk_ASN1_INTEGER_dup(st) SKM_sk_dup(ASN1_INTEGER, st)
271#define sk_ASN1_INTEGER_pop_free(st, free_func) SKM_sk_pop_free(ASN1_INTEGER, (st), (free_func))
272#define sk_ASN1_INTEGER_shift(st) SKM_sk_shift(ASN1_INTEGER, (st))
273#define sk_ASN1_INTEGER_pop(st) SKM_sk_pop(ASN1_INTEGER, (st))
274#define sk_ASN1_INTEGER_sort(st) SKM_sk_sort(ASN1_INTEGER, (st))
275#define sk_ASN1_INTEGER_is_sorted(st) SKM_sk_is_sorted(ASN1_INTEGER, (st))
276
277#define sk_ASN1_OBJECT_new(st) SKM_sk_new(ASN1_OBJECT, (st))
278#define sk_ASN1_OBJECT_new_null() SKM_sk_new_null(ASN1_OBJECT)
279#define sk_ASN1_OBJECT_free(st) SKM_sk_free(ASN1_OBJECT, (st))
280#define sk_ASN1_OBJECT_num(st) SKM_sk_num(ASN1_OBJECT, (st))
281#define sk_ASN1_OBJECT_value(st, i) SKM_sk_value(ASN1_OBJECT, (st), (i))
282#define sk_ASN1_OBJECT_set(st, i, val) SKM_sk_set(ASN1_OBJECT, (st), (i), (val))
283#define sk_ASN1_OBJECT_zero(st) SKM_sk_zero(ASN1_OBJECT, (st))
284#define sk_ASN1_OBJECT_push(st, val) SKM_sk_push(ASN1_OBJECT, (st), (val))
285#define sk_ASN1_OBJECT_unshift(st, val) SKM_sk_unshift(ASN1_OBJECT, (st), (val))
286#define sk_ASN1_OBJECT_find(st, val) SKM_sk_find(ASN1_OBJECT, (st), (val))
287#define sk_ASN1_OBJECT_delete(st, i) SKM_sk_delete(ASN1_OBJECT, (st), (i))
288#define sk_ASN1_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_OBJECT, (st), (ptr))
289#define sk_ASN1_OBJECT_insert(st, val, i) SKM_sk_insert(ASN1_OBJECT, (st), (val), (i))
290#define sk_ASN1_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_OBJECT, (st), (cmp))
291#define sk_ASN1_OBJECT_dup(st) SKM_sk_dup(ASN1_OBJECT, st)
292#define sk_ASN1_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(ASN1_OBJECT, (st), (free_func))
293#define sk_ASN1_OBJECT_shift(st) SKM_sk_shift(ASN1_OBJECT, (st))
294#define sk_ASN1_OBJECT_pop(st) SKM_sk_pop(ASN1_OBJECT, (st))
295#define sk_ASN1_OBJECT_sort(st) SKM_sk_sort(ASN1_OBJECT, (st))
296#define sk_ASN1_OBJECT_is_sorted(st) SKM_sk_is_sorted(ASN1_OBJECT, (st))
297
298#define sk_ASN1_STRING_TABLE_new(st) SKM_sk_new(ASN1_STRING_TABLE, (st))
299#define sk_ASN1_STRING_TABLE_new_null() SKM_sk_new_null(ASN1_STRING_TABLE)
300#define sk_ASN1_STRING_TABLE_free(st) SKM_sk_free(ASN1_STRING_TABLE, (st))
301#define sk_ASN1_STRING_TABLE_num(st) SKM_sk_num(ASN1_STRING_TABLE, (st))
302#define sk_ASN1_STRING_TABLE_value(st, i) SKM_sk_value(ASN1_STRING_TABLE, (st), (i))
303#define sk_ASN1_STRING_TABLE_set(st, i, val) SKM_sk_set(ASN1_STRING_TABLE, (st), (i), (val))
304#define sk_ASN1_STRING_TABLE_zero(st) SKM_sk_zero(ASN1_STRING_TABLE, (st))
305#define sk_ASN1_STRING_TABLE_push(st, val) SKM_sk_push(ASN1_STRING_TABLE, (st), (val))
306#define sk_ASN1_STRING_TABLE_unshift(st, val) SKM_sk_unshift(ASN1_STRING_TABLE, (st), (val))
307#define sk_ASN1_STRING_TABLE_find(st, val) SKM_sk_find(ASN1_STRING_TABLE, (st), (val))
308#define sk_ASN1_STRING_TABLE_delete(st, i) SKM_sk_delete(ASN1_STRING_TABLE, (st), (i))
309#define sk_ASN1_STRING_TABLE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_STRING_TABLE, (st), (ptr))
310#define sk_ASN1_STRING_TABLE_insert(st, val, i) SKM_sk_insert(ASN1_STRING_TABLE, (st), (val), (i))
311#define sk_ASN1_STRING_TABLE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_STRING_TABLE, (st), (cmp))
312#define sk_ASN1_STRING_TABLE_dup(st) SKM_sk_dup(ASN1_STRING_TABLE, st)
313#define sk_ASN1_STRING_TABLE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_STRING_TABLE, (st), (free_func))
314#define sk_ASN1_STRING_TABLE_shift(st) SKM_sk_shift(ASN1_STRING_TABLE, (st))
315#define sk_ASN1_STRING_TABLE_pop(st) SKM_sk_pop(ASN1_STRING_TABLE, (st))
316#define sk_ASN1_STRING_TABLE_sort(st) SKM_sk_sort(ASN1_STRING_TABLE, (st))
317#define sk_ASN1_STRING_TABLE_is_sorted(st) SKM_sk_is_sorted(ASN1_STRING_TABLE, (st))
318
319#define sk_ASN1_TYPE_new(st) SKM_sk_new(ASN1_TYPE, (st))
320#define sk_ASN1_TYPE_new_null() SKM_sk_new_null(ASN1_TYPE)
321#define sk_ASN1_TYPE_free(st) SKM_sk_free(ASN1_TYPE, (st))
322#define sk_ASN1_TYPE_num(st) SKM_sk_num(ASN1_TYPE, (st))
323#define sk_ASN1_TYPE_value(st, i) SKM_sk_value(ASN1_TYPE, (st), (i))
324#define sk_ASN1_TYPE_set(st, i, val) SKM_sk_set(ASN1_TYPE, (st), (i), (val))
325#define sk_ASN1_TYPE_zero(st) SKM_sk_zero(ASN1_TYPE, (st))
326#define sk_ASN1_TYPE_push(st, val) SKM_sk_push(ASN1_TYPE, (st), (val))
327#define sk_ASN1_TYPE_unshift(st, val) SKM_sk_unshift(ASN1_TYPE, (st), (val))
328#define sk_ASN1_TYPE_find(st, val) SKM_sk_find(ASN1_TYPE, (st), (val))
329#define sk_ASN1_TYPE_delete(st, i) SKM_sk_delete(ASN1_TYPE, (st), (i))
330#define sk_ASN1_TYPE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_TYPE, (st), (ptr))
331#define sk_ASN1_TYPE_insert(st, val, i) SKM_sk_insert(ASN1_TYPE, (st), (val), (i))
332#define sk_ASN1_TYPE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_TYPE, (st), (cmp))
333#define sk_ASN1_TYPE_dup(st) SKM_sk_dup(ASN1_TYPE, st)
334#define sk_ASN1_TYPE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_TYPE, (st), (free_func))
335#define sk_ASN1_TYPE_shift(st) SKM_sk_shift(ASN1_TYPE, (st))
336#define sk_ASN1_TYPE_pop(st) SKM_sk_pop(ASN1_TYPE, (st))
337#define sk_ASN1_TYPE_sort(st) SKM_sk_sort(ASN1_TYPE, (st))
338#define sk_ASN1_TYPE_is_sorted(st) SKM_sk_is_sorted(ASN1_TYPE, (st))
339
340#define sk_ASN1_VALUE_new(st) SKM_sk_new(ASN1_VALUE, (st))
341#define sk_ASN1_VALUE_new_null() SKM_sk_new_null(ASN1_VALUE)
342#define sk_ASN1_VALUE_free(st) SKM_sk_free(ASN1_VALUE, (st))
343#define sk_ASN1_VALUE_num(st) SKM_sk_num(ASN1_VALUE, (st))
344#define sk_ASN1_VALUE_value(st, i) SKM_sk_value(ASN1_VALUE, (st), (i))
345#define sk_ASN1_VALUE_set(st, i, val) SKM_sk_set(ASN1_VALUE, (st), (i), (val))
346#define sk_ASN1_VALUE_zero(st) SKM_sk_zero(ASN1_VALUE, (st))
347#define sk_ASN1_VALUE_push(st, val) SKM_sk_push(ASN1_VALUE, (st), (val))
348#define sk_ASN1_VALUE_unshift(st, val) SKM_sk_unshift(ASN1_VALUE, (st), (val))
349#define sk_ASN1_VALUE_find(st, val) SKM_sk_find(ASN1_VALUE, (st), (val))
350#define sk_ASN1_VALUE_delete(st, i) SKM_sk_delete(ASN1_VALUE, (st), (i))
351#define sk_ASN1_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_VALUE, (st), (ptr))
352#define sk_ASN1_VALUE_insert(st, val, i) SKM_sk_insert(ASN1_VALUE, (st), (val), (i))
353#define sk_ASN1_VALUE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASN1_VALUE, (st), (cmp))
354#define sk_ASN1_VALUE_dup(st) SKM_sk_dup(ASN1_VALUE, st)
355#define sk_ASN1_VALUE_pop_free(st, free_func) SKM_sk_pop_free(ASN1_VALUE, (st), (free_func))
356#define sk_ASN1_VALUE_shift(st) SKM_sk_shift(ASN1_VALUE, (st))
357#define sk_ASN1_VALUE_pop(st) SKM_sk_pop(ASN1_VALUE, (st))
358#define sk_ASN1_VALUE_sort(st) SKM_sk_sort(ASN1_VALUE, (st))
359#define sk_ASN1_VALUE_is_sorted(st) SKM_sk_is_sorted(ASN1_VALUE, (st))
360
361#define sk_BIO_new(st) SKM_sk_new(BIO, (st))
362#define sk_BIO_new_null() SKM_sk_new_null(BIO)
363#define sk_BIO_free(st) SKM_sk_free(BIO, (st))
364#define sk_BIO_num(st) SKM_sk_num(BIO, (st))
365#define sk_BIO_value(st, i) SKM_sk_value(BIO, (st), (i))
366#define sk_BIO_set(st, i, val) SKM_sk_set(BIO, (st), (i), (val))
367#define sk_BIO_zero(st) SKM_sk_zero(BIO, (st))
368#define sk_BIO_push(st, val) SKM_sk_push(BIO, (st), (val))
369#define sk_BIO_unshift(st, val) SKM_sk_unshift(BIO, (st), (val))
370#define sk_BIO_find(st, val) SKM_sk_find(BIO, (st), (val))
371#define sk_BIO_delete(st, i) SKM_sk_delete(BIO, (st), (i))
372#define sk_BIO_delete_ptr(st, ptr) SKM_sk_delete_ptr(BIO, (st), (ptr))
373#define sk_BIO_insert(st, val, i) SKM_sk_insert(BIO, (st), (val), (i))
374#define sk_BIO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(BIO, (st), (cmp))
375#define sk_BIO_dup(st) SKM_sk_dup(BIO, st)
376#define sk_BIO_pop_free(st, free_func) SKM_sk_pop_free(BIO, (st), (free_func))
377#define sk_BIO_shift(st) SKM_sk_shift(BIO, (st))
378#define sk_BIO_pop(st) SKM_sk_pop(BIO, (st))
379#define sk_BIO_sort(st) SKM_sk_sort(BIO, (st))
380#define sk_BIO_is_sorted(st) SKM_sk_is_sorted(BIO, (st))
381
382#define sk_CONF_IMODULE_new(st) SKM_sk_new(CONF_IMODULE, (st))
383#define sk_CONF_IMODULE_new_null() SKM_sk_new_null(CONF_IMODULE)
384#define sk_CONF_IMODULE_free(st) SKM_sk_free(CONF_IMODULE, (st))
385#define sk_CONF_IMODULE_num(st) SKM_sk_num(CONF_IMODULE, (st))
386#define sk_CONF_IMODULE_value(st, i) SKM_sk_value(CONF_IMODULE, (st), (i))
387#define sk_CONF_IMODULE_set(st, i, val) SKM_sk_set(CONF_IMODULE, (st), (i), (val))
388#define sk_CONF_IMODULE_zero(st) SKM_sk_zero(CONF_IMODULE, (st))
389#define sk_CONF_IMODULE_push(st, val) SKM_sk_push(CONF_IMODULE, (st), (val))
390#define sk_CONF_IMODULE_unshift(st, val) SKM_sk_unshift(CONF_IMODULE, (st), (val))
391#define sk_CONF_IMODULE_find(st, val) SKM_sk_find(CONF_IMODULE, (st), (val))
392#define sk_CONF_IMODULE_delete(st, i) SKM_sk_delete(CONF_IMODULE, (st), (i))
393#define sk_CONF_IMODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_IMODULE, (st), (ptr))
394#define sk_CONF_IMODULE_insert(st, val, i) SKM_sk_insert(CONF_IMODULE, (st), (val), (i))
395#define sk_CONF_IMODULE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_IMODULE, (st), (cmp))
396#define sk_CONF_IMODULE_dup(st) SKM_sk_dup(CONF_IMODULE, st)
397#define sk_CONF_IMODULE_pop_free(st, free_func) SKM_sk_pop_free(CONF_IMODULE, (st), (free_func))
398#define sk_CONF_IMODULE_shift(st) SKM_sk_shift(CONF_IMODULE, (st))
399#define sk_CONF_IMODULE_pop(st) SKM_sk_pop(CONF_IMODULE, (st))
400#define sk_CONF_IMODULE_sort(st) SKM_sk_sort(CONF_IMODULE, (st))
401#define sk_CONF_IMODULE_is_sorted(st) SKM_sk_is_sorted(CONF_IMODULE, (st))
402
403#define sk_CONF_MODULE_new(st) SKM_sk_new(CONF_MODULE, (st))
404#define sk_CONF_MODULE_new_null() SKM_sk_new_null(CONF_MODULE)
405#define sk_CONF_MODULE_free(st) SKM_sk_free(CONF_MODULE, (st))
406#define sk_CONF_MODULE_num(st) SKM_sk_num(CONF_MODULE, (st))
407#define sk_CONF_MODULE_value(st, i) SKM_sk_value(CONF_MODULE, (st), (i))
408#define sk_CONF_MODULE_set(st, i, val) SKM_sk_set(CONF_MODULE, (st), (i), (val))
409#define sk_CONF_MODULE_zero(st) SKM_sk_zero(CONF_MODULE, (st))
410#define sk_CONF_MODULE_push(st, val) SKM_sk_push(CONF_MODULE, (st), (val))
411#define sk_CONF_MODULE_unshift(st, val) SKM_sk_unshift(CONF_MODULE, (st), (val))
412#define sk_CONF_MODULE_find(st, val) SKM_sk_find(CONF_MODULE, (st), (val))
413#define sk_CONF_MODULE_delete(st, i) SKM_sk_delete(CONF_MODULE, (st), (i))
414#define sk_CONF_MODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_MODULE, (st), (ptr))
415#define sk_CONF_MODULE_insert(st, val, i) SKM_sk_insert(CONF_MODULE, (st), (val), (i))
416#define sk_CONF_MODULE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_MODULE, (st), (cmp))
417#define sk_CONF_MODULE_dup(st) SKM_sk_dup(CONF_MODULE, st)
418#define sk_CONF_MODULE_pop_free(st, free_func) SKM_sk_pop_free(CONF_MODULE, (st), (free_func))
419#define sk_CONF_MODULE_shift(st) SKM_sk_shift(CONF_MODULE, (st))
420#define sk_CONF_MODULE_pop(st) SKM_sk_pop(CONF_MODULE, (st))
421#define sk_CONF_MODULE_sort(st) SKM_sk_sort(CONF_MODULE, (st))
422#define sk_CONF_MODULE_is_sorted(st) SKM_sk_is_sorted(CONF_MODULE, (st))
423
424#define sk_CONF_VALUE_new(st) SKM_sk_new(CONF_VALUE, (st))
425#define sk_CONF_VALUE_new_null() SKM_sk_new_null(CONF_VALUE)
426#define sk_CONF_VALUE_free(st) SKM_sk_free(CONF_VALUE, (st))
427#define sk_CONF_VALUE_num(st) SKM_sk_num(CONF_VALUE, (st))
428#define sk_CONF_VALUE_value(st, i) SKM_sk_value(CONF_VALUE, (st), (i))
429#define sk_CONF_VALUE_set(st, i, val) SKM_sk_set(CONF_VALUE, (st), (i), (val))
430#define sk_CONF_VALUE_zero(st) SKM_sk_zero(CONF_VALUE, (st))
431#define sk_CONF_VALUE_push(st, val) SKM_sk_push(CONF_VALUE, (st), (val))
432#define sk_CONF_VALUE_unshift(st, val) SKM_sk_unshift(CONF_VALUE, (st), (val))
433#define sk_CONF_VALUE_find(st, val) SKM_sk_find(CONF_VALUE, (st), (val))
434#define sk_CONF_VALUE_delete(st, i) SKM_sk_delete(CONF_VALUE, (st), (i))
435#define sk_CONF_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_VALUE, (st), (ptr))
436#define sk_CONF_VALUE_insert(st, val, i) SKM_sk_insert(CONF_VALUE, (st), (val), (i))
437#define sk_CONF_VALUE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CONF_VALUE, (st), (cmp))
438#define sk_CONF_VALUE_dup(st) SKM_sk_dup(CONF_VALUE, st)
439#define sk_CONF_VALUE_pop_free(st, free_func) SKM_sk_pop_free(CONF_VALUE, (st), (free_func))
440#define sk_CONF_VALUE_shift(st) SKM_sk_shift(CONF_VALUE, (st))
441#define sk_CONF_VALUE_pop(st) SKM_sk_pop(CONF_VALUE, (st))
442#define sk_CONF_VALUE_sort(st) SKM_sk_sort(CONF_VALUE, (st))
443#define sk_CONF_VALUE_is_sorted(st) SKM_sk_is_sorted(CONF_VALUE, (st))
444
445#define sk_CRYPTO_EX_DATA_FUNCS_new(st) SKM_sk_new(CRYPTO_EX_DATA_FUNCS, (st))
446#define sk_CRYPTO_EX_DATA_FUNCS_new_null() SKM_sk_new_null(CRYPTO_EX_DATA_FUNCS)
447#define sk_CRYPTO_EX_DATA_FUNCS_free(st) SKM_sk_free(CRYPTO_EX_DATA_FUNCS, (st))
448#define sk_CRYPTO_EX_DATA_FUNCS_num(st) SKM_sk_num(CRYPTO_EX_DATA_FUNCS, (st))
449#define sk_CRYPTO_EX_DATA_FUNCS_value(st, i) SKM_sk_value(CRYPTO_EX_DATA_FUNCS, (st), (i))
450#define sk_CRYPTO_EX_DATA_FUNCS_set(st, i, val) SKM_sk_set(CRYPTO_EX_DATA_FUNCS, (st), (i), (val))
451#define sk_CRYPTO_EX_DATA_FUNCS_zero(st) SKM_sk_zero(CRYPTO_EX_DATA_FUNCS, (st))
452#define sk_CRYPTO_EX_DATA_FUNCS_push(st, val) SKM_sk_push(CRYPTO_EX_DATA_FUNCS, (st), (val))
453#define sk_CRYPTO_EX_DATA_FUNCS_unshift(st, val) SKM_sk_unshift(CRYPTO_EX_DATA_FUNCS, (st), (val))
454#define sk_CRYPTO_EX_DATA_FUNCS_find(st, val) SKM_sk_find(CRYPTO_EX_DATA_FUNCS, (st), (val))
455#define sk_CRYPTO_EX_DATA_FUNCS_delete(st, i) SKM_sk_delete(CRYPTO_EX_DATA_FUNCS, (st), (i))
456#define sk_CRYPTO_EX_DATA_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_EX_DATA_FUNCS, (st), (ptr))
457#define sk_CRYPTO_EX_DATA_FUNCS_insert(st, val, i) SKM_sk_insert(CRYPTO_EX_DATA_FUNCS, (st), (val), (i))
458#define sk_CRYPTO_EX_DATA_FUNCS_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CRYPTO_EX_DATA_FUNCS, (st), (cmp))
459#define sk_CRYPTO_EX_DATA_FUNCS_dup(st) SKM_sk_dup(CRYPTO_EX_DATA_FUNCS, st)
460#define sk_CRYPTO_EX_DATA_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_EX_DATA_FUNCS, (st), (free_func))
461#define sk_CRYPTO_EX_DATA_FUNCS_shift(st) SKM_sk_shift(CRYPTO_EX_DATA_FUNCS, (st))
462#define sk_CRYPTO_EX_DATA_FUNCS_pop(st) SKM_sk_pop(CRYPTO_EX_DATA_FUNCS, (st))
463#define sk_CRYPTO_EX_DATA_FUNCS_sort(st) SKM_sk_sort(CRYPTO_EX_DATA_FUNCS, (st))
464#define sk_CRYPTO_EX_DATA_FUNCS_is_sorted(st) SKM_sk_is_sorted(CRYPTO_EX_DATA_FUNCS, (st))
465
466#define sk_CRYPTO_dynlock_new(st) SKM_sk_new(CRYPTO_dynlock, (st))
467#define sk_CRYPTO_dynlock_new_null() SKM_sk_new_null(CRYPTO_dynlock)
468#define sk_CRYPTO_dynlock_free(st) SKM_sk_free(CRYPTO_dynlock, (st))
469#define sk_CRYPTO_dynlock_num(st) SKM_sk_num(CRYPTO_dynlock, (st))
470#define sk_CRYPTO_dynlock_value(st, i) SKM_sk_value(CRYPTO_dynlock, (st), (i))
471#define sk_CRYPTO_dynlock_set(st, i, val) SKM_sk_set(CRYPTO_dynlock, (st), (i), (val))
472#define sk_CRYPTO_dynlock_zero(st) SKM_sk_zero(CRYPTO_dynlock, (st))
473#define sk_CRYPTO_dynlock_push(st, val) SKM_sk_push(CRYPTO_dynlock, (st), (val))
474#define sk_CRYPTO_dynlock_unshift(st, val) SKM_sk_unshift(CRYPTO_dynlock, (st), (val))
475#define sk_CRYPTO_dynlock_find(st, val) SKM_sk_find(CRYPTO_dynlock, (st), (val))
476#define sk_CRYPTO_dynlock_delete(st, i) SKM_sk_delete(CRYPTO_dynlock, (st), (i))
477#define sk_CRYPTO_dynlock_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_dynlock, (st), (ptr))
478#define sk_CRYPTO_dynlock_insert(st, val, i) SKM_sk_insert(CRYPTO_dynlock, (st), (val), (i))
479#define sk_CRYPTO_dynlock_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CRYPTO_dynlock, (st), (cmp))
480#define sk_CRYPTO_dynlock_dup(st) SKM_sk_dup(CRYPTO_dynlock, st)
481#define sk_CRYPTO_dynlock_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_dynlock, (st), (free_func))
482#define sk_CRYPTO_dynlock_shift(st) SKM_sk_shift(CRYPTO_dynlock, (st))
483#define sk_CRYPTO_dynlock_pop(st) SKM_sk_pop(CRYPTO_dynlock, (st))
484#define sk_CRYPTO_dynlock_sort(st) SKM_sk_sort(CRYPTO_dynlock, (st))
485#define sk_CRYPTO_dynlock_is_sorted(st) SKM_sk_is_sorted(CRYPTO_dynlock, (st))
486
487#define sk_DIST_POINT_new(st) SKM_sk_new(DIST_POINT, (st))
488#define sk_DIST_POINT_new_null() SKM_sk_new_null(DIST_POINT)
489#define sk_DIST_POINT_free(st) SKM_sk_free(DIST_POINT, (st))
490#define sk_DIST_POINT_num(st) SKM_sk_num(DIST_POINT, (st))
491#define sk_DIST_POINT_value(st, i) SKM_sk_value(DIST_POINT, (st), (i))
492#define sk_DIST_POINT_set(st, i, val) SKM_sk_set(DIST_POINT, (st), (i), (val))
493#define sk_DIST_POINT_zero(st) SKM_sk_zero(DIST_POINT, (st))
494#define sk_DIST_POINT_push(st, val) SKM_sk_push(DIST_POINT, (st), (val))
495#define sk_DIST_POINT_unshift(st, val) SKM_sk_unshift(DIST_POINT, (st), (val))
496#define sk_DIST_POINT_find(st, val) SKM_sk_find(DIST_POINT, (st), (val))
497#define sk_DIST_POINT_delete(st, i) SKM_sk_delete(DIST_POINT, (st), (i))
498#define sk_DIST_POINT_delete_ptr(st, ptr) SKM_sk_delete_ptr(DIST_POINT, (st), (ptr))
499#define sk_DIST_POINT_insert(st, val, i) SKM_sk_insert(DIST_POINT, (st), (val), (i))
500#define sk_DIST_POINT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(DIST_POINT, (st), (cmp))
501#define sk_DIST_POINT_dup(st) SKM_sk_dup(DIST_POINT, st)
502#define sk_DIST_POINT_pop_free(st, free_func) SKM_sk_pop_free(DIST_POINT, (st), (free_func))
503#define sk_DIST_POINT_shift(st) SKM_sk_shift(DIST_POINT, (st))
504#define sk_DIST_POINT_pop(st) SKM_sk_pop(DIST_POINT, (st))
505#define sk_DIST_POINT_sort(st) SKM_sk_sort(DIST_POINT, (st))
506#define sk_DIST_POINT_is_sorted(st) SKM_sk_is_sorted(DIST_POINT, (st))
507
508#define sk_ENGINE_new(st) SKM_sk_new(ENGINE, (st))
509#define sk_ENGINE_new_null() SKM_sk_new_null(ENGINE)
510#define sk_ENGINE_free(st) SKM_sk_free(ENGINE, (st))
511#define sk_ENGINE_num(st) SKM_sk_num(ENGINE, (st))
512#define sk_ENGINE_value(st, i) SKM_sk_value(ENGINE, (st), (i))
513#define sk_ENGINE_set(st, i, val) SKM_sk_set(ENGINE, (st), (i), (val))
514#define sk_ENGINE_zero(st) SKM_sk_zero(ENGINE, (st))
515#define sk_ENGINE_push(st, val) SKM_sk_push(ENGINE, (st), (val))
516#define sk_ENGINE_unshift(st, val) SKM_sk_unshift(ENGINE, (st), (val))
517#define sk_ENGINE_find(st, val) SKM_sk_find(ENGINE, (st), (val))
518#define sk_ENGINE_delete(st, i) SKM_sk_delete(ENGINE, (st), (i))
519#define sk_ENGINE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE, (st), (ptr))
520#define sk_ENGINE_insert(st, val, i) SKM_sk_insert(ENGINE, (st), (val), (i))
521#define sk_ENGINE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ENGINE, (st), (cmp))
522#define sk_ENGINE_dup(st) SKM_sk_dup(ENGINE, st)
523#define sk_ENGINE_pop_free(st, free_func) SKM_sk_pop_free(ENGINE, (st), (free_func))
524#define sk_ENGINE_shift(st) SKM_sk_shift(ENGINE, (st))
525#define sk_ENGINE_pop(st) SKM_sk_pop(ENGINE, (st))
526#define sk_ENGINE_sort(st) SKM_sk_sort(ENGINE, (st))
527#define sk_ENGINE_is_sorted(st) SKM_sk_is_sorted(ENGINE, (st))
528
529#define sk_ENGINE_CLEANUP_ITEM_new(st) SKM_sk_new(ENGINE_CLEANUP_ITEM, (st))
530#define sk_ENGINE_CLEANUP_ITEM_new_null() SKM_sk_new_null(ENGINE_CLEANUP_ITEM)
531#define sk_ENGINE_CLEANUP_ITEM_free(st) SKM_sk_free(ENGINE_CLEANUP_ITEM, (st))
532#define sk_ENGINE_CLEANUP_ITEM_num(st) SKM_sk_num(ENGINE_CLEANUP_ITEM, (st))
533#define sk_ENGINE_CLEANUP_ITEM_value(st, i) SKM_sk_value(ENGINE_CLEANUP_ITEM, (st), (i))
534#define sk_ENGINE_CLEANUP_ITEM_set(st, i, val) SKM_sk_set(ENGINE_CLEANUP_ITEM, (st), (i), (val))
535#define sk_ENGINE_CLEANUP_ITEM_zero(st) SKM_sk_zero(ENGINE_CLEANUP_ITEM, (st))
536#define sk_ENGINE_CLEANUP_ITEM_push(st, val) SKM_sk_push(ENGINE_CLEANUP_ITEM, (st), (val))
537#define sk_ENGINE_CLEANUP_ITEM_unshift(st, val) SKM_sk_unshift(ENGINE_CLEANUP_ITEM, (st), (val))
538#define sk_ENGINE_CLEANUP_ITEM_find(st, val) SKM_sk_find(ENGINE_CLEANUP_ITEM, (st), (val))
539#define sk_ENGINE_CLEANUP_ITEM_delete(st, i) SKM_sk_delete(ENGINE_CLEANUP_ITEM, (st), (i))
540#define sk_ENGINE_CLEANUP_ITEM_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE_CLEANUP_ITEM, (st), (ptr))
541#define sk_ENGINE_CLEANUP_ITEM_insert(st, val, i) SKM_sk_insert(ENGINE_CLEANUP_ITEM, (st), (val), (i))
542#define sk_ENGINE_CLEANUP_ITEM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ENGINE_CLEANUP_ITEM, (st), (cmp))
543#define sk_ENGINE_CLEANUP_ITEM_dup(st) SKM_sk_dup(ENGINE_CLEANUP_ITEM, st)
544#define sk_ENGINE_CLEANUP_ITEM_pop_free(st, free_func) SKM_sk_pop_free(ENGINE_CLEANUP_ITEM, (st), (free_func))
545#define sk_ENGINE_CLEANUP_ITEM_shift(st) SKM_sk_shift(ENGINE_CLEANUP_ITEM, (st))
546#define sk_ENGINE_CLEANUP_ITEM_pop(st) SKM_sk_pop(ENGINE_CLEANUP_ITEM, (st))
547#define sk_ENGINE_CLEANUP_ITEM_sort(st) SKM_sk_sort(ENGINE_CLEANUP_ITEM, (st))
548#define sk_ENGINE_CLEANUP_ITEM_is_sorted(st) SKM_sk_is_sorted(ENGINE_CLEANUP_ITEM, (st))
549
550#define sk_GENERAL_NAME_new(st) SKM_sk_new(GENERAL_NAME, (st))
551#define sk_GENERAL_NAME_new_null() SKM_sk_new_null(GENERAL_NAME)
552#define sk_GENERAL_NAME_free(st) SKM_sk_free(GENERAL_NAME, (st))
553#define sk_GENERAL_NAME_num(st) SKM_sk_num(GENERAL_NAME, (st))
554#define sk_GENERAL_NAME_value(st, i) SKM_sk_value(GENERAL_NAME, (st), (i))
555#define sk_GENERAL_NAME_set(st, i, val) SKM_sk_set(GENERAL_NAME, (st), (i), (val))
556#define sk_GENERAL_NAME_zero(st) SKM_sk_zero(GENERAL_NAME, (st))
557#define sk_GENERAL_NAME_push(st, val) SKM_sk_push(GENERAL_NAME, (st), (val))
558#define sk_GENERAL_NAME_unshift(st, val) SKM_sk_unshift(GENERAL_NAME, (st), (val))
559#define sk_GENERAL_NAME_find(st, val) SKM_sk_find(GENERAL_NAME, (st), (val))
560#define sk_GENERAL_NAME_delete(st, i) SKM_sk_delete(GENERAL_NAME, (st), (i))
561#define sk_GENERAL_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_NAME, (st), (ptr))
562#define sk_GENERAL_NAME_insert(st, val, i) SKM_sk_insert(GENERAL_NAME, (st), (val), (i))
563#define sk_GENERAL_NAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_NAME, (st), (cmp))
564#define sk_GENERAL_NAME_dup(st) SKM_sk_dup(GENERAL_NAME, st)
565#define sk_GENERAL_NAME_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_NAME, (st), (free_func))
566#define sk_GENERAL_NAME_shift(st) SKM_sk_shift(GENERAL_NAME, (st))
567#define sk_GENERAL_NAME_pop(st) SKM_sk_pop(GENERAL_NAME, (st))
568#define sk_GENERAL_NAME_sort(st) SKM_sk_sort(GENERAL_NAME, (st))
569#define sk_GENERAL_NAME_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAME, (st))
570
571#define sk_KRB5_APREQBODY_new(st) SKM_sk_new(KRB5_APREQBODY, (st))
572#define sk_KRB5_APREQBODY_new_null() SKM_sk_new_null(KRB5_APREQBODY)
573#define sk_KRB5_APREQBODY_free(st) SKM_sk_free(KRB5_APREQBODY, (st))
574#define sk_KRB5_APREQBODY_num(st) SKM_sk_num(KRB5_APREQBODY, (st))
575#define sk_KRB5_APREQBODY_value(st, i) SKM_sk_value(KRB5_APREQBODY, (st), (i))
576#define sk_KRB5_APREQBODY_set(st, i, val) SKM_sk_set(KRB5_APREQBODY, (st), (i), (val))
577#define sk_KRB5_APREQBODY_zero(st) SKM_sk_zero(KRB5_APREQBODY, (st))
578#define sk_KRB5_APREQBODY_push(st, val) SKM_sk_push(KRB5_APREQBODY, (st), (val))
579#define sk_KRB5_APREQBODY_unshift(st, val) SKM_sk_unshift(KRB5_APREQBODY, (st), (val))
580#define sk_KRB5_APREQBODY_find(st, val) SKM_sk_find(KRB5_APREQBODY, (st), (val))
581#define sk_KRB5_APREQBODY_delete(st, i) SKM_sk_delete(KRB5_APREQBODY, (st), (i))
582#define sk_KRB5_APREQBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_APREQBODY, (st), (ptr))
583#define sk_KRB5_APREQBODY_insert(st, val, i) SKM_sk_insert(KRB5_APREQBODY, (st), (val), (i))
584#define sk_KRB5_APREQBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_APREQBODY, (st), (cmp))
585#define sk_KRB5_APREQBODY_dup(st) SKM_sk_dup(KRB5_APREQBODY, st)
586#define sk_KRB5_APREQBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_APREQBODY, (st), (free_func))
587#define sk_KRB5_APREQBODY_shift(st) SKM_sk_shift(KRB5_APREQBODY, (st))
588#define sk_KRB5_APREQBODY_pop(st) SKM_sk_pop(KRB5_APREQBODY, (st))
589#define sk_KRB5_APREQBODY_sort(st) SKM_sk_sort(KRB5_APREQBODY, (st))
590#define sk_KRB5_APREQBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_APREQBODY, (st))
591
592#define sk_KRB5_AUTHDATA_new(st) SKM_sk_new(KRB5_AUTHDATA, (st))
593#define sk_KRB5_AUTHDATA_new_null() SKM_sk_new_null(KRB5_AUTHDATA)
594#define sk_KRB5_AUTHDATA_free(st) SKM_sk_free(KRB5_AUTHDATA, (st))
595#define sk_KRB5_AUTHDATA_num(st) SKM_sk_num(KRB5_AUTHDATA, (st))
596#define sk_KRB5_AUTHDATA_value(st, i) SKM_sk_value(KRB5_AUTHDATA, (st), (i))
597#define sk_KRB5_AUTHDATA_set(st, i, val) SKM_sk_set(KRB5_AUTHDATA, (st), (i), (val))
598#define sk_KRB5_AUTHDATA_zero(st) SKM_sk_zero(KRB5_AUTHDATA, (st))
599#define sk_KRB5_AUTHDATA_push(st, val) SKM_sk_push(KRB5_AUTHDATA, (st), (val))
600#define sk_KRB5_AUTHDATA_unshift(st, val) SKM_sk_unshift(KRB5_AUTHDATA, (st), (val))
601#define sk_KRB5_AUTHDATA_find(st, val) SKM_sk_find(KRB5_AUTHDATA, (st), (val))
602#define sk_KRB5_AUTHDATA_delete(st, i) SKM_sk_delete(KRB5_AUTHDATA, (st), (i))
603#define sk_KRB5_AUTHDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHDATA, (st), (ptr))
604#define sk_KRB5_AUTHDATA_insert(st, val, i) SKM_sk_insert(KRB5_AUTHDATA, (st), (val), (i))
605#define sk_KRB5_AUTHDATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_AUTHDATA, (st), (cmp))
606#define sk_KRB5_AUTHDATA_dup(st) SKM_sk_dup(KRB5_AUTHDATA, st)
607#define sk_KRB5_AUTHDATA_pop_free(st, free_func) SKM_sk_pop_free(KRB5_AUTHDATA, (st), (free_func))
608#define sk_KRB5_AUTHDATA_shift(st) SKM_sk_shift(KRB5_AUTHDATA, (st))
609#define sk_KRB5_AUTHDATA_pop(st) SKM_sk_pop(KRB5_AUTHDATA, (st))
610#define sk_KRB5_AUTHDATA_sort(st) SKM_sk_sort(KRB5_AUTHDATA, (st))
611#define sk_KRB5_AUTHDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHDATA, (st))
612
613#define sk_KRB5_AUTHENTBODY_new(st) SKM_sk_new(KRB5_AUTHENTBODY, (st))
614#define sk_KRB5_AUTHENTBODY_new_null() SKM_sk_new_null(KRB5_AUTHENTBODY)
615#define sk_KRB5_AUTHENTBODY_free(st) SKM_sk_free(KRB5_AUTHENTBODY, (st))
616#define sk_KRB5_AUTHENTBODY_num(st) SKM_sk_num(KRB5_AUTHENTBODY, (st))
617#define sk_KRB5_AUTHENTBODY_value(st, i) SKM_sk_value(KRB5_AUTHENTBODY, (st), (i))
618#define sk_KRB5_AUTHENTBODY_set(st, i, val) SKM_sk_set(KRB5_AUTHENTBODY, (st), (i), (val))
619#define sk_KRB5_AUTHENTBODY_zero(st) SKM_sk_zero(KRB5_AUTHENTBODY, (st))
620#define sk_KRB5_AUTHENTBODY_push(st, val) SKM_sk_push(KRB5_AUTHENTBODY, (st), (val))
621#define sk_KRB5_AUTHENTBODY_unshift(st, val) SKM_sk_unshift(KRB5_AUTHENTBODY, (st), (val))
622#define sk_KRB5_AUTHENTBODY_find(st, val) SKM_sk_find(KRB5_AUTHENTBODY, (st), (val))
623#define sk_KRB5_AUTHENTBODY_delete(st, i) SKM_sk_delete(KRB5_AUTHENTBODY, (st), (i))
624#define sk_KRB5_AUTHENTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHENTBODY, (st), (ptr))
625#define sk_KRB5_AUTHENTBODY_insert(st, val, i) SKM_sk_insert(KRB5_AUTHENTBODY, (st), (val), (i))
626#define sk_KRB5_AUTHENTBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_AUTHENTBODY, (st), (cmp))
627#define sk_KRB5_AUTHENTBODY_dup(st) SKM_sk_dup(KRB5_AUTHENTBODY, st)
628#define sk_KRB5_AUTHENTBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_AUTHENTBODY, (st), (free_func))
629#define sk_KRB5_AUTHENTBODY_shift(st) SKM_sk_shift(KRB5_AUTHENTBODY, (st))
630#define sk_KRB5_AUTHENTBODY_pop(st) SKM_sk_pop(KRB5_AUTHENTBODY, (st))
631#define sk_KRB5_AUTHENTBODY_sort(st) SKM_sk_sort(KRB5_AUTHENTBODY, (st))
632#define sk_KRB5_AUTHENTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_AUTHENTBODY, (st))
633
634#define sk_KRB5_CHECKSUM_new(st) SKM_sk_new(KRB5_CHECKSUM, (st))
635#define sk_KRB5_CHECKSUM_new_null() SKM_sk_new_null(KRB5_CHECKSUM)
636#define sk_KRB5_CHECKSUM_free(st) SKM_sk_free(KRB5_CHECKSUM, (st))
637#define sk_KRB5_CHECKSUM_num(st) SKM_sk_num(KRB5_CHECKSUM, (st))
638#define sk_KRB5_CHECKSUM_value(st, i) SKM_sk_value(KRB5_CHECKSUM, (st), (i))
639#define sk_KRB5_CHECKSUM_set(st, i, val) SKM_sk_set(KRB5_CHECKSUM, (st), (i), (val))
640#define sk_KRB5_CHECKSUM_zero(st) SKM_sk_zero(KRB5_CHECKSUM, (st))
641#define sk_KRB5_CHECKSUM_push(st, val) SKM_sk_push(KRB5_CHECKSUM, (st), (val))
642#define sk_KRB5_CHECKSUM_unshift(st, val) SKM_sk_unshift(KRB5_CHECKSUM, (st), (val))
643#define sk_KRB5_CHECKSUM_find(st, val) SKM_sk_find(KRB5_CHECKSUM, (st), (val))
644#define sk_KRB5_CHECKSUM_delete(st, i) SKM_sk_delete(KRB5_CHECKSUM, (st), (i))
645#define sk_KRB5_CHECKSUM_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_CHECKSUM, (st), (ptr))
646#define sk_KRB5_CHECKSUM_insert(st, val, i) SKM_sk_insert(KRB5_CHECKSUM, (st), (val), (i))
647#define sk_KRB5_CHECKSUM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_CHECKSUM, (st), (cmp))
648#define sk_KRB5_CHECKSUM_dup(st) SKM_sk_dup(KRB5_CHECKSUM, st)
649#define sk_KRB5_CHECKSUM_pop_free(st, free_func) SKM_sk_pop_free(KRB5_CHECKSUM, (st), (free_func))
650#define sk_KRB5_CHECKSUM_shift(st) SKM_sk_shift(KRB5_CHECKSUM, (st))
651#define sk_KRB5_CHECKSUM_pop(st) SKM_sk_pop(KRB5_CHECKSUM, (st))
652#define sk_KRB5_CHECKSUM_sort(st) SKM_sk_sort(KRB5_CHECKSUM, (st))
653#define sk_KRB5_CHECKSUM_is_sorted(st) SKM_sk_is_sorted(KRB5_CHECKSUM, (st))
654
655#define sk_KRB5_ENCDATA_new(st) SKM_sk_new(KRB5_ENCDATA, (st))
656#define sk_KRB5_ENCDATA_new_null() SKM_sk_new_null(KRB5_ENCDATA)
657#define sk_KRB5_ENCDATA_free(st) SKM_sk_free(KRB5_ENCDATA, (st))
658#define sk_KRB5_ENCDATA_num(st) SKM_sk_num(KRB5_ENCDATA, (st))
659#define sk_KRB5_ENCDATA_value(st, i) SKM_sk_value(KRB5_ENCDATA, (st), (i))
660#define sk_KRB5_ENCDATA_set(st, i, val) SKM_sk_set(KRB5_ENCDATA, (st), (i), (val))
661#define sk_KRB5_ENCDATA_zero(st) SKM_sk_zero(KRB5_ENCDATA, (st))
662#define sk_KRB5_ENCDATA_push(st, val) SKM_sk_push(KRB5_ENCDATA, (st), (val))
663#define sk_KRB5_ENCDATA_unshift(st, val) SKM_sk_unshift(KRB5_ENCDATA, (st), (val))
664#define sk_KRB5_ENCDATA_find(st, val) SKM_sk_find(KRB5_ENCDATA, (st), (val))
665#define sk_KRB5_ENCDATA_delete(st, i) SKM_sk_delete(KRB5_ENCDATA, (st), (i))
666#define sk_KRB5_ENCDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCDATA, (st), (ptr))
667#define sk_KRB5_ENCDATA_insert(st, val, i) SKM_sk_insert(KRB5_ENCDATA, (st), (val), (i))
668#define sk_KRB5_ENCDATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_ENCDATA, (st), (cmp))
669#define sk_KRB5_ENCDATA_dup(st) SKM_sk_dup(KRB5_ENCDATA, st)
670#define sk_KRB5_ENCDATA_pop_free(st, free_func) SKM_sk_pop_free(KRB5_ENCDATA, (st), (free_func))
671#define sk_KRB5_ENCDATA_shift(st) SKM_sk_shift(KRB5_ENCDATA, (st))
672#define sk_KRB5_ENCDATA_pop(st) SKM_sk_pop(KRB5_ENCDATA, (st))
673#define sk_KRB5_ENCDATA_sort(st) SKM_sk_sort(KRB5_ENCDATA, (st))
674#define sk_KRB5_ENCDATA_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCDATA, (st))
675
676#define sk_KRB5_ENCKEY_new(st) SKM_sk_new(KRB5_ENCKEY, (st))
677#define sk_KRB5_ENCKEY_new_null() SKM_sk_new_null(KRB5_ENCKEY)
678#define sk_KRB5_ENCKEY_free(st) SKM_sk_free(KRB5_ENCKEY, (st))
679#define sk_KRB5_ENCKEY_num(st) SKM_sk_num(KRB5_ENCKEY, (st))
680#define sk_KRB5_ENCKEY_value(st, i) SKM_sk_value(KRB5_ENCKEY, (st), (i))
681#define sk_KRB5_ENCKEY_set(st, i, val) SKM_sk_set(KRB5_ENCKEY, (st), (i), (val))
682#define sk_KRB5_ENCKEY_zero(st) SKM_sk_zero(KRB5_ENCKEY, (st))
683#define sk_KRB5_ENCKEY_push(st, val) SKM_sk_push(KRB5_ENCKEY, (st), (val))
684#define sk_KRB5_ENCKEY_unshift(st, val) SKM_sk_unshift(KRB5_ENCKEY, (st), (val))
685#define sk_KRB5_ENCKEY_find(st, val) SKM_sk_find(KRB5_ENCKEY, (st), (val))
686#define sk_KRB5_ENCKEY_delete(st, i) SKM_sk_delete(KRB5_ENCKEY, (st), (i))
687#define sk_KRB5_ENCKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCKEY, (st), (ptr))
688#define sk_KRB5_ENCKEY_insert(st, val, i) SKM_sk_insert(KRB5_ENCKEY, (st), (val), (i))
689#define sk_KRB5_ENCKEY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_ENCKEY, (st), (cmp))
690#define sk_KRB5_ENCKEY_dup(st) SKM_sk_dup(KRB5_ENCKEY, st)
691#define sk_KRB5_ENCKEY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_ENCKEY, (st), (free_func))
692#define sk_KRB5_ENCKEY_shift(st) SKM_sk_shift(KRB5_ENCKEY, (st))
693#define sk_KRB5_ENCKEY_pop(st) SKM_sk_pop(KRB5_ENCKEY, (st))
694#define sk_KRB5_ENCKEY_sort(st) SKM_sk_sort(KRB5_ENCKEY, (st))
695#define sk_KRB5_ENCKEY_is_sorted(st) SKM_sk_is_sorted(KRB5_ENCKEY, (st))
696
697#define sk_KRB5_PRINCNAME_new(st) SKM_sk_new(KRB5_PRINCNAME, (st))
698#define sk_KRB5_PRINCNAME_new_null() SKM_sk_new_null(KRB5_PRINCNAME)
699#define sk_KRB5_PRINCNAME_free(st) SKM_sk_free(KRB5_PRINCNAME, (st))
700#define sk_KRB5_PRINCNAME_num(st) SKM_sk_num(KRB5_PRINCNAME, (st))
701#define sk_KRB5_PRINCNAME_value(st, i) SKM_sk_value(KRB5_PRINCNAME, (st), (i))
702#define sk_KRB5_PRINCNAME_set(st, i, val) SKM_sk_set(KRB5_PRINCNAME, (st), (i), (val))
703#define sk_KRB5_PRINCNAME_zero(st) SKM_sk_zero(KRB5_PRINCNAME, (st))
704#define sk_KRB5_PRINCNAME_push(st, val) SKM_sk_push(KRB5_PRINCNAME, (st), (val))
705#define sk_KRB5_PRINCNAME_unshift(st, val) SKM_sk_unshift(KRB5_PRINCNAME, (st), (val))
706#define sk_KRB5_PRINCNAME_find(st, val) SKM_sk_find(KRB5_PRINCNAME, (st), (val))
707#define sk_KRB5_PRINCNAME_delete(st, i) SKM_sk_delete(KRB5_PRINCNAME, (st), (i))
708#define sk_KRB5_PRINCNAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_PRINCNAME, (st), (ptr))
709#define sk_KRB5_PRINCNAME_insert(st, val, i) SKM_sk_insert(KRB5_PRINCNAME, (st), (val), (i))
710#define sk_KRB5_PRINCNAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_PRINCNAME, (st), (cmp))
711#define sk_KRB5_PRINCNAME_dup(st) SKM_sk_dup(KRB5_PRINCNAME, st)
712#define sk_KRB5_PRINCNAME_pop_free(st, free_func) SKM_sk_pop_free(KRB5_PRINCNAME, (st), (free_func))
713#define sk_KRB5_PRINCNAME_shift(st) SKM_sk_shift(KRB5_PRINCNAME, (st))
714#define sk_KRB5_PRINCNAME_pop(st) SKM_sk_pop(KRB5_PRINCNAME, (st))
715#define sk_KRB5_PRINCNAME_sort(st) SKM_sk_sort(KRB5_PRINCNAME, (st))
716#define sk_KRB5_PRINCNAME_is_sorted(st) SKM_sk_is_sorted(KRB5_PRINCNAME, (st))
717
718#define sk_KRB5_TKTBODY_new(st) SKM_sk_new(KRB5_TKTBODY, (st))
719#define sk_KRB5_TKTBODY_new_null() SKM_sk_new_null(KRB5_TKTBODY)
720#define sk_KRB5_TKTBODY_free(st) SKM_sk_free(KRB5_TKTBODY, (st))
721#define sk_KRB5_TKTBODY_num(st) SKM_sk_num(KRB5_TKTBODY, (st))
722#define sk_KRB5_TKTBODY_value(st, i) SKM_sk_value(KRB5_TKTBODY, (st), (i))
723#define sk_KRB5_TKTBODY_set(st, i, val) SKM_sk_set(KRB5_TKTBODY, (st), (i), (val))
724#define sk_KRB5_TKTBODY_zero(st) SKM_sk_zero(KRB5_TKTBODY, (st))
725#define sk_KRB5_TKTBODY_push(st, val) SKM_sk_push(KRB5_TKTBODY, (st), (val))
726#define sk_KRB5_TKTBODY_unshift(st, val) SKM_sk_unshift(KRB5_TKTBODY, (st), (val))
727#define sk_KRB5_TKTBODY_find(st, val) SKM_sk_find(KRB5_TKTBODY, (st), (val))
728#define sk_KRB5_TKTBODY_delete(st, i) SKM_sk_delete(KRB5_TKTBODY, (st), (i))
729#define sk_KRB5_TKTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_TKTBODY, (st), (ptr))
730#define sk_KRB5_TKTBODY_insert(st, val, i) SKM_sk_insert(KRB5_TKTBODY, (st), (val), (i))
731#define sk_KRB5_TKTBODY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(KRB5_TKTBODY, (st), (cmp))
732#define sk_KRB5_TKTBODY_dup(st) SKM_sk_dup(KRB5_TKTBODY, st)
733#define sk_KRB5_TKTBODY_pop_free(st, free_func) SKM_sk_pop_free(KRB5_TKTBODY, (st), (free_func))
734#define sk_KRB5_TKTBODY_shift(st) SKM_sk_shift(KRB5_TKTBODY, (st))
735#define sk_KRB5_TKTBODY_pop(st) SKM_sk_pop(KRB5_TKTBODY, (st))
736#define sk_KRB5_TKTBODY_sort(st) SKM_sk_sort(KRB5_TKTBODY, (st))
737#define sk_KRB5_TKTBODY_is_sorted(st) SKM_sk_is_sorted(KRB5_TKTBODY, (st))
738
739#define sk_MIME_HEADER_new(st) SKM_sk_new(MIME_HEADER, (st))
740#define sk_MIME_HEADER_new_null() SKM_sk_new_null(MIME_HEADER)
741#define sk_MIME_HEADER_free(st) SKM_sk_free(MIME_HEADER, (st))
742#define sk_MIME_HEADER_num(st) SKM_sk_num(MIME_HEADER, (st))
743#define sk_MIME_HEADER_value(st, i) SKM_sk_value(MIME_HEADER, (st), (i))
744#define sk_MIME_HEADER_set(st, i, val) SKM_sk_set(MIME_HEADER, (st), (i), (val))
745#define sk_MIME_HEADER_zero(st) SKM_sk_zero(MIME_HEADER, (st))
746#define sk_MIME_HEADER_push(st, val) SKM_sk_push(MIME_HEADER, (st), (val))
747#define sk_MIME_HEADER_unshift(st, val) SKM_sk_unshift(MIME_HEADER, (st), (val))
748#define sk_MIME_HEADER_find(st, val) SKM_sk_find(MIME_HEADER, (st), (val))
749#define sk_MIME_HEADER_delete(st, i) SKM_sk_delete(MIME_HEADER, (st), (i))
750#define sk_MIME_HEADER_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_HEADER, (st), (ptr))
751#define sk_MIME_HEADER_insert(st, val, i) SKM_sk_insert(MIME_HEADER, (st), (val), (i))
752#define sk_MIME_HEADER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_HEADER, (st), (cmp))
753#define sk_MIME_HEADER_dup(st) SKM_sk_dup(MIME_HEADER, st)
754#define sk_MIME_HEADER_pop_free(st, free_func) SKM_sk_pop_free(MIME_HEADER, (st), (free_func))
755#define sk_MIME_HEADER_shift(st) SKM_sk_shift(MIME_HEADER, (st))
756#define sk_MIME_HEADER_pop(st) SKM_sk_pop(MIME_HEADER, (st))
757#define sk_MIME_HEADER_sort(st) SKM_sk_sort(MIME_HEADER, (st))
758#define sk_MIME_HEADER_is_sorted(st) SKM_sk_is_sorted(MIME_HEADER, (st))
759
760#define sk_MIME_PARAM_new(st) SKM_sk_new(MIME_PARAM, (st))
761#define sk_MIME_PARAM_new_null() SKM_sk_new_null(MIME_PARAM)
762#define sk_MIME_PARAM_free(st) SKM_sk_free(MIME_PARAM, (st))
763#define sk_MIME_PARAM_num(st) SKM_sk_num(MIME_PARAM, (st))
764#define sk_MIME_PARAM_value(st, i) SKM_sk_value(MIME_PARAM, (st), (i))
765#define sk_MIME_PARAM_set(st, i, val) SKM_sk_set(MIME_PARAM, (st), (i), (val))
766#define sk_MIME_PARAM_zero(st) SKM_sk_zero(MIME_PARAM, (st))
767#define sk_MIME_PARAM_push(st, val) SKM_sk_push(MIME_PARAM, (st), (val))
768#define sk_MIME_PARAM_unshift(st, val) SKM_sk_unshift(MIME_PARAM, (st), (val))
769#define sk_MIME_PARAM_find(st, val) SKM_sk_find(MIME_PARAM, (st), (val))
770#define sk_MIME_PARAM_delete(st, i) SKM_sk_delete(MIME_PARAM, (st), (i))
771#define sk_MIME_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_PARAM, (st), (ptr))
772#define sk_MIME_PARAM_insert(st, val, i) SKM_sk_insert(MIME_PARAM, (st), (val), (i))
773#define sk_MIME_PARAM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MIME_PARAM, (st), (cmp))
774#define sk_MIME_PARAM_dup(st) SKM_sk_dup(MIME_PARAM, st)
775#define sk_MIME_PARAM_pop_free(st, free_func) SKM_sk_pop_free(MIME_PARAM, (st), (free_func))
776#define sk_MIME_PARAM_shift(st) SKM_sk_shift(MIME_PARAM, (st))
777#define sk_MIME_PARAM_pop(st) SKM_sk_pop(MIME_PARAM, (st))
778#define sk_MIME_PARAM_sort(st) SKM_sk_sort(MIME_PARAM, (st))
779#define sk_MIME_PARAM_is_sorted(st) SKM_sk_is_sorted(MIME_PARAM, (st))
780
781#define sk_NAME_FUNCS_new(st) SKM_sk_new(NAME_FUNCS, (st))
782#define sk_NAME_FUNCS_new_null() SKM_sk_new_null(NAME_FUNCS)
783#define sk_NAME_FUNCS_free(st) SKM_sk_free(NAME_FUNCS, (st))
784#define sk_NAME_FUNCS_num(st) SKM_sk_num(NAME_FUNCS, (st))
785#define sk_NAME_FUNCS_value(st, i) SKM_sk_value(NAME_FUNCS, (st), (i))
786#define sk_NAME_FUNCS_set(st, i, val) SKM_sk_set(NAME_FUNCS, (st), (i), (val))
787#define sk_NAME_FUNCS_zero(st) SKM_sk_zero(NAME_FUNCS, (st))
788#define sk_NAME_FUNCS_push(st, val) SKM_sk_push(NAME_FUNCS, (st), (val))
789#define sk_NAME_FUNCS_unshift(st, val) SKM_sk_unshift(NAME_FUNCS, (st), (val))
790#define sk_NAME_FUNCS_find(st, val) SKM_sk_find(NAME_FUNCS, (st), (val))
791#define sk_NAME_FUNCS_delete(st, i) SKM_sk_delete(NAME_FUNCS, (st), (i))
792#define sk_NAME_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(NAME_FUNCS, (st), (ptr))
793#define sk_NAME_FUNCS_insert(st, val, i) SKM_sk_insert(NAME_FUNCS, (st), (val), (i))
794#define sk_NAME_FUNCS_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(NAME_FUNCS, (st), (cmp))
795#define sk_NAME_FUNCS_dup(st) SKM_sk_dup(NAME_FUNCS, st)
796#define sk_NAME_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(NAME_FUNCS, (st), (free_func))
797#define sk_NAME_FUNCS_shift(st) SKM_sk_shift(NAME_FUNCS, (st))
798#define sk_NAME_FUNCS_pop(st) SKM_sk_pop(NAME_FUNCS, (st))
799#define sk_NAME_FUNCS_sort(st) SKM_sk_sort(NAME_FUNCS, (st))
800#define sk_NAME_FUNCS_is_sorted(st) SKM_sk_is_sorted(NAME_FUNCS, (st))
801
802#define sk_OCSP_CERTID_new(st) SKM_sk_new(OCSP_CERTID, (st))
803#define sk_OCSP_CERTID_new_null() SKM_sk_new_null(OCSP_CERTID)
804#define sk_OCSP_CERTID_free(st) SKM_sk_free(OCSP_CERTID, (st))
805#define sk_OCSP_CERTID_num(st) SKM_sk_num(OCSP_CERTID, (st))
806#define sk_OCSP_CERTID_value(st, i) SKM_sk_value(OCSP_CERTID, (st), (i))
807#define sk_OCSP_CERTID_set(st, i, val) SKM_sk_set(OCSP_CERTID, (st), (i), (val))
808#define sk_OCSP_CERTID_zero(st) SKM_sk_zero(OCSP_CERTID, (st))
809#define sk_OCSP_CERTID_push(st, val) SKM_sk_push(OCSP_CERTID, (st), (val))
810#define sk_OCSP_CERTID_unshift(st, val) SKM_sk_unshift(OCSP_CERTID, (st), (val))
811#define sk_OCSP_CERTID_find(st, val) SKM_sk_find(OCSP_CERTID, (st), (val))
812#define sk_OCSP_CERTID_delete(st, i) SKM_sk_delete(OCSP_CERTID, (st), (i))
813#define sk_OCSP_CERTID_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_CERTID, (st), (ptr))
814#define sk_OCSP_CERTID_insert(st, val, i) SKM_sk_insert(OCSP_CERTID, (st), (val), (i))
815#define sk_OCSP_CERTID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_CERTID, (st), (cmp))
816#define sk_OCSP_CERTID_dup(st) SKM_sk_dup(OCSP_CERTID, st)
817#define sk_OCSP_CERTID_pop_free(st, free_func) SKM_sk_pop_free(OCSP_CERTID, (st), (free_func))
818#define sk_OCSP_CERTID_shift(st) SKM_sk_shift(OCSP_CERTID, (st))
819#define sk_OCSP_CERTID_pop(st) SKM_sk_pop(OCSP_CERTID, (st))
820#define sk_OCSP_CERTID_sort(st) SKM_sk_sort(OCSP_CERTID, (st))
821#define sk_OCSP_CERTID_is_sorted(st) SKM_sk_is_sorted(OCSP_CERTID, (st))
822
823#define sk_OCSP_ONEREQ_new(st) SKM_sk_new(OCSP_ONEREQ, (st))
824#define sk_OCSP_ONEREQ_new_null() SKM_sk_new_null(OCSP_ONEREQ)
825#define sk_OCSP_ONEREQ_free(st) SKM_sk_free(OCSP_ONEREQ, (st))
826#define sk_OCSP_ONEREQ_num(st) SKM_sk_num(OCSP_ONEREQ, (st))
827#define sk_OCSP_ONEREQ_value(st, i) SKM_sk_value(OCSP_ONEREQ, (st), (i))
828#define sk_OCSP_ONEREQ_set(st, i, val) SKM_sk_set(OCSP_ONEREQ, (st), (i), (val))
829#define sk_OCSP_ONEREQ_zero(st) SKM_sk_zero(OCSP_ONEREQ, (st))
830#define sk_OCSP_ONEREQ_push(st, val) SKM_sk_push(OCSP_ONEREQ, (st), (val))
831#define sk_OCSP_ONEREQ_unshift(st, val) SKM_sk_unshift(OCSP_ONEREQ, (st), (val))
832#define sk_OCSP_ONEREQ_find(st, val) SKM_sk_find(OCSP_ONEREQ, (st), (val))
833#define sk_OCSP_ONEREQ_delete(st, i) SKM_sk_delete(OCSP_ONEREQ, (st), (i))
834#define sk_OCSP_ONEREQ_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_ONEREQ, (st), (ptr))
835#define sk_OCSP_ONEREQ_insert(st, val, i) SKM_sk_insert(OCSP_ONEREQ, (st), (val), (i))
836#define sk_OCSP_ONEREQ_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_ONEREQ, (st), (cmp))
837#define sk_OCSP_ONEREQ_dup(st) SKM_sk_dup(OCSP_ONEREQ, st)
838#define sk_OCSP_ONEREQ_pop_free(st, free_func) SKM_sk_pop_free(OCSP_ONEREQ, (st), (free_func))
839#define sk_OCSP_ONEREQ_shift(st) SKM_sk_shift(OCSP_ONEREQ, (st))
840#define sk_OCSP_ONEREQ_pop(st) SKM_sk_pop(OCSP_ONEREQ, (st))
841#define sk_OCSP_ONEREQ_sort(st) SKM_sk_sort(OCSP_ONEREQ, (st))
842#define sk_OCSP_ONEREQ_is_sorted(st) SKM_sk_is_sorted(OCSP_ONEREQ, (st))
843
844#define sk_OCSP_SINGLERESP_new(st) SKM_sk_new(OCSP_SINGLERESP, (st))
845#define sk_OCSP_SINGLERESP_new_null() SKM_sk_new_null(OCSP_SINGLERESP)
846#define sk_OCSP_SINGLERESP_free(st) SKM_sk_free(OCSP_SINGLERESP, (st))
847#define sk_OCSP_SINGLERESP_num(st) SKM_sk_num(OCSP_SINGLERESP, (st))
848#define sk_OCSP_SINGLERESP_value(st, i) SKM_sk_value(OCSP_SINGLERESP, (st), (i))
849#define sk_OCSP_SINGLERESP_set(st, i, val) SKM_sk_set(OCSP_SINGLERESP, (st), (i), (val))
850#define sk_OCSP_SINGLERESP_zero(st) SKM_sk_zero(OCSP_SINGLERESP, (st))
851#define sk_OCSP_SINGLERESP_push(st, val) SKM_sk_push(OCSP_SINGLERESP, (st), (val))
852#define sk_OCSP_SINGLERESP_unshift(st, val) SKM_sk_unshift(OCSP_SINGLERESP, (st), (val))
853#define sk_OCSP_SINGLERESP_find(st, val) SKM_sk_find(OCSP_SINGLERESP, (st), (val))
854#define sk_OCSP_SINGLERESP_delete(st, i) SKM_sk_delete(OCSP_SINGLERESP, (st), (i))
855#define sk_OCSP_SINGLERESP_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_SINGLERESP, (st), (ptr))
856#define sk_OCSP_SINGLERESP_insert(st, val, i) SKM_sk_insert(OCSP_SINGLERESP, (st), (val), (i))
857#define sk_OCSP_SINGLERESP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_SINGLERESP, (st), (cmp))
858#define sk_OCSP_SINGLERESP_dup(st) SKM_sk_dup(OCSP_SINGLERESP, st)
859#define sk_OCSP_SINGLERESP_pop_free(st, free_func) SKM_sk_pop_free(OCSP_SINGLERESP, (st), (free_func))
860#define sk_OCSP_SINGLERESP_shift(st) SKM_sk_shift(OCSP_SINGLERESP, (st))
861#define sk_OCSP_SINGLERESP_pop(st) SKM_sk_pop(OCSP_SINGLERESP, (st))
862#define sk_OCSP_SINGLERESP_sort(st) SKM_sk_sort(OCSP_SINGLERESP, (st))
863#define sk_OCSP_SINGLERESP_is_sorted(st) SKM_sk_is_sorted(OCSP_SINGLERESP, (st))
864
865#define sk_PKCS12_SAFEBAG_new(st) SKM_sk_new(PKCS12_SAFEBAG, (st))
866#define sk_PKCS12_SAFEBAG_new_null() SKM_sk_new_null(PKCS12_SAFEBAG)
867#define sk_PKCS12_SAFEBAG_free(st) SKM_sk_free(PKCS12_SAFEBAG, (st))
868#define sk_PKCS12_SAFEBAG_num(st) SKM_sk_num(PKCS12_SAFEBAG, (st))
869#define sk_PKCS12_SAFEBAG_value(st, i) SKM_sk_value(PKCS12_SAFEBAG, (st), (i))
870#define sk_PKCS12_SAFEBAG_set(st, i, val) SKM_sk_set(PKCS12_SAFEBAG, (st), (i), (val))
871#define sk_PKCS12_SAFEBAG_zero(st) SKM_sk_zero(PKCS12_SAFEBAG, (st))
872#define sk_PKCS12_SAFEBAG_push(st, val) SKM_sk_push(PKCS12_SAFEBAG, (st), (val))
873#define sk_PKCS12_SAFEBAG_unshift(st, val) SKM_sk_unshift(PKCS12_SAFEBAG, (st), (val))
874#define sk_PKCS12_SAFEBAG_find(st, val) SKM_sk_find(PKCS12_SAFEBAG, (st), (val))
875#define sk_PKCS12_SAFEBAG_delete(st, i) SKM_sk_delete(PKCS12_SAFEBAG, (st), (i))
876#define sk_PKCS12_SAFEBAG_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS12_SAFEBAG, (st), (ptr))
877#define sk_PKCS12_SAFEBAG_insert(st, val, i) SKM_sk_insert(PKCS12_SAFEBAG, (st), (val), (i))
878#define sk_PKCS12_SAFEBAG_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS12_SAFEBAG, (st), (cmp))
879#define sk_PKCS12_SAFEBAG_dup(st) SKM_sk_dup(PKCS12_SAFEBAG, st)
880#define sk_PKCS12_SAFEBAG_pop_free(st, free_func) SKM_sk_pop_free(PKCS12_SAFEBAG, (st), (free_func))
881#define sk_PKCS12_SAFEBAG_shift(st) SKM_sk_shift(PKCS12_SAFEBAG, (st))
882#define sk_PKCS12_SAFEBAG_pop(st) SKM_sk_pop(PKCS12_SAFEBAG, (st))
883#define sk_PKCS12_SAFEBAG_sort(st) SKM_sk_sort(PKCS12_SAFEBAG, (st))
884#define sk_PKCS12_SAFEBAG_is_sorted(st) SKM_sk_is_sorted(PKCS12_SAFEBAG, (st))
885
886#define sk_PKCS7_new(st) SKM_sk_new(PKCS7, (st))
887#define sk_PKCS7_new_null() SKM_sk_new_null(PKCS7)
888#define sk_PKCS7_free(st) SKM_sk_free(PKCS7, (st))
889#define sk_PKCS7_num(st) SKM_sk_num(PKCS7, (st))
890#define sk_PKCS7_value(st, i) SKM_sk_value(PKCS7, (st), (i))
891#define sk_PKCS7_set(st, i, val) SKM_sk_set(PKCS7, (st), (i), (val))
892#define sk_PKCS7_zero(st) SKM_sk_zero(PKCS7, (st))
893#define sk_PKCS7_push(st, val) SKM_sk_push(PKCS7, (st), (val))
894#define sk_PKCS7_unshift(st, val) SKM_sk_unshift(PKCS7, (st), (val))
895#define sk_PKCS7_find(st, val) SKM_sk_find(PKCS7, (st), (val))
896#define sk_PKCS7_delete(st, i) SKM_sk_delete(PKCS7, (st), (i))
897#define sk_PKCS7_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7, (st), (ptr))
898#define sk_PKCS7_insert(st, val, i) SKM_sk_insert(PKCS7, (st), (val), (i))
899#define sk_PKCS7_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7, (st), (cmp))
900#define sk_PKCS7_dup(st) SKM_sk_dup(PKCS7, st)
901#define sk_PKCS7_pop_free(st, free_func) SKM_sk_pop_free(PKCS7, (st), (free_func))
902#define sk_PKCS7_shift(st) SKM_sk_shift(PKCS7, (st))
903#define sk_PKCS7_pop(st) SKM_sk_pop(PKCS7, (st))
904#define sk_PKCS7_sort(st) SKM_sk_sort(PKCS7, (st))
905#define sk_PKCS7_is_sorted(st) SKM_sk_is_sorted(PKCS7, (st))
906
907#define sk_PKCS7_RECIP_INFO_new(st) SKM_sk_new(PKCS7_RECIP_INFO, (st))
908#define sk_PKCS7_RECIP_INFO_new_null() SKM_sk_new_null(PKCS7_RECIP_INFO)
909#define sk_PKCS7_RECIP_INFO_free(st) SKM_sk_free(PKCS7_RECIP_INFO, (st))
910#define sk_PKCS7_RECIP_INFO_num(st) SKM_sk_num(PKCS7_RECIP_INFO, (st))
911#define sk_PKCS7_RECIP_INFO_value(st, i) SKM_sk_value(PKCS7_RECIP_INFO, (st), (i))
912#define sk_PKCS7_RECIP_INFO_set(st, i, val) SKM_sk_set(PKCS7_RECIP_INFO, (st), (i), (val))
913#define sk_PKCS7_RECIP_INFO_zero(st) SKM_sk_zero(PKCS7_RECIP_INFO, (st))
914#define sk_PKCS7_RECIP_INFO_push(st, val) SKM_sk_push(PKCS7_RECIP_INFO, (st), (val))
915#define sk_PKCS7_RECIP_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_RECIP_INFO, (st), (val))
916#define sk_PKCS7_RECIP_INFO_find(st, val) SKM_sk_find(PKCS7_RECIP_INFO, (st), (val))
917#define sk_PKCS7_RECIP_INFO_delete(st, i) SKM_sk_delete(PKCS7_RECIP_INFO, (st), (i))
918#define sk_PKCS7_RECIP_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_RECIP_INFO, (st), (ptr))
919#define sk_PKCS7_RECIP_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_RECIP_INFO, (st), (val), (i))
920#define sk_PKCS7_RECIP_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7_RECIP_INFO, (st), (cmp))
921#define sk_PKCS7_RECIP_INFO_dup(st) SKM_sk_dup(PKCS7_RECIP_INFO, st)
922#define sk_PKCS7_RECIP_INFO_pop_free(st, free_func) SKM_sk_pop_free(PKCS7_RECIP_INFO, (st), (free_func))
923#define sk_PKCS7_RECIP_INFO_shift(st) SKM_sk_shift(PKCS7_RECIP_INFO, (st))
924#define sk_PKCS7_RECIP_INFO_pop(st) SKM_sk_pop(PKCS7_RECIP_INFO, (st))
925#define sk_PKCS7_RECIP_INFO_sort(st) SKM_sk_sort(PKCS7_RECIP_INFO, (st))
926#define sk_PKCS7_RECIP_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_RECIP_INFO, (st))
927
928#define sk_PKCS7_SIGNER_INFO_new(st) SKM_sk_new(PKCS7_SIGNER_INFO, (st))
929#define sk_PKCS7_SIGNER_INFO_new_null() SKM_sk_new_null(PKCS7_SIGNER_INFO)
930#define sk_PKCS7_SIGNER_INFO_free(st) SKM_sk_free(PKCS7_SIGNER_INFO, (st))
931#define sk_PKCS7_SIGNER_INFO_num(st) SKM_sk_num(PKCS7_SIGNER_INFO, (st))
932#define sk_PKCS7_SIGNER_INFO_value(st, i) SKM_sk_value(PKCS7_SIGNER_INFO, (st), (i))
933#define sk_PKCS7_SIGNER_INFO_set(st, i, val) SKM_sk_set(PKCS7_SIGNER_INFO, (st), (i), (val))
934#define sk_PKCS7_SIGNER_INFO_zero(st) SKM_sk_zero(PKCS7_SIGNER_INFO, (st))
935#define sk_PKCS7_SIGNER_INFO_push(st, val) SKM_sk_push(PKCS7_SIGNER_INFO, (st), (val))
936#define sk_PKCS7_SIGNER_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_SIGNER_INFO, (st), (val))
937#define sk_PKCS7_SIGNER_INFO_find(st, val) SKM_sk_find(PKCS7_SIGNER_INFO, (st), (val))
938#define sk_PKCS7_SIGNER_INFO_delete(st, i) SKM_sk_delete(PKCS7_SIGNER_INFO, (st), (i))
939#define sk_PKCS7_SIGNER_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_SIGNER_INFO, (st), (ptr))
940#define sk_PKCS7_SIGNER_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_SIGNER_INFO, (st), (val), (i))
941#define sk_PKCS7_SIGNER_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(PKCS7_SIGNER_INFO, (st), (cmp))
942#define sk_PKCS7_SIGNER_INFO_dup(st) SKM_sk_dup(PKCS7_SIGNER_INFO, st)
943#define sk_PKCS7_SIGNER_INFO_pop_free(st, free_func) SKM_sk_pop_free(PKCS7_SIGNER_INFO, (st), (free_func))
944#define sk_PKCS7_SIGNER_INFO_shift(st) SKM_sk_shift(PKCS7_SIGNER_INFO, (st))
945#define sk_PKCS7_SIGNER_INFO_pop(st) SKM_sk_pop(PKCS7_SIGNER_INFO, (st))
946#define sk_PKCS7_SIGNER_INFO_sort(st) SKM_sk_sort(PKCS7_SIGNER_INFO, (st))
947#define sk_PKCS7_SIGNER_INFO_is_sorted(st) SKM_sk_is_sorted(PKCS7_SIGNER_INFO, (st))
948
949#define sk_POLICYINFO_new(st) SKM_sk_new(POLICYINFO, (st))
950#define sk_POLICYINFO_new_null() SKM_sk_new_null(POLICYINFO)
951#define sk_POLICYINFO_free(st) SKM_sk_free(POLICYINFO, (st))
952#define sk_POLICYINFO_num(st) SKM_sk_num(POLICYINFO, (st))
953#define sk_POLICYINFO_value(st, i) SKM_sk_value(POLICYINFO, (st), (i))
954#define sk_POLICYINFO_set(st, i, val) SKM_sk_set(POLICYINFO, (st), (i), (val))
955#define sk_POLICYINFO_zero(st) SKM_sk_zero(POLICYINFO, (st))
956#define sk_POLICYINFO_push(st, val) SKM_sk_push(POLICYINFO, (st), (val))
957#define sk_POLICYINFO_unshift(st, val) SKM_sk_unshift(POLICYINFO, (st), (val))
958#define sk_POLICYINFO_find(st, val) SKM_sk_find(POLICYINFO, (st), (val))
959#define sk_POLICYINFO_delete(st, i) SKM_sk_delete(POLICYINFO, (st), (i))
960#define sk_POLICYINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYINFO, (st), (ptr))
961#define sk_POLICYINFO_insert(st, val, i) SKM_sk_insert(POLICYINFO, (st), (val), (i))
962#define sk_POLICYINFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICYINFO, (st), (cmp))
963#define sk_POLICYINFO_dup(st) SKM_sk_dup(POLICYINFO, st)
964#define sk_POLICYINFO_pop_free(st, free_func) SKM_sk_pop_free(POLICYINFO, (st), (free_func))
965#define sk_POLICYINFO_shift(st) SKM_sk_shift(POLICYINFO, (st))
966#define sk_POLICYINFO_pop(st) SKM_sk_pop(POLICYINFO, (st))
967#define sk_POLICYINFO_sort(st) SKM_sk_sort(POLICYINFO, (st))
968#define sk_POLICYINFO_is_sorted(st) SKM_sk_is_sorted(POLICYINFO, (st))
969
970#define sk_POLICYQUALINFO_new(st) SKM_sk_new(POLICYQUALINFO, (st))
971#define sk_POLICYQUALINFO_new_null() SKM_sk_new_null(POLICYQUALINFO)
972#define sk_POLICYQUALINFO_free(st) SKM_sk_free(POLICYQUALINFO, (st))
973#define sk_POLICYQUALINFO_num(st) SKM_sk_num(POLICYQUALINFO, (st))
974#define sk_POLICYQUALINFO_value(st, i) SKM_sk_value(POLICYQUALINFO, (st), (i))
975#define sk_POLICYQUALINFO_set(st, i, val) SKM_sk_set(POLICYQUALINFO, (st), (i), (val))
976#define sk_POLICYQUALINFO_zero(st) SKM_sk_zero(POLICYQUALINFO, (st))
977#define sk_POLICYQUALINFO_push(st, val) SKM_sk_push(POLICYQUALINFO, (st), (val))
978#define sk_POLICYQUALINFO_unshift(st, val) SKM_sk_unshift(POLICYQUALINFO, (st), (val))
979#define sk_POLICYQUALINFO_find(st, val) SKM_sk_find(POLICYQUALINFO, (st), (val))
980#define sk_POLICYQUALINFO_delete(st, i) SKM_sk_delete(POLICYQUALINFO, (st), (i))
981#define sk_POLICYQUALINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYQUALINFO, (st), (ptr))
982#define sk_POLICYQUALINFO_insert(st, val, i) SKM_sk_insert(POLICYQUALINFO, (st), (val), (i))
983#define sk_POLICYQUALINFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICYQUALINFO, (st), (cmp))
984#define sk_POLICYQUALINFO_dup(st) SKM_sk_dup(POLICYQUALINFO, st)
985#define sk_POLICYQUALINFO_pop_free(st, free_func) SKM_sk_pop_free(POLICYQUALINFO, (st), (free_func))
986#define sk_POLICYQUALINFO_shift(st) SKM_sk_shift(POLICYQUALINFO, (st))
987#define sk_POLICYQUALINFO_pop(st) SKM_sk_pop(POLICYQUALINFO, (st))
988#define sk_POLICYQUALINFO_sort(st) SKM_sk_sort(POLICYQUALINFO, (st))
989#define sk_POLICYQUALINFO_is_sorted(st) SKM_sk_is_sorted(POLICYQUALINFO, (st))
990
991#define sk_SSL_CIPHER_new(st) SKM_sk_new(SSL_CIPHER, (st))
992#define sk_SSL_CIPHER_new_null() SKM_sk_new_null(SSL_CIPHER)
993#define sk_SSL_CIPHER_free(st) SKM_sk_free(SSL_CIPHER, (st))
994#define sk_SSL_CIPHER_num(st) SKM_sk_num(SSL_CIPHER, (st))
995#define sk_SSL_CIPHER_value(st, i) SKM_sk_value(SSL_CIPHER, (st), (i))
996#define sk_SSL_CIPHER_set(st, i, val) SKM_sk_set(SSL_CIPHER, (st), (i), (val))
997#define sk_SSL_CIPHER_zero(st) SKM_sk_zero(SSL_CIPHER, (st))
998#define sk_SSL_CIPHER_push(st, val) SKM_sk_push(SSL_CIPHER, (st), (val))
999#define sk_SSL_CIPHER_unshift(st, val) SKM_sk_unshift(SSL_CIPHER, (st), (val))
1000#define sk_SSL_CIPHER_find(st, val) SKM_sk_find(SSL_CIPHER, (st), (val))
1001#define sk_SSL_CIPHER_delete(st, i) SKM_sk_delete(SSL_CIPHER, (st), (i))
1002#define sk_SSL_CIPHER_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_CIPHER, (st), (ptr))
1003#define sk_SSL_CIPHER_insert(st, val, i) SKM_sk_insert(SSL_CIPHER, (st), (val), (i))
1004#define sk_SSL_CIPHER_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SSL_CIPHER, (st), (cmp))
1005#define sk_SSL_CIPHER_dup(st) SKM_sk_dup(SSL_CIPHER, st)
1006#define sk_SSL_CIPHER_pop_free(st, free_func) SKM_sk_pop_free(SSL_CIPHER, (st), (free_func))
1007#define sk_SSL_CIPHER_shift(st) SKM_sk_shift(SSL_CIPHER, (st))
1008#define sk_SSL_CIPHER_pop(st) SKM_sk_pop(SSL_CIPHER, (st))
1009#define sk_SSL_CIPHER_sort(st) SKM_sk_sort(SSL_CIPHER, (st))
1010#define sk_SSL_CIPHER_is_sorted(st) SKM_sk_is_sorted(SSL_CIPHER, (st))
1011
1012#define sk_SSL_COMP_new(st) SKM_sk_new(SSL_COMP, (st))
1013#define sk_SSL_COMP_new_null() SKM_sk_new_null(SSL_COMP)
1014#define sk_SSL_COMP_free(st) SKM_sk_free(SSL_COMP, (st))
1015#define sk_SSL_COMP_num(st) SKM_sk_num(SSL_COMP, (st))
1016#define sk_SSL_COMP_value(st, i) SKM_sk_value(SSL_COMP, (st), (i))
1017#define sk_SSL_COMP_set(st, i, val) SKM_sk_set(SSL_COMP, (st), (i), (val))
1018#define sk_SSL_COMP_zero(st) SKM_sk_zero(SSL_COMP, (st))
1019#define sk_SSL_COMP_push(st, val) SKM_sk_push(SSL_COMP, (st), (val))
1020#define sk_SSL_COMP_unshift(st, val) SKM_sk_unshift(SSL_COMP, (st), (val))
1021#define sk_SSL_COMP_find(st, val) SKM_sk_find(SSL_COMP, (st), (val))
1022#define sk_SSL_COMP_delete(st, i) SKM_sk_delete(SSL_COMP, (st), (i))
1023#define sk_SSL_COMP_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_COMP, (st), (ptr))
1024#define sk_SSL_COMP_insert(st, val, i) SKM_sk_insert(SSL_COMP, (st), (val), (i))
1025#define sk_SSL_COMP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SSL_COMP, (st), (cmp))
1026#define sk_SSL_COMP_dup(st) SKM_sk_dup(SSL_COMP, st)
1027#define sk_SSL_COMP_pop_free(st, free_func) SKM_sk_pop_free(SSL_COMP, (st), (free_func))
1028#define sk_SSL_COMP_shift(st) SKM_sk_shift(SSL_COMP, (st))
1029#define sk_SSL_COMP_pop(st) SKM_sk_pop(SSL_COMP, (st))
1030#define sk_SSL_COMP_sort(st) SKM_sk_sort(SSL_COMP, (st))
1031#define sk_SSL_COMP_is_sorted(st) SKM_sk_is_sorted(SSL_COMP, (st))
1032
1033#define sk_SXNETID_new(st) SKM_sk_new(SXNETID, (st))
1034#define sk_SXNETID_new_null() SKM_sk_new_null(SXNETID)
1035#define sk_SXNETID_free(st) SKM_sk_free(SXNETID, (st))
1036#define sk_SXNETID_num(st) SKM_sk_num(SXNETID, (st))
1037#define sk_SXNETID_value(st, i) SKM_sk_value(SXNETID, (st), (i))
1038#define sk_SXNETID_set(st, i, val) SKM_sk_set(SXNETID, (st), (i), (val))
1039#define sk_SXNETID_zero(st) SKM_sk_zero(SXNETID, (st))
1040#define sk_SXNETID_push(st, val) SKM_sk_push(SXNETID, (st), (val))
1041#define sk_SXNETID_unshift(st, val) SKM_sk_unshift(SXNETID, (st), (val))
1042#define sk_SXNETID_find(st, val) SKM_sk_find(SXNETID, (st), (val))
1043#define sk_SXNETID_delete(st, i) SKM_sk_delete(SXNETID, (st), (i))
1044#define sk_SXNETID_delete_ptr(st, ptr) SKM_sk_delete_ptr(SXNETID, (st), (ptr))
1045#define sk_SXNETID_insert(st, val, i) SKM_sk_insert(SXNETID, (st), (val), (i))
1046#define sk_SXNETID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(SXNETID, (st), (cmp))
1047#define sk_SXNETID_dup(st) SKM_sk_dup(SXNETID, st)
1048#define sk_SXNETID_pop_free(st, free_func) SKM_sk_pop_free(SXNETID, (st), (free_func))
1049#define sk_SXNETID_shift(st) SKM_sk_shift(SXNETID, (st))
1050#define sk_SXNETID_pop(st) SKM_sk_pop(SXNETID, (st))
1051#define sk_SXNETID_sort(st) SKM_sk_sort(SXNETID, (st))
1052#define sk_SXNETID_is_sorted(st) SKM_sk_is_sorted(SXNETID, (st))
1053
1054#define sk_UI_STRING_new(st) SKM_sk_new(UI_STRING, (st))
1055#define sk_UI_STRING_new_null() SKM_sk_new_null(UI_STRING)
1056#define sk_UI_STRING_free(st) SKM_sk_free(UI_STRING, (st))
1057#define sk_UI_STRING_num(st) SKM_sk_num(UI_STRING, (st))
1058#define sk_UI_STRING_value(st, i) SKM_sk_value(UI_STRING, (st), (i))
1059#define sk_UI_STRING_set(st, i, val) SKM_sk_set(UI_STRING, (st), (i), (val))
1060#define sk_UI_STRING_zero(st) SKM_sk_zero(UI_STRING, (st))
1061#define sk_UI_STRING_push(st, val) SKM_sk_push(UI_STRING, (st), (val))
1062#define sk_UI_STRING_unshift(st, val) SKM_sk_unshift(UI_STRING, (st), (val))
1063#define sk_UI_STRING_find(st, val) SKM_sk_find(UI_STRING, (st), (val))
1064#define sk_UI_STRING_delete(st, i) SKM_sk_delete(UI_STRING, (st), (i))
1065#define sk_UI_STRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(UI_STRING, (st), (ptr))
1066#define sk_UI_STRING_insert(st, val, i) SKM_sk_insert(UI_STRING, (st), (val), (i))
1067#define sk_UI_STRING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(UI_STRING, (st), (cmp))
1068#define sk_UI_STRING_dup(st) SKM_sk_dup(UI_STRING, st)
1069#define sk_UI_STRING_pop_free(st, free_func) SKM_sk_pop_free(UI_STRING, (st), (free_func))
1070#define sk_UI_STRING_shift(st) SKM_sk_shift(UI_STRING, (st))
1071#define sk_UI_STRING_pop(st) SKM_sk_pop(UI_STRING, (st))
1072#define sk_UI_STRING_sort(st) SKM_sk_sort(UI_STRING, (st))
1073#define sk_UI_STRING_is_sorted(st) SKM_sk_is_sorted(UI_STRING, (st))
1074
1075#define sk_X509_new(st) SKM_sk_new(X509, (st))
1076#define sk_X509_new_null() SKM_sk_new_null(X509)
1077#define sk_X509_free(st) SKM_sk_free(X509, (st))
1078#define sk_X509_num(st) SKM_sk_num(X509, (st))
1079#define sk_X509_value(st, i) SKM_sk_value(X509, (st), (i))
1080#define sk_X509_set(st, i, val) SKM_sk_set(X509, (st), (i), (val))
1081#define sk_X509_zero(st) SKM_sk_zero(X509, (st))
1082#define sk_X509_push(st, val) SKM_sk_push(X509, (st), (val))
1083#define sk_X509_unshift(st, val) SKM_sk_unshift(X509, (st), (val))
1084#define sk_X509_find(st, val) SKM_sk_find(X509, (st), (val))
1085#define sk_X509_delete(st, i) SKM_sk_delete(X509, (st), (i))
1086#define sk_X509_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509, (st), (ptr))
1087#define sk_X509_insert(st, val, i) SKM_sk_insert(X509, (st), (val), (i))
1088#define sk_X509_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509, (st), (cmp))
1089#define sk_X509_dup(st) SKM_sk_dup(X509, st)
1090#define sk_X509_pop_free(st, free_func) SKM_sk_pop_free(X509, (st), (free_func))
1091#define sk_X509_shift(st) SKM_sk_shift(X509, (st))
1092#define sk_X509_pop(st) SKM_sk_pop(X509, (st))
1093#define sk_X509_sort(st) SKM_sk_sort(X509, (st))
1094#define sk_X509_is_sorted(st) SKM_sk_is_sorted(X509, (st))
1095
1096#define sk_X509V3_EXT_METHOD_new(st) SKM_sk_new(X509V3_EXT_METHOD, (st))
1097#define sk_X509V3_EXT_METHOD_new_null() SKM_sk_new_null(X509V3_EXT_METHOD)
1098#define sk_X509V3_EXT_METHOD_free(st) SKM_sk_free(X509V3_EXT_METHOD, (st))
1099#define sk_X509V3_EXT_METHOD_num(st) SKM_sk_num(X509V3_EXT_METHOD, (st))
1100#define sk_X509V3_EXT_METHOD_value(st, i) SKM_sk_value(X509V3_EXT_METHOD, (st), (i))
1101#define sk_X509V3_EXT_METHOD_set(st, i, val) SKM_sk_set(X509V3_EXT_METHOD, (st), (i), (val))
1102#define sk_X509V3_EXT_METHOD_zero(st) SKM_sk_zero(X509V3_EXT_METHOD, (st))
1103#define sk_X509V3_EXT_METHOD_push(st, val) SKM_sk_push(X509V3_EXT_METHOD, (st), (val))
1104#define sk_X509V3_EXT_METHOD_unshift(st, val) SKM_sk_unshift(X509V3_EXT_METHOD, (st), (val))
1105#define sk_X509V3_EXT_METHOD_find(st, val) SKM_sk_find(X509V3_EXT_METHOD, (st), (val))
1106#define sk_X509V3_EXT_METHOD_delete(st, i) SKM_sk_delete(X509V3_EXT_METHOD, (st), (i))
1107#define sk_X509V3_EXT_METHOD_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509V3_EXT_METHOD, (st), (ptr))
1108#define sk_X509V3_EXT_METHOD_insert(st, val, i) SKM_sk_insert(X509V3_EXT_METHOD, (st), (val), (i))
1109#define sk_X509V3_EXT_METHOD_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509V3_EXT_METHOD, (st), (cmp))
1110#define sk_X509V3_EXT_METHOD_dup(st) SKM_sk_dup(X509V3_EXT_METHOD, st)
1111#define sk_X509V3_EXT_METHOD_pop_free(st, free_func) SKM_sk_pop_free(X509V3_EXT_METHOD, (st), (free_func))
1112#define sk_X509V3_EXT_METHOD_shift(st) SKM_sk_shift(X509V3_EXT_METHOD, (st))
1113#define sk_X509V3_EXT_METHOD_pop(st) SKM_sk_pop(X509V3_EXT_METHOD, (st))
1114#define sk_X509V3_EXT_METHOD_sort(st) SKM_sk_sort(X509V3_EXT_METHOD, (st))
1115#define sk_X509V3_EXT_METHOD_is_sorted(st) SKM_sk_is_sorted(X509V3_EXT_METHOD, (st))
1116
1117#define sk_X509_ALGOR_new(st) SKM_sk_new(X509_ALGOR, (st))
1118#define sk_X509_ALGOR_new_null() SKM_sk_new_null(X509_ALGOR)
1119#define sk_X509_ALGOR_free(st) SKM_sk_free(X509_ALGOR, (st))
1120#define sk_X509_ALGOR_num(st) SKM_sk_num(X509_ALGOR, (st))
1121#define sk_X509_ALGOR_value(st, i) SKM_sk_value(X509_ALGOR, (st), (i))
1122#define sk_X509_ALGOR_set(st, i, val) SKM_sk_set(X509_ALGOR, (st), (i), (val))
1123#define sk_X509_ALGOR_zero(st) SKM_sk_zero(X509_ALGOR, (st))
1124#define sk_X509_ALGOR_push(st, val) SKM_sk_push(X509_ALGOR, (st), (val))
1125#define sk_X509_ALGOR_unshift(st, val) SKM_sk_unshift(X509_ALGOR, (st), (val))
1126#define sk_X509_ALGOR_find(st, val) SKM_sk_find(X509_ALGOR, (st), (val))
1127#define sk_X509_ALGOR_delete(st, i) SKM_sk_delete(X509_ALGOR, (st), (i))
1128#define sk_X509_ALGOR_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ALGOR, (st), (ptr))
1129#define sk_X509_ALGOR_insert(st, val, i) SKM_sk_insert(X509_ALGOR, (st), (val), (i))
1130#define sk_X509_ALGOR_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_ALGOR, (st), (cmp))
1131#define sk_X509_ALGOR_dup(st) SKM_sk_dup(X509_ALGOR, st)
1132#define sk_X509_ALGOR_pop_free(st, free_func) SKM_sk_pop_free(X509_ALGOR, (st), (free_func))
1133#define sk_X509_ALGOR_shift(st) SKM_sk_shift(X509_ALGOR, (st))
1134#define sk_X509_ALGOR_pop(st) SKM_sk_pop(X509_ALGOR, (st))
1135#define sk_X509_ALGOR_sort(st) SKM_sk_sort(X509_ALGOR, (st))
1136#define sk_X509_ALGOR_is_sorted(st) SKM_sk_is_sorted(X509_ALGOR, (st))
1137
1138#define sk_X509_ATTRIBUTE_new(st) SKM_sk_new(X509_ATTRIBUTE, (st))
1139#define sk_X509_ATTRIBUTE_new_null() SKM_sk_new_null(X509_ATTRIBUTE)
1140#define sk_X509_ATTRIBUTE_free(st) SKM_sk_free(X509_ATTRIBUTE, (st))
1141#define sk_X509_ATTRIBUTE_num(st) SKM_sk_num(X509_ATTRIBUTE, (st))
1142#define sk_X509_ATTRIBUTE_value(st, i) SKM_sk_value(X509_ATTRIBUTE, (st), (i))
1143#define sk_X509_ATTRIBUTE_set(st, i, val) SKM_sk_set(X509_ATTRIBUTE, (st), (i), (val))
1144#define sk_X509_ATTRIBUTE_zero(st) SKM_sk_zero(X509_ATTRIBUTE, (st))
1145#define sk_X509_ATTRIBUTE_push(st, val) SKM_sk_push(X509_ATTRIBUTE, (st), (val))
1146#define sk_X509_ATTRIBUTE_unshift(st, val) SKM_sk_unshift(X509_ATTRIBUTE, (st), (val))
1147#define sk_X509_ATTRIBUTE_find(st, val) SKM_sk_find(X509_ATTRIBUTE, (st), (val))
1148#define sk_X509_ATTRIBUTE_delete(st, i) SKM_sk_delete(X509_ATTRIBUTE, (st), (i))
1149#define sk_X509_ATTRIBUTE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ATTRIBUTE, (st), (ptr))
1150#define sk_X509_ATTRIBUTE_insert(st, val, i) SKM_sk_insert(X509_ATTRIBUTE, (st), (val), (i))
1151#define sk_X509_ATTRIBUTE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_ATTRIBUTE, (st), (cmp))
1152#define sk_X509_ATTRIBUTE_dup(st) SKM_sk_dup(X509_ATTRIBUTE, st)
1153#define sk_X509_ATTRIBUTE_pop_free(st, free_func) SKM_sk_pop_free(X509_ATTRIBUTE, (st), (free_func))
1154#define sk_X509_ATTRIBUTE_shift(st) SKM_sk_shift(X509_ATTRIBUTE, (st))
1155#define sk_X509_ATTRIBUTE_pop(st) SKM_sk_pop(X509_ATTRIBUTE, (st))
1156#define sk_X509_ATTRIBUTE_sort(st) SKM_sk_sort(X509_ATTRIBUTE, (st))
1157#define sk_X509_ATTRIBUTE_is_sorted(st) SKM_sk_is_sorted(X509_ATTRIBUTE, (st))
1158
1159#define sk_X509_CRL_new(st) SKM_sk_new(X509_CRL, (st))
1160#define sk_X509_CRL_new_null() SKM_sk_new_null(X509_CRL)
1161#define sk_X509_CRL_free(st) SKM_sk_free(X509_CRL, (st))
1162#define sk_X509_CRL_num(st) SKM_sk_num(X509_CRL, (st))
1163#define sk_X509_CRL_value(st, i) SKM_sk_value(X509_CRL, (st), (i))
1164#define sk_X509_CRL_set(st, i, val) SKM_sk_set(X509_CRL, (st), (i), (val))
1165#define sk_X509_CRL_zero(st) SKM_sk_zero(X509_CRL, (st))
1166#define sk_X509_CRL_push(st, val) SKM_sk_push(X509_CRL, (st), (val))
1167#define sk_X509_CRL_unshift(st, val) SKM_sk_unshift(X509_CRL, (st), (val))
1168#define sk_X509_CRL_find(st, val) SKM_sk_find(X509_CRL, (st), (val))
1169#define sk_X509_CRL_delete(st, i) SKM_sk_delete(X509_CRL, (st), (i))
1170#define sk_X509_CRL_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_CRL, (st), (ptr))
1171#define sk_X509_CRL_insert(st, val, i) SKM_sk_insert(X509_CRL, (st), (val), (i))
1172#define sk_X509_CRL_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_CRL, (st), (cmp))
1173#define sk_X509_CRL_dup(st) SKM_sk_dup(X509_CRL, st)
1174#define sk_X509_CRL_pop_free(st, free_func) SKM_sk_pop_free(X509_CRL, (st), (free_func))
1175#define sk_X509_CRL_shift(st) SKM_sk_shift(X509_CRL, (st))
1176#define sk_X509_CRL_pop(st) SKM_sk_pop(X509_CRL, (st))
1177#define sk_X509_CRL_sort(st) SKM_sk_sort(X509_CRL, (st))
1178#define sk_X509_CRL_is_sorted(st) SKM_sk_is_sorted(X509_CRL, (st))
1179
1180#define sk_X509_EXTENSION_new(st) SKM_sk_new(X509_EXTENSION, (st))
1181#define sk_X509_EXTENSION_new_null() SKM_sk_new_null(X509_EXTENSION)
1182#define sk_X509_EXTENSION_free(st) SKM_sk_free(X509_EXTENSION, (st))
1183#define sk_X509_EXTENSION_num(st) SKM_sk_num(X509_EXTENSION, (st))
1184#define sk_X509_EXTENSION_value(st, i) SKM_sk_value(X509_EXTENSION, (st), (i))
1185#define sk_X509_EXTENSION_set(st, i, val) SKM_sk_set(X509_EXTENSION, (st), (i), (val))
1186#define sk_X509_EXTENSION_zero(st) SKM_sk_zero(X509_EXTENSION, (st))
1187#define sk_X509_EXTENSION_push(st, val) SKM_sk_push(X509_EXTENSION, (st), (val))
1188#define sk_X509_EXTENSION_unshift(st, val) SKM_sk_unshift(X509_EXTENSION, (st), (val))
1189#define sk_X509_EXTENSION_find(st, val) SKM_sk_find(X509_EXTENSION, (st), (val))
1190#define sk_X509_EXTENSION_delete(st, i) SKM_sk_delete(X509_EXTENSION, (st), (i))
1191#define sk_X509_EXTENSION_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_EXTENSION, (st), (ptr))
1192#define sk_X509_EXTENSION_insert(st, val, i) SKM_sk_insert(X509_EXTENSION, (st), (val), (i))
1193#define sk_X509_EXTENSION_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_EXTENSION, (st), (cmp))
1194#define sk_X509_EXTENSION_dup(st) SKM_sk_dup(X509_EXTENSION, st)
1195#define sk_X509_EXTENSION_pop_free(st, free_func) SKM_sk_pop_free(X509_EXTENSION, (st), (free_func))
1196#define sk_X509_EXTENSION_shift(st) SKM_sk_shift(X509_EXTENSION, (st))
1197#define sk_X509_EXTENSION_pop(st) SKM_sk_pop(X509_EXTENSION, (st))
1198#define sk_X509_EXTENSION_sort(st) SKM_sk_sort(X509_EXTENSION, (st))
1199#define sk_X509_EXTENSION_is_sorted(st) SKM_sk_is_sorted(X509_EXTENSION, (st))
1200
1201#define sk_X509_INFO_new(st) SKM_sk_new(X509_INFO, (st))
1202#define sk_X509_INFO_new_null() SKM_sk_new_null(X509_INFO)
1203#define sk_X509_INFO_free(st) SKM_sk_free(X509_INFO, (st))
1204#define sk_X509_INFO_num(st) SKM_sk_num(X509_INFO, (st))
1205#define sk_X509_INFO_value(st, i) SKM_sk_value(X509_INFO, (st), (i))
1206#define sk_X509_INFO_set(st, i, val) SKM_sk_set(X509_INFO, (st), (i), (val))
1207#define sk_X509_INFO_zero(st) SKM_sk_zero(X509_INFO, (st))
1208#define sk_X509_INFO_push(st, val) SKM_sk_push(X509_INFO, (st), (val))
1209#define sk_X509_INFO_unshift(st, val) SKM_sk_unshift(X509_INFO, (st), (val))
1210#define sk_X509_INFO_find(st, val) SKM_sk_find(X509_INFO, (st), (val))
1211#define sk_X509_INFO_delete(st, i) SKM_sk_delete(X509_INFO, (st), (i))
1212#define sk_X509_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_INFO, (st), (ptr))
1213#define sk_X509_INFO_insert(st, val, i) SKM_sk_insert(X509_INFO, (st), (val), (i))
1214#define sk_X509_INFO_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_INFO, (st), (cmp))
1215#define sk_X509_INFO_dup(st) SKM_sk_dup(X509_INFO, st)
1216#define sk_X509_INFO_pop_free(st, free_func) SKM_sk_pop_free(X509_INFO, (st), (free_func))
1217#define sk_X509_INFO_shift(st) SKM_sk_shift(X509_INFO, (st))
1218#define sk_X509_INFO_pop(st) SKM_sk_pop(X509_INFO, (st))
1219#define sk_X509_INFO_sort(st) SKM_sk_sort(X509_INFO, (st))
1220#define sk_X509_INFO_is_sorted(st) SKM_sk_is_sorted(X509_INFO, (st))
1221
1222#define sk_X509_LOOKUP_new(st) SKM_sk_new(X509_LOOKUP, (st))
1223#define sk_X509_LOOKUP_new_null() SKM_sk_new_null(X509_LOOKUP)
1224#define sk_X509_LOOKUP_free(st) SKM_sk_free(X509_LOOKUP, (st))
1225#define sk_X509_LOOKUP_num(st) SKM_sk_num(X509_LOOKUP, (st))
1226#define sk_X509_LOOKUP_value(st, i) SKM_sk_value(X509_LOOKUP, (st), (i))
1227#define sk_X509_LOOKUP_set(st, i, val) SKM_sk_set(X509_LOOKUP, (st), (i), (val))
1228#define sk_X509_LOOKUP_zero(st) SKM_sk_zero(X509_LOOKUP, (st))
1229#define sk_X509_LOOKUP_push(st, val) SKM_sk_push(X509_LOOKUP, (st), (val))
1230#define sk_X509_LOOKUP_unshift(st, val) SKM_sk_unshift(X509_LOOKUP, (st), (val))
1231#define sk_X509_LOOKUP_find(st, val) SKM_sk_find(X509_LOOKUP, (st), (val))
1232#define sk_X509_LOOKUP_delete(st, i) SKM_sk_delete(X509_LOOKUP, (st), (i))
1233#define sk_X509_LOOKUP_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_LOOKUP, (st), (ptr))
1234#define sk_X509_LOOKUP_insert(st, val, i) SKM_sk_insert(X509_LOOKUP, (st), (val), (i))
1235#define sk_X509_LOOKUP_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_LOOKUP, (st), (cmp))
1236#define sk_X509_LOOKUP_dup(st) SKM_sk_dup(X509_LOOKUP, st)
1237#define sk_X509_LOOKUP_pop_free(st, free_func) SKM_sk_pop_free(X509_LOOKUP, (st), (free_func))
1238#define sk_X509_LOOKUP_shift(st) SKM_sk_shift(X509_LOOKUP, (st))
1239#define sk_X509_LOOKUP_pop(st) SKM_sk_pop(X509_LOOKUP, (st))
1240#define sk_X509_LOOKUP_sort(st) SKM_sk_sort(X509_LOOKUP, (st))
1241#define sk_X509_LOOKUP_is_sorted(st) SKM_sk_is_sorted(X509_LOOKUP, (st))
1242
1243#define sk_X509_NAME_new(st) SKM_sk_new(X509_NAME, (st))
1244#define sk_X509_NAME_new_null() SKM_sk_new_null(X509_NAME)
1245#define sk_X509_NAME_free(st) SKM_sk_free(X509_NAME, (st))
1246#define sk_X509_NAME_num(st) SKM_sk_num(X509_NAME, (st))
1247#define sk_X509_NAME_value(st, i) SKM_sk_value(X509_NAME, (st), (i))
1248#define sk_X509_NAME_set(st, i, val) SKM_sk_set(X509_NAME, (st), (i), (val))
1249#define sk_X509_NAME_zero(st) SKM_sk_zero(X509_NAME, (st))
1250#define sk_X509_NAME_push(st, val) SKM_sk_push(X509_NAME, (st), (val))
1251#define sk_X509_NAME_unshift(st, val) SKM_sk_unshift(X509_NAME, (st), (val))
1252#define sk_X509_NAME_find(st, val) SKM_sk_find(X509_NAME, (st), (val))
1253#define sk_X509_NAME_delete(st, i) SKM_sk_delete(X509_NAME, (st), (i))
1254#define sk_X509_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME, (st), (ptr))
1255#define sk_X509_NAME_insert(st, val, i) SKM_sk_insert(X509_NAME, (st), (val), (i))
1256#define sk_X509_NAME_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_NAME, (st), (cmp))
1257#define sk_X509_NAME_dup(st) SKM_sk_dup(X509_NAME, st)
1258#define sk_X509_NAME_pop_free(st, free_func) SKM_sk_pop_free(X509_NAME, (st), (free_func))
1259#define sk_X509_NAME_shift(st) SKM_sk_shift(X509_NAME, (st))
1260#define sk_X509_NAME_pop(st) SKM_sk_pop(X509_NAME, (st))
1261#define sk_X509_NAME_sort(st) SKM_sk_sort(X509_NAME, (st))
1262#define sk_X509_NAME_is_sorted(st) SKM_sk_is_sorted(X509_NAME, (st))
1263
1264#define sk_X509_NAME_ENTRY_new(st) SKM_sk_new(X509_NAME_ENTRY, (st))
1265#define sk_X509_NAME_ENTRY_new_null() SKM_sk_new_null(X509_NAME_ENTRY)
1266#define sk_X509_NAME_ENTRY_free(st) SKM_sk_free(X509_NAME_ENTRY, (st))
1267#define sk_X509_NAME_ENTRY_num(st) SKM_sk_num(X509_NAME_ENTRY, (st))
1268#define sk_X509_NAME_ENTRY_value(st, i) SKM_sk_value(X509_NAME_ENTRY, (st), (i))
1269#define sk_X509_NAME_ENTRY_set(st, i, val) SKM_sk_set(X509_NAME_ENTRY, (st), (i), (val))
1270#define sk_X509_NAME_ENTRY_zero(st) SKM_sk_zero(X509_NAME_ENTRY, (st))
1271#define sk_X509_NAME_ENTRY_push(st, val) SKM_sk_push(X509_NAME_ENTRY, (st), (val))
1272#define sk_X509_NAME_ENTRY_unshift(st, val) SKM_sk_unshift(X509_NAME_ENTRY, (st), (val))
1273#define sk_X509_NAME_ENTRY_find(st, val) SKM_sk_find(X509_NAME_ENTRY, (st), (val))
1274#define sk_X509_NAME_ENTRY_delete(st, i) SKM_sk_delete(X509_NAME_ENTRY, (st), (i))
1275#define sk_X509_NAME_ENTRY_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME_ENTRY, (st), (ptr))
1276#define sk_X509_NAME_ENTRY_insert(st, val, i) SKM_sk_insert(X509_NAME_ENTRY, (st), (val), (i))
1277#define sk_X509_NAME_ENTRY_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_NAME_ENTRY, (st), (cmp))
1278#define sk_X509_NAME_ENTRY_dup(st) SKM_sk_dup(X509_NAME_ENTRY, st)
1279#define sk_X509_NAME_ENTRY_pop_free(st, free_func) SKM_sk_pop_free(X509_NAME_ENTRY, (st), (free_func))
1280#define sk_X509_NAME_ENTRY_shift(st) SKM_sk_shift(X509_NAME_ENTRY, (st))
1281#define sk_X509_NAME_ENTRY_pop(st) SKM_sk_pop(X509_NAME_ENTRY, (st))
1282#define sk_X509_NAME_ENTRY_sort(st) SKM_sk_sort(X509_NAME_ENTRY, (st))
1283#define sk_X509_NAME_ENTRY_is_sorted(st) SKM_sk_is_sorted(X509_NAME_ENTRY, (st))
1284
1285#define sk_X509_OBJECT_new(st) SKM_sk_new(X509_OBJECT, (st))
1286#define sk_X509_OBJECT_new_null() SKM_sk_new_null(X509_OBJECT)
1287#define sk_X509_OBJECT_free(st) SKM_sk_free(X509_OBJECT, (st))
1288#define sk_X509_OBJECT_num(st) SKM_sk_num(X509_OBJECT, (st))
1289#define sk_X509_OBJECT_value(st, i) SKM_sk_value(X509_OBJECT, (st), (i))
1290#define sk_X509_OBJECT_set(st, i, val) SKM_sk_set(X509_OBJECT, (st), (i), (val))
1291#define sk_X509_OBJECT_zero(st) SKM_sk_zero(X509_OBJECT, (st))
1292#define sk_X509_OBJECT_push(st, val) SKM_sk_push(X509_OBJECT, (st), (val))
1293#define sk_X509_OBJECT_unshift(st, val) SKM_sk_unshift(X509_OBJECT, (st), (val))
1294#define sk_X509_OBJECT_find(st, val) SKM_sk_find(X509_OBJECT, (st), (val))
1295#define sk_X509_OBJECT_delete(st, i) SKM_sk_delete(X509_OBJECT, (st), (i))
1296#define sk_X509_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_OBJECT, (st), (ptr))
1297#define sk_X509_OBJECT_insert(st, val, i) SKM_sk_insert(X509_OBJECT, (st), (val), (i))
1298#define sk_X509_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_OBJECT, (st), (cmp))
1299#define sk_X509_OBJECT_dup(st) SKM_sk_dup(X509_OBJECT, st)
1300#define sk_X509_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(X509_OBJECT, (st), (free_func))
1301#define sk_X509_OBJECT_shift(st) SKM_sk_shift(X509_OBJECT, (st))
1302#define sk_X509_OBJECT_pop(st) SKM_sk_pop(X509_OBJECT, (st))
1303#define sk_X509_OBJECT_sort(st) SKM_sk_sort(X509_OBJECT, (st))
1304#define sk_X509_OBJECT_is_sorted(st) SKM_sk_is_sorted(X509_OBJECT, (st))
1305
1306#define sk_X509_PURPOSE_new(st) SKM_sk_new(X509_PURPOSE, (st))
1307#define sk_X509_PURPOSE_new_null() SKM_sk_new_null(X509_PURPOSE)
1308#define sk_X509_PURPOSE_free(st) SKM_sk_free(X509_PURPOSE, (st))
1309#define sk_X509_PURPOSE_num(st) SKM_sk_num(X509_PURPOSE, (st))
1310#define sk_X509_PURPOSE_value(st, i) SKM_sk_value(X509_PURPOSE, (st), (i))
1311#define sk_X509_PURPOSE_set(st, i, val) SKM_sk_set(X509_PURPOSE, (st), (i), (val))
1312#define sk_X509_PURPOSE_zero(st) SKM_sk_zero(X509_PURPOSE, (st))
1313#define sk_X509_PURPOSE_push(st, val) SKM_sk_push(X509_PURPOSE, (st), (val))
1314#define sk_X509_PURPOSE_unshift(st, val) SKM_sk_unshift(X509_PURPOSE, (st), (val))
1315#define sk_X509_PURPOSE_find(st, val) SKM_sk_find(X509_PURPOSE, (st), (val))
1316#define sk_X509_PURPOSE_delete(st, i) SKM_sk_delete(X509_PURPOSE, (st), (i))
1317#define sk_X509_PURPOSE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_PURPOSE, (st), (ptr))
1318#define sk_X509_PURPOSE_insert(st, val, i) SKM_sk_insert(X509_PURPOSE, (st), (val), (i))
1319#define sk_X509_PURPOSE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_PURPOSE, (st), (cmp))
1320#define sk_X509_PURPOSE_dup(st) SKM_sk_dup(X509_PURPOSE, st)
1321#define sk_X509_PURPOSE_pop_free(st, free_func) SKM_sk_pop_free(X509_PURPOSE, (st), (free_func))
1322#define sk_X509_PURPOSE_shift(st) SKM_sk_shift(X509_PURPOSE, (st))
1323#define sk_X509_PURPOSE_pop(st) SKM_sk_pop(X509_PURPOSE, (st))
1324#define sk_X509_PURPOSE_sort(st) SKM_sk_sort(X509_PURPOSE, (st))
1325#define sk_X509_PURPOSE_is_sorted(st) SKM_sk_is_sorted(X509_PURPOSE, (st))
1326
1327#define sk_X509_REVOKED_new(st) SKM_sk_new(X509_REVOKED, (st))
1328#define sk_X509_REVOKED_new_null() SKM_sk_new_null(X509_REVOKED)
1329#define sk_X509_REVOKED_free(st) SKM_sk_free(X509_REVOKED, (st))
1330#define sk_X509_REVOKED_num(st) SKM_sk_num(X509_REVOKED, (st))
1331#define sk_X509_REVOKED_value(st, i) SKM_sk_value(X509_REVOKED, (st), (i))
1332#define sk_X509_REVOKED_set(st, i, val) SKM_sk_set(X509_REVOKED, (st), (i), (val))
1333#define sk_X509_REVOKED_zero(st) SKM_sk_zero(X509_REVOKED, (st))
1334#define sk_X509_REVOKED_push(st, val) SKM_sk_push(X509_REVOKED, (st), (val))
1335#define sk_X509_REVOKED_unshift(st, val) SKM_sk_unshift(X509_REVOKED, (st), (val))
1336#define sk_X509_REVOKED_find(st, val) SKM_sk_find(X509_REVOKED, (st), (val))
1337#define sk_X509_REVOKED_delete(st, i) SKM_sk_delete(X509_REVOKED, (st), (i))
1338#define sk_X509_REVOKED_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_REVOKED, (st), (ptr))
1339#define sk_X509_REVOKED_insert(st, val, i) SKM_sk_insert(X509_REVOKED, (st), (val), (i))
1340#define sk_X509_REVOKED_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_REVOKED, (st), (cmp))
1341#define sk_X509_REVOKED_dup(st) SKM_sk_dup(X509_REVOKED, st)
1342#define sk_X509_REVOKED_pop_free(st, free_func) SKM_sk_pop_free(X509_REVOKED, (st), (free_func))
1343#define sk_X509_REVOKED_shift(st) SKM_sk_shift(X509_REVOKED, (st))
1344#define sk_X509_REVOKED_pop(st) SKM_sk_pop(X509_REVOKED, (st))
1345#define sk_X509_REVOKED_sort(st) SKM_sk_sort(X509_REVOKED, (st))
1346#define sk_X509_REVOKED_is_sorted(st) SKM_sk_is_sorted(X509_REVOKED, (st))
1347
1348#define sk_X509_TRUST_new(st) SKM_sk_new(X509_TRUST, (st))
1349#define sk_X509_TRUST_new_null() SKM_sk_new_null(X509_TRUST)
1350#define sk_X509_TRUST_free(st) SKM_sk_free(X509_TRUST, (st))
1351#define sk_X509_TRUST_num(st) SKM_sk_num(X509_TRUST, (st))
1352#define sk_X509_TRUST_value(st, i) SKM_sk_value(X509_TRUST, (st), (i))
1353#define sk_X509_TRUST_set(st, i, val) SKM_sk_set(X509_TRUST, (st), (i), (val))
1354#define sk_X509_TRUST_zero(st) SKM_sk_zero(X509_TRUST, (st))
1355#define sk_X509_TRUST_push(st, val) SKM_sk_push(X509_TRUST, (st), (val))
1356#define sk_X509_TRUST_unshift(st, val) SKM_sk_unshift(X509_TRUST, (st), (val))
1357#define sk_X509_TRUST_find(st, val) SKM_sk_find(X509_TRUST, (st), (val))
1358#define sk_X509_TRUST_delete(st, i) SKM_sk_delete(X509_TRUST, (st), (i))
1359#define sk_X509_TRUST_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_TRUST, (st), (ptr))
1360#define sk_X509_TRUST_insert(st, val, i) SKM_sk_insert(X509_TRUST, (st), (val), (i))
1361#define sk_X509_TRUST_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_TRUST, (st), (cmp))
1362#define sk_X509_TRUST_dup(st) SKM_sk_dup(X509_TRUST, st)
1363#define sk_X509_TRUST_pop_free(st, free_func) SKM_sk_pop_free(X509_TRUST, (st), (free_func))
1364#define sk_X509_TRUST_shift(st) SKM_sk_shift(X509_TRUST, (st))
1365#define sk_X509_TRUST_pop(st) SKM_sk_pop(X509_TRUST, (st))
1366#define sk_X509_TRUST_sort(st) SKM_sk_sort(X509_TRUST, (st))
1367#define sk_X509_TRUST_is_sorted(st) SKM_sk_is_sorted(X509_TRUST, (st))
1368
1369#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1370 SKM_ASN1_SET_OF_d2i(ACCESS_DESCRIPTION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1371#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1372 SKM_ASN1_SET_OF_i2d(ACCESS_DESCRIPTION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1373#define ASN1_seq_pack_ACCESS_DESCRIPTION(st, i2d_func, buf, len) \
1374 SKM_ASN1_seq_pack(ACCESS_DESCRIPTION, (st), (i2d_func), (buf), (len))
1375#define ASN1_seq_unpack_ACCESS_DESCRIPTION(buf, len, d2i_func, free_func) \
1376 SKM_ASN1_seq_unpack(ACCESS_DESCRIPTION, (buf), (len), (d2i_func), (free_func))
1377
1378#define d2i_ASN1_SET_OF_ASN1_INTEGER(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1379 SKM_ASN1_SET_OF_d2i(ASN1_INTEGER, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1380#define i2d_ASN1_SET_OF_ASN1_INTEGER(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1381 SKM_ASN1_SET_OF_i2d(ASN1_INTEGER, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1382#define ASN1_seq_pack_ASN1_INTEGER(st, i2d_func, buf, len) \
1383 SKM_ASN1_seq_pack(ASN1_INTEGER, (st), (i2d_func), (buf), (len))
1384#define ASN1_seq_unpack_ASN1_INTEGER(buf, len, d2i_func, free_func) \
1385 SKM_ASN1_seq_unpack(ASN1_INTEGER, (buf), (len), (d2i_func), (free_func))
1386
1387#define d2i_ASN1_SET_OF_ASN1_OBJECT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1388 SKM_ASN1_SET_OF_d2i(ASN1_OBJECT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1389#define i2d_ASN1_SET_OF_ASN1_OBJECT(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1390 SKM_ASN1_SET_OF_i2d(ASN1_OBJECT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1391#define ASN1_seq_pack_ASN1_OBJECT(st, i2d_func, buf, len) \
1392 SKM_ASN1_seq_pack(ASN1_OBJECT, (st), (i2d_func), (buf), (len))
1393#define ASN1_seq_unpack_ASN1_OBJECT(buf, len, d2i_func, free_func) \
1394 SKM_ASN1_seq_unpack(ASN1_OBJECT, (buf), (len), (d2i_func), (free_func))
1395
1396#define d2i_ASN1_SET_OF_ASN1_TYPE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1397 SKM_ASN1_SET_OF_d2i(ASN1_TYPE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1398#define i2d_ASN1_SET_OF_ASN1_TYPE(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1399 SKM_ASN1_SET_OF_i2d(ASN1_TYPE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1400#define ASN1_seq_pack_ASN1_TYPE(st, i2d_func, buf, len) \
1401 SKM_ASN1_seq_pack(ASN1_TYPE, (st), (i2d_func), (buf), (len))
1402#define ASN1_seq_unpack_ASN1_TYPE(buf, len, d2i_func, free_func) \
1403 SKM_ASN1_seq_unpack(ASN1_TYPE, (buf), (len), (d2i_func), (free_func))
1404
1405#define d2i_ASN1_SET_OF_DIST_POINT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1406 SKM_ASN1_SET_OF_d2i(DIST_POINT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1407#define i2d_ASN1_SET_OF_DIST_POINT(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1408 SKM_ASN1_SET_OF_i2d(DIST_POINT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1409#define ASN1_seq_pack_DIST_POINT(st, i2d_func, buf, len) \
1410 SKM_ASN1_seq_pack(DIST_POINT, (st), (i2d_func), (buf), (len))
1411#define ASN1_seq_unpack_DIST_POINT(buf, len, d2i_func, free_func) \
1412 SKM_ASN1_seq_unpack(DIST_POINT, (buf), (len), (d2i_func), (free_func))
1413
1414#define d2i_ASN1_SET_OF_GENERAL_NAME(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1415 SKM_ASN1_SET_OF_d2i(GENERAL_NAME, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1416#define i2d_ASN1_SET_OF_GENERAL_NAME(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1417 SKM_ASN1_SET_OF_i2d(GENERAL_NAME, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1418#define ASN1_seq_pack_GENERAL_NAME(st, i2d_func, buf, len) \
1419 SKM_ASN1_seq_pack(GENERAL_NAME, (st), (i2d_func), (buf), (len))
1420#define ASN1_seq_unpack_GENERAL_NAME(buf, len, d2i_func, free_func) \
1421 SKM_ASN1_seq_unpack(GENERAL_NAME, (buf), (len), (d2i_func), (free_func))
1422
1423#define d2i_ASN1_SET_OF_OCSP_ONEREQ(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1424 SKM_ASN1_SET_OF_d2i(OCSP_ONEREQ, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1425#define i2d_ASN1_SET_OF_OCSP_ONEREQ(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1426 SKM_ASN1_SET_OF_i2d(OCSP_ONEREQ, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1427#define ASN1_seq_pack_OCSP_ONEREQ(st, i2d_func, buf, len) \
1428 SKM_ASN1_seq_pack(OCSP_ONEREQ, (st), (i2d_func), (buf), (len))
1429#define ASN1_seq_unpack_OCSP_ONEREQ(buf, len, d2i_func, free_func) \
1430 SKM_ASN1_seq_unpack(OCSP_ONEREQ, (buf), (len), (d2i_func), (free_func))
1431
1432#define d2i_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1433 SKM_ASN1_SET_OF_d2i(OCSP_SINGLERESP, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1434#define i2d_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1435 SKM_ASN1_SET_OF_i2d(OCSP_SINGLERESP, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1436#define ASN1_seq_pack_OCSP_SINGLERESP(st, i2d_func, buf, len) \
1437 SKM_ASN1_seq_pack(OCSP_SINGLERESP, (st), (i2d_func), (buf), (len))
1438#define ASN1_seq_unpack_OCSP_SINGLERESP(buf, len, d2i_func, free_func) \
1439 SKM_ASN1_seq_unpack(OCSP_SINGLERESP, (buf), (len), (d2i_func), (free_func))
1440
1441#define d2i_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1442 SKM_ASN1_SET_OF_d2i(PKCS12_SAFEBAG, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1443#define i2d_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1444 SKM_ASN1_SET_OF_i2d(PKCS12_SAFEBAG, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1445#define ASN1_seq_pack_PKCS12_SAFEBAG(st, i2d_func, buf, len) \
1446 SKM_ASN1_seq_pack(PKCS12_SAFEBAG, (st), (i2d_func), (buf), (len))
1447#define ASN1_seq_unpack_PKCS12_SAFEBAG(buf, len, d2i_func, free_func) \
1448 SKM_ASN1_seq_unpack(PKCS12_SAFEBAG, (buf), (len), (d2i_func), (free_func))
1449
1450#define d2i_ASN1_SET_OF_PKCS7(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1451 SKM_ASN1_SET_OF_d2i(PKCS7, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1452#define i2d_ASN1_SET_OF_PKCS7(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1453 SKM_ASN1_SET_OF_i2d(PKCS7, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1454#define ASN1_seq_pack_PKCS7(st, i2d_func, buf, len) \
1455 SKM_ASN1_seq_pack(PKCS7, (st), (i2d_func), (buf), (len))
1456#define ASN1_seq_unpack_PKCS7(buf, len, d2i_func, free_func) \
1457 SKM_ASN1_seq_unpack(PKCS7, (buf), (len), (d2i_func), (free_func))
1458
1459#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1460 SKM_ASN1_SET_OF_d2i(PKCS7_RECIP_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1461#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1462 SKM_ASN1_SET_OF_i2d(PKCS7_RECIP_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1463#define ASN1_seq_pack_PKCS7_RECIP_INFO(st, i2d_func, buf, len) \
1464 SKM_ASN1_seq_pack(PKCS7_RECIP_INFO, (st), (i2d_func), (buf), (len))
1465#define ASN1_seq_unpack_PKCS7_RECIP_INFO(buf, len, d2i_func, free_func) \
1466 SKM_ASN1_seq_unpack(PKCS7_RECIP_INFO, (buf), (len), (d2i_func), (free_func))
1467
1468#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1469 SKM_ASN1_SET_OF_d2i(PKCS7_SIGNER_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1470#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1471 SKM_ASN1_SET_OF_i2d(PKCS7_SIGNER_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1472#define ASN1_seq_pack_PKCS7_SIGNER_INFO(st, i2d_func, buf, len) \
1473 SKM_ASN1_seq_pack(PKCS7_SIGNER_INFO, (st), (i2d_func), (buf), (len))
1474#define ASN1_seq_unpack_PKCS7_SIGNER_INFO(buf, len, d2i_func, free_func) \
1475 SKM_ASN1_seq_unpack(PKCS7_SIGNER_INFO, (buf), (len), (d2i_func), (free_func))
1476
1477#define d2i_ASN1_SET_OF_POLICYINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1478 SKM_ASN1_SET_OF_d2i(POLICYINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1479#define i2d_ASN1_SET_OF_POLICYINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1480 SKM_ASN1_SET_OF_i2d(POLICYINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1481#define ASN1_seq_pack_POLICYINFO(st, i2d_func, buf, len) \
1482 SKM_ASN1_seq_pack(POLICYINFO, (st), (i2d_func), (buf), (len))
1483#define ASN1_seq_unpack_POLICYINFO(buf, len, d2i_func, free_func) \
1484 SKM_ASN1_seq_unpack(POLICYINFO, (buf), (len), (d2i_func), (free_func))
1485
1486#define d2i_ASN1_SET_OF_POLICYQUALINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1487 SKM_ASN1_SET_OF_d2i(POLICYQUALINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1488#define i2d_ASN1_SET_OF_POLICYQUALINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1489 SKM_ASN1_SET_OF_i2d(POLICYQUALINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1490#define ASN1_seq_pack_POLICYQUALINFO(st, i2d_func, buf, len) \
1491 SKM_ASN1_seq_pack(POLICYQUALINFO, (st), (i2d_func), (buf), (len))
1492#define ASN1_seq_unpack_POLICYQUALINFO(buf, len, d2i_func, free_func) \
1493 SKM_ASN1_seq_unpack(POLICYQUALINFO, (buf), (len), (d2i_func), (free_func))
1494
1495#define d2i_ASN1_SET_OF_SXNETID(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1496 SKM_ASN1_SET_OF_d2i(SXNETID, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1497#define i2d_ASN1_SET_OF_SXNETID(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1498 SKM_ASN1_SET_OF_i2d(SXNETID, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1499#define ASN1_seq_pack_SXNETID(st, i2d_func, buf, len) \
1500 SKM_ASN1_seq_pack(SXNETID, (st), (i2d_func), (buf), (len))
1501#define ASN1_seq_unpack_SXNETID(buf, len, d2i_func, free_func) \
1502 SKM_ASN1_seq_unpack(SXNETID, (buf), (len), (d2i_func), (free_func))
1503
1504#define d2i_ASN1_SET_OF_X509(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1505 SKM_ASN1_SET_OF_d2i(X509, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1506#define i2d_ASN1_SET_OF_X509(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1507 SKM_ASN1_SET_OF_i2d(X509, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1508#define ASN1_seq_pack_X509(st, i2d_func, buf, len) \
1509 SKM_ASN1_seq_pack(X509, (st), (i2d_func), (buf), (len))
1510#define ASN1_seq_unpack_X509(buf, len, d2i_func, free_func) \
1511 SKM_ASN1_seq_unpack(X509, (buf), (len), (d2i_func), (free_func))
1512
1513#define d2i_ASN1_SET_OF_X509_ALGOR(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1514 SKM_ASN1_SET_OF_d2i(X509_ALGOR, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1515#define i2d_ASN1_SET_OF_X509_ALGOR(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1516 SKM_ASN1_SET_OF_i2d(X509_ALGOR, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1517#define ASN1_seq_pack_X509_ALGOR(st, i2d_func, buf, len) \
1518 SKM_ASN1_seq_pack(X509_ALGOR, (st), (i2d_func), (buf), (len))
1519#define ASN1_seq_unpack_X509_ALGOR(buf, len, d2i_func, free_func) \
1520 SKM_ASN1_seq_unpack(X509_ALGOR, (buf), (len), (d2i_func), (free_func))
1521
1522#define d2i_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1523 SKM_ASN1_SET_OF_d2i(X509_ATTRIBUTE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1524#define i2d_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1525 SKM_ASN1_SET_OF_i2d(X509_ATTRIBUTE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1526#define ASN1_seq_pack_X509_ATTRIBUTE(st, i2d_func, buf, len) \
1527 SKM_ASN1_seq_pack(X509_ATTRIBUTE, (st), (i2d_func), (buf), (len))
1528#define ASN1_seq_unpack_X509_ATTRIBUTE(buf, len, d2i_func, free_func) \
1529 SKM_ASN1_seq_unpack(X509_ATTRIBUTE, (buf), (len), (d2i_func), (free_func))
1530
1531#define d2i_ASN1_SET_OF_X509_CRL(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1532 SKM_ASN1_SET_OF_d2i(X509_CRL, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1533#define i2d_ASN1_SET_OF_X509_CRL(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1534 SKM_ASN1_SET_OF_i2d(X509_CRL, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1535#define ASN1_seq_pack_X509_CRL(st, i2d_func, buf, len) \
1536 SKM_ASN1_seq_pack(X509_CRL, (st), (i2d_func), (buf), (len))
1537#define ASN1_seq_unpack_X509_CRL(buf, len, d2i_func, free_func) \
1538 SKM_ASN1_seq_unpack(X509_CRL, (buf), (len), (d2i_func), (free_func))
1539
1540#define d2i_ASN1_SET_OF_X509_EXTENSION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1541 SKM_ASN1_SET_OF_d2i(X509_EXTENSION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1542#define i2d_ASN1_SET_OF_X509_EXTENSION(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1543 SKM_ASN1_SET_OF_i2d(X509_EXTENSION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1544#define ASN1_seq_pack_X509_EXTENSION(st, i2d_func, buf, len) \
1545 SKM_ASN1_seq_pack(X509_EXTENSION, (st), (i2d_func), (buf), (len))
1546#define ASN1_seq_unpack_X509_EXTENSION(buf, len, d2i_func, free_func) \
1547 SKM_ASN1_seq_unpack(X509_EXTENSION, (buf), (len), (d2i_func), (free_func))
1548
1549#define d2i_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1550 SKM_ASN1_SET_OF_d2i(X509_NAME_ENTRY, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1551#define i2d_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1552 SKM_ASN1_SET_OF_i2d(X509_NAME_ENTRY, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1553#define ASN1_seq_pack_X509_NAME_ENTRY(st, i2d_func, buf, len) \
1554 SKM_ASN1_seq_pack(X509_NAME_ENTRY, (st), (i2d_func), (buf), (len))
1555#define ASN1_seq_unpack_X509_NAME_ENTRY(buf, len, d2i_func, free_func) \
1556 SKM_ASN1_seq_unpack(X509_NAME_ENTRY, (buf), (len), (d2i_func), (free_func))
1557
1558#define d2i_ASN1_SET_OF_X509_REVOKED(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1559 SKM_ASN1_SET_OF_d2i(X509_REVOKED, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1560#define i2d_ASN1_SET_OF_X509_REVOKED(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1561 SKM_ASN1_SET_OF_i2d(X509_REVOKED, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1562#define ASN1_seq_pack_X509_REVOKED(st, i2d_func, buf, len) \
1563 SKM_ASN1_seq_pack(X509_REVOKED, (st), (i2d_func), (buf), (len))
1564#define ASN1_seq_unpack_X509_REVOKED(buf, len, d2i_func, free_func) \
1565 SKM_ASN1_seq_unpack(X509_REVOKED, (buf), (len), (d2i_func), (free_func))
1566
1567#define PKCS12_decrypt_d2i_PKCS12_SAFEBAG(algor, d2i_func, free_func, pass, passlen, oct, seq) \
1568 SKM_PKCS12_decrypt_d2i(PKCS12_SAFEBAG, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
1569
1570#define PKCS12_decrypt_d2i_PKCS7(algor, d2i_func, free_func, pass, passlen, oct, seq) \
1571 SKM_PKCS12_decrypt_d2i(PKCS7, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
1572/* End of util/mkstack.pl block, you may now edit :-) */
1573
1574#endif /* !defined HEADER_SAFESTACK_H */
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c
deleted file mode 100644
index c7173eb6ab..0000000000
--- a/src/lib/libcrypto/stack/stack.c
+++ /dev/null
@@ -1,340 +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#include <errno.h>
78
79int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,const char * const *)))
80 (const char * const *, const char * const *)
81 {
82 int (*old)(const char * const *,const char * const *)=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 **)OPENSSL_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 if(ret)
110 sk_free(ret);
111 return(NULL);
112 }
113
114STACK *sk_new_null(void)
115 {
116 return sk_new((int (*)(const char * const *, const char * const *))0);
117 }
118
119STACK *sk_new(int (*c)(const char * const *, const char * const *))
120 {
121 STACK *ret;
122 int i;
123
124 if ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL)
125 goto err;
126 if ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)
127 goto err;
128 for (i=0; i<MIN_NODES; i++)
129 ret->data[i]=NULL;
130 ret->comp=c;
131 ret->num_alloc=MIN_NODES;
132 ret->num=0;
133 ret->sorted=0;
134 return(ret);
135err:
136 if(ret)
137 OPENSSL_free(ret);
138 return(NULL);
139 }
140
141int sk_insert(STACK *st, char *data, int loc)
142 {
143 char **s;
144
145 if(st == NULL) return 0;
146 if (st->num_alloc <= st->num+1)
147 {
148 s=(char **)OPENSSL_realloc((char *)st->data,
149 (unsigned int)sizeof(char *)*st->num_alloc*2);
150 if (s == NULL)
151 return(0);
152 st->data=s;
153 st->num_alloc*=2;
154 }
155 if ((loc >= (int)st->num) || (loc < 0))
156 st->data[st->num]=data;
157 else
158 {
159 int i;
160 char **f,**t;
161
162 f=(char **)st->data;
163 t=(char **)&(st->data[1]);
164 for (i=st->num; i>=loc; i--)
165 t[i]=f[i];
166
167#ifdef undef /* no memmove on sunos :-( */
168 memmove( (char *)&(st->data[loc+1]),
169 (char *)&(st->data[loc]),
170 sizeof(char *)*(st->num-loc));
171#endif
172 st->data[loc]=data;
173 }
174 st->num++;
175 st->sorted=0;
176 return(st->num);
177 }
178
179char *sk_delete_ptr(STACK *st, char *p)
180 {
181 int i;
182
183 for (i=0; i<st->num; i++)
184 if (st->data[i] == p)
185 return(sk_delete(st,i));
186 return(NULL);
187 }
188
189char *sk_delete(STACK *st, int loc)
190 {
191 char *ret;
192 int i,j;
193
194 if(!st || (loc < 0) || (loc >= st->num)) return NULL;
195
196 ret=st->data[loc];
197 if (loc != st->num-1)
198 {
199 j=st->num-1;
200 for (i=loc; i<j; i++)
201 st->data[i]=st->data[i+1];
202 /* In theory memcpy is not safe for this
203 * memcpy( &(st->data[loc]),
204 * &(st->data[loc+1]),
205 * sizeof(char *)*(st->num-loc-1));
206 */
207 }
208 st->num--;
209 return(ret);
210 }
211
212int sk_find(STACK *st, char *data)
213 {
214 char **r;
215 int i;
216 int (*comp_func)(const void *,const void *);
217 if(st == NULL) return -1;
218
219 if (st->comp == NULL)
220 {
221 for (i=0; i<st->num; i++)
222 if (st->data[i] == data)
223 return(i);
224 return(-1);
225 }
226 sk_sort(st);
227 if (data == NULL) return(-1);
228 /* This (and the "qsort" below) are the two places in OpenSSL
229 * where we need to convert from our standard (type **,type **)
230 * compare callback type to the (void *,void *) type required by
231 * bsearch. However, the "data" it is being called(back) with are
232 * not (type *) pointers, but the *pointers* to (type *) pointers,
233 * so we get our extra level of pointer dereferencing that way. */
234 comp_func=(int (*)(const void *,const void *))(st->comp);
235 r=(char **)bsearch(&data,(char *)st->data,
236 st->num,sizeof(char *), comp_func);
237 if (r == NULL) return(-1);
238 i=(int)(r-st->data);
239 for ( ; i>0; i--)
240 /* This needs a cast because the type being pointed to from
241 * the "&" expressions are (char *) rather than (const char *).
242 * For an explanation, read:
243 * http://www.eskimo.com/~scs/C-faq/q11.10.html :-) */
244 if ((*st->comp)((const char * const *)&(st->data[i-1]),
245 (const char * const *)&data) < 0)
246 break;
247 return(i);
248 }
249
250int sk_push(STACK *st, char *data)
251 {
252 return(sk_insert(st,data,st->num));
253 }
254
255int sk_unshift(STACK *st, char *data)
256 {
257 return(sk_insert(st,data,0));
258 }
259
260char *sk_shift(STACK *st)
261 {
262 if (st == NULL) return(NULL);
263 if (st->num <= 0) return(NULL);
264 return(sk_delete(st,0));
265 }
266
267char *sk_pop(STACK *st)
268 {
269 if (st == NULL) return(NULL);
270 if (st->num <= 0) return(NULL);
271 return(sk_delete(st,st->num-1));
272 }
273
274void sk_zero(STACK *st)
275 {
276 if (st == NULL) return;
277 if (st->num <= 0) return;
278 memset((char *)st->data,0,sizeof(st->data)*st->num);
279 st->num=0;
280 }
281
282void sk_pop_free(STACK *st, void (*func)(void *))
283 {
284 int i;
285
286 if (st == NULL) return;
287 for (i=0; i<st->num; i++)
288 if (st->data[i] != NULL)
289 func(st->data[i]);
290 sk_free(st);
291 }
292
293void sk_free(STACK *st)
294 {
295 if (st == NULL) return;
296 if (st->data != NULL) OPENSSL_free(st->data);
297 OPENSSL_free(st);
298 }
299
300int sk_num(const STACK *st)
301{
302 if(st == NULL) return -1;
303 return st->num;
304}
305
306char *sk_value(const STACK *st, int i)
307{
308 if(!st || (i < 0) || (i >= st->num)) return NULL;
309 return st->data[i];
310}
311
312char *sk_set(STACK *st, int i, char *value)
313{
314 if(!st || (i < 0) || (i >= st->num)) return NULL;
315 return (st->data[i] = value);
316}
317
318void sk_sort(STACK *st)
319 {
320 if (st && !st->sorted)
321 {
322 int (*comp_func)(const void *,const void *);
323
324 /* same comment as in sk_find ... previously st->comp was declared
325 * as a (void*,void*) callback type, but this made the population
326 * of the callback pointer illogical - our callbacks compare
327 * type** with type**, so we leave the casting until absolutely
328 * necessary (ie. "now"). */
329 comp_func=(int (*)(const void *,const void *))(st->comp);
330 qsort(st->data,st->num,sizeof(char *), comp_func);
331 st->sorted=1;
332 }
333 }
334
335int sk_is_sorted(const STACK *st)
336 {
337 if (!st)
338 return 1;
339 return st->sorted;
340 }
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h
deleted file mode 100644
index 7570b85fe8..0000000000
--- a/src/lib/libcrypto/stack/stack.h
+++ /dev/null
@@ -1,108 +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)(const char * const *, const char * const *);
74 } STACK;
75
76#define M_sk_num(sk) ((sk) ? (sk)->num:-1)
77#define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL)
78
79int sk_num(const STACK *);
80char *sk_value(const STACK *, int);
81
82char *sk_set(STACK *, int, char *);
83
84STACK *sk_new(int (*cmp)(const char * const *, const char * const *));
85STACK *sk_new_null(void);
86void sk_free(STACK *);
87void sk_pop_free(STACK *st, void (*func)(void *));
88int sk_insert(STACK *sk,char *data,int where);
89char *sk_delete(STACK *st,int loc);
90char *sk_delete_ptr(STACK *st, char *p);
91int sk_find(STACK *st,char *data);
92int sk_push(STACK *st,char *data);
93int sk_unshift(STACK *st,char *data);
94char *sk_shift(STACK *st);
95char *sk_pop(STACK *st);
96void sk_zero(STACK *st);
97int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,
98 const char * const *)))
99 (const char * const *, const char * const *);
100STACK *sk_dup(STACK *st);
101void sk_sort(STACK *st);
102int sk_is_sorted(const STACK *st);
103
104#ifdef __cplusplus
105}
106#endif
107
108#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 58b300b00b..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 *)OPENSSL_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 **)OPENSSL_malloc(sizeof(LHASH *)*num)) == NULL)
94 goto err;
95 if ((ret->qual=(int (**)())OPENSSL_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_clean(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 if (!(p=(char *)OPENSSL_malloc(add+offset))) goto err;
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(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_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(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_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(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
180 if (er == 1) fprintf(stderr,"OPENSSL_malloc failure\n");
181#endif
182 if (ret->data != NULL) sk_free(ret->data);
183 if (ret->index != NULL) OPENSSL_free(ret->index);
184 if (ret->qual != NULL) OPENSSL_free(ret->qual);
185 if (ret != NULL) OPENSSL_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 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE 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_clean(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 OPENSSL_free(db->index);
353 }
354 if (db->qual != NULL)
355 OPENSSL_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) OPENSSL_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 OPENSSL_free(p[n]);
376 }
377 }
378 OPENSSL_free(sk_value(db->data,i));
379 }
380 sk_free(db->data);
381 }
382 OPENSSL_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 563392aeff..0000000000
--- a/src/lib/libcrypto/txt_db/txt_db.h
+++ /dev/null
@@ -1,108 +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#ifndef OPENSSL_NO_BIO
63#include <openssl/bio.h>
64#endif
65#include <openssl/stack.h>
66#include <openssl/lhash.h>
67
68#define DB_ERROR_OK 0
69#define DB_ERROR_MALLOC 1
70#define DB_ERROR_INDEX_CLASH 2
71#define DB_ERROR_INDEX_OUT_OF_RANGE 3
72#define DB_ERROR_NO_INDEX 4
73#define DB_ERROR_INSERT_INDEX_CLASH 5
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79typedef struct txt_db_st
80 {
81 int num_fields;
82 STACK /* char ** */ *data;
83 LHASH **index;
84 int (**qual)();
85 long error;
86 long arg1;
87 long arg2;
88 char **arg_row;
89 } TXT_DB;
90
91#ifndef OPENSSL_NO_BIO
92TXT_DB *TXT_DB_read(BIO *in, int num);
93long TXT_DB_write(BIO *out, TXT_DB *db);
94#else
95TXT_DB *TXT_DB_read(char *in, int num);
96long TXT_DB_write(char *out, TXT_DB *db);
97#endif
98int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(),
99 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);
100void TXT_DB_free(TXT_DB *db);
101char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value);
102int TXT_DB_insert(TXT_DB *db,char **value);
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif
diff --git a/src/lib/libcrypto/ui/ui.h b/src/lib/libcrypto/ui/ui.h
deleted file mode 100644
index 735a2d988e..0000000000
--- a/src/lib/libcrypto/ui/ui.h
+++ /dev/null
@@ -1,387 +0,0 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_H
60#define HEADER_UI_H
61
62#include <openssl/crypto.h>
63#include <openssl/safestack.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* The UI type is a holder for a specific user interface session. It can
70 contain an illimited number of informational or error strings as well
71 as things to prompt for, both passwords (noecho mode) and others (echo
72 mode), and verification of the same. All of these are called strings,
73 and are further described below. */
74typedef struct ui_st UI;
75
76/* All instances of UI have a reference to a method structure, which is a
77 ordered vector of functions that implement the lower level things to do.
78 There is an instruction on the implementation further down, in the section
79 for method implementors. */
80typedef struct ui_method_st UI_METHOD;
81
82
83/* All the following functions return -1 or NULL on error and in some cases
84 (UI_process()) -2 if interrupted or in some other way cancelled.
85 When everything is fine, they return 0, a positive value or a non-NULL
86 pointer, all depending on their purpose. */
87
88/* Creators and destructor. */
89UI *UI_new(void);
90UI *UI_new_method(const UI_METHOD *method);
91void UI_free(UI *ui);
92
93/* The following functions are used to add strings to be printed and prompt
94 strings to prompt for data. The names are UI_{add,dup}_<function>_string
95 and UI_{add,dup}_input_boolean.
96
97 UI_{add,dup}_<function>_string have the following meanings:
98 add add a text or prompt string. The pointers given to these
99 functions are used verbatim, no copying is done.
100 dup make a copy of the text or prompt string, then add the copy
101 to the collection of strings in the user interface.
102 <function>
103 The function is a name for the functionality that the given
104 string shall be used for. It can be one of:
105 input use the string as data prompt.
106 verify use the string as verification prompt. This
107 is used to verify a previous input.
108 info use the string for informational output.
109 error use the string for error output.
110 Honestly, there's currently no difference between info and error for the
111 moment.
112
113 UI_{add,dup}_input_boolean have the same semantics for "add" and "dup",
114 and are typically used when one wants to prompt for a yes/no response.
115
116
117 All of the functions in this group take a UI and a prompt string.
118 The string input and verify addition functions also take a flag argument,
119 a buffer for the result to end up with, a minimum input size and a maximum
120 input size (the result buffer MUST be large enough to be able to contain
121 the maximum number of characters). Additionally, the verify addition
122 functions takes another buffer to compare the result against.
123 The boolean input functions take an action description string (which should
124 be safe to ignore if the expected user action is obvious, for example with
125 a dialog box with an OK button and a Cancel button), a string of acceptable
126 characters to mean OK and to mean Cancel. The two last strings are checked
127 to make sure they don't have common characters. Additionally, the same
128 flag argument as for the string input is taken, as well as a result buffer.
129 The result buffer is required to be at least one byte long. Depending on
130 the answer, the first character from the OK or the Cancel character strings
131 will be stored in the first byte of the result buffer. No NUL will be
132 added, so the result is *not* a string.
133
134 On success, the all return an index of the added information. That index
135 is usefull when retrieving results with UI_get0_result(). */
136int UI_add_input_string(UI *ui, const char *prompt, int flags,
137 char *result_buf, int minsize, int maxsize);
138int UI_dup_input_string(UI *ui, const char *prompt, int flags,
139 char *result_buf, int minsize, int maxsize);
140int UI_add_verify_string(UI *ui, const char *prompt, int flags,
141 char *result_buf, int minsize, int maxsize, const char *test_buf);
142int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
143 char *result_buf, int minsize, int maxsize, const char *test_buf);
144int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
145 const char *ok_chars, const char *cancel_chars,
146 int flags, char *result_buf);
147int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
148 const char *ok_chars, const char *cancel_chars,
149 int flags, char *result_buf);
150int UI_add_info_string(UI *ui, const char *text);
151int UI_dup_info_string(UI *ui, const char *text);
152int UI_add_error_string(UI *ui, const char *text);
153int UI_dup_error_string(UI *ui, const char *text);
154
155/* These are the possible flags. They can be or'ed together. */
156/* Use to have echoing of input */
157#define UI_INPUT_FLAG_ECHO 0x01
158/* Use a default password. Where that password is found is completely
159 up to the application, it might for example be in the user data set
160 with UI_add_user_data(). It is not recommended to have more than
161 one input in each UI being marked with this flag, or the application
162 might get confused. */
163#define UI_INPUT_FLAG_DEFAULT_PWD 0x02
164
165/* The user of these routines may want to define flags of their own. The core
166 UI won't look at those, but will pass them on to the method routines. They
167 must use higher bits so they don't get confused with the UI bits above.
168 UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good
169 example of use is this:
170
171 #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE)
172
173*/
174#define UI_INPUT_FLAG_USER_BASE 16
175
176
177/* The following function helps construct a prompt. object_desc is a
178 textual short description of the object, for example "pass phrase",
179 and object_name is the name of the object (might be a card name or
180 a file name.
181 The returned string shall always be allocated on the heap with
182 OPENSSL_malloc(), and need to be free'd with OPENSSL_free().
183
184 If the ui_method doesn't contain a pointer to a user-defined prompt
185 constructor, a default string is built, looking like this:
186
187 "Enter {object_desc} for {object_name}:"
188
189 So, if object_desc has the value "pass phrase" and object_name has
190 the value "foo.key", the resulting string is:
191
192 "Enter pass phrase for foo.key:"
193*/
194char *UI_construct_prompt(UI *ui_method,
195 const char *object_desc, const char *object_name);
196
197
198/* The following function is used to store a pointer to user-specific data.
199 Any previous such pointer will be returned and replaced.
200
201 For callback purposes, this function makes a lot more sense than using
202 ex_data, since the latter requires that different parts of OpenSSL or
203 applications share the same ex_data index.
204
205 Note that the UI_OpenSSL() method completely ignores the user data.
206 Other methods may not, however. */
207void *UI_add_user_data(UI *ui, void *user_data);
208/* We need a user data retrieving function as well. */
209void *UI_get0_user_data(UI *ui);
210
211/* Return the result associated with a prompt given with the index i. */
212const char *UI_get0_result(UI *ui, int i);
213
214/* When all strings have been added, process the whole thing. */
215int UI_process(UI *ui);
216
217/* Give a user interface parametrised control commands. This can be used to
218 send down an integer, a data pointer or a function pointer, as well as
219 be used to get information from a UI. */
220int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
221
222/* The commands */
223/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the
224 OpenSSL error stack before printing any info or added error messages and
225 before any prompting. */
226#define UI_CTRL_PRINT_ERRORS 1
227/* Check if a UI_process() is possible to do again with the same instance of
228 a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0
229 if not. */
230#define UI_CTRL_IS_REDOABLE 2
231
232
233/* Some methods may use extra data */
234#define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg)
235#define UI_get_app_data(s) UI_get_ex_data(s,0)
236int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
237 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
238int UI_set_ex_data(UI *r,int idx,void *arg);
239void *UI_get_ex_data(UI *r, int idx);
240
241/* Use specific methods instead of the built-in one */
242void UI_set_default_method(const UI_METHOD *meth);
243const UI_METHOD *UI_get_default_method(void);
244const UI_METHOD *UI_get_method(UI *ui);
245const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
246
247/* The method with all the built-in thingies */
248UI_METHOD *UI_OpenSSL(void);
249
250
251/* ---------- For method writers ---------- */
252/* A method contains a number of functions that implement the low level
253 of the User Interface. The functions are:
254
255 an opener This function starts a session, maybe by opening
256 a channel to a tty, or by opening a window.
257 a writer This function is called to write a given string,
258 maybe to the tty, maybe as a field label in a
259 window.
260 a flusher This function is called to flush everything that
261 has been output so far. It can be used to actually
262 display a dialog box after it has been built.
263 a reader This function is called to read a given prompt,
264 maybe from the tty, maybe from a field in a
265 window. Note that it's called wth all string
266 structures, not only the prompt ones, so it must
267 check such things itself.
268 a closer This function closes the session, maybe by closing
269 the channel to the tty, or closing the window.
270
271 All these functions are expected to return:
272
273 0 on error.
274 1 on success.
275 -1 on out-of-band events, for example if some prompting has
276 been canceled (by pressing Ctrl-C, for example). This is
277 only checked when returned by the flusher or the reader.
278
279 The way this is used, the opener is first called, then the writer for all
280 strings, then the flusher, then the reader for all strings and finally the
281 closer. Note that if you want to prompt from a terminal or other command
282 line interface, the best is to have the reader also write the prompts
283 instead of having the writer do it. If you want to prompt from a dialog
284 box, the writer can be used to build up the contents of the box, and the
285 flusher to actually display the box and run the event loop until all data
286 has been given, after which the reader only grabs the given data and puts
287 them back into the UI strings.
288
289 All method functions take a UI as argument. Additionally, the writer and
290 the reader take a UI_STRING.
291*/
292
293/* The UI_STRING type is the data structure that contains all the needed info
294 about a string or a prompt, including test data for a verification prompt.
295*/
296DECLARE_STACK_OF(UI_STRING)
297typedef struct ui_string_st UI_STRING;
298
299/* The different types of strings that are currently supported.
300 This is only needed by method authors. */
301enum UI_string_types
302 {
303 UIT_NONE=0,
304 UIT_PROMPT, /* Prompt for a string */
305 UIT_VERIFY, /* Prompt for a string and verify */
306 UIT_BOOLEAN, /* Prompt for a yes/no response */
307 UIT_INFO, /* Send info to the user */
308 UIT_ERROR /* Send an error message to the user */
309 };
310
311/* Create and manipulate methods */
312UI_METHOD *UI_create_method(char *name);
313void UI_destroy_method(UI_METHOD *ui_method);
314int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui));
315int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis));
316int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
317int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis));
318int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
319int (*UI_method_get_opener(UI_METHOD *method))(UI*);
320int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*);
321int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
322int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*);
323int (*UI_method_get_closer(UI_METHOD *method))(UI*);
324
325/* The following functions are helpers for method writers to access relevant
326 data from a UI_STRING. */
327
328/* Return type of the UI_STRING */
329enum UI_string_types UI_get_string_type(UI_STRING *uis);
330/* Return input flags of the UI_STRING */
331int UI_get_input_flags(UI_STRING *uis);
332/* Return the actual string to output (the prompt, info or error) */
333const char *UI_get0_output_string(UI_STRING *uis);
334/* Return the optional action string to output (the boolean promtp instruction) */
335const char *UI_get0_action_string(UI_STRING *uis);
336/* Return the result of a prompt */
337const char *UI_get0_result_string(UI_STRING *uis);
338/* Return the string to test the result against. Only useful with verifies. */
339const char *UI_get0_test_string(UI_STRING *uis);
340/* Return the required minimum size of the result */
341int UI_get_result_minsize(UI_STRING *uis);
342/* Return the required maximum size of the result */
343int UI_get_result_maxsize(UI_STRING *uis);
344/* Set the result of a UI_STRING. */
345int UI_set_result(UI *ui, UI_STRING *uis, const char *result);
346
347
348/* A couple of popular utility functions */
349int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify);
350int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
351
352
353/* BEGIN ERROR CODES */
354/* The following lines are auto generated by the script mkerr.pl. Any changes
355 * made after this point may be overwritten when the script is next run.
356 */
357void ERR_load_UI_strings(void);
358
359/* Error codes for the UI functions. */
360
361/* Function codes. */
362#define UI_F_GENERAL_ALLOCATE_BOOLEAN 108
363#define UI_F_GENERAL_ALLOCATE_PROMPT 109
364#define UI_F_GENERAL_ALLOCATE_STRING 100
365#define UI_F_UI_CTRL 111
366#define UI_F_UI_DUP_ERROR_STRING 101
367#define UI_F_UI_DUP_INFO_STRING 102
368#define UI_F_UI_DUP_INPUT_BOOLEAN 110
369#define UI_F_UI_DUP_INPUT_STRING 103
370#define UI_F_UI_DUP_VERIFY_STRING 106
371#define UI_F_UI_GET0_RESULT 107
372#define UI_F_UI_NEW_METHOD 104
373#define UI_F_UI_SET_RESULT 105
374
375/* Reason codes. */
376#define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104
377#define UI_R_INDEX_TOO_LARGE 102
378#define UI_R_INDEX_TOO_SMALL 103
379#define UI_R_NO_RESULT_BUFFER 105
380#define UI_R_RESULT_TOO_LARGE 100
381#define UI_R_RESULT_TOO_SMALL 101
382#define UI_R_UNKNOWN_CONTROL_COMMAND 106
383
384#ifdef __cplusplus
385}
386#endif
387#endif
diff --git a/src/lib/libcrypto/ui/ui_compat.h b/src/lib/libcrypto/ui/ui_compat.h
deleted file mode 100644
index b35c9bb7fd..0000000000
--- a/src/lib/libcrypto/ui/ui_compat.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_COMPAT_H
60#define HEADER_UI_COMPAT_H
61
62#include <openssl/opensslconf.h>
63#include <openssl/ui.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* The following functions were previously part of the DES section,
70 and are provided here for backward compatibility reasons. */
71
72#define des_read_pw_string(b,l,p,v) \
73 _ossl_old_des_read_pw_string((b),(l),(p),(v))
74#define des_read_pw(b,bf,s,p,v) \
75 _ossl_old_des_read_pw((b),(bf),(s),(p),(v))
76
77int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify);
78int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
79
80#ifdef __cplusplus
81}
82#endif
83#endif
diff --git a/src/lib/libcrypto/ui/ui_err.c b/src/lib/libcrypto/ui/ui_err.c
deleted file mode 100644
index d983cdd66f..0000000000
--- a/src/lib/libcrypto/ui/ui_err.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/* crypto/ui/ui_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ui.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_UI,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason)
70
71static ERR_STRING_DATA UI_str_functs[]=
72 {
73{ERR_FUNC(UI_F_GENERAL_ALLOCATE_BOOLEAN), "GENERAL_ALLOCATE_BOOLEAN"},
74{ERR_FUNC(UI_F_GENERAL_ALLOCATE_PROMPT), "GENERAL_ALLOCATE_PROMPT"},
75{ERR_FUNC(UI_F_GENERAL_ALLOCATE_STRING), "GENERAL_ALLOCATE_STRING"},
76{ERR_FUNC(UI_F_UI_CTRL), "UI_ctrl"},
77{ERR_FUNC(UI_F_UI_DUP_ERROR_STRING), "UI_dup_error_string"},
78{ERR_FUNC(UI_F_UI_DUP_INFO_STRING), "UI_dup_info_string"},
79{ERR_FUNC(UI_F_UI_DUP_INPUT_BOOLEAN), "UI_dup_input_boolean"},
80{ERR_FUNC(UI_F_UI_DUP_INPUT_STRING), "UI_dup_input_string"},
81{ERR_FUNC(UI_F_UI_DUP_VERIFY_STRING), "UI_dup_verify_string"},
82{ERR_FUNC(UI_F_UI_GET0_RESULT), "UI_get0_result"},
83{ERR_FUNC(UI_F_UI_NEW_METHOD), "UI_new_method"},
84{ERR_FUNC(UI_F_UI_SET_RESULT), "UI_set_result"},
85{0,NULL}
86 };
87
88static ERR_STRING_DATA UI_str_reasons[]=
89 {
90{ERR_REASON(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS),"common ok and cancel characters"},
91{ERR_REASON(UI_R_INDEX_TOO_LARGE) ,"index too large"},
92{ERR_REASON(UI_R_INDEX_TOO_SMALL) ,"index too small"},
93{ERR_REASON(UI_R_NO_RESULT_BUFFER) ,"no result buffer"},
94{ERR_REASON(UI_R_RESULT_TOO_LARGE) ,"result too large"},
95{ERR_REASON(UI_R_RESULT_TOO_SMALL) ,"result too small"},
96{ERR_REASON(UI_R_UNKNOWN_CONTROL_COMMAND),"unknown control command"},
97{0,NULL}
98 };
99
100#endif
101
102void ERR_load_UI_strings(void)
103 {
104 static int init=1;
105
106 if (init)
107 {
108 init=0;
109#ifndef OPENSSL_NO_ERR
110 ERR_load_strings(0,UI_str_functs);
111 ERR_load_strings(0,UI_str_reasons);
112#endif
113
114 }
115 }
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c
deleted file mode 100644
index dbc9711a2d..0000000000
--- a/src/lib/libcrypto/ui/ui_lib.c
+++ /dev/null
@@ -1,902 +0,0 @@
1/* crypto/ui/ui_lib.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/e_os2.h>
61#include <openssl/buffer.h>
62#include <openssl/ui.h>
63#include <openssl/err.h>
64#include "ui_locl.h"
65#include "cryptlib.h"
66
67IMPLEMENT_STACK_OF(UI_STRING_ST)
68
69static const UI_METHOD *default_UI_meth=NULL;
70
71UI *UI_new(void)
72 {
73 return(UI_new_method(NULL));
74 }
75
76UI *UI_new_method(const UI_METHOD *method)
77 {
78 UI *ret;
79
80 ret=(UI *)OPENSSL_malloc(sizeof(UI));
81 if (ret == NULL)
82 {
83 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE);
84 return NULL;
85 }
86 if (method == NULL)
87 ret->meth=UI_get_default_method();
88 else
89 ret->meth=method;
90
91 ret->strings=NULL;
92 ret->user_data=NULL;
93 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data);
94 return ret;
95 }
96
97static void free_string(UI_STRING *uis)
98 {
99 if (uis->flags & OUT_STRING_FREEABLE)
100 {
101 OPENSSL_free((char *)uis->out_string);
102 switch(uis->type)
103 {
104 case UIT_BOOLEAN:
105 OPENSSL_free((char *)uis->_.boolean_data.action_desc);
106 OPENSSL_free((char *)uis->_.boolean_data.ok_chars);
107 OPENSSL_free((char *)uis->_.boolean_data.cancel_chars);
108 break;
109 default:
110 break;
111 }
112 }
113 OPENSSL_free(uis);
114 }
115
116void UI_free(UI *ui)
117 {
118 if (ui == NULL)
119 return;
120 sk_UI_STRING_pop_free(ui->strings,free_string);
121 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
122 OPENSSL_free(ui);
123 }
124
125static int allocate_string_stack(UI *ui)
126 {
127 if (ui->strings == NULL)
128 {
129 ui->strings=sk_UI_STRING_new_null();
130 if (ui->strings == NULL)
131 {
132 return -1;
133 }
134 }
135 return 0;
136 }
137
138static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt,
139 int prompt_freeable, enum UI_string_types type, int input_flags,
140 char *result_buf)
141 {
142 UI_STRING *ret = NULL;
143
144 if (prompt == NULL)
145 {
146 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER);
147 }
148 else if ((type == UIT_PROMPT || type == UIT_VERIFY
149 || type == UIT_BOOLEAN) && result_buf == NULL)
150 {
151 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER);
152 }
153 else if ((ret = (UI_STRING *)OPENSSL_malloc(sizeof(UI_STRING))))
154 {
155 ret->out_string=prompt;
156 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0;
157 ret->input_flags=input_flags;
158 ret->type=type;
159 ret->result_buf=result_buf;
160 }
161 return ret;
162 }
163
164static int general_allocate_string(UI *ui, const char *prompt,
165 int prompt_freeable, enum UI_string_types type, int input_flags,
166 char *result_buf, int minsize, int maxsize, const char *test_buf)
167 {
168 int ret = -1;
169 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
170 type, input_flags, result_buf);
171
172 if (s)
173 {
174 if (allocate_string_stack(ui) >= 0)
175 {
176 s->_.string_data.result_minsize=minsize;
177 s->_.string_data.result_maxsize=maxsize;
178 s->_.string_data.test_buf=test_buf;
179 ret=sk_UI_STRING_push(ui->strings, s);
180 /* sk_push() returns 0 on error. Let's addapt that */
181 if (ret <= 0) ret--;
182 }
183 else
184 free_string(s);
185 }
186 return ret;
187 }
188
189static int general_allocate_boolean(UI *ui,
190 const char *prompt, const char *action_desc,
191 const char *ok_chars, const char *cancel_chars,
192 int prompt_freeable, enum UI_string_types type, int input_flags,
193 char *result_buf)
194 {
195 int ret = -1;
196 UI_STRING *s;
197 const char *p;
198
199 if (ok_chars == NULL)
200 {
201 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
202 }
203 else if (cancel_chars == NULL)
204 {
205 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
206 }
207 else
208 {
209 for(p = ok_chars; *p; p++)
210 {
211 if (strchr(cancel_chars, *p))
212 {
213 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,
214 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
215 }
216 }
217
218 s = general_allocate_prompt(ui, prompt, prompt_freeable,
219 type, input_flags, result_buf);
220
221 if (s)
222 {
223 if (allocate_string_stack(ui) >= 0)
224 {
225 s->_.boolean_data.action_desc = action_desc;
226 s->_.boolean_data.ok_chars = ok_chars;
227 s->_.boolean_data.cancel_chars = cancel_chars;
228 ret=sk_UI_STRING_push(ui->strings, s);
229 /* sk_push() returns 0 on error.
230 Let's addapt that */
231 if (ret <= 0) ret--;
232 }
233 else
234 free_string(s);
235 }
236 }
237 return ret;
238 }
239
240/* Returns the index to the place in the stack or -1 for error. Uses a
241 direct reference to the prompt. */
242int UI_add_input_string(UI *ui, const char *prompt, int flags,
243 char *result_buf, int minsize, int maxsize)
244 {
245 return general_allocate_string(ui, prompt, 0,
246 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
247 }
248
249/* Same as UI_add_input_string(), excepts it takes a copy of the prompt */
250int UI_dup_input_string(UI *ui, const char *prompt, int flags,
251 char *result_buf, int minsize, int maxsize)
252 {
253 char *prompt_copy=NULL;
254
255 if (prompt)
256 {
257 prompt_copy=BUF_strdup(prompt);
258 if (prompt_copy == NULL)
259 {
260 UIerr(UI_F_UI_DUP_INPUT_STRING,ERR_R_MALLOC_FAILURE);
261 return 0;
262 }
263 }
264
265 return general_allocate_string(ui, prompt_copy, 1,
266 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
267 }
268
269int UI_add_verify_string(UI *ui, const char *prompt, int flags,
270 char *result_buf, int minsize, int maxsize, const char *test_buf)
271 {
272 return general_allocate_string(ui, prompt, 0,
273 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
274 }
275
276int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
277 char *result_buf, int minsize, int maxsize, const char *test_buf)
278 {
279 char *prompt_copy=NULL;
280
281 if (prompt)
282 {
283 prompt_copy=BUF_strdup(prompt);
284 if (prompt_copy == NULL)
285 {
286 UIerr(UI_F_UI_DUP_VERIFY_STRING,ERR_R_MALLOC_FAILURE);
287 return -1;
288 }
289 }
290
291 return general_allocate_string(ui, prompt_copy, 1,
292 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
293 }
294
295int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
296 const char *ok_chars, const char *cancel_chars,
297 int flags, char *result_buf)
298 {
299 return general_allocate_boolean(ui, prompt, action_desc,
300 ok_chars, cancel_chars, 0, UIT_BOOLEAN, flags, result_buf);
301 }
302
303int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
304 const char *ok_chars, const char *cancel_chars,
305 int flags, char *result_buf)
306 {
307 char *prompt_copy = NULL;
308 char *action_desc_copy = NULL;
309 char *ok_chars_copy = NULL;
310 char *cancel_chars_copy = NULL;
311
312 if (prompt)
313 {
314 prompt_copy=BUF_strdup(prompt);
315 if (prompt_copy == NULL)
316 {
317 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
318 goto err;
319 }
320 }
321
322 if (action_desc)
323 {
324 action_desc_copy=BUF_strdup(action_desc);
325 if (action_desc_copy == NULL)
326 {
327 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
328 goto err;
329 }
330 }
331
332 if (ok_chars)
333 {
334 ok_chars_copy=BUF_strdup(ok_chars);
335 if (ok_chars_copy == NULL)
336 {
337 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
338 goto err;
339 }
340 }
341
342 if (cancel_chars)
343 {
344 cancel_chars_copy=BUF_strdup(cancel_chars);
345 if (cancel_chars_copy == NULL)
346 {
347 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN,ERR_R_MALLOC_FAILURE);
348 goto err;
349 }
350 }
351
352 return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
353 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
354 result_buf);
355 err:
356 if (prompt_copy) OPENSSL_free(prompt_copy);
357 if (action_desc_copy) OPENSSL_free(action_desc_copy);
358 if (ok_chars_copy) OPENSSL_free(ok_chars_copy);
359 if (cancel_chars_copy) OPENSSL_free(cancel_chars_copy);
360 return -1;
361 }
362
363int UI_add_info_string(UI *ui, const char *text)
364 {
365 return general_allocate_string(ui, text, 0, UIT_INFO, 0, NULL, 0, 0,
366 NULL);
367 }
368
369int UI_dup_info_string(UI *ui, const char *text)
370 {
371 char *text_copy=NULL;
372
373 if (text)
374 {
375 text_copy=BUF_strdup(text);
376 if (text_copy == NULL)
377 {
378 UIerr(UI_F_UI_DUP_INFO_STRING,ERR_R_MALLOC_FAILURE);
379 return -1;
380 }
381 }
382
383 return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL,
384 0, 0, NULL);
385 }
386
387int UI_add_error_string(UI *ui, const char *text)
388 {
389 return general_allocate_string(ui, text, 0, UIT_ERROR, 0, NULL, 0, 0,
390 NULL);
391 }
392
393int UI_dup_error_string(UI *ui, const char *text)
394 {
395 char *text_copy=NULL;
396
397 if (text)
398 {
399 text_copy=BUF_strdup(text);
400 if (text_copy == NULL)
401 {
402 UIerr(UI_F_UI_DUP_ERROR_STRING,ERR_R_MALLOC_FAILURE);
403 return -1;
404 }
405 }
406 return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL,
407 0, 0, NULL);
408 }
409
410char *UI_construct_prompt(UI *ui, const char *object_desc,
411 const char *object_name)
412 {
413 char *prompt = NULL;
414
415 if (ui->meth->ui_construct_prompt)
416 prompt = ui->meth->ui_construct_prompt(ui,
417 object_desc, object_name);
418 else
419 {
420 char prompt1[] = "Enter ";
421 char prompt2[] = " for ";
422 char prompt3[] = ":";
423 int len = 0;
424
425 if (object_desc == NULL)
426 return NULL;
427 len = sizeof(prompt1) - 1 + strlen(object_desc);
428 if (object_name)
429 len += sizeof(prompt2) - 1 + strlen(object_name);
430 len += sizeof(prompt3) - 1;
431
432 prompt = (char *)OPENSSL_malloc(len + 1);
433 BUF_strlcpy(prompt, prompt1, len + 1);
434 BUF_strlcat(prompt, object_desc, len + 1);
435 if (object_name)
436 {
437 BUF_strlcat(prompt, prompt2, len + 1);
438 BUF_strlcat(prompt, object_name, len + 1);
439 }
440 BUF_strlcat(prompt, prompt3, len + 1);
441 }
442 return prompt;
443 }
444
445void *UI_add_user_data(UI *ui, void *user_data)
446 {
447 void *old_data = ui->user_data;
448 ui->user_data = user_data;
449 return old_data;
450 }
451
452void *UI_get0_user_data(UI *ui)
453 {
454 return ui->user_data;
455 }
456
457const char *UI_get0_result(UI *ui, int i)
458 {
459 if (i < 0)
460 {
461 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_SMALL);
462 return NULL;
463 }
464 if (i >= sk_UI_STRING_num(ui->strings))
465 {
466 UIerr(UI_F_UI_GET0_RESULT,UI_R_INDEX_TOO_LARGE);
467 return NULL;
468 }
469 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
470 }
471
472static int print_error(const char *str, size_t len, UI *ui)
473 {
474 UI_STRING uis;
475
476 memset(&uis, 0, sizeof(uis));
477 uis.type = UIT_ERROR;
478 uis.out_string = str;
479
480 if (ui->meth->ui_write_string
481 && !ui->meth->ui_write_string(ui, &uis))
482 return -1;
483 return 0;
484 }
485
486int UI_process(UI *ui)
487 {
488 int i, ok=0;
489
490 if (ui->meth->ui_open_session && !ui->meth->ui_open_session(ui))
491 return -1;
492
493 if (ui->flags & UI_FLAG_PRINT_ERRORS)
494 ERR_print_errors_cb(
495 (int (*)(const char *, size_t, void *))print_error,
496 (void *)ui);
497
498 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
499 {
500 if (ui->meth->ui_write_string
501 && !ui->meth->ui_write_string(ui,
502 sk_UI_STRING_value(ui->strings, i)))
503 {
504 ok=-1;
505 goto err;
506 }
507 }
508
509 if (ui->meth->ui_flush)
510 switch(ui->meth->ui_flush(ui))
511 {
512 case -1: /* Interrupt/Cancel/something... */
513 ok = -2;
514 goto err;
515 case 0: /* Errors */
516 ok = -1;
517 goto err;
518 default: /* Success */
519 ok = 0;
520 break;
521 }
522
523 for(i=0; i<sk_UI_STRING_num(ui->strings); i++)
524 {
525 if (ui->meth->ui_read_string)
526 {
527 switch(ui->meth->ui_read_string(ui,
528 sk_UI_STRING_value(ui->strings, i)))
529 {
530 case -1: /* Interrupt/Cancel/something... */
531 ok = -2;
532 goto err;
533 case 0: /* Errors */
534 ok = -1;
535 goto err;
536 default: /* Success */
537 ok = 0;
538 break;
539 }
540 }
541 }
542 err:
543 if (ui->meth->ui_close_session && !ui->meth->ui_close_session(ui))
544 return -1;
545 return ok;
546 }
547
548int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)())
549 {
550 if (ui == NULL)
551 {
552 UIerr(UI_F_UI_CTRL,ERR_R_PASSED_NULL_PARAMETER);
553 return -1;
554 }
555 switch(cmd)
556 {
557 case UI_CTRL_PRINT_ERRORS:
558 {
559 int save_flag = !!(ui->flags & UI_FLAG_PRINT_ERRORS);
560 if (i)
561 ui->flags |= UI_FLAG_PRINT_ERRORS;
562 else
563 ui->flags &= ~UI_FLAG_PRINT_ERRORS;
564 return save_flag;
565 }
566 case UI_CTRL_IS_REDOABLE:
567 return !!(ui->flags & UI_FLAG_REDOABLE);
568 default:
569 break;
570 }
571 UIerr(UI_F_UI_CTRL,UI_R_UNKNOWN_CONTROL_COMMAND);
572 return -1;
573 }
574
575int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
576 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
577 {
578 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, argl, argp,
579 new_func, dup_func, free_func);
580 }
581
582int UI_set_ex_data(UI *r, int idx, void *arg)
583 {
584 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
585 }
586
587void *UI_get_ex_data(UI *r, int idx)
588 {
589 return(CRYPTO_get_ex_data(&r->ex_data,idx));
590 }
591
592void UI_set_default_method(const UI_METHOD *meth)
593 {
594 default_UI_meth=meth;
595 }
596
597const UI_METHOD *UI_get_default_method(void)
598 {
599 if (default_UI_meth == NULL)
600 {
601 default_UI_meth=UI_OpenSSL();
602 }
603 return default_UI_meth;
604 }
605
606const UI_METHOD *UI_get_method(UI *ui)
607 {
608 return ui->meth;
609 }
610
611const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth)
612 {
613 ui->meth=meth;
614 return ui->meth;
615 }
616
617
618UI_METHOD *UI_create_method(char *name)
619 {
620 UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD));
621
622 if (ui_method)
623 memset(ui_method, 0, sizeof(*ui_method));
624 ui_method->name = BUF_strdup(name);
625 return ui_method;
626 }
627
628/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
629 (that is, it hasn't been allocated using UI_create_method(), you deserve
630 anything Murphy can throw at you and more! You have been warned. */
631void UI_destroy_method(UI_METHOD *ui_method)
632 {
633 OPENSSL_free(ui_method->name);
634 ui_method->name = NULL;
635 OPENSSL_free(ui_method);
636 }
637
638int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
639 {
640 if (method)
641 {
642 method->ui_open_session = opener;
643 return 0;
644 }
645 else
646 return -1;
647 }
648
649int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis))
650 {
651 if (method)
652 {
653 method->ui_write_string = writer;
654 return 0;
655 }
656 else
657 return -1;
658 }
659
660int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui))
661 {
662 if (method)
663 {
664 method->ui_flush = flusher;
665 return 0;
666 }
667 else
668 return -1;
669 }
670
671int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis))
672 {
673 if (method)
674 {
675 method->ui_read_string = reader;
676 return 0;
677 }
678 else
679 return -1;
680 }
681
682int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui))
683 {
684 if (method)
685 {
686 method->ui_close_session = closer;
687 return 0;
688 }
689 else
690 return -1;
691 }
692
693int (*UI_method_get_opener(UI_METHOD *method))(UI*)
694 {
695 if (method)
696 return method->ui_open_session;
697 else
698 return NULL;
699 }
700
701int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*)
702 {
703 if (method)
704 return method->ui_write_string;
705 else
706 return NULL;
707 }
708
709int (*UI_method_get_flusher(UI_METHOD *method))(UI*)
710 {
711 if (method)
712 return method->ui_flush;
713 else
714 return NULL;
715 }
716
717int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*)
718 {
719 if (method)
720 return method->ui_read_string;
721 else
722 return NULL;
723 }
724
725int (*UI_method_get_closer(UI_METHOD *method))(UI*)
726 {
727 if (method)
728 return method->ui_close_session;
729 else
730 return NULL;
731 }
732
733enum UI_string_types UI_get_string_type(UI_STRING *uis)
734 {
735 if (!uis)
736 return UIT_NONE;
737 return uis->type;
738 }
739
740int UI_get_input_flags(UI_STRING *uis)
741 {
742 if (!uis)
743 return 0;
744 return uis->input_flags;
745 }
746
747const char *UI_get0_output_string(UI_STRING *uis)
748 {
749 if (!uis)
750 return NULL;
751 return uis->out_string;
752 }
753
754const char *UI_get0_action_string(UI_STRING *uis)
755 {
756 if (!uis)
757 return NULL;
758 switch(uis->type)
759 {
760 case UIT_PROMPT:
761 case UIT_BOOLEAN:
762 return uis->_.boolean_data.action_desc;
763 default:
764 return NULL;
765 }
766 }
767
768const char *UI_get0_result_string(UI_STRING *uis)
769 {
770 if (!uis)
771 return NULL;
772 switch(uis->type)
773 {
774 case UIT_PROMPT:
775 case UIT_VERIFY:
776 return uis->result_buf;
777 default:
778 return NULL;
779 }
780 }
781
782const char *UI_get0_test_string(UI_STRING *uis)
783 {
784 if (!uis)
785 return NULL;
786 switch(uis->type)
787 {
788 case UIT_VERIFY:
789 return uis->_.string_data.test_buf;
790 default:
791 return NULL;
792 }
793 }
794
795int UI_get_result_minsize(UI_STRING *uis)
796 {
797 if (!uis)
798 return -1;
799 switch(uis->type)
800 {
801 case UIT_PROMPT:
802 case UIT_VERIFY:
803 return uis->_.string_data.result_minsize;
804 default:
805 return -1;
806 }
807 }
808
809int UI_get_result_maxsize(UI_STRING *uis)
810 {
811 if (!uis)
812 return -1;
813 switch(uis->type)
814 {
815 case UIT_PROMPT:
816 case UIT_VERIFY:
817 return uis->_.string_data.result_maxsize;
818 default:
819 return -1;
820 }
821 }
822
823int UI_set_result(UI *ui, UI_STRING *uis, const char *result)
824 {
825 int l = strlen(result);
826
827 ui->flags &= ~UI_FLAG_REDOABLE;
828
829 if (!uis)
830 return -1;
831 switch (uis->type)
832 {
833 case UIT_PROMPT:
834 case UIT_VERIFY:
835 {
836 char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize)+1];
837 char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize)+1];
838
839 BIO_snprintf(number1, sizeof(number1), "%d",
840 uis->_.string_data.result_minsize);
841 BIO_snprintf(number2, sizeof(number2), "%d",
842 uis->_.string_data.result_maxsize);
843
844 if (l < uis->_.string_data.result_minsize)
845 {
846 ui->flags |= UI_FLAG_REDOABLE;
847 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_SMALL);
848 ERR_add_error_data(5,"You must type in ",
849 number1," to ",number2," characters");
850 return -1;
851 }
852 if (l > uis->_.string_data.result_maxsize)
853 {
854 ui->flags |= UI_FLAG_REDOABLE;
855 UIerr(UI_F_UI_SET_RESULT,UI_R_RESULT_TOO_LARGE);
856 ERR_add_error_data(5,"You must type in ",
857 number1," to ",number2," characters");
858 return -1;
859 }
860 }
861
862 if (!uis->result_buf)
863 {
864 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
865 return -1;
866 }
867
868 BUF_strlcpy(uis->result_buf, result,
869 uis->_.string_data.result_maxsize + 1);
870 break;
871 case UIT_BOOLEAN:
872 {
873 const char *p;
874
875 if (!uis->result_buf)
876 {
877 UIerr(UI_F_UI_SET_RESULT,UI_R_NO_RESULT_BUFFER);
878 return -1;
879 }
880
881 uis->result_buf[0] = '\0';
882 for(p = result; *p; p++)
883 {
884 if (strchr(uis->_.boolean_data.ok_chars, *p))
885 {
886 uis->result_buf[0] =
887 uis->_.boolean_data.ok_chars[0];
888 break;
889 }
890 if (strchr(uis->_.boolean_data.cancel_chars, *p))
891 {
892 uis->result_buf[0] =
893 uis->_.boolean_data.cancel_chars[0];
894 break;
895 }
896 }
897 default:
898 break;
899 }
900 }
901 return 0;
902 }
diff --git a/src/lib/libcrypto/ui/ui_locl.h b/src/lib/libcrypto/ui/ui_locl.h
deleted file mode 100644
index 7d3a75a619..0000000000
--- a/src/lib/libcrypto/ui/ui_locl.h
+++ /dev/null
@@ -1,148 +0,0 @@
1/* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_UI_LOCL_H
60#define HEADER_UI_LOCL_H
61
62#include <openssl/ui.h>
63
64struct ui_method_st
65 {
66 char *name;
67
68 /* All the functions return 1 or non-NULL for success and 0 or NULL
69 for failure */
70
71 /* Open whatever channel for this, be it the console, an X window
72 or whatever.
73 This function should use the ex_data structure to save
74 intermediate data. */
75 int (*ui_open_session)(UI *ui);
76
77 int (*ui_write_string)(UI *ui, UI_STRING *uis);
78
79 /* Flush the output. If a GUI dialog box is used, this function can
80 be used to actually display it. */
81 int (*ui_flush)(UI *ui);
82
83 int (*ui_read_string)(UI *ui, UI_STRING *uis);
84
85 int (*ui_close_session)(UI *ui);
86
87 /* Construct a prompt in a user-defined manner. object_desc is a
88 textual short description of the object, for example "pass phrase",
89 and object_name is the name of the object (might be a card name or
90 a file name.
91 The returned string shall always be allocated on the heap with
92 OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). */
93 char *(*ui_construct_prompt)(UI *ui, const char *object_desc,
94 const char *object_name);
95 };
96
97struct ui_string_st
98 {
99 enum UI_string_types type; /* Input */
100 const char *out_string; /* Input */
101 int input_flags; /* Flags from the user */
102
103 /* The following parameters are completely irrelevant for UIT_INFO,
104 and can therefore be set to 0 or NULL */
105 char *result_buf; /* Input and Output: If not NULL, user-defined
106 with size in result_maxsize. Otherwise, it
107 may be allocated by the UI routine, meaning
108 result_minsize is going to be overwritten.*/
109 union
110 {
111 struct
112 {
113 int result_minsize; /* Input: minimum required
114 size of the result.
115 */
116 int result_maxsize; /* Input: maximum permitted
117 size of the result */
118
119 const char *test_buf; /* Input: test string to verify
120 against */
121 } string_data;
122 struct
123 {
124 const char *action_desc; /* Input */
125 const char *ok_chars; /* Input */
126 const char *cancel_chars; /* Input */
127 } boolean_data;
128 } _;
129
130#define OUT_STRING_FREEABLE 0x01
131 int flags; /* flags for internal use */
132 };
133
134struct ui_st
135 {
136 const UI_METHOD *meth;
137 STACK_OF(UI_STRING) *strings; /* We might want to prompt for more
138 than one thing at a time, and
139 with different echoing status. */
140 void *user_data;
141 CRYPTO_EX_DATA ex_data;
142
143#define UI_FLAG_REDOABLE 0x0001
144#define UI_FLAG_PRINT_ERRORS 0x0100
145 int flags;
146 };
147
148#endif
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c
deleted file mode 100644
index d03aeba91a..0000000000
--- a/src/lib/libcrypto/ui/ui_openssl.c
+++ /dev/null
@@ -1,674 +0,0 @@
1/* crypto/ui/ui_openssl.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) and others
3 * for the OpenSSL project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* The lowest level part of this file was previously in crypto/des/read_pwd.c,
60 * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
61 * All rights reserved.
62 *
63 * This package is an SSL implementation written
64 * by Eric Young (eay@cryptsoft.com).
65 * The implementation was written so as to conform with Netscapes SSL.
66 *
67 * This library is free for commercial and non-commercial use as long as
68 * the following conditions are aheared to. The following conditions
69 * apply to all code found in this distribution, be it the RC4, RSA,
70 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
71 * included with this distribution is covered by the same copyright terms
72 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
73 *
74 * Copyright remains Eric Young's, and as such any Copyright notices in
75 * the code are not to be removed.
76 * If this package is used in a product, Eric Young should be given attribution
77 * as the author of the parts of the library used.
78 * This can be in the form of a textual message at program startup or
79 * in documentation (online or textual) provided with the package.
80 *
81 * Redistribution and use in source and binary forms, with or without
82 * modification, are permitted provided that the following conditions
83 * are met:
84 * 1. Redistributions of source code must retain the copyright
85 * notice, this list of conditions and the following disclaimer.
86 * 2. Redistributions in binary form must reproduce the above copyright
87 * notice, this list of conditions and the following disclaimer in the
88 * documentation and/or other materials provided with the distribution.
89 * 3. All advertising materials mentioning features or use of this software
90 * must display the following acknowledgement:
91 * "This product includes cryptographic software written by
92 * Eric Young (eay@cryptsoft.com)"
93 * The word 'cryptographic' can be left out if the rouines from the library
94 * being used are not cryptographic related :-).
95 * 4. If you include any Windows specific code (or a derivative thereof) from
96 * the apps directory (application code) you must include an acknowledgement:
97 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
98 *
99 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
100 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
102 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
103 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
104 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
105 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
106 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
107 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
108 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
109 * SUCH DAMAGE.
110 *
111 * The licence and distribution terms for any publically available version or
112 * derivative of this code cannot be changed. i.e. this code cannot simply be
113 * copied and put under another distribution licence
114 * [including the GNU Public Licence.]
115 */
116
117
118#include <openssl/e_os2.h>
119
120#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
121# ifdef OPENSSL_UNISTD
122# include OPENSSL_UNISTD
123# else
124# include <unistd.h>
125# endif
126/* If unistd.h defines _POSIX_VERSION, we conclude that we
127 * are on a POSIX system and have sigaction and termios. */
128# if defined(_POSIX_VERSION)
129
130# define SIGACTION
131# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
132# define TERMIOS
133# endif
134
135# endif
136#endif
137
138#ifdef WIN16TTY
139# undef OPENSSL_SYS_WIN16
140# undef WIN16
141# undef _WINDOWS
142# include <graph.h>
143#endif
144
145/* 06-Apr-92 Luke Brennan Support for VMS */
146#include "ui_locl.h"
147#include "cryptlib.h"
148#include <signal.h>
149#include <stdio.h>
150#include <string.h>
151#include <errno.h>
152
153#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
154# include <starlet.h>
155# ifdef __DECC
156# pragma message disable DOLLARID
157# endif
158#endif
159
160#ifdef WIN_CONSOLE_BUG
161# include <windows.h>
162#ifndef OPENSSL_SYS_WINCE
163# include <wincon.h>
164#endif
165#endif
166
167
168/* There are 5 types of terminal interface supported,
169 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
170 */
171
172#if defined(__sgi) && !defined(TERMIOS)
173# define TERMIOS
174# undef TERMIO
175# undef SGTTY
176#endif
177
178#if defined(linux) && !defined(TERMIO)
179# undef TERMIOS
180# define TERMIO
181# undef SGTTY
182#endif
183
184#ifdef _LIBC
185# undef TERMIOS
186# define TERMIO
187# undef SGTTY
188#endif
189
190#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
191# undef TERMIOS
192# undef TERMIO
193# define SGTTY
194#endif
195
196#if defined(OPENSSL_SYS_VXWORKS)
197#undef TERMIOS
198#undef TERMIO
199#undef SGTTY
200#endif
201
202#ifdef TERMIOS
203# include <termios.h>
204# define TTY_STRUCT struct termios
205# define TTY_FLAGS c_lflag
206# define TTY_get(tty,data) tcgetattr(tty,data)
207# define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
208#endif
209
210#ifdef TERMIO
211# include <termio.h>
212# define TTY_STRUCT struct termio
213# define TTY_FLAGS c_lflag
214# define TTY_get(tty,data) ioctl(tty,TCGETA,data)
215# define TTY_set(tty,data) ioctl(tty,TCSETA,data)
216#endif
217
218#ifdef SGTTY
219# include <sgtty.h>
220# define TTY_STRUCT struct sgttyb
221# define TTY_FLAGS sg_flags
222# define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
223# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
224#endif
225
226#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS)
227# include <sys/ioctl.h>
228#endif
229
230#ifdef OPENSSL_SYS_MSDOS
231# include <conio.h>
232#endif
233
234#ifdef OPENSSL_SYS_VMS
235# include <ssdef.h>
236# include <iodef.h>
237# include <ttdef.h>
238# include <descrip.h>
239struct IOSB {
240 short iosb$w_value;
241 short iosb$w_count;
242 long iosb$l_info;
243 };
244#endif
245
246#ifdef OPENSSL_SYS_SUNOS
247 typedef int sig_atomic_t;
248#endif
249
250#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE)
251/*
252 * This one needs work. As a matter of fact the code is unoperational
253 * and this is only a trick to get it compiled.
254 * <appro@fy.chalmers.se>
255 */
256# define TTY_STRUCT int
257#endif
258
259#ifndef NX509_SIG
260# define NX509_SIG 32
261#endif
262
263
264/* Define globals. They are protected by a lock */
265#ifdef SIGACTION
266static struct sigaction savsig[NX509_SIG];
267#else
268static void (*savsig[NX509_SIG])(int );
269#endif
270
271#ifdef OPENSSL_SYS_VMS
272static struct IOSB iosb;
273static $DESCRIPTOR(terminal,"TT");
274static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this will always suffice for the actual structures? */
275static long status;
276static unsigned short channel = 0;
277#else
278#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
279static TTY_STRUCT tty_orig,tty_new;
280#endif
281#endif
282static FILE *tty_in, *tty_out;
283static int is_a_tty;
284
285/* Declare static functions */
286#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
287static void read_till_nl(FILE *);
288static void recsig(int);
289static void pushsig(void);
290static void popsig(void);
291#endif
292#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
293static int noecho_fgets(char *buf, int size, FILE *tty);
294#endif
295static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
296
297static int read_string(UI *ui, UI_STRING *uis);
298static int write_string(UI *ui, UI_STRING *uis);
299
300static int open_console(UI *ui);
301static int echo_console(UI *ui);
302static int noecho_console(UI *ui);
303static int close_console(UI *ui);
304
305static UI_METHOD ui_openssl =
306 {
307 "OpenSSL default user interface",
308 open_console,
309 write_string,
310 NULL, /* No flusher is needed for command lines */
311 read_string,
312 close_console,
313 NULL
314 };
315
316/* The method with all the built-in thingies */
317UI_METHOD *UI_OpenSSL(void)
318 {
319 return &ui_openssl;
320 }
321
322/* The following function makes sure that info and error strings are printed
323 before any prompt. */
324static int write_string(UI *ui, UI_STRING *uis)
325 {
326 switch (UI_get_string_type(uis))
327 {
328 case UIT_ERROR:
329 case UIT_INFO:
330 fputs(UI_get0_output_string(uis), tty_out);
331 fflush(tty_out);
332 break;
333 default:
334 break;
335 }
336 return 1;
337 }
338
339static int read_string(UI *ui, UI_STRING *uis)
340 {
341 int ok = 0;
342
343 switch (UI_get_string_type(uis))
344 {
345 case UIT_BOOLEAN:
346 fputs(UI_get0_output_string(uis), tty_out);
347 fputs(UI_get0_action_string(uis), tty_out);
348 fflush(tty_out);
349 return read_string_inner(ui, uis,
350 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
351 case UIT_PROMPT:
352 fputs(UI_get0_output_string(uis), tty_out);
353 fflush(tty_out);
354 return read_string_inner(ui, uis,
355 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
356 case UIT_VERIFY:
357 fprintf(tty_out,"Verifying - %s",
358 UI_get0_output_string(uis));
359 fflush(tty_out);
360 if ((ok = read_string_inner(ui, uis,
361 UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
362 return ok;
363 if (strcmp(UI_get0_result_string(uis),
364 UI_get0_test_string(uis)) != 0)
365 {
366 fprintf(tty_out,"Verify failure\n");
367 fflush(tty_out);
368 return 0;
369 }
370 break;
371 default:
372 break;
373 }
374 return 1;
375 }
376
377
378#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
379/* Internal functions to read a string without echoing */
380static void read_till_nl(FILE *in)
381 {
382#define SIZE 4
383 char buf[SIZE+1];
384
385 do {
386 if (fgets(buf,sizeof(buf),in) == NULL)
387 break;
388 } while (strchr(buf,'\n') == NULL);
389 }
390
391static volatile sig_atomic_t intr_signal;
392#endif
393
394static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
395 {
396 static int ps;
397 int ok;
398 char result[BUFSIZ];
399 int maxsize = BUFSIZ-1;
400#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
401 char *p;
402
403 intr_signal=0;
404 ok=0;
405 ps=0;
406
407 pushsig();
408 ps=1;
409
410 if (!echo && !noecho_console(ui))
411 goto error;
412 ps=2;
413
414 result[0]='\0';
415#ifdef OPENSSL_SYS_MSDOS
416 if (!echo)
417 {
418 noecho_fgets(result,maxsize,tty_in);
419 p=result; /* FIXME: noecho_fgets doesn't return errors */
420 }
421 else
422 p=fgets(result,maxsize,tty_in);
423#else
424 p=fgets(result,maxsize,tty_in);
425#endif
426 if(!p)
427 goto error;
428 if (feof(tty_in)) goto error;
429 if (ferror(tty_in)) goto error;
430 if ((p=(char *)strchr(result,'\n')) != NULL)
431 {
432 if (strip_nl)
433 *p='\0';
434 }
435 else
436 read_till_nl(tty_in);
437 if (UI_set_result(ui, uis, result) >= 0)
438 ok=1;
439
440error:
441 if (intr_signal == SIGINT)
442 ok=-1;
443 if (!echo) fprintf(tty_out,"\n");
444 if (ps >= 2 && !echo && !echo_console(ui))
445 ok=0;
446
447 if (ps >= 1)
448 popsig();
449#else
450 ok=1;
451#endif
452
453 OPENSSL_cleanse(result,BUFSIZ);
454 return ok;
455 }
456
457
458/* Internal functions to open, handle and close a channel to the console. */
459static int open_console(UI *ui)
460 {
461 CRYPTO_w_lock(CRYPTO_LOCK_UI);
462 is_a_tty = 1;
463
464#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS)
465 tty_in=stdin;
466 tty_out=stderr;
467#else
468# ifdef OPENSSL_SYS_MSDOS
469# define DEV_TTY "con"
470# else
471# define DEV_TTY "/dev/tty"
472# endif
473 if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
474 tty_in=stdin;
475 if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
476 tty_out=stderr;
477#endif
478
479#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
480 if (TTY_get(fileno(tty_in),&tty_orig) == -1)
481 {
482#ifdef ENOTTY
483 if (errno == ENOTTY)
484 is_a_tty=0;
485 else
486#endif
487#ifdef EINVAL
488 /* Ariel Glenn ariel@columbia.edu reports that solaris
489 * can return EINVAL instead. This should be ok */
490 if (errno == EINVAL)
491 is_a_tty=0;
492 else
493#endif
494 return 0;
495 }
496#endif
497#ifdef OPENSSL_SYS_VMS
498 status = sys$assign(&terminal,&channel,0,0);
499 if (status != SS$_NORMAL)
500 return 0;
501 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
502 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
503 return 0;
504#endif
505 return 1;
506 }
507
508static int noecho_console(UI *ui)
509 {
510#ifdef TTY_FLAGS
511 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
512 tty_new.TTY_FLAGS &= ~ECHO;
513#endif
514
515#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
516 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
517 return 0;
518#endif
519#ifdef OPENSSL_SYS_VMS
520 tty_new[0] = tty_orig[0];
521 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
522 tty_new[2] = tty_orig[2];
523 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
524 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
525 return 0;
526#endif
527 return 1;
528 }
529
530static int echo_console(UI *ui)
531 {
532#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
533 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
534 tty_new.TTY_FLAGS |= ECHO;
535#endif
536
537#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
538 if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
539 return 0;
540#endif
541#ifdef OPENSSL_SYS_VMS
542 tty_new[0] = tty_orig[0];
543 tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
544 tty_new[2] = tty_orig[2];
545 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
546 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
547 return 0;
548#endif
549 return 1;
550 }
551
552static int close_console(UI *ui)
553 {
554 if (tty_in != stdin) fclose(tty_in);
555 if (tty_out != stderr) fclose(tty_out);
556#ifdef OPENSSL_SYS_VMS
557 status = sys$dassgn(channel);
558#endif
559 CRYPTO_w_unlock(CRYPTO_LOCK_UI);
560
561 return 1;
562 }
563
564
565#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
566/* Internal functions to handle signals and act on them */
567static void pushsig(void)
568 {
569 int i;
570#ifdef SIGACTION
571 struct sigaction sa;
572
573 memset(&sa,0,sizeof sa);
574 sa.sa_handler=recsig;
575#endif
576
577 for (i=1; i<NX509_SIG; i++)
578 {
579#ifdef SIGUSR1
580 if (i == SIGUSR1)
581 continue;
582#endif
583#ifdef SIGUSR2
584 if (i == SIGUSR2)
585 continue;
586#endif
587#ifdef SIGKILL
588 if (i == SIGKILL) /* We can't make any action on that. */
589 continue;
590#endif
591#ifdef SIGACTION
592 sigaction(i,&sa,&savsig[i]);
593#else
594 savsig[i]=signal(i,recsig);
595#endif
596 }
597
598#ifdef SIGWINCH
599 signal(SIGWINCH,SIG_DFL);
600#endif
601 }
602
603static void popsig(void)
604 {
605 int i;
606
607 for (i=1; i<NX509_SIG; i++)
608 {
609#ifdef SIGUSR1
610 if (i == SIGUSR1)
611 continue;
612#endif
613#ifdef SIGUSR2
614 if (i == SIGUSR2)
615 continue;
616#endif
617#ifdef SIGACTION
618 sigaction(i,&savsig[i],NULL);
619#else
620 signal(i,savsig[i]);
621#endif
622 }
623 }
624
625static void recsig(int i)
626 {
627 intr_signal=i;
628 }
629#endif
630
631/* Internal functions specific for Windows */
632#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
633static int noecho_fgets(char *buf, int size, FILE *tty)
634 {
635 int i;
636 char *p;
637
638 p=buf;
639 for (;;)
640 {
641 if (size == 0)
642 {
643 *p='\0';
644 break;
645 }
646 size--;
647#ifdef WIN16TTY
648 i=_inchar();
649#else
650 i=getch();
651#endif
652 if (i == '\r') i='\n';
653 *(p++)=i;
654 if (i == '\n')
655 {
656 *p='\0';
657 break;
658 }
659 }
660#ifdef WIN_CONSOLE_BUG
661/* Win95 has several evil console bugs: one of these is that the
662 * last character read using getch() is passed to the next read: this is
663 * usually a CR so this can be trouble. No STDIO fix seems to work but
664 * flushing the console appears to do the trick.
665 */
666 {
667 HANDLE inh;
668 inh = GetStdHandle(STD_INPUT_HANDLE);
669 FlushConsoleInputBuffer(inh);
670 }
671#endif
672 return(strlen(buf));
673 }
674#endif
diff --git a/src/lib/libcrypto/ui/ui_util.c b/src/lib/libcrypto/ui/ui_util.c
deleted file mode 100644
index 46bc8c1a9a..0000000000
--- a/src/lib/libcrypto/ui/ui_util.c
+++ /dev/null
@@ -1,91 +0,0 @@
1/* crypto/ui/ui_util.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57#include <openssl/ui.h>
58
59int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 {
61 char buff[BUFSIZ];
62 int ret;
63
64 ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
65 OPENSSL_cleanse(buff,BUFSIZ);
66 return(ret);
67 }
68
69int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
70 {
71 int ok = 0;
72 UI *ui;
73
74 if (size < 1)
75 return -1;
76
77 ui = UI_new();
78 if (ui)
79 {
80 ok = UI_add_input_string(ui,prompt,0,buf,0,size-1);
81 if (ok >= 0 && verify)
82 ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1,
83 buf);
84 if (ok >= 0)
85 ok=UI_process(ui);
86 UI_free(ui);
87 }
88 if (ok > 0)
89 ok = 0;
90 return(ok);
91 }
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl
deleted file mode 100644
index 9678514604..0000000000
--- a/src/lib/libcrypto/util/mkerr.pl
+++ /dev/null
@@ -1,653 +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;
10my $staticloader = "";
11
12my $pack_errcode;
13my $load_errcode;
14
15while (@ARGV) {
16 my $arg = $ARGV[0];
17 if($arg eq "-conf") {
18 shift @ARGV;
19 $config = shift @ARGV;
20 } elsif($arg eq "-debug") {
21 $debug = 1;
22 shift @ARGV;
23 } elsif($arg eq "-rebuild") {
24 $rebuild = 1;
25 shift @ARGV;
26 } elsif($arg eq "-recurse") {
27 $recurse = 1;
28 shift @ARGV;
29 } elsif($arg eq "-reindex") {
30 $reindex = 1;
31 shift @ARGV;
32 } elsif($arg eq "-nostatic") {
33 $static = 0;
34 shift @ARGV;
35 } elsif($arg eq "-staticloader") {
36 $staticloader = "static ";
37 shift @ARGV;
38 } elsif($arg eq "-write") {
39 $dowrite = 1;
40 shift @ARGV;
41 } else {
42 last;
43 }
44}
45
46if($recurse) {
47 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <fips-1.0/*.c>,
48 <fips-1.0/*/*.c>);
49} else {
50 @source = @ARGV;
51}
52
53# Read in the config file
54
55open(IN, "<$config") || die "Can't open config file $config";
56
57# Parse config file
58
59while(<IN>)
60{
61 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
62 $hinc{$1} = $2;
63 $libinc{$2} = $1;
64 $cskip{$3} = $1;
65 if($3 ne "NONE") {
66 $csrc{$1} = $3;
67 $fmax{$1} = 99;
68 $rmax{$1} = 99;
69 $fnew{$1} = 0;
70 $rnew{$1} = 0;
71 }
72 } elsif (/^F\s+(\S+)/) {
73 # Add extra function with $1
74 } elsif (/^R\s+(\S+)\s+(\S+)/) {
75 $rextra{$1} = $2;
76 $rcodes{$1} = $2;
77 }
78}
79
80close IN;
81
82# Scan each header file in turn and make a list of error codes
83# and function names
84
85while (($hdr, $lib) = each %libinc)
86{
87 next if($hdr eq "NONE");
88 print STDERR "Scanning header file $hdr\n" if $debug;
89 my $line = "", $def= "", $linenr = 0, $gotfile = 0;
90 if (open(IN, "<$hdr")) {
91 $gotfile = 1;
92 while(<IN>) {
93 $linenr++;
94 print STDERR "line: $linenr\r" if $debug;
95
96 last if(/BEGIN\s+ERROR\s+CODES/);
97 if ($line ne '') {
98 $_ = $line . $_;
99 $line = '';
100 }
101
102 if (/\\$/) {
103 $line = $_;
104 next;
105 }
106
107 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
108 if ($cpp) {
109 $cpp = 0 if /^#.*endif/;
110 next;
111 }
112
113 next if (/^\#/); # skip preprocessor directives
114
115 s/\/\*.*?\*\///gs; # ignore comments
116 s/{[^{}]*}//gs; # ignore {} blocks
117
118 if (/\{|\/\*/) { # Add a } so editor works...
119 $line = $_;
120 } else {
121 $def .= $_;
122 }
123 }
124 }
125
126 print STDERR " \r" if $debug;
127 $defnr = 0;
128 foreach (split /;/, $def) {
129 $defnr++;
130 print STDERR "def: $defnr\r" if $debug;
131
132 s/^[\n\s]*//g;
133 s/[\n\s]*$//g;
134 next if(/typedef\W/);
135 if (/\(\*(\w*)\([^\)]+/) {
136 my $name = $1;
137 $name =~ tr/[a-z]/[A-Z]/;
138 $ftrans{$name} = $1;
139 } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s){
140 # K&R C
141 next ;
142 } elsif (/\w+\W+\w+\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) {
143 while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) {
144 s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
145 s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
146 }
147 s/\(void\)//;
148 /(\w+(\{[0-9]+\})?)\W*\(\)/s;
149 my $name = $1;
150 $name =~ tr/[a-z]/[A-Z]/;
151 $ftrans{$name} = $1;
152 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
153 print STDERR "Header $hdr: cannot parse: $_;\n";
154 }
155 }
156
157 print STDERR " \r" if $debug;
158
159 next if $reindex;
160
161 # Scan function and reason codes and store them: keep a note of the
162 # maximum code used.
163
164 if ($gotfile) {
165 while(<IN>) {
166 if(/^\#define\s+(\S+)\s+(\S+)/) {
167 $name = $1;
168 $code = $2;
169 next if $name =~ /^${lib}err/;
170 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
171 print STDERR "Invalid error code $name\n";
172 next;
173 }
174 if($1 eq "R") {
175 $rcodes{$name} = $code;
176 if(!(exists $rextra{$name}) &&
177 ($code > $rmax{$lib}) ) {
178 $rmax{$lib} = $code;
179 }
180 } else {
181 if($code > $fmax{$lib}) {
182 $fmax{$lib} = $code;
183 }
184 $fcodes{$name} = $code;
185 }
186 }
187 }
188 }
189 close IN;
190}
191
192# Scan each C source file and look for function and reason codes
193# This is done by looking for strings that "look like" function or
194# reason codes: basically anything consisting of all upper case and
195# numerics which has _F_ or _R_ in it and which has the name of an
196# error library at the start. This seems to work fine except for the
197# oddly named structure BIO_F_CTX which needs to be ignored.
198# If a code doesn't exist in list compiled from headers then mark it
199# with the value "X" as a place holder to give it a value later.
200# Store all function and reason codes found in %ufcodes and %urcodes
201# so all those unreferenced can be printed out.
202
203
204print STDERR "Files loaded: " if $debug;
205foreach $file (@source) {
206 # Don't parse the error source file.
207 next if exists $cskip{$file};
208 print STDERR $file if $debug;
209 open(IN, "<$file") || die "Can't open source file $file\n";
210 while(<IN>) {
211 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
212 next unless exists $csrc{$2};
213 next if($1 eq "BIO_F_BUFFER_CTX");
214 $ufcodes{$1} = 1;
215 if(!exists $fcodes{$1}) {
216 $fcodes{$1} = "X";
217 $fnew{$2}++;
218 }
219 $notrans{$1} = 1 unless exists $ftrans{$3};
220 }
221 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
222 next unless exists $csrc{$2};
223 $urcodes{$1} = 1;
224 if(!exists $rcodes{$1}) {
225 $rcodes{$1} = "X";
226 $rnew{$2}++;
227 }
228 }
229 }
230 close IN;
231}
232print STDERR "\n" if $debug;
233
234# Now process each library in turn.
235
236foreach $lib (keys %csrc)
237{
238 my $hfile = $hinc{$lib};
239 my $cfile = $csrc{$lib};
240 if(!$fnew{$lib} && !$rnew{$lib}) {
241 print STDERR "$lib:\t\tNo new error codes\n";
242 next unless $rebuild;
243 } else {
244 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
245 print STDERR " $rnew{$lib} New Reasons.\n";
246 next unless $dowrite;
247 }
248
249 # If we get here then we have some new error codes so we
250 # need to rebuild the header file and C file.
251
252 # Make a sorted list of error and reason codes for later use.
253
254 my @function = sort grep(/^${lib}_/,keys %fcodes);
255 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
256
257 # Rewrite the header file
258
259 if (open(IN, "<$hfile")) {
260 # Copy across the old file
261 while(<IN>) {
262 push @out, $_;
263 last if (/BEGIN ERROR CODES/);
264 }
265 close IN;
266 } else {
267 push @out,
268"/* ====================================================================\n",
269" * Copyright (c) 2001-2005 The OpenSSL Project. All rights reserved.\n",
270" *\n",
271" * Redistribution and use in source and binary forms, with or without\n",
272" * modification, are permitted provided that the following conditions\n",
273" * are met:\n",
274" *\n",
275" * 1. Redistributions of source code must retain the above copyright\n",
276" * notice, this list of conditions and the following disclaimer. \n",
277" *\n",
278" * 2. Redistributions in binary form must reproduce the above copyright\n",
279" * notice, this list of conditions and the following disclaimer in\n",
280" * the documentation and/or other materials provided with the\n",
281" * distribution.\n",
282" *\n",
283" * 3. All advertising materials mentioning features or use of this\n",
284" * software must display the following acknowledgment:\n",
285" * \"This product includes software developed by the OpenSSL Project\n",
286" * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
287" *\n",
288" * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
289" * endorse or promote products derived from this software without\n",
290" * prior written permission. For written permission, please contact\n",
291" * openssl-core\@openssl.org.\n",
292" *\n",
293" * 5. Products derived from this software may not be called \"OpenSSL\"\n",
294" * nor may \"OpenSSL\" appear in their names without prior written\n",
295" * permission of the OpenSSL Project.\n",
296" *\n",
297" * 6. Redistributions of any form whatsoever must retain the following\n",
298" * acknowledgment:\n",
299" * \"This product includes software developed by the OpenSSL Project\n",
300" * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
301" *\n",
302" * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
303" * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
304" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
305" * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
306" * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
307" * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
308" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
309" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
310" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
311" * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
312" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
313" * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
314" * ====================================================================\n",
315" *\n",
316" * This product includes cryptographic software written by Eric Young\n",
317" * (eay\@cryptsoft.com). This product includes software written by Tim\n",
318" * Hudson (tjh\@cryptsoft.com).\n",
319" *\n",
320" */\n",
321"\n",
322"#ifndef HEADER_${lib}_ERR_H\n",
323"#define HEADER_${lib}_ERR_H\n",
324"\n",
325"/* BEGIN ERROR CODES */\n";
326 }
327 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
328
329 print OUT @out;
330 undef @out;
331 print OUT <<"EOF";
332/* The following lines are auto generated by the script mkerr.pl. Any changes
333 * made after this point may be overwritten when the script is next run.
334 */
335EOF
336 if($static) {
337 print OUT <<"EOF";
338${staticloader}void ERR_load_${lib}_strings(void);
339
340EOF
341 } else {
342 print OUT <<"EOF";
343${staticloader}void ERR_load_${lib}_strings(void);
344${staticloader}void ERR_unload_${lib}_strings(void);
345${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
346#define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
347
348EOF
349 }
350 print OUT <<"EOF";
351/* Error codes for the $lib functions. */
352
353/* Function codes. */
354EOF
355
356 foreach $i (@function) {
357 $z=6-int(length($i)/8);
358 if($fcodes{$i} eq "X") {
359 $fcodes{$i} = ++$fmax{$lib};
360 print STDERR "New Function code $i\n" if $debug;
361 }
362 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
363 }
364
365 print OUT "\n/* Reason codes. */\n";
366
367 foreach $i (@reasons) {
368 $z=6-int(length($i)/8);
369 if($rcodes{$i} eq "X") {
370 $rcodes{$i} = ++$rmax{$lib};
371 print STDERR "New Reason code $i\n" if $debug;
372 }
373 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
374 }
375 print OUT <<"EOF";
376
377#ifdef __cplusplus
378}
379#endif
380#endif
381EOF
382 close OUT;
383
384 # Rewrite the C source file containing the error details.
385
386 # First, read any existing reason string definitions:
387 my %err_reason_strings;
388 if (open(IN,"<$cfile")) {
389 while (<IN>) {
390 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
391 $err_reason_strings{$1} = $2;
392 }
393 }
394 close(IN);
395 }
396
397 my $hincf;
398 if($static) {
399 $hfile =~ /([^\/]+)$/;
400 $hincf = "<openssl/$1>";
401 } else {
402 $hincf = "\"$hfile\"";
403 }
404
405 # If static we know the error code at compile time so use it
406 # in error definitions.
407
408 if ($static)
409 {
410 $pack_errcode = "ERR_LIB_${lib}";
411 $load_errcode = "0";
412 }
413 else
414 {
415 $pack_errcode = "0";
416 $load_errcode = "ERR_LIB_${lib}";
417 }
418
419
420 open (OUT,">$cfile") || die "Can't open $cfile for writing";
421
422 print OUT <<"EOF";
423/* $cfile */
424/* ====================================================================
425 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
426 *
427 * Redistribution and use in source and binary forms, with or without
428 * modification, are permitted provided that the following conditions
429 * are met:
430 *
431 * 1. Redistributions of source code must retain the above copyright
432 * notice, this list of conditions and the following disclaimer.
433 *
434 * 2. Redistributions in binary form must reproduce the above copyright
435 * notice, this list of conditions and the following disclaimer in
436 * the documentation and/or other materials provided with the
437 * distribution.
438 *
439 * 3. All advertising materials mentioning features or use of this
440 * software must display the following acknowledgment:
441 * "This product includes software developed by the OpenSSL Project
442 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
443 *
444 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
445 * endorse or promote products derived from this software without
446 * prior written permission. For written permission, please contact
447 * openssl-core\@OpenSSL.org.
448 *
449 * 5. Products derived from this software may not be called "OpenSSL"
450 * nor may "OpenSSL" appear in their names without prior written
451 * permission of the OpenSSL Project.
452 *
453 * 6. Redistributions of any form whatsoever must retain the following
454 * acknowledgment:
455 * "This product includes software developed by the OpenSSL Project
456 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
457 *
458 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
459 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
460 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
461 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
462 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
463 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
464 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
465 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
466 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
467 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
468 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
469 * OF THE POSSIBILITY OF SUCH DAMAGE.
470 * ====================================================================
471 *
472 * This product includes cryptographic software written by Eric Young
473 * (eay\@cryptsoft.com). This product includes software written by Tim
474 * Hudson (tjh\@cryptsoft.com).
475 *
476 */
477
478/* NOTE: this file was auto generated by the mkerr.pl script: any changes
479 * made to it will be overwritten when the script next updates this file,
480 * only reason strings will be preserved.
481 */
482
483#include <stdio.h>
484#include <openssl/err.h>
485#include $hincf
486
487/* BEGIN ERROR CODES */
488#ifndef OPENSSL_NO_ERR
489
490#define ERR_FUNC(func) ERR_PACK($pack_errcode,func,0)
491#define ERR_REASON(reason) ERR_PACK($pack_errcode,0,reason)
492
493static ERR_STRING_DATA ${lib}_str_functs[]=
494 {
495EOF
496 # Add each function code: if a function name is found then use it.
497 foreach $i (@function) {
498 my $fn;
499 $i =~ /^${lib}_F_(\S+)$/;
500 $fn = $1;
501 if(exists $ftrans{$fn}) {
502 $fn = $ftrans{$fn};
503 }
504# print OUT "{ERR_PACK($pack_errcode,$i,0),\t\"$fn\"},\n";
505 print OUT "{ERR_FUNC($i),\t\"$fn\"},\n";
506 }
507 print OUT <<"EOF";
508{0,NULL}
509 };
510
511static ERR_STRING_DATA ${lib}_str_reasons[]=
512 {
513EOF
514 # Add each reason code.
515 foreach $i (@reasons) {
516 my $rn;
517 my $rstr = "ERR_REASON($i)";
518 my $nspc = 0;
519 if (exists $err_reason_strings{$i}) {
520 $rn = $err_reason_strings{$i};
521 } else {
522 $i =~ /^${lib}_R_(\S+)$/;
523 $rn = $1;
524 $rn =~ tr/_[A-Z]/ [a-z]/;
525 }
526 $nspc = 40 - length($rstr) unless length($rstr) > 40;
527 $nspc = " " x $nspc;
528 print OUT "{${rstr}${nspc},\"$rn\"},\n";
529 }
530if($static) {
531 print OUT <<"EOF";
532{0,NULL}
533 };
534
535#endif
536
537${staticloader}void ERR_load_${lib}_strings(void)
538 {
539 static int init=1;
540
541 if (init)
542 {
543 init=0;
544#ifndef OPENSSL_NO_ERR
545 ERR_load_strings($load_errcode,${lib}_str_functs);
546 ERR_load_strings($load_errcode,${lib}_str_reasons);
547#endif
548
549 }
550 }
551EOF
552} else {
553 print OUT <<"EOF";
554{0,NULL}
555 };
556
557#endif
558
559#ifdef ${lib}_LIB_NAME
560static ERR_STRING_DATA ${lib}_lib_name[]=
561 {
562{0 ,${lib}_LIB_NAME},
563{0,NULL}
564 };
565#endif
566
567
568static int ${lib}_lib_error_code=0;
569static int ${lib}_error_init=1;
570
571${staticloader}void ERR_load_${lib}_strings(void)
572 {
573 if (${lib}_lib_error_code == 0)
574 ${lib}_lib_error_code=ERR_get_next_error_library();
575
576 if (${lib}_error_init)
577 {
578 ${lib}_error_init=0;
579#ifndef OPENSSL_NO_ERR
580 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
581 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
582#endif
583
584#ifdef ${lib}_LIB_NAME
585 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
586 ERR_load_strings(0,${lib}_lib_name);
587#endif
588 }
589 }
590
591${staticloader}void ERR_unload_${lib}_strings(void)
592 {
593 if (${lib}_error_init == 0)
594 {
595#ifndef OPENSSL_NO_ERR
596 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
597 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
598#endif
599
600#ifdef ${lib}_LIB_NAME
601 ERR_unload_strings(0,${lib}_lib_name);
602#endif
603 ${lib}_error_init=1;
604 }
605 }
606
607${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
608 {
609 if (${lib}_lib_error_code == 0)
610 ${lib}_lib_error_code=ERR_get_next_error_library();
611 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
612 }
613EOF
614
615}
616
617 close OUT;
618 undef %err_reason_strings;
619}
620
621if($debug && defined(%notrans)) {
622 print STDERR "The following function codes were not translated:\n";
623 foreach(sort keys %notrans)
624 {
625 print STDERR "$_\n";
626 }
627}
628
629# Make a list of unreferenced function and reason codes
630
631foreach (keys %fcodes) {
632 push (@funref, $_) unless exists $ufcodes{$_};
633}
634
635foreach (keys %rcodes) {
636 push (@runref, $_) unless exists $urcodes{$_};
637}
638
639if($debug && defined(@funref) ) {
640 print STDERR "The following function codes were not referenced:\n";
641 foreach(sort @funref)
642 {
643 print STDERR "$_\n";
644 }
645}
646
647if($debug && defined(@runref) ) {
648 print STDERR "The following reason codes were not referenced:\n";
649 foreach(sort @runref)
650 {
651 print STDERR "$_\n";
652 }
653}
diff --git a/src/lib/libcrypto/util/mkstack.pl b/src/lib/libcrypto/util/mkstack.pl
deleted file mode 100644
index 0ca9eb6a76..0000000000
--- a/src/lib/libcrypto/util/mkstack.pl
+++ /dev/null
@@ -1,125 +0,0 @@
1#!/usr/local/bin/perl -w
2
3# This is a utility that searches out "DECLARE_STACK_OF()"
4# declarations in .h and .c files, and updates/creates/replaces
5# the corresponding macro declarations in crypto/stack/safestack.h.
6# As it's not generally possible to have macros that generate macros,
7# we need to control this from the "outside", here in this script.
8#
9# Geoff Thorpe, June, 2000 (with massive Perl-hacking
10# help from Steve Robb)
11
12my $safestack = "crypto/stack/safestack";
13
14my $do_write;
15while (@ARGV) {
16 my $arg = $ARGV[0];
17 if($arg eq "-write") {
18 $do_write = 1;
19 }
20 shift @ARGV;
21}
22
23
24@source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <ssl/*.[ch]>);
25foreach $file (@source) {
26 next if -l $file;
27
28 # Open the .c/.h file for reading
29 open(IN, "< $file") || die "Can't open $file for reading: $!";
30
31 while(<IN>) {
32 if (/^DECLARE_STACK_OF\(([^)]+)\)/) {
33 push @stacklst, $1;
34 } if (/^DECLARE_ASN1_SET_OF\(([^)]+)\)/) {
35 push @asn1setlst, $1;
36 } if (/^DECLARE_PKCS12_STACK_OF\(([^)]+)\)/) {
37 push @p12stklst, $1;
38 }
39 }
40 close(IN);
41}
42
43
44
45my $old_stackfile = "";
46my $new_stackfile = "";
47my $inside_block = 0;
48my $type_thing;
49
50open(IN, "< $safestack.h") || die "Can't open input file: $!";
51while(<IN>) {
52 $old_stackfile .= $_;
53
54 if (m|^/\* This block of defines is updated by util/mkstack.pl, please do not touch! \*/|) {
55 $inside_block = 1;
56 }
57 if (m|^/\* End of util/mkstack.pl block, you may now edit :-\) \*/|) {
58 $inside_block = 0;
59 } elsif ($inside_block == 0) {
60 $new_stackfile .= $_;
61 }
62 next if($inside_block != 1);
63 $new_stackfile .= "/* This block of defines is updated by util/mkstack.pl, please do not touch! */";
64
65 foreach $type_thing (sort @stacklst) {
66 $new_stackfile .= <<EOF;
67
68#define sk_${type_thing}_new(st) SKM_sk_new($type_thing, (st))
69#define sk_${type_thing}_new_null() SKM_sk_new_null($type_thing)
70#define sk_${type_thing}_free(st) SKM_sk_free($type_thing, (st))
71#define sk_${type_thing}_num(st) SKM_sk_num($type_thing, (st))
72#define sk_${type_thing}_value(st, i) SKM_sk_value($type_thing, (st), (i))
73#define sk_${type_thing}_set(st, i, val) SKM_sk_set($type_thing, (st), (i), (val))
74#define sk_${type_thing}_zero(st) SKM_sk_zero($type_thing, (st))
75#define sk_${type_thing}_push(st, val) SKM_sk_push($type_thing, (st), (val))
76#define sk_${type_thing}_unshift(st, val) SKM_sk_unshift($type_thing, (st), (val))
77#define sk_${type_thing}_find(st, val) SKM_sk_find($type_thing, (st), (val))
78#define sk_${type_thing}_delete(st, i) SKM_sk_delete($type_thing, (st), (i))
79#define sk_${type_thing}_delete_ptr(st, ptr) SKM_sk_delete_ptr($type_thing, (st), (ptr))
80#define sk_${type_thing}_insert(st, val, i) SKM_sk_insert($type_thing, (st), (val), (i))
81#define sk_${type_thing}_set_cmp_func(st, cmp) SKM_sk_set_cmp_func($type_thing, (st), (cmp))
82#define sk_${type_thing}_dup(st) SKM_sk_dup($type_thing, st)
83#define sk_${type_thing}_pop_free(st, free_func) SKM_sk_pop_free($type_thing, (st), (free_func))
84#define sk_${type_thing}_shift(st) SKM_sk_shift($type_thing, (st))
85#define sk_${type_thing}_pop(st) SKM_sk_pop($type_thing, (st))
86#define sk_${type_thing}_sort(st) SKM_sk_sort($type_thing, (st))
87#define sk_${type_thing}_is_sorted(st) SKM_sk_is_sorted($type_thing, (st))
88EOF
89 }
90 foreach $type_thing (sort @asn1setlst) {
91 $new_stackfile .= <<EOF;
92
93#define d2i_ASN1_SET_OF_${type_thing}(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \\
94 SKM_ASN1_SET_OF_d2i($type_thing, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
95#define i2d_ASN1_SET_OF_${type_thing}(st, pp, i2d_func, ex_tag, ex_class, is_set) \\
96 SKM_ASN1_SET_OF_i2d($type_thing, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
97#define ASN1_seq_pack_${type_thing}(st, i2d_func, buf, len) \\
98 SKM_ASN1_seq_pack($type_thing, (st), (i2d_func), (buf), (len))
99#define ASN1_seq_unpack_${type_thing}(buf, len, d2i_func, free_func) \\
100 SKM_ASN1_seq_unpack($type_thing, (buf), (len), (d2i_func), (free_func))
101EOF
102 }
103 foreach $type_thing (sort @p12stklst) {
104 $new_stackfile .= <<EOF;
105
106#define PKCS12_decrypt_d2i_${type_thing}(algor, d2i_func, free_func, pass, passlen, oct, seq) \\
107 SKM_PKCS12_decrypt_d2i($type_thing, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
108EOF
109 }
110 $new_stackfile .= "/* End of util/mkstack.pl block, you may now edit :-) */\n";
111 $inside_block = 2;
112}
113
114
115if ($new_stackfile eq $old_stackfile) {
116 print "No changes to $safestack.h.\n";
117 exit 0; # avoid unnecessary rebuild
118}
119
120if ($do_write) {
121 print "Writing new $safestack.h.\n";
122 open OUT, ">$safestack.h" || die "Can't open output file";
123 print OUT $new_stackfile;
124 close OUT;
125}
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c
deleted file mode 100644
index ea689aed1a..0000000000
--- a/src/lib/libcrypto/x509/by_dir.c
+++ /dev/null
@@ -1,380 +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 = NULL;
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 dir=(char *)Getenv(X509_get_default_cert_dir_env());
127 if (dir)
128 ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
129 else
130 ret=add_cert_dir(ld,X509_get_default_cert_dir(),
131 X509_FILETYPE_PEM);
132 if (!ret)
133 {
134 X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR);
135 }
136 }
137 else
138 ret=add_cert_dir(ld,argp,(int)argl);
139 break;
140 }
141 return(ret);
142 }
143
144static int new_dir(X509_LOOKUP *lu)
145 {
146 BY_DIR *a;
147
148 if ((a=(BY_DIR *)OPENSSL_malloc(sizeof(BY_DIR))) == NULL)
149 return(0);
150 if ((a->buffer=BUF_MEM_new()) == NULL)
151 {
152 OPENSSL_free(a);
153 return(0);
154 }
155 a->num_dirs=0;
156 a->dirs=NULL;
157 a->dirs_type=NULL;
158 a->num_dirs_alloced=0;
159 lu->method_data=(char *)a;
160 return(1);
161 }
162
163static void free_dir(X509_LOOKUP *lu)
164 {
165 BY_DIR *a;
166 int i;
167
168 a=(BY_DIR *)lu->method_data;
169 for (i=0; i<a->num_dirs; i++)
170 if (a->dirs[i] != NULL) OPENSSL_free(a->dirs[i]);
171 if (a->dirs != NULL) OPENSSL_free(a->dirs);
172 if (a->dirs_type != NULL) OPENSSL_free(a->dirs_type);
173 if (a->buffer != NULL) BUF_MEM_free(a->buffer);
174 OPENSSL_free(a);
175 }
176
177static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
178 {
179 int j,len;
180 int *ip;
181 const char *s,*ss,*p;
182 char **pp;
183
184 if (dir == NULL || !*dir)
185 {
186 X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY);
187 return 0;
188 }
189
190 s=dir;
191 p=s;
192 for (;;)
193 {
194 if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0'))
195 {
196 ss=s;
197 s=p+1;
198 len=(int)(p-ss);
199 if (len == 0) continue;
200 for (j=0; j<ctx->num_dirs; j++)
201 if (strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
202 continue;
203 if (ctx->num_dirs_alloced < (ctx->num_dirs+1))
204 {
205 ctx->num_dirs_alloced+=10;
206 pp=(char **)OPENSSL_malloc(ctx->num_dirs_alloced*
207 sizeof(char *));
208 ip=(int *)OPENSSL_malloc(ctx->num_dirs_alloced*
209 sizeof(int));
210 if ((pp == NULL) || (ip == NULL))
211 {
212 X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE);
213 return(0);
214 }
215 memcpy(pp,ctx->dirs,(ctx->num_dirs_alloced-10)*
216 sizeof(char *));
217 memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)*
218 sizeof(int));
219 if (ctx->dirs != NULL)
220 OPENSSL_free(ctx->dirs);
221 if (ctx->dirs_type != NULL)
222 OPENSSL_free(ctx->dirs_type);
223 ctx->dirs=pp;
224 ctx->dirs_type=ip;
225 }
226 ctx->dirs_type[ctx->num_dirs]=type;
227 ctx->dirs[ctx->num_dirs]=(char *)OPENSSL_malloc((unsigned int)len+1);
228 if (ctx->dirs[ctx->num_dirs] == NULL) return(0);
229 strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len);
230 ctx->dirs[ctx->num_dirs][len]='\0';
231 ctx->num_dirs++;
232 }
233 if (*p == '\0') break;
234 p++;
235 }
236 return(1);
237 }
238
239static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
240 X509_OBJECT *ret)
241 {
242 BY_DIR *ctx;
243 union {
244 struct {
245 X509 st_x509;
246 X509_CINF st_x509_cinf;
247 } x509;
248 struct {
249 X509_CRL st_crl;
250 X509_CRL_INFO st_crl_info;
251 } crl;
252 } data;
253 int ok=0;
254 int i,j,k;
255 unsigned long h;
256 BUF_MEM *b=NULL;
257 struct stat st;
258 X509_OBJECT stmp,*tmp;
259 const char *postfix="";
260
261 if (name == NULL) return(0);
262
263 stmp.type=type;
264 if (type == X509_LU_X509)
265 {
266 data.x509.st_x509.cert_info= &data.x509.st_x509_cinf;
267 data.x509.st_x509_cinf.subject=name;
268 stmp.data.x509= &data.x509.st_x509;
269 postfix="";
270 }
271 else if (type == X509_LU_CRL)
272 {
273 data.crl.st_crl.crl= &data.crl.st_crl_info;
274 data.crl.st_crl_info.issuer=name;
275 stmp.data.crl= &data.crl.st_crl;
276 postfix="r";
277 }
278 else
279 {
280 X509err(X509_F_GET_CERT_BY_SUBJECT,X509_R_WRONG_LOOKUP_TYPE);
281 goto finish;
282 }
283
284 if ((b=BUF_MEM_new()) == NULL)
285 {
286 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_BUF_LIB);
287 goto finish;
288 }
289
290 ctx=(BY_DIR *)xl->method_data;
291
292 h=X509_NAME_hash(name);
293 for (i=0; i<ctx->num_dirs; i++)
294 {
295 j=strlen(ctx->dirs[i])+1+8+6+1+1;
296 if (!BUF_MEM_grow(b,j))
297 {
298 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE);
299 goto finish;
300 }
301 k=0;
302 for (;;)
303 {
304 char c = '/';
305#ifdef OPENSSL_SYS_VMS
306 c = ctx->dirs[i][strlen(ctx->dirs[i])-1];
307 if (c != ':' && c != '>' && c != ']')
308 {
309 /* If no separator is present, we assume the
310 directory specifier is a logical name, and
311 add a colon. We really should use better
312 VMS routines for merging things like this,
313 but this will do for now...
314 -- Richard Levitte */
315 c = ':';
316 }
317 else
318 {
319 c = '\0';
320 }
321#endif
322 if (c == '\0')
323 {
324 /* This is special. When c == '\0', no
325 directory separator should be added. */
326 BIO_snprintf(b->data,b->max,
327 "%s%08lx.%s%d",ctx->dirs[i],h,
328 postfix,k);
329 }
330 else
331 {
332 BIO_snprintf(b->data,b->max,
333 "%s%c%08lx.%s%d",ctx->dirs[i],c,h,
334 postfix,k);
335 }
336 k++;
337 if (stat(b->data,&st) < 0)
338 break;
339 /* found one. */
340 if (type == X509_LU_X509)
341 {
342 if ((X509_load_cert_file(xl,b->data,
343 ctx->dirs_type[i])) == 0)
344 break;
345 }
346 else if (type == X509_LU_CRL)
347 {
348 if ((X509_load_crl_file(xl,b->data,
349 ctx->dirs_type[i])) == 0)
350 break;
351 }
352 /* else case will caught higher up */
353 }
354
355 /* we have added it to the cache so now pull
356 * it out again */
357 CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE);
358 j = sk_X509_OBJECT_find(xl->store_ctx->objs,&stmp);
359 if(j != -1) tmp=sk_X509_OBJECT_value(xl->store_ctx->objs,j);
360 else tmp = NULL;
361 CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
362
363 if (tmp != NULL)
364 {
365 ok=1;
366 ret->type=tmp->type;
367 memcpy(&ret->data,&tmp->data,sizeof(ret->data));
368 /* If we were going to up the reference count,
369 * we would need to do it on a perl 'type'
370 * basis */
371 /* CRYPTO_add(&tmp->data.x509->references,1,
372 CRYPTO_LOCK_X509);*/
373 goto finish;
374 }
375 }
376finish:
377 if (b != NULL) BUF_MEM_free(b);
378 return(ok);
379 }
380
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c
deleted file mode 100644
index a5e0d4aefa..0000000000
--- a/src/lib/libcrypto/x509/by_file.c
+++ /dev/null
@@ -1,300 +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 OPENSSL_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 file = (char *)Getenv(X509_get_default_cert_file_env());
104 if (file)
105 ok = (X509_load_cert_crl_file(ctx,file,
106 X509_FILETYPE_PEM) != 0);
107
108 else
109 ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(),
110 X509_FILETYPE_PEM) != 0);
111
112 if (!ok)
113 {
114 X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS);
115 }
116 }
117 else
118 {
119 if(argl == X509_FILETYPE_PEM)
120 ok = (X509_load_cert_crl_file(ctx,argp,
121 X509_FILETYPE_PEM) != 0);
122 else
123 ok = (X509_load_cert_file(ctx,argp,(int)argl) != 0);
124 }
125 break;
126 }
127 return(ok);
128 }
129
130int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
131 {
132 int ret=0;
133 BIO *in=NULL;
134 int i,count=0;
135 X509 *x=NULL;
136
137 if (file == NULL) return(1);
138 in=BIO_new(BIO_s_file_internal());
139
140 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
141 {
142 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB);
143 goto err;
144 }
145
146 if (type == X509_FILETYPE_PEM)
147 {
148 for (;;)
149 {
150 x=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL);
151 if (x == NULL)
152 {
153 if ((ERR_GET_REASON(ERR_peek_last_error()) ==
154 PEM_R_NO_START_LINE) && (count > 0))
155 {
156 ERR_clear_error();
157 break;
158 }
159 else
160 {
161 X509err(X509_F_X509_LOAD_CERT_FILE,
162 ERR_R_PEM_LIB);
163 goto err;
164 }
165 }
166 i=X509_STORE_add_cert(ctx->store_ctx,x);
167 if (!i) goto err;
168 count++;
169 X509_free(x);
170 x=NULL;
171 }
172 ret=count;
173 }
174 else if (type == X509_FILETYPE_ASN1)
175 {
176 x=d2i_X509_bio(in,NULL);
177 if (x == NULL)
178 {
179 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB);
180 goto err;
181 }
182 i=X509_STORE_add_cert(ctx->store_ctx,x);
183 if (!i) goto err;
184 ret=i;
185 }
186 else
187 {
188 X509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE);
189 goto err;
190 }
191err:
192 if (x != NULL) X509_free(x);
193 if (in != NULL) BIO_free(in);
194 return(ret);
195 }
196
197int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
198 {
199 int ret=0;
200 BIO *in=NULL;
201 int i,count=0;
202 X509_CRL *x=NULL;
203
204 if (file == NULL) return(1);
205 in=BIO_new(BIO_s_file_internal());
206
207 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
208 {
209 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_SYS_LIB);
210 goto err;
211 }
212
213 if (type == X509_FILETYPE_PEM)
214 {
215 for (;;)
216 {
217 x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);
218 if (x == NULL)
219 {
220 if ((ERR_GET_REASON(ERR_peek_last_error()) ==
221 PEM_R_NO_START_LINE) && (count > 0))
222 {
223 ERR_clear_error();
224 break;
225 }
226 else
227 {
228 X509err(X509_F_X509_LOAD_CRL_FILE,
229 ERR_R_PEM_LIB);
230 goto err;
231 }
232 }
233 i=X509_STORE_add_crl(ctx->store_ctx,x);
234 if (!i) goto err;
235 count++;
236 X509_CRL_free(x);
237 x=NULL;
238 }
239 ret=count;
240 }
241 else if (type == X509_FILETYPE_ASN1)
242 {
243 x=d2i_X509_CRL_bio(in,NULL);
244 if (x == NULL)
245 {
246 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_ASN1_LIB);
247 goto err;
248 }
249 i=X509_STORE_add_crl(ctx->store_ctx,x);
250 if (!i) goto err;
251 ret=i;
252 }
253 else
254 {
255 X509err(X509_F_X509_LOAD_CRL_FILE,X509_R_BAD_X509_FILETYPE);
256 goto err;
257 }
258err:
259 if (x != NULL) X509_CRL_free(x);
260 if (in != NULL) BIO_free(in);
261 return(ret);
262 }
263
264int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type)
265{
266 STACK_OF(X509_INFO) *inf;
267 X509_INFO *itmp;
268 BIO *in;
269 int i, count = 0;
270 if(type != X509_FILETYPE_PEM)
271 return X509_load_cert_file(ctx, file, type);
272 in = BIO_new_file(file, "r");
273 if(!in) {
274 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_SYS_LIB);
275 return 0;
276 }
277 inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
278 BIO_free(in);
279 if(!inf) {
280 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB);
281 return 0;
282 }
283 for(i = 0; i < sk_X509_INFO_num(inf); i++) {
284 itmp = sk_X509_INFO_value(inf, i);
285 if(itmp->x509) {
286 X509_STORE_add_cert(ctx->store_ctx, itmp->x509);
287 count++;
288 }
289 if(itmp->crl) {
290 X509_STORE_add_crl(ctx->store_ctx, itmp->crl);
291 count++;
292 }
293 }
294 sk_X509_INFO_pop_free(inf, X509_INFO_free);
295 return count;
296}
297
298
299#endif /* OPENSSL_NO_STDIO */
300
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
deleted file mode 100644
index e8c1a59cf2..0000000000
--- a/src/lib/libcrypto/x509/x509.h
+++ /dev/null
@@ -1,1259 +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#include <openssl/symhacks.h>
63#ifndef OPENSSL_NO_BUFFER
64#include <openssl/buffer.h>
65#endif
66#ifndef OPENSSL_NO_EVP
67#include <openssl/evp.h>
68#endif
69#ifndef OPENSSL_NO_BIO
70#include <openssl/bio.h>
71#endif
72#include <openssl/stack.h>
73#include <openssl/asn1.h>
74#include <openssl/safestack.h>
75
76#ifndef OPENSSL_NO_RSA
77#include <openssl/rsa.h>
78#endif
79
80#ifndef OPENSSL_NO_DSA
81#include <openssl/dsa.h>
82#endif
83
84#ifndef OPENSSL_NO_DH
85#include <openssl/dh.h>
86#endif
87#ifndef OPENSSL_NO_SHA
88#include <openssl/sha.h>
89#endif
90#include <openssl/e_os2.h>
91#include <openssl/ossl_typ.h>
92
93#ifdef __cplusplus
94extern "C" {
95#endif
96
97#ifdef OPENSSL_SYS_WIN32
98/* Under Win32 this is defined in wincrypt.h */
99#undef X509_NAME
100#endif
101
102#define X509_FILETYPE_PEM 1
103#define X509_FILETYPE_ASN1 2
104#define X509_FILETYPE_DEFAULT 3
105
106#define X509v3_KU_DIGITAL_SIGNATURE 0x0080
107#define X509v3_KU_NON_REPUDIATION 0x0040
108#define X509v3_KU_KEY_ENCIPHERMENT 0x0020
109#define X509v3_KU_DATA_ENCIPHERMENT 0x0010
110#define X509v3_KU_KEY_AGREEMENT 0x0008
111#define X509v3_KU_KEY_CERT_SIGN 0x0004
112#define X509v3_KU_CRL_SIGN 0x0002
113#define X509v3_KU_ENCIPHER_ONLY 0x0001
114#define X509v3_KU_DECIPHER_ONLY 0x8000
115#define X509v3_KU_UNDEF 0xffff
116
117typedef struct X509_objects_st
118 {
119 int nid;
120 int (*a2i)();
121 int (*i2a)();
122 } X509_OBJECTS;
123
124struct X509_algor_st
125 {
126 ASN1_OBJECT *algorithm;
127 ASN1_TYPE *parameter;
128 } /* X509_ALGOR */;
129
130DECLARE_STACK_OF(X509_ALGOR)
131DECLARE_ASN1_SET_OF(X509_ALGOR)
132
133typedef struct X509_val_st
134 {
135 ASN1_TIME *notBefore;
136 ASN1_TIME *notAfter;
137 } X509_VAL;
138
139typedef struct X509_pubkey_st
140 {
141 X509_ALGOR *algor;
142 ASN1_BIT_STRING *public_key;
143 EVP_PKEY *pkey;
144 } X509_PUBKEY;
145
146typedef struct X509_sig_st
147 {
148 X509_ALGOR *algor;
149 ASN1_OCTET_STRING *digest;
150 } X509_SIG;
151
152typedef struct X509_name_entry_st
153 {
154 ASN1_OBJECT *object;
155 ASN1_STRING *value;
156 int set;
157 int size; /* temp variable */
158 } X509_NAME_ENTRY;
159
160DECLARE_STACK_OF(X509_NAME_ENTRY)
161DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)
162
163/* we always keep X509_NAMEs in 2 forms. */
164struct X509_name_st
165 {
166 STACK_OF(X509_NAME_ENTRY) *entries;
167 int modified; /* true if 'bytes' needs to be built */
168#ifndef OPENSSL_NO_BUFFER
169 BUF_MEM *bytes;
170#else
171 char *bytes;
172#endif
173 unsigned long hash; /* Keep the hash around for lookups */
174 } /* X509_NAME */;
175
176DECLARE_STACK_OF(X509_NAME)
177
178#define X509_EX_V_NETSCAPE_HACK 0x8000
179#define X509_EX_V_INIT 0x0001
180typedef struct X509_extension_st
181 {
182 ASN1_OBJECT *object;
183 ASN1_BOOLEAN critical;
184 ASN1_OCTET_STRING *value;
185 } X509_EXTENSION;
186
187DECLARE_STACK_OF(X509_EXTENSION)
188DECLARE_ASN1_SET_OF(X509_EXTENSION)
189
190/* a sequence of these are used */
191typedef struct x509_attributes_st
192 {
193 ASN1_OBJECT *object;
194 int single; /* 0 for a set, 1 for a single item (which is wrong) */
195 union {
196 char *ptr;
197/* 0 */ STACK_OF(ASN1_TYPE) *set;
198/* 1 */ ASN1_TYPE *single;
199 } value;
200 } X509_ATTRIBUTE;
201
202DECLARE_STACK_OF(X509_ATTRIBUTE)
203DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)
204
205
206typedef struct X509_req_info_st
207 {
208 ASN1_ENCODING enc;
209 ASN1_INTEGER *version;
210 X509_NAME *subject;
211 X509_PUBKEY *pubkey;
212 /* d=2 hl=2 l= 0 cons: cont: 00 */
213 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
214 } X509_REQ_INFO;
215
216typedef struct X509_req_st
217 {
218 X509_REQ_INFO *req_info;
219 X509_ALGOR *sig_alg;
220 ASN1_BIT_STRING *signature;
221 int references;
222 } X509_REQ;
223
224typedef struct x509_cinf_st
225 {
226 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
227 ASN1_INTEGER *serialNumber;
228 X509_ALGOR *signature;
229 X509_NAME *issuer;
230 X509_VAL *validity;
231 X509_NAME *subject;
232 X509_PUBKEY *key;
233 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
234 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
235 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
236 } X509_CINF;
237
238/* This stuff is certificate "auxiliary info"
239 * it contains details which are useful in certificate
240 * stores and databases. When used this is tagged onto
241 * the end of the certificate itself
242 */
243
244typedef struct x509_cert_aux_st
245 {
246 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
247 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
248 ASN1_UTF8STRING *alias; /* "friendly name" */
249 ASN1_OCTET_STRING *keyid; /* key id of private key */
250 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
251 } X509_CERT_AUX;
252
253struct x509_st
254 {
255 X509_CINF *cert_info;
256 X509_ALGOR *sig_alg;
257 ASN1_BIT_STRING *signature;
258 int valid;
259 int references;
260 char *name;
261 CRYPTO_EX_DATA ex_data;
262 /* These contain copies of various extension values */
263 long ex_pathlen;
264 unsigned long ex_flags;
265 unsigned long ex_kusage;
266 unsigned long ex_xkusage;
267 unsigned long ex_nscert;
268 ASN1_OCTET_STRING *skid;
269 struct AUTHORITY_KEYID_st *akid;
270#ifndef OPENSSL_NO_SHA
271 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
272#endif
273 X509_CERT_AUX *aux;
274 } /* X509 */;
275
276DECLARE_STACK_OF(X509)
277DECLARE_ASN1_SET_OF(X509)
278
279/* This is used for a table of trust checking functions */
280
281typedef struct x509_trust_st {
282 int trust;
283 int flags;
284 int (*check_trust)(struct x509_trust_st *, X509 *, int);
285 char *name;
286 int arg1;
287 void *arg2;
288} X509_TRUST;
289
290DECLARE_STACK_OF(X509_TRUST)
291
292/* standard trust ids */
293
294#define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */
295
296#define X509_TRUST_COMPAT 1
297#define X509_TRUST_SSL_CLIENT 2
298#define X509_TRUST_SSL_SERVER 3
299#define X509_TRUST_EMAIL 4
300#define X509_TRUST_OBJECT_SIGN 5
301#define X509_TRUST_OCSP_SIGN 6
302#define X509_TRUST_OCSP_REQUEST 7
303
304/* Keep these up to date! */
305#define X509_TRUST_MIN 1
306#define X509_TRUST_MAX 7
307
308
309/* trust_flags values */
310#define X509_TRUST_DYNAMIC 1
311#define X509_TRUST_DYNAMIC_NAME 2
312
313/* check_trust return codes */
314
315#define X509_TRUST_TRUSTED 1
316#define X509_TRUST_REJECTED 2
317#define X509_TRUST_UNTRUSTED 3
318
319/* Flags for X509_print_ex() */
320
321#define X509_FLAG_COMPAT 0
322#define X509_FLAG_NO_HEADER 1L
323#define X509_FLAG_NO_VERSION (1L << 1)
324#define X509_FLAG_NO_SERIAL (1L << 2)
325#define X509_FLAG_NO_SIGNAME (1L << 3)
326#define X509_FLAG_NO_ISSUER (1L << 4)
327#define X509_FLAG_NO_VALIDITY (1L << 5)
328#define X509_FLAG_NO_SUBJECT (1L << 6)
329#define X509_FLAG_NO_PUBKEY (1L << 7)
330#define X509_FLAG_NO_EXTENSIONS (1L << 8)
331#define X509_FLAG_NO_SIGDUMP (1L << 9)
332#define X509_FLAG_NO_AUX (1L << 10)
333#define X509_FLAG_NO_ATTRIBUTES (1L << 11)
334
335/* Flags specific to X509_NAME_print_ex() */
336
337/* The field separator information */
338
339#define XN_FLAG_SEP_MASK (0xf << 16)
340
341#define XN_FLAG_COMPAT 0 /* Traditional SSLeay: use old X509_NAME_print */
342#define XN_FLAG_SEP_COMMA_PLUS (1 << 16) /* RFC2253 ,+ */
343#define XN_FLAG_SEP_CPLUS_SPC (2 << 16) /* ,+ spaced: more readable */
344#define XN_FLAG_SEP_SPLUS_SPC (3 << 16) /* ;+ spaced */
345#define XN_FLAG_SEP_MULTILINE (4 << 16) /* One line per field */
346
347#define XN_FLAG_DN_REV (1 << 20) /* Reverse DN order */
348
349/* How the field name is shown */
350
351#define XN_FLAG_FN_MASK (0x3 << 21)
352
353#define XN_FLAG_FN_SN 0 /* Object short name */
354#define XN_FLAG_FN_LN (1 << 21) /* Object long name */
355#define XN_FLAG_FN_OID (2 << 21) /* Always use OIDs */
356#define XN_FLAG_FN_NONE (3 << 21) /* No field names */
357
358#define XN_FLAG_SPC_EQ (1 << 23) /* Put spaces round '=' */
359
360/* This determines if we dump fields we don't recognise:
361 * RFC2253 requires this.
362 */
363
364#define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24)
365
366#define XN_FLAG_FN_ALIGN (1 << 25) /* Align field names to 20 characters */
367
368/* Complete set of RFC2253 flags */
369
370#define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \
371 XN_FLAG_SEP_COMMA_PLUS | \
372 XN_FLAG_DN_REV | \
373 XN_FLAG_FN_SN | \
374 XN_FLAG_DUMP_UNKNOWN_FIELDS)
375
376/* readable oneline form */
377
378#define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \
379 ASN1_STRFLGS_ESC_QUOTE | \
380 XN_FLAG_SEP_CPLUS_SPC | \
381 XN_FLAG_SPC_EQ | \
382 XN_FLAG_FN_SN)
383
384/* readable multiline form */
385
386#define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \
387 ASN1_STRFLGS_ESC_MSB | \
388 XN_FLAG_SEP_MULTILINE | \
389 XN_FLAG_SPC_EQ | \
390 XN_FLAG_FN_LN | \
391 XN_FLAG_FN_ALIGN)
392
393typedef struct X509_revoked_st
394 {
395 ASN1_INTEGER *serialNumber;
396 ASN1_TIME *revocationDate;
397 STACK_OF(X509_EXTENSION) /* optional */ *extensions;
398 int sequence; /* load sequence */
399 } X509_REVOKED;
400
401DECLARE_STACK_OF(X509_REVOKED)
402DECLARE_ASN1_SET_OF(X509_REVOKED)
403
404typedef struct X509_crl_info_st
405 {
406 ASN1_INTEGER *version;
407 X509_ALGOR *sig_alg;
408 X509_NAME *issuer;
409 ASN1_TIME *lastUpdate;
410 ASN1_TIME *nextUpdate;
411 STACK_OF(X509_REVOKED) *revoked;
412 STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
413 ASN1_ENCODING enc;
414 } X509_CRL_INFO;
415
416struct X509_crl_st
417 {
418 /* actual signature */
419 X509_CRL_INFO *crl;
420 X509_ALGOR *sig_alg;
421 ASN1_BIT_STRING *signature;
422 int references;
423 } /* X509_CRL */;
424
425DECLARE_STACK_OF(X509_CRL)
426DECLARE_ASN1_SET_OF(X509_CRL)
427
428typedef struct private_key_st
429 {
430 int version;
431 /* The PKCS#8 data types */
432 X509_ALGOR *enc_algor;
433 ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */
434
435 /* When decrypted, the following will not be NULL */
436 EVP_PKEY *dec_pkey;
437
438 /* used to encrypt and decrypt */
439 int key_length;
440 char *key_data;
441 int key_free; /* true if we should auto free key_data */
442
443 /* expanded version of 'enc_algor' */
444 EVP_CIPHER_INFO cipher;
445
446 int references;
447 } X509_PKEY;
448
449#ifndef OPENSSL_NO_EVP
450typedef struct X509_info_st
451 {
452 X509 *x509;
453 X509_CRL *crl;
454 X509_PKEY *x_pkey;
455
456 EVP_CIPHER_INFO enc_cipher;
457 int enc_len;
458 char *enc_data;
459
460 int references;
461 } X509_INFO;
462
463DECLARE_STACK_OF(X509_INFO)
464#endif
465
466/* The next 2 structures and their 8 routines were sent to me by
467 * Pat Richard <patr@x509.com> and are used to manipulate
468 * Netscapes spki structures - useful if you are writing a CA web page
469 */
470typedef struct Netscape_spkac_st
471 {
472 X509_PUBKEY *pubkey;
473 ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */
474 } NETSCAPE_SPKAC;
475
476typedef struct Netscape_spki_st
477 {
478 NETSCAPE_SPKAC *spkac; /* signed public key and challenge */
479 X509_ALGOR *sig_algor;
480 ASN1_BIT_STRING *signature;
481 } NETSCAPE_SPKI;
482
483/* Netscape certificate sequence structure */
484typedef struct Netscape_certificate_sequence
485 {
486 ASN1_OBJECT *type;
487 STACK_OF(X509) *certs;
488 } NETSCAPE_CERT_SEQUENCE;
489
490/* Unused (and iv length is wrong)
491typedef struct CBCParameter_st
492 {
493 unsigned char iv[8];
494 } CBC_PARAM;
495*/
496
497/* Password based encryption structure */
498
499typedef struct PBEPARAM_st {
500ASN1_OCTET_STRING *salt;
501ASN1_INTEGER *iter;
502} PBEPARAM;
503
504/* Password based encryption V2 structures */
505
506typedef struct PBE2PARAM_st {
507X509_ALGOR *keyfunc;
508X509_ALGOR *encryption;
509} PBE2PARAM;
510
511typedef struct PBKDF2PARAM_st {
512ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */
513ASN1_INTEGER *iter;
514ASN1_INTEGER *keylength;
515X509_ALGOR *prf;
516} PBKDF2PARAM;
517
518
519/* PKCS#8 private key info structure */
520
521typedef struct pkcs8_priv_key_info_st
522 {
523 int broken; /* Flag for various broken formats */
524#define PKCS8_OK 0
525#define PKCS8_NO_OCTET 1
526#define PKCS8_EMBEDDED_PARAM 2
527#define PKCS8_NS_DB 3
528 ASN1_INTEGER *version;
529 X509_ALGOR *pkeyalg;
530 ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
531 STACK_OF(X509_ATTRIBUTE) *attributes;
532 } PKCS8_PRIV_KEY_INFO;
533
534#ifdef __cplusplus
535}
536#endif
537
538#include <openssl/x509_vfy.h>
539#include <openssl/pkcs7.h>
540
541#ifdef __cplusplus
542extern "C" {
543#endif
544
545#ifdef SSLEAY_MACROS
546#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
547 a->signature,(char *)a->cert_info,r)
548#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
549 a->sig_alg,a->signature,(char *)a->req_info,r)
550#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
551 a->sig_alg, a->signature,(char *)a->crl,r)
552
553#define X509_sign(x,pkey,md) \
554 ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
555 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
556#define X509_REQ_sign(x,pkey,md) \
557 ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
558 x->signature, (char *)x->req_info,pkey,md)
559#define X509_CRL_sign(x,pkey,md) \
560 ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
561 x->signature, (char *)x->crl,pkey,md)
562#define NETSCAPE_SPKI_sign(x,pkey,md) \
563 ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
564 x->signature, (char *)x->spkac,pkey,md)
565
566#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
567 (char *(*)())d2i_X509,(char *)x509)
568#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
569 (int (*)())i2d_X509_ATTRIBUTE, \
570 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
571#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
572 (int (*)())i2d_X509_EXTENSION, \
573 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
574#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
575 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
576#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
577#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
578 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
579#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
580
581#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
582 (char *(*)())d2i_X509_CRL,(char *)crl)
583#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
584 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
585 (unsigned char **)(crl))
586#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
587 (unsigned char *)crl)
588#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
589 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
590 (unsigned char **)(crl))
591#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
592 (unsigned char *)crl)
593
594#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
595 (char *(*)())d2i_PKCS7,(char *)p7)
596#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
597 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
598 (unsigned char **)(p7))
599#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
600 (unsigned char *)p7)
601#define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
602 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
603 (unsigned char **)(p7))
604#define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
605 (unsigned char *)p7)
606
607#define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
608 (char *(*)())d2i_X509_REQ,(char *)req)
609#define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
610 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
611 (unsigned char **)(req))
612#define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
613 (unsigned char *)req)
614#define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
615 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
616 (unsigned char **)(req))
617#define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
618 (unsigned char *)req)
619
620#define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
621 (char *(*)())d2i_RSAPublicKey,(char *)rsa)
622#define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
623 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
624
625#define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
626 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
627 (unsigned char **)(rsa))
628#define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
629 (unsigned char *)rsa)
630#define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
631 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
632 (unsigned char **)(rsa))
633#define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
634 (unsigned char *)rsa)
635
636#define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
637 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
638 (unsigned char **)(rsa))
639#define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
640 (unsigned char *)rsa)
641#define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
642 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
643 (unsigned char **)(rsa))
644#define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
645 (unsigned char *)rsa)
646
647#define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
648 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
649 (unsigned char **)(dsa))
650#define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
651 (unsigned char *)dsa)
652#define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
653 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
654 (unsigned char **)(dsa))
655#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
656 (unsigned char *)dsa)
657
658#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
659 (char *(*)())d2i_X509_ALGOR,(char *)xn)
660
661#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
662 (char *(*)())d2i_X509_NAME,(char *)xn)
663#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
664 (int (*)())i2d_X509_NAME_ENTRY, \
665 (char *(*)())d2i_X509_NAME_ENTRY,\
666 (char *)ne)
667
668#define X509_digest(data,type,md,len) \
669 ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
670#define X509_NAME_digest(data,type,md,len) \
671 ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
672#ifndef PKCS7_ISSUER_AND_SERIAL_digest
673#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
674 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
675 (char *)data,md,len)
676#endif
677#endif
678
679#define X509_EXT_PACK_UNKNOWN 1
680#define X509_EXT_PACK_STRING 2
681
682#define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
683/* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
684#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
685#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
686#define X509_extract_key(x) X509_get_pubkey(x) /*****/
687#define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
688#define X509_REQ_get_subject_name(x) ((x)->req_info->subject)
689#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
690#define X509_name_cmp(a,b) X509_NAME_cmp((a),(b))
691#define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
692
693#define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
694#define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
695#define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
696#define X509_CRL_get_issuer(x) ((x)->crl->issuer)
697#define X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
698
699/* This one is only used so that a binary form can output, as in
700 * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
701#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
702
703
704const char *X509_verify_cert_error_string(long n);
705
706#ifndef SSLEAY_MACROS
707#ifndef OPENSSL_NO_EVP
708int X509_verify(X509 *a, EVP_PKEY *r);
709
710int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
711int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
712int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
713
714NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len);
715char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x);
716EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x);
717int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);
718
719int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);
720
721int X509_signature_print(BIO *bp,X509_ALGOR *alg, ASN1_STRING *sig);
722
723int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
724int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
725int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
726int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
727
728int X509_pubkey_digest(const X509 *data,const EVP_MD *type,
729 unsigned char *md, unsigned int *len);
730int X509_digest(const X509 *data,const EVP_MD *type,
731 unsigned char *md, unsigned int *len);
732int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type,
733 unsigned char *md, unsigned int *len);
734int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type,
735 unsigned char *md, unsigned int *len);
736int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type,
737 unsigned char *md, unsigned int *len);
738#endif
739
740#ifndef OPENSSL_NO_FP_API
741X509 *d2i_X509_fp(FILE *fp, X509 **x509);
742int i2d_X509_fp(FILE *fp,X509 *x509);
743X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
744int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
745X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
746int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
747#ifndef OPENSSL_NO_RSA
748RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
749int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
750RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
751int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
752RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa);
753int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa);
754#endif
755#ifndef OPENSSL_NO_DSA
756DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);
757int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
758DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
759int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
760#endif
761X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
762int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
763PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
764 PKCS8_PRIV_KEY_INFO **p8inf);
765int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
766int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);
767int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
768EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
769int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey);
770EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a);
771#endif
772
773#ifndef OPENSSL_NO_BIO
774X509 *d2i_X509_bio(BIO *bp,X509 **x509);
775int i2d_X509_bio(BIO *bp,X509 *x509);
776X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
777int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
778X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
779int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
780#ifndef OPENSSL_NO_RSA
781RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
782int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
783RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
784int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
785RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);
786int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);
787#endif
788#ifndef OPENSSL_NO_DSA
789DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);
790int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
791DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
792int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
793#endif
794X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
795int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
796PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
797 PKCS8_PRIV_KEY_INFO **p8inf);
798int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
799int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);
800int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);
801EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
802int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey);
803EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a);
804#endif
805
806X509 *X509_dup(X509 *x509);
807X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
808X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
809X509_CRL *X509_CRL_dup(X509_CRL *crl);
810X509_REQ *X509_REQ_dup(X509_REQ *req);
811X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
812X509_NAME *X509_NAME_dup(X509_NAME *xn);
813X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
814
815#endif /* !SSLEAY_MACROS */
816
817int X509_cmp_time(ASN1_TIME *s, time_t *t);
818int X509_cmp_current_time(ASN1_TIME *s);
819ASN1_TIME * X509_time_adj(ASN1_TIME *s, long adj, time_t *t);
820ASN1_TIME * X509_gmtime_adj(ASN1_TIME *s, long adj);
821
822const char * X509_get_default_cert_area(void );
823const char * X509_get_default_cert_dir(void );
824const char * X509_get_default_cert_file(void );
825const char * X509_get_default_cert_dir_env(void );
826const char * X509_get_default_cert_file_env(void );
827const char * X509_get_default_private_dir(void );
828
829X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
830X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
831
832DECLARE_ASN1_FUNCTIONS(X509_ALGOR)
833DECLARE_ASN1_FUNCTIONS(X509_VAL)
834
835DECLARE_ASN1_FUNCTIONS(X509_PUBKEY)
836
837int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
838EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
839int X509_get_pubkey_parameters(EVP_PKEY *pkey,
840 STACK_OF(X509) *chain);
841int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
842EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,unsigned char **pp,
843 long length);
844#ifndef OPENSSL_NO_RSA
845int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
846RSA * d2i_RSA_PUBKEY(RSA **a,unsigned char **pp,
847 long length);
848#endif
849#ifndef OPENSSL_NO_DSA
850int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
851DSA * d2i_DSA_PUBKEY(DSA **a,unsigned char **pp,
852 long length);
853#endif
854
855DECLARE_ASN1_FUNCTIONS(X509_SIG)
856DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO)
857DECLARE_ASN1_FUNCTIONS(X509_REQ)
858
859DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE)
860X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
861
862DECLARE_ASN1_FUNCTIONS(X509_EXTENSION)
863
864DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY)
865
866DECLARE_ASN1_FUNCTIONS(X509_NAME)
867
868int X509_NAME_set(X509_NAME **xn, X509_NAME *name);
869
870DECLARE_ASN1_FUNCTIONS(X509_CINF)
871
872DECLARE_ASN1_FUNCTIONS(X509)
873DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX)
874
875int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
876 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
877int X509_set_ex_data(X509 *r, int idx, void *arg);
878void *X509_get_ex_data(X509 *r, int idx);
879int i2d_X509_AUX(X509 *a,unsigned char **pp);
880X509 * d2i_X509_AUX(X509 **a,unsigned char **pp,long length);
881
882int X509_alias_set1(X509 *x, unsigned char *name, int len);
883int X509_keyid_set1(X509 *x, unsigned char *id, int len);
884unsigned char * X509_alias_get0(X509 *x, int *len);
885int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);
886int X509_TRUST_set(int *t, int trust);
887int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
888int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj);
889void X509_trust_clear(X509 *x);
890void X509_reject_clear(X509 *x);
891
892DECLARE_ASN1_FUNCTIONS(X509_REVOKED)
893DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO)
894DECLARE_ASN1_FUNCTIONS(X509_CRL)
895
896int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
897
898X509_PKEY * X509_PKEY_new(void );
899void X509_PKEY_free(X509_PKEY *a);
900int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
901X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
902
903DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI)
904DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
905DECLARE_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE)
906
907#ifndef OPENSSL_NO_EVP
908X509_INFO * X509_INFO_new(void);
909void X509_INFO_free(X509_INFO *a);
910char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
911
912int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
913 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
914
915int ASN1_digest(int (*i2d)(),const EVP_MD *type,char *data,
916 unsigned char *md,unsigned int *len);
917
918int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
919 ASN1_BIT_STRING *signature,
920 char *data,EVP_PKEY *pkey, const EVP_MD *type);
921
922int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data,
923 unsigned char *md,unsigned int *len);
924
925int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1,
926 ASN1_BIT_STRING *signature,void *data,EVP_PKEY *pkey);
927
928int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
929 ASN1_BIT_STRING *signature,
930 void *data, EVP_PKEY *pkey, const EVP_MD *type);
931#endif
932
933int X509_set_version(X509 *x,long version);
934int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
935ASN1_INTEGER * X509_get_serialNumber(X509 *x);
936int X509_set_issuer_name(X509 *x, X509_NAME *name);
937X509_NAME * X509_get_issuer_name(X509 *a);
938int X509_set_subject_name(X509 *x, X509_NAME *name);
939X509_NAME * X509_get_subject_name(X509 *a);
940int X509_set_notBefore(X509 *x, ASN1_TIME *tm);
941int X509_set_notAfter(X509 *x, ASN1_TIME *tm);
942int X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
943EVP_PKEY * X509_get_pubkey(X509 *x);
944ASN1_BIT_STRING * X509_get0_pubkey_bitstr(const X509 *x);
945int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
946
947int X509_REQ_set_version(X509_REQ *x,long version);
948int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
949int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
950EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req);
951int X509_REQ_extension_nid(int nid);
952int * X509_REQ_get_extension_nids(void);
953void X509_REQ_set_extension_nids(int *nids);
954STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);
955int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
956 int nid);
957int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts);
958int X509_REQ_get_attr_count(const X509_REQ *req);
959int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
960 int lastpos);
961int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
962 int lastpos);
963X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
964X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
965int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
966int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
967 const ASN1_OBJECT *obj, int type,
968 const unsigned char *bytes, int len);
969int X509_REQ_add1_attr_by_NID(X509_REQ *req,
970 int nid, int type,
971 const unsigned char *bytes, int len);
972int X509_REQ_add1_attr_by_txt(X509_REQ *req,
973 const char *attrname, int type,
974 const unsigned char *bytes, int len);
975
976int X509_CRL_set_version(X509_CRL *x, long version);
977int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name);
978int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm);
979int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm);
980int X509_CRL_sort(X509_CRL *crl);
981
982int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);
983int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm);
984
985int X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
986
987int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
988unsigned long X509_issuer_and_serial_hash(X509 *a);
989
990int X509_issuer_name_cmp(const X509 *a, const X509 *b);
991unsigned long X509_issuer_name_hash(X509 *a);
992
993int X509_subject_name_cmp(const X509 *a, const X509 *b);
994unsigned long X509_subject_name_hash(X509 *x);
995
996int X509_cmp(const X509 *a, const X509 *b);
997int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
998unsigned long X509_NAME_hash(X509_NAME *x);
999
1000int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
1001#ifndef OPENSSL_NO_FP_API
1002int X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
1003int X509_print_fp(FILE *bp,X509 *x);
1004int X509_CRL_print_fp(FILE *bp,X509_CRL *x);
1005int X509_REQ_print_fp(FILE *bp,X509_REQ *req);
1006int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags);
1007#endif
1008
1009#ifndef OPENSSL_NO_BIO
1010int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
1011int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags);
1012int X509_print_ex(BIO *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
1013int X509_print(BIO *bp,X509 *x);
1014int X509_ocspid_print(BIO *bp,X509 *x);
1015int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent);
1016int X509_CRL_print(BIO *bp,X509_CRL *x);
1017int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag);
1018int X509_REQ_print(BIO *bp,X509_REQ *req);
1019#endif
1020
1021int X509_NAME_entry_count(X509_NAME *name);
1022int X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
1023 char *buf,int len);
1024int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
1025 char *buf,int len);
1026
1027/* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use
1028 * lastpos, search after that position on. */
1029int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
1030int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
1031 int lastpos);
1032X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
1033X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
1034int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
1035 int loc, int set);
1036int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
1037 unsigned char *bytes, int len, int loc, int set);
1038int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
1039 unsigned char *bytes, int len, int loc, int set);
1040X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
1041 const char *field, int type, const unsigned char *bytes, int len);
1042X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
1043 int type,unsigned char *bytes, int len);
1044int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,
1045 const unsigned char *bytes, int len, int loc, int set);
1046X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
1047 ASN1_OBJECT *obj, int type,const unsigned char *bytes,
1048 int len);
1049int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
1050 ASN1_OBJECT *obj);
1051int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
1052 const unsigned char *bytes, int len);
1053ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
1054ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
1055
1056int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
1057int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
1058 int nid, int lastpos);
1059int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
1060 ASN1_OBJECT *obj,int lastpos);
1061int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
1062 int crit, int lastpos);
1063X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
1064X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
1065STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
1066 X509_EXTENSION *ex, int loc);
1067
1068int X509_get_ext_count(X509 *x);
1069int X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
1070int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
1071int X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
1072X509_EXTENSION *X509_get_ext(X509 *x, int loc);
1073X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
1074int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
1075void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
1076int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
1077 unsigned long flags);
1078
1079int X509_CRL_get_ext_count(X509_CRL *x);
1080int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
1081int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
1082int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
1083X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
1084X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
1085int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
1086void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
1087int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit,
1088 unsigned long flags);
1089
1090int X509_REVOKED_get_ext_count(X509_REVOKED *x);
1091int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
1092int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
1093int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
1094X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
1095X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
1096int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
1097void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
1098int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit,
1099 unsigned long flags);
1100
1101X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
1102 int nid, int crit, ASN1_OCTET_STRING *data);
1103X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
1104 ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
1105int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
1106int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
1107int X509_EXTENSION_set_data(X509_EXTENSION *ex,
1108 ASN1_OCTET_STRING *data);
1109ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex);
1110ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
1111int X509_EXTENSION_get_critical(X509_EXTENSION *ex);
1112
1113int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
1114int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
1115 int lastpos);
1116int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
1117 int lastpos);
1118X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
1119X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
1120STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
1121 X509_ATTRIBUTE *attr);
1122STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
1123 const ASN1_OBJECT *obj, int type,
1124 const unsigned char *bytes, int len);
1125STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
1126 int nid, int type,
1127 const unsigned char *bytes, int len);
1128STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
1129 const char *attrname, int type,
1130 const unsigned char *bytes, int len);
1131X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
1132 int atrtype, const void *data, int len);
1133X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
1134 const ASN1_OBJECT *obj, int atrtype, const void *data, int len);
1135X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
1136 const char *atrname, int type, const unsigned char *bytes, int len);
1137int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj);
1138int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len);
1139void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
1140 int atrtype, void *data);
1141int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
1142ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
1143ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
1144
1145int X509_verify_cert(X509_STORE_CTX *ctx);
1146
1147/* lookup a cert from a X509 STACK */
1148X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
1149 ASN1_INTEGER *serial);
1150X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
1151
1152DECLARE_ASN1_FUNCTIONS(PBEPARAM)
1153DECLARE_ASN1_FUNCTIONS(PBE2PARAM)
1154DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM)
1155
1156X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
1157X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
1158 unsigned char *salt, int saltlen);
1159
1160/* PKCS#8 utilities */
1161
1162DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
1163
1164EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
1165PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
1166PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken);
1167PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
1168
1169int X509_check_trust(X509 *x, int id, int flags);
1170int X509_TRUST_get_count(void);
1171X509_TRUST * X509_TRUST_get0(int idx);
1172int X509_TRUST_get_by_id(int id);
1173int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
1174 char *name, int arg1, void *arg2);
1175void X509_TRUST_cleanup(void);
1176int X509_TRUST_get_flags(X509_TRUST *xp);
1177char *X509_TRUST_get0_name(X509_TRUST *xp);
1178int X509_TRUST_get_trust(X509_TRUST *xp);
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 */
1184void ERR_load_X509_strings(void);
1185
1186/* Error codes for the X509 functions. */
1187
1188/* Function codes. */
1189#define X509_F_ADD_CERT_DIR 100
1190#define X509_F_BY_FILE_CTRL 101
1191#define X509_F_DIR_CTRL 102
1192#define X509_F_GET_CERT_BY_SUBJECT 103
1193#define X509_F_NETSCAPE_SPKI_B64_DECODE 129
1194#define X509_F_NETSCAPE_SPKI_B64_ENCODE 130
1195#define X509_F_X509V3_ADD_EXT 104
1196#define X509_F_X509_ADD_ATTR 135
1197#define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136
1198#define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137
1199#define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140
1200#define X509_F_X509_ATTRIBUTE_GET0_DATA 139
1201#define X509_F_X509_ATTRIBUTE_SET1_DATA 138
1202#define X509_F_X509_CHECK_PRIVATE_KEY 128
1203#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
1204#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
1205#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
1206#define X509_F_X509_LOAD_CERT_CRL_FILE 132
1207#define X509_F_X509_LOAD_CERT_FILE 111
1208#define X509_F_X509_LOAD_CRL_FILE 112
1209#define X509_F_X509_NAME_ADD_ENTRY 113
1210#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114
1211#define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131
1212#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
1213#define X509_F_X509_NAME_ONELINE 116
1214#define X509_F_X509_NAME_PRINT 117
1215#define X509_F_X509_PRINT_FP 118
1216#define X509_F_X509_PUBKEY_GET 119
1217#define X509_F_X509_PUBKEY_SET 120
1218#define X509_F_X509_REQ_PRINT 121
1219#define X509_F_X509_REQ_PRINT_FP 122
1220#define X509_F_X509_REQ_TO_X509 123
1221#define X509_F_X509_STORE_ADD_CERT 124
1222#define X509_F_X509_STORE_ADD_CRL 125
1223#define X509_F_X509_STORE_CTX_INIT 143
1224#define X509_F_X509_STORE_CTX_NEW 142
1225#define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134
1226#define X509_F_X509_TO_X509_REQ 126
1227#define X509_F_X509_TRUST_ADD 133
1228#define X509_F_X509_TRUST_SET 141
1229#define X509_F_X509_VERIFY_CERT 127
1230
1231/* Reason codes. */
1232#define X509_R_BAD_X509_FILETYPE 100
1233#define X509_R_BASE64_DECODE_ERROR 118
1234#define X509_R_CANT_CHECK_DH_KEY 114
1235#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
1236#define X509_R_ERR_ASN1_LIB 102
1237#define X509_R_INVALID_DIRECTORY 113
1238#define X509_R_INVALID_FIELD_NAME 119
1239#define X509_R_INVALID_TRUST 123
1240#define X509_R_KEY_TYPE_MISMATCH 115
1241#define X509_R_KEY_VALUES_MISMATCH 116
1242#define X509_R_LOADING_CERT_DIR 103
1243#define X509_R_LOADING_DEFAULTS 104
1244#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105
1245#define X509_R_SHOULD_RETRY 106
1246#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107
1247#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
1248#define X509_R_UNKNOWN_KEY_TYPE 117
1249#define X509_R_UNKNOWN_NID 109
1250#define X509_R_UNKNOWN_PURPOSE_ID 121
1251#define X509_R_UNKNOWN_TRUST_ID 120
1252#define X509_R_UNSUPPORTED_ALGORITHM 111
1253#define X509_R_WRONG_LOOKUP_TYPE 112
1254#define X509_R_WRONG_TYPE 122
1255
1256#ifdef __cplusplus
1257}
1258#endif
1259#endif
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c
deleted file mode 100644
index 0bae3d32a1..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 const ASN1_OBJECT *obj, int type,
153 const 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 const 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 const char *attrname, int type,
179 const 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, const 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 const ASN1_OBJECT *obj, int atrtype, const 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 const char *atrname, int type, const 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, const 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, const 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->single = 0;
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->single) 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->single) 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 030d0966fc..0000000000
--- a/src/lib/libcrypto/x509/x509_cmp.c
+++ /dev/null
@@ -1,440 +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 <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b)
68 {
69 int i;
70 X509_CINF *ai,*bi;
71
72 ai=a->cert_info;
73 bi=b->cert_info;
74 i=M_ASN1_INTEGER_cmp(ai->serialNumber,bi->serialNumber);
75 if (i) return(i);
76 return(X509_NAME_cmp(ai->issuer,bi->issuer));
77 }
78
79#ifndef OPENSSL_NO_MD5
80unsigned long X509_issuer_and_serial_hash(X509 *a)
81 {
82 unsigned long ret=0;
83 EVP_MD_CTX ctx;
84 unsigned char md[16];
85 char *f;
86
87 EVP_MD_CTX_init(&ctx);
88 f=X509_NAME_oneline(a->cert_info->issuer,NULL,0);
89 ret=strlen(f);
90 EVP_DigestInit_ex(&ctx, EVP_md5(), NULL);
91 EVP_DigestUpdate(&ctx,(unsigned char *)f,ret);
92 OPENSSL_free(f);
93 EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data,
94 (unsigned long)a->cert_info->serialNumber->length);
95 EVP_DigestFinal_ex(&ctx,&(md[0]),NULL);
96 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
97 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
98 )&0xffffffffL;
99 EVP_MD_CTX_cleanup(&ctx);
100 return(ret);
101 }
102#endif
103
104int X509_issuer_name_cmp(const X509 *a, const X509 *b)
105 {
106 return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer));
107 }
108
109int X509_subject_name_cmp(const X509 *a, const X509 *b)
110 {
111 return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject));
112 }
113
114int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b)
115 {
116 return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer));
117 }
118
119X509_NAME *X509_get_issuer_name(X509 *a)
120 {
121 return(a->cert_info->issuer);
122 }
123
124unsigned long X509_issuer_name_hash(X509 *x)
125 {
126 return(X509_NAME_hash(x->cert_info->issuer));
127 }
128
129X509_NAME *X509_get_subject_name(X509 *a)
130 {
131 return(a->cert_info->subject);
132 }
133
134ASN1_INTEGER *X509_get_serialNumber(X509 *a)
135 {
136 return(a->cert_info->serialNumber);
137 }
138
139unsigned long X509_subject_name_hash(X509 *x)
140 {
141 return(X509_NAME_hash(x->cert_info->subject));
142 }
143
144#ifndef OPENSSL_NO_SHA
145/* Compare two certificates: they must be identical for
146 * this to work. NB: Although "cmp" operations are generally
147 * prototyped to take "const" arguments (eg. for use in
148 * STACKs), the way X509 handling is - these operations may
149 * involve ensuring the hashes are up-to-date and ensuring
150 * certain cert information is cached. So this is the point
151 * where the "depth-first" constification tree has to halt
152 * with an evil cast.
153 */
154int X509_cmp(const X509 *a, const X509 *b)
155{
156 /* ensure hash is valid */
157 X509_check_purpose((X509 *)a, -1, 0);
158 X509_check_purpose((X509 *)b, -1, 0);
159
160 return memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH);
161}
162#endif
163
164
165/* Case insensitive string comparision */
166static int nocase_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
167{
168 int i;
169
170 if (a->length != b->length)
171 return (a->length - b->length);
172
173 for (i=0; i<a->length; i++)
174 {
175 int ca, cb;
176
177 ca = tolower(a->data[i]);
178 cb = tolower(b->data[i]);
179
180 if (ca != cb)
181 return(ca-cb);
182 }
183 return 0;
184}
185
186/* Case insensitive string comparision with space normalization
187 * Space normalization - ignore leading, trailing spaces,
188 * multiple spaces between characters are replaced by single space
189 */
190static int nocase_spacenorm_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
191{
192 unsigned char *pa = NULL, *pb = NULL;
193 int la, lb;
194
195 la = a->length;
196 lb = b->length;
197 pa = a->data;
198 pb = b->data;
199
200 /* skip leading spaces */
201 while (la > 0 && isspace(*pa))
202 {
203 la--;
204 pa++;
205 }
206 while (lb > 0 && isspace(*pb))
207 {
208 lb--;
209 pb++;
210 }
211
212 /* skip trailing spaces */
213 while (la > 0 && isspace(pa[la-1]))
214 la--;
215 while (lb > 0 && isspace(pb[lb-1]))
216 lb--;
217
218 /* compare strings with space normalization */
219 while (la > 0 && lb > 0)
220 {
221 int ca, cb;
222
223 /* compare character */
224 ca = tolower(*pa);
225 cb = tolower(*pb);
226 if (ca != cb)
227 return (ca - cb);
228
229 pa++; pb++;
230 la--; lb--;
231
232 if (la <= 0 || lb <= 0)
233 break;
234
235 /* is white space next character ? */
236 if (isspace(*pa) && isspace(*pb))
237 {
238 /* skip remaining white spaces */
239 while (la > 0 && isspace(*pa))
240 {
241 la--;
242 pa++;
243 }
244 while (lb > 0 && isspace(*pb))
245 {
246 lb--;
247 pb++;
248 }
249 }
250 }
251 if (la > 0 || lb > 0)
252 return la - lb;
253
254 return 0;
255}
256
257static int asn1_string_memcmp(ASN1_STRING *a, ASN1_STRING *b)
258 {
259 int j;
260 j = a->length - b->length;
261 if (j)
262 return j;
263 return memcmp(a->data, b->data, a->length);
264 }
265
266#define STR_TYPE_CMP (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_UTF8STRING)
267
268int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b)
269 {
270 int i,j;
271 X509_NAME_ENTRY *na,*nb;
272
273 unsigned long nabit, nbbit;
274
275 j = sk_X509_NAME_ENTRY_num(a->entries)
276 - sk_X509_NAME_ENTRY_num(b->entries);
277 if (j)
278 return j;
279 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
280 {
281 na=sk_X509_NAME_ENTRY_value(a->entries,i);
282 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
283 j=na->value->type-nb->value->type;
284 if (j)
285 {
286 nabit = ASN1_tag2bit(na->value->type);
287 nbbit = ASN1_tag2bit(nb->value->type);
288 if (!(nabit & STR_TYPE_CMP) ||
289 !(nbbit & STR_TYPE_CMP))
290 return j;
291 j = asn1_string_memcmp(na->value, nb->value);
292 }
293 else if (na->value->type == V_ASN1_PRINTABLESTRING)
294 j=nocase_spacenorm_cmp(na->value, nb->value);
295 else if (na->value->type == V_ASN1_IA5STRING
296 && OBJ_obj2nid(na->object) == NID_pkcs9_emailAddress)
297 j=nocase_cmp(na->value, nb->value);
298 else
299 j = asn1_string_memcmp(na->value, nb->value);
300 if (j) return(j);
301 j=na->set-nb->set;
302 if (j) return(j);
303 }
304
305 /* We will check the object types after checking the values
306 * since the values will more often be different than the object
307 * types. */
308 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
309 {
310 na=sk_X509_NAME_ENTRY_value(a->entries,i);
311 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
312 j=OBJ_cmp(na->object,nb->object);
313 if (j) return(j);
314 }
315 return(0);
316 }
317
318#ifndef OPENSSL_NO_MD5
319/* I now DER encode the name and hash it. Since I cache the DER encoding,
320 * this is reasonably efficient. */
321unsigned long X509_NAME_hash(X509_NAME *x)
322 {
323 unsigned long ret=0;
324 unsigned char md[16];
325 EVP_MD_CTX md_ctx;
326
327 /* Make sure X509_NAME structure contains valid cached encoding */
328 i2d_X509_NAME(x,NULL);
329 EVP_MD_CTX_init(&md_ctx);
330 EVP_MD_CTX_set_flags(&md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
331 EVP_DigestInit_ex(&md_ctx, EVP_md5(), NULL);
332 EVP_DigestUpdate(&md_ctx, x->bytes->data, x->bytes->length);
333 EVP_DigestFinal_ex(&md_ctx,md,NULL);
334 EVP_MD_CTX_cleanup(&md_ctx);
335
336 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
337 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
338 )&0xffffffffL;
339 return(ret);
340 }
341#endif
342
343/* Search a stack of X509 for a match */
344X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name,
345 ASN1_INTEGER *serial)
346 {
347 int i;
348 X509_CINF cinf;
349 X509 x,*x509=NULL;
350
351 if(!sk) return NULL;
352
353 x.cert_info= &cinf;
354 cinf.serialNumber=serial;
355 cinf.issuer=name;
356
357 for (i=0; i<sk_X509_num(sk); i++)
358 {
359 x509=sk_X509_value(sk,i);
360 if (X509_issuer_and_serial_cmp(x509,&x) == 0)
361 return(x509);
362 }
363 return(NULL);
364 }
365
366X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name)
367 {
368 X509 *x509;
369 int i;
370
371 for (i=0; i<sk_X509_num(sk); i++)
372 {
373 x509=sk_X509_value(sk,i);
374 if (X509_NAME_cmp(X509_get_subject_name(x509),name) == 0)
375 return(x509);
376 }
377 return(NULL);
378 }
379
380EVP_PKEY *X509_get_pubkey(X509 *x)
381 {
382 if ((x == NULL) || (x->cert_info == NULL))
383 return(NULL);
384 return(X509_PUBKEY_get(x->cert_info->key));
385 }
386
387ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x)
388 {
389 if(!x) return NULL;
390 return x->cert_info->key->public_key;
391 }
392
393int X509_check_private_key(X509 *x, EVP_PKEY *k)
394 {
395 EVP_PKEY *xk=NULL;
396 int ok=0;
397
398 xk=X509_get_pubkey(x);
399 if (xk->type != k->type)
400 {
401 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);
402 goto err;
403 }
404 switch (k->type)
405 {
406#ifndef OPENSSL_NO_RSA
407 case EVP_PKEY_RSA:
408 if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0
409 || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)
410 {
411 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
412 goto err;
413 }
414 break;
415#endif
416#ifndef OPENSSL_NO_DSA
417 case EVP_PKEY_DSA:
418 if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)
419 {
420 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
421 goto err;
422 }
423 break;
424#endif
425#ifndef OPENSSL_NO_DH
426 case EVP_PKEY_DH:
427 /* No idea */
428 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);
429 goto err;
430#endif
431 default:
432 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);
433 goto err;
434 }
435
436 ok=1;
437err:
438 EVP_PKEY_free(xk);
439 return(ok);
440 }
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c
deleted file mode 100644
index 51410cfd1a..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 OPENSSL_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 d44d046027..0000000000
--- a/src/lib/libcrypto/x509/x509_err.c
+++ /dev/null
@@ -1,160 +0,0 @@
1/* crypto/x509/x509_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509,0,reason)
70
71static ERR_STRING_DATA X509_str_functs[]=
72 {
73{ERR_FUNC(X509_F_ADD_CERT_DIR), "ADD_CERT_DIR"},
74{ERR_FUNC(X509_F_BY_FILE_CTRL), "BY_FILE_CTRL"},
75{ERR_FUNC(X509_F_DIR_CTRL), "DIR_CTRL"},
76{ERR_FUNC(X509_F_GET_CERT_BY_SUBJECT), "GET_CERT_BY_SUBJECT"},
77{ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_DECODE), "NETSCAPE_SPKI_b64_decode"},
78{ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_ENCODE), "NETSCAPE_SPKI_b64_encode"},
79{ERR_FUNC(X509_F_X509V3_ADD_EXT), "X509v3_add_ext"},
80{ERR_FUNC(X509_F_X509_ADD_ATTR), "X509_ADD_ATTR"},
81{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_NID), "X509_ATTRIBUTE_create_by_NID"},
82{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ), "X509_ATTRIBUTE_create_by_OBJ"},
83{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT), "X509_ATTRIBUTE_create_by_txt"},
84{ERR_FUNC(X509_F_X509_ATTRIBUTE_GET0_DATA), "X509_ATTRIBUTE_get0_data"},
85{ERR_FUNC(X509_F_X509_ATTRIBUTE_SET1_DATA), "X509_ATTRIBUTE_set1_data"},
86{ERR_FUNC(X509_F_X509_CHECK_PRIVATE_KEY), "X509_check_private_key"},
87{ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_NID), "X509_EXTENSION_create_by_NID"},
88{ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_OBJ), "X509_EXTENSION_create_by_OBJ"},
89{ERR_FUNC(X509_F_X509_GET_PUBKEY_PARAMETERS), "X509_get_pubkey_parameters"},
90{ERR_FUNC(X509_F_X509_LOAD_CERT_CRL_FILE), "X509_load_cert_crl_file"},
91{ERR_FUNC(X509_F_X509_LOAD_CERT_FILE), "X509_load_cert_file"},
92{ERR_FUNC(X509_F_X509_LOAD_CRL_FILE), "X509_load_crl_file"},
93{ERR_FUNC(X509_F_X509_NAME_ADD_ENTRY), "X509_NAME_add_entry"},
94{ERR_FUNC(X509_F_X509_NAME_ENTRY_CREATE_BY_NID), "X509_NAME_ENTRY_create_by_NID"},
95{ERR_FUNC(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT), "X509_NAME_ENTRY_create_by_txt"},
96{ERR_FUNC(X509_F_X509_NAME_ENTRY_SET_OBJECT), "X509_NAME_ENTRY_set_object"},
97{ERR_FUNC(X509_F_X509_NAME_ONELINE), "X509_NAME_oneline"},
98{ERR_FUNC(X509_F_X509_NAME_PRINT), "X509_NAME_print"},
99{ERR_FUNC(X509_F_X509_PRINT_FP), "X509_print_fp"},
100{ERR_FUNC(X509_F_X509_PUBKEY_GET), "X509_PUBKEY_get"},
101{ERR_FUNC(X509_F_X509_PUBKEY_SET), "X509_PUBKEY_set"},
102{ERR_FUNC(X509_F_X509_REQ_PRINT), "X509_REQ_print"},
103{ERR_FUNC(X509_F_X509_REQ_PRINT_FP), "X509_REQ_print_fp"},
104{ERR_FUNC(X509_F_X509_REQ_TO_X509), "X509_REQ_to_X509"},
105{ERR_FUNC(X509_F_X509_STORE_ADD_CERT), "X509_STORE_add_cert"},
106{ERR_FUNC(X509_F_X509_STORE_ADD_CRL), "X509_STORE_add_crl"},
107{ERR_FUNC(X509_F_X509_STORE_CTX_INIT), "X509_STORE_CTX_init"},
108{ERR_FUNC(X509_F_X509_STORE_CTX_NEW), "X509_STORE_CTX_new"},
109{ERR_FUNC(X509_F_X509_STORE_CTX_PURPOSE_INHERIT), "X509_STORE_CTX_purpose_inherit"},
110{ERR_FUNC(X509_F_X509_TO_X509_REQ), "X509_to_X509_REQ"},
111{ERR_FUNC(X509_F_X509_TRUST_ADD), "X509_TRUST_add"},
112{ERR_FUNC(X509_F_X509_TRUST_SET), "X509_TRUST_set"},
113{ERR_FUNC(X509_F_X509_VERIFY_CERT), "X509_verify_cert"},
114{0,NULL}
115 };
116
117static ERR_STRING_DATA X509_str_reasons[]=
118 {
119{ERR_REASON(X509_R_BAD_X509_FILETYPE) ,"bad x509 filetype"},
120{ERR_REASON(X509_R_BASE64_DECODE_ERROR) ,"base64 decode error"},
121{ERR_REASON(X509_R_CANT_CHECK_DH_KEY) ,"cant check dh key"},
122{ERR_REASON(X509_R_CERT_ALREADY_IN_HASH_TABLE),"cert already in hash table"},
123{ERR_REASON(X509_R_ERR_ASN1_LIB) ,"err asn1 lib"},
124{ERR_REASON(X509_R_INVALID_DIRECTORY) ,"invalid directory"},
125{ERR_REASON(X509_R_INVALID_FIELD_NAME) ,"invalid field name"},
126{ERR_REASON(X509_R_INVALID_TRUST) ,"invalid trust"},
127{ERR_REASON(X509_R_KEY_TYPE_MISMATCH) ,"key type mismatch"},
128{ERR_REASON(X509_R_KEY_VALUES_MISMATCH) ,"key values mismatch"},
129{ERR_REASON(X509_R_LOADING_CERT_DIR) ,"loading cert dir"},
130{ERR_REASON(X509_R_LOADING_DEFAULTS) ,"loading defaults"},
131{ERR_REASON(X509_R_NO_CERT_SET_FOR_US_TO_VERIFY),"no cert set for us to verify"},
132{ERR_REASON(X509_R_SHOULD_RETRY) ,"should retry"},
133{ERR_REASON(X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN),"unable to find parameters in chain"},
134{ERR_REASON(X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY),"unable to get certs public key"},
135{ERR_REASON(X509_R_UNKNOWN_KEY_TYPE) ,"unknown key type"},
136{ERR_REASON(X509_R_UNKNOWN_NID) ,"unknown nid"},
137{ERR_REASON(X509_R_UNKNOWN_PURPOSE_ID) ,"unknown purpose id"},
138{ERR_REASON(X509_R_UNKNOWN_TRUST_ID) ,"unknown trust id"},
139{ERR_REASON(X509_R_UNSUPPORTED_ALGORITHM),"unsupported algorithm"},
140{ERR_REASON(X509_R_WRONG_LOOKUP_TYPE) ,"wrong lookup type"},
141{ERR_REASON(X509_R_WRONG_TYPE) ,"wrong type"},
142{0,NULL}
143 };
144
145#endif
146
147void ERR_load_X509_strings(void)
148 {
149 static int init=1;
150
151 if (init)
152 {
153 init=0;
154#ifndef OPENSSL_NO_ERR
155 ERR_load_strings(0,X509_str_functs);
156 ERR_load_strings(0,X509_str_reasons);
157#endif
158
159 }
160 }
diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c
deleted file mode 100644
index e7fdacb5e4..0000000000
--- a/src/lib/libcrypto/x509/x509_ext.c
+++ /dev/null
@@ -1,210 +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_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit,
105 unsigned long flags)
106{
107 return X509V3_add1_i2d(&x->crl->extensions, nid, value, crit, flags);
108}
109
110int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc)
111 {
112 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL);
113 }
114
115int X509_get_ext_count(X509 *x)
116 {
117 return(X509v3_get_ext_count(x->cert_info->extensions));
118 }
119
120int X509_get_ext_by_NID(X509 *x, int nid, int lastpos)
121 {
122 return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos));
123 }
124
125int X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos)
126 {
127 return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos));
128 }
129
130int X509_get_ext_by_critical(X509 *x, int crit, int lastpos)
131 {
132 return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos));
133 }
134
135X509_EXTENSION *X509_get_ext(X509 *x, int loc)
136 {
137 return(X509v3_get_ext(x->cert_info->extensions,loc));
138 }
139
140X509_EXTENSION *X509_delete_ext(X509 *x, int loc)
141 {
142 return(X509v3_delete_ext(x->cert_info->extensions,loc));
143 }
144
145int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
146 {
147 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL);
148 }
149
150void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)
151{
152 return X509V3_get_d2i(x->cert_info->extensions, nid, crit, idx);
153}
154
155int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
156 unsigned long flags)
157{
158 return X509V3_add1_i2d(&x->cert_info->extensions, nid, value, crit,
159 flags);
160}
161
162int X509_REVOKED_get_ext_count(X509_REVOKED *x)
163 {
164 return(X509v3_get_ext_count(x->extensions));
165 }
166
167int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos)
168 {
169 return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos));
170 }
171
172int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x, ASN1_OBJECT *obj,
173 int lastpos)
174 {
175 return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos));
176 }
177
178int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos)
179 {
180 return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos));
181 }
182
183X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc)
184 {
185 return(X509v3_get_ext(x->extensions,loc));
186 }
187
188X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc)
189 {
190 return(X509v3_delete_ext(x->extensions,loc));
191 }
192
193int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc)
194 {
195 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL);
196 }
197
198void *X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx)
199{
200 return X509V3_get_d2i(x->extensions, nid, crit, idx);
201}
202
203int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit,
204 unsigned long flags)
205{
206 return X509V3_add1_i2d(&x->extensions, nid, value, crit, flags);
207}
208
209IMPLEMENT_STACK_OF(X509_EXTENSION)
210IMPLEMENT_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 b780dae5e2..0000000000
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ /dev/null
@@ -1,557 +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#include <openssl/x509v3.h>
64
65X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method)
66 {
67 X509_LOOKUP *ret;
68
69 ret=(X509_LOOKUP *)OPENSSL_malloc(sizeof(X509_LOOKUP));
70 if (ret == NULL) return NULL;
71
72 ret->init=0;
73 ret->skip=0;
74 ret->method=method;
75 ret->method_data=NULL;
76 ret->store_ctx=NULL;
77 if ((method->new_item != NULL) && !method->new_item(ret))
78 {
79 OPENSSL_free(ret);
80 return NULL;
81 }
82 return ret;
83 }
84
85void X509_LOOKUP_free(X509_LOOKUP *ctx)
86 {
87 if (ctx == NULL) return;
88 if ( (ctx->method != NULL) &&
89 (ctx->method->free != NULL))
90 ctx->method->free(ctx);
91 OPENSSL_free(ctx);
92 }
93
94int X509_LOOKUP_init(X509_LOOKUP *ctx)
95 {
96 if (ctx->method == NULL) return 0;
97 if (ctx->method->init != NULL)
98 return ctx->method->init(ctx);
99 else
100 return 1;
101 }
102
103int X509_LOOKUP_shutdown(X509_LOOKUP *ctx)
104 {
105 if (ctx->method == NULL) return 0;
106 if (ctx->method->shutdown != NULL)
107 return ctx->method->shutdown(ctx);
108 else
109 return 1;
110 }
111
112int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
113 char **ret)
114 {
115 if (ctx->method == NULL) return -1;
116 if (ctx->method->ctrl != NULL)
117 return ctx->method->ctrl(ctx,cmd,argc,argl,ret);
118 else
119 return 1;
120 }
121
122int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
123 X509_OBJECT *ret)
124 {
125 if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL))
126 return X509_LU_FAIL;
127 if (ctx->skip) return 0;
128 return ctx->method->get_by_subject(ctx,type,name,ret);
129 }
130
131int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
132 ASN1_INTEGER *serial, X509_OBJECT *ret)
133 {
134 if ((ctx->method == NULL) ||
135 (ctx->method->get_by_issuer_serial == NULL))
136 return X509_LU_FAIL;
137 return ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret);
138 }
139
140int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
141 unsigned char *bytes, int len, X509_OBJECT *ret)
142 {
143 if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL))
144 return X509_LU_FAIL;
145 return ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret);
146 }
147
148int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len,
149 X509_OBJECT *ret)
150 {
151 if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL))
152 return X509_LU_FAIL;
153 return ctx->method->get_by_alias(ctx,type,str,len,ret);
154 }
155
156
157static int x509_object_cmp(const X509_OBJECT * const *a, const X509_OBJECT * const *b)
158 {
159 int ret;
160
161 ret=((*a)->type - (*b)->type);
162 if (ret) return ret;
163 switch ((*a)->type)
164 {
165 case X509_LU_X509:
166 ret=X509_subject_name_cmp((*a)->data.x509,(*b)->data.x509);
167 break;
168 case X509_LU_CRL:
169 ret=X509_CRL_cmp((*a)->data.crl,(*b)->data.crl);
170 break;
171 default:
172 /* abort(); */
173 return 0;
174 }
175 return ret;
176 }
177
178X509_STORE *X509_STORE_new(void)
179 {
180 X509_STORE *ret;
181
182 if ((ret=(X509_STORE *)OPENSSL_malloc(sizeof(X509_STORE))) == NULL)
183 return NULL;
184 ret->objs = sk_X509_OBJECT_new(x509_object_cmp);
185 ret->cache=1;
186 ret->get_cert_methods=sk_X509_LOOKUP_new_null();
187 ret->verify=0;
188 ret->verify_cb=0;
189
190 ret->purpose = 0;
191 ret->trust = 0;
192
193 ret->flags = 0;
194
195 ret->get_issuer = 0;
196 ret->check_issued = 0;
197 ret->check_revocation = 0;
198 ret->get_crl = 0;
199 ret->check_crl = 0;
200 ret->cert_crl = 0;
201 ret->cleanup = 0;
202
203 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data);
204 ret->references=1;
205 ret->depth=0;
206 return ret;
207 }
208
209static void cleanup(X509_OBJECT *a)
210 {
211 if (a->type == X509_LU_X509)
212 {
213 X509_free(a->data.x509);
214 }
215 else if (a->type == X509_LU_CRL)
216 {
217 X509_CRL_free(a->data.crl);
218 }
219 else
220 {
221 /* abort(); */
222 }
223
224 OPENSSL_free(a);
225 }
226
227void X509_STORE_free(X509_STORE *vfy)
228 {
229 int i;
230 STACK_OF(X509_LOOKUP) *sk;
231 X509_LOOKUP *lu;
232
233 if (vfy == NULL)
234 return;
235
236 sk=vfy->get_cert_methods;
237 for (i=0; i<sk_X509_LOOKUP_num(sk); i++)
238 {
239 lu=sk_X509_LOOKUP_value(sk,i);
240 X509_LOOKUP_shutdown(lu);
241 X509_LOOKUP_free(lu);
242 }
243 sk_X509_LOOKUP_free(sk);
244 sk_X509_OBJECT_pop_free(vfy->objs, cleanup);
245
246 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, vfy, &vfy->ex_data);
247 OPENSSL_free(vfy);
248 }
249
250X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m)
251 {
252 int i;
253 STACK_OF(X509_LOOKUP) *sk;
254 X509_LOOKUP *lu;
255
256 sk=v->get_cert_methods;
257 for (i=0; i<sk_X509_LOOKUP_num(sk); i++)
258 {
259 lu=sk_X509_LOOKUP_value(sk,i);
260 if (m == lu->method)
261 {
262 return lu;
263 }
264 }
265 /* a new one */
266 lu=X509_LOOKUP_new(m);
267 if (lu == NULL)
268 return NULL;
269 else
270 {
271 lu->store_ctx=v;
272 if (sk_X509_LOOKUP_push(v->get_cert_methods,lu))
273 return lu;
274 else
275 {
276 X509_LOOKUP_free(lu);
277 return NULL;
278 }
279 }
280 }
281
282int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
283 X509_OBJECT *ret)
284 {
285 X509_STORE *ctx=vs->ctx;
286 X509_LOOKUP *lu;
287 X509_OBJECT stmp,*tmp;
288 int i,j;
289
290 tmp=X509_OBJECT_retrieve_by_subject(ctx->objs,type,name);
291
292 if (tmp == NULL)
293 {
294 for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++)
295 {
296 lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i);
297 j=X509_LOOKUP_by_subject(lu,type,name,&stmp);
298 if (j < 0)
299 {
300 vs->current_method=j;
301 return j;
302 }
303 else if (j)
304 {
305 tmp= &stmp;
306 break;
307 }
308 }
309 vs->current_method=0;
310 if (tmp == NULL)
311 return 0;
312 }
313
314/* if (ret->data.ptr != NULL)
315 X509_OBJECT_free_contents(ret); */
316
317 ret->type=tmp->type;
318 ret->data.ptr=tmp->data.ptr;
319
320 X509_OBJECT_up_ref_count(ret);
321
322 return 1;
323 }
324
325int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
326 {
327 X509_OBJECT *obj;
328 int ret=1;
329
330 if (x == NULL) return 0;
331 obj=(X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));
332 if (obj == NULL)
333 {
334 X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);
335 return 0;
336 }
337 obj->type=X509_LU_X509;
338 obj->data.x509=x;
339
340 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
341
342 X509_OBJECT_up_ref_count(obj);
343
344
345 if (X509_OBJECT_retrieve_match(ctx->objs, obj))
346 {
347 X509_OBJECT_free_contents(obj);
348 OPENSSL_free(obj);
349 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);
350 ret=0;
351 }
352 else sk_X509_OBJECT_push(ctx->objs, obj);
353
354 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
355
356 return ret;
357 }
358
359int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
360 {
361 X509_OBJECT *obj;
362 int ret=1;
363
364 if (x == NULL) return 0;
365 obj=(X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));
366 if (obj == NULL)
367 {
368 X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE);
369 return 0;
370 }
371 obj->type=X509_LU_CRL;
372 obj->data.crl=x;
373
374 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
375
376 X509_OBJECT_up_ref_count(obj);
377
378 if (X509_OBJECT_retrieve_match(ctx->objs, obj))
379 {
380 X509_OBJECT_free_contents(obj);
381 OPENSSL_free(obj);
382 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE);
383 ret=0;
384 }
385 else sk_X509_OBJECT_push(ctx->objs, obj);
386
387 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
388
389 return ret;
390 }
391
392void X509_OBJECT_up_ref_count(X509_OBJECT *a)
393 {
394 switch (a->type)
395 {
396 case X509_LU_X509:
397 CRYPTO_add(&a->data.x509->references,1,CRYPTO_LOCK_X509);
398 break;
399 case X509_LU_CRL:
400 CRYPTO_add(&a->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
401 break;
402 }
403 }
404
405void X509_OBJECT_free_contents(X509_OBJECT *a)
406 {
407 switch (a->type)
408 {
409 case X509_LU_X509:
410 X509_free(a->data.x509);
411 break;
412 case X509_LU_CRL:
413 X509_CRL_free(a->data.crl);
414 break;
415 }
416 }
417
418int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
419 X509_NAME *name)
420 {
421 X509_OBJECT stmp;
422 X509 x509_s;
423 X509_CINF cinf_s;
424 X509_CRL crl_s;
425 X509_CRL_INFO crl_info_s;
426
427 stmp.type=type;
428 switch (type)
429 {
430 case X509_LU_X509:
431 stmp.data.x509= &x509_s;
432 x509_s.cert_info= &cinf_s;
433 cinf_s.subject=name;
434 break;
435 case X509_LU_CRL:
436 stmp.data.crl= &crl_s;
437 crl_s.crl= &crl_info_s;
438 crl_info_s.issuer=name;
439 break;
440 default:
441 /* abort(); */
442 return -1;
443 }
444
445 return sk_X509_OBJECT_find(h,&stmp);
446 }
447
448X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type,
449 X509_NAME *name)
450{
451 int idx;
452 idx = X509_OBJECT_idx_by_subject(h, type, name);
453 if (idx==-1) return NULL;
454 return sk_X509_OBJECT_value(h, idx);
455}
456
457X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x)
458{
459 int idx, i;
460 X509_OBJECT *obj;
461 idx = sk_X509_OBJECT_find(h, x);
462 if (idx == -1) return NULL;
463 if (x->type != X509_LU_X509) return sk_X509_OBJECT_value(h, idx);
464 for (i = idx; i < sk_X509_OBJECT_num(h); i++)
465 {
466 obj = sk_X509_OBJECT_value(h, i);
467 if (x509_object_cmp((const X509_OBJECT **)&obj, (const X509_OBJECT **)&x))
468 return NULL;
469 if ((x->type != X509_LU_X509) || !X509_cmp(obj->data.x509, x->data.x509))
470 return obj;
471 }
472 return NULL;
473}
474
475
476/* Try to get issuer certificate from store. Due to limitations
477 * of the API this can only retrieve a single certificate matching
478 * a given subject name. However it will fill the cache with all
479 * matching certificates, so we can examine the cache for all
480 * matches.
481 *
482 * Return values are:
483 * 1 lookup successful.
484 * 0 certificate not found.
485 * -1 some other error.
486 */
487
488
489int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
490{
491 X509_NAME *xn;
492 X509_OBJECT obj, *pobj;
493 int i, ok, idx;
494 xn=X509_get_issuer_name(x);
495 ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);
496 if (ok != X509_LU_X509)
497 {
498 if (ok == X509_LU_RETRY)
499 {
500 X509_OBJECT_free_contents(&obj);
501 X509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);
502 return -1;
503 }
504 else if (ok != X509_LU_FAIL)
505 {
506 X509_OBJECT_free_contents(&obj);
507 /* not good :-(, break anyway */
508 return -1;
509 }
510 return 0;
511 }
512 /* If certificate matches all OK */
513 if (ctx->check_issued(ctx, x, obj.data.x509))
514 {
515 *issuer = obj.data.x509;
516 return 1;
517 }
518 X509_OBJECT_free_contents(&obj);
519 /* Else find index of first matching cert */
520 idx = X509_OBJECT_idx_by_subject(ctx->ctx->objs, X509_LU_X509, xn);
521 /* This shouldn't normally happen since we already have one match */
522 if (idx == -1) return 0;
523
524 /* Look through all matching certificates for a suitable issuer */
525 for (i = idx; i < sk_X509_OBJECT_num(ctx->ctx->objs); i++)
526 {
527 pobj = sk_X509_OBJECT_value(ctx->ctx->objs, i);
528 /* See if we've ran out of matches */
529 if (pobj->type != X509_LU_X509) return 0;
530 if (X509_NAME_cmp(xn, X509_get_subject_name(pobj->data.x509))) return 0;
531 if (ctx->check_issued(ctx, x, pobj->data.x509))
532 {
533 *issuer = pobj->data.x509;
534 X509_OBJECT_up_ref_count(pobj);
535 return 1;
536 }
537 }
538 return 0;
539}
540
541void X509_STORE_set_flags(X509_STORE *ctx, long flags)
542 {
543 ctx->flags |= flags;
544 }
545
546int X509_STORE_set_purpose(X509_STORE *ctx, int purpose)
547 {
548 return X509_PURPOSE_set(&ctx->purpose, purpose);
549 }
550
551int X509_STORE_set_trust(X509_STORE *ctx, int trust)
552 {
553 return X509_TRUST_set(&ctx->trust, trust);
554 }
555
556IMPLEMENT_STACK_OF(X509_LOOKUP)
557IMPLEMENT_STACK_OF(X509_OBJECT)
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c
deleted file mode 100644
index 1e718f76eb..0000000000
--- a/src/lib/libcrypto/x509/x509_obj.c
+++ /dev/null
@@ -1,226 +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 OPENSSL_free(b);
95 }
96 strncpy(buf,"NO X509_NAME",len);
97 buf[len-1]='\0';
98 return buf;
99 }
100
101 len--; /* space for '\0' */
102 l=0;
103 for (i=0; i<sk_X509_NAME_ENTRY_num(a->entries); i++)
104 {
105 ne=sk_X509_NAME_ENTRY_value(a->entries,i);
106 n=OBJ_obj2nid(ne->object);
107 if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL))
108 {
109 i2t_ASN1_OBJECT(tmp_buf,sizeof(tmp_buf),ne->object);
110 s=tmp_buf;
111 }
112 l1=strlen(s);
113
114 type=ne->value->type;
115 num=ne->value->length;
116 q=ne->value->data;
117#ifdef CHARSET_EBCDIC
118 if (type == V_ASN1_GENERALSTRING ||
119 type == V_ASN1_VISIBLESTRING ||
120 type == V_ASN1_PRINTABLESTRING ||
121 type == V_ASN1_TELETEXSTRING ||
122 type == V_ASN1_VISIBLESTRING ||
123 type == V_ASN1_IA5STRING) {
124 ascii2ebcdic(ebcdic_buf, q,
125 (num > sizeof ebcdic_buf)
126 ? sizeof ebcdic_buf : num);
127 q=ebcdic_buf;
128 }
129#endif
130
131 if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0))
132 {
133 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=0;
134 for (j=0; j<num; j++)
135 if (q[j] != 0) gs_doit[j&3]=1;
136
137 if (gs_doit[0]|gs_doit[1]|gs_doit[2])
138 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;
139 else
140 {
141 gs_doit[0]=gs_doit[1]=gs_doit[2]=0;
142 gs_doit[3]=1;
143 }
144 }
145 else
146 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;
147
148 for (l2=j=0; j<num; j++)
149 {
150 if (!gs_doit[j&3]) continue;
151 l2++;
152#ifndef CHARSET_EBCDIC
153 if ((q[j] < ' ') || (q[j] > '~')) l2+=3;
154#else
155 if ((os_toascii[q[j]] < os_toascii[' ']) ||
156 (os_toascii[q[j]] > os_toascii['~'])) l2+=3;
157#endif
158 }
159
160 lold=l;
161 l+=1+l1+1+l2;
162 if (b != NULL)
163 {
164 if (!BUF_MEM_grow(b,l+1)) goto err;
165 p= &(b->data[lold]);
166 }
167 else if (l > len)
168 {
169 break;
170 }
171 else
172 p= &(buf[lold]);
173 *(p++)='/';
174 memcpy(p,s,(unsigned int)l1); p+=l1;
175 *(p++)='=';
176
177#ifndef CHARSET_EBCDIC /* q was assigned above already. */
178 q=ne->value->data;
179#endif
180
181 for (j=0; j<num; j++)
182 {
183 if (!gs_doit[j&3]) continue;
184#ifndef CHARSET_EBCDIC
185 n=q[j];
186 if ((n < ' ') || (n > '~'))
187 {
188 *(p++)='\\';
189 *(p++)='x';
190 *(p++)=hex[(n>>4)&0x0f];
191 *(p++)=hex[n&0x0f];
192 }
193 else
194 *(p++)=n;
195#else
196 n=os_toascii[q[j]];
197 if ((n < os_toascii[' ']) ||
198 (n > os_toascii['~']))
199 {
200 *(p++)='\\';
201 *(p++)='x';
202 *(p++)=hex[(n>>4)&0x0f];
203 *(p++)=hex[n&0x0f];
204 }
205 else
206 *(p++)=q[j];
207#endif
208 }
209 *p='\0';
210 }
211 if (b != NULL)
212 {
213 p=b->data;
214 OPENSSL_free(b);
215 }
216 else
217 p=buf;
218 if (i == 0)
219 *p = '\0';
220 return(p);
221err:
222 X509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE);
223 if (b != NULL) BUF_MEM_free(b);
224 return(NULL);
225 }
226
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c
deleted file mode 100644
index fb8a78dabe..0000000000
--- a/src/lib/libcrypto/x509/x509_r2x.c
+++ /dev/null
@@ -1,112 +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 if (X509_gmtime_adj(xi->validity->notBefore,0) == NULL)
96 goto err;
97 if (X509_gmtime_adj(xi->validity->notAfter,(long)60*60*24*days) == NULL)
98 goto err;
99
100 X509_set_pubkey(ret,X509_REQ_get_pubkey(r));
101
102 if (!X509_sign(ret,pkey,EVP_md5()))
103 goto err;
104 if (0)
105 {
106err:
107 X509_free(ret);
108 ret=NULL;
109 }
110 return(ret);
111 }
112
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
deleted file mode 100644
index 59fc6ca548..0000000000
--- a/src/lib/libcrypto/x509/x509_req.c
+++ /dev/null
@@ -1,279 +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 *)OPENSSL_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_ext_req, NID_ms_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 ASN1_TYPE *ext = NULL;
149 int idx, *pnid;
150 unsigned char *p;
151
152 if ((req == NULL) || (req->req_info == NULL) || !ext_nids)
153 return(NULL);
154 for (pnid = ext_nids; *pnid != NID_undef; pnid++)
155 {
156 idx = X509_REQ_get_attr_by_NID(req, *pnid, -1);
157 if (idx == -1)
158 continue;
159 attr = X509_REQ_get_attr(req, idx);
160 if(attr->single) ext = attr->value.single;
161 else if(sk_ASN1_TYPE_num(attr->value.set))
162 ext = sk_ASN1_TYPE_value(attr->value.set, 0);
163 break;
164 }
165 if(!ext || (ext->type != V_ASN1_SEQUENCE))
166 return NULL;
167 p = ext->value.sequence->data;
168 return d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p,
169 ext->value.sequence->length,
170 d2i_X509_EXTENSION, X509_EXTENSION_free,
171 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
172 }
173
174/* Add a STACK_OF extensions to a certificate request: allow alternative OIDs
175 * in case we want to create a non standard one.
176 */
177
178int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
179 int nid)
180{
181 unsigned char *p = NULL, *q;
182 long len;
183 ASN1_TYPE *at = NULL;
184 X509_ATTRIBUTE *attr = NULL;
185 if(!(at = ASN1_TYPE_new()) ||
186 !(at->value.sequence = ASN1_STRING_new())) goto err;
187
188 at->type = V_ASN1_SEQUENCE;
189 /* Generate encoding of extensions */
190 len = i2d_ASN1_SET_OF_X509_EXTENSION(exts, NULL, i2d_X509_EXTENSION,
191 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
192 if(!(p = OPENSSL_malloc(len))) goto err;
193 q = p;
194 i2d_ASN1_SET_OF_X509_EXTENSION(exts, &q, i2d_X509_EXTENSION,
195 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
196 at->value.sequence->data = p;
197 p = NULL;
198 at->value.sequence->length = len;
199 if(!(attr = X509_ATTRIBUTE_new())) goto err;
200 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
201 if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err;
202 at = NULL;
203 attr->single = 0;
204 attr->object = OBJ_nid2obj(nid);
205 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err;
206 return 1;
207 err:
208 if(p) OPENSSL_free(p);
209 X509_ATTRIBUTE_free(attr);
210 ASN1_TYPE_free(at);
211 return 0;
212}
213/* This is the normal usage: use the "official" OID */
214int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts)
215{
216 return X509_REQ_add_extensions_nid(req, exts, NID_ext_req);
217}
218
219/* Request attribute functions */
220
221int X509_REQ_get_attr_count(const X509_REQ *req)
222{
223 return X509at_get_attr_count(req->req_info->attributes);
224}
225
226int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
227 int lastpos)
228{
229 return X509at_get_attr_by_NID(req->req_info->attributes, nid, lastpos);
230}
231
232int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
233 int lastpos)
234{
235 return X509at_get_attr_by_OBJ(req->req_info->attributes, obj, lastpos);
236}
237
238X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc)
239{
240 return X509at_get_attr(req->req_info->attributes, loc);
241}
242
243X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc)
244{
245 return X509at_delete_attr(req->req_info->attributes, loc);
246}
247
248int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr)
249{
250 if(X509at_add1_attr(&req->req_info->attributes, attr)) return 1;
251 return 0;
252}
253
254int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
255 const ASN1_OBJECT *obj, int type,
256 const unsigned char *bytes, int len)
257{
258 if(X509at_add1_attr_by_OBJ(&req->req_info->attributes, obj,
259 type, bytes, len)) return 1;
260 return 0;
261}
262
263int X509_REQ_add1_attr_by_NID(X509_REQ *req,
264 int nid, int type,
265 const unsigned char *bytes, int len)
266{
267 if(X509at_add1_attr_by_NID(&req->req_info->attributes, nid,
268 type, bytes, len)) return 1;
269 return 0;
270}
271
272int X509_REQ_add1_attr_by_txt(X509_REQ *req,
273 const char *attrname, int type,
274 const unsigned char *bytes, int len)
275{
276 if(X509at_add1_attr_by_txt(&req->req_info->attributes, attrname,
277 type, bytes, len)) return 1;
278 return 0;
279}
diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c
deleted file mode 100644
index aaf61ca062..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_TIME *tm)
108 {
109 ASN1_TIME *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_TIME_dup(tm);
116 if (in != NULL)
117 {
118 M_ASN1_TIME_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_TIME *tm)
126 {
127 ASN1_TIME *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_TIME_dup(tm);
134 if (in != NULL)
135 {
136 M_ASN1_TIME_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 881252608d..0000000000
--- a/src/lib/libcrypto/x509/x509_trs.c
+++ /dev/null
@@ -1,287 +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(const X509_TRUST * const *a,
65 const X509_TRUST * const *b);
66static void trtable_free(X509_TRUST *p);
67
68static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags);
69static int trust_1oid(X509_TRUST *trust, X509 *x, int flags);
70static int trust_compat(X509_TRUST *trust, X509 *x, int flags);
71
72static int obj_trust(int id, X509 *x, int flags);
73static int (*default_trust)(int id, X509 *x, int flags) = obj_trust;
74
75/* WARNING: the following table should be kept in order of trust
76 * and without any gaps so we can just subtract the minimum trust
77 * value to get an index into the table
78 */
79
80static X509_TRUST trstandard[] = {
81{X509_TRUST_COMPAT, 0, trust_compat, "compatible", 0, NULL},
82{X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL},
83{X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Server", NID_server_auth, NULL},
84{X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL},
85{X509_TRUST_OBJECT_SIGN, 0, trust_1oidany, "Object Signer", NID_code_sign, NULL},
86{X509_TRUST_OCSP_SIGN, 0, trust_1oid, "OCSP responder", NID_OCSP_sign, NULL},
87{X509_TRUST_OCSP_REQUEST, 0, trust_1oid, "OCSP request", NID_ad_OCSP, NULL}
88};
89
90#define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST))
91
92IMPLEMENT_STACK_OF(X509_TRUST)
93
94static STACK_OF(X509_TRUST) *trtable = NULL;
95
96static int tr_cmp(const X509_TRUST * const *a,
97 const X509_TRUST * const *b)
98{
99 return (*a)->trust - (*b)->trust;
100}
101
102int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int)
103{
104 int (*oldtrust)(int , X509 *, int);
105 oldtrust = default_trust;
106 default_trust = trust;
107 return oldtrust;
108}
109
110
111int X509_check_trust(X509 *x, int id, int flags)
112{
113 X509_TRUST *pt;
114 int idx;
115 if(id == -1) return 1;
116 idx = X509_TRUST_get_by_id(id);
117 if(idx == -1) return default_trust(id, x, flags);
118 pt = X509_TRUST_get0(idx);
119 return pt->check_trust(pt, x, flags);
120}
121
122int X509_TRUST_get_count(void)
123{
124 if(!trtable) return X509_TRUST_COUNT;
125 return sk_X509_TRUST_num(trtable) + X509_TRUST_COUNT;
126}
127
128X509_TRUST * X509_TRUST_get0(int idx)
129{
130 if(idx < 0) return NULL;
131 if(idx < X509_TRUST_COUNT) return trstandard + idx;
132 return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
133}
134
135int X509_TRUST_get_by_id(int id)
136{
137 X509_TRUST tmp;
138 int idx;
139 if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
140 return id - X509_TRUST_MIN;
141 tmp.trust = id;
142 if(!trtable) return -1;
143 idx = sk_X509_TRUST_find(trtable, &tmp);
144 if(idx == -1) return -1;
145 return idx + X509_TRUST_COUNT;
146}
147
148int X509_TRUST_set(int *t, int trust)
149{
150 if(X509_TRUST_get_by_id(trust) == -1) {
151 X509err(X509_F_X509_TRUST_SET, X509_R_INVALID_TRUST);
152 return 0;
153 }
154 *t = trust;
155 return 1;
156}
157
158int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
159 char *name, int arg1, void *arg2)
160{
161 int idx;
162 X509_TRUST *trtmp;
163 /* This is set according to what we change: application can't set it */
164 flags &= ~X509_TRUST_DYNAMIC;
165 /* This will always be set for application modified trust entries */
166 flags |= X509_TRUST_DYNAMIC_NAME;
167 /* Get existing entry if any */
168 idx = X509_TRUST_get_by_id(id);
169 /* Need a new entry */
170 if(idx == -1) {
171 if(!(trtmp = OPENSSL_malloc(sizeof(X509_TRUST)))) {
172 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
173 return 0;
174 }
175 trtmp->flags = X509_TRUST_DYNAMIC;
176 } else trtmp = X509_TRUST_get0(idx);
177
178 /* OPENSSL_free existing name if dynamic */
179 if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_free(trtmp->name);
180 /* dup supplied name */
181 if(!(trtmp->name = BUF_strdup(name))) {
182 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
183 return 0;
184 }
185 /* Keep the dynamic flag of existing entry */
186 trtmp->flags &= X509_TRUST_DYNAMIC;
187 /* Set all other flags */
188 trtmp->flags |= flags;
189
190 trtmp->trust = id;
191 trtmp->check_trust = ck;
192 trtmp->arg1 = arg1;
193 trtmp->arg2 = arg2;
194
195 /* If its a new entry manage the dynamic table */
196 if(idx == -1) {
197 if(!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) {
198 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
199 return 0;
200 }
201 if (!sk_X509_TRUST_push(trtable, trtmp)) {
202 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
203 return 0;
204 }
205 }
206 return 1;
207}
208
209static void trtable_free(X509_TRUST *p)
210 {
211 if(!p) return;
212 if (p->flags & X509_TRUST_DYNAMIC)
213 {
214 if (p->flags & X509_TRUST_DYNAMIC_NAME)
215 OPENSSL_free(p->name);
216 OPENSSL_free(p);
217 }
218 }
219
220void X509_TRUST_cleanup(void)
221{
222 int i;
223 for(i = 0; i < X509_TRUST_COUNT; i++) trtable_free(trstandard + i);
224 sk_X509_TRUST_pop_free(trtable, trtable_free);
225 trtable = NULL;
226}
227
228int X509_TRUST_get_flags(X509_TRUST *xp)
229{
230 return xp->flags;
231}
232
233char *X509_TRUST_get0_name(X509_TRUST *xp)
234{
235 return xp->name;
236}
237
238int X509_TRUST_get_trust(X509_TRUST *xp)
239{
240 return xp->trust;
241}
242
243static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags)
244{
245 if(x->aux && (x->aux->trust || x->aux->reject))
246 return obj_trust(trust->arg1, x, flags);
247 /* we don't have any trust settings: for compatibility
248 * we return trusted if it is self signed
249 */
250 return trust_compat(trust, x, flags);
251}
252
253static int trust_1oid(X509_TRUST *trust, X509 *x, int flags)
254{
255 if(x->aux) return obj_trust(trust->arg1, x, flags);
256 return X509_TRUST_UNTRUSTED;
257}
258
259static int trust_compat(X509_TRUST *trust, X509 *x, int flags)
260{
261 X509_check_purpose(x, -1, 0);
262 if(x->ex_flags & EXFLAG_SS) return X509_TRUST_TRUSTED;
263 else return X509_TRUST_UNTRUSTED;
264}
265
266static int obj_trust(int id, X509 *x, int flags)
267{
268 ASN1_OBJECT *obj;
269 int i;
270 X509_CERT_AUX *ax;
271 ax = x->aux;
272 if(!ax) return X509_TRUST_UNTRUSTED;
273 if(ax->reject) {
274 for(i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) {
275 obj = sk_ASN1_OBJECT_value(ax->reject, i);
276 if(OBJ_obj2nid(obj) == id) return X509_TRUST_REJECTED;
277 }
278 }
279 if(ax->trust) {
280 for(i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) {
281 obj = sk_ASN1_OBJECT_value(ax->trust, i);
282 if(OBJ_obj2nid(obj) == id) return X509_TRUST_TRUSTED;
283 }
284 }
285 return X509_TRUST_UNTRUSTED;
286}
287
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c
deleted file mode 100644
index f19e66a238..0000000000
--- a/src/lib/libcrypto/x509/x509_txt.c
+++ /dev/null
@@ -1,165 +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 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_INVALID_NON_CA:
126 return ("invalid non-CA certificate (has CA markings)");
127 case X509_V_ERR_PATH_LENGTH_EXCEEDED:
128 return ("path length constraint exceeded");
129 case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED:
130 return("proxy path length constraint exceeded");
131 case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED:
132 return("proxy cerificates not allowed, please set the appropriate flag");
133 case X509_V_ERR_INVALID_PURPOSE:
134 return ("unsupported certificate purpose");
135 case X509_V_ERR_CERT_UNTRUSTED:
136 return ("certificate not trusted");
137 case X509_V_ERR_CERT_REJECTED:
138 return ("certificate rejected");
139 case X509_V_ERR_APPLICATION_VERIFICATION:
140 return("application verification failure");
141 case X509_V_ERR_SUBJECT_ISSUER_MISMATCH:
142 return("subject issuer mismatch");
143 case X509_V_ERR_AKID_SKID_MISMATCH:
144 return("authority and subject key identifier mismatch");
145 case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH:
146 return("authority and issuer serial number mismatch");
147 case X509_V_ERR_KEYUSAGE_NO_CERTSIGN:
148 return("key usage does not include certificate signing");
149 case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
150 return("unable to get CRL issuer certificate");
151 case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
152 return("unhandled critical extension");
153 case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN:
154 return("key usage does not include CRL signing");
155 case X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE:
156 return("key usage does not include digital signature");
157 case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION:
158 return("unhandled critical CRL extension");
159 default:
160 BIO_snprintf(buf,sizeof buf,"error number %ld",n);
161 return(buf);
162 }
163 }
164
165
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
deleted file mode 100644
index 67b1796a92..0000000000
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ /dev/null
@@ -1,268 +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 > 0) && crit) ||
119 ((ex->critical <= 0) && !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:-1;
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 if(ex->critical > 0) return 1;
267 return 0;
268 }
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
deleted file mode 100644
index 383e082aba..0000000000
--- a/src/lib/libcrypto/x509/x509_vfy.c
+++ /dev/null
@@ -1,1333 +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_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
75static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x);
76static int check_chain_extensions(X509_STORE_CTX *ctx);
77static int check_trust(X509_STORE_CTX *ctx);
78static int check_revocation(X509_STORE_CTX *ctx);
79static int check_cert(X509_STORE_CTX *ctx);
80static int internal_verify(X509_STORE_CTX *ctx);
81const char *X509_version="X.509" OPENSSL_VERSION_PTEXT;
82
83
84static int null_callback(int ok, X509_STORE_CTX *e)
85 {
86 return ok;
87 }
88
89#if 0
90static int x509_subject_cmp(X509 **a, X509 **b)
91 {
92 return X509_subject_name_cmp(*a,*b);
93 }
94#endif
95
96int X509_verify_cert(X509_STORE_CTX *ctx)
97 {
98 X509 *x,*xtmp,*chain_ss=NULL;
99 X509_NAME *xn;
100 int depth,i,ok=0;
101 int num;
102 int (*cb)();
103 STACK_OF(X509) *sktmp=NULL;
104
105 if (ctx->cert == NULL)
106 {
107 X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
108 return -1;
109 }
110
111 cb=ctx->verify_cb;
112
113 /* first we make sure the chain we are going to build is
114 * present and that the first entry is in place */
115 if (ctx->chain == NULL)
116 {
117 if ( ((ctx->chain=sk_X509_new_null()) == NULL) ||
118 (!sk_X509_push(ctx->chain,ctx->cert)))
119 {
120 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
121 goto end;
122 }
123 CRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);
124 ctx->last_untrusted=1;
125 }
126
127 /* We use a temporary STACK so we can chop and hack at it */
128 if (ctx->untrusted != NULL
129 && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
130 {
131 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
132 goto end;
133 }
134
135 num=sk_X509_num(ctx->chain);
136 x=sk_X509_value(ctx->chain,num-1);
137 depth=ctx->depth;
138
139
140 for (;;)
141 {
142 /* If we have enough, we break */
143 if (depth < num) break; /* FIXME: If this happens, we should take
144 * note of it and, if appropriate, use the
145 * X509_V_ERR_CERT_CHAIN_TOO_LONG error
146 * code later.
147 */
148
149 /* If we are self signed, we break */
150 xn=X509_get_issuer_name(x);
151 if (ctx->check_issued(ctx, x,x)) break;
152
153 /* If we were passed a cert chain, use it first */
154 if (ctx->untrusted != NULL)
155 {
156 xtmp=find_issuer(ctx, sktmp,x);
157 if (xtmp != NULL)
158 {
159 if (!sk_X509_push(ctx->chain,xtmp))
160 {
161 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
162 goto end;
163 }
164 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
165 sk_X509_delete_ptr(sktmp,xtmp);
166 ctx->last_untrusted++;
167 x=xtmp;
168 num++;
169 /* reparse the full chain for
170 * the next one */
171 continue;
172 }
173 }
174 break;
175 }
176
177 /* at this point, chain should contain a list of untrusted
178 * certificates. We now need to add at least one trusted one,
179 * if possible, otherwise we complain. */
180
181 /* Examine last certificate in chain and see if it
182 * is self signed.
183 */
184
185 i=sk_X509_num(ctx->chain);
186 x=sk_X509_value(ctx->chain,i-1);
187 xn = X509_get_subject_name(x);
188 if (ctx->check_issued(ctx, x, x))
189 {
190 /* we have a self signed certificate */
191 if (sk_X509_num(ctx->chain) == 1)
192 {
193 /* We have a single self signed certificate: see if
194 * we can find it in the store. We must have an exact
195 * match to avoid possible impersonation.
196 */
197 ok = ctx->get_issuer(&xtmp, ctx, x);
198 if ((ok <= 0) || X509_cmp(x, xtmp))
199 {
200 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
201 ctx->current_cert=x;
202 ctx->error_depth=i-1;
203 if (ok == 1) X509_free(xtmp);
204 ok=cb(0,ctx);
205 if (!ok) goto end;
206 }
207 else
208 {
209 /* We have a match: replace certificate with store version
210 * so we get any trust settings.
211 */
212 X509_free(x);
213 x = xtmp;
214 sk_X509_set(ctx->chain, i - 1, x);
215 ctx->last_untrusted=0;
216 }
217 }
218 else
219 {
220 /* extract and save self signed certificate for later use */
221 chain_ss=sk_X509_pop(ctx->chain);
222 ctx->last_untrusted--;
223 num--;
224 x=sk_X509_value(ctx->chain,num-1);
225 }
226 }
227
228 /* We now lookup certs from the certificate store */
229 for (;;)
230 {
231 /* If we have enough, we break */
232 if (depth < num) break;
233
234 /* If we are self signed, we break */
235 xn=X509_get_issuer_name(x);
236 if (ctx->check_issued(ctx,x,x)) break;
237
238 ok = ctx->get_issuer(&xtmp, ctx, x);
239
240 if (ok < 0) return ok;
241 if (ok == 0) break;
242
243 x = xtmp;
244 if (!sk_X509_push(ctx->chain,x))
245 {
246 X509_free(xtmp);
247 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
248 return 0;
249 }
250 num++;
251 }
252
253 /* we now have our chain, lets check it... */
254 xn=X509_get_issuer_name(x);
255
256 /* Is last certificate looked up self signed? */
257 if (!ctx->check_issued(ctx,x,x))
258 {
259 if ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss))
260 {
261 if (ctx->last_untrusted >= num)
262 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
263 else
264 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;
265 ctx->current_cert=x;
266 }
267 else
268 {
269
270 sk_X509_push(ctx->chain,chain_ss);
271 num++;
272 ctx->last_untrusted=num;
273 ctx->current_cert=chain_ss;
274 ctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
275 chain_ss=NULL;
276 }
277
278 ctx->error_depth=num-1;
279 ok=cb(0,ctx);
280 if (!ok) goto end;
281 }
282
283 /* We have the chain complete: now we need to check its purpose */
284 ok = check_chain_extensions(ctx);
285
286 if (!ok) goto end;
287
288 /* The chain extensions are OK: check trust */
289
290 if (ctx->trust > 0) ok = check_trust(ctx);
291
292 if (!ok) goto end;
293
294 /* We may as well copy down any DSA parameters that are required */
295 X509_get_pubkey_parameters(NULL,ctx->chain);
296
297 /* Check revocation status: we do this after copying parameters
298 * because they may be needed for CRL signature verification.
299 */
300
301 ok = ctx->check_revocation(ctx);
302 if(!ok) goto end;
303
304 /* At this point, we have a chain and just need to verify it */
305 if (ctx->verify != NULL)
306 ok=ctx->verify(ctx);
307 else
308 ok=internal_verify(ctx);
309 if (0)
310 {
311end:
312 X509_get_pubkey_parameters(NULL,ctx->chain);
313 }
314 if (sktmp != NULL) sk_X509_free(sktmp);
315 if (chain_ss != NULL) X509_free(chain_ss);
316 return ok;
317 }
318
319
320/* Given a STACK_OF(X509) find the issuer of cert (if any)
321 */
322
323static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x)
324{
325 int i;
326 X509 *issuer;
327 for (i = 0; i < sk_X509_num(sk); i++)
328 {
329 issuer = sk_X509_value(sk, i);
330 if (ctx->check_issued(ctx, x, issuer))
331 return issuer;
332 }
333 return NULL;
334}
335
336/* Given a possible certificate and issuer check them */
337
338static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer)
339{
340 int ret;
341 ret = X509_check_issued(issuer, x);
342 if (ret == X509_V_OK)
343 return 1;
344 /* If we haven't asked for issuer errors don't set ctx */
345 if (!(ctx->flags & X509_V_FLAG_CB_ISSUER_CHECK))
346 return 0;
347
348 ctx->error = ret;
349 ctx->current_cert = x;
350 ctx->current_issuer = issuer;
351 return ctx->verify_cb(0, ctx);
352 return 0;
353}
354
355/* Alternative lookup method: look from a STACK stored in other_ctx */
356
357static int get_issuer_sk(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
358{
359 *issuer = find_issuer(ctx, ctx->other_ctx, x);
360 if (*issuer)
361 {
362 CRYPTO_add(&(*issuer)->references,1,CRYPTO_LOCK_X509);
363 return 1;
364 }
365 else
366 return 0;
367}
368
369
370/* Check a certificate chains extensions for consistency
371 * with the supplied purpose
372 */
373
374static int check_chain_extensions(X509_STORE_CTX *ctx)
375{
376#ifdef OPENSSL_NO_CHAIN_VERIFY
377 return 1;
378#else
379 int i, ok=0, must_be_ca;
380 X509 *x;
381 int (*cb)();
382 int proxy_path_length = 0;
383 int allow_proxy_certs = !!(ctx->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
384 cb=ctx->verify_cb;
385
386 /* must_be_ca can have 1 of 3 values:
387 -1: we accept both CA and non-CA certificates, to allow direct
388 use of self-signed certificates (which are marked as CA).
389 0: we only accept non-CA certificates. This is currently not
390 used, but the possibility is present for future extensions.
391 1: we only accept CA certificates. This is currently used for
392 all certificates in the chain except the leaf certificate.
393 */
394 must_be_ca = -1;
395
396 /* A hack to keep people who don't want to modify their software
397 happy */
398 if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
399 allow_proxy_certs = 1;
400
401 /* Check all untrusted certificates */
402 for (i = 0; i < ctx->last_untrusted; i++)
403 {
404 int ret;
405 x = sk_X509_value(ctx->chain, i);
406 if (!(ctx->flags & X509_V_FLAG_IGNORE_CRITICAL)
407 && (x->ex_flags & EXFLAG_CRITICAL))
408 {
409 ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
410 ctx->error_depth = i;
411 ctx->current_cert = x;
412 ok=cb(0,ctx);
413 if (!ok) goto end;
414 }
415 if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY))
416 {
417 ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;
418 ctx->error_depth = i;
419 ctx->current_cert = x;
420 ok=cb(0,ctx);
421 if (!ok) goto end;
422 }
423 ret = X509_check_ca(x);
424 switch(must_be_ca)
425 {
426 case -1:
427 if ((ctx->flags & X509_V_FLAG_X509_STRICT)
428 && (ret != 1) && (ret != 0))
429 {
430 ret = 0;
431 ctx->error = X509_V_ERR_INVALID_CA;
432 }
433 else
434 ret = 1;
435 break;
436 case 0:
437 if (ret != 0)
438 {
439 ret = 0;
440 ctx->error = X509_V_ERR_INVALID_NON_CA;
441 }
442 else
443 ret = 1;
444 break;
445 default:
446 if ((ret == 0)
447 || ((ctx->flags & X509_V_FLAG_X509_STRICT)
448 && (ret != 1)))
449 {
450 ret = 0;
451 ctx->error = X509_V_ERR_INVALID_CA;
452 }
453 else
454 ret = 1;
455 break;
456 }
457 if (ret == 0)
458 {
459 ctx->error_depth = i;
460 ctx->current_cert = x;
461 ok=cb(0,ctx);
462 if (!ok) goto end;
463 }
464 if (ctx->purpose > 0)
465 {
466 ret = X509_check_purpose(x, ctx->purpose,
467 must_be_ca > 0);
468 if ((ret == 0)
469 || ((ctx->flags & X509_V_FLAG_X509_STRICT)
470 && (ret != 1)))
471 {
472 ctx->error = X509_V_ERR_INVALID_PURPOSE;
473 ctx->error_depth = i;
474 ctx->current_cert = x;
475 ok=cb(0,ctx);
476 if (!ok) goto end;
477 }
478 }
479 /* Check pathlen */
480 if ((i > 1) && (x->ex_pathlen != -1)
481 && (i > (x->ex_pathlen + proxy_path_length + 1)))
482 {
483 ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
484 ctx->error_depth = i;
485 ctx->current_cert = x;
486 ok=cb(0,ctx);
487 if (!ok) goto end;
488 }
489 /* If this certificate is a proxy certificate, the next
490 certificate must be another proxy certificate or a EE
491 certificate. If not, the next certificate must be a
492 CA certificate. */
493 if (x->ex_flags & EXFLAG_PROXY)
494 {
495 PROXY_CERT_INFO_EXTENSION *pci =
496 X509_get_ext_d2i(x, NID_proxyCertInfo,
497 NULL, NULL);
498 if (pci->pcPathLengthConstraint &&
499 ASN1_INTEGER_get(pci->pcPathLengthConstraint)
500 < i)
501 {
502 PROXY_CERT_INFO_EXTENSION_free(pci);
503 ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
504 ctx->error_depth = i;
505 ctx->current_cert = x;
506 ok=cb(0,ctx);
507 if (!ok) goto end;
508 }
509 PROXY_CERT_INFO_EXTENSION_free(pci);
510 proxy_path_length++;
511 must_be_ca = 0;
512 }
513 else
514 must_be_ca = 1;
515 }
516 ok = 1;
517 end:
518 return ok;
519#endif
520}
521
522static int check_trust(X509_STORE_CTX *ctx)
523{
524#ifdef OPENSSL_NO_CHAIN_VERIFY
525 return 1;
526#else
527 int i, ok;
528 X509 *x;
529 int (*cb)();
530 cb=ctx->verify_cb;
531/* For now just check the last certificate in the chain */
532 i = sk_X509_num(ctx->chain) - 1;
533 x = sk_X509_value(ctx->chain, i);
534 ok = X509_check_trust(x, ctx->trust, 0);
535 if (ok == X509_TRUST_TRUSTED)
536 return 1;
537 ctx->error_depth = i;
538 ctx->current_cert = x;
539 if (ok == X509_TRUST_REJECTED)
540 ctx->error = X509_V_ERR_CERT_REJECTED;
541 else
542 ctx->error = X509_V_ERR_CERT_UNTRUSTED;
543 ok = cb(0, ctx);
544 return ok;
545#endif
546}
547
548static int check_revocation(X509_STORE_CTX *ctx)
549 {
550 int i, last, ok;
551 if (!(ctx->flags & X509_V_FLAG_CRL_CHECK))
552 return 1;
553 if (ctx->flags & X509_V_FLAG_CRL_CHECK_ALL)
554 last = sk_X509_num(ctx->chain) - 1;
555 else
556 last = 0;
557 for(i = 0; i <= last; i++)
558 {
559 ctx->error_depth = i;
560 ok = check_cert(ctx);
561 if (!ok) return ok;
562 }
563 return 1;
564 }
565
566static int check_cert(X509_STORE_CTX *ctx)
567 {
568 X509_CRL *crl = NULL;
569 X509 *x;
570 int ok, cnum;
571 cnum = ctx->error_depth;
572 x = sk_X509_value(ctx->chain, cnum);
573 ctx->current_cert = x;
574 /* Try to retrieve relevant CRL */
575 ok = ctx->get_crl(ctx, &crl, x);
576 /* If error looking up CRL, nothing we can do except
577 * notify callback
578 */
579 if(!ok)
580 {
581 ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
582 ok = ctx->verify_cb(0, ctx);
583 goto err;
584 }
585 ctx->current_crl = crl;
586 ok = ctx->check_crl(ctx, crl);
587 if (!ok) goto err;
588 ok = ctx->cert_crl(ctx, crl, x);
589 err:
590 ctx->current_crl = NULL;
591 X509_CRL_free(crl);
592 return ok;
593
594 }
595
596/* Retrieve CRL corresponding to certificate: currently just a
597 * subject lookup: maybe use AKID later...
598 * Also might look up any included CRLs too (e.g PKCS#7 signedData).
599 */
600static int get_crl(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x)
601 {
602 int ok;
603 X509_OBJECT xobj;
604 ok = X509_STORE_get_by_subject(ctx, X509_LU_CRL, X509_get_issuer_name(x), &xobj);
605 if (!ok) return 0;
606 *crl = xobj.data.crl;
607 return 1;
608 }
609
610/* Check CRL validity */
611static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
612 {
613 X509 *issuer = NULL;
614 EVP_PKEY *ikey = NULL;
615 int ok = 0, chnum, cnum, i;
616 time_t *ptime;
617 cnum = ctx->error_depth;
618 chnum = sk_X509_num(ctx->chain) - 1;
619 /* Find CRL issuer: if not last certificate then issuer
620 * is next certificate in chain.
621 */
622 if(cnum < chnum)
623 issuer = sk_X509_value(ctx->chain, cnum + 1);
624 else
625 {
626 issuer = sk_X509_value(ctx->chain, chnum);
627 /* If not self signed, can't check signature */
628 if(!ctx->check_issued(ctx, issuer, issuer))
629 {
630 ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER;
631 ok = ctx->verify_cb(0, ctx);
632 if(!ok) goto err;
633 }
634 }
635
636 if(issuer)
637 {
638 /* Check for cRLSign bit if keyUsage present */
639 if ((issuer->ex_flags & EXFLAG_KUSAGE) &&
640 !(issuer->ex_kusage & KU_CRL_SIGN))
641 {
642 ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN;
643 ok = ctx->verify_cb(0, ctx);
644 if(!ok) goto err;
645 }
646
647 /* Attempt to get issuer certificate public key */
648 ikey = X509_get_pubkey(issuer);
649
650 if(!ikey)
651 {
652 ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
653 ok = ctx->verify_cb(0, ctx);
654 if (!ok) goto err;
655 }
656 else
657 {
658 /* Verify CRL signature */
659 if(X509_CRL_verify(crl, ikey) <= 0)
660 {
661 ctx->error=X509_V_ERR_CRL_SIGNATURE_FAILURE;
662 ok = ctx->verify_cb(0, ctx);
663 if (!ok) goto err;
664 }
665 }
666 }
667
668 /* OK, CRL signature valid check times */
669 if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
670 ptime = &ctx->check_time;
671 else
672 ptime = NULL;
673
674 i=X509_cmp_time(X509_CRL_get_lastUpdate(crl), ptime);
675 if (i == 0)
676 {
677 ctx->error=X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD;
678 ok = ctx->verify_cb(0, ctx);
679 if (!ok) goto err;
680 }
681
682 if (i > 0)
683 {
684 ctx->error=X509_V_ERR_CRL_NOT_YET_VALID;
685 ok = ctx->verify_cb(0, ctx);
686 if (!ok) goto err;
687 }
688
689 if(X509_CRL_get_nextUpdate(crl))
690 {
691 i=X509_cmp_time(X509_CRL_get_nextUpdate(crl), ptime);
692
693 if (i == 0)
694 {
695 ctx->error=X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD;
696 ok = ctx->verify_cb(0, ctx);
697 if (!ok) goto err;
698 }
699
700 if (i < 0)
701 {
702 ctx->error=X509_V_ERR_CRL_HAS_EXPIRED;
703 ok = ctx->verify_cb(0, ctx);
704 if (!ok) goto err;
705 }
706 }
707
708 ok = 1;
709
710 err:
711 EVP_PKEY_free(ikey);
712 return ok;
713 }
714
715/* Check certificate against CRL */
716static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x)
717 {
718 int idx, ok;
719 X509_REVOKED rtmp;
720 STACK_OF(X509_EXTENSION) *exts;
721 X509_EXTENSION *ext;
722 /* Look for serial number of certificate in CRL */
723 rtmp.serialNumber = X509_get_serialNumber(x);
724 /* Sort revoked into serial number order if not already sorted.
725 * Do this under a lock to avoid race condition.
726 */
727 if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked))
728 {
729 CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL);
730 sk_X509_REVOKED_sort(crl->crl->revoked);
731 CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
732 }
733 idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp);
734 /* If found assume revoked: want something cleverer than
735 * this to handle entry extensions in V2 CRLs.
736 */
737 if(idx >= 0)
738 {
739 ctx->error = X509_V_ERR_CERT_REVOKED;
740 ok = ctx->verify_cb(0, ctx);
741 if (!ok) return 0;
742 }
743
744 if (ctx->flags & X509_V_FLAG_IGNORE_CRITICAL)
745 return 1;
746
747 /* See if we have any critical CRL extensions: since we
748 * currently don't handle any CRL extensions the CRL must be
749 * rejected.
750 * This code accesses the X509_CRL structure directly: applications
751 * shouldn't do this.
752 */
753
754 exts = crl->crl->extensions;
755
756 for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++)
757 {
758 ext = sk_X509_EXTENSION_value(exts, idx);
759 if (ext->critical > 0)
760 {
761 ctx->error =
762 X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION;
763 ok = ctx->verify_cb(0, ctx);
764 if(!ok) return 0;
765 break;
766 }
767 }
768 return 1;
769 }
770
771static int internal_verify(X509_STORE_CTX *ctx)
772 {
773 int i,ok=0,n;
774 X509 *xs,*xi;
775 EVP_PKEY *pkey=NULL;
776 time_t *ptime;
777 int (*cb)();
778
779 cb=ctx->verify_cb;
780
781 n=sk_X509_num(ctx->chain);
782 ctx->error_depth=n-1;
783 n--;
784 xi=sk_X509_value(ctx->chain,n);
785 if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
786 ptime = &ctx->check_time;
787 else
788 ptime = NULL;
789 if (ctx->check_issued(ctx, xi, xi))
790 xs=xi;
791 else
792 {
793 if (n <= 0)
794 {
795 ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
796 ctx->current_cert=xi;
797 ok=cb(0,ctx);
798 goto end;
799 }
800 else
801 {
802 n--;
803 ctx->error_depth=n;
804 xs=sk_X509_value(ctx->chain,n);
805 }
806 }
807
808/* ctx->error=0; not needed */
809 while (n >= 0)
810 {
811 ctx->error_depth=n;
812 if (!xs->valid)
813 {
814 if ((pkey=X509_get_pubkey(xi)) == NULL)
815 {
816 ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
817 ctx->current_cert=xi;
818 ok=(*cb)(0,ctx);
819 if (!ok) goto end;
820 }
821 else if (X509_verify(xs,pkey) <= 0)
822 /* XXX For the final trusted self-signed cert,
823 * this is a waste of time. That check should
824 * optional so that e.g. 'openssl x509' can be
825 * used to detect invalid self-signatures, but
826 * we don't verify again and again in SSL
827 * handshakes and the like once the cert has
828 * been declared trusted. */
829 {
830 ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
831 ctx->current_cert=xs;
832 ok=(*cb)(0,ctx);
833 if (!ok)
834 {
835 EVP_PKEY_free(pkey);
836 goto end;
837 }
838 }
839 EVP_PKEY_free(pkey);
840 pkey=NULL;
841
842 i=X509_cmp_time(X509_get_notBefore(xs), ptime);
843 if (i == 0)
844 {
845 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
846 ctx->current_cert=xs;
847 ok=(*cb)(0,ctx);
848 if (!ok) goto end;
849 }
850 if (i > 0)
851 {
852 ctx->error=X509_V_ERR_CERT_NOT_YET_VALID;
853 ctx->current_cert=xs;
854 ok=(*cb)(0,ctx);
855 if (!ok) goto end;
856 }
857 xs->valid=1;
858 }
859
860 i=X509_cmp_time(X509_get_notAfter(xs), ptime);
861 if (i == 0)
862 {
863 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
864 ctx->current_cert=xs;
865 ok=(*cb)(0,ctx);
866 if (!ok) goto end;
867 }
868
869 if (i < 0)
870 {
871 ctx->error=X509_V_ERR_CERT_HAS_EXPIRED;
872 ctx->current_cert=xs;
873 ok=(*cb)(0,ctx);
874 if (!ok) goto end;
875 }
876
877 /* The last error (if any) is still in the error value */
878 ctx->current_issuer=xi;
879 ctx->current_cert=xs;
880 ok=(*cb)(1,ctx);
881 if (!ok) goto end;
882
883 n--;
884 if (n >= 0)
885 {
886 xi=xs;
887 xs=sk_X509_value(ctx->chain,n);
888 }
889 }
890 ok=1;
891end:
892 return ok;
893 }
894
895int X509_cmp_current_time(ASN1_TIME *ctm)
896{
897 return X509_cmp_time(ctm, NULL);
898}
899
900int X509_cmp_time(ASN1_TIME *ctm, time_t *cmp_time)
901 {
902 char *str;
903 ASN1_TIME atm;
904 long offset;
905 char buff1[24],buff2[24],*p;
906 int i,j;
907
908 p=buff1;
909 i=ctm->length;
910 str=(char *)ctm->data;
911 if (ctm->type == V_ASN1_UTCTIME)
912 {
913 if ((i < 11) || (i > 17)) return 0;
914 memcpy(p,str,10);
915 p+=10;
916 str+=10;
917 }
918 else
919 {
920 if (i < 13) return 0;
921 memcpy(p,str,12);
922 p+=12;
923 str+=12;
924 }
925
926 if ((*str == 'Z') || (*str == '-') || (*str == '+'))
927 { *(p++)='0'; *(p++)='0'; }
928 else
929 {
930 *(p++)= *(str++);
931 *(p++)= *(str++);
932 /* Skip any fractional seconds... */
933 if (*str == '.')
934 {
935 str++;
936 while ((*str >= '0') && (*str <= '9')) str++;
937 }
938
939 }
940 *(p++)='Z';
941 *(p++)='\0';
942
943 if (*str == 'Z')
944 offset=0;
945 else
946 {
947 if ((*str != '+') && (*str != '-'))
948 return 0;
949 offset=((str[1]-'0')*10+(str[2]-'0'))*60;
950 offset+=(str[3]-'0')*10+(str[4]-'0');
951 if (*str == '-')
952 offset= -offset;
953 }
954 atm.type=ctm->type;
955 atm.length=sizeof(buff2);
956 atm.data=(unsigned char *)buff2;
957
958 if (X509_time_adj(&atm,-offset*60, cmp_time) == NULL)
959 return 0;
960
961 if (ctm->type == V_ASN1_UTCTIME)
962 {
963 i=(buff1[0]-'0')*10+(buff1[1]-'0');
964 if (i < 50) i+=100; /* cf. RFC 2459 */
965 j=(buff2[0]-'0')*10+(buff2[1]-'0');
966 if (j < 50) j+=100;
967
968 if (i < j) return -1;
969 if (i > j) return 1;
970 }
971 i=strcmp(buff1,buff2);
972 if (i == 0) /* wait a second then return younger :-) */
973 return -1;
974 else
975 return i;
976 }
977
978ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj)
979{
980 return X509_time_adj(s, adj, NULL);
981}
982
983ASN1_TIME *X509_time_adj(ASN1_TIME *s, long adj, time_t *in_tm)
984 {
985 time_t t;
986 int type = -1;
987
988 if (in_tm) t = *in_tm;
989 else time(&t);
990
991 t+=adj;
992 if (s) type = s->type;
993 if (type == V_ASN1_UTCTIME) return ASN1_UTCTIME_set(s,t);
994 if (type == V_ASN1_GENERALIZEDTIME) return ASN1_GENERALIZEDTIME_set(s, t);
995 return ASN1_TIME_set(s, t);
996 }
997
998int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
999 {
1000 EVP_PKEY *ktmp=NULL,*ktmp2;
1001 int i,j;
1002
1003 if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return 1;
1004
1005 for (i=0; i<sk_X509_num(chain); i++)
1006 {
1007 ktmp=X509_get_pubkey(sk_X509_value(chain,i));
1008 if (ktmp == NULL)
1009 {
1010 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);
1011 return 0;
1012 }
1013 if (!EVP_PKEY_missing_parameters(ktmp))
1014 break;
1015 else
1016 {
1017 EVP_PKEY_free(ktmp);
1018 ktmp=NULL;
1019 }
1020 }
1021 if (ktmp == NULL)
1022 {
1023 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN);
1024 return 0;
1025 }
1026
1027 /* first, populate the other certs */
1028 for (j=i-1; j >= 0; j--)
1029 {
1030 ktmp2=X509_get_pubkey(sk_X509_value(chain,j));
1031 EVP_PKEY_copy_parameters(ktmp2,ktmp);
1032 EVP_PKEY_free(ktmp2);
1033 }
1034
1035 if (pkey != NULL) EVP_PKEY_copy_parameters(pkey,ktmp);
1036 EVP_PKEY_free(ktmp);
1037 return 1;
1038 }
1039
1040int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1041 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
1042 {
1043 /* This function is (usually) called only once, by
1044 * SSL_get_ex_data_X509_STORE_CTX_idx (ssl/ssl_cert.c). */
1045 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE_CTX, argl, argp,
1046 new_func, dup_func, free_func);
1047 }
1048
1049int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data)
1050 {
1051 return CRYPTO_set_ex_data(&ctx->ex_data,idx,data);
1052 }
1053
1054void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx)
1055 {
1056 return CRYPTO_get_ex_data(&ctx->ex_data,idx);
1057 }
1058
1059int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx)
1060 {
1061 return ctx->error;
1062 }
1063
1064void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err)
1065 {
1066 ctx->error=err;
1067 }
1068
1069int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx)
1070 {
1071 return ctx->error_depth;
1072 }
1073
1074X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx)
1075 {
1076 return ctx->current_cert;
1077 }
1078
1079STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx)
1080 {
1081 return ctx->chain;
1082 }
1083
1084STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
1085 {
1086 int i;
1087 X509 *x;
1088 STACK_OF(X509) *chain;
1089 if (!ctx->chain || !(chain = sk_X509_dup(ctx->chain))) return NULL;
1090 for (i = 0; i < sk_X509_num(chain); i++)
1091 {
1092 x = sk_X509_value(chain, i);
1093 CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
1094 }
1095 return chain;
1096 }
1097
1098void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)
1099 {
1100 ctx->cert=x;
1101 }
1102
1103void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
1104 {
1105 ctx->untrusted=sk;
1106 }
1107
1108int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose)
1109 {
1110 return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0);
1111 }
1112
1113int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust)
1114 {
1115 return X509_STORE_CTX_purpose_inherit(ctx, 0, 0, trust);
1116 }
1117
1118/* This function is used to set the X509_STORE_CTX purpose and trust
1119 * values. This is intended to be used when another structure has its
1120 * own trust and purpose values which (if set) will be inherited by
1121 * the ctx. If they aren't set then we will usually have a default
1122 * purpose in mind which should then be used to set the trust value.
1123 * An example of this is SSL use: an SSL structure will have its own
1124 * purpose and trust settings which the application can set: if they
1125 * aren't set then we use the default of SSL client/server.
1126 */
1127
1128int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
1129 int purpose, int trust)
1130{
1131 int idx;
1132 /* If purpose not set use default */
1133 if (!purpose) purpose = def_purpose;
1134 /* If we have a purpose then check it is valid */
1135 if (purpose)
1136 {
1137 X509_PURPOSE *ptmp;
1138 idx = X509_PURPOSE_get_by_id(purpose);
1139 if (idx == -1)
1140 {
1141 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
1142 X509_R_UNKNOWN_PURPOSE_ID);
1143 return 0;
1144 }
1145 ptmp = X509_PURPOSE_get0(idx);
1146 if (ptmp->trust == X509_TRUST_DEFAULT)
1147 {
1148 idx = X509_PURPOSE_get_by_id(def_purpose);
1149 if (idx == -1)
1150 {
1151 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
1152 X509_R_UNKNOWN_PURPOSE_ID);
1153 return 0;
1154 }
1155 ptmp = X509_PURPOSE_get0(idx);
1156 }
1157 /* If trust not set then get from purpose default */
1158 if (!trust) trust = ptmp->trust;
1159 }
1160 if (trust)
1161 {
1162 idx = X509_TRUST_get_by_id(trust);
1163 if (idx == -1)
1164 {
1165 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
1166 X509_R_UNKNOWN_TRUST_ID);
1167 return 0;
1168 }
1169 }
1170
1171 if (purpose && !ctx->purpose) ctx->purpose = purpose;
1172 if (trust && !ctx->trust) ctx->trust = trust;
1173 return 1;
1174}
1175
1176X509_STORE_CTX *X509_STORE_CTX_new(void)
1177{
1178 X509_STORE_CTX *ctx;
1179 ctx = (X509_STORE_CTX *)OPENSSL_malloc(sizeof(X509_STORE_CTX));
1180 if (!ctx)
1181 {
1182 X509err(X509_F_X509_STORE_CTX_NEW,ERR_R_MALLOC_FAILURE);
1183 return NULL;
1184 }
1185 memset(ctx, 0, sizeof(X509_STORE_CTX));
1186 return ctx;
1187}
1188
1189void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
1190{
1191 X509_STORE_CTX_cleanup(ctx);
1192 OPENSSL_free(ctx);
1193}
1194
1195int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
1196 STACK_OF(X509) *chain)
1197 {
1198 ctx->ctx=store;
1199 ctx->current_method=0;
1200 ctx->cert=x509;
1201 ctx->untrusted=chain;
1202 ctx->last_untrusted=0;
1203 ctx->check_time=0;
1204 ctx->other_ctx=NULL;
1205 ctx->valid=0;
1206 ctx->chain=NULL;
1207 ctx->depth=9;
1208 ctx->error=0;
1209 ctx->error_depth=0;
1210 ctx->current_cert=NULL;
1211 ctx->current_issuer=NULL;
1212
1213 /* Inherit callbacks and flags from X509_STORE if not set
1214 * use defaults.
1215 */
1216
1217
1218 if (store)
1219 {
1220 ctx->purpose=store->purpose;
1221 ctx->trust=store->trust;
1222 ctx->flags = store->flags;
1223 ctx->cleanup = store->cleanup;
1224 }
1225 else
1226 {
1227 ctx->purpose = 0;
1228 ctx->trust = 0;
1229 ctx->flags = 0;
1230 ctx->cleanup = 0;
1231 }
1232
1233 if (store && store->check_issued)
1234 ctx->check_issued = store->check_issued;
1235 else
1236 ctx->check_issued = check_issued;
1237
1238 if (store && store->get_issuer)
1239 ctx->get_issuer = store->get_issuer;
1240 else
1241 ctx->get_issuer = X509_STORE_CTX_get1_issuer;
1242
1243 if (store && store->verify_cb)
1244 ctx->verify_cb = store->verify_cb;
1245 else
1246 ctx->verify_cb = null_callback;
1247
1248 if (store && store->verify)
1249 ctx->verify = store->verify;
1250 else
1251 ctx->verify = internal_verify;
1252
1253 if (store && store->check_revocation)
1254 ctx->check_revocation = store->check_revocation;
1255 else
1256 ctx->check_revocation = check_revocation;
1257
1258 if (store && store->get_crl)
1259 ctx->get_crl = store->get_crl;
1260 else
1261 ctx->get_crl = get_crl;
1262
1263 if (store && store->check_crl)
1264 ctx->check_crl = store->check_crl;
1265 else
1266 ctx->check_crl = check_crl;
1267
1268 if (store && store->cert_crl)
1269 ctx->cert_crl = store->cert_crl;
1270 else
1271 ctx->cert_crl = cert_crl;
1272
1273
1274 /* This memset() can't make any sense anyway, so it's removed. As
1275 * X509_STORE_CTX_cleanup does a proper "free" on the ex_data, we put a
1276 * corresponding "new" here and remove this bogus initialisation. */
1277 /* memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA)); */
1278 if(!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx,
1279 &(ctx->ex_data)))
1280 {
1281 OPENSSL_free(ctx);
1282 X509err(X509_F_X509_STORE_CTX_INIT,ERR_R_MALLOC_FAILURE);
1283 return 0;
1284 }
1285 return 1;
1286 }
1287
1288/* Set alternative lookup method: just a STACK of trusted certificates.
1289 * This avoids X509_STORE nastiness where it isn't needed.
1290 */
1291
1292void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
1293{
1294 ctx->other_ctx = sk;
1295 ctx->get_issuer = get_issuer_sk;
1296}
1297
1298void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
1299 {
1300 if (ctx->cleanup) ctx->cleanup(ctx);
1301 if (ctx->chain != NULL)
1302 {
1303 sk_X509_pop_free(ctx->chain,X509_free);
1304 ctx->chain=NULL;
1305 }
1306 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx, &(ctx->ex_data));
1307 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA));
1308 }
1309
1310void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, long flags)
1311 {
1312 ctx->flags |= flags;
1313 }
1314
1315void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, long flags, time_t t)
1316 {
1317 ctx->check_time = t;
1318 ctx->flags |= X509_V_FLAG_USE_CHECK_TIME;
1319 }
1320
1321void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
1322 int (*verify_cb)(int, X509_STORE_CTX *))
1323 {
1324 ctx->verify_cb=verify_cb;
1325 }
1326
1327IMPLEMENT_STACK_OF(X509)
1328IMPLEMENT_ASN1_SET_OF(X509)
1329
1330IMPLEMENT_STACK_OF(X509_NAME)
1331
1332IMPLEMENT_STACK_OF(X509_ATTRIBUTE)
1333IMPLEMENT_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 7fd1f0bc4d..0000000000
--- a/src/lib/libcrypto/x509/x509_vfy.h
+++ /dev/null
@@ -1,422 +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#ifndef OPENSSL_NO_LHASH
69#include <openssl/lhash.h>
70#endif
71#include <openssl/bio.h>
72#include <openssl/crypto.h>
73#include <openssl/symhacks.h>
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79/* Outer object */
80typedef struct x509_hash_dir_st
81 {
82 int num_dirs;
83 char **dirs;
84 int *dirs_type;
85 int num_dirs_alloced;
86 } X509_HASH_DIR_CTX;
87
88typedef struct x509_file_st
89 {
90 int num_paths; /* number of paths to files or directories */
91 int num_alloced;
92 char **paths; /* the list of paths or directories */
93 int *path_type;
94 } X509_CERT_FILE_CTX;
95
96/*******************************/
97/*
98SSL_CTX -> X509_STORE
99 -> X509_LOOKUP
100 ->X509_LOOKUP_METHOD
101 -> X509_LOOKUP
102 ->X509_LOOKUP_METHOD
103
104SSL -> X509_STORE_CTX
105 ->X509_STORE
106
107The X509_STORE holds the tables etc for verification stuff.
108A X509_STORE_CTX is used while validating a single certificate.
109The X509_STORE has X509_LOOKUPs for looking up certs.
110The X509_STORE then calls a function to actually verify the
111certificate chain.
112*/
113
114#define X509_LU_RETRY -1
115#define X509_LU_FAIL 0
116#define X509_LU_X509 1
117#define X509_LU_CRL 2
118#define X509_LU_PKEY 3
119
120typedef struct x509_object_st
121 {
122 /* one of the above types */
123 int type;
124 union {
125 char *ptr;
126 X509 *x509;
127 X509_CRL *crl;
128 EVP_PKEY *pkey;
129 } data;
130 } X509_OBJECT;
131
132typedef struct x509_lookup_st X509_LOOKUP;
133
134DECLARE_STACK_OF(X509_LOOKUP)
135DECLARE_STACK_OF(X509_OBJECT)
136
137/* This is a static that defines the function interface */
138typedef struct x509_lookup_method_st
139 {
140 const char *name;
141 int (*new_item)(X509_LOOKUP *ctx);
142 void (*free)(X509_LOOKUP *ctx);
143 int (*init)(X509_LOOKUP *ctx);
144 int (*shutdown)(X509_LOOKUP *ctx);
145 int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl,
146 char **ret);
147 int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name,
148 X509_OBJECT *ret);
149 int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name,
150 ASN1_INTEGER *serial,X509_OBJECT *ret);
151 int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type,
152 unsigned char *bytes,int len,
153 X509_OBJECT *ret);
154 int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len,
155 X509_OBJECT *ret);
156 } X509_LOOKUP_METHOD;
157
158/* This is used to hold everything. It is used for all certificate
159 * validation. Once we have a certificate chain, the 'verify'
160 * function is then called to actually check the cert chain. */
161struct x509_store_st
162 {
163 /* The following is a cache of trusted certs */
164 int cache; /* if true, stash any hits */
165 STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */
166
167 /* These are external lookup methods */
168 STACK_OF(X509_LOOKUP) *get_cert_methods;
169
170 /* The following fields are not used by X509_STORE but are
171 * inherited by X509_STORE_CTX when it is initialised.
172 */
173
174 unsigned long flags; /* Various verify flags */
175 int purpose;
176 int trust;
177 /* Callbacks for various operations */
178 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
179 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
180 int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */
181 int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
182 int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
183 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
184 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
185 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
186 int (*cleanup)(X509_STORE_CTX *ctx);
187
188 CRYPTO_EX_DATA ex_data;
189 int references;
190 int depth; /* how deep to look (still unused -- X509_STORE_CTX's depth is used) */
191 } /* X509_STORE */;
192
193#define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d))
194
195#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func))
196#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func))
197
198/* This is the functions plus an instance of the local variables. */
199struct x509_lookup_st
200 {
201 int init; /* have we been started */
202 int skip; /* don't use us. */
203 X509_LOOKUP_METHOD *method; /* the functions */
204 char *method_data; /* method data */
205
206 X509_STORE *store_ctx; /* who owns us */
207 } /* X509_LOOKUP */;
208
209/* This is a used when verifying cert chains. Since the
210 * gathering of the cert chain can take some time (and have to be
211 * 'retried', this needs to be kept and passed around. */
212struct x509_store_ctx_st /* X509_STORE_CTX */
213 {
214 X509_STORE *ctx;
215 int current_method; /* used when looking up certs */
216
217 /* The following are set by the caller */
218 X509 *cert; /* The cert to check */
219 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */
220 int purpose; /* purpose to check untrusted certificates */
221 int trust; /* trust setting to check */
222 time_t check_time; /* time to make verify at */
223 unsigned long flags; /* Various verify flags */
224 void *other_ctx; /* Other info for use with get_issuer() */
225
226 /* Callbacks for various operations */
227 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
228 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
229 int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */
230 int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
231 int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
232 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
233 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
234 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
235 int (*cleanup)(X509_STORE_CTX *ctx);
236
237 /* The following is built up */
238 int depth; /* how far to go looking up certs */
239 int valid; /* if 0, rebuild chain */
240 int last_untrusted; /* index of last untrusted cert */
241 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */
242
243 /* When something goes wrong, this is why */
244 int error_depth;
245 int error;
246 X509 *current_cert;
247 X509 *current_issuer; /* cert currently being tested as valid issuer */
248 X509_CRL *current_crl; /* current CRL */
249
250 CRYPTO_EX_DATA ex_data;
251 } /* X509_STORE_CTX */;
252
253#define X509_STORE_CTX_set_depth(ctx,d) ((ctx)->depth=(d))
254
255#define X509_STORE_CTX_set_app_data(ctx,data) \
256 X509_STORE_CTX_set_ex_data(ctx,0,data)
257#define X509_STORE_CTX_get_app_data(ctx) \
258 X509_STORE_CTX_get_ex_data(ctx,0)
259
260#define X509_L_FILE_LOAD 1
261#define X509_L_ADD_DIR 2
262
263#define X509_LOOKUP_load_file(x,name,type) \
264 X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL)
265
266#define X509_LOOKUP_add_dir(x,name,type) \
267 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)
268
269#define X509_V_OK 0
270/* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */
271
272#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
273#define X509_V_ERR_UNABLE_TO_GET_CRL 3
274#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4
275#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5
276#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6
277#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7
278#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8
279#define X509_V_ERR_CERT_NOT_YET_VALID 9
280#define X509_V_ERR_CERT_HAS_EXPIRED 10
281#define X509_V_ERR_CRL_NOT_YET_VALID 11
282#define X509_V_ERR_CRL_HAS_EXPIRED 12
283#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13
284#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14
285#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15
286#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16
287#define X509_V_ERR_OUT_OF_MEM 17
288#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18
289#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19
290#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20
291#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21
292#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22
293#define X509_V_ERR_CERT_REVOKED 23
294#define X509_V_ERR_INVALID_CA 24
295#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25
296#define X509_V_ERR_INVALID_PURPOSE 26
297#define X509_V_ERR_CERT_UNTRUSTED 27
298#define X509_V_ERR_CERT_REJECTED 28
299/* These are 'informational' when looking for issuer cert */
300#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29
301#define X509_V_ERR_AKID_SKID_MISMATCH 30
302#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31
303#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32
304
305#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33
306#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34
307#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35
308#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36
309#define X509_V_ERR_INVALID_NON_CA 37
310#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38
311#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39
312#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40
313
314/* The application is not happy */
315#define X509_V_ERR_APPLICATION_VERIFICATION 50
316
317/* Certificate verify flags */
318
319/* Send issuer+subject checks to verify_cb */
320#define X509_V_FLAG_CB_ISSUER_CHECK 0x1
321/* Use check time instead of current time */
322#define X509_V_FLAG_USE_CHECK_TIME 0x2
323/* Lookup CRLs */
324#define X509_V_FLAG_CRL_CHECK 0x4
325/* Lookup CRLs for whole chain */
326#define X509_V_FLAG_CRL_CHECK_ALL 0x8
327/* Ignore unhandled critical extensions */
328#define X509_V_FLAG_IGNORE_CRITICAL 0x10
329/* Disable workarounds for broken certificates */
330#define X509_V_FLAG_X509_STRICT 0x20
331/* Enable proxy certificate validation */
332#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40
333
334int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
335 X509_NAME *name);
336X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h,int type,X509_NAME *name);
337X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x);
338void X509_OBJECT_up_ref_count(X509_OBJECT *a);
339void X509_OBJECT_free_contents(X509_OBJECT *a);
340X509_STORE *X509_STORE_new(void );
341void X509_STORE_free(X509_STORE *v);
342
343void X509_STORE_set_flags(X509_STORE *ctx, long flags);
344int X509_STORE_set_purpose(X509_STORE *ctx, int purpose);
345int X509_STORE_set_trust(X509_STORE *ctx, int trust);
346
347X509_STORE_CTX *X509_STORE_CTX_new(void);
348
349int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
350
351void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
352int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
353 X509 *x509, STACK_OF(X509) *chain);
354void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
355void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
356
357X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);
358
359X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
360X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
361
362int X509_STORE_add_cert(X509_STORE *ctx, X509 *x);
363int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x);
364
365int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name,
366 X509_OBJECT *ret);
367
368int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
369 long argl, char **ret);
370
371#ifndef OPENSSL_NO_STDIO
372int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
373int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
374int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type);
375#endif
376
377
378X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
379void X509_LOOKUP_free(X509_LOOKUP *ctx);
380int X509_LOOKUP_init(X509_LOOKUP *ctx);
381int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
382 X509_OBJECT *ret);
383int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
384 ASN1_INTEGER *serial, X509_OBJECT *ret);
385int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
386 unsigned char *bytes, int len, X509_OBJECT *ret);
387int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str,
388 int len, X509_OBJECT *ret);
389int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
390
391#ifndef OPENSSL_NO_STDIO
392int X509_STORE_load_locations (X509_STORE *ctx,
393 const char *file, const char *dir);
394int X509_STORE_set_default_paths(X509_STORE *ctx);
395#endif
396
397int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
398 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
399int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data);
400void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
401int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
402void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
403int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
404X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
405STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
406STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
407void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
408void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);
409int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
410int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
411int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
412 int purpose, int trust);
413void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, long flags);
414void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, long flags, time_t t);
415void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
416 int (*verify_cb)(int, X509_STORE_CTX *));
417
418#ifdef __cplusplus
419}
420#endif
421#endif
422
diff --git a/src/lib/libcrypto/x509/x509cset.c b/src/lib/libcrypto/x509/x509cset.c
deleted file mode 100644
index 9d1646d5c8..0000000000
--- a/src/lib/libcrypto/x509/x509cset.c
+++ /dev/null
@@ -1,170 +0,0 @@
1/* crypto/x509/x509cset.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65
66int X509_CRL_set_version(X509_CRL *x, long version)
67 {
68 if (x == NULL) return(0);
69 if (x->crl->version == NULL)
70 {
71 if ((x->crl->version=M_ASN1_INTEGER_new()) == NULL)
72 return(0);
73 }
74 return(ASN1_INTEGER_set(x->crl->version,version));
75 }
76
77int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
78 {
79 if ((x == NULL) || (x->crl == NULL)) return(0);
80 return(X509_NAME_set(&x->crl->issuer,name));
81 }
82
83
84int X509_CRL_set_lastUpdate(X509_CRL *x, ASN1_TIME *tm)
85 {
86 ASN1_TIME *in;
87
88 if (x == NULL) return(0);
89 in=x->crl->lastUpdate;
90 if (in != tm)
91 {
92 in=M_ASN1_TIME_dup(tm);
93 if (in != NULL)
94 {
95 M_ASN1_TIME_free(x->crl->lastUpdate);
96 x->crl->lastUpdate=in;
97 }
98 }
99 return(in != NULL);
100 }
101
102int X509_CRL_set_nextUpdate(X509_CRL *x, ASN1_TIME *tm)
103 {
104 ASN1_TIME *in;
105
106 if (x == NULL) return(0);
107 in=x->crl->nextUpdate;
108 if (in != tm)
109 {
110 in=M_ASN1_TIME_dup(tm);
111 if (in != NULL)
112 {
113 M_ASN1_TIME_free(x->crl->nextUpdate);
114 x->crl->nextUpdate=in;
115 }
116 }
117 return(in != NULL);
118 }
119
120int X509_CRL_sort(X509_CRL *c)
121 {
122 int i;
123 X509_REVOKED *r;
124 /* sort the data so it will be written in serial
125 * number order */
126 sk_X509_REVOKED_sort(c->crl->revoked);
127 for (i=0; i<sk_X509_REVOKED_num(c->crl->revoked); i++)
128 {
129 r=sk_X509_REVOKED_value(c->crl->revoked,i);
130 r->sequence=i;
131 }
132 c->crl->enc.modified = 1;
133 return 1;
134 }
135
136int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm)
137 {
138 ASN1_TIME *in;
139
140 if (x == NULL) return(0);
141 in=x->revocationDate;
142 if (in != tm)
143 {
144 in=M_ASN1_TIME_dup(tm);
145 if (in != NULL)
146 {
147 M_ASN1_TIME_free(x->revocationDate);
148 x->revocationDate=in;
149 }
150 }
151 return(in != NULL);
152 }
153
154int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
155 {
156 ASN1_INTEGER *in;
157
158 if (x == NULL) return(0);
159 in=x->serialNumber;
160 if (in != serial)
161 {
162 in=M_ASN1_INTEGER_dup(serial);
163 if (in != NULL)
164 {
165 M_ASN1_INTEGER_free(x->serialNumber);
166 x->serialNumber=in;
167 }
168 }
169 return(in != NULL);
170 }
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c
deleted file mode 100644
index 068abfe5f0..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, const char *field, int type,
199 const 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 const char *field, int type, const 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, const 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 const 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 4c3af946ec..0000000000
--- a/src/lib/libcrypto/x509/x509spki.c
+++ /dev/null
@@ -1,120 +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
63int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey)
64{
65 if ((x == NULL) || (x->spkac == NULL)) return(0);
66 return(X509_PUBKEY_set(&(x->spkac->pubkey),pkey));
67}
68
69EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x)
70{
71 if ((x == NULL) || (x->spkac == NULL))
72 return(NULL);
73 return(X509_PUBKEY_get(x->spkac->pubkey));
74}
75
76/* Load a Netscape SPKI from a base64 encoded string */
77
78NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len)
79{
80 unsigned char *spki_der, *p;
81 int spki_len;
82 NETSCAPE_SPKI *spki;
83 if(len <= 0) len = strlen(str);
84 if (!(spki_der = OPENSSL_malloc(len + 1))) {
85 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE);
86 return NULL;
87 }
88 spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len);
89 if(spki_len < 0) {
90 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE,
91 X509_R_BASE64_DECODE_ERROR);
92 OPENSSL_free(spki_der);
93 return NULL;
94 }
95 p = spki_der;
96 spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len);
97 OPENSSL_free(spki_der);
98 return spki;
99}
100
101/* Generate a base64 encoded string from an SPKI */
102
103char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
104{
105 unsigned char *der_spki, *p;
106 char *b64_str;
107 int der_len;
108 der_len = i2d_NETSCAPE_SPKI(spki, NULL);
109 der_spki = OPENSSL_malloc(der_len);
110 b64_str = OPENSSL_malloc(der_len * 2);
111 if(!der_spki || !b64_str) {
112 X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE);
113 return NULL;
114 }
115 p = der_spki;
116 i2d_NETSCAPE_SPKI(spki, &p);
117 EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len);
118 OPENSSL_free(der_spki);
119 return b64_str;
120}
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c
deleted file mode 100644
index c25959a742..0000000000
--- a/src/lib/libcrypto/x509/x509type.c
+++ /dev/null
@@ -1,115 +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_PKEY_DSA:
103 ret|=EVP_PKS_DSA;
104 break;
105 default:
106 break;
107 }
108
109 if (EVP_PKEY_size(pk) <= 1024/8)/* /8 because it's 1024 bits we look
110 for, not bytes */
111 ret|=EVP_PKT_EXP;
112 if(pkey==NULL) EVP_PKEY_free(pk);
113 return(ret);
114 }
115
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c
deleted file mode 100644
index ac6dea493a..0000000000
--- a/src/lib/libcrypto/x509/x_all.c
+++ /dev/null
@@ -1,489 +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_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg,
71 a->signature,a->cert_info,r));
72 }
73
74int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r)
75 {
76 return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO),
77 a->sig_alg,a->signature,a->req_info,r));
78 }
79
80int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r)
81 {
82 return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO),
83 a->sig_alg, a->signature,a->crl,r));
84 }
85
86int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r)
87 {
88 return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC),
89 a->sig_algor,a->signature,a->spkac,r));
90 }
91
92int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
93 {
94 return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature,
95 x->sig_alg, x->signature, 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_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO),x->sig_alg, NULL,
101 x->signature, x->req_info,pkey,md));
102 }
103
104int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md)
105 {
106 x->crl->enc.modified = 1;
107 return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO),x->crl->sig_alg,
108 x->sig_alg, x->signature, x->crl,pkey,md));
109 }
110
111int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md)
112 {
113 return(ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor,NULL,
114 x->signature, x->spkac,pkey,md));
115 }
116
117#ifndef OPENSSL_NO_FP_API
118X509 *d2i_X509_fp(FILE *fp, X509 **x509)
119 {
120 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509);
121 }
122
123int i2d_X509_fp(FILE *fp, X509 *x509)
124 {
125 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509);
126 }
127#endif
128
129X509 *d2i_X509_bio(BIO *bp, X509 **x509)
130 {
131 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509);
132 }
133
134int i2d_X509_bio(BIO *bp, X509 *x509)
135 {
136 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509);
137 }
138
139#ifndef OPENSSL_NO_FP_API
140X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl)
141 {
142 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl);
143 }
144
145int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl)
146 {
147 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl);
148 }
149#endif
150
151X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl)
152 {
153 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl);
154 }
155
156int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl)
157 {
158 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl);
159 }
160
161#ifndef OPENSSL_NO_FP_API
162PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7)
163 {
164 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7);
165 }
166
167int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7)
168 {
169 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7);
170 }
171#endif
172
173PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7)
174 {
175 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7);
176 }
177
178int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7)
179 {
180 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7);
181 }
182
183#ifndef OPENSSL_NO_FP_API
184X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req)
185 {
186 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req);
187 }
188
189int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req)
190 {
191 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req);
192 }
193#endif
194
195X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req)
196 {
197 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req);
198 }
199
200int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req)
201 {
202 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req);
203 }
204
205#ifndef OPENSSL_NO_RSA
206
207#ifndef OPENSSL_NO_FP_API
208RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa)
209 {
210 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa);
211 }
212
213int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa)
214 {
215 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa);
216 }
217
218RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa)
219 {
220 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa);
221 }
222
223
224RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa)
225 {
226 return((RSA *)ASN1_d2i_fp((char *(*)())
227 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (fp),
228 (unsigned char **)(rsa)));
229 }
230
231int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
232 {
233 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa);
234 }
235
236int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa)
237 {
238 return(ASN1_i2d_fp(i2d_RSA_PUBKEY,fp,(unsigned char *)rsa));
239 }
240#endif
241
242RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa)
243 {
244 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa);
245 }
246
247int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa)
248 {
249 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa);
250 }
251
252RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa)
253 {
254 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa);
255 }
256
257
258RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa)
259 {
260 return((RSA *)ASN1_d2i_bio((char *(*)())
261 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (bp),
262 (unsigned char **)(rsa)));
263 }
264
265int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
266 {
267 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa);
268 }
269
270int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
271 {
272 return(ASN1_i2d_bio(i2d_RSA_PUBKEY,bp,(unsigned char *)rsa));
273 }
274#endif
275
276#ifndef OPENSSL_NO_DSA
277#ifndef OPENSSL_NO_FP_API
278DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa)
279 {
280 return((DSA *)ASN1_d2i_fp((char *(*)())
281 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp),
282 (unsigned char **)(dsa)));
283 }
284
285int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
286 {
287 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
288 }
289
290DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa)
291 {
292 return((DSA *)ASN1_d2i_fp((char *(*)())
293 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (fp),
294 (unsigned char **)(dsa)));
295 }
296
297int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa)
298 {
299 return(ASN1_i2d_fp(i2d_DSA_PUBKEY,fp,(unsigned char *)dsa));
300 }
301#endif
302
303DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa)
304 {
305 return((DSA *)ASN1_d2i_bio((char *(*)())
306 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp),
307 (unsigned char **)(dsa)));
308 }
309
310int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa)
311 {
312 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
313 }
314
315DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa)
316 {
317 return((DSA *)ASN1_d2i_bio((char *(*)())
318 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (bp),
319 (unsigned char **)(dsa)));
320 }
321
322int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa)
323 {
324 return(ASN1_i2d_bio(i2d_DSA_PUBKEY,bp,(unsigned char *)dsa));
325 }
326
327#endif
328
329int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
330 unsigned int *len)
331 {
332 ASN1_BIT_STRING *key;
333 key = X509_get0_pubkey_bitstr(data);
334 if(!key) return 0;
335 return EVP_Digest(key->data, key->length, md, len, type, NULL);
336 }
337
338int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
339 unsigned int *len)
340 {
341 return(ASN1_item_digest(ASN1_ITEM_rptr(X509),type,(char *)data,md,len));
342 }
343
344int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md,
345 unsigned int *len)
346 {
347 return(ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL),type,(char *)data,md,len));
348 }
349
350int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md,
351 unsigned int *len)
352 {
353 return(ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ),type,(char *)data,md,len));
354 }
355
356int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md,
357 unsigned int *len)
358 {
359 return(ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME),type,(char *)data,md,len));
360 }
361
362int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type,
363 unsigned char *md, unsigned int *len)
364 {
365 return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL),type,
366 (char *)data,md,len));
367 }
368
369
370#ifndef OPENSSL_NO_FP_API
371X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8)
372 {
373 return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new,
374 (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8)));
375 }
376
377int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8)
378 {
379 return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8));
380 }
381#endif
382
383X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8)
384 {
385 return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new,
386 (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8)));
387 }
388
389int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8)
390 {
391 return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8));
392 }
393
394#ifndef OPENSSL_NO_FP_API
395PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
396 PKCS8_PRIV_KEY_INFO **p8inf)
397 {
398 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp(
399 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
400 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp),
401 (unsigned char **)(p8inf)));
402 }
403
404int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
405 {
406 return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf));
407 }
408
409int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key)
410 {
411 PKCS8_PRIV_KEY_INFO *p8inf;
412 int ret;
413 p8inf = EVP_PKEY2PKCS8(key);
414 if(!p8inf) return 0;
415 ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf);
416 PKCS8_PRIV_KEY_INFO_free(p8inf);
417 return ret;
418 }
419
420int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey)
421 {
422 return(ASN1_i2d_fp(i2d_PrivateKey,fp,(unsigned char *)pkey));
423 }
424
425EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
426{
427 return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new,
428 (char *(*)())d2i_AutoPrivateKey, (fp),(unsigned char **)(a)));
429}
430
431int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey)
432 {
433 return(ASN1_i2d_fp(i2d_PUBKEY,fp,(unsigned char *)pkey));
434 }
435
436EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a)
437{
438 return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new,
439 (char *(*)())d2i_PUBKEY, (fp),(unsigned char **)(a)));
440}
441
442#endif
443
444PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
445 PKCS8_PRIV_KEY_INFO **p8inf)
446 {
447 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio(
448 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
449 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp),
450 (unsigned char **)(p8inf)));
451 }
452
453int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
454 {
455 return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf));
456 }
457
458int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
459 {
460 PKCS8_PRIV_KEY_INFO *p8inf;
461 int ret;
462 p8inf = EVP_PKEY2PKCS8(key);
463 if(!p8inf) return 0;
464 ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
465 PKCS8_PRIV_KEY_INFO_free(p8inf);
466 return ret;
467 }
468
469int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey)
470 {
471 return(ASN1_i2d_bio(i2d_PrivateKey,bp,(unsigned char *)pkey));
472 }
473
474EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a)
475 {
476 return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new,
477 (char *(*)())d2i_AutoPrivateKey, (bp),(unsigned char **)(a)));
478 }
479
480int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey)
481 {
482 return(ASN1_i2d_bio(i2d_PUBKEY,bp,(unsigned char *)pkey));
483 }
484
485EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a)
486 {
487 return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new,
488 (char *(*)())d2i_PUBKEY, (bp),(unsigned char **)(a)));
489 }
diff --git a/src/lib/libcrypto/x509v3/ext_dat.h b/src/lib/libcrypto/x509v3/ext_dat.h
deleted file mode 100644
index d8328ac468..0000000000
--- a/src/lib/libcrypto/x509v3/ext_dat.h
+++ /dev/null
@@ -1,118 +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-2004 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, v3_sinfo;
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_crl_invdate;
64extern X509V3_EXT_METHOD v3_delta_crl, v3_cpols, v3_crld;
65extern X509V3_EXT_METHOD v3_ocsp_nonce, v3_ocsp_accresp, v3_ocsp_acutoff;
66extern X509V3_EXT_METHOD v3_ocsp_crlid, v3_ocsp_nocheck, v3_ocsp_serviceloc;
67extern X509V3_EXT_METHOD v3_crl_hold, v3_pci;
68
69/* This table will be searched using OBJ_bsearch so it *must* kept in
70 * order of the ext_nid values.
71 */
72
73static X509V3_EXT_METHOD *standard_exts[] = {
74&v3_nscert,
75&v3_ns_ia5_list[0],
76&v3_ns_ia5_list[1],
77&v3_ns_ia5_list[2],
78&v3_ns_ia5_list[3],
79&v3_ns_ia5_list[4],
80&v3_ns_ia5_list[5],
81&v3_ns_ia5_list[6],
82&v3_skey_id,
83&v3_key_usage,
84&v3_pkey_usage_period,
85&v3_alt[0],
86&v3_alt[1],
87&v3_bcons,
88&v3_crl_num,
89&v3_cpols,
90&v3_akey_id,
91&v3_crld,
92&v3_ext_ku,
93&v3_delta_crl,
94&v3_crl_reason,
95#ifndef OPENSSL_NO_OCSP
96&v3_crl_invdate,
97#endif
98&v3_sxnet,
99&v3_info,
100#ifndef OPENSSL_NO_OCSP
101&v3_ocsp_nonce,
102&v3_ocsp_crlid,
103&v3_ocsp_accresp,
104&v3_ocsp_nocheck,
105&v3_ocsp_acutoff,
106&v3_ocsp_serviceloc,
107#endif
108&v3_sinfo,
109#ifndef OPENSSL_NO_OCSP
110&v3_crl_hold,
111#endif
112&v3_pci,
113};
114
115/* Number of standard extensions */
116
117#define STANDARD_EXTENSION_COUNT (sizeof(standard_exts)/sizeof(X509V3_EXT_METHOD *))
118
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c
deleted file mode 100644
index 97e686f97a..0000000000
--- a/src/lib/libcrypto/x509v3/v3_akey.c
+++ /dev/null
@@ -1,190 +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/asn1t.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, ASN1_ITEM_ref(AUTHORITY_KEYID),
730,0,0,0,
740,0,
75(X509V3_EXT_I2V)i2v_AUTHORITY_KEYID,
76(X509V3_EXT_V2I)v2i_AUTHORITY_KEYID,
770,0,
78NULL
79};
80
81static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
82 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist)
83{
84 char *tmp;
85 if(akeyid->keyid) {
86 tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length);
87 X509V3_add_value("keyid", tmp, &extlist);
88 OPENSSL_free(tmp);
89 }
90 if(akeyid->issuer)
91 extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
92 if(akeyid->serial) {
93 tmp = hex_to_string(akeyid->serial->data,
94 akeyid->serial->length);
95 X509V3_add_value("serial", tmp, &extlist);
96 OPENSSL_free(tmp);
97 }
98 return extlist;
99}
100
101/* Currently two options:
102 * keyid: use the issuers subject keyid, the value 'always' means its is
103 * an error if the issuer certificate doesn't have a key id.
104 * issuer: use the issuers cert issuer and serial number. The default is
105 * to only use this if keyid is not present. With the option 'always'
106 * this is always included.
107 */
108
109static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
110 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
111{
112char keyid=0, issuer=0;
113int i;
114CONF_VALUE *cnf;
115ASN1_OCTET_STRING *ikeyid = NULL;
116X509_NAME *isname = NULL;
117GENERAL_NAMES * gens = NULL;
118GENERAL_NAME *gen = NULL;
119ASN1_INTEGER *serial = NULL;
120X509_EXTENSION *ext;
121X509 *cert;
122AUTHORITY_KEYID *akeyid;
123for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
124 cnf = sk_CONF_VALUE_value(values, i);
125 if(!strcmp(cnf->name, "keyid")) {
126 keyid = 1;
127 if(cnf->value && !strcmp(cnf->value, "always")) keyid = 2;
128 } else if(!strcmp(cnf->name, "issuer")) {
129 issuer = 1;
130 if(cnf->value && !strcmp(cnf->value, "always")) issuer = 2;
131 } else {
132 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION);
133 ERR_add_error_data(2, "name=", cnf->name);
134 return NULL;
135 }
136}
137
138if(!ctx || !ctx->issuer_cert) {
139 if(ctx && (ctx->flags==CTX_TEST)) return AUTHORITY_KEYID_new();
140 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE);
141 return NULL;
142}
143
144cert = ctx->issuer_cert;
145
146if(keyid) {
147 i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
148 if((i >= 0) && (ext = X509_get_ext(cert, i)))
149 ikeyid = X509V3_EXT_d2i(ext);
150 if(keyid==2 && !ikeyid) {
151 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
152 return NULL;
153 }
154}
155
156if((issuer && !ikeyid) || (issuer == 2)) {
157 isname = X509_NAME_dup(X509_get_issuer_name(cert));
158 serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert));
159 if(!isname || !serial) {
160 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
161 goto err;
162 }
163}
164
165if(!(akeyid = AUTHORITY_KEYID_new())) goto err;
166
167if(isname) {
168 if(!(gens = sk_GENERAL_NAME_new_null()) || !(gen = GENERAL_NAME_new())
169 || !sk_GENERAL_NAME_push(gens, gen)) {
170 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE);
171 goto err;
172 }
173 gen->type = GEN_DIRNAME;
174 gen->d.dirn = isname;
175}
176
177akeyid->issuer = gens;
178akeyid->serial = serial;
179akeyid->keyid = ikeyid;
180
181return akeyid;
182
183err:
184X509_NAME_free(isname);
185M_ASN1_INTEGER_free(serial);
186M_ASN1_OCTET_STRING_free(ikeyid);
187return NULL;
188
189}
190
diff --git a/src/lib/libcrypto/x509v3/v3_akeya.c b/src/lib/libcrypto/x509v3/v3_akeya.c
deleted file mode 100644
index 2aafa26ba7..0000000000
--- a/src/lib/libcrypto/x509v3/v3_akeya.c
+++ /dev/null
@@ -1,72 +0,0 @@
1/* v3_akey_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h>
65
66ASN1_SEQUENCE(AUTHORITY_KEYID) = {
67 ASN1_IMP_OPT(AUTHORITY_KEYID, keyid, ASN1_OCTET_STRING, 0),
68 ASN1_IMP_SEQUENCE_OF_OPT(AUTHORITY_KEYID, issuer, GENERAL_NAME, 1),
69 ASN1_IMP_OPT(AUTHORITY_KEYID, serial, ASN1_INTEGER, 2)
70} ASN1_SEQUENCE_END(AUTHORITY_KEYID)
71
72IMPLEMENT_ASN1_FUNCTIONS(AUTHORITY_KEYID)
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c
deleted file mode 100644
index 58b935a3b6..0000000000
--- a/src/lib/libcrypto/x509v3/v3_alt.c
+++ /dev/null
@@ -1,458 +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 GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
65static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p);
67static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens);
68X509V3_EXT_METHOD v3_alt[] = {
69{ NID_subject_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
700,0,0,0,
710,0,
72(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
73(X509V3_EXT_V2I)v2i_subject_alt,
74NULL, NULL, NULL},
75
76{ NID_issuer_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
770,0,0,0,
780,0,
79(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
80(X509V3_EXT_V2I)v2i_issuer_alt,
81NULL, NULL, NULL},
82};
83
84STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
85 GENERAL_NAMES *gens, STACK_OF(CONF_VALUE) *ret)
86{
87 int i;
88 GENERAL_NAME *gen;
89 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
90 gen = sk_GENERAL_NAME_value(gens, i);
91 ret = i2v_GENERAL_NAME(method, gen, ret);
92 }
93 if(!ret) return sk_CONF_VALUE_new_null();
94 return ret;
95}
96
97STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
98 GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret)
99{
100 unsigned char *p;
101 char oline[256];
102 switch (gen->type)
103 {
104 case GEN_OTHERNAME:
105 X509V3_add_value("othername","<unsupported>", &ret);
106 break;
107
108 case GEN_X400:
109 X509V3_add_value("X400Name","<unsupported>", &ret);
110 break;
111
112 case GEN_EDIPARTY:
113 X509V3_add_value("EdiPartyName","<unsupported>", &ret);
114 break;
115
116 case GEN_EMAIL:
117 X509V3_add_value_uchar("email",gen->d.ia5->data, &ret);
118 break;
119
120 case GEN_DNS:
121 X509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret);
122 break;
123
124 case GEN_URI:
125 X509V3_add_value_uchar("URI",gen->d.ia5->data, &ret);
126 break;
127
128 case GEN_DIRNAME:
129 X509_NAME_oneline(gen->d.dirn, oline, 256);
130 X509V3_add_value("DirName",oline, &ret);
131 break;
132
133 case GEN_IPADD:
134 p = gen->d.ip->data;
135 /* BUG: doesn't support IPV6 */
136 if(gen->d.ip->length != 4) {
137 X509V3_add_value("IP Address","<invalid>", &ret);
138 break;
139 }
140 BIO_snprintf(oline, sizeof oline,
141 "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
142 X509V3_add_value("IP Address",oline, &ret);
143 break;
144
145 case GEN_RID:
146 i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
147 X509V3_add_value("Registered ID",oline, &ret);
148 break;
149 }
150 return ret;
151}
152
153int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen)
154{
155 unsigned char *p;
156 switch (gen->type)
157 {
158 case GEN_OTHERNAME:
159 BIO_printf(out, "othername:<unsupported>");
160 break;
161
162 case GEN_X400:
163 BIO_printf(out, "X400Name:<unsupported>");
164 break;
165
166 case GEN_EDIPARTY:
167 /* Maybe fix this: it is supported now */
168 BIO_printf(out, "EdiPartyName:<unsupported>");
169 break;
170
171 case GEN_EMAIL:
172 BIO_printf(out, "email:%s",gen->d.ia5->data);
173 break;
174
175 case GEN_DNS:
176 BIO_printf(out, "DNS:%s",gen->d.ia5->data);
177 break;
178
179 case GEN_URI:
180 BIO_printf(out, "URI:%s",gen->d.ia5->data);
181 break;
182
183 case GEN_DIRNAME:
184 BIO_printf(out, "DirName: ");
185 X509_NAME_print_ex(out, gen->d.dirn, 0, XN_FLAG_ONELINE);
186 break;
187
188 case GEN_IPADD:
189 p = gen->d.ip->data;
190 /* BUG: doesn't support IPV6 */
191 if(gen->d.ip->length != 4) {
192 BIO_printf(out,"IP Address:<invalid>");
193 break;
194 }
195 BIO_printf(out, "IP Address:%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
196 break;
197
198 case GEN_RID:
199 BIO_printf(out, "Registered ID");
200 i2a_ASN1_OBJECT(out, gen->d.rid);
201 break;
202 }
203 return 1;
204}
205
206static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method,
207 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
208{
209 GENERAL_NAMES *gens = NULL;
210 CONF_VALUE *cnf;
211 int i;
212 if(!(gens = sk_GENERAL_NAME_new_null())) {
213 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
214 return NULL;
215 }
216 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
217 cnf = sk_CONF_VALUE_value(nval, i);
218 if(!name_cmp(cnf->name, "issuer") && cnf->value &&
219 !strcmp(cnf->value, "copy")) {
220 if(!copy_issuer(ctx, gens)) goto err;
221 } else {
222 GENERAL_NAME *gen;
223 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
224 goto err;
225 sk_GENERAL_NAME_push(gens, gen);
226 }
227 }
228 return gens;
229 err:
230 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
231 return NULL;
232}
233
234/* Append subject altname of issuer to issuer alt name of subject */
235
236static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens)
237{
238 GENERAL_NAMES *ialt;
239 GENERAL_NAME *gen;
240 X509_EXTENSION *ext;
241 int i;
242 if(ctx && (ctx->flags == CTX_TEST)) return 1;
243 if(!ctx || !ctx->issuer_cert) {
244 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_NO_ISSUER_DETAILS);
245 goto err;
246 }
247 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
248 if(i < 0) return 1;
249 if(!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
250 !(ialt = X509V3_EXT_d2i(ext)) ) {
251 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR);
252 goto err;
253 }
254
255 for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
256 gen = sk_GENERAL_NAME_value(ialt, i);
257 if(!sk_GENERAL_NAME_push(gens, gen)) {
258 X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE);
259 goto err;
260 }
261 }
262 sk_GENERAL_NAME_free(ialt);
263
264 return 1;
265
266 err:
267 return 0;
268
269}
270
271static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method,
272 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
273{
274 GENERAL_NAMES *gens = NULL;
275 CONF_VALUE *cnf;
276 int i;
277 if(!(gens = sk_GENERAL_NAME_new_null())) {
278 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
279 return NULL;
280 }
281 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
282 cnf = sk_CONF_VALUE_value(nval, i);
283 if(!name_cmp(cnf->name, "email") && cnf->value &&
284 !strcmp(cnf->value, "copy")) {
285 if(!copy_email(ctx, gens, 0)) goto err;
286 } else if(!name_cmp(cnf->name, "email") && cnf->value &&
287 !strcmp(cnf->value, "move")) {
288 if(!copy_email(ctx, gens, 1)) goto err;
289 } else {
290 GENERAL_NAME *gen;
291 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
292 goto err;
293 sk_GENERAL_NAME_push(gens, gen);
294 }
295 }
296 return gens;
297 err:
298 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
299 return NULL;
300}
301
302/* Copy any email addresses in a certificate or request to
303 * GENERAL_NAMES
304 */
305
306static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
307{
308 X509_NAME *nm;
309 ASN1_IA5STRING *email = NULL;
310 X509_NAME_ENTRY *ne;
311 GENERAL_NAME *gen = NULL;
312 int i;
313 if(ctx->flags == CTX_TEST) return 1;
314 if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
315 X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS);
316 goto err;
317 }
318 /* Find the subject name */
319 if(ctx->subject_cert) nm = X509_get_subject_name(ctx->subject_cert);
320 else nm = X509_REQ_get_subject_name(ctx->subject_req);
321
322 /* Now add any email address(es) to STACK */
323 i = -1;
324 while((i = X509_NAME_get_index_by_NID(nm,
325 NID_pkcs9_emailAddress, i)) >= 0) {
326 ne = X509_NAME_get_entry(nm, i);
327 email = M_ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne));
328 if (move_p)
329 {
330 X509_NAME_delete_entry(nm, i);
331 i--;
332 }
333 if(!email || !(gen = GENERAL_NAME_new())) {
334 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
335 goto err;
336 }
337 gen->d.ia5 = email;
338 email = NULL;
339 gen->type = GEN_EMAIL;
340 if(!sk_GENERAL_NAME_push(gens, gen)) {
341 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
342 goto err;
343 }
344 gen = NULL;
345 }
346
347
348 return 1;
349
350 err:
351 GENERAL_NAME_free(gen);
352 M_ASN1_IA5STRING_free(email);
353 return 0;
354
355}
356
357GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
358 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
359{
360 GENERAL_NAME *gen;
361 GENERAL_NAMES *gens = NULL;
362 CONF_VALUE *cnf;
363 int i;
364 if(!(gens = sk_GENERAL_NAME_new_null())) {
365 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
366 return NULL;
367 }
368 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
369 cnf = sk_CONF_VALUE_value(nval, i);
370 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
371 sk_GENERAL_NAME_push(gens, gen);
372 }
373 return gens;
374 err:
375 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
376 return NULL;
377}
378
379GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
380 CONF_VALUE *cnf)
381{
382char is_string = 0;
383int type;
384GENERAL_NAME *gen = NULL;
385
386char *name, *value;
387
388name = cnf->name;
389value = cnf->value;
390
391if(!value) {
392 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE);
393 return NULL;
394}
395
396if(!(gen = GENERAL_NAME_new())) {
397 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
398 return NULL;
399}
400
401if(!name_cmp(name, "email")) {
402 is_string = 1;
403 type = GEN_EMAIL;
404} else if(!name_cmp(name, "URI")) {
405 is_string = 1;
406 type = GEN_URI;
407} else if(!name_cmp(name, "DNS")) {
408 is_string = 1;
409 type = GEN_DNS;
410} else if(!name_cmp(name, "RID")) {
411 ASN1_OBJECT *obj;
412 if(!(obj = OBJ_txt2obj(value,0))) {
413 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT);
414 ERR_add_error_data(2, "value=", value);
415 goto err;
416 }
417 gen->d.rid = obj;
418 type = GEN_RID;
419} else if(!name_cmp(name, "IP")) {
420 int i1,i2,i3,i4;
421 unsigned char ip[4];
422 if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) ||
423 (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) ||
424 (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) {
425 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS);
426 ERR_add_error_data(2, "value=", value);
427 goto err;
428 }
429 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4;
430 if(!(gen->d.ip = M_ASN1_OCTET_STRING_new()) ||
431 !ASN1_STRING_set(gen->d.ip, ip, 4)) {
432 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
433 goto err;
434 }
435 type = GEN_IPADD;
436} else {
437 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION);
438 ERR_add_error_data(2, "name=", name);
439 goto err;
440}
441
442if(is_string) {
443 if(!(gen->d.ia5 = M_ASN1_IA5STRING_new()) ||
444 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
445 strlen(value))) {
446 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
447 goto err;
448 }
449}
450
451gen->type = type;
452
453return gen;
454
455err:
456GENERAL_NAME_free(gen);
457return NULL;
458}
diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c
deleted file mode 100644
index cbb012715e..0000000000
--- a/src/lib/libcrypto/x509v3/v3_bcons.c
+++ /dev/null
@@ -1,124 +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/asn1t.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,
72ASN1_ITEM_ref(BASIC_CONSTRAINTS),
730,0,0,0,
740,0,
75(X509V3_EXT_I2V)i2v_BASIC_CONSTRAINTS,
76(X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
77NULL,NULL,
78NULL
79};
80
81ASN1_SEQUENCE(BASIC_CONSTRAINTS) = {
82 ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN),
83 ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER)
84} ASN1_SEQUENCE_END(BASIC_CONSTRAINTS)
85
86IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)
87
88
89static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
90 BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist)
91{
92 X509V3_add_value_bool("CA", bcons->ca, &extlist);
93 X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
94 return extlist;
95}
96
97static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
98 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
99{
100 BASIC_CONSTRAINTS *bcons=NULL;
101 CONF_VALUE *val;
102 int i;
103 if(!(bcons = BASIC_CONSTRAINTS_new())) {
104 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE);
105 return NULL;
106 }
107 for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
108 val = sk_CONF_VALUE_value(values, i);
109 if(!strcmp(val->name, "CA")) {
110 if(!X509V3_get_value_bool(val, &bcons->ca)) goto err;
111 } else if(!strcmp(val->name, "pathlen")) {
112 if(!X509V3_get_value_int(val, &bcons->pathlen)) goto err;
113 } else {
114 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME);
115 X509V3_conf_err(val);
116 goto err;
117 }
118 }
119 return bcons;
120 err:
121 BASIC_CONSTRAINTS_free(bcons);
122 return NULL;
123}
124
diff --git a/src/lib/libcrypto/x509v3/v3_bitst.c b/src/lib/libcrypto/x509v3/v3_bitst.c
deleted file mode 100644
index 274965306d..0000000000
--- a/src/lib/libcrypto/x509v3/v3_bitst.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/* v3_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static ASN1_BIT_STRING *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);
69
70static BIT_STRING_BITNAME ns_cert_type_table[] = {
71{0, "SSL Client", "client"},
72{1, "SSL Server", "server"},
73{2, "S/MIME", "email"},
74{3, "Object Signing", "objsign"},
75{4, "Unused", "reserved"},
76{5, "SSL CA", "sslCA"},
77{6, "S/MIME CA", "emailCA"},
78{7, "Object Signing CA", "objCA"},
79{-1, NULL, NULL}
80};
81
82static BIT_STRING_BITNAME key_usage_type_table[] = {
83{0, "Digital Signature", "digitalSignature"},
84{1, "Non Repudiation", "nonRepudiation"},
85{2, "Key Encipherment", "keyEncipherment"},
86{3, "Data Encipherment", "dataEncipherment"},
87{4, "Key Agreement", "keyAgreement"},
88{5, "Certificate Sign", "keyCertSign"},
89{6, "CRL Sign", "cRLSign"},
90{7, "Encipher Only", "encipherOnly"},
91{8, "Decipher Only", "decipherOnly"},
92{-1, NULL, NULL}
93};
94
95
96
97X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
98X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table);
99
100static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
101 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret)
102{
103 BIT_STRING_BITNAME *bnam;
104 for(bnam =method->usr_data; bnam->lname; bnam++) {
105 if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
106 X509V3_add_value(bnam->lname, NULL, &ret);
107 }
108 return ret;
109}
110
111static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
112 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
113{
114 CONF_VALUE *val;
115 ASN1_BIT_STRING *bs;
116 int i;
117 BIT_STRING_BITNAME *bnam;
118 if(!(bs = M_ASN1_BIT_STRING_new())) {
119 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE);
120 return NULL;
121 }
122 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
123 val = sk_CONF_VALUE_value(nval, i);
124 for(bnam = method->usr_data; bnam->lname; bnam++) {
125 if(!strcmp(bnam->sname, val->name) ||
126 !strcmp(bnam->lname, val->name) ) {
127 if(!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
128 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
129 ERR_R_MALLOC_FAILURE);
130 M_ASN1_BIT_STRING_free(bs);
131 return NULL;
132 }
133 break;
134 }
135 }
136 if(!bnam->lname) {
137 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
138 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
139 X509V3_conf_err(val);
140 M_ASN1_BIT_STRING_free(bs);
141 return NULL;
142 }
143 }
144 return bs;
145}
146
147
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
deleted file mode 100644
index 1284d5aaa5..0000000000
--- a/src/lib/libcrypto/x509v3/v3_conf.c
+++ /dev/null
@@ -1,485 +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_nconf(CONF *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/* CONF *conf: Config file */
78/* char *name: Name */
79/* char *value: Value */
80X509_EXTENSION *X509V3_EXT_nconf(CONF *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_nconf(conf, ctx, OBJ_sn2nid(name), crit, value);
90 if (!ret)
91 {
92 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_ERROR_IN_EXTENSION);
93 ERR_add_error_data(4,"name=", name, ", value=", value);
94 }
95 return ret;
96 }
97
98/* CONF *conf: Config file */
99/* char *value: Value */
100X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid,
101 char *value)
102 {
103 int crit;
104 int ext_type;
105 crit = v3_check_critical(&value);
106 if ((ext_type = v3_check_generic(&value)))
107 return v3_generic_extension(OBJ_nid2sn(ext_nid),
108 value, crit, ext_type);
109 return do_ext_nconf(conf, ctx, ext_nid, crit, value);
110 }
111
112/* CONF *conf: Config file */
113/* char *value: Value */
114static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
115 int crit, char *value)
116 {
117 X509V3_EXT_METHOD *method;
118 X509_EXTENSION *ext;
119 STACK_OF(CONF_VALUE) *nval;
120 void *ext_struc;
121 if (ext_nid == NID_undef)
122 {
123 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION_NAME);
124 return NULL;
125 }
126 if (!(method = X509V3_EXT_get_nid(ext_nid)))
127 {
128 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION);
129 return NULL;
130 }
131 /* Now get internal extension representation based on type */
132 if (method->v2i)
133 {
134 if(*value == '@') nval = NCONF_get_section(conf, value + 1);
135 else nval = X509V3_parse_list(value);
136 if(!nval)
137 {
138 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_INVALID_EXTENSION_STRING);
139 ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value);
140 return NULL;
141 }
142 ext_struc = method->v2i(method, ctx, nval);
143 if(*value != '@') sk_CONF_VALUE_pop_free(nval,
144 X509V3_conf_free);
145 if(!ext_struc) return NULL;
146 }
147 else if(method->s2i)
148 {
149 if(!(ext_struc = method->s2i(method, ctx, value))) return NULL;
150 }
151 else if(method->r2i)
152 {
153 if(!ctx->db)
154 {
155 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_NO_CONFIG_DATABASE);
156 return NULL;
157 }
158 if(!(ext_struc = method->r2i(method, ctx, value))) return NULL;
159 }
160 else
161 {
162 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
163 ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid));
164 return NULL;
165 }
166
167 ext = do_ext_i2d(method, ext_nid, crit, ext_struc);
168 if(method->it) ASN1_item_free(ext_struc, ASN1_ITEM_ptr(method->it));
169 else method->ext_free(ext_struc);
170 return ext;
171
172 }
173
174static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
175 int crit, void *ext_struc)
176 {
177 unsigned char *ext_der;
178 int ext_len;
179 ASN1_OCTET_STRING *ext_oct;
180 X509_EXTENSION *ext;
181 /* Convert internal representation to DER */
182 if (method->it)
183 {
184 ext_der = NULL;
185 ext_len = ASN1_item_i2d(ext_struc, &ext_der, ASN1_ITEM_ptr(method->it));
186 if (ext_len < 0) goto merr;
187 }
188 else
189 {
190 unsigned char *p;
191 ext_len = method->i2d(ext_struc, NULL);
192 if(!(ext_der = OPENSSL_malloc(ext_len))) goto merr;
193 p = ext_der;
194 method->i2d(ext_struc, &p);
195 }
196 if (!(ext_oct = M_ASN1_OCTET_STRING_new())) goto merr;
197 ext_oct->data = ext_der;
198 ext_oct->length = ext_len;
199
200 ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
201 if (!ext) goto merr;
202 M_ASN1_OCTET_STRING_free(ext_oct);
203
204 return ext;
205
206 merr:
207 X509V3err(X509V3_F_DO_EXT_I2D,ERR_R_MALLOC_FAILURE);
208 return NULL;
209
210 }
211
212/* Given an internal structure, nid and critical flag create an extension */
213
214X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
215 {
216 X509V3_EXT_METHOD *method;
217 if (!(method = X509V3_EXT_get_nid(ext_nid))) {
218 X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION);
219 return NULL;
220 }
221 return do_ext_i2d(method, ext_nid, crit, ext_struc);
222}
223
224/* Check the extension string for critical flag */
225static int v3_check_critical(char **value)
226{
227 char *p = *value;
228 if ((strlen(p) < 9) || strncmp(p, "critical,", 9)) return 0;
229 p+=9;
230 while(isspace((unsigned char)*p)) p++;
231 *value = p;
232 return 1;
233}
234
235/* Check extension string for generic extension and return the type */
236static int v3_check_generic(char **value)
237{
238 char *p = *value;
239 if ((strlen(p) < 4) || strncmp(p, "DER:", 4)) return 0;
240 p+=4;
241 while (isspace((unsigned char)*p)) p++;
242 *value = p;
243 return 1;
244}
245
246/* Create a generic extension: for now just handle DER type */
247static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
248 int crit, int type)
249 {
250 unsigned char *ext_der=NULL;
251 long ext_len;
252 ASN1_OBJECT *obj=NULL;
253 ASN1_OCTET_STRING *oct=NULL;
254 X509_EXTENSION *extension=NULL;
255 if (!(obj = OBJ_txt2obj(ext, 0)))
256 {
257 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_NAME_ERROR);
258 ERR_add_error_data(2, "name=", ext);
259 goto err;
260 }
261
262 if (!(ext_der = string_to_hex(value, &ext_len)))
263 {
264 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR);
265 ERR_add_error_data(2, "value=", value);
266 goto err;
267 }
268
269 if (!(oct = M_ASN1_OCTET_STRING_new()))
270 {
271 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE);
272 goto err;
273 }
274
275 oct->data = ext_der;
276 oct->length = ext_len;
277 ext_der = NULL;
278
279 extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
280
281 err:
282 ASN1_OBJECT_free(obj);
283 M_ASN1_OCTET_STRING_free(oct);
284 if(ext_der) OPENSSL_free(ext_der);
285 return extension;
286
287 }
288
289
290/* This is the main function: add a bunch of extensions based on a config file
291 * section to an extension STACK.
292 */
293
294
295int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section,
296 STACK_OF(X509_EXTENSION) **sk)
297 {
298 X509_EXTENSION *ext;
299 STACK_OF(CONF_VALUE) *nval;
300 CONF_VALUE *val;
301 int i;
302 if (!(nval = NCONF_get_section(conf, section))) return 0;
303 for (i = 0; i < sk_CONF_VALUE_num(nval); i++)
304 {
305 val = sk_CONF_VALUE_value(nval, i);
306 if (!(ext = X509V3_EXT_nconf(conf, ctx, val->name, val->value)))
307 return 0;
308 if (sk) X509v3_add_ext(sk, ext, -1);
309 X509_EXTENSION_free(ext);
310 }
311 return 1;
312 }
313
314/* Convenience functions to add extensions to a certificate, CRL and request */
315
316int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
317 X509 *cert)
318 {
319 STACK_OF(X509_EXTENSION) **sk = NULL;
320 if (cert)
321 sk = &cert->cert_info->extensions;
322 return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
323 }
324
325/* Same as above but for a CRL */
326
327int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
328 X509_CRL *crl)
329 {
330 STACK_OF(X509_EXTENSION) **sk = NULL;
331 if (crl)
332 sk = &crl->crl->extensions;
333 return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
334 }
335
336/* Add extensions to certificate request */
337
338int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
339 X509_REQ *req)
340 {
341 STACK_OF(X509_EXTENSION) *extlist = NULL, **sk = NULL;
342 int i;
343 if (req)
344 sk = &extlist;
345 i = X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
346 if (!i || !sk)
347 return i;
348 i = X509_REQ_add_extensions(req, extlist);
349 sk_X509_EXTENSION_pop_free(extlist, X509_EXTENSION_free);
350 return i;
351 }
352
353/* Config database functions */
354
355char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
356 {
357 if (ctx->db_meth->get_string)
358 return ctx->db_meth->get_string(ctx->db, name, section);
359 return NULL;
360 }
361
362STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section)
363 {
364 if (ctx->db_meth->get_section)
365 return ctx->db_meth->get_section(ctx->db, section);
366 return NULL;
367 }
368
369void X509V3_string_free(X509V3_CTX *ctx, char *str)
370 {
371 if (!str) return;
372 if (ctx->db_meth->free_string)
373 ctx->db_meth->free_string(ctx->db, str);
374 }
375
376void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
377 {
378 if (!section) return;
379 if (ctx->db_meth->free_section)
380 ctx->db_meth->free_section(ctx->db, section);
381 }
382
383static char *nconf_get_string(void *db, char *section, char *value)
384 {
385 return NCONF_get_string(db, section, value);
386 }
387
388static STACK_OF(CONF_VALUE) *nconf_get_section(void *db, char *section)
389 {
390 return NCONF_get_section(db, section);
391 }
392
393static X509V3_CONF_METHOD nconf_method = {
394nconf_get_string,
395nconf_get_section,
396NULL,
397NULL
398};
399
400void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf)
401 {
402 ctx->db_meth = &nconf_method;
403 ctx->db = conf;
404 }
405
406void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
407 X509_CRL *crl, int flags)
408 {
409 ctx->issuer_cert = issuer;
410 ctx->subject_cert = subj;
411 ctx->crl = crl;
412 ctx->subject_req = req;
413 ctx->flags = flags;
414 }
415
416/* Old conf compatibility functions */
417
418X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
419 char *value)
420 {
421 CONF ctmp;
422 CONF_set_nconf(&ctmp, conf);
423 return X509V3_EXT_nconf(&ctmp, ctx, name, value);
424 }
425
426/* LHASH *conf: Config file */
427/* char *value: Value */
428X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
429 char *value)
430 {
431 CONF ctmp;
432 CONF_set_nconf(&ctmp, conf);
433 return X509V3_EXT_nconf_nid(&ctmp, ctx, ext_nid, value);
434 }
435
436static char *conf_lhash_get_string(void *db, char *section, char *value)
437 {
438 return CONF_get_string(db, section, value);
439 }
440
441static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section)
442 {
443 return CONF_get_section(db, section);
444 }
445
446static X509V3_CONF_METHOD conf_lhash_method = {
447conf_lhash_get_string,
448conf_lhash_get_section,
449NULL,
450NULL
451};
452
453void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash)
454 {
455 ctx->db_meth = &conf_lhash_method;
456 ctx->db = lhash;
457 }
458
459int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
460 X509 *cert)
461 {
462 CONF ctmp;
463 CONF_set_nconf(&ctmp, conf);
464 return X509V3_EXT_add_nconf(&ctmp, ctx, section, cert);
465 }
466
467/* Same as above but for a CRL */
468
469int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
470 X509_CRL *crl)
471 {
472 CONF ctmp;
473 CONF_set_nconf(&ctmp, conf);
474 return X509V3_EXT_CRL_add_nconf(&ctmp, ctx, section, crl);
475 }
476
477/* Add extensions to certificate request */
478
479int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
480 X509_REQ *req)
481 {
482 CONF ctmp;
483 CONF_set_nconf(&ctmp, conf);
484 return X509V3_EXT_REQ_add_nconf(&ctmp, ctx, section, req);
485 }
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
deleted file mode 100644
index 867525f336..0000000000
--- a/src/lib/libcrypto/x509v3/v3_cpols.c
+++ /dev/null
@@ -1,431 +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/asn1t.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 int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos);
77
78X509V3_EXT_METHOD v3_cpols = {
79NID_certificate_policies, 0,ASN1_ITEM_ref(CERTIFICATEPOLICIES),
800,0,0,0,
810,0,
820,0,
83(X509V3_EXT_I2R)i2r_certpol,
84(X509V3_EXT_R2I)r2i_certpol,
85NULL
86};
87
88ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) =
89 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO)
90ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES)
91
92IMPLEMENT_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)
93
94ASN1_SEQUENCE(POLICYINFO) = {
95 ASN1_SIMPLE(POLICYINFO, policyid, ASN1_OBJECT),
96 ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO)
97} ASN1_SEQUENCE_END(POLICYINFO)
98
99IMPLEMENT_ASN1_FUNCTIONS(POLICYINFO)
100
101ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY);
102
103ASN1_ADB(POLICYQUALINFO) = {
104 ADB_ENTRY(NID_id_qt_cps, ASN1_SIMPLE(POLICYQUALINFO, d.cpsuri, ASN1_IA5STRING)),
105 ADB_ENTRY(NID_id_qt_unotice, ASN1_SIMPLE(POLICYQUALINFO, d.usernotice, USERNOTICE))
106} ASN1_ADB_END(POLICYQUALINFO, 0, pqualid, 0, &policydefault_tt, NULL);
107
108ASN1_SEQUENCE(POLICYQUALINFO) = {
109 ASN1_SIMPLE(POLICYQUALINFO, pqualid, ASN1_OBJECT),
110 ASN1_ADB_OBJECT(POLICYQUALINFO)
111} ASN1_SEQUENCE_END(POLICYQUALINFO)
112
113IMPLEMENT_ASN1_FUNCTIONS(POLICYQUALINFO)
114
115ASN1_SEQUENCE(USERNOTICE) = {
116 ASN1_OPT(USERNOTICE, noticeref, NOTICEREF),
117 ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT)
118} ASN1_SEQUENCE_END(USERNOTICE)
119
120IMPLEMENT_ASN1_FUNCTIONS(USERNOTICE)
121
122ASN1_SEQUENCE(NOTICEREF) = {
123 ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT),
124 ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER)
125} ASN1_SEQUENCE_END(NOTICEREF)
126
127IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF)
128
129static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
130 X509V3_CTX *ctx, char *value)
131{
132 STACK_OF(POLICYINFO) *pols = NULL;
133 char *pstr;
134 POLICYINFO *pol;
135 ASN1_OBJECT *pobj;
136 STACK_OF(CONF_VALUE) *vals;
137 CONF_VALUE *cnf;
138 int i, ia5org;
139 pols = sk_POLICYINFO_new_null();
140 if (pols == NULL) {
141 X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE);
142 return NULL;
143 }
144 vals = X509V3_parse_list(value);
145 if (vals == NULL) {
146 X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_X509V3_LIB);
147 goto err;
148 }
149 ia5org = 0;
150 for(i = 0; i < sk_CONF_VALUE_num(vals); i++) {
151 cnf = sk_CONF_VALUE_value(vals, i);
152 if(cnf->value || !cnf->name ) {
153 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER);
154 X509V3_conf_err(cnf);
155 goto err;
156 }
157 pstr = cnf->name;
158 if(!strcmp(pstr,"ia5org")) {
159 ia5org = 1;
160 continue;
161 } else if(*pstr == '@') {
162 STACK_OF(CONF_VALUE) *polsect;
163 polsect = X509V3_get_section(ctx, pstr + 1);
164 if(!polsect) {
165 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION);
166
167 X509V3_conf_err(cnf);
168 goto err;
169 }
170 pol = policy_section(ctx, polsect, ia5org);
171 X509V3_section_free(ctx, polsect);
172 if(!pol) goto err;
173 } else {
174 if(!(pobj = OBJ_txt2obj(cnf->name, 0))) {
175 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER);
176 X509V3_conf_err(cnf);
177 goto err;
178 }
179 pol = POLICYINFO_new();
180 pol->policyid = pobj;
181 }
182 sk_POLICYINFO_push(pols, pol);
183 }
184 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
185 return pols;
186 err:
187 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
188 sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
189 return NULL;
190}
191
192static POLICYINFO *policy_section(X509V3_CTX *ctx,
193 STACK_OF(CONF_VALUE) *polstrs, int ia5org)
194{
195 int i;
196 CONF_VALUE *cnf;
197 POLICYINFO *pol;
198 POLICYQUALINFO *qual;
199 if(!(pol = POLICYINFO_new())) goto merr;
200 for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
201 cnf = sk_CONF_VALUE_value(polstrs, i);
202 if(!strcmp(cnf->name, "policyIdentifier")) {
203 ASN1_OBJECT *pobj;
204 if(!(pobj = OBJ_txt2obj(cnf->value, 0))) {
205 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER);
206 X509V3_conf_err(cnf);
207 goto err;
208 }
209 pol->policyid = pobj;
210
211 } else if(!name_cmp(cnf->name, "CPS")) {
212 if(!pol->qualifiers) pol->qualifiers =
213 sk_POLICYQUALINFO_new_null();
214 if(!(qual = POLICYQUALINFO_new())) goto merr;
215 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
216 goto merr;
217 qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
218 qual->d.cpsuri = M_ASN1_IA5STRING_new();
219 if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
220 strlen(cnf->value))) goto merr;
221 } else if(!name_cmp(cnf->name, "userNotice")) {
222 STACK_OF(CONF_VALUE) *unot;
223 if(*cnf->value != '@') {
224 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME);
225 X509V3_conf_err(cnf);
226 goto err;
227 }
228 unot = X509V3_get_section(ctx, cnf->value + 1);
229 if(!unot) {
230 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION);
231
232 X509V3_conf_err(cnf);
233 goto err;
234 }
235 qual = notice_section(ctx, unot, ia5org);
236 X509V3_section_free(ctx, unot);
237 if(!qual) goto err;
238 if(!pol->qualifiers) pol->qualifiers =
239 sk_POLICYQUALINFO_new_null();
240 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
241 goto merr;
242 } else {
243 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION);
244
245 X509V3_conf_err(cnf);
246 goto err;
247 }
248 }
249 if(!pol->policyid) {
250 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER);
251 goto err;
252 }
253
254 return pol;
255
256 merr:
257 X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE);
258
259 err:
260 POLICYINFO_free(pol);
261 return NULL;
262
263
264}
265
266static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
267 STACK_OF(CONF_VALUE) *unot, int ia5org)
268{
269 int i, ret;
270 CONF_VALUE *cnf;
271 USERNOTICE *not;
272 POLICYQUALINFO *qual;
273 if(!(qual = POLICYQUALINFO_new())) goto merr;
274 qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
275 if(!(not = USERNOTICE_new())) goto merr;
276 qual->d.usernotice = not;
277 for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
278 cnf = sk_CONF_VALUE_value(unot, i);
279 if(!strcmp(cnf->name, "explicitText")) {
280 not->exptext = M_ASN1_VISIBLESTRING_new();
281 if(!ASN1_STRING_set(not->exptext, cnf->value,
282 strlen(cnf->value))) goto merr;
283 } else if(!strcmp(cnf->name, "organization")) {
284 NOTICEREF *nref;
285 if(!not->noticeref) {
286 if(!(nref = NOTICEREF_new())) goto merr;
287 not->noticeref = nref;
288 } else nref = not->noticeref;
289 if(ia5org) nref->organization->type = V_ASN1_IA5STRING;
290 else nref->organization->type = V_ASN1_VISIBLESTRING;
291 if(!ASN1_STRING_set(nref->organization, cnf->value,
292 strlen(cnf->value))) goto merr;
293 } else if(!strcmp(cnf->name, "noticeNumbers")) {
294 NOTICEREF *nref;
295 STACK_OF(CONF_VALUE) *nos;
296 if(!not->noticeref) {
297 if(!(nref = NOTICEREF_new())) goto merr;
298 not->noticeref = nref;
299 } else nref = not->noticeref;
300 nos = X509V3_parse_list(cnf->value);
301 if(!nos || !sk_CONF_VALUE_num(nos)) {
302 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS);
303 X509V3_conf_err(cnf);
304 goto err;
305 }
306 ret = nref_nos(nref->noticenos, nos);
307 sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
308 if (!ret)
309 goto err;
310 } else {
311 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION);
312 X509V3_conf_err(cnf);
313 goto err;
314 }
315 }
316
317 if(not->noticeref &&
318 (!not->noticeref->noticenos || !not->noticeref->organization)) {
319 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
320 goto err;
321 }
322
323 return qual;
324
325 merr:
326 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
327
328 err:
329 POLICYQUALINFO_free(qual);
330 return NULL;
331}
332
333static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
334{
335 CONF_VALUE *cnf;
336 ASN1_INTEGER *aint;
337
338 int i;
339
340 for(i = 0; i < sk_CONF_VALUE_num(nos); i++) {
341 cnf = sk_CONF_VALUE_value(nos, i);
342 if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
343 X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER);
344 goto err;
345 }
346 if(!sk_ASN1_INTEGER_push(nnums, aint)) goto merr;
347 }
348 return 1;
349
350 merr:
351 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
352
353 err:
354 sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free);
355 return 0;
356}
357
358
359static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
360 BIO *out, int indent)
361{
362 int i;
363 POLICYINFO *pinfo;
364 /* First print out the policy OIDs */
365 for(i = 0; i < sk_POLICYINFO_num(pol); i++) {
366 pinfo = sk_POLICYINFO_value(pol, i);
367 BIO_printf(out, "%*sPolicy: ", indent, "");
368 i2a_ASN1_OBJECT(out, pinfo->policyid);
369 BIO_puts(out, "\n");
370 if(pinfo->qualifiers)
371 print_qualifiers(out, pinfo->qualifiers, indent + 2);
372 }
373 return 1;
374}
375
376static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
377 int indent)
378{
379 POLICYQUALINFO *qualinfo;
380 int i;
381 for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
382 qualinfo = sk_POLICYQUALINFO_value(quals, i);
383 switch(OBJ_obj2nid(qualinfo->pqualid))
384 {
385 case NID_id_qt_cps:
386 BIO_printf(out, "%*sCPS: %s\n", indent, "",
387 qualinfo->d.cpsuri->data);
388 break;
389
390 case NID_id_qt_unotice:
391 BIO_printf(out, "%*sUser Notice:\n", indent, "");
392 print_notice(out, qualinfo->d.usernotice, indent + 2);
393 break;
394
395 default:
396 BIO_printf(out, "%*sUnknown Qualifier: ",
397 indent + 2, "");
398
399 i2a_ASN1_OBJECT(out, qualinfo->pqualid);
400 BIO_puts(out, "\n");
401 break;
402 }
403 }
404}
405
406static void print_notice(BIO *out, USERNOTICE *notice, int indent)
407{
408 int i;
409 if(notice->noticeref) {
410 NOTICEREF *ref;
411 ref = notice->noticeref;
412 BIO_printf(out, "%*sOrganization: %s\n", indent, "",
413 ref->organization->data);
414 BIO_printf(out, "%*sNumber%s: ", indent, "",
415 sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "");
416 for(i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
417 ASN1_INTEGER *num;
418 char *tmp;
419 num = sk_ASN1_INTEGER_value(ref->noticenos, i);
420 if(i) BIO_puts(out, ", ");
421 tmp = i2s_ASN1_INTEGER(NULL, num);
422 BIO_puts(out, tmp);
423 OPENSSL_free(tmp);
424 }
425 BIO_puts(out, "\n");
426 }
427 if(notice->exptext)
428 BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
429 notice->exptext->data);
430}
431
diff --git a/src/lib/libcrypto/x509v3/v3_crld.c b/src/lib/libcrypto/x509v3/v3_crld.c
deleted file mode 100644
index f90829c574..0000000000
--- a/src/lib/libcrypto/x509v3/v3_crld.c
+++ /dev/null
@@ -1,162 +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/asn1t.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, ASN1_ITEM_ref(CRL_DIST_POINTS),
730,0,0,0,
740,0,
75(X509V3_EXT_I2V)i2v_crld,
76(X509V3_EXT_V2I)v2i_crld,
770,0,
78NULL
79};
80
81static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
82 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts)
83{
84 DIST_POINT *point;
85 int i;
86 for(i = 0; i < sk_DIST_POINT_num(crld); i++) {
87 point = sk_DIST_POINT_value(crld, i);
88 if(point->distpoint) {
89 if(point->distpoint->type == 0)
90 exts = i2v_GENERAL_NAMES(NULL,
91 point->distpoint->name.fullname, exts);
92 else X509V3_add_value("RelativeName","<UNSUPPORTED>", &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 }
99 return exts;
100}
101
102static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
103 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
104{
105 STACK_OF(DIST_POINT) *crld = NULL;
106 GENERAL_NAMES *gens = NULL;
107 GENERAL_NAME *gen = NULL;
108 CONF_VALUE *cnf;
109 int i;
110 if(!(crld = sk_DIST_POINT_new_null())) goto merr;
111 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
112 DIST_POINT *point;
113 cnf = sk_CONF_VALUE_value(nval, i);
114 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
115 if(!(gens = GENERAL_NAMES_new())) goto merr;
116 if(!sk_GENERAL_NAME_push(gens, gen)) goto merr;
117 gen = NULL;
118 if(!(point = DIST_POINT_new())) goto merr;
119 if(!sk_DIST_POINT_push(crld, point)) {
120 DIST_POINT_free(point);
121 goto merr;
122 }
123 if(!(point->distpoint = DIST_POINT_NAME_new())) goto merr;
124 point->distpoint->name.fullname = gens;
125 point->distpoint->type = 0;
126 gens = NULL;
127 }
128 return crld;
129
130 merr:
131 X509V3err(X509V3_F_V2I_CRLD,ERR_R_MALLOC_FAILURE);
132 err:
133 GENERAL_NAME_free(gen);
134 GENERAL_NAMES_free(gens);
135 sk_DIST_POINT_pop_free(crld, DIST_POINT_free);
136 return NULL;
137}
138
139IMPLEMENT_STACK_OF(DIST_POINT)
140IMPLEMENT_ASN1_SET_OF(DIST_POINT)
141
142
143ASN1_CHOICE(DIST_POINT_NAME) = {
144 ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0),
145 ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1)
146} ASN1_CHOICE_END(DIST_POINT_NAME)
147
148IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT_NAME)
149
150ASN1_SEQUENCE(DIST_POINT) = {
151 ASN1_EXP_OPT(DIST_POINT, distpoint, DIST_POINT_NAME, 0),
152 ASN1_IMP_OPT(DIST_POINT, reasons, ASN1_BIT_STRING, 1),
153 ASN1_IMP_SEQUENCE_OF_OPT(DIST_POINT, CRLissuer, GENERAL_NAME, 2)
154} ASN1_SEQUENCE_END(DIST_POINT)
155
156IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT)
157
158ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) =
159 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CRLDistributionPoints, DIST_POINT)
160ASN1_ITEM_TEMPLATE_END(CRL_DIST_POINTS)
161
162IMPLEMENT_ASN1_FUNCTIONS(CRL_DIST_POINTS)
diff --git a/src/lib/libcrypto/x509v3/v3_enum.c b/src/lib/libcrypto/x509v3/v3_enum.c
deleted file mode 100644
index 010c9d6260..0000000000
--- a/src/lib/libcrypto/x509v3/v3_enum.c
+++ /dev/null
@@ -1,94 +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, ASN1_ITEM_ref(ASN1_ENUMERATED),
770,0,0,0,
78(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
790,
800,0,0,0,
81crl_reasons};
82
83
84char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
85 ASN1_ENUMERATED *e)
86{
87 ENUMERATED_NAMES *enam;
88 long strval;
89 strval = ASN1_ENUMERATED_get(e);
90 for(enam = method->usr_data; enam->lname; enam++) {
91 if(strval == enam->bitnum) return BUF_strdup(enam->lname);
92 }
93 return i2s_ASN1_ENUMERATED(method, e);
94}
diff --git a/src/lib/libcrypto/x509v3/v3_extku.c b/src/lib/libcrypto/x509v3/v3_extku.c
deleted file mode 100644
index b1cfaba1aa..0000000000
--- a/src/lib/libcrypto/x509v3/v3_extku.c
+++ /dev/null
@@ -1,142 +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/asn1t.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
67 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
68static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
69 void *eku, STACK_OF(CONF_VALUE) *extlist);
70
71X509V3_EXT_METHOD v3_ext_ku = {
72 NID_ext_key_usage, 0,
73 ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
74 0,0,0,0,
75 0,0,
76 i2v_EXTENDED_KEY_USAGE,
77 v2i_EXTENDED_KEY_USAGE,
78 0,0,
79 NULL
80};
81
82/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */
83X509V3_EXT_METHOD v3_ocsp_accresp = {
84 NID_id_pkix_OCSP_acceptableResponses, 0,
85 ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
86 0,0,0,0,
87 0,0,
88 i2v_EXTENDED_KEY_USAGE,
89 v2i_EXTENDED_KEY_USAGE,
90 0,0,
91 NULL
92};
93
94ASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) =
95 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT)
96ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE)
97
98IMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
99
100static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
101 void *a, STACK_OF(CONF_VALUE) *ext_list)
102{
103 EXTENDED_KEY_USAGE *eku = a;
104 int i;
105 ASN1_OBJECT *obj;
106 char obj_tmp[80];
107 for(i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
108 obj = sk_ASN1_OBJECT_value(eku, i);
109 i2t_ASN1_OBJECT(obj_tmp, 80, obj);
110 X509V3_add_value(NULL, obj_tmp, &ext_list);
111 }
112 return ext_list;
113}
114
115static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
116 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
117{
118 EXTENDED_KEY_USAGE *extku;
119 char *extval;
120 ASN1_OBJECT *objtmp;
121 CONF_VALUE *val;
122 int i;
123
124 if(!(extku = sk_ASN1_OBJECT_new_null())) {
125 X509V3err(X509V3_F_V2I_EXT_KU,ERR_R_MALLOC_FAILURE);
126 return NULL;
127 }
128
129 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
130 val = sk_CONF_VALUE_value(nval, i);
131 if(val->value) extval = val->value;
132 else extval = val->name;
133 if(!(objtmp = OBJ_txt2obj(extval, 0))) {
134 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
135 X509V3err(X509V3_F_V2I_EXT_KU,X509V3_R_INVALID_OBJECT_IDENTIFIER);
136 X509V3_conf_err(val);
137 return NULL;
138 }
139 sk_ASN1_OBJECT_push(extku, objtmp);
140 }
141 return extku;
142}
diff --git a/src/lib/libcrypto/x509v3/v3_genn.c b/src/lib/libcrypto/x509v3/v3_genn.c
deleted file mode 100644
index 650b510980..0000000000
--- a/src/lib/libcrypto/x509v3/v3_genn.c
+++ /dev/null
@@ -1,101 +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/asn1t.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66ASN1_SEQUENCE(OTHERNAME) = {
67 ASN1_SIMPLE(OTHERNAME, type_id, ASN1_OBJECT),
68 /* Maybe have a true ANY DEFINED BY later */
69 ASN1_EXP(OTHERNAME, value, ASN1_ANY, 0)
70} ASN1_SEQUENCE_END(OTHERNAME)
71
72IMPLEMENT_ASN1_FUNCTIONS(OTHERNAME)
73
74ASN1_SEQUENCE(EDIPARTYNAME) = {
75 ASN1_IMP_OPT(EDIPARTYNAME, nameAssigner, DIRECTORYSTRING, 0),
76 ASN1_IMP_OPT(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1)
77} ASN1_SEQUENCE_END(EDIPARTYNAME)
78
79IMPLEMENT_ASN1_FUNCTIONS(EDIPARTYNAME)
80
81ASN1_CHOICE(GENERAL_NAME) = {
82 ASN1_IMP(GENERAL_NAME, d.otherName, OTHERNAME, GEN_OTHERNAME),
83 ASN1_IMP(GENERAL_NAME, d.rfc822Name, ASN1_IA5STRING, GEN_EMAIL),
84 ASN1_IMP(GENERAL_NAME, d.dNSName, ASN1_IA5STRING, GEN_DNS),
85 /* Don't decode this */
86 ASN1_IMP(GENERAL_NAME, d.x400Address, ASN1_SEQUENCE, GEN_X400),
87 /* X509_NAME is a CHOICE type so use EXPLICIT */
88 ASN1_EXP(GENERAL_NAME, d.directoryName, X509_NAME, GEN_DIRNAME),
89 ASN1_IMP(GENERAL_NAME, d.ediPartyName, EDIPARTYNAME, GEN_EDIPARTY),
90 ASN1_IMP(GENERAL_NAME, d.uniformResourceIdentifier, ASN1_IA5STRING, GEN_URI),
91 ASN1_IMP(GENERAL_NAME, d.iPAddress, ASN1_OCTET_STRING, GEN_IPADD),
92 ASN1_IMP(GENERAL_NAME, d.registeredID, ASN1_OBJECT, GEN_RID)
93} ASN1_CHOICE_END(GENERAL_NAME)
94
95IMPLEMENT_ASN1_FUNCTIONS(GENERAL_NAME)
96
97ASN1_ITEM_TEMPLATE(GENERAL_NAMES) =
98 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, GeneralNames, GENERAL_NAME)
99ASN1_ITEM_TEMPLATE_END(GENERAL_NAMES)
100
101IMPLEMENT_ASN1_FUNCTIONS(GENERAL_NAMES)
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
deleted file mode 100644
index 9683afa47c..0000000000
--- a/src/lib/libcrypto/x509v3/v3_ia5.c
+++ /dev/null
@@ -1,116 +0,0 @@
1/* v3_ia5.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static 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 if(!(tmp = OPENSSL_malloc(ia5->length + 1))) {
86 X509V3err(X509V3_F_I2S_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89 memcpy(tmp, ia5->data, ia5->length);
90 tmp[ia5->length] = 0;
91 return tmp;
92}
93
94static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
95 X509V3_CTX *ctx, char *str)
96{
97 ASN1_IA5STRING *ia5;
98 if(!str) {
99 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT);
100 return NULL;
101 }
102 if(!(ia5 = M_ASN1_IA5STRING_new())) goto err;
103 if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str,
104 strlen(str))) {
105 M_ASN1_IA5STRING_free(ia5);
106 goto err;
107 }
108#ifdef CHARSET_EBCDIC
109 ebcdic2ascii(ia5->data, ia5->data, ia5->length);
110#endif /*CHARSET_EBCDIC*/
111 return ia5;
112 err:
113 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
114 return NULL;
115}
116
diff --git a/src/lib/libcrypto/x509v3/v3_info.c b/src/lib/libcrypto/x509v3/v3_info.c
deleted file mode 100644
index 53e3f48859..0000000000
--- a/src/lib/libcrypto/x509v3/v3_info.c
+++ /dev/null
@@ -1,194 +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/asn1t.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
67 AUTHORITY_INFO_ACCESS *ainfo,
68 STACK_OF(CONF_VALUE) *ret);
69static AUTHORITY_INFO_ACCESS *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, ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
740,0,0,0,
750,0,
76(X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
77(X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
780,0,
79NULL};
80
81X509V3_EXT_METHOD v3_sinfo =
82{ NID_sinfo_access, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
830,0,0,0,
840,0,
85(X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
86(X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
870,0,
88NULL};
89
90ASN1_SEQUENCE(ACCESS_DESCRIPTION) = {
91 ASN1_SIMPLE(ACCESS_DESCRIPTION, method, ASN1_OBJECT),
92 ASN1_SIMPLE(ACCESS_DESCRIPTION, location, GENERAL_NAME)
93} ASN1_SEQUENCE_END(ACCESS_DESCRIPTION)
94
95IMPLEMENT_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)
96
97ASN1_ITEM_TEMPLATE(AUTHORITY_INFO_ACCESS) =
98 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, GeneralNames, ACCESS_DESCRIPTION)
99ASN1_ITEM_TEMPLATE_END(AUTHORITY_INFO_ACCESS)
100
101IMPLEMENT_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)
102
103static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
104 AUTHORITY_INFO_ACCESS *ainfo,
105 STACK_OF(CONF_VALUE) *ret)
106{
107 ACCESS_DESCRIPTION *desc;
108 int i,nlen;
109 char objtmp[80], *ntmp;
110 CONF_VALUE *vtmp;
111 for(i = 0; i < sk_ACCESS_DESCRIPTION_num(ainfo); i++) {
112 desc = sk_ACCESS_DESCRIPTION_value(ainfo, i);
113 ret = i2v_GENERAL_NAME(method, desc->location, ret);
114 if(!ret) break;
115 vtmp = sk_CONF_VALUE_value(ret, i);
116 i2t_ASN1_OBJECT(objtmp, sizeof objtmp, desc->method);
117 nlen = strlen(objtmp) + strlen(vtmp->name) + 5;
118 ntmp = OPENSSL_malloc(nlen);
119 if(!ntmp) {
120 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS,
121 ERR_R_MALLOC_FAILURE);
122 return NULL;
123 }
124 BUF_strlcpy(ntmp, objtmp, nlen);
125 BUF_strlcat(ntmp, " - ", nlen);
126 BUF_strlcat(ntmp, vtmp->name, nlen);
127 OPENSSL_free(vtmp->name);
128 vtmp->name = ntmp;
129
130 }
131 if(!ret) return sk_CONF_VALUE_new_null();
132 return ret;
133}
134
135static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
136 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
137{
138 AUTHORITY_INFO_ACCESS *ainfo = NULL;
139 CONF_VALUE *cnf, ctmp;
140 ACCESS_DESCRIPTION *acc;
141 int i, objlen;
142 char *objtmp, *ptmp;
143 if(!(ainfo = sk_ACCESS_DESCRIPTION_new_null())) {
144 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
145 return NULL;
146 }
147 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
148 cnf = sk_CONF_VALUE_value(nval, i);
149 if(!(acc = ACCESS_DESCRIPTION_new())
150 || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) {
151 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
152 goto err;
153 }
154 ptmp = strchr(cnf->name, ';');
155 if(!ptmp) {
156 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_INVALID_SYNTAX);
157 goto err;
158 }
159 objlen = ptmp - cnf->name;
160 ctmp.name = ptmp + 1;
161 ctmp.value = cnf->value;
162 GENERAL_NAME_free(acc->location);
163 if(!(acc->location = v2i_GENERAL_NAME(method, ctx, &ctmp)))
164 goto err;
165 if(!(objtmp = OPENSSL_malloc(objlen + 1))) {
166 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
167 goto err;
168 }
169 strncpy(objtmp, cnf->name, objlen);
170 objtmp[objlen] = 0;
171 acc->method = OBJ_txt2obj(objtmp, 0);
172 if(!acc->method) {
173 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_BAD_OBJECT);
174 ERR_add_error_data(2, "value=", objtmp);
175 OPENSSL_free(objtmp);
176 goto err;
177 }
178 OPENSSL_free(objtmp);
179
180 }
181 return ainfo;
182 err:
183 sk_ACCESS_DESCRIPTION_pop_free(ainfo, ACCESS_DESCRIPTION_free);
184 return NULL;
185}
186
187int i2a_ACCESS_DESCRIPTION(BIO *bp, ACCESS_DESCRIPTION* a)
188 {
189 i2a_ASN1_OBJECT(bp, a->method);
190#ifdef UNDEF
191 i2a_GENERAL_NAME(bp, a->location);
192#endif
193 return 2;
194 }
diff --git a/src/lib/libcrypto/x509v3/v3_int.c b/src/lib/libcrypto/x509v3/v3_int.c
deleted file mode 100644
index 7a43b4717b..0000000000
--- a/src/lib/libcrypto/x509v3/v3_int.c
+++ /dev/null
@@ -1,76 +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-2004 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 = {
64 NID_crl_number, 0, ASN1_ITEM_ref(ASN1_INTEGER),
65 0,0,0,0,
66 (X509V3_EXT_I2S)i2s_ASN1_INTEGER,
67 0,
68 0,0,0,0, NULL};
69
70X509V3_EXT_METHOD v3_delta_crl = {
71 NID_delta_crl, 0, ASN1_ITEM_ref(ASN1_INTEGER),
72 0,0,0,0,
73 (X509V3_EXT_I2S)i2s_ASN1_INTEGER,
74 0,
75 0,0,0,0, NULL};
76
diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c
deleted file mode 100644
index ca5a4a4a57..0000000000
--- a/src/lib/libcrypto/x509v3/v3_lib.c
+++ /dev/null
@@ -1,302 +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_OF(X509V3_EXT_METHOD) *ext_list = NULL;
68
69static int ext_cmp(const X509V3_EXT_METHOD * const *a,
70 const X509V3_EXT_METHOD * const *b);
71static void ext_list_free(X509V3_EXT_METHOD *ext);
72
73int X509V3_EXT_add(X509V3_EXT_METHOD *ext)
74{
75 if(!ext_list && !(ext_list = sk_X509V3_EXT_METHOD_new(ext_cmp))) {
76 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
77 return 0;
78 }
79 if(!sk_X509V3_EXT_METHOD_push(ext_list, ext)) {
80 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
81 return 0;
82 }
83 return 1;
84}
85
86static int ext_cmp(const X509V3_EXT_METHOD * const *a,
87 const X509V3_EXT_METHOD * const *b)
88{
89 return ((*a)->ext_nid - (*b)->ext_nid);
90}
91
92X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
93{
94 X509V3_EXT_METHOD tmp, *t = &tmp, **ret;
95 int idx;
96 if(nid < 0) return NULL;
97 tmp.ext_nid = nid;
98 ret = (X509V3_EXT_METHOD **) OBJ_bsearch((char *)&t,
99 (char *)standard_exts, STANDARD_EXTENSION_COUNT,
100 sizeof(X509V3_EXT_METHOD *), (int (*)(const void *, const void *))ext_cmp);
101 if(ret) return *ret;
102 if(!ext_list) return NULL;
103 idx = sk_X509V3_EXT_METHOD_find(ext_list, &tmp);
104 if(idx == -1) return NULL;
105 return sk_X509V3_EXT_METHOD_value(ext_list, idx);
106}
107
108X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
109{
110 int nid;
111 if((nid = OBJ_obj2nid(ext->object)) == NID_undef) return NULL;
112 return X509V3_EXT_get_nid(nid);
113}
114
115
116int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist)
117{
118 for(;extlist->ext_nid!=-1;extlist++)
119 if(!X509V3_EXT_add(extlist)) return 0;
120 return 1;
121}
122
123int X509V3_EXT_add_alias(int nid_to, int nid_from)
124{
125 X509V3_EXT_METHOD *ext, *tmpext;
126 if(!(ext = X509V3_EXT_get_nid(nid_from))) {
127 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
128 return 0;
129 }
130 if(!(tmpext = (X509V3_EXT_METHOD *)OPENSSL_malloc(sizeof(X509V3_EXT_METHOD)))) {
131 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE);
132 return 0;
133 }
134 *tmpext = *ext;
135 tmpext->ext_nid = nid_to;
136 tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
137 return X509V3_EXT_add(tmpext);
138}
139
140void X509V3_EXT_cleanup(void)
141{
142 sk_X509V3_EXT_METHOD_pop_free(ext_list, ext_list_free);
143 ext_list = NULL;
144}
145
146static void ext_list_free(X509V3_EXT_METHOD *ext)
147{
148 if(ext->ext_flags & X509V3_EXT_DYNAMIC) OPENSSL_free(ext);
149}
150
151/* Legacy function: we don't need to add standard extensions
152 * any more because they are now kept in ext_dat.h.
153 */
154
155int X509V3_add_standard_extensions(void)
156{
157 return 1;
158}
159
160/* Return an extension internal structure */
161
162void *X509V3_EXT_d2i(X509_EXTENSION *ext)
163{
164 X509V3_EXT_METHOD *method;
165 unsigned char *p;
166 if(!(method = X509V3_EXT_get(ext))) return NULL;
167 p = ext->value->data;
168 if(method->it) return ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it));
169 return method->d2i(NULL, &p, ext->value->length);
170}
171
172/* Get critical flag and decoded version of extension from a NID.
173 * The "idx" variable returns the last found extension and can
174 * be used to retrieve multiple extensions of the same NID.
175 * However multiple extensions with the same NID is usually
176 * due to a badly encoded certificate so if idx is NULL we
177 * choke if multiple extensions exist.
178 * The "crit" variable is set to the critical value.
179 * The return value is the decoded extension or NULL on
180 * error. The actual error can have several different causes,
181 * the value of *crit reflects the cause:
182 * >= 0, extension found but not decoded (reflects critical value).
183 * -1 extension not found.
184 * -2 extension occurs more than once.
185 */
186
187void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx)
188{
189 int lastpos, i;
190 X509_EXTENSION *ex, *found_ex = NULL;
191 if(!x) {
192 if(idx) *idx = -1;
193 if(crit) *crit = -1;
194 return NULL;
195 }
196 if(idx) lastpos = *idx + 1;
197 else lastpos = 0;
198 if(lastpos < 0) lastpos = 0;
199 for(i = lastpos; i < sk_X509_EXTENSION_num(x); i++)
200 {
201 ex = sk_X509_EXTENSION_value(x, i);
202 if(OBJ_obj2nid(ex->object) == nid) {
203 if(idx) {
204 *idx = i;
205 found_ex = ex;
206 break;
207 } else if(found_ex) {
208 /* Found more than one */
209 if(crit) *crit = -2;
210 return NULL;
211 }
212 found_ex = ex;
213 }
214 }
215 if(found_ex) {
216 /* Found it */
217 if(crit) *crit = X509_EXTENSION_get_critical(found_ex);
218 return X509V3_EXT_d2i(found_ex);
219 }
220
221 /* Extension not found */
222 if(idx) *idx = -1;
223 if(crit) *crit = -1;
224 return NULL;
225}
226
227/* This function is a general extension append, replace and delete utility.
228 * The precise operation is governed by the 'flags' value. The 'crit' and
229 * 'value' arguments (if relevant) are the extensions internal structure.
230 */
231
232int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
233 int crit, unsigned long flags)
234{
235 int extidx = -1;
236 int errcode;
237 X509_EXTENSION *ext, *extmp;
238 unsigned long ext_op = flags & X509V3_ADD_OP_MASK;
239
240 /* If appending we don't care if it exists, otherwise
241 * look for existing extension.
242 */
243 if(ext_op != X509V3_ADD_APPEND)
244 extidx = X509v3_get_ext_by_NID(*x, nid, -1);
245
246 /* See if extension exists */
247 if(extidx >= 0) {
248 /* If keep existing, nothing to do */
249 if(ext_op == X509V3_ADD_KEEP_EXISTING)
250 return 1;
251 /* If default then its an error */
252 if(ext_op == X509V3_ADD_DEFAULT) {
253 errcode = X509V3_R_EXTENSION_EXISTS;
254 goto err;
255 }
256 /* If delete, just delete it */
257 if(ext_op == X509V3_ADD_DELETE) {
258 if(!sk_X509_EXTENSION_delete(*x, extidx)) return -1;
259 return 1;
260 }
261 } else {
262 /* If replace existing or delete, error since
263 * extension must exist
264 */
265 if((ext_op == X509V3_ADD_REPLACE_EXISTING) ||
266 (ext_op == X509V3_ADD_DELETE)) {
267 errcode = X509V3_R_EXTENSION_NOT_FOUND;
268 goto err;
269 }
270 }
271
272 /* If we get this far then we have to create an extension:
273 * could have some flags for alternative encoding schemes...
274 */
275
276 ext = X509V3_EXT_i2d(nid, crit, value);
277
278 if(!ext) {
279 X509V3err(X509V3_F_X509V3_ADD_I2D, X509V3_R_ERROR_CREATING_EXTENSION);
280 return 0;
281 }
282
283 /* If extension exists replace it.. */
284 if(extidx >= 0) {
285 extmp = sk_X509_EXTENSION_value(*x, extidx);
286 X509_EXTENSION_free(extmp);
287 if(!sk_X509_EXTENSION_set(*x, extidx, ext)) return -1;
288 return 1;
289 }
290
291 if(!*x && !(*x = sk_X509_EXTENSION_new_null())) return -1;
292 if(!sk_X509_EXTENSION_push(*x, ext)) return -1;
293
294 return 1;
295
296 err:
297 if(!(flags & X509V3_ADD_SILENT))
298 X509V3err(X509V3_F_X509V3_ADD_I2D, errcode);
299 return 0;
300}
301
302IMPLEMENT_STACK_OF(X509V3_EXT_METHOD)
diff --git a/src/lib/libcrypto/x509v3/v3_ocsp.c b/src/lib/libcrypto/x509v3/v3_ocsp.c
deleted file mode 100644
index 21badc13f9..0000000000
--- a/src/lib/libcrypto/x509v3/v3_ocsp.c
+++ /dev/null
@@ -1,275 +0,0 @@
1/* v3_ocsp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef OPENSSL_NO_OCSP
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/conf.h>
64#include <openssl/asn1.h>
65#include <openssl/ocsp.h>
66#include <openssl/x509v3.h>
67
68/* OCSP extensions and a couple of CRL entry extensions
69 */
70
71static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
72static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
73static int i2r_object(X509V3_EXT_METHOD *method, void *obj, BIO *out, int indent);
74
75static void *ocsp_nonce_new(void);
76static int i2d_ocsp_nonce(void *a, unsigned char **pp);
77static void *d2i_ocsp_nonce(void *a, unsigned char **pp, long length);
78static void ocsp_nonce_free(void *a);
79static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
80
81static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent);
82static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
83static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind);
84
85X509V3_EXT_METHOD v3_ocsp_crlid = {
86 NID_id_pkix_OCSP_CrlID, 0, ASN1_ITEM_ref(OCSP_CRLID),
87 0,0,0,0,
88 0,0,
89 0,0,
90 i2r_ocsp_crlid,0,
91 NULL
92};
93
94X509V3_EXT_METHOD v3_ocsp_acutoff = {
95 NID_id_pkix_OCSP_archiveCutoff, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
96 0,0,0,0,
97 0,0,
98 0,0,
99 i2r_ocsp_acutoff,0,
100 NULL
101};
102
103X509V3_EXT_METHOD v3_crl_invdate = {
104 NID_invalidity_date, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
105 0,0,0,0,
106 0,0,
107 0,0,
108 i2r_ocsp_acutoff,0,
109 NULL
110};
111
112X509V3_EXT_METHOD v3_crl_hold = {
113 NID_hold_instruction_code, 0, ASN1_ITEM_ref(ASN1_OBJECT),
114 0,0,0,0,
115 0,0,
116 0,0,
117 i2r_object,0,
118 NULL
119};
120
121X509V3_EXT_METHOD v3_ocsp_nonce = {
122 NID_id_pkix_OCSP_Nonce, 0, NULL,
123 ocsp_nonce_new,
124 ocsp_nonce_free,
125 d2i_ocsp_nonce,
126 i2d_ocsp_nonce,
127 0,0,
128 0,0,
129 i2r_ocsp_nonce,0,
130 NULL
131};
132
133X509V3_EXT_METHOD v3_ocsp_nocheck = {
134 NID_id_pkix_OCSP_noCheck, 0, ASN1_ITEM_ref(ASN1_NULL),
135 0,0,0,0,
136 0,s2i_ocsp_nocheck,
137 0,0,
138 i2r_ocsp_nocheck,0,
139 NULL
140};
141
142X509V3_EXT_METHOD v3_ocsp_serviceloc = {
143 NID_id_pkix_OCSP_serviceLocator, 0, ASN1_ITEM_ref(OCSP_SERVICELOC),
144 0,0,0,0,
145 0,0,
146 0,0,
147 i2r_ocsp_serviceloc,0,
148 NULL
149};
150
151static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
152{
153 OCSP_CRLID *a = in;
154 if (a->crlUrl)
155 {
156 if (!BIO_printf(bp, "%*scrlUrl: ", ind, "")) goto err;
157 if (!ASN1_STRING_print(bp, (ASN1_STRING*)a->crlUrl)) goto err;
158 if (!BIO_write(bp, "\n", 1)) goto err;
159 }
160 if (a->crlNum)
161 {
162 if (!BIO_printf(bp, "%*scrlNum: ", ind, "")) goto err;
163 if (!i2a_ASN1_INTEGER(bp, a->crlNum)) goto err;
164 if (!BIO_write(bp, "\n", 1)) goto err;
165 }
166 if (a->crlTime)
167 {
168 if (!BIO_printf(bp, "%*scrlTime: ", ind, "")) goto err;
169 if (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime)) goto err;
170 if (!BIO_write(bp, "\n", 1)) goto err;
171 }
172 return 1;
173 err:
174 return 0;
175}
176
177static int i2r_ocsp_acutoff(X509V3_EXT_METHOD *method, void *cutoff, BIO *bp, int ind)
178{
179 if (!BIO_printf(bp, "%*s", ind, "")) return 0;
180 if(!ASN1_GENERALIZEDTIME_print(bp, cutoff)) return 0;
181 return 1;
182}
183
184
185static int i2r_object(X509V3_EXT_METHOD *method, void *oid, BIO *bp, int ind)
186{
187 if (!BIO_printf(bp, "%*s", ind, "")) return 0;
188 if(!i2a_ASN1_OBJECT(bp, oid)) return 0;
189 return 1;
190}
191
192/* OCSP nonce. This is needs special treatment because it doesn't have
193 * an ASN1 encoding at all: it just contains arbitrary data.
194 */
195
196static void *ocsp_nonce_new(void)
197{
198 return ASN1_OCTET_STRING_new();
199}
200
201static int i2d_ocsp_nonce(void *a, unsigned char **pp)
202{
203 ASN1_OCTET_STRING *os = a;
204 if(pp) {
205 memcpy(*pp, os->data, os->length);
206 *pp += os->length;
207 }
208 return os->length;
209}
210
211static void *d2i_ocsp_nonce(void *a, unsigned char **pp, long length)
212{
213 ASN1_OCTET_STRING *os, **pos;
214 pos = a;
215 if(!pos || !*pos) os = ASN1_OCTET_STRING_new();
216 else os = *pos;
217 if(!ASN1_OCTET_STRING_set(os, *pp, length)) goto err;
218
219 *pp += length;
220
221 if(pos) *pos = os;
222 return os;
223
224 err:
225 if(os && (!pos || (*pos != os))) M_ASN1_OCTET_STRING_free(os);
226 OCSPerr(OCSP_F_D2I_OCSP_NONCE, ERR_R_MALLOC_FAILURE);
227 return NULL;
228}
229
230static void ocsp_nonce_free(void *a)
231{
232 M_ASN1_OCTET_STRING_free(a);
233}
234
235static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent)
236{
237 if(BIO_printf(out, "%*s", indent, "") <= 0) return 0;
238 if(i2a_ASN1_STRING(out, nonce, V_ASN1_OCTET_STRING) <= 0) return 0;
239 return 1;
240}
241
242/* Nocheck is just a single NULL. Don't print anything and always set it */
243
244static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent)
245{
246 return 1;
247}
248
249static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
250{
251 return ASN1_NULL_new();
252}
253
254static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)
255 {
256 int i;
257 OCSP_SERVICELOC *a = in;
258 ACCESS_DESCRIPTION *ad;
259
260 if (BIO_printf(bp, "%*sIssuer: ", ind, "") <= 0) goto err;
261 if (X509_NAME_print_ex(bp, a->issuer, 0, XN_FLAG_ONELINE) <= 0) goto err;
262 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(a->locator); i++)
263 {
264 ad = sk_ACCESS_DESCRIPTION_value(a->locator,i);
265 if (BIO_printf(bp, "\n%*s", (2*ind), "") <= 0)
266 goto err;
267 if(i2a_ASN1_OBJECT(bp, ad->method) <= 0) goto err;
268 if(BIO_puts(bp, " - ") <= 0) goto err;
269 if(GENERAL_NAME_print(bp, ad->location) <= 0) goto err;
270 }
271 return 1;
272err:
273 return 0;
274 }
275#endif
diff --git a/src/lib/libcrypto/x509v3/v3_pci.c b/src/lib/libcrypto/x509v3/v3_pci.c
deleted file mode 100644
index b32d968619..0000000000
--- a/src/lib/libcrypto/x509v3/v3_pci.c
+++ /dev/null
@@ -1,313 +0,0 @@
1/* v3_pci.c -*- mode:C; c-file-style: "eay" -*- */
2/* Contributed to the OpenSSL Project 2004
3 * by Richard Levitte (richard@levitte.org)
4 */
5/* Copyright (c) 2004 Kungliga Tekniska Högskolan
6 * (Royal Institute of Technology, Stockholm, Sweden).
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <stdio.h>
38#include "cryptlib.h"
39#include <openssl/conf.h>
40#include <openssl/x509v3.h>
41
42static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *ext,
43 BIO *out, int indent);
44static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method,
45 X509V3_CTX *ctx, char *str);
46
47X509V3_EXT_METHOD v3_pci =
48 { NID_proxyCertInfo, 0, ASN1_ITEM_ref(PROXY_CERT_INFO_EXTENSION),
49 0,0,0,0,
50 0,0,
51 NULL, NULL,
52 (X509V3_EXT_I2R)i2r_pci,
53 (X509V3_EXT_R2I)r2i_pci,
54 NULL,
55 };
56
57static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *pci,
58 BIO *out, int indent)
59 {
60 BIO_printf(out, "%*sPath Length Constraint: ", indent, "");
61 if (pci->pcPathLengthConstraint)
62 i2a_ASN1_INTEGER(out, pci->pcPathLengthConstraint);
63 else
64 BIO_printf(out, "infinite");
65 BIO_puts(out, "\n");
66 BIO_printf(out, "%*sPolicy Language: ", indent, "");
67 i2a_ASN1_OBJECT(out, pci->proxyPolicy->policyLanguage);
68 BIO_puts(out, "\n");
69 if (pci->proxyPolicy->policy && pci->proxyPolicy->policy->data)
70 BIO_printf(out, "%*sPolicy Text: %s\n", indent, "",
71 pci->proxyPolicy->policy->data);
72 return 1;
73 }
74
75static int process_pci_value(CONF_VALUE *val,
76 ASN1_OBJECT **language, ASN1_INTEGER **pathlen,
77 ASN1_OCTET_STRING **policy)
78 {
79 int free_policy = 0;
80
81 if (strcmp(val->name, "language") == 0)
82 {
83 if (*language)
84 {
85 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED);
86 X509V3_conf_err(val);
87 return 0;
88 }
89 if (!(*language = OBJ_txt2obj(val->value, 0)))
90 {
91 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_OBJECT_IDENTIFIER);
92 X509V3_conf_err(val);
93 return 0;
94 }
95 }
96 else if (strcmp(val->name, "pathlen") == 0)
97 {
98 if (*pathlen)
99 {
100 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED);
101 X509V3_conf_err(val);
102 return 0;
103 }
104 if (!X509V3_get_value_int(val, pathlen))
105 {
106 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_PATH_LENGTH);
107 X509V3_conf_err(val);
108 return 0;
109 }
110 }
111 else if (strcmp(val->name, "policy") == 0)
112 {
113 unsigned char *tmp_data = NULL;
114 long val_len;
115 if (!*policy)
116 {
117 *policy = ASN1_OCTET_STRING_new();
118 if (!*policy)
119 {
120 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
121 X509V3_conf_err(val);
122 return 0;
123 }
124 free_policy = 1;
125 }
126 if (strncmp(val->value, "hex:", 4) == 0)
127 {
128 unsigned char *tmp_data2 =
129 string_to_hex(val->value + 4, &val_len);
130
131 if (!tmp_data2) goto err;
132
133 tmp_data = OPENSSL_realloc((*policy)->data,
134 (*policy)->length + val_len + 1);
135 if (tmp_data)
136 {
137 (*policy)->data = tmp_data;
138 memcpy(&(*policy)->data[(*policy)->length],
139 tmp_data2, val_len);
140 (*policy)->length += val_len;
141 (*policy)->data[(*policy)->length] = '\0';
142 }
143 }
144 else if (strncmp(val->value, "file:", 5) == 0)
145 {
146 unsigned char buf[2048];
147 int n;
148 BIO *b = BIO_new_file(val->value + 5, "r");
149 if (!b)
150 {
151 X509V3err(X509V3_F_R2I_PCI,ERR_R_BIO_LIB);
152 X509V3_conf_err(val);
153 goto err;
154 }
155 while((n = BIO_read(b, buf, sizeof(buf))) > 0
156 || (n == 0 && BIO_should_retry(b)))
157 {
158 if (!n) continue;
159
160 tmp_data = OPENSSL_realloc((*policy)->data,
161 (*policy)->length + n + 1);
162
163 if (!tmp_data)
164 break;
165
166 (*policy)->data = tmp_data;
167 memcpy(&(*policy)->data[(*policy)->length],
168 buf, n);
169 (*policy)->length += n;
170 (*policy)->data[(*policy)->length] = '\0';
171 }
172
173 if (n < 0)
174 {
175 X509V3err(X509V3_F_R2I_PCI,ERR_R_BIO_LIB);
176 X509V3_conf_err(val);
177 goto err;
178 }
179 }
180 else if (strncmp(val->value, "text:", 5) == 0)
181 {
182 val_len = strlen(val->value + 5);
183 tmp_data = OPENSSL_realloc((*policy)->data,
184 (*policy)->length + val_len + 1);
185 if (tmp_data)
186 {
187 (*policy)->data = tmp_data;
188 memcpy(&(*policy)->data[(*policy)->length],
189 val->value + 5, val_len);
190 (*policy)->length += val_len;
191 (*policy)->data[(*policy)->length] = '\0';
192 }
193 }
194 else
195 {
196 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INCORRECT_POLICY_SYNTAX_TAG);
197 X509V3_conf_err(val);
198 goto err;
199 }
200 if (!tmp_data)
201 {
202 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
203 X509V3_conf_err(val);
204 goto err;
205 }
206 }
207 return 1;
208err:
209 if (free_policy)
210 {
211 ASN1_OCTET_STRING_free(*policy);
212 *policy = NULL;
213 }
214 return 0;
215 }
216
217static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method,
218 X509V3_CTX *ctx, char *value)
219 {
220 PROXY_CERT_INFO_EXTENSION *pci = NULL;
221 STACK_OF(CONF_VALUE) *vals;
222 ASN1_OBJECT *language = NULL;
223 ASN1_INTEGER *pathlen = NULL;
224 ASN1_OCTET_STRING *policy = NULL;
225 int i, j;
226
227 vals = X509V3_parse_list(value);
228 for (i = 0; i < sk_CONF_VALUE_num(vals); i++)
229 {
230 CONF_VALUE *cnf = sk_CONF_VALUE_value(vals, i);
231 if (!cnf->name || (*cnf->name != '@' && !cnf->value))
232 {
233 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_PROXY_POLICY_SETTING);
234 X509V3_conf_err(cnf);
235 goto err;
236 }
237 if (*cnf->name == '@')
238 {
239 STACK_OF(CONF_VALUE) *sect;
240 int success_p = 1;
241
242 sect = X509V3_get_section(ctx, cnf->name + 1);
243 if (!sect)
244 {
245 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_SECTION);
246 X509V3_conf_err(cnf);
247 goto err;
248 }
249 for (j = 0; success_p && j < sk_CONF_VALUE_num(sect); j++)
250 {
251 success_p =
252 process_pci_value(sk_CONF_VALUE_value(sect, j),
253 &language, &pathlen, &policy);
254 }
255 X509V3_section_free(ctx, sect);
256 if (!success_p)
257 goto err;
258 }
259 else
260 {
261 if (!process_pci_value(cnf,
262 &language, &pathlen, &policy))
263 {
264 X509V3_conf_err(cnf);
265 goto err;
266 }
267 }
268 }
269
270 /* Language is mandatory */
271 if (!language)
272 {
273 X509V3err(X509V3_F_R2I_PCI,X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED);
274 goto err;
275 }
276 i = OBJ_obj2nid(language);
277 if ((i == NID_Independent || i == NID_id_ppl_inheritAll) && policy)
278 {
279 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY);
280 goto err;
281 }
282
283 pci = PROXY_CERT_INFO_EXTENSION_new();
284 if (!pci)
285 {
286 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
287 goto err;
288 }
289 pci->proxyPolicy = PROXY_POLICY_new();
290 if (!pci->proxyPolicy)
291 {
292 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
293 goto err;
294 }
295
296 pci->proxyPolicy->policyLanguage = language; language = NULL;
297 pci->proxyPolicy->policy = policy; policy = NULL;
298 pci->pcPathLengthConstraint = pathlen; pathlen = NULL;
299 goto end;
300err:
301 if (language) { ASN1_OBJECT_free(language); language = NULL; }
302 if (pathlen) { ASN1_INTEGER_free(pathlen); pathlen = NULL; }
303 if (policy) { ASN1_OCTET_STRING_free(policy); policy = NULL; }
304 if (pci && pci->proxyPolicy)
305 {
306 PROXY_POLICY_free(pci->proxyPolicy);
307 pci->proxyPolicy = NULL;
308 }
309 if (pci) { PROXY_CERT_INFO_EXTENSION_free(pci); pci = NULL; }
310end:
311 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
312 return pci;
313 }
diff --git a/src/lib/libcrypto/x509v3/v3_pcia.c b/src/lib/libcrypto/x509v3/v3_pcia.c
deleted file mode 100644
index bb362e0e5a..0000000000
--- a/src/lib/libcrypto/x509v3/v3_pcia.c
+++ /dev/null
@@ -1,55 +0,0 @@
1/* v3_pcia.c -*- mode:C; c-file-style: "eay" -*- */
2/* Contributed to the OpenSSL Project 2004
3 * by Richard Levitte (richard@levitte.org)
4 */
5/* Copyright (c) 2004 Kungliga Tekniska Högskolan
6 * (Royal Institute of Technology, Stockholm, Sweden).
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <openssl/asn1.h>
38#include <openssl/asn1t.h>
39#include <openssl/x509v3.h>
40
41ASN1_SEQUENCE(PROXY_POLICY) =
42 {
43 ASN1_SIMPLE(PROXY_POLICY,policyLanguage,ASN1_OBJECT),
44 ASN1_OPT(PROXY_POLICY,policy,ASN1_OCTET_STRING)
45} ASN1_SEQUENCE_END(PROXY_POLICY)
46
47IMPLEMENT_ASN1_FUNCTIONS(PROXY_POLICY)
48
49ASN1_SEQUENCE(PROXY_CERT_INFO_EXTENSION) =
50 {
51 ASN1_OPT(PROXY_CERT_INFO_EXTENSION,pcPathLengthConstraint,ASN1_INTEGER),
52 ASN1_SIMPLE(PROXY_CERT_INFO_EXTENSION,proxyPolicy,PROXY_POLICY)
53} ASN1_SEQUENCE_END(PROXY_CERT_INFO_EXTENSION)
54
55IMPLEMENT_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
diff --git a/src/lib/libcrypto/x509v3/v3_pku.c b/src/lib/libcrypto/x509v3/v3_pku.c
deleted file mode 100644
index 49a2e4697a..0000000000
--- a/src/lib/libcrypto/x509v3/v3_pku.c
+++ /dev/null
@@ -1,108 +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/asn1t.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, ASN1_ITEM_ref(PKEY_USAGE_PERIOD),
710,0,0,0,
720,0,0,0,
73(X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD, NULL,
74NULL
75};
76
77ASN1_SEQUENCE(PKEY_USAGE_PERIOD) = {
78 ASN1_IMP_OPT(PKEY_USAGE_PERIOD, notBefore, ASN1_GENERALIZEDTIME, 0),
79 ASN1_IMP_OPT(PKEY_USAGE_PERIOD, notAfter, ASN1_GENERALIZEDTIME, 1)
80} ASN1_SEQUENCE_END(PKEY_USAGE_PERIOD)
81
82IMPLEMENT_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)
83
84static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
85 PKEY_USAGE_PERIOD *usage, BIO *out, int indent)
86{
87 BIO_printf(out, "%*s", indent, "");
88 if(usage->notBefore) {
89 BIO_write(out, "Not Before: ", 12);
90 ASN1_GENERALIZEDTIME_print(out, usage->notBefore);
91 if(usage->notAfter) BIO_write(out, ", ", 2);
92 }
93 if(usage->notAfter) {
94 BIO_write(out, "Not After: ", 11);
95 ASN1_GENERALIZEDTIME_print(out, usage->notAfter);
96 }
97 return 1;
98}
99
100/*
101static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(method, ctx, values)
102X509V3_EXT_METHOD *method;
103X509V3_CTX *ctx;
104STACK_OF(CONF_VALUE) *values;
105{
106return NULL;
107}
108*/
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c
deleted file mode 100644
index 5d268eb768..0000000000
--- a/src/lib/libcrypto/x509v3/v3_prn.c
+++ /dev/null
@@ -1,233 +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
67static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent, int supported);
68
69/* Print out a name+value stack */
70
71void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml)
72{
73 int i;
74 CONF_VALUE *nval;
75 if(!val) return;
76 if(!ml || !sk_CONF_VALUE_num(val)) {
77 BIO_printf(out, "%*s", indent, "");
78 if(!sk_CONF_VALUE_num(val)) BIO_puts(out, "<EMPTY>\n");
79 }
80 for(i = 0; i < sk_CONF_VALUE_num(val); i++) {
81 if(ml) BIO_printf(out, "%*s", indent, "");
82 else if(i > 0) BIO_printf(out, ", ");
83 nval = sk_CONF_VALUE_value(val, i);
84 if(!nval->name) BIO_puts(out, nval->value);
85 else if(!nval->value) BIO_puts(out, nval->name);
86#ifndef CHARSET_EBCDIC
87 else BIO_printf(out, "%s:%s", nval->name, nval->value);
88#else
89 else {
90 int len;
91 char *tmp;
92 len = strlen(nval->value)+1;
93 tmp = OPENSSL_malloc(len);
94 if (tmp)
95 {
96 ascii2ebcdic(tmp, nval->value, len);
97 BIO_printf(out, "%s:%s", nval->name, tmp);
98 OPENSSL_free(tmp);
99 }
100 }
101#endif
102 if(ml) BIO_puts(out, "\n");
103 }
104}
105
106/* Main routine: print out a general extension */
107
108int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent)
109{
110 void *ext_str = NULL;
111 char *value = NULL;
112 unsigned char *p;
113 X509V3_EXT_METHOD *method;
114 STACK_OF(CONF_VALUE) *nval = NULL;
115 int ok = 1;
116 if(!(method = X509V3_EXT_get(ext)))
117 return unknown_ext_print(out, ext, flag, indent, 0);
118 p = ext->value->data;
119 if(method->it) ext_str = ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it));
120 else ext_str = method->d2i(NULL, &p, ext->value->length);
121
122 if(!ext_str) return unknown_ext_print(out, ext, flag, indent, 1);
123
124 if(method->i2s) {
125 if(!(value = method->i2s(method, ext_str))) {
126 ok = 0;
127 goto err;
128 }
129#ifndef CHARSET_EBCDIC
130 BIO_printf(out, "%*s%s", indent, "", value);
131#else
132 {
133 int len;
134 char *tmp;
135 len = strlen(value)+1;
136 tmp = OPENSSL_malloc(len);
137 if (tmp)
138 {
139 ascii2ebcdic(tmp, value, len);
140 BIO_printf(out, "%*s%s", indent, "", tmp);
141 OPENSSL_free(tmp);
142 }
143 }
144#endif
145 } else if(method->i2v) {
146 if(!(nval = method->i2v(method, ext_str, NULL))) {
147 ok = 0;
148 goto err;
149 }
150 X509V3_EXT_val_prn(out, nval, indent,
151 method->ext_flags & X509V3_EXT_MULTILINE);
152 } else if(method->i2r) {
153 if(!method->i2r(method, ext_str, out, indent)) ok = 0;
154 } else ok = 0;
155
156 err:
157 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
158 if(value) OPENSSL_free(value);
159 if(method->it) ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it));
160 else method->ext_free(ext_str);
161 return ok;
162}
163
164int X509V3_extensions_print(BIO *bp, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent)
165{
166 int i, j;
167
168 if(sk_X509_EXTENSION_num(exts) <= 0) return 1;
169
170 if(title)
171 {
172 BIO_printf(bp,"%*s%s:\n",indent, "", title);
173 indent += 4;
174 }
175
176 for (i=0; i<sk_X509_EXTENSION_num(exts); i++)
177 {
178 ASN1_OBJECT *obj;
179 X509_EXTENSION *ex;
180 ex=sk_X509_EXTENSION_value(exts, i);
181 if (indent && BIO_printf(bp,"%*s",indent, "") <= 0) return 0;
182 obj=X509_EXTENSION_get_object(ex);
183 i2a_ASN1_OBJECT(bp,obj);
184 j=X509_EXTENSION_get_critical(ex);
185 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
186 return 0;
187 if(!X509V3_EXT_print(bp, ex, flag, indent + 4))
188 {
189 BIO_printf(bp, "%*s", indent + 4, "");
190 M_ASN1_OCTET_STRING_print(bp,ex->value);
191 }
192 if (BIO_write(bp,"\n",1) <= 0) return 0;
193 }
194 return 1;
195}
196
197static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent, int supported)
198{
199 switch(flag & X509V3_EXT_UNKNOWN_MASK) {
200
201 case X509V3_EXT_DEFAULT:
202 return 0;
203
204 case X509V3_EXT_ERROR_UNKNOWN:
205 if(supported)
206 BIO_printf(out, "%*s<Parse Error>", indent, "");
207 else
208 BIO_printf(out, "%*s<Not Supported>", indent, "");
209 return 1;
210
211 case X509V3_EXT_PARSE_UNKNOWN:
212 return ASN1_parse_dump(out,
213 ext->value->data, ext->value->length, indent, -1);
214 case X509V3_EXT_DUMP_UNKNOWN:
215 return BIO_dump_indent(out, (char *)ext->value->data, ext->value->length, indent);
216
217 default:
218 return 1;
219 }
220}
221
222
223#ifndef OPENSSL_NO_FP_API
224int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent)
225{
226 BIO *bio_tmp;
227 int ret;
228 if(!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) return 0;
229 ret = X509V3_EXT_print(bio_tmp, ext, flag, indent);
230 BIO_free(bio_tmp);
231 return ret;
232}
233#endif
diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c
deleted file mode 100644
index bbdf6da493..0000000000
--- a/src/lib/libcrypto/x509v3/v3_purp.c
+++ /dev/null
@@ -1,647 +0,0 @@
1/* v3_purp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2004 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#include <openssl/x509_vfy.h>
63
64static void x509v3_cache_extensions(X509 *x);
65
66static int check_ssl_ca(const X509 *x);
67static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x, int ca);
68static int check_purpose_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca);
69static int check_purpose_ns_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca);
70static int purpose_smime(const X509 *x, int ca);
71static int check_purpose_smime_sign(const X509_PURPOSE *xp, const X509 *x, int ca);
72static int check_purpose_smime_encrypt(const X509_PURPOSE *xp, const X509 *x, int ca);
73static int check_purpose_crl_sign(const X509_PURPOSE *xp, const X509 *x, int ca);
74static int no_check(const X509_PURPOSE *xp, const X509 *x, int ca);
75static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca);
76
77static int xp_cmp(const X509_PURPOSE * const *a,
78 const X509_PURPOSE * const *b);
79static void xptable_free(X509_PURPOSE *p);
80
81static X509_PURPOSE xstandard[] = {
82 {X509_PURPOSE_SSL_CLIENT, X509_TRUST_SSL_CLIENT, 0, check_purpose_ssl_client, "SSL client", "sslclient", NULL},
83 {X509_PURPOSE_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ssl_server, "SSL server", "sslserver", NULL},
84 {X509_PURPOSE_NS_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ns_ssl_server, "Netscape SSL server", "nssslserver", NULL},
85 {X509_PURPOSE_SMIME_SIGN, X509_TRUST_EMAIL, 0, check_purpose_smime_sign, "S/MIME signing", "smimesign", NULL},
86 {X509_PURPOSE_SMIME_ENCRYPT, X509_TRUST_EMAIL, 0, check_purpose_smime_encrypt, "S/MIME encryption", "smimeencrypt", NULL},
87 {X509_PURPOSE_CRL_SIGN, X509_TRUST_COMPAT, 0, check_purpose_crl_sign, "CRL signing", "crlsign", NULL},
88 {X509_PURPOSE_ANY, X509_TRUST_DEFAULT, 0, no_check, "Any Purpose", "any", NULL},
89 {X509_PURPOSE_OCSP_HELPER, X509_TRUST_COMPAT, 0, ocsp_helper, "OCSP helper", "ocsphelper", NULL},
90};
91
92#define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
93
94IMPLEMENT_STACK_OF(X509_PURPOSE)
95
96static STACK_OF(X509_PURPOSE) *xptable = NULL;
97
98static int xp_cmp(const X509_PURPOSE * const *a,
99 const X509_PURPOSE * const *b)
100{
101 return (*a)->purpose - (*b)->purpose;
102}
103
104/* As much as I'd like to make X509_check_purpose use a "const" X509*
105 * I really can't because it does recalculate hashes and do other non-const
106 * things. */
107int X509_check_purpose(X509 *x, int id, int ca)
108{
109 int idx;
110 const X509_PURPOSE *pt;
111 if(!(x->ex_flags & EXFLAG_SET)) {
112 CRYPTO_w_lock(CRYPTO_LOCK_X509);
113 x509v3_cache_extensions(x);
114 CRYPTO_w_unlock(CRYPTO_LOCK_X509);
115 }
116 if(id == -1) return 1;
117 idx = X509_PURPOSE_get_by_id(id);
118 if(idx == -1) return -1;
119 pt = X509_PURPOSE_get0(idx);
120 return pt->check_purpose(pt, x, ca);
121}
122
123int X509_PURPOSE_set(int *p, int purpose)
124{
125 if(X509_PURPOSE_get_by_id(purpose) == -1) {
126 X509V3err(X509V3_F_X509_PURPOSE_SET, X509V3_R_INVALID_PURPOSE);
127 return 0;
128 }
129 *p = purpose;
130 return 1;
131}
132
133int X509_PURPOSE_get_count(void)
134{
135 if(!xptable) return X509_PURPOSE_COUNT;
136 return sk_X509_PURPOSE_num(xptable) + X509_PURPOSE_COUNT;
137}
138
139X509_PURPOSE * X509_PURPOSE_get0(int idx)
140{
141 if(idx < 0) return NULL;
142 if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
143 return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
144}
145
146int X509_PURPOSE_get_by_sname(char *sname)
147{
148 int i;
149 X509_PURPOSE *xptmp;
150 for(i = 0; i < X509_PURPOSE_get_count(); i++) {
151 xptmp = X509_PURPOSE_get0(i);
152 if(!strcmp(xptmp->sname, sname)) return i;
153 }
154 return -1;
155}
156
157int X509_PURPOSE_get_by_id(int purpose)
158{
159 X509_PURPOSE tmp;
160 int idx;
161 if((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
162 return purpose - X509_PURPOSE_MIN;
163 tmp.purpose = purpose;
164 if(!xptable) return -1;
165 idx = sk_X509_PURPOSE_find(xptable, &tmp);
166 if(idx == -1) return -1;
167 return idx + X509_PURPOSE_COUNT;
168}
169
170int X509_PURPOSE_add(int id, int trust, int flags,
171 int (*ck)(const X509_PURPOSE *, const X509 *, int),
172 char *name, char *sname, void *arg)
173{
174 int idx;
175 X509_PURPOSE *ptmp;
176 /* This is set according to what we change: application can't set it */
177 flags &= ~X509_PURPOSE_DYNAMIC;
178 /* This will always be set for application modified trust entries */
179 flags |= X509_PURPOSE_DYNAMIC_NAME;
180 /* Get existing entry if any */
181 idx = X509_PURPOSE_get_by_id(id);
182 /* Need a new entry */
183 if(idx == -1) {
184 if(!(ptmp = OPENSSL_malloc(sizeof(X509_PURPOSE)))) {
185 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
186 return 0;
187 }
188 ptmp->flags = X509_PURPOSE_DYNAMIC;
189 } else ptmp = X509_PURPOSE_get0(idx);
190
191 /* OPENSSL_free existing name if dynamic */
192 if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
193 OPENSSL_free(ptmp->name);
194 OPENSSL_free(ptmp->sname);
195 }
196 /* dup supplied name */
197 ptmp->name = BUF_strdup(name);
198 ptmp->sname = BUF_strdup(sname);
199 if(!ptmp->name || !ptmp->sname) {
200 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
201 return 0;
202 }
203 /* Keep the dynamic flag of existing entry */
204 ptmp->flags &= X509_PURPOSE_DYNAMIC;
205 /* Set all other flags */
206 ptmp->flags |= flags;
207
208 ptmp->purpose = id;
209 ptmp->trust = trust;
210 ptmp->check_purpose = ck;
211 ptmp->usr_data = arg;
212
213 /* If its a new entry manage the dynamic table */
214 if(idx == -1) {
215 if(!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) {
216 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
217 return 0;
218 }
219 if (!sk_X509_PURPOSE_push(xptable, ptmp)) {
220 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
221 return 0;
222 }
223 }
224 return 1;
225}
226
227static void xptable_free(X509_PURPOSE *p)
228 {
229 if(!p) return;
230 if (p->flags & X509_PURPOSE_DYNAMIC)
231 {
232 if (p->flags & X509_PURPOSE_DYNAMIC_NAME) {
233 OPENSSL_free(p->name);
234 OPENSSL_free(p->sname);
235 }
236 OPENSSL_free(p);
237 }
238 }
239
240void X509_PURPOSE_cleanup(void)
241{
242 int i;
243 sk_X509_PURPOSE_pop_free(xptable, xptable_free);
244 for(i = 0; i < X509_PURPOSE_COUNT; i++) xptable_free(xstandard + i);
245 xptable = NULL;
246}
247
248int X509_PURPOSE_get_id(X509_PURPOSE *xp)
249{
250 return xp->purpose;
251}
252
253char *X509_PURPOSE_get0_name(X509_PURPOSE *xp)
254{
255 return xp->name;
256}
257
258char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp)
259{
260 return xp->sname;
261}
262
263int X509_PURPOSE_get_trust(X509_PURPOSE *xp)
264{
265 return xp->trust;
266}
267
268static int nid_cmp(int *a, int *b)
269 {
270 return *a - *b;
271 }
272
273int X509_supported_extension(X509_EXTENSION *ex)
274 {
275 /* This table is a list of the NIDs of supported extensions:
276 * that is those which are used by the verify process. If
277 * an extension is critical and doesn't appear in this list
278 * then the verify process will normally reject the certificate.
279 * The list must be kept in numerical order because it will be
280 * searched using bsearch.
281 */
282
283 static int supported_nids[] = {
284 NID_netscape_cert_type, /* 71 */
285 NID_key_usage, /* 83 */
286 NID_subject_alt_name, /* 85 */
287 NID_basic_constraints, /* 87 */
288 NID_ext_key_usage, /* 126 */
289 NID_proxyCertInfo /* 661 */
290 };
291
292 int ex_nid;
293
294 ex_nid = OBJ_obj2nid(X509_EXTENSION_get_object(ex));
295
296 if (ex_nid == NID_undef)
297 return 0;
298
299 if (OBJ_bsearch((char *)&ex_nid, (char *)supported_nids,
300 sizeof(supported_nids)/sizeof(int), sizeof(int),
301 (int (*)(const void *, const void *))nid_cmp))
302 return 1;
303 return 0;
304 }
305
306
307static void x509v3_cache_extensions(X509 *x)
308{
309 BASIC_CONSTRAINTS *bs;
310 PROXY_CERT_INFO_EXTENSION *pci;
311 ASN1_BIT_STRING *usage;
312 ASN1_BIT_STRING *ns;
313 EXTENDED_KEY_USAGE *extusage;
314 X509_EXTENSION *ex;
315
316 int i;
317 if(x->ex_flags & EXFLAG_SET) return;
318#ifndef OPENSSL_NO_SHA
319 X509_digest(x, EVP_sha1(), x->sha1_hash, NULL);
320#endif
321 /* Does subject name match issuer ? */
322 if(!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x)))
323 x->ex_flags |= EXFLAG_SS;
324 /* V1 should mean no extensions ... */
325 if(!X509_get_version(x)) x->ex_flags |= EXFLAG_V1;
326 /* Handle basic constraints */
327 if((bs=X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {
328 if(bs->ca) x->ex_flags |= EXFLAG_CA;
329 if(bs->pathlen) {
330 if((bs->pathlen->type == V_ASN1_NEG_INTEGER)
331 || !bs->ca) {
332 x->ex_flags |= EXFLAG_INVALID;
333 x->ex_pathlen = 0;
334 } else x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);
335 } else x->ex_pathlen = -1;
336 BASIC_CONSTRAINTS_free(bs);
337 x->ex_flags |= EXFLAG_BCONS;
338 }
339 /* Handle proxy certificates */
340 if((pci=X509_get_ext_d2i(x, NID_proxyCertInfo, NULL, NULL))) {
341 if (x->ex_flags & EXFLAG_CA
342 || X509_get_ext_by_NID(x, NID_subject_alt_name, 0) >= 0
343 || X509_get_ext_by_NID(x, NID_issuer_alt_name, 0) >= 0) {
344 x->ex_flags |= EXFLAG_INVALID;
345 }
346 PROXY_CERT_INFO_EXTENSION_free(pci);
347 x->ex_flags |= EXFLAG_PROXY;
348 }
349 /* Handle key usage */
350 if((usage=X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {
351 if(usage->length > 0) {
352 x->ex_kusage = usage->data[0];
353 if(usage->length > 1)
354 x->ex_kusage |= usage->data[1] << 8;
355 } else x->ex_kusage = 0;
356 x->ex_flags |= EXFLAG_KUSAGE;
357 ASN1_BIT_STRING_free(usage);
358 }
359 x->ex_xkusage = 0;
360 if((extusage=X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {
361 x->ex_flags |= EXFLAG_XKUSAGE;
362 for(i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {
363 switch(OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage,i))) {
364 case NID_server_auth:
365 x->ex_xkusage |= XKU_SSL_SERVER;
366 break;
367
368 case NID_client_auth:
369 x->ex_xkusage |= XKU_SSL_CLIENT;
370 break;
371
372 case NID_email_protect:
373 x->ex_xkusage |= XKU_SMIME;
374 break;
375
376 case NID_code_sign:
377 x->ex_xkusage |= XKU_CODE_SIGN;
378 break;
379
380 case NID_ms_sgc:
381 case NID_ns_sgc:
382 x->ex_xkusage |= XKU_SGC;
383 break;
384
385 case NID_OCSP_sign:
386 x->ex_xkusage |= XKU_OCSP_SIGN;
387 break;
388
389 case NID_time_stamp:
390 x->ex_xkusage |= XKU_TIMESTAMP;
391 break;
392
393 case NID_dvcs:
394 x->ex_xkusage |= XKU_DVCS;
395 break;
396 }
397 }
398 sk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);
399 }
400
401 if((ns=X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {
402 if(ns->length > 0) x->ex_nscert = ns->data[0];
403 else x->ex_nscert = 0;
404 x->ex_flags |= EXFLAG_NSCERT;
405 ASN1_BIT_STRING_free(ns);
406 }
407 x->skid =X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL);
408 x->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);
409 for (i = 0; i < X509_get_ext_count(x); i++)
410 {
411 ex = X509_get_ext(x, i);
412 if (!X509_EXTENSION_get_critical(ex))
413 continue;
414 if (!X509_supported_extension(ex))
415 {
416 x->ex_flags |= EXFLAG_CRITICAL;
417 break;
418 }
419 }
420 x->ex_flags |= EXFLAG_SET;
421}
422
423/* CA checks common to all purposes
424 * return codes:
425 * 0 not a CA
426 * 1 is a CA
427 * 2 basicConstraints absent so "maybe" a CA
428 * 3 basicConstraints absent but self signed V1.
429 * 4 basicConstraints absent but keyUsage present and keyCertSign asserted.
430 */
431
432#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)
433#define ku_reject(x, usage) \
434 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
435#define xku_reject(x, usage) \
436 (((x)->ex_flags & EXFLAG_XKUSAGE) && !((x)->ex_xkusage & (usage)))
437#define ns_reject(x, usage) \
438 (((x)->ex_flags & EXFLAG_NSCERT) && !((x)->ex_nscert & (usage)))
439
440static int check_ca(const X509 *x)
441{
442 /* keyUsage if present should allow cert signing */
443 if(ku_reject(x, KU_KEY_CERT_SIGN)) return 0;
444 if(x->ex_flags & EXFLAG_BCONS) {
445 if(x->ex_flags & EXFLAG_CA) return 1;
446 /* If basicConstraints says not a CA then say so */
447 else return 0;
448 } else {
449 /* we support V1 roots for... uh, I don't really know why. */
450 if((x->ex_flags & V1_ROOT) == V1_ROOT) return 3;
451 /* If key usage present it must have certSign so tolerate it */
452 else if (x->ex_flags & EXFLAG_KUSAGE) return 4;
453 /* Older certificates could have Netscape-specific CA types */
454 else if (x->ex_flags & EXFLAG_NSCERT
455 && x->ex_nscert & NS_ANY_CA) return 5;
456 /* can this still be regarded a CA certificate? I doubt it */
457 return 0;
458 }
459}
460
461int X509_check_ca(X509 *x)
462{
463 if(!(x->ex_flags & EXFLAG_SET)) {
464 CRYPTO_w_lock(CRYPTO_LOCK_X509);
465 x509v3_cache_extensions(x);
466 CRYPTO_w_unlock(CRYPTO_LOCK_X509);
467 }
468
469 return check_ca(x);
470}
471
472/* Check SSL CA: common checks for SSL client and server */
473static int check_ssl_ca(const X509 *x)
474{
475 int ca_ret;
476 ca_ret = check_ca(x);
477 if(!ca_ret) return 0;
478 /* check nsCertType if present */
479 if(ca_ret != 5 || x->ex_nscert & NS_SSL_CA) return ca_ret;
480 else return 0;
481}
482
483
484static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x, int ca)
485{
486 if(xku_reject(x,XKU_SSL_CLIENT)) return 0;
487 if(ca) return check_ssl_ca(x);
488 /* We need to do digital signatures with it */
489 if(ku_reject(x,KU_DIGITAL_SIGNATURE)) return 0;
490 /* nsCertType if present should allow SSL client use */
491 if(ns_reject(x, NS_SSL_CLIENT)) return 0;
492 return 1;
493}
494
495static int check_purpose_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca)
496{
497 if(xku_reject(x,XKU_SSL_SERVER|XKU_SGC)) return 0;
498 if(ca) return check_ssl_ca(x);
499
500 if(ns_reject(x, NS_SSL_SERVER)) return 0;
501 /* Now as for keyUsage: we'll at least need to sign OR encipher */
502 if(ku_reject(x, KU_DIGITAL_SIGNATURE|KU_KEY_ENCIPHERMENT)) return 0;
503
504 return 1;
505
506}
507
508static int check_purpose_ns_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca)
509{
510 int ret;
511 ret = check_purpose_ssl_server(xp, x, ca);
512 if(!ret || ca) return ret;
513 /* We need to encipher or Netscape complains */
514 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
515 return ret;
516}
517
518/* common S/MIME checks */
519static int purpose_smime(const X509 *x, int ca)
520{
521 if(xku_reject(x,XKU_SMIME)) return 0;
522 if(ca) {
523 int ca_ret;
524 ca_ret = check_ca(x);
525 if(!ca_ret) return 0;
526 /* check nsCertType if present */
527 if(ca_ret != 5 || x->ex_nscert & NS_SMIME_CA) return ca_ret;
528 else return 0;
529 }
530 if(x->ex_flags & EXFLAG_NSCERT) {
531 if(x->ex_nscert & NS_SMIME) return 1;
532 /* Workaround for some buggy certificates */
533 if(x->ex_nscert & NS_SSL_CLIENT) return 2;
534 return 0;
535 }
536 return 1;
537}
538
539static int check_purpose_smime_sign(const X509_PURPOSE *xp, const X509 *x, int ca)
540{
541 int ret;
542 ret = purpose_smime(x, ca);
543 if(!ret || ca) return ret;
544 if(ku_reject(x, KU_DIGITAL_SIGNATURE|KU_NON_REPUDIATION)) return 0;
545 return ret;
546}
547
548static int check_purpose_smime_encrypt(const X509_PURPOSE *xp, const X509 *x, int ca)
549{
550 int ret;
551 ret = purpose_smime(x, ca);
552 if(!ret || ca) return ret;
553 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
554 return ret;
555}
556
557static int check_purpose_crl_sign(const X509_PURPOSE *xp, const X509 *x, int ca)
558{
559 if(ca) {
560 int ca_ret;
561 if((ca_ret = check_ca(x)) != 2) return ca_ret;
562 else return 0;
563 }
564 if(ku_reject(x, KU_CRL_SIGN)) return 0;
565 return 1;
566}
567
568/* OCSP helper: this is *not* a full OCSP check. It just checks that
569 * each CA is valid. Additional checks must be made on the chain.
570 */
571
572static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca)
573{
574 /* Must be a valid CA. Should we really support the "I don't know"
575 value (2)? */
576 if(ca) return check_ca(x);
577 /* leaf certificate is checked in OCSP_verify() */
578 return 1;
579}
580
581static int no_check(const X509_PURPOSE *xp, const X509 *x, int ca)
582{
583 return 1;
584}
585
586/* Various checks to see if one certificate issued the second.
587 * This can be used to prune a set of possible issuer certificates
588 * which have been looked up using some simple method such as by
589 * subject name.
590 * These are:
591 * 1. Check issuer_name(subject) == subject_name(issuer)
592 * 2. If akid(subject) exists check it matches issuer
593 * 3. If key_usage(issuer) exists check it supports certificate signing
594 * returns 0 for OK, positive for reason for mismatch, reasons match
595 * codes for X509_verify_cert()
596 */
597
598int X509_check_issued(X509 *issuer, X509 *subject)
599{
600 if(X509_NAME_cmp(X509_get_subject_name(issuer),
601 X509_get_issuer_name(subject)))
602 return X509_V_ERR_SUBJECT_ISSUER_MISMATCH;
603 x509v3_cache_extensions(issuer);
604 x509v3_cache_extensions(subject);
605 if(subject->akid) {
606 /* Check key ids (if present) */
607 if(subject->akid->keyid && issuer->skid &&
608 ASN1_OCTET_STRING_cmp(subject->akid->keyid, issuer->skid) )
609 return X509_V_ERR_AKID_SKID_MISMATCH;
610 /* Check serial number */
611 if(subject->akid->serial &&
612 ASN1_INTEGER_cmp(X509_get_serialNumber(issuer),
613 subject->akid->serial))
614 return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
615 /* Check issuer name */
616 if(subject->akid->issuer) {
617 /* Ugh, for some peculiar reason AKID includes
618 * SEQUENCE OF GeneralName. So look for a DirName.
619 * There may be more than one but we only take any
620 * notice of the first.
621 */
622 GENERAL_NAMES *gens;
623 GENERAL_NAME *gen;
624 X509_NAME *nm = NULL;
625 int i;
626 gens = subject->akid->issuer;
627 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
628 gen = sk_GENERAL_NAME_value(gens, i);
629 if(gen->type == GEN_DIRNAME) {
630 nm = gen->d.dirn;
631 break;
632 }
633 }
634 if(nm && X509_NAME_cmp(nm, X509_get_issuer_name(issuer)))
635 return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
636 }
637 }
638 if(subject->ex_flags & EXFLAG_PROXY)
639 {
640 if(ku_reject(issuer, KU_DIGITAL_SIGNATURE))
641 return X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE;
642 }
643 else if(ku_reject(issuer, KU_KEY_CERT_SIGN))
644 return X509_V_ERR_KEYUSAGE_NO_CERTSIGN;
645 return X509_V_OK;
646}
647
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c
deleted file mode 100644
index c0f044ac1b..0000000000
--- a/src/lib/libcrypto/x509v3/v3_skey.c
+++ /dev/null
@@ -1,144 +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, ASN1_ITEM_ref(ASN1_OCTET_STRING),
670,0,0,0,
68(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING,
69(X509V3_EXT_S2I)s2i_skey_id,
700,0,0,0,
71NULL};
72
73char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
74 ASN1_OCTET_STRING *oct)
75{
76 return hex_to_string(oct->data, oct->length);
77}
78
79ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
80 X509V3_CTX *ctx, char *str)
81{
82 ASN1_OCTET_STRING *oct;
83 long length;
84
85 if(!(oct = M_ASN1_OCTET_STRING_new())) {
86 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89
90 if(!(oct->data = string_to_hex(str, &length))) {
91 M_ASN1_OCTET_STRING_free(oct);
92 return NULL;
93 }
94
95 oct->length = length;
96
97 return oct;
98
99}
100
101static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
102 X509V3_CTX *ctx, char *str)
103{
104 ASN1_OCTET_STRING *oct;
105 ASN1_BIT_STRING *pk;
106 unsigned char pkey_dig[EVP_MAX_MD_SIZE];
107 unsigned int diglen;
108
109 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str);
110
111 if(!(oct = M_ASN1_OCTET_STRING_new())) {
112 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
113 return NULL;
114 }
115
116 if(ctx && (ctx->flags == CTX_TEST)) return oct;
117
118 if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
119 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
120 goto err;
121 }
122
123 if(ctx->subject_req)
124 pk = ctx->subject_req->req_info->pubkey->public_key;
125 else pk = ctx->subject_cert->cert_info->key->public_key;
126
127 if(!pk) {
128 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
129 goto err;
130 }
131
132 EVP_Digest(pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL);
133
134 if(!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
135 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
136 goto err;
137 }
138
139 return oct;
140
141 err:
142 M_ASN1_OCTET_STRING_free(oct);
143 return NULL;
144}
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
deleted file mode 100644
index d3f4ba3a72..0000000000
--- a/src/lib/libcrypto/x509v3/v3_sxnet.c
+++ /dev/null
@@ -1,262 +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/asn1t.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, ASN1_ITEM_ref(SXNET),
770,0,0,0,
780,0,
790,
80#ifdef SXNET_TEST
81(X509V3_EXT_V2I)sxnet_v2i,
82#else
830,
84#endif
85(X509V3_EXT_I2R)sxnet_i2r,
860,
87NULL
88};
89
90ASN1_SEQUENCE(SXNETID) = {
91 ASN1_SIMPLE(SXNETID, zone, ASN1_INTEGER),
92 ASN1_SIMPLE(SXNETID, user, ASN1_OCTET_STRING)
93} ASN1_SEQUENCE_END(SXNETID)
94
95IMPLEMENT_ASN1_FUNCTIONS(SXNETID)
96
97ASN1_SEQUENCE(SXNET) = {
98 ASN1_SIMPLE(SXNET, version, ASN1_INTEGER),
99 ASN1_SEQUENCE_OF(SXNET, ids, SXNETID)
100} ASN1_SEQUENCE_END(SXNET)
101
102IMPLEMENT_ASN1_FUNCTIONS(SXNET)
103
104static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
105 int indent)
106{
107 long v;
108 char *tmp;
109 SXNETID *id;
110 int i;
111 v = ASN1_INTEGER_get(sx->version);
112 BIO_printf(out, "%*sVersion: %d (0x%X)", indent, "", v + 1, v);
113 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
114 id = sk_SXNETID_value(sx->ids, i);
115 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
116 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
117 OPENSSL_free(tmp);
118 M_ASN1_OCTET_STRING_print(out, id->user);
119 }
120 return 1;
121}
122
123#ifdef SXNET_TEST
124
125/* NBB: this is used for testing only. It should *not* be used for anything
126 * else because it will just take static IDs from the configuration file and
127 * they should really be separate values for each user.
128 */
129
130
131static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
132 STACK_OF(CONF_VALUE) *nval)
133{
134 CONF_VALUE *cnf;
135 SXNET *sx = NULL;
136 int i;
137 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
138 cnf = sk_CONF_VALUE_value(nval, i);
139 if(!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
140 return NULL;
141 }
142 return sx;
143}
144
145
146#endif
147
148/* Strong Extranet utility functions */
149
150/* Add an id given the zone as an ASCII number */
151
152int SXNET_add_id_asc(SXNET **psx, char *zone, char *user,
153 int userlen)
154{
155 ASN1_INTEGER *izone = NULL;
156 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
157 X509V3err(X509V3_F_SXNET_ADD_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
158 return 0;
159 }
160 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
161}
162
163/* Add an id given the zone as an unsigned long */
164
165int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
166 int userlen)
167{
168 ASN1_INTEGER *izone = NULL;
169 if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
170 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
171 M_ASN1_INTEGER_free(izone);
172 return 0;
173 }
174 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
175
176}
177
178/* Add an id given the zone as an ASN1_INTEGER.
179 * Note this version uses the passed integer and doesn't make a copy so don't
180 * free it up afterwards.
181 */
182
183int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
184 int userlen)
185{
186 SXNET *sx = NULL;
187 SXNETID *id = NULL;
188 if(!psx || !zone || !user) {
189 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT);
190 return 0;
191 }
192 if(userlen == -1) userlen = strlen(user);
193 if(userlen > 64) {
194 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG);
195 return 0;
196 }
197 if(!*psx) {
198 if(!(sx = SXNET_new())) goto err;
199 if(!ASN1_INTEGER_set(sx->version, 0)) goto err;
200 *psx = sx;
201 } else sx = *psx;
202 if(SXNET_get_id_INTEGER(sx, zone)) {
203 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID);
204 return 0;
205 }
206
207 if(!(id = SXNETID_new())) goto err;
208 if(userlen == -1) userlen = strlen(user);
209
210 if(!M_ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err;
211 if(!sk_SXNETID_push(sx->ids, id)) goto err;
212 id->zone = zone;
213 return 1;
214
215 err:
216 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE);
217 SXNETID_free(id);
218 SXNET_free(sx);
219 *psx = NULL;
220 return 0;
221}
222
223ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone)
224{
225 ASN1_INTEGER *izone = NULL;
226 ASN1_OCTET_STRING *oct;
227 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
228 X509V3err(X509V3_F_SXNET_GET_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
229 return NULL;
230 }
231 oct = SXNET_get_id_INTEGER(sx, izone);
232 M_ASN1_INTEGER_free(izone);
233 return oct;
234}
235
236ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
237{
238 ASN1_INTEGER *izone = NULL;
239 ASN1_OCTET_STRING *oct;
240 if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
241 X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);
242 M_ASN1_INTEGER_free(izone);
243 return NULL;
244 }
245 oct = SXNET_get_id_INTEGER(sx, izone);
246 M_ASN1_INTEGER_free(izone);
247 return oct;
248}
249
250ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
251{
252 SXNETID *id;
253 int i;
254 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
255 id = sk_SXNETID_value(sx->ids, i);
256 if(!M_ASN1_INTEGER_cmp(id->zone, zone)) return id->user;
257 }
258 return NULL;
259}
260
261IMPLEMENT_STACK_OF(SXNETID)
262IMPLEMENT_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 f23a8d29a0..0000000000
--- a/src/lib/libcrypto/x509v3/v3_utl.c
+++ /dev/null
@@ -1,535 +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);
68static int sk_strcmp(const char * const *a, const char * const *b);
69static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens);
70static void str_free(void *str);
71static int append_ia5(STACK **sk, ASN1_IA5STRING *email);
72
73/* Add a CONF_VALUE name value pair to stack */
74
75int X509V3_add_value(const char *name, const char *value,
76 STACK_OF(CONF_VALUE) **extlist)
77{
78 CONF_VALUE *vtmp = NULL;
79 char *tname = NULL, *tvalue = NULL;
80 if(name && !(tname = BUF_strdup(name))) goto err;
81 if(value && !(tvalue = BUF_strdup(value))) goto err;
82 if(!(vtmp = (CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) goto err;
83 if(!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err;
84 vtmp->section = NULL;
85 vtmp->name = tname;
86 vtmp->value = tvalue;
87 if(!sk_CONF_VALUE_push(*extlist, vtmp)) goto err;
88 return 1;
89 err:
90 X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE);
91 if(vtmp) OPENSSL_free(vtmp);
92 if(tname) OPENSSL_free(tname);
93 if(tvalue) OPENSSL_free(tvalue);
94 return 0;
95}
96
97int X509V3_add_value_uchar(const char *name, const unsigned char *value,
98 STACK_OF(CONF_VALUE) **extlist)
99 {
100 return X509V3_add_value(name,(const char *)value,extlist);
101 }
102
103/* Free function for STACK_OF(CONF_VALUE) */
104
105void X509V3_conf_free(CONF_VALUE *conf)
106{
107 if(!conf) return;
108 if(conf->name) OPENSSL_free(conf->name);
109 if(conf->value) OPENSSL_free(conf->value);
110 if(conf->section) OPENSSL_free(conf->section);
111 OPENSSL_free(conf);
112}
113
114int X509V3_add_value_bool(const char *name, int asn1_bool,
115 STACK_OF(CONF_VALUE) **extlist)
116{
117 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
118 return X509V3_add_value(name, "FALSE", extlist);
119}
120
121int X509V3_add_value_bool_nf(char *name, int asn1_bool,
122 STACK_OF(CONF_VALUE) **extlist)
123{
124 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
125 return 1;
126}
127
128
129char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *a)
130{
131 BIGNUM *bntmp = NULL;
132 char *strtmp = NULL;
133 if(!a) return NULL;
134 if(!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) ||
135 !(strtmp = BN_bn2dec(bntmp)) )
136 X509V3err(X509V3_F_I2S_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
137 BN_free(bntmp);
138 return strtmp;
139}
140
141char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a)
142{
143 BIGNUM *bntmp = NULL;
144 char *strtmp = NULL;
145 if(!a) return NULL;
146 if(!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||
147 !(strtmp = BN_bn2dec(bntmp)) )
148 X509V3err(X509V3_F_I2S_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
149 BN_free(bntmp);
150 return strtmp;
151}
152
153ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
154{
155 BIGNUM *bn = NULL;
156 ASN1_INTEGER *aint;
157 int isneg, ishex;
158 int ret;
159 bn = BN_new();
160 if (!value) {
161 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE);
162 return 0;
163 }
164 if (value[0] == '-') {
165 value++;
166 isneg = 1;
167 } else isneg = 0;
168
169 if (value[0] == '0' && ((value[1] == 'x') || (value[1] == 'X'))) {
170 value += 2;
171 ishex = 1;
172 } else ishex = 0;
173
174 if (ishex) ret = BN_hex2bn(&bn, value);
175 else ret = BN_dec2bn(&bn, value);
176
177 if (!ret) {
178 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR);
179 return 0;
180 }
181
182 if (isneg && BN_is_zero(bn)) isneg = 0;
183
184 aint = BN_to_ASN1_INTEGER(bn, NULL);
185 BN_free(bn);
186 if (!aint) {
187 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
188 return 0;
189 }
190 if (isneg) aint->type |= V_ASN1_NEG;
191 return aint;
192}
193
194int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
195 STACK_OF(CONF_VALUE) **extlist)
196{
197 char *strtmp;
198 int ret;
199 if(!aint) return 1;
200 if(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0;
201 ret = X509V3_add_value(name, strtmp, extlist);
202 OPENSSL_free(strtmp);
203 return ret;
204}
205
206int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool)
207{
208 char *btmp;
209 if(!(btmp = value->value)) goto err;
210 if(!strcmp(btmp, "TRUE") || !strcmp(btmp, "true")
211 || !strcmp(btmp, "Y") || !strcmp(btmp, "y")
212 || !strcmp(btmp, "YES") || !strcmp(btmp, "yes")) {
213 *asn1_bool = 0xff;
214 return 1;
215 } else if(!strcmp(btmp, "FALSE") || !strcmp(btmp, "false")
216 || !strcmp(btmp, "N") || !strcmp(btmp, "n")
217 || !strcmp(btmp, "NO") || !strcmp(btmp, "no")) {
218 *asn1_bool = 0;
219 return 1;
220 }
221 err:
222 X509V3err(X509V3_F_X509V3_GET_VALUE_BOOL,X509V3_R_INVALID_BOOLEAN_STRING);
223 X509V3_conf_err(value);
224 return 0;
225}
226
227int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint)
228{
229 ASN1_INTEGER *itmp;
230 if(!(itmp = s2i_ASN1_INTEGER(NULL, value->value))) {
231 X509V3_conf_err(value);
232 return 0;
233 }
234 *aint = itmp;
235 return 1;
236}
237
238#define HDR_NAME 1
239#define HDR_VALUE 2
240
241/*#define DEBUG*/
242
243STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line)
244{
245 char *p, *q, c;
246 char *ntmp, *vtmp;
247 STACK_OF(CONF_VALUE) *values = NULL;
248 char *linebuf;
249 int state;
250 /* We are going to modify the line so copy it first */
251 linebuf = BUF_strdup(line);
252 state = HDR_NAME;
253 ntmp = NULL;
254 /* Go through all characters */
255 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
256
257 switch(state) {
258 case HDR_NAME:
259 if(c == ':') {
260 state = HDR_VALUE;
261 *p = 0;
262 ntmp = strip_spaces(q);
263 if(!ntmp) {
264 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
265 goto err;
266 }
267 q = p + 1;
268 } else if(c == ',') {
269 *p = 0;
270 ntmp = strip_spaces(q);
271 q = p + 1;
272#if 0
273 printf("%s\n", ntmp);
274#endif
275 if(!ntmp) {
276 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
277 goto err;
278 }
279 X509V3_add_value(ntmp, NULL, &values);
280 }
281 break ;
282
283 case HDR_VALUE:
284 if(c == ',') {
285 state = HDR_NAME;
286 *p = 0;
287 vtmp = strip_spaces(q);
288#if 0
289 printf("%s\n", ntmp);
290#endif
291 if(!vtmp) {
292 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
293 goto err;
294 }
295 X509V3_add_value(ntmp, vtmp, &values);
296 ntmp = NULL;
297 q = p + 1;
298 }
299
300 }
301 }
302
303 if(state == HDR_VALUE) {
304 vtmp = strip_spaces(q);
305#if 0
306 printf("%s=%s\n", ntmp, vtmp);
307#endif
308 if(!vtmp) {
309 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
310 goto err;
311 }
312 X509V3_add_value(ntmp, vtmp, &values);
313 } else {
314 ntmp = strip_spaces(q);
315#if 0
316 printf("%s\n", ntmp);
317#endif
318 if(!ntmp) {
319 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
320 goto err;
321 }
322 X509V3_add_value(ntmp, NULL, &values);
323 }
324OPENSSL_free(linebuf);
325return values;
326
327err:
328OPENSSL_free(linebuf);
329sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
330return NULL;
331
332}
333
334/* Delete leading and trailing spaces from a string */
335static char *strip_spaces(char *name)
336{
337 char *p, *q;
338 /* Skip over leading spaces */
339 p = name;
340 while(isspace((unsigned char)*p)) p++;
341 if(!*p) return NULL;
342 q = p + strlen(p) - 1;
343 while((q != p) && isspace((unsigned char)*q)) q--;
344 if(p != q) q[1] = 0;
345 if(!*p) return NULL;
346 return p;
347}
348
349/* hex string utilities */
350
351/* Given a buffer of length 'len' return a OPENSSL_malloc'ed string with its
352 * hex representation
353 * @@@ (Contents of buffer are always kept in ASCII, also on EBCDIC machines)
354 */
355
356char *hex_to_string(unsigned char *buffer, long len)
357{
358 char *tmp, *q;
359 unsigned char *p;
360 int i;
361 static char hexdig[] = "0123456789ABCDEF";
362 if(!buffer || !len) return NULL;
363 if(!(tmp = OPENSSL_malloc(len * 3 + 1))) {
364 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
365 return NULL;
366 }
367 q = tmp;
368 for(i = 0, p = buffer; i < len; i++,p++) {
369 *q++ = hexdig[(*p >> 4) & 0xf];
370 *q++ = hexdig[*p & 0xf];
371 *q++ = ':';
372 }
373 q[-1] = 0;
374#ifdef CHARSET_EBCDIC
375 ebcdic2ascii(tmp, tmp, q - tmp - 1);
376#endif
377
378 return tmp;
379}
380
381/* Give a string of hex digits convert to
382 * a buffer
383 */
384
385unsigned char *string_to_hex(char *str, long *len)
386{
387 unsigned char *hexbuf, *q;
388 unsigned char ch, cl, *p;
389 if(!str) {
390 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_INVALID_NULL_ARGUMENT);
391 return NULL;
392 }
393 if(!(hexbuf = OPENSSL_malloc(strlen(str) >> 1))) goto err;
394 for(p = (unsigned char *)str, q = hexbuf; *p;) {
395 ch = *p++;
396#ifdef CHARSET_EBCDIC
397 ch = os_toebcdic[ch];
398#endif
399 if(ch == ':') continue;
400 cl = *p++;
401#ifdef CHARSET_EBCDIC
402 cl = os_toebcdic[cl];
403#endif
404 if(!cl) {
405 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ODD_NUMBER_OF_DIGITS);
406 OPENSSL_free(hexbuf);
407 return NULL;
408 }
409 if(isupper(ch)) ch = tolower(ch);
410 if(isupper(cl)) cl = tolower(cl);
411
412 if((ch >= '0') && (ch <= '9')) ch -= '0';
413 else if ((ch >= 'a') && (ch <= 'f')) ch -= 'a' - 10;
414 else goto badhex;
415
416 if((cl >= '0') && (cl <= '9')) cl -= '0';
417 else if ((cl >= 'a') && (cl <= 'f')) cl -= 'a' - 10;
418 else goto badhex;
419
420 *q++ = (ch << 4) | cl;
421 }
422
423 if(len) *len = q - hexbuf;
424
425 return hexbuf;
426
427 err:
428 if(hexbuf) OPENSSL_free(hexbuf);
429 X509V3err(X509V3_F_STRING_TO_HEX,ERR_R_MALLOC_FAILURE);
430 return NULL;
431
432 badhex:
433 OPENSSL_free(hexbuf);
434 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ILLEGAL_HEX_DIGIT);
435 return NULL;
436
437}
438
439/* V2I name comparison function: returns zero if 'name' matches
440 * cmp or cmp.*
441 */
442
443int name_cmp(const char *name, const char *cmp)
444{
445 int len, ret;
446 char c;
447 len = strlen(cmp);
448 if((ret = strncmp(name, cmp, len))) return ret;
449 c = name[len];
450 if(!c || (c=='.')) return 0;
451 return 1;
452}
453
454static int sk_strcmp(const char * const *a, const char * const *b)
455{
456 return strcmp(*a, *b);
457}
458
459STACK *X509_get1_email(X509 *x)
460{
461 GENERAL_NAMES *gens;
462 STACK *ret;
463 gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL);
464 ret = get_email(X509_get_subject_name(x), gens);
465 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
466 return ret;
467}
468
469STACK *X509_REQ_get1_email(X509_REQ *x)
470{
471 GENERAL_NAMES *gens;
472 STACK_OF(X509_EXTENSION) *exts;
473 STACK *ret;
474 exts = X509_REQ_get_extensions(x);
475 gens = X509V3_get_d2i(exts, NID_subject_alt_name, NULL, NULL);
476 ret = get_email(X509_REQ_get_subject_name(x), gens);
477 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
478 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
479 return ret;
480}
481
482
483static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
484{
485 STACK *ret = NULL;
486 X509_NAME_ENTRY *ne;
487 ASN1_IA5STRING *email;
488 GENERAL_NAME *gen;
489 int i;
490 /* Now add any email address(es) to STACK */
491 i = -1;
492 /* First supplied X509_NAME */
493 while((i = X509_NAME_get_index_by_NID(name,
494 NID_pkcs9_emailAddress, i)) >= 0) {
495 ne = X509_NAME_get_entry(name, i);
496 email = X509_NAME_ENTRY_get_data(ne);
497 if(!append_ia5(&ret, email)) return NULL;
498 }
499 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++)
500 {
501 gen = sk_GENERAL_NAME_value(gens, i);
502 if(gen->type != GEN_EMAIL) continue;
503 if(!append_ia5(&ret, gen->d.ia5)) return NULL;
504 }
505 return ret;
506}
507
508static void str_free(void *str)
509{
510 OPENSSL_free(str);
511}
512
513static int append_ia5(STACK **sk, ASN1_IA5STRING *email)
514{
515 char *emtmp;
516 /* First some sanity checks */
517 if(email->type != V_ASN1_IA5STRING) return 1;
518 if(!email->data || !email->length) return 1;
519 if(!*sk) *sk = sk_new(sk_strcmp);
520 if(!*sk) return 0;
521 /* Don't add duplicates */
522 if(sk_find(*sk, (char *)email->data) != -1) return 1;
523 emtmp = BUF_strdup((char *)email->data);
524 if(!emtmp || !sk_push(*sk, emtmp)) {
525 X509_email_free(*sk);
526 *sk = NULL;
527 return 0;
528 }
529 return 1;
530}
531
532void X509_email_free(STACK *sk)
533{
534 sk_pop_free(sk, str_free);
535}
diff --git a/src/lib/libcrypto/x509v3/v3err.c b/src/lib/libcrypto/x509v3/v3err.c
deleted file mode 100644
index e1edaf5248..0000000000
--- a/src/lib/libcrypto/x509v3/v3err.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/* crypto/x509v3/v3err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509V3,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509V3,0,reason)
70
71static ERR_STRING_DATA X509V3_str_functs[]=
72 {
73{ERR_FUNC(X509V3_F_COPY_EMAIL), "COPY_EMAIL"},
74{ERR_FUNC(X509V3_F_COPY_ISSUER), "COPY_ISSUER"},
75{ERR_FUNC(X509V3_F_DO_EXT_CONF), "DO_EXT_CONF"},
76{ERR_FUNC(X509V3_F_DO_EXT_I2D), "DO_EXT_I2D"},
77{ERR_FUNC(X509V3_F_HEX_TO_STRING), "hex_to_string"},
78{ERR_FUNC(X509V3_F_I2S_ASN1_ENUMERATED), "i2s_ASN1_ENUMERATED"},
79{ERR_FUNC(X509V3_F_I2S_ASN1_IA5STRING), "I2S_ASN1_IA5STRING"},
80{ERR_FUNC(X509V3_F_I2S_ASN1_INTEGER), "i2s_ASN1_INTEGER"},
81{ERR_FUNC(X509V3_F_I2V_AUTHORITY_INFO_ACCESS), "I2V_AUTHORITY_INFO_ACCESS"},
82{ERR_FUNC(X509V3_F_NOTICE_SECTION), "NOTICE_SECTION"},
83{ERR_FUNC(X509V3_F_NREF_NOS), "NREF_NOS"},
84{ERR_FUNC(X509V3_F_POLICY_SECTION), "POLICY_SECTION"},
85{ERR_FUNC(X509V3_F_R2I_CERTPOL), "R2I_CERTPOL"},
86{ERR_FUNC(X509V3_F_R2I_PCI), "R2I_PCI"},
87{ERR_FUNC(X509V3_F_S2I_ASN1_IA5STRING), "S2I_ASN1_IA5STRING"},
88{ERR_FUNC(X509V3_F_S2I_ASN1_INTEGER), "s2i_ASN1_INTEGER"},
89{ERR_FUNC(X509V3_F_S2I_ASN1_OCTET_STRING), "s2i_ASN1_OCTET_STRING"},
90{ERR_FUNC(X509V3_F_S2I_ASN1_SKEY_ID), "S2I_ASN1_SKEY_ID"},
91{ERR_FUNC(X509V3_F_S2I_S2I_SKEY_ID), "S2I_S2I_SKEY_ID"},
92{ERR_FUNC(X509V3_F_STRING_TO_HEX), "string_to_hex"},
93{ERR_FUNC(X509V3_F_SXNET_ADD_ASC), "SXNET_ADD_ASC"},
94{ERR_FUNC(X509V3_F_SXNET_ADD_ID_INTEGER), "SXNET_add_id_INTEGER"},
95{ERR_FUNC(X509V3_F_SXNET_ADD_ID_ULONG), "SXNET_add_id_ulong"},
96{ERR_FUNC(X509V3_F_SXNET_GET_ID_ASC), "SXNET_get_id_asc"},
97{ERR_FUNC(X509V3_F_SXNET_GET_ID_ULONG), "SXNET_get_id_ulong"},
98{ERR_FUNC(X509V3_F_V2I_ACCESS_DESCRIPTION), "V2I_ACCESS_DESCRIPTION"},
99{ERR_FUNC(X509V3_F_V2I_ASN1_BIT_STRING), "V2I_ASN1_BIT_STRING"},
100{ERR_FUNC(X509V3_F_V2I_AUTHORITY_KEYID), "V2I_AUTHORITY_KEYID"},
101{ERR_FUNC(X509V3_F_V2I_BASIC_CONSTRAINTS), "V2I_BASIC_CONSTRAINTS"},
102{ERR_FUNC(X509V3_F_V2I_CRLD), "V2I_CRLD"},
103{ERR_FUNC(X509V3_F_V2I_EXT_KU), "V2I_EXT_KU"},
104{ERR_FUNC(X509V3_F_V2I_GENERAL_NAME), "v2i_GENERAL_NAME"},
105{ERR_FUNC(X509V3_F_V2I_GENERAL_NAMES), "v2i_GENERAL_NAMES"},
106{ERR_FUNC(X509V3_F_V3_GENERIC_EXTENSION), "V3_GENERIC_EXTENSION"},
107{ERR_FUNC(X509V3_F_X509V3_ADD_I2D), "X509V3_ADD_I2D"},
108{ERR_FUNC(X509V3_F_X509V3_ADD_VALUE), "X509V3_add_value"},
109{ERR_FUNC(X509V3_F_X509V3_EXT_ADD), "X509V3_EXT_add"},
110{ERR_FUNC(X509V3_F_X509V3_EXT_ADD_ALIAS), "X509V3_EXT_add_alias"},
111{ERR_FUNC(X509V3_F_X509V3_EXT_CONF), "X509V3_EXT_conf"},
112{ERR_FUNC(X509V3_F_X509V3_EXT_I2D), "X509V3_EXT_i2d"},
113{ERR_FUNC(X509V3_F_X509V3_GET_VALUE_BOOL), "X509V3_get_value_bool"},
114{ERR_FUNC(X509V3_F_X509V3_PARSE_LIST), "X509V3_parse_list"},
115{ERR_FUNC(X509V3_F_X509_PURPOSE_ADD), "X509_PURPOSE_add"},
116{ERR_FUNC(X509V3_F_X509_PURPOSE_SET), "X509_PURPOSE_set"},
117{0,NULL}
118 };
119
120static ERR_STRING_DATA X509V3_str_reasons[]=
121 {
122{ERR_REASON(X509V3_R_BAD_IP_ADDRESS) ,"bad ip address"},
123{ERR_REASON(X509V3_R_BAD_OBJECT) ,"bad object"},
124{ERR_REASON(X509V3_R_BN_DEC2BN_ERROR) ,"bn dec2bn error"},
125{ERR_REASON(X509V3_R_BN_TO_ASN1_INTEGER_ERROR),"bn to asn1 integer error"},
126{ERR_REASON(X509V3_R_DUPLICATE_ZONE_ID) ,"duplicate zone id"},
127{ERR_REASON(X509V3_R_ERROR_CONVERTING_ZONE),"error converting zone"},
128{ERR_REASON(X509V3_R_ERROR_CREATING_EXTENSION),"error creating extension"},
129{ERR_REASON(X509V3_R_ERROR_IN_EXTENSION) ,"error in extension"},
130{ERR_REASON(X509V3_R_EXPECTED_A_SECTION_NAME),"expected a section name"},
131{ERR_REASON(X509V3_R_EXTENSION_EXISTS) ,"extension exists"},
132{ERR_REASON(X509V3_R_EXTENSION_NAME_ERROR),"extension name error"},
133{ERR_REASON(X509V3_R_EXTENSION_NOT_FOUND),"extension not found"},
134{ERR_REASON(X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED),"extension setting not supported"},
135{ERR_REASON(X509V3_R_EXTENSION_VALUE_ERROR),"extension value error"},
136{ERR_REASON(X509V3_R_ILLEGAL_HEX_DIGIT) ,"illegal hex digit"},
137{ERR_REASON(X509V3_R_INCORRECT_POLICY_SYNTAX_TAG),"incorrect policy syntax tag"},
138{ERR_REASON(X509V3_R_INVALID_BOOLEAN_STRING),"invalid boolean string"},
139{ERR_REASON(X509V3_R_INVALID_EXTENSION_STRING),"invalid extension string"},
140{ERR_REASON(X509V3_R_INVALID_NAME) ,"invalid name"},
141{ERR_REASON(X509V3_R_INVALID_NULL_ARGUMENT),"invalid null argument"},
142{ERR_REASON(X509V3_R_INVALID_NULL_NAME) ,"invalid null name"},
143{ERR_REASON(X509V3_R_INVALID_NULL_VALUE) ,"invalid null value"},
144{ERR_REASON(X509V3_R_INVALID_NUMBER) ,"invalid number"},
145{ERR_REASON(X509V3_R_INVALID_NUMBERS) ,"invalid numbers"},
146{ERR_REASON(X509V3_R_INVALID_OBJECT_IDENTIFIER),"invalid object identifier"},
147{ERR_REASON(X509V3_R_INVALID_OPTION) ,"invalid option"},
148{ERR_REASON(X509V3_R_INVALID_POLICY_IDENTIFIER),"invalid policy identifier"},
149{ERR_REASON(X509V3_R_INVALID_PROXY_POLICY_IDENTIFIER),"invalid proxy policy identifier"},
150{ERR_REASON(X509V3_R_INVALID_PROXY_POLICY_SETTING),"invalid proxy policy setting"},
151{ERR_REASON(X509V3_R_INVALID_PURPOSE) ,"invalid purpose"},
152{ERR_REASON(X509V3_R_INVALID_SECTION) ,"invalid section"},
153{ERR_REASON(X509V3_R_INVALID_SYNTAX) ,"invalid syntax"},
154{ERR_REASON(X509V3_R_ISSUER_DECODE_ERROR),"issuer decode error"},
155{ERR_REASON(X509V3_R_MISSING_VALUE) ,"missing value"},
156{ERR_REASON(X509V3_R_NEED_ORGANIZATION_AND_NUMBERS),"need organization and numbers"},
157{ERR_REASON(X509V3_R_NO_CONFIG_DATABASE) ,"no config database"},
158{ERR_REASON(X509V3_R_NO_ISSUER_CERTIFICATE),"no issuer certificate"},
159{ERR_REASON(X509V3_R_NO_ISSUER_DETAILS) ,"no issuer details"},
160{ERR_REASON(X509V3_R_NO_POLICY_IDENTIFIER),"no policy identifier"},
161{ERR_REASON(X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED),"no proxy cert policy language defined"},
162{ERR_REASON(X509V3_R_NO_PUBLIC_KEY) ,"no public key"},
163{ERR_REASON(X509V3_R_NO_SUBJECT_DETAILS) ,"no subject details"},
164{ERR_REASON(X509V3_R_ODD_NUMBER_OF_DIGITS),"odd number of digits"},
165{ERR_REASON(X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED),"policy language alreadty defined"},
166{ERR_REASON(X509V3_R_POLICY_PATH_LENGTH) ,"policy path length"},
167{ERR_REASON(X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED),"policy path length alreadty defined"},
168{ERR_REASON(X509V3_R_POLICY_SYNTAX_NOT) ,"policy syntax not"},
169{ERR_REASON(X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED),"policy syntax not currently supported"},
170{ERR_REASON(X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY),"policy when proxy language requires no policy"},
171{ERR_REASON(X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS),"unable to get issuer details"},
172{ERR_REASON(X509V3_R_UNABLE_TO_GET_ISSUER_KEYID),"unable to get issuer keyid"},
173{ERR_REASON(X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT),"unknown bit string argument"},
174{ERR_REASON(X509V3_R_UNKNOWN_EXTENSION) ,"unknown extension"},
175{ERR_REASON(X509V3_R_UNKNOWN_EXTENSION_NAME),"unknown extension name"},
176{ERR_REASON(X509V3_R_UNKNOWN_OPTION) ,"unknown option"},
177{ERR_REASON(X509V3_R_UNSUPPORTED_OPTION) ,"unsupported option"},
178{ERR_REASON(X509V3_R_USER_TOO_LONG) ,"user too long"},
179{0,NULL}
180 };
181
182#endif
183
184void ERR_load_X509V3_strings(void)
185 {
186 static int init=1;
187
188 if (init)
189 {
190 init=0;
191#ifndef OPENSSL_NO_ERR
192 ERR_load_strings(0,X509V3_str_functs);
193 ERR_load_strings(0,X509V3_str_reasons);
194#endif
195
196 }
197 }
diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h
deleted file mode 100644
index e6d91251c2..0000000000
--- a/src/lib/libcrypto/x509v3/x509v3.h
+++ /dev/null
@@ -1,687 +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#include <openssl/bio.h>
62#include <openssl/x509.h>
63#include <openssl/conf.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
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;
91/* If this is set the following four fields are ignored */
92ASN1_ITEM_EXP *it;
93/* Old style ASN1 calls */
94X509V3_EXT_NEW ext_new;
95X509V3_EXT_FREE ext_free;
96X509V3_EXT_D2I d2i;
97X509V3_EXT_I2D i2d;
98
99/* The following pair is used for string extensions */
100X509V3_EXT_I2S i2s;
101X509V3_EXT_S2I s2i;
102
103/* The following pair is used for multi-valued extensions */
104X509V3_EXT_I2V i2v;
105X509V3_EXT_V2I v2i;
106
107/* The following are used for raw extensions */
108X509V3_EXT_I2R i2r;
109X509V3_EXT_R2I r2i;
110
111void *usr_data; /* Any extension specific data */
112};
113
114typedef struct X509V3_CONF_METHOD_st {
115char * (*get_string)(void *db, char *section, char *value);
116STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
117void (*free_string)(void *db, char * string);
118void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
119} X509V3_CONF_METHOD;
120
121/* Context specific info */
122struct v3_ext_ctx {
123#define CTX_TEST 0x1
124int flags;
125X509 *issuer_cert;
126X509 *subject_cert;
127X509_REQ *subject_req;
128X509_CRL *crl;
129X509V3_CONF_METHOD *db_meth;
130void *db;
131/* Maybe more here */
132};
133
134typedef struct v3_ext_method X509V3_EXT_METHOD;
135typedef struct v3_ext_ctx X509V3_CTX;
136
137DECLARE_STACK_OF(X509V3_EXT_METHOD)
138
139/* ext_flags values */
140#define X509V3_EXT_DYNAMIC 0x1
141#define X509V3_EXT_CTX_DEP 0x2
142#define X509V3_EXT_MULTILINE 0x4
143
144typedef BIT_STRING_BITNAME ENUMERATED_NAMES;
145
146typedef struct BASIC_CONSTRAINTS_st {
147int ca;
148ASN1_INTEGER *pathlen;
149} BASIC_CONSTRAINTS;
150
151
152typedef struct PKEY_USAGE_PERIOD_st {
153ASN1_GENERALIZEDTIME *notBefore;
154ASN1_GENERALIZEDTIME *notAfter;
155} PKEY_USAGE_PERIOD;
156
157typedef struct otherName_st {
158ASN1_OBJECT *type_id;
159ASN1_TYPE *value;
160} OTHERNAME;
161
162typedef struct EDIPartyName_st {
163 ASN1_STRING *nameAssigner;
164 ASN1_STRING *partyName;
165} EDIPARTYNAME;
166
167typedef struct GENERAL_NAME_st {
168
169#define GEN_OTHERNAME 0
170#define GEN_EMAIL 1
171#define GEN_DNS 2
172#define GEN_X400 3
173#define GEN_DIRNAME 4
174#define GEN_EDIPARTY 5
175#define GEN_URI 6
176#define GEN_IPADD 7
177#define GEN_RID 8
178
179int type;
180union {
181 char *ptr;
182 OTHERNAME *otherName; /* otherName */
183 ASN1_IA5STRING *rfc822Name;
184 ASN1_IA5STRING *dNSName;
185 ASN1_TYPE *x400Address;
186 X509_NAME *directoryName;
187 EDIPARTYNAME *ediPartyName;
188 ASN1_IA5STRING *uniformResourceIdentifier;
189 ASN1_OCTET_STRING *iPAddress;
190 ASN1_OBJECT *registeredID;
191
192 /* Old names */
193 ASN1_OCTET_STRING *ip; /* iPAddress */
194 X509_NAME *dirn; /* dirn */
195 ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */
196 ASN1_OBJECT *rid; /* registeredID */
197 ASN1_TYPE *other; /* x400Address */
198} d;
199} GENERAL_NAME;
200
201typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES;
202
203typedef struct ACCESS_DESCRIPTION_st {
204 ASN1_OBJECT *method;
205 GENERAL_NAME *location;
206} ACCESS_DESCRIPTION;
207
208typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS;
209
210typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE;
211
212DECLARE_STACK_OF(GENERAL_NAME)
213DECLARE_ASN1_SET_OF(GENERAL_NAME)
214
215DECLARE_STACK_OF(ACCESS_DESCRIPTION)
216DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION)
217
218typedef struct DIST_POINT_NAME_st {
219int type;
220union {
221 GENERAL_NAMES *fullname;
222 STACK_OF(X509_NAME_ENTRY) *relativename;
223} name;
224} DIST_POINT_NAME;
225
226typedef struct DIST_POINT_st {
227DIST_POINT_NAME *distpoint;
228ASN1_BIT_STRING *reasons;
229GENERAL_NAMES *CRLissuer;
230} DIST_POINT;
231
232typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS;
233
234DECLARE_STACK_OF(DIST_POINT)
235DECLARE_ASN1_SET_OF(DIST_POINT)
236
237typedef struct AUTHORITY_KEYID_st {
238ASN1_OCTET_STRING *keyid;
239GENERAL_NAMES *issuer;
240ASN1_INTEGER *serial;
241} AUTHORITY_KEYID;
242
243/* Strong extranet structures */
244
245typedef struct SXNET_ID_st {
246 ASN1_INTEGER *zone;
247 ASN1_OCTET_STRING *user;
248} SXNETID;
249
250DECLARE_STACK_OF(SXNETID)
251DECLARE_ASN1_SET_OF(SXNETID)
252
253typedef struct SXNET_st {
254 ASN1_INTEGER *version;
255 STACK_OF(SXNETID) *ids;
256} SXNET;
257
258typedef struct NOTICEREF_st {
259 ASN1_STRING *organization;
260 STACK_OF(ASN1_INTEGER) *noticenos;
261} NOTICEREF;
262
263typedef struct USERNOTICE_st {
264 NOTICEREF *noticeref;
265 ASN1_STRING *exptext;
266} USERNOTICE;
267
268typedef struct POLICYQUALINFO_st {
269 ASN1_OBJECT *pqualid;
270 union {
271 ASN1_IA5STRING *cpsuri;
272 USERNOTICE *usernotice;
273 ASN1_TYPE *other;
274 } d;
275} POLICYQUALINFO;
276
277DECLARE_STACK_OF(POLICYQUALINFO)
278DECLARE_ASN1_SET_OF(POLICYQUALINFO)
279
280typedef struct POLICYINFO_st {
281 ASN1_OBJECT *policyid;
282 STACK_OF(POLICYQUALINFO) *qualifiers;
283} POLICYINFO;
284
285typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES;
286
287DECLARE_STACK_OF(POLICYINFO)
288DECLARE_ASN1_SET_OF(POLICYINFO)
289
290/* Proxy certificate structures, see RFC 3820 */
291typedef struct PROXY_POLICY_st
292 {
293 ASN1_OBJECT *policyLanguage;
294 ASN1_OCTET_STRING *policy;
295 } PROXY_POLICY;
296
297typedef struct PROXY_CERT_INFO_EXTENSION_st
298 {
299 ASN1_INTEGER *pcPathLengthConstraint;
300 PROXY_POLICY *proxyPolicy;
301 } PROXY_CERT_INFO_EXTENSION;
302
303DECLARE_ASN1_FUNCTIONS(PROXY_POLICY)
304DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
305
306
307#define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \
308",name:", val->name, ",value:", val->value);
309
310#define X509V3_set_ctx_test(ctx) \
311 X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST)
312#define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL;
313
314#define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \
315 0,0,0,0, \
316 0,0, \
317 (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \
318 (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \
319 NULL, NULL, \
320 table}
321
322#define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \
323 0,0,0,0, \
324 (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \
325 (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \
326 0,0,0,0, \
327 NULL}
328
329#define EXT_END { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
330
331
332/* X509_PURPOSE stuff */
333
334#define EXFLAG_BCONS 0x1
335#define EXFLAG_KUSAGE 0x2
336#define EXFLAG_XKUSAGE 0x4
337#define EXFLAG_NSCERT 0x8
338
339#define EXFLAG_CA 0x10
340#define EXFLAG_SS 0x20
341#define EXFLAG_V1 0x40
342#define EXFLAG_INVALID 0x80
343#define EXFLAG_SET 0x100
344#define EXFLAG_CRITICAL 0x200
345#define EXFLAG_PROXY 0x400
346
347#define KU_DIGITAL_SIGNATURE 0x0080
348#define KU_NON_REPUDIATION 0x0040
349#define KU_KEY_ENCIPHERMENT 0x0020
350#define KU_DATA_ENCIPHERMENT 0x0010
351#define KU_KEY_AGREEMENT 0x0008
352#define KU_KEY_CERT_SIGN 0x0004
353#define KU_CRL_SIGN 0x0002
354#define KU_ENCIPHER_ONLY 0x0001
355#define KU_DECIPHER_ONLY 0x8000
356
357#define NS_SSL_CLIENT 0x80
358#define NS_SSL_SERVER 0x40
359#define NS_SMIME 0x20
360#define NS_OBJSIGN 0x10
361#define NS_SSL_CA 0x04
362#define NS_SMIME_CA 0x02
363#define NS_OBJSIGN_CA 0x01
364#define NS_ANY_CA (NS_SSL_CA|NS_SMIME_CA|NS_OBJSIGN_CA)
365
366#define XKU_SSL_SERVER 0x1
367#define XKU_SSL_CLIENT 0x2
368#define XKU_SMIME 0x4
369#define XKU_CODE_SIGN 0x8
370#define XKU_SGC 0x10
371#define XKU_OCSP_SIGN 0x20
372#define XKU_TIMESTAMP 0x40
373#define XKU_DVCS 0x80
374
375#define X509_PURPOSE_DYNAMIC 0x1
376#define X509_PURPOSE_DYNAMIC_NAME 0x2
377
378typedef struct x509_purpose_st {
379 int purpose;
380 int trust; /* Default trust ID */
381 int flags;
382 int (*check_purpose)(const struct x509_purpose_st *,
383 const X509 *, int);
384 char *name;
385 char *sname;
386 void *usr_data;
387} X509_PURPOSE;
388
389#define X509_PURPOSE_SSL_CLIENT 1
390#define X509_PURPOSE_SSL_SERVER 2
391#define X509_PURPOSE_NS_SSL_SERVER 3
392#define X509_PURPOSE_SMIME_SIGN 4
393#define X509_PURPOSE_SMIME_ENCRYPT 5
394#define X509_PURPOSE_CRL_SIGN 6
395#define X509_PURPOSE_ANY 7
396#define X509_PURPOSE_OCSP_HELPER 8
397
398#define X509_PURPOSE_MIN 1
399#define X509_PURPOSE_MAX 8
400
401/* Flags for X509V3_EXT_print() */
402
403#define X509V3_EXT_UNKNOWN_MASK (0xfL << 16)
404/* Return error for unknown extensions */
405#define X509V3_EXT_DEFAULT 0
406/* Print error for unknown extensions */
407#define X509V3_EXT_ERROR_UNKNOWN (1L << 16)
408/* ASN1 parse unknown extensions */
409#define X509V3_EXT_PARSE_UNKNOWN (2L << 16)
410/* BIO_dump unknown extensions */
411#define X509V3_EXT_DUMP_UNKNOWN (3L << 16)
412
413/* Flags for X509V3_add1_i2d */
414
415#define X509V3_ADD_OP_MASK 0xfL
416#define X509V3_ADD_DEFAULT 0L
417#define X509V3_ADD_APPEND 1L
418#define X509V3_ADD_REPLACE 2L
419#define X509V3_ADD_REPLACE_EXISTING 3L
420#define X509V3_ADD_KEEP_EXISTING 4L
421#define X509V3_ADD_DELETE 5L
422#define X509V3_ADD_SILENT 0x10
423
424DECLARE_STACK_OF(X509_PURPOSE)
425
426DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)
427
428DECLARE_ASN1_FUNCTIONS(SXNET)
429DECLARE_ASN1_FUNCTIONS(SXNETID)
430
431int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen);
432int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen);
433int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, char *user, int userlen);
434
435ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone);
436ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone);
437ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone);
438
439DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID)
440
441DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)
442
443DECLARE_ASN1_FUNCTIONS(GENERAL_NAME)
444
445STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret);
446int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen);
447
448DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES)
449
450STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
451 GENERAL_NAMES *gen, STACK_OF(CONF_VALUE) *extlist);
452GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
453 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
454
455DECLARE_ASN1_FUNCTIONS(OTHERNAME)
456DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME)
457
458char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
459ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
460
461DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
462int i2a_ACCESS_DESCRIPTION(BIO *bp, ACCESS_DESCRIPTION* a);
463
464DECLARE_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)
465DECLARE_ASN1_FUNCTIONS(POLICYINFO)
466DECLARE_ASN1_FUNCTIONS(POLICYQUALINFO)
467DECLARE_ASN1_FUNCTIONS(USERNOTICE)
468DECLARE_ASN1_FUNCTIONS(NOTICEREF)
469
470DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS)
471DECLARE_ASN1_FUNCTIONS(DIST_POINT)
472DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME)
473
474DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)
475DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)
476
477#ifdef HEADER_CONF_H
478GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf);
479void X509V3_conf_free(CONF_VALUE *val);
480
481X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, char *value);
482X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name, char *value);
483int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section, STACK_OF(X509_EXTENSION) **sk);
484int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509 *cert);
485int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);
486int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
487
488X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
489X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
490int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
491int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);
492int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
493
494int X509V3_add_value_bool_nf(char *name, int asn1_bool,
495 STACK_OF(CONF_VALUE) **extlist);
496int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
497int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
498void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf);
499void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
500#endif
501
502char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
503STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
504void X509V3_string_free(X509V3_CTX *ctx, char *str);
505void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
506void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
507 X509_REQ *req, X509_CRL *crl, int flags);
508
509int X509V3_add_value(const char *name, const char *value,
510 STACK_OF(CONF_VALUE) **extlist);
511int X509V3_add_value_uchar(const char *name, const unsigned char *value,
512 STACK_OF(CONF_VALUE) **extlist);
513int X509V3_add_value_bool(const char *name, int asn1_bool,
514 STACK_OF(CONF_VALUE) **extlist);
515int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
516 STACK_OF(CONF_VALUE) **extlist);
517char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
518ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
519char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
520char * i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
521int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
522int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist);
523int X509V3_EXT_add_alias(int nid_to, int nid_from);
524void X509V3_EXT_cleanup(void);
525
526X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
527X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
528int X509V3_add_standard_extensions(void);
529STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line);
530void *X509V3_EXT_d2i(X509_EXTENSION *ext);
531void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
532
533
534X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
535int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, int crit, unsigned long flags);
536
537char *hex_to_string(unsigned char *buffer, long len);
538unsigned char *string_to_hex(char *str, long *len);
539int name_cmp(const char *name, const char *cmp);
540
541void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,
542 int ml);
543int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent);
544int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
545
546int X509V3_extensions_print(BIO *out, char *title, STACK_OF(X509_EXTENSION) *exts, unsigned long flag, int indent);
547
548int X509_check_ca(X509 *x);
549int X509_check_purpose(X509 *x, int id, int ca);
550int X509_supported_extension(X509_EXTENSION *ex);
551int X509_PURPOSE_set(int *p, int purpose);
552int X509_check_issued(X509 *issuer, X509 *subject);
553int X509_PURPOSE_get_count(void);
554X509_PURPOSE * X509_PURPOSE_get0(int idx);
555int X509_PURPOSE_get_by_sname(char *sname);
556int X509_PURPOSE_get_by_id(int id);
557int X509_PURPOSE_add(int id, int trust, int flags,
558 int (*ck)(const X509_PURPOSE *, const X509 *, int),
559 char *name, char *sname, void *arg);
560char *X509_PURPOSE_get0_name(X509_PURPOSE *xp);
561char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp);
562int X509_PURPOSE_get_trust(X509_PURPOSE *xp);
563void X509_PURPOSE_cleanup(void);
564int X509_PURPOSE_get_id(X509_PURPOSE *);
565
566STACK *X509_get1_email(X509 *x);
567STACK *X509_REQ_get1_email(X509_REQ *x);
568void X509_email_free(STACK *sk);
569
570
571/* BEGIN ERROR CODES */
572/* The following lines are auto generated by the script mkerr.pl. Any changes
573 * made after this point may be overwritten when the script is next run.
574 */
575void ERR_load_X509V3_strings(void);
576
577/* Error codes for the X509V3 functions. */
578
579/* Function codes. */
580#define X509V3_F_COPY_EMAIL 122
581#define X509V3_F_COPY_ISSUER 123
582#define X509V3_F_DO_EXT_CONF 124
583#define X509V3_F_DO_EXT_I2D 135
584#define X509V3_F_HEX_TO_STRING 111
585#define X509V3_F_I2S_ASN1_ENUMERATED 121
586#define X509V3_F_I2S_ASN1_IA5STRING 142
587#define X509V3_F_I2S_ASN1_INTEGER 120
588#define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138
589#define X509V3_F_NOTICE_SECTION 132
590#define X509V3_F_NREF_NOS 133
591#define X509V3_F_POLICY_SECTION 131
592#define X509V3_F_R2I_CERTPOL 130
593#define X509V3_F_R2I_PCI 142
594#define X509V3_F_S2I_ASN1_IA5STRING 100
595#define X509V3_F_S2I_ASN1_INTEGER 108
596#define X509V3_F_S2I_ASN1_OCTET_STRING 112
597#define X509V3_F_S2I_ASN1_SKEY_ID 114
598#define X509V3_F_S2I_S2I_SKEY_ID 115
599#define X509V3_F_STRING_TO_HEX 113
600#define X509V3_F_SXNET_ADD_ASC 125
601#define X509V3_F_SXNET_ADD_ID_INTEGER 126
602#define X509V3_F_SXNET_ADD_ID_ULONG 127
603#define X509V3_F_SXNET_GET_ID_ASC 128
604#define X509V3_F_SXNET_GET_ID_ULONG 129
605#define X509V3_F_V2I_ACCESS_DESCRIPTION 139
606#define X509V3_F_V2I_ASN1_BIT_STRING 101
607#define X509V3_F_V2I_AUTHORITY_KEYID 119
608#define X509V3_F_V2I_BASIC_CONSTRAINTS 102
609#define X509V3_F_V2I_CRLD 134
610#define X509V3_F_V2I_EXT_KU 103
611#define X509V3_F_V2I_GENERAL_NAME 117
612#define X509V3_F_V2I_GENERAL_NAMES 118
613#define X509V3_F_V3_GENERIC_EXTENSION 116
614#define X509V3_F_X509V3_ADD_I2D 140
615#define X509V3_F_X509V3_ADD_VALUE 105
616#define X509V3_F_X509V3_EXT_ADD 104
617#define X509V3_F_X509V3_EXT_ADD_ALIAS 106
618#define X509V3_F_X509V3_EXT_CONF 107
619#define X509V3_F_X509V3_EXT_I2D 136
620#define X509V3_F_X509V3_GET_VALUE_BOOL 110
621#define X509V3_F_X509V3_PARSE_LIST 109
622#define X509V3_F_X509_PURPOSE_ADD 137
623#define X509V3_F_X509_PURPOSE_SET 141
624
625/* Reason codes. */
626#define X509V3_R_BAD_IP_ADDRESS 118
627#define X509V3_R_BAD_OBJECT 119
628#define X509V3_R_BN_DEC2BN_ERROR 100
629#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101
630#define X509V3_R_DUPLICATE_ZONE_ID 133
631#define X509V3_R_ERROR_CONVERTING_ZONE 131
632#define X509V3_R_ERROR_CREATING_EXTENSION 144
633#define X509V3_R_ERROR_IN_EXTENSION 128
634#define X509V3_R_EXPECTED_A_SECTION_NAME 137
635#define X509V3_R_EXTENSION_EXISTS 145
636#define X509V3_R_EXTENSION_NAME_ERROR 115
637#define X509V3_R_EXTENSION_NOT_FOUND 102
638#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103
639#define X509V3_R_EXTENSION_VALUE_ERROR 116
640#define X509V3_R_ILLEGAL_HEX_DIGIT 113
641#define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG 153
642#define X509V3_R_INVALID_BOOLEAN_STRING 104
643#define X509V3_R_INVALID_EXTENSION_STRING 105
644#define X509V3_R_INVALID_NAME 106
645#define X509V3_R_INVALID_NULL_ARGUMENT 107
646#define X509V3_R_INVALID_NULL_NAME 108
647#define X509V3_R_INVALID_NULL_VALUE 109
648#define X509V3_R_INVALID_NUMBER 140
649#define X509V3_R_INVALID_NUMBERS 141
650#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110
651#define X509V3_R_INVALID_OPTION 138
652#define X509V3_R_INVALID_POLICY_IDENTIFIER 134
653#define X509V3_R_INVALID_PROXY_POLICY_IDENTIFIER 147
654#define X509V3_R_INVALID_PROXY_POLICY_SETTING 151
655#define X509V3_R_INVALID_PURPOSE 146
656#define X509V3_R_INVALID_SECTION 135
657#define X509V3_R_INVALID_SYNTAX 143
658#define X509V3_R_ISSUER_DECODE_ERROR 126
659#define X509V3_R_MISSING_VALUE 124
660#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142
661#define X509V3_R_NO_CONFIG_DATABASE 136
662#define X509V3_R_NO_ISSUER_CERTIFICATE 121
663#define X509V3_R_NO_ISSUER_DETAILS 127
664#define X509V3_R_NO_POLICY_IDENTIFIER 139
665#define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED 148
666#define X509V3_R_NO_PUBLIC_KEY 114
667#define X509V3_R_NO_SUBJECT_DETAILS 125
668#define X509V3_R_ODD_NUMBER_OF_DIGITS 112
669#define X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED 149
670#define X509V3_R_POLICY_PATH_LENGTH 152
671#define X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED 150
672#define X509V3_R_POLICY_SYNTAX_NOT 154
673#define X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED 155
674#define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 156
675#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122
676#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123
677#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111
678#define X509V3_R_UNKNOWN_EXTENSION 129
679#define X509V3_R_UNKNOWN_EXTENSION_NAME 130
680#define X509V3_R_UNKNOWN_OPTION 120
681#define X509V3_R_UNSUPPORTED_OPTION 117
682#define X509V3_R_USER_TOO_LONG 132
683
684#ifdef __cplusplus
685}
686#endif
687#endif
diff --git a/src/lib/libssl/LICENSE b/src/lib/libssl/LICENSE
deleted file mode 100644
index e6afecc724..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-2005 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 d683ee43e1..0000000000
--- a/src/lib/libssl/bio_ssl.c
+++ /dev/null
@@ -1,598 +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, const char *buf, int num);
69static int ssl_read(BIO *h, char *buf, int size);
70static int ssl_puts(BIO *h, const char *str);
71static long ssl_ctrl(BIO *h, int cmd, long arg1, void *arg2);
72static int ssl_new(BIO *h);
73static int ssl_free(BIO *data);
74static long ssl_callback_ctrl(BIO *h, int cmd, bio_info_cb *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 *)OPENSSL_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 OPENSSL_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_ACCEPT:
210 BIO_set_retry_special(b);
211 retry_reason=BIO_RR_ACCEPT;
212 break;
213 case SSL_ERROR_WANT_CONNECT:
214 BIO_set_retry_special(b);
215 retry_reason=BIO_RR_CONNECT;
216 break;
217 case SSL_ERROR_SYSCALL:
218 case SSL_ERROR_SSL:
219 case SSL_ERROR_ZERO_RETURN:
220 default:
221 break;
222 }
223
224 b->retry_reason=retry_reason;
225 return(ret);
226 }
227
228static int ssl_write(BIO *b, const char *out, int outl)
229 {
230 int ret,r=0;
231 int retry_reason=0;
232 SSL *ssl;
233 BIO_SSL *bs;
234
235 if (out == NULL) return(0);
236 bs=(BIO_SSL *)b->ptr;
237 ssl=bs->ssl;
238
239 BIO_clear_retry_flags(b);
240
241/* ret=SSL_do_handshake(ssl);
242 if (ret > 0) */
243 ret=SSL_write(ssl,out,outl);
244
245 switch (SSL_get_error(ssl,ret))
246 {
247 case SSL_ERROR_NONE:
248 if (ret <= 0) break;
249 if (bs->renegotiate_count > 0)
250 {
251 bs->byte_count+=ret;
252 if (bs->byte_count > bs->renegotiate_count)
253 {
254 bs->byte_count=0;
255 bs->num_renegotiates++;
256 SSL_renegotiate(ssl);
257 r=1;
258 }
259 }
260 if ((bs->renegotiate_timeout > 0) && (!r))
261 {
262 unsigned long tm;
263
264 tm=(unsigned long)time(NULL);
265 if (tm > bs->last_time+bs->renegotiate_timeout)
266 {
267 bs->last_time=tm;
268 bs->num_renegotiates++;
269 SSL_renegotiate(ssl);
270 }
271 }
272 break;
273 case SSL_ERROR_WANT_WRITE:
274 BIO_set_retry_write(b);
275 break;
276 case SSL_ERROR_WANT_READ:
277 BIO_set_retry_read(b);
278 break;
279 case SSL_ERROR_WANT_X509_LOOKUP:
280 BIO_set_retry_special(b);
281 retry_reason=BIO_RR_SSL_X509_LOOKUP;
282 break;
283 case SSL_ERROR_WANT_CONNECT:
284 BIO_set_retry_special(b);
285 retry_reason=BIO_RR_CONNECT;
286 case SSL_ERROR_SYSCALL:
287 case SSL_ERROR_SSL:
288 default:
289 break;
290 }
291
292 b->retry_reason=retry_reason;
293 return(ret);
294 }
295
296static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
297 {
298 SSL **sslp,*ssl;
299 BIO_SSL *bs;
300 BIO *dbio,*bio;
301 long ret=1;
302
303 bs=(BIO_SSL *)b->ptr;
304 ssl=bs->ssl;
305 if ((ssl == NULL) && (cmd != BIO_C_SET_SSL))
306 return(0);
307 switch (cmd)
308 {
309 case BIO_CTRL_RESET:
310 SSL_shutdown(ssl);
311
312 if (ssl->handshake_func == ssl->method->ssl_connect)
313 SSL_set_connect_state(ssl);
314 else if (ssl->handshake_func == ssl->method->ssl_accept)
315 SSL_set_accept_state(ssl);
316
317 SSL_clear(ssl);
318
319 if (b->next_bio != NULL)
320 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
321 else if (ssl->rbio != NULL)
322 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
323 else
324 ret=1;
325 break;
326 case BIO_CTRL_INFO:
327 ret=0;
328 break;
329 case BIO_C_SSL_MODE:
330 if (num) /* client mode */
331 SSL_set_connect_state(ssl);
332 else
333 SSL_set_accept_state(ssl);
334 break;
335 case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT:
336 ret=bs->renegotiate_timeout;
337 if (num < 60) num=5;
338 bs->renegotiate_timeout=(unsigned long)num;
339 bs->last_time=(unsigned long)time(NULL);
340 break;
341 case BIO_C_SET_SSL_RENEGOTIATE_BYTES:
342 ret=bs->renegotiate_count;
343 if ((long)num >=512)
344 bs->renegotiate_count=(unsigned long)num;
345 break;
346 case BIO_C_GET_SSL_NUM_RENEGOTIATES:
347 ret=bs->num_renegotiates;
348 break;
349 case BIO_C_SET_SSL:
350 if (ssl != NULL)
351 ssl_free(b);
352 b->shutdown=(int)num;
353 ssl=(SSL *)ptr;
354 ((BIO_SSL *)b->ptr)->ssl=ssl;
355 bio=SSL_get_rbio(ssl);
356 if (bio != NULL)
357 {
358 if (b->next_bio != NULL)
359 BIO_push(bio,b->next_bio);
360 b->next_bio=bio;
361 CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO);
362 }
363 b->init=1;
364 break;
365 case BIO_C_GET_SSL:
366 if (ptr != NULL)
367 {
368 sslp=(SSL **)ptr;
369 *sslp=ssl;
370 }
371 else
372 ret=0;
373 break;
374 case BIO_CTRL_GET_CLOSE:
375 ret=b->shutdown;
376 break;
377 case BIO_CTRL_SET_CLOSE:
378 b->shutdown=(int)num;
379 break;
380 case BIO_CTRL_WPENDING:
381 ret=BIO_ctrl(ssl->wbio,cmd,num,ptr);
382 break;
383 case BIO_CTRL_PENDING:
384 ret=SSL_pending(ssl);
385 if (ret == 0)
386 ret=BIO_pending(ssl->rbio);
387 break;
388 case BIO_CTRL_FLUSH:
389 BIO_clear_retry_flags(b);
390 ret=BIO_ctrl(ssl->wbio,cmd,num,ptr);
391 BIO_copy_next_retry(b);
392 break;
393 case BIO_CTRL_PUSH:
394 if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio))
395 {
396 SSL_set_bio(ssl,b->next_bio,b->next_bio);
397 CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);
398 }
399 break;
400 case BIO_CTRL_POP:
401 /* ugly bit of a hack */
402 if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */
403 {
404 BIO_free_all(ssl->wbio);
405 }
406 if (b->next_bio != NULL)
407 {
408 CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);
409 }
410 ssl->wbio=NULL;
411 ssl->rbio=NULL;
412 break;
413 case BIO_C_DO_STATE_MACHINE:
414 BIO_clear_retry_flags(b);
415
416 b->retry_reason=0;
417 ret=(int)SSL_do_handshake(ssl);
418
419 switch (SSL_get_error(ssl,(int)ret))
420 {
421 case SSL_ERROR_WANT_READ:
422 BIO_set_flags(b,
423 BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);
424 break;
425 case SSL_ERROR_WANT_WRITE:
426 BIO_set_flags(b,
427 BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY);
428 break;
429 case SSL_ERROR_WANT_CONNECT:
430 BIO_set_flags(b,
431 BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY);
432 b->retry_reason=b->next_bio->retry_reason;
433 break;
434 default:
435 break;
436 }
437 break;
438 case BIO_CTRL_DUP:
439 dbio=(BIO *)ptr;
440 if (((BIO_SSL *)dbio->ptr)->ssl != NULL)
441 SSL_free(((BIO_SSL *)dbio->ptr)->ssl);
442 ((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl);
443 ((BIO_SSL *)dbio->ptr)->renegotiate_count=
444 ((BIO_SSL *)b->ptr)->renegotiate_count;
445 ((BIO_SSL *)dbio->ptr)->byte_count=
446 ((BIO_SSL *)b->ptr)->byte_count;
447 ((BIO_SSL *)dbio->ptr)->renegotiate_timeout=
448 ((BIO_SSL *)b->ptr)->renegotiate_timeout;
449 ((BIO_SSL *)dbio->ptr)->last_time=
450 ((BIO_SSL *)b->ptr)->last_time;
451 ret=(((BIO_SSL *)dbio->ptr)->ssl != NULL);
452 break;
453 case BIO_C_GET_FD:
454 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
455 break;
456 case BIO_CTRL_SET_CALLBACK:
457 {
458#if 0 /* FIXME: Should this be used? -- Richard Levitte */
459 BIOerr(SSL_F_SSL_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
460 ret = -1;
461#else
462 ret=0;
463#endif
464 }
465 break;
466 case BIO_CTRL_GET_CALLBACK:
467 {
468 void (**fptr)();
469
470 fptr=(void (**)())ptr;
471 *fptr=SSL_get_info_callback(ssl);
472 }
473 break;
474 default:
475 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
476 break;
477 }
478 return(ret);
479 }
480
481static long ssl_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
482 {
483 SSL *ssl;
484 BIO_SSL *bs;
485 long ret=1;
486
487 bs=(BIO_SSL *)b->ptr;
488 ssl=bs->ssl;
489 switch (cmd)
490 {
491 case BIO_CTRL_SET_CALLBACK:
492 {
493 /* FIXME: setting this via a completely different prototype
494 seems like a crap idea */
495 SSL_set_info_callback(ssl,(void (*)(const SSL *,int,int))fp);
496 }
497 break;
498 default:
499 ret=BIO_callback_ctrl(ssl->rbio,cmd,fp);
500 break;
501 }
502 return(ret);
503 }
504
505static int ssl_puts(BIO *bp, const char *str)
506 {
507 int n,ret;
508
509 n=strlen(str);
510 ret=BIO_write(bp,str,n);
511 return(ret);
512 }
513
514BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx)
515 {
516#ifndef OPENSSL_NO_SOCK
517 BIO *ret=NULL,*buf=NULL,*ssl=NULL;
518
519 if ((buf=BIO_new(BIO_f_buffer())) == NULL)
520 return(NULL);
521 if ((ssl=BIO_new_ssl_connect(ctx)) == NULL)
522 goto err;
523 if ((ret=BIO_push(buf,ssl)) == NULL)
524 goto err;
525 return(ret);
526err:
527 if (buf != NULL) BIO_free(buf);
528 if (ssl != NULL) BIO_free(ssl);
529#endif
530 return(NULL);
531 }
532
533BIO *BIO_new_ssl_connect(SSL_CTX *ctx)
534 {
535 BIO *ret=NULL,*con=NULL,*ssl=NULL;
536
537 if ((con=BIO_new(BIO_s_connect())) == NULL)
538 return(NULL);
539 if ((ssl=BIO_new_ssl(ctx,1)) == NULL)
540 goto err;
541 if ((ret=BIO_push(ssl,con)) == NULL)
542 goto err;
543 return(ret);
544err:
545 if (con != NULL) BIO_free(con);
546 if (ret != NULL) BIO_free(ret);
547 return(NULL);
548 }
549
550BIO *BIO_new_ssl(SSL_CTX *ctx, int client)
551 {
552 BIO *ret;
553 SSL *ssl;
554
555 if ((ret=BIO_new(BIO_f_ssl())) == NULL)
556 return(NULL);
557 if ((ssl=SSL_new(ctx)) == NULL)
558 {
559 BIO_free(ret);
560 return(NULL);
561 }
562 if (client)
563 SSL_set_connect_state(ssl);
564 else
565 SSL_set_accept_state(ssl);
566
567 BIO_set_ssl(ret,ssl,BIO_CLOSE);
568 return(ret);
569 }
570
571int BIO_ssl_copy_session_id(BIO *t, BIO *f)
572 {
573 t=BIO_find_type(t,BIO_TYPE_SSL);
574 f=BIO_find_type(f,BIO_TYPE_SSL);
575 if ((t == NULL) || (f == NULL))
576 return(0);
577 if ( (((BIO_SSL *)t->ptr)->ssl == NULL) ||
578 (((BIO_SSL *)f->ptr)->ssl == NULL))
579 return(0);
580 SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl,((BIO_SSL *)f->ptr)->ssl);
581 return(1);
582 }
583
584void BIO_ssl_shutdown(BIO *b)
585 {
586 SSL *s;
587
588 while (b != NULL)
589 {
590 if (b->method->type == BIO_TYPE_SSL)
591 {
592 s=((BIO_SSL *)b->ptr)->ssl;
593 SSL_shutdown(s);
594 break;
595 }
596 b=b->next_bio;
597 }
598 }
diff --git a/src/lib/libssl/doc/openssl.cnf b/src/lib/libssl/doc/openssl.cnf
deleted file mode 100644
index 4c1d595b0a..0000000000
--- a/src/lib/libssl/doc/openssl.cnf
+++ /dev/null
@@ -1,313 +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.
41#unique_subject = no # Set to 'no' to allow creation of
42 # several ctificates with same subject.
43new_certs_dir = $dir/newcerts # default place for new certs.
44
45certificate = $dir/cacert.pem # The CA certificate
46serial = $dir/serial # The current serial number
47#crlnumber = $dir/crlnumber # the current crl number must be
48 # commented out to leave a V1 CRL
49crl = $dir/crl.pem # The current CRL
50private_key = $dir/private/cakey.pem# The private key
51RANDFILE = $dir/private/.rand # private random number file
52
53x509_extensions = usr_cert # The extentions to add to the cert
54
55# Comment out the following two lines for the "traditional"
56# (and highly broken) format.
57name_opt = ca_default # Subject Name options
58cert_opt = ca_default # Certificate field options
59
60# Extension copying option: use with caution.
61# copy_extensions = copy
62
63# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
64# so this is commented out by default to leave a V1 CRL.
65# crlnumber must also be commented out to leave a V1 CRL.
66# crl_extensions = crl_ext
67
68default_days = 365 # how long to certify for
69default_crl_days= 30 # how long before next CRL
70default_md = md5 # which md to use.
71preserve = no # keep passed DN ordering
72
73# A few difference way of specifying how similar the request should look
74# For type CA, the listed attributes must be the same, and the optional
75# and supplied fields are just that :-)
76policy = policy_match
77
78# For the CA policy
79[ policy_match ]
80countryName = match
81stateOrProvinceName = match
82organizationName = match
83organizationalUnitName = optional
84commonName = supplied
85emailAddress = optional
86
87# For the 'anything' policy
88# At this point in time, you must list all acceptable 'object'
89# types.
90[ policy_anything ]
91countryName = optional
92stateOrProvinceName = optional
93localityName = optional
94organizationName = optional
95organizationalUnitName = optional
96commonName = supplied
97emailAddress = optional
98
99####################################################################
100[ req ]
101default_bits = 1024
102default_keyfile = privkey.pem
103distinguished_name = req_distinguished_name
104attributes = req_attributes
105x509_extensions = v3_ca # The extentions to add to the self signed cert
106
107# Passwords for private keys if not present they will be prompted for
108# input_password = secret
109# output_password = secret
110
111# This sets a mask for permitted string types. There are several options.
112# default: PrintableString, T61String, BMPString.
113# pkix : PrintableString, BMPString.
114# utf8only: only UTF8Strings.
115# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
116# MASK:XXXX a literal mask value.
117# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings
118# so use this option with caution!
119string_mask = nombstr
120
121# req_extensions = v3_req # The extensions to add to a certificate request
122
123[ req_distinguished_name ]
124countryName = Country Name (2 letter code)
125countryName_default = AU
126countryName_min = 2
127countryName_max = 2
128
129stateOrProvinceName = State or Province Name (full name)
130stateOrProvinceName_default = Some-State
131
132localityName = Locality Name (eg, city)
133
1340.organizationName = Organization Name (eg, company)
1350.organizationName_default = Internet Widgits Pty Ltd
136
137# we can do this but it is not needed normally :-)
138#1.organizationName = Second Organization Name (eg, company)
139#1.organizationName_default = World Wide Web Pty Ltd
140
141organizationalUnitName = Organizational Unit Name (eg, section)
142#organizationalUnitName_default =
143
144commonName = Common Name (eg, YOUR name)
145commonName_max = 64
146
147emailAddress = Email Address
148emailAddress_max = 64
149
150# SET-ex3 = SET extension number 3
151
152[ req_attributes ]
153challengePassword = A challenge password
154challengePassword_min = 4
155challengePassword_max = 20
156
157unstructuredName = An optional company name
158
159[ usr_cert ]
160
161# These extensions are added when 'ca' signs a request.
162
163# This goes against PKIX guidelines but some CAs do it and some software
164# requires this to avoid interpreting an end user certificate as a CA.
165
166basicConstraints=CA:FALSE
167
168# Here are some examples of the usage of nsCertType. If it is omitted
169# the certificate can be used for anything *except* object signing.
170
171# This is OK for an SSL server.
172# nsCertType = server
173
174# For an object signing certificate this would be used.
175# nsCertType = objsign
176
177# For normal client use this is typical
178# nsCertType = client, email
179
180# and for everything including object signing:
181# nsCertType = client, email, objsign
182
183# This is typical in keyUsage for a client certificate.
184# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
185
186# This will be displayed in Netscape's comment listbox.
187nsComment = "OpenSSL Generated Certificate"
188
189# PKIX recommendations harmless if included in all certificates.
190subjectKeyIdentifier=hash
191authorityKeyIdentifier=keyid,issuer:always
192
193# This stuff is for subjectAltName and issuerAltname.
194# Import the email address.
195# subjectAltName=email:copy
196# An alternative to produce certificates that aren't
197# deprecated according to PKIX.
198# subjectAltName=email:move
199
200# Copy subject details
201# issuerAltName=issuer:copy
202
203#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
204#nsBaseUrl
205#nsRevocationUrl
206#nsRenewalUrl
207#nsCaPolicyUrl
208#nsSslServerName
209
210[ v3_req ]
211
212# Extensions to add to a certificate request
213
214basicConstraints = CA:FALSE
215keyUsage = nonRepudiation, digitalSignature, keyEncipherment
216
217[ v3_ca ]
218
219
220# Extensions for a typical CA
221
222
223# PKIX recommendation.
224
225subjectKeyIdentifier=hash
226
227authorityKeyIdentifier=keyid:always,issuer:always
228
229# This is what PKIX recommends but some broken software chokes on critical
230# extensions.
231#basicConstraints = critical,CA:true
232# So we do this instead.
233basicConstraints = CA:true
234
235# Key usage: this is typical for a CA certificate. However since it will
236# prevent it being used as an test self-signed certificate it is best
237# left out by default.
238# keyUsage = cRLSign, keyCertSign
239
240# Some might want this also
241# nsCertType = sslCA, emailCA
242
243# Include email address in subject alt name: another PKIX recommendation
244# subjectAltName=email:copy
245# Copy issuer details
246# issuerAltName=issuer:copy
247
248# DER hex encoding of an extension: beware experts only!
249# obj=DER:02:03
250# Where 'obj' is a standard or added object
251# You can even override a supported extension:
252# basicConstraints= critical, DER:30:03:01:01:FF
253
254[ crl_ext ]
255
256# CRL extensions.
257# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
258
259# issuerAltName=issuer:copy
260authorityKeyIdentifier=keyid:always,issuer:always
261
262[ proxy_cert_ext ]
263# These extensions should be added when creating a proxy certificate
264
265# This goes against PKIX guidelines but some CAs do it and some software
266# requires this to avoid interpreting an end user certificate as a CA.
267
268basicConstraints=CA:FALSE
269
270# Here are some examples of the usage of nsCertType. If it is omitted
271# the certificate can be used for anything *except* object signing.
272
273# This is OK for an SSL server.
274# nsCertType = server
275
276# For an object signing certificate this would be used.
277# nsCertType = objsign
278
279# For normal client use this is typical
280# nsCertType = client, email
281
282# and for everything including object signing:
283# nsCertType = client, email, objsign
284
285# This is typical in keyUsage for a client certificate.
286# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
287
288# This will be displayed in Netscape's comment listbox.
289nsComment = "OpenSSL Generated Certificate"
290
291# PKIX recommendations harmless if included in all certificates.
292subjectKeyIdentifier=hash
293authorityKeyIdentifier=keyid,issuer:always
294
295# This stuff is for subjectAltName and issuerAltname.
296# Import the email address.
297# subjectAltName=email:copy
298# An alternative to produce certificates that aren't
299# deprecated according to PKIX.
300# subjectAltName=email:move
301
302# Copy subject details
303# issuerAltName=issuer:copy
304
305#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
306#nsBaseUrl
307#nsRevocationUrl
308#nsRenewalUrl
309#nsCaPolicyUrl
310#nsSslServerName
311
312# This really needs to be in place for it to be a proxy certificate.
313proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo
diff --git a/src/lib/libssl/doc/openssl.txt b/src/lib/libssl/doc/openssl.txt
deleted file mode 100644
index 432a17b66c..0000000000
--- a/src/lib/libssl/doc/openssl.txt
+++ /dev/null
@@ -1,1235 +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,URI: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
358Example:
359
360issuserAltName = issuer:copy
361
362Authority Info Access.
363
364The authority information access extension gives details about how to access
365certain information relating to the CA. Its syntax is accessOID;location
366where 'location' has the same syntax as subject alternative name (except
367that email:copy is not supported). accessOID can be any valid OID but only
368certain values are meaningful for example OCSP and caIssuers. OCSP gives the
369location of an OCSP responder: this is used by Netscape PSM and other software.
370
371Example:
372
373authorityInfoAccess = OCSP;URI:http://ocsp.my.host/
374authorityInfoAccess = caIssuers;URI:http://my.ca/ca.html
375
376CRL distribution points.
377
378This is a multi-valued extension that supports all the literal options of
379subject alternative name. Of the few software packages that currently interpret
380this extension most only interpret the URI option.
381
382Currently each option will set a new DistributionPoint with the fullName
383field set to the given value.
384
385Other fields like cRLissuer and reasons cannot currently be set or displayed:
386at this time no examples were available that used these fields.
387
388If you see this extension with <UNSUPPORTED> when you attempt to print it out
389or it doesn't appear to display correctly then let me know, including the
390certificate (mail me at steve@openssl.org) .
391
392Examples:
393
394crlDistributionPoints=URI:http://www.myhost.com/myca.crl
395crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
396
397Certificate Policies.
398
399This is a RAW extension. It attempts to display the contents of this extension:
400unfortunately this extension is often improperly encoded.
401
402The certificate policies extension will rarely be used in practice: few
403software packages interpret it correctly or at all. IE5 does partially
404support this extension: but it needs the 'ia5org' option because it will
405only correctly support a broken encoding. Of the options below only the
406policy OID, explicitText and CPS options are displayed with IE5.
407
408All the fields of this extension can be set by using the appropriate syntax.
409
410If you follow the PKIX recommendations of not including any qualifiers and just
411using only one OID then you just include the value of that OID. Multiple OIDs
412can be set separated by commas, for example:
413
414certificatePolicies= 1.2.4.5, 1.1.3.4
415
416If you wish to include qualifiers then the policy OID and qualifiers need to
417be specified in a separate section: this is done by using the @section syntax
418instead of a literal OID value.
419
420The section referred to must include the policy OID using the name
421policyIdentifier, cPSuri qualifiers can be included using the syntax:
422
423CPS.nnn=value
424
425userNotice qualifiers can be set using the syntax:
426
427userNotice.nnn=@notice
428
429The value of the userNotice qualifier is specified in the relevant section.
430This section can include explicitText, organization and noticeNumbers
431options. explicitText and organization are text strings, noticeNumbers is a
432comma separated list of numbers. The organization and noticeNumbers options
433(if included) must BOTH be present. If you use the userNotice option with IE5
434then you need the 'ia5org' option at the top level to modify the encoding:
435otherwise it will not be interpreted properly.
436
437Example:
438
439certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
440
441[polsect]
442
443policyIdentifier = 1.3.5.8
444CPS.1="http://my.host.name/"
445CPS.2="http://my.your.name/"
446userNotice.1=@notice
447
448[notice]
449
450explicitText="Explicit Text Here"
451organization="Organisation Name"
452noticeNumbers=1,2,3,4
453
454TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
455according to PKIX it should be of type DisplayText but Verisign uses an
456IA5STRING and IE5 needs this too.
457
458Display only extensions.
459
460Some extensions are only partially supported and currently are only displayed
461but cannot be set. These include private key usage period, CRL number, and
462CRL reason.
463
464==============================================================================
465 X509V3 Extension code: programmers guide
466==============================================================================
467
468The purpose of the extension code is twofold. It allows an extension to be
469created from a string or structure describing its contents and it prints out an
470extension in a human or machine readable form.
471
4721. Initialisation and cleanup.
473
474No special initialisation is needed before calling the extension functions.
475You used to have to call X509V3_add_standard_extensions(); but this is no longer
476required and this function no longer does anything.
477
478void X509V3_EXT_cleanup(void);
479
480This function should be called to cleanup the extension code if any custom
481extensions have been added. If no custom extensions have been added then this
482call does nothing. After this call all custom extension code is freed up but
483you can still use the standard extensions.
484
4852. Printing and parsing extensions.
486
487The simplest way to print out extensions is via the standard X509 printing
488routines: if you use the standard X509_print() function, the supported
489extensions will be printed out automatically.
490
491The following functions allow finer control over extension display:
492
493int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
494int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
495
496These two functions print out an individual extension to a BIO or FILE pointer.
497Currently the flag argument is unused and should be set to 0. The 'indent'
498argument is the number of spaces to indent each line.
499
500void *X509V3_EXT_d2i(X509_EXTENSION *ext);
501
502This function parses an extension and returns its internal structure. The
503precise structure you get back depends on the extension being parsed. If the
504extension if basicConstraints you will get back a pointer to a
505BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
506details about the structures returned. The returned structure should be freed
507after use using the relevant free function, BASIC_CONSTRAINTS_free() for
508example.
509
510void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
511void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
512void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
513void * X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
514
515These functions combine the operations of searching for extensions and
516parsing them. They search a certificate, a CRL a CRL entry or a stack
517of extensions respectively for extension whose NID is 'nid' and return
518the parsed result of NULL if an error occurred. For example:
519
520BASIC_CONSTRAINTS *bs;
521bs = X509_get_ext_d2i(cert, NID_basic_constraints, NULL, NULL);
522
523This will search for the basicConstraints extension and either return
524it value or NULL. NULL can mean either the extension was not found, it
525occurred more than once or it could not be parsed.
526
527If 'idx' is NULL then an extension is only parsed if it occurs precisely
528once. This is standard behaviour because extensions normally cannot occur
529more than once. If however more than one extension of the same type can
530occur it can be used to parse successive extensions for example:
531
532int i;
533void *ext;
534
535i = -1;
536for(;;) {
537 ext = X509_get_ext_d2i(x, nid, crit, &idx);
538 if(ext == NULL) break;
539 /* Do something with ext */
540}
541
542If 'crit' is not NULL and the extension was found then the int it points to
543is set to 1 for critical extensions and 0 for non critical. Therefore if the
544function returns NULL but 'crit' is set to 0 or 1 then the extension was
545found but it could not be parsed.
546
547The int pointed to by crit will be set to -1 if the extension was not found
548and -2 if the extension occurred more than once (this will only happen if
549idx is NULL). In both cases the function will return NULL.
550
5513. Generating extensions.
552
553An extension will typically be generated from a configuration file, or some
554other kind of configuration database.
555
556int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
557 X509 *cert);
558int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
559 X509_CRL *crl);
560
561These functions add all the extensions in the given section to the given
562certificate or CRL. They will normally be called just before the certificate
563or CRL is due to be signed. Both return 0 on error on non zero for success.
564
565In each case 'conf' is the LHASH pointer of the configuration file to use
566and 'section' is the section containing the extension details.
567
568See the 'context functions' section for a description of the ctx parameter.
569
570
571X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
572 char *value);
573
574This function returns an extension based on a name and value pair, if the
575pair will not need to access other sections in a config file (or there is no
576config file) then the 'conf' parameter can be set to NULL.
577
578X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
579 char *value);
580
581This function creates an extension in the same way as X509V3_EXT_conf() but
582takes the NID of the extension rather than its name.
583
584For example to produce basicConstraints with the CA flag and a path length of
58510:
586
587x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10");
588
589
590X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
591
592This function sets up an extension from its internal structure. The ext_nid
593parameter is the NID of the extension and 'crit' is the critical flag.
594
5954. Context functions.
596
597The following functions set and manipulate an extension context structure.
598The purpose of the extension context is to allow the extension code to
599access various structures relating to the "environment" of the certificate:
600for example the issuers certificate or the certificate request.
601
602void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
603 X509_REQ *req, X509_CRL *crl, int flags);
604
605This function sets up an X509V3_CTX structure with details of the certificate
606environment: specifically the issuers certificate, the subject certificate,
607the certificate request and the CRL: if these are not relevant or not
608available then they can be set to NULL. The 'flags' parameter should be set
609to zero.
610
611X509V3_set_ctx_test(ctx)
612
613This macro is used to set the 'ctx' structure to a 'test' value: this is to
614allow the syntax of an extension (or configuration file) to be tested.
615
616X509V3_set_ctx_nodb(ctx)
617
618This macro is used when no configuration database is present.
619
620void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
621
622This function is used to set the configuration database when it is an LHASH
623structure: typically a configuration file.
624
625The following functions are used to access a configuration database: they
626should only be used in RAW extensions.
627
628char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
629
630This function returns the value of the parameter "name" in "section", or NULL
631if there has been an error.
632
633void X509V3_string_free(X509V3_CTX *ctx, char *str);
634
635This function frees up the string returned by the above function.
636
637STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
638
639This function returns a whole section as a STACK_OF(CONF_VALUE) .
640
641void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
642
643This function frees up the STACK returned by the above function.
644
645Note: it is possible to use the extension code with a custom configuration
646database. To do this the "db_meth" element of the X509V3_CTX structure should
647be set to an X509V3_CTX_METHOD structure. This structure contains the following
648function pointers:
649
650char * (*get_string)(void *db, char *section, char *value);
651STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
652void (*free_string)(void *db, char * string);
653void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
654
655these will be called and passed the 'db' element in the X509V3_CTX structure
656to access the database. If a given function is not implemented or not required
657it can be set to NULL.
658
6595. String helper functions.
660
661There are several "i2s" and "s2i" functions that convert structures to and
662from ASCII strings. In all the "i2s" cases the returned string should be
663freed using Free() after use. Since some of these are part of other extension
664code they may take a 'method' parameter. Unless otherwise stated it can be
665safely set to NULL.
666
667char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
668
669This returns a hex string from an ASN1_OCTET_STRING.
670
671char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
672char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
673
674These return a string decimal representations of an ASN1_INTEGER and an
675ASN1_ENUMERATED type, respectively.
676
677ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
678 X509V3_CTX *ctx, char *str);
679
680This converts an ASCII hex string to an ASN1_OCTET_STRING.
681
682ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
683
684This converts a decimal ASCII string into an ASN1_INTEGER.
685
6866. Multi valued extension helper functions.
687
688The following functions can be used to manipulate STACKs of CONF_VALUE
689structures, as used by multi valued extensions.
690
691int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
692
693This function expects a boolean value in 'value' and sets 'asn1_bool' to
694it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
695strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
696"false", "N", "n", "NO" or "no".
697
698int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
699
700This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
701
702int X509V3_add_value(const char *name, const char *value,
703 STACK_OF(CONF_VALUE) **extlist);
704
705This simply adds a string name and value pair.
706
707int X509V3_add_value_uchar(const char *name, const unsigned char *value,
708 STACK_OF(CONF_VALUE) **extlist);
709
710The same as above but for an unsigned character value.
711
712int X509V3_add_value_bool(const char *name, int asn1_bool,
713 STACK_OF(CONF_VALUE) **extlist);
714
715This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool'
716
717int X509V3_add_value_bool_nf(char *name, int asn1_bool,
718 STACK_OF(CONF_VALUE) **extlist);
719
720This is the same as above except it adds nothing if asn1_bool is FALSE.
721
722int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
723 STACK_OF(CONF_VALUE) **extlist);
724
725This function adds the value of the ASN1_INTEGER in decimal form.
726
7277. Other helper functions.
728
729<to be added>
730
731ADDING CUSTOM EXTENSIONS.
732
733Currently there are three types of supported extensions.
734
735String extensions are simple strings where the value is placed directly in the
736extensions, and the string returned is printed out.
737
738Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
739or return a STACK_OF(CONF_VALUE).
740
741Raw extensions are just passed a BIO or a value and it is the extensions
742responsibility to handle all the necessary printing.
743
744There are two ways to add an extension. One is simply as an alias to an already
745existing extension. An alias is an extension that is identical in ASN1 structure
746to an existing extension but has a different OBJECT IDENTIFIER. This can be
747done by calling:
748
749int X509V3_EXT_add_alias(int nid_to, int nid_from);
750
751'nid_to' is the new extension NID and 'nid_from' is the already existing
752extension NID.
753
754Alternatively an extension can be written from scratch. This involves writing
755the ASN1 code to encode and decode the extension and functions to print out and
756generate the extension from strings. The relevant functions are then placed in
757a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
758called.
759
760The X509V3_EXT_METHOD structure is described below.
761
762strut {
763int ext_nid;
764int ext_flags;
765X509V3_EXT_NEW ext_new;
766X509V3_EXT_FREE ext_free;
767X509V3_EXT_D2I d2i;
768X509V3_EXT_I2D i2d;
769X509V3_EXT_I2S i2s;
770X509V3_EXT_S2I s2i;
771X509V3_EXT_I2V i2v;
772X509V3_EXT_V2I v2i;
773X509V3_EXT_R2I r2i;
774X509V3_EXT_I2R i2r;
775
776void *usr_data;
777};
778
779The elements have the following meanings.
780
781ext_nid is the NID of the object identifier of the extension.
782
783ext_flags is set of flags. Currently the only external flag is
784 X509V3_EXT_MULTILINE which means a multi valued extensions
785 should be printed on separate lines.
786
787usr_data is an extension specific pointer to any relevant data. This
788 allows extensions to share identical code but have different
789 uses. An example of this is the bit string extension which uses
790 usr_data to contain a list of the bit names.
791
792All the remaining elements are function pointers.
793
794ext_new is a pointer to a function that allocates memory for the
795 extension ASN1 structure: for example ASN1_OBJECT_new().
796
797ext_free is a pointer to a function that free up memory of the extension
798 ASN1 structure: for example ASN1_OBJECT_free().
799
800d2i is the standard ASN1 function that converts a DER buffer into
801 the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
802
803i2d is the standard ASN1 function that converts the internal
804 structure into the DER representation: for example
805 i2d_ASN1_IA5STRING().
806
807The remaining functions are depend on the type of extension. One i2X and
808one X2i should be set and the rest set to NULL. The types set do not need
809to match up, for example the extension could be set using the multi valued
810v2i function and printed out using the raw i2r.
811
812All functions have the X509V3_EXT_METHOD passed to them in the 'method'
813parameter and an X509V3_CTX structure. Extension code can then access the
814parent structure via the 'method' parameter to for example make use of the value
815of usr_data. If the code needs to use detail relating to the request it can
816use the 'ctx' parameter.
817
818A note should be given here about the 'flags' member of the 'ctx' parameter.
819If it has the value CTX_TEST then the configuration syntax is being checked
820and no actual certificate or CRL exists. Therefore any attempt in the config
821file to access such information should silently succeed. If the syntax is OK
822then it should simply return a (possibly bogus) extension, otherwise it
823should return NULL.
824
825char *i2s(struct v3_ext_method *method, void *ext);
826
827This function takes the internal structure in the ext parameter and returns
828a Malloc'ed string representing its value.
829
830void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
831
832This function takes the string representation in the ext parameter and returns
833an allocated internal structure: ext_free() will be used on this internal
834structure after use.
835
836i2v and v2i handle a STACK_OF(CONF_VALUE):
837
838typedef struct
839{
840 char *section;
841 char *name;
842 char *value;
843} CONF_VALUE;
844
845Only the name and value members are currently used.
846
847STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
848
849This function is passed the internal structure in the ext parameter and
850returns a STACK of CONF_VALUE structures. The values of name, value,
851section and the structure itself will be freed up with Free after use.
852Several helper functions are available to add values to this STACK.
853
854void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
855 STACK_OF(CONF_VALUE) *values);
856
857This function takes a STACK_OF(CONF_VALUE) structures and should set the
858values of the external structure. This typically uses the name element to
859determine which structure element to set and the value element to determine
860what to set it to. Several helper functions are available for this
861purpose (see above).
862
863int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
864
865This function is passed the internal extension structure in the ext parameter
866and sends out a human readable version of the extension to out. The 'indent'
867parameter should be noted to determine the necessary amount of indentation
868needed on the output.
869
870void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
871
872This is just passed the string representation of the extension. It is intended
873to be used for more elaborate extensions where the standard single and multi
874valued options are insufficient. They can use the 'ctx' parameter to parse the
875configuration database themselves. See the context functions section for details
876of how to do this.
877
878Note: although this type takes the same parameters as the "r2s" function there
879is a subtle difference. Whereas an "r2i" function can access a configuration
880database an "s2i" function MUST NOT. This is so the internal code can safely
881assume that an "s2i" function will work without a configuration database.
882
883==============================================================================
884 PKCS#12 Library
885==============================================================================
886
887This section describes the internal PKCS#12 support. There are very few
888differences between the old external library and the new internal code at
889present. This may well change because the external library will not be updated
890much in future.
891
892This version now includes a couple of high level PKCS#12 functions which
893generally "do the right thing" and should make it much easier to handle PKCS#12
894structures.
895
896HIGH LEVEL FUNCTIONS.
897
898For most applications you only need concern yourself with the high level
899functions. They can parse and generate simple PKCS#12 files as produced by
900Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
901private key and certificate pair.
902
9031. Initialisation and cleanup.
904
905No special initialisation is needed for the internal PKCS#12 library: the
906standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
907add all algorithms (you should at least add SHA1 though) then you can manually
908initialise the PKCS#12 library with:
909
910PKCS12_PBE_add();
911
912The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
913called or it can be directly freed with:
914
915EVP_PBE_cleanup();
916
917after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
918be called.
919
9202. I/O functions.
921
922i2d_PKCS12_bio(bp, p12)
923
924This writes out a PKCS12 structure to a BIO.
925
926i2d_PKCS12_fp(fp, p12)
927
928This is the same but for a FILE pointer.
929
930d2i_PKCS12_bio(bp, p12)
931
932This reads in a PKCS12 structure from a BIO.
933
934d2i_PKCS12_fp(fp, p12)
935
936This is the same but for a FILE pointer.
937
9383. High level functions.
939
9403.1 Parsing with PKCS12_parse().
941
942int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
943 STACK **ca);
944
945This function takes a PKCS12 structure and a password (ASCII, null terminated)
946and returns the private key, the corresponding certificate and any CA
947certificates. If any of these is not required it can be passed as a NULL.
948The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
949structure. Typically to read in a PKCS#12 file you might do:
950
951p12 = d2i_PKCS12_fp(fp, NULL);
952PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */
953PKCS12_free(p12);
954
9553.2 PKCS#12 creation with PKCS12_create().
956
957PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
958 STACK *ca, int nid_key, int nid_cert, int iter,
959 int mac_iter, int keytype);
960
961This function will create a PKCS12 structure from a given password, name,
962private key, certificate and optional STACK of CA certificates. The remaining
9635 parameters can be set to 0 and sensible defaults will be used.
964
965The parameters nid_key and nid_cert are the key and certificate encryption
966algorithms, iter is the encryption iteration count, mac_iter is the MAC
967iteration count and keytype is the type of private key. If you really want
968to know what these last 5 parameters do then read the low level section.
969
970Typically to create a PKCS#12 file the following could be used:
971
972p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
973i2d_PKCS12_fp(fp, p12);
974PKCS12_free(p12);
975
9763.3 Changing a PKCS#12 structure password.
977
978int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
979
980This changes the password of an already existing PKCS#12 structure. oldpass
981is the old password and newpass is the new one. An error occurs if the old
982password is incorrect.
983
984LOW LEVEL FUNCTIONS.
985
986In some cases the high level functions do not provide the necessary
987functionality. For example if you want to generate or parse more complex
988PKCS#12 files. The sample pkcs12 application uses the low level functions
989to display details about the internal structure of a PKCS#12 file.
990
991Introduction.
992
993This is a brief description of how a PKCS#12 file is represented internally:
994some knowledge of PKCS#12 is assumed.
995
996A PKCS#12 object contains several levels.
997
998At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
999CRL, a private key, encrypted or unencrypted, a set of safebags (so the
1000structure can be nested) or other secrets (not documented at present).
1001A safebag can optionally have attributes, currently these are: a unicode
1002friendlyName (a Unicode string) or a localKeyID (a string of bytes).
1003
1004At the next level is an authSafe which is a set of safebags collected into
1005a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
1006
1007At the top level is the PKCS12 structure itself which contains a set of
1008authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
1009contains a MAC which is a kind of password protected digest to preserve
1010integrity (so any unencrypted stuff below can't be tampered with).
1011
1012The reason for these levels is so various objects can be encrypted in various
1013ways. For example you might want to encrypt a set of private keys with
1014triple-DES and then include the related certificates either unencrypted or
1015with lower encryption. Yes it's the dreaded crypto laws at work again which
1016allow strong encryption on private keys and only weak encryption on other
1017stuff.
1018
1019To build one of these things you turn all certificates and keys into safebags
1020(with optional attributes). You collect the safebags into (one or more) STACKS
1021and convert these into authsafes (encrypted or unencrypted). The authsafes
1022are collected into a STACK and added to a PKCS12 structure. Finally a MAC
1023inserted.
1024
1025Pulling one apart is basically the reverse process. The MAC is verified against
1026the given password. The authsafes are extracted and each authsafe split into
1027a set of safebags (possibly involving decryption). Finally the safebags are
1028decomposed into the original keys and certificates and the attributes used to
1029match up private key and certificate pairs.
1030
1031Anyway here are the functions that do the dirty work.
1032
10331. Construction functions.
1034
10351.1 Safebag functions.
1036
1037M_PKCS12_x5092certbag(x509)
1038
1039This macro takes an X509 structure and returns a certificate bag. The
1040X509 structure can be freed up after calling this function.
1041
1042M_PKCS12_x509crl2certbag(crl)
1043
1044As above but for a CRL.
1045
1046PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
1047
1048Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
1049Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
1050structure contains a private key data in plain text form it should be free'd
1051up as soon as it has been encrypted for security reasons (freeing up the
1052structure zeros out the sensitive data). This can be done with
1053PKCS8_PRIV_KEY_INFO_free().
1054
1055PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
1056
1057This sets the key type when a key is imported into MSIE or Outlook 98. Two
1058values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
1059key that can also be used for signing but its size is limited in the export
1060versions of MS software to 512 bits, it is also the default. KEY_SIG is a
1061signing only key but the keysize is unlimited (well 16K is supposed to work).
1062If you are using the domestic version of MSIE then you can ignore this because
1063KEY_EX is not limited and can be used for both.
1064
1065PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
1066
1067Convert a PKCS8 private key structure into a keybag. This routine embeds the
1068p8 structure in the keybag so p8 should not be freed up or used after it is
1069called. The p8 structure will be freed up when the safebag is freed.
1070
1071PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
1072
1073Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
1074embedded and can be freed up after use.
1075
1076int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1077int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1078
1079Add a local key id or a friendlyname to a safebag.
1080
10811.2 Authsafe functions.
1082
1083PKCS7 *PKCS12_pack_p7data(STACK *sk)
1084Take a stack of safebags and convert them into an unencrypted authsafe. The
1085stack of safebags can be freed up after calling this function.
1086
1087PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
1088
1089As above but encrypted.
1090
10911.3 PKCS12 functions.
1092
1093PKCS12 *PKCS12_init(int mode)
1094
1095Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
1096
1097M_PKCS12_pack_authsafes(p12, safes)
1098
1099This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
1100
1101int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
1102
1103Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
1104that SHA-1 should be used.
1105
11062. Extraction Functions.
1107
11082.1 Safebags.
1109
1110M_PKCS12_bag_type(bag)
1111
1112Return the type of "bag". Returns one of the following
1113
1114NID_keyBag
1115NID_pkcs8ShroudedKeyBag 7
1116NID_certBag 8
1117NID_crlBag 9
1118NID_secretBag 10
1119NID_safeContentsBag 11
1120
1121M_PKCS12_cert_bag_type(bag)
1122
1123Returns type of certificate bag, following are understood.
1124
1125NID_x509Certificate 14
1126NID_sdsiCertificate 15
1127
1128M_PKCS12_crl_bag_type(bag)
1129
1130Returns crl bag type, currently only NID_crlBag is recognised.
1131
1132M_PKCS12_certbag2x509(bag)
1133
1134This macro extracts an X509 certificate from a certificate bag.
1135
1136M_PKCS12_certbag2x509crl(bag)
1137
1138As above but for a CRL.
1139
1140EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
1141
1142Extract a private key from a PKCS8 private key info structure.
1143
1144M_PKCS12_decrypt_skey(bag, pass, passlen)
1145
1146Decrypt a shrouded key bag and return a PKCS8 private key info structure.
1147Works with both RSA and DSA keys
1148
1149char *PKCS12_get_friendlyname(bag)
1150
1151Returns the friendlyName of a bag if present or NULL if none. The returned
1152string is a null terminated ASCII string allocated with Malloc(). It should
1153thus be freed up with Free() after use.
1154
11552.2 AuthSafe functions.
1156
1157M_PKCS12_unpack_p7data(p7)
1158
1159Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
1160
1161#define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
1162
1163As above but for an encrypted content info.
1164
11652.3 PKCS12 functions.
1166
1167M_PKCS12_unpack_authsafes(p12)
1168
1169Extract a STACK of authsafes from a PKCS12 structure.
1170
1171M_PKCS12_mac_present(p12)
1172
1173Check to see if a MAC is present.
1174
1175int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
1176
1177Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
1178
1179
1180Notes.
1181
11821. All the function return 0 or NULL on error.
11832. Encryption based functions take a common set of parameters. These are
1184described below.
1185
1186pass, passlen
1187ASCII password and length. The password on the MAC is called the "integrity
1188password" the encryption password is called the "privacy password" in the
1189PKCS#12 documentation. The passwords do not have to be the same. If -1 is
1190passed for the length it is worked out by the function itself (currently
1191this is sometimes done whatever is passed as the length but that may change).
1192
1193salt, saltlen
1194A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
1195default length is used.
1196
1197iter
1198Iteration count. This is a measure of how many times an internal function is
1199called to encrypt the data. The larger this value is the longer it takes, it
1200makes dictionary attacks on passwords harder. NOTE: Some implementations do
1201not support an iteration count on the MAC. If the password for the MAC and
1202encryption is the same then there is no point in having a high iteration
1203count for encryption if the MAC has no count. The MAC could be attacked
1204and the password used for the main decryption.
1205
1206pbe_nid
1207This is the NID of the password based encryption method used. The following are
1208supported.
1209NID_pbe_WithSHA1And128BitRC4
1210NID_pbe_WithSHA1And40BitRC4
1211NID_pbe_WithSHA1And3_Key_TripleDES_CBC
1212NID_pbe_WithSHA1And2_Key_TripleDES_CBC
1213NID_pbe_WithSHA1And128BitRC2_CBC
1214NID_pbe_WithSHA1And40BitRC2_CBC
1215
1216Which you use depends on the implementation you are exporting to. "Export
1217grade" (i.e. cryptographically challenged) products cannot support all
1218algorithms. Typically you may be able to use any encryption on shrouded key
1219bags but they must then be placed in an unencrypted authsafe. Other authsafes
1220may only support 40bit encryption. Of course if you are using SSLeay
1221throughout you can strongly encrypt everything and have high iteration counts
1222on everything.
1223
12243. For decryption routines only the password and length are needed.
1225
12264. Unlike the external version the nid's of objects are the values of the
1227constants: that is NID_certBag is the real nid, therefore there is no
1228PKCS12_obj_offset() function. Note the object constants are not the same as
1229those of the external version. If you use these constants then you will need
1230to recompile your code.
1231
12325. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or
1233macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
1234reused or freed up safely.
1235
diff --git a/src/lib/libssl/doc/standards.txt b/src/lib/libssl/doc/standards.txt
deleted file mode 100644
index f6675b574b..0000000000
--- a/src/lib/libssl/doc/standards.txt
+++ /dev/null
@@ -1,261 +0,0 @@
1Standards related to OpenSSL
2============================
3
4[Please, this is currently a draft. I made a first try at finding
5 documents that describe parts of what OpenSSL implements. There are
6 big gaps, and I've most certainly done something wrong. Please
7 correct whatever is... Also, this note should be removed when this
8 file is reaching a somewhat correct state. -- Richard Levitte]
9
10
11All pointers in here will be either URL's or blobs of text borrowed
12from miscellaneous indexes, like rfc-index.txt (index of RFCs),
131id-index.txt (index of Internet drafts) and the like.
14
15To find the latest possible RFCs, it's recommended to either browse
16ftp://ftp.isi.edu/in-notes/ or go to http://www.rfc-editor.org/ and
17use the search mechanism found there.
18To find the latest possible Internet drafts, it's recommended to
19browse ftp://ftp.isi.edu/internet-drafts/.
20To find the latest possible PKCS, it's recommended to browse
21http://www.rsasecurity.com/rsalabs/pkcs/.
22
23
24Implemented:
25------------
26
27These are documents that describe things that are implemented (in
28whole or at least great parts) in OpenSSL.
29
301319 The MD2 Message-Digest Algorithm. B. Kaliski. April 1992.
31 (Format: TXT=25661 bytes) (Status: INFORMATIONAL)
32
331320 The MD4 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
34 TXT=32407 bytes) (Status: INFORMATIONAL)
35
361321 The MD5 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
37 TXT=35222 bytes) (Status: INFORMATIONAL)
38
392246 The TLS Protocol Version 1.0. T. Dierks, C. Allen. January 1999.
40 (Format: TXT=170401 bytes) (Status: PROPOSED STANDARD)
41
422268 A Description of the RC2(r) Encryption Algorithm. R. Rivest.
43 January 1998. (Format: TXT=19048 bytes) (Status: INFORMATIONAL)
44
452315 PKCS 7: Cryptographic Message Syntax Version 1.5. B. Kaliski.
46 March 1998. (Format: TXT=69679 bytes) (Status: INFORMATIONAL)
47
48PKCS#8: Private-Key Information Syntax Standard
49
50PKCS#12: Personal Information Exchange Syntax Standard, version 1.0.
51
522560 X.509 Internet Public Key Infrastructure Online Certificate
53 Status Protocol - OCSP. M. Myers, R. Ankney, A. Malpani, S. Galperin,
54 C. Adams. June 1999. (Format: TXT=43243 bytes) (Status: PROPOSED
55 STANDARD)
56
572712 Addition of Kerberos Cipher Suites to Transport Layer Security
58 (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes)
59 (Status: PROPOSED STANDARD)
60
612898 PKCS #5: Password-Based Cryptography Specification Version 2.0.
62 B. Kaliski. September 2000. (Format: TXT=68692 bytes) (Status:
63 INFORMATIONAL)
64
652986 PKCS #10: Certification Request Syntax Specification Version 1.7.
66 M. Nystrom, B. Kaliski. November 2000. (Format: TXT=27794 bytes)
67 (Obsoletes RFC2314) (Status: INFORMATIONAL)
68
693174 US Secure Hash Algorithm 1 (SHA1). D. Eastlake 3rd, P. Jones.
70 September 2001. (Format: TXT=35525 bytes) (Status: INFORMATIONAL)
71
723268 Advanced Encryption Standard (AES) Ciphersuites for Transport
73 Layer Security (TLS). P. Chown. June 2002. (Format: TXT=13530 bytes)
74 (Status: PROPOSED STANDARD)
75
763279 Algorithms and Identifiers for the Internet X.509 Public Key
77 Infrastructure Certificate and Certificate Revocation List (CRL)
78 Profile. L. Bassham, W. Polk, R. Housley. April 2002. (Format:
79 TXT=53833 bytes) (Status: PROPOSED STANDARD)
80
813280 Internet X.509 Public Key Infrastructure Certificate and
82 Certificate Revocation List (CRL) Profile. R. Housley, W. Polk, W.
83 Ford, D. Solo. April 2002. (Format: TXT=295556 bytes) (Obsoletes
84 RFC2459) (Status: PROPOSED STANDARD)
85
863447 Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography
87 Specifications Version 2.1. J. Jonsson, B. Kaliski. February 2003.
88 (Format: TXT=143173 bytes) (Obsoletes RFC2437) (Status:
89 INFORMATIONAL)
90
913820 Internet X.509 Public Key Infrastructure (PKI) Proxy Certificate
92 Profile. S. Tuecke, V. Welch, D. Engert, L. Pearlman, M. Thompson.
93 June 2004. (Format: TXT=86374 bytes) (Status: PROPOSED STANDARD)
94
95
96Related:
97--------
98
99These are documents that are close to OpenSSL, for example the
100STARTTLS documents.
101
1021421 Privacy Enhancement for Internet Electronic Mail: Part I: Message
103 Encryption and Authentication Procedures. J. Linn. February 1993.
104 (Format: TXT=103894 bytes) (Obsoletes RFC1113) (Status: PROPOSED
105 STANDARD)
106
1071422 Privacy Enhancement for Internet Electronic Mail: Part II:
108 Certificate-Based Key Management. S. Kent. February 1993. (Format:
109 TXT=86085 bytes) (Obsoletes RFC1114) (Status: PROPOSED STANDARD)
110
1111423 Privacy Enhancement for Internet Electronic Mail: Part III:
112 Algorithms, Modes, and Identifiers. D. Balenson. February 1993.
113 (Format: TXT=33277 bytes) (Obsoletes RFC1115) (Status: PROPOSED
114 STANDARD)
115
1161424 Privacy Enhancement for Internet Electronic Mail: Part IV: Key
117 Certification and Related Services. B. Kaliski. February 1993.
118 (Format: TXT=17537 bytes) (Status: PROPOSED STANDARD)
119
1202025 The Simple Public-Key GSS-API Mechanism (SPKM). C. Adams. October
121 1996. (Format: TXT=101692 bytes) (Status: PROPOSED STANDARD)
122
1232510 Internet X.509 Public Key Infrastructure Certificate Management
124 Protocols. C. Adams, S. Farrell. March 1999. (Format: TXT=158178
125 bytes) (Status: PROPOSED STANDARD)
126
1272511 Internet X.509 Certificate Request Message Format. M. Myers, C.
128 Adams, D. Solo, D. Kemp. March 1999. (Format: TXT=48278 bytes)
129 (Status: PROPOSED STANDARD)
130
1312527 Internet X.509 Public Key Infrastructure Certificate Policy and
132 Certification Practices Framework. S. Chokhani, W. Ford. March 1999.
133 (Format: TXT=91860 bytes) (Status: INFORMATIONAL)
134
1352538 Storing Certificates in the Domain Name System (DNS). D. Eastlake
136 3rd, O. Gudmundsson. March 1999. (Format: TXT=19857 bytes) (Status:
137 PROPOSED STANDARD)
138
1392539 Storage of Diffie-Hellman Keys in the Domain Name System (DNS).
140 D. Eastlake 3rd. March 1999. (Format: TXT=21049 bytes) (Status:
141 PROPOSED STANDARD)
142
1432559 Internet X.509 Public Key Infrastructure Operational Protocols -
144 LDAPv2. S. Boeyen, T. Howes, P. Richard. April 1999. (Format:
145 TXT=22889 bytes) (Updates RFC1778) (Status: PROPOSED STANDARD)
146
1472585 Internet X.509 Public Key Infrastructure Operational Protocols:
148 FTP and HTTP. R. Housley, P. Hoffman. May 1999. (Format: TXT=14813
149 bytes) (Status: PROPOSED STANDARD)
150
1512587 Internet X.509 Public Key Infrastructure LDAPv2 Schema. S.
152 Boeyen, T. Howes, P. Richard. June 1999. (Format: TXT=15102 bytes)
153 (Status: PROPOSED STANDARD)
154
1552595 Using TLS with IMAP, POP3 and ACAP. C. Newman. June 1999.
156 (Format: TXT=32440 bytes) (Status: PROPOSED STANDARD)
157
1582631 Diffie-Hellman Key Agreement Method. E. Rescorla. June 1999.
159 (Format: TXT=25932 bytes) (Status: PROPOSED STANDARD)
160
1612632 S/MIME Version 3 Certificate Handling. B. Ramsdell, Ed.. June
162 1999. (Format: TXT=27925 bytes) (Status: PROPOSED STANDARD)
163
1642716 PPP EAP TLS Authentication Protocol. B. Aboba, D. Simon. October
165 1999. (Format: TXT=50108 bytes) (Status: EXPERIMENTAL)
166
1672773 Encryption using KEA and SKIPJACK. R. Housley, P. Yee, W. Nace.
168 February 2000. (Format: TXT=20008 bytes) (Updates RFC0959) (Status:
169 EXPERIMENTAL)
170
1712797 Certificate Management Messages over CMS. M. Myers, X. Liu, J.
172 Schaad, J. Weinstein. April 2000. (Format: TXT=103357 bytes) (Status:
173 PROPOSED STANDARD)
174
1752817 Upgrading to TLS Within HTTP/1.1. R. Khare, S. Lawrence. May
176 2000. (Format: TXT=27598 bytes) (Updates RFC2616) (Status: PROPOSED
177 STANDARD)
178
1792818 HTTP Over TLS. E. Rescorla. May 2000. (Format: TXT=15170 bytes)
180 (Status: INFORMATIONAL)
181
1822876 Use of the KEA and SKIPJACK Algorithms in CMS. J. Pawling. July
183 2000. (Format: TXT=29265 bytes) (Status: INFORMATIONAL)
184
1852984 Use of the CAST-128 Encryption Algorithm in CMS. C. Adams.
186 October 2000. (Format: TXT=11591 bytes) (Status: PROPOSED STANDARD)
187
1882985 PKCS #9: Selected Object Classes and Attribute Types Version 2.0.
189 M. Nystrom, B. Kaliski. November 2000. (Format: TXT=70703 bytes)
190 (Status: INFORMATIONAL)
191
1923029 Internet X.509 Public Key Infrastructure Data Validation and
193 Certification Server Protocols. C. Adams, P. Sylvester, M. Zolotarev,
194 R. Zuccherato. February 2001. (Format: TXT=107347 bytes) (Status:
195 EXPERIMENTAL)
196
1973039 Internet X.509 Public Key Infrastructure Qualified Certificates
198 Profile. S. Santesson, W. Polk, P. Barzin, M. Nystrom. January 2001.
199 (Format: TXT=67619 bytes) (Status: PROPOSED STANDARD)
200
2013058 Use of the IDEA Encryption Algorithm in CMS. S. Teiwes, P.
202 Hartmann, D. Kuenzi. February 2001. (Format: TXT=17257 bytes)
203 (Status: INFORMATIONAL)
204
2053161 Internet X.509 Public Key Infrastructure Time-Stamp Protocol
206 (TSP). C. Adams, P. Cain, D. Pinkas, R. Zuccherato. August 2001.
207 (Format: TXT=54585 bytes) (Status: PROPOSED STANDARD)
208
2093185 Reuse of CMS Content Encryption Keys. S. Farrell, S. Turner.
210 October 2001. (Format: TXT=20404 bytes) (Status: PROPOSED STANDARD)
211
2123207 SMTP Service Extension for Secure SMTP over Transport Layer
213 Security. P. Hoffman. February 2002. (Format: TXT=18679 bytes)
214 (Obsoletes RFC2487) (Status: PROPOSED STANDARD)
215
2163217 Triple-DES and RC2 Key Wrapping. R. Housley. December 2001.
217 (Format: TXT=19855 bytes) (Status: INFORMATIONAL)
218
2193274 Compressed Data Content Type for Cryptographic Message Syntax
220 (CMS). P. Gutmann. June 2002. (Format: TXT=11276 bytes) (Status:
221 PROPOSED STANDARD)
222
2233278 Use of Elliptic Curve Cryptography (ECC) Algorithms in
224 Cryptographic Message Syntax (CMS). S. Blake-Wilson, D. Brown, P.
225 Lambert. April 2002. (Format: TXT=33779 bytes) (Status:
226 INFORMATIONAL)
227
2283281 An Internet Attribute Certificate Profile for Authorization. S.
229 Farrell, R. Housley. April 2002. (Format: TXT=90580 bytes) (Status:
230 PROPOSED STANDARD)
231
2323369 Cryptographic Message Syntax (CMS). R. Housley. August 2002.
233 (Format: TXT=113975 bytes) (Obsoletes RFC2630, RFC3211) (Status:
234 PROPOSED STANDARD)
235
2363370 Cryptographic Message Syntax (CMS) Algorithms. R. Housley. August
237 2002. (Format: TXT=51001 bytes) (Obsoletes RFC2630, RFC3211) (Status:
238 PROPOSED STANDARD)
239
2403377 Lightweight Directory Access Protocol (v3): Technical
241 Specification. J. Hodges, R. Morgan. September 2002. (Format:
242 TXT=9981 bytes) (Updates RFC2251, RFC2252, RFC2253, RFC2254, RFC2255,
243 RFC2256, RFC2829, RFC2830) (Status: PROPOSED STANDARD)
244
2453394 Advanced Encryption Standard (AES) Key Wrap Algorithm. J. Schaad,
246 R. Housley. September 2002. (Format: TXT=73072 bytes) (Status:
247 INFORMATIONAL)
248
2493436 Transport Layer Security over Stream Control Transmission
250 Protocol. A. Jungmaier, E. Rescorla, M. Tuexen. December 2002.
251 (Format: TXT=16333 bytes) (Status: PROPOSED STANDARD)
252
253 "Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt>
254
255
256To be implemented:
257------------------
258
259These are documents that describe things that are planed to be
260implemented in the hopefully short future.
261
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c
deleted file mode 100644
index 86356731ea..0000000000
--- a/src/lib/libssl/s23_clnt.c
+++ /dev/null
@@ -1,616 +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 "ssl_locl.h"
61#include <openssl/buffer.h>
62#include <openssl/rand.h>
63#include <openssl/objects.h>
64#include <openssl/evp.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 OPENSSL_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 CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
91
92 if (init)
93 {
94 memcpy((char *)&SSLv23_client_data,
95 (char *)sslv23_base_method(),sizeof(SSL_METHOD));
96 SSLv23_client_data.ssl_connect=ssl23_connect;
97 SSLv23_client_data.get_ssl_method=ssl23_get_client_method;
98 init=0;
99 }
100
101 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
102 }
103 return(&SSLv23_client_data);
104 }
105
106int ssl23_connect(SSL *s)
107 {
108 BUF_MEM *buf=NULL;
109 unsigned long Time=(unsigned long)time(NULL);
110 void (*cb)(const SSL *ssl,int type,int val)=NULL;
111 int ret= -1;
112 int new_state,state;
113
114 RAND_add(&Time,sizeof(Time),0);
115 ERR_clear_error();
116 clear_sys_error();
117
118 if (s->info_callback != NULL)
119 cb=s->info_callback;
120 else if (s->ctx->info_callback != NULL)
121 cb=s->ctx->info_callback;
122
123 s->in_handshake++;
124 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
125
126 for (;;)
127 {
128 state=s->state;
129
130 switch(s->state)
131 {
132 case SSL_ST_BEFORE:
133 case SSL_ST_CONNECT:
134 case SSL_ST_BEFORE|SSL_ST_CONNECT:
135 case SSL_ST_OK|SSL_ST_CONNECT:
136
137 if (s->session != NULL)
138 {
139 SSLerr(SSL_F_SSL23_CONNECT,SSL_R_SSL23_DOING_SESSION_ID_REUSE);
140 ret= -1;
141 goto end;
142 }
143 s->server=0;
144 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
145
146 /* s->version=TLS1_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 buf=NULL;
163 }
164
165 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
166
167 ssl3_init_finished_mac(s);
168
169 s->state=SSL23_ST_CW_CLNT_HELLO_A;
170 s->ctx->stats.sess_connect++;
171 s->init_num=0;
172 break;
173
174 case SSL23_ST_CW_CLNT_HELLO_A:
175 case SSL23_ST_CW_CLNT_HELLO_B:
176
177 s->shutdown=0;
178 ret=ssl23_client_hello(s);
179 if (ret <= 0) goto end;
180 s->state=SSL23_ST_CR_SRVR_HELLO_A;
181 s->init_num=0;
182
183 break;
184
185 case SSL23_ST_CR_SRVR_HELLO_A:
186 case SSL23_ST_CR_SRVR_HELLO_B:
187 ret=ssl23_get_server_hello(s);
188 if (ret >= 0) cb=NULL;
189 goto end;
190 /* break; */
191
192 default:
193 SSLerr(SSL_F_SSL23_CONNECT,SSL_R_UNKNOWN_STATE);
194 ret= -1;
195 goto end;
196 /* break; */
197 }
198
199 if (s->debug) { (void)BIO_flush(s->wbio); }
200
201 if ((cb != NULL) && (s->state != state))
202 {
203 new_state=s->state;
204 s->state=state;
205 cb(s,SSL_CB_CONNECT_LOOP,1);
206 s->state=new_state;
207 }
208 }
209end:
210 s->in_handshake--;
211 if (buf != NULL)
212 BUF_MEM_free(buf);
213 if (cb != NULL)
214 cb(s,SSL_CB_CONNECT_EXIT,ret);
215 return(ret);
216 }
217
218
219static int ssl23_client_hello(SSL *s)
220 {
221 unsigned char *buf;
222 unsigned char *p,*d;
223 int i,j,ch_len;
224 unsigned long Time,l;
225 int ssl2_compat;
226 int version = 0, version_major, version_minor;
227 SSL_COMP *comp;
228 int ret;
229
230 ssl2_compat = (s->options & SSL_OP_NO_SSLv2) ? 0 : 1;
231
232 if (!(s->options & SSL_OP_NO_TLSv1))
233 {
234 version = TLS1_VERSION;
235 }
236 else if (!(s->options & SSL_OP_NO_SSLv3))
237 {
238 version = SSL3_VERSION;
239 }
240 else if (!(s->options & SSL_OP_NO_SSLv2))
241 {
242 version = SSL2_VERSION;
243 }
244
245 buf=(unsigned char *)s->init_buf->data;
246 if (s->state == SSL23_ST_CW_CLNT_HELLO_A)
247 {
248#if 0
249 /* don't reuse session-id's */
250 if (!ssl_get_new_session(s,0))
251 {
252 return(-1);
253 }
254#endif
255
256 p=s->s3->client_random;
257 Time=(unsigned long)time(NULL); /* Time */
258 l2n(Time,p);
259 if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
260 return -1;
261
262 if (version == TLS1_VERSION)
263 {
264 version_major = TLS1_VERSION_MAJOR;
265 version_minor = TLS1_VERSION_MINOR;
266 }
267#ifdef OPENSSL_FIPS
268 else if(FIPS_mode())
269 {
270 SSLerr(SSL_F_SSL23_CLIENT_HELLO,
271 SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
272 return -1;
273 }
274#endif
275 else if (version == SSL3_VERSION)
276 {
277 version_major = SSL3_VERSION_MAJOR;
278 version_minor = SSL3_VERSION_MINOR;
279 }
280 else if (version == SSL2_VERSION)
281 {
282 version_major = SSL2_VERSION_MAJOR;
283 version_minor = SSL2_VERSION_MINOR;
284 }
285 else
286 {
287 SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_PROTOCOLS_AVAILABLE);
288 return(-1);
289 }
290
291 s->client_version = version;
292
293 if (ssl2_compat)
294 {
295 /* create SSL 2.0 compatible Client Hello */
296
297 /* two byte record header will be written last */
298 d = &(buf[2]);
299 p = d + 9; /* leave space for message type, version, individual length fields */
300
301 *(d++) = SSL2_MT_CLIENT_HELLO;
302 *(d++) = version_major;
303 *(d++) = version_minor;
304
305 /* Ciphers supported */
306 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),p,0);
307 if (i == 0)
308 {
309 /* no ciphers */
310 SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
311 return -1;
312 }
313 s2n(i,d);
314 p+=i;
315
316 /* put in the session-id length (zero since there is no reuse) */
317#if 0
318 s->session->session_id_length=0;
319#endif
320 s2n(0,d);
321
322 if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
323 ch_len=SSL2_CHALLENGE_LENGTH;
324 else
325 ch_len=SSL2_MAX_CHALLENGE_LENGTH;
326
327 /* write out sslv2 challenge */
328 if (SSL3_RANDOM_SIZE < ch_len)
329 i=SSL3_RANDOM_SIZE;
330 else
331 i=ch_len;
332 s2n(i,d);
333 memset(&(s->s3->client_random[0]),0,SSL3_RANDOM_SIZE);
334 if (RAND_pseudo_bytes(&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i) <= 0)
335 return -1;
336
337 memcpy(p,&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
338 p+=i;
339
340 i= p- &(buf[2]);
341 buf[0]=((i>>8)&0xff)|0x80;
342 buf[1]=(i&0xff);
343
344 /* number of bytes to write */
345 s->init_num=i+2;
346 s->init_off=0;
347
348 ssl3_finish_mac(s,&(buf[2]),i);
349 }
350 else
351 {
352 /* create Client Hello in SSL 3.0/TLS 1.0 format */
353
354 /* do the record header (5 bytes) and handshake message header (4 bytes) last */
355 d = p = &(buf[9]);
356
357 *(p++) = version_major;
358 *(p++) = version_minor;
359
360 /* Random stuff */
361 memcpy(p, s->s3->client_random, SSL3_RANDOM_SIZE);
362 p += SSL3_RANDOM_SIZE;
363
364 /* Session ID (zero since there is no reuse) */
365 *(p++) = 0;
366
367 /* Ciphers supported (using SSL 3.0/TLS 1.0 format) */
368 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]),ssl3_put_cipher_by_char);
369 if (i == 0)
370 {
371 SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
372 return -1;
373 }
374 s2n(i,p);
375 p+=i;
376
377 /* COMPRESSION */
378 if (s->ctx->comp_methods == NULL)
379 j=0;
380 else
381 j=sk_SSL_COMP_num(s->ctx->comp_methods);
382 *(p++)=1+j;
383 for (i=0; i<j; i++)
384 {
385 comp=sk_SSL_COMP_value(s->ctx->comp_methods,i);
386 *(p++)=comp->id;
387 }
388 *(p++)=0; /* Add the NULL method */
389
390 l = p-d;
391 *p = 42;
392
393 /* fill in 4-byte handshake header */
394 d=&(buf[5]);
395 *(d++)=SSL3_MT_CLIENT_HELLO;
396 l2n3(l,d);
397
398 l += 4;
399
400 if (l > SSL3_RT_MAX_PLAIN_LENGTH)
401 {
402 SSLerr(SSL_F_SSL23_CLIENT_HELLO,ERR_R_INTERNAL_ERROR);
403 return -1;
404 }
405
406 /* fill in 5-byte record header */
407 d=buf;
408 *(d++) = SSL3_RT_HANDSHAKE;
409 *(d++) = version_major;
410 *(d++) = version_minor; /* arguably we should send the *lowest* suported version here
411 * (indicating, e.g., TLS 1.0 in "SSL 3.0 format") */
412 s2n((int)l,d);
413
414 /* number of bytes to write */
415 s->init_num=p-buf;
416 s->init_off=0;
417
418 ssl3_finish_mac(s,&(buf[5]), s->init_num - 5);
419 }
420
421 s->state=SSL23_ST_CW_CLNT_HELLO_B;
422 s->init_off=0;
423 }
424
425 /* SSL3_ST_CW_CLNT_HELLO_B */
426 ret = ssl23_write_bytes(s);
427
428 if ((ret >= 2) && s->msg_callback)
429 {
430 /* Client Hello has been sent; tell msg_callback */
431
432 if (ssl2_compat)
433 s->msg_callback(1, SSL2_VERSION, 0, s->init_buf->data+2, ret-2, s, s->msg_callback_arg);
434 else
435 s->msg_callback(1, version, SSL3_RT_HANDSHAKE, s->init_buf->data+5, ret-5, s, s->msg_callback_arg);
436 }
437
438 return ret;
439 }
440
441static int ssl23_get_server_hello(SSL *s)
442 {
443 char buf[8];
444 unsigned char *p;
445 int i;
446 int n;
447
448 n=ssl23_read_bytes(s,7);
449
450 if (n != 7) return(n);
451 p=s->packet;
452
453 memcpy(buf,p,n);
454
455 if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) &&
456 (p[5] == 0x00) && (p[6] == 0x02))
457 {
458#ifdef OPENSSL_NO_SSL2
459 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
460 goto err;
461#else
462 /* we are talking sslv2 */
463 /* we need to clean up the SSLv3 setup and put in the
464 * sslv2 stuff. */
465 int ch_len;
466
467 if (s->options & SSL_OP_NO_SSLv2)
468 {
469 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
470 goto err;
471 }
472 if (s->s2 == NULL)
473 {
474 if (!ssl2_new(s))
475 goto err;
476 }
477 else
478 ssl2_clear(s);
479
480 if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
481 ch_len=SSL2_CHALLENGE_LENGTH;
482 else
483 ch_len=SSL2_MAX_CHALLENGE_LENGTH;
484
485 /* write out sslv2 challenge */
486 i=(SSL3_RANDOM_SIZE < ch_len)
487 ?SSL3_RANDOM_SIZE:ch_len;
488 s->s2->challenge_length=i;
489 memcpy(s->s2->challenge,
490 &(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
491
492 if (s->s3 != NULL) ssl3_free(s);
493
494 if (!BUF_MEM_grow_clean(s->init_buf,
495 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
496 {
497 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB);
498 goto err;
499 }
500
501 s->state=SSL2_ST_GET_SERVER_HELLO_A;
502 if (!(s->client_version == SSL2_VERSION))
503 /* use special padding (SSL 3.0 draft/RFC 2246, App. E.2) */
504 s->s2->ssl2_rollback=1;
505
506 /* setup the 5 bytes we have read so we get them from
507 * the sslv2 buffer */
508 s->rstate=SSL_ST_READ_HEADER;
509 s->packet_length=n;
510 s->packet= &(s->s2->rbuf[0]);
511 memcpy(s->packet,buf,n);
512 s->s2->rbuf_left=n;
513 s->s2->rbuf_offs=0;
514
515 /* we have already written one */
516 s->s2->write_sequence=1;
517
518 s->method=SSLv2_client_method();
519 s->handshake_func=s->method->ssl_connect;
520#endif
521 }
522 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
523 (p[1] == SSL3_VERSION_MAJOR) &&
524 ((p[2] == SSL3_VERSION_MINOR) ||
525 (p[2] == TLS1_VERSION_MINOR)) &&
526 (p[5] == SSL3_MT_SERVER_HELLO))
527 {
528 /* we have sslv3 or tls1 */
529
530 if (!ssl_init_wbio_buffer(s,1)) goto err;
531
532 /* we are in this state */
533 s->state=SSL3_ST_CR_SRVR_HELLO_A;
534
535 /* put the 5 bytes we have read into the input buffer
536 * for SSLv3 */
537 s->rstate=SSL_ST_READ_HEADER;
538 s->packet_length=n;
539 s->packet= &(s->s3->rbuf.buf[0]);
540 memcpy(s->packet,buf,n);
541 s->s3->rbuf.left=n;
542 s->s3->rbuf.offset=0;
543
544 if ((p[2] == SSL3_VERSION_MINOR) &&
545 !(s->options & SSL_OP_NO_SSLv3))
546 {
547#ifdef OPENSSL_FIPS
548 if(FIPS_mode())
549 {
550 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,
551 SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
552 goto err;
553 }
554#endif
555 s->version=SSL3_VERSION;
556 s->method=SSLv3_client_method();
557 }
558 else if ((p[2] == TLS1_VERSION_MINOR) &&
559 !(s->options & SSL_OP_NO_TLSv1))
560 {
561 s->version=TLS1_VERSION;
562 s->method=TLSv1_client_method();
563 }
564 else
565 {
566 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
567 goto err;
568 }
569
570 s->handshake_func=s->method->ssl_connect;
571 }
572 else if ((p[0] == SSL3_RT_ALERT) &&
573 (p[1] == SSL3_VERSION_MAJOR) &&
574 ((p[2] == SSL3_VERSION_MINOR) ||
575 (p[2] == TLS1_VERSION_MINOR)) &&
576 (p[3] == 0) &&
577 (p[4] == 2))
578 {
579 void (*cb)(const SSL *ssl,int type,int val)=NULL;
580 int j;
581
582 /* An alert */
583 if (s->info_callback != NULL)
584 cb=s->info_callback;
585 else if (s->ctx->info_callback != NULL)
586 cb=s->ctx->info_callback;
587
588 i=p[5];
589 if (cb != NULL)
590 {
591 j=(i<<8)|p[6];
592 cb(s,SSL_CB_READ_ALERT,j);
593 }
594
595 s->rwstate=SSL_NOTHING;
596 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_AD_REASON_OFFSET+p[6]);
597 goto err;
598 }
599 else
600 {
601 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL);
602 goto err;
603 }
604 s->init_num=0;
605
606 /* Since, if we are sending a ssl23 client hello, we are not
607 * reusing a session-id */
608 if (!ssl_get_new_session(s,0))
609 goto err;
610
611 s->first_packet=1;
612 return(SSL_connect(s));
613err:
614 return(-1);
615 }
616
diff --git a/src/lib/libssl/s23_lib.c b/src/lib/libssl/s23_lib.c
deleted file mode 100644
index 8d7dbcf569..0000000000
--- a/src/lib/libssl/s23_lib.c
+++ /dev/null
@@ -1,236 +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_peek(SSL *s, void *buf, int len);
67static int ssl23_write(SSL *s, const void *buf, int len);
68static long ssl23_default_timeout(void );
69static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
70static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p);
71const char *SSL23_version_str="SSLv2/3 compatibility" OPENSSL_VERSION_PTEXT;
72
73static SSL_METHOD SSLv23_data= {
74 TLS1_VERSION,
75 tls1_new,
76 tls1_clear,
77 tls1_free,
78 ssl_undefined_function,
79 ssl_undefined_function,
80 ssl23_read,
81 ssl23_peek,
82 ssl23_write,
83 ssl_undefined_function,
84 ssl_undefined_function,
85 ssl_ok,
86 ssl3_ctrl,
87 ssl3_ctx_ctrl,
88 ssl23_get_cipher_by_char,
89 ssl23_put_cipher_by_char,
90 ssl_undefined_const_function,
91 ssl23_num_ciphers,
92 ssl23_get_cipher,
93 ssl_bad_method,
94 ssl23_default_timeout,
95 &ssl3_undef_enc_method,
96 ssl_undefined_function,
97 ssl3_callback_ctrl,
98 ssl3_ctx_callback_ctrl,
99 };
100
101static long ssl23_default_timeout(void)
102 {
103 return(300);
104 }
105
106SSL_METHOD *sslv23_base_method(void)
107 {
108 return(&SSLv23_data);
109 }
110
111static int ssl23_num_ciphers(void)
112 {
113 return(ssl3_num_ciphers()
114#ifndef OPENSSL_NO_SSL2
115 + ssl2_num_ciphers()
116#endif
117 );
118 }
119
120static SSL_CIPHER *ssl23_get_cipher(unsigned int u)
121 {
122 unsigned int uu=ssl3_num_ciphers();
123
124 if (u < uu)
125 return(ssl3_get_cipher(u));
126 else
127#ifndef OPENSSL_NO_SSL2
128 return(ssl2_get_cipher(u-uu));
129#else
130 return(NULL);
131#endif
132 }
133
134/* This function needs to check if the ciphers required are actually
135 * available */
136static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
137 {
138 SSL_CIPHER c,*cp;
139 unsigned long id;
140 int n;
141
142 n=ssl3_num_ciphers();
143 id=0x03000000|((unsigned long)p[0]<<16L)|
144 ((unsigned long)p[1]<<8L)|(unsigned long)p[2];
145 c.id=id;
146 cp=ssl3_get_cipher_by_char(p);
147#ifndef OPENSSL_NO_SSL2
148 if (cp == NULL)
149 cp=ssl2_get_cipher_by_char(p);
150#endif
151 return(cp);
152 }
153
154static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
155 {
156 long l;
157
158 /* We can write SSLv2 and SSLv3 ciphers */
159 if (p != NULL)
160 {
161 l=c->id;
162 p[0]=((unsigned char)(l>>16L))&0xFF;
163 p[1]=((unsigned char)(l>> 8L))&0xFF;
164 p[2]=((unsigned char)(l ))&0xFF;
165 }
166 return(3);
167 }
168
169static int ssl23_read(SSL *s, void *buf, int len)
170 {
171 int n;
172
173 clear_sys_error();
174 if (SSL_in_init(s) && (!s->in_handshake))
175 {
176 n=s->handshake_func(s);
177 if (n < 0) return(n);
178 if (n == 0)
179 {
180 SSLerr(SSL_F_SSL23_READ,SSL_R_SSL_HANDSHAKE_FAILURE);
181 return(-1);
182 }
183 return(SSL_read(s,buf,len));
184 }
185 else
186 {
187 ssl_undefined_function(s);
188 return(-1);
189 }
190 }
191
192static int ssl23_peek(SSL *s, void *buf, int len)
193 {
194 int n;
195
196 clear_sys_error();
197 if (SSL_in_init(s) && (!s->in_handshake))
198 {
199 n=s->handshake_func(s);
200 if (n < 0) return(n);
201 if (n == 0)
202 {
203 SSLerr(SSL_F_SSL23_PEEK,SSL_R_SSL_HANDSHAKE_FAILURE);
204 return(-1);
205 }
206 return(SSL_peek(s,buf,len));
207 }
208 else
209 {
210 ssl_undefined_function(s);
211 return(-1);
212 }
213 }
214
215static int ssl23_write(SSL *s, const void *buf, int len)
216 {
217 int n;
218
219 clear_sys_error();
220 if (SSL_in_init(s) && (!s->in_handshake))
221 {
222 n=s->handshake_func(s);
223 if (n < 0) return(n);
224 if (n == 0)
225 {
226 SSLerr(SSL_F_SSL23_WRITE,SSL_R_SSL_HANDSHAKE_FAILURE);
227 return(-1);
228 }
229 return(SSL_write(s,buf,len));
230 }
231 else
232 {
233 ssl_undefined_function(s);
234 return(-1);
235 }
236 }
diff --git a/src/lib/libssl/s23_pkt.c b/src/lib/libssl/s23_pkt.c
deleted file mode 100644
index 4ca6a1b258..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 "ssl_locl.h"
63#include <openssl/evp.h>
64#include <openssl/buffer.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 b73abc448f..0000000000
--- a/src/lib/libssl/s23_srvr.c
+++ /dev/null
@@ -1,600 +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 * Copyright (c) 1998-2001 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 "ssl_locl.h"
114#include <openssl/buffer.h>
115#include <openssl/rand.h>
116#include <openssl/objects.h>
117#include <openssl/evp.h>
118
119static SSL_METHOD *ssl23_get_server_method(int ver);
120int ssl23_get_client_hello(SSL *s);
121static SSL_METHOD *ssl23_get_server_method(int ver)
122 {
123#ifndef OPENSSL_NO_SSL2
124 if (ver == SSL2_VERSION)
125 return(SSLv2_server_method());
126#endif
127 if (ver == SSL3_VERSION)
128 return(SSLv3_server_method());
129 else if (ver == TLS1_VERSION)
130 return(TLSv1_server_method());
131 else
132 return(NULL);
133 }
134
135SSL_METHOD *SSLv23_server_method(void)
136 {
137 static int init=1;
138 static SSL_METHOD SSLv23_server_data;
139
140 if (init)
141 {
142 CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
143
144 if (init)
145 {
146 memcpy((char *)&SSLv23_server_data,
147 (char *)sslv23_base_method(),sizeof(SSL_METHOD));
148 SSLv23_server_data.ssl_accept=ssl23_accept;
149 SSLv23_server_data.get_ssl_method=ssl23_get_server_method;
150 init=0;
151 }
152
153 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
154 }
155 return(&SSLv23_server_data);
156 }
157
158int ssl23_accept(SSL *s)
159 {
160 BUF_MEM *buf;
161 unsigned long Time=(unsigned long)time(NULL);
162 void (*cb)(const SSL *ssl,int type,int val)=NULL;
163 int ret= -1;
164 int new_state,state;
165
166 RAND_add(&Time,sizeof(Time),0);
167 ERR_clear_error();
168 clear_sys_error();
169
170 if (s->info_callback != NULL)
171 cb=s->info_callback;
172 else if (s->ctx->info_callback != NULL)
173 cb=s->ctx->info_callback;
174
175 s->in_handshake++;
176 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
177
178 for (;;)
179 {
180 state=s->state;
181
182 switch(s->state)
183 {
184 case SSL_ST_BEFORE:
185 case SSL_ST_ACCEPT:
186 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
187 case SSL_ST_OK|SSL_ST_ACCEPT:
188
189 s->server=1;
190 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
191
192 /* s->version=SSL3_VERSION; */
193 s->type=SSL_ST_ACCEPT;
194
195 if (s->init_buf == NULL)
196 {
197 if ((buf=BUF_MEM_new()) == NULL)
198 {
199 ret= -1;
200 goto end;
201 }
202 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
203 {
204 ret= -1;
205 goto end;
206 }
207 s->init_buf=buf;
208 }
209
210 ssl3_init_finished_mac(s);
211
212 s->state=SSL23_ST_SR_CLNT_HELLO_A;
213 s->ctx->stats.sess_accept++;
214 s->init_num=0;
215 break;
216
217 case SSL23_ST_SR_CLNT_HELLO_A:
218 case SSL23_ST_SR_CLNT_HELLO_B:
219
220 s->shutdown=0;
221 ret=ssl23_get_client_hello(s);
222 if (ret >= 0) cb=NULL;
223 goto end;
224 /* break; */
225
226 default:
227 SSLerr(SSL_F_SSL23_ACCEPT,SSL_R_UNKNOWN_STATE);
228 ret= -1;
229 goto end;
230 /* break; */
231 }
232
233 if ((cb != NULL) && (s->state != state))
234 {
235 new_state=s->state;
236 s->state=state;
237 cb(s,SSL_CB_ACCEPT_LOOP,1);
238 s->state=new_state;
239 }
240 }
241end:
242 s->in_handshake--;
243 if (cb != NULL)
244 cb(s,SSL_CB_ACCEPT_EXIT,ret);
245 return(ret);
246 }
247
248
249int ssl23_get_client_hello(SSL *s)
250 {
251 char buf_space[11]; /* Request this many bytes in initial read.
252 * We can detect SSL 3.0/TLS 1.0 Client Hellos
253 * ('type == 3') correctly only when the following
254 * is in a single record, which is not guaranteed by
255 * the protocol specification:
256 * Byte Content
257 * 0 type \
258 * 1/2 version > record header
259 * 3/4 length /
260 * 5 msg_type \
261 * 6-8 length > Client Hello message
262 * 9/10 client_version /
263 */
264 char *buf= &(buf_space[0]);
265 unsigned char *p,*d,*d_len,*dd;
266 unsigned int i;
267 unsigned int csl,sil,cl;
268 int n=0,j;
269 int type=0;
270 int v[2];
271
272 if (s->state == SSL23_ST_SR_CLNT_HELLO_A)
273 {
274 /* read the initial header */
275 v[0]=v[1]=0;
276
277 if (!ssl3_setup_buffers(s)) goto err;
278
279 n=ssl23_read_bytes(s, sizeof buf_space);
280 if (n != sizeof buf_space) return(n); /* n == -1 || n == 0 */
281
282 p=s->packet;
283
284 memcpy(buf,p,n);
285
286 if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO))
287 {
288 /*
289 * SSLv2 header
290 */
291 if ((p[3] == 0x00) && (p[4] == 0x02))
292 {
293 v[0]=p[3]; v[1]=p[4];
294 /* SSLv2 */
295 if (!(s->options & SSL_OP_NO_SSLv2))
296 type=1;
297 }
298 else if (p[3] == SSL3_VERSION_MAJOR)
299 {
300 v[0]=p[3]; v[1]=p[4];
301 /* SSLv3/TLSv1 */
302 if (p[4] >= TLS1_VERSION_MINOR)
303 {
304 if (!(s->options & SSL_OP_NO_TLSv1))
305 {
306 s->version=TLS1_VERSION;
307 /* type=2; */ /* done later to survive restarts */
308 s->state=SSL23_ST_SR_CLNT_HELLO_B;
309 }
310 else if (!(s->options & SSL_OP_NO_SSLv3))
311 {
312 s->version=SSL3_VERSION;
313 /* type=2; */
314 s->state=SSL23_ST_SR_CLNT_HELLO_B;
315 }
316 else if (!(s->options & SSL_OP_NO_SSLv2))
317 {
318 type=1;
319 }
320 }
321 else if (!(s->options & SSL_OP_NO_SSLv3))
322 {
323 s->version=SSL3_VERSION;
324 /* type=2; */
325 s->state=SSL23_ST_SR_CLNT_HELLO_B;
326 }
327 else if (!(s->options & SSL_OP_NO_SSLv2))
328 type=1;
329
330 }
331 }
332 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
333 (p[1] == SSL3_VERSION_MAJOR) &&
334 (p[5] == SSL3_MT_CLIENT_HELLO) &&
335 ((p[3] == 0 && p[4] < 5 /* silly record length? */)
336 || (p[9] == p[1])))
337 {
338 /*
339 * SSLv3 or tls1 header
340 */
341
342 v[0]=p[1]; /* major version (= SSL3_VERSION_MAJOR) */
343 /* We must look at client_version inside the Client Hello message
344 * to get the correct minor version.
345 * However if we have only a pathologically small fragment of the
346 * Client Hello message, this would be difficult, and we'd have
347 * to read more records to find out.
348 * No known SSL 3.0 client fragments ClientHello like this,
349 * so we simply assume TLS 1.0 to avoid protocol version downgrade
350 * attacks. */
351 if (p[3] == 0 && p[4] < 6)
352 {
353#if 0
354 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_SMALL);
355 goto err;
356#else
357 v[1] = TLS1_VERSION_MINOR;
358#endif
359 }
360 else
361 v[1]=p[10]; /* minor version according to client_version */
362 if (v[1] >= TLS1_VERSION_MINOR)
363 {
364 if (!(s->options & SSL_OP_NO_TLSv1))
365 {
366 s->version=TLS1_VERSION;
367 type=3;
368 }
369 else if (!(s->options & SSL_OP_NO_SSLv3))
370 {
371 s->version=SSL3_VERSION;
372 type=3;
373 }
374 }
375 else
376 {
377 /* client requests SSL 3.0 */
378 if (!(s->options & SSL_OP_NO_SSLv3))
379 {
380 s->version=SSL3_VERSION;
381 type=3;
382 }
383 else if (!(s->options & SSL_OP_NO_TLSv1))
384 {
385 /* we won't be able to use TLS of course,
386 * but this will send an appropriate alert */
387 s->version=TLS1_VERSION;
388 type=3;
389 }
390 }
391 }
392 else if ((strncmp("GET ", (char *)p,4) == 0) ||
393 (strncmp("POST ",(char *)p,5) == 0) ||
394 (strncmp("HEAD ",(char *)p,5) == 0) ||
395 (strncmp("PUT ", (char *)p,4) == 0))
396 {
397 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST);
398 goto err;
399 }
400 else if (strncmp("CONNECT",(char *)p,7) == 0)
401 {
402 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST);
403 goto err;
404 }
405 }
406
407#ifdef OPENSSL_FIPS
408 if (FIPS_mode() && (s->version < TLS1_VERSION))
409 {
410 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,
411 SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
412 goto err;
413 }
414#endif
415
416 if (s->state == SSL23_ST_SR_CLNT_HELLO_B)
417 {
418 /* we have SSLv3/TLSv1 in an SSLv2 header
419 * (other cases skip this state) */
420
421 type=2;
422 p=s->packet;
423 v[0] = p[3]; /* == SSL3_VERSION_MAJOR */
424 v[1] = p[4];
425
426 n=((p[0]&0x7f)<<8)|p[1];
427 if (n > (1024*4))
428 {
429 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
430 goto err;
431 }
432
433 j=ssl23_read_bytes(s,n+2);
434 if (j <= 0) return(j);
435
436 ssl3_finish_mac(s, s->packet+2, s->packet_length-2);
437 if (s->msg_callback)
438 s->msg_callback(0, SSL2_VERSION, 0, s->packet+2, s->packet_length-2, s, s->msg_callback_arg); /* CLIENT-HELLO */
439
440 p=s->packet;
441 p+=5;
442 n2s(p,csl);
443 n2s(p,sil);
444 n2s(p,cl);
445 d=(unsigned char *)s->init_buf->data;
446 if ((csl+sil+cl+11) != s->packet_length)
447 {
448 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH);
449 goto err;
450 }
451
452 /* record header: msg_type ... */
453 *(d++) = SSL3_MT_CLIENT_HELLO;
454 /* ... and length (actual value will be written later) */
455 d_len = d;
456 d += 3;
457
458 /* client_version */
459 *(d++) = SSL3_VERSION_MAJOR; /* == v[0] */
460 *(d++) = v[1];
461
462 /* lets populate the random area */
463 /* get the challenge_length */
464 i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl;
465 memset(d,0,SSL3_RANDOM_SIZE);
466 memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i);
467 d+=SSL3_RANDOM_SIZE;
468
469 /* no session-id reuse */
470 *(d++)=0;
471
472 /* ciphers */
473 j=0;
474 dd=d;
475 d+=2;
476 for (i=0; i<csl; i+=3)
477 {
478 if (p[i] != 0) continue;
479 *(d++)=p[i+1];
480 *(d++)=p[i+2];
481 j+=2;
482 }
483 s2n(j,dd);
484
485 /* COMPRESSION */
486 *(d++)=1;
487 *(d++)=0;
488
489 i = (d-(unsigned char *)s->init_buf->data) - 4;
490 l2n3((long)i, d_len);
491
492 /* get the data reused from the init_buf */
493 s->s3->tmp.reuse_message=1;
494 s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO;
495 s->s3->tmp.message_size=i;
496 }
497
498 /* imaginary new state (for program structure): */
499 /* s->state = SSL23_SR_CLNT_HELLO_C */
500
501 if (type == 1)
502 {
503#ifdef OPENSSL_NO_SSL2
504 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
505 goto err;
506#else
507 /* we are talking sslv2 */
508 /* we need to clean up the SSLv3/TLSv1 setup and put in the
509 * sslv2 stuff. */
510
511 if (s->s2 == NULL)
512 {
513 if (!ssl2_new(s))
514 goto err;
515 }
516 else
517 ssl2_clear(s);
518
519 if (s->s3 != NULL) ssl3_free(s);
520
521 if (!BUF_MEM_grow_clean(s->init_buf,
522 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
523 {
524 goto err;
525 }
526
527 s->state=SSL2_ST_GET_CLIENT_HELLO_A;
528 if (s->options & SSL_OP_NO_TLSv1 && s->options & SSL_OP_NO_SSLv3)
529 s->s2->ssl2_rollback=0;
530 else
531 /* reject SSL 2.0 session if client supports SSL 3.0 or TLS 1.0
532 * (SSL 3.0 draft/RFC 2246, App. E.2) */
533 s->s2->ssl2_rollback=1;
534
535 /* setup the n bytes we have read so we get them from
536 * the sslv2 buffer */
537 s->rstate=SSL_ST_READ_HEADER;
538 s->packet_length=n;
539 s->packet= &(s->s2->rbuf[0]);
540 memcpy(s->packet,buf,n);
541 s->s2->rbuf_left=n;
542 s->s2->rbuf_offs=0;
543
544 s->method=SSLv2_server_method();
545 s->handshake_func=s->method->ssl_accept;
546#endif
547 }
548
549 if ((type == 2) || (type == 3))
550 {
551 /* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */
552
553 if (!ssl_init_wbio_buffer(s,1)) goto err;
554
555 /* we are in this state */
556 s->state=SSL3_ST_SR_CLNT_HELLO_A;
557
558 if (type == 3)
559 {
560 /* put the 'n' bytes we have read into the input buffer
561 * for SSLv3 */
562 s->rstate=SSL_ST_READ_HEADER;
563 s->packet_length=n;
564 s->packet= &(s->s3->rbuf.buf[0]);
565 memcpy(s->packet,buf,n);
566 s->s3->rbuf.left=n;
567 s->s3->rbuf.offset=0;
568 }
569 else
570 {
571 s->packet_length=0;
572 s->s3->rbuf.left=0;
573 s->s3->rbuf.offset=0;
574 }
575
576 if (s->version == TLS1_VERSION)
577 s->method = TLSv1_server_method();
578 else
579 s->method = SSLv3_server_method();
580#if 0 /* ssl3_get_client_hello does this */
581 s->client_version=(v[0]<<8)|v[1];
582#endif
583 s->handshake_func=s->method->ssl_accept;
584 }
585
586 if ((type < 1) || (type > 3))
587 {
588 /* bad, very bad */
589 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL);
590 goto err;
591 }
592 s->init_num=0;
593
594 if (buf != buf_space) OPENSSL_free(buf);
595 s->first_packet=1;
596 return(SSL_accept(s));
597err:
598 if (buf != buf_space) OPENSSL_free(buf);
599 return(-1);
600 }
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c
deleted file mode 100644
index 64d317b7ac..0000000000
--- a/src/lib/libssl/s3_both.c
+++ /dev/null
@@ -1,635 +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-2002 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 <limits.h>
113#include <string.h>
114#include <stdio.h>
115#include "ssl_locl.h"
116#include <openssl/buffer.h>
117#include <openssl/rand.h>
118#include <openssl/objects.h>
119#include <openssl/evp.h>
120#include <openssl/x509.h>
121
122/* send s->init_buf in records of type 'type' (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC) */
123int ssl3_do_write(SSL *s, int type)
124 {
125 int ret;
126
127 ret=ssl3_write_bytes(s,type,&s->init_buf->data[s->init_off],
128 s->init_num);
129 if (ret < 0) return(-1);
130 if (type == SSL3_RT_HANDSHAKE)
131 /* should not be done for 'Hello Request's, but in that case
132 * we'll ignore the result anyway */
133 ssl3_finish_mac(s,(unsigned char *)&s->init_buf->data[s->init_off],ret);
134
135 if (ret == s->init_num)
136 {
137 if (s->msg_callback)
138 s->msg_callback(1, s->version, type, s->init_buf->data, (size_t)(s->init_off + s->init_num), s, s->msg_callback_arg);
139 return(1);
140 }
141 s->init_off+=ret;
142 s->init_num-=ret;
143 return(0);
144 }
145
146int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen)
147 {
148 unsigned char *p,*d;
149 int i;
150 unsigned long l;
151
152 if (s->state == a)
153 {
154 d=(unsigned char *)s->init_buf->data;
155 p= &(d[4]);
156
157 i=s->method->ssl3_enc->final_finish_mac(s,
158 &(s->s3->finish_dgst1),
159 &(s->s3->finish_dgst2),
160 sender,slen,s->s3->tmp.finish_md);
161 s->s3->tmp.finish_md_len = i;
162 memcpy(p, s->s3->tmp.finish_md, i);
163 p+=i;
164 l=i;
165
166#ifdef OPENSSL_SYS_WIN16
167 /* MSVC 1.5 does not clear the top bytes of the word unless
168 * I do this.
169 */
170 l&=0xffff;
171#endif
172
173 *(d++)=SSL3_MT_FINISHED;
174 l2n3(l,d);
175 s->init_num=(int)l+4;
176 s->init_off=0;
177
178 s->state=b;
179 }
180
181 /* SSL3_ST_SEND_xxxxxx_HELLO_B */
182 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
183 }
184
185int ssl3_get_finished(SSL *s, int a, int b)
186 {
187 int al,i,ok;
188 long n;
189 unsigned char *p;
190
191 /* the mac has already been generated when we received the
192 * change cipher spec message and is in s->s3->tmp.peer_finish_md
193 */
194
195 n=ssl3_get_message(s,
196 a,
197 b,
198 SSL3_MT_FINISHED,
199 64, /* should actually be 36+4 :-) */
200 &ok);
201
202 if (!ok) return((int)n);
203
204 /* If this occurs, we have missed a message */
205 if (!s->s3->change_cipher_spec)
206 {
207 al=SSL_AD_UNEXPECTED_MESSAGE;
208 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS);
209 goto f_err;
210 }
211 s->s3->change_cipher_spec=0;
212
213 p = (unsigned char *)s->init_msg;
214 i = s->s3->tmp.peer_finish_md_len;
215
216 if (i != n)
217 {
218 al=SSL_AD_DECODE_ERROR;
219 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH);
220 goto f_err;
221 }
222
223 if (memcmp(p, s->s3->tmp.peer_finish_md, i) != 0)
224 {
225 al=SSL_AD_DECRYPT_ERROR;
226 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED);
227 goto f_err;
228 }
229
230 return(1);
231f_err:
232 ssl3_send_alert(s,SSL3_AL_FATAL,al);
233 return(0);
234 }
235
236/* for these 2 messages, we need to
237 * ssl->enc_read_ctx re-init
238 * ssl->s3->read_sequence zero
239 * ssl->s3->read_mac_secret re-init
240 * ssl->session->read_sym_enc assign
241 * ssl->session->read_compression assign
242 * ssl->session->read_hash assign
243 */
244int ssl3_send_change_cipher_spec(SSL *s, int a, int b)
245 {
246 unsigned char *p;
247
248 if (s->state == a)
249 {
250 p=(unsigned char *)s->init_buf->data;
251 *p=SSL3_MT_CCS;
252 s->init_num=1;
253 s->init_off=0;
254
255 s->state=b;
256 }
257
258 /* SSL3_ST_CW_CHANGE_B */
259 return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC));
260 }
261
262unsigned long ssl3_output_cert_chain(SSL *s, X509 *x)
263 {
264 unsigned char *p;
265 int n,i;
266 unsigned long l=7;
267 BUF_MEM *buf;
268 X509_STORE_CTX xs_ctx;
269 X509_OBJECT obj;
270
271 int no_chain;
272
273 if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || s->ctx->extra_certs)
274 no_chain = 1;
275 else
276 no_chain = 0;
277
278 /* TLSv1 sends a chain with nothing in it, instead of an alert */
279 buf=s->init_buf;
280 if (!BUF_MEM_grow_clean(buf,10))
281 {
282 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
283 return(0);
284 }
285 if (x != NULL)
286 {
287 if(!no_chain && !X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL))
288 {
289 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB);
290 return(0);
291 }
292
293 for (;;)
294 {
295 n=i2d_X509(x,NULL);
296 if (!BUF_MEM_grow_clean(buf,(int)(n+l+3)))
297 {
298 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
299 return(0);
300 }
301 p=(unsigned char *)&(buf->data[l]);
302 l2n3(n,p);
303 i2d_X509(x,&p);
304 l+=n+3;
305
306 if (no_chain)
307 break;
308
309 if (X509_NAME_cmp(X509_get_subject_name(x),
310 X509_get_issuer_name(x)) == 0) break;
311
312 i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509,
313 X509_get_issuer_name(x),&obj);
314 if (i <= 0) break;
315 x=obj.data.x509;
316 /* Count is one too high since the X509_STORE_get uped the
317 * ref count */
318 X509_free(x);
319 }
320 if (!no_chain)
321 X509_STORE_CTX_cleanup(&xs_ctx);
322 }
323
324 /* Thawte special :-) */
325 if (s->ctx->extra_certs != NULL)
326 for (i=0; i<sk_X509_num(s->ctx->extra_certs); i++)
327 {
328 x=sk_X509_value(s->ctx->extra_certs,i);
329 n=i2d_X509(x,NULL);
330 if (!BUF_MEM_grow_clean(buf,(int)(n+l+3)))
331 {
332 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
333 return(0);
334 }
335 p=(unsigned char *)&(buf->data[l]);
336 l2n3(n,p);
337 i2d_X509(x,&p);
338 l+=n+3;
339 }
340
341 l-=7;
342 p=(unsigned char *)&(buf->data[4]);
343 l2n3(l,p);
344 l+=3;
345 p=(unsigned char *)&(buf->data[0]);
346 *(p++)=SSL3_MT_CERTIFICATE;
347 l2n3(l,p);
348 l+=4;
349 return(l);
350 }
351
352/* Obtain handshake message of message type 'mt' (any if mt == -1),
353 * maximum acceptable body length 'max'.
354 * The first four bytes (msg_type and length) are read in state 'st1',
355 * the body is read in state 'stn'.
356 */
357long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
358 {
359 unsigned char *p;
360 unsigned long l;
361 long n;
362 int i,al;
363
364 if (s->s3->tmp.reuse_message)
365 {
366 s->s3->tmp.reuse_message=0;
367 if ((mt >= 0) && (s->s3->tmp.message_type != mt))
368 {
369 al=SSL_AD_UNEXPECTED_MESSAGE;
370 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
371 goto f_err;
372 }
373 *ok=1;
374 s->init_msg = s->init_buf->data + 4;
375 s->init_num = (int)s->s3->tmp.message_size;
376 return s->init_num;
377 }
378
379 p=(unsigned char *)s->init_buf->data;
380
381 if (s->state == st1) /* s->init_num < 4 */
382 {
383 int skip_message;
384
385 do
386 {
387 while (s->init_num < 4)
388 {
389 i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],
390 4 - s->init_num, 0);
391 if (i <= 0)
392 {
393 s->rwstate=SSL_READING;
394 *ok = 0;
395 return i;
396 }
397 s->init_num+=i;
398 }
399
400 skip_message = 0;
401 if (!s->server)
402 if (p[0] == SSL3_MT_HELLO_REQUEST)
403 /* The server may always send 'Hello Request' messages --
404 * we are doing a handshake anyway now, so ignore them
405 * if their format is correct. Does not count for
406 * 'Finished' MAC. */
407 if (p[1] == 0 && p[2] == 0 &&p[3] == 0)
408 {
409 s->init_num = 0;
410 skip_message = 1;
411
412 if (s->msg_callback)
413 s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, p, 4, s, s->msg_callback_arg);
414 }
415 }
416 while (skip_message);
417
418 /* s->init_num == 4 */
419
420 if ((mt >= 0) && (*p != mt))
421 {
422 al=SSL_AD_UNEXPECTED_MESSAGE;
423 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
424 goto f_err;
425 }
426 if ((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&
427 (st1 == SSL3_ST_SR_CERT_A) &&
428 (stn == SSL3_ST_SR_CERT_B))
429 {
430 /* At this point we have got an MS SGC second client
431 * hello (maybe we should always allow the client to
432 * start a new handshake?). We need to restart the mac.
433 * Don't increment {num,total}_renegotiations because
434 * we have not completed the handshake. */
435 ssl3_init_finished_mac(s);
436 }
437
438 s->s3->tmp.message_type= *(p++);
439
440 n2l3(p,l);
441 if (l > (unsigned long)max)
442 {
443 al=SSL_AD_ILLEGAL_PARAMETER;
444 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);
445 goto f_err;
446 }
447 if (l > (INT_MAX-4)) /* BUF_MEM_grow takes an 'int' parameter */
448 {
449 al=SSL_AD_ILLEGAL_PARAMETER;
450 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);
451 goto f_err;
452 }
453 if (l && !BUF_MEM_grow_clean(s->init_buf,(int)l+4))
454 {
455 SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);
456 goto err;
457 }
458 s->s3->tmp.message_size=l;
459 s->state=stn;
460
461 s->init_msg = s->init_buf->data + 4;
462 s->init_num = 0;
463 }
464
465 /* next state (stn) */
466 p = s->init_msg;
467 n = s->s3->tmp.message_size - s->init_num;
468 while (n > 0)
469 {
470 i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0);
471 if (i <= 0)
472 {
473 s->rwstate=SSL_READING;
474 *ok = 0;
475 return i;
476 }
477 s->init_num += i;
478 n -= i;
479 }
480 ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num + 4);
481 if (s->msg_callback)
482 s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, s->init_buf->data, (size_t)s->init_num + 4, s, s->msg_callback_arg);
483 *ok=1;
484 return s->init_num;
485f_err:
486 ssl3_send_alert(s,SSL3_AL_FATAL,al);
487err:
488 *ok=0;
489 return(-1);
490 }
491
492int ssl_cert_type(X509 *x, EVP_PKEY *pkey)
493 {
494 EVP_PKEY *pk;
495 int ret= -1,i,j;
496
497 if (pkey == NULL)
498 pk=X509_get_pubkey(x);
499 else
500 pk=pkey;
501 if (pk == NULL) goto err;
502
503 i=pk->type;
504 if (i == EVP_PKEY_RSA)
505 {
506 ret=SSL_PKEY_RSA_ENC;
507 if (x != NULL)
508 {
509 j=X509_get_ext_count(x);
510 /* check to see if this is a signing only certificate */
511 /* EAY EAY EAY EAY */
512 }
513 }
514 else if (i == EVP_PKEY_DSA)
515 {
516 ret=SSL_PKEY_DSA_SIGN;
517 }
518 else if (i == EVP_PKEY_DH)
519 {
520 /* if we just have a key, we needs to be guess */
521
522 if (x == NULL)
523 ret=SSL_PKEY_DH_DSA;
524 else
525 {
526 j=X509_get_signature_type(x);
527 if (j == EVP_PKEY_RSA)
528 ret=SSL_PKEY_DH_RSA;
529 else if (j== EVP_PKEY_DSA)
530 ret=SSL_PKEY_DH_DSA;
531 else ret= -1;
532 }
533 }
534 else
535 ret= -1;
536
537err:
538 if(!pkey) EVP_PKEY_free(pk);
539 return(ret);
540 }
541
542int ssl_verify_alarm_type(long type)
543 {
544 int al;
545
546 switch(type)
547 {
548 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
549 case X509_V_ERR_UNABLE_TO_GET_CRL:
550 case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
551 al=SSL_AD_UNKNOWN_CA;
552 break;
553 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
554 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
555 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
556 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
557 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
558 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
559 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
560 case X509_V_ERR_CERT_NOT_YET_VALID:
561 case X509_V_ERR_CRL_NOT_YET_VALID:
562 case X509_V_ERR_CERT_UNTRUSTED:
563 case X509_V_ERR_CERT_REJECTED:
564 al=SSL_AD_BAD_CERTIFICATE;
565 break;
566 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
567 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
568 al=SSL_AD_DECRYPT_ERROR;
569 break;
570 case X509_V_ERR_CERT_HAS_EXPIRED:
571 case X509_V_ERR_CRL_HAS_EXPIRED:
572 al=SSL_AD_CERTIFICATE_EXPIRED;
573 break;
574 case X509_V_ERR_CERT_REVOKED:
575 al=SSL_AD_CERTIFICATE_REVOKED;
576 break;
577 case X509_V_ERR_OUT_OF_MEM:
578 al=SSL_AD_INTERNAL_ERROR;
579 break;
580 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
581 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
582 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
583 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
584 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
585 case X509_V_ERR_PATH_LENGTH_EXCEEDED:
586 case X509_V_ERR_INVALID_CA:
587 al=SSL_AD_UNKNOWN_CA;
588 break;
589 case X509_V_ERR_APPLICATION_VERIFICATION:
590 al=SSL_AD_HANDSHAKE_FAILURE;
591 break;
592 case X509_V_ERR_INVALID_PURPOSE:
593 al=SSL_AD_UNSUPPORTED_CERTIFICATE;
594 break;
595 default:
596 al=SSL_AD_CERTIFICATE_UNKNOWN;
597 break;
598 }
599 return(al);
600 }
601
602int ssl3_setup_buffers(SSL *s)
603 {
604 unsigned char *p;
605 unsigned int extra;
606 size_t len;
607
608 if (s->s3->rbuf.buf == NULL)
609 {
610 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
611 extra=SSL3_RT_MAX_EXTRA;
612 else
613 extra=0;
614 len = SSL3_RT_MAX_PACKET_SIZE + extra;
615 if ((p=OPENSSL_malloc(len)) == NULL)
616 goto err;
617 s->s3->rbuf.buf = p;
618 s->s3->rbuf.len = len;
619 }
620
621 if (s->s3->wbuf.buf == NULL)
622 {
623 len = SSL3_RT_MAX_PACKET_SIZE;
624 len += SSL3_RT_HEADER_LENGTH + 256; /* extra space for empty fragment */
625 if ((p=OPENSSL_malloc(len)) == NULL)
626 goto err;
627 s->s3->wbuf.buf = p;
628 s->s3->wbuf.len = len;
629 }
630 s->packet= &(s->s3->rbuf.buf[0]);
631 return(1);
632err:
633 SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE);
634 return(0);
635 }
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c
deleted file mode 100644
index 4163d97944..0000000000
--- a/src/lib/libssl/s3_clnt.c
+++ /dev/null
@@ -1,1985 +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 * Copyright (c) 1998-2002 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 "ssl_locl.h"
114#include "kssl_lcl.h"
115#include <openssl/buffer.h>
116#include <openssl/rand.h>
117#include <openssl/objects.h>
118#include <openssl/evp.h>
119#include <openssl/md5.h>
120#include <openssl/fips.h>
121
122static SSL_METHOD *ssl3_get_client_method(int ver);
123static int ssl3_client_hello(SSL *s);
124static int ssl3_get_server_hello(SSL *s);
125static int ssl3_get_certificate_request(SSL *s);
126static int ca_dn_cmp(const X509_NAME * const *a,const X509_NAME * const *b);
127static int ssl3_get_server_done(SSL *s);
128static int ssl3_send_client_verify(SSL *s);
129static int ssl3_send_client_certificate(SSL *s);
130static int ssl3_send_client_key_exchange(SSL *s);
131static int ssl3_get_key_exchange(SSL *s);
132static int ssl3_get_server_certificate(SSL *s);
133static int ssl3_check_cert_and_algorithm(SSL *s);
134static SSL_METHOD *ssl3_get_client_method(int ver)
135 {
136 if (ver == SSL3_VERSION)
137 return(SSLv3_client_method());
138 else
139 return(NULL);
140 }
141
142SSL_METHOD *SSLv3_client_method(void)
143 {
144 static int init=1;
145 static SSL_METHOD SSLv3_client_data;
146
147 if (init)
148 {
149 CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
150
151 if (init)
152 {
153 memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(),
154 sizeof(SSL_METHOD));
155 SSLv3_client_data.ssl_connect=ssl3_connect;
156 SSLv3_client_data.get_ssl_method=ssl3_get_client_method;
157 init=0;
158 }
159
160 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
161 }
162 return(&SSLv3_client_data);
163 }
164
165int ssl3_connect(SSL *s)
166 {
167 BUF_MEM *buf=NULL;
168 unsigned long Time=(unsigned long)time(NULL),l;
169 long num1;
170 void (*cb)(const SSL *ssl,int type,int val)=NULL;
171 int ret= -1;
172 int new_state,state,skip=0;
173
174 RAND_add(&Time,sizeof(Time),0);
175 ERR_clear_error();
176 clear_sys_error();
177
178 if (s->info_callback != NULL)
179 cb=s->info_callback;
180 else if (s->ctx->info_callback != NULL)
181 cb=s->ctx->info_callback;
182
183 s->in_handshake++;
184 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
185
186 for (;;)
187 {
188 state=s->state;
189
190 switch(s->state)
191 {
192 case SSL_ST_RENEGOTIATE:
193 s->new_session=1;
194 s->state=SSL_ST_CONNECT;
195 s->ctx->stats.sess_connect_renegotiate++;
196 /* break */
197 case SSL_ST_BEFORE:
198 case SSL_ST_CONNECT:
199 case SSL_ST_BEFORE|SSL_ST_CONNECT:
200 case SSL_ST_OK|SSL_ST_CONNECT:
201
202 s->server=0;
203 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
204
205 if ((s->version & 0xff00 ) != 0x0300)
206 {
207 SSLerr(SSL_F_SSL3_CONNECT, ERR_R_INTERNAL_ERROR);
208 ret = -1;
209 goto end;
210 }
211
212 /* s->version=SSL3_VERSION; */
213 s->type=SSL_ST_CONNECT;
214
215 if (s->init_buf == NULL)
216 {
217 if ((buf=BUF_MEM_new()) == NULL)
218 {
219 ret= -1;
220 goto end;
221 }
222 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
223 {
224 ret= -1;
225 goto end;
226 }
227 s->init_buf=buf;
228 buf=NULL;
229 }
230
231 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
232
233 /* setup buffing BIO */
234 if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }
235
236 /* don't push the buffering BIO quite yet */
237
238 ssl3_init_finished_mac(s);
239
240 s->state=SSL3_ST_CW_CLNT_HELLO_A;
241 s->ctx->stats.sess_connect++;
242 s->init_num=0;
243 break;
244
245 case SSL3_ST_CW_CLNT_HELLO_A:
246 case SSL3_ST_CW_CLNT_HELLO_B:
247
248 s->shutdown=0;
249 ret=ssl3_client_hello(s);
250 if (ret <= 0) goto end;
251 s->state=SSL3_ST_CR_SRVR_HELLO_A;
252 s->init_num=0;
253
254 /* turn on buffering for the next lot of output */
255 if (s->bbio != s->wbio)
256 s->wbio=BIO_push(s->bbio,s->wbio);
257
258 break;
259
260 case SSL3_ST_CR_SRVR_HELLO_A:
261 case SSL3_ST_CR_SRVR_HELLO_B:
262 ret=ssl3_get_server_hello(s);
263 if (ret <= 0) goto end;
264 if (s->hit)
265 s->state=SSL3_ST_CR_FINISHED_A;
266 else
267 s->state=SSL3_ST_CR_CERT_A;
268 s->init_num=0;
269 break;
270
271 case SSL3_ST_CR_CERT_A:
272 case SSL3_ST_CR_CERT_B:
273 /* Check if it is anon DH */
274 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
275 {
276 ret=ssl3_get_server_certificate(s);
277 if (ret <= 0) goto end;
278 }
279 else
280 skip=1;
281 s->state=SSL3_ST_CR_KEY_EXCH_A;
282 s->init_num=0;
283 break;
284
285 case SSL3_ST_CR_KEY_EXCH_A:
286 case SSL3_ST_CR_KEY_EXCH_B:
287 ret=ssl3_get_key_exchange(s);
288 if (ret <= 0) goto end;
289 s->state=SSL3_ST_CR_CERT_REQ_A;
290 s->init_num=0;
291
292 /* at this point we check that we have the
293 * required stuff from the server */
294 if (!ssl3_check_cert_and_algorithm(s))
295 {
296 ret= -1;
297 goto end;
298 }
299 break;
300
301 case SSL3_ST_CR_CERT_REQ_A:
302 case SSL3_ST_CR_CERT_REQ_B:
303 ret=ssl3_get_certificate_request(s);
304 if (ret <= 0) goto end;
305 s->state=SSL3_ST_CR_SRVR_DONE_A;
306 s->init_num=0;
307 break;
308
309 case SSL3_ST_CR_SRVR_DONE_A:
310 case SSL3_ST_CR_SRVR_DONE_B:
311 ret=ssl3_get_server_done(s);
312 if (ret <= 0) goto end;
313 if (s->s3->tmp.cert_req)
314 s->state=SSL3_ST_CW_CERT_A;
315 else
316 s->state=SSL3_ST_CW_KEY_EXCH_A;
317 s->init_num=0;
318
319 break;
320
321 case SSL3_ST_CW_CERT_A:
322 case SSL3_ST_CW_CERT_B:
323 case SSL3_ST_CW_CERT_C:
324 case SSL3_ST_CW_CERT_D:
325 ret=ssl3_send_client_certificate(s);
326 if (ret <= 0) goto end;
327 s->state=SSL3_ST_CW_KEY_EXCH_A;
328 s->init_num=0;
329 break;
330
331 case SSL3_ST_CW_KEY_EXCH_A:
332 case SSL3_ST_CW_KEY_EXCH_B:
333 ret=ssl3_send_client_key_exchange(s);
334 if (ret <= 0) goto end;
335 l=s->s3->tmp.new_cipher->algorithms;
336 /* EAY EAY EAY need to check for DH fix cert
337 * sent back */
338 /* For TLS, cert_req is set to 2, so a cert chain
339 * of nothing is sent, but no verify packet is sent */
340 if (s->s3->tmp.cert_req == 1)
341 {
342 s->state=SSL3_ST_CW_CERT_VRFY_A;
343 }
344 else
345 {
346 s->state=SSL3_ST_CW_CHANGE_A;
347 s->s3->change_cipher_spec=0;
348 }
349
350 s->init_num=0;
351 break;
352
353 case SSL3_ST_CW_CERT_VRFY_A:
354 case SSL3_ST_CW_CERT_VRFY_B:
355 ret=ssl3_send_client_verify(s);
356 if (ret <= 0) goto end;
357 s->state=SSL3_ST_CW_CHANGE_A;
358 s->init_num=0;
359 s->s3->change_cipher_spec=0;
360 break;
361
362 case SSL3_ST_CW_CHANGE_A:
363 case SSL3_ST_CW_CHANGE_B:
364 ret=ssl3_send_change_cipher_spec(s,
365 SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
366 if (ret <= 0) goto end;
367 s->state=SSL3_ST_CW_FINISHED_A;
368 s->init_num=0;
369
370 s->session->cipher=s->s3->tmp.new_cipher;
371 if (s->s3->tmp.new_compression == NULL)
372 s->session->compress_meth=0;
373 else
374 s->session->compress_meth=
375 s->s3->tmp.new_compression->id;
376 if (!s->method->ssl3_enc->setup_key_block(s))
377 {
378 ret= -1;
379 goto end;
380 }
381
382 if (!s->method->ssl3_enc->change_cipher_state(s,
383 SSL3_CHANGE_CIPHER_CLIENT_WRITE))
384 {
385 ret= -1;
386 goto end;
387 }
388
389 break;
390
391 case SSL3_ST_CW_FINISHED_A:
392 case SSL3_ST_CW_FINISHED_B:
393 ret=ssl3_send_finished(s,
394 SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
395 s->method->ssl3_enc->client_finished_label,
396 s->method->ssl3_enc->client_finished_label_len);
397 if (ret <= 0) goto end;
398 s->state=SSL3_ST_CW_FLUSH;
399
400 /* clear flags */
401 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
402 if (s->hit)
403 {
404 s->s3->tmp.next_state=SSL_ST_OK;
405 if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
406 {
407 s->state=SSL_ST_OK;
408 s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
409 s->s3->delay_buf_pop_ret=0;
410 }
411 }
412 else
413 {
414 s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
415 }
416 s->init_num=0;
417 break;
418
419 case SSL3_ST_CR_FINISHED_A:
420 case SSL3_ST_CR_FINISHED_B:
421
422 ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
423 SSL3_ST_CR_FINISHED_B);
424 if (ret <= 0) goto end;
425
426 if (s->hit)
427 s->state=SSL3_ST_CW_CHANGE_A;
428 else
429 s->state=SSL_ST_OK;
430 s->init_num=0;
431 break;
432
433 case SSL3_ST_CW_FLUSH:
434 /* number of bytes to be flushed */
435 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
436 if (num1 > 0)
437 {
438 s->rwstate=SSL_WRITING;
439 num1=BIO_flush(s->wbio);
440 if (num1 <= 0) { ret= -1; goto end; }
441 s->rwstate=SSL_NOTHING;
442 }
443
444 s->state=s->s3->tmp.next_state;
445 break;
446
447 case SSL_ST_OK:
448 /* clean a few things up */
449 ssl3_cleanup_key_block(s);
450
451 if (s->init_buf != NULL)
452 {
453 BUF_MEM_free(s->init_buf);
454 s->init_buf=NULL;
455 }
456
457 /* If we are not 'joining' the last two packets,
458 * remove the buffering now */
459 if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
460 ssl_free_wbio_buffer(s);
461 /* else do it later in ssl3_write */
462
463 s->init_num=0;
464 s->new_session=0;
465
466 ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
467 if (s->hit) s->ctx->stats.sess_hit++;
468
469 ret=1;
470 /* s->server=0; */
471 s->handshake_func=ssl3_connect;
472 s->ctx->stats.sess_connect_good++;
473
474 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
475
476 goto end;
477 /* break; */
478
479 default:
480 SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE);
481 ret= -1;
482 goto end;
483 /* break; */
484 }
485
486 /* did we do anything */
487 if (!s->s3->tmp.reuse_message && !skip)
488 {
489 if (s->debug)
490 {
491 if ((ret=BIO_flush(s->wbio)) <= 0)
492 goto end;
493 }
494
495 if ((cb != NULL) && (s->state != state))
496 {
497 new_state=s->state;
498 s->state=state;
499 cb(s,SSL_CB_CONNECT_LOOP,1);
500 s->state=new_state;
501 }
502 }
503 skip=0;
504 }
505end:
506 s->in_handshake--;
507 if (buf != NULL)
508 BUF_MEM_free(buf);
509 if (cb != NULL)
510 cb(s,SSL_CB_CONNECT_EXIT,ret);
511 return(ret);
512 }
513
514
515static int ssl3_client_hello(SSL *s)
516 {
517 unsigned char *buf;
518 unsigned char *p,*d;
519 int i,j;
520 unsigned long Time,l;
521 SSL_COMP *comp;
522
523 buf=(unsigned char *)s->init_buf->data;
524 if (s->state == SSL3_ST_CW_CLNT_HELLO_A)
525 {
526 if ((s->session == NULL) ||
527 (s->session->ssl_version != s->version) ||
528 (s->session->not_resumable))
529 {
530 if (!ssl_get_new_session(s,0))
531 goto err;
532 }
533 /* else use the pre-loaded session */
534
535 p=s->s3->client_random;
536 Time=(unsigned long)time(NULL); /* Time */
537 l2n(Time,p);
538 if(RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
539 goto err;
540
541 /* Do the message type and length last */
542 d=p= &(buf[4]);
543
544 *(p++)=s->version>>8;
545 *(p++)=s->version&0xff;
546 s->client_version=s->version;
547
548 /* Random stuff */
549 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
550 p+=SSL3_RANDOM_SIZE;
551
552 /* Session ID */
553 if (s->new_session)
554 i=0;
555 else
556 i=s->session->session_id_length;
557 *(p++)=i;
558 if (i != 0)
559 {
560 if (i > sizeof s->session->session_id)
561 {
562 SSLerr(SSL_F_SSL3_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
563 goto err;
564 }
565 memcpy(p,s->session->session_id,i);
566 p+=i;
567 }
568
569 /* Ciphers supported */
570 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]),0);
571 if (i == 0)
572 {
573 SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
574 goto err;
575 }
576 s2n(i,p);
577 p+=i;
578
579 /* COMPRESSION */
580 if (s->ctx->comp_methods == NULL)
581 j=0;
582 else
583 j=sk_SSL_COMP_num(s->ctx->comp_methods);
584 *(p++)=1+j;
585 for (i=0; i<j; i++)
586 {
587 comp=sk_SSL_COMP_value(s->ctx->comp_methods,i);
588 *(p++)=comp->id;
589 }
590 *(p++)=0; /* Add the NULL method */
591
592 l=(p-d);
593 d=buf;
594 *(d++)=SSL3_MT_CLIENT_HELLO;
595 l2n3(l,d);
596
597 s->state=SSL3_ST_CW_CLNT_HELLO_B;
598 /* number of bytes to write */
599 s->init_num=p-buf;
600 s->init_off=0;
601 }
602
603 /* SSL3_ST_CW_CLNT_HELLO_B */
604 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
605err:
606 return(-1);
607 }
608
609static int ssl3_get_server_hello(SSL *s)
610 {
611 STACK_OF(SSL_CIPHER) *sk;
612 SSL_CIPHER *c;
613 unsigned char *p,*d;
614 int i,al,ok;
615 unsigned int j;
616 long n;
617 SSL_COMP *comp;
618
619 n=ssl3_get_message(s,
620 SSL3_ST_CR_SRVR_HELLO_A,
621 SSL3_ST_CR_SRVR_HELLO_B,
622 SSL3_MT_SERVER_HELLO,
623 300, /* ?? */
624 &ok);
625
626 if (!ok) return((int)n);
627 d=p=(unsigned char *)s->init_msg;
628
629 if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff)))
630 {
631 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION);
632 s->version=(s->version&0xff00)|p[1];
633 al=SSL_AD_PROTOCOL_VERSION;
634 goto f_err;
635 }
636 p+=2;
637
638 /* load the server hello data */
639 /* load the server random */
640 memcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE);
641 p+=SSL3_RANDOM_SIZE;
642
643 /* get the session-id */
644 j= *(p++);
645
646 if ((j > sizeof s->session->session_id) || (j > SSL3_SESSION_ID_SIZE))
647 {
648 al=SSL_AD_ILLEGAL_PARAMETER;
649 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_LONG);
650 goto f_err;
651 }
652
653 if (j != 0 && j == s->session->session_id_length
654 && memcmp(p,s->session->session_id,j) == 0)
655 {
656 if(s->sid_ctx_length != s->session->sid_ctx_length
657 || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length))
658 {
659 /* actually a client application bug */
660 al=SSL_AD_ILLEGAL_PARAMETER;
661 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
662 goto f_err;
663 }
664 s->hit=1;
665 }
666 else /* a miss or crap from the other end */
667 {
668 /* If we were trying for session-id reuse, make a new
669 * SSL_SESSION so we don't stuff up other people */
670 s->hit=0;
671 if (s->session->session_id_length > 0)
672 {
673 if (!ssl_get_new_session(s,0))
674 {
675 al=SSL_AD_INTERNAL_ERROR;
676 goto f_err;
677 }
678 }
679 s->session->session_id_length=j;
680 memcpy(s->session->session_id,p,j); /* j could be 0 */
681 }
682 p+=j;
683 c=ssl_get_cipher_by_char(s,p);
684 if (c == NULL)
685 {
686 /* unknown cipher */
687 al=SSL_AD_ILLEGAL_PARAMETER;
688 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED);
689 goto f_err;
690 }
691 p+=ssl_put_cipher_by_char(s,NULL,NULL);
692
693 sk=ssl_get_ciphers_by_id(s);
694 i=sk_SSL_CIPHER_find(sk,c);
695 if (i < 0)
696 {
697 /* we did not say we would use this cipher */
698 al=SSL_AD_ILLEGAL_PARAMETER;
699 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED);
700 goto f_err;
701 }
702
703 /* Depending on the session caching (internal/external), the cipher
704 and/or cipher_id values may not be set. Make sure that
705 cipher_id is set and use it for comparison. */
706 if (s->session->cipher)
707 s->session->cipher_id = s->session->cipher->id;
708 if (s->hit && (s->session->cipher_id != c->id))
709 {
710 if (!(s->options &
711 SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG))
712 {
713 al=SSL_AD_ILLEGAL_PARAMETER;
714 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
715 goto f_err;
716 }
717 }
718 s->s3->tmp.new_cipher=c;
719
720 /* lets get the compression algorithm */
721 /* COMPRESSION */
722 j= *(p++);
723 if (j == 0)
724 comp=NULL;
725 else
726 comp=ssl3_comp_find(s->ctx->comp_methods,j);
727
728 if ((j != 0) && (comp == NULL))
729 {
730 al=SSL_AD_ILLEGAL_PARAMETER;
731 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
732 goto f_err;
733 }
734 else
735 {
736 s->s3->tmp.new_compression=comp;
737 }
738
739 if (p != (d+n))
740 {
741 /* wrong packet length */
742 al=SSL_AD_DECODE_ERROR;
743 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH);
744 goto err;
745 }
746
747 return(1);
748f_err:
749 ssl3_send_alert(s,SSL3_AL_FATAL,al);
750err:
751 return(-1);
752 }
753
754static int ssl3_get_server_certificate(SSL *s)
755 {
756 int al,i,ok,ret= -1;
757 unsigned long n,nc,llen,l;
758 X509 *x=NULL;
759 unsigned char *p,*d,*q;
760 STACK_OF(X509) *sk=NULL;
761 SESS_CERT *sc;
762 EVP_PKEY *pkey=NULL;
763 int need_cert = 1; /* VRS: 0=> will allow null cert if auth == KRB5 */
764
765 n=ssl3_get_message(s,
766 SSL3_ST_CR_CERT_A,
767 SSL3_ST_CR_CERT_B,
768 -1,
769 s->max_cert_list,
770 &ok);
771
772 if (!ok) return((int)n);
773
774 if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE)
775 {
776 s->s3->tmp.reuse_message=1;
777 return(1);
778 }
779
780 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
781 {
782 al=SSL_AD_UNEXPECTED_MESSAGE;
783 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE);
784 goto f_err;
785 }
786 d=p=(unsigned char *)s->init_msg;
787
788 if ((sk=sk_X509_new_null()) == NULL)
789 {
790 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
791 goto err;
792 }
793
794 n2l3(p,llen);
795 if (llen+3 != n)
796 {
797 al=SSL_AD_DECODE_ERROR;
798 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
799 goto f_err;
800 }
801 for (nc=0; nc<llen; )
802 {
803 n2l3(p,l);
804 if ((l+nc+3) > llen)
805 {
806 al=SSL_AD_DECODE_ERROR;
807 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
808 goto f_err;
809 }
810
811 q=p;
812 x=d2i_X509(NULL,&q,l);
813 if (x == NULL)
814 {
815 al=SSL_AD_BAD_CERTIFICATE;
816 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB);
817 goto f_err;
818 }
819 if (q != (p+l))
820 {
821 al=SSL_AD_DECODE_ERROR;
822 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
823 goto f_err;
824 }
825 if (!sk_X509_push(sk,x))
826 {
827 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
828 goto err;
829 }
830 x=NULL;
831 nc+=l+3;
832 p=q;
833 }
834
835 i=ssl_verify_cert_chain(s,sk);
836 if ((s->verify_mode != SSL_VERIFY_NONE) && (!i)
837#ifndef OPENSSL_NO_KRB5
838 && (s->s3->tmp.new_cipher->algorithms & (SSL_MKEY_MASK|SSL_AUTH_MASK))
839 != (SSL_aKRB5|SSL_kKRB5)
840#endif /* OPENSSL_NO_KRB5 */
841 )
842 {
843 al=ssl_verify_alarm_type(s->verify_result);
844 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
845 goto f_err;
846 }
847 ERR_clear_error(); /* but we keep s->verify_result */
848
849 sc=ssl_sess_cert_new();
850 if (sc == NULL) goto err;
851
852 if (s->session->sess_cert) ssl_sess_cert_free(s->session->sess_cert);
853 s->session->sess_cert=sc;
854
855 sc->cert_chain=sk;
856 /* Inconsistency alert: cert_chain does include the peer's
857 * certificate, which we don't include in s3_srvr.c */
858 x=sk_X509_value(sk,0);
859 sk=NULL;
860 /* VRS 19990621: possible memory leak; sk=null ==> !sk_pop_free() @end*/
861
862 pkey=X509_get_pubkey(x);
863
864 /* VRS: allow null cert if auth == KRB5 */
865 need_cert = ((s->s3->tmp.new_cipher->algorithms
866 & (SSL_MKEY_MASK|SSL_AUTH_MASK))
867 == (SSL_aKRB5|SSL_kKRB5))? 0: 1;
868
869#ifdef KSSL_DEBUG
870 printf("pkey,x = %p, %p\n", pkey,x);
871 printf("ssl_cert_type(x,pkey) = %d\n", ssl_cert_type(x,pkey));
872 printf("cipher, alg, nc = %s, %lx, %d\n", s->s3->tmp.new_cipher->name,
873 s->s3->tmp.new_cipher->algorithms, need_cert);
874#endif /* KSSL_DEBUG */
875
876 if (need_cert && ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey)))
877 {
878 x=NULL;
879 al=SSL3_AL_FATAL;
880 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,
881 SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS);
882 goto f_err;
883 }
884
885 i=ssl_cert_type(x,pkey);
886 if (need_cert && i < 0)
887 {
888 x=NULL;
889 al=SSL3_AL_FATAL;
890 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,
891 SSL_R_UNKNOWN_CERTIFICATE_TYPE);
892 goto f_err;
893 }
894
895 if (need_cert)
896 {
897 sc->peer_cert_type=i;
898 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
899 /* Why would the following ever happen?
900 * We just created sc a couple of lines ago. */
901 if (sc->peer_pkeys[i].x509 != NULL)
902 X509_free(sc->peer_pkeys[i].x509);
903 sc->peer_pkeys[i].x509=x;
904 sc->peer_key= &(sc->peer_pkeys[i]);
905
906 if (s->session->peer != NULL)
907 X509_free(s->session->peer);
908 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
909 s->session->peer=x;
910 }
911 else
912 {
913 sc->peer_cert_type=i;
914 sc->peer_key= NULL;
915
916 if (s->session->peer != NULL)
917 X509_free(s->session->peer);
918 s->session->peer=NULL;
919 }
920 s->session->verify_result = s->verify_result;
921
922 x=NULL;
923 ret=1;
924
925 if (0)
926 {
927f_err:
928 ssl3_send_alert(s,SSL3_AL_FATAL,al);
929 }
930err:
931 EVP_PKEY_free(pkey);
932 X509_free(x);
933 sk_X509_pop_free(sk,X509_free);
934 return(ret);
935 }
936
937static int ssl3_get_key_exchange(SSL *s)
938 {
939#ifndef OPENSSL_NO_RSA
940 unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];
941#endif
942 EVP_MD_CTX md_ctx;
943 unsigned char *param,*p;
944 int al,i,j,param_len,ok;
945 long n,alg;
946 EVP_PKEY *pkey=NULL;
947#ifndef OPENSSL_NO_RSA
948 RSA *rsa=NULL;
949#endif
950#ifndef OPENSSL_NO_DH
951 DH *dh=NULL;
952#endif
953
954 /* use same message size as in ssl3_get_certificate_request()
955 * as ServerKeyExchange message may be skipped */
956 n=ssl3_get_message(s,
957 SSL3_ST_CR_KEY_EXCH_A,
958 SSL3_ST_CR_KEY_EXCH_B,
959 -1,
960 s->max_cert_list,
961 &ok);
962
963 if (!ok) return((int)n);
964
965 if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)
966 {
967 s->s3->tmp.reuse_message=1;
968 return(1);
969 }
970
971 param=p=(unsigned char *)s->init_msg;
972
973 if (s->session->sess_cert != NULL)
974 {
975#ifndef OPENSSL_NO_RSA
976 if (s->session->sess_cert->peer_rsa_tmp != NULL)
977 {
978 RSA_free(s->session->sess_cert->peer_rsa_tmp);
979 s->session->sess_cert->peer_rsa_tmp=NULL;
980 }
981#endif
982#ifndef OPENSSL_NO_DH
983 if (s->session->sess_cert->peer_dh_tmp)
984 {
985 DH_free(s->session->sess_cert->peer_dh_tmp);
986 s->session->sess_cert->peer_dh_tmp=NULL;
987 }
988#endif
989 }
990 else
991 {
992 s->session->sess_cert=ssl_sess_cert_new();
993 }
994
995 param_len=0;
996 alg=s->s3->tmp.new_cipher->algorithms;
997 EVP_MD_CTX_init(&md_ctx);
998
999#ifndef OPENSSL_NO_RSA
1000 if (alg & SSL_kRSA)
1001 {
1002 if ((rsa=RSA_new()) == NULL)
1003 {
1004 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
1005 goto err;
1006 }
1007 n2s(p,i);
1008 param_len=i+2;
1009 if (param_len > n)
1010 {
1011 al=SSL_AD_DECODE_ERROR;
1012 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);
1013 goto f_err;
1014 }
1015 if (!(rsa->n=BN_bin2bn(p,i,rsa->n)))
1016 {
1017 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
1018 goto err;
1019 }
1020 p+=i;
1021
1022 n2s(p,i);
1023 param_len+=i+2;
1024 if (param_len > n)
1025 {
1026 al=SSL_AD_DECODE_ERROR;
1027 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);
1028 goto f_err;
1029 }
1030 if (!(rsa->e=BN_bin2bn(p,i,rsa->e)))
1031 {
1032 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
1033 goto err;
1034 }
1035 p+=i;
1036 n-=param_len;
1037
1038 /* this should be because we are using an export cipher */
1039 if (alg & SSL_aRSA)
1040 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
1041 else
1042 {
1043 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);
1044 goto err;
1045 }
1046 s->session->sess_cert->peer_rsa_tmp=rsa;
1047 rsa=NULL;
1048 }
1049#else /* OPENSSL_NO_RSA */
1050 if (0)
1051 ;
1052#endif
1053#ifndef OPENSSL_NO_DH
1054 else if (alg & SSL_kEDH)
1055 {
1056 if ((dh=DH_new()) == NULL)
1057 {
1058 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB);
1059 goto err;
1060 }
1061 n2s(p,i);
1062 param_len=i+2;
1063 if (param_len > n)
1064 {
1065 al=SSL_AD_DECODE_ERROR;
1066 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH);
1067 goto f_err;
1068 }
1069 if (!(dh->p=BN_bin2bn(p,i,NULL)))
1070 {
1071 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
1072 goto err;
1073 }
1074 p+=i;
1075
1076 n2s(p,i);
1077 param_len+=i+2;
1078 if (param_len > n)
1079 {
1080 al=SSL_AD_DECODE_ERROR;
1081 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH);
1082 goto f_err;
1083 }
1084 if (!(dh->g=BN_bin2bn(p,i,NULL)))
1085 {
1086 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
1087 goto err;
1088 }
1089 p+=i;
1090
1091 n2s(p,i);
1092 param_len+=i+2;
1093 if (param_len > n)
1094 {
1095 al=SSL_AD_DECODE_ERROR;
1096 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH);
1097 goto f_err;
1098 }
1099 if (!(dh->pub_key=BN_bin2bn(p,i,NULL)))
1100 {
1101 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
1102 goto err;
1103 }
1104 p+=i;
1105 n-=param_len;
1106
1107#ifndef OPENSSL_NO_RSA
1108 if (alg & SSL_aRSA)
1109 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
1110#else
1111 if (0)
1112 ;
1113#endif
1114#ifndef OPENSSL_NO_DSA
1115 else if (alg & SSL_aDSS)
1116 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509);
1117#endif
1118 /* else anonymous DH, so no certificate or pkey. */
1119
1120 s->session->sess_cert->peer_dh_tmp=dh;
1121 dh=NULL;
1122 }
1123 else if ((alg & SSL_kDHr) || (alg & SSL_kDHd))
1124 {
1125 al=SSL_AD_ILLEGAL_PARAMETER;
1126 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1127 goto f_err;
1128 }
1129#endif /* !OPENSSL_NO_DH */
1130 if (alg & SSL_aFZA)
1131 {
1132 al=SSL_AD_HANDSHAKE_FAILURE;
1133 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1134 goto f_err;
1135 }
1136
1137
1138 /* p points to the next byte, there are 'n' bytes left */
1139
1140
1141 /* if it was signed, check the signature */
1142 if (pkey != NULL)
1143 {
1144 n2s(p,i);
1145 n-=2;
1146 j=EVP_PKEY_size(pkey);
1147
1148 if ((i != n) || (n > j) || (n <= 0))
1149 {
1150 /* wrong packet length */
1151 al=SSL_AD_DECODE_ERROR;
1152 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH);
1153 goto f_err;
1154 }
1155
1156#ifndef OPENSSL_NO_RSA
1157 if (pkey->type == EVP_PKEY_RSA)
1158 {
1159 int num;
1160
1161 j=0;
1162 q=md_buf;
1163 for (num=2; num > 0; num--)
1164 {
1165 EVP_MD_CTX_set_flags(&md_ctx,
1166 EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
1167 EVP_DigestInit_ex(&md_ctx,(num == 2)
1168 ?s->ctx->md5:s->ctx->sha1, NULL);
1169 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1170 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1171 EVP_DigestUpdate(&md_ctx,param,param_len);
1172
1173 EVP_DigestFinal_ex(&md_ctx,q,(unsigned int *)&i);
1174 q+=i;
1175 j+=i;
1176 }
1177 i=RSA_verify(NID_md5_sha1, md_buf, j, p, n,
1178 pkey->pkey.rsa);
1179 if (i < 0)
1180 {
1181 al=SSL_AD_DECRYPT_ERROR;
1182 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1183 goto f_err;
1184 }
1185 if (i == 0)
1186 {
1187 /* bad signature */
1188 al=SSL_AD_DECRYPT_ERROR;
1189 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1190 goto f_err;
1191 }
1192 }
1193 else
1194#endif
1195#ifndef OPENSSL_NO_DSA
1196 if (pkey->type == EVP_PKEY_DSA)
1197 {
1198 /* lets do DSS */
1199 EVP_VerifyInit_ex(&md_ctx,EVP_dss1(), NULL);
1200 EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1201 EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1202 EVP_VerifyUpdate(&md_ctx,param,param_len);
1203 if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))
1204 {
1205 /* bad signature */
1206 al=SSL_AD_DECRYPT_ERROR;
1207 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1208 goto f_err;
1209 }
1210 }
1211 else
1212#endif
1213 {
1214 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);
1215 goto err;
1216 }
1217 }
1218 else
1219 {
1220 /* still data left over */
1221 if (!(alg & SSL_aNULL))
1222 {
1223 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);
1224 goto err;
1225 }
1226 if (n != 0)
1227 {
1228 al=SSL_AD_DECODE_ERROR;
1229 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE);
1230 goto f_err;
1231 }
1232 }
1233 EVP_PKEY_free(pkey);
1234 EVP_MD_CTX_cleanup(&md_ctx);
1235 return(1);
1236f_err:
1237 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1238err:
1239 EVP_PKEY_free(pkey);
1240#ifndef OPENSSL_NO_RSA
1241 if (rsa != NULL)
1242 RSA_free(rsa);
1243#endif
1244#ifndef OPENSSL_NO_DH
1245 if (dh != NULL)
1246 DH_free(dh);
1247#endif
1248 EVP_MD_CTX_cleanup(&md_ctx);
1249 return(-1);
1250 }
1251
1252static int ssl3_get_certificate_request(SSL *s)
1253 {
1254 int ok,ret=0;
1255 unsigned long n,nc,l;
1256 unsigned int llen,ctype_num,i;
1257 X509_NAME *xn=NULL;
1258 unsigned char *p,*d,*q;
1259 STACK_OF(X509_NAME) *ca_sk=NULL;
1260
1261 n=ssl3_get_message(s,
1262 SSL3_ST_CR_CERT_REQ_A,
1263 SSL3_ST_CR_CERT_REQ_B,
1264 -1,
1265 s->max_cert_list,
1266 &ok);
1267
1268 if (!ok) return((int)n);
1269
1270 s->s3->tmp.cert_req=0;
1271
1272 if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)
1273 {
1274 s->s3->tmp.reuse_message=1;
1275 return(1);
1276 }
1277
1278 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)
1279 {
1280 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1281 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);
1282 goto err;
1283 }
1284
1285 /* TLS does not like anon-DH with client cert */
1286 if (s->version > SSL3_VERSION)
1287 {
1288 l=s->s3->tmp.new_cipher->algorithms;
1289 if (l & SSL_aNULL)
1290 {
1291 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1292 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);
1293 goto err;
1294 }
1295 }
1296
1297 d=p=(unsigned char *)s->init_msg;
1298
1299 if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL)
1300 {
1301 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1302 goto err;
1303 }
1304
1305 /* get the certificate types */
1306 ctype_num= *(p++);
1307 if (ctype_num > SSL3_CT_NUMBER)
1308 ctype_num=SSL3_CT_NUMBER;
1309 for (i=0; i<ctype_num; i++)
1310 s->s3->tmp.ctype[i]= p[i];
1311 p+=ctype_num;
1312
1313 /* get the CA RDNs */
1314 n2s(p,llen);
1315#if 0
1316{
1317FILE *out;
1318out=fopen("/tmp/vsign.der","w");
1319fwrite(p,1,llen,out);
1320fclose(out);
1321}
1322#endif
1323
1324 if ((llen+ctype_num+2+1) != n)
1325 {
1326 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1327 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);
1328 goto err;
1329 }
1330
1331 for (nc=0; nc<llen; )
1332 {
1333 n2s(p,l);
1334 if ((l+nc+2) > llen)
1335 {
1336 if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1337 goto cont; /* netscape bugs */
1338 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1339 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);
1340 goto err;
1341 }
1342
1343 q=p;
1344
1345 if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)
1346 {
1347 /* If netscape tolerance is on, ignore errors */
1348 if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)
1349 goto cont;
1350 else
1351 {
1352 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1353 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);
1354 goto err;
1355 }
1356 }
1357
1358 if (q != (p+l))
1359 {
1360 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1361 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);
1362 goto err;
1363 }
1364 if (!sk_X509_NAME_push(ca_sk,xn))
1365 {
1366 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1367 goto err;
1368 }
1369
1370 p+=l;
1371 nc+=l+2;
1372 }
1373
1374 if (0)
1375 {
1376cont:
1377 ERR_clear_error();
1378 }
1379
1380 /* we should setup a certificate to return.... */
1381 s->s3->tmp.cert_req=1;
1382 s->s3->tmp.ctype_num=ctype_num;
1383 if (s->s3->tmp.ca_names != NULL)
1384 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1385 s->s3->tmp.ca_names=ca_sk;
1386 ca_sk=NULL;
1387
1388 ret=1;
1389err:
1390 if (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free);
1391 return(ret);
1392 }
1393
1394static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
1395 {
1396 return(X509_NAME_cmp(*a,*b));
1397 }
1398
1399static int ssl3_get_server_done(SSL *s)
1400 {
1401 int ok,ret=0;
1402 long n;
1403
1404 n=ssl3_get_message(s,
1405 SSL3_ST_CR_SRVR_DONE_A,
1406 SSL3_ST_CR_SRVR_DONE_B,
1407 SSL3_MT_SERVER_DONE,
1408 30, /* should be very small, like 0 :-) */
1409 &ok);
1410
1411 if (!ok) return((int)n);
1412 if (n > 0)
1413 {
1414 /* should contain no data */
1415 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1416 SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH);
1417 return -1;
1418 }
1419 ret=1;
1420 return(ret);
1421 }
1422
1423static int ssl3_send_client_key_exchange(SSL *s)
1424 {
1425 unsigned char *p,*d;
1426 int n;
1427 unsigned long l;
1428#ifndef OPENSSL_NO_RSA
1429 unsigned char *q;
1430 EVP_PKEY *pkey=NULL;
1431#endif
1432#ifndef OPENSSL_NO_KRB5
1433 KSSL_ERR kssl_err;
1434#endif /* OPENSSL_NO_KRB5 */
1435
1436 if (s->state == SSL3_ST_CW_KEY_EXCH_A)
1437 {
1438 d=(unsigned char *)s->init_buf->data;
1439 p= &(d[4]);
1440
1441 l=s->s3->tmp.new_cipher->algorithms;
1442
1443 /* Fool emacs indentation */
1444 if (0) {}
1445#ifndef OPENSSL_NO_RSA
1446 else if (l & SSL_kRSA)
1447 {
1448 RSA *rsa;
1449 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
1450
1451 if (s->session->sess_cert->peer_rsa_tmp != NULL)
1452 rsa=s->session->sess_cert->peer_rsa_tmp;
1453 else
1454 {
1455 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
1456 if ((pkey == NULL) ||
1457 (pkey->type != EVP_PKEY_RSA) ||
1458 (pkey->pkey.rsa == NULL))
1459 {
1460 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);
1461 goto err;
1462 }
1463 rsa=pkey->pkey.rsa;
1464 EVP_PKEY_free(pkey);
1465 }
1466
1467 tmp_buf[0]=s->client_version>>8;
1468 tmp_buf[1]=s->client_version&0xff;
1469 if (RAND_bytes(&(tmp_buf[2]),sizeof tmp_buf-2) <= 0)
1470 goto err;
1471
1472 s->session->master_key_length=sizeof tmp_buf;
1473
1474 q=p;
1475 /* Fix buf for TLS and beyond */
1476 if (s->version > SSL3_VERSION)
1477 p+=2;
1478 n=RSA_public_encrypt(sizeof tmp_buf,
1479 tmp_buf,p,rsa,RSA_PKCS1_PADDING);
1480#ifdef PKCS1_CHECK
1481 if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++;
1482 if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70;
1483#endif
1484 if (n <= 0)
1485 {
1486 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT);
1487 goto err;
1488 }
1489
1490 /* Fix buf for TLS and beyond */
1491 if (s->version > SSL3_VERSION)
1492 {
1493 s2n(n,q);
1494 n+=2;
1495 }
1496
1497 s->session->master_key_length=
1498 s->method->ssl3_enc->generate_master_secret(s,
1499 s->session->master_key,
1500 tmp_buf,sizeof tmp_buf);
1501 OPENSSL_cleanse(tmp_buf,sizeof tmp_buf);
1502 }
1503#endif
1504#ifndef OPENSSL_NO_KRB5
1505 else if (l & SSL_kKRB5)
1506 {
1507 krb5_error_code krb5rc;
1508 KSSL_CTX *kssl_ctx = s->kssl_ctx;
1509 /* krb5_data krb5_ap_req; */
1510 krb5_data *enc_ticket;
1511 krb5_data authenticator, *authp = NULL;
1512 EVP_CIPHER_CTX ciph_ctx;
1513 EVP_CIPHER *enc = NULL;
1514 unsigned char iv[EVP_MAX_IV_LENGTH];
1515 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
1516 unsigned char epms[SSL_MAX_MASTER_KEY_LENGTH
1517 + EVP_MAX_IV_LENGTH];
1518 int padl, outl = sizeof(epms);
1519
1520 EVP_CIPHER_CTX_init(&ciph_ctx);
1521
1522#ifdef KSSL_DEBUG
1523 printf("ssl3_send_client_key_exchange(%lx & %lx)\n",
1524 l, SSL_kKRB5);
1525#endif /* KSSL_DEBUG */
1526
1527 authp = NULL;
1528#ifdef KRB5SENDAUTH
1529 if (KRB5SENDAUTH) authp = &authenticator;
1530#endif /* KRB5SENDAUTH */
1531
1532 krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket, authp,
1533 &kssl_err);
1534 enc = kssl_map_enc(kssl_ctx->enctype);
1535 if (enc == NULL)
1536 goto err;
1537#ifdef KSSL_DEBUG
1538 {
1539 printf("kssl_cget_tkt rtn %d\n", krb5rc);
1540 if (krb5rc && kssl_err.text)
1541 printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text);
1542 }
1543#endif /* KSSL_DEBUG */
1544
1545 if (krb5rc)
1546 {
1547 ssl3_send_alert(s,SSL3_AL_FATAL,
1548 SSL_AD_HANDSHAKE_FAILURE);
1549 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
1550 kssl_err.reason);
1551 goto err;
1552 }
1553
1554 /* 20010406 VRS - Earlier versions used KRB5 AP_REQ
1555 ** in place of RFC 2712 KerberosWrapper, as in:
1556 **
1557 ** Send ticket (copy to *p, set n = length)
1558 ** n = krb5_ap_req.length;
1559 ** memcpy(p, krb5_ap_req.data, krb5_ap_req.length);
1560 ** if (krb5_ap_req.data)
1561 ** kssl_krb5_free_data_contents(NULL,&krb5_ap_req);
1562 **
1563 ** Now using real RFC 2712 KerberosWrapper
1564 ** (Thanks to Simon Wilkinson <sxw@sxw.org.uk>)
1565 ** Note: 2712 "opaque" types are here replaced
1566 ** with a 2-byte length followed by the value.
1567 ** Example:
1568 ** KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms
1569 ** Where "xx xx" = length bytes. Shown here with
1570 ** optional authenticator omitted.
1571 */
1572
1573 /* KerberosWrapper.Ticket */
1574 s2n(enc_ticket->length,p);
1575 memcpy(p, enc_ticket->data, enc_ticket->length);
1576 p+= enc_ticket->length;
1577 n = enc_ticket->length + 2;
1578
1579 /* KerberosWrapper.Authenticator */
1580 if (authp && authp->length)
1581 {
1582 s2n(authp->length,p);
1583 memcpy(p, authp->data, authp->length);
1584 p+= authp->length;
1585 n+= authp->length + 2;
1586
1587 free(authp->data);
1588 authp->data = NULL;
1589 authp->length = 0;
1590 }
1591 else
1592 {
1593 s2n(0,p);/* null authenticator length */
1594 n+=2;
1595 }
1596
1597 if (RAND_bytes(tmp_buf,sizeof tmp_buf) <= 0)
1598 goto err;
1599
1600 /* 20010420 VRS. Tried it this way; failed.
1601 ** EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL);
1602 ** EVP_CIPHER_CTX_set_key_length(&ciph_ctx,
1603 ** kssl_ctx->length);
1604 ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv);
1605 */
1606
1607 memset(iv, 0, sizeof iv); /* per RFC 1510 */
1608 EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,
1609 kssl_ctx->key,iv);
1610 EVP_EncryptUpdate(&ciph_ctx,epms,&outl,tmp_buf,
1611 sizeof tmp_buf);
1612 EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl);
1613 outl += padl;
1614 if (outl > sizeof epms)
1615 {
1616 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
1617 goto err;
1618 }
1619 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
1620
1621 /* KerberosWrapper.EncryptedPreMasterSecret */
1622 s2n(outl,p);
1623 memcpy(p, epms, outl);
1624 p+=outl;
1625 n+=outl + 2;
1626
1627 s->session->master_key_length=
1628 s->method->ssl3_enc->generate_master_secret(s,
1629 s->session->master_key,
1630 tmp_buf, sizeof tmp_buf);
1631
1632 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf);
1633 OPENSSL_cleanse(epms, outl);
1634 }
1635#endif
1636#ifndef OPENSSL_NO_DH
1637 else if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1638 {
1639 DH *dh_srvr,*dh_clnt;
1640
1641 if (s->session->sess_cert->peer_dh_tmp != NULL)
1642 dh_srvr=s->session->sess_cert->peer_dh_tmp;
1643 else
1644 {
1645 /* we get them from the cert */
1646 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1647 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS);
1648 goto err;
1649 }
1650
1651 /* generate a new random key */
1652 if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL)
1653 {
1654 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1655 goto err;
1656 }
1657 if (!DH_generate_key(dh_clnt))
1658 {
1659 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1660 goto err;
1661 }
1662
1663 /* use the 'p' output buffer for the DH key, but
1664 * make sure to clear it out afterwards */
1665
1666 n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt);
1667
1668 if (n <= 0)
1669 {
1670 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1671 goto err;
1672 }
1673
1674 /* generate master key from the result */
1675 s->session->master_key_length=
1676 s->method->ssl3_enc->generate_master_secret(s,
1677 s->session->master_key,p,n);
1678 /* clean up */
1679 memset(p,0,n);
1680
1681 /* send off the data */
1682 n=BN_num_bytes(dh_clnt->pub_key);
1683 s2n(n,p);
1684 BN_bn2bin(dh_clnt->pub_key,p);
1685 n+=2;
1686
1687 DH_free(dh_clnt);
1688
1689 /* perhaps clean things up a bit EAY EAY EAY EAY*/
1690 }
1691#endif
1692 else
1693 {
1694 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1695 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);
1696 goto err;
1697 }
1698
1699 *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE;
1700 l2n3(n,d);
1701
1702 s->state=SSL3_ST_CW_KEY_EXCH_B;
1703 /* number of bytes to write */
1704 s->init_num=n+4;
1705 s->init_off=0;
1706 }
1707
1708 /* SSL3_ST_CW_KEY_EXCH_B */
1709 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1710err:
1711 return(-1);
1712 }
1713
1714static int ssl3_send_client_verify(SSL *s)
1715 {
1716 unsigned char *p,*d;
1717 unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
1718 EVP_PKEY *pkey;
1719#ifndef OPENSSL_NO_RSA
1720 unsigned u=0;
1721#endif
1722 unsigned long n;
1723#ifndef OPENSSL_NO_DSA
1724 int j;
1725#endif
1726
1727 if (s->state == SSL3_ST_CW_CERT_VRFY_A)
1728 {
1729 d=(unsigned char *)s->init_buf->data;
1730 p= &(d[4]);
1731 pkey=s->cert->key->privatekey;
1732
1733 s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
1734 &(data[MD5_DIGEST_LENGTH]));
1735
1736#ifndef OPENSSL_NO_RSA
1737 if (pkey->type == EVP_PKEY_RSA)
1738 {
1739 s->method->ssl3_enc->cert_verify_mac(s,
1740 &(s->s3->finish_dgst1),&(data[0]));
1741 if (RSA_sign(NID_md5_sha1, data,
1742 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
1743 &(p[2]), &u, pkey->pkey.rsa) <= 0 )
1744 {
1745 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB);
1746 goto err;
1747 }
1748 s2n(u,p);
1749 n=u+2;
1750 }
1751 else
1752#endif
1753#ifndef OPENSSL_NO_DSA
1754 if (pkey->type == EVP_PKEY_DSA)
1755 {
1756 if (!DSA_sign(pkey->save_type,
1757 &(data[MD5_DIGEST_LENGTH]),
1758 SHA_DIGEST_LENGTH,&(p[2]),
1759 (unsigned int *)&j,pkey->pkey.dsa))
1760 {
1761 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB);
1762 goto err;
1763 }
1764 s2n(j,p);
1765 n=j+2;
1766 }
1767 else
1768#endif
1769 {
1770 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_INTERNAL_ERROR);
1771 goto err;
1772 }
1773 *(d++)=SSL3_MT_CERTIFICATE_VERIFY;
1774 l2n3(n,d);
1775
1776 s->state=SSL3_ST_CW_CERT_VRFY_B;
1777 s->init_num=(int)n+4;
1778 s->init_off=0;
1779 }
1780 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1781err:
1782 return(-1);
1783 }
1784
1785static int ssl3_send_client_certificate(SSL *s)
1786 {
1787 X509 *x509=NULL;
1788 EVP_PKEY *pkey=NULL;
1789 int i;
1790 unsigned long l;
1791
1792 if (s->state == SSL3_ST_CW_CERT_A)
1793 {
1794 if ((s->cert == NULL) ||
1795 (s->cert->key->x509 == NULL) ||
1796 (s->cert->key->privatekey == NULL))
1797 s->state=SSL3_ST_CW_CERT_B;
1798 else
1799 s->state=SSL3_ST_CW_CERT_C;
1800 }
1801
1802 /* We need to get a client cert */
1803 if (s->state == SSL3_ST_CW_CERT_B)
1804 {
1805 /* If we get an error, we need to
1806 * ssl->rwstate=SSL_X509_LOOKUP; return(-1);
1807 * We then get retied later */
1808 i=0;
1809 if (s->ctx->client_cert_cb != NULL)
1810 i=s->ctx->client_cert_cb(s,&(x509),&(pkey));
1811 if (i < 0)
1812 {
1813 s->rwstate=SSL_X509_LOOKUP;
1814 return(-1);
1815 }
1816 s->rwstate=SSL_NOTHING;
1817 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
1818 {
1819 s->state=SSL3_ST_CW_CERT_B;
1820 if ( !SSL_use_certificate(s,x509) ||
1821 !SSL_use_PrivateKey(s,pkey))
1822 i=0;
1823 }
1824 else if (i == 1)
1825 {
1826 i=0;
1827 SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
1828 }
1829
1830 if (x509 != NULL) X509_free(x509);
1831 if (pkey != NULL) EVP_PKEY_free(pkey);
1832 if (i == 0)
1833 {
1834 if (s->version == SSL3_VERSION)
1835 {
1836 s->s3->tmp.cert_req=0;
1837 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE);
1838 return(1);
1839 }
1840 else
1841 {
1842 s->s3->tmp.cert_req=2;
1843 }
1844 }
1845
1846 /* Ok, we have a cert */
1847 s->state=SSL3_ST_CW_CERT_C;
1848 }
1849
1850 if (s->state == SSL3_ST_CW_CERT_C)
1851 {
1852 s->state=SSL3_ST_CW_CERT_D;
1853 l=ssl3_output_cert_chain(s,
1854 (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509);
1855 s->init_num=(int)l;
1856 s->init_off=0;
1857 }
1858 /* SSL3_ST_CW_CERT_D */
1859 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1860 }
1861
1862#define has_bits(i,m) (((i)&(m)) == (m))
1863
1864static int ssl3_check_cert_and_algorithm(SSL *s)
1865 {
1866 int i,idx;
1867 long algs;
1868 EVP_PKEY *pkey=NULL;
1869 SESS_CERT *sc;
1870#ifndef OPENSSL_NO_RSA
1871 RSA *rsa;
1872#endif
1873#ifndef OPENSSL_NO_DH
1874 DH *dh;
1875#endif
1876
1877 sc=s->session->sess_cert;
1878
1879 if (sc == NULL)
1880 {
1881 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,ERR_R_INTERNAL_ERROR);
1882 goto err;
1883 }
1884
1885 algs=s->s3->tmp.new_cipher->algorithms;
1886
1887 /* we don't have a certificate */
1888 if (algs & (SSL_aDH|SSL_aNULL|SSL_aKRB5))
1889 return(1);
1890
1891#ifndef OPENSSL_NO_RSA
1892 rsa=s->session->sess_cert->peer_rsa_tmp;
1893#endif
1894#ifndef OPENSSL_NO_DH
1895 dh=s->session->sess_cert->peer_dh_tmp;
1896#endif
1897
1898 /* This is the passed certificate */
1899
1900 idx=sc->peer_cert_type;
1901 pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509);
1902 i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey);
1903 EVP_PKEY_free(pkey);
1904
1905
1906 /* Check that we have a certificate if we require one */
1907 if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
1908 {
1909 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);
1910 goto f_err;
1911 }
1912#ifndef OPENSSL_NO_DSA
1913 else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
1914 {
1915 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);
1916 goto f_err;
1917 }
1918#endif
1919#ifndef OPENSSL_NO_RSA
1920 if ((algs & SSL_kRSA) &&
1921 !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))
1922 {
1923 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);
1924 goto f_err;
1925 }
1926#endif
1927#ifndef OPENSSL_NO_DH
1928 if ((algs & SSL_kEDH) &&
1929 !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))
1930 {
1931 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);
1932 goto f_err;
1933 }
1934 else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
1935 {
1936 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);
1937 goto f_err;
1938 }
1939#ifndef OPENSSL_NO_DSA
1940 else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
1941 {
1942 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);
1943 goto f_err;
1944 }
1945#endif
1946#endif
1947
1948 if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))
1949 {
1950#ifndef OPENSSL_NO_RSA
1951 if (algs & SSL_kRSA)
1952 {
1953 if (rsa == NULL
1954 || RSA_size(rsa)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
1955 {
1956 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
1957 goto f_err;
1958 }
1959 }
1960 else
1961#endif
1962#ifndef OPENSSL_NO_DH
1963 if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1964 {
1965 if (dh == NULL
1966 || DH_size(dh)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
1967 {
1968 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);
1969 goto f_err;
1970 }
1971 }
1972 else
1973#endif
1974 {
1975 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1976 goto f_err;
1977 }
1978 }
1979 return(1);
1980f_err:
1981 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1982err:
1983 return(0);
1984 }
1985
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
deleted file mode 100644
index a77588e725..0000000000
--- a/src/lib/libssl/s3_lib.c
+++ /dev/null
@@ -1,1799 +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 * Copyright (c) 1998-2002 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 <openssl/objects.h>
114#include "ssl_locl.h"
115#include "kssl_lcl.h"
116#include <openssl/md5.h>
117
118const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT;
119
120#define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
121
122static long ssl3_default_timeout(void );
123
124OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
125/* The RSA ciphers */
126/* Cipher 01 */
127 {
128 1,
129 SSL3_TXT_RSA_NULL_MD5,
130 SSL3_CK_RSA_NULL_MD5,
131 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_SSLV3,
132 SSL_NOT_EXP|SSL_STRONG_NONE,
133 0,
134 0,
135 0,
136 SSL_ALL_CIPHERS,
137 SSL_ALL_STRENGTHS,
138 },
139/* Cipher 02 */
140 {
141 1,
142 SSL3_TXT_RSA_NULL_SHA,
143 SSL3_CK_RSA_NULL_SHA,
144 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3,
145 SSL_NOT_EXP|SSL_STRONG_NONE|SSL_FIPS,
146 0,
147 0,
148 0,
149 SSL_ALL_CIPHERS,
150 SSL_ALL_STRENGTHS,
151 },
152
153/* anon DH */
154/* Cipher 17 */
155 {
156 1,
157 SSL3_TXT_ADH_RC4_40_MD5,
158 SSL3_CK_ADH_RC4_40_MD5,
159 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
160 SSL_EXPORT|SSL_EXP40,
161 0,
162 40,
163 128,
164 SSL_ALL_CIPHERS,
165 SSL_ALL_STRENGTHS,
166 },
167/* Cipher 18 */
168 {
169 1,
170 SSL3_TXT_ADH_RC4_128_MD5,
171 SSL3_CK_ADH_RC4_128_MD5,
172 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
173 SSL_NOT_EXP|SSL_MEDIUM,
174 0,
175 128,
176 128,
177 SSL_ALL_CIPHERS,
178 SSL_ALL_STRENGTHS,
179 },
180/* Cipher 19 */
181 {
182 1,
183 SSL3_TXT_ADH_DES_40_CBC_SHA,
184 SSL3_CK_ADH_DES_40_CBC_SHA,
185 SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3,
186 SSL_EXPORT|SSL_EXP40|SSL_FIPS,
187 0,
188 40,
189 128,
190 SSL_ALL_CIPHERS,
191 SSL_ALL_STRENGTHS,
192 },
193/* Cipher 1A */
194 {
195 1,
196 SSL3_TXT_ADH_DES_64_CBC_SHA,
197 SSL3_CK_ADH_DES_64_CBC_SHA,
198 SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_SSLV3,
199 SSL_NOT_EXP|SSL_LOW|SSL_FIPS,
200 0,
201 56,
202 56,
203 SSL_ALL_CIPHERS,
204 SSL_ALL_STRENGTHS,
205 },
206/* Cipher 1B */
207 {
208 1,
209 SSL3_TXT_ADH_DES_192_CBC_SHA,
210 SSL3_CK_ADH_DES_192_CBC_SHA,
211 SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3,
212 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
213 0,
214 168,
215 168,
216 SSL_ALL_CIPHERS,
217 SSL_ALL_STRENGTHS,
218 },
219
220/* RSA again */
221/* Cipher 03 */
222 {
223 1,
224 SSL3_TXT_RSA_RC4_40_MD5,
225 SSL3_CK_RSA_RC4_40_MD5,
226 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
227 SSL_EXPORT|SSL_EXP40,
228 0,
229 40,
230 128,
231 SSL_ALL_CIPHERS,
232 SSL_ALL_STRENGTHS,
233 },
234/* Cipher 04 */
235 {
236 1,
237 SSL3_TXT_RSA_RC4_128_MD5,
238 SSL3_CK_RSA_RC4_128_MD5,
239 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_SSLV3,
240 SSL_NOT_EXP|SSL_MEDIUM,
241 0,
242 128,
243 128,
244 SSL_ALL_CIPHERS,
245 SSL_ALL_STRENGTHS,
246 },
247/* Cipher 05 */
248 {
249 1,
250 SSL3_TXT_RSA_RC4_128_SHA,
251 SSL3_CK_RSA_RC4_128_SHA,
252 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_SSLV3,
253 SSL_NOT_EXP|SSL_MEDIUM,
254 0,
255 128,
256 128,
257 SSL_ALL_CIPHERS,
258 SSL_ALL_STRENGTHS,
259 },
260/* Cipher 06 */
261 {
262 1,
263 SSL3_TXT_RSA_RC2_40_MD5,
264 SSL3_CK_RSA_RC2_40_MD5,
265 SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_SSLV3,
266 SSL_EXPORT|SSL_EXP40,
267 0,
268 40,
269 128,
270 SSL_ALL_CIPHERS,
271 SSL_ALL_STRENGTHS,
272 },
273/* Cipher 07 */
274#ifndef OPENSSL_NO_IDEA
275 {
276 1,
277 SSL3_TXT_RSA_IDEA_128_SHA,
278 SSL3_CK_RSA_IDEA_128_SHA,
279 SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_SSLV3,
280 SSL_NOT_EXP|SSL_MEDIUM,
281 0,
282 128,
283 128,
284 SSL_ALL_CIPHERS,
285 SSL_ALL_STRENGTHS,
286 },
287#endif
288/* Cipher 08 */
289 {
290 1,
291 SSL3_TXT_RSA_DES_40_CBC_SHA,
292 SSL3_CK_RSA_DES_40_CBC_SHA,
293 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
294 SSL_EXPORT|SSL_EXP40|SSL_FIPS,
295 0,
296 40,
297 56,
298 SSL_ALL_CIPHERS,
299 SSL_ALL_STRENGTHS,
300 },
301/* Cipher 09 */
302 {
303 1,
304 SSL3_TXT_RSA_DES_64_CBC_SHA,
305 SSL3_CK_RSA_DES_64_CBC_SHA,
306 SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3,
307 SSL_NOT_EXP|SSL_LOW|SSL_FIPS,
308 0,
309 56,
310 56,
311 SSL_ALL_CIPHERS,
312 SSL_ALL_STRENGTHS,
313 },
314/* Cipher 0A */
315 {
316 1,
317 SSL3_TXT_RSA_DES_192_CBC3_SHA,
318 SSL3_CK_RSA_DES_192_CBC3_SHA,
319 SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
320 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
321 0,
322 168,
323 168,
324 SSL_ALL_CIPHERS,
325 SSL_ALL_STRENGTHS,
326 },
327
328/* The DH ciphers */
329/* Cipher 0B */
330 {
331 0,
332 SSL3_TXT_DH_DSS_DES_40_CBC_SHA,
333 SSL3_CK_DH_DSS_DES_40_CBC_SHA,
334 SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
335 SSL_EXPORT|SSL_EXP40|SSL_FIPS,
336 0,
337 40,
338 56,
339 SSL_ALL_CIPHERS,
340 SSL_ALL_STRENGTHS,
341 },
342/* Cipher 0C */
343 {
344 0,
345 SSL3_TXT_DH_DSS_DES_64_CBC_SHA,
346 SSL3_CK_DH_DSS_DES_64_CBC_SHA,
347 SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3,
348 SSL_NOT_EXP|SSL_LOW|SSL_FIPS,
349 0,
350 56,
351 56,
352 SSL_ALL_CIPHERS,
353 SSL_ALL_STRENGTHS,
354 },
355/* Cipher 0D */
356 {
357 0,
358 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA,
359 SSL3_CK_DH_DSS_DES_192_CBC3_SHA,
360 SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
361 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
362 0,
363 168,
364 168,
365 SSL_ALL_CIPHERS,
366 SSL_ALL_STRENGTHS,
367 },
368/* Cipher 0E */
369 {
370 0,
371 SSL3_TXT_DH_RSA_DES_40_CBC_SHA,
372 SSL3_CK_DH_RSA_DES_40_CBC_SHA,
373 SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
374 SSL_EXPORT|SSL_EXP40|SSL_FIPS,
375 0,
376 40,
377 56,
378 SSL_ALL_CIPHERS,
379 SSL_ALL_STRENGTHS,
380 },
381/* Cipher 0F */
382 {
383 0,
384 SSL3_TXT_DH_RSA_DES_64_CBC_SHA,
385 SSL3_CK_DH_RSA_DES_64_CBC_SHA,
386 SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3,
387 SSL_NOT_EXP|SSL_LOW|SSL_FIPS,
388 0,
389 56,
390 56,
391 SSL_ALL_CIPHERS,
392 SSL_ALL_STRENGTHS,
393 },
394/* Cipher 10 */
395 {
396 0,
397 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA,
398 SSL3_CK_DH_RSA_DES_192_CBC3_SHA,
399 SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
400 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
401 0,
402 168,
403 168,
404 SSL_ALL_CIPHERS,
405 SSL_ALL_STRENGTHS,
406 },
407
408/* The Ephemeral DH ciphers */
409/* Cipher 11 */
410 {
411 1,
412 SSL3_TXT_EDH_DSS_DES_40_CBC_SHA,
413 SSL3_CK_EDH_DSS_DES_40_CBC_SHA,
414 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3,
415 SSL_EXPORT|SSL_EXP40|SSL_FIPS,
416 0,
417 40,
418 56,
419 SSL_ALL_CIPHERS,
420 SSL_ALL_STRENGTHS,
421 },
422/* Cipher 12 */
423 {
424 1,
425 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA,
426 SSL3_CK_EDH_DSS_DES_64_CBC_SHA,
427 SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_SSLV3,
428 SSL_NOT_EXP|SSL_LOW|SSL_FIPS,
429 0,
430 56,
431 56,
432 SSL_ALL_CIPHERS,
433 SSL_ALL_STRENGTHS,
434 },
435/* Cipher 13 */
436 {
437 1,
438 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA,
439 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA,
440 SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3,
441 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
442 0,
443 168,
444 168,
445 SSL_ALL_CIPHERS,
446 SSL_ALL_STRENGTHS,
447 },
448/* Cipher 14 */
449 {
450 1,
451 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA,
452 SSL3_CK_EDH_RSA_DES_40_CBC_SHA,
453 SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
454 SSL_EXPORT|SSL_EXP40|SSL_FIPS,
455 0,
456 40,
457 56,
458 SSL_ALL_CIPHERS,
459 SSL_ALL_STRENGTHS,
460 },
461/* Cipher 15 */
462 {
463 1,
464 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA,
465 SSL3_CK_EDH_RSA_DES_64_CBC_SHA,
466 SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3,
467 SSL_NOT_EXP|SSL_LOW|SSL_FIPS,
468 0,
469 56,
470 56,
471 SSL_ALL_CIPHERS,
472 SSL_ALL_STRENGTHS,
473 },
474/* Cipher 16 */
475 {
476 1,
477 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA,
478 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA,
479 SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
480 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
481 0,
482 168,
483 168,
484 SSL_ALL_CIPHERS,
485 SSL_ALL_STRENGTHS,
486 },
487
488/* Fortezza */
489/* Cipher 1C */
490 {
491 0,
492 SSL3_TXT_FZA_DMS_NULL_SHA,
493 SSL3_CK_FZA_DMS_NULL_SHA,
494 SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_SSLV3,
495 SSL_NOT_EXP|SSL_STRONG_NONE,
496 0,
497 0,
498 0,
499 SSL_ALL_CIPHERS,
500 SSL_ALL_STRENGTHS,
501 },
502
503/* Cipher 1D */
504 {
505 0,
506 SSL3_TXT_FZA_DMS_FZA_SHA,
507 SSL3_CK_FZA_DMS_FZA_SHA,
508 SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_SSLV3,
509 SSL_NOT_EXP|SSL_STRONG_NONE,
510 0,
511 0,
512 0,
513 SSL_ALL_CIPHERS,
514 SSL_ALL_STRENGTHS,
515 },
516
517#if 0
518/* Cipher 1E */
519 {
520 0,
521 SSL3_TXT_FZA_DMS_RC4_SHA,
522 SSL3_CK_FZA_DMS_RC4_SHA,
523 SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_SSLV3,
524 SSL_NOT_EXP|SSL_MEDIUM,
525 0,
526 128,
527 128,
528 SSL_ALL_CIPHERS,
529 SSL_ALL_STRENGTHS,
530 },
531#endif
532
533#ifndef OPENSSL_NO_KRB5
534/* The Kerberos ciphers
535** 20000107 VRS: And the first shall be last,
536** in hopes of avoiding the lynx ssl renegotiation problem.
537*/
538/* Cipher 1E VRS */
539 {
540 1,
541 SSL3_TXT_KRB5_DES_64_CBC_SHA,
542 SSL3_CK_KRB5_DES_64_CBC_SHA,
543 SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3,
544 SSL_NOT_EXP|SSL_LOW|SSL_FIPS,
545 0,
546 56,
547 56,
548 SSL_ALL_CIPHERS,
549 SSL_ALL_STRENGTHS,
550 },
551
552/* Cipher 1F VRS */
553 {
554 1,
555 SSL3_TXT_KRB5_DES_192_CBC3_SHA,
556 SSL3_CK_KRB5_DES_192_CBC3_SHA,
557 SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_SHA1 |SSL_SSLV3,
558 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
559 0,
560 112,
561 168,
562 SSL_ALL_CIPHERS,
563 SSL_ALL_STRENGTHS,
564 },
565
566/* Cipher 20 VRS */
567 {
568 1,
569 SSL3_TXT_KRB5_RC4_128_SHA,
570 SSL3_CK_KRB5_RC4_128_SHA,
571 SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3,
572 SSL_NOT_EXP|SSL_MEDIUM,
573 0,
574 128,
575 128,
576 SSL_ALL_CIPHERS,
577 SSL_ALL_STRENGTHS,
578 },
579
580/* Cipher 21 VRS */
581 {
582 1,
583 SSL3_TXT_KRB5_IDEA_128_CBC_SHA,
584 SSL3_CK_KRB5_IDEA_128_CBC_SHA,
585 SSL_kKRB5|SSL_aKRB5| SSL_IDEA|SSL_SHA1 |SSL_SSLV3,
586 SSL_NOT_EXP|SSL_MEDIUM,
587 0,
588 128,
589 128,
590 SSL_ALL_CIPHERS,
591 SSL_ALL_STRENGTHS,
592 },
593
594/* Cipher 22 VRS */
595 {
596 1,
597 SSL3_TXT_KRB5_DES_64_CBC_MD5,
598 SSL3_CK_KRB5_DES_64_CBC_MD5,
599 SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3,
600 SSL_NOT_EXP|SSL_LOW,
601 0,
602 56,
603 56,
604 SSL_ALL_CIPHERS,
605 SSL_ALL_STRENGTHS,
606 },
607
608/* Cipher 23 VRS */
609 {
610 1,
611 SSL3_TXT_KRB5_DES_192_CBC3_MD5,
612 SSL3_CK_KRB5_DES_192_CBC3_MD5,
613 SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_MD5 |SSL_SSLV3,
614 SSL_NOT_EXP|SSL_HIGH,
615 0,
616 112,
617 168,
618 SSL_ALL_CIPHERS,
619 SSL_ALL_STRENGTHS,
620 },
621
622/* Cipher 24 VRS */
623 {
624 1,
625 SSL3_TXT_KRB5_RC4_128_MD5,
626 SSL3_CK_KRB5_RC4_128_MD5,
627 SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3,
628 SSL_NOT_EXP|SSL_MEDIUM,
629 0,
630 128,
631 128,
632 SSL_ALL_CIPHERS,
633 SSL_ALL_STRENGTHS,
634 },
635
636/* Cipher 25 VRS */
637 {
638 1,
639 SSL3_TXT_KRB5_IDEA_128_CBC_MD5,
640 SSL3_CK_KRB5_IDEA_128_CBC_MD5,
641 SSL_kKRB5|SSL_aKRB5| SSL_IDEA|SSL_MD5 |SSL_SSLV3,
642 SSL_NOT_EXP|SSL_MEDIUM,
643 0,
644 128,
645 128,
646 SSL_ALL_CIPHERS,
647 SSL_ALL_STRENGTHS,
648 },
649
650/* Cipher 26 VRS */
651 {
652 1,
653 SSL3_TXT_KRB5_DES_40_CBC_SHA,
654 SSL3_CK_KRB5_DES_40_CBC_SHA,
655 SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3,
656 SSL_EXPORT|SSL_EXP40|SSL_FIPS,
657 0,
658 40,
659 56,
660 SSL_ALL_CIPHERS,
661 SSL_ALL_STRENGTHS,
662 },
663
664/* Cipher 27 VRS */
665 {
666 1,
667 SSL3_TXT_KRB5_RC2_40_CBC_SHA,
668 SSL3_CK_KRB5_RC2_40_CBC_SHA,
669 SSL_kKRB5|SSL_aKRB5| SSL_RC2|SSL_SHA1 |SSL_SSLV3,
670 SSL_EXPORT|SSL_EXP40,
671 0,
672 40,
673 128,
674 SSL_ALL_CIPHERS,
675 SSL_ALL_STRENGTHS,
676 },
677
678/* Cipher 28 VRS */
679 {
680 1,
681 SSL3_TXT_KRB5_RC4_40_SHA,
682 SSL3_CK_KRB5_RC4_40_SHA,
683 SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3,
684 SSL_EXPORT|SSL_EXP40,
685 0,
686 128,
687 128,
688 SSL_ALL_CIPHERS,
689 SSL_ALL_STRENGTHS,
690 },
691
692/* Cipher 29 VRS */
693 {
694 1,
695 SSL3_TXT_KRB5_DES_40_CBC_MD5,
696 SSL3_CK_KRB5_DES_40_CBC_MD5,
697 SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3,
698 SSL_EXPORT|SSL_EXP40,
699 0,
700 40,
701 56,
702 SSL_ALL_CIPHERS,
703 SSL_ALL_STRENGTHS,
704 },
705
706/* Cipher 2A VRS */
707 {
708 1,
709 SSL3_TXT_KRB5_RC2_40_CBC_MD5,
710 SSL3_CK_KRB5_RC2_40_CBC_MD5,
711 SSL_kKRB5|SSL_aKRB5| SSL_RC2|SSL_MD5 |SSL_SSLV3,
712 SSL_EXPORT|SSL_EXP40,
713 0,
714 40,
715 128,
716 SSL_ALL_CIPHERS,
717 SSL_ALL_STRENGTHS,
718 },
719
720/* Cipher 2B VRS */
721 {
722 1,
723 SSL3_TXT_KRB5_RC4_40_MD5,
724 SSL3_CK_KRB5_RC4_40_MD5,
725 SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3,
726 SSL_EXPORT|SSL_EXP40,
727 0,
728 128,
729 128,
730 SSL_ALL_CIPHERS,
731 SSL_ALL_STRENGTHS,
732 },
733#endif /* OPENSSL_NO_KRB5 */
734
735
736#if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
737 /* New TLS Export CipherSuites */
738 /* Cipher 60 */
739 {
740 1,
741 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5,
742 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5,
743 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_TLSV1,
744 SSL_EXPORT|SSL_EXP56,
745 0,
746 56,
747 128,
748 SSL_ALL_CIPHERS,
749 SSL_ALL_STRENGTHS,
750 },
751 /* Cipher 61 */
752 {
753 1,
754 TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
755 TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
756 SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_TLSV1,
757 SSL_EXPORT|SSL_EXP56,
758 0,
759 56,
760 128,
761 SSL_ALL_CIPHERS,
762 SSL_ALL_STRENGTHS,
763 },
764 /* Cipher 62 */
765 {
766 1,
767 TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA,
768 TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA,
769 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1,
770 SSL_EXPORT|SSL_EXP56|SSL_FIPS,
771 0,
772 56,
773 56,
774 SSL_ALL_CIPHERS,
775 SSL_ALL_STRENGTHS,
776 },
777 /* Cipher 63 */
778 {
779 1,
780 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
781 TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
782 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1,
783 SSL_EXPORT|SSL_EXP56|SSL_FIPS,
784 0,
785 56,
786 56,
787 SSL_ALL_CIPHERS,
788 SSL_ALL_STRENGTHS,
789 },
790 /* Cipher 64 */
791 {
792 1,
793 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA,
794 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA,
795 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
796 SSL_EXPORT|SSL_EXP56,
797 0,
798 56,
799 128,
800 SSL_ALL_CIPHERS,
801 SSL_ALL_STRENGTHS,
802 },
803 /* Cipher 65 */
804 {
805 1,
806 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
807 TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
808 SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
809 SSL_EXPORT|SSL_EXP56,
810 0,
811 56,
812 128,
813 SSL_ALL_CIPHERS,
814 SSL_ALL_STRENGTHS,
815 },
816 /* Cipher 66 */
817 {
818 1,
819 TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA,
820 TLS1_CK_DHE_DSS_WITH_RC4_128_SHA,
821 SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
822 SSL_NOT_EXP|SSL_MEDIUM,
823 0,
824 128,
825 128,
826 SSL_ALL_CIPHERS,
827 SSL_ALL_STRENGTHS
828 },
829#endif
830 /* New AES ciphersuites */
831
832 /* Cipher 2F */
833 {
834 1,
835 TLS1_TXT_RSA_WITH_AES_128_SHA,
836 TLS1_CK_RSA_WITH_AES_128_SHA,
837 SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1,
838 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
839 0,
840 128,
841 128,
842 SSL_ALL_CIPHERS,
843 SSL_ALL_STRENGTHS,
844 },
845 /* Cipher 30 */
846 {
847 0,
848 TLS1_TXT_DH_DSS_WITH_AES_128_SHA,
849 TLS1_CK_DH_DSS_WITH_AES_128_SHA,
850 SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
851 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
852 0,
853 128,
854 128,
855 SSL_ALL_CIPHERS,
856 SSL_ALL_STRENGTHS,
857 },
858 /* Cipher 31 */
859 {
860 0,
861 TLS1_TXT_DH_RSA_WITH_AES_128_SHA,
862 TLS1_CK_DH_RSA_WITH_AES_128_SHA,
863 SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
864 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
865 0,
866 128,
867 128,
868 SSL_ALL_CIPHERS,
869 SSL_ALL_STRENGTHS,
870 },
871 /* Cipher 32 */
872 {
873 1,
874 TLS1_TXT_DHE_DSS_WITH_AES_128_SHA,
875 TLS1_CK_DHE_DSS_WITH_AES_128_SHA,
876 SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1,
877 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
878 0,
879 128,
880 128,
881 SSL_ALL_CIPHERS,
882 SSL_ALL_STRENGTHS,
883 },
884 /* Cipher 33 */
885 {
886 1,
887 TLS1_TXT_DHE_RSA_WITH_AES_128_SHA,
888 TLS1_CK_DHE_RSA_WITH_AES_128_SHA,
889 SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
890 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
891 0,
892 128,
893 128,
894 SSL_ALL_CIPHERS,
895 SSL_ALL_STRENGTHS,
896 },
897 /* Cipher 34 */
898 {
899 1,
900 TLS1_TXT_ADH_WITH_AES_128_SHA,
901 TLS1_CK_ADH_WITH_AES_128_SHA,
902 SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
903 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
904 0,
905 128,
906 128,
907 SSL_ALL_CIPHERS,
908 SSL_ALL_STRENGTHS,
909 },
910
911 /* Cipher 35 */
912 {
913 1,
914 TLS1_TXT_RSA_WITH_AES_256_SHA,
915 TLS1_CK_RSA_WITH_AES_256_SHA,
916 SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1,
917 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
918 0,
919 256,
920 256,
921 SSL_ALL_CIPHERS,
922 SSL_ALL_STRENGTHS,
923 },
924 /* Cipher 36 */
925 {
926 0,
927 TLS1_TXT_DH_DSS_WITH_AES_256_SHA,
928 TLS1_CK_DH_DSS_WITH_AES_256_SHA,
929 SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
930 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
931 0,
932 256,
933 256,
934 SSL_ALL_CIPHERS,
935 SSL_ALL_STRENGTHS,
936 },
937 /* Cipher 37 */
938 {
939 0,
940 TLS1_TXT_DH_RSA_WITH_AES_256_SHA,
941 TLS1_CK_DH_RSA_WITH_AES_256_SHA,
942 SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
943 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
944 0,
945 256,
946 256,
947 SSL_ALL_CIPHERS,
948 SSL_ALL_STRENGTHS,
949 },
950 /* Cipher 38 */
951 {
952 1,
953 TLS1_TXT_DHE_DSS_WITH_AES_256_SHA,
954 TLS1_CK_DHE_DSS_WITH_AES_256_SHA,
955 SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1,
956 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
957 0,
958 256,
959 256,
960 SSL_ALL_CIPHERS,
961 SSL_ALL_STRENGTHS,
962 },
963 /* Cipher 39 */
964 {
965 1,
966 TLS1_TXT_DHE_RSA_WITH_AES_256_SHA,
967 TLS1_CK_DHE_RSA_WITH_AES_256_SHA,
968 SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
969 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
970 0,
971 256,
972 256,
973 SSL_ALL_CIPHERS,
974 SSL_ALL_STRENGTHS,
975 },
976 /* Cipher 3A */
977 {
978 1,
979 TLS1_TXT_ADH_WITH_AES_256_SHA,
980 TLS1_CK_ADH_WITH_AES_256_SHA,
981 SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
982 SSL_NOT_EXP|SSL_HIGH|SSL_FIPS,
983 0,
984 256,
985 256,
986 SSL_ALL_CIPHERS,
987 SSL_ALL_STRENGTHS,
988 },
989
990/* end of list */
991 };
992
993static SSL3_ENC_METHOD SSLv3_enc_data={
994 ssl3_enc,
995 ssl3_mac,
996 ssl3_setup_key_block,
997 ssl3_generate_master_secret,
998 ssl3_change_cipher_state,
999 ssl3_final_finish_mac,
1000 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
1001 ssl3_cert_verify_mac,
1002 SSL3_MD_CLIENT_FINISHED_CONST,4,
1003 SSL3_MD_SERVER_FINISHED_CONST,4,
1004 ssl3_alert_code,
1005 };
1006
1007static SSL_METHOD SSLv3_data= {
1008 SSL3_VERSION,
1009 ssl3_new,
1010 ssl3_clear,
1011 ssl3_free,
1012 ssl_undefined_function,
1013 ssl_undefined_function,
1014 ssl3_read,
1015 ssl3_peek,
1016 ssl3_write,
1017 ssl3_shutdown,
1018 ssl3_renegotiate,
1019 ssl3_renegotiate_check,
1020 ssl3_ctrl,
1021 ssl3_ctx_ctrl,
1022 ssl3_get_cipher_by_char,
1023 ssl3_put_cipher_by_char,
1024 ssl3_pending,
1025 ssl3_num_ciphers,
1026 ssl3_get_cipher,
1027 ssl_bad_method,
1028 ssl3_default_timeout,
1029 &SSLv3_enc_data,
1030 ssl_undefined_function,
1031 ssl3_callback_ctrl,
1032 ssl3_ctx_callback_ctrl,
1033 };
1034
1035static long ssl3_default_timeout(void)
1036 {
1037 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
1038 * is way too long for http, the cache would over fill */
1039 return(60*60*2);
1040 }
1041
1042SSL_METHOD *sslv3_base_method(void)
1043 {
1044 return(&SSLv3_data);
1045 }
1046
1047int ssl3_num_ciphers(void)
1048 {
1049 return(SSL3_NUM_CIPHERS);
1050 }
1051
1052SSL_CIPHER *ssl3_get_cipher(unsigned int u)
1053 {
1054 if (u < SSL3_NUM_CIPHERS)
1055 return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
1056 else
1057 return(NULL);
1058 }
1059
1060int ssl3_pending(const SSL *s)
1061 {
1062 if (s->rstate == SSL_ST_READ_BODY)
1063 return 0;
1064
1065 return (s->s3->rrec.type == SSL3_RT_APPLICATION_DATA) ? s->s3->rrec.length : 0;
1066 }
1067
1068int ssl3_new(SSL *s)
1069 {
1070 SSL3_STATE *s3;
1071
1072 if ((s3=OPENSSL_malloc(sizeof *s3)) == NULL) goto err;
1073 memset(s3,0,sizeof *s3);
1074 EVP_MD_CTX_init(&s3->finish_dgst1);
1075 EVP_MD_CTX_init(&s3->finish_dgst2);
1076
1077 s->s3=s3;
1078
1079 s->method->ssl_clear(s);
1080 return(1);
1081err:
1082 return(0);
1083 }
1084
1085void ssl3_free(SSL *s)
1086 {
1087 if(s == NULL)
1088 return;
1089
1090 ssl3_cleanup_key_block(s);
1091 if (s->s3->rbuf.buf != NULL)
1092 OPENSSL_free(s->s3->rbuf.buf);
1093 if (s->s3->wbuf.buf != NULL)
1094 OPENSSL_free(s->s3->wbuf.buf);
1095 if (s->s3->rrec.comp != NULL)
1096 OPENSSL_free(s->s3->rrec.comp);
1097#ifndef OPENSSL_NO_DH
1098 if (s->s3->tmp.dh != NULL)
1099 DH_free(s->s3->tmp.dh);
1100#endif
1101 if (s->s3->tmp.ca_names != NULL)
1102 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1103 EVP_MD_CTX_cleanup(&s->s3->finish_dgst1);
1104 EVP_MD_CTX_cleanup(&s->s3->finish_dgst2);
1105 OPENSSL_cleanse(s->s3,sizeof *s->s3);
1106 OPENSSL_free(s->s3);
1107 s->s3=NULL;
1108 }
1109
1110void ssl3_clear(SSL *s)
1111 {
1112 unsigned char *rp,*wp;
1113 size_t rlen, wlen;
1114
1115 ssl3_cleanup_key_block(s);
1116 if (s->s3->tmp.ca_names != NULL)
1117 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1118
1119 if (s->s3->rrec.comp != NULL)
1120 {
1121 OPENSSL_free(s->s3->rrec.comp);
1122 s->s3->rrec.comp=NULL;
1123 }
1124#ifndef OPENSSL_NO_DH
1125 if (s->s3->tmp.dh != NULL)
1126 DH_free(s->s3->tmp.dh);
1127#endif
1128
1129 rp = s->s3->rbuf.buf;
1130 wp = s->s3->wbuf.buf;
1131 rlen = s->s3->rbuf.len;
1132 wlen = s->s3->wbuf.len;
1133
1134 EVP_MD_CTX_cleanup(&s->s3->finish_dgst1);
1135 EVP_MD_CTX_cleanup(&s->s3->finish_dgst2);
1136
1137 memset(s->s3,0,sizeof *s->s3);
1138 s->s3->rbuf.buf = rp;
1139 s->s3->wbuf.buf = wp;
1140 s->s3->rbuf.len = rlen;
1141 s->s3->wbuf.len = wlen;
1142
1143 ssl_free_wbio_buffer(s);
1144
1145 s->packet_length=0;
1146 s->s3->renegotiate=0;
1147 s->s3->total_renegotiations=0;
1148 s->s3->num_renegotiations=0;
1149 s->s3->in_read_app_data=0;
1150 s->version=SSL3_VERSION;
1151 }
1152
1153long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
1154 {
1155 int ret=0;
1156
1157#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
1158 if (
1159#ifndef OPENSSL_NO_RSA
1160 cmd == SSL_CTRL_SET_TMP_RSA ||
1161 cmd == SSL_CTRL_SET_TMP_RSA_CB ||
1162#endif
1163#ifndef OPENSSL_NO_DSA
1164 cmd == SSL_CTRL_SET_TMP_DH ||
1165 cmd == SSL_CTRL_SET_TMP_DH_CB ||
1166#endif
1167 0)
1168 {
1169 if (!ssl_cert_inst(&s->cert))
1170 {
1171 SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE);
1172 return(0);
1173 }
1174 }
1175#endif
1176
1177 switch (cmd)
1178 {
1179 case SSL_CTRL_GET_SESSION_REUSED:
1180 ret=s->hit;
1181 break;
1182 case SSL_CTRL_GET_CLIENT_CERT_REQUEST:
1183 break;
1184 case SSL_CTRL_GET_NUM_RENEGOTIATIONS:
1185 ret=s->s3->num_renegotiations;
1186 break;
1187 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:
1188 ret=s->s3->num_renegotiations;
1189 s->s3->num_renegotiations=0;
1190 break;
1191 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS:
1192 ret=s->s3->total_renegotiations;
1193 break;
1194 case SSL_CTRL_GET_FLAGS:
1195 ret=(int)(s->s3->flags);
1196 break;
1197#ifndef OPENSSL_NO_RSA
1198 case SSL_CTRL_NEED_TMP_RSA:
1199 if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) &&
1200 ((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
1201 (EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))))
1202 ret = 1;
1203 break;
1204 case SSL_CTRL_SET_TMP_RSA:
1205 {
1206 RSA *rsa = (RSA *)parg;
1207 if (rsa == NULL)
1208 {
1209 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
1210 return(ret);
1211 }
1212 if ((rsa = RSAPrivateKey_dup(rsa)) == NULL)
1213 {
1214 SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB);
1215 return(ret);
1216 }
1217 if (s->cert->rsa_tmp != NULL)
1218 RSA_free(s->cert->rsa_tmp);
1219 s->cert->rsa_tmp = rsa;
1220 ret = 1;
1221 }
1222 break;
1223 case SSL_CTRL_SET_TMP_RSA_CB:
1224 {
1225 SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1226 return(ret);
1227 }
1228 break;
1229#endif
1230#ifndef OPENSSL_NO_DH
1231 case SSL_CTRL_SET_TMP_DH:
1232 {
1233 DH *dh = (DH *)parg;
1234 if (dh == NULL)
1235 {
1236 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
1237 return(ret);
1238 }
1239 if ((dh = DHparams_dup(dh)) == NULL)
1240 {
1241 SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
1242 return(ret);
1243 }
1244 if (!(s->options & SSL_OP_SINGLE_DH_USE))
1245 {
1246 if (!DH_generate_key(dh))
1247 {
1248 DH_free(dh);
1249 SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
1250 return(ret);
1251 }
1252 }
1253 if (s->cert->dh_tmp != NULL)
1254 DH_free(s->cert->dh_tmp);
1255 s->cert->dh_tmp = dh;
1256 ret = 1;
1257 }
1258 break;
1259 case SSL_CTRL_SET_TMP_DH_CB:
1260 {
1261 SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1262 return(ret);
1263 }
1264 break;
1265#endif
1266 default:
1267 break;
1268 }
1269 return(ret);
1270 }
1271
1272long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)())
1273 {
1274 int ret=0;
1275
1276#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
1277 if (
1278#ifndef OPENSSL_NO_RSA
1279 cmd == SSL_CTRL_SET_TMP_RSA_CB ||
1280#endif
1281#ifndef OPENSSL_NO_DSA
1282 cmd == SSL_CTRL_SET_TMP_DH_CB ||
1283#endif
1284 0)
1285 {
1286 if (!ssl_cert_inst(&s->cert))
1287 {
1288 SSLerr(SSL_F_SSL3_CALLBACK_CTRL, ERR_R_MALLOC_FAILURE);
1289 return(0);
1290 }
1291 }
1292#endif
1293
1294 switch (cmd)
1295 {
1296#ifndef OPENSSL_NO_RSA
1297 case SSL_CTRL_SET_TMP_RSA_CB:
1298 {
1299 s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
1300 }
1301 break;
1302#endif
1303#ifndef OPENSSL_NO_DH
1304 case SSL_CTRL_SET_TMP_DH_CB:
1305 {
1306 s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
1307 }
1308 break;
1309#endif
1310 default:
1311 break;
1312 }
1313 return(ret);
1314 }
1315
1316long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
1317 {
1318 CERT *cert;
1319
1320 cert=ctx->cert;
1321
1322 switch (cmd)
1323 {
1324#ifndef OPENSSL_NO_RSA
1325 case SSL_CTRL_NEED_TMP_RSA:
1326 if ( (cert->rsa_tmp == NULL) &&
1327 ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
1328 (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))
1329 )
1330 return(1);
1331 else
1332 return(0);
1333 /* break; */
1334 case SSL_CTRL_SET_TMP_RSA:
1335 {
1336 RSA *rsa;
1337 int i;
1338
1339 rsa=(RSA *)parg;
1340 i=1;
1341 if (rsa == NULL)
1342 i=0;
1343 else
1344 {
1345 if ((rsa=RSAPrivateKey_dup(rsa)) == NULL)
1346 i=0;
1347 }
1348 if (!i)
1349 {
1350 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB);
1351 return(0);
1352 }
1353 else
1354 {
1355 if (cert->rsa_tmp != NULL)
1356 RSA_free(cert->rsa_tmp);
1357 cert->rsa_tmp=rsa;
1358 return(1);
1359 }
1360 }
1361 /* break; */
1362 case SSL_CTRL_SET_TMP_RSA_CB:
1363 {
1364 SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1365 return(0);
1366 }
1367 break;
1368#endif
1369#ifndef OPENSSL_NO_DH
1370 case SSL_CTRL_SET_TMP_DH:
1371 {
1372 DH *new=NULL,*dh;
1373
1374 dh=(DH *)parg;
1375 if ((new=DHparams_dup(dh)) == NULL)
1376 {
1377 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
1378 return 0;
1379 }
1380 if (!(ctx->options & SSL_OP_SINGLE_DH_USE))
1381 {
1382 if (!DH_generate_key(new))
1383 {
1384 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
1385 DH_free(new);
1386 return 0;
1387 }
1388 }
1389 if (cert->dh_tmp != NULL)
1390 DH_free(cert->dh_tmp);
1391 cert->dh_tmp=new;
1392 return 1;
1393 }
1394 /*break; */
1395 case SSL_CTRL_SET_TMP_DH_CB:
1396 {
1397 SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1398 return(0);
1399 }
1400 break;
1401#endif
1402 /* A Thawte special :-) */
1403 case SSL_CTRL_EXTRA_CHAIN_CERT:
1404 if (ctx->extra_certs == NULL)
1405 {
1406 if ((ctx->extra_certs=sk_X509_new_null()) == NULL)
1407 return(0);
1408 }
1409 sk_X509_push(ctx->extra_certs,(X509 *)parg);
1410 break;
1411
1412 default:
1413 return(0);
1414 }
1415 return(1);
1416 }
1417
1418long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
1419 {
1420 CERT *cert;
1421
1422 cert=ctx->cert;
1423
1424 switch (cmd)
1425 {
1426#ifndef OPENSSL_NO_RSA
1427 case SSL_CTRL_SET_TMP_RSA_CB:
1428 {
1429 cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
1430 }
1431 break;
1432#endif
1433#ifndef OPENSSL_NO_DH
1434 case SSL_CTRL_SET_TMP_DH_CB:
1435 {
1436 cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
1437 }
1438 break;
1439#endif
1440 default:
1441 return(0);
1442 }
1443 return(1);
1444 }
1445
1446/* This function needs to check if the ciphers required are actually
1447 * available */
1448SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
1449 {
1450 static int init=1;
1451 static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS];
1452 SSL_CIPHER c,*cp= &c,**cpp;
1453 unsigned long id;
1454 int i;
1455
1456 if (init)
1457 {
1458 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
1459
1460 if (init)
1461 {
1462 for (i=0; i<SSL3_NUM_CIPHERS; i++)
1463 sorted[i]= &(ssl3_ciphers[i]);
1464
1465 qsort(sorted,
1466 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
1467 FP_ICC ssl_cipher_ptr_id_cmp);
1468
1469 init=0;
1470 }
1471
1472 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
1473 }
1474
1475 id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
1476 c.id=id;
1477 cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp,
1478 (char *)sorted,
1479 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
1480 FP_ICC ssl_cipher_ptr_id_cmp);
1481 if ((cpp == NULL) || !(*cpp)->valid)
1482 return(NULL);
1483 else
1484 return(*cpp);
1485 }
1486
1487int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
1488 {
1489 long l;
1490
1491 if (p != NULL)
1492 {
1493 l=c->id;
1494 if ((l & 0xff000000) != 0x03000000) return(0);
1495 p[0]=((unsigned char)(l>> 8L))&0xFF;
1496 p[1]=((unsigned char)(l ))&0xFF;
1497 }
1498 return(2);
1499 }
1500
1501SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
1502 STACK_OF(SSL_CIPHER) *srvr)
1503 {
1504 SSL_CIPHER *c,*ret=NULL;
1505 STACK_OF(SSL_CIPHER) *prio, *allow;
1506 int i,j,ok;
1507 CERT *cert;
1508 unsigned long alg,mask,emask;
1509
1510 /* Let's see which ciphers we can support */
1511 cert=s->cert;
1512
1513#if 0
1514 /* Do not set the compare functions, because this may lead to a
1515 * reordering by "id". We want to keep the original ordering.
1516 * We may pay a price in performance during sk_SSL_CIPHER_find(),
1517 * but would have to pay with the price of sk_SSL_CIPHER_dup().
1518 */
1519 sk_SSL_CIPHER_set_cmp_func(srvr, ssl_cipher_ptr_id_cmp);
1520 sk_SSL_CIPHER_set_cmp_func(clnt, ssl_cipher_ptr_id_cmp);
1521#endif
1522
1523#ifdef CIPHER_DEBUG
1524 printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr), srvr);
1525 for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i)
1526 {
1527 c=sk_SSL_CIPHER_value(srvr,i);
1528 printf("%p:%s\n",c,c->name);
1529 }
1530 printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt), clnt);
1531 for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i)
1532 {
1533 c=sk_SSL_CIPHER_value(clnt,i);
1534 printf("%p:%s\n",c,c->name);
1535 }
1536#endif
1537
1538 if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE)
1539 {
1540 prio = srvr;
1541 allow = clnt;
1542 }
1543 else
1544 {
1545 prio = clnt;
1546 allow = srvr;
1547 }
1548
1549 for (i=0; i<sk_SSL_CIPHER_num(prio); i++)
1550 {
1551 c=sk_SSL_CIPHER_value(prio,i);
1552
1553 ssl_set_cert_masks(cert,c);
1554 mask=cert->mask;
1555 emask=cert->export_mask;
1556
1557#ifdef KSSL_DEBUG
1558 printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);
1559#endif /* KSSL_DEBUG */
1560
1561 alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1562#ifndef OPENSSL_NO_KRB5
1563 if (alg & SSL_KRB5)
1564 {
1565 if ( !kssl_keytab_is_available(s->kssl_ctx) )
1566 continue;
1567 }
1568#endif /* OPENSSL_NO_KRB5 */
1569 if (SSL_C_IS_EXPORT(c))
1570 {
1571 ok=((alg & emask) == alg)?1:0;
1572#ifdef CIPHER_DEBUG
1573 printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask,
1574 c,c->name);
1575#endif
1576 }
1577 else
1578 {
1579 ok=((alg & mask) == alg)?1:0;
1580#ifdef CIPHER_DEBUG
1581 printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c,
1582 c->name);
1583#endif
1584 }
1585
1586 if (!ok) continue;
1587
1588 j=sk_SSL_CIPHER_find(allow,c);
1589 if (j >= 0)
1590 {
1591 ret=sk_SSL_CIPHER_value(allow,j);
1592 break;
1593 }
1594 }
1595 return(ret);
1596 }
1597
1598int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
1599 {
1600 int ret=0;
1601 unsigned long alg;
1602
1603 alg=s->s3->tmp.new_cipher->algorithms;
1604
1605#ifndef OPENSSL_NO_DH
1606 if (alg & (SSL_kDHr|SSL_kEDH))
1607 {
1608# ifndef OPENSSL_NO_RSA
1609 p[ret++]=SSL3_CT_RSA_FIXED_DH;
1610# endif
1611# ifndef OPENSSL_NO_DSA
1612 p[ret++]=SSL3_CT_DSS_FIXED_DH;
1613# endif
1614 }
1615 if ((s->version == SSL3_VERSION) &&
1616 (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
1617 {
1618# ifndef OPENSSL_NO_RSA
1619 p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH;
1620# endif
1621# ifndef OPENSSL_NO_DSA
1622 p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH;
1623# endif
1624 }
1625#endif /* !OPENSSL_NO_DH */
1626#ifndef OPENSSL_NO_RSA
1627 p[ret++]=SSL3_CT_RSA_SIGN;
1628#endif
1629#ifndef OPENSSL_NO_DSA
1630 p[ret++]=SSL3_CT_DSS_SIGN;
1631#endif
1632 return(ret);
1633 }
1634
1635int ssl3_shutdown(SSL *s)
1636 {
1637
1638 /* Don't do anything much if we have not done the handshake or
1639 * we don't want to send messages :-) */
1640 if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE))
1641 {
1642 s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
1643 return(1);
1644 }
1645
1646 if (!(s->shutdown & SSL_SENT_SHUTDOWN))
1647 {
1648 s->shutdown|=SSL_SENT_SHUTDOWN;
1649#if 1
1650 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY);
1651#endif
1652 /* our shutdown alert has been sent now, and if it still needs
1653 * to be written, s->s3->alert_dispatch will be true */
1654 }
1655 else if (s->s3->alert_dispatch)
1656 {
1657 /* resend it if not sent */
1658#if 1
1659 ssl3_dispatch_alert(s);
1660#endif
1661 }
1662 else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
1663 {
1664 /* If we are waiting for a close from our peer, we are closed */
1665 ssl3_read_bytes(s,0,NULL,0,0);
1666 }
1667
1668 if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
1669 !s->s3->alert_dispatch)
1670 return(1);
1671 else
1672 return(0);
1673 }
1674
1675int ssl3_write(SSL *s, const void *buf, int len)
1676 {
1677 int ret,n;
1678
1679#if 0
1680 if (s->shutdown & SSL_SEND_SHUTDOWN)
1681 {
1682 s->rwstate=SSL_NOTHING;
1683 return(0);
1684 }
1685#endif
1686 clear_sys_error();
1687 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
1688
1689 /* This is an experimental flag that sends the
1690 * last handshake message in the same packet as the first
1691 * use data - used to see if it helps the TCP protocol during
1692 * session-id reuse */
1693 /* The second test is because the buffer may have been removed */
1694 if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
1695 {
1696 /* First time through, we write into the buffer */
1697 if (s->s3->delay_buf_pop_ret == 0)
1698 {
1699 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
1700 buf,len);
1701 if (ret <= 0) return(ret);
1702
1703 s->s3->delay_buf_pop_ret=ret;
1704 }
1705
1706 s->rwstate=SSL_WRITING;
1707 n=BIO_flush(s->wbio);
1708 if (n <= 0) return(n);
1709 s->rwstate=SSL_NOTHING;
1710
1711 /* We have flushed the buffer, so remove it */
1712 ssl_free_wbio_buffer(s);
1713 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
1714
1715 ret=s->s3->delay_buf_pop_ret;
1716 s->s3->delay_buf_pop_ret=0;
1717 }
1718 else
1719 {
1720 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
1721 buf,len);
1722 if (ret <= 0) return(ret);
1723 }
1724
1725 return(ret);
1726 }
1727
1728static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
1729 {
1730 int ret;
1731
1732 clear_sys_error();
1733 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
1734 s->s3->in_read_app_data=1;
1735 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
1736 if ((ret == -1) && (s->s3->in_read_app_data == 2))
1737 {
1738 /* ssl3_read_bytes decided to call s->handshake_func, which
1739 * called ssl3_read_bytes to read handshake data.
1740 * However, ssl3_read_bytes actually found application data
1741 * and thinks that application data makes sense here; so disable
1742 * handshake processing and try to read application data again. */
1743 s->in_handshake++;
1744 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
1745 s->in_handshake--;
1746 }
1747 else
1748 s->s3->in_read_app_data=0;
1749
1750 return(ret);
1751 }
1752
1753int ssl3_read(SSL *s, void *buf, int len)
1754 {
1755 return ssl3_read_internal(s, buf, len, 0);
1756 }
1757
1758int ssl3_peek(SSL *s, void *buf, int len)
1759 {
1760 return ssl3_read_internal(s, buf, len, 1);
1761 }
1762
1763int ssl3_renegotiate(SSL *s)
1764 {
1765 if (s->handshake_func == NULL)
1766 return(1);
1767
1768 if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
1769 return(0);
1770
1771 s->s3->renegotiate=1;
1772 return(1);
1773 }
1774
1775int ssl3_renegotiate_check(SSL *s)
1776 {
1777 int ret=0;
1778
1779 if (s->s3->renegotiate)
1780 {
1781 if ( (s->s3->rbuf.left == 0) &&
1782 (s->s3->wbuf.left == 0) &&
1783 !SSL_in_init(s))
1784 {
1785/*
1786if we are the server, and we have sent a 'RENEGOTIATE' message, we
1787need to go to SSL_ST_ACCEPT.
1788*/
1789 /* SSL_ST_ACCEPT */
1790 s->state=SSL_ST_RENEGOTIATE;
1791 s->s3->renegotiate=0;
1792 s->s3->num_renegotiations++;
1793 s->s3->total_renegotiations++;
1794 ret=1;
1795 }
1796 }
1797 return(ret);
1798 }
1799
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c
deleted file mode 100644
index cb0b12b400..0000000000
--- a/src/lib/libssl/s3_pkt.c
+++ /dev/null
@@ -1,1310 +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-2002 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 "ssl_locl.h"
116#include <openssl/evp.h>
117#include <openssl/buffer.h>
118
119static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
120 unsigned int len, int create_empty_fragment);
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 = s->s3->rbuf.len - s->packet_length;
166 if (max > max_max)
167 max = max_max;
168 }
169 if (n > max) /* does not happen */
170 {
171 SSLerr(SSL_F_SSL3_READ_N,ERR_R_INTERNAL_ERROR);
172 return -1;
173 }
174
175 off = s->packet_length;
176 newb = s->s3->rbuf.left;
177 /* Move any available bytes to front of buffer:
178 * 'off' bytes already pointed to by 'packet',
179 * 'newb' extra ones at the end */
180 if (s->packet != s->s3->rbuf.buf)
181 {
182 /* off > 0 */
183 memmove(s->s3->rbuf.buf, s->packet, off+newb);
184 s->packet = s->s3->rbuf.buf;
185 }
186
187 while (newb < n)
188 {
189 /* Now we have off+newb bytes at the front of s->s3->rbuf.buf and need
190 * to read in more until we have off+n (up to off+max if possible) */
191
192 clear_sys_error();
193 if (s->rbio != NULL)
194 {
195 s->rwstate=SSL_READING;
196 i=BIO_read(s->rbio, &(s->s3->rbuf.buf[off+newb]), max-newb);
197 }
198 else
199 {
200 SSLerr(SSL_F_SSL3_READ_N,SSL_R_READ_BIO_NOT_SET);
201 i = -1;
202 }
203
204 if (i <= 0)
205 {
206 s->s3->rbuf.left = newb;
207 return(i);
208 }
209 newb+=i;
210 }
211
212 /* done reading, now the book-keeping */
213 s->s3->rbuf.offset = off + n;
214 s->s3->rbuf.left = newb - n;
215 s->packet_length += n;
216 s->rwstate=SSL_NOTHING;
217 return(n);
218 }
219
220/* Call this to get a new input record.
221 * It will return <= 0 if more data is needed, normally due to an error
222 * or non-blocking IO.
223 * When it finishes, one packet has been decoded and can be found in
224 * ssl->s3->rrec.type - is the type of record
225 * ssl->s3->rrec.data, - data
226 * ssl->s3->rrec.length, - number of bytes
227 */
228/* used only by ssl3_read_bytes */
229static int ssl3_get_record(SSL *s)
230 {
231 int ssl_major,ssl_minor,al;
232 int enc_err,n,i,ret= -1;
233 SSL3_RECORD *rr;
234 SSL_SESSION *sess;
235 unsigned char *p;
236 unsigned char md[EVP_MAX_MD_SIZE];
237 short version;
238 unsigned int mac_size;
239 int clear=0;
240 size_t extra;
241 int decryption_failed_or_bad_record_mac = 0;
242 unsigned char *mac = NULL;
243
244 rr= &(s->s3->rrec);
245 sess=s->session;
246
247 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
248 extra=SSL3_RT_MAX_EXTRA;
249 else
250 extra=0;
251 if (extra != s->s3->rbuf.len - SSL3_RT_MAX_PACKET_SIZE)
252 {
253 /* actually likely an application error: SLS_OP_MICROSOFT_BIG_SSLV3_BUFFER
254 * set after ssl3_setup_buffers() was done */
255 SSLerr(SSL_F_SSL3_GET_RECORD, ERR_R_INTERNAL_ERROR);
256 return -1;
257 }
258
259again:
260 /* check if we have the header */
261 if ( (s->rstate != SSL_ST_READ_BODY) ||
262 (s->packet_length < SSL3_RT_HEADER_LENGTH))
263 {
264 n=ssl3_read_n(s, SSL3_RT_HEADER_LENGTH, s->s3->rbuf.len, 0);
265 if (n <= 0) return(n); /* error or non-blocking */
266 s->rstate=SSL_ST_READ_BODY;
267
268 p=s->packet;
269
270 /* Pull apart the header into the SSL3_RECORD */
271 rr->type= *(p++);
272 ssl_major= *(p++);
273 ssl_minor= *(p++);
274 version=(ssl_major<<8)|ssl_minor;
275 n2s(p,rr->length);
276
277 /* Lets check version */
278 if (s->first_packet)
279 {
280 s->first_packet=0;
281 }
282 else
283 {
284 if (version != s->version)
285 {
286 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
287 /* Send back error using their
288 * version number :-) */
289 s->version=version;
290 al=SSL_AD_PROTOCOL_VERSION;
291 goto f_err;
292 }
293 }
294
295 if ((version>>8) != SSL3_VERSION_MAJOR)
296 {
297 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
298 goto err;
299 }
300
301 if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
302 {
303 al=SSL_AD_RECORD_OVERFLOW;
304 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG);
305 goto f_err;
306 }
307
308 /* now s->rstate == SSL_ST_READ_BODY */
309 }
310
311 /* s->rstate == SSL_ST_READ_BODY, get and decode the data */
312
313 if (rr->length > s->packet_length-SSL3_RT_HEADER_LENGTH)
314 {
315 /* now s->packet_length == SSL3_RT_HEADER_LENGTH */
316 i=rr->length;
317 n=ssl3_read_n(s,i,i,1);
318 if (n <= 0) return(n); /* error or non-blocking io */
319 /* now n == rr->length,
320 * and s->packet_length == SSL3_RT_HEADER_LENGTH + rr->length */
321 }
322
323 s->rstate=SSL_ST_READ_HEADER; /* set state for later operations */
324
325 /* At this point, s->packet_length == SSL3_RT_HEADER_LNGTH + rr->length,
326 * and we have that many bytes in s->packet
327 */
328 rr->input= &(s->packet[SSL3_RT_HEADER_LENGTH]);
329
330 /* ok, we can now read from 's->packet' data into 'rr'
331 * rr->input points at rr->length bytes, which
332 * need to be copied into rr->data by either
333 * the decryption or by the decompression
334 * When the data is 'copied' into the rr->data buffer,
335 * rr->input will be pointed at the new buffer */
336
337 /* We now have - encrypted [ MAC [ compressed [ plain ] ] ]
338 * rr->length bytes of encrypted compressed stuff. */
339
340 /* check is not needed I believe */
341 if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
342 {
343 al=SSL_AD_RECORD_OVERFLOW;
344 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG);
345 goto f_err;
346 }
347
348 /* decrypt in place in 'rr->input' */
349 rr->data=rr->input;
350
351 enc_err = s->method->ssl3_enc->enc(s,0);
352 if (enc_err <= 0)
353 {
354 if (enc_err == 0)
355 /* SSLerr() and ssl3_send_alert() have been called */
356 goto err;
357
358 /* Otherwise enc_err == -1, which indicates bad padding
359 * (rec->length has not been changed in this case).
360 * To minimize information leaked via timing, we will perform
361 * the MAC computation anyway. */
362 decryption_failed_or_bad_record_mac = 1;
363 }
364
365#ifdef TLS_DEBUG
366printf("dec %d\n",rr->length);
367{ unsigned int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?' ':'\n'); }
368printf("\n");
369#endif
370
371 /* r->length is now the compressed data plus mac */
372 if ( (sess == NULL) ||
373 (s->enc_read_ctx == NULL) ||
374 (s->read_hash == NULL))
375 clear=1;
376
377 if (!clear)
378 {
379 mac_size=EVP_MD_size(s->read_hash);
380
381 if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra+mac_size)
382 {
383#if 0 /* OK only for stream ciphers (then rr->length is visible from ciphertext anyway) */
384 al=SSL_AD_RECORD_OVERFLOW;
385 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG);
386 goto f_err;
387#else
388 decryption_failed_or_bad_record_mac = 1;
389#endif
390 }
391 /* check the MAC for rr->input (it's in mac_size bytes at the tail) */
392 if (rr->length >= mac_size)
393 {
394 rr->length -= mac_size;
395 mac = &rr->data[rr->length];
396 }
397 else
398 {
399 /* record (minus padding) is too short to contain a MAC */
400#if 0 /* OK only for stream ciphers */
401 al=SSL_AD_DECODE_ERROR;
402 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT);
403 goto f_err;
404#else
405 decryption_failed_or_bad_record_mac = 1;
406 rr->length = 0;
407#endif
408 }
409 i=s->method->ssl3_enc->mac(s,md,0);
410 if (mac == NULL || memcmp(md, mac, mac_size) != 0)
411 {
412 decryption_failed_or_bad_record_mac = 1;
413 }
414 }
415
416 if (decryption_failed_or_bad_record_mac)
417 {
418 /* A separate 'decryption_failed' alert was introduced with TLS 1.0,
419 * SSL 3.0 only has 'bad_record_mac'. But unless a decryption
420 * failure is directly visible from the ciphertext anyway,
421 * we should not reveal which kind of error occured -- this
422 * might become visible to an attacker (e.g. via a logfile) */
423 al=SSL_AD_BAD_RECORD_MAC;
424 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC);
425 goto f_err;
426 }
427
428 /* r->length is now just compressed */
429 if (s->expand != NULL)
430 {
431 if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra)
432 {
433 al=SSL_AD_RECORD_OVERFLOW;
434 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG);
435 goto f_err;
436 }
437 if (!do_uncompress(s))
438 {
439 al=SSL_AD_DECOMPRESSION_FAILURE;
440 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION);
441 goto f_err;
442 }
443 }
444
445 if (rr->length > SSL3_RT_MAX_PLAIN_LENGTH+extra)
446 {
447 al=SSL_AD_RECORD_OVERFLOW;
448 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DATA_LENGTH_TOO_LONG);
449 goto f_err;
450 }
451
452 rr->off=0;
453 /* So at this point the following is true
454 * ssl->s3->rrec.type is the type of record
455 * ssl->s3->rrec.length == number of bytes in record
456 * ssl->s3->rrec.off == offset to first valid byte
457 * ssl->s3->rrec.data == where to take bytes from, increment
458 * after use :-).
459 */
460
461 /* we have pulled in a full packet so zero things */
462 s->packet_length=0;
463
464 /* just read a 0 length packet */
465 if (rr->length == 0) goto again;
466
467 return(1);
468
469f_err:
470 ssl3_send_alert(s,SSL3_AL_FATAL,al);
471err:
472 return(ret);
473 }
474
475static int do_uncompress(SSL *ssl)
476 {
477 int i;
478 SSL3_RECORD *rr;
479
480 rr= &(ssl->s3->rrec);
481 i=COMP_expand_block(ssl->expand,rr->comp,
482 SSL3_RT_MAX_PLAIN_LENGTH,rr->data,(int)rr->length);
483 if (i < 0)
484 return(0);
485 else
486 rr->length=i;
487 rr->data=rr->comp;
488
489 return(1);
490 }
491
492static int do_compress(SSL *ssl)
493 {
494 int i;
495 SSL3_RECORD *wr;
496
497 wr= &(ssl->s3->wrec);
498 i=COMP_compress_block(ssl->compress,wr->data,
499 SSL3_RT_MAX_COMPRESSED_LENGTH,
500 wr->input,(int)wr->length);
501 if (i < 0)
502 return(0);
503 else
504 wr->length=i;
505
506 wr->input=wr->data;
507 return(1);
508 }
509
510/* Call this to write data in records of type 'type'
511 * It will return <= 0 if not all data has been sent or non-blocking IO.
512 */
513int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
514 {
515 const unsigned char *buf=buf_;
516 unsigned int tot,n,nw;
517 int i;
518
519 s->rwstate=SSL_NOTHING;
520 tot=s->s3->wnum;
521 s->s3->wnum=0;
522
523 if (SSL_in_init(s) && !s->in_handshake)
524 {
525 i=s->handshake_func(s);
526 if (i < 0) return(i);
527 if (i == 0)
528 {
529 SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
530 return -1;
531 }
532 }
533
534 n=(len-tot);
535 for (;;)
536 {
537 if (n > SSL3_RT_MAX_PLAIN_LENGTH)
538 nw=SSL3_RT_MAX_PLAIN_LENGTH;
539 else
540 nw=n;
541
542 i=do_ssl3_write(s, type, &(buf[tot]), nw, 0);
543 if (i <= 0)
544 {
545 s->s3->wnum=tot;
546 return i;
547 }
548
549 if ((i == (int)n) ||
550 (type == SSL3_RT_APPLICATION_DATA &&
551 (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE)))
552 {
553 /* next chunk of data should get another prepended empty fragment
554 * in ciphersuites with known-IV weakness: */
555 s->s3->empty_fragment_done = 0;
556
557 return tot+i;
558 }
559
560 n-=i;
561 tot+=i;
562 }
563 }
564
565static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
566 unsigned int len, int create_empty_fragment)
567 {
568 unsigned char *p,*plen;
569 int i,mac_size,clear=0;
570 int prefix_len = 0;
571 SSL3_RECORD *wr;
572 SSL3_BUFFER *wb;
573 SSL_SESSION *sess;
574
575 /* first check if there is a SSL3_BUFFER still being written
576 * out. This will happen with non blocking IO */
577 if (s->s3->wbuf.left != 0)
578 return(ssl3_write_pending(s,type,buf,len));
579
580 /* If we have an alert to send, lets send it */
581 if (s->s3->alert_dispatch)
582 {
583 i=ssl3_dispatch_alert(s);
584 if (i <= 0)
585 return(i);
586 /* if it went, fall through and send more stuff */
587 }
588
589 if (len == 0 && !create_empty_fragment)
590 return 0;
591
592 wr= &(s->s3->wrec);
593 wb= &(s->s3->wbuf);
594 sess=s->session;
595
596 if ( (sess == NULL) ||
597 (s->enc_write_ctx == NULL) ||
598 (s->write_hash == NULL))
599 clear=1;
600
601 if (clear)
602 mac_size=0;
603 else
604 mac_size=EVP_MD_size(s->write_hash);
605
606 /* 'create_empty_fragment' is true only when this function calls itself */
607 if (!clear && !create_empty_fragment && !s->s3->empty_fragment_done)
608 {
609 /* countermeasure against known-IV weakness in CBC ciphersuites
610 * (see http://www.openssl.org/~bodo/tls-cbc.txt) */
611
612 if (s->s3->need_empty_fragments && type == SSL3_RT_APPLICATION_DATA)
613 {
614 /* recursive function call with 'create_empty_fragment' set;
615 * this prepares and buffers the data for an empty fragment
616 * (these 'prefix_len' bytes are sent out later
617 * together with the actual payload) */
618 prefix_len = do_ssl3_write(s, type, buf, 0, 1);
619 if (prefix_len <= 0)
620 goto err;
621
622 if (s->s3->wbuf.len < (size_t)prefix_len + SSL3_RT_MAX_PACKET_SIZE)
623 {
624 /* insufficient space */
625 SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR);
626 goto err;
627 }
628 }
629
630 s->s3->empty_fragment_done = 1;
631 }
632
633 p = wb->buf + prefix_len;
634
635 /* write the header */
636
637 *(p++)=type&0xff;
638 wr->type=type;
639
640 *(p++)=(s->version>>8);
641 *(p++)=s->version&0xff;
642
643 /* field where we are to write out packet length */
644 plen=p;
645 p+=2;
646
647 /* lets setup the record stuff. */
648 wr->data=p;
649 wr->length=(int)len;
650 wr->input=(unsigned char *)buf;
651
652 /* we now 'read' from wr->input, wr->length bytes into
653 * wr->data */
654
655 /* first we compress */
656 if (s->compress != NULL)
657 {
658 if (!do_compress(s))
659 {
660 SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE);
661 goto err;
662 }
663 }
664 else
665 {
666 memcpy(wr->data,wr->input,wr->length);
667 wr->input=wr->data;
668 }
669
670 /* we should still have the output to wr->data and the input
671 * from wr->input. Length should be wr->length.
672 * wr->data still points in the wb->buf */
673
674 if (mac_size != 0)
675 {
676 s->method->ssl3_enc->mac(s,&(p[wr->length]),1);
677 wr->length+=mac_size;
678 wr->input=p;
679 wr->data=p;
680 }
681
682 /* ssl3_enc can only have an error on read */
683 s->method->ssl3_enc->enc(s,1);
684
685 /* record length after mac and block padding */
686 s2n(wr->length,plen);
687
688 /* we should now have
689 * wr->data pointing to the encrypted data, which is
690 * wr->length long */
691 wr->type=type; /* not needed but helps for debugging */
692 wr->length+=SSL3_RT_HEADER_LENGTH;
693
694 if (create_empty_fragment)
695 {
696 /* we are in a recursive call;
697 * just return the length, don't write out anything here
698 */
699 return wr->length;
700 }
701
702 /* now let's set up wb */
703 wb->left = prefix_len + wr->length;
704 wb->offset = 0;
705
706 /* memorize arguments so that ssl3_write_pending can detect bad write retries later */
707 s->s3->wpend_tot=len;
708 s->s3->wpend_buf=buf;
709 s->s3->wpend_type=type;
710 s->s3->wpend_ret=len;
711
712 /* we now just need to write the buffer */
713 return ssl3_write_pending(s,type,buf,len);
714err:
715 return -1;
716 }
717
718/* if s->s3->wbuf.left != 0, we need to call this */
719static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
720 unsigned int len)
721 {
722 int i;
723
724/* XXXX */
725 if ((s->s3->wpend_tot > (int)len)
726 || ((s->s3->wpend_buf != buf) &&
727 !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))
728 || (s->s3->wpend_type != type))
729 {
730 SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BAD_WRITE_RETRY);
731 return(-1);
732 }
733
734 for (;;)
735 {
736 clear_sys_error();
737 if (s->wbio != NULL)
738 {
739 s->rwstate=SSL_WRITING;
740 i=BIO_write(s->wbio,
741 (char *)&(s->s3->wbuf.buf[s->s3->wbuf.offset]),
742 (unsigned int)s->s3->wbuf.left);
743 }
744 else
745 {
746 SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BIO_NOT_SET);
747 i= -1;
748 }
749 if (i == s->s3->wbuf.left)
750 {
751 s->s3->wbuf.left=0;
752 s->rwstate=SSL_NOTHING;
753 return(s->s3->wpend_ret);
754 }
755 else if (i <= 0)
756 return(i);
757 s->s3->wbuf.offset+=i;
758 s->s3->wbuf.left-=i;
759 }
760 }
761
762/* Return up to 'len' payload bytes received in 'type' records.
763 * 'type' is one of the following:
764 *
765 * - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
766 * - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us)
767 * - 0 (during a shutdown, no data has to be returned)
768 *
769 * If we don't have stored data to work from, read a SSL/TLS record first
770 * (possibly multiple records if we still don't have anything to return).
771 *
772 * This function must handle any surprises the peer may have for us, such as
773 * Alert records (e.g. close_notify), ChangeCipherSpec records (not really
774 * a surprise, but handled as if it were), or renegotiation requests.
775 * Also if record payloads contain fragments too small to process, we store
776 * them until there is enough for the respective protocol (the record protocol
777 * may use arbitrary fragmentation and even interleaving):
778 * Change cipher spec protocol
779 * just 1 byte needed, no need for keeping anything stored
780 * Alert protocol
781 * 2 bytes needed (AlertLevel, AlertDescription)
782 * Handshake protocol
783 * 4 bytes needed (HandshakeType, uint24 length) -- we just have
784 * to detect unexpected Client Hello and Hello Request messages
785 * here, anything else is handled by higher layers
786 * Application data protocol
787 * none of our business
788 */
789int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
790 {
791 int al,i,j,ret;
792 unsigned int n;
793 SSL3_RECORD *rr;
794 void (*cb)(const SSL *ssl,int type2,int val)=NULL;
795
796 if (s->s3->rbuf.buf == NULL) /* Not initialized yet */
797 if (!ssl3_setup_buffers(s))
798 return(-1);
799
800 if ((type && (type != SSL3_RT_APPLICATION_DATA) && (type != SSL3_RT_HANDSHAKE) && type) ||
801 (peek && (type != SSL3_RT_APPLICATION_DATA)))
802 {
803 SSLerr(SSL_F_SSL3_READ_BYTES, ERR_R_INTERNAL_ERROR);
804 return -1;
805 }
806
807 if ((type == SSL3_RT_HANDSHAKE) && (s->s3->handshake_fragment_len > 0))
808 /* (partially) satisfy request from storage */
809 {
810 unsigned char *src = s->s3->handshake_fragment;
811 unsigned char *dst = buf;
812 unsigned int k;
813
814 /* peek == 0 */
815 n = 0;
816 while ((len > 0) && (s->s3->handshake_fragment_len > 0))
817 {
818 *dst++ = *src++;
819 len--; s->s3->handshake_fragment_len--;
820 n++;
821 }
822 /* move any remaining fragment bytes: */
823 for (k = 0; k < s->s3->handshake_fragment_len; k++)
824 s->s3->handshake_fragment[k] = *src++;
825 return n;
826 }
827
828 /* Now s->s3->handshake_fragment_len == 0 if type == SSL3_RT_HANDSHAKE. */
829
830 if (!s->in_handshake && SSL_in_init(s))
831 {
832 /* type == SSL3_RT_APPLICATION_DATA */
833 i=s->handshake_func(s);
834 if (i < 0) return(i);
835 if (i == 0)
836 {
837 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
838 return(-1);
839 }
840 }
841start:
842 s->rwstate=SSL_NOTHING;
843
844 /* s->s3->rrec.type - is the type of record
845 * s->s3->rrec.data, - data
846 * s->s3->rrec.off, - offset into 'data' for next read
847 * s->s3->rrec.length, - number of bytes. */
848 rr = &(s->s3->rrec);
849
850 /* get new packet if necessary */
851 if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY))
852 {
853 ret=ssl3_get_record(s);
854 if (ret <= 0) return(ret);
855 }
856
857 /* we now have a packet which can be read and processed */
858
859 if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
860 * reset by ssl3_get_finished */
861 && (rr->type != SSL3_RT_HANDSHAKE))
862 {
863 al=SSL_AD_UNEXPECTED_MESSAGE;
864 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED);
865 goto f_err;
866 }
867
868 /* If the other end has shut down, throw anything we read away
869 * (even in 'peek' mode) */
870 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
871 {
872 rr->length=0;
873 s->rwstate=SSL_NOTHING;
874 return(0);
875 }
876
877
878 if (type == rr->type) /* SSL3_RT_APPLICATION_DATA or SSL3_RT_HANDSHAKE */
879 {
880 /* make sure that we are not getting application data when we
881 * are doing a handshake for the first time */
882 if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&
883 (s->enc_read_ctx == NULL))
884 {
885 al=SSL_AD_UNEXPECTED_MESSAGE;
886 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE);
887 goto f_err;
888 }
889
890 if (len <= 0) return(len);
891
892 if ((unsigned int)len > rr->length)
893 n = rr->length;
894 else
895 n = (unsigned int)len;
896
897 memcpy(buf,&(rr->data[rr->off]),n);
898 if (!peek)
899 {
900 rr->length-=n;
901 rr->off+=n;
902 if (rr->length == 0)
903 {
904 s->rstate=SSL_ST_READ_HEADER;
905 rr->off=0;
906 }
907 }
908 return(n);
909 }
910
911
912 /* If we get here, then type != rr->type; if we have a handshake
913 * message, then it was unexpected (Hello Request or Client Hello). */
914
915 /* In case of record types for which we have 'fragment' storage,
916 * fill that so that we can process the data at a fixed place.
917 */
918 {
919 unsigned int dest_maxlen = 0;
920 unsigned char *dest = NULL;
921 unsigned int *dest_len = NULL;
922
923 if (rr->type == SSL3_RT_HANDSHAKE)
924 {
925 dest_maxlen = sizeof s->s3->handshake_fragment;
926 dest = s->s3->handshake_fragment;
927 dest_len = &s->s3->handshake_fragment_len;
928 }
929 else if (rr->type == SSL3_RT_ALERT)
930 {
931 dest_maxlen = sizeof s->s3->alert_fragment;
932 dest = s->s3->alert_fragment;
933 dest_len = &s->s3->alert_fragment_len;
934 }
935
936 if (dest_maxlen > 0)
937 {
938 n = dest_maxlen - *dest_len; /* available space in 'dest' */
939 if (rr->length < n)
940 n = rr->length; /* available bytes */
941
942 /* now move 'n' bytes: */
943 while (n-- > 0)
944 {
945 dest[(*dest_len)++] = rr->data[rr->off++];
946 rr->length--;
947 }
948
949 if (*dest_len < dest_maxlen)
950 goto start; /* fragment was too small */
951 }
952 }
953
954 /* s->s3->handshake_fragment_len == 4 iff rr->type == SSL3_RT_HANDSHAKE;
955 * s->s3->alert_fragment_len == 2 iff rr->type == SSL3_RT_ALERT.
956 * (Possibly rr is 'empty' now, i.e. rr->length may be 0.) */
957
958 /* If we are a client, check for an incoming 'Hello Request': */
959 if ((!s->server) &&
960 (s->s3->handshake_fragment_len >= 4) &&
961 (s->s3->handshake_fragment[0] == SSL3_MT_HELLO_REQUEST) &&
962 (s->session != NULL) && (s->session->cipher != NULL))
963 {
964 s->s3->handshake_fragment_len = 0;
965
966 if ((s->s3->handshake_fragment[1] != 0) ||
967 (s->s3->handshake_fragment[2] != 0) ||
968 (s->s3->handshake_fragment[3] != 0))
969 {
970 al=SSL_AD_DECODE_ERROR;
971 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_HELLO_REQUEST);
972 goto f_err;
973 }
974
975 if (s->msg_callback)
976 s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, s->s3->handshake_fragment, 4, s, s->msg_callback_arg);
977
978 if (SSL_is_init_finished(s) &&
979 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&
980 !s->s3->renegotiate)
981 {
982 ssl3_renegotiate(s);
983 if (ssl3_renegotiate_check(s))
984 {
985 i=s->handshake_func(s);
986 if (i < 0) return(i);
987 if (i == 0)
988 {
989 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
990 return(-1);
991 }
992
993 if (!(s->mode & SSL_MODE_AUTO_RETRY))
994 {
995 if (s->s3->rbuf.left == 0) /* no read-ahead left? */
996 {
997 BIO *bio;
998 /* In the case where we try to read application data,
999 * but we trigger an SSL handshake, we return -1 with
1000 * the retry option set. Otherwise renegotiation may
1001 * cause nasty problems in the blocking world */
1002 s->rwstate=SSL_READING;
1003 bio=SSL_get_rbio(s);
1004 BIO_clear_retry_flags(bio);
1005 BIO_set_retry_read(bio);
1006 return(-1);
1007 }
1008 }
1009 }
1010 }
1011 /* we either finished a handshake or ignored the request,
1012 * now try again to obtain the (application) data we were asked for */
1013 goto start;
1014 }
1015
1016 if (s->s3->alert_fragment_len >= 2)
1017 {
1018 int alert_level = s->s3->alert_fragment[0];
1019 int alert_descr = s->s3->alert_fragment[1];
1020
1021 s->s3->alert_fragment_len = 0;
1022
1023 if (s->msg_callback)
1024 s->msg_callback(0, s->version, SSL3_RT_ALERT, s->s3->alert_fragment, 2, s, s->msg_callback_arg);
1025
1026 if (s->info_callback != NULL)
1027 cb=s->info_callback;
1028 else if (s->ctx->info_callback != NULL)
1029 cb=s->ctx->info_callback;
1030
1031 if (cb != NULL)
1032 {
1033 j = (alert_level << 8) | alert_descr;
1034 cb(s, SSL_CB_READ_ALERT, j);
1035 }
1036
1037 if (alert_level == 1) /* warning */
1038 {
1039 s->s3->warn_alert = alert_descr;
1040 if (alert_descr == SSL_AD_CLOSE_NOTIFY)
1041 {
1042 s->shutdown |= SSL_RECEIVED_SHUTDOWN;
1043 return(0);
1044 }
1045 }
1046 else if (alert_level == 2) /* fatal */
1047 {
1048 char tmp[16];
1049
1050 s->rwstate=SSL_NOTHING;
1051 s->s3->fatal_alert = alert_descr;
1052 SSLerr(SSL_F_SSL3_READ_BYTES, SSL_AD_REASON_OFFSET + alert_descr);
1053 BIO_snprintf(tmp,sizeof tmp,"%d",alert_descr);
1054 ERR_add_error_data(2,"SSL alert number ",tmp);
1055 s->shutdown|=SSL_RECEIVED_SHUTDOWN;
1056 SSL_CTX_remove_session(s->ctx,s->session);
1057 return(0);
1058 }
1059 else
1060 {
1061 al=SSL_AD_ILLEGAL_PARAMETER;
1062 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE);
1063 goto f_err;
1064 }
1065
1066 goto start;
1067 }
1068
1069 if (s->shutdown & SSL_SENT_SHUTDOWN) /* but we have not received a shutdown */
1070 {
1071 s->rwstate=SSL_NOTHING;
1072 rr->length=0;
1073 return(0);
1074 }
1075
1076 if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC)
1077 {
1078 /* 'Change Cipher Spec' is just a single byte, so we know
1079 * exactly what the record payload has to look like */
1080 if ( (rr->length != 1) || (rr->off != 0) ||
1081 (rr->data[0] != SSL3_MT_CCS))
1082 {
1083 al=SSL_AD_ILLEGAL_PARAMETER;
1084 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC);
1085 goto f_err;
1086 }
1087
1088 /* Check we have a cipher to change to */
1089 if (s->s3->tmp.new_cipher == NULL)
1090 {
1091 al=SSL_AD_UNEXPECTED_MESSAGE;
1092 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY);
1093 goto f_err;
1094 }
1095
1096 rr->length=0;
1097
1098 if (s->msg_callback)
1099 s->msg_callback(0, s->version, SSL3_RT_CHANGE_CIPHER_SPEC, rr->data, 1, s, s->msg_callback_arg);
1100
1101 s->s3->change_cipher_spec=1;
1102 if (!do_change_cipher_spec(s))
1103 goto err;
1104 else
1105 goto start;
1106 }
1107
1108 /* Unexpected handshake message (Client Hello, or protocol violation) */
1109 if ((s->s3->handshake_fragment_len >= 4) && !s->in_handshake)
1110 {
1111 if (((s->state&SSL_ST_MASK) == SSL_ST_OK) &&
1112 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS))
1113 {
1114#if 0 /* worked only because C operator preferences are not as expected (and
1115 * because this is not really needed for clients except for detecting
1116 * protocol violations): */
1117 s->state=SSL_ST_BEFORE|(s->server)
1118 ?SSL_ST_ACCEPT
1119 :SSL_ST_CONNECT;
1120#else
1121 s->state = s->server ? SSL_ST_ACCEPT : SSL_ST_CONNECT;
1122#endif
1123 s->new_session=1;
1124 }
1125 i=s->handshake_func(s);
1126 if (i < 0) return(i);
1127 if (i == 0)
1128 {
1129 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
1130 return(-1);
1131 }
1132
1133 if (!(s->mode & SSL_MODE_AUTO_RETRY))
1134 {
1135 if (s->s3->rbuf.left == 0) /* no read-ahead left? */
1136 {
1137 BIO *bio;
1138 /* In the case where we try to read application data,
1139 * but we trigger an SSL handshake, we return -1 with
1140 * the retry option set. Otherwise renegotiation may
1141 * cause nasty problems in the blocking world */
1142 s->rwstate=SSL_READING;
1143 bio=SSL_get_rbio(s);
1144 BIO_clear_retry_flags(bio);
1145 BIO_set_retry_read(bio);
1146 return(-1);
1147 }
1148 }
1149 goto start;
1150 }
1151
1152 switch (rr->type)
1153 {
1154 default:
1155#ifndef OPENSSL_NO_TLS
1156 /* TLS just ignores unknown message types */
1157 if (s->version == TLS1_VERSION)
1158 {
1159 rr->length = 0;
1160 goto start;
1161 }
1162#endif
1163 al=SSL_AD_UNEXPECTED_MESSAGE;
1164 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
1165 goto f_err;
1166 case SSL3_RT_CHANGE_CIPHER_SPEC:
1167 case SSL3_RT_ALERT:
1168 case SSL3_RT_HANDSHAKE:
1169 /* we already handled all of these, with the possible exception
1170 * of SSL3_RT_HANDSHAKE when s->in_handshake is set, but that
1171 * should not happen when type != rr->type */
1172 al=SSL_AD_UNEXPECTED_MESSAGE;
1173 SSLerr(SSL_F_SSL3_READ_BYTES,ERR_R_INTERNAL_ERROR);
1174 goto f_err;
1175 case SSL3_RT_APPLICATION_DATA:
1176 /* At this point, we were expecting handshake data,
1177 * but have application data. If the library was
1178 * running inside ssl3_read() (i.e. in_read_app_data
1179 * is set) and it makes sense to read application data
1180 * at this point (session renegotiation not yet started),
1181 * we will indulge it.
1182 */
1183 if (s->s3->in_read_app_data &&
1184 (s->s3->total_renegotiations != 0) &&
1185 ((
1186 (s->state & SSL_ST_CONNECT) &&
1187 (s->state >= SSL3_ST_CW_CLNT_HELLO_A) &&
1188 (s->state <= SSL3_ST_CR_SRVR_HELLO_A)
1189 ) || (
1190 (s->state & SSL_ST_ACCEPT) &&
1191 (s->state <= SSL3_ST_SW_HELLO_REQ_A) &&
1192 (s->state >= SSL3_ST_SR_CLNT_HELLO_A)
1193 )
1194 ))
1195 {
1196 s->s3->in_read_app_data=2;
1197 return(-1);
1198 }
1199 else
1200 {
1201 al=SSL_AD_UNEXPECTED_MESSAGE;
1202 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
1203 goto f_err;
1204 }
1205 }
1206 /* not reached */
1207
1208f_err:
1209 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1210err:
1211 return(-1);
1212 }
1213
1214static int do_change_cipher_spec(SSL *s)
1215 {
1216 int i;
1217 const char *sender;
1218 int slen;
1219
1220 if (s->state & SSL_ST_ACCEPT)
1221 i=SSL3_CHANGE_CIPHER_SERVER_READ;
1222 else
1223 i=SSL3_CHANGE_CIPHER_CLIENT_READ;
1224
1225 if (s->s3->tmp.key_block == NULL)
1226 {
1227 s->session->cipher=s->s3->tmp.new_cipher;
1228 if (!s->method->ssl3_enc->setup_key_block(s)) return(0);
1229 }
1230
1231 if (!s->method->ssl3_enc->change_cipher_state(s,i))
1232 return(0);
1233
1234 /* we have to record the message digest at
1235 * this point so we can get it before we read
1236 * the finished message */
1237 if (s->state & SSL_ST_CONNECT)
1238 {
1239 sender=s->method->ssl3_enc->server_finished_label;
1240 slen=s->method->ssl3_enc->server_finished_label_len;
1241 }
1242 else
1243 {
1244 sender=s->method->ssl3_enc->client_finished_label;
1245 slen=s->method->ssl3_enc->client_finished_label_len;
1246 }
1247
1248 s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
1249 &(s->s3->finish_dgst1),
1250 &(s->s3->finish_dgst2),
1251 sender,slen,s->s3->tmp.peer_finish_md);
1252
1253 return(1);
1254 }
1255
1256void ssl3_send_alert(SSL *s, int level, int desc)
1257 {
1258 /* Map tls/ssl alert value to correct one */
1259 desc=s->method->ssl3_enc->alert_value(desc);
1260 if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)
1261 desc = SSL_AD_HANDSHAKE_FAILURE; /* SSL 3.0 does not have protocol_version alerts */
1262 if (desc < 0) return;
1263 /* If a fatal one, remove from cache */
1264 if ((level == 2) && (s->session != NULL))
1265 SSL_CTX_remove_session(s->ctx,s->session);
1266
1267 s->s3->alert_dispatch=1;
1268 s->s3->send_alert[0]=level;
1269 s->s3->send_alert[1]=desc;
1270 if (s->s3->wbuf.left == 0) /* data still being written out? */
1271 ssl3_dispatch_alert(s);
1272 /* else data is still being written out, we will get written
1273 * some time in the future */
1274 }
1275
1276int ssl3_dispatch_alert(SSL *s)
1277 {
1278 int i,j;
1279 void (*cb)(const SSL *ssl,int type,int val)=NULL;
1280
1281 s->s3->alert_dispatch=0;
1282 i = do_ssl3_write(s, SSL3_RT_ALERT, &s->s3->send_alert[0], 2, 0);
1283 if (i <= 0)
1284 {
1285 s->s3->alert_dispatch=1;
1286 }
1287 else
1288 {
1289 /* Alert sent to BIO. If it is important, flush it now.
1290 * If the message does not get sent due to non-blocking IO,
1291 * we will not worry too much. */
1292 if (s->s3->send_alert[0] == SSL3_AL_FATAL)
1293 (void)BIO_flush(s->wbio);
1294
1295 if (s->msg_callback)
1296 s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3->send_alert, 2, s, s->msg_callback_arg);
1297
1298 if (s->info_callback != NULL)
1299 cb=s->info_callback;
1300 else if (s->ctx->info_callback != NULL)
1301 cb=s->ctx->info_callback;
1302
1303 if (cb != NULL)
1304 {
1305 j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1];
1306 cb(s,SSL_CB_WRITE_ALERT,j);
1307 }
1308 }
1309 return(i);
1310 }
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c
deleted file mode 100644
index 36fc39d7f8..0000000000
--- a/src/lib/libssl/s3_srvr.c
+++ /dev/null
@@ -1,2082 +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 * Copyright (c) 1998-2002 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#define REUSE_CIPHER_BUG
113#define NETSCAPE_HANG_BUG
114
115
116#include <stdio.h>
117#include "ssl_locl.h"
118#include "kssl_lcl.h"
119#include <openssl/buffer.h>
120#include <openssl/rand.h>
121#include <openssl/objects.h>
122#include <openssl/evp.h>
123#include <openssl/x509.h>
124#ifndef OPENSSL_NO_KRB5
125#include <openssl/krb5_asn.h>
126#endif
127#include <openssl/md5.h>
128#include <openssl/fips.h>
129
130static SSL_METHOD *ssl3_get_server_method(int ver);
131static int ssl3_get_client_hello(SSL *s);
132static int ssl3_check_client_hello(SSL *s);
133static int ssl3_send_server_hello(SSL *s);
134static int ssl3_send_server_key_exchange(SSL *s);
135static int ssl3_send_certificate_request(SSL *s);
136static int ssl3_send_server_done(SSL *s);
137static int ssl3_get_client_key_exchange(SSL *s);
138static int ssl3_get_client_certificate(SSL *s);
139static int ssl3_get_cert_verify(SSL *s);
140static int ssl3_send_hello_request(SSL *s);
141
142static SSL_METHOD *ssl3_get_server_method(int ver)
143 {
144 if (ver == SSL3_VERSION)
145 return(SSLv3_server_method());
146 else
147 return(NULL);
148 }
149
150SSL_METHOD *SSLv3_server_method(void)
151 {
152 static int init=1;
153 static SSL_METHOD SSLv3_server_data;
154
155 if (init)
156 {
157 CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
158
159 if (init)
160 {
161 memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
162 sizeof(SSL_METHOD));
163 SSLv3_server_data.ssl_accept=ssl3_accept;
164 SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
165 init=0;
166 }
167
168 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
169 }
170 return(&SSLv3_server_data);
171 }
172
173int ssl3_accept(SSL *s)
174 {
175 BUF_MEM *buf;
176 unsigned long l,Time=(unsigned long)time(NULL);
177 void (*cb)(const SSL *ssl,int type,int val)=NULL;
178 long num1;
179 int ret= -1;
180 int new_state,state,skip=0;
181
182 RAND_add(&Time,sizeof(Time),0);
183 ERR_clear_error();
184 clear_sys_error();
185
186 if (s->info_callback != NULL)
187 cb=s->info_callback;
188 else if (s->ctx->info_callback != NULL)
189 cb=s->ctx->info_callback;
190
191 /* init things to blank */
192 s->in_handshake++;
193 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
194
195 if (s->cert == NULL)
196 {
197 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET);
198 return(-1);
199 }
200
201 for (;;)
202 {
203 state=s->state;
204
205 switch (s->state)
206 {
207 case SSL_ST_RENEGOTIATE:
208 s->new_session=1;
209 /* s->state=SSL_ST_ACCEPT; */
210
211 case SSL_ST_BEFORE:
212 case SSL_ST_ACCEPT:
213 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
214 case SSL_ST_OK|SSL_ST_ACCEPT:
215
216 s->server=1;
217 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
218
219 if ((s->version>>8) != 3)
220 {
221 SSLerr(SSL_F_SSL3_ACCEPT, ERR_R_INTERNAL_ERROR);
222 return -1;
223 }
224 s->type=SSL_ST_ACCEPT;
225
226 if (s->init_buf == NULL)
227 {
228 if ((buf=BUF_MEM_new()) == NULL)
229 {
230 ret= -1;
231 goto end;
232 }
233 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
234 {
235 ret= -1;
236 goto end;
237 }
238 s->init_buf=buf;
239 }
240
241 if (!ssl3_setup_buffers(s))
242 {
243 ret= -1;
244 goto end;
245 }
246
247 s->init_num=0;
248
249 if (s->state != SSL_ST_RENEGOTIATE)
250 {
251 /* Ok, we now need to push on a buffering BIO so that
252 * the output is sent in a way that TCP likes :-)
253 */
254 if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }
255
256 ssl3_init_finished_mac(s);
257 s->state=SSL3_ST_SR_CLNT_HELLO_A;
258 s->ctx->stats.sess_accept++;
259 }
260 else
261 {
262 /* s->state == SSL_ST_RENEGOTIATE,
263 * we will just send a HelloRequest */
264 s->ctx->stats.sess_accept_renegotiate++;
265 s->state=SSL3_ST_SW_HELLO_REQ_A;
266 }
267 break;
268
269 case SSL3_ST_SW_HELLO_REQ_A:
270 case SSL3_ST_SW_HELLO_REQ_B:
271
272 s->shutdown=0;
273 ret=ssl3_send_hello_request(s);
274 if (ret <= 0) goto end;
275 s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;
276 s->state=SSL3_ST_SW_FLUSH;
277 s->init_num=0;
278
279 ssl3_init_finished_mac(s);
280 break;
281
282 case SSL3_ST_SW_HELLO_REQ_C:
283 s->state=SSL_ST_OK;
284 break;
285
286 case SSL3_ST_SR_CLNT_HELLO_A:
287 case SSL3_ST_SR_CLNT_HELLO_B:
288 case SSL3_ST_SR_CLNT_HELLO_C:
289
290 s->shutdown=0;
291 ret=ssl3_get_client_hello(s);
292 if (ret <= 0) goto end;
293 s->new_session = 2;
294 s->state=SSL3_ST_SW_SRVR_HELLO_A;
295 s->init_num=0;
296 break;
297
298 case SSL3_ST_SW_SRVR_HELLO_A:
299 case SSL3_ST_SW_SRVR_HELLO_B:
300 ret=ssl3_send_server_hello(s);
301 if (ret <= 0) goto end;
302
303 if (s->hit)
304 s->state=SSL3_ST_SW_CHANGE_A;
305 else
306 s->state=SSL3_ST_SW_CERT_A;
307 s->init_num=0;
308 break;
309
310 case SSL3_ST_SW_CERT_A:
311 case SSL3_ST_SW_CERT_B:
312 /* Check if it is anon DH */
313 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
314 {
315 ret=ssl3_send_server_certificate(s);
316 if (ret <= 0) goto end;
317 }
318 else
319 skip=1;
320 s->state=SSL3_ST_SW_KEY_EXCH_A;
321 s->init_num=0;
322 break;
323
324 case SSL3_ST_SW_KEY_EXCH_A:
325 case SSL3_ST_SW_KEY_EXCH_B:
326 l=s->s3->tmp.new_cipher->algorithms;
327
328 /* clear this, it may get reset by
329 * send_server_key_exchange */
330 if ((s->options & SSL_OP_EPHEMERAL_RSA)
331#ifndef OPENSSL_NO_KRB5
332 && !(l & SSL_KRB5)
333#endif /* OPENSSL_NO_KRB5 */
334 )
335 /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key
336 * even when forbidden by protocol specs
337 * (handshake may fail as clients are not required to
338 * be able to handle this) */
339 s->s3->tmp.use_rsa_tmp=1;
340 else
341 s->s3->tmp.use_rsa_tmp=0;
342
343 /* only send if a DH key exchange, fortezza or
344 * RSA but we have a sign only certificate */
345 if (s->s3->tmp.use_rsa_tmp
346 || (l & (SSL_DH|SSL_kFZA))
347 || ((l & SSL_kRSA)
348 && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL
349 || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)
350 && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)
351 )
352 )
353 )
354 )
355 {
356 ret=ssl3_send_server_key_exchange(s);
357 if (ret <= 0) goto end;
358 }
359 else
360 skip=1;
361
362 s->state=SSL3_ST_SW_CERT_REQ_A;
363 s->init_num=0;
364 break;
365
366 case SSL3_ST_SW_CERT_REQ_A:
367 case SSL3_ST_SW_CERT_REQ_B:
368 if (/* don't request cert unless asked for it: */
369 !(s->verify_mode & SSL_VERIFY_PEER) ||
370 /* if SSL_VERIFY_CLIENT_ONCE is set,
371 * don't request cert during re-negotiation: */
372 ((s->session->peer != NULL) &&
373 (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||
374 /* never request cert in anonymous ciphersuites
375 * (see section "Certificate request" in SSL 3 drafts
376 * and in RFC 2246): */
377 ((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) &&
378 /* ... except when the application insists on verification
379 * (against the specs, but s3_clnt.c accepts this for SSL 3) */
380 !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||
381 /* never request cert in Kerberos ciphersuites */
382 (s->s3->tmp.new_cipher->algorithms & SSL_aKRB5))
383 {
384 /* no cert request */
385 skip=1;
386 s->s3->tmp.cert_request=0;
387 s->state=SSL3_ST_SW_SRVR_DONE_A;
388 }
389 else
390 {
391 s->s3->tmp.cert_request=1;
392 ret=ssl3_send_certificate_request(s);
393 if (ret <= 0) goto end;
394#ifndef NETSCAPE_HANG_BUG
395 s->state=SSL3_ST_SW_SRVR_DONE_A;
396#else
397 s->state=SSL3_ST_SW_FLUSH;
398 s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
399#endif
400 s->init_num=0;
401 }
402 break;
403
404 case SSL3_ST_SW_SRVR_DONE_A:
405 case SSL3_ST_SW_SRVR_DONE_B:
406 ret=ssl3_send_server_done(s);
407 if (ret <= 0) goto end;
408 s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
409 s->state=SSL3_ST_SW_FLUSH;
410 s->init_num=0;
411 break;
412
413 case SSL3_ST_SW_FLUSH:
414 /* number of bytes to be flushed */
415 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
416 if (num1 > 0)
417 {
418 s->rwstate=SSL_WRITING;
419 num1=BIO_flush(s->wbio);
420 if (num1 <= 0) { ret= -1; goto end; }
421 s->rwstate=SSL_NOTHING;
422 }
423
424 s->state=s->s3->tmp.next_state;
425 break;
426
427 case SSL3_ST_SR_CERT_A:
428 case SSL3_ST_SR_CERT_B:
429 /* Check for second client hello (MS SGC) */
430 ret = ssl3_check_client_hello(s);
431 if (ret <= 0)
432 goto end;
433 if (ret == 2)
434 s->state = SSL3_ST_SR_CLNT_HELLO_C;
435 else {
436 if (s->s3->tmp.cert_request)
437 {
438 ret=ssl3_get_client_certificate(s);
439 if (ret <= 0) goto end;
440 }
441 s->init_num=0;
442 s->state=SSL3_ST_SR_KEY_EXCH_A;
443 }
444 break;
445
446 case SSL3_ST_SR_KEY_EXCH_A:
447 case SSL3_ST_SR_KEY_EXCH_B:
448 ret=ssl3_get_client_key_exchange(s);
449 if (ret <= 0) goto end;
450 s->state=SSL3_ST_SR_CERT_VRFY_A;
451 s->init_num=0;
452
453 /* We need to get hashes here so if there is
454 * a client cert, it can be verified */
455 s->method->ssl3_enc->cert_verify_mac(s,
456 &(s->s3->finish_dgst1),
457 &(s->s3->tmp.cert_verify_md[0]));
458 s->method->ssl3_enc->cert_verify_mac(s,
459 &(s->s3->finish_dgst2),
460 &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));
461
462 break;
463
464 case SSL3_ST_SR_CERT_VRFY_A:
465 case SSL3_ST_SR_CERT_VRFY_B:
466
467 /* we should decide if we expected this one */
468 ret=ssl3_get_cert_verify(s);
469 if (ret <= 0) goto end;
470
471 s->state=SSL3_ST_SR_FINISHED_A;
472 s->init_num=0;
473 break;
474
475 case SSL3_ST_SR_FINISHED_A:
476 case SSL3_ST_SR_FINISHED_B:
477 ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
478 SSL3_ST_SR_FINISHED_B);
479 if (ret <= 0) goto end;
480 if (s->hit)
481 s->state=SSL_ST_OK;
482 else
483 s->state=SSL3_ST_SW_CHANGE_A;
484 s->init_num=0;
485 break;
486
487 case SSL3_ST_SW_CHANGE_A:
488 case SSL3_ST_SW_CHANGE_B:
489
490 s->session->cipher=s->s3->tmp.new_cipher;
491 if (!s->method->ssl3_enc->setup_key_block(s))
492 { ret= -1; goto end; }
493
494 ret=ssl3_send_change_cipher_spec(s,
495 SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);
496
497 if (ret <= 0) goto end;
498 s->state=SSL3_ST_SW_FINISHED_A;
499 s->init_num=0;
500
501 if (!s->method->ssl3_enc->change_cipher_state(s,
502 SSL3_CHANGE_CIPHER_SERVER_WRITE))
503 {
504 ret= -1;
505 goto end;
506 }
507
508 break;
509
510 case SSL3_ST_SW_FINISHED_A:
511 case SSL3_ST_SW_FINISHED_B:
512 ret=ssl3_send_finished(s,
513 SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,
514 s->method->ssl3_enc->server_finished_label,
515 s->method->ssl3_enc->server_finished_label_len);
516 if (ret <= 0) goto end;
517 s->state=SSL3_ST_SW_FLUSH;
518 if (s->hit)
519 s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
520 else
521 s->s3->tmp.next_state=SSL_ST_OK;
522 s->init_num=0;
523 break;
524
525 case SSL_ST_OK:
526 /* clean a few things up */
527 ssl3_cleanup_key_block(s);
528
529 BUF_MEM_free(s->init_buf);
530 s->init_buf=NULL;
531
532 /* remove buffering on output */
533 ssl_free_wbio_buffer(s);
534
535 s->init_num=0;
536
537 if (s->new_session == 2) /* skipped if we just sent a HelloRequest */
538 {
539 /* actually not necessarily a 'new' session unless
540 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */
541
542 s->new_session=0;
543
544 ssl_update_cache(s,SSL_SESS_CACHE_SERVER);
545
546 s->ctx->stats.sess_accept_good++;
547 /* s->server=1; */
548 s->handshake_func=ssl3_accept;
549
550 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
551 }
552
553 ret = 1;
554 goto end;
555 /* break; */
556
557 default:
558 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE);
559 ret= -1;
560 goto end;
561 /* break; */
562 }
563
564 if (!s->s3->tmp.reuse_message && !skip)
565 {
566 if (s->debug)
567 {
568 if ((ret=BIO_flush(s->wbio)) <= 0)
569 goto end;
570 }
571
572
573 if ((cb != NULL) && (s->state != state))
574 {
575 new_state=s->state;
576 s->state=state;
577 cb(s,SSL_CB_ACCEPT_LOOP,1);
578 s->state=new_state;
579 }
580 }
581 skip=0;
582 }
583end:
584 /* BIO_flush(s->wbio); */
585
586 s->in_handshake--;
587 if (cb != NULL)
588 cb(s,SSL_CB_ACCEPT_EXIT,ret);
589 return(ret);
590 }
591
592static int ssl3_send_hello_request(SSL *s)
593 {
594 unsigned char *p;
595
596 if (s->state == SSL3_ST_SW_HELLO_REQ_A)
597 {
598 p=(unsigned char *)s->init_buf->data;
599 *(p++)=SSL3_MT_HELLO_REQUEST;
600 *(p++)=0;
601 *(p++)=0;
602 *(p++)=0;
603
604 s->state=SSL3_ST_SW_HELLO_REQ_B;
605 /* number of bytes to write */
606 s->init_num=4;
607 s->init_off=0;
608 }
609
610 /* SSL3_ST_SW_HELLO_REQ_B */
611 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
612 }
613
614static int ssl3_check_client_hello(SSL *s)
615 {
616 int ok;
617 long n;
618
619 /* this function is called when we really expect a Certificate message,
620 * so permit appropriate message length */
621 n=ssl3_get_message(s,
622 SSL3_ST_SR_CERT_A,
623 SSL3_ST_SR_CERT_B,
624 -1,
625 s->max_cert_list,
626 &ok);
627 if (!ok) return((int)n);
628 s->s3->tmp.reuse_message = 1;
629 if (s->s3->tmp.message_type == SSL3_MT_CLIENT_HELLO)
630 {
631 /* Throw away what we have done so far in the current handshake,
632 * which will now be aborted. (A full SSL_clear would be too much.)
633 * I hope that tmp.dh is the only thing that may need to be cleared
634 * when a handshake is not completed ... */
635#ifndef OPENSSL_NO_DH
636 if (s->s3->tmp.dh != NULL)
637 {
638 DH_free(s->s3->tmp.dh);
639 s->s3->tmp.dh = NULL;
640 }
641#endif
642 return 2;
643 }
644 return 1;
645}
646
647static int ssl3_get_client_hello(SSL *s)
648 {
649 int i,j,ok,al,ret= -1;
650 long n;
651 unsigned long id;
652 unsigned char *p,*d,*q;
653 SSL_CIPHER *c;
654 SSL_COMP *comp=NULL;
655 STACK_OF(SSL_CIPHER) *ciphers=NULL;
656
657 /* We do this so that we will respond with our native type.
658 * If we are TLSv1 and we get SSLv3, we will respond with TLSv1,
659 * This down switching should be handled by a different method.
660 * If we are SSLv3, we will respond with SSLv3, even if prompted with
661 * TLSv1.
662 */
663 if (s->state == SSL3_ST_SR_CLNT_HELLO_A)
664 {
665 s->first_packet=1;
666 s->state=SSL3_ST_SR_CLNT_HELLO_B;
667 }
668 n=ssl3_get_message(s,
669 SSL3_ST_SR_CLNT_HELLO_B,
670 SSL3_ST_SR_CLNT_HELLO_C,
671 SSL3_MT_CLIENT_HELLO,
672 SSL3_RT_MAX_PLAIN_LENGTH,
673 &ok);
674
675 if (!ok) return((int)n);
676 d=p=(unsigned char *)s->init_msg;
677
678 /* use version from inside client hello, not from record header
679 * (may differ: see RFC 2246, Appendix E, second paragraph) */
680 s->client_version=(((int)p[0])<<8)|(int)p[1];
681 p+=2;
682
683 if (s->client_version < s->version)
684 {
685 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_WRONG_VERSION_NUMBER);
686 if ((s->client_version>>8) == SSL3_VERSION_MAJOR)
687 {
688 /* similar to ssl3_get_record, send alert using remote version number */
689 s->version = s->client_version;
690 }
691 al = SSL_AD_PROTOCOL_VERSION;
692 goto f_err;
693 }
694
695 /* load the client random */
696 memcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);
697 p+=SSL3_RANDOM_SIZE;
698
699 /* get the session-id */
700 j= *(p++);
701
702 s->hit=0;
703 /* Versions before 0.9.7 always allow session reuse during renegotiation
704 * (i.e. when s->new_session is true), option
705 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is new with 0.9.7.
706 * Maybe this optional behaviour should always have been the default,
707 * but we cannot safely change the default behaviour (or new applications
708 * might be written that become totally unsecure when compiled with
709 * an earlier library version)
710 */
711 if (j == 0 || (s->new_session && (s->options & SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)))
712 {
713 if (!ssl_get_new_session(s,1))
714 goto err;
715 }
716 else
717 {
718 i=ssl_get_prev_session(s,p,j);
719 if (i == 1)
720 { /* previous session */
721 s->hit=1;
722 }
723 else if (i == -1)
724 goto err;
725 else /* i == 0 */
726 {
727 if (!ssl_get_new_session(s,1))
728 goto err;
729 }
730 }
731
732 p+=j;
733 n2s(p,i);
734 if ((i == 0) && (j != 0))
735 {
736 /* we need a cipher if we are not resuming a session */
737 al=SSL_AD_ILLEGAL_PARAMETER;
738 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);
739 goto f_err;
740 }
741 if ((p+i) >= (d+n))
742 {
743 /* not enough data */
744 al=SSL_AD_DECODE_ERROR;
745 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
746 goto f_err;
747 }
748 if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))
749 == NULL))
750 {
751 goto err;
752 }
753 p+=i;
754
755 /* If it is a hit, check that the cipher is in the list */
756 if ((s->hit) && (i > 0))
757 {
758 j=0;
759 id=s->session->cipher->id;
760
761#ifdef CIPHER_DEBUG
762 printf("client sent %d ciphers\n",sk_num(ciphers));
763#endif
764 for (i=0; i<sk_SSL_CIPHER_num(ciphers); i++)
765 {
766 c=sk_SSL_CIPHER_value(ciphers,i);
767#ifdef CIPHER_DEBUG
768 printf("client [%2d of %2d]:%s\n",
769 i,sk_num(ciphers),SSL_CIPHER_get_name(c));
770#endif
771 if (c->id == id)
772 {
773 j=1;
774 break;
775 }
776 }
777 if (j == 0)
778 {
779 if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1))
780 {
781 /* Very bad for multi-threading.... */
782 s->session->cipher=sk_SSL_CIPHER_value(ciphers,
783 0);
784 }
785 else
786 {
787 /* we need to have the cipher in the cipher
788 * list if we are asked to reuse it */
789 al=SSL_AD_ILLEGAL_PARAMETER;
790 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);
791 goto f_err;
792 }
793 }
794 }
795
796 /* compression */
797 i= *(p++);
798 if ((p+i) > (d+n))
799 {
800 /* not enough data */
801 al=SSL_AD_DECODE_ERROR;
802 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
803 goto f_err;
804 }
805 q=p;
806 for (j=0; j<i; j++)
807 {
808 if (p[j] == 0) break;
809 }
810
811 p+=i;
812 if (j >= i)
813 {
814 /* no compress */
815 al=SSL_AD_DECODE_ERROR;
816 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);
817 goto f_err;
818 }
819
820 /* Worst case, we will use the NULL compression, but if we have other
821 * options, we will now look for them. We have i-1 compression
822 * algorithms from the client, starting at q. */
823 s->s3->tmp.new_compression=NULL;
824 if (s->ctx->comp_methods != NULL)
825 { /* See if we have a match */
826 int m,nn,o,v,done=0;
827
828 nn=sk_SSL_COMP_num(s->ctx->comp_methods);
829 for (m=0; m<nn; m++)
830 {
831 comp=sk_SSL_COMP_value(s->ctx->comp_methods,m);
832 v=comp->id;
833 for (o=0; o<i; o++)
834 {
835 if (v == q[o])
836 {
837 done=1;
838 break;
839 }
840 }
841 if (done) break;
842 }
843 if (done)
844 s->s3->tmp.new_compression=comp;
845 else
846 comp=NULL;
847 }
848
849 /* TLS does not mind if there is extra stuff */
850#if 0 /* SSL 3.0 does not mind either, so we should disable this test
851 * (was enabled in 0.9.6d through 0.9.6j and 0.9.7 through 0.9.7b,
852 * in earlier SSLeay/OpenSSL releases this test existed but was buggy) */
853 if (s->version == SSL3_VERSION)
854 {
855 if (p < (d+n))
856 {
857 /* wrong number of bytes,
858 * there could be more to follow */
859 al=SSL_AD_DECODE_ERROR;
860 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
861 goto f_err;
862 }
863 }
864#endif
865
866 /* Given s->session->ciphers and SSL_get_ciphers, we must
867 * pick a cipher */
868
869 if (!s->hit)
870 {
871 s->session->compress_meth=(comp == NULL)?0:comp->id;
872 if (s->session->ciphers != NULL)
873 sk_SSL_CIPHER_free(s->session->ciphers);
874 s->session->ciphers=ciphers;
875 if (ciphers == NULL)
876 {
877 al=SSL_AD_ILLEGAL_PARAMETER;
878 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);
879 goto f_err;
880 }
881 ciphers=NULL;
882 c=ssl3_choose_cipher(s,s->session->ciphers,
883 SSL_get_ciphers(s));
884
885 if (c == NULL)
886 {
887 al=SSL_AD_HANDSHAKE_FAILURE;
888 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
889 goto f_err;
890 }
891 s->s3->tmp.new_cipher=c;
892 }
893 else
894 {
895 /* Session-id reuse */
896#ifdef REUSE_CIPHER_BUG
897 STACK_OF(SSL_CIPHER) *sk;
898 SSL_CIPHER *nc=NULL;
899 SSL_CIPHER *ec=NULL;
900
901 if (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
902 {
903 sk=s->session->ciphers;
904 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
905 {
906 c=sk_SSL_CIPHER_value(sk,i);
907 if (c->algorithms & SSL_eNULL)
908 nc=c;
909 if (SSL_C_IS_EXPORT(c))
910 ec=c;
911 }
912 if (nc != NULL)
913 s->s3->tmp.new_cipher=nc;
914 else if (ec != NULL)
915 s->s3->tmp.new_cipher=ec;
916 else
917 s->s3->tmp.new_cipher=s->session->cipher;
918 }
919 else
920#endif
921 s->s3->tmp.new_cipher=s->session->cipher;
922 }
923
924 /* we now have the following setup.
925 * client_random
926 * cipher_list - our prefered list of ciphers
927 * ciphers - the clients prefered list of ciphers
928 * compression - basically ignored right now
929 * ssl version is set - sslv3
930 * s->session - The ssl session has been setup.
931 * s->hit - session reuse flag
932 * s->tmp.new_cipher - the new cipher to use.
933 */
934
935 ret=1;
936 if (0)
937 {
938f_err:
939 ssl3_send_alert(s,SSL3_AL_FATAL,al);
940 }
941err:
942 if (ciphers != NULL) sk_SSL_CIPHER_free(ciphers);
943 return(ret);
944 }
945
946static int ssl3_send_server_hello(SSL *s)
947 {
948 unsigned char *buf;
949 unsigned char *p,*d;
950 int i,sl;
951 unsigned long l,Time;
952
953 if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
954 {
955 buf=(unsigned char *)s->init_buf->data;
956 p=s->s3->server_random;
957 Time=(unsigned long)time(NULL); /* Time */
958 l2n(Time,p);
959 if(RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
960 return -1;
961 /* Do the message type and length last */
962 d=p= &(buf[4]);
963
964 *(p++)=s->version>>8;
965 *(p++)=s->version&0xff;
966
967 /* Random stuff */
968 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
969 p+=SSL3_RANDOM_SIZE;
970
971 /* now in theory we have 3 options to sending back the
972 * session id. If it is a re-use, we send back the
973 * old session-id, if it is a new session, we send
974 * back the new session-id or we send back a 0 length
975 * session-id if we want it to be single use.
976 * Currently I will not implement the '0' length session-id
977 * 12-Jan-98 - I'll now support the '0' length stuff.
978 */
979 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER))
980 s->session->session_id_length=0;
981
982 sl=s->session->session_id_length;
983 if (sl > sizeof s->session->session_id)
984 {
985 SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO, ERR_R_INTERNAL_ERROR);
986 return -1;
987 }
988 *(p++)=sl;
989 memcpy(p,s->session->session_id,sl);
990 p+=sl;
991
992 /* put the cipher */
993 i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p);
994 p+=i;
995
996 /* put the compression method */
997 if (s->s3->tmp.new_compression == NULL)
998 *(p++)=0;
999 else
1000 *(p++)=s->s3->tmp.new_compression->id;
1001
1002 /* do the header */
1003 l=(p-d);
1004 d=buf;
1005 *(d++)=SSL3_MT_SERVER_HELLO;
1006 l2n3(l,d);
1007
1008 s->state=SSL3_ST_CW_CLNT_HELLO_B;
1009 /* number of bytes to write */
1010 s->init_num=p-buf;
1011 s->init_off=0;
1012 }
1013
1014 /* SSL3_ST_CW_CLNT_HELLO_B */
1015 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1016 }
1017
1018static int ssl3_send_server_done(SSL *s)
1019 {
1020 unsigned char *p;
1021
1022 if (s->state == SSL3_ST_SW_SRVR_DONE_A)
1023 {
1024 p=(unsigned char *)s->init_buf->data;
1025
1026 /* do the header */
1027 *(p++)=SSL3_MT_SERVER_DONE;
1028 *(p++)=0;
1029 *(p++)=0;
1030 *(p++)=0;
1031
1032 s->state=SSL3_ST_SW_SRVR_DONE_B;
1033 /* number of bytes to write */
1034 s->init_num=4;
1035 s->init_off=0;
1036 }
1037
1038 /* SSL3_ST_CW_CLNT_HELLO_B */
1039 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1040 }
1041
1042static int ssl3_send_server_key_exchange(SSL *s)
1043 {
1044#ifndef OPENSSL_NO_RSA
1045 unsigned char *q;
1046 int j,num;
1047 RSA *rsa;
1048 unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
1049 unsigned int u;
1050#endif
1051#ifndef OPENSSL_NO_DH
1052 DH *dh=NULL,*dhp;
1053#endif
1054 EVP_PKEY *pkey;
1055 unsigned char *p,*d;
1056 int al,i;
1057 unsigned long type;
1058 int n;
1059 CERT *cert;
1060 BIGNUM *r[4];
1061 int nr[4],kn;
1062 BUF_MEM *buf;
1063 EVP_MD_CTX md_ctx;
1064
1065 EVP_MD_CTX_init(&md_ctx);
1066 if (s->state == SSL3_ST_SW_KEY_EXCH_A)
1067 {
1068 type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK;
1069 cert=s->cert;
1070
1071 buf=s->init_buf;
1072
1073 r[0]=r[1]=r[2]=r[3]=NULL;
1074 n=0;
1075#ifndef OPENSSL_NO_RSA
1076 if (type & SSL_kRSA)
1077 {
1078 rsa=cert->rsa_tmp;
1079 if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL))
1080 {
1081 rsa=s->cert->rsa_tmp_cb(s,
1082 SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
1083 SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
1084 if(rsa == NULL)
1085 {
1086 al=SSL_AD_HANDSHAKE_FAILURE;
1087 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_ERROR_GENERATING_TMP_RSA_KEY);
1088 goto f_err;
1089 }
1090 RSA_up_ref(rsa);
1091 cert->rsa_tmp=rsa;
1092 }
1093 if (rsa == NULL)
1094 {
1095 al=SSL_AD_HANDSHAKE_FAILURE;
1096 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY);
1097 goto f_err;
1098 }
1099 r[0]=rsa->n;
1100 r[1]=rsa->e;
1101 s->s3->tmp.use_rsa_tmp=1;
1102 }
1103 else
1104#endif
1105#ifndef OPENSSL_NO_DH
1106 if (type & SSL_kEDH)
1107 {
1108 dhp=cert->dh_tmp;
1109 if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL))
1110 dhp=s->cert->dh_tmp_cb(s,
1111 SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
1112 SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
1113 if (dhp == NULL)
1114 {
1115 al=SSL_AD_HANDSHAKE_FAILURE;
1116 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
1117 goto f_err;
1118 }
1119
1120 if (s->s3->tmp.dh != NULL)
1121 {
1122 DH_free(dh);
1123 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
1124 goto err;
1125 }
1126
1127 if ((dh=DHparams_dup(dhp)) == NULL)
1128 {
1129 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
1130 goto err;
1131 }
1132
1133 s->s3->tmp.dh=dh;
1134 if ((dhp->pub_key == NULL ||
1135 dhp->priv_key == NULL ||
1136 (s->options & SSL_OP_SINGLE_DH_USE)))
1137 {
1138 if(!DH_generate_key(dh))
1139 {
1140 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
1141 ERR_R_DH_LIB);
1142 goto err;
1143 }
1144 }
1145 else
1146 {
1147 dh->pub_key=BN_dup(dhp->pub_key);
1148 dh->priv_key=BN_dup(dhp->priv_key);
1149 if ((dh->pub_key == NULL) ||
1150 (dh->priv_key == NULL))
1151 {
1152 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
1153 goto err;
1154 }
1155 }
1156 r[0]=dh->p;
1157 r[1]=dh->g;
1158 r[2]=dh->pub_key;
1159 }
1160 else
1161#endif
1162 {
1163 al=SSL_AD_HANDSHAKE_FAILURE;
1164 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1165 goto f_err;
1166 }
1167 for (i=0; r[i] != NULL; i++)
1168 {
1169 nr[i]=BN_num_bytes(r[i]);
1170 n+=2+nr[i];
1171 }
1172
1173 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
1174 {
1175 if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher))
1176 == NULL)
1177 {
1178 al=SSL_AD_DECODE_ERROR;
1179 goto f_err;
1180 }
1181 kn=EVP_PKEY_size(pkey);
1182 }
1183 else
1184 {
1185 pkey=NULL;
1186 kn=0;
1187 }
1188
1189 if (!BUF_MEM_grow_clean(buf,n+4+kn))
1190 {
1191 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF);
1192 goto err;
1193 }
1194 d=(unsigned char *)s->init_buf->data;
1195 p= &(d[4]);
1196
1197 for (i=0; r[i] != NULL; i++)
1198 {
1199 s2n(nr[i],p);
1200 BN_bn2bin(r[i],p);
1201 p+=nr[i];
1202 }
1203
1204 /* not anonymous */
1205 if (pkey != NULL)
1206 {
1207 /* n is the length of the params, they start at &(d[4])
1208 * and p points to the space at the end. */
1209#ifndef OPENSSL_NO_RSA
1210 if (pkey->type == EVP_PKEY_RSA)
1211 {
1212 q=md_buf;
1213 j=0;
1214 for (num=2; num > 0; num--)
1215 {
1216 EVP_MD_CTX_set_flags(&md_ctx,
1217 EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
1218 EVP_DigestInit_ex(&md_ctx,(num == 2)
1219 ?s->ctx->md5:s->ctx->sha1, NULL);
1220 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1221 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1222 EVP_DigestUpdate(&md_ctx,&(d[4]),n);
1223 EVP_DigestFinal_ex(&md_ctx,q,
1224 (unsigned int *)&i);
1225 q+=i;
1226 j+=i;
1227 }
1228 if (RSA_sign(NID_md5_sha1, md_buf, j,
1229 &(p[2]), &u, pkey->pkey.rsa) <= 0)
1230 {
1231 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA);
1232 goto err;
1233 }
1234 s2n(u,p);
1235 n+=u+2;
1236 }
1237 else
1238#endif
1239#if !defined(OPENSSL_NO_DSA)
1240 if (pkey->type == EVP_PKEY_DSA)
1241 {
1242 /* lets do DSS */
1243 EVP_SignInit_ex(&md_ctx,EVP_dss1(), NULL);
1244 EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1245 EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1246 EVP_SignUpdate(&md_ctx,&(d[4]),n);
1247 if (!EVP_SignFinal(&md_ctx,&(p[2]),
1248 (unsigned int *)&i,pkey))
1249 {
1250 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA);
1251 goto err;
1252 }
1253 s2n(i,p);
1254 n+=i+2;
1255 }
1256 else
1257#endif
1258 {
1259 /* Is this error check actually needed? */
1260 al=SSL_AD_HANDSHAKE_FAILURE;
1261 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE);
1262 goto f_err;
1263 }
1264 }
1265
1266 *(d++)=SSL3_MT_SERVER_KEY_EXCHANGE;
1267 l2n3(n,d);
1268
1269 /* we should now have things packed up, so lets send
1270 * it off */
1271 s->init_num=n+4;
1272 s->init_off=0;
1273 }
1274
1275 s->state = SSL3_ST_SW_KEY_EXCH_B;
1276 EVP_MD_CTX_cleanup(&md_ctx);
1277 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1278f_err:
1279 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1280err:
1281 EVP_MD_CTX_cleanup(&md_ctx);
1282 return(-1);
1283 }
1284
1285static int ssl3_send_certificate_request(SSL *s)
1286 {
1287 unsigned char *p,*d;
1288 int i,j,nl,off,n;
1289 STACK_OF(X509_NAME) *sk=NULL;
1290 X509_NAME *name;
1291 BUF_MEM *buf;
1292
1293 if (s->state == SSL3_ST_SW_CERT_REQ_A)
1294 {
1295 buf=s->init_buf;
1296
1297 d=p=(unsigned char *)&(buf->data[4]);
1298
1299 /* get the list of acceptable cert types */
1300 p++;
1301 n=ssl3_get_req_cert_type(s,p);
1302 d[0]=n;
1303 p+=n;
1304 n++;
1305
1306 off=n;
1307 p+=2;
1308 n+=2;
1309
1310 sk=SSL_get_client_CA_list(s);
1311 nl=0;
1312 if (sk != NULL)
1313 {
1314 for (i=0; i<sk_X509_NAME_num(sk); i++)
1315 {
1316 name=sk_X509_NAME_value(sk,i);
1317 j=i2d_X509_NAME(name,NULL);
1318 if (!BUF_MEM_grow_clean(buf,4+n+j+2))
1319 {
1320 SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB);
1321 goto err;
1322 }
1323 p=(unsigned char *)&(buf->data[4+n]);
1324 if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1325 {
1326 s2n(j,p);
1327 i2d_X509_NAME(name,&p);
1328 n+=2+j;
1329 nl+=2+j;
1330 }
1331 else
1332 {
1333 d=p;
1334 i2d_X509_NAME(name,&p);
1335 j-=2; s2n(j,d); j+=2;
1336 n+=j;
1337 nl+=j;
1338 }
1339 }
1340 }
1341 /* else no CA names */
1342 p=(unsigned char *)&(buf->data[4+off]);
1343 s2n(nl,p);
1344
1345 d=(unsigned char *)buf->data;
1346 *(d++)=SSL3_MT_CERTIFICATE_REQUEST;
1347 l2n3(n,d);
1348
1349 /* we should now have things packed up, so lets send
1350 * it off */
1351
1352 s->init_num=n+4;
1353 s->init_off=0;
1354#ifdef NETSCAPE_HANG_BUG
1355 p=(unsigned char *)s->init_buf->data + s->init_num;
1356
1357 /* do the header */
1358 *(p++)=SSL3_MT_SERVER_DONE;
1359 *(p++)=0;
1360 *(p++)=0;
1361 *(p++)=0;
1362 s->init_num += 4;
1363#endif
1364
1365 s->state = SSL3_ST_SW_CERT_REQ_B;
1366 }
1367
1368 /* SSL3_ST_SW_CERT_REQ_B */
1369 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1370err:
1371 return(-1);
1372 }
1373
1374static int ssl3_get_client_key_exchange(SSL *s)
1375 {
1376 int i,al,ok;
1377 long n;
1378 unsigned long l;
1379 unsigned char *p;
1380#ifndef OPENSSL_NO_RSA
1381 RSA *rsa=NULL;
1382 EVP_PKEY *pkey=NULL;
1383#endif
1384#ifndef OPENSSL_NO_DH
1385 BIGNUM *pub=NULL;
1386 DH *dh_srvr;
1387#endif
1388#ifndef OPENSSL_NO_KRB5
1389 KSSL_ERR kssl_err;
1390#endif /* OPENSSL_NO_KRB5 */
1391
1392 n=ssl3_get_message(s,
1393 SSL3_ST_SR_KEY_EXCH_A,
1394 SSL3_ST_SR_KEY_EXCH_B,
1395 SSL3_MT_CLIENT_KEY_EXCHANGE,
1396 2048, /* ??? */
1397 &ok);
1398
1399 if (!ok) return((int)n);
1400 p=(unsigned char *)s->init_msg;
1401
1402 l=s->s3->tmp.new_cipher->algorithms;
1403
1404#ifndef OPENSSL_NO_RSA
1405 if (l & SSL_kRSA)
1406 {
1407 /* FIX THIS UP EAY EAY EAY EAY */
1408 if (s->s3->tmp.use_rsa_tmp)
1409 {
1410 if ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))
1411 rsa=s->cert->rsa_tmp;
1412 /* Don't do a callback because rsa_tmp should
1413 * be sent already */
1414 if (rsa == NULL)
1415 {
1416 al=SSL_AD_HANDSHAKE_FAILURE;
1417 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);
1418 goto f_err;
1419
1420 }
1421 }
1422 else
1423 {
1424 pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;
1425 if ( (pkey == NULL) ||
1426 (pkey->type != EVP_PKEY_RSA) ||
1427 (pkey->pkey.rsa == NULL))
1428 {
1429 al=SSL_AD_HANDSHAKE_FAILURE;
1430 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);
1431 goto f_err;
1432 }
1433 rsa=pkey->pkey.rsa;
1434 }
1435
1436 /* TLS */
1437 if (s->version > SSL3_VERSION)
1438 {
1439 n2s(p,i);
1440 if (n != i+2)
1441 {
1442 if (!(s->options & SSL_OP_TLS_D5_BUG))
1443 {
1444 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);
1445 goto err;
1446 }
1447 else
1448 p-=2;
1449 }
1450 else
1451 n=i;
1452 }
1453
1454 i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);
1455
1456 al = -1;
1457
1458 if (i != SSL_MAX_MASTER_KEY_LENGTH)
1459 {
1460 al=SSL_AD_DECODE_ERROR;
1461 /* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); */
1462 }
1463
1464 if ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))
1465 {
1466 /* The premaster secret must contain the same version number as the
1467 * ClientHello to detect version rollback attacks (strangely, the
1468 * protocol does not offer such protection for DH ciphersuites).
1469 * However, buggy clients exist that send the negotiated protocol
1470 * version instead if the server does not support the requested
1471 * protocol version.
1472 * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */
1473 if (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) &&
1474 (p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))
1475 {
1476 al=SSL_AD_DECODE_ERROR;
1477 /* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */
1478
1479 /* The Klima-Pokorny-Rosa extension of Bleichenbacher's attack
1480 * (http://eprint.iacr.org/2003/052/) exploits the version
1481 * number check as a "bad version oracle" -- an alert would
1482 * reveal that the plaintext corresponding to some ciphertext
1483 * made up by the adversary is properly formatted except
1484 * that the version number is wrong. To avoid such attacks,
1485 * we should treat this just like any other decryption error. */
1486 }
1487 }
1488
1489 if (al != -1)
1490 {
1491 /* Some decryption failure -- use random value instead as countermeasure
1492 * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding
1493 * (see RFC 2246, section 7.4.7.1). */
1494 ERR_clear_error();
1495 i = SSL_MAX_MASTER_KEY_LENGTH;
1496 p[0] = s->client_version >> 8;
1497 p[1] = s->client_version & 0xff;
1498 if(RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */
1499 goto err;
1500 }
1501
1502 s->session->master_key_length=
1503 s->method->ssl3_enc->generate_master_secret(s,
1504 s->session->master_key,
1505 p,i);
1506 OPENSSL_cleanse(p,i);
1507 }
1508 else
1509#endif
1510#ifndef OPENSSL_NO_DH
1511 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1512 {
1513 n2s(p,i);
1514 if (n != i+2)
1515 {
1516 if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))
1517 {
1518 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);
1519 goto err;
1520 }
1521 else
1522 {
1523 p-=2;
1524 i=(int)n;
1525 }
1526 }
1527
1528 if (n == 0L) /* the parameters are in the cert */
1529 {
1530 al=SSL_AD_HANDSHAKE_FAILURE;
1531 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);
1532 goto f_err;
1533 }
1534 else
1535 {
1536 if (s->s3->tmp.dh == NULL)
1537 {
1538 al=SSL_AD_HANDSHAKE_FAILURE;
1539 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
1540 goto f_err;
1541 }
1542 else
1543 dh_srvr=s->s3->tmp.dh;
1544 }
1545
1546 pub=BN_bin2bn(p,i,NULL);
1547 if (pub == NULL)
1548 {
1549 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);
1550 goto err;
1551 }
1552
1553 i=DH_compute_key(p,pub,dh_srvr);
1554
1555 if (i <= 0)
1556 {
1557 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1558 goto err;
1559 }
1560
1561 DH_free(s->s3->tmp.dh);
1562 s->s3->tmp.dh=NULL;
1563
1564 BN_clear_free(pub);
1565 pub=NULL;
1566 s->session->master_key_length=
1567 s->method->ssl3_enc->generate_master_secret(s,
1568 s->session->master_key,p,i);
1569 OPENSSL_cleanse(p,i);
1570 }
1571 else
1572#endif
1573#ifndef OPENSSL_NO_KRB5
1574 if (l & SSL_kKRB5)
1575 {
1576 krb5_error_code krb5rc;
1577 krb5_data enc_ticket;
1578 krb5_data authenticator;
1579 krb5_data enc_pms;
1580 KSSL_CTX *kssl_ctx = s->kssl_ctx;
1581 EVP_CIPHER_CTX ciph_ctx;
1582 EVP_CIPHER *enc = NULL;
1583 unsigned char iv[EVP_MAX_IV_LENGTH];
1584 unsigned char pms[SSL_MAX_MASTER_KEY_LENGTH
1585 + EVP_MAX_BLOCK_LENGTH];
1586 int padl, outl;
1587 krb5_timestamp authtime = 0;
1588 krb5_ticket_times ttimes;
1589
1590 EVP_CIPHER_CTX_init(&ciph_ctx);
1591
1592 if (!kssl_ctx) kssl_ctx = kssl_ctx_new();
1593
1594 n2s(p,i);
1595 enc_ticket.length = i;
1596
1597 if (n < (long)enc_ticket.length + 6)
1598 {
1599 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1600 SSL_R_DATA_LENGTH_TOO_LONG);
1601 goto err;
1602 }
1603
1604 enc_ticket.data = (char *)p;
1605 p+=enc_ticket.length;
1606
1607 n2s(p,i);
1608 authenticator.length = i;
1609
1610 if (n < (long)(enc_ticket.length + authenticator.length + 6))
1611 {
1612 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1613 SSL_R_DATA_LENGTH_TOO_LONG);
1614 goto err;
1615 }
1616
1617 authenticator.data = (char *)p;
1618 p+=authenticator.length;
1619
1620 n2s(p,i);
1621 enc_pms.length = i;
1622 enc_pms.data = (char *)p;
1623 p+=enc_pms.length;
1624
1625 /* Note that the length is checked again below,
1626 ** after decryption
1627 */
1628 if(enc_pms.length > sizeof pms)
1629 {
1630 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1631 SSL_R_DATA_LENGTH_TOO_LONG);
1632 goto err;
1633 }
1634
1635 if (n != (long)(enc_ticket.length + authenticator.length +
1636 enc_pms.length + 6))
1637 {
1638 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1639 SSL_R_DATA_LENGTH_TOO_LONG);
1640 goto err;
1641 }
1642
1643 if ((krb5rc = kssl_sget_tkt(kssl_ctx, &enc_ticket, &ttimes,
1644 &kssl_err)) != 0)
1645 {
1646#ifdef KSSL_DEBUG
1647 printf("kssl_sget_tkt rtn %d [%d]\n",
1648 krb5rc, kssl_err.reason);
1649 if (kssl_err.text)
1650 printf("kssl_err text= %s\n", kssl_err.text);
1651#endif /* KSSL_DEBUG */
1652 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
1653 kssl_err.reason);
1654 goto err;
1655 }
1656
1657 /* Note: no authenticator is not considered an error,
1658 ** but will return authtime == 0.
1659 */
1660 if ((krb5rc = kssl_check_authent(kssl_ctx, &authenticator,
1661 &authtime, &kssl_err)) != 0)
1662 {
1663#ifdef KSSL_DEBUG
1664 printf("kssl_check_authent rtn %d [%d]\n",
1665 krb5rc, kssl_err.reason);
1666 if (kssl_err.text)
1667 printf("kssl_err text= %s\n", kssl_err.text);
1668#endif /* KSSL_DEBUG */
1669 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
1670 kssl_err.reason);
1671 goto err;
1672 }
1673
1674 if ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0)
1675 {
1676 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, krb5rc);
1677 goto err;
1678 }
1679
1680#ifdef KSSL_DEBUG
1681 kssl_ctx_show(kssl_ctx);
1682#endif /* KSSL_DEBUG */
1683
1684 enc = kssl_map_enc(kssl_ctx->enctype);
1685 if (enc == NULL)
1686 goto err;
1687
1688 memset(iv, 0, sizeof iv); /* per RFC 1510 */
1689
1690 if (!EVP_DecryptInit_ex(&ciph_ctx,enc,NULL,kssl_ctx->key,iv))
1691 {
1692 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1693 SSL_R_DECRYPTION_FAILED);
1694 goto err;
1695 }
1696 if (!EVP_DecryptUpdate(&ciph_ctx, pms,&outl,
1697 (unsigned char *)enc_pms.data, enc_pms.length))
1698 {
1699 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1700 SSL_R_DECRYPTION_FAILED);
1701 goto err;
1702 }
1703 if (outl > SSL_MAX_MASTER_KEY_LENGTH)
1704 {
1705 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1706 SSL_R_DATA_LENGTH_TOO_LONG);
1707 goto err;
1708 }
1709 if (!EVP_DecryptFinal_ex(&ciph_ctx,&(pms[outl]),&padl))
1710 {
1711 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1712 SSL_R_DECRYPTION_FAILED);
1713 goto err;
1714 }
1715 outl += padl;
1716 if (outl > SSL_MAX_MASTER_KEY_LENGTH)
1717 {
1718 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1719 SSL_R_DATA_LENGTH_TOO_LONG);
1720 goto err;
1721 }
1722 EVP_CIPHER_CTX_cleanup(&ciph_ctx);
1723
1724 s->session->master_key_length=
1725 s->method->ssl3_enc->generate_master_secret(s,
1726 s->session->master_key, pms, outl);
1727
1728 if (kssl_ctx->client_princ)
1729 {
1730 int len = strlen(kssl_ctx->client_princ);
1731 if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH )
1732 {
1733 s->session->krb5_client_princ_len = len;
1734 memcpy(s->session->krb5_client_princ,kssl_ctx->client_princ,len);
1735 }
1736 }
1737
1738
1739 /* Was doing kssl_ctx_free() here,
1740 ** but it caused problems for apache.
1741 ** kssl_ctx = kssl_ctx_free(kssl_ctx);
1742 ** if (s->kssl_ctx) s->kssl_ctx = NULL;
1743 */
1744 }
1745 else
1746#endif /* OPENSSL_NO_KRB5 */
1747 {
1748 al=SSL_AD_HANDSHAKE_FAILURE;
1749 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
1750 SSL_R_UNKNOWN_CIPHER_TYPE);
1751 goto f_err;
1752 }
1753
1754 return(1);
1755f_err:
1756 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1757#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA)
1758err:
1759#endif
1760 return(-1);
1761 }
1762
1763static int ssl3_get_cert_verify(SSL *s)
1764 {
1765 EVP_PKEY *pkey=NULL;
1766 unsigned char *p;
1767 int al,ok,ret=0;
1768 long n;
1769 int type=0,i,j;
1770 X509 *peer;
1771
1772 n=ssl3_get_message(s,
1773 SSL3_ST_SR_CERT_VRFY_A,
1774 SSL3_ST_SR_CERT_VRFY_B,
1775 -1,
1776 514, /* 514? */
1777 &ok);
1778
1779 if (!ok) return((int)n);
1780
1781 if (s->session->peer != NULL)
1782 {
1783 peer=s->session->peer;
1784 pkey=X509_get_pubkey(peer);
1785 type=X509_certificate_type(peer,pkey);
1786 }
1787 else
1788 {
1789 peer=NULL;
1790 pkey=NULL;
1791 }
1792
1793 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY)
1794 {
1795 s->s3->tmp.reuse_message=1;
1796 if ((peer != NULL) && (type | EVP_PKT_SIGN))
1797 {
1798 al=SSL_AD_UNEXPECTED_MESSAGE;
1799 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_MISSING_VERIFY_MESSAGE);
1800 goto f_err;
1801 }
1802 ret=1;
1803 goto end;
1804 }
1805
1806 if (peer == NULL)
1807 {
1808 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_NO_CLIENT_CERT_RECEIVED);
1809 al=SSL_AD_UNEXPECTED_MESSAGE;
1810 goto f_err;
1811 }
1812
1813 if (!(type & EVP_PKT_SIGN))
1814 {
1815 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);
1816 al=SSL_AD_ILLEGAL_PARAMETER;
1817 goto f_err;
1818 }
1819
1820 if (s->s3->change_cipher_spec)
1821 {
1822 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY);
1823 al=SSL_AD_UNEXPECTED_MESSAGE;
1824 goto f_err;
1825 }
1826
1827 /* we now have a signature that we need to verify */
1828 p=(unsigned char *)s->init_msg;
1829 n2s(p,i);
1830 n-=2;
1831 if (i > n)
1832 {
1833 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH);
1834 al=SSL_AD_DECODE_ERROR;
1835 goto f_err;
1836 }
1837
1838 j=EVP_PKEY_size(pkey);
1839 if ((i > j) || (n > j) || (n <= 0))
1840 {
1841 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_WRONG_SIGNATURE_SIZE);
1842 al=SSL_AD_DECODE_ERROR;
1843 goto f_err;
1844 }
1845
1846#ifndef OPENSSL_NO_RSA
1847 if (pkey->type == EVP_PKEY_RSA)
1848 {
1849 i=RSA_verify(NID_md5_sha1, s->s3->tmp.cert_verify_md,
1850 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, p, i,
1851 pkey->pkey.rsa);
1852 if (i < 0)
1853 {
1854 al=SSL_AD_DECRYPT_ERROR;
1855 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_DECRYPT);
1856 goto f_err;
1857 }
1858 if (i == 0)
1859 {
1860 al=SSL_AD_DECRYPT_ERROR;
1861 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_SIGNATURE);
1862 goto f_err;
1863 }
1864 }
1865 else
1866#endif
1867#ifndef OPENSSL_NO_DSA
1868 if (pkey->type == EVP_PKEY_DSA)
1869 {
1870 j=DSA_verify(pkey->save_type,
1871 &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]),
1872 SHA_DIGEST_LENGTH,p,i,pkey->pkey.dsa);
1873 if (j <= 0)
1874 {
1875 /* bad signature */
1876 al=SSL_AD_DECRYPT_ERROR;
1877 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_DSA_SIGNATURE);
1878 goto f_err;
1879 }
1880 }
1881 else
1882#endif
1883 {
1884 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,ERR_R_INTERNAL_ERROR);
1885 al=SSL_AD_UNSUPPORTED_CERTIFICATE;
1886 goto f_err;
1887 }
1888
1889
1890 ret=1;
1891 if (0)
1892 {
1893f_err:
1894 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1895 }
1896end:
1897 EVP_PKEY_free(pkey);
1898 return(ret);
1899 }
1900
1901static int ssl3_get_client_certificate(SSL *s)
1902 {
1903 int i,ok,al,ret= -1;
1904 X509 *x=NULL;
1905 unsigned long l,nc,llen,n;
1906 unsigned char *p,*d,*q;
1907 STACK_OF(X509) *sk=NULL;
1908
1909 n=ssl3_get_message(s,
1910 SSL3_ST_SR_CERT_A,
1911 SSL3_ST_SR_CERT_B,
1912 -1,
1913 s->max_cert_list,
1914 &ok);
1915
1916 if (!ok) return((int)n);
1917
1918 if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE)
1919 {
1920 if ( (s->verify_mode & SSL_VERIFY_PEER) &&
1921 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1922 {
1923 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1924 al=SSL_AD_HANDSHAKE_FAILURE;
1925 goto f_err;
1926 }
1927 /* If tls asked for a client cert, the client must return a 0 list */
1928 if ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request)
1929 {
1930 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST);
1931 al=SSL_AD_UNEXPECTED_MESSAGE;
1932 goto f_err;
1933 }
1934 s->s3->tmp.reuse_message=1;
1935 return(1);
1936 }
1937
1938 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
1939 {
1940 al=SSL_AD_UNEXPECTED_MESSAGE;
1941 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE);
1942 goto f_err;
1943 }
1944 d=p=(unsigned char *)s->init_msg;
1945
1946 if ((sk=sk_X509_new_null()) == NULL)
1947 {
1948 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1949 goto err;
1950 }
1951
1952 n2l3(p,llen);
1953 if (llen+3 != n)
1954 {
1955 al=SSL_AD_DECODE_ERROR;
1956 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
1957 goto f_err;
1958 }
1959 for (nc=0; nc<llen; )
1960 {
1961 n2l3(p,l);
1962 if ((l+nc+3) > llen)
1963 {
1964 al=SSL_AD_DECODE_ERROR;
1965 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1966 goto f_err;
1967 }
1968
1969 q=p;
1970 x=d2i_X509(NULL,&p,l);
1971 if (x == NULL)
1972 {
1973 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB);
1974 goto err;
1975 }
1976 if (p != (q+l))
1977 {
1978 al=SSL_AD_DECODE_ERROR;
1979 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1980 goto f_err;
1981 }
1982 if (!sk_X509_push(sk,x))
1983 {
1984 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1985 goto err;
1986 }
1987 x=NULL;
1988 nc+=l+3;
1989 }
1990
1991 if (sk_X509_num(sk) <= 0)
1992 {
1993 /* TLS does not mind 0 certs returned */
1994 if (s->version == SSL3_VERSION)
1995 {
1996 al=SSL_AD_HANDSHAKE_FAILURE;
1997 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED);
1998 goto f_err;
1999 }
2000 /* Fail for TLS only if we required a certificate */
2001 else if ((s->verify_mode & SSL_VERIFY_PEER) &&
2002 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
2003 {
2004 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
2005 al=SSL_AD_HANDSHAKE_FAILURE;
2006 goto f_err;
2007 }
2008 }
2009 else
2010 {
2011 i=ssl_verify_cert_chain(s,sk);
2012 if (!i)
2013 {
2014 al=ssl_verify_alarm_type(s->verify_result);
2015 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED);
2016 goto f_err;
2017 }
2018 }
2019
2020 if (s->session->peer != NULL) /* This should not be needed */
2021 X509_free(s->session->peer);
2022 s->session->peer=sk_X509_shift(sk);
2023 s->session->verify_result = s->verify_result;
2024
2025 /* With the current implementation, sess_cert will always be NULL
2026 * when we arrive here. */
2027 if (s->session->sess_cert == NULL)
2028 {
2029 s->session->sess_cert = ssl_sess_cert_new();
2030 if (s->session->sess_cert == NULL)
2031 {
2032 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE, ERR_R_MALLOC_FAILURE);
2033 goto err;
2034 }
2035 }
2036 if (s->session->sess_cert->cert_chain != NULL)
2037 sk_X509_pop_free(s->session->sess_cert->cert_chain, X509_free);
2038 s->session->sess_cert->cert_chain=sk;
2039 /* Inconsistency alert: cert_chain does *not* include the
2040 * peer's own certificate, while we do include it in s3_clnt.c */
2041
2042 sk=NULL;
2043
2044 ret=1;
2045 if (0)
2046 {
2047f_err:
2048 ssl3_send_alert(s,SSL3_AL_FATAL,al);
2049 }
2050err:
2051 if (x != NULL) X509_free(x);
2052 if (sk != NULL) sk_X509_pop_free(sk,X509_free);
2053 return(ret);
2054 }
2055
2056int ssl3_send_server_certificate(SSL *s)
2057 {
2058 unsigned long l;
2059 X509 *x;
2060
2061 if (s->state == SSL3_ST_SW_CERT_A)
2062 {
2063 x=ssl_get_server_send_cert(s);
2064 if (x == NULL &&
2065 /* VRS: allow null cert if auth == KRB5 */
2066 (s->s3->tmp.new_cipher->algorithms
2067 & (SSL_MKEY_MASK|SSL_AUTH_MASK))
2068 != (SSL_aKRB5|SSL_kKRB5))
2069 {
2070 SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR);
2071 return(0);
2072 }
2073
2074 l=ssl3_output_cert_chain(s,x);
2075 s->state=SSL3_ST_SW_CERT_B;
2076 s->init_num=(int)l;
2077 s->init_off=0;
2078 }
2079
2080 /* SSL3_ST_SW_CERT_B */
2081 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
2082 }
diff --git a/src/lib/libssl/shlib_version b/src/lib/libssl/shlib_version
deleted file mode 100644
index f461c53390..0000000000
--- a/src/lib/libssl/shlib_version
+++ /dev/null
@@ -1,2 +0,0 @@
1major=11
2minor=0
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
deleted file mode 100644
index 99e188086b..0000000000
--- a/src/lib/libssl/ssl.h
+++ /dev/null
@@ -1,1853 +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 * Copyright (c) 1998-2001 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 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
113 *
114 * Redistribution and use in source and binary forms, with or without
115 * modification, are permitted provided that the following conditions
116 * are met:
117 *
118 * 1. Redistributions of source code must retain the above copyright
119 * notice, this list of conditions and the following disclaimer.
120 *
121 * 2. Redistributions in binary form must reproduce the above copyright
122 * notice, this list of conditions and the following disclaimer in
123 * the documentation and/or other materials provided with the
124 * distribution.
125 *
126 * 3. All advertising materials mentioning features or use of this
127 * software must display the following acknowledgment:
128 * "This product includes software developed by the OpenSSL Project
129 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
130 *
131 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
132 * endorse or promote products derived from this software without
133 * prior written permission. For written permission, please contact
134 * openssl-core@openssl.org.
135 *
136 * 5. Products derived from this software may not be called "OpenSSL"
137 * nor may "OpenSSL" appear in their names without prior written
138 * permission of the OpenSSL Project.
139 *
140 * 6. Redistributions of any form whatsoever must retain the following
141 * acknowledgment:
142 * "This product includes software developed by the OpenSSL Project
143 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
144 *
145 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
146 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
147 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
148 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
149 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
150 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
151 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
152 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
153 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
154 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
155 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
156 * OF THE POSSIBILITY OF SUCH DAMAGE.
157 * ====================================================================
158 *
159 * This product includes cryptographic software written by Eric Young
160 * (eay@cryptsoft.com). This product includes software written by Tim
161 * Hudson (tjh@cryptsoft.com).
162 *
163 */
164
165#ifndef HEADER_SSL_H
166#define HEADER_SSL_H
167
168#include <openssl/e_os2.h>
169
170#ifndef OPENSSL_NO_COMP
171#include <openssl/comp.h>
172#endif
173#ifndef OPENSSL_NO_BIO
174#include <openssl/bio.h>
175#endif
176#ifndef OPENSSL_NO_X509
177#include <openssl/x509.h>
178#endif
179#include <openssl/kssl.h>
180#include <openssl/safestack.h>
181#include <openssl/symhacks.h>
182
183#ifdef __cplusplus
184extern "C" {
185#endif
186
187/* SSLeay version number for ASN.1 encoding of the session information */
188/* Version 0 - initial version
189 * Version 1 - added the optional peer certificate
190 */
191#define SSL_SESSION_ASN1_VERSION 0x0001
192
193/* text strings for the ciphers */
194#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5
195#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5
196#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5
197#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5
198#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5
199#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5
200#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5
201#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA
202#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5
203#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA
204
205/* VRS Additional Kerberos5 entries
206 */
207#define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA
208#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA
209#define SSL_TXT_KRB5_RC4_128_SHA SSL3_TXT_KRB5_RC4_128_SHA
210#define SSL_TXT_KRB5_IDEA_128_CBC_SHA SSL3_TXT_KRB5_IDEA_128_CBC_SHA
211#define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5
212#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5
213#define SSL_TXT_KRB5_RC4_128_MD5 SSL3_TXT_KRB5_RC4_128_MD5
214#define SSL_TXT_KRB5_IDEA_128_CBC_MD5 SSL3_TXT_KRB5_IDEA_128_CBC_MD5
215
216#define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA
217#define SSL_TXT_KRB5_RC2_40_CBC_SHA SSL3_TXT_KRB5_RC2_40_CBC_SHA
218#define SSL_TXT_KRB5_RC4_40_SHA SSL3_TXT_KRB5_RC4_40_SHA
219#define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5
220#define SSL_TXT_KRB5_RC2_40_CBC_MD5 SSL3_TXT_KRB5_RC2_40_CBC_MD5
221#define SSL_TXT_KRB5_RC4_40_MD5 SSL3_TXT_KRB5_RC4_40_MD5
222
223#define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA
224#define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5
225#define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA
226#define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5
227#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA
228#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5
229#define SSL_MAX_KRB5_PRINCIPAL_LENGTH 256
230
231#define SSL_MAX_SSL_SESSION_ID_LENGTH 32
232#define SSL_MAX_SID_CTX_LENGTH 32
233
234#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8)
235#define SSL_MAX_KEY_ARG_LENGTH 8
236#define SSL_MAX_MASTER_KEY_LENGTH 48
237
238/* These are used to specify which ciphers to use and not to use */
239#define SSL_TXT_LOW "LOW"
240#define SSL_TXT_MEDIUM "MEDIUM"
241#define SSL_TXT_HIGH "HIGH"
242#define SSL_TXT_FIPS "FIPS"
243#define SSL_TXT_kFZA "kFZA"
244#define SSL_TXT_aFZA "aFZA"
245#define SSL_TXT_eFZA "eFZA"
246#define SSL_TXT_FZA "FZA"
247
248#define SSL_TXT_aNULL "aNULL"
249#define SSL_TXT_eNULL "eNULL"
250#define SSL_TXT_NULL "NULL"
251
252#define SSL_TXT_kKRB5 "kKRB5"
253#define SSL_TXT_aKRB5 "aKRB5"
254#define SSL_TXT_KRB5 "KRB5"
255
256#define SSL_TXT_kRSA "kRSA"
257#define SSL_TXT_kDHr "kDHr"
258#define SSL_TXT_kDHd "kDHd"
259#define SSL_TXT_kEDH "kEDH"
260#define SSL_TXT_aRSA "aRSA"
261#define SSL_TXT_aDSS "aDSS"
262#define SSL_TXT_aDH "aDH"
263#define SSL_TXT_DSS "DSS"
264#define SSL_TXT_DH "DH"
265#define SSL_TXT_EDH "EDH"
266#define SSL_TXT_ADH "ADH"
267#define SSL_TXT_RSA "RSA"
268#define SSL_TXT_DES "DES"
269#define SSL_TXT_3DES "3DES"
270#define SSL_TXT_RC4 "RC4"
271#define SSL_TXT_RC2 "RC2"
272#define SSL_TXT_IDEA "IDEA"
273#define SSL_TXT_AES "AES"
274#define SSL_TXT_MD5 "MD5"
275#define SSL_TXT_SHA1 "SHA1"
276#define SSL_TXT_SHA "SHA"
277#define SSL_TXT_EXP "EXP"
278#define SSL_TXT_EXPORT "EXPORT"
279#define SSL_TXT_EXP40 "EXPORT40"
280#define SSL_TXT_EXP56 "EXPORT56"
281#define SSL_TXT_SSLV2 "SSLv2"
282#define SSL_TXT_SSLV3 "SSLv3"
283#define SSL_TXT_TLSV1 "TLSv1"
284#define SSL_TXT_ALL "ALL"
285
286/*
287 * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
288 * ciphers normally not being used.
289 * Example: "RC4" will activate all ciphers using RC4 including ciphers
290 * without authentication, which would normally disabled by DEFAULT (due
291 * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"
292 * will make sure that it is also disabled in the specific selection.
293 * COMPLEMENTOF* identifiers are portable between version, as adjustments
294 * to the default cipher setup will also be included here.
295 *
296 * COMPLEMENTOFDEFAULT does not experience the same special treatment that
297 * DEFAULT gets, as only selection is being done and no sorting as needed
298 * for DEFAULT.
299 */
300#define SSL_TXT_CMPALL "COMPLEMENTOFALL"
301#define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT"
302
303/* The following cipher list is used by default.
304 * It also is substituted when an application-defined cipher list string
305 * starts with 'DEFAULT'. */
306#define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:+RC4:@STRENGTH" /* low priority for RC4 */
307
308/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
309#define SSL_SENT_SHUTDOWN 1
310#define SSL_RECEIVED_SHUTDOWN 2
311
312#ifdef __cplusplus
313}
314#endif
315
316#include <openssl/crypto.h>
317#include <openssl/lhash.h>
318#include <openssl/buffer.h>
319#include <openssl/pem.h>
320
321#ifdef __cplusplus
322extern "C" {
323#endif
324
325#if (defined(OPENSSL_NO_RSA) || defined(OPENSSL_NO_MD5)) && !defined(OPENSSL_NO_SSL2)
326#define OPENSSL_NO_SSL2
327#endif
328
329#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
330#define SSL_FILETYPE_PEM X509_FILETYPE_PEM
331
332/* This is needed to stop compilers complaining about the
333 * 'struct ssl_st *' function parameters used to prototype callbacks
334 * in SSL_CTX. */
335typedef struct ssl_st *ssl_crock_st;
336
337/* used to hold info on the particular ciphers used */
338typedef struct ssl_cipher_st
339 {
340 int valid;
341 const char *name; /* text name */
342 unsigned long id; /* id, 4 bytes, first is version */
343 unsigned long algorithms; /* what ciphers are used */
344 unsigned long algo_strength; /* strength and export flags */
345 unsigned long algorithm2; /* Extra flags */
346 int strength_bits; /* Number of bits really used */
347 int alg_bits; /* Number of bits for algorithm */
348 unsigned long mask; /* used for matching */
349 unsigned long mask_strength; /* also used for matching */
350 } SSL_CIPHER;
351
352DECLARE_STACK_OF(SSL_CIPHER)
353
354typedef struct ssl_st SSL;
355typedef struct ssl_ctx_st SSL_CTX;
356
357/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
358typedef struct ssl_method_st
359 {
360 int version;
361 int (*ssl_new)(SSL *s);
362 void (*ssl_clear)(SSL *s);
363 void (*ssl_free)(SSL *s);
364 int (*ssl_accept)(SSL *s);
365 int (*ssl_connect)(SSL *s);
366 int (*ssl_read)(SSL *s,void *buf,int len);
367 int (*ssl_peek)(SSL *s,void *buf,int len);
368 int (*ssl_write)(SSL *s,const void *buf,int len);
369 int (*ssl_shutdown)(SSL *s);
370 int (*ssl_renegotiate)(SSL *s);
371 int (*ssl_renegotiate_check)(SSL *s);
372 long (*ssl_ctrl)(SSL *s,int cmd,long larg,void *parg);
373 long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,void *parg);
374 SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
375 int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr);
376 int (*ssl_pending)(const SSL *s);
377 int (*num_ciphers)(void);
378 SSL_CIPHER *(*get_cipher)(unsigned ncipher);
379 struct ssl_method_st *(*get_ssl_method)(int version);
380 long (*get_timeout)(void);
381 struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
382 int (*ssl_version)();
383 long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)());
384 long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)());
385 } SSL_METHOD;
386
387/* Lets make this into an ASN.1 type structure as follows
388 * SSL_SESSION_ID ::= SEQUENCE {
389 * version INTEGER, -- structure version number
390 * SSLversion INTEGER, -- SSL version number
391 * Cipher OCTET_STRING, -- the 3 byte cipher ID
392 * Session_ID OCTET_STRING, -- the Session ID
393 * Master_key OCTET_STRING, -- the master key
394 * KRB5_principal OCTET_STRING -- optional Kerberos principal
395 * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument
396 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
397 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
398 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
399 * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context
400 * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer'
401 * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX
402 * }
403 * Look in ssl/ssl_asn1.c for more details
404 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
405 */
406typedef struct ssl_session_st
407 {
408 int ssl_version; /* what ssl version session info is
409 * being kept in here? */
410
411 /* only really used in SSLv2 */
412 unsigned int key_arg_length;
413 unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];
414 int master_key_length;
415 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
416 /* session_id - valid? */
417 unsigned int session_id_length;
418 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
419 /* this is used to determine whether the session is being reused in
420 * the appropriate context. It is up to the application to set this,
421 * via SSL_new */
422 unsigned int sid_ctx_length;
423 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
424
425#ifndef OPENSSL_NO_KRB5
426 unsigned int krb5_client_princ_len;
427 unsigned char krb5_client_princ[SSL_MAX_KRB5_PRINCIPAL_LENGTH];
428#endif /* OPENSSL_NO_KRB5 */
429
430 int not_resumable;
431
432 /* The cert is the certificate used to establish this connection */
433 struct sess_cert_st /* SESS_CERT */ *sess_cert;
434
435 /* This is the cert for the other end.
436 * On clients, it will be the same as sess_cert->peer_key->x509
437 * (the latter is not enough as sess_cert is not retained
438 * in the external representation of sessions, see ssl_asn1.c). */
439 X509 *peer;
440 /* when app_verify_callback accepts a session where the peer's certificate
441 * is not ok, we must remember the error for session reuse: */
442 long verify_result; /* only for servers */
443
444 int references;
445 long timeout;
446 long time;
447
448 int compress_meth; /* Need to lookup the method */
449
450 SSL_CIPHER *cipher;
451 unsigned long cipher_id; /* when ASN.1 loaded, this
452 * needs to be used to load
453 * the 'cipher' structure */
454
455 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
456
457 CRYPTO_EX_DATA ex_data; /* application specific data */
458
459 /* These are used to make removal of session-ids more
460 * efficient and to implement a maximum cache size. */
461 struct ssl_session_st *prev,*next;
462 } SSL_SESSION;
463
464
465#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L
466#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L
467#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L
468#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L
469#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L
470#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L /* no effect since 0.9.7h and 0.9.8b */
471#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L
472#define SSL_OP_TLS_D5_BUG 0x00000100L
473#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L
474
475/* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
476 * in OpenSSL 0.9.6d. Usually (depending on the application protocol)
477 * the workaround is not needed. Unfortunately some broken SSL/TLS
478 * implementations cannot handle it at all, which is why we include
479 * it in SSL_OP_ALL. */
480#define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800L /* added in 0.9.6e */
481
482/* SSL_OP_ALL: various bug workarounds that should be rather harmless.
483 * This used to be 0x000FFFFFL before 0.9.7. */
484#define SSL_OP_ALL 0x00000FFFL
485
486/* As server, disallow session resumption on renegotiation */
487#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000L
488/* If set, always create a new key when using tmp_dh parameters */
489#define SSL_OP_SINGLE_DH_USE 0x00100000L
490/* Set to always use the tmp_rsa key when doing RSA operations,
491 * even when this violates protocol specs */
492#define SSL_OP_EPHEMERAL_RSA 0x00200000L
493/* Set on servers to choose the cipher according to the server's
494 * preferences */
495#define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000L
496/* If set, a server will allow a client to issue a SSLv3.0 version number
497 * as latest version supported in the premaster secret, even when TLSv1.0
498 * (version 3.1) was announced in the client hello. Normally this is
499 * forbidden to prevent version rollback attacks. */
500#define SSL_OP_TLS_ROLLBACK_BUG 0x00800000L
501
502#define SSL_OP_NO_SSLv2 0x01000000L
503#define SSL_OP_NO_SSLv3 0x02000000L
504#define SSL_OP_NO_TLSv1 0x04000000L
505
506/* The next flag deliberately changes the ciphertest, this is a check
507 * for the PKCS#1 attack */
508#define SSL_OP_PKCS1_CHECK_1 0x08000000L
509#define SSL_OP_PKCS1_CHECK_2 0x10000000L
510#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L
511#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x40000000L
512
513
514/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
515 * when just a single record has been written): */
516#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
517/* Make it possible to retry SSL_write() with changed buffer location
518 * (buffer contents must stay the same!); this is not the default to avoid
519 * the misconception that non-blocking SSL_write() behaves like
520 * non-blocking write(): */
521#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
522/* Never bother the application with retries if the transport
523 * is blocking: */
524#define SSL_MODE_AUTO_RETRY 0x00000004L
525/* Don't attempt to automatically build certificate chain */
526#define SSL_MODE_NO_AUTO_CHAIN 0x00000008L
527
528
529/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
530 * they cannot be used to clear bits. */
531
532#define SSL_CTX_set_options(ctx,op) \
533 SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL)
534#define SSL_CTX_get_options(ctx) \
535 SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,0,NULL)
536#define SSL_set_options(ssl,op) \
537 SSL_ctrl((ssl),SSL_CTRL_OPTIONS,(op),NULL)
538#define SSL_get_options(ssl) \
539 SSL_ctrl((ssl),SSL_CTRL_OPTIONS,0,NULL)
540
541#define SSL_CTX_set_mode(ctx,op) \
542 SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
543#define SSL_CTX_get_mode(ctx) \
544 SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)
545#define SSL_set_mode(ssl,op) \
546 SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)
547#define SSL_get_mode(ssl) \
548 SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)
549
550
551void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
552void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
553#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
554#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
555
556
557
558#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32)
559#define SSL_MAX_CERT_LIST_DEFAULT 1024*30 /* 30k max cert list :-) */
560#else
561#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */
562#endif
563
564#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
565
566/* This callback type is used inside SSL_CTX, SSL, and in the functions that set
567 * them. It is used to override the generation of SSL/TLS session IDs in a
568 * server. Return value should be zero on an error, non-zero to proceed. Also,
569 * callbacks should themselves check if the id they generate is unique otherwise
570 * the SSL handshake will fail with an error - callbacks can do this using the
571 * 'ssl' value they're passed by;
572 * SSL_has_matching_session_id(ssl, id, *id_len)
573 * The length value passed in is set at the maximum size the session ID can be.
574 * In SSLv2 this is 16 bytes, whereas SSLv3/TLSv1 it is 32 bytes. The callback
575 * can alter this length to be less if desired, but under SSLv2 session IDs are
576 * supposed to be fixed at 16 bytes so the id will be padded after the callback
577 * returns in this case. It is also an error for the callback to set the size to
578 * zero. */
579typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,
580 unsigned int *id_len);
581
582typedef struct ssl_comp_st
583 {
584 int id;
585 char *name;
586#ifndef OPENSSL_NO_COMP
587 COMP_METHOD *method;
588#else
589 char *method;
590#endif
591 } SSL_COMP;
592
593DECLARE_STACK_OF(SSL_COMP)
594
595struct ssl_ctx_st
596 {
597 SSL_METHOD *method;
598
599 STACK_OF(SSL_CIPHER) *cipher_list;
600 /* same as above but sorted for lookup */
601 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
602
603 struct x509_store_st /* X509_STORE */ *cert_store;
604 struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */
605 /* Most session-ids that will be cached, default is
606 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
607 unsigned long session_cache_size;
608 struct ssl_session_st *session_cache_head;
609 struct ssl_session_st *session_cache_tail;
610
611 /* This can have one of 2 values, ored together,
612 * SSL_SESS_CACHE_CLIENT,
613 * SSL_SESS_CACHE_SERVER,
614 * Default is SSL_SESSION_CACHE_SERVER, which means only
615 * SSL_accept which cache SSL_SESSIONS. */
616 int session_cache_mode;
617
618 /* If timeout is not 0, it is the default timeout value set
619 * when SSL_new() is called. This has been put in to make
620 * life easier to set things up */
621 long session_timeout;
622
623 /* If this callback is not null, it will be called each
624 * time a session id is added to the cache. If this function
625 * returns 1, it means that the callback will do a
626 * SSL_SESSION_free() when it has finished using it. Otherwise,
627 * on 0, it means the callback has finished with it.
628 * If remove_session_cb is not null, it will be called when
629 * a session-id is removed from the cache. After the call,
630 * OpenSSL will SSL_SESSION_free() it. */
631 int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);
632 void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);
633 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
634 unsigned char *data,int len,int *copy);
635
636 struct
637 {
638 int sess_connect; /* SSL new conn - started */
639 int sess_connect_renegotiate;/* SSL reneg - requested */
640 int sess_connect_good; /* SSL new conne/reneg - finished */
641 int sess_accept; /* SSL new accept - started */
642 int sess_accept_renegotiate;/* SSL reneg - requested */
643 int sess_accept_good; /* SSL accept/reneg - finished */
644 int sess_miss; /* session lookup misses */
645 int sess_timeout; /* reuse attempt on timeouted session */
646 int sess_cache_full; /* session removed due to full cache */
647 int sess_hit; /* session reuse actually done */
648 int sess_cb_hit; /* session-id that was not
649 * in the cache was
650 * passed back via the callback. This
651 * indicates that the application is
652 * supplying session-id's from other
653 * processes - spooky :-) */
654 } stats;
655
656 int references;
657
658 /* if defined, these override the X509_verify_cert() calls */
659 int (*app_verify_callback)(X509_STORE_CTX *, void *);
660 void *app_verify_arg;
661 /* before OpenSSL 0.9.7, 'app_verify_arg' was ignored
662 * ('app_verify_callback' was called with just one argument) */
663
664 /* Default password callback. */
665 pem_password_cb *default_passwd_callback;
666
667 /* Default password callback user data. */
668 void *default_passwd_callback_userdata;
669
670 /* get client cert callback */
671 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
672
673 CRYPTO_EX_DATA ex_data;
674
675 const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */
676 const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
677 const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */
678
679 STACK_OF(X509) *extra_certs;
680 STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */
681
682
683 /* Default values used when no per-SSL value is defined follow */
684
685 void (*info_callback)(const SSL *ssl,int type,int val); /* used if SSL's info_callback is NULL */
686
687 /* what we put in client cert requests */
688 STACK_OF(X509_NAME) *client_CA;
689
690
691 /* Default values to use in SSL structures follow (these are copied by SSL_new) */
692
693 unsigned long options;
694 unsigned long mode;
695 long max_cert_list;
696
697 struct cert_st /* CERT */ *cert;
698 int read_ahead;
699
700 /* callback that allows applications to peek at protocol messages */
701 void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg);
702 void *msg_callback_arg;
703
704 int verify_mode;
705 int verify_depth;
706 unsigned int sid_ctx_length;
707 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
708 int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */
709
710 /* Default generate session ID callback. */
711 GEN_SESSION_CB generate_session_id;
712
713 int purpose; /* Purpose setting */
714 int trust; /* Trust setting */
715
716 int quiet_shutdown;
717 };
718
719#define SSL_SESS_CACHE_OFF 0x0000
720#define SSL_SESS_CACHE_CLIENT 0x0001
721#define SSL_SESS_CACHE_SERVER 0x0002
722#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
723#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
724/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */
725#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
726#define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200
727#define SSL_SESS_CACHE_NO_INTERNAL \
728 (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)
729
730 struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);
731#define SSL_CTX_sess_number(ctx) \
732 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
733#define SSL_CTX_sess_connect(ctx) \
734 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
735#define SSL_CTX_sess_connect_good(ctx) \
736 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
737#define SSL_CTX_sess_connect_renegotiate(ctx) \
738 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
739#define SSL_CTX_sess_accept(ctx) \
740 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
741#define SSL_CTX_sess_accept_renegotiate(ctx) \
742 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
743#define SSL_CTX_sess_accept_good(ctx) \
744 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
745#define SSL_CTX_sess_hits(ctx) \
746 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
747#define SSL_CTX_sess_cb_hits(ctx) \
748 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
749#define SSL_CTX_sess_misses(ctx) \
750 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
751#define SSL_CTX_sess_timeouts(ctx) \
752 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
753#define SSL_CTX_sess_cache_full(ctx) \
754 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)
755
756#define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))
757#define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb)
758#define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb))
759#define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)
760#define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))
761#define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb)
762#define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb))
763#define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback)
764#define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb))
765#define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb)
766
767#define SSL_NOTHING 1
768#define SSL_WRITING 2
769#define SSL_READING 3
770#define SSL_X509_LOOKUP 4
771
772/* These will only be used when doing non-blocking IO */
773#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)
774#define SSL_want_read(s) (SSL_want(s) == SSL_READING)
775#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)
776#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)
777
778struct ssl_st
779 {
780 /* protocol version
781 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION)
782 */
783 int version;
784 int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
785
786 SSL_METHOD *method; /* SSLv3 */
787
788 /* There are 2 BIO's even though they are normally both the
789 * same. This is so data can be read and written to different
790 * handlers */
791
792#ifndef OPENSSL_NO_BIO
793 BIO *rbio; /* used by SSL_read */
794 BIO *wbio; /* used by SSL_write */
795 BIO *bbio; /* used during session-id reuse to concatenate
796 * messages */
797#else
798 char *rbio; /* used by SSL_read */
799 char *wbio; /* used by SSL_write */
800 char *bbio;
801#endif
802 /* This holds a variable that indicates what we were doing
803 * when a 0 or -1 is returned. This is needed for
804 * non-blocking IO so we know what request needs re-doing when
805 * in SSL_accept or SSL_connect */
806 int rwstate;
807
808 /* true when we are actually in SSL_accept() or SSL_connect() */
809 int in_handshake;
810 int (*handshake_func)();
811
812 /* Imagine that here's a boolean member "init" that is
813 * switched as soon as SSL_set_{accept/connect}_state
814 * is called for the first time, so that "state" and
815 * "handshake_func" are properly initialized. But as
816 * handshake_func is == 0 until then, we use this
817 * test instead of an "init" member.
818 */
819
820 int server; /* are we the server side? - mostly used by SSL_clear*/
821
822 int new_session;/* 1 if we are to use a new session.
823 * 2 if we are a server and are inside a handshake
824 * (i.e. not just sending a HelloRequest)
825 * NB: For servers, the 'new' session may actually be a previously
826 * cached session or even the previous session unless
827 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */
828 int quiet_shutdown;/* don't send shutdown packets */
829 int shutdown; /* we have shut things down, 0x01 sent, 0x02
830 * for received */
831 int state; /* where we are */
832 int rstate; /* where we are when reading */
833
834 BUF_MEM *init_buf; /* buffer used during init */
835 void *init_msg; /* pointer to handshake message body, set by ssl3_get_message() */
836 int init_num; /* amount read/written */
837 int init_off; /* amount read/written */
838
839 /* used internally to point at a raw packet */
840 unsigned char *packet;
841 unsigned int packet_length;
842
843 struct ssl2_state_st *s2; /* SSLv2 variables */
844 struct ssl3_state_st *s3; /* SSLv3 variables */
845
846 int read_ahead; /* Read as many input bytes as possible
847 * (for non-blocking reads) */
848
849 /* callback that allows applications to peek at protocol messages */
850 void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg);
851 void *msg_callback_arg;
852
853 int hit; /* reusing a previous session */
854
855 int purpose; /* Purpose setting */
856 int trust; /* Trust setting */
857
858 /* crypto */
859 STACK_OF(SSL_CIPHER) *cipher_list;
860 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
861
862 /* These are the ones being used, the ones in SSL_SESSION are
863 * the ones to be 'copied' into these ones */
864
865 EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
866 const EVP_MD *read_hash; /* used for mac generation */
867#ifndef OPENSSL_NO_COMP
868 COMP_CTX *expand; /* uncompress */
869#else
870 char *expand;
871#endif
872
873 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
874 const EVP_MD *write_hash; /* used for mac generation */
875#ifndef OPENSSL_NO_COMP
876 COMP_CTX *compress; /* compression */
877#else
878 char *compress;
879#endif
880
881 /* session info */
882
883 /* client cert? */
884 /* This is used to hold the server certificate used */
885 struct cert_st /* CERT */ *cert;
886
887 /* the session_id_context is used to ensure sessions are only reused
888 * in the appropriate context */
889 unsigned int sid_ctx_length;
890 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
891
892 /* This can also be in the session once a session is established */
893 SSL_SESSION *session;
894
895 /* Default generate session ID callback. */
896 GEN_SESSION_CB generate_session_id;
897
898 /* Used in SSL2 and SSL3 */
899 int verify_mode; /* 0 don't care about verify failure.
900 * 1 fail if verify fails */
901 int verify_depth;
902 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
903
904 void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */
905
906 int error; /* error bytes to be written */
907 int error_code; /* actual code */
908
909#ifndef OPENSSL_NO_KRB5
910 KSSL_CTX *kssl_ctx; /* Kerberos 5 context */
911#endif /* OPENSSL_NO_KRB5 */
912
913 SSL_CTX *ctx;
914 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
915 * and SSL_write() calls, good for nbio debuging :-) */
916 int debug;
917
918 /* extra application data */
919 long verify_result;
920 CRYPTO_EX_DATA ex_data;
921
922 /* for server side, keep the list of CA_dn we can use */
923 STACK_OF(X509_NAME) *client_CA;
924
925 int references;
926 unsigned long options; /* protocol behaviour */
927 unsigned long mode; /* API behaviour */
928 long max_cert_list;
929 int first_packet;
930 int client_version; /* what was passed, used for
931 * SSLv3/TLS rollback check */
932 };
933
934#ifdef __cplusplus
935}
936#endif
937
938#include <openssl/ssl2.h>
939#include <openssl/ssl3.h>
940#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */
941#include <openssl/ssl23.h>
942
943#ifdef __cplusplus
944extern "C" {
945#endif
946
947/* compatibility */
948#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
949#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
950#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
951#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
952#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
953#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
954
955/* The following are the possible values for ssl->state are are
956 * used to indicate where we are up to in the SSL connection establishment.
957 * The macros that follow are about the only things you should need to use
958 * and even then, only when using non-blocking IO.
959 * It can also be useful to work out where you were when the connection
960 * failed */
961
962#define SSL_ST_CONNECT 0x1000
963#define SSL_ST_ACCEPT 0x2000
964#define SSL_ST_MASK 0x0FFF
965#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
966#define SSL_ST_BEFORE 0x4000
967#define SSL_ST_OK 0x03
968#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
969
970#define SSL_CB_LOOP 0x01
971#define SSL_CB_EXIT 0x02
972#define SSL_CB_READ 0x04
973#define SSL_CB_WRITE 0x08
974#define SSL_CB_ALERT 0x4000 /* used in callback */
975#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
976#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
977#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
978#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
979#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
980#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
981#define SSL_CB_HANDSHAKE_START 0x10
982#define SSL_CB_HANDSHAKE_DONE 0x20
983
984/* Is the SSL_connection established? */
985#define SSL_get_state(a) SSL_state(a)
986#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)
987#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)
988#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)
989#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)
990#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
991
992/* The following 2 states are kept in ssl->rstate when reads fail,
993 * you should not need these */
994#define SSL_ST_READ_HEADER 0xF0
995#define SSL_ST_READ_BODY 0xF1
996#define SSL_ST_READ_DONE 0xF2
997
998/* Obtain latest Finished message
999 * -- that we sent (SSL_get_finished)
1000 * -- that we expected from peer (SSL_get_peer_finished).
1001 * Returns length (0 == no Finished so far), copies up to 'count' bytes. */
1002size_t SSL_get_finished(const SSL *s, void *buf, size_t count);
1003size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
1004
1005/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
1006 * are 'ored' with SSL_VERIFY_PEER if they are desired */
1007#define SSL_VERIFY_NONE 0x00
1008#define SSL_VERIFY_PEER 0x01
1009#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
1010#define SSL_VERIFY_CLIENT_ONCE 0x04
1011
1012#define OpenSSL_add_ssl_algorithms() SSL_library_init()
1013#define SSLeay_add_ssl_algorithms() SSL_library_init()
1014
1015/* this is for backward compatibility */
1016#if 0 /* NEW_SSLEAY */
1017#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)
1018#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n)
1019#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b))
1020#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b))
1021#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b))
1022#endif
1023/* More backward compatibility */
1024#define SSL_get_cipher(s) \
1025 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
1026#define SSL_get_cipher_bits(s,np) \
1027 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
1028#define SSL_get_cipher_version(s) \
1029 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
1030#define SSL_get_cipher_name(s) \
1031 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
1032#define SSL_get_time(a) SSL_SESSION_get_time(a)
1033#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
1034#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
1035#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
1036
1037#if 1 /*SSLEAY_MACROS*/
1038#define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
1039 (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
1040 (bp),(unsigned char **)(s_id))
1041#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \
1042 bp,(unsigned char *)s_id)
1043#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
1044 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
1045#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
1046 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
1047#define PEM_write_SSL_SESSION(fp,x) \
1048 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
1049 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
1050#define PEM_write_bio_SSL_SESSION(bp,x) \
1051 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
1052 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
1053#endif
1054
1055#define SSL_AD_REASON_OFFSET 1000
1056/* These alert types are for SSLv3 and TLSv1 */
1057#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
1058#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
1059#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */
1060#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
1061#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
1062#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */
1063#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */
1064#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */
1065#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
1066#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
1067#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
1068#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
1069#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
1070#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */
1071#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */
1072#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */
1073#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */
1074#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
1075#define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */
1076#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */
1077#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */
1078#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */
1079#define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED
1080#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
1081
1082#define SSL_ERROR_NONE 0
1083#define SSL_ERROR_SSL 1
1084#define SSL_ERROR_WANT_READ 2
1085#define SSL_ERROR_WANT_WRITE 3
1086#define SSL_ERROR_WANT_X509_LOOKUP 4
1087#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */
1088#define SSL_ERROR_ZERO_RETURN 6
1089#define SSL_ERROR_WANT_CONNECT 7
1090#define SSL_ERROR_WANT_ACCEPT 8
1091
1092#define SSL_CTRL_NEED_TMP_RSA 1
1093#define SSL_CTRL_SET_TMP_RSA 2
1094#define SSL_CTRL_SET_TMP_DH 3
1095#define SSL_CTRL_SET_TMP_RSA_CB 4
1096#define SSL_CTRL_SET_TMP_DH_CB 5
1097
1098#define SSL_CTRL_GET_SESSION_REUSED 6
1099#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7
1100#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8
1101#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9
1102#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10
1103#define SSL_CTRL_GET_FLAGS 11
1104#define SSL_CTRL_EXTRA_CHAIN_CERT 12
1105
1106#define SSL_CTRL_SET_MSG_CALLBACK 13
1107#define SSL_CTRL_SET_MSG_CALLBACK_ARG 14
1108
1109/* Stats */
1110#define SSL_CTRL_SESS_NUMBER 20
1111#define SSL_CTRL_SESS_CONNECT 21
1112#define SSL_CTRL_SESS_CONNECT_GOOD 22
1113#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23
1114#define SSL_CTRL_SESS_ACCEPT 24
1115#define SSL_CTRL_SESS_ACCEPT_GOOD 25
1116#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26
1117#define SSL_CTRL_SESS_HIT 27
1118#define SSL_CTRL_SESS_CB_HIT 28
1119#define SSL_CTRL_SESS_MISSES 29
1120#define SSL_CTRL_SESS_TIMEOUTS 30
1121#define SSL_CTRL_SESS_CACHE_FULL 31
1122#define SSL_CTRL_OPTIONS 32
1123#define SSL_CTRL_MODE 33
1124
1125#define SSL_CTRL_GET_READ_AHEAD 40
1126#define SSL_CTRL_SET_READ_AHEAD 41
1127#define SSL_CTRL_SET_SESS_CACHE_SIZE 42
1128#define SSL_CTRL_GET_SESS_CACHE_SIZE 43
1129#define SSL_CTRL_SET_SESS_CACHE_MODE 44
1130#define SSL_CTRL_GET_SESS_CACHE_MODE 45
1131
1132#define SSL_CTRL_GET_MAX_CERT_LIST 50
1133#define SSL_CTRL_SET_MAX_CERT_LIST 51
1134
1135#define SSL_session_reused(ssl) \
1136 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
1137#define SSL_num_renegotiations(ssl) \
1138 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
1139#define SSL_clear_num_renegotiations(ssl) \
1140 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
1141#define SSL_total_renegotiations(ssl) \
1142 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
1143
1144#define SSL_CTX_need_tmp_RSA(ctx) \
1145 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
1146#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
1147 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
1148#define SSL_CTX_set_tmp_dh(ctx,dh) \
1149 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
1150
1151#define SSL_need_tmp_RSA(ssl) \
1152 SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
1153#define SSL_set_tmp_rsa(ssl,rsa) \
1154 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
1155#define SSL_set_tmp_dh(ssl,dh) \
1156 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
1157
1158#define SSL_CTX_add_extra_chain_cert(ctx,x509) \
1159 SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
1160
1161#ifndef OPENSSL_NO_BIO
1162BIO_METHOD *BIO_f_ssl(void);
1163BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
1164BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
1165BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
1166int BIO_ssl_copy_session_id(BIO *to,BIO *from);
1167void BIO_ssl_shutdown(BIO *ssl_bio);
1168
1169#endif
1170
1171int SSL_CTX_set_cipher_list(SSL_CTX *,const char *str);
1172SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
1173void SSL_CTX_free(SSL_CTX *);
1174long SSL_CTX_set_timeout(SSL_CTX *ctx,long t);
1175long SSL_CTX_get_timeout(const SSL_CTX *ctx);
1176X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *);
1177void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *);
1178int SSL_want(const SSL *s);
1179int SSL_clear(SSL *s);
1180
1181void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
1182
1183SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
1184int SSL_CIPHER_get_bits(const SSL_CIPHER *c,int *alg_bits);
1185char * SSL_CIPHER_get_version(const SSL_CIPHER *c);
1186const char * SSL_CIPHER_get_name(const SSL_CIPHER *c);
1187
1188int SSL_get_fd(const SSL *s);
1189int SSL_get_rfd(const SSL *s);
1190int SSL_get_wfd(const SSL *s);
1191const char * SSL_get_cipher_list(const SSL *s,int n);
1192char * SSL_get_shared_ciphers(const SSL *s, char *buf, int len);
1193int SSL_get_read_ahead(const SSL * s);
1194int SSL_pending(const SSL *s);
1195#ifndef OPENSSL_NO_SOCK
1196int SSL_set_fd(SSL *s, int fd);
1197int SSL_set_rfd(SSL *s, int fd);
1198int SSL_set_wfd(SSL *s, int fd);
1199#endif
1200#ifndef OPENSSL_NO_BIO
1201void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
1202BIO * SSL_get_rbio(const SSL *s);
1203BIO * SSL_get_wbio(const SSL *s);
1204#endif
1205int SSL_set_cipher_list(SSL *s, const char *str);
1206void SSL_set_read_ahead(SSL *s, int yes);
1207int SSL_get_verify_mode(const SSL *s);
1208int SSL_get_verify_depth(const SSL *s);
1209int (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *);
1210void SSL_set_verify(SSL *s, int mode,
1211 int (*callback)(int ok,X509_STORE_CTX *ctx));
1212void SSL_set_verify_depth(SSL *s, int depth);
1213#ifndef OPENSSL_NO_RSA
1214int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
1215#endif
1216int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
1217int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
1218int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
1219int SSL_use_certificate(SSL *ssl, X509 *x);
1220int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
1221
1222#ifndef OPENSSL_NO_STDIO
1223int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
1224int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
1225int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
1226int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1227int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1228int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
1229int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
1230STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
1231int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
1232 const char *file);
1233#ifndef OPENSSL_SYS_VMS
1234#ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! [was: #ifndef MAC_OS_pre_X] */
1235int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
1236 const char *dir);
1237#endif
1238#endif
1239
1240#endif
1241
1242void SSL_load_error_strings(void );
1243const char *SSL_state_string(const SSL *s);
1244const char *SSL_rstate_string(const SSL *s);
1245const char *SSL_state_string_long(const SSL *s);
1246const char *SSL_rstate_string_long(const SSL *s);
1247long SSL_SESSION_get_time(const SSL_SESSION *s);
1248long SSL_SESSION_set_time(SSL_SESSION *s, long t);
1249long SSL_SESSION_get_timeout(const SSL_SESSION *s);
1250long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
1251void SSL_copy_session_id(SSL *to,const SSL *from);
1252
1253SSL_SESSION *SSL_SESSION_new(void);
1254unsigned long SSL_SESSION_hash(const SSL_SESSION *a);
1255int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b);
1256#ifndef OPENSSL_NO_FP_API
1257int SSL_SESSION_print_fp(FILE *fp,const SSL_SESSION *ses);
1258#endif
1259#ifndef OPENSSL_NO_BIO
1260int SSL_SESSION_print(BIO *fp,const SSL_SESSION *ses);
1261#endif
1262void SSL_SESSION_free(SSL_SESSION *ses);
1263int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
1264int SSL_set_session(SSL *to, SSL_SESSION *session);
1265int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
1266int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
1267int SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB);
1268int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB);
1269int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
1270 unsigned int id_len);
1271SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,const unsigned char * const *pp,
1272 long length);
1273
1274#ifdef HEADER_X509_H
1275X509 * SSL_get_peer_certificate(const SSL *s);
1276#endif
1277
1278STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s);
1279
1280int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
1281int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
1282int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *);
1283void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,
1284 int (*callback)(int, X509_STORE_CTX *));
1285void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
1286void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg);
1287#ifndef OPENSSL_NO_RSA
1288int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
1289#endif
1290int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
1291int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
1292int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
1293 unsigned char *d, long len);
1294int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
1295int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
1296
1297void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
1298void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
1299
1300int SSL_CTX_check_private_key(const SSL_CTX *ctx);
1301int SSL_check_private_key(const SSL *ctx);
1302
1303int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
1304 unsigned int sid_ctx_len);
1305
1306SSL * SSL_new(SSL_CTX *ctx);
1307int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
1308 unsigned int sid_ctx_len);
1309
1310int SSL_CTX_set_purpose(SSL_CTX *s, int purpose);
1311int SSL_set_purpose(SSL *s, int purpose);
1312int SSL_CTX_set_trust(SSL_CTX *s, int trust);
1313int SSL_set_trust(SSL *s, int trust);
1314
1315void SSL_free(SSL *ssl);
1316int SSL_accept(SSL *ssl);
1317int SSL_connect(SSL *ssl);
1318int SSL_read(SSL *ssl,void *buf,int num);
1319int SSL_peek(SSL *ssl,void *buf,int num);
1320int SSL_write(SSL *ssl,const void *buf,int num);
1321long SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg);
1322long SSL_callback_ctrl(SSL *, int, void (*)());
1323long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, void *parg);
1324long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)());
1325
1326int SSL_get_error(const SSL *s,int ret_code);
1327const char *SSL_get_version(const SSL *s);
1328
1329/* This sets the 'default' SSL version that SSL_new() will create */
1330int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
1331
1332SSL_METHOD *SSLv2_method(void); /* SSLv2 */
1333SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */
1334SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */
1335
1336SSL_METHOD *SSLv3_method(void); /* SSLv3 */
1337SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */
1338SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */
1339
1340SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */
1341SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */
1342SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */
1343
1344SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
1345SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
1346SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
1347
1348STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);
1349
1350int SSL_do_handshake(SSL *s);
1351int SSL_renegotiate(SSL *s);
1352int SSL_renegotiate_pending(SSL *s);
1353int SSL_shutdown(SSL *s);
1354
1355SSL_METHOD *SSL_get_ssl_method(SSL *s);
1356int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
1357const char *SSL_alert_type_string_long(int value);
1358const char *SSL_alert_type_string(int value);
1359const char *SSL_alert_desc_string_long(int value);
1360const char *SSL_alert_desc_string(int value);
1361
1362void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
1363void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
1364STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);
1365STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s);
1366int SSL_add_client_CA(SSL *ssl,X509 *x);
1367int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);
1368
1369void SSL_set_connect_state(SSL *s);
1370void SSL_set_accept_state(SSL *s);
1371
1372long SSL_get_default_timeout(const SSL *s);
1373
1374int SSL_library_init(void );
1375
1376char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
1377STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk);
1378
1379SSL *SSL_dup(SSL *ssl);
1380
1381X509 *SSL_get_certificate(const SSL *ssl);
1382/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
1383
1384void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
1385int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
1386void SSL_set_quiet_shutdown(SSL *ssl,int mode);
1387int SSL_get_quiet_shutdown(const SSL *ssl);
1388void SSL_set_shutdown(SSL *ssl,int mode);
1389int SSL_get_shutdown(const SSL *ssl);
1390int SSL_version(const SSL *ssl);
1391int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
1392int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1393 const char *CApath);
1394#define SSL_get0_session SSL_get_session /* just peek at pointer */
1395SSL_SESSION *SSL_get_session(const SSL *ssl);
1396SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
1397SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
1398void SSL_set_info_callback(SSL *ssl,
1399 void (*cb)(const SSL *ssl,int type,int val));
1400void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val);
1401int SSL_state(const SSL *ssl);
1402
1403void SSL_set_verify_result(SSL *ssl,long v);
1404long SSL_get_verify_result(const SSL *ssl);
1405
1406int SSL_set_ex_data(SSL *ssl,int idx,void *data);
1407void *SSL_get_ex_data(const SSL *ssl,int idx);
1408int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1409 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1410
1411int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data);
1412void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss,int idx);
1413int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1414 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1415
1416int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data);
1417void *SSL_CTX_get_ex_data(const SSL_CTX *ssl,int idx);
1418int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1419 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1420
1421int SSL_get_ex_data_X509_STORE_CTX_idx(void );
1422
1423#define SSL_CTX_sess_set_cache_size(ctx,t) \
1424 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
1425#define SSL_CTX_sess_get_cache_size(ctx) \
1426 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
1427#define SSL_CTX_set_session_cache_mode(ctx,m) \
1428 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
1429#define SSL_CTX_get_session_cache_mode(ctx) \
1430 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
1431
1432#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
1433#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
1434#define SSL_CTX_get_read_ahead(ctx) \
1435 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
1436#define SSL_CTX_set_read_ahead(ctx,m) \
1437 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)
1438#define SSL_CTX_get_max_cert_list(ctx) \
1439 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
1440#define SSL_CTX_set_max_cert_list(ctx,m) \
1441 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
1442#define SSL_get_max_cert_list(ssl) \
1443 SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
1444#define SSL_set_max_cert_list(ssl,m) \
1445 SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
1446
1447 /* NB: the keylength is only applicable when is_export is true */
1448#ifndef OPENSSL_NO_RSA
1449void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
1450 RSA *(*cb)(SSL *ssl,int is_export,
1451 int keylength));
1452
1453void SSL_set_tmp_rsa_callback(SSL *ssl,
1454 RSA *(*cb)(SSL *ssl,int is_export,
1455 int keylength));
1456#endif
1457#ifndef OPENSSL_NO_DH
1458void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
1459 DH *(*dh)(SSL *ssl,int is_export,
1460 int keylength));
1461void SSL_set_tmp_dh_callback(SSL *ssl,
1462 DH *(*dh)(SSL *ssl,int is_export,
1463 int keylength));
1464#endif
1465
1466#ifndef OPENSSL_NO_COMP
1467int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);
1468#else
1469int SSL_COMP_add_compression_method(int id,char *cm);
1470#endif
1471
1472/* BEGIN ERROR CODES */
1473/* The following lines are auto generated by the script mkerr.pl. Any changes
1474 * made after this point may be overwritten when the script is next run.
1475 */
1476void ERR_load_SSL_strings(void);
1477
1478/* Error codes for the SSL functions. */
1479
1480/* Function codes. */
1481#define SSL_F_CLIENT_CERTIFICATE 100
1482#define SSL_F_CLIENT_FINISHED 238
1483#define SSL_F_CLIENT_HELLO 101
1484#define SSL_F_CLIENT_MASTER_KEY 102
1485#define SSL_F_D2I_SSL_SESSION 103
1486#define SSL_F_DO_SSL3_WRITE 104
1487#define SSL_F_GET_CLIENT_FINISHED 105
1488#define SSL_F_GET_CLIENT_HELLO 106
1489#define SSL_F_GET_CLIENT_MASTER_KEY 107
1490#define SSL_F_GET_SERVER_FINISHED 108
1491#define SSL_F_GET_SERVER_HELLO 109
1492#define SSL_F_GET_SERVER_VERIFY 110
1493#define SSL_F_I2D_SSL_SESSION 111
1494#define SSL_F_READ_N 112
1495#define SSL_F_REQUEST_CERTIFICATE 113
1496#define SSL_F_SERVER_FINISH 239
1497#define SSL_F_SERVER_HELLO 114
1498#define SSL_F_SERVER_VERIFY 240
1499#define SSL_F_SSL23_ACCEPT 115
1500#define SSL_F_SSL23_CLIENT_HELLO 116
1501#define SSL_F_SSL23_CONNECT 117
1502#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1503#define SSL_F_SSL23_GET_SERVER_HELLO 119
1504#define SSL_F_SSL23_PEEK 237
1505#define SSL_F_SSL23_READ 120
1506#define SSL_F_SSL23_WRITE 121
1507#define SSL_F_SSL2_ACCEPT 122
1508#define SSL_F_SSL2_CONNECT 123
1509#define SSL_F_SSL2_ENC_INIT 124
1510#define SSL_F_SSL2_GENERATE_KEY_MATERIAL 241
1511#define SSL_F_SSL2_PEEK 234
1512#define SSL_F_SSL2_READ 125
1513#define SSL_F_SSL2_READ_INTERNAL 236
1514#define SSL_F_SSL2_SET_CERTIFICATE 126
1515#define SSL_F_SSL2_WRITE 127
1516#define SSL_F_SSL3_ACCEPT 128
1517#define SSL_F_SSL3_CALLBACK_CTRL 233
1518#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1519#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1520#define SSL_F_SSL3_CLIENT_HELLO 131
1521#define SSL_F_SSL3_CONNECT 132
1522#define SSL_F_SSL3_CTRL 213
1523#define SSL_F_SSL3_CTX_CTRL 133
1524#define SSL_F_SSL3_ENC 134
1525#define SSL_F_SSL3_GENERATE_KEY_BLOCK 238
1526#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1527#define SSL_F_SSL3_GET_CERT_VERIFY 136
1528#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1529#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1530#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1531#define SSL_F_SSL3_GET_FINISHED 140
1532#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1533#define SSL_F_SSL3_GET_MESSAGE 142
1534#define SSL_F_SSL3_GET_RECORD 143
1535#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1536#define SSL_F_SSL3_GET_SERVER_DONE 145
1537#define SSL_F_SSL3_GET_SERVER_HELLO 146
1538#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1539#define SSL_F_SSL3_PEEK 235
1540#define SSL_F_SSL3_READ_BYTES 148
1541#define SSL_F_SSL3_READ_N 149
1542#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1543#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1544#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1545#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1546#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1547#define SSL_F_SSL3_SEND_SERVER_HELLO 242
1548#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1549#define SSL_F_SSL3_SETUP_BUFFERS 156
1550#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1551#define SSL_F_SSL3_WRITE_BYTES 158
1552#define SSL_F_SSL3_WRITE_PENDING 159
1553#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215
1554#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216
1555#define SSL_F_SSL_BAD_METHOD 160
1556#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1557#define SSL_F_SSL_CERT_DUP 221
1558#define SSL_F_SSL_CERT_INST 222
1559#define SSL_F_SSL_CERT_INSTANTIATE 214
1560#define SSL_F_SSL_CERT_NEW 162
1561#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1562#define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230
1563#define SSL_F_SSL_CIPHER_STRENGTH_SORT 231
1564#define SSL_F_SSL_CLEAR 164
1565#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165
1566#define SSL_F_SSL_CREATE_CIPHER_LIST 166
1567#define SSL_F_SSL_CTRL 232
1568#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168
1569#define SSL_F_SSL_CTX_NEW 169
1570#define SSL_F_SSL_CTX_SET_CIPHER_LIST 269
1571#define SSL_F_SSL_CTX_SET_PURPOSE 226
1572#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219
1573#define SSL_F_SSL_CTX_SET_SSL_VERSION 170
1574#define SSL_F_SSL_CTX_SET_TRUST 229
1575#define SSL_F_SSL_CTX_USE_CERTIFICATE 171
1576#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172
1577#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220
1578#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173
1579#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174
1580#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175
1581#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176
1582#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
1583#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
1584#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
1585#define SSL_F_SSL_DO_HANDSHAKE 180
1586#define SSL_F_SSL_GET_NEW_SESSION 181
1587#define SSL_F_SSL_GET_PREV_SESSION 217
1588#define SSL_F_SSL_GET_SERVER_SEND_CERT 182
1589#define SSL_F_SSL_GET_SIGN_PKEY 183
1590#define SSL_F_SSL_INIT_WBIO_BUFFER 184
1591#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185
1592#define SSL_F_SSL_NEW 186
1593#define SSL_F_SSL_READ 223
1594#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187
1595#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188
1596#define SSL_F_SSL_SESSION_NEW 189
1597#define SSL_F_SSL_SESSION_PRINT_FP 190
1598#define SSL_F_SSL_SESS_CERT_NEW 225
1599#define SSL_F_SSL_SET_CERT 191
1600#define SSL_F_SSL_SET_CIPHER_LIST 271
1601#define SSL_F_SSL_SET_FD 192
1602#define SSL_F_SSL_SET_PKEY 193
1603#define SSL_F_SSL_SET_PURPOSE 227
1604#define SSL_F_SSL_SET_RFD 194
1605#define SSL_F_SSL_SET_SESSION 195
1606#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218
1607#define SSL_F_SSL_SET_TRUST 228
1608#define SSL_F_SSL_SET_WFD 196
1609#define SSL_F_SSL_SHUTDOWN 224
1610#define SSL_F_SSL_UNDEFINED_CONST_FUNCTION 243
1611#define SSL_F_SSL_UNDEFINED_FUNCTION 197
1612#define SSL_F_SSL_USE_CERTIFICATE 198
1613#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199
1614#define SSL_F_SSL_USE_CERTIFICATE_FILE 200
1615#define SSL_F_SSL_USE_PRIVATEKEY 201
1616#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202
1617#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203
1618#define SSL_F_SSL_USE_RSAPRIVATEKEY 204
1619#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205
1620#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206
1621#define SSL_F_SSL_VERIFY_CERT_CHAIN 207
1622#define SSL_F_SSL_WRITE 208
1623#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209
1624#define SSL_F_TLS1_ENC 210
1625#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
1626#define SSL_F_WRITE_PENDING 212
1627
1628/* Reason codes. */
1629#define SSL_R_APP_DATA_IN_HANDSHAKE 100
1630#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272
1631#define SSL_R_BAD_ALERT_RECORD 101
1632#define SSL_R_BAD_AUTHENTICATION_TYPE 102
1633#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
1634#define SSL_R_BAD_CHECKSUM 104
1635#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
1636#define SSL_R_BAD_DECOMPRESSION 107
1637#define SSL_R_BAD_DH_G_LENGTH 108
1638#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
1639#define SSL_R_BAD_DH_P_LENGTH 110
1640#define SSL_R_BAD_DIGEST_LENGTH 111
1641#define SSL_R_BAD_DSA_SIGNATURE 112
1642#define SSL_R_BAD_HELLO_REQUEST 105
1643#define SSL_R_BAD_LENGTH 271
1644#define SSL_R_BAD_MAC_DECODE 113
1645#define SSL_R_BAD_MESSAGE_TYPE 114
1646#define SSL_R_BAD_PACKET_LENGTH 115
1647#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
1648#define SSL_R_BAD_RESPONSE_ARGUMENT 117
1649#define SSL_R_BAD_RSA_DECRYPT 118
1650#define SSL_R_BAD_RSA_ENCRYPT 119
1651#define SSL_R_BAD_RSA_E_LENGTH 120
1652#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
1653#define SSL_R_BAD_RSA_SIGNATURE 122
1654#define SSL_R_BAD_SIGNATURE 123
1655#define SSL_R_BAD_SSL_FILETYPE 124
1656#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
1657#define SSL_R_BAD_STATE 126
1658#define SSL_R_BAD_WRITE_RETRY 127
1659#define SSL_R_BIO_NOT_SET 128
1660#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
1661#define SSL_R_BN_LIB 130
1662#define SSL_R_CA_DN_LENGTH_MISMATCH 131
1663#define SSL_R_CA_DN_TOO_LONG 132
1664#define SSL_R_CCS_RECEIVED_EARLY 133
1665#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
1666#define SSL_R_CERT_LENGTH_MISMATCH 135
1667#define SSL_R_CHALLENGE_IS_DIFFERENT 136
1668#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
1669#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
1670#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
1671#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
1672#define SSL_R_COMPRESSION_FAILURE 141
1673#define SSL_R_COMPRESSION_LIBRARY_ERROR 142
1674#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143
1675#define SSL_R_CONNECTION_TYPE_NOT_SET 144
1676#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145
1677#define SSL_R_DATA_LENGTH_TOO_LONG 146
1678#define SSL_R_DECRYPTION_FAILED 147
1679#define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281
1680#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148
1681#define SSL_R_DIGEST_CHECK_FAILED 149
1682#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150
1683#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 282
1684#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151
1685#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152
1686#define SSL_R_EXTRA_DATA_IN_MESSAGE 153
1687#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154
1688#define SSL_R_HTTPS_PROXY_REQUEST 155
1689#define SSL_R_HTTP_REQUEST 156
1690#define SSL_R_ILLEGAL_PADDING 283
1691#define SSL_R_INVALID_CHALLENGE_LENGTH 158
1692#define SSL_R_INVALID_COMMAND 280
1693#define SSL_R_INVALID_PURPOSE 278
1694#define SSL_R_INVALID_TRUST 279
1695#define SSL_R_KEY_ARG_TOO_LONG 284
1696#define SSL_R_KRB5 285
1697#define SSL_R_KRB5_C_CC_PRINC 286
1698#define SSL_R_KRB5_C_GET_CRED 287
1699#define SSL_R_KRB5_C_INIT 288
1700#define SSL_R_KRB5_C_MK_REQ 289
1701#define SSL_R_KRB5_S_BAD_TICKET 290
1702#define SSL_R_KRB5_S_INIT 291
1703#define SSL_R_KRB5_S_RD_REQ 292
1704#define SSL_R_KRB5_S_TKT_EXPIRED 293
1705#define SSL_R_KRB5_S_TKT_NYV 294
1706#define SSL_R_KRB5_S_TKT_SKEW 295
1707#define SSL_R_LENGTH_MISMATCH 159
1708#define SSL_R_LENGTH_TOO_SHORT 160
1709#define SSL_R_LIBRARY_BUG 274
1710#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161
1711#define SSL_R_MESSAGE_TOO_LONG 296
1712#define SSL_R_MISSING_DH_DSA_CERT 162
1713#define SSL_R_MISSING_DH_KEY 163
1714#define SSL_R_MISSING_DH_RSA_CERT 164
1715#define SSL_R_MISSING_DSA_SIGNING_CERT 165
1716#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166
1717#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167
1718#define SSL_R_MISSING_RSA_CERTIFICATE 168
1719#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169
1720#define SSL_R_MISSING_RSA_SIGNING_CERT 170
1721#define SSL_R_MISSING_TMP_DH_KEY 171
1722#define SSL_R_MISSING_TMP_RSA_KEY 172
1723#define SSL_R_MISSING_TMP_RSA_PKEY 173
1724#define SSL_R_MISSING_VERIFY_MESSAGE 174
1725#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
1726#define SSL_R_NO_CERTIFICATES_RETURNED 176
1727#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
1728#define SSL_R_NO_CERTIFICATE_RETURNED 178
1729#define SSL_R_NO_CERTIFICATE_SET 179
1730#define SSL_R_NO_CERTIFICATE_SPECIFIED 180
1731#define SSL_R_NO_CIPHERS_AVAILABLE 181
1732#define SSL_R_NO_CIPHERS_PASSED 182
1733#define SSL_R_NO_CIPHERS_SPECIFIED 183
1734#define SSL_R_NO_CIPHER_LIST 184
1735#define SSL_R_NO_CIPHER_MATCH 185
1736#define SSL_R_NO_CLIENT_CERT_RECEIVED 186
1737#define SSL_R_NO_COMPRESSION_SPECIFIED 187
1738#define SSL_R_NO_METHOD_SPECIFIED 188
1739#define SSL_R_NO_PRIVATEKEY 189
1740#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190
1741#define SSL_R_NO_PROTOCOLS_AVAILABLE 191
1742#define SSL_R_NO_PUBLICKEY 192
1743#define SSL_R_NO_SHARED_CIPHER 193
1744#define SSL_R_NO_VERIFY_CALLBACK 194
1745#define SSL_R_NULL_SSL_CTX 195
1746#define SSL_R_NULL_SSL_METHOD_PASSED 196
1747#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197
1748#define SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE 297
1749#define SSL_R_PACKET_LENGTH_TOO_LONG 198
1750#define SSL_R_PATH_TOO_LONG 270
1751#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199
1752#define SSL_R_PEER_ERROR 200
1753#define SSL_R_PEER_ERROR_CERTIFICATE 201
1754#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202
1755#define SSL_R_PEER_ERROR_NO_CIPHER 203
1756#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204
1757#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205
1758#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206
1759#define SSL_R_PROTOCOL_IS_SHUTDOWN 207
1760#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208
1761#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209
1762#define SSL_R_PUBLIC_KEY_NOT_RSA 210
1763#define SSL_R_READ_BIO_NOT_SET 211
1764#define SSL_R_READ_WRONG_PACKET_TYPE 212
1765#define SSL_R_RECORD_LENGTH_MISMATCH 213
1766#define SSL_R_RECORD_TOO_LARGE 214
1767#define SSL_R_RECORD_TOO_SMALL 298
1768#define SSL_R_REQUIRED_CIPHER_MISSING 215
1769#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216
1770#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217
1771#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218
1772#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277
1773#define SSL_R_SHORT_READ 219
1774#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220
1775#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221
1776#define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 299
1777#define SSL_R_SSL3_SESSION_ID_TOO_LONG 300
1778#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222
1779#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
1780#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
1781#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
1782#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
1783#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
1784#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
1785#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
1786#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
1787#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
1788#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
1789#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
1790#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228
1791#define SSL_R_SSL_HANDSHAKE_FAILURE 229
1792#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230
1793#define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED 301
1794#define SSL_R_SSL_SESSION_ID_CONFLICT 302
1795#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273
1796#define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH 303
1797#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231
1798#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
1799#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
1800#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
1801#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
1802#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
1803#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
1804#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
1805#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
1806#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
1807#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
1808#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
1809#define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
1810#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232
1811#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
1812#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234
1813#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235
1814#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236
1815#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237
1816#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238
1817#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239
1818#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240
1819#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241
1820#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242
1821#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243
1822#define SSL_R_UNEXPECTED_MESSAGE 244
1823#define SSL_R_UNEXPECTED_RECORD 245
1824#define SSL_R_UNINITIALIZED 276
1825#define SSL_R_UNKNOWN_ALERT_TYPE 246
1826#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247
1827#define SSL_R_UNKNOWN_CIPHER_RETURNED 248
1828#define SSL_R_UNKNOWN_CIPHER_TYPE 249
1829#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250
1830#define SSL_R_UNKNOWN_PKEY_TYPE 251
1831#define SSL_R_UNKNOWN_PROTOCOL 252
1832#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253
1833#define SSL_R_UNKNOWN_SSL_VERSION 254
1834#define SSL_R_UNKNOWN_STATE 255
1835#define SSL_R_UNSUPPORTED_CIPHER 256
1836#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257
1837#define SSL_R_UNSUPPORTED_PROTOCOL 258
1838#define SSL_R_UNSUPPORTED_SSL_VERSION 259
1839#define SSL_R_WRITE_BIO_NOT_SET 260
1840#define SSL_R_WRONG_CIPHER_RETURNED 261
1841#define SSL_R_WRONG_MESSAGE_TYPE 262
1842#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263
1843#define SSL_R_WRONG_SIGNATURE_LENGTH 264
1844#define SSL_R_WRONG_SIGNATURE_SIZE 265
1845#define SSL_R_WRONG_SSL_VERSION 266
1846#define SSL_R_WRONG_VERSION_NUMBER 267
1847#define SSL_R_X509_LIB 268
1848#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
1849
1850#ifdef __cplusplus
1851}
1852#endif
1853#endif
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h
deleted file mode 100644
index 99a52ea0dd..0000000000
--- a/src/lib/libssl/ssl2.h
+++ /dev/null
@@ -1,268 +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#ifdef OPENSSL_SYS_MPE
137#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 29998u
138#else
139#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 32767u /* 2^15-1 */
140#endif
141#define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /* 2^14-1 */
142
143#define SSL2_CHALLENGE_LENGTH 16
144/*#define SSL2_CHALLENGE_LENGTH 32 */
145#define SSL2_MIN_CHALLENGE_LENGTH 16
146#define SSL2_MAX_CHALLENGE_LENGTH 32
147#define SSL2_CONNECTION_ID_LENGTH 16
148#define SSL2_MAX_CONNECTION_ID_LENGTH 16
149#define SSL2_SSL_SESSION_ID_LENGTH 16
150#define SSL2_MAX_CERT_CHALLENGE_LENGTH 32
151#define SSL2_MIN_CERT_CHALLENGE_LENGTH 16
152#define SSL2_MAX_KEY_MATERIAL_LENGTH 24
153
154#ifndef HEADER_SSL_LOCL_H
155#define CERT char
156#endif
157
158typedef struct ssl2_state_st
159 {
160 int three_byte_header;
161 int clear_text; /* clear text */
162 int escape; /* not used in SSLv2 */
163 int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */
164
165 /* non-blocking io info, used to make sure the same
166 * args were passwd */
167 unsigned int wnum; /* number of bytes sent so far */
168 int wpend_tot;
169 const unsigned char *wpend_buf;
170
171 int wpend_off; /* offset to data to write */
172 int wpend_len; /* number of bytes passwd to write */
173 int wpend_ret; /* number of bytes to return to caller */
174
175 /* buffer raw data */
176 int rbuf_left;
177 int rbuf_offs;
178 unsigned char *rbuf;
179 unsigned char *wbuf;
180
181 unsigned char *write_ptr;/* used to point to the start due to
182 * 2/3 byte header. */
183
184 unsigned int padding;
185 unsigned int rlength; /* passed to ssl2_enc */
186 int ract_data_length; /* Set when things are encrypted. */
187 unsigned int wlength; /* passed to ssl2_enc */
188 int wact_data_length; /* Set when things are decrypted. */
189 unsigned char *ract_data;
190 unsigned char *wact_data;
191 unsigned char *mac_data;
192
193 unsigned char *read_key;
194 unsigned char *write_key;
195
196 /* Stuff specifically to do with this SSL session */
197 unsigned int challenge_length;
198 unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];
199 unsigned int conn_id_length;
200 unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
201 unsigned int key_material_length;
202 unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2];
203
204 unsigned long read_sequence;
205 unsigned long write_sequence;
206
207 struct {
208 unsigned int conn_id_length;
209 unsigned int cert_type;
210 unsigned int cert_length;
211 unsigned int csl;
212 unsigned int clear;
213 unsigned int enc;
214 unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];
215 unsigned int cipher_spec_length;
216 unsigned int session_id_length;
217 unsigned int clen;
218 unsigned int rlen;
219 } tmp;
220 } SSL2_STATE;
221
222/* SSLv2 */
223/* client */
224#define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT)
225#define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT)
226#define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT)
227#define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT)
228#define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT)
229#define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT)
230#define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT)
231#define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT)
232#define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT)
233#define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT)
234#define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT)
235#define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT)
236#define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT)
237#define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT)
238#define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT)
239#define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT)
240#define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT)
241#define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT)
242/* server */
243#define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT)
244#define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT)
245#define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT)
246#define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT)
247#define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT)
248#define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT)
249#define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT)
250#define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT)
251#define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT)
252#define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT)
253#define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT)
254#define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT)
255#define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT)
256#define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT)
257#define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT)
258#define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT)
259#define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT)
260#define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT)
261#define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT)
262#define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT)
263
264#ifdef __cplusplus
265}
266#endif
267#endif
268
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 1153aeda74..0000000000
--- a/src/lib/libssl/ssl3.h
+++ /dev/null
@@ -1,526 +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 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_SSL3_H
113#define HEADER_SSL3_H
114
115#ifndef OPENSSL_NO_COMP
116#include <openssl/comp.h>
117#endif
118#include <openssl/buffer.h>
119#include <openssl/evp.h>
120#include <openssl/ssl.h>
121
122#ifdef __cplusplus
123extern "C" {
124#endif
125
126#define SSL3_CK_RSA_NULL_MD5 0x03000001
127#define SSL3_CK_RSA_NULL_SHA 0x03000002
128#define SSL3_CK_RSA_RC4_40_MD5 0x03000003
129#define SSL3_CK_RSA_RC4_128_MD5 0x03000004
130#define SSL3_CK_RSA_RC4_128_SHA 0x03000005
131#define SSL3_CK_RSA_RC2_40_MD5 0x03000006
132#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007
133#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008
134#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009
135#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A
136
137#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B
138#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C
139#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D
140#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E
141#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F
142#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010
143
144#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011
145#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012
146#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013
147#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014
148#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015
149#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016
150
151#define SSL3_CK_ADH_RC4_40_MD5 0x03000017
152#define SSL3_CK_ADH_RC4_128_MD5 0x03000018
153#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019
154#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A
155#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B
156
157#define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C
158#define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D
159#if 0 /* Because it clashes with KRB5, is never used any more, and is safe
160 to remove according to David Hopwood <david.hopwood@zetnet.co.uk>
161 of the ietf-tls list */
162#define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E
163#endif
164
165/* VRS Additional Kerberos5 entries
166 */
167#define SSL3_CK_KRB5_DES_64_CBC_SHA 0x0300001E
168#define SSL3_CK_KRB5_DES_192_CBC3_SHA 0x0300001F
169#define SSL3_CK_KRB5_RC4_128_SHA 0x03000020
170#define SSL3_CK_KRB5_IDEA_128_CBC_SHA 0x03000021
171#define SSL3_CK_KRB5_DES_64_CBC_MD5 0x03000022
172#define SSL3_CK_KRB5_DES_192_CBC3_MD5 0x03000023
173#define SSL3_CK_KRB5_RC4_128_MD5 0x03000024
174#define SSL3_CK_KRB5_IDEA_128_CBC_MD5 0x03000025
175
176#define SSL3_CK_KRB5_DES_40_CBC_SHA 0x03000026
177#define SSL3_CK_KRB5_RC2_40_CBC_SHA 0x03000027
178#define SSL3_CK_KRB5_RC4_40_SHA 0x03000028
179#define SSL3_CK_KRB5_DES_40_CBC_MD5 0x03000029
180#define SSL3_CK_KRB5_RC2_40_CBC_MD5 0x0300002A
181#define SSL3_CK_KRB5_RC4_40_MD5 0x0300002B
182
183#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5"
184#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA"
185#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5"
186#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5"
187#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA"
188#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5"
189#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA"
190#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA"
191#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA"
192#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA"
193
194#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA"
195#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA"
196#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA"
197#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA"
198#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA"
199#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA"
200
201#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA"
202#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA"
203#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA"
204#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA"
205#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA"
206#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA"
207
208#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5"
209#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5"
210#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA"
211#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA"
212#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA"
213
214#define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA"
215#define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA"
216#define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA"
217
218#define SSL3_TXT_KRB5_DES_64_CBC_SHA "KRB5-DES-CBC-SHA"
219#define SSL3_TXT_KRB5_DES_192_CBC3_SHA "KRB5-DES-CBC3-SHA"
220#define SSL3_TXT_KRB5_RC4_128_SHA "KRB5-RC4-SHA"
221#define SSL3_TXT_KRB5_IDEA_128_CBC_SHA "KRB5-IDEA-CBC-SHA"
222#define SSL3_TXT_KRB5_DES_64_CBC_MD5 "KRB5-DES-CBC-MD5"
223#define SSL3_TXT_KRB5_DES_192_CBC3_MD5 "KRB5-DES-CBC3-MD5"
224#define SSL3_TXT_KRB5_RC4_128_MD5 "KRB5-RC4-MD5"
225#define SSL3_TXT_KRB5_IDEA_128_CBC_MD5 "KRB5-IDEA-CBC-MD5"
226
227#define SSL3_TXT_KRB5_DES_40_CBC_SHA "EXP-KRB5-DES-CBC-SHA"
228#define SSL3_TXT_KRB5_RC2_40_CBC_SHA "EXP-KRB5-RC2-CBC-SHA"
229#define SSL3_TXT_KRB5_RC4_40_SHA "EXP-KRB5-RC4-SHA"
230#define SSL3_TXT_KRB5_DES_40_CBC_MD5 "EXP-KRB5-DES-CBC-MD5"
231#define SSL3_TXT_KRB5_RC2_40_CBC_MD5 "EXP-KRB5-RC2-CBC-MD5"
232#define SSL3_TXT_KRB5_RC4_40_MD5 "EXP-KRB5-RC4-MD5"
233
234#define SSL3_SSL_SESSION_ID_LENGTH 32
235#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32
236
237#define SSL3_MASTER_SECRET_SIZE 48
238#define SSL3_RANDOM_SIZE 32
239#define SSL3_SESSION_ID_SIZE 32
240#define SSL3_RT_HEADER_LENGTH 5
241
242/* Due to MS stuffing up, this can change.... */
243#if defined(OPENSSL_SYS_WIN16) || \
244 (defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32))
245#define SSL3_RT_MAX_EXTRA (14000)
246#else
247#define SSL3_RT_MAX_EXTRA (16384)
248#endif
249
250#define SSL3_RT_MAX_PLAIN_LENGTH 16384
251#define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH)
252#define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH)
253#define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
254#define SSL3_RT_MAX_DATA_SIZE (1024*1024)
255
256#define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54"
257#define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52"
258
259#define SSL3_VERSION 0x0300
260#define SSL3_VERSION_MAJOR 0x03
261#define SSL3_VERSION_MINOR 0x00
262
263#define SSL3_RT_CHANGE_CIPHER_SPEC 20
264#define SSL3_RT_ALERT 21
265#define SSL3_RT_HANDSHAKE 22
266#define SSL3_RT_APPLICATION_DATA 23
267
268#define SSL3_AL_WARNING 1
269#define SSL3_AL_FATAL 2
270
271#define SSL3_AD_CLOSE_NOTIFY 0
272#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
273#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
274#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
275#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
276#define SSL3_AD_NO_CERTIFICATE 41
277#define SSL3_AD_BAD_CERTIFICATE 42
278#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
279#define SSL3_AD_CERTIFICATE_REVOKED 44
280#define SSL3_AD_CERTIFICATE_EXPIRED 45
281#define SSL3_AD_CERTIFICATE_UNKNOWN 46
282#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
283
284typedef struct ssl3_record_st
285 {
286/*r */ int type; /* type of record */
287/*rw*/ unsigned int length; /* How many bytes available */
288/*r */ unsigned int off; /* read/write offset into 'buf' */
289/*rw*/ unsigned char *data; /* pointer to the record data */
290/*rw*/ unsigned char *input; /* where the decode bytes are */
291/*r */ unsigned char *comp; /* only used with decompression - malloc()ed */
292 } SSL3_RECORD;
293
294typedef struct ssl3_buffer_st
295 {
296 unsigned char *buf; /* at least SSL3_RT_MAX_PACKET_SIZE bytes,
297 * see ssl3_setup_buffers() */
298 size_t len; /* buffer size */
299 int offset; /* where to 'copy from' */
300 int left; /* how many bytes left */
301 } SSL3_BUFFER;
302
303#define SSL3_CT_RSA_SIGN 1
304#define SSL3_CT_DSS_SIGN 2
305#define SSL3_CT_RSA_FIXED_DH 3
306#define SSL3_CT_DSS_FIXED_DH 4
307#define SSL3_CT_RSA_EPHEMERAL_DH 5
308#define SSL3_CT_DSS_EPHEMERAL_DH 6
309#define SSL3_CT_FORTEZZA_DMS 20
310#define SSL3_CT_NUMBER 7
311
312#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
313#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
314#define SSL3_FLAGS_POP_BUFFER 0x0004
315#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
316
317typedef struct ssl3_state_st
318 {
319 long flags;
320 int delay_buf_pop_ret;
321
322 unsigned char read_sequence[8];
323 unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
324 unsigned char write_sequence[8];
325 unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
326
327 unsigned char server_random[SSL3_RANDOM_SIZE];
328 unsigned char client_random[SSL3_RANDOM_SIZE];
329
330 /* flags for countermeasure against known-IV weakness */
331 int need_empty_fragments;
332 int empty_fragment_done;
333
334 SSL3_BUFFER rbuf; /* read IO goes into here */
335 SSL3_BUFFER wbuf; /* write IO goes into here */
336
337 SSL3_RECORD rrec; /* each decoded record goes in here */
338 SSL3_RECORD wrec; /* goes out from here */
339
340 /* storage for Alert/Handshake protocol data received but not
341 * yet processed by ssl3_read_bytes: */
342 unsigned char alert_fragment[2];
343 unsigned int alert_fragment_len;
344 unsigned char handshake_fragment[4];
345 unsigned int handshake_fragment_len;
346
347 /* partial write - check the numbers match */
348 unsigned int wnum; /* number of bytes sent so far */
349 int wpend_tot; /* number bytes written */
350 int wpend_type;
351 int wpend_ret; /* number of bytes submitted */
352 const unsigned char *wpend_buf;
353
354 /* used during startup, digest all incoming/outgoing packets */
355 EVP_MD_CTX finish_dgst1;
356 EVP_MD_CTX finish_dgst2;
357
358 /* this is set whenerver we see a change_cipher_spec message
359 * come in when we are not looking for one */
360 int change_cipher_spec;
361
362 int warn_alert;
363 int fatal_alert;
364 /* we allow one fatal and one warning alert to be outstanding,
365 * send close alert via the warning alert */
366 int alert_dispatch;
367 unsigned char send_alert[2];
368
369 /* This flag is set when we should renegotiate ASAP, basically when
370 * there is no more data in the read or write buffers */
371 int renegotiate;
372 int total_renegotiations;
373 int num_renegotiations;
374
375 int in_read_app_data;
376
377 struct {
378 /* actually only needs to be 16+20 */
379 unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];
380
381 /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
382 unsigned char finish_md[EVP_MAX_MD_SIZE*2];
383 int finish_md_len;
384 unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2];
385 int peer_finish_md_len;
386
387 unsigned long message_size;
388 int message_type;
389
390 /* used to hold the new cipher we are going to use */
391 SSL_CIPHER *new_cipher;
392#ifndef OPENSSL_NO_DH
393 DH *dh;
394#endif
395 /* used when SSL_ST_FLUSH_DATA is entered */
396 int next_state;
397
398 int reuse_message;
399
400 /* used for certificate requests */
401 int cert_req;
402 int ctype_num;
403 char ctype[SSL3_CT_NUMBER];
404 STACK_OF(X509_NAME) *ca_names;
405
406 int use_rsa_tmp;
407
408 int key_block_length;
409 unsigned char *key_block;
410
411 const EVP_CIPHER *new_sym_enc;
412 const EVP_MD *new_hash;
413#ifndef OPENSSL_NO_COMP
414 const SSL_COMP *new_compression;
415#else
416 char *new_compression;
417#endif
418 int cert_request;
419 } tmp;
420
421 } SSL3_STATE;
422
423/* SSLv3 */
424/*client */
425/* extra state */
426#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
427/* write to server */
428#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
429#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
430/* read from server */
431#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
432#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
433#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
434#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
435#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
436#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
437#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
438#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
439#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
440#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
441/* write to server */
442#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
443#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
444#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
445#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
446#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
447#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
448#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
449#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
450#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
451#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
452#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
453#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
454/* read from server */
455#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
456#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
457#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
458#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
459
460/* server */
461/* extra state */
462#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
463/* read from client */
464/* Do not change the number values, they do matter */
465#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
466#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
467#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
468/* write to client */
469#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
470#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
471#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
472#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
473#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
474#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
475#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
476#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
477#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
478#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
479#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
480#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
481#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
482/* read from client */
483#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
484#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
485#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
486#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
487#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
488#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
489#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
490#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
491#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
492#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
493/* write to client */
494#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
495#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
496#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
497#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
498
499#define SSL3_MT_HELLO_REQUEST 0
500#define SSL3_MT_CLIENT_HELLO 1
501#define SSL3_MT_SERVER_HELLO 2
502#define SSL3_MT_CERTIFICATE 11
503#define SSL3_MT_SERVER_KEY_EXCHANGE 12
504#define SSL3_MT_CERTIFICATE_REQUEST 13
505#define SSL3_MT_SERVER_DONE 14
506#define SSL3_MT_CERTIFICATE_VERIFY 15
507#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
508#define SSL3_MT_FINISHED 20
509
510#define SSL3_MT_CCS 1
511
512/* These are used when changing over to a new cipher */
513#define SSL3_CC_READ 0x01
514#define SSL3_CC_WRITE 0x02
515#define SSL3_CC_CLIENT 0x10
516#define SSL3_CC_SERVER 0x20
517#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
518#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
519#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
520#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
521
522#ifdef __cplusplus
523}
524#endif
525#endif
526
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c
deleted file mode 100644
index 3d1299ee7b..0000000000
--- a/src/lib/libssl/ssl_algs.c
+++ /dev/null
@@ -1,111 +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
67#ifndef OPENSSL_NO_DES
68 EVP_add_cipher(EVP_des_cbc());
69 EVP_add_cipher(EVP_des_ede3_cbc());
70#endif
71#ifndef OPENSSL_NO_IDEA
72 EVP_add_cipher(EVP_idea_cbc());
73#endif
74#ifndef OPENSSL_NO_RC4
75 EVP_add_cipher(EVP_rc4());
76#endif
77#ifndef OPENSSL_NO_RC2
78 EVP_add_cipher(EVP_rc2_cbc());
79#endif
80#ifndef OPENSSL_NO_AES
81 EVP_add_cipher(EVP_aes_128_cbc());
82 EVP_add_cipher(EVP_aes_192_cbc());
83 EVP_add_cipher(EVP_aes_256_cbc());
84#endif
85#ifndef OPENSSL_NO_MD2
86 EVP_add_digest(EVP_md2());
87#endif
88#ifndef OPENSSL_NO_MD5
89 EVP_add_digest(EVP_md5());
90 EVP_add_digest_alias(SN_md5,"ssl2-md5");
91 EVP_add_digest_alias(SN_md5,"ssl3-md5");
92#endif
93#ifndef OPENSSL_NO_SHA
94 EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
95 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
96 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
97#endif
98#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_DSA)
99 EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
100 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
101 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
102 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
103#endif
104 /* If you want support for phased out ciphers, add the following */
105#if 0
106 EVP_add_digest(EVP_sha());
107 EVP_add_digest(EVP_dss());
108#endif
109 return(1);
110 }
111
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
deleted file mode 100644
index fc5fcce108..0000000000
--- a/src/lib/libssl/ssl_asn1.c
+++ /dev/null
@@ -1,398 +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 "ssl_locl.h"
62#include <openssl/asn1_mac.h>
63#include <openssl/objects.h>
64#include <openssl/x509.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#ifndef OPENSSL_NO_KRB5
76 ASN1_OCTET_STRING krb5_princ;
77#endif /* OPENSSL_NO_KRB5 */
78 ASN1_INTEGER time;
79 ASN1_INTEGER timeout;
80 ASN1_INTEGER verify_result;
81 } SSL_SESSION_ASN1;
82
83int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
84 {
85#define LSIZE2 (sizeof(long)*2)
86 int v1=0,v2=0,v3=0,v4=0,v5=0;
87 unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2];
88 unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2];
89 long l;
90 SSL_SESSION_ASN1 a;
91 M_ASN1_I2D_vars(in);
92
93 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
94 return(0);
95
96 /* Note that I cheat in the following 2 assignments. I know
97 * that if the ASN1_INTEGER passed to ASN1_INTEGER_set
98 * is > sizeof(long)+1, the buffer will not be re-OPENSSL_malloc()ed.
99 * This is a bit evil but makes things simple, no dynamic allocation
100 * to clean up :-) */
101 a.version.length=LSIZE2;
102 a.version.type=V_ASN1_INTEGER;
103 a.version.data=ibuf1;
104 ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION);
105
106 a.ssl_version.length=LSIZE2;
107 a.ssl_version.type=V_ASN1_INTEGER;
108 a.ssl_version.data=ibuf2;
109 ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version);
110
111 a.cipher.type=V_ASN1_OCTET_STRING;
112 a.cipher.data=buf;
113
114 if (in->cipher == NULL)
115 l=in->cipher_id;
116 else
117 l=in->cipher->id;
118 if (in->ssl_version == SSL2_VERSION)
119 {
120 a.cipher.length=3;
121 buf[0]=((unsigned char)(l>>16L))&0xff;
122 buf[1]=((unsigned char)(l>> 8L))&0xff;
123 buf[2]=((unsigned char)(l ))&0xff;
124 }
125 else
126 {
127 a.cipher.length=2;
128 buf[0]=((unsigned char)(l>>8L))&0xff;
129 buf[1]=((unsigned char)(l ))&0xff;
130 }
131
132 a.master_key.length=in->master_key_length;
133 a.master_key.type=V_ASN1_OCTET_STRING;
134 a.master_key.data=in->master_key;
135
136 a.session_id.length=in->session_id_length;
137 a.session_id.type=V_ASN1_OCTET_STRING;
138 a.session_id.data=in->session_id;
139
140 a.session_id_context.length=in->sid_ctx_length;
141 a.session_id_context.type=V_ASN1_OCTET_STRING;
142 a.session_id_context.data=in->sid_ctx;
143
144 a.key_arg.length=in->key_arg_length;
145 a.key_arg.type=V_ASN1_OCTET_STRING;
146 a.key_arg.data=in->key_arg;
147
148#ifndef OPENSSL_NO_KRB5
149 if (in->krb5_client_princ_len)
150 {
151 a.krb5_princ.length=in->krb5_client_princ_len;
152 a.krb5_princ.type=V_ASN1_OCTET_STRING;
153 a.krb5_princ.data=in->krb5_client_princ;
154 }
155#endif /* OPENSSL_NO_KRB5 */
156
157 if (in->time != 0L)
158 {
159 a.time.length=LSIZE2;
160 a.time.type=V_ASN1_INTEGER;
161 a.time.data=ibuf3;
162 ASN1_INTEGER_set(&(a.time),in->time);
163 }
164
165 if (in->timeout != 0L)
166 {
167 a.timeout.length=LSIZE2;
168 a.timeout.type=V_ASN1_INTEGER;
169 a.timeout.data=ibuf4;
170 ASN1_INTEGER_set(&(a.timeout),in->timeout);
171 }
172
173 if (in->verify_result != X509_V_OK)
174 {
175 a.verify_result.length=LSIZE2;
176 a.verify_result.type=V_ASN1_INTEGER;
177 a.verify_result.data=ibuf5;
178 ASN1_INTEGER_set(&a.verify_result,in->verify_result);
179 }
180
181
182 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
183 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
184 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
185 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
186 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
187#ifndef OPENSSL_NO_KRB5
188 if (in->krb5_client_princ_len)
189 M_ASN1_I2D_len(&(a.krb5_princ), i2d_ASN1_OCTET_STRING);
190#endif /* OPENSSL_NO_KRB5 */
191 if (in->key_arg_length > 0)
192 M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING);
193 if (in->time != 0L)
194 M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
195 if (in->timeout != 0L)
196 M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
197 if (in->peer != NULL)
198 M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3);
199 M_ASN1_I2D_len_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,v4);
200 if (in->verify_result != X509_V_OK)
201 M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5);
202
203 M_ASN1_I2D_seq_total();
204
205 M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
206 M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
207 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
208 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
209 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
210#ifndef OPENSSL_NO_KRB5
211 if (in->krb5_client_princ_len)
212 M_ASN1_I2D_put(&(a.krb5_princ), i2d_ASN1_OCTET_STRING);
213#endif /* OPENSSL_NO_KRB5 */
214 if (in->key_arg_length > 0)
215 M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0);
216 if (in->time != 0L)
217 M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
218 if (in->timeout != 0L)
219 M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
220 if (in->peer != NULL)
221 M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3);
222 M_ASN1_I2D_put_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,
223 v4);
224 if (in->verify_result != X509_V_OK)
225 M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5);
226 M_ASN1_I2D_finish();
227 }
228
229SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char * const *pp,
230 long length)
231 {
232 int version,ssl_version=0,i;
233 long id;
234 ASN1_INTEGER ai,*aip;
235 ASN1_OCTET_STRING os,*osp;
236 M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new);
237
238 aip= &ai;
239 osp= &os;
240
241 M_ASN1_D2I_Init();
242 M_ASN1_D2I_start_sequence();
243
244 ai.data=NULL; ai.length=0;
245 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
246 version=(int)ASN1_INTEGER_get(aip);
247 if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; }
248
249 /* we don't care about the version right now :-) */
250 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
251 ssl_version=(int)ASN1_INTEGER_get(aip);
252 ret->ssl_version=ssl_version;
253 if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; }
254
255 os.data=NULL; os.length=0;
256 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
257 if (ssl_version == SSL2_VERSION)
258 {
259 if (os.length != 3)
260 {
261 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
262 goto err;
263 }
264 id=0x02000000L|
265 ((unsigned long)os.data[0]<<16L)|
266 ((unsigned long)os.data[1]<< 8L)|
267 (unsigned long)os.data[2];
268 }
269 else if ((ssl_version>>8) == SSL3_VERSION_MAJOR)
270 {
271 if (os.length != 2)
272 {
273 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
274 goto err;
275 }
276 id=0x03000000L|
277 ((unsigned long)os.data[0]<<8L)|
278 (unsigned long)os.data[1];
279 }
280 else
281 {
282 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION);
283 return(NULL);
284 }
285
286 ret->cipher=NULL;
287 ret->cipher_id=id;
288
289 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
290 if ((ssl_version>>8) == SSL3_VERSION_MAJOR)
291 i=SSL3_MAX_SSL_SESSION_ID_LENGTH;
292 else /* if (ssl_version == SSL2_VERSION_MAJOR) */
293 i=SSL2_MAX_SSL_SESSION_ID_LENGTH;
294
295 if (os.length > i)
296 os.length = i;
297 if (os.length > sizeof ret->session_id) /* can't happen */
298 os.length = sizeof ret->session_id;
299
300 ret->session_id_length=os.length;
301 OPENSSL_assert(os.length <= sizeof ret->session_id);
302 memcpy(ret->session_id,os.data,os.length);
303
304 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
305 if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH)
306 ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
307 else
308 ret->master_key_length=os.length;
309 memcpy(ret->master_key,os.data,ret->master_key_length);
310
311 os.length=0;
312
313#ifndef OPENSSL_NO_KRB5
314 os.length=0;
315 M_ASN1_D2I_get_opt(osp,d2i_ASN1_OCTET_STRING,V_ASN1_OCTET_STRING);
316 if (os.data)
317 {
318 if (os.length > SSL_MAX_KRB5_PRINCIPAL_LENGTH)
319 ret->krb5_client_princ_len=0;
320 else
321 ret->krb5_client_princ_len=os.length;
322 memcpy(ret->krb5_client_princ,os.data,ret->krb5_client_princ_len);
323 OPENSSL_free(os.data);
324 os.data = NULL;
325 os.length = 0;
326 }
327 else
328 ret->krb5_client_princ_len=0;
329#endif /* OPENSSL_NO_KRB5 */
330
331 M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING);
332 if (os.length > SSL_MAX_KEY_ARG_LENGTH)
333 ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH;
334 else
335 ret->key_arg_length=os.length;
336 memcpy(ret->key_arg,os.data,ret->key_arg_length);
337 if (os.data != NULL) OPENSSL_free(os.data);
338
339 ai.length=0;
340 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1);
341 if (ai.data != NULL)
342 {
343 ret->time=ASN1_INTEGER_get(aip);
344 OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
345 }
346 else
347 ret->time=(unsigned long)time(NULL);
348
349 ai.length=0;
350 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2);
351 if (ai.data != NULL)
352 {
353 ret->timeout=ASN1_INTEGER_get(aip);
354 OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
355 }
356 else
357 ret->timeout=3;
358
359 if (ret->peer != NULL)
360 {
361 X509_free(ret->peer);
362 ret->peer=NULL;
363 }
364 M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3);
365
366 os.length=0;
367 os.data=NULL;
368 M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,4);
369
370 if(os.data != NULL)
371 {
372 if (os.length > SSL_MAX_SID_CTX_LENGTH)
373 {
374 ret->sid_ctx_length=os.length;
375 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH);
376 }
377 else
378 {
379 ret->sid_ctx_length=os.length;
380 memcpy(ret->sid_ctx,os.data,os.length);
381 }
382 OPENSSL_free(os.data); os.data=NULL; os.length=0;
383 }
384 else
385 ret->sid_ctx_length=0;
386
387 ai.length=0;
388 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,5);
389 if (ai.data != NULL)
390 {
391 ret->verify_result=ASN1_INTEGER_get(aip);
392 OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
393 }
394 else
395 ret->verify_result=X509_V_OK;
396
397 M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION);
398 }
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c
deleted file mode 100644
index b779e6bb4d..0000000000
--- a/src/lib/libssl/ssl_cert.c
+++ /dev/null
@@ -1,898 +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 "e_os.h"
110#ifndef NO_SYS_TYPES_H
111# include <sys/types.h>
112#endif
113
114#if !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS) && !defined(NeXT) && !defined(MAC_OS_pre_X)
115#include <dirent.h>
116#endif
117
118#if defined(WIN32)
119#include <windows.h>
120#include <tchar.h>
121#endif
122
123#ifdef NeXT
124#include <sys/dir.h>
125#define dirent direct
126#endif
127
128#include <openssl/objects.h>
129#include <openssl/bio.h>
130#include <openssl/pem.h>
131#include <openssl/x509v3.h>
132#include "ssl_locl.h"
133#include <openssl/fips.h>
134
135int SSL_get_ex_data_X509_STORE_CTX_idx(void)
136 {
137 static volatile int ssl_x509_store_ctx_idx= -1;
138
139 if (ssl_x509_store_ctx_idx < 0)
140 {
141 /* any write lock will do; usually this branch
142 * will only be taken once anyway */
143 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
144
145 if (ssl_x509_store_ctx_idx < 0)
146 {
147 ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index(
148 0,"SSL for verify callback",NULL,NULL,NULL);
149 }
150
151 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
152 }
153 return ssl_x509_store_ctx_idx;
154 }
155
156CERT *ssl_cert_new(void)
157 {
158 CERT *ret;
159
160 ret=(CERT *)OPENSSL_malloc(sizeof(CERT));
161 if (ret == NULL)
162 {
163 SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE);
164 return(NULL);
165 }
166 memset(ret,0,sizeof(CERT));
167
168 ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]);
169 ret->references=1;
170
171 return(ret);
172 }
173
174CERT *ssl_cert_dup(CERT *cert)
175 {
176 CERT *ret;
177 int i;
178
179 ret = (CERT *)OPENSSL_malloc(sizeof(CERT));
180 if (ret == NULL)
181 {
182 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE);
183 return(NULL);
184 }
185
186 memset(ret, 0, sizeof(CERT));
187
188 ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
189 /* or ret->key = ret->pkeys + (cert->key - cert->pkeys),
190 * if you find that more readable */
191
192 ret->valid = cert->valid;
193 ret->mask = cert->mask;
194 ret->export_mask = cert->export_mask;
195
196#ifndef OPENSSL_NO_RSA
197 if (cert->rsa_tmp != NULL)
198 {
199 RSA_up_ref(cert->rsa_tmp);
200 ret->rsa_tmp = cert->rsa_tmp;
201 }
202 ret->rsa_tmp_cb = cert->rsa_tmp_cb;
203#endif
204
205#ifndef OPENSSL_NO_DH
206 if (cert->dh_tmp != NULL)
207 {
208 /* DH parameters don't have a reference count */
209 ret->dh_tmp = DHparams_dup(cert->dh_tmp);
210 if (ret->dh_tmp == NULL)
211 {
212 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_DH_LIB);
213 goto err;
214 }
215 if (cert->dh_tmp->priv_key)
216 {
217 BIGNUM *b = BN_dup(cert->dh_tmp->priv_key);
218 if (!b)
219 {
220 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
221 goto err;
222 }
223 ret->dh_tmp->priv_key = b;
224 }
225 if (cert->dh_tmp->pub_key)
226 {
227 BIGNUM *b = BN_dup(cert->dh_tmp->pub_key);
228 if (!b)
229 {
230 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
231 goto err;
232 }
233 ret->dh_tmp->pub_key = b;
234 }
235 }
236 ret->dh_tmp_cb = cert->dh_tmp_cb;
237#endif
238
239 for (i = 0; i < SSL_PKEY_NUM; i++)
240 {
241 if (cert->pkeys[i].x509 != NULL)
242 {
243 ret->pkeys[i].x509 = cert->pkeys[i].x509;
244 CRYPTO_add(&ret->pkeys[i].x509->references, 1,
245 CRYPTO_LOCK_X509);
246 }
247
248 if (cert->pkeys[i].privatekey != NULL)
249 {
250 ret->pkeys[i].privatekey = cert->pkeys[i].privatekey;
251 CRYPTO_add(&ret->pkeys[i].privatekey->references, 1,
252 CRYPTO_LOCK_EVP_PKEY);
253
254 switch(i)
255 {
256 /* If there was anything special to do for
257 * certain types of keys, we'd do it here.
258 * (Nothing at the moment, I think.) */
259
260 case SSL_PKEY_RSA_ENC:
261 case SSL_PKEY_RSA_SIGN:
262 /* We have an RSA key. */
263 break;
264
265 case SSL_PKEY_DSA_SIGN:
266 /* We have a DSA key. */
267 break;
268
269 case SSL_PKEY_DH_RSA:
270 case SSL_PKEY_DH_DSA:
271 /* We have a DH key. */
272 break;
273
274 default:
275 /* Can't happen. */
276 SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG);
277 }
278 }
279 }
280
281 /* ret->extra_certs *should* exist, but currently the own certificate
282 * chain is held inside SSL_CTX */
283
284 ret->references=1;
285
286 return(ret);
287
288#ifndef OPENSSL_NO_DH /* avoid 'unreferenced label' warning if OPENSSL_NO_DH is defined */
289err:
290#endif
291#ifndef OPENSSL_NO_RSA
292 if (ret->rsa_tmp != NULL)
293 RSA_free(ret->rsa_tmp);
294#endif
295#ifndef OPENSSL_NO_DH
296 if (ret->dh_tmp != NULL)
297 DH_free(ret->dh_tmp);
298#endif
299
300 for (i = 0; i < SSL_PKEY_NUM; i++)
301 {
302 if (ret->pkeys[i].x509 != NULL)
303 X509_free(ret->pkeys[i].x509);
304 if (ret->pkeys[i].privatekey != NULL)
305 EVP_PKEY_free(ret->pkeys[i].privatekey);
306 }
307
308 return NULL;
309 }
310
311
312void ssl_cert_free(CERT *c)
313 {
314 int i;
315
316 if(c == NULL)
317 return;
318
319 i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT);
320#ifdef REF_PRINT
321 REF_PRINT("CERT",c);
322#endif
323 if (i > 0) return;
324#ifdef REF_CHECK
325 if (i < 0)
326 {
327 fprintf(stderr,"ssl_cert_free, bad reference count\n");
328 abort(); /* ok */
329 }
330#endif
331
332#ifndef OPENSSL_NO_RSA
333 if (c->rsa_tmp) RSA_free(c->rsa_tmp);
334#endif
335#ifndef OPENSSL_NO_DH
336 if (c->dh_tmp) DH_free(c->dh_tmp);
337#endif
338
339 for (i=0; i<SSL_PKEY_NUM; i++)
340 {
341 if (c->pkeys[i].x509 != NULL)
342 X509_free(c->pkeys[i].x509);
343 if (c->pkeys[i].privatekey != NULL)
344 EVP_PKEY_free(c->pkeys[i].privatekey);
345#if 0
346 if (c->pkeys[i].publickey != NULL)
347 EVP_PKEY_free(c->pkeys[i].publickey);
348#endif
349 }
350 OPENSSL_free(c);
351 }
352
353int ssl_cert_inst(CERT **o)
354 {
355 /* Create a CERT if there isn't already one
356 * (which cannot really happen, as it is initially created in
357 * SSL_CTX_new; but the earlier code usually allows for that one
358 * being non-existant, so we follow that behaviour, as it might
359 * turn out that there actually is a reason for it -- but I'm
360 * not sure that *all* of the existing code could cope with
361 * s->cert being NULL, otherwise we could do without the
362 * initialization in SSL_CTX_new).
363 */
364
365 if (o == NULL)
366 {
367 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_PASSED_NULL_PARAMETER);
368 return(0);
369 }
370 if (*o == NULL)
371 {
372 if ((*o = ssl_cert_new()) == NULL)
373 {
374 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_MALLOC_FAILURE);
375 return(0);
376 }
377 }
378 return(1);
379 }
380
381
382SESS_CERT *ssl_sess_cert_new(void)
383 {
384 SESS_CERT *ret;
385
386 ret = OPENSSL_malloc(sizeof *ret);
387 if (ret == NULL)
388 {
389 SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE);
390 return NULL;
391 }
392
393 memset(ret, 0 ,sizeof *ret);
394 ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]);
395 ret->references = 1;
396
397 return ret;
398 }
399
400void ssl_sess_cert_free(SESS_CERT *sc)
401 {
402 int i;
403
404 if (sc == NULL)
405 return;
406
407 i = CRYPTO_add(&sc->references, -1, CRYPTO_LOCK_SSL_SESS_CERT);
408#ifdef REF_PRINT
409 REF_PRINT("SESS_CERT", sc);
410#endif
411 if (i > 0)
412 return;
413#ifdef REF_CHECK
414 if (i < 0)
415 {
416 fprintf(stderr,"ssl_sess_cert_free, bad reference count\n");
417 abort(); /* ok */
418 }
419#endif
420
421 /* i == 0 */
422 if (sc->cert_chain != NULL)
423 sk_X509_pop_free(sc->cert_chain, X509_free);
424 for (i = 0; i < SSL_PKEY_NUM; i++)
425 {
426 if (sc->peer_pkeys[i].x509 != NULL)
427 X509_free(sc->peer_pkeys[i].x509);
428#if 0 /* We don't have the peer's private key. These lines are just
429 * here as a reminder that we're still using a not-quite-appropriate
430 * data structure. */
431 if (sc->peer_pkeys[i].privatekey != NULL)
432 EVP_PKEY_free(sc->peer_pkeys[i].privatekey);
433#endif
434 }
435
436#ifndef OPENSSL_NO_RSA
437 if (sc->peer_rsa_tmp != NULL)
438 RSA_free(sc->peer_rsa_tmp);
439#endif
440#ifndef OPENSSL_NO_DH
441 if (sc->peer_dh_tmp != NULL)
442 DH_free(sc->peer_dh_tmp);
443#endif
444
445 OPENSSL_free(sc);
446 }
447
448int ssl_set_peer_cert_type(SESS_CERT *sc,int type)
449 {
450 sc->peer_cert_type = type;
451 return(1);
452 }
453
454int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
455 {
456 X509 *x;
457 int i;
458 X509_STORE_CTX ctx;
459
460 if ((sk == NULL) || (sk_X509_num(sk) == 0))
461 return(0);
462
463 x=sk_X509_value(sk,0);
464 if(!X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk))
465 {
466 SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,ERR_R_X509_LIB);
467 return(0);
468 }
469 if (SSL_get_verify_depth(s) >= 0)
470 X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s));
471 X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s);
472
473 /* We need to set the verify purpose. The purpose can be determined by
474 * the context: if its a server it will verify SSL client certificates
475 * or vice versa.
476 */
477 if (s->server)
478 i = X509_PURPOSE_SSL_CLIENT;
479 else
480 i = X509_PURPOSE_SSL_SERVER;
481
482 X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust);
483
484 if (s->verify_callback)
485 X509_STORE_CTX_set_verify_cb(&ctx, s->verify_callback);
486
487 if (s->ctx->app_verify_callback != NULL)
488#if 1 /* new with OpenSSL 0.9.7 */
489 i=s->ctx->app_verify_callback(&ctx, s->ctx->app_verify_arg);
490#else
491 i=s->ctx->app_verify_callback(&ctx); /* should pass app_verify_arg */
492#endif
493 else
494 {
495#ifndef OPENSSL_NO_X509_VERIFY
496 i=X509_verify_cert(&ctx);
497#else
498 i=0;
499 ctx.error=X509_V_ERR_APPLICATION_VERIFICATION;
500 SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,SSL_R_NO_VERIFY_CALLBACK);
501#endif
502 }
503
504 s->verify_result=ctx.error;
505 X509_STORE_CTX_cleanup(&ctx);
506
507 return(i);
508 }
509
510static void set_client_CA_list(STACK_OF(X509_NAME) **ca_list,STACK_OF(X509_NAME) *name_list)
511 {
512 if (*ca_list != NULL)
513 sk_X509_NAME_pop_free(*ca_list,X509_NAME_free);
514
515 *ca_list=name_list;
516 }
517
518STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk)
519 {
520 int i;
521 STACK_OF(X509_NAME) *ret;
522 X509_NAME *name;
523
524 ret=sk_X509_NAME_new_null();
525 for (i=0; i<sk_X509_NAME_num(sk); i++)
526 {
527 name=X509_NAME_dup(sk_X509_NAME_value(sk,i));
528 if ((name == NULL) || !sk_X509_NAME_push(ret,name))
529 {
530 sk_X509_NAME_pop_free(ret,X509_NAME_free);
531 return(NULL);
532 }
533 }
534 return(ret);
535 }
536
537void SSL_set_client_CA_list(SSL *s,STACK_OF(X509_NAME) *name_list)
538 {
539 set_client_CA_list(&(s->client_CA),name_list);
540 }
541
542void SSL_CTX_set_client_CA_list(SSL_CTX *ctx,STACK_OF(X509_NAME) *name_list)
543 {
544 set_client_CA_list(&(ctx->client_CA),name_list);
545 }
546
547STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx)
548 {
549 return(ctx->client_CA);
550 }
551
552STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s)
553 {
554 if (s->type == SSL_ST_CONNECT)
555 { /* we are in the client */
556 if (((s->version>>8) == SSL3_VERSION_MAJOR) &&
557 (s->s3 != NULL))
558 return(s->s3->tmp.ca_names);
559 else
560 return(NULL);
561 }
562 else
563 {
564 if (s->client_CA != NULL)
565 return(s->client_CA);
566 else
567 return(s->ctx->client_CA);
568 }
569 }
570
571static int add_client_CA(STACK_OF(X509_NAME) **sk,X509 *x)
572 {
573 X509_NAME *name;
574
575 if (x == NULL) return(0);
576 if ((*sk == NULL) && ((*sk=sk_X509_NAME_new_null()) == NULL))
577 return(0);
578
579 if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL)
580 return(0);
581
582 if (!sk_X509_NAME_push(*sk,name))
583 {
584 X509_NAME_free(name);
585 return(0);
586 }
587 return(1);
588 }
589
590int SSL_add_client_CA(SSL *ssl,X509 *x)
591 {
592 return(add_client_CA(&(ssl->client_CA),x));
593 }
594
595int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x)
596 {
597 return(add_client_CA(&(ctx->client_CA),x));
598 }
599
600static int xname_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
601 {
602 return(X509_NAME_cmp(*a,*b));
603 }
604
605#ifndef OPENSSL_NO_STDIO
606/*!
607 * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed;
608 * it doesn't really have anything to do with clients (except that a common use
609 * for a stack of CAs is to send it to the client). Actually, it doesn't have
610 * much to do with CAs, either, since it will load any old cert.
611 * \param file the file containing one or more certs.
612 * \return a ::STACK containing the certs.
613 */
614STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file)
615 {
616 BIO *in;
617 X509 *x=NULL;
618 X509_NAME *xn=NULL;
619 STACK_OF(X509_NAME) *ret = NULL,*sk;
620
621 sk=sk_X509_NAME_new(xname_cmp);
622
623 in=BIO_new(BIO_s_file_internal());
624
625 if ((sk == NULL) || (in == NULL))
626 {
627 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE);
628 goto err;
629 }
630
631 if (!BIO_read_filename(in,file))
632 goto err;
633
634 for (;;)
635 {
636 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
637 break;
638 if (ret == NULL)
639 {
640 ret = sk_X509_NAME_new_null();
641 if (ret == NULL)
642 {
643 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE);
644 goto err;
645 }
646 }
647 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
648 /* check for duplicates */
649 xn=X509_NAME_dup(xn);
650 if (xn == NULL) goto err;
651 if (sk_X509_NAME_find(sk,xn) >= 0)
652 X509_NAME_free(xn);
653 else
654 {
655 sk_X509_NAME_push(sk,xn);
656 sk_X509_NAME_push(ret,xn);
657 }
658 }
659
660 if (0)
661 {
662err:
663 if (ret != NULL) sk_X509_NAME_pop_free(ret,X509_NAME_free);
664 ret=NULL;
665 }
666 if (sk != NULL) sk_X509_NAME_free(sk);
667 if (in != NULL) BIO_free(in);
668 if (x != NULL) X509_free(x);
669 if (ret != NULL)
670 ERR_clear_error();
671 return(ret);
672 }
673#endif
674
675/*!
676 * Add a file of certs to a stack.
677 * \param stack the stack to add to.
678 * \param file the file to add from. All certs in this file that are not
679 * already in the stack will be added.
680 * \return 1 for success, 0 for failure. Note that in the case of failure some
681 * certs may have been added to \c stack.
682 */
683
684int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
685 const char *file)
686 {
687 BIO *in;
688 X509 *x=NULL;
689 X509_NAME *xn=NULL;
690 int ret=1;
691 int (*oldcmp)(const X509_NAME * const *a, const X509_NAME * const *b);
692
693 oldcmp=sk_X509_NAME_set_cmp_func(stack,xname_cmp);
694
695 in=BIO_new(BIO_s_file_internal());
696
697 if (in == NULL)
698 {
699 SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,ERR_R_MALLOC_FAILURE);
700 goto err;
701 }
702
703 if (!BIO_read_filename(in,file))
704 goto err;
705
706 for (;;)
707 {
708 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
709 break;
710 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
711 xn=X509_NAME_dup(xn);
712 if (xn == NULL) goto err;
713 if (sk_X509_NAME_find(stack,xn) >= 0)
714 X509_NAME_free(xn);
715 else
716 sk_X509_NAME_push(stack,xn);
717 }
718
719 if (0)
720 {
721err:
722 ret=0;
723 }
724 if(in != NULL)
725 BIO_free(in);
726 if(x != NULL)
727 X509_free(x);
728
729 sk_X509_NAME_set_cmp_func(stack,oldcmp);
730
731 return ret;
732 }
733
734/*!
735 * Add a directory of certs to a stack.
736 * \param stack the stack to append to.
737 * \param dir the directory to append from. All files in this directory will be
738 * examined as potential certs. Any that are acceptable to
739 * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will be
740 * included.
741 * \return 1 for success, 0 for failure. Note that in the case of failure some
742 * certs may have been added to \c stack.
743 */
744
745#ifndef OPENSSL_SYS_WIN32
746#ifndef OPENSSL_SYS_VMS /* XXXX This may be fixed in the future */
747#ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! */
748
749int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
750 const char *dir)
751 {
752 DIR *d;
753 struct dirent *dstruct;
754 int ret = 0;
755
756 CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
757 d = opendir(dir);
758
759 /* Note that a side effect is that the CAs will be sorted by name */
760 if(!d)
761 {
762 SYSerr(SYS_F_OPENDIR, get_last_sys_error());
763 ERR_add_error_data(3, "opendir('", dir, "')");
764 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
765 goto err;
766 }
767
768 while((dstruct=readdir(d)))
769 {
770 char buf[1024];
771 int r;
772
773 if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
774 {
775 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
776 goto err;
777 }
778
779 r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);
780 if (r <= 0 || r >= sizeof buf)
781 goto err;
782 if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
783 goto err;
784 }
785 ret = 1;
786
787err:
788 if (d) closedir(d);
789 CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
790 return ret;
791 }
792
793#endif
794#endif
795
796#else /* OPENSSL_SYS_WIN32 */
797
798#if defined(_WIN32_WCE)
799# ifndef UNICODE
800# error "WinCE comes in UNICODE flavor only..."
801# endif
802# if _WIN32_WCE<101 && !defined(OPENSSL_NO_MULTIBYTE)
803# define OPENSSL_NO_MULTIBYTE
804# endif
805# ifndef FindFirstFile
806# define FindFirstFile FindFirstFileW
807# endif
808# ifndef FindNextFile
809# define FindNextFile FindNextFileW
810# endif
811#endif
812
813int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
814 const char *dir)
815 {
816 WIN32_FIND_DATA FindFileData;
817 HANDLE hFind;
818 int ret = 0;
819 TCHAR *wdir = NULL;
820 size_t i,len_0 = strlen(dir)+1; /* len_0 accounts for trailing 0 */
821 char buf[1024],*slash;
822
823 if (len_0 > (sizeof(buf)-14)) /* 14 is just some value... */
824 {
825 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
826 return ret;
827 }
828
829 CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
830
831 if (sizeof(TCHAR) != sizeof(char))
832 {
833 wdir = (TCHAR *)malloc(len_0*sizeof(TCHAR));
834 if (wdir == NULL)
835 goto err_noclose;
836#ifndef OPENSSL_NO_MULTIBYTE
837 if (!MultiByteToWideChar(CP_ACP,0,dir,len_0,
838 (WCHAR *)wdir,len_0))
839#endif
840 for (i=0;i<len_0;i++) wdir[i]=(TCHAR)dir[i];
841
842 hFind = FindFirstFile(wdir, &FindFileData);
843 }
844 else hFind = FindFirstFile((const TCHAR *)dir, &FindFileData);
845
846 /* Note that a side effect is that the CAs will be sorted by name */
847 if(hFind == INVALID_HANDLE_VALUE)
848 {
849 SYSerr(SYS_F_OPENDIR, get_last_sys_error());
850 ERR_add_error_data(3, "opendir('", dir, "')");
851 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
852 goto err_noclose;
853 }
854
855 strncpy(buf,dir,sizeof(buf)); /* strcpy is safe too... */
856 buf[len_0-1]='/'; /* no trailing zero! */
857 slash=buf+len_0;
858
859 do {
860 const TCHAR *fnam=FindFileData.cFileName;
861 size_t flen_0=_tcslen(fnam)+1;
862
863 if (flen_0 > (sizeof(buf)-len_0))
864 {
865 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
866 goto err;
867 }
868 /* else strcpy would be safe too... */
869
870 if (sizeof(TCHAR) != sizeof(char))
871 {
872#ifndef OPENSSL_NO_MULTIBYTE
873 if (!WideCharToMultiByte(CP_ACP,0,
874 (WCHAR *)fnam,flen_0,
875 slash,sizeof(buf)-len_0,
876 NULL,0))
877#endif
878 for (i=0;i<flen_0;i++) slash[i]=(char)fnam[i];
879 }
880 else strncpy(slash,(const char *)fnam,sizeof(buf)-len_0);
881
882 if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
883 goto err;
884 }
885 while (FindNextFile(hFind, &FindFileData) != FALSE);
886 ret = 1;
887
888err:
889 FindClose(hFind);
890err_noclose:
891 if (wdir != NULL)
892 free(wdir);
893
894 CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
895 return ret;
896 }
897
898#endif
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
deleted file mode 100644
index f622180c69..0000000000
--- a/src/lib/libssl/ssl_ciph.c
+++ /dev/null
@@ -1,1139 +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 <openssl/fips.h>
63#include "ssl_locl.h"
64
65#define SSL_ENC_DES_IDX 0
66#define SSL_ENC_3DES_IDX 1
67#define SSL_ENC_RC4_IDX 2
68#define SSL_ENC_RC2_IDX 3
69#define SSL_ENC_IDEA_IDX 4
70#define SSL_ENC_eFZA_IDX 5
71#define SSL_ENC_NULL_IDX 6
72#define SSL_ENC_AES128_IDX 7
73#define SSL_ENC_AES256_IDX 8
74#define SSL_ENC_NUM_IDX 9
75
76static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
77 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
78 };
79
80static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL;
81
82#define SSL_MD_MD5_IDX 0
83#define SSL_MD_SHA1_IDX 1
84#define SSL_MD_NUM_IDX 2
85static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
86 NULL,NULL,
87 };
88
89#define CIPHER_ADD 1
90#define CIPHER_KILL 2
91#define CIPHER_DEL 3
92#define CIPHER_ORD 4
93#define CIPHER_SPECIAL 5
94
95typedef struct cipher_order_st
96 {
97 SSL_CIPHER *cipher;
98 int active;
99 int dead;
100 struct cipher_order_st *next,*prev;
101 } CIPHER_ORDER;
102
103static const SSL_CIPHER cipher_aliases[]={
104 /* Don't include eNULL unless specifically enabled. */
105 {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */
106 {0,SSL_TXT_CMPALL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, /* COMPLEMENT OF ALL */
107 {0,SSL_TXT_CMPDEF,0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK,0},
108 {0,SSL_TXT_kKRB5,0,SSL_kKRB5,0,0,0,0,SSL_MKEY_MASK,0}, /* VRS Kerberos5 */
109 {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0},
110 {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0},
111 {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0},
112 {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0},
113 {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0},
114 {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0},
115 {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0},
116
117 {0,SSL_TXT_aKRB5,0,SSL_aKRB5,0,0,0,0,SSL_AUTH_MASK,0}, /* VRS Kerberos5 */
118 {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0},
119 {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0},
120 {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,0,0,0,SSL_AUTH_MASK,0},
121 {0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0},
122 {0,SSL_TXT_aDH, 0,SSL_aDH, 0,0,0,0,SSL_AUTH_MASK,0},
123 {0,SSL_TXT_DSS, 0,SSL_DSS, 0,0,0,0,SSL_AUTH_MASK,0},
124
125 {0,SSL_TXT_DES, 0,SSL_DES, 0,0,0,0,SSL_ENC_MASK,0},
126 {0,SSL_TXT_3DES,0,SSL_3DES, 0,0,0,0,SSL_ENC_MASK,0},
127 {0,SSL_TXT_RC4, 0,SSL_RC4, 0,0,0,0,SSL_ENC_MASK,0},
128 {0,SSL_TXT_RC2, 0,SSL_RC2, 0,0,0,0,SSL_ENC_MASK,0},
129#ifndef OPENSSL_NO_IDEA
130 {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0},
131#endif
132 {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0},
133 {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0},
134 {0,SSL_TXT_AES, 0,SSL_AES, 0,0,0,0,SSL_ENC_MASK,0},
135
136 {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0},
137 {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0},
138 {0,SSL_TXT_SHA, 0,SSL_SHA, 0,0,0,0,SSL_MAC_MASK,0},
139
140 {0,SSL_TXT_NULL,0,SSL_NULL, 0,0,0,0,SSL_ENC_MASK,0},
141 {0,SSL_TXT_KRB5,0,SSL_KRB5, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
142 {0,SSL_TXT_RSA, 0,SSL_RSA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
143 {0,SSL_TXT_ADH, 0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
144 {0,SSL_TXT_FZA, 0,SSL_FZA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0},
145
146 {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0},
147 {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0},
148 {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0},
149
150 {0,SSL_TXT_EXP ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
151 {0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
152 {0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK},
153 {0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK},
154 {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK},
155 {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK},
156 {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK},
157 {0,SSL_TXT_FIPS, 0, 0, SSL_FIPS, 0,0,0,0,SSL_FIPS|SSL_STRONG_NONE},
158 };
159
160static int init_ciphers=1;
161
162static void load_ciphers(void)
163 {
164 ssl_cipher_methods[SSL_ENC_DES_IDX]=
165 EVP_get_cipherbyname(SN_des_cbc);
166 ssl_cipher_methods[SSL_ENC_3DES_IDX]=
167 EVP_get_cipherbyname(SN_des_ede3_cbc);
168 ssl_cipher_methods[SSL_ENC_RC4_IDX]=
169 EVP_get_cipherbyname(SN_rc4);
170 ssl_cipher_methods[SSL_ENC_RC2_IDX]=
171 EVP_get_cipherbyname(SN_rc2_cbc);
172#ifndef OPENSSL_NO_IDEA
173 ssl_cipher_methods[SSL_ENC_IDEA_IDX]=
174 EVP_get_cipherbyname(SN_idea_cbc);
175#else
176 ssl_cipher_methods[SSL_ENC_IDEA_IDX]= NULL;
177#endif
178 ssl_cipher_methods[SSL_ENC_AES128_IDX]=
179 EVP_get_cipherbyname(SN_aes_128_cbc);
180 ssl_cipher_methods[SSL_ENC_AES256_IDX]=
181 EVP_get_cipherbyname(SN_aes_256_cbc);
182
183 ssl_digest_methods[SSL_MD_MD5_IDX]=
184 EVP_get_digestbyname(SN_md5);
185 ssl_digest_methods[SSL_MD_SHA1_IDX]=
186 EVP_get_digestbyname(SN_sha1);
187 init_ciphers=0;
188 }
189
190int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
191 const EVP_MD **md, SSL_COMP **comp)
192 {
193 int i;
194 SSL_CIPHER *c;
195
196 c=s->cipher;
197 if (c == NULL) return(0);
198 if (comp != NULL)
199 {
200 SSL_COMP ctmp;
201
202 if (s->compress_meth == 0)
203 *comp=NULL;
204 else if (ssl_comp_methods == NULL)
205 {
206 /* bad */
207 *comp=NULL;
208 }
209 else
210 {
211
212 ctmp.id=s->compress_meth;
213 i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
214 if (i >= 0)
215 *comp=sk_SSL_COMP_value(ssl_comp_methods,i);
216 else
217 *comp=NULL;
218 }
219 }
220
221 if ((enc == NULL) || (md == NULL)) return(0);
222
223 switch (c->algorithms & SSL_ENC_MASK)
224 {
225 case SSL_DES:
226 i=SSL_ENC_DES_IDX;
227 break;
228 case SSL_3DES:
229 i=SSL_ENC_3DES_IDX;
230 break;
231 case SSL_RC4:
232 i=SSL_ENC_RC4_IDX;
233 break;
234 case SSL_RC2:
235 i=SSL_ENC_RC2_IDX;
236 break;
237 case SSL_IDEA:
238 i=SSL_ENC_IDEA_IDX;
239 break;
240 case SSL_eNULL:
241 i=SSL_ENC_NULL_IDX;
242 break;
243 case SSL_AES:
244 switch(c->alg_bits)
245 {
246 case 128: i=SSL_ENC_AES128_IDX; break;
247 case 256: i=SSL_ENC_AES256_IDX; break;
248 default: i=-1; break;
249 }
250 break;
251 default:
252 i= -1;
253 break;
254 }
255
256 if ((i < 0) || (i >= SSL_ENC_NUM_IDX))
257 *enc=NULL;
258 else
259 {
260 if (i == SSL_ENC_NULL_IDX)
261 *enc=EVP_enc_null();
262 else
263 *enc=ssl_cipher_methods[i];
264 }
265
266 switch (c->algorithms & SSL_MAC_MASK)
267 {
268 case SSL_MD5:
269 i=SSL_MD_MD5_IDX;
270 break;
271 case SSL_SHA1:
272 i=SSL_MD_SHA1_IDX;
273 break;
274 default:
275 i= -1;
276 break;
277 }
278 if ((i < 0) || (i >= SSL_MD_NUM_IDX))
279 *md=NULL;
280 else
281 *md=ssl_digest_methods[i];
282
283 if ((*enc != NULL) && (*md != NULL))
284 return(1);
285 else
286 return(0);
287 }
288
289#define ITEM_SEP(a) \
290 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
291
292static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
293 CIPHER_ORDER **tail)
294 {
295 if (curr == *tail) return;
296 if (curr == *head)
297 *head=curr->next;
298 if (curr->prev != NULL)
299 curr->prev->next=curr->next;
300 if (curr->next != NULL) /* should always be true */
301 curr->next->prev=curr->prev;
302 (*tail)->next=curr;
303 curr->prev= *tail;
304 curr->next=NULL;
305 *tail=curr;
306 }
307
308static unsigned long ssl_cipher_get_disabled(void)
309 {
310 unsigned long mask;
311
312 mask = SSL_kFZA;
313#ifdef OPENSSL_NO_RSA
314 mask |= SSL_aRSA|SSL_kRSA;
315#endif
316#ifdef OPENSSL_NO_DSA
317 mask |= SSL_aDSS;
318#endif
319#ifdef OPENSSL_NO_DH
320 mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
321#endif
322#ifdef OPENSSL_NO_KRB5
323 mask |= SSL_kKRB5|SSL_aKRB5;
324#endif
325
326#ifdef SSL_FORBID_ENULL
327 mask |= SSL_eNULL;
328#endif
329
330 mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0;
331 mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0;
332 mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0;
333 mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0;
334 mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0;
335 mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0;
336 mask |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES:0;
337
338 mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0;
339 mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0;
340
341 return(mask);
342 }
343
344static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
345 int num_of_ciphers, unsigned long mask, CIPHER_ORDER *co_list,
346 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
347 {
348 int i, co_list_num;
349 SSL_CIPHER *c;
350
351 /*
352 * We have num_of_ciphers descriptions compiled in, depending on the
353 * method selected (SSLv2 and/or SSLv3, TLSv1 etc).
354 * These will later be sorted in a linked list with at most num
355 * entries.
356 */
357
358 /* Get the initial list of ciphers */
359 co_list_num = 0; /* actual count of ciphers */
360 for (i = 0; i < num_of_ciphers; i++)
361 {
362 c = ssl_method->get_cipher(i);
363 /* drop those that use any of that is not available */
364#ifdef OPENSSL_FIPS
365 if ((c != NULL) && c->valid && !(c->algorithms & mask)
366 && (!FIPS_mode() || (c->algo_strength & SSL_FIPS)))
367#else
368 if ((c != NULL) && c->valid && !(c->algorithms & mask))
369#endif
370 {
371 co_list[co_list_num].cipher = c;
372 co_list[co_list_num].next = NULL;
373 co_list[co_list_num].prev = NULL;
374 co_list[co_list_num].active = 0;
375 co_list_num++;
376#ifdef KSSL_DEBUG
377 printf("\t%d: %s %lx %lx\n",i,c->name,c->id,c->algorithms);
378#endif /* KSSL_DEBUG */
379 /*
380 if (!sk_push(ca_list,(char *)c)) goto err;
381 */
382 }
383 }
384
385 /*
386 * Prepare linked list from list entries
387 */
388 for (i = 1; i < co_list_num - 1; i++)
389 {
390 co_list[i].prev = &(co_list[i-1]);
391 co_list[i].next = &(co_list[i+1]);
392 }
393 if (co_list_num > 0)
394 {
395 (*head_p) = &(co_list[0]);
396 (*head_p)->prev = NULL;
397 (*head_p)->next = &(co_list[1]);
398 (*tail_p) = &(co_list[co_list_num - 1]);
399 (*tail_p)->prev = &(co_list[co_list_num - 2]);
400 (*tail_p)->next = NULL;
401 }
402 }
403
404static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list,
405 int num_of_group_aliases, unsigned long mask,
406 CIPHER_ORDER *head)
407 {
408 CIPHER_ORDER *ciph_curr;
409 SSL_CIPHER **ca_curr;
410 int i;
411
412 /*
413 * First, add the real ciphers as already collected
414 */
415 ciph_curr = head;
416 ca_curr = ca_list;
417 while (ciph_curr != NULL)
418 {
419 *ca_curr = ciph_curr->cipher;
420 ca_curr++;
421 ciph_curr = ciph_curr->next;
422 }
423
424 /*
425 * Now we add the available ones from the cipher_aliases[] table.
426 * They represent either an algorithm, that must be fully
427 * supported (not match any bit in mask) or represent a cipher
428 * strength value (will be added in any case because algorithms=0).
429 */
430 for (i = 0; i < num_of_group_aliases; i++)
431 {
432 if ((i == 0) || /* always fetch "ALL" */
433 !(cipher_aliases[i].algorithms & mask))
434 {
435 *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
436 ca_curr++;
437 }
438 }
439
440 *ca_curr = NULL; /* end of list */
441 }
442
443static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask,
444 unsigned long algo_strength, unsigned long mask_strength,
445 int rule, int strength_bits, CIPHER_ORDER *co_list,
446 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
447 {
448 CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2;
449 SSL_CIPHER *cp;
450 unsigned long ma, ma_s;
451
452#ifdef CIPHER_DEBUG
453 printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n",
454 rule, algorithms, mask, algo_strength, mask_strength,
455 strength_bits);
456#endif
457
458 curr = head = *head_p;
459 curr2 = head;
460 tail2 = tail = *tail_p;
461 for (;;)
462 {
463 if ((curr == NULL) || (curr == tail2)) break;
464 curr = curr2;
465 curr2 = curr->next;
466
467 cp = curr->cipher;
468
469 /*
470 * Selection criteria is either the number of strength_bits
471 * or the algorithm used.
472 */
473 if (strength_bits == -1)
474 {
475 ma = mask & cp->algorithms;
476 ma_s = mask_strength & cp->algo_strength;
477
478#ifdef CIPHER_DEBUG
479 printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength);
480 printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength);
481#endif
482 /*
483 * Select: if none of the mask bit was met from the
484 * cipher or not all of the bits were met, the
485 * selection does not apply.
486 */
487 if (((ma == 0) && (ma_s == 0)) ||
488 ((ma & algorithms) != ma) ||
489 ((ma_s & algo_strength) != ma_s))
490 continue; /* does not apply */
491 }
492 else if (strength_bits != cp->strength_bits)
493 continue; /* does not apply */
494
495#ifdef CIPHER_DEBUG
496 printf("Action = %d\n", rule);
497#endif
498
499 /* add the cipher if it has not been added yet. */
500 if (rule == CIPHER_ADD)
501 {
502 if (!curr->active)
503 {
504 ll_append_tail(&head, curr, &tail);
505 curr->active = 1;
506 }
507 }
508 /* Move the added cipher to this location */
509 else if (rule == CIPHER_ORD)
510 {
511 if (curr->active)
512 {
513 ll_append_tail(&head, curr, &tail);
514 }
515 }
516 else if (rule == CIPHER_DEL)
517 curr->active = 0;
518 else if (rule == CIPHER_KILL)
519 {
520 if (head == curr)
521 head = curr->next;
522 else
523 curr->prev->next = curr->next;
524 if (tail == curr)
525 tail = curr->prev;
526 curr->active = 0;
527 if (curr->next != NULL)
528 curr->next->prev = curr->prev;
529 if (curr->prev != NULL)
530 curr->prev->next = curr->next;
531 curr->next = NULL;
532 curr->prev = NULL;
533 }
534 }
535
536 *head_p = head;
537 *tail_p = tail;
538 }
539
540static int ssl_cipher_strength_sort(CIPHER_ORDER *co_list,
541 CIPHER_ORDER **head_p,
542 CIPHER_ORDER **tail_p)
543 {
544 int max_strength_bits, i, *number_uses;
545 CIPHER_ORDER *curr;
546
547 /*
548 * This routine sorts the ciphers with descending strength. The sorting
549 * must keep the pre-sorted sequence, so we apply the normal sorting
550 * routine as '+' movement to the end of the list.
551 */
552 max_strength_bits = 0;
553 curr = *head_p;
554 while (curr != NULL)
555 {
556 if (curr->active &&
557 (curr->cipher->strength_bits > max_strength_bits))
558 max_strength_bits = curr->cipher->strength_bits;
559 curr = curr->next;
560 }
561
562 number_uses = OPENSSL_malloc((max_strength_bits + 1) * sizeof(int));
563 if (!number_uses)
564 {
565 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE);
566 return(0);
567 }
568 memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
569
570 /*
571 * Now find the strength_bits values actually used
572 */
573 curr = *head_p;
574 while (curr != NULL)
575 {
576 if (curr->active)
577 number_uses[curr->cipher->strength_bits]++;
578 curr = curr->next;
579 }
580 /*
581 * Go through the list of used strength_bits values in descending
582 * order.
583 */
584 for (i = max_strength_bits; i >= 0; i--)
585 if (number_uses[i] > 0)
586 ssl_cipher_apply_rule(0, 0, 0, 0, CIPHER_ORD, i,
587 co_list, head_p, tail_p);
588
589 OPENSSL_free(number_uses);
590 return(1);
591 }
592
593static int ssl_cipher_process_rulestr(const char *rule_str,
594 CIPHER_ORDER *co_list, CIPHER_ORDER **head_p,
595 CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)
596 {
597 unsigned long algorithms, mask, algo_strength, mask_strength;
598 const char *l, *start, *buf;
599 int j, multi, found, rule, retval, ok, buflen;
600 char ch;
601
602 retval = 1;
603 l = rule_str;
604 for (;;)
605 {
606 ch = *l;
607
608 if (ch == '\0')
609 break; /* done */
610 if (ch == '-')
611 { rule = CIPHER_DEL; l++; }
612 else if (ch == '+')
613 { rule = CIPHER_ORD; l++; }
614 else if (ch == '!')
615 { rule = CIPHER_KILL; l++; }
616 else if (ch == '@')
617 { rule = CIPHER_SPECIAL; l++; }
618 else
619 { rule = CIPHER_ADD; }
620
621 if (ITEM_SEP(ch))
622 {
623 l++;
624 continue;
625 }
626
627 algorithms = mask = algo_strength = mask_strength = 0;
628
629 start=l;
630 for (;;)
631 {
632 ch = *l;
633 buf = l;
634 buflen = 0;
635#ifndef CHARSET_EBCDIC
636 while ( ((ch >= 'A') && (ch <= 'Z')) ||
637 ((ch >= '0') && (ch <= '9')) ||
638 ((ch >= 'a') && (ch <= 'z')) ||
639 (ch == '-'))
640#else
641 while ( isalnum(ch) || (ch == '-'))
642#endif
643 {
644 ch = *(++l);
645 buflen++;
646 }
647
648 if (buflen == 0)
649 {
650 /*
651 * We hit something we cannot deal with,
652 * it is no command or separator nor
653 * alphanumeric, so we call this an error.
654 */
655 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
656 SSL_R_INVALID_COMMAND);
657 retval = found = 0;
658 l++;
659 break;
660 }
661
662 if (rule == CIPHER_SPECIAL)
663 {
664 found = 0; /* unused -- avoid compiler warning */
665 break; /* special treatment */
666 }
667
668 /* check for multi-part specification */
669 if (ch == '+')
670 {
671 multi=1;
672 l++;
673 }
674 else
675 multi=0;
676
677 /*
678 * Now search for the cipher alias in the ca_list. Be careful
679 * with the strncmp, because the "buflen" limitation
680 * will make the rule "ADH:SOME" and the cipher
681 * "ADH-MY-CIPHER" look like a match for buflen=3.
682 * So additionally check whether the cipher name found
683 * has the correct length. We can save a strlen() call:
684 * just checking for the '\0' at the right place is
685 * sufficient, we have to strncmp() anyway. (We cannot
686 * use strcmp(), because buf is not '\0' terminated.)
687 */
688 j = found = 0;
689 while (ca_list[j])
690 {
691 if (!strncmp(buf, ca_list[j]->name, buflen) &&
692 (ca_list[j]->name[buflen] == '\0'))
693 {
694 found = 1;
695 break;
696 }
697 else
698 j++;
699 }
700 if (!found)
701 break; /* ignore this entry */
702
703 /* New algorithms:
704 * 1 - any old restrictions apply outside new mask
705 * 2 - any new restrictions apply outside old mask
706 * 3 - enforce old & new where masks intersect
707 */
708 algorithms = (algorithms & ~ca_list[j]->mask) | /* 1 */
709 (ca_list[j]->algorithms & ~mask) | /* 2 */
710 (algorithms & ca_list[j]->algorithms); /* 3 */
711 mask |= ca_list[j]->mask;
712 algo_strength = (algo_strength & ~ca_list[j]->mask_strength) |
713 (ca_list[j]->algo_strength & ~mask_strength) |
714 (algo_strength & ca_list[j]->algo_strength);
715 mask_strength |= ca_list[j]->mask_strength;
716
717 if (!multi) break;
718 }
719
720 /*
721 * Ok, we have the rule, now apply it
722 */
723 if (rule == CIPHER_SPECIAL)
724 { /* special command */
725 ok = 0;
726 if ((buflen == 8) &&
727 !strncmp(buf, "STRENGTH", 8))
728 ok = ssl_cipher_strength_sort(co_list,
729 head_p, tail_p);
730 else
731 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
732 SSL_R_INVALID_COMMAND);
733 if (ok == 0)
734 retval = 0;
735 /*
736 * We do not support any "multi" options
737 * together with "@", so throw away the
738 * rest of the command, if any left, until
739 * end or ':' is found.
740 */
741 while ((*l != '\0') && ITEM_SEP(*l))
742 l++;
743 }
744 else if (found)
745 {
746 ssl_cipher_apply_rule(algorithms, mask,
747 algo_strength, mask_strength, rule, -1,
748 co_list, head_p, tail_p);
749 }
750 else
751 {
752 while ((*l != '\0') && ITEM_SEP(*l))
753 l++;
754 }
755 if (*l == '\0') break; /* done */
756 }
757
758 return(retval);
759 }
760
761STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
762 STACK_OF(SSL_CIPHER) **cipher_list,
763 STACK_OF(SSL_CIPHER) **cipher_list_by_id,
764 const char *rule_str)
765 {
766 int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
767 unsigned long disabled_mask;
768 STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list;
769 const char *rule_p;
770 CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
771 SSL_CIPHER **ca_list = NULL;
772
773 /*
774 * Return with error if nothing to do.
775 */
776 if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL)
777 return NULL;
778
779 if (init_ciphers)
780 {
781 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
782 if (init_ciphers) load_ciphers();
783 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
784 }
785
786 /*
787 * To reduce the work to do we only want to process the compiled
788 * in algorithms, so we first get the mask of disabled ciphers.
789 */
790 disabled_mask = ssl_cipher_get_disabled();
791
792 /*
793 * Now we have to collect the available ciphers from the compiled
794 * in ciphers. We cannot get more than the number compiled in, so
795 * it is used for allocation.
796 */
797 num_of_ciphers = ssl_method->num_ciphers();
798#ifdef KSSL_DEBUG
799 printf("ssl_create_cipher_list() for %d ciphers\n", num_of_ciphers);
800#endif /* KSSL_DEBUG */
801 co_list = (CIPHER_ORDER *)OPENSSL_malloc(sizeof(CIPHER_ORDER) * num_of_ciphers);
802 if (co_list == NULL)
803 {
804 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
805 return(NULL); /* Failure */
806 }
807
808 ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask,
809 co_list, &head, &tail);
810
811 /*
812 * We also need cipher aliases for selecting based on the rule_str.
813 * There might be two types of entries in the rule_str: 1) names
814 * of ciphers themselves 2) aliases for groups of ciphers.
815 * For 1) we need the available ciphers and for 2) the cipher
816 * groups of cipher_aliases added together in one list (otherwise
817 * we would be happy with just the cipher_aliases table).
818 */
819 num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
820 num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
821 ca_list =
822 (SSL_CIPHER **)OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
823 if (ca_list == NULL)
824 {
825 OPENSSL_free(co_list);
826 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
827 return(NULL); /* Failure */
828 }
829 ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask,
830 head);
831
832 /*
833 * If the rule_string begins with DEFAULT, apply the default rule
834 * before using the (possibly available) additional rules.
835 */
836 ok = 1;
837 rule_p = rule_str;
838 if (strncmp(rule_str,"DEFAULT",7) == 0)
839 {
840 ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
841 co_list, &head, &tail, ca_list);
842 rule_p += 7;
843 if (*rule_p == ':')
844 rule_p++;
845 }
846
847 if (ok && (strlen(rule_p) > 0))
848 ok = ssl_cipher_process_rulestr(rule_p, co_list, &head, &tail,
849 ca_list);
850
851 OPENSSL_free(ca_list); /* Not needed anymore */
852
853 if (!ok)
854 { /* Rule processing failure */
855 OPENSSL_free(co_list);
856 return(NULL);
857 }
858 /*
859 * Allocate new "cipherstack" for the result, return with error
860 * if we cannot get one.
861 */
862 if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL)
863 {
864 OPENSSL_free(co_list);
865 return(NULL);
866 }
867
868 /*
869 * The cipher selection for the list is done. The ciphers are added
870 * to the resulting precedence to the STACK_OF(SSL_CIPHER).
871 */
872 for (curr = head; curr != NULL; curr = curr->next)
873 {
874#ifdef OPENSSL_FIPS
875 if (curr->active && (!FIPS_mode() || curr->cipher->algo_strength & SSL_FIPS))
876#else
877 if (curr->active)
878#endif
879 {
880 sk_SSL_CIPHER_push(cipherstack, curr->cipher);
881#ifdef CIPHER_DEBUG
882 printf("<%s>\n",curr->cipher->name);
883#endif
884 }
885 }
886 OPENSSL_free(co_list); /* Not needed any longer */
887
888 tmp_cipher_list = sk_SSL_CIPHER_dup(cipherstack);
889 if (tmp_cipher_list == NULL)
890 {
891 sk_SSL_CIPHER_free(cipherstack);
892 return NULL;
893 }
894 if (*cipher_list != NULL)
895 sk_SSL_CIPHER_free(*cipher_list);
896 *cipher_list = cipherstack;
897 if (*cipher_list_by_id != NULL)
898 sk_SSL_CIPHER_free(*cipher_list_by_id);
899 *cipher_list_by_id = tmp_cipher_list;
900 sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
901
902 return(cipherstack);
903 }
904
905char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len)
906 {
907 int is_export,pkl,kl;
908 char *ver,*exp_str;
909 char *kx,*au,*enc,*mac;
910 unsigned long alg,alg2,alg_s;
911#ifdef KSSL_DEBUG
912 static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n";
913#else
914 static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
915#endif /* KSSL_DEBUG */
916
917 alg=cipher->algorithms;
918 alg_s=cipher->algo_strength;
919 alg2=cipher->algorithm2;
920
921 is_export=SSL_C_IS_EXPORT(cipher);
922 pkl=SSL_C_EXPORT_PKEYLENGTH(cipher);
923 kl=SSL_C_EXPORT_KEYLENGTH(cipher);
924 exp_str=is_export?" export":"";
925
926 if (alg & SSL_SSLV2)
927 ver="SSLv2";
928 else if (alg & SSL_SSLV3)
929 ver="SSLv3";
930 else
931 ver="unknown";
932
933 switch (alg&SSL_MKEY_MASK)
934 {
935 case SSL_kRSA:
936 kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA";
937 break;
938 case SSL_kDHr:
939 kx="DH/RSA";
940 break;
941 case SSL_kDHd:
942 kx="DH/DSS";
943 break;
944 case SSL_kKRB5: /* VRS */
945 case SSL_KRB5: /* VRS */
946 kx="KRB5";
947 break;
948 case SSL_kFZA:
949 kx="Fortezza";
950 break;
951 case SSL_kEDH:
952 kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH";
953 break;
954 default:
955 kx="unknown";
956 }
957
958 switch (alg&SSL_AUTH_MASK)
959 {
960 case SSL_aRSA:
961 au="RSA";
962 break;
963 case SSL_aDSS:
964 au="DSS";
965 break;
966 case SSL_aDH:
967 au="DH";
968 break;
969 case SSL_aKRB5: /* VRS */
970 case SSL_KRB5: /* VRS */
971 au="KRB5";
972 break;
973 case SSL_aFZA:
974 case SSL_aNULL:
975 au="None";
976 break;
977 default:
978 au="unknown";
979 break;
980 }
981
982 switch (alg&SSL_ENC_MASK)
983 {
984 case SSL_DES:
985 enc=(is_export && kl == 5)?"DES(40)":"DES(56)";
986 break;
987 case SSL_3DES:
988 enc="3DES(168)";
989 break;
990 case SSL_RC4:
991 enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)")
992 :((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)");
993 break;
994 case SSL_RC2:
995 enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)";
996 break;
997 case SSL_IDEA:
998 enc="IDEA(128)";
999 break;
1000 case SSL_eFZA:
1001 enc="Fortezza";
1002 break;
1003 case SSL_eNULL:
1004 enc="None";
1005 break;
1006 case SSL_AES:
1007 switch(cipher->strength_bits)
1008 {
1009 case 128: enc="AES(128)"; break;
1010 case 192: enc="AES(192)"; break;
1011 case 256: enc="AES(256)"; break;
1012 default: enc="AES(?""?""?)"; break;
1013 }
1014 break;
1015 default:
1016 enc="unknown";
1017 break;
1018 }
1019
1020 switch (alg&SSL_MAC_MASK)
1021 {
1022 case SSL_MD5:
1023 mac="MD5";
1024 break;
1025 case SSL_SHA1:
1026 mac="SHA1";
1027 break;
1028 default:
1029 mac="unknown";
1030 break;
1031 }
1032
1033 if (buf == NULL)
1034 {
1035 len=128;
1036 buf=OPENSSL_malloc(len);
1037 if (buf == NULL) return("OPENSSL_malloc Error");
1038 }
1039 else if (len < 128)
1040 return("Buffer too small");
1041
1042#ifdef KSSL_DEBUG
1043 BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str,alg);
1044#else
1045 BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str);
1046#endif /* KSSL_DEBUG */
1047 return(buf);
1048 }
1049
1050char *SSL_CIPHER_get_version(const SSL_CIPHER *c)
1051 {
1052 int i;
1053
1054 if (c == NULL) return("(NONE)");
1055 i=(int)(c->id>>24L);
1056 if (i == 3)
1057 return("TLSv1/SSLv3");
1058 else if (i == 2)
1059 return("SSLv2");
1060 else
1061 return("unknown");
1062 }
1063
1064/* return the actual cipher being used */
1065const char *SSL_CIPHER_get_name(const SSL_CIPHER *c)
1066 {
1067 if (c != NULL)
1068 return(c->name);
1069 return("(NONE)");
1070 }
1071
1072/* number of bits for symmetric cipher */
1073int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits)
1074 {
1075 int ret=0;
1076
1077 if (c != NULL)
1078 {
1079 if (alg_bits != NULL) *alg_bits = c->alg_bits;
1080 ret = c->strength_bits;
1081 }
1082 return(ret);
1083 }
1084
1085SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
1086 {
1087 SSL_COMP *ctmp;
1088 int i,nn;
1089
1090 if ((n == 0) || (sk == NULL)) return(NULL);
1091 nn=sk_SSL_COMP_num(sk);
1092 for (i=0; i<nn; i++)
1093 {
1094 ctmp=sk_SSL_COMP_value(sk,i);
1095 if (ctmp->id == n)
1096 return(ctmp);
1097 }
1098 return(NULL);
1099 }
1100
1101static int sk_comp_cmp(const SSL_COMP * const *a,
1102 const SSL_COMP * const *b)
1103 {
1104 return((*a)->id-(*b)->id);
1105 }
1106
1107STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void)
1108 {
1109 return(ssl_comp_methods);
1110 }
1111
1112int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
1113 {
1114 SSL_COMP *comp;
1115 STACK_OF(SSL_COMP) *sk;
1116
1117 if (cm == NULL || cm->type == NID_undef)
1118 return 1;
1119
1120 MemCheck_off();
1121 comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP));
1122 comp->id=id;
1123 comp->method=cm;
1124 if (ssl_comp_methods == NULL)
1125 sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp);
1126 else
1127 sk=ssl_comp_methods;
1128 if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp))
1129 {
1130 MemCheck_on();
1131 SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);
1132 return(1);
1133 }
1134 else
1135 {
1136 MemCheck_on();
1137 return(0);
1138 }
1139 }
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
deleted file mode 100644
index 4bcf591298..0000000000
--- a/src/lib/libssl/ssl_err.c
+++ /dev/null
@@ -1,462 +0,0 @@
1/* ssl/ssl_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 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 OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_SSL,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_SSL,0,reason)
70
71static ERR_STRING_DATA SSL_str_functs[]=
72 {
73{ERR_FUNC(SSL_F_CLIENT_CERTIFICATE), "CLIENT_CERTIFICATE"},
74{ERR_FUNC(SSL_F_CLIENT_FINISHED), "CLIENT_FINISHED"},
75{ERR_FUNC(SSL_F_CLIENT_HELLO), "CLIENT_HELLO"},
76{ERR_FUNC(SSL_F_CLIENT_MASTER_KEY), "CLIENT_MASTER_KEY"},
77{ERR_FUNC(SSL_F_D2I_SSL_SESSION), "d2i_SSL_SESSION"},
78{ERR_FUNC(SSL_F_DO_SSL3_WRITE), "DO_SSL3_WRITE"},
79{ERR_FUNC(SSL_F_GET_CLIENT_FINISHED), "GET_CLIENT_FINISHED"},
80{ERR_FUNC(SSL_F_GET_CLIENT_HELLO), "GET_CLIENT_HELLO"},
81{ERR_FUNC(SSL_F_GET_CLIENT_MASTER_KEY), "GET_CLIENT_MASTER_KEY"},
82{ERR_FUNC(SSL_F_GET_SERVER_FINISHED), "GET_SERVER_FINISHED"},
83{ERR_FUNC(SSL_F_GET_SERVER_HELLO), "GET_SERVER_HELLO"},
84{ERR_FUNC(SSL_F_GET_SERVER_VERIFY), "GET_SERVER_VERIFY"},
85{ERR_FUNC(SSL_F_I2D_SSL_SESSION), "i2d_SSL_SESSION"},
86{ERR_FUNC(SSL_F_READ_N), "READ_N"},
87{ERR_FUNC(SSL_F_REQUEST_CERTIFICATE), "REQUEST_CERTIFICATE"},
88{ERR_FUNC(SSL_F_SERVER_FINISH), "SERVER_FINISH"},
89{ERR_FUNC(SSL_F_SERVER_HELLO), "SERVER_HELLO"},
90{ERR_FUNC(SSL_F_SERVER_VERIFY), "SERVER_VERIFY"},
91{ERR_FUNC(SSL_F_SSL23_ACCEPT), "SSL23_ACCEPT"},
92{ERR_FUNC(SSL_F_SSL23_CLIENT_HELLO), "SSL23_CLIENT_HELLO"},
93{ERR_FUNC(SSL_F_SSL23_CONNECT), "SSL23_CONNECT"},
94{ERR_FUNC(SSL_F_SSL23_GET_CLIENT_HELLO), "SSL23_GET_CLIENT_HELLO"},
95{ERR_FUNC(SSL_F_SSL23_GET_SERVER_HELLO), "SSL23_GET_SERVER_HELLO"},
96{ERR_FUNC(SSL_F_SSL23_PEEK), "SSL23_PEEK"},
97{ERR_FUNC(SSL_F_SSL23_READ), "SSL23_READ"},
98{ERR_FUNC(SSL_F_SSL23_WRITE), "SSL23_WRITE"},
99{ERR_FUNC(SSL_F_SSL2_ACCEPT), "SSL2_ACCEPT"},
100{ERR_FUNC(SSL_F_SSL2_CONNECT), "SSL2_CONNECT"},
101{ERR_FUNC(SSL_F_SSL2_ENC_INIT), "SSL2_ENC_INIT"},
102{ERR_FUNC(SSL_F_SSL2_GENERATE_KEY_MATERIAL), "SSL2_GENERATE_KEY_MATERIAL"},
103{ERR_FUNC(SSL_F_SSL2_PEEK), "SSL2_PEEK"},
104{ERR_FUNC(SSL_F_SSL2_READ), "SSL2_READ"},
105{ERR_FUNC(SSL_F_SSL2_READ_INTERNAL), "SSL2_READ_INTERNAL"},
106{ERR_FUNC(SSL_F_SSL2_SET_CERTIFICATE), "SSL2_SET_CERTIFICATE"},
107{ERR_FUNC(SSL_F_SSL2_WRITE), "SSL2_WRITE"},
108{ERR_FUNC(SSL_F_SSL3_ACCEPT), "SSL3_ACCEPT"},
109{ERR_FUNC(SSL_F_SSL3_CALLBACK_CTRL), "SSL3_CALLBACK_CTRL"},
110{ERR_FUNC(SSL_F_SSL3_CHANGE_CIPHER_STATE), "SSL3_CHANGE_CIPHER_STATE"},
111{ERR_FUNC(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM), "SSL3_CHECK_CERT_AND_ALGORITHM"},
112{ERR_FUNC(SSL_F_SSL3_CLIENT_HELLO), "SSL3_CLIENT_HELLO"},
113{ERR_FUNC(SSL_F_SSL3_CONNECT), "SSL3_CONNECT"},
114{ERR_FUNC(SSL_F_SSL3_CTRL), "SSL3_CTRL"},
115{ERR_FUNC(SSL_F_SSL3_CTX_CTRL), "SSL3_CTX_CTRL"},
116{ERR_FUNC(SSL_F_SSL3_ENC), "SSL3_ENC"},
117{ERR_FUNC(SSL_F_SSL3_GENERATE_KEY_BLOCK), "SSL3_GENERATE_KEY_BLOCK"},
118{ERR_FUNC(SSL_F_SSL3_GET_CERTIFICATE_REQUEST), "SSL3_GET_CERTIFICATE_REQUEST"},
119{ERR_FUNC(SSL_F_SSL3_GET_CERT_VERIFY), "SSL3_GET_CERT_VERIFY"},
120{ERR_FUNC(SSL_F_SSL3_GET_CLIENT_CERTIFICATE), "SSL3_GET_CLIENT_CERTIFICATE"},
121{ERR_FUNC(SSL_F_SSL3_GET_CLIENT_HELLO), "SSL3_GET_CLIENT_HELLO"},
122{ERR_FUNC(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE), "SSL3_GET_CLIENT_KEY_EXCHANGE"},
123{ERR_FUNC(SSL_F_SSL3_GET_FINISHED), "SSL3_GET_FINISHED"},
124{ERR_FUNC(SSL_F_SSL3_GET_KEY_EXCHANGE), "SSL3_GET_KEY_EXCHANGE"},
125{ERR_FUNC(SSL_F_SSL3_GET_MESSAGE), "SSL3_GET_MESSAGE"},
126{ERR_FUNC(SSL_F_SSL3_GET_RECORD), "SSL3_GET_RECORD"},
127{ERR_FUNC(SSL_F_SSL3_GET_SERVER_CERTIFICATE), "SSL3_GET_SERVER_CERTIFICATE"},
128{ERR_FUNC(SSL_F_SSL3_GET_SERVER_DONE), "SSL3_GET_SERVER_DONE"},
129{ERR_FUNC(SSL_F_SSL3_GET_SERVER_HELLO), "SSL3_GET_SERVER_HELLO"},
130{ERR_FUNC(SSL_F_SSL3_OUTPUT_CERT_CHAIN), "SSL3_OUTPUT_CERT_CHAIN"},
131{ERR_FUNC(SSL_F_SSL3_PEEK), "SSL3_PEEK"},
132{ERR_FUNC(SSL_F_SSL3_READ_BYTES), "SSL3_READ_BYTES"},
133{ERR_FUNC(SSL_F_SSL3_READ_N), "SSL3_READ_N"},
134{ERR_FUNC(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST), "SSL3_SEND_CERTIFICATE_REQUEST"},
135{ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE), "SSL3_SEND_CLIENT_CERTIFICATE"},
136{ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE), "SSL3_SEND_CLIENT_KEY_EXCHANGE"},
137{ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_VERIFY), "SSL3_SEND_CLIENT_VERIFY"},
138{ERR_FUNC(SSL_F_SSL3_SEND_SERVER_CERTIFICATE), "SSL3_SEND_SERVER_CERTIFICATE"},
139{ERR_FUNC(SSL_F_SSL3_SEND_SERVER_HELLO), "SSL3_SEND_SERVER_HELLO"},
140{ERR_FUNC(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE), "SSL3_SEND_SERVER_KEY_EXCHANGE"},
141{ERR_FUNC(SSL_F_SSL3_SETUP_BUFFERS), "SSL3_SETUP_BUFFERS"},
142{ERR_FUNC(SSL_F_SSL3_SETUP_KEY_BLOCK), "SSL3_SETUP_KEY_BLOCK"},
143{ERR_FUNC(SSL_F_SSL3_WRITE_BYTES), "SSL3_WRITE_BYTES"},
144{ERR_FUNC(SSL_F_SSL3_WRITE_PENDING), "SSL3_WRITE_PENDING"},
145{ERR_FUNC(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK), "SSL_add_dir_cert_subjects_to_stack"},
146{ERR_FUNC(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK), "SSL_add_file_cert_subjects_to_stack"},
147{ERR_FUNC(SSL_F_SSL_BAD_METHOD), "SSL_BAD_METHOD"},
148{ERR_FUNC(SSL_F_SSL_BYTES_TO_CIPHER_LIST), "SSL_BYTES_TO_CIPHER_LIST"},
149{ERR_FUNC(SSL_F_SSL_CERT_DUP), "SSL_CERT_DUP"},
150{ERR_FUNC(SSL_F_SSL_CERT_INST), "SSL_CERT_INST"},
151{ERR_FUNC(SSL_F_SSL_CERT_INSTANTIATE), "SSL_CERT_INSTANTIATE"},
152{ERR_FUNC(SSL_F_SSL_CERT_NEW), "SSL_CERT_NEW"},
153{ERR_FUNC(SSL_F_SSL_CHECK_PRIVATE_KEY), "SSL_check_private_key"},
154{ERR_FUNC(SSL_F_SSL_CIPHER_PROCESS_RULESTR), "SSL_CIPHER_PROCESS_RULESTR"},
155{ERR_FUNC(SSL_F_SSL_CIPHER_STRENGTH_SORT), "SSL_CIPHER_STRENGTH_SORT"},
156{ERR_FUNC(SSL_F_SSL_CLEAR), "SSL_clear"},
157{ERR_FUNC(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD), "SSL_COMP_add_compression_method"},
158{ERR_FUNC(SSL_F_SSL_CREATE_CIPHER_LIST), "SSL_CREATE_CIPHER_LIST"},
159{ERR_FUNC(SSL_F_SSL_CTRL), "SSL_ctrl"},
160{ERR_FUNC(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY), "SSL_CTX_check_private_key"},
161{ERR_FUNC(SSL_F_SSL_CTX_NEW), "SSL_CTX_new"},
162{ERR_FUNC(SSL_F_SSL_CTX_SET_CIPHER_LIST), "SSL_CTX_set_cipher_list"},
163{ERR_FUNC(SSL_F_SSL_CTX_SET_PURPOSE), "SSL_CTX_set_purpose"},
164{ERR_FUNC(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT), "SSL_CTX_set_session_id_context"},
165{ERR_FUNC(SSL_F_SSL_CTX_SET_SSL_VERSION), "SSL_CTX_set_ssl_version"},
166{ERR_FUNC(SSL_F_SSL_CTX_SET_TRUST), "SSL_CTX_set_trust"},
167{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE), "SSL_CTX_use_certificate"},
168{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1), "SSL_CTX_use_certificate_ASN1"},
169{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE), "SSL_CTX_use_certificate_chain_file"},
170{ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE), "SSL_CTX_use_certificate_file"},
171{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY), "SSL_CTX_use_PrivateKey"},
172{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1), "SSL_CTX_use_PrivateKey_ASN1"},
173{ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE), "SSL_CTX_use_PrivateKey_file"},
174{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY), "SSL_CTX_use_RSAPrivateKey"},
175{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1), "SSL_CTX_use_RSAPrivateKey_ASN1"},
176{ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE), "SSL_CTX_use_RSAPrivateKey_file"},
177{ERR_FUNC(SSL_F_SSL_DO_HANDSHAKE), "SSL_do_handshake"},
178{ERR_FUNC(SSL_F_SSL_GET_NEW_SESSION), "SSL_GET_NEW_SESSION"},
179{ERR_FUNC(SSL_F_SSL_GET_PREV_SESSION), "SSL_GET_PREV_SESSION"},
180{ERR_FUNC(SSL_F_SSL_GET_SERVER_SEND_CERT), "SSL_GET_SERVER_SEND_CERT"},
181{ERR_FUNC(SSL_F_SSL_GET_SIGN_PKEY), "SSL_GET_SIGN_PKEY"},
182{ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER), "SSL_INIT_WBIO_BUFFER"},
183{ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE), "SSL_load_client_CA_file"},
184{ERR_FUNC(SSL_F_SSL_NEW), "SSL_new"},
185{ERR_FUNC(SSL_F_SSL_READ), "SSL_read"},
186{ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT), "SSL_RSA_PRIVATE_DECRYPT"},
187{ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT), "SSL_RSA_PUBLIC_ENCRYPT"},
188{ERR_FUNC(SSL_F_SSL_SESSION_NEW), "SSL_SESSION_new"},
189{ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP), "SSL_SESSION_print_fp"},
190{ERR_FUNC(SSL_F_SSL_SESS_CERT_NEW), "SSL_SESS_CERT_NEW"},
191{ERR_FUNC(SSL_F_SSL_SET_CERT), "SSL_SET_CERT"},
192{ERR_FUNC(SSL_F_SSL_SET_CIPHER_LIST), "SSL_set_cipher_list"},
193{ERR_FUNC(SSL_F_SSL_SET_FD), "SSL_set_fd"},
194{ERR_FUNC(SSL_F_SSL_SET_PKEY), "SSL_SET_PKEY"},
195{ERR_FUNC(SSL_F_SSL_SET_PURPOSE), "SSL_set_purpose"},
196{ERR_FUNC(SSL_F_SSL_SET_RFD), "SSL_set_rfd"},
197{ERR_FUNC(SSL_F_SSL_SET_SESSION), "SSL_set_session"},
198{ERR_FUNC(SSL_F_SSL_SET_SESSION_ID_CONTEXT), "SSL_set_session_id_context"},
199{ERR_FUNC(SSL_F_SSL_SET_TRUST), "SSL_set_trust"},
200{ERR_FUNC(SSL_F_SSL_SET_WFD), "SSL_set_wfd"},
201{ERR_FUNC(SSL_F_SSL_SHUTDOWN), "SSL_shutdown"},
202{ERR_FUNC(SSL_F_SSL_UNDEFINED_CONST_FUNCTION), "SSL_UNDEFINED_CONST_FUNCTION"},
203{ERR_FUNC(SSL_F_SSL_UNDEFINED_FUNCTION), "SSL_UNDEFINED_FUNCTION"},
204{ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE), "SSL_use_certificate"},
205{ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_ASN1), "SSL_use_certificate_ASN1"},
206{ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_FILE), "SSL_use_certificate_file"},
207{ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY), "SSL_use_PrivateKey"},
208{ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_ASN1), "SSL_use_PrivateKey_ASN1"},
209{ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_FILE), "SSL_use_PrivateKey_file"},
210{ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY), "SSL_use_RSAPrivateKey"},
211{ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1), "SSL_use_RSAPrivateKey_ASN1"},
212{ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE), "SSL_use_RSAPrivateKey_file"},
213{ERR_FUNC(SSL_F_SSL_VERIFY_CERT_CHAIN), "SSL_VERIFY_CERT_CHAIN"},
214{ERR_FUNC(SSL_F_SSL_WRITE), "SSL_write"},
215{ERR_FUNC(SSL_F_TLS1_CHANGE_CIPHER_STATE), "TLS1_CHANGE_CIPHER_STATE"},
216{ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
217{ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
218{ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
219{0,NULL}
220 };
221
222static ERR_STRING_DATA SSL_str_reasons[]=
223 {
224{ERR_REASON(SSL_R_APP_DATA_IN_HANDSHAKE) ,"app data in handshake"},
225{ERR_REASON(SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT),"attempt to reuse session in different context"},
226{ERR_REASON(SSL_R_BAD_ALERT_RECORD) ,"bad alert record"},
227{ERR_REASON(SSL_R_BAD_AUTHENTICATION_TYPE),"bad authentication type"},
228{ERR_REASON(SSL_R_BAD_CHANGE_CIPHER_SPEC),"bad change cipher spec"},
229{ERR_REASON(SSL_R_BAD_CHECKSUM) ,"bad checksum"},
230{ERR_REASON(SSL_R_BAD_DATA_RETURNED_BY_CALLBACK),"bad data returned by callback"},
231{ERR_REASON(SSL_R_BAD_DECOMPRESSION) ,"bad decompression"},
232{ERR_REASON(SSL_R_BAD_DH_G_LENGTH) ,"bad dh g length"},
233{ERR_REASON(SSL_R_BAD_DH_PUB_KEY_LENGTH) ,"bad dh pub key length"},
234{ERR_REASON(SSL_R_BAD_DH_P_LENGTH) ,"bad dh p length"},
235{ERR_REASON(SSL_R_BAD_DIGEST_LENGTH) ,"bad digest length"},
236{ERR_REASON(SSL_R_BAD_DSA_SIGNATURE) ,"bad dsa signature"},
237{ERR_REASON(SSL_R_BAD_HELLO_REQUEST) ,"bad hello request"},
238{ERR_REASON(SSL_R_BAD_LENGTH) ,"bad length"},
239{ERR_REASON(SSL_R_BAD_MAC_DECODE) ,"bad mac decode"},
240{ERR_REASON(SSL_R_BAD_MESSAGE_TYPE) ,"bad message type"},
241{ERR_REASON(SSL_R_BAD_PACKET_LENGTH) ,"bad packet length"},
242{ERR_REASON(SSL_R_BAD_PROTOCOL_VERSION_NUMBER),"bad protocol version number"},
243{ERR_REASON(SSL_R_BAD_RESPONSE_ARGUMENT) ,"bad response argument"},
244{ERR_REASON(SSL_R_BAD_RSA_DECRYPT) ,"bad rsa decrypt"},
245{ERR_REASON(SSL_R_BAD_RSA_ENCRYPT) ,"bad rsa encrypt"},
246{ERR_REASON(SSL_R_BAD_RSA_E_LENGTH) ,"bad rsa e length"},
247{ERR_REASON(SSL_R_BAD_RSA_MODULUS_LENGTH),"bad rsa modulus length"},
248{ERR_REASON(SSL_R_BAD_RSA_SIGNATURE) ,"bad rsa signature"},
249{ERR_REASON(SSL_R_BAD_SIGNATURE) ,"bad signature"},
250{ERR_REASON(SSL_R_BAD_SSL_FILETYPE) ,"bad ssl filetype"},
251{ERR_REASON(SSL_R_BAD_SSL_SESSION_ID_LENGTH),"bad ssl session id length"},
252{ERR_REASON(SSL_R_BAD_STATE) ,"bad state"},
253{ERR_REASON(SSL_R_BAD_WRITE_RETRY) ,"bad write retry"},
254{ERR_REASON(SSL_R_BIO_NOT_SET) ,"bio not set"},
255{ERR_REASON(SSL_R_BLOCK_CIPHER_PAD_IS_WRONG),"block cipher pad is wrong"},
256{ERR_REASON(SSL_R_BN_LIB) ,"bn lib"},
257{ERR_REASON(SSL_R_CA_DN_LENGTH_MISMATCH) ,"ca dn length mismatch"},
258{ERR_REASON(SSL_R_CA_DN_TOO_LONG) ,"ca dn too long"},
259{ERR_REASON(SSL_R_CCS_RECEIVED_EARLY) ,"ccs received early"},
260{ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED),"certificate verify failed"},
261{ERR_REASON(SSL_R_CERT_LENGTH_MISMATCH) ,"cert length mismatch"},
262{ERR_REASON(SSL_R_CHALLENGE_IS_DIFFERENT),"challenge is different"},
263{ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH),"cipher code wrong length"},
264{ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE),"cipher or hash unavailable"},
265{ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR),"cipher table src error"},
266{ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG),"compressed length too long"},
267{ERR_REASON(SSL_R_COMPRESSION_FAILURE) ,"compression failure"},
268{ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR),"compression library error"},
269{ERR_REASON(SSL_R_CONNECTION_ID_IS_DIFFERENT),"connection id is different"},
270{ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET),"connection type not set"},
271{ERR_REASON(SSL_R_DATA_BETWEEN_CCS_AND_FINISHED),"data between ccs and finished"},
272{ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) ,"data length too long"},
273{ERR_REASON(SSL_R_DECRYPTION_FAILED) ,"decryption failed"},
274{ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),"decryption failed or bad record mac"},
275{ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),"dh public value length is wrong"},
276{ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) ,"digest check failed"},
277{ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG),"encrypted length too long"},
278{ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY),"error generating tmp rsa key"},
279{ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST),"error in received cipher list"},
280{ERR_REASON(SSL_R_EXCESSIVE_MESSAGE_SIZE),"excessive message size"},
281{ERR_REASON(SSL_R_EXTRA_DATA_IN_MESSAGE) ,"extra data in message"},
282{ERR_REASON(SSL_R_GOT_A_FIN_BEFORE_A_CCS),"got a fin before a ccs"},
283{ERR_REASON(SSL_R_HTTPS_PROXY_REQUEST) ,"https proxy request"},
284{ERR_REASON(SSL_R_HTTP_REQUEST) ,"http request"},
285{ERR_REASON(SSL_R_ILLEGAL_PADDING) ,"illegal padding"},
286{ERR_REASON(SSL_R_INVALID_CHALLENGE_LENGTH),"invalid challenge length"},
287{ERR_REASON(SSL_R_INVALID_COMMAND) ,"invalid command"},
288{ERR_REASON(SSL_R_INVALID_PURPOSE) ,"invalid purpose"},
289{ERR_REASON(SSL_R_INVALID_TRUST) ,"invalid trust"},
290{ERR_REASON(SSL_R_KEY_ARG_TOO_LONG) ,"key arg too long"},
291{ERR_REASON(SSL_R_KRB5) ,"krb5"},
292{ERR_REASON(SSL_R_KRB5_C_CC_PRINC) ,"krb5 client cc principal (no tkt?)"},
293{ERR_REASON(SSL_R_KRB5_C_GET_CRED) ,"krb5 client get cred"},
294{ERR_REASON(SSL_R_KRB5_C_INIT) ,"krb5 client init"},
295{ERR_REASON(SSL_R_KRB5_C_MK_REQ) ,"krb5 client mk_req (expired tkt?)"},
296{ERR_REASON(SSL_R_KRB5_S_BAD_TICKET) ,"krb5 server bad ticket"},
297{ERR_REASON(SSL_R_KRB5_S_INIT) ,"krb5 server init"},
298{ERR_REASON(SSL_R_KRB5_S_RD_REQ) ,"krb5 server rd_req (keytab perms?)"},
299{ERR_REASON(SSL_R_KRB5_S_TKT_EXPIRED) ,"krb5 server tkt expired"},
300{ERR_REASON(SSL_R_KRB5_S_TKT_NYV) ,"krb5 server tkt not yet valid"},
301{ERR_REASON(SSL_R_KRB5_S_TKT_SKEW) ,"krb5 server tkt skew"},
302{ERR_REASON(SSL_R_LENGTH_MISMATCH) ,"length mismatch"},
303{ERR_REASON(SSL_R_LENGTH_TOO_SHORT) ,"length too short"},
304{ERR_REASON(SSL_R_LIBRARY_BUG) ,"library bug"},
305{ERR_REASON(SSL_R_LIBRARY_HAS_NO_CIPHERS),"library has no ciphers"},
306{ERR_REASON(SSL_R_MESSAGE_TOO_LONG) ,"message too long"},
307{ERR_REASON(SSL_R_MISSING_DH_DSA_CERT) ,"missing dh dsa cert"},
308{ERR_REASON(SSL_R_MISSING_DH_KEY) ,"missing dh key"},
309{ERR_REASON(SSL_R_MISSING_DH_RSA_CERT) ,"missing dh rsa cert"},
310{ERR_REASON(SSL_R_MISSING_DSA_SIGNING_CERT),"missing dsa signing cert"},
311{ERR_REASON(SSL_R_MISSING_EXPORT_TMP_DH_KEY),"missing export tmp dh key"},
312{ERR_REASON(SSL_R_MISSING_EXPORT_TMP_RSA_KEY),"missing export tmp rsa key"},
313{ERR_REASON(SSL_R_MISSING_RSA_CERTIFICATE),"missing rsa certificate"},
314{ERR_REASON(SSL_R_MISSING_RSA_ENCRYPTING_CERT),"missing rsa encrypting cert"},
315{ERR_REASON(SSL_R_MISSING_RSA_SIGNING_CERT),"missing rsa signing cert"},
316{ERR_REASON(SSL_R_MISSING_TMP_DH_KEY) ,"missing tmp dh key"},
317{ERR_REASON(SSL_R_MISSING_TMP_RSA_KEY) ,"missing tmp rsa key"},
318{ERR_REASON(SSL_R_MISSING_TMP_RSA_PKEY) ,"missing tmp rsa pkey"},
319{ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE),"missing verify message"},
320{ERR_REASON(SSL_R_NON_SSLV2_INITIAL_PACKET),"non sslv2 initial packet"},
321{ERR_REASON(SSL_R_NO_CERTIFICATES_RETURNED),"no certificates returned"},
322{ERR_REASON(SSL_R_NO_CERTIFICATE_ASSIGNED),"no certificate assigned"},
323{ERR_REASON(SSL_R_NO_CERTIFICATE_RETURNED),"no certificate returned"},
324{ERR_REASON(SSL_R_NO_CERTIFICATE_SET) ,"no certificate set"},
325{ERR_REASON(SSL_R_NO_CERTIFICATE_SPECIFIED),"no certificate specified"},
326{ERR_REASON(SSL_R_NO_CIPHERS_AVAILABLE) ,"no ciphers available"},
327{ERR_REASON(SSL_R_NO_CIPHERS_PASSED) ,"no ciphers passed"},
328{ERR_REASON(SSL_R_NO_CIPHERS_SPECIFIED) ,"no ciphers specified"},
329{ERR_REASON(SSL_R_NO_CIPHER_LIST) ,"no cipher list"},
330{ERR_REASON(SSL_R_NO_CIPHER_MATCH) ,"no cipher match"},
331{ERR_REASON(SSL_R_NO_CLIENT_CERT_RECEIVED),"no client cert received"},
332{ERR_REASON(SSL_R_NO_COMPRESSION_SPECIFIED),"no compression specified"},
333{ERR_REASON(SSL_R_NO_METHOD_SPECIFIED) ,"no method specified"},
334{ERR_REASON(SSL_R_NO_PRIVATEKEY) ,"no privatekey"},
335{ERR_REASON(SSL_R_NO_PRIVATE_KEY_ASSIGNED),"no private key assigned"},
336{ERR_REASON(SSL_R_NO_PROTOCOLS_AVAILABLE),"no protocols available"},
337{ERR_REASON(SSL_R_NO_PUBLICKEY) ,"no publickey"},
338{ERR_REASON(SSL_R_NO_SHARED_CIPHER) ,"no shared cipher"},
339{ERR_REASON(SSL_R_NO_VERIFY_CALLBACK) ,"no verify callback"},
340{ERR_REASON(SSL_R_NULL_SSL_CTX) ,"null ssl ctx"},
341{ERR_REASON(SSL_R_NULL_SSL_METHOD_PASSED),"null ssl method passed"},
342{ERR_REASON(SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED),"old session cipher not returned"},
343{ERR_REASON(SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE),"only tls allowed in fips mode"},
344{ERR_REASON(SSL_R_PACKET_LENGTH_TOO_LONG),"packet length too long"},
345{ERR_REASON(SSL_R_PATH_TOO_LONG) ,"path too long"},
346{ERR_REASON(SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE),"peer did not return a certificate"},
347{ERR_REASON(SSL_R_PEER_ERROR) ,"peer error"},
348{ERR_REASON(SSL_R_PEER_ERROR_CERTIFICATE),"peer error certificate"},
349{ERR_REASON(SSL_R_PEER_ERROR_NO_CERTIFICATE),"peer error no certificate"},
350{ERR_REASON(SSL_R_PEER_ERROR_NO_CIPHER) ,"peer error no cipher"},
351{ERR_REASON(SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE),"peer error unsupported certificate type"},
352{ERR_REASON(SSL_R_PRE_MAC_LENGTH_TOO_LONG),"pre mac length too long"},
353{ERR_REASON(SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS),"problems mapping cipher functions"},
354{ERR_REASON(SSL_R_PROTOCOL_IS_SHUTDOWN) ,"protocol is shutdown"},
355{ERR_REASON(SSL_R_PUBLIC_KEY_ENCRYPT_ERROR),"public key encrypt error"},
356{ERR_REASON(SSL_R_PUBLIC_KEY_IS_NOT_RSA) ,"public key is not rsa"},
357{ERR_REASON(SSL_R_PUBLIC_KEY_NOT_RSA) ,"public key not rsa"},
358{ERR_REASON(SSL_R_READ_BIO_NOT_SET) ,"read bio not set"},
359{ERR_REASON(SSL_R_READ_WRONG_PACKET_TYPE),"read wrong packet type"},
360{ERR_REASON(SSL_R_RECORD_LENGTH_MISMATCH),"record length mismatch"},
361{ERR_REASON(SSL_R_RECORD_TOO_LARGE) ,"record too large"},
362{ERR_REASON(SSL_R_RECORD_TOO_SMALL) ,"record too small"},
363{ERR_REASON(SSL_R_REQUIRED_CIPHER_MISSING),"required cipher missing"},
364{ERR_REASON(SSL_R_REUSE_CERT_LENGTH_NOT_ZERO),"reuse cert length not zero"},
365{ERR_REASON(SSL_R_REUSE_CERT_TYPE_NOT_ZERO),"reuse cert type not zero"},
366{ERR_REASON(SSL_R_REUSE_CIPHER_LIST_NOT_ZERO),"reuse cipher list not zero"},
367{ERR_REASON(SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED),"session id context uninitialized"},
368{ERR_REASON(SSL_R_SHORT_READ) ,"short read"},
369{ERR_REASON(SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE),"signature for non signing certificate"},
370{ERR_REASON(SSL_R_SSL23_DOING_SESSION_ID_REUSE),"ssl23 doing session id reuse"},
371{ERR_REASON(SSL_R_SSL2_CONNECTION_ID_TOO_LONG),"ssl2 connection id too long"},
372{ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_LONG),"ssl3 session id too long"},
373{ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_SHORT),"ssl3 session id too short"},
374{ERR_REASON(SSL_R_SSLV3_ALERT_BAD_CERTIFICATE),"sslv3 alert bad certificate"},
375{ERR_REASON(SSL_R_SSLV3_ALERT_BAD_RECORD_MAC),"sslv3 alert bad record mac"},
376{ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED),"sslv3 alert certificate expired"},
377{ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED),"sslv3 alert certificate revoked"},
378{ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN),"sslv3 alert certificate unknown"},
379{ERR_REASON(SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE),"sslv3 alert decompression failure"},
380{ERR_REASON(SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE),"sslv3 alert handshake failure"},
381{ERR_REASON(SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER),"sslv3 alert illegal parameter"},
382{ERR_REASON(SSL_R_SSLV3_ALERT_NO_CERTIFICATE),"sslv3 alert no certificate"},
383{ERR_REASON(SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE),"sslv3 alert unexpected message"},
384{ERR_REASON(SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE),"sslv3 alert unsupported certificate"},
385{ERR_REASON(SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION),"ssl ctx has no default ssl version"},
386{ERR_REASON(SSL_R_SSL_HANDSHAKE_FAILURE) ,"ssl handshake failure"},
387{ERR_REASON(SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS),"ssl library has no ciphers"},
388{ERR_REASON(SSL_R_SSL_SESSION_ID_CALLBACK_FAILED),"ssl session id callback failed"},
389{ERR_REASON(SSL_R_SSL_SESSION_ID_CONFLICT),"ssl session id conflict"},
390{ERR_REASON(SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG),"ssl session id context too long"},
391{ERR_REASON(SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH),"ssl session id has bad length"},
392{ERR_REASON(SSL_R_SSL_SESSION_ID_IS_DIFFERENT),"ssl session id is different"},
393{ERR_REASON(SSL_R_TLSV1_ALERT_ACCESS_DENIED),"tlsv1 alert access denied"},
394{ERR_REASON(SSL_R_TLSV1_ALERT_DECODE_ERROR),"tlsv1 alert decode error"},
395{ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPTION_FAILED),"tlsv1 alert decryption failed"},
396{ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPT_ERROR),"tlsv1 alert decrypt error"},
397{ERR_REASON(SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION),"tlsv1 alert export restriction"},
398{ERR_REASON(SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY),"tlsv1 alert insufficient security"},
399{ERR_REASON(SSL_R_TLSV1_ALERT_INTERNAL_ERROR),"tlsv1 alert internal error"},
400{ERR_REASON(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION),"tlsv1 alert no renegotiation"},
401{ERR_REASON(SSL_R_TLSV1_ALERT_PROTOCOL_VERSION),"tlsv1 alert protocol version"},
402{ERR_REASON(SSL_R_TLSV1_ALERT_RECORD_OVERFLOW),"tlsv1 alert record overflow"},
403{ERR_REASON(SSL_R_TLSV1_ALERT_UNKNOWN_CA),"tlsv1 alert unknown ca"},
404{ERR_REASON(SSL_R_TLSV1_ALERT_USER_CANCELLED),"tlsv1 alert user cancelled"},
405{ERR_REASON(SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER),"tls client cert req with anon cipher"},
406{ERR_REASON(SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST),"tls peer did not respond with certificate list"},
407{ERR_REASON(SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG),"tls rsa encrypted value length is wrong"},
408{ERR_REASON(SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER),"tried to use unsupported cipher"},
409{ERR_REASON(SSL_R_UNABLE_TO_DECODE_DH_CERTS),"unable to decode dh certs"},
410{ERR_REASON(SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY),"unable to extract public key"},
411{ERR_REASON(SSL_R_UNABLE_TO_FIND_DH_PARAMETERS),"unable to find dh parameters"},
412{ERR_REASON(SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS),"unable to find public key parameters"},
413{ERR_REASON(SSL_R_UNABLE_TO_FIND_SSL_METHOD),"unable to find ssl method"},
414{ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES),"unable to load ssl2 md5 routines"},
415{ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES),"unable to load ssl3 md5 routines"},
416{ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES),"unable to load ssl3 sha1 routines"},
417{ERR_REASON(SSL_R_UNEXPECTED_MESSAGE) ,"unexpected message"},
418{ERR_REASON(SSL_R_UNEXPECTED_RECORD) ,"unexpected record"},
419{ERR_REASON(SSL_R_UNINITIALIZED) ,"uninitialized"},
420{ERR_REASON(SSL_R_UNKNOWN_ALERT_TYPE) ,"unknown alert type"},
421{ERR_REASON(SSL_R_UNKNOWN_CERTIFICATE_TYPE),"unknown certificate type"},
422{ERR_REASON(SSL_R_UNKNOWN_CIPHER_RETURNED),"unknown cipher returned"},
423{ERR_REASON(SSL_R_UNKNOWN_CIPHER_TYPE) ,"unknown cipher type"},
424{ERR_REASON(SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE),"unknown key exchange type"},
425{ERR_REASON(SSL_R_UNKNOWN_PKEY_TYPE) ,"unknown pkey type"},
426{ERR_REASON(SSL_R_UNKNOWN_PROTOCOL) ,"unknown protocol"},
427{ERR_REASON(SSL_R_UNKNOWN_REMOTE_ERROR_TYPE),"unknown remote error type"},
428{ERR_REASON(SSL_R_UNKNOWN_SSL_VERSION) ,"unknown ssl version"},
429{ERR_REASON(SSL_R_UNKNOWN_STATE) ,"unknown state"},
430{ERR_REASON(SSL_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"},
431{ERR_REASON(SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM),"unsupported compression algorithm"},
432{ERR_REASON(SSL_R_UNSUPPORTED_PROTOCOL) ,"unsupported protocol"},
433{ERR_REASON(SSL_R_UNSUPPORTED_SSL_VERSION),"unsupported ssl version"},
434{ERR_REASON(SSL_R_WRITE_BIO_NOT_SET) ,"write bio not set"},
435{ERR_REASON(SSL_R_WRONG_CIPHER_RETURNED) ,"wrong cipher returned"},
436{ERR_REASON(SSL_R_WRONG_MESSAGE_TYPE) ,"wrong message type"},
437{ERR_REASON(SSL_R_WRONG_NUMBER_OF_KEY_BITS),"wrong number of key bits"},
438{ERR_REASON(SSL_R_WRONG_SIGNATURE_LENGTH),"wrong signature length"},
439{ERR_REASON(SSL_R_WRONG_SIGNATURE_SIZE) ,"wrong signature size"},
440{ERR_REASON(SSL_R_WRONG_SSL_VERSION) ,"wrong ssl version"},
441{ERR_REASON(SSL_R_WRONG_VERSION_NUMBER) ,"wrong version number"},
442{ERR_REASON(SSL_R_X509_LIB) ,"x509 lib"},
443{ERR_REASON(SSL_R_X509_VERIFICATION_SETUP_PROBLEMS),"x509 verification setup problems"},
444{0,NULL}
445 };
446
447#endif
448
449void ERR_load_SSL_strings(void)
450 {
451 static int init=1;
452
453 if (init)
454 {
455 init=0;
456#ifndef OPENSSL_NO_ERR
457 ERR_load_strings(0,SSL_str_functs);
458 ERR_load_strings(0,SSL_str_reasons);
459#endif
460
461 }
462 }
diff --git a/src/lib/libssl/ssl_err2.c b/src/lib/libssl/ssl_err2.c
deleted file mode 100644
index ea95a5f983..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 OPENSSL_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 0f4b7a475b..0000000000
--- a/src/lib/libssl/ssl_lib.c
+++ /dev/null
@@ -1,2355 +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 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
62 *
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
65 * are met:
66 *
67 * 1. Redistributions of source code must retain the above copyright
68 * notice, this list of conditions and the following disclaimer.
69 *
70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in
72 * the documentation and/or other materials provided with the
73 * distribution.
74 *
75 * 3. All advertising materials mentioning features or use of this
76 * software must display the following acknowledgment:
77 * "This product includes software developed by the OpenSSL Project
78 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
79 *
80 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
81 * endorse or promote products derived from this software without
82 * prior written permission. For written permission, please contact
83 * openssl-core@openssl.org.
84 *
85 * 5. Products derived from this software may not be called "OpenSSL"
86 * nor may "OpenSSL" appear in their names without prior written
87 * permission of the OpenSSL Project.
88 *
89 * 6. Redistributions of any form whatsoever must retain the following
90 * acknowledgment:
91 * "This product includes software developed by the OpenSSL Project
92 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
93 *
94 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
95 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
97 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
98 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
99 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
100 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
101 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
102 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
103 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
104 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
105 * OF THE POSSIBILITY OF SUCH DAMAGE.
106 * ====================================================================
107 *
108 * This product includes cryptographic software written by Eric Young
109 * (eay@cryptsoft.com). This product includes software written by Tim
110 * Hudson (tjh@cryptsoft.com).
111 *
112 */
113
114
115#ifdef REF_CHECK
116# include <assert.h>
117#endif
118#include <stdio.h>
119#include "ssl_locl.h"
120#include "kssl_lcl.h"
121#include <openssl/objects.h>
122#include <openssl/lhash.h>
123#include <openssl/x509v3.h>
124#include <openssl/fips.h>
125
126const char *SSL_version_str=OPENSSL_VERSION_TEXT;
127
128SSL3_ENC_METHOD ssl3_undef_enc_method={
129 /* evil casts, but these functions are only called if there's a library bug */
130 (int (*)(SSL *,int))ssl_undefined_function,
131 (int (*)(SSL *, unsigned char *, int))ssl_undefined_function,
132 ssl_undefined_function,
133 (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function,
134 (int (*)(SSL*, int))ssl_undefined_function,
135 (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function
136 };
137
138int SSL_clear(SSL *s)
139 {
140
141 if (s->method == NULL)
142 {
143 SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);
144 return(0);
145 }
146
147 if (ssl_clear_bad_session(s))
148 {
149 SSL_SESSION_free(s->session);
150 s->session=NULL;
151 }
152
153 s->error=0;
154 s->hit=0;
155 s->shutdown=0;
156
157#if 0 /* Disabled since version 1.10 of this file (early return not
158 * needed because SSL_clear is not called when doing renegotiation) */
159 /* This is set if we are doing dynamic renegotiation so keep
160 * the old cipher. It is sort of a SSL_clear_lite :-) */
161 if (s->new_session) return(1);
162#else
163 if (s->new_session)
164 {
165 SSLerr(SSL_F_SSL_CLEAR,ERR_R_INTERNAL_ERROR);
166 return 0;
167 }
168#endif
169
170 s->type=0;
171
172 s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);
173
174 s->version=s->method->version;
175 s->client_version=s->version;
176 s->rwstate=SSL_NOTHING;
177 s->rstate=SSL_ST_READ_HEADER;
178#if 0
179 s->read_ahead=s->ctx->read_ahead;
180#endif
181
182 if (s->init_buf != NULL)
183 {
184 BUF_MEM_free(s->init_buf);
185 s->init_buf=NULL;
186 }
187
188 ssl_clear_cipher_ctx(s);
189
190 s->first_packet=0;
191
192#if 1
193 /* Check to see if we were changed into a different method, if
194 * so, revert back if we are not doing session-id reuse. */
195 if (!s->in_handshake && (s->session == NULL) && (s->method != s->ctx->method))
196 {
197 s->method->ssl_free(s);
198 s->method=s->ctx->method;
199 if (!s->method->ssl_new(s))
200 return(0);
201 }
202 else
203#endif
204 s->method->ssl_clear(s);
205 return(1);
206 }
207
208/** Used to change an SSL_CTXs default SSL method type */
209int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth)
210 {
211 STACK_OF(SSL_CIPHER) *sk;
212
213 ctx->method=meth;
214
215 sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list),
216 &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST);
217 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0))
218 {
219 SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
220 return(0);
221 }
222 return(1);
223 }
224
225SSL *SSL_new(SSL_CTX *ctx)
226 {
227 SSL *s;
228
229 if (ctx == NULL)
230 {
231 SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);
232 return(NULL);
233 }
234 if (ctx->method == NULL)
235 {
236 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
237 return(NULL);
238 }
239
240 s=(SSL *)OPENSSL_malloc(sizeof(SSL));
241 if (s == NULL) goto err;
242 memset(s,0,sizeof(SSL));
243
244#ifndef OPENSSL_NO_KRB5
245 s->kssl_ctx = kssl_ctx_new();
246#endif /* OPENSSL_NO_KRB5 */
247
248 s->options=ctx->options;
249 s->mode=ctx->mode;
250 s->max_cert_list=ctx->max_cert_list;
251
252 if (ctx->cert != NULL)
253 {
254 /* Earlier library versions used to copy the pointer to
255 * the CERT, not its contents; only when setting new
256 * parameters for the per-SSL copy, ssl_cert_new would be
257 * called (and the direct reference to the per-SSL_CTX
258 * settings would be lost, but those still were indirectly
259 * accessed for various purposes, and for that reason they
260 * used to be known as s->ctx->default_cert).
261 * Now we don't look at the SSL_CTX's CERT after having
262 * duplicated it once. */
263
264 s->cert = ssl_cert_dup(ctx->cert);
265 if (s->cert == NULL)
266 goto err;
267 }
268 else
269 s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */
270
271 s->read_ahead=ctx->read_ahead;
272 s->msg_callback=ctx->msg_callback;
273 s->msg_callback_arg=ctx->msg_callback_arg;
274 s->verify_mode=ctx->verify_mode;
275 s->verify_depth=ctx->verify_depth;
276 s->sid_ctx_length=ctx->sid_ctx_length;
277 OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);
278 memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));
279 s->verify_callback=ctx->default_verify_callback;
280 s->generate_session_id=ctx->generate_session_id;
281 s->purpose = ctx->purpose;
282 s->trust = ctx->trust;
283 s->quiet_shutdown=ctx->quiet_shutdown;
284
285 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
286 s->ctx=ctx;
287
288 s->verify_result=X509_V_OK;
289
290 s->method=ctx->method;
291
292 if (!s->method->ssl_new(s))
293 goto err;
294
295 s->references=1;
296 s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;
297
298 SSL_clear(s);
299
300 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
301
302 return(s);
303err:
304 if (s != NULL)
305 {
306 if (s->cert != NULL)
307 ssl_cert_free(s->cert);
308 if (s->ctx != NULL)
309 SSL_CTX_free(s->ctx); /* decrement reference count */
310 OPENSSL_free(s);
311 }
312 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
313 return(NULL);
314 }
315
316int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
317 unsigned int sid_ctx_len)
318 {
319 if(sid_ctx_len > sizeof ctx->sid_ctx)
320 {
321 SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
322 return 0;
323 }
324 ctx->sid_ctx_length=sid_ctx_len;
325 memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len);
326
327 return 1;
328 }
329
330int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
331 unsigned int sid_ctx_len)
332 {
333 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
334 {
335 SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
336 return 0;
337 }
338 ssl->sid_ctx_length=sid_ctx_len;
339 memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len);
340
341 return 1;
342 }
343
344int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb)
345 {
346 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
347 ctx->generate_session_id = cb;
348 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
349 return 1;
350 }
351
352int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB cb)
353 {
354 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
355 ssl->generate_session_id = cb;
356 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
357 return 1;
358 }
359
360int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
361 unsigned int id_len)
362 {
363 /* A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp shows how
364 * we can "construct" a session to give us the desired check - ie. to
365 * find if there's a session in the hash table that would conflict with
366 * any new session built out of this id/id_len and the ssl_version in
367 * use by this SSL. */
368 SSL_SESSION r, *p;
369
370 if(id_len > sizeof r.session_id)
371 return 0;
372
373 r.ssl_version = ssl->version;
374 r.session_id_length = id_len;
375 memcpy(r.session_id, id, id_len);
376 /* NB: SSLv2 always uses a fixed 16-byte session ID, so even if a
377 * callback is calling us to check the uniqueness of a shorter ID, it
378 * must be compared as a padded-out ID because that is what it will be
379 * converted to when the callback has finished choosing it. */
380 if((r.ssl_version == SSL2_VERSION) &&
381 (id_len < SSL2_SSL_SESSION_ID_LENGTH))
382 {
383 memset(r.session_id + id_len, 0,
384 SSL2_SSL_SESSION_ID_LENGTH - id_len);
385 r.session_id_length = SSL2_SSL_SESSION_ID_LENGTH;
386 }
387
388 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
389 p = (SSL_SESSION *)lh_retrieve(ssl->ctx->sessions, &r);
390 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
391 return (p != NULL);
392 }
393
394int SSL_CTX_set_purpose(SSL_CTX *s, int purpose)
395 {
396 return X509_PURPOSE_set(&s->purpose, purpose);
397 }
398
399int SSL_set_purpose(SSL *s, int purpose)
400 {
401 return X509_PURPOSE_set(&s->purpose, purpose);
402 }
403
404int SSL_CTX_set_trust(SSL_CTX *s, int trust)
405 {
406 return X509_TRUST_set(&s->trust, trust);
407 }
408
409int SSL_set_trust(SSL *s, int trust)
410 {
411 return X509_TRUST_set(&s->trust, trust);
412 }
413
414void SSL_free(SSL *s)
415 {
416 int i;
417
418 if(s == NULL)
419 return;
420
421 i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);
422#ifdef REF_PRINT
423 REF_PRINT("SSL",s);
424#endif
425 if (i > 0) return;
426#ifdef REF_CHECK
427 if (i < 0)
428 {
429 fprintf(stderr,"SSL_free, bad reference count\n");
430 abort(); /* ok */
431 }
432#endif
433
434 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
435
436 if (s->bbio != NULL)
437 {
438 /* If the buffering BIO is in place, pop it off */
439 if (s->bbio == s->wbio)
440 {
441 s->wbio=BIO_pop(s->wbio);
442 }
443 BIO_free(s->bbio);
444 s->bbio=NULL;
445 }
446 if (s->rbio != NULL)
447 BIO_free_all(s->rbio);
448 if ((s->wbio != NULL) && (s->wbio != s->rbio))
449 BIO_free_all(s->wbio);
450
451 if (s->init_buf != NULL) BUF_MEM_free(s->init_buf);
452
453 /* add extra stuff */
454 if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);
455 if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);
456
457 /* Make the next call work :-) */
458 if (s->session != NULL)
459 {
460 ssl_clear_bad_session(s);
461 SSL_SESSION_free(s->session);
462 }
463
464 ssl_clear_cipher_ctx(s);
465
466 if (s->cert != NULL) ssl_cert_free(s->cert);
467 /* Free up if allocated */
468
469 if (s->ctx) SSL_CTX_free(s->ctx);
470
471 if (s->client_CA != NULL)
472 sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
473
474 if (s->method != NULL) s->method->ssl_free(s);
475
476#ifndef OPENSSL_NO_KRB5
477 if (s->kssl_ctx != NULL)
478 kssl_ctx_free(s->kssl_ctx);
479#endif /* OPENSSL_NO_KRB5 */
480
481 OPENSSL_free(s);
482 }
483
484void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
485 {
486 /* If the output buffering BIO is still in place, remove it
487 */
488 if (s->bbio != NULL)
489 {
490 if (s->wbio == s->bbio)
491 {
492 s->wbio=s->wbio->next_bio;
493 s->bbio->next_bio=NULL;
494 }
495 }
496 if ((s->rbio != NULL) && (s->rbio != rbio))
497 BIO_free_all(s->rbio);
498 if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio))
499 BIO_free_all(s->wbio);
500 s->rbio=rbio;
501 s->wbio=wbio;
502 }
503
504BIO *SSL_get_rbio(const SSL *s)
505 { return(s->rbio); }
506
507BIO *SSL_get_wbio(const SSL *s)
508 { return(s->wbio); }
509
510int SSL_get_fd(const SSL *s)
511 {
512 return(SSL_get_rfd(s));
513 }
514
515int SSL_get_rfd(const SSL *s)
516 {
517 int ret= -1;
518 BIO *b,*r;
519
520 b=SSL_get_rbio(s);
521 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
522 if (r != NULL)
523 BIO_get_fd(r,&ret);
524 return(ret);
525 }
526
527int SSL_get_wfd(const SSL *s)
528 {
529 int ret= -1;
530 BIO *b,*r;
531
532 b=SSL_get_wbio(s);
533 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
534 if (r != NULL)
535 BIO_get_fd(r,&ret);
536 return(ret);
537 }
538
539#ifndef OPENSSL_NO_SOCK
540int SSL_set_fd(SSL *s,int fd)
541 {
542 int ret=0;
543 BIO *bio=NULL;
544
545 bio=BIO_new(BIO_s_socket());
546
547 if (bio == NULL)
548 {
549 SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB);
550 goto err;
551 }
552 BIO_set_fd(bio,fd,BIO_NOCLOSE);
553 SSL_set_bio(s,bio,bio);
554 ret=1;
555err:
556 return(ret);
557 }
558
559int SSL_set_wfd(SSL *s,int fd)
560 {
561 int ret=0;
562 BIO *bio=NULL;
563
564 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
565 || ((int)BIO_get_fd(s->rbio,NULL) != fd))
566 {
567 bio=BIO_new(BIO_s_socket());
568
569 if (bio == NULL)
570 { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; }
571 BIO_set_fd(bio,fd,BIO_NOCLOSE);
572 SSL_set_bio(s,SSL_get_rbio(s),bio);
573 }
574 else
575 SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s));
576 ret=1;
577err:
578 return(ret);
579 }
580
581int SSL_set_rfd(SSL *s,int fd)
582 {
583 int ret=0;
584 BIO *bio=NULL;
585
586 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
587 || ((int)BIO_get_fd(s->wbio,NULL) != fd))
588 {
589 bio=BIO_new(BIO_s_socket());
590
591 if (bio == NULL)
592 {
593 SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB);
594 goto err;
595 }
596 BIO_set_fd(bio,fd,BIO_NOCLOSE);
597 SSL_set_bio(s,bio,SSL_get_wbio(s));
598 }
599 else
600 SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s));
601 ret=1;
602err:
603 return(ret);
604 }
605#endif
606
607
608/* return length of latest Finished message we sent, copy to 'buf' */
609size_t SSL_get_finished(const SSL *s, void *buf, size_t count)
610 {
611 size_t ret = 0;
612
613 if (s->s3 != NULL)
614 {
615 ret = s->s3->tmp.finish_md_len;
616 if (count > ret)
617 count = ret;
618 memcpy(buf, s->s3->tmp.finish_md, count);
619 }
620 return ret;
621 }
622
623/* return length of latest Finished message we expected, copy to 'buf' */
624size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count)
625 {
626 size_t ret = 0;
627
628 if (s->s3 != NULL)
629 {
630 ret = s->s3->tmp.peer_finish_md_len;
631 if (count > ret)
632 count = ret;
633 memcpy(buf, s->s3->tmp.peer_finish_md, count);
634 }
635 return ret;
636 }
637
638
639int SSL_get_verify_mode(const SSL *s)
640 {
641 return(s->verify_mode);
642 }
643
644int SSL_get_verify_depth(const SSL *s)
645 {
646 return(s->verify_depth);
647 }
648
649int (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *)
650 {
651 return(s->verify_callback);
652 }
653
654int SSL_CTX_get_verify_mode(const SSL_CTX *ctx)
655 {
656 return(ctx->verify_mode);
657 }
658
659int SSL_CTX_get_verify_depth(const SSL_CTX *ctx)
660 {
661 return(ctx->verify_depth);
662 }
663
664int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *)
665 {
666 return(ctx->default_verify_callback);
667 }
668
669void SSL_set_verify(SSL *s,int mode,
670 int (*callback)(int ok,X509_STORE_CTX *ctx))
671 {
672 s->verify_mode=mode;
673 if (callback != NULL)
674 s->verify_callback=callback;
675 }
676
677void SSL_set_verify_depth(SSL *s,int depth)
678 {
679 s->verify_depth=depth;
680 }
681
682void SSL_set_read_ahead(SSL *s,int yes)
683 {
684 s->read_ahead=yes;
685 }
686
687int SSL_get_read_ahead(const SSL *s)
688 {
689 return(s->read_ahead);
690 }
691
692int SSL_pending(const SSL *s)
693 {
694 /* SSL_pending cannot work properly if read-ahead is enabled
695 * (SSL_[CTX_]ctrl(..., SSL_CTRL_SET_READ_AHEAD, 1, NULL)),
696 * and it is impossible to fix since SSL_pending cannot report
697 * errors that may be observed while scanning the new data.
698 * (Note that SSL_pending() is often used as a boolean value,
699 * so we'd better not return -1.)
700 */
701 return(s->method->ssl_pending(s));
702 }
703
704X509 *SSL_get_peer_certificate(const SSL *s)
705 {
706 X509 *r;
707
708 if ((s == NULL) || (s->session == NULL))
709 r=NULL;
710 else
711 r=s->session->peer;
712
713 if (r == NULL) return(r);
714
715 CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509);
716
717 return(r);
718 }
719
720STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s)
721 {
722 STACK_OF(X509) *r;
723
724 if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL))
725 r=NULL;
726 else
727 r=s->session->sess_cert->cert_chain;
728
729 /* If we are a client, cert_chain includes the peer's own
730 * certificate; if we are a server, it does not. */
731
732 return(r);
733 }
734
735/* Now in theory, since the calling process own 't' it should be safe to
736 * modify. We need to be able to read f without being hassled */
737void SSL_copy_session_id(SSL *t,const SSL *f)
738 {
739 CERT *tmp;
740
741 /* Do we need to to SSL locking? */
742 SSL_set_session(t,SSL_get_session(f));
743
744 /* what if we are setup as SSLv2 but want to talk SSLv3 or
745 * vice-versa */
746 if (t->method != f->method)
747 {
748 t->method->ssl_free(t); /* cleanup current */
749 t->method=f->method; /* change method */
750 t->method->ssl_new(t); /* setup new */
751 }
752
753 tmp=t->cert;
754 if (f->cert != NULL)
755 {
756 CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT);
757 t->cert=f->cert;
758 }
759 else
760 t->cert=NULL;
761 if (tmp != NULL) ssl_cert_free(tmp);
762 SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length);
763 }
764
765/* Fix this so it checks all the valid key/cert options */
766int SSL_CTX_check_private_key(const SSL_CTX *ctx)
767 {
768 if ( (ctx == NULL) ||
769 (ctx->cert == NULL) ||
770 (ctx->cert->key->x509 == NULL))
771 {
772 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
773 return(0);
774 }
775 if (ctx->cert->key->privatekey == NULL)
776 {
777 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
778 return(0);
779 }
780 return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey));
781 }
782
783/* Fix this function so that it takes an optional type parameter */
784int SSL_check_private_key(const SSL *ssl)
785 {
786 if (ssl == NULL)
787 {
788 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER);
789 return(0);
790 }
791 if (ssl->cert == NULL)
792 {
793 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
794 return 0;
795 }
796 if (ssl->cert->key->x509 == NULL)
797 {
798 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
799 return(0);
800 }
801 if (ssl->cert->key->privatekey == NULL)
802 {
803 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
804 return(0);
805 }
806 return(X509_check_private_key(ssl->cert->key->x509,
807 ssl->cert->key->privatekey));
808 }
809
810int SSL_accept(SSL *s)
811 {
812 if (s->handshake_func == 0)
813 /* Not properly initialized yet */
814 SSL_set_accept_state(s);
815
816 return(s->method->ssl_accept(s));
817 }
818
819int SSL_connect(SSL *s)
820 {
821 if (s->handshake_func == 0)
822 /* Not properly initialized yet */
823 SSL_set_connect_state(s);
824
825 return(s->method->ssl_connect(s));
826 }
827
828long SSL_get_default_timeout(const SSL *s)
829 {
830 return(s->method->get_timeout());
831 }
832
833int SSL_read(SSL *s,void *buf,int num)
834 {
835 if (s->handshake_func == 0)
836 {
837 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
838 return -1;
839 }
840
841 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
842 {
843 s->rwstate=SSL_NOTHING;
844 return(0);
845 }
846 return(s->method->ssl_read(s,buf,num));
847 }
848
849int SSL_peek(SSL *s,void *buf,int num)
850 {
851 if (s->handshake_func == 0)
852 {
853 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
854 return -1;
855 }
856
857 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
858 {
859 return(0);
860 }
861 return(s->method->ssl_peek(s,buf,num));
862 }
863
864int SSL_write(SSL *s,const void *buf,int num)
865 {
866 if (s->handshake_func == 0)
867 {
868 SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED);
869 return -1;
870 }
871
872 if (s->shutdown & SSL_SENT_SHUTDOWN)
873 {
874 s->rwstate=SSL_NOTHING;
875 SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN);
876 return(-1);
877 }
878 return(s->method->ssl_write(s,buf,num));
879 }
880
881int SSL_shutdown(SSL *s)
882 {
883 /* Note that this function behaves differently from what one might
884 * expect. Return values are 0 for no success (yet),
885 * 1 for success; but calling it once is usually not enough,
886 * even if blocking I/O is used (see ssl3_shutdown).
887 */
888
889 if (s->handshake_func == 0)
890 {
891 SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED);
892 return -1;
893 }
894
895 if ((s != NULL) && !SSL_in_init(s))
896 return(s->method->ssl_shutdown(s));
897 else
898 return(1);
899 }
900
901int SSL_renegotiate(SSL *s)
902 {
903 if (s->new_session == 0)
904 {
905 s->new_session=1;
906 }
907 return(s->method->ssl_renegotiate(s));
908 }
909
910int SSL_renegotiate_pending(SSL *s)
911 {
912 /* becomes true when negotiation is requested;
913 * false again once a handshake has finished */
914 return (s->new_session != 0);
915 }
916
917long SSL_ctrl(SSL *s,int cmd,long larg,void *parg)
918 {
919 long l;
920
921 switch (cmd)
922 {
923 case SSL_CTRL_GET_READ_AHEAD:
924 return(s->read_ahead);
925 case SSL_CTRL_SET_READ_AHEAD:
926 l=s->read_ahead;
927 s->read_ahead=larg;
928 return(l);
929
930 case SSL_CTRL_SET_MSG_CALLBACK_ARG:
931 s->msg_callback_arg = parg;
932 return 1;
933
934 case SSL_CTRL_OPTIONS:
935 return(s->options|=larg);
936 case SSL_CTRL_MODE:
937 return(s->mode|=larg);
938 case SSL_CTRL_GET_MAX_CERT_LIST:
939 return(s->max_cert_list);
940 case SSL_CTRL_SET_MAX_CERT_LIST:
941 l=s->max_cert_list;
942 s->max_cert_list=larg;
943 return(l);
944 default:
945 return(s->method->ssl_ctrl(s,cmd,larg,parg));
946 }
947 }
948
949long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)())
950 {
951 switch(cmd)
952 {
953 case SSL_CTRL_SET_MSG_CALLBACK:
954 s->msg_callback = (void (*)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))(fp);
955 return 1;
956
957 default:
958 return(s->method->ssl_callback_ctrl(s,cmd,fp));
959 }
960 }
961
962struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx)
963 {
964 return ctx->sessions;
965 }
966
967long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg)
968 {
969 long l;
970
971 switch (cmd)
972 {
973 case SSL_CTRL_GET_READ_AHEAD:
974 return(ctx->read_ahead);
975 case SSL_CTRL_SET_READ_AHEAD:
976 l=ctx->read_ahead;
977 ctx->read_ahead=larg;
978 return(l);
979
980 case SSL_CTRL_SET_MSG_CALLBACK_ARG:
981 ctx->msg_callback_arg = parg;
982 return 1;
983
984 case SSL_CTRL_GET_MAX_CERT_LIST:
985 return(ctx->max_cert_list);
986 case SSL_CTRL_SET_MAX_CERT_LIST:
987 l=ctx->max_cert_list;
988 ctx->max_cert_list=larg;
989 return(l);
990
991 case SSL_CTRL_SET_SESS_CACHE_SIZE:
992 l=ctx->session_cache_size;
993 ctx->session_cache_size=larg;
994 return(l);
995 case SSL_CTRL_GET_SESS_CACHE_SIZE:
996 return(ctx->session_cache_size);
997 case SSL_CTRL_SET_SESS_CACHE_MODE:
998 l=ctx->session_cache_mode;
999 ctx->session_cache_mode=larg;
1000 return(l);
1001 case SSL_CTRL_GET_SESS_CACHE_MODE:
1002 return(ctx->session_cache_mode);
1003
1004 case SSL_CTRL_SESS_NUMBER:
1005 return(ctx->sessions->num_items);
1006 case SSL_CTRL_SESS_CONNECT:
1007 return(ctx->stats.sess_connect);
1008 case SSL_CTRL_SESS_CONNECT_GOOD:
1009 return(ctx->stats.sess_connect_good);
1010 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
1011 return(ctx->stats.sess_connect_renegotiate);
1012 case SSL_CTRL_SESS_ACCEPT:
1013 return(ctx->stats.sess_accept);
1014 case SSL_CTRL_SESS_ACCEPT_GOOD:
1015 return(ctx->stats.sess_accept_good);
1016 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
1017 return(ctx->stats.sess_accept_renegotiate);
1018 case SSL_CTRL_SESS_HIT:
1019 return(ctx->stats.sess_hit);
1020 case SSL_CTRL_SESS_CB_HIT:
1021 return(ctx->stats.sess_cb_hit);
1022 case SSL_CTRL_SESS_MISSES:
1023 return(ctx->stats.sess_miss);
1024 case SSL_CTRL_SESS_TIMEOUTS:
1025 return(ctx->stats.sess_timeout);
1026 case SSL_CTRL_SESS_CACHE_FULL:
1027 return(ctx->stats.sess_cache_full);
1028 case SSL_CTRL_OPTIONS:
1029 return(ctx->options|=larg);
1030 case SSL_CTRL_MODE:
1031 return(ctx->mode|=larg);
1032 default:
1033 return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg));
1034 }
1035 }
1036
1037long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
1038 {
1039 switch(cmd)
1040 {
1041 case SSL_CTRL_SET_MSG_CALLBACK:
1042 ctx->msg_callback = (void (*)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))(fp);
1043 return 1;
1044
1045 default:
1046 return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp));
1047 }
1048 }
1049
1050int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b)
1051 {
1052 long l;
1053
1054 l=a->id-b->id;
1055 if (l == 0L)
1056 return(0);
1057 else
1058 return((l > 0)?1:-1);
1059 }
1060
1061int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
1062 const SSL_CIPHER * const *bp)
1063 {
1064 long l;
1065
1066 l=(*ap)->id-(*bp)->id;
1067 if (l == 0L)
1068 return(0);
1069 else
1070 return((l > 0)?1:-1);
1071 }
1072
1073/** return a STACK of the ciphers available for the SSL and in order of
1074 * preference */
1075STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s)
1076 {
1077 if (s != NULL)
1078 {
1079 if (s->cipher_list != NULL)
1080 {
1081 return(s->cipher_list);
1082 }
1083 else if ((s->ctx != NULL) &&
1084 (s->ctx->cipher_list != NULL))
1085 {
1086 return(s->ctx->cipher_list);
1087 }
1088 }
1089 return(NULL);
1090 }
1091
1092/** return a STACK of the ciphers available for the SSL and in order of
1093 * algorithm id */
1094STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s)
1095 {
1096 if (s != NULL)
1097 {
1098 if (s->cipher_list_by_id != NULL)
1099 {
1100 return(s->cipher_list_by_id);
1101 }
1102 else if ((s->ctx != NULL) &&
1103 (s->ctx->cipher_list_by_id != NULL))
1104 {
1105 return(s->ctx->cipher_list_by_id);
1106 }
1107 }
1108 return(NULL);
1109 }
1110
1111/** The old interface to get the same thing as SSL_get_ciphers() */
1112const char *SSL_get_cipher_list(const SSL *s,int n)
1113 {
1114 SSL_CIPHER *c;
1115 STACK_OF(SSL_CIPHER) *sk;
1116
1117 if (s == NULL) return(NULL);
1118 sk=SSL_get_ciphers(s);
1119 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n))
1120 return(NULL);
1121 c=sk_SSL_CIPHER_value(sk,n);
1122 if (c == NULL) return(NULL);
1123 return(c->name);
1124 }
1125
1126/** specify the ciphers to be used by default by the SSL_CTX */
1127int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
1128 {
1129 STACK_OF(SSL_CIPHER) *sk;
1130
1131 sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list,
1132 &ctx->cipher_list_by_id,str);
1133 /* ssl_create_cipher_list may return an empty stack if it
1134 * was unable to find a cipher matching the given rule string
1135 * (for example if the rule string specifies a cipher which
1136 * has been disabled). This is not an error as far as
1137 * ssl_create_cipher_list is concerned, and hence
1138 * ctx->cipher_list and ctx->cipher_list_by_id has been
1139 * updated. */
1140 if (sk == NULL)
1141 return 0;
1142 else if (sk_SSL_CIPHER_num(sk) == 0)
1143 {
1144 SSLerr(SSL_F_SSL_CTX_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH);
1145 return 0;
1146 }
1147 return 1;
1148 }
1149
1150/** specify the ciphers to be used by the SSL */
1151int SSL_set_cipher_list(SSL *s,const char *str)
1152 {
1153 STACK_OF(SSL_CIPHER) *sk;
1154
1155 sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list,
1156 &s->cipher_list_by_id,str);
1157 /* see comment in SSL_CTX_set_cipher_list */
1158 if (sk == NULL)
1159 return 0;
1160 else if (sk_SSL_CIPHER_num(sk) == 0)
1161 {
1162 SSLerr(SSL_F_SSL_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH);
1163 return 0;
1164 }
1165 return 1;
1166 }
1167
1168/* works well for SSLv2, not so good for SSLv3 */
1169char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len)
1170 {
1171 char *end;
1172 STACK_OF(SSL_CIPHER) *sk;
1173 SSL_CIPHER *c;
1174 size_t curlen = 0;
1175 int i;
1176
1177 if ((s->session == NULL) || (s->session->ciphers == NULL) ||
1178 (len < 2))
1179 return(NULL);
1180
1181 sk=s->session->ciphers;
1182 buf[0] = '\0';
1183 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
1184 {
1185 c=sk_SSL_CIPHER_value(sk,i);
1186 end = buf + curlen;
1187 if (strlcat(buf, c->name, len) >= len ||
1188 (curlen = strlcat(buf, ":", len)) >= len)
1189 {
1190 /* remove truncated cipher from list */
1191 *end = '\0';
1192 break;
1193 }
1194 }
1195 /* remove trailing colon */
1196 if ((end = strrchr(buf, ':')) != NULL)
1197 *end = '\0';
1198 return(buf);
1199 }
1200
1201int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,
1202 int (*put_cb)(const SSL_CIPHER *, unsigned char *))
1203 {
1204 int i,j=0;
1205 SSL_CIPHER *c;
1206 unsigned char *q;
1207#ifndef OPENSSL_NO_KRB5
1208 int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx);
1209#endif /* OPENSSL_NO_KRB5 */
1210
1211 if (sk == NULL) return(0);
1212 q=p;
1213
1214 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
1215 {
1216 c=sk_SSL_CIPHER_value(sk,i);
1217#ifndef OPENSSL_NO_KRB5
1218 if ((c->algorithms & SSL_KRB5) && nokrb5)
1219 continue;
1220#endif /* OPENSSL_NO_KRB5 */
1221
1222 j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p);
1223 p+=j;
1224 }
1225 return(p-q);
1226 }
1227
1228STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
1229 STACK_OF(SSL_CIPHER) **skp)
1230 {
1231 SSL_CIPHER *c;
1232 STACK_OF(SSL_CIPHER) *sk;
1233 int i,n;
1234
1235 n=ssl_put_cipher_by_char(s,NULL,NULL);
1236 if ((num%n) != 0)
1237 {
1238 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1239 return(NULL);
1240 }
1241 if ((skp == NULL) || (*skp == NULL))
1242 sk=sk_SSL_CIPHER_new_null(); /* change perhaps later */
1243 else
1244 {
1245 sk= *skp;
1246 sk_SSL_CIPHER_zero(sk);
1247 }
1248
1249 for (i=0; i<num; i+=n)
1250 {
1251 c=ssl_get_cipher_by_char(s,p);
1252 p+=n;
1253 if (c != NULL)
1254 {
1255 if (!sk_SSL_CIPHER_push(sk,c))
1256 {
1257 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
1258 goto err;
1259 }
1260 }
1261 }
1262
1263 if (skp != NULL)
1264 *skp=sk;
1265 return(sk);
1266err:
1267 if ((skp == NULL) || (*skp == NULL))
1268 sk_SSL_CIPHER_free(sk);
1269 return(NULL);
1270 }
1271
1272unsigned long SSL_SESSION_hash(const SSL_SESSION *a)
1273 {
1274 unsigned long l;
1275
1276 l=(unsigned long)
1277 ((unsigned int) a->session_id[0] )|
1278 ((unsigned int) a->session_id[1]<< 8L)|
1279 ((unsigned long)a->session_id[2]<<16L)|
1280 ((unsigned long)a->session_id[3]<<24L);
1281 return(l);
1282 }
1283
1284/* NB: If this function (or indeed the hash function which uses a sort of
1285 * coarser function than this one) is changed, ensure
1286 * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
1287 * able to construct an SSL_SESSION that will collide with any existing session
1288 * with a matching session ID. */
1289int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b)
1290 {
1291 if (a->ssl_version != b->ssl_version)
1292 return(1);
1293 if (a->session_id_length != b->session_id_length)
1294 return(1);
1295 return(memcmp(a->session_id,b->session_id,a->session_id_length));
1296 }
1297
1298/* These wrapper functions should remain rather than redeclaring
1299 * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each
1300 * variable. The reason is that the functions aren't static, they're exposed via
1301 * ssl.h. */
1302static IMPLEMENT_LHASH_HASH_FN(SSL_SESSION_hash, SSL_SESSION *)
1303static IMPLEMENT_LHASH_COMP_FN(SSL_SESSION_cmp, SSL_SESSION *)
1304
1305SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
1306 {
1307 SSL_CTX *ret=NULL;
1308
1309 if (meth == NULL)
1310 {
1311 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);
1312 return(NULL);
1313 }
1314
1315#ifdef OPENSSL_FIPS
1316 if (FIPS_mode() && (meth->version < TLS1_VERSION))
1317 {
1318 SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);
1319 return NULL;
1320 }
1321#endif
1322
1323 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
1324 {
1325 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
1326 goto err;
1327 }
1328 ret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
1329 if (ret == NULL)
1330 goto err;
1331
1332 memset(ret,0,sizeof(SSL_CTX));
1333
1334 ret->method=meth;
1335
1336 ret->cert_store=NULL;
1337 ret->session_cache_mode=SSL_SESS_CACHE_SERVER;
1338 ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
1339 ret->session_cache_head=NULL;
1340 ret->session_cache_tail=NULL;
1341
1342 /* We take the system default */
1343 ret->session_timeout=meth->get_timeout();
1344
1345 ret->new_session_cb=0;
1346 ret->remove_session_cb=0;
1347 ret->get_session_cb=0;
1348 ret->generate_session_id=0;
1349
1350 memset((char *)&ret->stats,0,sizeof(ret->stats));
1351
1352 ret->references=1;
1353 ret->quiet_shutdown=0;
1354
1355/* ret->cipher=NULL;*/
1356/* ret->s2->challenge=NULL;
1357 ret->master_key=NULL;
1358 ret->key_arg=NULL;
1359 ret->s2->conn_id=NULL; */
1360
1361 ret->info_callback=NULL;
1362
1363 ret->app_verify_callback=0;
1364 ret->app_verify_arg=NULL;
1365
1366 ret->max_cert_list=SSL_MAX_CERT_LIST_DEFAULT;
1367 ret->read_ahead=0;
1368 ret->msg_callback=0;
1369 ret->msg_callback_arg=NULL;
1370 ret->verify_mode=SSL_VERIFY_NONE;
1371 ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */
1372 ret->sid_ctx_length=0;
1373 ret->default_verify_callback=NULL;
1374 if ((ret->cert=ssl_cert_new()) == NULL)
1375 goto err;
1376
1377 ret->default_passwd_callback=0;
1378 ret->default_passwd_callback_userdata=NULL;
1379 ret->client_cert_cb=0;
1380
1381 ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash),
1382 LHASH_COMP_FN(SSL_SESSION_cmp));
1383 if (ret->sessions == NULL) goto err;
1384 ret->cert_store=X509_STORE_new();
1385 if (ret->cert_store == NULL) goto err;
1386
1387 ssl_create_cipher_list(ret->method,
1388 &ret->cipher_list,&ret->cipher_list_by_id,
1389 SSL_DEFAULT_CIPHER_LIST);
1390 if (ret->cipher_list == NULL
1391 || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)
1392 {
1393 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);
1394 goto err2;
1395 }
1396
1397 if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)
1398 {
1399 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);
1400 goto err2;
1401 }
1402 if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)
1403 {
1404 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);
1405 goto err2;
1406 }
1407 if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)
1408 {
1409 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);
1410 goto err2;
1411 }
1412
1413 if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)
1414 goto err;
1415
1416 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data);
1417
1418 ret->extra_certs=NULL;
1419 ret->comp_methods=SSL_COMP_get_compression_methods();
1420
1421 return(ret);
1422err:
1423 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
1424err2:
1425 if (ret != NULL) SSL_CTX_free(ret);
1426 return(NULL);
1427 }
1428
1429#if 0
1430static void SSL_COMP_free(SSL_COMP *comp)
1431 { OPENSSL_free(comp); }
1432#endif
1433
1434void SSL_CTX_free(SSL_CTX *a)
1435 {
1436 int i;
1437
1438 if (a == NULL) return;
1439
1440 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);
1441#ifdef REF_PRINT
1442 REF_PRINT("SSL_CTX",a);
1443#endif
1444 if (i > 0) return;
1445#ifdef REF_CHECK
1446 if (i < 0)
1447 {
1448 fprintf(stderr,"SSL_CTX_free, bad reference count\n");
1449 abort(); /* ok */
1450 }
1451#endif
1452
1453 /*
1454 * Free internal session cache. However: the remove_cb() may reference
1455 * the ex_data of SSL_CTX, thus the ex_data store can only be removed
1456 * after the sessions were flushed.
1457 * As the ex_data handling routines might also touch the session cache,
1458 * the most secure solution seems to be: empty (flush) the cache, then
1459 * free ex_data, then finally free the cache.
1460 * (See ticket [openssl.org #212].)
1461 */
1462 if (a->sessions != NULL)
1463 SSL_CTX_flush_sessions(a,0);
1464
1465 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);
1466
1467 if (a->sessions != NULL)
1468 lh_free(a->sessions);
1469
1470 if (a->cert_store != NULL)
1471 X509_STORE_free(a->cert_store);
1472 if (a->cipher_list != NULL)
1473 sk_SSL_CIPHER_free(a->cipher_list);
1474 if (a->cipher_list_by_id != NULL)
1475 sk_SSL_CIPHER_free(a->cipher_list_by_id);
1476 if (a->cert != NULL)
1477 ssl_cert_free(a->cert);
1478 if (a->client_CA != NULL)
1479 sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);
1480 if (a->extra_certs != NULL)
1481 sk_X509_pop_free(a->extra_certs,X509_free);
1482#if 0 /* This should never be done, since it removes a global database */
1483 if (a->comp_methods != NULL)
1484 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1485#else
1486 a->comp_methods = NULL;
1487#endif
1488 OPENSSL_free(a);
1489 }
1490
1491void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1492 {
1493 ctx->default_passwd_callback=cb;
1494 }
1495
1496void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u)
1497 {
1498 ctx->default_passwd_callback_userdata=u;
1499 }
1500
1501void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg)
1502 {
1503 ctx->app_verify_callback=cb;
1504 ctx->app_verify_arg=arg;
1505 }
1506
1507void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *))
1508 {
1509 ctx->verify_mode=mode;
1510 ctx->default_verify_callback=cb;
1511 }
1512
1513void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth)
1514 {
1515 ctx->verify_depth=depth;
1516 }
1517
1518void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
1519 {
1520 CERT_PKEY *cpk;
1521 int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;
1522 int rsa_enc_export,dh_rsa_export,dh_dsa_export;
1523 int rsa_tmp_export,dh_tmp_export,kl;
1524 unsigned long mask,emask;
1525
1526 if (c == NULL) return;
1527
1528 kl=SSL_C_EXPORT_PKEYLENGTH(cipher);
1529
1530#ifndef OPENSSL_NO_RSA
1531 rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL);
1532 rsa_tmp_export=(c->rsa_tmp_cb != NULL ||
1533 (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl));
1534#else
1535 rsa_tmp=rsa_tmp_export=0;
1536#endif
1537#ifndef OPENSSL_NO_DH
1538 dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL);
1539 dh_tmp_export=(c->dh_tmp_cb != NULL ||
1540 (dh_tmp && DH_size(c->dh_tmp)*8 <= kl));
1541#else
1542 dh_tmp=dh_tmp_export=0;
1543#endif
1544
1545 cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);
1546 rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL);
1547 rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1548 cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]);
1549 rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1550 cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]);
1551 dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1552 cpk= &(c->pkeys[SSL_PKEY_DH_RSA]);
1553 dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1554 dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1555 cpk= &(c->pkeys[SSL_PKEY_DH_DSA]);
1556/* FIX THIS EAY EAY EAY */
1557 dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1558 dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1559
1560 mask=0;
1561 emask=0;
1562
1563#ifdef CIPHER_DEBUG
1564 printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n",
1565 rsa_tmp,rsa_tmp_export,dh_tmp,
1566 rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa);
1567#endif
1568
1569 if (rsa_enc || (rsa_tmp && rsa_sign))
1570 mask|=SSL_kRSA;
1571 if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc)))
1572 emask|=SSL_kRSA;
1573
1574#if 0
1575 /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */
1576 if ( (dh_tmp || dh_rsa || dh_dsa) &&
1577 (rsa_enc || rsa_sign || dsa_sign))
1578 mask|=SSL_kEDH;
1579 if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&
1580 (rsa_enc || rsa_sign || dsa_sign))
1581 emask|=SSL_kEDH;
1582#endif
1583
1584 if (dh_tmp_export)
1585 emask|=SSL_kEDH;
1586
1587 if (dh_tmp)
1588 mask|=SSL_kEDH;
1589
1590 if (dh_rsa) mask|=SSL_kDHr;
1591 if (dh_rsa_export) emask|=SSL_kDHr;
1592
1593 if (dh_dsa) mask|=SSL_kDHd;
1594 if (dh_dsa_export) emask|=SSL_kDHd;
1595
1596 if (rsa_enc || rsa_sign)
1597 {
1598 mask|=SSL_aRSA;
1599 emask|=SSL_aRSA;
1600 }
1601
1602 if (dsa_sign)
1603 {
1604 mask|=SSL_aDSS;
1605 emask|=SSL_aDSS;
1606 }
1607
1608 mask|=SSL_aNULL;
1609 emask|=SSL_aNULL;
1610
1611#ifndef OPENSSL_NO_KRB5
1612 mask|=SSL_kKRB5|SSL_aKRB5;
1613 emask|=SSL_kKRB5|SSL_aKRB5;
1614#endif
1615
1616 c->mask=mask;
1617 c->export_mask=emask;
1618 c->valid=1;
1619 }
1620
1621/* THIS NEEDS CLEANING UP */
1622X509 *ssl_get_server_send_cert(SSL *s)
1623 {
1624 unsigned long alg,mask,kalg;
1625 CERT *c;
1626 int i,is_export;
1627
1628 c=s->cert;
1629 ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
1630 alg=s->s3->tmp.new_cipher->algorithms;
1631 is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
1632 mask=is_export?c->export_mask:c->mask;
1633 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1634
1635 if (kalg & SSL_kDHr)
1636 i=SSL_PKEY_DH_RSA;
1637 else if (kalg & SSL_kDHd)
1638 i=SSL_PKEY_DH_DSA;
1639 else if (kalg & SSL_aDSS)
1640 i=SSL_PKEY_DSA_SIGN;
1641 else if (kalg & SSL_aRSA)
1642 {
1643 if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
1644 i=SSL_PKEY_RSA_SIGN;
1645 else
1646 i=SSL_PKEY_RSA_ENC;
1647 }
1648 else if (kalg & SSL_aKRB5)
1649 {
1650 /* VRS something else here? */
1651 return(NULL);
1652 }
1653 else /* if (kalg & SSL_aNULL) */
1654 {
1655 SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR);
1656 return(NULL);
1657 }
1658 if (c->pkeys[i].x509 == NULL) return(NULL);
1659 return(c->pkeys[i].x509);
1660 }
1661
1662EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher)
1663 {
1664 unsigned long alg;
1665 CERT *c;
1666
1667 alg=cipher->algorithms;
1668 c=s->cert;
1669
1670 if ((alg & SSL_aDSS) &&
1671 (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
1672 return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey);
1673 else if (alg & SSL_aRSA)
1674 {
1675 if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
1676 return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey);
1677 else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL)
1678 return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey);
1679 else
1680 return(NULL);
1681 }
1682 else /* if (alg & SSL_aNULL) */
1683 {
1684 SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR);
1685 return(NULL);
1686 }
1687 }
1688
1689void ssl_update_cache(SSL *s,int mode)
1690 {
1691 int i;
1692
1693 /* If the session_id_length is 0, we are not supposed to cache it,
1694 * and it would be rather hard to do anyway :-) */
1695 if (s->session->session_id_length == 0) return;
1696
1697 i=s->ctx->session_cache_mode;
1698 if ((i & mode) && (!s->hit)
1699 && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE)
1700 || SSL_CTX_add_session(s->ctx,s->session))
1701 && (s->ctx->new_session_cb != NULL))
1702 {
1703 CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);
1704 if (!s->ctx->new_session_cb(s,s->session))
1705 SSL_SESSION_free(s->session);
1706 }
1707
1708 /* auto flush every 255 connections */
1709 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&
1710 ((i & mode) == mode))
1711 {
1712 if ( (((mode & SSL_SESS_CACHE_CLIENT)
1713 ?s->ctx->stats.sess_connect_good
1714 :s->ctx->stats.sess_accept_good) & 0xff) == 0xff)
1715 {
1716 SSL_CTX_flush_sessions(s->ctx,(unsigned long)time(NULL));
1717 }
1718 }
1719 }
1720
1721SSL_METHOD *SSL_get_ssl_method(SSL *s)
1722 {
1723 return(s->method);
1724 }
1725
1726int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth)
1727 {
1728 int conn= -1;
1729 int ret=1;
1730
1731 if (s->method != meth)
1732 {
1733 if (s->handshake_func != NULL)
1734 conn=(s->handshake_func == s->method->ssl_connect);
1735
1736 if (s->method->version == meth->version)
1737 s->method=meth;
1738 else
1739 {
1740 s->method->ssl_free(s);
1741 s->method=meth;
1742 ret=s->method->ssl_new(s);
1743 }
1744
1745 if (conn == 1)
1746 s->handshake_func=meth->ssl_connect;
1747 else if (conn == 0)
1748 s->handshake_func=meth->ssl_accept;
1749 }
1750 return(ret);
1751 }
1752
1753int SSL_get_error(const SSL *s,int i)
1754 {
1755 int reason;
1756 unsigned long l;
1757 BIO *bio;
1758
1759 if (i > 0) return(SSL_ERROR_NONE);
1760
1761 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
1762 * etc, where we do encode the error */
1763 if ((l=ERR_peek_error()) != 0)
1764 {
1765 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
1766 return(SSL_ERROR_SYSCALL);
1767 else
1768 return(SSL_ERROR_SSL);
1769 }
1770
1771 if ((i < 0) && SSL_want_read(s))
1772 {
1773 bio=SSL_get_rbio(s);
1774 if (BIO_should_read(bio))
1775 return(SSL_ERROR_WANT_READ);
1776 else if (BIO_should_write(bio))
1777 /* This one doesn't make too much sense ... We never try
1778 * to write to the rbio, and an application program where
1779 * rbio and wbio are separate couldn't even know what it
1780 * should wait for.
1781 * However if we ever set s->rwstate incorrectly
1782 * (so that we have SSL_want_read(s) instead of
1783 * SSL_want_write(s)) and rbio and wbio *are* the same,
1784 * this test works around that bug; so it might be safer
1785 * to keep it. */
1786 return(SSL_ERROR_WANT_WRITE);
1787 else if (BIO_should_io_special(bio))
1788 {
1789 reason=BIO_get_retry_reason(bio);
1790 if (reason == BIO_RR_CONNECT)
1791 return(SSL_ERROR_WANT_CONNECT);
1792 else if (reason == BIO_RR_ACCEPT)
1793 return(SSL_ERROR_WANT_ACCEPT);
1794 else
1795 return(SSL_ERROR_SYSCALL); /* unknown */
1796 }
1797 }
1798
1799 if ((i < 0) && SSL_want_write(s))
1800 {
1801 bio=SSL_get_wbio(s);
1802 if (BIO_should_write(bio))
1803 return(SSL_ERROR_WANT_WRITE);
1804 else if (BIO_should_read(bio))
1805 /* See above (SSL_want_read(s) with BIO_should_write(bio)) */
1806 return(SSL_ERROR_WANT_READ);
1807 else if (BIO_should_io_special(bio))
1808 {
1809 reason=BIO_get_retry_reason(bio);
1810 if (reason == BIO_RR_CONNECT)
1811 return(SSL_ERROR_WANT_CONNECT);
1812 else if (reason == BIO_RR_ACCEPT)
1813 return(SSL_ERROR_WANT_ACCEPT);
1814 else
1815 return(SSL_ERROR_SYSCALL);
1816 }
1817 }
1818 if ((i < 0) && SSL_want_x509_lookup(s))
1819 {
1820 return(SSL_ERROR_WANT_X509_LOOKUP);
1821 }
1822
1823 if (i == 0)
1824 {
1825 if (s->version == SSL2_VERSION)
1826 {
1827 /* assume it is the socket being closed */
1828 return(SSL_ERROR_ZERO_RETURN);
1829 }
1830 else
1831 {
1832 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
1833 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
1834 return(SSL_ERROR_ZERO_RETURN);
1835 }
1836 }
1837 return(SSL_ERROR_SYSCALL);
1838 }
1839
1840int SSL_do_handshake(SSL *s)
1841 {
1842 int ret=1;
1843
1844 if (s->handshake_func == NULL)
1845 {
1846 SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET);
1847 return(-1);
1848 }
1849
1850 s->method->ssl_renegotiate_check(s);
1851
1852 if (SSL_in_init(s) || SSL_in_before(s))
1853 {
1854 ret=s->handshake_func(s);
1855 }
1856 return(ret);
1857 }
1858
1859/* For the next 2 functions, SSL_clear() sets shutdown and so
1860 * one of these calls will reset it */
1861void SSL_set_accept_state(SSL *s)
1862 {
1863 s->server=1;
1864 s->shutdown=0;
1865 s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE;
1866 s->handshake_func=s->method->ssl_accept;
1867 /* clear the current cipher */
1868 ssl_clear_cipher_ctx(s);
1869 }
1870
1871void SSL_set_connect_state(SSL *s)
1872 {
1873 s->server=0;
1874 s->shutdown=0;
1875 s->state=SSL_ST_CONNECT|SSL_ST_BEFORE;
1876 s->handshake_func=s->method->ssl_connect;
1877 /* clear the current cipher */
1878 ssl_clear_cipher_ctx(s);
1879 }
1880
1881int ssl_undefined_function(SSL *s)
1882 {
1883 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1884 return(0);
1885 }
1886
1887int ssl_undefined_const_function(const SSL *s)
1888 {
1889 SSLerr(SSL_F_SSL_UNDEFINED_CONST_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1890 return(0);
1891 }
1892
1893SSL_METHOD *ssl_bad_method(int ver)
1894 {
1895 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1896 return(NULL);
1897 }
1898
1899const char *SSL_get_version(const SSL *s)
1900 {
1901 if (s->version == TLS1_VERSION)
1902 return("TLSv1");
1903 else if (s->version == SSL3_VERSION)
1904 return("SSLv3");
1905 else if (s->version == SSL2_VERSION)
1906 return("SSLv2");
1907 else
1908 return("unknown");
1909 }
1910
1911SSL *SSL_dup(SSL *s)
1912 {
1913 STACK_OF(X509_NAME) *sk;
1914 X509_NAME *xn;
1915 SSL *ret;
1916 int i;
1917
1918 if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL)
1919 return(NULL);
1920
1921 ret->version = s->version;
1922 ret->type = s->type;
1923 ret->method = s->method;
1924
1925 if (s->session != NULL)
1926 {
1927 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
1928 SSL_copy_session_id(ret,s);
1929 }
1930 else
1931 {
1932 /* No session has been established yet, so we have to expect
1933 * that s->cert or ret->cert will be changed later --
1934 * they should not both point to the same object,
1935 * and thus we can't use SSL_copy_session_id. */
1936
1937 ret->method->ssl_free(ret);
1938 ret->method = s->method;
1939 ret->method->ssl_new(ret);
1940
1941 if (s->cert != NULL)
1942 {
1943 if (ret->cert != NULL)
1944 {
1945 ssl_cert_free(ret->cert);
1946 }
1947 ret->cert = ssl_cert_dup(s->cert);
1948 if (ret->cert == NULL)
1949 goto err;
1950 }
1951
1952 SSL_set_session_id_context(ret,
1953 s->sid_ctx, s->sid_ctx_length);
1954 }
1955
1956 ret->options=s->options;
1957 ret->mode=s->mode;
1958 SSL_set_max_cert_list(ret,SSL_get_max_cert_list(s));
1959 SSL_set_read_ahead(ret,SSL_get_read_ahead(s));
1960 ret->msg_callback = s->msg_callback;
1961 ret->msg_callback_arg = s->msg_callback_arg;
1962 SSL_set_verify(ret,SSL_get_verify_mode(s),
1963 SSL_get_verify_callback(s));
1964 SSL_set_verify_depth(ret,SSL_get_verify_depth(s));
1965 ret->generate_session_id = s->generate_session_id;
1966
1967 SSL_set_info_callback(ret,SSL_get_info_callback(s));
1968
1969 ret->debug=s->debug;
1970
1971 /* copy app data, a little dangerous perhaps */
1972 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL, &ret->ex_data, &s->ex_data))
1973 goto err;
1974
1975 /* setup rbio, and wbio */
1976 if (s->rbio != NULL)
1977 {
1978 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
1979 goto err;
1980 }
1981 if (s->wbio != NULL)
1982 {
1983 if (s->wbio != s->rbio)
1984 {
1985 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
1986 goto err;
1987 }
1988 else
1989 ret->wbio=ret->rbio;
1990 }
1991 ret->rwstate = s->rwstate;
1992 ret->in_handshake = s->in_handshake;
1993 ret->handshake_func = s->handshake_func;
1994 ret->server = s->server;
1995 ret->new_session = s->new_session;
1996 ret->quiet_shutdown = s->quiet_shutdown;
1997 ret->shutdown=s->shutdown;
1998 ret->state=s->state; /* SSL_dup does not really work at any state, though */
1999 ret->rstate=s->rstate;
2000 ret->init_num = 0; /* would have to copy ret->init_buf, ret->init_msg, ret->init_num, ret->init_off */
2001 ret->hit=s->hit;
2002 ret->purpose=s->purpose;
2003 ret->trust=s->trust;
2004
2005 /* dup the cipher_list and cipher_list_by_id stacks */
2006 if (s->cipher_list != NULL)
2007 {
2008 if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
2009 goto err;
2010 }
2011 if (s->cipher_list_by_id != NULL)
2012 if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id))
2013 == NULL)
2014 goto err;
2015
2016 /* Dup the client_CA list */
2017 if (s->client_CA != NULL)
2018 {
2019 if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;
2020 ret->client_CA=sk;
2021 for (i=0; i<sk_X509_NAME_num(sk); i++)
2022 {
2023 xn=sk_X509_NAME_value(sk,i);
2024 if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL)
2025 {
2026 X509_NAME_free(xn);
2027 goto err;
2028 }
2029 }
2030 }
2031
2032 if (0)
2033 {
2034err:
2035 if (ret != NULL) SSL_free(ret);
2036 ret=NULL;
2037 }
2038 return(ret);
2039 }
2040
2041void ssl_clear_cipher_ctx(SSL *s)
2042 {
2043 if (s->enc_read_ctx != NULL)
2044 {
2045 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
2046 OPENSSL_free(s->enc_read_ctx);
2047 s->enc_read_ctx=NULL;
2048 }
2049 if (s->enc_write_ctx != NULL)
2050 {
2051 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
2052 OPENSSL_free(s->enc_write_ctx);
2053 s->enc_write_ctx=NULL;
2054 }
2055 if (s->expand != NULL)
2056 {
2057 COMP_CTX_free(s->expand);
2058 s->expand=NULL;
2059 }
2060 if (s->compress != NULL)
2061 {
2062 COMP_CTX_free(s->compress);
2063 s->compress=NULL;
2064 }
2065 }
2066
2067/* Fix this function so that it takes an optional type parameter */
2068X509 *SSL_get_certificate(const SSL *s)
2069 {
2070 if (s->cert != NULL)
2071 return(s->cert->key->x509);
2072 else
2073 return(NULL);
2074 }
2075
2076/* Fix this function so that it takes an optional type parameter */
2077EVP_PKEY *SSL_get_privatekey(SSL *s)
2078 {
2079 if (s->cert != NULL)
2080 return(s->cert->key->privatekey);
2081 else
2082 return(NULL);
2083 }
2084
2085SSL_CIPHER *SSL_get_current_cipher(const SSL *s)
2086 {
2087 if ((s->session != NULL) && (s->session->cipher != NULL))
2088 return(s->session->cipher);
2089 return(NULL);
2090 }
2091
2092int ssl_init_wbio_buffer(SSL *s,int push)
2093 {
2094 BIO *bbio;
2095
2096 if (s->bbio == NULL)
2097 {
2098 bbio=BIO_new(BIO_f_buffer());
2099 if (bbio == NULL) return(0);
2100 s->bbio=bbio;
2101 }
2102 else
2103 {
2104 bbio=s->bbio;
2105 if (s->bbio == s->wbio)
2106 s->wbio=BIO_pop(s->wbio);
2107 }
2108 (void)BIO_reset(bbio);
2109/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
2110 if (!BIO_set_read_buffer_size(bbio,1))
2111 {
2112 SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB);
2113 return(0);
2114 }
2115 if (push)
2116 {
2117 if (s->wbio != bbio)
2118 s->wbio=BIO_push(bbio,s->wbio);
2119 }
2120 else
2121 {
2122 if (s->wbio == bbio)
2123 s->wbio=BIO_pop(bbio);
2124 }
2125 return(1);
2126 }
2127
2128void ssl_free_wbio_buffer(SSL *s)
2129 {
2130 if (s->bbio == NULL) return;
2131
2132 if (s->bbio == s->wbio)
2133 {
2134 /* remove buffering */
2135 s->wbio=BIO_pop(s->wbio);
2136#ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */
2137 assert(s->wbio != NULL);
2138#endif
2139 }
2140 BIO_free(s->bbio);
2141 s->bbio=NULL;
2142 }
2143
2144void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
2145 {
2146 ctx->quiet_shutdown=mode;
2147 }
2148
2149int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx)
2150 {
2151 return(ctx->quiet_shutdown);
2152 }
2153
2154void SSL_set_quiet_shutdown(SSL *s,int mode)
2155 {
2156 s->quiet_shutdown=mode;
2157 }
2158
2159int SSL_get_quiet_shutdown(const SSL *s)
2160 {
2161 return(s->quiet_shutdown);
2162 }
2163
2164void SSL_set_shutdown(SSL *s,int mode)
2165 {
2166 s->shutdown=mode;
2167 }
2168
2169int SSL_get_shutdown(const SSL *s)
2170 {
2171 return(s->shutdown);
2172 }
2173
2174int SSL_version(const SSL *s)
2175 {
2176 return(s->version);
2177 }
2178
2179SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl)
2180 {
2181 return(ssl->ctx);
2182 }
2183
2184#ifndef OPENSSL_NO_STDIO
2185int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
2186 {
2187 return(X509_STORE_set_default_paths(ctx->cert_store));
2188 }
2189
2190int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
2191 const char *CApath)
2192 {
2193 int r;
2194 r=X509_STORE_load_locations(ctx->cert_store,CAfile,CApath);
2195 return r;
2196 }
2197#endif
2198
2199void SSL_set_info_callback(SSL *ssl,
2200 void (*cb)(const SSL *ssl,int type,int val))
2201 {
2202 ssl->info_callback=cb;
2203 }
2204
2205void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val)
2206 {
2207 return ssl->info_callback;
2208 }
2209
2210int SSL_state(const SSL *ssl)
2211 {
2212 return(ssl->state);
2213 }
2214
2215void SSL_set_verify_result(SSL *ssl,long arg)
2216 {
2217 ssl->verify_result=arg;
2218 }
2219
2220long SSL_get_verify_result(const SSL *ssl)
2221 {
2222 return(ssl->verify_result);
2223 }
2224
2225int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
2226 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
2227 {
2228 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, argl, argp,
2229 new_func, dup_func, free_func);
2230 }
2231
2232int SSL_set_ex_data(SSL *s,int idx,void *arg)
2233 {
2234 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
2235 }
2236
2237void *SSL_get_ex_data(const SSL *s,int idx)
2238 {
2239 return(CRYPTO_get_ex_data(&s->ex_data,idx));
2240 }
2241
2242int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
2243 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
2244 {
2245 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, argl, argp,
2246 new_func, dup_func, free_func);
2247 }
2248
2249int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg)
2250 {
2251 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
2252 }
2253
2254void *SSL_CTX_get_ex_data(const SSL_CTX *s,int idx)
2255 {
2256 return(CRYPTO_get_ex_data(&s->ex_data,idx));
2257 }
2258
2259int ssl_ok(SSL *s)
2260 {
2261 return(1);
2262 }
2263
2264X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx)
2265 {
2266 return(ctx->cert_store);
2267 }
2268
2269void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store)
2270 {
2271 if (ctx->cert_store != NULL)
2272 X509_STORE_free(ctx->cert_store);
2273 ctx->cert_store=store;
2274 }
2275
2276int SSL_want(const SSL *s)
2277 {
2278 return(s->rwstate);
2279 }
2280
2281/*!
2282 * \brief Set the callback for generating temporary RSA keys.
2283 * \param ctx the SSL context.
2284 * \param cb the callback
2285 */
2286
2287#ifndef OPENSSL_NO_RSA
2288void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl,
2289 int is_export,
2290 int keylength))
2291 {
2292 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2293 }
2294
2295void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl,
2296 int is_export,
2297 int keylength))
2298 {
2299 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2300 }
2301#endif
2302
2303#ifdef DOXYGEN
2304/*!
2305 * \brief The RSA temporary key callback function.
2306 * \param ssl the SSL session.
2307 * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite.
2308 * \param keylength if \c is_export is \c TRUE, then \c keylength is the size
2309 * of the required key in bits.
2310 * \return the temporary RSA key.
2311 * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback
2312 */
2313
2314RSA *cb(SSL *ssl,int is_export,int keylength)
2315 {}
2316#endif
2317
2318/*!
2319 * \brief Set the callback for generating temporary DH keys.
2320 * \param ctx the SSL context.
2321 * \param dh the callback
2322 */
2323
2324#ifndef OPENSSL_NO_DH
2325void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export,
2326 int keylength))
2327 {
2328 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2329 }
2330
2331void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export,
2332 int keylength))
2333 {
2334 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2335 }
2336#endif
2337
2338
2339void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
2340 {
2341 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb);
2342 }
2343void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
2344 {
2345 SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb);
2346 }
2347
2348
2349
2350#if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16)
2351#include "../crypto/bio/bss_file.c"
2352#endif
2353
2354IMPLEMENT_STACK_OF(SSL_CIPHER)
2355IMPLEMENT_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 6a0b7595f4..0000000000
--- a/src/lib/libssl/ssl_locl.h
+++ /dev/null
@@ -1,623 +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 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_SSL_LOCL_H
113#define HEADER_SSL_LOCL_H
114#include <stdlib.h>
115#include <time.h>
116#include <string.h>
117#include <errno.h>
118
119#include "e_os.h"
120
121#include <openssl/buffer.h>
122#include <openssl/comp.h>
123#include <openssl/bio.h>
124#include <openssl/crypto.h>
125#include <openssl/evp.h>
126#include <openssl/stack.h>
127#include <openssl/x509.h>
128#include <openssl/err.h>
129#include <openssl/ssl.h>
130#include <openssl/symhacks.h>
131
132#ifdef OPENSSL_BUILD_SHLIBSSL
133# undef OPENSSL_EXTERN
134# define OPENSSL_EXTERN OPENSSL_EXPORT
135#endif
136
137#define PKCS1_CHECK
138
139#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
140 l|=(((unsigned long)(*((c)++)))<< 8), \
141 l|=(((unsigned long)(*((c)++)))<<16), \
142 l|=(((unsigned long)(*((c)++)))<<24))
143
144/* NOTE - c is not incremented as per c2l */
145#define c2ln(c,l1,l2,n) { \
146 c+=n; \
147 l1=l2=0; \
148 switch (n) { \
149 case 8: l2 =((unsigned long)(*(--(c))))<<24; \
150 case 7: l2|=((unsigned long)(*(--(c))))<<16; \
151 case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
152 case 5: l2|=((unsigned long)(*(--(c)))); \
153 case 4: l1 =((unsigned long)(*(--(c))))<<24; \
154 case 3: l1|=((unsigned long)(*(--(c))))<<16; \
155 case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
156 case 1: l1|=((unsigned long)(*(--(c)))); \
157 } \
158 }
159
160#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
161 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
162 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
163 *((c)++)=(unsigned char)(((l)>>24)&0xff))
164
165#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \
166 l|=((unsigned long)(*((c)++)))<<16, \
167 l|=((unsigned long)(*((c)++)))<< 8, \
168 l|=((unsigned long)(*((c)++))))
169
170#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
171 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
172 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
173 *((c)++)=(unsigned char)(((l) )&0xff))
174
175/* NOTE - c is not incremented as per l2c */
176#define l2cn(l1,l2,c,n) { \
177 c+=n; \
178 switch (n) { \
179 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
180 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
181 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
182 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
183 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
184 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
185 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
186 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
187 } \
188 }
189
190#define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \
191 (((unsigned int)(c[1])) )),c+=2)
192#define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \
193 c[1]=(unsigned char)(((s) )&0xff)),c+=2)
194
195#define n2l3(c,l) ((l =(((unsigned long)(c[0]))<<16)| \
196 (((unsigned long)(c[1]))<< 8)| \
197 (((unsigned long)(c[2])) )),c+=3)
198
199#define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \
200 c[1]=(unsigned char)(((l)>> 8)&0xff), \
201 c[2]=(unsigned char)(((l) )&0xff)),c+=3)
202
203/* LOCAL STUFF */
204
205#define SSL_DECRYPT 0
206#define SSL_ENCRYPT 1
207
208#define TWO_BYTE_BIT 0x80
209#define SEC_ESC_BIT 0x40
210#define TWO_BYTE_MASK 0x7fff
211#define THREE_BYTE_MASK 0x3fff
212
213#define INC32(a) ((a)=((a)+1)&0xffffffffL)
214#define DEC32(a) ((a)=((a)-1)&0xffffffffL)
215#define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */
216
217/*
218 * Define the Bitmasks for SSL_CIPHER.algorithms.
219 * This bits are used packed as dense as possible. If new methods/ciphers
220 * etc will be added, the bits a likely to change, so this information
221 * is for internal library use only, even though SSL_CIPHER.algorithms
222 * can be publicly accessed.
223 * Use the according functions for cipher management instead.
224 *
225 * The bit mask handling in the selection and sorting scheme in
226 * ssl_create_cipher_list() has only limited capabilities, reflecting
227 * that the different entities within are mutually exclusive:
228 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
229 */
230#define SSL_MKEY_MASK 0x0000003FL
231#define SSL_kRSA 0x00000001L /* RSA key exchange */
232#define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */
233#define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */
234#define SSL_kFZA 0x00000008L
235#define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */
236#define SSL_kKRB5 0x00000020L /* Kerberos5 key exchange */
237#define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL))
238
239#define SSL_AUTH_MASK 0x00000FC0L
240#define SSL_aRSA 0x00000040L /* Authenticate with RSA */
241#define SSL_aDSS 0x00000080L /* Authenticate with DSS */
242#define SSL_DSS SSL_aDSS
243#define SSL_aFZA 0x00000100L
244#define SSL_aNULL 0x00000200L /* no Authenticate, ADH */
245#define SSL_aDH 0x00000400L /* no Authenticate, ADH */
246#define SSL_aKRB5 0x00000800L /* Authenticate with KRB5 */
247
248#define SSL_NULL (SSL_eNULL)
249#define SSL_ADH (SSL_kEDH|SSL_aNULL)
250#define SSL_RSA (SSL_kRSA|SSL_aRSA)
251#define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH)
252#define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA)
253#define SSL_KRB5 (SSL_kKRB5|SSL_aKRB5)
254
255#define SSL_ENC_MASK 0x0087F000L
256#define SSL_DES 0x00001000L
257#define SSL_3DES 0x00002000L
258#define SSL_RC4 0x00004000L
259#define SSL_RC2 0x00008000L
260#define SSL_IDEA 0x00010000L
261#define SSL_eFZA 0x00020000L
262#define SSL_eNULL 0x00040000L
263#define SSL_AES 0x00800000L
264
265#define SSL_MAC_MASK 0x00180000L
266#define SSL_MD5 0x00080000L
267#define SSL_SHA1 0x00100000L
268#define SSL_SHA (SSL_SHA1)
269
270#define SSL_SSL_MASK 0x00600000L
271#define SSL_SSLV2 0x00200000L
272#define SSL_SSLV3 0x00400000L
273#define SSL_TLSV1 SSL_SSLV3 /* for now */
274
275/* we have used 007fffff - 9 bits left to go */
276
277/*
278 * Export and cipher strength information. For each cipher we have to decide
279 * whether it is exportable or not. This information is likely to change
280 * over time, since the export control rules are no static technical issue.
281 *
282 * Independent of the export flag the cipher strength is sorted into classes.
283 * SSL_EXP40 was denoting the 40bit US export limit of past times, which now
284 * is at 56bit (SSL_EXP56). If the exportable cipher class is going to change
285 * again (eg. to 64bit) the use of "SSL_EXP*" becomes blurred even more,
286 * since SSL_EXP64 could be similar to SSL_LOW.
287 * For this reason SSL_MICRO and SSL_MINI macros are included to widen the
288 * namespace of SSL_LOW-SSL_HIGH to lower values. As development of speed
289 * and ciphers goes, another extension to SSL_SUPER and/or SSL_ULTRA would
290 * be possible.
291 */
292#define SSL_EXP_MASK 0x00000003L
293#define SSL_NOT_EXP 0x00000001L
294#define SSL_EXPORT 0x00000002L
295
296#define SSL_STRONG_MASK 0x000000fcL
297#define SSL_STRONG_NONE 0x00000004L
298#define SSL_EXP40 0x00000008L
299#define SSL_MICRO (SSL_EXP40)
300#define SSL_EXP56 0x00000010L
301#define SSL_MINI (SSL_EXP56)
302#define SSL_LOW 0x00000020L
303#define SSL_MEDIUM 0x00000040L
304#define SSL_HIGH 0x00000080L
305#define SSL_FIPS 0x00000100L
306
307/* we have used 000001ff - 23 bits left to go */
308
309/*
310 * Macros to check the export status and cipher strength for export ciphers.
311 * Even though the macros for EXPORT and EXPORT40/56 have similar names,
312 * their meaning is different:
313 * *_EXPORT macros check the 'exportable' status.
314 * *_EXPORT40/56 macros are used to check whether a certain cipher strength
315 * is given.
316 * Since the SSL_IS_EXPORT* and SSL_EXPORT* macros depend on the correct
317 * algorithm structure element to be passed (algorithms, algo_strength) and no
318 * typechecking can be done as they are all of type unsigned long, their
319 * direct usage is discouraged.
320 * Use the SSL_C_* macros instead.
321 */
322#define SSL_IS_EXPORT(a) ((a)&SSL_EXPORT)
323#define SSL_IS_EXPORT56(a) ((a)&SSL_EXP56)
324#define SSL_IS_EXPORT40(a) ((a)&SSL_EXP40)
325#define SSL_C_IS_EXPORT(c) SSL_IS_EXPORT((c)->algo_strength)
326#define SSL_C_IS_EXPORT56(c) SSL_IS_EXPORT56((c)->algo_strength)
327#define SSL_C_IS_EXPORT40(c) SSL_IS_EXPORT40((c)->algo_strength)
328
329#define SSL_EXPORT_KEYLENGTH(a,s) (SSL_IS_EXPORT40(s) ? 5 : \
330 ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7)
331#define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024)
332#define SSL_C_EXPORT_KEYLENGTH(c) SSL_EXPORT_KEYLENGTH((c)->algorithms, \
333 (c)->algo_strength)
334#define SSL_C_EXPORT_PKEYLENGTH(c) SSL_EXPORT_PKEYLENGTH((c)->algo_strength)
335
336
337#define SSL_ALL 0xffffffffL
338#define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\
339 SSL_MAC_MASK)
340#define SSL_ALL_STRENGTHS (SSL_EXP_MASK|SSL_STRONG_MASK)
341
342/* Mostly for SSLv3 */
343#define SSL_PKEY_RSA_ENC 0
344#define SSL_PKEY_RSA_SIGN 1
345#define SSL_PKEY_DSA_SIGN 2
346#define SSL_PKEY_DH_RSA 3
347#define SSL_PKEY_DH_DSA 4
348#define SSL_PKEY_NUM 5
349
350/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
351 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
352 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
353 * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN
354 * SSL_aRSA <- RSA_ENC | RSA_SIGN
355 * SSL_aDSS <- DSA_SIGN
356 */
357
358/*
359#define CERT_INVALID 0
360#define CERT_PUBLIC_KEY 1
361#define CERT_PRIVATE_KEY 2
362*/
363
364typedef struct cert_pkey_st
365 {
366 X509 *x509;
367 EVP_PKEY *privatekey;
368 } CERT_PKEY;
369
370typedef struct cert_st
371 {
372 /* Current active set */
373 CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array
374 * Probably it would make more sense to store
375 * an index, not a pointer. */
376
377 /* The following masks are for the key and auth
378 * algorithms that are supported by the certs below */
379 int valid;
380 unsigned long mask;
381 unsigned long export_mask;
382#ifndef OPENSSL_NO_RSA
383 RSA *rsa_tmp;
384 RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize);
385#endif
386#ifndef OPENSSL_NO_DH
387 DH *dh_tmp;
388 DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize);
389#endif
390
391 CERT_PKEY pkeys[SSL_PKEY_NUM];
392
393 int references; /* >1 only if SSL_copy_session_id is used */
394 } CERT;
395
396
397typedef struct sess_cert_st
398 {
399 STACK_OF(X509) *cert_chain; /* as received from peer (not for SSL2) */
400
401 /* The 'peer_...' members are used only by clients. */
402 int peer_cert_type;
403
404 CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */
405 CERT_PKEY peer_pkeys[SSL_PKEY_NUM];
406 /* Obviously we don't have the private keys of these,
407 * so maybe we shouldn't even use the CERT_PKEY type here. */
408
409#ifndef OPENSSL_NO_RSA
410 RSA *peer_rsa_tmp; /* not used for SSL 2 */
411#endif
412#ifndef OPENSSL_NO_DH
413 DH *peer_dh_tmp; /* not used for SSL 2 */
414#endif
415
416 int references; /* actually always 1 at the moment */
417 } SESS_CERT;
418
419
420/*#define MAC_DEBUG */
421
422/*#define ERR_DEBUG */
423/*#define ABORT_DEBUG */
424/*#define PKT_DEBUG 1 */
425/*#define DES_DEBUG */
426/*#define DES_OFB_DEBUG */
427/*#define SSL_DEBUG */
428/*#define RSA_DEBUG */
429/*#define IDEA_DEBUG */
430
431#define FP_ICC (int (*)(const void *,const void *))
432#define ssl_put_cipher_by_char(ssl,ciph,ptr) \
433 ((ssl)->method->put_cipher_by_char((ciph),(ptr)))
434#define ssl_get_cipher_by_char(ssl,ptr) \
435 ((ssl)->method->get_cipher_by_char(ptr))
436
437/* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff
438 * It is a bit of a mess of functions, but hell, think of it as
439 * an opaque structure :-) */
440typedef struct ssl3_enc_method
441 {
442 int (*enc)(SSL *, int);
443 int (*mac)(SSL *, unsigned char *, int);
444 int (*setup_key_block)(SSL *);
445 int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *, int);
446 int (*change_cipher_state)(SSL *, int);
447 int (*final_finish_mac)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char *, int, unsigned char *);
448 int finish_mac_length;
449 int (*cert_verify_mac)(SSL *, EVP_MD_CTX *, unsigned char *);
450 const char *client_finished_label;
451 int client_finished_label_len;
452 const char *server_finished_label;
453 int server_finished_label_len;
454 int (*alert_value)(int);
455 } SSL3_ENC_METHOD;
456
457/* Used for holding the relevant compression methods loaded into SSL_CTX */
458typedef struct ssl3_comp_st
459 {
460 int comp_id; /* The identifier byte for this compression type */
461 char *name; /* Text name used for the compression type */
462 COMP_METHOD *method; /* The method :-) */
463 } SSL3_COMP;
464
465extern SSL3_ENC_METHOD ssl3_undef_enc_method;
466OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[];
467OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[];
468
469#ifdef OPENSSL_SYS_VMS
470#undef SSL_COMP_get_compression_methods
471#define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods
472#endif
473
474
475SSL_METHOD *ssl_bad_method(int ver);
476SSL_METHOD *sslv2_base_method(void);
477SSL_METHOD *sslv23_base_method(void);
478SSL_METHOD *sslv3_base_method(void);
479
480void ssl_clear_cipher_ctx(SSL *s);
481int ssl_clear_bad_session(SSL *s);
482CERT *ssl_cert_new(void);
483CERT *ssl_cert_dup(CERT *cert);
484int ssl_cert_inst(CERT **o);
485void ssl_cert_free(CERT *c);
486SESS_CERT *ssl_sess_cert_new(void);
487void ssl_sess_cert_free(SESS_CERT *sc);
488int ssl_set_peer_cert_type(SESS_CERT *c, int type);
489int ssl_get_new_session(SSL *s, int session);
490int ssl_get_prev_session(SSL *s, unsigned char *session,int len);
491int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);
492int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
493 const SSL_CIPHER * const *bp);
494STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
495 STACK_OF(SSL_CIPHER) **skp);
496int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,
497 int (*put_cb)(const SSL_CIPHER *, unsigned char *));
498STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
499 STACK_OF(SSL_CIPHER) **pref,
500 STACK_OF(SSL_CIPHER) **sorted,
501 const char *rule_str);
502void ssl_update_cache(SSL *s, int mode);
503int ssl_cipher_get_evp(const SSL_SESSION *s,const EVP_CIPHER **enc,
504 const EVP_MD **md,SSL_COMP **comp);
505int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);
506int ssl_undefined_function(SSL *s);
507int ssl_undefined_const_function(const SSL *s);
508X509 *ssl_get_server_send_cert(SSL *);
509EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
510int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
511void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher);
512STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
513int ssl_verify_alarm_type(long type);
514
515int ssl2_enc_init(SSL *s, int client);
516int ssl2_generate_key_material(SSL *s);
517void ssl2_enc(SSL *s,int send_data);
518void ssl2_mac(SSL *s,unsigned char *mac,int send_data);
519SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);
520int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
521int ssl2_part_read(SSL *s, unsigned long f, int i);
522int ssl2_do_write(SSL *s);
523int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data);
524void ssl2_return_error(SSL *s,int reason);
525void ssl2_write_error(SSL *s);
526int ssl2_num_ciphers(void);
527SSL_CIPHER *ssl2_get_cipher(unsigned int u);
528int ssl2_new(SSL *s);
529void ssl2_free(SSL *s);
530int ssl2_accept(SSL *s);
531int ssl2_connect(SSL *s);
532int ssl2_read(SSL *s, void *buf, int len);
533int ssl2_peek(SSL *s, void *buf, int len);
534int ssl2_write(SSL *s, const void *buf, int len);
535int ssl2_shutdown(SSL *s);
536void ssl2_clear(SSL *s);
537long ssl2_ctrl(SSL *s,int cmd, long larg, void *parg);
538long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg);
539long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)());
540long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
541int ssl2_pending(const SSL *s);
542
543SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
544int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
545void ssl3_init_finished_mac(SSL *s);
546int ssl3_send_server_certificate(SSL *s);
547int ssl3_get_finished(SSL *s,int state_a,int state_b);
548int ssl3_setup_key_block(SSL *s);
549int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b);
550int ssl3_change_cipher_state(SSL *s,int which);
551void ssl3_cleanup_key_block(SSL *s);
552int ssl3_do_write(SSL *s,int type);
553void ssl3_send_alert(SSL *s,int level, int desc);
554int ssl3_generate_master_secret(SSL *s, unsigned char *out,
555 unsigned char *p, int len);
556int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
557long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
558int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen);
559int ssl3_num_ciphers(void);
560SSL_CIPHER *ssl3_get_cipher(unsigned int u);
561int ssl3_renegotiate(SSL *ssl);
562int ssl3_renegotiate_check(SSL *ssl);
563int ssl3_dispatch_alert(SSL *s);
564int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
565int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
566int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2,
567 const char *sender, int slen,unsigned char *p);
568int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
569void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len);
570int ssl3_enc(SSL *s, int send_data);
571int ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
572unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
573SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *clnt,
574 STACK_OF(SSL_CIPHER) *srvr);
575int ssl3_setup_buffers(SSL *s);
576int ssl3_new(SSL *s);
577void ssl3_free(SSL *s);
578int ssl3_accept(SSL *s);
579int ssl3_connect(SSL *s);
580int ssl3_read(SSL *s, void *buf, int len);
581int ssl3_peek(SSL *s, void *buf, int len);
582int ssl3_write(SSL *s, const void *buf, int len);
583int ssl3_shutdown(SSL *s);
584void ssl3_clear(SSL *s);
585long ssl3_ctrl(SSL *s,int cmd, long larg, void *parg);
586long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg);
587long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)());
588long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
589int ssl3_pending(const SSL *s);
590
591int ssl23_accept(SSL *s);
592int ssl23_connect(SSL *s);
593int ssl23_read_bytes(SSL *s, int n);
594int ssl23_write_bytes(SSL *s);
595
596int tls1_new(SSL *s);
597void tls1_free(SSL *s);
598void tls1_clear(SSL *s);
599long tls1_ctrl(SSL *s,int cmd, long larg, void *parg);
600long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)());
601SSL_METHOD *tlsv1_base_method(void );
602
603int ssl_init_wbio_buffer(SSL *s, int push);
604void ssl_free_wbio_buffer(SSL *s);
605
606int tls1_change_cipher_state(SSL *s, int which);
607int tls1_setup_key_block(SSL *s);
608int tls1_enc(SSL *s, int snd);
609int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
610 const char *str, int slen, unsigned char *p);
611int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
612int tls1_mac(SSL *ssl, unsigned char *md, int snd);
613int tls1_generate_master_secret(SSL *s, unsigned char *out,
614 unsigned char *p, int len);
615int tls1_alert_code(int code);
616int ssl3_alert_code(int code);
617int ssl_ok(SSL *s);
618
619SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
620STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
621
622
623#endif
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
deleted file mode 100644
index fb0bd4d045..0000000000
--- a/src/lib/libssl/ssl_rsa.c
+++ /dev/null
@@ -1,817 +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 "ssl_locl.h"
61#include <openssl/bio.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pem.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 OPENSSL_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 OPENSSL_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 RSA_up_ref(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 OPENSSL_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 ERR_clear_error(); /* make sure no error from X509_check_private_key()
245 * is left if we have chosen to ignore it */
246 if (c->pkeys[i].privatekey != NULL)
247 EVP_PKEY_free(c->pkeys[i].privatekey);
248 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
249 c->pkeys[i].privatekey=pkey;
250 c->key= &(c->pkeys[i]);
251
252 c->valid=0;
253 return(1);
254 }
255
256#ifndef OPENSSL_NO_RSA
257#ifndef OPENSSL_NO_STDIO
258int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type)
259 {
260 int j,ret=0;
261 BIO *in;
262 RSA *rsa=NULL;
263
264 in=BIO_new(BIO_s_file_internal());
265 if (in == NULL)
266 {
267 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB);
268 goto end;
269 }
270
271 if (BIO_read_filename(in,file) <= 0)
272 {
273 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB);
274 goto end;
275 }
276 if (type == SSL_FILETYPE_ASN1)
277 {
278 j=ERR_R_ASN1_LIB;
279 rsa=d2i_RSAPrivateKey_bio(in,NULL);
280 }
281 else if (type == SSL_FILETYPE_PEM)
282 {
283 j=ERR_R_PEM_LIB;
284 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,
285 ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata);
286 }
287 else
288 {
289 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
290 goto end;
291 }
292 if (rsa == NULL)
293 {
294 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,j);
295 goto end;
296 }
297 ret=SSL_use_RSAPrivateKey(ssl,rsa);
298 RSA_free(rsa);
299end:
300 if (in != NULL) BIO_free(in);
301 return(ret);
302 }
303#endif
304
305int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len)
306 {
307 int ret;
308 const unsigned char *p;
309 RSA *rsa;
310
311 p=d;
312 if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL)
313 {
314 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
315 return(0);
316 }
317
318 ret=SSL_use_RSAPrivateKey(ssl,rsa);
319 RSA_free(rsa);
320 return(ret);
321 }
322#endif /* !OPENSSL_NO_RSA */
323
324int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey)
325 {
326 int ret;
327
328 if (pkey == NULL)
329 {
330 SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
331 return(0);
332 }
333 if (!ssl_cert_inst(&ssl->cert))
334 {
335 SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE);
336 return(0);
337 }
338 ret=ssl_set_pkey(ssl->cert,pkey);
339 return(ret);
340 }
341
342#ifndef OPENSSL_NO_STDIO
343int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type)
344 {
345 int j,ret=0;
346 BIO *in;
347 EVP_PKEY *pkey=NULL;
348
349 in=BIO_new(BIO_s_file_internal());
350 if (in == NULL)
351 {
352 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB);
353 goto end;
354 }
355
356 if (BIO_read_filename(in,file) <= 0)
357 {
358 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB);
359 goto end;
360 }
361 if (type == SSL_FILETYPE_PEM)
362 {
363 j=ERR_R_PEM_LIB;
364 pkey=PEM_read_bio_PrivateKey(in,NULL,
365 ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata);
366 }
367 else
368 {
369 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
370 goto end;
371 }
372 if (pkey == NULL)
373 {
374 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,j);
375 goto end;
376 }
377 ret=SSL_use_PrivateKey(ssl,pkey);
378 EVP_PKEY_free(pkey);
379end:
380 if (in != NULL) BIO_free(in);
381 return(ret);
382 }
383#endif
384
385int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, unsigned char *d, long len)
386 {
387 int ret;
388 unsigned char *p;
389 EVP_PKEY *pkey;
390
391 p=d;
392 if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL)
393 {
394 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
395 return(0);
396 }
397
398 ret=SSL_use_PrivateKey(ssl,pkey);
399 EVP_PKEY_free(pkey);
400 return(ret);
401 }
402
403int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
404 {
405 if (x == NULL)
406 {
407 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER);
408 return(0);
409 }
410 if (!ssl_cert_inst(&ctx->cert))
411 {
412 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE);
413 return(0);
414 }
415 return(ssl_set_cert(ctx->cert, x));
416 }
417
418static int ssl_set_cert(CERT *c, X509 *x)
419 {
420 EVP_PKEY *pkey;
421 int i,ok=0,bad=0;
422
423 pkey=X509_get_pubkey(x);
424 if (pkey == NULL)
425 {
426 SSLerr(SSL_F_SSL_SET_CERT,SSL_R_X509_LIB);
427 return(0);
428 }
429
430 i=ssl_cert_type(x,pkey);
431 if (i < 0)
432 {
433 SSLerr(SSL_F_SSL_SET_CERT,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
434 EVP_PKEY_free(pkey);
435 return(0);
436 }
437
438 if (c->pkeys[i].privatekey != NULL)
439 {
440 EVP_PKEY_copy_parameters(pkey,c->pkeys[i].privatekey);
441 ERR_clear_error();
442
443#ifndef OPENSSL_NO_RSA
444 /* Don't check the public/private key, this is mostly
445 * for smart cards. */
446 if ((c->pkeys[i].privatekey->type == EVP_PKEY_RSA) &&
447 (RSA_flags(c->pkeys[i].privatekey->pkey.rsa) &
448 RSA_METHOD_FLAG_NO_CHECK))
449 ok=1;
450 else
451#endif
452 {
453 if (!X509_check_private_key(x,c->pkeys[i].privatekey))
454 {
455 if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
456 {
457 i=(i == SSL_PKEY_DH_RSA)?
458 SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
459
460 if (c->pkeys[i].privatekey == NULL)
461 ok=1;
462 else
463 {
464 if (!X509_check_private_key(x,
465 c->pkeys[i].privatekey))
466 bad=1;
467 else
468 ok=1;
469 }
470 }
471 else
472 bad=1;
473 }
474 else
475 ok=1;
476 } /* OPENSSL_NO_RSA */
477 }
478 else
479 ok=1;
480
481 EVP_PKEY_free(pkey);
482 if (bad)
483 {
484 EVP_PKEY_free(c->pkeys[i].privatekey);
485 c->pkeys[i].privatekey=NULL;
486 }
487
488 if (c->pkeys[i].x509 != NULL)
489 X509_free(c->pkeys[i].x509);
490 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
491 c->pkeys[i].x509=x;
492 c->key= &(c->pkeys[i]);
493
494 c->valid=0;
495 return(1);
496 }
497
498#ifndef OPENSSL_NO_STDIO
499int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
500 {
501 int j;
502 BIO *in;
503 int ret=0;
504 X509 *x=NULL;
505
506 in=BIO_new(BIO_s_file_internal());
507 if (in == NULL)
508 {
509 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB);
510 goto end;
511 }
512
513 if (BIO_read_filename(in,file) <= 0)
514 {
515 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB);
516 goto end;
517 }
518 if (type == SSL_FILETYPE_ASN1)
519 {
520 j=ERR_R_ASN1_LIB;
521 x=d2i_X509_bio(in,NULL);
522 }
523 else if (type == SSL_FILETYPE_PEM)
524 {
525 j=ERR_R_PEM_LIB;
526 x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
527 }
528 else
529 {
530 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE);
531 goto end;
532 }
533
534 if (x == NULL)
535 {
536 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,j);
537 goto end;
538 }
539
540 ret=SSL_CTX_use_certificate(ctx,x);
541end:
542 if (x != NULL) X509_free(x);
543 if (in != NULL) BIO_free(in);
544 return(ret);
545 }
546#endif
547
548int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d)
549 {
550 X509 *x;
551 int ret;
552
553 x=d2i_X509(NULL,&d,(long)len);
554 if (x == NULL)
555 {
556 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB);
557 return(0);
558 }
559
560 ret=SSL_CTX_use_certificate(ctx,x);
561 X509_free(x);
562 return(ret);
563 }
564
565#ifndef OPENSSL_NO_RSA
566int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa)
567 {
568 int ret;
569 EVP_PKEY *pkey;
570
571 if (rsa == NULL)
572 {
573 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
574 return(0);
575 }
576 if (!ssl_cert_inst(&ctx->cert))
577 {
578 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE);
579 return(0);
580 }
581 if ((pkey=EVP_PKEY_new()) == NULL)
582 {
583 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB);
584 return(0);
585 }
586
587 RSA_up_ref(rsa);
588 EVP_PKEY_assign_RSA(pkey,rsa);
589
590 ret=ssl_set_pkey(ctx->cert, pkey);
591 EVP_PKEY_free(pkey);
592 return(ret);
593 }
594
595#ifndef OPENSSL_NO_STDIO
596int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type)
597 {
598 int j,ret=0;
599 BIO *in;
600 RSA *rsa=NULL;
601
602 in=BIO_new(BIO_s_file_internal());
603 if (in == NULL)
604 {
605 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB);
606 goto end;
607 }
608
609 if (BIO_read_filename(in,file) <= 0)
610 {
611 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB);
612 goto end;
613 }
614 if (type == SSL_FILETYPE_ASN1)
615 {
616 j=ERR_R_ASN1_LIB;
617 rsa=d2i_RSAPrivateKey_bio(in,NULL);
618 }
619 else if (type == SSL_FILETYPE_PEM)
620 {
621 j=ERR_R_PEM_LIB;
622 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,
623 ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
624 }
625 else
626 {
627 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
628 goto end;
629 }
630 if (rsa == NULL)
631 {
632 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,j);
633 goto end;
634 }
635 ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa);
636 RSA_free(rsa);
637end:
638 if (in != NULL) BIO_free(in);
639 return(ret);
640 }
641#endif
642
643int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len)
644 {
645 int ret;
646 const unsigned char *p;
647 RSA *rsa;
648
649 p=d;
650 if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL)
651 {
652 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
653 return(0);
654 }
655
656 ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa);
657 RSA_free(rsa);
658 return(ret);
659 }
660#endif /* !OPENSSL_NO_RSA */
661
662int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
663 {
664 if (pkey == NULL)
665 {
666 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
667 return(0);
668 }
669 if (!ssl_cert_inst(&ctx->cert))
670 {
671 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE);
672 return(0);
673 }
674 return(ssl_set_pkey(ctx->cert,pkey));
675 }
676
677#ifndef OPENSSL_NO_STDIO
678int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
679 {
680 int j,ret=0;
681 BIO *in;
682 EVP_PKEY *pkey=NULL;
683
684 in=BIO_new(BIO_s_file_internal());
685 if (in == NULL)
686 {
687 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB);
688 goto end;
689 }
690
691 if (BIO_read_filename(in,file) <= 0)
692 {
693 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB);
694 goto end;
695 }
696 if (type == SSL_FILETYPE_PEM)
697 {
698 j=ERR_R_PEM_LIB;
699 pkey=PEM_read_bio_PrivateKey(in,NULL,
700 ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
701 }
702 else
703 {
704 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
705 goto end;
706 }
707 if (pkey == NULL)
708 {
709 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,j);
710 goto end;
711 }
712 ret=SSL_CTX_use_PrivateKey(ctx,pkey);
713 EVP_PKEY_free(pkey);
714end:
715 if (in != NULL) BIO_free(in);
716 return(ret);
717 }
718#endif
719
720int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, unsigned char *d,
721 long len)
722 {
723 int ret;
724 unsigned char *p;
725 EVP_PKEY *pkey;
726
727 p=d;
728 if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL)
729 {
730 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
731 return(0);
732 }
733
734 ret=SSL_CTX_use_PrivateKey(ctx,pkey);
735 EVP_PKEY_free(pkey);
736 return(ret);
737 }
738
739
740#ifndef OPENSSL_NO_STDIO
741/* Read a file that contains our certificate in "PEM" format,
742 * possibly followed by a sequence of CA certificates that should be
743 * sent to the peer in the Certificate message.
744 */
745int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file)
746 {
747 BIO *in;
748 int ret=0;
749 X509 *x=NULL;
750
751 in=BIO_new(BIO_s_file_internal());
752 if (in == NULL)
753 {
754 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_BUF_LIB);
755 goto end;
756 }
757
758 if (BIO_read_filename(in,file) <= 0)
759 {
760 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_SYS_LIB);
761 goto end;
762 }
763
764 x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
765 if (x == NULL)
766 {
767 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_PEM_LIB);
768 goto end;
769 }
770
771 ret=SSL_CTX_use_certificate(ctx,x);
772 if (ERR_peek_error() != 0)
773 ret = 0; /* Key/certificate mismatch doesn't imply ret==0 ... */
774 if (ret)
775 {
776 /* If we could set up our certificate, now proceed to
777 * the CA certificates.
778 */
779 X509 *ca;
780 int r;
781 unsigned long err;
782
783 if (ctx->extra_certs != NULL)
784 {
785 sk_X509_pop_free(ctx->extra_certs, X509_free);
786 ctx->extra_certs = NULL;
787 }
788
789 while ((ca = PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata))
790 != NULL)
791 {
792 r = SSL_CTX_add_extra_chain_cert(ctx, ca);
793 if (!r)
794 {
795 X509_free(ca);
796 ret = 0;
797 goto end;
798 }
799 /* Note that we must not free r if it was successfully
800 * added to the chain (while we must free the main
801 * certificate, since its reference count is increased
802 * by SSL_CTX_use_certificate). */
803 }
804 /* When the while loop ends, it's usually just EOF. */
805 err = ERR_peek_last_error();
806 if (ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE)
807 ERR_clear_error();
808 else
809 ret = 0; /* some real error */
810 }
811
812end:
813 if (x != NULL) X509_free(x);
814 if (in != NULL) BIO_free(in);
815 return(ret);
816 }
817#endif
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
deleted file mode 100644
index 2ba8b9612e..0000000000
--- a/src/lib/libssl/ssl_sess.c
+++ /dev/null
@@ -1,755 +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);
67
68SSL_SESSION *SSL_get_session(const SSL *ssl)
69/* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
70 {
71 return(ssl->session);
72 }
73
74SSL_SESSION *SSL_get1_session(SSL *ssl)
75/* variant of SSL_get_session: caller really gets something */
76 {
77 SSL_SESSION *sess;
78 /* Need to lock this all up rather than just use CRYPTO_add so that
79 * somebody doesn't free ssl->session between when we check it's
80 * non-null and when we up the reference count. */
81 CRYPTO_w_lock(CRYPTO_LOCK_SSL_SESSION);
82 sess = ssl->session;
83 if(sess)
84 sess->references++;
85 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_SESSION);
86 return(sess);
87 }
88
89int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
90 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
91 {
92 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, argl, argp,
93 new_func, dup_func, free_func);
94 }
95
96int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
97 {
98 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
99 }
100
101void *SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx)
102 {
103 return(CRYPTO_get_ex_data(&s->ex_data,idx));
104 }
105
106SSL_SESSION *SSL_SESSION_new(void)
107 {
108 SSL_SESSION *ss;
109
110 ss=(SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION));
111 if (ss == NULL)
112 {
113 SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);
114 return(0);
115 }
116 memset(ss,0,sizeof(SSL_SESSION));
117
118 ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
119 ss->references=1;
120 ss->timeout=60*5+4; /* 5 minute timeout by default */
121 ss->time=(unsigned long)time(NULL);
122 ss->prev=NULL;
123 ss->next=NULL;
124 ss->compress_meth=0;
125 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
126 return(ss);
127 }
128
129/* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1
130 * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly
131 * until we have no conflict is going to complete in one iteration pretty much
132 * "most" of the time (btw: understatement). So, if it takes us 10 iterations
133 * and we still can't avoid a conflict - well that's a reasonable point to call
134 * it quits. Either the RAND code is broken or someone is trying to open roughly
135 * very close to 2^128 (or 2^256) SSL sessions to our server. How you might
136 * store that many sessions is perhaps a more interesting question ... */
137
138#define MAX_SESS_ID_ATTEMPTS 10
139static int def_generate_session_id(const SSL *ssl, unsigned char *id,
140 unsigned int *id_len)
141{
142 unsigned int retry = 0;
143 do
144 if(RAND_pseudo_bytes(id, *id_len) <= 0)
145 return 0;
146 while(SSL_has_matching_session_id(ssl, id, *id_len) &&
147 (++retry < MAX_SESS_ID_ATTEMPTS));
148 if(retry < MAX_SESS_ID_ATTEMPTS)
149 return 1;
150 /* else - woops a session_id match */
151 /* XXX We should also check the external cache --
152 * but the probability of a collision is negligible, and
153 * we could not prevent the concurrent creation of sessions
154 * with identical IDs since we currently don't have means
155 * to atomically check whether a session ID already exists
156 * and make a reservation for it if it does not
157 * (this problem applies to the internal cache as well).
158 */
159 return 0;
160}
161
162int ssl_get_new_session(SSL *s, int session)
163 {
164 /* This gets used by clients and servers. */
165
166 unsigned int tmp;
167 SSL_SESSION *ss=NULL;
168 GEN_SESSION_CB cb = def_generate_session_id;
169
170 if ((ss=SSL_SESSION_new()) == NULL) return(0);
171
172 /* If the context has a default timeout, use it */
173 if (s->ctx->session_timeout == 0)
174 ss->timeout=SSL_get_default_timeout(s);
175 else
176 ss->timeout=s->ctx->session_timeout;
177
178 if (s->session != NULL)
179 {
180 SSL_SESSION_free(s->session);
181 s->session=NULL;
182 }
183
184 if (session)
185 {
186 if (s->version == SSL2_VERSION)
187 {
188 ss->ssl_version=SSL2_VERSION;
189 ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH;
190 }
191 else if (s->version == SSL3_VERSION)
192 {
193 ss->ssl_version=SSL3_VERSION;
194 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
195 }
196 else if (s->version == TLS1_VERSION)
197 {
198 ss->ssl_version=TLS1_VERSION;
199 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
200 }
201 else
202 {
203 SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION);
204 SSL_SESSION_free(ss);
205 return(0);
206 }
207 /* Choose which callback will set the session ID */
208 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
209 if(s->generate_session_id)
210 cb = s->generate_session_id;
211 else if(s->ctx->generate_session_id)
212 cb = s->ctx->generate_session_id;
213 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
214 /* Choose a session ID */
215 tmp = ss->session_id_length;
216 if(!cb(s, ss->session_id, &tmp))
217 {
218 /* The callback failed */
219 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
220 SSL_R_SSL_SESSION_ID_CALLBACK_FAILED);
221 SSL_SESSION_free(ss);
222 return(0);
223 }
224 /* Don't allow the callback to set the session length to zero.
225 * nor set it higher than it was. */
226 if(!tmp || (tmp > ss->session_id_length))
227 {
228 /* The callback set an illegal length */
229 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
230 SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH);
231 SSL_SESSION_free(ss);
232 return(0);
233 }
234 /* If the session length was shrunk and we're SSLv2, pad it */
235 if((tmp < ss->session_id_length) && (s->version == SSL2_VERSION))
236 memset(ss->session_id + tmp, 0, ss->session_id_length - tmp);
237 else
238 ss->session_id_length = tmp;
239 /* Finally, check for a conflict */
240 if(SSL_has_matching_session_id(s, ss->session_id,
241 ss->session_id_length))
242 {
243 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
244 SSL_R_SSL_SESSION_ID_CONFLICT);
245 SSL_SESSION_free(ss);
246 return(0);
247 }
248 }
249 else
250 {
251 ss->session_id_length=0;
252 }
253
254 if (s->sid_ctx_length > sizeof ss->sid_ctx)
255 {
256 SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR);
257 SSL_SESSION_free(ss);
258 return 0;
259 }
260 memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length);
261 ss->sid_ctx_length=s->sid_ctx_length;
262 s->session=ss;
263 ss->ssl_version=s->version;
264 ss->verify_result = X509_V_OK;
265
266 return(1);
267 }
268
269int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len)
270 {
271 /* This is used only by servers. */
272
273 SSL_SESSION *ret=NULL,data;
274 int fatal = 0;
275
276 data.ssl_version=s->version;
277 data.session_id_length=len;
278 if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
279 goto err;
280 memcpy(data.session_id,session_id,len);
281
282 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
283 {
284 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
285 ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data);
286 if (ret != NULL)
287 /* don't allow other threads to steal it: */
288 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
289 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
290 }
291
292 if (ret == NULL)
293 {
294 int copy=1;
295
296 s->ctx->stats.sess_miss++;
297 ret=NULL;
298 if (s->ctx->get_session_cb != NULL
299 && (ret=s->ctx->get_session_cb(s,session_id,len,&copy))
300 != NULL)
301 {
302 s->ctx->stats.sess_cb_hit++;
303
304 /* Increment reference count now if the session callback
305 * asks us to do so (note that if the session structures
306 * returned by the callback are shared between threads,
307 * it must handle the reference count itself [i.e. copy == 0],
308 * or things won't be thread-safe). */
309 if (copy)
310 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
311
312 /* Add the externally cached session to the internal
313 * cache as well if and only if we are supposed to. */
314 if(!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE))
315 /* The following should not return 1, otherwise,
316 * things are very strange */
317 SSL_CTX_add_session(s->ctx,ret);
318 }
319 if (ret == NULL)
320 goto err;
321 }
322
323 /* Now ret is non-NULL, and we own one of its reference counts. */
324
325 if((s->verify_mode&SSL_VERIFY_PEER)
326 && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length
327 || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length)))
328 {
329 /* We've found the session named by the client, but we don't
330 * want to use it in this context. */
331
332 if (s->sid_ctx_length == 0)
333 {
334 /* application should have used SSL[_CTX]_set_session_id_context
335 * -- we could tolerate this and just pretend we never heard
336 * of this session, but then applications could effectively
337 * disable the session cache by accident without anyone noticing */
338
339 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
340 fatal = 1;
341 goto err;
342 }
343 else
344 {
345#if 0 /* The client cannot always know when a session is not appropriate,
346 * so we shouldn't generate an error message. */
347
348 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
349#endif
350 goto err; /* treat like cache miss */
351 }
352 }
353
354 if (ret->cipher == NULL)
355 {
356 unsigned char buf[5],*p;
357 unsigned long l;
358
359 p=buf;
360 l=ret->cipher_id;
361 l2n(l,p);
362 if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR)
363 ret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));
364 else
365 ret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));
366 if (ret->cipher == NULL)
367 goto err;
368 }
369
370
371#if 0 /* This is way too late. */
372
373 /* If a thread got the session, then 'swaped', and another got
374 * it and then due to a time-out decided to 'OPENSSL_free' it we could
375 * be in trouble. So I'll increment it now, then double decrement
376 * later - am I speaking rubbish?. */
377 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
378#endif
379
380 if (ret->timeout < (long)(time(NULL) - ret->time)) /* timeout */
381 {
382 s->ctx->stats.sess_timeout++;
383 /* remove it from the cache */
384 SSL_CTX_remove_session(s->ctx,ret);
385 goto err;
386 }
387
388 s->ctx->stats.sess_hit++;
389
390 /* ret->time=time(NULL); */ /* rezero timeout? */
391 /* again, just leave the session
392 * if it is the same session, we have just incremented and
393 * then decremented the reference count :-) */
394 if (s->session != NULL)
395 SSL_SESSION_free(s->session);
396 s->session=ret;
397 s->verify_result = s->session->verify_result;
398 return(1);
399
400 err:
401 if (ret != NULL)
402 SSL_SESSION_free(ret);
403 if (fatal)
404 return -1;
405 else
406 return 0;
407 }
408
409int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
410 {
411 int ret=0;
412 SSL_SESSION *s;
413
414 /* add just 1 reference count for the SSL_CTX's session cache
415 * even though it has two ways of access: each session is in a
416 * doubly linked list and an lhash */
417 CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);
418 /* if session c is in already in cache, we take back the increment later */
419
420 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
421 s=(SSL_SESSION *)lh_insert(ctx->sessions,c);
422
423 /* s != NULL iff we already had a session with the given PID.
424 * In this case, s == c should hold (then we did not really modify
425 * ctx->sessions), or we're in trouble. */
426 if (s != NULL && s != c)
427 {
428 /* We *are* in trouble ... */
429 SSL_SESSION_list_remove(ctx,s);
430 SSL_SESSION_free(s);
431 /* ... so pretend the other session did not exist in cache
432 * (we cannot handle two SSL_SESSION structures with identical
433 * session ID in the same cache, which could happen e.g. when
434 * two threads concurrently obtain the same session from an external
435 * cache) */
436 s = NULL;
437 }
438
439 /* Put at the head of the queue unless it is already in the cache */
440 if (s == NULL)
441 SSL_SESSION_list_add(ctx,c);
442
443 if (s != NULL)
444 {
445 /* existing cache entry -- decrement previously incremented reference
446 * count because it already takes into account the cache */
447
448 SSL_SESSION_free(s); /* s == c */
449 ret=0;
450 }
451 else
452 {
453 /* new cache entry -- remove old ones if cache has become too large */
454
455 ret=1;
456
457 if (SSL_CTX_sess_get_cache_size(ctx) > 0)
458 {
459 while (SSL_CTX_sess_number(ctx) >
460 SSL_CTX_sess_get_cache_size(ctx))
461 {
462 if (!remove_session_lock(ctx,
463 ctx->session_cache_tail, 0))
464 break;
465 else
466 ctx->stats.sess_cache_full++;
467 }
468 }
469 }
470 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
471 return(ret);
472 }
473
474int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
475{
476 return remove_session_lock(ctx, c, 1);
477}
478
479static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
480 {
481 SSL_SESSION *r;
482 int ret=0;
483
484 if ((c != NULL) && (c->session_id_length != 0))
485 {
486 if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
487 if ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)
488 {
489 ret=1;
490 r=(SSL_SESSION *)lh_delete(ctx->sessions,c);
491 SSL_SESSION_list_remove(ctx,c);
492 }
493
494 if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
495
496 if (ret)
497 {
498 r->not_resumable=1;
499 if (ctx->remove_session_cb != NULL)
500 ctx->remove_session_cb(ctx,r);
501 SSL_SESSION_free(r);
502 }
503 }
504 else
505 ret=0;
506 return(ret);
507 }
508
509void SSL_SESSION_free(SSL_SESSION *ss)
510 {
511 int i;
512
513 if(ss == NULL)
514 return;
515
516 i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION);
517#ifdef REF_PRINT
518 REF_PRINT("SSL_SESSION",ss);
519#endif
520 if (i > 0) return;
521#ifdef REF_CHECK
522 if (i < 0)
523 {
524 fprintf(stderr,"SSL_SESSION_free, bad reference count\n");
525 abort(); /* ok */
526 }
527#endif
528
529 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
530
531 OPENSSL_cleanse(ss->key_arg,sizeof ss->key_arg);
532 OPENSSL_cleanse(ss->master_key,sizeof ss->master_key);
533 OPENSSL_cleanse(ss->session_id,sizeof ss->session_id);
534 if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert);
535 if (ss->peer != NULL) X509_free(ss->peer);
536 if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers);
537 OPENSSL_cleanse(ss,sizeof(*ss));
538 OPENSSL_free(ss);
539 }
540
541int SSL_set_session(SSL *s, SSL_SESSION *session)
542 {
543 int ret=0;
544 SSL_METHOD *meth;
545
546 if (session != NULL)
547 {
548 meth=s->ctx->method->get_ssl_method(session->ssl_version);
549 if (meth == NULL)
550 meth=s->method->get_ssl_method(session->ssl_version);
551 if (meth == NULL)
552 {
553 SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD);
554 return(0);
555 }
556
557 if (meth != s->method)
558 {
559 if (!SSL_set_ssl_method(s,meth))
560 return(0);
561 if (s->ctx->session_timeout == 0)
562 session->timeout=SSL_get_default_timeout(s);
563 else
564 session->timeout=s->ctx->session_timeout;
565 }
566
567#ifndef OPENSSL_NO_KRB5
568 if (s->kssl_ctx && !s->kssl_ctx->client_princ &&
569 session->krb5_client_princ_len > 0)
570 {
571 s->kssl_ctx->client_princ = (char *)malloc(session->krb5_client_princ_len + 1);
572 memcpy(s->kssl_ctx->client_princ,session->krb5_client_princ,
573 session->krb5_client_princ_len);
574 s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0';
575 }
576#endif /* OPENSSL_NO_KRB5 */
577
578 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
579 CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION);
580 if (s->session != NULL)
581 SSL_SESSION_free(s->session);
582 s->session=session;
583 s->verify_result = s->session->verify_result;
584 /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/
585 ret=1;
586 }
587 else
588 {
589 if (s->session != NULL)
590 {
591 SSL_SESSION_free(s->session);
592 s->session=NULL;
593 }
594
595 meth=s->ctx->method;
596 if (meth != s->method)
597 {
598 if (!SSL_set_ssl_method(s,meth))
599 return(0);
600 }
601 ret=1;
602 }
603 return(ret);
604 }
605
606long SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
607 {
608 if (s == NULL) return(0);
609 s->timeout=t;
610 return(1);
611 }
612
613long SSL_SESSION_get_timeout(const SSL_SESSION *s)
614 {
615 if (s == NULL) return(0);
616 return(s->timeout);
617 }
618
619long SSL_SESSION_get_time(const SSL_SESSION *s)
620 {
621 if (s == NULL) return(0);
622 return(s->time);
623 }
624
625long SSL_SESSION_set_time(SSL_SESSION *s, long t)
626 {
627 if (s == NULL) return(0);
628 s->time=t;
629 return(t);
630 }
631
632long SSL_CTX_set_timeout(SSL_CTX *s, long t)
633 {
634 long l;
635 if (s == NULL) return(0);
636 l=s->session_timeout;
637 s->session_timeout=t;
638 return(l);
639 }
640
641long SSL_CTX_get_timeout(const SSL_CTX *s)
642 {
643 if (s == NULL) return(0);
644 return(s->session_timeout);
645 }
646
647typedef struct timeout_param_st
648 {
649 SSL_CTX *ctx;
650 long time;
651 LHASH *cache;
652 } TIMEOUT_PARAM;
653
654static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p)
655 {
656 if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */
657 {
658 /* The reason we don't call SSL_CTX_remove_session() is to
659 * save on locking overhead */
660 lh_delete(p->cache,s);
661 SSL_SESSION_list_remove(p->ctx,s);
662 s->not_resumable=1;
663 if (p->ctx->remove_session_cb != NULL)
664 p->ctx->remove_session_cb(p->ctx,s);
665 SSL_SESSION_free(s);
666 }
667 }
668
669static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION *, TIMEOUT_PARAM *)
670
671void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
672 {
673 unsigned long i;
674 TIMEOUT_PARAM tp;
675
676 tp.ctx=s;
677 tp.cache=s->sessions;
678 if (tp.cache == NULL) return;
679 tp.time=t;
680 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
681 i=tp.cache->down_load;
682 tp.cache->down_load=0;
683 lh_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout), &tp);
684 tp.cache->down_load=i;
685 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
686 }
687
688int ssl_clear_bad_session(SSL *s)
689 {
690 if ( (s->session != NULL) &&
691 !(s->shutdown & SSL_SENT_SHUTDOWN) &&
692 !(SSL_in_init(s) || SSL_in_before(s)))
693 {
694 SSL_CTX_remove_session(s->ctx,s->session);
695 return(1);
696 }
697 else
698 return(0);
699 }
700
701/* locked by SSL_CTX in the calling function */
702static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
703 {
704 if ((s->next == NULL) || (s->prev == NULL)) return;
705
706 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail))
707 { /* last element in list */
708 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
709 { /* only one element in list */
710 ctx->session_cache_head=NULL;
711 ctx->session_cache_tail=NULL;
712 }
713 else
714 {
715 ctx->session_cache_tail=s->prev;
716 s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail);
717 }
718 }
719 else
720 {
721 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
722 { /* first element in list */
723 ctx->session_cache_head=s->next;
724 s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head);
725 }
726 else
727 { /* middle of list */
728 s->next->prev=s->prev;
729 s->prev->next=s->next;
730 }
731 }
732 s->prev=s->next=NULL;
733 }
734
735static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
736 {
737 if ((s->next != NULL) && (s->prev != NULL))
738 SSL_SESSION_list_remove(ctx,s);
739
740 if (ctx->session_cache_head == NULL)
741 {
742 ctx->session_cache_head=s;
743 ctx->session_cache_tail=s;
744 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
745 s->next=(SSL_SESSION *)&(ctx->session_cache_tail);
746 }
747 else
748 {
749 s->next=ctx->session_cache_head;
750 s->next->prev=s;
751 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
752 ctx->session_cache_head=s;
753 }
754 }
755
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c
deleted file mode 100644
index b16d253081..0000000000
--- a/src/lib/libssl/ssl_stat.c
+++ /dev/null
@@ -1,502 +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
62const char *SSL_state_string_long(const SSL *s)
63 {
64 const 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 OPENSSL_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 OPENSSL_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 B"; 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 B"; 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(OPENSSL_NO_SSL2) && !defined(OPENSSL_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
202const char *SSL_rstate_string_long(const SSL *s)
203 {
204 const 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
216const char *SSL_state_string(const SSL *s)
217 {
218 const 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 OPENSSL_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 OPENSSL_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(OPENSSL_NO_SSL2) && !defined(OPENSSL_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
350const char *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
361const char *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
372const char *SSL_alert_desc_string(int value)
373 {
374 const 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 case TLS1_AD_DECRYPTION_FAILED: str="DC"; break;
391 case TLS1_AD_RECORD_OVERFLOW: str="RO"; break;
392 case TLS1_AD_UNKNOWN_CA: str="CA"; break;
393 case TLS1_AD_ACCESS_DENIED: str="AD"; break;
394 case TLS1_AD_DECODE_ERROR: str="DE"; break;
395 case TLS1_AD_DECRYPT_ERROR: str="CY"; break;
396 case TLS1_AD_EXPORT_RESTRICTION: str="ER"; break;
397 case TLS1_AD_PROTOCOL_VERSION: str="PV"; break;
398 case TLS1_AD_INSUFFICIENT_SECURITY: str="IS"; break;
399 case TLS1_AD_INTERNAL_ERROR: str="IE"; break;
400 case TLS1_AD_USER_CANCELLED: str="US"; break;
401 case TLS1_AD_NO_RENEGOTIATION: str="NR"; break;
402 default: str="UK"; break;
403 }
404 return(str);
405 }
406
407const char *SSL_alert_desc_string_long(int value)
408 {
409 const char *str;
410
411 switch (value & 0xff)
412 {
413 case SSL3_AD_CLOSE_NOTIFY:
414 str="close notify";
415 break;
416 case SSL3_AD_UNEXPECTED_MESSAGE:
417 str="unexpected_message";
418 break;
419 case SSL3_AD_BAD_RECORD_MAC:
420 str="bad record mac";
421 break;
422 case SSL3_AD_DECOMPRESSION_FAILURE:
423 str="decompression failure";
424 break;
425 case SSL3_AD_HANDSHAKE_FAILURE:
426 str="handshake failure";
427 break;
428 case SSL3_AD_NO_CERTIFICATE:
429 str="no certificate";
430 break;
431 case SSL3_AD_BAD_CERTIFICATE:
432 str="bad certificate";
433 break;
434 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
435 str="unsupported certificate";
436 break;
437 case SSL3_AD_CERTIFICATE_REVOKED:
438 str="certificate revoked";
439 break;
440 case SSL3_AD_CERTIFICATE_EXPIRED:
441 str="certificate expired";
442 break;
443 case SSL3_AD_CERTIFICATE_UNKNOWN:
444 str="certificate unknown";
445 break;
446 case SSL3_AD_ILLEGAL_PARAMETER:
447 str="illegal parameter";
448 break;
449 case TLS1_AD_DECRYPTION_FAILED:
450 str="decryption failed";
451 break;
452 case TLS1_AD_RECORD_OVERFLOW:
453 str="record overflow";
454 break;
455 case TLS1_AD_UNKNOWN_CA:
456 str="unknown CA";
457 break;
458 case TLS1_AD_ACCESS_DENIED:
459 str="access denied";
460 break;
461 case TLS1_AD_DECODE_ERROR:
462 str="decode error";
463 break;
464 case TLS1_AD_DECRYPT_ERROR:
465 str="decrypt error";
466 break;
467 case TLS1_AD_EXPORT_RESTRICTION:
468 str="export restriction";
469 break;
470 case TLS1_AD_PROTOCOL_VERSION:
471 str="protocol version";
472 break;
473 case TLS1_AD_INSUFFICIENT_SECURITY:
474 str="insufficient security";
475 break;
476 case TLS1_AD_INTERNAL_ERROR:
477 str="internal error";
478 break;
479 case TLS1_AD_USER_CANCELLED:
480 str="user canceled";
481 break;
482 case TLS1_AD_NO_RENEGOTIATION:
483 str="no renegotiation";
484 break;
485 default: str="unknown"; break;
486 }
487 return(str);
488 }
489
490const char *SSL_rstate_string(const SSL *s)
491 {
492 const char *str;
493
494 switch (s->rstate)
495 {
496 case SSL_ST_READ_HEADER:str="RH"; break;
497 case SSL_ST_READ_BODY: str="RB"; break;
498 case SSL_ST_READ_DONE: str="RD"; break;
499 default: str="unknown"; break;
500 }
501 return(str);
502 }
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c
deleted file mode 100644
index 8655a31333..0000000000
--- a/src/lib/libssl/ssl_txt.c
+++ /dev/null
@@ -1,186 +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 OPENSSL_NO_FP_API
64int SSL_SESSION_print_fp(FILE *fp, const 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, const SSL_SESSION *x)
82 {
83 unsigned int i;
84 char *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 if (BIO_printf(bp," Protocol : %s\n",s) <= 0) goto err;
97
98 if (x->cipher == NULL)
99 {
100 if (((x->cipher_id) & 0xff000000) == 0x02000000)
101 {
102 if (BIO_printf(bp," Cipher : %06lX\n",x->cipher_id&0xffffff) <= 0)
103 goto err;
104 }
105 else
106 {
107 if (BIO_printf(bp," Cipher : %04lX\n",x->cipher_id&0xffff) <= 0)
108 goto err;
109 }
110 }
111 else
112 {
113 if (BIO_printf(bp," Cipher : %s\n",((x->cipher == NULL)?"unknown":x->cipher->name)) <= 0)
114 goto err;
115 }
116 if (BIO_puts(bp," Session-ID: ") <= 0) goto err;
117 for (i=0; i<x->session_id_length; i++)
118 {
119 if (BIO_printf(bp,"%02X",x->session_id[i]) <= 0) goto err;
120 }
121 if (BIO_puts(bp,"\n Session-ID-ctx: ") <= 0) goto err;
122 for (i=0; i<x->sid_ctx_length; i++)
123 {
124 if (BIO_printf(bp,"%02X",x->sid_ctx[i]) <= 0)
125 goto err;
126 }
127 if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err;
128 for (i=0; i<(unsigned int)x->master_key_length; i++)
129 {
130 if (BIO_printf(bp,"%02X",x->master_key[i]) <= 0) goto err;
131 }
132 if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err;
133 if (x->key_arg_length == 0)
134 {
135 if (BIO_puts(bp,"None") <= 0) goto err;
136 }
137 else
138 for (i=0; i<x->key_arg_length; i++)
139 {
140 if (BIO_printf(bp,"%02X",x->key_arg[i]) <= 0) goto err;
141 }
142#ifndef OPENSSL_NO_KRB5
143 if (BIO_puts(bp,"\n Krb5 Principal: ") <= 0) goto err;
144 if (x->krb5_client_princ_len == 0)
145 {
146 if (BIO_puts(bp,"None") <= 0) goto err;
147 }
148 else
149 for (i=0; i<x->krb5_client_princ_len; i++)
150 {
151 if (BIO_printf(bp,"%02X",x->krb5_client_princ[i]) <= 0) goto err;
152 }
153#endif /* OPENSSL_NO_KRB5 */
154 if (x->compress_meth != 0)
155 {
156 SSL_COMP *comp;
157
158 ssl_cipher_get_evp(x,NULL,NULL,&comp);
159 if (comp == NULL)
160 {
161 if (BIO_printf(bp,"\n Compression: %d",x->compress_meth) <= 0) goto err;
162 }
163 else
164 {
165 if (BIO_printf(bp,"\n Compression: %d (%s)", comp->id,comp->method->name) <= 0) goto err;
166 }
167 }
168 if (x->time != 0L)
169 {
170 if (BIO_printf(bp, "\n Start Time: %ld",x->time) <= 0) goto err;
171 }
172 if (x->timeout != 0L)
173 {
174 if (BIO_printf(bp, "\n Timeout : %ld (sec)",x->timeout) <= 0) goto err;
175 }
176 if (BIO_puts(bp,"\n") <= 0) goto err;
177
178 if (BIO_puts(bp, " Verify return code: ") <= 0) goto err;
179 if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
180 X509_verify_cert_error_string(x->verify_result)) <= 0) goto err;
181
182 return(1);
183err:
184 return(0);
185 }
186
diff --git a/src/lib/libssl/t1_clnt.c b/src/lib/libssl/t1_clnt.c
deleted file mode 100644
index 57205fb429..0000000000
--- a/src/lib/libssl/t1_clnt.c
+++ /dev/null
@@ -1,97 +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 "ssl_locl.h"
61#include <openssl/buffer.h>
62#include <openssl/rand.h>
63#include <openssl/objects.h>
64#include <openssl/evp.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 CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
83
84 if (init)
85 {
86 memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(),
87 sizeof(SSL_METHOD));
88 TLSv1_client_data.ssl_connect=ssl3_connect;
89 TLSv1_client_data.get_ssl_method=tls1_get_client_method;
90 init=0;
91 }
92
93 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
94 }
95 return(&TLSv1_client_data);
96 }
97
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c
deleted file mode 100644
index 2c6246abf5..0000000000
--- a/src/lib/libssl/t1_enc.c
+++ /dev/null
@@ -1,816 +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 * Copyright (c) 1998-2002 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 "ssl_locl.h"
114#include <openssl/comp.h>
115#include <openssl/evp.h>
116#include <openssl/hmac.h>
117#include <openssl/md5.h>
118#include <openssl/fips.h>
119
120static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
121 int sec_len, unsigned char *seed, int seed_len,
122 unsigned char *out, int olen)
123 {
124 int chunk,n;
125 unsigned int j;
126 HMAC_CTX ctx;
127 HMAC_CTX ctx_tmp;
128 unsigned char A1[EVP_MAX_MD_SIZE];
129 unsigned int A1_len;
130
131 chunk=EVP_MD_size(md);
132
133 HMAC_CTX_init(&ctx);
134 HMAC_CTX_init(&ctx_tmp);
135 HMAC_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
136 HMAC_CTX_set_flags(&ctx_tmp, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
137 HMAC_Init_ex(&ctx,sec,sec_len,md, NULL);
138 HMAC_Init_ex(&ctx_tmp,sec,sec_len,md, NULL);
139 HMAC_Update(&ctx,seed,seed_len);
140 HMAC_Final(&ctx,A1,&A1_len);
141
142 n=0;
143 for (;;)
144 {
145 HMAC_Init_ex(&ctx,NULL,0,NULL,NULL); /* re-init */
146 HMAC_Init_ex(&ctx_tmp,NULL,0,NULL,NULL); /* re-init */
147 HMAC_Update(&ctx,A1,A1_len);
148 HMAC_Update(&ctx_tmp,A1,A1_len);
149 HMAC_Update(&ctx,seed,seed_len);
150
151 if (olen > chunk)
152 {
153 HMAC_Final(&ctx,out,&j);
154 out+=j;
155 olen-=j;
156 HMAC_Final(&ctx_tmp,A1,&A1_len); /* calc the next A1 value */
157 }
158 else /* last one */
159 {
160 HMAC_Final(&ctx,A1,&A1_len);
161 memcpy(out,A1,olen);
162 break;
163 }
164 }
165 HMAC_CTX_cleanup(&ctx);
166 HMAC_CTX_cleanup(&ctx_tmp);
167 OPENSSL_cleanse(A1,sizeof(A1));
168 }
169
170static void tls1_PRF(const EVP_MD *md5, const EVP_MD *sha1,
171 unsigned char *label, int label_len,
172 const unsigned char *sec, int slen, unsigned char *out1,
173 unsigned char *out2, int olen)
174 {
175 int len,i;
176 const unsigned char *S1,*S2;
177
178 len=slen/2;
179 S1=sec;
180 S2= &(sec[len]);
181 len+=(slen&1); /* add for odd, make longer */
182
183 tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen);
184 tls1_P_hash(sha1,S2,len,label,label_len,out2,olen);
185
186 for (i=0; i<olen; i++)
187 out1[i]^=out2[i];
188 }
189
190static void tls1_generate_key_block(SSL *s, unsigned char *km,
191 unsigned char *tmp, int num)
192 {
193 unsigned char *p;
194 unsigned char buf[SSL3_RANDOM_SIZE*2+
195 TLS_MD_MAX_CONST_SIZE];
196 p=buf;
197
198 memcpy(p,TLS_MD_KEY_EXPANSION_CONST,
199 TLS_MD_KEY_EXPANSION_CONST_SIZE);
200 p+=TLS_MD_KEY_EXPANSION_CONST_SIZE;
201 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
202 p+=SSL3_RANDOM_SIZE;
203 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
204 p+=SSL3_RANDOM_SIZE;
205
206 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf),
207 s->session->master_key,s->session->master_key_length,
208 km,tmp,num);
209#ifdef KSSL_DEBUG
210 printf("tls1_generate_key_block() ==> %d byte master_key =\n\t",
211 s->session->master_key_length);
212 {
213 int i;
214 for (i=0; i < s->session->master_key_length; i++)
215 {
216 printf("%02X", s->session->master_key[i]);
217 }
218 printf("\n"); }
219#endif /* KSSL_DEBUG */
220 }
221
222int tls1_change_cipher_state(SSL *s, int which)
223 {
224 static const unsigned char empty[]="";
225 unsigned char *p,*key_block,*mac_secret;
226 unsigned char *exp_label,buf[TLS_MD_MAX_CONST_SIZE+
227 SSL3_RANDOM_SIZE*2];
228 unsigned char tmp1[EVP_MAX_KEY_LENGTH];
229 unsigned char tmp2[EVP_MAX_KEY_LENGTH];
230 unsigned char iv1[EVP_MAX_IV_LENGTH*2];
231 unsigned char iv2[EVP_MAX_IV_LENGTH*2];
232 unsigned char *ms,*key,*iv,*er1,*er2;
233 int client_write;
234 EVP_CIPHER_CTX *dd;
235 const EVP_CIPHER *c;
236 const SSL_COMP *comp;
237 const EVP_MD *m;
238 int is_export,n,i,j,k,exp_label_len,cl;
239 int reuse_dd = 0;
240
241 is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
242 c=s->s3->tmp.new_sym_enc;
243 m=s->s3->tmp.new_hash;
244 comp=s->s3->tmp.new_compression;
245 key_block=s->s3->tmp.key_block;
246
247#ifdef KSSL_DEBUG
248 printf("tls1_change_cipher_state(which= %d) w/\n", which);
249 printf("\talg= %ld, comp= %p\n", s->s3->tmp.new_cipher->algorithms,
250 comp);
251 printf("\tevp_cipher == %p ==? &d_cbc_ede_cipher3\n", c);
252 printf("\tevp_cipher: nid, blksz= %d, %d, keylen=%d, ivlen=%d\n",
253 c->nid,c->block_size,c->key_len,c->iv_len);
254 printf("\tkey_block: len= %d, data= ", s->s3->tmp.key_block_length);
255 {
256 int i;
257 for (i=0; i<s->s3->tmp.key_block_length; i++)
258 printf("%02x", key_block[i]); printf("\n");
259 }
260#endif /* KSSL_DEBUG */
261
262 if (which & SSL3_CC_READ)
263 {
264 if (s->enc_read_ctx != NULL)
265 reuse_dd = 1;
266 else if ((s->enc_read_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
267 goto err;
268 dd= s->enc_read_ctx;
269 s->read_hash=m;
270 if (s->expand != NULL)
271 {
272 COMP_CTX_free(s->expand);
273 s->expand=NULL;
274 }
275 if (comp != NULL)
276 {
277 s->expand=COMP_CTX_new(comp->method);
278 if (s->expand == NULL)
279 {
280 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR);
281 goto err2;
282 }
283 if (s->s3->rrec.comp == NULL)
284 s->s3->rrec.comp=(unsigned char *)
285 OPENSSL_malloc(SSL3_RT_MAX_ENCRYPTED_LENGTH);
286 if (s->s3->rrec.comp == NULL)
287 goto err;
288 }
289 memset(&(s->s3->read_sequence[0]),0,8);
290 mac_secret= &(s->s3->read_mac_secret[0]);
291 }
292 else
293 {
294 if (s->enc_write_ctx != NULL)
295 reuse_dd = 1;
296 else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
297 goto err;
298 if ((s->enc_write_ctx == NULL) &&
299 ((s->enc_write_ctx=(EVP_CIPHER_CTX *)
300 OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
301 goto err;
302 dd= s->enc_write_ctx;
303 s->write_hash=m;
304 if (s->compress != NULL)
305 {
306 COMP_CTX_free(s->compress);
307 s->compress=NULL;
308 }
309 if (comp != NULL)
310 {
311 s->compress=COMP_CTX_new(comp->method);
312 if (s->compress == NULL)
313 {
314 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR);
315 goto err2;
316 }
317 }
318 memset(&(s->s3->write_sequence[0]),0,8);
319 mac_secret= &(s->s3->write_mac_secret[0]);
320 }
321
322 if (reuse_dd)
323 EVP_CIPHER_CTX_cleanup(dd);
324 EVP_CIPHER_CTX_init(dd);
325
326 p=s->s3->tmp.key_block;
327 i=EVP_MD_size(m);
328 cl=EVP_CIPHER_key_length(c);
329 j=is_export ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ?
330 cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl;
331 /* Was j=(exp)?5:EVP_CIPHER_key_length(c); */
332 k=EVP_CIPHER_iv_length(c);
333 er1= &(s->s3->client_random[0]);
334 er2= &(s->s3->server_random[0]);
335 if ( (which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
336 (which == SSL3_CHANGE_CIPHER_SERVER_READ))
337 {
338 ms= &(p[ 0]); n=i+i;
339 key= &(p[ n]); n+=j+j;
340 iv= &(p[ n]); n+=k+k;
341 exp_label=(unsigned char *)TLS_MD_CLIENT_WRITE_KEY_CONST;
342 exp_label_len=TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE;
343 client_write=1;
344 }
345 else
346 {
347 n=i;
348 ms= &(p[ n]); n+=i+j;
349 key= &(p[ n]); n+=j+k;
350 iv= &(p[ n]); n+=k;
351 exp_label=(unsigned char *)TLS_MD_SERVER_WRITE_KEY_CONST;
352 exp_label_len=TLS_MD_SERVER_WRITE_KEY_CONST_SIZE;
353 client_write=0;
354 }
355
356 if (n > s->s3->tmp.key_block_length)
357 {
358 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_INTERNAL_ERROR);
359 goto err2;
360 }
361
362 memcpy(mac_secret,ms,i);
363#ifdef TLS_DEBUG
364printf("which = %04X\nmac key=",which);
365{ int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); }
366#endif
367 if (is_export)
368 {
369 /* In here I set both the read and write key/iv to the
370 * same value since only the correct one will be used :-).
371 */
372 p=buf;
373 memcpy(p,exp_label,exp_label_len);
374 p+=exp_label_len;
375 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
376 p+=SSL3_RANDOM_SIZE;
377 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
378 p+=SSL3_RANDOM_SIZE;
379 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf),key,j,
380 tmp1,tmp2,EVP_CIPHER_key_length(c));
381 key=tmp1;
382
383 if (k > 0)
384 {
385 p=buf;
386 memcpy(p,TLS_MD_IV_BLOCK_CONST,
387 TLS_MD_IV_BLOCK_CONST_SIZE);
388 p+=TLS_MD_IV_BLOCK_CONST_SIZE;
389 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
390 p+=SSL3_RANDOM_SIZE;
391 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
392 p+=SSL3_RANDOM_SIZE;
393 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf,empty,0,
394 iv1,iv2,k*2);
395 if (client_write)
396 iv=iv1;
397 else
398 iv= &(iv1[k]);
399 }
400 }
401
402 s->session->key_arg_length=0;
403#ifdef KSSL_DEBUG
404 {
405 int i;
406 printf("EVP_CipherInit_ex(dd,c,key=,iv=,which)\n");
407 printf("\tkey= "); for (i=0; i<c->key_len; i++) printf("%02x", key[i]);
408 printf("\n");
409 printf("\t iv= "); for (i=0; i<c->iv_len; i++) printf("%02x", iv[i]);
410 printf("\n");
411 }
412#endif /* KSSL_DEBUG */
413
414 EVP_CipherInit_ex(dd,c,NULL,key,iv,(which & SSL3_CC_WRITE));
415#ifdef TLS_DEBUG
416printf("which = %04X\nkey=",which);
417{ int z; for (z=0; z<EVP_CIPHER_key_length(c); z++) printf("%02X%c",key[z],((z+1)%16)?' ':'\n'); }
418printf("\niv=");
419{ int z; for (z=0; z<k; z++) printf("%02X%c",iv[z],((z+1)%16)?' ':'\n'); }
420printf("\n");
421#endif
422
423 OPENSSL_cleanse(tmp1,sizeof(tmp1));
424 OPENSSL_cleanse(tmp2,sizeof(tmp1));
425 OPENSSL_cleanse(iv1,sizeof(iv1));
426 OPENSSL_cleanse(iv2,sizeof(iv2));
427 return(1);
428err:
429 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE);
430err2:
431 return(0);
432 }
433
434int tls1_setup_key_block(SSL *s)
435 {
436 unsigned char *p1,*p2;
437 const EVP_CIPHER *c;
438 const EVP_MD *hash;
439 int num;
440 SSL_COMP *comp;
441
442#ifdef KSSL_DEBUG
443 printf ("tls1_setup_key_block()\n");
444#endif /* KSSL_DEBUG */
445
446 if (s->s3->tmp.key_block_length != 0)
447 return(1);
448
449 if (!ssl_cipher_get_evp(s->session,&c,&hash,&comp))
450 {
451 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
452 return(0);
453 }
454
455 s->s3->tmp.new_sym_enc=c;
456 s->s3->tmp.new_hash=hash;
457
458 num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c);
459 num*=2;
460
461 ssl3_cleanup_key_block(s);
462
463 if ((p1=(unsigned char *)OPENSSL_malloc(num)) == NULL)
464 goto err;
465 if ((p2=(unsigned char *)OPENSSL_malloc(num)) == NULL)
466 goto err;
467
468 s->s3->tmp.key_block_length=num;
469 s->s3->tmp.key_block=p1;
470
471
472#ifdef TLS_DEBUG
473printf("client random\n");
474{ int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->client_random[z],((z+1)%16)?' ':'\n'); }
475printf("server random\n");
476{ int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->server_random[z],((z+1)%16)?' ':'\n'); }
477printf("pre-master\n");
478{ int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); }
479#endif
480 tls1_generate_key_block(s,p1,p2,num);
481 OPENSSL_cleanse(p2,num);
482 OPENSSL_free(p2);
483#ifdef TLS_DEBUG
484printf("\nkey block\n");
485{ int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); }
486#endif
487
488 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS))
489 {
490 /* enable vulnerability countermeasure for CBC ciphers with
491 * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt)
492 */
493 s->s3->need_empty_fragments = 1;
494
495 if (s->session->cipher != NULL)
496 {
497 if ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_eNULL)
498 s->s3->need_empty_fragments = 0;
499
500#ifndef OPENSSL_NO_RC4
501 if ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_RC4)
502 s->s3->need_empty_fragments = 0;
503#endif
504 }
505 }
506
507 return(1);
508err:
509 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE);
510 return(0);
511 }
512
513int tls1_enc(SSL *s, int send)
514 {
515 SSL3_RECORD *rec;
516 EVP_CIPHER_CTX *ds;
517 unsigned long l;
518 int bs,i,ii,j,k,n=0;
519 const EVP_CIPHER *enc;
520
521 if (send)
522 {
523 if (s->write_hash != NULL)
524 n=EVP_MD_size(s->write_hash);
525 ds=s->enc_write_ctx;
526 rec= &(s->s3->wrec);
527 if (s->enc_write_ctx == NULL)
528 enc=NULL;
529 else
530 enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx);
531 }
532 else
533 {
534 if (s->read_hash != NULL)
535 n=EVP_MD_size(s->read_hash);
536 ds=s->enc_read_ctx;
537 rec= &(s->s3->rrec);
538 if (s->enc_read_ctx == NULL)
539 enc=NULL;
540 else
541 enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx);
542 }
543
544#ifdef KSSL_DEBUG
545 printf("tls1_enc(%d)\n", send);
546#endif /* KSSL_DEBUG */
547
548 if ((s->session == NULL) || (ds == NULL) ||
549 (enc == NULL))
550 {
551 memmove(rec->data,rec->input,rec->length);
552 rec->input=rec->data;
553 }
554 else
555 {
556 l=rec->length;
557 bs=EVP_CIPHER_block_size(ds->cipher);
558
559 if ((bs != 1) && send)
560 {
561 i=bs-((int)l%bs);
562
563 /* Add weird padding of upto 256 bytes */
564
565 /* we need to add 'i' padding bytes of value j */
566 j=i-1;
567 if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG)
568 {
569 if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG)
570 j++;
571 }
572 for (k=(int)l; k<(int)(l+i); k++)
573 rec->input[k]=j;
574 l+=i;
575 rec->length+=i;
576 }
577
578#ifdef KSSL_DEBUG
579 {
580 unsigned long ui;
581 printf("EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n",
582 ds,rec->data,rec->input,l);
583 printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n",
584 ds->buf_len, ds->cipher->key_len,
585 DES_KEY_SZ, DES_SCHEDULE_SZ,
586 ds->cipher->iv_len);
587 printf("\t\tIV: ");
588 for (i=0; i<ds->cipher->iv_len; i++) printf("%02X", ds->iv[i]);
589 printf("\n");
590 printf("\trec->input=");
591 for (ui=0; ui<l; ui++) printf(" %02x", rec->input[ui]);
592 printf("\n");
593 }
594#endif /* KSSL_DEBUG */
595
596 if (!send)
597 {
598 if (l == 0 || l%bs != 0)
599 {
600 SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);
601 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED);
602 return 0;
603 }
604 }
605
606 EVP_Cipher(ds,rec->data,rec->input,l);
607
608#ifdef KSSL_DEBUG
609 {
610 unsigned long i;
611 printf("\trec->data=");
612 for (i=0; i<l; i++)
613 printf(" %02x", rec->data[i]); printf("\n");
614 }
615#endif /* KSSL_DEBUG */
616
617 if ((bs != 1) && !send)
618 {
619 ii=i=rec->data[l-1]; /* padding_length */
620 i++;
621 if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG)
622 {
623 /* First packet is even in size, so check */
624 if ((memcmp(s->s3->read_sequence,
625 "\0\0\0\0\0\0\0\0",8) == 0) && !(ii & 1))
626 s->s3->flags|=TLS1_FLAGS_TLS_PADDING_BUG;
627 if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG)
628 i--;
629 }
630 /* TLS 1.0 does not bound the number of padding bytes by the block size.
631 * All of them must have value 'padding_length'. */
632 if (i > (int)rec->length)
633 {
634 /* Incorrect padding. SSLerr() and ssl3_alert are done
635 * by caller: we don't want to reveal whether this is
636 * a decryption error or a MAC verification failure
637 * (see http://www.openssl.org/~bodo/tls-cbc.txt) */
638 return -1;
639 }
640 for (j=(int)(l-i); j<(int)l; j++)
641 {
642 if (rec->data[j] != ii)
643 {
644 /* Incorrect padding */
645 return -1;
646 }
647 }
648 rec->length-=i;
649 }
650 }
651 return(1);
652 }
653
654int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in_ctx, unsigned char *out)
655 {
656 unsigned int ret;
657 EVP_MD_CTX ctx;
658
659 EVP_MD_CTX_init(&ctx);
660 EVP_MD_CTX_copy_ex(&ctx,in_ctx);
661 EVP_DigestFinal_ex(&ctx,out,&ret);
662 EVP_MD_CTX_cleanup(&ctx);
663 return((int)ret);
664 }
665
666int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
667 const char *str, int slen, unsigned char *out)
668 {
669 unsigned int i;
670 EVP_MD_CTX ctx;
671 unsigned char buf[TLS_MD_MAX_CONST_SIZE+MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
672 unsigned char *q,buf2[12];
673
674 q=buf;
675 memcpy(q,str,slen);
676 q+=slen;
677
678 EVP_MD_CTX_init(&ctx);
679 EVP_MD_CTX_copy_ex(&ctx,in1_ctx);
680 EVP_DigestFinal_ex(&ctx,q,&i);
681 q+=i;
682 EVP_MD_CTX_copy_ex(&ctx,in2_ctx);
683 EVP_DigestFinal_ex(&ctx,q,&i);
684 q+=i;
685
686 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf),
687 s->session->master_key,s->session->master_key_length,
688 out,buf2,sizeof buf2);
689 EVP_MD_CTX_cleanup(&ctx);
690
691 return sizeof buf2;
692 }
693
694int tls1_mac(SSL *ssl, unsigned char *md, int send)
695 {
696 SSL3_RECORD *rec;
697 unsigned char *mac_sec,*seq;
698 const EVP_MD *hash;
699 unsigned int md_size;
700 int i;
701 HMAC_CTX hmac;
702 unsigned char buf[5];
703
704 if (send)
705 {
706 rec= &(ssl->s3->wrec);
707 mac_sec= &(ssl->s3->write_mac_secret[0]);
708 seq= &(ssl->s3->write_sequence[0]);
709 hash=ssl->write_hash;
710 }
711 else
712 {
713 rec= &(ssl->s3->rrec);
714 mac_sec= &(ssl->s3->read_mac_secret[0]);
715 seq= &(ssl->s3->read_sequence[0]);
716 hash=ssl->read_hash;
717 }
718
719 md_size=EVP_MD_size(hash);
720
721 buf[0]=rec->type;
722 buf[1]=TLS1_VERSION_MAJOR;
723 buf[2]=TLS1_VERSION_MINOR;
724 buf[3]=rec->length>>8;
725 buf[4]=rec->length&0xff;
726
727 /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */
728 HMAC_CTX_init(&hmac);
729 HMAC_Init_ex(&hmac,mac_sec,EVP_MD_size(hash),hash,NULL);
730 HMAC_Update(&hmac,seq,8);
731 HMAC_Update(&hmac,buf,5);
732 HMAC_Update(&hmac,rec->input,rec->length);
733 HMAC_Final(&hmac,md,&md_size);
734 HMAC_CTX_cleanup(&hmac);
735
736#ifdef TLS_DEBUG
737printf("sec=");
738{unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); }
739printf("seq=");
740{int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); }
741printf("buf=");
742{int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); }
743printf("rec=");
744{unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); }
745#endif
746
747 for (i=7; i>=0; i--)
748 {
749 ++seq[i];
750 if (seq[i] != 0) break;
751 }
752
753#ifdef TLS_DEBUG
754{unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",md[z]); printf("\n"); }
755#endif
756 return(md_size);
757 }
758
759int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
760 int len)
761 {
762 unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE];
763 unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH];
764
765#ifdef KSSL_DEBUG
766 printf ("tls1_generate_master_secret(%p,%p, %p, %d)\n", s,out, p,len);
767#endif /* KSSL_DEBUG */
768
769 /* Setup the stuff to munge */
770 memcpy(buf,TLS_MD_MASTER_SECRET_CONST,
771 TLS_MD_MASTER_SECRET_CONST_SIZE);
772 memcpy(&(buf[TLS_MD_MASTER_SECRET_CONST_SIZE]),
773 s->s3->client_random,SSL3_RANDOM_SIZE);
774 memcpy(&(buf[SSL3_RANDOM_SIZE+TLS_MD_MASTER_SECRET_CONST_SIZE]),
775 s->s3->server_random,SSL3_RANDOM_SIZE);
776 tls1_PRF(s->ctx->md5,s->ctx->sha1,
777 buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len,
778 s->session->master_key,buff,sizeof buff);
779#ifdef KSSL_DEBUG
780 printf ("tls1_generate_master_secret() complete\n");
781#endif /* KSSL_DEBUG */
782 return(SSL3_MASTER_SECRET_SIZE);
783 }
784
785int tls1_alert_code(int code)
786 {
787 switch (code)
788 {
789 case SSL_AD_CLOSE_NOTIFY: return(SSL3_AD_CLOSE_NOTIFY);
790 case SSL_AD_UNEXPECTED_MESSAGE: return(SSL3_AD_UNEXPECTED_MESSAGE);
791 case SSL_AD_BAD_RECORD_MAC: return(SSL3_AD_BAD_RECORD_MAC);
792 case SSL_AD_DECRYPTION_FAILED: return(TLS1_AD_DECRYPTION_FAILED);
793 case SSL_AD_RECORD_OVERFLOW: return(TLS1_AD_RECORD_OVERFLOW);
794 case SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE);
795 case SSL_AD_HANDSHAKE_FAILURE: return(SSL3_AD_HANDSHAKE_FAILURE);
796 case SSL_AD_NO_CERTIFICATE: return(-1);
797 case SSL_AD_BAD_CERTIFICATE: return(SSL3_AD_BAD_CERTIFICATE);
798 case SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE);
799 case SSL_AD_CERTIFICATE_REVOKED:return(SSL3_AD_CERTIFICATE_REVOKED);
800 case SSL_AD_CERTIFICATE_EXPIRED:return(SSL3_AD_CERTIFICATE_EXPIRED);
801 case SSL_AD_CERTIFICATE_UNKNOWN:return(SSL3_AD_CERTIFICATE_UNKNOWN);
802 case SSL_AD_ILLEGAL_PARAMETER: return(SSL3_AD_ILLEGAL_PARAMETER);
803 case SSL_AD_UNKNOWN_CA: return(TLS1_AD_UNKNOWN_CA);
804 case SSL_AD_ACCESS_DENIED: return(TLS1_AD_ACCESS_DENIED);
805 case SSL_AD_DECODE_ERROR: return(TLS1_AD_DECODE_ERROR);
806 case SSL_AD_DECRYPT_ERROR: return(TLS1_AD_DECRYPT_ERROR);
807 case SSL_AD_EXPORT_RESTRICTION: return(TLS1_AD_EXPORT_RESTRICTION);
808 case SSL_AD_PROTOCOL_VERSION: return(TLS1_AD_PROTOCOL_VERSION);
809 case SSL_AD_INSUFFICIENT_SECURITY:return(TLS1_AD_INSUFFICIENT_SECURITY);
810 case SSL_AD_INTERNAL_ERROR: return(TLS1_AD_INTERNAL_ERROR);
811 case SSL_AD_USER_CANCELLED: return(TLS1_AD_USER_CANCELLED);
812 case SSL_AD_NO_RENEGOTIATION: return(TLS1_AD_NO_RENEGOTIATION);
813 default: return(-1);
814 }
815 }
816
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 fcc243f782..0000000000
--- a/src/lib/libssl/t1_meth.c
+++ /dev/null
@@ -1,96 +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 CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
80
81 if (init)
82 {
83 memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(),
84 sizeof(SSL_METHOD));
85 TLSv1_data.ssl_connect=ssl3_connect;
86 TLSv1_data.ssl_accept=ssl3_accept;
87 TLSv1_data.get_ssl_method=tls1_get_method;
88 init=0;
89 }
90
91 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
92 }
93
94 return(&TLSv1_data);
95 }
96
diff --git a/src/lib/libssl/t1_srvr.c b/src/lib/libssl/t1_srvr.c
deleted file mode 100644
index 1c1149e49f..0000000000
--- a/src/lib/libssl/t1_srvr.c
+++ /dev/null
@@ -1,98 +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 "ssl_locl.h"
61#include <openssl/buffer.h>
62#include <openssl/rand.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.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 CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
84
85 if (init)
86 {
87 memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(),
88 sizeof(SSL_METHOD));
89 TLSv1_server_data.ssl_accept=ssl3_accept;
90 TLSv1_server_data.get_ssl_method=tls1_get_server_method;
91 init=0;
92 }
93
94 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
95 }
96 return(&TLSv1_server_data);
97 }
98
diff --git a/src/lib/libssl/test/CAss.cnf b/src/lib/libssl/test/CAss.cnf
deleted file mode 100644
index 21da59a73a..0000000000
--- a/src/lib/libssl/test/CAss.cnf
+++ /dev/null
@@ -1,33 +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
26
27[ v3_ca ]
28subjectKeyIdentifier=hash
29authorityKeyIdentifier=keyid:always,issuer:always
30basicConstraints = CA:true,pathlen:1
31keyUsage = cRLSign, keyCertSign
32issuerAltName=issuer:copy
33
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/P1ss.cnf b/src/lib/libssl/test/P1ss.cnf
deleted file mode 100644
index 876a0d35f8..0000000000
--- a/src/lib/libssl/test/P1ss.cnf
+++ /dev/null
@@ -1,37 +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
29
302.commonName = Common Name (eg, YOUR name)
312.commonName_value = Proxy 1
32
33[ v3_proxy ]
34basicConstraints=CA:FALSE
35subjectKeyIdentifier=hash
36authorityKeyIdentifier=keyid,issuer:always
37proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB
diff --git a/src/lib/libssl/test/P2ss.cnf b/src/lib/libssl/test/P2ss.cnf
deleted file mode 100644
index 373a87e7c2..0000000000
--- a/src/lib/libssl/test/P2ss.cnf
+++ /dev/null
@@ -1,45 +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
29
302.commonName = Common Name (eg, YOUR name)
312.commonName_value = Proxy 1
32
333.commonName = Common Name (eg, YOUR name)
343.commonName_value = Proxy 2
35
36[ v3_proxy ]
37basicConstraints=CA:FALSE
38subjectKeyIdentifier=hash
39authorityKeyIdentifier=keyid,issuer:always
40proxyCertInfo=critical,@proxy_ext
41
42[ proxy_ext ]
43language=id-ppl-anyLanguage
44pathlen=0
45policy=text:BC
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 0c0ebb5f67..0000000000
--- a/src/lib/libssl/test/Uss.cnf
+++ /dev/null
@@ -1,36 +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
29
30[ v3_ee ]
31subjectKeyIdentifier=hash
32authorityKeyIdentifier=keyid,issuer:always
33basicConstraints = CA:false
34keyUsage = nonRepudiation, digitalSignature, keyEncipherment
35issuerAltName=issuer:copy
36
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/bctest b/src/lib/libssl/test/bctest
deleted file mode 100644
index e81fc0733a..0000000000
--- a/src/lib/libssl/test/bctest
+++ /dev/null
@@ -1,111 +0,0 @@
1#!/bin/sh
2
3# This script is used by test/Makefile to check whether a sane 'bc'
4# is installed.
5# ('make test_bn' should not try to run 'bc' if it does not exist or if
6# it is a broken 'bc' version that is known to cause trouble.)
7#
8# If 'bc' works, we also test if it knows the 'print' command.
9#
10# In any case, output an appropriate command line for running (or not
11# running) bc.
12
13
14IFS=:
15try_without_dir=true
16# First we try "bc", then "$dir/bc" for each item in $PATH.
17for dir in dummy:$PATH; do
18 if [ "$try_without_dir" = true ]; then
19 # first iteration
20 bc=bc
21 try_without_dir=false
22 else
23 # second and later iterations
24 bc="$dir/bc"
25 if [ ! -f "$bc" ]; then # '-x' is not available on Ultrix
26 bc=''
27 fi
28 fi
29
30 if [ ! "$bc" = '' ]; then
31 failure=none
32
33
34 # Test for SunOS 5.[78] bc bug
35 "$bc" >tmp.bctest <<\EOF
36obase=16
37ibase=16
38a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\
39CEEC1A0EC16950233F77F1C2F2363D56DD71A36C57E0B2511FC4BA8F22D261FE2E9356D99AF57\
4010F3817C0E05BF79C423C3F66FDF321BE8D3F18F625D91B670931C1EF25F28E489BDA1C5422D1\
41C3F6F7A1AD21585746ECC4F10A14A778AF56F08898E965E9909E965E0CB6F85B514150C644759\
423BE731877B16EA07B552088FF2EA728AC5E0FF3A23EB939304519AB8B60F2C33D6BA0945B66F0\
434FC3CADF855448B24A9D7640BCF473E
44b=DCE91E7D120B983EA9A104B5A96D634DD644C37657B1C7860B45E6838999B3DCE5A555583C6\
459209E41F413422954175A06E67FFEF6746DD652F0F48AEFECC3D8CAC13523BDAAD3F5AF4212BD\
468B3CD64126E1A82E190228020C05B91C8B141F1110086FC2A4C6ED631EBA129D04BB9A19FC53D\
473ED0E2017D60A68775B75481449
48(a/b)*b + (a%b) - a
49EOF
50 if [ 0 != "`cat tmp.bctest`" ]; then
51 failure=SunOStest
52 fi
53
54
55 if [ "$failure" = none ]; then
56 # Test for SCO bc bug.
57 "$bc" >tmp.bctest <<\EOF
58obase=16
59ibase=16
60-FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\
619DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7F5ADFACEE54573F5D256A06\
6211B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99FB9812A0E4A5773D8B254117\
631239157EC6E3D8D50199 * -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4\
64AEC6F15AC177F176F2274D29DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7\
65F5ADFACEE54573F5D256A0611B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99F\
66B9812A0E4A5773D8B2541171239157EC6E3D8D50199 - FFBACC221682DA464B6D7F123482522\
6702EDAEDCA38C3B69E9B7BBCD6165A9CD8716C4903417F23C09A85B851961F92C217258CEEB866\
6885EFCC5DD131853A02C07A873B8E2AF2E40C6D5ED598CD0E8F35AD49F3C3A17FDB7653E4E2DC4\
69A8D23CC34686EE4AD01F7407A7CD74429AC6D36DBF0CB6A3E302D0E5BDFCD048A3B90C1BE5AA8\
70E16C3D5884F9136B43FF7BB443764153D4AEC176C681B078F4CC53D6EB6AB76285537DDEE7C18\
718C72441B52EDBDDBC77E02D34E513F2AABF92F44109CAFE8242BD0ECBAC5604A94B02EA44D43C\
7204E9476E6FBC48043916BFA1485C6093603600273C9C33F13114D78064AE42F3DC466C7DA543D\
7389C8D71
74AD534AFBED2FA39EE9F40E20FCF9E2C861024DB98DDCBA1CD118C49CA55EEBC20D6BA51B2271C\
75928B693D6A73F67FEB1B4571448588B46194617D25D910C6A9A130CC963155CF34079CB218A44\
768A1F57E276D92A33386DDCA3D241DB78C8974ABD71DD05B0FA555709C9910D745185E6FE108E3\
7737F1907D0C56F8BFBF52B9704 % -E557905B56B13441574CAFCE2BD257A750B1A8B2C88D0E36\
78E18EF7C38DAC80D3948E17ED63AFF3B3467866E3B89D09A81B3D16B52F6A3C7134D3C6F5123E9\
79F617E3145BBFBE9AFD0D6E437EA4FF6F04BC67C4F1458B4F0F47B64 - 1C2BBBB19B74E86FD32\
809E8DB6A8C3B1B9986D57ED5419C2E855F7D5469E35E76334BB42F4C43E3F3A31B9697C171DAC4\
81D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\
825296964
83EOF
84 if [ "0
850" != "`cat tmp.bctest`" ]; then
86 failure=SCOtest
87 fi
88 fi
89
90
91 if [ "$failure" = none ]; then
92 # bc works; now check if it knows the 'print' command.
93 if [ "OK" = "`echo 'print \"OK\"' | $bc 2>/dev/null`" ]
94 then
95 echo "$bc"
96 else
97 echo "sed 's/print.*//' | $bc"
98 fi
99 exit 0
100 fi
101
102 echo "$bc does not work properly ('$failure' failed). Looking for another bc ..." >&2
103 fi
104done
105
106echo "No working bc found. Consider installing GNU bc." >&2
107if [ "$1" = ignore ]; then
108 echo "cat >/dev/null"
109 exit 0
110fi
111exit 1
diff --git a/src/lib/libssl/test/methtest.c b/src/lib/libssl/test/methtest.c
deleted file mode 100644
index 005c2f4822..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 3ffed12a03..0000000000
--- a/src/lib/libssl/test/tcrl
+++ /dev/null
@@ -1,85 +0,0 @@
1#!/bin/sh
2
3if test "$OSTYPE" = msdosdjgpp; then
4 PATH=../apps\;$PATH
5else
6 PATH=../apps:$PATH
7fi
8export PATH
9
10cmd='../util/shlib_wrap.sh ../apps/openssl crl'
11
12if [ "$1"x != "x" ]; then
13 t=$1
14else
15 t=testcrl.pem
16fi
17
18echo testing crl conversions
19cp $t fff.p
20
21echo "p -> d"
22$cmd -in fff.p -inform p -outform d >f.d
23if [ $? != 0 ]; then exit 1; fi
24#echo "p -> t"
25#$cmd -in fff.p -inform p -outform t >f.t
26#if [ $? != 0 ]; then exit 1; fi
27echo "p -> p"
28$cmd -in fff.p -inform p -outform p >f.p
29if [ $? != 0 ]; then exit 1; fi
30
31echo "d -> d"
32$cmd -in f.d -inform d -outform d >ff.d1
33if [ $? != 0 ]; then exit 1; fi
34#echo "t -> d"
35#$cmd -in f.t -inform t -outform d >ff.d2
36#if [ $? != 0 ]; then exit 1; fi
37echo "p -> d"
38$cmd -in f.p -inform p -outform d >ff.d3
39if [ $? != 0 ]; then exit 1; fi
40
41#echo "d -> t"
42#$cmd -in f.d -inform d -outform t >ff.t1
43#if [ $? != 0 ]; then exit 1; fi
44#echo "t -> t"
45#$cmd -in f.t -inform t -outform t >ff.t2
46#if [ $? != 0 ]; then exit 1; fi
47#echo "p -> t"
48#$cmd -in f.p -inform p -outform t >ff.t3
49#if [ $? != 0 ]; then exit 1; fi
50
51echo "d -> p"
52$cmd -in f.d -inform d -outform p >ff.p1
53if [ $? != 0 ]; then exit 1; fi
54#echo "t -> p"
55#$cmd -in f.t -inform t -outform p >ff.p2
56#if [ $? != 0 ]; then exit 1; fi
57echo "p -> p"
58$cmd -in f.p -inform p -outform p >ff.p3
59if [ $? != 0 ]; then exit 1; fi
60
61cmp fff.p f.p
62if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p1
64if [ $? != 0 ]; then exit 1; fi
65#cmp fff.p ff.p2
66#if [ $? != 0 ]; then exit 1; fi
67cmp fff.p ff.p3
68if [ $? != 0 ]; then exit 1; fi
69
70#cmp f.t ff.t1
71#if [ $? != 0 ]; then exit 1; fi
72#cmp f.t ff.t2
73#if [ $? != 0 ]; then exit 1; fi
74#cmp f.t ff.t3
75#if [ $? != 0 ]; then exit 1; fi
76
77cmp f.p ff.p1
78if [ $? != 0 ]; then exit 1; fi
79#cmp f.p ff.p2
80#if [ $? != 0 ]; then exit 1; fi
81cmp f.p ff.p3
82if [ $? != 0 ]; then exit 1; fi
83
84/bin/rm -f f.* ff.* fff.*
85exit 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 5b2faa78f1..0000000000
--- a/src/lib/libssl/test/testca
+++ /dev/null
@@ -1,51 +0,0 @@
1#!/bin/sh
2
3SH="/bin/sh"
4if test "$OSTYPE" = msdosdjgpp; then
5 PATH=./apps\;../apps\;$PATH
6else
7 PATH=../apps:$PATH
8fi
9export SH PATH
10
11SSLEAY_CONFIG="-config CAss.cnf"
12export SSLEAY_CONFIG
13
14OPENSSL="`pwd`/../util/shlib_wrap.sh openssl"
15export OPENSSL
16
17/bin/rm -fr demoCA
18$SH ../apps/CA.sh -newca <<EOF
19EOF
20
21if [ $? != 0 ]; then
22 exit 1;
23fi
24
25SSLEAY_CONFIG="-config Uss.cnf"
26export SSLEAY_CONFIG
27$SH ../apps/CA.sh -newreq
28if [ $? != 0 ]; then
29 exit 1;
30fi
31
32
33SSLEAY_CONFIG="-config ../apps/openssl.cnf"
34export SSLEAY_CONFIG
35$SH ../apps/CA.sh -sign <<EOF
36y
37y
38EOF
39if [ $? != 0 ]; then
40 exit 1;
41fi
42
43
44$SH ../apps/CA.sh -verify newcert.pem
45if [ $? != 0 ]; then
46 exit 1;
47fi
48
49/bin/rm -fr demoCA newcert.pem newreq.pem
50#usage: CA -newcert|-newreq|-newca|-sign|-verify
51
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 4571ea2875..0000000000
--- a/src/lib/libssl/test/testenc
+++ /dev/null
@@ -1,54 +0,0 @@
1#!/bin/sh
2
3testsrc=Makefile
4test=./p
5cmd="../util/shlib_wrap.sh ../apps/openssl"
6
7cat $testsrc >$test;
8
9echo cat
10$cmd enc -non-fips-allow < $test > $test.cipher
11$cmd enc -non-fips-allow < $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 -non-fips-allow -a -e < $test > $test.cipher
21$cmd enc -non-fips-allow -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 -non-fips-allow -bufsize 113 -e -k test < $test > $test.$i.cipher
34 $cmd $i -non-fips-allow -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 -non-fips-allow -bufsize 113 -a -e -k test < $test > $test.$i.cipher
45 $cmd $i -non-fips-allow -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 524c0d134c..0000000000
--- a/src/lib/libssl/test/testgen
+++ /dev/null
@@ -1,44 +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
9if test "$OSTYPE" = msdosdjgpp; then
10 PATH=../apps\;$PATH;
11else
12 PATH=../apps:$PATH;
13fi
14export PATH
15
16echo "generating certificate request"
17
18echo "string to make the random number generator think it has entropy" >> ./.rnd
19
20if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
21 req_new='-newkey dsa:../apps/dsa512.pem'
22else
23 req_new='-new'
24 echo "There should be a 2 sequences of .'s and some +'s."
25 echo "There should not be more that at most 80 per line"
26fi
27
28echo "This could take some time."
29
30rm -f testkey.pem testreq.pem
31
32../util/shlib_wrap.sh ../apps/openssl req -config test.cnf $req_new -out testreq.pem
33if [ $? != 0 ]; then
34echo problems creating request
35exit 1
36fi
37
38../util/shlib_wrap.sh ../apps/openssl req -config test.cnf -verify -in testreq.pem -noout
39if [ $? != 0 ]; then
40echo signature on req is wrong
41exit 1
42fi
43
44exit 0
diff --git a/src/lib/libssl/test/testp7.pem b/src/lib/libssl/test/testp7.pem
deleted file mode 100644
index e5b7866c31..0000000000
--- a/src/lib/libssl/test/testp7.pem
+++ /dev/null
@@ -1,46 +0,0 @@
1-----BEGIN PKCS7-----
2MIIIGAYJKoZIhvcNAQcCoIIICTCCCAUCAQExADALBgkqhkiG9w0BBwGgggY8MIIE
3cjCCBBygAwIBAgIQeS+OJfWJUZAx6cX0eAiMjzANBgkqhkiG9w0BAQQFADBiMREw
4DwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNV
5BAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIw
6HhcNOTYwNzE5MDAwMDAwWhcNOTcwMzMwMjM1OTU5WjCB1TERMA8GA1UEBxMISW50
7ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2ln
8biBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMSgwJgYDVQQLEx9E
9aWdpdGFsIElEIENsYXNzIDEgLSBTTUlNRSBUZXN0MUcwRQYDVQQLEz53d3cudmVy
10aXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEuMCBJbmMuIGJ5IFJlZi4sTElBQi5M
11VEQoYyk5NjBbMA0GCSqGSIb3DQEBAQUAA0oAMEcCQA7LvHEIAiQ5+4gDYvJGnGAq
12UM5GXyG11diEXmIEZTHUZhorooX5sr8IIjSXiPY59YYUFSvAaharFM1xaBN8zNEC
13AwEAAaOCAjkwggI1MAkGA1UdEwQCMAAwggImBgNVHQMEggIdMIICGTCCAhUwggIR
14BgtghkgBhvhFAQcBATCCAgAWggGrVGhpcyBjZXJ0aWZpY2F0ZSBpbmNvcnBvcmF0
15ZXMgYnkgcmVmZXJlbmNlLCBhbmQgaXRzIHVzZSBpcyBzdHJpY3RseSBzdWJqZWN0
16IHRvLCB0aGUgVmVyaVNpZ24gQ2VydGlmaWNhdGlvbiBQcmFjdGljZSBTdGF0ZW1l
17bnQgKENQUyksIGF2YWlsYWJsZSBhdDogaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
18L0NQUy0xLjA7IGJ5IEUtbWFpbCBhdCBDUFMtcmVxdWVzdHNAdmVyaXNpZ24uY29t
19OyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMuLCAyNTkzIENvYXN0IEF2ZS4s
20IE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBUZWwuICsxICg0MTUpIDk2MS04
21ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2lnbiwgSW5jLiAgQWxsIFJpZ2h0
22cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVTIERJU0NMQUlNRUQgYW5kIExJ
23QUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcBAQGhDgYMYIZIAYb4RQEHAQEC
24MC8wLRYraHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEu
25AzANBgkqhkiG9w0BAQQFAANBAMCYDuSb/eIlYSxY31nZZTaCZkCSfHjlacMofExr
26cF+A2yHoEuT+eCQkqM0pMNHXddUeoQ9RjV+VuMBNmm63DUYwggHCMIIBbKADAgEC
27AhB8CYTq1bkRFJBYOd67cp9JMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT
28MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD
29QTAeFw05NjA3MTcwMDAwMDBaFw05NzA3MTcyMzU5NTlaMGIxETAPBgNVBAcTCElu
30dGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNp
31Z24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjBcMA0GCSqGSIb3
32DQEBAQUAA0sAMEgCQQDsVzrNgnDhbAJZrWeLd9g1vMZJA2W67D33TTbga6yMt+ES
33TWEywhS6RNP+fzLGg7utinjH4tL60cXa0G27GDsLAgMBAAGjIjAgMAsGA1UdDwQE
34AwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADQQAUp6bRwkaD
352d1MBs/mjUcgTI2fXVmW8tTm/Ud6OzUwpC3vYgybiOOA4f6mOC5dbyUHrLOsrihU
3647ZQ0Jo1DUfboYIBrTCBwTBtMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT
37MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD
38QRcNOTYwNzE3MTc0NDA5WhcNOTgwNzE3MDAwMDAwWjANBgkqhkiG9w0BAQIFAANB
39AHitA0/xAukCjHzeh1AMT/l2oC68N+yFb+aJPHBBMxc6gG2MaKjBNwb5hcXUllMl
40ExONA3ju10f7owIq3s3wx10wgeYwgZEwDQYJKoZIhvcNAQECBQAwYjERMA8GA1UE
41BxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytW
42ZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyFw05NjA3
43MTcxNzU5MjlaFw05NzA3MTgwMDAwMDBaMA0GCSqGSIb3DQEBAgUAA0EAubVWYTsW
44sQmste9f+UgMw8BkjDlM25fwQLrCfmmnLxjewey10kSROypUaJLb+r4oRALc0fG9
45XfZsaiiIgotQHjEA
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 1a426857d3..0000000000
--- a/src/lib/libssl/test/testss
+++ /dev/null
@@ -1,163 +0,0 @@
1#!/bin/sh
2
3digest='-sha1'
4reqcmd="../util/shlib_wrap.sh ../apps/openssl req"
5x509cmd="../util/shlib_wrap.sh ../apps/openssl x509 $digest"
6verifycmd="../util/shlib_wrap.sh ../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
20P1conf="P1ss.cnf"
21P1key="keyP1.ss"
22P1req="reqP1.ss"
23P1cert="certP1.ss"
24P1intermediate="tmp_intP1.ss"
25
26P2conf="P2ss.cnf"
27P2key="keyP2.ss"
28P2req="reqP2.ss"
29P2cert="certP2.ss"
30P2intermediate="tmp_intP2.ss"
31
32echo
33echo "make a certificate request using 'req'"
34
35echo "string to make the random number generator think it has entropy" >> ./.rnd
36
37if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
38 req_new='-newkey dsa:../apps/dsa512.pem'
39else
40 req_new='-new'
41fi
42
43$reqcmd -config $CAconf -out $CAreq -keyout $CAkey $req_new #>err.ss
44if [ $? != 0 ]; then
45 echo "error using 'req' to generate a certificate request"
46 exit 1
47fi
48echo
49echo "convert the certificate request into a self signed certificate using 'x509'"
50$x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey -extfile $CAconf -extensions v3_ca >err.ss
51if [ $? != 0 ]; then
52 echo "error using 'x509' to self sign a certificate request"
53 exit 1
54fi
55
56echo
57echo "convert a certificate into a certificate request using 'x509'"
58$x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
59if [ $? != 0 ]; then
60 echo "error using 'x509' convert a certificate to a certificate request"
61 exit 1
62fi
63
64$reqcmd -config $dummycnf -verify -in $CAreq -noout
65if [ $? != 0 ]; then
66 echo first generated request is invalid
67 exit 1
68fi
69
70$reqcmd -config $dummycnf -verify -in $CAreq2 -noout
71if [ $? != 0 ]; then
72 echo second generated request is invalid
73 exit 1
74fi
75
76$verifycmd -CAfile $CAcert $CAcert
77if [ $? != 0 ]; then
78 echo first generated cert is invalid
79 exit 1
80fi
81
82echo
83echo "make a user certificate request using 'req'"
84$reqcmd -config $Uconf -out $Ureq -keyout $Ukey $req_new >err.ss
85if [ $? != 0 ]; then
86 echo "error using 'req' to generate a user certificate request"
87 exit 1
88fi
89
90echo
91echo "sign user certificate request with the just created CA via 'x509'"
92$x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -extfile $Uconf -extensions v3_ee >err.ss
93if [ $? != 0 ]; then
94 echo "error using 'x509' to sign a user certificate request"
95 exit 1
96fi
97
98$verifycmd -CAfile $CAcert $Ucert
99echo
100echo "Certificate details"
101$x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
102
103echo
104echo "make a proxy certificate request using 'req'"
105$reqcmd -config $P1conf -out $P1req -keyout $P1key $req_new >err.ss
106if [ $? != 0 ]; then
107 echo "error using 'req' to generate a proxy certificate request"
108 exit 1
109fi
110
111echo
112echo "sign proxy certificate request with the just created user certificate via 'x509'"
113$x509cmd -CAcreateserial -in $P1req -days 30 -req -out $P1cert -CA $Ucert -CAkey $Ukey -extfile $P1conf -extensions v3_proxy >err.ss
114if [ $? != 0 ]; then
115 echo "error using 'x509' to sign a proxy certificate request"
116 exit 1
117fi
118
119cat $Ucert > $P1intermediate
120$verifycmd -CAfile $CAcert -untrusted $P1intermediate $P1cert
121echo
122echo "Certificate details"
123$x509cmd -subject -issuer -startdate -enddate -noout -in $P1cert
124
125echo
126echo "make another proxy certificate request using 'req'"
127$reqcmd -config $P2conf -out $P2req -keyout $P2key $req_new >err.ss
128if [ $? != 0 ]; then
129 echo "error using 'req' to generate another proxy certificate request"
130 exit 1
131fi
132
133echo
134echo "sign second proxy certificate request with the first proxy certificate via 'x509'"
135$x509cmd -CAcreateserial -in $P2req -days 30 -req -out $P2cert -CA $P1cert -CAkey $P1key -extfile $P2conf -extensions v3_proxy >err.ss
136if [ $? != 0 ]; then
137 echo "error using 'x509' to sign a second proxy certificate request"
138 exit 1
139fi
140
141cat $Ucert $P1cert > $P2intermediate
142$verifycmd -CAfile $CAcert -untrusted $P2intermediate $P2cert
143echo
144echo "Certificate details"
145$x509cmd -subject -issuer -startdate -enddate -noout -in $P2cert
146
147echo
148echo The generated CA certificate is $CAcert
149echo The generated CA private key is $CAkey
150
151echo The generated user certificate is $Ucert
152echo The generated user private key is $Ukey
153
154echo The first generated proxy certificate is $P1cert
155echo The first generated proxy private key is $P1key
156
157echo The second generated proxy certificate is $P2cert
158echo The second generated proxy private key is $P2key
159
160/bin/rm err.ss
161#/bin/rm $P1intermediate
162#/bin/rm $P2intermediate
163exit 0
diff --git a/src/lib/libssl/test/testssl b/src/lib/libssl/test/testssl
deleted file mode 100644
index 8ac90ae5ee..0000000000
--- a/src/lib/libssl/test/testssl
+++ /dev/null
@@ -1,145 +0,0 @@
1#!/bin/sh
2
3if [ "$1" = "" ]; then
4 key=../apps/server.pem
5else
6 key="$1"
7fi
8if [ "$2" = "" ]; then
9 cert=../apps/server.pem
10else
11 cert="$2"
12fi
13ssltest="../util/shlib_wrap.sh ./ssltest -key $key -cert $cert -c_key $key -c_cert $cert"
14
15if ../util/shlib_wrap.sh ../apps/openssl x509 -in $cert -text -noout | fgrep 'DSA Public Key' >/dev/null; then
16 dsa_cert=YES
17else
18 dsa_cert=NO
19fi
20
21if [ "$3" = "" ]; then
22 CA="-CApath ../certs"
23else
24 CA="-CAfile $3"
25fi
26
27if [ "$4" = "" ]; then
28 extra=""
29else
30 extra="$4"
31fi
32
33#############################################################################
34
35echo test sslv2
36$ssltest -ssl2 $extra || exit 1
37
38echo test sslv2 with server authentication
39$ssltest -ssl2 -server_auth $CA $extra || exit 1
40
41if [ $dsa_cert = NO ]; then
42 echo test sslv2 with client authentication
43 $ssltest -ssl2 -client_auth $CA $extra || exit 1
44
45 echo test sslv2 with both client and server authentication
46 $ssltest -ssl2 -server_auth -client_auth $CA $extra || exit 1
47fi
48
49echo test sslv3
50$ssltest -ssl3 $extra || exit 1
51
52echo test sslv3 with server authentication
53$ssltest -ssl3 -server_auth $CA $extra || exit 1
54
55echo test sslv3 with client authentication
56$ssltest -ssl3 -client_auth $CA $extra || exit 1
57
58echo test sslv3 with both client and server authentication
59$ssltest -ssl3 -server_auth -client_auth $CA $extra || exit 1
60
61echo test sslv2/sslv3
62$ssltest $extra || exit 1
63
64echo test sslv2/sslv3 with server authentication
65$ssltest -server_auth $CA $extra || exit 1
66
67echo test sslv2/sslv3 with client authentication
68$ssltest -client_auth $CA $extra || exit 1
69
70echo test sslv2/sslv3 with both client and server authentication
71$ssltest -server_auth -client_auth $CA $extra || exit 1
72
73echo test sslv2 via BIO pair
74$ssltest -bio_pair -ssl2 $extra || exit 1
75
76echo test sslv2 with server authentication via BIO pair
77$ssltest -bio_pair -ssl2 -server_auth $CA $extra || exit 1
78
79if [ $dsa_cert = NO ]; then
80 echo test sslv2 with client authentication via BIO pair
81 $ssltest -bio_pair -ssl2 -client_auth $CA $extra || exit 1
82
83 echo test sslv2 with both client and server authentication via BIO pair
84 $ssltest -bio_pair -ssl2 -server_auth -client_auth $CA $extra || exit 1
85fi
86
87echo test sslv3 via BIO pair
88$ssltest -bio_pair -ssl3 $extra || exit 1
89
90echo test sslv3 with server authentication via BIO pair
91$ssltest -bio_pair -ssl3 -server_auth $CA $extra || exit 1
92
93echo test sslv3 with client authentication via BIO pair
94$ssltest -bio_pair -ssl3 -client_auth $CA $extra || exit 1
95
96echo test sslv3 with both client and server authentication via BIO pair
97$ssltest -bio_pair -ssl3 -server_auth -client_auth $CA $extra || exit 1
98
99echo test sslv2/sslv3 via BIO pair
100$ssltest $extra || exit 1
101
102if [ $dsa_cert = NO ]; then
103 echo test sslv2/sslv3 w/o DHE via BIO pair
104 $ssltest -bio_pair -no_dhe $extra || exit 1
105fi
106
107echo test sslv2/sslv3 with 1024bit DHE via BIO pair
108$ssltest -bio_pair -dhe1024dsa -v $extra || exit 1
109
110echo test sslv2/sslv3 with server authentication
111$ssltest -bio_pair -server_auth $CA $extra || exit 1
112
113echo test sslv2/sslv3 with client authentication via BIO pair
114$ssltest -bio_pair -client_auth $CA $extra || exit 1
115
116echo test sslv2/sslv3 with both client and server authentication via BIO pair
117$ssltest -bio_pair -server_auth -client_auth $CA $extra || exit 1
118
119echo test sslv2/sslv3 with both client and server authentication via BIO pair and app verify
120$ssltest -bio_pair -server_auth -client_auth -app_verify $CA $extra || exit 1
121
122#############################################################################
123
124if ../util/shlib_wrap.sh ../apps/openssl no-dh; then
125 echo skipping anonymous DH tests
126else
127 echo test tls1 with 1024bit anonymous DH, multiple handshakes
128 $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1
129fi
130
131if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
132 echo skipping RSA tests
133else
134 echo test tls1 with 1024bit RSA, no DHE, multiple handshakes
135 ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -no_dhe -num 10 -f -time $extra || exit 1
136
137 if ../util/shlib_wrap.sh ../apps/openssl no-dh; then
138 echo skipping RSA+DHE tests
139 else
140 echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes
141 ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1
142 fi
143fi
144
145exit 0
diff --git a/src/lib/libssl/test/testsslproxy b/src/lib/libssl/test/testsslproxy
deleted file mode 100644
index 58bbda8ab7..0000000000
--- a/src/lib/libssl/test/testsslproxy
+++ /dev/null
@@ -1,10 +0,0 @@
1#! /bin/sh
2
3echo 'Testing a lot of proxy conditions.'
4echo 'Some of them may turn out being invalid, which is fine.'
5for auth in A B C BC; do
6 for cond in A B C 'A|B&!C'; do
7 sh ./testssl $1 $2 $3 "-proxy -proxy_auth $auth -proxy_cond $cond"
8 if [ $? = 3 ]; then exit 1; fi
9 done
10done
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 738d569b8f..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/kernel 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 79bb6e0edf..0000000000
--- a/src/lib/libssl/test/tpkcs7
+++ /dev/null
@@ -1,55 +0,0 @@
1#!/bin/sh
2
3if test "$OSTYPE" = msdosdjgpp; then
4 PATH=../apps\;$PATH
5else
6 PATH=../apps:$PATH
7fi
8export PATH
9
10cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7'
11
12if [ "$1"x != "x" ]; then
13 t=$1
14else
15 t=testp7.pem
16fi
17
18echo testing pkcs7 conversions
19cp $t fff.p
20
21echo "p -> d"
22$cmd -in fff.p -inform p -outform d >f.d
23if [ $? != 0 ]; then exit 1; fi
24echo "p -> p"
25$cmd -in fff.p -inform p -outform p >f.p
26if [ $? != 0 ]; then exit 1; fi
27
28echo "d -> d"
29$cmd -in f.d -inform d -outform d >ff.d1
30if [ $? != 0 ]; then exit 1; fi
31echo "p -> d"
32$cmd -in f.p -inform p -outform d >ff.d3
33if [ $? != 0 ]; then exit 1; fi
34
35echo "d -> p"
36$cmd -in f.d -inform d -outform p >ff.p1
37if [ $? != 0 ]; then exit 1; fi
38echo "p -> p"
39$cmd -in f.p -inform p -outform p >ff.p3
40if [ $? != 0 ]; then exit 1; fi
41
42cmp fff.p f.p
43if [ $? != 0 ]; then exit 1; fi
44cmp fff.p ff.p1
45if [ $? != 0 ]; then exit 1; fi
46cmp fff.p ff.p3
47if [ $? != 0 ]; then exit 1; fi
48
49cmp f.p ff.p1
50if [ $? != 0 ]; then exit 1; fi
51cmp f.p ff.p3
52if [ $? != 0 ]; then exit 1; fi
53
54/bin/rm -f f.* ff.* fff.*
55exit 0
diff --git a/src/lib/libssl/test/tpkcs7d b/src/lib/libssl/test/tpkcs7d
deleted file mode 100644
index 20394b34c4..0000000000
--- a/src/lib/libssl/test/tpkcs7d
+++ /dev/null
@@ -1,48 +0,0 @@
1#!/bin/sh
2
3if test "$OSTYPE" = msdosdjgpp; then
4 PATH=../apps\;$PATH
5else
6 PATH=../apps:$PATH
7fi
8export PATH
9
10cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7'
11
12if [ "$1"x != "x" ]; then
13 t=$1
14else
15 t=pkcs7-1.pem
16fi
17
18echo "testing pkcs7 conversions (2)"
19cp $t fff.p
20
21echo "p -> d"
22$cmd -in fff.p -inform p -outform d >f.d
23if [ $? != 0 ]; then exit 1; fi
24echo "p -> p"
25$cmd -in fff.p -inform p -outform p >f.p
26if [ $? != 0 ]; then exit 1; fi
27
28echo "d -> d"
29$cmd -in f.d -inform d -outform d >ff.d1
30if [ $? != 0 ]; then exit 1; fi
31echo "p -> d"
32$cmd -in f.p -inform p -outform d >ff.d3
33if [ $? != 0 ]; then exit 1; fi
34
35echo "d -> p"
36$cmd -in f.d -inform d -outform p >ff.p1
37if [ $? != 0 ]; then exit 1; fi
38echo "p -> p"
39$cmd -in f.p -inform p -outform p >ff.p3
40if [ $? != 0 ]; then exit 1; fi
41
42cmp f.p ff.p1
43if [ $? != 0 ]; then exit 1; fi
44cmp f.p ff.p3
45if [ $? != 0 ]; then exit 1; fi
46
47/bin/rm -f f.* ff.* fff.*
48exit 0
diff --git a/src/lib/libssl/test/treq b/src/lib/libssl/test/treq
deleted file mode 100644
index 7e020210a5..0000000000
--- a/src/lib/libssl/test/treq
+++ /dev/null
@@ -1,90 +0,0 @@
1#!/bin/sh
2
3if test "$OSTYPE" = msdosdjgpp; then
4 PATH=../apps\;$PATH
5else
6 PATH=../apps:$PATH
7fi
8export PATH
9
10cmd='../util/shlib_wrap.sh ../apps/openssl req -config ../apps/openssl.cnf'
11
12if [ "$1"x != "x" ]; then
13 t=$1
14else
15 t=testreq.pem
16fi
17
18if $cmd -in $t -inform p -noout -text | fgrep 'Unknown Public Key'; then
19 echo "skipping req conversion test for $t"
20 exit 0
21fi
22
23echo testing req conversions
24cp $t fff.p
25
26echo "p -> d"
27$cmd -in fff.p -inform p -outform d >f.d
28if [ $? != 0 ]; then exit 1; fi
29#echo "p -> t"
30#$cmd -in fff.p -inform p -outform t >f.t
31#if [ $? != 0 ]; then exit 1; fi
32echo "p -> p"
33$cmd -in fff.p -inform p -outform p >f.p
34if [ $? != 0 ]; then exit 1; fi
35
36echo "d -> d"
37$cmd -verify -in f.d -inform d -outform d >ff.d1
38if [ $? != 0 ]; then exit 1; fi
39#echo "t -> d"
40#$cmd -in f.t -inform t -outform d >ff.d2
41#if [ $? != 0 ]; then exit 1; fi
42echo "p -> d"
43$cmd -verify -in f.p -inform p -outform d >ff.d3
44if [ $? != 0 ]; then exit 1; fi
45
46#echo "d -> t"
47#$cmd -in f.d -inform d -outform t >ff.t1
48#if [ $? != 0 ]; then exit 1; fi
49#echo "t -> t"
50#$cmd -in f.t -inform t -outform t >ff.t2
51#if [ $? != 0 ]; then exit 1; fi
52#echo "p -> t"
53#$cmd -in f.p -inform p -outform t >ff.t3
54#if [ $? != 0 ]; then exit 1; fi
55
56echo "d -> p"
57$cmd -in f.d -inform d -outform p >ff.p1
58if [ $? != 0 ]; then exit 1; fi
59#echo "t -> p"
60#$cmd -in f.t -inform t -outform p >ff.p2
61#if [ $? != 0 ]; then exit 1; fi
62echo "p -> p"
63$cmd -in f.p -inform p -outform p >ff.p3
64if [ $? != 0 ]; then exit 1; fi
65
66cmp fff.p f.p
67if [ $? != 0 ]; then exit 1; fi
68cmp fff.p ff.p1
69if [ $? != 0 ]; then exit 1; fi
70#cmp fff.p ff.p2
71#if [ $? != 0 ]; then exit 1; fi
72cmp fff.p ff.p3
73if [ $? != 0 ]; then exit 1; fi
74
75#cmp f.t ff.t1
76#if [ $? != 0 ]; then exit 1; fi
77#cmp f.t ff.t2
78#if [ $? != 0 ]; then exit 1; fi
79#cmp f.t ff.t3
80#if [ $? != 0 ]; then exit 1; fi
81
82cmp f.p ff.p1
83if [ $? != 0 ]; then exit 1; fi
84#cmp f.p ff.p2
85#if [ $? != 0 ]; then exit 1; fi
86cmp f.p ff.p3
87if [ $? != 0 ]; then exit 1; fi
88
89/bin/rm -f f.* ff.* fff.*
90exit 0
diff --git a/src/lib/libssl/test/trsa b/src/lib/libssl/test/trsa
deleted file mode 100644
index 67b4a98841..0000000000
--- a/src/lib/libssl/test/trsa
+++ /dev/null
@@ -1,90 +0,0 @@
1#!/bin/sh
2
3if test "$OSTYPE" = msdosdjgpp; then
4 PATH=../apps\;$PATH
5else
6 PATH=../apps:$PATH
7fi
8export PATH
9
10if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
11 echo skipping rsa conversion test
12 exit 0
13fi
14
15cmd='../util/shlib_wrap.sh ../apps/openssl rsa'
16
17if [ "$1"x != "x" ]; then
18 t=$1
19else
20 t=testrsa.pem
21fi
22
23echo testing rsa conversions
24cp $t fff.p
25
26echo "p -> d"
27$cmd -in fff.p -inform p -outform d >f.d
28if [ $? != 0 ]; then exit 1; fi
29#echo "p -> t"
30#$cmd -in fff.p -inform p -outform t >f.t
31#if [ $? != 0 ]; then exit 1; fi
32echo "p -> p"
33$cmd -in fff.p -inform p -outform p >f.p
34if [ $? != 0 ]; then exit 1; fi
35
36echo "d -> d"
37$cmd -in f.d -inform d -outform d >ff.d1
38if [ $? != 0 ]; then exit 1; fi
39#echo "t -> d"
40#$cmd -in f.t -inform t -outform d >ff.d2
41#if [ $? != 0 ]; then exit 1; fi
42echo "p -> d"
43$cmd -in f.p -inform p -outform d >ff.d3
44if [ $? != 0 ]; then exit 1; fi
45
46#echo "d -> t"
47#$cmd -in f.d -inform d -outform t >ff.t1
48#if [ $? != 0 ]; then exit 1; fi
49#echo "t -> t"
50#$cmd -in f.t -inform t -outform t >ff.t2
51#if [ $? != 0 ]; then exit 1; fi
52#echo "p -> t"
53#$cmd -in f.p -inform p -outform t >ff.t3
54#if [ $? != 0 ]; then exit 1; fi
55
56echo "d -> p"
57$cmd -in f.d -inform d -outform p >ff.p1
58if [ $? != 0 ]; then exit 1; fi
59#echo "t -> p"
60#$cmd -in f.t -inform t -outform p >ff.p2
61#if [ $? != 0 ]; then exit 1; fi
62echo "p -> p"
63$cmd -in f.p -inform p -outform p >ff.p3
64if [ $? != 0 ]; then exit 1; fi
65
66cmp fff.p f.p
67if [ $? != 0 ]; then exit 1; fi
68cmp fff.p ff.p1
69if [ $? != 0 ]; then exit 1; fi
70#cmp fff.p ff.p2
71#if [ $? != 0 ]; then exit 1; fi
72cmp fff.p ff.p3
73if [ $? != 0 ]; then exit 1; fi
74
75#cmp f.t ff.t1
76#if [ $? != 0 ]; then exit 1; fi
77#cmp f.t ff.t2
78#if [ $? != 0 ]; then exit 1; fi
79#cmp f.t ff.t3
80#if [ $? != 0 ]; then exit 1; fi
81
82cmp f.p ff.p1
83if [ $? != 0 ]; then exit 1; fi
84#cmp f.p ff.p2
85#if [ $? != 0 ]; then exit 1; fi
86cmp f.p ff.p3
87if [ $? != 0 ]; then exit 1; fi
88
89/bin/rm -f f.* ff.* fff.*
90exit 0
diff --git a/src/lib/libssl/test/tsid b/src/lib/libssl/test/tsid
deleted file mode 100644
index fb4a7213b9..0000000000
--- a/src/lib/libssl/test/tsid
+++ /dev/null
@@ -1,85 +0,0 @@
1#!/bin/sh
2
3if test "$OSTYPE" = msdosdjgpp; then
4 PATH=../apps\;$PATH
5else
6 PATH=../apps:$PATH
7fi
8export PATH
9
10cmd='../util/shlib_wrap.sh ../apps/openssl sess_id'
11
12if [ "$1"x != "x" ]; then
13 t=$1
14else
15 t=testsid.pem
16fi
17
18echo testing session-id conversions
19cp $t fff.p
20
21echo "p -> d"
22$cmd -in fff.p -inform p -outform d >f.d
23if [ $? != 0 ]; then exit 1; fi
24#echo "p -> t"
25#$cmd -in fff.p -inform p -outform t >f.t
26#if [ $? != 0 ]; then exit 1; fi
27echo "p -> p"
28$cmd -in fff.p -inform p -outform p >f.p
29if [ $? != 0 ]; then exit 1; fi
30
31echo "d -> d"
32$cmd -in f.d -inform d -outform d >ff.d1
33if [ $? != 0 ]; then exit 1; fi
34#echo "t -> d"
35#$cmd -in f.t -inform t -outform d >ff.d2
36#if [ $? != 0 ]; then exit 1; fi
37echo "p -> d"
38$cmd -in f.p -inform p -outform d >ff.d3
39if [ $? != 0 ]; then exit 1; fi
40
41#echo "d -> t"
42#$cmd -in f.d -inform d -outform t >ff.t1
43#if [ $? != 0 ]; then exit 1; fi
44#echo "t -> t"
45#$cmd -in f.t -inform t -outform t >ff.t2
46#if [ $? != 0 ]; then exit 1; fi
47#echo "p -> t"
48#$cmd -in f.p -inform p -outform t >ff.t3
49#if [ $? != 0 ]; then exit 1; fi
50
51echo "d -> p"
52$cmd -in f.d -inform d -outform p >ff.p1
53if [ $? != 0 ]; then exit 1; fi
54#echo "t -> p"
55#$cmd -in f.t -inform t -outform p >ff.p2
56#if [ $? != 0 ]; then exit 1; fi
57echo "p -> p"
58$cmd -in f.p -inform p -outform p >ff.p3
59if [ $? != 0 ]; then exit 1; fi
60
61cmp fff.p f.p
62if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p1
64if [ $? != 0 ]; then exit 1; fi
65#cmp fff.p ff.p2
66#if [ $? != 0 ]; then exit 1; fi
67cmp fff.p ff.p3
68if [ $? != 0 ]; then exit 1; fi
69
70#cmp f.t ff.t1
71#if [ $? != 0 ]; then exit 1; fi
72#cmp f.t ff.t2
73#if [ $? != 0 ]; then exit 1; fi
74#cmp f.t ff.t3
75#if [ $? != 0 ]; then exit 1; fi
76
77cmp f.p ff.p1
78if [ $? != 0 ]; then exit 1; fi
79#cmp f.p ff.p2
80#if [ $? != 0 ]; then exit 1; fi
81cmp f.p ff.p3
82if [ $? != 0 ]; then exit 1; fi
83
84/bin/rm -f f.* ff.* fff.*
85exit 0
diff --git a/src/lib/libssl/test/tx509 b/src/lib/libssl/test/tx509
deleted file mode 100644
index 1b9c8661f3..0000000000
--- a/src/lib/libssl/test/tx509
+++ /dev/null
@@ -1,85 +0,0 @@
1#!/bin/sh
2
3if test "$OSTYPE" = msdosdjgpp; then
4 PATH=../apps\;$PATH
5else
6 PATH=../apps:$PATH
7fi
8export PATH
9
10cmd='../util/shlib_wrap.sh ../apps/openssl x509'
11
12if [ "$1"x != "x" ]; then
13 t=$1
14else
15 t=testx509.pem
16fi
17
18echo testing X509 conversions
19cp $t fff.p
20
21echo "p -> d"
22$cmd -in fff.p -inform p -outform d >f.d
23if [ $? != 0 ]; then exit 1; fi
24echo "p -> n"
25$cmd -in fff.p -inform p -outform n >f.n
26if [ $? != 0 ]; then exit 1; fi
27echo "p -> p"
28$cmd -in fff.p -inform p -outform p >f.p
29if [ $? != 0 ]; then exit 1; fi
30
31echo "d -> d"
32$cmd -in f.d -inform d -outform d >ff.d1
33if [ $? != 0 ]; then exit 1; fi
34echo "n -> d"
35$cmd -in f.n -inform n -outform d >ff.d2
36if [ $? != 0 ]; then exit 1; fi
37echo "p -> d"
38$cmd -in f.p -inform p -outform d >ff.d3
39if [ $? != 0 ]; then exit 1; fi
40
41echo "d -> n"
42$cmd -in f.d -inform d -outform n >ff.n1
43if [ $? != 0 ]; then exit 1; fi
44echo "n -> n"
45$cmd -in f.n -inform n -outform n >ff.n2
46if [ $? != 0 ]; then exit 1; fi
47echo "p -> n"
48$cmd -in f.p -inform p -outform n >ff.n3
49if [ $? != 0 ]; then exit 1; fi
50
51echo "d -> p"
52$cmd -in f.d -inform d -outform p >ff.p1
53if [ $? != 0 ]; then exit 1; fi
54echo "n -> p"
55$cmd -in f.n -inform n -outform p >ff.p2
56if [ $? != 0 ]; then exit 1; fi
57echo "p -> p"
58$cmd -in f.p -inform p -outform p >ff.p3
59if [ $? != 0 ]; then exit 1; fi
60
61cmp fff.p f.p
62if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p1
64if [ $? != 0 ]; then exit 1; fi
65cmp fff.p ff.p2
66if [ $? != 0 ]; then exit 1; fi
67cmp fff.p ff.p3
68if [ $? != 0 ]; then exit 1; fi
69
70cmp f.n ff.n1
71if [ $? != 0 ]; then exit 1; fi
72cmp f.n ff.n2
73if [ $? != 0 ]; then exit 1; fi
74cmp f.n ff.n3
75if [ $? != 0 ]; then exit 1; fi
76
77cmp f.p ff.p1
78if [ $? != 0 ]; then exit 1; fi
79cmp f.p ff.p2
80if [ $? != 0 ]; then exit 1; fi
81cmp f.p ff.p3
82if [ $? != 0 ]; then exit 1; fi
83
84/bin/rm -f f.* ff.* fff.*
85exit 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 38838ea9a5..0000000000
--- a/src/lib/libssl/tls1.h
+++ /dev/null
@@ -1,195 +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/* Additional TLS ciphersuites from draft-ietf-tls-56-bit-ciphersuites-00.txt
88 * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see
89 * s3_lib.c). We actually treat them like SSL 3.0 ciphers, which we probably
90 * shouldn't. */
91#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5 0x03000060
92#define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 0x03000061
93#define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA 0x03000062
94#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA 0x03000063
95#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA 0x03000064
96#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA 0x03000065
97#define TLS1_CK_DHE_DSS_WITH_RC4_128_SHA 0x03000066
98
99/* AES ciphersuites from RFC3268 */
100
101#define TLS1_CK_RSA_WITH_AES_128_SHA 0x0300002F
102#define TLS1_CK_DH_DSS_WITH_AES_128_SHA 0x03000030
103#define TLS1_CK_DH_RSA_WITH_AES_128_SHA 0x03000031
104#define TLS1_CK_DHE_DSS_WITH_AES_128_SHA 0x03000032
105#define TLS1_CK_DHE_RSA_WITH_AES_128_SHA 0x03000033
106#define TLS1_CK_ADH_WITH_AES_128_SHA 0x03000034
107
108#define TLS1_CK_RSA_WITH_AES_256_SHA 0x03000035
109#define TLS1_CK_DH_DSS_WITH_AES_256_SHA 0x03000036
110#define TLS1_CK_DH_RSA_WITH_AES_256_SHA 0x03000037
111#define TLS1_CK_DHE_DSS_WITH_AES_256_SHA 0x03000038
112#define TLS1_CK_DHE_RSA_WITH_AES_256_SHA 0x03000039
113#define TLS1_CK_ADH_WITH_AES_256_SHA 0x0300003A
114
115/* XXX
116 * Inconsistency alert:
117 * The OpenSSL names of ciphers with ephemeral DH here include the string
118 * "DHE", while elsewhere it has always been "EDH".
119 * (The alias for the list of all such ciphers also is "EDH".)
120 * The specifications speak of "EDH"; maybe we should allow both forms
121 * for everything. */
122#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5 "EXP1024-RC4-MD5"
123#define TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 "EXP1024-RC2-CBC-MD5"
124#define TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DES-CBC-SHA"
125#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DHE-DSS-DES-CBC-SHA"
126#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA "EXP1024-RC4-SHA"
127#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA "EXP1024-DHE-DSS-RC4-SHA"
128#define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA"
129
130/* AES ciphersuites from RFC3268 */
131#define TLS1_TXT_RSA_WITH_AES_128_SHA "AES128-SHA"
132#define TLS1_TXT_DH_DSS_WITH_AES_128_SHA "DH-DSS-AES128-SHA"
133#define TLS1_TXT_DH_RSA_WITH_AES_128_SHA "DH-RSA-AES128-SHA"
134#define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA "DHE-DSS-AES128-SHA"
135#define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA "DHE-RSA-AES128-SHA"
136#define TLS1_TXT_ADH_WITH_AES_128_SHA "ADH-AES128-SHA"
137
138#define TLS1_TXT_RSA_WITH_AES_256_SHA "AES256-SHA"
139#define TLS1_TXT_DH_DSS_WITH_AES_256_SHA "DH-DSS-AES256-SHA"
140#define TLS1_TXT_DH_RSA_WITH_AES_256_SHA "DH-RSA-AES256-SHA"
141#define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA "DHE-DSS-AES256-SHA"
142#define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA "DHE-RSA-AES256-SHA"
143#define TLS1_TXT_ADH_WITH_AES_256_SHA "ADH-AES256-SHA"
144
145
146#define TLS_CT_RSA_SIGN 1
147#define TLS_CT_DSS_SIGN 2
148#define TLS_CT_RSA_FIXED_DH 3
149#define TLS_CT_DSS_FIXED_DH 4
150#define TLS_CT_NUMBER 4
151
152#define TLS1_FINISH_MAC_LENGTH 12
153
154#define TLS_MD_MAX_CONST_SIZE 20
155#define TLS_MD_CLIENT_FINISH_CONST "client finished"
156#define TLS_MD_CLIENT_FINISH_CONST_SIZE 15
157#define TLS_MD_SERVER_FINISH_CONST "server finished"
158#define TLS_MD_SERVER_FINISH_CONST_SIZE 15
159#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
160#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
161#define TLS_MD_KEY_EXPANSION_CONST "key expansion"
162#define TLS_MD_KEY_EXPANSION_CONST_SIZE 13
163#define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key"
164#define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16
165#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
166#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
167#define TLS_MD_IV_BLOCK_CONST "IV block"
168#define TLS_MD_IV_BLOCK_CONST_SIZE 8
169#define TLS_MD_MASTER_SECRET_CONST "master secret"
170#define TLS_MD_MASTER_SECRET_CONST_SIZE 13
171
172#ifdef CHARSET_EBCDIC
173#undef TLS_MD_CLIENT_FINISH_CONST
174#define TLS_MD_CLIENT_FINISH_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*client finished*/
175#undef TLS_MD_SERVER_FINISH_CONST
176#define TLS_MD_SERVER_FINISH_CONST "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*server finished*/
177#undef TLS_MD_SERVER_WRITE_KEY_CONST
178#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*/
179#undef TLS_MD_KEY_EXPANSION_CONST
180#define TLS_MD_KEY_EXPANSION_CONST "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e" /*key expansion*/
181#undef TLS_MD_CLIENT_WRITE_KEY_CONST
182#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*/
183#undef TLS_MD_SERVER_WRITE_KEY_CONST
184#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*/
185#undef TLS_MD_IV_BLOCK_CONST
186#define TLS_MD_IV_BLOCK_CONST "\x49\x56\x20\x62\x6c\x6f\x63\x6b" /*IV block*/
187#undef TLS_MD_MASTER_SECRET_CONST
188#define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
189#endif
190
191#ifdef __cplusplus
192}
193#endif
194#endif
195