summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
authorbeck <>2000-03-19 11:13:58 +0000
committerbeck <>2000-03-19 11:13:58 +0000
commit796d609550df3a33fc11468741c5d2f6d3df4c11 (patch)
tree6c6d539061caa20372dad0ac4ddb1dfae2fbe7fe /src/lib/libcrypto
parent5be3114c1fd7e0dfea1e38d3abb4cbba75244419 (diff)
downloadopenbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.gz
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.bz2
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.zip
OpenSSL 0.9.5 merge
*warning* this bumps shared lib minors for libssl and libcrypto from 2.1 to 2.2 if you are using the ssl26 packages for ssh and other things to work you will need to get new ones (see ~beck/libsslsnap/<arch>) on cvs or ~beck/src-patent.tar.gz on cvs
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r--src/lib/libcrypto/Attic/Makefile36
-rw-r--r--src/lib/libcrypto/Makefile.ssl36
-rw-r--r--src/lib/libcrypto/asn1/Makefile.ssl138
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c15
-rw-r--r--src/lib/libcrypto/asn1/a_bmp.c6
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c19
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c11
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c2
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c25
-rw-r--r--src/lib/libcrypto/asn1/a_gentm.c10
-rw-r--r--src/lib/libcrypto/asn1/a_hdr.c6
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c2
-rw-r--r--src/lib/libcrypto/asn1/a_int.c41
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c390
-rw-r--r--src/lib/libcrypto/asn1/a_null.c119
-rw-r--r--src/lib/libcrypto/asn1/a_object.c6
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c20
-rw-r--r--src/lib/libcrypto/asn1/a_print.c32
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c15
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c247
-rw-r--r--src/lib/libcrypto/asn1/a_time.c6
-rw-r--r--src/lib/libcrypto/asn1/a_type.c2
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c10
-rw-r--r--src/lib/libcrypto/asn1/a_utf8.c155
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c9
-rw-r--r--src/lib/libcrypto/asn1/a_vis.c6
-rw-r--r--src/lib/libcrypto/asn1/asn1.h290
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c24
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c19
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h14
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c78
-rw-r--r--src/lib/libcrypto/asn1/d2i_dhp.c4
-rw-r--r--src/lib/libcrypto/asn1/d2i_dsap.c4
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c23
-rw-r--r--src/lib/libcrypto/asn1/d2i_r_pr.c11
-rw-r--r--src/lib/libcrypto/asn1/d2i_r_pu.c10
-rw-r--r--src/lib/libcrypto/asn1/d2i_s_pr.c4
-rw-r--r--src/lib/libcrypto/asn1/d2i_s_pu.c4
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c24
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c2
-rw-r--r--src/lib/libcrypto/asn1/f_int.c2
-rw-r--r--src/lib/libcrypto/asn1/f_string.c2
-rw-r--r--src/lib/libcrypto/asn1/i2d_dhp.c2
-rw-r--r--src/lib/libcrypto/asn1/i2d_dsap.c2
-rw-r--r--src/lib/libcrypto/asn1/i2d_r_pr.c8
-rw-r--r--src/lib/libcrypto/asn1/i2d_r_pu.c8
-rw-r--r--src/lib/libcrypto/asn1/i2d_s_pr.c2
-rw-r--r--src/lib/libcrypto/asn1/i2d_s_pu.c2
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c25
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c13
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c33
-rw-r--r--src/lib/libcrypto/asn1/p7_dgst.c10
-rw-r--r--src/lib/libcrypto/asn1/p7_enc.c6
-rw-r--r--src/lib/libcrypto/asn1/p7_enc_c.c7
-rw-r--r--src/lib/libcrypto/asn1/p7_evp.c6
-rw-r--r--src/lib/libcrypto/asn1/p7_i_s.c6
-rw-r--r--src/lib/libcrypto/asn1/p7_lib.c8
-rw-r--r--src/lib/libcrypto/asn1/p7_recip.c8
-rw-r--r--src/lib/libcrypto/asn1/p7_s_e.c4
-rw-r--r--src/lib/libcrypto/asn1/p7_signd.c4
-rw-r--r--src/lib/libcrypto/asn1/p7_signi.c10
-rw-r--r--src/lib/libcrypto/asn1/p8_key.c131
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c6
-rw-r--r--src/lib/libcrypto/asn1/pkcs8.c131
-rw-r--r--src/lib/libcrypto/asn1/t_bitst.c99
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c2
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c10
-rw-r--r--src/lib/libcrypto/asn1/t_req.c27
-rw-r--r--src/lib/libcrypto/asn1/t_spki.c116
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c9
-rw-r--r--src/lib/libcrypto/asn1/t_x509a.c102
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c2
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c2
-rw-r--r--src/lib/libcrypto/asn1/x_cinf.c16
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c57
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c15
-rw-r--r--src/lib/libcrypto/asn1/x_info.c3
-rw-r--r--src/lib/libcrypto/asn1/x_name.c2
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c8
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c118
-rw-r--r--src/lib/libcrypto/asn1/x_req.c18
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c6
-rw-r--r--src/lib/libcrypto/asn1/x_spki.c14
-rw-r--r--src/lib/libcrypto/asn1/x_val.c10
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c67
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c200
-rw-r--r--src/lib/libcrypto/bf/bf_cbc.c32
-rw-r--r--src/lib/libcrypto/bf/bf_cfb64.c4
-rw-r--r--src/lib/libcrypto/bf/bf_ecb.c12
-rw-r--r--src/lib/libcrypto/bf/bf_enc.c44
-rw-r--r--src/lib/libcrypto/bf/bf_locl.h6
-rw-r--r--src/lib/libcrypto/bf/bf_ofb64.c4
-rw-r--r--src/lib/libcrypto/bf/bf_opts.c2
-rw-r--r--src/lib/libcrypto/bf/bf_pi.h2
-rw-r--r--src/lib/libcrypto/bf/bf_skey.c4
-rw-r--r--src/lib/libcrypto/bf/bfspeed.c2
-rw-r--r--src/lib/libcrypto/bf/bftest.c12
-rw-r--r--src/lib/libcrypto/bf/blowfish.h24
-rw-r--r--src/lib/libcrypto/bio/Makefile.ssl48
-rw-r--r--src/lib/libcrypto/bio/b_dump.c4
-rw-r--r--src/lib/libcrypto/bio/b_print.c631
-rw-r--r--src/lib/libcrypto/bio/b_sock.c24
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c26
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c20
-rw-r--r--src/lib/libcrypto/bio/bf_null.c16
-rw-r--r--src/lib/libcrypto/bio/bio.h54
-rw-r--r--src/lib/libcrypto/bio/bio_err.c7
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c56
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c1
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c256
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c42
-rw-r--r--src/lib/libcrypto/bio/bss_file.c3
-rw-r--r--src/lib/libcrypto/bio/bss_log.c14
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c58
-rw-r--r--src/lib/libcrypto/bio/bss_null.c1
-rw-r--r--src/lib/libcrypto/bio/bss_rtcp.c1
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c5
-rw-r--r--src/lib/libcrypto/bn/Makefile.ssl104
-rw-r--r--src/lib/libcrypto/bn/asm/README9
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.s2415
-rw-r--r--src/lib/libcrypto/bn/asm/mips3.s143
-rw-r--r--src/lib/libcrypto/bn/bn.h135
-rw-r--r--src/lib/libcrypto/bn/bn_add.c4
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c145
-rw-r--r--src/lib/libcrypto/bn/bn_comba.c345
-rw-r--r--src/lib/libcrypto/bn/bn_ctx.c144
-rw-r--r--src/lib/libcrypto/bn/bn_div.c206
-rw-r--r--src/lib/libcrypto/bn/bn_err.c2
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c238
-rw-r--r--src/lib/libcrypto/bn/bn_exp2.c14
-rw-r--r--src/lib/libcrypto/bn/bn_gcd.c28
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h125
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c60
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c313
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c247
-rw-r--r--src/lib/libcrypto/bn/bn_opts.c324
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c378
-rw-r--r--src/lib/libcrypto/bn/bn_prime.h4
-rw-r--r--src/lib/libcrypto/bn/bn_prime.pl69
-rw-r--r--src/lib/libcrypto/bn/bn_print.c23
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c25
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c43
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c25
-rw-r--r--src/lib/libcrypto/bn/bn_word.c2
-rw-r--r--src/lib/libcrypto/bn/bnspeed.c2
-rw-r--r--src/lib/libcrypto/bn/bntest.c239
-rw-r--r--src/lib/libcrypto/bn/comba.pl285
-rw-r--r--src/lib/libcrypto/bn/d.c72
-rw-r--r--src/lib/libcrypto/bn/divtest.c41
-rw-r--r--src/lib/libcrypto/bn/exp.c2
-rw-r--r--src/lib/libcrypto/bn/expspeed.c2
-rw-r--r--src/lib/libcrypto/bn/exptest.c15
-rw-r--r--src/lib/libcrypto/bn/new23
-rw-r--r--src/lib/libcrypto/bn/old/b_sqr.c199
-rw-r--r--src/lib/libcrypto/bn/old/bn_com.c90
-rw-r--r--src/lib/libcrypto/bn/old/bn_high.c135
-rw-r--r--src/lib/libcrypto/bn/old/bn_ka.c567
-rw-r--r--src/lib/libcrypto/bn/old/bn_low.c194
-rw-r--r--src/lib/libcrypto/bn/old/bn_m.c139
-rw-r--r--src/lib/libcrypto/bn/old/bn_mul.c.works219
-rw-r--r--src/lib/libcrypto/bn/old/bn_wmul.c173
-rw-r--r--src/lib/libcrypto/bn/old/build3
-rw-r--r--src/lib/libcrypto/bn/old/info22
-rw-r--r--src/lib/libcrypto/bn/old/test.works205
-rw-r--r--src/lib/libcrypto/bn/test.c241
-rw-r--r--src/lib/libcrypto/buffer/Makefile.ssl3
-rw-r--r--src/lib/libcrypto/cast/c_ecb.c2
-rw-r--r--src/lib/libcrypto/cast/cast_lcl.h16
-rw-r--r--src/lib/libcrypto/cast/cast_s.h16
-rw-r--r--src/lib/libcrypto/cast/cast_spd.c2
-rw-r--r--src/lib/libcrypto/cast/castopts.c2
-rw-r--r--src/lib/libcrypto/cast/casttest.c18
-rw-r--r--src/lib/libcrypto/comp/comp.h1
-rw-r--r--src/lib/libcrypto/conf/conf.c32
-rw-r--r--src/lib/libcrypto/conf/conf.h2
-rw-r--r--src/lib/libcrypto/cryptlib.c6
-rw-r--r--src/lib/libcrypto/crypto-lib.com439
-rw-r--r--src/lib/libcrypto/crypto.h204
-rw-r--r--src/lib/libcrypto/des/Makefile.ssl14
-rw-r--r--src/lib/libcrypto/des/cbc3_enc.c20
-rw-r--r--src/lib/libcrypto/des/des.c22
-rw-r--r--src/lib/libcrypto/des/des.h7
-rw-r--r--src/lib/libcrypto/des/des_locl.h10
-rw-r--r--src/lib/libcrypto/des/des_opts.c10
-rw-r--r--src/lib/libcrypto/des/destest.c81
-rw-r--r--src/lib/libcrypto/des/enc_read.c4
-rw-r--r--src/lib/libcrypto/des/enc_writ.c13
-rw-r--r--src/lib/libcrypto/des/fcrypt.c10
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c2
-rw-r--r--src/lib/libcrypto/des/rand_key.c153
-rw-r--r--src/lib/libcrypto/des/read_pwd.c19
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c2
-rw-r--r--src/lib/libcrypto/des/set_key.c37
-rw-r--r--src/lib/libcrypto/des/speed.c10
-rw-r--r--src/lib/libcrypto/des/str2key.c20
-rw-r--r--src/lib/libcrypto/dh/Makefile.ssl20
-rw-r--r--src/lib/libcrypto/dh/dh.h51
-rw-r--r--src/lib/libcrypto/dh/dh_check.c10
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c19
-rw-r--r--src/lib/libcrypto/dh/dh_key.c65
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c92
-rw-r--r--src/lib/libcrypto/dh/dhtest.c12
-rw-r--r--src/lib/libcrypto/doc/DH_generate_key.pod50
-rw-r--r--src/lib/libcrypto/doc/DH_generate_parameters.pod72
-rw-r--r--src/lib/libcrypto/doc/DH_get_ex_new_index.pod36
-rw-r--r--src/lib/libcrypto/doc/DH_new.pod40
-rw-r--r--src/lib/libcrypto/doc/DH_set_method.pod99
-rw-r--r--src/lib/libcrypto/doc/DH_size.pod33
-rw-r--r--src/lib/libcrypto/doc/DSA_SIG_new.pod39
-rw-r--r--src/lib/libcrypto/doc/DSA_do_sign.pod47
-rw-r--r--src/lib/libcrypto/doc/DSA_dup_DH.pod36
-rw-r--r--src/lib/libcrypto/doc/DSA_generate_key.pod33
-rw-r--r--src/lib/libcrypto/doc/DSA_generate_parameters.pod105
-rw-r--r--src/lib/libcrypto/doc/DSA_get_ex_new_index.pod36
-rw-r--r--src/lib/libcrypto/doc/DSA_new.pod41
-rw-r--r--src/lib/libcrypto/doc/DSA_set_method.pod111
-rw-r--r--src/lib/libcrypto/doc/DSA_sign.pod66
-rw-r--r--src/lib/libcrypto/doc/DSA_size.pod33
-rw-r--r--src/lib/libcrypto/doc/ERR_GET_LIB.pod51
-rw-r--r--src/lib/libcrypto/doc/ERR_clear_error.pod29
-rw-r--r--src/lib/libcrypto/doc/ERR_error_string.pod65
-rw-r--r--src/lib/libcrypto/doc/ERR_get_error.pod62
-rw-r--r--src/lib/libcrypto/doc/ERR_load_crypto_strings.pod46
-rw-r--r--src/lib/libcrypto/doc/ERR_load_strings.pod54
-rw-r--r--src/lib/libcrypto/doc/ERR_print_errors.pod51
-rw-r--r--src/lib/libcrypto/doc/ERR_put_error.pod44
-rw-r--r--src/lib/libcrypto/doc/ERR_remove_state.pod34
-rw-r--r--src/lib/libcrypto/doc/EVP_DigestInit.pod197
-rw-r--r--src/lib/libcrypto/doc/EVP_EncryptInit.pod224
-rw-r--r--src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod46
-rw-r--r--src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod65
-rw-r--r--src/lib/libcrypto/doc/RAND_add.pod68
-rw-r--r--src/lib/libcrypto/doc/RAND_bytes.pod46
-rw-r--r--src/lib/libcrypto/doc/RAND_cleanup.pod29
-rw-r--r--src/lib/libcrypto/doc/RAND_load_file.pod53
-rw-r--r--src/lib/libcrypto/doc/RAND_set_rand_method.pod57
-rw-r--r--src/lib/libcrypto/doc/RSA_blinding_on.pod43
-rw-r--r--src/lib/libcrypto/doc/RSA_check_key.pod39
-rw-r--r--src/lib/libcrypto/doc/RSA_generate_key.pod68
-rw-r--r--src/lib/libcrypto/doc/RSA_get_ex_new_index.pod122
-rw-r--r--src/lib/libcrypto/doc/RSA_new.pod38
-rw-r--r--src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod124
-rw-r--r--src/lib/libcrypto/doc/RSA_print.pod48
-rw-r--r--src/lib/libcrypto/doc/RSA_private_encrypt.pod69
-rw-r--r--src/lib/libcrypto/doc/RSA_public_encrypt.pod86
-rw-r--r--src/lib/libcrypto/doc/RSA_set_method.pod153
-rw-r--r--src/lib/libcrypto/doc/RSA_sign.pod62
-rw-r--r--src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod59
-rw-r--r--src/lib/libcrypto/doc/RSA_size.pod33
-rw-r--r--src/lib/libcrypto/doc/bn.pod148
-rw-r--r--src/lib/libcrypto/doc/d2i_DHparams.pod30
-rw-r--r--src/lib/libcrypto/doc/d2i_RSAPublicKey.pod39
-rw-r--r--src/lib/libcrypto/doc/dh.pod68
-rw-r--r--src/lib/libcrypto/doc/dsa.pod104
-rw-r--r--src/lib/libcrypto/doc/lh_stats.pod60
-rw-r--r--src/lib/libcrypto/doc/rsa.pod115
-rw-r--r--src/lib/libcrypto/dsa/Makefile.ssl31
-rw-r--r--src/lib/libcrypto/dsa/dsa.h61
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c4
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c1
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c171
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c68
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c321
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c123
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c68
-rw-r--r--src/lib/libcrypto/dsa/dsatest.c28
-rw-r--r--src/lib/libcrypto/ebcdic.c217
-rw-r--r--src/lib/libcrypto/ebcdic.h14
-rw-r--r--src/lib/libcrypto/err/Makefile.ssl21
-rw-r--r--src/lib/libcrypto/err/err.c20
-rw-r--r--src/lib/libcrypto/err/err.h10
-rw-r--r--src/lib/libcrypto/err/err_all.c2
-rw-r--r--src/lib/libcrypto/err/openssl.ec5
-rw-r--r--src/lib/libcrypto/evp/Makefile.ssl46
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c18
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c30
-rw-r--r--src/lib/libcrypto/evp/bio_md.c17
-rw-r--r--src/lib/libcrypto/evp/bio_ok.c33
-rw-r--r--src/lib/libcrypto/evp/c_all.c136
-rw-r--r--src/lib/libcrypto/evp/c_allc.c149
-rw-r--r--src/lib/libcrypto/evp/c_alld.c100
-rw-r--r--src/lib/libcrypto/evp/e_cbc_3d.c10
-rw-r--r--src/lib/libcrypto/evp/e_cbc_d.c2
-rw-r--r--src/lib/libcrypto/evp/e_cfb_3d.c10
-rw-r--r--src/lib/libcrypto/evp/e_cfb_d.c2
-rw-r--r--src/lib/libcrypto/evp/e_ecb_3d.c10
-rw-r--r--src/lib/libcrypto/evp/e_ecb_d.c2
-rw-r--r--src/lib/libcrypto/evp/e_ofb_3d.c10
-rw-r--r--src/lib/libcrypto/evp/e_ofb_d.c2
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c2
-rw-r--r--src/lib/libcrypto/evp/encode.c4
-rw-r--r--src/lib/libcrypto/evp/evp.h43
-rw-r--r--src/lib/libcrypto/evp/evp_err.c8
-rw-r--r--src/lib/libcrypto/evp/evp_key.c11
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c6
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c265
-rw-r--r--src/lib/libcrypto/evp/p_lib.c64
-rw-r--r--src/lib/libcrypto/evp/p_open.c6
-rw-r--r--src/lib/libcrypto/evp/p_seal.c5
-rw-r--r--src/lib/libcrypto/ex_data.c40
-rw-r--r--src/lib/libcrypto/hmac/hmac.c4
-rw-r--r--src/lib/libcrypto/hmac/hmac.h4
-rw-r--r--src/lib/libcrypto/hmac/hmactest.c2
-rw-r--r--src/lib/libcrypto/install.com1
-rw-r--r--src/lib/libcrypto/lhash/Makefile.ssl7
-rw-r--r--src/lib/libcrypto/lhash/lhash.c40
-rw-r--r--src/lib/libcrypto/lhash/lhash.h14
-rw-r--r--src/lib/libcrypto/md2/Makefile.ssl4
-rw-r--r--src/lib/libcrypto/md2/md2.h4
-rw-r--r--src/lib/libcrypto/md2/md2_dgst.c8
-rw-r--r--src/lib/libcrypto/md2/md2_one.c2
-rw-r--r--src/lib/libcrypto/md2/md2test.c4
-rw-r--r--src/lib/libcrypto/md32_common.h41
-rw-r--r--src/lib/libcrypto/md5/Makefile.ssl9
-rw-r--r--src/lib/libcrypto/md5/md5.h4
-rw-r--r--src/lib/libcrypto/md5/md5_dgst.c154
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h17
-rw-r--r--src/lib/libcrypto/md5/md5_one.c2
-rw-r--r--src/lib/libcrypto/md5/md5test.c4
-rw-r--r--src/lib/libcrypto/mdc2/Makefile.ssl4
-rw-r--r--src/lib/libcrypto/mdc2/mdc2.h5
-rw-r--r--src/lib/libcrypto/mem.c432
-rw-r--r--src/lib/libcrypto/mem_dbg.c703
-rw-r--r--src/lib/libcrypto/objects/Makefile.ssl3
-rw-r--r--src/lib/libcrypto/objects/o_names.c106
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c22
-rw-r--r--src/lib/libcrypto/objects/obj_dat.pl54
-rw-r--r--src/lib/libcrypto/objects/objects.h74
-rw-r--r--src/lib/libcrypto/opensslconf.h.in19
-rw-r--r--src/lib/libcrypto/opensslv.h6
-rw-r--r--src/lib/libcrypto/pem/pem.h38
-rw-r--r--src/lib/libcrypto/pem/pem_all.c94
-rw-r--r--src/lib/libcrypto/pem/pem_err.c3
-rw-r--r--src/lib/libcrypto/pem/pem_info.c11
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c222
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c6
-rw-r--r--src/lib/libcrypto/perlasm/x86ms.pl9
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl6
-rw-r--r--src/lib/libcrypto/pkcs12/Makefile.ssl23
-rw-r--r--src/lib/libcrypto/pkcs12/p12_add.c26
-rw-r--r--src/lib/libcrypto/pkcs12/p12_attr.c10
-rw-r--r--src/lib/libcrypto/pkcs12/p12_bags.c8
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crpt.c2
-rw-r--r--src/lib/libcrypto/pkcs12/p12_decr.c2
-rw-r--r--src/lib/libcrypto/pkcs12/p12_init.c6
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c23
-rw-r--r--src/lib/libcrypto/pkcs12/p12_kiss.c30
-rw-r--r--src/lib/libcrypto/pkcs12/p12_lib.c4
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mac.c16
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c13
-rw-r--r--src/lib/libcrypto/pkcs12/p12_npas.c212
-rw-r--r--src/lib/libcrypto/pkcs12/pk12err.c2
-rw-r--r--src/lib/libcrypto/pkcs12/pkcs12.h3
-rw-r--r--src/lib/libcrypto/pkcs7/Makefile.ssl85
-rw-r--r--src/lib/libcrypto/pkcs7/bio_ber.c18
-rw-r--r--src/lib/libcrypto/pkcs7/dec.c12
-rw-r--r--src/lib/libcrypto/pkcs7/enc.c15
-rw-r--r--src/lib/libcrypto/pkcs7/example.c15
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c85
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c121
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c54
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_mime.c673
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c427
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.h85
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7err.c39
-rw-r--r--src/lib/libcrypto/pkcs7/sign.c13
-rw-r--r--src/lib/libcrypto/pkcs7/verify.c11
-rw-r--r--src/lib/libcrypto/rand/Makefile.ssl17
-rw-r--r--src/lib/libcrypto/rand/md_rand.c312
-rw-r--r--src/lib/libcrypto/rand/md_rand_munged.c515
-rw-r--r--src/lib/libcrypto/rand/rand.h29
-rw-r--r--src/lib/libcrypto/rand/rand_egd.c110
-rw-r--r--src/lib/libcrypto/rand/rand_err.c93
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c18
-rw-r--r--src/lib/libcrypto/rand/randfile.c108
-rw-r--r--src/lib/libcrypto/rand/randtest.c2
-rw-r--r--src/lib/libcrypto/rc2/rc2speed.c2
-rw-r--r--src/lib/libcrypto/rc2/rc2test.c6
-rw-r--r--src/lib/libcrypto/rc4/rc4.h4
-rw-r--r--src/lib/libcrypto/rc4/rc4_enc.c186
-rw-r--r--src/lib/libcrypto/rc4/rc4_skey.c2
-rw-r--r--src/lib/libcrypto/rc4/rc4speed.c2
-rw-r--r--src/lib/libcrypto/rc4/rc4test.c8
-rw-r--r--src/lib/libcrypto/ripemd/Makefile.ssl5
-rw-r--r--src/lib/libcrypto/ripemd/asm/rips.cpp6
-rw-r--r--src/lib/libcrypto/ripemd/asm/rm-win32.asm3433
-rw-r--r--src/lib/libcrypto/ripemd/asm/rmd-586.pl108
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.h27
-rw-r--r--src/lib/libcrypto/ripemd/rmd_dgst.c448
-rw-r--r--src/lib/libcrypto/ripemd/rmd_locl.h184
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c5
-rw-r--r--src/lib/libcrypto/ripemd/rmdtest.c4
-rw-r--r--src/lib/libcrypto/rsa/Makefile.ssl45
-rw-r--r--src/lib/libcrypto/rsa/rsa.h33
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c5
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c1
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c24
-rw-r--r--src/lib/libcrypto/rsa/rsa_null.c149
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c3
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep_test.c309
-rw-r--r--src/lib/libcrypto/rsa/rsa_pk1.c18
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c2
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c153
-rw-r--r--src/lib/libcrypto/rsa/rsa_ssl.c11
-rw-r--r--src/lib/libcrypto/rsa/rsa_test.c314
-rw-r--r--src/lib/libcrypto/sha/Makefile.ssl4
-rw-r--r--src/lib/libcrypto/sha/asm/s1-win32.asm1138
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl107
-rw-r--r--src/lib/libcrypto/sha/sha.h10
-rw-r--r--src/lib/libcrypto/sha/sha1dgst.c437
-rw-r--r--src/lib/libcrypto/sha/sha1s.cpp5
-rw-r--r--src/lib/libcrypto/sha/sha1test.c10
-rw-r--r--src/lib/libcrypto/sha/sha_dgst.c435
-rw-r--r--src/lib/libcrypto/sha/sha_locl.h563
-rw-r--r--src/lib/libcrypto/sha/shatest.c10
-rw-r--r--src/lib/libcrypto/stack/Makefile.ssl3
-rw-r--r--src/lib/libcrypto/stack/stack.c8
-rw-r--r--src/lib/libcrypto/stack/stack.h4
-rw-r--r--src/lib/libcrypto/threads/README14
-rw-r--r--src/lib/libcrypto/threads/mttest.c122
-rw-r--r--src/lib/libcrypto/threads/profile.sh4
-rw-r--r--src/lib/libcrypto/threads/ptest.bat4
-rw-r--r--src/lib/libcrypto/threads/pthread.sh9
-rw-r--r--src/lib/libcrypto/threads/pthread2.sh7
-rw-r--r--src/lib/libcrypto/threads/pthreads-vms.com9
-rw-r--r--src/lib/libcrypto/threads/purify.sh4
-rw-r--r--src/lib/libcrypto/threads/solaris.sh4
-rw-r--r--src/lib/libcrypto/threads/th-lock.c55
-rw-r--r--src/lib/libcrypto/threads/win32.bat4
-rw-r--r--src/lib/libcrypto/txt_db/Makefile.ssl5
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.c8
-rw-r--r--src/lib/libcrypto/util/domd2
-rw-r--r--src/lib/libcrypto/util/libeay.num403
-rw-r--r--src/lib/libcrypto/util/mkdef.pl139
-rw-r--r--src/lib/libcrypto/util/mkerr.pl2
-rw-r--r--src/lib/libcrypto/util/pl/BC-32.pl2
-rw-r--r--src/lib/libcrypto/util/pl/Mingw32.pl2
-rw-r--r--src/lib/libcrypto/util/pl/VC-32.pl2
-rw-r--r--src/lib/libcrypto/util/pod2man.pl1181
-rw-r--r--src/lib/libcrypto/util/selftest.pl174
-rw-r--r--src/lib/libcrypto/util/ssleay.num10
-rw-r--r--src/lib/libcrypto/x509/Makefile.ssl123
-rw-r--r--src/lib/libcrypto/x509/by_dir.c19
-rw-r--r--src/lib/libcrypto/x509/by_file.c63
-rw-r--r--src/lib/libcrypto/x509/x509.h239
-rw-r--r--src/lib/libcrypto/x509/x509_att.c326
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c23
-rw-r--r--src/lib/libcrypto/x509/x509_d2.c8
-rw-r--r--src/lib/libcrypto/x509/x509_def.c2
-rw-r--r--src/lib/libcrypto/x509/x509_err.c17
-rw-r--r--src/lib/libcrypto/x509/x509_ext.c17
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c26
-rw-r--r--src/lib/libcrypto/x509/x509_r2x.c2
-rw-r--r--src/lib/libcrypto/x509/x509_req.c165
-rw-r--r--src/lib/libcrypto/x509/x509_set.c14
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c263
-rw-r--r--src/lib/libcrypto/x509/x509_txt.c11
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c3
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c206
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.h20
-rw-r--r--src/lib/libcrypto/x509/x509name.c66
-rw-r--r--src/lib/libcrypto/x509/x509spki.c121
-rw-r--r--src/lib/libcrypto/x509/x_all.c100
-rw-r--r--src/lib/libcrypto/x509v3/Makefile.ssl43
-rw-r--r--src/lib/libcrypto/x509v3/README4
-rw-r--r--src/lib/libcrypto/x509v3/ext_dat.h97
-rw-r--r--src/lib/libcrypto/x509v3/tabtest.c88
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c12
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c9
-rw-r--r--src/lib/libcrypto/x509v3/v3_bcons.c4
-rw-r--r--src/lib/libcrypto/x509v3/v3_bitst.c10
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c34
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c14
-rw-r--r--src/lib/libcrypto/x509v3/v3_crld.c18
-rw-r--r--src/lib/libcrypto/x509v3/v3_enum.c13
-rw-r--r--src/lib/libcrypto/x509v3/v3_genn.c70
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c13
-rw-r--r--src/lib/libcrypto/x509v3/v3_info.c236
-rw-r--r--src/lib/libcrypto/x509v3/v3_int.c13
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c88
-rw-r--r--src/lib/libcrypto/x509v3/v3_pku.c6
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c16
-rw-r--r--src/lib/libcrypto/x509v3/v3_purp.c456
-rw-r--r--src/lib/libcrypto/x509v3/v3_skey.c21
-rw-r--r--src/lib/libcrypto/x509v3/v3_sxnet.c28
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3err.c4
-rw-r--r--src/lib/libcrypto/x509v3/x509v3.h135
489 files changed, 27215 insertions, 12148 deletions
diff --git a/src/lib/libcrypto/Attic/Makefile b/src/lib/libcrypto/Attic/Makefile
index f4813d3aaa..c0b6e906a8 100644
--- a/src/lib/libcrypto/Attic/Makefile
+++ b/src/lib/libcrypto/Attic/Makefile
@@ -34,8 +34,8 @@ SDIRS= md2 md5 sha mdc2 hmac ripemd \
34GENERAL=Makefile README crypto-lib.com install.com 34GENERAL=Makefile README crypto-lib.com install.com
35 35
36LIB= $(TOP)/libcrypto.a 36LIB= $(TOP)/libcrypto.a
37LIBSRC= cryptlib.c mem.c cversion.c ex_data.c tmdiff.c cpt_err.c 37LIBSRC= cryptlib.c mem.c mem_dbg.c cversion.c ex_data.c tmdiff.c cpt_err.c ebcdic.c
38LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o tmdiff.o cpt_err.o 38LIBOBJ= cryptlib.o mem.o mem_dbg.o cversion.o ex_data.o tmdiff.o cpt_err.o ebcdic.o
39 39
40SRC= $(LIBSRC) 40SRC= $(LIBSRC)
41 41
@@ -57,6 +57,11 @@ buildinf.h: ../Makefile.ssl
57 echo " #define DATE \"`date`\""; \ 57 echo " #define DATE \"`date`\""; \
58 echo "#endif" ) >buildinf.h 58 echo "#endif" ) >buildinf.h
59 59
60testapps:
61 if echo ${SDIRS} | fgrep ' des '; \
62 then cd des && $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' des; fi
63 cd pkcs7 && $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' testapps
64
60subdirs: 65subdirs:
61 @for i in $(SDIRS) ;\ 66 @for i in $(SDIRS) ;\
62 do \ 67 do \
@@ -122,7 +127,7 @@ lint:
122 done; 127 done;
123 128
124depend: 129depend:
125 if [ ! -e buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist 130 if [ ! -f buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist
126 $(MAKEDEPEND) $(INCLUDE) $(DEPFLAG) $(PROGS) $(LIBSRC) 131 $(MAKEDEPEND) $(INCLUDE) $(DEPFLAG) $(PROGS) $(LIBSRC)
127 if [ ! -s buildinf.h ]; then rm buildinf.h; fi 132 if [ ! -s buildinf.h ]; then rm buildinf.h; fi
128 @for i in $(SDIRS) ;\ 133 @for i in $(SDIRS) ;\
@@ -151,29 +156,40 @@ dclean:
151# DO NOT DELETE THIS LINE -- make depend depends on it. 156# DO NOT DELETE THIS LINE -- make depend depends on it.
152 157
153cpt_err.o: ../include/openssl/crypto.h ../include/openssl/err.h 158cpt_err.o: ../include/openssl/crypto.h ../include/openssl/err.h
154cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/stack.h 159cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/safestack.h
160cpt_err.o: ../include/openssl/stack.h
155cryptlib.o: ../include/openssl/bio.h ../include/openssl/buffer.h 161cryptlib.o: ../include/openssl/bio.h ../include/openssl/buffer.h
156cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 162cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
157cryptlib.o: ../include/openssl/e_os2.h ../include/openssl/err.h 163cryptlib.o: ../include/openssl/e_os2.h ../include/openssl/err.h
158cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h 164cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
159cryptlib.o: ../include/openssl/stack.h cryptlib.h 165cryptlib.o: ../include/openssl/safestack.h ../include/openssl/stack.h
166cryptlib.o: cryptlib.h
160cversion.o: ../include/openssl/bio.h ../include/openssl/buffer.h 167cversion.o: ../include/openssl/bio.h ../include/openssl/buffer.h
161cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 168cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
162cversion.o: ../include/openssl/e_os2.h ../include/openssl/err.h 169cversion.o: ../include/openssl/e_os2.h ../include/openssl/err.h
163cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h 170cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
164cversion.o: ../include/openssl/stack.h buildinf.h cryptlib.h 171cversion.o: ../include/openssl/safestack.h ../include/openssl/stack.h
172cversion.o: buildinf.h cryptlib.h
165ex_data.o: ../include/openssl/bio.h ../include/openssl/buffer.h 173ex_data.o: ../include/openssl/bio.h ../include/openssl/buffer.h
166ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 174ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
167ex_data.o: ../include/openssl/e_os2.h ../include/openssl/err.h 175ex_data.o: ../include/openssl/e_os2.h ../include/openssl/err.h
168ex_data.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h 176ex_data.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
169ex_data.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h 177ex_data.o: ../include/openssl/opensslv.h ../include/openssl/safestack.h
178ex_data.o: ../include/openssl/stack.h cryptlib.h
170mem.o: ../include/openssl/bio.h ../include/openssl/buffer.h 179mem.o: ../include/openssl/bio.h ../include/openssl/buffer.h
171mem.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 180mem.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
172mem.o: ../include/openssl/e_os2.h ../include/openssl/err.h 181mem.o: ../include/openssl/e_os2.h ../include/openssl/err.h
173mem.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h 182mem.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
174mem.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h 183mem.o: ../include/openssl/safestack.h ../include/openssl/stack.h cryptlib.h
184mem_dbg.o: ../include/openssl/bio.h ../include/openssl/buffer.h
185mem_dbg.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
186mem_dbg.o: ../include/openssl/e_os2.h ../include/openssl/err.h
187mem_dbg.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
188mem_dbg.o: ../include/openssl/opensslv.h ../include/openssl/safestack.h
189mem_dbg.o: ../include/openssl/stack.h cryptlib.h
175tmdiff.o: ../include/openssl/bio.h ../include/openssl/buffer.h 190tmdiff.o: ../include/openssl/bio.h ../include/openssl/buffer.h
176tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 191tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
177tmdiff.o: ../include/openssl/e_os2.h ../include/openssl/err.h 192tmdiff.o: ../include/openssl/e_os2.h ../include/openssl/err.h
178tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h 193tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
179tmdiff.o: ../include/openssl/stack.h ../include/openssl/tmdiff.h cryptlib.h 194tmdiff.o: ../include/openssl/safestack.h ../include/openssl/stack.h
195tmdiff.o: ../include/openssl/tmdiff.h cryptlib.h
diff --git a/src/lib/libcrypto/Makefile.ssl b/src/lib/libcrypto/Makefile.ssl
index 2fcbf18545..cab75d9f80 100644
--- a/src/lib/libcrypto/Makefile.ssl
+++ b/src/lib/libcrypto/Makefile.ssl
@@ -34,8 +34,8 @@ SDIRS= md2 md5 sha mdc2 hmac ripemd \
34GENERAL=Makefile README crypto-lib.com install.com 34GENERAL=Makefile README crypto-lib.com install.com
35 35
36LIB= $(TOP)/libcrypto.a 36LIB= $(TOP)/libcrypto.a
37LIBSRC= cryptlib.c mem.c cversion.c ex_data.c tmdiff.c cpt_err.c 37LIBSRC= cryptlib.c mem.c mem_dbg.c cversion.c ex_data.c tmdiff.c cpt_err.c ebcdic.c
38LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o tmdiff.o cpt_err.o 38LIBOBJ= cryptlib.o mem.o mem_dbg.o cversion.o ex_data.o tmdiff.o cpt_err.o ebcdic.o
39 39
40SRC= $(LIBSRC) 40SRC= $(LIBSRC)
41 41
@@ -57,6 +57,11 @@ buildinf.h: ../Makefile.ssl
57 echo " #define DATE \"`date`\""; \ 57 echo " #define DATE \"`date`\""; \
58 echo "#endif" ) >buildinf.h 58 echo "#endif" ) >buildinf.h
59 59
60testapps:
61 if echo ${SDIRS} | fgrep ' des '; \
62 then cd des && $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' des; fi
63 cd pkcs7 && $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' testapps
64
60subdirs: 65subdirs:
61 @for i in $(SDIRS) ;\ 66 @for i in $(SDIRS) ;\
62 do \ 67 do \
@@ -122,7 +127,7 @@ lint:
122 done; 127 done;
123 128
124depend: 129depend:
125 if [ ! -e buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist 130 if [ ! -f buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist
126 $(MAKEDEPEND) $(INCLUDE) $(DEPFLAG) $(PROGS) $(LIBSRC) 131 $(MAKEDEPEND) $(INCLUDE) $(DEPFLAG) $(PROGS) $(LIBSRC)
127 if [ ! -s buildinf.h ]; then rm buildinf.h; fi 132 if [ ! -s buildinf.h ]; then rm buildinf.h; fi
128 @for i in $(SDIRS) ;\ 133 @for i in $(SDIRS) ;\
@@ -151,29 +156,40 @@ dclean:
151# DO NOT DELETE THIS LINE -- make depend depends on it. 156# DO NOT DELETE THIS LINE -- make depend depends on it.
152 157
153cpt_err.o: ../include/openssl/crypto.h ../include/openssl/err.h 158cpt_err.o: ../include/openssl/crypto.h ../include/openssl/err.h
154cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/stack.h 159cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/safestack.h
160cpt_err.o: ../include/openssl/stack.h
155cryptlib.o: ../include/openssl/bio.h ../include/openssl/buffer.h 161cryptlib.o: ../include/openssl/bio.h ../include/openssl/buffer.h
156cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 162cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
157cryptlib.o: ../include/openssl/e_os2.h ../include/openssl/err.h 163cryptlib.o: ../include/openssl/e_os2.h ../include/openssl/err.h
158cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h 164cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
159cryptlib.o: ../include/openssl/stack.h cryptlib.h 165cryptlib.o: ../include/openssl/safestack.h ../include/openssl/stack.h
166cryptlib.o: cryptlib.h
160cversion.o: ../include/openssl/bio.h ../include/openssl/buffer.h 167cversion.o: ../include/openssl/bio.h ../include/openssl/buffer.h
161cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 168cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
162cversion.o: ../include/openssl/e_os2.h ../include/openssl/err.h 169cversion.o: ../include/openssl/e_os2.h ../include/openssl/err.h
163cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h 170cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
164cversion.o: ../include/openssl/stack.h buildinf.h cryptlib.h 171cversion.o: ../include/openssl/safestack.h ../include/openssl/stack.h
172cversion.o: buildinf.h cryptlib.h
165ex_data.o: ../include/openssl/bio.h ../include/openssl/buffer.h 173ex_data.o: ../include/openssl/bio.h ../include/openssl/buffer.h
166ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 174ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
167ex_data.o: ../include/openssl/e_os2.h ../include/openssl/err.h 175ex_data.o: ../include/openssl/e_os2.h ../include/openssl/err.h
168ex_data.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h 176ex_data.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
169ex_data.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h 177ex_data.o: ../include/openssl/opensslv.h ../include/openssl/safestack.h
178ex_data.o: ../include/openssl/stack.h cryptlib.h
170mem.o: ../include/openssl/bio.h ../include/openssl/buffer.h 179mem.o: ../include/openssl/bio.h ../include/openssl/buffer.h
171mem.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 180mem.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
172mem.o: ../include/openssl/e_os2.h ../include/openssl/err.h 181mem.o: ../include/openssl/e_os2.h ../include/openssl/err.h
173mem.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h 182mem.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
174mem.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h 183mem.o: ../include/openssl/safestack.h ../include/openssl/stack.h cryptlib.h
184mem_dbg.o: ../include/openssl/bio.h ../include/openssl/buffer.h
185mem_dbg.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
186mem_dbg.o: ../include/openssl/e_os2.h ../include/openssl/err.h
187mem_dbg.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
188mem_dbg.o: ../include/openssl/opensslv.h ../include/openssl/safestack.h
189mem_dbg.o: ../include/openssl/stack.h cryptlib.h
175tmdiff.o: ../include/openssl/bio.h ../include/openssl/buffer.h 190tmdiff.o: ../include/openssl/bio.h ../include/openssl/buffer.h
176tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os.h 191tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
177tmdiff.o: ../include/openssl/e_os2.h ../include/openssl/err.h 192tmdiff.o: ../include/openssl/e_os2.h ../include/openssl/err.h
178tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h 193tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
179tmdiff.o: ../include/openssl/stack.h ../include/openssl/tmdiff.h cryptlib.h 194tmdiff.o: ../include/openssl/safestack.h ../include/openssl/stack.h
195tmdiff.o: ../include/openssl/tmdiff.h cryptlib.h
diff --git a/src/lib/libcrypto/asn1/Makefile.ssl b/src/lib/libcrypto/asn1/Makefile.ssl
index 5d668411f6..a17a713a75 100644
--- a/src/lib/libcrypto/asn1/Makefile.ssl
+++ b/src/lib/libcrypto/asn1/Makefile.ssl
@@ -23,34 +23,34 @@ APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \ 25LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
26 a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \ 26 a_null.c a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \
27 a_enum.c a_vis.c a_utf8.c a_sign.c a_digest.c a_verify.c \ 27 a_enum.c a_vis.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c \
28 x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \ 28 x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \
29 x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c nsseq.c \ 29 x_name.c x_cinf.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c \
30 d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \ 30 d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \
31 d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \ 31 d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \
32 d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\ 32 d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\
33 t_req.c t_x509.c t_crl.c t_pkey.c \ 33 t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c \
34 p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \ 34 p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \
35 p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \ 35 p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \
36 f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \ 36 f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \
37 f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c \ 37 f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c \
38 asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c \ 38 asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c a_strnid.c \
39 evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c 39 evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c
40LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \ 40LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
41 a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \ 41 a_null.o a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \
42 a_enum.o a_vis.o a_utf8.o a_sign.o a_digest.o a_verify.o \ 42 a_enum.o a_vis.o a_utf8.o a_sign.o a_digest.o a_verify.o a_mbstr.o \
43 x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \ 43 x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \
44 x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o nsseq.o \ 44 x_name.o x_cinf.o x_x509.o x_x509a.o x_crl.o x_info.o x_spki.o nsseq.o \
45 d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \ 45 d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \
46 d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \ 46 d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \
47 d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \ 47 d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \
48 t_req.o t_x509.o t_crl.o t_pkey.o \ 48 t_req.o t_x509.o t_x509a.o t_crl.o t_pkey.o t_spki.o t_bitst.o \
49 p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \ 49 p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \
50 p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \ 50 p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \
51 f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \ 51 f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \
52 f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o \ 52 f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o \
53 asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o \ 53 asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o a_strnid.o \
54 evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o 54 evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o
55 55
56SRC= $(LIBSRC) 56SRC= $(LIBSRC)
@@ -160,11 +160,13 @@ a_digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
160a_digest.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 160a_digest.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
161a_digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 161a_digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
162a_digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 162a_digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
163a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h 163a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
164a_digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h 164a_digest.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
165a_digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h 165a_digest.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
166a_digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 166a_digest.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
167a_digest.o: ../../include/openssl/stack.h ../cryptlib.h 167a_digest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
168a_digest.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
169a_digest.o: ../cryptlib.h
168a_dup.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h 170a_dup.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
169a_dup.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 171a_dup.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
170a_dup.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 172a_dup.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
@@ -207,6 +209,13 @@ a_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
207a_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 209a_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
208a_int.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 210a_int.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
209a_int.o: ../cryptlib.h 211a_int.o: ../cryptlib.h
212a_mbstr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
213a_mbstr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
214a_mbstr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
215a_mbstr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
216a_mbstr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
217a_mbstr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
218a_mbstr.o: ../cryptlib.h
210a_meth.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 219a_meth.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
211a_meth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 220a_meth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
212a_meth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 221a_meth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
@@ -214,6 +223,13 @@ a_meth.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
214a_meth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 223a_meth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
215a_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 224a_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
216a_meth.o: ../cryptlib.h 225a_meth.o: ../cryptlib.h
226a_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
227a_null.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
228a_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
229a_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
230a_null.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
231a_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
232a_null.o: ../cryptlib.h
217a_object.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 233a_object.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
218a_object.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 234a_object.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
219a_object.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 235a_object.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
@@ -259,6 +275,13 @@ a_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
259a_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 275a_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
260a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 276a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
261a_sign.o: ../cryptlib.h 277a_sign.o: ../cryptlib.h
278a_strnid.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
279a_strnid.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
280a_strnid.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
281a_strnid.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
282a_strnid.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
283a_strnid.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
284a_strnid.o: ../../include/openssl/stack.h ../cryptlib.h
262a_time.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 285a_time.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
263a_time.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 286a_time.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
264a_time.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 287a_time.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
@@ -788,6 +811,24 @@ p8_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
788p8_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 811p8_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
789p8_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h 812p8_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
790p8_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h 813p8_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
814t_bitst.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
815t_bitst.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
816t_bitst.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
817t_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
818t_bitst.o: ../../include/openssl/des.h ../../include/openssl/dh.h
819t_bitst.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
820t_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
821t_bitst.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
822t_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
823t_bitst.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
824t_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
825t_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
826t_bitst.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
827t_bitst.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
828t_bitst.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
829t_bitst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
830t_bitst.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
831t_bitst.o: ../../include/openssl/x509v3.h ../cryptlib.h
791t_crl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 832t_crl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
792t_crl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 833t_crl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
793t_crl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 834t_crl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -812,15 +853,17 @@ t_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
812t_pkey.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 853t_pkey.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
813t_pkey.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 854t_pkey.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
814t_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h 855t_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
815t_pkey.o: ../../include/openssl/stack.h ../cryptlib.h 856t_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
857t_pkey.o: ../cryptlib.h
816t_req.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 858t_req.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
817t_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 859t_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
818t_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 860t_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
819t_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 861t_req.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
820t_req.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 862t_req.o: ../../include/openssl/des.h ../../include/openssl/dh.h
821t_req.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 863t_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
822t_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h 864t_req.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
823t_req.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 865t_req.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
866t_req.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
824t_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 867t_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
825t_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 868t_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
826t_req.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h 869t_req.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
@@ -829,7 +872,24 @@ t_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
829t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 872t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
830t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 873t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
831t_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 874t_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
832t_req.o: ../cryptlib.h 875t_req.o: ../../include/openssl/x509v3.h ../cryptlib.h
876t_spki.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
877t_spki.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
878t_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
879t_spki.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
880t_spki.o: ../../include/openssl/des.h ../../include/openssl/dh.h
881t_spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
882t_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
883t_spki.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
884t_spki.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
885t_spki.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
886t_spki.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
887t_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
888t_spki.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
889t_spki.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
890t_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
891t_spki.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
892t_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
833t_x509.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 893t_x509.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
834t_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 894t_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
835t_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 895t_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -848,6 +908,23 @@ t_x509.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
848t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 908t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
849t_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 909t_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
850t_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h 910t_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h
911t_x509a.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
912t_x509a.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
913t_x509a.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
914t_x509a.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
915t_x509a.o: ../../include/openssl/des.h ../../include/openssl/dh.h
916t_x509a.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
917t_x509a.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
918t_x509a.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
919t_x509a.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
920t_x509a.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
921t_x509a.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
922t_x509a.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
923t_x509a.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
924t_x509a.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
925t_x509a.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
926t_x509a.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
927t_x509a.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
851x_algor.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h 928x_algor.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
852x_algor.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h 929x_algor.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
853x_algor.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 930x_algor.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
@@ -1088,3 +1165,20 @@ x_x509.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1088x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 1165x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1089x_x509.o: ../../include/openssl/stack.h ../../include/openssl/x509.h 1166x_x509.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1090x_x509.o: ../../include/openssl/x509_vfy.h ../cryptlib.h 1167x_x509.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
1168x_x509a.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
1169x_x509a.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1170x_x509a.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1171x_x509a.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1172x_x509a.o: ../../include/openssl/des.h ../../include/openssl/dh.h
1173x_x509a.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
1174x_x509a.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1175x_x509a.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1176x_x509a.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
1177x_x509a.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
1178x_x509a.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1179x_x509a.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1180x_x509a.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1181x_x509a.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1182x_x509a.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1183x_x509a.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1184x_x509a.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index 38ea802be8..c77456b315 100644
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -60,6 +60,15 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_BIT_STRING *ASN1_BIT_STRING_new(void)
64{ return M_ASN1_BIT_STRING_new(); }
65
66void ASN1_BIT_STRING_free(ASN1_BIT_STRING *x)
67{ M_ASN1_BIT_STRING_free(x); }
68
69int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
70{ return M_ASN1_BIT_STRING_set(x, d, len); }
71
63int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) 72int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
64 { 73 {
65 int ret,j,r,bits,len; 74 int ret,j,r,bits,len;
@@ -121,7 +130,7 @@ ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
121 130
122 if ((a == NULL) || ((*a) == NULL)) 131 if ((a == NULL) || ((*a) == NULL))
123 { 132 {
124 if ((ret=ASN1_BIT_STRING_new()) == NULL) return(NULL); 133 if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL);
125 } 134 }
126 else 135 else
127 ret=(*a); 136 ret=(*a);
@@ -164,7 +173,7 @@ ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
164 s=NULL; 173 s=NULL;
165 174
166 ret->length=(int)len; 175 ret->length=(int)len;
167 if (ret->data != NULL) Free((char *)ret->data); 176 if (ret->data != NULL) Free(ret->data);
168 ret->data=s; 177 ret->data=s;
169 ret->type=V_ASN1_BIT_STRING; 178 ret->type=V_ASN1_BIT_STRING;
170 if (a != NULL) (*a)=ret; 179 if (a != NULL) (*a)=ret;
@@ -173,7 +182,7 @@ ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
173err: 182err:
174 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i); 183 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
175 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 184 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
176 ASN1_BIT_STRING_free(ret); 185 M_ASN1_BIT_STRING_free(ret);
177 return(NULL); 186 return(NULL);
178 } 187 }
179 188
diff --git a/src/lib/libcrypto/asn1/a_bmp.c b/src/lib/libcrypto/asn1/a_bmp.c
index 6075871984..d9ac5a0475 100644
--- a/src/lib/libcrypto/asn1/a_bmp.c
+++ b/src/lib/libcrypto/asn1/a_bmp.c
@@ -60,6 +60,12 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_BMPSTRING *ASN1_BMPSTRING_new(void)
64{ return M_ASN1_BMPSTRING_new(); }
65
66void ASN1_BMPSTRING_free(ASN1_BMPSTRING *x)
67{ M_ASN1_BMPSTRING_free(x); }
68
63int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp) 69int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp)
64 { 70 {
65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 71 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
index e452e03b88..8cde695804 100644
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ b/src/lib/libcrypto/asn1/a_bytes.c
@@ -71,7 +71,7 @@ B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0,
71B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, 71B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN,
72 }; 72 };
73 73
74static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c); 74static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c);
75/* type is a 'bitmap' of acceptable string types. 75/* type is a 'bitmap' of acceptable string types.
76 */ 76 */
77ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp, 77ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
@@ -124,7 +124,7 @@ ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
124 else 124 else
125 s=NULL; 125 s=NULL;
126 126
127 if (ret->data != NULL) Free((char *)ret->data); 127 if (ret->data != NULL) Free(ret->data);
128 ret->length=(int)len; 128 ret->length=(int)len;
129 ret->data=s; 129 ret->data=s;
130 ret->type=tag; 130 ret->type=tag;
@@ -205,7 +205,7 @@ ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
205 c.tag=Ptag; 205 c.tag=Ptag;
206 c.xclass=Pclass; 206 c.xclass=Pclass;
207 c.max=(length == 0)?0:(p+length); 207 c.max=(length == 0)?0:(p+length);
208 if (!asn1_collate_primative(ret,&c)) 208 if (!asn1_collate_primitive(ret,&c))
209 goto err; 209 goto err;
210 else 210 else
211 { 211 {
@@ -218,8 +218,8 @@ ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
218 { 218 {
219 if ((ret->length < len) || (ret->data == NULL)) 219 if ((ret->length < len) || (ret->data == NULL))
220 { 220 {
221 if (ret->data != NULL) Free((char *)ret->data); 221 if (ret->data != NULL) Free(ret->data);
222 s=(unsigned char *)Malloc((int)len); 222 s=(unsigned char *)Malloc((int)len + 1);
223 if (s == NULL) 223 if (s == NULL)
224 { 224 {
225 i=ERR_R_MALLOC_FAILURE; 225 i=ERR_R_MALLOC_FAILURE;
@@ -229,12 +229,13 @@ ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
229 else 229 else
230 s=ret->data; 230 s=ret->data;
231 memcpy(s,p,(int)len); 231 memcpy(s,p,(int)len);
232 s[len] = '\0';
232 p+=len; 233 p+=len;
233 } 234 }
234 else 235 else
235 { 236 {
236 s=NULL; 237 s=NULL;
237 if (ret->data != NULL) Free((char *)ret->data); 238 if (ret->data != NULL) Free(ret->data);
238 } 239 }
239 240
240 ret->length=(int)len; 241 ret->length=(int)len;
@@ -253,11 +254,11 @@ err:
253 } 254 }
254 255
255 256
256/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapes 257/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
257 * them into the one struture that is then returned */ 258 * them into the one structure that is then returned */
258/* There have been a few bug fixes for this function from 259/* There have been a few bug fixes for this function from
259 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ 260 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
260static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c) 261static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c)
261 { 262 {
262 ASN1_STRING *os=NULL; 263 ASN1_STRING *os=NULL;
263 BUF_MEM b; 264 BUF_MEM b;
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
index 8c45add557..3370aae998 100644
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ b/src/lib/libcrypto/asn1/a_digest.c
@@ -58,16 +58,19 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include <sys/types.h>
62#include <sys/stat.h>
63 61
64#include "cryptlib.h" 62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
65#include <openssl/evp.h> 68#include <openssl/evp.h>
66#include <openssl/buffer.h> 69#include <openssl/buffer.h>
67#include <openssl/x509.h> 70#include <openssl/x509.h>
68 71
69int ASN1_digest(int (*i2d)(), EVP_MD *type, char *data, unsigned char *md, 72int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
70 unsigned int *len) 73 unsigned char *md, unsigned int *len)
71 { 74 {
72 EVP_MD_CTX ctx; 75 EVP_MD_CTX ctx;
73 int i; 76 int i;
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
index c0a8709f3b..3202a816d0 100644
--- a/src/lib/libcrypto/asn1/a_dup.c
+++ b/src/lib/libcrypto/asn1/a_dup.c
@@ -78,6 +78,6 @@ char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x)
78 i=i2d(x,&p); 78 i=i2d(x,&p);
79 p= b; 79 p= b;
80 ret=d2i(NULL,&p,i); 80 ret=d2i(NULL,&p,i);
81 Free((char *)b); 81 Free(b);
82 return(ret); 82 return(ret);
83 } 83 }
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
index 9239ecc439..ccf62e5a04 100644
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ b/src/lib/libcrypto/asn1/a_enum.c
@@ -65,6 +65,12 @@
65 * for comments on encoding see a_int.c 65 * for comments on encoding see a_int.c
66 */ 66 */
67 67
68ASN1_ENUMERATED *ASN1_ENUMERATED_new(void)
69{ return M_ASN1_ENUMERATED_new(); }
70
71void ASN1_ENUMERATED_free(ASN1_ENUMERATED *x)
72{ M_ASN1_ENUMERATED_free(x); }
73
68int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp) 74int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
69 { 75 {
70 int pad=0,ret,r,i,t; 76 int pad=0,ret,r,i,t;
@@ -142,7 +148,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
142 148
143 if ((a == NULL) || ((*a) == NULL)) 149 if ((a == NULL) || ((*a) == NULL))
144 { 150 {
145 if ((ret=ASN1_ENUMERATED_new()) == NULL) return(NULL); 151 if ((ret=M_ASN1_ENUMERATED_new()) == NULL) return(NULL);
146 ret->type=V_ASN1_ENUMERATED; 152 ret->type=V_ASN1_ENUMERATED;
147 } 153 }
148 else 154 else
@@ -171,7 +177,12 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
171 goto err; 177 goto err;
172 } 178 }
173 to=s; 179 to=s;
174 if (*p & 0x80) /* a negative number */ 180 if(!len) {
181 /* Strictly speaking this is an illegal ENUMERATED but we
182 * tolerate it.
183 */
184 ret->type=V_ASN1_ENUMERATED;
185 } else if (*p & 0x80) /* a negative number */
175 { 186 {
176 ret->type=V_ASN1_NEG_ENUMERATED; 187 ret->type=V_ASN1_NEG_ENUMERATED;
177 if ((*p == 0xff) && (len != 1)) { 188 if ((*p == 0xff) && (len != 1)) {
@@ -208,7 +219,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
208 p+=len; 219 p+=len;
209 } 220 }
210 221
211 if (ret->data != NULL) Free((char *)ret->data); 222 if (ret->data != NULL) Free(ret->data);
212 ret->data=s; 223 ret->data=s;
213 ret->length=(int)len; 224 ret->length=(int)len;
214 if (a != NULL) (*a)=ret; 225 if (a != NULL) (*a)=ret;
@@ -217,7 +228,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
217err: 228err:
218 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i); 229 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
219 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 230 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
220 ASN1_ENUMERATED_free(ret); 231 M_ASN1_ENUMERATED_free(ret);
221 return(NULL); 232 return(NULL);
222 } 233 }
223 234
@@ -231,7 +242,7 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
231 if (a->length < (sizeof(long)+1)) 242 if (a->length < (sizeof(long)+1))
232 { 243 {
233 if (a->data != NULL) 244 if (a->data != NULL)
234 Free((char *)a->data); 245 Free(a->data);
235 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL) 246 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
236 memset((char *)a->data,0,sizeof(long)+1); 247 memset((char *)a->data,0,sizeof(long)+1);
237 } 248 }
@@ -295,7 +306,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
295 int len,j; 306 int len,j;
296 307
297 if (ai == NULL) 308 if (ai == NULL)
298 ret=ASN1_ENUMERATED_new(); 309 ret=M_ASN1_ENUMERATED_new();
299 else 310 else
300 ret=ai; 311 ret=ai;
301 if (ret == NULL) 312 if (ret == NULL)
@@ -311,7 +322,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
311 ret->length=BN_bn2bin(bn,ret->data); 322 ret->length=BN_bn2bin(bn,ret->data);
312 return(ret); 323 return(ret);
313err: 324err:
314 if (ret != ai) ASN1_ENUMERATED_free(ret); 325 if (ret != ai) M_ASN1_ENUMERATED_free(ret);
315 return(NULL); 326 return(NULL);
316 } 327 }
317 328
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c
index 226474f057..84062170e8 100644
--- a/src/lib/libcrypto/asn1/a_gentm.c
+++ b/src/lib/libcrypto/asn1/a_gentm.c
@@ -63,6 +63,12 @@
63#include "cryptlib.h" 63#include "cryptlib.h"
64#include <openssl/asn1.h> 64#include <openssl/asn1.h>
65 65
66ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_new(void)
67{ return M_ASN1_GENERALIZEDTIME_new(); }
68
69void ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *x)
70{ M_ASN1_GENERALIZEDTIME_free(x); }
71
66int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) 72int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
67 { 73 {
68#ifdef CHARSET_EBCDIC 74#ifdef CHARSET_EBCDIC
@@ -106,7 +112,7 @@ ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
106 return(ret); 112 return(ret);
107err: 113err:
108 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 114 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
109 ASN1_GENERALIZEDTIME_free(ret); 115 M_ASN1_GENERALIZEDTIME_free(ret);
110 return(NULL); 116 return(NULL);
111 } 117 }
112 118
@@ -193,7 +199,7 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
193#endif 199#endif
194 200
195 if (s == NULL) 201 if (s == NULL)
196 s=ASN1_GENERALIZEDTIME_new(); 202 s=M_ASN1_GENERALIZEDTIME_new();
197 if (s == NULL) 203 if (s == NULL)
198 return(NULL); 204 return(NULL);
199 205
diff --git a/src/lib/libcrypto/asn1/a_hdr.c b/src/lib/libcrypto/asn1/a_hdr.c
index 1171d36443..434610e8e1 100644
--- a/src/lib/libcrypto/asn1/a_hdr.c
+++ b/src/lib/libcrypto/asn1/a_hdr.c
@@ -102,7 +102,7 @@ ASN1_HEADER *ASN1_HEADER_new(void)
102 ASN1_CTX c; 102 ASN1_CTX c;
103 103
104 M_ASN1_New_Malloc(ret,ASN1_HEADER); 104 M_ASN1_New_Malloc(ret,ASN1_HEADER);
105 M_ASN1_New(ret->header,ASN1_OCTET_STRING_new); 105 M_ASN1_New(ret->header,M_ASN1_OCTET_STRING_new);
106 ret->meth=NULL; 106 ret->meth=NULL;
107 ret->data=NULL; 107 ret->data=NULL;
108 return(ret); 108 return(ret);
@@ -112,8 +112,8 @@ ASN1_HEADER *ASN1_HEADER_new(void)
112void ASN1_HEADER_free(ASN1_HEADER *a) 112void ASN1_HEADER_free(ASN1_HEADER *a)
113 { 113 {
114 if (a == NULL) return; 114 if (a == NULL) return;
115 ASN1_OCTET_STRING_free(a->header); 115 M_ASN1_OCTET_STRING_free(a->header);
116 if (a->meth != NULL) 116 if (a->meth != NULL)
117 a->meth->destroy(a->data); 117 a->meth->destroy(a->data);
118 Free((char *)a); 118 Free(a);
119 } 119 }
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
index 6bd845443c..d9b8035e17 100644
--- a/src/lib/libcrypto/asn1/a_i2d_fp.c
+++ b/src/lib/libcrypto/asn1/a_i2d_fp.c
@@ -108,6 +108,6 @@ int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x)
108 j+=i; 108 j+=i;
109 n-=i; 109 n-=i;
110 } 110 }
111 Free((char *)b); 111 Free(b);
112 return(ret); 112 return(ret);
113 } 113 }
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
index d05436378b..8b6794e8c1 100644
--- a/src/lib/libcrypto/asn1/a_int.c
+++ b/src/lib/libcrypto/asn1/a_int.c
@@ -60,6 +60,18 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_INTEGER *ASN1_INTEGER_new(void)
64{ return M_ASN1_INTEGER_new();}
65
66void ASN1_INTEGER_free(ASN1_INTEGER *x)
67{ M_ASN1_INTEGER_free(x);}
68
69ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x)
70{ return M_ASN1_INTEGER_dup(x);}
71
72int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y)
73{ return M_ASN1_INTEGER_cmp(x,y);}
74
63/* 75/*
64 * This converts an ASN1 INTEGER into its DER encoding. 76 * This converts an ASN1 INTEGER into its DER encoding.
65 * The internal representation is an ASN1_STRING whose data is a big endian 77 * The internal representation is an ASN1_STRING whose data is a big endian
@@ -160,7 +172,7 @@ ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
160 172
161 if ((a == NULL) || ((*a) == NULL)) 173 if ((a == NULL) || ((*a) == NULL))
162 { 174 {
163 if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL); 175 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
164 ret->type=V_ASN1_INTEGER; 176 ret->type=V_ASN1_INTEGER;
165 } 177 }
166 else 178 else
@@ -190,7 +202,12 @@ ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
190 goto err; 202 goto err;
191 } 203 }
192 to=s; 204 to=s;
193 if (*p & 0x80) /* a negative number */ 205 if(!len) {
206 /* Strictly speaking this is an illegal INTEGER but we
207 * tolerate it.
208 */
209 ret->type=V_ASN1_INTEGER;
210 } else if (*p & 0x80) /* a negative number */
194 { 211 {
195 ret->type=V_ASN1_NEG_INTEGER; 212 ret->type=V_ASN1_NEG_INTEGER;
196 if ((*p == 0xff) && (len != 1)) { 213 if ((*p == 0xff) && (len != 1)) {
@@ -231,7 +248,7 @@ ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
231 memcpy(s,p,(int)len); 248 memcpy(s,p,(int)len);
232 } 249 }
233 250
234 if (ret->data != NULL) Free((char *)ret->data); 251 if (ret->data != NULL) Free(ret->data);
235 ret->data=s; 252 ret->data=s;
236 ret->length=(int)len; 253 ret->length=(int)len;
237 if (a != NULL) (*a)=ret; 254 if (a != NULL) (*a)=ret;
@@ -240,7 +257,7 @@ ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
240err: 257err:
241 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i); 258 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
242 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 259 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
243 ASN1_INTEGER_free(ret); 260 M_ASN1_INTEGER_free(ret);
244 return(NULL); 261 return(NULL);
245 } 262 }
246 263
@@ -260,7 +277,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
260 277
261 if ((a == NULL) || ((*a) == NULL)) 278 if ((a == NULL) || ((*a) == NULL))
262 { 279 {
263 if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL); 280 if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
264 ret->type=V_ASN1_INTEGER; 281 ret->type=V_ASN1_INTEGER;
265 } 282 }
266 else 283 else
@@ -289,7 +306,8 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
289 goto err; 306 goto err;
290 } 307 }
291 to=s; 308 to=s;
292 ret->type=V_ASN1_INTEGER; 309 ret->type=V_ASN1_INTEGER;
310 if(len) {
293 if ((*p == 0) && (len != 1)) 311 if ((*p == 0) && (len != 1))
294 { 312 {
295 p++; 313 p++;
@@ -297,8 +315,9 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
297 } 315 }
298 memcpy(s,p,(int)len); 316 memcpy(s,p,(int)len);
299 p+=len; 317 p+=len;
318 }
300 319
301 if (ret->data != NULL) Free((char *)ret->data); 320 if (ret->data != NULL) Free(ret->data);
302 ret->data=s; 321 ret->data=s;
303 ret->length=(int)len; 322 ret->length=(int)len;
304 if (a != NULL) (*a)=ret; 323 if (a != NULL) (*a)=ret;
@@ -307,7 +326,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
307err: 326err:
308 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i); 327 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
309 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 328 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
310 ASN1_INTEGER_free(ret); 329 M_ASN1_INTEGER_free(ret);
311 return(NULL); 330 return(NULL);
312 } 331 }
313 332
@@ -321,7 +340,7 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
321 if (a->length < (sizeof(long)+1)) 340 if (a->length < (sizeof(long)+1))
322 { 341 {
323 if (a->data != NULL) 342 if (a->data != NULL)
324 Free((char *)a->data); 343 Free(a->data);
325 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL) 344 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
326 memset((char *)a->data,0,sizeof(long)+1); 345 memset((char *)a->data,0,sizeof(long)+1);
327 } 346 }
@@ -385,7 +404,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
385 int len,j; 404 int len,j;
386 405
387 if (ai == NULL) 406 if (ai == NULL)
388 ret=ASN1_INTEGER_new(); 407 ret=M_ASN1_INTEGER_new();
389 else 408 else
390 ret=ai; 409 ret=ai;
391 if (ret == NULL) 410 if (ret == NULL)
@@ -401,7 +420,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
401 ret->length=BN_bn2bin(bn,ret->data); 420 ret->length=BN_bn2bin(bn,ret->data);
402 return(ret); 421 return(ret);
403err: 422err:
404 if (ret != ai) ASN1_INTEGER_free(ret); 423 if (ret != ai) M_ASN1_INTEGER_free(ret);
405 return(NULL); 424 return(NULL);
406 } 425 }
407 426
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
new file mode 100644
index 0000000000..7a710d5459
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -0,0 +1,390 @@
1/* a_mbstr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63
64static int traverse_string(const unsigned char *p, int len, int inform,
65 int (*rfunc)(unsigned long value, void *in), void *arg);
66static int in_utf8(unsigned long value, void *arg);
67static int out_utf8(unsigned long value, void *arg);
68static int type_str(unsigned long value, void *arg);
69static int cpy_asc(unsigned long value, void *arg);
70static int cpy_bmp(unsigned long value, void *arg);
71static int cpy_univ(unsigned long value, void *arg);
72static int cpy_utf8(unsigned long value, void *arg);
73static int is_printable(unsigned long value);
74
75/* These functions take a string in UTF8, ASCII or multibyte form and
76 * a mask of permissible ASN1 string types. It then works out the minimal
77 * type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8)
78 * and creates a string of the correct type with the supplied data.
79 * Yes this is horrible: it has to be :-(
80 * The 'ncopy' form checks minimum and maximum size limits too.
81 */
82
83int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
84 int inform, unsigned long mask)
85{
86 return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
87}
88
89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
90 int inform, unsigned long mask,
91 long minsize, long maxsize)
92{
93 int str_type;
94 int ret;
95 int outform, outlen;
96 ASN1_STRING *dest;
97 unsigned char *p;
98 int nchar;
99 char strbuf[32];
100 int (*cpyfunc)(unsigned long,void *) = NULL;
101 if(len == -1) len = strlen((const char *)in);
102 if(!mask) mask = DIRSTRING_TYPE;
103
104 /* First do a string check and work out the number of characters */
105 switch(inform) {
106
107 case MBSTRING_BMP:
108 if(len & 1) {
109 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
110 ASN1_R_INVALID_BMPSTRING_LENGTH);
111 return -1;
112 }
113 nchar = len >> 1;
114 break;
115
116 case MBSTRING_UNIV:
117 if(len & 3) {
118 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
119 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
120 return -1;
121 }
122 nchar = len >> 2;
123 break;
124
125 case MBSTRING_UTF8:
126 nchar = 0;
127 /* This counts the characters and does utf8 syntax checking */
128 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
129 if(ret < 0) {
130 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
131 ASN1_R_INVALID_UTF8STRING);
132 return -1;
133 }
134 break;
135
136 case MBSTRING_ASC:
137 nchar = len;
138 break;
139
140 default:
141 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT);
142 return -1;
143 }
144
145 if((minsize > 0) && (nchar < minsize)) {
146 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT);
147 sprintf(strbuf, "%ld", minsize);
148 ERR_add_error_data(2, "minsize=", strbuf);
149 return -1;
150 }
151
152 if((maxsize > 0) && (nchar > maxsize)) {
153 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG);
154 sprintf(strbuf, "%ld", maxsize);
155 ERR_add_error_data(2, "maxsize=", strbuf);
156 return -1;
157 }
158
159 /* Now work out minimal type (if any) */
160 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
161 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS);
162 return -1;
163 }
164
165
166 /* Now work out output format and string type */
167 outform = MBSTRING_ASC;
168 if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
169 else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
170 else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
171 else if(mask & B_ASN1_BMPSTRING) {
172 str_type = V_ASN1_BMPSTRING;
173 outform = MBSTRING_BMP;
174 } else if(mask & B_ASN1_UNIVERSALSTRING) {
175 str_type = V_ASN1_UNIVERSALSTRING;
176 outform = MBSTRING_UNIV;
177 } else {
178 str_type = V_ASN1_UTF8STRING;
179 outform = MBSTRING_UTF8;
180 }
181 if(!out) return str_type;
182 if(*out) {
183 dest = *out;
184 if(dest->data) {
185 dest->length = 0;
186 Free(dest->data);
187 dest->data = NULL;
188 }
189 dest->type = str_type;
190 } else {
191 dest = ASN1_STRING_type_new(str_type);
192 if(!dest) {
193 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
194 ERR_R_MALLOC_FAILURE);
195 return -1;
196 }
197 *out = dest;
198 }
199 /* If both the same type just copy across */
200 if(inform == outform) {
201 if(!ASN1_STRING_set(dest, in, len)) {
202 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
203 return -1;
204 }
205 return str_type;
206 }
207
208 /* Work out how much space the destination will need */
209 switch(outform) {
210 case MBSTRING_ASC:
211 outlen = nchar;
212 cpyfunc = cpy_asc;
213 break;
214
215 case MBSTRING_BMP:
216 outlen = nchar << 1;
217 cpyfunc = cpy_bmp;
218 break;
219
220 case MBSTRING_UNIV:
221 outlen = nchar << 2;
222 cpyfunc = cpy_univ;
223 break;
224
225 case MBSTRING_UTF8:
226 outlen = 0;
227 traverse_string(in, len, inform, out_utf8, &outlen);
228 cpyfunc = cpy_utf8;
229 break;
230 }
231 if(!(p = Malloc(outlen + 1))) {
232 ASN1_STRING_free(dest);
233 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
234 return -1;
235 }
236 dest->length = outlen;
237 dest->data = p;
238 p[outlen] = 0;
239 traverse_string(in, len, inform, cpyfunc, &p);
240 return str_type;
241}
242
243/* This function traverses a string and passes the value of each character
244 * to an optional function along with a void * argument.
245 */
246
247static int traverse_string(const unsigned char *p, int len, int inform,
248 int (*rfunc)(unsigned long value, void *in), void *arg)
249{
250 unsigned long value;
251 int ret;
252 while(len) {
253 if(inform == MBSTRING_ASC) {
254 value = *p++;
255 len--;
256 } else if(inform == MBSTRING_BMP) {
257 value = *p++ << 8;
258 value |= *p++;
259 len -= 2;
260 } else if(inform == MBSTRING_UNIV) {
261 value = *p++ << 24;
262 value |= *p++ << 16;
263 value |= *p++ << 8;
264 value |= *p++;
265 len -= 4;
266 } else {
267 ret = UTF8_getc(p, len, &value);
268 if(ret < 0) return -1;
269 len -= ret;
270 p += ret;
271 }
272 if(rfunc) {
273 ret = rfunc(value, arg);
274 if(ret <= 0) return ret;
275 }
276 }
277 return 1;
278}
279
280/* Various utility functions for traverse_string */
281
282/* Just count number of characters */
283
284static int in_utf8(unsigned long value, void *arg)
285{
286 int *nchar;
287 nchar = arg;
288 (*nchar)++;
289 return 1;
290}
291
292/* Determine size of output as a UTF8 String */
293
294static int out_utf8(unsigned long value, void *arg)
295{
296 long *outlen;
297 outlen = arg;
298 *outlen += UTF8_putc(NULL, -1, value);
299 return 1;
300}
301
302/* Determine the "type" of a string: check each character against a
303 * supplied "mask".
304 */
305
306static int type_str(unsigned long value, void *arg)
307{
308 unsigned long types;
309 types = *((unsigned long *)arg);
310 if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
311 types &= ~B_ASN1_PRINTABLESTRING;
312 if((types & B_ASN1_IA5STRING) && (value > 127))
313 types &= ~B_ASN1_IA5STRING;
314 if((types & B_ASN1_T61STRING) && (value > 0xff))
315 types &= ~B_ASN1_T61STRING;
316 if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
317 types &= ~B_ASN1_BMPSTRING;
318 if(!types) return -1;
319 *((unsigned long *)arg) = types;
320 return 1;
321}
322
323/* Copy one byte per character ASCII like strings */
324
325static int cpy_asc(unsigned long value, void *arg)
326{
327 unsigned char **p, *q;
328 p = arg;
329 q = *p;
330 *q = (unsigned char) value;
331 (*p)++;
332 return 1;
333}
334
335/* Copy two byte per character BMPStrings */
336
337static int cpy_bmp(unsigned long value, void *arg)
338{
339 unsigned char **p, *q;
340 p = arg;
341 q = *p;
342 *q++ = (unsigned char) ((value >> 8) & 0xff);
343 *q = (unsigned char) (value & 0xff);
344 *p += 2;
345 return 1;
346}
347
348/* Copy four byte per character UniversalStrings */
349
350static int cpy_univ(unsigned long value, void *arg)
351{
352 unsigned char **p, *q;
353 p = arg;
354 q = *p;
355 *q++ = (unsigned char) ((value >> 24) & 0xff);
356 *q++ = (unsigned char) ((value >> 16) & 0xff);
357 *q++ = (unsigned char) ((value >> 8) & 0xff);
358 *q = (unsigned char) (value & 0xff);
359 *p += 4;
360 return 1;
361}
362
363/* Copy to a UTF8String */
364
365static int cpy_utf8(unsigned long value, void *arg)
366{
367 unsigned char **p;
368 int ret;
369 p = arg;
370 /* We already know there is enough room so pass 0xff as the length */
371 ret = UTF8_putc(*p, 0xff, value);
372 *p += ret;
373 return 1;
374}
375
376/* Return 1 if the character is permitted in a PrintableString */
377static int is_printable(unsigned long value)
378{
379 int ch;
380 if(value > 0x7f) return 0;
381 ch = (int) value;
382 /* Note: we can't use 'isalnum' because certain accented
383 * characters may count as alphanumeric in some environments.
384 */
385 if((ch >= 'a') && (ch <= 'z')) return 1;
386 if((ch >= 'A') && (ch <= 'Z')) return 1;
387 if((ch >= '0') && (ch <= '9')) return 1;
388 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
389 return 0;
390}
diff --git a/src/lib/libcrypto/asn1/a_null.c b/src/lib/libcrypto/asn1/a_null.c
new file mode 100644
index 0000000000..119fd784be
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_null.c
@@ -0,0 +1,119 @@
1/* a_null.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/* ASN1 functions for NULL type. For compatibility with other ASN1 code
64 * it returns a pointer to an "ASN1_NULL" structure. The new/free functions
65 * don't need to do any allocating because nothing is stored in a NULL.
66 */
67
68int i2d_ASN1_NULL(ASN1_NULL *a, unsigned char **pp)
69 {
70 if(!a) return 0;
71 if (pp) ASN1_put_object(pp,0,0,V_ASN1_NULL,V_ASN1_UNIVERSAL);
72 return 2;
73 }
74
75ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **a, unsigned char **pp, long length)
76 {
77 ASN1_NULL *ret = NULL;
78 unsigned char *p;
79 long len;
80 int inf,tag,xclass;
81 int i=0;
82
83 p= *pp;
84 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
85 if (inf & 0x80)
86 {
87 i=ASN1_R_BAD_OBJECT_HEADER;
88 goto err;
89 }
90
91 if (tag != V_ASN1_NULL)
92 {
93 i=ASN1_R_EXPECTING_A_NULL;
94 goto err;
95 }
96
97 if (len != 0)
98 {
99 i=ASN1_R_NULL_IS_WRONG_LENGTH;
100 goto err;
101 }
102 ret=(ASN1_NULL *)1;
103 if (a != NULL) (*a)=ret;
104 *pp=p;
105 return(ret);
106err:
107 ASN1err(ASN1_F_D2I_ASN1_NULL,i);
108 return(ret);
109 }
110
111ASN1_NULL *ASN1_NULL_new(void)
112{
113 return (ASN1_NULL *)1;
114}
115
116void ASN1_NULL_free(ASN1_NULL *a)
117{
118 return;
119}
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
index b94b418ee8..09d56fb669 100644
--- a/src/lib/libcrypto/asn1/a_object.c
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -222,8 +222,8 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
222 } 222 }
223 if ((ret->data == NULL) || (ret->length < len)) 223 if ((ret->data == NULL) || (ret->length < len))
224 { 224 {
225 if (ret->data != NULL) Free((char *)ret->data); 225 if (ret->data != NULL) Free(ret->data);
226 ret->data=(unsigned char *)Malloc((int)len); 226 ret->data=(unsigned char *)Malloc(len ? (int)len : 1);
227 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; 227 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
228 if (ret->data == NULL) 228 if (ret->data == NULL)
229 { i=ERR_R_MALLOC_FAILURE; goto err; } 229 { i=ERR_R_MALLOC_FAILURE; goto err; }
@@ -269,7 +269,7 @@ void ASN1_OBJECT_free(ASN1_OBJECT *a)
269 if (a == NULL) return; 269 if (a == NULL) return;
270 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) 270 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
271 { 271 {
272#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause mempory leaks */ 272#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
273 if (a->sn != NULL) Free((void *)a->sn); 273 if (a->sn != NULL) Free((void *)a->sn);
274 if (a->ln != NULL) Free((void *)a->ln); 274 if (a->ln != NULL) Free((void *)a->ln);
275#endif 275#endif
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c
index 7659a13bd3..2586f4327d 100644
--- a/src/lib/libcrypto/asn1/a_octet.c
+++ b/src/lib/libcrypto/asn1/a_octet.c
@@ -60,11 +60,23 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_OCTET_STRING *ASN1_OCTET_STRING_new(void)
64{ return M_ASN1_OCTET_STRING_new(); }
65
66void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *x)
67{ M_ASN1_OCTET_STRING_free(x); }
68
69ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x)
70{ return M_ASN1_OCTET_STRING_dup(x); }
71
72int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b)
73{ return M_ASN1_OCTET_STRING_cmp(a, b); }
74
75int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len)
76{ return M_ASN1_OCTET_STRING_set(x, d, len); }
77
63int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp) 78int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)
64 { 79{ return M_i2d_ASN1_OCTET_STRING(a, pp); }
65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
66 V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL));
67 }
68 80
69ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, 81ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
70 unsigned char **pp, long length) 82 unsigned char **pp, long length)
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c
index cdec7a1561..b7bd2bd18a 100644
--- a/src/lib/libcrypto/asn1/a_print.c
+++ b/src/lib/libcrypto/asn1/a_print.c
@@ -60,6 +60,12 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_IA5STRING *ASN1_IA5STRING_new(void)
64{ return M_ASN1_IA5STRING_new();}
65
66void ASN1_IA5STRING_free(ASN1_IA5STRING *x)
67{ M_ASN1_IA5STRING_free(x);}
68
63int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **pp) 69int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **pp)
64 { return(M_i2d_ASN1_IA5STRING(a,pp)); } 70 { return(M_i2d_ASN1_IA5STRING(a,pp)); }
65 71
@@ -67,15 +73,30 @@ ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, unsigned char **pp,
67 long l) 73 long l)
68 { return(M_d2i_ASN1_IA5STRING(a,pp,l)); } 74 { return(M_d2i_ASN1_IA5STRING(a,pp,l)); }
69 75
76ASN1_T61STRING *ASN1_T61STRING_new(void)
77{ return M_ASN1_T61STRING_new();}
78
79void ASN1_T61STRING_free(ASN1_T61STRING *x)
80{ M_ASN1_T61STRING_free(x);}
81
70ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, unsigned char **pp, 82ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, unsigned char **pp,
71 long l) 83 long l)
72 { return(M_d2i_ASN1_T61STRING(a,pp,l)); } 84 { return(M_d2i_ASN1_T61STRING(a,pp,l)); }
73 85
86ASN1_PRINTABLESTRING *ASN1_PRINTABLESTRING_new(void)
87{ return M_ASN1_PRINTABLESTRING_new();}
88
89void ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *x)
90{ M_ASN1_PRINTABLESTRING_free(x);}
91
74ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, 92ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
75 unsigned char **pp, long l) 93 unsigned char **pp, long l)
76 { return(M_d2i_ASN1_PRINTABLESTRING(a,pp, 94 { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,
77 l)); } 95 l)); }
78 96
97int i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **pp)
98 { return(M_i2d_ASN1_PRINTABLESTRING(a,pp)); }
99
79int i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **pp) 100int i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **pp)
80 { return(M_i2d_ASN1_PRINTABLE(a,pp)); } 101 { return(M_i2d_ASN1_PRINTABLE(a,pp)); }
81 102
@@ -149,6 +170,11 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
149 return(1); 170 return(1);
150 } 171 }
151 172
173ASN1_STRING *DIRECTORYSTRING_new(void)
174{ return M_DIRECTORYSTRING_new();}
175
176void DIRECTORYSTRING_free(ASN1_STRING *x)
177{ M_DIRECTORYSTRING_free(x);}
152 178
153int i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **pp) 179int i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **pp)
154 { return(M_i2d_DIRECTORYSTRING(a,pp)); } 180 { return(M_i2d_DIRECTORYSTRING(a,pp)); }
@@ -157,6 +183,12 @@ ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
157 long l) 183 long l)
158 { return(M_d2i_DIRECTORYSTRING(a,pp,l)); } 184 { return(M_d2i_DIRECTORYSTRING(a,pp,l)); }
159 185
186ASN1_STRING *DISPLAYTEXT_new(void)
187{ return M_DISPLAYTEXT_new();}
188
189void DISPLAYTEXT_free(ASN1_STRING *x)
190{ M_DISPLAYTEXT_free(x);}
191
160int i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **pp) 192int i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **pp)
161 { return(M_i2d_DISPLAYTEXT(a,pp)); } 193 { return(M_i2d_DISPLAYTEXT(a,pp)); }
162 194
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
index 57595692e5..cfb4bca4f1 100644
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -58,10 +58,13 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include <sys/types.h>
62#include <sys/stat.h>
63 61
64#include "cryptlib.h" 62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
65#include <openssl/bn.h> 68#include <openssl/bn.h>
66#include <openssl/evp.h> 69#include <openssl/evp.h>
67#include <openssl/x509.h> 70#include <openssl/x509.h>
@@ -126,11 +129,11 @@ int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
126 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB); 129 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
127 goto err; 130 goto err;
128 } 131 }
129 if (signature->data != NULL) Free((char *)signature->data); 132 if (signature->data != NULL) Free(signature->data);
130 signature->data=buf_out; 133 signature->data=buf_out;
131 buf_out=NULL; 134 buf_out=NULL;
132 signature->length=outl; 135 signature->length=outl;
133 /* In the interests of compatability, I'll make sure that 136 /* In the interests of compatibility, I'll make sure that
134 * the bit string has a 'not-used bits' value of 0 137 * the bit string has a 'not-used bits' value of 0
135 */ 138 */
136 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); 139 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
@@ -138,8 +141,8 @@ int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
138err: 141err:
139 memset(&ctx,0,sizeof(ctx)); 142 memset(&ctx,0,sizeof(ctx));
140 if (buf_in != NULL) 143 if (buf_in != NULL)
141 { memset((char *)buf_in,0,(unsigned int)inl); Free((char *)buf_in); } 144 { memset((char *)buf_in,0,(unsigned int)inl); Free(buf_in); }
142 if (buf_out != NULL) 145 if (buf_out != NULL)
143 { memset((char *)buf_out,0,outll); Free((char *)buf_out); } 146 { memset((char *)buf_out,0,outll); Free(buf_out); }
144 return(outl); 147 return(outl);
145 } 148 }
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
new file mode 100644
index 0000000000..ab8417ffab
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_strnid.c
@@ -0,0 +1,247 @@
1/* a_strnid.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64
65
66static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
67static void st_free(ASN1_STRING_TABLE *tbl);
68static int sk_table_cmp(ASN1_STRING_TABLE **a, ASN1_STRING_TABLE **b);
69static int table_cmp(ASN1_STRING_TABLE *a, ASN1_STRING_TABLE *b);
70
71
72/* This is the global mask for the mbstring functions: this is use to
73 * mask out certain types (such as BMPString and UTF8String) because
74 * certain software (e.g. Netscape) has problems with them.
75 */
76
77static unsigned long global_mask = 0xFFFFFFFFL;
78
79void ASN1_STRING_set_default_mask(unsigned long mask)
80{
81 global_mask = mask;
82}
83
84unsigned long ASN1_STRING_get_default_mask(void)
85{
86 return global_mask;
87}
88
89/* This function sets the default to various "flavours" of configuration.
90 * based on an ASCII string. Currently this is:
91 * MASK:XXXX : a numerical mask value.
92 * nobmp : Don't use BMPStrings (just Printable, T61).
93 * pkix : PKIX recommendation in RFC2459.
94 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
95 * default: the default value, Printable, T61, BMP.
96 */
97
98int ASN1_STRING_set_default_mask_asc(char *p)
99{
100 unsigned long mask;
101 char *end;
102 if(!strncmp(p, "MASK:", 5)) {
103 if(!p[5]) return 0;
104 mask = strtoul(p + 5, &end, 0);
105 if(*end) return 0;
106 } else if(!strcmp(p, "nombstr"))
107 mask = ~(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING);
108 else if(!strcmp(p, "pkix"))
109 mask = ~B_ASN1_T61STRING;
110 else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING;
111 else if(!strcmp(p, "default"))
112 mask = 0xFFFFFFFFL;
113 else return 0;
114 ASN1_STRING_set_default_mask(mask);
115 return 1;
116}
117
118/* The following function generates an ASN1_STRING based on limits in a table.
119 * Frequently the types and length of an ASN1_STRING are restricted by a
120 * corresponding OID. For example certificates and certificate requests.
121 */
122
123ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
124 int inlen, int inform, int nid)
125{
126 ASN1_STRING_TABLE *tbl;
127 ASN1_STRING *str = NULL;
128 unsigned long mask;
129 int ret;
130 if(!out) out = &str;
131 tbl = ASN1_STRING_TABLE_get(nid);
132 if(tbl) {
133 mask = tbl->mask;
134 if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask;
135 ret = ASN1_mbstring_ncopy(out, in, inlen, inform, tbl->mask,
136 tbl->minsize, tbl->maxsize);
137 } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask);
138 if(ret <= 0) return NULL;
139 return *out;
140}
141
142/* Now the tables and helper functions for the string table:
143 */
144
145/* size limits: this stuff is taken straight from RFC2459 */
146
147#define ub_name 32768
148#define ub_common_name 64
149#define ub_locality_name 128
150#define ub_state_name 128
151#define ub_organization_name 64
152#define ub_organization_unit_name 64
153#define ub_title 64
154#define ub_email_address 128
155
156/* This table must be kept in NID order */
157
158static ASN1_STRING_TABLE tbl_standard[] = {
159{NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
160{NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
161{NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
162{NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
163{NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
164{NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0},
165{NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK},
166{NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
167{NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
168{NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
169{NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
170{NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
171{NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
172{NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
173{NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}
174};
175
176static int sk_table_cmp(ASN1_STRING_TABLE **a, ASN1_STRING_TABLE **b)
177{
178 return (*a)->nid - (*b)->nid;
179}
180
181static int table_cmp(ASN1_STRING_TABLE *a, ASN1_STRING_TABLE *b)
182{
183 return a->nid - b->nid;
184}
185
186ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
187{
188 int idx;
189 ASN1_STRING_TABLE *ttmp;
190 ASN1_STRING_TABLE fnd;
191 fnd.nid = nid;
192 ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
193 (char *)tbl_standard,
194 sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
195 sizeof(ASN1_STRING_TABLE), (int(*)())table_cmp);
196 if(ttmp) return ttmp;
197 if(!stable) return NULL;
198 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
199 if(idx < 0) return NULL;
200 return sk_ASN1_STRING_TABLE_value(stable, idx);
201}
202
203int ASN1_STRING_TABLE_add(int nid,
204 long minsize, long maxsize, unsigned long mask,
205 unsigned long flags)
206{
207 ASN1_STRING_TABLE *tmp;
208 char new_nid = 0;
209 flags &= ~STABLE_FLAGS_MALLOC;
210 if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
211 if(!stable) {
212 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE);
213 return 0;
214 }
215 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
216 tmp = Malloc(sizeof(ASN1_STRING_TABLE));
217 if(!tmp) {
218 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
219 ERR_R_MALLOC_FAILURE);
220 return 0;
221 }
222 tmp->flags = flags | STABLE_FLAGS_MALLOC;
223 tmp->nid = nid;
224 new_nid = 1;
225 } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags;
226 if(minsize != -1) tmp->minsize = minsize;
227 if(maxsize != -1) tmp->maxsize = maxsize;
228 tmp->mask = mask;
229 if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp);
230 return 1;
231}
232
233void ASN1_STRING_TABLE_cleanup(void)
234{
235 STACK_OF(ASN1_STRING_TABLE) *tmp;
236 tmp = stable;
237 if(!tmp) return;
238 stable = NULL;
239 sk_ASN1_STRING_TABLE_pop_free(tmp, st_free);
240}
241
242static void st_free(ASN1_STRING_TABLE *tbl)
243{
244 if(tbl->flags & STABLE_FLAGS_MALLOC) Free(tbl);
245}
246
247IMPLEMENT_STACK_OF(ASN1_STRING_TABLE)
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
index c1690a5694..b193f1c71f 100644
--- a/src/lib/libcrypto/asn1/a_time.c
+++ b/src/lib/libcrypto/asn1/a_time.c
@@ -66,6 +66,12 @@
66#include "cryptlib.h" 66#include "cryptlib.h"
67#include <openssl/asn1.h> 67#include <openssl/asn1.h>
68 68
69ASN1_TIME *ASN1_TIME_new(void)
70{ return M_ASN1_TIME_new(); }
71
72void ASN1_TIME_free(ASN1_TIME *x)
73{ M_ASN1_TIME_free(x); }
74
69int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) 75int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
70 { 76 {
71#ifdef CHARSET_EBCDIC 77#ifdef CHARSET_EBCDIC
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
index 3f2ecee5c2..161ef81197 100644
--- a/src/lib/libcrypto/asn1/a_type.c
+++ b/src/lib/libcrypto/asn1/a_type.c
@@ -282,7 +282,7 @@ void ASN1_TYPE_free(ASN1_TYPE *a)
282 { 282 {
283 if (a == NULL) return; 283 if (a == NULL) return;
284 ASN1_TYPE_component_free(a); 284 ASN1_TYPE_component_free(a);
285 Free((char *)(char *)a); 285 Free(a);
286 } 286 }
287 287
288int ASN1_TYPE_get(ASN1_TYPE *a) 288int ASN1_TYPE_get(ASN1_TYPE *a)
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c
index 688199fdd2..07565974e3 100644
--- a/src/lib/libcrypto/asn1/a_utctm.c
+++ b/src/lib/libcrypto/asn1/a_utctm.c
@@ -66,6 +66,12 @@
66#include "cryptlib.h" 66#include "cryptlib.h"
67#include <openssl/asn1.h> 67#include <openssl/asn1.h>
68 68
69ASN1_UTCTIME *ASN1_UTCTIME_new(void)
70{ return M_ASN1_UTCTIME_new(); }
71
72void ASN1_UTCTIME_free(ASN1_UTCTIME *x)
73{ M_ASN1_UTCTIME_free(x); }
74
69int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) 75int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
70 { 76 {
71#ifndef CHARSET_EBCDIC 77#ifndef CHARSET_EBCDIC
@@ -109,7 +115,7 @@ ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
109 return(ret); 115 return(ret);
110err: 116err:
111 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 117 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
112 ASN1_UTCTIME_free(ret); 118 M_ASN1_UTCTIME_free(ret);
113 return(NULL); 119 return(NULL);
114 } 120 }
115 121
@@ -192,7 +198,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
192#endif 198#endif
193 199
194 if (s == NULL) 200 if (s == NULL)
195 s=ASN1_UTCTIME_new(); 201 s=M_ASN1_UTCTIME_new();
196 if (s == NULL) 202 if (s == NULL)
197 return(NULL); 203 return(NULL);
198 204
diff --git a/src/lib/libcrypto/asn1/a_utf8.c b/src/lib/libcrypto/asn1/a_utf8.c
index 4a8a92e9e4..b5125af224 100644
--- a/src/lib/libcrypto/asn1/a_utf8.c
+++ b/src/lib/libcrypto/asn1/a_utf8.c
@@ -60,6 +60,12 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_UTF8STRING *ASN1_UTF8STRING_new(void)
64{ return M_ASN1_UTF8STRING_new();}
65
66void ASN1_UTF8STRING_free(ASN1_UTF8STRING *x)
67{ M_ASN1_UTF8STRING_free(x);}
68
63int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **pp) 69int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **pp)
64 { 70 {
65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 71 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
@@ -81,3 +87,152 @@ ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, unsigned char **pp,
81 return(ret); 87 return(ret);
82 } 88 }
83 89
90
91/* UTF8 utilities */
92
93/* This parses a UTF8 string one character at a time. It is passed a pointer
94 * to the string and the length of the string. It sets 'value' to the value of
95 * the current character. It returns the number of characters read or a
96 * negative error code:
97 * -1 = string too short
98 * -2 = illegal character
99 * -3 = subsequent characters not of the form 10xxxxxx
100 * -4 = character encoded incorrectly (not minimal length).
101 */
102
103int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
104{
105 const unsigned char *p;
106 unsigned long value;
107 int ret;
108 if(len <= 0) return 0;
109 p = str;
110
111 /* Check syntax and work out the encoded value (if correct) */
112 if((*p & 0x80) == 0) {
113 value = *p++ & 0x7f;
114 ret = 1;
115 } else if((*p & 0xe0) == 0xc0) {
116 if(len < 2) return -1;
117 if((p[1] & 0xc0) != 0x80) return -3;
118 value = (*p++ & 0x1f) << 6;
119 value |= *p++ & 0x3f;
120 if(value < 0x80) return -4;
121 ret = 2;
122 } else if((*p & 0xf0) == 0xe0) {
123 if(len < 3) return -1;
124 if( ((p[1] & 0xc0) != 0x80)
125 || ((p[2] & 0xc0) != 0x80) ) return -3;
126 value = (*p++ & 0xf) << 12;
127 value |= (*p++ & 0x3f) << 6;
128 value |= *p++ & 0x3f;
129 if(value < 0x800) return -4;
130 ret = 3;
131 } else if((*p & 0xf8) == 0xf0) {
132 if(len < 4) return -1;
133 if( ((p[1] & 0xc0) != 0x80)
134 || ((p[2] & 0xc0) != 0x80)
135 || ((p[3] & 0xc0) != 0x80) ) return -3;
136 value = (*p++ & 0x7) << 18;
137 value |= (*p++ & 0x3f) << 12;
138 value |= (*p++ & 0x3f) << 6;
139 value |= *p++ & 0x3f;
140 if(value < 0x10000) return -4;
141 ret = 4;
142 } else if((*p & 0xfc) == 0xf8) {
143 if(len < 5) return -1;
144 if( ((p[1] & 0xc0) != 0x80)
145 || ((p[2] & 0xc0) != 0x80)
146 || ((p[3] & 0xc0) != 0x80)
147 || ((p[4] & 0xc0) != 0x80) ) return -3;
148 value = (*p++ & 0x3) << 24;
149 value |= (*p++ & 0x3f) << 18;
150 value |= (*p++ & 0x3f) << 12;
151 value |= (*p++ & 0x3f) << 6;
152 value |= *p++ & 0x3f;
153 if(value < 0x200000) return -4;
154 ret = 5;
155 } else if((*p & 0xfe) == 0xfc) {
156 if(len < 6) return -1;
157 if( ((p[1] & 0xc0) != 0x80)
158 || ((p[2] & 0xc0) != 0x80)
159 || ((p[3] & 0xc0) != 0x80)
160 || ((p[4] & 0xc0) != 0x80)
161 || ((p[5] & 0xc0) != 0x80) ) return -3;
162 value = (*p++ & 0x1) << 30;
163 value |= (*p++ & 0x3f) << 24;
164 value |= (*p++ & 0x3f) << 18;
165 value |= (*p++ & 0x3f) << 12;
166 value |= (*p++ & 0x3f) << 6;
167 value |= *p++ & 0x3f;
168 if(value < 0x4000000) return -4;
169 ret = 6;
170 } else return -2;
171 *val = value;
172 return ret;
173}
174
175/* This takes a character 'value' and writes the UTF8 encoded value in
176 * 'str' where 'str' is a buffer containing 'len' characters. Returns
177 * the number of characters written or -1 if 'len' is too small. 'str' can
178 * be set to NULL in which case it just returns the number of characters.
179 * It will need at most 6 characters.
180 */
181
182int UTF8_putc(unsigned char *str, int len, unsigned long value)
183{
184 if(!str) len = 6; /* Maximum we will need */
185 else if(len <= 0) return -1;
186 if(value < 0x80) {
187 if(str) *str = (unsigned char)value;
188 return 1;
189 }
190 if(value < 0x800) {
191 if(len < 2) return -1;
192 if(str) {
193 *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0);
194 *str = (unsigned char)((value & 0x3f) | 0x80);
195 }
196 return 2;
197 }
198 if(value < 0x10000) {
199 if(len < 3) return -1;
200 if(str) {
201 *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0);
202 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
203 *str = (unsigned char)((value & 0x3f) | 0x80);
204 }
205 return 3;
206 }
207 if(value < 0x200000) {
208 if(len < 4) return -1;
209 if(str) {
210 *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0);
211 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
212 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
213 *str = (unsigned char)((value & 0x3f) | 0x80);
214 }
215 return 4;
216 }
217 if(value < 0x4000000) {
218 if(len < 5) return -1;
219 if(str) {
220 *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8);
221 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
222 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
223 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
224 *str = (unsigned char)((value & 0x3f) | 0x80);
225 }
226 return 5;
227 }
228 if(len < 6) return -1;
229 if(str) {
230 *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc);
231 *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80);
232 *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80);
233 *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80);
234 *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80);
235 *str = (unsigned char)((value & 0x3f) | 0x80);
236 }
237 return 6;
238}
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
index 6383d2c698..d4aede85c3 100644
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ b/src/lib/libcrypto/asn1/a_verify.c
@@ -58,10 +58,13 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include <sys/types.h>
62#include <sys/stat.h>
63 61
64#include "cryptlib.h" 62#include "cryptlib.h"
63
64#ifndef NO_SYS_TYPES_H
65# include <sys/types.h>
66#endif
67
65#include <openssl/bn.h> 68#include <openssl/bn.h>
66#include <openssl/x509.h> 69#include <openssl/x509.h>
67#include <openssl/objects.h> 70#include <openssl/objects.h>
@@ -98,7 +101,7 @@ int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
98 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); 101 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
99 102
100 memset(buf_in,0,(unsigned int)inl); 103 memset(buf_in,0,(unsigned int)inl);
101 Free((char *)buf_in); 104 Free(buf_in);
102 105
103 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, 106 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
104 (unsigned int)signature->length,pkey) <= 0) 107 (unsigned int)signature->length,pkey) <= 0)
diff --git a/src/lib/libcrypto/asn1/a_vis.c b/src/lib/libcrypto/asn1/a_vis.c
index 2072be780d..5cfc080bec 100644
--- a/src/lib/libcrypto/asn1/a_vis.c
+++ b/src/lib/libcrypto/asn1/a_vis.c
@@ -60,6 +60,12 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63ASN1_VISIBLESTRING *ASN1_VISIBLESTRING_new(void)
64{ return M_ASN1_VISIBLESTRING_new(); }
65
66void ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *x)
67{ M_ASN1_VISIBLESTRING_free(x); }
68
63int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a, unsigned char **pp) 69int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a, unsigned char **pp)
64 { 70 {
65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 71 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
index 5c2d8999bc..99bd64a11e 100644
--- a/src/lib/libcrypto/asn1/asn1.h
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -68,6 +68,10 @@ extern "C" {
68#include <openssl/stack.h> 68#include <openssl/stack.h>
69#include <openssl/safestack.h> 69#include <openssl/safestack.h>
70 70
71#ifdef VMS
72#include <openssl/vms_idhacks.h>
73#endif
74
71#define V_ASN1_UNIVERSAL 0x00 75#define V_ASN1_UNIVERSAL 0x00
72#define V_ASN1_APPLICATION 0x40 76#define V_ASN1_APPLICATION 0x40
73#define V_ASN1_CONTEXT_SPECIFIC 0x80 77#define V_ASN1_CONTEXT_SPECIFIC 0x80
@@ -77,7 +81,7 @@ extern "C" {
77#define V_ASN1_PRIMITIVE_TAG 0x1f 81#define V_ASN1_PRIMITIVE_TAG 0x1f
78#define V_ASN1_PRIMATIVE_TAG 0x1f 82#define V_ASN1_PRIMATIVE_TAG 0x1f
79 83
80#define V_ASN1_APP_CHOOSE -2 /* let the recipent choose */ 84#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
81 85
82#define V_ASN1_UNDEF -1 86#define V_ASN1_UNDEF -1
83#define V_ASN1_EOC 0 87#define V_ASN1_EOC 0
@@ -129,6 +133,13 @@ extern "C" {
129#define B_ASN1_UNKNOWN 0x1000 133#define B_ASN1_UNKNOWN 0x1000
130#define B_ASN1_UTF8STRING 0x2000 134#define B_ASN1_UTF8STRING 0x2000
131 135
136/* For use with ASN1_mbstring_copy() */
137#define MBSTRING_FLAG 0x1000
138#define MBSTRING_ASC (MBSTRING_FLAG|1)
139#define MBSTRING_BMP (MBSTRING_FLAG|2)
140#define MBSTRING_UNIV (MBSTRING_FLAG|3)
141#define MBSTRING_UTF8 (MBSTRING_FLAG|4)
142
132#define DECLARE_ASN1_SET_OF(type) \ 143#define DECLARE_ASN1_SET_OF(type) \
133int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \ 144int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
134 int (*func)(type *,unsigned char **), int ex_tag, \ 145 int (*func)(type *,unsigned char **), int ex_tag, \
@@ -165,7 +176,7 @@ typedef struct asn1_ctx_st
165 int tag; /* tag from last 'get object' */ 176 int tag; /* tag from last 'get object' */
166 int xclass; /* class from last 'get object' */ 177 int xclass; /* class from last 'get object' */
167 long slen; /* length of last 'get object' */ 178 long slen; /* length of last 'get object' */
168 unsigned char *max; /* largest value of p alowed */ 179 unsigned char *max; /* largest value of p allowed */
169 unsigned char *q;/* temporary variable */ 180 unsigned char *q;/* temporary variable */
170 unsigned char **pp;/* variable */ 181 unsigned char **pp;/* variable */
171 int line; /* used in error processing */ 182 int line; /* used in error processing */
@@ -200,7 +211,34 @@ typedef struct asn1_string_st
200 long flags; 211 long flags;
201 } ASN1_STRING; 212 } ASN1_STRING;
202 213
203#ifndef DEBUG 214#define STABLE_FLAGS_MALLOC 0x01
215#define STABLE_NO_MASK 0x02
216#define DIRSTRING_TYPE \
217 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
218#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
219
220typedef struct asn1_string_table_st {
221 int nid;
222 long minsize;
223 long maxsize;
224 unsigned long mask;
225 unsigned long flags;
226} ASN1_STRING_TABLE;
227
228DECLARE_STACK_OF(ASN1_STRING_TABLE)
229
230/* size limits: this stuff is taken straight from RFC2459 */
231
232#define ub_name 32768
233#define ub_common_name 64
234#define ub_locality_name 128
235#define ub_state_name 128
236#define ub_organization_name 64
237#define ub_organization_unit_name 64
238#define ub_title 64
239#define ub_email_address 128
240
241#ifdef NO_ASN1_TYPEDEFS
204#define ASN1_INTEGER ASN1_STRING 242#define ASN1_INTEGER ASN1_STRING
205#define ASN1_ENUMERATED ASN1_STRING 243#define ASN1_ENUMERATED ASN1_STRING
206#define ASN1_BIT_STRING ASN1_STRING 244#define ASN1_BIT_STRING ASN1_STRING
@@ -234,6 +272,8 @@ typedef struct asn1_string_st ASN1_VISIBLESTRING;
234typedef struct asn1_string_st ASN1_UTF8STRING; 272typedef struct asn1_string_st ASN1_UTF8STRING;
235#endif 273#endif
236 274
275typedef int ASN1_NULL;
276
237typedef struct asn1_type_st 277typedef struct asn1_type_st
238 { 278 {
239 int type; 279 int type;
@@ -281,60 +321,58 @@ typedef struct asn1_header_st
281 ASN1_METHOD *meth; 321 ASN1_METHOD *meth;
282 } ASN1_HEADER; 322 } ASN1_HEADER;
283 323
284#define ASN1_STRING_length(x) ((x)->length) 324/* This is used to contain a list of bit names */
285#define ASN1_STRING_type(x) ((x)->type) 325typedef struct BIT_STRING_BITNAME_st {
286#define ASN1_STRING_data(x) ((x)->data) 326 int bitnum;
327 const char *lname;
328 const char *sname;
329} BIT_STRING_BITNAME;
330
331
332#define M_ASN1_STRING_length(x) ((x)->length)
333#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
334#define M_ASN1_STRING_type(x) ((x)->type)
335#define M_ASN1_STRING_data(x) ((x)->data)
287 336
288/* Macros for string operations */ 337/* Macros for string operations */
289#define ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\ 338#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
290 ASN1_STRING_type_new(V_ASN1_BIT_STRING) 339 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
291#define ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 340#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
292#define ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\ 341#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
293 ASN1_STRING_dup((ASN1_STRING *)a) 342 ASN1_STRING_dup((ASN1_STRING *)a)
294#define ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\ 343#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
295 (ASN1_STRING *)a,(ASN1_STRING *)b) 344 (ASN1_STRING *)a,(ASN1_STRING *)b)
296#define ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) 345#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
297/* i2d_ASN1_BIT_STRING() is a function */
298/* d2i_ASN1_BIT_STRING() is a function */
299 346
300#define ASN1_INTEGER_new() (ASN1_INTEGER *)\ 347#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
301 ASN1_STRING_type_new(V_ASN1_INTEGER) 348 ASN1_STRING_type_new(V_ASN1_INTEGER)
302#define ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a) 349#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
303#define ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a) 350#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
304#define ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\ 351#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
305 (ASN1_STRING *)a,(ASN1_STRING *)b) 352 (ASN1_STRING *)a,(ASN1_STRING *)b)
306/* ASN1_INTEGER_set() is a function, also see BN_to_ASN1_INTEGER() */
307/* ASN1_INTEGER_get() is a function, also see ASN1_INTEGER_to_BN() */
308/* i2d_ASN1_INTEGER() is a function */
309/* d2i_ASN1_INTEGER() is a function */
310 353
311#define ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\ 354#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
312 ASN1_STRING_type_new(V_ASN1_ENUMERATED) 355 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
313#define ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a) 356#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
314#define ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a) 357#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
315#define ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\ 358#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
316 (ASN1_STRING *)a,(ASN1_STRING *)b) 359 (ASN1_STRING *)a,(ASN1_STRING *)b)
317/* ASN1_ENUMERATED_set() is a function, also see BN_to_ASN1_ENUMERATED() */
318/* ASN1_ENUMERATED_get() is a function, also see ASN1_ENUMERATED_to_BN() */
319/* i2d_ASN1_ENUMERATED() is a function */
320/* d2i_ASN1_ENUMERATED() is a function */
321 360
322#define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\ 361#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
323 ASN1_STRING_type_new(V_ASN1_OCTET_STRING) 362 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
324#define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 363#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
325#define ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\ 364#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
326 ASN1_STRING_dup((ASN1_STRING *)a) 365 ASN1_STRING_dup((ASN1_STRING *)a)
327#define ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\ 366#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
328 (ASN1_STRING *)a,(ASN1_STRING *)b) 367 (ASN1_STRING *)a,(ASN1_STRING *)b)
329#define ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) 368#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
330#define ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b) 369#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
331#define M_i2d_ASN1_OCTET_STRING(a,pp) \ 370#define M_i2d_ASN1_OCTET_STRING(a,pp) \
332 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\ 371 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
333 V_ASN1_OCTET_STRING) 372 V_ASN1_UNIVERSAL)
334/* d2i_ASN1_OCTET_STRING() is a function */
335 373
336#define ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING) 374#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
337#define ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a) 375#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
338#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ 376#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
339 pp,a->type,V_ASN1_UNIVERSAL) 377 pp,a->type,V_ASN1_UNIVERSAL)
340#define M_d2i_ASN1_PRINTABLE(a,pp,l) \ 378#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
@@ -345,10 +383,11 @@ typedef struct asn1_header_st
345 B_ASN1_BIT_STRING| \ 383 B_ASN1_BIT_STRING| \
346 B_ASN1_UNIVERSALSTRING|\ 384 B_ASN1_UNIVERSALSTRING|\
347 B_ASN1_BMPSTRING|\ 385 B_ASN1_BMPSTRING|\
386 B_ASN1_UTF8STRING|\
348 B_ASN1_UNKNOWN) 387 B_ASN1_UNKNOWN)
349 388
350#define DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) 389#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
351#define DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 390#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
352#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ 391#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
353 pp,a->type,V_ASN1_UNIVERSAL) 392 pp,a->type,V_ASN1_UNIVERSAL)
354#define M_d2i_DIRECTORYSTRING(a,pp,l) \ 393#define M_d2i_DIRECTORYSTRING(a,pp,l) \
@@ -359,8 +398,8 @@ typedef struct asn1_header_st
359 B_ASN1_UNIVERSALSTRING|\ 398 B_ASN1_UNIVERSALSTRING|\
360 B_ASN1_UTF8STRING) 399 B_ASN1_UTF8STRING)
361 400
362#define DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) 401#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
363#define DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a) 402#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
364#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ 403#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
365 pp,a->type,V_ASN1_UNIVERSAL) 404 pp,a->type,V_ASN1_UNIVERSAL)
366#define M_d2i_DISPLAYTEXT(a,pp,l) \ 405#define M_d2i_DISPLAYTEXT(a,pp,l) \
@@ -369,9 +408,9 @@ typedef struct asn1_header_st
369 B_ASN1_BMPSTRING|\ 408 B_ASN1_BMPSTRING|\
370 B_ASN1_UTF8STRING) 409 B_ASN1_UTF8STRING)
371 410
372#define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\ 411#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
373 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) 412 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
374#define ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 413#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
375#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \ 414#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
376 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\ 415 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
377 V_ASN1_UNIVERSAL) 416 V_ASN1_UNIVERSAL)
@@ -379,9 +418,9 @@ typedef struct asn1_header_st
379 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\ 418 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
380 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING) 419 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
381 420
382#define ASN1_T61STRING_new() (ASN1_T61STRING_STRING *)\ 421#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
383 ASN1_STRING_type_new(V_ASN1_T61STRING) 422 ASN1_STRING_type_new(V_ASN1_T61STRING)
384#define ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 423#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
385#define M_i2d_ASN1_T61STRING(a,pp) \ 424#define M_i2d_ASN1_T61STRING(a,pp) \
386 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\ 425 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
387 V_ASN1_UNIVERSAL) 426 V_ASN1_UNIVERSAL)
@@ -389,10 +428,10 @@ typedef struct asn1_header_st
389 (ASN1_T61STRING *)d2i_ASN1_type_bytes\ 428 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
390 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING) 429 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
391 430
392#define ASN1_IA5STRING_new() (ASN1_IA5STRING *)\ 431#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
393 ASN1_STRING_type_new(V_ASN1_IA5STRING) 432 ASN1_STRING_type_new(V_ASN1_IA5STRING)
394#define ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 433#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
395#define ASN1_IA5STRING_dup(a) \ 434#define M_ASN1_IA5STRING_dup(a) \
396 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a) 435 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
397#define M_i2d_ASN1_IA5STRING(a,pp) \ 436#define M_i2d_ASN1_IA5STRING(a,pp) \
398 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\ 437 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
@@ -401,38 +440,25 @@ typedef struct asn1_header_st
401 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\ 440 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
402 B_ASN1_IA5STRING) 441 B_ASN1_IA5STRING)
403 442
404#define ASN1_UTCTIME_new() (ASN1_UTCTIME *)\ 443#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
405 ASN1_STRING_type_new(V_ASN1_UTCTIME) 444 ASN1_STRING_type_new(V_ASN1_UTCTIME)
406#define ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) 445#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
407#define ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a) 446#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
408/* i2d_ASN1_UTCTIME() is a function */ 447
409/* d2i_ASN1_UTCTIME() is a function */ 448#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
410/* ASN1_UTCTIME_set() is a function */
411/* ASN1_UTCTIME_check() is a function */
412
413#define ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
414 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME) 449 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
415#define ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) 450#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
416#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\ 451#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
417 (ASN1_STRING *)a) 452 (ASN1_STRING *)a)
418/* i2d_ASN1_GENERALIZEDTIME() is a function */
419/* d2i_ASN1_GENERALIZEDTIME() is a function */
420/* ASN1_GENERALIZEDTIME_set() is a function */
421/* ASN1_GENERALIZEDTIME_check() is a function */
422 453
423#define ASN1_TIME_new() (ASN1_TIME *)\ 454#define M_ASN1_TIME_new() (ASN1_TIME *)\
424 ASN1_STRING_type_new(V_ASN1_UTCTIME) 455 ASN1_STRING_type_new(V_ASN1_UTCTIME)
425#define ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) 456#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
426#define ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a) 457#define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
427 458
428/* i2d_ASN1_TIME() is a function */ 459#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
429/* d2i_ASN1_TIME() is a function */
430/* ASN1_TIME_set() is a function */
431/* ASN1_TIME_check() is a function */
432
433#define ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
434 ASN1_STRING_type_new(V_ASN1_GENERALSTRING) 460 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
435#define ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 461#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
436#define M_i2d_ASN1_GENERALSTRING(a,pp) \ 462#define M_i2d_ASN1_GENERALSTRING(a,pp) \
437 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\ 463 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
438 V_ASN1_UNIVERSAL) 464 V_ASN1_UNIVERSAL)
@@ -440,9 +466,9 @@ typedef struct asn1_header_st
440 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\ 466 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
441 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING) 467 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
442 468
443#define ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\ 469#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
444 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING) 470 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
445#define ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 471#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
446#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \ 472#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
447 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\ 473 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
448 V_ASN1_UNIVERSAL) 474 V_ASN1_UNIVERSAL)
@@ -450,9 +476,9 @@ typedef struct asn1_header_st
450 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\ 476 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
451 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING) 477 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
452 478
453#define ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\ 479#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
454 ASN1_STRING_type_new(V_ASN1_BMPSTRING) 480 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
455#define ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 481#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
456#define M_i2d_ASN1_BMPSTRING(a,pp) \ 482#define M_i2d_ASN1_BMPSTRING(a,pp) \
457 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\ 483 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
458 V_ASN1_UNIVERSAL) 484 V_ASN1_UNIVERSAL)
@@ -460,9 +486,9 @@ typedef struct asn1_header_st
460 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\ 486 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
461 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING) 487 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
462 488
463#define ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\ 489#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
464 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) 490 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
465#define ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 491#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
466#define M_i2d_ASN1_VISIBLESTRING(a,pp) \ 492#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
467 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\ 493 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
468 V_ASN1_UNIVERSAL) 494 V_ASN1_UNIVERSAL)
@@ -470,9 +496,9 @@ typedef struct asn1_header_st
470 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\ 496 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
471 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING) 497 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
472 498
473#define ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\ 499#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
474 ASN1_STRING_type_new(V_ASN1_UTF8STRING) 500 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
475#define ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 501#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
476#define M_i2d_ASN1_UTF8STRING(a,pp) \ 502#define M_i2d_ASN1_UTF8STRING(a,pp) \
477 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\ 503 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
478 V_ASN1_UNIVERSAL) 504 V_ASN1_UNIVERSAL)
@@ -500,7 +526,7 @@ ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
500DECLARE_STACK_OF(ASN1_OBJECT) 526DECLARE_STACK_OF(ASN1_OBJECT)
501DECLARE_ASN1_SET_OF(ASN1_OBJECT) 527DECLARE_ASN1_SET_OF(ASN1_OBJECT)
502 528
503ASN1_STRING * ASN1_STRING_new(void ); 529ASN1_STRING * ASN1_STRING_new(void);
504void ASN1_STRING_free(ASN1_STRING *a); 530void ASN1_STRING_free(ASN1_STRING *a);
505ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a); 531ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
506ASN1_STRING * ASN1_STRING_type_new(int type ); 532ASN1_STRING * ASN1_STRING_type_new(int type );
@@ -508,23 +534,44 @@ int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
508 /* Since this is used to store all sorts of things, via macros, for now, make 534 /* Since this is used to store all sorts of things, via macros, for now, make
509 its data void * */ 535 its data void * */
510int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); 536int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
537int ASN1_STRING_length(ASN1_STRING *x);
538void ASN1_STRING_length_set(ASN1_STRING *x, int n);
539int ASN1_STRING_type(ASN1_STRING *x);
540unsigned char * ASN1_STRING_data(ASN1_STRING *x);
511 541
542ASN1_BIT_STRING * ASN1_BIT_STRING_new(void);
543void ASN1_BIT_STRING_free(ASN1_BIT_STRING *a);
512int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp); 544int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
513ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp, 545ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
514 long length); 546 long length);
547int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
548 int length );
515int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value); 549int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
516int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n); 550int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
517 551
552#ifdef HEADER_BIO_H
553int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
554 BIT_STRING_BITNAME *tbl, int indent);
555#endif
556int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
557int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
558 BIT_STRING_BITNAME *tbl);
518 559
519int i2d_ASN1_BOOLEAN(int a,unsigned char **pp); 560int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
520int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length); 561int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
521 562
563ASN1_INTEGER * ASN1_INTEGER_new(void);
564void ASN1_INTEGER_free(ASN1_INTEGER *a);
522int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); 565int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
523ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp, 566ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
524 long length); 567 long length);
525ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp, 568ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
526 long length); 569 long length);
570ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
571int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
527 572
573ASN1_ENUMERATED * ASN1_ENUMERATED_new(void);
574void ASN1_ENUMERATED_free(ASN1_ENUMERATED *a);
528int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp); 575int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp);
529ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp, 576ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp,
530 long length); 577 long length);
@@ -537,49 +584,88 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
537ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t); 584ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
538int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str); 585int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
539 586
587ASN1_OCTET_STRING * ASN1_OCTET_STRING_new(void);
588void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a);
540int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp); 589int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
541ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, 590ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
542 unsigned char **pp,long length); 591 unsigned char **pp,long length);
592ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
593int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
594int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
543 595
596ASN1_VISIBLESTRING * ASN1_VISIBLESTRING_new(void);
597void ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *a);
544int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp); 598int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp);
545ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a, 599ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a,
546 unsigned char **pp,long length); 600 unsigned char **pp,long length);
547 601
602ASN1_UTF8STRING * ASN1_UTF8STRING_new(void);
603void ASN1_UTF8STRING_free(ASN1_UTF8STRING *a);
548int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp); 604int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
549ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, 605ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
550 unsigned char **pp,long length); 606 unsigned char **pp,long length);
551 607
608ASN1_NULL * ASN1_NULL_new(void);
609void ASN1_NULL_free(ASN1_NULL *a);
610int i2d_ASN1_NULL(ASN1_NULL *a,unsigned char **pp);
611ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **a, unsigned char **pp,long length);
612
613ASN1_BMPSTRING * ASN1_BMPSTRING_new(void);
614void ASN1_BMPSTRING_free(ASN1_BMPSTRING *a);
552int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp); 615int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
553ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp, 616ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp,
554 long length); 617 long length);
555 618
619
620int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
621int UTF8_putc(unsigned char *str, int len, unsigned long value);
622
556int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp); 623int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
557ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, 624ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
558 unsigned char **pp, long l); 625 unsigned char **pp, long l);
626
627ASN1_PRINTABLESTRING * ASN1_PRINTABLESTRING_new(void);
628void ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *a);
559ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, 629ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
560 unsigned char **pp, long l); 630 unsigned char **pp, long l);
631int i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **pp);
561 632
633ASN1_STRING * DIRECTORYSTRING_new(void);
634void DIRECTORYSTRING_free(ASN1_STRING *a);
562int i2d_DIRECTORYSTRING(ASN1_STRING *a,unsigned char **pp); 635int i2d_DIRECTORYSTRING(ASN1_STRING *a,unsigned char **pp);
563ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp, 636ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
564 long length); 637 long length);
565 638
639ASN1_STRING * DISPLAYTEXT_new(void);
640void DISPLAYTEXT_free(ASN1_STRING *a);
566int i2d_DISPLAYTEXT(ASN1_STRING *a,unsigned char **pp); 641int i2d_DISPLAYTEXT(ASN1_STRING *a,unsigned char **pp);
567ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, long length); 642ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, long length);
568 643
644ASN1_T61STRING * ASN1_T61STRING_new(void);
645void ASN1_T61STRING_free(ASN1_IA5STRING *a);
569ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, 646ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
570 unsigned char **pp, long l); 647 unsigned char **pp, long l);
648
649ASN1_IA5STRING * ASN1_IA5STRING_new(void);
650void ASN1_IA5STRING_free(ASN1_IA5STRING *a);
571int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp); 651int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
572ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, 652ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a,
573 unsigned char **pp, long l); 653 unsigned char **pp, long l);
574 654
655ASN1_UTCTIME * ASN1_UTCTIME_new(void);
656void ASN1_UTCTIME_free(ASN1_UTCTIME *a);
575int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp); 657int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
576ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp, 658ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
577 long length); 659 long length);
578 660
661ASN1_GENERALIZEDTIME * ASN1_GENERALIZEDTIME_new(void);
662void ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *a);
579int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp); 663int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp);
580ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp, 664ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp,
581 long length); 665 long length);
582 666
667ASN1_TIME * ASN1_TIME_new(void);
668void ASN1_TIME_free(ASN1_TIME *a);
583int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp); 669int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp);
584ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length); 670ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length);
585ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t); 671ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
@@ -654,6 +740,7 @@ int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
654int ASN1_STRING_print(BIO *bp,ASN1_STRING *v); 740int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
655int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent); 741int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
656#endif 742#endif
743const char *ASN1_tag2str(int tag);
657 744
658/* Used to load and write netscape format cert/key */ 745/* Used to load and write netscape format cert/key */
659int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp); 746int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
@@ -687,6 +774,21 @@ unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
687void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)()); 774void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
688ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct); 775ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
689 776
777void ASN1_STRING_set_default_mask(unsigned long mask);
778int ASN1_STRING_set_default_mask_asc(char *p);
779unsigned long ASN1_STRING_get_default_mask(void);
780int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
781 int inform, unsigned long mask);
782int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
783 int inform, unsigned long mask,
784 long minsize, long maxsize);
785
786ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
787 const unsigned char *in, int inlen, int inform, int nid);
788ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
789int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
790void ASN1_STRING_TABLE_cleanup(void);
791
690/* BEGIN ERROR CODES */ 792/* BEGIN ERROR CODES */
691/* The following lines are auto generated by the script mkerr.pl. Any changes 793/* The following lines are auto generated by the script mkerr.pl. Any changes
692 * made after this point may be overwritten when the script is next run. 794 * made after this point may be overwritten when the script is next run.
@@ -699,6 +801,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
699#define ASN1_F_A2I_ASN1_ENUMERATED 236 801#define ASN1_F_A2I_ASN1_ENUMERATED 236
700#define ASN1_F_A2I_ASN1_INTEGER 101 802#define ASN1_F_A2I_ASN1_INTEGER 101
701#define ASN1_F_A2I_ASN1_STRING 102 803#define ASN1_F_A2I_ASN1_STRING 102
804#define ASN1_F_ACCESS_DESCRIPTION_NEW 291
702#define ASN1_F_ASN1_COLLATE_PRIMITIVE 103 805#define ASN1_F_ASN1_COLLATE_PRIMITIVE 103
703#define ASN1_F_ASN1_D2I_BIO 104 806#define ASN1_F_ASN1_D2I_BIO 104
704#define ASN1_F_ASN1_D2I_FP 105 807#define ASN1_F_ASN1_D2I_FP 105
@@ -712,6 +815,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
712#define ASN1_F_ASN1_I2D_FP 110 815#define ASN1_F_ASN1_I2D_FP 110
713#define ASN1_F_ASN1_INTEGER_SET 111 816#define ASN1_F_ASN1_INTEGER_SET 111
714#define ASN1_F_ASN1_INTEGER_TO_BN 112 817#define ASN1_F_ASN1_INTEGER_TO_BN 112
818#define ASN1_F_ASN1_MBSTRING_COPY 282
715#define ASN1_F_ASN1_OBJECT_NEW 113 819#define ASN1_F_ASN1_OBJECT_NEW 113
716#define ASN1_F_ASN1_PACK_STRING 245 820#define ASN1_F_ASN1_PACK_STRING 245
717#define ASN1_F_ASN1_PBE_SET 253 821#define ASN1_F_ASN1_PBE_SET 253
@@ -719,6 +823,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
719#define ASN1_F_ASN1_SEQ_UNPACK 247 823#define ASN1_F_ASN1_SEQ_UNPACK 247
720#define ASN1_F_ASN1_SIGN 114 824#define ASN1_F_ASN1_SIGN 114
721#define ASN1_F_ASN1_STRING_NEW 115 825#define ASN1_F_ASN1_STRING_NEW 115
826#define ASN1_F_ASN1_STRING_TABLE_ADD 283
722#define ASN1_F_ASN1_STRING_TYPE_NEW 116 827#define ASN1_F_ASN1_STRING_TYPE_NEW 116
723#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117 828#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117
724#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118 829#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118
@@ -730,6 +835,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
730#define ASN1_F_BASIC_CONSTRAINTS_NEW 226 835#define ASN1_F_BASIC_CONSTRAINTS_NEW 226
731#define ASN1_F_BN_TO_ASN1_ENUMERATED 234 836#define ASN1_F_BN_TO_ASN1_ENUMERATED 234
732#define ASN1_F_BN_TO_ASN1_INTEGER 122 837#define ASN1_F_BN_TO_ASN1_INTEGER 122
838#define ASN1_F_D2I_ACCESS_DESCRIPTION 284
733#define ASN1_F_D2I_ASN1_BIT_STRING 123 839#define ASN1_F_D2I_ASN1_BIT_STRING 123
734#define ASN1_F_D2I_ASN1_BMPSTRING 124 840#define ASN1_F_D2I_ASN1_BMPSTRING 124
735#define ASN1_F_D2I_ASN1_BOOLEAN 125 841#define ASN1_F_D2I_ASN1_BOOLEAN 125
@@ -738,6 +844,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
738#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223 844#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
739#define ASN1_F_D2I_ASN1_HEADER 127 845#define ASN1_F_D2I_ASN1_HEADER 127
740#define ASN1_F_D2I_ASN1_INTEGER 128 846#define ASN1_F_D2I_ASN1_INTEGER 128
847#define ASN1_F_D2I_ASN1_NULL 292
741#define ASN1_F_D2I_ASN1_OBJECT 129 848#define ASN1_F_D2I_ASN1_OBJECT 129
742#define ASN1_F_D2I_ASN1_OCTET_STRING 130 849#define ASN1_F_D2I_ASN1_OCTET_STRING 130
743#define ASN1_F_D2I_ASN1_PRINT_TYPE 131 850#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
@@ -765,6 +872,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
765#define ASN1_F_D2I_NETSCAPE_SPKAC 143 872#define ASN1_F_D2I_NETSCAPE_SPKAC 143
766#define ASN1_F_D2I_NETSCAPE_SPKI 144 873#define ASN1_F_D2I_NETSCAPE_SPKI 144
767#define ASN1_F_D2I_NOTICEREF 268 874#define ASN1_F_D2I_NOTICEREF 268
875#define ASN1_F_D2I_OTHERNAME 287
768#define ASN1_F_D2I_PBE2PARAM 262 876#define ASN1_F_D2I_PBE2PARAM 262
769#define ASN1_F_D2I_PBEPARAM 249 877#define ASN1_F_D2I_PBEPARAM 249
770#define ASN1_F_D2I_PBKDF2PARAM 263 878#define ASN1_F_D2I_PBKDF2PARAM 263
@@ -796,6 +904,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
796#define ASN1_F_D2I_X509 159 904#define ASN1_F_D2I_X509 159
797#define ASN1_F_D2I_X509_ALGOR 160 905#define ASN1_F_D2I_X509_ALGOR 160
798#define ASN1_F_D2I_X509_ATTRIBUTE 161 906#define ASN1_F_D2I_X509_ATTRIBUTE 161
907#define ASN1_F_D2I_X509_CERT_AUX 285
799#define ASN1_F_D2I_X509_CINF 162 908#define ASN1_F_D2I_X509_CINF 162
800#define ASN1_F_D2I_X509_CRL 163 909#define ASN1_F_D2I_X509_CRL 163
801#define ASN1_F_D2I_X509_CRL_INFO 164 910#define ASN1_F_D2I_X509_CRL_INFO 164
@@ -819,12 +928,14 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
819#define ASN1_F_I2D_DSAPARAMS 178 928#define ASN1_F_I2D_DSAPARAMS 178
820#define ASN1_F_I2D_DSAPRIVATEKEY 179 929#define ASN1_F_I2D_DSAPRIVATEKEY 179
821#define ASN1_F_I2D_DSAPUBLICKEY 180 930#define ASN1_F_I2D_DSAPUBLICKEY 180
931#define ASN1_F_I2D_DSA_PUBKEY 290
822#define ASN1_F_I2D_NETSCAPE_RSA 181 932#define ASN1_F_I2D_NETSCAPE_RSA 181
823#define ASN1_F_I2D_PKCS7 182 933#define ASN1_F_I2D_PKCS7 182
824#define ASN1_F_I2D_PRIVATEKEY 183 934#define ASN1_F_I2D_PRIVATEKEY 183
825#define ASN1_F_I2D_PUBLICKEY 184 935#define ASN1_F_I2D_PUBLICKEY 184
826#define ASN1_F_I2D_RSAPRIVATEKEY 185 936#define ASN1_F_I2D_RSAPRIVATEKEY 185
827#define ASN1_F_I2D_RSAPUBLICKEY 186 937#define ASN1_F_I2D_RSAPUBLICKEY 186
938#define ASN1_F_I2D_RSA_PUBKEY 289
828#define ASN1_F_I2D_X509_ATTRIBUTE 187 939#define ASN1_F_I2D_X509_ATTRIBUTE 187
829#define ASN1_F_I2T_ASN1_OBJECT 188 940#define ASN1_F_I2T_ASN1_OBJECT 188
830#define ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW 229 941#define ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW 229
@@ -832,6 +943,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
832#define ASN1_F_NETSCAPE_SPKAC_NEW 190 943#define ASN1_F_NETSCAPE_SPKAC_NEW 190
833#define ASN1_F_NETSCAPE_SPKI_NEW 191 944#define ASN1_F_NETSCAPE_SPKI_NEW 191
834#define ASN1_F_NOTICEREF_NEW 272 945#define ASN1_F_NOTICEREF_NEW 272
946#define ASN1_F_OTHERNAME_NEW 288
835#define ASN1_F_PBE2PARAM_NEW 264 947#define ASN1_F_PBE2PARAM_NEW 264
836#define ASN1_F_PBEPARAM_NEW 251 948#define ASN1_F_PBEPARAM_NEW 251
837#define ASN1_F_PBKDF2PARAM_NEW 265 949#define ASN1_F_PBKDF2PARAM_NEW 265
@@ -859,6 +971,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
859#define ASN1_F_USERNOTICE_NEW 275 971#define ASN1_F_USERNOTICE_NEW 275
860#define ASN1_F_X509_ALGOR_NEW 202 972#define ASN1_F_X509_ALGOR_NEW 202
861#define ASN1_F_X509_ATTRIBUTE_NEW 203 973#define ASN1_F_X509_ATTRIBUTE_NEW 203
974#define ASN1_F_X509_CERT_AUX_NEW 286
862#define ASN1_F_X509_CINF_NEW 204 975#define ASN1_F_X509_CINF_NEW 204
863#define ASN1_F_X509_CRL_INFO_NEW 205 976#define ASN1_F_X509_CRL_INFO_NEW 205
864#define ASN1_F_X509_CRL_NEW 206 977#define ASN1_F_X509_CRL_NEW 206
@@ -889,6 +1002,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
889#define ASN1_R_BN_LIB 107 1002#define ASN1_R_BN_LIB 107
890#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108 1003#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108
891#define ASN1_R_BUFFER_TOO_SMALL 109 1004#define ASN1_R_BUFFER_TOO_SMALL 109
1005#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 166
892#define ASN1_R_DATA_IS_WRONG 110 1006#define ASN1_R_DATA_IS_WRONG 110
893#define ASN1_R_DECODE_ERROR 155 1007#define ASN1_R_DECODE_ERROR 155
894#define ASN1_R_DECODING_ERROR 111 1008#define ASN1_R_DECODING_ERROR 111
@@ -902,24 +1016,31 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
902#define ASN1_R_EXPECTING_A_BIT_STRING 116 1016#define ASN1_R_EXPECTING_A_BIT_STRING 116
903#define ASN1_R_EXPECTING_A_BOOLEAN 117 1017#define ASN1_R_EXPECTING_A_BOOLEAN 117
904#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151 1018#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151
1019#define ASN1_R_EXPECTING_A_NULL 164
905#define ASN1_R_EXPECTING_A_TIME 152 1020#define ASN1_R_EXPECTING_A_TIME 152
906#define ASN1_R_EXPECTING_A_UTCTIME 118 1021#define ASN1_R_EXPECTING_A_UTCTIME 118
907#define ASN1_R_FIRST_NUM_TOO_LARGE 119 1022#define ASN1_R_FIRST_NUM_TOO_LARGE 119
908#define ASN1_R_GENERALIZEDTIME_TOO_LONG 153 1023#define ASN1_R_GENERALIZEDTIME_TOO_LONG 153
909#define ASN1_R_HEADER_TOO_LONG 120 1024#define ASN1_R_HEADER_TOO_LONG 120
1025#define ASN1_R_ILLEGAL_CHARACTERS 158
1026#define ASN1_R_INVALID_BMPSTRING_LENGTH 159
910#define ASN1_R_INVALID_DIGIT 121 1027#define ASN1_R_INVALID_DIGIT 121
911#define ASN1_R_INVALID_SEPARATOR 122 1028#define ASN1_R_INVALID_SEPARATOR 122
912#define ASN1_R_INVALID_TIME_FORMAT 123 1029#define ASN1_R_INVALID_TIME_FORMAT 123
1030#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 160
1031#define ASN1_R_INVALID_UTF8STRING 161
913#define ASN1_R_IV_TOO_LARGE 124 1032#define ASN1_R_IV_TOO_LARGE 124
914#define ASN1_R_LENGTH_ERROR 125 1033#define ASN1_R_LENGTH_ERROR 125
915#define ASN1_R_MISSING_SECOND_NUMBER 126 1034#define ASN1_R_MISSING_SECOND_NUMBER 126
916#define ASN1_R_NON_HEX_CHARACTERS 127 1035#define ASN1_R_NON_HEX_CHARACTERS 127
917#define ASN1_R_NOT_ENOUGH_DATA 128 1036#define ASN1_R_NOT_ENOUGH_DATA 128
1037#define ASN1_R_NULL_IS_WRONG_LENGTH 165
918#define ASN1_R_ODD_NUMBER_OF_CHARS 129 1038#define ASN1_R_ODD_NUMBER_OF_CHARS 129
919#define ASN1_R_PARSING 130 1039#define ASN1_R_PARSING 130
920#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131 1040#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131
921#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132 1041#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132
922#define ASN1_R_SHORT_LINE 133 1042#define ASN1_R_SHORT_LINE 133
1043#define ASN1_R_STRING_TOO_LONG 163
923#define ASN1_R_STRING_TOO_SHORT 134 1044#define ASN1_R_STRING_TOO_SHORT 134
924#define ASN1_R_TAG_VALUE_TOO_HIGH 135 1045#define ASN1_R_TAG_VALUE_TOO_HIGH 135
925#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136 1046#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136
@@ -927,6 +1048,7 @@ ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
927#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138 1048#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138
928#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139 1049#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139
929#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140 1050#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140
1051#define ASN1_R_UNKNOWN_FORMAT 162
930#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141 1052#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141
931#define ASN1_R_UNKNOWN_OBJECT_TYPE 142 1053#define ASN1_R_UNKNOWN_OBJECT_TYPE 142
932#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143 1054#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
index 16755a0b05..b183814242 100644
--- a/src/lib/libcrypto/asn1/asn1_err.c
+++ b/src/lib/libcrypto/asn1/asn1_err.c
@@ -69,19 +69,21 @@ static ERR_STRING_DATA ASN1_str_functs[]=
69{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"}, 69{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"},
70{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"}, 70{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"},
71{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"}, 71{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"},
72{ERR_PACK(0,ASN1_F_ACCESS_DESCRIPTION_NEW,0), "ACCESS_DESCRIPTION_new"},
72{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"}, 73{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"},
73{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"}, 74{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
74{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"}, 75{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
75{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"}, 76{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
76{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"}, 77{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
77{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"}, 78{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
78{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_NEW"}, 79{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_new"},
79{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"}, 80{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
80{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"}, 81{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
81{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"}, 82{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
82{ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"}, 83{ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"},
83{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"}, 84{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"},
84{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"}, 85{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"},
86{ERR_PACK(0,ASN1_F_ASN1_MBSTRING_COPY,0), "ASN1_mbstring_copy"},
85{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"}, 87{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"},
86{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"}, 88{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"},
87{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"}, 89{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"},
@@ -89,17 +91,19 @@ static ERR_STRING_DATA ASN1_str_functs[]=
89{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"}, 91{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"},
90{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"}, 92{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"},
91{ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"}, 93{ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"},
94{ERR_PACK(0,ASN1_F_ASN1_STRING_TABLE_ADD,0), "ASN1_STRING_TABLE_add"},
92{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"}, 95{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
93{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"}, 96{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"},
94{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"}, 97{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
95{ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"}, 98{ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"},
96{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"}, 99{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"},
97{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"}, 100{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_new"},
98{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"}, 101{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"},
99{ERR_PACK(0,ASN1_F_AUTHORITY_KEYID_NEW,0), "AUTHORITY_KEYID_new"}, 102{ERR_PACK(0,ASN1_F_AUTHORITY_KEYID_NEW,0), "AUTHORITY_KEYID_new"},
100{ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_new"}, 103{ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_new"},
101{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"}, 104{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
102{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"}, 105{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
106{ERR_PACK(0,ASN1_F_D2I_ACCESS_DESCRIPTION,0), "d2i_ACCESS_DESCRIPTION"},
103{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"}, 107{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"},
104{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"}, 108{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"},
105{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"}, 109{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
@@ -108,6 +112,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
108{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"}, 112{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"},
109{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"}, 113{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
110{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"}, 114{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"},
115{ERR_PACK(0,ASN1_F_D2I_ASN1_NULL,0), "d2i_ASN1_NULL"},
111{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"}, 116{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
112{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"}, 117{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"},
113{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"}, 118{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"},
@@ -135,6 +140,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
135{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "d2i_NETSCAPE_SPKAC"}, 140{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "d2i_NETSCAPE_SPKAC"},
136{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "d2i_NETSCAPE_SPKI"}, 141{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "d2i_NETSCAPE_SPKI"},
137{ERR_PACK(0,ASN1_F_D2I_NOTICEREF,0), "d2i_NOTICEREF"}, 142{ERR_PACK(0,ASN1_F_D2I_NOTICEREF,0), "d2i_NOTICEREF"},
143{ERR_PACK(0,ASN1_F_D2I_OTHERNAME,0), "d2i_OTHERNAME"},
138{ERR_PACK(0,ASN1_F_D2I_PBE2PARAM,0), "d2i_PBE2PARAM"}, 144{ERR_PACK(0,ASN1_F_D2I_PBE2PARAM,0), "d2i_PBE2PARAM"},
139{ERR_PACK(0,ASN1_F_D2I_PBEPARAM,0), "d2i_PBEPARAM"}, 145{ERR_PACK(0,ASN1_F_D2I_PBEPARAM,0), "d2i_PBEPARAM"},
140{ERR_PACK(0,ASN1_F_D2I_PBKDF2PARAM,0), "d2i_PBKDF2PARAM"}, 146{ERR_PACK(0,ASN1_F_D2I_PBKDF2PARAM,0), "d2i_PBKDF2PARAM"},
@@ -166,6 +172,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
166{ERR_PACK(0,ASN1_F_D2I_X509,0), "d2i_X509"}, 172{ERR_PACK(0,ASN1_F_D2I_X509,0), "d2i_X509"},
167{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "d2i_X509_ALGOR"}, 173{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "d2i_X509_ALGOR"},
168{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "d2i_X509_ATTRIBUTE"}, 174{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "d2i_X509_ATTRIBUTE"},
175{ERR_PACK(0,ASN1_F_D2I_X509_CERT_AUX,0), "d2i_X509_CERT_AUX"},
169{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "d2i_X509_CINF"}, 176{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "d2i_X509_CINF"},
170{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "d2i_X509_CRL"}, 177{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "d2i_X509_CRL"},
171{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "d2i_X509_CRL_INFO"}, 178{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "d2i_X509_CRL_INFO"},
@@ -189,12 +196,14 @@ static ERR_STRING_DATA ASN1_str_functs[]=
189{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "i2d_DSAparams"}, 196{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "i2d_DSAparams"},
190{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "i2d_DSAPrivateKey"}, 197{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "i2d_DSAPrivateKey"},
191{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "i2d_DSAPublicKey"}, 198{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "i2d_DSAPublicKey"},
199{ERR_PACK(0,ASN1_F_I2D_DSA_PUBKEY,0), "i2d_DSA_PUBKEY"},
192{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"}, 200{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"},
193{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "i2d_PKCS7"}, 201{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "i2d_PKCS7"},
194{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"}, 202{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"},
195{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"}, 203{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"},
196{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "i2d_RSAPrivateKey"}, 204{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "i2d_RSAPrivateKey"},
197{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "i2d_RSAPublicKey"}, 205{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "i2d_RSAPublicKey"},
206{ERR_PACK(0,ASN1_F_I2D_RSA_PUBKEY,0), "i2d_RSA_PUBKEY"},
198{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "i2d_X509_ATTRIBUTE"}, 207{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "i2d_X509_ATTRIBUTE"},
199{ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"}, 208{ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"},
200{ERR_PACK(0,ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW,0), "NETSCAPE_CERT_SEQUENCE_new"}, 209{ERR_PACK(0,ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW,0), "NETSCAPE_CERT_SEQUENCE_new"},
@@ -202,6 +211,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
202{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_new"}, 211{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_new"},
203{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_new"}, 212{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_new"},
204{ERR_PACK(0,ASN1_F_NOTICEREF_NEW,0), "NOTICEREF_new"}, 213{ERR_PACK(0,ASN1_F_NOTICEREF_NEW,0), "NOTICEREF_new"},
214{ERR_PACK(0,ASN1_F_OTHERNAME_NEW,0), "OTHERNAME_new"},
205{ERR_PACK(0,ASN1_F_PBE2PARAM_NEW,0), "PBE2PARAM_new"}, 215{ERR_PACK(0,ASN1_F_PBE2PARAM_NEW,0), "PBE2PARAM_new"},
206{ERR_PACK(0,ASN1_F_PBEPARAM_NEW,0), "PBEPARAM_new"}, 216{ERR_PACK(0,ASN1_F_PBEPARAM_NEW,0), "PBEPARAM_new"},
207{ERR_PACK(0,ASN1_F_PBKDF2PARAM_NEW,0), "PBKDF2PARAM_new"}, 217{ERR_PACK(0,ASN1_F_PBKDF2PARAM_NEW,0), "PBKDF2PARAM_new"},
@@ -229,6 +239,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
229{ERR_PACK(0,ASN1_F_USERNOTICE_NEW,0), "USERNOTICE_new"}, 239{ERR_PACK(0,ASN1_F_USERNOTICE_NEW,0), "USERNOTICE_new"},
230{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_new"}, 240{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_new"},
231{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_new"}, 241{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_new"},
242{ERR_PACK(0,ASN1_F_X509_CERT_AUX_NEW,0), "X509_CERT_AUX_new"},
232{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_new"}, 243{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_new"},
233{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_new"}, 244{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_new"},
234{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_new"}, 245{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_new"},
@@ -262,6 +273,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
262{ASN1_R_BN_LIB ,"bn lib"}, 273{ASN1_R_BN_LIB ,"bn lib"},
263{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"}, 274{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"},
264{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"}, 275{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"},
276{ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"},
265{ASN1_R_DATA_IS_WRONG ,"data is wrong"}, 277{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
266{ASN1_R_DECODE_ERROR ,"decode error"}, 278{ASN1_R_DECODE_ERROR ,"decode error"},
267{ASN1_R_DECODING_ERROR ,"decoding error"}, 279{ASN1_R_DECODING_ERROR ,"decoding error"},
@@ -275,24 +287,31 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
275{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"}, 287{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"},
276{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"}, 288{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
277{ASN1_R_EXPECTING_A_GENERALIZEDTIME ,"expecting a generalizedtime"}, 289{ASN1_R_EXPECTING_A_GENERALIZEDTIME ,"expecting a generalizedtime"},
290{ASN1_R_EXPECTING_A_NULL ,"expecting a null"},
278{ASN1_R_EXPECTING_A_TIME ,"expecting a time"}, 291{ASN1_R_EXPECTING_A_TIME ,"expecting a time"},
279{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"}, 292{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"},
280{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"}, 293{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
281{ASN1_R_GENERALIZEDTIME_TOO_LONG ,"generalizedtime too long"}, 294{ASN1_R_GENERALIZEDTIME_TOO_LONG ,"generalizedtime too long"},
282{ASN1_R_HEADER_TOO_LONG ,"header too long"}, 295{ASN1_R_HEADER_TOO_LONG ,"header too long"},
296{ASN1_R_ILLEGAL_CHARACTERS ,"illegal characters"},
297{ASN1_R_INVALID_BMPSTRING_LENGTH ,"invalid bmpstring length"},
283{ASN1_R_INVALID_DIGIT ,"invalid digit"}, 298{ASN1_R_INVALID_DIGIT ,"invalid digit"},
284{ASN1_R_INVALID_SEPARATOR ,"invalid separator"}, 299{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
285{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"}, 300{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
301{ASN1_R_INVALID_UNIVERSALSTRING_LENGTH ,"invalid universalstring length"},
302{ASN1_R_INVALID_UTF8STRING ,"invalid utf8string"},
286{ASN1_R_IV_TOO_LARGE ,"iv too large"}, 303{ASN1_R_IV_TOO_LARGE ,"iv too large"},
287{ASN1_R_LENGTH_ERROR ,"length error"}, 304{ASN1_R_LENGTH_ERROR ,"length error"},
288{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"}, 305{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
289{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"}, 306{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
290{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"}, 307{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
308{ASN1_R_NULL_IS_WRONG_LENGTH ,"null is wrong length"},
291{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"}, 309{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
292{ASN1_R_PARSING ,"parsing"}, 310{ASN1_R_PARSING ,"parsing"},
293{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"}, 311{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},
294{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"}, 312{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"},
295{ASN1_R_SHORT_LINE ,"short line"}, 313{ASN1_R_SHORT_LINE ,"short line"},
314{ASN1_R_STRING_TOO_LONG ,"string too long"},
296{ASN1_R_STRING_TOO_SHORT ,"string too short"}, 315{ASN1_R_STRING_TOO_SHORT ,"string too short"},
297{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"}, 316{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"},
298{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, 317{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
@@ -300,6 +319,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
300{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"}, 319{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"},
301{ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"}, 320{ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"},
302{ASN1_R_UNKNOWN_ATTRIBUTE_TYPE ,"unknown attribute type"}, 321{ASN1_R_UNKNOWN_ATTRIBUTE_TYPE ,"unknown attribute type"},
322{ASN1_R_UNKNOWN_FORMAT ,"unknown format"},
303{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"}, 323{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"},
304{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"}, 324{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"},
305{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"}, 325{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"},
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
index 95e54ed626..be8daa8688 100644
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -176,7 +176,7 @@ static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
176 } 176 }
177 177
178/* class 0 is constructed 178/* class 0 is constructed
179 * constructed == 2 for indefinitle length constructed */ 179 * constructed == 2 for indefinite length constructed */
180void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, 180void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
181 int xclass) 181 int xclass)
182 { 182 {
@@ -349,7 +349,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
349 if (data != NULL) 349 if (data != NULL)
350 { 350 {
351 memcpy(str->data,data,len); 351 memcpy(str->data,data,len);
352 /* an alowance for strings :-) */ 352 /* an allowance for strings :-) */
353 str->data[len]='\0'; 353 str->data[len]='\0';
354 } 354 }
355 return(1); 355 return(1);
@@ -381,8 +381,8 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
381void ASN1_STRING_free(ASN1_STRING *a) 381void ASN1_STRING_free(ASN1_STRING *a)
382 { 382 {
383 if (a == NULL) return; 383 if (a == NULL) return;
384 if (a->data != NULL) Free((char *)a->data); 384 if (a->data != NULL) Free(a->data);
385 Free((char *)a); 385 Free(a);
386 } 386 }
387 387
388int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b) 388int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
@@ -411,3 +411,14 @@ void asn1_add_error(unsigned char *address, int offset)
411 ERR_add_error_data(4,"address=",buf1," offset=",buf2); 411 ERR_add_error_data(4,"address=",buf1," offset=",buf2);
412 } 412 }
413 413
414int ASN1_STRING_length(ASN1_STRING *x)
415{ return M_ASN1_STRING_length(x); }
416
417void ASN1_STRING_length_set(ASN1_STRING *x, int len)
418{ M_ASN1_STRING_length_set(x, len); return; }
419
420int ASN1_STRING_type(ASN1_STRING *x)
421{ return M_ASN1_STRING_type(x); }
422
423unsigned char * ASN1_STRING_data(ASN1_STRING *x)
424{ return M_ASN1_STRING_data(x); }
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
index 93f9c5193c..4f2a82d340 100644
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ b/src/lib/libcrypto/asn1/asn1_mac.h
@@ -106,6 +106,20 @@ err:\
106#define M_ASN1_D2I_start_sequence() \ 106#define M_ASN1_D2I_start_sequence() \
107 if (!asn1_GetSequence(&c,&length)) \ 107 if (!asn1_GetSequence(&c,&length)) \
108 { c.line=__LINE__; goto err; } 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)
109 123
110#define M_ASN1_D2I_end_sequence() \ 124#define M_ASN1_D2I_end_sequence() \
111 (((c.inf&1) == 0)?(c.slen <= 0): \ 125 (((c.inf&1) == 0)?(c.slen <= 0): \
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c
index 86886606ef..d1e9816bad 100644
--- a/src/lib/libcrypto/asn1/asn1_par.c
+++ b/src/lib/libcrypto/asn1/asn1_par.c
@@ -93,55 +93,8 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
93 sprintf(str,"cont [ %d ]",tag); 93 sprintf(str,"cont [ %d ]",tag);
94 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) 94 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
95 sprintf(str,"appl [ %d ]",tag); 95 sprintf(str,"appl [ %d ]",tag);
96 else if ((tag == V_ASN1_EOC) /* && (xclass == V_ASN1_UNIVERSAL) */) 96 else p = ASN1_tag2str(tag);
97 p="EOC";
98 else if (tag == V_ASN1_BOOLEAN)
99 p="BOOLEAN";
100 else if (tag == V_ASN1_INTEGER)
101 p="INTEGER";
102 else if (tag == V_ASN1_ENUMERATED)
103 p="ENUMERATED";
104 else if (tag == V_ASN1_BIT_STRING)
105 p="BIT STRING";
106 else if (tag == V_ASN1_OCTET_STRING)
107 p="OCTET STRING";
108 else if (tag == V_ASN1_NULL)
109 p="NULL";
110 else if (tag == V_ASN1_OBJECT)
111 p="OBJECT";
112 else if (tag == V_ASN1_SEQUENCE)
113 p="SEQUENCE";
114 else if (tag == V_ASN1_SET)
115 p="SET";
116 else if (tag == V_ASN1_PRINTABLESTRING)
117 p="PRINTABLESTRING";
118 else if (tag == V_ASN1_T61STRING)
119 p="T61STRING";
120 else if (tag == V_ASN1_IA5STRING)
121 p="IA5STRING";
122 else if (tag == V_ASN1_UTCTIME)
123 p="UTCTIME";
124 97
125 /* extras */
126 else if (tag == V_ASN1_NUMERICSTRING)
127 p="NUMERICSTRING";
128 else if (tag == V_ASN1_VIDEOTEXSTRING)
129 p="VIDEOTEXSTRING";
130 else if (tag == V_ASN1_GENERALIZEDTIME)
131 p="GENERALIZEDTIME";
132 else if (tag == V_ASN1_GRAPHICSTRING)
133 p="GRAPHICSTRING";
134 else if (tag == V_ASN1_VISIBLESTRING)
135 p="VISIBLESTRING";
136 else if (tag == V_ASN1_GENERALSTRING)
137 p="GENERALSTRING";
138 else if (tag == V_ASN1_UNIVERSALSTRING)
139 p="UNIVERSALSTRING";
140 else if (tag == V_ASN1_BMPSTRING)
141 p="BMPSTRING";
142 else
143 p2="(unknown)";
144
145 if (p2 != NULL) 98 if (p2 != NULL)
146 { 99 {
147 if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err; 100 if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err;
@@ -320,7 +273,7 @@ static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
320 os->length) <= 0) 273 os->length) <= 0)
321 goto end; 274 goto end;
322 } 275 }
323 ASN1_OCTET_STRING_free(os); 276 M_ASN1_OCTET_STRING_free(os);
324 os=NULL; 277 os=NULL;
325 } 278 }
326 } 279 }
@@ -354,7 +307,7 @@ static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
354 if (BIO_write(bp,"BAD INTEGER",11) <= 0) 307 if (BIO_write(bp,"BAD INTEGER",11) <= 0)
355 goto end; 308 goto end;
356 } 309 }
357 ASN1_INTEGER_free(bs); 310 M_ASN1_INTEGER_free(bs);
358 } 311 }
359 else if (tag == V_ASN1_ENUMERATED) 312 else if (tag == V_ASN1_ENUMERATED)
360 { 313 {
@@ -386,7 +339,7 @@ static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
386 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0) 339 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
387 goto end; 340 goto end;
388 } 341 }
389 ASN1_ENUMERATED_free(bs); 342 M_ASN1_ENUMERATED_free(bs);
390 } 343 }
391 344
392 if (!nl) 345 if (!nl)
@@ -405,7 +358,28 @@ static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
405 ret=1; 358 ret=1;
406end: 359end:
407 if (o != NULL) ASN1_OBJECT_free(o); 360 if (o != NULL) ASN1_OBJECT_free(o);
408 if (os != NULL) ASN1_OCTET_STRING_free(os); 361 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
409 *pp=p; 362 *pp=p;
410 return(ret); 363 return(ret);
411 } 364 }
365
366const char *ASN1_tag2str(int tag)
367{
368 const static char *tag2str[] = {
369 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */
370 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */
371 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */
372 "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */
373 "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */
374 "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */
375 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */
376 "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */
377 };
378
379 if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED))
380 tag &= ~0x100;
381
382 if(tag < 0 || tag > 30) return "(unknown)";
383 return tag2str[tag];
384}
385
diff --git a/src/lib/libcrypto/asn1/d2i_dhp.c b/src/lib/libcrypto/asn1/d2i_dhp.c
index a077211a4c..635ae829db 100644
--- a/src/lib/libcrypto/asn1/d2i_dhp.c
+++ b/src/lib/libcrypto/asn1/d2i_dhp.c
@@ -86,7 +86,7 @@ DH *d2i_DHparams(DH **a, unsigned char **pp, long length)
86 ret->length=(int)v; 86 ret->length=(int)v;
87 } 87 }
88 88
89 ASN1_BIT_STRING_free(bs); 89 M_ASN1_BIT_STRING_free(bs);
90 90
91 M_ASN1_D2I_Finish_2(a); 91 M_ASN1_D2I_Finish_2(a);
92 92
@@ -95,7 +95,7 @@ err_bn:
95err: 95err:
96 ASN1err(ASN1_F_D2I_DHPARAMS,i); 96 ASN1err(ASN1_F_D2I_DHPARAMS,i);
97 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DH_free(ret); 97 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DH_free(ret);
98 if (bs != NULL) ASN1_BIT_STRING_free(bs); 98 if (bs != NULL) M_ASN1_BIT_STRING_free(bs);
99 return(NULL); 99 return(NULL);
100 } 100 }
101#endif 101#endif
diff --git a/src/lib/libcrypto/asn1/d2i_dsap.c b/src/lib/libcrypto/asn1/d2i_dsap.c
index cdd7136f51..6d1c297133 100644
--- a/src/lib/libcrypto/asn1/d2i_dsap.c
+++ b/src/lib/libcrypto/asn1/d2i_dsap.c
@@ -83,7 +83,7 @@ DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)
83 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); 83 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
84 if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn; 84 if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;
85 85
86 ASN1_BIT_STRING_free(bs); 86 M_ASN1_BIT_STRING_free(bs);
87 87
88 M_ASN1_D2I_Finish_2(a); 88 M_ASN1_D2I_Finish_2(a);
89 89
@@ -92,7 +92,7 @@ err_bn:
92err: 92err:
93 ASN1err(ASN1_F_D2I_DSAPARAMS,i); 93 ASN1err(ASN1_F_D2I_DSAPARAMS,i);
94 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); 94 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);
95 if (bs != NULL) ASN1_BIT_STRING_free(bs); 95 if (bs != NULL) M_ASN1_BIT_STRING_free(bs);
96 return(NULL); 96 return(NULL);
97 } 97 }
98#endif 98#endif
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c
index f3d1aa6240..c92b8325d8 100644
--- a/src/lib/libcrypto/asn1/d2i_pr.c
+++ b/src/lib/libcrypto/asn1/d2i_pr.c
@@ -112,3 +112,26 @@ err:
112 return(NULL); 112 return(NULL);
113 } 113 }
114 114
115/* This works like d2i_PrivateKey() except it automatically works out the type */
116
117EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
118 long length)
119{
120 STACK_OF(ASN1_TYPE) *inkey;
121 unsigned char *p;
122 int keytype;
123 p = *pp;
124 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
125 * by analyzing it we can determine the passed structure: this
126 * assumes the input is surrounded by an ASN1 SEQUENCE.
127 */
128 inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE,
129 ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
130 /* Since we only need to discern "traditional format" RSA and DSA
131 * keys we can just count the elements.
132 */
133 if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA;
134 else keytype = EVP_PKEY_RSA;
135 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
136 return d2i_PrivateKey(keytype, a, pp, length);
137}
diff --git a/src/lib/libcrypto/asn1/d2i_r_pr.c b/src/lib/libcrypto/asn1/d2i_r_pr.c
index 18f11b6f5e..6c8a45f821 100644
--- a/src/lib/libcrypto/asn1/d2i_r_pr.c
+++ b/src/lib/libcrypto/asn1/d2i_r_pr.c
@@ -107,7 +107,7 @@ RSA *d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length)
107 if ((ret->iqmp=BN_bin2bn(bs->data,bs->length,ret->iqmp)) == NULL) 107 if ((ret->iqmp=BN_bin2bn(bs->data,bs->length,ret->iqmp)) == NULL)
108 goto err_bn; 108 goto err_bn;
109 109
110 ASN1_INTEGER_free(bs); 110 M_ASN1_INTEGER_free(bs);
111 111
112 M_ASN1_D2I_Finish_2(a); 112 M_ASN1_D2I_Finish_2(a);
113err_bn: 113err_bn:
@@ -115,7 +115,14 @@ err_bn:
115err: 115err:
116 ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,i); 116 ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,i);
117 if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret); 117 if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret);
118 if (bs != NULL) ASN1_INTEGER_free(bs); 118 if (bs != NULL) M_ASN1_INTEGER_free(bs);
119
119 return(NULL); 120 return(NULL);
120 } 121 }
122#else /* !NO_RSA */
123
124# if PEDANTIC
125static void *dummy=&dummy;
126# endif
127
121#endif 128#endif
diff --git a/src/lib/libcrypto/asn1/d2i_r_pu.c b/src/lib/libcrypto/asn1/d2i_r_pu.c
index c4ae58b594..d1289f160e 100644
--- a/src/lib/libcrypto/asn1/d2i_r_pu.c
+++ b/src/lib/libcrypto/asn1/d2i_r_pu.c
@@ -81,7 +81,7 @@ RSA *d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length)
81 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); 81 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
82 if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn; 82 if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn;
83 83
84 ASN1_INTEGER_free(bs); 84 M_ASN1_INTEGER_free(bs);
85 bs=NULL; 85 bs=NULL;
86 86
87 M_ASN1_D2I_Finish_2(a); 87 M_ASN1_D2I_Finish_2(a);
@@ -91,7 +91,13 @@ err_bn:
91err: 91err:
92 ASN1err(ASN1_F_D2I_RSAPUBLICKEY,i); 92 ASN1err(ASN1_F_D2I_RSAPUBLICKEY,i);
93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret); 93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret);
94 if (bs != NULL) ASN1_INTEGER_free(bs); 94 if (bs != NULL) M_ASN1_INTEGER_free(bs);
95 return(NULL); 95 return(NULL);
96 } 96 }
97#else /* !NO_RSA */
98
99# if PEDANTIC
100static void *dummy=&dummy;
101# endif
102
97#endif 103#endif
diff --git a/src/lib/libcrypto/asn1/d2i_s_pr.c b/src/lib/libcrypto/asn1/d2i_s_pr.c
index 050e1cc5fb..dec2a2ebd3 100644
--- a/src/lib/libcrypto/asn1/d2i_s_pr.c
+++ b/src/lib/libcrypto/asn1/d2i_s_pr.c
@@ -91,7 +91,7 @@ DSA *d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length)
91 if ((ret->priv_key=BN_bin2bn(bs->data,bs->length,ret->priv_key)) 91 if ((ret->priv_key=BN_bin2bn(bs->data,bs->length,ret->priv_key))
92 == NULL) goto err_bn; 92 == NULL) goto err_bn;
93 93
94 ASN1_INTEGER_free(bs); 94 M_ASN1_INTEGER_free(bs);
95 95
96 M_ASN1_D2I_Finish_2(a); 96 M_ASN1_D2I_Finish_2(a);
97err_bn: 97err_bn:
@@ -99,7 +99,7 @@ err_bn:
99err: 99err:
100 ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,i); 100 ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,i);
101 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); 101 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);
102 if (bs != NULL) ASN1_INTEGER_free(bs); 102 if (bs != NULL) M_ASN1_INTEGER_free(bs);
103 return(NULL); 103 return(NULL);
104 } 104 }
105#endif 105#endif
diff --git a/src/lib/libcrypto/asn1/d2i_s_pu.c b/src/lib/libcrypto/asn1/d2i_s_pu.c
index 94ea1c313b..e0adaa0393 100644
--- a/src/lib/libcrypto/asn1/d2i_s_pu.c
+++ b/src/lib/libcrypto/asn1/d2i_s_pu.c
@@ -107,7 +107,7 @@ DSA *d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length)
107 ret->write_params=1; 107 ret->write_params=1;
108 } 108 }
109 109
110 ASN1_INTEGER_free(bs); 110 M_ASN1_INTEGER_free(bs);
111 bs=NULL; 111 bs=NULL;
112 M_ASN1_D2I_Finish_2(a); 112 M_ASN1_D2I_Finish_2(a);
113err_bn: 113err_bn:
@@ -115,7 +115,7 @@ err_bn:
115err: 115err:
116 ASN1err(ASN1_F_D2I_DSAPUBLICKEY,i); 116 ASN1err(ASN1_F_D2I_DSAPUBLICKEY,i);
117 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); 117 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);
118 if (bs != NULL) ASN1_INTEGER_free(bs); 118 if (bs != NULL) M_ASN1_INTEGER_free(bs);
119 return(NULL); 119 return(NULL);
120 } 120 }
121#endif 121#endif
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
index 41ced49c19..3506005a71 100644
--- a/src/lib/libcrypto/asn1/evp_asn1.c
+++ b/src/lib/libcrypto/asn1/evp_asn1.c
@@ -65,8 +65,8 @@ int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
65 { 65 {
66 ASN1_STRING *os; 66 ASN1_STRING *os;
67 67
68 if ((os=ASN1_OCTET_STRING_new()) == NULL) return(0); 68 if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0);
69 if (!ASN1_OCTET_STRING_set(os,data,len)) return(0); 69 if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0);
70 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); 70 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os);
71 return(1); 71 return(1);
72 } 72 }
@@ -83,8 +83,8 @@ int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data,
83 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); 83 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
84 return(-1); 84 return(-1);
85 } 85 }
86 p=ASN1_STRING_data(a->value.octet_string); 86 p=M_ASN1_STRING_data(a->value.octet_string);
87 ret=ASN1_STRING_length(a->value.octet_string); 87 ret=M_ASN1_STRING_length(a->value.octet_string);
88 if (ret < max_len) 88 if (ret < max_len)
89 num=ret; 89 num=ret;
90 else 90 else
@@ -117,8 +117,8 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
117 /* Grow the 'string' */ 117 /* Grow the 'string' */
118 ASN1_STRING_set(osp,NULL,size); 118 ASN1_STRING_set(osp,NULL,size);
119 119
120 ASN1_STRING_length(osp)=size; 120 M_ASN1_STRING_length_set(osp, size);
121 p=ASN1_STRING_data(osp); 121 p=M_ASN1_STRING_data(osp);
122 122
123 ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); 123 ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
124 i2d_ASN1_INTEGER(&in,&p); 124 i2d_ASN1_INTEGER(&in,&p);
@@ -145,8 +145,8 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
145 { 145 {
146 goto err; 146 goto err;
147 } 147 }
148 p=ASN1_STRING_data(a->value.sequence); 148 p=M_ASN1_STRING_data(a->value.sequence);
149 length=ASN1_STRING_length(a->value.sequence); 149 length=M_ASN1_STRING_length(a->value.sequence);
150 150
151 c.pp= &p; 151 c.pp= &p;
152 c.p=p; 152 c.p=p;
@@ -165,21 +165,21 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
165 if (num != NULL) 165 if (num != NULL)
166 *num=ASN1_INTEGER_get(ai); 166 *num=ASN1_INTEGER_get(ai);
167 167
168 ret=ASN1_STRING_length(os); 168 ret=M_ASN1_STRING_length(os);
169 if (max_len > ret) 169 if (max_len > ret)
170 n=ret; 170 n=ret;
171 else 171 else
172 n=max_len; 172 n=max_len;
173 173
174 if (data != NULL) 174 if (data != NULL)
175 memcpy(data,ASN1_STRING_data(os),n); 175 memcpy(data,M_ASN1_STRING_data(os),n);
176 if (0) 176 if (0)
177 { 177 {
178err: 178err:
179 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); 179 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
180 } 180 }
181 if (os != NULL) ASN1_OCTET_STRING_free(os); 181 if (os != NULL) M_ASN1_OCTET_STRING_free(os);
182 if (ai != NULL) ASN1_INTEGER_free(ai); 182 if (ai != NULL) M_ASN1_INTEGER_free(ai);
183 return(ret); 183 return(ret);
184 } 184 }
185 185
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c
index 3bcceecdb8..3d0b1107cb 100644
--- a/src/lib/libcrypto/asn1/f_enum.c
+++ b/src/lib/libcrypto/asn1/f_enum.c
@@ -161,7 +161,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
161 if (sp == NULL) 161 if (sp == NULL)
162 { 162 {
163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); 163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
164 if (s != NULL) Free((char *)s); 164 if (s != NULL) Free(s);
165 goto err; 165 goto err;
166 } 166 }
167 s=sp; 167 s=sp;
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c
index 55560dd814..cd57331c3f 100644
--- a/src/lib/libcrypto/asn1/f_int.c
+++ b/src/lib/libcrypto/asn1/f_int.c
@@ -168,7 +168,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
168 if (sp == NULL) 168 if (sp == NULL)
169 { 169 {
170 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); 170 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
171 if (s != NULL) Free((char *)s); 171 if (s != NULL) Free(s);
172 goto err; 172 goto err;
173 } 173 }
174 s=sp; 174 s=sp;
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
index 5d0cf5a46d..088313689a 100644
--- a/src/lib/libcrypto/asn1/f_string.c
+++ b/src/lib/libcrypto/asn1/f_string.c
@@ -166,7 +166,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
166 if (sp == NULL) 166 if (sp == NULL)
167 { 167 {
168 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); 168 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
169 if (s != NULL) Free((char *)s); 169 if (s != NULL) Free(s);
170 goto err; 170 goto err;
171 } 171 }
172 s=sp; 172 s=sp;
diff --git a/src/lib/libcrypto/asn1/i2d_dhp.c b/src/lib/libcrypto/asn1/i2d_dhp.c
index fdda4ec41b..61eeb646f9 100644
--- a/src/lib/libcrypto/asn1/i2d_dhp.c
+++ b/src/lib/libcrypto/asn1/i2d_dhp.c
@@ -118,7 +118,7 @@ int i2d_DHparams(DH *a, unsigned char **pp)
118 bs.length=BN_bn2bin(num[i],bs.data); 118 bs.length=BN_bn2bin(num[i],bs.data);
119 i2d_ASN1_INTEGER(&bs,&p); 119 i2d_ASN1_INTEGER(&bs,&p);
120 } 120 }
121 Free((char *)bs.data); 121 Free(bs.data);
122 ret=t; 122 ret=t;
123err: 123err:
124 if (num[2] != NULL) BN_free(num[2]); 124 if (num[2] != NULL) BN_free(num[2]);
diff --git a/src/lib/libcrypto/asn1/i2d_dsap.c b/src/lib/libcrypto/asn1/i2d_dsap.c
index f36f0da4e2..4021123ba3 100644
--- a/src/lib/libcrypto/asn1/i2d_dsap.c
+++ b/src/lib/libcrypto/asn1/i2d_dsap.c
@@ -107,7 +107,7 @@ int i2d_DSAparams(DSA *a, unsigned char **pp)
107 bs.length=BN_bn2bin(num[i],bs.data); 107 bs.length=BN_bn2bin(num[i],bs.data);
108 i2d_ASN1_INTEGER(&bs,&p); 108 i2d_ASN1_INTEGER(&bs,&p);
109 } 109 }
110 Free((char *)bs.data); 110 Free(bs.data);
111 ret=t; 111 ret=t;
112err: 112err:
113 *pp=p; 113 *pp=p;
diff --git a/src/lib/libcrypto/asn1/i2d_r_pr.c b/src/lib/libcrypto/asn1/i2d_r_pr.c
index 27e6844a7f..1250fa4b2d 100644
--- a/src/lib/libcrypto/asn1/i2d_r_pr.c
+++ b/src/lib/libcrypto/asn1/i2d_r_pr.c
@@ -119,9 +119,15 @@ int i2d_RSAPrivateKey(RSA *a, unsigned char **pp)
119 bs.length=BN_bn2bin(num[i],bs.data); 119 bs.length=BN_bn2bin(num[i],bs.data);
120 i2d_ASN1_INTEGER(&bs,&p); 120 i2d_ASN1_INTEGER(&bs,&p);
121 } 121 }
122 Free((char *)bs.data); 122 Free(bs.data);
123 *pp=p; 123 *pp=p;
124 return(t); 124 return(t);
125 } 125 }
126#else /* !NO_RSA */
127
128# if PEDANTIC
129static void *dummy=&dummy;
130# endif
131
126#endif 132#endif
127 133
diff --git a/src/lib/libcrypto/asn1/i2d_r_pu.c b/src/lib/libcrypto/asn1/i2d_r_pu.c
index 6d01bfa8b5..582b92ee4c 100644
--- a/src/lib/libcrypto/asn1/i2d_r_pu.c
+++ b/src/lib/libcrypto/asn1/i2d_r_pu.c
@@ -105,8 +105,14 @@ int i2d_RSAPublicKey(RSA *a, unsigned char **pp)
105 bs.length=BN_bn2bin(num[i],bs.data); 105 bs.length=BN_bn2bin(num[i],bs.data);
106 i2d_ASN1_INTEGER(&bs,&p); 106 i2d_ASN1_INTEGER(&bs,&p);
107 } 107 }
108 Free((char *)bs.data); 108 Free(bs.data);
109 *pp=p; 109 *pp=p;
110 return(t); 110 return(t);
111 } 111 }
112#else /* !NO_RSA */
113
114# if PEDANTIC
115static void *dummy=&dummy;
116# endif
117
112#endif 118#endif
diff --git a/src/lib/libcrypto/asn1/i2d_s_pr.c b/src/lib/libcrypto/asn1/i2d_s_pr.c
index 5d3dcdf197..e399ceaeb9 100644
--- a/src/lib/libcrypto/asn1/i2d_s_pr.c
+++ b/src/lib/libcrypto/asn1/i2d_s_pr.c
@@ -116,7 +116,7 @@ int i2d_DSAPrivateKey(DSA *a, unsigned char **pp)
116 bs.length=BN_bn2bin(num[i],bs.data); 116 bs.length=BN_bn2bin(num[i],bs.data);
117 i2d_ASN1_INTEGER(&bs,&p); 117 i2d_ASN1_INTEGER(&bs,&p);
118 } 118 }
119 Free((char *)bs.data); 119 Free(bs.data);
120 *pp=p; 120 *pp=p;
121 return(t); 121 return(t);
122 } 122 }
diff --git a/src/lib/libcrypto/asn1/i2d_s_pu.c b/src/lib/libcrypto/asn1/i2d_s_pu.c
index 18f790f746..ca7f251b71 100644
--- a/src/lib/libcrypto/asn1/i2d_s_pu.c
+++ b/src/lib/libcrypto/asn1/i2d_s_pu.c
@@ -121,7 +121,7 @@ int i2d_DSAPublicKey(DSA *a, unsigned char **pp)
121 bs.length=BN_bn2bin(num[i],bs.data); 121 bs.length=BN_bn2bin(num[i],bs.data);
122 i2d_ASN1_INTEGER(&bs,&p); 122 i2d_ASN1_INTEGER(&bs,&p);
123 } 123 }
124 Free((char *)bs.data); 124 Free(bs.data);
125 *pp=p; 125 *pp=p;
126 if(all) return(t); 126 if(all) return(t);
127 else return(tot); 127 else return(tot);
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
index cdc0d8b7c4..d804986b73 100644
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -139,7 +139,7 @@ int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)())
139 } 139 }
140 140
141 if (pkey->private_key->data != NULL) 141 if (pkey->private_key->data != NULL)
142 Free((char *)pkey->private_key->data); 142 Free(pkey->private_key->data);
143 if ((pkey->private_key->data=(unsigned char *)Malloc(l[0])) == NULL) 143 if ((pkey->private_key->data=(unsigned char *)Malloc(l[0])) == NULL)
144 { 144 {
145 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); 145 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
@@ -205,10 +205,10 @@ RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)())
205 (char *)os->data,os->length) != 0)) 205 (char *)os->data,os->length) != 0))
206 { 206 {
207 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING); 207 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
208 ASN1_BIT_STRING_free(os); 208 M_ASN1_BIT_STRING_free(os);
209 goto err; 209 goto err;
210 } 210 }
211 ASN1_BIT_STRING_free(os); 211 M_ASN1_BIT_STRING_free(os);
212 c.q=c.p; 212 c.q=c.p;
213 if ((ret=d2i_Netscape_RSA_2(a,&c.p,c.slen,cb)) == NULL) goto err; 213 if ((ret=d2i_Netscape_RSA_2(a,&c.p,c.slen,cb)) == NULL) goto err;
214 c.slen-=(c.p-c.q); 214 c.slen-=(c.p-c.q);
@@ -279,7 +279,7 @@ RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length,
279 *pp=c.p; 279 *pp=c.p;
280err: 280err:
281 if (pkey != NULL) NETSCAPE_PKEY_free(pkey); 281 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
282 if (os != NULL) ASN1_BIT_STRING_free(os); 282 if (os != NULL) M_ASN1_BIT_STRING_free(os);
283 if (alg != NULL) X509_ALGOR_free(alg); 283 if (alg != NULL) X509_ALGOR_free(alg);
284 return(ret); 284 return(ret);
285 } 285 }
@@ -321,9 +321,9 @@ static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void)
321 ASN1_CTX c; 321 ASN1_CTX c;
322 322
323 M_ASN1_New_Malloc(ret,NETSCAPE_PKEY); 323 M_ASN1_New_Malloc(ret,NETSCAPE_PKEY);
324 M_ASN1_New(ret->version,ASN1_INTEGER_new); 324 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
325 M_ASN1_New(ret->algor,X509_ALGOR_new); 325 M_ASN1_New(ret->algor,X509_ALGOR_new);
326 M_ASN1_New(ret->private_key,ASN1_OCTET_STRING_new); 326 M_ASN1_New(ret->private_key,M_ASN1_OCTET_STRING_new);
327 return(ret); 327 return(ret);
328 M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW); 328 M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW);
329 } 329 }
@@ -331,11 +331,18 @@ static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void)
331static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a) 331static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a)
332 { 332 {
333 if (a == NULL) return; 333 if (a == NULL) return;
334 ASN1_INTEGER_free(a->version); 334 M_ASN1_INTEGER_free(a->version);
335 X509_ALGOR_free(a->algor); 335 X509_ALGOR_free(a->algor);
336 ASN1_OCTET_STRING_free(a->private_key); 336 M_ASN1_OCTET_STRING_free(a->private_key);
337 Free((char *)a); 337 Free(a);
338 } 338 }
339 339
340#endif /* NO_RC4 */ 340#endif /* NO_RC4 */
341
342#else /* !NO_RSA */
343
344# if PEDANTIC
345static void *dummy=&dummy;
346# endif
347
341#endif 348#endif
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
index b831836e7b..64e90237cc 100644
--- a/src/lib/libcrypto/asn1/p5_pbe.c
+++ b/src/lib/libcrypto/asn1/p5_pbe.c
@@ -82,8 +82,8 @@ PBEPARAM *PBEPARAM_new(void)
82 PBEPARAM *ret=NULL; 82 PBEPARAM *ret=NULL;
83 ASN1_CTX c; 83 ASN1_CTX c;
84 M_ASN1_New_Malloc(ret, PBEPARAM); 84 M_ASN1_New_Malloc(ret, PBEPARAM);
85 M_ASN1_New(ret->iter,ASN1_INTEGER_new); 85 M_ASN1_New(ret->iter,M_ASN1_INTEGER_new);
86 M_ASN1_New(ret->salt,ASN1_OCTET_STRING_new); 86 M_ASN1_New(ret->salt,M_ASN1_OCTET_STRING_new);
87 return (ret); 87 return (ret);
88 M_ASN1_New_Error(ASN1_F_PBEPARAM_NEW); 88 M_ASN1_New_Error(ASN1_F_PBEPARAM_NEW);
89} 89}
@@ -101,9 +101,9 @@ PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length)
101void PBEPARAM_free (PBEPARAM *a) 101void PBEPARAM_free (PBEPARAM *a)
102{ 102{
103 if(a==NULL) return; 103 if(a==NULL) return;
104 ASN1_OCTET_STRING_free(a->salt); 104 M_ASN1_OCTET_STRING_free(a->salt);
105 ASN1_INTEGER_free (a->iter); 105 M_ASN1_INTEGER_free (a->iter);
106 Free ((char *)a); 106 Free (a);
107} 107}
108 108
109/* Return an algorithm identifier for a PKCS#5 PBE algorithm */ 109/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
@@ -129,7 +129,8 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
129 } 129 }
130 pbe->salt->length = saltlen; 130 pbe->salt->length = saltlen;
131 if (salt) memcpy (pbe->salt->data, salt, saltlen); 131 if (salt) memcpy (pbe->salt->data, salt, saltlen);
132 else RAND_bytes (pbe->salt->data, saltlen); 132 else if (RAND_bytes (pbe->salt->data, saltlen) <= 0)
133 return NULL;
133 134
134 if (!(astype = ASN1_TYPE_new())) { 135 if (!(astype = ASN1_TYPE_new())) {
135 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); 136 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
index 09f4bf6112..4ce06a94ab 100644
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ b/src/lib/libcrypto/asn1/p5_pbev2.c
@@ -104,7 +104,7 @@ void PBE2PARAM_free (PBE2PARAM *a)
104 if(a==NULL) return; 104 if(a==NULL) return;
105 X509_ALGOR_free(a->keyfunc); 105 X509_ALGOR_free(a->keyfunc);
106 X509_ALGOR_free(a->encryption); 106 X509_ALGOR_free(a->encryption);
107 Free ((char *)a); 107 Free (a);
108} 108}
109 109
110int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp) 110int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp)
@@ -131,7 +131,7 @@ PBKDF2PARAM *PBKDF2PARAM_new(void)
131 ASN1_CTX c; 131 ASN1_CTX c;
132 M_ASN1_New_Malloc(ret, PBKDF2PARAM); 132 M_ASN1_New_Malloc(ret, PBKDF2PARAM);
133 M_ASN1_New(ret->salt, ASN1_TYPE_new); 133 M_ASN1_New(ret->salt, ASN1_TYPE_new);
134 M_ASN1_New(ret->iter, ASN1_INTEGER_new); 134 M_ASN1_New(ret->iter, M_ASN1_INTEGER_new);
135 ret->keylength = NULL; 135 ret->keylength = NULL;
136 ret->prf = NULL; 136 ret->prf = NULL;
137 return (ret); 137 return (ret);
@@ -155,10 +155,10 @@ void PBKDF2PARAM_free (PBKDF2PARAM *a)
155{ 155{
156 if(a==NULL) return; 156 if(a==NULL) return;
157 ASN1_TYPE_free(a->salt); 157 ASN1_TYPE_free(a->salt);
158 ASN1_INTEGER_free(a->iter); 158 M_ASN1_INTEGER_free(a->iter);
159 ASN1_INTEGER_free(a->keylength); 159 M_ASN1_INTEGER_free(a->keylength);
160 X509_ALGOR_free(a->prf); 160 X509_ALGOR_free(a->prf);
161 Free ((char *)a); 161 Free (a);
162} 162}
163 163
164/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm: 164/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
@@ -175,19 +175,26 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
175 PBKDF2PARAM *kdf = NULL; 175 PBKDF2PARAM *kdf = NULL;
176 PBE2PARAM *pbe2 = NULL; 176 PBE2PARAM *pbe2 = NULL;
177 ASN1_OCTET_STRING *osalt = NULL; 177 ASN1_OCTET_STRING *osalt = NULL;
178 ASN1_OBJECT *obj;
179
180 alg_nid = EVP_CIPHER_type(cipher);
181 if(alg_nid == NID_undef) {
182 ASN1err(ASN1_F_PKCS5_PBE2_SET,
183 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
184 goto err;
185 }
186 obj = OBJ_nid2obj(alg_nid);
178 187
179 if(!(pbe2 = PBE2PARAM_new())) goto merr; 188 if(!(pbe2 = PBE2PARAM_new())) goto merr;
180 189
181 /* Setup the AlgorithmIdentifier for the encryption scheme */ 190 /* Setup the AlgorithmIdentifier for the encryption scheme */
182 scheme = pbe2->encryption; 191 scheme = pbe2->encryption;
183 192
184 alg_nid = EVP_CIPHER_type(cipher); 193 scheme->algorithm = obj;
185
186 scheme->algorithm = OBJ_nid2obj(alg_nid);
187 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr; 194 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
188 195
189 /* Create random IV */ 196 /* Create random IV */
190 RAND_bytes(iv, EVP_CIPHER_iv_length(cipher)); 197 RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher));
191 198
192 /* Dummy cipherinit to just setup the IV */ 199 /* Dummy cipherinit to just setup the IV */
193 EVP_CipherInit(&ctx, cipher, NULL, iv, 0); 200 EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
@@ -199,13 +206,13 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
199 EVP_CIPHER_CTX_cleanup(&ctx); 206 EVP_CIPHER_CTX_cleanup(&ctx);
200 207
201 if(!(kdf = PBKDF2PARAM_new())) goto merr; 208 if(!(kdf = PBKDF2PARAM_new())) goto merr;
202 if(!(osalt = ASN1_OCTET_STRING_new())) goto merr; 209 if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr;
203 210
204 if (!saltlen) saltlen = PKCS5_SALT_LEN; 211 if (!saltlen) saltlen = PKCS5_SALT_LEN;
205 if (!(osalt->data = Malloc (saltlen))) goto merr; 212 if (!(osalt->data = Malloc (saltlen))) goto merr;
206 osalt->length = saltlen; 213 osalt->length = saltlen;
207 if (salt) memcpy (osalt->data, salt, saltlen); 214 if (salt) memcpy (osalt->data, salt, saltlen);
208 else RAND_bytes (osalt->data, saltlen); 215 else if (RAND_bytes (osalt->data, saltlen) <= 0) goto merr;
209 216
210 if(iter <= 0) iter = PKCS5_DEFAULT_ITER; 217 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
211 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr; 218 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
@@ -218,7 +225,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
218 /* If its RC2 then we'd better setup the key length */ 225 /* If its RC2 then we'd better setup the key length */
219 226
220 if(alg_nid == NID_rc2_cbc) { 227 if(alg_nid == NID_rc2_cbc) {
221 if(!(kdf->keylength = ASN1_INTEGER_new())) goto merr; 228 if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr;
222 if(!ASN1_INTEGER_set (kdf->keylength, 229 if(!ASN1_INTEGER_set (kdf->keylength,
223 EVP_CIPHER_key_length(cipher))) goto merr; 230 EVP_CIPHER_key_length(cipher))) goto merr;
224 } 231 }
@@ -264,7 +271,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
264 err: 271 err:
265 PBE2PARAM_free(pbe2); 272 PBE2PARAM_free(pbe2);
266 /* Note 'scheme' is freed as part of pbe2 */ 273 /* Note 'scheme' is freed as part of pbe2 */
267 ASN1_OCTET_STRING_free(osalt); 274 M_ASN1_OCTET_STRING_free(osalt);
268 PBKDF2PARAM_free(kdf); 275 PBKDF2PARAM_free(kdf);
269 X509_ALGOR_free(kalg); 276 X509_ALGOR_free(kalg);
270 X509_ALGOR_free(ret); 277 X509_ALGOR_free(ret);
diff --git a/src/lib/libcrypto/asn1/p7_dgst.c b/src/lib/libcrypto/asn1/p7_dgst.c
index 62783a2b8d..cba90e94a1 100644
--- a/src/lib/libcrypto/asn1/p7_dgst.c
+++ b/src/lib/libcrypto/asn1/p7_dgst.c
@@ -101,10 +101,10 @@ PKCS7_DIGEST *PKCS7_DIGEST_new(void)
101 ASN1_CTX c; 101 ASN1_CTX c;
102 102
103 M_ASN1_New_Malloc(ret,PKCS7_DIGEST); 103 M_ASN1_New_Malloc(ret,PKCS7_DIGEST);
104 M_ASN1_New(ret->version,ASN1_INTEGER_new); 104 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
105 M_ASN1_New(ret->md,X509_ALGOR_new); 105 M_ASN1_New(ret->md,X509_ALGOR_new);
106 M_ASN1_New(ret->contents,PKCS7_new); 106 M_ASN1_New(ret->contents,PKCS7_new);
107 M_ASN1_New(ret->digest,ASN1_OCTET_STRING_new); 107 M_ASN1_New(ret->digest,M_ASN1_OCTET_STRING_new);
108 return(ret); 108 return(ret);
109 M_ASN1_New_Error(ASN1_F_PKCS7_DIGEST_NEW); 109 M_ASN1_New_Error(ASN1_F_PKCS7_DIGEST_NEW);
110 } 110 }
@@ -112,10 +112,10 @@ PKCS7_DIGEST *PKCS7_DIGEST_new(void)
112void PKCS7_DIGEST_free(PKCS7_DIGEST *a) 112void PKCS7_DIGEST_free(PKCS7_DIGEST *a)
113 { 113 {
114 if (a == NULL) return; 114 if (a == NULL) return;
115 ASN1_INTEGER_free(a->version); 115 M_ASN1_INTEGER_free(a->version);
116 X509_ALGOR_free(a->md); 116 X509_ALGOR_free(a->md);
117 PKCS7_free(a->contents); 117 PKCS7_free(a->contents);
118 ASN1_OCTET_STRING_free(a->digest); 118 M_ASN1_OCTET_STRING_free(a->digest);
119 Free((char *)a); 119 Free(a);
120 } 120 }
121 121
diff --git a/src/lib/libcrypto/asn1/p7_enc.c b/src/lib/libcrypto/asn1/p7_enc.c
index 4741126587..83b0e15faa 100644
--- a/src/lib/libcrypto/asn1/p7_enc.c
+++ b/src/lib/libcrypto/asn1/p7_enc.c
@@ -95,7 +95,7 @@ PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void)
95 ASN1_CTX c; 95 ASN1_CTX c;
96 96
97 M_ASN1_New_Malloc(ret,PKCS7_ENCRYPT); 97 M_ASN1_New_Malloc(ret,PKCS7_ENCRYPT);
98 M_ASN1_New(ret->version,ASN1_INTEGER_new); 98 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
99 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); 99 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new);
100 return(ret); 100 return(ret);
101 M_ASN1_New_Error(ASN1_F_PKCS7_ENCRYPT_NEW); 101 M_ASN1_New_Error(ASN1_F_PKCS7_ENCRYPT_NEW);
@@ -104,8 +104,8 @@ PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void)
104void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a) 104void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a)
105 { 105 {
106 if (a == NULL) return; 106 if (a == NULL) return;
107 ASN1_INTEGER_free(a->version); 107 M_ASN1_INTEGER_free(a->version);
108 PKCS7_ENC_CONTENT_free(a->enc_data); 108 PKCS7_ENC_CONTENT_free(a->enc_data);
109 Free((char *)a); 109 Free(a);
110 } 110 }
111 111
diff --git a/src/lib/libcrypto/asn1/p7_enc_c.c b/src/lib/libcrypto/asn1/p7_enc_c.c
index a832737a38..582cc78b06 100644
--- a/src/lib/libcrypto/asn1/p7_enc_c.c
+++ b/src/lib/libcrypto/asn1/p7_enc_c.c
@@ -101,7 +101,8 @@ PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(void)
101 101
102 M_ASN1_New_Malloc(ret,PKCS7_ENC_CONTENT); 102 M_ASN1_New_Malloc(ret,PKCS7_ENC_CONTENT);
103 /* M_ASN1_New(ret->content_type,ASN1_OBJECT_new); */ 103 /* M_ASN1_New(ret->content_type,ASN1_OBJECT_new); */
104 ret->content_type=OBJ_nid2obj(NID_pkcs7_encrypted); 104 /* We will almost always want this: so make it the default */
105 ret->content_type=OBJ_nid2obj(NID_pkcs7_data);
105 M_ASN1_New(ret->algorithm,X509_ALGOR_new); 106 M_ASN1_New(ret->algorithm,X509_ALGOR_new);
106 ret->enc_data=NULL; 107 ret->enc_data=NULL;
107 return(ret); 108 return(ret);
@@ -113,7 +114,7 @@ void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a)
113 if (a == NULL) return; 114 if (a == NULL) return;
114 ASN1_OBJECT_free(a->content_type); 115 ASN1_OBJECT_free(a->content_type);
115 X509_ALGOR_free(a->algorithm); 116 X509_ALGOR_free(a->algorithm);
116 ASN1_OCTET_STRING_free(a->enc_data); 117 M_ASN1_OCTET_STRING_free(a->enc_data);
117 Free((char *)a); 118 Free(a);
118 } 119 }
119 120
diff --git a/src/lib/libcrypto/asn1/p7_evp.c b/src/lib/libcrypto/asn1/p7_evp.c
index b2b3d50dcd..4e734fdd28 100644
--- a/src/lib/libcrypto/asn1/p7_evp.c
+++ b/src/lib/libcrypto/asn1/p7_evp.c
@@ -101,7 +101,7 @@ PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void)
101 ASN1_CTX c; 101 ASN1_CTX c;
102 102
103 M_ASN1_New_Malloc(ret,PKCS7_ENVELOPE); 103 M_ASN1_New_Malloc(ret,PKCS7_ENVELOPE);
104 M_ASN1_New(ret->version,ASN1_INTEGER_new); 104 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
105 M_ASN1_New(ret->recipientinfo,sk_PKCS7_RECIP_INFO_new_null); 105 M_ASN1_New(ret->recipientinfo,sk_PKCS7_RECIP_INFO_new_null);
106 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); 106 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new);
107 return(ret); 107 return(ret);
@@ -111,9 +111,9 @@ PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void)
111void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a) 111void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a)
112 { 112 {
113 if (a == NULL) return; 113 if (a == NULL) return;
114 ASN1_INTEGER_free(a->version); 114 M_ASN1_INTEGER_free(a->version);
115 sk_PKCS7_RECIP_INFO_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); 115 sk_PKCS7_RECIP_INFO_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free);
116 PKCS7_ENC_CONTENT_free(a->enc_data); 116 PKCS7_ENC_CONTENT_free(a->enc_data);
117 Free((char *)a); 117 Free(a);
118 } 118 }
119 119
diff --git a/src/lib/libcrypto/asn1/p7_i_s.c b/src/lib/libcrypto/asn1/p7_i_s.c
index 7d4b457e01..d21f7ddb84 100644
--- a/src/lib/libcrypto/asn1/p7_i_s.c
+++ b/src/lib/libcrypto/asn1/p7_i_s.c
@@ -96,7 +96,7 @@ PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void)
96 96
97 M_ASN1_New_Malloc(ret,PKCS7_ISSUER_AND_SERIAL); 97 M_ASN1_New_Malloc(ret,PKCS7_ISSUER_AND_SERIAL);
98 M_ASN1_New(ret->issuer,X509_NAME_new); 98 M_ASN1_New(ret->issuer,X509_NAME_new);
99 M_ASN1_New(ret->serial,ASN1_INTEGER_new); 99 M_ASN1_New(ret->serial,M_ASN1_INTEGER_new);
100 return(ret); 100 return(ret);
101 M_ASN1_New_Error(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW); 101 M_ASN1_New_Error(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW);
102 } 102 }
@@ -105,7 +105,7 @@ void PKCS7_ISSUER_AND_SERIAL_free(PKCS7_ISSUER_AND_SERIAL *a)
105 { 105 {
106 if (a == NULL) return; 106 if (a == NULL) return;
107 X509_NAME_free(a->issuer); 107 X509_NAME_free(a->issuer);
108 ASN1_INTEGER_free(a->serial); 108 M_ASN1_INTEGER_free(a->serial);
109 Free((char *)a); 109 Free(a);
110 } 110 }
111 111
diff --git a/src/lib/libcrypto/asn1/p7_lib.c b/src/lib/libcrypto/asn1/p7_lib.c
index 846be17158..86db82cfa1 100644
--- a/src/lib/libcrypto/asn1/p7_lib.c
+++ b/src/lib/libcrypto/asn1/p7_lib.c
@@ -152,7 +152,7 @@ PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length)
152 { 152 {
153 if ((*a)->asn1 != NULL) 153 if ((*a)->asn1 != NULL)
154 { 154 {
155 Free((char *)(*a)->asn1); 155 Free((*a)->asn1);
156 (*a)->asn1=NULL; 156 (*a)->asn1=NULL;
157 } 157 }
158 (*a)->length=0; 158 (*a)->length=0;
@@ -251,7 +251,7 @@ void PKCS7_free(PKCS7 *a)
251 { 251 {
252 ASN1_OBJECT_free(a->type); 252 ASN1_OBJECT_free(a->type);
253 } 253 }
254 Free((char *)(char *)a); 254 Free(a);
255 } 255 }
256 256
257void PKCS7_content_free(PKCS7 *a) 257void PKCS7_content_free(PKCS7 *a)
@@ -259,7 +259,7 @@ void PKCS7_content_free(PKCS7 *a)
259 if(a == NULL) 259 if(a == NULL)
260 return; 260 return;
261 261
262 if (a->asn1 != NULL) Free((char *)a->asn1); 262 if (a->asn1 != NULL) Free(a->asn1);
263 263
264 if (a->d.ptr != NULL) 264 if (a->d.ptr != NULL)
265 { 265 {
@@ -268,7 +268,7 @@ void PKCS7_content_free(PKCS7 *a)
268 switch (OBJ_obj2nid(a->type)) 268 switch (OBJ_obj2nid(a->type))
269 { 269 {
270 case NID_pkcs7_data: 270 case NID_pkcs7_data:
271 ASN1_OCTET_STRING_free(a->d.data); 271 M_ASN1_OCTET_STRING_free(a->d.data);
272 break; 272 break;
273 case NID_pkcs7_signed: 273 case NID_pkcs7_signed:
274 PKCS7_SIGNED_free(a->d.sign); 274 PKCS7_SIGNED_free(a->d.sign);
diff --git a/src/lib/libcrypto/asn1/p7_recip.c b/src/lib/libcrypto/asn1/p7_recip.c
index 9fda4f20d4..b1abfa3b8f 100644
--- a/src/lib/libcrypto/asn1/p7_recip.c
+++ b/src/lib/libcrypto/asn1/p7_recip.c
@@ -101,10 +101,10 @@ PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void)
101 ASN1_CTX c; 101 ASN1_CTX c;
102 102
103 M_ASN1_New_Malloc(ret,PKCS7_RECIP_INFO); 103 M_ASN1_New_Malloc(ret,PKCS7_RECIP_INFO);
104 M_ASN1_New(ret->version,ASN1_INTEGER_new); 104 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
105 M_ASN1_New(ret->issuer_and_serial,PKCS7_ISSUER_AND_SERIAL_new); 105 M_ASN1_New(ret->issuer_and_serial,PKCS7_ISSUER_AND_SERIAL_new);
106 M_ASN1_New(ret->key_enc_algor,X509_ALGOR_new); 106 M_ASN1_New(ret->key_enc_algor,X509_ALGOR_new);
107 M_ASN1_New(ret->enc_key,ASN1_OCTET_STRING_new); 107 M_ASN1_New(ret->enc_key,M_ASN1_OCTET_STRING_new);
108 ret->cert=NULL; 108 ret->cert=NULL;
109 return(ret); 109 return(ret);
110 M_ASN1_New_Error(ASN1_F_PKCS7_RECIP_INFO_NEW); 110 M_ASN1_New_Error(ASN1_F_PKCS7_RECIP_INFO_NEW);
@@ -113,10 +113,10 @@ PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void)
113void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a) 113void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a)
114 { 114 {
115 if (a == NULL) return; 115 if (a == NULL) return;
116 ASN1_INTEGER_free(a->version); 116 M_ASN1_INTEGER_free(a->version);
117 PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial); 117 PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial);
118 X509_ALGOR_free(a->key_enc_algor); 118 X509_ALGOR_free(a->key_enc_algor);
119 ASN1_OCTET_STRING_free(a->enc_key); 119 M_ASN1_OCTET_STRING_free(a->enc_key);
120 if (a->cert != NULL) X509_free(a->cert); 120 if (a->cert != NULL) X509_free(a->cert);
121 Free(a); 121 Free(a);
122 } 122 }
diff --git a/src/lib/libcrypto/asn1/p7_s_e.c b/src/lib/libcrypto/asn1/p7_s_e.c
index 90946695c9..3d18fedf8e 100644
--- a/src/lib/libcrypto/asn1/p7_s_e.c
+++ b/src/lib/libcrypto/asn1/p7_s_e.c
@@ -119,7 +119,7 @@ PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void)
119 ASN1_CTX c; 119 ASN1_CTX c;
120 120
121 M_ASN1_New_Malloc(ret,PKCS7_SIGN_ENVELOPE); 121 M_ASN1_New_Malloc(ret,PKCS7_SIGN_ENVELOPE);
122 M_ASN1_New(ret->version,ASN1_INTEGER_new); 122 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
123 M_ASN1_New(ret->recipientinfo,sk_PKCS7_RECIP_INFO_new_null); 123 M_ASN1_New(ret->recipientinfo,sk_PKCS7_RECIP_INFO_new_null);
124 M_ASN1_New(ret->md_algs,sk_X509_ALGOR_new_null); 124 M_ASN1_New(ret->md_algs,sk_X509_ALGOR_new_null);
125 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); 125 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new);
@@ -133,7 +133,7 @@ PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void)
133void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a) 133void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a)
134 { 134 {
135 if (a == NULL) return; 135 if (a == NULL) return;
136 ASN1_INTEGER_free(a->version); 136 M_ASN1_INTEGER_free(a->version);
137 sk_PKCS7_RECIP_INFO_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); 137 sk_PKCS7_RECIP_INFO_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free);
138 sk_X509_ALGOR_pop_free(a->md_algs,X509_ALGOR_free); 138 sk_X509_ALGOR_pop_free(a->md_algs,X509_ALGOR_free);
139 PKCS7_ENC_CONTENT_free(a->enc_data); 139 PKCS7_ENC_CONTENT_free(a->enc_data);
diff --git a/src/lib/libcrypto/asn1/p7_signd.c b/src/lib/libcrypto/asn1/p7_signd.c
index 74f0f522e1..f6f16a8715 100644
--- a/src/lib/libcrypto/asn1/p7_signd.c
+++ b/src/lib/libcrypto/asn1/p7_signd.c
@@ -112,7 +112,7 @@ PKCS7_SIGNED *PKCS7_SIGNED_new(void)
112 ASN1_CTX c; 112 ASN1_CTX c;
113 113
114 M_ASN1_New_Malloc(ret,PKCS7_SIGNED); 114 M_ASN1_New_Malloc(ret,PKCS7_SIGNED);
115 M_ASN1_New(ret->version,ASN1_INTEGER_new); 115 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
116 M_ASN1_New(ret->md_algs,sk_X509_ALGOR_new_null); 116 M_ASN1_New(ret->md_algs,sk_X509_ALGOR_new_null);
117 M_ASN1_New(ret->contents,PKCS7_new); 117 M_ASN1_New(ret->contents,PKCS7_new);
118 ret->cert=NULL; 118 ret->cert=NULL;
@@ -125,7 +125,7 @@ PKCS7_SIGNED *PKCS7_SIGNED_new(void)
125void PKCS7_SIGNED_free(PKCS7_SIGNED *a) 125void PKCS7_SIGNED_free(PKCS7_SIGNED *a)
126 { 126 {
127 if (a == NULL) return; 127 if (a == NULL) return;
128 ASN1_INTEGER_free(a->version); 128 M_ASN1_INTEGER_free(a->version);
129 sk_X509_ALGOR_pop_free(a->md_algs,X509_ALGOR_free); 129 sk_X509_ALGOR_pop_free(a->md_algs,X509_ALGOR_free);
130 PKCS7_free(a->contents); 130 PKCS7_free(a->contents);
131 sk_X509_pop_free(a->cert,X509_free); 131 sk_X509_pop_free(a->cert,X509_free);
diff --git a/src/lib/libcrypto/asn1/p7_signi.c b/src/lib/libcrypto/asn1/p7_signi.c
index 21132ef4dd..f74658ffe6 100644
--- a/src/lib/libcrypto/asn1/p7_signi.c
+++ b/src/lib/libcrypto/asn1/p7_signi.c
@@ -119,12 +119,12 @@ PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void)
119 ASN1_CTX c; 119 ASN1_CTX c;
120 120
121 M_ASN1_New_Malloc(ret,PKCS7_SIGNER_INFO); 121 M_ASN1_New_Malloc(ret,PKCS7_SIGNER_INFO);
122 M_ASN1_New(ret->version,ASN1_INTEGER_new); 122 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
123 M_ASN1_New(ret->issuer_and_serial,PKCS7_ISSUER_AND_SERIAL_new); 123 M_ASN1_New(ret->issuer_and_serial,PKCS7_ISSUER_AND_SERIAL_new);
124 M_ASN1_New(ret->digest_alg,X509_ALGOR_new); 124 M_ASN1_New(ret->digest_alg,X509_ALGOR_new);
125 ret->auth_attr=NULL; 125 ret->auth_attr=NULL;
126 M_ASN1_New(ret->digest_enc_alg,X509_ALGOR_new); 126 M_ASN1_New(ret->digest_enc_alg,X509_ALGOR_new);
127 M_ASN1_New(ret->enc_digest,ASN1_OCTET_STRING_new); 127 M_ASN1_New(ret->enc_digest,M_ASN1_OCTET_STRING_new);
128 ret->unauth_attr=NULL; 128 ret->unauth_attr=NULL;
129 ret->pkey=NULL; 129 ret->pkey=NULL;
130 return(ret); 130 return(ret);
@@ -134,16 +134,16 @@ PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void)
134void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a) 134void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a)
135 { 135 {
136 if (a == NULL) return; 136 if (a == NULL) return;
137 ASN1_INTEGER_free(a->version); 137 M_ASN1_INTEGER_free(a->version);
138 PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial); 138 PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial);
139 X509_ALGOR_free(a->digest_alg); 139 X509_ALGOR_free(a->digest_alg);
140 sk_X509_ATTRIBUTE_pop_free(a->auth_attr,X509_ATTRIBUTE_free); 140 sk_X509_ATTRIBUTE_pop_free(a->auth_attr,X509_ATTRIBUTE_free);
141 X509_ALGOR_free(a->digest_enc_alg); 141 X509_ALGOR_free(a->digest_enc_alg);
142 ASN1_OCTET_STRING_free(a->enc_digest); 142 M_ASN1_OCTET_STRING_free(a->enc_digest);
143 sk_X509_ATTRIBUTE_pop_free(a->unauth_attr,X509_ATTRIBUTE_free); 143 sk_X509_ATTRIBUTE_pop_free(a->unauth_attr,X509_ATTRIBUTE_free);
144 if (a->pkey != NULL) 144 if (a->pkey != NULL)
145 EVP_PKEY_free(a->pkey); 145 EVP_PKEY_free(a->pkey);
146 Free((char *)a); 146 Free(a);
147 } 147 }
148 148
149IMPLEMENT_STACK_OF(PKCS7_SIGNER_INFO) 149IMPLEMENT_STACK_OF(PKCS7_SIGNER_INFO)
diff --git a/src/lib/libcrypto/asn1/p8_key.c b/src/lib/libcrypto/asn1/p8_key.c
new file mode 100644
index 0000000000..0b24374627
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p8_key.c
@@ -0,0 +1,131 @@
1/* crypto/asn1/p8_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/objects.h>
63
64int i2d_X509_KEY(X509 *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
69 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
70 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
71
72 M_ASN1_I2D_seq_total();
73
74 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
75 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
76 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
77
78 M_ASN1_I2D_finish();
79 }
80
81X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length)
82 {
83 M_ASN1_D2I_vars(a,X509 *,X509_new);
84
85 M_ASN1_D2I_Init();
86 M_ASN1_D2I_start_sequence();
87 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
88 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
89 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
90 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
91 }
92
93X509 *X509_KEY_new(void)
94 {
95 X509_KEY *ret=NULL;
96
97 M_ASN1_New_Malloc(ret,X509_KEY);
98 ret->references=1;
99 ret->type=NID
100 M_ASN1_New(ret->cert_info,X509_CINF_new);
101 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
102 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_NEW);
105 }
106
107void X509_KEY_free(X509 *a)
108 {
109 int i;
110
111 if (a == NULL) return;
112
113 i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY);
114#ifdef REF_PRINT
115 REF_PRINT("X509_KEY",a);
116#endif
117 if (i > 0) return;
118#ifdef REF_CHECK
119 if (i < 0)
120 {
121 fprintf(stderr,"X509_KEY_free, bad reference count\n");
122 abort();
123 }
124#endif
125
126 X509_CINF_free(a->cert_info);
127 X509_ALGOR_free(a->sig_alg);
128 ASN1_BIT_STRING_free(a->signature);
129 Free(a);
130 }
131
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
index aa9a4f6c96..59cfbe7f28 100644
--- a/src/lib/libcrypto/asn1/p8_pkey.c
+++ b/src/lib/libcrypto/asn1/p8_pkey.c
@@ -88,7 +88,7 @@ PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void)
88 PKCS8_PRIV_KEY_INFO *ret=NULL; 88 PKCS8_PRIV_KEY_INFO *ret=NULL;
89 ASN1_CTX c; 89 ASN1_CTX c;
90 M_ASN1_New_Malloc(ret, PKCS8_PRIV_KEY_INFO); 90 M_ASN1_New_Malloc(ret, PKCS8_PRIV_KEY_INFO);
91 M_ASN1_New (ret->version, ASN1_INTEGER_new); 91 M_ASN1_New (ret->version, M_ASN1_INTEGER_new);
92 M_ASN1_New (ret->pkeyalg, X509_ALGOR_new); 92 M_ASN1_New (ret->pkeyalg, X509_ALGOR_new);
93 M_ASN1_New (ret->pkey, ASN1_TYPE_new); 93 M_ASN1_New (ret->pkey, ASN1_TYPE_new);
94 ret->attributes = NULL; 94 ret->attributes = NULL;
@@ -109,15 +109,13 @@ PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
109 M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes, 109 M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes,
110 d2i_X509_ATTRIBUTE, 110 d2i_X509_ATTRIBUTE,
111 X509_ATTRIBUTE_free, 0); 111 X509_ATTRIBUTE_free, 0);
112 if (ASN1_TYPE_get(ret->pkey) == V_ASN1_SEQUENCE)
113 ret->broken = PKCS8_NO_OCTET;
114 M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO); 112 M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO);
115} 113}
116 114
117void PKCS8_PRIV_KEY_INFO_free (PKCS8_PRIV_KEY_INFO *a) 115void PKCS8_PRIV_KEY_INFO_free (PKCS8_PRIV_KEY_INFO *a)
118{ 116{
119 if (a == NULL) return; 117 if (a == NULL) return;
120 ASN1_INTEGER_free (a->version); 118 M_ASN1_INTEGER_free (a->version);
121 X509_ALGOR_free(a->pkeyalg); 119 X509_ALGOR_free(a->pkeyalg);
122 /* Clear sensitive data */ 120 /* Clear sensitive data */
123 if (a->pkey->value.octet_string) 121 if (a->pkey->value.octet_string)
diff --git a/src/lib/libcrypto/asn1/pkcs8.c b/src/lib/libcrypto/asn1/pkcs8.c
index 29c4ea6a29..e69de29bb2 100644
--- a/src/lib/libcrypto/asn1/pkcs8.c
+++ b/src/lib/libcrypto/asn1/pkcs8.c
@@ -1,131 +0,0 @@
1/* crypto/asn1/pkcs8.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/objects.h>
63
64int i2d_X509_KEY(X509 *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
69 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
70 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
71
72 M_ASN1_I2D_seq_total();
73
74 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
75 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
76 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
77
78 M_ASN1_I2D_finish();
79 }
80
81X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length)
82 {
83 M_ASN1_D2I_vars(a,X509 *,X509_new);
84
85 M_ASN1_D2I_Init();
86 M_ASN1_D2I_start_sequence();
87 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
88 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
89 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
90 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
91 }
92
93X509 *X509_KEY_new(void)
94 {
95 X509_KEY *ret=NULL;
96
97 M_ASN1_New_Malloc(ret,X509_KEY);
98 ret->references=1;
99 ret->type=NID
100 M_ASN1_New(ret->cert_info,X509_CINF_new);
101 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
102 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_NEW);
105 }
106
107void X509_KEY_free(X509 *a)
108 {
109 int i;
110
111 if (a == NULL) return;
112
113 i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY);
114#ifdef REF_PRINT
115 REF_PRINT("X509_KEY",a);
116#endif
117 if (i > 0) return;
118#ifdef REF_CHECK
119 if (i < 0)
120 {
121 fprintf(stderr,"X509_KEY_free, bad reference count\n");
122 abort();
123 }
124#endif
125
126 X509_CINF_free(a->cert_info);
127 X509_ALGOR_free(a->sig_alg);
128 ASN1_BIT_STRING_free(a->signature);
129 Free((char *)a);
130 }
131
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c
new file mode 100644
index 0000000000..8ee789f082
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_bitst.c
@@ -0,0 +1,99 @@
1/* t_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
65 BIT_STRING_BITNAME *tbl, int indent)
66{
67 BIT_STRING_BITNAME *bnam;
68 char first = 1;
69 BIO_printf(out, "%*s", indent, "");
70 for(bnam = tbl; bnam->lname; bnam++) {
71 if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
72 if(!first) BIO_puts(out, ", ");
73 BIO_puts(out, bnam->lname);
74 first = 0;
75 }
76 }
77 BIO_puts(out, "\n");
78 return 1;
79}
80
81int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
82 BIT_STRING_BITNAME *tbl)
83{
84 int bitnum;
85 bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
86 if(bitnum < 0) return 0;
87 if(bs) ASN1_BIT_STRING_set_bit(bs, bitnum, value);
88 return 1;
89}
90
91int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
92{
93 BIT_STRING_BITNAME *bnam;
94 for(bnam = tbl; bnam->lname; bnam++) {
95 if(!strcmp(bnam->sname, name) ||
96 !strcmp(bnam->lname, name) ) return bnam->bitnum;
97 }
98 return -1;
99}
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
index c2e447ce6f..d78e4a8f88 100644
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ b/src/lib/libcrypto/asn1/t_crl.c
@@ -160,7 +160,7 @@ static void ext_print(BIO *out, X509_EXTENSION *ex)
160 BIO_printf(out, ": %s\n", j ? "critical":"",""); 160 BIO_printf(out, ": %s\n", j ? "critical":"","");
161 if(!X509V3_EXT_print(out, ex, 0, 16)) { 161 if(!X509V3_EXT_print(out, ex, 0, 16)) {
162 BIO_printf(out, "%16s", ""); 162 BIO_printf(out, "%16s", "");
163 ASN1_OCTET_STRING_print(out,ex->value); 163 M_ASN1_OCTET_STRING_print(out,ex->value);
164 } 164 }
165 BIO_write(out,"\n",1); 165 BIO_write(out,"\n",1);
166} 166}
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
index 0dc6e30c3d..e570ed1c47 100644
--- a/src/lib/libcrypto/asn1/t_pkey.c
+++ b/src/lib/libcrypto/asn1/t_pkey.c
@@ -133,7 +133,7 @@ int RSA_print(BIO *bp, RSA *x, int off)
133 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err; 133 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
134 ret=1; 134 ret=1;
135err: 135err:
136 if (m != NULL) Free((char *)m); 136 if (m != NULL) Free(m);
137 return(ret); 137 return(ret);
138 } 138 }
139#endif /* NO_RSA */ 139#endif /* NO_RSA */
@@ -204,7 +204,7 @@ int DSA_print(BIO *bp, DSA *x, int off)
204 if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err; 204 if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err;
205 ret=1; 205 ret=1;
206err: 206err:
207 if (m != NULL) Free((char *)m); 207 if (m != NULL) Free(m);
208 return(ret); 208 return(ret);
209 } 209 }
210#endif /* !NO_DSA */ 210#endif /* !NO_DSA */
@@ -298,7 +298,7 @@ int DHparams_print(BIO *bp, DH *x)
298 if (!print(bp,"generator:",x->g,m,4)) goto err; 298 if (!print(bp,"generator:",x->g,m,4)) goto err;
299 if (x->length != 0) 299 if (x->length != 0)
300 { 300 {
301 if (BIO_printf(bp," recomented-private-length: %d bits\n", 301 if (BIO_printf(bp," recommended-private-length: %d bits\n",
302 (int)x->length) <= 0) goto err; 302 (int)x->length) <= 0) goto err;
303 } 303 }
304 ret=1; 304 ret=1;
@@ -307,7 +307,7 @@ int DHparams_print(BIO *bp, DH *x)
307err: 307err:
308 DHerr(DH_F_DHPARAMS_PRINT,reason); 308 DHerr(DH_F_DHPARAMS_PRINT,reason);
309 } 309 }
310 if (m != NULL) Free((char *)m); 310 if (m != NULL) Free(m);
311 return(ret); 311 return(ret);
312 } 312 }
313#endif 313#endif
@@ -352,7 +352,7 @@ int DSAparams_print(BIO *bp, DSA *x)
352 if (!print(bp,"g:",x->g,m,4)) goto err; 352 if (!print(bp,"g:",x->g,m,4)) goto err;
353 ret=1; 353 ret=1;
354err: 354err:
355 if (m != NULL) Free((char *)m); 355 if (m != NULL) Free(m);
356 DSAerr(DSA_F_DSAPARAMS_PRINT,reason); 356 DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
357 return(ret); 357 return(ret);
358 } 358 }
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
index bdd749436a..81dd6355a8 100644
--- a/src/lib/libcrypto/asn1/t_req.c
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -62,6 +62,7 @@
62#include <openssl/bn.h> 62#include <openssl/bn.h>
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
65 66
66#ifndef NO_FP_API 67#ifndef NO_FP_API
67int X509_REQ_print_fp(FILE *fp, X509_REQ *x) 68int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
@@ -90,6 +91,7 @@ int X509_REQ_print(BIO *bp, X509_REQ *x)
90 X509_REQ_INFO *ri; 91 X509_REQ_INFO *ri;
91 EVP_PKEY *pkey; 92 EVP_PKEY *pkey;
92 STACK_OF(X509_ATTRIBUTE) *sk; 93 STACK_OF(X509_ATTRIBUTE) *sk;
94 STACK_OF(X509_EXTENSION) *exts;
93 char str[128]; 95 char str[128];
94 96
95 ri=x->req_info; 97 ri=x->req_info;
@@ -161,6 +163,8 @@ int X509_REQ_print(BIO *bp, X509_REQ *x)
161 int j,type=0,count=1,ii=0; 163 int j,type=0,count=1,ii=0;
162 164
163 a=sk_X509_ATTRIBUTE_value(sk,i); 165 a=sk_X509_ATTRIBUTE_value(sk,i);
166 if(X509_REQ_extension_nid(OBJ_obj2nid(a->object)))
167 continue;
164 sprintf(str,"%12s",""); 168 sprintf(str,"%12s","");
165 if (BIO_puts(bp,str) <= 0) goto err; 169 if (BIO_puts(bp,str) <= 0) goto err;
166 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) 170 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
@@ -201,6 +205,29 @@ get_next:
201 } 205 }
202 } 206 }
203 207
208 exts = X509_REQ_get_extensions(x);
209 if(exts) {
210 BIO_printf(bp,"%8sRequested Extensions:\n","");
211 for (i=0; i<sk_X509_EXTENSION_num(exts); i++) {
212 ASN1_OBJECT *obj;
213 X509_EXTENSION *ex;
214 int j;
215 ex=sk_X509_EXTENSION_value(exts, i);
216 if (BIO_printf(bp,"%12s","") <= 0) goto err;
217 obj=X509_EXTENSION_get_object(ex);
218 i2a_ASN1_OBJECT(bp,obj);
219 j=X509_EXTENSION_get_critical(ex);
220 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
221 goto err;
222 if(!X509V3_EXT_print(bp, ex, 0, 16)) {
223 BIO_printf(bp, "%16s", "");
224 M_ASN1_OCTET_STRING_print(bp,ex->value);
225 }
226 if (BIO_write(bp,"\n",1) <= 0) goto err;
227 }
228 sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
229 }
230
204 i=OBJ_obj2nid(x->sig_alg->algorithm); 231 i=OBJ_obj2nid(x->sig_alg->algorithm);
205 sprintf(str,"%4sSignature Algorithm: %s","", 232 sprintf(str,"%4sSignature Algorithm: %s","",
206 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); 233 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c
new file mode 100644
index 0000000000..d708434fca
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_spki.c
@@ -0,0 +1,116 @@
1/* t_spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/asn1_mac.h>
63
64/* Print out an SPKI */
65
66int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
67{
68 EVP_PKEY *pkey;
69 ASN1_IA5STRING *chal;
70 int i, n;
71 char *s;
72 BIO_printf(out, "Netscape SPKI:\n");
73 i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm);
74 BIO_printf(out," Public Key Algorithm: %s\n",
75 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
76 pkey = X509_PUBKEY_get(spki->spkac->pubkey);
77 if(!pkey) BIO_printf(out, " Unable to load public key\n");
78 else {
79#ifndef NO_RSA
80 if (pkey->type == EVP_PKEY_RSA)
81 {
82 BIO_printf(out," RSA Public Key: (%d bit)\n",
83 BN_num_bits(pkey->pkey.rsa->n));
84 RSA_print(out,pkey->pkey.rsa,2);
85 }
86 else
87#endif
88#ifndef NO_DSA
89 if (pkey->type == EVP_PKEY_DSA)
90 {
91 BIO_printf(out," DSA Public Key:\n");
92 DSA_print(out,pkey->pkey.dsa,2);
93 }
94 else
95#endif
96 BIO_printf(out," Unknown Public Key:\n");
97 EVP_PKEY_free(pkey);
98 }
99 chal = spki->spkac->challenge;
100 if(chal->length)
101 BIO_printf(out, " Challenge String: %s\n", chal->data);
102 i=OBJ_obj2nid(spki->sig_algor->algorithm);
103 BIO_printf(out," Signature Algorithm: %s",
104 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
105
106 n=spki->signature->length;
107 s=(char *)spki->signature->data;
108 for (i=0; i<n; i++)
109 {
110 if ((i%18) == 0) BIO_write(out,"\n ",7);
111 BIO_printf(out,"%02x%s",(unsigned char)s[i],
112 ((i+1) == n)?"":":");
113 }
114 BIO_write(out,"\n",1);
115 return 1;
116}
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index 42f4d498cf..6ee1065ce9 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -188,11 +188,7 @@ int X509_print(BIO *bp, X509 *x)
188 BIO_printf(bp,"%8sX509v3 extensions:\n",""); 188 BIO_printf(bp,"%8sX509v3 extensions:\n","");
189 for (i=0; i<n; i++) 189 for (i=0; i<n; i++)
190 { 190 {
191#if 0
192 int data_type,pack_type;
193#endif
194 ASN1_OBJECT *obj; 191 ASN1_OBJECT *obj;
195
196 ex=X509_get_ext(x,i); 192 ex=X509_get_ext(x,i);
197 if (BIO_printf(bp,"%12s","") <= 0) goto err; 193 if (BIO_printf(bp,"%12s","") <= 0) goto err;
198 obj=X509_EXTENSION_get_object(ex); 194 obj=X509_EXTENSION_get_object(ex);
@@ -203,7 +199,7 @@ int X509_print(BIO *bp, X509 *x)
203 if(!X509V3_EXT_print(bp, ex, 0, 16)) 199 if(!X509V3_EXT_print(bp, ex, 0, 16))
204 { 200 {
205 BIO_printf(bp, "%16s", ""); 201 BIO_printf(bp, "%16s", "");
206 ASN1_OCTET_STRING_print(bp,ex->value); 202 M_ASN1_OCTET_STRING_print(bp,ex->value);
207 } 203 }
208 if (BIO_write(bp,"\n",1) <= 0) goto err; 204 if (BIO_write(bp,"\n",1) <= 0) goto err;
209 } 205 }
@@ -223,10 +219,11 @@ int X509_print(BIO *bp, X509 *x)
223 ((i+1) == n)?"":":") <= 0) goto err; 219 ((i+1) == n)?"":":") <= 0) goto err;
224 } 220 }
225 if (BIO_write(bp,"\n",1) != 1) goto err; 221 if (BIO_write(bp,"\n",1) != 1) goto err;
222 if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err;
226 ret=1; 223 ret=1;
227err: 224err:
228 if (str != NULL) ASN1_STRING_free(str); 225 if (str != NULL) ASN1_STRING_free(str);
229 if (m != NULL) Free((char *)m); 226 if (m != NULL) Free(m);
230 return(ret); 227 return(ret);
231 } 228 }
232 229
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c
new file mode 100644
index 0000000000..a18ebb586c
--- /dev/null
+++ b/src/lib/libcrypto/asn1/t_x509a.c
@@ -0,0 +1,102 @@
1/* t_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX and string set routines
66 */
67
68int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)
69{
70 char oidstr[80], first;
71 int i;
72 if(!aux) return 1;
73 if(aux->trust) {
74 first = 1;
75 BIO_printf(out, "%*sTrusted Uses:\n%*s",
76 indent, "", indent + 2, "");
77 for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {
78 if(!first) BIO_puts(out, ", ");
79 else first = 0;
80 OBJ_obj2txt(oidstr, 80,
81 sk_ASN1_OBJECT_value(aux->trust, i), 0);
82 BIO_puts(out, oidstr);
83 }
84 BIO_puts(out, "\n");
85 } else BIO_printf(out, "%*sNo Trusted Uses.\n", indent, "");
86 if(aux->reject) {
87 first = 1;
88 BIO_printf(out, "%*sRejected Uses:\n%*s",
89 indent, "", indent + 2, "");
90 for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {
91 if(!first) BIO_puts(out, ", ");
92 else first = 0;
93 OBJ_obj2txt(oidstr, 80,
94 sk_ASN1_OBJECT_value(aux->reject, i), 0);
95 BIO_puts(out, oidstr);
96 }
97 BIO_puts(out, "\n");
98 } else BIO_printf(out, "%*sNo Rejected Uses.\n", indent, "");
99 if(aux->alias) BIO_printf(out, "%*sAlias: %s\n", indent, "",
100 aux->alias->data);
101 return 1;
102}
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
index b2c20d139f..fe023842f8 100644
--- a/src/lib/libcrypto/asn1/x_algor.c
+++ b/src/lib/libcrypto/asn1/x_algor.c
@@ -111,7 +111,7 @@ void X509_ALGOR_free(X509_ALGOR *a)
111 if (a == NULL) return; 111 if (a == NULL) return;
112 ASN1_OBJECT_free(a->algorithm); 112 ASN1_OBJECT_free(a->algorithm);
113 ASN1_TYPE_free(a->parameter); 113 ASN1_TYPE_free(a->parameter);
114 Free((char *)a); 114 Free(a);
115 } 115 }
116 116
117IMPLEMENT_STACK_OF(X509_ALGOR) 117IMPLEMENT_STACK_OF(X509_ALGOR)
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c
index a1cbebf5a5..a874df79db 100644
--- a/src/lib/libcrypto/asn1/x_attrib.c
+++ b/src/lib/libcrypto/asn1/x_attrib.c
@@ -160,6 +160,6 @@ void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a)
160 sk_ASN1_TYPE_pop_free(a->value.set,ASN1_TYPE_free); 160 sk_ASN1_TYPE_pop_free(a->value.set,ASN1_TYPE_free);
161 else 161 else
162 ASN1_TYPE_free(a->value.single); 162 ASN1_TYPE_free(a->value.single);
163 Free((char *)a); 163 Free(a);
164 } 164 }
165 165
diff --git a/src/lib/libcrypto/asn1/x_cinf.c b/src/lib/libcrypto/asn1/x_cinf.c
index fe1b18a90f..b87c8fff17 100644
--- a/src/lib/libcrypto/asn1/x_cinf.c
+++ b/src/lib/libcrypto/asn1/x_cinf.c
@@ -115,7 +115,7 @@ X509_CINF *d2i_X509_CINF(X509_CINF **a, unsigned char **pp, long length)
115 { 115 {
116 if (ret->version != NULL) 116 if (ret->version != NULL)
117 { 117 {
118 ASN1_INTEGER_free(ret->version); 118 M_ASN1_INTEGER_free(ret->version);
119 ret->version=NULL; 119 ret->version=NULL;
120 } 120 }
121 } 121 }
@@ -129,12 +129,12 @@ X509_CINF *d2i_X509_CINF(X509_CINF **a, unsigned char **pp, long length)
129 { 129 {
130 if (ret->issuerUID != NULL) 130 if (ret->issuerUID != NULL)
131 { 131 {
132 ASN1_BIT_STRING_free(ret->issuerUID); 132 M_ASN1_BIT_STRING_free(ret->issuerUID);
133 ret->issuerUID=NULL; 133 ret->issuerUID=NULL;
134 } 134 }
135 if (ret->subjectUID != NULL) 135 if (ret->subjectUID != NULL)
136 { 136 {
137 ASN1_BIT_STRING_free(ret->subjectUID); 137 M_ASN1_BIT_STRING_free(ret->subjectUID);
138 ret->subjectUID=NULL; 138 ret->subjectUID=NULL;
139 } 139 }
140 M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1, 140 M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1,
@@ -170,7 +170,7 @@ X509_CINF *X509_CINF_new(void)
170 170
171 M_ASN1_New_Malloc(ret,X509_CINF); 171 M_ASN1_New_Malloc(ret,X509_CINF);
172 ret->version=NULL; 172 ret->version=NULL;
173 M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); 173 M_ASN1_New(ret->serialNumber,M_ASN1_INTEGER_new);
174 M_ASN1_New(ret->signature,X509_ALGOR_new); 174 M_ASN1_New(ret->signature,X509_ALGOR_new);
175 M_ASN1_New(ret->issuer,X509_NAME_new); 175 M_ASN1_New(ret->issuer,X509_NAME_new);
176 M_ASN1_New(ret->validity,X509_VAL_new); 176 M_ASN1_New(ret->validity,X509_VAL_new);
@@ -186,15 +186,15 @@ X509_CINF *X509_CINF_new(void)
186void X509_CINF_free(X509_CINF *a) 186void X509_CINF_free(X509_CINF *a)
187 { 187 {
188 if (a == NULL) return; 188 if (a == NULL) return;
189 ASN1_INTEGER_free(a->version); 189 M_ASN1_INTEGER_free(a->version);
190 ASN1_INTEGER_free(a->serialNumber); 190 M_ASN1_INTEGER_free(a->serialNumber);
191 X509_ALGOR_free(a->signature); 191 X509_ALGOR_free(a->signature);
192 X509_NAME_free(a->issuer); 192 X509_NAME_free(a->issuer);
193 X509_VAL_free(a->validity); 193 X509_VAL_free(a->validity);
194 X509_NAME_free(a->subject); 194 X509_NAME_free(a->subject);
195 X509_PUBKEY_free(a->key); 195 X509_PUBKEY_free(a->key);
196 ASN1_BIT_STRING_free(a->issuerUID); 196 M_ASN1_BIT_STRING_free(a->issuerUID);
197 ASN1_BIT_STRING_free(a->subjectUID); 197 M_ASN1_BIT_STRING_free(a->subjectUID);
198 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free); 198 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
199 Free(a); 199 Free(a);
200 } 200 }
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
index cd46bbebc2..12a42d04c7 100644
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -130,9 +130,9 @@ int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp)
130 } 130 }
131 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR); 131 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
132 M_ASN1_I2D_put(a->issuer,i2d_X509_NAME); 132 M_ASN1_I2D_put(a->issuer,i2d_X509_NAME);
133 M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME); 133 M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_TIME);
134 if (a->nextUpdate != NULL) 134 if (a->nextUpdate != NULL)
135 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); } 135 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_TIME); }
136 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_REVOKED,a->revoked, 136 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
137 i2d_X509_REVOKED); 137 i2d_X509_REVOKED);
138 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions, 138 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
@@ -157,20 +157,16 @@ X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, unsigned char **pp,
157 157
158 if ((ver == 0) && (ret->version != NULL)) 158 if ((ver == 0) && (ret->version != NULL))
159 { 159 {
160 ASN1_INTEGER_free(ret->version); 160 M_ASN1_INTEGER_free(ret->version);
161 ret->version=NULL; 161 ret->version=NULL;
162 } 162 }
163 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); 163 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
164 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); 164 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
165 M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_TIME); 165 M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_TIME);
166 /* Manually handle the OPTIONAL ASN1_TIME stuff */ 166 /* Manually handle the OPTIONAL ASN1_TIME stuff */
167 if(c.slen != 0 167 /* First try UTCTime */
168 && ( (M_ASN1_next & ~V_ASN1_CONSTRUCTED) == 168 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME, V_ASN1_UTCTIME);
169 (V_ASN1_UNIVERSAL|V_ASN1_UTCTIME) 169 /* If that doesn't work try GeneralizedTime */
170 || (M_ASN1_next & ~V_ASN1_CONSTRUCTED) ==
171 (V_ASN1_UNIVERSAL|V_ASN1_GENERALIZEDTIME) ) ) {
172 M_ASN1_D2I_get(ret->nextUpdate,d2i_ASN1_TIME);
173 }
174 if(!ret->nextUpdate) 170 if(!ret->nextUpdate)
175 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME, 171 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME,
176 V_ASN1_GENERALIZEDTIME); 172 V_ASN1_GENERALIZEDTIME);
@@ -190,20 +186,17 @@ X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, unsigned char **pp,
190 } 186 }
191 } 187 }
192 188
193 if (ver >= 1) 189 if (ret->extensions != NULL)
194 { 190 {
195 if (ret->extensions != NULL) 191 while (sk_X509_EXTENSION_num(ret->extensions))
196 { 192 X509_EXTENSION_free(
197 while (sk_X509_EXTENSION_num(ret->extensions)) 193 sk_X509_EXTENSION_pop(ret->extensions));
198 X509_EXTENSION_free(
199 sk_X509_EXTENSION_pop(ret->extensions));
200 }
201
202 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
203 d2i_X509_EXTENSION,
204 X509_EXTENSION_free,0,
205 V_ASN1_SEQUENCE);
206 } 194 }
195
196 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
197 d2i_X509_EXTENSION,
198 X509_EXTENSION_free,0,
199 V_ASN1_SEQUENCE);
207 200
208 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO); 201 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO);
209 } 202 }
@@ -245,8 +238,8 @@ X509_REVOKED *X509_REVOKED_new(void)
245 ASN1_CTX c; 238 ASN1_CTX c;
246 239
247 M_ASN1_New_Malloc(ret,X509_REVOKED); 240 M_ASN1_New_Malloc(ret,X509_REVOKED);
248 M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); 241 M_ASN1_New(ret->serialNumber,M_ASN1_INTEGER_new);
249 M_ASN1_New(ret->revocationDate,ASN1_UTCTIME_new); 242 M_ASN1_New(ret->revocationDate,M_ASN1_UTCTIME_new);
250 ret->extensions=NULL; 243 ret->extensions=NULL;
251 return(ret); 244 return(ret);
252 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW); 245 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW);
@@ -261,7 +254,7 @@ X509_CRL_INFO *X509_CRL_INFO_new(void)
261 ret->version=NULL; 254 ret->version=NULL;
262 M_ASN1_New(ret->sig_alg,X509_ALGOR_new); 255 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
263 M_ASN1_New(ret->issuer,X509_NAME_new); 256 M_ASN1_New(ret->issuer,X509_NAME_new);
264 M_ASN1_New(ret->lastUpdate,ASN1_UTCTIME_new); 257 M_ASN1_New(ret->lastUpdate,M_ASN1_UTCTIME_new);
265 ret->nextUpdate=NULL; 258 ret->nextUpdate=NULL;
266 M_ASN1_New(ret->revoked,sk_X509_REVOKED_new_null); 259 M_ASN1_New(ret->revoked,sk_X509_REVOKED_new_null);
267 M_ASN1_New(ret->extensions,sk_X509_EXTENSION_new_null); 260 M_ASN1_New(ret->extensions,sk_X509_EXTENSION_new_null);
@@ -279,7 +272,7 @@ X509_CRL *X509_CRL_new(void)
279 ret->references=1; 272 ret->references=1;
280 M_ASN1_New(ret->crl,X509_CRL_INFO_new); 273 M_ASN1_New(ret->crl,X509_CRL_INFO_new);
281 M_ASN1_New(ret->sig_alg,X509_ALGOR_new); 274 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
282 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); 275 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
283 return(ret); 276 return(ret);
284 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW); 277 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW);
285 } 278 }
@@ -287,8 +280,8 @@ X509_CRL *X509_CRL_new(void)
287void X509_REVOKED_free(X509_REVOKED *a) 280void X509_REVOKED_free(X509_REVOKED *a)
288 { 281 {
289 if (a == NULL) return; 282 if (a == NULL) return;
290 ASN1_INTEGER_free(a->serialNumber); 283 M_ASN1_INTEGER_free(a->serialNumber);
291 ASN1_UTCTIME_free(a->revocationDate); 284 M_ASN1_UTCTIME_free(a->revocationDate);
292 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free); 285 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
293 Free(a); 286 Free(a);
294 } 287 }
@@ -296,12 +289,12 @@ void X509_REVOKED_free(X509_REVOKED *a)
296void X509_CRL_INFO_free(X509_CRL_INFO *a) 289void X509_CRL_INFO_free(X509_CRL_INFO *a)
297 { 290 {
298 if (a == NULL) return; 291 if (a == NULL) return;
299 ASN1_INTEGER_free(a->version); 292 M_ASN1_INTEGER_free(a->version);
300 X509_ALGOR_free(a->sig_alg); 293 X509_ALGOR_free(a->sig_alg);
301 X509_NAME_free(a->issuer); 294 X509_NAME_free(a->issuer);
302 ASN1_UTCTIME_free(a->lastUpdate); 295 M_ASN1_UTCTIME_free(a->lastUpdate);
303 if (a->nextUpdate) 296 if (a->nextUpdate)
304 ASN1_UTCTIME_free(a->nextUpdate); 297 M_ASN1_UTCTIME_free(a->nextUpdate);
305 sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free); 298 sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free);
306 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free); 299 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
307 Free(a); 300 Free(a);
@@ -328,7 +321,7 @@ void X509_CRL_free(X509_CRL *a)
328 321
329 X509_CRL_INFO_free(a->crl); 322 X509_CRL_INFO_free(a->crl);
330 X509_ALGOR_free(a->sig_alg); 323 X509_ALGOR_free(a->sig_alg);
331 ASN1_BIT_STRING_free(a->signature); 324 M_ASN1_BIT_STRING_free(a->signature);
332 Free(a); 325 Free(a);
333 } 326 }
334 327
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
index d5f9e1df9e..185cbd78a0 100644
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ b/src/lib/libcrypto/asn1/x_exten.c
@@ -100,10 +100,6 @@ X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a, unsigned char **pp,
100 M_ASN1_D2I_start_sequence(); 100 M_ASN1_D2I_start_sequence();
101 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT); 101 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
102 102
103 if ((ret->argp != NULL) && (ret->ex_free != NULL))
104 ret->ex_free(ret);
105 ret->argl=0;
106 ret->argp=NULL;
107 ret->netscape_hack=0; 103 ret->netscape_hack=0;
108 if ((c.slen != 0) && 104 if ((c.slen != 0) &&
109 (M_ASN1_next == (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN))) 105 (M_ASN1_next == (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN)))
@@ -126,12 +122,9 @@ X509_EXTENSION *X509_EXTENSION_new(void)
126 122
127 M_ASN1_New_Malloc(ret,X509_EXTENSION); 123 M_ASN1_New_Malloc(ret,X509_EXTENSION);
128 ret->object=OBJ_nid2obj(NID_undef); 124 ret->object=OBJ_nid2obj(NID_undef);
129 M_ASN1_New(ret->value,ASN1_OCTET_STRING_new); 125 M_ASN1_New(ret->value,M_ASN1_OCTET_STRING_new);
130 ret->critical=0; 126 ret->critical=0;
131 ret->netscape_hack=0; 127 ret->netscape_hack=0;
132 ret->argl=0L;
133 ret->argp=NULL;
134 ret->ex_free=NULL;
135 return(ret); 128 return(ret);
136 M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW); 129 M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW);
137 } 130 }
@@ -139,10 +132,8 @@ X509_EXTENSION *X509_EXTENSION_new(void)
139void X509_EXTENSION_free(X509_EXTENSION *a) 132void X509_EXTENSION_free(X509_EXTENSION *a)
140 { 133 {
141 if (a == NULL) return; 134 if (a == NULL) return;
142 if ((a->argp != NULL) && (a->ex_free != NULL))
143 a->ex_free(a);
144 ASN1_OBJECT_free(a->object); 135 ASN1_OBJECT_free(a->object);
145 ASN1_OCTET_STRING_free(a->value); 136 M_ASN1_OCTET_STRING_free(a->value);
146 Free((char *)a); 137 Free(a);
147 } 138 }
148 139
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
index 99ce011f07..7fdc6f9dc8 100644
--- a/src/lib/libcrypto/asn1/x_info.c
+++ b/src/lib/libcrypto/asn1/x_info.c
@@ -106,7 +106,8 @@ void X509_INFO_free(X509_INFO *x)
106 if (x->x509 != NULL) X509_free(x->x509); 106 if (x->x509 != NULL) X509_free(x->x509);
107 if (x->crl != NULL) X509_CRL_free(x->crl); 107 if (x->crl != NULL) X509_CRL_free(x->crl);
108 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); 108 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey);
109 Free((char *)x); 109 if (x->enc_data != NULL) Free(x->enc_data);
110 Free(x);
110 } 111 }
111 112
112IMPLEMENT_STACK_OF(X509_INFO) 113IMPLEMENT_STACK_OF(X509_INFO)
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
index b09fba33fb..64baf5719d 100644
--- a/src/lib/libcrypto/asn1/x_name.c
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -253,7 +253,7 @@ void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a)
253 { 253 {
254 if (a == NULL) return; 254 if (a == NULL) return;
255 ASN1_OBJECT_free(a->object); 255 ASN1_OBJECT_free(a->object);
256 ASN1_BIT_STRING_free(a->value); 256 M_ASN1_BIT_STRING_free(a->value);
257 Free(a); 257 Free(a);
258 } 258 }
259 259
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
index b0057eb212..fe58919dbb 100644
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -112,7 +112,7 @@ X509_PKEY *X509_PKEY_new(void)
112 M_ASN1_New_Malloc(ret,X509_PKEY); 112 M_ASN1_New_Malloc(ret,X509_PKEY);
113 ret->version=0; 113 ret->version=0;
114 M_ASN1_New(ret->enc_algor,X509_ALGOR_new); 114 M_ASN1_New(ret->enc_algor,X509_ALGOR_new);
115 M_ASN1_New(ret->enc_pkey,ASN1_OCTET_STRING_new); 115 M_ASN1_New(ret->enc_pkey,M_ASN1_OCTET_STRING_new);
116 ret->dec_pkey=NULL; 116 ret->dec_pkey=NULL;
117 ret->key_length=0; 117 ret->key_length=0;
118 ret->key_data=NULL; 118 ret->key_data=NULL;
@@ -144,8 +144,8 @@ void X509_PKEY_free(X509_PKEY *x)
144#endif 144#endif
145 145
146 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor); 146 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor);
147 if (x->enc_pkey != NULL) ASN1_OCTET_STRING_free(x->enc_pkey); 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); 148 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey);
149 if ((x->key_data != NULL) && (x->key_free)) Free((char *)x->key_data); 149 if ((x->key_data != NULL) && (x->key_free)) Free(x->key_data);
150 Free((char *)(char *)x); 150 Free(x);
151 } 151 }
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index 4ac32c59dd..81e9815222 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -100,7 +100,7 @@ X509_PUBKEY *X509_PUBKEY_new(void)
100 100
101 M_ASN1_New_Malloc(ret,X509_PUBKEY); 101 M_ASN1_New_Malloc(ret,X509_PUBKEY);
102 M_ASN1_New(ret->algor,X509_ALGOR_new); 102 M_ASN1_New(ret->algor,X509_ALGOR_new);
103 M_ASN1_New(ret->public_key,ASN1_BIT_STRING_new); 103 M_ASN1_New(ret->public_key,M_ASN1_BIT_STRING_new);
104 ret->pkey=NULL; 104 ret->pkey=NULL;
105 return(ret); 105 return(ret);
106 M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW); 106 M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW);
@@ -110,9 +110,9 @@ void X509_PUBKEY_free(X509_PUBKEY *a)
110 { 110 {
111 if (a == NULL) return; 111 if (a == NULL) return;
112 X509_ALGOR_free(a->algor); 112 X509_ALGOR_free(a->algor);
113 ASN1_BIT_STRING_free(a->public_key); 113 M_ASN1_BIT_STRING_free(a->public_key);
114 if (a->pkey != NULL) EVP_PKEY_free(a->pkey); 114 if (a->pkey != NULL) EVP_PKEY_free(a->pkey);
115 Free((char *)a); 115 Free(a);
116 } 116 }
117 117
118int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) 118int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
@@ -176,7 +176,7 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
176 if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err; 176 if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err;
177 p=s; 177 p=s;
178 i2d_PublicKey(pkey,&p); 178 i2d_PublicKey(pkey,&p);
179 if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err; 179 if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
180 /* Set number of unused bits to zero */ 180 /* Set number of unused bits to zero */
181 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); 181 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
182 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; 182 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
@@ -252,3 +252,113 @@ err:
252 return(NULL); 252 return(NULL);
253 } 253 }
254 254
255/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
256 * and encode or decode as X509_PUBKEY
257 */
258
259EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
260 long length)
261{
262 X509_PUBKEY *xpk;
263 EVP_PKEY *pktmp;
264 xpk = d2i_X509_PUBKEY(NULL, pp, length);
265 if(!xpk) return NULL;
266 pktmp = X509_PUBKEY_get(xpk);
267 X509_PUBKEY_free(xpk);
268 if(!pktmp) return NULL;
269 if(a) {
270 EVP_PKEY_free(*a);
271 *a = pktmp;
272 }
273 return pktmp;
274}
275
276int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
277{
278 X509_PUBKEY *xpk=NULL;
279 int ret;
280 if(!a) return 0;
281 if(!X509_PUBKEY_set(&xpk, a)) return 0;
282 ret = i2d_X509_PUBKEY(xpk, pp);
283 X509_PUBKEY_free(xpk);
284 return ret;
285}
286
287/* The following are equivalents but which return RSA and DSA
288 * keys
289 */
290#ifndef NO_RSA
291RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
292 long length)
293{
294 EVP_PKEY *pkey;
295 RSA *key;
296 unsigned char *q;
297 q = *pp;
298 pkey = d2i_PUBKEY(NULL, &q, length);
299 if(!pkey) return NULL;
300 key = EVP_PKEY_get1_RSA(pkey);
301 EVP_PKEY_free(pkey);
302 if(!key) return NULL;
303 *pp = q;
304 if(a) {
305 RSA_free(*a);
306 *a = key;
307 }
308 return key;
309}
310
311int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
312{
313 EVP_PKEY *pktmp;
314 int ret;
315 if(!a) return 0;
316 pktmp = EVP_PKEY_new();
317 if(!pktmp) {
318 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
319 return 0;
320 }
321 EVP_PKEY_set1_RSA(pktmp, a);
322 ret = i2d_PUBKEY(pktmp, pp);
323 EVP_PKEY_free(pktmp);
324 return ret;
325}
326#endif
327
328#ifndef NO_DSA
329DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
330 long length)
331{
332 EVP_PKEY *pkey;
333 DSA *key;
334 unsigned char *q;
335 q = *pp;
336 pkey = d2i_PUBKEY(NULL, &q, length);
337 if(!pkey) return NULL;
338 key = EVP_PKEY_get1_DSA(pkey);
339 EVP_PKEY_free(pkey);
340 if(!key) return NULL;
341 *pp = q;
342 if(a) {
343 DSA_free(*a);
344 *a = key;
345 }
346 return key;
347}
348
349int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
350{
351 EVP_PKEY *pktmp;
352 int ret;
353 if(!a) return 0;
354 pktmp = EVP_PKEY_new();
355 if(!pktmp) {
356 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
357 return 0;
358 }
359 EVP_PKEY_set1_DSA(pktmp, a);
360 ret = i2d_PUBKEY(pktmp, pp);
361 EVP_PKEY_free(pktmp);
362 return ret;
363}
364#endif
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
index 9b1d6abe64..0cd572ee73 100644
--- a/src/lib/libcrypto/asn1/x_req.c
+++ b/src/lib/libcrypto/asn1/x_req.c
@@ -73,7 +73,7 @@ int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **pp)
73 * allow some CA Software to accept the cert request. 73 * allow some CA Software to accept the cert request.
74 * It is not following the PKCS standards ... 74 * It is not following the PKCS standards ...
75 * PKCS#10 pg 5 75 * PKCS#10 pg 5
76 * attributes [0] IMPLICIT Attibutes 76 * attributes [0] IMPLICIT Attributes
77 * NOTE: no OPTIONAL ... so it *must* be there 77 * NOTE: no OPTIONAL ... so it *must* be there
78 */ 78 */
79 if (a->req_kludge) 79 if (a->req_kludge)
@@ -94,7 +94,7 @@ int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **pp)
94 /* this is a *nasty* hack reported to be required by some CA's. 94 /* this is a *nasty* hack reported to be required by some CA's.
95 * It is not following the PKCS standards ... 95 * It is not following the PKCS standards ...
96 * PKCS#10 pg 5 96 * PKCS#10 pg 5
97 * attributes [0] IMPLICIT Attibutes 97 * attributes [0] IMPLICIT Attributes
98 * NOTE: no OPTIONAL ... so it *must* be there 98 * NOTE: no OPTIONAL ... so it *must* be there
99 */ 99 */
100 if (a->req_kludge) 100 if (a->req_kludge)
@@ -126,7 +126,7 @@ X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, unsigned char **pp,
126 * have been reported as requiring it. 126 * have been reported as requiring it.
127 * It is not following the PKCS standards ... 127 * It is not following the PKCS standards ...
128 * PKCS#10 pg 5 128 * PKCS#10 pg 5
129 * attributes [0] IMPLICIT Attibutes 129 * attributes [0] IMPLICIT Attributes
130 * NOTE: no OPTIONAL ... so it *must* be there 130 * NOTE: no OPTIONAL ... so it *must* be there
131 */ 131 */
132 if (asn1_Finish(&c)) 132 if (asn1_Finish(&c))
@@ -147,7 +147,7 @@ X509_REQ_INFO *X509_REQ_INFO_new(void)
147 ASN1_CTX c; 147 ASN1_CTX c;
148 148
149 M_ASN1_New_Malloc(ret,X509_REQ_INFO); 149 M_ASN1_New_Malloc(ret,X509_REQ_INFO);
150 M_ASN1_New(ret->version,ASN1_INTEGER_new); 150 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
151 M_ASN1_New(ret->subject,X509_NAME_new); 151 M_ASN1_New(ret->subject,X509_NAME_new);
152 M_ASN1_New(ret->pubkey,X509_PUBKEY_new); 152 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
153 M_ASN1_New(ret->attributes,sk_X509_ATTRIBUTE_new_null); 153 M_ASN1_New(ret->attributes,sk_X509_ATTRIBUTE_new_null);
@@ -159,11 +159,11 @@ X509_REQ_INFO *X509_REQ_INFO_new(void)
159void X509_REQ_INFO_free(X509_REQ_INFO *a) 159void X509_REQ_INFO_free(X509_REQ_INFO *a)
160 { 160 {
161 if (a == NULL) return; 161 if (a == NULL) return;
162 ASN1_INTEGER_free(a->version); 162 M_ASN1_INTEGER_free(a->version);
163 X509_NAME_free(a->subject); 163 X509_NAME_free(a->subject);
164 X509_PUBKEY_free(a->pubkey); 164 X509_PUBKEY_free(a->pubkey);
165 sk_X509_ATTRIBUTE_pop_free(a->attributes,X509_ATTRIBUTE_free); 165 sk_X509_ATTRIBUTE_pop_free(a->attributes,X509_ATTRIBUTE_free);
166 Free((char *)a); 166 Free(a);
167 } 167 }
168 168
169int i2d_X509_REQ(X509_REQ *a, unsigned char **pp) 169int i2d_X509_REQ(X509_REQ *a, unsigned char **pp)
@@ -203,7 +203,7 @@ X509_REQ *X509_REQ_new(void)
203 ret->references=1; 203 ret->references=1;
204 M_ASN1_New(ret->req_info,X509_REQ_INFO_new); 204 M_ASN1_New(ret->req_info,X509_REQ_INFO_new);
205 M_ASN1_New(ret->sig_alg,X509_ALGOR_new); 205 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
206 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); 206 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
207 return(ret); 207 return(ret);
208 M_ASN1_New_Error(ASN1_F_X509_REQ_NEW); 208 M_ASN1_New_Error(ASN1_F_X509_REQ_NEW);
209 } 209 }
@@ -229,8 +229,8 @@ void X509_REQ_free(X509_REQ *a)
229 229
230 X509_REQ_INFO_free(a->req_info); 230 X509_REQ_INFO_free(a->req_info);
231 X509_ALGOR_free(a->sig_alg); 231 X509_ALGOR_free(a->sig_alg);
232 ASN1_BIT_STRING_free(a->signature); 232 M_ASN1_BIT_STRING_free(a->signature);
233 Free((char *)a); 233 Free(a);
234 } 234 }
235 235
236 236
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
index c2782d1b9c..3559bd5368 100644
--- a/src/lib/libcrypto/asn1/x_sig.c
+++ b/src/lib/libcrypto/asn1/x_sig.c
@@ -94,7 +94,7 @@ X509_SIG *X509_SIG_new(void)
94 94
95 M_ASN1_New_Malloc(ret,X509_SIG); 95 M_ASN1_New_Malloc(ret,X509_SIG);
96 M_ASN1_New(ret->algor,X509_ALGOR_new); 96 M_ASN1_New(ret->algor,X509_ALGOR_new);
97 M_ASN1_New(ret->digest,ASN1_OCTET_STRING_new); 97 M_ASN1_New(ret->digest,M_ASN1_OCTET_STRING_new);
98 return(ret); 98 return(ret);
99 M_ASN1_New_Error(ASN1_F_X509_SIG_NEW); 99 M_ASN1_New_Error(ASN1_F_X509_SIG_NEW);
100 } 100 }
@@ -103,8 +103,8 @@ void X509_SIG_free(X509_SIG *a)
103 { 103 {
104 if (a == NULL) return; 104 if (a == NULL) return;
105 X509_ALGOR_free(a->algor); 105 X509_ALGOR_free(a->algor);
106 ASN1_OCTET_STRING_free(a->digest); 106 M_ASN1_OCTET_STRING_free(a->digest);
107 Free((char *)a); 107 Free(a);
108 } 108 }
109 109
110 110
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c
index 43e0023839..8f5e7e6380 100644
--- a/src/lib/libcrypto/asn1/x_spki.c
+++ b/src/lib/libcrypto/asn1/x_spki.c
@@ -57,7 +57,7 @@
57 */ 57 */
58 58
59 /* This module was send to me my Pat Richards <patr@x509.com> who 59 /* This module was send to me my Pat Richards <patr@x509.com> who
60 * wrote it. It is under my Copyright with his permision 60 * wrote it. It is under my Copyright with his permission
61 */ 61 */
62 62
63#include <stdio.h> 63#include <stdio.h>
@@ -99,7 +99,7 @@ NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void)
99 99
100 M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC); 100 M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC);
101 M_ASN1_New(ret->pubkey,X509_PUBKEY_new); 101 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
102 M_ASN1_New(ret->challenge,ASN1_IA5STRING_new); 102 M_ASN1_New(ret->challenge,M_ASN1_IA5STRING_new);
103 return(ret); 103 return(ret);
104 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW); 104 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW);
105 } 105 }
@@ -108,8 +108,8 @@ void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a)
108 { 108 {
109 if (a == NULL) return; 109 if (a == NULL) return;
110 X509_PUBKEY_free(a->pubkey); 110 X509_PUBKEY_free(a->pubkey);
111 ASN1_IA5STRING_free(a->challenge); 111 M_ASN1_IA5STRING_free(a->challenge);
112 Free((char *)a); 112 Free(a);
113 } 113 }
114 114
115int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a, unsigned char **pp) 115int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a, unsigned char **pp)
@@ -150,7 +150,7 @@ NETSCAPE_SPKI *NETSCAPE_SPKI_new(void)
150 M_ASN1_New_Malloc(ret,NETSCAPE_SPKI); 150 M_ASN1_New_Malloc(ret,NETSCAPE_SPKI);
151 M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new); 151 M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new);
152 M_ASN1_New(ret->sig_algor,X509_ALGOR_new); 152 M_ASN1_New(ret->sig_algor,X509_ALGOR_new);
153 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); 153 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
154 return(ret); 154 return(ret);
155 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW); 155 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW);
156 } 156 }
@@ -160,7 +160,7 @@ void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a)
160 if (a == NULL) return; 160 if (a == NULL) return;
161 NETSCAPE_SPKAC_free(a->spkac); 161 NETSCAPE_SPKAC_free(a->spkac);
162 X509_ALGOR_free(a->sig_algor); 162 X509_ALGOR_free(a->sig_algor);
163 ASN1_BIT_STRING_free(a->signature); 163 M_ASN1_BIT_STRING_free(a->signature);
164 Free((char *)a); 164 Free(a);
165 } 165 }
166 166
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c
index 84d6f7ca4d..1a2f49ffdf 100644
--- a/src/lib/libcrypto/asn1/x_val.c
+++ b/src/lib/libcrypto/asn1/x_val.c
@@ -93,8 +93,8 @@ X509_VAL *X509_VAL_new(void)
93 ASN1_CTX c; 93 ASN1_CTX c;
94 94
95 M_ASN1_New_Malloc(ret,X509_VAL); 95 M_ASN1_New_Malloc(ret,X509_VAL);
96 M_ASN1_New(ret->notBefore,ASN1_TIME_new); 96 M_ASN1_New(ret->notBefore,M_ASN1_TIME_new);
97 M_ASN1_New(ret->notAfter,ASN1_TIME_new); 97 M_ASN1_New(ret->notAfter,M_ASN1_TIME_new);
98 return(ret); 98 return(ret);
99 M_ASN1_New_Error(ASN1_F_X509_VAL_NEW); 99 M_ASN1_New_Error(ASN1_F_X509_VAL_NEW);
100 } 100 }
@@ -102,8 +102,8 @@ X509_VAL *X509_VAL_new(void)
102void X509_VAL_free(X509_VAL *a) 102void X509_VAL_free(X509_VAL *a)
103 { 103 {
104 if (a == NULL) return; 104 if (a == NULL) return;
105 ASN1_TIME_free(a->notBefore); 105 M_ASN1_TIME_free(a->notBefore);
106 ASN1_TIME_free(a->notAfter); 106 M_ASN1_TIME_free(a->notAfter);
107 Free((char *)a); 107 Free(a);
108 } 108 }
109 109
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
index 7abf6b2a6b..11e564ea30 100644
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ b/src/lib/libcrypto/asn1/x_x509.c
@@ -62,6 +62,9 @@
62#include <openssl/asn1_mac.h> 62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65static int x509_meth_num = 0;
66static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_meth = NULL;
67
65static ASN1_METHOD meth={ 68static ASN1_METHOD meth={
66 (int (*)()) i2d_X509, 69 (int (*)()) i2d_X509,
67 (char *(*)())d2i_X509, 70 (char *(*)())d2i_X509,
@@ -113,10 +116,13 @@ X509 *X509_new(void)
113 M_ASN1_New_Malloc(ret,X509); 116 M_ASN1_New_Malloc(ret,X509);
114 ret->references=1; 117 ret->references=1;
115 ret->valid=0; 118 ret->valid=0;
119 ret->ex_flags = 0;
116 ret->name=NULL; 120 ret->name=NULL;
121 ret->aux=NULL;
117 M_ASN1_New(ret->cert_info,X509_CINF_new); 122 M_ASN1_New(ret->cert_info,X509_CINF_new);
118 M_ASN1_New(ret->sig_alg,X509_ALGOR_new); 123 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
119 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); 124 M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new);
125 CRYPTO_new_ex_data(x509_meth, ret, &ret->ex_data);
120 return(ret); 126 return(ret);
121 M_ASN1_New_Error(ASN1_F_X509_NEW); 127 M_ASN1_New_Error(ASN1_F_X509_NEW);
122 } 128 }
@@ -140,12 +146,65 @@ void X509_free(X509 *a)
140 } 146 }
141#endif 147#endif
142 148
143 /* CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); */ 149 CRYPTO_free_ex_data(x509_meth,a,&a->ex_data);
144 X509_CINF_free(a->cert_info); 150 X509_CINF_free(a->cert_info);
145 X509_ALGOR_free(a->sig_alg); 151 X509_ALGOR_free(a->sig_alg);
146 ASN1_BIT_STRING_free(a->signature); 152 M_ASN1_BIT_STRING_free(a->signature);
153 X509_CERT_AUX_free(a->aux);
147 154
148 if (a->name != NULL) Free(a->name); 155 if (a->name != NULL) Free(a->name);
149 Free((char *)a); 156 Free(a);
157 }
158
159int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
160 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
161 {
162 x509_meth_num++;
163 return(CRYPTO_get_ex_new_index(x509_meth_num-1,
164 &x509_meth,argl,argp,new_func,dup_func,free_func));
165 }
166
167int X509_set_ex_data(X509 *r, int idx, void *arg)
168 {
169 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
150 } 170 }
151 171
172void *X509_get_ex_data(X509 *r, int idx)
173 {
174 return(CRYPTO_get_ex_data(&r->ex_data,idx));
175 }
176
177/* X509_AUX ASN1 routines. X509_AUX is the name given to
178 * a certificate with extra info tagged on the end. Since these
179 * functions set how a certificate is trusted they should only
180 * be used when the certificate comes from a reliable source
181 * such as local storage.
182 *
183 */
184
185X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length)
186{
187 unsigned char *q;
188 X509 *ret;
189 /* Save start position */
190 q = *pp;
191 ret = d2i_X509(a, pp, length);
192 /* If certificate unreadable then forget it */
193 if(!ret) return NULL;
194 /* update length */
195 length -= *pp - q;
196 if(!length) return ret;
197 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err;
198 return ret;
199 err:
200 X509_free(ret);
201 return NULL;
202}
203
204int i2d_X509_AUX(X509 *a, unsigned char **pp)
205{
206 int length;
207 length = i2d_X509(a, pp);
208 if(a) length += i2d_X509_CERT_AUX(a->aux, pp);
209 return length;
210}
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
new file mode 100644
index 0000000000..b9987ea968
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_x509a.c
@@ -0,0 +1,200 @@
1/* a_x509a.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65/* X509_CERT_AUX routines. These are used to encode additional
66 * user modifiable data about a certificate. This data is
67 * appended to the X509 encoding when the *_X509_AUX routines
68 * are used. This means that the "traditional" X509 routines
69 * will simply ignore the extra data.
70 */
71
72static X509_CERT_AUX *aux_get(X509 *x);
73
74X509_CERT_AUX *d2i_X509_CERT_AUX(X509_CERT_AUX **a, unsigned char **pp, long length)
75{
76 M_ASN1_D2I_vars(a, X509_CERT_AUX *, X509_CERT_AUX_new);
77
78 M_ASN1_D2I_Init();
79 M_ASN1_D2I_start_sequence();
80
81 M_ASN1_D2I_get_seq_opt_type(ASN1_OBJECT, ret->trust,
82 d2i_ASN1_OBJECT, ASN1_OBJECT_free);
83 M_ASN1_D2I_get_IMP_set_opt_type(ASN1_OBJECT, ret->reject,
84 d2i_ASN1_OBJECT, ASN1_OBJECT_free, 0);
85 M_ASN1_D2I_get_opt(ret->alias, d2i_ASN1_UTF8STRING, V_ASN1_UTF8STRING);
86 M_ASN1_D2I_get_opt(ret->keyid, d2i_ASN1_OCTET_STRING, V_ASN1_OCTET_STRING);
87 M_ASN1_D2I_get_IMP_set_opt_type(X509_ALGOR, ret->other,
88 d2i_X509_ALGOR, X509_ALGOR_free, 1);
89
90 M_ASN1_D2I_Finish(a, X509_CERT_AUX_free, ASN1_F_D2I_X509_CERT_AUX);
91}
92
93X509_CERT_AUX *X509_CERT_AUX_new()
94{
95 X509_CERT_AUX *ret = NULL;
96 ASN1_CTX c;
97 M_ASN1_New_Malloc(ret, X509_CERT_AUX);
98 ret->trust = NULL;
99 ret->reject = NULL;
100 ret->alias = NULL;
101 ret->keyid = NULL;
102 ret->other = NULL;
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_CERT_AUX_NEW);
105}
106
107void X509_CERT_AUX_free(X509_CERT_AUX *a)
108{
109 if(a == NULL) return;
110 sk_ASN1_OBJECT_pop_free(a->trust, ASN1_OBJECT_free);
111 sk_ASN1_OBJECT_pop_free(a->reject, ASN1_OBJECT_free);
112 ASN1_UTF8STRING_free(a->alias);
113 ASN1_OCTET_STRING_free(a->keyid);
114 sk_X509_ALGOR_pop_free(a->other, X509_ALGOR_free);
115 Free(a);
116}
117
118int i2d_X509_CERT_AUX(X509_CERT_AUX *a, unsigned char **pp)
119{
120 M_ASN1_I2D_vars(a);
121
122 M_ASN1_I2D_len_SEQUENCE_opt_type(ASN1_OBJECT, a->trust, i2d_ASN1_OBJECT);
123 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->reject, i2d_ASN1_OBJECT, 0);
124
125 M_ASN1_I2D_len(a->alias, i2d_ASN1_UTF8STRING);
126 M_ASN1_I2D_len(a->keyid, i2d_ASN1_OCTET_STRING);
127 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(X509_ALGOR, a->other, i2d_X509_ALGOR, 1);
128
129 M_ASN1_I2D_seq_total();
130
131 M_ASN1_I2D_put_SEQUENCE_opt_type(ASN1_OBJECT, a->trust, i2d_ASN1_OBJECT);
132 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(ASN1_OBJECT, a->reject, i2d_ASN1_OBJECT, 0);
133
134 M_ASN1_I2D_put(a->alias, i2d_ASN1_UTF8STRING);
135 M_ASN1_I2D_put(a->keyid, i2d_ASN1_OCTET_STRING);
136 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(X509_ALGOR, a->other, i2d_X509_ALGOR, 1);
137
138 M_ASN1_I2D_finish();
139}
140
141static X509_CERT_AUX *aux_get(X509 *x)
142{
143 if(!x) return NULL;
144 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL;
145 return x->aux;
146}
147
148int X509_alias_set1(X509 *x, unsigned char *name, int len)
149{
150 X509_CERT_AUX *aux;
151 if(!(aux = aux_get(x))) return 0;
152 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
153 return ASN1_STRING_set(aux->alias, name, len);
154}
155
156unsigned char *X509_alias_get0(X509 *x, int *len)
157{
158 if(!x->aux || !x->aux->alias) return NULL;
159 if(len) *len = x->aux->alias->length;
160 return x->aux->alias->data;
161}
162
163int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
164{
165 X509_CERT_AUX *aux;
166 ASN1_OBJECT *objtmp;
167 if(!(objtmp = OBJ_dup(obj))) return 0;
168 if(!(aux = aux_get(x))) return 0;
169 if(!aux->trust
170 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0;
171 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
172}
173
174int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
175{
176 X509_CERT_AUX *aux;
177 ASN1_OBJECT *objtmp;
178 if(!(objtmp = OBJ_dup(obj))) return 0;
179 if(!(aux = aux_get(x))) return 0;
180 if(!aux->reject
181 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0;
182 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
183}
184
185void X509_trust_clear(X509 *x)
186{
187 if(x->aux && x->aux->trust) {
188 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
189 x->aux->trust = NULL;
190 }
191}
192
193void X509_reject_clear(X509 *x)
194{
195 if(x->aux && x->aux->reject) {
196 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
197 x->aux->reject = NULL;
198 }
199}
200
diff --git a/src/lib/libcrypto/bf/bf_cbc.c b/src/lib/libcrypto/bf/bf_cbc.c
index 95d1cdcdf9..f949629dc6 100644
--- a/src/lib/libcrypto/bf/bf_cbc.c
+++ b/src/lib/libcrypto/bf/bf_cbc.c
@@ -59,8 +59,8 @@
59#include <openssl/blowfish.h> 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61 61
62void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, 62void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63 BF_KEY *ks, unsigned char *iv, int encrypt) 63 const BF_KEY *schedule, unsigned char *ivec, int encrypt)
64 { 64 {
65 register BF_LONG tin0,tin1; 65 register BF_LONG tin0,tin1;
66 register BF_LONG tout0,tout1,xor0,xor1; 66 register BF_LONG tout0,tout1,xor0,xor1;
@@ -69,9 +69,9 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
69 69
70 if (encrypt) 70 if (encrypt)
71 { 71 {
72 n2l(iv,tout0); 72 n2l(ivec,tout0);
73 n2l(iv,tout1); 73 n2l(ivec,tout1);
74 iv-=8; 74 ivec-=8;
75 for (l-=8; l>=0; l-=8) 75 for (l-=8; l>=0; l-=8)
76 { 76 {
77 n2l(in,tin0); 77 n2l(in,tin0);
@@ -80,7 +80,7 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
80 tin1^=tout1; 80 tin1^=tout1;
81 tin[0]=tin0; 81 tin[0]=tin0;
82 tin[1]=tin1; 82 tin[1]=tin1;
83 BF_encrypt(tin,ks); 83 BF_encrypt(tin,schedule);
84 tout0=tin[0]; 84 tout0=tin[0];
85 tout1=tin[1]; 85 tout1=tin[1];
86 l2n(tout0,out); 86 l2n(tout0,out);
@@ -93,27 +93,27 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
93 tin1^=tout1; 93 tin1^=tout1;
94 tin[0]=tin0; 94 tin[0]=tin0;
95 tin[1]=tin1; 95 tin[1]=tin1;
96 BF_encrypt(tin,ks); 96 BF_encrypt(tin,schedule);
97 tout0=tin[0]; 97 tout0=tin[0];
98 tout1=tin[1]; 98 tout1=tin[1];
99 l2n(tout0,out); 99 l2n(tout0,out);
100 l2n(tout1,out); 100 l2n(tout1,out);
101 } 101 }
102 l2n(tout0,iv); 102 l2n(tout0,ivec);
103 l2n(tout1,iv); 103 l2n(tout1,ivec);
104 } 104 }
105 else 105 else
106 { 106 {
107 n2l(iv,xor0); 107 n2l(ivec,xor0);
108 n2l(iv,xor1); 108 n2l(ivec,xor1);
109 iv-=8; 109 ivec-=8;
110 for (l-=8; l>=0; l-=8) 110 for (l-=8; l>=0; l-=8)
111 { 111 {
112 n2l(in,tin0); 112 n2l(in,tin0);
113 n2l(in,tin1); 113 n2l(in,tin1);
114 tin[0]=tin0; 114 tin[0]=tin0;
115 tin[1]=tin1; 115 tin[1]=tin1;
116 BF_decrypt(tin,ks); 116 BF_decrypt(tin,schedule);
117 tout0=tin[0]^xor0; 117 tout0=tin[0]^xor0;
118 tout1=tin[1]^xor1; 118 tout1=tin[1]^xor1;
119 l2n(tout0,out); 119 l2n(tout0,out);
@@ -127,15 +127,15 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
127 n2l(in,tin1); 127 n2l(in,tin1);
128 tin[0]=tin0; 128 tin[0]=tin0;
129 tin[1]=tin1; 129 tin[1]=tin1;
130 BF_decrypt(tin,ks); 130 BF_decrypt(tin,schedule);
131 tout0=tin[0]^xor0; 131 tout0=tin[0]^xor0;
132 tout1=tin[1]^xor1; 132 tout1=tin[1]^xor1;
133 l2nn(tout0,tout1,out,l+8); 133 l2nn(tout0,tout1,out,l+8);
134 xor0=tin0; 134 xor0=tin0;
135 xor1=tin1; 135 xor1=tin1;
136 } 136 }
137 l2n(xor0,iv); 137 l2n(xor0,ivec);
138 l2n(xor1,iv); 138 l2n(xor1,ivec);
139 } 139 }
140 tin0=tin1=tout0=tout1=xor0=xor1=0; 140 tin0=tin1=tout0=tout1=xor0=xor1=0;
141 tin[0]=tin[1]=0; 141 tin[0]=tin[1]=0;
diff --git a/src/lib/libcrypto/bf/bf_cfb64.c b/src/lib/libcrypto/bf/bf_cfb64.c
index 1fb8905f49..6451c8d407 100644
--- a/src/lib/libcrypto/bf/bf_cfb64.c
+++ b/src/lib/libcrypto/bf/bf_cfb64.c
@@ -64,8 +64,8 @@
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66 66
67void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, 67void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
68 BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt) 68 const BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt)
69 { 69 {
70 register BF_LONG v0,v1,t; 70 register BF_LONG v0,v1,t;
71 register int n= *num; 71 register int n= *num;
diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c
index 9f8a24cdff..341991636f 100644
--- a/src/lib/libcrypto/bf/bf_ecb.c
+++ b/src/lib/libcrypto/bf/bf_ecb.c
@@ -61,11 +61,11 @@
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' 63/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
64 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, 64 * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
65 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) 65 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
66 */ 66 */
67 67
68const char *BF_version="BlowFish" OPENSSL_VERSION_PTEXT; 68const char *BF_version="Blowfish" OPENSSL_VERSION_PTEXT;
69 69
70const char *BF_options(void) 70const char *BF_options(void)
71 { 71 {
@@ -78,17 +78,17 @@ const char *BF_options(void)
78#endif 78#endif
79 } 79 }
80 80
81void BF_ecb_encrypt(unsigned char *in, unsigned char *out, BF_KEY *ks, 81void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
82 int encrypt) 82 const BF_KEY *key, int encrypt)
83 { 83 {
84 BF_LONG l,d[2]; 84 BF_LONG l,d[2];
85 85
86 n2l(in,l); d[0]=l; 86 n2l(in,l); d[0]=l;
87 n2l(in,l); d[1]=l; 87 n2l(in,l); d[1]=l;
88 if (encrypt) 88 if (encrypt)
89 BF_encrypt(d,ks); 89 BF_encrypt(d,key);
90 else 90 else
91 BF_decrypt(d,ks); 91 BF_decrypt(d,key);
92 l=d[0]; l2n(l,out); 92 l=d[0]; l2n(l,out);
93 l=d[1]; l2n(l,out); 93 l=d[1]; l2n(l,out);
94 l=d[0]=d[1]=0; 94 l=d[0]=d[1]=0;
diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c
index ee01834561..b380acf959 100644
--- a/src/lib/libcrypto/bf/bf_enc.c
+++ b/src/lib/libcrypto/bf/bf_enc.c
@@ -60,7 +60,7 @@
60#include "bf_locl.h" 60#include "bf_locl.h"
61 61
62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' 62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
63 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, 63 * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) 64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
65 */ 65 */
66 66
@@ -69,10 +69,11 @@
69to modify the code. 69to modify the code.
70#endif 70#endif
71 71
72void BF_encrypt(BF_LONG *data, BF_KEY *key) 72void BF_encrypt(BF_LONG *data, const BF_KEY *key)
73 { 73 {
74#ifndef BF_PTR2 74#ifndef BF_PTR2
75 register BF_LONG l,r,*p,*s; 75 register BF_LONG l,r;
76 const register BF_LONG *p,*s;
76 77
77 p=key->P; 78 p=key->P;
78 s= &(key->S[0]); 79 s= &(key->S[0]);
@@ -145,10 +146,11 @@ void BF_encrypt(BF_LONG *data, BF_KEY *key)
145 146
146#ifndef BF_DEFAULT_OPTIONS 147#ifndef BF_DEFAULT_OPTIONS
147 148
148void BF_decrypt(BF_LONG *data, BF_KEY *key) 149void BF_decrypt(BF_LONG *data, const BF_KEY *key)
149 { 150 {
150#ifndef BF_PTR2 151#ifndef BF_PTR2
151 register BF_LONG l,r,*p,*s; 152 register BF_LONG l,r;
153 const register BF_LONG *p,*s;
152 154
153 p=key->P; 155 p=key->P;
154 s= &(key->S[0]); 156 s= &(key->S[0]);
@@ -219,8 +221,8 @@ void BF_decrypt(BF_LONG *data, BF_KEY *key)
219#endif 221#endif
220 } 222 }
221 223
222void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, 224void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
223 BF_KEY *ks, unsigned char *iv, int encrypt) 225 const BF_KEY *schedule, unsigned char *ivec, int encrypt)
224 { 226 {
225 register BF_LONG tin0,tin1; 227 register BF_LONG tin0,tin1;
226 register BF_LONG tout0,tout1,xor0,xor1; 228 register BF_LONG tout0,tout1,xor0,xor1;
@@ -229,9 +231,9 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
229 231
230 if (encrypt) 232 if (encrypt)
231 { 233 {
232 n2l(iv,tout0); 234 n2l(ivec,tout0);
233 n2l(iv,tout1); 235 n2l(ivec,tout1);
234 iv-=8; 236 ivec-=8;
235 for (l-=8; l>=0; l-=8) 237 for (l-=8; l>=0; l-=8)
236 { 238 {
237 n2l(in,tin0); 239 n2l(in,tin0);
@@ -240,7 +242,7 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
240 tin1^=tout1; 242 tin1^=tout1;
241 tin[0]=tin0; 243 tin[0]=tin0;
242 tin[1]=tin1; 244 tin[1]=tin1;
243 BF_encrypt(tin,ks); 245 BF_encrypt(tin,schedule);
244 tout0=tin[0]; 246 tout0=tin[0];
245 tout1=tin[1]; 247 tout1=tin[1];
246 l2n(tout0,out); 248 l2n(tout0,out);
@@ -253,27 +255,27 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
253 tin1^=tout1; 255 tin1^=tout1;
254 tin[0]=tin0; 256 tin[0]=tin0;
255 tin[1]=tin1; 257 tin[1]=tin1;
256 BF_encrypt(tin,ks); 258 BF_encrypt(tin,schedule);
257 tout0=tin[0]; 259 tout0=tin[0];
258 tout1=tin[1]; 260 tout1=tin[1];
259 l2n(tout0,out); 261 l2n(tout0,out);
260 l2n(tout1,out); 262 l2n(tout1,out);
261 } 263 }
262 l2n(tout0,iv); 264 l2n(tout0,ivec);
263 l2n(tout1,iv); 265 l2n(tout1,ivec);
264 } 266 }
265 else 267 else
266 { 268 {
267 n2l(iv,xor0); 269 n2l(ivec,xor0);
268 n2l(iv,xor1); 270 n2l(ivec,xor1);
269 iv-=8; 271 ivec-=8;
270 for (l-=8; l>=0; l-=8) 272 for (l-=8; l>=0; l-=8)
271 { 273 {
272 n2l(in,tin0); 274 n2l(in,tin0);
273 n2l(in,tin1); 275 n2l(in,tin1);
274 tin[0]=tin0; 276 tin[0]=tin0;
275 tin[1]=tin1; 277 tin[1]=tin1;
276 BF_decrypt(tin,ks); 278 BF_decrypt(tin,schedule);
277 tout0=tin[0]^xor0; 279 tout0=tin[0]^xor0;
278 tout1=tin[1]^xor1; 280 tout1=tin[1]^xor1;
279 l2n(tout0,out); 281 l2n(tout0,out);
@@ -287,15 +289,15 @@ void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
287 n2l(in,tin1); 289 n2l(in,tin1);
288 tin[0]=tin0; 290 tin[0]=tin0;
289 tin[1]=tin1; 291 tin[1]=tin1;
290 BF_decrypt(tin,ks); 292 BF_decrypt(tin,schedule);
291 tout0=tin[0]^xor0; 293 tout0=tin[0]^xor0;
292 tout1=tin[1]^xor1; 294 tout1=tin[1]^xor1;
293 l2nn(tout0,tout1,out,l+8); 295 l2nn(tout0,tout1,out,l+8);
294 xor0=tin0; 296 xor0=tin0;
295 xor1=tin1; 297 xor1=tin1;
296 } 298 }
297 l2n(xor0,iv); 299 l2n(xor0,ivec);
298 l2n(xor1,iv); 300 l2n(xor1,ivec);
299 } 301 }
300 tin0=tin1=tout0=tout1=xor0=xor1=0; 302 tin0=tin1=tout0=tout1=xor0=xor1=0;
301 tin[0]=tin[1]=0; 303 tin[0]=tin[1]=0;
diff --git a/src/lib/libcrypto/bf/bf_locl.h b/src/lib/libcrypto/bf/bf_locl.h
index 05756b5d3b..cc7c3ec992 100644
--- a/src/lib/libcrypto/bf/bf_locl.h
+++ b/src/lib/libcrypto/bf/bf_locl.h
@@ -148,7 +148,7 @@
148 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 148 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
149 *((c)++)=(unsigned char)(((l) )&0xff)) 149 *((c)++)=(unsigned char)(((l) )&0xff))
150 150
151/* This is actually a big endian algorithm, the most significate byte 151/* This is actually a big endian algorithm, the most significant byte
152 * is used to lookup array 0 */ 152 * is used to lookup array 0 */
153 153
154#if defined(BF_PTR2) 154#if defined(BF_PTR2)
@@ -183,8 +183,8 @@
183 183
184/* 184/*
185 * This is normally very good on RISC platforms where normally you 185 * This is normally very good on RISC platforms where normally you
186 * have to explicitely "multiplicate" array index by sizeof(BF_LONG) 186 * have to explicitly "multiply" array index by sizeof(BF_LONG)
187 * in order to caclulate the effective address. This implementation 187 * in order to calculate the effective address. This implementation
188 * excuses CPU from this extra work. Power[PC] uses should have most 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 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. 190 * rlwinm. So let'em double-check if their compiler does it.
diff --git a/src/lib/libcrypto/bf/bf_ofb64.c b/src/lib/libcrypto/bf/bf_ofb64.c
index 8ceb8d9bda..f2a9ff6e41 100644
--- a/src/lib/libcrypto/bf/bf_ofb64.c
+++ b/src/lib/libcrypto/bf/bf_ofb64.c
@@ -63,8 +63,8 @@
63 * used. The extra state information to record how much of the 63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, 66void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
67 BF_KEY *schedule, unsigned char *ivec, int *num) 67 const BF_KEY *schedule, unsigned char *ivec, int *num)
68 { 68 {
69 register BF_LONG v0,v1,t; 69 register BF_LONG v0,v1,t;
70 register int n= *num; 70 register int n= *num;
diff --git a/src/lib/libcrypto/bf/bf_opts.c b/src/lib/libcrypto/bf/bf_opts.c
index 5f330cc53c..bbe32b28c9 100644
--- a/src/lib/libcrypto/bf/bf_opts.c
+++ b/src/lib/libcrypto/bf/bf_opts.c
@@ -242,7 +242,7 @@ int main(int argc, char **argv)
242 } 242 }
243 243
244#ifndef TIMES 244#ifndef TIMES
245 fprintf(stderr,"To get the most acurate results, try to run this\n"); 245 fprintf(stderr,"To get the most accurate results, try to run this\n");
246 fprintf(stderr,"program when this computer is idle.\n"); 246 fprintf(stderr,"program when this computer is idle.\n");
247#endif 247#endif
248 248
diff --git a/src/lib/libcrypto/bf/bf_pi.h b/src/lib/libcrypto/bf/bf_pi.h
index 417b935538..9949513c68 100644
--- a/src/lib/libcrypto/bf/bf_pi.h
+++ b/src/lib/libcrypto/bf/bf_pi.h
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59static BF_KEY bf_init= { 59static const BF_KEY bf_init= {
60 { 60 {
61 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L, 61 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L,
62 0xa4093822L, 0x299f31d0L, 0x082efa98L, 0xec4e6c89L, 62 0xa4093822L, 0x299f31d0L, 0x082efa98L, 0xec4e6c89L,
diff --git a/src/lib/libcrypto/bf/bf_skey.c b/src/lib/libcrypto/bf/bf_skey.c
index eefa8e6f51..4d6a232fe0 100644
--- a/src/lib/libcrypto/bf/bf_skey.c
+++ b/src/lib/libcrypto/bf/bf_skey.c
@@ -62,11 +62,11 @@
62#include "bf_locl.h" 62#include "bf_locl.h"
63#include "bf_pi.h" 63#include "bf_pi.h"
64 64
65void BF_set_key(BF_KEY *key, int len, unsigned char *data) 65void BF_set_key(BF_KEY *key, int len, const unsigned char *data)
66 { 66 {
67 int i; 67 int i;
68 BF_LONG *p,ri,in[2]; 68 BF_LONG *p,ri,in[2];
69 unsigned char *d,*end; 69 const unsigned char *d,*end;
70 70
71 71
72 memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY)); 72 memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY));
diff --git a/src/lib/libcrypto/bf/bfspeed.c b/src/lib/libcrypto/bf/bfspeed.c
index 9b893e92cc..ecc9dff4e4 100644
--- a/src/lib/libcrypto/bf/bfspeed.c
+++ b/src/lib/libcrypto/bf/bfspeed.c
@@ -183,7 +183,7 @@ int main(int argc, char **argv)
183#endif 183#endif
184 184
185#ifndef TIMES 185#ifndef TIMES
186 printf("To get the most acurate results, try to run this\n"); 186 printf("To get the most accurate results, try to run this\n");
187 printf("program when this computer is idle.\n"); 187 printf("program when this computer is idle.\n");
188#endif 188#endif
189 189
diff --git a/src/lib/libcrypto/bf/bftest.c b/src/lib/libcrypto/bf/bftest.c
index 6ecd2609a9..5695250195 100644
--- a/src/lib/libcrypto/bf/bftest.c
+++ b/src/lib/libcrypto/bf/bftest.c
@@ -76,18 +76,18 @@ int main(int argc, char *argv[])
76#include <openssl/ebcdic.h> 76#include <openssl/ebcdic.h>
77#endif 77#endif
78 78
79char *bf_key[2]={ 79static char *bf_key[2]={
80 "abcdefghijklmnopqrstuvwxyz", 80 "abcdefghijklmnopqrstuvwxyz",
81 "Who is John Galt?" 81 "Who is John Galt?"
82 }; 82 };
83 83
84/* big endian */ 84/* big endian */
85BF_LONG bf_plain[2][2]={ 85static BF_LONG bf_plain[2][2]={
86 {0x424c4f57L,0x46495348L}, 86 {0x424c4f57L,0x46495348L},
87 {0xfedcba98L,0x76543210L} 87 {0xfedcba98L,0x76543210L}
88 }; 88 };
89 89
90BF_LONG bf_cipher[2][2]={ 90static BF_LONG bf_cipher[2][2]={
91 {0x324ed0feL,0xf413a203L}, 91 {0x324ed0feL,0xf413a203L},
92 {0xcc91732bL,0x8022f684L} 92 {0xcc91732bL,0x8022f684L}
93 }; 93 };
@@ -228,16 +228,16 @@ static unsigned char ofb64_ok[]={
228 0x63,0xC2,0xCF,0x80,0xDA}; 228 0x63,0xC2,0xCF,0x80,0xDA};
229 229
230#define KEY_TEST_NUM 25 230#define KEY_TEST_NUM 25
231unsigned char key_test[KEY_TEST_NUM]={ 231static unsigned char key_test[KEY_TEST_NUM]={
232 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87, 232 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87,
233 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f, 233 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f,
234 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, 234 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
235 0x88}; 235 0x88};
236 236
237unsigned char key_data[8]= 237static unsigned char key_data[8]=
238 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}; 238 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
239 239
240unsigned char key_out[KEY_TEST_NUM][8]={ 240static unsigned char key_out[KEY_TEST_NUM][8]={
241 {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E}, 241 {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E},
242 {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6}, 242 {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6},
243 {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3}, 243 {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3},
diff --git a/src/lib/libcrypto/bf/blowfish.h b/src/lib/libcrypto/bf/blowfish.h
index 02f73b2f30..78acfd63b4 100644
--- a/src/lib/libcrypto/bf/blowfish.h
+++ b/src/lib/libcrypto/bf/blowfish.h
@@ -103,17 +103,19 @@ typedef struct bf_key_st
103 } BF_KEY; 103 } BF_KEY;
104 104
105 105
106void BF_set_key(BF_KEY *key, int len, unsigned char *data); 106void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
107void BF_ecb_encrypt(unsigned char *in,unsigned char *out,BF_KEY *key, 107
108 int enc); 108void BF_encrypt(BF_LONG *data,const BF_KEY *key);
109void BF_encrypt(BF_LONG *data,BF_KEY *key); 109void BF_decrypt(BF_LONG *data,const BF_KEY *key);
110void BF_decrypt(BF_LONG *data,BF_KEY *key); 110
111void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, 111void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
112 BF_KEY *ks, unsigned char *iv, int enc); 112 const BF_KEY *key, int enc);
113void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, 113void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
114 BF_KEY *schedule, unsigned char *ivec, int *num, int enc); 114 const BF_KEY *schedule, unsigned char *ivec, int enc);
115void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, 115void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
116 BF_KEY *schedule, unsigned char *ivec, int *num); 116 const BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
117void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
118 const BF_KEY *schedule, unsigned char *ivec, int *num);
117const char *BF_options(void); 119const char *BF_options(void);
118 120
119#ifdef __cplusplus 121#ifdef __cplusplus
diff --git a/src/lib/libcrypto/bio/Makefile.ssl b/src/lib/libcrypto/bio/Makefile.ssl
index d9c381d263..2e7480ead9 100644
--- a/src/lib/libcrypto/bio/Makefile.ssl
+++ b/src/lib/libcrypto/bio/Makefile.ssl
@@ -90,17 +90,20 @@ b_dump.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
90b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 90b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
91b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 91b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
92b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 92b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
93b_dump.o: ../../include/openssl/stack.h ../cryptlib.h 93b_dump.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
94b_dump.o: ../cryptlib.h
94b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 95b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
95b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 96b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
96b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 97b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
97b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 98b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
98b_print.o: ../../include/openssl/stack.h ../cryptlib.h 99b_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
100b_print.o: ../cryptlib.h
99b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 101b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
100b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 102b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
101b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 103b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
102b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 104b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
103b_sock.o: ../../include/openssl/stack.h ../cryptlib.h 105b_sock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
106b_sock.o: ../cryptlib.h
104bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 107bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
105bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 108bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
106bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 109bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -151,60 +154,65 @@ bio_cb.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
151bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 154bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
152bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 155bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
153bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 156bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
154bio_cb.o: ../../include/openssl/stack.h ../cryptlib.h 157bio_cb.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
158bio_cb.o: ../cryptlib.h
155bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h 159bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
156bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h 160bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h
157bio_err.o: ../../include/openssl/stack.h 161bio_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
158bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 162bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
159bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 163bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
160bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 164bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
161bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 165bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
162bio_lib.o: ../../include/openssl/stack.h ../cryptlib.h 166bio_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
167bio_lib.o: ../cryptlib.h
163bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 168bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
164bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 169bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
165bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 170bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
166bss_acpt.o: ../../include/openssl/opensslconf.h 171bss_acpt.o: ../../include/openssl/opensslconf.h
167bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 172bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
168bss_acpt.o: ../cryptlib.h 173bss_acpt.o: ../../include/openssl/stack.h ../cryptlib.h
169bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h 174bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
170bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h 175bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h
171bss_bio.o: ../../include/openssl/stack.h 176bss_bio.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
172bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 177bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
173bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 178bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
174bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 179bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
175bss_conn.o: ../../include/openssl/opensslconf.h 180bss_conn.o: ../../include/openssl/opensslconf.h
176bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 181bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
177bss_conn.o: ../cryptlib.h 182bss_conn.o: ../../include/openssl/stack.h ../cryptlib.h
178bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 183bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
179bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 184bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
180bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 185bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
181bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 186bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
182bss_fd.o: ../../include/openssl/stack.h ../cryptlib.h bss_sock.c 187bss_fd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
188bss_fd.o: ../cryptlib.h bss_sock.c
183bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 189bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
184bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 190bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
185bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 191bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
186bss_file.o: ../../include/openssl/opensslconf.h 192bss_file.o: ../../include/openssl/opensslconf.h
187bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 193bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
188bss_file.o: ../cryptlib.h 194bss_file.o: ../../include/openssl/stack.h ../cryptlib.h
189bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 195bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
190bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 196bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
191bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 197bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
192bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 198bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
193bss_log.o: ../../include/openssl/stack.h ../cryptlib.h 199bss_log.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
200bss_log.o: ../cryptlib.h
194bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 201bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
195bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 202bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
196bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 203bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
197bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 204bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
198bss_mem.o: ../../include/openssl/stack.h ../cryptlib.h 205bss_mem.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
206bss_mem.o: ../cryptlib.h
199bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 207bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
200bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 208bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
201bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 209bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
202bss_null.o: ../../include/openssl/opensslconf.h 210bss_null.o: ../../include/openssl/opensslconf.h
203bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 211bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
204bss_null.o: ../cryptlib.h 212bss_null.o: ../../include/openssl/stack.h ../cryptlib.h
205bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 213bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
206bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 214bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
207bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 215bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
208bss_sock.o: ../../include/openssl/opensslconf.h 216bss_sock.o: ../../include/openssl/opensslconf.h
209bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 217bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
210bss_sock.o: ../cryptlib.h 218bss_sock.o: ../../include/openssl/stack.h ../cryptlib.h
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
index a7cd828978..f5aeb237f5 100644
--- a/src/lib/libcrypto/bio/b_dump.c
+++ b/src/lib/libcrypto/bio/b_dump.c
@@ -92,7 +92,7 @@ int BIO_dump(BIO *bio, const char *s, int len)
92 if (((i*DUMP_WIDTH)+j)>=len) { 92 if (((i*DUMP_WIDTH)+j)>=len) {
93 strcat(buf," "); 93 strcat(buf," ");
94 } else { 94 } else {
95 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; 95 ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff;
96 sprintf(tmp,"%02x%c",ch,j==7?'-':' '); 96 sprintf(tmp,"%02x%c",ch,j==7?'-':' ');
97 strcat(buf,tmp); 97 strcat(buf,tmp);
98 } 98 }
@@ -101,7 +101,7 @@ int BIO_dump(BIO *bio, const char *s, int len)
101 for(j=0;j<DUMP_WIDTH;j++) { 101 for(j=0;j<DUMP_WIDTH;j++) {
102 if (((i*DUMP_WIDTH)+j)>=len) 102 if (((i*DUMP_WIDTH)+j)>=len)
103 break; 103 break;
104 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; 104 ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff;
105#ifndef CHARSET_EBCDIC 105#ifndef CHARSET_EBCDIC
106 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); 106 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
107#else 107#else
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
index f448004298..2a5e8b58c9 100644
--- a/src/lib/libcrypto/bio/b_print.c
+++ b/src/lib/libcrypto/bio/b_print.c
@@ -62,26 +62,649 @@
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include <stdarg.h> 64#include <stdarg.h>
65#include <string.h>
66#include <ctype.h>
65#include "cryptlib.h" 67#include "cryptlib.h"
68#ifndef NO_SYS_TYPES_H
69#include <sys/types.h>
70#endif
66#include <openssl/bio.h> 71#include <openssl/bio.h>
67 72
73#ifdef BN_LLONG
74# ifndef HAVE_LONG_LONG
75# define HAVE_LONG_LONG
76# endif
77#endif
78
79static void dopr (char *buffer, size_t maxlen, size_t *retlen,
80 const char *format, va_list args);
81
68int BIO_printf (BIO *bio, ...) 82int BIO_printf (BIO *bio, ...)
69 { 83 {
70 va_list args; 84 va_list args;
71 char *format; 85 char *format;
72 int ret; 86 int ret;
87 size_t retlen;
73 MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */ 88 MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */
74 89
75 va_start(args, bio); 90 va_start(args, bio);
76 format=va_arg(args, char *); 91 format=va_arg(args, char *);
77 92
78 hugebuf[0]='\0'; 93 hugebuf[0]='\0';
79 94 dopr(hugebuf, sizeof(hugebuf), &retlen, format, args);
80 vsprintf(hugebuf,format,args); 95 ret=BIO_write(bio, hugebuf, (int)retlen);
81
82 ret=BIO_write(bio,hugebuf,strlen(hugebuf));
83 96
84 va_end(args); 97 va_end(args);
85 return(ret); 98 return(ret);
86 } 99 }
87 100
101/*
102 * Copyright Patrick Powell 1995
103 * This code is based on code written by Patrick Powell <papowell@astart.com>
104 * It may be used for any purpose as long as this notice remains intact
105 * on all source code distributions.
106 */
107
108/*
109 * This code contains numerious changes and enhancements which were
110 * made by lots of contributors over the last years to Patrick Powell's
111 * original code:
112 *
113 * o Patrick Powell <papowell@astart.com> (1995)
114 * o Brandon Long <blong@fiction.net> (1996, for Mutt)
115 * o Thomas Roessler <roessler@guug.de> (1998, for Mutt)
116 * o Michael Elkins <me@cs.hmc.edu> (1998, for Mutt)
117 * o Andrew Tridgell <tridge@samba.org> (1998, for Samba)
118 * o Luke Mewburn <lukem@netbsd.org> (1999, for LukemFTP)
119 * o Ralf S. Engelschall <rse@engelschall.com> (1999, for Pth)
120 */
121
122#if HAVE_LONG_DOUBLE
123#define LDOUBLE long double
124#else
125#define LDOUBLE double
126#endif
127
128#if HAVE_LONG_LONG
129#define LLONG long long
130#else
131#define LLONG long
132#endif
133
134static void fmtstr (char *, size_t *, size_t, char *, int, int, int);
135static void fmtint (char *, size_t *, size_t, LLONG, int, int, int, int);
136static void fmtfp (char *, size_t *, size_t, LDOUBLE, int, int, int);
137static void dopr_outch (char *, size_t *, size_t, int);
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 MAX(p,q) ((p >= q) ? p : q)
167
168static void
169dopr(
170 char *buffer,
171 size_t maxlen,
172 size_t *retlen,
173 const char *format,
174 va_list args)
175{
176 char ch;
177 LLONG value;
178 LDOUBLE fvalue;
179 char *strvalue;
180 int min;
181 int max;
182 int state;
183 int flags;
184 int cflags;
185 size_t currlen;
186
187 state = DP_S_DEFAULT;
188 flags = currlen = cflags = min = 0;
189 max = -1;
190 ch = *format++;
191
192 while (state != DP_S_DONE) {
193 if ((ch == '\0') || (currlen >= maxlen))
194 state = DP_S_DONE;
195
196 switch (state) {
197 case DP_S_DEFAULT:
198 if (ch == '%')
199 state = DP_S_FLAGS;
200 else
201 dopr_outch(buffer, &currlen, maxlen, ch);
202 ch = *format++;
203 break;
204 case DP_S_FLAGS:
205 switch (ch) {
206 case '-':
207 flags |= DP_F_MINUS;
208 ch = *format++;
209 break;
210 case '+':
211 flags |= DP_F_PLUS;
212 ch = *format++;
213 break;
214 case ' ':
215 flags |= DP_F_SPACE;
216 ch = *format++;
217 break;
218 case '#':
219 flags |= DP_F_NUM;
220 ch = *format++;
221 break;
222 case '0':
223 flags |= DP_F_ZERO;
224 ch = *format++;
225 break;
226 default:
227 state = DP_S_MIN;
228 break;
229 }
230 break;
231 case DP_S_MIN:
232 if (isdigit((unsigned char)ch)) {
233 min = 10 * min + char_to_int(ch);
234 ch = *format++;
235 } else if (ch == '*') {
236 min = va_arg(args, int);
237 ch = *format++;
238 state = DP_S_DOT;
239 } else
240 state = DP_S_DOT;
241 break;
242 case DP_S_DOT:
243 if (ch == '.') {
244 state = DP_S_MAX;
245 ch = *format++;
246 } else
247 state = DP_S_MOD;
248 break;
249 case DP_S_MAX:
250 if (isdigit((unsigned char)ch)) {
251 if (max < 0)
252 max = 0;
253 max = 10 * max + char_to_int(ch);
254 ch = *format++;
255 } else if (ch == '*') {
256 max = va_arg(args, int);
257 ch = *format++;
258 state = DP_S_MOD;
259 } else
260 state = DP_S_MOD;
261 break;
262 case DP_S_MOD:
263 switch (ch) {
264 case 'h':
265 cflags = DP_C_SHORT;
266 ch = *format++;
267 break;
268 case 'l':
269 if (*format == 'l') {
270 cflags = DP_C_LLONG;
271 format++;
272 } else
273 cflags = DP_C_LONG;
274 ch = *format++;
275 break;
276 case 'q':
277 cflags = DP_C_LLONG;
278 ch = *format++;
279 break;
280 case 'L':
281 cflags = DP_C_LDOUBLE;
282 ch = *format++;
283 break;
284 default:
285 break;
286 }
287 state = DP_S_CONV;
288 break;
289 case DP_S_CONV:
290 switch (ch) {
291 case 'd':
292 case 'i':
293 switch (cflags) {
294 case DP_C_SHORT:
295 value = (short int)va_arg(args, int);
296 break;
297 case DP_C_LONG:
298 value = va_arg(args, long int);
299 break;
300 case DP_C_LLONG:
301 value = va_arg(args, LLONG);
302 break;
303 default:
304 value = va_arg(args, int);
305 break;
306 }
307 fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
308 break;
309 case 'X':
310 flags |= DP_F_UP;
311 /* FALLTHROUGH */
312 case 'x':
313 case 'o':
314 case 'u':
315 flags |= DP_F_UNSIGNED;
316 switch (cflags) {
317 case DP_C_SHORT:
318 value = (unsigned short int)va_arg(args, unsigned int);
319 break;
320 case DP_C_LONG:
321 value = (LLONG) va_arg(args,
322 unsigned long int);
323 break;
324 case DP_C_LLONG:
325 value = va_arg(args, unsigned LLONG);
326 break;
327 default:
328 value = (LLONG) va_arg(args,
329 unsigned int);
330 break;
331 }
332 fmtint(buffer, &currlen, maxlen, value,
333 ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
334 min, max, flags);
335 break;
336 case 'f':
337 if (cflags == DP_C_LDOUBLE)
338 fvalue = va_arg(args, LDOUBLE);
339 else
340 fvalue = va_arg(args, double);
341 fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
342 break;
343 case 'E':
344 flags |= DP_F_UP;
345 case 'e':
346 if (cflags == DP_C_LDOUBLE)
347 fvalue = va_arg(args, LDOUBLE);
348 else
349 fvalue = va_arg(args, double);
350 break;
351 case 'G':
352 flags |= DP_F_UP;
353 case 'g':
354 if (cflags == DP_C_LDOUBLE)
355 fvalue = va_arg(args, LDOUBLE);
356 else
357 fvalue = va_arg(args, double);
358 break;
359 case 'c':
360 dopr_outch(buffer, &currlen, maxlen,
361 va_arg(args, int));
362 break;
363 case 's':
364 strvalue = va_arg(args, char *);
365 if (max < 0)
366 max = maxlen;
367 fmtstr(buffer, &currlen, maxlen, strvalue,
368 flags, min, max);
369 break;
370 case 'p':
371 value = (long)va_arg(args, void *);
372 fmtint(buffer, &currlen, maxlen,
373 value, 16, min, max, flags);
374 break;
375 case 'n': /* XXX */
376 if (cflags == DP_C_SHORT) {
377 short int *num;
378 num = va_arg(args, short int *);
379 *num = currlen;
380 } else if (cflags == DP_C_LONG) { /* XXX */
381 long int *num;
382 num = va_arg(args, long int *);
383 *num = (long int) currlen;
384 } else if (cflags == DP_C_LLONG) { /* XXX */
385 LLONG *num;
386 num = va_arg(args, LLONG *);
387 *num = (LLONG) currlen;
388 } else {
389 int *num;
390 num = va_arg(args, int *);
391 *num = currlen;
392 }
393 break;
394 case '%':
395 dopr_outch(buffer, &currlen, maxlen, ch);
396 break;
397 case 'w':
398 /* not supported yet, treat as next char */
399 ch = *format++;
400 break;
401 default:
402 /* unknown, skip */
403 break;
404 }
405 ch = *format++;
406 state = DP_S_DEFAULT;
407 flags = cflags = min = 0;
408 max = -1;
409 break;
410 case DP_S_DONE:
411 break;
412 default:
413 break;
414 }
415 }
416 if (currlen >= maxlen - 1)
417 currlen = maxlen - 1;
418 buffer[currlen] = '\0';
419 *retlen = currlen;
420 return;
421}
422
423static void
424fmtstr(
425 char *buffer,
426 size_t *currlen,
427 size_t maxlen,
428 char *value,
429 int flags,
430 int min,
431 int max)
432{
433 int padlen, strln;
434 int cnt = 0;
435
436 if (value == 0)
437 value = "<NULL>";
438 for (strln = 0; value[strln]; ++strln)
439 ;
440 padlen = min - strln;
441 if (padlen < 0)
442 padlen = 0;
443 if (flags & DP_F_MINUS)
444 padlen = -padlen;
445
446 while ((padlen > 0) && (cnt < max)) {
447 dopr_outch(buffer, currlen, maxlen, ' ');
448 --padlen;
449 ++cnt;
450 }
451 while (*value && (cnt < max)) {
452 dopr_outch(buffer, currlen, maxlen, *value++);
453 ++cnt;
454 }
455 while ((padlen < 0) && (cnt < max)) {
456 dopr_outch(buffer, currlen, maxlen, ' ');
457 ++padlen;
458 ++cnt;
459 }
460}
461
462static void
463fmtint(
464 char *buffer,
465 size_t *currlen,
466 size_t maxlen,
467 LLONG value,
468 int base,
469 int min,
470 int max,
471 int flags)
472{
473 int signvalue = 0;
474 unsigned LLONG uvalue;
475 char convert[20];
476 int place = 0;
477 int spadlen = 0;
478 int zpadlen = 0;
479 int caps = 0;
480
481 if (max < 0)
482 max = 0;
483 uvalue = value;
484 if (!(flags & DP_F_UNSIGNED)) {
485 if (value < 0) {
486 signvalue = '-';
487 uvalue = -value;
488 } else if (flags & DP_F_PLUS)
489 signvalue = '+';
490 else if (flags & DP_F_SPACE)
491 signvalue = ' ';
492 }
493 if (flags & DP_F_UP)
494 caps = 1;
495 do {
496 convert[place++] =
497 (caps ? "0123456789ABCDEF" : "0123456789abcdef")
498 [uvalue % (unsigned) base];
499 uvalue = (uvalue / (unsigned) base);
500 } while (uvalue && (place < 20));
501 if (place == 20)
502 place--;
503 convert[place] = 0;
504
505 zpadlen = max - place;
506 spadlen = min - MAX(max, place) - (signvalue ? 1 : 0);
507 if (zpadlen < 0)
508 zpadlen = 0;
509 if (spadlen < 0)
510 spadlen = 0;
511 if (flags & DP_F_ZERO) {
512 zpadlen = MAX(zpadlen, spadlen);
513 spadlen = 0;
514 }
515 if (flags & DP_F_MINUS)
516 spadlen = -spadlen;
517
518 /* spaces */
519 while (spadlen > 0) {
520 dopr_outch(buffer, currlen, maxlen, ' ');
521 --spadlen;
522 }
523
524 /* sign */
525 if (signvalue)
526 dopr_outch(buffer, currlen, maxlen, signvalue);
527
528 /* zeros */
529 if (zpadlen > 0) {
530 while (zpadlen > 0) {
531 dopr_outch(buffer, currlen, maxlen, '0');
532 --zpadlen;
533 }
534 }
535 /* digits */
536 while (place > 0)
537 dopr_outch(buffer, currlen, maxlen, convert[--place]);
538
539 /* left justified spaces */
540 while (spadlen < 0) {
541 dopr_outch(buffer, currlen, maxlen, ' ');
542 ++spadlen;
543 }
544 return;
545}
546
547static LDOUBLE
548abs_val(LDOUBLE value)
549{
550 LDOUBLE result = value;
551 if (value < 0)
552 result = -value;
553 return result;
554}
555
556static LDOUBLE
557pow10(int exp)
558{
559 LDOUBLE result = 1;
560 while (exp) {
561 result *= 10;
562 exp--;
563 }
564 return result;
565}
566
567static long
568round(LDOUBLE value)
569{
570 long intpart;
571 intpart = (long) value;
572 value = value - intpart;
573 if (value >= 0.5)
574 intpart++;
575 return intpart;
576}
577
578static void
579fmtfp(
580 char *buffer,
581 size_t *currlen,
582 size_t maxlen,
583 LDOUBLE fvalue,
584 int min,
585 int max,
586 int flags)
587{
588 int signvalue = 0;
589 LDOUBLE ufvalue;
590 char iconvert[20];
591 char fconvert[20];
592 int iplace = 0;
593 int fplace = 0;
594 int padlen = 0;
595 int zpadlen = 0;
596 int caps = 0;
597 long intpart;
598 long fracpart;
599
600 if (max < 0)
601 max = 6;
602 ufvalue = abs_val(fvalue);
603 if (fvalue < 0)
604 signvalue = '-';
605 else if (flags & DP_F_PLUS)
606 signvalue = '+';
607 else if (flags & DP_F_SPACE)
608 signvalue = ' ';
609
610 intpart = (long)ufvalue;
611
612 /* sorry, we only support 9 digits past the decimal because of our
613 conversion method */
614 if (max > 9)
615 max = 9;
616
617 /* we "cheat" by converting the fractional part to integer by
618 multiplying by a factor of 10 */
619 fracpart = round((pow10(max)) * (ufvalue - intpart));
620
621 if (fracpart >= pow10(max)) {
622 intpart++;
623 fracpart -= (long)pow10(max);
624 }
625
626 /* convert integer part */
627 do {
628 iconvert[iplace++] =
629 (caps ? "0123456789ABCDEF"
630 : "0123456789abcdef")[intpart % 10];
631 intpart = (intpart / 10);
632 } while (intpart && (iplace < 20));
633 if (iplace == 20)
634 iplace--;
635 iconvert[iplace] = 0;
636
637 /* convert fractional part */
638 do {
639 fconvert[fplace++] =
640 (caps ? "0123456789ABCDEF"
641 : "0123456789abcdef")[fracpart % 10];
642 fracpart = (fracpart / 10);
643 } while (fracpart && (fplace < 20));
644 if (fplace == 20)
645 fplace--;
646 fconvert[fplace] = 0;
647
648 /* -1 for decimal point, another -1 if we are printing a sign */
649 padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
650 zpadlen = max - fplace;
651 if (zpadlen < 0)
652 zpadlen = 0;
653 if (padlen < 0)
654 padlen = 0;
655 if (flags & DP_F_MINUS)
656 padlen = -padlen;
657
658 if ((flags & DP_F_ZERO) && (padlen > 0)) {
659 if (signvalue) {
660 dopr_outch(buffer, currlen, maxlen, signvalue);
661 --padlen;
662 signvalue = 0;
663 }
664 while (padlen > 0) {
665 dopr_outch(buffer, currlen, maxlen, '0');
666 --padlen;
667 }
668 }
669 while (padlen > 0) {
670 dopr_outch(buffer, currlen, maxlen, ' ');
671 --padlen;
672 }
673 if (signvalue)
674 dopr_outch(buffer, currlen, maxlen, signvalue);
675
676 while (iplace > 0)
677 dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
678
679 /*
680 * Decimal point. This should probably use locale to find the correct
681 * char to print out.
682 */
683 if (max > 0) {
684 dopr_outch(buffer, currlen, maxlen, '.');
685
686 while (fplace > 0)
687 dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
688 }
689 while (zpadlen > 0) {
690 dopr_outch(buffer, currlen, maxlen, '0');
691 --zpadlen;
692 }
693
694 while (padlen < 0) {
695 dopr_outch(buffer, currlen, maxlen, ' ');
696 ++padlen;
697 }
698}
699
700static void
701dopr_outch(
702 char *buffer,
703 size_t *currlen,
704 size_t maxlen,
705 int c)
706{
707 if (*currlen < maxlen)
708 buffer[(*currlen)++] = (char)c;
709 return;
710}
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
index d29b29ff8b..6409f98f57 100644
--- a/src/lib/libcrypto/bio/b_sock.c
+++ b/src/lib/libcrypto/bio/b_sock.c
@@ -163,7 +163,14 @@ int BIO_get_port(const char *str, unsigned short *port_ptr)
163 else 163 else
164 { 164 {
165 CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); 165 CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
166 s=getservbyname(str,"tcp"); 166 /* Note: under VMS with SOCKETSHR, it seems like the first
167 * parameter is 'char *', instead of 'const char *'
168 */
169 s=getservbyname(
170#ifndef CONST_STRICT
171 (char *)
172#endif
173 str,"tcp");
167 if(s != NULL) 174 if(s != NULL)
168 *port_ptr=ntohs((unsigned short)s->s_port); 175 *port_ptr=ntohs((unsigned short)s->s_port);
169 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); 176 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
@@ -282,12 +289,12 @@ static struct hostent *ghbn_dup(struct hostent *a)
282 289
283 j=strlen(a->h_name)+1; 290 j=strlen(a->h_name)+1;
284 if ((ret->h_name=Malloc(j)) == NULL) goto err; 291 if ((ret->h_name=Malloc(j)) == NULL) goto err;
285 memcpy((char *)ret->h_name,a->h_name,j+1); 292 memcpy((char *)ret->h_name,a->h_name,j);
286 for (i=0; a->h_aliases[i] != NULL; i++) 293 for (i=0; a->h_aliases[i] != NULL; i++)
287 { 294 {
288 j=strlen(a->h_aliases[i])+1; 295 j=strlen(a->h_aliases[i])+1;
289 if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err; 296 if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err;
290 memcpy(ret->h_aliases[i],a->h_aliases[i],j+1); 297 memcpy(ret->h_aliases[i],a->h_aliases[i],j);
291 } 298 }
292 ret->h_length=a->h_length; 299 ret->h_length=a->h_length;
293 ret->h_addrtype=a->h_addrtype; 300 ret->h_addrtype=a->h_addrtype;
@@ -327,7 +334,7 @@ static void ghbn_free(struct hostent *a)
327 Free(a->h_addr_list[i]); 334 Free(a->h_addr_list[i]);
328 Free(a->h_addr_list); 335 Free(a->h_addr_list);
329 } 336 }
330 if (a->h_name != NULL) Free((char *)a->h_name); 337 if (a->h_name != NULL) Free(a->h_name);
331 Free(a); 338 Free(a);
332 } 339 }
333 340
@@ -368,7 +375,14 @@ struct hostent *BIO_gethostbyname(const char *name)
368 if (i == GHBN_NUM) /* no hit*/ 375 if (i == GHBN_NUM) /* no hit*/
369 { 376 {
370 BIO_ghbn_miss++; 377 BIO_ghbn_miss++;
371 ret=gethostbyname(name); 378 /* Note: under VMS with SOCKETSHR, it seems like the first
379 * parameter is 'char *', instead of 'const char *'
380 */
381 ret=gethostbyname(
382#ifndef CONST_STRICT
383 (char *)
384#endif
385 name);
372 386
373 if (ret == NULL) 387 if (ret == NULL)
374 goto end; 388 goto end;
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
index acd8148138..ff0c9070ae 100644
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ b/src/lib/libcrypto/bio/bf_buff.c
@@ -69,6 +69,7 @@ static int buffer_gets(BIO *h,char *str,int size);
69static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int buffer_new(BIO *h); 70static int buffer_new(BIO *h);
71static int buffer_free(BIO *data); 71static int buffer_free(BIO *data);
72static long buffer_callback_ctrl(BIO *h,int cmd, void (*fp)());
72#define DEFAULT_BUFFER_SIZE 1024 73#define DEFAULT_BUFFER_SIZE 1024
73 74
74static BIO_METHOD methods_buffer= 75static BIO_METHOD methods_buffer=
@@ -82,6 +83,7 @@ static BIO_METHOD methods_buffer=
82 buffer_ctrl, 83 buffer_ctrl,
83 buffer_new, 84 buffer_new,
84 buffer_free, 85 buffer_free,
86 buffer_callback_ctrl,
85 }; 87 };
86 88
87BIO_METHOD *BIO_f_buffer(void) 89BIO_METHOD *BIO_f_buffer(void)
@@ -284,6 +286,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
284 ctx->ibuf_len=0; 286 ctx->ibuf_len=0;
285 ctx->obuf_off=0; 287 ctx->obuf_off=0;
286 ctx->obuf_len=0; 288 ctx->obuf_len=0;
289 if (b->next_bio == NULL) return(0);
287 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); 290 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
288 break; 291 break;
289 case BIO_CTRL_INFO: 292 case BIO_CTRL_INFO:
@@ -300,12 +303,18 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
300 case BIO_CTRL_WPENDING: 303 case BIO_CTRL_WPENDING:
301 ret=(long)ctx->obuf_len; 304 ret=(long)ctx->obuf_len;
302 if (ret == 0) 305 if (ret == 0)
306 {
307 if (b->next_bio == NULL) return(0);
303 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); 308 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
309 }
304 break; 310 break;
305 case BIO_CTRL_PENDING: 311 case BIO_CTRL_PENDING:
306 ret=(long)ctx->ibuf_len; 312 ret=(long)ctx->ibuf_len;
307 if (ret == 0) 313 if (ret == 0)
314 {
315 if (b->next_bio == NULL) return(0);
308 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); 316 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
317 }
309 break; 318 break;
310 case BIO_C_SET_BUFF_READ_DATA: 319 case BIO_C_SET_BUFF_READ_DATA:
311 if (num > ctx->ibuf_size) 320 if (num > ctx->ibuf_size)
@@ -374,12 +383,14 @@ static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
374 } 383 }
375 break; 384 break;
376 case BIO_C_DO_STATE_MACHINE: 385 case BIO_C_DO_STATE_MACHINE:
386 if (b->next_bio == NULL) return(0);
377 BIO_clear_retry_flags(b); 387 BIO_clear_retry_flags(b);
378 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); 388 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
379 BIO_copy_next_retry(b); 389 BIO_copy_next_retry(b);
380 break; 390 break;
381 391
382 case BIO_CTRL_FLUSH: 392 case BIO_CTRL_FLUSH:
393 if (b->next_bio == NULL) return(0);
383 if (ctx->obuf_len <= 0) 394 if (ctx->obuf_len <= 0)
384 { 395 {
385 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); 396 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
@@ -418,6 +429,7 @@ fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_
418 ret=0; 429 ret=0;
419 break; 430 break;
420 default: 431 default:
432 if (b->next_bio == NULL) return(0);
421 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); 433 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
422 break; 434 break;
423 } 435 }
@@ -427,6 +439,20 @@ malloc_error:
427 return(0); 439 return(0);
428 } 440 }
429 441
442static long buffer_callback_ctrl(BIO *b, int cmd, void (*fp)())
443 {
444 long ret=1;
445
446 if (b->next_bio == NULL) return(0);
447 switch (cmd)
448 {
449 default:
450 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
451 break;
452 }
453 return(ret);
454 }
455
430static int buffer_gets(BIO *b, char *buf, int size) 456static int buffer_gets(BIO *b, char *buf, int size)
431 { 457 {
432 BIO_F_BUFFER_CTX *ctx; 458 BIO_F_BUFFER_CTX *ctx;
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
index cbec2bae29..5e574b7231 100644
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ b/src/lib/libcrypto/bio/bf_nbio.c
@@ -73,6 +73,7 @@ static int nbiof_gets(BIO *h,char *str,int size);
73static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); 73static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2);
74static int nbiof_new(BIO *h); 74static int nbiof_new(BIO *h);
75static int nbiof_free(BIO *data); 75static int nbiof_free(BIO *data);
76static long nbiof_callback_ctrl(BIO *h,int cmd,void (*fp)());
76typedef struct nbio_test_st 77typedef struct nbio_test_st
77 { 78 {
78 /* only set if we sent a 'should retry' error */ 79 /* only set if we sent a 'should retry' error */
@@ -91,6 +92,7 @@ static BIO_METHOD methods_nbiof=
91 nbiof_ctrl, 92 nbiof_ctrl,
92 nbiof_new, 93 nbiof_new,
93 nbiof_free, 94 nbiof_free,
95 nbiof_callback_ctrl,
94 }; 96 };
95 97
96BIO_METHOD *BIO_f_nbio_test(void) 98BIO_METHOD *BIO_f_nbio_test(void)
@@ -137,7 +139,7 @@ static int nbiof_read(BIO *b, char *out, int outl)
137 139
138 BIO_clear_retry_flags(b); 140 BIO_clear_retry_flags(b);
139#if 0 141#if 0
140 RAND_bytes(&n,1); 142 RAND_pseudo_bytes(&n,1);
141 num=(n&0x07); 143 num=(n&0x07);
142 144
143 if (outl > num) outl=num; 145 if (outl > num) outl=num;
@@ -178,7 +180,7 @@ static int nbiof_write(BIO *b, char *in, int inl)
178 } 180 }
179 else 181 else
180 { 182 {
181 RAND_bytes(&n,1); 183 RAND_pseudo_bytes(&n,1);
182 num=(n&7); 184 num=(n&7);
183 } 185 }
184 186
@@ -224,6 +226,20 @@ static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr)
224 return(ret); 226 return(ret);
225 } 227 }
226 228
229static long nbiof_callback_ctrl(BIO *b, int cmd, void (*fp)())
230 {
231 long ret=1;
232
233 if (b->next_bio == NULL) return(0);
234 switch (cmd)
235 {
236 default:
237 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
238 break;
239 }
240 return(ret);
241 }
242
227static int nbiof_gets(BIO *bp, char *buf, int size) 243static int nbiof_gets(BIO *bp, char *buf, int size)
228 { 244 {
229 if (bp->next_bio == NULL) return(0); 245 if (bp->next_bio == NULL) return(0);
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c
index 3254a55dce..0d183a6d9a 100644
--- a/src/lib/libcrypto/bio/bf_null.c
+++ b/src/lib/libcrypto/bio/bf_null.c
@@ -72,6 +72,7 @@ static int nullf_gets(BIO *h,char *str,int size);
72static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); 72static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2);
73static int nullf_new(BIO *h); 73static int nullf_new(BIO *h);
74static int nullf_free(BIO *data); 74static int nullf_free(BIO *data);
75static long nullf_callback_ctrl(BIO *h,int cmd,void (*fp)());
75static BIO_METHOD methods_nullf= 76static BIO_METHOD methods_nullf=
76 { 77 {
77 BIO_TYPE_NULL_FILTER, 78 BIO_TYPE_NULL_FILTER,
@@ -83,6 +84,7 @@ static BIO_METHOD methods_nullf=
83 nullf_ctrl, 84 nullf_ctrl,
84 nullf_new, 85 nullf_new,
85 nullf_free, 86 nullf_free,
87 nullf_callback_ctrl,
86 }; 88 };
87 89
88BIO_METHOD *BIO_f_null(void) 90BIO_METHOD *BIO_f_null(void)
@@ -152,6 +154,20 @@ static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr)
152 return(ret); 154 return(ret);
153 } 155 }
154 156
157static long nullf_callback_ctrl(BIO *b, int cmd, void (*fp)())
158 {
159 long ret=1;
160
161 if (b->next_bio == NULL) return(0);
162 switch (cmd)
163 {
164 default:
165 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
166 break;
167 }
168 return(ret);
169 }
170
155static int nullf_gets(BIO *bp, char *buf, int size) 171static int nullf_gets(BIO *bp, char *buf, int size)
156 { 172 {
157 if (bp->next_bio == NULL) return(0); 173 if (bp->next_bio == NULL) return(0);
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
index 54bf622a3b..bc08401eeb 100644
--- a/src/lib/libcrypto/bio/bio.h
+++ b/src/lib/libcrypto/bio/bio.h
@@ -76,7 +76,7 @@ extern "C" {
76#define BIO_TYPE_SOCKET (5|0x0400|0x0100) 76#define BIO_TYPE_SOCKET (5|0x0400|0x0100)
77#define BIO_TYPE_NULL (6|0x0400) 77#define BIO_TYPE_NULL (6|0x0400)
78#define BIO_TYPE_SSL (7|0x0200) 78#define BIO_TYPE_SSL (7|0x0200)
79#define BIO_TYPE_MD (8|0x0200) /* pasive filter */ 79#define BIO_TYPE_MD (8|0x0200) /* passive filter */
80#define BIO_TYPE_BUFFER (9|0x0200) /* filter */ 80#define BIO_TYPE_BUFFER (9|0x0200) /* filter */
81#define BIO_TYPE_CIPHER (10|0x0200) /* filter */ 81#define BIO_TYPE_CIPHER (10|0x0200) /* filter */
82#define BIO_TYPE_BASE64 (11|0x0200) /* filter */ 82#define BIO_TYPE_BASE64 (11|0x0200) /* filter */
@@ -147,6 +147,11 @@ extern "C" {
147 147
148#define BIO_FLAGS_BASE64_NO_NL 0x100 148#define BIO_FLAGS_BASE64_NO_NL 0x100
149 149
150/* This is used with memory BIOs: it means we shouldn't free up or change the
151 * data in any way.
152 */
153#define BIO_FLAGS_MEM_RDONLY 0x200
154
150#define BIO_set_flags(b,f) ((b)->flags|=(f)) 155#define BIO_set_flags(b,f) ((b)->flags|=(f))
151#define BIO_get_flags(b) ((b)->flags) 156#define BIO_get_flags(b) ((b)->flags)
152#define BIO_set_retry_special(b) \ 157#define BIO_set_retry_special(b) \
@@ -163,7 +168,7 @@ extern "C" {
163#define BIO_get_retry_flags(b) \ 168#define BIO_get_retry_flags(b) \
164 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) 169 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
165 170
166/* These shouldbe used by the application to tell why we should retry */ 171/* These should be used by the application to tell why we should retry */
167#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ) 172#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
168#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE) 173#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
169#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL) 174#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
@@ -214,6 +219,7 @@ typedef struct bio_method_st
214 long (*ctrl)(); 219 long (*ctrl)();
215 int (*create)(); 220 int (*create)();
216 int (*destroy)(); 221 int (*destroy)();
222 long (*callback_ctrl)();
217 } BIO_METHOD; 223 } BIO_METHOD;
218#else 224#else
219typedef struct bio_method_st 225typedef struct bio_method_st
@@ -227,6 +233,7 @@ typedef struct bio_method_st
227 long (_far *ctrl)(); 233 long (_far *ctrl)();
228 int (_far *create)(); 234 int (_far *create)();
229 int (_far *destroy)(); 235 int (_far *destroy)();
236 long (_fat *callback_ctrl)();
230 } BIO_METHOD; 237 } BIO_METHOD;
231#endif 238#endif
232 239
@@ -278,9 +285,6 @@ typedef struct bio_f_buffer_ctx_struct
278#define BIO_CONN_S_NBIO 8 285#define BIO_CONN_S_NBIO 8
279/*#define BIO_CONN_get_param_hostname BIO_ctrl */ 286/*#define BIO_CONN_get_param_hostname BIO_ctrl */
280 287
281#define BIO_number_read(b) ((b)->num_read)
282#define BIO_number_written(b) ((b)->num_write)
283
284#define BIO_C_SET_CONNECT 100 288#define BIO_C_SET_CONNECT 100
285#define BIO_C_DO_STATE_MACHINE 101 289#define BIO_C_DO_STATE_MACHINE 101
286#define BIO_C_SET_NBIO 102 290#define BIO_C_SET_NBIO 102
@@ -325,9 +329,14 @@ typedef struct bio_f_buffer_ctx_struct
325#define BIO_C_GET_WRITE_GUARANTEE 140 329#define BIO_C_GET_WRITE_GUARANTEE 140
326#define BIO_C_GET_READ_REQUEST 141 330#define BIO_C_GET_READ_REQUEST 141
327#define BIO_C_SHUTDOWN_WR 142 331#define BIO_C_SHUTDOWN_WR 142
332#define BIO_C_NREAD0 143
333#define BIO_C_NREAD 144
334#define BIO_C_NWRITE0 145
335#define BIO_C_NWRITE 146
336#define BIO_C_RESET_READ_REQUEST 147
328 337
329 338
330#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) 339#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg)
331#define BIO_get_app_data(s) BIO_get_ex_data(s,0) 340#define BIO_get_app_data(s) BIO_get_ex_data(s,0)
332 341
333/* BIO_s_connect() and BIO_s_socks4a_connect() */ 342/* BIO_s_connect() and BIO_s_socks4a_connect() */
@@ -366,7 +375,7 @@ typedef struct bio_f_buffer_ctx_struct
366/* BIO_set_nbio(b,n) */ 375/* BIO_set_nbio(b,n) */
367#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) 376#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))
368/* BIO *BIO_get_filter_bio(BIO *bio); */ 377/* BIO *BIO_get_filter_bio(BIO *bio); */
369#define BIO_set_proxy_cb(b,cb) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(char *)(cb)) 378#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)()))
370#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) 379#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)
371#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) 380#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)
372 381
@@ -445,8 +454,8 @@ int BIO_read_filename(BIO *b,const char *name);
445size_t BIO_ctrl_pending(BIO *b); 454size_t BIO_ctrl_pending(BIO *b);
446size_t BIO_ctrl_wpending(BIO *b); 455size_t BIO_ctrl_wpending(BIO *b);
447#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) 456#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
448#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp) 457#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(void (**)())(cbp))
449#define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb) 458#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,(void (*)())(cb))
450 459
451/* For the BIO_f_buffer() type */ 460/* For the BIO_f_buffer() type */
452#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) 461#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
@@ -461,8 +470,7 @@ size_t BIO_ctrl_wpending(BIO *b);
461#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) 470#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
462size_t BIO_ctrl_get_write_guarantee(BIO *b); 471size_t BIO_ctrl_get_write_guarantee(BIO *b);
463size_t BIO_ctrl_get_read_request(BIO *b); 472size_t BIO_ctrl_get_read_request(BIO *b);
464 473int BIO_ctrl_reset_read_request(BIO *b);
465
466 474
467#ifdef NO_STDIO 475#ifdef NO_STDIO
468#define NO_FP_API 476#define NO_FP_API
@@ -472,10 +480,12 @@ size_t BIO_ctrl_get_read_request(BIO *b);
472/* These two aren't currently implemented */ 480/* These two aren't currently implemented */
473/* int BIO_get_ex_num(BIO *bio); */ 481/* int BIO_get_ex_num(BIO *bio); */
474/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ 482/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
475int BIO_set_ex_data(BIO *bio,int idx,char *data); 483int BIO_set_ex_data(BIO *bio,int idx,void *data);
476char *BIO_get_ex_data(BIO *bio,int idx); 484void *BIO_get_ex_data(BIO *bio,int idx);
477int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), 485int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
478 int (*dup_func)(), void (*free_func)()); 486 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
487unsigned long BIO_number_read(BIO *bio);
488unsigned long BIO_number_written(BIO *bio);
479 489
480# if defined(WIN16) && defined(_WINDLL) 490# if defined(WIN16) && defined(_WINDLL)
481BIO_METHOD *BIO_s_file_internal(void); 491BIO_METHOD *BIO_s_file_internal(void);
@@ -500,6 +510,7 @@ int BIO_gets(BIO *bp,char *buf, int size);
500int BIO_write(BIO *b, const char *data, int len); 510int BIO_write(BIO *b, const char *data, int len);
501int BIO_puts(BIO *bp,const char *buf); 511int BIO_puts(BIO *bp,const char *buf);
502long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); 512long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
513long BIO_callback_ctrl(BIO *bp,int cmd,void (*fp)());
503char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); 514char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
504long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); 515long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
505BIO * BIO_push(BIO *b,BIO *append); 516BIO * BIO_push(BIO *b,BIO *append);
@@ -510,6 +521,11 @@ BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
510int BIO_get_retry_reason(BIO *bio); 521int BIO_get_retry_reason(BIO *bio);
511BIO * BIO_dup_chain(BIO *in); 522BIO * BIO_dup_chain(BIO *in);
512 523
524int BIO_nread0(BIO *bio, char **buf);
525int BIO_nread(BIO *bio, char **buf, int num);
526int BIO_nwrite0(BIO *bio, char **buf);
527int BIO_nwrite(BIO *bio, char **buf, int num);
528
513#ifndef WIN16 529#ifndef WIN16
514long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, 530long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
515 long argl,long ret); 531 long argl,long ret);
@@ -519,6 +535,7 @@ long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
519#endif 535#endif
520 536
521BIO_METHOD *BIO_s_mem(void); 537BIO_METHOD *BIO_s_mem(void);
538BIO *BIO_new_mem_buf(void *buf, int len);
522BIO_METHOD *BIO_s_socket(void); 539BIO_METHOD *BIO_s_socket(void);
523BIO_METHOD *BIO_s_connect(void); 540BIO_METHOD *BIO_s_connect(void);
524BIO_METHOD *BIO_s_accept(void); 541BIO_METHOD *BIO_s_accept(void);
@@ -597,11 +614,17 @@ int BIO_printf(BIO *bio, ...);
597#define BIO_F_BIO_MAKE_PAIR 121 614#define BIO_F_BIO_MAKE_PAIR 121
598#define BIO_F_BIO_NEW 108 615#define BIO_F_BIO_NEW 108
599#define BIO_F_BIO_NEW_FILE 109 616#define BIO_F_BIO_NEW_FILE 109
617#define BIO_F_BIO_NEW_MEM_BUF 126
618#define BIO_F_BIO_NREAD 123
619#define BIO_F_BIO_NREAD0 124
620#define BIO_F_BIO_NWRITE 125
621#define BIO_F_BIO_NWRITE0 122
600#define BIO_F_BIO_PUTS 110 622#define BIO_F_BIO_PUTS 110
601#define BIO_F_BIO_READ 111 623#define BIO_F_BIO_READ 111
602#define BIO_F_BIO_SOCK_INIT 112 624#define BIO_F_BIO_SOCK_INIT 112
603#define BIO_F_BIO_WRITE 113 625#define BIO_F_BIO_WRITE 113
604#define BIO_F_BUFFER_CTRL 114 626#define BIO_F_BUFFER_CTRL 114
627#define BIO_F_CONN_CTRL 127
605#define BIO_F_CONN_STATE 115 628#define BIO_F_CONN_STATE 115
606#define BIO_F_FILE_CTRL 116 629#define BIO_F_FILE_CTRL 116
607#define BIO_F_MEM_WRITE 117 630#define BIO_F_MEM_WRITE 117
@@ -634,6 +657,7 @@ int BIO_printf(BIO *bio, ...);
634#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 657#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119
635#define BIO_R_UNINITIALIZED 120 658#define BIO_R_UNINITIALIZED 120
636#define BIO_R_UNSUPPORTED_METHOD 121 659#define BIO_R_UNSUPPORTED_METHOD 121
660#define BIO_R_WRITE_TO_READ_ONLY_BIO 126
637#define BIO_R_WSASTARTUP 122 661#define BIO_R_WSASTARTUP 122
638 662
639#ifdef __cplusplus 663#ifdef __cplusplus
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
index 712d98a3a1..b5f07de5a0 100644
--- a/src/lib/libcrypto/bio/bio_err.c
+++ b/src/lib/libcrypto/bio/bio_err.c
@@ -77,11 +77,17 @@ static ERR_STRING_DATA BIO_str_functs[]=
77{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"}, 77{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"},
78{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"}, 78{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"},
79{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"}, 79{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"},
80{ERR_PACK(0,BIO_F_BIO_NEW_MEM_BUF,0), "BIO_new_mem_buf"},
81{ERR_PACK(0,BIO_F_BIO_NREAD,0), "BIO_nread"},
82{ERR_PACK(0,BIO_F_BIO_NREAD0,0), "BIO_nread0"},
83{ERR_PACK(0,BIO_F_BIO_NWRITE,0), "BIO_nwrite"},
84{ERR_PACK(0,BIO_F_BIO_NWRITE0,0), "BIO_nwrite0"},
80{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"}, 85{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"},
81{ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"}, 86{ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"},
82{ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"}, 87{ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"},
83{ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"}, 88{ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"},
84{ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"}, 89{ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"},
90{ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"},
85{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, 91{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
86{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, 92{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
87{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, 93{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
@@ -117,6 +123,7 @@ static ERR_STRING_DATA BIO_str_reasons[]=
117{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, 123{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
118{BIO_R_UNINITIALIZED ,"uninitialized"}, 124{BIO_R_UNINITIALIZED ,"uninitialized"},
119{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, 125{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
126{BIO_R_WRITE_TO_READ_ONLY_BIO ,"write to read only bio"},
120{BIO_R_WSASTARTUP ,"wsastartup"}, 127{BIO_R_WSASTARTUP ,"wsastartup"},
121{0,NULL} 128{0,NULL}
122 }; 129 };
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
index b72688ea90..cf8e6150fd 100644
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -63,7 +63,7 @@
63#include <openssl/bio.h> 63#include <openssl/bio.h>
64#include <openssl/stack.h> 64#include <openssl/stack.h>
65 65
66static STACK *bio_meth=NULL; 66static STACK_OF(CRYPTO_EX_DATA_FUNCS) *bio_meth=NULL;
67static int bio_meth_num=0; 67static int bio_meth_num=0;
68 68
69BIO *BIO_new(BIO_METHOD *method) 69BIO *BIO_new(BIO_METHOD *method)
@@ -100,7 +100,7 @@ int BIO_set(BIO *bio, BIO_METHOD *method)
100 bio->references=1; 100 bio->references=1;
101 bio->num_read=0L; 101 bio->num_read=0L;
102 bio->num_write=0L; 102 bio->num_write=0L;
103 CRYPTO_new_ex_data(bio_meth,(char *)bio,&bio->ex_data); 103 CRYPTO_new_ex_data(bio_meth,bio,&bio->ex_data);
104 if (method->create != NULL) 104 if (method->create != NULL)
105 if (!method->create(bio)) 105 if (!method->create(bio))
106 return(0); 106 return(0);
@@ -129,7 +129,7 @@ int BIO_free(BIO *a)
129 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0)) 129 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
130 return(i); 130 return(i);
131 131
132 CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); 132 CRYPTO_free_ex_data(bio_meth,a,&a->ex_data);
133 133
134 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); 134 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
135 ret=a->method->destroy(a); 135 ret=a->method->destroy(a);
@@ -317,16 +317,43 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
317 return(ret); 317 return(ret);
318 } 318 }
319 319
320long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)())
321 {
322 long ret;
323 long (*cb)();
324
325 if (b == NULL) return(0);
326
327 if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
328 {
329 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
330 return(-2);
331 }
332
333 cb=b->callback;
334
335 if ((cb != NULL) &&
336 ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0))
337 return(ret);
338
339 ret=b->method->callback_ctrl(b,cmd,fp);
340
341 if (cb != NULL)
342 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd,
343 0,ret);
344 return(ret);
345 }
346
320/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros 347/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
321 * do; but those macros have inappropriate return type, and for interfacing 348 * do; but those macros have inappropriate return type, and for interfacing
322 * from other programming languages, C macros aren't much of a help anyway. */ 349 * from other programming languages, C macros aren't much of a help anyway. */
323size_t BIO_ctrl_pending(BIO *bio) 350size_t BIO_ctrl_pending(BIO *bio)
324 { 351 {
325 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); 352 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
326 } 353 }
327 354
328size_t BIO_ctrl_wpending(BIO *bio) 355size_t BIO_ctrl_wpending(BIO *bio)
329 { 356 {
330 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); 357 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
331 } 358 }
332 359
@@ -476,21 +503,32 @@ void BIO_copy_next_retry(BIO *b)
476 b->retry_reason=b->next_bio->retry_reason; 503 b->retry_reason=b->next_bio->retry_reason;
477 } 504 }
478 505
479int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), 506int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
480 int (*dup_func)(), void (*free_func)()) 507 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
481 { 508 {
482 bio_meth_num++; 509 bio_meth_num++;
483 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, 510 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth,
484 argl,argp,new_func,dup_func,free_func)); 511 argl,argp,new_func,dup_func,free_func));
485 } 512 }
486 513
487int BIO_set_ex_data(BIO *bio, int idx, char *data) 514int BIO_set_ex_data(BIO *bio, int idx, void *data)
488 { 515 {
489 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); 516 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
490 } 517 }
491 518
492char *BIO_get_ex_data(BIO *bio, int idx) 519void *BIO_get_ex_data(BIO *bio, int idx)
493 { 520 {
494 return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); 521 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
495 } 522 }
496 523
524unsigned long BIO_number_read(BIO *bio)
525{
526 if(bio) return bio->num_read;
527 return 0;
528}
529
530unsigned long BIO_number_written(BIO *bio)
531{
532 if(bio) return bio->num_write;
533 return 0;
534}
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
index 47af80f76d..9afa636406 100644
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ b/src/lib/libcrypto/bio/bss_acpt.c
@@ -118,6 +118,7 @@ static BIO_METHOD methods_acceptp=
118 acpt_ctrl, 118 acpt_ctrl,
119 acpt_new, 119 acpt_new,
120 acpt_free, 120 acpt_free,
121 NULL,
121 }; 122 };
122 123
123BIO_METHOD *BIO_s_accept(void) 124BIO_METHOD *BIO_s_accept(void)
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
index 562e9d8de2..0d0f9356f7 100644
--- a/src/lib/libcrypto/bio/bss_bio.c
+++ b/src/lib/libcrypto/bio/bss_bio.c
@@ -13,6 +13,7 @@
13#endif 13#endif
14 14
15#include <assert.h> 15#include <assert.h>
16#include <limits.h>
16#include <stdlib.h> 17#include <stdlib.h>
17#include <string.h> 18#include <string.h>
18 19
@@ -40,7 +41,8 @@ static BIO_METHOD methods_biop =
40 NULL /* no bio_gets */, 41 NULL /* no bio_gets */,
41 bio_ctrl, 42 bio_ctrl,
42 bio_new, 43 bio_new,
43 bio_free 44 bio_free,
45 NULL /* no bio_callback_ctrl */
44}; 46};
45 47
46BIO_METHOD *BIO_s_bio(void) 48BIO_METHOD *BIO_s_bio(void)
@@ -64,7 +66,7 @@ struct bio_bio_st
64 66
65 size_t request; /* valid iff peer != NULL; 0 if len != 0, 67 size_t request; /* valid iff peer != NULL; 0 if len != 0,
66 * otherwise set by peer to number of bytes 68 * otherwise set by peer to number of bytes
67 * it (unsuccesfully) tried to read, 69 * it (unsuccessfully) tried to read,
68 * never more than buffer space (size-len) warrants. */ 70 * never more than buffer space (size-len) warrants. */
69}; 71};
70 72
@@ -195,6 +197,81 @@ static int bio_read(BIO *bio, char *buf, int size_)
195 return size; 197 return size;
196 } 198 }
197 199
200/* non-copying interface: provide pointer to available data in buffer
201 * bio_nread0: return number of available bytes
202 * bio_nread: also advance index
203 * (example usage: bio_nread0(), read from buffer, bio_nread()
204 * or just bio_nread(), read from buffer)
205 */
206/* WARNING: The non-copying interface is largely untested as of yet
207 * and may contain bugs. */
208static size_t bio_nread0(BIO *bio, char **buf)
209 {
210 struct bio_bio_st *b, *peer_b;
211 size_t num;
212
213 BIO_clear_retry_flags(bio);
214
215 if (!bio->init)
216 return 0;
217
218 b = bio->ptr;
219 assert(b != NULL);
220 assert(b->peer != NULL);
221 peer_b = b->peer->ptr;
222 assert(peer_b != NULL);
223 assert(peer_b->buf != NULL);
224
225 peer_b->request = 0;
226
227 if (peer_b->len == 0)
228 {
229 char dummy;
230
231 /* avoid code duplication -- nothing available for reading */
232 return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
233 }
234
235 num = peer_b->len;
236 if (peer_b->size < peer_b->offset + num)
237 /* no ring buffer wrap-around for non-copying interface */
238 num = peer_b->size - peer_b->offset;
239 assert(num > 0);
240
241 if (buf != NULL)
242 *buf = peer_b->buf + peer_b->offset;
243 return num;
244 }
245
246static size_t bio_nread(BIO *bio, char **buf, size_t num)
247 {
248 struct bio_bio_st *b, *peer_b;
249 size_t available;
250
251 available = bio_nread0(bio, buf);
252 if (num > available)
253 num = available;
254 if (num == 0)
255 return num;
256
257 b = bio->ptr;
258 peer_b = b->peer->ptr;
259
260 peer_b->len -= num;
261 if (peer_b->len)
262 {
263 peer_b->offset += num;
264 assert(peer_b->offset <= peer_b->size);
265 if (peer_b->offset == peer_b->size)
266 peer_b->offset = 0;
267 }
268 else
269 peer_b->offset = 0;
270
271 return num;
272 }
273
274
198static int bio_write(BIO *bio, char *buf, int num_) 275static int bio_write(BIO *bio, char *buf, int num_)
199 { 276 {
200 size_t num = num_; 277 size_t num = num_;
@@ -268,6 +345,78 @@ static int bio_write(BIO *bio, char *buf, int num_)
268 return num; 345 return num;
269 } 346 }
270 347
348/* non-copying interface: provide pointer to region to write to
349 * bio_nwrite0: check how much space is available
350 * bio_nwrite: also increase length
351 * (example usage: bio_nwrite0(), write to buffer, bio_nwrite()
352 * or just bio_nwrite(), write to buffer)
353 */
354static size_t bio_nwrite0(BIO *bio, char **buf)
355 {
356 struct bio_bio_st *b;
357 size_t num;
358 size_t write_offset;
359
360 BIO_clear_retry_flags(bio);
361
362 if (!bio->init)
363 return 0;
364
365 b = bio->ptr;
366 assert(b != NULL);
367 assert(b->peer != NULL);
368 assert(b->buf != NULL);
369
370 b->request = 0;
371 if (b->closed)
372 {
373 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE);
374 return -1;
375 }
376
377 assert(b->len <= b->size);
378
379 if (b->len == b->size)
380 {
381 BIO_set_retry_write(bio);
382 return -1;
383 }
384
385 num = b->size - b->len;
386 write_offset = b->offset + b->len;
387 if (write_offset >= b->size)
388 write_offset -= b->size;
389 if (write_offset + num > b->size)
390 /* no ring buffer wrap-around for non-copying interface
391 * (to fulfil the promise by BIO_ctrl_get_write_guarantee,
392 * BIO_nwrite may have to be called twice) */
393 num = b->size - write_offset;
394
395 if (buf != NULL)
396 *buf = b->buf + write_offset;
397 assert(write_offset + num <= b->size);
398
399 return num;
400 }
401
402static size_t bio_nwrite(BIO *bio, char **buf, size_t num)
403 {
404 struct bio_bio_st *b;
405 size_t space;
406
407 space = bio_nwrite0(bio, buf);
408 if (num > space)
409 num = space;
410 if (num == 0)
411 return num;
412 b = bio->ptr;
413 assert(b != NULL);
414 b->len += num;
415 assert(b->len <= b->size);
416
417 return num;
418 }
419
271 420
272static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) 421static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
273 { 422 {
@@ -331,7 +480,7 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
331 480
332 case BIO_C_GET_WRITE_GUARANTEE: 481 case BIO_C_GET_WRITE_GUARANTEE:
333 /* How many bytes can the caller feed to the next write 482 /* How many bytes can the caller feed to the next write
334 * withouth having to keep any? */ 483 * without having to keep any? */
335 if (b->peer == NULL || b->closed) 484 if (b->peer == NULL || b->closed)
336 ret = 0; 485 ret = 0;
337 else 486 else
@@ -339,18 +488,42 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
339 break; 488 break;
340 489
341 case BIO_C_GET_READ_REQUEST: 490 case BIO_C_GET_READ_REQUEST:
342 /* If the peer unsuccesfully tried to read, how many bytes 491 /* If the peer unsuccessfully tried to read, how many bytes
343 * were requested? (As with BIO_CTRL_PENDING, that number 492 * were requested? (As with BIO_CTRL_PENDING, that number
344 * can usually be treated as boolean.) */ 493 * can usually be treated as boolean.) */
345 ret = (long) b->request; 494 ret = (long) b->request;
346 break; 495 break;
347 496
497 case BIO_C_RESET_READ_REQUEST:
498 /* Reset request. (Can be useful after read attempts
499 * at the other side that are meant to be non-blocking,
500 * e.g. when probing SSL_read to see if any data is
501 * available.) */
502 b->request = 0;
503 ret = 1;
504 break;
505
348 case BIO_C_SHUTDOWN_WR: 506 case BIO_C_SHUTDOWN_WR:
349 /* similar to shutdown(..., SHUT_WR) */ 507 /* similar to shutdown(..., SHUT_WR) */
350 b->closed = 1; 508 b->closed = 1;
351 ret = 1; 509 ret = 1;
352 break; 510 break;
353 511
512 case BIO_C_NREAD:
513 /* non-copying read */
514 ret = (long) bio_nread(bio, ptr, (size_t) num);
515 break;
516
517 case BIO_C_NWRITE0:
518 /* prepare for non-copying write */
519 ret = (long) bio_nwrite0(bio, ptr);
520 break;
521
522 case BIO_C_NWRITE:
523 /* non-copying write */
524 ret = (long) bio_nwrite(bio, ptr, (size_t) num);
525 break;
526
354 527
355 /* standard CTRL codes follow */ 528 /* standard CTRL codes follow */
356 529
@@ -586,3 +759,78 @@ size_t BIO_ctrl_get_read_request(BIO *bio)
586 { 759 {
587 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); 760 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
588 } 761 }
762
763int BIO_ctrl_reset_read_request(BIO *bio)
764 {
765 return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
766 }
767
768
769/* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now
770 * (conceivably some other BIOs could allow non-copying reads and writes too.)
771 */
772int BIO_nread0(BIO *bio, char **buf)
773 {
774 long ret;
775
776 if (!bio->init)
777 {
778 BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED);
779 return -2;
780 }
781
782 ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf);
783 if (ret > INT_MAX)
784 return INT_MAX;
785 else
786 return (int) ret;
787 }
788
789int BIO_nread(BIO *bio, char **buf, int num)
790 {
791 int ret;
792
793 if (!bio->init)
794 {
795 BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED);
796 return -2;
797 }
798
799 ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf);
800 if (ret > 0)
801 bio->num_read += ret;
802 return ret;
803 }
804
805int BIO_nwrite0(BIO *bio, char **buf)
806 {
807 long ret;
808
809 if (!bio->init)
810 {
811 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED);
812 return -2;
813 }
814
815 ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf);
816 if (ret > INT_MAX)
817 return INT_MAX;
818 else
819 return (int) ret;
820 }
821
822int BIO_nwrite(BIO *bio, char **buf, int num)
823 {
824 int ret;
825
826 if (!bio->init)
827 {
828 BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED);
829 return -2;
830 }
831
832 ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf);
833 if (ret > 0)
834 bio->num_read += ret;
835 return ret;
836 }
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
index 68c46e3d69..22d00b369e 100644
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ b/src/lib/libcrypto/bio/bss_conn.c
@@ -90,11 +90,11 @@ typedef struct bio_connect_st
90 struct sockaddr_in them; 90 struct sockaddr_in them;
91 91
92 /* int socket; this will be kept in bio->num so that it is 92 /* int socket; this will be kept in bio->num so that it is
93 * compatable with the bss_sock bio */ 93 * compatible with the bss_sock bio */
94 94
95 /* called when the connection is initially made 95 /* called when the connection is initially made
96 * callback(BIO,state,ret); The callback should return 96 * callback(BIO,state,ret); The callback should return
97 * 'ret'. state is for compatablity with the ssl info_callback */ 97 * 'ret'. state is for compatibility with the ssl info_callback */
98 int (*info_callback)(); 98 int (*info_callback)();
99 } BIO_CONNECT; 99 } BIO_CONNECT;
100 100
@@ -104,6 +104,7 @@ static int conn_puts(BIO *h,char *str);
104static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); 104static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2);
105static int conn_new(BIO *h); 105static int conn_new(BIO *h);
106static int conn_free(BIO *data); 106static int conn_free(BIO *data);
107static long conn_callback_ctrl(BIO *h,int cmd,void *(*fp)());
107 108
108static int conn_state(BIO *b, BIO_CONNECT *c); 109static int conn_state(BIO *b, BIO_CONNECT *c);
109static void conn_close_socket(BIO *data); 110static void conn_close_socket(BIO *data);
@@ -121,6 +122,7 @@ static BIO_METHOD methods_connectp=
121 conn_ctrl, 122 conn_ctrl,
122 conn_new, 123 conn_new,
123 conn_free, 124 conn_free,
125 conn_callback_ctrl,
124 }; 126 };
125 127
126static int conn_state(BIO *b, BIO_CONNECT *c) 128static int conn_state(BIO *b, BIO_CONNECT *c)
@@ -494,7 +496,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
494 *((int *)ptr)=data->port; 496 *((int *)ptr)=data->port;
495 } 497 }
496 if ((!b->init) || (ptr == NULL)) 498 if ((!b->init) || (ptr == NULL))
497 *pptr="not initalised"; 499 *pptr="not initialized";
498 ret=1; 500 ret=1;
499 } 501 }
500 break; 502 break;
@@ -564,16 +566,25 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
564 case BIO_CTRL_FLUSH: 566 case BIO_CTRL_FLUSH:
565 break; 567 break;
566 case BIO_CTRL_DUP: 568 case BIO_CTRL_DUP:
569 {
567 dbio=(BIO *)ptr; 570 dbio=(BIO *)ptr;
568 if (data->param_port) 571 if (data->param_port)
569 BIO_set_conn_port(dbio,data->param_port); 572 BIO_set_conn_port(dbio,data->param_port);
570 if (data->param_hostname) 573 if (data->param_hostname)
571 BIO_set_conn_hostname(dbio,data->param_hostname); 574 BIO_set_conn_hostname(dbio,data->param_hostname);
572 BIO_set_nbio(dbio,data->nbio); 575 BIO_set_nbio(dbio,data->nbio);
573 (void)BIO_set_info_callback(dbio,data->info_callback); 576 (void)BIO_set_info_callback(dbio,(void *(*)())(data->info_callback));
577 }
574 break; 578 break;
575 case BIO_CTRL_SET_CALLBACK: 579 case BIO_CTRL_SET_CALLBACK:
576 data->info_callback=(int (*)())ptr; 580 {
581#if 0 /* FIXME: Should this be used? -- Richard Levitte */
582 BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
583 ret = -1;
584#else
585 ret=0;
586#endif
587 }
577 break; 588 break;
578 case BIO_CTRL_GET_CALLBACK: 589 case BIO_CTRL_GET_CALLBACK:
579 { 590 {
@@ -590,6 +601,27 @@ static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
590 return(ret); 601 return(ret);
591 } 602 }
592 603
604static long conn_callback_ctrl(BIO *b, int cmd, void *(*fp)())
605 {
606 long ret=1;
607 BIO_CONNECT *data;
608
609 data=(BIO_CONNECT *)b->ptr;
610
611 switch (cmd)
612 {
613 case BIO_CTRL_SET_CALLBACK:
614 {
615 data->info_callback=(int (*)())fp;
616 }
617 break;
618 default:
619 ret=0;
620 break;
621 }
622 return(ret);
623 }
624
593static int conn_puts(BIO *bp, char *str) 625static int conn_puts(BIO *bp, char *str)
594 { 626 {
595 int n,ret; 627 int n,ret;
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
index 52c0c39df0..0d44dc3889 100644
--- a/src/lib/libcrypto/bio/bss_file.c
+++ b/src/lib/libcrypto/bio/bss_file.c
@@ -91,6 +91,7 @@ static BIO_METHOD methods_filep=
91 file_ctrl, 91 file_ctrl,
92 file_new, 92 file_new,
93 file_free, 93 file_free,
94 NULL,
94 }; 95 };
95 96
96BIO *BIO_new_file(const char *filename, const char *mode) 97BIO *BIO_new_file(const char *filename, const char *mode)
@@ -171,7 +172,7 @@ static int MS_CALLBACK file_write(BIO *b, char *in, int inl)
171 if (fwrite(in,(int)inl,1,(FILE *)b->ptr)) 172 if (fwrite(in,(int)inl,1,(FILE *)b->ptr))
172 ret=inl; 173 ret=inl;
173 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ 174 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
174 /* acording to Tim Hudson <tjh@cryptsoft.com>, the commented 175 /* according to Tim Hudson <tjh@cryptsoft.com>, the commented
175 * out version above can cause 'inl' write calls under 176 * out version above can cause 'inl' write calls under
176 * some stupid stdio implementations (VMS) */ 177 * some stupid stdio implementations (VMS) */
177 } 178 }
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
index db82e757e7..4308b19663 100644
--- a/src/lib/libcrypto/bio/bss_log.c
+++ b/src/lib/libcrypto/bio/bss_log.c
@@ -72,6 +72,8 @@
72#else 72#else
73#include <syslog.h> 73#include <syslog.h>
74#endif 74#endif
75#else
76#include <process.h>
75#endif 77#endif
76 78
77#include "cryptlib.h" 79#include "cryptlib.h"
@@ -98,6 +100,7 @@ static BIO_METHOD methods_slg=
98 slg_ctrl, 100 slg_ctrl,
99 slg_new, 101 slg_new,
100 slg_free, 102 slg_free,
103 NULL,
101 }; 104 };
102 105
103BIO_METHOD *BIO_s_log(void) 106BIO_METHOD *BIO_s_log(void)
@@ -131,8 +134,10 @@ static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
131 char* buf= in; 134 char* buf= in;
132 char* pp; 135 char* pp;
133#if defined(WIN32) 136#if defined(WIN32)
134 LPTSTR lpszStrings[1]; 137 LPCSTR lpszStrings[2];
135 WORD evtype= EVENTLOG_ERROR_TYPE; 138 WORD evtype= EVENTLOG_ERROR_TYPE;
139 int pid = _getpid();
140 char pidbuf[20];
136#else 141#else
137 int priority; 142 int priority;
138#endif 143#endif
@@ -156,10 +161,13 @@ static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
156 evtype= EVENTLOG_ERROR_TYPE; 161 evtype= EVENTLOG_ERROR_TYPE;
157 pp= buf; 162 pp= buf;
158 } 163 }
159 lpszStrings[0]= pp; 164
165 sprintf(pidbuf, "[%d] ", pid);
166 lpszStrings[0] = pidbuf;
167 lpszStrings[1] = pp;
160 168
161 if(b->ptr) 169 if(b->ptr)
162 ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0, 170 ReportEvent(b->ptr, evtype, 0, 1024, NULL, 2, 0,
163 lpszStrings, NULL); 171 lpszStrings, NULL);
164#else 172#else
165 if(strncmp(buf, "ERR ", 4) == 0){ 173 if(strncmp(buf, "ERR ", 4) == 0){
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c
index 7e749a503e..41eab92415 100644
--- a/src/lib/libcrypto/bio/bss_mem.c
+++ b/src/lib/libcrypto/bio/bss_mem.c
@@ -79,6 +79,7 @@ static BIO_METHOD mem_method=
79 mem_ctrl, 79 mem_ctrl,
80 mem_new, 80 mem_new,
81 mem_free, 81 mem_free,
82 NULL,
82 }; 83 };
83 84
84/* bio->num is used to hold the value to return on 'empty', if it is 85/* bio->num is used to hold the value to return on 'empty', if it is
@@ -89,6 +90,26 @@ BIO_METHOD *BIO_s_mem(void)
89 return(&mem_method); 90 return(&mem_method);
90 } 91 }
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
92static int mem_new(BIO *bi) 113static int mem_new(BIO *bi)
93 { 114 {
94 BUF_MEM *b; 115 BUF_MEM *b;
@@ -109,7 +130,10 @@ static int mem_free(BIO *a)
109 { 130 {
110 if ((a->init) && (a->ptr != NULL)) 131 if ((a->init) && (a->ptr != NULL))
111 { 132 {
112 BUF_MEM_free((BUF_MEM *)a->ptr); 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);
113 a->ptr=NULL; 137 a->ptr=NULL;
114 } 138 }
115 } 139 }
@@ -126,17 +150,18 @@ static int mem_read(BIO *b, char *out, int outl)
126 bm=(BUF_MEM *)b->ptr; 150 bm=(BUF_MEM *)b->ptr;
127 BIO_clear_retry_flags(b); 151 BIO_clear_retry_flags(b);
128 ret=(outl > bm->length)?bm->length:outl; 152 ret=(outl > bm->length)?bm->length:outl;
129 if ((out != NULL) && (ret > 0)) 153 if ((out != NULL) && (ret > 0)) {
130 {
131 memcpy(out,bm->data,ret); 154 memcpy(out,bm->data,ret);
132 bm->length-=ret; 155 bm->length-=ret;
133 /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */ 156 /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */
134 from=(char *)&(bm->data[ret]); 157 if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
135 to=(char *)&(bm->data[0]); 158 else {
136 for (i=0; i<bm->length; i++) 159 from=(char *)&(bm->data[ret]);
137 to[i]=from[i]; 160 to=(char *)&(bm->data[0]);
161 for (i=0; i<bm->length; i++)
162 to[i]=from[i];
138 } 163 }
139 else if (bm->length == 0) 164 } else if (bm->length == 0)
140 { 165 {
141 if (b->num != 0) 166 if (b->num != 0)
142 BIO_set_retry_read(b); 167 BIO_set_retry_read(b);
@@ -158,6 +183,11 @@ static int mem_write(BIO *b, char *in, int inl)
158 goto end; 183 goto end;
159 } 184 }
160 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
161 BIO_clear_retry_flags(b); 191 BIO_clear_retry_flags(b);
162 blen=bm->length; 192 blen=bm->length;
163 if (BUF_MEM_grow(bm,blen+inl) != (blen+inl)) 193 if (BUF_MEM_grow(bm,blen+inl) != (blen+inl))
@@ -178,9 +208,15 @@ static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
178 switch (cmd) 208 switch (cmd)
179 { 209 {
180 case BIO_CTRL_RESET: 210 case BIO_CTRL_RESET:
181 if (bm->data != NULL) 211 if (bm->data != NULL) {
182 memset(bm->data,0,bm->max); 212 /* For read only case reset to the start again */
183 bm->length=0; 213 if(b->flags & BIO_FLAGS_MEM_RDONLY)
214 bm->data -= bm->max - bm->length;
215 else {
216 memset(bm->data,0,bm->max);
217 bm->length=0;
218 }
219 }
184 break; 220 break;
185 case BIO_CTRL_EOF: 221 case BIO_CTRL_EOF:
186 ret=(long)(bm->length == 0); 222 ret=(long)(bm->length == 0);
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c
index d04be888e5..aee18e3ada 100644
--- a/src/lib/libcrypto/bio/bss_null.c
+++ b/src/lib/libcrypto/bio/bss_null.c
@@ -79,6 +79,7 @@ static BIO_METHOD null_method=
79 null_ctrl, 79 null_ctrl,
80 null_new, 80 null_new,
81 null_free, 81 null_free,
82 NULL,
82 }; 83 };
83 84
84BIO_METHOD *BIO_s_null(void) 85BIO_METHOD *BIO_s_null(void)
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c
index 2ef040057e..4ad0739464 100644
--- a/src/lib/libcrypto/bio/bss_rtcp.c
+++ b/src/lib/libcrypto/bio/bss_rtcp.c
@@ -107,6 +107,7 @@ static BIO_METHOD rtcp_method=
107 rtcp_ctrl, 107 rtcp_ctrl,
108 rtcp_new, 108 rtcp_new,
109 rtcp_free, 109 rtcp_free,
110 NULL,
110 }; 111 };
111 112
112BIO_METHOD *BIO_s_rtcp(void) 113BIO_METHOD *BIO_s_rtcp(void)
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
index d336b99fe8..8ce80ef68d 100644
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ b/src/lib/libcrypto/bio/bss_sock.c
@@ -95,6 +95,7 @@ static BIO_METHOD methods_sockp=
95 sock_ctrl, 95 sock_ctrl,
96 sock_new, 96 sock_new,
97 sock_free, 97 sock_free,
98 NULL,
98 }; 99 };
99 100
100BIO_METHOD *BIO_s_socket(void) 101BIO_METHOD *BIO_s_socket(void)
@@ -112,6 +113,7 @@ static BIO_METHOD methods_fdp=
112 fd_ctrl, 113 fd_ctrl,
113 fd_new, 114 fd_new,
114 fd_free, 115 fd_free,
116 NULL,
115 }; 117 };
116 118
117BIO_METHOD *BIO_s_fd(void) 119BIO_METHOD *BIO_s_fd(void)
@@ -163,8 +165,7 @@ static int fd_free(BIO *a)
163 if (a->init) 165 if (a->init)
164 { 166 {
165#ifndef BIO_FD 167#ifndef BIO_FD
166 shutdown(a->num,2); 168 SHUTDOWN2(a->num);
167 closesocket(a->num);
168#else /* BIO_FD */ 169#else /* BIO_FD */
169 close(a->num); 170 close(a->num);
170#endif 171#endif
diff --git a/src/lib/libcrypto/bn/Makefile.ssl b/src/lib/libcrypto/bn/Makefile.ssl
index cf77869fab..fa23a43fa0 100644
--- a/src/lib/libcrypto/bn/Makefile.ssl
+++ b/src/lib/libcrypto/bn/Makefile.ssl
@@ -20,6 +20,13 @@ BN_ASM= bn_asm.o
20#BN_ASM= bn86-elf.o 20#BN_ASM= bn86-elf.o
21 21
22CFLAGS= $(INCLUDES) $(CFLAG) 22CFLAGS= $(INCLUDES) $(CFLAG)
23
24# We let the C compiler driver to take care of .s files. This is done in
25# order to be excused from maintaining a separate set of architecture
26# dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
27# gcc, then the driver will automatically translate it to -xarch=v8plus
28# and pass it down to assembler.
29AS=$(CC) -c
23ASFLAGS=$(CFLAGS) 30ASFLAGS=$(CFLAGS)
24 31
25GENERAL=Makefile 32GENERAL=Makefile
@@ -27,12 +34,12 @@ TEST=bntest.c exptest.c
27APPS= 34APPS=
28 35
29LIB=$(TOP)/libcrypto.a 36LIB=$(TOP)/libcrypto.a
30LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mul.c \ 37LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c \
31 bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \ 38 bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
32 bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c bn_recp.c bn_mont.c \ 39 bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c bn_recp.c bn_mont.c \
33 bn_mpi.c bn_exp2.c 40 bn_mpi.c bn_exp2.c
34 41
35LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_mul.o \ 42LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o \
36 bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \ 43 bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \
37 bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) bn_recp.o bn_mont.o \ 44 bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) bn_recp.o bn_mont.o \
38 bn_mpi.o bn_exp2.o 45 bn_mpi.o bn_exp2.o
@@ -49,12 +56,14 @@ top:
49 56
50all: lib 57all: lib
51 58
52knuth: bn_knuth.c 59bn_prime.h: bn_prime.pl
53 cc -pg -I.. -I../../include bn_knuth.c -o knuth $(LIB) #../../../libefence.a 60 $(PERL) bn_prime.pl >bn_prime.h
54 61
55knuth.fast: bn_knuth.c 62divtest: divtest.c ../../libcrypto.a
56 cc -pg -fast -I.. -I../../include bn_knuth.c -o knuth $(LIB) #../../../libefence.a 63 cc -I../../include divtest.c -o divtest ../../libcrypto.a
57 64
65bnbug: bnbug.c ../../libcrypto.a top
66 cc -g -I../../include bnbug.c -o bnbug ../../libcrypto.a
58 67
59lib: $(LIBOBJ) 68lib: $(LIBOBJ)
60 $(AR) $(LIB) $(LIBOBJ) 69 $(AR) $(LIB) $(LIBOBJ)
@@ -113,13 +122,6 @@ asm/sparcv8plus-gcc27.o: asm/sparcv8plus.S
113 $(CC) $(ASFLAGS) -E asm/sparcv8plus.S | \ 122 $(CC) $(ASFLAGS) -E asm/sparcv8plus.S | \
114 /usr/ccs/bin/as -xarch=v8plus - -o asm/sparcv8plus-gcc27.o 123 /usr/ccs/bin/as -xarch=v8plus - -o asm/sparcv8plus-gcc27.o
115 124
116# MIPS 64 bit assember
117asm/mips3.o: asm/mips3.s
118
119# MIPS 32 bit assember
120asm/mips1.o: asm/mips1.s
121 /usr/bin/as -O2 -o asm/mips1.o asm/mips1.s
122
123files: 125files:
124 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 126 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
125 127
@@ -168,109 +170,117 @@ bn_add.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
168bn_add.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 170bn_add.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
169bn_add.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 171bn_add.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
170bn_add.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 172bn_add.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
171bn_add.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 173bn_add.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
172bn_add.o: ../cryptlib.h bn_lcl.h 174bn_add.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
173bn_asm.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 175bn_asm.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
174bn_asm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 176bn_asm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
175bn_asm.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 177bn_asm.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
176bn_asm.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 178bn_asm.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
177bn_asm.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 179bn_asm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
178bn_asm.o: ../cryptlib.h bn_lcl.h 180bn_asm.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
179bn_blind.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 181bn_blind.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
180bn_blind.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 182bn_blind.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
181bn_blind.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 183bn_blind.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
182bn_blind.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 184bn_blind.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
183bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 185bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
184bn_blind.o: ../cryptlib.h bn_lcl.h 186bn_blind.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
187bn_ctx.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
188bn_ctx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
189bn_ctx.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
190bn_ctx.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
191bn_ctx.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
192bn_ctx.o: ../../include/openssl/stack.h ../cryptlib.h
185bn_div.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 193bn_div.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
186bn_div.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 194bn_div.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
187bn_div.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 195bn_div.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
188bn_div.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 196bn_div.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
189bn_div.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 197bn_div.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
190bn_div.o: ../cryptlib.h bn_lcl.h 198bn_div.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
191bn_err.o: ../../include/openssl/bn.h ../../include/openssl/err.h 199bn_err.o: ../../include/openssl/bn.h ../../include/openssl/err.h
192bn_err.o: ../../include/openssl/opensslconf.h 200bn_err.o: ../../include/openssl/opensslconf.h
193bn_exp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 201bn_exp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
194bn_exp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 202bn_exp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
195bn_exp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 203bn_exp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
196bn_exp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 204bn_exp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
197bn_exp.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 205bn_exp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
198bn_exp.o: ../cryptlib.h bn_lcl.h 206bn_exp.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
199bn_exp2.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 207bn_exp2.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
200bn_exp2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 208bn_exp2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
201bn_exp2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 209bn_exp2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
202bn_exp2.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 210bn_exp2.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
203bn_exp2.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 211bn_exp2.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
204bn_exp2.o: ../cryptlib.h bn_lcl.h 212bn_exp2.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
205bn_gcd.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 213bn_gcd.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
206bn_gcd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 214bn_gcd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
207bn_gcd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 215bn_gcd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
208bn_gcd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 216bn_gcd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
209bn_gcd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 217bn_gcd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
210bn_gcd.o: ../cryptlib.h bn_lcl.h 218bn_gcd.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
211bn_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 219bn_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
212bn_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 220bn_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
213bn_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 221bn_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
214bn_lib.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 222bn_lib.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
215bn_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 223bn_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
216bn_lib.o: ../cryptlib.h bn_lcl.h 224bn_lib.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
217bn_mont.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 225bn_mont.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
218bn_mont.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 226bn_mont.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
219bn_mont.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 227bn_mont.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
220bn_mont.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 228bn_mont.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
221bn_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 229bn_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
222bn_mont.o: ../cryptlib.h bn_lcl.h 230bn_mont.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
223bn_mpi.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 231bn_mpi.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
224bn_mpi.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 232bn_mpi.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
225bn_mpi.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 233bn_mpi.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
226bn_mpi.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 234bn_mpi.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
227bn_mpi.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 235bn_mpi.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
228bn_mpi.o: ../cryptlib.h bn_lcl.h 236bn_mpi.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
229bn_mul.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 237bn_mul.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
230bn_mul.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 238bn_mul.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
231bn_mul.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 239bn_mul.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
232bn_mul.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 240bn_mul.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
233bn_mul.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 241bn_mul.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
234bn_mul.o: ../cryptlib.h bn_lcl.h 242bn_mul.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
235bn_prime.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 243bn_prime.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
236bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 244bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
237bn_prime.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 245bn_prime.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
238bn_prime.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 246bn_prime.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
239bn_prime.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 247bn_prime.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
240bn_prime.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h bn_prime.h 248bn_prime.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
249bn_prime.o: ../cryptlib.h bn_lcl.h bn_prime.h
241bn_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 250bn_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
242bn_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 251bn_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
243bn_print.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 252bn_print.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
244bn_print.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 253bn_print.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
245bn_print.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 254bn_print.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
246bn_print.o: ../cryptlib.h bn_lcl.h 255bn_print.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
247bn_rand.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 256bn_rand.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
248bn_rand.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 257bn_rand.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
249bn_rand.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 258bn_rand.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
250bn_rand.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 259bn_rand.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
251bn_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 260bn_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
252bn_rand.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h 261bn_rand.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
262bn_rand.o: ../cryptlib.h bn_lcl.h
253bn_recp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 263bn_recp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
254bn_recp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 264bn_recp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
255bn_recp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 265bn_recp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
256bn_recp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 266bn_recp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
257bn_recp.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 267bn_recp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
258bn_recp.o: ../cryptlib.h bn_lcl.h 268bn_recp.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
259bn_shift.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 269bn_shift.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
260bn_shift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 270bn_shift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
261bn_shift.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 271bn_shift.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
262bn_shift.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 272bn_shift.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
263bn_shift.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 273bn_shift.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
264bn_shift.o: ../cryptlib.h bn_lcl.h 274bn_shift.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
265bn_sqr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 275bn_sqr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
266bn_sqr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 276bn_sqr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
267bn_sqr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 277bn_sqr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
268bn_sqr.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 278bn_sqr.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
269bn_sqr.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 279bn_sqr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
270bn_sqr.o: ../cryptlib.h bn_lcl.h 280bn_sqr.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
271bn_word.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 281bn_word.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
272bn_word.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 282bn_word.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
273bn_word.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 283bn_word.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
274bn_word.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 284bn_word.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
275bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 285bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
276bn_word.o: ../cryptlib.h bn_lcl.h 286bn_word.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
diff --git a/src/lib/libcrypto/bn/asm/README b/src/lib/libcrypto/bn/asm/README
index d93fbff77f..86bf64cfc2 100644
--- a/src/lib/libcrypto/bn/asm/README
+++ b/src/lib/libcrypto/bn/asm/README
@@ -1,5 +1,5 @@
1All assember in this directory are just version of the file 1All assember in this directory are just version of the file
2crypto/bn/bn_mulw.c. 2crypto/bn/bn_asm.c.
3 3
4Quite a few of these files are just the assember output from gcc since on 4Quite a few of these files are just the assember output from gcc since on
5quite a few machines they are 2 times faster than the system compiler. 5quite a few machines they are 2 times faster than the system compiler.
@@ -15,13 +15,6 @@ On the 2 alpha C compilers I had access to, it was not possible to do
15were 64 bits). So the hand assember gives access to the 128 bit result and 15were 64 bits). So the hand assember gives access to the 128 bit result and
16a 2 times speedup :-). 16a 2 times speedup :-).
17 17
18The x86xxxx.obj files are the assembled version of x86xxxx.asm files.
19I had such a hard time finding a macro assember for Microsoft, I decided to
20include the object file to save others the hassle :-).
21
22I have also included uu encoded versions of the .obj incase they get
23trashed.
24
25There are 2 versions of assember for the HP PA-RISC. 18There are 2 versions of assember for the HP PA-RISC.
26pa-risc.s is the origional one which works fine. 19pa-risc.s is the origional one which works fine.
27pa-risc2.s is a new version that often generates warnings but if the 20pa-risc2.s is a new version that often generates warnings but if the
diff --git a/src/lib/libcrypto/bn/asm/alpha.s b/src/lib/libcrypto/bn/asm/alpha.s
index a351694ca2..555ff0b92d 100644
--- a/src/lib/libcrypto/bn/asm/alpha.s
+++ b/src/lib/libcrypto/bn/asm/alpha.s
@@ -694,567 +694,1868 @@ bn_mul_comba8:
694bn_mul_comba8..ng: 694bn_mul_comba8..ng:
695 .frame $30,0,$26,0 695 .frame $30,0,$26,0
696 .prologue 0 696 .prologue 0
697 697 ldq $1, 0($17)
698 subq $30, 16, $30 698 ldq $2, 0($18)
699 ldq $0, 0($17) 699 zapnot $1, 15, $7
700 srl $2, 32, $8
701 mulq $8, $7, $22
702 srl $1, 32, $6
703 zapnot $2, 15, $5
704 mulq $5, $6, $4
705 mulq $7, $5, $24
706 addq $22, $4, $22
707 cmpult $22, $4, $1
708 mulq $6, $8, $3
709 beq $1, $173
710 bis $31, 1, $1
711 sll $1, 32, $1
712 addq $3, $1, $3
713$173:
714 sll $22, 32, $4
715 addq $24, $4, $24
716 stq $24, 0($16)
717 ldq $2, 0($17)
718 ldq $1, 8($18)
719 zapnot $2, 15, $7
720 srl $1, 32, $8
721 mulq $8, $7, $25
722 zapnot $1, 15, $5
723 mulq $7, $5, $0
724 srl $2, 32, $6
725 mulq $5, $6, $23
726 mulq $6, $8, $6
727 srl $22, 32, $1
728 cmpult $24, $4, $2
729 addq $3, $1, $3
730 addq $2, $3, $22
731 addq $25, $23, $25
732 cmpult $25, $23, $1
733 bis $31, 1, $2
734 beq $1, $177
735 sll $2, 32, $1
736 addq $6, $1, $6
737$177:
738 sll $25, 32, $23
700 ldq $1, 0($18) 739 ldq $1, 0($18)
701 stq $9, 0($30) 740 addq $0, $23, $0
702 stq $10, 8($30) 741 bis $0, $0, $7
703 ldq $2, 8($17) 742 ldq $3, 8($17)
704 ldq $3, 8($18) 743 addq $22, $7, $22
705 ldq $4, 16($17) 744 srl $1, 32, $8
706 ldq $5, 16($18) 745 cmpult $22, $7, $4
707 ldq $6, 24($17) 746 zapnot $3, 15, $7
708 ldq $7, 24($18) 747 mulq $8, $7, $28
709 ldq $8, 8($17) 748 zapnot $1, 15, $5
710 ldq $22, 8($18) 749 mulq $7, $5, $21
711 ldq $23, 8($17) 750 srl $25, 32, $1
712 ldq $24, 8($18) 751 cmpult $0, $23, $2
713 ldq $25, 8($17) 752 addq $6, $1, $6
714 ldq $27, 8($18) 753 addq $2, $6, $6
715 ldq $28, 8($17) 754 addq $4, $6, $24
716 ldq $21, 8($18) 755 srl $3, 32, $6
717 bis $31, $31, $9 756 mulq $5, $6, $2
718 mulq $0, $1, $20 757 mulq $6, $8, $6
719 umulh $0, $1, $19 758 addq $28, $2, $28
720 stq $20, 0($16) 759 cmpult $28, $2, $1
721 bis $31, $31, $20 760 bis $31, 1, $2
722 mulq $0, $3, $10 761 beq $1, $181
723 umulh $0, $3, $17 762 sll $2, 32, $1
724 addq $19, $10, $19 763 addq $6, $1, $6
725 cmpult $19, $10, $18 764$181:
726 addq $18, $17, $17 765 sll $28, 32, $2
727 addq $9, $17, $9 766 addq $21, $2, $21
728 cmpult $9, $17, $10 767 bis $21, $21, $7
729 addq $20, $10, $20 768 addq $22, $7, $22
730 mulq $2, $1, $18 769 stq $22, 8($16)
731 umulh $2, $1, $17 770 ldq $3, 16($17)
732 addq $19, $18, $19 771 ldq $1, 0($18)
733 cmpult $19, $18, $10 772 cmpult $22, $7, $4
734 addq $10, $17, $17 773 zapnot $3, 15, $7
735 addq $9, $17, $9 774 srl $1, 32, $8
736 cmpult $9, $17, $18 775 mulq $8, $7, $22
737 addq $20, $18, $20 776 zapnot $1, 15, $5
738 stq $19, 8($16) 777 mulq $7, $5, $20
739 bis $31, $31, $19 778 srl $28, 32, $1
740 mulq $0, $5, $10 779 cmpult $21, $2, $2
741 umulh $0, $5, $17 780 addq $6, $1, $6
742 addq $9, $10, $9 781 addq $2, $6, $6
743 cmpult $9, $10, $18 782 addq $4, $6, $6
744 addq $18, $17, $17 783 addq $24, $6, $24
745 addq $20, $17, $20 784 cmpult $24, $6, $23
746 cmpult $20, $17, $10 785 srl $3, 32, $6
747 addq $19, $10, $19 786 mulq $5, $6, $2
748 mulq $2, $3, $18 787 mulq $6, $8, $6
749 umulh $2, $3, $17 788 addq $22, $2, $22
750 addq $9, $18, $9 789 cmpult $22, $2, $1
751 cmpult $9, $18, $10 790 bis $31, 1, $2
752 addq $10, $17, $17 791 beq $1, $185
753 addq $20, $17, $20 792 sll $2, 32, $1
754 cmpult $20, $17, $18 793 addq $6, $1, $6
755 addq $19, $18, $19 794$185:
756 mulq $4, $1, $10 795 sll $22, 32, $2
757 umulh $4, $1, $17 796 ldq $1, 8($18)
758 addq $9, $10, $9
759 cmpult $9, $10, $18
760 addq $18, $17, $17
761 addq $20, $17, $20
762 cmpult $20, $17, $10
763 addq $19, $10, $19
764 stq $9, 16($16)
765 bis $31, $31, $9
766 mulq $0, $7, $18
767 umulh $0, $7, $17
768 addq $20, $18, $20
769 cmpult $20, $18, $10
770 addq $10, $17, $17
771 addq $19, $17, $19
772 cmpult $19, $17, $18
773 addq $9, $18, $9
774 mulq $2, $5, $10
775 umulh $2, $5, $17
776 addq $20, $10, $20
777 cmpult $20, $10, $18
778 addq $18, $17, $17
779 addq $19, $17, $19
780 cmpult $19, $17, $10
781 addq $9, $10, $9
782 mulq $4, $3, $18
783 umulh $4, $3, $17
784 addq $20, $18, $20
785 cmpult $20, $18, $10
786 addq $10, $17, $17
787 addq $19, $17, $19
788 cmpult $19, $17, $18
789 addq $9, $18, $9
790 mulq $6, $1, $10
791 umulh $6, $1, $17
792 addq $20, $10, $20
793 cmpult $20, $10, $18
794 addq $18, $17, $17
795 addq $19, $17, $19
796 cmpult $19, $17, $10
797 addq $9, $10, $9
798 stq $20, 24($16)
799 bis $31, $31, $20
800 mulq $0, $22, $18
801 umulh $0, $22, $17
802 addq $19, $18, $19
803 cmpult $19, $18, $10
804 addq $10, $17, $17
805 addq $9, $17, $9
806 cmpult $9, $17, $18
807 addq $20, $18, $20
808 mulq $2, $7, $10
809 umulh $2, $7, $17
810 addq $19, $10, $19
811 cmpult $19, $10, $18
812 addq $18, $17, $17
813 addq $9, $17, $9
814 cmpult $9, $17, $10
815 addq $20, $10, $20
816 mulq $4, $5, $18
817 umulh $4, $5, $17
818 addq $19, $18, $19
819 cmpult $19, $18, $10
820 addq $10, $17, $17
821 addq $9, $17, $9
822 cmpult $9, $17, $18
823 addq $20, $18, $20
824 mulq $6, $3, $10
825 umulh $6, $3, $17
826 addq $19, $10, $19
827 cmpult $19, $10, $18
828 addq $18, $17, $17
829 addq $9, $17, $9
830 cmpult $9, $17, $10
831 addq $20, $10, $20
832 mulq $8, $1, $18
833 umulh $8, $1, $17
834 addq $19, $18, $19
835 cmpult $19, $18, $10
836 addq $10, $17, $17
837 addq $9, $17, $9
838 cmpult $9, $17, $18
839 addq $20, $18, $20
840 stq $19, 32($16)
841 bis $31, $31, $19
842 mulq $0, $24, $10
843 umulh $0, $24, $17
844 addq $9, $10, $9
845 cmpult $9, $10, $18
846 addq $18, $17, $17
847 addq $20, $17, $20
848 cmpult $20, $17, $10
849 addq $19, $10, $19
850 mulq $2, $22, $18
851 umulh $2, $22, $17
852 addq $9, $18, $9
853 cmpult $9, $18, $10
854 addq $10, $17, $17
855 addq $20, $17, $20
856 cmpult $20, $17, $18
857 addq $19, $18, $19
858 mulq $4, $7, $10
859 umulh $4, $7, $17
860 addq $9, $10, $9
861 cmpult $9, $10, $18
862 addq $18, $17, $17
863 addq $20, $17, $20
864 cmpult $20, $17, $10
865 addq $19, $10, $19
866 mulq $6, $5, $18
867 umulh $6, $5, $17
868 addq $9, $18, $9
869 cmpult $9, $18, $10
870 addq $10, $17, $17
871 addq $20, $17, $20
872 cmpult $20, $17, $18
873 addq $19, $18, $19
874 mulq $8, $3, $10
875 umulh $8, $3, $17
876 addq $9, $10, $9
877 cmpult $9, $10, $18
878 addq $18, $17, $17
879 addq $20, $17, $20
880 cmpult $20, $17, $10
881 addq $19, $10, $19
882 mulq $23, $1, $18
883 umulh $23, $1, $17
884 addq $9, $18, $9
885 cmpult $9, $18, $10
886 addq $10, $17, $17
887 addq $20, $17, $20
888 cmpult $20, $17, $18
889 addq $19, $18, $19
890 stq $9, 40($16)
891 bis $31, $31, $9
892 mulq $0, $27, $10
893 umulh $0, $27, $17
894 addq $20, $10, $20
895 cmpult $20, $10, $18
896 addq $18, $17, $17
897 addq $19, $17, $19
898 cmpult $19, $17, $10
899 addq $9, $10, $9
900 mulq $2, $24, $18
901 umulh $2, $24, $17
902 addq $20, $18, $20
903 cmpult $20, $18, $10
904 addq $10, $17, $17
905 addq $19, $17, $19
906 cmpult $19, $17, $18
907 addq $9, $18, $9
908 mulq $4, $22, $10
909 umulh $4, $22, $17
910 addq $20, $10, $20
911 cmpult $20, $10, $18
912 addq $18, $17, $17
913 addq $19, $17, $19
914 cmpult $19, $17, $10
915 addq $9, $10, $9
916 mulq $6, $7, $18
917 umulh $6, $7, $17
918 addq $20, $18, $20
919 cmpult $20, $18, $10
920 addq $10, $17, $17
921 addq $19, $17, $19
922 cmpult $19, $17, $18
923 addq $9, $18, $9
924 mulq $8, $5, $10
925 umulh $8, $5, $17
926 addq $20, $10, $20
927 cmpult $20, $10, $18
928 addq $18, $17, $17
929 addq $19, $17, $19
930 cmpult $19, $17, $10
931 addq $9, $10, $9
932 mulq $23, $3, $18
933 umulh $23, $3, $17
934 addq $20, $18, $20
935 cmpult $20, $18, $10
936 addq $10, $17, $17
937 addq $19, $17, $19
938 cmpult $19, $17, $18
939 addq $9, $18, $9
940 mulq $25, $1, $10
941 umulh $25, $1, $17
942 addq $20, $10, $20
943 cmpult $20, $10, $18
944 addq $18, $17, $17
945 addq $19, $17, $19
946 cmpult $19, $17, $10
947 addq $9, $10, $9
948 stq $20, 48($16)
949 bis $31, $31, $20
950 mulq $0, $21, $18
951 umulh $0, $21, $17
952 addq $19, $18, $19
953 cmpult $19, $18, $10
954 addq $10, $17, $17
955 addq $9, $17, $9
956 cmpult $9, $17, $18
957 addq $20, $18, $20
958 mulq $2, $27, $10
959 umulh $2, $27, $17
960 addq $19, $10, $19
961 cmpult $19, $10, $18
962 addq $18, $17, $17
963 addq $9, $17, $9
964 cmpult $9, $17, $0
965 addq $20, $0, $20
966 mulq $4, $24, $10
967 umulh $4, $24, $18
968 addq $19, $10, $19
969 cmpult $19, $10, $17
970 addq $17, $18, $18
971 addq $9, $18, $9
972 cmpult $9, $18, $0
973 addq $20, $0, $20
974 mulq $6, $22, $10
975 umulh $6, $22, $17
976 addq $19, $10, $19
977 cmpult $19, $10, $18
978 addq $18, $17, $17
979 addq $9, $17, $9
980 cmpult $9, $17, $0
981 addq $20, $0, $20
982 mulq $8, $7, $10
983 umulh $8, $7, $18
984 addq $19, $10, $19
985 cmpult $19, $10, $17
986 addq $17, $18, $18
987 addq $9, $18, $9
988 cmpult $9, $18, $0
989 addq $20, $0, $20
990 mulq $23, $5, $10
991 umulh $23, $5, $17
992 addq $19, $10, $19
993 cmpult $19, $10, $18
994 addq $18, $17, $17
995 addq $9, $17, $9
996 cmpult $9, $17, $0
997 addq $20, $0, $20
998 mulq $25, $3, $10
999 umulh $25, $3, $18
1000 addq $19, $10, $19
1001 cmpult $19, $10, $17
1002 addq $17, $18, $18
1003 addq $9, $18, $9
1004 cmpult $9, $18, $0
1005 addq $20, $0, $20
1006 mulq $28, $1, $10
1007 umulh $28, $1, $17
1008 addq $19, $10, $19
1009 cmpult $19, $10, $18
1010 addq $18, $17, $17
1011 addq $9, $17, $9
1012 cmpult $9, $17, $0
1013 addq $20, $0, $20
1014 stq $19, 56($16)
1015 bis $31, $31, $19
1016 mulq $2, $21, $10
1017 umulh $2, $21, $18
1018 addq $9, $10, $9
1019 cmpult $9, $10, $17
1020 addq $17, $18, $18
1021 addq $20, $18, $20
1022 cmpult $20, $18, $0
1023 addq $19, $0, $19
1024 mulq $4, $27, $1
1025 umulh $4, $27, $10
1026 addq $9, $1, $9
1027 cmpult $9, $1, $17
1028 addq $17, $10, $10
1029 addq $20, $10, $20
1030 cmpult $20, $10, $18
1031 addq $19, $18, $19
1032 mulq $6, $24, $0
1033 umulh $6, $24, $2
1034 addq $9, $0, $9
1035 cmpult $9, $0, $1
1036 addq $1, $2, $2
1037 addq $20, $2, $20
1038 cmpult $20, $2, $17
1039 addq $19, $17, $19
1040 mulq $8, $22, $10
1041 umulh $8, $22, $18
1042 addq $9, $10, $9
1043 cmpult $9, $10, $0
1044 addq $0, $18, $18
1045 addq $20, $18, $20
1046 cmpult $20, $18, $1
1047 addq $19, $1, $19
1048 mulq $23, $7, $2
1049 umulh $23, $7, $17
1050 addq $9, $2, $9
1051 cmpult $9, $2, $10
1052 addq $10, $17, $17
1053 addq $20, $17, $20
1054 cmpult $20, $17, $0
1055 addq $19, $0, $19
1056 mulq $25, $5, $18
1057 umulh $25, $5, $1
1058 addq $9, $18, $9
1059 cmpult $9, $18, $2
1060 addq $2, $1, $1
1061 addq $20, $1, $20
1062 cmpult $20, $1, $10
1063 addq $19, $10, $19
1064 mulq $28, $3, $17
1065 umulh $28, $3, $0
1066 addq $9, $17, $9
1067 cmpult $9, $17, $18
1068 addq $18, $0, $0
1069 addq $20, $0, $20
1070 cmpult $20, $0, $2
1071 addq $19, $2, $19
1072 stq $9, 64($16)
1073 bis $31, $31, $9
1074 mulq $4, $21, $1
1075 umulh $4, $21, $10
1076 addq $20, $1, $20
1077 cmpult $20, $1, $17
1078 addq $17, $10, $10
1079 addq $19, $10, $19
1080 cmpult $19, $10, $18
1081 addq $9, $18, $9
1082 mulq $6, $27, $0
1083 umulh $6, $27, $2
1084 addq $20, $0, $20
1085 cmpult $20, $0, $3
1086 addq $3, $2, $2
1087 addq $19, $2, $19
1088 cmpult $19, $2, $1
1089 addq $9, $1, $9
1090 mulq $8, $24, $17
1091 umulh $8, $24, $10
1092 addq $20, $17, $20
1093 cmpult $20, $17, $18
1094 addq $18, $10, $10
1095 addq $19, $10, $19
1096 cmpult $19, $10, $4
1097 addq $9, $4, $9
1098 mulq $23, $22, $0
1099 umulh $23, $22, $3
1100 addq $20, $0, $20
1101 cmpult $20, $0, $2
1102 addq $2, $3, $3
1103 addq $19, $3, $19
1104 cmpult $19, $3, $1
1105 addq $9, $1, $9
1106 mulq $25, $7, $17
1107 umulh $25, $7, $18
1108 addq $20, $17, $20
1109 cmpult $20, $17, $10
1110 addq $10, $18, $18
1111 addq $19, $18, $19
1112 cmpult $19, $18, $4
1113 addq $9, $4, $9
1114 mulq $28, $5, $0
1115 umulh $28, $5, $2
1116 addq $20, $0, $20
1117 cmpult $20, $0, $3
1118 addq $3, $2, $2
1119 addq $19, $2, $19
1120 cmpult $19, $2, $1
1121 addq $9, $1, $9
1122 stq $20, 72($16)
1123 bis $31, $31, $20
1124 mulq $6, $21, $17
1125 umulh $6, $21, $10
1126 addq $19, $17, $19
1127 cmpult $19, $17, $18
1128 addq $18, $10, $10
1129 addq $9, $10, $9
1130 cmpult $9, $10, $4
1131 addq $20, $4, $20
1132 mulq $8, $27, $0
1133 umulh $8, $27, $3
1134 addq $19, $0, $19
1135 cmpult $19, $0, $2
1136 addq $2, $3, $3
1137 addq $9, $3, $9
1138 cmpult $9, $3, $1
1139 addq $20, $1, $20
1140 mulq $23, $24, $5
1141 umulh $23, $24, $17
1142 addq $19, $5, $19
1143 cmpult $19, $5, $18
1144 addq $18, $17, $17
1145 addq $9, $17, $9
1146 cmpult $9, $17, $10
1147 addq $20, $10, $20
1148 mulq $25, $22, $4
1149 umulh $25, $22, $6
1150 addq $19, $4, $19
1151 cmpult $19, $4, $0
1152 addq $0, $6, $6
1153 addq $9, $6, $9
1154 cmpult $9, $6, $2
1155 addq $20, $2, $20
1156 mulq $28, $7, $3
1157 umulh $28, $7, $1
1158 addq $19, $3, $19
1159 cmpult $19, $3, $5
1160 addq $5, $1, $1
1161 addq $9, $1, $9
1162 cmpult $9, $1, $18
1163 addq $20, $18, $20
1164 stq $19, 80($16)
1165 bis $31, $31, $19
1166 mulq $8, $21, $17
1167 umulh $8, $21, $10
1168 addq $9, $17, $9
1169 cmpult $9, $17, $4
1170 addq $4, $10, $10
1171 addq $20, $10, $20
1172 cmpult $20, $10, $0
1173 addq $19, $0, $19
1174 mulq $23, $27, $6
1175 umulh $23, $27, $2
1176 addq $9, $6, $9
1177 cmpult $9, $6, $3
1178 addq $3, $2, $2
1179 addq $20, $2, $20 797 addq $20, $2, $20
1180 cmpult $20, $2, $5 798 bis $20, $20, $7
1181 addq $19, $5, $19 799 ldq $4, 8($17)
1182 mulq $25, $24, $1 800 addq $24, $7, $24
1183 umulh $25, $24, $18 801 srl $1, 32, $8
1184 addq $9, $1, $9 802 cmpult $24, $7, $3
1185 cmpult $9, $1, $7 803 zapnot $4, 15, $7
1186 addq $7, $18, $18 804 mulq $8, $7, $25
1187 addq $20, $18, $20 805 zapnot $1, 15, $5
1188 cmpult $20, $18, $17 806 mulq $7, $5, $0
1189 addq $19, $17, $19 807 srl $22, 32, $1
1190 mulq $28, $22, $4 808 cmpult $20, $2, $2
1191 umulh $28, $22, $10 809 addq $6, $1, $6
1192 addq $9, $4, $9 810 addq $2, $6, $6
1193 cmpult $9, $4, $0 811 addq $3, $6, $6
1194 addq $0, $10, $10 812 addq $23, $6, $23
1195 addq $20, $10, $20 813 cmpult $23, $6, $22
1196 cmpult $20, $10, $8 814 srl $4, 32, $6
1197 addq $19, $8, $19 815 mulq $5, $6, $5
1198 stq $9, 88($16) 816 bis $31, 1, $21
1199 bis $31, $31, $9 817 addq $25, $5, $25
1200 mulq $23, $21, $6 818 cmpult $25, $5, $1
1201 umulh $23, $21, $3 819 mulq $6, $8, $6
1202 addq $20, $6, $20 820 beq $1, $189
1203 cmpult $20, $6, $2 821 sll $21, 32, $1
1204 addq $2, $3, $3 822 addq $6, $1, $6
1205 addq $19, $3, $19 823$189:
1206 cmpult $19, $3, $5 824 sll $25, 32, $5
1207 addq $9, $5, $9 825 ldq $2, 16($18)
1208 mulq $25, $27, $1 826 addq $0, $5, $0
1209 umulh $25, $27, $7 827 bis $0, $0, $7
1210 addq $20, $1, $20 828 ldq $4, 0($17)
1211 cmpult $20, $1, $18 829 addq $24, $7, $24
1212 addq $18, $7, $7 830 srl $2, 32, $8
1213 addq $19, $7, $19 831 cmpult $24, $7, $3
1214 cmpult $19, $7, $17 832 zapnot $4, 15, $7
1215 addq $9, $17, $9 833 mulq $8, $7, $28
1216 mulq $28, $24, $4 834 srl $25, 32, $1
1217 umulh $28, $24, $0 835 addq $6, $1, $6
1218 addq $20, $4, $20 836 cmpult $0, $5, $1
1219 cmpult $20, $4, $10 837 zapnot $2, 15, $5
1220 addq $10, $0, $0 838 addq $1, $6, $6
1221 addq $19, $0, $19 839 addq $3, $6, $6
1222 cmpult $19, $0, $8 840 addq $23, $6, $23
1223 addq $9, $8, $9 841 cmpult $23, $6, $1
1224 stq $20, 96($16) 842 srl $4, 32, $6
1225 bis $31, $31, $20 843 mulq $5, $6, $25
1226 mulq $25, $21, $22 844 mulq $7, $5, $2
1227 umulh $25, $21, $6 845 addq $1, $22, $22
1228 addq $19, $22, $19 846 addq $28, $25, $28
1229 cmpult $19, $22, $2 847 cmpult $28, $25, $1
848 mulq $6, $8, $6
849 beq $1, $193
850 sll $21, 32, $1
851 addq $6, $1, $6
852$193:
853 sll $28, 32, $25
854 addq $2, $25, $2
855 bis $2, $2, $7
856 addq $24, $7, $24
857 stq $24, 16($16)
858 ldq $4, 0($17)
859 ldq $5, 24($18)
860 cmpult $24, $7, $3
861 zapnot $4, 15, $7
862 srl $5, 32, $8
863 mulq $8, $7, $0
864 srl $28, 32, $1
865 cmpult $2, $25, $2
866 addq $6, $1, $6
867 addq $2, $6, $6
868 addq $3, $6, $6
869 addq $23, $6, $23
870 cmpult $23, $6, $1
871 srl $4, 32, $6
872 zapnot $5, 15, $5
873 mulq $5, $6, $24
874 mulq $7, $5, $2
875 addq $1, $22, $22
876 addq $0, $24, $0
877 cmpult $0, $24, $1
878 mulq $6, $8, $6
879 beq $1, $197
880 sll $21, 32, $1
881 addq $6, $1, $6
882$197:
883 sll $0, 32, $24
884 ldq $1, 16($18)
885 addq $2, $24, $2
886 bis $2, $2, $7
887 ldq $4, 8($17)
888 addq $23, $7, $23
889 srl $1, 32, $8
890 cmpult $23, $7, $3
891 zapnot $4, 15, $7
892 mulq $8, $7, $25
893 zapnot $1, 15, $5
894 mulq $7, $5, $21
895 srl $0, 32, $1
896 cmpult $2, $24, $2
897 addq $6, $1, $6
898 addq $2, $6, $6
899 addq $3, $6, $6
900 addq $22, $6, $22
901 cmpult $22, $6, $24
902 srl $4, 32, $6
903 mulq $5, $6, $5
904 bis $31, 1, $20
905 addq $25, $5, $25
906 cmpult $25, $5, $1
907 mulq $6, $8, $6
908 beq $1, $201
909 sll $20, 32, $1
910 addq $6, $1, $6
911$201:
912 sll $25, 32, $5
913 ldq $2, 8($18)
914 addq $21, $5, $21
915 bis $21, $21, $7
916 ldq $4, 16($17)
917 addq $23, $7, $23
918 srl $2, 32, $8
919 cmpult $23, $7, $3
920 zapnot $4, 15, $7
921 mulq $8, $7, $28
922 srl $25, 32, $1
923 addq $6, $1, $6
924 cmpult $21, $5, $1
925 zapnot $2, 15, $5
926 addq $1, $6, $6
927 addq $3, $6, $6
928 addq $22, $6, $22
929 cmpult $22, $6, $1
930 srl $4, 32, $6
931 mulq $5, $6, $25
932 mulq $7, $5, $5
933 addq $1, $24, $24
934 addq $28, $25, $28
935 cmpult $28, $25, $1
936 mulq $6, $8, $6
937 beq $1, $205
938 sll $20, 32, $1
939 addq $6, $1, $6
940$205:
941 sll $28, 32, $25
942 ldq $2, 0($18)
943 addq $5, $25, $5
944 bis $5, $5, $7
945 ldq $4, 24($17)
946 addq $23, $7, $23
947 srl $2, 32, $8
948 cmpult $23, $7, $3
949 zapnot $4, 15, $7
950 mulq $8, $7, $0
951 srl $28, 32, $1
952 addq $6, $1, $6
953 cmpult $5, $25, $1
954 zapnot $2, 15, $5
955 addq $1, $6, $6
956 addq $3, $6, $6
957 addq $22, $6, $22
958 cmpult $22, $6, $1
959 srl $4, 32, $6
960 mulq $5, $6, $25
961 mulq $7, $5, $2
962 addq $1, $24, $24
963 addq $0, $25, $0
964 cmpult $0, $25, $1
965 mulq $6, $8, $6
966 beq $1, $209
967 sll $20, 32, $1
968 addq $6, $1, $6
969$209:
970 sll $0, 32, $25
971 addq $2, $25, $2
972 bis $2, $2, $7
973 addq $23, $7, $23
974 stq $23, 24($16)
975 ldq $4, 32($17)
976 ldq $5, 0($18)
977 cmpult $23, $7, $3
978 zapnot $4, 15, $7
979 srl $5, 32, $8
980 mulq $8, $7, $28
981 srl $0, 32, $1
982 cmpult $2, $25, $2
983 addq $6, $1, $6
984 addq $2, $6, $6
985 addq $3, $6, $6
986 addq $22, $6, $22
987 cmpult $22, $6, $1
988 srl $4, 32, $6
989 zapnot $5, 15, $5
990 mulq $5, $6, $23
991 mulq $7, $5, $2
992 addq $1, $24, $24
993 addq $28, $23, $28
994 cmpult $28, $23, $1
995 mulq $6, $8, $6
996 beq $1, $213
997 sll $20, 32, $1
998 addq $6, $1, $6
999$213:
1000 sll $28, 32, $23
1001 ldq $1, 8($18)
1002 addq $2, $23, $2
1003 bis $2, $2, $7
1004 ldq $4, 24($17)
1005 addq $22, $7, $22
1006 srl $1, 32, $8
1007 cmpult $22, $7, $3
1008 zapnot $4, 15, $7
1009 mulq $8, $7, $25
1010 zapnot $1, 15, $5
1011 mulq $7, $5, $0
1012 srl $28, 32, $1
1013 cmpult $2, $23, $2
1014 addq $6, $1, $6
1230 addq $2, $6, $6 1015 addq $2, $6, $6
1231 addq $9, $6, $9 1016 addq $3, $6, $6
1232 cmpult $9, $6, $3 1017 addq $24, $6, $24
1233 addq $20, $3, $20 1018 cmpult $24, $6, $23
1234 mulq $28, $27, $5 1019 srl $4, 32, $6
1235 umulh $28, $27, $23 1020 mulq $5, $6, $5
1236 addq $19, $5, $19 1021 bis $31, 1, $21
1237 cmpult $19, $5, $1 1022 addq $25, $5, $25
1023 cmpult $25, $5, $1
1024 mulq $6, $8, $6
1025 beq $1, $217
1026 sll $21, 32, $1
1027 addq $6, $1, $6
1028$217:
1029 sll $25, 32, $5
1030 ldq $2, 16($18)
1031 addq $0, $5, $0
1032 bis $0, $0, $7
1033 ldq $4, 16($17)
1034 addq $22, $7, $22
1035 srl $2, 32, $8
1036 cmpult $22, $7, $3
1037 zapnot $4, 15, $7
1038 mulq $8, $7, $28
1039 srl $25, 32, $1
1040 addq $6, $1, $6
1041 cmpult $0, $5, $1
1042 zapnot $2, 15, $5
1043 addq $1, $6, $6
1044 addq $3, $6, $6
1045 addq $24, $6, $24
1046 cmpult $24, $6, $1
1047 srl $4, 32, $6
1048 mulq $5, $6, $25
1049 mulq $7, $5, $5
1238 addq $1, $23, $23 1050 addq $1, $23, $23
1239 addq $9, $23, $9 1051 addq $28, $25, $28
1240 cmpult $9, $23, $18 1052 cmpult $28, $25, $1
1241 addq $20, $18, $20 1053 mulq $6, $8, $6
1242 stq $19, 104($16) 1054 beq $1, $221
1243 bis $31, $31, $19 1055 sll $21, 32, $1
1244 mulq $28, $21, $7 1056 addq $6, $1, $6
1245 umulh $28, $21, $17 1057$221:
1246 addq $9, $7, $9 1058 sll $28, 32, $25
1247 cmpult $9, $7, $4 1059 ldq $2, 24($18)
1248 addq $4, $17, $17 1060 addq $5, $25, $5
1249 addq $20, $17, $20 1061 bis $5, $5, $7
1250 cmpult $20, $17, $10 1062 ldq $4, 8($17)
1251 addq $19, $10, $19 1063 addq $22, $7, $22
1252 stq $9, 112($16) 1064 srl $2, 32, $8
1253 stq $20, 120($16) 1065 cmpult $22, $7, $3
1254 ldq $9, 0($30) 1066 zapnot $4, 15, $7
1255 ldq $10, 8($30) 1067 mulq $8, $7, $0
1256 addq $30, 16, $30 1068 srl $28, 32, $1
1257 ret $31,($26),1 1069 addq $6, $1, $6
1070 cmpult $5, $25, $1
1071 zapnot $2, 15, $5
1072 addq $1, $6, $6
1073 addq $3, $6, $6
1074 addq $24, $6, $24
1075 cmpult $24, $6, $1
1076 srl $4, 32, $6
1077 mulq $5, $6, $25
1078 mulq $7, $5, $5
1079 addq $1, $23, $23
1080 addq $0, $25, $0
1081 cmpult $0, $25, $1
1082 mulq $6, $8, $6
1083 beq $1, $225
1084 sll $21, 32, $1
1085 addq $6, $1, $6
1086$225:
1087 sll $0, 32, $25
1088 ldq $2, 32($18)
1089 addq $5, $25, $5
1090 bis $5, $5, $7
1091 ldq $4, 0($17)
1092 addq $22, $7, $22
1093 srl $2, 32, $8
1094 cmpult $22, $7, $3
1095 zapnot $4, 15, $7
1096 mulq $8, $7, $28
1097 srl $0, 32, $1
1098 addq $6, $1, $6
1099 cmpult $5, $25, $1
1100 zapnot $2, 15, $5
1101 addq $1, $6, $6
1102 addq $3, $6, $6
1103 addq $24, $6, $24
1104 cmpult $24, $6, $1
1105 srl $4, 32, $6
1106 mulq $5, $6, $25
1107 mulq $7, $5, $2
1108 addq $1, $23, $23
1109 addq $28, $25, $28
1110 cmpult $28, $25, $1
1111 mulq $6, $8, $6
1112 beq $1, $229
1113 sll $21, 32, $1
1114 addq $6, $1, $6
1115$229:
1116 sll $28, 32, $25
1117 addq $2, $25, $2
1118 bis $2, $2, $7
1119 addq $22, $7, $22
1120 stq $22, 32($16)
1121 ldq $4, 0($17)
1122 ldq $5, 40($18)
1123 cmpult $22, $7, $3
1124 zapnot $4, 15, $7
1125 srl $5, 32, $8
1126 mulq $8, $7, $0
1127 srl $28, 32, $1
1128 cmpult $2, $25, $2
1129 addq $6, $1, $6
1130 addq $2, $6, $6
1131 addq $3, $6, $6
1132 addq $24, $6, $24
1133 cmpult $24, $6, $1
1134 srl $4, 32, $6
1135 zapnot $5, 15, $5
1136 mulq $5, $6, $22
1137 mulq $7, $5, $2
1138 addq $1, $23, $23
1139 addq $0, $22, $0
1140 cmpult $0, $22, $1
1141 mulq $6, $8, $6
1142 beq $1, $233
1143 sll $21, 32, $1
1144 addq $6, $1, $6
1145$233:
1146 sll $0, 32, $22
1147 ldq $1, 32($18)
1148 addq $2, $22, $2
1149 bis $2, $2, $7
1150 ldq $4, 8($17)
1151 addq $24, $7, $24
1152 srl $1, 32, $8
1153 cmpult $24, $7, $3
1154 zapnot $4, 15, $7
1155 mulq $8, $7, $25
1156 zapnot $1, 15, $5
1157 mulq $7, $5, $21
1158 srl $0, 32, $1
1159 cmpult $2, $22, $2
1160 addq $6, $1, $6
1161 addq $2, $6, $6
1162 addq $3, $6, $6
1163 addq $23, $6, $23
1164 cmpult $23, $6, $22
1165 srl $4, 32, $6
1166 mulq $5, $6, $5
1167 bis $31, 1, $20
1168 addq $25, $5, $25
1169 cmpult $25, $5, $1
1170 mulq $6, $8, $6
1171 beq $1, $237
1172 sll $20, 32, $1
1173 addq $6, $1, $6
1174$237:
1175 sll $25, 32, $5
1176 ldq $2, 24($18)
1177 addq $21, $5, $21
1178 bis $21, $21, $7
1179 ldq $4, 16($17)
1180 addq $24, $7, $24
1181 srl $2, 32, $8
1182 cmpult $24, $7, $3
1183 zapnot $4, 15, $7
1184 mulq $8, $7, $28
1185 srl $25, 32, $1
1186 addq $6, $1, $6
1187 cmpult $21, $5, $1
1188 zapnot $2, 15, $5
1189 addq $1, $6, $6
1190 addq $3, $6, $6
1191 addq $23, $6, $23
1192 cmpult $23, $6, $1
1193 srl $4, 32, $6
1194 mulq $5, $6, $25
1195 mulq $7, $5, $5
1196 addq $1, $22, $22
1197 addq $28, $25, $28
1198 cmpult $28, $25, $1
1199 mulq $6, $8, $6
1200 beq $1, $241
1201 sll $20, 32, $1
1202 addq $6, $1, $6
1203$241:
1204 sll $28, 32, $25
1205 ldq $2, 16($18)
1206 addq $5, $25, $5
1207 bis $5, $5, $7
1208 ldq $4, 24($17)
1209 addq $24, $7, $24
1210 srl $2, 32, $8
1211 cmpult $24, $7, $3
1212 zapnot $4, 15, $7
1213 mulq $8, $7, $0
1214 srl $28, 32, $1
1215 addq $6, $1, $6
1216 cmpult $5, $25, $1
1217 zapnot $2, 15, $5
1218 addq $1, $6, $6
1219 addq $3, $6, $6
1220 addq $23, $6, $23
1221 cmpult $23, $6, $1
1222 srl $4, 32, $6
1223 mulq $5, $6, $25
1224 mulq $7, $5, $5
1225 addq $1, $22, $22
1226 addq $0, $25, $0
1227 cmpult $0, $25, $1
1228 mulq $6, $8, $6
1229 beq $1, $245
1230 sll $20, 32, $1
1231 addq $6, $1, $6
1232$245:
1233 sll $0, 32, $25
1234 ldq $2, 8($18)
1235 addq $5, $25, $5
1236 bis $5, $5, $7
1237 ldq $4, 32($17)
1238 addq $24, $7, $24
1239 srl $2, 32, $8
1240 cmpult $24, $7, $3
1241 zapnot $4, 15, $7
1242 mulq $8, $7, $28
1243 srl $0, 32, $1
1244 addq $6, $1, $6
1245 cmpult $5, $25, $1
1246 zapnot $2, 15, $5
1247 addq $1, $6, $6
1248 addq $3, $6, $6
1249 addq $23, $6, $23
1250 cmpult $23, $6, $1
1251 srl $4, 32, $6
1252 mulq $5, $6, $25
1253 mulq $7, $5, $5
1254 addq $1, $22, $22
1255 addq $28, $25, $28
1256 cmpult $28, $25, $1
1257 mulq $6, $8, $6
1258 beq $1, $249
1259 sll $20, 32, $1
1260 addq $6, $1, $6
1261$249:
1262 sll $28, 32, $25
1263 ldq $2, 0($18)
1264 addq $5, $25, $5
1265 bis $5, $5, $7
1266 ldq $4, 40($17)
1267 addq $24, $7, $24
1268 srl $2, 32, $8
1269 cmpult $24, $7, $3
1270 zapnot $4, 15, $7
1271 mulq $8, $7, $0
1272 srl $28, 32, $1
1273 addq $6, $1, $6
1274 cmpult $5, $25, $1
1275 zapnot $2, 15, $5
1276 addq $1, $6, $6
1277 addq $3, $6, $6
1278 addq $23, $6, $23
1279 cmpult $23, $6, $1
1280 srl $4, 32, $6
1281 mulq $5, $6, $25
1282 mulq $7, $5, $2
1283 addq $1, $22, $22
1284 addq $0, $25, $0
1285 cmpult $0, $25, $1
1286 mulq $6, $8, $6
1287 beq $1, $253
1288 sll $20, 32, $1
1289 addq $6, $1, $6
1290$253:
1291 sll $0, 32, $25
1292 addq $2, $25, $2
1293 bis $2, $2, $7
1294 addq $24, $7, $24
1295 stq $24, 40($16)
1296 ldq $4, 48($17)
1297 ldq $5, 0($18)
1298 cmpult $24, $7, $3
1299 zapnot $4, 15, $7
1300 srl $5, 32, $8
1301 mulq $8, $7, $28
1302 srl $0, 32, $1
1303 cmpult $2, $25, $2
1304 addq $6, $1, $6
1305 addq $2, $6, $6
1306 addq $3, $6, $6
1307 addq $23, $6, $23
1308 cmpult $23, $6, $1
1309 srl $4, 32, $6
1310 zapnot $5, 15, $5
1311 mulq $5, $6, $24
1312 mulq $7, $5, $2
1313 addq $1, $22, $22
1314 addq $28, $24, $28
1315 cmpult $28, $24, $1
1316 mulq $6, $8, $6
1317 beq $1, $257
1318 sll $20, 32, $1
1319 addq $6, $1, $6
1320$257:
1321 sll $28, 32, $24
1322 ldq $1, 8($18)
1323 addq $2, $24, $2
1324 bis $2, $2, $7
1325 ldq $4, 40($17)
1326 addq $23, $7, $23
1327 srl $1, 32, $8
1328 cmpult $23, $7, $3
1329 zapnot $4, 15, $7
1330 mulq $8, $7, $25
1331 zapnot $1, 15, $5
1332 mulq $7, $5, $0
1333 srl $28, 32, $1
1334 cmpult $2, $24, $2
1335 addq $6, $1, $6
1336 addq $2, $6, $6
1337 addq $3, $6, $6
1338 addq $22, $6, $22
1339 cmpult $22, $6, $24
1340 srl $4, 32, $6
1341 mulq $5, $6, $5
1342 bis $31, 1, $21
1343 addq $25, $5, $25
1344 cmpult $25, $5, $1
1345 mulq $6, $8, $6
1346 beq $1, $261
1347 sll $21, 32, $1
1348 addq $6, $1, $6
1349$261:
1350 sll $25, 32, $5
1351 ldq $2, 16($18)
1352 addq $0, $5, $0
1353 bis $0, $0, $7
1354 ldq $4, 32($17)
1355 addq $23, $7, $23
1356 srl $2, 32, $8
1357 cmpult $23, $7, $3
1358 zapnot $4, 15, $7
1359 mulq $8, $7, $28
1360 srl $25, 32, $1
1361 addq $6, $1, $6
1362 cmpult $0, $5, $1
1363 zapnot $2, 15, $5
1364 addq $1, $6, $6
1365 addq $3, $6, $6
1366 addq $22, $6, $22
1367 cmpult $22, $6, $1
1368 srl $4, 32, $6
1369 mulq $5, $6, $25
1370 mulq $7, $5, $5
1371 addq $1, $24, $24
1372 addq $28, $25, $28
1373 cmpult $28, $25, $1
1374 mulq $6, $8, $6
1375 beq $1, $265
1376 sll $21, 32, $1
1377 addq $6, $1, $6
1378$265:
1379 sll $28, 32, $25
1380 ldq $2, 24($18)
1381 addq $5, $25, $5
1382 bis $5, $5, $7
1383 ldq $4, 24($17)
1384 addq $23, $7, $23
1385 srl $2, 32, $8
1386 cmpult $23, $7, $3
1387 zapnot $4, 15, $7
1388 mulq $8, $7, $0
1389 srl $28, 32, $1
1390 addq $6, $1, $6
1391 cmpult $5, $25, $1
1392 zapnot $2, 15, $5
1393 addq $1, $6, $6
1394 addq $3, $6, $6
1395 addq $22, $6, $22
1396 cmpult $22, $6, $1
1397 srl $4, 32, $6
1398 mulq $5, $6, $25
1399 mulq $7, $5, $5
1400 addq $1, $24, $24
1401 addq $0, $25, $0
1402 cmpult $0, $25, $1
1403 mulq $6, $8, $6
1404 beq $1, $269
1405 sll $21, 32, $1
1406 addq $6, $1, $6
1407$269:
1408 sll $0, 32, $25
1409 ldq $2, 32($18)
1410 addq $5, $25, $5
1411 bis $5, $5, $7
1412 ldq $4, 16($17)
1413 addq $23, $7, $23
1414 srl $2, 32, $8
1415 cmpult $23, $7, $3
1416 zapnot $4, 15, $7
1417 mulq $8, $7, $28
1418 srl $0, 32, $1
1419 addq $6, $1, $6
1420 cmpult $5, $25, $1
1421 zapnot $2, 15, $5
1422 addq $1, $6, $6
1423 addq $3, $6, $6
1424 addq $22, $6, $22
1425 cmpult $22, $6, $1
1426 srl $4, 32, $6
1427 mulq $5, $6, $25
1428 mulq $7, $5, $5
1429 addq $1, $24, $24
1430 addq $28, $25, $28
1431 cmpult $28, $25, $1
1432 mulq $6, $8, $6
1433 beq $1, $273
1434 sll $21, 32, $1
1435 addq $6, $1, $6
1436$273:
1437 sll $28, 32, $25
1438 ldq $2, 40($18)
1439 addq $5, $25, $5
1440 bis $5, $5, $7
1441 ldq $4, 8($17)
1442 addq $23, $7, $23
1443 srl $2, 32, $8
1444 cmpult $23, $7, $3
1445 zapnot $4, 15, $7
1446 mulq $8, $7, $0
1447 srl $28, 32, $1
1448 addq $6, $1, $6
1449 cmpult $5, $25, $1
1450 zapnot $2, 15, $5
1451 addq $1, $6, $6
1452 addq $3, $6, $6
1453 addq $22, $6, $22
1454 cmpult $22, $6, $1
1455 srl $4, 32, $6
1456 mulq $5, $6, $25
1457 mulq $7, $5, $5
1458 addq $1, $24, $24
1459 addq $0, $25, $0
1460 cmpult $0, $25, $1
1461 mulq $6, $8, $6
1462 beq $1, $277
1463 sll $21, 32, $1
1464 addq $6, $1, $6
1465$277:
1466 sll $0, 32, $25
1467 ldq $2, 48($18)
1468 addq $5, $25, $5
1469 bis $5, $5, $7
1470 ldq $4, 0($17)
1471 addq $23, $7, $23
1472 srl $2, 32, $8
1473 cmpult $23, $7, $3
1474 zapnot $4, 15, $7
1475 mulq $8, $7, $28
1476 srl $0, 32, $1
1477 addq $6, $1, $6
1478 cmpult $5, $25, $1
1479 zapnot $2, 15, $5
1480 addq $1, $6, $6
1481 addq $3, $6, $6
1482 addq $22, $6, $22
1483 cmpult $22, $6, $1
1484 srl $4, 32, $6
1485 mulq $5, $6, $25
1486 mulq $7, $5, $2
1487 addq $1, $24, $24
1488 addq $28, $25, $28
1489 cmpult $28, $25, $1
1490 mulq $6, $8, $6
1491 beq $1, $281
1492 sll $21, 32, $1
1493 addq $6, $1, $6
1494$281:
1495 sll $28, 32, $25
1496 addq $2, $25, $2
1497 bis $2, $2, $7
1498 addq $23, $7, $23
1499 stq $23, 48($16)
1500 ldq $4, 0($17)
1501 ldq $5, 56($18)
1502 cmpult $23, $7, $3
1503 zapnot $4, 15, $7
1504 srl $5, 32, $8
1505 mulq $8, $7, $0
1506 srl $28, 32, $1
1507 cmpult $2, $25, $2
1508 addq $6, $1, $6
1509 addq $2, $6, $6
1510 addq $3, $6, $6
1511 addq $22, $6, $22
1512 cmpult $22, $6, $1
1513 srl $4, 32, $6
1514 zapnot $5, 15, $5
1515 mulq $5, $6, $23
1516 mulq $7, $5, $2
1517 addq $1, $24, $24
1518 addq $0, $23, $0
1519 cmpult $0, $23, $1
1520 mulq $6, $8, $6
1521 beq $1, $285
1522 sll $21, 32, $1
1523 addq $6, $1, $6
1524$285:
1525 sll $0, 32, $23
1526 ldq $1, 48($18)
1527 addq $2, $23, $2
1528 bis $2, $2, $7
1529 ldq $4, 8($17)
1530 addq $22, $7, $22
1531 srl $1, 32, $8
1532 cmpult $22, $7, $3
1533 zapnot $4, 15, $7
1534 mulq $8, $7, $25
1535 zapnot $1, 15, $5
1536 mulq $7, $5, $21
1537 srl $0, 32, $1
1538 cmpult $2, $23, $2
1539 addq $6, $1, $6
1540 addq $2, $6, $6
1541 addq $3, $6, $6
1542 addq $24, $6, $24
1543 cmpult $24, $6, $23
1544 srl $4, 32, $6
1545 mulq $5, $6, $5
1546 bis $31, 1, $20
1547 addq $25, $5, $25
1548 cmpult $25, $5, $1
1549 mulq $6, $8, $6
1550 beq $1, $289
1551 sll $20, 32, $1
1552 addq $6, $1, $6
1553$289:
1554 sll $25, 32, $5
1555 ldq $2, 40($18)
1556 addq $21, $5, $21
1557 bis $21, $21, $7
1558 ldq $4, 16($17)
1559 addq $22, $7, $22
1560 srl $2, 32, $8
1561 cmpult $22, $7, $3
1562 zapnot $4, 15, $7
1563 mulq $8, $7, $28
1564 srl $25, 32, $1
1565 addq $6, $1, $6
1566 cmpult $21, $5, $1
1567 zapnot $2, 15, $5
1568 addq $1, $6, $6
1569 addq $3, $6, $6
1570 addq $24, $6, $24
1571 cmpult $24, $6, $1
1572 srl $4, 32, $6
1573 mulq $5, $6, $25
1574 mulq $7, $5, $5
1575 addq $1, $23, $23
1576 addq $28, $25, $28
1577 cmpult $28, $25, $1
1578 mulq $6, $8, $6
1579 beq $1, $293
1580 sll $20, 32, $1
1581 addq $6, $1, $6
1582$293:
1583 sll $28, 32, $25
1584 ldq $2, 32($18)
1585 addq $5, $25, $5
1586 bis $5, $5, $7
1587 ldq $4, 24($17)
1588 addq $22, $7, $22
1589 srl $2, 32, $8
1590 cmpult $22, $7, $3
1591 zapnot $4, 15, $7
1592 mulq $8, $7, $0
1593 srl $28, 32, $1
1594 addq $6, $1, $6
1595 cmpult $5, $25, $1
1596 zapnot $2, 15, $5
1597 addq $1, $6, $6
1598 addq $3, $6, $6
1599 addq $24, $6, $24
1600 cmpult $24, $6, $1
1601 srl $4, 32, $6
1602 mulq $5, $6, $25
1603 mulq $7, $5, $5
1604 addq $1, $23, $23
1605 addq $0, $25, $0
1606 cmpult $0, $25, $1
1607 mulq $6, $8, $6
1608 beq $1, $297
1609 sll $20, 32, $1
1610 addq $6, $1, $6
1611$297:
1612 sll $0, 32, $25
1613 ldq $2, 24($18)
1614 addq $5, $25, $5
1615 bis $5, $5, $7
1616 ldq $4, 32($17)
1617 addq $22, $7, $22
1618 srl $2, 32, $8
1619 cmpult $22, $7, $3
1620 zapnot $4, 15, $7
1621 mulq $8, $7, $28
1622 srl $0, 32, $1
1623 addq $6, $1, $6
1624 cmpult $5, $25, $1
1625 zapnot $2, 15, $5
1626 addq $1, $6, $6
1627 addq $3, $6, $6
1628 addq $24, $6, $24
1629 cmpult $24, $6, $1
1630 srl $4, 32, $6
1631 mulq $5, $6, $25
1632 mulq $7, $5, $5
1633 addq $1, $23, $23
1634 addq $28, $25, $28
1635 cmpult $28, $25, $1
1636 mulq $6, $8, $6
1637 beq $1, $301
1638 sll $20, 32, $1
1639 addq $6, $1, $6
1640$301:
1641 sll $28, 32, $25
1642 ldq $2, 16($18)
1643 addq $5, $25, $5
1644 bis $5, $5, $7
1645 ldq $4, 40($17)
1646 addq $22, $7, $22
1647 srl $2, 32, $8
1648 cmpult $22, $7, $3
1649 zapnot $4, 15, $7
1650 mulq $8, $7, $0
1651 srl $28, 32, $1
1652 addq $6, $1, $6
1653 cmpult $5, $25, $1
1654 zapnot $2, 15, $5
1655 addq $1, $6, $6
1656 addq $3, $6, $6
1657 addq $24, $6, $24
1658 cmpult $24, $6, $1
1659 srl $4, 32, $6
1660 mulq $5, $6, $25
1661 mulq $7, $5, $5
1662 addq $1, $23, $23
1663 addq $0, $25, $0
1664 cmpult $0, $25, $1
1665 mulq $6, $8, $6
1666 beq $1, $305
1667 sll $20, 32, $1
1668 addq $6, $1, $6
1669$305:
1670 sll $0, 32, $25
1671 ldq $2, 8($18)
1672 addq $5, $25, $5
1673 bis $5, $5, $7
1674 ldq $4, 48($17)
1675 addq $22, $7, $22
1676 srl $2, 32, $8
1677 cmpult $22, $7, $3
1678 zapnot $4, 15, $7
1679 mulq $8, $7, $28
1680 srl $0, 32, $1
1681 addq $6, $1, $6
1682 cmpult $5, $25, $1
1683 zapnot $2, 15, $5
1684 addq $1, $6, $6
1685 addq $3, $6, $6
1686 addq $24, $6, $24
1687 cmpult $24, $6, $1
1688 srl $4, 32, $6
1689 mulq $5, $6, $25
1690 mulq $7, $5, $5
1691 addq $1, $23, $23
1692 addq $28, $25, $28
1693 cmpult $28, $25, $1
1694 mulq $6, $8, $6
1695 beq $1, $309
1696 sll $20, 32, $1
1697 addq $6, $1, $6
1698$309:
1699 sll $28, 32, $25
1700 ldq $2, 0($18)
1701 addq $5, $25, $5
1702 bis $5, $5, $7
1703 ldq $4, 56($17)
1704 addq $22, $7, $22
1705 srl $2, 32, $8
1706 cmpult $22, $7, $3
1707 zapnot $4, 15, $7
1708 mulq $8, $7, $0
1709 srl $28, 32, $1
1710 addq $6, $1, $6
1711 cmpult $5, $25, $1
1712 zapnot $2, 15, $5
1713 addq $1, $6, $6
1714 addq $3, $6, $6
1715 addq $24, $6, $24
1716 cmpult $24, $6, $1
1717 srl $4, 32, $6
1718 mulq $5, $6, $25
1719 mulq $7, $5, $2
1720 addq $1, $23, $23
1721 addq $0, $25, $0
1722 cmpult $0, $25, $1
1723 mulq $6, $8, $6
1724 beq $1, $313
1725 sll $20, 32, $1
1726 addq $6, $1, $6
1727$313:
1728 sll $0, 32, $25
1729 addq $2, $25, $2
1730 bis $2, $2, $7
1731 addq $22, $7, $22
1732 stq $22, 56($16)
1733 ldq $4, 56($17)
1734 ldq $5, 8($18)
1735 cmpult $22, $7, $3
1736 zapnot $4, 15, $7
1737 srl $5, 32, $8
1738 mulq $8, $7, $28
1739 srl $0, 32, $1
1740 cmpult $2, $25, $2
1741 addq $6, $1, $6
1742 addq $2, $6, $6
1743 addq $3, $6, $6
1744 addq $24, $6, $24
1745 cmpult $24, $6, $1
1746 srl $4, 32, $6
1747 zapnot $5, 15, $5
1748 mulq $5, $6, $22
1749 mulq $7, $5, $2
1750 addq $1, $23, $23
1751 addq $28, $22, $28
1752 cmpult $28, $22, $1
1753 mulq $6, $8, $6
1754 beq $1, $317
1755 sll $20, 32, $1
1756 addq $6, $1, $6
1757$317:
1758 sll $28, 32, $22
1759 ldq $1, 16($18)
1760 addq $2, $22, $2
1761 bis $2, $2, $7
1762 ldq $4, 48($17)
1763 addq $24, $7, $24
1764 srl $1, 32, $8
1765 cmpult $24, $7, $3
1766 zapnot $4, 15, $7
1767 mulq $8, $7, $25
1768 zapnot $1, 15, $5
1769 mulq $7, $5, $0
1770 srl $28, 32, $1
1771 cmpult $2, $22, $2
1772 addq $6, $1, $6
1773 addq $2, $6, $6
1774 addq $3, $6, $6
1775 addq $23, $6, $23
1776 cmpult $23, $6, $22
1777 srl $4, 32, $6
1778 mulq $5, $6, $5
1779 bis $31, 1, $21
1780 addq $25, $5, $25
1781 cmpult $25, $5, $1
1782 mulq $6, $8, $6
1783 beq $1, $321
1784 sll $21, 32, $1
1785 addq $6, $1, $6
1786$321:
1787 sll $25, 32, $5
1788 ldq $2, 24($18)
1789 addq $0, $5, $0
1790 bis $0, $0, $7
1791 ldq $4, 40($17)
1792 addq $24, $7, $24
1793 srl $2, 32, $8
1794 cmpult $24, $7, $3
1795 zapnot $4, 15, $7
1796 mulq $8, $7, $28
1797 srl $25, 32, $1
1798 addq $6, $1, $6
1799 cmpult $0, $5, $1
1800 zapnot $2, 15, $5
1801 addq $1, $6, $6
1802 addq $3, $6, $6
1803 addq $23, $6, $23
1804 cmpult $23, $6, $1
1805 srl $4, 32, $6
1806 mulq $5, $6, $25
1807 mulq $7, $5, $5
1808 addq $1, $22, $22
1809 addq $28, $25, $28
1810 cmpult $28, $25, $1
1811 mulq $6, $8, $6
1812 beq $1, $325
1813 sll $21, 32, $1
1814 addq $6, $1, $6
1815$325:
1816 sll $28, 32, $25
1817 ldq $2, 32($18)
1818 addq $5, $25, $5
1819 bis $5, $5, $7
1820 ldq $4, 32($17)
1821 addq $24, $7, $24
1822 srl $2, 32, $8
1823 cmpult $24, $7, $3
1824 zapnot $4, 15, $7
1825 mulq $8, $7, $0
1826 srl $28, 32, $1
1827 addq $6, $1, $6
1828 cmpult $5, $25, $1
1829 zapnot $2, 15, $5
1830 addq $1, $6, $6
1831 addq $3, $6, $6
1832 addq $23, $6, $23
1833 cmpult $23, $6, $1
1834 srl $4, 32, $6
1835 mulq $5, $6, $25
1836 mulq $7, $5, $5
1837 addq $1, $22, $22
1838 addq $0, $25, $0
1839 cmpult $0, $25, $1
1840 mulq $6, $8, $6
1841 beq $1, $329
1842 sll $21, 32, $1
1843 addq $6, $1, $6
1844$329:
1845 sll $0, 32, $25
1846 ldq $2, 40($18)
1847 addq $5, $25, $5
1848 bis $5, $5, $7
1849 ldq $4, 24($17)
1850 addq $24, $7, $24
1851 srl $2, 32, $8
1852 cmpult $24, $7, $3
1853 zapnot $4, 15, $7
1854 mulq $8, $7, $28
1855 srl $0, 32, $1
1856 addq $6, $1, $6
1857 cmpult $5, $25, $1
1858 zapnot $2, 15, $5
1859 addq $1, $6, $6
1860 addq $3, $6, $6
1861 addq $23, $6, $23
1862 cmpult $23, $6, $1
1863 srl $4, 32, $6
1864 mulq $5, $6, $25
1865 mulq $7, $5, $5
1866 addq $1, $22, $22
1867 addq $28, $25, $28
1868 cmpult $28, $25, $1
1869 mulq $6, $8, $6
1870 beq $1, $333
1871 sll $21, 32, $1
1872 addq $6, $1, $6
1873$333:
1874 sll $28, 32, $25
1875 ldq $2, 48($18)
1876 addq $5, $25, $5
1877 bis $5, $5, $7
1878 ldq $4, 16($17)
1879 addq $24, $7, $24
1880 srl $2, 32, $8
1881 cmpult $24, $7, $3
1882 zapnot $4, 15, $7
1883 mulq $8, $7, $0
1884 srl $28, 32, $1
1885 addq $6, $1, $6
1886 cmpult $5, $25, $1
1887 zapnot $2, 15, $5
1888 addq $1, $6, $6
1889 addq $3, $6, $6
1890 addq $23, $6, $23
1891 cmpult $23, $6, $1
1892 srl $4, 32, $6
1893 mulq $5, $6, $25
1894 mulq $7, $5, $5
1895 addq $1, $22, $22
1896 addq $0, $25, $0
1897 cmpult $0, $25, $1
1898 mulq $6, $8, $6
1899 beq $1, $337
1900 sll $21, 32, $1
1901 addq $6, $1, $6
1902$337:
1903 sll $0, 32, $25
1904 ldq $2, 56($18)
1905 addq $5, $25, $5
1906 bis $5, $5, $7
1907 ldq $4, 8($17)
1908 addq $24, $7, $24
1909 srl $2, 32, $8
1910 cmpult $24, $7, $3
1911 zapnot $4, 15, $7
1912 mulq $8, $7, $28
1913 srl $0, 32, $1
1914 addq $6, $1, $6
1915 cmpult $5, $25, $1
1916 zapnot $2, 15, $5
1917 addq $1, $6, $6
1918 addq $3, $6, $6
1919 addq $23, $6, $23
1920 cmpult $23, $6, $1
1921 srl $4, 32, $6
1922 mulq $5, $6, $25
1923 mulq $7, $5, $2
1924 addq $1, $22, $22
1925 addq $28, $25, $28
1926 cmpult $28, $25, $1
1927 mulq $6, $8, $6
1928 beq $1, $341
1929 sll $21, 32, $1
1930 addq $6, $1, $6
1931$341:
1932 sll $28, 32, $25
1933 addq $2, $25, $2
1934 bis $2, $2, $7
1935 addq $24, $7, $24
1936 stq $24, 64($16)
1937 ldq $4, 16($17)
1938 ldq $5, 56($18)
1939 cmpult $24, $7, $3
1940 zapnot $4, 15, $7
1941 srl $5, 32, $8
1942 mulq $8, $7, $0
1943 srl $28, 32, $1
1944 cmpult $2, $25, $2
1945 addq $6, $1, $6
1946 addq $2, $6, $6
1947 addq $3, $6, $6
1948 addq $23, $6, $23
1949 cmpult $23, $6, $1
1950 srl $4, 32, $6
1951 zapnot $5, 15, $5
1952 mulq $5, $6, $24
1953 mulq $7, $5, $2
1954 addq $1, $22, $22
1955 addq $0, $24, $0
1956 cmpult $0, $24, $1
1957 mulq $6, $8, $6
1958 beq $1, $345
1959 sll $21, 32, $1
1960 addq $6, $1, $6
1961$345:
1962 sll $0, 32, $24
1963 ldq $1, 48($18)
1964 addq $2, $24, $2
1965 bis $2, $2, $7
1966 ldq $4, 24($17)
1967 addq $23, $7, $23
1968 srl $1, 32, $8
1969 cmpult $23, $7, $3
1970 zapnot $4, 15, $7
1971 mulq $8, $7, $25
1972 zapnot $1, 15, $5
1973 mulq $7, $5, $21
1974 srl $0, 32, $1
1975 cmpult $2, $24, $2
1976 addq $6, $1, $6
1977 addq $2, $6, $6
1978 addq $3, $6, $6
1979 addq $22, $6, $22
1980 cmpult $22, $6, $24
1981 srl $4, 32, $6
1982 mulq $5, $6, $5
1983 bis $31, 1, $20
1984 addq $25, $5, $25
1985 cmpult $25, $5, $1
1986 mulq $6, $8, $6
1987 beq $1, $349
1988 sll $20, 32, $1
1989 addq $6, $1, $6
1990$349:
1991 sll $25, 32, $5
1992 ldq $2, 40($18)
1993 addq $21, $5, $21
1994 bis $21, $21, $7
1995 ldq $4, 32($17)
1996 addq $23, $7, $23
1997 srl $2, 32, $8
1998 cmpult $23, $7, $3
1999 zapnot $4, 15, $7
2000 mulq $8, $7, $28
2001 srl $25, 32, $1
2002 addq $6, $1, $6
2003 cmpult $21, $5, $1
2004 zapnot $2, 15, $5
2005 addq $1, $6, $6
2006 addq $3, $6, $6
2007 addq $22, $6, $22
2008 cmpult $22, $6, $1
2009 srl $4, 32, $6
2010 mulq $5, $6, $25
2011 mulq $7, $5, $5
2012 addq $1, $24, $24
2013 addq $28, $25, $28
2014 cmpult $28, $25, $1
2015 mulq $6, $8, $6
2016 beq $1, $353
2017 sll $20, 32, $1
2018 addq $6, $1, $6
2019$353:
2020 sll $28, 32, $25
2021 ldq $2, 32($18)
2022 addq $5, $25, $5
2023 bis $5, $5, $7
2024 ldq $4, 40($17)
2025 addq $23, $7, $23
2026 srl $2, 32, $8
2027 cmpult $23, $7, $3
2028 zapnot $4, 15, $7
2029 mulq $8, $7, $0
2030 srl $28, 32, $1
2031 addq $6, $1, $6
2032 cmpult $5, $25, $1
2033 zapnot $2, 15, $5
2034 addq $1, $6, $6
2035 addq $3, $6, $6
2036 addq $22, $6, $22
2037 cmpult $22, $6, $1
2038 srl $4, 32, $6
2039 mulq $5, $6, $25
2040 mulq $7, $5, $5
2041 addq $1, $24, $24
2042 addq $0, $25, $0
2043 cmpult $0, $25, $1
2044 mulq $6, $8, $6
2045 beq $1, $357
2046 sll $20, 32, $1
2047 addq $6, $1, $6
2048$357:
2049 sll $0, 32, $25
2050 ldq $2, 24($18)
2051 addq $5, $25, $5
2052 bis $5, $5, $7
2053 ldq $4, 48($17)
2054 addq $23, $7, $23
2055 srl $2, 32, $8
2056 cmpult $23, $7, $3
2057 zapnot $4, 15, $7
2058 mulq $8, $7, $28
2059 srl $0, 32, $1
2060 addq $6, $1, $6
2061 cmpult $5, $25, $1
2062 zapnot $2, 15, $5
2063 addq $1, $6, $6
2064 addq $3, $6, $6
2065 addq $22, $6, $22
2066 cmpult $22, $6, $1
2067 srl $4, 32, $6
2068 mulq $5, $6, $25
2069 mulq $7, $5, $5
2070 addq $1, $24, $24
2071 addq $28, $25, $28
2072 cmpult $28, $25, $1
2073 mulq $6, $8, $6
2074 beq $1, $361
2075 sll $20, 32, $1
2076 addq $6, $1, $6
2077$361:
2078 sll $28, 32, $25
2079 ldq $2, 16($18)
2080 addq $5, $25, $5
2081 bis $5, $5, $7
2082 ldq $4, 56($17)
2083 addq $23, $7, $23
2084 srl $2, 32, $8
2085 cmpult $23, $7, $3
2086 zapnot $4, 15, $7
2087 mulq $8, $7, $0
2088 srl $28, 32, $1
2089 addq $6, $1, $6
2090 cmpult $5, $25, $1
2091 zapnot $2, 15, $5
2092 addq $1, $6, $6
2093 addq $3, $6, $6
2094 addq $22, $6, $22
2095 cmpult $22, $6, $1
2096 srl $4, 32, $6
2097 mulq $5, $6, $25
2098 mulq $7, $5, $2
2099 addq $1, $24, $24
2100 addq $0, $25, $0
2101 cmpult $0, $25, $1
2102 mulq $6, $8, $6
2103 beq $1, $365
2104 sll $20, 32, $1
2105 addq $6, $1, $6
2106$365:
2107 sll $0, 32, $25
2108 addq $2, $25, $2
2109 bis $2, $2, $7
2110 addq $23, $7, $23
2111 stq $23, 72($16)
2112 ldq $4, 56($17)
2113 ldq $5, 24($18)
2114 cmpult $23, $7, $3
2115 zapnot $4, 15, $7
2116 srl $5, 32, $8
2117 mulq $8, $7, $28
2118 srl $0, 32, $1
2119 cmpult $2, $25, $2
2120 addq $6, $1, $6
2121 addq $2, $6, $6
2122 addq $3, $6, $6
2123 addq $22, $6, $22
2124 cmpult $22, $6, $1
2125 srl $4, 32, $6
2126 zapnot $5, 15, $5
2127 mulq $5, $6, $23
2128 mulq $7, $5, $2
2129 addq $1, $24, $24
2130 addq $28, $23, $28
2131 cmpult $28, $23, $1
2132 mulq $6, $8, $6
2133 beq $1, $369
2134 sll $20, 32, $1
2135 addq $6, $1, $6
2136$369:
2137 sll $28, 32, $23
2138 ldq $1, 32($18)
2139 addq $2, $23, $2
2140 bis $2, $2, $7
2141 ldq $4, 48($17)
2142 addq $22, $7, $22
2143 srl $1, 32, $8
2144 cmpult $22, $7, $3
2145 zapnot $4, 15, $7
2146 mulq $8, $7, $25
2147 zapnot $1, 15, $5
2148 mulq $7, $5, $0
2149 srl $28, 32, $1
2150 cmpult $2, $23, $2
2151 addq $6, $1, $6
2152 addq $2, $6, $6
2153 addq $3, $6, $6
2154 addq $24, $6, $24
2155 cmpult $24, $6, $23
2156 srl $4, 32, $6
2157 mulq $5, $6, $5
2158 bis $31, 1, $21
2159 addq $25, $5, $25
2160 cmpult $25, $5, $1
2161 mulq $6, $8, $6
2162 beq $1, $373
2163 sll $21, 32, $1
2164 addq $6, $1, $6
2165$373:
2166 sll $25, 32, $5
2167 ldq $2, 40($18)
2168 addq $0, $5, $0
2169 bis $0, $0, $7
2170 ldq $4, 40($17)
2171 addq $22, $7, $22
2172 srl $2, 32, $8
2173 cmpult $22, $7, $3
2174 zapnot $4, 15, $7
2175 mulq $8, $7, $28
2176 srl $25, 32, $1
2177 addq $6, $1, $6
2178 cmpult $0, $5, $1
2179 zapnot $2, 15, $5
2180 addq $1, $6, $6
2181 addq $3, $6, $6
2182 addq $24, $6, $24
2183 cmpult $24, $6, $1
2184 srl $4, 32, $6
2185 mulq $5, $6, $25
2186 mulq $7, $5, $5
2187 addq $1, $23, $23
2188 addq $28, $25, $28
2189 cmpult $28, $25, $1
2190 mulq $6, $8, $6
2191 beq $1, $377
2192 sll $21, 32, $1
2193 addq $6, $1, $6
2194$377:
2195 sll $28, 32, $25
2196 ldq $2, 48($18)
2197 addq $5, $25, $5
2198 bis $5, $5, $7
2199 ldq $4, 32($17)
2200 addq $22, $7, $22
2201 srl $2, 32, $8
2202 cmpult $22, $7, $3
2203 zapnot $4, 15, $7
2204 mulq $8, $7, $0
2205 srl $28, 32, $1
2206 addq $6, $1, $6
2207 cmpult $5, $25, $1
2208 zapnot $2, 15, $5
2209 addq $1, $6, $6
2210 addq $3, $6, $6
2211 addq $24, $6, $24
2212 cmpult $24, $6, $1
2213 srl $4, 32, $6
2214 mulq $5, $6, $25
2215 mulq $7, $5, $5
2216 addq $1, $23, $23
2217 addq $0, $25, $0
2218 cmpult $0, $25, $1
2219 mulq $6, $8, $6
2220 beq $1, $381
2221 sll $21, 32, $1
2222 addq $6, $1, $6
2223$381:
2224 sll $0, 32, $25
2225 ldq $2, 56($18)
2226 addq $5, $25, $5
2227 bis $5, $5, $7
2228 ldq $4, 24($17)
2229 addq $22, $7, $22
2230 srl $2, 32, $8
2231 cmpult $22, $7, $3
2232 zapnot $4, 15, $7
2233 mulq $8, $7, $28
2234 srl $0, 32, $1
2235 addq $6, $1, $6
2236 cmpult $5, $25, $1
2237 zapnot $2, 15, $5
2238 addq $1, $6, $6
2239 addq $3, $6, $6
2240 addq $24, $6, $24
2241 cmpult $24, $6, $1
2242 srl $4, 32, $6
2243 mulq $5, $6, $25
2244 mulq $7, $5, $2
2245 addq $1, $23, $23
2246 addq $28, $25, $28
2247 cmpult $28, $25, $1
2248 mulq $6, $8, $6
2249 beq $1, $385
2250 sll $21, 32, $1
2251 addq $6, $1, $6
2252$385:
2253 sll $28, 32, $25
2254 addq $2, $25, $2
2255 bis $2, $2, $7
2256 addq $22, $7, $22
2257 stq $22, 80($16)
2258 ldq $4, 32($17)
2259 ldq $5, 56($18)
2260 cmpult $22, $7, $3
2261 zapnot $4, 15, $7
2262 srl $5, 32, $8
2263 mulq $8, $7, $0
2264 srl $28, 32, $1
2265 cmpult $2, $25, $2
2266 addq $6, $1, $6
2267 addq $2, $6, $6
2268 addq $3, $6, $6
2269 addq $24, $6, $24
2270 cmpult $24, $6, $1
2271 srl $4, 32, $6
2272 zapnot $5, 15, $5
2273 mulq $5, $6, $22
2274 mulq $7, $5, $2
2275 addq $1, $23, $23
2276 addq $0, $22, $0
2277 cmpult $0, $22, $1
2278 mulq $6, $8, $6
2279 beq $1, $389
2280 sll $21, 32, $1
2281 addq $6, $1, $6
2282$389:
2283 sll $0, 32, $22
2284 ldq $1, 48($18)
2285 addq $2, $22, $2
2286 bis $2, $2, $7
2287 ldq $4, 40($17)
2288 addq $24, $7, $24
2289 srl $1, 32, $8
2290 cmpult $24, $7, $3
2291 zapnot $4, 15, $7
2292 mulq $8, $7, $25
2293 zapnot $1, 15, $5
2294 mulq $7, $5, $21
2295 srl $0, 32, $1
2296 cmpult $2, $22, $2
2297 addq $6, $1, $6
2298 addq $2, $6, $6
2299 addq $3, $6, $6
2300 addq $23, $6, $23
2301 cmpult $23, $6, $22
2302 srl $4, 32, $6
2303 mulq $5, $6, $5
2304 bis $31, 1, $20
2305 addq $25, $5, $25
2306 cmpult $25, $5, $1
2307 mulq $6, $8, $6
2308 beq $1, $393
2309 sll $20, 32, $1
2310 addq $6, $1, $6
2311$393:
2312 sll $25, 32, $5
2313 ldq $2, 40($18)
2314 addq $21, $5, $21
2315 bis $21, $21, $7
2316 ldq $4, 48($17)
2317 addq $24, $7, $24
2318 srl $2, 32, $8
2319 cmpult $24, $7, $3
2320 zapnot $4, 15, $7
2321 mulq $8, $7, $28
2322 srl $25, 32, $1
2323 addq $6, $1, $6
2324 cmpult $21, $5, $1
2325 zapnot $2, 15, $5
2326 addq $1, $6, $6
2327 addq $3, $6, $6
2328 addq $23, $6, $23
2329 cmpult $23, $6, $1
2330 srl $4, 32, $6
2331 mulq $5, $6, $25
2332 mulq $7, $5, $5
2333 addq $1, $22, $22
2334 addq $28, $25, $28
2335 cmpult $28, $25, $1
2336 mulq $6, $8, $6
2337 beq $1, $397
2338 sll $20, 32, $1
2339 addq $6, $1, $6
2340$397:
2341 sll $28, 32, $25
2342 ldq $2, 32($18)
2343 addq $5, $25, $5
2344 bis $5, $5, $7
2345 ldq $4, 56($17)
2346 addq $24, $7, $24
2347 srl $2, 32, $8
2348 cmpult $24, $7, $3
2349 zapnot $4, 15, $7
2350 mulq $8, $7, $21
2351 srl $28, 32, $1
2352 addq $6, $1, $6
2353 cmpult $5, $25, $1
2354 zapnot $2, 15, $5
2355 addq $1, $6, $6
2356 addq $3, $6, $6
2357 addq $23, $6, $23
2358 cmpult $23, $6, $1
2359 srl $4, 32, $6
2360 mulq $5, $6, $25
2361 mulq $7, $5, $2
2362 addq $1, $22, $22
2363 addq $21, $25, $21
2364 cmpult $21, $25, $1
2365 mulq $6, $8, $6
2366 beq $1, $401
2367 sll $20, 32, $1
2368 addq $6, $1, $6
2369$401:
2370 sll $21, 32, $25
2371 addq $2, $25, $2
2372 bis $2, $2, $7
2373 addq $24, $7, $24
2374 stq $24, 88($16)
2375 ldq $4, 56($17)
2376 ldq $5, 40($18)
2377 cmpult $24, $7, $3
2378 zapnot $4, 15, $7
2379 srl $5, 32, $8
2380 mulq $8, $7, $0
2381 srl $21, 32, $1
2382 cmpult $2, $25, $2
2383 addq $6, $1, $6
2384 addq $2, $6, $6
2385 addq $3, $6, $6
2386 addq $23, $6, $23
2387 cmpult $23, $6, $1
2388 srl $4, 32, $6
2389 zapnot $5, 15, $5
2390 mulq $5, $6, $24
2391 mulq $7, $5, $5
2392 addq $1, $22, $22
2393 addq $0, $24, $0
2394 cmpult $0, $24, $1
2395 mulq $6, $8, $6
2396 beq $1, $405
2397 sll $20, 32, $1
2398 addq $6, $1, $6
2399$405:
2400 sll $0, 32, $24
2401 ldq $2, 48($18)
2402 addq $5, $24, $5
2403 bis $5, $5, $7
2404 ldq $4, 48($17)
2405 addq $23, $7, $23
2406 srl $2, 32, $8
2407 cmpult $23, $7, $3
2408 zapnot $4, 15, $7
2409 mulq $8, $7, $28
2410 srl $0, 32, $1
2411 addq $6, $1, $6
2412 cmpult $5, $24, $1
2413 zapnot $2, 15, $5
2414 addq $1, $6, $6
2415 addq $3, $6, $6
2416 addq $22, $6, $22
2417 cmpult $22, $6, $24
2418 srl $4, 32, $6
2419 mulq $5, $6, $25
2420 mulq $7, $5, $5
2421 addq $28, $25, $28
2422 cmpult $28, $25, $1
2423 mulq $6, $8, $6
2424 beq $1, $409
2425 sll $20, 32, $1
2426 addq $6, $1, $6
2427$409:
2428 sll $28, 32, $25
2429 ldq $2, 56($18)
2430 addq $5, $25, $5
2431 bis $5, $5, $7
2432 ldq $4, 40($17)
2433 addq $23, $7, $23
2434 srl $2, 32, $8
2435 cmpult $23, $7, $3
2436 zapnot $4, 15, $7
2437 mulq $8, $7, $0
2438 srl $28, 32, $1
2439 addq $6, $1, $6
2440 cmpult $5, $25, $1
2441 zapnot $2, 15, $5
2442 addq $1, $6, $6
2443 addq $3, $6, $6
2444 addq $22, $6, $22
2445 cmpult $22, $6, $1
2446 srl $4, 32, $6
2447 mulq $5, $6, $25
2448 mulq $7, $5, $2
2449 addq $1, $24, $24
2450 addq $0, $25, $0
2451 cmpult $0, $25, $1
2452 mulq $6, $8, $6
2453 beq $1, $413
2454 sll $20, 32, $1
2455 addq $6, $1, $6
2456$413:
2457 sll $0, 32, $25
2458 addq $2, $25, $2
2459 bis $2, $2, $7
2460 addq $23, $7, $23
2461 stq $23, 96($16)
2462 ldq $4, 48($17)
2463 ldq $5, 56($18)
2464 cmpult $23, $7, $3
2465 zapnot $4, 15, $7
2466 srl $5, 32, $8
2467 mulq $8, $7, $28
2468 srl $0, 32, $1
2469 cmpult $2, $25, $2
2470 addq $6, $1, $6
2471 addq $2, $6, $6
2472 addq $3, $6, $6
2473 addq $22, $6, $22
2474 cmpult $22, $6, $1
2475 srl $4, 32, $6
2476 zapnot $5, 15, $5
2477 mulq $5, $6, $23
2478 mulq $7, $5, $5
2479 addq $1, $24, $24
2480 addq $28, $23, $28
2481 cmpult $28, $23, $1
2482 mulq $6, $8, $6
2483 beq $1, $417
2484 sll $20, 32, $1
2485 addq $6, $1, $6
2486$417:
2487 sll $28, 32, $23
2488 ldq $2, 48($18)
2489 addq $5, $23, $5
2490 bis $5, $5, $7
2491 ldq $4, 56($17)
2492 addq $22, $7, $22
2493 srl $2, 32, $8
2494 cmpult $22, $7, $3
2495 zapnot $4, 15, $7
2496 mulq $8, $7, $0
2497 srl $28, 32, $1
2498 addq $6, $1, $6
2499 cmpult $5, $23, $1
2500 zapnot $2, 15, $5
2501 addq $1, $6, $6
2502 addq $3, $6, $6
2503 addq $24, $6, $24
2504 cmpult $24, $6, $23
2505 srl $4, 32, $6
2506 mulq $5, $6, $25
2507 mulq $7, $5, $2
2508 addq $0, $25, $0
2509 cmpult $0, $25, $1
2510 mulq $6, $8, $6
2511 beq $1, $421
2512 sll $20, 32, $1
2513 addq $6, $1, $6
2514$421:
2515 sll $0, 32, $25
2516 addq $2, $25, $2
2517 bis $2, $2, $7
2518 addq $22, $7, $22
2519 stq $22, 104($16)
2520 ldq $4, 56($17)
2521 ldq $5, 56($18)
2522 cmpult $22, $7, $3
2523 zapnot $4, 15, $7
2524 srl $5, 32, $8
2525 mulq $8, $7, $28
2526 srl $0, 32, $1
2527 cmpult $2, $25, $2
2528 addq $6, $1, $6
2529 addq $2, $6, $6
2530 addq $3, $6, $6
2531 addq $24, $6, $24
2532 cmpult $24, $6, $1
2533 srl $4, 32, $6
2534 zapnot $5, 15, $5
2535 mulq $5, $6, $22
2536 mulq $7, $5, $2
2537 addq $1, $23, $23
2538 addq $28, $22, $28
2539 cmpult $28, $22, $1
2540 mulq $6, $8, $3
2541 beq $1, $425
2542 sll $20, 32, $1
2543 addq $3, $1, $3
2544$425:
2545 sll $28, 32, $22
2546 srl $28, 32, $1
2547 addq $2, $22, $2
2548 addq $3, $1, $3
2549 bis $2, $2, $7
2550 addq $24, $7, $24
2551 cmpult $7, $22, $1
2552 cmpult $24, $7, $2
2553 addq $1, $3, $6
2554 addq $2, $6, $6
2555 stq $24, 112($16)
2556 addq $23, $6, $23
2557 stq $23, 120($16)
2558 ret $31, ($26), 1
1258 .end bn_mul_comba8 2559 .end bn_mul_comba8
1259 .text 2560 .text
1260 .align 3 2561 .align 3
diff --git a/src/lib/libcrypto/bn/asm/mips3.s b/src/lib/libcrypto/bn/asm/mips3.s
index 191345d920..2df4dcd4b0 100644
--- a/src/lib/libcrypto/bn/asm/mips3.s
+++ b/src/lib/libcrypto/bn/asm/mips3.s
@@ -395,32 +395,32 @@ LEAF(bn_add_words)
395 395
396.L_bn_add_words_loop: 396.L_bn_add_words_loop:
397 ld ta0,0(a2) 397 ld ta0,0(a2)
398 subu a3,4
398 ld t1,8(a1) 399 ld t1,8(a1)
399 ld ta1,8(a2) 400 and AT,a3,MINUS4
400 ld t2,16(a1) 401 ld t2,16(a1)
401 ld ta2,16(a2) 402 PTR_ADD a2,32
402 ld t3,24(a1) 403 ld t3,24(a1)
403 ld ta3,24(a2) 404 PTR_ADD a0,32
405 ld ta1,-24(a2)
406 PTR_ADD a1,32
407 ld ta2,-16(a2)
408 ld ta3,-8(a2)
404 daddu ta0,t0 409 daddu ta0,t0
405 subu a3,4
406 sltu t8,ta0,t0 410 sltu t8,ta0,t0
407 daddu t0,ta0,v0 411 daddu t0,ta0,v0
408 PTR_ADD a0,32
409 sltu v0,t0,ta0 412 sltu v0,t0,ta0
410 sd t0,-32(a0) 413 sd t0,-32(a0)
411 daddu v0,t8 414 daddu v0,t8
412 415
413 daddu ta1,t1 416 daddu ta1,t1
414 PTR_ADD a1,32
415 sltu t9,ta1,t1 417 sltu t9,ta1,t1
416 daddu t1,ta1,v0 418 daddu t1,ta1,v0
417 PTR_ADD a2,32
418 sltu v0,t1,ta1 419 sltu v0,t1,ta1
419 sd t1,-24(a0) 420 sd t1,-24(a0)
420 daddu v0,t9 421 daddu v0,t9
421 422
422 daddu ta2,t2 423 daddu ta2,t2
423 and AT,a3,MINUS4
424 sltu t8,ta2,t2 424 sltu t8,ta2,t2
425 daddu t2,ta2,v0 425 daddu t2,ta2,v0
426 sltu v0,t2,ta2 426 sltu v0,t2,ta2
@@ -495,25 +495,26 @@ LEAF(bn_sub_words)
495 495
496.L_bn_sub_words_loop: 496.L_bn_sub_words_loop:
497 ld ta0,0(a2) 497 ld ta0,0(a2)
498 subu a3,4
498 ld t1,8(a1) 499 ld t1,8(a1)
499 ld ta1,8(a2) 500 and AT,a3,MINUS4
500 ld t2,16(a1) 501 ld t2,16(a1)
501 ld ta2,16(a2) 502 PTR_ADD a2,32
502 ld t3,24(a1) 503 ld t3,24(a1)
503 ld ta3,24(a2) 504 PTR_ADD a0,32
505 ld ta1,-24(a2)
506 PTR_ADD a1,32
507 ld ta2,-16(a2)
508 ld ta3,-8(a2)
504 sltu t8,t0,ta0 509 sltu t8,t0,ta0
505 dsubu t0,ta0 510 dsubu t0,ta0
506 subu a3,4
507 dsubu ta0,t0,v0 511 dsubu ta0,t0,v0
508 and AT,a3,MINUS4 512 sd ta0,-32(a0)
509 sd ta0,0(a0)
510 MOVNZ (t0,v0,t8) 513 MOVNZ (t0,v0,t8)
511 514
512 sltu t9,t1,ta1 515 sltu t9,t1,ta1
513 dsubu t1,ta1 516 dsubu t1,ta1
514 PTR_ADD a0,32
515 dsubu ta1,t1,v0 517 dsubu ta1,t1,v0
516 PTR_ADD a1,32
517 sd ta1,-24(a0) 518 sd ta1,-24(a0)
518 MOVNZ (t1,v0,t9) 519 MOVNZ (t1,v0,t9)
519 520
@@ -521,7 +522,6 @@ LEAF(bn_sub_words)
521 sltu t8,t2,ta2 522 sltu t8,t2,ta2
522 dsubu t2,ta2 523 dsubu t2,ta2
523 dsubu ta2,t2,v0 524 dsubu ta2,t2,v0
524 PTR_ADD a2,32
525 sd ta2,-16(a0) 525 sd ta2,-16(a0)
526 MOVNZ (t2,v0,t8) 526 MOVNZ (t2,v0,t8)
527 527
@@ -574,6 +574,51 @@ END(bn_sub_words)
574 574
575#undef MINUS4 575#undef MINUS4
576 576
577.align 5
578LEAF(bn_div_3_words)
579 .set reorder
580 move a3,a0 /* we know that bn_div_words doesn't
581 * touch a3, ta2, ta3 and preserves a2
582 * so that we can save two arguments
583 * and return address in registers
584 * instead of stack:-)
585 */
586 ld a0,(a3)
587 move ta2,a1
588 ld a1,-8(a3)
589 move ta3,ra
590 move v1,zero
591 li v0,-1
592 beq a0,a2,.L_bn_div_3_words_skip_div
593 bal bn_div_words
594 move ra,ta3
595.L_bn_div_3_words_skip_div:
596 dmultu ta2,v0
597 ld t2,-16(a3)
598 move ta0,zero
599 mfhi t1
600 mflo t0
601 sltu t8,t1,v1
602.L_bn_div_3_words_inner_loop:
603 bnez t8,.L_bn_div_3_words_inner_loop_done
604 sgeu AT,t2,t0
605 seq t9,t1,v1
606 and AT,t9
607 sltu t3,t0,ta2
608 daddu v1,a2
609 dsubu t1,t3
610 dsubu t0,ta2
611 sltu t8,t1,v1
612 sltu ta0,v1,a2
613 or t8,ta0
614 .set noreorder
615 beqzl AT,.L_bn_div_3_words_inner_loop
616 dsubu v0,1
617 .set reorder
618.L_bn_div_3_words_inner_loop_done:
619 jr ra
620END(bn_div_3_words)
621
577.align 5 622.align 5
578LEAF(bn_div_words) 623LEAF(bn_div_words)
579 .set noreorder 624 .set noreorder
@@ -633,16 +678,16 @@ LEAF(bn_div_words)
633 seq t8,HH,t1 678 seq t8,HH,t1
634 sltu AT,HH,t1 679 sltu AT,HH,t1
635 and t2,t8 680 and t2,t8
681 sltu v0,t0,a2
636 or AT,t2 682 or AT,t2
637 .set noreorder 683 .set noreorder
638 beqz AT,.L_bn_div_words_inner_loop1_done 684 beqz AT,.L_bn_div_words_inner_loop1_done
639 sltu t2,t0,a2 685 dsubu t1,v0
640 .set reorder
641 dsubu QT,1
642 dsubu t0,a2 686 dsubu t0,a2
643 dsubu t1,t2
644 b .L_bn_div_words_inner_loop1 687 b .L_bn_div_words_inner_loop1
645.L_bn_div_words_inner_loop1_done: 688 dsubu QT,1
689 .set reorder
690.L_bn_div_words_inner_loop1_done:
646 691
647 dsll a1,32 692 dsll a1,32
648 dsubu a0,t3,t0 693 dsubu a0,t3,t0
@@ -655,6 +700,7 @@ LEAF(bn_div_words)
655 ddivu zero,a0,DH 700 ddivu zero,a0,DH
656 mflo QT 701 mflo QT
657.L_bn_div_words_skip_div2: 702.L_bn_div_words_skip_div2:
703#undef DH
658 dmultu a2,QT 704 dmultu a2,QT
659 dsll t3,a0,32 705 dsll t3,a0,32
660 dsrl AT,a1,32 706 dsrl AT,a1,32
@@ -666,69 +712,26 @@ LEAF(bn_div_words)
666 seq t8,HH,t1 712 seq t8,HH,t1
667 sltu AT,HH,t1 713 sltu AT,HH,t1
668 and t2,t8 714 and t2,t8
715 sltu v1,t0,a2
669 or AT,t2 716 or AT,t2
670 .set noreorder 717 .set noreorder
671 beqz AT,.L_bn_div_words_inner_loop2_done 718 beqz AT,.L_bn_div_words_inner_loop2_done
672 sltu t2,t0,a2 719 dsubu t1,v1
673 .set reorder
674 dsubu QT,1
675 dsubu t0,a2 720 dsubu t0,a2
676 dsubu t1,t2
677 b .L_bn_div_words_inner_loop2 721 b .L_bn_div_words_inner_loop2
722 dsubu QT,1
723 .set reorder
678.L_bn_div_words_inner_loop2_done: 724.L_bn_div_words_inner_loop2_done:
725#undef HH
679 726
680 dsubu a0,t3,t0 727 dsubu a0,t3,t0
681 or v0,QT 728 or v0,QT
682 dsrl v1,a0,t9 /* v1 contains remainder if anybody wants it */ 729 dsrl v1,a0,t9 /* v1 contains remainder if anybody wants it */
683 dsrl a2,t9 /* restore a2 */ 730 dsrl a2,t9 /* restore a2 */
684 jr ra 731 jr ra
685#undef HH
686#undef DH
687#undef QT 732#undef QT
688END(bn_div_words) 733END(bn_div_words)
689 734
690.align 5
691LEAF(bn_div_3_words)
692 .set reorder
693 move a3,a0 /* we know that bn_div_words doesn't
694 * touch a3, ta2, ta3 and preserves a2
695 * so that we can save two arguments
696 * and return address in registers
697 * instead of stack:-)
698 */
699 ld a0,(a3)
700 move ta2,a2
701 move a2,a1
702 ld a1,-8(a3)
703 move ta3,ra
704 move v1,zero
705 li v0,-1
706 beq a0,a2,.L_bn_div_3_words_skip_div
707 jal bn_div_words
708 move ra,ta3
709.L_bn_div_3_words_skip_div:
710 dmultu ta2,v0
711 ld t2,-16(a3)
712 mflo t0
713 mfhi t1
714.L_bn_div_3_words_inner_loop:
715 sgeu AT,t2,t0
716 seq t9,t1,v1
717 sltu t8,t1,v1
718 and AT,t9
719 or AT,t8
720 bnez AT,.L_bn_div_3_words_inner_loop_done
721 daddu v1,a2
722 sltu t3,t0,ta2
723 sltu AT,v1,a2
724 dsubu v0,1
725 dsubu t0,ta2
726 dsubu t1,t3
727 beqz AT,.L_bn_div_3_words_inner_loop
728.L_bn_div_3_words_inner_loop_done:
729 jr ra
730END(bn_div_3_words)
731
732#define a_0 t0 735#define a_0 t0
733#define a_1 t1 736#define a_1 t1
734#define a_2 t2 737#define a_2 t2
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
index f935e1ca79..d8822610df 100644
--- a/src/lib/libcrypto/bn/bn.h
+++ b/src/lib/libcrypto/bn/bn.h
@@ -83,12 +83,12 @@ extern "C" {
83 * The reason for this flag is that when the particular C compiler 83 * The reason for this flag is that when the particular C compiler
84 * library routine is used, and the library is linked with a different 84 * library routine is used, and the library is linked with a different
85 * compiler, the library is missing. This mostly happens when the 85 * compiler, the library is missing. This mostly happens when the
86 * library is built with gcc and then linked using nornal cc. This would 86 * library is built with gcc and then linked using normal cc. This would
87 * be a common occurance because gcc normally produces code that is 87 * be a common occurrence because gcc normally produces code that is
88 * 2 times faster than system compilers for the big number stuff. 88 * 2 times faster than system compilers for the big number stuff.
89 * For machines with only one compiler (or shared libraries), this should 89 * For machines with only one compiler (or shared libraries), this should
90 * be on. Again this in only really a problem on machines 90 * be on. Again this in only really a problem on machines
91 * using "long long's", are 32bit, and are not using my assember code. */ 91 * using "long long's", are 32bit, and are not using my assembler code. */
92#if defined(MSDOS) || defined(WINDOWS) || defined(linux) 92#if defined(MSDOS) || defined(WINDOWS) || defined(linux)
93#define BN_DIV2W 93#define BN_DIV2W
94#endif 94#endif
@@ -118,8 +118,8 @@ extern "C" {
118 118
119/* This is where the long long data type is 64 bits, but long is 32. 119/* This is where the long long data type is 64 bits, but long is 32.
120 * For machines where there are 64bit registers, this is the mode to use. 120 * For machines where there are 64bit registers, this is the mode to use.
121 * IRIX, on R4000 and above should use this mode, along with the relevent 121 * IRIX, on R4000 and above should use this mode, along with the relevant
122 * assember code :-). Do NOT define BN_LLONG. 122 * assembler code :-). Do NOT define BN_LLONG.
123 */ 123 */
124#ifdef SIXTY_FOUR_BIT 124#ifdef SIXTY_FOUR_BIT
125#undef BN_LLONG 125#undef BN_LLONG
@@ -240,11 +240,15 @@ typedef struct bignum_st
240 240
241/* Used for temp variables */ 241/* Used for temp variables */
242#define BN_CTX_NUM 12 242#define BN_CTX_NUM 12
243#define BN_CTX_NUM_POS 12
243typedef struct bignum_ctx 244typedef struct bignum_ctx
244 { 245 {
245 int tos; 246 int tos;
246 BIGNUM bn[BN_CTX_NUM+1]; 247 BIGNUM bn[BN_CTX_NUM];
247 int flags; 248 int flags;
249 int depth;
250 int pos[BN_CTX_NUM_POS];
251 int too_many;
248 } BN_CTX; 252 } BN_CTX;
249 253
250typedef struct bn_blinding_st 254typedef struct bn_blinding_st
@@ -257,16 +261,15 @@ typedef struct bn_blinding_st
257 261
258/* Used for montgomery multiplication */ 262/* Used for montgomery multiplication */
259typedef struct bn_mont_ctx_st 263typedef struct bn_mont_ctx_st
260 { 264 {
261 int use_word; /* 0 for word form, 1 for long form */ 265 int ri; /* number of bits in R */
262 int ri; /* number of bits in R */ 266 BIGNUM RR; /* used to convert to montgomery form */
263 BIGNUM RR; /* used to convert to montgomery form */ 267 BIGNUM N; /* The modulus */
264 BIGNUM N; /* The modulus */ 268 BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
265 BIGNUM Ni; /* The inverse of N */ 269 * (Ni is only stored for bignum algorithm) */
266 BN_ULONG n0; /* word form of inverse, normally only one of 270 BN_ULONG n0; /* least significant word of Ni */
267 * Ni or n0 is defined */
268 int flags; 271 int flags;
269 } BN_MONT_CTX; 272 } BN_MONT_CTX;
270 273
271/* Used for reciprocal division/mod functions 274/* Used for reciprocal division/mod functions
272 * It cannot be shared between threads 275 * It cannot be shared between threads
@@ -283,7 +286,26 @@ typedef struct bn_recp_ctx_st
283#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ 286#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
284 r,a,&((mont)->RR),(mont),ctx) 287 r,a,&((mont)->RR),(mont),ctx)
285 288
286#define BN_prime_checks (5) 289#define BN_prime_checks 0 /* default: select number of iterations
290 based on the size of the number */
291
292/* number of Miller-Rabin iterations for an error rate of less than 2^-80
293 * for random 'b'-bit input, b >= 100 (taken from table 4.4 in the Handbook
294 * of Applied Cryptography [Menezes, van Oorschot, Vanstone; CRC Press 1996];
295 * original paper: Damgaard, Landrock, Pomerance: Average case error estimates
296 * for the strong probable prime test. -- Math. Comp. 61 (1993) 177-194) */
297#define BN_prime_checks_for_size(b) ((b) >= 1300 ? 2 : \
298 (b) >= 850 ? 3 : \
299 (b) >= 650 ? 4 : \
300 (b) >= 550 ? 5 : \
301 (b) >= 450 ? 6 : \
302 (b) >= 400 ? 7 : \
303 (b) >= 350 ? 8 : \
304 (b) >= 300 ? 9 : \
305 (b) >= 250 ? 12 : \
306 (b) >= 200 ? 15 : \
307 (b) >= 150 ? 18 : \
308 /* b >= 100 */ 27)
287 309
288#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) 310#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
289#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) 311#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
@@ -296,26 +318,16 @@ typedef struct bn_recp_ctx_st
296/*#define BN_ascii2bn(a) BN_hex2bn(a) */ 318/*#define BN_ascii2bn(a) BN_hex2bn(a) */
297/*#define BN_bn2ascii(a) BN_bn2hex(a) */ 319/*#define BN_bn2ascii(a) BN_bn2hex(a) */
298 320
299#define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\
300 (n):bn_expand2((n),(b)/BN_BITS2+1))
301#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b)))
302
303#define bn_fix_top(a) \
304 { \
305 BN_ULONG *ftl; \
306 if ((a)->top > 0) \
307 { \
308 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
309 if (*(ftl--)) break; \
310 } \
311 }
312
313BIGNUM *BN_value_one(void); 321BIGNUM *BN_value_one(void);
314char * BN_options(void); 322char * BN_options(void);
315BN_CTX *BN_CTX_new(void); 323BN_CTX *BN_CTX_new(void);
316void BN_CTX_init(BN_CTX *c); 324void BN_CTX_init(BN_CTX *c);
317void BN_CTX_free(BN_CTX *c); 325void BN_CTX_free(BN_CTX *c);
326void BN_CTX_start(BN_CTX *ctx);
327BIGNUM *BN_CTX_get(BN_CTX *ctx);
328void BN_CTX_end(BN_CTX *ctx);
318int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); 329int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
330int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom);
319int BN_num_bits(const BIGNUM *a); 331int BN_num_bits(const BIGNUM *a);
320int BN_num_bits_word(BN_ULONG); 332int BN_num_bits_word(BN_ULONG);
321BIGNUM *BN_new(void); 333BIGNUM *BN_new(void);
@@ -329,13 +341,13 @@ int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
329int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 341int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
330int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 342int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
331int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 343int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
332int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b); 344int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
333int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); 345int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
334int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, 346int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
335 BN_CTX *ctx); 347 BN_CTX *ctx);
336int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx); 348int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
337int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx); 349int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx);
338BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w); 350BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
339BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); 351BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
340int BN_mul_word(BIGNUM *a, BN_ULONG w); 352int BN_mul_word(BIGNUM *a, BN_ULONG w);
341int BN_add_word(BIGNUM *a, BN_ULONG w); 353int BN_add_word(BIGNUM *a, BN_ULONG w);
@@ -358,19 +370,18 @@ int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p,
358 BIGNUM *m,BN_CTX *ctx); 370 BIGNUM *m,BN_CTX *ctx);
359int BN_mask_bits(BIGNUM *a,int n); 371int BN_mask_bits(BIGNUM *a,int n);
360int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); 372int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
361#ifndef WIN16 373#ifndef NO_FP_API
362int BN_print_fp(FILE *fp, BIGNUM *a); 374int BN_print_fp(FILE *fp, const BIGNUM *a);
363#endif 375#endif
364#ifdef HEADER_BIO_H 376#ifdef HEADER_BIO_H
365int BN_print(BIO *fp, const BIGNUM *a); 377int BN_print(BIO *fp, const BIGNUM *a);
366#else 378#else
367int BN_print(char *fp, const BIGNUM *a); 379int BN_print(void *fp, const BIGNUM *a);
368#endif 380#endif
369int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx); 381int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx);
370int BN_rshift(BIGNUM *r, BIGNUM *a, int n); 382int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
371int BN_rshift1(BIGNUM *r, BIGNUM *a); 383int BN_rshift1(BIGNUM *r, BIGNUM *a);
372void BN_clear(BIGNUM *a); 384void BN_clear(BIGNUM *a);
373BIGNUM *bn_expand2(BIGNUM *b, int bits);
374BIGNUM *BN_dup(const BIGNUM *a); 385BIGNUM *BN_dup(const BIGNUM *a);
375int BN_ucmp(const BIGNUM *a, const BIGNUM *b); 386int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
376int BN_set_bit(BIGNUM *a, int n); 387int BN_set_bit(BIGNUM *a, int n);
@@ -381,19 +392,16 @@ int BN_hex2bn(BIGNUM **a, const char *str);
381int BN_dec2bn(BIGNUM **a, const char *str); 392int BN_dec2bn(BIGNUM **a, const char *str);
382int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx); 393int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx);
383BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); 394BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
384BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int strong,BIGNUM *add, 395BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,BIGNUM *add,
385 BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg); 396 BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg);
386int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,void *), 397int BN_is_prime(const BIGNUM *p,int nchecks,
398 void (*callback)(int,int,void *),
387 BN_CTX *ctx,void *cb_arg); 399 BN_CTX *ctx,void *cb_arg);
400int BN_is_prime_fasttest(const BIGNUM *p,int nchecks,
401 void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg,
402 int do_trial_division);
388void ERR_load_BN_strings(void ); 403void ERR_load_BN_strings(void );
389 404
390BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
391BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
392void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
393BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
394BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
395BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
396
397BN_MONT_CTX *BN_MONT_CTX_new(void ); 405BN_MONT_CTX *BN_MONT_CTX_new(void );
398void BN_MONT_CTX_init(BN_MONT_CTX *ctx); 406void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
399int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont, 407int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont,
@@ -423,6 +431,39 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
423int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, 431int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m,
424 BN_RECP_CTX *recp, BN_CTX *ctx); 432 BN_RECP_CTX *recp, BN_CTX *ctx);
425 433
434/* library internal functions */
435
436#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->max)?\
437 (a):bn_expand2((a),(bits)/BN_BITS2+1))
438#define bn_wexpand(a,words) (((words) <= (a)->max)?(a):bn_expand2((a),(words)))
439BIGNUM *bn_expand2(BIGNUM *a, int words);
440
441#define bn_fix_top(a) \
442 { \
443 BN_ULONG *ftl; \
444 if ((a)->top > 0) \
445 { \
446 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
447 if (*(ftl--)) break; \
448 } \
449 }
450
451BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
452BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
453void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
454BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
455BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
456BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
457
458#ifdef BN_DEBUG
459 void bn_dump1(FILE *o, const char *a, BN_ULONG *b,int n);
460# define bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \
461 fprintf(stderr,"\n");}
462# define bn_dump(a,n) bn_dump1(stderr,#a,a,n);
463#else
464# define bn_print(a)
465# define bn_dump(a,b)
466#endif
426 467
427/* BEGIN ERROR CODES */ 468/* BEGIN ERROR CODES */
428/* The following lines are auto generated by the script mkerr.pl. Any changes 469/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -438,6 +479,7 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m,
438#define BN_F_BN_BLINDING_UPDATE 103 479#define BN_F_BN_BLINDING_UPDATE 103
439#define BN_F_BN_BN2DEC 104 480#define BN_F_BN_BN2DEC 104
440#define BN_F_BN_BN2HEX 105 481#define BN_F_BN_BN2HEX 105
482#define BN_F_BN_CTX_GET 116
441#define BN_F_BN_CTX_NEW 106 483#define BN_F_BN_CTX_NEW 106
442#define BN_F_BN_DIV 107 484#define BN_F_BN_DIV 107
443#define BN_F_BN_EXPAND2 108 485#define BN_F_BN_EXPAND2 108
@@ -459,6 +501,7 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m,
459#define BN_R_INVALID_LENGTH 106 501#define BN_R_INVALID_LENGTH 106
460#define BN_R_NOT_INITIALIZED 107 502#define BN_R_NOT_INITIALIZED 107
461#define BN_R_NO_INVERSE 108 503#define BN_R_NO_INVERSE 108
504#define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109
462 505
463#ifdef __cplusplus 506#ifdef __cplusplus
464} 507}
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
index c5ab066c9e..5d24691233 100644
--- a/src/lib/libcrypto/bn/bn_add.c
+++ b/src/lib/libcrypto/bn/bn_add.c
@@ -61,9 +61,9 @@
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63/* r can == a or b */ 63/* r can == a or b */
64int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b) 64int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
65 { 65 {
66 BIGNUM *tmp; 66 const BIGNUM *tmp;
67 67
68 bn_check_top(a); 68 bn_check_top(a);
69 bn_check_top(b); 69 bn_check_top(b);
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c
index 4d3da16a0c..3329cc18e6 100644
--- a/src/lib/libcrypto/bn/bn_asm.c
+++ b/src/lib/libcrypto/bn/bn_asm.c
@@ -56,31 +56,38 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef BN_DEBUG
60# undef NDEBUG /* avoid conflicting definitions */
61# define NDEBUG
62#endif
63
59#include <stdio.h> 64#include <stdio.h>
65#include <assert.h>
60#include "cryptlib.h" 66#include "cryptlib.h"
61#include "bn_lcl.h" 67#include "bn_lcl.h"
62 68
63#ifdef BN_LLONG 69#if defined(BN_LLONG) || defined(BN_UMULT_HIGH)
64 70
65BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) 71BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
66 { 72 {
67 BN_ULONG c1=0; 73 BN_ULONG c1=0;
68 74
69 bn_check_num(num); 75 assert(num >= 0);
70 if (num <= 0) return(c1); 76 if (num <= 0) return(c1);
71 77
72 for (;;) 78 while (num&~3)
73 { 79 {
74 mul_add(rp[0],ap[0],w,c1); 80 mul_add(rp[0],ap[0],w,c1);
75 if (--num == 0) break;
76 mul_add(rp[1],ap[1],w,c1); 81 mul_add(rp[1],ap[1],w,c1);
77 if (--num == 0) break;
78 mul_add(rp[2],ap[2],w,c1); 82 mul_add(rp[2],ap[2],w,c1);
79 if (--num == 0) break;
80 mul_add(rp[3],ap[3],w,c1); 83 mul_add(rp[3],ap[3],w,c1);
81 if (--num == 0) break; 84 ap+=4; rp+=4; num-=4;
82 ap+=4; 85 }
83 rp+=4; 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;
84 } 91 }
85 92
86 return(c1); 93 return(c1);
@@ -90,63 +97,54 @@ BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
90 { 97 {
91 BN_ULONG c1=0; 98 BN_ULONG c1=0;
92 99
93 bn_check_num(num); 100 assert(num >= 0);
94 if (num <= 0) return(c1); 101 if (num <= 0) return(c1);
95 102
96 /* for (;;) */ 103 while (num&~3)
97 while (1) /* circumvent egcs-1.1.2 bug */
98 { 104 {
99 mul(rp[0],ap[0],w,c1); 105 mul(rp[0],ap[0],w,c1);
100 if (--num == 0) break;
101 mul(rp[1],ap[1],w,c1); 106 mul(rp[1],ap[1],w,c1);
102 if (--num == 0) break;
103 mul(rp[2],ap[2],w,c1); 107 mul(rp[2],ap[2],w,c1);
104 if (--num == 0) break;
105 mul(rp[3],ap[3],w,c1); 108 mul(rp[3],ap[3],w,c1);
106 if (--num == 0) break; 109 ap+=4; rp+=4; num-=4;
107 ap+=4; 110 }
108 rp+=4; 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);
109 } 116 }
110 return(c1); 117 return(c1);
111 } 118 }
112 119
113void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) 120void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
114 { 121 {
115 bn_check_num(n); 122 assert(n >= 0);
116 if (n <= 0) return; 123 if (n <= 0) return;
117 for (;;) 124 while (n&~3)
118 { 125 {
119 BN_ULLONG t; 126 sqr(r[0],r[1],a[0]);
120 127 sqr(r[2],r[3],a[1]);
121 t=(BN_ULLONG)(a[0])*(a[0]); 128 sqr(r[4],r[5],a[2]);
122 r[0]=Lw(t); r[1]=Hw(t); 129 sqr(r[6],r[7],a[3]);
123 if (--n == 0) break; 130 a+=4; r+=8; n-=4;
124 131 }
125 t=(BN_ULLONG)(a[1])*(a[1]); 132 if (n)
126 r[2]=Lw(t); r[3]=Hw(t); 133 {
127 if (--n == 0) break; 134 sqr(r[0],r[1],a[0]); if (--n == 0) return;
128 135 sqr(r[2],r[3],a[1]); if (--n == 0) return;
129 t=(BN_ULLONG)(a[2])*(a[2]); 136 sqr(r[4],r[5],a[2]);
130 r[4]=Lw(t); r[5]=Hw(t);
131 if (--n == 0) break;
132
133 t=(BN_ULLONG)(a[3])*(a[3]);
134 r[6]=Lw(t); r[7]=Hw(t);
135 if (--n == 0) break;
136
137 a+=4;
138 r+=8;
139 } 137 }
140 } 138 }
141 139
142#else 140#else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
143 141
144BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) 142BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
145 { 143 {
146 BN_ULONG c=0; 144 BN_ULONG c=0;
147 BN_ULONG bl,bh; 145 BN_ULONG bl,bh;
148 146
149 bn_check_num(num); 147 assert(num >= 0);
150 if (num <= 0) return((BN_ULONG)0); 148 if (num <= 0) return((BN_ULONG)0);
151 149
152 bl=LBITS(w); 150 bl=LBITS(w);
@@ -173,7 +171,7 @@ BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
173 BN_ULONG carry=0; 171 BN_ULONG carry=0;
174 BN_ULONG bl,bh; 172 BN_ULONG bl,bh;
175 173
176 bn_check_num(num); 174 assert(num >= 0);
177 if (num <= 0) return((BN_ULONG)0); 175 if (num <= 0) return((BN_ULONG)0);
178 176
179 bl=LBITS(w); 177 bl=LBITS(w);
@@ -197,7 +195,7 @@ BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
197 195
198void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) 196void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
199 { 197 {
200 bn_check_num(n); 198 assert(n >= 0);
201 if (n <= 0) return; 199 if (n <= 0) return;
202 for (;;) 200 for (;;)
203 { 201 {
@@ -218,7 +216,7 @@ void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
218 } 216 }
219 } 217 }
220 218
221#endif 219#endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
222 220
223#if defined(BN_LLONG) && defined(BN_DIV2W) 221#if defined(BN_LLONG) && defined(BN_DIV2W)
224 222
@@ -300,14 +298,14 @@ BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
300 ret|=q; 298 ret|=q;
301 return(ret); 299 return(ret);
302 } 300 }
303#endif 301#endif /* !defined(BN_LLONG) && defined(BN_DIV2W) */
304 302
305#ifdef BN_LLONG 303#ifdef BN_LLONG
306BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) 304BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
307 { 305 {
308 BN_ULLONG ll=0; 306 BN_ULLONG ll=0;
309 307
310 bn_check_num(n); 308 assert(n >= 0);
311 if (n <= 0) return((BN_ULONG)0); 309 if (n <= 0) return((BN_ULONG)0);
312 310
313 for (;;) 311 for (;;)
@@ -338,12 +336,12 @@ BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
338 } 336 }
339 return((BN_ULONG)ll); 337 return((BN_ULONG)ll);
340 } 338 }
341#else 339#else /* !BN_LLONG */
342BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) 340BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
343 { 341 {
344 BN_ULONG c,l,t; 342 BN_ULONG c,l,t;
345 343
346 bn_check_num(n); 344 assert(n >= 0);
347 if (n <= 0) return((BN_ULONG)0); 345 if (n <= 0) return((BN_ULONG)0);
348 346
349 c=0; 347 c=0;
@@ -387,14 +385,14 @@ BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
387 } 385 }
388 return((BN_ULONG)c); 386 return((BN_ULONG)c);
389 } 387 }
390#endif 388#endif /* !BN_LLONG */
391 389
392BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) 390BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
393 { 391 {
394 BN_ULONG t1,t2; 392 BN_ULONG t1,t2;
395 int c=0; 393 int c=0;
396 394
397 bn_check_num(n); 395 assert(n >= 0);
398 if (n <= 0) return((BN_ULONG)0); 396 if (n <= 0) return((BN_ULONG)0);
399 397
400 for (;;) 398 for (;;)
@@ -433,6 +431,11 @@ BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
433#undef bn_sqr_comba8 431#undef bn_sqr_comba8
434#undef bn_sqr_comba4 432#undef bn_sqr_comba4
435 433
434/* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */
435/* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */
436/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
437/* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
438
436#ifdef BN_LLONG 439#ifdef BN_LLONG
437#define mul_add_c(a,b,c0,c1,c2) \ 440#define mul_add_c(a,b,c0,c1,c2) \
438 t=(BN_ULLONG)a*b; \ 441 t=(BN_ULLONG)a*b; \
@@ -460,7 +463,39 @@ BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
460 463
461#define sqr_add_c2(a,i,j,c0,c1,c2) \ 464#define sqr_add_c2(a,i,j,c0,c1,c2) \
462 mul_add_c2((a)[i],(a)[j],c0,c1,c2) 465 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
463#else 466
467#elif defined(BN_UMULT_HIGH)
468
469#define mul_add_c(a,b,c0,c1,c2) { \
470 BN_ULONG ta=(a),tb=(b); \
471 t1 = ta * tb; \
472 t2 = BN_UMULT_HIGH(ta,tb); \
473 c0 += t1; t2 += (c0<t1)?1:0; \
474 c1 += t2; c2 += (c1<t2)?1:0; \
475 }
476
477#define mul_add_c2(a,b,c0,c1,c2) { \
478 BN_ULONG ta=(a),tb=(b),t0; \
479 t1 = BN_UMULT_HIGH(ta,tb); \
480 t0 = ta * tb; \
481 t2 = t1+t1; c2 += (t2<t1)?1:0; \
482 t1 = t0+t0; t2 += (t1<t0)?1:0; \
483 c0 += t1; t2 += (c0<t1)?1:0; \
484 c1 += t2; c2 += (c1<t2)?1:0; \
485 }
486
487#define sqr_add_c(a,i,c0,c1,c2) { \
488 BN_ULONG ta=(a)[i]; \
489 t1 = ta * ta; \
490 t2 = BN_UMULT_HIGH(ta,ta); \
491 c0 += t1; t2 += (c0<t1)?1:0; \
492 c1 += t2; c2 += (c1<t2)?1:0; \
493 }
494
495#define sqr_add_c2(a,i,j,c0,c1,c2) \
496 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
497
498#else /* !BN_LLONG */
464#define mul_add_c(a,b,c0,c1,c2) \ 499#define mul_add_c(a,b,c0,c1,c2) \
465 t1=LBITS(a); t2=HBITS(a); \ 500 t1=LBITS(a); t2=HBITS(a); \
466 bl=LBITS(b); bh=HBITS(b); \ 501 bl=LBITS(b); bh=HBITS(b); \
@@ -487,7 +522,7 @@ BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
487 522
488#define sqr_add_c2(a,i,j,c0,c1,c2) \ 523#define sqr_add_c2(a,i,j,c0,c1,c2) \
489 mul_add_c2((a)[i],(a)[j],c0,c1,c2) 524 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
490#endif 525#endif /* !BN_LLONG */
491 526
492void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) 527void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
493 { 528 {
@@ -762,7 +797,7 @@ void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
762 r[6]=c1; 797 r[6]=c1;
763 r[7]=c2; 798 r[7]=c2;
764 } 799 }
765#else 800#else /* !BN_MUL_COMBA */
766 801
767/* hmm... is it faster just to do a multiply? */ 802/* hmm... is it faster just to do a multiply? */
768#undef bn_sqr_comba4 803#undef bn_sqr_comba4
@@ -799,4 +834,4 @@ void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
799 r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]); 834 r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
800 } 835 }
801 836
802#endif /* BN_COMBA */ 837#endif /* !BN_MUL_COMBA */
diff --git a/src/lib/libcrypto/bn/bn_comba.c b/src/lib/libcrypto/bn/bn_comba.c
index 7ad09b4a6d..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/bn_comba.c
+++ b/src/lib/libcrypto/bn/bn_comba.c
@@ -1,345 +0,0 @@
1/* crypto/bn/bn_comba.c */
2#include <stdio.h>
3#include "bn_lcl.h"
4/* Auto generated from crypto/bn/comba.pl
5 */
6
7#undef bn_mul_comba8
8#undef bn_mul_comba4
9#undef bn_sqr_comba8
10#undef bn_sqr_comba4
11
12#ifdef BN_LLONG
13#define mul_add_c(a,b,c0,c1,c2) \
14 t=(BN_ULLONG)a*b; \
15 t1=(BN_ULONG)Lw(t); \
16 t2=(BN_ULONG)Hw(t); \
17 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
18 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
19
20#define mul_add_c2(a,b,c0,c1,c2) \
21 t=(BN_ULLONG)a*b; \
22 tt=(t+t)&BN_MASK; \
23 if (tt < t) c2++; \
24 t1=(BN_ULONG)Lw(tt); \
25 t2=(BN_ULONG)Hw(tt); \
26 c0=(c0+t1)&BN_MASK2; \
27 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
28 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
29
30#define sqr_add_c(a,i,c0,c1,c2) \
31 t=(BN_ULLONG)a[i]*a[i]; \
32 t1=(BN_ULONG)Lw(t); \
33 t2=(BN_ULONG)Hw(t); \
34 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
35 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
36
37#define sqr_add_c2(a,i,j,c0,c1,c2) \
38 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
39#else
40#define mul_add_c(a,b,c0,c1,c2) \
41 t1=LBITS(a); t2=HBITS(a); \
42 bl=LBITS(b); bh=HBITS(b); \
43 mul64(t1,t2,bl,bh); \
44 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
45 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
46
47#define mul_add_c2(a,b,c0,c1,c2) \
48 t1=LBITS(a); t2=HBITS(a); \
49 bl=LBITS(b); bh=HBITS(b); \
50 mul64(t1,t2,bl,bh); \
51 if (t2 & BN_TBIT) c2++; \
52 t2=(t2+t2)&BN_MASK2; \
53 if (t1 & BN_TBIT) t2++; \
54 t1=(t1+t1)&BN_MASK2; \
55 c0=(c0+t1)&BN_MASK2; \
56 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
57 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
58
59#define sqr_add_c(a,i,c0,c1,c2) \
60 sqr64(t1,t2,(a)[i]); \
61 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
62 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
63
64#define sqr_add_c2(a,i,j,c0,c1,c2) \
65 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
66#endif
67
68void bn_mul_comba88(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
69void bn_mul_comba44(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
70void bn_sqr_comba88(BN_ULONG *r,BN_ULONG *a);
71void bn_sqr_comba44(BN_ULONG *r,BN_ULONG *a);
72
73void bn_mul_comba88(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
74 {
75#ifdef BN_LLONG
76 BN_ULLONG t;
77#else
78 BN_ULONG bl,bh;
79#endif
80 BN_ULONG t1,t2;
81 BN_ULONG c1,c2,c3;
82
83 c1=0;
84 c2=0;
85 c3=0;
86 mul_add_c(a[0],b[0],c1,c2,c3);
87 r[0]=c1;
88 c1=0;
89 mul_add_c(a[0],b[1],c2,c3,c1);
90 mul_add_c(a[1],b[0],c2,c3,c1);
91 r[1]=c2;
92 c2=0;
93 mul_add_c(a[2],b[0],c3,c1,c2);
94 mul_add_c(a[1],b[1],c3,c1,c2);
95 mul_add_c(a[0],b[2],c3,c1,c2);
96 r[2]=c3;
97 c3=0;
98 mul_add_c(a[0],b[3],c1,c2,c3);
99 mul_add_c(a[1],b[2],c1,c2,c3);
100 mul_add_c(a[2],b[1],c1,c2,c3);
101 mul_add_c(a[3],b[0],c1,c2,c3);
102 r[3]=c1;
103 c1=0;
104 mul_add_c(a[4],b[0],c2,c3,c1);
105 mul_add_c(a[3],b[1],c2,c3,c1);
106 mul_add_c(a[2],b[2],c2,c3,c1);
107 mul_add_c(a[1],b[3],c2,c3,c1);
108 mul_add_c(a[0],b[4],c2,c3,c1);
109 r[4]=c2;
110 c2=0;
111 mul_add_c(a[0],b[5],c3,c1,c2);
112 mul_add_c(a[1],b[4],c3,c1,c2);
113 mul_add_c(a[2],b[3],c3,c1,c2);
114 mul_add_c(a[3],b[2],c3,c1,c2);
115 mul_add_c(a[4],b[1],c3,c1,c2);
116 mul_add_c(a[5],b[0],c3,c1,c2);
117 r[5]=c3;
118 c3=0;
119 mul_add_c(a[6],b[0],c1,c2,c3);
120 mul_add_c(a[5],b[1],c1,c2,c3);
121 mul_add_c(a[4],b[2],c1,c2,c3);
122 mul_add_c(a[3],b[3],c1,c2,c3);
123 mul_add_c(a[2],b[4],c1,c2,c3);
124 mul_add_c(a[1],b[5],c1,c2,c3);
125 mul_add_c(a[0],b[6],c1,c2,c3);
126 r[6]=c1;
127 c1=0;
128 mul_add_c(a[0],b[7],c2,c3,c1);
129 mul_add_c(a[1],b[6],c2,c3,c1);
130 mul_add_c(a[2],b[5],c2,c3,c1);
131 mul_add_c(a[3],b[4],c2,c3,c1);
132 mul_add_c(a[4],b[3],c2,c3,c1);
133 mul_add_c(a[5],b[2],c2,c3,c1);
134 mul_add_c(a[6],b[1],c2,c3,c1);
135 mul_add_c(a[7],b[0],c2,c3,c1);
136 r[7]=c2;
137 c2=0;
138 mul_add_c(a[7],b[1],c3,c1,c2);
139 mul_add_c(a[6],b[2],c3,c1,c2);
140 mul_add_c(a[5],b[3],c3,c1,c2);
141 mul_add_c(a[4],b[4],c3,c1,c2);
142 mul_add_c(a[3],b[5],c3,c1,c2);
143 mul_add_c(a[2],b[6],c3,c1,c2);
144 mul_add_c(a[1],b[7],c3,c1,c2);
145 r[8]=c3;
146 c3=0;
147 mul_add_c(a[2],b[7],c1,c2,c3);
148 mul_add_c(a[3],b[6],c1,c2,c3);
149 mul_add_c(a[4],b[5],c1,c2,c3);
150 mul_add_c(a[5],b[4],c1,c2,c3);
151 mul_add_c(a[6],b[3],c1,c2,c3);
152 mul_add_c(a[7],b[2],c1,c2,c3);
153 r[9]=c1;
154 c1=0;
155 mul_add_c(a[7],b[3],c2,c3,c1);
156 mul_add_c(a[6],b[4],c2,c3,c1);
157 mul_add_c(a[5],b[5],c2,c3,c1);
158 mul_add_c(a[4],b[6],c2,c3,c1);
159 mul_add_c(a[3],b[7],c2,c3,c1);
160 r[10]=c2;
161 c2=0;
162 mul_add_c(a[4],b[7],c3,c1,c2);
163 mul_add_c(a[5],b[6],c3,c1,c2);
164 mul_add_c(a[6],b[5],c3,c1,c2);
165 mul_add_c(a[7],b[4],c3,c1,c2);
166 r[11]=c3;
167 c3=0;
168 mul_add_c(a[7],b[5],c1,c2,c3);
169 mul_add_c(a[6],b[6],c1,c2,c3);
170 mul_add_c(a[5],b[7],c1,c2,c3);
171 r[12]=c1;
172 c1=0;
173 mul_add_c(a[6],b[7],c2,c3,c1);
174 mul_add_c(a[7],b[6],c2,c3,c1);
175 r[13]=c2;
176 c2=0;
177 mul_add_c(a[7],b[7],c3,c1,c2);
178 r[14]=c3;
179 r[15]=c1;
180 }
181
182void bn_mul_comba44(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
183 {
184#ifdef BN_LLONG
185 BN_ULLONG t;
186#else
187 BN_ULONG bl,bh;
188#endif
189 BN_ULONG t1,t2;
190 BN_ULONG c1,c2,c3;
191
192 c1=0;
193 c2=0;
194 c3=0;
195 mul_add_c(a[0],b[0],c1,c2,c3);
196 r[0]=c1;
197 c1=0;
198 mul_add_c(a[0],b[1],c2,c3,c1);
199 mul_add_c(a[1],b[0],c2,c3,c1);
200 r[1]=c2;
201 c2=0;
202 mul_add_c(a[2],b[0],c3,c1,c2);
203 mul_add_c(a[1],b[1],c3,c1,c2);
204 mul_add_c(a[0],b[2],c3,c1,c2);
205 r[2]=c3;
206 c3=0;
207 mul_add_c(a[0],b[3],c1,c2,c3);
208 mul_add_c(a[1],b[2],c1,c2,c3);
209 mul_add_c(a[2],b[1],c1,c2,c3);
210 mul_add_c(a[3],b[0],c1,c2,c3);
211 r[3]=c1;
212 c1=0;
213 mul_add_c(a[3],b[1],c2,c3,c1);
214 mul_add_c(a[2],b[2],c2,c3,c1);
215 mul_add_c(a[1],b[3],c2,c3,c1);
216 r[4]=c2;
217 c2=0;
218 mul_add_c(a[2],b[3],c3,c1,c2);
219 mul_add_c(a[3],b[2],c3,c1,c2);
220 r[5]=c3;
221 c3=0;
222 mul_add_c(a[3],b[3],c1,c2,c3);
223 r[6]=c1;
224 r[7]=c2;
225 }
226
227void bn_sqr_comba88(BN_ULONG *r, BN_ULONG *a)
228 {
229#ifdef BN_LLONG
230 BN_ULLONG t,tt;
231#else
232 BN_ULONG bl,bh;
233#endif
234 BN_ULONG t1,t2;
235 BN_ULONG c1,c2,c3;
236
237 c1=0;
238 c2=0;
239 c3=0;
240 sqr_add_c(a,0,c1,c2,c3);
241 r[0]=c1;
242 c1=0;
243 sqr_add_c2(a,1,0,c2,c3,c1);
244 r[1]=c2;
245 c2=0;
246 sqr_add_c(a,1,c3,c1,c2);
247 sqr_add_c2(a,2,0,c3,c1,c2);
248 r[2]=c3;
249 c3=0;
250 sqr_add_c2(a,3,0,c1,c2,c3);
251 sqr_add_c2(a,2,1,c1,c2,c3);
252 r[3]=c1;
253 c1=0;
254 sqr_add_c(a,2,c2,c3,c1);
255 sqr_add_c2(a,3,1,c2,c3,c1);
256 sqr_add_c2(a,4,0,c2,c3,c1);
257 r[4]=c2;
258 c2=0;
259 sqr_add_c2(a,5,0,c3,c1,c2);
260 sqr_add_c2(a,4,1,c3,c1,c2);
261 sqr_add_c2(a,3,2,c3,c1,c2);
262 r[5]=c3;
263 c3=0;
264 sqr_add_c(a,3,c1,c2,c3);
265 sqr_add_c2(a,4,2,c1,c2,c3);
266 sqr_add_c2(a,5,1,c1,c2,c3);
267 sqr_add_c2(a,6,0,c1,c2,c3);
268 r[6]=c1;
269 c1=0;
270 sqr_add_c2(a,7,0,c2,c3,c1);
271 sqr_add_c2(a,6,1,c2,c3,c1);
272 sqr_add_c2(a,5,2,c2,c3,c1);
273 sqr_add_c2(a,4,3,c2,c3,c1);
274 r[7]=c2;
275 c2=0;
276 sqr_add_c(a,4,c3,c1,c2);
277 sqr_add_c2(a,5,3,c3,c1,c2);
278 sqr_add_c2(a,6,2,c3,c1,c2);
279 sqr_add_c2(a,7,1,c3,c1,c2);
280 r[8]=c3;
281 c3=0;
282 sqr_add_c2(a,7,2,c1,c2,c3);
283 sqr_add_c2(a,6,3,c1,c2,c3);
284 sqr_add_c2(a,5,4,c1,c2,c3);
285 r[9]=c1;
286 c1=0;
287 sqr_add_c(a,5,c2,c3,c1);
288 sqr_add_c2(a,6,4,c2,c3,c1);
289 sqr_add_c2(a,7,3,c2,c3,c1);
290 r[10]=c2;
291 c2=0;
292 sqr_add_c2(a,7,4,c3,c1,c2);
293 sqr_add_c2(a,6,5,c3,c1,c2);
294 r[11]=c3;
295 c3=0;
296 sqr_add_c(a,6,c1,c2,c3);
297 sqr_add_c2(a,7,5,c1,c2,c3);
298 r[12]=c1;
299 c1=0;
300 sqr_add_c2(a,7,6,c2,c3,c1);
301 r[13]=c2;
302 c2=0;
303 sqr_add_c(a,7,c3,c1,c2);
304 r[14]=c3;
305 r[15]=c1;
306 }
307
308void bn_sqr_comba44(BN_ULONG *r, BN_ULONG *a)
309 {
310#ifdef BN_LLONG
311 BN_ULLONG t,tt;
312#else
313 BN_ULONG bl,bh;
314#endif
315 BN_ULONG t1,t2;
316 BN_ULONG c1,c2,c3;
317
318 c1=0;
319 c2=0;
320 c3=0;
321 sqr_add_c(a,0,c1,c2,c3);
322 r[0]=c1;
323 c1=0;
324 sqr_add_c2(a,1,0,c2,c3,c1);
325 r[1]=c2;
326 c2=0;
327 sqr_add_c(a,1,c3,c1,c2);
328 sqr_add_c2(a,2,0,c3,c1,c2);
329 r[2]=c3;
330 c3=0;
331 sqr_add_c2(a,3,0,c1,c2,c3);
332 sqr_add_c2(a,2,1,c1,c2,c3);
333 r[3]=c1;
334 c1=0;
335 sqr_add_c(a,2,c2,c3,c1);
336 sqr_add_c2(a,3,1,c2,c3,c1);
337 r[4]=c2;
338 c2=0;
339 sqr_add_c2(a,3,2,c3,c1,c2);
340 r[5]=c3;
341 c3=0;
342 sqr_add_c(a,3,c1,c2,c3);
343 r[6]=c1;
344 r[7]=c2;
345 }
diff --git a/src/lib/libcrypto/bn/bn_ctx.c b/src/lib/libcrypto/bn/bn_ctx.c
new file mode 100644
index 0000000000..46132fd180
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_ctx.c
@@ -0,0 +1,144 @@
1/* crypto/bn/bn_ctx.c */
2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ====================================================================
4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@openssl.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#ifndef BN_CTX_DEBUG
58# undef NDEBUG /* avoid conflicting definitions */
59# define NDEBUG
60#endif
61
62#include <stdio.h>
63#include <assert.h>
64#include "cryptlib.h"
65#include <openssl/bn.h>
66
67
68BN_CTX *BN_CTX_new(void)
69 {
70 BN_CTX *ret;
71
72 ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
73 if (ret == NULL)
74 {
75 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
76 return(NULL);
77 }
78
79 BN_CTX_init(ret);
80 ret->flags=BN_FLG_MALLOCED;
81 return(ret);
82 }
83
84void BN_CTX_init(BN_CTX *ctx)
85 {
86 int i;
87 ctx->tos = 0;
88 ctx->flags = 0;
89 ctx->depth = 0;
90 ctx->too_many = 0;
91 for (i = 0; i < BN_CTX_NUM; i++)
92 BN_init(&(ctx->bn[i]));
93 }
94
95void BN_CTX_free(BN_CTX *ctx)
96 {
97 int i;
98
99 if (ctx == NULL) return;
100 assert(ctx->depth == 0);
101
102 for (i=0; i < BN_CTX_NUM; i++)
103 BN_clear_free(&(ctx->bn[i]));
104 if (ctx->flags & BN_FLG_MALLOCED)
105 Free(ctx);
106 }
107
108void BN_CTX_start(BN_CTX *ctx)
109 {
110 if (ctx->depth < BN_CTX_NUM_POS)
111 ctx->pos[ctx->depth] = ctx->tos;
112 ctx->depth++;
113 }
114
115BIGNUM *BN_CTX_get(BN_CTX *ctx)
116 {
117 if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
118 {
119 if (!ctx->too_many)
120 {
121 BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
122 /* disable error code until BN_CTX_end is called: */
123 ctx->too_many = 1;
124 }
125 return NULL;
126 }
127 return (&(ctx->bn[ctx->tos++]));
128 }
129
130void BN_CTX_end(BN_CTX *ctx)
131 {
132 if (ctx == NULL) return;
133 assert(ctx->depth > 0);
134 if (ctx->depth == 0)
135 /* should never happen, but we can tolerate it if not in
136 * debug mode (could be a 'goto err' in the calling function
137 * before BN_CTX_start was reached) */
138 BN_CTX_start(ctx);
139
140 ctx->too_many = 0;
141 ctx->depth--;
142 if (ctx->depth < BN_CTX_NUM_POS)
143 ctx->tos = ctx->pos[ctx->depth];
144 }
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
index 150dd289a5..07af1d3b44 100644
--- a/src/lib/libcrypto/bn/bn_div.c
+++ b/src/lib/libcrypto/bn/bn_div.c
@@ -63,9 +63,11 @@
63 63
64/* The old slow way */ 64/* The old slow way */
65#if 0 65#if 0
66int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx) 66int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
67 BN_CTX *ctx)
67 { 68 {
68 int i,nm,nd; 69 int i,nm,nd;
70 int ret = 0;
69 BIGNUM *D; 71 BIGNUM *D;
70 72
71 bn_check_top(m); 73 bn_check_top(m);
@@ -84,14 +86,17 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)
84 return(1); 86 return(1);
85 } 87 }
86 88
87 D= &(ctx->bn[ctx->tos]); 89 BN_CTX_start(ctx);
88 if (dv == NULL) dv= &(ctx->bn[ctx->tos+1]); 90 D = BN_CTX_get(ctx);
89 if (rem == NULL) rem= &(ctx->bn[ctx->tos+2]); 91 if (dv == NULL) dv = BN_CTX_get(ctx);
92 if (rem == NULL) rem = BN_CTX_get(ctx);
93 if (D == NULL || dv == NULL || rem == NULL)
94 goto end;
90 95
91 nd=BN_num_bits(d); 96 nd=BN_num_bits(d);
92 nm=BN_num_bits(m); 97 nm=BN_num_bits(m);
93 if (BN_copy(D,d) == NULL) return(0); 98 if (BN_copy(D,d) == NULL) goto end;
94 if (BN_copy(rem,m) == NULL) return(0); 99 if (BN_copy(rem,m) == NULL) goto end;
95 100
96 /* The next 2 are needed so we can do a dv->d[0]|=1 later 101 /* The next 2 are needed so we can do a dv->d[0]|=1 later
97 * since BN_lshift1 will only work once there is a value :-) */ 102 * since BN_lshift1 will only work once there is a value :-) */
@@ -99,25 +104,54 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)
99 bn_wexpand(dv,1); 104 bn_wexpand(dv,1);
100 dv->top=1; 105 dv->top=1;
101 106
102 if (!BN_lshift(D,D,nm-nd)) return(0); 107 if (!BN_lshift(D,D,nm-nd)) goto end;
103 for (i=nm-nd; i>=0; i--) 108 for (i=nm-nd; i>=0; i--)
104 { 109 {
105 if (!BN_lshift1(dv,dv)) return(0); 110 if (!BN_lshift1(dv,dv)) goto end;
106 if (BN_ucmp(rem,D) >= 0) 111 if (BN_ucmp(rem,D) >= 0)
107 { 112 {
108 dv->d[0]|=1; 113 dv->d[0]|=1;
109 if (!BN_usub(rem,rem,D)) return(0); 114 if (!BN_usub(rem,rem,D)) goto end;
110 } 115 }
111/* CAN IMPROVE (and have now :=) */ 116/* CAN IMPROVE (and have now :=) */
112 if (!BN_rshift1(D,D)) return(0); 117 if (!BN_rshift1(D,D)) goto end;
113 } 118 }
114 rem->neg=BN_is_zero(rem)?0:m->neg; 119 rem->neg=BN_is_zero(rem)?0:m->neg;
115 dv->neg=m->neg^d->neg; 120 dv->neg=m->neg^d->neg;
116 return(1); 121 ret = 1;
122 end:
123 BN_CTX_end(ctx);
124 return(ret);
117 } 125 }
118 126
119#else 127#else
120 128
129#if !defined(NO_ASM) && !defined(NO_INLINE_ASM) && !defined(PEDANTIC) && !defined(BN_DIV3W)
130# if defined(__GNUC__) && __GNUC__>=2
131# if defined(__i386)
132 /*
133 * There were two reasons for implementing this template:
134 * - GNU C generates a call to a function (__udivdi3 to be exact)
135 * in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to
136 * understand why...);
137 * - divl doesn't only calculate quotient, but also leaves
138 * remainder in %edx which we can definitely use here:-)
139 *
140 * <appro@fy.chalmers.se>
141 */
142# define bn_div_words(n0,n1,d0) \
143 ({ asm volatile ( \
144 "divl %4" \
145 : "=a"(q), "=d"(rem) \
146 : "a"(n1), "d"(n0), "g"(d0) \
147 : "cc"); \
148 q; \
149 })
150# define REMAINDER_IS_ALREADY_CALCULATED
151# endif /* __<cpu> */
152# endif /* __GNUC__ */
153#endif /* NO_ASM */
154
121int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, 155int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
122 BN_CTX *ctx) 156 BN_CTX *ctx)
123 { 157 {
@@ -144,13 +178,15 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
144 return(1); 178 return(1);
145 } 179 }
146 180
147 tmp= &(ctx->bn[ctx->tos]); 181 BN_CTX_start(ctx);
182 tmp=BN_CTX_get(ctx);
148 tmp->neg=0; 183 tmp->neg=0;
149 snum= &(ctx->bn[ctx->tos+1]); 184 snum=BN_CTX_get(ctx);
150 sdiv= &(ctx->bn[ctx->tos+2]); 185 sdiv=BN_CTX_get(ctx);
151 if (dv == NULL) 186 if (dv == NULL)
152 res= &(ctx->bn[ctx->tos+3]); 187 res=BN_CTX_get(ctx);
153 else res=dv; 188 else res=dv;
189 if (res == NULL) goto err;
154 190
155 /* First we normalise the numbers */ 191 /* First we normalise the numbers */
156 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2); 192 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
@@ -202,97 +238,76 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
202 { 238 {
203 BN_ULONG q,l0; 239 BN_ULONG q,l0;
204#ifdef BN_DIV3W 240#ifdef BN_DIV3W
205 q=bn_div_3_words(wnump,d0,d1); 241 q=bn_div_3_words(wnump,d1,d0);
206#else 242#else
207
208#if !defined(NO_ASM) && !defined(PEDANTIC)
209# if defined(__GNUC__) && __GNUC__>=2
210# if defined(__i386)
211 /*
212 * There were two reasons for implementing this template:
213 * - GNU C generates a call to a function (__udivdi3 to be exact)
214 * in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to
215 * understand why...);
216 * - divl doesn't only calculate quotient, but also leaves
217 * remainder in %edx which we can definitely use here:-)
218 *
219 * <appro@fy.chalmers.se>
220 */
221# define bn_div_words(n0,n1,d0) \
222 ({ asm volatile ( \
223 "divl %4" \
224 : "=a"(q), "=d"(rem) \
225 : "a"(n1), "d"(n0), "g"(d0) \
226 : "cc"); \
227 q; \
228 })
229# define REMINDER_IS_ALREADY_CALCULATED
230# endif /* __<cpu> */
231# endif /* __GNUC__ */
232#endif /* NO_ASM */
233 BN_ULONG n0,n1,rem=0; 243 BN_ULONG n0,n1,rem=0;
234 244
235 n0=wnump[0]; 245 n0=wnump[0];
236 n1=wnump[-1]; 246 n1=wnump[-1];
237 if (n0 == d0) 247 if (n0 == d0)
238 q=BN_MASK2; 248 q=BN_MASK2;
239 else 249 else /* n0 < d0 */
250 {
251#ifdef BN_LLONG
252 BN_ULLONG t2;
253
240#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words) 254#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
241 q=((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0; 255 q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);
242#else 256#else
243 q=bn_div_words(n0,n1,d0); 257 q=bn_div_words(n0,n1,d0);
244#endif 258#endif
245 { 259
246#ifdef BN_LLONG 260#ifndef REMAINDER_IS_ALREADY_CALCULATED
247 BN_ULLONG t2; 261 /*
248 262 * rem doesn't have to be BN_ULLONG. The least we
249#ifndef REMINDER_IS_ALREADY_CALCULATED 263 * know it's less that d0, isn't it?
250 /* 264 */
251 * rem doesn't have to be BN_ULLONG. The least we 265 rem=(n1-q*d0)&BN_MASK2;
252 * know it's less that d0, isn't it?
253 */
254 rem=(n1-q*d0)&BN_MASK2;
255#endif 266#endif
256 t2=(BN_ULLONG)d1*q; 267 t2=(BN_ULLONG)d1*q;
268
269 for (;;)
270 {
271 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
272 break;
273 q--;
274 rem += d0;
275 if (rem < d0) break; /* don't let rem overflow */
276 t2 -= d1;
277 }
278#else /* !BN_LLONG */
279 BN_ULONG t2l,t2h,ql,qh;
257 280
258 for (;;) 281 q=bn_div_words(n0,n1,d0);
259 { 282#ifndef REMAINDER_IS_ALREADY_CALCULATED
260 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2])) 283 rem=(n1-q*d0)&BN_MASK2;
261 break; 284#endif
262 q--; 285
263 rem += d0; 286#ifdef BN_UMULT_HIGH
264 if (rem < d0) break; /* don't let rem overflow */ 287 t2l = d1 * q;
265 t2 -= d1; 288 t2h = BN_UMULT_HIGH(d1,q);
266 }
267#else 289#else
268 BN_ULONG t2l,t2h,ql,qh; 290 t2l=LBITS(d1); t2h=HBITS(d1);
269 291 ql =LBITS(q); qh =HBITS(q);
270#ifndef REMINDER_IS_ALREADY_CALCULATED 292 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
271 /*
272 * It's more than enough with the only multiplication.
273 * See the comment above in BN_LLONG section...
274 */
275 rem=(n1-q*d0)&BN_MASK2;
276#endif 293#endif
277 t2l=LBITS(d1); t2h=HBITS(d1);
278 ql =LBITS(q); qh =HBITS(q);
279 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
280 294
281 for (;;) 295 for (;;)
282 { 296 {
283 if ((t2h < rem) || 297 if ((t2h < rem) ||
284 ((t2h == rem) && (t2l <= wnump[-2]))) 298 ((t2h == rem) && (t2l <= wnump[-2])))
285 break; 299 break;
286 q--; 300 q--;
287 rem += d0; 301 rem += d0;
288 if (rem < d0) break; /* don't let rem overflow */ 302 if (rem < d0) break; /* don't let rem overflow */
289 if (t2l < d1) t2h--; t2l -= d1; 303 if (t2l < d1) t2h--; t2l -= d1;
304 }
305#endif /* !BN_LLONG */
290 } 306 }
291#endif
292 }
293#endif /* !BN_DIV3W */ 307#endif /* !BN_DIV3W */
294 wnum.d--; wnum.top++; 308
295 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q); 309 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
310 wnum.d--; wnum.top++;
296 tmp->d[div_n]=l0; 311 tmp->d[div_n]=l0;
297 for (j=div_n+1; j>0; j--) 312 for (j=div_n+1; j>0; j--)
298 if (tmp->d[j-1]) break; 313 if (tmp->d[j-1]) break;
@@ -318,8 +333,10 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
318 BN_rshift(rm,snum,norm_shift); 333 BN_rshift(rm,snum,norm_shift);
319 rm->neg=num->neg; 334 rm->neg=num->neg;
320 } 335 }
336 BN_CTX_end(ctx);
321 return(1); 337 return(1);
322err: 338err:
339 BN_CTX_end(ctx);
323 return(0); 340 return(0);
324 } 341 }
325 342
@@ -335,22 +352,27 @@ int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
335 if (BN_ucmp(m,d) < 0) 352 if (BN_ucmp(m,d) < 0)
336 return((BN_copy(rem,m) == NULL)?0:1); 353 return((BN_copy(rem,m) == NULL)?0:1);
337 354
338 dv= &(ctx->bn[ctx->tos]); 355 BN_CTX_start(ctx);
356 dv=BN_CTX_get(ctx);
339 357
340 if (!BN_copy(rem,m)) return(0); 358 if (!BN_copy(rem,m)) goto err;
341 359
342 nm=BN_num_bits(rem); 360 nm=BN_num_bits(rem);
343 nd=BN_num_bits(d); 361 nd=BN_num_bits(d);
344 if (!BN_lshift(dv,d,nm-nd)) return(0); 362 if (!BN_lshift(dv,d,nm-nd)) goto err;
345 for (i=nm-nd; i>=0; i--) 363 for (i=nm-nd; i>=0; i--)
346 { 364 {
347 if (BN_cmp(rem,dv) >= 0) 365 if (BN_cmp(rem,dv) >= 0)
348 { 366 {
349 if (!BN_sub(rem,rem,dv)) return(0); 367 if (!BN_sub(rem,rem,dv)) goto err;
350 } 368 }
351 if (!BN_rshift1(dv,dv)) return(0); 369 if (!BN_rshift1(dv,dv)) goto err;
352 } 370 }
371 BN_CTX_end(ctx);
353 return(1); 372 return(1);
373 err:
374 BN_CTX_end(ctx);
375 return(0);
354#else 376#else
355 return(BN_div(NULL,rem,m,d,ctx)); 377 return(BN_div(NULL,rem,m,d,ctx));
356#endif 378#endif
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c
index 73e80774e5..f3b9497dca 100644
--- a/src/lib/libcrypto/bn/bn_err.c
+++ b/src/lib/libcrypto/bn/bn_err.c
@@ -71,6 +71,7 @@ static ERR_STRING_DATA BN_str_functs[]=
71{ERR_PACK(0,BN_F_BN_BLINDING_UPDATE,0), "BN_BLINDING_update"}, 71{ERR_PACK(0,BN_F_BN_BLINDING_UPDATE,0), "BN_BLINDING_update"},
72{ERR_PACK(0,BN_F_BN_BN2DEC,0), "BN_bn2dec"}, 72{ERR_PACK(0,BN_F_BN_BN2DEC,0), "BN_bn2dec"},
73{ERR_PACK(0,BN_F_BN_BN2HEX,0), "BN_bn2hex"}, 73{ERR_PACK(0,BN_F_BN_BN2HEX,0), "BN_bn2hex"},
74{ERR_PACK(0,BN_F_BN_CTX_GET,0), "BN_CTX_get"},
74{ERR_PACK(0,BN_F_BN_CTX_NEW,0), "BN_CTX_new"}, 75{ERR_PACK(0,BN_F_BN_CTX_NEW,0), "BN_CTX_new"},
75{ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"}, 76{ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"},
76{ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"}, 77{ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"},
@@ -95,6 +96,7 @@ static ERR_STRING_DATA BN_str_reasons[]=
95{BN_R_INVALID_LENGTH ,"invalid length"}, 96{BN_R_INVALID_LENGTH ,"invalid length"},
96{BN_R_NOT_INITIALIZED ,"not initialized"}, 97{BN_R_NOT_INITIALIZED ,"not initialized"},
97{BN_R_NO_INVERSE ,"no inverse"}, 98{BN_R_NO_INVERSE ,"no inverse"},
99{BN_R_TOO_MANY_TEMPORARY_VARIABLES ,"too many temporary variables"},
98{0,NULL} 100{0,NULL}
99 }; 101 };
100 102
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index 2df1614ada..0c11601675 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -59,6 +59,12 @@
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62#ifdef ATALLA
63# include <alloca.h>
64# include <atasi.h>
65# include <assert.h>
66# include <dlfcn.h>
67#endif
62 68
63#define TABLE_SIZE 16 69#define TABLE_SIZE 16
64 70
@@ -72,7 +78,8 @@ int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
72 bn_check_top(b); 78 bn_check_top(b);
73 bn_check_top(m); 79 bn_check_top(m);
74 80
75 t= &(ctx->bn[ctx->tos++]); 81 BN_CTX_start(ctx);
82 if ((t = BN_CTX_get(ctx)) == NULL) goto err;
76 if (a == b) 83 if (a == b)
77 { if (!BN_sqr(t,a,ctx)) goto err; } 84 { if (!BN_sqr(t,a,ctx)) goto err; }
78 else 85 else
@@ -80,7 +87,7 @@ int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
80 if (!BN_mod(ret,t,m,ctx)) goto err; 87 if (!BN_mod(ret,t,m,ctx)) goto err;
81 r=1; 88 r=1;
82err: 89err:
83 ctx->tos--; 90 BN_CTX_end(ctx);
84 return(r); 91 return(r);
85 } 92 }
86 93
@@ -91,8 +98,10 @@ int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)
91 int i,bits,ret=0; 98 int i,bits,ret=0;
92 BIGNUM *v,*tmp; 99 BIGNUM *v,*tmp;
93 100
94 v= &(ctx->bn[ctx->tos++]); 101 BN_CTX_start(ctx);
95 tmp= &(ctx->bn[ctx->tos++]); 102 v = BN_CTX_get(ctx);
103 tmp = BN_CTX_get(ctx);
104 if (v == NULL || tmp == NULL) goto err;
96 105
97 if (BN_copy(v,a) == NULL) goto err; 106 if (BN_copy(v,a) == NULL) goto err;
98 bits=BN_num_bits(p); 107 bits=BN_num_bits(p);
@@ -113,7 +122,7 @@ int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)
113 } 122 }
114 ret=1; 123 ret=1;
115err: 124err:
116 ctx->tos-=2; 125 BN_CTX_end(ctx);
117 return(ret); 126 return(ret);
118 } 127 }
119 128
@@ -122,15 +131,15 @@ err:
122/* this one works - simple but works */ 131/* this one works - simple but works */
123int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx) 132int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx)
124 { 133 {
125 int i,bits,ret=0,tos; 134 int i,bits,ret=0;
126 BIGNUM *v,*rr; 135 BIGNUM *v,*rr;
127 136
128 tos=ctx->tos; 137 BN_CTX_start(ctx);
129 v= &(ctx->bn[ctx->tos++]);
130 if ((r == a) || (r == p)) 138 if ((r == a) || (r == p))
131 rr= &(ctx->bn[ctx->tos++]); 139 rr = BN_CTX_get(ctx);
132 else 140 else
133 rr=r; 141 rr = r;
142 if ((v = BN_CTX_get(ctx)) == NULL) goto err;
134 143
135 if (BN_copy(v,a) == NULL) goto err; 144 if (BN_copy(v,a) == NULL) goto err;
136 bits=BN_num_bits(p); 145 bits=BN_num_bits(p);
@@ -149,11 +158,178 @@ int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx)
149 } 158 }
150 ret=1; 159 ret=1;
151err: 160err:
152 ctx->tos=tos;
153 if (r != rr) BN_copy(r,rr); 161 if (r != rr) BN_copy(r,rr);
162 BN_CTX_end(ctx);
154 return(ret); 163 return(ret);
155 } 164 }
156 165
166#ifdef ATALLA
167
168/*
169 * This routine will dynamically check for the existance of an Atalla AXL-200
170 * SSL accelerator module. If one is found, the variable
171 * asi_accelerator_present is set to 1 and the function pointers
172 * ptr_ASI_xxxxxx above will be initialized to corresponding ASI API calls.
173 */
174typedef int tfnASI_GetPerformanceStatistics(int reset_flag,
175 unsigned int *ret_buf);
176typedef int tfnASI_GetHardwareConfig(long card_num, unsigned int *ret_buf);
177typedef int tfnASI_RSAPrivateKeyOpFn(RSAPrivateKey * rsaKey,
178 unsigned char *output,
179 unsigned char *input,
180 unsigned int modulus_len);
181
182static tfnASI_GetHardwareConfig *ptr_ASI_GetHardwareConfig;
183static tfnASI_RSAPrivateKeyOpFn *ptr_ASI_RSAPrivateKeyOpFn;
184static tfnASI_GetPerformanceStatistics *ptr_ASI_GetPerformanceStatistics;
185static int asi_accelerator_present;
186static int tried_atalla;
187
188void atalla_initialize_accelerator_handle(void)
189 {
190 void *dl_handle;
191 int status;
192 unsigned int config_buf[1024];
193 static int tested;
194
195 if(tested)
196 return;
197
198 tested=1;
199
200 bzero((void *)config_buf, 1024);
201
202 /*
203 * Check to see if the library is present on the system
204 */
205 dl_handle = dlopen("atasi.so", RTLD_NOW);
206 if (dl_handle == (void *) NULL)
207 {
208/* printf("atasi.so library is not present on the system\n");
209 printf("No HW acceleration available\n");*/
210 return;
211 }
212
213 /*
214 * The library is present. Now we'll check to insure that the
215 * LDM is up and running. First we'll get the address of the
216 * function in the atasi library that we need to see if the
217 * LDM is operating.
218 */
219
220 ptr_ASI_GetHardwareConfig =
221 (tfnASI_GetHardwareConfig *)dlsym(dl_handle,"ASI_GetHardwareConfig");
222
223 if (ptr_ASI_GetHardwareConfig)
224 {
225 /*
226 * We found the call, now we'll get our config
227 * status. If we get a non 0 result, the LDM is not
228 * running and we cannot use the Atalla ASI *
229 * library.
230 */
231 status = (*ptr_ASI_GetHardwareConfig)(0L, config_buf);
232 if (status != 0)
233 {
234 printf("atasi.so library is present but not initialized\n");
235 printf("No HW acceleration available\n");
236 return;
237 }
238 }
239 else
240 {
241/* printf("We found the library, but not the function. Very Strange!\n");*/
242 return ;
243 }
244
245 /*
246 * It looks like we have acceleration capabilities. Load up the
247 * pointers to our ASI API calls.
248 */
249 ptr_ASI_RSAPrivateKeyOpFn=
250 (tfnASI_RSAPrivateKeyOpFn *)dlsym(dl_handle, "ASI_RSAPrivateKeyOpFn");
251 if (ptr_ASI_RSAPrivateKeyOpFn == NULL)
252 {
253/* printf("We found the library, but no RSA function. Very Strange!\n");*/
254 return;
255 }
256
257 ptr_ASI_GetPerformanceStatistics =
258 (tfnASI_GetPerformanceStatistics *)dlsym(dl_handle, "ASI_GetPerformanceStatistics");
259 if (ptr_ASI_GetPerformanceStatistics == NULL)
260 {
261/* printf("We found the library, but no stat function. Very Strange!\n");*/
262 return;
263 }
264
265 /*
266 * Indicate that acceleration is available
267 */
268 asi_accelerator_present = 1;
269
270/* printf("This system has acceleration!\n");*/
271
272 return;
273 }
274
275/* make sure this only gets called once when bn_mod_exp calls bn_mod_exp_mont */
276int BN_mod_exp_atalla(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m)
277 {
278 unsigned char *abin;
279 unsigned char *pbin;
280 unsigned char *mbin;
281 unsigned char *rbin;
282 int an,pn,mn,ret;
283 RSAPrivateKey keydata;
284
285 atalla_initialize_accelerator_handle();
286 if(!asi_accelerator_present)
287 return 0;
288
289
290/* We should be able to run without size testing */
291# define ASIZE 128
292 an=BN_num_bytes(a);
293 pn=BN_num_bytes(p);
294 mn=BN_num_bytes(m);
295
296 if(an <= ASIZE && pn <= ASIZE && mn <= ASIZE)
297 {
298 int size=mn;
299
300 assert(an <= mn);
301 abin=alloca(size);
302 memset(abin,'\0',mn);
303 BN_bn2bin(a,abin+size-an);
304
305 pbin=alloca(pn);
306 BN_bn2bin(p,pbin);
307
308 mbin=alloca(size);
309 memset(mbin,'\0',mn);
310 BN_bn2bin(m,mbin+size-mn);
311
312 rbin=alloca(size);
313
314 memset(&keydata,'\0',sizeof keydata);
315 keydata.privateExponent.data=pbin;
316 keydata.privateExponent.len=pn;
317 keydata.modulus.data=mbin;
318 keydata.modulus.len=size;
319
320 ret=(*ptr_ASI_RSAPrivateKeyOpFn)(&keydata,rbin,abin,keydata.modulus.len);
321/*fprintf(stderr,"!%s\n",BN_bn2hex(a));*/
322 if(!ret)
323 {
324 BN_bin2bn(rbin,keydata.modulus.len,r);
325/*fprintf(stderr,"?%s\n",BN_bn2hex(r));*/
326 return 1;
327 }
328 }
329 return 0;
330 }
331#endif /* def ATALLA */
332
157int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m, 333int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
158 BN_CTX *ctx) 334 BN_CTX *ctx)
159 { 335 {
@@ -163,6 +339,13 @@ int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
163 bn_check_top(p); 339 bn_check_top(p);
164 bn_check_top(m); 340 bn_check_top(m);
165 341
342#ifdef ATALLA
343 if(BN_mod_exp_atalla(r,a,p,m))
344 return 1;
345/* If it fails, try the other methods (but don't try atalla again) */
346 tried_atalla=1;
347#endif
348
166#ifdef MONT_MUL_MOD 349#ifdef MONT_MUL_MOD
167 /* I have finally been able to take out this pre-condition of 350 /* I have finally been able to take out this pre-condition of
168 * the top bit being set. It was caused by an error in BN_div 351 * the top bit being set. It was caused by an error in BN_div
@@ -180,6 +363,10 @@ int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
180 { ret=BN_mod_exp_simple(r,a,p,m,ctx); } 363 { ret=BN_mod_exp_simple(r,a,p,m,ctx); }
181#endif 364#endif
182 365
366#ifdef ATALLA
367 tried_atalla=0;
368#endif
369
183 return(ret); 370 return(ret);
184 } 371 }
185 372
@@ -193,7 +380,6 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
193 BIGNUM val[TABLE_SIZE]; 380 BIGNUM val[TABLE_SIZE];
194 BN_RECP_CTX recp; 381 BN_RECP_CTX recp;
195 382
196 aa= &(ctx->bn[ctx->tos++]);
197 bits=BN_num_bits(p); 383 bits=BN_num_bits(p);
198 384
199 if (bits == 0) 385 if (bits == 0)
@@ -201,6 +387,10 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
201 BN_one(r); 387 BN_one(r);
202 return(1); 388 return(1);
203 } 389 }
390
391 BN_CTX_start(ctx);
392 if ((aa = BN_CTX_get(ctx)) == NULL) goto err;
393
204 BN_RECP_CTX_init(&recp); 394 BN_RECP_CTX_init(&recp);
205 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err; 395 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;
206 396
@@ -289,7 +479,7 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
289 } 479 }
290 ret=1; 480 ret=1;
291err: 481err:
292 ctx->tos--; 482 BN_CTX_end(ctx);
293 for (i=0; i<ts; i++) 483 for (i=0; i<ts; i++)
294 BN_clear_free(&(val[i])); 484 BN_clear_free(&(val[i]));
295 BN_RECP_CTX_free(&recp); 485 BN_RECP_CTX_free(&recp);
@@ -312,19 +502,27 @@ int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, const BIGNUM *p,
312 bn_check_top(p); 502 bn_check_top(p);
313 bn_check_top(m); 503 bn_check_top(m);
314 504
505#ifdef ATALLA
506 if(!tried_atalla && BN_mod_exp_atalla(rr,a,p,m))
507 return 1;
508/* If it fails, try the other methods */
509#endif
510
315 if (!(m->d[0] & 1)) 511 if (!(m->d[0] & 1))
316 { 512 {
317 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); 513 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
318 return(0); 514 return(0);
319 } 515 }
320 d= &(ctx->bn[ctx->tos++]);
321 r= &(ctx->bn[ctx->tos++]);
322 bits=BN_num_bits(p); 516 bits=BN_num_bits(p);
323 if (bits == 0) 517 if (bits == 0)
324 { 518 {
325 BN_one(r); 519 BN_one(rr);
326 return(1); 520 return(1);
327 } 521 }
522 BN_CTX_start(ctx);
523 d = BN_CTX_get(ctx);
524 r = BN_CTX_get(ctx);
525 if (d == NULL || r == NULL) goto err;
328 526
329 /* If this is not done, things will break in the montgomery 527 /* If this is not done, things will break in the montgomery
330 * part */ 528 * part */
@@ -432,7 +630,7 @@ int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, const BIGNUM *p,
432 ret=1; 630 ret=1;
433err: 631err:
434 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); 632 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
435 ctx->tos-=2; 633 BN_CTX_end(ctx);
436 for (i=0; i<ts; i++) 634 for (i=0; i<ts; i++)
437 BN_clear_free(&(val[i])); 635 BN_clear_free(&(val[i]));
438 return(ret); 636 return(ret);
@@ -448,7 +646,6 @@ int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,
448 BIGNUM *d; 646 BIGNUM *d;
449 BIGNUM val[TABLE_SIZE]; 647 BIGNUM val[TABLE_SIZE];
450 648
451 d= &(ctx->bn[ctx->tos++]);
452 bits=BN_num_bits(p); 649 bits=BN_num_bits(p);
453 650
454 if (bits == 0) 651 if (bits == 0)
@@ -457,6 +654,9 @@ int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,
457 return(1); 654 return(1);
458 } 655 }
459 656
657 BN_CTX_start(ctx);
658 if ((d = BN_CTX_get(ctx)) == NULL) goto err;
659
460 BN_init(&(val[0])); 660 BN_init(&(val[0]));
461 ts=1; 661 ts=1;
462 if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */ 662 if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */
@@ -541,7 +741,7 @@ int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,
541 } 741 }
542 ret=1; 742 ret=1;
543err: 743err:
544 ctx->tos--; 744 BN_CTX_end(ctx);
545 for (i=0; i<ts; i++) 745 for (i=0; i<ts; i++)
546 BN_clear_free(&(val[i])); 746 BN_clear_free(&(val[i]));
547 return(ret); 747 return(ret);
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c
index 1132d53365..4f4e9e3299 100644
--- a/src/lib/libcrypto/bn/bn_exp2.c
+++ b/src/lib/libcrypto/bn/bn_exp2.c
@@ -9,7 +9,7 @@
9 * bits=1 75.4% 79.4% 9 * bits=1 75.4% 79.4%
10 * bits=2 61.2% 62.4% 10 * bits=2 61.2% 62.4%
11 * bits=3 61.3% 59.3% 11 * bits=3 61.3% 59.3%
12 * The lack of speed improvment is also a function of the pre-calculation 12 * The lack of speed improvement is also a function of the pre-calculation
13 * which could be removed. 13 * which could be removed.
14 */ 14 */
15#define EXP2_TABLE_BITS 2 /* 1 2 3 4 5 */ 15#define EXP2_TABLE_BITS 2 /* 1 2 3 4 5 */
@@ -35,15 +35,19 @@ int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,
35 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); 35 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
36 return(0); 36 return(0);
37 } 37 }
38 d= &(ctx->bn[ctx->tos++]);
39 r= &(ctx->bn[ctx->tos++]);
40 bits1=BN_num_bits(p1); 38 bits1=BN_num_bits(p1);
41 bits2=BN_num_bits(p2); 39 bits2=BN_num_bits(p2);
42 if ((bits1 == 0) && (bits2 == 0)) 40 if ((bits1 == 0) && (bits2 == 0))
43 { 41 {
44 BN_one(r); 42 BN_one(rr);
45 return(1); 43 return(1);
46 } 44 }
45
46 BN_CTX_start(ctx);
47 d = BN_CTX_get(ctx);
48 r = BN_CTX_get(ctx);
49 if (d == NULL || r == NULL) goto err;
50
47 bits=(bits1 > bits2)?bits1:bits2; 51 bits=(bits1 > bits2)?bits1:bits2;
48 52
49 /* If this is not done, things will break in the montgomery 53 /* If this is not done, things will break in the montgomery
@@ -183,7 +187,7 @@ int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,
183 ret=1; 187 ret=1;
184err: 188err:
185 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); 189 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
186 ctx->tos-=2; 190 BN_CTX_end(ctx);
187 for (i=0; i<ts; i++) 191 for (i=0; i<ts; i++)
188 { 192 {
189 for (j=0; j<ts; j++) 193 for (j=0; j<ts; j++)
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c
index 64a76f4498..398207196b 100644
--- a/src/lib/libcrypto/bn/bn_gcd.c
+++ b/src/lib/libcrypto/bn/bn_gcd.c
@@ -61,6 +61,7 @@
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63static BIGNUM *euclid(BIGNUM *a, BIGNUM *b); 63static BIGNUM *euclid(BIGNUM *a, BIGNUM *b);
64
64int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx) 65int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx)
65 { 66 {
66 BIGNUM *a,*b,*t; 67 BIGNUM *a,*b,*t;
@@ -69,8 +70,10 @@ int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx)
69 bn_check_top(in_a); 70 bn_check_top(in_a);
70 bn_check_top(in_b); 71 bn_check_top(in_b);
71 72
72 a= &(ctx->bn[ctx->tos]); 73 BN_CTX_start(ctx);
73 b= &(ctx->bn[ctx->tos+1]); 74 a = BN_CTX_get(ctx);
75 b = BN_CTX_get(ctx);
76 if (a == NULL || b == NULL) goto err;
74 77
75 if (BN_copy(a,in_a) == NULL) goto err; 78 if (BN_copy(a,in_a) == NULL) goto err;
76 if (BN_copy(b,in_b) == NULL) goto err; 79 if (BN_copy(b,in_b) == NULL) goto err;
@@ -82,6 +85,7 @@ int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx)
82 if (BN_copy(r,t) == NULL) goto err; 85 if (BN_copy(r,t) == NULL) goto err;
83 ret=1; 86 ret=1;
84err: 87err:
88 BN_CTX_end(ctx);
85 return(ret); 89 return(ret);
86 } 90 }
87 91
@@ -142,20 +146,22 @@ err:
142/* solves ax == 1 (mod n) */ 146/* solves ax == 1 (mod n) */
143BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) 147BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
144 { 148 {
145 BIGNUM *A,*B,*X,*Y,*M,*D,*R; 149 BIGNUM *A,*B,*X,*Y,*M,*D,*R=NULL;
146 BIGNUM *T,*ret=NULL; 150 BIGNUM *T,*ret=NULL;
147 int sign; 151 int sign;
148 152
149 bn_check_top(a); 153 bn_check_top(a);
150 bn_check_top(n); 154 bn_check_top(n);
151 155
152 A= &(ctx->bn[ctx->tos]); 156 BN_CTX_start(ctx);
153 B= &(ctx->bn[ctx->tos+1]); 157 A = BN_CTX_get(ctx);
154 X= &(ctx->bn[ctx->tos+2]); 158 B = BN_CTX_get(ctx);
155 D= &(ctx->bn[ctx->tos+3]); 159 X = BN_CTX_get(ctx);
156 M= &(ctx->bn[ctx->tos+4]); 160 D = BN_CTX_get(ctx);
157 Y= &(ctx->bn[ctx->tos+5]); 161 M = BN_CTX_get(ctx);
158 ctx->tos+=6; 162 Y = BN_CTX_get(ctx);
163 if (Y == NULL) goto err;
164
159 if (in == NULL) 165 if (in == NULL)
160 R=BN_new(); 166 R=BN_new();
161 else 167 else
@@ -198,7 +204,7 @@ BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
198 ret=R; 204 ret=R;
199err: 205err:
200 if ((ret == NULL) && (in == NULL)) BN_free(R); 206 if ((ret == NULL) && (in == NULL)) BN_free(R);
201 ctx->tos-=6; 207 BN_CTX_end(ctx);
202 return(ret); 208 return(ret);
203 } 209 }
204 210
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h
index 85a372695b..e36ccbc4c2 100644
--- a/src/lib/libcrypto/bn/bn_lcl.h
+++ b/src/lib/libcrypto/bn/bn_lcl.h
@@ -73,18 +73,53 @@ extern "C" {
73#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */ 73#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */
74#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */ 74#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */
75 75
76#if 0 76#if !defined(NO_ASM) && !defined(NO_INLINE_ASM) && !defined(PEDANTIC)
77#ifndef BN_MUL_COMBA 77/*
78/* #define bn_mul_comba8(r,a,b) bn_mul_normal(r,a,8,b,8) */ 78 * BN_UMULT_HIGH section.
79/* #define bn_mul_comba4(r,a,b) bn_mul_normal(r,a,4,b,4) */ 79 *
80#endif 80 * No, I'm not trying to overwhelm you when stating that the
81 81 * product of N-bit numbers is 2*N bits wide:-) No, I don't expect
82#ifndef BN_SQR_COMBA 82 * you to be impressed when I say that if the compiler doesn't
83/* This is probably faster than using the C code - I need to check */ 83 * support 2*N integer type, then you have to replace every N*N
84#define bn_sqr_comba8(r,a) bn_mul_normal(r,a,8,a,8) 84 * multiplication with 4 (N/2)*(N/2) accompanied by some shifts
85#define bn_sqr_comba4(r,a) bn_mul_normal(r,a,4,a,4) 85 * and additions which unavoidably results in severe performance
86#endif 86 * penalties. Of course provided that the hardware is capable of
87#endif 87 * producing 2*N result... That's when you normally start
88 * considering assembler implementation. However! It should be
89 * pointed out that some CPUs (most notably Alpha, PowerPC and
90 * upcoming IA-64 family:-) provide *separate* instruction
91 * calculating the upper half of the product placing the result
92 * into a general purpose register. Now *if* the compiler supports
93 * inline assembler, then it's not impossible to implement the
94 * "bignum" routines (and have the compiler optimize 'em)
95 * exhibiting "native" performance in C. That's what BN_UMULT_HIGH
96 * macro is about:-)
97 *
98 * <appro@fy.chalmers.se>
99 */
100# if defined(__alpha) && (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT))
101# if defined(__DECC)
102# include <c_asm.h>
103# define BN_UMULT_HIGH(a,b) (BN_ULONG)asm("umulh %a0,%a1,%v0",(a),(b))
104# elif defined(__GNUC__)
105# define BN_UMULT_HIGH(a,b) ({ \
106 register BN_ULONG ret; \
107 asm ("umulh %1,%2,%0" \
108 : "=r"(ret) \
109 : "r"(a), "r"(b)); \
110 ret; })
111# endif /* compiler */
112# elif defined(_ARCH_PPC) && defined(__64BIT__) && defined(SIXTY_FOUR_BIT_LONG)
113# if defined(__GNUC__)
114# define BN_UMULT_HIGH(a,b) ({ \
115 register BN_ULONG ret; \
116 asm ("mulhdu %0,%1,%2" \
117 : "=r"(ret) \
118 : "r"(a), "r"(b)); \
119 ret; })
120# endif /* compiler */
121# endif /* cpu */
122#endif /* NO_ASM */
88 123
89/************************************************************* 124/*************************************************************
90 * Using the long long type 125 * Using the long long type
@@ -92,15 +127,12 @@ extern "C" {
92#define Lw(t) (((BN_ULONG)(t))&BN_MASK2) 127#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
93#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) 128#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
94 129
95/* These are used for internal error checking and are not normally used */ 130/* This is used for internal error checking and is not normally used */
96#ifdef BN_DEBUG 131#ifdef BN_DEBUG
97#define bn_check_top(a) \ 132# include <assert.h>
98 { if (((a)->top < 0) || ((a)->top > (a)->max)) \ 133# define bn_check_top(a) assert ((a)->top >= 0 && (a)->top <= (a)->max);
99 { char *nullp=NULL; *nullp='z'; } }
100#define bn_check_num(a) if ((a) < 0) { char *nullp=NULL; *nullp='z'; }
101#else 134#else
102#define bn_check_top(a) 135# define bn_check_top(a)
103#define bn_check_num(a)
104#endif 136#endif
105 137
106/* This macro is to add extra stuff for development checking */ 138/* This macro is to add extra stuff for development checking */
@@ -134,8 +166,6 @@ extern "C" {
134 bn_set_max(r); \ 166 bn_set_max(r); \
135 } 167 }
136 168
137/* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */
138
139#ifdef BN_LLONG 169#ifdef BN_LLONG
140#define mul_add(r,a,w,c) { \ 170#define mul_add(r,a,w,c) { \
141 BN_ULLONG t; \ 171 BN_ULLONG t; \
@@ -151,6 +181,43 @@ extern "C" {
151 (c)= Hw(t); \ 181 (c)= Hw(t); \
152 } 182 }
153 183
184#define sqr(r0,r1,a) { \
185 BN_ULLONG t; \
186 t=(BN_ULLONG)(a)*(a); \
187 (r0)=Lw(t); \
188 (r1)=Hw(t); \
189 }
190
191#elif defined(BN_UMULT_HIGH)
192#define mul_add(r,a,w,c) { \
193 BN_ULONG high,low,ret,tmp=(a); \
194 ret = (r); \
195 high= BN_UMULT_HIGH(w,tmp); \
196 ret += (c); \
197 low = (w) * tmp; \
198 (c) = (ret<(c))?1:0; \
199 (c) += high; \
200 ret += low; \
201 (c) += (ret<low)?1:0; \
202 (r) = ret; \
203 }
204
205#define mul(r,a,w,c) { \
206 BN_ULONG high,low,ret,ta=(a); \
207 low = (w) * ta; \
208 high= BN_UMULT_HIGH(w,ta); \
209 ret = low + (c); \
210 (c) = high; \
211 (c) += (ret<low)?1:0; \
212 (r) = ret; \
213 }
214
215#define sqr(r0,r1,a) { \
216 BN_ULONG tmp=(a); \
217 (r0) = tmp * tmp; \
218 (r1) = BN_UMULT_HIGH(tmp,tmp); \
219 }
220
154#else 221#else
155/************************************************************* 222/*************************************************************
156 * No long long type 223 * No long long type
@@ -228,21 +295,7 @@ extern "C" {
228 (c)=h&BN_MASK2; \ 295 (c)=h&BN_MASK2; \
229 (r)=l&BN_MASK2; \ 296 (r)=l&BN_MASK2; \
230 } 297 }
231 298#endif /* !BN_LLONG */
232#endif
233
234OPENSSL_EXTERN int bn_limit_bits;
235OPENSSL_EXTERN int bn_limit_num; /* (1<<bn_limit_bits) */
236/* Recursive 'low' limit */
237OPENSSL_EXTERN int bn_limit_bits_low;
238OPENSSL_EXTERN int bn_limit_num_low; /* (1<<bn_limit_bits_low) */
239/* Do modified 'high' part calculation' */
240OPENSSL_EXTERN int bn_limit_bits_high;
241OPENSSL_EXTERN int bn_limit_num_high; /* (1<<bn_limit_bits_high) */
242OPENSSL_EXTERN int bn_limit_bits_mont;
243OPENSSL_EXTERN int bn_limit_num_mont; /* (1<<bn_limit_bits_mont) */
244
245BIGNUM *bn_expand2(BIGNUM *b, int bits);
246 299
247void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb); 300void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb);
248void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b); 301void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 5d62d88e8b..0e6b12d9c3 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -71,14 +71,14 @@ const char *BN_version="Big Number" OPENSSL_VERSION_PTEXT;
71 * 7 - 128 == 4096 71 * 7 - 128 == 4096
72 * 8 - 256 == 8192 72 * 8 - 256 == 8192
73 */ 73 */
74OPENSSL_GLOBAL int bn_limit_bits=0; 74static int bn_limit_bits=0;
75OPENSSL_GLOBAL int bn_limit_num=8; /* (1<<bn_limit_bits) */ 75static int bn_limit_num=8; /* (1<<bn_limit_bits) */
76OPENSSL_GLOBAL int bn_limit_bits_low=0; 76static int bn_limit_bits_low=0;
77OPENSSL_GLOBAL int bn_limit_num_low=8; /* (1<<bn_limit_bits_low) */ 77static int bn_limit_num_low=8; /* (1<<bn_limit_bits_low) */
78OPENSSL_GLOBAL int bn_limit_bits_high=0; 78static int bn_limit_bits_high=0;
79OPENSSL_GLOBAL int bn_limit_num_high=8; /* (1<<bn_limit_bits_high) */ 79static int bn_limit_num_high=8; /* (1<<bn_limit_bits_high) */
80OPENSSL_GLOBAL int bn_limit_bits_mont=0; 80static int bn_limit_bits_mont=0;
81OPENSSL_GLOBAL int bn_limit_num_mont=8; /* (1<<bn_limit_bits_mont) */ 81static int bn_limit_num_mont=8; /* (1<<bn_limit_bits_mont) */
82 82
83void BN_set_params(int mult, int high, int low, int mont) 83void BN_set_params(int mult, int high, int low, int mont)
84 { 84 {
@@ -304,42 +304,10 @@ BIGNUM *BN_new(void)
304 return(ret); 304 return(ret);
305 } 305 }
306 306
307 307/* This is an internal function that should not be used in applications.
308BN_CTX *BN_CTX_new(void) 308 * It ensures that 'b' has enough room for a 'words' word number number.
309 { 309 * It is mostly used by the various BIGNUM routines. If there is an error,
310 BN_CTX *ret; 310 * NULL is returned. If not, 'b' is returned. */
311
312 ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
313 if (ret == NULL)
314 {
315 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
316 return(NULL);
317 }
318
319 BN_CTX_init(ret);
320 ret->flags=BN_FLG_MALLOCED;
321 return(ret);
322 }
323
324void BN_CTX_init(BN_CTX *ctx)
325 {
326 memset(ctx,0,sizeof(BN_CTX));
327 ctx->tos=0;
328 ctx->flags=0;
329 }
330
331void BN_CTX_free(BN_CTX *c)
332 {
333 int i;
334
335 if(c == NULL)
336 return;
337
338 for (i=0; i<BN_CTX_NUM; i++)
339 BN_clear_free(&(c->bn[i]));
340 if (c->flags & BN_FLG_MALLOCED)
341 Free(c);
342 }
343 311
344BIGNUM *bn_expand2(BIGNUM *b, int words) 312BIGNUM *bn_expand2(BIGNUM *b, int words)
345 { 313 {
@@ -389,7 +357,7 @@ BIGNUM *bn_expand2(BIGNUM *b, int words)
389 * if A and B happen to share same cache line such code is going to 357 * if A and B happen to share same cache line such code is going to
390 * cause severe cache trashing. Both factors have severe impact on 358 * cause severe cache trashing. Both factors have severe impact on
391 * performance of modern CPUs and this is the reason why this 359 * performance of modern CPUs and this is the reason why this
392 * particulare piece of code is #ifdefed away and replaced by more 360 * particular piece of code is #ifdefed away and replaced by more
393 * "friendly" version found in #else section below. This comment 361 * "friendly" version found in #else section below. This comment
394 * also applies to BN_copy function. 362 * also applies to BN_copy function.
395 * 363 *
@@ -420,7 +388,7 @@ BIGNUM *bn_expand2(BIGNUM *b, int words)
420 A[0]=B[0]; 388 A[0]=B[0];
421 case 0: 389 case 0:
422 /* I need the 'case 0' entry for utrix cc. 390 /* I need the 'case 0' entry for utrix cc.
423 * If the optimiser is turned on, it does the 391 * If the optimizer is turned on, it does the
424 * switch table by doing 392 * switch table by doing
425 * a=top&7 393 * a=top&7
426 * a--; 394 * a--;
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
index ee0f410c22..7bb0b91223 100644
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ b/src/lib/libcrypto/bn/bn_mont.c
@@ -57,25 +57,27 @@
57 */ 57 */
58 58
59/* 59/*
60 * Details about Montgomery multiplication algorithms can be found at: 60 * Details about Montgomery multiplication algorithms can be found at
61 * http://www.ece.orst.edu/ISL/Publications.html 61 * http://security.ece.orst.edu/publications.html, e.g.
62 * http://www.ece.orst.edu/ISL/Koc/papers/j37acmon.pdf 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
63 */ 64 */
64 65
65#include <stdio.h> 66#include <stdio.h>
66#include "cryptlib.h" 67#include "cryptlib.h"
67#include "bn_lcl.h" 68#include "bn_lcl.h"
68 69
69#define MONT_WORD 70#define MONT_WORD /* use the faster word-based algorithm */
70 71
71int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, 72int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
72 BN_MONT_CTX *mont, BN_CTX *ctx) 73 BN_MONT_CTX *mont, BN_CTX *ctx)
73 { 74 {
74 BIGNUM *tmp,*tmp2; 75 BIGNUM *tmp,*tmp2;
75 76
76 tmp= &(ctx->bn[ctx->tos]); 77 BN_CTX_start(ctx);
77 tmp2= &(ctx->bn[ctx->tos]); 78 tmp = BN_CTX_get(ctx);
78 ctx->tos+=2; 79 tmp2 = BN_CTX_get(ctx);
80 if (tmp == NULL || tmp2 == NULL) goto err;
79 81
80 bn_check_top(tmp); 82 bn_check_top(tmp);
81 bn_check_top(tmp2); 83 bn_check_top(tmp2);
@@ -99,7 +101,7 @@ int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
99 } 101 }
100 /* reduce from aRR to aR */ 102 /* reduce from aRR to aR */
101 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err; 103 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
102 ctx->tos-=2; 104 BN_CTX_end(ctx);
103 return(1); 105 return(1);
104err: 106err:
105 return(0); 107 return(0);
@@ -108,160 +110,123 @@ err:
108int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont, 110int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
109 BN_CTX *ctx) 111 BN_CTX *ctx)
110 { 112 {
111#ifdef BN_RECURSION_MONT 113 int retn=0;
112 if (mont->use_word)
113#endif
114 {
115 BIGNUM *n,*r;
116 BN_ULONG *ap,*np,*rp,n0,v,*nrp;
117 int al,nl,max,i,x,ri;
118 int retn=0;
119 114
120 r= &(ctx->bn[ctx->tos]); 115#ifdef MONT_WORD
116 BIGNUM *n,*r;
117 BN_ULONG *ap,*np,*rp,n0,v,*nrp;
118 int al,nl,max,i,x,ri;
121 119
122 if (!BN_copy(r,a)) goto err1; 120 BN_CTX_start(ctx);
123 n= &(mont->N); 121 if ((r = BN_CTX_get(ctx)) == NULL) goto err;
124 122
125 ap=a->d; 123 if (!BN_copy(r,a)) goto err;
126 /* mont->ri is the size of mont->N in bits/words */ 124 n= &(mont->N);
127 al=ri=mont->ri/BN_BITS2;
128 125
129 nl=n->top; 126 ap=a->d;
130 if ((al == 0) || (nl == 0)) { r->top=0; return(1); } 127 /* mont->ri is the size of mont->N in bits (rounded up
128 to the word size) */
129 al=ri=mont->ri/BN_BITS2;
130
131 nl=n->top;
132 if ((al == 0) || (nl == 0)) { r->top=0; return(1); }
131 133
132 max=(nl+al+1); /* allow for overflow (no?) XXX */ 134 max=(nl+al+1); /* allow for overflow (no?) XXX */
133 if (bn_wexpand(r,max) == NULL) goto err1; 135 if (bn_wexpand(r,max) == NULL) goto err;
134 if (bn_wexpand(ret,max) == NULL) goto err1; 136 if (bn_wexpand(ret,max) == NULL) goto err;
135 137
136 r->neg=a->neg^n->neg; 138 r->neg=a->neg^n->neg;
137 np=n->d; 139 np=n->d;
138 rp=r->d; 140 rp=r->d;
139 nrp= &(r->d[nl]); 141 nrp= &(r->d[nl]);
140 142
141 /* clear the top words of T */ 143 /* clear the top words of T */
142#if 1 144#if 1
143 for (i=r->top; i<max; i++) /* memset? XXX */ 145 for (i=r->top; i<max; i++) /* memset? XXX */
144 r->d[i]=0; 146 r->d[i]=0;
145#else 147#else
146 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); 148 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
147#endif 149#endif
148 150
149 r->top=max; 151 r->top=max;
150 n0=mont->n0; 152 n0=mont->n0;
151 153
152#ifdef BN_COUNT 154#ifdef BN_COUNT
153printf("word BN_from_montgomery %d * %d\n",nl,nl); 155 printf("word BN_from_montgomery %d * %d\n",nl,nl);
154#endif 156#endif
155 for (i=0; i<nl; i++) 157 for (i=0; i<nl; i++)
156 { 158 {
157 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2); 159 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
158 nrp++; 160 nrp++;
159 rp++; 161 rp++;
160 if (((nrp[-1]+=v)&BN_MASK2) >= v) 162 if (((nrp[-1]+=v)&BN_MASK2) >= v)
161 continue; 163 continue;
162 else
163 {
164 if (((++nrp[0])&BN_MASK2) != 0) continue;
165 if (((++nrp[1])&BN_MASK2) != 0) continue;
166 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
167 }
168 }
169 bn_fix_top(r);
170
171 /* mont->ri will be a multiple of the word size */
172#if 0
173 BN_rshift(ret,r,mont->ri);
174#else
175 x=ri;
176 rp=ret->d;
177 ap= &(r->d[x]);
178 if (r->top < x)
179 al=0;
180 else 164 else
181 al=r->top-x;
182 ret->top=al;
183 al-=4;
184 for (i=0; i<al; i+=4)
185 { 165 {
186 BN_ULONG t1,t2,t3,t4; 166 if (((++nrp[0])&BN_MASK2) != 0) continue;
187 167 if (((++nrp[1])&BN_MASK2) != 0) continue;
188 t1=ap[i+0]; 168 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
189 t2=ap[i+1];
190 t3=ap[i+2];
191 t4=ap[i+3];
192 rp[i+0]=t1;
193 rp[i+1]=t2;
194 rp[i+2]=t3;
195 rp[i+3]=t4;
196 } 169 }
197 al+=4;
198 for (; i<al; i++)
199 rp[i]=ap[i];
200#endif
201
202 if (BN_ucmp(ret, &(mont->N)) >= 0)
203 {
204 BN_usub(ret,ret,&(mont->N)); /* XXX */
205 }
206 retn=1;
207err1:
208 return(retn);
209 } 170 }
210#ifdef BN_RECURSION_MONT 171 bn_fix_top(r);
211 else /* bignum version */ 172
173 /* mont->ri will be a multiple of the word size */
174#if 0
175 BN_rshift(ret,r,mont->ri);
176#else
177 x=ri;
178 rp=ret->d;
179 ap= &(r->d[x]);
180 if (r->top < x)
181 al=0;
182 else
183 al=r->top-x;
184 ret->top=al;
185 al-=4;
186 for (i=0; i<al; i+=4)
212 { 187 {
213 BIGNUM *t1,*t2,*t3; 188 BN_ULONG t1,t2,t3,t4;
214 int j,i; 189
215 190 t1=ap[i+0];
216#ifdef BN_COUNT 191 t2=ap[i+1];
217printf("number BN_from_montgomery\n"); 192 t3=ap[i+2];
218#endif 193 t4=ap[i+3];
219 194 rp[i+0]=t1;
220 t1= &(ctx->bn[ctx->tos]); 195 rp[i+1]=t2;
221 t2= &(ctx->bn[ctx->tos+1]); 196 rp[i+2]=t3;
222 t3= &(ctx->bn[ctx->tos+2]); 197 rp[i+3]=t4;
223
224 i=mont->Ni.top;
225 bn_wexpand(ret,i); /* perhaps only i*2 */
226 bn_wexpand(t1,i*4); /* perhaps only i*2 */
227 bn_wexpand(t2,i*2); /* perhaps only i */
228
229 bn_mul_low_recursive(t2->d,a->d,mont->Ni.d,i,t1->d);
230
231 BN_zero(t3);
232 BN_set_bit(t3,mont->N.top*BN_BITS2);
233 bn_sub_words(t3->d,t3->d,a->d,i);
234 bn_mul_high(ret->d,t2->d,mont->N.d,t3->d,i,t1->d);
235
236 /* hmm... if a is between i and 2*i, things are bad */
237 if (a->top > i)
238 {
239 j=(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i));
240 if (j) /* overflow */
241 bn_sub_words(ret->d,ret->d,mont->N.d,i);
242 }
243 ret->top=i;
244 bn_fix_top(ret);
245 if (a->d[0])
246 BN_add_word(ret,1); /* Always? */
247 else /* Very very rare */
248 {
249 for (i=1; i<mont->N.top-1; i++)
250 {
251 if (a->d[i])
252 {
253 BN_add_word(ret,1); /* Always? */
254 break;
255 }
256 }
257 }
258
259 if (BN_ucmp(ret,&(mont->N)) >= 0)
260 BN_usub(ret,ret,&(mont->N));
261
262 return(1);
263 } 198 }
199 al+=4;
200 for (; i<al; i++)
201 rp[i]=ap[i];
264#endif 202#endif
203#else /* !MONT_WORD */
204 BIGNUM *t1,*t2;
205
206 BN_CTX_start(ctx);
207 t1 = BN_CTX_get(ctx);
208 t2 = BN_CTX_get(ctx);
209 if (t1 == NULL || t2 == NULL) goto err;
210
211 if (!BN_copy(t1,a)) goto err;
212 BN_mask_bits(t1,mont->ri);
213
214 if (!BN_mul(t2,t1,&mont->Ni,ctx)) goto err;
215 BN_mask_bits(t2,mont->ri);
216
217 if (!BN_mul(t1,t2,&mont->N,ctx)) goto err;
218 if (!BN_add(t2,a,t1)) goto err;
219 BN_rshift(ret,t2,mont->ri);
220#endif /* MONT_WORD */
221
222 if (BN_ucmp(ret, &(mont->N)) >= 0)
223 {
224 BN_usub(ret,ret,&(mont->N));
225 }
226 retn=1;
227 err:
228 BN_CTX_end(ctx);
229 return(retn);
265 } 230 }
266 231
267BN_MONT_CTX *BN_MONT_CTX_new(void) 232BN_MONT_CTX *BN_MONT_CTX_new(void)
@@ -278,7 +243,6 @@ BN_MONT_CTX *BN_MONT_CTX_new(void)
278 243
279void BN_MONT_CTX_init(BN_MONT_CTX *ctx) 244void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
280 { 245 {
281 ctx->use_word=0;
282 ctx->ri=0; 246 ctx->ri=0;
283 BN_init(&(ctx->RR)); 247 BN_init(&(ctx->RR));
284 BN_init(&(ctx->N)); 248 BN_init(&(ctx->N));
@@ -306,85 +270,53 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
306 R= &(mont->RR); /* grab RR as a temp */ 270 R= &(mont->RR); /* grab RR as a temp */
307 BN_copy(&(mont->N),mod); /* Set N */ 271 BN_copy(&(mont->N),mod); /* Set N */
308 272
309#ifdef BN_RECURSION_MONT 273#ifdef MONT_WORD
310 if (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)
311#endif
312 { 274 {
313 BIGNUM tmod; 275 BIGNUM tmod;
314 BN_ULONG buf[2]; 276 BN_ULONG buf[2];
315 277
316 mont->use_word=1;
317
318 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; 278 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
319 BN_zero(R); 279 BN_zero(R);
320 BN_set_bit(R,BN_BITS2); 280 BN_set_bit(R,BN_BITS2); /* R */
321 /* I was bad, this modification of a passed variable was
322 * breaking the multithreaded stuff :-(
323 * z=mod->top;
324 * mod->top=1; */
325 281
326 buf[0]=mod->d[0]; 282 buf[0]=mod->d[0]; /* tmod = N mod word size */
327 buf[1]=0; 283 buf[1]=0;
328 tmod.d=buf; 284 tmod.d=buf;
329 tmod.top=1; 285 tmod.top=1;
330 tmod.max=mod->max; 286 tmod.max=2;
331 tmod.neg=mod->neg; 287 tmod.neg=mod->neg;
332 288 /* Ri = R^-1 mod N*/
333 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL) 289 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)
334 goto err; 290 goto err;
335 BN_lshift(&Ri,&Ri,BN_BITS2); /* R*Ri */ 291 BN_lshift(&Ri,&Ri,BN_BITS2); /* R*Ri */
336 if (!BN_is_zero(&Ri)) 292 if (!BN_is_zero(&Ri))
337 {
338#if 1
339 BN_sub_word(&Ri,1); 293 BN_sub_word(&Ri,1);
340#else 294 else /* if N mod word size == 1 */
341 BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */ 295 BN_set_word(&Ri,BN_MASK2); /* Ri-- (mod word size) */
342#endif 296 BN_div(&Ri,NULL,&Ri,&tmod,ctx); /* Ni = (R*Ri-1)/N,
343 } 297 * keep only least significant word: */
344 else
345 {
346 /* This is not common..., 1 in BN_MASK2,
347 * It happens when buf[0] was == 1. So for 8 bit,
348 * this is 1/256, 16bit, 1 in 2^16 etc.
349 */
350 BN_set_word(&Ri,BN_MASK2);
351 }
352 BN_div(&Ri,NULL,&Ri,&tmod,ctx);
353 mont->n0=Ri.d[0]; 298 mont->n0=Ri.d[0];
354 BN_free(&Ri); 299 BN_free(&Ri);
355 /* mod->top=z; */
356 } 300 }
357#ifdef BN_RECURSION_MONT 301#else /* !MONT_WORD */
358 else 302 { /* bignum version */
359 { 303 mont->ri=BN_num_bits(mod);
360 mont->use_word=0;
361 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
362#if 1
363 BN_zero(R); 304 BN_zero(R);
364 BN_set_bit(R,mont->ri); 305 BN_set_bit(R,mont->ri); /* R = 2^ri */
365#else 306 /* Ri = R^-1 mod N*/
366 BN_lshift(R,BN_value_one(),mont->ri); /* R */
367#endif
368 if ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL) 307 if ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)
369 goto err; 308 goto err;
370 BN_lshift(&Ri,&Ri,mont->ri); /* R*Ri */ 309 BN_lshift(&Ri,&Ri,mont->ri); /* R*Ri */
371#if 1
372 BN_sub_word(&Ri,1); 310 BN_sub_word(&Ri,1);
373#else 311 /* Ni = (R*Ri-1) / N */
374 BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */
375#endif
376 BN_div(&(mont->Ni),NULL,&Ri,mod,ctx); 312 BN_div(&(mont->Ni),NULL,&Ri,mod,ctx);
377 BN_free(&Ri); 313 BN_free(&Ri);
378 } 314 }
379#endif 315#endif
380 316
381 /* setup RR for conversions */ 317 /* setup RR for conversions */
382#if 1
383 BN_zero(&(mont->RR)); 318 BN_zero(&(mont->RR));
384 BN_set_bit(&(mont->RR),mont->ri*2); 319 BN_set_bit(&(mont->RR),mont->ri*2);
385#else
386 BN_lshift(mont->RR,BN_value_one(),mont->ri*2);
387#endif
388 BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx); 320 BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);
389 321
390 return(1); 322 return(1);
@@ -399,7 +331,6 @@ BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
399 BN_copy(&(to->RR),&(from->RR)); 331 BN_copy(&(to->RR),&(from->RR));
400 BN_copy(&(to->N),&(from->N)); 332 BN_copy(&(to->N),&(from->N));
401 BN_copy(&(to->Ni),&(from->Ni)); 333 BN_copy(&(to->Ni),&(from->Ni));
402 to->use_word=from->use_word;
403 to->ri=from->ri; 334 to->ri=from->ri;
404 to->n0=from->n0; 335 to->n0=from->n0;
405 return(to); 336 return(to);
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c
index 38c47f3d1f..eb007e19e9 100644
--- a/src/lib/libcrypto/bn/bn_mul.c
+++ b/src/lib/libcrypto/bn/bn_mul.c
@@ -66,7 +66,7 @@
66 * n2 must be a power of 2. 66 * n2 must be a power of 2.
67 * We multiply and return the result. 67 * We multiply and return the result.
68 * t must be 2*n2 words in size 68 * t must be 2*n2 words in size
69 * We calulate 69 * We calculate
70 * a[0]*b[0] 70 * a[0]*b[0]
71 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) 71 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
72 * a[1]*b[1] 72 * a[1]*b[1]
@@ -78,21 +78,23 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
78 unsigned int neg,zero; 78 unsigned int neg,zero;
79 BN_ULONG ln,lo,*p; 79 BN_ULONG ln,lo,*p;
80 80
81#ifdef BN_COUNT 81# ifdef BN_COUNT
82printf(" bn_mul_recursive %d * %d\n",n2,n2); 82 printf(" bn_mul_recursive %d * %d\n",n2,n2);
83#endif 83# endif
84#ifdef BN_MUL_COMBA 84# ifdef BN_MUL_COMBA
85/* if (n2 == 4) 85# if 0
86 if (n2 == 4)
86 { 87 {
87 bn_mul_comba4(r,a,b); 88 bn_mul_comba4(r,a,b);
88 return; 89 return;
89 } 90 }
90 else */ if (n2 == 8) 91# endif
92 if (n2 == 8)
91 { 93 {
92 bn_mul_comba8(r,a,b); 94 bn_mul_comba8(r,a,b);
93 return; 95 return;
94 } 96 }
95#endif 97# endif /* BN_MUL_COMBA */
96 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) 98 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)
97 { 99 {
98 /* This should not happen */ 100 /* This should not happen */
@@ -136,7 +138,7 @@ printf(" bn_mul_recursive %d * %d\n",n2,n2);
136 break; 138 break;
137 } 139 }
138 140
139#ifdef BN_MUL_COMBA 141# ifdef BN_MUL_COMBA
140 if (n == 4) 142 if (n == 4)
141 { 143 {
142 if (!zero) 144 if (!zero)
@@ -158,7 +160,7 @@ printf(" bn_mul_recursive %d * %d\n",n2,n2);
158 bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n])); 160 bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));
159 } 161 }
160 else 162 else
161#endif 163# endif /* BN_MUL_COMBA */
162 { 164 {
163 p= &(t[n2*2]); 165 p= &(t[n2*2]);
164 if (!zero) 166 if (!zero)
@@ -219,12 +221,12 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
219 int n, BN_ULONG *t) 221 int n, BN_ULONG *t)
220 { 222 {
221 int i,j,n2=n*2; 223 int i,j,n2=n*2;
222 unsigned int c1; 224 unsigned int c1,c2,neg,zero;
223 BN_ULONG ln,lo,*p; 225 BN_ULONG ln,lo,*p;
224 226
225#ifdef BN_COUNT 227# ifdef BN_COUNT
226printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n); 228 printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
227#endif 229# endif
228 if (n < 8) 230 if (n < 8)
229 { 231 {
230 i=tn+n; 232 i=tn+n;
@@ -233,17 +235,54 @@ printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
233 } 235 }
234 236
235 /* r=(a[0]-a[1])*(b[1]-b[0]) */ 237 /* r=(a[0]-a[1])*(b[1]-b[0]) */
236 bn_sub_words(t, a, &(a[n]),n); /* + */ 238 c1=bn_cmp_words(a,&(a[n]),n);
237 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ 239 c2=bn_cmp_words(&(b[n]),b,n);
238 240 zero=neg=0;
239/* if (n == 4) 241 switch (c1*3+c2)
242 {
243 case -4:
244 bn_sub_words(t, &(a[n]),a, n); /* - */
245 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
246 break;
247 case -3:
248 zero=1;
249 /* break; */
250 case -2:
251 bn_sub_words(t, &(a[n]),a, n); /* - */
252 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
253 neg=1;
254 break;
255 case -1:
256 case 0:
257 case 1:
258 zero=1;
259 /* break; */
260 case 2:
261 bn_sub_words(t, a, &(a[n]),n); /* + */
262 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
263 neg=1;
264 break;
265 case 3:
266 zero=1;
267 /* break; */
268 case 4:
269 bn_sub_words(t, a, &(a[n]),n);
270 bn_sub_words(&(t[n]),&(b[n]),b, n);
271 break;
272 }
273 /* The zero case isn't yet implemented here. The speedup
274 would probably be negligible. */
275# if 0
276 if (n == 4)
240 { 277 {
241 bn_mul_comba4(&(t[n2]),t,&(t[n])); 278 bn_mul_comba4(&(t[n2]),t,&(t[n]));
242 bn_mul_comba4(r,a,b); 279 bn_mul_comba4(r,a,b);
243 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); 280 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
244 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); 281 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
245 } 282 }
246 else */ if (n == 8) 283 else
284# endif
285 if (n == 8)
247 { 286 {
248 bn_mul_comba8(&(t[n2]),t,&(t[n])); 287 bn_mul_comba8(&(t[n2]),t,&(t[n]));
249 bn_mul_comba8(r,a,b); 288 bn_mul_comba8(r,a,b);
@@ -308,7 +347,16 @@ printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
308 */ 347 */
309 348
310 c1=(int)(bn_add_words(t,r,&(r[n2]),n2)); 349 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
311 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2)); 350
351 if (neg) /* if t[32] is negative */
352 {
353 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
354 }
355 else
356 {
357 /* Might have a carry */
358 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));
359 }
312 360
313 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) 361 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
314 * r[10] holds (a[0]*b[0]) 362 * r[10] holds (a[0]*b[0])
@@ -345,9 +393,9 @@ void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
345 { 393 {
346 int n=n2/2; 394 int n=n2/2;
347 395
348#ifdef BN_COUNT 396# ifdef BN_COUNT
349printf(" bn_mul_low_recursive %d * %d\n",n2,n2); 397 printf(" bn_mul_low_recursive %d * %d\n",n2,n2);
350#endif 398# endif
351 399
352 bn_mul_recursive(r,a,b,n,&(t[0])); 400 bn_mul_recursive(r,a,b,n,&(t[0]));
353 if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) 401 if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL)
@@ -379,9 +427,9 @@ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
379 int neg,oneg,zero; 427 int neg,oneg,zero;
380 BN_ULONG ll,lc,*lp,*mp; 428 BN_ULONG ll,lc,*lp,*mp;
381 429
382#ifdef BN_COUNT 430# ifdef BN_COUNT
383printf(" bn_mul_high %d * %d\n",n2,n2); 431 printf(" bn_mul_high %d * %d\n",n2,n2);
384#endif 432# endif
385 n=n2/2; 433 n=n2/2;
386 434
387 /* Calculate (al-ah)*(bh-bl) */ 435 /* Calculate (al-ah)*(bh-bl) */
@@ -424,14 +472,14 @@ printf(" bn_mul_high %d * %d\n",n2,n2);
424 oneg=neg; 472 oneg=neg;
425 /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */ 473 /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */
426 /* r[10] = (a[1]*b[1]) */ 474 /* r[10] = (a[1]*b[1]) */
427#ifdef BN_MUL_COMBA 475# ifdef BN_MUL_COMBA
428 if (n == 8) 476 if (n == 8)
429 { 477 {
430 bn_mul_comba8(&(t[0]),&(r[0]),&(r[n])); 478 bn_mul_comba8(&(t[0]),&(r[0]),&(r[n]));
431 bn_mul_comba8(r,&(a[n]),&(b[n])); 479 bn_mul_comba8(r,&(a[n]),&(b[n]));
432 } 480 }
433 else 481 else
434#endif 482# endif
435 { 483 {
436 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2])); 484 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2]));
437 bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2])); 485 bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2]));
@@ -555,19 +603,23 @@ printf(" bn_mul_high %d * %d\n",n2,n2);
555 } 603 }
556 } 604 }
557 } 605 }
558#endif 606#endif /* BN_RECURSION */
559 607
560int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) 608int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
561 { 609 {
562 int top,al,bl; 610 int top,al,bl;
563 BIGNUM *rr; 611 BIGNUM *rr;
612 int ret = 0;
613#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
614 int i;
615#endif
564#ifdef BN_RECURSION 616#ifdef BN_RECURSION
565 BIGNUM *t; 617 BIGNUM *t;
566 int i,j,k; 618 int j,k;
567#endif 619#endif
568 620
569#ifdef BN_COUNT 621#ifdef BN_COUNT
570printf("BN_mul %d * %d\n",a->top,b->top); 622 printf("BN_mul %d * %d\n",a->top,b->top);
571#endif 623#endif
572 624
573 bn_check_top(a); 625 bn_check_top(a);
@@ -585,115 +637,99 @@ printf("BN_mul %d * %d\n",a->top,b->top);
585 } 637 }
586 top=al+bl; 638 top=al+bl;
587 639
640 BN_CTX_start(ctx);
588 if ((r == a) || (r == b)) 641 if ((r == a) || (r == b))
589 rr= &(ctx->bn[ctx->tos+1]); 642 {
643 if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
644 }
590 else 645 else
591 rr=r; 646 rr = r;
592 647
593#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) 648#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
594 if (al == bl) 649 i = al-bl;
650#endif
651#ifdef BN_MUL_COMBA
652 if (i == 0)
595 { 653 {
596# ifdef BN_MUL_COMBA 654# if 0
597/* if (al == 4) 655 if (al == 4)
598 { 656 {
599 if (bn_wexpand(rr,8) == NULL) return(0); 657 if (bn_wexpand(rr,8) == NULL) goto err;
600 rr->top=8; 658 rr->top=8;
601 bn_mul_comba4(rr->d,a->d,b->d); 659 bn_mul_comba4(rr->d,a->d,b->d);
602 goto end; 660 goto end;
603 } 661 }
604 else */ if (al == 8) 662# endif
663 if (al == 8)
605 { 664 {
606 if (bn_wexpand(rr,16) == NULL) return(0); 665 if (bn_wexpand(rr,16) == NULL) goto err;
607 rr->top=16; 666 rr->top=16;
608 bn_mul_comba8(rr->d,a->d,b->d); 667 bn_mul_comba8(rr->d,a->d,b->d);
609 goto end; 668 goto end;
610 } 669 }
611 else
612# endif
613#ifdef BN_RECURSION
614 if (al < BN_MULL_SIZE_NORMAL)
615#endif
616 {
617 if (bn_wexpand(rr,top) == NULL) return(0);
618 rr->top=top;
619 bn_mul_normal(rr->d,a->d,al,b->d,bl);
620 goto end;
621 }
622# ifdef BN_RECURSION
623 goto symetric;
624# endif
625 } 670 }
626#endif 671#endif /* BN_MUL_COMBA */
627#ifdef BN_RECURSION 672#ifdef BN_RECURSION
628 else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL)) 673 if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))
629 { 674 {
630 if (bn_wexpand(rr,top) == NULL) return(0); 675 if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))
631 rr->top=top;
632 bn_mul_normal(rr->d,a->d,al,b->d,bl);
633 goto end;
634 }
635 else
636 {
637 i=(al-bl);
638 if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))
639 { 676 {
640 bn_wexpand(b,al); 677 bn_wexpand(b,al);
641 b->d[bl]=0; 678 b->d[bl]=0;
642 bl++; 679 bl++;
643 goto symetric; 680 i--;
644 } 681 }
645 else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) 682 else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))
646 { 683 {
647 bn_wexpand(a,bl); 684 bn_wexpand(a,bl);
648 a->d[al]=0; 685 a->d[al]=0;
649 al++; 686 al++;
650 goto symetric; 687 i++;
688 }
689 if (i == 0)
690 {
691 /* symmetric and > 4 */
692 /* 16 or larger */
693 j=BN_num_bits_word((BN_ULONG)al);
694 j=1<<(j-1);
695 k=j+j;
696 t = BN_CTX_get(ctx);
697 if (al == j) /* exact multiple */
698 {
699 bn_wexpand(t,k*2);
700 bn_wexpand(rr,k*2);
701 bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
702 }
703 else
704 {
705 bn_wexpand(a,k);
706 bn_wexpand(b,k);
707 bn_wexpand(t,k*4);
708 bn_wexpand(rr,k*4);
709 for (i=a->top; i<k; i++)
710 a->d[i]=0;
711 for (i=b->top; i<k; i++)
712 b->d[i]=0;
713 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
714 }
715 rr->top=top;
716 goto end;
651 } 717 }
652 } 718 }
653#endif 719#endif /* BN_RECURSION */
654 720 if (bn_wexpand(rr,top) == NULL) goto err;
655 /* asymetric and >= 4 */
656 if (bn_wexpand(rr,top) == NULL) return(0);
657 rr->top=top; 721 rr->top=top;
658 bn_mul_normal(rr->d,a->d,al,b->d,bl); 722 bn_mul_normal(rr->d,a->d,al,b->d,bl);
659 723
660#ifdef BN_RECURSION
661 if (0)
662 {
663symetric:
664 /* symetric and > 4 */
665 /* 16 or larger */
666 j=BN_num_bits_word((BN_ULONG)al);
667 j=1<<(j-1);
668 k=j+j;
669 t= &(ctx->bn[ctx->tos]);
670 if (al == j) /* exact multiple */
671 {
672 bn_wexpand(t,k*2);
673 bn_wexpand(rr,k*2);
674 bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
675 }
676 else
677 {
678 bn_wexpand(a,k);
679 bn_wexpand(b,k);
680 bn_wexpand(t,k*4);
681 bn_wexpand(rr,k*4);
682 for (i=a->top; i<k; i++)
683 a->d[i]=0;
684 for (i=b->top; i<k; i++)
685 b->d[i]=0;
686 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
687 }
688 rr->top=top;
689 }
690#endif
691#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) 724#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
692end: 725end:
693#endif 726#endif
694 bn_fix_top(rr); 727 bn_fix_top(rr);
695 if (r != rr) BN_copy(r,rr); 728 if (r != rr) BN_copy(r,rr);
696 return(1); 729 ret=1;
730err:
731 BN_CTX_end(ctx);
732 return(ret);
697 } 733 }
698 734
699void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) 735void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
@@ -701,7 +737,7 @@ void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
701 BN_ULONG *rr; 737 BN_ULONG *rr;
702 738
703#ifdef BN_COUNT 739#ifdef BN_COUNT
704printf(" bn_mul_normal %d * %d\n",na,nb); 740 printf(" bn_mul_normal %d * %d\n",na,nb);
705#endif 741#endif
706 742
707 if (na < nb) 743 if (na < nb)
@@ -735,7 +771,7 @@ printf(" bn_mul_normal %d * %d\n",na,nb);
735void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) 771void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
736 { 772 {
737#ifdef BN_COUNT 773#ifdef BN_COUNT
738printf(" bn_mul_low_normal %d * %d\n",n,n); 774 printf(" bn_mul_low_normal %d * %d\n",n,n);
739#endif 775#endif
740 bn_mul_words(r,a,n,b[0]); 776 bn_mul_words(r,a,n,b[0]);
741 777
@@ -753,4 +789,3 @@ printf(" bn_mul_low_normal %d * %d\n",n,n);
753 b+=4; 789 b+=4;
754 } 790 }
755 } 791 }
756
diff --git a/src/lib/libcrypto/bn/bn_opts.c b/src/lib/libcrypto/bn/bn_opts.c
index 381be529b2..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/bn_opts.c
+++ b/src/lib/libcrypto/bn/bn_opts.c
@@ -1,324 +0,0 @@
1/* crypto/bn/expspeed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* most of this code has been pilfered from my libdes speed.c program */
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <signal.h>
64#include <string.h>
65#include <openssl/crypto.h>
66#include <openssl/tmdiff.h>
67#include <openssl/bn.h>
68#include <openssl/err.h>
69
70#define DEFAULT_SIZE 512
71#define DEFAULT_TIME 3
72
73int verbose=1;
74
75typedef struct parms_st
76 {
77 char *name;
78 void (*func)();
79 BIGNUM r;
80 BIGNUM a;
81 BIGNUM b;
82 BIGNUM c;
83 BIGNUM low;
84 BN_CTX *ctx;
85 BN_MONT_CTX *mont;
86 int w;
87 } PARMS;
88
89void do_mul_exp(int num,PARMS *p);
90void do_mul(int num,PARMS *p);
91void do_sqr(int num,PARMS *p);
92void do_mul_low(int num,PARMS *p);
93void do_mul_high(int num,PARMS *p);
94void do_from_montgomery(int num,PARMS *p);
95int time_it(int sec, PARMS *p);
96void do_it(int sec, PARMS *p);
97
98#define P_EXP 1
99#define P_MUL 2
100#define P_SQR 3
101#define P_MULL 4
102#define P_MULH 5
103#define P_MRED 6
104
105int main(int argc, char **argv)
106 {
107 PARMS p;
108 BN_MONT_CTX *mont;
109 int size=0,num;
110 char *name;
111 int type=P_EXP;
112
113 mont=BN_MONT_CTX_new();
114 p.mont=NULL;
115 p.ctx=BN_CTX_new();
116 BN_init(&p.r);
117 BN_init(&p.a);
118 BN_init(&p.b);
119 BN_init(&p.c);
120 BN_init(&p.low);
121 p.w=0;
122
123 for (;;)
124 {
125 if (argc > 1)
126 {
127 if (argv[1][0] == '-')
128 {
129 switch(argv[1][1])
130 {
131 case 'e': type=P_EXP; break;
132 case 'm': type=P_MUL; break;
133 case 's': type=P_SQR; break;
134 case 'l': type=P_MULL; break;
135 case 'h': type=P_MULH; break;
136 case 'r': type=P_MRED; break;
137 default:
138 fprintf(stderr,"options: -[emslhr]\n");
139 exit(1);
140 }
141 }
142 else
143 {
144 size=atoi(argv[1]);
145 }
146 argc--;
147 argv++;
148 }
149 else
150 break;
151 }
152 if (size == 0)
153 size=DEFAULT_SIZE;
154
155 printf("bit size:%5d\n",size);
156
157 BN_rand(&p.a,size,1,0);
158 BN_rand(&p.b,size,1,0);
159 BN_rand(&p.c,size,1,1);
160 BN_mod(&p.a,&p.a,&p.c,p.ctx);
161 BN_mod(&p.b,&p.b,&p.c,p.ctx);
162 p.w=(p.a.top+1)/2;
163
164 BN_mul(&p.low,&p.a,&p.b,p.ctx);
165 p.low.top=p.a.top;
166
167 switch(type)
168 {
169 case P_EXP:
170 p.name="r=a^b%c";
171 p.func=do_mul_exp;
172 p.mont=mont;
173 break;
174 case P_MUL:
175 p.name="r=a*b";
176 p.func=do_mul;
177 break;
178 case P_SQR:
179 p.name="r=a*a";
180 p.func=do_sqr;
181 break;
182 case P_MULL:
183 p.name="r=low(a*b)";
184 p.func=do_mul_low;
185 break;
186 case P_MULH:
187 p.name="r=high(a*b)";
188 p.func=do_mul_high;
189 break;
190 case P_MRED:
191 p.name="r=montgomery_reduction(a)";
192 p.func=do_from_montgomery;
193 p.mont=mont;
194 break;
195 default:
196 fprintf(stderr,"options: -[emslhr]\n");
197 exit(1);
198 }
199
200 num=time_it(DEFAULT_TIME,&p);
201 do_it(num,&p);
202 }
203
204void do_it(int num, PARMS *p)
205 {
206 char *start,*end;
207 int i,j,number;
208 double d;
209
210 start=ms_time_new();
211 end=ms_time_new();
212
213 number=BN_num_bits_word((BN_ULONG)BN_num_bits(&(p->c)))-
214 BN_num_bits_word(BN_BITS2)+2;
215 for (i=number-1; i >=0; i--)
216 {
217 if (i == 1) continue;
218 BN_set_params(i,i,i,1);
219 if (p->mont != NULL)
220 BN_MONT_CTX_set(p->mont,&(p->c),p->ctx);
221
222 printf("Timing %5d (%2d bit) %2d %2d %2d %2d :",
223 (1<<i)*BN_BITS2,i,
224 BN_get_params(0),
225 BN_get_params(1),
226 BN_get_params(2),
227 BN_get_params(3));
228 fflush(stdout);
229
230 ms_time_get(start);
231 p->func(num,p);
232 ms_time_get(end);
233 d=ms_time_diff(start,end);
234 printf("%6.6f sec, or %d in %.4f seconds\n",
235 (double)d/num,num,d);
236 }
237 }
238
239int time_it(int sec, PARMS *p)
240 {
241 char *start,*end;
242 int i,j;
243 double d;
244
245 if (p->mont != NULL)
246 BN_MONT_CTX_set(p->mont,&(p->c),p->ctx);
247
248 start=ms_time_new();
249 end=ms_time_new();
250
251 i=1;
252 for (;;)
253 {
254 if (verbose)
255 printf("timing %s for %d interations\n",p->name,i);
256
257 ms_time_get(start);
258 p->func(i,p);
259 ms_time_get(end);
260 d=ms_time_diff(start,end);
261
262 if (d < 0.01) i*=100;
263 else if (d < 0.1 ) i*=10;
264 else if (d > (double)sec) break;
265 else
266 {
267 i=(int)(1.0*i*sec/d);
268 break;
269 }
270 }
271 if (verbose)
272 printf("using %d interations\n",i);
273 return(i);
274 }
275
276void do_mul_exp(int num, PARMS *p)
277 {
278 int i;
279
280 for (i=0; i<num; i++)
281 BN_mod_exp_mont(&(p->r),&(p->a),&(p->b),&(p->c),
282 p->ctx,p->mont);
283 }
284
285void do_mul(int num, PARMS *p)
286 {
287 int i;
288
289 for (i=0; i<num; i++)
290 BN_mul(&(p->r),&(p->a),&(p->b),p->ctx);
291 }
292
293void do_sqr(int num, PARMS *p)
294 {
295 int i;
296
297 for (i=0; i<num; i++)
298 BN_sqr(&(p->r),&(p->a),p->ctx);
299 }
300
301void do_mul_low(int num, PARMS *p)
302 {
303 int i;
304
305 for (i=0; i<num; i++)
306 BN_mul_low(&(p->r),&(p->a),&(p->b),p->w,p->ctx);
307 }
308
309void do_mul_high(int num, PARMS *p)
310 {
311 int i;
312
313 for (i=0; i<num; i++)
314 BN_mul_low(&(p->r),&(p->a),&(p->b),&(p->low),p->w,p->ctx);
315 }
316
317void do_from_montgomery(int num, PARMS *p)
318 {
319 int i;
320
321 for (i=0; i<num; i++)
322 BN_from_montgomery(&(p->r),&(p->a),p->mont,p->ctx);
323 }
324
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
index 6fa0f9be1e..a5f01b92eb 100644
--- a/src/lib/libcrypto/bn/bn_prime.c
+++ b/src/lib/libcrypto/bn/bn_prime.c
@@ -55,6 +55,59 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 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 */
58 111
59#include <stdio.h> 112#include <stdio.h>
60#include <time.h> 113#include <time.h>
@@ -62,26 +115,29 @@
62#include "bn_lcl.h" 115#include "bn_lcl.h"
63#include <openssl/rand.h> 116#include <openssl/rand.h>
64 117
65/* The quick seive algorithm approach to weeding out primes is 118/* The quick sieve algorithm approach to weeding out primes is
66 * Philip Zimmermann's, as implemented in PGP. I have had a read of 119 * Philip Zimmermann's, as implemented in PGP. I have had a read of
67 * his comments and implemented my own version. 120 * his comments and implemented my own version.
68 */ 121 */
69#include "bn_prime.h" 122#include "bn_prime.h"
70 123
71static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx,BN_CTX *ctx2, 124static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
72 BN_MONT_CTX *mont); 125 const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont);
73static int probable_prime(BIGNUM *rnd, int bits); 126static int probable_prime(BIGNUM *rnd, int bits);
74static int probable_prime_dh(BIGNUM *rnd, int bits, 127static int probable_prime_dh(BIGNUM *rnd, int bits,
75 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); 128 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
76static int probable_prime_dh_strong(BIGNUM *rnd, int bits, 129static int probable_prime_dh_safe(BIGNUM *rnd, int bits,
77 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); 130 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
78BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int strong, BIGNUM *add, 131
132BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, BIGNUM *add,
79 BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg) 133 BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg)
80 { 134 {
81 BIGNUM *rnd=NULL; 135 BIGNUM *rnd=NULL;
82 BIGNUM t; 136 BIGNUM t;
137 int found=0;
83 int i,j,c1=0; 138 int i,j,c1=0;
84 BN_CTX *ctx; 139 BN_CTX *ctx;
140 int checks = BN_prime_checks_for_size(bits);
85 141
86 ctx=BN_CTX_new(); 142 ctx=BN_CTX_new();
87 if (ctx == NULL) goto err; 143 if (ctx == NULL) goto err;
@@ -100,9 +156,9 @@ loop:
100 } 156 }
101 else 157 else
102 { 158 {
103 if (strong) 159 if (safe)
104 { 160 {
105 if (!probable_prime_dh_strong(rnd,bits,add,rem,ctx)) 161 if (!probable_prime_dh_safe(rnd,bits,add,rem,ctx))
106 goto err; 162 goto err;
107 } 163 }
108 else 164 else
@@ -114,160 +170,185 @@ loop:
114 /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */ 170 /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */
115 if (callback != NULL) callback(0,c1++,cb_arg); 171 if (callback != NULL) callback(0,c1++,cb_arg);
116 172
117 if (!strong) 173 if (!safe)
118 { 174 {
119 i=BN_is_prime(rnd,BN_prime_checks,callback,ctx,cb_arg); 175 i=BN_is_prime_fasttest(rnd,checks,callback,ctx,cb_arg,0);
120 if (i == -1) goto err; 176 if (i == -1) goto err;
121 if (i == 0) goto loop; 177 if (i == 0) goto loop;
122 } 178 }
123 else 179 else
124 { 180 {
125 /* for a strong prime generation, 181 /* for "safe prime" generation,
126 * check that (p-1)/2 is prime. 182 * check that (p-1)/2 is prime.
127 * Since a prime is odd, We just 183 * Since a prime is odd, We just
128 * need to divide by 2 */ 184 * need to divide by 2 */
129 if (!BN_rshift1(&t,rnd)) goto err; 185 if (!BN_rshift1(&t,rnd)) goto err;
130 186
131 for (i=0; i<BN_prime_checks; i++) 187 for (i=0; i<checks; i++)
132 { 188 {
133 j=BN_is_prime(rnd,1,callback,ctx,cb_arg); 189 j=BN_is_prime_fasttest(rnd,1,callback,ctx,cb_arg,0);
134 if (j == -1) goto err; 190 if (j == -1) goto err;
135 if (j == 0) goto loop; 191 if (j == 0) goto loop;
136 192
137 j=BN_is_prime(&t,1,callback,ctx,cb_arg); 193 j=BN_is_prime_fasttest(&t,1,callback,ctx,cb_arg,0);
138 if (j == -1) goto err; 194 if (j == -1) goto err;
139 if (j == 0) goto loop; 195 if (j == 0) goto loop;
140 196
141 if (callback != NULL) callback(2,c1-1,cb_arg); 197 if (callback != NULL) callback(2,c1-1,cb_arg);
142 /* We have a strong prime test pass */ 198 /* We have a safe prime test pass */
143 } 199 }
144 } 200 }
145 /* we have a prime :-) */ 201 /* we have a prime :-) */
146 ret=rnd; 202 found = 1;
147err: 203err:
148 if ((ret == NULL) && (rnd != NULL)) BN_free(rnd); 204 if (!found && (ret == NULL) && (rnd != NULL)) BN_free(rnd);
149 BN_free(&t); 205 BN_free(&t);
150 if (ctx != NULL) BN_CTX_free(ctx); 206 if (ctx != NULL) BN_CTX_free(ctx);
151 return(ret); 207 return(found ? rnd : NULL);
152 } 208 }
153 209
154int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,void *), 210int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
155 BN_CTX *ctx_passed, void *cb_arg) 211 BN_CTX *ctx_passed, void *cb_arg)
156 { 212 {
157 int i,j,c2=0,ret= -1; 213 return BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);
158 BIGNUM *check; 214 }
159 BN_CTX *ctx=NULL,*ctx2=NULL;
160 BN_MONT_CTX *mont=NULL;
161 215
216int BN_is_prime_fasttest(const BIGNUM *a, int checks,
217 void (*callback)(int,int,void *),
218 BN_CTX *ctx_passed, void *cb_arg,
219 int do_trial_division)
220 {
221 int i, j, ret = -1;
222 int k;
223 BN_CTX *ctx = NULL;
224 BIGNUM *A1, *A1_odd, *check; /* taken from ctx */
225 BN_MONT_CTX *mont = NULL;
226 const BIGNUM *A = NULL;
227
228 if (checks == BN_prime_checks)
229 checks = BN_prime_checks_for_size(BN_num_bits(a));
230
231 /* first look for small factors */
162 if (!BN_is_odd(a)) 232 if (!BN_is_odd(a))
163 return(0); 233 return(0);
234 if (do_trial_division)
235 {
236 for (i = 1; i < NUMPRIMES; i++)
237 if (BN_mod_word(a, primes[i]) == 0)
238 return 0;
239 if (callback != NULL) callback(1, -1, cb_arg);
240 }
241
164 if (ctx_passed != NULL) 242 if (ctx_passed != NULL)
165 ctx=ctx_passed; 243 ctx = ctx_passed;
166 else 244 else
167 if ((ctx=BN_CTX_new()) == NULL) goto err; 245 if ((ctx=BN_CTX_new()) == NULL)
168 246 goto err;
169 if ((ctx2=BN_CTX_new()) == NULL) goto err; 247 BN_CTX_start(ctx);
170 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
171
172 check= &(ctx->bn[ctx->tos++]);
173 248
174 /* Setup the montgomery structure */ 249 /* A := abs(a) */
175 if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err; 250 if (a->neg)
251 {
252 BIGNUM *t;
253 if ((t = BN_CTX_get(ctx)) == NULL) goto err;
254 BN_copy(t, a);
255 t->neg = 0;
256 A = t;
257 }
258 else
259 A = a;
260 A1 = BN_CTX_get(ctx);
261 A1_odd = BN_CTX_get(ctx);
262 check = BN_CTX_get(ctx);
263 if (check == NULL) goto err;
264
265 /* compute A1 := A - 1 */
266 if (!BN_copy(A1, A))
267 goto err;
268 if (!BN_sub_word(A1, 1))
269 goto err;
270 if (BN_is_zero(A1))
271 {
272 ret = 0;
273 goto err;
274 }
176 275
177 for (i=0; i<checks; i++) 276 /* write A1 as A1_odd * 2^k */
277 k = 1;
278 while (!BN_is_bit_set(A1, k))
279 k++;
280 if (!BN_rshift(A1_odd, A1, k))
281 goto err;
282
283 /* Montgomery setup for computations mod A */
284 mont = BN_MONT_CTX_new();
285 if (mont == NULL)
286 goto err;
287 if (!BN_MONT_CTX_set(mont, A, ctx))
288 goto err;
289
290 for (i = 0; i < checks; i++)
178 { 291 {
179 if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err; 292 if (!BN_pseudo_rand(check, BN_num_bits(A1), 0, 0))
180 j=witness(check,a,ctx,ctx2,mont); 293 goto err;
294 if (BN_cmp(check, A1) >= 0)
295 if (!BN_sub(check, check, A1))
296 goto err;
297 if (!BN_add_word(check, 1))
298 goto err;
299 /* now 1 <= check < A */
300
301 j = witness(check, A, A1, A1_odd, k, ctx, mont);
181 if (j == -1) goto err; 302 if (j == -1) goto err;
182 if (j) 303 if (j)
183 { 304 {
184 ret=0; 305 ret=0;
185 goto err; 306 goto err;
186 } 307 }
187 if (callback != NULL) callback(1,c2++,cb_arg); 308 if (callback != NULL) callback(1,i,cb_arg);
188 } 309 }
189 ret=1; 310 ret=1;
190err: 311err:
191 ctx->tos--; 312 if (ctx != NULL)
192 if ((ctx_passed == NULL) && (ctx != NULL)) 313 {
193 BN_CTX_free(ctx); 314 BN_CTX_end(ctx);
194 if (ctx2 != NULL) 315 if (ctx_passed == NULL)
195 BN_CTX_free(ctx2); 316 BN_CTX_free(ctx);
196 if (mont != NULL) BN_MONT_CTX_free(mont); 317 }
197 318 if (mont != NULL)
319 BN_MONT_CTX_free(mont);
320
198 return(ret); 321 return(ret);
199 } 322 }
200 323
201#define RECP_MUL_MOD 324static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
202 325 const BIGNUM *a1_odd, int k, BN_CTX *ctx, BN_MONT_CTX *mont)
203static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2,
204 BN_MONT_CTX *mont)
205 { 326 {
206 int k,i,ret= -1,good; 327 if (!BN_mod_exp_mont(w, w, a1_odd, a, ctx, mont)) /* w := w^a1_odd mod a */
207 BIGNUM *d,*dd,*tmp,*d1,*d2,*n1; 328 return -1;
208 BIGNUM *mont_one,*mont_n1,*mont_a; 329 if (BN_is_one(w))
209 330 return 0; /* probably prime */
210 d1= &(ctx->bn[ctx->tos]); 331 if (BN_cmp(w, a1) == 0)
211 d2= &(ctx->bn[ctx->tos+1]); 332 return 0; /* w == -1 (mod a), 'a' is probably prime */
212 n1= &(ctx->bn[ctx->tos+2]); 333 while (--k)
213 ctx->tos+=3;
214
215 mont_one= &(ctx2->bn[ctx2->tos]);
216 mont_n1= &(ctx2->bn[ctx2->tos+1]);
217 mont_a= &(ctx2->bn[ctx2->tos+2]);
218 ctx2->tos+=3;
219
220 d=d1;
221 dd=d2;
222 if (!BN_one(d)) goto err;
223 if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */
224 k=BN_num_bits(n1);
225
226 if (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err;
227 if (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err;
228 if (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err;
229
230 BN_copy(d,mont_one);
231 for (i=k-1; i>=0; i--)
232 { 334 {
233 if ( (BN_cmp(d,mont_one) != 0) && 335 if (!BN_mod_mul(w, w, w, a, ctx)) /* w := w^2 mod a */
234 (BN_cmp(d,mont_n1) != 0)) 336 return -1;
235 good=1; 337 if (BN_is_one(w))
236 else 338 return 1; /* 'a' is composite, otherwise a previous 'w' would
237 good=0; 339 * have been == -1 (mod 'a') */
238 340 if (BN_cmp(w, a1) == 0)
239 BN_mod_mul_montgomery(dd,d,d,mont,ctx2); 341 return 0; /* w == -1 (mod a), 'a' is probably prime */
240
241 if (good && (BN_cmp(dd,mont_one) == 0))
242 {
243 ret=1;
244 goto err;
245 }
246 if (BN_is_bit_set(n1,i))
247 {
248 BN_mod_mul_montgomery(d,dd,mont_a,mont,ctx2);
249 }
250 else
251 {
252 tmp=d;
253 d=dd;
254 dd=tmp;
255 }
256 } 342 }
257 if (BN_cmp(d,mont_one) == 0) 343 /* If we get here, 'w' is the (a-1)/2-th power of the original 'w',
258 i=0; 344 * and it is neither -1 nor +1 -- so 'a' cannot be prime */
259 else i=1; 345 return 1;
260 ret=i;
261err:
262 ctx->tos-=3;
263 ctx2->tos-=3;
264 return(ret);
265 } 346 }
266 347
267static int probable_prime(BIGNUM *rnd, int bits) 348static int probable_prime(BIGNUM *rnd, int bits)
268 { 349 {
269 int i; 350 int i;
270 MS_STATIC BN_ULONG mods[NUMPRIMES]; 351 BN_ULONG mods[NUMPRIMES];
271 BN_ULONG delta,d; 352 BN_ULONG delta,d;
272 353
273again: 354again:
@@ -285,7 +366,7 @@ again:
285 d=delta; 366 d=delta;
286 delta+=2; 367 delta+=2;
287 /* perhaps need to check for overflow of 368 /* perhaps need to check for overflow of
288 * delta (but delta can be upto 2^32) 369 * delta (but delta can be up to 2^32)
289 * 21-May-98 eay - added overflow check */ 370 * 21-May-98 eay - added overflow check */
290 if (delta < d) goto again; 371 if (delta < d) goto again;
291 goto loop; 372 goto loop;
@@ -301,7 +382,8 @@ static int probable_prime_dh(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem,
301 int i,ret=0; 382 int i,ret=0;
302 BIGNUM *t1; 383 BIGNUM *t1;
303 384
304 t1= &(ctx->bn[ctx->tos++]); 385 BN_CTX_start(ctx);
386 if ((t1 = BN_CTX_get(ctx)) == NULL) goto err;
305 387
306 if (!BN_rand(rnd,bits,0,1)) goto err; 388 if (!BN_rand(rnd,bits,0,1)) goto err;
307 389
@@ -327,20 +409,22 @@ static int probable_prime_dh(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem,
327 } 409 }
328 ret=1; 410 ret=1;
329err: 411err:
330 ctx->tos--; 412 BN_CTX_end(ctx);
331 return(ret); 413 return(ret);
332 } 414 }
333 415
334static int probable_prime_dh_strong(BIGNUM *p, int bits, BIGNUM *padd, 416static int probable_prime_dh_safe(BIGNUM *p, int bits, BIGNUM *padd,
335 BIGNUM *rem, BN_CTX *ctx) 417 BIGNUM *rem, BN_CTX *ctx)
336 { 418 {
337 int i,ret=0; 419 int i,ret=0;
338 BIGNUM *t1,*qadd=NULL,*q=NULL; 420 BIGNUM *t1,*qadd,*q;
339 421
340 bits--; 422 bits--;
341 t1= &(ctx->bn[ctx->tos++]); 423 BN_CTX_start(ctx);
342 q= &(ctx->bn[ctx->tos++]); 424 t1 = BN_CTX_get(ctx);
343 qadd= &(ctx->bn[ctx->tos++]); 425 q = BN_CTX_get(ctx);
426 qadd = BN_CTX_get(ctx);
427 if (qadd == NULL) goto err;
344 428
345 if (!BN_rshift1(qadd,padd)) goto err; 429 if (!BN_rshift1(qadd,padd)) goto err;
346 430
@@ -376,72 +460,6 @@ static int probable_prime_dh_strong(BIGNUM *p, int bits, BIGNUM *padd,
376 } 460 }
377 ret=1; 461 ret=1;
378err: 462err:
379 ctx->tos-=3; 463 BN_CTX_end(ctx);
380 return(ret);
381 }
382
383#if 0
384static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx)
385 {
386 int k,i,nb,ret= -1;
387 BIGNUM *d,*dd,*tmp;
388 BIGNUM *d1,*d2,*x,*n1,*inv;
389
390 d1= &(ctx->bn[ctx->tos]);
391 d2= &(ctx->bn[ctx->tos+1]);
392 x= &(ctx->bn[ctx->tos+2]);
393 n1= &(ctx->bn[ctx->tos+3]);
394 inv=&(ctx->bn[ctx->tos+4]);
395 ctx->tos+=5;
396
397 d=d1;
398 dd=d2;
399 if (!BN_one(d)) goto err;
400 if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */
401 k=BN_num_bits(n1);
402
403 /* i=BN_num_bits(n); */
404#ifdef RECP_MUL_MOD
405 nb=BN_reciprocal(inv,n,ctx); /**/
406 if (nb == -1) goto err;
407#endif
408
409 for (i=k-1; i>=0; i--)
410 {
411 if (BN_copy(x,d) == NULL) goto err;
412#ifndef RECP_MUL_MOD
413 if (!BN_mod_mul(dd,d,d,n,ctx)) goto err;
414#else
415 if (!BN_mod_mul_reciprocal(dd,d,d,n,inv,nb,ctx)) goto err;
416#endif
417 if ( BN_is_one(dd) &&
418 !BN_is_one(x) &&
419 (BN_cmp(x,n1) != 0))
420 {
421 ret=1;
422 goto err;
423 }
424 if (BN_is_bit_set(n1,i))
425 {
426#ifndef RECP_MUL_MOD
427 if (!BN_mod_mul(d,dd,a,n,ctx)) goto err;
428#else
429 if (!BN_mod_mul_reciprocal(d,dd,a,n,inv,nb,ctx)) goto err;
430#endif
431 }
432 else
433 {
434 tmp=d;
435 d=dd;
436 dd=tmp;
437 }
438 }
439 if (BN_is_one(d))
440 i=0;
441 else i=1;
442 ret=i;
443err:
444 ctx->tos-=5;
445 return(ret); 464 return(ret);
446 } 465 }
447#endif
diff --git a/src/lib/libcrypto/bn/bn_prime.h b/src/lib/libcrypto/bn/bn_prime.h
index 6fce0210cd..b7cf9a9bfe 100644
--- a/src/lib/libcrypto/bn/bn_prime.h
+++ b/src/lib/libcrypto/bn/bn_prime.h
@@ -1,4 +1,4 @@
1/* crypto/bn/bn_prime.h */ 1/* Auto generated by bn_prime.pl */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -61,7 +61,7 @@
61#else 61#else
62#define NUMPRIMES 54 62#define NUMPRIMES 54
63#endif 63#endif
64static unsigned int primes[NUMPRIMES]= 64static const unsigned int primes[NUMPRIMES]=
65 { 65 {
66 2, 3, 5, 7, 11, 13, 17, 19, 66 2, 3, 5, 7, 11, 13, 17, 19,
67 23, 29, 31, 37, 41, 43, 47, 53, 67 23, 29, 31, 37, 41, 43, 47, 53,
diff --git a/src/lib/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl
index 979385a334..9fc3765486 100644
--- a/src/lib/libcrypto/bn/bn_prime.pl
+++ b/src/lib/libcrypto/bn/bn_prime.pl
@@ -18,13 +18,74 @@ loop: while ($#primes < $num-1)
18 push(@primes,$p); 18 push(@primes,$p);
19 } 19 }
20 20
21print <<"EOF"; 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;
22/* Auto generated by bn_prime.pl */ 33/* Auto generated by bn_prime.pl */
23/* Copyright (C) 1995-1997 Eric Young (eay\@mincom.oz.au). 34/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
24 * All rights reserved. 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 *
25 * Copyright remains Eric Young's, and as such any Copyright notices in 48 * Copyright remains Eric Young's, and as such any Copyright notices in
26 * the code are not to be removed. 49 * the code are not to be removed.
27 * See the COPYRIGHT file in the SSLeay distribution for more details. 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.]
28 */ 89 */
29 90
30EOF 91EOF
@@ -43,7 +104,7 @@ printf "#define NUMPRIMES %d\n",$num;
43printf "#else\n"; 104printf "#else\n";
44printf "#define NUMPRIMES %d\n",$eight; 105printf "#define NUMPRIMES %d\n",$eight;
45printf "#endif\n"; 106printf "#endif\n";
46print "static unsigned int primes[NUMPRIMES]=\n\t{\n\t"; 107print "static const unsigned int primes[NUMPRIMES]=\n\t{\n\t";
47$init=0; 108$init=0;
48for ($i=0; $i <= $#primes; $i++) 109for ($i=0; $i <= $#primes; $i++)
49 { 110 {
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
index 2f5ab2617b..782a96e7e0 100644
--- a/src/lib/libcrypto/bn/bn_print.c
+++ b/src/lib/libcrypto/bn/bn_print.c
@@ -137,7 +137,7 @@ char *BN_bn2dec(const BIGNUM *a)
137 } 137 }
138 lp--; 138 lp--;
139 /* We now have a series of blocks, BN_DEC_NUM chars 139 /* We now have a series of blocks, BN_DEC_NUM chars
140 * in length, where the last one needs trucation. 140 * in length, where the last one needs truncation.
141 * The blocks need to be reversed in order. */ 141 * The blocks need to be reversed in order. */
142 sprintf(p,BN_DEC_FMT1,*lp); 142 sprintf(p,BN_DEC_FMT1,*lp);
143 while (*p) p++; 143 while (*p) p++;
@@ -171,7 +171,7 @@ int BN_hex2bn(BIGNUM **bn, const char *a)
171 num=i+neg; 171 num=i+neg;
172 if (bn == NULL) return(num); 172 if (bn == NULL) return(num);
173 173
174 /* a is the start of the hex digets, and it is 'i' long */ 174 /* a is the start of the hex digits, and it is 'i' long */
175 if (*bn == NULL) 175 if (*bn == NULL)
176 { 176 {
177 if ((ret=BN_new()) == NULL) return(0); 177 if ((ret=BN_new()) == NULL) return(0);
@@ -185,7 +185,7 @@ int BN_hex2bn(BIGNUM **bn, const char *a)
185 /* i is the number of hex digests; */ 185 /* i is the number of hex digests; */
186 if (bn_expand(ret,i*4) == NULL) goto err; 186 if (bn_expand(ret,i*4) == NULL) goto err;
187 187
188 j=i; /* least significate 'hex' */ 188 j=i; /* least significant 'hex' */
189 m=0; 189 m=0;
190 h=0; 190 h=0;
191 while (j > 0) 191 while (j > 0)
@@ -236,8 +236,8 @@ int BN_dec2bn(BIGNUM **bn, const char *a)
236 num=i+neg; 236 num=i+neg;
237 if (bn == NULL) return(num); 237 if (bn == NULL) return(num);
238 238
239 /* a is the start of the digets, and it is 'i' long. 239 /* a is the start of the digits, and it is 'i' long.
240 * We chop it into BN_DEC_NUM digets at a time */ 240 * We chop it into BN_DEC_NUM digits at a time */
241 if (*bn == NULL) 241 if (*bn == NULL)
242 { 242 {
243 if ((ret=BN_new()) == NULL) return(0); 243 if ((ret=BN_new()) == NULL) return(0);
@@ -278,9 +278,8 @@ err:
278 } 278 }
279 279
280#ifndef NO_BIO 280#ifndef NO_BIO
281
282#ifndef NO_FP_API 281#ifndef NO_FP_API
283int BN_print_fp(FILE *fp, BIGNUM *a) 282int BN_print_fp(FILE *fp, const BIGNUM *a)
284 { 283 {
285 BIO *b; 284 BIO *b;
286 int ret; 285 int ret;
@@ -319,5 +318,15 @@ int BN_print(BIO *bp, const BIGNUM *a)
319end: 318end:
320 return(ret); 319 return(ret);
321 } 320 }
321#endif
322 322
323#ifdef BN_DEBUG
324void bn_dump1(FILE *o, const char *a, BN_ULONG *b,int n)
325 {
326 int i;
327 fprintf(o, "%s=", a);
328 for (i=n-1;i>=0;i--)
329 fprintf(o, "%08lX", b[i]); /* assumes 32-bit BN_ULONG */
330 fprintf(o, "\n");
331 }
323#endif 332#endif
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
index 91b8e34ae6..943712c15b 100644
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -62,7 +62,7 @@
62#include "bn_lcl.h" 62#include "bn_lcl.h"
63#include <openssl/rand.h> 63#include <openssl/rand.h>
64 64
65int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) 65static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
66 { 66 {
67 unsigned char *buf=NULL; 67 unsigned char *buf=NULL;
68 int ret=0,bit,bytes,mask; 68 int ret=0,bit,bytes,mask;
@@ -81,9 +81,19 @@ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
81 81
82 /* make a random number and set the top and bottom bits */ 82 /* make a random number and set the top and bottom bits */
83 time(&tim); 83 time(&tim);
84 RAND_seed(&tim,sizeof(tim)); 84 RAND_add(&tim,sizeof(tim),0);
85
86 if (pseudorand)
87 {
88 if (RAND_pseudo_bytes(buf, bytes) == -1)
89 goto err;
90 }
91 else
92 {
93 if (RAND_bytes(buf, bytes) <= 0)
94 goto err;
95 }
85 96
86 RAND_bytes(buf,(int)bytes);
87 if (top) 97 if (top)
88 { 98 {
89 if (bit == 0) 99 if (bit == 0)
@@ -115,3 +125,12 @@ err:
115 return(ret); 125 return(ret);
116 } 126 }
117 127
128int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
129 {
130 return bnrand(0, rnd, bits, top, bottom);
131 }
132
133int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
134 {
135 return bnrand(1, rnd, bits, top, bottom);
136 }
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
index c1b0e230ea..a8796bd0aa 100644
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ b/src/lib/libcrypto/bn/bn_recp.c
@@ -106,7 +106,8 @@ int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,
106 int ret=0; 106 int ret=0;
107 BIGNUM *a; 107 BIGNUM *a;
108 108
109 a= &(ctx->bn[ctx->tos++]); 109 BN_CTX_start(ctx);
110 if ((a = BN_CTX_get(ctx)) == NULL) goto err;
110 if (y != NULL) 111 if (y != NULL)
111 { 112 {
112 if (x == y) 113 if (x == y)
@@ -120,33 +121,34 @@ int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,
120 BN_div_recp(NULL,r,a,recp,ctx); 121 BN_div_recp(NULL,r,a,recp,ctx);
121 ret=1; 122 ret=1;
122err: 123err:
123 ctx->tos--; 124 BN_CTX_end(ctx);
124 return(ret); 125 return(ret);
125 } 126 }
126 127
127int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp, 128int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
128 BN_CTX *ctx) 129 BN_CTX *ctx)
129 { 130 {
130 int i,j,tos,ret=0,ex; 131 int i,j,ret=0;
131 BIGNUM *a,*b,*d,*r; 132 BIGNUM *a,*b,*d,*r;
132 133
133 tos=ctx->tos; 134 BN_CTX_start(ctx);
134 a= &(ctx->bn[ctx->tos++]); 135 a=BN_CTX_get(ctx);
135 b= &(ctx->bn[ctx->tos++]); 136 b=BN_CTX_get(ctx);
136 if (dv != NULL) 137 if (dv != NULL)
137 d=dv; 138 d=dv;
138 else 139 else
139 d= &(ctx->bn[ctx->tos++]); 140 d=BN_CTX_get(ctx);
140 if (rem != NULL) 141 if (rem != NULL)
141 r=rem; 142 r=rem;
142 else 143 else
143 r= &(ctx->bn[ctx->tos++]); 144 r=BN_CTX_get(ctx);
145 if (a == NULL || b == NULL || d == NULL || r == NULL) goto err;
144 146
145 if (BN_ucmp(m,&(recp->N)) < 0) 147 if (BN_ucmp(m,&(recp->N)) < 0)
146 { 148 {
147 BN_zero(d); 149 BN_zero(d);
148 BN_copy(r,m); 150 BN_copy(r,m);
149 ctx->tos=tos; 151 BN_CTX_end(ctx);
150 return(1); 152 return(1);
151 } 153 }
152 154
@@ -157,33 +159,24 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
157 */ 159 */
158 i=BN_num_bits(m); 160 i=BN_num_bits(m);
159 161
160 j=recp->num_bits*2; 162 j=recp->num_bits<<1;
161 if (j > i) 163 if (j>i) i=j;
162 { 164 j>>=1;
163 i=j;
164 ex=0;
165 }
166 else
167 {
168 ex=(i-j)/2;
169 }
170
171 j=i/2;
172 165
173 if (i != recp->shift) 166 if (i != recp->shift)
174 recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N), 167 recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
175 i,ctx); 168 i,ctx);
176 169
177 if (!BN_rshift(a,m,j-ex)) goto err; 170 if (!BN_rshift(a,m,j)) goto err;
178 if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err; 171 if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;
179 if (!BN_rshift(d,b,j+ex)) goto err; 172 if (!BN_rshift(d,b,i-j)) goto err;
180 d->neg=0; 173 d->neg=0;
181 if (!BN_mul(b,&(recp->N),d,ctx)) goto err; 174 if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
182 if (!BN_usub(r,m,b)) goto err; 175 if (!BN_usub(r,m,b)) goto err;
183 r->neg=0; 176 r->neg=0;
184 177
185 j=0;
186#if 1 178#if 1
179 j=0;
187 while (BN_ucmp(r,&(recp->N)) >= 0) 180 while (BN_ucmp(r,&(recp->N)) >= 0)
188 { 181 {
189 if (j++ > 2) 182 if (j++ > 2)
@@ -200,7 +193,7 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
200 d->neg=m->neg^recp->N.neg; 193 d->neg=m->neg^recp->N.neg;
201 ret=1; 194 ret=1;
202err: 195err:
203 ctx->tos=tos; 196 BN_CTX_end(ctx);
204 return(ret); 197 return(ret);
205 } 198 }
206 199
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
index 12cce4d7ce..fe00c5f69a 100644
--- a/src/lib/libcrypto/bn/bn_sqr.c
+++ b/src/lib/libcrypto/bn/bn_sqr.c
@@ -65,14 +65,13 @@
65int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx) 65int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx)
66 { 66 {
67 int max,al; 67 int max,al;
68 int ret = 0;
68 BIGNUM *tmp,*rr; 69 BIGNUM *tmp,*rr;
69 70
70#ifdef BN_COUNT 71#ifdef BN_COUNT
71printf("BN_sqr %d * %d\n",a->top,a->top); 72printf("BN_sqr %d * %d\n",a->top,a->top);
72#endif 73#endif
73 bn_check_top(a); 74 bn_check_top(a);
74 tmp= &(ctx->bn[ctx->tos]);
75 rr=(a != r)?r: (&ctx->bn[ctx->tos+1]);
76 75
77 al=a->top; 76 al=a->top;
78 if (al <= 0) 77 if (al <= 0)
@@ -81,8 +80,13 @@ printf("BN_sqr %d * %d\n",a->top,a->top);
81 return(1); 80 return(1);
82 } 81 }
83 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
84 max=(al+al); 88 max=(al+al);
85 if (bn_wexpand(rr,max+1) == NULL) return(0); 89 if (bn_wexpand(rr,max+1) == NULL) goto err;
86 90
87 r->neg=0; 91 r->neg=0;
88 if (al == 4) 92 if (al == 4)
@@ -120,18 +124,18 @@ printf("BN_sqr %d * %d\n",a->top,a->top);
120 k=j+j; 124 k=j+j;
121 if (al == j) 125 if (al == j)
122 { 126 {
123 if (bn_wexpand(a,k*2) == NULL) return(0); 127 if (bn_wexpand(a,k*2) == NULL) goto err;
124 if (bn_wexpand(tmp,k*2) == NULL) return(0); 128 if (bn_wexpand(tmp,k*2) == NULL) goto err;
125 bn_sqr_recursive(rr->d,a->d,al,tmp->d); 129 bn_sqr_recursive(rr->d,a->d,al,tmp->d);
126 } 130 }
127 else 131 else
128 { 132 {
129 if (bn_wexpand(tmp,max) == NULL) return(0); 133 if (bn_wexpand(tmp,max) == NULL) goto err;
130 bn_sqr_normal(rr->d,a->d,al,tmp->d); 134 bn_sqr_normal(rr->d,a->d,al,tmp->d);
131 } 135 }
132 } 136 }
133#else 137#else
134 if (bn_wexpand(tmp,max) == NULL) return(0); 138 if (bn_wexpand(tmp,max) == NULL) goto err;
135 bn_sqr_normal(rr->d,a->d,al,tmp->d); 139 bn_sqr_normal(rr->d,a->d,al,tmp->d);
136#endif 140#endif
137 } 141 }
@@ -139,7 +143,10 @@ printf("BN_sqr %d * %d\n",a->top,a->top);
139 rr->top=max; 143 rr->top=max;
140 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; 144 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
141 if (rr != r) BN_copy(r,rr); 145 if (rr != r) BN_copy(r,rr);
142 return(1); 146 ret = 1;
147 err:
148 BN_CTX_end(ctx);
149 return(ret);
143 } 150 }
144 151
145/* tmp must have 2*n words */ 152/* tmp must have 2*n words */
@@ -185,7 +192,7 @@ void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)
185 * n must be a power of 2. 192 * n must be a power of 2.
186 * We multiply and return the result. 193 * We multiply and return the result.
187 * t must be 2*n words in size 194 * t must be 2*n words in size
188 * We calulate 195 * We calculate
189 * a[0]*b[0] 196 * a[0]*b[0]
190 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) 197 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
191 * a[1]*b[1] 198 * a[1]*b[1]
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
index c0cfbc6797..73157a7d43 100644
--- a/src/lib/libcrypto/bn/bn_word.c
+++ b/src/lib/libcrypto/bn/bn_word.c
@@ -60,7 +60,7 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w) 63BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
64 { 64 {
65#ifndef BN_LLONG 65#ifndef BN_LLONG
66 BN_ULONG ret=0; 66 BN_ULONG ret=0;
diff --git a/src/lib/libcrypto/bn/bnspeed.c b/src/lib/libcrypto/bn/bnspeed.c
index 0922aa3e16..20fc7e08ff 100644
--- a/src/lib/libcrypto/bn/bnspeed.c
+++ b/src/lib/libcrypto/bn/bnspeed.c
@@ -1,3 +1,5 @@
1/* unused */
2
1/* crypto/bn/bnspeed.c */ 3/* crypto/bn/bnspeed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 5 * All rights reserved.
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c
index df4b81f5b2..41c22f5954 100644
--- a/src/lib/libcrypto/bn/bntest.c
+++ b/src/lib/libcrypto/bn/bntest.c
@@ -72,6 +72,10 @@
72#include "../bio/bss_file.c" 72#include "../bio/bss_file.c"
73#endif 73#endif
74 74
75const int num0 = 100; /* number of tests */
76const int num1 = 50; /* additional tests for some functions */
77const int num2 = 5; /* number of tests for slow functions */
78
75int test_add(BIO *bp); 79int test_add(BIO *bp);
76int test_sub(BIO *bp); 80int test_sub(BIO *bp);
77int test_lshift1(BIO *bp); 81int test_lshift1(BIO *bp);
@@ -95,15 +99,33 @@ static int results=0;
95#include "bss_file.c" 99#include "bss_file.c"
96#endif 100#endif
97 101
98static unsigned char lst1[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9" 102static unsigned char lst[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9"
99"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0"; 103"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0";
100 104
105static const char rnd_seed[] = "string to make the random number generator think it has entropy";
106
107static void message(BIO *out, char *m)
108 {
109 fprintf(stderr, "test %s\n", m);
110#if defined(linux) || defined(__FreeBSD__) /* can we use GNU bc features? */
111 BIO_puts(out, "print \"test ");
112 BIO_puts(out, m);
113 BIO_puts(out, "\\n\"\n");
114#endif
115 }
116
101int main(int argc, char *argv[]) 117int main(int argc, char *argv[])
102 { 118 {
103 BN_CTX *ctx; 119 BN_CTX *ctx;
104 BIO *out; 120 BIO *out;
105 char *outfile=NULL; 121 char *outfile=NULL;
106 122
123 results = 0;
124
125 RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't
126 * even check its return value
127 * (which we should) */
128
107 argc--; 129 argc--;
108 argv++; 130 argv++;
109 while (argc >= 1) 131 while (argc >= 1)
@@ -141,78 +163,81 @@ int main(int argc, char *argv[])
141 if (!results) 163 if (!results)
142 BIO_puts(out,"obase=16\nibase=16\n"); 164 BIO_puts(out,"obase=16\nibase=16\n");
143 165
144 fprintf(stderr,"test BN_add\n"); 166 message(out,"BN_add");
145 if (!test_add(out)) goto err; 167 if (!test_add(out)) goto err;
146 fflush(stdout); 168 BIO_flush(out);
147 169
148 fprintf(stderr,"test BN_sub\n"); 170 message(out,"BN_sub");
149 if (!test_sub(out)) goto err; 171 if (!test_sub(out)) goto err;
150 fflush(stdout); 172 BIO_flush(out);
151 173
152 fprintf(stderr,"test BN_lshift1\n"); 174 message(out,"BN_lshift1");
153 if (!test_lshift1(out)) goto err; 175 if (!test_lshift1(out)) goto err;
154 fflush(stdout); 176 BIO_flush(out);
155 177
156 fprintf(stderr,"test BN_lshift (fixed)\n"); 178 message(out,"BN_lshift (fixed)");
157 if (!test_lshift(out,ctx,BN_bin2bn(lst1,sizeof(lst1)-1,NULL))) 179 if (!test_lshift(out,ctx,BN_bin2bn(lst,sizeof(lst)-1,NULL)))
158 goto err; 180 goto err;
159 fflush(stdout); 181 BIO_flush(out);
160 182
161 fprintf(stderr,"test BN_lshift\n"); 183 message(out,"BN_lshift");
162 if (!test_lshift(out,ctx,NULL)) goto err; 184 if (!test_lshift(out,ctx,NULL)) goto err;
163 fflush(stdout); 185 BIO_flush(out);
164 186
165 fprintf(stderr,"test BN_rshift1\n"); 187 message(out,"BN_rshift1");
166 if (!test_rshift1(out)) goto err; 188 if (!test_rshift1(out)) goto err;
167 fflush(stdout); 189 BIO_flush(out);
168 190
169 fprintf(stderr,"test BN_rshift\n"); 191 message(out,"BN_rshift");
170 if (!test_rshift(out,ctx)) goto err; 192 if (!test_rshift(out,ctx)) goto err;
171 fflush(stdout); 193 BIO_flush(out);
172 194
173 fprintf(stderr,"test BN_sqr\n"); 195 message(out,"BN_sqr");
174 if (!test_sqr(out,ctx)) goto err; 196 if (!test_sqr(out,ctx)) goto err;
175 fflush(stdout); 197 BIO_flush(out);
176 198
177 fprintf(stderr,"test BN_mul\n"); 199 message(out,"BN_mul");
178 if (!test_mul(out)) goto err; 200 if (!test_mul(out)) goto err;
179 fflush(stdout); 201 BIO_flush(out);
180 202
181 fprintf(stderr,"test BN_div\n"); 203 message(out,"BN_div");
182 if (!test_div(out,ctx)) goto err; 204 if (!test_div(out,ctx)) goto err;
183 fflush(stdout); 205 BIO_flush(out);
184 206
185 fprintf(stderr,"test BN_div_recp\n"); 207 message(out,"BN_div_recp");
186 if (!test_div_recp(out,ctx)) goto err; 208 if (!test_div_recp(out,ctx)) goto err;
187 fflush(stdout); 209 BIO_flush(out);
188 210
189 fprintf(stderr,"test BN_mod\n"); 211 message(out,"BN_mod");
190 if (!test_mod(out,ctx)) goto err; 212 if (!test_mod(out,ctx)) goto err;
191 fflush(stdout); 213 BIO_flush(out);
192 214
193 fprintf(stderr,"test BN_mod_mul\n"); 215 message(out,"BN_mod_mul");
194 if (!test_mod_mul(out,ctx)) goto err; 216 if (!test_mod_mul(out,ctx)) goto err;
195 fflush(stdout); 217 BIO_flush(out);
196 218
197/* 219 message(out,"BN_mont");
198 fprintf(stderr,"test BN_mont\n");
199 if (!test_mont(out,ctx)) goto err; 220 if (!test_mont(out,ctx)) goto err;
200 fflush(stdout); 221 BIO_flush(out);
201*/ 222
202 fprintf(stderr,"test BN_mod_exp\n"); 223 message(out,"BN_mod_exp");
203 if (!test_mod_exp(out,ctx)) goto err; 224 if (!test_mod_exp(out,ctx)) goto err;
204 fflush(stdout); 225 BIO_flush(out);
205 226
206 fprintf(stderr,"test BN_exp\n"); 227 message(out,"BN_exp");
207 if (!test_exp(out,ctx)) goto err; 228 if (!test_exp(out,ctx)) goto err;
208 fflush(stdout); 229 BIO_flush(out);
230
231 BN_CTX_free(ctx);
232 BIO_free(out);
209 233
210/**/ 234/**/
211 exit(0); 235 exit(0);
212err: 236err:
213 BIO_puts(out,"1\n"); /* make sure bc fails if we are piping to it */ 237 BIO_puts(out,"1\n"); /* make sure bc fails if we are piping to it */
238 BIO_flush(out);
214 ERR_load_crypto_strings(); 239 ERR_load_crypto_strings();
215 ERR_print_errors(out); 240 ERR_print_errors_fp(stderr);
216 exit(1); 241 exit(1);
217 return(1); 242 return(1);
218 } 243 }
@@ -228,7 +253,7 @@ int test_add(BIO *bp)
228 BN_init(&c); 253 BN_init(&c);
229 254
230 BN_rand(&a,512,0,0); 255 BN_rand(&a,512,0,0);
231 for (i=0; i<100; i++) 256 for (i=0; i<num0; i++)
232 { 257 {
233 BN_rand(&b,450+i,0,0); 258 BN_rand(&b,450+i,0,0);
234 a.neg=rand_neg(); 259 a.neg=rand_neg();
@@ -255,7 +280,7 @@ int test_add(BIO *bp)
255 BN_add(&c,&c,&a); 280 BN_add(&c,&c,&a);
256 if(!BN_is_zero(&c)) 281 if(!BN_is_zero(&c))
257 { 282 {
258 BIO_puts(bp,"Add test failed!\n"); 283 fprintf(stderr,"Add test failed!\n");
259 return 0; 284 return 0;
260 } 285 }
261 } 286 }
@@ -275,12 +300,21 @@ int test_sub(BIO *bp)
275 BN_init(&b); 300 BN_init(&b);
276 BN_init(&c); 301 BN_init(&c);
277 302
278 BN_rand(&a,512,0,0); 303 for (i=0; i<num0+num1; i++)
279 for (i=0; i<100; i++)
280 { 304 {
281 BN_rand(&b,400+i,0,0); 305 if (i < num1)
282 a.neg=rand_neg(); 306 {
283 b.neg=rand_neg(); 307 BN_rand(&a,512,0,0);
308 BN_copy(&b,&a);
309 if (BN_set_bit(&a,i)==0) return(0);
310 BN_add_word(&b,i);
311 }
312 else
313 {
314 BN_rand(&b,400+i-num1,0,0);
315 a.neg=rand_neg();
316 b.neg=rand_neg();
317 }
284 if (bp == NULL) 318 if (bp == NULL)
285 for (j=0; j<10000; j++) 319 for (j=0; j<10000; j++)
286 BN_sub(&c,&a,&b); 320 BN_sub(&c,&a,&b);
@@ -301,7 +335,7 @@ int test_sub(BIO *bp)
301 BN_sub(&c,&c,&a); 335 BN_sub(&c,&c,&a);
302 if(!BN_is_zero(&c)) 336 if(!BN_is_zero(&c))
303 { 337 {
304 BIO_puts(bp,"Subtract test failed!\n"); 338 fprintf(stderr,"Subtract test failed!\n");
305 return 0; 339 return 0;
306 } 340 }
307 } 341 }
@@ -323,10 +357,17 @@ int test_div(BIO *bp, BN_CTX *ctx)
323 BN_init(&d); 357 BN_init(&d);
324 BN_init(&e); 358 BN_init(&e);
325 359
326 BN_rand(&a,400,0,0); 360 for (i=0; i<num0+num1; i++)
327 for (i=0; i<100; i++)
328 { 361 {
329 BN_rand(&b,50+i,0,0); 362 if (i < num1)
363 {
364 BN_rand(&a,400,0,0);
365 BN_copy(&b,&a);
366 BN_lshift(&a,&a,i);
367 BN_add_word(&a,i);
368 }
369 else
370 BN_rand(&b,50+3*(i-num1),0,0);
330 a.neg=rand_neg(); 371 a.neg=rand_neg();
331 b.neg=rand_neg(); 372 b.neg=rand_neg();
332 if (bp == NULL) 373 if (bp == NULL)
@@ -360,7 +401,7 @@ int test_div(BIO *bp, BN_CTX *ctx)
360 BN_sub(&d,&d,&a); 401 BN_sub(&d,&d,&a);
361 if(!BN_is_zero(&d)) 402 if(!BN_is_zero(&d))
362 { 403 {
363 BIO_puts(bp,"Division test failed!\n"); 404 fprintf(stderr,"Division test failed!\n");
364 return 0; 405 return 0;
365 } 406 }
366 } 407 }
@@ -386,10 +427,17 @@ int test_div_recp(BIO *bp, BN_CTX *ctx)
386 BN_init(&d); 427 BN_init(&d);
387 BN_init(&e); 428 BN_init(&e);
388 429
389 BN_rand(&a,400,0,0); 430 for (i=0; i<num0+num1; i++)
390 for (i=0; i<100; i++)
391 { 431 {
392 BN_rand(&b,50+i,0,0); 432 if (i < num1)
433 {
434 BN_rand(&a,400,0,0);
435 BN_copy(&b,&a);
436 BN_lshift(&a,&a,i);
437 BN_add_word(&a,i);
438 }
439 else
440 BN_rand(&b,50+3*(i-num1),0,0);
393 a.neg=rand_neg(); 441 a.neg=rand_neg();
394 b.neg=rand_neg(); 442 b.neg=rand_neg();
395 BN_RECP_CTX_set(&recp,&b,ctx); 443 BN_RECP_CTX_set(&recp,&b,ctx);
@@ -424,7 +472,12 @@ int test_div_recp(BIO *bp, BN_CTX *ctx)
424 BN_sub(&d,&d,&a); 472 BN_sub(&d,&d,&a);
425 if(!BN_is_zero(&d)) 473 if(!BN_is_zero(&d))
426 { 474 {
427 BIO_puts(bp,"Reciprocal division test failed!\n"); 475 fprintf(stderr,"Reciprocal division test failed!\n");
476 fprintf(stderr,"a=");
477 BN_print_fp(stderr,&a);
478 fprintf(stderr,"\nb=");
479 BN_print_fp(stderr,&b);
480 fprintf(stderr,"\n");
428 return 0; 481 return 0;
429 } 482 }
430 } 483 }
@@ -451,11 +504,15 @@ int test_mul(BIO *bp)
451 BN_init(&d); 504 BN_init(&d);
452 BN_init(&e); 505 BN_init(&e);
453 506
454 BN_rand(&a,200,0,0); 507 for (i=0; i<num0+num1; i++)
455 for (i=0; i<100; i++)
456 { 508 {
457 BN_rand(&b,250+i,0,0); 509 if (i <= num1)
458 BN_rand(&b,200,0,0); 510 {
511 BN_rand(&a,100,0,0);
512 BN_rand(&b,100,0,0);
513 }
514 else
515 BN_rand(&b,i-num1,0,0);
459 a.neg=rand_neg(); 516 a.neg=rand_neg();
460 b.neg=rand_neg(); 517 b.neg=rand_neg();
461 if (bp == NULL) 518 if (bp == NULL)
@@ -478,7 +535,7 @@ int test_mul(BIO *bp)
478 BN_sub(&d,&d,&b); 535 BN_sub(&d,&d,&b);
479 if(!BN_is_zero(&d) || !BN_is_zero(&e)) 536 if(!BN_is_zero(&d) || !BN_is_zero(&e))
480 { 537 {
481 BIO_puts(bp,"Multiplication test failed!\n"); 538 fprintf(stderr,"Multiplication test failed!\n");
482 return 0; 539 return 0;
483 } 540 }
484 } 541 }
@@ -502,7 +559,7 @@ int test_sqr(BIO *bp, BN_CTX *ctx)
502 BN_init(&d); 559 BN_init(&d);
503 BN_init(&e); 560 BN_init(&e);
504 561
505 for (i=0; i<40; i++) 562 for (i=0; i<num0; i++)
506 { 563 {
507 BN_rand(&a,40+i*10,0,0); 564 BN_rand(&a,40+i*10,0,0);
508 a.neg=rand_neg(); 565 a.neg=rand_neg();
@@ -526,7 +583,7 @@ int test_sqr(BIO *bp, BN_CTX *ctx)
526 BN_sub(&d,&d,&a); 583 BN_sub(&d,&d,&a);
527 if(!BN_is_zero(&d) || !BN_is_zero(&e)) 584 if(!BN_is_zero(&d) || !BN_is_zero(&e))
528 { 585 {
529 BIO_puts(bp,"Square test failed!\n"); 586 fprintf(stderr,"Square test failed!\n");
530 return 0; 587 return 0;
531 } 588 }
532 } 589 }
@@ -557,9 +614,13 @@ int test_mont(BIO *bp, BN_CTX *ctx)
557 614
558 BN_rand(&a,100,0,0); /**/ 615 BN_rand(&a,100,0,0); /**/
559 BN_rand(&b,100,0,0); /**/ 616 BN_rand(&b,100,0,0); /**/
560 for (i=0; i<10; i++) 617 for (i=0; i<num2; i++)
561 { 618 {
562 BN_rand(&n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/ 619 int bits = (200*(i+1))/num2;
620
621 if (bits == 0)
622 continue;
623 BN_rand(&n,bits,0,1);
563 BN_MONT_CTX_set(mont,&n,ctx); 624 BN_MONT_CTX_set(mont,&n,ctx);
564 625
565 BN_to_montgomery(&A,&a,mont,ctx); 626 BN_to_montgomery(&A,&a,mont,ctx);
@@ -594,7 +655,7 @@ BN_num_bits(mont->N));
594 BN_sub(&d,&d,&A); 655 BN_sub(&d,&d,&A);
595 if(!BN_is_zero(&d)) 656 if(!BN_is_zero(&d))
596 { 657 {
597 BIO_puts(bp,"Montgomery multiplication test failed!\n"); 658 fprintf(stderr,"Montgomery multiplication test failed!\n");
598 return 0; 659 return 0;
599 } 660 }
600 } 661 }
@@ -622,7 +683,7 @@ int test_mod(BIO *bp, BN_CTX *ctx)
622 e=BN_new(); 683 e=BN_new();
623 684
624 BN_rand(a,1024,0,0); /**/ 685 BN_rand(a,1024,0,0); /**/
625 for (i=0; i<20; i++) 686 for (i=0; i<num0; i++)
626 { 687 {
627 BN_rand(b,450+i*10,0,0); /**/ 688 BN_rand(b,450+i*10,0,0); /**/
628 a->neg=rand_neg(); 689 a->neg=rand_neg();
@@ -647,7 +708,7 @@ int test_mod(BIO *bp, BN_CTX *ctx)
647 BN_sub(e,e,c); 708 BN_sub(e,e,c);
648 if(!BN_is_zero(e)) 709 if(!BN_is_zero(e))
649 { 710 {
650 BIO_puts(bp,"Modulo test failed!\n"); 711 fprintf(stderr,"Modulo test failed!\n");
651 return 0; 712 return 0;
652 } 713 }
653 } 714 }
@@ -671,10 +732,10 @@ int test_mod_mul(BIO *bp, BN_CTX *ctx)
671 e=BN_new(); 732 e=BN_new();
672 733
673 BN_rand(c,1024,0,0); /**/ 734 BN_rand(c,1024,0,0); /**/
674 for (i=0; i<10; i++) 735 for (i=0; i<num0; i++)
675 { 736 {
676 BN_rand(a,475+i*10,0,0); /**/ 737 BN_rand(a,475+i*10,0,0); /**/
677 BN_rand(b,425+i*10,0,0); /**/ 738 BN_rand(b,425+i*11,0,0); /**/
678 a->neg=rand_neg(); 739 a->neg=rand_neg();
679 b->neg=rand_neg(); 740 b->neg=rand_neg();
680 /* if (bp == NULL) 741 /* if (bp == NULL)
@@ -709,7 +770,7 @@ int test_mod_mul(BIO *bp, BN_CTX *ctx)
709 BN_div(a,b,d,c,ctx); 770 BN_div(a,b,d,c,ctx);
710 if(!BN_is_zero(b)) 771 if(!BN_is_zero(b))
711 { 772 {
712 BIO_puts(bp,"Modulo multiply test failed!\n"); 773 fprintf(stderr,"Modulo multiply test failed!\n");
713 return 0; 774 return 0;
714 } 775 }
715 } 776 }
@@ -733,7 +794,7 @@ int test_mod_exp(BIO *bp, BN_CTX *ctx)
733 e=BN_new(); 794 e=BN_new();
734 795
735 BN_rand(c,30,0,1); /* must be odd for montgomery */ 796 BN_rand(c,30,0,1); /* must be odd for montgomery */
736 for (i=0; i<6; i++) 797 for (i=0; i<num2; i++)
737 { 798 {
738 BN_rand(a,20+i*5,0,0); /**/ 799 BN_rand(a,20+i*5,0,0); /**/
739 BN_rand(b,2+i,0,0); /**/ 800 BN_rand(b,2+i,0,0); /**/
@@ -760,7 +821,7 @@ int test_mod_exp(BIO *bp, BN_CTX *ctx)
760 BN_div(a,b,e,c,ctx); 821 BN_div(a,b,e,c,ctx);
761 if(!BN_is_zero(b)) 822 if(!BN_is_zero(b))
762 { 823 {
763 BIO_puts(bp,"Modulo exponentiation test failed!\n"); 824 fprintf(stderr,"Modulo exponentiation test failed!\n");
764 return 0; 825 return 0;
765 } 826 }
766 } 827 }
@@ -784,7 +845,7 @@ int test_exp(BIO *bp, BN_CTX *ctx)
784 one=BN_new(); 845 one=BN_new();
785 BN_one(one); 846 BN_one(one);
786 847
787 for (i=0; i<6; i++) 848 for (i=0; i<num2; i++)
788 { 849 {
789 BN_rand(a,20+i*5,0,0); /**/ 850 BN_rand(a,20+i*5,0,0); /**/
790 BN_rand(b,2+i,0,0); /**/ 851 BN_rand(b,2+i,0,0); /**/
@@ -810,7 +871,7 @@ int test_exp(BIO *bp, BN_CTX *ctx)
810 BN_sub(e,e,d); 871 BN_sub(e,e,d);
811 if(!BN_is_zero(e)) 872 if(!BN_is_zero(e))
812 { 873 {
813 BIO_puts(bp,"Exponentiation test failed!\n"); 874 fprintf(stderr,"Exponentiation test failed!\n");
814 return 0; 875 return 0;
815 } 876 }
816 } 877 }
@@ -840,7 +901,7 @@ int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_)
840 BN_rand(a,200,0,0); /**/ 901 BN_rand(a,200,0,0); /**/
841 a->neg=rand_neg(); 902 a->neg=rand_neg();
842 } 903 }
843 for (i=0; i<70; i++) 904 for (i=0; i<num0; i++)
844 { 905 {
845 BN_lshift(b,a,i+1); 906 BN_lshift(b,a,i+1);
846 BN_add(c,c,c); 907 BN_add(c,c,c);
@@ -860,16 +921,16 @@ int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_)
860 BN_sub(d,d,b); 921 BN_sub(d,d,b);
861 if(!BN_is_zero(d)) 922 if(!BN_is_zero(d))
862 { 923 {
863 BIO_puts(bp,"Left shift test failed!\n"); 924 fprintf(stderr,"Left shift test failed!\n");
864 BIO_puts(bp,"a="); 925 fprintf(stderr,"a=");
865 BN_print(bp,a); 926 BN_print_fp(stderr,a);
866 BIO_puts(bp,"\nb="); 927 fprintf(stderr,"\nb=");
867 BN_print(bp,b); 928 BN_print_fp(stderr,b);
868 BIO_puts(bp,"\nc="); 929 fprintf(stderr,"\nc=");
869 BN_print(bp,c); 930 BN_print_fp(stderr,c);
870 BIO_puts(bp,"\nd="); 931 fprintf(stderr,"\nd=");
871 BN_print(bp,d); 932 BN_print_fp(stderr,d);
872 BIO_puts(bp,"\n"); 933 fprintf(stderr,"\n");
873 return 0; 934 return 0;
874 } 935 }
875 } 936 }
@@ -891,7 +952,7 @@ int test_lshift1(BIO *bp)
891 952
892 BN_rand(a,200,0,0); /**/ 953 BN_rand(a,200,0,0); /**/
893 a->neg=rand_neg(); 954 a->neg=rand_neg();
894 for (i=0; i<70; i++) 955 for (i=0; i<num0; i++)
895 { 956 {
896 BN_lshift1(b,a); 957 BN_lshift1(b,a);
897 if (bp != NULL) 958 if (bp != NULL)
@@ -909,7 +970,7 @@ int test_lshift1(BIO *bp)
909 BN_sub(a,b,c); 970 BN_sub(a,b,c);
910 if(!BN_is_zero(a)) 971 if(!BN_is_zero(a))
911 { 972 {
912 BIO_puts(bp,"Left shift one test failed!\n"); 973 fprintf(stderr,"Left shift one test failed!\n");
913 return 0; 974 return 0;
914 } 975 }
915 976
@@ -935,7 +996,7 @@ int test_rshift(BIO *bp,BN_CTX *ctx)
935 996
936 BN_rand(a,200,0,0); /**/ 997 BN_rand(a,200,0,0); /**/
937 a->neg=rand_neg(); 998 a->neg=rand_neg();
938 for (i=0; i<70; i++) 999 for (i=0; i<num0; i++)
939 { 1000 {
940 BN_rshift(b,a,i+1); 1001 BN_rshift(b,a,i+1);
941 BN_add(c,c,c); 1002 BN_add(c,c,c);
@@ -955,7 +1016,7 @@ int test_rshift(BIO *bp,BN_CTX *ctx)
955 BN_sub(d,d,b); 1016 BN_sub(d,d,b);
956 if(!BN_is_zero(d)) 1017 if(!BN_is_zero(d))
957 { 1018 {
958 BIO_puts(bp,"Right shift test failed!\n"); 1019 fprintf(stderr,"Right shift test failed!\n");
959 return 0; 1020 return 0;
960 } 1021 }
961 } 1022 }
@@ -978,7 +1039,7 @@ int test_rshift1(BIO *bp)
978 1039
979 BN_rand(a,200,0,0); /**/ 1040 BN_rand(a,200,0,0); /**/
980 a->neg=rand_neg(); 1041 a->neg=rand_neg();
981 for (i=0; i<70; i++) 1042 for (i=0; i<num0; i++)
982 { 1043 {
983 BN_rshift1(b,a); 1044 BN_rshift1(b,a);
984 if (bp != NULL) 1045 if (bp != NULL)
@@ -996,7 +1057,7 @@ int test_rshift1(BIO *bp)
996 BN_sub(c,c,b); 1057 BN_sub(c,c,b);
997 if(!BN_is_zero(c) && !BN_is_one(c)) 1058 if(!BN_is_zero(c) && !BN_is_one(c))
998 { 1059 {
999 BIO_puts(bp,"Right shift one test failed!\n"); 1060 fprintf(stderr,"Right shift one test failed!\n");
1000 return 0; 1061 return 0;
1001 } 1062 }
1002 BN_copy(a,b); 1063 BN_copy(a,b);
diff --git a/src/lib/libcrypto/bn/comba.pl b/src/lib/libcrypto/bn/comba.pl
index 211a8b45c7..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/comba.pl
+++ b/src/lib/libcrypto/bn/comba.pl
@@ -1,285 +0,0 @@
1#!/usr/local/bin/perl
2
3$num=8;
4$num2=8/2;
5
6print <<"EOF";
7/* crypto/bn/bn_comba.c */
8#include <stdio.h>
9#include "bn_lcl.h"
10/* Auto generated from crypto/bn/comba.pl
11 */
12
13#undef bn_mul_comba8
14#undef bn_mul_comba4
15#undef bn_sqr_comba8
16#undef bn_sqr_comba4
17
18#ifdef BN_LLONG
19#define mul_add_c(a,b,c0,c1,c2) \\
20 t=(BN_ULLONG)a*b; \\
21 t1=(BN_ULONG)Lw(t); \\
22 t2=(BN_ULONG)Hw(t); \\
23 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
24 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
25
26#define mul_add_c2(a,b,c0,c1,c2) \\
27 t=(BN_ULLONG)a*b; \\
28 tt=(t+t)&BN_MASK; \\
29 if (tt < t) c2++; \\
30 t1=(BN_ULONG)Lw(tt); \\
31 t2=(BN_ULONG)Hw(tt); \\
32 c0=(c0+t1)&BN_MASK2; \\
33 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \\
34 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
35
36#define sqr_add_c(a,i,c0,c1,c2) \\
37 t=(BN_ULLONG)a[i]*a[i]; \\
38 t1=(BN_ULONG)Lw(t); \\
39 t2=(BN_ULONG)Hw(t); \\
40 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
41 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
42
43#define sqr_add_c2(a,i,j,c0,c1,c2) \\
44 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
45#else
46#define mul_add_c(a,b,c0,c1,c2) \\
47 t1=LBITS(a); t2=HBITS(a); \\
48 bl=LBITS(b); bh=HBITS(b); \\
49 mul64(t1,t2,bl,bh); \\
50 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
51 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
52
53#define mul_add_c2(a,b,c0,c1,c2) \\
54 t1=LBITS(a); t2=HBITS(a); \\
55 bl=LBITS(b); bh=HBITS(b); \\
56 mul64(t1,t2,bl,bh); \\
57 if (t2 & BN_TBIT) c2++; \\
58 t2=(t2+t2)&BN_MASK2; \\
59 if (t1 & BN_TBIT) t2++; \\
60 t1=(t1+t1)&BN_MASK2; \\
61 c0=(c0+t1)&BN_MASK2; \\
62 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \\
63 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
64
65#define sqr_add_c(a,i,c0,c1,c2) \\
66 sqr64(t1,t2,(a)[i]); \\
67 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
68 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
69
70#define sqr_add_c2(a,i,j,c0,c1,c2) \\
71 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
72#endif
73
74void bn_mul_comba${num}(r,a,b)
75BN_ULONG *r,*a,*b;
76 {
77#ifdef BN_LLONG
78 BN_ULLONG t;
79#else
80 BN_ULONG bl,bh;
81#endif
82 BN_ULONG t1,t2;
83 BN_ULONG c1,c2,c3;
84
85EOF
86$ret=&combas_mul("r","a","b",$num,"c1","c2","c3");
87printf <<"EOF";
88 }
89
90void bn_mul_comba${num2}(r,a,b)
91BN_ULONG *r,*a,*b;
92 {
93#ifdef BN_LLONG
94 BN_ULLONG t;
95#else
96 BN_ULONG bl,bh;
97#endif
98 BN_ULONG t1,t2;
99 BN_ULONG c1,c2,c3;
100
101EOF
102$ret=&combas_mul("r","a","b",$num2,"c1","c2","c3");
103printf <<"EOF";
104 }
105
106void bn_sqr_comba${num}(r,a)
107BN_ULONG *r,*a;
108 {
109#ifdef BN_LLONG
110 BN_ULLONG t,tt;
111#else
112 BN_ULONG bl,bh;
113#endif
114 BN_ULONG t1,t2;
115 BN_ULONG c1,c2,c3;
116
117EOF
118$ret=&combas_sqr("r","a",$num,"c1","c2","c3");
119printf <<"EOF";
120 }
121
122void bn_sqr_comba${num2}(r,a)
123BN_ULONG *r,*a;
124 {
125#ifdef BN_LLONG
126 BN_ULLONG t,tt;
127#else
128 BN_ULONG bl,bh;
129#endif
130 BN_ULONG t1,t2;
131 BN_ULONG c1,c2,c3;
132
133EOF
134$ret=&combas_sqr("r","a",$num2,"c1","c2","c3");
135printf <<"EOF";
136 }
137EOF
138
139sub bn_str
140 {
141 local($var,$val)=@_;
142 print "\t$var=$val;\n";
143 }
144
145sub bn_ary
146 {
147 local($var,$idx)=@_;
148 return("${var}[$idx]");
149 }
150
151sub bn_clr
152 {
153 local($var)=@_;
154
155 print "\t$var=0;\n";
156 }
157
158sub bn_mad
159 {
160 local($a,$b,$c0,$c1,$c2,$num)=@_;
161
162 if ($num == 2)
163 { printf("\tmul_add_c2($a,$b,$c0,$c1,$c2);\n"); }
164 else
165 { printf("\tmul_add_c($a,$b,$c0,$c1,$c2);\n"); }
166 }
167
168sub bn_sad
169 {
170 local($a,$i,$j,$c0,$c1,$c2,$num)=@_;
171
172 if ($num == 2)
173 { printf("\tsqr_add_c2($a,$i,$j,$c0,$c1,$c2);\n"); }
174 else
175 { printf("\tsqr_add_c($a,$i,$c0,$c1,$c2);\n"); }
176 }
177
178sub combas_mul
179 {
180 local($r,$a,$b,$num,$c0,$c1,$c2)=@_;
181 local($i,$as,$ae,$bs,$be,$ai,$bi);
182 local($tot,$end);
183
184 $as=0;
185 $ae=0;
186 $bs=0;
187 $be=0;
188 $tot=$num+$num-1;
189 &bn_clr($c0);
190 &bn_clr($c1);
191 for ($i=0; $i<$tot; $i++)
192 {
193 $ai=$as;
194 $bi=$bs;
195 $end=$be+1;
196 @numa=@numb=();
197
198#print "($as $ae) ($bs $be) $bs -> $end [$i $num]\n";
199 for ($j=$bs; $j<$end; $j++)
200 {
201 push(@numa,$ai);
202 push(@numb,$bi);
203 $ai--;
204 $bi++;
205 }
206
207 if ($i & 1)
208 {
209 @numa=reverse(@numa);
210 @numb=reverse(@numb);
211 }
212
213 &bn_clr($c2);
214 for ($j=0; $j<=$#numa; $j++)
215 {
216 &bn_mad(&bn_ary($a,$numa[$j]),
217 &bn_ary($b,$numb[$j]),$c0,$c1,$c2,1);
218 }
219 &bn_str(&bn_ary($r,$i),$c0);
220 ($c0,$c1,$c2)=($c1,$c2,$c0);
221
222 $as++ if ($i < ($num-1));
223 $ae++ if ($i >= ($num-1));
224
225 $bs++ if ($i >= ($num-1));
226 $be++ if ($i < ($num-1));
227 }
228 &bn_str(&bn_ary($r,$i),$c0);
229 }
230
231sub combas_sqr
232 {
233 local($r,$a,$num,$c0,$c1,$c2)=@_;
234 local($i,$as,$ae,$bs,$be,$ai,$bi);
235 local($b,$tot,$end,$half);
236
237 $b=$a;
238 $as=0;
239 $ae=0;
240 $bs=0;
241 $be=0;
242 $tot=$num+$num-1;
243 &bn_clr($c0);
244 &bn_clr($c1);
245 for ($i=0; $i<$tot; $i++)
246 {
247 $ai=$as;
248 $bi=$bs;
249 $end=$be+1;
250 @numa=@numb=();
251
252#print "($as $ae) ($bs $be) $bs -> $end [$i $num]\n";
253 for ($j=$bs; $j<$end; $j++)
254 {
255 push(@numa,$ai);
256 push(@numb,$bi);
257 $ai--;
258 $bi++;
259 last if ($ai < $bi);
260 }
261 if (!($i & 1))
262 {
263 @numa=reverse(@numa);
264 @numb=reverse(@numb);
265 }
266
267 &bn_clr($c2);
268 for ($j=0; $j <= $#numa; $j++)
269 {
270 if ($numa[$j] == $numb[$j])
271 {&bn_sad($a,$numa[$j],$numb[$j],$c0,$c1,$c2,1);}
272 else
273 {&bn_sad($a,$numa[$j],$numb[$j],$c0,$c1,$c2,2);}
274 }
275 &bn_str(&bn_ary($r,$i),$c0);
276 ($c0,$c1,$c2)=($c1,$c2,$c0);
277
278 $as++ if ($i < ($num-1));
279 $ae++ if ($i >= ($num-1));
280
281 $bs++ if ($i >= ($num-1));
282 $be++ if ($i < ($num-1));
283 }
284 &bn_str(&bn_ary($r,$i),$c0);
285 }
diff --git a/src/lib/libcrypto/bn/d.c b/src/lib/libcrypto/bn/d.c
index ced2291b25..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/d.c
+++ b/src/lib/libcrypto/bn/d.c
@@ -1,72 +0,0 @@
1#include <stdio.h>
2#include <openssl/bio.h>
3#include "bn_lcl.h"
4
5#define SIZE_A (100*4+4)
6#define SIZE_B (13*4)
7
8main(argc,argv)
9int argc;
10char *argv[];
11 {
12 BN_CTX ctx;
13 BN_RECP_CTX recp;
14 BIGNUM a,b,dd,d,r,rr,t,l;
15 int i;
16
17 MemCheck_start();
18 MemCheck_on();
19 BN_CTX_init(&ctx);
20 BN_RECP_CTX_init(&recp);
21
22 BN_init(&r);
23 BN_init(&rr);
24 BN_init(&d);
25 BN_init(&dd);
26 BN_init(&a);
27 BN_init(&b);
28
29 {
30 BN_rand(&a,SIZE_A,0,0);
31 BN_rand(&b,SIZE_B,0,0);
32
33 a.neg=1;
34 BN_RECP_CTX_set(&recp,&b,&ctx);
35
36 BN_print_fp(stdout,&a); printf(" a\n");
37 BN_print_fp(stdout,&b); printf(" b\n");
38
39 BN_print_fp(stdout,&recp.N); printf(" N\n");
40 BN_print_fp(stdout,&recp.Nr); printf(" Nr num_bits=%d\n",recp.num_bits);
41
42 BN_div_recp(&r,&d,&a,&recp,&ctx);
43
44for (i=0; i<300; i++)
45 BN_div(&rr,&dd,&a,&b,&ctx);
46
47 BN_print_fp(stdout,&r); printf(" div recp\n");
48 BN_print_fp(stdout,&rr); printf(" div\n");
49 BN_print_fp(stdout,&d); printf(" rem recp\n");
50 BN_print_fp(stdout,&dd); printf(" rem\n");
51 }
52 BN_CTX_free(&ctx);
53 BN_RECP_CTX_free(&recp);
54
55 BN_free(&r);
56 BN_free(&rr);
57 BN_free(&d);
58 BN_free(&dd);
59 BN_free(&a);
60 BN_free(&b);
61
62 {
63 BIO *out;
64
65 if ((out=BIO_new(BIO_s_file())) != NULL)
66 BIO_set_fp(out,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
67
68 CRYPTO_mem_leaks(out);
69 BIO_free(out);
70 }
71
72 }
diff --git a/src/lib/libcrypto/bn/divtest.c b/src/lib/libcrypto/bn/divtest.c
new file mode 100644
index 0000000000..13ba86e3c4
--- /dev/null
+++ b/src/lib/libcrypto/bn/divtest.c
@@ -0,0 +1,41 @@
1#include <openssl/bn.h>
2#include <openssl/rand.h>
3
4static int rand(n)
5{
6 unsigned char x[2];
7 RAND_pseudo_bytes(x,2);
8 return (x[0] + 2*x[1]);
9}
10
11static void bug(char *m, BIGNUM *a, BIGNUM *b)
12{
13 printf("%s!\na=",m);
14 BN_print_fp(stdout, a);
15 printf("\nb=");
16 BN_print_fp(stdout, b);
17 printf("\n");
18 fflush(stdout);
19}
20
21main()
22{
23 BIGNUM *a=BN_new(), *b=BN_new(), *c=BN_new(), *d=BN_new(),
24 *C=BN_new(), *D=BN_new();
25 BN_RECP_CTX *recp=BN_RECP_CTX_new();
26 BN_CTX *ctx=BN_CTX_new();
27
28 for(;;) {
29 BN_pseudo_rand(a,rand(),0,0);
30 BN_pseudo_rand(b,rand(),0,0);
31 if (BN_is_zero(b)) continue;
32
33 BN_RECP_CTX_set(recp,b,ctx);
34 if (BN_div(C,D,a,b,ctx) != 1)
35 bug("BN_div failed",a,b);
36 if (BN_div_recp(c,d,a,recp,ctx) != 1)
37 bug("BN_div_recp failed",a,b);
38 else if (BN_cmp(c,C) != 0 || BN_cmp(c,C) != 0)
39 bug("mismatch",a,b);
40 }
41}
diff --git a/src/lib/libcrypto/bn/exp.c b/src/lib/libcrypto/bn/exp.c
index ec443459d8..4865b0ef74 100644
--- a/src/lib/libcrypto/bn/exp.c
+++ b/src/lib/libcrypto/bn/exp.c
@@ -1,3 +1,5 @@
1/* unused */
2
1#include <stdio.h> 3#include <stdio.h>
2#include <openssl/tmdiff.h> 4#include <openssl/tmdiff.h>
3#include "bn_lcl.h" 5#include "bn_lcl.h"
diff --git a/src/lib/libcrypto/bn/expspeed.c b/src/lib/libcrypto/bn/expspeed.c
index 3656d5bb4c..2044ab9bff 100644
--- a/src/lib/libcrypto/bn/expspeed.c
+++ b/src/lib/libcrypto/bn/expspeed.c
@@ -1,3 +1,5 @@
1/* unused */
2
1/* crypto/bn/expspeed.c */ 3/* crypto/bn/expspeed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 5 * All rights reserved.
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c
index 9e4ae91d20..3e86f2ea0e 100644
--- a/src/lib/libcrypto/bn/exptest.c
+++ b/src/lib/libcrypto/bn/exptest.c
@@ -69,6 +69,8 @@
69 69
70#define NUM_BITS (BN_BITS*2) 70#define NUM_BITS (BN_BITS*2)
71 71
72static const char rnd_seed[] = "string to make the random number generator think it has entropy";
73
72int main(int argc, char *argv[]) 74int main(int argc, char *argv[])
73 { 75 {
74 BN_CTX *ctx; 76 BN_CTX *ctx;
@@ -77,6 +79,10 @@ int main(int argc, char *argv[])
77 unsigned char c; 79 unsigned char c;
78 BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m; 80 BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m;
79 81
82 RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't
83 * even check its return value
84 * (which we should) */
85
80 ERR_load_BN_strings(); 86 ERR_load_BN_strings();
81 87
82 ctx=BN_CTX_new(); 88 ctx=BN_CTX_new();
@@ -160,7 +166,16 @@ int main(int argc, char *argv[])
160 exit(1); 166 exit(1);
161 } 167 }
162 } 168 }
169 BN_free(r_mont);
170 BN_free(r_recp);
171 BN_free(r_simple);
172 BN_free(a);
173 BN_free(b);
174 BN_free(m);
175 BN_CTX_free(ctx);
176 ERR_remove_state(0);
163 CRYPTO_mem_leaks(out); 177 CRYPTO_mem_leaks(out);
178 BIO_free(out);
164 printf(" done\n"); 179 printf(" done\n");
165 exit(0); 180 exit(0);
166err: 181err:
diff --git a/src/lib/libcrypto/bn/new b/src/lib/libcrypto/bn/new
index 285d506f19..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/new
+++ b/src/lib/libcrypto/bn/new
@@ -1,23 +0,0 @@
1void BN_RECP_CTX_init(BN_RECP_CTX *recp);
2BN_RECP_CTX *BN_RECP_CTX_new();
3void BN_RECP_CTX_free(BN_RECP_CTX *recp);
4int BN_RECP_CTX_set(BN_RECP_CTX *recp,BIGNUM *div,BN_CTX *ctx);
5
6int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,
7 BN_RECP_CTX *recp,BN_CTX *ctx);
8
9int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d,
10 BN_RECP_CTX *recp, BN_CTX *ctx);
11int BN_mod_recp(BIGNUM *rem, BIGNUM *m, BIGNUM *d,
12 BN_RECP_CTX *recp, BN_CTX *ctx);
13int BN_mod_mul_recp(BIGNUM *ret,BIGNUM *a,BIGNUM *b,BIGNUM *m
14
15int BN_mod_exp_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *p,
16 BN_MONT_CTX *m_ctx,BN_CTX *ctx);
17int BN_mod_exp2_montgomery(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2,
18 BIGNUM *p2,BN_MONT_CTX *m_ctx,BN_CTX *ctx);
19
20
21bn_div64 -> bn_div_words
22
23
diff --git a/src/lib/libcrypto/bn/old/b_sqr.c b/src/lib/libcrypto/bn/old/b_sqr.c
index 715cb1c8ab..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/b_sqr.c
+++ b/src/lib/libcrypto/bn/old/b_sqr.c
@@ -1,199 +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
63static int bn_mm(BIGNUM *m,BIGNUM *A,BIGNUM *B, BIGNUM *sk,BN_CTX *ctx);
64
65/* r must be different to a and b */
66/* int BN_mmul(r, a, b) */
67int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b)
68 {
69 BN_ULONG *ap,*bp,*rp;
70 BIGNUM *sk;
71 int i,n,ret;
72 int max,al,bl;
73 BN_CTX ctx;
74
75 bn_check_top(a);
76 bn_check_top(b);
77
78 al=a->top;
79 bl=b->top;
80 if ((al == 0) || (bl == 0))
81 {
82 r->top=0;
83 return(1);
84 }
85#ifdef BN_MUL_DEBUG
86printf("BN_mul(%d,%d)\n",a->top,b->top);
87#endif
88
89 if ( (bn_limit_bits > 0) &&
90 (bl > bn_limit_num) && (al > bn_limit_num))
91 {
92 n=(BN_num_bits_word(al|bl)-bn_limit_bits);
93 n*=2;
94 sk=(BIGNUM *)Malloc(sizeof(BIGNUM)*n);
95 memset(sk,0,sizeof(BIGNUM)*n);
96 memset(&ctx,0,sizeof(ctx));
97
98 ret=bn_mm(r,a,b,&(sk[0]),&ctx);
99 for (i=0; i<n; i+=2)
100 {
101 BN_clear_free(&sk[i]);
102 BN_clear_free(&sk[i+1]);
103 }
104 Free(sk);
105 return(ret);
106 }
107
108 max=(al+bl);
109 if (bn_wexpand(r,max) == NULL) return(0);
110 r->top=max;
111 r->neg=a->neg^b->neg;
112 ap=a->d;
113 bp=b->d;
114 rp=r->d;
115
116 rp[al]=bn_mul_words(rp,ap,al,*(bp++));
117 rp++;
118 for (i=1; i<bl; i++)
119 {
120 rp[al]=bn_mul_add_words(rp,ap,al,*(bp++));
121 rp++;
122 }
123 if ((max > 0) && (r->d[max-1] == 0)) r->top--;
124 return(1);
125 }
126
127
128#define ahal (sk[0])
129#define blbh (sk[1])
130
131/* r must be different to a and b */
132int bn_mm(BIGNUM *m, BIGNUM *A, BIGNUM *B, BIGNUM *sk, BN_CTX *ctx)
133 {
134 int n,num,sqr=0;
135 int an,bn;
136 BIGNUM ah,al,bh,bl;
137
138 an=A->top;
139 bn=B->top;
140#ifdef BN_MUL_DEBUG
141printf("bn_mm(%d,%d)\n",A->top,B->top);
142#endif
143
144 if (A == B) sqr=1;
145 num=(an>bn)?an:bn;
146 n=(num+1)/2;
147 /* Are going to now chop things into 'num' word chunks. */
148
149 BN_init(&ah);
150 BN_init(&al);
151 BN_init(&bh);
152 BN_init(&bl);
153
154 bn_set_low (&al,A,n);
155 bn_set_high(&ah,A,n);
156 bn_set_low (&bl,B,n);
157 bn_set_high(&bh,B,n);
158
159 BN_sub(&ahal,&ah,&al);
160 BN_sub(&blbh,&bl,&bh);
161
162 if (num <= (bn_limit_num+bn_limit_num))
163 {
164 BN_mul(m,&ahal,&blbh);
165 if (sqr)
166 {
167 BN_sqr(&ahal,&al,ctx);
168 BN_sqr(&blbh,&ah,ctx);
169 }
170 else
171 {
172 BN_mul(&ahal,&al,&bl);
173 BN_mul(&blbh,&ah,&bh);
174 }
175 }
176 else
177 {
178 bn_mm(m,&ahal,&blbh,&(sk[2]),ctx);
179 bn_mm(&ahal,&al,&bl,&(sk[2]),ctx);
180 bn_mm(&blbh,&ah,&bh,&(sk[2]),ctx);
181 }
182
183 BN_add(m,m,&ahal);
184 BN_add(m,m,&blbh);
185
186 BN_lshift(m,m,n*BN_BITS2);
187 BN_lshift(&blbh,&blbh,n*BN_BITS2*2);
188
189 BN_add(m,m,&ahal);
190 BN_add(m,m,&blbh);
191
192 m->neg=A->neg^B->neg;
193 return(1);
194 }
195#undef ahal (sk[0])
196#undef blbh (sk[1])
197
198#include "bn_low.c"
199#include "bn_high.c"
diff --git a/src/lib/libcrypto/bn/old/bn_com.c b/src/lib/libcrypto/bn/old/bn_com.c
index 7666b2304c..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/bn_com.c
+++ b/src/lib/libcrypto/bn/old/bn_com.c
@@ -1,90 +0,0 @@
1/* crypto/bn/bn_mulw.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63#ifdef BN_LLONG
64
65ab
6612
67 a2 b2
68a1 b1
69
70abc
71123
72 a3 b3 c3
73 a2 b2 c2
74a1 b1 c1
75
76abcd
771234
78 a4 b4 c4 d4
79 a3 b3 c3 d3
80 a2 b2 c2 d2
81a1 b1 c1 d1
82
83abcde
8401234
85 a5 b5 c5 d5 e5
86 a4 b4 c4 d4 e4
87 a3 b3 c3 d3 e3
88 a2 b2 c2 d2 e2
89 a1 b1 c1 d1 e1
90a0 b0 c0 d0 e0
diff --git a/src/lib/libcrypto/bn/old/bn_high.c b/src/lib/libcrypto/bn/old/bn_high.c
index 763bcb605b..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/bn_high.c
+++ b/src/lib/libcrypto/bn/old/bn_high.c
@@ -1,135 +0,0 @@
1#include <stdio.h>
2#include "cryptlib.h"
3#include "bn_lcl.h"
4
5#undef BN_MUL_HIGH_DEBUG
6
7#ifdef BN_MUL_HIGH_DEBUG
8#define debug_BN_print(a,b,c) BN_print_fp(a,b); printf(c);
9#else
10#define debug_BN_print(a,b,c)
11#endif
12
13int BN_mul_high(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *low, int words);
14
15#undef t1
16#undef t2
17
18int BN_mul_high(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *low, int words)
19 {
20 int w2,borrow=0,full=0;
21 BIGNUM t1,t2,t3,h,ah,al,bh,bl,m,s0,s1;
22 BN_ULONG ul1,ul2;
23
24 BN_mul(r,a,b);
25 BN_rshift(r,r,words*BN_BITS2);
26 return(1);
27
28 w2=(words+1)/2;
29
30#ifdef BN_MUL_HIGH_DEBUG
31fprintf(stdout,"words=%d w2=%d\n",words,w2);
32#endif
33debug_BN_print(stdout,a," a\n");
34debug_BN_print(stdout,b," b\n");
35debug_BN_print(stdout,low," low\n");
36 BN_init(&al); BN_init(&ah);
37 BN_init(&bl); BN_init(&bh);
38 BN_init(&t1); BN_init(&t2); BN_init(&t3);
39 BN_init(&s0); BN_init(&s1);
40 BN_init(&h); BN_init(&m);
41
42 bn_set_low (&al,a,w2);
43 bn_set_high(&ah,a,w2);
44 bn_set_low (&bl,b,w2);
45 bn_set_high(&bh,b,w2);
46
47 bn_set_low(&s0,low,w2);
48 bn_set_high(&s1,low,w2);
49
50debug_BN_print(stdout,&al," al\n");
51debug_BN_print(stdout,&ah," ah\n");
52debug_BN_print(stdout,&bl," bl\n");
53debug_BN_print(stdout,&bh," bh\n");
54debug_BN_print(stdout,&s0," s0\n");
55debug_BN_print(stdout,&s1," s1\n");
56
57 /* Calculate (al-ah)*(bh-bl) */
58 BN_sub(&t1,&al,&ah);
59 BN_sub(&t2,&bh,&bl);
60 BN_mul(&m,&t1,&t2);
61
62 /* Calculate ah*bh */
63 BN_mul(&h,&ah,&bh);
64
65 /* s0 == low(al*bl)
66 * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl)
67 * We know s0 and s1 so the only unknown is high(al*bl)
68 * high(al*bl) == s1 - low(ah*bh+(al-ah)*(bh-bl)+s0)
69 */
70 BN_add(&m,&m,&h);
71 BN_add(&t2,&m,&s0);
72
73debug_BN_print(stdout,&t2," middle value\n");
74
75 /* Quick and dirty mask off of high words */
76 if (w2 < t2.top) t2.top=w2;
77#if 0
78 bn_set_low(&t3,&t2,w2);
79#endif
80
81debug_BN_print(stdout,&t2," low middle value\n");
82 BN_sub(&t1,&s1,&t2);
83
84 if (t1.neg)
85 {
86debug_BN_print(stdout,&t1," before\n");
87 BN_zero(&t2);
88 BN_set_bit(&t2,w2*BN_BITS2);
89 BN_add(&t1,&t2,&t1);
90 /* BN_mask_bits(&t1,w2*BN_BITS2); */
91 /* if (words < t1.top) t1.top=words; */
92debug_BN_print(stdout,&t1," after\n");
93 borrow=1;
94 }
95
96/* XXXXX SPEED THIS UP */
97 /* al*bl == high(al*bl)<<words+s0 */
98 BN_lshift(&t1,&t1,w2*BN_BITS2);
99 BN_add(&t1,&t1,&s0);
100 if (w2*2 < t1.top) t1.top=w2*2; /* This should not happen? */
101
102 /* We now have
103 * al*bl - t1
104 * (al-ah)*(bh-bl)+ah*bh - m
105 * ah*bh - h
106 */
107#if 0
108 BN_add(&m,&m,&t1);
109debug_BN_print(stdout,&t1," s10\n");
110debug_BN_print(stdout,&m," s21\n");
111debug_BN_print(stdout,&h," s32\n");
112 BN_lshift(&m,&m,w2*BN_BITS2);
113 BN_lshift(&h,&h,w2*2*BN_BITS2);
114 BN_add(r,&m,&t1);
115 BN_add(r,r,&h);
116 BN_rshift(r,r,w2*2*BN_BITS2);
117#else
118 BN_add(&m,&m,&t1); /* Do a cmp then +1 if needed? */
119 bn_set_high(&t3,&t1,w2);
120 BN_add(&m,&m,&t3);
121 bn_set_high(&t3,&m,w2);
122 BN_add(r,&h,&t3);
123#endif
124
125#ifdef BN_MUL_HIGH_DEBUG
126printf("carry=%d\n",borrow);
127#endif
128debug_BN_print(stdout,r," ret\n");
129 BN_free(&t1); BN_free(&t2);
130 BN_free(&m); BN_free(&h);
131 return(1);
132 }
133
134
135
diff --git a/src/lib/libcrypto/bn/old/bn_ka.c b/src/lib/libcrypto/bn/old/bn_ka.c
index 378c94dc5a..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/bn_ka.c
+++ b/src/lib/libcrypto/bn/old/bn_ka.c
@@ -1,567 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <strings.h>
4#include "bn_lcl.h"
5
6/* r is 2*n2 words in size,
7 * a and b are both n2 words in size.
8 * n2 must be a power of 2.
9 * We multiply and return the result.
10 * t must be 2*n2 words in size
11 * We calulate
12 * a[0]*b[0]
13 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
14 * a[1]*b[1]
15 */
16void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
17 BN_ULONG *t)
18 {
19 int n=n2/2;
20 int neg,zero,c1,c2;
21 BN_ULONG ln,lo,*p;
22
23#ifdef BN_COUNT
24printf(" bn_mul_recursive %d * %d\n",n2,n2);
25#endif
26 if (n2 <= 8)
27 {
28 if (n2 == 8)
29 bn_mul_comba8(r,a,b);
30 else
31 bn_mul_normal(r,a,n2,b,n2);
32 return;
33 }
34
35 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)
36 {
37 /* This should not happen */
38 /*abort(); */
39 bn_mul_normal(r,a,n2,b,n2);
40 return;
41 }
42 /* r=(a[0]-a[1])*(b[1]-b[0]) */
43 c1=bn_cmp_words(a,&(a[n]),n);
44 c2=bn_cmp_words(&(b[n]),b,n);
45 zero=neg=0;
46 switch (c1*3+c2)
47 {
48 case -4:
49 bn_sub_words(t, &(a[n]),a, n); /* - */
50 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
51 break;
52 case -3:
53 zero=1;
54 break;
55 case -2:
56 bn_sub_words(t, &(a[n]),a, n); /* - */
57 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
58 neg=1;
59 break;
60 case -1:
61 case 0:
62 case 1:
63 zero=1;
64 break;
65 case 2:
66 bn_sub_words(t, a, &(a[n]),n); /* + */
67 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
68 neg=1;
69 break;
70 case 3:
71 zero=1;
72 break;
73 case 4:
74 bn_sub_words(t, a, &(a[n]),n);
75 bn_sub_words(&(t[n]),&(b[n]),b, n);
76 break;
77 }
78
79 if (n == 8)
80 {
81 if (!zero)
82 bn_mul_comba8(&(t[n2]),t,&(t[n]));
83 else
84 memset(&(t[n2]),0,8*sizeof(BN_ULONG));
85
86 bn_mul_comba8(r,a,b);
87 bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));
88 }
89 else
90 {
91 p= &(t[n2*2]);
92 if (!zero)
93 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
94 else
95 memset(&(t[n2]),0,n*sizeof(BN_ULONG));
96 bn_mul_recursive(r,a,b,n,p);
97 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);
98 }
99
100 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
101 * r[10] holds (a[0]*b[0])
102 * r[32] holds (b[1]*b[1])
103 */
104
105 c1=bn_add_words(t,r,&(r[n2]),n2);
106
107 if (neg) /* if t[32] is negative */
108 {
109 c1-=bn_sub_words(&(t[n2]),t,&(t[n2]),n2);
110 }
111 else
112 {
113 /* Might have a carry */
114 c1+=bn_add_words(&(t[n2]),&(t[n2]),t,n2);
115 }
116
117 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
118 * r[10] holds (a[0]*b[0])
119 * r[32] holds (b[1]*b[1])
120 * c1 holds the carry bits
121 */
122 c1+=bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2);
123 if (c1)
124 {
125 p= &(r[n+n2]);
126 lo= *p;
127 ln=(lo+c1)&BN_MASK2;
128 *p=ln;
129
130 /* The overflow will stop before we over write
131 * words we should not overwrite */
132 if (ln < c1)
133 {
134 do {
135 p++;
136 lo= *p;
137 ln=(lo+1)&BN_MASK2;
138 *p=ln;
139 } while (ln == 0);
140 }
141 }
142 }
143
144/* n+tn is the word length
145 * t needs to be n*4 is size, as does r */
146void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
147 int n, BN_ULONG *t)
148 {
149 int n2=n*2,i,j;
150 int c1;
151 BN_ULONG ln,lo,*p;
152
153#ifdef BN_COUNT
154printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
155#endif
156 if (n < 8)
157 {
158 i=tn+n;
159 bn_mul_normal(r,a,i,b,i);
160 return;
161 }
162
163 /* r=(a[0]-a[1])*(b[1]-b[0]) */
164 bn_sub_words(t, a, &(a[n]),n); /* + */
165 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
166
167 if (n == 8)
168 {
169 bn_mul_comba8(&(t[n2]),t,&(t[n]));
170 bn_mul_comba8(r,a,b);
171 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
172 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
173 }
174 else
175 {
176 p= &(t[n2*2]);
177 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
178 bn_mul_recursive(r,a,b,n,p);
179 i=n/2;
180 /* If there is only a bottom half to the number,
181 * just do it */
182 j=tn-i;
183 if (j == 0)
184 {
185 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);
186 memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));
187 }
188 else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */
189 {
190 bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),
191 j,i,p);
192 memset(&(r[n2+tn*2]),0,
193 sizeof(BN_ULONG)*(n2-tn*2));
194 }
195 else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */
196 {
197 memset(&(r[n2]),0,sizeof(BN_ULONG)*(tn*2));
198 for (;;)
199 {
200 i/=2;
201 if (i < tn)
202 {
203 bn_mul_part_recursive(&(r[n2]),
204 &(a[n]),&(b[n]),
205 tn-i,i,p);
206 break;
207 }
208 else if (i == tn)
209 {
210 bn_mul_recursive(&(r[n2]),
211 &(a[n]),&(b[n]),
212 i,p);
213 break;
214 }
215 }
216 }
217 }
218
219 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
220 * r[10] holds (a[0]*b[0])
221 * r[32] holds (b[1]*b[1])
222 */
223
224 c1=bn_add_words(t,r,&(r[n2]),n2);
225 c1-=bn_sub_words(&(t[n2]),t,&(t[n2]),n2);
226
227 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
228 * r[10] holds (a[0]*b[0])
229 * r[32] holds (b[1]*b[1])
230 * c1 holds the carry bits
231 */
232 c1+=bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2);
233 if (c1)
234 {
235 p= &(r[n+n2]);
236 lo= *p;
237 ln=(lo+c1)&BN_MASK2;
238 *p=ln;
239
240 /* The overflow will stop before we over write
241 * words we should not overwrite */
242 if (ln < c1)
243 {
244 do {
245 p++;
246 lo= *p;
247 ln=(lo+1)&BN_MASK2;
248 *p=ln;
249 } while (ln == 0);
250 }
251 }
252 }
253
254/* r is 2*n words in size,
255 * a and b are both n words in size.
256 * n must be a power of 2.
257 * We multiply and return the result.
258 * t must be 2*n words in size
259 * We calulate
260 * a[0]*b[0]
261 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
262 * a[1]*b[1]
263 */
264void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *t)
265 {
266 int n=n2/2;
267 int zero,c1;
268 BN_ULONG ln,lo,*p;
269
270#ifdef BN_COUNT
271printf(" bn_sqr_recursive %d * %d\n",n2,n2);
272#endif
273 if (n2 == 4)
274 {
275 bn_sqr_comba4(r,a);
276 return;
277 }
278 else if (n2 == 8)
279 {
280 bn_sqr_comba8(r,a);
281 return;
282 }
283 if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL)
284 {
285 bn_sqr_normal(r,a,n2,t);
286 return;
287 abort();
288 }
289 /* r=(a[0]-a[1])*(a[1]-a[0]) */
290 c1=bn_cmp_words(a,&(a[n]),n);
291 zero=0;
292 if (c1 > 0)
293 bn_sub_words(t,a,&(a[n]),n);
294 else if (c1 < 0)
295 bn_sub_words(t,&(a[n]),a,n);
296 else
297 zero=1;
298
299 /* The result will always be negative unless it is zero */
300
301 if (n == 8)
302 {
303 if (!zero)
304 bn_sqr_comba8(&(t[n2]),t);
305 else
306 memset(&(t[n2]),0,8*sizeof(BN_ULONG));
307
308 bn_sqr_comba8(r,a);
309 bn_sqr_comba8(&(r[n2]),&(a[n]));
310 }
311 else
312 {
313 p= &(t[n2*2]);
314 if (!zero)
315 bn_sqr_recursive(&(t[n2]),t,n,p);
316 else
317 memset(&(t[n2]),0,n*sizeof(BN_ULONG));
318 bn_sqr_recursive(r,a,n,p);
319 bn_sqr_recursive(&(r[n2]),&(a[n]),n,p);
320 }
321
322 /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero
323 * r[10] holds (a[0]*b[0])
324 * r[32] holds (b[1]*b[1])
325 */
326
327 c1=bn_add_words(t,r,&(r[n2]),n2);
328
329 /* t[32] is negative */
330 c1-=bn_sub_words(&(t[n2]),t,&(t[n2]),n2);
331
332 /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1])
333 * r[10] holds (a[0]*a[0])
334 * r[32] holds (a[1]*a[1])
335 * c1 holds the carry bits
336 */
337 c1+=bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2);
338 if (c1)
339 {
340 p= &(r[n+n2]);
341 lo= *p;
342 ln=(lo+c1)&BN_MASK2;
343 *p=ln;
344
345 /* The overflow will stop before we over write
346 * words we should not overwrite */
347 if (ln < c1)
348 {
349 do {
350 p++;
351 lo= *p;
352 ln=(lo+1)&BN_MASK2;
353 *p=ln;
354 } while (ln == 0);
355 }
356 }
357 }
358
359#if 1
360/* a and b must be the same size, which is n2.
361 * r needs to be n2 words and t needs to be n2*2
362 */
363void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
364 BN_ULONG *t)
365 {
366 int n=n2/2;
367
368#ifdef BN_COUNT
369printf(" bn_mul_low_recursive %d * %d\n",n2,n2);
370#endif
371
372 bn_mul_recursive(r,a,b,n,&(t[0]));
373 if (n > BN_MUL_LOW_RECURSIVE_SIZE_NORMAL)
374 {
375 bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2]));
376 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
377 bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2]));
378 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
379 }
380 else
381 {
382 bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n);
383 bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n);
384 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
385 bn_add_words(&(r[n]),&(r[n]),&(t[n]),n);
386 }
387 }
388
389/* a and b must be the same size, which is n2.
390 * r needs to be n2 words and t needs to be n2*2
391 * l is the low words of the output.
392 * t needs to be n2*3
393 */
394void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
395 BN_ULONG *t)
396 {
397 int j,i,n,c1,c2;
398 int neg,oneg,zero;
399 BN_ULONG ll,lc,*lp,*mp;
400
401#ifdef BN_COUNT
402printf(" bn_mul_high %d * %d\n",n2,n2);
403#endif
404 n=(n2+1)/2;
405
406 /* Calculate (al-ah)*(bh-bl) */
407 neg=zero=0;
408 c1=bn_cmp_words(&(a[0]),&(a[n]),n);
409 c2=bn_cmp_words(&(b[n]),&(b[0]),n);
410 switch (c1*3+c2)
411 {
412 case -4:
413 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
414 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
415 break;
416 case -3:
417 zero=1;
418 break;
419 case -2:
420 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
421 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
422 neg=1;
423 break;
424 case -1:
425 case 0:
426 case 1:
427 zero=1;
428 break;
429 case 2:
430 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
431 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
432 neg=1;
433 break;
434 case 3:
435 zero=1;
436 break;
437 case 4:
438 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
439 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
440 break;
441 }
442
443 oneg=neg;
444 /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */
445 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2]));
446 /* r[10] = (a[1]*b[1]) */
447 bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2]));
448
449 /* s0 == low(al*bl)
450 * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl)
451 * We know s0 and s1 so the only unknown is high(al*bl)
452 * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl))
453 * high(al*bl) == s1 - (r[0]+l[0]+t[0])
454 */
455 if (l != NULL)
456 {
457 lp= &(t[n2+n]);
458 c1=bn_add_words(lp,&(r[0]),&(l[0]),n);
459 }
460 else
461 {
462 c1=0;
463 lp= &(r[0]);
464 }
465
466 if (neg)
467 neg=bn_sub_words(&(t[n2]),lp,&(t[0]),n);
468 else
469 {
470 bn_add_words(&(t[n2]),lp,&(t[0]),n);
471 neg=0;
472 }
473
474 if (l != NULL)
475 {
476 bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n);
477 }
478 else
479 {
480 lp= &(t[n2+n]);
481 mp= &(t[n2]);
482 for (i=0; i<n; i++)
483 lp[i]=((~mp[i])+1)&BN_MASK2;
484 }
485
486 /* s[0] = low(al*bl)
487 * t[3] = high(al*bl)
488 * t[10] = (a[0]-a[1])*(b[1]-b[0]) neg is the sign
489 * r[10] = (a[1]*b[1])
490 */
491 /* R[10] = al*bl
492 * R[21] = al*bl + ah*bh + (a[0]-a[1])*(b[1]-b[0])
493 * R[32] = ah*bh
494 */
495 /* R[1]=t[3]+l[0]+r[0](+-)t[0] (have carry/borrow)
496 * R[2]=r[0]+t[3]+r[1](+-)t[1] (have carry/borrow)
497 * R[3]=r[1]+(carry/borrow)
498 */
499 if (l != NULL)
500 {
501 lp= &(t[n2]);
502 c1= bn_add_words(lp,&(t[n2+n]),&(l[0]),n);
503 }
504 else
505 {
506 lp= &(t[n2+n]);
507 c1=0;
508 }
509 c1+=bn_add_words(&(t[n2]),lp, &(r[0]),n);
510 if (oneg)
511 c1-=bn_sub_words(&(t[n2]),&(t[n2]),&(t[0]),n);
512 else
513 c1+=bn_add_words(&(t[n2]),&(t[n2]),&(t[0]),n);
514
515 c2 =bn_add_words(&(r[0]),&(r[0]),&(t[n2+n]),n);
516 c2+=bn_add_words(&(r[0]),&(r[0]),&(r[n]),n);
517 if (oneg)
518 c2-=bn_sub_words(&(r[0]),&(r[0]),&(t[n]),n);
519 else
520 c2+=bn_add_words(&(r[0]),&(r[0]),&(t[n]),n);
521
522 if (c1 != 0) /* Add starting at r[0], could be +ve or -ve */
523 {
524 i=0;
525 if (c1 > 0)
526 {
527 lc=c1;
528 do {
529 ll=(r[i]+lc)&BN_MASK2;
530 r[i++]=ll;
531 lc=(lc > ll);
532 } while (lc);
533 }
534 else
535 {
536 lc= -c1;
537 do {
538 ll=r[i];
539 r[i++]=(ll-lc)&BN_MASK2;
540 lc=(lc > ll);
541 } while (lc);
542 }
543 }
544 if (c2 != 0) /* Add starting at r[1] */
545 {
546 i=n;
547 if (c2 > 0)
548 {
549 lc=c2;
550 do {
551 ll=(r[i]+lc)&BN_MASK2;
552 r[i++]=ll;
553 lc=(lc > ll);
554 } while (lc);
555 }
556 else
557 {
558 lc= -c2;
559 do {
560 ll=r[i];
561 r[i++]=(ll-lc)&BN_MASK2;
562 lc=(lc > ll);
563 } while (lc);
564 }
565 }
566 }
567#endif
diff --git a/src/lib/libcrypto/bn/old/bn_low.c b/src/lib/libcrypto/bn/old/bn_low.c
index cbc406751c..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/bn_low.c
+++ b/src/lib/libcrypto/bn/old/bn_low.c
@@ -1,194 +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
63static int bn_mm_low(BIGNUM *m,BIGNUM *A,BIGNUM *B, int num,
64 BIGNUM *sk,BN_CTX *ctx);
65int BN_mul_low(BIGNUM *r, BIGNUM *a, BIGNUM *b,int words);
66
67/* r must be different to a and b */
68int BN_mul_low(BIGNUM *r, BIGNUM *a, BIGNUM *b, int num)
69 {
70 BN_ULONG *ap,*bp,*rp;
71 BIGNUM *sk;
72 int j,i,n,ret;
73 int max,al,bl;
74 BN_CTX ctx;
75
76 bn_check_top(a);
77 bn_check_top(b);
78
79#ifdef BN_MUL_DEBUG
80printf("BN_mul_low(%d,%d,%d)\n",a->top,b->top,num);
81#endif
82
83 al=a->top;
84 bl=b->top;
85 if ((al == 0) || (bl == 0))
86 {
87 r->top=0;
88 return(1);
89 }
90
91 if ((bn_limit_bits_low > 0) && (num > bn_limit_num_low))
92 {
93 n=BN_num_bits_word(num*2)-bn_limit_bits_low;
94 n*=2;
95 sk=(BIGNUM *)Malloc(sizeof(BIGNUM)*n);
96 memset(sk,0,sizeof(BIGNUM)*n);
97 memset(&ctx,0,sizeof(ctx));
98
99 ret=bn_mm_low(r,a,b,num,&(sk[0]),&ctx);
100 for (i=0; i<n; i+=2)
101 {
102 BN_clear_free(&sk[i]);
103 BN_clear_free(&sk[i+1]);
104 }
105 Free(sk);
106 return(ret);
107 }
108
109 max=(al+bl);
110 if (bn_wexpand(r,max) == NULL) return(0);
111 r->neg=a->neg^b->neg;
112 ap=a->d;
113 bp=b->d;
114 rp=r->d;
115 r->top=(max > num)?num:max;
116
117 rp[al]=bn_mul_words(rp,ap,al,*(bp++));
118 rp++;
119 j=bl;
120 for (i=1; i<j; i++)
121 {
122 if (al >= num--)
123 {
124 al--;
125 if (al <= 0) break;
126 }
127 rp[al]=bn_mul_add_words(rp,ap,al,*(bp++));
128 rp++;
129 }
130
131 while ((r->top > 0) && (r->d[r->top-1] == 0))
132 r->top--;
133 return(1);
134 }
135
136
137#define t1 (sk[0])
138#define t2 (sk[1])
139
140/* r must be different to a and b */
141int bn_mm_low(BIGNUM *m, BIGNUM *A, BIGNUM *B, int num, BIGNUM *sk,
142 BN_CTX *ctx)
143 {
144 int n; /* ,sqr=0; */
145 int an,bn;
146 BIGNUM ah,al,bh,bl;
147
148 bn_wexpand(m,num+3);
149 an=A->top;
150 bn=B->top;
151
152#ifdef BN_MUL_DEBUG
153printf("bn_mm_low(%d,%d,%d)\n",A->top,B->top,num);
154#endif
155
156 n=(num+1)/2;
157
158 BN_init(&ah); BN_init(&al); BN_init(&bh); BN_init(&bl);
159
160 bn_set_low( &al,A,n);
161 bn_set_high(&ah,A,n);
162 bn_set_low( &bl,B,n);
163 bn_set_high(&bh,B,n);
164
165 if (num <= (bn_limit_num_low+bn_limit_num_low))
166 {
167 BN_mul(m,&al,&bl);
168 BN_mul_low(&t1,&al,&bh,n);
169 BN_mul_low(&t2,&ah,&bl,n);
170 }
171 else
172 {
173 bn_mm(m ,&al,&bl,&(sk[2]),ctx);
174 bn_mm_low(&t1,&al,&bh,n,&(sk[2]),ctx);
175 bn_mm_low(&t2,&ah,&bl,n,&(sk[2]),ctx);
176 }
177
178 BN_add(&t1,&t1,&t2);
179
180 /* We will now do an evil hack instead of
181 * BN_lshift(&t1,&t1,n*BN_BITS2);
182 * BN_add(m,m,&t1);
183 * BN_mask_bits(m,num*BN_BITS2);
184 */
185 bn_set_high(&ah,m,n); ah.max=num+2;
186 BN_add(&ah,&ah,&t1);
187 m->top=num;
188
189 m->neg=A->neg^B->neg;
190 return(1);
191 }
192
193#undef t1 (sk[0])
194#undef t2 (sk[1])
diff --git a/src/lib/libcrypto/bn/old/bn_m.c b/src/lib/libcrypto/bn/old/bn_m.c
index 522beb02bc..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/bn_m.c
+++ b/src/lib/libcrypto/bn/old/bn_m.c
@@ -1,139 +0,0 @@
1/* crypto/bn/bn_m.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60/*#include "cryptlib.h"*/
61#include "bn_lcl.h"
62
63#define limit_bits 5 /* 2^5, or 32 words */
64#define limit_num (1<<limit_bits)
65
66int BN_m(BIGNUM *r, BIGNUM *a, BIGNUM *b)
67 {
68 BIGNUM *sk;
69 int i,n;
70
71 n=(BN_num_bits_word(a->top|b->top)-limit_bits);
72 n*=2;
73 sk=(BIGNUM *)malloc(sizeof(BIGNUM)*n);
74 for (i=0; i<n; i++)
75 BN_init(&(sk[i]));
76
77 return(BN_mm(r,a,b,&(sk[0])));
78 }
79
80#define ahal (sk[0])
81#define blbh (sk[1])
82
83/* r must be different to a and b */
84int BN_mm(BIGNUM *m, BIGNUM *A, BIGNUM *B, BIGNUM *sk)
85 {
86 int i,num,anum,bnum;
87 int an,bn;
88 BIGNUM ah,al,bh,bl;
89
90 an=A->top;
91 bn=B->top;
92 if ((an <= limit_num) || (bn <= limit_num))
93 {
94 return(BN_mul(m,A,B));
95 }
96
97 anum=(an>bn)?an:bn;
98 num=(anum)/2;
99
100 /* Are going to now chop things into 'num' word chunks. */
101 bnum=num*BN_BITS2;
102
103 BN_init(&ahal);
104 BN_init(&blbh);
105 BN_init(&ah);
106 BN_init(&al);
107 BN_init(&bh);
108 BN_init(&bl);
109
110 al.top=num;
111 al.d=A->d;
112 ah.top=A->top-num;
113 ah.d= &(A->d[num]);
114
115 bl.top=num;
116 bl.d=B->d;
117 bh.top=B->top-num;
118 bh.d= &(B->d[num]);
119
120 BN_sub(&ahal,&ah,&al);
121 BN_sub(&blbh,&bl,&bh);
122
123 BN_mm(m,&ahal,&blbh,&(sk[2]));
124 BN_mm(&ahal,&al,&bl,&(sk[2]));
125 BN_mm(&blbh,&ah,&bh,&(sk[2]));
126
127 BN_add(m,m,&ahal);
128 BN_add(m,m,&blbh);
129
130 BN_lshift(m,m,bnum);
131 BN_add(m,m,&ahal);
132
133 BN_lshift(&blbh,&blbh,bnum*2);
134 BN_add(m,m,&blbh);
135
136 m->neg=A->neg^B->neg;
137 return(1);
138 }
139
diff --git a/src/lib/libcrypto/bn/old/bn_mul.c.works b/src/lib/libcrypto/bn/old/bn_mul.c.works
index 6d565d44a2..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/bn_mul.c.works
+++ b/src/lib/libcrypto/bn/old/bn_mul.c.works
@@ -1,219 +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
63int bn_mm(BIGNUM *m,BIGNUM *A,BIGNUM *B, BIGNUM *sk,BN_CTX *ctx);
64
65/* r must be different to a and b */
66int BN_mul(r, a, b)
67BIGNUM *r;
68BIGNUM *a;
69BIGNUM *b;
70 {
71 BN_ULONG *ap,*bp,*rp;
72 BIGNUM *sk;
73 int i,n,ret;
74 int max,al,bl;
75 BN_CTX ctx;
76
77 bn_check_top(a);
78 bn_check_top(b);
79
80 al=a->top;
81 bl=b->top;
82 if ((al == 0) || (bl == 0))
83 {
84 r->top=0;
85 return(1);
86 }
87#ifdef BN_MUL_DEBUG
88printf("BN_mul(%d,%d)\n",a->top,b->top);
89#endif
90
91#ifdef BN_RECURSION
92 if ( (bn_limit_bits > 0) &&
93 (bl > bn_limit_num) && (al > bn_limit_num))
94 {
95 n=(BN_num_bits_word(al|bl)-bn_limit_bits);
96 n*=2;
97 sk=(BIGNUM *)Malloc(sizeof(BIGNUM)*n);
98 memset(sk,0,sizeof(BIGNUM)*n);
99 memset(&ctx,0,sizeof(ctx));
100
101 ret=bn_mm(r,a,b,&(sk[0]),&ctx);
102 for (i=0; i<n; i+=2)
103 {
104 BN_clear_free(&sk[i]);
105 BN_clear_free(&sk[i+1]);
106 }
107 Free(sk);
108 return(ret);
109 }
110#endif
111
112 max=(al+bl);
113 if (bn_wexpand(r,max) == NULL) return(0);
114 r->top=max;
115 r->neg=a->neg^b->neg;
116 ap=a->d;
117 bp=b->d;
118 rp=r->d;
119
120#ifdef BN_RECURSION
121 if ((al == bl) && (al == 8))
122 {
123 bn_mul_comba8(rp,ap,bp);
124 }
125 else
126#endif
127 {
128 rp[al]=bn_mul_words(rp,ap,al,*(bp++));
129 rp++;
130 for (i=1; i<bl; i++)
131 {
132 rp[al]=bn_mul_add_words(rp,ap,al,*(bp++));
133 rp++;
134 }
135 }
136 if ((max > 0) && (r->d[max-1] == 0)) r->top--;
137 return(1);
138 }
139
140#ifdef BN_RECURSION
141
142#define ahal (sk[0])
143#define blbh (sk[1])
144
145/* r must be different to a and b */
146int bn_mm(m, A, B, sk,ctx)
147BIGNUM *m,*A,*B;
148BIGNUM *sk;
149BN_CTX *ctx;
150 {
151 int n,num,sqr=0;
152 int an,bn;
153 BIGNUM ah,al,bh,bl;
154
155 an=A->top;
156 bn=B->top;
157#ifdef BN_MUL_DEBUG
158printf("bn_mm(%d,%d)\n",A->top,B->top);
159#endif
160
161 if (A == B) sqr=1;
162 num=(an>bn)?an:bn;
163 n=(num+1)/2;
164 /* Are going to now chop things into 'num' word chunks. */
165
166 BN_init(&ah);
167 BN_init(&al);
168 BN_init(&bh);
169 BN_init(&bl);
170
171 bn_set_low (&al,A,n);
172 bn_set_high(&ah,A,n);
173 bn_set_low (&bl,B,n);
174 bn_set_high(&bh,B,n);
175
176 BN_sub(&ahal,&ah,&al);
177 BN_sub(&blbh,&bl,&bh);
178
179 if (num <= (bn_limit_num+bn_limit_num))
180 {
181 BN_mul(m,&ahal,&blbh);
182 if (sqr)
183 {
184 BN_sqr(&ahal,&al,ctx);
185 BN_sqr(&blbh,&ah,ctx);
186 }
187 else
188 {
189 BN_mul(&ahal,&al,&bl);
190 BN_mul(&blbh,&ah,&bh);
191 }
192 }
193 else
194 {
195 bn_mm(m,&ahal,&blbh,&(sk[2]),ctx);
196 bn_mm(&ahal,&al,&bl,&(sk[2]),ctx);
197 bn_mm(&blbh,&ah,&bh,&(sk[2]),ctx);
198 }
199
200 BN_add(m,m,&ahal);
201 BN_add(m,m,&blbh);
202
203 BN_lshift(m,m,n*BN_BITS2);
204 BN_lshift(&blbh,&blbh,n*BN_BITS2*2);
205
206 BN_add(m,m,&ahal);
207 BN_add(m,m,&blbh);
208
209 m->neg=A->neg^B->neg;
210 return(1);
211 }
212#undef ahal (sk[0])
213#undef blbh (sk[1])
214
215#include "bn_low.c"
216#include "bn_high.c"
217#include "f.c"
218
219#endif
diff --git a/src/lib/libcrypto/bn/old/bn_wmul.c b/src/lib/libcrypto/bn/old/bn_wmul.c
index a467b2f17a..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/bn_wmul.c
+++ b/src/lib/libcrypto/bn/old/bn_wmul.c
@@ -1,173 +0,0 @@
1#include <stdio.h>
2#include "bn_lcl.h"
3
4#if 1
5
6int bn_mull(BIGNUM *r,BIGNUM *a,BIGNUM *b, BN_CTX *ctx);
7
8int bn_mull(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
9 {
10 int top,i,j,k,al,bl;
11 BIGNUM *t;
12
13#ifdef BN_COUNT
14printf("bn_mull %d * %d\n",a->top,b->top);
15#endif
16
17 bn_check_top(a);
18 bn_check_top(b);
19 bn_check_top(r);
20
21 al=a->top;
22 bl=b->top;
23 r->neg=a->neg^b->neg;
24
25 top=al+bl;
26 if ((al < 4) || (bl < 4))
27 {
28 if (bn_wexpand(r,top) == NULL) return(0);
29 r->top=top;
30 bn_mul_normal(r->d,a->d,al,b->d,bl);
31 goto end;
32 }
33 else if (al == bl) /* A good start, they are the same size */
34 goto symetric;
35 else
36 {
37 i=(al-bl);
38 if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))
39 {
40 bn_wexpand(b,al);
41 b->d[bl]=0;
42 bl++;
43 goto symetric;
44 }
45 else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))
46 {
47 bn_wexpand(a,bl);
48 a->d[al]=0;
49 al++;
50 goto symetric;
51 }
52 }
53
54 /* asymetric and >= 4 */
55 if (bn_wexpand(r,top) == NULL) return(0);
56 r->top=top;
57 bn_mul_normal(r->d,a->d,al,b->d,bl);
58
59 if (0)
60 {
61 /* symetric and > 4 */
62symetric:
63 if (al == 4)
64 {
65 if (bn_wexpand(r,al*2) == NULL) return(0);
66 r->top=top;
67 bn_mul_comba4(r->d,a->d,b->d);
68 goto end;
69 }
70 if (al == 8)
71 {
72 if (bn_wexpand(r,al*2) == NULL) return(0);
73 r->top=top;
74 bn_mul_comba8(r->d,a->d,b->d);
75 goto end;
76 }
77 if (al <= BN_MULL_NORMAL_SIZE)
78 {
79 if (bn_wexpand(r,al*2) == NULL) return(0);
80 r->top=top;
81 bn_mul_normal(r->d,a->d,al,b->d,bl);
82 goto end;
83 }
84 /* 16 or larger */
85 j=BN_num_bits_word((BN_ULONG)al);
86 j=1<<(j-1);
87 k=j+j;
88 t= &(ctx->bn[ctx->tos]);
89 if (al == j) /* exact multiple */
90 {
91 bn_wexpand(t,k*2);
92 bn_wexpand(r,k*2);
93 bn_mul_recursive(r->d,a->d,b->d,al,t->d);
94 }
95 else
96 {
97 bn_wexpand(a,k);
98 bn_wexpand(b,k);
99 bn_wexpand(t,k*4);
100 bn_wexpand(r,k*4);
101 for (i=a->top; i<k; i++)
102 a->d[i]=0;
103 for (i=b->top; i<k; i++)
104 b->d[i]=0;
105 bn_mul_part_recursive(r->d,a->d,b->d,al-j,j,t->d);
106 }
107 r->top=top;
108 }
109end:
110 bn_fix_top(r);
111 return(1);
112 }
113#endif
114
115void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
116 {
117 BN_ULONG *rr;
118
119#ifdef BN_COUNT
120printf(" bn_mul_normal %d * %d\n",na,nb);
121#endif
122
123 if (na < nb)
124 {
125 int itmp;
126 BN_ULONG *ltmp;
127
128 itmp=na; na=nb; nb=itmp;
129 ltmp=a; a=b; b=ltmp;
130
131 }
132 rr= &(r[na]);
133 rr[0]=bn_mul_words(r,a,na,b[0]);
134
135 for (;;)
136 {
137 if (--nb <= 0) return;
138 rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
139 if (--nb <= 0) return;
140 rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
141 if (--nb <= 0) return;
142 rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
143 if (--nb <= 0) return;
144 rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
145 rr+=4;
146 r+=4;
147 b+=4;
148 }
149 }
150
151#if 1
152void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
153 {
154#ifdef BN_COUNT
155printf(" bn_mul_low_normal %d * %d\n",n,n);
156#endif
157 bn_mul_words(r,a,n,b[0]);
158
159 for (;;)
160 {
161 if (--n <= 0) return;
162 bn_mul_add_words(&(r[1]),a,n,b[1]);
163 if (--n <= 0) return;
164 bn_mul_add_words(&(r[2]),a,n,b[2]);
165 if (--n <= 0) return;
166 bn_mul_add_words(&(r[3]),a,n,b[3]);
167 if (--n <= 0) return;
168 bn_mul_add_words(&(r[4]),a,n,b[4]);
169 r+=4;
170 b+=4;
171 }
172 }
173#endif
diff --git a/src/lib/libcrypto/bn/old/build b/src/lib/libcrypto/bn/old/build
index 8cd99e5f17..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/build
+++ b/src/lib/libcrypto/bn/old/build
@@ -1,3 +0,0 @@
1#!/bin/sh -x
2
3gcc -g -I../../include test.c -L../.. -lcrypto
diff --git a/src/lib/libcrypto/bn/old/info b/src/lib/libcrypto/bn/old/info
index 5ac99c3b23..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/info
+++ b/src/lib/libcrypto/bn/old/info
@@ -1,22 +0,0 @@
1Given A1A0 * B1B0 == S3S2S1S0
2
3S0= low(A0*B0)
4S1= low( (A1-A0)*(B0-B1)) +low( A1*B1) +high(A0*B0)
5S2= high((A1-A0)*(B0-B1)) +high(A1*B1) +low( A1*B1)
6S3= high(A1*B1);
7
8Assume we know S1 and S0, and can calulate A1*B1 and high((A1-A0)*(B0-B1))
9
10k0= S0 == low(A0*B0)
11k1= S1
12k2= low( A1*B1)
13k3= high(A1*B1)
14k4= high((A1-A0)*(B0-B1))
15
16k1= low((A1-A0)*(B0-B1)) +k2 +high(A0*B0)
17S2= k4 +k3 +k2
18S3= k3
19
20S1-k2= low((A1-A0)*(B0-B1)) +high(A0*B0)
21
22We potentially have a carry or a borrow from S1
diff --git a/src/lib/libcrypto/bn/old/test.works b/src/lib/libcrypto/bn/old/test.works
index 127c7b415d..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/old/test.works
+++ b/src/lib/libcrypto/bn/old/test.works
@@ -1,205 +0,0 @@
1#include <stdio.h>
2#include "cryptlib.h"
3#include "bn_lcl.h"
4
5#define SIZE 128
6
7#define BN_MONT_CTX_set bn_mcs
8#define BN_from_montgomery bn_fm
9#define BN_mod_mul_montgomery bn_mmm
10#undef BN_to_montgomery
11#define BN_to_montgomery(r,a,mont,ctx) bn_mmm(\
12 r,a,(mont)->RR,(mont),ctx)
13
14main()
15 {
16 BIGNUM prime,a,b,r,A,B,R;
17 BN_MONT_CTX *mont;
18 BN_CTX *ctx;
19 int i;
20
21 ctx=BN_CTX_new();
22 BN_init(&prime);
23 BN_init(&a); BN_init(&b); BN_init(&r);
24 BN_init(&A); BN_init(&B); BN_init(&R);
25
26 BN_generate_prime(&prime,SIZE,0,NULL,NULL,NULL,NULL);
27 BN_rand(&A,SIZE,1,0);
28 BN_rand(&B,SIZE,1,0);
29 BN_mod(&A,&A,&prime,ctx);
30 BN_mod(&B,&B,&prime,ctx);
31
32 mont=BN_MONT_CTX_new();
33 BN_MONT_CTX_set(mont,&prime,ctx);
34
35 BN_to_montgomery(&a,&A,mont,ctx);
36 BN_to_montgomery(&b,&B,mont,ctx);
37
38 BN_mul(&r,&a,&b);
39 BN_print_fp(stdout,&r); printf("\n");
40 BN_from_montgomery(&r,&r,mont,ctx);
41 BN_print_fp(stdout,&r); printf("\n");
42 BN_from_montgomery(&r,&r,mont,ctx);
43 BN_print_fp(stdout,&r); printf("\n");
44
45 BN_mod_mul(&R,&A,&B,&prime,ctx);
46
47 BN_print_fp(stdout,&a); printf("\n");
48 BN_print_fp(stdout,&b); printf("\n");
49 BN_print_fp(stdout,&prime); printf("\n");
50 BN_print_fp(stdout,&r); printf("\n\n");
51
52 BN_print_fp(stdout,&A); printf("\n");
53 BN_print_fp(stdout,&B); printf("\n");
54 BN_print_fp(stdout,&prime); printf("\n");
55 BN_print_fp(stdout,&R); printf("\n\n");
56
57 BN_mul(&r,&a,&b);
58 BN_print_fp(stdout,&r); printf(" <- BA*DC\n");
59 BN_copy(&A,&r);
60 i=SIZE/2;
61 BN_mask_bits(&A,i*2);
62// BN_print_fp(stdout,&A); printf(" <- low(BA*DC)\n");
63 bn_do_lower(&r,&a,&b,&A,i);
64// BN_print_fp(stdout,&r); printf(" <- low(BA*DC)\n");
65 }
66
67int bn_mul_low(r,a,b,low,i)
68BIGNUM *r,*a,*b,*low;
69int i;
70 {
71 int w;
72 BIGNUM Kh,Km,t1,t2,h,ah,al,bh,bl,l,m,s0,s1;
73
74 BN_init(&Kh); BN_init(&Km); BN_init(&t1); BN_init(&t2); BN_init(&l);
75 BN_init(&ah); BN_init(&al); BN_init(&bh); BN_init(&bl); BN_init(&h);
76 BN_init(&m); BN_init(&s0); BN_init(&s1);
77
78 BN_copy(&al,a); BN_mask_bits(&al,i); BN_rshift(&ah,a,i);
79 BN_copy(&bl,b); BN_mask_bits(&bl,i); BN_rshift(&bh,b,i);
80
81
82 BN_sub(&t1,&al,&ah);
83 BN_sub(&t2,&bh,&bl);
84 BN_mul(&m,&t1,&t2);
85 BN_mul(&h,&ah,&bh);
86
87 BN_copy(&s0,low); BN_mask_bits(&s0,i);
88 BN_rshift(&s1,low,i);
89
90 BN_add(&t1,&h,&m);
91 BN_add(&t1,&t1,&s0);
92
93 BN_copy(&t2,&t1); BN_mask_bits(&t2,i);
94 BN_sub(&t1,&s1,&t2);
95 BN_lshift(&t1,&t1,i);
96 BN_add(&t1,&t1,&s0);
97 if (t1.neg)
98 {
99 BN_lshift(&t2,BN_value_one(),i*2);
100 BN_add(&t1,&t2,&t1);
101 BN_mask_bits(&t1,i*2);
102 }
103
104 BN_free(&Kh); BN_free(&Km); BN_free(&t1); BN_free(&t2);
105 BN_free(&ah); BN_free(&al); BN_free(&bh); BN_free(&bl);
106 }
107
108int BN_mod_mul_montgomery(r,a,b,mont,ctx)
109BIGNUM *r,*a,*b;
110BN_MONT_CTX *mont;
111BN_CTX *ctx;
112 {
113 BIGNUM *tmp;
114
115 tmp= &(ctx->bn[ctx->tos++]);
116
117 if (a == b)
118 {
119 if (!BN_sqr(tmp,a,ctx)) goto err;
120 }
121 else
122 {
123 if (!BN_mul(tmp,a,b)) goto err;
124 }
125 /* reduce from aRR to aR */
126 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
127 ctx->tos--;
128 return(1);
129err:
130 return(0);
131 }
132
133int BN_from_montgomery(r,a,mont,ctx)
134BIGNUM *r;
135BIGNUM *a;
136BN_MONT_CTX *mont;
137BN_CTX *ctx;
138 {
139 BIGNUM z1;
140 BIGNUM *t1,*t2;
141 BN_ULONG *ap,*bp,*rp;
142 int j,i,bl,al;
143
144 BN_init(&z1);
145 t1= &(ctx->bn[ctx->tos]);
146 t2= &(ctx->bn[ctx->tos+1]);
147
148 if (!BN_copy(t1,a)) goto err;
149 /* can cheat */
150 BN_mask_bits(t1,mont->ri);
151 if (!BN_mul(t2,t1,mont->Ni)) goto err;
152 BN_mask_bits(t2,mont->ri);
153
154 if (!BN_mul(t1,t2,mont->N)) goto err;
155 if (!BN_add(t2,t1,a)) goto err;
156
157 /* At this point, t2 has the bottom ri bits set to zero.
158 * This means that the bottom ri bits == the 1^ri minus the bottom
159 * ri bits of a.
160 * This means that only the bits above 'ri' in a need to be added,
161 * and XXXXXXXXXXXXXXXXXXXXXXXX
162 */
163BN_print_fp(stdout,t2); printf("\n");
164 BN_rshift(r,t2,mont->ri);
165
166 if (BN_ucmp(r,mont->N) >= 0)
167 bn_qsub(r,r,mont->N);
168
169 return(1);
170err:
171 return(0);
172 }
173
174int BN_MONT_CTX_set(mont,mod,ctx)
175BN_MONT_CTX *mont;
176BIGNUM *mod;
177BN_CTX *ctx;
178 {
179 BIGNUM *Ri=NULL,*R=NULL;
180
181 if (mont->RR == NULL) mont->RR=BN_new();
182 if (mont->N == NULL) mont->N=BN_new();
183
184 R=mont->RR; /* grab RR as a temp */
185 BN_copy(mont->N,mod); /* Set N */
186
187 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
188 BN_lshift(R,BN_value_one(),mont->ri); /* R */
189 if ((Ri=BN_mod_inverse(NULL,R,mod,ctx)) == NULL) goto err;/* Ri */
190 BN_lshift(Ri,Ri,mont->ri); /* R*Ri */
191 bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */
192 BN_div(Ri,NULL,Ri,mod,ctx);
193 if (mont->Ni != NULL) BN_free(mont->Ni);
194 mont->Ni=Ri; /* Ni=(R*Ri-1)/N */
195
196 /* setup RR for conversions */
197 BN_lshift(mont->RR,BN_value_one(),mont->ri*2);
198 BN_mod(mont->RR,mont->RR,mont->N,ctx);
199
200 return(1);
201err:
202 return(0);
203 }
204
205
diff --git a/src/lib/libcrypto/bn/test.c b/src/lib/libcrypto/bn/test.c
index a048b9f878..e69de29bb2 100644
--- a/src/lib/libcrypto/bn/test.c
+++ b/src/lib/libcrypto/bn/test.c
@@ -1,241 +0,0 @@
1#include <stdio.h>
2#include "cryptlib.h"
3#include "bn_lcl.h"
4
5#define SIZE 32
6
7#define BN_MONT_CTX_set bn_mcs
8#define BN_from_montgomery bn_fm
9#define BN_mod_mul_montgomery bn_mmm
10#undef BN_to_montgomery
11#define BN_to_montgomery(r,a,mont,ctx) bn_mmm(\
12 r,a,(mont)->RR,(mont),ctx)
13
14main()
15 {
16 BIGNUM prime,a,b,r,A,B,R;
17 BN_MONT_CTX *mont;
18 BN_CTX *ctx;
19 int i;
20
21 ctx=BN_CTX_new();
22 BN_init(&prime);
23 BN_init(&a); BN_init(&b); BN_init(&r);
24 BN_init(&A); BN_init(&B); BN_init(&R);
25
26 BN_generate_prime(&prime,SIZE,0,NULL,NULL,NULL,NULL);
27 BN_rand(&A,SIZE,1,0);
28 BN_rand(&B,SIZE,1,0);
29 BN_mod(&A,&A,&prime,ctx);
30 BN_mod(&B,&B,&prime,ctx);
31
32 i=A.top;
33 BN_mul(&R,&A,&B,ctx);
34 BN_mask_bits(&R,i*BN_BITS2);
35
36
37 BN_print_fp(stdout,&A); printf(" <- a\n");
38 BN_print_fp(stdout,&B); printf(" <- b\n");
39 BN_mul_high(&r,&A,&B,&R,i);
40 BN_print_fp(stdout,&r); printf(" <- high(BA*DC)\n");
41
42 BN_mask_bits(&A,i*32);
43 BN_mask_bits(&B,i*32);
44
45 BN_mul(&R,&A,&B);
46 BN_rshift(&R,&R,i*32);
47 BN_print_fp(stdout,&R); printf(" <- norm BA*DC\n");
48 BN_sub(&R,&R,&r);
49 BN_print_fp(stdout,&R); printf(" <- diff\n");
50 }
51
52#if 0
53int bn_mul_high(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *low, int words)
54 {
55 int i;
56 BIGNUM t1,t2,t3,h,ah,al,bh,bl,m,s0,s1;
57
58 BN_init(&al); BN_init(&ah);
59 BN_init(&bl); BN_init(&bh);
60 BN_init(&t1); BN_init(&t2); BN_init(&t3);
61 BN_init(&s0); BN_init(&s1);
62 BN_init(&h); BN_init(&m);
63
64 i=a->top;
65 if (i >= words)
66 {
67 al.top=words;
68 ah.top=a->top-words;
69 ah.d= &(a->d[ah.top]);
70 }
71 else
72 al.top=i;
73 al.d=a->d;
74
75 i=b->top;
76 if (i >= words)
77 {
78 bl.top=words;
79 bh.top=i-words;
80 bh.d= &(b->d[bh.top]);
81 }
82 else
83 bl.top=i;
84 bl.d=b->d;
85
86 i=low->top;
87 if (i >= words)
88 {
89 s0.top=words;
90 s1.top=i-words;
91 s1.d= &(low->d[s1.top]);
92 }
93 else
94 s0.top=i;
95 s0.d=low->d;
96
97al.max=al.top; ah.max=ah.top;
98bl.max=bl.top; bh.max=bh.top;
99s0.max=bl.top; s1.max=bh.top;
100
101 /* Calculate (al-ah)*(bh-bl) */
102 BN_sub(&t1,&al,&ah);
103 BN_sub(&t2,&bh,&bl);
104 BN_mul(&m,&t1,&t2);
105
106 /* Calculate ah*bh */
107 BN_mul(&h,&ah,&bh);
108
109 /* s0 == low(al*bl)
110 * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl)
111 * We know s0 and s1 so the only unknown is high(al*bl)
112 * high(al*bl) == s1 - low(ah*bh+(al-ah)*(bh-bl)+s0)
113 */
114 BN_add(&m,&m,&h);
115 BN_add(&t2,&m,&s0);
116 /* Quick and dirty mask off of high words */
117 t3.d=t2.d;
118 t3.top=(t2.top > words)?words:t2.top;
119 t3.neg=t2.neg;
120t3.max=t3.top;
121/* BN_print_fp(stdout,&s1); printf(" s1\n"); */
122/* BN_print_fp(stdout,&t2); printf(" middle value\n"); */
123/* BN_print_fp(stdout,&t3); printf(" low middle value\n"); */
124 BN_sub(&t1,&s1,&t3);
125
126 if (t1.neg)
127 {
128/*printf("neg fixup\n"); BN_print_fp(stdout,&t1); printf(" before\n"); */
129 BN_lshift(&t2,BN_value_one(),words*32);
130 BN_add(&t1,&t2,&t1);
131 BN_mask_bits(&t1,words*32);
132/* BN_print_fp(stdout,&t1); printf(" after\n"); */
133 }
134 /* al*bl == high(al*bl)<<words+s0 */
135 BN_lshift(&t1,&t1,words*32);
136 BN_add(&t1,&t1,&s0);
137
138 /* We now have
139 * al*bl - t1
140 * (al-ah)*(bh-bl)+ah*bh - m
141 * ah*bh - h
142 */
143 BN_copy(r,&t1);
144 BN_mask_bits(r,words*32*2);
145
146 /*BN_lshift(&m,&m,words*/
147
148 BN_free(&t1); BN_free(&t2);
149 BN_free(&m); BN_free(&h);
150 }
151
152int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,
153 BN_CTX *ctx)
154 {
155 BIGNUM *tmp;
156
157 tmp= &(ctx->bn[ctx->tos++]);
158
159 if (a == b)
160 {
161 if (!BN_sqr(tmp,a,ctx)) goto err;
162 }
163 else
164 {
165 if (!BN_mul(tmp,a,b)) goto err;
166 }
167 /* reduce from aRR to aR */
168 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
169 ctx->tos--;
170 return(1);
171err:
172 return(0);
173 }
174
175int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont, BN_CTX *ctx)
176 {
177 BIGNUM z1;
178 BIGNUM *t1,*t2;
179 BN_ULONG *ap,*bp,*rp;
180 int j,i,bl,al;
181
182 BN_init(&z1);
183 t1= &(ctx->bn[ctx->tos]);
184 t2= &(ctx->bn[ctx->tos+1]);
185
186 if (!BN_copy(t1,a)) goto err;
187 /* can cheat */
188 BN_mask_bits(t1,mont->ri);
189 if (!BN_mul(t2,t1,mont->Ni)) goto err;
190 BN_mask_bits(t2,mont->ri);
191
192 if (!BN_mul(t1,t2,mont->N)) goto err;
193 if (!BN_add(t2,t1,a)) goto err;
194
195 /* At this point, t2 has the bottom ri bits set to zero.
196 * This means that the bottom ri bits == the 1^ri minus the bottom
197 * ri bits of a.
198 * This means that only the bits above 'ri' in a need to be added,
199 * and XXXXXXXXXXXXXXXXXXXXXXXX
200 */
201BN_print_fp(stdout,t2); printf("\n");
202 BN_rshift(r,t2,mont->ri);
203
204 if (BN_ucmp(r,mont->N) >= 0)
205 BN_usub(r,r,mont->N);
206
207 return(1);
208err:
209 return(0);
210 }
211
212int BN_MONT_CTX_set(BN_MONT_CTX *mont, BIGNUM *mod, BN_CTX *ctx)
213 {
214 BIGNUM *Ri=NULL,*R=NULL;
215
216 if (mont->RR == NULL) mont->RR=BN_new();
217 if (mont->N == NULL) mont->N=BN_new();
218
219 R=mont->RR; /* grab RR as a temp */
220 BN_copy(mont->N,mod); /* Set N */
221
222 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
223 BN_lshift(R,BN_value_one(),mont->ri); /* R */
224 if ((Ri=BN_mod_inverse(NULL,R,mod,ctx)) == NULL) goto err;/* Ri */
225 BN_lshift(Ri,Ri,mont->ri); /* R*Ri */
226 BN_usub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */
227 BN_div(Ri,NULL,Ri,mod,ctx);
228 if (mont->Ni != NULL) BN_free(mont->Ni);
229 mont->Ni=Ri; /* Ni=(R*Ri-1)/N */
230
231 /* setup RR for conversions */
232 BN_lshift(mont->RR,BN_value_one(),mont->ri*2);
233 BN_mod(mont->RR,mont->RR,mont->N,ctx);
234
235 return(1);
236err:
237 return(0);
238 }
239
240
241#endif
diff --git a/src/lib/libcrypto/buffer/Makefile.ssl b/src/lib/libcrypto/buffer/Makefile.ssl
index f23de89e33..506708c37f 100644
--- a/src/lib/libcrypto/buffer/Makefile.ssl
+++ b/src/lib/libcrypto/buffer/Makefile.ssl
@@ -83,4 +83,5 @@ buffer.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
83buffer.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 83buffer.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
84buffer.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 84buffer.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85buffer.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 85buffer.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
86buffer.o: ../../include/openssl/stack.h ../cryptlib.h 86buffer.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
87buffer.o: ../cryptlib.h
diff --git a/src/lib/libcrypto/cast/c_ecb.c b/src/lib/libcrypto/cast/c_ecb.c
index 33182f2b71..0b3da9ad87 100644
--- a/src/lib/libcrypto/cast/c_ecb.c
+++ b/src/lib/libcrypto/cast/c_ecb.c
@@ -60,7 +60,7 @@
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63char *CAST_version="CAST" OPENSSL_VERSION_PTEXT; 63const char *CAST_version="CAST" OPENSSL_VERSION_PTEXT;
64 64
65void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, 65void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
66 CAST_KEY *ks, int enc) 66 CAST_KEY *ks, int enc)
diff --git a/src/lib/libcrypto/cast/cast_lcl.h b/src/lib/libcrypto/cast/cast_lcl.h
index 83cf382a91..cfe3842e91 100644
--- a/src/lib/libcrypto/cast/cast_lcl.h
+++ b/src/lib/libcrypto/cast/cast_lcl.h
@@ -216,11 +216,11 @@
216 } 216 }
217#endif 217#endif
218 218
219OPENSSL_EXTERN CAST_LONG CAST_S_table0[256]; 219OPENSSL_EXTERN const CAST_LONG CAST_S_table0[256];
220OPENSSL_EXTERN CAST_LONG CAST_S_table1[256]; 220OPENSSL_EXTERN const CAST_LONG CAST_S_table1[256];
221OPENSSL_EXTERN CAST_LONG CAST_S_table2[256]; 221OPENSSL_EXTERN const CAST_LONG CAST_S_table2[256];
222OPENSSL_EXTERN CAST_LONG CAST_S_table3[256]; 222OPENSSL_EXTERN const CAST_LONG CAST_S_table3[256];
223OPENSSL_EXTERN CAST_LONG CAST_S_table4[256]; 223OPENSSL_EXTERN const CAST_LONG CAST_S_table4[256];
224OPENSSL_EXTERN CAST_LONG CAST_S_table5[256]; 224OPENSSL_EXTERN const CAST_LONG CAST_S_table5[256];
225OPENSSL_EXTERN CAST_LONG CAST_S_table6[256]; 225OPENSSL_EXTERN const CAST_LONG CAST_S_table6[256];
226OPENSSL_EXTERN CAST_LONG CAST_S_table7[256]; 226OPENSSL_EXTERN const CAST_LONG CAST_S_table7[256];
diff --git a/src/lib/libcrypto/cast/cast_s.h b/src/lib/libcrypto/cast/cast_s.h
index 9af28972c5..c483fd5e43 100644
--- a/src/lib/libcrypto/cast/cast_s.h
+++ b/src/lib/libcrypto/cast/cast_s.h
@@ -55,7 +55,7 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58OPENSSL_GLOBAL CAST_LONG CAST_S_table0[256]={ 58OPENSSL_GLOBAL const CAST_LONG CAST_S_table0[256]={
59 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a, 59 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a,
60 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949, 60 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949,
61 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675, 61 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675,
@@ -121,7 +121,7 @@ OPENSSL_GLOBAL CAST_LONG CAST_S_table0[256]={
121 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d, 121 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d,
122 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf, 122 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf,
123 }; 123 };
124OPENSSL_GLOBAL CAST_LONG CAST_S_table1[256]={ 124OPENSSL_GLOBAL const CAST_LONG CAST_S_table1[256]={
125 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380, 125 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380,
126 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651, 126 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651,
127 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba, 127 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba,
@@ -187,7 +187,7 @@ OPENSSL_GLOBAL CAST_LONG CAST_S_table1[256]={
187 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef, 187 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef,
188 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1, 188 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1,
189 }; 189 };
190OPENSSL_GLOBAL CAST_LONG CAST_S_table2[256]={ 190OPENSSL_GLOBAL const CAST_LONG CAST_S_table2[256]={
191 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907, 191 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907,
192 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90, 192 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90,
193 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae, 193 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae,
@@ -253,7 +253,7 @@ OPENSSL_GLOBAL CAST_LONG CAST_S_table2[256]={
253 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5, 253 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5,
254 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783, 254 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783,
255 }; 255 };
256OPENSSL_GLOBAL CAST_LONG CAST_S_table3[256]={ 256OPENSSL_GLOBAL const CAST_LONG CAST_S_table3[256]={
257 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298, 257 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298,
258 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1, 258 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1,
259 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120, 259 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120,
@@ -319,7 +319,7 @@ OPENSSL_GLOBAL CAST_LONG CAST_S_table3[256]={
319 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e, 319 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e,
320 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2, 320 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2,
321 }; 321 };
322OPENSSL_GLOBAL CAST_LONG CAST_S_table4[256]={ 322OPENSSL_GLOBAL const CAST_LONG CAST_S_table4[256]={
323 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911, 323 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911,
324 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f, 324 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f,
325 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00, 325 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00,
@@ -385,7 +385,7 @@ OPENSSL_GLOBAL CAST_LONG CAST_S_table4[256]={
385 0xe822fe15,0x88570983,0x750e6249,0xda627e55, 385 0xe822fe15,0x88570983,0x750e6249,0xda627e55,
386 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4, 386 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4,
387 }; 387 };
388OPENSSL_GLOBAL CAST_LONG CAST_S_table5[256]={ 388OPENSSL_GLOBAL const CAST_LONG CAST_S_table5[256]={
389 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c, 389 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c,
390 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac, 390 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac,
391 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9, 391 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9,
@@ -451,7 +451,7 @@ OPENSSL_GLOBAL CAST_LONG CAST_S_table5[256]={
451 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454, 451 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454,
452 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f, 452 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f,
453 }; 453 };
454OPENSSL_GLOBAL CAST_LONG CAST_S_table6[256]={ 454OPENSSL_GLOBAL const CAST_LONG CAST_S_table6[256]={
455 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693, 455 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693,
456 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f, 456 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f,
457 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82, 457 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82,
@@ -517,7 +517,7 @@ OPENSSL_GLOBAL CAST_LONG CAST_S_table6[256]={
517 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada, 517 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada,
518 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3, 518 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3,
519 }; 519 };
520OPENSSL_GLOBAL CAST_LONG CAST_S_table7[256]={ 520OPENSSL_GLOBAL const CAST_LONG CAST_S_table7[256]={
521 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095, 521 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095,
522 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5, 522 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5,
523 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174, 523 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174,
diff --git a/src/lib/libcrypto/cast/cast_spd.c b/src/lib/libcrypto/cast/cast_spd.c
index c0726906c2..0af915cf20 100644
--- a/src/lib/libcrypto/cast/cast_spd.c
+++ b/src/lib/libcrypto/cast/cast_spd.c
@@ -183,7 +183,7 @@ int main(int argc, char **argv)
183#endif 183#endif
184 184
185#ifndef TIMES 185#ifndef TIMES
186 printf("To get the most acurate results, try to run this\n"); 186 printf("To get the most accurate results, try to run this\n");
187 printf("program when this computer is idle.\n"); 187 printf("program when this computer is idle.\n");
188#endif 188#endif
189 189
diff --git a/src/lib/libcrypto/cast/castopts.c b/src/lib/libcrypto/cast/castopts.c
index 642e9725af..c783796610 100644
--- a/src/lib/libcrypto/cast/castopts.c
+++ b/src/lib/libcrypto/cast/castopts.c
@@ -252,7 +252,7 @@ int main(int argc, char **argv)
252 } 252 }
253 253
254#ifndef TIMES 254#ifndef TIMES
255 fprintf(stderr,"To get the most acurate results, try to run this\n"); 255 fprintf(stderr,"To get the most accurate results, try to run this\n");
256 fprintf(stderr,"program when this computer is idle.\n"); 256 fprintf(stderr,"program when this computer is idle.\n");
257#endif 257#endif
258 258
diff --git a/src/lib/libcrypto/cast/casttest.c b/src/lib/libcrypto/cast/casttest.c
index 3244b119e9..ab2aeac606 100644
--- a/src/lib/libcrypto/cast/casttest.c
+++ b/src/lib/libcrypto/cast/casttest.c
@@ -71,32 +71,32 @@ int main(int argc, char *argv[])
71 71
72#define FULL_TEST 72#define FULL_TEST
73 73
74unsigned char k[16]={ 74static unsigned char k[16]={
75 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, 75 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
76 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A 76 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
77 }; 77 };
78 78
79unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; 79static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
80 80
81int k_len[3]={16,10,5}; 81static int k_len[3]={16,10,5};
82unsigned char c[3][8]={ 82static unsigned char c[3][8]={
83 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, 83 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
84 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, 84 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
85 {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E}, 85 {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
86 }; 86 };
87unsigned char out[80]; 87static unsigned char out[80];
88 88
89unsigned char in_a[16]={ 89static unsigned char in_a[16]={
90 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, 90 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
91 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; 91 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
92unsigned char in_b[16]={ 92static unsigned char in_b[16]={
93 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, 93 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
94 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; 94 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
95 95
96unsigned char c_a[16]={ 96static unsigned char c_a[16]={
97 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6, 97 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
98 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92}; 98 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
99unsigned char c_b[16]={ 99static unsigned char c_b[16]={
100 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71, 100 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
101 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E}; 101 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
102 102
diff --git a/src/lib/libcrypto/comp/comp.h b/src/lib/libcrypto/comp/comp.h
index 93bd9c34c8..811cb5833d 100644
--- a/src/lib/libcrypto/comp/comp.h
+++ b/src/lib/libcrypto/comp/comp.h
@@ -17,6 +17,7 @@ typedef struct comp_method_st
17 int (*compress)(); 17 int (*compress)();
18 int (*expand)(); 18 int (*expand)();
19 long (*ctrl)(); 19 long (*ctrl)();
20 long (*callback_ctrl)();
20 } COMP_METHOD; 21 } COMP_METHOD;
21 22
22typedef struct comp_ctx_st 23typedef struct comp_ctx_st
diff --git a/src/lib/libcrypto/conf/conf.c b/src/lib/libcrypto/conf/conf.c
index 7d8b89168a..3031fa3b44 100644
--- a/src/lib/libcrypto/conf/conf.c
+++ b/src/lib/libcrypto/conf/conf.c
@@ -86,28 +86,25 @@ const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
86LHASH *CONF_load(LHASH *h, const char *file, long *line) 86LHASH *CONF_load(LHASH *h, const char *file, long *line)
87 { 87 {
88 LHASH *ltmp; 88 LHASH *ltmp;
89 FILE *in=NULL; 89 BIO *in=NULL;
90 90
91#ifdef VMS 91#ifdef VMS
92 in=fopen(file,"r"); 92 in=BIO_new_file(file, "r");
93#else 93#else
94 in=fopen(file,"rb"); 94 in=BIO_new_file(file, "rb");
95#endif 95#endif
96 if (in == NULL) 96 if (in == NULL)
97 { 97 {
98 SYSerr(SYS_F_FOPEN,get_last_sys_error());
99 ERR_set_error_data(BUF_strdup(file),
100 ERR_TXT_MALLOCED|ERR_TXT_STRING);
101 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB); 98 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
102 return NULL; 99 return NULL;
103 } 100 }
104 101
105 ltmp = CONF_load_fp(h, in, line); 102 ltmp = CONF_load_bio(h, in, line);
106 fclose(in); 103 BIO_free(in);
107 104
108 return ltmp; 105 return ltmp;
109} 106}
110 107#ifndef NO_FP_API
111LHASH *CONF_load_fp(LHASH *h, FILE *in, long *line) 108LHASH *CONF_load_fp(LHASH *h, FILE *in, long *line)
112{ 109{
113 BIO *btmp; 110 BIO *btmp;
@@ -120,6 +117,7 @@ LHASH *CONF_load_fp(LHASH *h, FILE *in, long *line)
120 BIO_free(btmp); 117 BIO_free(btmp);
121 return ltmp; 118 return ltmp;
122} 119}
120#endif
123 121
124LHASH *CONF_load_bio(LHASH *h, BIO *in, long *line) 122LHASH *CONF_load_bio(LHASH *h, BIO *in, long *line)
125 { 123 {
@@ -338,7 +336,7 @@ again:
338 ERR_R_MALLOC_FAILURE); 336 ERR_R_MALLOC_FAILURE);
339 goto err; 337 goto err;
340 } 338 }
341 vv=(CONF_VALUE *)lh_insert(ret,(char *)v); 339 vv=(CONF_VALUE *)lh_insert(ret,v);
342 if (vv != NULL) 340 if (vv != NULL)
343 { 341 {
344 sk_CONF_VALUE_delete_ptr(ts,vv); 342 sk_CONF_VALUE_delete_ptr(ts,vv);
@@ -380,7 +378,7 @@ char *CONF_get_string(LHASH *conf, char *section, char *name)
380 { 378 {
381 vv.name=name; 379 vv.name=name;
382 vv.section=section; 380 vv.section=section;
383 v=(CONF_VALUE *)lh_retrieve(conf,(char *)&vv); 381 v=(CONF_VALUE *)lh_retrieve(conf,&vv);
384 if (v != NULL) return(v->value); 382 if (v != NULL) return(v->value);
385 if (strcmp(section,"ENV") == 0) 383 if (strcmp(section,"ENV") == 0)
386 { 384 {
@@ -390,7 +388,7 @@ char *CONF_get_string(LHASH *conf, char *section, char *name)
390 } 388 }
391 vv.section="default"; 389 vv.section="default";
392 vv.name=name; 390 vv.name=name;
393 v=(CONF_VALUE *)lh_retrieve(conf,(char *)&vv); 391 v=(CONF_VALUE *)lh_retrieve(conf,&vv);
394 if (v != NULL) 392 if (v != NULL)
395 return(v->value); 393 return(v->value);
396 else 394 else
@@ -407,7 +405,7 @@ static CONF_VALUE *get_section(LHASH *conf, char *section)
407 if ((conf == NULL) || (section == NULL)) return(NULL); 405 if ((conf == NULL) || (section == NULL)) return(NULL);
408 vv.name=NULL; 406 vv.name=NULL;
409 vv.section=section; 407 vv.section=section;
410 v=(CONF_VALUE *)lh_retrieve(conf,(char *)&vv); 408 v=(CONF_VALUE *)lh_retrieve(conf,&vv);
411 return(v); 409 return(v);
412 } 410 }
413 411
@@ -445,12 +443,12 @@ void CONF_free(LHASH *conf)
445 443
446 conf->down_load=0; /* evil thing to make sure the 'Free()' 444 conf->down_load=0; /* evil thing to make sure the 'Free()'
447 * works as expected */ 445 * works as expected */
448 lh_doall_arg(conf,(void (*)())value_free_hash,(char *)conf); 446 lh_doall_arg(conf,(void (*)())value_free_hash,conf);
449 447
450 /* We now have only 'section' entries in the hash table. 448 /* We now have only 'section' entries in the hash table.
451 * Due to problems with */ 449 * Due to problems with */
452 450
453 lh_doall_arg(conf,(void (*)())value_free_stack,(char *)conf); 451 lh_doall_arg(conf,(void (*)())value_free_stack,conf);
454 lh_free(conf); 452 lh_free(conf);
455 } 453 }
456 454
@@ -458,7 +456,7 @@ static void value_free_hash(CONF_VALUE *a, LHASH *conf)
458 { 456 {
459 if (a->name != NULL) 457 if (a->name != NULL)
460 { 458 {
461 a=(CONF_VALUE *)lh_delete(conf,(char *)a); 459 a=(CONF_VALUE *)lh_delete(conf,a);
462 } 460 }
463 } 461 }
464 462
@@ -710,7 +708,7 @@ static CONF_VALUE *new_section(LHASH *conf, char *section)
710 v->name=NULL; 708 v->name=NULL;
711 v->value=(char *)sk; 709 v->value=(char *)sk;
712 710
713 vv=(CONF_VALUE *)lh_insert(conf,(char *)v); 711 vv=(CONF_VALUE *)lh_insert(conf,v);
714 if (vv != NULL) 712 if (vv != NULL)
715 { 713 {
716#if !defined(NO_STDIO) && !defined(WIN16) 714#if !defined(NO_STDIO) && !defined(WIN16)
diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h
index e7c5150097..21831a92a3 100644
--- a/src/lib/libcrypto/conf/conf.h
+++ b/src/lib/libcrypto/conf/conf.h
@@ -78,7 +78,9 @@ typedef struct
78DECLARE_STACK_OF(CONF_VALUE) 78DECLARE_STACK_OF(CONF_VALUE)
79 79
80LHASH *CONF_load(LHASH *conf,const char *file,long *eline); 80LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
81#ifndef NO_FP_API
81LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline); 82LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
83#endif
82LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline); 84LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
83STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section); 85STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section);
84char *CONF_get_string(LHASH *conf,char *group,char *name); 86char *CONF_get_string(LHASH *conf,char *group,char *name);
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
index 356c476a99..a8f29f1e65 100644
--- a/src/lib/libcrypto/cryptlib.c
+++ b/src/lib/libcrypto/cryptlib.c
@@ -92,7 +92,9 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] =
92 "getservbyname", 92 "getservbyname",
93 "readdir", 93 "readdir",
94 "RSA_blinding", 94 "RSA_blinding",
95#if CRYPTO_NUM_LOCKS != 24 95 "dh",
96 "debug_malloc2",
97#if CRYPTO_NUM_LOCKS != 26
96# error "Inconsistency between crypto.h and cryptlib.c" 98# error "Inconsistency between crypto.h and cryptlib.c"
97#endif 99#endif
98 }; 100 };
@@ -181,7 +183,7 @@ unsigned long CRYPTO_thread_id(void)
181 ret=(unsigned long)GetCurrentTask(); 183 ret=(unsigned long)GetCurrentTask();
182#elif defined(WIN32) 184#elif defined(WIN32)
183 ret=(unsigned long)GetCurrentThreadId(); 185 ret=(unsigned long)GetCurrentThreadId();
184#elif defined(MSDOS) 186#elif defined(GETPID_IS_MEANINGLESS)
185 ret=1L; 187 ret=1L;
186#else 188#else
187 ret=(unsigned long)getpid(); 189 ret=(unsigned long)getpid();
diff --git a/src/lib/libcrypto/crypto-lib.com b/src/lib/libcrypto/crypto-lib.com
index bf916528eb..79d86771e8 100644
--- a/src/lib/libcrypto/crypto-lib.com
+++ b/src/lib/libcrypto/crypto-lib.com
@@ -14,7 +14,14 @@ $!
14$! It was re-written so it would try to determine what "C" compiler to use 14$! It was re-written so it would try to determine what "C" compiler to use
15$! or you can specify which "C" compiler to use. 15$! or you can specify which "C" compiler to use.
16$! 16$!
17$! Specify RSAREF as P1 to compile with the RSAREF library instead of 17$! Specify the following as P1 to build just that part or ALL to just
18$! build everything.
19$!
20$! LIBRARY To just compile the [.xxx.EXE.CRYPTO]LIBCRYPTO.OLB Library.
21$! APPS To just compile the [.xxx.EXE.CRYPTO]*.EXE
22$! ALL To do both LIBRARY and APPS
23$!
24$! Specify RSAREF as P2 to compile with the RSAREF library instead of
18$! the regular one. If you specify NORSAREF it will compile with the 25$! the regular one. If you specify NORSAREF it will compile with the
19$! regular RSAREF routines. (Note: If you are in the United States 26$! regular RSAREF routines. (Note: If you are in the United States
20$! you MUST compile with RSAREF unless you have a license from RSA). 27$! you MUST compile with RSAREF unless you have a license from RSA).
@@ -26,10 +33,10 @@ $! directory structure stored. You have to extract the file
26$! into the [.RSAREF] directory under the root directory as that 33$! into the [.RSAREF] directory under the root directory as that
27$! is where the scripts will look for the files. 34$! is where the scripts will look for the files.
28$! 35$!
29$! Specify DEBUG or NODEBUG as P2 to compile with or without debugger 36$! Specify DEBUG or NODEBUG as P3 to compile with or without debugger
30$! information. 37$! information.
31$! 38$!
32$! Specify which compiler at P3 to try to compile under. 39$! Specify which compiler at P4 to try to compile under.
33$! 40$!
34$! VAXC For VAX C. 41$! VAXC For VAX C.
35$! DECC For DEC C. 42$! DECC For DEC C.
@@ -38,15 +45,15 @@ $!
38$! If you don't speficy a compiler, it will try to determine which 45$! If you don't speficy a compiler, it will try to determine which
39$! "C" compiler to use. 46$! "C" compiler to use.
40$! 47$!
41$! P4, if defined, sets a TCP/IP library to use, through one of the following 48$! P5, if defined, sets a TCP/IP library to use, through one of the following
42$! keywords: 49$! keywords:
43$! 50$!
44$! UCX for UCX 51$! UCX for UCX
45$! SOCKETSHR for SOCKETSHR+NETLIB 52$! SOCKETSHR for SOCKETSHR+NETLIB
46$! 53$!
47$! P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up) 54$! P6, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
48$! 55$!
49$! P6, if defined, sets a choice of crypto methods to compile. 56$! P7, if defined, sets a choice of crypto methods to compile.
50$! WARNING: this should only be done to recompile some part of an already 57$! WARNING: this should only be done to recompile some part of an already
51$! fully compiled library. 58$! fully compiled library.
52$! 59$!
@@ -79,12 +86,13 @@ $ ENDIF
79$! 86$!
80$! Define The Different Encryption Types. 87$! Define The Different Encryption Types.
81$! 88$!
82$ ENCRYPT_TYPES = ",MD2,MD5,SHA,MDC2,HMAC,RIPEMD,"+ - 89$ ENCRYPT_TYPES = "Basic,MD2,MD5,SHA,MDC2,HMAC,RIPEMD,"+ -
83 "DES,RC2,RC4,RC5,IDEA,BF,CAST,"+ - 90 "DES,RC2,RC4,RC5,IDEA,BF,CAST,"+ -
84 "BN,RSA,DSA,DH,"+ - 91 "BN,RSA,DSA,DH,"+ -
85 "BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ - 92 "BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ -
86 "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ - 93 "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
87 "CONF,TXT_DB,PKCS7,PKCS12,COMP" 94 "CONF,TXT_DB,PKCS7,PKCS12,COMP"
95$ ENCRYPT_PROGRAMS = "DES,PKCS7"
88$! 96$!
89$! Check To Make Sure We Have Valid Command Line Parameters. 97$! Check To Make Sure We Have Valid Command Line Parameters.
90$! 98$!
@@ -136,6 +144,14 @@ $! Define The Library Name.
136$! 144$!
137$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB 145$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB
138$! 146$!
147$! Define The CRYPTO-LIB We Are To Use.
148$!
149$ CRYPTO_LIB := 'EXE_DIR'LIBCRYPTO.OLB
150$!
151$! Define The RSAREF-LIB We Are To Use.
152$!
153$ RSAREF_LIB := SYS$DISK:[-.'ARCH'.EXE.RSAREF]LIBRSAGLUE.OLB
154$!
139$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library... 155$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library...
140$! 156$!
141$ IF (F$SEARCH(LIB_NAME).EQS."") 157$ IF (F$SEARCH(LIB_NAME).EQS."")
@@ -149,9 +165,16 @@ $! End The Library Check.
149$! 165$!
150$ ENDIF 166$ ENDIF
151$! 167$!
168$! Build our options file for the application
169$!
170$ GOSUB CHECK_OPT_FILE
171$!
152$! Define The Different Encryption "library" Strings. 172$! Define The Different Encryption "library" Strings.
153$! 173$!
154$ LIB_ = "cryptlib,mem,cversion,ex_data,tmdiff,cpt_err" 174$ APPS_DES = "DES/DES,CBC3_ENC"
175$ APPS_PKCS7 = "ENC/ENC;DEC/DEC;SIGN/SIGN;VERIFY/VERIFY,EXAMPLE"
176$
177$ LIB_ = "cryptlib,mem,mem_dbg,cversion,ex_data,tmdiff,cpt_err"
155$ LIB_MD2 = "md2_dgst,md2_one" 178$ LIB_MD2 = "md2_dgst,md2_one"
156$ LIB_MD5 = "md5_dgst,md5_one" 179$ LIB_MD5 = "md5_dgst,md5_one"
157$ LIB_SHA = "sha_dgst,sha1dgst,sha_one,sha1_one" 180$ LIB_SHA = "sha_dgst,sha1dgst,sha_one,sha1_one"
@@ -171,14 +194,14 @@ $ LIB_IDEA = "i_cbc,i_cfb64,i_ofb64,i_ecb,i_skey"
171$ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64" 194$ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64"
172$ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64" 195$ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64"
173$ LIB_BN_ASM = "[.asm]vms.mar,vms-helper" 196$ LIB_BN_ASM = "[.asm]vms.mar,vms-helper"
174$ IF F$TRNLNM("OPENSSL_NO_ASM") .NES. "" THEN LIB_BN_ASM = "bn_asm" 197$ IF F$TRNLNM("OPENSSL_NO_ASM").OR.ARCH.EQS."AXP" THEN LIB_BN_ASM = "bn_asm"
175$ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_mul,"+ - 198$ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_ctx,bn_mul,"+ -
176 "bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ - 199 "bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ -
177 "bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+",bn_recp,bn_mont,"+ - 200 "bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+",bn_recp,bn_mont,"+ -
178 "bn_mpi,bn_exp2" 201 "bn_mpi,bn_exp2"
179$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ - 202$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ -
180 "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk" 203 "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk,rsa_null"
181$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err" 204$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err,dsa_ossl"
182$ LIB_DH = "dh_gen,dh_key,dh_lib,dh_check,dh_err" 205$ LIB_DH = "dh_gen,dh_key,dh_lib,dh_check,dh_err"
183$ LIB_BUFFER = "buffer,buf_err" 206$ LIB_BUFFER = "buffer,buf_err"
184$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ - 207$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
@@ -188,7 +211,7 @@ $ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
188 "b_sock,bss_acpt,bf_nbio,bss_rtcp,bss_bio" ! + ",bss_log" for syslog 211 "b_sock,bss_acpt,bf_nbio,bss_rtcp,bss_bio" ! + ",bss_log" for syslog
189$ LIB_STACK = "stack" 212$ LIB_STACK = "stack"
190$ LIB_LHASH = "lhash,lh_stats" 213$ LIB_LHASH = "lhash,lh_stats"
191$ LIB_RAND = "md_rand,randfile,rand_lib" 214$ LIB_RAND = "md_rand,randfile,rand_lib,rand_err,rand_egd"
192$ LIB_ERR = "err,err_all,err_prn" 215$ LIB_ERR = "err,err_all,err_prn"
193$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err" 216$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err"
194$ LIB_EVP = "encode,digest,evp_enc,evp_key,"+ - 217$ LIB_EVP = "encode,digest,evp_enc,evp_key,"+ -
@@ -204,38 +227,39 @@ $ LIB_EVP_2 = "e_ecb_c,e_cbc_c,e_cfb_c,e_ofb_c,"+ -
204 "m_ripemd,"+ - 227 "m_ripemd,"+ -
205 "p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ - 228 "p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ -
206 "bio_md,bio_b64,bio_enc,evp_err,e_null,"+ - 229 "bio_md,bio_b64,bio_enc,evp_err,e_null,"+ -
207 "c_all,evp_lib,bio_ok,evp_pkey,evp_pbe,p5_crpt,p5_crpt2" 230 "c_all,c_allc,c_alld,evp_lib,bio_ok,"+-
231 "evp_pkey,evp_pbe,p5_crpt,p5_crpt2"
208$ LIB_ASN1 = "a_object,a_bitstr,a_utctm,a_gentm,a_time,a_int,a_octet,"+ - 232$ LIB_ASN1 = "a_object,a_bitstr,a_utctm,a_gentm,a_time,a_int,a_octet,"+ -
209 "a_print,a_type,a_set,a_dup,a_d2i_fp,a_i2d_fp,a_bmp,"+ - 233 "a_null,a_print,a_type,a_set,a_dup,a_d2i_fp,a_i2d_fp,a_bmp,"+ -
210 "a_enum,a_vis,a_utf8,a_sign,a_digest,a_verify,"+ - 234 "a_enum,a_vis,a_utf8,a_sign,a_digest,a_verify,a_mbstr,"+ -
211 "x_algor,x_val,x_pubkey,x_sig,x_req,x_attrib,"+ - 235 "x_algor,x_val,x_pubkey,x_sig,x_req,x_attrib,"+ -
212 "x_name,x_cinf,x_x509,x_crl,x_info,x_spki,nsseq,"+ - 236 "x_name,x_cinf,x_x509,x_x509a,x_crl,x_info,x_spki,nsseq,"+ -
213 "d2i_r_pr,i2d_r_pr,d2i_r_pu,i2d_r_pu,"+ - 237 "d2i_r_pr,i2d_r_pr,d2i_r_pu,i2d_r_pu,"+ -
214 "d2i_s_pr,i2d_s_pr,d2i_s_pu,i2d_s_pu,"+ - 238 "d2i_s_pr,i2d_s_pr,d2i_s_pu,i2d_s_pu,"+ -
215 "d2i_pu,d2i_pr,i2d_pu,i2d_pr" 239 "d2i_pu,d2i_pr,i2d_pu,i2d_pr"
216$ LIB_ASN1_2 = "t_req,t_x509,t_crl,t_pkey,"+ - 240$ LIB_ASN1_2 = "t_req,t_x509,t_x509a,t_crl,t_pkey,t_spki,t_bitst,"+ -
217 "p7_i_s,p7_signi,p7_signd,p7_recip,p7_enc_c,p7_evp,"+ - 241 "p7_i_s,p7_signi,p7_signd,p7_recip,p7_enc_c,p7_evp,"+ -
218 "p7_dgst,p7_s_e,p7_enc,p7_lib,"+ - 242 "p7_dgst,p7_s_e,p7_enc,p7_lib,"+ -
219 "f_int,f_string,i2d_dhp,i2d_dsap,d2i_dhp,d2i_dsap,n_pkey,"+ - 243 "f_int,f_string,i2d_dhp,i2d_dsap,d2i_dhp,d2i_dsap,n_pkey,"+ -
220 "f_enum,a_hdr,x_pkey,a_bool,x_exten,"+ - 244 "f_enum,a_hdr,x_pkey,a_bool,x_exten,"+ -
221 "asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,"+ - 245 "asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,a_strnid,"+ -
222 "evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey" 246 "evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey"
223$ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err" 247$ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err"
224$ LIB_X509 = "x509_def,x509_d2,x509_r2x,x509_cmp,"+ - 248$ LIB_X509 = "x509_def,x509_d2,x509_r2x,x509_cmp,"+ -
225 "x509_obj,x509_req,x509_vfy,"+ - 249 "x509_obj,x509_req,x509spki,x509_vfy,"+ -
226 "x509_set,x509rset,x509_err,"+ - 250 "x509_set,x509rset,x509_err,"+ -
227 "x509name,x509_v3,x509_ext,"+ - 251 "x509name,x509_v3,x509_ext,x509_att,"+ -
228 "x509type,x509_lu,x_all,x509_txt,"+ - 252 "x509type,x509_lu,x_all,x509_txt,"+ -
229 "by_file,by_dir" 253 "x509_trs,by_file,by_dir"
230$ LIB_X509V3 = "v3_bcons,v3_bitst,v3_conf,v3_extku,v3_ia5,v3_lib,"+ - 254$ LIB_X509V3 = "v3_bcons,v3_bitst,v3_conf,v3_extku,v3_ia5,v3_lib,"+ -
231 "v3_prn,v3_utl,v3err,v3_genn,v3_alt,v3_skey,v3_akey,v3_pku,"+ - 255 "v3_prn,v3_utl,v3err,v3_genn,v3_alt,v3_skey,v3_akey,v3_pku,"+ -
232 "v3_int,v3_enum,v3_sxnet,v3_cpols,v3_crld" 256 "v3_int,v3_enum,v3_sxnet,v3_cpols,v3_crld,v3_purp,v3_info"
233$ LIB_CONF = "conf,conf_err" 257$ LIB_CONF = "conf,conf_err"
234$ LIB_TXT_DB = "txt_db" 258$ LIB_TXT_DB = "txt_db"
235$ LIB_PKCS7 = "pk7_lib,pkcs7err,pk7_doit" 259$ LIB_PKCS7 = "pk7_lib,pkcs7err,pk7_doit,pk7_smime,pk7_attr,pk7_mime"
236$ LIB_PKCS12 = "p12_add,p12_attr,p12_bags,p12_crpt,p12_crt,p12_decr,"+ - 260$ LIB_PKCS12 = "p12_add,p12_attr,p12_bags,p12_crpt,p12_crt,p12_decr,"+ -
237 "p12_init,p12_key,p12_kiss,p12_lib,p12_mac,p12_mutl,"+ - 261 "p12_init,p12_key,p12_kiss,p12_lib,p12_mac,p12_mutl,"+ -
238 "p12_sbag,p12_utl,pk12err" 262 "p12_sbag,p12_utl,p12_npas,pk12err"
239$ LIB_COMP = "comp_lib,"+ - 263$ LIB_COMP = "comp_lib,"+ -
240 "c_rle,c_zlib" 264 "c_rle,c_zlib"
241$! 265$!
@@ -248,7 +272,8 @@ $ COMPILEWITH_CC5 = ",md2_dgst,md5_dgst,mdc2dgst,sha_dgst,sha1dgst," + -
248$! 272$!
249$! Check To See If We Are Going To Use RSAREF. 273$! Check To See If We Are Going To Use RSAREF.
250$! 274$!
251$ IF (RSAREF.EQS."TRUE" .AND. ENCRYPT_TYPES - "RSA".NES.ENCRYPT_TYPES) 275$ IF (RSAREF.EQS."TRUE" .AND. ENCRYPT_TYPES - "RSA".NES.ENCRYPT_TYPES -
276 .AND. (BUILDALL .EQS. "TRUE" .OR. BUILDALL .EQS. "LIBRARY"))
252$ THEN 277$ THEN
253$! 278$!
254$! Check To See If The File [-.RSAREF]RSAREF.C Is Actually There. 279$! Check To See If The File [-.RSAREF]RSAREF.C Is Actually There.
@@ -340,6 +365,8 @@ $!
340$! Extract The Module Name From The Encryption List. 365$! Extract The Module Name From The Encryption List.
341$! 366$!
342$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES) 367$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES)
368$ IF MODULE_NAME.EQS."Basic" THEN MODULE_NAME = ""
369$ MODULE_NAME1 = MODULE_NAME
343$! 370$!
344$! Check To See If We Are At The End Of The Module List. 371$! Check To See If We Are At The End Of The Module List.
345$! 372$!
@@ -358,20 +385,10 @@ $! Increment The Moudle Counter.
358$! 385$!
359$ MODULE_COUNTER = MODULE_COUNTER + 1 386$ MODULE_COUNTER = MODULE_COUNTER + 1
360$! 387$!
361$! Tell The User What Module We Are Building. 388$! Create The Library and Apps Module Names.
362$!
363$ IF (MODULE_NAME.NES."")
364$ THEN
365$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME," Files."
366$ ENDIF
367$!
368$! Define A File Counter And Set It To "0".
369$!
370$ FILE_COUNTER = 0
371$!
372$! Create The Library Module Name.
373$! 389$!
374$ LIB_MODULE = "LIB_" + MODULE_NAME 390$ LIB_MODULE = "LIB_" + MODULE_NAME
391$ APPS_MODULE = "APPS_" + MODULE_NAME
375$ IF (MODULE_NAME.EQS."ASN1_2") 392$ IF (MODULE_NAME.EQS."ASN1_2")
376$ THEN 393$ THEN
377$ MODULE_NAME = "ASN1" 394$ MODULE_NAME = "ASN1"
@@ -381,6 +398,11 @@ $ THEN
381$ MODULE_NAME = "EVP" 398$ MODULE_NAME = "EVP"
382$ ENDIF 399$ ENDIF
383$! 400$!
401$! Set state (can be LIB and APPS)
402$!
403$ STATE = "LIB"
404$ IF BUILDALL .EQS. "APPS" THEN STATE = "APPS"
405$!
384$! Check if the library module name actually is defined 406$! Check if the library module name actually is defined
385$! 407$!
386$ IF F$TYPE('LIB_MODULE') .EQS. "" 408$ IF F$TYPE('LIB_MODULE') .EQS. ""
@@ -391,22 +413,92 @@ $ WRITE SYS$ERROR ""
391$ GOTO MODULE_NEXT 413$ GOTO MODULE_NEXT
392$ ENDIF 414$ ENDIF
393$! 415$!
416$! Top Of The Module Loop.
417$!
418$ MODULE_AGAIN:
419$!
420$! Tell The User What Module We Are Building.
421$!
422$ IF (MODULE_NAME1.NES."")
423$ THEN
424$ IF STATE .EQS. "LIB"
425$ THEN
426$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME1," Library Files. (",BUILDALL,",",STATE,")"
427$ ELSE IF F$TYPE('APPS_MODULE') .NES. ""
428$ THEN
429$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME1," Applications. (",BUILDALL,",",STATE,")"
430$ ENDIF
431$ ENDIF
432$ ENDIF
433$!
434$! Define A File Counter And Set It To "0".
435$!
436$ FILE_COUNTER = 0
437$ APPLICATION = ""
438$ APPLICATION_COUNTER = 0
439$!
394$! Top Of The File Loop. 440$! Top Of The File Loop.
395$! 441$!
396$ NEXT_FILE: 442$ NEXT_FILE:
397$! 443$!
398$! O.K, Extract The File Name From The File List. 444$! Look in the LIB_MODULE is we're in state LIB
445$!
446$ IF STATE .EQS. "LIB"
447$ THEN
448$!
449$! O.K, Extract The File Name From The File List.
450$!
451$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE')
452$!
453$! else
454$!
455$ ELSE
456$ FILE_NAME = ","
457$!
458$ IF F$TYPE('APPS_MODULE') .NES. ""
459$ THEN
460$!
461$! Extract The File Name From The File List.
462$! This part is a bit more complicated.
399$! 463$!
400$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE') 464$ IF APPLICATION .EQS. ""
465$ THEN
466$ APPLICATION = F$ELEMENT(APPLICATION_COUNTER,";",'APPS_MODULE')
467$ APPLICATION_COUNTER = APPLICATION_COUNTER + 1
468$ APPLICATION_OBJECTS = F$ELEMENT(1,"/",APPLICATION)
469$ APPLICATION = F$ELEMENT(0,"/",APPLICATION)
470$ FILE_COUNTER = 0
471$ ENDIF
472$
473$! WRITE SYS$OUTPUT "DEBUG: SHOW SYMBOL APPLICATION*"
474$! SHOW SYMBOL APPLICATION*
475$!
476$ IF APPLICATION .NES. ";"
477$ THEN
478$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",APPLICATION_OBJECTS)
479$ IF FILE_NAME .EQS. ","
480$ THEN
481$ APPLICATION = ""
482$ GOTO NEXT_FILE
483$ ENDIF
484$ ENDIF
485$ ENDIF
486$ ENDIF
401$! 487$!
402$! Check To See If We Are At The End Of The File List. 488$! Check To See If We Are At The End Of The File List.
403$! 489$!
404$ IF (FILE_NAME.EQS.",") 490$ IF (FILE_NAME.EQS.",")
405$ THEN 491$ THEN
406$! 492$!
407$! We Are At The End Of The File List, Goto FILE_DONE. 493$! We Are At The End Of The File List, Change State Or Goto FILE_DONE.
408$! 494$!
409$ GOTO FILE_DONE 495$ IF STATE .EQS. "LIB" .AND. BUILDALL .NES. "LIBRARY"
496$ THEN
497$ STATE = "APPS"
498$ GOTO MODULE_AGAIN
499$ ELSE
500$ GOTO FILE_DONE
501$ ENDIF
410$! 502$!
411$! End The File List Check. 503$! End The File List Check.
412$! 504$!
@@ -458,7 +550,7 @@ $! Tell The User We Are Compiling The File.
458$! 550$!
459$ IF (MODULE_NAME.EQS."") 551$ IF (MODULE_NAME.EQS."")
460$ THEN 552$ THEN
461 WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File." 553$ WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File. (",BUILDALL,",",STATE,")"
462$ ENDIF 554$ ENDIF
463$ IF (MODULE_NAME.NES."") 555$ IF (MODULE_NAME.NES."")
464$ THEN 556$ THEN
@@ -490,14 +582,17 @@ $ ENDIF
490$ ENDIF 582$ ENDIF
491$ ENDIF 583$ ENDIF
492$ ENDIF 584$ ENDIF
585$ IF STATE .EQS. "LIB"
586$ THEN
493$! 587$!
494$! Add It To The Library. 588$! Add It To The Library.
495$! 589$!
496$ LIBRARY/REPLACE 'LIB_NAME' 'OBJECT_FILE' 590$ LIBRARY/REPLACE 'LIB_NAME' 'OBJECT_FILE'
497$! 591$!
498$! Time To Clean Up The Object File. 592$! Time To Clean Up The Object File.
499$! 593$!
500$ DELETE 'OBJECT_FILE';* 594$ DELETE 'OBJECT_FILE';*
595$ ENDIF
501$! 596$!
502$! Go Back And Do It Again. 597$! Go Back And Do It Again.
503$! 598$!
@@ -507,6 +602,99 @@ $! All Done With This Library Part.
507$! 602$!
508$ FILE_DONE: 603$ FILE_DONE:
509$! 604$!
605$! Time To Build Some Applications
606$!
607$ IF F$TYPE('APPS_MODULE') .NES. "" .AND. BUILDALL .NES. "LIBRARY"
608$ THEN
609$ APPLICATION_COUNTER = 0
610$ NEXT_APPLICATION:
611$ APPLICATION = F$ELEMENT(APPLICATION_COUNTER,";",'APPS_MODULE')
612$ IF APPLICATION .EQS. ";" THEN GOTO APPLICATION_DONE
613$
614$ APPLICATION_COUNTER = APPLICATION_COUNTER + 1
615$ APPLICATION_OBJECTS = F$ELEMENT(1,"/",APPLICATION)
616$ APPLICATION = F$ELEMENT(0,"/",APPLICATION)
617$
618$! WRITE SYS$OUTPUT "DEBUG: SHOW SYMBOL APPLICATION*"
619$! SHOW SYMBOL APPLICATION*
620$!
621$! Tell the user what happens
622$!
623$ WRITE SYS$OUTPUT " ",APPLICATION,".exe"
624$!
625$! Link The Program, Check To See If We Need To Link With RSAREF Or Not.
626$!
627$ IF (RSAREF.EQS."TRUE")
628$ THEN
629$!
630$! Check To See If We Are To Link With A Specific TCP/IP Library.
631$!
632$ IF (TCPIP_LIB.NES."")
633$ THEN
634$!
635$! Link With The RSAREF Library And A Specific TCP/IP Library.
636$!
637$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
638 'OBJ_DIR''APPLICATION_OBJECTS', -
639 'CRYPTO_LIB'/LIBRARY,'RSAREF_LIB'/LIBRARY, -
640 'TCPIP_LIB','OPT_FILE'/OPTION
641$!
642$! Else...
643$!
644$ ELSE
645$!
646$! Link With The RSAREF Library And NO TCP/IP Library.
647$!
648$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
649 'OBJ_DIR''APPLICATION_OBJECTS', -
650 'CRYPTO_LIB'/LIBRARY,'RSAREF_LIB'/LIBRARY, -
651 'OPT_FILE'/OPTION
652$!
653$! End The TCP/IP Library Check.
654$!
655$ ENDIF
656$!
657$! Else...
658$!
659$ ELSE
660$!
661$! Don't Link With The RSAREF Routines.
662$!
663$!
664$! Check To See If We Are To Link With A Specific TCP/IP Library.
665$!
666$ IF (TCPIP_LIB.NES."")
667$ THEN
668$!
669$! Don't Link With The RSAREF Routines And TCP/IP Library.
670$!
671$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
672 'OBJ_DIR''APPLICATION_OBJECTS', -
673 'CRYPTO_LIB'/LIBRARY, -
674 'TCPIP_LIB','OPT_FILE'/OPTION
675$!
676$! Else...
677$!
678$ ELSE
679$!
680$! Don't Link With The RSAREF Routines And Link With A TCP/IP Library.
681$!
682$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
683 'OBJ_DIR''APPLICATION_OBJECTS',-
684 'CRYPTO_LIB'/LIBRARY, -
685 'OPT_FILE'/OPTION
686$!
687$! End The TCP/IP Library Check.
688$!
689$ ENDIF
690$!
691$! End The RSAREF Link Check.
692$!
693$ ENDIF
694$ GOTO NEXT_APPLICATION
695$ APPLICATION_DONE:
696$ ENDIF
697$!
510$! Go Back And Get The Next Module. 698$! Go Back And Get The Next Module.
511$! 699$!
512$ GOTO MODULE_NEXT 700$ GOTO MODULE_NEXT
@@ -653,17 +841,70 @@ $ CHECK_OPTIONS:
653$! 841$!
654$! Check To See If P1 Is Blank. 842$! Check To See If P1 Is Blank.
655$! 843$!
656$ IF (P1.EQS."NORSAREF") 844$ IF (P1.EQS."ALL")
657$ THEN 845$ THEN
658$! 846$!
659$! P1 Is NORSAREF, So Compile With The Regular RSA Libraries. 847$! P1 Is Blank, So Build Everything.
848$!
849$ BUILDALL = "TRUE"
850$!
851$! Else...
852$!
853$ ELSE
854$!
855$! Else, Check To See If P1 Has A Valid Arguement.
856$!
857$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."APPS")
858$ THEN
859$!
860$! A Valid Arguement.
861$!
862$ BUILDALL = P1
863$!
864$! Else...
865$!
866$ ELSE
867$!
868$! Tell The User We Don't Know What They Want.
869$!
870$ WRITE SYS$OUTPUT ""
871$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
872$ WRITE SYS$OUTPUT ""
873$ WRITE SYS$OUTPUT " ALL : Just Build Everything."
874$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.SSL]LIBCRYPTO.OLB Library."
875$ WRITE SYS$OUTPUT " APPS : To Compile Just The [.xxx.EXE.SSL]*.EXE Programs."
876$ WRITE SYS$OUTPUT ""
877$ WRITE SYS$OUTPUT " Where 'xxx' Stands For:"
878$ WRITE SYS$OUTPUT ""
879$ WRITE SYS$OUTPUT " AXP : Alpha Architecture."
880$ WRITE SYS$OUTPUT " VAX : VAX Architecture."
881$ WRITE SYS$OUTPUT ""
882$!
883$! Time To EXIT.
884$!
885$ EXIT
886$!
887$! End The Valid Arguement Check.
888$!
889$ ENDIF
890$!
891$! End The P1 Check.
892$!
893$ ENDIF
894$!
895$! Check To See If P2 Is Blank.
896$!
897$ IF (P2.EQS."NORSAREF")
898$ THEN
899$!
900$! P2 Is NORSAREF, So Compile With The Regular RSA Libraries.
660$! 901$!
661$ RSAREF = "FALSE" 902$ RSAREF = "FALSE"
662$ ELSE 903$ ELSE
663$! 904$!
664$! Check To See If We Are To Use The RSAREF Library. 905$! Check To See If We Are To Use The RSAREF Library.
665$! 906$!
666$ IF (P1.EQS."RSAREF") 907$ IF (P2.EQS."RSAREF")
667$ THEN 908$ THEN
668$! 909$!
669$! Check To Make Sure We Have The RSAREF Source Code Directory. 910$! Check To Make Sure We Have The RSAREF Source Code Directory.
@@ -697,7 +938,7 @@ $!
697$! They Entered An Invalid Option.. 938$! They Entered An Invalid Option..
698$! 939$!
699$ WRITE SYS$OUTPUT "" 940$ WRITE SYS$OUTPUT ""
700$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:" 941$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
701$ WRITE SYS$OUTPUT "" 942$ WRITE SYS$OUTPUT ""
702$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library." 943$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library."
703$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library." 944$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library."
@@ -711,16 +952,16 @@ $! End The Valid Arguement Check.
711$! 952$!
712$ ENDIF 953$ ENDIF
713$! 954$!
714$! End The P1 Check. 955$! End The P2 Check.
715$! 956$!
716$ ENDIF 957$ ENDIF
717$! 958$!
718$! Check To See If P2 Is Blank. 959$! Check To See If P3 Is Blank.
719$! 960$!
720$ IF (P2.EQS."NODEBUG") 961$ IF (P3.EQS."NODEBUG")
721$ THEN 962$ THEN
722$! 963$!
723$! P2 Is NODEBUG, So Compile Without The Debugger Information. 964$! P3 Is NODEBUG, So Compile Without The Debugger Information.
724$! 965$!
725$ DEBUGGER = "NODEBUG" 966$ DEBUGGER = "NODEBUG"
726$ TRACEBACK = "NOTRACEBACK" 967$ TRACEBACK = "NOTRACEBACK"
@@ -733,7 +974,7 @@ $ ELSE
733$! 974$!
734$! Check To See If We Are To Compile With Debugger Information. 975$! Check To See If We Are To Compile With Debugger Information.
735$! 976$!
736$ IF (P2.EQS."DEBUG") 977$ IF (P3.EQS."DEBUG")
737$ THEN 978$ THEN
738$! 979$!
739$! Compile With Debugger Information. 980$! Compile With Debugger Information.
@@ -750,7 +991,7 @@ $!
750$! They Entered An Invalid Option.. 991$! They Entered An Invalid Option..
751$! 992$!
752$ WRITE SYS$OUTPUT "" 993$ WRITE SYS$OUTPUT ""
753$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:" 994$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
754$ WRITE SYS$OUTPUT "" 995$ WRITE SYS$OUTPUT ""
755$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information." 996$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
756$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information." 997$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
@@ -764,7 +1005,7 @@ $! End The Valid Arguement Check.
764$! 1005$!
765$ ENDIF 1006$ ENDIF
766$! 1007$!
767$! End The P2 Check. 1008$! End The P3 Check.
768$! 1009$!
769$ ENDIF 1010$ ENDIF
770$! 1011$!
@@ -774,9 +1015,9 @@ $! Written By: Richard Levitte
774$! richard@levitte.org 1015$! richard@levitte.org
775$! 1016$!
776$! 1017$!
777$! Check To See If We Have A Option For P5. 1018$! Check To See If We Have A Option For P6.
778$! 1019$!
779$ IF (P5.EQS."") 1020$ IF (P6.EQS."")
780$ THEN 1021$ THEN
781$! 1022$!
782$! Get The Version Of VMS We Are Using. 1023$! Get The Version Of VMS We Are Using.
@@ -798,13 +1039,13 @@ $! End The VMS Version Check.
798$! 1039$!
799$ ENDIF 1040$ ENDIF
800$! 1041$!
801$! End The P5 Check. 1042$! End The P6 Check.
802$! 1043$!
803$ ENDIF 1044$ ENDIF
804$! 1045$!
805$! Check To See If P3 Is Blank. 1046$! Check To See If P4 Is Blank.
806$! 1047$!
807$ IF (P3.EQS."") 1048$ IF (P4.EQS."")
808$ THEN 1049$ THEN
809$! 1050$!
810$! O.K., The User Didn't Specify A Compiler, Let's Try To 1051$! O.K., The User Didn't Specify A Compiler, Let's Try To
@@ -817,7 +1058,7 @@ $ THEN
817$! 1058$!
818$! Looks Like GNUC, Set To Use GNUC. 1059$! Looks Like GNUC, Set To Use GNUC.
819$! 1060$!
820$ P3 = "GNUC" 1061$ P4 = "GNUC"
821$! 1062$!
822$! Else... 1063$! Else...
823$! 1064$!
@@ -830,7 +1071,7 @@ $ THEN
830$! 1071$!
831$! Looks Like DECC, Set To Use DECC. 1072$! Looks Like DECC, Set To Use DECC.
832$! 1073$!
833$ P3 = "DECC" 1074$ P4 = "DECC"
834$! 1075$!
835$! Else... 1076$! Else...
836$! 1077$!
@@ -838,7 +1079,7 @@ $ ELSE
838$! 1079$!
839$! Looks Like VAXC, Set To Use VAXC. 1080$! Looks Like VAXC, Set To Use VAXC.
840$! 1081$!
841$ P3 = "VAXC" 1082$ P4 = "VAXC"
842$! 1083$!
843$! End The VAXC Compiler Check. 1084$! End The VAXC Compiler Check.
844$! 1085$!
@@ -852,9 +1093,9 @@ $! End The Compiler Check.
852$! 1093$!
853$ ENDIF 1094$ ENDIF
854$! 1095$!
855$! Check To See If We Have A Option For P4. 1096$! Check To See If We Have A Option For P5.
856$! 1097$!
857$ IF (P4.EQS."") 1098$ IF (P5.EQS."")
858$ THEN 1099$ THEN
859$! 1100$!
860$! Find out what socket library we have available 1101$! Find out what socket library we have available
@@ -864,7 +1105,7 @@ $ THEN
864$! 1105$!
865$! We have SOCKETSHR, and it is my opinion that it's the best to use. 1106$! We have SOCKETSHR, and it is my opinion that it's the best to use.
866$! 1107$!
867$ P4 = "SOCKETSHR" 1108$ P5 = "SOCKETSHR"
868$! 1109$!
869$! Tell the user 1110$! Tell the user
870$! 1111$!
@@ -884,7 +1125,7 @@ $ THEN
884$! 1125$!
885$! Last resort: a UCX or UCX-compatible library 1126$! Last resort: a UCX or UCX-compatible library
886$! 1127$!
887$ P4 = "UCX" 1128$ P5 = "UCX"
888$! 1129$!
889$! Tell the user 1130$! Tell the user
890$! 1131$!
@@ -898,22 +1139,46 @@ $ ENDIF
898$! 1139$!
899$! Set Up Initial CC Definitions, Possibly With User Ones 1140$! Set Up Initial CC Definitions, Possibly With User Ones
900$! 1141$!
901$ CCDEFS = "VMS=1,TCPIP_TYPE_''P4'" 1142$ CCDEFS = "VMS=1,TCPIP_TYPE_''P5'"
1143$ IF F$TRNLNM("OPENSSL_NO_ASM") THEN CCDEFS = CCDEFS + ",NO_ASM"
1144$ IF F$TRNLNM("OPENSSL_NO_RSA") THEN CCDEFS = CCDEFS + ",NO_RSA"
1145$ IF F$TRNLNM("OPENSSL_NO_DSA") THEN CCDEFS = CCDEFS + ",NO_DSA"
1146$ IF F$TRNLNM("OPENSSL_NO_DH") THEN CCDEFS = CCDEFS + ",NO_DH"
1147$ IF F$TRNLNM("OPENSSL_NO_MD2") THEN CCDEFS = CCDEFS + ",NO_MD2"
1148$ IF F$TRNLNM("OPENSSL_NO_MD5") THEN CCDEFS = CCDEFS + ",NO_MD5"
1149$ IF F$TRNLNM("OPENSSL_NO_RIPEMD") THEN CCDEFS = CCDEFS + ",NO_RIPEMD"
1150$ IF F$TRNLNM("OPENSSL_NO_SHA") THEN CCDEFS = CCDEFS + ",NO_SHA"
1151$ IF F$TRNLNM("OPENSSL_NO_SHA0") THEN CCDEFS = CCDEFS + ",NO_SHA0"
1152$ IF F$TRNLNM("OPENSSL_NO_SHA1") THEN CCDEFS = CCDEFS + ",NO_SHA1"
1153$ IF F$TRNLNM("OPENSSL_NO_DES")
1154$ THEN
1155$ CCDEFS = CCDEFS + ",NO_DES,NO_MDC2"
1156$ ELSE
1157$ IF F$TRNLNM("OPENSSL_NO_MDC2") THEN CCDEFS = CCDEFS + ",NO_MDC2"
1158$ ENDIF
1159$ IF F$TRNLNM("OPENSSL_NO_RC2") THEN CCDEFS = CCDEFS + ",NO_RC2"
1160$ IF F$TRNLNM("OPENSSL_NO_RC4") THEN CCDEFS = CCDEFS + ",NO_RC4"
1161$ IF F$TRNLNM("OPENSSL_NO_RC5") THEN CCDEFS = CCDEFS + ",NO_RC5"
1162$ IF F$TRNLNM("OPENSSL_NO_IDEA") THEN CCDEFS = CCDEFS + ",NO_IDEA"
1163$ IF F$TRNLNM("OPENSSL_NO_BF") THEN CCDEFS = CCDEFS + ",NO_BF"
1164$ IF F$TRNLNM("OPENSSL_NO_CAST") THEN CCDEFS = CCDEFS + ",NO_CAST"
1165$ IF F$TRNLNM("OPENSSL_NO_HMAC") THEN CCDEFS = CCDEFS + ",NO_HMAC"
1166$ IF F$TRNLNM("OPENSSL_NO_SSL2") THEN CCDEFS = CCDEFS + ",NO_SSL2"
902$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS 1167$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
903$ CCEXTRAFLAGS = "" 1168$ CCEXTRAFLAGS = ""
904$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS 1169$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
905$ CCDISABLEWARNINGS = "" 1170$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX"
906$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN - 1171$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
907 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS 1172 CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
908$! 1173$!
909$! Check To See If The User Entered A Valid Paramter. 1174$! Check To See If The User Entered A Valid Paramter.
910$! 1175$!
911$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC") 1176$ IF (P4.EQS."VAXC").OR.(P4.EQS."DECC").OR.(P4.EQS."GNUC")
912$ THEN 1177$ THEN
913$! 1178$!
914$! Check To See If The User Wanted DECC. 1179$! Check To See If The User Wanted DECC.
915$! 1180$!
916$ IF (P3.EQS."DECC") 1181$ IF (P4.EQS."DECC")
917$ THEN 1182$ THEN
918$! 1183$!
919$! Looks Like DECC, Set To Use DECC. 1184$! Looks Like DECC, Set To Use DECC.
@@ -942,7 +1207,7 @@ $ ENDIF
942$! 1207$!
943$! Check To See If We Are To Use VAXC. 1208$! Check To See If We Are To Use VAXC.
944$! 1209$!
945$ IF (P3.EQS."VAXC") 1210$ IF (P4.EQS."VAXC")
946$ THEN 1211$ THEN
947$! 1212$!
948$! Looks Like VAXC, Set To Use VAXC. 1213$! Looks Like VAXC, Set To Use VAXC.
@@ -980,7 +1245,7 @@ $ ENDIF
980$! 1245$!
981$! Check To See If We Are To Use GNU C. 1246$! Check To See If We Are To Use GNU C.
982$! 1247$!
983$ IF (P3.EQS."GNUC") 1248$ IF (P4.EQS."GNUC")
984$ THEN 1249$ THEN
985$! 1250$!
986$! Looks Like GNUC, Set To Use GNUC. 1251$! Looks Like GNUC, Set To Use GNUC.
@@ -1051,7 +1316,7 @@ $ CC4DISABLEWARNINGS = ""
1051$ ENDIF 1316$ ENDIF
1052$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS 1317$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
1053$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS 1318$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
1054$ IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P2 .NES. "DEBUG" 1319$ IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P3 .NES. "DEBUG"
1055$ THEN 1320$ THEN
1056$ CC5 = CC + "/OPTIMIZE=NODISJOINT" 1321$ CC5 = CC + "/OPTIMIZE=NODISJOINT"
1057$ ELSE 1322$ ELSE
@@ -1070,7 +1335,7 @@ $!
1070$! Tell The User We Don't Know What They Want. 1335$! Tell The User We Don't Know What They Want.
1071$! 1336$!
1072$ WRITE SYS$OUTPUT "" 1337$ WRITE SYS$OUTPUT ""
1073$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:" 1338$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:"
1074$ WRITE SYS$OUTPUT "" 1339$ WRITE SYS$OUTPUT ""
1075$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C." 1340$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
1076$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C." 1341$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
@@ -1096,12 +1361,12 @@ $ WRITE SYS$OUTPUT "Main MACRO Compiling Command: ",MACRO
1096$! 1361$!
1097$! Time to check the contents, and to make sure we get the correct library. 1362$! Time to check the contents, and to make sure we get the correct library.
1098$! 1363$!
1099$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX" 1364$ IF P5.EQS."SOCKETSHR" .OR. P5.EQS."MULTINET" .OR. P5.EQS."UCX"
1100$ THEN 1365$ THEN
1101$! 1366$!
1102$! Check to see if SOCKETSHR was chosen 1367$! Check to see if SOCKETSHR was chosen
1103$! 1368$!
1104$ IF P4.EQS."SOCKETSHR" 1369$ IF P5.EQS."SOCKETSHR"
1105$ THEN 1370$ THEN
1106$! 1371$!
1107$! Set the library to use SOCKETSHR 1372$! Set the library to use SOCKETSHR
@@ -1114,12 +1379,12 @@ $ ENDIF
1114$! 1379$!
1115$! Check to see if MULTINET was chosen 1380$! Check to see if MULTINET was chosen
1116$! 1381$!
1117$ IF P4.EQS."MULTINET" 1382$ IF P5.EQS."MULTINET"
1118$ THEN 1383$ THEN
1119$! 1384$!
1120$! Set the library to use UCX emulation. 1385$! Set the library to use UCX emulation.
1121$! 1386$!
1122$ P4 = "UCX" 1387$ P5 = "UCX"
1123$! 1388$!
1124$! Done with MULTINET 1389$! Done with MULTINET
1125$! 1390$!
@@ -1127,7 +1392,7 @@ $ ENDIF
1127$! 1392$!
1128$! Check to see if UCX was chosen 1393$! Check to see if UCX was chosen
1129$! 1394$!
1130$ IF P4.EQS."UCX" 1395$ IF P5.EQS."UCX"
1131$ THEN 1396$ THEN
1132$! 1397$!
1133$! Set the library to use UCX. 1398$! Set the library to use UCX.
@@ -1156,7 +1421,7 @@ $!
1156$! Tell The User We Don't Know What They Want. 1421$! Tell The User We Don't Know What They Want.
1157$! 1422$!
1158$ WRITE SYS$OUTPUT "" 1423$ WRITE SYS$OUTPUT ""
1159$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:" 1424$ WRITE SYS$OUTPUT "The Option ",P5," Is Invalid. The Valid Options Are:"
1160$ WRITE SYS$OUTPUT "" 1425$ WRITE SYS$OUTPUT ""
1161$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library." 1426$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library."
1162$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library." 1427$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library."
@@ -1173,9 +1438,9 @@ $!
1173$! Check if the user wanted to compile just a subset of all the encryption 1438$! Check if the user wanted to compile just a subset of all the encryption
1174$! methods. 1439$! methods.
1175$! 1440$!
1176$ IF P6 .NES. "" 1441$ IF P7 .NES. ""
1177$ THEN 1442$ THEN
1178$ ENCRYPT_TYPES = P6 1443$ ENCRYPT_TYPES = P7
1179$ ENDIF 1444$ ENDIF
1180$! 1445$!
1181$! Time To RETURN... 1446$! Time To RETURN...
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h
index 8ad8c25e5a..41c937966e 100644
--- a/src/lib/libcrypto/crypto.h
+++ b/src/lib/libcrypto/crypto.h
@@ -63,17 +63,25 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include <stdlib.h>
67
66#ifndef NO_FP_API 68#ifndef NO_FP_API
67#include <stdio.h> 69#include <stdio.h>
68#endif 70#endif
69 71
70#include <openssl/stack.h> 72#include <openssl/stack.h>
73#include <openssl/safestack.h>
71#include <openssl/opensslv.h> 74#include <openssl/opensslv.h>
72 75
73#ifdef CHARSET_EBCDIC 76#ifdef CHARSET_EBCDIC
74#include <openssl/ebcdic.h> 77#include <openssl/ebcdic.h>
75#endif 78#endif
76 79
80#if defined(VMS) || defined(__VMS)
81#include "vms_idhacks.h"
82#endif
83
84
77/* Backward compatibility to SSLeay */ 85/* Backward compatibility to SSLeay */
78/* This is more to be used to check the correct DLL is being used 86/* This is more to be used to check the correct DLL is being used
79 * in the MS world. */ 87 * in the MS world. */
@@ -111,7 +119,9 @@ extern "C" {
111#define CRYPTO_LOCK_GETSERVBYNAME 21 119#define CRYPTO_LOCK_GETSERVBYNAME 21
112#define CRYPTO_LOCK_READDIR 22 120#define CRYPTO_LOCK_READDIR 22
113#define CRYPTO_LOCK_RSA_BLINDING 23 121#define CRYPTO_LOCK_RSA_BLINDING 23
114#define CRYPTO_NUM_LOCKS 24 122#define CRYPTO_LOCK_DH 24
123#define CRYPTO_LOCK_MALLOC2 25
124#define CRYPTO_NUM_LOCKS 26
115 125
116#define CRYPTO_LOCK 1 126#define CRYPTO_LOCK 1
117#define CRYPTO_UNLOCK 2 127#define CRYPTO_UNLOCK 2
@@ -147,14 +157,16 @@ extern "C" {
147#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */ 157#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */
148#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */ 158#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */
149 159
150/* 160/* The following are bit values to turn on or off options connected to the
151typedef struct crypto_mem_st 161 * malloc checking functionality */
152 { 162
153 char *(*malloc_func)(); 163/* Adds time to the memory checking information */
154 char *(*realloc_func)(); 164#define V_CRYPTO_MDEBUG_TIME 0x1 /* a bit */
155 void (*free_func)(); 165/* Adds thread number to the memory checking information */
156 } CRYPTO_MEM_FUNC; 166#define V_CRYPTO_MDEBUG_THREAD 0x2 /* a bit */
157*/ 167
168#define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)
169
158 170
159/* predec of the BIO type */ 171/* predec of the BIO type */
160typedef struct bio_st BIO_dummy; 172typedef struct bio_st BIO_dummy;
@@ -165,24 +177,30 @@ typedef struct crypto_ex_data_st
165 int dummy; /* gcc is screwing up this data structure :-( */ 177 int dummy; /* gcc is screwing up this data structure :-( */
166 } CRYPTO_EX_DATA; 178 } CRYPTO_EX_DATA;
167 179
180/* Called when a new object is created */
181typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
182 int idx, long argl, void *argp);
183/* Called when an object is free()ed */
184typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
185 int idx, long argl, void *argp);
186/* Called when we need to dup an object */
187typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
188 int idx, long argl, void *argp);
189
168/* This stuff is basically class callback functions 190/* This stuff is basically class callback functions
169 * The current classes are SSL_CTX, SSL, SSL_SESION, and a few more */ 191 * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */
192
170typedef struct crypto_ex_data_func_st 193typedef struct crypto_ex_data_func_st
171 { 194 {
172 long argl; /* Arbitary long */ 195 long argl; /* Arbitary long */
173 char *argp; /* Arbitary char * */ 196 void *argp; /* Arbitary void * */
174 /* Called when a new object is created */ 197 CRYPTO_EX_new *new_func;
175 int (*new_func)(/*char *obj, 198 CRYPTO_EX_free *free_func;
176 char *item,int index,long argl,char *argp*/); 199 CRYPTO_EX_dup *dup_func;
177 /* Called when this object is free()ed */
178 void (*free_func)(/*char *obj,
179 char *item,int index,long argl,char *argp*/);
180
181 /* Called when we need to dup this one */
182 int (*dup_func)(/*char *obj_to,char *obj_from,
183 char **new,int index,long argl,char *argp*/);
184 } CRYPTO_EX_DATA_FUNCS; 200 } CRYPTO_EX_DATA_FUNCS;
185 201
202DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
203
186/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA 204/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
187 * entry. 205 * entry.
188 */ 206 */
@@ -194,63 +212,54 @@ typedef struct crypto_ex_data_func_st
194#define CRYPTO_EX_INDEX_X509_STORE 4 212#define CRYPTO_EX_INDEX_X509_STORE 4
195#define CRYPTO_EX_INDEX_X509_STORE_CTX 5 213#define CRYPTO_EX_INDEX_X509_STORE_CTX 5
196 214
197/* Use this for win32 DLL's */
198#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
199 (char *(*)())malloc,\
200 (char *(*)())realloc,\
201 (void (*)())free)
202 215
203#ifdef CRYPTO_MDEBUG_ALL 216/* This is the default callbacks, but we can have others as well:
204# ifndef CRYPTO_MDEBUG_TIME 217 * this is needed in Win32 where the application malloc and the
205# define CRYPTO_MDEBUG_TIME 218 * library malloc may not be the same.
206# endif 219 */
207# ifndef CRYPTO_MDEBUG_THREAD 220#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
208# define CRYPTO_MDEBUG_THREAD 221 malloc, realloc, free)
209# endif
210#endif
211 222
212#if defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD 223#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
213# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */ 224# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
214# define CRYPTO_MDEBUG 225# define CRYPTO_MDEBUG
215# endif 226# endif
216#endif 227#endif
217 228
218#ifdef CRYPTO_MDEBUG 229/* Set standard debugging functions (not done by default
230 * unless CRYPTO_MDEBUG is defined) */
231#define CRYPTO_malloc_debug_init() do {\
232 CRYPTO_set_mem_debug_functions(\
233 (void (*)())CRYPTO_dbg_malloc,\
234 (void (*)())CRYPTO_dbg_realloc,\
235 (void (*)())CRYPTO_dbg_free,\
236 (void (*)())CRYPTO_dbg_set_options,\
237 (long (*)())CRYPTO_dbg_get_options);\
238 } while(0)
239
240int CRYPTO_mem_ctrl(int mode);
241int CRYPTO_is_mem_check_on(void);
242
243/* for applications */
219#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON) 244#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
220#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF) 245#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
246
247/* for library-internal use */
221#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE) 248#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
222#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE) 249#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
223#define Malloc(num) CRYPTO_dbg_malloc((int)num,__FILE__,__LINE__) 250#define is_MemCheck_on() CRYPTO_is_mem_check_on()
251
252#define Malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__)
224#define Realloc(addr,num) \ 253#define Realloc(addr,num) \
225 CRYPTO_dbg_realloc((char *)addr,(int)num,__FILE__,__LINE__) 254 CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__)
226#define Remalloc(addr,num) \ 255#define Remalloc(addr,num) \
227 CRYPTO_dbg_remalloc((char **)addr,(int)num,__FILE__,__LINE__) 256 CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
228#define FreeFunc CRYPTO_dbg_free
229#define Free(addr) CRYPTO_dbg_free(addr)
230#define Malloc_locked(num) CRYPTO_malloc_locked((int)num)
231#define Free_locked(addr) CRYPTO_free_locked(addr)
232#else
233#define MemCheck_start()
234#define MemCheck_stop()
235#define MemCheck_on()
236#define MemCheck_off()
237#define Remalloc CRYPTO_remalloc
238#if defined(WIN32) || defined(MFUNC)
239#define Malloc CRYPTO_malloc
240#define Realloc(a,n) CRYPTO_realloc(a,(n))
241#define FreeFunc CRYPTO_free 257#define FreeFunc CRYPTO_free
242#define Free(addr) CRYPTO_free(addr) 258#define Free(addr) CRYPTO_free(addr)
243#define Malloc_locked CRYPTO_malloc_locked 259
260#define Malloc_locked(num) CRYPTO_malloc_locked((int)num,__FILE__,__LINE__)
244#define Free_locked(addr) CRYPTO_free_locked(addr) 261#define Free_locked(addr) CRYPTO_free_locked(addr)
245#else 262
246#define Malloc malloc
247#define Realloc realloc
248#define FreeFunc free
249#define Free(addr) free(addr)
250#define Malloc_locked malloc
251#define Free_locked(addr) free(addr)
252#endif /* WIN32 || MFUNC */
253#endif /* MDEBUG */
254 263
255/* Case insensiteve linking causes problems.... */ 264/* Case insensiteve linking causes problems.... */
256#if defined(WIN16) || defined(VMS) 265#if defined(WIN16) || defined(VMS)
@@ -261,15 +270,15 @@ typedef struct crypto_ex_data_func_st
261const char *SSLeay_version(int type); 270const char *SSLeay_version(int type);
262unsigned long SSLeay(void); 271unsigned long SSLeay(void);
263 272
264int CRYPTO_get_ex_new_index(int idx,STACK **sk,long argl,char *argp, 273int CRYPTO_get_ex_new_index(int idx, STACK_OF(CRYPTO_EX_DATA_FUNCS) **skp, long argl, void *argp,
265 int (*new_func)(),int (*dup_func)(),void (*free_func)()); 274 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
266int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad,int idx,char *val); 275int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);
267char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad,int idx); 276void *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad,int idx);
268int CRYPTO_dup_ex_data(STACK *meth,CRYPTO_EX_DATA *from,CRYPTO_EX_DATA *to); 277int CRYPTO_dup_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, CRYPTO_EX_DATA *to,
269void CRYPTO_free_ex_data(STACK *meth,char *obj,CRYPTO_EX_DATA *ad); 278 CRYPTO_EX_DATA *from);
270void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad); 279void CRYPTO_free_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad);
280void CRYPTO_new_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad);
271 281
272int CRYPTO_mem_ctrl(int mode);
273int CRYPTO_get_new_lockid(char *name); 282int CRYPTO_get_new_lockid(char *name);
274 283
275int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */ 284int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
@@ -289,22 +298,51 @@ const char *CRYPTO_get_lock_name(int type);
289int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file, 298int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
290 int line); 299 int line);
291 300
292void CRYPTO_set_mem_functions(char *(*m)(),char *(*r)(), void (*free_func)()); 301/* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions --
293void CRYPTO_get_mem_functions(char *(**m)(),char *(**r)(), void (**f)()); 302 * call the latter last if you need different functions */
294void CRYPTO_set_locked_mem_functions(char *(*m)(), void (*free_func)()); 303int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *));
295void CRYPTO_get_locked_mem_functions(char *(**m)(), void (**f)()); 304int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *));
305int CRYPTO_set_mem_debug_functions(void (*m)(),void (*r)(),void (*f)(),void (*so)(),long (*go)());
306void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));
307void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));
308void CRYPTO_get_mem_debug_functions(void (**m)(),void (**r)(),void (**f)(),void (**so)(),long (**go)());
296 309
297void *CRYPTO_malloc_locked(int num); 310void *CRYPTO_malloc_locked(int num, const char *file, int line);
298void CRYPTO_free_locked(void *); 311void CRYPTO_free_locked(void *);
299void *CRYPTO_malloc(int num); 312void *CRYPTO_malloc(int num, const char *file, int line);
300void CRYPTO_free(void *); 313void CRYPTO_free(void *);
301void *CRYPTO_realloc(void *addr,int num); 314void *CRYPTO_realloc(void *addr,int num, const char *file, int line);
302void *CRYPTO_remalloc(void *addr,int num); 315void *CRYPTO_remalloc(void *addr,int num, const char *file, int line);
316
317void CRYPTO_set_mem_debug_options(long bits);
318long CRYPTO_get_mem_debug_options(void);
319
320#define CRYPTO_push_info(info) \
321 CRYPTO_push_info_(info, __FILE__, __LINE__);
322int CRYPTO_push_info_(const char *info, const char *file, int line);
323int CRYPTO_pop_info(void);
324int CRYPTO_remove_all_info(void);
325
326/* The last argument has the following significance:
327 *
328 * 0: called before the actual memory allocation has taken place
329 * 1: called after the actual memory allocation has taken place
330 */
331void CRYPTO_dbg_malloc(void *addr,int num,const char *file,int line,int before_p);
332void CRYPTO_dbg_realloc(void *addr1,void *addr2,int num,const char *file,int line,int before_p);
333void CRYPTO_dbg_free(void *addr,int before_p);
334
335/* Tell the debugging code about options. By default, the following values
336 * apply:
337 *
338 * 0: Clear all options.
339 * 1: Set the "Show Time" option.
340 * 2: Set the "Show Thread Number" option.
341 * 3: 1 + 2
342 */
343void CRYPTO_dbg_set_options(long bits);
344long CRYPTO_dbg_get_options(void);
303 345
304void *CRYPTO_dbg_malloc(int num,const char *file,int line);
305void *CRYPTO_dbg_realloc(void *addr,int num,const char *file,int line);
306void CRYPTO_dbg_free(void *);
307void *CRYPTO_dbg_remalloc(void *addr,int num,const char *file,int line);
308#ifndef NO_FP_API 346#ifndef NO_FP_API
309void CRYPTO_mem_leaks_fp(FILE *); 347void CRYPTO_mem_leaks_fp(FILE *);
310#endif 348#endif
@@ -312,7 +350,7 @@ void CRYPTO_mem_leaks(struct bio_st *bio);
312/* unsigned long order, char *file, int line, int num_bytes, char *addr */ 350/* unsigned long order, char *file, int line, int num_bytes, char *addr */
313void CRYPTO_mem_leaks_cb(void (*cb)()); 351void CRYPTO_mem_leaks_cb(void (*cb)());
314 352
315void ERR_load_CRYPTO_strings(void ); 353void ERR_load_CRYPTO_strings(void);
316 354
317/* BEGIN ERROR CODES */ 355/* BEGIN ERROR CODES */
318/* The following lines are auto generated by the script mkerr.pl. Any changes 356/* The following lines are auto generated by the script mkerr.pl. Any changes
diff --git a/src/lib/libcrypto/des/Makefile.ssl b/src/lib/libcrypto/des/Makefile.ssl
index 7f9600cf02..41976655e9 100644
--- a/src/lib/libcrypto/des/Makefile.ssl
+++ b/src/lib/libcrypto/des/Makefile.ssl
@@ -15,6 +15,7 @@ MAKE= make -f Makefile.ssl
15MAKEDEPEND= $(TOP)/util/domd $(TOP) 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
16MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
17AR= ar r 17AR= ar r
18RANLIB= ranlib
18DES_ENC= des_enc.o fcrypt_b.o 19DES_ENC= des_enc.o fcrypt_b.o
19# or use 20# or use
20#DES_ENC= dx86-elf.o yx86-elf.o 21#DES_ENC= dx86-elf.o yx86-elf.o
@@ -162,14 +163,15 @@ enc_read.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
162enc_read.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 163enc_read.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
163enc_read.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 164enc_read.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
164enc_read.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 165enc_read.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
165enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 166enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
166enc_read.o: ../cryptlib.h des_locl.h 167enc_read.o: ../../include/openssl/stack.h ../cryptlib.h des_locl.h
167enc_writ.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 168enc_writ.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
168enc_writ.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 169enc_writ.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
169enc_writ.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 170enc_writ.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
170enc_writ.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 171enc_writ.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
171enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 172enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
172enc_writ.o: ../../include/openssl/stack.h ../cryptlib.h des_locl.h 173enc_writ.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
174enc_writ.o: ../cryptlib.h des_locl.h
173fcrypt.o: ../../include/openssl/des.h ../../include/openssl/des.h 175fcrypt.o: ../../include/openssl/des.h ../../include/openssl/des.h
174fcrypt.o: ../../include/openssl/e_os2.h ../../include/openssl/e_os2.h 176fcrypt.o: ../../include/openssl/e_os2.h ../../include/openssl/e_os2.h
175fcrypt.o: ../../include/openssl/opensslconf.h 177fcrypt.o: ../../include/openssl/opensslconf.h
@@ -187,15 +189,15 @@ pcbc_enc.o: ../../include/openssl/opensslconf.h des_locl.h
187qud_cksm.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 189qud_cksm.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
188qud_cksm.o: ../../include/openssl/opensslconf.h des_locl.h 190qud_cksm.o: ../../include/openssl/opensslconf.h des_locl.h
189rand_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 191rand_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
190rand_key.o: ../../include/openssl/opensslconf.h des_locl.h 192rand_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/rand.h
191read2pwd.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 193read2pwd.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
192read2pwd.o: ../../include/openssl/opensslconf.h des_locl.h 194read2pwd.o: ../../include/openssl/opensslconf.h des_locl.h
193read_pwd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 195read_pwd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
194read_pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 196read_pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
195read_pwd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 197read_pwd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
196read_pwd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 198read_pwd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
197read_pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 199read_pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
198read_pwd.o: ../cryptlib.h des_locl.h 200read_pwd.o: ../../include/openssl/stack.h ../cryptlib.h des_locl.h
199rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 201rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
200rpc_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_ver.h rpc_des.h 202rpc_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_ver.h rpc_des.h
201set_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 203set_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
diff --git a/src/lib/libcrypto/des/cbc3_enc.c b/src/lib/libcrypto/des/cbc3_enc.c
index 3863a676d4..527e74f3de 100644
--- a/src/lib/libcrypto/des/cbc3_enc.c
+++ b/src/lib/libcrypto/des/cbc3_enc.c
@@ -58,7 +58,7 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61/* HAS BUGS? DON'T USE - this is only present for use in des.c */ 61/* HAS BUGS! DON'T USE - this is only present for use in des.c */
62void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length, 62void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
63 des_key_schedule ks1, des_key_schedule ks2, des_cblock *iv1, 63 des_key_schedule ks1, des_key_schedule ks2, des_cblock *iv1,
64 des_cblock *iv2, int enc) 64 des_cblock *iv2, int enc)
@@ -69,11 +69,14 @@ void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
69 69
70 if (enc == DES_ENCRYPT) 70 if (enc == DES_ENCRYPT)
71 { 71 {
72 des_cbc_encrypt(input,output,length,ks1,iv1,enc); 72 des_cbc_encrypt((unsigned char*)input,
73 (unsigned char*)output,length,ks1,iv1,enc);
73 if (length >= sizeof(des_cblock)) 74 if (length >= sizeof(des_cblock))
74 memcpy(niv1,output[off],sizeof(des_cblock)); 75 memcpy(niv1,output[off],sizeof(des_cblock));
75 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc); 76 des_cbc_encrypt((unsigned char*)output,
76 des_cbc_encrypt(output,output,l8,ks1,iv2, enc); 77 (unsigned char*)output,l8,ks2,iv1,!enc);
78 des_cbc_encrypt((unsigned char*)output,
79 (unsigned char*)output,l8,ks1,iv2,enc);
77 if (length >= sizeof(des_cblock)) 80 if (length >= sizeof(des_cblock))
78 memcpy(niv2,output[off],sizeof(des_cblock)); 81 memcpy(niv2,output[off],sizeof(des_cblock));
79 } 82 }
@@ -81,11 +84,14 @@ void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
81 { 84 {
82 if (length >= sizeof(des_cblock)) 85 if (length >= sizeof(des_cblock))
83 memcpy(niv2,input[off],sizeof(des_cblock)); 86 memcpy(niv2,input[off],sizeof(des_cblock));
84 des_cbc_encrypt(input,output,l8,ks1,iv2,enc); 87 des_cbc_encrypt((unsigned char*)input,
85 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc); 88 (unsigned char*)output,l8,ks1,iv2,enc);
89 des_cbc_encrypt((unsigned char*)output,
90 (unsigned char*)output,l8,ks2,iv1,!enc);
86 if (length >= sizeof(des_cblock)) 91 if (length >= sizeof(des_cblock))
87 memcpy(niv1,output[off],sizeof(des_cblock)); 92 memcpy(niv1,output[off],sizeof(des_cblock));
88 des_cbc_encrypt(output,output,length,ks1,iv1, enc); 93 des_cbc_encrypt((unsigned char*)output,
94 (unsigned char*)output,length,ks1,iv1,enc);
89 } 95 }
90 memcpy(*iv1,niv1,sizeof(des_cblock)); 96 memcpy(*iv1,niv1,sizeof(des_cblock));
91 memcpy(*iv2,niv2,sizeof(des_cblock)); 97 memcpy(*iv2,niv2,sizeof(des_cblock));
diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c
index b2d7f0da78..91d7153b34 100644
--- a/src/lib/libcrypto/des/des.c
+++ b/src/lib/libcrypto/des/des.c
@@ -325,25 +325,25 @@ void usage(void)
325"des <options> [input-file [output-file]]", 325"des <options> [input-file [output-file]]",
326"options:", 326"options:",
327"-v : des(1) version number", 327"-v : des(1) version number",
328"-e : encrypt using sunOS compatible user key to DES key conversion.", 328"-e : encrypt using SunOS compatible user key to DES key conversion.",
329"-E : encrypt ", 329"-E : encrypt ",
330"-d : decrypt using sunOS compatible user key to DES key conversion.", 330"-d : decrypt using SunOS compatible user key to DES key conversion.",
331"-D : decrypt ", 331"-D : decrypt ",
332"-c[ckname] : generate a cbc_cksum using sunOS compatible user key to", 332"-c[ckname] : generate a cbc_cksum using SunOS compatible user key to",
333" DES key conversion and output to ckname (stdout default,", 333" DES key conversion and output to ckname (stdout default,",
334" stderr if data being output on stdout). The checksum is", 334" stderr if data being output on stdout). The checksum is",
335" generated before encryption and after decryption if used", 335" generated before encryption and after decryption if used",
336" in conjunction with -[eEdD].", 336" in conjunction with -[eEdD].",
337"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].", 337"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
338"-k key : use key 'key'", 338"-k key : use key 'key'",
339"-h : the key that is entered will be a hexidecimal number", 339"-h : the key that is entered will be a hexadecimal number",
340" that is used directly as the des key", 340" that is used directly as the des key",
341"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]", 341"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
342" (uuname is the filename to put in the uuencode header).", 342" (uuname is the filename to put in the uuencode header).",
343"-b : encrypt using DES in ecb encryption mode, the defaut is cbc mode.", 343"-b : encrypt using DES in ecb encryption mode, the default is cbc mode.",
344"-3 : encrypt using tripple DES encryption. This uses 2 keys", 344"-3 : encrypt using triple DES encryption. This uses 2 keys",
345" generated from the input key. If the input key is less", 345" generated from the input key. If the input key is less",
346" than 8 characters long, this is equivelent to normal", 346" than 8 characters long, this is equivalent to normal",
347" encryption. Default is triple cbc, -b makes it triple ecb.", 347" encryption. Default is triple cbc, -b makes it triple ecb.",
348NULL 348NULL
349}; 349};
@@ -425,7 +425,7 @@ void doencryption(void)
425 else 425 else
426 k2[i-8]=k; 426 k2[i-8]=k;
427 } 427 }
428 des_set_key(&k2,ks2); 428 des_set_key_unchecked(&k2,ks2);
429 memset(k2,0,sizeof(k2)); 429 memset(k2,0,sizeof(k2));
430 } 430 }
431 else if (longk || flag3) 431 else if (longk || flag3)
@@ -433,7 +433,7 @@ void doencryption(void)
433 if (flag3) 433 if (flag3)
434 { 434 {
435 des_string_to_2keys(key,&kk,&k2); 435 des_string_to_2keys(key,&kk,&k2);
436 des_set_key(&k2,ks2); 436 des_set_key_unchecked(&k2,ks2);
437 memset(k2,0,sizeof(k2)); 437 memset(k2,0,sizeof(k2));
438 } 438 }
439 else 439 else
@@ -455,7 +455,7 @@ void doencryption(void)
455 kk[i]=key[i]|0x80; 455 kk[i]=key[i]|0x80;
456 } 456 }
457 457
458 des_set_key(&kk,ks); 458 des_set_key_unchecked(&kk,ks);
459 memset(key,0,sizeof(key)); 459 memset(key,0,sizeof(key));
460 memset(kk,0,sizeof(kk)); 460 memset(kk,0,sizeof(kk));
461 /* woops - A bug that does not showup under unix :-( */ 461 /* woops - A bug that does not showup under unix :-( */
@@ -484,7 +484,7 @@ void doencryption(void)
484 if (feof(DES_IN)) 484 if (feof(DES_IN))
485 { 485 {
486 for (i=7-rem; i>0; i--) 486 for (i=7-rem; i>0; i--)
487 RAND_bytes(buf + l++, 1); 487 RAND_pseudo_bytes(buf + l++, 1);
488 buf[l++]=rem; 488 buf[l++]=rem;
489 ex=1; 489 ex=1;
490 len+=rem; 490 len+=rem;
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
index 67f90aaf17..98a9c4127c 100644
--- a/src/lib/libcrypto/des/des.h
+++ b/src/lib/libcrypto/des/des.h
@@ -186,15 +186,20 @@ void des_pcbc_encrypt(const unsigned char *input,unsigned char *output,
186DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[], 186DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[],
187 long length,int out_count,des_cblock *seed); 187 long length,int out_count,des_cblock *seed);
188void des_random_seed(des_cblock *key); 188void des_random_seed(des_cblock *key);
189void des_random_key(des_cblock *ret); 189int des_random_key(des_cblock *ret);
190int des_read_password(des_cblock *key,const char *prompt,int verify); 190int des_read_password(des_cblock *key,const char *prompt,int verify);
191int des_read_2passwords(des_cblock *key1,des_cblock *key2, 191int des_read_2passwords(des_cblock *key1,des_cblock *key2,
192 const char *prompt,int verify); 192 const char *prompt,int verify);
193int des_read_pw_string(char *buf,int length,const char *prompt,int verify); 193int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
194void des_set_odd_parity(des_cblock *key); 194void des_set_odd_parity(des_cblock *key);
195int des_is_weak_key(const_des_cblock *key); 195int des_is_weak_key(const_des_cblock *key);
196/* des_set_key (= set_key = des_key_sched = key_sched) calls
197 * des_set_key_checked if global variable des_check_key is set,
198 * des_set_key_unchecked otherwise. */
196int des_set_key(const_des_cblock *key,des_key_schedule schedule); 199int des_set_key(const_des_cblock *key,des_key_schedule schedule);
197int des_key_sched(const_des_cblock *key,des_key_schedule schedule); 200int des_key_sched(const_des_cblock *key,des_key_schedule schedule);
201int des_set_key_checked(const_des_cblock *key,des_key_schedule schedule);
202void des_set_key_unchecked(const_des_cblock *key,des_key_schedule schedule);
198void des_string_to_key(const char *str,des_cblock *key); 203void des_string_to_key(const char *str,des_cblock *key);
199void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2); 204void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2);
200void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, 205void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
index d6ea17cb68..4dfed199a7 100644
--- a/src/lib/libcrypto/des/des_locl.h
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -72,7 +72,11 @@
72 72
73#ifndef MSDOS 73#ifndef MSDOS
74#if !defined(VMS) || defined(__DECC) 74#if !defined(VMS) || defined(__DECC)
75#include OPENSSL_UNISTD 75#ifdef OPENSSL_UNISTD
76# include OPENSSL_UNISTD
77#else
78# include <unistd.h>
79#endif
76#include <math.h> 80#include <math.h>
77#endif 81#endif
78#endif 82#endif
@@ -178,14 +182,14 @@
178#endif 182#endif
179 183
180/* The changes to this macro may help or hinder, depending on the 184/* The changes to this macro may help or hinder, depending on the
181 * compiler and the achitecture. gcc2 always seems to do well :-). 185 * compiler and the architecture. gcc2 always seems to do well :-).
182 * Inspired by Dana How <how@isl.stanford.edu> 186 * Inspired by Dana How <how@isl.stanford.edu>
183 * DO NOT use the alternative version on machines with 8 byte longs. 187 * DO NOT use the alternative version on machines with 8 byte longs.
184 * It does not seem to work on the Alpha, even when DES_LONG is 4 188 * It does not seem to work on the Alpha, even when DES_LONG is 4
185 * bytes, probably an issue of accessing non-word aligned objects :-( */ 189 * bytes, probably an issue of accessing non-word aligned objects :-( */
186#ifdef DES_PTR 190#ifdef DES_PTR
187 191
188/* It recently occured to me that 0^0^0^0^0^0^0 == 0, so there 192/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
189 * is no reason to not xor all the sub items together. This potentially 193 * is no reason to not xor all the sub items together. This potentially
190 * saves a register since things can be xored directly into L */ 194 * saves a register since things can be xored directly into L */
191 195
diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c
index 746c456f8f..b2ca7ac31d 100644
--- a/src/lib/libcrypto/des/des_opts.c
+++ b/src/lib/libcrypto/des/des_opts.c
@@ -434,17 +434,17 @@ int main(int argc, char **argv)
434 } 434 }
435 435
436#ifndef TIMES 436#ifndef TIMES
437 fprintf(stderr,"To get the most acurate results, try to run this\n"); 437 fprintf(stderr,"To get the most accurate results, try to run this\n");
438 fprintf(stderr,"program when this computer is idle.\n"); 438 fprintf(stderr,"program when this computer is idle.\n");
439#endif 439#endif
440 440
441 des_set_key(&key,sch); 441 des_set_key_unchecked(&key,sch);
442 des_set_key(&key2,sch2); 442 des_set_key_unchecked(&key2,sch2);
443 des_set_key(&key3,sch3); 443 des_set_key_unchecked(&key3,sch3);
444 444
445#ifndef SIGALRM 445#ifndef SIGALRM
446 fprintf(stderr,"First we calculate the approximate speed ...\n"); 446 fprintf(stderr,"First we calculate the approximate speed ...\n");
447 des_set_key(&key,sch); 447 des_set_key_unchecked(&key,sch);
448 count=10; 448 count=10;
449 do { 449 do {
450 long i; 450 long i;
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c
index 5a04fc9298..9ad4ecb072 100644
--- a/src/lib/libcrypto/des/destest.c
+++ b/src/lib/libcrypto/des/destest.c
@@ -234,7 +234,7 @@ static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
234 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; 234 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
235 235
236static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; 236static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
237static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; 237static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86};
238static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; 238static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
239static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; 239static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
240/* Changed the following text constant to binary so it will work on ebcdic 240/* Changed the following text constant to binary so it will work on ebcdic
@@ -254,12 +254,24 @@ static unsigned char cbc_ok[32]={
254 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, 254 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
255 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; 255 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
256 256
257#ifdef SCREW_THE_PARITY
258#error "SCREW_THE_PARITY is not ment to be defined."
259#error "Original vectors are preserved for reference only."
260static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
257static unsigned char xcbc_ok[32]={ 261static unsigned char xcbc_ok[32]={
258 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, 262 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
259 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, 263 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
260 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, 264 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
261 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, 265 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
262 }; 266 };
267#else
268static unsigned char xcbc_ok[32]={
269 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29,
270 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1,
271 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53,
272 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4,
273 };
274#endif
263 275
264static unsigned char cbc3_ok[32]={ 276static unsigned char cbc3_ok[32]={
265 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, 277 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
@@ -309,8 +321,8 @@ static unsigned char ofb_cipher[24]=
309 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 321 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
310 }; 322 };
311 323
312DES_LONG cbc_cksum_ret=0xB462FEF7L; 324static DES_LONG cbc_cksum_ret=0xB462FEF7L;
313unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; 325static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
314 326
315static char *pt(unsigned char *p); 327static char *pt(unsigned char *p);
316static int cfb_test(int bits, unsigned char *cfb_cipher); 328static int cfb_test(int bits, unsigned char *cfb_cipher);
@@ -331,17 +343,17 @@ int main(int argc, char *argv[])
331 343
332#ifndef NO_DESCBCM 344#ifndef NO_DESCBCM
333 printf("Doing cbcm\n"); 345 printf("Doing cbcm\n");
334 if ((j=des_key_sched(&cbc_key,ks)) != 0) 346 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
335 { 347 {
336 printf("Key error %d\n",j); 348 printf("Key error %d\n",j);
337 err=1; 349 err=1;
338 } 350 }
339 if ((j=des_key_sched(&cbc2_key,ks2)) != 0) 351 if ((j=des_set_key_checked(&cbc2_key,ks2)) != 0)
340 { 352 {
341 printf("Key error %d\n",j); 353 printf("Key error %d\n",j);
342 err=1; 354 err=1;
343 } 355 }
344 if ((j=des_key_sched(&cbc3_key,ks3)) != 0) 356 if ((j=des_set_key_checked(&cbc3_key,ks3)) != 0)
345 { 357 {
346 printf("Key error %d\n",j); 358 printf("Key error %d\n",j);
347 err=1; 359 err=1;
@@ -385,11 +397,7 @@ int main(int argc, char *argv[])
385 printf("Doing ecb\n"); 397 printf("Doing ecb\n");
386 for (i=0; i<NUM_TESTS; i++) 398 for (i=0; i<NUM_TESTS; i++)
387 { 399 {
388 if ((j=des_key_sched(&key_data[i],ks)) != 0) 400 des_set_key_unchecked(&key_data[i],ks);
389 {
390 printf("Key error %2d:%d\n",i+1,j);
391 err=1;
392 }
393 memcpy(in,plain_data[i],8); 401 memcpy(in,plain_data[i],8);
394 memset(out,0,8); 402 memset(out,0,8);
395 memset(outin,0,8); 403 memset(outin,0,8);
@@ -415,21 +423,9 @@ int main(int argc, char *argv[])
415 printf("Doing ede ecb\n"); 423 printf("Doing ede ecb\n");
416 for (i=0; i<(NUM_TESTS-1); i++) 424 for (i=0; i<(NUM_TESTS-1); i++)
417 { 425 {
418 if ((j=des_key_sched(&key_data[i],ks)) != 0) 426 des_set_key_unchecked(&key_data[i],ks);
419 { 427 des_set_key_unchecked(&key_data[i+1],ks2);
420 err=1; 428 des_set_key_unchecked(&key_data[i+2],ks3);
421 printf("Key error %2d:%d\n",i+1,j);
422 }
423 if ((j=des_key_sched(&key_data[i+1],ks2)) != 0)
424 {
425 printf("Key error %2d:%d\n",i+2,j);
426 err=1;
427 }
428 if ((j=des_key_sched(&key_data[i+2],ks3)) != 0)
429 {
430 printf("Key error %2d:%d\n",i+3,j);
431 err=1;
432 }
433 memcpy(in,plain_data[i],8); 429 memcpy(in,plain_data[i],8);
434 memset(out,0,8); 430 memset(out,0,8);
435 memset(outin,0,8); 431 memset(outin,0,8);
@@ -453,7 +449,7 @@ int main(int argc, char *argv[])
453#endif 449#endif
454 450
455 printf("Doing cbc\n"); 451 printf("Doing cbc\n");
456 if ((j=des_key_sched(&cbc_key,ks)) != 0) 452 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
457 { 453 {
458 printf("Key error %d\n",j); 454 printf("Key error %d\n",j);
459 err=1; 455 err=1;
@@ -464,7 +460,10 @@ int main(int argc, char *argv[])
464 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks, 460 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
465 &iv3,DES_ENCRYPT); 461 &iv3,DES_ENCRYPT);
466 if (memcmp(cbc_out,cbc_ok,32) != 0) 462 if (memcmp(cbc_out,cbc_ok,32) != 0)
463 {
467 printf("cbc_encrypt encrypt error\n"); 464 printf("cbc_encrypt encrypt error\n");
465 err=1;
466 }
468 467
469 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 468 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
470 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, 469 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
@@ -477,7 +476,7 @@ int main(int argc, char *argv[])
477 476
478#ifndef LIBDES_LIT 477#ifndef LIBDES_LIT
479 printf("Doing desx cbc\n"); 478 printf("Doing desx cbc\n");
480 if ((j=des_key_sched(&cbc_key,ks)) != 0) 479 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
481 { 480 {
482 printf("Key error %d\n",j); 481 printf("Key error %d\n",j);
483 err=1; 482 err=1;
@@ -490,6 +489,7 @@ int main(int argc, char *argv[])
490 if (memcmp(cbc_out,xcbc_ok,32) != 0) 489 if (memcmp(cbc_out,xcbc_ok,32) != 0)
491 { 490 {
492 printf("des_xcbc_encrypt encrypt error\n"); 491 printf("des_xcbc_encrypt encrypt error\n");
492 err=1;
493 } 493 }
494 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 494 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
495 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, 495 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
@@ -502,17 +502,17 @@ int main(int argc, char *argv[])
502#endif 502#endif
503 503
504 printf("Doing ede cbc\n"); 504 printf("Doing ede cbc\n");
505 if ((j=des_key_sched(&cbc_key,ks)) != 0) 505 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
506 { 506 {
507 printf("Key error %d\n",j); 507 printf("Key error %d\n",j);
508 err=1; 508 err=1;
509 } 509 }
510 if ((j=des_key_sched(&cbc2_key,ks2)) != 0) 510 if ((j=des_set_key_checked(&cbc2_key,ks2)) != 0)
511 { 511 {
512 printf("Key error %d\n",j); 512 printf("Key error %d\n",j);
513 err=1; 513 err=1;
514 } 514 }
515 if ((j=des_key_sched(&cbc3_key,ks3)) != 0) 515 if ((j=des_set_key_checked(&cbc3_key,ks3)) != 0)
516 { 516 {
517 printf("Key error %d\n",j); 517 printf("Key error %d\n",j);
518 err=1; 518 err=1;
@@ -543,7 +543,7 @@ int main(int argc, char *argv[])
543 543
544#ifndef LIBDES_LIT 544#ifndef LIBDES_LIT
545 printf("Doing pcbc\n"); 545 printf("Doing pcbc\n");
546 if ((j=des_key_sched(&cbc_key,ks)) != 0) 546 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
547 { 547 {
548 printf("Key error %d\n",j); 548 printf("Key error %d\n",j);
549 err=1; 549 err=1;
@@ -606,7 +606,7 @@ int main(int argc, char *argv[])
606 printf("done\n"); 606 printf("done\n");
607 607
608 printf("Doing ofb\n"); 608 printf("Doing ofb\n");
609 des_key_sched(&ofb_key,ks); 609 des_set_key_checked(&ofb_key,ks);
610 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 610 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
611 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp); 611 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
612 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) 612 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
@@ -635,7 +635,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
635 } 635 }
636 636
637 printf("Doing ofb64\n"); 637 printf("Doing ofb64\n");
638 des_key_sched(&ofb_key,ks); 638 des_set_key_checked(&ofb_key,ks);
639 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 639 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
640 memset(ofb_buf1,0,sizeof(ofb_buf1)); 640 memset(ofb_buf1,0,sizeof(ofb_buf1));
641 memset(ofb_buf2,0,sizeof(ofb_buf1)); 641 memset(ofb_buf2,0,sizeof(ofb_buf1));
@@ -660,7 +660,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
660 } 660 }
661 661
662 printf("Doing ede_ofb64\n"); 662 printf("Doing ede_ofb64\n");
663 des_key_sched(&ofb_key,ks); 663 des_set_key_checked(&ofb_key,ks);
664 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 664 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
665 memset(ofb_buf1,0,sizeof(ofb_buf1)); 665 memset(ofb_buf1,0,sizeof(ofb_buf1));
666 memset(ofb_buf2,0,sizeof(ofb_buf1)); 666 memset(ofb_buf2,0,sizeof(ofb_buf1));
@@ -686,7 +686,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
686 } 686 }
687 687
688 printf("Doing cbc_cksum\n"); 688 printf("Doing cbc_cksum\n");
689 des_key_sched(&cbc_key,ks); 689 des_set_key_checked(&cbc_key,ks);
690 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv); 690 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
691 if (cs != cbc_cksum_ret) 691 if (cs != cbc_cksum_ret)
692 { 692 {
@@ -795,8 +795,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
795 err=1; 795 err=1;
796 } 796 }
797 printf("\n"); 797 printf("\n");
798 exit(err); 798 return(err);
799 return(0);
800 } 799 }
801 800
802static char *pt(unsigned char *p) 801static char *pt(unsigned char *p)
@@ -825,7 +824,7 @@ static int cfb_test(int bits, unsigned char *cfb_cipher)
825 des_key_schedule ks; 824 des_key_schedule ks;
826 int i,err=0; 825 int i,err=0;
827 826
828 des_key_sched(&cfb_key,ks); 827 des_set_key_checked(&cfb_key,ks);
829 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 828 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
830 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp, 829 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
831 DES_ENCRYPT); 830 DES_ENCRYPT);
@@ -854,7 +853,7 @@ static int cfb64_test(unsigned char *cfb_cipher)
854 des_key_schedule ks; 853 des_key_schedule ks;
855 int err=0,i,n; 854 int err=0,i,n;
856 855
857 des_key_sched(&cfb_key,ks); 856 des_set_key_checked(&cfb_key,ks);
858 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 857 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
859 n=0; 858 n=0;
860 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT); 859 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
@@ -887,7 +886,7 @@ static int ede_cfb64_test(unsigned char *cfb_cipher)
887 des_key_schedule ks; 886 des_key_schedule ks;
888 int err=0,i,n; 887 int err=0,i,n;
889 888
890 des_key_sched(&cfb_key,ks); 889 des_set_key_checked(&cfb_key,ks);
891 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 890 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
892 n=0; 891 n=0;
893 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n, 892 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
index 694970ccd2..7399ff7269 100644
--- a/src/lib/libcrypto/des/enc_read.c
+++ b/src/lib/libcrypto/des/enc_read.c
@@ -147,7 +147,7 @@ int des_enc_read(int fd, void *buf, int len, des_key_schedule sched,
147 /* first - get the length */ 147 /* first - get the length */
148 while (net_num < HDRSIZE) 148 while (net_num < HDRSIZE)
149 { 149 {
150 i=read(fd,&(net[net_num]),HDRSIZE-net_num); 150 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
151#ifdef EINTR 151#ifdef EINTR
152 if ((i == -1) && (errno == EINTR)) continue; 152 if ((i == -1) && (errno == EINTR)) continue;
153#endif 153#endif
@@ -169,7 +169,7 @@ int des_enc_read(int fd, void *buf, int len, des_key_schedule sched,
169 net_num=0; 169 net_num=0;
170 while (net_num < rnum) 170 while (net_num < rnum)
171 { 171 {
172 i=read(fd,&(net[net_num]),rnum-net_num); 172 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
173#ifdef EINTR 173#ifdef EINTR
174 if ((i == -1) && (errno == EINTR)) continue; 174 if ((i == -1) && (errno == EINTR)) continue;
175#endif 175#endif
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
index ba3f0822ef..4d3452724e 100644
--- a/src/lib/libcrypto/des/enc_writ.c
+++ b/src/lib/libcrypto/des/enc_writ.c
@@ -130,12 +130,12 @@ int des_enc_write(int fd, const void *_buf, int len,
130 { 130 {
131 cp=shortbuf; 131 cp=shortbuf;
132 memcpy(shortbuf,buf,len); 132 memcpy(shortbuf,buf,len);
133 RAND_bytes(shortbuf+len, 8-len); 133 RAND_pseudo_bytes(shortbuf+len, 8-len);
134 rnum=8; 134 rnum=8;
135 } 135 }
136 else 136 else
137 { 137 {
138 cp=(unsigned char*)buf; 138 cp=buf;
139 rnum=((len+7)/8*8); /* round up to nearest eight */ 139 rnum=((len+7)/8*8); /* round up to nearest eight */
140 } 140 }
141 141
@@ -152,13 +152,16 @@ int des_enc_write(int fd, const void *_buf, int len,
152 for (j=0; j<outnum; j+=i) 152 for (j=0; j<outnum; j+=i)
153 { 153 {
154 /* eay 26/08/92 I was not doing writing from where we 154 /* eay 26/08/92 I was not doing writing from where we
155 * got upto. */ 155 * got up to. */
156 i=write(fd,&(outbuf[j]),outnum-j); 156 i=write(fd,(void *)&(outbuf[j]),outnum-j);
157 if (i == -1) 157 if (i == -1)
158 { 158 {
159#ifdef EINTR
159 if (errno == EINTR) 160 if (errno == EINTR)
160 i=0; 161 i=0;
161 else /* This is really a bad error - very bad 162 else
163#endif
164 /* This is really a bad error - very bad
162 * It will stuff-up both ends. */ 165 * It will stuff-up both ends. */
163 return(-1); 166 return(-1);
164 } 167 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
index f36746b376..fa1b8aa34a 100644
--- a/src/lib/libcrypto/des/fcrypt.c
+++ b/src/lib/libcrypto/des/fcrypt.c
@@ -1,7 +1,7 @@
1/* NOCW */ 1/* NOCW */
2#include <stdio.h> 2#include <stdio.h>
3 3
4/* This version of crypt has been developed from my MIT compatable 4/* This version of crypt has been developed from my MIT compatible
5 * DES library. 5 * DES library.
6 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au 6 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
7 * Eric Young (eay@cryptsoft.com) 7 * Eric Young (eay@cryptsoft.com)
@@ -11,7 +11,7 @@
11 * I have included directive PARA for shared memory computers. 11 * I have included directive PARA for shared memory computers.
12 * I have included a directive LONGCRYPT to using this routine to cipher 12 * I have included a directive LONGCRYPT to using this routine to cipher
13 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN 13 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
14 * definition is the maximum of lenght of password and can changed. I have 14 * definition is the maximum of length of password and can changed. I have
15 * defined 24. 15 * defined 24.
16 */ 16 */
17 17
@@ -103,8 +103,8 @@ char *ret;
103 * returns *\0XXXXXXXXX 103 * returns *\0XXXXXXXXX
104 * The \0 makes the string look like * so the pwd "*" would 104 * The \0 makes the string look like * so the pwd "*" would
105 * crypt to "*". This was found when replacing the crypt in 105 * crypt to "*". This was found when replacing the crypt in
106 * our shared libraries. People found that the disbled 106 * our shared libraries. People found that the disabled
107 * accounts effectivly had no passwd :-(. */ 107 * accounts effectively had no passwd :-(. */
108 x=ret[0]=((salt[0] == '\0')?'A':salt[0]); 108 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
109 Eswap0=con_salt[x]<<2; 109 Eswap0=con_salt[x]<<2;
110 x=ret[1]=((salt[1] == '\0')?'A':salt[1]); 110 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
@@ -123,7 +123,7 @@ r=(r+7)/8;
123 for (; i<8; i++) 123 for (; i<8; i++)
124 key[i]=0; 124 key[i]=0;
125 125
126 des_set_key((des_cblock *)(key),ks); 126 des_set_key_unchecked(&key,ks);
127 fcrypt_body(&(out[0]),ks,Eswap0,Eswap1); 127 fcrypt_body(&(out[0]),ks,Eswap0,Eswap1);
128 128
129 ll=out[0]; l2c(ll,b); 129 ll=out[0]; l2c(ll,b);
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
index 9cbea97c1f..83c94054e3 100644
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ b/src/lib/libcrypto/des/fcrypt_b.c
@@ -58,7 +58,7 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60 60
61/* This version of crypt has been developed from my MIT compatable 61/* This version of crypt has been developed from my MIT compatible
62 * DES library. 62 * DES library.
63 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au 63 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
64 * Eric Young (eay@cryptsoft.com) 64 * Eric Young (eay@cryptsoft.com)
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
index fc11792cda..7816a8f25c 100644
--- a/src/lib/libcrypto/des/rand_key.c
+++ b/src/lib/libcrypto/des/rand_key.c
@@ -1,114 +1,69 @@
1/* crypto/des/rand_key.c */ 1/* crypto/des/rand_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@openssl.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 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 *
57 */ 54 */
58 55
59#include "des_locl.h" 56#include <openssl/des.h>
60#include <time.h> 57#include <openssl/rand.h>
61
62static int seed=0;
63static des_cblock init;
64 58
65void des_random_seed(des_cblock *key) 59void des_random_seed(des_cblock *key)
66 { 60 {
67 memcpy(&init,key,sizeof(des_cblock)); 61 RAND_seed(key, sizeof(des_cblock));
68 seed=1;
69 } 62 }
70 63
71void des_random_key(des_cblock *ret) 64int des_random_key(des_cblock *ret)
72 { 65 {
73 des_key_schedule ks; 66 int r = RAND_bytes((unsigned char *)ret, sizeof(des_cblock));
74 static DES_LONG c=0; 67 des_set_odd_parity(ret);
75 static unsigned short pid=0; 68 return r;
76 static des_cblock data={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
77 des_cblock key;
78 unsigned char *p;
79 DES_LONG t;
80 int i;
81
82#ifdef MSDOS
83 pid=1;
84#else
85 if (!pid) pid=getpid();
86#endif
87 p=key;
88 if (seed)
89 {
90 for (i=0; i<8; i++)
91 {
92 data[i] ^= init[i];
93 init[i]=0;
94 }
95 seed=0;
96 }
97 t=(DES_LONG)time(NULL);
98 l2c(t,p);
99 t=(DES_LONG)((pid)|((c++)<<16));
100 l2c(t,p);
101
102 des_set_odd_parity(&data);
103 des_set_key(&data,ks);
104 des_cbc_cksum(key,&key,sizeof(key),ks,&data);
105
106 des_set_odd_parity(&key);
107 des_set_key(&key,ks);
108 des_cbc_cksum(key,&data,sizeof(key),ks,&key);
109
110 memcpy(ret,data,sizeof(key));
111 memset(key,0,sizeof(key));
112 memset(ks,0,sizeof(ks));
113 t=0;
114 } 69 }
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c
index fed49652c0..fa2d67da64 100644
--- a/src/lib/libcrypto/des/read_pwd.c
+++ b/src/lib/libcrypto/des/read_pwd.c
@@ -58,7 +58,11 @@
58 58
59#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) 59#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32)
60#include <openssl/opensslconf.h> 60#include <openssl/opensslconf.h>
61#include OPENSSL_UNISTD 61#ifdef OPENSSL_UNISTD
62# include OPENSSL_UNISTD
63#else
64# include <unistd.h>
65#endif
62/* If unistd.h defines _POSIX_VERSION, we conclude that we 66/* If unistd.h defines _POSIX_VERSION, we conclude that we
63 * are on a POSIX system and have sigaction and termios. */ 67 * are on a POSIX system and have sigaction and termios. */
64#if defined(_POSIX_VERSION) 68#if defined(_POSIX_VERSION)
@@ -123,7 +127,7 @@
123#undef SGTTY 127#undef SGTTY
124#endif 128#endif
125 129
126#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) 130#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) && !defined(MAC_OS_pre_X) && !defined(MAC_OS_GUSI_SOURCE)
127#undef TERMIOS 131#undef TERMIOS
128#undef TERMIO 132#undef TERMIO
129#define SGTTY 133#define SGTTY
@@ -153,7 +157,7 @@
153#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) 157#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
154#endif 158#endif
155 159
156#if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS) 160#if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS) && !defined(MAC_OS_pre_X)
157#include <sys/ioctl.h> 161#include <sys/ioctl.h>
158#endif 162#endif
159 163
@@ -174,6 +178,15 @@ struct IOSB {
174 }; 178 };
175#endif 179#endif
176 180
181#if defined(MAC_OS_pre_X) || defined(MAC_OS_GUSI_SOURCE)
182/*
183 * This one needs work. As a matter of fact the code is unoperational
184 * and this is only a trick to get it compiled.
185 * <appro@fy.chalmers.se>
186 */
187#define TTY_STRUCT int
188#endif
189
177#ifndef NX509_SIG 190#ifndef NX509_SIG
178#define NX509_SIG 32 191#define NX509_SIG 32
179#endif 192#endif
diff --git a/src/lib/libcrypto/des/rpc_enc.c b/src/lib/libcrypto/des/rpc_enc.c
index c96c204147..32d96d5cae 100644
--- a/src/lib/libcrypto/des/rpc_enc.c
+++ b/src/lib/libcrypto/des/rpc_enc.c
@@ -66,7 +66,7 @@ int _des_crypt(char *buf, int len, struct desparams *desp)
66 des_key_schedule ks; 66 des_key_schedule ks;
67 int enc; 67 int enc;
68 68
69 des_set_key(&desp->des_key,ks); 69 des_set_key_unchecked(&desp->des_key,ks);
70 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT; 70 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
71 71
72 if (desp->des_mode == CBC) 72 if (desp->des_mode == CBC)
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
index 52553a4c16..bbdc71ba6b 100644
--- a/src/lib/libcrypto/des/set_key.c
+++ b/src/lib/libcrypto/des/set_key.c
@@ -125,7 +125,7 @@ int des_is_weak_key(const_des_cblock *key)
125 int i; 125 int i;
126 126
127 for (i=0; i<NUM_WEAK_KEY; i++) 127 for (i=0; i<NUM_WEAK_KEY; i++)
128 /* Added == 0 to comparision, I obviously don't run 128 /* Added == 0 to comparison, I obviously don't run
129 * this section very often :-(, thanks to 129 * this section very often :-(, thanks to
130 * engineering@MorningStar.Com for the fix 130 * engineering@MorningStar.Com for the fix
131 * eay 93/06/29 131 * eay 93/06/29
@@ -145,11 +145,34 @@ int des_is_weak_key(const_des_cblock *key)
145#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ 145#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
146 (a)=(a)^(t)^(t>>(16-(n)))) 146 (a)=(a)^(t)^(t>>(16-(n))))
147 147
148int des_set_key(const_des_cblock *key, des_key_schedule schedule)
149 {
150 if (des_check_key)
151 {
152 return des_set_key_checked(key, schedule);
153 }
154 else
155 {
156 des_set_key_unchecked(key, schedule);
157 return 0;
158 }
159 }
160
148/* return 0 if key parity is odd (correct), 161/* return 0 if key parity is odd (correct),
149 * return -1 if key parity error, 162 * return -1 if key parity error,
150 * return -2 if illegal weak key. 163 * return -2 if illegal weak key.
151 */ 164 */
152int des_set_key(const_des_cblock *key, des_key_schedule schedule) 165int des_set_key_checked(const_des_cblock *key, des_key_schedule schedule)
166 {
167 if (!check_parity(key))
168 return(-1);
169 if (des_is_weak_key(key))
170 return(-2);
171 des_set_key_unchecked(key, schedule);
172 return 0;
173 }
174
175void des_set_key_unchecked(const_des_cblock *key, des_key_schedule schedule)
153 { 176 {
154 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; 177 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
155 register DES_LONG c,d,t,s,t2; 178 register DES_LONG c,d,t,s,t2;
@@ -157,15 +180,6 @@ int des_set_key(const_des_cblock *key, des_key_schedule schedule)
157 register DES_LONG *k; 180 register DES_LONG *k;
158 register int i; 181 register int i;
159 182
160 if (des_check_key)
161 {
162 if (!check_parity(key))
163 return(-1);
164
165 if (des_is_weak_key(key))
166 return(-2);
167 }
168
169 k = &schedule->ks.deslong[0]; 183 k = &schedule->ks.deslong[0];
170 in = &(*key)[0]; 184 in = &(*key)[0];
171 185
@@ -225,7 +239,6 @@ int des_set_key(const_des_cblock *key, des_key_schedule schedule)
225 t2=((s>>16L)|(t&0xffff0000L)); 239 t2=((s>>16L)|(t&0xffff0000L));
226 *(k++)=ROTATE(t2,26)&0xffffffffL; 240 *(k++)=ROTATE(t2,26)&0xffffffffL;
227 } 241 }
228 return(0);
229 } 242 }
230 243
231int des_key_sched(const_des_cblock *key, des_key_schedule schedule) 244int des_key_sched(const_des_cblock *key, des_key_schedule schedule)
diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c
index da41abcb03..814b86f4ae 100644
--- a/src/lib/libcrypto/des/speed.c
+++ b/src/lib/libcrypto/des/speed.c
@@ -186,16 +186,16 @@ int main(int argc, char **argv)
186#endif 186#endif
187 187
188#ifndef TIMES 188#ifndef TIMES
189 printf("To get the most acurate results, try to run this\n"); 189 printf("To get the most accurate results, try to run this\n");
190 printf("program when this computer is idle.\n"); 190 printf("program when this computer is idle.\n");
191#endif 191#endif
192 192
193 des_set_key(&key2,sch2); 193 des_set_key_unchecked(&key2,sch2);
194 des_set_key(&key3,sch3); 194 des_set_key_unchecked(&key3,sch3);
195 195
196#ifndef SIGALRM 196#ifndef SIGALRM
197 printf("First we calculate the approximate speed ...\n"); 197 printf("First we calculate the approximate speed ...\n");
198 des_set_key(&key,sch); 198 des_set_key_unchecked(&key,sch);
199 count=10; 199 count=10;
200 do { 200 do {
201 long i; 201 long i;
@@ -225,7 +225,7 @@ int main(int argc, char **argv)
225 225
226 Time_F(START); 226 Time_F(START);
227 for (count=0,run=1; COND(ca); count++) 227 for (count=0,run=1; COND(ca); count++)
228 des_set_key(&key,sch); 228 des_set_key_unchecked(&key,sch);
229 d=Time_F(STOP); 229 d=Time_F(STOP);
230 printf("%ld set_key's in %.2f seconds\n",count,d); 230 printf("%ld set_key's in %.2f seconds\n",count,d);
231 a=((double)COUNT(ca))/d; 231 a=((double)COUNT(ca))/d;
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
index 24841452f1..c6abb87201 100644
--- a/src/lib/libcrypto/des/str2key.c
+++ b/src/lib/libcrypto/des/str2key.c
@@ -58,8 +58,6 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61OPENSSL_EXTERN int des_check_key;
62
63void des_string_to_key(const char *str, des_cblock *key) 61void des_string_to_key(const char *str, des_cblock *key)
64 { 62 {
65 des_key_schedule ks; 63 des_key_schedule ks;
@@ -88,11 +86,8 @@ void des_string_to_key(const char *str, des_cblock *key)
88 } 86 }
89#endif 87#endif
90 des_set_odd_parity(key); 88 des_set_odd_parity(key);
91 i=des_check_key; 89 des_set_key_unchecked(key,ks);
92 des_check_key=0; 90 des_cbc_cksum((const unsigned char*)str,key,length,ks,key);
93 des_set_key(key,ks);
94 des_check_key=i;
95 des_cbc_cksum((unsigned char*)str,key,length,ks,key);
96 memset(ks,0,sizeof(ks)); 91 memset(ks,0,sizeof(ks));
97 des_set_odd_parity(key); 92 des_set_odd_parity(key);
98 } 93 }
@@ -150,13 +145,10 @@ void des_string_to_2keys(const char *str, des_cblock *key1, des_cblock *key2)
150#endif 145#endif
151 des_set_odd_parity(key1); 146 des_set_odd_parity(key1);
152 des_set_odd_parity(key2); 147 des_set_odd_parity(key2);
153 i=des_check_key; 148 des_set_key_unchecked(key1,ks);
154 des_check_key=0; 149 des_cbc_cksum((const unsigned char*)str,key1,length,ks,key1);
155 des_set_key(key1,ks); 150 des_set_key_unchecked(key2,ks);
156 des_cbc_cksum((unsigned char*)str,key1,length,ks,key1); 151 des_cbc_cksum((const unsigned char*)str,key2,length,ks,key2);
157 des_set_key(key2,ks);
158 des_cbc_cksum((unsigned char*)str,key2,length,ks,key2);
159 des_check_key=i;
160 memset(ks,0,sizeof(ks)); 152 memset(ks,0,sizeof(ks));
161 des_set_odd_parity(key1); 153 des_set_odd_parity(key1);
162 des_set_odd_parity(key2); 154 des_set_odd_parity(key2);
diff --git a/src/lib/libcrypto/dh/Makefile.ssl b/src/lib/libcrypto/dh/Makefile.ssl
index 3b5ec0e115..8df60872ef 100644
--- a/src/lib/libcrypto/dh/Makefile.ssl
+++ b/src/lib/libcrypto/dh/Makefile.ssl
@@ -83,26 +83,30 @@ dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
83dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h 83dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
84dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 84dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85dh_check.o: ../../include/openssl/opensslconf.h 85dh_check.o: ../../include/openssl/opensslconf.h
86dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 86dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
87dh_check.o: ../cryptlib.h 87dh_check.o: ../../include/openssl/stack.h ../cryptlib.h
88dh_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h 88dh_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
89dh_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 89dh_err.o: ../../include/openssl/dh.h ../../include/openssl/err.h
90dh_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
91dh_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
90dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 92dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
91dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 93dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
92dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h 94dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
93dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 95dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
94dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 96dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95dh_gen.o: ../../include/openssl/stack.h ../cryptlib.h 97dh_gen.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
98dh_gen.o: ../cryptlib.h
96dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 99dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
97dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 100dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
98dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h 101dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
99dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 102dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
100dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 103dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
101dh_key.o: ../../include/openssl/rand.h ../../include/openssl/stack.h 104dh_key.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
102dh_key.o: ../cryptlib.h 105dh_key.o: ../../include/openssl/stack.h ../cryptlib.h
103dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 106dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
104dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 107dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
105dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h 108dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
106dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 109dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
107dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 110dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
108dh_lib.o: ../../include/openssl/stack.h ../cryptlib.h 111dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
112dh_lib.o: ../cryptlib.h
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h
index 2cc3797a94..c15b2ad483 100644
--- a/src/lib/libcrypto/dh/dh.h
+++ b/src/lib/libcrypto/dh/dh.h
@@ -68,10 +68,28 @@ extern "C" {
68#endif 68#endif
69 69
70#include <openssl/bn.h> 70#include <openssl/bn.h>
71#include <openssl/crypto.h>
71 72
72#define DH_FLAG_CACHE_MONT_P 0x01 73#define DH_FLAG_CACHE_MONT_P 0x01
73 74
74typedef struct dh_st 75typedef struct dh_st DH;
76
77typedef struct dh_method {
78 const char *name;
79 /* Methods here */
80 int (*generate_key)(DH *dh);
81 int (*compute_key)(unsigned char *key,BIGNUM *pub_key,DH *dh);
82 int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
83 const BIGNUM *m, BN_CTX *ctx,
84 BN_MONT_CTX *m_ctx); /* Can be null */
85
86 int (*init)(DH *dh);
87 int (*finish)(DH *dh);
88 int flags;
89 char *app_data;
90} DH_METHOD;
91
92struct dh_st
75 { 93 {
76 /* This first argument is used to pick up errors when 94 /* This first argument is used to pick up errors when
77 * a DH is passed instead of a EVP_PKEY */ 95 * a DH is passed instead of a EVP_PKEY */
@@ -80,12 +98,22 @@ typedef struct dh_st
80 BIGNUM *p; 98 BIGNUM *p;
81 BIGNUM *g; 99 BIGNUM *g;
82 int length; /* optional */ 100 int length; /* optional */
83 BIGNUM *pub_key; /* y */ 101 BIGNUM *pub_key; /* g^x */
84 BIGNUM *priv_key; /* x */ 102 BIGNUM *priv_key; /* x */
85 103
86 int flags; 104 int flags;
87 char *method_mont_p; 105 char *method_mont_p;
88 } DH; 106 /* Place holders if we want to do X9.42 DH */
107 BIGNUM *q;
108 BIGNUM *j;
109 unsigned char *seed;
110 int seedlen;
111 BIGNUM *counter;
112
113 int references;
114 CRYPTO_EX_DATA ex_data;
115 DH_METHOD *meth;
116 };
89 117
90#define DH_GENERATOR_2 2 118#define DH_GENERATOR_2 2
91/* #define DH_GENERATOR_3 3 */ 119/* #define DH_GENERATOR_3 3 */
@@ -93,10 +121,14 @@ typedef struct dh_st
93 121
94/* DH_check error codes */ 122/* DH_check error codes */
95#define DH_CHECK_P_NOT_PRIME 0x01 123#define DH_CHECK_P_NOT_PRIME 0x01
96#define DH_CHECK_P_NOT_STRONG_PRIME 0x02 124#define DH_CHECK_P_NOT_SAFE_PRIME 0x02
97#define DH_UNABLE_TO_CHECK_GENERATOR 0x04 125#define DH_UNABLE_TO_CHECK_GENERATOR 0x04
98#define DH_NOT_SUITABLE_GENERATOR 0x08 126#define DH_NOT_SUITABLE_GENERATOR 0x08
99 127
128/* primes p where (p-1)/2 is prime too are called "safe"; we define
129 this for backward compatibility: */
130#define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME
131
100#define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \ 132#define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \
101 (char *(*)())d2i_DHparams,(char *)(x)) 133 (char *(*)())d2i_DHparams,(char *)(x))
102#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ 134#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \
@@ -113,9 +145,20 @@ typedef struct dh_st
113 (unsigned char *)(x)) 145 (unsigned char *)(x))
114#endif 146#endif
115 147
148DH_METHOD *DH_OpenSSL(void);
149
150void DH_set_default_method(DH_METHOD *meth);
151DH_METHOD *DH_get_default_method(void);
152DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
153DH *DH_new_method(DH_METHOD *meth);
154
116DH * DH_new(void); 155DH * DH_new(void);
117void DH_free(DH *dh); 156void DH_free(DH *dh);
118int DH_size(DH *dh); 157int DH_size(DH *dh);
158int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
159 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
160int DH_set_ex_data(DH *d, int idx, void *arg);
161void *DH_get_ex_data(DH *d, int idx);
119DH * DH_generate_parameters(int prime_len,int generator, 162DH * DH_generate_parameters(int prime_len,int generator,
120 void (*callback)(int,int,void *),void *cb_arg); 163 void (*callback)(int,int,void *),void *cb_arg);
121int DH_check(DH *dh,int *codes); 164int DH_check(DH *dh,int *codes);
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c
index 95ce9cfad0..7e5cfd8bfc 100644
--- a/src/lib/libcrypto/dh/dh_check.c
+++ b/src/lib/libcrypto/dh/dh_check.c
@@ -61,7 +61,7 @@
61#include <openssl/bn.h> 61#include <openssl/bn.h>
62#include <openssl/dh.h> 62#include <openssl/dh.h>
63 63
64/* Check that p is a strong prime and 64/* Check that p is a safe prime and
65 * if g is 2, 3 or 5, check that is is a suitable generator 65 * if g is 2, 3 or 5, check that is is a suitable generator
66 * where 66 * where
67 * for 2, p mod 24 == 11 67 * for 2, p mod 24 == 11
@@ -88,11 +88,13 @@ int DH_check(DH *dh, int *ret)
88 l=BN_mod_word(dh->p,24); 88 l=BN_mod_word(dh->p,24);
89 if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR; 89 if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;
90 } 90 }
91/* else if (BN_is_word(dh->g,DH_GENERATOR_3)) 91#if 0
92 else if (BN_is_word(dh->g,DH_GENERATOR_3))
92 { 93 {
93 l=BN_mod_word(dh->p,12); 94 l=BN_mod_word(dh->p,12);
94 if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR; 95 if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;
95 }*/ 96 }
97#endif
96 else if (BN_is_word(dh->g,DH_GENERATOR_5)) 98 else if (BN_is_word(dh->g,DH_GENERATOR_5))
97 { 99 {
98 l=BN_mod_word(dh->p,10); 100 l=BN_mod_word(dh->p,10);
@@ -108,7 +110,7 @@ int DH_check(DH *dh, int *ret)
108 { 110 {
109 if (!BN_rshift1(q,dh->p)) goto err; 111 if (!BN_rshift1(q,dh->p)) goto err;
110 if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL)) 112 if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))
111 *ret|=DH_CHECK_P_NOT_STRONG_PRIME; 113 *ret|=DH_CHECK_P_NOT_SAFE_PRIME;
112 } 114 }
113 ok=1; 115 ok=1;
114err: 116err:
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c
index b7bcd2c7a4..7a6a38fbb4 100644
--- a/src/lib/libcrypto/dh/dh_gen.c
+++ b/src/lib/libcrypto/dh/dh_gen.c
@@ -72,14 +72,14 @@
72 * Having said all that, 72 * Having said all that,
73 * there is another special case method for the generators 2, 3 and 5. 73 * there is another special case method for the generators 2, 3 and 5.
74 * for 2, p mod 24 == 11 74 * for 2, p mod 24 == 11
75 * for 3, p mod 12 == 5 <<<<< does not work for strong primes. 75 * for 3, p mod 12 == 5 <<<<< does not work for safe primes.
76 * for 5, p mod 10 == 3 or 7 76 * for 5, p mod 10 == 3 or 7
77 * 77 *
78 * Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the 78 * Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
79 * special generators and for answering some of my questions. 79 * special generators and for answering some of my questions.
80 * 80 *
81 * I've implemented the second simple method :-). 81 * I've implemented the second simple method :-).
82 * Since DH should be using a strong prime (both p and q are prime), 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. 83 * this generator function can take a very very long time to run.
84 */ 84 */
85 85
@@ -95,9 +95,10 @@ DH *DH_generate_parameters(int prime_len, int generator,
95 if (ret == NULL) goto err; 95 if (ret == NULL) goto err;
96 ctx=BN_CTX_new(); 96 ctx=BN_CTX_new();
97 if (ctx == NULL) goto err; 97 if (ctx == NULL) goto err;
98 t1= &(ctx->bn[0]); 98 BN_CTX_start(ctx);
99 t2= &(ctx->bn[1]); 99 t1 = BN_CTX_get(ctx);
100 ctx->tos=2; 100 t2 = BN_CTX_get(ctx);
101 if (t1 == NULL || t2 == NULL) goto err;
101 102
102 if (generator == DH_GENERATOR_2) 103 if (generator == DH_GENERATOR_2)
103 { 104 {
@@ -105,7 +106,7 @@ DH *DH_generate_parameters(int prime_len, int generator,
105 BN_set_word(t2,11); 106 BN_set_word(t2,11);
106 g=2; 107 g=2;
107 } 108 }
108#ifdef undef /* does not work for strong primes */ 109#ifdef undef /* does not work for safe primes */
109 else if (generator == DH_GENERATOR_3) 110 else if (generator == DH_GENERATOR_3)
110 { 111 {
111 BN_set_word(t1,12); 112 BN_set_word(t1,12);
@@ -138,7 +139,11 @@ err:
138 ok=0; 139 ok=0;
139 } 140 }
140 141
141 if (ctx != NULL) BN_CTX_free(ctx); 142 if (ctx != NULL)
143 {
144 BN_CTX_end(ctx);
145 BN_CTX_free(ctx);
146 }
142 if (!ok && (ret != NULL)) 147 if (!ok && (ret != NULL))
143 { 148 {
144 DH_free(ret); 149 DH_free(ret);
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
index cede53bfc1..0c7eeaf260 100644
--- a/src/lib/libcrypto/dh/dh_key.c
+++ b/src/lib/libcrypto/dh/dh_key.c
@@ -62,8 +62,42 @@
62#include <openssl/rand.h> 62#include <openssl/rand.h>
63#include <openssl/dh.h> 63#include <openssl/dh.h>
64 64
65static int generate_key(DH *dh);
66static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
67static int dh_bn_mod_exp(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
68 const BIGNUM *m, BN_CTX *ctx,
69 BN_MONT_CTX *m_ctx);
70static int dh_init(DH *dh);
71static int dh_finish(DH *dh);
72
65int DH_generate_key(DH *dh) 73int DH_generate_key(DH *dh)
66 { 74 {
75 return dh->meth->generate_key(dh);
76 }
77
78int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
79 {
80 return dh->meth->compute_key(key, pub_key, dh);
81 }
82
83static DH_METHOD dh_ossl = {
84"OpenSSL DH Method",
85generate_key,
86compute_key,
87dh_bn_mod_exp,
88dh_init,
89dh_finish,
900,
91NULL
92};
93
94DH_METHOD *DH_OpenSSL(void)
95{
96 return &dh_ossl;
97}
98
99static int generate_key(DH *dh)
100 {
67 int ok=0; 101 int ok=0;
68 unsigned int i; 102 unsigned int i;
69 BN_CTX ctx; 103 BN_CTX ctx;
@@ -103,7 +137,8 @@ int DH_generate_key(DH *dh)
103 } 137 }
104 mont=(BN_MONT_CTX *)dh->method_mont_p; 138 mont=(BN_MONT_CTX *)dh->method_mont_p;
105 139
106 if (!BN_mod_exp_mont(pub_key,dh->g,priv_key,dh->p,&ctx,mont)) goto err; 140 if (!dh->meth->bn_mod_exp(dh, pub_key,dh->g,priv_key,dh->p,&ctx,mont))
141 goto err;
107 142
108 dh->pub_key=pub_key; 143 dh->pub_key=pub_key;
109 dh->priv_key=priv_key; 144 dh->priv_key=priv_key;
@@ -118,7 +153,7 @@ err:
118 return(ok); 153 return(ok);
119 } 154 }
120 155
121int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh) 156static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
122 { 157 {
123 BN_CTX ctx; 158 BN_CTX ctx;
124 BN_MONT_CTX *mont; 159 BN_MONT_CTX *mont;
@@ -126,7 +161,8 @@ int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
126 int ret= -1; 161 int ret= -1;
127 162
128 BN_CTX_init(&ctx); 163 BN_CTX_init(&ctx);
129 tmp= &(ctx.bn[ctx.tos++]); 164 BN_CTX_start(&ctx);
165 tmp = BN_CTX_get(&ctx);
130 166
131 if (dh->priv_key == NULL) 167 if (dh->priv_key == NULL)
132 { 168 {
@@ -141,7 +177,7 @@ int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
141 } 177 }
142 178
143 mont=(BN_MONT_CTX *)dh->method_mont_p; 179 mont=(BN_MONT_CTX *)dh->method_mont_p;
144 if (!BN_mod_exp_mont(tmp,pub_key,dh->priv_key,dh->p,&ctx,mont)) 180 if (!dh->meth->bn_mod_exp(dh, tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
145 { 181 {
146 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB); 182 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
147 goto err; 183 goto err;
@@ -149,6 +185,27 @@ int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
149 185
150 ret=BN_bn2bin(tmp,key); 186 ret=BN_bn2bin(tmp,key);
151err: 187err:
188 BN_CTX_end(&ctx);
152 BN_CTX_free(&ctx); 189 BN_CTX_free(&ctx);
153 return(ret); 190 return(ret);
154 } 191 }
192
193static int dh_bn_mod_exp(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
194 const BIGNUM *m, BN_CTX *ctx,
195 BN_MONT_CTX *m_ctx)
196{
197 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
198}
199
200static int dh_init(DH *dh)
201{
202 dh->flags |= DH_FLAG_CACHE_MONT_P;
203 return(1);
204}
205
206static int dh_finish(DH *dh)
207{
208 if(dh->method_mont_p)
209 BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
210 return(1);
211}
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index 61e0720e8a..6c21463028 100644
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -63,16 +63,49 @@
63 63
64const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT; 64const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
65 65
66static DH_METHOD *default_DH_method;
67static int dh_meth_num = 0;
68static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dh_meth = NULL;
69
70void DH_set_default_method(DH_METHOD *meth)
71{
72 default_DH_method = meth;
73}
74
75DH_METHOD *DH_get_default_method(void)
76{
77 if(!default_DH_method) default_DH_method = DH_OpenSSL();
78 return default_DH_method;
79}
80
81DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth)
82{
83 DH_METHOD *mtmp;
84 mtmp = dh->meth;
85 if (mtmp->finish) mtmp->finish(dh);
86 dh->meth = meth;
87 if (meth->init) meth->init(dh);
88 return mtmp;
89}
90
66DH *DH_new(void) 91DH *DH_new(void)
92{
93 return DH_new_method(NULL);
94}
95
96DH *DH_new_method(DH_METHOD *meth)
67 { 97 {
68 DH *ret; 98 DH *ret;
69
70 ret=(DH *)Malloc(sizeof(DH)); 99 ret=(DH *)Malloc(sizeof(DH));
100
71 if (ret == NULL) 101 if (ret == NULL)
72 { 102 {
73 DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE); 103 DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE);
74 return(NULL); 104 return(NULL);
75 } 105 }
106 if(!default_DH_method) default_DH_method = DH_OpenSSL();
107 if(meth) ret->meth = meth;
108 else ret->meth = default_DH_method;
76 ret->pad=0; 109 ret->pad=0;
77 ret->version=0; 110 ret->version=0;
78 ret->p=NULL; 111 ret->p=NULL;
@@ -80,23 +113,74 @@ DH *DH_new(void)
80 ret->length=0; 113 ret->length=0;
81 ret->pub_key=NULL; 114 ret->pub_key=NULL;
82 ret->priv_key=NULL; 115 ret->priv_key=NULL;
83 ret->flags=DH_FLAG_CACHE_MONT_P; 116 ret->q=NULL;
117 ret->j=NULL;
118 ret->seed = NULL;
119 ret->seedlen = 0;
120 ret->counter = NULL;
84 ret->method_mont_p=NULL; 121 ret->method_mont_p=NULL;
122 ret->references = 1;
123 ret->flags=ret->meth->flags;
124 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
125 {
126 Free(ret);
127 ret=NULL;
128 }
129 else
130 CRYPTO_new_ex_data(dh_meth,ret,&ret->ex_data);
85 return(ret); 131 return(ret);
86 } 132 }
87 133
88void DH_free(DH *r) 134void DH_free(DH *r)
89 { 135 {
136 int i;
90 if(r == NULL) return; 137 if(r == NULL) return;
138 i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
139#ifdef REF_PRINT
140 REF_PRINT("DH",r);
141#endif
142 if (i > 0) return;
143#ifdef REF_CHECK
144 if (i < 0)
145 {
146 fprintf(stderr,"DH_free, bad reference count\n");
147 abort();
148 }
149#endif
150
151 CRYPTO_free_ex_data(dh_meth, r, &r->ex_data);
152
153 if(r->meth->finish) r->meth->finish(r);
154
91 if (r->p != NULL) BN_clear_free(r->p); 155 if (r->p != NULL) BN_clear_free(r->p);
92 if (r->g != NULL) BN_clear_free(r->g); 156 if (r->g != NULL) BN_clear_free(r->g);
157 if (r->q != NULL) BN_clear_free(r->q);
158 if (r->j != NULL) BN_clear_free(r->j);
159 if (r->seed) Free(r->seed);
160 if (r->counter != NULL) BN_clear_free(r->counter);
93 if (r->pub_key != NULL) BN_clear_free(r->pub_key); 161 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
94 if (r->priv_key != NULL) BN_clear_free(r->priv_key); 162 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
95 if (r->method_mont_p != NULL)
96 BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p);
97 Free(r); 163 Free(r);
98 } 164 }
99 165
166int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
167 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
168 {
169 dh_meth_num++;
170 return(CRYPTO_get_ex_new_index(dh_meth_num-1,
171 &dh_meth,argl,argp,new_func,dup_func,free_func));
172 }
173
174int DH_set_ex_data(DH *d, int idx, void *arg)
175 {
176 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
177 }
178
179void *DH_get_ex_data(DH *d, int idx)
180 {
181 return(CRYPTO_get_ex_data(&d->ex_data,idx));
182 }
183
100int DH_size(DH *dh) 184int DH_size(DH *dh)
101 { 185 {
102 return(BN_num_bytes(dh->p)); 186 return(BN_num_bytes(dh->p));
diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c
index 770331971f..d66c28455e 100644
--- a/src/lib/libcrypto/dh/dhtest.c
+++ b/src/lib/libcrypto/dh/dhtest.c
@@ -65,6 +65,7 @@
65#include <openssl/crypto.h> 65#include <openssl/crypto.h>
66#include <openssl/bio.h> 66#include <openssl/bio.h>
67#include <openssl/bn.h> 67#include <openssl/bn.h>
68#include <openssl/rand.h>
68 69
69#ifdef NO_DH 70#ifdef NO_DH
70int main(int argc, char *argv[]) 71int main(int argc, char *argv[])
@@ -87,19 +88,23 @@ static void MS_CALLBACK cb(int p, int n, void *arg);
87#include "bss_file.c" 88#include "bss_file.c"
88#endif 89#endif
89 90
90BIO *out=NULL; 91static const char rnd_seed[] = "string to make the random number generator think it has entropy";
91 92
92int main(int argc, char *argv[]) 93int main(int argc, char *argv[])
93 { 94 {
94 DH *a,*b; 95 DH *a;
96 DH *b=NULL;
95 char buf[12]; 97 char buf[12];
96 unsigned char *abuf=NULL,*bbuf=NULL; 98 unsigned char *abuf=NULL,*bbuf=NULL;
97 int i,alen,blen,aout,bout,ret=1; 99 int i,alen,blen,aout,bout,ret=1;
100 BIO *out;
98 101
99#ifdef WIN32 102#ifdef WIN32
100 CRYPTO_malloc_init(); 103 CRYPTO_malloc_init();
101#endif 104#endif
102 105
106 RAND_seed(rnd_seed, sizeof rnd_seed);
107
103 out=BIO_new(BIO_s_file()); 108 out=BIO_new(BIO_s_file());
104 if (out == NULL) exit(1); 109 if (out == NULL) exit(1);
105 BIO_set_fp(out,stdout,BIO_NOCLOSE); 110 BIO_set_fp(out,stdout,BIO_NOCLOSE);
@@ -167,6 +172,9 @@ int main(int argc, char *argv[])
167err: 172err:
168 if (abuf != NULL) Free(abuf); 173 if (abuf != NULL) Free(abuf);
169 if (bbuf != NULL) Free(bbuf); 174 if (bbuf != NULL) Free(bbuf);
175 if(b != NULL) DH_free(b);
176 if(a != NULL) DH_free(a);
177 BIO_free(out);
170 exit(ret); 178 exit(ret);
171 return(ret); 179 return(ret);
172 } 180 }
diff --git a/src/lib/libcrypto/doc/DH_generate_key.pod b/src/lib/libcrypto/doc/DH_generate_key.pod
new file mode 100644
index 0000000000..920995b2e5
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_generate_key.pod
@@ -0,0 +1,50 @@
1=pod
2
3=head1 NAME
4
5DH_generate_key, DH_compute_key - perform Diffie-Hellman key exchange
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_generate_key(DH *dh);
12
13 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
14
15=head1 DESCRIPTION
16
17DH_generate_key() performs the first step of a Diffie-Hellman key
18exchange by generating private and public DH values. By calling
19DH_compute_key(), these are combined with the other party's public
20value to compute the shared key.
21
22DH_generate_key() expects B<dh> to contain the shared parameters
23B<dh-E<gt>p> and B<dh-E<gt>g>. It generates a random private DH value
24unless B<dh-E<gt>priv_key> is already set, and computes the
25corresponding public value B<dh-E<gt>pub_key>, which can then be
26published.
27
28DH_compute_key() computes the shared secret from the private DH value
29in B<dh> and the other party's public value in B<pub_key> and stores
30it in B<key>. B<key> must point to B<DH_size(dh)> bytes of memory.
31
32=head1 RETURN VALUES
33
34DH_generate_key() returns 1 on success, 0 otherwise.
35
36DH_compute_key() returns the size of the shared secret on success, -1
37on error.
38
39The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
40
41=head1 SEE ALSO
42
43L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DH_size(3)|DH_size(3)>
44
45=head1 HISTORY
46
47DH_generate_key() and DH_compute_key() are available in all versions
48of SSLeay and OpenSSL.
49
50=cut
diff --git a/src/lib/libcrypto/doc/DH_generate_parameters.pod b/src/lib/libcrypto/doc/DH_generate_parameters.pod
new file mode 100644
index 0000000000..a7d0c75f0c
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_generate_parameters.pod
@@ -0,0 +1,72 @@
1=pod
2
3=head1 NAME
4
5DH_generate_parameters, DH_check - generate and check Diffie-Hellman parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH *DH_generate_parameters(int prime_len, int generator,
12 void (*callback)(int, int, void *), void *cb_arg);
13
14 int DH_check(DH *dh, int *codes);
15
16=head1 DESCRIPTION
17
18DH_generate_parameters() generates Diffie-Hellman parameters that can
19be shared among a group of users, and returns them in a newly
20allocated B<DH> structure. The pseudo-random number generator must be
21seeded prior to calling DH_generate_parameters().
22
23B<prime_len> is the length in bits of the safe prime to be generated.
24B<generator> is a small number E<gt> 1, typically 2 or 5.
25
26A callback function may be used to provide feedback about the progress
27of the key generation. If B<callback> is not B<NULL>, it will be
28called as described in L<BN_generate_prime(3)|BN_generate_prime(3)> while a random prime
29number is generated, and when a prime has been found, B<callback(3,
300, cb_arg)> is called.
31
32DH_check() validates Diffie-Hellman parameters. It checks that B<p> is
33a safe prime, and that B<g> is a suitable generator. In the case of an
34error, the bit flags DH_CHECK_P_NOT_SAFE_PRIME or
35DH_NOT_SUITABLE_GENERATOR are set in B<*codes>.
36DH_UNABLE_TO_CHECK_GENERATOR is set if the generator cannot be
37checked, i.e. it does not equal 2 or 5.
38
39=head1 RETURN VALUES
40
41DH_generate_parameters() returns a pointer to the DH structure, or
42NULL if the parameter generation fails. The error codes can be
43obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
44
45DH_check() returns 1 if the check could be performed, 0 otherwise.
46
47=head1 NOTES
48
49DH_generate_parameters() may run for several hours before finding a
50suitable prime.
51
52The parameters generated by DH_generate_parameters() are not to be
53used in signature schemes.
54
55=head1 BUGS
56
57If B<generator> is not 2 or 5, B<dh-E<gt>g>=B<generator> is not
58a usable generator.
59
60=head1 SEE ALSO
61
62L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DH_free(3)|DH_free(3)>
63
64=head1 HISTORY
65
66DH_check() is available in all versions of SSLeay and OpenSSL.
67The B<cb_arg> argument to DH_generate_parameters() was added in SSLeay 0.9.0.
68
69In versions before OpenSSL 0.9.5, DH_CHECK_P_NOT_STRONG_PRIME is used
70instead of DH_CHECK_P_NOT_SAFE_PRIME.
71
72=cut
diff --git a/src/lib/libcrypto/doc/DH_get_ex_new_index.pod b/src/lib/libcrypto/doc/DH_get_ex_new_index.pod
new file mode 100644
index 0000000000..82e2548bcd
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_get_ex_new_index.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DH_get_ex_new_index, DH_set_ex_data, DH_get_ex_data - add application specific data to DH structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int DH_set_ex_data(DH *d, int idx, void *arg);
17
18 char *DH_get_ex_data(DH *d, int idx);
19
20=head1 DESCRIPTION
21
22These functions handle application specific data in DH
23structures. Their usage is identical to that of
24RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
25as described in L<RSA_get_ex_new_index(3)>.
26
27=head1 SEE ALSO
28
29L<RSA_get_ex_new_index()|RSA_get_ex_new_index()>, L<dh(3)|dh(3)>
30
31=head1 HISTORY
32
33DH_get_ex_new_index(), DH_set_ex_data() and DH_get_ex_data() are
34available since OpenSSL 0.9.5.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DH_new.pod b/src/lib/libcrypto/doc/DH_new.pod
new file mode 100644
index 0000000000..64624b9d15
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_new.pod
@@ -0,0 +1,40 @@
1=pod
2
3=head1 NAME
4
5DH_new, DH_free - allocate and free DH objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH* DH_new(void);
12
13 void DH_free(DH *dh);
14
15=head1 DESCRIPTION
16
17DH_new() allocates and initializes a B<DH> structure.
18
19DH_free() frees the B<DH> structure and its components. The values are
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DH_new() returns B<NULL> and sets an error
25code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
26a pointer to the newly allocated structure.
27
28DH_free() returns no value.
29
30=head1 SEE ALSO
31
32L<dh(3)|dh(3)>, L<err(3)|err(3)>,
33L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
34L<DH_generate_key(3)|DH_generate_key(3)>
35
36=head1 HISTORY
37
38DH_new() and DH_free() are available in all versions of SSLeay and OpenSSL.
39
40=cut
diff --git a/src/lib/libcrypto/doc/DH_set_method.pod b/src/lib/libcrypto/doc/DH_set_method.pod
new file mode 100644
index 0000000000..dca41d8dbc
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_set_method.pod
@@ -0,0 +1,99 @@
1=pod
2
3=head1 NAME
4
5DH_set_default_method, DH_get_default_method, DH_set_method,
6DH_new_method, DH_OpenSSL - select DH method
7
8=head1 SYNOPSIS
9
10 #include <openssl/dh.h>
11
12 void DH_set_default_method(DH_METHOD *meth);
13
14 DH_METHOD *DH_get_default_method(void);
15
16 DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
17
18 DH *DH_new_method(DH_METHOD *meth);
19
20 DH_METHOD *DH_OpenSSL(void);
21
22=head1 DESCRIPTION
23
24A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman
25operations. By modifying the method, alternative implementations
26such as hardware accelerators may be used.
27
28Initially, the default is to use the OpenSSL internal implementation.
29DH_OpenSSL() returns a pointer to that method.
30
31DH_set_default_method() makes B<meth> the default method for all B<DH>
32structures created later.
33
34DH_get_default_method() returns a pointer to the current default
35method.
36
37DH_set_method() selects B<meth> for all operations using the structure B<dh>.
38
39DH_get_method() returns a pointer to the method currently selected
40for B<dh>.
41
42DH_new_method() allocates and initializes a B<DH> structure so that
43B<method> will be used for the DH operations. If B<method> is B<NULL>,
44the default method is used.
45
46=head1 THE DH_METHOD STRUCTURE
47
48 typedef struct dh_meth_st
49 {
50 /* name of the implementation */
51 const char *name;
52
53 /* generate private and public DH values for key agreement */
54 int (*generate_key)(DH *dh);
55
56 /* compute shared secret */
57 int (*compute_key)(unsigned char *key, BIGNUM *pub_key, DH *dh);
58
59 /* compute r = a ^ p mod m. May be NULL */
60 int (*bn_mod_exp)(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
61 const BIGNUM *m, BN_CTX *ctx,
62 BN_MONT_CTX *m_ctx);
63
64 /* called at DH_new */
65 int (*init)(DH *dh);
66
67 /* called at DH_free */
68 int (*finish)(DH *dh);
69
70 int flags;
71
72 char *app_data; /* ?? */
73
74 } DH_METHOD;
75
76=head1 RETURN VALUES
77
78DH_OpenSSL(), DH_get_default_method() and DH_get_method() return
79pointers to the respective B<DH_METHOD>s.
80
81DH_set_default_method() returns no value.
82
83DH_set_method() returns a pointer to the B<DH_METHOD> previously
84associated with B<dh>.
85
86DH_new_method() returns B<NULL> and sets an error code that can be
87obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
88returns a pointer to the newly allocated structure.
89
90=head1 SEE ALSO
91
92L<dh(3)|dh(3)>, L<DH_new(3)|DH_new(3)>
93
94=head1 HISTORY
95
96DH_set_default_method(), DH_get_default_method(), DH_set_method(),
97DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4.
98
99=cut
diff --git a/src/lib/libcrypto/doc/DH_size.pod b/src/lib/libcrypto/doc/DH_size.pod
new file mode 100644
index 0000000000..97f26fda78
--- /dev/null
+++ b/src/lib/libcrypto/doc/DH_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5DH_size - get Diffie-Hellman prime size
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 int DH_size(DH *dh);
12
13=head1 DESCRIPTION
14
15This function returns the Diffie-Hellman size in bytes. It can be used
16to determine how much memory must be allocated for the shared secret
17computed by DH_compute_key().
18
19B<dh-E<gt>p> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<dh(3)|dh(3)>, L<DH_generate_key(3)|DH_generate_key(3)>
28
29=head1 HISTORY
30
31DH_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/DSA_SIG_new.pod b/src/lib/libcrypto/doc/DSA_SIG_new.pod
new file mode 100644
index 0000000000..671655554a
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_SIG_new.pod
@@ -0,0 +1,39 @@
1=pod
2
3=head1 NAME
4
5DSA_SIG_new, DSA_SIG_free - allocate and free DSA signature objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA_SIG *DSA_SIG_new(void);
12
13 void DSA_SIG_free(DSA_SIG *a);
14
15=head1 DESCRIPTION
16
17DSA_SIG_new() allocates and initializes a B<DSA_SIG> structure.
18
19DSA_SIG_free() frees the B<DSA_SIG> structure and its components. The
20values are erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DSA_SIG_new() returns B<NULL> and sets an
25error code that can be obtained by
26L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
27to the newly allocated structure.
28
29DSA_SIG_free() returns no value.
30
31=head1 SEE ALSO
32
33L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<DSA_do_sign(3)|DSA_do_sign(3)>
34
35=head1 HISTORY
36
37DSA_SIG_new() and DSA_SIG_free() were added in OpenSSL 0.9.3.
38
39=cut
diff --git a/src/lib/libcrypto/doc/DSA_do_sign.pod b/src/lib/libcrypto/doc/DSA_do_sign.pod
new file mode 100644
index 0000000000..a24fd5714e
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_do_sign.pod
@@ -0,0 +1,47 @@
1=pod
2
3=head1 NAME
4
5DSA_do_sign, DSA_do_verify - raw DSA signature operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
12
13 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
14 DSA_SIG *sig, DSA *dsa);
15
16=head1 DESCRIPTION
17
18DSA_do_sign() computes a digital signature on the B<len> byte message
19digest B<dgst> using the private key B<dsa> and returns it in a
20newly allocated B<DSA_SIG> structure.
21
22L<DSA_sign_setup(3)|DSA_sign_setup(3)> may be used to precompute part
23of the signing operation in case signature generation is
24time-critical.
25
26DSA_do_verify() verifies that the signature B<sig> matches a given
27message digest B<dgst> of size B<len>. B<dsa> is the signer's public
28key.
29
30=head1 RETURN VALUES
31
32DSA_do_sign() returns the signature, NULL on error. DSA_do_verify()
33returns 1 for a valid signature, 0 for an incorrect signature and -1
34on error. The error codes can be obtained by
35L<ERR_get_error(3)|ERR_get_error(3)>.
36
37=head1 SEE ALSO
38
39L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
40L<DSA_SIG_new(3)|DSA_SIG_new(3)>,
41L<DSA_sign(3)|DSA_sign(3)>
42
43=head1 HISTORY
44
45DSA_do_sign() and DSA_do_verify() were added in OpenSSL 0.9.3.
46
47=cut
diff --git a/src/lib/libcrypto/doc/DSA_dup_DH.pod b/src/lib/libcrypto/doc/DSA_dup_DH.pod
new file mode 100644
index 0000000000..29cb1075d1
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_dup_DH.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DSA_dup_DH - create a DH structure out of DSA structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DH * DSA_dup_DH(DSA *r);
12
13=head1 DESCRIPTION
14
15DSA_dup_DH() duplicates DSA parameters/keys as DH parameters/keys. q
16is lost during that conversion, but the resulting DH parameters
17contain its length.
18
19=head1 RETURN VALUE
20
21DSA_dup_DH() returns the new B<DH> structure, and NULL on error. The
22error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
23
24=head1 NOTE
25
26Be careful to avoid small subgroup attacks when using this.
27
28=head1 SEE ALSO
29
30L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>
31
32=head1 HISTORY
33
34DSA_dup_DH() was added in OpenSSL 0.9.4.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DSA_generate_key.pod b/src/lib/libcrypto/doc/DSA_generate_key.pod
new file mode 100644
index 0000000000..52890db5be
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_generate_key.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5DSA_generate_key - generate DSA key pair
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_generate_key(DSA *a);
12
13=head1 DESCRIPTION
14
15DSA_generate_key() expects B<a> to contain DSA parameters. It generates
16a new key pair and stores it in B<a-E<gt>pub_key> and B<a-E<gt>priv_key>.
17
18The PRNG must be seeded prior to calling DSA_generate_key().
19
20=head1 RETURN VALUE
21
22DSA_generate_key() returns 1 on success, 0 otherwise.
23The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
24
25=head1 SEE ALSO
26
27L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>
28
29=head1 HISTORY
30
31DSA_generate_key() is available since SSLeay 0.8.
32
33=cut
diff --git a/src/lib/libcrypto/doc/DSA_generate_parameters.pod b/src/lib/libcrypto/doc/DSA_generate_parameters.pod
new file mode 100644
index 0000000000..43f60b0eb9
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_generate_parameters.pod
@@ -0,0 +1,105 @@
1=pod
2
3=head1 NAME
4
5DSA_generate_parameters - generate DSA parameters
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA *DSA_generate_parameters(int bits, unsigned char *seed,
12 int seed_len, int *counter_ret, unsigned long *h_ret,
13 void (*callback)(int, int, void *), void *cb_arg);
14
15=head1 DESCRIPTION
16
17DSA_generate_parameters() generates primes p and q and a generator g
18for use in the DSA.
19
20B<bits> is the length of the prime to be generated; the DSS allows a
21maximum of 1024 bits.
22
23If B<seed> is B<NULL> or B<seed_len> E<lt> 20, the primes will be
24generated at random. Otherwise, the seed is used to generate
25them. If the given seed does not yield a prime q, a new random
26seed is chosen and placed at B<seed>.
27
28DSA_generate_parameters() places the iteration count in
29*B<counter_ret> and a counter used for finding a generator in
30*B<h_ret>, unless these are B<NULL>.
31
32A callback function may be used to provide feedback about the progress
33of the key generation. If B<callback> is not B<NULL>, it will be
34called as follows:
35
36=over 4
37
38=item *
39
40When a candidate for q is generated, B<callback(0, m++, cb_arg)> is called
41(m is 0 for the first candidate).
42
43=item *
44
45When a candidate for q has passed a test by trial division,
46B<callback(1, -1, cb_arg)> is called.
47While a candidate for q is tested by Miller-Rabin primality tests,
48B<callback(1, i, cb_arg)> is called in the outer loop
49(once for each witness that confirms that the candidate may be prime);
50i is the loop counter (starting at 0).
51
52=item *
53
54When a prime q has been found, B<callback(2, 0, cb_arg)> and
55B<callback(3, 0, cb_arg)> are called.
56
57=item *
58
59Before a candidate for p (other than the first) is generated and tested,
60B<callback(0, counter, cb_arg)> is called.
61
62=item *
63
64When a candidate for p has passed the test by trial division,
65B<callback(1, -1, cb_arg)> is called.
66While it is tested by the Miller-Rabin primality test,
67B<callback(1, i, cb_arg)> is called in the outer loop
68(once for each witness that confirms that the candidate may be prime).
69i is the loop counter (starting at 0).
70
71=item *
72
73When p has been found, B<callback(2, 1, cb_arg)> is called.
74
75=item *
76
77When the generator has been found, B<callback(3, 1, cb_arg)> is called.
78
79=back
80
81=head1 RETURN VALUE
82
83DSA_generate_parameters() returns a pointer to the DSA structure, or
84B<NULL> if the parameter generation fails. The error codes can be
85obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
86
87=head1 BUGS
88
89Seed lengths E<gt> 20 are not supported.
90
91=head1 SEE ALSO
92
93L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
94L<DSA_free(3)|DSA_free(3)>
95
96=head1 HISTORY
97
98DSA_generate_parameters() appeared in SSLeay 0.8. The B<cb_arg>
99argument was added in SSLeay 0.9.0.
100In versions up to OpenSSL 0.9.4, B<callback(1, ...)> was called
101in the inner loop of the Miller-Rabin test whenever it reached the
102squaring step (the parameters to B<callback> did not reveal how many
103witnesses had been tested); since OpenSSL 0.9.5, B<callback(1, ...)>
104is called as in BN_is_prime(3), i.e. once for each witness.
105=cut
diff --git a/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod b/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod
new file mode 100644
index 0000000000..4612e708ec
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_get_ex_new_index.pod
@@ -0,0 +1,36 @@
1=pod
2
3=head1 NAME
4
5DSA_get_ex_new_index, DSA_set_ex_data, DSA_get_ex_data - add application specific data to DSA structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/DSA.h>
10
11 int DSA_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int DSA_set_ex_data(DSA *d, int idx, void *arg);
17
18 char *DSA_get_ex_data(DSA *d, int idx);
19
20=head1 DESCRIPTION
21
22These functions handle application specific data in DSA
23structures. Their usage is identical to that of
24RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data()
25as described in L<RSA_get_ex_new_index(3)>.
26
27=head1 SEE ALSO
28
29L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>, L<dsa(3)|dsa(3)>
30
31=head1 HISTORY
32
33DSA_get_ex_new_index(), DSA_set_ex_data() and DSA_get_ex_data() are
34available since OpenSSL 0.9.5.
35
36=cut
diff --git a/src/lib/libcrypto/doc/DSA_new.pod b/src/lib/libcrypto/doc/DSA_new.pod
new file mode 100644
index 0000000000..7dde54445b
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_new.pod
@@ -0,0 +1,41 @@
1=pod
2
3=head1 NAME
4
5DSA_new, DSA_free - allocate and free DSA objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA* DSA_new(void);
12
13 void DSA_free(DSA *dsa);
14
15=head1 DESCRIPTION
16
17DSA_new() allocates and initializes a B<DSA> structure.
18
19DSA_free() frees the B<DSA> structure and its components. The values are
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, DSA_new() returns B<NULL> and sets an error
25code that can be obtained by
26L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns a pointer
27to the newly allocated structure.
28
29DSA_free() returns no value.
30
31=head1 SEE ALSO
32
33L<dsa(3)|dsa(3)>, L<err(3)|err(3)>,
34L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
35L<DSA_generate_key(3)|DSA_generate_key(3)>
36
37=head1 HISTORY
38
39DSA_new() and DSA_free() are available in all versions of SSLeay and OpenSSL.
40
41=cut
diff --git a/src/lib/libcrypto/doc/DSA_set_method.pod b/src/lib/libcrypto/doc/DSA_set_method.pod
new file mode 100644
index 0000000000..0b13ec9237
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_set_method.pod
@@ -0,0 +1,111 @@
1=pod
2
3=head1 NAME
4
5DSA_set_default_method, DSA_get_default_method, DSA_set_method,
6DSA_new_method, DSA_OpenSSL - select RSA method
7
8=head1 SYNOPSIS
9
10 #include <openssl/DSA.h>
11
12 void DSA_set_default_method(DSA_METHOD *meth);
13
14 DSA_METHOD *DSA_get_default_method(void);
15
16 DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth);
17
18 DSA *DSA_new_method(DSA_METHOD *meth);
19
20 DSA_METHOD *DSA_OpenSSL(void);
21
22=head1 DESCRIPTION
23
24A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA
25operations. By modifying the method, alternative implementations
26such as hardware accelerators may be used.
27
28Initially, the default is to use the OpenSSL internal implementation.
29DSA_OpenSSL() returns a pointer to that method.
30
31DSA_set_default_method() makes B<meth> the default method for all B<DSA>
32structures created later.
33
34DSA_get_default_method() returns a pointer to the current default
35method.
36
37DSA_set_method() selects B<meth> for all operations using the structure B<DSA>.
38
39DSA_get_method() returns a pointer to the method currently selected
40for B<DSA>.
41
42DSA_new_method() allocates and initializes a B<DSA> structure so that
43B<method> will be used for the DSA operations. If B<method> is B<NULL>,
44the default method is used.
45
46=head1 THE DSA_METHOD STRUCTURE
47
48struct
49 {
50 /* name of the implementation */
51 const char *name;
52
53 /* sign */
54 DSA_SIG *(*dsa_do_sign)(const unsigned char *dgst, int dlen,
55 DSA *dsa);
56
57 /* pre-compute k^-1 and r */
58 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
59 BIGNUM **rp);
60
61 /* verify */
62 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
63 DSA_SIG *sig, DSA *dsa);
64
65 /* compute rr = a1^p1 * a2^p2 mod m. May be NULL */
66 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
67 BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
68 BN_CTX *ctx, BN_MONT_CTX *in_mont);
69
70 /* compute r = a ^ p mod m. May be NULL */
71 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a,
72 const BIGNUM *p, const BIGNUM *m,
73 BN_CTX *ctx, BN_MONT_CTX *m_ctx);
74
75 /* called at DSA_new */
76 int (*init)(DSA *DSA);
77
78 /* called at DSA_free */
79 int (*finish)(DSA *DSA);
80
81 int flags;
82
83 char *app_data; /* ?? */
84
85 } DSA_METHOD;
86
87=head1 RETURN VALUES
88
89DSA_OpenSSL(), DSA_get_default_method() and DSA_get_method() return
90pointers to the respective B<DSA_METHOD>s.
91
92DSA_set_default_method() returns no value.
93
94DSA_set_method() returns a pointer to the B<DSA_METHOD> previously
95associated with B<dsa>.
96
97DSA_new_method() returns B<NULL> and sets an error code that can be
98obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation
99fails. Otherwise it returns a pointer to the newly allocated
100structure.
101
102=head1 SEE ALSO
103
104L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)>
105
106=head1 HISTORY
107
108DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(),
109DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4.
110
111=cut
diff --git a/src/lib/libcrypto/doc/DSA_sign.pod b/src/lib/libcrypto/doc/DSA_sign.pod
new file mode 100644
index 0000000000..f6e60a8ca3
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_sign.pod
@@ -0,0 +1,66 @@
1=pod
2
3=head1 NAME
4
5DSA_sign, DSA_sign_setup, DSA_verify - DSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_sign(int type, const unsigned char *dgst, int len,
12 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
13
14 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
15 BIGNUM **rp);
16
17 int DSA_verify(int type, const unsigned char *dgst, int len,
18 unsigned char *sigbuf, int siglen, DSA *dsa);
19
20=head1 DESCRIPTION
21
22DSA_sign() computes a digital signature on the B<len> byte message
23digest B<dgst> using the private key B<dsa> and places its ASN.1 DER
24encoding at B<sigret>. The length of the signature is places in
25*B<siglen>. B<sigret> must point to DSA_size(B<dsa>) bytes of memory.
26
27DSA_sign_setup() may be used to precompute part of the signing
28operation in case signature generation is time-critical. It expects
29B<dsa> to contain DSA parameters. It places the precomputed values
30in newly allocated B<BIGNUM>s at *B<kinvp> and *B<rp>, after freeing
31the old ones unless *B<kinvp> and *B<rp> are NULL. These values may
32be passed to DSA_sign() in B<dsa-E<gt>kinv> and B<dsa-E<gt>r>.
33B<ctx> is a pre-allocated B<BN_CTX> or NULL.
34
35DSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
36matches a given message digest B<dgst> of size B<len>.
37B<dsa> is the signer's public key.
38
39The B<type> parameter is ignored.
40
41The PRNG must be seeded before DSA_sign() (or DSA_sign_setup())
42is called.
43
44=head1 RETURN VALUES
45
46DSA_sign() and DSA_sign_setup() return 1 on success, 0 on error.
47DSA_verify() returns 1 for a valid signature, 0 for an incorrect
48signature and -1 on error. The error codes can be obtained by
49L<ERR_get_error(3)|ERR_get_error(3)>.
50
51=head1 CONFORMING TO
52
53US Federal Information Processing Standard FIPS 186 (Digital Signature
54Standard, DSS), ANSI X9.30
55
56=head1 SEE ALSO
57
58L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
59L<DSA_do_sign(3)|DSA_do_sign(3)>
60
61=head1 HISTORY
62
63DSA_sign() and DSA_verify() are available in all versions of SSLeay.
64DSA_sign_setup() was added in SSLeay 0.8.
65
66=cut
diff --git a/src/lib/libcrypto/doc/DSA_size.pod b/src/lib/libcrypto/doc/DSA_size.pod
new file mode 100644
index 0000000000..23b6320a4d
--- /dev/null
+++ b/src/lib/libcrypto/doc/DSA_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5DSA_size - get DSA signature size
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 int DSA_size(DSA *dsa);
12
13=head1 DESCRIPTION
14
15This function returns the size of an ASN.1 encoded DSA signature in
16bytes. It can be used to determine how much memory must be allocated
17for a DSA signature.
18
19B<dsa-E<gt>q> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<dsa(3)|dsa(3)>, L<DSA_sign(3)|DSA_sign(3)>
28
29=head1 HISTORY
30
31DSA_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/ERR_GET_LIB.pod b/src/lib/libcrypto/doc/ERR_GET_LIB.pod
new file mode 100644
index 0000000000..2a129da036
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_GET_LIB.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5ERR_GET_LIB, ERR_GET_FUNC, ERR_GET_REASON - get library, function and
6reason code
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 int ERR_GET_LIB(unsigned long e);
13
14 int ERR_GET_FUNC(unsigned long e);
15
16 int ERR_GET_REASON(unsigned long e);
17
18=head1 DESCRIPTION
19
20The error code returned by ERR_get_error() consists of a library
21number, function code and reason code. ERR_GET_LIB(), ERR_GET_FUNC()
22and ERR_GET_REASON() can be used to extract these.
23
24The library number and function code describe where the error
25occurred, the reason code is the information about what went wrong.
26
27Each sub-library of OpenSSL has a unique library number; function and
28reason codes are unique within each sub-library. Note that different
29libraries may use the same value to signal different functions and
30reasons.
31
32B<ERR_R_...> reason codes such as B<ERR_R_MALLOC_FAILURE> are globally
33unique. However, when checking for sub-library specific reason codes,
34be sure to also compare the library number.
35
36ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are macros.
37
38=head1 RETURN VALUES
39
40The library number, function code and reason code respectively.
41
42=head1 SEE ALSO
43
44L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
45
46=head1 HISTORY
47
48ERR_GET_LIB(), ERR_GET_FUNC() and ERR_GET_REASON() are available in
49all versions of SSLeay and OpenSSL.
50
51=cut
diff --git a/src/lib/libcrypto/doc/ERR_clear_error.pod b/src/lib/libcrypto/doc/ERR_clear_error.pod
new file mode 100644
index 0000000000..566e1f4e31
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_clear_error.pod
@@ -0,0 +1,29 @@
1=pod
2
3=head1 NAME
4
5ERR_clear_error - clear the error queue
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_clear_error(void);
12
13=head1 DESCRIPTION
14
15ERR_clear_error() empties the current thread's error queue.
16
17=head1 RETURN VALUES
18
19ERR_clear_error() has no return value.
20
21=head1 SEE ALSO
22
23L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
24
25=head1 HISTORY
26
27ERR_clear_error() is available in all versions of SSLeay and OpenSSL.
28
29=cut
diff --git a/src/lib/libcrypto/doc/ERR_error_string.pod b/src/lib/libcrypto/doc/ERR_error_string.pod
new file mode 100644
index 0000000000..0d2417599c
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_error_string.pod
@@ -0,0 +1,65 @@
1=pod
2
3=head1 NAME
4
5ERR_error_string - obtain human-readable error message
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 char *ERR_error_string(unsigned long e, char *buf);
12
13 const char *ERR_lib_error_string(unsigned long e);
14 const char *ERR_func_error_string(unsigned long e);
15 const char *ERR_reason_error_string(unsigned long e);
16
17=head1 DESCRIPTION
18
19ERR_error_string() generates a human-readable string representing the
20error code B<e>, and places it at B<buf>. B<buf> must be at least 120
21bytes long. If B<buf> is B<NULL>, the error string is placed in a
22static buffer.
23
24The string will have the following format:
25
26 error:[error code]:[library name]:[function name]:[reason string]
27
28I<error code> is an 8 digit hexadecimal number, I<library name>,
29I<function name> and I<reason string> are ASCII text.
30
31ERR_lib_error_string(), ERR_func_error_string() and
32ERR_reason_error_string() return the library name, function
33name and reason string respectively.
34
35The OpenSSL error strings should be loaded by calling
36L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)> or, for SSL
37applications, L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
38first.
39If there is no text string registered for the given error code,
40the error string will contain the numeric code.
41
42L<ERR_print_errors(3)|ERR_print_errors(3)> can be used to print
43all error codes currently in the queue.
44
45=head1 RETURN VALUES
46
47ERR_error_string() returns a pointer to a static buffer containing the
48string if B<buf == NULL>, B<buf> otherwise.
49
50ERR_lib_error_string(), ERR_func_error_string() and
51ERR_reason_error_string() return the strings, and B<NULL> if
52none is registered for the error code.
53
54=head1 SEE ALSO
55
56L<err(3)|err(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
57L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
58L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
59L<ERR_print_errors(3)|ERR_print_errors(3)>
60
61=head1 HISTORY
62
63ERR_error_string() is available in all versions of SSLeay and OpenSSL.
64
65=cut
diff --git a/src/lib/libcrypto/doc/ERR_get_error.pod b/src/lib/libcrypto/doc/ERR_get_error.pod
new file mode 100644
index 0000000000..75ece00d97
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_get_error.pod
@@ -0,0 +1,62 @@
1=pod
2
3=head1 NAME
4
5ERR_get_error, ERR_peek_error - obtain error code
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 unsigned long ERR_get_error(void);
12 unsigned long ERR_peek_error(void);
13
14 unsigned long ERR_get_error_line(const char **file, int *line);
15 unsigned long ERR_peek_error_line(const char **file, int *line);
16
17 unsigned long ERR_get_error_line_data(const char **file, int *line,
18 const char **data, int *flags);
19 unsigned long ERR_peek_error_line_data(const char **file, int *line,
20 const char **data, int *flags);
21
22=head1 DESCRIPTION
23
24ERR_get_error() returns the last error code from the thread's error
25queue and removes the entry. This function can be called repeatedly
26until there are no more error codes to return.
27
28ERR_peek_error() returns the last error code from the thread's
29error queue without modifying it.
30
31See L<ERR_GET_LIB(3)|ERR_GET_LIB(3)> for obtaining information about
32location and reason of the error, and
33L<ERR_error_string(3)|ERR_error_string(3)> for human-readable error
34messages.
35
36ERR_get_error_line() and ERR_peek_error_line() are the same as the
37above, but they additionally store the file name and line number where
38the error occurred in *B<file> and *B<line>, unless these are B<NULL>.
39
40ERR_get_error_line_data() and ERR_peek_error_line_data() store
41additional data and flags associated with the error code in *B<data>
42and *B<flags>, unless these are B<NULL>. *B<data> contains a string
43if *B<flags>&B<ERR_TXT_STRING>. If it has been allocated by Malloc(),
44*B<flags>&B<ERR_TXT_MALLOCED> is true.
45
46=head1 RETURN VALUES
47
48The error code, or 0 if there is no error in the queue.
49
50=head1 SEE ALSO
51
52L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
53L<ERR_GET_LIB(3)|ERR_GET_LIB(3)>
54
55=head1 HISTORY
56
57ERR_get_error(), ERR_peek_error(), ERR_get_error_line() and
58ERR_peek_error_line() are available in all versions of SSLeay and
59OpenSSL. ERR_get_error_line_data() and ERR_peek_error_line_data()
60were added in SSLeay 0.9.0.
61
62=cut
diff --git a/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod b/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod
new file mode 100644
index 0000000000..9bdec75a46
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_load_crypto_strings.pod
@@ -0,0 +1,46 @@
1=pod
2
3=head1 NAME
4
5ERR_load_crypto_strings, SSL_load_error_strings, ERR_free_strings -
6load and free error strings
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 void ERR_load_crypto_strings(void);
13 void ERR_free_strings(void);
14
15 #include <openssl/ssl.h>
16
17 void SSL_load_error_strings(void);
18
19=head1 DESCRIPTION
20
21ERR_load_crypto_strings() registers the error strings for all
22B<libcrypto> functions. SSL_load_error_strings() does the same,
23but also registers the B<libssl> error strings.
24
25One of these functions should be called before generating
26textual error messages. However, this is not required when memory
27usage is an issue.
28
29ERR_free_strings() frees all previously loaded error strings.
30
31=head1 RETURN VALUES
32
33ERR_load_crypto_strings(), SSL_load_error_strings() and
34ERR_free_strings() return no values.
35
36=head1 SEE ALSO
37
38L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>
39
40=head1 HISTORY
41
42ERR_load_error_strings(), SSL_load_error_strings() and
43ERR_free_strings() are available in all versions of SSLeay and
44OpenSSL.
45
46=cut
diff --git a/src/lib/libcrypto/doc/ERR_load_strings.pod b/src/lib/libcrypto/doc/ERR_load_strings.pod
new file mode 100644
index 0000000000..5acdd0edbc
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_load_strings.pod
@@ -0,0 +1,54 @@
1=pod
2
3=head1 NAME
4
5ERR_load_strings, ERR_PACK, ERR_get_next_error_library - load
6arbitrary error strings
7
8=head1 SYNOPSIS
9
10 #include <openssl/err.h>
11
12 void ERR_load_strings(int lib, ERR_STRING_DATA str[]);
13
14 int ERR_get_next_error_library(void);
15
16 unsigned long ERR_PACK(int lib, int func, int reason);
17
18=head1 DESCRIPTION
19
20ERR_load_strings() registers error strings for library number B<lib>.
21
22B<str> is an array of error string data:
23
24 typedef struct ERR_string_data_st
25 {
26 unsigned long error;
27 char *string;
28 } ERR_STRING_DATA;
29
30The error code is generated from the library number and a function and
31reason code: B<error> = ERR_PACK(B<lib>, B<func>, B<reason>).
32ERR_PACK() is a macro.
33
34The last entry in the array is {0,0}.
35
36ERR_get_next_error_library() can be used to assign library numbers
37to user libraries at runtime.
38
39=head1 RETURN VALUE
40
41ERR_load_strings() returns no value. ERR_PACK() return the error code.
42ERR_get_next_error_library() returns a new library number.
43
44=head1 SEE ALSO
45
46L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
47
48=head1 HISTORY
49
50ERR_load_error_strings() and ERR_PACK() are available in all versions
51of SSLeay and OpenSSL. ERR_get_next_error_library() was added in
52SSLeay 0.9.0.
53
54=cut
diff --git a/src/lib/libcrypto/doc/ERR_print_errors.pod b/src/lib/libcrypto/doc/ERR_print_errors.pod
new file mode 100644
index 0000000000..b100a5fa2b
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_print_errors.pod
@@ -0,0 +1,51 @@
1=pod
2
3=head1 NAME
4
5ERR_print_errors, ERR_print_errors_fp - print error messages
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_print_errors(BIO *bp);
12 void ERR_print_errors_fp(FILE *fp);
13
14=head1 DESCRIPTION
15
16ERR_print_errors() is a convenience function that prints the error
17strings for all errors that OpenSSL has recorded to B<bp>, thus
18emptying the error queue.
19
20ERR_print_errors_fp() is the same, except that the output goes to a
21B<FILE>.
22
23
24The error strings will have the following format:
25
26 [pid]:error:[error code]:[library name]:[function name]:[reason string]:[file name]:[line]:[optional text message]
27
28I<error code> is an 8 digit hexadecimal number. I<library name>,
29I<function name> and I<reason string> are ASCII text, as is I<optional
30text message> if one was set for the respective error code.
31
32If there is no text string registered for the given error code,
33the error string will contain the numeric code.
34
35=head1 RETURN VALUES
36
37ERR_print_errors() and ERR_print_errors_fp() return no values.
38
39=head1 SEE ALSO
40
41L<err(3)|err(3)>, L<ERR_error_string(3)|ERR_error_string(3)>,
42L<ERR_get_error(3)|ERR_get_error(3)>,
43L<ERR_load_crypto_strings(3)|ERR_load_crypto_strings(3)>,
44L<SSL_load_error_strings(3)|SSL_load_error_strings(3)>
45
46=head1 HISTORY
47
48ERR_print_errors() and ERR_print_errors_fp()
49are available in all versions of SSLeay and OpenSSL.
50
51=cut
diff --git a/src/lib/libcrypto/doc/ERR_put_error.pod b/src/lib/libcrypto/doc/ERR_put_error.pod
new file mode 100644
index 0000000000..acd241fbe4
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_put_error.pod
@@ -0,0 +1,44 @@
1=pod
2
3=head1 NAME
4
5ERR_put_error, ERR_add_error_data - record an error
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_put_error(int lib, int func, int reason, const char *file,
12 int line);
13
14 void ERR_add_error_data(int num, ...);
15
16=head1 DESCRIPTION
17
18ERR_put_error() adds an error code to the thread's error queue. It
19signals that the error of reason code B<reason> occurred in function
20B<func> of library B<lib>, in line number B<line> of B<file>.
21This function is usually called by a macro.
22
23ERR_add_error_data() associates the concatenation of its B<num> string
24arguments with the error code added last.
25
26L<ERR_load_strings(3)|ERR_load_strings(3)> can be used to register
27error strings so that the application can a generate human-readable
28error messages for the error code.
29
30=head1 RETURN VALUES
31
32ERR_put_error() and ERR_add_error_data() return
33no values.
34
35=head1 SEE ALSO
36
37L<err(3)|err(3)>, L<ERR_load_strings(3)|ERR_load_strings(3)>
38
39=head1 HISTORY
40
41ERR_put_error() is available in all versions of SSLeay and OpenSSL.
42ERR_add_error_data() was added in SSLeay 0.9.0.
43
44=cut
diff --git a/src/lib/libcrypto/doc/ERR_remove_state.pod b/src/lib/libcrypto/doc/ERR_remove_state.pod
new file mode 100644
index 0000000000..ebcdc0f5a5
--- /dev/null
+++ b/src/lib/libcrypto/doc/ERR_remove_state.pod
@@ -0,0 +1,34 @@
1=pod
2
3=head1 NAME
4
5ERR_remove_state - free a thread's error queue
6
7=head1 SYNOPSIS
8
9 #include <openssl/err.h>
10
11 void ERR_remove_state(unsigned long pid);
12
13=head1 DESCRIPTION
14
15ERR_remove_state() frees the error queue associated with thread B<pid>.
16If B<pid> == 0, the current thread will have its error queue removed.
17
18Since error queue data structures are allocated automatically for new
19threads, they must be freed when threads are terminated in oder to
20avoid memory leaks.
21
22=head1 RETURN VALUE
23
24ERR_remove_state() returns no value.
25
26=head1 SEE ALSO
27
28L<err(3)|err(3)>
29
30=head1 HISTORY
31
32ERR_remove_state() is available in all versions of SSLeay and OpenSSL.
33
34=cut
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod
new file mode 100644
index 0000000000..345b1ddfa7
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_DigestInit.pod
@@ -0,0 +1,197 @@
1=pod
2
3=head1 NAME
4
5EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal - EVP digest routines
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
12 void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
13 void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
14 unsigned int *s);
15
16 #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
17
18 int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
19
20 #define EVP_MD_type(e) ((e)->type)
21 #define EVP_MD_pkey_type(e) ((e)->pkey_type)
22 #define EVP_MD_size(e) ((e)->md_size)
23 #define EVP_MD_block_size(e) ((e)->block_size)
24
25 #define EVP_MD_CTX_md(e) (e)->digest)
26 #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
27 #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
28 #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
29
30 EVP_MD *EVP_md_null(void);
31 EVP_MD *EVP_md2(void);
32 EVP_MD *EVP_md5(void);
33 EVP_MD *EVP_sha(void);
34 EVP_MD *EVP_sha1(void);
35 EVP_MD *EVP_dss(void);
36 EVP_MD *EVP_dss1(void);
37 EVP_MD *EVP_mdc2(void);
38 EVP_MD *EVP_ripemd160(void);
39
40 const EVP_MD *EVP_get_digestbyname(const char *name);
41 #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
42 #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
43
44=head1 DESCRIPTION
45
46The EVP digest routines are a high level interface to message digests.
47
48EVP_DigestInit() initialises a digest context B<ctx> to use a digest
49B<type>: this will typically be supplied by a function such as
50EVP_sha1().
51
52EVP_DigestUpdate() hashes B<cnt> bytes of data at B<d> into the
53digest context B<ctx>. This funtion can be called several times on the
54same B<ctx> to hash additional data.
55
56EVP_DigestFinal() retrieves the digest value from B<ctx> and places
57it in B<md>. If the B<s> parameter is not NULL then the number of
58bytes of data written (i.e. the length of the digest) will be written
59to the integer at B<s>, at most B<EVP_MAX_MD_SIZE> bytes will be written.
60After calling EVP_DigestFinal() no additional calls to EVP_DigestUpdate()
61can be made, but EVP_DigestInit() can be called to initialiase a new
62digest operation.
63
64EVP_MD_CTX_copy() can be used to copy the message digest state from
65B<in> to B<out>. This is useful if large amounts of data are to be
66hashed which only differ in the last few bytes.
67
68EVP_MD_size() and EVP_MD_CTX_size() return the size of the message digest
69when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure, i.e. the size of the
70hash.
71
72EVP_MD_block_size() and EVP_MD_CTX_block_size() return the block size of the
73message digest when passed an B<EVP_MD> or an B<EVP_MD_CTX> structure.
74
75EVP_MD_type() and EVP_MD_CTX_type() return the NID of the OBJECT IDENTIFIER
76representing the given message digest when passed an B<EVP_MD> structure.
77For example EVP_MD_type(EVP_sha1()) returns B<NID_sha1>. This function is
78normally used when setting ASN1 OIDs.
79
80EVP_MD_CTX_md() returns the B<EVP_MD> structure corresponding to the passed
81B<EVP_MD_CTX>.
82
83EVP_MD_pkey_type() returns the NID of the public key signing algorithm associated
84with this digest. For example EVP_sha1() is associated with RSA so this will
85return B<NID_sha1WithRSAEncryption>. This "link" between digests and signature
86algorithms may not be retained in future versions of OpenSSL.
87
88EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_mdc2() and EVP_ripemd160()
89return B<EVP_MD> structures for the MD2, MD5, SHA, SHA1, MDC2 and RIPEMD160 digest
90algorithms respectively. The associated signature algorithm is RSA in each case.
91
92EVP_dss() and EVP_dss1() return B<EVP_MD> structures for SHA and SHA1 digest
93algorithms but using DSS (DSA) for the signature algorithm.
94
95EVP_md_null() is a "null" message digest that does nothing: i.e. the hash it
96returns is of zero length.
97
98EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
99return an B<EVP_MD> structure when passed a digest name, a digest NID or
100an ASN1_OBJECT structure respectively. The digest table must be initialised
101using, for example, OpenSSL_add_all_digests() for these functions to work.
102
103=head1 RETURN VALUES
104
105EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() do not return values.
106
107EVP_MD_CTX_copy() returns 1 if successful or 0 for failure.
108
109EVP_MD_type(), EVP_MD_pkey_type() and EVP_MD_type() return the NID of the
110corresponding OBJECT IDENTIFIER or NID_undef if none exists.
111
112EVP_MD_size(), EVP_MD_block_size(), EVP_MD_CTX_size(e), EVP_MD_size(),
113EVP_MD_CTX_block_size() and EVP_MD_block_size() return the digest or block
114size in bytes.
115
116EVP_md_null(), EVP_md2(), EVP_md5(), EVP_sha(), EVP_sha1(), EVP_dss(),
117EVP_dss1(), EVP_mdc2() and EVP_ripemd160() return pointers to the
118corresponding EVP_MD structures.
119
120EVP_get_digestbyname(), EVP_get_digestbynid() and EVP_get_digestbyobj()
121return either an B<EVP_MD> structure or NULL if an error occurs.
122
123=head1 NOTES
124
125The B<EVP> interface to message digests should almost always be used in
126preference to the low level interfaces. This is because the code then becomes
127transparent to the digest used and much more flexible.
128
129SHA1 is the digest of choice for new applications. The other digest algorithms
130are still in common use.
131
132=head1 EXAMPLE
133
134This example digests the data "Test Message\n" and "Hello World\n", using the
135digest name passed on the command line.
136
137 #include <stdio.h>
138 #include <openssl/evp.h>
139
140 main(int argc, char *argv[])
141 {
142 EVP_MD_CTX mdctx;
143 const EVP_MD *md;
144 char mess1[] = "Test Message\n";
145 char mess2[] = "Hello World\n";
146 unsigned char md_value[EVP_MAX_MD_SIZE];
147 int md_len, i;
148
149 OpenSSL_add_all_digests();
150
151 if(!argv[1]) {
152 printf("Usage: mdtest digestname\n");
153 exit(1);
154 }
155
156 md = EVP_get_digestbyname(argv[1]);
157
158 if(!md) {
159 printf("Unknown message digest %s\n", argv[1]);
160 exit(1);
161 }
162
163 EVP_DigestInit(&mdctx, md);
164 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
165 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
166 EVP_DigestFinal(&mdctx, md_value, &md_len);
167
168 printf("Digest is: ");
169 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
170 printf("\n");
171 }
172
173=head1 BUGS
174
175Several of the functions do not return values: maybe they should. Although the
176internal digest operations will never fail some future hardware based operations
177might.
178
179The link between digests and signing algorithms results in a situation where
180EVP_sha1() must be used with RSA and EVP_dss1() must be used with DSS
181even though they are identical digests.
182
183The size of an B<EVP_MD_CTX> structure is determined at compile time: this results
184in code that must be recompiled if the size of B<EVP_MD_CTX> increases.
185
186=head1 SEE ALSO
187
188L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
189L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
190L<sha(3)|sha(3)>, L<digest(1)|digest(1)>
191
192=head1 HISTORY
193
194EVP_DigestInit(), EVP_DigestUpdate() and EVP_DigestFinal() are
195available in all versions of SSLeay and OpenSSL.
196
197=cut
diff --git a/src/lib/libcrypto/doc/EVP_EncryptInit.pod b/src/lib/libcrypto/doc/EVP_EncryptInit.pod
new file mode 100644
index 0000000000..77ed4ccdba
--- /dev/null
+++ b/src/lib/libcrypto/doc/EVP_EncryptInit.pod
@@ -0,0 +1,224 @@
1=pod
2
3=head1 NAME
4
5EVP_EncryptInit, EVP_EncryptUpdate, EVP_EncryptFinal - EVP cipher routines
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
12 unsigned char *key, unsigned char *iv);
13 void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
14 int *outl, unsigned char *in, int inl);
15 void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
16 int *outl);
17
18 void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
19 unsigned char *key, unsigned char *iv);
20 void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
21 int *outl, unsigned char *in, int inl);
22 int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
23 int *outl);
24
25 void EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
26 unsigned char *key, unsigned char *iv, int enc);
27 void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
28 int *outl, unsigned char *in, int inl);
29 int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
30 int *outl);
31
32 void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
33
34 const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
35 #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
36 #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
37
38 #define EVP_CIPHER_nid(e) ((e)->nid)
39 #define EVP_CIPHER_block_size(e) ((e)->block_size)
40 #define EVP_CIPHER_key_length(e) ((e)->key_len)
41 #define EVP_CIPHER_iv_length(e) ((e)->iv_len)
42
43 int EVP_CIPHER_type(const EVP_CIPHER *ctx);
44 #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
45 #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
46 #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
47 #define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len)
48 #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
49 #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
50
51 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
52 int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
53
54=head1 DESCRIPTION
55
56The EVP cipher routines are a high level interface to certain
57symmetric ciphers.
58
59EVP_EncryptInit() initialises a cipher context B<ctx> for encryption
60with cipher B<type>. B<type> is normally supplied by a function such
61as EVP_des_cbc() . B<key> is the symmetric key to use and B<iv> is the
62IV to use (if necessary), the actual number of bytes used for the
63key and IV depends on the cipher. It is possible to set all parameters
64to NULL except B<type> in an initial call and supply the remaining
65parameters in subsequent calls. This is normally done when the
66EVP_CIPHER_asn1_to_param() function is called to set the cipher
67parameters from an ASN1 AlgorithmIdentifier and the key from a
68different source.
69
70EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and
71writes the encrypted version to B<out>. This function can be called
72multiple times to encrypt successive blocks of data. The amount
73of data written depends on the block alignment of the encrypted data:
74as a result the amount of data written may be anything from zero bytes
75to (inl + cipher_block_size - 1) so B<outl> should contain sufficient
76room. The actual number of bytes written is placed in B<outl>.
77
78EVP_EncryptFinal() encrypts the "final" data, that is any data that
79remains in a partial block. It uses L<standard block padding|/NOTES> (aka PKCS
80padding). The encrypted final data is written to B<out> which should
81have sufficient space for one cipher block. The number of bytes written
82is placed in B<outl>. After this function is called the encryption operation
83is finished and no further calls to EVP_EncryptUpdate() should be made.
84
85EVP_DecryptInit(), EVP_DecryptUpdate() and EVP_DecryptFinal() are the
86corresponding decryption operations. EVP_DecryptFinal() will return an
87error code if the final block is not correctly formatted. The parameters
88and restrictions are identical to the encryption operations except that
89the decrypted data buffer B<out> passed to EVP_DecryptUpdate() should
90have sufficient room for (B<inl> + cipher_block_size) bytes unless the
91cipher block size is 1 in which case B<inl> bytes is sufficient.
92
93EVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal() are functions
94that can be used for decryption or encryption. The operation performed
95depends on the value of the B<enc> parameter. It should be set to 1 for
96encryption and 0 for decryption.
97
98EVP_CIPHER_CTX_cleanup() clears all information from a cipher context.
99It should be called after all operations using a cipher are complete
100so sensitive information does not remain in memory.
101
102EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
103return an EVP_CIPHER structure when passed a cipher name, a NID or an
104ASN1_OBJECT structure.
105
106EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return the NID of a cipher when
107passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX> structure. The actual NID
108value is an internal value which may not have a corresponding OBJECT
109IDENTIFIER.
110
111EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
112length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
113structure. The constant B<EVP_MAX_KEY_LENGTH> is the maximum key length
114for all ciphers.
115
116EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
117length of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>.
118It will return zero if the cipher does not use an IV. The constant
119B<EVP_MAX_IV_LENGTH> is the maximum IV length for all ciphers.
120
121EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
122size of a cipher when passed an B<EVP_CIPHER> or B<EVP_CIPHER_CTX>
123structure. The constant B<EVP_MAX_IV_LENGTH> is also the maximum block
124length for all ciphers.
125
126EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the type of the passed
127cipher or context. This "type" is the actual NID of the cipher OBJECT
128IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and
129128 bit RC2 have the same NID. If the cipher does not have an object
130identifier or does not have ASN1 support this function will return
131B<NID_undef>.
132
133EVP_CIPHER_CTX_cipher() returns the B<EVP_CIPHER> structure when passed
134an B<EVP_CIPHER_CTX> structure.
135
136EVP_CIPHER_param_to_asn1() sets the AlgorithmIdentifier "parameter" based
137on the passed cipher. This will typically include any parameters and an
138IV. The cipher IV (if any) must be set when this call is made. This call
139should be made before the cipher is actually "used" (before any
140EVP_EncryptUpdate(), EVP_DecryptUpdate() calls for example). This function
141may fail if the cipher does not have any ASN1 support.
142
143EVP_CIPHER_asn1_to_param() sets the cipher parameters based on an ASN1
144AlgorithmIdentifier "parameter". The precise effect depends on the cipher
145In the case of RC2, for example, it will set the IV and effective key length.
146This function should be called after the base cipher type is set but before
147the key is set. For example EVP_CipherInit() will be called with the IV and
148key set to NULL, EVP_CIPHER_asn1_to_param() will be called and finally
149EVP_CipherInit() again with all parameters except the key set to NULL. It is
150possible for this function to fail if the cipher does not have any ASN1 support
151or the parameters cannot be set (for example the RC2 effective key length
152does not have an B<EVP_CIPHER> structure).
153
154=head1 RETURN VALUES
155
156EVP_EncryptInit(), EVP_EncryptUpdate() and EVP_EncryptFinal() do not return
157values.
158
159EVP_DecryptInit() and EVP_DecryptUpdate() do not return values.
160EVP_DecryptFinal() returns 0 if the decrypt failed or 1 for success.
161
162EVP_CipherInit() and EVP_CipherUpdate() do not return values.
163EVP_CipherFinal() returns 1 for a decryption failure or 1 for success, if
164the operation is encryption then it always returns 1.
165
166EVP_CIPHER_CTX_cleanup() does not return a value.
167
168EVP_get_cipherbyname(), EVP_get_cipherbynid() and EVP_get_cipherbyobj()
169return an B<EVP_CIPHER> structure or NULL on error.
170
171EVP_CIPHER_nid() and EVP_CIPHER_CTX_nid() return a NID.
172
173EVP_CIPHER_block_size() and EVP_CIPHER_CTX_block_size() return the block
174size.
175
176EVP_CIPHER_key_length() and EVP_CIPHER_CTX_key_length() return the key
177length.
178
179EVP_CIPHER_iv_length() and EVP_CIPHER_CTX_iv_length() return the IV
180length or zero if the cipher does not use an IV.
181
182EVP_CIPHER_type() and EVP_CIPHER_CTX_type() return the NID of the cipher's
183OBJECT IDENTIFIER or NID_undef if it has no defined OBJECT IDENTIFIER.
184
185EVP_CIPHER_CTX_cipher() returns an B<EVP_CIPHER> structure.
186
187EVP_CIPHER_param_to_asn1() and EVP_CIPHER_asn1_to_param() return 1 for
188success or zero for failure.
189
190=head1 NOTES
191
192Where possible the B<EVP> interface to symmetric ciphers should be used in
193preference to the low level interfaces. This is because the code then becomes
194transparent to the cipher used and much more flexible.
195
196PKCS padding works by adding B<n> padding bytes of value B<n> to make the total
197length of the encrypted data a multiple of the block size. Padding is always
198added so if the data is already a multiple of the block size B<n> will equal
199the block size. For example if the block size is 8 and 11 bytes are to be
200encrypted then 5 padding bytes of value 5 will be added.
201
202When decrypting the final block is checked to see if it has the correct form.
203
204Although the decryption operation can produce an error, it is not a strong
205test that the input data or key is correct. A random block has better than
2061 in 256 chance of being of the correct format and problems with the
207input data earlier on will not produce a final decrypt error.
208
209=head1 BUGS
210
211The current B<EVP> cipher interface is not as flexible as it should be. Only
212certain "spot" encryption algorithms can be used for ciphers which have various
213parameters associated with them (RC2, RC5 for example) this is inadequate.
214
215Several of the functions do not return error codes because the software versions
216can never fail. This is not true of hardware versions.
217
218=head1 SEE ALSO
219
220L<evp(3)|evp(3)>
221
222=head1 HISTORY
223
224=cut
diff --git a/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod b/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod
new file mode 100644
index 0000000000..b0b1058d19
--- /dev/null
+++ b/src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod
@@ -0,0 +1,46 @@
1=pod
2
3=head1 NAME
4
5OPENSSL_VERSION_NUMBER, SSLeay - get OpenSSL version number
6
7=head1 SYNOPSIS
8
9 #include <openssl/opensslv.h>
10 #define OPENSSL_VERSION_NUMBER 0xnnnnnnnnnL
11
12 #include <openssl/crypto.h>
13 long SSLeay(void);
14
15=head1 DESCRIPTION
16
17OPENSSL_VERSION_NUMBER is a numeric release version identifier:
18
19 MMNNFFRBB major minor fix final beta/patch
20
21for example
22
23 0x000904100 == 0.9.4 release
24 0x000905000 == 0.9.5 dev
25
26Versions prior to 0.9.3 have identifiers E<lt> 0x0930.
27For backward compatibility, SSLEAY_VERSION_NUMBER is also defined.
28
29SSLeay() returns this number. The return value can be compared to the
30macro to make sure that the correct version of the library has been
31loaded, especially when using DLLs on Windows systems.
32
33=head1 RETURN VALUE
34
35The version number.
36
37=head1 SEE ALSO
38
39L<crypto(3)|crypto(3)>
40
41=head1 HISTORY
42
43SSLeay() and SSLEAY_VERSION_NUMBER are available in all versions of SSLeay and OpenSSL.
44OPENSSL_VERSION_NUMBER is available in all versions of OpenSSL.
45
46=cut
diff --git a/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod b/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod
new file mode 100644
index 0000000000..1300fe190c
--- /dev/null
+++ b/src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod
@@ -0,0 +1,65 @@
1=pod
2
3=head1 NAME
4
5OpenSSL_add_all_algorithms() - add algorithms to internal table
6
7=head1 SYNOPSIS
8
9 #include <openssl/evp.h>
10
11 void OpenSSL_add_all_algorithms(void);
12 void OpenSSL_add_all_ciphers(void);
13 void OpenSSL_add_all_digests(void);
14
15 void EVP_cleanup(void);
16
17=head1 DESCRIPTION
18
19OpenSSL keeps an internal table of digest algorithms and ciphers. It uses
20this table to lookup ciphers via functions such as EVP_get_cipher_byname().
21
22OpenSSL_add_all_digests() adds all digest algorithms to the table.
23
24OpenSSL_add_all_algorithms() adds all algorithms to the table (digests and
25ciphers).
26
27OpenSSL_add_all_ciphers() adds all encryption algorithms to the table including
28password based encryption algorithms.
29
30EVP_cleanup() removes all ciphers and digests from the table.
31
32=head1 RETURN VALUES
33
34None of the functions return a value.
35
36=head1 NOTES
37
38A typical application will will call OpenSSL_add_all_algorithms() initially and
39EVP_cleanup() before exiting.
40
41An application does not need to add algorithms to use them explicitly, for example
42by EVP_sha1(). It just needs to add them if it (or any of the functions it calls)
43needs to lookup algorithms.
44
45The cipher and digest lookup functions are used in many parts of the library. If
46the table is not initialised several functions will misbehave and complain they
47cannot find algorithms. This includes the PEM, PKCS#12, SSL and S/MIME libraries.
48This is a common query in the OpenSSL mailing lists.
49
50Calling OpenSSL_add_all_algorithms() links in all algorithms: as a result a
51statically linked executable can be quite large. If this is important it is possible
52to just add the required ciphers and digests.
53
54=head1 BUGS
55
56Although the functions do not return error codes it is possible for them to fail.
57This will only happen as a result of a memory allocation failure so this is not
58too much of a problem in practice.
59
60=head1 SEE ALSO
61
62L<evp(3)|evp(3)>, L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
63L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>
64
65=cut
diff --git a/src/lib/libcrypto/doc/RAND_add.pod b/src/lib/libcrypto/doc/RAND_add.pod
new file mode 100644
index 0000000000..0a13ec2a92
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_add.pod
@@ -0,0 +1,68 @@
1=pod
2
3=head1 NAME
4
5RAND_add, RAND_seed, RAND_screen - add entropy to the PRNG
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_seed(const void *buf, int num);
12
13 void RAND_add(const void *buf, int num, double entropy);
14
15 int RAND_status(void);
16
17 void RAND_screen(void);
18
19=head1 DESCRIPTION
20
21RAND_add() mixes the B<num> bytes at B<buf> into the PRNG state. Thus,
22if the data at B<buf> are unpredictable to an adversary, this
23increases the uncertainty about the state and makes the PRNG output
24less predictable. Suitable input comes from user interaction (random
25key presses, mouse movements) and certain hardware events. The
26B<entropy> argument is (the lower bound of) an estimate of how much
27randomness is contained in B<buf>, measured in bytes. Details about
28sources of randomness and how to estimate their entropy can be found
29in the literature, e.g. RFC 1750.
30
31RAND_add() may be called with sensitive data such as user entered
32passwords. The seed values cannot be recovered from the PRNG output.
33
34OpenSSL makes sure that the PRNG state is unique for each thread. On
35systems that provide C</dev/urandom>, the randomness device is used
36to seed the PRNG transparently. However, on all other systems, the
37application is responsible for seeding the PRNG by calling RAND_add(),
38L<RAND_egd(3)|RAND_egd(3)>
39or L<RAND_load_file(3)|RAND_load_file(3)>.
40
41RAND_seed() is equivalent to RAND_add() when B<num == entropy>.
42
43The RAND_screen() function is available for the convenience of Windows
44programmers. It adds the current contents of the screen to the PRNG.
45For applications that can catch Windows events, seeding the PRNG with
46the parameters of B<WM_MOUSEMOVE> events is a significantly better
47source of randomness. It should be noted that both methods cannot be
48used on servers that run without user interaction.
49
50=head1 RETURN VALUES
51
52RAND_status() returns 1 if the PRNG has been seeded with enough data,
530 otherwise.
54
55The other functions do not return values.
56
57=head1 SEE ALSO
58
59L<rand(3)|rand(3)>, L<RAND_egd(3)|RAND_egd(3)>,
60L<RAND_load_file(3)|RAND_load_file(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
61
62=head1 HISTORY
63
64RAND_seed() and RAND_screen() are available in all versions of SSLeay
65and OpenSSL. RAND_add() and RAND_status() have been added in OpenSSL
660.9.5.
67
68=cut
diff --git a/src/lib/libcrypto/doc/RAND_bytes.pod b/src/lib/libcrypto/doc/RAND_bytes.pod
new file mode 100644
index 0000000000..b6ebd50527
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_bytes.pod
@@ -0,0 +1,46 @@
1=pod
2
3=head1 NAME
4
5RAND_bytes, RAND_pseudo_bytes - generate random data
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 int RAND_bytes(unsigned char *buf, int num);
12
13 int RAND_pseudo_bytes(unsigned char *buf, int num);
14
15=head1 DESCRIPTION
16
17RAND_bytes() puts B<num> cryptographically strong pseudo-random bytes
18into B<buf>. An error occurs if the PRNG has not been seeded with
19enough randomness to ensure an unpredictable byte sequence.
20
21RAND_pseudo_bytes() puts B<num> pseudo-random bytes into B<buf>.
22Pseudo-random byte sequences generated by RAND_pseudo_bytes() will be
23unique if they are of sufficient length, but are not necessarily
24unpredictable. They can be used for non-cryptographic purposes and for
25certain purposes in cryptographic protocols, but usually not for key
26generation etc.
27
28=head1 RETURN VALUES
29
30RAND_bytes() returns 1 on success, 0 otherwise. The error code can be
31obtained by L<ERR_get_error(3)|ERR_get_error(3)>. RAND_pseudo_bytes() returns 1 if the
32bytes generated are cryptographically strong, 0 otherwise. Both
33functions return -1 if they are not supported by the current RAND
34method.
35
36=head1 SEE ALSO
37
38L<rand(3)|rand(3)>, L<err(3)|err(3)>, L<RAND_add(3)|RAND_add(3)>
39
40=head1 HISTORY
41
42RAND_bytes() is available in all versions of SSLeay and OpenSSL. It
43has a return value since OpenSSL 0.9.5. RAND_pseudo_bytes() was added
44in OpenSSL 0.9.5.
45
46=cut
diff --git a/src/lib/libcrypto/doc/RAND_cleanup.pod b/src/lib/libcrypto/doc/RAND_cleanup.pod
new file mode 100644
index 0000000000..3a8f0749a8
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_cleanup.pod
@@ -0,0 +1,29 @@
1=pod
2
3=head1 NAME
4
5RAND_cleanup - erase the PRNG state
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_cleanup(void);
12
13=head1 DESCRIPTION
14
15RAND_cleanup() erases the memory used by the PRNG.
16
17=head1 RETURN VALUE
18
19RAND_cleanup() returns no value.
20
21=head1 SEE ALSO
22
23L<rand(3)|rand(3)>
24
25=head1 HISTORY
26
27RAND_cleanup() is available in all versions of SSLeay and OpenSSL.
28
29=cut
diff --git a/src/lib/libcrypto/doc/RAND_load_file.pod b/src/lib/libcrypto/doc/RAND_load_file.pod
new file mode 100644
index 0000000000..8dd700ca3d
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_load_file.pod
@@ -0,0 +1,53 @@
1=pod
2
3=head1 NAME
4
5RAND_load_file, RAND_write_file, RAND_file_name - PRNG seed file
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 const char *RAND_file_name(char *buf, int num);
12
13 int RAND_load_file(const char *filename, long max_bytes);
14
15 int RAND_write_file(const char *filename);
16
17=head1 DESCRIPTION
18
19RAND_file_name() generates a default path for the random seed
20file. B<buf> points to a buffer of size B<num> in which to store the
21filename. The seed file is $RANDFILE if that environment variable is
22set, $HOME/.rnd otherwise. If $HOME is not set either, or B<num> is
23too small for the path name, an error occurs.
24
25RAND_load_file() reads a number of bytes from file B<filename> and
26adds them to the PRNG. If B<max_bytes> is non-negative,
27up to to B<max_bytes> are read; starting with OpenSSL 0.9.5,
28if B<max_bytes> is -1, the complete file is read.
29
30RAND_write_file() writes a number of random bytes (currently 1024) to
31file B<filename> which can be used to initialize the PRNG by calling
32RAND_load_file() in a later session.
33
34=head1 RETURN VALUES
35
36RAND_load_file() returns the number of bytes read.
37
38RAND_write_file() returns the number of bytes written, and -1 if the
39bytes written were generated without appropriate seed.
40
41RAND_file_name() returns a pointer to B<buf> on success, and NULL on
42error.
43
44=head1 SEE ALSO
45
46L<rand(3)|rand(3)>, L<RAND_add(3)|RAND_add(3)>, L<RAND_cleanup(3)|RAND_cleanup(3)>
47
48=head1 HISTORY
49
50RAND_load_file(), RAND_write_file() and RAND_file_name() are available in
51all versions of SSLeay and OpenSSL.
52
53=cut
diff --git a/src/lib/libcrypto/doc/RAND_set_rand_method.pod b/src/lib/libcrypto/doc/RAND_set_rand_method.pod
new file mode 100644
index 0000000000..466e9b8767
--- /dev/null
+++ b/src/lib/libcrypto/doc/RAND_set_rand_method.pod
@@ -0,0 +1,57 @@
1=pod
2
3=head1 NAME
4
5RAND_set_rand_method, RAND_get_rand_method, RAND_SSLeay - select RAND method
6
7=head1 SYNOPSIS
8
9 #include <openssl/rand.h>
10
11 void RAND_set_rand_method(RAND_METHOD *meth);
12
13 RAND_METHOD *RAND_get_rand_method(void);
14
15 RAND_METHOD *RAND_SSLeay(void);
16
17=head1 DESCRIPTION
18
19A B<RAND_METHOD> specifies the functions that OpenSSL uses for random
20number generation. By modifying the method, alternative
21implementations such as hardware RNGs may be used. Initially, the
22default is to use the OpenSSL internal implementation. RAND_SSLeay()
23returns a pointer to that method.
24
25RAND_set_rand_method() sets the RAND method to B<meth>.
26RAND_get_rand_method() returns a pointer to the current method.
27
28=head1 THE RAND_METHOD STRUCTURE
29
30 typedef struct rand_meth_st
31 {
32 void (*seed)(const void *buf, int num);
33 int (*bytes)(unsigned char *buf, int num);
34 void (*cleanup)(void);
35 void (*add)(const void *buf, int num, int entropy);
36 int (*pseudorand)(unsigned char *buf, int num);
37 } RAND_METHOD;
38
39The components point to the implementation of RAND_seed(),
40RAND_bytes(), RAND_cleanup(), RAND_add() and RAND_pseudo_rand().
41Each component may be NULL if the function is not implemented.
42
43=head1 RETURN VALUES
44
45RAND_set_rand_method() returns no value. RAND_get_rand_method() and
46RAND_SSLeay() return pointers to the respective methods.
47
48=head1 SEE ALSO
49
50L<rand(3)|rand(3)>
51
52=head1 HISTORY
53
54RAND_set_rand_method(), RAND_get_rand_method() and RAND_SSLeay() are
55available in all versions of OpenSSL.
56
57=cut
diff --git a/src/lib/libcrypto/doc/RSA_blinding_on.pod b/src/lib/libcrypto/doc/RSA_blinding_on.pod
new file mode 100644
index 0000000000..fd2c69abd8
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_blinding_on.pod
@@ -0,0 +1,43 @@
1=pod
2
3=head1 NAME
4
5RSA_blinding_on, RSA_blinding_off - protect the RSA operation from timing attacks
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
12
13 void RSA_blinding_off(RSA *rsa);
14
15=head1 DESCRIPTION
16
17RSA is vulnerable to timing attacks. In a setup where attackers can
18measure the time of RSA decryption or signature operations, blinding
19must be used to protect the RSA operation from that attack.
20
21RSA_blinding_on() turns blinding on for key B<rsa> and generates a
22random blinding factor. B<ctx> is B<NULL> or a pre-allocated and
23initialized B<BN_CTX>. The random number generator must be seeded
24prior to calling RSA_blinding_on().
25
26RSA_blinding_off() turns blinding off and frees the memory used for
27the blinding factor.
28
29=head1 RETURN VALUES
30
31RSA_blinding_on() returns 1 on success, and 0 if an error occurred.
32
33RSA_blinding_off() returns no value.
34
35=head1 SEE ALSO
36
37L<rsa(3)|rsa(3)>, L<rand(3)|rand(3)>
38
39=head1 HISTORY
40
41RSA_blinding_on() and RSA_blinding_off() appeared in SSLeay 0.9.0.
42
43=cut
diff --git a/src/lib/libcrypto/doc/RSA_check_key.pod b/src/lib/libcrypto/doc/RSA_check_key.pod
new file mode 100644
index 0000000000..79fed753ad
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_check_key.pod
@@ -0,0 +1,39 @@
1=pod
2
3=head1 NAME
4
5RSA_check_key - validate private RSA keys
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_check_key(RSA *rsa);
12
13=head1 DESCRIPTION
14
15This function validates RSA keys. It checks that B<p> and B<q> are
16in fact prime, and that B<n = p*q>.
17
18It also checks that B<d*e = 1 mod (p-1*q-1)>,
19and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>.
20
21The key's public components may not be B<NULL>.
22
23=head1 RETURN VALUE
24
25RSA_check_key() returns 1 if B<rsa> is a valid RSA key, and 0 otherwise.
26-1 is returned if an error occurs while checking the key.
27
28If the key is invalid or an error occurred, the reason code can be
29obtained using L<ERR_get_error(3)|ERR_get_error(3)>.
30
31=head1 SEE ALSO
32
33L<rsa(3)|rsa(3)>, L<err(3)|err(3)>
34
35=head1 HISTORY
36
37RSA_check() appeared in OpenSSL 0.9.4.
38
39=cut
diff --git a/src/lib/libcrypto/doc/RSA_generate_key.pod b/src/lib/libcrypto/doc/RSA_generate_key.pod
new file mode 100644
index 0000000000..fdaddbcb13
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_generate_key.pod
@@ -0,0 +1,68 @@
1=pod
2
3=head1 NAME
4
5RSA_generate_key - generate RSA key pair
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA *RSA_generate_key(int num, unsigned long e,
12 void (*callback)(int,int,void *), void *cb_arg);
13
14=head1 DESCRIPTION
15
16RSA_generate_key() generates a key pair and returns it in a newly
17allocated B<RSA> structure. The pseudo-random number generator must
18be seeded prior to calling RSA_generate_key().
19
20The modulus size will be B<num> bits, and the public exponent will be
21B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure.
22The exponent is an odd number, typically 3 or 65535.
23
24A callback function may be used to provide feedback about the
25progress of the key generation. If B<callback> is not B<NULL>, it
26will be called as follows:
27
28=over 4
29
30=item *
31
32While a random prime number is generated, it is called as
33described in L<BN_generate_prime(3)|BN_generate_prime(3)>.
34
35=item *
36
37When the n-th randomly generated prime is rejected as not
38suitable for the key, B<callback(2, n, cb_arg)> is called.
39
40=item *
41
42When a random p has been found with p-1 relatively prime to B<e>,
43it is called as B<callback(3, 0, cb_arg)>.
44
45=back
46
47The process is then repeated for prime q with B<callback(3, 1, cb_arg)>.
48
49=head1 RETURN VALUE
50
51If key generation fails, RSA_generate_key() returns B<NULL>; the
52error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
53
54=head1 BUGS
55
56B<callback(2, x, cb_arg)> is used with two different meanings.
57
58RSA_generate_key() goes into an infinite loop for illegal input values.
59
60=head1 SEE ALSO
61
62L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_free(3)|RSA_free(3)>
63
64=head1 HISTORY
65
66The B<cb_arg> argument was added in SSLeay 0.9.0.
67
68=cut
diff --git a/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod b/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
new file mode 100644
index 0000000000..920dc76325
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
@@ -0,0 +1,122 @@
1=pod
2
3=head1 NAME
4
5RSA_get_ex_new_index, RSA_set_ex_data, RSA_get_ex_data - add application specific data to RSA structures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_get_ex_new_index(long argl, void *argp,
12 CRYPTO_EX_new *new_func,
13 CRYPTO_EX_dup *dup_func,
14 CRYPTO_EX_free *free_func);
15
16 int RSA_set_ex_data(RSA *r, int idx, void *arg);
17
18 void *RSA_get_ex_data(RSA *r, int idx);
19
20 int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp);
22
23 void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
24 int idx, long argl, void *argp);
25
26 int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
27 int idx, long argl, void *argp);
28
29=head1 DESCRIPTION
30
31Several OpenSSL structures can have application specific data attached to them.
32This has several potential uses, it can be used to cache data associated with
33a structure (for example the hash of some part of the structure) or some
34additional data (for example a handle to the data in an external library).
35
36Since the application data can be anything at all it is passed and retrieved
37as a B<void *> type.
38
39The B<RSA_get_ex_new_index()> function is initially called to "register" some
40new application specific data. It takes three optional function pointers which
41are called when the parent structure (in this case an RSA structure) is
42initially created, when it is copied and when it is freed up. If any or all of
43these function pointer arguments are not used they should be set to NULL. The
44precise manner in which these function pointers are called is described in more
45detail below. B<RSA_get_ex_new_index()> also takes additional long and pointer
46parameters which will be passed to the supplied functions but which otherwise
47have no special meaning. It returns an B<index> which should be stored
48(typically in a static variable) and passed used in the B<idx> parameter in
49the remaining functions. Each successful call to B<RSA_get_ex_new_index()>
50will return an index greater than any previously returned, this is important
51because the optional functions are called in order of increasing index value.
52
53B<RSA_set_ex_data()> is used to set application specific data, the data is
54supplied in the B<arg> parameter and its precise meaning is up to the
55application.
56
57B<RSA_get_ex_data()> is used to retrieve application specific data. The data
58is returned to the application, this will be the same value as supplied to
59a previous B<RSA_set_ex_data()> call.
60
61B<new_func()> is called when a structure is initially allocated (for example
62with B<RSA_new()>. The parent structure members will not have any meaningful
63values at this point. This function will typically be used to allocate any
64application specific structure.
65
66B<free_func()> is called when a structure is being freed up. The dynamic parent
67structure members should not be accessed because they will be freed up when
68this function is called.
69
70B<new_func()> and B<free_func()> take the same parameters. B<parent> is a
71pointer to the parent RSA structure. B<ptr> is a the application specific data
72(this wont be of much use in B<new_func()>. B<ad> is a pointer to the
73B<CRYPTO_EX_DATA> structure from the parent RSA structure: the functions
74B<CRYPTO_get_ex_data()> and B<CRYPTO_set_ex_data()> can be called to manipulate
75it. The B<idx> parameter is the index: this will be the same value returned by
76B<RSA_get_ex_new_index()> when the functions were initially registered. Finally
77the B<argl> and B<argp> parameters are the values originally passed to the same
78corresponding parameters when B<RSA_get_ex_new_index()> was called.
79
80B<dup_func()> is called when a structure is being copied. Pointers to the
81destination and source B<CRYPTO_EX_DATA> structures are passed in the B<to> and
82B<from> parameters respectively. The B<from_d> parameter is passed a pointer to
83the source application data when the function is called, when the function returns
84the value is copied to the destination: the application can thus modify the data
85pointed to by B<from_d> and have different values in the source and destination.
86The B<idx>, B<argl> and B<argp> parameters are the same as those in B<new_func()>
87and B<free_func()>.
88
89=head1 RETURN VALUES
90
91B<RSA_get_ex_new_index()> returns a new index or -1 on failure (note 0 is a valid
92index value).
93
94B<RSA_set_ex_data()> returns 1 on success or 0 on failure.
95
96B<RSA_get_ex_data()> returns the application data or 0 on failure. 0 may also
97be valid application data but currently it can only fail if given an invalid B<idx>
98parameter.
99
100B<new_func()> and B<dup_func()> should return 0 for failure and 1 for success.
101
102On failure an error code can be obtained from L<ERR_get_error(3)|ERR_get_error(3)>.
103
104=head1 BUGS
105
106B<dup_func()> is currently never called.
107
108The return value of B<new_func()> is ignored.
109
110The B<new_func()> function isn't very useful because no meaningful values are
111present in the parent RSA structure when it is called.
112
113=head1 SEE ALSO
114
115L<rsa(3)|rsa(3)>, L<CRYPTO_set_ex_data(3)|CRYPTO_set_ex_data(3)>
116
117=head1 HISTORY
118
119RSA_get_ex_new_index(), RSA_set_ex_data() and RSA_get_ex_data() are
120available since SSLeay 0.9.0.
121
122=cut
diff --git a/src/lib/libcrypto/doc/RSA_new.pod b/src/lib/libcrypto/doc/RSA_new.pod
new file mode 100644
index 0000000000..f16490ea6a
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_new.pod
@@ -0,0 +1,38 @@
1=pod
2
3=head1 NAME
4
5RSA_new, RSA_free - allocate and free RSA objects
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * RSA_new(void);
12
13 void RSA_free(RSA *rsa);
14
15=head1 DESCRIPTION
16
17RSA_new() allocates and initializes an B<RSA> structure.
18
19RSA_free() frees the B<RSA> structure and its components. The key is
20erased before the memory is returned to the system.
21
22=head1 RETURN VALUES
23
24If the allocation fails, RSA_new() returns B<NULL> and sets an error
25code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. Otherwise it returns
26a pointer to the newly allocated structure.
27
28RSA_free() returns no value.
29
30=head1 SEE ALSO
31
32L<err(3)|err(3)>, L<rsa(3)|rsa(3)>, L<RSA_generate_key(3)|RSA_generate_key(3)>
33
34=head1 HISTORY
35
36RSA_new() and RSA_free() are available in all versions of SSLeay and OpenSSL.
37
38=cut
diff --git a/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod b/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod
new file mode 100644
index 0000000000..b8f678fe72
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod
@@ -0,0 +1,124 @@
1=pod
2
3=head1 NAME
4
5RSA_padding_add_PKCS1_type_1, RSA_padding_check_PKCS1_type_1,
6RSA_padding_add_PKCS1_type_2, RSA_padding_check_PKCS1_type_2,
7RSA_padding_add_PKCS1_OAEP, RSA_padding_check_PKCS1_OAEP,
8RSA_padding_add_SSLv23, RSA_padding_check_SSLv23,
9RSA_padding_add_none, RSA_padding_check_none - asymmetric encryption
10padding
11
12=head1 SYNOPSIS
13
14 #include <openssl/rsa.h>
15
16 int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
17 unsigned char *f, int fl);
18
19 int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
20 unsigned char *f, int fl, int rsa_len);
21
22 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
23 unsigned char *f, int fl);
24
25 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
26 unsigned char *f, int fl, int rsa_len);
27
28 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
29 unsigned char *f, int fl, unsigned char *p, int pl);
30
31 int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
32 unsigned char *f, int fl, int rsa_len, unsigned char *p, int pl);
33
34 int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
35 unsigned char *f, int fl);
36
37 int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
38 unsigned char *f, int fl, int rsa_len);
39
40 int RSA_padding_add_none(unsigned char *to, int tlen,
41 unsigned char *f, int fl);
42
43 int RSA_padding_check_none(unsigned char *to, int tlen,
44 unsigned char *f, int fl, int rsa_len);
45
46=head1 DESCRIPTION
47
48The RSA_padding_xxx_xxx() functions are called from the RSA encrypt,
49decrypt, sign and verify functions. Normally they should not be called
50from application programs.
51
52However, they can also be called directly to implement padding for other
53asymmetric ciphers. RSA_padding_add_PKCS1_OAEP() and
54RSA_padding_check_PKCS1_OAEP() may be used in an application combined
55with B<RSA_NO_PADDING> in order to implement OAEP with an encoding
56parameter.
57
58RSA_padding_add_xxx() encodes B<fl> bytes from B<f> so as to fit into
59B<tlen> bytes and stores the result at B<to>. An error occurs if B<fl>
60does not meet the size requirements of the encoding method.
61
62The following encoding methods are implemented:
63
64=over 4
65
66=item PKCS1_type_1
67
68PKCS #1 v2.0 EMSA-PKCS1-v1_5 (PKCS #1 v1.5 block type 1); used for signatures
69
70=item PKCS1_type_2
71
72PKCS #1 v2.0 EME-PKCS1-v1_5 (PKCS #1 v1.5 block type 2)
73
74=item PKCS1_OAEP
75
76PKCS #1 v2.0 EME-OAEP
77
78=item SSLv23
79
80PKCS #1 EME-PKCS1-v1_5 with SSL-specific modification
81
82=item none
83
84simply copy the data
85
86=back
87
88The random number generator must be seeded prior to calling
89RSA_padding_add_xxx().
90
91RSA_padding_check_xxx() verifies that the B<fl> bytes at B<f> contain
92a valid encoding for a B<rsa_len> byte RSA key in the respective
93encoding method and stores the recovered data of at most B<tlen> bytes
94(for B<RSA_NO_PADDING>: of size B<tlen>)
95at B<to>.
96
97For RSA_padding_xxx_OAEP(), B<p> points to the encoding parameter
98of length B<pl>. B<p> may be B<NULL> if B<pl> is 0.
99
100=head1 RETURN VALUES
101
102The RSA_padding_add_xxx() functions return 1 on success, 0 on error.
103The RSA_padding_check_xxx() functions return the length of the
104recovered data, -1 on error. Error codes can be obtained by calling
105L<ERR_get_error(3)|ERR_get_error(3)>.
106
107=head1 SEE ALSO
108
109L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
110L<RSA_private_decrypt(3)|RSA_private_decrypt(3)>,
111L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
112
113=head1 HISTORY
114
115RSA_padding_add_PKCS1_type_1(), RSA_padding_check_PKCS1_type_1(),
116RSA_padding_add_PKCS1_type_2(), RSA_padding_check_PKCS1_type_2(),
117RSA_padding_add_SSLv23(), RSA_padding_check_SSLv23(),
118RSA_padding_add_none() and RSA_padding_check_none() appeared in
119SSLeay 0.9.0.
120
121RSA_padding_add_PKCS1_OAEP() and RSA_padding_check_PKCS1_OAEP() were
122added in OpenSSL 0.9.2b.
123
124=cut
diff --git a/src/lib/libcrypto/doc/RSA_print.pod b/src/lib/libcrypto/doc/RSA_print.pod
new file mode 100644
index 0000000000..dd968a5274
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_print.pod
@@ -0,0 +1,48 @@
1=pod
2
3=head1 NAME
4
5RSA_print, RSA_print_fp, DHparams_print, DHparams_print_fp - print
6cryptographic parameters
7
8=head1 SYNOPSIS
9
10 #include <openssl/rsa.h>
11
12 int RSA_print(BIO *bp, RSA *x, int offset);
13 int RSA_print_fp(FILE *fp, RSA *x, int offset);
14
15 #include <openssl/dsa.h>
16
17 int DSAparams_print(BIO *bp, DSA *x);
18 int DSAparams_print_fp(FILE *fp, DSA *x);
19 int DSA_print(BIO *bp, DSA *x, int offset);
20 int DSA_print_fp(FILE *fp, DSA *x, int offset);
21
22 #include <openssl/dh.h>
23
24 int DHparams_print(BIO *bp, DH *x);
25 int DHparams_print_fp(FILE *fp, DH *x);
26
27=head1 DESCRIPTION
28
29A human-readable hexadecimal output of the components of the RSA
30key, DSA parameters or key or DH parameters is printed to B<bp> or B<fp>.
31
32The output lines are indented by B<offset> spaces.
33
34=head1 RETURN VALUES
35
36These functions return 1 on success, 0 on error.
37
38=head1 SEE ALSO
39
40L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<rsa(3)|rsa(3)>, L<BN_bn2bin(3)|BN_bn2bin(3)>
41
42=head1 HISTORY
43
44RSA_print(), RSA_print_fp(), DSA_print(), DSA_print_fp(), DH_print(),
45DH_print_fp() are available in all versions of SSLeay and OpenSSL.
46DSAparams_print() and DSAparams_print_pf() were added in SSLeay 0.8.
47
48=cut
diff --git a/src/lib/libcrypto/doc/RSA_private_encrypt.pod b/src/lib/libcrypto/doc/RSA_private_encrypt.pod
new file mode 100644
index 0000000000..6861a98a10
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_private_encrypt.pod
@@ -0,0 +1,69 @@
1=pod
2
3=head1 NAME
4
5RSA_private_encrypt, RSA_public_decrypt - low level signature operations
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_private_encrypt(int flen, unsigned char *from,
12 unsigned char *to, RSA *rsa, int padding);
13
14 int RSA_public_decrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16
17=head1 DESCRIPTION
18
19These functions handle RSA signatures at a low level.
20
21RSA_private_encrypt() signs the B<flen> bytes at B<from> (usually a
22message digest with an algorithm identifier) using the private key
23B<rsa> and stores the signature in B<to>. B<to> must point to
24B<RSA_size(rsa)> bytes of memory.
25
26B<padding> denotes one of the following modes:
27
28=over 4
29
30=item RSA_PKCS1_PADDING
31
32PKCS #1 v1.5 padding. This function does not handle the
33B<algorithmIdentifier> specified in PKCS #1. When generating or
34verifying PKCS #1 signatures, L<RSA_sign(3)|RSA_sign(3)> and L<RSA_verify(3)|RSA_verify(3)> should be
35used.
36
37=item RSA_NO_PADDING
38
39Raw RSA signature. This mode should I<only> be used to implement
40cryptographically sound padding modes in the application code.
41Signing user data directly with RSA is insecure.
42
43=back
44
45RSA_public_decrypt() recovers the message digest from the B<flen>
46bytes long signature at B<from> using the signer's public key
47B<rsa>. B<to> must point to a memory section large enough to hold the
48message digest (which is smaller than B<RSA_size(rsa) -
4911>). B<padding> is the padding mode that was used to sign the data.
50
51=head1 RETURN VALUES
52
53RSA_private_encrypt() returns the size of the signature (i.e.,
54RSA_size(rsa)). RSA_public_decrypt() returns the size of the
55recovered message digest.
56
57On error, -1 is returned; the error codes can be
58obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
59
60=head1 SEE ALSO
61
62L<err(3)|err(3)>, L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)>
63
64=head1 HISTORY
65
66The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
67available since SSLeay 0.9.0.
68
69=cut
diff --git a/src/lib/libcrypto/doc/RSA_public_encrypt.pod b/src/lib/libcrypto/doc/RSA_public_encrypt.pod
new file mode 100644
index 0000000000..910c4752b8
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_public_encrypt.pod
@@ -0,0 +1,86 @@
1=pod
2
3=head1 NAME
4
5RSA_public_encrypt, RSA_private_decrypt - RSA public key cryptography
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_public_encrypt(int flen, unsigned char *from,
12 unsigned char *to, RSA *rsa, int padding);
13
14 int RSA_private_decrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16
17=head1 DESCRIPTION
18
19RSA_public_encrypt() encrypts the B<flen> bytes at B<from> (usually a
20session key) using the public key B<rsa> and stores the ciphertext in
21B<to>. B<to> must point to RSA_size(B<rsa>) bytes of memory.
22
23B<padding> denotes one of the following modes:
24
25=over 4
26
27=item RSA_PKCS1_PADDING
28
29PKCS #1 v1.5 padding. This currently is the most widely used mode.
30
31=item RSA_PKCS1_OAEP_PADDING
32
33EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
34encoding parameter. This mode is recommended for all new applications.
35
36=item RSA_SSLV23_PADDING
37
38PKCS #1 v1.5 padding with an SSL-specific modification that denotes
39that the server is SSL3 capable.
40
41=item RSA_NO_PADDING
42
43Raw RSA encryption. This mode should I<only> be used to implement
44cryptographically sound padding modes in the application code.
45Encrypting user data directly with RSA is insecure.
46
47=back
48
49B<flen> must be less than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5
50based padding modes, and less than RSA_size(B<rsa>) - 21 for
51RSA_PKCS1_OAEP_PADDING. The random number generator must be seeded
52prior to calling RSA_public_encrypt().
53
54RSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the
55private key B<rsa> and stores the plaintext in B<to>. B<to> must point
56to a memory section large enough to hold the decrypted data (which is
57smaller than RSA_size(B<rsa>)). B<padding> is the padding mode that
58was used to encrypt the data.
59
60=head1 RETURN VALUES
61
62RSA_public_encrypt() returns the size of the encrypted data (i.e.,
63RSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the
64recovered plaintext.
65
66On error, -1 is returned; the error codes can be
67obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
68
69=head1 CONFORMING TO
70
71SSL, PKCS #1 v2.0
72
73=head1 SEE ALSO
74
75L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_size(3)|RSA_size(3)>
76
77=head1 NOTES
78
79The L<RSA_PKCS1_RSAref(3)|RSA_PKCS1_RSAref(3)> method supports only the RSA_PKCS1_PADDING mode.
80
81=head1 HISTORY
82
83The B<padding> argument was added in SSLeay 0.8. RSA_NO_PADDING is
84available since SSLeay 0.9.0, OAEP was added in OpenSSL 0.9.2b.
85
86=cut
diff --git a/src/lib/libcrypto/doc/RSA_set_method.pod b/src/lib/libcrypto/doc/RSA_set_method.pod
new file mode 100644
index 0000000000..deb1183a23
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_set_method.pod
@@ -0,0 +1,153 @@
1=pod
2
3=head1 NAME
4
5RSA_set_default_method, RSA_get_default_method, RSA_set_method,
6RSA_get_method, RSA_PKCS1_SSLeay, RSA_PKCS1_RSAref,
7RSA_PKCS1_null_method, RSA_flags, RSA_new_method - select RSA method
8
9=head1 SYNOPSIS
10
11 #include <openssl/rsa.h>
12
13 void RSA_set_default_method(RSA_METHOD *meth);
14
15 RSA_METHOD *RSA_get_default_method(void);
16
17 RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
18
19 RSA_METHOD *RSA_get_method(RSA *rsa);
20
21 RSA_METHOD *RSA_PKCS1_SSLeay(void);
22
23 RSA_METHOD *RSA_PKCS1_RSAref(void);
24
25 RSA_METHOD *RSA_null_method(void);
26
27 int RSA_flags(RSA *rsa);
28
29 RSA *RSA_new_method(RSA_METHOD *method);
30
31=head1 DESCRIPTION
32
33An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
34operations. By modifying the method, alternative implementations
35such as hardware accelerators may be used.
36
37Initially, the default is to use the OpenSSL internal implementation,
38unless OpenSSL was configured with the C<rsaref> or C<-DRSA_NULL>
39options. RSA_PKCS1_SSLeay() returns a pointer to that method.
40
41RSA_PKCS1_RSAref() returns a pointer to a method that uses the RSAref
42library. This is the default method in the C<rsaref> configuration;
43the function is not available in other configurations.
44RSA_null_method() returns a pointer to a method that does not support
45the RSA transformation. It is the default if OpenSSL is compiled with
46C<-DRSA_NULL>. These methods may be useful in the USA because of a
47patent on the RSA cryptosystem.
48
49RSA_set_default_method() makes B<meth> the default method for all B<RSA>
50structures created later.
51
52RSA_get_default_method() returns a pointer to the current default
53method.
54
55RSA_set_method() selects B<meth> for all operations using the key
56B<rsa>.
57
58RSA_get_method() returns a pointer to the method currently selected
59for B<rsa>.
60
61RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
62
63RSA_new_method() allocates and initializes an B<RSA> structure so that
64B<method> will be used for the RSA operations. If B<method> is B<NULL>,
65the default method is used.
66
67=head1 THE RSA_METHOD STRUCTURE
68
69 typedef struct rsa_meth_st
70 {
71 /* name of the implementation */
72 const char *name;
73
74 /* encrypt */
75 int (*rsa_pub_enc)(int flen, unsigned char *from,
76 unsigned char *to, RSA *rsa, int padding);
77
78 /* verify arbitrary data */
79 int (*rsa_pub_dec)(int flen, unsigned char *from,
80 unsigned char *to, RSA *rsa, int padding);
81
82 /* sign arbitrary data */
83 int (*rsa_priv_enc)(int flen, unsigned char *from,
84 unsigned char *to, RSA *rsa, int padding);
85
86 /* decrypt */
87 int (*rsa_priv_dec)(int flen, unsigned char *from,
88 unsigned char *to, RSA *rsa, int padding);
89
90 /* compute r0 = r0 ^ I mod rsa->n. May be NULL */
91 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
92
93 /* compute r = a ^ p mod m. May be NULL */
94 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
95 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
96
97 /* called at RSA_new */
98 int (*init)(RSA *rsa);
99
100 /* called at RSA_free */
101 int (*finish)(RSA *rsa);
102
103 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
104 * operations, even if p,q,dmp1,dmq1,iqmp
105 * are NULL
106 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
107 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
108 */
109 int flags;
110
111 char *app_data; /* ?? */
112
113 /* sign. For backward compatibility, this is used only
114 * if (flags & RSA_FLAG_SIGN_VER)
115 */
116 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
117 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
118
119 /* verify. For backward compatibility, this is used only
120 * if (flags & RSA_FLAG_SIGN_VER)
121 */
122 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
123 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
124
125 } RSA_METHOD;
126
127=head1 RETURN VALUES
128
129RSA_PKCS1_SSLeay(), RSA_PKCS1_RSAref(), RSA_PKCS1_null_method(),
130RSA_get_default_method() and RSA_get_method() return pointers to the
131respective B<RSA_METHOD>s.
132
133RSA_set_default_method() returns no value.
134
135RSA_set_method() returns a pointer to the B<RSA_METHOD> previously
136associated with B<rsa>.
137
138RSA_new_method() returns B<NULL> and sets an error code that can be
139obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it
140returns a pointer to the newly allocated structure.
141
142=head1 SEE ALSO
143
144L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
145
146=head1 HISTORY
147
148RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
149RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
150well as the rsa_sign and rsa_verify components of RSA_METHOD were
151added in OpenSSL 0.9.4.
152
153=cut
diff --git a/src/lib/libcrypto/doc/RSA_sign.pod b/src/lib/libcrypto/doc/RSA_sign.pod
new file mode 100644
index 0000000000..f0bf6eea1b
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_sign.pod
@@ -0,0 +1,62 @@
1=pod
2
3=head1 NAME
4
5RSA_sign, RSA_verify - RSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
12 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
13
14 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
15 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
16
17=head1 DESCRIPTION
18
19RSA_sign() signs the message digest B<m> of size B<m_len> using the
20private key B<rsa> as specified in PKCS #1 v2.0. It stores the
21signature in B<sigret> and the signature size in B<siglen>. B<sigret>
22must point to RSA_size(B<rsa>) bytes of memory.
23
24B<type> denotes the message digest algorithm that was used to generate
25B<m>. It usually is one of B<NID_sha1>, B<NID_ripemd160> and B<NID_md5>;
26see L<objects(3)|objects(3)> for details. If B<type> is B<NID_md5_sha1>,
27an SSL signature (MD5 and SHA1 message digests with PKCS #1 padding
28and no algorithm identifier) is created.
29
30RSA_verify() verifies that the signature B<sigbuf> of size B<siglen>
31matches a given message digest B<m> of size B<m_len>. B<type> denotes
32the message digest algorithm that was used to generate the signature.
33B<rsa> is the signer's public key.
34
35=head1 RETURN VALUES
36
37RSA_sign() returns 1 on success, 0 otherwise. RSA_verify() returns 1
38on successful verification, 0 otherwise.
39
40The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
41
42=head1 BUGS
43
44Certain signatures with an improper algorithm identifier are accepted
45for compatibility with SSLeay 0.4.5 :-)
46
47=head1 CONFORMING TO
48
49SSL, PKCS #1 v2.0
50
51=head1 SEE ALSO
52
53L<err(3)|err(3)>, L<objects(3)|objects(3)>, L<rsa(3)|rsa(3)>,
54L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
55L<RSA_public_decrypt(3)|RSA_public_decrypt(3)>
56
57=head1 HISTORY
58
59RSA_sign() and RSA_verify() are available in all versions of SSLeay
60and OpenSSL.
61
62=cut
diff --git a/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod b/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod
new file mode 100644
index 0000000000..df9ceb339a
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod
@@ -0,0 +1,59 @@
1=pod
2
3=head1 NAME
4
5RSA_sign_ASN1_OCTET_STRING, RSA_verify_ASN1_OCTET_STRING - RSA signatures
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
12 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
13 RSA *rsa);
14
15 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
16 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
17 RSA *rsa);
18
19=head1 DESCRIPTION
20
21RSA_sign_ASN1_OCTET_STRING() signs the octet string B<m> of size
22B<m_len> using the private key B<rsa> represented in DER using PKCS #1
23padding. It stores the signature in B<sigret> and the signature size
24in B<siglen>. B<sigret> must point to B<RSA_size(rsa)> bytes of
25memory.
26
27B<dummy> is ignored.
28
29The random number generator must be seeded prior to calling RSA_sign_ASN1_OCTET_STRING().
30
31RSA_verify_ASN1_OCTET_STRING() verifies that the signature B<sigbuf>
32of size B<siglen> is the DER representation of a given octet string
33B<m> of size B<m_len>. B<dummy> is ignored. B<rsa> is the signer's
34public key.
35
36=head1 RETURN VALUES
37
38RSA_sign_ASN1_OCTET_STRING() returns 1 on success, 0 otherwise.
39RSA_verify_ASN1_OCTET_STRING() returns 1 on successful verification, 0
40otherwise.
41
42The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
43
44=head1 BUGS
45
46These functions serve no recognizable purpose.
47
48=head1 SEE ALSO
49
50L<err(3)|err(3)>, L<objects(3)|objects(3)>, L<rand(3)|rand(3)>,
51L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>,
52L<RSA_verify(3)|RSA_verify(3)>
53
54=head1 HISTORY
55
56RSA_sign_ASN1_OCTET_STRING() and RSA_verify_ASN1_OCTET_STRING() were
57added in SSLeay 0.8.
58
59=cut
diff --git a/src/lib/libcrypto/doc/RSA_size.pod b/src/lib/libcrypto/doc/RSA_size.pod
new file mode 100644
index 0000000000..b36b4d58d5
--- /dev/null
+++ b/src/lib/libcrypto/doc/RSA_size.pod
@@ -0,0 +1,33 @@
1=pod
2
3=head1 NAME
4
5RSA_size - get RSA modulus size
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 int RSA_size(RSA *rsa);
12
13=head1 DESCRIPTION
14
15This function returns the RSA modulus size in bytes. It can be used to
16determine how much memory must be allocated for an RSA encrypted
17value.
18
19B<rsa-E<gt>n> must not be B<NULL>.
20
21=head1 RETURN VALUE
22
23The size in bytes.
24
25=head1 SEE ALSO
26
27L<rsa(3)|rsa(3)>
28
29=head1 HISTORY
30
31RSA_size() is available in all versions of SSLeay and OpenSSL.
32
33=cut
diff --git a/src/lib/libcrypto/doc/bn.pod b/src/lib/libcrypto/doc/bn.pod
new file mode 100644
index 0000000000..1504a1c92d
--- /dev/null
+++ b/src/lib/libcrypto/doc/bn.pod
@@ -0,0 +1,148 @@
1=pod
2
3=head1 NAME
4
5bn - multiprecision integer arithmetics
6
7=head1 SYNOPSIS
8
9 #include <openssl/bn.h>
10
11 BIGNUM *BN_new(void);
12 void BN_free(BIGNUM *a);
13 void BN_init(BIGNUM *);
14 void BN_clear(BIGNUM *a);
15 void BN_clear_free(BIGNUM *a);
16
17 BN_CTX *BN_CTX_new(void);
18 void BN_CTX_init(BN_CTX *c);
19 void BN_CTX_free(BN_CTX *c);
20
21 BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
22 BIGNUM *BN_dup(const BIGNUM *a);
23
24 int BN_num_bytes(const BIGNUM *a);
25 int BN_num_bits(const BIGNUM *a);
26 int BN_num_bits_word(BN_ULONG w);
27
28 int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
29 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
30 int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
31 int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *a, const BIGNUM *d,
32 BN_CTX *ctx);
33 int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx);
34 int BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
35 int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m,
36 BN_CTX *ctx);
37 int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
38 int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
39 const BIGNUM *m, BN_CTX *ctx);
40 int BN_gcd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
41
42 int BN_add_word(BIGNUM *a, BN_ULONG w);
43 int BN_sub_word(BIGNUM *a, BN_ULONG w);
44 int BN_mul_word(BIGNUM *a, BN_ULONG w);
45 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
46 BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
47
48 int BN_cmp(BIGNUM *a, BIGNUM *b);
49 int BN_ucmp(BIGNUM *a, BIGNUM *b);
50 int BN_is_zero(BIGNUM *a);
51 int BN_is_one(BIGNUM *a);
52 int BN_is_word(BIGNUM *a, BN_ULONG w);
53 int BN_is_odd(BIGNUM *a);
54
55 int BN_zero(BIGNUM *a);
56 int BN_one(BIGNUM *a);
57 BIGNUM *BN_value_one(void);
58 int BN_set_word(BIGNUM *a, unsigned long w);
59 unsigned long BN_get_word(BIGNUM *a);
60
61 int BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
62 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom);
63
64 BIGNUM *BN_generate_prime(BIGNUM *ret, int bits,int safe, BIGNUM *add,
65 BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
66 int BN_is_prime(const BIGNUM *p, int nchecks,
67 void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg);
68
69 int BN_set_bit(BIGNUM *a, int n);
70 int BN_clear_bit(BIGNUM *a, int n);
71 int BN_is_bit_set(const BIGNUM *a, int n);
72 int BN_mask_bits(BIGNUM *a, int n);
73 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
74 int BN_lshift1(BIGNUM *r, BIGNUM *a);
75 int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
76 int BN_rshift1(BIGNUM *r, BIGNUM *a);
77
78 int BN_bn2bin(const BIGNUM *a, unsigned char *to);
79 BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
80 char *BN_bn2hex(const BIGNUM *a);
81 char *BN_bn2dec(const BIGNUM *a);
82 int BN_hex2bn(BIGNUM **a, const char *str);
83 int BN_dec2bn(BIGNUM **a, const char *str);
84 int BN_print(BIO *fp, const BIGNUM *a);
85 int BN_print_fp(FILE *fp, const BIGNUM *a);
86 int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
87 BIGNUM *BN_mpi2bn(unsigned char *s, int len, BIGNUM *ret);
88
89 BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
90 BN_CTX *ctx);
91
92 BN_RECP_CTX *BN_RECP_CTX_new(void);
93 void BN_RECP_CTX_init(BN_RECP_CTX *recp);
94 void BN_RECP_CTX_free(BN_RECP_CTX *recp);
95 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
96 int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
97 BN_RECP_CTX *recp, BN_CTX *ctx);
98
99 BN_MONT_CTX *BN_MONT_CTX_new(void);
100 void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
101 void BN_MONT_CTX_free(BN_MONT_CTX *mont);
102 int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
103 BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
104 int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
105 BN_MONT_CTX *mont, BN_CTX *ctx);
106 int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
107 BN_CTX *ctx);
108 int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
109 BN_CTX *ctx);
110
111
112=head1 DESCRIPTION
113
114This library performs arithmetic operations on integers of arbitrary
115size. It was written for use in public key cryptography, such as RSA
116and Diffie-Hellman.
117
118It uses dynamic memory allocation for storing its data structures.
119That means that there is no limit on the size of the numbers
120manipulated by these functions, but return values must always be
121checked in case a memory allocation error has occurred.
122
123The basic object in this library is a B<BIGNUM>. It is used to hold a
124single large integer. This type should be considered opaque and fields
125should not be modified or accessed directly.
126
127The creation of B<BIGNUM> objects is described in L<BN_new(3)|BN_new(3)>;
128L<BN_add(3)|BN_add(3)> describes most of the arithmetic operations.
129Comparison is described in L<BN_cmp(3)|BN_cmp(3)>; L<BN_zero(3)|BN_zero(3)>
130describes certain assignments, L<BN_rand(3)|BN_rand(3)> the generation of
131random numbers, L<BN_generate_prime(3)|BN_generate_prime(3)> deals with prime
132numbers and L<BN_set_bit(3)|BN_set_bit(3)> with bit operations. The conversion
133of B<BIGNUM>s to external formats is described in L<BN_bn2bin(3)|BN_bn2bin(3)>.
134
135=head1 SEE ALSO
136
137L<bn_internal(3)|bn_internal(3)>,
138L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
139L<BN_new(3)|BN_new(3)>, L<BN_CTX_new(3)|BN_CTX_new(3)>,
140L<BN_copy(3)|BN_copy(3)>, L<BN_num_bytes(3)|BN_num_bytes(3)>,
141L<BN_add(3)|BN_add(3)>, L<BN_add_word(3)|BN_add_word(3)>,
142L<BN_cmp(3)|BN_cmp(3)>, L<BN_zero(3)|BN_zero(3)>, L<BN_rand(3)|BN_rand(3)>,
143L<BN_generate_prime(3)|BN_generate_prime(3)>, L<BN_set_bit(3)|BN_set_bit(3)>,
144L<BN_bn2bin(3)|BN_bn2bin(3)>, L<BN_mod_inverse(3)|BN_mod_inverse(3)>,
145L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>,
146L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>
147
148=cut
diff --git a/src/lib/libcrypto/doc/d2i_DHparams.pod b/src/lib/libcrypto/doc/d2i_DHparams.pod
new file mode 100644
index 0000000000..a6d1743d39
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_DHparams.pod
@@ -0,0 +1,30 @@
1=pod
2
3=head1 NAME
4
5d2i_DHparams, i2d_DHparams - ...
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH *d2i_DHparams(DH **a, unsigned char **pp, long length);
12 int i2d_DHparams(DH *a, unsigned char **pp);
13
14=head1 DESCRIPTION
15
16...
17
18=head1 RETURN VALUES
19
20...
21
22=head1 SEE ALSO
23
24...
25
26=head1 HISTORY
27
28...
29
30=cut
diff --git a/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod b/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod
new file mode 100644
index 0000000000..ff4d0d57db
--- /dev/null
+++ b/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod
@@ -0,0 +1,39 @@
1=pod
2
3=head1 NAME
4
5d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey, i2d_Netscape_RSA, d2i_Netscape_RSA - ...
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
12
13 int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
14
15 RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
16
17 int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
18
19 int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
20
21 RSA * d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
22
23=head1 DESCRIPTION
24
25...
26
27=head1 RETURN VALUES
28
29...
30
31=head1 SEE ALSO
32
33...
34
35=head1 HISTORY
36
37...
38
39=cut
diff --git a/src/lib/libcrypto/doc/dh.pod b/src/lib/libcrypto/doc/dh.pod
new file mode 100644
index 0000000000..0a9b7c03a2
--- /dev/null
+++ b/src/lib/libcrypto/doc/dh.pod
@@ -0,0 +1,68 @@
1=pod
2
3=head1 NAME
4
5dh - Diffie-Hellman key agreement
6
7=head1 SYNOPSIS
8
9 #include <openssl/dh.h>
10
11 DH * DH_new(void);
12 void DH_free(DH *dh);
13
14 int DH_size(DH *dh);
15
16 DH * DH_generate_parameters(int prime_len, int generator,
17 void (*callback)(int, int, void *), void *cb_arg);
18 int DH_check(DH *dh, int *codes);
19
20 int DH_generate_key(DH *dh);
21 int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
22
23 void DH_set_default_method(DH_METHOD *meth);
24 DH_METHOD *DH_get_default_method(void);
25 DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
26 DH *DH_new_method(DH_METHOD *meth);
27 DH_METHOD *DH_OpenSSL(void);
28
29 int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(),
30 int (*dup_func)(), void (*free_func)());
31 int DH_set_ex_data(DH *d, int idx, char *arg);
32 char *DH_get_ex_data(DH *d, int idx);
33
34 DH * d2i_DHparams(DH **a, unsigned char **pp, long length);
35 int i2d_DHparams(DH *a, unsigned char **pp);
36
37 int DHparams_print_fp(FILE *fp, DH *x);
38 int DHparams_print(BIO *bp, DH *x);
39
40=head1 DESCRIPTION
41
42These functions implement the Diffie-Hellman key agreement protocol.
43The generation of shared DH parameters is described in
44L<DH_generate_parameters(3)|DH_generate_parameters(3)>; L<DH_generate_key(3)|DH_generate_key(3)> describes how
45to perform a key agreement.
46
47The B<DH> structure consists of several BIGNUM components.
48
49 struct
50 {
51 BIGNUM *p; // prime number (shared)
52 BIGNUM *g; // generator of Z_p (shared)
53 BIGNUM *priv_key; // private DH value x
54 BIGNUM *pub_key; // public DH value g^x
55 // ...
56 };
57 DH
58
59=head1 SEE ALSO
60
61L<dhparam(1)|dhparam(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>,
62L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<DH_set_method(3)|DH_set_method(3)>,
63L<DH_new(3)|DH_new(3)>, L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>,
64L<DH_generate_parameters(3)|DH_generate_parameters(3)>,
65L<DH_compute_key(3)|DH_compute_key(3)>, L<d2i_DHparams(3)|d2i_DHparams(3)>,
66L<RSA_print(3)|RSA_print(3)>
67
68=cut
diff --git a/src/lib/libcrypto/doc/dsa.pod b/src/lib/libcrypto/doc/dsa.pod
new file mode 100644
index 0000000000..2c09244899
--- /dev/null
+++ b/src/lib/libcrypto/doc/dsa.pod
@@ -0,0 +1,104 @@
1=pod
2
3=head1 NAME
4
5dsa - Digital Signature Algorithm
6
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
11 DSA * DSA_new(void);
12 void DSA_free(DSA *dsa);
13
14 int DSA_size(DSA *dsa);
15
16 DSA * DSA_generate_parameters(int bits, unsigned char *seed,
17 int seed_len, int *counter_ret, unsigned long *h_ret,
18 void (*callback)(int, int, void *), void *cb_arg);
19
20 DH * DSA_dup_DH(DSA *r);
21
22 int DSA_generate_key(DSA *dsa);
23
24 int DSA_sign(int dummy, const unsigned char *dgst, int len,
25 unsigned char *sigret, unsigned int *siglen, DSA *dsa);
26 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp,
27 BIGNUM **rp);
28 int DSA_verify(int dummy, const unsigned char *dgst, int len,
29 unsigned char *sigbuf, int siglen, DSA *dsa);
30
31 void DSA_set_default_method(DSA_METHOD *meth);
32 DSA_METHOD *DSA_get_default_method(void);
33 DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth);
34 DSA *DSA_new_method(DSA_METHOD *meth);
35 DSA_METHOD *DSA_OpenSSL(void);
36
37 int DSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
38 int (*dup_func)(), void (*free_func)());
39 int DSA_set_ex_data(DSA *d, int idx, char *arg);
40 char *DSA_get_ex_data(DSA *d, int idx);
41
42 DSA_SIG *DSA_SIG_new(void);
43 void DSA_SIG_free(DSA_SIG *a);
44 int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp);
45 DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
46
47 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
48 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
49 DSA_SIG *sig, DSA *dsa);
50
51 DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
52 DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
53 DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
54 int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
55 int i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
56 int i2d_DSAparams(DSA *a,unsigned char **pp);
57
58 int DSAparams_print(BIO *bp, DSA *x);
59 int DSAparams_print_fp(FILE *fp, DSA *x);
60 int DSA_print(BIO *bp, DSA *x, int off);
61 int DSA_print_fp(FILE *bp, DSA *x, int off);
62
63=head1 DESCRIPTION
64
65These functions implement the Digital Signature Algorithm (DSA). The
66generation of shared DSA parameters is described in
67L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>;
68L<DSA_generate_key(3)|DSA_generate_key(3)> describes how to
69generate a signature key. Signature generation and verification are
70described in L<DSA_sign(3)|DSA_sign(3)>.
71
72The B<DSA> structure consists of several BIGNUM components.
73
74 struct
75 {
76 BIGNUM *p; // prime number (public)
77 BIGNUM *q; // 160-bit subprime, q | p-1 (public)
78 BIGNUM *g; // generator of subgroup (public)
79 BIGNUM *priv_key; // private key x
80 BIGNUM *pub_key; // public key y = g^x
81 // ...
82 }
83 DSA;
84
85In public keys, B<priv_key> is NULL.
86
87=head1 CONFORMING TO
88
89US Federal Information Processing Standard FIPS 186 (Digital Signature
90Standard, DSS), ANSI X9.30
91
92=head1 SEE ALSO
93
94L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
95L<rsa(3)|rsa(3)>, L<sha(3)|sha(3)>, L<DSA_new(3)|DSA_new(3)>,
96L<DSA_size(3)|DSA_size(3)>,
97L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
98L<DSA_dup_DH(3)|DSA_dup_DH(3)>,
99L<DSA_generate_key(3)|DSA_generate_key(3)>,
100L<DSA_sign(3)|DSA_sign(3)>, L<DSA_set_method(3)|DSA_set_method(3)>,
101L<DSA_get_ex_new_index(3)|DSA_get_ex_new_index(3)>,
102L<RSA_print(3)|RSA_print(3)>
103
104=cut
diff --git a/src/lib/libcrypto/doc/lh_stats.pod b/src/lib/libcrypto/doc/lh_stats.pod
new file mode 100644
index 0000000000..3eeaa72e52
--- /dev/null
+++ b/src/lib/libcrypto/doc/lh_stats.pod
@@ -0,0 +1,60 @@
1=pod
2
3=head1 NAME
4
5lh_stats, lh_node_stats, lh_node_usage_stats, lh_stats_bio,
6lh_node_stats_bio, lh_node_usage_stats_bio - LHASH statistics
7
8=head1 SYNOPSIS
9
10 #include <openssl/lhash.h>
11
12 void lh_stats(LHASH *table, FILE *out);
13 void lh_node_stats(LHASH *table, FILE *out);
14 void lh_node_usage_stats(LHASH *table, FILE *out);
15
16 void lh_stats_bio(LHASH *table, BIO *out);
17 void lh_node_stats_bio(LHASH *table, BIO *out);
18 void lh_node_usage_stats_bio(LHASH *table, BIO *out);
19
20=head1 DESCRIPTION
21
22The B<LHASH> structure records statistics about most aspects of
23accessing the hash table. This is mostly a legacy of Eric Young
24writing this library for the reasons of implementing what looked like
25a nice algorithm rather than for a particular software product.
26
27lh_stats() prints out statistics on the size of the hash table, how
28many entries are in it, and the number and result of calls to the
29routines in this library.
30
31lh_node_stats() prints the number of entries for each 'bucket' in the
32hash table.
33
34lh_node_usage_stats() prints out a short summary of the state of the
35hash table. It prints the 'load' and the 'actual load'. The load is
36the average number of data items per 'bucket' in the hash table. The
37'actual load' is the average number of items per 'bucket', but only
38for buckets which contain entries. So the 'actual load' is the
39average number of searches that will need to find an item in the hash
40table, while the 'load' is the average number that will be done to
41record a miss.
42
43lh_stats_bio(), lh_node_stats_bio() and lh_node_usage_stats_bio()
44are the same as the above, except that the output goes to a B<BIO>.
45
46=head1 RETURN VALUES
47
48These functions do not return values.
49
50=head1 SEE ALSO
51
52L<bio(3)|bio(3)>, L<lhash(3)|lhash(3)>
53
54=head1 HISTORY
55
56These functions are available in all versions of SSLeay and OpenSSL.
57
58This manpage is derived from the SSLeay documentation.
59
60=cut
diff --git a/src/lib/libcrypto/doc/rsa.pod b/src/lib/libcrypto/doc/rsa.pod
new file mode 100644
index 0000000000..0486c044a6
--- /dev/null
+++ b/src/lib/libcrypto/doc/rsa.pod
@@ -0,0 +1,115 @@
1=pod
2
3=head1 NAME
4
5rsa - RSA public key cryptosystem
6
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
11 RSA * RSA_new(void);
12 void RSA_free(RSA *rsa);
13
14 int RSA_public_encrypt(int flen, unsigned char *from,
15 unsigned char *to, RSA *rsa, int padding);
16 int RSA_private_decrypt(int flen, unsigned char *from,
17 unsigned char *to, RSA *rsa, int padding);
18
19 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
20 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
21 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
22 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
23
24 int RSA_size(RSA *rsa);
25
26 RSA *RSA_generate_key(int num, unsigned long e,
27 void (*callback)(int,int,void *), void *cb_arg);
28
29 int RSA_check_key(RSA *rsa);
30
31 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
32 void RSA_blinding_off(RSA *rsa);
33
34 void RSA_set_default_method(RSA_METHOD *meth);
35 RSA_METHOD *RSA_get_default_method(void);
36 RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
37 RSA_METHOD *RSA_get_method(RSA *rsa);
38 RSA_METHOD *RSA_PKCS1_SSLeay(void);
39 RSA_METHOD *RSA_PKCS1_RSAref(void);
40 RSA_METHOD *RSA_null_method(void);
41 int RSA_flags(RSA *rsa);
42 RSA *RSA_new_method(RSA_METHOD *method);
43
44 int RSA_print(BIO *bp, RSA *x, int offset);
45 int RSA_print_fp(FILE *fp, RSA *x, int offset);
46
47 int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
48 int (*dup_func)(), void (*free_func)());
49 int RSA_set_ex_data(RSA *r,int idx,char *arg);
50 char *RSA_get_ex_data(RSA *r, int idx);
51
52 int RSA_private_encrypt(int flen, unsigned char *from,
53 unsigned char *to, RSA *rsa,int padding);
54 int RSA_public_decrypt(int flen, unsigned char *from,
55 unsigned char *to, RSA *rsa,int padding);
56
57 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
58 unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
59 RSA *rsa);
60 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
61 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
62 RSA *rsa);
63
64=head1 DESCRIPTION
65
66These functions implement RSA public key encryption and signatures
67as defined in PKCS #1 v2.0 [RFC 2437].
68
69The B<RSA> structure consists of several BIGNUM components. It can
70contain public as well as private RSA keys:
71
72 struct
73 {
74 BIGNUM *n; // public modulus
75 BIGNUM *e; // public exponent
76 BIGNUM *d; // private exponent
77 BIGNUM *p; // secret prime factor
78 BIGNUM *q; // secret prime factor
79 BIGNUM *dmp1; // d mod (p-1)
80 BIGNUM *dmq1; // d mod (q-1)
81 BIGNUM *iqmp; // q^-1 mod p
82 // ...
83 };
84 RSA
85
86In public keys, the private exponent and the related secret values are
87B<NULL>.
88
89B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private keys, but the
90RSA operations are much faster when these values are available.
91
92=head1 CONFORMING TO
93
94SSL, PKCS #1 v2.0
95
96=head1 PATENTS
97
98RSA is covered by a US patent which expires in September 2000.
99
100=head1 SEE ALSO
101
102L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>,
103L<rand(3)|rand(3)>, L<RSA_new(3)|RSA_new(3)>,
104L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
105L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>,
106L<RSA_generate_key(3)|RSA_generate_key(3)>,
107L<RSA_check_key(3)|RSA_check_key(3)>,
108L<RSA_blinding_on(3)|RSA_blinding_on(3)>,
109L<RSA_set_method(3)|RSA_set_method(3)>, L<RSA_print(3)|RSA_print(3)>,
110L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
111L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
112L<RSA_sign_ASN_OCTET_STRING(3)|RSA_sign_ASN_OCTET_STRING(3)>,
113L<RSA_padding_add_PKCS1_type_1(3)|RSA_padding_add_PKCS1_type_1(3)>
114
115=cut
diff --git a/src/lib/libcrypto/dsa/Makefile.ssl b/src/lib/libcrypto/dsa/Makefile.ssl
index 4bc74a2f7c..b0bcf974fb 100644
--- a/src/lib/libcrypto/dsa/Makefile.ssl
+++ b/src/lib/libcrypto/dsa/Makefile.ssl
@@ -22,8 +22,10 @@ TEST=dsatest.c
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c dsa_err.c 25LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c \
26LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o dsa_err.o 26 dsa_err.c dsa_ossl.c
27LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o \
28 dsa_err.o dsa_ossl.o
27 29
28SRC= $(LIBSRC) 30SRC= $(LIBSRC)
29 31
@@ -86,25 +88,27 @@ dsa_asn1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
86dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 88dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
87dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 89dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
88dsa_asn1.o: ../../include/openssl/stack.h ../cryptlib.h 90dsa_asn1.o: ../../include/openssl/stack.h ../cryptlib.h
89dsa_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h 91dsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
90dsa_err.o: ../../include/openssl/dsa.h ../../include/openssl/err.h 92dsa_err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
91dsa_err.o: ../../include/openssl/opensslconf.h 93dsa_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
94dsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
95dsa_err.o: ../../include/openssl/stack.h
92dsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 96dsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
93dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 97dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
94dsa_gen.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 98dsa_gen.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
95dsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 99dsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
96dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 100dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
97dsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 101dsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
98dsa_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 102dsa_gen.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
99dsa_gen.o: ../cryptlib.h 103dsa_gen.o: ../../include/openssl/stack.h ../cryptlib.h
100dsa_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 104dsa_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
101dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 105dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
102dsa_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 106dsa_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
103dsa_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 107dsa_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
104dsa_key.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 108dsa_key.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
105dsa_key.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 109dsa_key.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
106dsa_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 110dsa_key.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
107dsa_key.o: ../cryptlib.h 111dsa_key.o: ../../include/openssl/stack.h ../cryptlib.h
108dsa_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 112dsa_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
109dsa_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 113dsa_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
110dsa_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h 114dsa_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
@@ -113,6 +117,15 @@ dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
113dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 117dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
114dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 118dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
115dsa_lib.o: ../cryptlib.h 119dsa_lib.o: ../cryptlib.h
120dsa_ossl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
121dsa_ossl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
122dsa_ossl.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
123dsa_ossl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
124dsa_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
125dsa_ossl.o: ../../include/openssl/opensslconf.h
126dsa_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
127dsa_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
128dsa_ossl.o: ../cryptlib.h
116dsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 129dsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
117dsa_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 130dsa_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
118dsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h 131dsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
index 20b3f8d90a..68d9912cbc 100644
--- a/src/lib/libcrypto/dsa/dsa.h
+++ b/src/lib/libcrypto/dsa/dsa.h
@@ -74,13 +74,41 @@ extern "C" {
74#endif 74#endif
75 75
76#include <openssl/bn.h> 76#include <openssl/bn.h>
77#include <openssl/crypto.h>
77#ifndef NO_DH 78#ifndef NO_DH
78# include <openssl/dh.h> 79# include <openssl/dh.h>
79#endif 80#endif
80 81
81#define DSA_FLAG_CACHE_MONT_P 0x01 82#define DSA_FLAG_CACHE_MONT_P 0x01
82 83
83typedef struct dsa_st 84typedef struct dsa_st DSA;
85
86typedef struct DSA_SIG_st
87 {
88 BIGNUM *r;
89 BIGNUM *s;
90 } DSA_SIG;
91
92typedef struct dsa_method {
93 const char *name;
94 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
95 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
96 BIGNUM **rp);
97 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
98 DSA_SIG *sig, DSA *dsa);
99 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
100 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
101 BN_MONT_CTX *in_mont);
102 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
103 const BIGNUM *m, BN_CTX *ctx,
104 BN_MONT_CTX *m_ctx); /* Can be null */
105 int (*init)(DSA *dsa);
106 int (*finish)(DSA *dsa);
107 int flags;
108 char *app_data;
109} DSA_METHOD;
110
111struct dsa_st
84 { 112 {
85 /* This first variable is used to pick up errors where 113 /* This first variable is used to pick up errors where
86 * a DSA is passed instead of of a EVP_PKEY */ 114 * a DSA is passed instead of of a EVP_PKEY */
@@ -100,15 +128,10 @@ typedef struct dsa_st
100 int flags; 128 int flags;
101 /* Normally used to cache montgomery values */ 129 /* Normally used to cache montgomery values */
102 char *method_mont_p; 130 char *method_mont_p;
103
104 int references; 131 int references;
105 } DSA; 132 CRYPTO_EX_DATA ex_data;
106 133 DSA_METHOD *meth;
107typedef struct DSA_SIG_st 134 };
108 {
109 BIGNUM *r;
110 BIGNUM *s;
111 } DSA_SIG;
112 135
113#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \ 136#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
114 (char *(*)())d2i_DSAparams,(char *)(x)) 137 (char *(*)())d2i_DSAparams,(char *)(x))
@@ -131,7 +154,14 @@ DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
131int DSA_do_verify(const unsigned char *dgst,int dgst_len, 154int DSA_do_verify(const unsigned char *dgst,int dgst_len,
132 DSA_SIG *sig,DSA *dsa); 155 DSA_SIG *sig,DSA *dsa);
133 156
157DSA_METHOD *DSA_OpenSSL(void);
158
159void DSA_set_default_method(DSA_METHOD *);
160DSA_METHOD *DSA_get_default_method(void);
161DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *);
162
134DSA * DSA_new(void); 163DSA * DSA_new(void);
164DSA * DSA_new_method(DSA_METHOD *meth);
135int DSA_size(DSA *); 165int DSA_size(DSA *);
136 /* next 4 return -1 on error */ 166 /* next 4 return -1 on error */
137int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); 167int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
@@ -140,6 +170,10 @@ int DSA_sign(int type,const unsigned char *dgst,int dlen,
140int DSA_verify(int type,const unsigned char *dgst,int dgst_len, 170int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
141 unsigned char *sigbuf, int siglen, DSA *dsa); 171 unsigned char *sigbuf, int siglen, DSA *dsa);
142void DSA_free (DSA *r); 172void DSA_free (DSA *r);
173int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
174 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
175int DSA_set_ex_data(DSA *d, int idx, void *arg);
176void *DSA_get_ex_data(DSA *d, int idx);
143 177
144void ERR_load_DSA_strings(void ); 178void ERR_load_DSA_strings(void );
145 179
@@ -148,7 +182,7 @@ DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
148DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length); 182DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
149DSA * DSA_generate_parameters(int bits, unsigned char *seed,int seed_len, 183DSA * DSA_generate_parameters(int bits, unsigned char *seed,int seed_len,
150 int *counter_ret, unsigned long *h_ret,void 184 int *counter_ret, unsigned long *h_ret,void
151 (*callback)(),char *cb_arg); 185 (*callback)(int, int, void *),void *cb_arg);
152int DSA_generate_key(DSA *a); 186int DSA_generate_key(DSA *a);
153int i2d_DSAPublicKey(DSA *a, unsigned char **pp); 187int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
154int i2d_DSAPrivateKey(DSA *a, unsigned char **pp); 188int i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
@@ -163,7 +197,11 @@ int DSAparams_print_fp(FILE *fp, DSA *x);
163int DSA_print_fp(FILE *bp, DSA *x, int off); 197int DSA_print_fp(FILE *bp, DSA *x, int off);
164#endif 198#endif
165 199
166int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg); 200#define DSS_prime_checks 50
201/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:
202 * 50 rounds of Rabin-Miller */
203#define DSA_is_prime(n, callback, cb_arg) \
204 BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
167 205
168#ifndef NO_DH 206#ifndef NO_DH
169/* Convert DSA structure (key or just parameters) into DH structure 207/* Convert DSA structure (key or just parameters) into DH structure
@@ -184,7 +222,6 @@ DH *DSA_dup_DH(DSA *r);
184#define DSA_F_DSAPARAMS_PRINT_FP 101 222#define DSA_F_DSAPARAMS_PRINT_FP 101
185#define DSA_F_DSA_DO_SIGN 112 223#define DSA_F_DSA_DO_SIGN 112
186#define DSA_F_DSA_DO_VERIFY 113 224#define DSA_F_DSA_DO_VERIFY 113
187#define DSA_F_DSA_IS_PRIME 102
188#define DSA_F_DSA_NEW 103 225#define DSA_F_DSA_NEW 103
189#define DSA_F_DSA_PRINT 104 226#define DSA_F_DSA_PRINT 104
190#define DSA_F_DSA_PRINT_FP 105 227#define DSA_F_DSA_PRINT_FP 105
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
index 7523b21654..c9b32b4db7 100644
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ b/src/lib/libcrypto/dsa/dsa_asn1.c
@@ -83,7 +83,7 @@ DSA_SIG *d2i_DSA_SIG(DSA_SIG **a, unsigned char **pp, long length)
83 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); 83 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
84 if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL) 84 if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL)
85 goto err_bn; 85 goto err_bn;
86 ASN1_BIT_STRING_free(bs); 86 M_ASN1_BIT_STRING_free(bs);
87 M_ASN1_D2I_Finish_2(a); 87 M_ASN1_D2I_Finish_2(a);
88 88
89err_bn: 89err_bn:
@@ -91,6 +91,6 @@ err_bn:
91err: 91err:
92 DSAerr(DSA_F_D2I_DSA_SIG,i); 92 DSAerr(DSA_F_D2I_DSA_SIG,i);
93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret); 93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret);
94 if (bs != NULL) ASN1_BIT_STRING_free(bs); 94 if (bs != NULL) M_ASN1_BIT_STRING_free(bs);
95 return(NULL); 95 return(NULL);
96} 96}
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
index 33a8270afd..38e4af968c 100644
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ b/src/lib/libcrypto/dsa/dsa_err.c
@@ -70,7 +70,6 @@ static ERR_STRING_DATA DSA_str_functs[]=
70{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"}, 70{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"},
71{ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"}, 71{ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"},
72{ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"}, 72{ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"},
73{ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"},
74{ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"}, 73{ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"},
75{ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"}, 74{ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"},
76{ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"}, 75{ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"},
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
index b5e5ec06e5..2294a362d9 100644
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ b/src/lib/libcrypto/dsa/dsa_gen.c
@@ -59,12 +59,18 @@
59#undef GENUINE_DSA 59#undef GENUINE_DSA
60 60
61#ifdef GENUINE_DSA 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) */
62#define HASH SHA 64#define HASH SHA
63#else 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) */
64#define HASH SHA1 69#define HASH SHA1
65#endif 70#endif
66 71
67#ifndef NO_SHA 72#ifndef NO_SHA
73
68#include <stdio.h> 74#include <stdio.h>
69#include <time.h> 75#include <time.h>
70#include "cryptlib.h" 76#include "cryptlib.h"
@@ -74,8 +80,9 @@
74#include <openssl/rand.h> 80#include <openssl/rand.h>
75 81
76DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, 82DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
77 int *counter_ret, unsigned long *h_ret, void (*callback)(), 83 int *counter_ret, unsigned long *h_ret,
78 char *cb_arg) 84 void (*callback)(int, int, void *),
85 void *cb_arg)
79 { 86 {
80 int ok=0; 87 int ok=0;
81 unsigned char seed[SHA_DIGEST_LENGTH]; 88 unsigned char seed[SHA_DIGEST_LENGTH];
@@ -86,47 +93,63 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
86 BN_MONT_CTX *mont=NULL; 93 BN_MONT_CTX *mont=NULL;
87 int k,n=0,i,b,m=0; 94 int k,n=0,i,b,m=0;
88 int counter=0; 95 int counter=0;
89 BN_CTX *ctx=NULL,*ctx2=NULL; 96 int r=0;
97 BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL;
90 unsigned int h=2; 98 unsigned int h=2;
91 DSA *ret=NULL; 99 DSA *ret=NULL;
92 100
93 if (bits < 512) bits=512; 101 if (bits < 512) bits=512;
94 bits=(bits+63)/64*64; 102 bits=(bits+63)/64*64;
95 103
104 if (seed_len < 20)
105 seed_in = NULL; /* seed buffer too small -- ignore */
106 if (seed_len > 20)
107 seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
108 * but our internal buffers are restricted to 160 bits*/
96 if ((seed_in != NULL) && (seed_len == 20)) 109 if ((seed_in != NULL) && (seed_len == 20))
97 memcpy(seed,seed_in,seed_len); 110 memcpy(seed,seed_in,seed_len);
98 111
99 if ((ctx=BN_CTX_new()) == NULL) goto err; 112 if ((ctx=BN_CTX_new()) == NULL) goto err;
100 if ((ctx2=BN_CTX_new()) == NULL) goto err; 113 if ((ctx2=BN_CTX_new()) == NULL) goto err;
114 if ((ctx3=BN_CTX_new()) == NULL) goto err;
101 if ((ret=DSA_new()) == NULL) goto err; 115 if ((ret=DSA_new()) == NULL) goto err;
102 116
103 if ((mont=BN_MONT_CTX_new()) == NULL) goto err; 117 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
104 118
105 r0= &(ctx2->bn[0]); 119 BN_CTX_start(ctx2);
106 g= &(ctx2->bn[1]); 120 r0 = BN_CTX_get(ctx2);
107 W= &(ctx2->bn[2]); 121 g = BN_CTX_get(ctx2);
108 q= &(ctx2->bn[3]); 122 W = BN_CTX_get(ctx2);
109 X= &(ctx2->bn[4]); 123 q = BN_CTX_get(ctx2);
110 c= &(ctx2->bn[5]); 124 X = BN_CTX_get(ctx2);
111 p= &(ctx2->bn[6]); 125 c = BN_CTX_get(ctx2);
112 test= &(ctx2->bn[7]); 126 p = BN_CTX_get(ctx2);
127 test = BN_CTX_get(ctx2);
113 128
114 BN_lshift(test,BN_value_one(),bits-1); 129 BN_lshift(test,BN_value_one(),bits-1);
115 130
116 for (;;) 131 for (;;)
117 { 132 {
118 for (;;) 133 for (;;) /* find q */
119 { 134 {
135 int seed_is_random;
136
120 /* step 1 */ 137 /* step 1 */
121 if (callback != NULL) callback(0,m++,cb_arg); 138 if (callback != NULL) callback(0,m++,cb_arg);
122 139
123 if (!seed_len) 140 if (!seed_len)
124 RAND_bytes(seed,SHA_DIGEST_LENGTH); 141 {
142 RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH);
143 seed_is_random = 1;
144 }
125 else 145 else
126 seed_len=0; 146 {
127 147 seed_is_random = 0;
148 seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
149 }
128 memcpy(buf,seed,SHA_DIGEST_LENGTH); 150 memcpy(buf,seed,SHA_DIGEST_LENGTH);
129 memcpy(buf2,seed,SHA_DIGEST_LENGTH); 151 memcpy(buf2,seed,SHA_DIGEST_LENGTH);
152 /* precompute "SEED + 1" for step 7: */
130 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--) 153 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
131 { 154 {
132 buf[i]++; 155 buf[i]++;
@@ -142,10 +165,15 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
142 /* step 3 */ 165 /* step 3 */
143 md[0]|=0x80; 166 md[0]|=0x80;
144 md[SHA_DIGEST_LENGTH-1]|=0x01; 167 md[SHA_DIGEST_LENGTH-1]|=0x01;
145 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) abort(); 168 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
146 169
147 /* step 4 */ 170 /* step 4 */
148 if (DSA_is_prime(q,callback,cb_arg) > 0) break; 171 r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, cb_arg, seed_is_random);
172 if (r > 0)
173 break;
174 if (r != 0)
175 goto err;
176
149 /* do a callback call */ 177 /* do a callback call */
150 /* step 5 */ 178 /* step 5 */
151 } 179 }
@@ -155,16 +183,22 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
155 183
156 /* step 6 */ 184 /* step 6 */
157 counter=0; 185 counter=0;
186 /* "offset = 2" */
158 187
159 n=(bits-1)/160; 188 n=(bits-1)/160;
160 b=(bits-1)-n*160; 189 b=(bits-1)-n*160;
161 190
162 for (;;) 191 for (;;)
163 { 192 {
193 if (callback != NULL && counter != 0)
194 callback(0,counter,cb_arg);
195
164 /* step 7 */ 196 /* step 7 */
165 BN_zero(W); 197 BN_zero(W);
198 /* now 'buf' contains "SEED + offset - 1" */
166 for (k=0; k<=n; k++) 199 for (k=0; k<=n; k++)
167 { 200 {
201 /* obtain "SEED + offset + k" by incrementing: */
168 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--) 202 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
169 { 203 {
170 buf[i]++; 204 buf[i]++;
@@ -174,7 +208,8 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
174 HASH(buf,SHA_DIGEST_LENGTH,md); 208 HASH(buf,SHA_DIGEST_LENGTH,md);
175 209
176 /* step 8 */ 210 /* step 8 */
177 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0)) abort(); 211 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
212 goto err;
178 BN_lshift(r0,r0,160*k); 213 BN_lshift(r0,r0,160*k);
179 BN_add(W,W,r0); 214 BN_add(W,W,r0);
180 } 215 }
@@ -194,23 +229,25 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
194 if (BN_cmp(p,test) >= 0) 229 if (BN_cmp(p,test) >= 0)
195 { 230 {
196 /* step 11 */ 231 /* step 11 */
197 if (DSA_is_prime(p,callback,cb_arg) > 0) 232 r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, cb_arg, 1);
198 goto end; 233 if (r > 0)
234 goto end; /* found it */
235 if (r != 0)
236 goto err;
199 } 237 }
200 238
201 /* step 13 */ 239 /* step 13 */
202 counter++; 240 counter++;
241 /* "offset = offset + n + 1" */
203 242
204 /* step 14 */ 243 /* step 14 */
205 if (counter >= 4096) break; 244 if (counter >= 4096) break;
206
207 if (callback != NULL) callback(0,counter,cb_arg);
208 } 245 }
209 } 246 }
210end: 247end:
211 if (callback != NULL) callback(2,1,cb_arg); 248 if (callback != NULL) callback(2,1,cb_arg);
212 249
213 /* We now need to gernerate g */ 250 /* We now need to generate g */
214 /* Set r0=(p-1)/q */ 251 /* Set r0=(p-1)/q */
215 BN_sub(test,p,BN_value_one()); 252 BN_sub(test,p,BN_value_one());
216 BN_div(r0,NULL,test,q,ctx); 253 BN_div(r0,NULL,test,q,ctx);
@@ -245,89 +282,13 @@ err:
245 if (h_ret != NULL) *h_ret=h; 282 if (h_ret != NULL) *h_ret=h;
246 } 283 }
247 if (ctx != NULL) BN_CTX_free(ctx); 284 if (ctx != NULL) BN_CTX_free(ctx);
248 if (ctx != NULL) BN_CTX_free(ctx2); 285 if (ctx2 != NULL)
249 if (mont != NULL) BN_MONT_CTX_free(mont);
250 return(ok?ret:NULL);
251 }
252
253int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg)
254 {
255 int ok= -1,j,i,n;
256 BN_CTX *ctx=NULL,*ctx2=NULL;
257 BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1;
258 int a;
259 BN_MONT_CTX *mont=NULL;
260
261 if (!BN_is_bit_set(w,0)) return(0);
262
263 if ((ctx=BN_CTX_new()) == NULL) goto err;
264 if ((ctx2=BN_CTX_new()) == NULL) goto err;
265 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
266
267 m= &(ctx2->bn[2]);
268 b= &(ctx2->bn[3]);
269 z= &(ctx2->bn[4]);
270 w_1= &(ctx2->bn[5]);
271 tmp= &(ctx2->bn[6]);
272 mont_1= &(ctx2->bn[7]);
273
274 /* step 1 */
275 n=50;
276
277 /* step 2 */
278 if (!BN_sub(w_1,w,BN_value_one())) goto err;
279 for (a=1; !BN_is_bit_set(w_1,a); a++)
280 ;
281 if (!BN_rshift(m,w_1,a)) goto err;
282
283 BN_MONT_CTX_set(mont,w,ctx);
284 BN_to_montgomery(mont_1,BN_value_one(),mont,ctx);
285 BN_to_montgomery(w_1,w_1,mont,ctx);
286 for (i=1; i < n; i++)
287 { 286 {
288 /* step 3 */ 287 BN_CTX_end(ctx2);
289 BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0); 288 BN_CTX_free(ctx2);
290 /* BN_set_word(b,0x10001L); */
291
292 /* step 4 */
293 j=0;
294 if (!BN_mod_exp_mont(z,b,m,w,ctx,mont)) goto err;
295
296 if (!BN_to_montgomery(z,z,mont,ctx)) goto err;
297
298 /* step 5 */
299 for (;;)
300 {
301 if (((j == 0) && (BN_cmp(z,mont_1) == 0)) ||
302 (BN_cmp(z,w_1) == 0))
303 break;
304
305 /* step 6 */
306 if ((j > 0) && (BN_cmp(z,mont_1) == 0))
307 {
308 ok=0;
309 goto err;
310 }
311
312 j++;
313 if (j >= a)
314 {
315 ok=0;
316 goto err;
317 }
318
319 if (!BN_mod_mul_montgomery(z,z,z,mont,ctx)) goto err;
320 if (callback != NULL) callback(1,j,cb_arg);
321 }
322 } 289 }
323 290 if (ctx3 != NULL) BN_CTX_free(ctx3);
324 ok=1; 291 if (mont != NULL) BN_MONT_CTX_free(mont);
325err: 292 return(ok?ret:NULL);
326 if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB);
327 BN_CTX_free(ctx);
328 BN_CTX_free(ctx2);
329 BN_MONT_CTX_free(mont);
330
331 return(ok);
332 } 293 }
333#endif 294#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index ce8e204f7e..224e412afc 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -66,7 +66,38 @@
66 66
67const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; 67const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT;
68 68
69static DSA_METHOD *default_DSA_method;
70static int dsa_meth_num = 0;
71static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dsa_meth = NULL;
72
73void DSA_set_default_method(DSA_METHOD *meth)
74{
75 default_DSA_method = meth;
76}
77
78DSA_METHOD *DSA_get_default_method(void)
79{
80 if(!default_DSA_method) default_DSA_method = DSA_OpenSSL();
81 return default_DSA_method;
82}
83
69DSA *DSA_new(void) 84DSA *DSA_new(void)
85{
86 return DSA_new_method(NULL);
87}
88
89DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth)
90{
91 DSA_METHOD *mtmp;
92 mtmp = dsa->meth;
93 if (mtmp->finish) mtmp->finish(dsa);
94 dsa->meth = meth;
95 if (meth->init) meth->init(dsa);
96 return mtmp;
97}
98
99
100DSA *DSA_new_method(DSA_METHOD *meth)
70 { 101 {
71 DSA *ret; 102 DSA *ret;
72 103
@@ -76,13 +107,15 @@ DSA *DSA_new(void)
76 DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE); 107 DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE);
77 return(NULL); 108 return(NULL);
78 } 109 }
110 if(!default_DSA_method) default_DSA_method = DSA_OpenSSL();
111 if(meth) ret->meth = meth;
112 else ret->meth = default_DSA_method;
79 ret->pad=0; 113 ret->pad=0;
80 ret->version=0; 114 ret->version=0;
81 ret->write_params=1; 115 ret->write_params=1;
82 ret->p=NULL; 116 ret->p=NULL;
83 ret->q=NULL; 117 ret->q=NULL;
84 ret->g=NULL; 118 ret->g=NULL;
85 ret->flags=DSA_FLAG_CACHE_MONT_P;
86 119
87 ret->pub_key=NULL; 120 ret->pub_key=NULL;
88 ret->priv_key=NULL; 121 ret->priv_key=NULL;
@@ -92,6 +125,15 @@ DSA *DSA_new(void)
92 ret->method_mont_p=NULL; 125 ret->method_mont_p=NULL;
93 126
94 ret->references=1; 127 ret->references=1;
128 ret->flags=ret->meth->flags;
129 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
130 {
131 Free(ret);
132 ret=NULL;
133 }
134 else
135 CRYPTO_new_ex_data(dsa_meth,ret,&ret->ex_data);
136
95 return(ret); 137 return(ret);
96 } 138 }
97 139
@@ -114,6 +156,10 @@ void DSA_free(DSA *r)
114 } 156 }
115#endif 157#endif
116 158
159 CRYPTO_free_ex_data(dsa_meth, r, &r->ex_data);
160
161 if(r->meth->finish) r->meth->finish(r);
162
117 if (r->p != NULL) BN_clear_free(r->p); 163 if (r->p != NULL) BN_clear_free(r->p);
118 if (r->q != NULL) BN_clear_free(r->q); 164 if (r->q != NULL) BN_clear_free(r->q);
119 if (r->g != NULL) BN_clear_free(r->g); 165 if (r->g != NULL) BN_clear_free(r->g);
@@ -121,8 +167,6 @@ void DSA_free(DSA *r)
121 if (r->priv_key != NULL) BN_clear_free(r->priv_key); 167 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
122 if (r->kinv != NULL) BN_clear_free(r->kinv); 168 if (r->kinv != NULL) BN_clear_free(r->kinv);
123 if (r->r != NULL) BN_clear_free(r->r); 169 if (r->r != NULL) BN_clear_free(r->r);
124 if (r->method_mont_p != NULL)
125 BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p);
126 Free(r); 170 Free(r);
127 } 171 }
128 172
@@ -145,6 +189,24 @@ int DSA_size(DSA *r)
145 return(ret); 189 return(ret);
146 } 190 }
147 191
192int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
193 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
194 {
195 dsa_meth_num++;
196 return(CRYPTO_get_ex_new_index(dsa_meth_num-1,
197 &dsa_meth,argl,argp,new_func,dup_func,free_func));
198 }
199
200int DSA_set_ex_data(DSA *d, int idx, void *arg)
201 {
202 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
203 }
204
205void *DSA_get_ex_data(DSA *d, int idx)
206 {
207 return(CRYPTO_get_ex_data(&d->ex_data,idx));
208 }
209
148#ifndef NO_DH 210#ifndef NO_DH
149DH *DSA_dup_DH(DSA *r) 211DH *DSA_dup_DH(DSA *r)
150 { 212 {
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
new file mode 100644
index 0000000000..b51cf6ad8d
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsa_ossl.c
@@ -0,0 +1,321 @@
1/* crypto/dsa/dsa_ossl.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67
68static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
69static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
70static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
71 DSA *dsa);
72static int dsa_init(DSA *dsa);
73static int dsa_finish(DSA *dsa);
74static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
75 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
76 BN_MONT_CTX *in_mont);
77static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
78 const BIGNUM *m, BN_CTX *ctx,
79 BN_MONT_CTX *m_ctx);
80
81static DSA_METHOD openssl_dsa_meth = {
82"OpenSSL DSA method",
83dsa_do_sign,
84dsa_sign_setup,
85dsa_do_verify,
86dsa_mod_exp,
87dsa_bn_mod_exp,
88dsa_init,
89dsa_finish,
900,
91NULL
92};
93
94DSA_METHOD *DSA_OpenSSL(void)
95{
96 return &openssl_dsa_meth;
97}
98
99static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
100 {
101 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
102 BIGNUM m;
103 BIGNUM xr;
104 BN_CTX *ctx=NULL;
105 int i,reason=ERR_R_BN_LIB;
106 DSA_SIG *ret=NULL;
107
108 BN_init(&m);
109 BN_init(&xr);
110 s=BN_new();
111 if (s == NULL) goto err;
112
113 i=BN_num_bytes(dsa->q); /* should be 20 */
114 if ((dlen > i) || (dlen > 50))
115 {
116 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
117 goto err;
118 }
119
120 ctx=BN_CTX_new();
121 if (ctx == NULL) goto err;
122
123 if ((dsa->kinv == NULL) || (dsa->r == NULL))
124 {
125 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
126 }
127 else
128 {
129 kinv=dsa->kinv;
130 dsa->kinv=NULL;
131 r=dsa->r;
132 dsa->r=NULL;
133 }
134
135 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
136
137 /* Compute s = inv(k) (m + xr) mod q */
138 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
139 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
140 if (BN_cmp(s,dsa->q) > 0)
141 BN_sub(s,s,dsa->q);
142 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
143
144 ret=DSA_SIG_new();
145 if (ret == NULL) goto err;
146 ret->r = r;
147 ret->s = s;
148
149err:
150 if (!ret)
151 {
152 DSAerr(DSA_F_DSA_DO_SIGN,reason);
153 BN_free(r);
154 BN_free(s);
155 }
156 if (ctx != NULL) BN_CTX_free(ctx);
157 BN_clear_free(&m);
158 BN_clear_free(&xr);
159 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
160 BN_clear_free(kinv);
161 return(ret);
162 }
163
164static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
165 {
166 BN_CTX *ctx;
167 BIGNUM k,*kinv=NULL,*r=NULL;
168 int ret=0;
169
170 if (ctx_in == NULL)
171 {
172 if ((ctx=BN_CTX_new()) == NULL) goto err;
173 }
174 else
175 ctx=ctx_in;
176
177 BN_init(&k);
178 if ((r=BN_new()) == NULL) goto err;
179 kinv=NULL;
180
181 /* Get random k */
182 for (;;)
183 {
184 if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err;
185 if (BN_cmp(&k,dsa->q) >= 0)
186 BN_sub(&k,&k,dsa->q);
187 if (!BN_is_zero(&k)) break;
188 }
189
190 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
191 {
192 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
193 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
194 dsa->p,ctx)) goto err;
195 }
196
197 /* Compute r = (g^k mod p) mod q */
198 if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx,
199 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
200 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
201
202 /* Compute part of 's = inv(k) (m + xr) mod q' */
203 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
204
205 if (*kinvp != NULL) BN_clear_free(*kinvp);
206 *kinvp=kinv;
207 kinv=NULL;
208 if (*rp != NULL) BN_clear_free(*rp);
209 *rp=r;
210 ret=1;
211err:
212 if (!ret)
213 {
214 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
215 if (kinv != NULL) BN_clear_free(kinv);
216 if (r != NULL) BN_clear_free(r);
217 }
218 if (ctx_in == NULL) BN_CTX_free(ctx);
219 if (kinv != NULL) BN_clear_free(kinv);
220 BN_clear_free(&k);
221 return(ret);
222 }
223
224static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
225 DSA *dsa)
226 {
227 BN_CTX *ctx;
228 BIGNUM u1,u2,t1;
229 BN_MONT_CTX *mont=NULL;
230 int ret = -1;
231
232 if ((ctx=BN_CTX_new()) == NULL) goto err;
233 BN_init(&u1);
234 BN_init(&u2);
235 BN_init(&t1);
236
237 /* Calculate W = inv(S) mod Q
238 * save W in u2 */
239 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
240
241 /* save M in u1 */
242 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
243
244 /* u1 = M * w mod q */
245 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
246
247 /* u2 = r * w mod q */
248 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
249
250 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
251 {
252 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
253 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
254 dsa->p,ctx)) goto err;
255 }
256 mont=(BN_MONT_CTX *)dsa->method_mont_p;
257
258#if 0
259 {
260 BIGNUM t2;
261
262 BN_init(&t2);
263 /* v = ( g^u1 * y^u2 mod p ) mod q */
264 /* let t1 = g ^ u1 mod p */
265 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
266 /* let t2 = y ^ u2 mod p */
267 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
268 /* let u1 = t1 * t2 mod p */
269 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
270 BN_free(&t2);
271 }
272 /* let u1 = u1 mod q */
273 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
274#else
275 {
276 if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
277 dsa->p,ctx,mont)) goto err;
278 /* BN_copy(&u1,&t1); */
279 /* let u1 = u1 mod q */
280 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
281 }
282#endif
283 /* V is now in u1. If the signature is correct, it will be
284 * equal to R. */
285 ret=(BN_ucmp(&u1, sig->r) == 0);
286
287 err:
288 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
289 if (ctx != NULL) BN_CTX_free(ctx);
290 BN_free(&u1);
291 BN_free(&u2);
292 BN_free(&t1);
293 return(ret);
294 }
295
296static int dsa_init(DSA *dsa)
297{
298 dsa->flags|=DSA_FLAG_CACHE_MONT_P;
299 return(1);
300}
301
302static int dsa_finish(DSA *dsa)
303{
304 if(dsa->method_mont_p)
305 BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
306 return(1);
307}
308
309static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
310 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
311 BN_MONT_CTX *in_mont)
312{
313 return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
314}
315
316static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
317 const BIGNUM *m, BN_CTX *ctx,
318 BN_MONT_CTX *m_ctx)
319{
320 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
321}
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
index 774c161964..89205026f0 100644
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ b/src/lib/libcrypto/dsa/dsa_sign.c
@@ -67,73 +67,9 @@
67 67
68DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) 68DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
69 { 69 {
70 BIGNUM *kinv=NULL,*r=NULL,*s=NULL; 70 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
71 BIGNUM m;
72 BIGNUM xr;
73 BN_CTX *ctx=NULL;
74 int i,reason=ERR_R_BN_LIB;
75 DSA_SIG *ret=NULL;
76
77 BN_init(&m);
78 BN_init(&xr);
79 s=BN_new();
80 if (s == NULL) goto err;
81
82 i=BN_num_bytes(dsa->q); /* should be 20 */
83 if ((dlen > i) || (dlen > 50))
84 {
85 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
86 goto err;
87 }
88
89 ctx=BN_CTX_new();
90 if (ctx == NULL) goto err;
91
92 if ((dsa->kinv == NULL) || (dsa->r == NULL))
93 {
94 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
95 }
96 else
97 {
98 kinv=dsa->kinv;
99 dsa->kinv=NULL;
100 r=dsa->r;
101 dsa->r=NULL;
102 }
103
104 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
105
106 /* Compute s = inv(k) (m + xr) mod q */
107 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
108 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
109 if (BN_cmp(s,dsa->q) > 0)
110 BN_sub(s,s,dsa->q);
111 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
112
113 ret=DSA_SIG_new();
114 if (ret == NULL) goto err;
115 ret->r = r;
116 ret->s = s;
117
118err:
119 if (!ret)
120 {
121 DSAerr(DSA_F_DSA_DO_SIGN,reason);
122 BN_free(r);
123 BN_free(s);
124 }
125 if (ctx != NULL) BN_CTX_free(ctx);
126 BN_clear_free(&m);
127 BN_clear_free(&xr);
128 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
129 BN_clear_free(kinv);
130 return(ret);
131 } 71 }
132 72
133/* data has already been hashed (probably with SHA or SHA-1). */
134
135/* unsigned char *sig: out */
136/* unsigned int *siglen: out */
137int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, 73int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
138 unsigned int *siglen, DSA *dsa) 74 unsigned int *siglen, DSA *dsa)
139 { 75 {
@@ -151,61 +87,6 @@ int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
151 87
152int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) 88int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
153 { 89 {
154 BN_CTX *ctx; 90 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
155 BIGNUM k,*kinv=NULL,*r=NULL;
156 int ret=0;
157
158 if (ctx_in == NULL)
159 {
160 if ((ctx=BN_CTX_new()) == NULL) goto err;
161 }
162 else
163 ctx=ctx_in;
164
165 BN_init(&k);
166 if ((r=BN_new()) == NULL) goto err;
167 kinv=NULL;
168
169 /* Get random k */
170 for (;;)
171 {
172 if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err;
173 if (BN_cmp(&k,dsa->q) >= 0)
174 BN_sub(&k,&k,dsa->q);
175 if (!BN_is_zero(&k)) break;
176 }
177
178 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
179 {
180 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
181 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
182 dsa->p,ctx)) goto err;
183 }
184
185 /* Compute r = (g^k mod p) mod q */
186 if (!BN_mod_exp_mont(r,dsa->g,&k,dsa->p,ctx,
187 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
188 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
189
190 /* Compute part of 's = inv(k) (m + xr) mod q' */
191 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
192
193 if (*kinvp != NULL) BN_clear_free(*kinvp);
194 *kinvp=kinv;
195 kinv=NULL;
196 if (*rp != NULL) BN_clear_free(*rp);
197 *rp=r;
198 ret=1;
199err:
200 if (!ret)
201 {
202 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
203 if (kinv != NULL) BN_clear_free(kinv);
204 if (r != NULL) BN_clear_free(r);
205 }
206 if (ctx_in == NULL) BN_CTX_free(ctx);
207 if (kinv != NULL) BN_clear_free(kinv);
208 BN_clear_free(&k);
209 return(ret);
210 } 91 }
211 92
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
index ff552208aa..03277f80fd 100644
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ b/src/lib/libcrypto/dsa/dsa_vrf.c
@@ -69,73 +69,7 @@
69int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, 69int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
70 DSA *dsa) 70 DSA *dsa)
71 { 71 {
72 BN_CTX *ctx; 72 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
73 BIGNUM u1,u2,t1;
74 BN_MONT_CTX *mont=NULL;
75 int ret = -1;
76
77 if ((ctx=BN_CTX_new()) == NULL) goto err;
78 BN_init(&u1);
79 BN_init(&u2);
80 BN_init(&t1);
81
82 /* Calculate W = inv(S) mod Q
83 * save W in u2 */
84 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
85
86 /* save M in u1 */
87 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
88
89 /* u1 = M * w mod q */
90 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
91
92 /* u2 = r * w mod q */
93 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
94
95 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
96 {
97 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
98 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
99 dsa->p,ctx)) goto err;
100 }
101 mont=(BN_MONT_CTX *)dsa->method_mont_p;
102
103#if 0
104 {
105 BIGNUM t2;
106
107 BN_init(&t2);
108 /* v = ( g^u1 * y^u2 mod p ) mod q */
109 /* let t1 = g ^ u1 mod p */
110 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
111 /* let t2 = y ^ u2 mod p */
112 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
113 /* let u1 = t1 * t2 mod p */
114 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
115 BN_free(&t2);
116 }
117 /* let u1 = u1 mod q */
118 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
119#else
120 {
121 if (!BN_mod_exp2_mont(&t1,dsa->g,&u1,dsa->pub_key,&u2,dsa->p,ctx,mont))
122 goto err;
123 /* BN_copy(&u1,&t1); */
124 /* let u1 = u1 mod q */
125 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
126 }
127#endif
128 /* V is now in u1. If the signature is correct, it will be
129 * equal to R. */
130 ret=(BN_ucmp(&u1, sig->r) == 0);
131
132 err:
133 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
134 if (ctx != NULL) BN_CTX_free(ctx);
135 BN_free(&u1);
136 BN_free(&u2);
137 BN_free(&t1);
138 return(ret);
139 } 73 }
140 74
141/* data has already been hashed (probably with SHA or SHA-1). */ 75/* data has already been hashed (probably with SHA or SHA-1). */
diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c
index fc25c9a1b7..309a7cda89 100644
--- a/src/lib/libcrypto/dsa/dsatest.c
+++ b/src/lib/libcrypto/dsa/dsatest.c
@@ -84,7 +84,10 @@ int main(int argc, char *argv[])
84#define MS_CALLBACK 84#define MS_CALLBACK
85#endif 85#endif
86 86
87static void MS_CALLBACK dsa_cb(int p, int n, char *arg); 87static void MS_CALLBACK dsa_cb(int p, int n, void *arg);
88
89/* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to
90 * FIPS PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1 */
88static unsigned char seed[20]={ 91static unsigned char seed[20]={
89 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, 92 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40,
90 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, 93 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3,
@@ -120,6 +123,8 @@ static unsigned char out_g[]={
120 123
121static const unsigned char str1[]="12345678901234567890"; 124static const unsigned char str1[]="12345678901234567890";
122 125
126static const char rnd_seed[] = "string to make the random number generator think it has entropy";
127
123static BIO *bio_err=NULL; 128static BIO *bio_err=NULL;
124 129
125int main(int argc, char **argv) 130int main(int argc, char **argv)
@@ -131,15 +136,17 @@ int main(int argc, char **argv)
131 unsigned char sig[256]; 136 unsigned char sig[256];
132 unsigned int siglen; 137 unsigned int siglen;
133 138
139 ERR_load_crypto_strings();
140 RAND_seed(rnd_seed, sizeof rnd_seed);
141
134 if (bio_err == NULL) 142 if (bio_err == NULL)
135 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 143 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
136 144
137 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); 145 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
138 146
139 BIO_printf(bio_err,"test generation of DSA parameters\n"); 147 BIO_printf(bio_err,"test generation of DSA parameters\n");
140 BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n"); 148
141 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, 149 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,bio_err);
142 (char *)bio_err);
143 150
144 BIO_printf(bio_err,"seed\n"); 151 BIO_printf(bio_err,"seed\n");
145 for (i=0; i<20; i+=4) 152 for (i=0; i<20; i+=4)
@@ -193,13 +200,18 @@ end:
193 if (!ret) 200 if (!ret)
194 ERR_print_errors(bio_err); 201 ERR_print_errors(bio_err);
195 if (dsa != NULL) DSA_free(dsa); 202 if (dsa != NULL) DSA_free(dsa);
203 ERR_remove_state(0);
196 CRYPTO_mem_leaks(bio_err); 204 CRYPTO_mem_leaks(bio_err);
197 if (bio_err != NULL) BIO_free(bio_err); 205 if (bio_err != NULL)
206 {
207 BIO_free(bio_err);
208 bio_err = NULL;
209 }
198 exit(!ret); 210 exit(!ret);
199 return(0); 211 return(0);
200 } 212 }
201 213
202static void MS_CALLBACK dsa_cb(int p, int n, char *arg) 214static void MS_CALLBACK dsa_cb(int p, int n, void *arg)
203 { 215 {
204 char c='*'; 216 char c='*';
205 static int ok=0,num=0; 217 static int ok=0,num=0;
@@ -208,8 +220,8 @@ static void MS_CALLBACK dsa_cb(int p, int n, char *arg)
208 if (p == 1) c='+'; 220 if (p == 1) c='+';
209 if (p == 2) { c='*'; ok++; } 221 if (p == 2) { c='*'; ok++; }
210 if (p == 3) c='\n'; 222 if (p == 3) c='\n';
211 BIO_write((BIO *)arg,&c,1); 223 BIO_write(arg,&c,1);
212 (void)BIO_flush((BIO *)arg); 224 (void)BIO_flush(arg);
213 225
214 if (!ok && (p == 0) && (num > 1)) 226 if (!ok && (p == 0) && (num > 1))
215 { 227 {
diff --git a/src/lib/libcrypto/ebcdic.c b/src/lib/libcrypto/ebcdic.c
new file mode 100644
index 0000000000..31397b2add
--- /dev/null
+++ b/src/lib/libcrypto/ebcdic.c
@@ -0,0 +1,217 @@
1/* crypto/ebcdic.c */
2
3#ifdef CHARSET_EBCDIC
4#include "ebcdic.h"
5/* Initial Port for Apache-1.3 by <Martin.Kraemer@Mch.SNI.De>
6 * Adapted for OpenSSL-0.9.4 by <Martin.Kraemer@Mch.SNI.De>
7 */
8
9#ifdef _OSD_POSIX
10/*
11 "BS2000 OSD" is a POSIX subsystem on a main frame.
12 It is made by Siemens AG, Germany, for their BS2000 mainframe machines.
13 Within the POSIX subsystem, the same character set was chosen as in
14 "native BS2000", namely EBCDIC. (EDF04)
15
16 The name "ASCII" in these routines is misleading: actually, conversion
17 is not between EBCDIC and ASCII, but EBCDIC(EDF04) and ISO-8859.1;
18 that means that (western european) national characters are preserved.
19
20 This table is identical to the one used by rsh/rcp/ftp and other POSIX tools.
21*/
22
23/* Here's the bijective ebcdic-to-ascii table: */
24const unsigned char os_toascii[256] = {
25/*00*/ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
26 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
27/*10*/ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
28 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
29/*20*/ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
30 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /*................*/
31/*30*/ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
32 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /*................*/
33/*40*/ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
34 0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* .........`.<(+|*/
35/*50*/ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
36 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f, /*&.........!$*);.*/
37/*60*/ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
38 0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /*-/........^,%_>?*/
39/*70*/ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
40 0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /*..........:#@'="*/
41/*80*/ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
42 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /*.abcdefghi......*/
43/*90*/ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
44 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /*.jklmnopqr......*/
45/*a0*/ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
46 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae, /*..stuvwxyz......*/
47/*b0*/ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
48 0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7, /*...........[\]..*/
49/*c0*/ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
50 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /*.ABCDEFGHI......*/
51/*d0*/ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
52 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff, /*.JKLMNOPQR......*/
53/*e0*/ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
54 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /*..STUVWXYZ......*/
55/*f0*/ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
56 0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e /*0123456789.{.}.~*/
57};
58
59
60/* The ascii-to-ebcdic table: */
61const unsigned char os_toebcdic[256] = {
62/*00*/ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f,
63 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
64/*10*/ 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26,
65 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
66/*20*/ 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d,
67 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
68/*30*/ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
69 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /*0123456789:;<=>?*/
70/*40*/ 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
71 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /*@ABCDEFGHIJKLMNO*/
72/*50*/ 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
73 0xe7, 0xe8, 0xe9, 0xbb, 0xbc, 0xbd, 0x6a, 0x6d, /*PQRSTUVWXYZ[\]^_*/
74/*60*/ 0x4a, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
75 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /*`abcdefghijklmno*/
76/*70*/ 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
77 0xa7, 0xa8, 0xa9, 0xfb, 0x4f, 0xfd, 0xff, 0x07, /*pqrstuvwxyz{|}~.*/
78/*80*/ 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08,
79 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /*................*/
80/*90*/ 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17,
81 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0x5f, /*................*/
82/*a0*/ 0x41, 0xaa, 0xb0, 0xb1, 0x9f, 0xb2, 0xd0, 0xb5,
83 0x79, 0xb4, 0x9a, 0x8a, 0xba, 0xca, 0xaf, 0xa1, /*................*/
84/*b0*/ 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3,
85 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /*................*/
86/*c0*/ 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68,
87 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /*................*/
88/*d0*/ 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf,
89 0x80, 0xe0, 0xfe, 0xdd, 0xfc, 0xad, 0xae, 0x59, /*................*/
90/*e0*/ 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48,
91 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /*................*/
92/*f0*/ 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1,
93 0x70, 0xc0, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /*................*/
94};
95
96#else /*_OSD_POSIX*/
97
98/*
99This code does basic character mapping for IBM's TPF and OS/390 operating systems.
100It is a modified version of the BS2000 table.
101
102Bijective EBCDIC (character set IBM-1047) to US-ASCII table:
103This table is bijective - there are no ambigous or duplicate characters.
104*/
105const unsigned char os_toascii[256] = {
106 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f, /* 00-0f: */
107 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */
108 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97, /* 10-1f: */
109 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */
110 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b, /* 20-2f: */
111 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /* ................ */
112 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, /* 30-3f: */
113 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /* ................ */
114 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5, /* 40-4f: */
115 0xe7, 0xf1, 0xa2, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* ...........<(+| */
116 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef, /* 50-5f: */
117 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x5e, /* &.........!$*);^ */
118 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5, /* 60-6f: */
119 0xc7, 0xd1, 0xa6, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /* -/.........,%_>? */
120 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, /* 70-7f: */
121 0xcc, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /* .........`:#@'=" */
122 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 80-8f: */
123 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /* .abcdefghi...... */
124 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, /* 90-9f: */
125 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /* .jklmnopqr...... */
126 0xb5, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, /* a0-af: */
127 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0x5b, 0xde, 0xae, /* .~stuvwxyz...[.. */
128 0xac, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc, /* b0-bf: */
129 0xbd, 0xbe, 0xdd, 0xa8, 0xaf, 0x5d, 0xb4, 0xd7, /* .............].. */
130 0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* c0-cf: */
131 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /* {ABCDEFGHI...... */
132 0x7d, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, /* d0-df: */
133 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xf9, 0xfa, 0xff, /* }JKLMNOPQR...... */
134 0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, /* e0-ef: */
135 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /* \.STUVWXYZ...... */
136 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* f0-ff: */
137 0x38, 0x39, 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f /* 0123456789...... */
138};
139
140
141/*
142The US-ASCII to EBCDIC (character set IBM-1047) table:
143This table is bijective (no ambiguous or duplicate characters)
144*/
145const unsigned char os_toebcdic[256] = {
146 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, /* 00-0f: */
147 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */
148 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, /* 10-1f: */
149 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */
150 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, /* 20-2f: */
151 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
152 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 30-3f: */
153 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /* 0123456789:;<=>? */
154 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 40-4f: */
155 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /* @ABCDEFGHIJKLMNO */
156 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, /* 50-5f: */
157 0xe7, 0xe8, 0xe9, 0xad, 0xe0, 0xbd, 0x5f, 0x6d, /* PQRSTUVWXYZ[\]^_ */
158 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 60-6f: */
159 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /* `abcdefghijklmno */
160 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, /* 70-7f: */
161 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07, /* pqrstuvwxyz{|}~. */
162 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08, /* 80-8f: */
163 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /* ................ */
164 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17, /* 90-9f: */
165 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0xff, /* ................ */
166 0x41, 0xaa, 0x4a, 0xb1, 0x9f, 0xb2, 0x6a, 0xb5, /* a0-af: */
167 0xbb, 0xb4, 0x9a, 0x8a, 0xb0, 0xca, 0xaf, 0xbc, /* ................ */
168 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3, /* b0-bf: */
169 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /* ................ */
170 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68, /* c0-cf: */
171 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /* ................ */
172 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf, /* d0-df: */
173 0x80, 0xfd, 0xfe, 0xfb, 0xfc, 0xba, 0xae, 0x59, /* ................ */
174 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48, /* e0-ef: */
175 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /* ................ */
176 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, /* f0-ff: */
177 0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /* ................ */
178};
179#endif /*_OSD_POSIX*/
180
181/* Translate a memory block from EBCDIC (host charset) to ASCII (net charset)
182 * dest and srce may be identical, or separate memory blocks, but
183 * should not overlap. These functions intentionally have an interface
184 * compatible to memcpy(3).
185 */
186
187void *
188ebcdic2ascii(void *dest, const void *srce, size_t count)
189{
190 unsigned char *udest = dest;
191 const unsigned char *usrce = srce;
192
193 while (count-- != 0) {
194 *udest++ = os_toascii[*usrce++];
195 }
196
197 return dest;
198}
199
200void *
201ascii2ebcdic(void *dest, const void *srce, size_t count)
202{
203 unsigned char *udest = dest;
204 const unsigned char *usrce = srce;
205
206 while (count-- != 0) {
207 *udest++ = os_toebcdic[*usrce++];
208 }
209
210 return dest;
211}
212
213#else /*CHARSET_EBCDIC*/
214#ifdef PEDANTIC
215static void *dummy=&dummy;
216#endif
217#endif
diff --git a/src/lib/libcrypto/ebcdic.h b/src/lib/libcrypto/ebcdic.h
index d3b4e98b12..6d65afcf9e 100644
--- a/src/lib/libcrypto/ebcdic.h
+++ b/src/lib/libcrypto/ebcdic.h
@@ -1,17 +1,19 @@
1/* crypto/ebcdic.h */
2
1#ifndef HEADER_EBCDIC_H 3#ifndef HEADER_EBCDIC_H
2#define HEADER_EBCDIC_H 4#define HEADER_EBCDIC_H
3 5
4#include <sys/types.h> 6#include <sys/types.h>
5 7
6/* Avoid name clashes with other applications */ 8/* Avoid name clashes with other applications */
7#define os_toascii _eay2000_os_toascii 9#define os_toascii _openssl_os_toascii
8#define os_toebcdic _eay2000_os_toebcdic 10#define os_toebcdic _openssl_os_toebcdic
9#define ebcdic2ascii _eay2000_ebcdic2ascii 11#define ebcdic2ascii _openssl_ebcdic2ascii
10#define ascii2ebcdic _eay2000_ascii2ebcdic 12#define ascii2ebcdic _openssl_ascii2ebcdic
11 13
12extern const unsigned char os_toascii[256]; 14extern const unsigned char os_toascii[256];
13extern const unsigned char os_toebcdic[256]; 15extern const unsigned char os_toebcdic[256];
14void ebcdic2ascii(unsigned char *dest, const unsigned char *srce, size_t count); 16void *ebcdic2ascii(void *dest, const void *srce, size_t count);
15void ascii2ebcdic(unsigned char *dest, const unsigned char *srce, size_t count); 17void *ascii2ebcdic(void *dest, const void *srce, size_t count);
16 18
17#endif 19#endif
diff --git a/src/lib/libcrypto/err/Makefile.ssl b/src/lib/libcrypto/err/Makefile.ssl
index ae827edddb..fb74e4eb13 100644
--- a/src/lib/libcrypto/err/Makefile.ssl
+++ b/src/lib/libcrypto/err/Makefile.ssl
@@ -82,8 +82,8 @@ err.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 82err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 83err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 84err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
85err.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 85err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
86err.o: ../cryptlib.h 86err.o: ../../include/openssl/stack.h ../cryptlib.h
87err_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 87err_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
88err_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 88err_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
89err_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 89err_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -96,15 +96,16 @@ err_all.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
96err_all.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h 96err_all.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
97err_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 97err_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
98err_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h 98err_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
99err_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h 99err_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
100err_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h 100err_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
101err_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h 101err_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
102err_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 102err_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
103err_all.o: ../../include/openssl/stack.h ../../include/openssl/x509.h 103err_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
104err_all.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h 104err_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
105err_all.o: ../../include/openssl/x509v3.h
105err_prn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 106err_prn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
106err_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 107err_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
107err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 108err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
108err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 109err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
109err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 110err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
110err_prn.o: ../cryptlib.h 111err_prn.o: ../../include/openssl/stack.h ../cryptlib.h
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index 8810d838c6..93c64cbc4f 100644
--- a/src/lib/libcrypto/err/err.c
+++ b/src/lib/libcrypto/err/err.c
@@ -91,7 +91,7 @@ static ERR_STRING_DATA ERR_str_libraries[]=
91{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"}, 91{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"},
92{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"}, 92{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"},
93{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"}, 93{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"},
94{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuation file routines"}, 94{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuration file routines"},
95{ERR_PACK(ERR_LIB_METH,0,0) ,"X509 lookup 'method' routines"}, 95{ERR_PACK(ERR_LIB_METH,0,0) ,"X509 lookup 'method' routines"},
96{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"}, 96{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"},
97{ERR_PACK(ERR_LIB_RSAREF,0,0) ,"RSAref routines"}, 97{ERR_PACK(ERR_LIB_RSAREF,0,0) ,"RSAref routines"},
@@ -100,6 +100,7 @@ static ERR_STRING_DATA ERR_str_libraries[]=
100{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"}, 100{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
101{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"}, 101{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
102{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"}, 102{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
103{ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"},
103{0,NULL}, 104{0,NULL},
104 }; 105 };
105 106
@@ -221,7 +222,7 @@ void ERR_load_strings(int lib, ERR_STRING_DATA *str)
221 while (str->error) 222 while (str->error)
222 { 223 {
223 str->error|=ERR_PACK(lib,0,0); 224 str->error|=ERR_PACK(lib,0,0);
224 lh_insert(error_hash,(char *)str); 225 lh_insert(error_hash,str);
225 str++; 226 str++;
226 } 227 }
227 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH); 228 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
@@ -427,7 +428,7 @@ const char *ERR_lib_error_string(unsigned long e)
427 if (error_hash != NULL) 428 if (error_hash != NULL)
428 { 429 {
429 d.error=ERR_PACK(l,0,0); 430 d.error=ERR_PACK(l,0,0);
430 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d); 431 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
431 } 432 }
432 433
433 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH); 434 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
@@ -448,7 +449,7 @@ const char *ERR_func_error_string(unsigned long e)
448 if (error_hash != NULL) 449 if (error_hash != NULL)
449 { 450 {
450 d.error=ERR_PACK(l,f,0); 451 d.error=ERR_PACK(l,f,0);
451 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d); 452 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
452 } 453 }
453 454
454 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH); 455 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
@@ -469,12 +470,11 @@ const char *ERR_reason_error_string(unsigned long e)
469 if (error_hash != NULL) 470 if (error_hash != NULL)
470 { 471 {
471 d.error=ERR_PACK(l,0,r); 472 d.error=ERR_PACK(l,0,r);
472 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d); 473 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
473 if (p == NULL) 474 if (p == NULL)
474 { 475 {
475 d.error=ERR_PACK(0,0,r); 476 d.error=ERR_PACK(0,0,r);
476 p=(ERR_STRING_DATA *)lh_retrieve(error_hash, 477 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
477 (char *)&d);
478 } 478 }
479 } 479 }
480 480
@@ -517,7 +517,7 @@ void ERR_remove_state(unsigned long pid)
517 pid=(unsigned long)CRYPTO_thread_id(); 517 pid=(unsigned long)CRYPTO_thread_id();
518 tmp.pid=pid; 518 tmp.pid=pid;
519 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 519 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
520 p=(ERR_STATE *)lh_delete(thread_hash,(char *)&tmp); 520 p=(ERR_STATE *)lh_delete(thread_hash,&tmp);
521 CRYPTO_w_unlock(CRYPTO_LOCK_ERR); 521 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
522 522
523 if (p != NULL) ERR_STATE_free(p); 523 if (p != NULL) ERR_STATE_free(p);
@@ -551,7 +551,7 @@ ERR_STATE *ERR_get_state(void)
551 else 551 else
552 { 552 {
553 tmp.pid=pid; 553 tmp.pid=pid;
554 ret=(ERR_STATE *)lh_retrieve(thread_hash,(char *)&tmp); 554 ret=(ERR_STATE *)lh_retrieve(thread_hash,&tmp);
555 CRYPTO_r_unlock(CRYPTO_LOCK_ERR); 555 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
556 } 556 }
557 557
@@ -569,7 +569,7 @@ ERR_STATE *ERR_get_state(void)
569 ret->err_data_flags[i]=0; 569 ret->err_data_flags[i]=0;
570 } 570 }
571 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 571 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
572 tmpp=(ERR_STATE *)lh_insert(thread_hash,(char *)ret); 572 tmpp=(ERR_STATE *)lh_insert(thread_hash,ret);
573 CRYPTO_w_unlock(CRYPTO_LOCK_ERR); 573 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
574 if (tmpp != NULL) /* old entry - should not happen */ 574 if (tmpp != NULL) /* old entry - should not happen */
575 { 575 {
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h
index 9411fb3568..15bafbff43 100644
--- a/src/lib/libcrypto/err/err.h
+++ b/src/lib/libcrypto/err/err.h
@@ -122,6 +122,7 @@ typedef struct err_state_st
122#define ERR_LIB_PKCS7 33 122#define ERR_LIB_PKCS7 33
123#define ERR_LIB_X509V3 34 123#define ERR_LIB_X509V3 34
124#define ERR_LIB_PKCS12 35 124#define ERR_LIB_PKCS12 35
125#define ERR_LIB_RAND 36
125 126
126#define ERR_LIB_USER 128 127#define ERR_LIB_USER 128
127 128
@@ -149,6 +150,7 @@ typedef struct err_state_st
149#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__) 150#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__)
150#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__) 151#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__)
151#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__) 152#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__)
153#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),ERR_file_name,__LINE__)
152 154
153/* Borland C seems too stupid to be able to shift and do longs in 155/* Borland C seems too stupid to be able to shift and do longs in
154 * the pre-processor :-( */ 156 * the pre-processor :-( */
@@ -160,7 +162,7 @@ typedef struct err_state_st
160#define ERR_GET_REASON(l) (int)((l)&0xfffL) 162#define ERR_GET_REASON(l) (int)((l)&0xfffL)
161#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL) 163#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL)
162 164
163/* OS fuctions */ 165/* OS functions */
164#define SYS_F_FOPEN 1 166#define SYS_F_FOPEN 1
165#define SYS_F_CONNECT 2 167#define SYS_F_CONNECT 2
166#define SYS_F_GETSERVBYNAME 3 168#define SYS_F_GETSERVBYNAME 3
@@ -239,9 +241,9 @@ void ERR_print_errors(BIO *bp);
239void ERR_add_error_data(int num, ...); 241void ERR_add_error_data(int num, ...);
240#endif 242#endif
241void ERR_load_strings(int lib,ERR_STRING_DATA str[]); 243void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
242void ERR_load_ERR_strings(void ); 244void ERR_load_ERR_strings(void);
243void ERR_load_crypto_strings(void ); 245void ERR_load_crypto_strings(void);
244void ERR_free_strings(void ); 246void ERR_free_strings(void);
245 247
246void ERR_remove_state(unsigned long pid); /* if zero we look it up */ 248void ERR_remove_state(unsigned long pid); /* if zero we look it up */
247ERR_STATE *ERR_get_state(void); 249ERR_STATE *ERR_get_state(void);
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
index ad820227d2..10c463b389 100644
--- a/src/lib/libcrypto/err/err_all.c
+++ b/src/lib/libcrypto/err/err_all.c
@@ -80,6 +80,7 @@
80#include <openssl/x509v3.h> 80#include <openssl/x509v3.h>
81#include <openssl/conf.h> 81#include <openssl/conf.h>
82#include <openssl/pkcs12.h> 82#include <openssl/pkcs12.h>
83#include <openssl/rand.h>
83#include <openssl/err.h> 84#include <openssl/err.h>
84 85
85void ERR_load_crypto_strings(void) 86void ERR_load_crypto_strings(void)
@@ -116,5 +117,6 @@ void ERR_load_crypto_strings(void)
116 ERR_load_CRYPTO_strings(); 117 ERR_load_CRYPTO_strings();
117 ERR_load_PKCS7_strings(); 118 ERR_load_PKCS7_strings();
118 ERR_load_PKCS12_strings(); 119 ERR_load_PKCS12_strings();
120 ERR_load_RAND_strings();
119#endif 121#endif
120 } 122 }
diff --git a/src/lib/libcrypto/err/openssl.ec b/src/lib/libcrypto/err/openssl.ec
index c2a8acff0c..e132ba3182 100644
--- a/src/lib/libcrypto/err/openssl.ec
+++ b/src/lib/libcrypto/err/openssl.ec
@@ -21,6 +21,7 @@ L PKCS12 crypto/pkcs12/pkcs12.h crypto/pkcs12/pk12err.c
21L RSAREF rsaref/rsaref.h rsaref/rsar_err.c 21L RSAREF rsaref/rsaref.h rsaref/rsar_err.c
22L SSL ssl/ssl.h ssl/ssl_err.c 22L SSL ssl/ssl.h ssl/ssl_err.c
23L COMP crypto/comp/comp.h crypto/comp/comp_err.c 23L COMP crypto/comp/comp.h crypto/comp/comp_err.c
24L RAND crypto/rand/rand.h crypto/rand/rand_err.c
24 25
25 26
26F RSAREF_F_RSA_BN2BIN 27F RSAREF_F_RSA_BN2BIN
@@ -47,11 +48,11 @@ R SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
47R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049 48R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
48R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050 49R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
49R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051 50R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
50R SSL_R_TLSV1_ALERT_EXPORT_RESTRICION 1060 51R SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
51R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070 52R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
52R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071 53R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
53R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080 54R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
54R SSL_R_TLSV1_ALERT_USER_CANCLED 1090 55R SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
55R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100 56R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
56 57
57R RSAREF_R_CONTENT_ENCODING 0x0400 58R RSAREF_R_CONTENT_ENCODING 0x0400
diff --git a/src/lib/libcrypto/evp/Makefile.ssl b/src/lib/libcrypto/evp/Makefile.ssl
index 753479a015..c763b5ccd6 100644
--- a/src/lib/libcrypto/evp/Makefile.ssl
+++ b/src/lib/libcrypto/evp/Makefile.ssl
@@ -35,7 +35,8 @@ LIBSRC= encode.c digest.c evp_enc.c evp_key.c \
35 m_ripemd.c \ 35 m_ripemd.c \
36 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \ 36 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
37 bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \ 37 bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
38 c_all.c evp_lib.c bio_ok.c evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c 38 c_all.c c_allc.c c_alld.c evp_lib.c bio_ok.c \
39 evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c
39 40
40LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \ 41LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \
41 e_ecb_d.o e_cbc_d.o e_cfb_d.o e_ofb_d.o \ 42 e_ecb_d.o e_cbc_d.o e_cfb_d.o e_ofb_d.o \
@@ -50,7 +51,8 @@ LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \
50 m_ripemd.o \ 51 m_ripemd.o \
51 p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \ 52 p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \
52 bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \ 53 bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \
53 c_all.o evp_lib.o bio_ok.o evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o 54 c_all.o c_allc.o c_alld.o evp_lib.o bio_ok.o \
55 evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o
54 56
55SRC= $(LIBSRC) 57SRC= $(LIBSRC)
56 58
@@ -176,13 +178,45 @@ c_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
176c_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 178c_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
177c_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 179c_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
178c_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 180c_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
179c_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs12.h 181c_all.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
180c_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
181c_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h 182c_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
182c_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h 183c_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
183c_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 184c_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
184c_all.o: ../../include/openssl/stack.h ../../include/openssl/x509.h 185c_all.o: ../../include/openssl/stack.h ../cryptlib.h
185c_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h 186c_allc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
187c_allc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
188c_allc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
189c_allc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
190c_allc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
191c_allc.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
192c_allc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
193c_allc.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
194c_allc.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
195c_allc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
196c_allc.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs12.h
197c_allc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
198c_allc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
199c_allc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
200c_allc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
201c_allc.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
202c_allc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
203c_alld.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
204c_alld.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
205c_alld.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
206c_alld.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
207c_alld.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
208c_alld.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
209c_alld.o: ../../include/openssl/err.h ../../include/openssl/evp.h
210c_alld.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
211c_alld.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
212c_alld.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
213c_alld.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs12.h
214c_alld.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
215c_alld.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
216c_alld.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
217c_alld.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
218c_alld.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
219c_alld.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
186digest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 220digest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
187digest.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 221digest.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
188digest.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 222digest.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
index 84729119df..bd5e24f993 100644
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ b/src/lib/libcrypto/evp/bio_b64.c
@@ -69,6 +69,7 @@ static int b64_read(BIO *h,char *buf,int size);
69static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int b64_new(BIO *h); 70static int b64_new(BIO *h);
71static int b64_free(BIO *data); 71static int b64_free(BIO *data);
72static long b64_callback_ctrl(BIO *h,int cmd,void (*fp)());
72#define B64_BLOCK_SIZE 1024 73#define B64_BLOCK_SIZE 1024
73#define B64_BLOCK_SIZE2 768 74#define B64_BLOCK_SIZE2 768
74#define B64_NONE 0 75#define B64_NONE 0
@@ -100,6 +101,7 @@ static BIO_METHOD methods_b64=
100 b64_ctrl, 101 b64_ctrl,
101 b64_new, 102 b64_new,
102 b64_free, 103 b64_free,
104 b64_callback_ctrl,
103 }; 105 };
104 106
105BIO_METHOD *BIO_f_base64(void) 107BIO_METHOD *BIO_f_base64(void)
@@ -237,8 +239,8 @@ static int b64_read(BIO *b, char *out, int outl)
237 &(ctx->tmp[0])); 239 &(ctx->tmp[0]));
238 for (x=0; x < i; x++) 240 for (x=0; x < i; x++)
239 ctx->tmp[x]=p[x]; 241 ctx->tmp[x]=p[x];
240 EVP_DecodeInit(&ctx->base64);
241 } 242 }
243 EVP_DecodeInit(&ctx->base64);
242 ctx->start=0; 244 ctx->start=0;
243 break; 245 break;
244 } 246 }
@@ -522,3 +524,17 @@ again:
522 return(ret); 524 return(ret);
523 } 525 }
524 526
527static long b64_callback_ctrl(BIO *b, int cmd, void (*fp)())
528 {
529 long ret=1;
530
531 if (b->next_bio == NULL) return(0);
532 switch (cmd)
533 {
534 default:
535 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
536 break;
537 }
538 return(ret);
539 }
540
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
index 0a7b1ecf07..629bf4b95d 100644
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -69,6 +69,7 @@ static int enc_read(BIO *h,char *buf,int size);
69static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int enc_new(BIO *h); 70static int enc_new(BIO *h);
71static int enc_free(BIO *data); 71static int enc_free(BIO *data);
72static long enc_callback_ctrl(BIO *h,int cmd,void (*fp)());
72#define ENC_BLOCK_SIZE (1024*4) 73#define ENC_BLOCK_SIZE (1024*4)
73 74
74typedef struct enc_struct 75typedef struct enc_struct
@@ -92,6 +93,7 @@ static BIO_METHOD methods_enc=
92 enc_ctrl, 93 enc_ctrl,
93 enc_new, 94 enc_new,
94 enc_free, 95 enc_free,
96 enc_callback_ctrl,
95 }; 97 };
96 98
97BIO_METHOD *BIO_f_cipher(void) 99BIO_METHOD *BIO_f_cipher(void)
@@ -184,9 +186,11 @@ static int enc_read(BIO *b, char *out, int outl)
184 ctx->ok=i; 186 ctx->ok=i;
185 ctx->buf_off=0; 187 ctx->buf_off=0;
186 } 188 }
187 else 189 else
190 {
188 ret=(ret == 0)?i:ret; 191 ret=(ret == 0)?i:ret;
189 break; 192 break;
193 }
190 } 194 }
191 else 195 else
192 { 196 {
@@ -194,13 +198,19 @@ static int enc_read(BIO *b, char *out, int outl)
194 (unsigned char *)ctx->buf,&ctx->buf_len, 198 (unsigned char *)ctx->buf,&ctx->buf_len,
195 (unsigned char *)&(ctx->buf[8]),i); 199 (unsigned char *)&(ctx->buf[8]),i);
196 ctx->cont=1; 200 ctx->cont=1;
201 /* Note: it is possible for EVP_CipherUpdate to
202 * decrypt zero bytes because this is or looks like
203 * the final block: if this happens we should retry
204 * and either read more data or decrypt the final
205 * block
206 */
207 if(ctx->buf_len == 0) continue;
197 } 208 }
198 209
199 if (ctx->buf_len <= outl) 210 if (ctx->buf_len <= outl)
200 i=ctx->buf_len; 211 i=ctx->buf_len;
201 else 212 else
202 i=outl; 213 i=outl;
203
204 if (i <= 0) break; 214 if (i <= 0) break;
205 memcpy(out,ctx->buf,i); 215 memcpy(out,ctx->buf,i);
206 ret+=i; 216 ret+=i;
@@ -360,6 +370,20 @@ again:
360 return(ret); 370 return(ret);
361 } 371 }
362 372
373static long enc_callback_ctrl(BIO *b, int cmd, void (*fp)())
374 {
375 long ret=1;
376
377 if (b->next_bio == NULL) return(0);
378 switch (cmd)
379 {
380 default:
381 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
382 break;
383 }
384 return(ret);
385 }
386
363/* 387/*
364void BIO_set_cipher_ctx(b,c) 388void BIO_set_cipher_ctx(b,c)
365BIO *b; 389BIO *b;
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
index 317167f9c4..aef928dd8f 100644
--- a/src/lib/libcrypto/evp/bio_md.c
+++ b/src/lib/libcrypto/evp/bio_md.c
@@ -72,6 +72,8 @@ static int md_gets(BIO *h,char *str,int size);
72static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2); 72static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2);
73static int md_new(BIO *h); 73static int md_new(BIO *h);
74static int md_free(BIO *data); 74static int md_free(BIO *data);
75static long md_callback_ctrl(BIO *h,int cmd,void (*fp)());
76
75static BIO_METHOD methods_md= 77static BIO_METHOD methods_md=
76 { 78 {
77 BIO_TYPE_MD,"message digest", 79 BIO_TYPE_MD,"message digest",
@@ -82,6 +84,7 @@ static BIO_METHOD methods_md=
82 md_ctrl, 84 md_ctrl,
83 md_new, 85 md_new,
84 md_free, 86 md_free,
87 md_callback_ctrl,
85 }; 88 };
86 89
87BIO_METHOD *BIO_f_md(void) 90BIO_METHOD *BIO_f_md(void)
@@ -220,6 +223,20 @@ static long md_ctrl(BIO *b, int cmd, long num, char *ptr)
220 return(ret); 223 return(ret);
221 } 224 }
222 225
226static long md_callback_ctrl(BIO *b, int cmd, void (*fp)())
227 {
228 long ret=1;
229
230 if (b->next_bio == NULL) return(0);
231 switch (cmd)
232 {
233 default:
234 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
235 break;
236 }
237 return(ret);
238 }
239
223static int md_gets(BIO *bp, char *buf, int size) 240static int md_gets(BIO *bp, char *buf, int size)
224 { 241 {
225 EVP_MD_CTX *ctx; 242 EVP_MD_CTX *ctx;
diff --git a/src/lib/libcrypto/evp/bio_ok.c b/src/lib/libcrypto/evp/bio_ok.c
index 101275d648..e6ff5f2cdb 100644
--- a/src/lib/libcrypto/evp/bio_ok.c
+++ b/src/lib/libcrypto/evp/bio_ok.c
@@ -67,7 +67,7 @@
67 and everything was OK. BUT if user types wrong password 67 and everything was OK. BUT if user types wrong password
68 BIO_f_cipher outputs only garbage and my function crashes. Yes 68 BIO_f_cipher outputs only garbage and my function crashes. Yes
69 I can and I should fix my function, but BIO_f_cipher is 69 I can and I should fix my function, but BIO_f_cipher is
70 easy way to add encryption support to many exisiting applications 70 easy way to add encryption support to many existing applications
71 and it's hard to debug and fix them all. 71 and it's hard to debug and fix them all.
72 72
73 So I wanted another BIO which would catch the incorrect passwords and 73 So I wanted another BIO which would catch the incorrect passwords and
@@ -80,10 +80,10 @@
80 1) you must somehow separate checksum from actual data. 80 1) you must somehow separate checksum from actual data.
81 2) you need lot's of memory when reading the file, because you 81 2) you need lot's of memory when reading the file, because you
82 must read to the end of the file and verify the checksum before 82 must read to the end of the file and verify the checksum before
83 leting the application to read the data. 83 letting the application to read the data.
84 84
85 BIO_f_reliable tries to solve both problems, so that you can 85 BIO_f_reliable tries to solve both problems, so that you can
86 read and write arbitraly long streams using only fixed amount 86 read and write arbitrary long streams using only fixed amount
87 of memory. 87 of memory.
88 88
89 BIO_f_reliable splits data stream into blocks. Each block is prefixed 89 BIO_f_reliable splits data stream into blocks. Each block is prefixed
@@ -91,7 +91,7 @@
91 several Kbytes of memory to buffer single block before verifying 91 several Kbytes of memory to buffer single block before verifying
92 it's digest. 92 it's digest.
93 93
94 BIO_f_reliable goes futher and adds several important capabilities: 94 BIO_f_reliable goes further and adds several important capabilities:
95 95
96 1) the digest of the block is computed over the whole stream 96 1) the digest of the block is computed over the whole stream
97 -- so nobody can rearrange the blocks or remove or replace them. 97 -- so nobody can rearrange the blocks or remove or replace them.
@@ -110,7 +110,7 @@
110 and then compare the digest output. 110 and then compare the digest output.
111 111
112 Bad things: BIO_f_reliable knows what's going on in EVP_Digest. I 112 Bad things: BIO_f_reliable knows what's going on in EVP_Digest. I
113 initialy wrote and tested this code on x86 machine and wrote the 113 initially wrote and tested this code on x86 machine and wrote the
114 digests out in machine-dependent order :( There are people using 114 digests out in machine-dependent order :( There are people using
115 this code and I cannot change this easily without making existing 115 this code and I cannot change this easily without making existing
116 data files unreadable. 116 data files unreadable.
@@ -130,6 +130,8 @@ static int ok_read(BIO *h,char *buf,int size);
130static long ok_ctrl(BIO *h,int cmd,long arg1,char *arg2); 130static long ok_ctrl(BIO *h,int cmd,long arg1,char *arg2);
131static int ok_new(BIO *h); 131static int ok_new(BIO *h);
132static int ok_free(BIO *data); 132static int ok_free(BIO *data);
133static long ok_callback_ctrl(BIO *h,int cmd,void (*fp)());
134
133static void sig_out(BIO* b); 135static void sig_out(BIO* b);
134static void sig_in(BIO* b); 136static void sig_in(BIO* b);
135static void block_out(BIO* b); 137static void block_out(BIO* b);
@@ -173,6 +175,7 @@ static BIO_METHOD methods_ok=
173 ok_ctrl, 175 ok_ctrl,
174 ok_new, 176 ok_new,
175 ok_free, 177 ok_free,
178 ok_callback_ctrl,
176 }; 179 };
177 180
178BIO_METHOD *BIO_f_reliable(void) 181BIO_METHOD *BIO_f_reliable(void)
@@ -428,6 +431,20 @@ static long ok_ctrl(BIO *b, int cmd, long num, char *ptr)
428 return(ret); 431 return(ret);
429 } 432 }
430 433
434static long ok_callback_ctrl(BIO *b, int cmd, void (*fp)())
435 {
436 long ret=1;
437
438 if (b->next_bio == NULL) return(0);
439 switch (cmd)
440 {
441 default:
442 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
443 break;
444 }
445 return(ret);
446 }
447
431static void longswap(void *_ptr, int len) 448static void longswap(void *_ptr, int len)
432{ 449{
433#ifndef L_ENDIAN 450#ifndef L_ENDIAN
@@ -451,12 +468,12 @@ static void sig_out(BIO* b)
451 if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return; 468 if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return;
452 469
453 EVP_DigestInit(md, md->digest); 470 EVP_DigestInit(md, md->digest);
454 RAND_bytes(&(md->md.base[0]), md->digest->md_size); 471 RAND_pseudo_bytes(&(md->md.base[0]), md->digest->md_size);
455 memcpy(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]), md->digest->md_size); 472 memcpy(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]), md->digest->md_size);
456 longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size); 473 longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
457 ctx->buf_len+= md->digest->md_size; 474 ctx->buf_len+= md->digest->md_size;
458 475
459 EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN)); 476 EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN));
460 md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0])); 477 md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]));
461 ctx->buf_len+= md->digest->md_size; 478 ctx->buf_len+= md->digest->md_size;
462 ctx->blockout= 1; 479 ctx->blockout= 1;
@@ -480,7 +497,7 @@ static void sig_in(BIO* b)
480 longswap(&(md->md.base[0]), md->digest->md_size); 497 longswap(&(md->md.base[0]), md->digest->md_size);
481 ctx->buf_off+= md->digest->md_size; 498 ctx->buf_off+= md->digest->md_size;
482 499
483 EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN)); 500 EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN));
484 md->digest->final(tmp, &(md->md.base[0])); 501 md->digest->final(tmp, &(md->md.base[0]));
485 ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0; 502 ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
486 ctx->buf_off+= md->digest->md_size; 503 ctx->buf_off+= md->digest->md_size;
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
index a4d3b43fb9..1e185830a3 100644
--- a/src/lib/libcrypto/evp/c_all.c
+++ b/src/lib/libcrypto/evp/c_all.c
@@ -59,135 +59,9 @@
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/evp.h> 61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64 62
65void SSLeay_add_all_algorithms(void) 63void OpenSSL_add_all_algorithms(void)
66 { 64{
67 SSLeay_add_all_ciphers(); 65 OpenSSL_add_all_ciphers();
68 SSLeay_add_all_digests(); 66 OpenSSL_add_all_digests();
69 } 67}
70
71void SSLeay_add_all_ciphers(void)
72 {
73#ifndef NO_DES
74 EVP_add_cipher(EVP_des_cfb());
75 EVP_add_cipher(EVP_des_ede_cfb());
76 EVP_add_cipher(EVP_des_ede3_cfb());
77
78 EVP_add_cipher(EVP_des_ofb());
79 EVP_add_cipher(EVP_des_ede_ofb());
80 EVP_add_cipher(EVP_des_ede3_ofb());
81
82 EVP_add_cipher(EVP_desx_cbc());
83 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
84 EVP_add_cipher_alias(SN_desx_cbc,"desx");
85
86 EVP_add_cipher(EVP_des_cbc());
87 EVP_add_cipher_alias(SN_des_cbc,"DES");
88 EVP_add_cipher_alias(SN_des_cbc,"des");
89 EVP_add_cipher(EVP_des_ede_cbc());
90 EVP_add_cipher(EVP_des_ede3_cbc());
91 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
92 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
93
94 EVP_add_cipher(EVP_des_ecb());
95 EVP_add_cipher(EVP_des_ede());
96 EVP_add_cipher(EVP_des_ede3());
97#endif
98
99#ifndef NO_RC4
100 EVP_add_cipher(EVP_rc4());
101 EVP_add_cipher(EVP_rc4_40());
102#endif
103
104#ifndef NO_IDEA
105 EVP_add_cipher(EVP_idea_ecb());
106 EVP_add_cipher(EVP_idea_cfb());
107 EVP_add_cipher(EVP_idea_ofb());
108 EVP_add_cipher(EVP_idea_cbc());
109 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
110 EVP_add_cipher_alias(SN_idea_cbc,"idea");
111#endif
112
113#ifndef NO_RC2
114 EVP_add_cipher(EVP_rc2_ecb());
115 EVP_add_cipher(EVP_rc2_cfb());
116 EVP_add_cipher(EVP_rc2_ofb());
117 EVP_add_cipher(EVP_rc2_cbc());
118 EVP_add_cipher(EVP_rc2_40_cbc());
119 EVP_add_cipher(EVP_rc2_64_cbc());
120 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
121 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
122#endif
123
124#ifndef NO_BF
125 EVP_add_cipher(EVP_bf_ecb());
126 EVP_add_cipher(EVP_bf_cfb());
127 EVP_add_cipher(EVP_bf_ofb());
128 EVP_add_cipher(EVP_bf_cbc());
129 EVP_add_cipher_alias(SN_bf_cbc,"BF");
130 EVP_add_cipher_alias(SN_bf_cbc,"bf");
131 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
132#endif
133
134#ifndef NO_CAST
135 EVP_add_cipher(EVP_cast5_ecb());
136 EVP_add_cipher(EVP_cast5_cfb());
137 EVP_add_cipher(EVP_cast5_ofb());
138 EVP_add_cipher(EVP_cast5_cbc());
139 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
140 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
141 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
142 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
143#endif
144
145#ifndef NO_RC5
146 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
147 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
148 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
149 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
150 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
151 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
152#endif
153 }
154
155
156void SSLeay_add_all_digests(void)
157 {
158#ifndef NO_MD2
159 EVP_add_digest(EVP_md2());
160#endif
161#ifndef NO_MD5
162 EVP_add_digest(EVP_md5());
163 EVP_add_digest_alias(SN_md5,"ssl2-md5");
164 EVP_add_digest_alias(SN_md5,"ssl3-md5");
165#endif
166#ifndef NO_SHA
167 EVP_add_digest(EVP_sha());
168#ifndef NO_DSA
169 EVP_add_digest(EVP_dss());
170#endif
171#endif
172#ifndef NO_SHA
173 EVP_add_digest(EVP_sha1());
174 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
175 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
176#ifndef NO_DSA
177 EVP_add_digest(EVP_dss1());
178 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
179 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
180 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
181#endif
182#endif
183#if !defined(NO_MDC2) && !defined(NO_DES)
184 EVP_add_digest(EVP_mdc2());
185#endif
186#ifndef NO_RIPEMD
187 EVP_add_digest(EVP_ripemd160());
188 EVP_add_digest_alias(SN_ripemd160,"ripemd");
189 EVP_add_digest_alias(SN_ripemd160,"rmd160");
190#endif
191 PKCS12_PBE_add();
192 PKCS5_PBE_add();
193 }
diff --git a/src/lib/libcrypto/evp/c_allc.c b/src/lib/libcrypto/evp/c_allc.c
new file mode 100644
index 0000000000..f24d3756c9
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_allc.c
@@ -0,0 +1,149 @@
1/* crypto/evp/c_allc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_ciphers(void)
66 {
67#ifndef NO_DES
68 EVP_add_cipher(EVP_des_cfb());
69 EVP_add_cipher(EVP_des_ede_cfb());
70 EVP_add_cipher(EVP_des_ede3_cfb());
71
72 EVP_add_cipher(EVP_des_ofb());
73 EVP_add_cipher(EVP_des_ede_ofb());
74 EVP_add_cipher(EVP_des_ede3_ofb());
75
76 EVP_add_cipher(EVP_desx_cbc());
77 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
78 EVP_add_cipher_alias(SN_desx_cbc,"desx");
79
80 EVP_add_cipher(EVP_des_cbc());
81 EVP_add_cipher_alias(SN_des_cbc,"DES");
82 EVP_add_cipher_alias(SN_des_cbc,"des");
83 EVP_add_cipher(EVP_des_ede_cbc());
84 EVP_add_cipher(EVP_des_ede3_cbc());
85 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
86 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
87
88 EVP_add_cipher(EVP_des_ecb());
89 EVP_add_cipher(EVP_des_ede());
90 EVP_add_cipher(EVP_des_ede3());
91#endif
92
93#ifndef NO_RC4
94 EVP_add_cipher(EVP_rc4());
95 EVP_add_cipher(EVP_rc4_40());
96#endif
97
98#ifndef NO_IDEA
99 EVP_add_cipher(EVP_idea_ecb());
100 EVP_add_cipher(EVP_idea_cfb());
101 EVP_add_cipher(EVP_idea_ofb());
102 EVP_add_cipher(EVP_idea_cbc());
103 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
104 EVP_add_cipher_alias(SN_idea_cbc,"idea");
105#endif
106
107#ifndef NO_RC2
108 EVP_add_cipher(EVP_rc2_ecb());
109 EVP_add_cipher(EVP_rc2_cfb());
110 EVP_add_cipher(EVP_rc2_ofb());
111 EVP_add_cipher(EVP_rc2_cbc());
112 EVP_add_cipher(EVP_rc2_40_cbc());
113 EVP_add_cipher(EVP_rc2_64_cbc());
114 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
115 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
116#endif
117
118#ifndef NO_BF
119 EVP_add_cipher(EVP_bf_ecb());
120 EVP_add_cipher(EVP_bf_cfb());
121 EVP_add_cipher(EVP_bf_ofb());
122 EVP_add_cipher(EVP_bf_cbc());
123 EVP_add_cipher_alias(SN_bf_cbc,"BF");
124 EVP_add_cipher_alias(SN_bf_cbc,"bf");
125 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
126#endif
127
128#ifndef NO_CAST
129 EVP_add_cipher(EVP_cast5_ecb());
130 EVP_add_cipher(EVP_cast5_cfb());
131 EVP_add_cipher(EVP_cast5_ofb());
132 EVP_add_cipher(EVP_cast5_cbc());
133 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
134 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
135 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
136 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
137#endif
138
139#ifndef NO_RC5
140 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
141 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
142 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
143 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
144 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
145 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
146#endif
147 PKCS12_PBE_add();
148 PKCS5_PBE_add();
149 }
diff --git a/src/lib/libcrypto/evp/c_alld.c b/src/lib/libcrypto/evp/c_alld.c
new file mode 100644
index 0000000000..febe51a3ee
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_alld.c
@@ -0,0 +1,100 @@
1/* crypto/evp/c_alld.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_digests(void)
66 {
67#ifndef NO_MD2
68 EVP_add_digest(EVP_md2());
69#endif
70#ifndef NO_MD5
71 EVP_add_digest(EVP_md5());
72 EVP_add_digest_alias(SN_md5,"ssl2-md5");
73 EVP_add_digest_alias(SN_md5,"ssl3-md5");
74#endif
75#ifndef NO_SHA
76 EVP_add_digest(EVP_sha());
77#ifndef NO_DSA
78 EVP_add_digest(EVP_dss());
79#endif
80#endif
81#ifndef NO_SHA
82 EVP_add_digest(EVP_sha1());
83 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
84 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
85#ifndef NO_DSA
86 EVP_add_digest(EVP_dss1());
87 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
88 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
89 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
90#endif
91#endif
92#if !defined(NO_MDC2) && !defined(NO_DES)
93 EVP_add_digest(EVP_mdc2());
94#endif
95#ifndef NO_RIPEMD
96 EVP_add_digest(EVP_ripemd160());
97 EVP_add_digest_alias(SN_ripemd160,"ripemd");
98 EVP_add_digest_alias(SN_ripemd160,"rmd160");
99#endif
100 }
diff --git a/src/lib/libcrypto/evp/e_cbc_3d.c b/src/lib/libcrypto/evp/e_cbc_3d.c
index 02ccc6dc90..5d16b865c5 100644
--- a/src/lib/libcrypto/evp/e_cbc_3d.c
+++ b/src/lib/libcrypto/evp/e_cbc_3d.c
@@ -115,8 +115,8 @@ static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
115 115
116 if (deskey != NULL) 116 if (deskey != NULL)
117 { 117 {
118 des_set_key(&deskey[0],ctx->c.des_ede.ks1); 118 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
119 des_set_key(&deskey[1],ctx->c.des_ede.ks2); 119 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
120 memcpy( (char *)ctx->c.des_ede.ks3, 120 memcpy( (char *)ctx->c.des_ede.ks3,
121 (char *)ctx->c.des_ede.ks1, 121 (char *)ctx->c.des_ede.ks1,
122 sizeof(ctx->c.des_ede.ks1)); 122 sizeof(ctx->c.des_ede.ks1));
@@ -134,9 +134,9 @@ static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
134 134
135 if (deskey != NULL) 135 if (deskey != NULL)
136 { 136 {
137 des_set_key(&deskey[0],ctx->c.des_ede.ks1); 137 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
138 des_set_key(&deskey[1],ctx->c.des_ede.ks2); 138 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
139 des_set_key(&deskey[2],ctx->c.des_ede.ks3); 139 des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
140 } 140 }
141 } 141 }
142 142
diff --git a/src/lib/libcrypto/evp/e_cbc_d.c b/src/lib/libcrypto/evp/e_cbc_d.c
index 9203f3f52d..5b4e5b8601 100644
--- a/src/lib/libcrypto/evp/e_cbc_d.c
+++ b/src/lib/libcrypto/evp/e_cbc_d.c
@@ -93,7 +93,7 @@ static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
93 memcpy(&(ctx->oiv[0]),iv,8); 93 memcpy(&(ctx->oiv[0]),iv,8);
94 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 94 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
95 if (deskey != NULL) 95 if (deskey != NULL)
96 des_set_key(deskey,ctx->c.des_ks); 96 des_set_key_unchecked(deskey,ctx->c.des_ks);
97 } 97 }
98 98
99static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 99static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
diff --git a/src/lib/libcrypto/evp/e_cfb_3d.c b/src/lib/libcrypto/evp/e_cfb_3d.c
index bd32b072e2..b364bd4e31 100644
--- a/src/lib/libcrypto/evp/e_cfb_3d.c
+++ b/src/lib/libcrypto/evp/e_cfb_3d.c
@@ -116,8 +116,8 @@ static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
116 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 116 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
117 if (deskey != NULL) 117 if (deskey != NULL)
118 { 118 {
119 des_set_key(&deskey[0],ctx->c.des_ede.ks1); 119 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
120 des_set_key(&deskey[1],ctx->c.des_ede.ks2); 120 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
121 memcpy( (char *)ctx->c.des_ede.ks3, 121 memcpy( (char *)ctx->c.des_ede.ks3,
122 (char *)ctx->c.des_ede.ks1, 122 (char *)ctx->c.des_ede.ks1,
123 sizeof(ctx->c.des_ede.ks1)); 123 sizeof(ctx->c.des_ede.ks1));
@@ -136,9 +136,9 @@ static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
136 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 136 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
137 if (deskey != NULL) 137 if (deskey != NULL)
138 { 138 {
139 des_set_key(&deskey[0],ctx->c.des_ede.ks1); 139 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
140 des_set_key(&deskey[1],ctx->c.des_ede.ks2); 140 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
141 des_set_key(&deskey[2],ctx->c.des_ede.ks3); 141 des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
142 } 142 }
143 } 143 }
144 144
diff --git a/src/lib/libcrypto/evp/e_cfb_d.c b/src/lib/libcrypto/evp/e_cfb_d.c
index 6bdf20b646..9e1714bd15 100644
--- a/src/lib/libcrypto/evp/e_cfb_d.c
+++ b/src/lib/libcrypto/evp/e_cfb_d.c
@@ -95,7 +95,7 @@ static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95 memcpy(&(ctx->oiv[0]),iv,8); 95 memcpy(&(ctx->oiv[0]),iv,8);
96 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 96 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
97 if (deskey != NULL) 97 if (deskey != NULL)
98 des_set_key(deskey,ctx->c.des_ks); 98 des_set_key_unchecked(deskey,ctx->c.des_ks);
99 } 99 }
100 100
101static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 101static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
diff --git a/src/lib/libcrypto/evp/e_ecb_3d.c b/src/lib/libcrypto/evp/e_ecb_3d.c
index 354a8b79a7..806e971d36 100644
--- a/src/lib/libcrypto/evp/e_ecb_3d.c
+++ b/src/lib/libcrypto/evp/e_ecb_3d.c
@@ -110,8 +110,8 @@ static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
110 110
111 if (deskey != NULL) 111 if (deskey != NULL)
112 { 112 {
113 des_set_key(&deskey[0],ctx->c.des_ede.ks1); 113 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
114 des_set_key(&deskey[1],ctx->c.des_ede.ks2); 114 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
115 memcpy( (char *)ctx->c.des_ede.ks3, 115 memcpy( (char *)ctx->c.des_ede.ks3,
116 (char *)ctx->c.des_ede.ks1, 116 (char *)ctx->c.des_ede.ks1,
117 sizeof(ctx->c.des_ede.ks1)); 117 sizeof(ctx->c.des_ede.ks1));
@@ -125,9 +125,9 @@ static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
125 125
126 if (deskey != NULL) 126 if (deskey != NULL)
127 { 127 {
128 des_set_key(&deskey[0],ctx->c.des_ede.ks1); 128 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
129 des_set_key(&deskey[1],ctx->c.des_ede.ks2); 129 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
130 des_set_key(&deskey[2],ctx->c.des_ede.ks3); 130 des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
131 } 131 }
132 } 132 }
133 133
diff --git a/src/lib/libcrypto/evp/e_ecb_d.c b/src/lib/libcrypto/evp/e_ecb_d.c
index 5fb4e64b1c..c11bef55ef 100644
--- a/src/lib/libcrypto/evp/e_ecb_d.c
+++ b/src/lib/libcrypto/evp/e_ecb_d.c
@@ -90,7 +90,7 @@ static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
90 des_cblock *deskey = (des_cblock *)key; 90 des_cblock *deskey = (des_cblock *)key;
91 91
92 if (deskey != NULL) 92 if (deskey != NULL)
93 des_set_key(deskey,ctx->c.des_ks); 93 des_set_key_unchecked(deskey,ctx->c.des_ks);
94 } 94 }
95 95
96static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 96static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
diff --git a/src/lib/libcrypto/evp/e_ofb_3d.c b/src/lib/libcrypto/evp/e_ofb_3d.c
index 5233567c0c..d1a33e2ecd 100644
--- a/src/lib/libcrypto/evp/e_ofb_3d.c
+++ b/src/lib/libcrypto/evp/e_ofb_3d.c
@@ -116,8 +116,8 @@ static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
116 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 116 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
117 if (deskey != NULL) 117 if (deskey != NULL)
118 { 118 {
119 des_set_key(&deskey[0],ctx->c.des_ede.ks1); 119 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
120 des_set_key(&deskey[1],ctx->c.des_ede.ks2); 120 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
121 memcpy( (char *)ctx->c.des_ede.ks3, 121 memcpy( (char *)ctx->c.des_ede.ks3,
122 (char *)ctx->c.des_ede.ks1, 122 (char *)ctx->c.des_ede.ks1,
123 sizeof(ctx->c.des_ede.ks1)); 123 sizeof(ctx->c.des_ede.ks1));
@@ -136,9 +136,9 @@ static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
136 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 136 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
137 if (deskey != NULL) 137 if (deskey != NULL)
138 { 138 {
139 des_set_key(&deskey[0],ctx->c.des_ede.ks1); 139 des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
140 des_set_key(&deskey[1],ctx->c.des_ede.ks2); 140 des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
141 des_set_key(&deskey[2],ctx->c.des_ede.ks3); 141 des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
142 } 142 }
143 } 143 }
144 144
diff --git a/src/lib/libcrypto/evp/e_ofb_d.c b/src/lib/libcrypto/evp/e_ofb_d.c
index 398b3a002e..d51ce230f4 100644
--- a/src/lib/libcrypto/evp/e_ofb_d.c
+++ b/src/lib/libcrypto/evp/e_ofb_d.c
@@ -95,7 +95,7 @@ static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95 memcpy(&(ctx->oiv[0]),iv,8); 95 memcpy(&(ctx->oiv[0]),iv,8);
96 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 96 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
97 if (deskey != NULL) 97 if (deskey != NULL)
98 des_set_key(deskey,ctx->c.des_ks); 98 des_set_key_unchecked(deskey,ctx->c.des_ks);
99 } 99 }
100 100
101static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 101static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c
index 3a6628a75c..7568fad4ff 100644
--- a/src/lib/libcrypto/evp/e_xcbc_d.c
+++ b/src/lib/libcrypto/evp/e_xcbc_d.c
@@ -94,7 +94,7 @@ static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
94 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 94 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
95 if (deskey != NULL) 95 if (deskey != NULL)
96 { 96 {
97 des_set_key(deskey,ctx->c.desx_cbc.ks); 97 des_set_key_unchecked(deskey,ctx->c.desx_cbc.ks);
98 memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); 98 memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8);
99 memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); 99 memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8);
100 } 100 }
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c
index 0152624a76..14a4cb11f6 100644
--- a/src/lib/libcrypto/evp/encode.c
+++ b/src/lib/libcrypto/evp/encode.c
@@ -185,7 +185,7 @@ void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
185 *outl=ret; 185 *outl=ret;
186 } 186 }
187 187
188int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int dlen) 188int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen)
189 { 189 {
190 int i,ret=0; 190 int i,ret=0;
191 unsigned long l; 191 unsigned long l;
@@ -337,7 +337,7 @@ end:
337 return(rv); 337 return(rv);
338 } 338 }
339 339
340int EVP_DecodeBlock(unsigned char *t, unsigned char *f, int n) 340int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n)
341 { 341 {
342 int i,ret=0,a,b,c,d; 342 int i,ret=0,a,b,c,d;
343 unsigned long l; 343 unsigned long l;
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index 570fe27d39..54215b0905 100644
--- a/src/lib/libcrypto/evp/evp.h
+++ b/src/lib/libcrypto/evp/evp.h
@@ -149,7 +149,7 @@ extern "C" {
149 149
150/* Type needs to be a bit field 150/* Type needs to be a bit field
151 * Sub-type needs to be for variations on the method, as in, can it do 151 * Sub-type needs to be for variations on the method, as in, can it do
152 * arbitary encryption.... */ 152 * arbitrary encryption.... */
153typedef struct evp_pkey_st 153typedef struct evp_pkey_st
154 { 154 {
155 int type; 155 int type;
@@ -343,7 +343,7 @@ typedef struct evp_cipher_ctx_st
343 unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */ 343 unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */
344 int num; /* used by cfb/ofb mode */ 344 int num; /* used by cfb/ofb mode */
345 345
346 char *app_data; /* aplication stuff */ 346 char *app_data; /* application stuff */
347 union { 347 union {
348#ifndef NO_RC4 348#ifndef NO_RC4
349 struct 349 struct
@@ -421,9 +421,10 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
421#define EVP_MD_size(e) ((e)->md_size) 421#define EVP_MD_size(e) ((e)->md_size)
422#define EVP_MD_block_size(e) ((e)->block_size) 422#define EVP_MD_block_size(e) ((e)->block_size)
423 423
424#define EVP_MD_CTX_md(e) ((e)->digest)
424#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest) 425#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
425#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest) 426#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
426#define EVP_MD_CTX_type(e) ((e)->digest) 427#define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
427 428
428#define EVP_CIPHER_nid(e) ((e)->nid) 429#define EVP_CIPHER_nid(e) ((e)->nid)
429#define EVP_CIPHER_block_size(e) ((e)->block_size) 430#define EVP_CIPHER_block_size(e) ((e)->block_size)
@@ -521,15 +522,14 @@ void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
521void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out, 522void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
522 int *outl,unsigned char *in,int inl); 523 int *outl,unsigned char *in,int inl);
523void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl); 524void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
524int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int n); 525int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
525 526
526void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); 527void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
527int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl, 528int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
528 unsigned char *in, int inl); 529 unsigned char *in, int inl);
529int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned 530int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
530 char *out, int *outl); 531 char *out, int *outl);
531int EVP_DecodeBlock(unsigned char *t, unsigned 532int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
532 char *f, int n);
533 533
534void ERR_load_EVP_strings(void ); 534void ERR_load_EVP_strings(void );
535 535
@@ -594,9 +594,12 @@ EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
594EVP_CIPHER *EVP_rc5_32_12_16_cfb(void); 594EVP_CIPHER *EVP_rc5_32_12_16_cfb(void);
595EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); 595EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
596 596
597void SSLeay_add_all_algorithms(void); 597void OpenSSL_add_all_algorithms(void);
598void SSLeay_add_all_ciphers(void); 598void OpenSSL_add_all_ciphers(void);
599void SSLeay_add_all_digests(void); 599void OpenSSL_add_all_digests(void);
600#define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms()
601#define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers()
602#define SSLeay_add_all_digests() OpenSSL_add_all_digests()
600 603
601int EVP_add_cipher(EVP_CIPHER *cipher); 604int EVP_add_cipher(EVP_CIPHER *cipher);
602int EVP_add_digest(EVP_MD *digest); 605int EVP_add_digest(EVP_MD *digest);
@@ -613,6 +616,18 @@ int EVP_PKEY_type(int type);
613int EVP_PKEY_bits(EVP_PKEY *pkey); 616int EVP_PKEY_bits(EVP_PKEY *pkey);
614int EVP_PKEY_size(EVP_PKEY *pkey); 617int EVP_PKEY_size(EVP_PKEY *pkey);
615int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key); 618int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
619#ifndef NO_RSA
620int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key);
621RSA * EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
622#endif
623#ifndef NO_DSA
624int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key);
625DSA * EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
626#endif
627#ifndef NO_DH
628int EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key);
629DH * EVP_PKEY_get1_DH(EVP_PKEY *pkey);
630#endif
616EVP_PKEY * EVP_PKEY_new(void); 631EVP_PKEY * EVP_PKEY_new(void);
617void EVP_PKEY_free(EVP_PKEY *pkey); 632void EVP_PKEY_free(EVP_PKEY *pkey);
618EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp, 633EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
@@ -621,6 +636,8 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
621 636
622EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp, 637EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
623 long length); 638 long length);
639EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
640 long length);
624int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); 641int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
625 642
626int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from); 643int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
@@ -677,6 +694,9 @@ void EVP_PBE_cleanup(void);
677#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 694#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
678#define EVP_F_EVP_PKEY_DECRYPT 104 695#define EVP_F_EVP_PKEY_DECRYPT 104
679#define EVP_F_EVP_PKEY_ENCRYPT 105 696#define EVP_F_EVP_PKEY_ENCRYPT 105
697#define EVP_F_EVP_PKEY_GET1_DH 119
698#define EVP_F_EVP_PKEY_GET1_DSA 120
699#define EVP_F_EVP_PKEY_GET1_RSA 121
680#define EVP_F_EVP_PKEY_NEW 106 700#define EVP_F_EVP_PKEY_NEW 106
681#define EVP_F_EVP_SIGNFINAL 107 701#define EVP_F_EVP_SIGNFINAL 107
682#define EVP_F_EVP_VERIFYFINAL 108 702#define EVP_F_EVP_VERIFYFINAL 108
@@ -693,10 +713,13 @@ void EVP_PBE_cleanup(void);
693#define EVP_R_DIFFERENT_KEY_TYPES 101 713#define EVP_R_DIFFERENT_KEY_TYPES 101
694#define EVP_R_ENCODE_ERROR 115 714#define EVP_R_ENCODE_ERROR 115
695#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119 715#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
716#define EVP_R_EXPECTING_AN_RSA_KEY 127
717#define EVP_R_EXPECTING_A_DH_KEY 128
718#define EVP_R_EXPECTING_A_DSA_KEY 129
696#define EVP_R_INPUT_NOT_INITIALIZED 111 719#define EVP_R_INPUT_NOT_INITIALIZED 111
697#define EVP_R_IV_TOO_LARGE 102 720#define EVP_R_IV_TOO_LARGE 102
698#define EVP_R_KEYGEN_FAILURE 120 721#define EVP_R_KEYGEN_FAILURE 120
699#define EVP_R_MISSING_PARMATERS 103 722#define EVP_R_MISSING_PARAMETERS 103
700#define EVP_R_NO_DSA_PARAMETERS 116 723#define EVP_R_NO_DSA_PARAMETERS 116
701#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 724#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
702#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 725#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
index c61cc922e8..97953a0fc1 100644
--- a/src/lib/libcrypto/evp/evp_err.c
+++ b/src/lib/libcrypto/evp/evp_err.c
@@ -77,6 +77,9 @@ static ERR_STRING_DATA EVP_str_functs[]=
77{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"}, 77{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
78{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"}, 78{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
79{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"}, 79{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
80{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DH,0), "EVP_PKEY_get1_DH"},
81{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DSA,0), "EVP_PKEY_get1_DSA"},
82{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_RSA,0), "EVP_PKEY_get1_RSA"},
80{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"}, 83{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
81{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"}, 84{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
82{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"}, 85{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
@@ -96,10 +99,13 @@ static ERR_STRING_DATA EVP_str_reasons[]=
96{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"}, 99{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
97{EVP_R_ENCODE_ERROR ,"encode error"}, 100{EVP_R_ENCODE_ERROR ,"encode error"},
98{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"}, 101{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"},
102{EVP_R_EXPECTING_AN_RSA_KEY ,"expecting an rsa key"},
103{EVP_R_EXPECTING_A_DH_KEY ,"expecting a dh key"},
104{EVP_R_EXPECTING_A_DSA_KEY ,"expecting a dsa key"},
99{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"}, 105{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"},
100{EVP_R_IV_TOO_LARGE ,"iv too large"}, 106{EVP_R_IV_TOO_LARGE ,"iv too large"},
101{EVP_R_KEYGEN_FAILURE ,"keygen failure"}, 107{EVP_R_KEYGEN_FAILURE ,"keygen failure"},
102{EVP_R_MISSING_PARMATERS ,"missing parmaters"}, 108{EVP_R_MISSING_PARAMETERS ,"missing parameters"},
103{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"}, 109{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"},
104{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"}, 110{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
105{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"}, 111{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
index 21eda418bc..667c21cca8 100644
--- a/src/lib/libcrypto/evp/evp_key.c
+++ b/src/lib/libcrypto/evp/evp_key.c
@@ -81,15 +81,18 @@ char *EVP_get_pw_prompt(void)
81 return(prompt_string); 81 return(prompt_string);
82 } 82 }
83 83
84#ifdef NO_DES 84/* For historical reasons, the standard function for reading passwords is
85int des_read_pw_string(char *buf,int len,const char *prompt,int verify); 85 * in the DES library -- if someone ever wants to disable DES,
86#endif 86 * this function will fail */
87
88int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) 87int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
89 { 88 {
89#ifndef NO_DES
90 if ((prompt == NULL) && (prompt_string[0] != '\0')) 90 if ((prompt == NULL) && (prompt_string[0] != '\0'))
91 prompt=prompt_string; 91 prompt=prompt_string;
92 return(des_read_pw_string(buf,len,prompt,verify)); 92 return(des_read_pw_string(buf,len,prompt,verify));
93#else
94 return -1;
95#endif
93 } 96 }
94 97
95int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, unsigned char *salt, 98int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, unsigned char *salt,
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
index 3f9bf55828..a431945ef5 100644
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ b/src/lib/libcrypto/evp/evp_lib.c
@@ -115,6 +115,7 @@ int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
115int EVP_CIPHER_type(const EVP_CIPHER *ctx) 115int EVP_CIPHER_type(const EVP_CIPHER *ctx)
116{ 116{
117 int nid; 117 int nid;
118 ASN1_OBJECT *otmp;
118 nid = EVP_CIPHER_nid(ctx); 119 nid = EVP_CIPHER_nid(ctx);
119 120
120 switch(nid) { 121 switch(nid) {
@@ -131,7 +132,10 @@ int EVP_CIPHER_type(const EVP_CIPHER *ctx)
131 return NID_rc4; 132 return NID_rc4;
132 133
133 default: 134 default:
134 135 /* Check it has an OID and it is valid */
136 otmp = OBJ_nid2obj(nid);
137 if(!otmp || !otmp->data) nid = NID_undef;
138 ASN1_OBJECT_free(otmp);
135 return nid; 139 return nid;
136 } 140 }
137} 141}
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
index 421e452db1..d5e6f5880f 100644
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -62,19 +62,22 @@
62#include <openssl/x509.h> 62#include <openssl/x509.h>
63#include <openssl/rand.h> 63#include <openssl/rand.h>
64 64
65static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
66
65/* Extract a private key from a PKCS8 structure */ 67/* Extract a private key from a PKCS8 structure */
66 68
67EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8) 69EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
68{ 70{
69 EVP_PKEY *pkey; 71 EVP_PKEY *pkey = NULL;
70#ifndef NO_RSA 72#ifndef NO_RSA
71 RSA *rsa; 73 RSA *rsa = NULL;
72#endif 74#endif
73#ifndef NO_DSA 75#ifndef NO_DSA
74 DSA *dsa; 76 DSA *dsa = NULL;
75 ASN1_INTEGER *dsapriv; 77 ASN1_INTEGER *privkey;
76 STACK *ndsa; 78 ASN1_TYPE *t1, *t2, *param = NULL;
77 BN_CTX *ctx; 79 STACK *ndsa = NULL;
80 BN_CTX *ctx = NULL;
78 int plen; 81 int plen;
79#endif 82#endif
80 X509_ALGOR *a; 83 X509_ALGOR *a;
@@ -82,21 +85,14 @@ EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
82 int pkeylen; 85 int pkeylen;
83 char obj_tmp[80]; 86 char obj_tmp[80];
84 87
85 switch (p8->broken) { 88 if(p8->pkey->type == V_ASN1_OCTET_STRING) {
86 case PKCS8_OK: 89 p8->broken = PKCS8_OK;
87 p = p8->pkey->value.octet_string->data; 90 p = p8->pkey->value.octet_string->data;
88 pkeylen = p8->pkey->value.octet_string->length; 91 pkeylen = p8->pkey->value.octet_string->length;
89 break; 92 } else {
90 93 p8->broken = PKCS8_NO_OCTET;
91 case PKCS8_NO_OCTET:
92 p = p8->pkey->value.sequence->data; 94 p = p8->pkey->value.sequence->data;
93 pkeylen = p8->pkey->value.sequence->length; 95 pkeylen = p8->pkey->value.sequence->length;
94 break;
95
96 default:
97 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
98 return NULL;
99 break;
100 } 96 }
101 if (!(pkey = EVP_PKEY_new())) { 97 if (!(pkey = EVP_PKEY_new())) {
102 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); 98 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
@@ -121,65 +117,83 @@ EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
121 * be recalculated. 117 * be recalculated.
122 */ 118 */
123 119
124 /* Check for broken Netscape Database DSA PKCS#8, UGH! */ 120 /* Check for broken DSA PKCS#8, UGH! */
125 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) { 121 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
126 if(!(ndsa = ASN1_seq_unpack(p, pkeylen, 122 if(!(ndsa = ASN1_seq_unpack(p, pkeylen,
127 (char *(*)())d2i_ASN1_INTEGER, 123 (char *(*)())d2i_ASN1_TYPE,
128 ASN1_STRING_free))) { 124 ASN1_TYPE_free))) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); 125 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 return NULL; 126 goto dsaerr;
131 } 127 }
132 if(sk_num(ndsa) != 2 ) { 128 if(sk_num(ndsa) != 2 ) {
133 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); 129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
134 sk_pop_free(ndsa, ASN1_STRING_free); 130 goto dsaerr;
135 return NULL;
136 } 131 }
137 dsapriv = (ASN1_INTEGER *) sk_pop(ndsa); 132 /* Handle Two broken types:
138 sk_pop_free(ndsa, ASN1_STRING_free); 133 * SEQUENCE {parameters, priv_key}
139 } else if (!(dsapriv=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) { 134 * SEQUENCE {pub_key, priv_key}
135 */
136
137 t1 = (ASN1_TYPE *)sk_value(ndsa, 0);
138 t2 = (ASN1_TYPE *)sk_value(ndsa, 1);
139 if(t1->type == V_ASN1_SEQUENCE) {
140 p8->broken = PKCS8_EMBEDDED_PARAM;
141 param = t1;
142 } else if(a->parameter->type == V_ASN1_SEQUENCE) {
143 p8->broken = PKCS8_NS_DB;
144 param = a->parameter;
145 } else {
140 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); 146 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
141 return NULL; 147 goto dsaerr;
142 } 148 }
143 /* Retrieve parameters */ 149
144 if (a->parameter->type != V_ASN1_SEQUENCE) { 150 if(t2->type != V_ASN1_INTEGER) {
145 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_NO_DSA_PARAMETERS); 151 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
146 return NULL; 152 goto dsaerr;
153 }
154 privkey = t2->value.integer;
155 } else if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
156 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
157 goto dsaerr;
147 } 158 }
148 p = a->parameter->value.sequence->data; 159 p = param->value.sequence->data;
149 plen = a->parameter->value.sequence->length; 160 plen = param->value.sequence->length;
150 if (!(dsa = d2i_DSAparams (NULL, &p, plen))) { 161 if (!(dsa = d2i_DSAparams (NULL, &p, plen))) {
151 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); 162 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
152 return NULL; 163 goto dsaerr;
153 } 164 }
154 /* We have parameters now set private key */ 165 /* We have parameters now set private key */
155 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(dsapriv, NULL))) { 166 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
156 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR); 167 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
157 DSA_free (dsa); 168 goto dsaerr;
158 return NULL;
159 } 169 }
160 /* Calculate public key (ouch!) */ 170 /* Calculate public key (ouch!) */
161 if (!(dsa->pub_key = BN_new())) { 171 if (!(dsa->pub_key = BN_new())) {
162 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); 172 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
163 DSA_free (dsa); 173 goto dsaerr;
164 return NULL;
165 } 174 }
166 if (!(ctx = BN_CTX_new())) { 175 if (!(ctx = BN_CTX_new())) {
167 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); 176 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
168 DSA_free (dsa); 177 goto dsaerr;
169 return NULL;
170 } 178 }
171 179
172 if (!BN_mod_exp(dsa->pub_key, dsa->g, 180 if (!BN_mod_exp(dsa->pub_key, dsa->g,
173 dsa->priv_key, dsa->p, ctx)) { 181 dsa->priv_key, dsa->p, ctx)) {
174 182
175 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR); 183 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
176 BN_CTX_free (ctx); 184 goto dsaerr;
177 DSA_free (dsa);
178 return NULL;
179 } 185 }
180 186
181 EVP_PKEY_assign_DSA (pkey, dsa); 187 EVP_PKEY_assign_DSA(pkey, dsa);
182 BN_CTX_free (ctx); 188 BN_CTX_free (ctx);
189 sk_pop_free(ndsa, ASN1_TYPE_free);
190 break;
191 dsaerr:
192 BN_CTX_free (ctx);
193 sk_pop_free(ndsa, ASN1_TYPE_free);
194 DSA_free(dsa);
195 EVP_PKEY_free(pkey);
196 return NULL;
183 break; 197 break;
184#endif 198#endif
185 default: 199 default:
@@ -193,30 +207,35 @@ EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
193 return pkey; 207 return pkey;
194} 208}
195 209
210PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
211{
212 return EVP_PKEY2PKCS8_broken(pkey, PKCS8_OK);
213}
214
196/* Turn a private key into a PKCS8 structure */ 215/* Turn a private key into a PKCS8 structure */
197 216
198PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey) 217PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
199{ 218{
200 PKCS8_PRIV_KEY_INFO *p8; 219 PKCS8_PRIV_KEY_INFO *p8;
201#ifndef NO_DSA 220
202 ASN1_INTEGER *dpkey;
203 unsigned char *p, *q;
204 int len;
205#endif
206 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) { 221 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
207 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 222 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
208 return NULL; 223 return NULL;
209 } 224 }
225 p8->broken = broken;
210 ASN1_INTEGER_set (p8->version, 0); 226 ASN1_INTEGER_set (p8->version, 0);
211 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) { 227 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
212 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 228 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
213 PKCS8_PRIV_KEY_INFO_free (p8); 229 PKCS8_PRIV_KEY_INFO_free (p8);
214 return NULL; 230 return NULL;
215 } 231 }
232 p8->pkey->type = V_ASN1_OCTET_STRING;
216 switch (EVP_PKEY_type(pkey->type)) { 233 switch (EVP_PKEY_type(pkey->type)) {
217#ifndef NO_RSA 234#ifndef NO_RSA
218 case EVP_PKEY_RSA: 235 case EVP_PKEY_RSA:
219 236
237 if(p8->broken == PKCS8_NO_OCTET) p8->pkey->type = V_ASN1_SEQUENCE;
238
220 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption); 239 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
221 p8->pkeyalg->parameter->type = V_ASN1_NULL; 240 p8->pkeyalg->parameter->type = V_ASN1_NULL;
222 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey, 241 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
@@ -229,36 +248,11 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
229#endif 248#endif
230#ifndef NO_DSA 249#ifndef NO_DSA
231 case EVP_PKEY_DSA: 250 case EVP_PKEY_DSA:
232 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa); 251 if(!dsa_pkey2pkcs8(p8, pkey)) {
233
234 /* get paramaters and place in AlgorithmIdentifier */
235 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
236 if (!(p = Malloc(len))) {
237 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
238 PKCS8_PRIV_KEY_INFO_free (p8); 252 PKCS8_PRIV_KEY_INFO_free (p8);
239 return NULL; 253 return NULL;
240 } 254 }
241 q = p; 255
242 i2d_DSAparams (pkey->pkey.dsa, &q);
243 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
244 p8->pkeyalg->parameter->value.sequence = ASN1_STRING_new();
245 ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, len);
246 Free(p);
247 /* Get private key into an integer and pack */
248 if (!(dpkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
249 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
250 PKCS8_PRIV_KEY_INFO_free (p8);
251 return NULL;
252 }
253
254 if (!ASN1_pack_string((char *)dpkey, i2d_ASN1_INTEGER,
255 &p8->pkey->value.octet_string)) {
256 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
257 ASN1_INTEGER_free (dpkey);
258 PKCS8_PRIV_KEY_INFO_free (p8);
259 return NULL;
260 }
261 ASN1_INTEGER_free (dpkey);
262 break; 256 break;
263#endif 257#endif
264 default: 258 default:
@@ -266,9 +260,8 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
266 PKCS8_PRIV_KEY_INFO_free (p8); 260 PKCS8_PRIV_KEY_INFO_free (p8);
267 return NULL; 261 return NULL;
268 } 262 }
269 p8->pkey->type = V_ASN1_OCTET_STRING; 263 RAND_add(p8->pkey->value.octet_string->data,
270 RAND_seed (p8->pkey->value.octet_string->data, 264 p8->pkey->value.octet_string->length, 0);
271 p8->pkey->value.octet_string->length);
272 return p8; 265 return p8;
273} 266}
274 267
@@ -295,4 +288,112 @@ PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
295 } 288 }
296} 289}
297 290
291#ifndef NO_DSA
292static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
293{
294 ASN1_STRING *params;
295 ASN1_INTEGER *prkey;
296 ASN1_TYPE *ttmp;
297 STACK *ndsa;
298 unsigned char *p, *q;
299 int len;
300 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
301 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
302 if (!(p = Malloc(len))) {
303 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
304 PKCS8_PRIV_KEY_INFO_free (p8);
305 return 0;
306 }
307 q = p;
308 i2d_DSAparams (pkey->pkey.dsa, &q);
309 params = ASN1_STRING_new();
310 ASN1_STRING_set(params, p, len);
311 Free(p);
312 /* Get private key into integer */
313 if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
314 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
315 return 0;
316 }
317
318 switch(p8->broken) {
298 319
320 case PKCS8_OK:
321 case PKCS8_NO_OCTET:
322
323 if (!ASN1_pack_string((char *)prkey, i2d_ASN1_INTEGER,
324 &p8->pkey->value.octet_string)) {
325 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
326 M_ASN1_INTEGER_free (prkey);
327 return 0;
328 }
329
330 M_ASN1_INTEGER_free (prkey);
331 p8->pkeyalg->parameter->value.sequence = params;
332 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
333
334 break;
335
336 case PKCS8_NS_DB:
337
338 p8->pkeyalg->parameter->value.sequence = params;
339 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
340 ndsa = sk_new_null();
341 ttmp = ASN1_TYPE_new();
342 if (!(ttmp->value.integer = BN_to_ASN1_INTEGER (pkey->pkey.dsa->pub_key, NULL))) {
343 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
344 PKCS8_PRIV_KEY_INFO_free(p8);
345 return 0;
346 }
347 ttmp->type = V_ASN1_INTEGER;
348 sk_push(ndsa, (char *)ttmp);
349
350 ttmp = ASN1_TYPE_new();
351 ttmp->value.integer = prkey;
352 ttmp->type = V_ASN1_INTEGER;
353 sk_push(ndsa, (char *)ttmp);
354
355 p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
356
357 if (!ASN1_seq_pack(ndsa, i2d_ASN1_TYPE,
358 &p8->pkey->value.octet_string->data,
359 &p8->pkey->value.octet_string->length)) {
360
361 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
362 sk_pop_free(ndsa, ASN1_TYPE_free);
363 M_ASN1_INTEGER_free(prkey);
364 return 0;
365 }
366 sk_pop_free(ndsa, ASN1_TYPE_free);
367 break;
368
369 case PKCS8_EMBEDDED_PARAM:
370
371 p8->pkeyalg->parameter->type = V_ASN1_NULL;
372 ndsa = sk_new_null();
373 ttmp = ASN1_TYPE_new();
374 ttmp->value.sequence = params;
375 ttmp->type = V_ASN1_SEQUENCE;
376 sk_push(ndsa, (char *)ttmp);
377
378 ttmp = ASN1_TYPE_new();
379 ttmp->value.integer = prkey;
380 ttmp->type = V_ASN1_INTEGER;
381 sk_push(ndsa, (char *)ttmp);
382
383 p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
384
385 if (!ASN1_seq_pack(ndsa, i2d_ASN1_TYPE,
386 &p8->pkey->value.octet_string->data,
387 &p8->pkey->value.octet_string->length)) {
388
389 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
390 sk_pop_free(ndsa, ASN1_TYPE_free);
391 M_ASN1_INTEGER_free (prkey);
392 return 0;
393 }
394 sk_pop_free(ndsa, ASN1_TYPE_free);
395 break;
396 }
397 return 1;
398}
399#endif
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 3422b77de6..4cb387f8de 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -119,7 +119,7 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
119 119
120 if (EVP_PKEY_missing_parameters(from)) 120 if (EVP_PKEY_missing_parameters(from))
121 { 121 {
122 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARMATERS); 122 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
123 goto err; 123 goto err;
124 } 124 }
125#ifndef NO_DSA 125#ifndef NO_DSA
@@ -202,8 +202,66 @@ int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
202 pkey->type=EVP_PKEY_type(type); 202 pkey->type=EVP_PKEY_type(type);
203 pkey->save_type=type; 203 pkey->save_type=type;
204 pkey->pkey.ptr=key; 204 pkey->pkey.ptr=key;
205 return(1); 205 return(key != NULL);
206 }
207
208#ifndef NO_RSA
209int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
210{
211 int ret = EVP_PKEY_assign_RSA(pkey, key);
212 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_RSA);
213 return ret;
214}
215
216RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
217 {
218 if(pkey->type != EVP_PKEY_RSA) {
219 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
220 return NULL;
221 }
222 CRYPTO_add(&pkey->pkey.rsa->references, 1, CRYPTO_LOCK_RSA);
223 return pkey->pkey.rsa;
224}
225#endif
226
227#ifndef NO_DSA
228int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
229{
230 int ret = EVP_PKEY_assign_DSA(pkey, key);
231 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_DSA);
232 return ret;
233}
234
235DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
236 {
237 if(pkey->type != EVP_PKEY_DSA) {
238 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
239 return NULL;
240 }
241 CRYPTO_add(&pkey->pkey.dsa->references, 1, CRYPTO_LOCK_DSA);
242 return pkey->pkey.dsa;
243}
244#endif
245
246#ifndef NO_DH
247
248int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
249{
250 int ret = EVP_PKEY_assign_DH(pkey, key);
251 if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_DH);
252 return ret;
253}
254
255DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
256 {
257 if(pkey->type != EVP_PKEY_DH) {
258 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
259 return NULL;
206 } 260 }
261 CRYPTO_add(&pkey->pkey.dh->references, 1, CRYPTO_LOCK_DH);
262 return pkey->pkey.dh;
263}
264#endif
207 265
208int EVP_PKEY_type(int type) 266int EVP_PKEY_type(int type)
209 { 267 {
@@ -244,7 +302,7 @@ void EVP_PKEY_free(EVP_PKEY *x)
244 } 302 }
245#endif 303#endif
246 EVP_PKEY_free_it(x); 304 EVP_PKEY_free_it(x);
247 Free((char *)x); 305 Free(x);
248 } 306 }
249 307
250static void EVP_PKEY_free_it(EVP_PKEY *x) 308static void EVP_PKEY_free_it(EVP_PKEY *x)
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
index ddb9fd6942..b9ca7892c2 100644
--- a/src/lib/libcrypto/evp/p_open.c
+++ b/src/lib/libcrypto/evp/p_open.c
@@ -110,4 +110,10 @@ int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
110 EVP_DecryptInit(ctx,NULL,NULL,NULL); 110 EVP_DecryptInit(ctx,NULL,NULL,NULL);
111 return(i); 111 return(i);
112 } 112 }
113#else /* !NO_RSA */
114
115# ifdef PEDANTIC
116static void *dummy=&dummy;
117# endif
118
113#endif 119#endif
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c
index 09b46f4b0e..d449e892bf 100644
--- a/src/lib/libcrypto/evp/p_seal.c
+++ b/src/lib/libcrypto/evp/p_seal.c
@@ -73,9 +73,10 @@ int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
73 int i; 73 int i;
74 74
75 if (npubk <= 0) return(0); 75 if (npubk <= 0) return(0);
76 RAND_bytes(key,EVP_MAX_KEY_LENGTH); 76 if (RAND_bytes(key,EVP_MAX_KEY_LENGTH) <= 0)
77 return(0);
77 if (type->iv_len > 0) 78 if (type->iv_len > 0)
78 RAND_bytes(iv,type->iv_len); 79 RAND_pseudo_bytes(iv,type->iv_len);
79 80
80 EVP_CIPHER_CTX_init(ctx); 81 EVP_CIPHER_CTX_init(ctx);
81 EVP_EncryptInit(ctx,type,key,iv); 82 EVP_EncryptInit(ctx,type,key,iv);
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c
index 176574766b..a057dd3b68 100644
--- a/src/lib/libcrypto/ex_data.c
+++ b/src/lib/libcrypto/ex_data.c
@@ -63,15 +63,15 @@
63#include <openssl/lhash.h> 63#include <openssl/lhash.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65 65
66int CRYPTO_get_ex_new_index(int idx, STACK **skp, long argl, char *argp, 66int CRYPTO_get_ex_new_index(int idx, STACK_OF(CRYPTO_EX_DATA_FUNCS) **skp, long argl, void *argp,
67 int (*new_func)(), int (*dup_func)(), void (*free_func)()) 67 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
68 { 68 {
69 int ret= -1; 69 int ret= -1;
70 CRYPTO_EX_DATA_FUNCS *a; 70 CRYPTO_EX_DATA_FUNCS *a;
71 71
72 MemCheck_off(); 72 MemCheck_off();
73 if (*skp == NULL) 73 if (*skp == NULL)
74 *skp=sk_new_null(); 74 *skp=sk_CRYPTO_EX_DATA_FUNCS_new_null();
75 if (*skp == NULL) 75 if (*skp == NULL)
76 { 76 {
77 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); 77 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
@@ -88,23 +88,23 @@ int CRYPTO_get_ex_new_index(int idx, STACK **skp, long argl, char *argp,
88 a->new_func=new_func; 88 a->new_func=new_func;
89 a->dup_func=dup_func; 89 a->dup_func=dup_func;
90 a->free_func=free_func; 90 a->free_func=free_func;
91 while (sk_num(*skp) <= idx) 91 while (sk_CRYPTO_EX_DATA_FUNCS_num(*skp) <= idx)
92 { 92 {
93 if (!sk_push(*skp,NULL)) 93 if (!sk_CRYPTO_EX_DATA_FUNCS_push(*skp,NULL))
94 { 94 {
95 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); 95 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
96 Free(a); 96 Free(a);
97 goto err; 97 goto err;
98 } 98 }
99 } 99 }
100 sk_set(*skp,idx, (char *)a); 100 sk_CRYPTO_EX_DATA_FUNCS_set(*skp,idx, a);
101 ret=idx; 101 ret=idx;
102err: 102err:
103 MemCheck_on(); 103 MemCheck_on();
104 return(idx); 104 return(idx);
105 } 105 }
106 106
107int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, char *val) 107int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val)
108 { 108 {
109 int i; 109 int i;
110 110
@@ -131,7 +131,7 @@ int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, char *val)
131 return(1); 131 return(1);
132 } 132 }
133 133
134char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad, int idx) 134void *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad, int idx)
135 { 135 {
136 if (ad->sk == NULL) 136 if (ad->sk == NULL)
137 return(0); 137 return(0);
@@ -145,7 +145,7 @@ char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad, int idx)
145 * being duplicated, a pointer to the 145 * being duplicated, a pointer to the
146 * 'new' object to be inserted, the index, and the argi/argp 146 * 'new' object to be inserted, the index, and the argi/argp
147 */ 147 */
148int CRYPTO_dup_ex_data(STACK *meth, CRYPTO_EX_DATA *to, 148int CRYPTO_dup_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, CRYPTO_EX_DATA *to,
149 CRYPTO_EX_DATA *from) 149 CRYPTO_EX_DATA *from)
150 { 150 {
151 int i,j,m,r; 151 int i,j,m,r;
@@ -154,14 +154,14 @@ int CRYPTO_dup_ex_data(STACK *meth, CRYPTO_EX_DATA *to,
154 154
155 if (meth == NULL) return(1); 155 if (meth == NULL) return(1);
156 if (from->sk == NULL) return(1); 156 if (from->sk == NULL) return(1);
157 m=sk_num(meth); 157 m=sk_CRYPTO_EX_DATA_FUNCS_num(meth);
158 j=sk_num(from->sk); 158 j=sk_num(from->sk);
159 for (i=0; i<j; i++) 159 for (i=0; i<j; i++)
160 { 160 {
161 from_d=CRYPTO_get_ex_data(from,i); 161 from_d=CRYPTO_get_ex_data(from,i);
162 if (i < m) 162 if (i < m)
163 { 163 {
164 mm=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i); 164 mm=sk_CRYPTO_EX_DATA_FUNCS_value(meth,i);
165 if (mm->dup_func != NULL) 165 if (mm->dup_func != NULL)
166 r=mm->dup_func(to,from,(char **)&from_d,i, 166 r=mm->dup_func(to,from,(char **)&from_d,i,
167 mm->argl,mm->argp); 167 mm->argl,mm->argp);
@@ -172,18 +172,18 @@ int CRYPTO_dup_ex_data(STACK *meth, CRYPTO_EX_DATA *to,
172 } 172 }
173 173
174/* Call each free callback */ 174/* Call each free callback */
175void CRYPTO_free_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad) 175void CRYPTO_free_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad)
176 { 176 {
177 CRYPTO_EX_DATA_FUNCS *m; 177 CRYPTO_EX_DATA_FUNCS *m;
178 char *ptr; 178 void *ptr;
179 int i,max; 179 int i,max;
180 180
181 if (meth != NULL) 181 if (meth != NULL)
182 { 182 {
183 max=sk_num(meth); 183 max=sk_CRYPTO_EX_DATA_FUNCS_num(meth);
184 for (i=0; i<max; i++) 184 for (i=0; i<max; i++)
185 { 185 {
186 m=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i); 186 m=sk_CRYPTO_EX_DATA_FUNCS_value(meth,i);
187 if ((m != NULL) && (m->free_func != NULL)) 187 if ((m != NULL) && (m->free_func != NULL))
188 { 188 {
189 ptr=CRYPTO_get_ex_data(ad,i); 189 ptr=CRYPTO_get_ex_data(ad,i);
@@ -198,19 +198,19 @@ void CRYPTO_free_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad)
198 } 198 }
199 } 199 }
200 200
201void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad) 201void CRYPTO_new_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad)
202 { 202 {
203 CRYPTO_EX_DATA_FUNCS *m; 203 CRYPTO_EX_DATA_FUNCS *m;
204 char *ptr; 204 void *ptr;
205 int i,max; 205 int i,max;
206 206
207 ad->sk=NULL; 207 ad->sk=NULL;
208 if (meth != NULL) 208 if (meth != NULL)
209 { 209 {
210 max=sk_num(meth); 210 max=sk_CRYPTO_EX_DATA_FUNCS_num(meth);
211 for (i=0; i<max; i++) 211 for (i=0; i<max; i++)
212 { 212 {
213 m=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i); 213 m=sk_CRYPTO_EX_DATA_FUNCS_value(meth,i);
214 if ((m != NULL) && (m->new_func != NULL)) 214 if ((m != NULL) && (m->new_func != NULL))
215 { 215 {
216 ptr=CRYPTO_get_ex_data(ad,i); 216 ptr=CRYPTO_get_ex_data(ad,i);
@@ -220,4 +220,4 @@ void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad)
220 } 220 }
221 } 221 }
222 222
223 223IMPLEMENT_STACK_OF(CRYPTO_EX_DATA_FUNCS)
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c
index 5c349bbb56..23b7c98f8f 100644
--- a/src/lib/libcrypto/hmac/hmac.c
+++ b/src/lib/libcrypto/hmac/hmac.c
@@ -109,7 +109,7 @@ void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
109 memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx)); 109 memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx));
110 } 110 }
111 111
112void HMAC_Update(HMAC_CTX *ctx, unsigned char *data, int len) 112void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len)
113 { 113 {
114 EVP_DigestUpdate(&(ctx->md_ctx),data,len); 114 EVP_DigestUpdate(&(ctx->md_ctx),data,len);
115 } 115 }
@@ -134,7 +134,7 @@ void HMAC_cleanup(HMAC_CTX *ctx)
134 } 134 }
135 135
136unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 136unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
137 unsigned char *d, int n, unsigned char *md, 137 const unsigned char *d, int n, unsigned char *md,
138 unsigned int *md_len) 138 unsigned int *md_len)
139 { 139 {
140 HMAC_CTX c; 140 HMAC_CTX c;
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
index f928975fcd..223eeda7f3 100644
--- a/src/lib/libcrypto/hmac/hmac.h
+++ b/src/lib/libcrypto/hmac/hmac.h
@@ -85,11 +85,11 @@ typedef struct hmac_ctx_st
85 85
86void HMAC_Init(HMAC_CTX *ctx, const void *key, int len, 86void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
87 const EVP_MD *md); 87 const EVP_MD *md);
88void HMAC_Update(HMAC_CTX *ctx,unsigned char *key, int len); 88void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
89void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 89void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
90void HMAC_cleanup(HMAC_CTX *ctx); 90void HMAC_cleanup(HMAC_CTX *ctx);
91unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 91unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
92 unsigned char *d, int n, unsigned char *md, 92 const unsigned char *d, int n, unsigned char *md,
93 unsigned int *md_len); 93 unsigned int *md_len);
94 94
95 95
diff --git a/src/lib/libcrypto/hmac/hmactest.c b/src/lib/libcrypto/hmac/hmactest.c
index 9a67dff36a..4b56b8ee13 100644
--- a/src/lib/libcrypto/hmac/hmactest.c
+++ b/src/lib/libcrypto/hmac/hmactest.c
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
73#include <openssl/ebcdic.h> 73#include <openssl/ebcdic.h>
74#endif 74#endif
75 75
76struct test_st 76static struct test_st
77 { 77 {
78 unsigned char key[16]; 78 unsigned char key[16];
79 int key_len; 79 int key_len;
diff --git a/src/lib/libcrypto/install.com b/src/lib/libcrypto/install.com
index b75d1b44b2..44cfc4e89a 100644
--- a/src/lib/libcrypto/install.com
+++ b/src/lib/libcrypto/install.com
@@ -90,6 +90,7 @@ $ COPY 'tmp' WRK_SSLINCLUDE: /LOG
90$ ELSE 90$ ELSE
91$ COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG 91$ COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG
92$ ENDIF 92$ ENDIF
93$ SET FILE/PROT=WORLD:RE WRK_SSLINCLUDE:'tmp'
93$ GOTO LOOP_SDIRS 94$ GOTO LOOP_SDIRS
94$ LOOP_SDIRS_END: 95$ LOOP_SDIRS_END:
95$ 96$
diff --git a/src/lib/libcrypto/lhash/Makefile.ssl b/src/lib/libcrypto/lhash/Makefile.ssl
index d6845d6caa..eef4000460 100644
--- a/src/lib/libcrypto/lhash/Makefile.ssl
+++ b/src/lib/libcrypto/lhash/Makefile.ssl
@@ -82,7 +82,8 @@ lh_stats.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82lh_stats.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 82lh_stats.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 83lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 84lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
85lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 85lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
86lh_stats.o: ../cryptlib.h 86lh_stats.o: ../../include/openssl/stack.h ../cryptlib.h
87lhash.o: ../../include/openssl/crypto.h ../../include/openssl/lhash.h 87lhash.o: ../../include/openssl/crypto.h ../../include/openssl/lhash.h
88lhash.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 88lhash.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
89lhash.o: ../../include/openssl/stack.h
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
index 801322beb6..6a340a2403 100644
--- a/src/lib/libcrypto/lhash/lhash.c
+++ b/src/lib/libcrypto/lhash/lhash.c
@@ -64,11 +64,11 @@
64 * 64 *
65 * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98 65 * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
66 * 66 *
67 * 2.0 eay - Fixed a bug that occured when using lh_delete 67 * 2.0 eay - Fixed a bug that occurred when using lh_delete
68 * from inside lh_doall(). As entries were deleted, 68 * from inside lh_doall(). As entries were deleted,
69 * the 'table' was 'contract()ed', making some entries 69 * the 'table' was 'contract()ed', making some entries
70 * jump from the end of the table to the start, there by 70 * jump from the end of the table to the start, there by
71 * skiping the lh_doall() processing. eay - 4/12/95 71 * skipping the lh_doall() processing. eay - 4/12/95
72 * 72 *
73 * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs 73 * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs
74 * were not being free()ed. 21/11/95 74 * were not being free()ed. 21/11/95
@@ -107,12 +107,9 @@ const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
107#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ 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) */ 108#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */
109 109
110
111#define P_CP char *
112#define P_CPP char *,char *
113static void expand(LHASH *lh); 110static void expand(LHASH *lh);
114static void contract(LHASH *lh); 111static void contract(LHASH *lh);
115static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash); 112static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash);
116 113
117LHASH *lh_new(unsigned long (*h)(), int (*c)()) 114LHASH *lh_new(unsigned long (*h)(), int (*c)())
118 { 115 {
@@ -152,7 +149,7 @@ LHASH *lh_new(unsigned long (*h)(), int (*c)())
152 ret->error=0; 149 ret->error=0;
153 return(ret); 150 return(ret);
154err1: 151err1:
155 Free((char *)ret); 152 Free(ret);
156err0: 153err0:
157 return(NULL); 154 return(NULL);
158 } 155 }
@@ -175,15 +172,15 @@ void lh_free(LHASH *lh)
175 n=nn; 172 n=nn;
176 } 173 }
177 } 174 }
178 Free((char *)lh->b); 175 Free(lh->b);
179 Free((char *)lh); 176 Free(lh);
180 } 177 }
181 178
182char *lh_insert(LHASH *lh, char *data) 179void *lh_insert(LHASH *lh, void *data)
183 { 180 {
184 unsigned long hash; 181 unsigned long hash;
185 LHASH_NODE *nn,**rn; 182 LHASH_NODE *nn,**rn;
186 char *ret; 183 void *ret;
187 184
188 lh->error=0; 185 lh->error=0;
189 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) 186 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
@@ -217,11 +214,11 @@ char *lh_insert(LHASH *lh, char *data)
217 return(ret); 214 return(ret);
218 } 215 }
219 216
220char *lh_delete(LHASH *lh, char *data) 217void *lh_delete(LHASH *lh, void *data)
221 { 218 {
222 unsigned long hash; 219 unsigned long hash;
223 LHASH_NODE *nn,**rn; 220 LHASH_NODE *nn,**rn;
224 char *ret; 221 void *ret;
225 222
226 lh->error=0; 223 lh->error=0;
227 rn=getrn(lh,data,&hash); 224 rn=getrn(lh,data,&hash);
@@ -236,7 +233,7 @@ char *lh_delete(LHASH *lh, char *data)
236 nn= *rn; 233 nn= *rn;
237 *rn=nn->next; 234 *rn=nn->next;
238 ret=nn->data; 235 ret=nn->data;
239 Free((char *)nn); 236 Free(nn);
240 lh->num_delete++; 237 lh->num_delete++;
241 } 238 }
242 239
@@ -248,11 +245,11 @@ char *lh_delete(LHASH *lh, char *data)
248 return(ret); 245 return(ret);
249 } 246 }
250 247
251char *lh_retrieve(LHASH *lh, char *data) 248void *lh_retrieve(LHASH *lh, void *data)
252 { 249 {
253 unsigned long hash; 250 unsigned long hash;
254 LHASH_NODE **rn; 251 LHASH_NODE **rn;
255 char *ret; 252 void *ret;
256 253
257 lh->error=0; 254 lh->error=0;
258 rn=getrn(lh,data,&hash); 255 rn=getrn(lh,data,&hash);
@@ -275,7 +272,7 @@ void lh_doall(LHASH *lh, void (*func)())
275 lh_doall_arg(lh,func,NULL); 272 lh_doall_arg(lh,func,NULL);
276 } 273 }
277 274
278void lh_doall_arg(LHASH *lh, void (*func)(), char *arg) 275void lh_doall_arg(LHASH *lh, void (*func)(), void *arg)
279 { 276 {
280 int i; 277 int i;
281 LHASH_NODE *a,*n; 278 LHASH_NODE *a,*n;
@@ -332,7 +329,7 @@ static void expand(LHASH *lh)
332 if ((lh->p) >= lh->pmax) 329 if ((lh->p) >= lh->pmax)
333 { 330 {
334 j=(int)lh->num_alloc_nodes*2; 331 j=(int)lh->num_alloc_nodes*2;
335 n=(LHASH_NODE **)Realloc((char *)lh->b, 332 n=(LHASH_NODE **)Realloc(lh->b,
336 (unsigned int)sizeof(LHASH_NODE *)*j); 333 (unsigned int)sizeof(LHASH_NODE *)*j);
337 if (n == NULL) 334 if (n == NULL)
338 { 335 {
@@ -360,7 +357,7 @@ static void contract(LHASH *lh)
360 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */ 357 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
361 if (lh->p == 0) 358 if (lh->p == 0)
362 { 359 {
363 n=(LHASH_NODE **)Realloc((char *)lh->b, 360 n=(LHASH_NODE **)Realloc(lh->b,
364 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); 361 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
365 if (n == NULL) 362 if (n == NULL)
366 { 363 {
@@ -391,7 +388,7 @@ static void contract(LHASH *lh)
391 } 388 }
392 } 389 }
393 390
394static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash) 391static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash)
395 { 392 {
396 LHASH_NODE **ret,*n1; 393 LHASH_NODE **ret,*n1;
397 unsigned long hash,nn; 394 unsigned long hash,nn;
@@ -426,8 +423,7 @@ static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash)
426 } 423 }
427 424
428/* 425/*
429static unsigned long lh_strhash(str) 426unsigned long lh_strhash(char *str)
430char *str;
431 { 427 {
432 int i,l; 428 int i,l;
433 unsigned long ret=0; 429 unsigned long ret=0;
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h
index 6e5a1fe708..6f6eeb2698 100644
--- a/src/lib/libcrypto/lhash/lhash.h
+++ b/src/lib/libcrypto/lhash/lhash.h
@@ -73,7 +73,7 @@ extern "C" {
73 73
74typedef struct lhash_node_st 74typedef struct lhash_node_st
75 { 75 {
76 char *data; 76 void *data;
77 struct lhash_node_st *next; 77 struct lhash_node_st *next;
78#ifndef NO_HASH_COMP 78#ifndef NO_HASH_COMP
79 unsigned long hash; 79 unsigned long hash;
@@ -116,13 +116,13 @@ typedef struct lhash_st
116 * in lh_insert(). */ 116 * in lh_insert(). */
117#define lh_error(lh) ((lh)->error) 117#define lh_error(lh) ((lh)->error)
118 118
119LHASH *lh_new(unsigned long (*h)(), int (*c)()); 119LHASH *lh_new(unsigned long (*h)(/* void *a */), int (*c)(/* void *a,void *b */));
120void lh_free(LHASH *lh); 120void lh_free(LHASH *lh);
121char *lh_insert(LHASH *lh, char *data); 121void *lh_insert(LHASH *lh, void *data);
122char *lh_delete(LHASH *lh, char *data); 122void *lh_delete(LHASH *lh, void *data);
123char *lh_retrieve(LHASH *lh, char *data); 123void *lh_retrieve(LHASH *lh, void *data);
124void lh_doall(LHASH *lh, void (*func)(/* char *b */)); 124 void lh_doall(LHASH *lh, void (*func)(/*void *b*/));
125void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg); 125void lh_doall_arg(LHASH *lh, void (*func)(/*void *a,void *b*/),void *arg);
126unsigned long lh_strhash(const char *c); 126unsigned long lh_strhash(const char *c);
127 127
128#ifndef NO_FP_API 128#ifndef NO_FP_API
diff --git a/src/lib/libcrypto/md2/Makefile.ssl b/src/lib/libcrypto/md2/Makefile.ssl
index 4274354b5f..eab615a5be 100644
--- a/src/lib/libcrypto/md2/Makefile.ssl
+++ b/src/lib/libcrypto/md2/Makefile.ssl
@@ -84,5 +84,5 @@ md2_one.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
84md2_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 84md2_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
85md2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 85md2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
86md2_one.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h 86md2_one.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h
87md2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 87md2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
88md2_one.o: ../cryptlib.h 88md2_one.o: ../../include/openssl/stack.h ../cryptlib.h
diff --git a/src/lib/libcrypto/md2/md2.h b/src/lib/libcrypto/md2/md2.h
index 0d3592506c..582bffb859 100644
--- a/src/lib/libcrypto/md2/md2.h
+++ b/src/lib/libcrypto/md2/md2.h
@@ -81,9 +81,9 @@ typedef struct MD2state_st
81 81
82const char *MD2_options(void); 82const char *MD2_options(void);
83void MD2_Init(MD2_CTX *c); 83void MD2_Init(MD2_CTX *c);
84void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len); 84void MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len);
85void MD2_Final(unsigned char *md, MD2_CTX *c); 85void MD2_Final(unsigned char *md, MD2_CTX *c);
86unsigned char *MD2(unsigned char *d, unsigned long n,unsigned char *md); 86unsigned char *MD2(const unsigned char *d, unsigned long n,unsigned char *md);
87#ifdef __cplusplus 87#ifdef __cplusplus
88} 88}
89#endif 89#endif
diff --git a/src/lib/libcrypto/md2/md2_dgst.c b/src/lib/libcrypto/md2/md2_dgst.c
index c7d8d6aef5..608baefa8f 100644
--- a/src/lib/libcrypto/md2/md2_dgst.c
+++ b/src/lib/libcrypto/md2/md2_dgst.c
@@ -69,9 +69,9 @@ const char *MD2_version="MD2" OPENSSL_VERSION_PTEXT;
69 69
70#define UCHAR unsigned char 70#define UCHAR unsigned char
71 71
72static void md2_block(MD2_CTX *c, unsigned char *d); 72static void md2_block(MD2_CTX *c, const unsigned char *d);
73/* The magic S table - I have converted it to hex since it is 73/* The magic S table - I have converted it to hex since it is
74 * basicaly just a random byte string. */ 74 * basically just a random byte string. */
75static MD2_INT S[256]={ 75static MD2_INT S[256]={
76 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, 76 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01,
77 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13, 77 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
@@ -123,7 +123,7 @@ void MD2_Init(MD2_CTX *c)
123 memset(c->data,0,MD2_BLOCK); 123 memset(c->data,0,MD2_BLOCK);
124 } 124 }
125 125
126void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len) 126void MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len)
127 { 127 {
128 register UCHAR *p; 128 register UCHAR *p;
129 129
@@ -161,7 +161,7 @@ void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len)
161 c->num=(int)len; 161 c->num=(int)len;
162 } 162 }
163 163
164static void md2_block(MD2_CTX *c, unsigned char *d) 164static void md2_block(MD2_CTX *c, const unsigned char *d)
165 { 165 {
166 register MD2_INT t,*sp1,*sp2; 166 register MD2_INT t,*sp1,*sp2;
167 register int i,j; 167 register int i,j;
diff --git a/src/lib/libcrypto/md2/md2_one.c b/src/lib/libcrypto/md2/md2_one.c
index 7157299d95..b12c37ce4d 100644
--- a/src/lib/libcrypto/md2/md2_one.c
+++ b/src/lib/libcrypto/md2/md2_one.c
@@ -63,7 +63,7 @@
63/* This is a separate file so that #defines in cryptlib.h can 63/* This is a separate file so that #defines in cryptlib.h can
64 * map my MD functions to different names */ 64 * map my MD functions to different names */
65 65
66unsigned char *MD2(unsigned char *d, unsigned long n, unsigned char *md) 66unsigned char *MD2(const unsigned char *d, unsigned long n, unsigned char *md)
67 { 67 {
68 MD2_CTX c; 68 MD2_CTX c;
69 static unsigned char m[MD2_DIGEST_LENGTH]; 69 static unsigned char m[MD2_DIGEST_LENGTH];
diff --git a/src/lib/libcrypto/md2/md2test.c b/src/lib/libcrypto/md2/md2test.c
index 461d124957..e3f4fb4c34 100644
--- a/src/lib/libcrypto/md2/md2test.c
+++ b/src/lib/libcrypto/md2/md2test.c
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
73#include <openssl/ebcdic.h> 73#include <openssl/ebcdic.h>
74#endif 74#endif
75 75
76char *test[]={ 76static char *test[]={
77 "", 77 "",
78 "a", 78 "a",
79 "abc", 79 "abc",
@@ -84,7 +84,7 @@ char *test[]={
84 NULL, 84 NULL,
85 }; 85 };
86 86
87char *ret[]={ 87static char *ret[]={
88 "8350e5a3e24c153df2275c9f80692773", 88 "8350e5a3e24c153df2275c9f80692773",
89 "32ec01ec4a6dac72c0ab96fb34c0b5d1", 89 "32ec01ec4a6dac72c0ab96fb34c0b5d1",
90 "da853b0d3f88d99b30283a69e6ded6bb", 90 "da853b0d3f88d99b30283a69e6ded6bb",
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h
index 2b91f9eef2..1a404a458d 100644
--- a/src/lib/libcrypto/md32_common.h
+++ b/src/lib/libcrypto/md32_common.h
@@ -94,6 +94,8 @@
94 * in original (data) byte order, implemented externally (it 94 * in original (data) byte order, implemented externally (it
95 * actually is optional if data and host are of the same 95 * actually is optional if data and host are of the same
96 * "endianess"). 96 * "endianess").
97 * HASH_MAKE_STRING
98 * macro convering context variables to an ASCII hash string.
97 * 99 *
98 * Optional macros: 100 * Optional macros:
99 * 101 *
@@ -178,8 +180,17 @@
178#undef ROTATE 180#undef ROTATE
179#ifndef PEDANTIC 181#ifndef PEDANTIC
180# if defined(_MSC_VER) 182# if defined(_MSC_VER)
181# define ROTATE(a,n) _lrotl(a,n) 183# define ROTATE(a,n) _lrotl(a,n)
182# elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) 184# elif defined(__MWERKS__)
185# if defined(__POWERPC__)
186# define ROTATE(a,n) __rlwinm(a,n,0,31)
187# elif defined(__MC68K__)
188 /* Motorola specific tweak. <appro@fy.chalmers.se> */
189# define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) )
190# else
191# define ROTATE(a,n) __rol(a,n)
192# endif
193# elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) && !defined(NO_INLINE_ASM)
183 /* 194 /*
184 * Some GNU C inline assembler templates. Note that these are 195 * Some GNU C inline assembler templates. Note that these are
185 * rotates by *constant* number of bits! But that's exactly 196 * rotates by *constant* number of bits! But that's exactly
@@ -189,16 +200,16 @@
189 */ 200 */
190# if defined(__i386) 201# if defined(__i386)
191# define ROTATE(a,n) ({ register unsigned int ret; \ 202# define ROTATE(a,n) ({ register unsigned int ret; \
192 asm volatile ( \ 203 asm ( \
193 "roll %1,%0" \ 204 "roll %1,%0" \
194 : "=r"(ret) \ 205 : "=r"(ret) \
195 : "I"(n), "0"(a) \ 206 : "I"(n), "0"(a) \
196 : "cc"); \ 207 : "cc"); \
197 ret; \ 208 ret; \
198 }) 209 })
199# elif defined(__powerpc) 210# elif defined(__powerpc) || defined(__ppc)
200# define ROTATE(a,n) ({ register unsigned int ret; \ 211# define ROTATE(a,n) ({ register unsigned int ret; \
201 asm volatile ( \ 212 asm ( \
202 "rlwinm %0,%1,%2,0,31" \ 213 "rlwinm %0,%1,%2,0,31" \
203 : "=r"(ret) \ 214 : "=r"(ret) \
204 : "r"(a), "I"(n)); \ 215 : "r"(a), "I"(n)); \
@@ -211,18 +222,18 @@
211 * Engage compiler specific "fetch in reverse byte order" 222 * Engage compiler specific "fetch in reverse byte order"
212 * intrinsic function if available. 223 * intrinsic function if available.
213 */ 224 */
214# if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) 225# if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) && !defined(NO_INLINE_ASM)
215 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */ 226 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
216# if defined(__i386) && !defined(I386_ONLY) 227# if defined(__i386) && !defined(I386_ONLY)
217# define BE_FETCH32(a) ({ register unsigned int l=(a);\ 228# define BE_FETCH32(a) ({ register unsigned int l=(a);\
218 asm volatile ( \ 229 asm ( \
219 "bswapl %0" \ 230 "bswapl %0" \
220 : "=r"(l) : "0"(l)); \ 231 : "=r"(l) : "0"(l)); \
221 l; \ 232 l; \
222 }) 233 })
223# elif defined(__powerpc) 234# elif defined(__powerpc)
224# define LE_FETCH32(a) ({ register unsigned int l; \ 235# define LE_FETCH32(a) ({ register unsigned int l; \
225 asm volatile ( \ 236 asm ( \
226 "lwbrx %0,0,%1" \ 237 "lwbrx %0,0,%1" \
227 : "=r"(l) \ 238 : "=r"(l) \
228 : "r"(a)); \ 239 : "r"(a)); \
@@ -231,7 +242,7 @@
231 242
232# elif defined(__sparc) && defined(ULTRASPARC) 243# elif defined(__sparc) && defined(ULTRASPARC)
233# define LE_FETCH32(a) ({ register unsigned int l; \ 244# define LE_FETCH32(a) ({ register unsigned int l; \
234 asm volatile ( \ 245 asm ( \
235 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\ 246 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
236 : "=r"(l) \ 247 : "=r"(l) \
237 : "r"(a)); \ 248 : "r"(a)); \
@@ -399,8 +410,9 @@
399 * Time for some action:-) 410 * Time for some action:-)
400 */ 411 */
401 412
402void HASH_UPDATE (HASH_CTX *c, const unsigned char *data, unsigned long len) 413void HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
403 { 414 {
415 const unsigned char *data=data_;
404 register HASH_LONG * p; 416 register HASH_LONG * p;
405 register unsigned long l; 417 register unsigned long l;
406 int sw,sc,ew,ec; 418 int sw,sc,ew,ec;
@@ -581,10 +593,11 @@ void HASH_FINAL (unsigned char *md, HASH_CTX *c)
581#endif 593#endif
582 HASH_BLOCK_HOST_ORDER (c,p,1); 594 HASH_BLOCK_HOST_ORDER (c,p,1);
583 595
584 l=c->A; HOST_l2c(l,md); 596#ifndef HASH_MAKE_STRING
585 l=c->B; HOST_l2c(l,md); 597#error "HASH_MAKE_STRING must be defined!"
586 l=c->C; HOST_l2c(l,md); 598#else
587 l=c->D; HOST_l2c(l,md); 599 HASH_MAKE_STRING(c,md);
600#endif
588 601
589 c->num=0; 602 c->num=0;
590 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack 603 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
diff --git a/src/lib/libcrypto/md5/Makefile.ssl b/src/lib/libcrypto/md5/Makefile.ssl
index cc73fba2ba..d50f967be7 100644
--- a/src/lib/libcrypto/md5/Makefile.ssl
+++ b/src/lib/libcrypto/md5/Makefile.ssl
@@ -19,6 +19,13 @@ AR= ar r
19MD5_ASM_OBJ= 19MD5_ASM_OBJ=
20 20
21CFLAGS= $(INCLUDES) $(CFLAG) 21CFLAGS= $(INCLUDES) $(CFLAG)
22
23# We let the C compiler driver to take care of .s files. This is done in
24# order to be excused from maintaining a separate set of architecture
25# dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
26# gcc, then the driver will automatically translate it to -xarch=v8plus
27# and pass it down to assembler.
28AS=$(CC) -c
22ASFLAGS=$(CFLAGS) 29ASFLAGS=$(CFLAGS)
23 30
24GENERAL=Makefile 31GENERAL=Makefile
@@ -77,7 +84,7 @@ asm/md5-sparcv8plus.o: asm/md5-sparcv9.S
77# if they didn't bother to upgrade GNU assembler. Such users should 84# if they didn't bother to upgrade GNU assembler. Such users should
78# not choose this option, but be adviced to *remove* GNU assembler 85# not choose this option, but be adviced to *remove* GNU assembler
79# or upgrade it. 86# or upgrade it.
80sm/md5-sparcv8plus-gcc27.o: asm/md5-sparcv9.S 87asm/md5-sparcv8plus-gcc27.o: asm/md5-sparcv9.S
81 $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -E asm/md5-sparcv9.S | \ 88 $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -E asm/md5-sparcv9.S | \
82 /usr/ccs/bin/as -xarch=v8plus - -o asm/md5-sparcv8plus-gcc27.o 89 /usr/ccs/bin/as -xarch=v8plus - -o asm/md5-sparcv8plus-gcc27.o
83 90
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h
index bdab6d45e8..d10bc8397f 100644
--- a/src/lib/libcrypto/md5/md5.h
+++ b/src/lib/libcrypto/md5/md5.h
@@ -103,9 +103,9 @@ typedef struct MD5state_st
103 } MD5_CTX; 103 } MD5_CTX;
104 104
105void MD5_Init(MD5_CTX *c); 105void MD5_Init(MD5_CTX *c);
106void MD5_Update(MD5_CTX *c, const unsigned char *data, unsigned long len); 106void MD5_Update(MD5_CTX *c, const void *data, unsigned long len);
107void MD5_Final(unsigned char *md, MD5_CTX *c); 107void MD5_Final(unsigned char *md, MD5_CTX *c);
108unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md); 108unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md);
109void MD5_Transform(MD5_CTX *c, const unsigned char *b); 109void MD5_Transform(MD5_CTX *c, const unsigned char *b);
110#ifdef __cplusplus 110#ifdef __cplusplus
111} 111}
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c
index ba0115ae79..23d196b8d4 100644
--- a/src/lib/libcrypto/md5/md5_dgst.c
+++ b/src/lib/libcrypto/md5/md5_dgst.c
@@ -60,7 +60,7 @@
60#include "md5_locl.h" 60#include "md5_locl.h"
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63char *MD5_version="MD5" OPENSSL_VERSION_PTEXT; 63const char *MD5_version="MD5" OPENSSL_VERSION_PTEXT;
64 64
65/* Implemented from RFC1321 The MD5 Message-Digest Algorithm 65/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
66 */ 66 */
@@ -186,6 +186,9 @@ void md5_block_host_order (MD5_CTX *c, const void *data, int num)
186#endif 186#endif
187 187
188#ifndef md5_block_data_order 188#ifndef md5_block_data_order
189#ifdef X
190#undef X
191#endif
189void md5_block_data_order (MD5_CTX *c, const void *data_, int num) 192void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
190 { 193 {
191 const unsigned char *data=data_; 194 const unsigned char *data=data_;
@@ -204,16 +207,15 @@ void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
204 * 207 *
205 * <appro@fy.chalmers.se> 208 * <appro@fy.chalmers.se>
206 */ 209 */
207 MD5_LONG X[MD5_LBLOCK]; 210#ifndef MD32_XARRAY
208 /* 211 /* See comment in crypto/sha/sha_locl.h for details. */
209 * In case you wonder why don't I use c->data for this. 212 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
210 * RISCs usually have a handful of registers and if X is 213 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
211 * declared as automatic array good optimizing compiler 214# define X(i) XX##i
212 * shall accomodate at least part of it in register bank 215#else
213 * instead of memory. 216 MD5_LONG XX[MD5_LBLOCK];
214 * 217# define X(i) XX[i]
215 * <appro@fy.chalmers.se> 218#endif
216 */
217 219
218 A=c->A; 220 A=c->A;
219 B=c->B; 221 B=c->B;
@@ -222,75 +224,75 @@ void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
222 224
223 for (;num--;) 225 for (;num--;)
224 { 226 {
225 HOST_c2l(data,l); X[ 0]=l; HOST_c2l(data,l); X[ 1]=l; 227 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
226 /* Round 0 */ 228 /* Round 0 */
227 R0(A,B,C,D,X[ 0], 7,0xd76aa478L); HOST_c2l(data,l); X[ 2]=l; 229 R0(A,B,C,D,X( 0), 7,0xd76aa478L); HOST_c2l(data,l); X( 2)=l;
228 R0(D,A,B,C,X[ 1],12,0xe8c7b756L); HOST_c2l(data,l); X[ 3]=l; 230 R0(D,A,B,C,X( 1),12,0xe8c7b756L); HOST_c2l(data,l); X( 3)=l;
229 R0(C,D,A,B,X[ 2],17,0x242070dbL); HOST_c2l(data,l); X[ 4]=l; 231 R0(C,D,A,B,X( 2),17,0x242070dbL); HOST_c2l(data,l); X( 4)=l;
230 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL); HOST_c2l(data,l); X[ 5]=l; 232 R0(B,C,D,A,X( 3),22,0xc1bdceeeL); HOST_c2l(data,l); X( 5)=l;
231 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL); HOST_c2l(data,l); X[ 6]=l; 233 R0(A,B,C,D,X( 4), 7,0xf57c0fafL); HOST_c2l(data,l); X( 6)=l;
232 R0(D,A,B,C,X[ 5],12,0x4787c62aL); HOST_c2l(data,l); X[ 7]=l; 234 R0(D,A,B,C,X( 5),12,0x4787c62aL); HOST_c2l(data,l); X( 7)=l;
233 R0(C,D,A,B,X[ 6],17,0xa8304613L); HOST_c2l(data,l); X[ 8]=l; 235 R0(C,D,A,B,X( 6),17,0xa8304613L); HOST_c2l(data,l); X( 8)=l;
234 R0(B,C,D,A,X[ 7],22,0xfd469501L); HOST_c2l(data,l); X[ 9]=l; 236 R0(B,C,D,A,X( 7),22,0xfd469501L); HOST_c2l(data,l); X( 9)=l;
235 R0(A,B,C,D,X[ 8], 7,0x698098d8L); HOST_c2l(data,l); X[10]=l; 237 R0(A,B,C,D,X( 8), 7,0x698098d8L); HOST_c2l(data,l); X(10)=l;
236 R0(D,A,B,C,X[ 9],12,0x8b44f7afL); HOST_c2l(data,l); X[11]=l; 238 R0(D,A,B,C,X( 9),12,0x8b44f7afL); HOST_c2l(data,l); X(11)=l;
237 R0(C,D,A,B,X[10],17,0xffff5bb1L); HOST_c2l(data,l); X[12]=l; 239 R0(C,D,A,B,X(10),17,0xffff5bb1L); HOST_c2l(data,l); X(12)=l;
238 R0(B,C,D,A,X[11],22,0x895cd7beL); HOST_c2l(data,l); X[13]=l; 240 R0(B,C,D,A,X(11),22,0x895cd7beL); HOST_c2l(data,l); X(13)=l;
239 R0(A,B,C,D,X[12], 7,0x6b901122L); HOST_c2l(data,l); X[14]=l; 241 R0(A,B,C,D,X(12), 7,0x6b901122L); HOST_c2l(data,l); X(14)=l;
240 R0(D,A,B,C,X[13],12,0xfd987193L); HOST_c2l(data,l); X[15]=l; 242 R0(D,A,B,C,X(13),12,0xfd987193L); HOST_c2l(data,l); X(15)=l;
241 R0(C,D,A,B,X[14],17,0xa679438eL); 243 R0(C,D,A,B,X(14),17,0xa679438eL);
242 R0(B,C,D,A,X[15],22,0x49b40821L); 244 R0(B,C,D,A,X(15),22,0x49b40821L);
243 /* Round 1 */ 245 /* Round 1 */
244 R1(A,B,C,D,X[ 1], 5,0xf61e2562L); 246 R1(A,B,C,D,X( 1), 5,0xf61e2562L);
245 R1(D,A,B,C,X[ 6], 9,0xc040b340L); 247 R1(D,A,B,C,X( 6), 9,0xc040b340L);
246 R1(C,D,A,B,X[11],14,0x265e5a51L); 248 R1(C,D,A,B,X(11),14,0x265e5a51L);
247 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL); 249 R1(B,C,D,A,X( 0),20,0xe9b6c7aaL);
248 R1(A,B,C,D,X[ 5], 5,0xd62f105dL); 250 R1(A,B,C,D,X( 5), 5,0xd62f105dL);
249 R1(D,A,B,C,X[10], 9,0x02441453L); 251 R1(D,A,B,C,X(10), 9,0x02441453L);
250 R1(C,D,A,B,X[15],14,0xd8a1e681L); 252 R1(C,D,A,B,X(15),14,0xd8a1e681L);
251 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L); 253 R1(B,C,D,A,X( 4),20,0xe7d3fbc8L);
252 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L); 254 R1(A,B,C,D,X( 9), 5,0x21e1cde6L);
253 R1(D,A,B,C,X[14], 9,0xc33707d6L); 255 R1(D,A,B,C,X(14), 9,0xc33707d6L);
254 R1(C,D,A,B,X[ 3],14,0xf4d50d87L); 256 R1(C,D,A,B,X( 3),14,0xf4d50d87L);
255 R1(B,C,D,A,X[ 8],20,0x455a14edL); 257 R1(B,C,D,A,X( 8),20,0x455a14edL);
256 R1(A,B,C,D,X[13], 5,0xa9e3e905L); 258 R1(A,B,C,D,X(13), 5,0xa9e3e905L);
257 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L); 259 R1(D,A,B,C,X( 2), 9,0xfcefa3f8L);
258 R1(C,D,A,B,X[ 7],14,0x676f02d9L); 260 R1(C,D,A,B,X( 7),14,0x676f02d9L);
259 R1(B,C,D,A,X[12],20,0x8d2a4c8aL); 261 R1(B,C,D,A,X(12),20,0x8d2a4c8aL);
260 /* Round 2 */ 262 /* Round 2 */
261 R2(A,B,C,D,X[ 5], 4,0xfffa3942L); 263 R2(A,B,C,D,X( 5), 4,0xfffa3942L);
262 R2(D,A,B,C,X[ 8],11,0x8771f681L); 264 R2(D,A,B,C,X( 8),11,0x8771f681L);
263 R2(C,D,A,B,X[11],16,0x6d9d6122L); 265 R2(C,D,A,B,X(11),16,0x6d9d6122L);
264 R2(B,C,D,A,X[14],23,0xfde5380cL); 266 R2(B,C,D,A,X(14),23,0xfde5380cL);
265 R2(A,B,C,D,X[ 1], 4,0xa4beea44L); 267 R2(A,B,C,D,X( 1), 4,0xa4beea44L);
266 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L); 268 R2(D,A,B,C,X( 4),11,0x4bdecfa9L);
267 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L); 269 R2(C,D,A,B,X( 7),16,0xf6bb4b60L);
268 R2(B,C,D,A,X[10],23,0xbebfbc70L); 270 R2(B,C,D,A,X(10),23,0xbebfbc70L);
269 R2(A,B,C,D,X[13], 4,0x289b7ec6L); 271 R2(A,B,C,D,X(13), 4,0x289b7ec6L);
270 R2(D,A,B,C,X[ 0],11,0xeaa127faL); 272 R2(D,A,B,C,X( 0),11,0xeaa127faL);
271 R2(C,D,A,B,X[ 3],16,0xd4ef3085L); 273 R2(C,D,A,B,X( 3),16,0xd4ef3085L);
272 R2(B,C,D,A,X[ 6],23,0x04881d05L); 274 R2(B,C,D,A,X( 6),23,0x04881d05L);
273 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L); 275 R2(A,B,C,D,X( 9), 4,0xd9d4d039L);
274 R2(D,A,B,C,X[12],11,0xe6db99e5L); 276 R2(D,A,B,C,X(12),11,0xe6db99e5L);
275 R2(C,D,A,B,X[15],16,0x1fa27cf8L); 277 R2(C,D,A,B,X(15),16,0x1fa27cf8L);
276 R2(B,C,D,A,X[ 2],23,0xc4ac5665L); 278 R2(B,C,D,A,X( 2),23,0xc4ac5665L);
277 /* Round 3 */ 279 /* Round 3 */
278 R3(A,B,C,D,X[ 0], 6,0xf4292244L); 280 R3(A,B,C,D,X( 0), 6,0xf4292244L);
279 R3(D,A,B,C,X[ 7],10,0x432aff97L); 281 R3(D,A,B,C,X( 7),10,0x432aff97L);
280 R3(C,D,A,B,X[14],15,0xab9423a7L); 282 R3(C,D,A,B,X(14),15,0xab9423a7L);
281 R3(B,C,D,A,X[ 5],21,0xfc93a039L); 283 R3(B,C,D,A,X( 5),21,0xfc93a039L);
282 R3(A,B,C,D,X[12], 6,0x655b59c3L); 284 R3(A,B,C,D,X(12), 6,0x655b59c3L);
283 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L); 285 R3(D,A,B,C,X( 3),10,0x8f0ccc92L);
284 R3(C,D,A,B,X[10],15,0xffeff47dL); 286 R3(C,D,A,B,X(10),15,0xffeff47dL);
285 R3(B,C,D,A,X[ 1],21,0x85845dd1L); 287 R3(B,C,D,A,X( 1),21,0x85845dd1L);
286 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL); 288 R3(A,B,C,D,X( 8), 6,0x6fa87e4fL);
287 R3(D,A,B,C,X[15],10,0xfe2ce6e0L); 289 R3(D,A,B,C,X(15),10,0xfe2ce6e0L);
288 R3(C,D,A,B,X[ 6],15,0xa3014314L); 290 R3(C,D,A,B,X( 6),15,0xa3014314L);
289 R3(B,C,D,A,X[13],21,0x4e0811a1L); 291 R3(B,C,D,A,X(13),21,0x4e0811a1L);
290 R3(A,B,C,D,X[ 4], 6,0xf7537e82L); 292 R3(A,B,C,D,X( 4), 6,0xf7537e82L);
291 R3(D,A,B,C,X[11],10,0xbd3af235L); 293 R3(D,A,B,C,X(11),10,0xbd3af235L);
292 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL); 294 R3(C,D,A,B,X( 2),15,0x2ad7d2bbL);
293 R3(B,C,D,A,X[ 9],21,0xeb86d391L); 295 R3(B,C,D,A,X( 9),21,0xeb86d391L);
294 296
295 A = c->A += A; 297 A = c->A += A;
296 B = c->B += B; 298 B = c->B += B;
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h
index 9d04696dbd..06af633228 100644
--- a/src/lib/libcrypto/md5/md5_locl.h
+++ b/src/lib/libcrypto/md5/md5_locl.h
@@ -66,7 +66,7 @@
66#endif 66#endif
67 67
68#ifdef MD5_ASM 68#ifdef MD5_ASM
69# if defined(__i386) || defined(_M_IX86) 69# if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
70# define md5_block_host_order md5_block_asm_host_order 70# define md5_block_host_order md5_block_asm_host_order
71# elif defined(__sparc) && defined(ULTRASPARC) 71# elif defined(__sparc) && defined(ULTRASPARC)
72 void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num); 72 void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num);
@@ -77,11 +77,11 @@
77void md5_block_host_order (MD5_CTX *c, const void *p,int num); 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); 78void md5_block_data_order (MD5_CTX *c, const void *p,int num);
79 79
80#if defined(__i386) || defined(_M_IX86) 80#if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
81/* 81/*
82 * *_block_host_order is expected to handle aligned data while 82 * *_block_host_order is expected to handle aligned data while
83 * *_block_data_order - unaligned. As algorithm and host (x86) 83 * *_block_data_order - unaligned. As algorithm and host (x86)
84 * are in this case of the same "endianess" these two are 84 * are in this case of the same "endianness" these two are
85 * otherwise indistinguishable. But normally you don't want to 85 * otherwise indistinguishable. But normally you don't want to
86 * call the same function because unaligned access in places 86 * call the same function because unaligned access in places
87 * where alignment is expected is usually a "Bad Thing". Indeed, 87 * where alignment is expected is usually a "Bad Thing". Indeed,
@@ -112,6 +112,13 @@ void md5_block_data_order (MD5_CTX *c, const void *p,int num);
112#define HASH_UPDATE MD5_Update 112#define HASH_UPDATE MD5_Update
113#define HASH_TRANSFORM MD5_Transform 113#define HASH_TRANSFORM MD5_Transform
114#define HASH_FINAL MD5_Final 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)
115#define HASH_BLOCK_HOST_ORDER md5_block_host_order 122#define HASH_BLOCK_HOST_ORDER md5_block_host_order
116#if !defined(L_ENDIAN) || defined(md5_block_data_order) 123#if !defined(L_ENDIAN) || defined(md5_block_data_order)
117#define HASH_BLOCK_DATA_ORDER md5_block_data_order 124#define HASH_BLOCK_DATA_ORDER md5_block_data_order
@@ -119,7 +126,7 @@ void md5_block_data_order (MD5_CTX *c, const void *p,int num);
119 * Little-endians (Intel and Alpha) feel better without this. 126 * Little-endians (Intel and Alpha) feel better without this.
120 * It looks like memcpy does better job than generic 127 * It looks like memcpy does better job than generic
121 * md5_block_data_order on copying-n-aligning input data. 128 * md5_block_data_order on copying-n-aligning input data.
122 * But franlky speaking I didn't expect such result on Alpha. 129 * But frankly speaking I didn't expect such result on Alpha.
123 * On the other hand I've got this with egcs-1.0.2 and if 130 * On the other hand I've got this with egcs-1.0.2 and if
124 * program is compiled with another (better?) compiler it 131 * program is compiled with another (better?) compiler it
125 * might turn out other way around. 132 * might turn out other way around.
@@ -140,7 +147,7 @@ void md5_block_data_order (MD5_CTX *c, const void *p,int num);
140*/ 147*/
141 148
142/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be 149/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
143 * simplified to the code below. Wei attributes these optimisations 150 * simplified to the code below. Wei attributes these optimizations
144 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. 151 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
145 */ 152 */
146#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) 153#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c
index 4b10e7f940..b89dec850d 100644
--- a/src/lib/libcrypto/md5/md5_one.c
+++ b/src/lib/libcrypto/md5/md5_one.c
@@ -64,7 +64,7 @@
64#include <openssl/ebcdic.h> 64#include <openssl/ebcdic.h>
65#endif 65#endif
66 66
67unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md) 67unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md)
68 { 68 {
69 MD5_CTX c; 69 MD5_CTX c;
70 static unsigned char m[MD5_DIGEST_LENGTH]; 70 static unsigned char m[MD5_DIGEST_LENGTH];
diff --git a/src/lib/libcrypto/md5/md5test.c b/src/lib/libcrypto/md5/md5test.c
index a192a62bb3..6bd8656302 100644
--- a/src/lib/libcrypto/md5/md5test.c
+++ b/src/lib/libcrypto/md5/md5test.c
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
69#else 69#else
70#include <openssl/md5.h> 70#include <openssl/md5.h>
71 71
72char *test[]={ 72static char *test[]={
73 "", 73 "",
74 "a", 74 "a",
75 "abc", 75 "abc",
@@ -80,7 +80,7 @@ char *test[]={
80 NULL, 80 NULL,
81 }; 81 };
82 82
83char *ret[]={ 83static char *ret[]={
84 "d41d8cd98f00b204e9800998ecf8427e", 84 "d41d8cd98f00b204e9800998ecf8427e",
85 "0cc175b9c0f1b6a831c399e269772661", 85 "0cc175b9c0f1b6a831c399e269772661",
86 "900150983cd24fb0d6963f7d28e17f72", 86 "900150983cd24fb0d6963f7d28e17f72",
diff --git a/src/lib/libcrypto/mdc2/Makefile.ssl b/src/lib/libcrypto/mdc2/Makefile.ssl
index f8c824c4a8..7c28103350 100644
--- a/src/lib/libcrypto/mdc2/Makefile.ssl
+++ b/src/lib/libcrypto/mdc2/Makefile.ssl
@@ -83,7 +83,7 @@ mdc2_one.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
83mdc2_one.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 83mdc2_one.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
84mdc2_one.o: ../../include/openssl/err.h ../../include/openssl/mdc2.h 84mdc2_one.o: ../../include/openssl/err.h ../../include/openssl/mdc2.h
85mdc2_one.o: ../../include/openssl/opensslconf.h 85mdc2_one.o: ../../include/openssl/opensslconf.h
86mdc2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 86mdc2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
87mdc2_one.o: ../cryptlib.h 87mdc2_one.o: ../../include/openssl/stack.h ../cryptlib.h
88mdc2dgst.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 88mdc2dgst.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
89mdc2dgst.o: ../../include/openssl/mdc2.h ../../include/openssl/opensslconf.h 89mdc2dgst.o: ../../include/openssl/mdc2.h ../../include/openssl/opensslconf.h
diff --git a/src/lib/libcrypto/mdc2/mdc2.h b/src/lib/libcrypto/mdc2/mdc2.h
index ec8e159fc9..00acd707cd 100644
--- a/src/lib/libcrypto/mdc2/mdc2.h
+++ b/src/lib/libcrypto/mdc2/mdc2.h
@@ -82,9 +82,10 @@ typedef struct mdc2_ctx_st
82 82
83 83
84void MDC2_Init(MDC2_CTX *c); 84void MDC2_Init(MDC2_CTX *c);
85void MDC2_Update(MDC2_CTX *c, unsigned char *data, unsigned long len); 85void MDC2_Update(MDC2_CTX *c, const unsigned char *data, unsigned long len);
86void MDC2_Final(unsigned char *md, MDC2_CTX *c); 86void MDC2_Final(unsigned char *md, MDC2_CTX *c);
87unsigned char *MDC2(unsigned char *d, unsigned long n, unsigned char *md); 87unsigned char *MDC2(const unsigned char *d, unsigned long n,
88 unsigned char *md);
88 89
89#ifdef __cplusplus 90#ifdef __cplusplus
90} 91}
diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c
index 61fc1e184e..5a661e5f45 100644
--- a/src/lib/libcrypto/mem.c
+++ b/src/lib/libcrypto/mem.c
@@ -59,371 +59,203 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <openssl/crypto.h> 61#include <openssl/crypto.h>
62#ifdef CRYPTO_MDEBUG_TIME
63# include <time.h>
64#endif
65#include <openssl/buffer.h>
66#include <openssl/bio.h>
67#include <openssl/lhash.h>
68#include "cryptlib.h" 62#include "cryptlib.h"
69 63
70/* #ifdef CRYPTO_MDEBUG */
71/* static int mh_mode=CRYPTO_MEM_CHECK_ON; */
72/* #else */
73static int mh_mode=CRYPTO_MEM_CHECK_OFF;
74/* #endif */
75/* State CRYPTO_MEM_CHECK_ON exists only temporarily when the library
76 * thinks that certain allocations should not be checked (e.g. the data
77 * structures used for memory checking). It is not suitable as an initial
78 * state: the library will unexpectedly enable memory checking when it
79 * executes one of those sections that want to disable checking
80 * temporarily.
81 *
82 * State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes no sense whatsoever.
83 */
84
85static unsigned long order=0;
86
87static LHASH *mh=NULL;
88 64
89typedef struct mem_st 65static int allow_customize = 1; /* we provide flexible functions for */
90 { 66static int allow_customize_debug = 1;/* exchanging memory-related functions at
91 char *addr; 67 * run-time, but this must be done
92 int num; 68 * before any blocks are actually
93 const char *file; 69 * allocated; or we'll run into huge
94 int line; 70 * problems when malloc/free pairs
95#ifdef CRYPTO_MDEBUG_THREAD 71 * don't match etc. */
96 unsigned long thread; 72
73/* may be changed as long as `allow_customize' is set */
74static void *(*malloc_locked_func)(size_t) = malloc;
75static void (*free_locked_func)(void *) = free;
76static void *(*malloc_func)(size_t) = malloc;
77static void *(*realloc_func)(void *, size_t)= realloc;
78static void (*free_func)(void *) = free;
79
80/* may be changed as long as `allow_customize_debug' is set */
81/* XXX use correct function pointer types */
82#ifdef CRYPTO_MDEBUG
83 /* use default functions from mem_dbg.c */
84 static void (*malloc_debug_func)()= (void (*)())CRYPTO_dbg_malloc;
85 static void (*realloc_debug_func)()= (void (*)())CRYPTO_dbg_realloc;
86 static void (*free_debug_func)()= (void (*)())CRYPTO_dbg_free;
87 static void (*set_debug_options_func)()= (void (*)())CRYPTO_dbg_set_options;
88 static long (*get_debug_options_func)()= (long (*)())CRYPTO_dbg_get_options;
89#else
90 /* applications can use CRYPTO_malloc_debug_init() to select above case
91 * at run-time */
92 static void (*malloc_debug_func)()= NULL;
93 static void (*realloc_debug_func)()= NULL;
94 static void (*free_debug_func)()= NULL;
95 static void (*set_debug_options_func)()= NULL;
96 static long (*get_debug_options_func)()= NULL;
97#endif 97#endif
98 unsigned long order;
99#ifdef CRYPTO_MDEBUG_TIME
100 time_t time;
101#endif
102 } MEM;
103
104int CRYPTO_mem_ctrl(int mode)
105 {
106 int ret=mh_mode;
107
108 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
109 switch (mode)
110 {
111 /* for applications: */
112 case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */
113 mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE;
114 break;
115 case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
116 mh_mode = 0;
117 break;
118 98
119 /* switch off temporarily (for library-internal use): */
120 case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
121 mh_mode&= ~CRYPTO_MEM_CHECK_ENABLE;
122 break;
123 case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
124 if (mh_mode&CRYPTO_MEM_CHECK_ON)
125 mh_mode|=CRYPTO_MEM_CHECK_ENABLE;
126 break;
127 99
128 default: 100int CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t),
129 break; 101 void (*f)(void *))
130 }
131 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
132 return(ret);
133 }
134
135static int mem_cmp(MEM *a, MEM *b)
136 {
137 return(a->addr - b->addr);
138 }
139
140static unsigned long mem_hash(MEM *a)
141 { 102 {
142 unsigned long ret; 103 if (!allow_customize)
143 104 return 0;
144 ret=(unsigned long)a->addr; 105 if ((m == NULL) || (r == NULL) || (f == NULL))
145 106 return 0;
146 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
147 return(ret);
148 }
149
150static char *(*malloc_locked_func)()=(char *(*)())malloc;
151static void (*free_locked_func)()=(void (*)())free;
152static char *(*malloc_func)()= (char *(*)())malloc;
153static char *(*realloc_func)()= (char *(*)())realloc;
154static void (*free_func)()= (void (*)())free;
155
156void CRYPTO_set_mem_functions(char *(*m)(), char *(*r)(), void (*f)())
157 {
158 if ((m == NULL) || (r == NULL) || (f == NULL)) return;
159 malloc_func=m; 107 malloc_func=m;
160 realloc_func=r; 108 realloc_func=r;
161 free_func=f; 109 free_func=f;
162 malloc_locked_func=m; 110 malloc_locked_func=m;
163 free_locked_func=f; 111 free_locked_func=f;
112 return 1;
164 } 113 }
165 114
166void CRYPTO_set_locked_mem_functions(char *(*m)(), void (*f)()) 115int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *))
167 { 116 {
168 if ((m == NULL) || (f == NULL)) return; 117 if (!allow_customize)
118 return 0;
119 if ((m == NULL) || (f == NULL))
120 return 0;
169 malloc_locked_func=m; 121 malloc_locked_func=m;
170 free_locked_func=f; 122 free_locked_func=f;
123 return 1;
124 }
125
126int CRYPTO_set_mem_debug_functions(void (*m)(), void (*r)(), void (*f)(),void (*so)(),long (*go)())
127 {
128 if (!allow_customize_debug)
129 return 0;
130 malloc_debug_func=m;
131 realloc_debug_func=r;
132 free_debug_func=f;
133 set_debug_options_func=so;
134 get_debug_options_func=go;
135 return 1;
171 } 136 }
172 137
173void CRYPTO_get_mem_functions(char *(**m)(), char *(**r)(), void (**f)()) 138void CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t),
139 void (**f)(void *))
174 { 140 {
175 if (m != NULL) *m=malloc_func; 141 if (m != NULL) *m=malloc_func;
176 if (r != NULL) *r=realloc_func; 142 if (r != NULL) *r=realloc_func;
177 if (f != NULL) *f=free_func; 143 if (f != NULL) *f=free_func;
178 } 144 }
179 145
180void CRYPTO_get_locked_mem_functions(char *(**m)(), void (**f)()) 146void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *))
181 { 147 {
182 if (m != NULL) *m=malloc_locked_func; 148 if (m != NULL) *m=malloc_locked_func;
183 if (f != NULL) *f=free_locked_func; 149 if (f != NULL) *f=free_locked_func;
184 } 150 }
185 151
186void *CRYPTO_malloc_locked(int num) 152void CRYPTO_get_mem_debug_functions(void (**m)(), void (**r)(), void (**f)(),void (**so)(),long (**go)())
187 { 153 {
188 return(malloc_locked_func(num)); 154 if (m != NULL) *m=malloc_debug_func;
155 if (r != NULL) *r=realloc_debug_func;
156 if (f != NULL) *f=free_debug_func;
157 if (so != NULL) *so=set_debug_options_func;
158 if (go != NULL) *go=get_debug_options_func;
189 } 159 }
190 160
191void CRYPTO_free_locked(void *str)
192 {
193 free_locked_func(str);
194 }
195 161
196void *CRYPTO_malloc(int num) 162void *CRYPTO_malloc_locked(int num, const char *file, int line)
197 { 163 {
198 return(malloc_func(num)); 164 char *ret = NULL;
199 }
200 165
201void *CRYPTO_realloc(void *str, int num) 166 allow_customize = 0;
202 { 167 if (malloc_debug_func != NULL)
203 return(realloc_func(str,num));
204 }
205
206void CRYPTO_free(void *str)
207 {
208 free_func(str);
209 }
210
211static unsigned long break_order_num=0;
212void *CRYPTO_dbg_malloc(int num, const char *file, int line)
213 {
214 char *ret;
215 MEM *m,*mm;
216
217 if ((ret=malloc_func(num)) == NULL)
218 return(NULL);
219
220 if (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
221 { 168 {
222 MemCheck_off(); 169 allow_customize_debug = 0;
223 if ((m=(MEM *)Malloc(sizeof(MEM))) == NULL) 170 malloc_debug_func(NULL, num, file, line, 0);
224 {
225 Free(ret);
226 MemCheck_on();
227 return(NULL);
228 }
229 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
230 if (mh == NULL)
231 {
232 if ((mh=lh_new(mem_hash,mem_cmp)) == NULL)
233 {
234 Free(ret);
235 Free(m);
236 ret=NULL;
237 goto err;
238 }
239 }
240
241 m->addr=ret;
242 m->file=file;
243 m->line=line;
244 m->num=num;
245#ifdef CRYPTO_MDEBUG_THREAD
246 m->thread=CRYPTO_thread_id();
247#endif
248 if (order == break_order_num)
249 {
250 /* BREAK HERE */
251 m->order=order;
252 }
253 m->order=order++;
254#ifdef CRYPTO_MDEBUG_TIME
255 m->time=time(NULL);
256#endif
257 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
258 {
259 /* Not good, but don't sweat it */
260 Free(mm);
261 }
262err:
263 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
264 MemCheck_on();
265 } 171 }
266 return(ret); 172 ret = malloc_locked_func(num);
173#ifdef LEVITTE_DEBUG
174 fprintf(stderr, "LEVITTE_DEBUG: > 0x%p (%d)\n", ret, num);
175#endif
176 if (malloc_debug_func != NULL)
177 malloc_debug_func(ret, num, file, line, 1);
178
179 return ret;
267 } 180 }
268 181
269void CRYPTO_dbg_free(void *addr) 182void CRYPTO_free_locked(void *str)
270 { 183 {
271 MEM m,*mp; 184 if (free_debug_func != NULL)
272 185 free_debug_func(str, 0);
273 if ((mh_mode & CRYPTO_MEM_CHECK_ENABLE) && (mh != NULL)) 186#ifdef LEVITTE_DEBUG
274 { 187 fprintf(stderr, "LEVITTE_DEBUG: < 0x%p\n", str);
275 MemCheck_off(); 188#endif
276 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); 189 free_locked_func(str);
277 m.addr=addr; 190 if (free_debug_func != NULL)
278 mp=(MEM *)lh_delete(mh,(char *)&m); 191 free_debug_func(NULL, 1);
279 if (mp != NULL)
280 Free(mp);
281 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
282 MemCheck_on();
283 }
284 free_func(addr);
285 } 192 }
286 193
287void *CRYPTO_dbg_realloc(void *addr, int num, const char *file, int line) 194void *CRYPTO_malloc(int num, const char *file, int line)
288 { 195 {
289 char *ret; 196 char *ret = NULL;
290 MEM m,*mp;
291
292 ret=realloc_func(addr,num);
293 if (ret == addr) return(ret);
294 197
295 if (mh_mode & CRYPTO_MEM_CHECK_ENABLE) 198 allow_customize = 0;
199 if (malloc_debug_func != NULL)
296 { 200 {
297 MemCheck_off(); 201 allow_customize_debug = 0;
298 if (ret == NULL) return(NULL); 202 malloc_debug_func(NULL, num, file, line, 0);
299 m.addr=addr;
300 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
301 mp=(MEM *)lh_delete(mh,(char *)&m);
302 if (mp != NULL)
303 {
304 mp->addr=ret;
305 lh_insert(mh,(char *)mp);
306 }
307 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
308 MemCheck_on();
309 } 203 }
310 return(ret); 204 ret = malloc_func(num);
311 } 205#ifdef LEVITTE_DEBUG
312 206 fprintf(stderr, "LEVITTE_DEBUG: > 0x%p (%d)\n", ret, num);
313void *CRYPTO_remalloc(void *a, int n) 207#endif
314 { 208 if (malloc_debug_func != NULL)
315 if (a != NULL) Free(a); 209 malloc_debug_func(ret, num, file, line, 1);
316 a=(char *)Malloc(n);
317 return(a);
318 }
319 210
320void *CRYPTO_dbg_remalloc(void *a, int n, const char *file, int line) 211 return ret;
321 {
322 if (a != NULL) CRYPTO_dbg_free(a);
323 a=(char *)CRYPTO_dbg_malloc(n,file,line);
324 return(a);
325 } 212 }
326 213
327 214void *CRYPTO_realloc(void *str, int num, const char *file, int line)
328typedef struct mem_leak_st
329 { 215 {
330 BIO *bio; 216 char *ret = NULL;
331 int chunks;
332 long bytes;
333 } MEM_LEAK;
334 217
335static void print_leak(MEM *m, MEM_LEAK *l) 218 if (realloc_debug_func != NULL)
336 { 219 realloc_debug_func(str, NULL, num, file, line, 0);
337 char buf[128]; 220 ret = realloc_func(str,num);
338#ifdef CRYPTO_MDEBUG_TIME 221#ifdef LEVITTE_DEBUG
339 struct tm *lcl; 222 fprintf(stderr, "LEVITTE_DEBUG: | 0x%p -> 0x%p (%d)\n", str, ret, num);
340#endif 223#endif
224 if (realloc_debug_func != NULL)
225 realloc_debug_func(str, ret, num, file, line, 1);
341 226
342 if(m->addr == (char *)l->bio) 227 return ret;
343 return;
344
345#ifdef CRYPTO_MDEBUG_TIME
346 lcl = localtime(&m->time);
347#endif
348
349 sprintf(buf,
350#ifdef CRYPTO_MDEBUG_TIME
351 "[%02d:%02d:%02d] "
352#endif
353 "%5lu file=%s, line=%d, "
354#ifdef CRYPTO_MDEBUG_THREAD
355 "thread=%lu, "
356#endif
357 "number=%d, address=%08lX\n",
358#ifdef CRYPTO_MDEBUG_TIME
359 lcl->tm_hour,lcl->tm_min,lcl->tm_sec,
360#endif
361 m->order,m->file,m->line,
362#ifdef CRYPTO_MDEBUG_THREAD
363 m->thread,
364#endif
365 m->num,(unsigned long)m->addr);
366
367 BIO_puts(l->bio,buf);
368 l->chunks++;
369 l->bytes+=m->num;
370 } 228 }
371 229
372void CRYPTO_mem_leaks(BIO *b) 230void CRYPTO_free(void *str)
373 { 231 {
374 MEM_LEAK ml; 232 if (free_debug_func != NULL)
375 char buf[80]; 233 free_debug_func(str, 0);
376 234#ifdef LEVITTE_DEBUG
377 if (mh == NULL) return; 235 fprintf(stderr, "LEVITTE_DEBUG: < 0x%p\n", str);
378 ml.bio=b;
379 ml.bytes=0;
380 ml.chunks=0;
381 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
382 lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml);
383 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
384 if (ml.chunks != 0)
385 {
386 sprintf(buf,"%ld bytes leaked in %d chunks\n",
387 ml.bytes,ml.chunks);
388 BIO_puts(b,buf);
389 }
390
391#if 0
392 lh_stats_bio(mh,b);
393 lh_node_stats_bio(mh,b);
394 lh_node_usage_stats_bio(mh,b);
395#endif 236#endif
237 free_func(str);
238 if (free_debug_func != NULL)
239 free_debug_func(NULL, 1);
396 } 240 }
397 241
398static void (*mem_cb)()=NULL; 242void *CRYPTO_remalloc(void *a, int num, const char *file, int line)
399
400static void cb_leak(MEM *m, char *cb)
401 { 243 {
402 void (*mem_callback)()=(void (*)())cb; 244 if (a != NULL) Free(a);
403 mem_callback(m->order,m->file,m->line,m->num,m->addr); 245 a=(char *)Malloc(num);
246 return(a);
404 } 247 }
405 248
406void CRYPTO_mem_leaks_cb(void (*cb)()) 249
250void CRYPTO_set_mem_debug_options(long bits)
407 { 251 {
408 if (mh == NULL) return; 252 if (set_debug_options_func != NULL)
409 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); 253 set_debug_options_func(bits);
410 mem_cb=cb;
411 lh_doall_arg(mh,(void (*)())cb_leak,(char *)mem_cb);
412 mem_cb=NULL;
413 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
414 } 254 }
415 255
416#ifndef NO_FP_API 256long CRYPTO_get_mem_debug_options(void)
417void CRYPTO_mem_leaks_fp(FILE *fp)
418 { 257 {
419 BIO *b; 258 if (get_debug_options_func != NULL)
420 259 return get_debug_options_func();
421 if (mh == NULL) return; 260 return 0;
422 if ((b=BIO_new(BIO_s_file())) == NULL)
423 return;
424 BIO_set_fp(b,fp,BIO_NOCLOSE);
425 CRYPTO_mem_leaks(b);
426 BIO_free(b);
427 } 261 }
428#endif
429
diff --git a/src/lib/libcrypto/mem_dbg.c b/src/lib/libcrypto/mem_dbg.c
new file mode 100644
index 0000000000..14770c0733
--- /dev/null
+++ b/src/lib/libcrypto/mem_dbg.c
@@ -0,0 +1,703 @@
1/* crypto/mem_dbg.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <time.h>
62#include <openssl/crypto.h>
63#include <openssl/buffer.h>
64#include <openssl/bio.h>
65#include <openssl/lhash.h>
66#include "cryptlib.h"
67
68static int mh_mode=CRYPTO_MEM_CHECK_OFF;
69/* The state changes to CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE
70 * when the application asks for it (usually after library initialisation
71 * for which no book-keeping is desired).
72 *
73 * State CRYPTO_MEM_CHECK_ON exists only temporarily when the library
74 * thinks that certain allocations should not be checked (e.g. the data
75 * structures used for memory checking). It is not suitable as an initial
76 * state: the library will unexpectedly enable memory checking when it
77 * executes one of those sections that want to disable checking
78 * temporarily.
79 *
80 * State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes no sense whatsoever.
81 */
82
83static unsigned long order = 0; /* number of memory requests */
84static LHASH *mh=NULL; /* hash-table of memory requests (address as key) */
85
86
87typedef struct app_mem_info_st
88/* For application-defined information (static C-string `info')
89 * to be displayed in memory leak list.
90 * Each thread has its own stack. For applications, there is
91 * CRYPTO_push_info("...") to push an entry,
92 * CRYPTO_pop_info() to pop an entry,
93 * CRYPTO_remove_all_info() to pop all entries.
94 */
95 {
96 unsigned long thread;
97 const char *file;
98 int line;
99 const char *info;
100 struct app_mem_info_st *next; /* tail of thread's stack */
101 int references;
102 } APP_INFO;
103
104static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's
105 * that are at the top of their thread's stack
106 * (with `thread' as key) */
107
108typedef struct mem_st
109/* memory-block description */
110 {
111 char *addr;
112 int num;
113 const char *file;
114 int line;
115 unsigned long thread;
116 unsigned long order;
117 time_t time;
118 APP_INFO *app_info;
119 } MEM;
120
121static long options = /* extra information to be recorded */
122#if defined(CRYPTO_MDEBUG_TIME) || defined(CRYPTO_MDEBUG_ALL)
123 V_CRYPTO_MDEBUG_TIME |
124#endif
125#if defined(CRYPTO_MDEBUG_THREAD) || defined(CRYPTO_MDEBUG_ALL)
126 V_CRYPTO_MDEBUG_THREAD |
127#endif
128 0;
129
130
131static unsigned long disabling_thread = 0;
132
133int CRYPTO_mem_ctrl(int mode)
134 {
135 int ret=mh_mode;
136
137 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
138 switch (mode)
139 {
140 /* for applications: */
141 case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */
142 mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE;
143 disabling_thread = 0;
144 break;
145 case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
146 mh_mode = 0;
147 disabling_thread = 0;
148 break;
149
150 /* switch off temporarily (for library-internal use): */
151 case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
152 if (mh_mode & CRYPTO_MEM_CHECK_ON)
153 {
154 mh_mode&= ~CRYPTO_MEM_CHECK_ENABLE;
155 if (disabling_thread != CRYPTO_thread_id()) /* otherwise we already have the MALLOC2 lock */
156 {
157 /* Long-time lock CRYPTO_LOCK_MALLOC2 must not be claimed while
158 * we're holding CRYPTO_LOCK_MALLOC, or we'll deadlock if
159 * somebody else holds CRYPTO_LOCK_MALLOC2 (and cannot release
160 * it because we block entry to this function).
161 * Give them a chance, first, and then claim the locks in
162 * appropriate order (long-time lock first).
163 */
164 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
165 /* Note that after we have waited for CRYPTO_LOCK_MALLOC2
166 * and CRYPTO_LOCK_MALLOC, we'll still be in the right
167 * "case" and "if" branch because MemCheck_start and
168 * MemCheck_stop may never be used while there are multiple
169 * OpenSSL threads. */
170 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
171 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
172 disabling_thread=CRYPTO_thread_id();
173 }
174 }
175 break;
176 case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
177 if (mh_mode & CRYPTO_MEM_CHECK_ON)
178 {
179 mh_mode|=CRYPTO_MEM_CHECK_ENABLE;
180 if (disabling_thread != 0)
181 {
182 disabling_thread=0;
183 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
184 }
185 }
186 break;
187
188 default:
189 break;
190 }
191 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
192 return(ret);
193 }
194
195int CRYPTO_is_mem_check_on(void)
196 {
197 int ret = 0;
198
199 if (mh_mode & CRYPTO_MEM_CHECK_ON)
200 {
201 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
202
203 ret = (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
204 && disabling_thread != CRYPTO_thread_id();
205
206 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
207 }
208 return(ret);
209 }
210
211
212void CRYPTO_dbg_set_options(long bits)
213 {
214 options = bits;
215 }
216
217long CRYPTO_dbg_get_options(void)
218 {
219 return options;
220 }
221
222static int mem_cmp(MEM *a, MEM *b)
223 {
224 return(a->addr - b->addr);
225 }
226
227static unsigned long mem_hash(MEM *a)
228 {
229 unsigned long ret;
230
231 ret=(unsigned long)a->addr;
232
233 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
234 return(ret);
235 }
236
237static int app_info_cmp(APP_INFO *a, APP_INFO *b)
238 {
239 return(a->thread != b->thread);
240 }
241
242static unsigned long app_info_hash(APP_INFO *a)
243 {
244 unsigned long ret;
245
246 ret=(unsigned long)a->thread;
247
248 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
249 return(ret);
250 }
251
252static APP_INFO *pop_info()
253 {
254 APP_INFO tmp;
255 APP_INFO *ret = NULL;
256
257 if (amih != NULL)
258 {
259 tmp.thread=CRYPTO_thread_id();
260 if ((ret=(APP_INFO *)lh_delete(amih,&tmp)) != NULL)
261 {
262 APP_INFO *next=ret->next;
263
264 if (next != NULL)
265 {
266 next->references++;
267 lh_insert(amih,(char *)next);
268 }
269#ifdef LEVITTE_DEBUG
270 if (ret->thread != tmp.thread)
271 {
272 fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
273 ret->thread, tmp.thread);
274 abort();
275 }
276#endif
277 if (--(ret->references) <= 0)
278 {
279 ret->next = NULL;
280 if (next != NULL)
281 next->references--;
282 Free(ret);
283 }
284 }
285 }
286 return(ret);
287 }
288
289int CRYPTO_push_info_(const char *info, const char *file, int line)
290 {
291 APP_INFO *ami, *amim;
292 int ret=0;
293
294 if (is_MemCheck_on())
295 {
296 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
297
298 if ((ami = (APP_INFO *)Malloc(sizeof(APP_INFO))) == NULL)
299 {
300 ret=0;
301 goto err;
302 }
303 if (amih == NULL)
304 {
305 if ((amih=lh_new(app_info_hash,app_info_cmp)) == NULL)
306 {
307 Free(ami);
308 ret=0;
309 goto err;
310 }
311 }
312
313 ami->thread=CRYPTO_thread_id();
314 ami->file=file;
315 ami->line=line;
316 ami->info=info;
317 ami->references=1;
318 ami->next=NULL;
319
320 if ((amim=(APP_INFO *)lh_insert(amih,(char *)ami)) != NULL)
321 {
322#ifdef LEVITTE_DEBUG
323 if (ami->thread != amim->thread)
324 {
325 fprintf(stderr, "CRYPTO_push_info(): previous info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
326 amim->thread, ami->thread);
327 abort();
328 }
329#endif
330 ami->next=amim;
331 }
332 err:
333 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
334 }
335
336 return(ret);
337 }
338
339int CRYPTO_pop_info(void)
340 {
341 int ret=0;
342
343 if (is_MemCheck_on()) /* _must_ be true, or something went severely wrong */
344 {
345 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
346
347 ret=(pop_info() != NULL);
348
349 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
350 }
351 return(ret);
352 }
353
354int CRYPTO_remove_all_info(void)
355 {
356 int ret=0;
357
358 if (is_MemCheck_on()) /* _must_ be true */
359 {
360 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
361
362 while(pop_info() != NULL)
363 ret++;
364
365 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
366 }
367 return(ret);
368 }
369
370
371static unsigned long break_order_num=0;
372void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
373 int before_p)
374 {
375 MEM *m,*mm;
376 APP_INFO tmp,*amim;
377
378 switch(before_p & 127)
379 {
380 case 0:
381 break;
382 case 1:
383 if (addr == NULL)
384 break;
385
386 if (is_MemCheck_on())
387 {
388 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
389 if ((m=(MEM *)Malloc(sizeof(MEM))) == NULL)
390 {
391 Free(addr);
392 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
393 return;
394 }
395 if (mh == NULL)
396 {
397 if ((mh=lh_new(mem_hash,mem_cmp)) == NULL)
398 {
399 Free(addr);
400 Free(m);
401 addr=NULL;
402 goto err;
403 }
404 }
405
406 m->addr=addr;
407 m->file=file;
408 m->line=line;
409 m->num=num;
410 if (options & V_CRYPTO_MDEBUG_THREAD)
411 m->thread=CRYPTO_thread_id();
412 else
413 m->thread=0;
414
415 if (order == break_order_num)
416 {
417 /* BREAK HERE */
418 m->order=order;
419 }
420 m->order=order++;
421#ifdef LEVITTE_DEBUG
422 fprintf(stderr, "LEVITTE_DEBUG: [%5d] %c 0x%p (%d)\n",
423 m->order,
424 (before_p & 128) ? '*' : '+',
425 m->addr, m->num);
426#endif
427 if (options & V_CRYPTO_MDEBUG_TIME)
428 m->time=time(NULL);
429 else
430 m->time=0;
431
432 tmp.thread=CRYPTO_thread_id();
433 m->app_info=NULL;
434 if (amih != NULL
435 && (amim=(APP_INFO *)lh_retrieve(amih,(char *)&tmp)) != NULL)
436 {
437 m->app_info = amim;
438 amim->references++;
439 }
440
441 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
442 {
443 /* Not good, but don't sweat it */
444 if (mm->app_info != NULL)
445 {
446 mm->app_info->references--;
447 }
448 Free(mm);
449 }
450 err:
451 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
452 }
453 break;
454 }
455 return;
456 }
457
458void CRYPTO_dbg_free(void *addr, int before_p)
459 {
460 MEM m,*mp;
461
462 switch(before_p)
463 {
464 case 0:
465 if (addr == NULL)
466 break;
467
468 if (is_MemCheck_on() && (mh != NULL))
469 {
470 MemCheck_off();
471
472 m.addr=addr;
473 mp=(MEM *)lh_delete(mh,(char *)&m);
474 if (mp != NULL)
475 {
476#ifdef LEVITTE_DEBUG
477 fprintf(stderr, "LEVITTE_DEBUG: [%5d] - 0x%p (%d)\n",
478 mp->order, mp->addr, mp->num);
479#endif
480 if (mp->app_info != NULL)
481 {
482 mp->app_info->references--;
483 }
484 Free(mp);
485 }
486
487 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
488 }
489 break;
490 case 1:
491 break;
492 }
493 }
494
495void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,
496 const char *file, int line, int before_p)
497 {
498 MEM m,*mp;
499
500#ifdef LEVITTE_DEBUG
501 fprintf(stderr, "LEVITTE_DEBUG: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \"%s\", line = %d, before_p = %d)\n",
502 addr1, addr2, num, file, line, before_p);
503#endif
504
505 switch(before_p)
506 {
507 case 0:
508 break;
509 case 1:
510 if (addr2 == NULL)
511 break;
512
513 if (addr1 == NULL)
514 {
515 CRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);
516 break;
517 }
518
519 if (is_MemCheck_on())
520 {
521 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
522
523 m.addr=addr1;
524 mp=(MEM *)lh_delete(mh,(char *)&m);
525 if (mp != NULL)
526 {
527#ifdef LEVITTE_DEBUG
528 fprintf(stderr, "LEVITTE_DEBUG: [%5d] * 0x%p (%d) -> 0x%p (%d)\n",
529 mp->order,
530 mp->addr, mp->num,
531 addr2, num);
532#endif
533 mp->addr=addr2;
534 mp->num=num;
535 lh_insert(mh,(char *)mp);
536 }
537
538 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
539 }
540 break;
541 }
542 return;
543 }
544
545
546typedef struct mem_leak_st
547 {
548 BIO *bio;
549 int chunks;
550 long bytes;
551 } MEM_LEAK;
552
553static void print_leak(MEM *m, MEM_LEAK *l)
554 {
555 char buf[1024];
556 char *bufp = buf;
557 APP_INFO *amip;
558 int ami_cnt;
559 struct tm *lcl = NULL;
560 unsigned long ti;
561
562 if(m->addr == (char *)l->bio)
563 return;
564
565 if (options & V_CRYPTO_MDEBUG_TIME)
566 {
567 lcl = localtime(&m->time);
568
569 sprintf(bufp, "[%02d:%02d:%02d] ",
570 lcl->tm_hour,lcl->tm_min,lcl->tm_sec);
571 bufp += strlen(bufp);
572 }
573
574 sprintf(bufp, "%5lu file=%s, line=%d, ",
575 m->order,m->file,m->line);
576 bufp += strlen(bufp);
577
578 if (options & V_CRYPTO_MDEBUG_THREAD)
579 {
580 sprintf(bufp, "thread=%lu, ", m->thread);
581 bufp += strlen(bufp);
582 }
583
584 sprintf(bufp, "number=%d, address=%08lX\n",
585 m->num,(unsigned long)m->addr);
586 bufp += strlen(bufp);
587
588 BIO_puts(l->bio,buf);
589
590 l->chunks++;
591 l->bytes+=m->num;
592
593 amip=m->app_info;
594 ami_cnt=0;
595 if (!amip)
596 return;
597 ti=amip->thread;
598
599 do
600 {
601 int buf_len;
602 int info_len;
603
604 ami_cnt++;
605 memset(buf,'>',ami_cnt);
606 sprintf(buf + ami_cnt,
607 " thread=%lu, file=%s, line=%d, info=\"",
608 amip->thread, amip->file, amip->line);
609 buf_len=strlen(buf);
610 info_len=strlen(amip->info);
611 if (128 - buf_len - 3 < info_len)
612 {
613 memcpy(buf + buf_len, amip->info, 128 - buf_len - 3);
614 buf_len = 128 - 3;
615 }
616 else
617 {
618 strcpy(buf + buf_len, amip->info);
619 buf_len = strlen(buf);
620 }
621 sprintf(buf + buf_len, "\"\n");
622
623 BIO_puts(l->bio,buf);
624
625 amip = amip->next;
626 }
627 while(amip && amip->thread == ti);
628
629#ifdef LEVITTE_DEBUG
630 if (amip)
631 {
632 fprintf(stderr, "Thread switch detected in backtrace!!!!\n");
633 abort();
634 }
635#endif
636 }
637
638void CRYPTO_mem_leaks(BIO *b)
639 {
640 MEM_LEAK ml;
641 char buf[80];
642
643 if (mh == NULL) return;
644 ml.bio=b;
645 ml.bytes=0;
646 ml.chunks=0;
647 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
648 lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml);
649 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
650 if (ml.chunks != 0)
651 {
652 sprintf(buf,"%ld bytes leaked in %d chunks\n",
653 ml.bytes,ml.chunks);
654 BIO_puts(b,buf);
655 }
656
657#if 0
658 lh_stats_bio(mh,b);
659 lh_node_stats_bio(mh,b);
660 lh_node_usage_stats_bio(mh,b);
661#endif
662 }
663
664union void_fn_to_char_u
665 {
666 char *char_p;
667 void (*fn_p)();
668 };
669
670static void cb_leak(MEM *m, char *cb)
671 {
672 union void_fn_to_char_u mem_callback;
673
674 mem_callback.char_p=cb;
675 mem_callback.fn_p(m->order,m->file,m->line,m->num,m->addr);
676 }
677
678void CRYPTO_mem_leaks_cb(void (*cb)())
679 {
680 union void_fn_to_char_u mem_cb;
681
682 if (mh == NULL) return;
683 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
684 mem_cb.fn_p=cb;
685 lh_doall_arg(mh,(void (*)())cb_leak,mem_cb.char_p);
686 mem_cb.char_p=NULL;
687 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
688 }
689
690#ifndef NO_FP_API
691void CRYPTO_mem_leaks_fp(FILE *fp)
692 {
693 BIO *b;
694
695 if (mh == NULL) return;
696 if ((b=BIO_new(BIO_s_file())) == NULL)
697 return;
698 BIO_set_fp(b,fp,BIO_NOCLOSE);
699 CRYPTO_mem_leaks(b);
700 BIO_free(b);
701 }
702#endif
703
diff --git a/src/lib/libcrypto/objects/Makefile.ssl b/src/lib/libcrypto/objects/Makefile.ssl
index 53450f8754..f05e15df96 100644
--- a/src/lib/libcrypto/objects/Makefile.ssl
+++ b/src/lib/libcrypto/objects/Makefile.ssl
@@ -37,9 +37,6 @@ top:
37 37
38all: obj_dat.h lib 38all: obj_dat.h lib
39 39
40obj_dat.h: objects.h obj_dat.pl
41 $(PERL) ./obj_dat.pl < objects.h > obj_dat.h
42
43lib: $(LIBOBJ) 40lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
45 $(RANLIB) $(LIB) 42 $(RANLIB) $(LIB)
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
index 4da5e45b9c..d654eb220e 100644
--- a/src/lib/libcrypto/objects/o_names.c
+++ b/src/lib/libcrypto/objects/o_names.c
@@ -4,15 +4,25 @@
4 4
5#include <openssl/lhash.h> 5#include <openssl/lhash.h>
6#include <openssl/objects.h> 6#include <openssl/objects.h>
7#include <openssl/safestack.h>
7 8
8/* I use the ex_data stuff to manage the identifiers for the obj_name_types 9/* I use the ex_data stuff to manage the identifiers for the obj_name_types
9 * that applications may define. I only really use the free function field. 10 * that applications may define. I only really use the free function field.
10 */ 11 */
11static LHASH *names_lh=NULL; 12static LHASH *names_lh=NULL;
12static int names_type_num=OBJ_NAME_TYPE_NUM; 13static int names_type_num=OBJ_NAME_TYPE_NUM;
13static STACK *names_cmp=NULL; 14
14static STACK *names_hash=NULL; 15typedef struct name_funcs_st
15static STACK *names_free=NULL; 16 {
17 unsigned long (*hash_func)();
18 int (*cmp_func)();
19 void (*free_func)();
20 } NAME_FUNCS;
21
22DECLARE_STACK_OF(NAME_FUNCS)
23IMPLEMENT_STACK_OF(NAME_FUNCS)
24
25STACK_OF(NAME_FUNCS) *name_funcs_stack;
16 26
17static unsigned long obj_name_hash(OBJ_NAME *a); 27static unsigned long obj_name_hash(OBJ_NAME *a);
18static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); 28static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b);
@@ -31,51 +41,57 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(), int (*cmp_func)(),
31 { 41 {
32 int ret; 42 int ret;
33 int i; 43 int i;
44 NAME_FUNCS *name_funcs;
34 45
35 if (names_free == NULL) 46 if (name_funcs_stack == NULL)
36 { 47 {
37 MemCheck_off(); 48 MemCheck_off();
38 names_hash=sk_new_null(); 49 name_funcs_stack=sk_NAME_FUNCS_new_null();
39 names_cmp=sk_new_null();
40 names_free=sk_new_null();
41 MemCheck_on(); 50 MemCheck_on();
42 } 51 }
43 if ((names_free == NULL) || (names_hash == NULL) || (names_cmp == NULL)) 52 if ((name_funcs_stack == NULL))
44 { 53 {
45 /* ERROR */ 54 /* ERROR */
46 return(0); 55 return(0);
47 } 56 }
48 ret=names_type_num; 57 ret=names_type_num;
49 names_type_num++; 58 names_type_num++;
50 for (i=sk_num(names_free); i<names_type_num; i++) 59 for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++)
51 { 60 {
52 MemCheck_off(); 61 MemCheck_off();
53 sk_push(names_hash,(char *)strcmp); 62 name_funcs = Malloc(sizeof(NAME_FUNCS));
54 sk_push(names_cmp,(char *)lh_strhash); 63 name_funcs->hash_func = lh_strhash;
55 sk_push(names_free,NULL); 64 name_funcs->cmp_func = (int (*)())strcmp;
65 name_funcs->free_func = 0; /* NULL is often declared to
66 * ((void *)0), which according
67 * to Compaq C is not really
68 * compatible with a function
69 * pointer. -- Richard Levitte*/
70 sk_NAME_FUNCS_push(name_funcs_stack,name_funcs);
56 MemCheck_on(); 71 MemCheck_on();
57 } 72 }
73 name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
58 if (hash_func != NULL) 74 if (hash_func != NULL)
59 sk_set(names_hash,ret,(char *)hash_func); 75 name_funcs->hash_func = hash_func;
60 if (cmp_func != NULL) 76 if (cmp_func != NULL)
61 sk_set(names_cmp,ret,(char *)cmp_func); 77 name_funcs->cmp_func = cmp_func;
62 if (free_func != NULL) 78 if (free_func != NULL)
63 sk_set(names_free,ret,(char *)free_func); 79 name_funcs->free_func = free_func;
64 return(ret); 80 return(ret);
65 } 81 }
66 82
67static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b) 83static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b)
68 { 84 {
69 int ret; 85 int ret;
70 int (*cmp)();
71 86
72 ret=a->type-b->type; 87 ret=a->type-b->type;
73 if (ret == 0) 88 if (ret == 0)
74 { 89 {
75 if ((names_cmp != NULL) && (sk_num(names_cmp) > a->type)) 90 if ((name_funcs_stack != NULL)
91 && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
76 { 92 {
77 cmp=(int (*)())sk_value(names_cmp,a->type); 93 ret=sk_NAME_FUNCS_value(name_funcs_stack,a->type)
78 ret=cmp(a->name,b->name); 94 ->cmp_func(a->name,b->name);
79 } 95 }
80 else 96 else
81 ret=strcmp(a->name,b->name); 97 ret=strcmp(a->name,b->name);
@@ -86,12 +102,11 @@ static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b)
86static unsigned long obj_name_hash(OBJ_NAME *a) 102static unsigned long obj_name_hash(OBJ_NAME *a)
87 { 103 {
88 unsigned long ret; 104 unsigned long ret;
89 unsigned long (*hash)();
90 105
91 if ((names_hash != NULL) && (sk_num(names_hash) > a->type)) 106 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
92 { 107 {
93 hash=(unsigned long (*)())sk_value(names_hash,a->type); 108 ret=sk_NAME_FUNCS_value(name_funcs_stack,a->type)
94 ret=hash(a->name); 109 ->hash_func(a->name);
95 } 110 }
96 else 111 else
97 { 112 {
@@ -117,7 +132,7 @@ const char *OBJ_NAME_get(const char *name, int type)
117 132
118 for (;;) 133 for (;;)
119 { 134 {
120 ret=(OBJ_NAME *)lh_retrieve(names_lh,(char *)&on); 135 ret=(OBJ_NAME *)lh_retrieve(names_lh,&on);
121 if (ret == NULL) return(NULL); 136 if (ret == NULL) return(NULL);
122 if ((ret->alias) && !alias) 137 if ((ret->alias) && !alias)
123 { 138 {
@@ -133,7 +148,6 @@ const char *OBJ_NAME_get(const char *name, int type)
133 148
134int OBJ_NAME_add(const char *name, int type, const char *data) 149int OBJ_NAME_add(const char *name, int type, const char *data)
135 { 150 {
136 void (*f)();
137 OBJ_NAME *onp,*ret; 151 OBJ_NAME *onp,*ret;
138 int alias; 152 int alias;
139 153
@@ -154,16 +168,20 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
154 onp->type=type; 168 onp->type=type;
155 onp->data=data; 169 onp->data=data;
156 170
157 ret=(OBJ_NAME *)lh_insert(names_lh,(char *)onp); 171 ret=(OBJ_NAME *)lh_insert(names_lh,onp);
158 if (ret != NULL) 172 if (ret != NULL)
159 { 173 {
160 /* free things */ 174 /* free things */
161 if ((names_free != NULL) && (sk_num(names_free) > ret->type)) 175 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
162 { 176 {
163 f=(void (*)())sk_value(names_free,ret->type); 177 /* XXX: I'm not sure I understand why the free
164 f(ret->name,ret->type,ret->data); 178 * function should get three arguments...
179 * -- Richard Levitte
180 */
181 sk_NAME_FUNCS_value(name_funcs_stack,ret->type)
182 ->free_func(ret->name,ret->type,ret->data);
165 } 183 }
166 Free((char *)ret); 184 Free(ret);
167 } 185 }
168 else 186 else
169 { 187 {
@@ -179,23 +197,26 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
179int OBJ_NAME_remove(const char *name, int type) 197int OBJ_NAME_remove(const char *name, int type)
180 { 198 {
181 OBJ_NAME on,*ret; 199 OBJ_NAME on,*ret;
182 void (*f)();
183 200
184 if (names_lh == NULL) return(0); 201 if (names_lh == NULL) return(0);
185 202
186 type&= ~OBJ_NAME_ALIAS; 203 type&= ~OBJ_NAME_ALIAS;
187 on.name=name; 204 on.name=name;
188 on.type=type; 205 on.type=type;
189 ret=(OBJ_NAME *)lh_delete(names_lh,(char *)&on); 206 ret=(OBJ_NAME *)lh_delete(names_lh,&on);
190 if (ret != NULL) 207 if (ret != NULL)
191 { 208 {
192 /* free things */ 209 /* free things */
193 if ((names_free != NULL) && (sk_num(names_free) > type)) 210 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
194 { 211 {
195 f=(void (*)())sk_value(names_free,type); 212 /* XXX: I'm not sure I understand why the free
196 f(ret->name,ret->type,ret->data); 213 * function should get three arguments...
214 * -- Richard Levitte
215 */
216 sk_NAME_FUNCS_value(name_funcs_stack,ret->type)
217 ->free_func(ret->name,ret->type,ret->data);
197 } 218 }
198 Free((char *)ret); 219 Free(ret);
199 return(1); 220 return(1);
200 } 221 }
201 else 222 else
@@ -215,6 +236,11 @@ static void names_lh_free(OBJ_NAME *onp, int type)
215 } 236 }
216 } 237 }
217 238
239static void name_funcs_free(NAME_FUNCS *ptr)
240 {
241 Free(ptr);
242 }
243
218void OBJ_NAME_cleanup(int type) 244void OBJ_NAME_cleanup(int type)
219 { 245 {
220 unsigned long down_load; 246 unsigned long down_load;
@@ -229,13 +255,9 @@ void OBJ_NAME_cleanup(int type)
229 if (type < 0) 255 if (type < 0)
230 { 256 {
231 lh_free(names_lh); 257 lh_free(names_lh);
232 sk_free(names_hash); 258 sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free);
233 sk_free(names_cmp);
234 sk_free(names_free);
235 names_lh=NULL; 259 names_lh=NULL;
236 names_hash=NULL; 260 name_funcs_stack = NULL;
237 names_cmp=NULL;
238 names_free=NULL;
239 } 261 }
240 else 262 else
241 names_lh->down_load=down_load; 263 names_lh->down_load=down_load;
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index d47b874399..da6df3762a 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -214,16 +214,12 @@ int OBJ_new_nid(int num)
214int OBJ_add_object(ASN1_OBJECT *obj) 214int OBJ_add_object(ASN1_OBJECT *obj)
215 { 215 {
216 ASN1_OBJECT *o; 216 ASN1_OBJECT *o;
217 ADDED_OBJ *ao[4],*aop; 217 ADDED_OBJ *ao[4]={NULL,NULL,NULL,NULL},*aop;
218 int i; 218 int i;
219 219
220 if (added == NULL) 220 if (added == NULL)
221 if (!init_added()) return(0); 221 if (!init_added()) return(0);
222 if ((o=OBJ_dup(obj)) == NULL) goto err; 222 if ((o=OBJ_dup(obj)) == NULL) goto err;
223 ao[ADDED_DATA]=NULL;
224 ao[ADDED_SNAME]=NULL;
225 ao[ADDED_LNAME]=NULL;
226 ao[ADDED_NID]=NULL;
227 ao[ADDED_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); 223 ao[ADDED_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
228 if ((o->length != 0) && (obj->data != NULL)) 224 if ((o->length != 0) && (obj->data != NULL))
229 ao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); 225 ao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
@@ -238,7 +234,7 @@ int OBJ_add_object(ASN1_OBJECT *obj)
238 { 234 {
239 ao[i]->type=i; 235 ao[i]->type=i;
240 ao[i]->obj=o; 236 ao[i]->obj=o;
241 aop=(ADDED_OBJ *)lh_insert(added,(char *)ao[i]); 237 aop=(ADDED_OBJ *)lh_insert(added,ao[i]);
242 /* memory leak, buit should not normally matter */ 238 /* memory leak, buit should not normally matter */
243 if (aop != NULL) 239 if (aop != NULL)
244 Free(aop); 240 Free(aop);
@@ -276,7 +272,7 @@ ASN1_OBJECT *OBJ_nid2obj(int n)
276 ad.type=ADDED_NID; 272 ad.type=ADDED_NID;
277 ad.obj= &ob; 273 ad.obj= &ob;
278 ob.nid=n; 274 ob.nid=n;
279 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); 275 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
280 if (adp != NULL) 276 if (adp != NULL)
281 return(adp->obj); 277 return(adp->obj);
282 else 278 else
@@ -308,7 +304,7 @@ const char *OBJ_nid2sn(int n)
308 ad.type=ADDED_NID; 304 ad.type=ADDED_NID;
309 ad.obj= &ob; 305 ad.obj= &ob;
310 ob.nid=n; 306 ob.nid=n;
311 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); 307 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
312 if (adp != NULL) 308 if (adp != NULL)
313 return(adp->obj->sn); 309 return(adp->obj->sn);
314 else 310 else
@@ -340,7 +336,7 @@ const char *OBJ_nid2ln(int n)
340 ad.type=ADDED_NID; 336 ad.type=ADDED_NID;
341 ad.obj= &ob; 337 ad.obj= &ob;
342 ob.nid=n; 338 ob.nid=n;
343 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); 339 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
344 if (adp != NULL) 340 if (adp != NULL)
345 return(adp->obj->ln); 341 return(adp->obj->ln);
346 else 342 else
@@ -365,7 +361,7 @@ int OBJ_obj2nid(ASN1_OBJECT *a)
365 { 361 {
366 ad.type=ADDED_DATA; 362 ad.type=ADDED_DATA;
367 ad.obj=a; 363 ad.obj=a;
368 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); 364 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
369 if (adp != NULL) return (adp->obj->nid); 365 if (adp != NULL) return (adp->obj->nid);
370 } 366 }
371 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ, 367 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,
@@ -504,7 +500,7 @@ int OBJ_ln2nid(const char *s)
504 { 500 {
505 ad.type=ADDED_LNAME; 501 ad.type=ADDED_LNAME;
506 ad.obj= &o; 502 ad.obj= &o;
507 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); 503 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
508 if (adp != NULL) return (adp->obj->nid); 504 if (adp != NULL) return (adp->obj->nid);
509 } 505 }
510 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN, 506 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN,
@@ -523,7 +519,7 @@ int OBJ_sn2nid(const char *s)
523 { 519 {
524 ad.type=ADDED_SNAME; 520 ad.type=ADDED_SNAME;
525 ad.obj= &o; 521 ad.obj= &o;
526 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); 522 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
527 if (adp != NULL) return (adp->obj->nid); 523 if (adp != NULL) return (adp->obj->nid);
528 } 524 }
529 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN, 525 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
@@ -647,7 +643,7 @@ int OBJ_create(char *oid, char *sn, char *ln)
647 ok=OBJ_add_object(op); 643 ok=OBJ_add_object(op);
648err: 644err:
649 ASN1_OBJECT_free(op); 645 ASN1_OBJECT_free(op);
650 Free((char *)buf); 646 Free(buf);
651 return(ok); 647 return(ok);
652 } 648 }
653 649
diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl
index 5043daef2a..e6e3c3b9c0 100644
--- a/src/lib/libcrypto/objects/obj_dat.pl
+++ b/src/lib/libcrypto/objects/obj_dat.pl
@@ -38,7 +38,10 @@ sub expand_obj
38 return(%objn); 38 return(%objn);
39 } 39 }
40 40
41while (<>) 41open (IN,"$ARGV[0]") || die "Can't open input file $ARGV[0]";
42open (OUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
43
44while (<IN>)
42 { 45 {
43 next unless /^\#define\s+(\S+)\s+(.*)$/; 46 next unless /^\#define\s+(\S+)\s+(.*)$/;
44 $v=$1; 47 $v=$1;
@@ -55,6 +58,7 @@ while (<>)
55 $objd{$v}=$d; 58 $objd{$v}=$d;
56 } 59 }
57 } 60 }
61close IN;
58 62
59%ob=&expand_obj(*objd); 63%ob=&expand_obj(*objd);
60 64
@@ -132,7 +136,7 @@ foreach (sort obj_cmp @a)
132 push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v)); 136 push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v));
133 } 137 }
134 138
135print <<'EOF'; 139print OUT <<'EOF';
136/* lib/obj/obj_dat.h */ 140/* lib/obj/obj_dat.h */
137/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 141/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
138 * All rights reserved. 142 * All rights reserved.
@@ -193,21 +197,21 @@ print <<'EOF';
193 197
194/* THIS FILE IS GENERATED FROM Objects.h by obj_dat.pl via the 198/* THIS FILE IS GENERATED FROM Objects.h by obj_dat.pl via the
195 * following command: 199 * following command:
196 * perl obj_dat.pl < objects.h > obj_dat.h 200 * perl obj_dat.pl objects.h obj_dat.h
197 */ 201 */
198 202
199EOF 203EOF
200 204
201printf "#define NUM_NID %d\n",$n; 205printf OUT "#define NUM_NID %d\n",$n;
202printf "#define NUM_SN %d\n",$#sn+1; 206printf OUT "#define NUM_SN %d\n",$#sn+1;
203printf "#define NUM_LN %d\n",$#ln+1; 207printf OUT "#define NUM_LN %d\n",$#ln+1;
204printf "#define NUM_OBJ %d\n\n",$#ob+1; 208printf OUT "#define NUM_OBJ %d\n\n",$#ob+1;
205 209
206printf "static unsigned char lvalues[%d]={\n",$lvalues+1; 210printf OUT "static unsigned char lvalues[%d]={\n",$lvalues+1;
207print @lvalues; 211print OUT @lvalues;
208print "};\n\n"; 212print OUT "};\n\n";
209 213
210printf "static ASN1_OBJECT nid_objs[NUM_NID]={\n"; 214printf OUT "static ASN1_OBJECT nid_objs[NUM_NID]={\n";
211foreach (@out) 215foreach (@out)
212 { 216 {
213 if (length($_) > 75) 217 if (length($_) > 75)
@@ -218,30 +222,32 @@ foreach (@out)
218 $t=$out.$_.","; 222 $t=$out.$_.",";
219 if (length($t) > 70) 223 if (length($t) > 70)
220 { 224 {
221 print "$out\n"; 225 print OUT "$out\n";
222 $t="\t$_,"; 226 $t="\t$_,";
223 } 227 }
224 $out=$t; 228 $out=$t;
225 } 229 }
226 chop $out; 230 chop $out;
227 print "$out"; 231 print OUT "$out";
228 } 232 }
229 else 233 else
230 { print $_; } 234 { print OUT $_; }
231 } 235 }
232print "};\n\n"; 236print OUT "};\n\n";
237
238printf OUT "static ASN1_OBJECT *sn_objs[NUM_SN]={\n";
239print OUT @sn;
240print OUT "};\n\n";
233 241
234printf "static ASN1_OBJECT *sn_objs[NUM_SN]={\n"; 242printf OUT "static ASN1_OBJECT *ln_objs[NUM_LN]={\n";
235print @sn; 243print OUT @ln;
236print "};\n\n"; 244print OUT "};\n\n";
237 245
238printf "static ASN1_OBJECT *ln_objs[NUM_LN]={\n"; 246printf OUT "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n";
239print @ln; 247print OUT @ob;
240print "};\n\n"; 248print OUT "};\n\n";
241 249
242printf "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n"; 250close OUT;
243print @ob;
244print "};\n\n";
245 251
246sub der_it 252sub der_it
247 { 253 {
diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h
index d03748e022..d1a5ad2502 100644
--- a/src/lib/libcrypto/objects/objects.h
+++ b/src/lib/libcrypto/objects/objects.h
@@ -110,10 +110,12 @@ extern "C" {
110#define NID_md5WithRSAEncryption 8 110#define NID_md5WithRSAEncryption 8
111#define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L 111#define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L
112 112
113#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES"
113#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC" 114#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
114#define NID_pbeWithMD2AndDES_CBC 9 115#define NID_pbeWithMD2AndDES_CBC 9
115#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L 116#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L
116 117
118#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES"
117#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC" 119#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
118#define NID_pbeWithMD5AndDES_CBC 10 120#define NID_pbeWithMD5AndDES_CBC 10
119#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L 121#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L
@@ -230,6 +232,7 @@ extern "C" {
230#define SN_idea_cbc "IDEA-CBC" 232#define SN_idea_cbc "IDEA-CBC"
231#define LN_idea_cbc "idea-cbc" 233#define LN_idea_cbc "idea-cbc"
232#define NID_idea_cbc 34 234#define NID_idea_cbc 34
235#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L
233 236
234#define SN_idea_cfb64 "IDEA-CFB" 237#define SN_idea_cfb64 "IDEA-CFB"
235#define LN_idea_cfb64 "idea-cfb" 238#define LN_idea_cfb64 "idea-cfb"
@@ -380,6 +383,7 @@ extern "C" {
380#define OBJ_dsa_2 OBJ_algorithm,12L 383#define OBJ_dsa_2 OBJ_algorithm,12L
381 384
382/* proposed by microsoft to RSA */ 385/* proposed by microsoft to RSA */
386#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
383#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" 387#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
384#define NID_pbeWithSHA1AndRC2_CBC 68 388#define NID_pbeWithSHA1AndRC2_CBC 68
385#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L 389#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
@@ -499,6 +503,7 @@ extern "C" {
499#define SN_bf_cbc "BF-CBC" 503#define SN_bf_cbc "BF-CBC"
500#define LN_bf_cbc "bf-cbc" 504#define LN_bf_cbc "bf-cbc"
501#define NID_bf_cbc 91 505#define NID_bf_cbc 91
506#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L
502 507
503#define SN_bf_ecb "BF-ECB" 508#define SN_bf_ecb "BF-ECB"
504#define LN_bf_ecb "bf-ecb" 509#define LN_bf_ecb "bf-ecb"
@@ -627,7 +632,7 @@ extern "C" {
627#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L 632#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
628 633
629/* The name should actually be rsaSignatureWithripemd160, but I'm going 634/* The name should actually be rsaSignatureWithripemd160, but I'm going
630 * to contiune using the convention I'm using with the other ciphers */ 635 * to continue using the convention I'm using with the other ciphers */
631#define SN_ripemd160WithRSA "RSA-RIPEMD160" 636#define SN_ripemd160WithRSA "RSA-RIPEMD160"
632#define LN_ripemd160WithRSA "ripemd160WithRSA" 637#define LN_ripemd160WithRSA "ripemd160WithRSA"
633#define NID_ripemd160WithRSA 119 638#define NID_ripemd160WithRSA 119
@@ -661,12 +666,12 @@ extern "C" {
661#define SN_rle_compression "RLE" 666#define SN_rle_compression "RLE"
662#define LN_rle_compression "run length compression" 667#define LN_rle_compression "run length compression"
663#define NID_rle_compression 124 668#define NID_rle_compression 124
664#define OBJ_rle_compression 1L,1L,1L,1L,666L.1L 669#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L
665 670
666#define SN_zlib_compression "ZLIB" 671#define SN_zlib_compression "ZLIB"
667#define LN_zlib_compression "zlib compression" 672#define LN_zlib_compression "zlib compression"
668#define NID_zlib_compression 125 673#define NID_zlib_compression 125
669#define OBJ_zlib_compression 1L,1L,1L,1L,666L.2L 674#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L
670 675
671#define SN_ext_key_usage "extendedKeyUsage" 676#define SN_ext_key_usage "extendedKeyUsage"
672#define LN_ext_key_usage "X509v3 Extended Key Usage" 677#define LN_ext_key_usage "X509v3 Extended Key Usage"
@@ -735,7 +740,7 @@ extern "C" {
735#define NID_ms_efs 138 740#define NID_ms_efs 138
736#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L 741#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
737 742
738/* Addidional usage: Netscape */ 743/* Additional usage: Netscape */
739 744
740#define SN_ns_sgc "nsSGC" 745#define SN_ns_sgc "nsSGC"
741#define LN_ns_sgc "Netscape Server Gated Crypto" 746#define LN_ns_sgc "Netscape Server Gated Crypto"
@@ -767,26 +772,32 @@ extern "C" {
767#define OBJ_pkcs12 OBJ_pkcs,12L 772#define OBJ_pkcs12 OBJ_pkcs,12L
768#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1 773#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1
769 774
775#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128"
770#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4" 776#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
771#define NID_pbe_WithSHA1And128BitRC4 144 777#define NID_pbe_WithSHA1And128BitRC4 144
772#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L 778#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L
773 779
780#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40"
774#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4" 781#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
775#define NID_pbe_WithSHA1And40BitRC4 145 782#define NID_pbe_WithSHA1And40BitRC4 145
776#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L 783#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L
777 784
785#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES"
778#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC" 786#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
779#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146 787#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
780#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L 788#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L
781 789
790#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES"
782#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC" 791#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
783#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147 792#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
784#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L 793#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L
785 794
795#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128"
786#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC" 796#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
787#define NID_pbe_WithSHA1And128BitRC2_CBC 148 797#define NID_pbe_WithSHA1And128BitRC2_CBC 148
788#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L 798#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L
789 799
800#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40"
790#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC" 801#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
791#define NID_pbe_WithSHA1And40BitRC2_CBC 149 802#define NID_pbe_WithSHA1And40BitRC2_CBC 149
792#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L 803#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L
@@ -876,20 +887,73 @@ extern "C" {
876#define SN_SMIMECapabilities "SMIME-CAPS" 887#define SN_SMIMECapabilities "SMIME-CAPS"
877#define LN_SMIMECapabilities "S/MIME Capabilities" 888#define LN_SMIMECapabilities "S/MIME Capabilities"
878#define NID_SMIMECapabilities 167 889#define NID_SMIMECapabilities 167
879#define OBJ_SMIMECapabilities OBJ_id_pkcs9,15L 890#define OBJ_SMIMECapabilities OBJ_pkcs9,15L
880 891
892#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64"
881#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC" 893#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
882#define NID_pbeWithMD2AndRC2_CBC 168 894#define NID_pbeWithMD2AndRC2_CBC 168
883#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L 895#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L
884 896
897#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64"
885#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC" 898#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
886#define NID_pbeWithMD5AndRC2_CBC 169 899#define NID_pbeWithMD5AndRC2_CBC 169
887#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L 900#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L
888 901
902#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES"
889#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC" 903#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
890#define NID_pbeWithSHA1AndDES_CBC 170 904#define NID_pbeWithSHA1AndDES_CBC 170
891#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L 905#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L
892 906
907/* Extension request OIDs */
908
909#define LN_ms_ext_req "Microsoft Extension Request"
910#define SN_ms_ext_req "msExtReq"
911#define NID_ms_ext_req 171
912#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L
913
914#define LN_ext_req "Extension Request"
915#define SN_ext_req "extReq"
916#define NID_ext_req 172
917#define OBJ_ext_req OBJ_pkcs9,14L
918
919#define SN_name "name"
920#define LN_name "name"
921#define NID_name 173
922#define OBJ_name OBJ_X509,41L
923
924#define SN_dnQualifier "dnQualifier"
925#define LN_dnQualifier "dnQualifier"
926#define NID_dnQualifier 174
927#define OBJ_dnQualifier OBJ_X509,46L
928
929#define SN_id_pe "id-pe"
930#define NID_id_pe 175
931#define OBJ_id_pe OBJ_id_pkix,1L
932
933#define SN_id_ad "id-ad"
934#define NID_id_ad 176
935#define OBJ_id_ad OBJ_id_pkix,48L
936
937#define SN_info_access "authorityInfoAccess"
938#define LN_info_access "Authority Information Access"
939#define NID_info_access 177
940#define OBJ_info_access OBJ_id_pe,1L
941
942#define SN_ad_OCSP "OCSP"
943#define LN_ad_OCSP "OCSP"
944#define NID_ad_OCSP 178
945#define OBJ_ad_OCSP OBJ_id_ad,1L
946
947#define SN_ad_ca_issuers "caIssuers"
948#define LN_ad_ca_issuers "CA Issuers"
949#define NID_ad_ca_issuers 179
950#define OBJ_ad_ca_issuers OBJ_id_ad,2L
951
952#define SN_OSCP_sign "OCSPSigning"
953#define LN_OCSP_sign "OCSP Signing"
954#define NID_OCSP_sign 180
955#define OBJ_OCSP_sign OBJ_id_kp,9L
956
893#include <openssl/bio.h> 957#include <openssl/bio.h>
894#include <openssl/asn1.h> 958#include <openssl/asn1.h>
895 959
diff --git a/src/lib/libcrypto/opensslconf.h.in b/src/lib/libcrypto/opensslconf.h.in
index e4a8f8ad54..1b85ae5989 100644
--- a/src/lib/libcrypto/opensslconf.h.in
+++ b/src/lib/libcrypto/opensslconf.h.in
@@ -1,5 +1,4 @@
1/* crypto/opensslconf.h */ 1/* crypto/opensslconf.h.in */
2/* WARNING: This file is autogenerated by Configure */
3 2
4/* Generate 80386 code? */ 3/* Generate 80386 code? */
5#undef I386_ONLY 4#undef I386_ONLY
@@ -25,11 +24,25 @@
25#define RC2_INT unsigned int 24#define RC2_INT unsigned int
26#endif 25#endif
27 26
28#if defined(HEADER_RC4_H) && !defined(RC4_INT) 27#if defined(HEADER_RC4_H)
28#if !defined(RC4_INT)
29/* using int types make the structure larger but make the code faster 29/* using int types make the structure larger but make the code faster
30 * on most boxes I have tested - up to %20 faster. */ 30 * on most boxes I have tested - up to %20 faster. */
31/*
32 * I don't know what does "most" mean, but declaring "int" is a must on:
33 * - Intel P6 because partial register stalls are very expensive;
34 * - elder Alpha because it lacks byte load/store instructions;
35 */
31#define RC4_INT unsigned int 36#define RC4_INT unsigned int
32#endif 37#endif
38#if !defined(RC4_CHUNK)
39/*
40 * This enables code handling data aligned at natural CPU word
41 * boundary. See crypto/rc4/rc4_enc.c for further details.
42 */
43#undef RC4_CHUNK
44#endif
45#endif
33 46
34#if defined(HEADER_DES_H) && !defined(DES_LONG) 47#if defined(HEADER_DES_H) && !defined(DES_LONG)
35/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a 48/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
diff --git a/src/lib/libcrypto/opensslv.h b/src/lib/libcrypto/opensslv.h
index b841347f05..55d5d06cf5 100644
--- a/src/lib/libcrypto/opensslv.h
+++ b/src/lib/libcrypto/opensslv.h
@@ -7,15 +7,15 @@
7 * 0.9.3-dev 0x00903000 7 * 0.9.3-dev 0x00903000
8 * 0.9.3beta1 0x00903001 8 * 0.9.3beta1 0x00903001
9 * 0.9.3beta2-dev 0x00903002 9 * 0.9.3beta2-dev 0x00903002
10 * 0.9.3beta2 0x00903002 10 * 0.9.3beta2 0x00903002 (same as ...beta2-dev)
11 * 0.9.3 0x00903100 11 * 0.9.3 0x00903100
12 * 0.9.3a 0x00903101 12 * 0.9.3a 0x00903101
13 * 0.9.4 0x00904100 13 * 0.9.4 0x00904100
14 * 1.2.3z 0x1020311a 14 * 1.2.3z 0x1020311a
15 * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) 15 * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.)
16 */ 16 */
17#define OPENSSL_VERSION_NUMBER 0x00904100L 17#define OPENSSL_VERSION_NUMBER 0x00905100L
18#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.4 09 Aug 1999" 18#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.5 28 Feb 2000"
19#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT 19#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
20 20
21#endif /* HEADER_OPENSSLV_H */ 21#endif /* HEADER_OPENSSLV_H */
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
index fc333e42c8..e4bae0b4aa 100644
--- a/src/lib/libcrypto/pem/pem.h
+++ b/src/lib/libcrypto/pem/pem.h
@@ -103,13 +103,16 @@ extern "C" {
103 103
104#define PEM_STRING_X509_OLD "X509 CERTIFICATE" 104#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
105#define PEM_STRING_X509 "CERTIFICATE" 105#define PEM_STRING_X509 "CERTIFICATE"
106#define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
106#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" 107#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
107#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" 108#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
108#define PEM_STRING_X509_CRL "X509 CRL" 109#define PEM_STRING_X509_CRL "X509 CRL"
109#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" 110#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
111#define PEM_STRING_PUBLIC "PUBLIC KEY"
110#define PEM_STRING_RSA "RSA PRIVATE KEY" 112#define PEM_STRING_RSA "RSA PRIVATE KEY"
111#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" 113#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
112#define PEM_STRING_DSA "DSA PRIVATE KEY" 114#define PEM_STRING_DSA "DSA PRIVATE KEY"
115#define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
113#define PEM_STRING_PKCS7 "PKCS7" 116#define PEM_STRING_PKCS7 "PKCS7"
114#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" 117#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
115#define PEM_STRING_PKCS8INF "PRIVATE KEY" 118#define PEM_STRING_PKCS8INF "PRIVATE KEY"
@@ -528,7 +531,10 @@ void PEM_dek_info(char *buf, const char *type, int len, char *str);
528 531
529DECLARE_PEM_rw(X509, X509) 532DECLARE_PEM_rw(X509, X509)
530 533
534DECLARE_PEM_rw(X509_AUX, X509)
535
531DECLARE_PEM_rw(X509_REQ, X509_REQ) 536DECLARE_PEM_rw(X509_REQ, X509_REQ)
537DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
532 538
533DECLARE_PEM_rw(X509_CRL, X509_CRL) 539DECLARE_PEM_rw(X509_CRL, X509_CRL)
534 540
@@ -545,6 +551,7 @@ DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
545DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) 551DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
546 552
547DECLARE_PEM_rw(RSAPublicKey, RSA) 553DECLARE_PEM_rw(RSAPublicKey, RSA)
554DECLARE_PEM_rw(RSA_PUBKEY, RSA)
548 555
549#endif 556#endif
550 557
@@ -552,6 +559,8 @@ DECLARE_PEM_rw(RSAPublicKey, RSA)
552 559
553DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) 560DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
554 561
562DECLARE_PEM_rw(DSA_PUBKEY, DSA)
563
555DECLARE_PEM_rw(DSAparams, DSA) 564DECLARE_PEM_rw(DSAparams, DSA)
556 565
557#endif 566#endif
@@ -564,10 +573,36 @@ DECLARE_PEM_rw(DHparams, DH)
564 573
565DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) 574DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
566 575
576DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
577
578int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
579 char *kstr, int klen,
580 pem_password_cb *cb, void *u);
567int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, 581int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
568 char *, int, pem_password_cb *, void *); 582 char *, int, pem_password_cb *, void *);
583int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
584 char *kstr, int klen,
585 pem_password_cb *cb, void *u);
586int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
587 char *kstr, int klen,
588 pem_password_cb *cb, void *u);
589EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
590
591int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
592 char *kstr, int klen,
593 pem_password_cb *cb, void *u);
594int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
595 char *kstr, int klen,
596 pem_password_cb *cb, void *u);
597int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
598 char *kstr, int klen,
599 pem_password_cb *cb, void *u);
600
601EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
602
569int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, 603int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
570 char *kstr,int klen, pem_password_cb *cd, void *u); 604 char *kstr,int klen, pem_password_cb *cd, void *u);
605
571#endif /* SSLEAY_MACROS */ 606#endif /* SSLEAY_MACROS */
572 607
573 608
@@ -579,6 +614,8 @@ int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
579/* Error codes for the PEM functions. */ 614/* Error codes for the PEM functions. */
580 615
581/* Function codes. */ 616/* Function codes. */
617#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
618#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
582#define PEM_F_DEF_CALLBACK 100 619#define PEM_F_DEF_CALLBACK 100
583#define PEM_F_LOAD_IV 101 620#define PEM_F_LOAD_IV 101
584#define PEM_F_PEM_ASN1_READ 102 621#define PEM_F_PEM_ASN1_READ 102
@@ -586,6 +623,7 @@ int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
586#define PEM_F_PEM_ASN1_WRITE 104 623#define PEM_F_PEM_ASN1_WRITE 104
587#define PEM_F_PEM_ASN1_WRITE_BIO 105 624#define PEM_F_PEM_ASN1_WRITE_BIO 105
588#define PEM_F_PEM_DO_HEADER 106 625#define PEM_F_PEM_DO_HEADER 106
626#define PEM_F_PEM_F_DO_PK8KEY_FP 122
589#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 627#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
590#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 628#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
591#define PEM_F_PEM_READ 108 629#define PEM_F_PEM_READ 108
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
index bc473f3cff..dc9c35b4b4 100644
--- a/src/lib/libcrypto/pem/pem_all.c
+++ b/src/lib/libcrypto/pem/pem_all.c
@@ -65,10 +65,21 @@
65#include <openssl/pkcs7.h> 65#include <openssl/pkcs7.h>
66#include <openssl/pem.h> 66#include <openssl/pem.h>
67 67
68#ifndef NO_RSA
69static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa);
70#endif
71#ifndef NO_DSA
72static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa);
73#endif
74
68IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509) 75IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
69 76
77IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)
78
70IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ) 79IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
71 80
81IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ)
82
72IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL) 83IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
73 84
74IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7) 85IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
@@ -82,15 +93,92 @@ IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
82 93
83#ifndef NO_RSA 94#ifndef NO_RSA
84 95
85IMPLEMENT_PEM_rw_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey) 96/* We treat RSA or DSA private keys as a special case.
97 *
98 * For private keys we read in an EVP_PKEY structure with
99 * PEM_read_bio_PrivateKey() and extract the relevant private
100 * key: this means can handle "traditional" and PKCS#8 formats
101 * transparently.
102 */
103
104static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa)
105{
106 RSA *rtmp;
107 if(!key) return NULL;
108 rtmp = EVP_PKEY_get1_RSA(key);
109 EVP_PKEY_free(key);
110 if(!rtmp) return NULL;
111 if(rsa) {
112 RSA_free(*rsa);
113 *rsa = rtmp;
114 }
115 return rtmp;
116}
117
118RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb,
119 void *u)
120{
121 EVP_PKEY *pktmp;
122 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
123 return pkey_get_rsa(pktmp, rsa);
124}
125
126#ifndef NO_FP_API
127
128RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
129 void *u)
130{
131 EVP_PKEY *pktmp;
132 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
133 return pkey_get_rsa(pktmp, rsa);
134}
135
136#endif
86 137
138IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
87IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey) 139IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
140IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
88 141
89#endif 142#endif
90 143
91#ifndef NO_DSA 144#ifndef NO_DSA
92 145
93IMPLEMENT_PEM_rw_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey) 146static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa)
147{
148 DSA *dtmp;
149 if(!key) return NULL;
150 dtmp = EVP_PKEY_get1_DSA(key);
151 EVP_PKEY_free(key);
152 if(!dtmp) return NULL;
153 if(dsa) {
154 DSA_free(*dsa);
155 *dsa = dtmp;
156 }
157 return dtmp;
158}
159
160DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
161 void *u)
162{
163 EVP_PKEY *pktmp;
164 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
165 return pkey_get_dsa(pktmp, dsa);
166}
167
168IMPLEMENT_PEM_write_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
169IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
170
171#ifndef NO_FP_API
172
173DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
174 void *u)
175{
176 EVP_PKEY *pktmp;
177 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
178 return pkey_get_dsa(pktmp, dsa);
179}
180
181#endif
94 182
95IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams) 183IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
96 184
@@ -111,3 +199,5 @@ IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
111 */ 199 */
112IMPLEMENT_PEM_read(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey) 200IMPLEMENT_PEM_read(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
113IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey) 201IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
202
203IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
index fa70f60998..642129da20 100644
--- a/src/lib/libcrypto/pem/pem_err.c
+++ b/src/lib/libcrypto/pem/pem_err.c
@@ -65,6 +65,8 @@
65#ifndef NO_ERR 65#ifndef NO_ERR
66static ERR_STRING_DATA PEM_str_functs[]= 66static ERR_STRING_DATA PEM_str_functs[]=
67 { 67 {
68{ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_BIO,0), "d2i_PKCS8PrivateKey_bio"},
69{ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_FP,0), "d2i_PKCS8PrivateKey_fp"},
68{ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"}, 70{ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"},
69{ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"}, 71{ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"},
70{ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"}, 72{ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"},
@@ -72,6 +74,7 @@ static ERR_STRING_DATA PEM_str_functs[]=
72{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"}, 74{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"},
73{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"}, 75{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"},
74{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"}, 76{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"},
77{ERR_PACK(0,PEM_F_PEM_F_DO_PK8KEY_FP,0), "PEM_F_DO_PK8KEY_FP"},
75{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"}, 78{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
76{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"}, 79{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"},
77{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"}, 80{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"},
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index fec18a4c2e..b65239a920 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -132,6 +132,17 @@ start:
132 } 132 }
133 pp=(char **)&(xi->x509); 133 pp=(char **)&(xi->x509);
134 } 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 }
135 else if (strcmp(name,PEM_STRING_X509_CRL) == 0) 146 else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
136 { 147 {
137 d2i=(char *(*)())d2i_X509_CRL; 148 d2i=(char *(*)())d2i_X509_CRL;
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 90f02011ba..072211ba0f 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -75,8 +75,17 @@ const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT;
75 75
76static int def_callback(char *buf, int num, int w, void *userdata); 76static int def_callback(char *buf, int num, int w, void *userdata);
77static int load_iv(unsigned char **fromp,unsigned char *to, int num); 77static int load_iv(unsigned char **fromp,unsigned char *to, int num);
78 78static int check_pem(const char *nm, const char *name);
79static int def_callback(char *buf, int num, int w, void *userdata) 79static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder,
80 int nid, const EVP_CIPHER *enc,
81 char *kstr, int klen,
82 pem_password_cb *cb, void *u);
83static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder,
84 int nid, const EVP_CIPHER *enc,
85 char *kstr, int klen,
86 pem_password_cb *cb, void *u);
87
88static int def_callback(char *buf, int num, int w, void *key)
80 { 89 {
81#ifdef NO_FP_API 90#ifdef NO_FP_API
82 /* We should not ever call the default callback routine from 91 /* We should not ever call the default callback routine from
@@ -86,6 +95,12 @@ static int def_callback(char *buf, int num, int w, void *userdata)
86#else 95#else
87 int i,j; 96 int i,j;
88 const char *prompt; 97 const char *prompt;
98 if(key) {
99 i=strlen(key);
100 i=(i > num)?num:i;
101 memcpy(buf,key,i);
102 return(i);
103 }
89 104
90 prompt=EVP_get_pw_prompt(); 105 prompt=EVP_get_pw_prompt();
91 if (prompt == NULL) 106 if (prompt == NULL)
@@ -168,6 +183,47 @@ char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
168 } 183 }
169#endif 184#endif
170 185
186static int check_pem(const char *nm, const char *name)
187{
188 /* Normal matching nm and name */
189 if (!strcmp(nm,name)) return 1;
190
191 /* Make PEM_STRING_EVP_PKEY match any private key */
192
193 if(!strcmp(nm,PEM_STRING_PKCS8) &&
194 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
195
196 if(!strcmp(nm,PEM_STRING_PKCS8INF) &&
197 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
198
199 if(!strcmp(nm,PEM_STRING_RSA) &&
200 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
201
202 if(!strcmp(nm,PEM_STRING_DSA) &&
203 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
204
205 /* Permit older strings */
206
207 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
208 !strcmp(name,PEM_STRING_X509)) return 1;
209
210 if(!strcmp(nm,PEM_STRING_X509_REQ_OLD) &&
211 !strcmp(name,PEM_STRING_X509_REQ)) return 1;
212
213 /* Allow normal certs to be read as trusted certs */
214 if(!strcmp(nm,PEM_STRING_X509) &&
215 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
216
217 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
218 !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1;
219
220 /* Some CAs use PKCS#7 with CERTIFICATE headers */
221 if(!strcmp(nm, PEM_STRING_X509) &&
222 !strcmp(name, PEM_STRING_PKCS7)) return 1;
223
224 return 0;
225}
226
171char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x, 227char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
172 pem_password_cb *cb, void *u) 228 pem_password_cb *cb, void *u)
173 { 229 {
@@ -179,22 +235,13 @@ char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
179 235
180 for (;;) 236 for (;;)
181 { 237 {
182 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) return(NULL); 238 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) {
183 if ( (strcmp(nm,name) == 0) || 239 if(ERR_GET_REASON(ERR_peek_error()) ==
184 ((strcmp(nm,PEM_STRING_RSA) == 0) && 240 PEM_R_NO_START_LINE)
185 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || 241 ERR_add_error_data(2, "Expecting: ", name);
186 ((strcmp(nm,PEM_STRING_DSA) == 0) && 242 return(NULL);
187 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || 243 }
188 ((strcmp(nm,PEM_STRING_PKCS8) == 0) && 244 if(check_pem(nm, name)) break;
189 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
190 ((strcmp(nm,PEM_STRING_PKCS8INF) == 0) &&
191 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
192 ((strcmp(nm,PEM_STRING_X509_OLD) == 0) &&
193 (strcmp(name,PEM_STRING_X509) == 0)) ||
194 ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) &&
195 (strcmp(name,PEM_STRING_X509_REQ) == 0))
196 )
197 break;
198 Free(nm); 245 Free(nm);
199 Free(header); 246 Free(header);
200 Free(data); 247 Free(data);
@@ -218,7 +265,7 @@ char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
218 X509_SIG *p8; 265 X509_SIG *p8;
219 int klen; 266 int klen;
220 char psbuf[PEM_BUFSIZE]; 267 char psbuf[PEM_BUFSIZE];
221 p8 = d2i_X509_SIG((X509_SIG **)x, &p, len); 268 p8 = d2i_X509_SIG(NULL, &p, len);
222 if(!p8) goto p8err; 269 if(!p8) goto p8err;
223 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u); 270 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
224 else klen=def_callback(psbuf,PEM_BUFSIZE,0,u); 271 else klen=def_callback(psbuf,PEM_BUFSIZE,0,u);
@@ -231,6 +278,10 @@ char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
231 X509_SIG_free(p8); 278 X509_SIG_free(p8);
232 if(!p8inf) goto p8err; 279 if(!p8inf) goto p8err;
233 ret = (char *)EVP_PKCS82PKEY(p8inf); 280 ret = (char *)EVP_PKCS82PKEY(p8inf);
281 if(x) {
282 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
283 *x = ret;
284 }
234 PKCS8_PRIV_KEY_INFO_free(p8inf); 285 PKCS8_PRIV_KEY_INFO_free(p8inf);
235 } 286 }
236 } else ret=d2i(x,&p,len); 287 } else ret=d2i(x,&p,len);
@@ -321,8 +372,9 @@ int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
321#endif 372#endif
322 kstr=(unsigned char *)buf; 373 kstr=(unsigned char *)buf;
323 } 374 }
324 RAND_seed(data,i);/* put in the RSA key. */ 375 RAND_add(data,i,0);/* put in the RSA key. */
325 RAND_bytes(iv,8); /* Generate a salt */ 376 if (RAND_bytes(iv,8) <= 0) /* Generate a salt */
377 goto err;
326 /* The 'iv' is used as the iv and as a salt. It is 378 /* The 'iv' is used as the iv and as a salt. It is
327 * NOT taken from the BytesToKey function */ 379 * NOT taken from the BytesToKey function */
328 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); 380 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
@@ -743,16 +795,44 @@ err:
743 return(0); 795 return(0);
744 } 796 }
745 797
746/* This function writes a private key in PKCS#8 format: it is a "drop in" 798/* These functions write a private key in PKCS#8 format: it is a "drop in"
747 * replacement for PEM_write_bio_PrivateKey(). As usual if 'enc' is NULL then 799 * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
748 * it uses the unencrypted private key form. It uses PKCS#5 v2.0 password based 800 * is NULL then it uses the unencrypted private key form. The 'nid' versions
749 * encryption algorithms. 801 * uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
750 */ 802 */
751 803
804int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
805 char *kstr, int klen,
806 pem_password_cb *cb, void *u)
807{
808 return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
809}
810
752int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, 811int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
753 char *kstr, int klen, 812 char *kstr, int klen,
754 pem_password_cb *cb, void *u) 813 pem_password_cb *cb, void *u)
755{ 814{
815 return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
816}
817
818int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
819 char *kstr, int klen,
820 pem_password_cb *cb, void *u)
821{
822 return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
823}
824
825int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
826 char *kstr, int klen,
827 pem_password_cb *cb, void *u)
828{
829 return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
830}
831
832static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
833 char *kstr, int klen,
834 pem_password_cb *cb, void *u)
835{
756 X509_SIG *p8; 836 X509_SIG *p8;
757 PKCS8_PRIV_KEY_INFO *p8inf; 837 PKCS8_PRIV_KEY_INFO *p8inf;
758 char buf[PEM_BUFSIZE]; 838 char buf[PEM_BUFSIZE];
@@ -762,7 +842,7 @@ int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
762 PEM_R_ERROR_CONVERTING_PRIVATE_KEY); 842 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
763 return 0; 843 return 0;
764 } 844 }
765 if(enc) { 845 if(enc || (nid != -1)) {
766 if(!kstr) { 846 if(!kstr) {
767 if(!cb) klen = def_callback(buf, PEM_BUFSIZE, 1, u); 847 if(!cb) klen = def_callback(buf, PEM_BUFSIZE, 1, u);
768 else klen = cb(buf, PEM_BUFSIZE, 1, u); 848 else klen = cb(buf, PEM_BUFSIZE, 1, u);
@@ -775,29 +855,109 @@ int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
775 855
776 kstr = buf; 856 kstr = buf;
777 } 857 }
778 p8 = PKCS8_encrypt(-1, enc, kstr, klen, NULL, 0, 0, p8inf); 858 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
779 if(kstr == buf) memset(buf, 0, klen); 859 if(kstr == buf) memset(buf, 0, klen);
780 PKCS8_PRIV_KEY_INFO_free(p8inf); 860 PKCS8_PRIV_KEY_INFO_free(p8inf);
781 ret = PEM_write_bio_PKCS8(bp, p8); 861 if(isder) ret = i2d_PKCS8_bio(bp, p8);
862 else ret = PEM_write_bio_PKCS8(bp, p8);
782 X509_SIG_free(p8); 863 X509_SIG_free(p8);
783 return ret; 864 return ret;
784 } else { 865 } else {
785 ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf); 866 if(isder) ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
867 else ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
786 PKCS8_PRIV_KEY_INFO_free(p8inf); 868 PKCS8_PRIV_KEY_INFO_free(p8inf);
787 return ret; 869 return ret;
788 } 870 }
789} 871}
790 872
873/* Finally the DER version to read PKCS#8 encrypted private keys. It has to be
874 * here to access the default callback.
875 */
876
877EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
878{
879 PKCS8_PRIV_KEY_INFO *p8inf = NULL;
880 X509_SIG *p8 = NULL;
881 int klen;
882 EVP_PKEY *ret;
883 char psbuf[PEM_BUFSIZE];
884 p8 = d2i_PKCS8_bio(bp, NULL);
885 if(!p8) return NULL;
886 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
887 else klen=def_callback(psbuf,PEM_BUFSIZE,0,u);
888 if (klen <= 0) {
889 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
890 X509_SIG_free(p8);
891 return NULL;
892 }
893 p8inf = M_PKCS8_decrypt(p8, psbuf, klen);
894 X509_SIG_free(p8);
895 if(!p8inf) return NULL;
896 ret = EVP_PKCS82PKEY(p8inf);
897 PKCS8_PRIV_KEY_INFO_free(p8inf);
898 if(!ret) return NULL;
899 if(x) {
900 if(*x) EVP_PKEY_free(*x);
901 *x = ret;
902 }
903 return ret;
904}
905
906#ifndef NO_FP_API
907
908int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
909 char *kstr, int klen,
910 pem_password_cb *cb, void *u)
911{
912 return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
913}
914
915int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
916 char *kstr, int klen,
917 pem_password_cb *cb, void *u)
918{
919 return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
920}
921
922int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
923 char *kstr, int klen,
924 pem_password_cb *cb, void *u)
925{
926 return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
927}
928
791int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, 929int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
792 char *kstr, int klen, pem_password_cb *cb, void *u) 930 char *kstr, int klen, pem_password_cb *cb, void *u)
793{ 931{
932 return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
933}
934
935static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
936 char *kstr, int klen,
937 pem_password_cb *cb, void *u)
938{
794 BIO *bp; 939 BIO *bp;
795 int ret; 940 int ret;
796 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { 941 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
797 PEMerr(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,ERR_R_BUF_LIB); 942 PEMerr(PEM_F_PEM_F_DO_PK8KEY_FP,ERR_R_BUF_LIB);
798 return(0); 943 return(0);
799 } 944 }
800 ret = PEM_write_bio_PKCS8PrivateKey(bp, x, enc, kstr, klen, cb, u); 945 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
801 BIO_free(bp); 946 BIO_free(bp);
802 return ret; 947 return ret;
803} 948}
949
950EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
951{
952 BIO *bp;
953 EVP_PKEY *ret;
954 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
955 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP,ERR_R_BUF_LIB);
956 return NULL;
957 }
958 ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
959 BIO_free(bp);
960 return ret;
961}
962
963#endif
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index 23f95beb1e..126e29d375 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -175,4 +175,10 @@ err:
175 if (s != NULL) Free(s); 175 if (s != NULL) Free(s);
176 return(ret); 176 return(ret);
177 } 177 }
178#else /* !NO_RSA */
179
180# if PEDANTIC
181static void *dummy=&dummy;
182# endif
183
178#endif 184#endif
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl
index 51dcce067f..252a57bdb5 100644
--- a/src/lib/libcrypto/perlasm/x86ms.pl
+++ b/src/lib/libcrypto/perlasm/x86ms.pl
@@ -341,7 +341,14 @@ sub main'set_label
341 $label{$_[0]}="${label}${_[0]}"; 341 $label{$_[0]}="${label}${_[0]}";
342 $label++; 342 $label++;
343 } 343 }
344 push(@out,"$label{$_[0]}:\n"); 344 if((defined $_[1]) && ($_[1] == 1))
345 {
346 push(@out,"$label{$_[0]}::\n");
347 }
348 else
349 {
350 push(@out,"$label{$_[0]}:\n");
351 }
345 } 352 }
346 353
347sub main'data_word 354sub main'data_word
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl
index 8c456b14af..60d75f5ce4 100644
--- a/src/lib/libcrypto/perlasm/x86unix.pl
+++ b/src/lib/libcrypto/perlasm/x86unix.pl
@@ -368,10 +368,10 @@ sub main'function_end_B
368 368
369 $func=$under.$func; 369 $func=$under.$func;
370 370
371 push(@out,".${func}_end:\n"); 371 push(@out,".L_${func}_end:\n");
372 if ($main'cpp) 372 if ($main'cpp)
373 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } 373 { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); }
374 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); } 374 else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); }
375 push(@out,".ident \"desasm.pl\"\n"); 375 push(@out,".ident \"desasm.pl\"\n");
376 $stack=0; 376 $stack=0;
377 %label=(); 377 %label=();
diff --git a/src/lib/libcrypto/pkcs12/Makefile.ssl b/src/lib/libcrypto/pkcs12/Makefile.ssl
index 7b0c65fad9..5716f608b6 100644
--- a/src/lib/libcrypto/pkcs12/Makefile.ssl
+++ b/src/lib/libcrypto/pkcs12/Makefile.ssl
@@ -1,5 +1,5 @@
1# 1#
2# SSLeay/crypto/asn1/Makefile 2# SSLeay/crypto/pkcs12/Makefile
3# 3#
4 4
5DIR= pkcs12 5DIR= pkcs12
@@ -24,10 +24,10 @@ APPS=
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= p12_add.c p12_attr.c p12_bags.c p12_crpt.c p12_crt.c p12_decr.c \ 25LIBSRC= p12_add.c p12_attr.c p12_bags.c p12_crpt.c p12_crt.c p12_decr.c \
26 p12_init.c p12_key.c p12_kiss.c p12_lib.c p12_mac.c p12_mutl.c\ 26 p12_init.c p12_key.c p12_kiss.c p12_lib.c p12_mac.c p12_mutl.c\
27 p12_sbag.c p12_utl.c pk12err.c 27 p12_sbag.c p12_utl.c p12_npas.c pk12err.c
28LIBOBJ= p12_add.o p12_attr.o p12_bags.o p12_crpt.o p12_crt.o p12_decr.o \ 28LIBOBJ= p12_add.o p12_attr.o p12_bags.o p12_crpt.o p12_crt.o p12_decr.o \
29 p12_init.o p12_key.o p12_kiss.o p12_lib.o p12_mac.o p12_mutl.o\ 29 p12_init.o p12_key.o p12_kiss.o p12_lib.o p12_mac.o p12_mutl.o\
30 p12_sbag.o p12_utl.o pk12err.o 30 p12_sbag.o p12_utl.o p12_npas.o pk12err.o
31 31
32SRC= $(LIBSRC) 32SRC= $(LIBSRC)
33 33
@@ -293,6 +293,23 @@ p12_mutl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
293p12_mutl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 293p12_mutl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
294p12_mutl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 294p12_mutl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
295p12_mutl.o: ../cryptlib.h 295p12_mutl.o: ../cryptlib.h
296p12_npas.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
297p12_npas.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
298p12_npas.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
299p12_npas.o: ../../include/openssl/des.h ../../include/openssl/dh.h
300p12_npas.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
301p12_npas.o: ../../include/openssl/err.h ../../include/openssl/evp.h
302p12_npas.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
303p12_npas.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
304p12_npas.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
305p12_npas.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
306p12_npas.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
307p12_npas.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
308p12_npas.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
309p12_npas.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
310p12_npas.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
311p12_npas.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
312p12_npas.o: ../../include/openssl/x509_vfy.h
296p12_sbag.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h 313p12_sbag.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
297p12_sbag.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h 314p12_sbag.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
298p12_sbag.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 315p12_sbag.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c
index ae3d9de3b4..d045cbba8d 100644
--- a/src/lib/libcrypto/pkcs12/p12_add.c
+++ b/src/lib/libcrypto/pkcs12/p12_add.c
@@ -133,7 +133,7 @@ PKCS7 *PKCS12_pack_p7data (STACK *sk)
133 return NULL; 133 return NULL;
134 } 134 }
135 p7->type = OBJ_nid2obj(NID_pkcs7_data); 135 p7->type = OBJ_nid2obj(NID_pkcs7_data);
136 if (!(p7->d.data = ASN1_OCTET_STRING_new())) { 136 if (!(p7->d.data = M_ASN1_OCTET_STRING_new())) {
137 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); 137 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
138 return NULL; 138 return NULL;
139 } 139 }
@@ -157,20 +157,18 @@ PKCS7 *PKCS12_pack_p7encdata (int pbe_nid, const char *pass, int passlen,
157 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); 157 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
158 return NULL; 158 return NULL;
159 } 159 }
160 p7->type = OBJ_nid2obj(NID_pkcs7_encrypted); 160 if(!PKCS7_set_type(p7, NID_pkcs7_encrypted)) {
161 if (!(p7->d.encrypted = PKCS7_ENCRYPT_new ())) { 161 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA,
162 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); 162 PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE);
163 return NULL; 163 return NULL;
164 } 164 }
165 ASN1_INTEGER_set (p7->d.encrypted->version, 0);
166 p7->d.encrypted->enc_data->content_type = OBJ_nid2obj(NID_pkcs7_data);
167 if (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) { 165 if (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) {
168 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); 166 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
169 return NULL; 167 return NULL;
170 } 168 }
171 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm); 169 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm);
172 p7->d.encrypted->enc_data->algorithm = pbe; 170 p7->d.encrypted->enc_data->algorithm = pbe;
173 ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data); 171 M_ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data);
174 if (!(p7->d.encrypted->enc_data->enc_data = 172 if (!(p7->d.encrypted->enc_data->enc_data =
175 PKCS12_i2d_encrypt (pbe, i2d_PKCS12_SAFEBAG, pass, passlen, 173 PKCS12_i2d_encrypt (pbe, i2d_PKCS12_SAFEBAG, pass, passlen,
176 (char *)bags, 1))) { 174 (char *)bags, 1))) {
@@ -191,24 +189,28 @@ X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
191 189
192 if (!(p8 = X509_SIG_new())) { 190 if (!(p8 = X509_SIG_new())) {
193 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); 191 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
194 return NULL; 192 goto err;
195 } 193 }
196 194
197 if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen); 195 if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
198 else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); 196 else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
199 if(!pbe) { 197 if(!pbe) {
200 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); 198 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB);
201 return NULL; 199 goto err;
202 } 200 }
203 X509_ALGOR_free(p8->algor); 201 X509_ALGOR_free(p8->algor);
204 p8->algor = pbe; 202 p8->algor = pbe;
205 ASN1_OCTET_STRING_free(p8->digest); 203 M_ASN1_OCTET_STRING_free(p8->digest);
206 if (!(p8->digest = 204 if (!(p8->digest =
207 PKCS12_i2d_encrypt (pbe, i2d_PKCS8_PRIV_KEY_INFO, pass, passlen, 205 PKCS12_i2d_encrypt (pbe, i2d_PKCS8_PRIV_KEY_INFO, pass, passlen,
208 (char *)p8inf, 0))) { 206 (char *)p8inf, 0))) {
209 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR); 207 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR);
210 return NULL; 208 goto err;
211 } 209 }
212 210
213 return p8; 211 return p8;
212
213 err:
214 X509_SIG_free(p8);
215 return NULL;
214} 216}
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c
index 31c9782b77..f559351d18 100644
--- a/src/lib/libcrypto/pkcs12/p12_attr.c
+++ b/src/lib/libcrypto/pkcs12/p12_attr.c
@@ -73,11 +73,11 @@ int PKCS12_add_localkeyid (PKCS12_SAFEBAG *bag, unsigned char *name,
73 return 0; 73 return 0;
74 } 74 }
75 keyid->type = V_ASN1_OCTET_STRING; 75 keyid->type = V_ASN1_OCTET_STRING;
76 if (!(oct = ASN1_OCTET_STRING_new())) { 76 if (!(oct = M_ASN1_OCTET_STRING_new())) {
77 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE); 77 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
78 return 0; 78 return 0;
79 } 79 }
80 if (!ASN1_OCTET_STRING_set(oct, name, namelen)) { 80 if (!M_ASN1_OCTET_STRING_set(oct, name, namelen)) {
81 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE); 81 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
82 return 0; 82 return 0;
83 } 83 }
@@ -115,11 +115,11 @@ int PKCS8_add_keyusage (PKCS8_PRIV_KEY_INFO *p8, int usage)
115 return 0; 115 return 0;
116 } 116 }
117 keyid->type = V_ASN1_BIT_STRING; 117 keyid->type = V_ASN1_BIT_STRING;
118 if (!(bstr = ASN1_BIT_STRING_new())) { 118 if (!(bstr = M_ASN1_BIT_STRING_new())) {
119 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE); 119 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
120 return 0; 120 return 0;
121 } 121 }
122 if (!ASN1_BIT_STRING_set(bstr, &us_val, 1)) { 122 if (!M_ASN1_BIT_STRING_set(bstr, &us_val, 1)) {
123 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE); 123 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
124 return 0; 124 return 0;
125 } 125 }
@@ -176,7 +176,7 @@ int PKCS12_add_friendlyname_uni (PKCS12_SAFEBAG *bag,
176 return 0; 176 return 0;
177 } 177 }
178 fname->type = V_ASN1_BMPSTRING; 178 fname->type = V_ASN1_BMPSTRING;
179 if (!(bmp = ASN1_BMPSTRING_new())) { 179 if (!(bmp = M_ASN1_BMPSTRING_new())) {
180 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI, 180 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
181 ERR_R_MALLOC_FAILURE); 181 ERR_R_MALLOC_FAILURE);
182 return 0; 182 return 0;
diff --git a/src/lib/libcrypto/pkcs12/p12_bags.c b/src/lib/libcrypto/pkcs12/p12_bags.c
index d6eab92c83..c358b06735 100644
--- a/src/lib/libcrypto/pkcs12/p12_bags.c
+++ b/src/lib/libcrypto/pkcs12/p12_bags.c
@@ -171,15 +171,15 @@ void PKCS12_BAGS_free (PKCS12_BAGS *a)
171 switch (OBJ_obj2nid(a->type)) { 171 switch (OBJ_obj2nid(a->type)) {
172 172
173 case NID_x509Certificate: 173 case NID_x509Certificate:
174 ASN1_OCTET_STRING_free (a->value.x509cert); 174 M_ASN1_OCTET_STRING_free (a->value.x509cert);
175 break; 175 break;
176 176
177 case NID_x509Crl: 177 case NID_x509Crl:
178 ASN1_OCTET_STRING_free (a->value.x509crl); 178 M_ASN1_OCTET_STRING_free (a->value.x509crl);
179 break; 179 break;
180 180
181 case NID_sdsiCertificate: 181 case NID_sdsiCertificate:
182 ASN1_IA5STRING_free (a->value.sdsicert); 182 M_ASN1_IA5STRING_free (a->value.sdsicert);
183 break; 183 break;
184 184
185 default: 185 default:
@@ -188,5 +188,5 @@ void PKCS12_BAGS_free (PKCS12_BAGS *a)
188 } 188 }
189 189
190 ASN1_OBJECT_free (a->type); 190 ASN1_OBJECT_free (a->type);
191 Free ((char *)a); 191 Free (a);
192} 192}
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c
index 6de6f8128f..7b96584f07 100644
--- a/src/lib/libcrypto/pkcs12/p12_crpt.c
+++ b/src/lib/libcrypto/pkcs12/p12_crpt.c
@@ -70,10 +70,12 @@ EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC4, EVP_rc4(), EVP_sha1(),
70EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC4, EVP_rc4_40(), EVP_sha1(), 70EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC4, EVP_rc4_40(), EVP_sha1(),
71 PKCS12_PBE_keyivgen); 71 PKCS12_PBE_keyivgen);
72#endif 72#endif
73#ifndef NO_DES
73EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC, 74EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
74 EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen); 75 EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
75EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC, 76EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
76 EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen); 77 EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
78#endif
77#ifndef NO_RC2 79#ifndef NO_RC2
78EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(), 80EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(),
79 EVP_sha1(), PKCS12_PBE_keyivgen); 81 EVP_sha1(), PKCS12_PBE_keyivgen);
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c
index d3d288e187..4be44eac50 100644
--- a/src/lib/libcrypto/pkcs12/p12_decr.c
+++ b/src/lib/libcrypto/pkcs12/p12_decr.c
@@ -155,7 +155,7 @@ ASN1_OCTET_STRING *PKCS12_i2d_encrypt (X509_ALGOR *algor, int (*i2d)(),
155 ASN1_OCTET_STRING *oct; 155 ASN1_OCTET_STRING *oct;
156 unsigned char *in, *p; 156 unsigned char *in, *p;
157 int inlen; 157 int inlen;
158 if (!(oct = ASN1_OCTET_STRING_new ())) { 158 if (!(oct = M_ASN1_OCTET_STRING_new ())) {
159 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE); 159 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE);
160 return NULL; 160 return NULL;
161 } 161 }
diff --git a/src/lib/libcrypto/pkcs12/p12_init.c b/src/lib/libcrypto/pkcs12/p12_init.c
index dc6ab41db8..d5d4884c82 100644
--- a/src/lib/libcrypto/pkcs12/p12_init.c
+++ b/src/lib/libcrypto/pkcs12/p12_init.c
@@ -69,11 +69,11 @@ PKCS12 *PKCS12_init (int mode)
69 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE); 69 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
70 return NULL; 70 return NULL;
71 } 71 }
72 if (!(pkcs12->version = ASN1_INTEGER_new ())) { 72 if (!(pkcs12->version = M_ASN1_INTEGER_new ())) {
73 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE); 73 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
74 return NULL; 74 return NULL;
75 } 75 }
76 ASN1_INTEGER_set (pkcs12->version, 3); 76 ASN1_INTEGER_set(pkcs12->version, 3);
77 if (!(pkcs12->authsafes = PKCS7_new())) { 77 if (!(pkcs12->authsafes = PKCS7_new())) {
78 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE); 78 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
79 return NULL; 79 return NULL;
@@ -82,7 +82,7 @@ PKCS12 *PKCS12_init (int mode)
82 switch (mode) { 82 switch (mode) {
83 case NID_pkcs7_data: 83 case NID_pkcs7_data:
84 if (!(pkcs12->authsafes->d.data = 84 if (!(pkcs12->authsafes->d.data =
85 ASN1_OCTET_STRING_new())) { 85 M_ASN1_OCTET_STRING_new())) {
86 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE); 86 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
87 return NULL; 87 return NULL;
88 } 88 }
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
index 25d8cdae57..02fdd20e2f 100644
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ b/src/lib/libcrypto/pkcs12/p12_key.c
@@ -64,7 +64,7 @@
64/* Uncomment out this line to get debugging info about key generation */ 64/* Uncomment out this line to get debugging info about key generation */
65/*#define DEBUG_KEYGEN*/ 65/*#define DEBUG_KEYGEN*/
66#ifdef DEBUG_KEYGEN 66#ifdef DEBUG_KEYGEN
67#include <bio.h> 67#include <openssl/bio.h>
68extern BIO *bio_err; 68extern BIO *bio_err;
69void h__dump (unsigned char *p, int len); 69void h__dump (unsigned char *p, int len);
70#endif 70#endif
@@ -104,13 +104,12 @@ int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt,
104#ifdef DEBUG_KEYGEN 104#ifdef DEBUG_KEYGEN
105 unsigned char *tmpout = out; 105 unsigned char *tmpout = out;
106 int tmpn = n; 106 int tmpn = n;
107 BIO_printf (bio_err, "KEYGEN DEBUG\n"); 107 fprintf(stderr, "KEYGEN DEBUG\n");
108 BIO_printf (bio_err, "ID %d, ITER %d\n", id, iter); 108 fprintf(stderr, "ID %d, ITER %d\n", id, iter);
109 BIO_printf (bio_err, "Password (length %d):\n", passlen); 109 fprintf(stderr, "Password (length %d):\n", passlen);
110 h__dump (pass, passlen); 110 h__dump(pass, passlen);
111 BIO_printf (bio_err, "Salt (length %d):\n", saltlen); 111 fprintf(stderr, "Salt (length %d):\n", saltlen);
112 h__dump (salt, saltlen); 112 h__dump(salt, saltlen);
113 BIO_printf (bio_err, "ID %d, ITER %d\n\n", id, iter);
114#endif 113#endif
115 v = EVP_MD_block_size (md_type); 114 v = EVP_MD_block_size (md_type);
116 u = EVP_MD_size (md_type); 115 u = EVP_MD_size (md_type);
@@ -150,8 +149,8 @@ int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt,
150 BN_free (Ij); 149 BN_free (Ij);
151 BN_free (Bpl1); 150 BN_free (Bpl1);
152#ifdef DEBUG_KEYGEN 151#ifdef DEBUG_KEYGEN
153 BIO_printf (bio_err, "Output KEY (length %d)\n", tmpn); 152 fprintf(stderr, "Output KEY (length %d)\n", tmpn);
154 h__dump (tmpout, tmpn); 153 h__dump(tmpout, tmpn);
155#endif 154#endif
156 return 1; 155 return 1;
157 } 156 }
@@ -176,7 +175,7 @@ int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt,
176#ifdef DEBUG_KEYGEN 175#ifdef DEBUG_KEYGEN
177void h__dump (unsigned char *p, int len) 176void h__dump (unsigned char *p, int len)
178{ 177{
179 for (; len --; p++) BIO_printf (bio_err, "%02X", *p); 178 for (; len --; p++) fprintf(stderr, "%02X", *p);
180 BIO_printf (bio_err, "\n"); 179 fprintf(stderr, "\n");
181} 180}
182#endif 181#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c
index 767e1303da..08a60556e0 100644
--- a/src/lib/libcrypto/pkcs12/p12_kiss.c
+++ b/src/lib/libcrypto/pkcs12/p12_kiss.c
@@ -139,16 +139,16 @@ static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen,
139 sk_pop_free (asafes, PKCS7_free); 139 sk_pop_free (asafes, PKCS7_free);
140 return 0; 140 return 0;
141 } 141 }
142 if (!parse_bags (bags, pass, passlen, pkey, cert, ca, 142 if (!parse_bags(bags, pass, passlen, pkey, cert, ca,
143 &keyid, &keymatch)) { 143 &keyid, &keymatch)) {
144 sk_pop_free (bags, PKCS12_SAFEBAG_free); 144 sk_pop_free(bags, PKCS12_SAFEBAG_free);
145 sk_pop_free (asafes, PKCS7_free); 145 sk_pop_free(asafes, PKCS7_free);
146 return 0; 146 return 0;
147 } 147 }
148 sk_pop_free (bags, PKCS12_SAFEBAG_free); 148 sk_pop_free(bags, PKCS12_SAFEBAG_free);
149 } 149 }
150 sk_pop_free (asafes, PKCS7_free); 150 sk_pop_free(asafes, PKCS7_free);
151 if (keyid) ASN1_OCTET_STRING_free (keyid); 151 if (keyid) M_ASN1_OCTET_STRING_free(keyid);
152 return 1; 152 return 1;
153} 153}
154 154
@@ -158,8 +158,8 @@ static int parse_bags (STACK *bags, const char *pass, int passlen,
158 ASN1_OCTET_STRING **keyid, char *keymatch) 158 ASN1_OCTET_STRING **keyid, char *keymatch)
159{ 159{
160 int i; 160 int i;
161 for (i = 0; i < sk_num (bags); i++) { 161 for (i = 0; i < sk_num(bags); i++) {
162 if (!parse_bag ((PKCS12_SAFEBAG *)sk_value (bags, i), 162 if (!parse_bag((PKCS12_SAFEBAG *)sk_value (bags, i),
163 pass, passlen, pkey, cert, ca, keyid, 163 pass, passlen, pkey, cert, ca, keyid,
164 keymatch)) return 0; 164 keymatch)) return 0;
165 } 165 }
@@ -170,7 +170,7 @@ static int parse_bags (STACK *bags, const char *pass, int passlen,
170#define MATCH_CERT 0x2 170#define MATCH_CERT 0x2
171#define MATCH_ALL 0x3 171#define MATCH_ALL 0x3
172 172
173static int parse_bag (PKCS12_SAFEBAG *bag, const char *pass, int passlen, 173static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
174 EVP_PKEY **pkey, X509 **cert, STACK **ca, 174 EVP_PKEY **pkey, X509 **cert, STACK **ca,
175 ASN1_OCTET_STRING **keyid, 175 ASN1_OCTET_STRING **keyid,
176 char *keymatch) 176 char *keymatch)
@@ -187,9 +187,9 @@ static int parse_bag (PKCS12_SAFEBAG *bag, const char *pass, int passlen,
187 /* Check for any local key id matching (if needed) */ 187 /* Check for any local key id matching (if needed) */
188 if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) { 188 if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) {
189 if (*keyid) { 189 if (*keyid) {
190 if (ASN1_OCTET_STRING_cmp (*keyid, lkey)) lkey = NULL; 190 if (M_ASN1_OCTET_STRING_cmp(*keyid, lkey)) lkey = NULL;
191 } else { 191 } else {
192 if (!(*keyid = ASN1_OCTET_STRING_dup (lkey))) { 192 if (!(*keyid = M_ASN1_OCTET_STRING_dup(lkey))) {
193 PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE); 193 PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE);
194 return 0; 194 return 0;
195 } 195 }
@@ -200,16 +200,16 @@ static int parse_bag (PKCS12_SAFEBAG *bag, const char *pass, int passlen,
200 { 200 {
201 case NID_keyBag: 201 case NID_keyBag:
202 if (!lkey || !pkey) return 1; 202 if (!lkey || !pkey) return 1;
203 if (!(*pkey = EVP_PKCS82PKEY (bag->value.keybag))) return 0; 203 if (!(*pkey = EVP_PKCS82PKEY(bag->value.keybag))) return 0;
204 *keymatch |= MATCH_KEY; 204 *keymatch |= MATCH_KEY;
205 break; 205 break;
206 206
207 case NID_pkcs8ShroudedKeyBag: 207 case NID_pkcs8ShroudedKeyBag:
208 if (!lkey || !pkey) return 1; 208 if (!lkey || !pkey) return 1;
209 if (!(p8 = M_PKCS12_decrypt_skey (bag, pass, passlen))) 209 if (!(p8 = M_PKCS12_decrypt_skey(bag, pass, passlen)))
210 return 0; 210 return 0;
211 *pkey = EVP_PKCS82PKEY (p8); 211 *pkey = EVP_PKCS82PKEY(p8);
212 PKCS8_PRIV_KEY_INFO_free (p8); 212 PKCS8_PRIV_KEY_INFO_free(p8);
213 if (!(*pkey)) return 0; 213 if (!(*pkey)) return 0;
214 *keymatch |= MATCH_KEY; 214 *keymatch |= MATCH_KEY;
215 break; 215 break;
diff --git a/src/lib/libcrypto/pkcs12/p12_lib.c b/src/lib/libcrypto/pkcs12/p12_lib.c
index 00a6695d9b..7ca9c14908 100644
--- a/src/lib/libcrypto/pkcs12/p12_lib.c
+++ b/src/lib/libcrypto/pkcs12/p12_lib.c
@@ -104,8 +104,8 @@ PKCS12 *PKCS12_new(void)
104void PKCS12_free (PKCS12 *a) 104void PKCS12_free (PKCS12 *a)
105{ 105{
106 if (a == NULL) return; 106 if (a == NULL) return;
107 ASN1_INTEGER_free (a->version); 107 M_ASN1_INTEGER_free(a->version);
108 PKCS12_MAC_DATA_free (a->mac); 108 PKCS12_MAC_DATA_free (a->mac);
109 PKCS7_free (a->authsafes); 109 PKCS7_free (a->authsafes);
110 Free ((char *)a); 110 Free (a);
111} 111}
diff --git a/src/lib/libcrypto/pkcs12/p12_mac.c b/src/lib/libcrypto/pkcs12/p12_mac.c
index f163d4cfaa..f5ab0d6464 100644
--- a/src/lib/libcrypto/pkcs12/p12_mac.c
+++ b/src/lib/libcrypto/pkcs12/p12_mac.c
@@ -82,9 +82,9 @@ PKCS12_MAC_DATA *PKCS12_MAC_DATA_new(void)
82 ASN1_CTX c; 82 ASN1_CTX c;
83 M_ASN1_New_Malloc(ret, PKCS12_MAC_DATA); 83 M_ASN1_New_Malloc(ret, PKCS12_MAC_DATA);
84 ret->dinfo = X509_SIG_new(); 84 ret->dinfo = X509_SIG_new();
85 ret->salt = ASN1_OCTET_STRING_new(); 85 ret->salt = M_ASN1_OCTET_STRING_new();
86 ret->iter = NULL; 86 ret->iter = NULL;
87 return (ret); 87 return(ret);
88 M_ASN1_New_Error(ASN1_F_PKCS12_MAC_DATA_NEW); 88 M_ASN1_New_Error(ASN1_F_PKCS12_MAC_DATA_NEW);
89} 89}
90 90
@@ -94,9 +94,9 @@ PKCS12_MAC_DATA *d2i_PKCS12_MAC_DATA(PKCS12_MAC_DATA **a, unsigned char **pp,
94 M_ASN1_D2I_vars(a,PKCS12_MAC_DATA *,PKCS12_MAC_DATA_new); 94 M_ASN1_D2I_vars(a,PKCS12_MAC_DATA *,PKCS12_MAC_DATA_new);
95 M_ASN1_D2I_Init(); 95 M_ASN1_D2I_Init();
96 M_ASN1_D2I_start_sequence(); 96 M_ASN1_D2I_start_sequence();
97 M_ASN1_D2I_get (ret->dinfo, d2i_X509_SIG); 97 M_ASN1_D2I_get(ret->dinfo, d2i_X509_SIG);
98 M_ASN1_D2I_get (ret->salt, d2i_ASN1_OCTET_STRING); 98 M_ASN1_D2I_get(ret->salt, d2i_ASN1_OCTET_STRING);
99 M_ASN1_D2I_get_opt (ret->iter, d2i_ASN1_INTEGER, V_ASN1_INTEGER); 99 M_ASN1_D2I_get_opt(ret->iter, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
100 M_ASN1_D2I_Finish(a, PKCS12_MAC_DATA_free, ASN1_F_D2I_PKCS12_MAC_DATA); 100 M_ASN1_D2I_Finish(a, PKCS12_MAC_DATA_free, ASN1_F_D2I_PKCS12_MAC_DATA);
101} 101}
102 102
@@ -104,7 +104,7 @@ void PKCS12_MAC_DATA_free (PKCS12_MAC_DATA *a)
104{ 104{
105 if (a == NULL) return; 105 if (a == NULL) return;
106 X509_SIG_free (a->dinfo); 106 X509_SIG_free (a->dinfo);
107 ASN1_OCTET_STRING_free (a->salt); 107 M_ASN1_OCTET_STRING_free(a->salt);
108 ASN1_INTEGER_free (a->iter); 108 M_ASN1_INTEGER_free(a->iter);
109 Free ((char *)a); 109 Free (a);
110} 110}
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
index bac558d6b9..f1094b3840 100644
--- a/src/lib/libcrypto/pkcs12/p12_mutl.c
+++ b/src/lib/libcrypto/pkcs12/p12_mutl.c
@@ -131,7 +131,7 @@ int PKCS12_set_mac (PKCS12 *p12, const char *pass, int passlen,
131 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR); 131 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR);
132 return 0; 132 return 0;
133 } 133 }
134 if (!(ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) { 134 if (!(M_ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) {
135 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR); 135 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR);
136 return 0; 136 return 0;
137 } 137 }
@@ -142,13 +142,13 @@ int PKCS12_set_mac (PKCS12 *p12, const char *pass, int passlen,
142int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen, 142int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
143 EVP_MD *md_type) 143 EVP_MD *md_type)
144{ 144{
145 if (!(p12->mac = PKCS12_MAC_DATA_new ())) return PKCS12_ERROR; 145 if (!(p12->mac = PKCS12_MAC_DATA_new())) return PKCS12_ERROR;
146 if (iter > 1) { 146 if (iter > 1) {
147 if(!(p12->mac->iter = ASN1_INTEGER_new())) { 147 if(!(p12->mac->iter = M_ASN1_INTEGER_new())) {
148 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); 148 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
149 return 0; 149 return 0;
150 } 150 }
151 ASN1_INTEGER_set (p12->mac->iter, iter); 151 ASN1_INTEGER_set(p12->mac->iter, iter);
152 } 152 }
153 if (!saltlen) saltlen = PKCS12_SALT_LEN; 153 if (!saltlen) saltlen = PKCS12_SALT_LEN;
154 p12->mac->salt->length = saltlen; 154 p12->mac->salt->length = saltlen;
@@ -156,7 +156,10 @@ int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
156 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); 156 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
157 return 0; 157 return 0;
158 } 158 }
159 if (!salt) RAND_bytes (p12->mac->salt->data, saltlen); 159 if (!salt) {
160 if (RAND_bytes (p12->mac->salt->data, saltlen) <= 0)
161 return 0;
162 }
160 else memcpy (p12->mac->salt->data, salt, saltlen); 163 else memcpy (p12->mac->salt->data, salt, saltlen);
161 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); 164 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type));
162 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { 165 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) {
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c
new file mode 100644
index 0000000000..ee71707e2c
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/p12_npas.c
@@ -0,0 +1,212 @@
1/* p12_npas.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64#include <openssl/pkcs12.h>
65
66/* PKCS#12 password change routine */
67
68static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass);
69static int newpass_bags(STACK *bags, char *oldpass, char *newpass);
70static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass);
71static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen);
72
73/*
74 * Change the password on a PKCS#12 structure.
75 */
76
77int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
78{
79
80/* Check for NULL PKCS12 structure */
81
82if(!p12) {
83 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
84 return 0;
85}
86
87/* Check the mac */
88
89if (!PKCS12_verify_mac(p12, oldpass, -1)) {
90 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE);
91 return 0;
92}
93
94if (!newpass_p12(p12, oldpass, newpass)) {
95 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR);
96 return 0;
97}
98
99return 1;
100
101}
102
103/* Parse the outer PKCS#12 structure */
104
105static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass)
106{
107 STACK *asafes, *newsafes, *bags;
108 int i, bagnid, pbe_nid, pbe_iter, pbe_saltlen;
109 PKCS7 *p7, *p7new;
110 ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL;
111 unsigned char mac[EVP_MAX_MD_SIZE];
112 unsigned int maclen;
113 if (!(asafes = M_PKCS12_unpack_authsafes(p12))) return 0;
114 if(!(newsafes = sk_new(NULL))) return 0;
115 for (i = 0; i < sk_num (asafes); i++) {
116 p7 = (PKCS7 *) sk_value(asafes, i);
117 bagnid = OBJ_obj2nid(p7->type);
118 if (bagnid == NID_pkcs7_data) {
119 bags = M_PKCS12_unpack_p7data(p7);
120 } else if (bagnid == NID_pkcs7_encrypted) {
121 bags = M_PKCS12_unpack_p7encdata(p7, oldpass, -1);
122 alg_get(p7->d.encrypted->enc_data->algorithm,
123 &pbe_nid, &pbe_iter, &pbe_saltlen);
124 } else continue;
125 if (!bags) {
126 sk_pop_free(asafes, PKCS7_free);
127 return 0;
128 }
129 if (!newpass_bags(bags, oldpass, newpass)) {
130 sk_pop_free(bags, PKCS12_SAFEBAG_free);
131 sk_pop_free(asafes, PKCS7_free);
132 return 0;
133 }
134 /* Repack bag in same form with new password */
135 if (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags);
136 else p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL,
137 pbe_saltlen, pbe_iter, bags);
138 sk_pop_free(bags, PKCS12_SAFEBAG_free);
139 if(!p7new) {
140 sk_pop_free(asafes, PKCS7_free);
141 return 0;
142 }
143 sk_push(newsafes, (char *)p7new);
144 }
145 sk_pop_free(asafes, PKCS7_free);
146
147 /* Repack safe: save old safe in case of error */
148
149 p12_data_tmp = p12->authsafes->d.data;
150 if(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr;
151 if(!M_PKCS12_pack_authsafes(p12, newsafes)) goto saferr;
152
153 if(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr;
154 if(!(macnew = ASN1_OCTET_STRING_new())) goto saferr;
155 if(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr;
156 ASN1_OCTET_STRING_free(p12->mac->dinfo->digest);
157 p12->mac->dinfo->digest = macnew;
158 ASN1_OCTET_STRING_free(p12_data_tmp);
159
160 return 1;
161
162 saferr:
163 /* Restore old safe */
164 ASN1_OCTET_STRING_free(p12->authsafes->d.data);
165 ASN1_OCTET_STRING_free(macnew);
166 p12->authsafes->d.data = p12_data_tmp;
167 return 0;
168
169}
170
171
172static int newpass_bags(STACK *bags, char *oldpass, char *newpass)
173{
174 int i;
175 for (i = 0; i < sk_num(bags); i++) {
176 if (!newpass_bag((PKCS12_SAFEBAG *)sk_value(bags, i),
177 oldpass, newpass)) return 0;
178 }
179 return 1;
180}
181
182/* Change password of safebag: only needs handle shrouded keybags */
183
184static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass)
185{
186 PKCS8_PRIV_KEY_INFO *p8;
187 X509_SIG *p8new;
188 int p8_nid, p8_saltlen, p8_iter;
189
190 if(M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) return 1;
191
192 if (!(p8 = M_PKCS12_decrypt_skey(bag, oldpass, -1))) return 0;
193 alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter, &p8_saltlen);
194 if(!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen,
195 p8_iter, p8))) return 0;
196 X509_SIG_free(bag->value.shkeybag);
197 bag->value.shkeybag = p8new;
198 return 1;
199}
200
201static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen)
202{
203 PBEPARAM *pbe;
204 unsigned char *p;
205 p = alg->parameter->value.sequence->data;
206 pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length);
207 *pnid = OBJ_obj2nid(alg->algorithm);
208 *piter = ASN1_INTEGER_get(pbe->iter);
209 *psaltlen = pbe->salt->length;
210 PBEPARAM_free(pbe);
211 return 0;
212}
diff --git a/src/lib/libcrypto/pkcs12/pk12err.c b/src/lib/libcrypto/pkcs12/pk12err.c
index 38d7be7675..9d8de10e1e 100644
--- a/src/lib/libcrypto/pkcs12/pk12err.c
+++ b/src/lib/libcrypto/pkcs12/pk12err.c
@@ -79,6 +79,7 @@ static ERR_STRING_DATA PKCS12_str_functs[]=
79{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_UNI,0), "PKCS12_key_gen_uni"}, 79{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_UNI,0), "PKCS12_key_gen_uni"},
80{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_KEYBAG,0), "PKCS12_MAKE_KEYBAG"}, 80{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_KEYBAG,0), "PKCS12_MAKE_KEYBAG"},
81{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_SHKEYBAG,0), "PKCS12_MAKE_SHKEYBAG"}, 81{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_SHKEYBAG,0), "PKCS12_MAKE_SHKEYBAG"},
82{ERR_PACK(0,PKCS12_F_PKCS12_NEWPASS,0), "PKCS12_newpass"},
82{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7DATA,0), "PKCS12_pack_p7data"}, 83{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7DATA,0), "PKCS12_pack_p7data"},
83{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7ENCDATA,0), "PKCS12_pack_p7encdata"}, 84{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7ENCDATA,0), "PKCS12_pack_p7encdata"},
84{ERR_PACK(0,PKCS12_F_PKCS12_PACK_SAFEBAG,0), "PKCS12_pack_safebag"}, 85{ERR_PACK(0,PKCS12_F_PKCS12_PACK_SAFEBAG,0), "PKCS12_pack_safebag"},
@@ -99,6 +100,7 @@ static ERR_STRING_DATA PKCS12_str_reasons[]=
99{PKCS12_R_DECODE_ERROR ,"decode error"}, 100{PKCS12_R_DECODE_ERROR ,"decode error"},
100{PKCS12_R_ENCODE_ERROR ,"encode error"}, 101{PKCS12_R_ENCODE_ERROR ,"encode error"},
101{PKCS12_R_ENCRYPT_ERROR ,"encrypt error"}, 102{PKCS12_R_ENCRYPT_ERROR ,"encrypt error"},
103{PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE,"error setting encrypted data type"},
102{PKCS12_R_INVALID_NULL_ARGUMENT ,"invalid null argument"}, 104{PKCS12_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
103{PKCS12_R_INVALID_NULL_PKCS12_POINTER ,"invalid null pkcs12 pointer"}, 105{PKCS12_R_INVALID_NULL_PKCS12_POINTER ,"invalid null pkcs12 pointer"},
104{PKCS12_R_IV_GEN_ERROR ,"iv gen error"}, 106{PKCS12_R_IV_GEN_ERROR ,"iv gen error"},
diff --git a/src/lib/libcrypto/pkcs12/pkcs12.h b/src/lib/libcrypto/pkcs12/pkcs12.h
index 4cfba5e6c6..254000fa12 100644
--- a/src/lib/libcrypto/pkcs12/pkcs12.h
+++ b/src/lib/libcrypto/pkcs12/pkcs12.h
@@ -273,6 +273,7 @@ int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
273int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12); 273int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
274PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12); 274PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
275PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12); 275PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
276int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
276 277
277/* BEGIN ERROR CODES */ 278/* BEGIN ERROR CODES */
278/* The following lines are auto generated by the script mkerr.pl. Any changes 279/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -296,6 +297,7 @@ PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
296#define PKCS12_F_PKCS12_KEY_GEN_UNI 111 297#define PKCS12_F_PKCS12_KEY_GEN_UNI 111
297#define PKCS12_F_PKCS12_MAKE_KEYBAG 112 298#define PKCS12_F_PKCS12_MAKE_KEYBAG 112
298#define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113 299#define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113
300#define PKCS12_F_PKCS12_NEWPASS 128
299#define PKCS12_F_PKCS12_PACK_P7DATA 114 301#define PKCS12_F_PKCS12_PACK_P7DATA 114
300#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115 302#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115
301#define PKCS12_F_PKCS12_PACK_SAFEBAG 117 303#define PKCS12_F_PKCS12_PACK_SAFEBAG 117
@@ -313,6 +315,7 @@ PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
313#define PKCS12_R_DECODE_ERROR 101 315#define PKCS12_R_DECODE_ERROR 101
314#define PKCS12_R_ENCODE_ERROR 102 316#define PKCS12_R_ENCODE_ERROR 102
315#define PKCS12_R_ENCRYPT_ERROR 103 317#define PKCS12_R_ENCRYPT_ERROR 103
318#define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120
316#define PKCS12_R_INVALID_NULL_ARGUMENT 104 319#define PKCS12_R_INVALID_NULL_ARGUMENT 104
317#define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105 320#define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105
318#define PKCS12_R_IV_GEN_ERROR 106 321#define PKCS12_R_IV_GEN_ERROR 106
diff --git a/src/lib/libcrypto/pkcs7/Makefile.ssl b/src/lib/libcrypto/pkcs7/Makefile.ssl
index 6c4644b2f2..0e508386e8 100644
--- a/src/lib/libcrypto/pkcs7/Makefile.ssl
+++ b/src/lib/libcrypto/pkcs7/Makefile.ssl
@@ -1,5 +1,5 @@
1# 1#
2# SSLeay/crypto/asn1/Makefile 2# SSLeay/crypto/pkcs7/Makefile
3# 3#
4 4
5DIR= pkcs7 5DIR= pkcs7
@@ -15,6 +15,9 @@ MAKEDEPEND= $(TOP)/util/domd $(TOP)
15MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
16AR= ar r 16AR= ar r
17 17
18PEX_LIBS=
19EX_LIBS=
20
18CFLAGS= $(INCLUDES) $(CFLAG) 21CFLAGS= $(INCLUDES) $(CFLAG)
19 22
20GENERAL=Makefile README 23GENERAL=Makefile README
@@ -22,8 +25,8 @@ TEST=
22APPS= 25APPS=
23 26
24LIB=$(TOP)/libcrypto.a 27LIB=$(TOP)/libcrypto.a
25LIBSRC= pk7_lib.c pkcs7err.c pk7_doit.c 28LIBSRC= pk7_lib.c pkcs7err.c pk7_doit.c pk7_smime.c pk7_attr.c pk7_mime.c
26LIBOBJ= pk7_lib.o pkcs7err.o pk7_doit.o 29LIBOBJ= pk7_lib.o pkcs7err.o pk7_doit.o pk7_smime.o pk7_attr.o pk7_mime.o
27 30
28SRC= $(LIBSRC) 31SRC= $(LIBSRC)
29 32
@@ -42,16 +45,16 @@ all: lib
42testapps: enc dec sign verify 45testapps: enc dec sign verify
43 46
44enc: enc.o lib 47enc: enc.o lib
45 $(CC) $(CFLAGS) -o enc enc.o $(LIB) 48 $(CC) $(CFLAGS) -o enc enc.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
46 49
47dec: dec.o lib 50dec: dec.o lib
48 $(CC) $(CFLAGS) -o dec dec.o $(LIB) 51 $(CC) $(CFLAGS) -o dec dec.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
49 52
50sign: sign.o lib 53sign: sign.o lib
51 $(CC) $(CFLAGS) -o sign sign.o $(LIB) 54 $(CC) $(CFLAGS) -o sign sign.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
52 55
53verify: verify.o example.o lib 56verify: verify.o example.o lib
54 $(CC) $(CFLAGS) -o verify verify.o example.o $(LIB) 57 $(CC) $(CFLAGS) -o verify verify.o $(PEX_LIBS) example.o $(LIB) $(EX_LIBS)
55 58
56lib: $(LIBOBJ) 59lib: $(LIBOBJ)
57 $(AR) $(LIB) $(LIBOBJ) 60 $(AR) $(LIB) $(LIBOBJ)
@@ -90,18 +93,35 @@ dclean:
90 mv -f Makefile.new $(MAKEFILE) 93 mv -f Makefile.new $(MAKEFILE)
91 94
92clean: 95clean:
93 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 96 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff enc dec sign verify
94 97
95# DO NOT DELETE THIS LINE -- make depend depends on it. 98# DO NOT DELETE THIS LINE -- make depend depends on it.
96 99
100pk7_attr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
101pk7_attr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
102pk7_attr.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
103pk7_attr.o: ../../include/openssl/des.h ../../include/openssl/dh.h
104pk7_attr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
105pk7_attr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
106pk7_attr.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
107pk7_attr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
108pk7_attr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
109pk7_attr.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
110pk7_attr.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
111pk7_attr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
112pk7_attr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
113pk7_attr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
114pk7_attr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
115pk7_attr.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
97pk7_doit.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 116pk7_doit.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
98pk7_doit.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 117pk7_doit.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
99pk7_doit.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 118pk7_doit.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
100pk7_doit.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 119pk7_doit.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
101pk7_doit.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 120pk7_doit.o: ../../include/openssl/des.h ../../include/openssl/dh.h
102pk7_doit.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 121pk7_doit.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
103pk7_doit.o: ../../include/openssl/err.h ../../include/openssl/evp.h 122pk7_doit.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
104pk7_doit.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 123pk7_doit.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
124pk7_doit.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
105pk7_doit.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 125pk7_doit.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
106pk7_doit.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 126pk7_doit.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
107pk7_doit.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h 127pk7_doit.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
@@ -110,7 +130,8 @@ pk7_doit.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
110pk7_doit.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h 130pk7_doit.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
111pk7_doit.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 131pk7_doit.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
112pk7_doit.o: ../../include/openssl/stack.h ../../include/openssl/x509.h 132pk7_doit.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
113pk7_doit.o: ../../include/openssl/x509_vfy.h ../cryptlib.h 133pk7_doit.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
134pk7_doit.o: ../cryptlib.h
114pk7_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 135pk7_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
115pk7_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 136pk7_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
116pk7_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 137pk7_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -128,6 +149,42 @@ pk7_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
128pk7_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 149pk7_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
129pk7_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 150pk7_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
130pk7_lib.o: ../cryptlib.h 151pk7_lib.o: ../cryptlib.h
152pk7_mime.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
153pk7_mime.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
154pk7_mime.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
155pk7_mime.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
156pk7_mime.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
157pk7_mime.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
158pk7_mime.o: ../../include/openssl/err.h ../../include/openssl/evp.h
159pk7_mime.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
160pk7_mime.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
161pk7_mime.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
162pk7_mime.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
163pk7_mime.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
164pk7_mime.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
165pk7_mime.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
166pk7_mime.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
167pk7_mime.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
168pk7_mime.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
169pk7_smime.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
170pk7_smime.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
171pk7_smime.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
172pk7_smime.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
173pk7_smime.o: ../../include/openssl/des.h ../../include/openssl/dh.h
174pk7_smime.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
175pk7_smime.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
176pk7_smime.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
177pk7_smime.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
178pk7_smime.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
179pk7_smime.o: ../../include/openssl/objects.h
180pk7_smime.o: ../../include/openssl/opensslconf.h
181pk7_smime.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
182pk7_smime.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
183pk7_smime.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
184pk7_smime.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
185pk7_smime.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
186pk7_smime.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
187pk7_smime.o: ../../include/openssl/x509v3.h ../cryptlib.h
131pkcs7err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 188pkcs7err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
132pkcs7err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 189pkcs7err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
133pkcs7err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h 190pkcs7err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
diff --git a/src/lib/libcrypto/pkcs7/bio_ber.c b/src/lib/libcrypto/pkcs7/bio_ber.c
index 2f17723e98..4803966fd2 100644
--- a/src/lib/libcrypto/pkcs7/bio_ber.c
+++ b/src/lib/libcrypto/pkcs7/bio_ber.c
@@ -69,6 +69,7 @@ static int ber_read(BIO *h,char *buf,int size);
69static long ber_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long ber_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int ber_new(BIO *h); 70static int ber_new(BIO *h);
71static int ber_free(BIO *data); 71static int ber_free(BIO *data);
72static long ber_callback_ctrl(BIO *h,int cmd,void *(*fp)());
72#define BER_BUF_SIZE (32) 73#define BER_BUF_SIZE (32)
73 74
74/* This is used to hold the state of the BER objects being read. */ 75/* This is used to hold the state of the BER objects being read. */
@@ -92,7 +93,7 @@ typedef struct bio_ber_struct
92 /* most of the following are used when doing non-blocking IO */ 93 /* most of the following are used when doing non-blocking IO */
93 /* reading */ 94 /* reading */
94 long num_left; /* number of bytes still to read/write in block */ 95 long num_left; /* number of bytes still to read/write in block */
95 int depth; /* used with idefinite encoding. */ 96 int depth; /* used with indefinite encoding. */
96 int finished; /* No more read data */ 97 int finished; /* No more read data */
97 98
98 /* writting */ 99 /* writting */
@@ -115,6 +116,7 @@ static BIO_METHOD methods_ber=
115 ber_ctrl, 116 ber_ctrl,
116 ber_new, 117 ber_new,
117 ber_free, 118 ber_free,
119 ber_callback_ctrl,
118 }; 120 };
119 121
120BIO_METHOD *BIO_f_ber(void) 122BIO_METHOD *BIO_f_ber(void)
@@ -409,6 +411,20 @@ again:
409 return(ret); 411 return(ret);
410 } 412 }
411 413
414static long ber_callback_ctrl(BIO *b, int cmd, void *(*fp)())
415 {
416 long ret=1;
417
418 if (b->next_bio == NULL) return(0);
419 switch (cmd)
420 {
421 default:
422 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
423 break;
424 }
425 return(ret);
426 }
427
412/* 428/*
413void BIO_set_cipher_ctx(b,c) 429void BIO_set_cipher_ctx(b,c)
414BIO *b; 430BIO *b;
diff --git a/src/lib/libcrypto/pkcs7/dec.c b/src/lib/libcrypto/pkcs7/dec.c
index b3661f28d3..6752ec568a 100644
--- a/src/lib/libcrypto/pkcs7/dec.c
+++ b/src/lib/libcrypto/pkcs7/dec.c
@@ -57,6 +57,7 @@
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include <stdlib.h> 59#include <stdlib.h>
60#include <string.h>
60#include <openssl/bio.h> 61#include <openssl/bio.h>
61#include <openssl/x509.h> 62#include <openssl/x509.h>
62#include <openssl/pem.h> 63#include <openssl/pem.h>
@@ -85,7 +86,7 @@ char *argv[];
85 int i,printit=0; 86 int i,printit=0;
86 STACK_OF(PKCS7_SIGNER_INFO) *sk; 87 STACK_OF(PKCS7_SIGNER_INFO) *sk;
87 88
88 SSLeay_add_all_algorithms(); 89 OpenSSL_add_all_algorithms();
89 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 90 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
90 91
91 data=BIO_new(BIO_s_file()); 92 data=BIO_new(BIO_s_file());
@@ -121,9 +122,10 @@ char *argv[];
121 } 122 }
122 123
123 if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err; 124 if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err;
124 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; 125 if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
125 BIO_reset(in); 126 BIO_reset(in);
126 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; 127 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL)
128 goto err;
127 BIO_free(in); 129 BIO_free(in);
128 130
129 if (pp == NULL) 131 if (pp == NULL)
@@ -131,7 +133,7 @@ char *argv[];
131 133
132 134
133 /* Load the PKCS7 object from a file */ 135 /* Load the PKCS7 object from a file */
134 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err; 136 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL,NULL)) == NULL) goto err;
135 137
136 138
137 139
@@ -148,7 +150,7 @@ char *argv[];
148 /* We need to process the data */ 150 /* We need to process the data */
149 /* We cannot support detached encryption */ 151 /* We cannot support detached encryption */
150 p7bio=PKCS7_dataDecode(p7,pkey,detached,x509); 152 p7bio=PKCS7_dataDecode(p7,pkey,detached,x509);
151 153
152 if (p7bio == NULL) 154 if (p7bio == NULL)
153 { 155 {
154 printf("problems decoding\n"); 156 printf("problems decoding\n");
diff --git a/src/lib/libcrypto/pkcs7/enc.c b/src/lib/libcrypto/pkcs7/enc.c
index 43bfd10a23..2b56c2eff3 100644
--- a/src/lib/libcrypto/pkcs7/enc.c
+++ b/src/lib/libcrypto/pkcs7/enc.c
@@ -56,6 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include <string.h>
59#include <openssl/bio.h> 60#include <openssl/bio.h>
60#include <openssl/x509.h> 61#include <openssl/x509.h>
61#include <openssl/pem.h> 62#include <openssl/pem.h>
@@ -76,7 +77,7 @@ char *argv[];
76 const EVP_CIPHER *cipher=NULL; 77 const EVP_CIPHER *cipher=NULL;
77 STACK_OF(X509) *recips=NULL; 78 STACK_OF(X509) *recips=NULL;
78 79
79 SSLeay_add_all_algorithms(); 80 OpenSSL_add_all_algorithms();
80 81
81 data=BIO_new(BIO_s_file()); 82 data=BIO_new(BIO_s_file());
82 while(argc > 1) 83 while(argc > 1)
@@ -98,7 +99,8 @@ char *argv[];
98 argc-=2; 99 argc-=2;
99 argv+=2; 100 argv+=2;
100 if (!(in=BIO_new_file(keyfile,"r"))) goto err; 101 if (!(in=BIO_new_file(keyfile,"r"))) goto err;
101 if (!(x509=PEM_read_bio_X509(in,NULL,NULL))) goto err; 102 if (!(x509=PEM_read_bio_X509(in,NULL,NULL,NULL)))
103 goto err;
102 if(!recips) recips = sk_X509_new_null(); 104 if(!recips) recips = sk_X509_new_null();
103 sk_X509_push(recips, x509); 105 sk_X509_push(recips, x509);
104 BIO_free(in); 106 BIO_free(in);
@@ -125,7 +127,14 @@ char *argv[];
125#else 127#else
126 PKCS7_set_type(p7,NID_pkcs7_enveloped); 128 PKCS7_set_type(p7,NID_pkcs7_enveloped);
127#endif 129#endif
128 if(!cipher) cipher = EVP_des_ede3_cbc(); 130 if(!cipher) {
131#ifndef NO_DES
132 cipher = EVP_des_ede3_cbc();
133#else
134 fprintf(stderr, "No cipher selected\n");
135 goto err;
136#endif
137 }
129 138
130 if (!PKCS7_set_cipher(p7,cipher)) goto err; 139 if (!PKCS7_set_cipher(p7,cipher)) goto err;
131 for(i = 0; i < sk_X509_num(recips); i++) { 140 for(i = 0; i < sk_X509_num(recips); i++) {
diff --git a/src/lib/libcrypto/pkcs7/example.c b/src/lib/libcrypto/pkcs7/example.c
index 7354890084..f6656be28e 100644
--- a/src/lib/libcrypto/pkcs7/example.c
+++ b/src/lib/libcrypto/pkcs7/example.c
@@ -1,5 +1,6 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h>
3#include <openssl/pkcs7.h> 4#include <openssl/pkcs7.h>
4#include <openssl/asn1_mac.h> 5#include <openssl/asn1_mac.h>
5 6
@@ -36,7 +37,7 @@ void add_signed_string(PKCS7_SIGNER_INFO *si, char *str)
36 signed_string_nid= 37 signed_string_nid=
37 OBJ_create("1.2.3.4.5","OID_example","Our example OID"); 38 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
38 os=ASN1_OCTET_STRING_new(); 39 os=ASN1_OCTET_STRING_new();
39 ASN1_OCTET_STRING_set(os,str,strlen(str)); 40 ASN1_OCTET_STRING_set(os,(unsigned char*)str,strlen(str));
40 /* When we add, we do not free */ 41 /* When we add, we do not free */
41 PKCS7_add_signed_attribute(si,signed_string_nid, 42 PKCS7_add_signed_attribute(si,signed_string_nid,
42 V_ASN1_OCTET_STRING,(char *)os); 43 V_ASN1_OCTET_STRING,(char *)os);
@@ -68,7 +69,7 @@ int get_signed_string(PKCS7_SIGNER_INFO *si, char *buf, int len)
68 return(0); 69 return(0);
69 } 70 }
70 71
71static signed_seq2string_nid= -1; 72static int signed_seq2string_nid= -1;
72/* ########################################### */ 73/* ########################################### */
73int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2) 74int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
74 { 75 {
@@ -86,8 +87,8 @@ int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
86 87
87 os1=ASN1_OCTET_STRING_new(); 88 os1=ASN1_OCTET_STRING_new();
88 os2=ASN1_OCTET_STRING_new(); 89 os2=ASN1_OCTET_STRING_new();
89 ASN1_OCTET_STRING_set(os1,str1,strlen(str1)); 90 ASN1_OCTET_STRING_set(os1,(unsigned char*)str1,strlen(str1));
90 ASN1_OCTET_STRING_set(os2,str1,strlen(str1)); 91 ASN1_OCTET_STRING_set(os2,(unsigned char*)str1,strlen(str1));
91 i =i2d_ASN1_OCTET_STRING(os1,NULL); 92 i =i2d_ASN1_OCTET_STRING(os1,NULL);
92 i+=i2d_ASN1_OCTET_STRING(os2,NULL); 93 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
93 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE); 94 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
@@ -197,7 +198,7 @@ X509_ATTRIBUTE *create_string(char *str)
197 signed_string_nid= 198 signed_string_nid=
198 OBJ_create("1.2.3.4.5","OID_example","Our example OID"); 199 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
199 os=ASN1_OCTET_STRING_new(); 200 os=ASN1_OCTET_STRING_new();
200 ASN1_OCTET_STRING_set(os,str,strlen(str)); 201 ASN1_OCTET_STRING_set(os,(unsigned char*)str,strlen(str));
201 /* When we add, we do not free */ 202 /* When we add, we do not free */
202 ret=X509_ATTRIBUTE_create(signed_string_nid, 203 ret=X509_ATTRIBUTE_create(signed_string_nid,
203 V_ASN1_OCTET_STRING,(char *)os); 204 V_ASN1_OCTET_STRING,(char *)os);
@@ -250,8 +251,8 @@ X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
250 251
251 os1=ASN1_OCTET_STRING_new(); 252 os1=ASN1_OCTET_STRING_new();
252 os2=ASN1_OCTET_STRING_new(); 253 os2=ASN1_OCTET_STRING_new();
253 ASN1_OCTET_STRING_set(os1,str1,strlen(str1)); 254 ASN1_OCTET_STRING_set(os1,(unsigned char*)str1,strlen(str1));
254 ASN1_OCTET_STRING_set(os2,str1,strlen(str1)); 255 ASN1_OCTET_STRING_set(os2,(unsigned char*)str1,strlen(str1));
255 i =i2d_ASN1_OCTET_STRING(os1,NULL); 256 i =i2d_ASN1_OCTET_STRING(os1,NULL);
256 i+=i2d_ASN1_OCTET_STRING(os2,NULL); 257 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
257 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE); 258 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
new file mode 100644
index 0000000000..3b9c0fe3f2
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_attr.c
@@ -0,0 +1,85 @@
1/* pk7_attr.c */
2/* S/MIME code.
3 * Copyright (C) 1997-8 Dr S N Henson (shenson@bigfoot.com)
4 * All Rights Reserved.
5 * Redistribution of this code without the authors permission is expressly
6 * prohibited.
7 */
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <openssl/bio.h>
12#include <openssl/asn1.h>
13#include <openssl/pem.h>
14#include <openssl/pkcs7.h>
15#include <openssl/err.h>
16
17int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK *cap)
18{
19 ASN1_STRING *seq;
20 unsigned char *p, *pp;
21 int len;
22 len=i2d_ASN1_SET(cap,NULL,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
23 V_ASN1_UNIVERSAL, IS_SEQUENCE);
24 if(!(pp=(unsigned char *)Malloc(len))) {
25 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
26 return 0;
27 }
28 p=pp;
29 i2d_ASN1_SET(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
30 V_ASN1_UNIVERSAL, IS_SEQUENCE);
31 if(!(seq = ASN1_STRING_new())) {
32 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
33 return 0;
34 }
35 if(!ASN1_STRING_set (seq, pp, len)) {
36 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
37 return 0;
38 }
39 Free (pp);
40 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
41 V_ASN1_SEQUENCE, seq);
42}
43
44STACK *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
45{
46 ASN1_TYPE *cap;
47 unsigned char *p;
48 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities);
49 if (!cap) return NULL;
50 p = cap->value.sequence->data;
51 return d2i_ASN1_SET (NULL, &p, cap->value.sequence->length,
52 (char *(*)())d2i_X509_ALGOR, X509_ALGOR_free, V_ASN1_SEQUENCE,
53 V_ASN1_UNIVERSAL);
54}
55
56/* Basic smime-capabilities OID and optional integer arg */
57int PKCS7_simple_smimecap(STACK *sk, int nid, int arg)
58{
59 X509_ALGOR *alg;
60 if(!(alg = X509_ALGOR_new())) {
61 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
62 return 0;
63 }
64 ASN1_OBJECT_free(alg->algorithm);
65 alg->algorithm = OBJ_nid2obj (nid);
66 if (arg > 0) {
67 ASN1_INTEGER *nbit;
68 if(!(alg->parameter = ASN1_TYPE_new())) {
69 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
70 return 0;
71 }
72 if(!(nbit = ASN1_INTEGER_new())) {
73 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
74 return 0;
75 }
76 if(!ASN1_INTEGER_set (nbit, arg)) {
77 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 alg->parameter->value.integer = nbit;
81 alg->parameter->type = V_ASN1_INTEGER;
82 }
83 sk_push (sk, (char *)alg);
84 return 1;
85}
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index dee81b547a..80ac5e34b4 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -61,6 +61,7 @@
61#include <openssl/rand.h> 61#include <openssl/rand.h>
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
64 65
65static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, 66static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
66 void *value); 67 void *value);
@@ -160,9 +161,10 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
160 BIO_get_cipher_ctx(btmp, &ctx); 161 BIO_get_cipher_ctx(btmp, &ctx);
161 keylen=EVP_CIPHER_key_length(evp_cipher); 162 keylen=EVP_CIPHER_key_length(evp_cipher);
162 ivlen=EVP_CIPHER_iv_length(evp_cipher); 163 ivlen=EVP_CIPHER_iv_length(evp_cipher);
163 RAND_bytes(key,keylen); 164 if (RAND_bytes(key,keylen) <= 0)
165 goto err;
164 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher)); 166 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
165 if (ivlen > 0) RAND_bytes(iv,ivlen); 167 if (ivlen > 0) RAND_pseudo_bytes(iv,ivlen);
166 EVP_CipherInit(ctx, evp_cipher, key, iv, 1); 168 EVP_CipherInit(ctx, evp_cipher, key, iv, 1);
167 169
168 if (ivlen > 0) { 170 if (ivlen > 0) {
@@ -204,7 +206,7 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
204 Free(tmp); 206 Free(tmp);
205 goto err; 207 goto err;
206 } 208 }
207 ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj); 209 M_ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj);
208 } 210 }
209 Free(tmp); 211 Free(tmp);
210 memset(key, 0, keylen); 212 memset(key, 0, keylen);
@@ -216,30 +218,23 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
216 btmp=NULL; 218 btmp=NULL;
217 } 219 }
218 220
219 if (bio == NULL) /* ??????????? */ 221 if (bio == NULL) {
220 {
221 if (p7->detached) 222 if (p7->detached)
222 bio=BIO_new(BIO_s_null()); 223 bio=BIO_new(BIO_s_null());
223 else 224 else {
224 {
225 bio=BIO_new(BIO_s_mem());
226 /* We need to set this so that when we have read all
227 * the data, the encrypt BIO, if present, will read
228 * EOF and encode the last few bytes */
229 BIO_set_mem_eof_return(bio,0);
230
231 if (PKCS7_type_is_signed(p7) && 225 if (PKCS7_type_is_signed(p7) &&
232 PKCS7_type_is_data(p7->d.sign->contents)) 226 PKCS7_type_is_data(p7->d.sign->contents)) {
233 {
234 ASN1_OCTET_STRING *os; 227 ASN1_OCTET_STRING *os;
235
236 os=p7->d.sign->contents->d.data; 228 os=p7->d.sign->contents->d.data;
237 if (os->length > 0) 229 if (os->length > 0) bio =
238 BIO_write(bio,(char *)os->data, 230 BIO_new_mem_buf(os->data, os->length);
239 os->length); 231 }
240 } 232 if(bio == NULL) {
233 bio=BIO_new(BIO_s_mem());
234 BIO_set_mem_eof_return(bio,0);
241 } 235 }
242 } 236 }
237 }
243 BIO_push(out,bio); 238 BIO_push(out,bio);
244 bio=NULL; 239 bio=NULL;
245 if (0) 240 if (0)
@@ -259,7 +254,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
259 { 254 {
260 int i,j; 255 int i,j;
261 BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL; 256 BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
262 char *tmp=NULL; 257 unsigned char *tmp=NULL;
263 X509_ALGOR *xa; 258 X509_ALGOR *xa;
264 ASN1_OCTET_STRING *data_body=NULL; 259 ASN1_OCTET_STRING *data_body=NULL;
265 const EVP_MD *evp_md; 260 const EVP_MD *evp_md;
@@ -270,6 +265,9 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
270 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL; 265 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
271 X509_ALGOR *xalg=NULL; 266 X509_ALGOR *xalg=NULL;
272 PKCS7_RECIP_INFO *ri=NULL; 267 PKCS7_RECIP_INFO *ri=NULL;
268#ifndef NO_RC2
269 char is_rc2 = 0;
270#endif
273/* EVP_PKEY *pkey; */ 271/* EVP_PKEY *pkey; */
274#if 0 272#if 0
275 X509_STORE_CTX s_ctx; 273 X509_STORE_CTX s_ctx;
@@ -314,6 +312,16 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
314 goto err; 312 goto err;
315 } 313 }
316 314
315 if(EVP_CIPHER_nid(evp_cipher) == NID_rc2_cbc)
316 {
317#ifndef NO_RC2
318 is_rc2 = 1;
319#else
320 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
321 goto err;
322#endif
323 }
324
317 /* We will be checking the signature */ 325 /* We will be checking the signature */
318 if (md_sk != NULL) 326 if (md_sk != NULL)
319 { 327 {
@@ -372,7 +380,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
372 ri=sk_PKCS7_RECIP_INFO_value(rsk,i); 380 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
373 if(!X509_NAME_cmp(ri->issuer_and_serial->issuer, 381 if(!X509_NAME_cmp(ri->issuer_and_serial->issuer,
374 pcert->cert_info->issuer) && 382 pcert->cert_info->issuer) &&
375 !ASN1_INTEGER_cmp(pcert->cert_info->serialNumber, 383 !M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
376 ri->issuer_and_serial->serial)) break; 384 ri->issuer_and_serial->serial)) break;
377 ri=NULL; 385 ri=NULL;
378 } 386 }
@@ -383,17 +391,15 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
383 } 391 }
384 392
385 jj=EVP_PKEY_size(pkey); 393 jj=EVP_PKEY_size(pkey);
386 tmp=Malloc(jj+10); 394 tmp=(unsigned char *)Malloc(jj+10);
387 if (tmp == NULL) 395 if (tmp == NULL)
388 { 396 {
389 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE); 397 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
390 goto err; 398 goto err;
391 } 399 }
392 400
393 jj=EVP_PKEY_decrypt((unsigned char *)tmp, 401 jj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key),
394 ASN1_STRING_data(ri->enc_key), 402 M_ASN1_STRING_length(ri->enc_key), pkey);
395 ASN1_STRING_length(ri->enc_key),
396 pkey);
397 if (jj <= 0) 403 if (jj <= 0)
398 { 404 {
399 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB); 405 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);
@@ -406,13 +412,25 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
406 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0) 412 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
407 return(NULL); 413 return(NULL);
408 414
409 if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) 415 if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) {
410 { 416 /* HACK: some S/MIME clients don't use the same key
411 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 417 * and effective key length. The key length is
418 * determined by the size of the decrypted RSA key.
419 * So we hack things to manually set the RC2 key
420 * because we currently can't do this with the EVP
421 * interface.
422 */
423#ifndef NO_RC2
424 if(is_rc2) RC2_set_key(&(evp_ctx->c.rc2_ks),jj, tmp,
425 EVP_CIPHER_CTX_key_length(evp_ctx)*8);
426 else
427#endif
428 {
429 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
412 PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH); 430 PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
413 goto err; 431 goto err;
414 } 432 }
415 EVP_CipherInit(evp_ctx,NULL,(unsigned char *)tmp,NULL,0); 433 } else EVP_CipherInit(evp_ctx,NULL,tmp,NULL,0);
416 434
417 memset(tmp,0,jj); 435 memset(tmp,0,jj);
418 436
@@ -430,6 +448,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
430 } 448 }
431 else 449 else
432 { 450 {
451#if 0
433 bio=BIO_new(BIO_s_mem()); 452 bio=BIO_new(BIO_s_mem());
434 /* We need to set this so that when we have read all 453 /* We need to set this so that when we have read all
435 * the data, the encrypt BIO, if present, will read 454 * the data, the encrypt BIO, if present, will read
@@ -438,6 +457,14 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
438 457
439 if (data_body->length > 0) 458 if (data_body->length > 0)
440 BIO_write(bio,(char *)data_body->data,data_body->length); 459 BIO_write(bio,(char *)data_body->data,data_body->length);
460#else
461 if (data_body->length > 0)
462 bio = BIO_new_mem_buf(data_body->data,data_body->length);
463 else {
464 bio=BIO_new(BIO_s_mem());
465 BIO_set_mem_eof_return(bio,0);
466 }
467#endif
441 } 468 }
442 BIO_push(out,bio); 469 BIO_push(out,bio);
443 bio=NULL; 470 bio=NULL;
@@ -479,12 +506,12 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
479 case NID_pkcs7_signedAndEnveloped: 506 case NID_pkcs7_signedAndEnveloped:
480 /* XXXXXXXXXXXXXXXX */ 507 /* XXXXXXXXXXXXXXXX */
481 si_sk=p7->d.signed_and_enveloped->signer_info; 508 si_sk=p7->d.signed_and_enveloped->signer_info;
482 os=ASN1_OCTET_STRING_new(); 509 os=M_ASN1_OCTET_STRING_new();
483 p7->d.signed_and_enveloped->enc_data->enc_data=os; 510 p7->d.signed_and_enveloped->enc_data->enc_data=os;
484 break; 511 break;
485 case NID_pkcs7_enveloped: 512 case NID_pkcs7_enveloped:
486 /* XXXXXXXXXXXXXXXX */ 513 /* XXXXXXXXXXXXXXXX */
487 os=ASN1_OCTET_STRING_new(); 514 os=M_ASN1_OCTET_STRING_new();
488 p7->d.enveloped->enc_data->enc_data=os; 515 p7->d.enveloped->enc_data->enc_data=os;
489 break; 516 break;
490 case NID_pkcs7_signed: 517 case NID_pkcs7_signed:
@@ -492,7 +519,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
492 os=p7->d.sign->contents->d.data; 519 os=p7->d.sign->contents->d.data;
493 /* If detached data then the content is excluded */ 520 /* If detached data then the content is excluded */
494 if(p7->detached) { 521 if(p7->detached) {
495 ASN1_OCTET_STRING_free(os); 522 M_ASN1_OCTET_STRING_free(os);
496 p7->d.sign->contents->d.data = NULL; 523 p7->d.sign->contents->d.data = NULL;
497 } 524 }
498 break; 525 break;
@@ -527,7 +554,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
527 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR); 554 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR);
528 goto err; 555 goto err;
529 } 556 }
530 if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == j) 557 if (EVP_MD_CTX_type(mdc) == j)
531 break; 558 break;
532 else 559 else
533 btmp=btmp->next_bio; 560 btmp=btmp->next_bio;
@@ -561,10 +588,10 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
561 V_ASN1_UTCTIME,sign_time); 588 V_ASN1_UTCTIME,sign_time);
562 589
563 /* Add digest */ 590 /* Add digest */
564 md_tmp=EVP_MD_CTX_type(&ctx_tmp); 591 md_tmp=EVP_MD_CTX_md(&ctx_tmp);
565 EVP_DigestFinal(&ctx_tmp,md_data,&md_len); 592 EVP_DigestFinal(&ctx_tmp,md_data,&md_len);
566 digest=ASN1_OCTET_STRING_new(); 593 digest=M_ASN1_OCTET_STRING_new();
567 ASN1_OCTET_STRING_set(digest,md_data,md_len); 594 M_ASN1_OCTET_STRING_set(digest,md_data,md_len);
568 PKCS7_add_signed_attribute(si, 595 PKCS7_add_signed_attribute(si,
569 NID_pkcs9_messageDigest, 596 NID_pkcs9_messageDigest,
570 V_ASN1_OCTET_STRING,digest); 597 V_ASN1_OCTET_STRING,digest);
@@ -611,8 +638,17 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
611 goto err; 638 goto err;
612 } 639 }
613 BIO_get_mem_ptr(btmp,&buf_mem); 640 BIO_get_mem_ptr(btmp,&buf_mem);
614 ASN1_OCTET_STRING_set(os, 641 /* Mark the BIO read only then we can use its copy of the data
642 * instead of making an extra copy.
643 */
644 BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
645 BIO_set_mem_eof_return(btmp, 0);
646 os->data = (unsigned char *)buf_mem->data;
647 os->length = buf_mem->length;
648#if 0
649 M_ASN1_OCTET_STRING_set(os,
615 (unsigned char *)buf_mem->data,buf_mem->length); 650 (unsigned char *)buf_mem->data,buf_mem->length);
651#endif
616 } 652 }
617 if (pp != NULL) Free(pp); 653 if (pp != NULL) Free(pp);
618 pp=NULL; 654 pp=NULL;
@@ -658,6 +694,7 @@ int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
658 694
659 /* Lets verify */ 695 /* Lets verify */
660 X509_STORE_CTX_init(ctx,cert_store,x509,cert); 696 X509_STORE_CTX_init(ctx,cert_store,x509,cert);
697 X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN);
661 i=X509_verify_cert(ctx); 698 i=X509_verify_cert(ctx);
662 if (i <= 0) 699 if (i <= 0)
663 { 700 {
@@ -709,7 +746,7 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
709 PKCS7_R_INTERNAL_ERROR); 746 PKCS7_R_INTERNAL_ERROR);
710 goto err; 747 goto err;
711 } 748 }
712 if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type) 749 if (EVP_MD_CTX_type(mdc) == md_type)
713 break; 750 break;
714 btmp=btmp->next_bio; 751 btmp=btmp->next_bio;
715 } 752 }
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
index 8b863d0558..45973fe850 100644
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ b/src/lib/libcrypto/pkcs7/pk7_lib.c
@@ -123,7 +123,7 @@ int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data)
123 { 123 {
124 case NID_pkcs7_signed: 124 case NID_pkcs7_signed:
125 if (p7->d.sign->contents != NULL) 125 if (p7->d.sign->contents != NULL)
126 PKCS7_content_free(p7->d.sign->contents); 126 PKCS7_free(p7->d.sign->contents);
127 p7->d.sign->contents=p7_data; 127 p7->d.sign->contents=p7_data;
128 break; 128 break;
129 case NID_pkcs7_digest: 129 case NID_pkcs7_digest:
@@ -157,7 +157,7 @@ int PKCS7_set_type(PKCS7 *p7, int type)
157 break; 157 break;
158 case NID_pkcs7_data: 158 case NID_pkcs7_data:
159 p7->type=obj; 159 p7->type=obj;
160 if ((p7->d.data=ASN1_OCTET_STRING_new()) == NULL) 160 if ((p7->d.data=M_ASN1_OCTET_STRING_new()) == NULL)
161 goto err; 161 goto err;
162 break; 162 break;
163 case NID_pkcs7_signedAndEnveloped: 163 case NID_pkcs7_signedAndEnveloped:
@@ -165,9 +165,6 @@ int PKCS7_set_type(PKCS7 *p7, int type)
165 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new()) 165 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new())
166 == NULL) goto err; 166 == NULL) goto err;
167 ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1); 167 ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1);
168/* p7->d.signed_and_enveloped->enc_data->content_type=
169 OBJ_nid2obj(NID_pkcs7_encrypted);*/
170
171 break; 168 break;
172 case NID_pkcs7_enveloped: 169 case NID_pkcs7_enveloped:
173 p7->type=obj; 170 p7->type=obj;
@@ -175,8 +172,14 @@ int PKCS7_set_type(PKCS7 *p7, int type)
175 == NULL) goto err; 172 == NULL) goto err;
176 ASN1_INTEGER_set(p7->d.enveloped->version,0); 173 ASN1_INTEGER_set(p7->d.enveloped->version,0);
177 break; 174 break;
178 case NID_pkcs7_digest:
179 case NID_pkcs7_encrypted: 175 case NID_pkcs7_encrypted:
176 p7->type=obj;
177 if ((p7->d.encrypted=PKCS7_ENCRYPT_new())
178 == NULL) goto err;
179 ASN1_INTEGER_set(p7->d.encrypted->version,0);
180 break;
181
182 case NID_pkcs7_digest:
180 default: 183 default:
181 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); 184 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
182 goto err; 185 goto err;
@@ -224,8 +227,13 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
224 } 227 }
225 if (!j) /* we need to add another algorithm */ 228 if (!j) /* we need to add another algorithm */
226 { 229 {
227 alg=X509_ALGOR_new(); 230 if(!(alg=X509_ALGOR_new())
231 || !(alg->parameter = ASN1_TYPE_new())) {
232 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE);
233 return(0);
234 }
228 alg->algorithm=OBJ_nid2obj(nid); 235 alg->algorithm=OBJ_nid2obj(nid);
236 alg->parameter->type = V_ASN1_NULL;
229 sk_X509_ALGOR_push(md_sk,alg); 237 sk_X509_ALGOR_push(md_sk,alg);
230 } 238 }
231 239
@@ -289,6 +297,9 @@ int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
289int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, 297int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
290 EVP_MD *dgst) 298 EVP_MD *dgst)
291 { 299 {
300 char is_dsa;
301 if (pkey->type == EVP_PKEY_DSA) is_dsa = 1;
302 else is_dsa = 0;
292 /* We now need to add another PKCS7_SIGNER_INFO entry */ 303 /* We now need to add another PKCS7_SIGNER_INFO entry */
293 ASN1_INTEGER_set(p7i->version,1); 304 ASN1_INTEGER_set(p7i->version,1);
294 X509_NAME_set(&p7i->issuer_and_serial->issuer, 305 X509_NAME_set(&p7i->issuer_and_serial->issuer,
@@ -296,17 +307,16 @@ int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
296 307
297 /* because ASN1_INTEGER_set is used to set a 'long' we will do 308 /* because ASN1_INTEGER_set is used to set a 'long' we will do
298 * things the ugly way. */ 309 * things the ugly way. */
299 ASN1_INTEGER_free(p7i->issuer_and_serial->serial); 310 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
300 p7i->issuer_and_serial->serial= 311 p7i->issuer_and_serial->serial=
301 ASN1_INTEGER_dup(X509_get_serialNumber(x509)); 312 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509));
302 313
303 /* lets keep the pkey around for a while */ 314 /* lets keep the pkey around for a while */
304 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); 315 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
305 p7i->pkey=pkey; 316 p7i->pkey=pkey;
306 317
307 /* Set the algorithms */ 318 /* Set the algorithms */
308 if (pkey->type == EVP_PKEY_DSA) 319 if (is_dsa) p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1);
309 p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1);
310 else 320 else
311 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst)); 321 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst));
312 322
@@ -320,9 +330,12 @@ int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
320 330
321 if (p7i->digest_enc_alg->parameter != NULL) 331 if (p7i->digest_enc_alg->parameter != NULL)
322 ASN1_TYPE_free(p7i->digest_enc_alg->parameter); 332 ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
323 if ((p7i->digest_enc_alg->parameter=ASN1_TYPE_new()) == NULL) 333 if(is_dsa) p7i->digest_enc_alg->parameter = NULL;
324 goto err; 334 else {
325 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL; 335 if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new()))
336 goto err;
337 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
338 }
326 339
327 return(1); 340 return(1);
328err: 341err:
@@ -397,9 +410,9 @@ int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
397 X509_NAME_set(&p7i->issuer_and_serial->issuer, 410 X509_NAME_set(&p7i->issuer_and_serial->issuer,
398 X509_get_issuer_name(x509)); 411 X509_get_issuer_name(x509));
399 412
400 ASN1_INTEGER_free(p7i->issuer_and_serial->serial); 413 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
401 p7i->issuer_and_serial->serial= 414 p7i->issuer_and_serial->serial=
402 ASN1_INTEGER_dup(X509_get_serialNumber(x509)); 415 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509));
403 416
404 X509_ALGOR_free(p7i->key_enc_algor); 417 X509_ALGOR_free(p7i->key_enc_algor);
405 p7i->key_enc_algor=(X509_ALGOR *)ASN1_dup(i2d_X509_ALGOR, 418 p7i->key_enc_algor=(X509_ALGOR *)ASN1_dup(i2d_X509_ALGOR,
@@ -425,6 +438,7 @@ X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
425int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher) 438int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
426 { 439 {
427 int i; 440 int i;
441 ASN1_OBJECT *objtmp;
428 PKCS7_ENC_CONTENT *ec; 442 PKCS7_ENC_CONTENT *ec;
429 443
430 i=OBJ_obj2nid(p7->type); 444 i=OBJ_obj2nid(p7->type);
@@ -441,7 +455,13 @@ int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
441 return(0); 455 return(0);
442 } 456 }
443 457
444 /* Setup cipher OID */ 458 /* Check cipher OID exists and has data in it*/
459 i = EVP_CIPHER_type(cipher);
460 if(i == NID_undef) {
461 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
462 return(0);
463 }
464 objtmp = OBJ_nid2obj(i);
445 465
446 ec->cipher = cipher; 466 ec->cipher = cipher;
447 return 1; 467 return 1;
diff --git a/src/lib/libcrypto/pkcs7/pk7_mime.c b/src/lib/libcrypto/pkcs7/pk7_mime.c
new file mode 100644
index 0000000000..734643be28
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_mime.c
@@ -0,0 +1,673 @@
1/* pk7_mime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "cryptlib.h"
62#include <openssl/rand.h>
63#include <openssl/x509.h>
64
65/* MIME and related routines */
66
67/* MIME format structures
68 * Note that all are translated to lower case apart from
69 * parameter values. Quotes are stripped off
70 */
71
72typedef struct {
73char *name; /* Name of line e.g. "content-type" */
74char *value; /* Value of line e.g. "text/plain" */
75STACK /* MIME_PARAM */ *params; /* Zero or more parameters */
76} MIME_HEADER;
77
78typedef struct {
79char *param_name; /* Param name e.g. "micalg" */
80char *param_value; /* Param value e.g. "sha1" */
81} MIME_PARAM;
82
83
84static int B64_write_PKCS7(BIO *bio, PKCS7 *p7);
85static PKCS7 *B64_read_PKCS7(BIO *bio);
86static char * strip_ends(char *name);
87static char * strip_start(char *name);
88static char * strip_end(char *name);
89static MIME_HEADER *mime_hdr_new(char *name, char *value);
90static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value);
91static STACK *mime_parse_hdr(BIO *bio);
92static int mime_hdr_cmp(MIME_HEADER **a, MIME_HEADER **b);
93static int mime_param_cmp(MIME_PARAM **a, MIME_PARAM **b);
94static void mime_param_free(MIME_PARAM *param);
95static int mime_bound_check(char *line, int linelen, char *bound, int blen);
96static int multi_split(BIO *bio, char *bound, STACK **ret);
97static int iscrlf(char c);
98static MIME_HEADER *mime_hdr_find(STACK *hdrs, char *name);
99static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name);
100static void mime_hdr_free(MIME_HEADER *hdr);
101
102#define MAX_SMLEN 1024
103#define mime_debug(x) /* x */
104
105
106typedef void (*stkfree)();
107
108/* Base 64 read and write of PKCS#7 structure */
109
110static int B64_write_PKCS7(BIO *bio, PKCS7 *p7)
111{
112 BIO *b64;
113 if(!(b64 = BIO_new(BIO_f_base64()))) {
114 PKCS7err(PKCS7_F_B64_WRITE_PKCS7,ERR_R_MALLOC_FAILURE);
115 return 0;
116 }
117 bio = BIO_push(b64, bio);
118 i2d_PKCS7_bio(bio, p7);
119 BIO_flush(bio);
120 bio = BIO_pop(bio);
121 BIO_free(b64);
122 return 1;
123}
124
125static PKCS7 *B64_read_PKCS7(BIO *bio)
126{
127 BIO *b64;
128 PKCS7 *p7;
129 if(!(b64 = BIO_new(BIO_f_base64()))) {
130 PKCS7err(PKCS7_F_B64_READ_PKCS7,ERR_R_MALLOC_FAILURE);
131 return 0;
132 }
133 bio = BIO_push(b64, bio);
134 if(!(p7 = d2i_PKCS7_bio(bio, NULL)))
135 PKCS7err(PKCS7_F_B64_READ_PKCS7,PKCS7_R_DECODE_ERROR);
136 BIO_flush(bio);
137 bio = BIO_pop(bio);
138 BIO_free(b64);
139 return p7;
140}
141
142/* SMIME sender */
143
144int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
145{
146 char linebuf[MAX_SMLEN];
147 char bound[33], c;
148 int i;
149 if((flags & PKCS7_DETACHED) && data) {
150 /* We want multipart/signed */
151 /* Generate a random boundary */
152 RAND_pseudo_bytes((unsigned char *)bound, 32);
153 for(i = 0; i < 32; i++) {
154 c = bound[i] & 0xf;
155 if(c < 10) c += '0';
156 else c += 'A' - 10;
157 bound[i] = c;
158 }
159 bound[32] = 0;
160 BIO_printf(bio, "MIME-Version: 1.0\n");
161 BIO_printf(bio, "Content-Type: multipart/signed ; ");
162 BIO_printf(bio, "protocol=\"application/x-pkcs7-signature\" ; ");
163 BIO_printf(bio, "micalg=sha1 ; boundary=\"----%s\"\n\n", bound);
164 BIO_printf(bio, "This is an S/MIME signed message\n\n");
165 /* Now write out the first part */
166 BIO_printf(bio, "------%s\r\n", bound);
167 if(flags & PKCS7_TEXT) BIO_printf(bio, "Content-Type: text/plain\n\n");
168 while((i = BIO_read(data, linebuf, MAX_SMLEN)) > 0)
169 BIO_write(bio, linebuf, i);
170 BIO_printf(bio, "\n------%s\n", bound);
171
172 /* Headers for signature */
173
174 BIO_printf(bio, "Content-Type: application/x-pkcs7-signature; name=\"smime.p7s\"\n");
175 BIO_printf(bio, "Content-Transfer-Encoding: base64\n");
176 BIO_printf(bio, "Content-Disposition: attachment; filename=\"smime.p7s\"\n\n");
177 B64_write_PKCS7(bio, p7);
178 BIO_printf(bio,"\n------%s--\n\n", bound);
179 return 1;
180 }
181 /* MIME headers */
182 BIO_printf(bio, "MIME-Version: 1.0\n");
183 BIO_printf(bio, "Content-Disposition: attachment; filename=\"smime.p7m\"\n");
184 BIO_printf(bio, "Content-Type: application/x-pkcs7-mime; name=\"smime.p7m\"\n");
185 BIO_printf(bio, "Content-Transfer-Encoding: base64\n\n");
186 B64_write_PKCS7(bio, p7);
187 BIO_printf(bio, "\n");
188 return 1;
189}
190
191/* SMIME reader: handle multipart/signed and opaque signing.
192 * in multipart case the content is placed in a memory BIO
193 * pointed to by "bcont". In opaque this is set to NULL
194 */
195
196PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
197{
198 BIO *p7in;
199 STACK *headers = NULL;
200 STACK *parts = NULL;
201 MIME_HEADER *hdr;
202 MIME_PARAM *prm;
203 PKCS7 *p7;
204 int ret;
205
206 if(bcont) *bcont = NULL;
207
208 if (!(headers = mime_parse_hdr(bio))) {
209 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_PARSE_ERROR);
210 return NULL;
211 }
212
213 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
214 sk_pop_free(headers, mime_hdr_free);
215 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_CONTENT_TYPE);
216 return NULL;
217 }
218
219 /* Handle multipart/signed */
220
221 if(!strcmp(hdr->value, "multipart/signed")) {
222 /* Split into two parts */
223 prm = mime_param_find(hdr, "boundary");
224 if(!prm || !prm->param_value) {
225 sk_pop_free(headers, mime_hdr_free);
226 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BOUNDARY);
227 return NULL;
228 }
229 ret = multi_split(bio, prm->param_value, &parts);
230 sk_pop_free(headers, mime_hdr_free);
231 if(!ret || (sk_num(parts) != 2) ) {
232 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BODY_FAILURE);
233 sk_pop_free(parts, (stkfree)BIO_free);
234 return NULL;
235 }
236
237 /* Parse the signature piece */
238 p7in = (BIO *)sk_value(parts, 1);
239
240 if (!(headers = mime_parse_hdr(p7in))) {
241 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_SIG_PARSE_ERROR);
242 sk_pop_free(parts, (stkfree)BIO_free);
243 return NULL;
244 }
245
246 /* Get content type */
247
248 if(!(hdr = mime_hdr_find(headers, "content-type")) ||
249 !hdr->value) {
250 sk_pop_free(headers, mime_hdr_free);
251 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_SIG_CONTENT_TYPE);
252 return NULL;
253 }
254
255 if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
256 strcmp(hdr->value, "application/pkcs7-signature")) {
257 sk_pop_free(headers, mime_hdr_free);
258 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_SIG_INVALID_MIME_TYPE);
259 ERR_add_error_data(2, "type: ", hdr->value);
260 sk_pop_free(parts, (stkfree)BIO_free);
261 return NULL;
262 }
263 sk_pop_free(headers, mime_hdr_free);
264 /* Read in PKCS#7 */
265 if(!(p7 = B64_read_PKCS7(p7in))) {
266 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_PKCS7_SIG_PARSE_ERROR);
267 sk_pop_free(parts, (stkfree)BIO_free);
268 return NULL;
269 }
270
271 if(bcont) {
272 *bcont = (BIO *)sk_value(parts, 0);
273 BIO_free(p7in);
274 sk_free(parts);
275 } else sk_pop_free(parts, (stkfree)BIO_free);
276 return p7;
277 }
278
279 /* OK, if not multipart/signed try opaque signature */
280
281 if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
282 strcmp (hdr->value, "application/pkcs7-mime")) {
283 PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_INVALID_MIME_TYPE);
284 ERR_add_error_data(2, "type: ", hdr->value);
285 sk_pop_free(headers, mime_hdr_free);
286 return NULL;
287 }
288
289 sk_pop_free(headers, mime_hdr_free);
290
291 if(!(p7 = B64_read_PKCS7(bio))) {
292 PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_PKCS7_PARSE_ERROR);
293 return NULL;
294 }
295 return p7;
296
297}
298
299/* Copy text from one BIO to another making the output CRLF at EOL */
300int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
301{
302 char eol;
303 int len;
304 char linebuf[MAX_SMLEN];
305 if(flags & PKCS7_BINARY) {
306 while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
307 BIO_write(out, linebuf, len);
308 return 1;
309 }
310 if(flags & PKCS7_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
311 while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
312 eol = 0;
313 while(iscrlf(linebuf[len - 1])) {
314 len--;
315 eol = 1;
316 }
317 BIO_write(out, linebuf, len);
318 if(eol) BIO_write(out, "\r\n", 2);
319 }
320 return 1;
321}
322
323/* Strip off headers if they are text/plain */
324int SMIME_text(BIO *in, BIO *out)
325{
326 char iobuf[4096];
327 int len;
328 STACK *headers;
329 MIME_HEADER *hdr;
330 if (!(headers = mime_parse_hdr(in))) {
331 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_PARSE_ERROR);
332 return 0;
333 }
334 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
335 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_NO_CONTENT_TYPE);
336 sk_pop_free(headers, mime_hdr_free);
337 return 0;
338 }
339 if (strcmp (hdr->value, "text/plain")) {
340 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_INVALID_MIME_TYPE);
341 ERR_add_error_data(2, "type: ", hdr->value);
342 sk_pop_free(headers, mime_hdr_free);
343 return 0;
344 }
345 sk_pop_free(headers, mime_hdr_free);
346 while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
347 BIO_write(out, iobuf, len);
348 return 1;
349}
350
351/* Split a multipart/XXX message body into component parts: result is
352 * canonical parts in a STACK of bios
353 */
354
355static int multi_split(BIO *bio, char *bound, STACK **ret)
356{
357 char linebuf[MAX_SMLEN];
358 int len, blen;
359 BIO *bpart = NULL;
360 STACK *parts;
361 char state, part, first;
362 blen = strlen(bound);
363 part = 0;
364 state = 0;
365 first = 1;
366 parts = sk_new(NULL);
367 *ret = parts;
368 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
369 state = mime_bound_check(linebuf, len, bound, blen);
370 if(state == 1) {
371 first = 1;
372 part++;
373 } else if(state == 2) {
374 sk_push(parts, (char *)bpart);
375 return 1;
376 } else if(part) {
377 if(first) {
378 first = 0;
379 if(bpart) sk_push(parts, (char *)bpart);
380 bpart = BIO_new(BIO_s_mem());
381
382 } else BIO_write(bpart, "\r\n", 2);
383 /* Strip CR+LF from linebuf */
384 while(iscrlf(linebuf[len - 1])) len--;
385 BIO_write(bpart, linebuf, len);
386 }
387 }
388 return 0;
389}
390
391static int iscrlf(char c)
392{
393 if(c == '\r' || c == '\n') return 1;
394 return 0;
395}
396
397/* This is the big one: parse MIME header lines up to message body */
398
399#define MIME_INVALID 0
400#define MIME_START 1
401#define MIME_TYPE 2
402#define MIME_NAME 3
403#define MIME_VALUE 4
404#define MIME_QUOTE 5
405#define MIME_COMMENT 6
406
407
408static STACK *mime_parse_hdr(BIO *bio)
409{
410 char *p, *q, c;
411 char *ntmp;
412 char linebuf[MAX_SMLEN];
413 MIME_HEADER *mhdr = NULL;
414 STACK *headers;
415 int len, state, save_state = 0;
416 headers = sk_new(mime_hdr_cmp);
417 while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
418 /* If whitespace at line start then continuation line */
419 if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
420 else state = MIME_START;
421 ntmp = NULL;
422 /* Go through all characters */
423 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
424
425 /* State machine to handle MIME headers
426 * if this looks horrible that's because it *is*
427 */
428
429 switch(state) {
430 case MIME_START:
431 if(c == ':') {
432 state = MIME_TYPE;
433 *p = 0;
434 ntmp = strip_ends(q);
435 q = p + 1;
436 }
437 break;
438
439 case MIME_TYPE:
440 if(c == ';') {
441 mime_debug("Found End Value\n");
442 *p = 0;
443 mhdr = mime_hdr_new(ntmp, strip_ends(q));
444 sk_push(headers, (char *)mhdr);
445 ntmp = NULL;
446 q = p + 1;
447 state = MIME_NAME;
448 } else if(c == '(') {
449 save_state = state;
450 state = MIME_COMMENT;
451 }
452 break;
453
454 case MIME_COMMENT:
455 if(c == ')') {
456 state = save_state;
457 }
458 break;
459
460 case MIME_NAME:
461 if(c == '=') {
462 state = MIME_VALUE;
463 *p = 0;
464 ntmp = strip_ends(q);
465 q = p + 1;
466 }
467 break ;
468
469 case MIME_VALUE:
470 if(c == ';') {
471 state = MIME_NAME;
472 *p = 0;
473 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
474 ntmp = NULL;
475 q = p + 1;
476 } else if (c == '"') {
477 mime_debug("Found Quote\n");
478 state = MIME_QUOTE;
479 } else if(c == '(') {
480 save_state = state;
481 state = MIME_COMMENT;
482 }
483 break;
484
485 case MIME_QUOTE:
486 if(c == '"') {
487 mime_debug("Found Match Quote\n");
488 state = MIME_VALUE;
489 }
490 break;
491 }
492 }
493
494 if(state == MIME_TYPE) {
495 mhdr = mime_hdr_new(ntmp, strip_ends(q));
496 sk_push(headers, (char *)mhdr);
497 } else if(state == MIME_VALUE)
498 mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
499 if(p == linebuf) break; /* Blank line means end of headers */
500}
501
502return headers;
503
504}
505
506static char *strip_ends(char *name)
507{
508 return strip_end(strip_start(name));
509}
510
511/* Strip a parameter of whitespace from start of param */
512static char *strip_start(char *name)
513{
514 char *p, c;
515 /* Look for first non white space or quote */
516 for(p = name; (c = *p) ;p++) {
517 if(c == '"') {
518 /* Next char is start of string if non null */
519 if(p[1]) return p + 1;
520 /* Else null string */
521 return NULL;
522 }
523 if(!isspace((unsigned char)c)) return p;
524 }
525 return NULL;
526}
527
528/* As above but strip from end of string : maybe should handle brackets? */
529static char *strip_end(char *name)
530{
531 char *p, c;
532 if(!name) return NULL;
533 /* Look for first non white space or quote */
534 for(p = name + strlen(name) - 1; p >= name ;p--) {
535 c = *p;
536 if(c == '"') {
537 if(p - 1 == name) return NULL;
538 *p = 0;
539 return name;
540 }
541 if(isspace((unsigned char)c)) *p = 0;
542 else return name;
543 }
544 return NULL;
545}
546
547static MIME_HEADER *mime_hdr_new(char *name, char *value)
548{
549 MIME_HEADER *mhdr;
550 char *tmpname, *tmpval, *p;
551 int c;
552 if(name) {
553 if(!(tmpname = BUF_strdup(name))) return NULL;
554 for(p = tmpname ; *p; p++) {
555 c = *p;
556 if(isupper(c)) {
557 c = tolower(c);
558 *p = c;
559 }
560 }
561 } else tmpname = NULL;
562 if(value) {
563 if(!(tmpval = BUF_strdup(value))) return NULL;
564 for(p = tmpval ; *p; p++) {
565 c = *p;
566 if(isupper(c)) {
567 c = tolower(c);
568 *p = c;
569 }
570 }
571 } else tmpval = NULL;
572 mhdr = (MIME_HEADER *) Malloc(sizeof(MIME_HEADER));
573 if(!mhdr) return NULL;
574 mhdr->name = tmpname;
575 mhdr->value = tmpval;
576 if(!(mhdr->params = sk_new(mime_param_cmp))) return NULL;
577 return mhdr;
578}
579
580static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
581{
582 char *tmpname, *tmpval, *p;
583 int c;
584 MIME_PARAM *mparam;
585 if(name) {
586 tmpname = BUF_strdup(name);
587 if(!tmpname) return 0;
588 for(p = tmpname ; *p; p++) {
589 c = *p;
590 if(isupper(c)) {
591 c = tolower(c);
592 *p = c;
593 }
594 }
595 } else tmpname = NULL;
596 if(value) {
597 tmpval = BUF_strdup(value);
598 if(!tmpval) return 0;
599 } else tmpval = NULL;
600 /* Parameter values are case sensitive so leave as is */
601 mparam = (MIME_PARAM *) Malloc(sizeof(MIME_PARAM));
602 if(!mparam) return 0;
603 mparam->param_name = tmpname;
604 mparam->param_value = tmpval;
605 sk_push(mhdr->params, (char *)mparam);
606 return 1;
607}
608
609static int mime_hdr_cmp(MIME_HEADER **a, MIME_HEADER **b)
610{
611 return(strcmp((*a)->name, (*b)->name));
612}
613
614static int mime_param_cmp(MIME_PARAM **a, MIME_PARAM **b)
615{
616 return(strcmp((*a)->param_name, (*b)->param_name));
617}
618
619/* Find a header with a given name (if possible) */
620
621static MIME_HEADER *mime_hdr_find(STACK *hdrs, char *name)
622{
623 MIME_HEADER htmp;
624 int idx;
625 htmp.name = name;
626 idx = sk_find(hdrs, (char *)&htmp);
627 if(idx < 0) return NULL;
628 return (MIME_HEADER *)sk_value(hdrs, idx);
629}
630
631static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
632{
633 MIME_PARAM param;
634 int idx;
635 param.param_name = name;
636 idx = sk_find(hdr->params, (char *)&param);
637 if(idx < 0) return NULL;
638 return (MIME_PARAM *)sk_value(hdr->params, idx);
639}
640
641static void mime_hdr_free(MIME_HEADER *hdr)
642{
643 if(hdr->name) Free(hdr->name);
644 if(hdr->value) Free(hdr->value);
645 if(hdr->params) sk_pop_free(hdr->params, mime_param_free);
646 Free(hdr);
647}
648
649static void mime_param_free(MIME_PARAM *param)
650{
651 if(param->param_name) Free(param->param_name);
652 if(param->param_value) Free(param->param_value);
653 Free(param);
654}
655
656/* Check for a multipart boundary. Returns:
657 * 0 : no boundary
658 * 1 : part boundary
659 * 2 : final boundary
660 */
661static int mime_bound_check(char *line, int linelen, char *bound, int blen)
662{
663 if(linelen == -1) linelen = strlen(line);
664 if(blen == -1) blen = strlen(bound);
665 /* Quickly eliminate if line length too short */
666 if(blen + 2 > linelen) return 0;
667 /* Check for part boundary */
668 if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
669 if(!strncmp(line + blen + 2, "--", 2)) return 2;
670 else return 1;
671 }
672 return 0;
673}
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
new file mode 100644
index 0000000000..b41f42ed04
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_smime.c
@@ -0,0 +1,427 @@
1/* pk7_smime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Simple PKCS#7 processing functions */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
67 BIO *data, int flags)
68{
69 PKCS7 *p7;
70 PKCS7_SIGNER_INFO *si;
71 BIO *p7bio;
72 STACK *smcap;
73 int i;
74
75 if(!X509_check_private_key(signcert, pkey)) {
76 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
77 return NULL;
78 }
79
80 if(!(p7 = PKCS7_new())) {
81 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
82 return NULL;
83 }
84
85 PKCS7_set_type(p7, NID_pkcs7_signed);
86
87 PKCS7_content_new(p7, NID_pkcs7_data);
88
89 if (!(si = PKCS7_add_signature(p7,signcert,pkey,EVP_sha1()))) {
90 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
91 return NULL;
92 }
93
94 if(!(flags & PKCS7_NOCERTS)) {
95 PKCS7_add_certificate(p7, signcert);
96 if(certs) for(i = 0; i < sk_X509_num(certs); i++)
97 PKCS7_add_certificate(p7, sk_X509_value(certs, i));
98 }
99
100 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
101 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104
105
106 SMIME_crlf_copy(data, p7bio, flags);
107
108 if(!(flags & PKCS7_NOATTR)) {
109 PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
110 V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data));
111 /* Add SMIMECapabilities */
112 if(!(smcap = sk_new(NULL))) {
113 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
114 return NULL;
115 }
116#ifndef NO_DES
117 PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1);
118#endif
119#ifndef NO_RC2
120 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128);
121 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64);
122#endif
123#ifndef NO_DES
124 PKCS7_simple_smimecap (smcap, NID_des_cbc, -1);
125#endif
126#ifndef NO_RC2
127 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40);
128#endif
129 PKCS7_add_attrib_smimecap (si, smcap);
130 sk_pop_free(smcap, X509_ALGOR_free);
131 }
132
133 if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1);
134
135 if (!PKCS7_dataFinal(p7,p7bio)) {
136 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN);
137 return NULL;
138 }
139
140 BIO_free_all(p7bio);
141 return p7;
142}
143
144int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
145 BIO *indata, BIO *out, int flags)
146{
147 STACK_OF(X509) *signers;
148 X509 *signer;
149 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
150 PKCS7_SIGNER_INFO *si;
151 X509_STORE_CTX cert_ctx;
152 char buf[4096];
153 int i, j=0;
154 BIO *p7bio;
155 BIO *tmpout;
156
157 if(!p7) {
158 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER);
159 return 0;
160 }
161
162 if(!PKCS7_type_is_signed(p7)) {
163 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_WRONG_CONTENT_TYPE);
164 return 0;
165 }
166
167 /* Check for no data and no content: no data to verify signature */
168 if(PKCS7_get_detached(p7) && !indata) {
169 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_CONTENT);
170 return 0;
171 }
172
173 /* Check for data and content: two sets of data */
174 if(!PKCS7_get_detached(p7) && indata) {
175 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CONTENT_AND_DATA_PRESENT);
176 return 0;
177 }
178
179 sinfos = PKCS7_get_signer_info(p7);
180
181 if(!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) {
182 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_SIGNATURES_ON_DATA);
183 return 0;
184 }
185
186
187 signers = PKCS7_get0_signers(p7, certs, flags);
188
189 if(!signers) return 0;
190
191 /* Now verify the certificates */
192
193 if (!(flags & PKCS7_NOVERIFY)) for (i = 0; i < sk_X509_num(signers); i++) {
194 signer = sk_X509_value (signers, i);
195 if (!(flags & PKCS7_NOCHAIN)) {
196 X509_STORE_CTX_init(&cert_ctx, store, signer,
197 p7->d.sign->cert);
198 X509_STORE_CTX_set_purpose(&cert_ctx,
199 X509_PURPOSE_SMIME_SIGN);
200 } else X509_STORE_CTX_init (&cert_ctx, store, signer, NULL);
201 i = X509_verify_cert(&cert_ctx);
202 if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx);
203 X509_STORE_CTX_cleanup(&cert_ctx);
204 if (i <= 0) {
205 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CERTIFICATE_VERIFY_ERROR);
206 ERR_add_error_data(2, "Verify error:",
207 X509_verify_cert_error_string(j));
208 sk_X509_free(signers);
209 return 0;
210 }
211 /* Check for revocation status here */
212 }
213
214 p7bio=PKCS7_dataInit(p7,indata);
215
216 if(flags & PKCS7_TEXT) {
217 if(!(tmpout = BIO_new(BIO_s_mem()))) {
218 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
219 goto err;
220 }
221 } else tmpout = out;
222
223 /* We now have to 'read' from p7bio to calculate digests etc. */
224 for (;;)
225 {
226 i=BIO_read(p7bio,buf,sizeof(buf));
227 if (i <= 0) break;
228 if (tmpout) BIO_write(tmpout, buf, i);
229 }
230
231 if(flags & PKCS7_TEXT) {
232 if(!SMIME_text(tmpout, out)) {
233 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SMIME_TEXT_ERROR);
234 BIO_free(tmpout);
235 goto err;
236 }
237 BIO_free(tmpout);
238 }
239
240 /* Now Verify All Signatures */
241 if (!(flags & PKCS7_NOSIGS))
242 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
243 {
244 si=sk_PKCS7_SIGNER_INFO_value(sinfos,i);
245 signer = sk_X509_value (signers, i);
246 j=PKCS7_signatureVerify(p7bio,p7,si, signer);
247 if (j <= 0) {
248 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SIGNATURE_FAILURE);
249 goto err;
250 }
251 }
252
253 sk_X509_free(signers);
254 if(indata) BIO_pop(p7bio);
255 BIO_free_all(p7bio);
256
257 return 1;
258
259 err:
260
261 sk_X509_free(signers);
262 BIO_free(p7bio);
263
264 return 0;
265}
266
267STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
268{
269 STACK_OF(X509) *signers;
270 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
271 PKCS7_SIGNER_INFO *si;
272 PKCS7_ISSUER_AND_SERIAL *ias;
273 X509 *signer;
274 int i;
275
276 if(!p7) {
277 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_INVALID_NULL_POINTER);
278 return NULL;
279 }
280
281 if(!PKCS7_type_is_signed(p7)) {
282 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE);
283 return NULL;
284 }
285 if(!(signers = sk_X509_new(NULL))) {
286 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE);
287 return NULL;
288 }
289
290 /* Collect all the signers together */
291
292 sinfos = PKCS7_get_signer_info(p7);
293
294 if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
295 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
296 return 0;
297 }
298
299 for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
300 {
301 si = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
302 ias = si->issuer_and_serial;
303 signer = NULL;
304 /* If any certificates passed they take priority */
305 if (certs) signer = X509_find_by_issuer_and_serial (certs,
306 ias->issuer, ias->serial);
307 if (!signer && !(flags & PKCS7_NOINTERN)
308 && p7->d.sign->cert) signer =
309 X509_find_by_issuer_and_serial (p7->d.sign->cert,
310 ias->issuer, ias->serial);
311 if (!signer) {
312 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
313 sk_X509_free(signers);
314 return 0;
315 }
316
317 sk_X509_push(signers, signer);
318 }
319 return signers;
320}
321
322
323/* Build a complete PKCS#7 enveloped data */
324
325PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
326 int flags)
327{
328 PKCS7 *p7;
329 BIO *p7bio = NULL;
330 int i;
331 X509 *x509;
332 if(!(p7 = PKCS7_new())) {
333 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
334 return NULL;
335 }
336
337 PKCS7_set_type(p7, NID_pkcs7_enveloped);
338 if(!PKCS7_set_cipher(p7, cipher)) {
339 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER);
340 goto err;
341 }
342
343 for(i = 0; i < sk_X509_num(certs); i++) {
344 x509 = sk_X509_value(certs, i);
345 if(!PKCS7_add_recipient(p7, x509)) {
346 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,
347 PKCS7_R_ERROR_ADDING_RECIPIENT);
348 goto err;
349 }
350 }
351
352 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
353 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
354 goto err;
355 }
356
357 SMIME_crlf_copy(in, p7bio, flags);
358
359 BIO_flush(p7bio);
360
361 if (!PKCS7_dataFinal(p7,p7bio)) {
362 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR);
363 goto err;
364 }
365 BIO_free_all(p7bio);
366
367 return p7;
368
369 err:
370
371 BIO_free(p7bio);
372 PKCS7_free(p7);
373 return NULL;
374
375}
376
377int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
378{
379 BIO *tmpmem;
380 int ret, i;
381 char buf[4096];
382
383 if(!p7) {
384 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_INVALID_NULL_POINTER);
385 return 0;
386 }
387
388 if(!PKCS7_type_is_enveloped(p7)) {
389 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_WRONG_CONTENT_TYPE);
390 return 0;
391 }
392
393 if(!X509_check_private_key(cert, pkey)) {
394 PKCS7err(PKCS7_F_PKCS7_DECRYPT,
395 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
396 return 0;
397 }
398
399 if(!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) {
400 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR);
401 return 0;
402 }
403
404 if (flags & PKCS7_TEXT) {
405 BIO *tmpbuf, *bread;
406 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
407 if(!(tmpbuf = BIO_new(BIO_f_buffer()))) {
408 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
409 return 0;
410 }
411 if(!(bread = BIO_push(tmpbuf, tmpmem))) {
412 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
413 return 0;
414 }
415 ret = SMIME_text(bread, data);
416 BIO_free_all(bread);
417 return ret;
418 } else {
419 for(;;) {
420 i = BIO_read(tmpmem, buf, sizeof(buf));
421 if(i <= 0) break;
422 BIO_write(data, buf, i);
423 }
424 BIO_free_all(tmpmem);
425 return 1;
426 }
427}
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h
index c42bd6d391..3ec725d226 100644
--- a/src/lib/libcrypto/pkcs7/pkcs7.h
+++ b/src/lib/libcrypto/pkcs7/pkcs7.h
@@ -71,8 +71,9 @@ extern "C" {
71#endif 71#endif
72 72
73#ifdef WIN32 73#ifdef WIN32
74/* Under Win32 this is defined in wincrypt.h */ 74/* Under Win32 thes are defined in wincrypt.h */
75#undef PKCS7_ISSUER_AND_SERIAL 75#undef PKCS7_ISSUER_AND_SERIAL
76#undef PKCS7_SIGNER_INFO
76#endif 77#endif
77 78
78/* 79/*
@@ -219,6 +220,7 @@ typedef struct pkcs7_st
219#define PKCS7_get_attributes(si) ((si)->unauth_attr) 220#define PKCS7_get_attributes(si) ((si)->unauth_attr)
220 221
221#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) 222#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
223#define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped)
222#define PKCS7_type_is_signedAndEnveloped(a) \ 224#define PKCS7_type_is_signedAndEnveloped(a) \
223 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) 225 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
224#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) 226#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
@@ -236,6 +238,29 @@ typedef struct pkcs7_st
236#endif 238#endif
237#endif 239#endif
238 240
241/* S/MIME related flags */
242
243#define PKCS7_TEXT 0x1
244#define PKCS7_NOCERTS 0x2
245#define PKCS7_NOSIGS 0x4
246#define PKCS7_NOCHAIN 0x8
247#define PKCS7_NOINTERN 0x10
248#define PKCS7_NOVERIFY 0x20
249#define PKCS7_DETACHED 0x40
250#define PKCS7_BINARY 0x80
251#define PKCS7_NOATTR 0x100
252
253/* Flags: for compatibility with older code */
254
255#define SMIME_TEXT PKCS7_TEXT
256#define SMIME_NOCERTS PKCS7_NOCERTS
257#define SMIME_NOSIGS PKCS7_NOSIGS
258#define SMIME_NOCHAIN PKCS7_NOCHAIN
259#define SMIME_NOINTERN PKCS7_NOINTERN
260#define SMIME_NOVERIFY PKCS7_NOVERIFY
261#define SMIME_DETACHED PKCS7_DETACHED
262#define SMIME_BINARY PKCS7_BINARY
263#define SMIME_NOATTR PKCS7_NOATTR
239 264
240PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void ); 265PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void );
241void PKCS7_ISSUER_AND_SERIAL_free( 266void PKCS7_ISSUER_AND_SERIAL_free(
@@ -247,7 +272,7 @@ PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(
247 unsigned char **pp, long length); 272 unsigned char **pp, long length);
248 273
249#ifndef SSLEAY_MACROS 274#ifndef SSLEAY_MACROS
250int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,EVP_MD *type, 275int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type,
251 unsigned char *md,unsigned int *len); 276 unsigned char *md,unsigned int *len);
252#ifndef NO_FP_API 277#ifndef NO_FP_API
253PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7); 278PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
@@ -368,6 +393,23 @@ int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
368int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk); 393int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
369 394
370 395
396PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
397 BIO *data, int flags);
398int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
399 BIO *indata, BIO *out, int flags);
400STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
401PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
402 int flags);
403int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
404
405int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK *cap);
406STACK *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
407int PKCS7_simple_smimecap(STACK *sk, int nid, int arg);
408
409int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
410PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
411int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
412int SMIME_text(BIO *in, BIO *out);
371 413
372/* BEGIN ERROR CODES */ 414/* BEGIN ERROR CODES */
373/* The following lines are auto generated by the script mkerr.pl. Any changes 415/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -377,6 +419,9 @@ int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
377/* Error codes for the PKCS7 functions. */ 419/* Error codes for the PKCS7 functions. */
378 420
379/* Function codes. */ 421/* Function codes. */
422#define PKCS7_F_B64_READ_PKCS7 120
423#define PKCS7_F_B64_WRITE_PKCS7 121
424#define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118
380#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100 425#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
381#define PKCS7_F_PKCS7_ADD_CRL 101 426#define PKCS7_F_PKCS7_ADD_CRL 101
382#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 427#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
@@ -386,20 +431,56 @@ int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
386#define PKCS7_F_PKCS7_DATAINIT 105 431#define PKCS7_F_PKCS7_DATAINIT 105
387#define PKCS7_F_PKCS7_DATASIGN 106 432#define PKCS7_F_PKCS7_DATASIGN 106
388#define PKCS7_F_PKCS7_DATAVERIFY 107 433#define PKCS7_F_PKCS7_DATAVERIFY 107
434#define PKCS7_F_PKCS7_DECRYPT 114
435#define PKCS7_F_PKCS7_ENCRYPT 115
436#define PKCS7_F_PKCS7_GET0_SIGNERS 124
389#define PKCS7_F_PKCS7_SET_CIPHER 108 437#define PKCS7_F_PKCS7_SET_CIPHER 108
390#define PKCS7_F_PKCS7_SET_CONTENT 109 438#define PKCS7_F_PKCS7_SET_CONTENT 109
391#define PKCS7_F_PKCS7_SET_TYPE 110 439#define PKCS7_F_PKCS7_SET_TYPE 110
440#define PKCS7_F_PKCS7_SIGN 116
392#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113 441#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
442#define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119
443#define PKCS7_F_PKCS7_VERIFY 117
444#define PKCS7_F_SMIME_READ_PKCS7 122
445#define PKCS7_F_SMIME_TEXT 123
393 446
394/* Reason codes. */ 447/* Reason codes. */
448#define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117
449#define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144
395#define PKCS7_R_CIPHER_NOT_INITIALIZED 116 450#define PKCS7_R_CIPHER_NOT_INITIALIZED 116
451#define PKCS7_R_CONTENT_AND_DATA_PRESENT 118
452#define PKCS7_R_DECODE_ERROR 130
396#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100 453#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100
454#define PKCS7_R_DECRYPT_ERROR 119
397#define PKCS7_R_DIGEST_FAILURE 101 455#define PKCS7_R_DIGEST_FAILURE 101
456#define PKCS7_R_ERROR_ADDING_RECIPIENT 120
457#define PKCS7_R_ERROR_SETTING_CIPHER 121
398#define PKCS7_R_INTERNAL_ERROR 102 458#define PKCS7_R_INTERNAL_ERROR 102
459#define PKCS7_R_INVALID_MIME_TYPE 131
460#define PKCS7_R_INVALID_NULL_POINTER 143
461#define PKCS7_R_MIME_NO_CONTENT_TYPE 132
462#define PKCS7_R_MIME_PARSE_ERROR 133
463#define PKCS7_R_MIME_SIG_PARSE_ERROR 134
399#define PKCS7_R_MISSING_CERIPEND_INFO 103 464#define PKCS7_R_MISSING_CERIPEND_INFO 103
465#define PKCS7_R_NO_CONTENT 122
466#define PKCS7_R_NO_CONTENT_TYPE 135
467#define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136
468#define PKCS7_R_NO_MULTIPART_BOUNDARY 137
400#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115 469#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
470#define PKCS7_R_NO_SIGNATURES_ON_DATA 123
471#define PKCS7_R_NO_SIGNERS 142
472#define PKCS7_R_NO_SIG_CONTENT_TYPE 138
401#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104 473#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
474#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124
475#define PKCS7_R_PKCS7_DATAFINAL_ERROR 125
476#define PKCS7_R_PKCS7_DATASIGN 126
477#define PKCS7_R_PKCS7_PARSE_ERROR 139
478#define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140
479#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127
402#define PKCS7_R_SIGNATURE_FAILURE 105 480#define PKCS7_R_SIGNATURE_FAILURE 105
481#define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128
482#define PKCS7_R_SIG_INVALID_MIME_TYPE 141
483#define PKCS7_R_SMIME_TEXT_ERROR 129
403#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106 484#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106
404#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107 485#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107
405#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108 486#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c
index 82be3c2ca1..813a8af9ed 100644
--- a/src/lib/libcrypto/pkcs7/pkcs7err.c
+++ b/src/lib/libcrypto/pkcs7/pkcs7err.c
@@ -65,6 +65,9 @@
65#ifndef NO_ERR 65#ifndef NO_ERR
66static ERR_STRING_DATA PKCS7_str_functs[]= 66static ERR_STRING_DATA PKCS7_str_functs[]=
67 { 67 {
68{ERR_PACK(0,PKCS7_F_B64_READ_PKCS7,0), "B64_READ_PKCS7"},
69{ERR_PACK(0,PKCS7_F_B64_WRITE_PKCS7,0), "B64_WRITE_PKCS7"},
70{ERR_PACK(0,PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,0), "PKCS7_add_attrib_smimecap"},
68{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CERTIFICATE,0), "PKCS7_add_certificate"}, 71{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CERTIFICATE,0), "PKCS7_add_certificate"},
69{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CRL,0), "PKCS7_add_crl"}, 72{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CRL,0), "PKCS7_add_crl"},
70{ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"}, 73{ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"},
@@ -74,23 +77,59 @@ static ERR_STRING_DATA PKCS7_str_functs[]=
74{ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"}, 77{ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"},
75{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_DATASIGN"}, 78{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_DATASIGN"},
76{ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"}, 79{ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"},
80{ERR_PACK(0,PKCS7_F_PKCS7_DECRYPT,0), "PKCS7_decrypt"},
81{ERR_PACK(0,PKCS7_F_PKCS7_ENCRYPT,0), "PKCS7_encrypt"},
82{ERR_PACK(0,PKCS7_F_PKCS7_GET0_SIGNERS,0), "PKCS7_get0_signers"},
77{ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"}, 83{ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"},
78{ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"}, 84{ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"},
79{ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"}, 85{ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"},
86{ERR_PACK(0,PKCS7_F_PKCS7_SIGN,0), "PKCS7_sign"},
80{ERR_PACK(0,PKCS7_F_PKCS7_SIGNATUREVERIFY,0), "PKCS7_signatureVerify"}, 87{ERR_PACK(0,PKCS7_F_PKCS7_SIGNATUREVERIFY,0), "PKCS7_signatureVerify"},
88{ERR_PACK(0,PKCS7_F_PKCS7_SIMPLE_SMIMECAP,0), "PKCS7_simple_smimecap"},
89{ERR_PACK(0,PKCS7_F_PKCS7_VERIFY,0), "PKCS7_verify"},
90{ERR_PACK(0,PKCS7_F_SMIME_READ_PKCS7,0), "SMIME_read_PKCS7"},
91{ERR_PACK(0,PKCS7_F_SMIME_TEXT,0), "SMIME_text"},
81{0,NULL} 92{0,NULL}
82 }; 93 };
83 94
84static ERR_STRING_DATA PKCS7_str_reasons[]= 95static ERR_STRING_DATA PKCS7_str_reasons[]=
85 { 96 {
97{PKCS7_R_CERTIFICATE_VERIFY_ERROR ,"certificate verify error"},
98{PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"},
86{PKCS7_R_CIPHER_NOT_INITIALIZED ,"cipher not initialized"}, 99{PKCS7_R_CIPHER_NOT_INITIALIZED ,"cipher not initialized"},
100{PKCS7_R_CONTENT_AND_DATA_PRESENT ,"content and data present"},
101{PKCS7_R_DECODE_ERROR ,"decode error"},
87{PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH ,"decrypted key is wrong length"}, 102{PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH ,"decrypted key is wrong length"},
103{PKCS7_R_DECRYPT_ERROR ,"decrypt error"},
88{PKCS7_R_DIGEST_FAILURE ,"digest failure"}, 104{PKCS7_R_DIGEST_FAILURE ,"digest failure"},
105{PKCS7_R_ERROR_ADDING_RECIPIENT ,"error adding recipient"},
106{PKCS7_R_ERROR_SETTING_CIPHER ,"error setting cipher"},
89{PKCS7_R_INTERNAL_ERROR ,"internal error"}, 107{PKCS7_R_INTERNAL_ERROR ,"internal error"},
108{PKCS7_R_INVALID_MIME_TYPE ,"invalid mime type"},
109{PKCS7_R_INVALID_NULL_POINTER ,"invalid null pointer"},
110{PKCS7_R_MIME_NO_CONTENT_TYPE ,"mime no content type"},
111{PKCS7_R_MIME_PARSE_ERROR ,"mime parse error"},
112{PKCS7_R_MIME_SIG_PARSE_ERROR ,"mime sig parse error"},
90{PKCS7_R_MISSING_CERIPEND_INFO ,"missing ceripend info"}, 113{PKCS7_R_MISSING_CERIPEND_INFO ,"missing ceripend info"},
114{PKCS7_R_NO_CONTENT ,"no content"},
115{PKCS7_R_NO_CONTENT_TYPE ,"no content type"},
116{PKCS7_R_NO_MULTIPART_BODY_FAILURE ,"no multipart body failure"},
117{PKCS7_R_NO_MULTIPART_BOUNDARY ,"no multipart boundary"},
91{PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE,"no recipient matches certificate"}, 118{PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE,"no recipient matches certificate"},
119{PKCS7_R_NO_SIGNATURES_ON_DATA ,"no signatures on data"},
120{PKCS7_R_NO_SIGNERS ,"no signers"},
121{PKCS7_R_NO_SIG_CONTENT_TYPE ,"no sig content type"},
92{PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"}, 122{PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"},
123{PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR ,"pkcs7 add signature error"},
124{PKCS7_R_PKCS7_DATAFINAL_ERROR ,"pkcs7 datafinal error"},
125{PKCS7_R_PKCS7_DATASIGN ,"pkcs7 datasign"},
126{PKCS7_R_PKCS7_PARSE_ERROR ,"pkcs7 parse error"},
127{PKCS7_R_PKCS7_SIG_PARSE_ERROR ,"pkcs7 sig parse error"},
128{PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE,"private key does not match certificate"},
93{PKCS7_R_SIGNATURE_FAILURE ,"signature failure"}, 129{PKCS7_R_SIGNATURE_FAILURE ,"signature failure"},
130{PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND ,"signer certificate not found"},
131{PKCS7_R_SIG_INVALID_MIME_TYPE ,"sig invalid mime type"},
132{PKCS7_R_SMIME_TEXT_ERROR ,"smime text error"},
94{PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"}, 133{PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"},
95{PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"}, 134{PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"},
96{PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"}, 135{PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"},
diff --git a/src/lib/libcrypto/pkcs7/sign.c b/src/lib/libcrypto/pkcs7/sign.c
index d5f1154006..22290e192c 100644
--- a/src/lib/libcrypto/pkcs7/sign.c
+++ b/src/lib/libcrypto/pkcs7/sign.c
@@ -56,6 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include <string.h>
59#include <openssl/bio.h> 60#include <openssl/bio.h>
60#include <openssl/x509.h> 61#include <openssl/x509.h>
61#include <openssl/pem.h> 62#include <openssl/pem.h>
@@ -75,10 +76,18 @@ char *argv[];
75 int i; 76 int i;
76 int nodetach=0; 77 int nodetach=0;
77 78
79#ifndef NO_MD2
78 EVP_add_digest(EVP_md2()); 80 EVP_add_digest(EVP_md2());
81#endif
82#ifndef NO_MD5
79 EVP_add_digest(EVP_md5()); 83 EVP_add_digest(EVP_md5());
84#endif
85#ifndef NO_SHA1
80 EVP_add_digest(EVP_sha1()); 86 EVP_add_digest(EVP_sha1());
87#endif
88#ifndef NO_MDC2
81 EVP_add_digest(EVP_mdc2()); 89 EVP_add_digest(EVP_mdc2());
90#endif
82 91
83 data=BIO_new(BIO_s_file()); 92 data=BIO_new(BIO_s_file());
84again: 93again:
@@ -97,9 +106,9 @@ again:
97 BIO_set_fp(data,stdin,BIO_NOCLOSE); 106 BIO_set_fp(data,stdin,BIO_NOCLOSE);
98 107
99 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err; 108 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
100 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; 109 if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
101 BIO_reset(in); 110 BIO_reset(in);
102 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; 111 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL) goto err;
103 BIO_free(in); 112 BIO_free(in);
104 113
105 p7=PKCS7_new(); 114 p7=PKCS7_new();
diff --git a/src/lib/libcrypto/pkcs7/verify.c b/src/lib/libcrypto/pkcs7/verify.c
index 32d9783e45..49fc8d8bed 100644
--- a/src/lib/libcrypto/pkcs7/verify.c
+++ b/src/lib/libcrypto/pkcs7/verify.c
@@ -56,6 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include <string.h>
59#include <openssl/bio.h> 60#include <openssl/bio.h>
60#include <openssl/asn1.h> 61#include <openssl/asn1.h>
61#include <openssl/x509.h> 62#include <openssl/x509.h>
@@ -84,10 +85,18 @@ char *argv[];
84 85
85 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 86 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
86 bio_out=BIO_new_fp(stdout,BIO_NOCLOSE); 87 bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);
88#ifndef NO_MD2
87 EVP_add_digest(EVP_md2()); 89 EVP_add_digest(EVP_md2());
90#endif
91#ifndef NO_MD5
88 EVP_add_digest(EVP_md5()); 92 EVP_add_digest(EVP_md5());
93#endif
94#ifndef NO_SHA1
89 EVP_add_digest(EVP_sha1()); 95 EVP_add_digest(EVP_sha1());
96#endif
97#ifndef NO_MDC2
90 EVP_add_digest(EVP_mdc2()); 98 EVP_add_digest(EVP_mdc2());
99#endif
91 100
92 data=BIO_new(BIO_s_file()); 101 data=BIO_new(BIO_s_file());
93 102
@@ -121,7 +130,7 @@ char *argv[];
121 130
122 131
123 /* Load the PKCS7 object from a file */ 132 /* Load the PKCS7 object from a file */
124 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err; 133 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL,NULL)) == NULL) goto err;
125 134
126 /* This stuff is being setup for certificate verification. 135 /* This stuff is being setup for certificate verification.
127 * When using SSL, it could be replaced with a 136 * When using SSL, it could be replaced with a
diff --git a/src/lib/libcrypto/rand/Makefile.ssl b/src/lib/libcrypto/rand/Makefile.ssl
index 014356cb18..be8eea34a2 100644
--- a/src/lib/libcrypto/rand/Makefile.ssl
+++ b/src/lib/libcrypto/rand/Makefile.ssl
@@ -22,8 +22,8 @@ TEST= randtest.c
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC=md_rand.c randfile.c rand_lib.c 25LIBSRC=md_rand.c randfile.c rand_lib.c rand_err.c rand_egd.c
26LIBOBJ=md_rand.o randfile.o rand_lib.o 26LIBOBJ=md_rand.o randfile.o rand_lib.o rand_err.o rand_egd.o
27 27
28SRC= $(LIBSRC) 28SRC= $(LIBSRC)
29 29
@@ -79,9 +79,14 @@ clean:
79# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80 80
81md_rand.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 81md_rand.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
82md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h 82md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
83md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 83md_rand.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
84md_rand.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
84md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 85md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
86rand_egd.o: ../../include/openssl/opensslconf.h ../../include/openssl/rand.h
87rand_err.o: ../../include/openssl/err.h ../../include/openssl/rand.h
85rand_lib.o: ../../include/openssl/rand.h 88rand_lib.o: ../../include/openssl/rand.h
86randfile.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 89randfile.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
87randfile.o: ../../include/openssl/opensslconf.h ../../include/openssl/rand.h 90randfile.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
91randfile.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
92randfile.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c
index c9a071bd22..6b158f0349 100644
--- a/src/lib/libcrypto/rand/md_rand.c
+++ b/src/lib/libcrypto/rand/md_rand.c
@@ -56,15 +56,23 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#define ENTROPY_NEEDED 16 /* require 128 bits = 16 bytes of randomness */
60
61#ifndef MD_RAND_DEBUG
62# ifndef NDEBUG
63# define NDEBUG
64# endif
65#endif
66
67#include <assert.h>
59#include <stdio.h> 68#include <stdio.h>
60#include <sys/types.h>
61#include <fcntl.h>
62#include <time.h> 69#include <time.h>
63#include <string.h> 70#include <string.h>
64 71
65#include "openssl/e_os.h" 72#include "openssl/e_os.h"
66 73
67#include <openssl/crypto.h> 74#include <openssl/crypto.h>
75#include <openssl/err.h>
68 76
69#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND) 77#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
70#if !defined(NO_SHA) && !defined(NO_SHA1) 78#if !defined(NO_SHA) && !defined(NO_SHA1)
@@ -130,17 +138,23 @@ static int state_num=0,state_index=0;
130static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH]; 138static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];
131static unsigned char md[MD_DIGEST_LENGTH]; 139static unsigned char md[MD_DIGEST_LENGTH];
132static long md_count[2]={0,0}; 140static long md_count[2]={0,0};
141static double entropy=0;
142static int initialized=0;
133 143
134const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT; 144const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT;
135 145
136static void ssleay_rand_cleanup(void); 146static void ssleay_rand_cleanup(void);
137static void ssleay_rand_seed(const void *buf, int num); 147static void ssleay_rand_seed(const void *buf, int num);
138static void ssleay_rand_bytes(unsigned char *buf, int num); 148static void ssleay_rand_add(const void *buf, int num, double add_entropy);
149static int ssleay_rand_bytes(unsigned char *buf, int num);
150static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num);
139 151
140RAND_METHOD rand_ssleay_meth={ 152RAND_METHOD rand_ssleay_meth={
141 ssleay_rand_seed, 153 ssleay_rand_seed,
142 ssleay_rand_bytes, 154 ssleay_rand_bytes,
143 ssleay_rand_cleanup, 155 ssleay_rand_cleanup,
156 ssleay_rand_add,
157 ssleay_rand_pseudo_bytes,
144 }; 158 };
145 159
146RAND_METHOD *RAND_SSLeay(void) 160RAND_METHOD *RAND_SSLeay(void)
@@ -156,22 +170,49 @@ static void ssleay_rand_cleanup(void)
156 memset(md,0,MD_DIGEST_LENGTH); 170 memset(md,0,MD_DIGEST_LENGTH);
157 md_count[0]=0; 171 md_count[0]=0;
158 md_count[1]=0; 172 md_count[1]=0;
173 entropy=0;
159 } 174 }
160 175
161static void ssleay_rand_seed(const void *buf, int num) 176static void ssleay_rand_add(const void *buf, int num, double add)
162 { 177 {
163 int i,j,k,st_idx,st_num; 178 int i,j,k,st_idx;
179 long md_c[2];
180 unsigned char local_md[MD_DIGEST_LENGTH];
164 MD_CTX m; 181 MD_CTX m;
165 182
166#ifdef NORAND 183#ifdef NORAND
167 return; 184 return;
168#endif 185#endif
169 186
187 /*
188 * (Based on the rand(3) manpage)
189 *
190 * The input is chopped up into units of 20 bytes (or less for
191 * the last block). Each of these blocks is run through the hash
192 * function as follows: The data passed to the hash function
193 * is the current 'md', the same number of bytes from the 'state'
194 * (the location determined by in incremented looping index) as
195 * the current 'block', the new key data 'block', and 'count'
196 * (which is incremented after each use).
197 * The result of this is kept in 'md' and also xored into the
198 * 'state' at the same locations that were used as input into the
199 * hash function.
200 */
201
170 CRYPTO_w_lock(CRYPTO_LOCK_RAND); 202 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
171 st_idx=state_index; 203 st_idx=state_index;
172 st_num=state_num;
173 204
174 state_index=(state_index+num); 205 /* use our own copies of the counters so that even
206 * if a concurrent thread seeds with exactly the
207 * same data and uses the same subarray there's _some_
208 * difference */
209 md_c[0] = md_count[0];
210 md_c[1] = md_count[1];
211
212 memcpy(local_md, md, sizeof md);
213
214 /* state_index <= state_num <= STATE_SIZE */
215 state_index += num;
175 if (state_index >= STATE_SIZE) 216 if (state_index >= STATE_SIZE)
176 { 217 {
177 state_index%=STATE_SIZE; 218 state_index%=STATE_SIZE;
@@ -182,6 +223,14 @@ static void ssleay_rand_seed(const void *buf, int num)
182 if (state_index > state_num) 223 if (state_index > state_num)
183 state_num=state_index; 224 state_num=state_index;
184 } 225 }
226 /* state_index <= state_num <= STATE_SIZE */
227
228 /* state[st_idx], ..., state[(st_idx + num - 1) % STATE_SIZE]
229 * are what we will use now, but other threads may use them
230 * as well */
231
232 md_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0);
233
185 CRYPTO_w_unlock(CRYPTO_LOCK_RAND); 234 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
186 235
187 for (i=0; i<num; i+=MD_DIGEST_LENGTH) 236 for (i=0; i<num; i+=MD_DIGEST_LENGTH)
@@ -190,7 +239,7 @@ static void ssleay_rand_seed(const void *buf, int num)
190 j=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j; 239 j=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j;
191 240
192 MD_Init(&m); 241 MD_Init(&m);
193 MD_Update(&m,md,MD_DIGEST_LENGTH); 242 MD_Update(&m,local_md,MD_DIGEST_LENGTH);
194 k=(st_idx+j)-STATE_SIZE; 243 k=(st_idx+j)-STATE_SIZE;
195 if (k > 0) 244 if (k > 0)
196 { 245 {
@@ -201,33 +250,107 @@ static void ssleay_rand_seed(const void *buf, int num)
201 MD_Update(&m,&(state[st_idx]),j); 250 MD_Update(&m,&(state[st_idx]),j);
202 251
203 MD_Update(&m,buf,j); 252 MD_Update(&m,buf,j);
204 MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count)); 253 MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
205 MD_Final(md,&m); 254 MD_Final(local_md,&m);
206 md_count[1]++; 255 md_c[1]++;
207 256
208 buf=(const char *)buf + j; 257 buf=(const char *)buf + j;
209 258
210 for (k=0; k<j; k++) 259 for (k=0; k<j; k++)
211 { 260 {
212 state[st_idx++]^=md[k]; 261 /* Parallel threads may interfere with this,
262 * but always each byte of the new state is
263 * the XOR of some previous value of its
264 * and local_md (itermediate values may be lost).
265 * Alway using locking could hurt performance more
266 * than necessary given that conflicts occur only
267 * when the total seeding is longer than the random
268 * state. */
269 state[st_idx++]^=local_md[k];
213 if (st_idx >= STATE_SIZE) 270 if (st_idx >= STATE_SIZE)
214 {
215 st_idx=0; 271 st_idx=0;
216 st_num=STATE_SIZE;
217 }
218 } 272 }
219 } 273 }
220 memset((char *)&m,0,sizeof(m)); 274 memset((char *)&m,0,sizeof(m));
275
276 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
277 /* Don't just copy back local_md into md -- this could mean that
278 * other thread's seeding remains without effect (except for
279 * the incremented counter). By XORing it we keep at least as
280 * much entropy as fits into md. */
281 for (k = 0; k < sizeof md; k++)
282 {
283 md[k] ^= local_md[k];
284 }
285 if (entropy < ENTROPY_NEEDED) /* stop counting when we have enough */
286 entropy += add;
287 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
288
289#ifndef THREADS
290 assert(md_c[1] == md_count[1]);
291#endif
221 } 292 }
222 293
223static void ssleay_rand_bytes(unsigned char *buf, int num) 294static void ssleay_rand_seed(const void *buf, int num)
295 {
296 ssleay_rand_add(buf, num, num);
297 }
298
299static void ssleay_rand_initialize(void)
224 { 300 {
225 int i,j,k,st_num,st_idx;
226 MD_CTX m;
227 static int init=1;
228 unsigned long l; 301 unsigned long l;
302#ifndef GETPID_IS_MEANINGLESS
303 pid_t curr_pid = getpid();
304#endif
229#ifdef DEVRANDOM 305#ifdef DEVRANDOM
230 int fd; 306 FILE *fh;
307#endif
308
309 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
310 /* put in some default random data, we need more than just this */
311#ifndef GETPID_IS_MEANINGLESS
312 l=curr_pid;
313 RAND_add(&l,sizeof(l),0);
314 l=getuid();
315 RAND_add(&l,sizeof(l),0);
316#endif
317 l=time(NULL);
318 RAND_add(&l,sizeof(l),0);
319
320#ifdef DEVRANDOM
321 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
322 * have this. Use /dev/urandom if you can as /dev/random may block
323 * if it runs out of random entries. */
324
325 if ((fh = fopen(DEVRANDOM, "r")) != NULL)
326 {
327 unsigned char tmpbuf[ENTROPY_NEEDED];
328 int n;
329
330 setvbuf(fh, NULL, _IONBF, 0);
331 n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh);
332 fclose(fh);
333 RAND_add(tmpbuf,sizeof tmpbuf,n);
334 memset(tmpbuf,0,n);
335 }
336#endif
337#ifdef PURIFY
338 memset(state,0,STATE_SIZE);
339 memset(md,0,MD_DIGEST_LENGTH);
340#endif
341 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
342 initialized=1;
343 }
344
345static int ssleay_rand_bytes(unsigned char *buf, int num)
346 {
347 int i,j,k,st_num,st_idx;
348 int ok;
349 long md_c[2];
350 unsigned char local_md[MD_DIGEST_LENGTH];
351 MD_CTX m;
352#ifndef GETPID_IS_MEANINGLESS
353 pid_t curr_pid = getpid();
231#endif 354#endif
232 355
233#ifdef PREDICT 356#ifdef PREDICT
@@ -236,65 +359,63 @@ static void ssleay_rand_bytes(unsigned char *buf, int num)
236 359
237 for (i=0; i<num; i++) 360 for (i=0; i<num; i++)
238 buf[i]=val++; 361 buf[i]=val++;
239 return; 362 return(1);
240 } 363 }
241#endif 364#endif
242 365
366 /*
367 * (Based on the rand(3) manpage:)
368 *
369 * For each group of 10 bytes (or less), we do the following:
370 *
371 * Input into the hash function the top 10 bytes from the
372 * local 'md' (which is initialized from the global 'md'
373 * before any bytes are generated), the bytes that are
374 * to be overwritten by the random bytes, and bytes from the
375 * 'state' (incrementing looping index). From this digest output
376 * (which is kept in 'md'), the top (up to) 10 bytes are
377 * returned to the caller and the bottom (up to) 10 bytes are xored
378 * into the 'state'.
379 * Finally, after we have finished 'num' random bytes for the
380 * caller, 'count' (which is incremented) and the local and global 'md'
381 * are fed into the hash function and the results are kept in the
382 * global 'md'.
383 */
384
243 CRYPTO_w_lock(CRYPTO_LOCK_RAND); 385 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
244 386
245 if (init) 387 if (!initialized)
388 ssleay_rand_initialize();
389
390 ok = (entropy >= ENTROPY_NEEDED);
391 if (!ok)
246 { 392 {
247 CRYPTO_w_unlock(CRYPTO_LOCK_RAND); 393 /* If the PRNG state is not yet unpredictable, then seeing
248 /* put in some default random data, we need more than 394 * the PRNG output may help attackers to determine the new
249 * just this */ 395 * state; thus we have to decrease the entropy estimate.
250 RAND_seed(&m,sizeof(m)); 396 * Once we've had enough initial seeding we don't bother to
251#ifndef MSDOS 397 * adjust the entropy count, though, because we're not ambitious
252 l=getpid(); 398 * to provide *information-theoretic* randomness.
253 RAND_seed(&l,sizeof(l));
254 l=getuid();
255 RAND_seed(&l,sizeof(l));
256#endif
257 l=time(NULL);
258 RAND_seed(&l,sizeof(l));
259
260/* #ifdef DEVRANDOM */
261 /*
262 * Use a random entropy pool device.
263 * Linux 1.3.x, OpenBSD, and FreeBSD have
264 * this. Use /dev/urandom if you can
265 * as /dev/random will block if it runs out
266 * of random entries.
267 */ 399 */
268 if ((fd = open(DEVRANDOM, O_RDONLY)) != NULL) 400 entropy -= num;
269 { 401 if (entropy < 0)
270 unsigned char tmpbuf[32]; 402 entropy = 0;
271
272 read(fd, tmpbuf, sizeof(tmpbuf));
273 /* we don't care how many bytes we read,
274 * we will just copy the 'stack' if there is
275 * nothing else :-) */
276 /* the above comment is EVIL. Security software
277 * RELIES ON THESE PRIMITIVES HAVING MORE SECURE
278 * BEHAVIOUR! Secure entropy is required in
279 * many cases! */
280 RAND_seed(tmpbuf,32);
281 memset(tmpbuf,0,32);
282 }
283/* #endif */
284#ifdef PURIFY
285 memset(state,0,STATE_SIZE);
286 memset(md,0,MD_DIGEST_LENGTH);
287#endif
288 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
289 init=0;
290 } 403 }
291 404
292 st_idx=state_index; 405 st_idx=state_index;
293 st_num=state_num; 406 st_num=state_num;
407 md_c[0] = md_count[0];
408 md_c[1] = md_count[1];
409 memcpy(local_md, md, sizeof md);
410
294 state_index+=num; 411 state_index+=num;
295 if (state_index > state_num) 412 if (state_index > state_num)
296 state_index=(state_index%state_num); 413 state_index %= state_num;
414
415 /* state[st_idx], ..., state[(st_idx + num - 1) % st_num]
416 * are now ours (but other threads may use them too) */
297 417
418 md_count[0] += 1;
298 CRYPTO_w_unlock(CRYPTO_LOCK_RAND); 419 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
299 420
300 while (num > 0) 421 while (num > 0)
@@ -302,8 +423,15 @@ static void ssleay_rand_bytes(unsigned char *buf, int num)
302 j=(num >= MD_DIGEST_LENGTH/2)?MD_DIGEST_LENGTH/2:num; 423 j=(num >= MD_DIGEST_LENGTH/2)?MD_DIGEST_LENGTH/2:num;
303 num-=j; 424 num-=j;
304 MD_Init(&m); 425 MD_Init(&m);
305 MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2); 426#ifndef GETPID_IS_MEANINGLESS
306 MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count)); 427 if (curr_pid) /* just in the first iteration to save time */
428 {
429 MD_Update(&m,(unsigned char*)&curr_pid,sizeof curr_pid);
430 curr_pid = 0;
431 }
432#endif
433 MD_Update(&m,&(local_md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2);
434 MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
307#ifndef PURIFY 435#ifndef PURIFY
308 MD_Update(&m,buf,j); /* purify complains */ 436 MD_Update(&m,buf,j); /* purify complains */
309#endif 437#endif
@@ -315,23 +443,57 @@ static void ssleay_rand_bytes(unsigned char *buf, int num)
315 } 443 }
316 else 444 else
317 MD_Update(&m,&(state[st_idx]),j); 445 MD_Update(&m,&(state[st_idx]),j);
318 MD_Final(md,&m); 446 MD_Final(local_md,&m);
319 447
320 for (i=0; i<j; i++) 448 for (i=0; i<j; i++)
321 { 449 {
450 state[st_idx++]^=local_md[i]; /* may compete with other threads */
451 *(buf++)=local_md[i+MD_DIGEST_LENGTH/2];
322 if (st_idx >= st_num) 452 if (st_idx >= st_num)
323 st_idx=0; 453 st_idx=0;
324 state[st_idx++]^=md[i];
325 *(buf++)=md[i+MD_DIGEST_LENGTH/2];
326 } 454 }
327 } 455 }
328 456
329 MD_Init(&m); 457 MD_Init(&m);
330 MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count)); 458 MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
331 md_count[0]++; 459 MD_Update(&m,local_md,MD_DIGEST_LENGTH);
460 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
332 MD_Update(&m,md,MD_DIGEST_LENGTH); 461 MD_Update(&m,md,MD_DIGEST_LENGTH);
333 MD_Final(md,&m); 462 MD_Final(md,&m);
463 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
464
334 memset(&m,0,sizeof(m)); 465 memset(&m,0,sizeof(m));
466 if (ok)
467 return(1);
468 else
469 {
470 RANDerr(RAND_F_SSLEAY_RAND_BYTES,RAND_R_PRNG_NOT_SEEDED);
471 return(0);
472 }
473 }
474
475/* pseudo-random bytes that are guaranteed to be unique but not
476 unpredictable */
477static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num)
478 {
479 int ret, err;
480
481 ret = RAND_bytes(buf, num);
482 if (ret == 0)
483 {
484 err = ERR_peek_error();
485 if (ERR_GET_LIB(err) == ERR_LIB_RAND &&
486 ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED)
487 (void)ERR_get_error();
488 }
489 return (ret);
490 }
491
492int RAND_status(void)
493 {
494 if (!initialized)
495 ssleay_rand_initialize();
496 return (entropy >= ENTROPY_NEEDED);
335 } 497 }
336 498
337#ifdef WINDOWS 499#ifdef WINDOWS
@@ -358,12 +520,12 @@ static void ssleay_rand_bytes(unsigned char *buf, int num)
358 */ 520 */
359/* 521/*
360 * I have modified the loading of bytes via RAND_seed() mechanism since 522 * I have modified the loading of bytes via RAND_seed() mechanism since
361 * the origional would have been very very CPU intensive since RAND_seed() 523 * the original would have been very very CPU intensive since RAND_seed()
362 * does an MD5 per 16 bytes of input. The cost to digest 16 bytes is the same 524 * does an MD5 per 16 bytes of input. The cost to digest 16 bytes is the same
363 * as that to digest 56 bytes. So under the old system, a screen of 525 * as that to digest 56 bytes. So under the old system, a screen of
364 * 1024*768*256 would have been CPU cost of approximatly 49,000 56 byte MD5 526 * 1024*768*256 would have been CPU cost of approximately 49,000 56 byte MD5
365 * digests or digesting 2.7 mbytes. What I have put in place would 527 * digests or digesting 2.7 mbytes. What I have put in place would
366 * be 48 16k MD5 digests, or efectivly 48*16+48 MD5 bytes or 816 kbytes 528 * be 48 16k MD5 digests, or effectively 48*16+48 MD5 bytes or 816 kbytes
367 * or about 3.5 times as much. 529 * or about 3.5 times as much.
368 * - eric 530 * - eric
369 */ 531 */
diff --git a/src/lib/libcrypto/rand/md_rand_munged.c b/src/lib/libcrypto/rand/md_rand_munged.c
new file mode 100644
index 0000000000..1611bf335b
--- /dev/null
+++ b/src/lib/libcrypto/rand/md_rand_munged.c
@@ -0,0 +1,515 @@
1/* crypto/rand/md_rand.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <sys/types.h>
61#include <fcntl.h>
62#include <time.h>
63#include <string.h>
64
65#include "openssl/e_os.h"
66
67#include <openssl/crypto.h>
68
69#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
70#if !defined(NO_SHA) && !defined(NO_SHA1)
71#define USE_SHA1_RAND
72#elif !defined(NO_MD5)
73#define USE_MD5_RAND
74#elif !defined(NO_MDC2) && !defined(NO_DES)
75#define USE_MDC2_RAND
76#elif !defined(NO_MD2)
77#define USE_MD2_RAND
78#else
79#error No message digest algorithm available
80#endif
81#endif
82
83/* Changed how the state buffer used. I now attempt to 'wrap' such
84 * that I don't run over the same locations the next time go through
85 * the 1023 bytes - many thanks to
86 * Robert J. LeBlanc <rjl@renaissoft.com> for his comments
87 */
88
89#if defined(USE_MD5_RAND)
90#include <openssl/md5.h>
91#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
92#define MD_CTX MD5_CTX
93#define MD_Init(a) MD5_Init(a)
94#define MD_Update(a,b,c) MD5_Update(a,b,c)
95#define MD_Final(a,b) MD5_Final(a,b)
96#define MD(a,b,c) MD5(a,b,c)
97#elif defined(USE_SHA1_RAND)
98#include <openssl/sha.h>
99#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
100#define MD_CTX SHA_CTX
101#define MD_Init(a) SHA1_Init(a)
102#define MD_Update(a,b,c) SHA1_Update(a,b,c)
103#define MD_Final(a,b) SHA1_Final(a,b)
104#define MD(a,b,c) SHA1(a,b,c)
105#elif defined(USE_MDC2_RAND)
106#include <openssl/mdc2.h>
107#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
108#define MD_CTX MDC2_CTX
109#define MD_Init(a) MDC2_Init(a)
110#define MD_Update(a,b,c) MDC2_Update(a,b,c)
111#define MD_Final(a,b) MDC2_Final(a,b)
112#define MD(a,b,c) MDC2(a,b,c)
113#elif defined(USE_MD2_RAND)
114#include <openssl/md2.h>
115#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
116#define MD_CTX MD2_CTX
117#define MD_Init(a) MD2_Init(a)
118#define MD_Update(a,b,c) MD2_Update(a,b,c)
119#define MD_Final(a,b) MD2_Final(a,b)
120#define MD(a,b,c) MD2(a,b,c)
121#endif
122
123#include <openssl/rand.h>
124
125/* #define NORAND 1 */
126/* #define PREDICT 1 */
127
128#define STATE_SIZE 1023
129static int state_num=0,state_index=0;
130static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];
131static unsigned char md[MD_DIGEST_LENGTH];
132static long md_count[2]={0,0};
133static double entropy=0;
134static int initialized=0;
135
136const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT;
137
138static void ssleay_rand_cleanup(void);
139static void ssleay_rand_seed(const void *buf, int num);
140static void ssleay_rand_add(const void *buf, int num, double add_entropy);
141static int ssleay_rand_bytes(unsigned char *buf, int num);
142static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num);
143
144RAND_METHOD rand_ssleay_meth={
145 ssleay_rand_seed,
146 ssleay_rand_bytes,
147 ssleay_rand_cleanup,
148 ssleay_rand_add,
149 ssleay_rand_pseudo_bytes,
150 };
151
152RAND_METHOD *RAND_SSLeay(void)
153 {
154 return(&rand_ssleay_meth);
155 }
156
157static void ssleay_rand_cleanup(void)
158 {
159 memset(state,0,sizeof(state));
160 state_num=0;
161 state_index=0;
162 memset(md,0,MD_DIGEST_LENGTH);
163 md_count[0]=0;
164 md_count[1]=0;
165 entropy=0;
166 }
167
168static void ssleay_rand_add(const void *buf, int num, double add)
169 {
170 int i,j,k,st_idx;
171 long md_c[2];
172 unsigned char local_md[MD_DIGEST_LENGTH];
173 MD_CTX m;
174
175#ifdef NORAND
176 return;
177#endif
178
179 /*
180 * (Based on the rand(3) manpage)
181 *
182 * The input is chopped up into units of 20 bytes (or less for
183 * the last block). Each of these blocks is run through the hash
184 * function as follows: The data passed to the hash function
185 * is the current 'md', the same number of bytes from the 'state'
186 * (the location determined by in incremented looping index) as
187 * the current 'block', the new key data 'block', and 'count'
188 * (which is incremented after each use).
189 * The result of this is kept in 'md' and also xored into the
190 * 'state' at the same locations that were used as input into the
191 * hash function.
192 */
193
194 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
195 st_idx=state_index;
196
197 /* use our own copies of the counters so that even
198 * if a concurrent thread seeds with exactly the
199 * same data and uses the same subarray there's _some_
200 * difference */
201 md_c[0] = md_count[0];
202 md_c[1] = md_count[1];
203
204 memcpy(local_md, md, sizeof md);
205
206 /* state_index <= state_num <= STATE_SIZE */
207 state_index += num;
208 if (state_index >= STATE_SIZE)
209 {
210 state_index%=STATE_SIZE;
211 state_num=STATE_SIZE;
212 }
213 else if (state_num < STATE_SIZE)
214 {
215 if (state_index > state_num)
216 state_num=state_index;
217 }
218 /* state_index <= state_num <= STATE_SIZE */
219
220 /* state[st_idx], ..., state[(st_idx + num - 1) % STATE_SIZE]
221 * are what we will use now, but other threads may use them
222 * as well */
223
224 md_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0);
225
226 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
227
228 for (i=0; i<num; i+=MD_DIGEST_LENGTH)
229 {
230 j=(num-i);
231 j=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j;
232
233 MD_Init(&m);
234 MD_Update(&m,local_md,MD_DIGEST_LENGTH);
235 k=(st_idx+j)-STATE_SIZE;
236 if (k > 0)
237 {
238 MD_Update(&m,&(state[st_idx]),j-k);
239 MD_Update(&m,&(state[0]),k);
240 }
241 else
242 MD_Update(&m,&(state[st_idx]),j);
243
244 MD_Update(&m,buf,j);
245 MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count));
246 MD_Final(md,&m);
247 md_count[1]++;
248
249 buf=(const char *)buf + j;
250
251 for (k=0; k<j; k++)
252 {
253 state[st_idx++]^=md[k];
254 if (st_idx >= STATE_SIZE)
255 {
256 st_idx=0;
257 st_num=STATE_SIZE;
258 }
259 }
260 }
261 memset((char *)&m,0,sizeof(m));
262 }
263
264static void ssleay_rand_bytes(unsigned char *buf, int num)
265 {
266 int i,j,k,st_num,st_idx;
267 MD_CTX m;
268 static int init=1;
269 unsigned long l;
270#ifdef DEVRANDOM
271 int fd;
272#endif
273
274#ifdef PREDICT
275 {
276 static unsigned char val=0;
277
278 for (i=0; i<num; i++)
279 buf[i]=val++;
280 return;
281 }
282#endif
283
284 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
285
286 if (init)
287 {
288 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
289 /* put in some default random data, we need more than
290 * just this */
291 RAND_seed(&m,sizeof(m));
292#ifndef MSDOS
293 l=getpid();
294 RAND_seed(&l,sizeof(l));
295 l=getuid();
296 RAND_seed(&l,sizeof(l));
297#endif
298 l=time(NULL);
299 RAND_seed(&l,sizeof(l));
300
301/* #ifdef DEVRANDOM */
302 /*
303 * Use a random entropy pool device.
304 * Linux 1.3.x, OpenBSD, and FreeBSD have
305 * this. Use /dev/urandom if you can
306 * as /dev/random will block if it runs out
307 * of random entries.
308 */
309 if ((fd = open(DEVRANDOM, O_RDONLY)) != NULL)
310 {
311 unsigned char tmpbuf[32];
312
313 read(fd, tmpbuf, sizeof(tmpbuf));
314 /* we don't care how many bytes we read,
315 * we will just copy the 'stack' if there is
316 * nothing else :-) */
317 /* the above comment is EVIL. Security software
318 * RELIES ON THESE PRIMITIVES HAVING MORE SECURE
319 * BEHAVIOUR! Secure entropy is required in
320 * many cases! */
321 RAND_seed(tmpbuf,32);
322 memset(tmpbuf,0,32);
323 }
324/* #endif */
325#ifdef PURIFY
326 memset(state,0,STATE_SIZE);
327 memset(md,0,MD_DIGEST_LENGTH);
328#endif
329 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
330 init=0;
331 }
332
333 st_idx=state_index;
334 st_num=state_num;
335 state_index+=num;
336 if (state_index > state_num)
337 state_index=(state_index%state_num);
338
339 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
340
341 while (num > 0)
342 {
343 j=(num >= MD_DIGEST_LENGTH/2)?MD_DIGEST_LENGTH/2:num;
344 num-=j;
345 MD_Init(&m);
346#ifndef GETPID_IS_MEANINGLESS
347 if (curr_pid) /* just in the first iteration to save time */
348 {
349 MD_Update(&m,(unsigned char*)&curr_pid,sizeof curr_pid);
350 curr_pid = 0;
351 }
352#endif
353 MD_Update(&m,&(local_md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2);
354 MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
355#ifndef PURIFY
356 MD_Update(&m,buf,j); /* purify complains */
357#endif
358 k=(st_idx+j)-st_num;
359 if (k > 0)
360 {
361 MD_Update(&m,&(state[st_idx]),j-k);
362 MD_Update(&m,&(state[0]),k);
363 }
364 else
365 MD_Update(&m,&(state[st_idx]),j);
366 MD_Final(local_md,&m);
367
368 for (i=0; i<j; i++)
369 {
370 state[st_idx++]^=local_md[i]; /* may compete with other threads */
371 *(buf++)=local_md[i+MD_DIGEST_LENGTH/2];
372 if (st_idx >= st_num)
373 st_idx=0;
374 }
375 }
376
377 MD_Init(&m);
378 MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
379 MD_Update(&m,local_md,MD_DIGEST_LENGTH);
380 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
381 MD_Update(&m,md,MD_DIGEST_LENGTH);
382 MD_Final(md,&m);
383 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
384
385 memset(&m,0,sizeof(m));
386 if (ok)
387 return(1);
388 else
389 {
390 RANDerr(RAND_F_SSLEAY_RAND_BYTES,RAND_R_PRNG_NOT_SEEDED);
391 return(0);
392 }
393 }
394
395/* pseudo-random bytes that are guaranteed to be unique but not
396 unpredictable */
397static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num)
398 {
399 int ret, err;
400
401 ret = RAND_bytes(buf, num);
402 if (ret == 0)
403 {
404 err = ERR_peek_error();
405 if (ERR_GET_LIB(err) == ERR_LIB_RAND &&
406 ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED)
407 (void)ERR_get_error();
408 }
409 return (ret);
410 }
411
412int RAND_status(void)
413 {
414 if (!initialized)
415 ssleay_rand_initialize();
416 return (entropy >= ENTROPY_NEEDED);
417 }
418
419#ifdef WINDOWS
420#include <windows.h>
421#include <openssl/rand.h>
422
423/*****************************************************************************
424 * Initialisation function for the SSL random generator. Takes the contents
425 * of the screen as random seed.
426 *
427 * Created 960901 by Gertjan van Oosten, gertjan@West.NL, West Consulting B.V.
428 *
429 * Code adapted from
430 * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>;
431 * the original copyright message is:
432 *
433 * (C) Copyright Microsoft Corp. 1993. All rights reserved.
434 *
435 * You have a royalty-free right to use, modify, reproduce and
436 * distribute the Sample Files (and/or any modified version) in
437 * any way you find useful, provided that you agree that
438 * Microsoft has no warranty obligations or liability for any
439 * Sample Application Files which are modified.
440 */
441/*
442 * I have modified the loading of bytes via RAND_seed() mechanism since
443 * the original would have been very very CPU intensive since RAND_seed()
444 * does an MD5 per 16 bytes of input. The cost to digest 16 bytes is the same
445 * as that to digest 56 bytes. So under the old system, a screen of
446 * 1024*768*256 would have been CPU cost of approximately 49,000 56 byte MD5
447 * digests or digesting 2.7 mbytes. What I have put in place would
448 * be 48 16k MD5 digests, or effectively 48*16+48 MD5 bytes or 816 kbytes
449 * or about 3.5 times as much.
450 * - eric
451 */
452void RAND_screen(void)
453{
454 HDC hScrDC; /* screen DC */
455 HDC hMemDC; /* memory DC */
456 HBITMAP hBitmap; /* handle for our bitmap */
457 HBITMAP hOldBitmap; /* handle for previous bitmap */
458 BITMAP bm; /* bitmap properties */
459 unsigned int size; /* size of bitmap */
460 char *bmbits; /* contents of bitmap */
461 int w; /* screen width */
462 int h; /* screen height */
463 int y; /* y-coordinate of screen lines to grab */
464 int n = 16; /* number of screen lines to grab at a time */
465
466 /* Create a screen DC and a memory DC compatible to screen DC */
467 hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
468 hMemDC = CreateCompatibleDC(hScrDC);
469
470 /* Get screen resolution */
471 w = GetDeviceCaps(hScrDC, HORZRES);
472 h = GetDeviceCaps(hScrDC, VERTRES);
473
474 /* Create a bitmap compatible with the screen DC */
475 hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
476
477 /* Select new bitmap into memory DC */
478 hOldBitmap = SelectObject(hMemDC, hBitmap);
479
480 /* Get bitmap properties */
481 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
482 size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
483
484 bmbits = Malloc(size);
485 if (bmbits) {
486 /* Now go through the whole screen, repeatedly grabbing n lines */
487 for (y = 0; y < h-n; y += n)
488 {
489 unsigned char md[MD_DIGEST_LENGTH];
490
491 /* Bitblt screen DC to memory DC */
492 BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY);
493
494 /* Copy bitmap bits from memory DC to bmbits */
495 GetBitmapBits(hBitmap, size, bmbits);
496
497 /* Get the MD5 of the bitmap */
498 MD(bmbits,size,md);
499
500 /* Seed the random generator with the MD5 digest */
501 RAND_seed(md, MD_DIGEST_LENGTH);
502 }
503
504 Free(bmbits);
505 }
506
507 /* Select old bitmap back into memory DC */
508 hBitmap = SelectObject(hMemDC, hOldBitmap);
509
510 /* Clean up */
511 DeleteObject(hBitmap);
512 DeleteDC(hMemDC);
513 DeleteDC(hScrDC);
514}
515#endif
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h
index fd8ee38366..28f45ec052 100644
--- a/src/lib/libcrypto/rand/rand.h
+++ b/src/lib/libcrypto/rand/rand.h
@@ -66,24 +66,45 @@ extern "C" {
66typedef struct rand_meth_st 66typedef struct rand_meth_st
67 { 67 {
68 void (*seed)(const void *buf, int num); 68 void (*seed)(const void *buf, int num);
69 void (*bytes)(unsigned char *buf, int num); 69 int (*bytes)(unsigned char *buf, int num);
70 void (*cleanup)(void); 70 void (*cleanup)(void);
71 void (*add)(const void *buf, int num, double entropy);
72 int (*pseudorand)(unsigned char *buf, int num);
71 } RAND_METHOD; 73 } RAND_METHOD;
72 74
73void RAND_set_rand_method(RAND_METHOD *meth); 75void RAND_set_rand_method(RAND_METHOD *meth);
74RAND_METHOD *RAND_get_rand_method(void ); 76RAND_METHOD *RAND_get_rand_method(void );
75RAND_METHOD *RAND_SSLeay(void); 77RAND_METHOD *RAND_SSLeay(void);
76void RAND_cleanup(void ); 78void RAND_cleanup(void );
77void RAND_bytes(unsigned char *buf,int num); 79int RAND_bytes(unsigned char *buf,int num);
80int RAND_pseudo_bytes(unsigned char *buf,int num);
78void RAND_seed(const void *buf,int num); 81void RAND_seed(const void *buf,int num);
82void RAND_add(const void *buf,int num,double entropy);
79int RAND_load_file(const char *file,long max_bytes); 83int RAND_load_file(const char *file,long max_bytes);
80int RAND_write_file(const char *file); 84int RAND_write_file(const char *file);
81char *RAND_file_name(char *file,int num); 85const char *RAND_file_name(char *file,int num);
86int RAND_status(void);
87int RAND_egd(const char *path);
82#ifdef WINDOWS 88#ifdef WINDOWS
83void RAND_screen(void); 89void RAND_screen(void);
84#endif 90#endif
91void ERR_load_RAND_strings(void);
92
93/* BEGIN ERROR CODES */
94/* The following lines are auto generated by the script mkerr.pl. Any changes
95 * made after this point may be overwritten when the script is next run.
96 */
97
98/* Error codes for the RAND functions. */
99
100/* Function codes. */
101#define RAND_F_SSLEAY_RAND_BYTES 100
102
103/* Reason codes. */
104#define RAND_R_PRNG_NOT_SEEDED 100
105
85#ifdef __cplusplus 106#ifdef __cplusplus
86} 107}
87#endif 108#endif
88
89#endif 109#endif
110
diff --git a/src/lib/libcrypto/rand/rand_egd.c b/src/lib/libcrypto/rand/rand_egd.c
new file mode 100644
index 0000000000..d834408bd4
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_egd.c
@@ -0,0 +1,110 @@
1/* crypto/rand/rand_egd.c */
2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ====================================================================
4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@openssl.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#include <openssl/rand.h>
58
59/* Query the EGD <URL: http://www.lothar.com/tech/crypto/>.
60 */
61
62#if defined(WIN32) || defined(VMS) || defined(__VMS)
63int RAND_egd(const char *path)
64 {
65 return(-1);
66 }
67#else
68#include <openssl/opensslconf.h>
69#include OPENSSL_UNISTD
70#include <sys/types.h>
71#include <sys/socket.h>
72#include <sys/un.h>
73#include <string.h>
74
75#ifndef offsetof
76# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
77#endif
78
79int RAND_egd(const char *path)
80 {
81 int ret = -1;
82 struct sockaddr_un addr;
83 int len, num;
84 int fd = -1;
85 unsigned char buf[256];
86
87 memset(&addr, 0, sizeof(addr));
88 addr.sun_family = AF_UNIX;
89 if (strlen(path) > sizeof(addr.sun_path))
90 return (-1);
91 strcpy(addr.sun_path,path);
92 len = offsetof(struct sockaddr_un, sun_path) + strlen(path);
93 fd = socket(AF_UNIX, SOCK_STREAM, 0);
94 if (fd == -1) return (-1);
95 if (connect(fd, (struct sockaddr *)&addr, len) == -1) goto err;
96 buf[0] = 1;
97 buf[1] = 255;
98 write(fd, buf, 2);
99 if (read(fd, buf, 1) != 1) goto err;
100 if (buf[0] == 0) goto err;
101 num = read(fd, buf, 255);
102 if (num < 1) goto err;
103 RAND_seed(buf, num);
104 if (RAND_status() == 1)
105 ret = num;
106 err:
107 if (fd != -1) close(fd);
108 return(ret);
109 }
110#endif
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c
new file mode 100644
index 0000000000..d1263edf80
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_err.c
@@ -0,0 +1,93 @@
1/* crypto/rand/rand_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/rand.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA RAND_str_functs[]=
67 {
68{ERR_PACK(0,RAND_F_SSLEAY_RAND_BYTES,0), "SSLEAY_RAND_BYTES"},
69{0,NULL}
70 };
71
72static ERR_STRING_DATA RAND_str_reasons[]=
73 {
74{RAND_R_PRNG_NOT_SEEDED ,"prng not seeded"},
75{0,NULL}
76 };
77
78#endif
79
80void ERR_load_RAND_strings(void)
81 {
82 static int init=1;
83
84 if (init)
85 {
86 init=0;
87#ifndef NO_ERR
88 ERR_load_strings(ERR_LIB_RAND,RAND_str_functs);
89 ERR_load_strings(ERR_LIB_RAND,RAND_str_reasons);
90#endif
91
92 }
93 }
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
index 34c6d5b968..b09a300c46 100644
--- a/src/lib/libcrypto/rand/rand_lib.c
+++ b/src/lib/libcrypto/rand/rand_lib.c
@@ -57,7 +57,6 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <sys/types.h>
61#include <time.h> 60#include <time.h>
62#include <openssl/rand.h> 61#include <openssl/rand.h>
63 62
@@ -90,9 +89,22 @@ void RAND_seed(const void *buf, int num)
90 rand_meth->seed(buf,num); 89 rand_meth->seed(buf,num);
91 } 90 }
92 91
93void RAND_bytes(unsigned char *buf, int num) 92void RAND_add(const void *buf, int num, double entropy)
94 { 93 {
95 if (rand_meth != NULL) 94 if (rand_meth != NULL)
96 rand_meth->bytes(buf,num); 95 rand_meth->add(buf,num,entropy);
97 } 96 }
98 97
98int RAND_bytes(unsigned char *buf, int num)
99 {
100 if (rand_meth != NULL)
101 return rand_meth->bytes(buf,num);
102 return(-1);
103 }
104
105int RAND_pseudo_bytes(unsigned char *buf, int num)
106 {
107 if (rand_meth != NULL)
108 return rand_meth->pseudorand(buf,num);
109 return(-1);
110 }
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
index 6829d4ec37..658a8d6b65 100644
--- a/src/lib/libcrypto/rand/randfile.c
+++ b/src/lib/libcrypto/rand/randfile.c
@@ -60,22 +60,35 @@
60#include <stdio.h> 60#include <stdio.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include <string.h> 62#include <string.h>
63#include <sys/types.h>
64#include <sys/stat.h>
65#include <sys/types.h>
66 63
67#include "openssl/e_os.h" 64#include "openssl/e_os.h"
68 65
66#ifdef VMS
67#include <unixio.h>
68#endif
69#ifndef NO_SYS_TYPES_H
70# include <sys/types.h>
71#endif
72#ifdef MAC_OS_pre_X
73# include <stat.h>
74#else
75# include <sys/stat.h>
76#endif
77
78#include <openssl/crypto.h>
69#include <openssl/rand.h> 79#include <openssl/rand.h>
70 80
71#undef BUFSIZE 81#undef BUFSIZE
72#define BUFSIZE 1024 82#define BUFSIZE 1024
73#define RAND_DATA 1024 83#define RAND_DATA 1024
74 84
75/* #define RFILE ".rand" - defined in ../../e_os.h */ 85/* #define RFILE ".rnd" - defined in ../../e_os.h */
76 86
77int RAND_load_file(const char *file, long bytes) 87int RAND_load_file(const char *file, long bytes)
78 { 88 {
89 /* If bytes >= 0, read up to 'bytes' bytes.
90 * if bytes == -1, read complete file. */
91
79 MS_STATIC unsigned char buf[BUFSIZE]; 92 MS_STATIC unsigned char buf[BUFSIZE];
80 struct stat sb; 93 struct stat sb;
81 int i,ret=0,n; 94 int i,ret=0,n;
@@ -85,23 +98,28 @@ int RAND_load_file(const char *file, long bytes)
85 98
86 i=stat(file,&sb); 99 i=stat(file,&sb);
87 /* If the state fails, put some crap in anyway */ 100 /* If the state fails, put some crap in anyway */
88 RAND_seed(&sb,sizeof(sb)); 101 RAND_add(&sb,sizeof(sb),0);
89 ret+=sizeof(sb);
90 if (i < 0) return(0); 102 if (i < 0) return(0);
91 if (bytes <= 0) return(ret); 103 if (bytes == 0) return(ret);
92 104
93 in=fopen(file,"rb"); 105 in=fopen(file,"rb");
94 if (in == NULL) goto err; 106 if (in == NULL) goto err;
95 for (;;) 107 for (;;)
96 { 108 {
97 n=(bytes < BUFSIZE)?(int)bytes:BUFSIZE; 109 if (bytes > 0)
110 n = (bytes < BUFSIZE)?(int)bytes:BUFSIZE;
111 else
112 n = BUFSIZE;
98 i=fread(buf,1,n,in); 113 i=fread(buf,1,n,in);
99 if (i <= 0) break; 114 if (i <= 0) break;
100 /* even if n != i, use the full array */ 115 /* even if n != i, use the full array */
101 RAND_seed(buf,n); 116 RAND_add(buf,n,i);
102 ret+=i; 117 ret+=i;
103 bytes-=n; 118 if (bytes > 0)
104 if (bytes <= 0) break; 119 {
120 bytes-=n;
121 if (bytes == 0) break;
122 }
105 } 123 }
106 fclose(in); 124 fclose(in);
107 memset(buf,0,BUFSIZE); 125 memset(buf,0,BUFSIZE);
@@ -112,29 +130,48 @@ err:
112int RAND_write_file(const char *file) 130int RAND_write_file(const char *file)
113 { 131 {
114 unsigned char buf[BUFSIZE]; 132 unsigned char buf[BUFSIZE];
115 int i,ret=0; 133 int i,ret=0,err=0;
116 FILE *out; 134 FILE *out = NULL;
117 int n; 135 int n;
118 136
119 /* Under VMS, fopen(file, "wb") will craete a new version of the 137#ifdef VMS
138 /* Under VMS, fopen(file, "wb") will create a new version of the
120 same file. This is not good, so let's try updating an existing 139 same file. This is not good, so let's try updating an existing
121 one, and create file only if it doesn't already exist. This 140 one, and create file only if it doesn't already exist. */
122 should be completely harmless on system that have no file 141 /* At the same time, if we just update a file, we also need to
123 versions. -- Richard Levitte */ 142 truncate it, and unfortunately, ftruncate() and truncate() do
143 not exist everywhere. All that remains is to delete old versions
144 of the random data file (done at the end). */
145#if 0
124 out=fopen(file,"rb+"); 146 out=fopen(file,"rb+");
125 if (out == NULL && errno == ENOENT) 147 if (out == NULL && errno != ENOENT)
148 goto err;
149#endif
150#endif
151
152 if (out == NULL)
126 { 153 {
127 errno = 0; 154#if defined O_CREAT && defined O_EXCL
155 /* chmod(..., 0600) is too late to protect the file,
156 * permissions should be restrictive from the start */
157 int fd = open(file, O_CREAT | O_EXCL, 0600);
158 if (fd != -1)
159 out = fdopen(fd, "wb");
160#else
128 out=fopen(file,"wb"); 161 out=fopen(file,"wb");
162#endif
129 } 163 }
130 if (out == NULL) goto err; 164 if (out == NULL) goto err;
165#ifndef NO_CHMOD
131 chmod(file,0600); 166 chmod(file,0600);
167#endif
132 n=RAND_DATA; 168 n=RAND_DATA;
133 for (;;) 169 for (;;)
134 { 170 {
135 i=(n > BUFSIZE)?BUFSIZE:n; 171 i=(n > BUFSIZE)?BUFSIZE:n;
136 n-=BUFSIZE; 172 n-=BUFSIZE;
137 RAND_bytes(buf,i); 173 if (RAND_bytes(buf,i) <= 0)
174 err=1;
138 i=fwrite(buf,1,i,out); 175 i=fwrite(buf,1,i,out);
139 if (i <= 0) 176 if (i <= 0)
140 { 177 {
@@ -144,13 +181,40 @@ int RAND_write_file(const char *file)
144 ret+=i; 181 ret+=i;
145 if (n <= 0) break; 182 if (n <= 0) break;
146 } 183 }
184#ifdef VMS
185 /* We may have updated an existing file using mode "rb+",
186 * now remove any old extra bytes */
187#if 0
188 if (ret > 0)
189 ftruncate(fileno(out), ret);
190#else
191 /* Try to delete older versions of the file, until there aren't
192 any */
193 {
194 char *tmpf;
195
196 tmpf = Malloc(strlen(file) + 4); /* to add ";-1" and a nul */
197 if (tmpf)
198 {
199 strcpy(tmpf, file);
200 strcat(tmpf, ";-1");
201 while(delete(tmpf) == 0)
202 ;
203 rename(file,";1"); /* Make sure it's version 1, or we
204 will reach the limit (32767) at
205 some point... */
206 }
207 }
208#endif
209#endif
210
147 fclose(out); 211 fclose(out);
148 memset(buf,0,BUFSIZE); 212 memset(buf,0,BUFSIZE);
149err: 213err:
150 return(ret); 214 return(err ? -1 : ret);
151 } 215 }
152 216
153char *RAND_file_name(char *buf, int size) 217const char *RAND_file_name(char *buf, int size)
154 { 218 {
155 char *s; 219 char *s;
156 char *ret=NULL; 220 char *ret=NULL;
diff --git a/src/lib/libcrypto/rand/randtest.c b/src/lib/libcrypto/rand/randtest.c
index f0706d779a..da96e3f695 100644
--- a/src/lib/libcrypto/rand/randtest.c
+++ b/src/lib/libcrypto/rand/randtest.c
@@ -73,7 +73,7 @@ int main()
73 /*double d; */ 73 /*double d; */
74 long d; 74 long d;
75 75
76 RAND_bytes(buf,2500); 76 RAND_pseudo_bytes(buf,2500);
77 77
78 n1=0; 78 n1=0;
79 for (i=0; i<16; i++) n2[i]=0; 79 for (i=0; i<16; i++) n2[i]=0;
diff --git a/src/lib/libcrypto/rc2/rc2speed.c b/src/lib/libcrypto/rc2/rc2speed.c
index c3da63e77e..9f7f5ccfa3 100644
--- a/src/lib/libcrypto/rc2/rc2speed.c
+++ b/src/lib/libcrypto/rc2/rc2speed.c
@@ -183,7 +183,7 @@ int main(int argc, char **argv)
183#endif 183#endif
184 184
185#ifndef TIMES 185#ifndef TIMES
186 printf("To get the most acurate results, try to run this\n"); 186 printf("To get the most accurate results, try to run this\n");
187 printf("program when this computer is idle.\n"); 187 printf("program when this computer is idle.\n");
188#endif 188#endif
189 189
diff --git a/src/lib/libcrypto/rc2/rc2test.c b/src/lib/libcrypto/rc2/rc2test.c
index 6a5defa6ea..521269ded1 100644
--- a/src/lib/libcrypto/rc2/rc2test.c
+++ b/src/lib/libcrypto/rc2/rc2test.c
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
72#else 72#else
73#include <openssl/rc2.h> 73#include <openssl/rc2.h>
74 74
75unsigned char RC2key[4][16]={ 75static unsigned char RC2key[4][16]={
76 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 76 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
77 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 77 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
78 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 78 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -83,14 +83,14 @@ unsigned char RC2key[4][16]={
83 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}, 83 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F},
84 }; 84 };
85 85
86unsigned char RC2plain[4][8]={ 86static unsigned char RC2plain[4][8]={
87 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 87 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
88 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 88 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
89 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, 89 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
90 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 90 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
91 }; 91 };
92 92
93unsigned char RC2cipher[4][8]={ 93static unsigned char RC2cipher[4][8]={
94 {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7}, 94 {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7},
95 {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74}, 95 {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74},
96 {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E}, 96 {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E},
diff --git a/src/lib/libcrypto/rc4/rc4.h b/src/lib/libcrypto/rc4/rc4.h
index 7418c2a9a2..8556dddab0 100644
--- a/src/lib/libcrypto/rc4/rc4.h
+++ b/src/lib/libcrypto/rc4/rc4.h
@@ -77,8 +77,8 @@ typedef struct rc4_key_st
77 77
78 78
79const char *RC4_options(void); 79const char *RC4_options(void);
80void RC4_set_key(RC4_KEY *key, int len, unsigned char *data); 80void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
81void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata, 81void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
82 unsigned char *outdata); 82 unsigned char *outdata);
83 83
84#ifdef __cplusplus 84#ifdef __cplusplus
diff --git a/src/lib/libcrypto/rc4/rc4_enc.c b/src/lib/libcrypto/rc4/rc4_enc.c
index 3256bea8cc..d5f18a3a70 100644
--- a/src/lib/libcrypto/rc4/rc4_enc.c
+++ b/src/lib/libcrypto/rc4/rc4_enc.c
@@ -67,7 +67,7 @@
67 * Date: Wed, 14 Sep 1994 06:35:31 GMT 67 * Date: Wed, 14 Sep 1994 06:35:31 GMT
68 */ 68 */
69 69
70void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata, 70void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
71 unsigned char *outdata) 71 unsigned char *outdata)
72 { 72 {
73 register RC4_INT *d; 73 register RC4_INT *d;
@@ -78,6 +78,190 @@ void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata,
78 y=key->y; 78 y=key->y;
79 d=key->data; 79 d=key->data;
80 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
81#define LOOP(in,out) \ 265#define LOOP(in,out) \
82 x=((x+1)&0xff); \ 266 x=((x+1)&0xff); \
83 tx=d[x]; \ 267 tx=d[x]; \
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c
index c67a445f1f..bb10c1ebe2 100644
--- a/src/lib/libcrypto/rc4/rc4_skey.c
+++ b/src/lib/libcrypto/rc4/rc4_skey.c
@@ -85,7 +85,7 @@ const char *RC4_options(void)
85 * Date: Wed, 14 Sep 1994 06:35:31 GMT 85 * Date: Wed, 14 Sep 1994 06:35:31 GMT
86 */ 86 */
87 87
88void RC4_set_key(RC4_KEY *key, int len, register unsigned char *data) 88void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
89 { 89 {
90 register RC4_INT tmp; 90 register RC4_INT tmp;
91 register int id1,id2; 91 register int id1,id2;
diff --git a/src/lib/libcrypto/rc4/rc4speed.c b/src/lib/libcrypto/rc4/rc4speed.c
index 4fb5ebf573..b448f4a5c6 100644
--- a/src/lib/libcrypto/rc4/rc4speed.c
+++ b/src/lib/libcrypto/rc4/rc4speed.c
@@ -183,7 +183,7 @@ int main(int argc, char **argv)
183#endif 183#endif
184 184
185#ifndef TIMES 185#ifndef TIMES
186 printf("To get the most acurate results, try to run this\n"); 186 printf("To get the most accurate results, try to run this\n");
187 printf("program when this computer is idle.\n"); 187 printf("program when this computer is idle.\n");
188#endif 188#endif
189 189
diff --git a/src/lib/libcrypto/rc4/rc4test.c b/src/lib/libcrypto/rc4/rc4test.c
index 5abf8cff30..3914eb6c38 100644
--- a/src/lib/libcrypto/rc4/rc4test.c
+++ b/src/lib/libcrypto/rc4/rc4test.c
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
69#else 69#else
70#include <openssl/rc4.h> 70#include <openssl/rc4.h>
71 71
72unsigned char keys[7][30]={ 72static unsigned char keys[7][30]={
73 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, 73 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
74 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, 74 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
75 {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 75 {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
@@ -78,8 +78,8 @@ unsigned char keys[7][30]={
78 {4,0xef,0x01,0x23,0x45}, 78 {4,0xef,0x01,0x23,0x45},
79 }; 79 };
80 80
81unsigned char data_len[7]={8,8,8,20,28,10}; 81static unsigned char data_len[7]={8,8,8,20,28,10};
82unsigned char data[7][30]={ 82static unsigned char data[7][30]={
83 {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff}, 83 {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff},
84 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, 84 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
85 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, 85 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
@@ -94,7 +94,7 @@ unsigned char data[7][30]={
94 {0}, 94 {0},
95 }; 95 };
96 96
97unsigned char output[7][30]={ 97static unsigned char output[7][30]={
98 {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00}, 98 {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00},
99 {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00}, 99 {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00},
100 {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00}, 100 {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00},
diff --git a/src/lib/libcrypto/ripemd/Makefile.ssl b/src/lib/libcrypto/ripemd/Makefile.ssl
index 5b6d1d2599..c6153d4361 100644
--- a/src/lib/libcrypto/ripemd/Makefile.ssl
+++ b/src/lib/libcrypto/ripemd/Makefile.ssl
@@ -102,6 +102,7 @@ clean:
102 102
103# DO NOT DELETE THIS LINE -- make depend depends on it. 103# DO NOT DELETE THIS LINE -- make depend depends on it.
104 104
105rmd_dgst.o: ../../include/openssl/opensslconf.h
105rmd_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ripemd.h 106rmd_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ripemd.h
106rmd_dgst.o: rmd_locl.h rmdconst.h 107rmd_dgst.o: ../md32_common.h rmd_locl.h rmdconst.h
107rmd_one.o: ../../include/openssl/ripemd.h rmd_locl.h rmdconst.h 108rmd_one.o: ../../include/openssl/ripemd.h
diff --git a/src/lib/libcrypto/ripemd/asm/rips.cpp b/src/lib/libcrypto/ripemd/asm/rips.cpp
index 321a98443e..f7a13677a9 100644
--- a/src/lib/libcrypto/ripemd/asm/rips.cpp
+++ b/src/lib/libcrypto/ripemd/asm/rips.cpp
@@ -34,6 +34,8 @@ void GetTSC(unsigned long& tsc)
34#include <stdlib.h> 34#include <stdlib.h>
35#include <openssl/ripemd.h> 35#include <openssl/ripemd.h>
36 36
37#define ripemd160_block_x86 ripemd160_block_asm_host_order
38
37extern "C" { 39extern "C" {
38void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num); 40void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num);
39} 41}
@@ -55,8 +57,10 @@ void main(int argc,char *argv[])
55 if (num == 0) num=16; 57 if (num == 0) num=16;
56 if (num > 250) num=16; 58 if (num > 250) num=16;
57 numm=num+2; 59 numm=num+2;
60#if 0
58 num*=64; 61 num*=64;
59 numm*=64; 62 numm*=64;
63#endif
60 64
61 for (j=0; j<6; j++) 65 for (j=0; j<6; j++)
62 { 66 {
@@ -71,7 +75,7 @@ void main(int argc,char *argv[])
71 GetTSC(e2); 75 GetTSC(e2);
72 ripemd160_block_x86(&ctx,buffer,num); 76 ripemd160_block_x86(&ctx,buffer,num);
73 } 77 }
74 printf("ripemd160 (%d bytes) %d %d (%.2f)\n",num, 78 printf("ripemd160 (%d bytes) %d %d (%.2f)\n",num*64,
75 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2); 79 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
76 } 80 }
77 } 81 }
diff --git a/src/lib/libcrypto/ripemd/asm/rm-win32.asm b/src/lib/libcrypto/ripemd/asm/rm-win32.asm
index bd38791c13..f07d517857 100644
--- a/src/lib/libcrypto/ripemd/asm/rm-win32.asm
+++ b/src/lib/libcrypto/ripemd/asm/rm-win32.asm
@@ -8,1965 +8,1966 @@
8 .386 8 .386
9.model FLAT 9.model FLAT
10_TEXT SEGMENT 10_TEXT SEGMENT
11PUBLIC _ripemd160_block_x86 11PUBLIC _ripemd160_block_asm_host_order
12 12
13_ripemd160_block_x86 PROC NEAR 13_ripemd160_block_asm_host_order PROC NEAR
14 mov edx, DWORD PTR 4[esp]
15 mov eax, DWORD PTR 8[esp]
14 push esi 16 push esi
15 mov ecx, DWORD PTR 16[esp] 17 mov ecx, DWORD PTR [edx]
16 push edi 18 push edi
17 mov esi, DWORD PTR 16[esp] 19 mov esi, DWORD PTR 4[edx]
18 push ebp 20 push ebp
19 add ecx, esi 21 mov edi, DWORD PTR 8[edx]
20 push ebx 22 push ebx
21 sub ecx, 64 23 sub esp, 108
22 sub esp, 88
23 mov DWORD PTR [esp],ecx
24 mov edi, DWORD PTR 108[esp]
25L000start: 24L000start:
26 ; 25 ;
27 mov eax, DWORD PTR [esi] 26 mov ebx, DWORD PTR [eax]
28 mov ebx, DWORD PTR 4[esi] 27 mov ebp, DWORD PTR 4[eax]
29 mov DWORD PTR 4[esp],eax 28 mov DWORD PTR [esp],ebx
29 mov DWORD PTR 4[esp],ebp
30 mov ebx, DWORD PTR 8[eax]
31 mov ebp, DWORD PTR 12[eax]
30 mov DWORD PTR 8[esp],ebx 32 mov DWORD PTR 8[esp],ebx
31 mov eax, DWORD PTR 8[esi] 33 mov DWORD PTR 12[esp],ebp
32 mov ebx, DWORD PTR 12[esi] 34 mov ebx, DWORD PTR 16[eax]
33 mov DWORD PTR 12[esp],eax 35 mov ebp, DWORD PTR 20[eax]
34 mov DWORD PTR 16[esp],ebx 36 mov DWORD PTR 16[esp],ebx
35 mov eax, DWORD PTR 16[esi] 37 mov DWORD PTR 20[esp],ebp
36 mov ebx, DWORD PTR 20[esi] 38 mov ebx, DWORD PTR 24[eax]
37 mov DWORD PTR 20[esp],eax 39 mov ebp, DWORD PTR 28[eax]
38 mov DWORD PTR 24[esp],ebx 40 mov DWORD PTR 24[esp],ebx
39 mov eax, DWORD PTR 24[esi] 41 mov DWORD PTR 28[esp],ebp
40 mov ebx, DWORD PTR 28[esi] 42 mov ebx, DWORD PTR 32[eax]
41 mov DWORD PTR 28[esp],eax 43 mov ebp, DWORD PTR 36[eax]
42 mov DWORD PTR 32[esp],ebx 44 mov DWORD PTR 32[esp],ebx
43 mov eax, DWORD PTR 32[esi] 45 mov DWORD PTR 36[esp],ebp
44 mov ebx, DWORD PTR 36[esi] 46 mov ebx, DWORD PTR 40[eax]
45 mov DWORD PTR 36[esp],eax 47 mov ebp, DWORD PTR 44[eax]
46 mov DWORD PTR 40[esp],ebx 48 mov DWORD PTR 40[esp],ebx
47 mov eax, DWORD PTR 40[esi] 49 mov DWORD PTR 44[esp],ebp
48 mov ebx, DWORD PTR 44[esi] 50 mov ebx, DWORD PTR 48[eax]
49 mov DWORD PTR 44[esp],eax 51 mov ebp, DWORD PTR 52[eax]
50 mov DWORD PTR 48[esp],ebx 52 mov DWORD PTR 48[esp],ebx
51 mov eax, DWORD PTR 48[esi] 53 mov DWORD PTR 52[esp],ebp
52 mov ebx, DWORD PTR 52[esi] 54 mov ebx, DWORD PTR 56[eax]
53 mov DWORD PTR 52[esp],eax 55 mov ebp, DWORD PTR 60[eax]
54 mov DWORD PTR 56[esp],ebx 56 mov DWORD PTR 56[esp],ebx
55 mov eax, DWORD PTR 56[esi] 57 mov DWORD PTR 60[esp],ebp
56 mov ebx, DWORD PTR 60[esi] 58 mov eax, edi
57 mov DWORD PTR 60[esp],eax 59 mov ebx, DWORD PTR 12[edx]
58 mov DWORD PTR 64[esp],ebx 60 mov ebp, DWORD PTR 16[edx]
59 add esi, 64
60 mov eax, DWORD PTR [edi]
61 mov DWORD PTR 112[esp],esi
62 mov ebx, DWORD PTR 4[edi]
63 mov ecx, DWORD PTR 8[edi]
64 mov edx, DWORD PTR 12[edi]
65 mov ebp, DWORD PTR 16[edi]
66 ; 0 61 ; 0
67 mov esi, ecx 62 xor eax, ebx
68 xor esi, edx 63 mov edx, DWORD PTR [esp]
69 mov edi, DWORD PTR 4[esp] 64 xor eax, esi
70 xor esi, ebx 65 add ecx, edx
71 add eax, edi 66 rol edi, 10
72 rol ecx, 10 67 add ecx, eax
73 add eax, esi 68 mov eax, esi
74 mov esi, ebx 69 rol ecx, 11
75 rol eax, 11 70 add ecx, ebp
76 add eax, ebp
77 ; 1 71 ; 1
78 xor esi, ecx 72 xor eax, edi
79 mov edi, DWORD PTR 8[esp] 73 mov edx, DWORD PTR 4[esp]
80 xor esi, eax 74 xor eax, ecx
81 add ebp, esi 75 add ebp, eax
82 mov esi, eax 76 mov eax, ecx
83 rol ebx, 10 77 rol esi, 10
84 add ebp, edi
85 xor esi, ebx
86 rol ebp, 14
87 add ebp, edx 78 add ebp, edx
79 xor eax, esi
80 rol ebp, 14
81 add ebp, ebx
88 ; 2 82 ; 2
89 mov edi, DWORD PTR 12[esp] 83 mov edx, DWORD PTR 8[esp]
90 xor esi, ebp 84 xor eax, ebp
91 add edx, edi 85 add ebx, edx
92 rol eax, 10 86 rol ecx, 10
93 add edx, esi 87 add ebx, eax
94 mov esi, ebp 88 mov eax, ebp
95 rol edx, 15 89 rol ebx, 15
96 add edx, ecx 90 add ebx, edi
97 ; 3 91 ; 3
98 xor esi, eax 92 xor eax, ecx
99 mov edi, DWORD PTR 16[esp] 93 mov edx, DWORD PTR 12[esp]
100 xor esi, edx 94 xor eax, ebx
101 add ecx, esi 95 add edi, eax
102 mov esi, edx 96 mov eax, ebx
103 rol ebp, 10 97 rol ebp, 10
104 add ecx, edi 98 add edi, edx
105 xor esi, ebp 99 xor eax, ebp
106 rol ecx, 12 100 rol edi, 12
107 add ecx, ebx 101 add edi, esi
108 ; 4 102 ; 4
109 mov edi, DWORD PTR 20[esp] 103 mov edx, DWORD PTR 16[esp]
110 xor esi, ecx 104 xor eax, edi
111 add ebx, edi 105 add esi, edx
112 rol edx, 10 106 rol ebx, 10
113 add ebx, esi 107 add esi, eax
114 mov esi, ecx 108 mov eax, edi
115 rol ebx, 5 109 rol esi, 5
116 add ebx, eax 110 add esi, ecx
117 ; 5 111 ; 5
118 xor esi, edx 112 xor eax, ebx
119 mov edi, DWORD PTR 24[esp] 113 mov edx, DWORD PTR 20[esp]
120 xor esi, ebx 114 xor eax, esi
121 add eax, esi 115 add ecx, eax
122 mov esi, ebx 116 mov eax, esi
123 rol ecx, 10 117 rol edi, 10
124 add eax, edi 118 add ecx, edx
125 xor esi, ecx 119 xor eax, edi
126 rol eax, 8 120 rol ecx, 8
127 add eax, ebp 121 add ecx, ebp
128 ; 6 122 ; 6
129 mov edi, DWORD PTR 28[esp] 123 mov edx, DWORD PTR 24[esp]
130 xor esi, eax 124 xor eax, ecx
131 add ebp, edi
132 rol ebx, 10
133 add ebp, esi
134 mov esi, eax
135 rol ebp, 7
136 add ebp, edx 125 add ebp, edx
126 rol esi, 10
127 add ebp, eax
128 mov eax, ecx
129 rol ebp, 7
130 add ebp, ebx
137 ; 7 131 ; 7
138 xor esi, ebx 132 xor eax, esi
139 mov edi, DWORD PTR 32[esp] 133 mov edx, DWORD PTR 28[esp]
140 xor esi, ebp 134 xor eax, ebp
141 add edx, esi 135 add ebx, eax
142 mov esi, ebp 136 mov eax, ebp
143 rol eax, 10 137 rol ecx, 10
144 add edx, edi 138 add ebx, edx
145 xor esi, eax 139 xor eax, ecx
146 rol edx, 9 140 rol ebx, 9
147 add edx, ecx 141 add ebx, edi
148 ; 8 142 ; 8
149 mov edi, DWORD PTR 36[esp] 143 mov edx, DWORD PTR 32[esp]
150 xor esi, edx 144 xor eax, ebx
151 add ecx, edi 145 add edi, edx
152 rol ebp, 10 146 rol ebp, 10
153 add ecx, esi 147 add edi, eax
154 mov esi, edx 148 mov eax, ebx
155 rol ecx, 11 149 rol edi, 11
156 add ecx, ebx 150 add edi, esi
157 ; 9 151 ; 9
158 xor esi, ebp 152 xor eax, ebp
159 mov edi, DWORD PTR 40[esp] 153 mov edx, DWORD PTR 36[esp]
160 xor esi, ecx 154 xor eax, edi
161 add ebx, esi 155 add esi, eax
162 mov esi, ecx 156 mov eax, edi
163 rol edx, 10 157 rol ebx, 10
164 add ebx, edi 158 add esi, edx
165 xor esi, edx 159 xor eax, ebx
166 rol ebx, 13 160 rol esi, 13
167 add ebx, eax 161 add esi, ecx
168 ; 10 162 ; 10
169 mov edi, DWORD PTR 44[esp] 163 mov edx, DWORD PTR 40[esp]
170 xor esi, ebx 164 xor eax, esi
171 add eax, edi 165 add ecx, edx
172 rol ecx, 10 166 rol edi, 10
173 add eax, esi 167 add ecx, eax
174 mov esi, ebx 168 mov eax, esi
175 rol eax, 14 169 rol ecx, 14
176 add eax, ebp 170 add ecx, ebp
177 ; 11 171 ; 11
178 xor esi, ecx 172 xor eax, edi
179 mov edi, DWORD PTR 48[esp] 173 mov edx, DWORD PTR 44[esp]
180 xor esi, eax 174 xor eax, ecx
181 add ebp, esi 175 add ebp, eax
182 mov esi, eax 176 mov eax, ecx
183 rol ebx, 10 177 rol esi, 10
184 add ebp, edi
185 xor esi, ebx
186 rol ebp, 15
187 add ebp, edx 178 add ebp, edx
179 xor eax, esi
180 rol ebp, 15
181 add ebp, ebx
188 ; 12 182 ; 12
189 mov edi, DWORD PTR 52[esp] 183 mov edx, DWORD PTR 48[esp]
190 xor esi, ebp 184 xor eax, ebp
191 add edx, edi 185 add ebx, edx
192 rol eax, 10 186 rol ecx, 10
193 add edx, esi 187 add ebx, eax
194 mov esi, ebp 188 mov eax, ebp
195 rol edx, 6 189 rol ebx, 6
196 add edx, ecx 190 add ebx, edi
197 ; 13 191 ; 13
198 xor esi, eax 192 xor eax, ecx
199 mov edi, DWORD PTR 56[esp] 193 mov edx, DWORD PTR 52[esp]
200 xor esi, edx 194 xor eax, ebx
201 add ecx, esi 195 add edi, eax
202 mov esi, edx 196 mov eax, ebx
203 rol ebp, 10 197 rol ebp, 10
204 add ecx, edi 198 add edi, edx
205 xor esi, ebp 199 xor eax, ebp
206 rol ecx, 7 200 rol edi, 7
207 add ecx, ebx 201 add edi, esi
208 ; 14 202 ; 14
209 mov edi, DWORD PTR 60[esp] 203 mov edx, DWORD PTR 56[esp]
210 xor esi, ecx 204 xor eax, edi
211 add ebx, edi 205 add esi, edx
212 rol edx, 10 206 rol ebx, 10
213 add ebx, esi 207 add esi, eax
214 mov esi, ecx 208 mov eax, edi
215 rol ebx, 9 209 rol esi, 9
216 add ebx, eax 210 add esi, ecx
217 ; 15 211 ; 15
218 xor esi, edx 212 xor eax, ebx
219 mov edi, DWORD PTR 64[esp] 213 mov edx, DWORD PTR 60[esp]
220 xor esi, ebx 214 xor eax, esi
221 add eax, esi 215 add ecx, eax
222 mov esi, -1 216 mov eax, -1
223 rol ecx, 10 217 rol edi, 10
224 add eax, edi 218 add ecx, edx
225 mov edi, DWORD PTR 32[esp] 219 mov edx, DWORD PTR 28[esp]
226 rol eax, 8 220 rol ecx, 8
227 add eax, ebp 221 add ecx, ebp
228 ; 16 222 ; 16
229 add ebp, edi
230 mov edi, ebx
231 sub esi, eax
232 and edi, eax
233 and esi, ecx
234 or edi, esi
235 mov esi, DWORD PTR 20[esp]
236 rol ebx, 10
237 lea ebp, DWORD PTR 1518500249[edi*1+ebp]
238 mov edi, -1
239 rol ebp, 7
240 add ebp, edx 223 add ebp, edx
224 mov edx, esi
225 sub eax, ecx
226 and edx, ecx
227 and eax, edi
228 or edx, eax
229 mov eax, DWORD PTR 16[esp]
230 rol esi, 10
231 lea ebp, DWORD PTR 1518500249[edx*1+ebp]
232 mov edx, -1
233 rol ebp, 7
234 add ebp, ebx
241 ; 17 235 ; 17
242 add edx, esi 236 add ebx, eax
243 mov esi, eax 237 mov eax, ecx
244 sub edi, ebp 238 sub edx, ebp
245 and esi, ebp 239 and eax, ebp
246 and edi, ebx 240 and edx, esi
247 or esi, edi 241 or eax, edx
248 mov edi, DWORD PTR 56[esp] 242 mov edx, DWORD PTR 52[esp]
249 rol eax, 10 243 rol ecx, 10
250 lea edx, DWORD PTR 1518500249[esi*1+edx] 244 lea ebx, DWORD PTR 1518500249[eax*1+ebx]
251 mov esi, -1 245 mov eax, -1
252 rol edx, 6 246 rol ebx, 6
253 add edx, ecx 247 add ebx, edi
254 ; 18 248 ; 18
255 add ecx, edi 249 add edi, edx
256 mov edi, ebp 250 mov edx, ebp
257 sub esi, edx 251 sub eax, ebx
258 and edi, edx 252 and edx, ebx
259 and esi, eax 253 and eax, ecx
260 or edi, esi 254 or edx, eax
261 mov esi, DWORD PTR 8[esp] 255 mov eax, DWORD PTR 4[esp]
262 rol ebp, 10 256 rol ebp, 10
263 lea ecx, DWORD PTR 1518500249[edi*1+ecx] 257 lea edi, DWORD PTR 1518500249[edx*1+edi]
264 mov edi, -1 258 mov edx, -1
265 rol ecx, 8 259 rol edi, 8
266 add ecx, ebx 260 add edi, esi
267 ; 19 261 ; 19
268 add ebx, esi 262 add esi, eax
269 mov esi, edx 263 mov eax, ebx
270 sub edi, ecx 264 sub edx, edi
271 and esi, ecx 265 and eax, edi
272 and edi, ebp 266 and edx, ebp
273 or esi, edi 267 or eax, edx
274 mov edi, DWORD PTR 44[esp] 268 mov edx, DWORD PTR 40[esp]
275 rol edx, 10 269 rol ebx, 10
276 lea ebx, DWORD PTR 1518500249[esi*1+ebx] 270 lea esi, DWORD PTR 1518500249[eax*1+esi]
277 mov esi, -1 271 mov eax, -1
278 rol ebx, 13 272 rol esi, 13
279 add ebx, eax 273 add esi, ecx
280 ; 20 274 ; 20
281 add eax, edi 275 add ecx, edx
282 mov edi, ecx 276 mov edx, edi
283 sub esi, ebx 277 sub eax, esi
284 and edi, ebx 278 and edx, esi
285 and esi, edx 279 and eax, ebx
286 or edi, esi 280 or edx, eax
287 mov esi, DWORD PTR 28[esp] 281 mov eax, DWORD PTR 24[esp]
288 rol ecx, 10 282 rol edi, 10
289 lea eax, DWORD PTR 1518500249[edi*1+eax] 283 lea ecx, DWORD PTR 1518500249[edx*1+ecx]
290 mov edi, -1 284 mov edx, -1
291 rol eax, 11 285 rol ecx, 11
292 add eax, ebp 286 add ecx, ebp
293 ; 21 287 ; 21
294 add ebp, esi 288 add ebp, eax
295 mov esi, ebx 289 mov eax, esi
296 sub edi, eax 290 sub edx, ecx
297 and esi, eax 291 and eax, ecx
298 and edi, ecx 292 and edx, edi
299 or esi, edi 293 or eax, edx
300 mov edi, DWORD PTR 64[esp] 294 mov edx, DWORD PTR 60[esp]
301 rol ebx, 10 295 rol esi, 10
302 lea ebp, DWORD PTR 1518500249[esi*1+ebp] 296 lea ebp, DWORD PTR 1518500249[eax*1+ebp]
303 mov esi, -1 297 mov eax, -1
304 rol ebp, 9 298 rol ebp, 9
305 add ebp, edx 299 add ebp, ebx
306 ; 22 300 ; 22
307 add edx, edi 301 add ebx, edx
308 mov edi, eax 302 mov edx, ecx
309 sub esi, ebp 303 sub eax, ebp
310 and edi, ebp 304 and edx, ebp
311 and esi, ebx 305 and eax, esi
312 or edi, esi 306 or edx, eax
313 mov esi, DWORD PTR 16[esp] 307 mov eax, DWORD PTR 12[esp]
314 rol eax, 10 308 rol ecx, 10
315 lea edx, DWORD PTR 1518500249[edi*1+edx] 309 lea ebx, DWORD PTR 1518500249[edx*1+ebx]
316 mov edi, -1 310 mov edx, -1
317 rol edx, 7 311 rol ebx, 7
318 add edx, ecx 312 add ebx, edi
319 ; 23 313 ; 23
320 add ecx, esi 314 add edi, eax
321 mov esi, ebp 315 mov eax, ebp
322 sub edi, edx 316 sub edx, ebx
323 and esi, edx 317 and eax, ebx
324 and edi, eax 318 and edx, ecx
325 or esi, edi 319 or eax, edx
326 mov edi, DWORD PTR 52[esp] 320 mov edx, DWORD PTR 48[esp]
327 rol ebp, 10 321 rol ebp, 10
328 lea ecx, DWORD PTR 1518500249[esi*1+ecx] 322 lea edi, DWORD PTR 1518500249[eax*1+edi]
329 mov esi, -1 323 mov eax, -1
330 rol ecx, 15 324 rol edi, 15
331 add ecx, ebx 325 add edi, esi
332 ; 24 326 ; 24
333 add ebx, edi 327 add esi, edx
334 mov edi, edx 328 mov edx, ebx
335 sub esi, ecx 329 sub eax, edi
336 and edi, ecx 330 and edx, edi
337 and esi, ebp 331 and eax, ebp
338 or edi, esi 332 or edx, eax
339 mov esi, DWORD PTR 4[esp] 333 mov eax, DWORD PTR [esp]
340 rol edx, 10 334 rol ebx, 10
341 lea ebx, DWORD PTR 1518500249[edi*1+ebx] 335 lea esi, DWORD PTR 1518500249[edx*1+esi]
342 mov edi, -1 336 mov edx, -1
343 rol ebx, 7 337 rol esi, 7
344 add ebx, eax 338 add esi, ecx
345 ; 25 339 ; 25
346 add eax, esi 340 add ecx, eax
347 mov esi, ecx 341 mov eax, edi
348 sub edi, ebx 342 sub edx, esi
349 and esi, ebx 343 and eax, esi
350 and edi, edx 344 and edx, ebx
351 or esi, edi 345 or eax, edx
352 mov edi, DWORD PTR 40[esp] 346 mov edx, DWORD PTR 36[esp]
353 rol ecx, 10 347 rol edi, 10
354 lea eax, DWORD PTR 1518500249[esi*1+eax] 348 lea ecx, DWORD PTR 1518500249[eax*1+ecx]
355 mov esi, -1 349 mov eax, -1
356 rol eax, 12 350 rol ecx, 12
357 add eax, ebp 351 add ecx, ebp
358 ; 26 352 ; 26
359 add ebp, edi
360 mov edi, ebx
361 sub esi, eax
362 and edi, eax
363 and esi, ecx
364 or edi, esi
365 mov esi, DWORD PTR 24[esp]
366 rol ebx, 10
367 lea ebp, DWORD PTR 1518500249[edi*1+ebp]
368 mov edi, -1
369 rol ebp, 15
370 add ebp, edx 353 add ebp, edx
354 mov edx, esi
355 sub eax, ecx
356 and edx, ecx
357 and eax, edi
358 or edx, eax
359 mov eax, DWORD PTR 20[esp]
360 rol esi, 10
361 lea ebp, DWORD PTR 1518500249[edx*1+ebp]
362 mov edx, -1
363 rol ebp, 15
364 add ebp, ebx
371 ; 27 365 ; 27
372 add edx, esi 366 add ebx, eax
373 mov esi, eax 367 mov eax, ecx
374 sub edi, ebp 368 sub edx, ebp
375 and esi, ebp 369 and eax, ebp
376 and edi, ebx 370 and edx, esi
377 or esi, edi 371 or eax, edx
378 mov edi, DWORD PTR 12[esp] 372 mov edx, DWORD PTR 8[esp]
379 rol eax, 10 373 rol ecx, 10
380 lea edx, DWORD PTR 1518500249[esi*1+edx] 374 lea ebx, DWORD PTR 1518500249[eax*1+ebx]
381 mov esi, -1 375 mov eax, -1
382 rol edx, 9 376 rol ebx, 9
383 add edx, ecx 377 add ebx, edi
384 ; 28 378 ; 28
385 add ecx, edi 379 add edi, edx
386 mov edi, ebp 380 mov edx, ebp
387 sub esi, edx 381 sub eax, ebx
388 and edi, edx 382 and edx, ebx
389 and esi, eax 383 and eax, ecx
390 or edi, esi 384 or edx, eax
391 mov esi, DWORD PTR 60[esp] 385 mov eax, DWORD PTR 56[esp]
392 rol ebp, 10 386 rol ebp, 10
393 lea ecx, DWORD PTR 1518500249[edi*1+ecx] 387 lea edi, DWORD PTR 1518500249[edx*1+edi]
394 mov edi, -1 388 mov edx, -1
395 rol ecx, 11 389 rol edi, 11
396 add ecx, ebx 390 add edi, esi
397 ; 29 391 ; 29
398 add ebx, esi 392 add esi, eax
399 mov esi, edx 393 mov eax, ebx
400 sub edi, ecx 394 sub edx, edi
401 and esi, ecx 395 and eax, edi
402 and edi, ebp 396 and edx, ebp
403 or esi, edi 397 or eax, edx
404 mov edi, DWORD PTR 48[esp] 398 mov edx, DWORD PTR 44[esp]
405 rol edx, 10 399 rol ebx, 10
406 lea ebx, DWORD PTR 1518500249[esi*1+ebx] 400 lea esi, DWORD PTR 1518500249[eax*1+esi]
407 mov esi, -1 401 mov eax, -1
408 rol ebx, 7 402 rol esi, 7
409 add ebx, eax 403 add esi, ecx
410 ; 30 404 ; 30
411 add eax, edi 405 add ecx, edx
412 mov edi, ecx 406 mov edx, edi
413 sub esi, ebx 407 sub eax, esi
414 and edi, ebx 408 and edx, esi
415 and esi, edx 409 and eax, ebx
416 or edi, esi 410 or edx, eax
417 mov esi, DWORD PTR 36[esp] 411 mov eax, DWORD PTR 32[esp]
418 rol ecx, 10 412 rol edi, 10
419 lea eax, DWORD PTR 1518500249[edi*1+eax] 413 lea ecx, DWORD PTR 1518500249[edx*1+ecx]
420 mov edi, -1 414 mov edx, -1
421 rol eax, 13 415 rol ecx, 13
422 add eax, ebp 416 add ecx, ebp
423 ; 31 417 ; 31
424 add ebp, esi 418 add ebp, eax
425 mov esi, ebx 419 mov eax, esi
426 sub edi, eax 420 sub edx, ecx
427 and esi, eax 421 and eax, ecx
428 and edi, ecx 422 and edx, edi
429 or esi, edi 423 or eax, edx
430 mov edi, -1 424 mov edx, -1
431 rol ebx, 10 425 rol esi, 10
432 lea ebp, DWORD PTR 1518500249[esi*1+ebp] 426 lea ebp, DWORD PTR 1518500249[eax*1+ebp]
433 sub edi, eax 427 sub edx, ecx
434 rol ebp, 12 428 rol ebp, 12
435 add ebp, edx 429 add ebp, ebx
436 ; 32 430 ; 32
437 mov esi, DWORD PTR 16[esp] 431 mov eax, DWORD PTR 12[esp]
438 or edi, ebp 432 or edx, ebp
439 add edx, esi 433 add ebx, eax
440 xor edi, ebx 434 xor edx, esi
441 mov esi, -1 435 mov eax, -1
442 rol eax, 10 436 rol ecx, 10
443 lea edx, DWORD PTR 1859775393[edi*1+edx] 437 lea ebx, DWORD PTR 1859775393[edx*1+ebx]
444 sub esi, ebp 438 sub eax, ebp
445 rol edx, 11 439 rol ebx, 11
446 add edx, ecx 440 add ebx, edi
447 ; 33 441 ; 33
448 mov edi, DWORD PTR 44[esp] 442 mov edx, DWORD PTR 40[esp]
449 or esi, edx 443 or eax, ebx
450 add ecx, edi 444 add edi, edx
451 xor esi, eax 445 xor eax, ecx
452 mov edi, -1 446 mov edx, -1
453 rol ebp, 10 447 rol ebp, 10
454 lea ecx, DWORD PTR 1859775393[esi*1+ecx] 448 lea edi, DWORD PTR 1859775393[eax*1+edi]
455 sub edi, edx 449 sub edx, ebx
456 rol ecx, 13 450 rol edi, 13
457 add ecx, ebx 451 add edi, esi
458 ; 34 452 ; 34
459 mov esi, DWORD PTR 60[esp] 453 mov eax, DWORD PTR 56[esp]
460 or edi, ecx 454 or edx, edi
461 add ebx, esi 455 add esi, eax
462 xor edi, ebp 456 xor edx, ebp
463 mov esi, -1 457 mov eax, -1
464 rol edx, 10 458 rol ebx, 10
465 lea ebx, DWORD PTR 1859775393[edi*1+ebx] 459 lea esi, DWORD PTR 1859775393[edx*1+esi]
466 sub esi, ecx 460 sub eax, edi
467 rol ebx, 6 461 rol esi, 6
468 add ebx, eax 462 add esi, ecx
469 ; 35 463 ; 35
470 mov edi, DWORD PTR 20[esp] 464 mov edx, DWORD PTR 16[esp]
471 or esi, ebx 465 or eax, esi
472 add eax, edi 466 add ecx, edx
473 xor esi, edx 467 xor eax, ebx
474 mov edi, -1 468 mov edx, -1
475 rol ecx, 10 469 rol edi, 10
476 lea eax, DWORD PTR 1859775393[esi*1+eax] 470 lea ecx, DWORD PTR 1859775393[eax*1+ecx]
477 sub edi, ebx 471 sub edx, esi
478 rol eax, 7 472 rol ecx, 7
479 add eax, ebp 473 add ecx, ebp
480 ; 36 474 ; 36
481 mov esi, DWORD PTR 40[esp] 475 mov eax, DWORD PTR 36[esp]
482 or edi, eax 476 or edx, ecx
483 add ebp, esi 477 add ebp, eax
484 xor edi, ecx 478 xor edx, edi
485 mov esi, -1 479 mov eax, -1
486 rol ebx, 10 480 rol esi, 10
487 lea ebp, DWORD PTR 1859775393[edi*1+ebp] 481 lea ebp, DWORD PTR 1859775393[edx*1+ebp]
488 sub esi, eax 482 sub eax, ecx
489 rol ebp, 14 483 rol ebp, 14
490 add ebp, edx 484 add ebp, ebx
491 ; 37 485 ; 37
492 mov edi, DWORD PTR 64[esp] 486 mov edx, DWORD PTR 60[esp]
493 or esi, ebp 487 or eax, ebp
494 add edx, edi 488 add ebx, edx
495 xor esi, ebx 489 xor eax, esi
496 mov edi, -1 490 mov edx, -1
497 rol eax, 10 491 rol ecx, 10
498 lea edx, DWORD PTR 1859775393[esi*1+edx] 492 lea ebx, DWORD PTR 1859775393[eax*1+ebx]
499 sub edi, ebp 493 sub edx, ebp
500 rol edx, 9 494 rol ebx, 9
501 add edx, ecx 495 add ebx, edi
502 ; 38 496 ; 38
503 mov esi, DWORD PTR 36[esp] 497 mov eax, DWORD PTR 32[esp]
504 or edi, edx 498 or edx, ebx
505 add ecx, esi 499 add edi, eax
506 xor edi, eax 500 xor edx, ecx
507 mov esi, -1 501 mov eax, -1
508 rol ebp, 10 502 rol ebp, 10
509 lea ecx, DWORD PTR 1859775393[edi*1+ecx] 503 lea edi, DWORD PTR 1859775393[edx*1+edi]
510 sub esi, edx 504 sub eax, ebx
511 rol ecx, 13 505 rol edi, 13
512 add ecx, ebx 506 add edi, esi
513 ; 39 507 ; 39
514 mov edi, DWORD PTR 8[esp] 508 mov edx, DWORD PTR 4[esp]
515 or esi, ecx 509 or eax, edi
516 add ebx, edi 510 add esi, edx
517 xor esi, ebp 511 xor eax, ebp
518 mov edi, -1 512 mov edx, -1
519 rol edx, 10 513 rol ebx, 10
520 lea ebx, DWORD PTR 1859775393[esi*1+ebx] 514 lea esi, DWORD PTR 1859775393[eax*1+esi]
521 sub edi, ecx 515 sub edx, edi
522 rol ebx, 15 516 rol esi, 15
523 add ebx, eax 517 add esi, ecx
524 ; 40 518 ; 40
525 mov esi, DWORD PTR 12[esp] 519 mov eax, DWORD PTR 8[esp]
526 or edi, ebx 520 or edx, esi
527 add eax, esi 521 add ecx, eax
528 xor edi, edx 522 xor edx, ebx
529 mov esi, -1 523 mov eax, -1
530 rol ecx, 10 524 rol edi, 10
531 lea eax, DWORD PTR 1859775393[edi*1+eax] 525 lea ecx, DWORD PTR 1859775393[edx*1+ecx]
532 sub esi, ebx 526 sub eax, esi
533 rol eax, 14 527 rol ecx, 14
534 add eax, ebp 528 add ecx, ebp
535 ; 41 529 ; 41
536 mov edi, DWORD PTR 32[esp] 530 mov edx, DWORD PTR 28[esp]
537 or esi, eax 531 or eax, ecx
538 add ebp, edi
539 xor esi, ecx
540 mov edi, -1
541 rol ebx, 10
542 lea ebp, DWORD PTR 1859775393[esi*1+ebp]
543 sub edi, eax
544 rol ebp, 8
545 add ebp, edx 532 add ebp, edx
533 xor eax, edi
534 mov edx, -1
535 rol esi, 10
536 lea ebp, DWORD PTR 1859775393[eax*1+ebp]
537 sub edx, ecx
538 rol ebp, 8
539 add ebp, ebx
546 ; 42 540 ; 42
547 mov esi, DWORD PTR 4[esp] 541 mov eax, DWORD PTR [esp]
548 or edi, ebp 542 or edx, ebp
549 add edx, esi 543 add ebx, eax
550 xor edi, ebx 544 xor edx, esi
551 mov esi, -1 545 mov eax, -1
552 rol eax, 10 546 rol ecx, 10
553 lea edx, DWORD PTR 1859775393[edi*1+edx] 547 lea ebx, DWORD PTR 1859775393[edx*1+ebx]
554 sub esi, ebp 548 sub eax, ebp
555 rol edx, 13 549 rol ebx, 13
556 add edx, ecx 550 add ebx, edi
557 ; 43 551 ; 43
558 mov edi, DWORD PTR 28[esp] 552 mov edx, DWORD PTR 24[esp]
559 or esi, edx 553 or eax, ebx
560 add ecx, edi 554 add edi, edx
561 xor esi, eax 555 xor eax, ecx
562 mov edi, -1 556 mov edx, -1
563 rol ebp, 10 557 rol ebp, 10
564 lea ecx, DWORD PTR 1859775393[esi*1+ecx] 558 lea edi, DWORD PTR 1859775393[eax*1+edi]
565 sub edi, edx 559 sub edx, ebx
566 rol ecx, 6 560 rol edi, 6
567 add ecx, ebx 561 add edi, esi
568 ; 44 562 ; 44
569 mov esi, DWORD PTR 56[esp] 563 mov eax, DWORD PTR 52[esp]
570 or edi, ecx 564 or edx, edi
571 add ebx, esi 565 add esi, eax
572 xor edi, ebp 566 xor edx, ebp
573 mov esi, -1 567 mov eax, -1
574 rol edx, 10 568 rol ebx, 10
575 lea ebx, DWORD PTR 1859775393[edi*1+ebx] 569 lea esi, DWORD PTR 1859775393[edx*1+esi]
576 sub esi, ecx 570 sub eax, edi
577 rol ebx, 5 571 rol esi, 5
578 add ebx, eax 572 add esi, ecx
579 ; 45 573 ; 45
580 mov edi, DWORD PTR 48[esp] 574 mov edx, DWORD PTR 44[esp]
581 or esi, ebx 575 or eax, esi
582 add eax, edi 576 add ecx, edx
583 xor esi, edx 577 xor eax, ebx
584 mov edi, -1 578 mov edx, -1
585 rol ecx, 10 579 rol edi, 10
586 lea eax, DWORD PTR 1859775393[esi*1+eax] 580 lea ecx, DWORD PTR 1859775393[eax*1+ecx]
587 sub edi, ebx 581 sub edx, esi
588 rol eax, 12 582 rol ecx, 12
589 add eax, ebp 583 add ecx, ebp
590 ; 46 584 ; 46
591 mov esi, DWORD PTR 24[esp] 585 mov eax, DWORD PTR 20[esp]
592 or edi, eax 586 or edx, ecx
593 add ebp, esi 587 add ebp, eax
594 xor edi, ecx 588 xor edx, edi
595 mov esi, -1 589 mov eax, -1
596 rol ebx, 10 590 rol esi, 10
597 lea ebp, DWORD PTR 1859775393[edi*1+ebp] 591 lea ebp, DWORD PTR 1859775393[edx*1+ebp]
598 sub esi, eax 592 sub eax, ecx
599 rol ebp, 7 593 rol ebp, 7
600 add ebp, edx 594 add ebp, ebx
601 ; 47 595 ; 47
602 mov edi, DWORD PTR 52[esp] 596 mov edx, DWORD PTR 48[esp]
603 or esi, ebp 597 or eax, ebp
604 add edx, edi 598 add ebx, edx
605 xor esi, ebx 599 xor eax, esi
606 mov edi, -1 600 mov edx, -1
607 rol eax, 10 601 rol ecx, 10
608 lea edx, DWORD PTR 1859775393[esi*1+edx] 602 lea ebx, DWORD PTR 1859775393[eax*1+ebx]
609 mov esi, eax 603 mov eax, ecx
610 rol edx, 5 604 rol ebx, 5
611 add edx, ecx 605 add ebx, edi
612 ; 48 606 ; 48
613 sub edi, eax 607 sub edx, ecx
614 and esi, edx 608 and eax, ebx
615 and edi, ebp 609 and edx, ebp
616 or edi, esi 610 or edx, eax
617 mov esi, DWORD PTR 8[esp] 611 mov eax, DWORD PTR 4[esp]
618 rol ebp, 10 612 rol ebp, 10
619 lea ecx, DWORD PTR 2400959708[edi+ecx] 613 lea edi, DWORD PTR 2400959708[edx+edi]
620 mov edi, -1 614 mov edx, -1
621 add ecx, esi 615 add edi, eax
622 mov esi, ebp 616 mov eax, ebp
623 rol ecx, 11 617 rol edi, 11
624 add ecx, ebx 618 add edi, esi
625 ; 49 619 ; 49
626 sub edi, ebp 620 sub edx, ebp
627 and esi, ecx 621 and eax, edi
628 and edi, edx 622 and edx, ebx
629 or edi, esi 623 or edx, eax
630 mov esi, DWORD PTR 40[esp] 624 mov eax, DWORD PTR 36[esp]
631 rol edx, 10 625 rol ebx, 10
632 lea ebx, DWORD PTR 2400959708[edi+ebx] 626 lea esi, DWORD PTR 2400959708[edx+esi]
633 mov edi, -1 627 mov edx, -1
634 add ebx, esi 628 add esi, eax
635 mov esi, edx 629 mov eax, ebx
636 rol ebx, 12 630 rol esi, 12
637 add ebx, eax 631 add esi, ecx
638 ; 50 632 ; 50
639 sub edi, edx 633 sub edx, ebx
640 and esi, ebx 634 and eax, esi
641 and edi, ecx 635 and edx, edi
642 or edi, esi 636 or edx, eax
643 mov esi, DWORD PTR 48[esp] 637 mov eax, DWORD PTR 44[esp]
644 rol ecx, 10 638 rol edi, 10
645 lea eax, DWORD PTR 2400959708[edi+eax] 639 lea ecx, DWORD PTR 2400959708[edx+ecx]
646 mov edi, -1 640 mov edx, -1
647 add eax, esi 641 add ecx, eax
648 mov esi, ecx 642 mov eax, edi
649 rol eax, 14 643 rol ecx, 14
650 add eax, ebp 644 add ecx, ebp
651 ; 51 645 ; 51
652 sub edi, ecx 646 sub edx, edi
653 and esi, eax 647 and eax, ecx
654 and edi, ebx 648 and edx, esi
655 or edi, esi 649 or edx, eax
656 mov esi, DWORD PTR 44[esp] 650 mov eax, DWORD PTR 40[esp]
657 rol ebx, 10 651 rol esi, 10
658 lea ebp, DWORD PTR 2400959708[edi+ebp] 652 lea ebp, DWORD PTR 2400959708[edx+ebp]
659 mov edi, -1 653 mov edx, -1
660 add ebp, esi 654 add ebp, eax
661 mov esi, ebx 655 mov eax, esi
662 rol ebp, 15 656 rol ebp, 15
663 add ebp, edx 657 add ebp, ebx
664 ; 52 658 ; 52
665 sub edi, ebx 659 sub edx, esi
666 and esi, ebp 660 and eax, ebp
667 and edi, eax 661 and edx, ecx
668 or edi, esi 662 or edx, eax
669 mov esi, DWORD PTR 4[esp] 663 mov eax, DWORD PTR [esp]
670 rol eax, 10 664 rol ecx, 10
671 lea edx, DWORD PTR 2400959708[edi+edx] 665 lea ebx, DWORD PTR 2400959708[edx+ebx]
672 mov edi, -1 666 mov edx, -1
673 add edx, esi 667 add ebx, eax
674 mov esi, eax 668 mov eax, ecx
675 rol edx, 14 669 rol ebx, 14
676 add edx, ecx 670 add ebx, edi
677 ; 53 671 ; 53
678 sub edi, eax 672 sub edx, ecx
679 and esi, edx 673 and eax, ebx
680 and edi, ebp 674 and edx, ebp
681 or edi, esi 675 or edx, eax
682 mov esi, DWORD PTR 36[esp] 676 mov eax, DWORD PTR 32[esp]
683 rol ebp, 10 677 rol ebp, 10
684 lea ecx, DWORD PTR 2400959708[edi+ecx] 678 lea edi, DWORD PTR 2400959708[edx+edi]
685 mov edi, -1 679 mov edx, -1
686 add ecx, esi 680 add edi, eax
687 mov esi, ebp 681 mov eax, ebp
688 rol ecx, 15 682 rol edi, 15
689 add ecx, ebx 683 add edi, esi
690 ; 54 684 ; 54
691 sub edi, ebp 685 sub edx, ebp
692 and esi, ecx 686 and eax, edi
693 and edi, edx 687 and edx, ebx
694 or edi, esi 688 or edx, eax
695 mov esi, DWORD PTR 52[esp] 689 mov eax, DWORD PTR 48[esp]
696 rol edx, 10 690 rol ebx, 10
697 lea ebx, DWORD PTR 2400959708[edi+ebx] 691 lea esi, DWORD PTR 2400959708[edx+esi]
698 mov edi, -1 692 mov edx, -1
699 add ebx, esi 693 add esi, eax
700 mov esi, edx 694 mov eax, ebx
701 rol ebx, 9 695 rol esi, 9
702 add ebx, eax 696 add esi, ecx
703 ; 55 697 ; 55
704 sub edi, edx 698 sub edx, ebx
705 and esi, ebx 699 and eax, esi
706 and edi, ecx 700 and edx, edi
707 or edi, esi 701 or edx, eax
708 mov esi, DWORD PTR 20[esp] 702 mov eax, DWORD PTR 16[esp]
709 rol ecx, 10 703 rol edi, 10
710 lea eax, DWORD PTR 2400959708[edi+eax] 704 lea ecx, DWORD PTR 2400959708[edx+ecx]
711 mov edi, -1 705 mov edx, -1
712 add eax, esi 706 add ecx, eax
713 mov esi, ecx 707 mov eax, edi
714 rol eax, 8 708 rol ecx, 8
715 add eax, ebp 709 add ecx, ebp
716 ; 56 710 ; 56
717 sub edi, ecx 711 sub edx, edi
718 and esi, eax 712 and eax, ecx
719 and edi, ebx 713 and edx, esi
720 or edi, esi 714 or edx, eax
721 mov esi, DWORD PTR 56[esp] 715 mov eax, DWORD PTR 52[esp]
722 rol ebx, 10 716 rol esi, 10
723 lea ebp, DWORD PTR 2400959708[edi+ebp] 717 lea ebp, DWORD PTR 2400959708[edx+ebp]
724 mov edi, -1 718 mov edx, -1
725 add ebp, esi 719 add ebp, eax
726 mov esi, ebx 720 mov eax, esi
727 rol ebp, 9 721 rol ebp, 9
728 add ebp, edx 722 add ebp, ebx
729 ; 57 723 ; 57
730 sub edi, ebx 724 sub edx, esi
731 and esi, ebp 725 and eax, ebp
732 and edi, eax 726 and edx, ecx
733 or edi, esi 727 or edx, eax
734 mov esi, DWORD PTR 16[esp] 728 mov eax, DWORD PTR 12[esp]
735 rol eax, 10 729 rol ecx, 10
736 lea edx, DWORD PTR 2400959708[edi+edx] 730 lea ebx, DWORD PTR 2400959708[edx+ebx]
737 mov edi, -1 731 mov edx, -1
738 add edx, esi 732 add ebx, eax
739 mov esi, eax 733 mov eax, ecx
740 rol edx, 14 734 rol ebx, 14
741 add edx, ecx 735 add ebx, edi
742 ; 58 736 ; 58
743 sub edi, eax 737 sub edx, ecx
744 and esi, edx 738 and eax, ebx
745 and edi, ebp 739 and edx, ebp
746 or edi, esi 740 or edx, eax
747 mov esi, DWORD PTR 32[esp] 741 mov eax, DWORD PTR 28[esp]
748 rol ebp, 10 742 rol ebp, 10
749 lea ecx, DWORD PTR 2400959708[edi+ecx] 743 lea edi, DWORD PTR 2400959708[edx+edi]
750 mov edi, -1 744 mov edx, -1
751 add ecx, esi 745 add edi, eax
752 mov esi, ebp 746 mov eax, ebp
753 rol ecx, 5 747 rol edi, 5
754 add ecx, ebx 748 add edi, esi
755 ; 59 749 ; 59
756 sub edi, ebp 750 sub edx, ebp
757 and esi, ecx 751 and eax, edi
758 and edi, edx 752 and edx, ebx
759 or edi, esi 753 or edx, eax
760 mov esi, DWORD PTR 64[esp] 754 mov eax, DWORD PTR 60[esp]
761 rol edx, 10 755 rol ebx, 10
762 lea ebx, DWORD PTR 2400959708[edi+ebx] 756 lea esi, DWORD PTR 2400959708[edx+esi]
763 mov edi, -1 757 mov edx, -1
764 add ebx, esi 758 add esi, eax
765 mov esi, edx 759 mov eax, ebx
766 rol ebx, 6 760 rol esi, 6
767 add ebx, eax 761 add esi, ecx
768 ; 60 762 ; 60
769 sub edi, edx 763 sub edx, ebx
770 and esi, ebx 764 and eax, esi
771 and edi, ecx 765 and edx, edi
772 or edi, esi 766 or edx, eax
773 mov esi, DWORD PTR 60[esp] 767 mov eax, DWORD PTR 56[esp]
774 rol ecx, 10 768 rol edi, 10
775 lea eax, DWORD PTR 2400959708[edi+eax] 769 lea ecx, DWORD PTR 2400959708[edx+ecx]
776 mov edi, -1 770 mov edx, -1
777 add eax, esi 771 add ecx, eax
778 mov esi, ecx 772 mov eax, edi
779 rol eax, 8 773 rol ecx, 8
780 add eax, ebp 774 add ecx, ebp
781 ; 61 775 ; 61
782 sub edi, ecx 776 sub edx, edi
783 and esi, eax 777 and eax, ecx
784 and edi, ebx 778 and edx, esi
785 or edi, esi 779 or edx, eax
786 mov esi, DWORD PTR 24[esp] 780 mov eax, DWORD PTR 20[esp]
787 rol ebx, 10 781 rol esi, 10
788 lea ebp, DWORD PTR 2400959708[edi+ebp] 782 lea ebp, DWORD PTR 2400959708[edx+ebp]
789 mov edi, -1 783 mov edx, -1
790 add ebp, esi 784 add ebp, eax
791 mov esi, ebx 785 mov eax, esi
792 rol ebp, 6 786 rol ebp, 6
793 add ebp, edx 787 add ebp, ebx
794 ; 62 788 ; 62
795 sub edi, ebx 789 sub edx, esi
796 and esi, ebp 790 and eax, ebp
797 and edi, eax 791 and edx, ecx
798 or edi, esi 792 or edx, eax
799 mov esi, DWORD PTR 28[esp] 793 mov eax, DWORD PTR 24[esp]
800 rol eax, 10 794 rol ecx, 10
801 lea edx, DWORD PTR 2400959708[edi+edx] 795 lea ebx, DWORD PTR 2400959708[edx+ebx]
802 mov edi, -1 796 mov edx, -1
803 add edx, esi 797 add ebx, eax
804 mov esi, eax 798 mov eax, ecx
805 rol edx, 5 799 rol ebx, 5
806 add edx, ecx 800 add ebx, edi
807 ; 63 801 ; 63
808 sub edi, eax 802 sub edx, ecx
809 and esi, edx 803 and eax, ebx
810 and edi, ebp 804 and edx, ebp
811 or edi, esi 805 or edx, eax
812 mov esi, DWORD PTR 12[esp] 806 mov eax, DWORD PTR 8[esp]
813 rol ebp, 10 807 rol ebp, 10
814 lea ecx, DWORD PTR 2400959708[edi+ecx] 808 lea edi, DWORD PTR 2400959708[edx+edi]
815 mov edi, -1 809 mov edx, -1
816 add ecx, esi 810 add edi, eax
817 sub edi, ebp 811 sub edx, ebp
818 rol ecx, 12 812 rol edi, 12
819 add ecx, ebx 813 add edi, esi
820 ; 64 814 ; 64
821 mov esi, DWORD PTR 20[esp] 815 mov eax, DWORD PTR 16[esp]
822 or edi, edx 816 or edx, ebx
823 add ebx, esi 817 add esi, eax
824 xor edi, ecx 818 xor edx, edi
825 mov esi, -1 819 mov eax, -1
826 rol edx, 10 820 rol ebx, 10
827 lea ebx, DWORD PTR 2840853838[edi*1+ebx] 821 lea esi, DWORD PTR 2840853838[edx*1+esi]
828 sub esi, edx 822 sub eax, ebx
829 rol ebx, 9 823 rol esi, 9
830 add ebx, eax 824 add esi, ecx
831 ; 65 825 ; 65
832 mov edi, DWORD PTR 4[esp] 826 mov edx, DWORD PTR [esp]
833 or esi, ecx 827 or eax, edi
834 add eax, edi 828 add ecx, edx
835 xor esi, ebx 829 xor eax, esi
836 mov edi, -1 830 mov edx, -1
837 rol ecx, 10 831 rol edi, 10
838 lea eax, DWORD PTR 2840853838[esi*1+eax] 832 lea ecx, DWORD PTR 2840853838[eax*1+ecx]
839 sub edi, ecx 833 sub edx, edi
840 rol eax, 15 834 rol ecx, 15
841 add eax, ebp 835 add ecx, ebp
842 ; 66 836 ; 66
843 mov esi, DWORD PTR 24[esp] 837 mov eax, DWORD PTR 20[esp]
844 or edi, ebx 838 or edx, esi
845 add ebp, esi 839 add ebp, eax
846 xor edi, eax 840 xor edx, ecx
847 mov esi, -1 841 mov eax, -1
848 rol ebx, 10 842 rol esi, 10
849 lea ebp, DWORD PTR 2840853838[edi*1+ebp] 843 lea ebp, DWORD PTR 2840853838[edx*1+ebp]
850 sub esi, ebx 844 sub eax, esi
851 rol ebp, 5 845 rol ebp, 5
852 add ebp, edx 846 add ebp, ebx
853 ; 67 847 ; 67
854 mov edi, DWORD PTR 40[esp] 848 mov edx, DWORD PTR 36[esp]
855 or esi, eax 849 or eax, ecx
856 add edx, edi 850 add ebx, edx
857 xor esi, ebp 851 xor eax, ebp
858 mov edi, -1 852 mov edx, -1
859 rol eax, 10 853 rol ecx, 10
860 lea edx, DWORD PTR 2840853838[esi*1+edx] 854 lea ebx, DWORD PTR 2840853838[eax*1+ebx]
861 sub edi, eax 855 sub edx, ecx
862 rol edx, 11 856 rol ebx, 11
863 add edx, ecx 857 add ebx, edi
864 ; 68 858 ; 68
865 mov esi, DWORD PTR 32[esp] 859 mov eax, DWORD PTR 28[esp]
866 or edi, ebp 860 or edx, ebp
867 add ecx, esi 861 add edi, eax
868 xor edi, edx 862 xor edx, ebx
869 mov esi, -1 863 mov eax, -1
870 rol ebp, 10 864 rol ebp, 10
871 lea ecx, DWORD PTR 2840853838[edi*1+ecx] 865 lea edi, DWORD PTR 2840853838[edx*1+edi]
872 sub esi, ebp 866 sub eax, ebp
873 rol ecx, 6 867 rol edi, 6
874 add ecx, ebx 868 add edi, esi
875 ; 69 869 ; 69
876 mov edi, DWORD PTR 52[esp] 870 mov edx, DWORD PTR 48[esp]
877 or esi, edx 871 or eax, ebx
878 add ebx, edi 872 add esi, edx
879 xor esi, ecx 873 xor eax, edi
880 mov edi, -1 874 mov edx, -1
881 rol edx, 10 875 rol ebx, 10
882 lea ebx, DWORD PTR 2840853838[esi*1+ebx] 876 lea esi, DWORD PTR 2840853838[eax*1+esi]
883 sub edi, edx 877 sub edx, ebx
884 rol ebx, 8 878 rol esi, 8
885 add ebx, eax 879 add esi, ecx
886 ; 70 880 ; 70
887 mov esi, DWORD PTR 12[esp] 881 mov eax, DWORD PTR 8[esp]
888 or edi, ecx 882 or edx, edi
889 add eax, esi 883 add ecx, eax
890 xor edi, ebx 884 xor edx, esi
891 mov esi, -1 885 mov eax, -1
892 rol ecx, 10 886 rol edi, 10
893 lea eax, DWORD PTR 2840853838[edi*1+eax] 887 lea ecx, DWORD PTR 2840853838[edx*1+ecx]
894 sub esi, ecx 888 sub eax, edi
895 rol eax, 13 889 rol ecx, 13
896 add eax, ebp 890 add ecx, ebp
897 ; 71 891 ; 71
898 mov edi, DWORD PTR 44[esp] 892 mov edx, DWORD PTR 40[esp]
899 or esi, ebx 893 or eax, esi
900 add ebp, edi
901 xor esi, eax
902 mov edi, -1
903 rol ebx, 10
904 lea ebp, DWORD PTR 2840853838[esi*1+ebp]
905 sub edi, ebx
906 rol ebp, 12
907 add ebp, edx 894 add ebp, edx
895 xor eax, ecx
896 mov edx, -1
897 rol esi, 10
898 lea ebp, DWORD PTR 2840853838[eax*1+ebp]
899 sub edx, esi
900 rol ebp, 12
901 add ebp, ebx
908 ; 72 902 ; 72
909 mov esi, DWORD PTR 60[esp] 903 mov eax, DWORD PTR 56[esp]
910 or edi, eax 904 or edx, ecx
911 add edx, esi 905 add ebx, eax
912 xor edi, ebp 906 xor edx, ebp
913 mov esi, -1 907 mov eax, -1
914 rol eax, 10 908 rol ecx, 10
915 lea edx, DWORD PTR 2840853838[edi*1+edx] 909 lea ebx, DWORD PTR 2840853838[edx*1+ebx]
916 sub esi, eax 910 sub eax, ecx
917 rol edx, 5 911 rol ebx, 5
918 add edx, ecx 912 add ebx, edi
919 ; 73 913 ; 73
920 mov edi, DWORD PTR 8[esp] 914 mov edx, DWORD PTR 4[esp]
921 or esi, ebp 915 or eax, ebp
922 add ecx, edi 916 add edi, edx
923 xor esi, edx 917 xor eax, ebx
924 mov edi, -1 918 mov edx, -1
925 rol ebp, 10 919 rol ebp, 10
926 lea ecx, DWORD PTR 2840853838[esi*1+ecx] 920 lea edi, DWORD PTR 2840853838[eax*1+edi]
927 sub edi, ebp 921 sub edx, ebp
928 rol ecx, 12 922 rol edi, 12
929 add ecx, ebx 923 add edi, esi
930 ; 74 924 ; 74
931 mov esi, DWORD PTR 16[esp] 925 mov eax, DWORD PTR 12[esp]
932 or edi, edx 926 or edx, ebx
933 add ebx, esi 927 add esi, eax
934 xor edi, ecx 928 xor edx, edi
935 mov esi, -1 929 mov eax, -1
936 rol edx, 10 930 rol ebx, 10
937 lea ebx, DWORD PTR 2840853838[edi*1+ebx] 931 lea esi, DWORD PTR 2840853838[edx*1+esi]
938 sub esi, edx 932 sub eax, ebx
939 rol ebx, 13 933 rol esi, 13
940 add ebx, eax 934 add esi, ecx
941 ; 75 935 ; 75
942 mov edi, DWORD PTR 36[esp] 936 mov edx, DWORD PTR 32[esp]
943 or esi, ecx 937 or eax, edi
944 add eax, edi 938 add ecx, edx
945 xor esi, ebx 939 xor eax, esi
946 mov edi, -1 940 mov edx, -1
947 rol ecx, 10 941 rol edi, 10
948 lea eax, DWORD PTR 2840853838[esi*1+eax] 942 lea ecx, DWORD PTR 2840853838[eax*1+ecx]
949 sub edi, ecx 943 sub edx, edi
950 rol eax, 14 944 rol ecx, 14
951 add eax, ebp 945 add ecx, ebp
952 ; 76 946 ; 76
953 mov esi, DWORD PTR 48[esp] 947 mov eax, DWORD PTR 44[esp]
954 or edi, ebx 948 or edx, esi
955 add ebp, esi 949 add ebp, eax
956 xor edi, eax 950 xor edx, ecx
957 mov esi, -1 951 mov eax, -1
958 rol ebx, 10 952 rol esi, 10
959 lea ebp, DWORD PTR 2840853838[edi*1+ebp] 953 lea ebp, DWORD PTR 2840853838[edx*1+ebp]
960 sub esi, ebx 954 sub eax, esi
961 rol ebp, 11 955 rol ebp, 11
962 add ebp, edx 956 add ebp, ebx
963 ; 77 957 ; 77
964 mov edi, DWORD PTR 28[esp] 958 mov edx, DWORD PTR 24[esp]
965 or esi, eax 959 or eax, ecx
966 add edx, edi 960 add ebx, edx
967 xor esi, ebp 961 xor eax, ebp
968 mov edi, -1 962 mov edx, -1
969 rol eax, 10 963 rol ecx, 10
970 lea edx, DWORD PTR 2840853838[esi*1+edx] 964 lea ebx, DWORD PTR 2840853838[eax*1+ebx]
971 sub edi, eax 965 sub edx, ecx
972 rol edx, 8 966 rol ebx, 8
973 add edx, ecx 967 add ebx, edi
974 ; 78 968 ; 78
975 mov esi, DWORD PTR 64[esp] 969 mov eax, DWORD PTR 60[esp]
976 or edi, ebp 970 or edx, ebp
977 add ecx, esi 971 add edi, eax
978 xor edi, edx 972 xor edx, ebx
979 mov esi, -1 973 mov eax, -1
980 rol ebp, 10 974 rol ebp, 10
981 lea ecx, DWORD PTR 2840853838[edi*1+ecx] 975 lea edi, DWORD PTR 2840853838[edx*1+edi]
982 sub esi, ebp 976 sub eax, ebp
983 rol ecx, 5 977 rol edi, 5
984 add ecx, ebx 978 add edi, esi
985 ; 79 979 ; 79
986 mov edi, DWORD PTR 56[esp] 980 mov edx, DWORD PTR 52[esp]
987 or esi, edx 981 or eax, ebx
988 add ebx, edi 982 add esi, edx
989 xor esi, ecx 983 xor eax, edi
990 mov edi, DWORD PTR 108[esp] 984 mov edx, DWORD PTR 128[esp]
991 rol edx, 10 985 rol ebx, 10
992 lea ebx, DWORD PTR 2840853838[esi*1+ebx] 986 lea esi, DWORD PTR 2840853838[eax*1+esi]
993 mov DWORD PTR 68[esp],eax 987 mov DWORD PTR 64[esp],ecx
994 rol ebx, 6 988 rol esi, 6
995 add ebx, eax 989 add esi, ecx
996 mov eax, DWORD PTR [edi] 990 mov ecx, DWORD PTR [edx]
997 mov DWORD PTR 72[esp],ebx 991 mov DWORD PTR 68[esp],esi
998 mov DWORD PTR 76[esp],ecx 992 mov DWORD PTR 72[esp],edi
999 mov ebx, DWORD PTR 4[edi] 993 mov esi, DWORD PTR 4[edx]
1000 mov DWORD PTR 80[esp],edx 994 mov DWORD PTR 76[esp],ebx
1001 mov ecx, DWORD PTR 8[edi] 995 mov edi, DWORD PTR 8[edx]
1002 mov DWORD PTR 84[esp],ebp 996 mov DWORD PTR 80[esp],ebp
1003 mov edx, DWORD PTR 12[edi] 997 mov ebx, DWORD PTR 12[edx]
1004 mov ebp, DWORD PTR 16[edi] 998 mov ebp, DWORD PTR 16[edx]
1005 ; 80 999 ; 80
1006 mov edi, -1 1000 mov edx, -1
1007 sub edi, edx 1001 sub edx, ebx
1008 mov esi, DWORD PTR 24[esp] 1002 mov eax, DWORD PTR 20[esp]
1009 or edi, ecx 1003 or edx, edi
1010 add eax, esi 1004 add ecx, eax
1011 xor edi, ebx 1005 xor edx, esi
1012 mov esi, -1 1006 mov eax, -1
1013 rol ecx, 10 1007 rol edi, 10
1014 lea eax, DWORD PTR 1352829926[edi*1+eax] 1008 lea ecx, DWORD PTR 1352829926[edx*1+ecx]
1015 sub esi, ecx 1009 sub eax, edi
1016 rol eax, 8 1010 rol ecx, 8
1017 add eax, ebp 1011 add ecx, ebp
1018 ; 81 1012 ; 81
1019 mov edi, DWORD PTR 60[esp] 1013 mov edx, DWORD PTR 56[esp]
1020 or esi, ebx 1014 or eax, esi
1021 add ebp, edi
1022 xor esi, eax
1023 mov edi, -1
1024 rol ebx, 10
1025 lea ebp, DWORD PTR 1352829926[esi*1+ebp]
1026 sub edi, ebx
1027 rol ebp, 9
1028 add ebp, edx 1015 add ebp, edx
1016 xor eax, ecx
1017 mov edx, -1
1018 rol esi, 10
1019 lea ebp, DWORD PTR 1352829926[eax*1+ebp]
1020 sub edx, esi
1021 rol ebp, 9
1022 add ebp, ebx
1029 ; 82 1023 ; 82
1030 mov esi, DWORD PTR 32[esp] 1024 mov eax, DWORD PTR 28[esp]
1031 or edi, eax 1025 or edx, ecx
1032 add edx, esi 1026 add ebx, eax
1033 xor edi, ebp 1027 xor edx, ebp
1034 mov esi, -1 1028 mov eax, -1
1035 rol eax, 10 1029 rol ecx, 10
1036 lea edx, DWORD PTR 1352829926[edi*1+edx] 1030 lea ebx, DWORD PTR 1352829926[edx*1+ebx]
1037 sub esi, eax 1031 sub eax, ecx
1038 rol edx, 9 1032 rol ebx, 9
1039 add edx, ecx 1033 add ebx, edi
1040 ; 83 1034 ; 83
1041 mov edi, DWORD PTR 4[esp] 1035 mov edx, DWORD PTR [esp]
1042 or esi, ebp 1036 or eax, ebp
1043 add ecx, edi 1037 add edi, edx
1044 xor esi, edx 1038 xor eax, ebx
1045 mov edi, -1 1039 mov edx, -1
1046 rol ebp, 10 1040 rol ebp, 10
1047 lea ecx, DWORD PTR 1352829926[esi*1+ecx] 1041 lea edi, DWORD PTR 1352829926[eax*1+edi]
1048 sub edi, ebp 1042 sub edx, ebp
1049 rol ecx, 11 1043 rol edi, 11
1050 add ecx, ebx 1044 add edi, esi
1051 ; 84 1045 ; 84
1052 mov esi, DWORD PTR 40[esp] 1046 mov eax, DWORD PTR 36[esp]
1053 or edi, edx 1047 or edx, ebx
1054 add ebx, esi 1048 add esi, eax
1055 xor edi, ecx 1049 xor edx, edi
1056 mov esi, -1 1050 mov eax, -1
1057 rol edx, 10 1051 rol ebx, 10
1058 lea ebx, DWORD PTR 1352829926[edi*1+ebx] 1052 lea esi, DWORD PTR 1352829926[edx*1+esi]
1059 sub esi, edx 1053 sub eax, ebx
1060 rol ebx, 13 1054 rol esi, 13
1061 add ebx, eax 1055 add esi, ecx
1062 ; 85 1056 ; 85
1063 mov edi, DWORD PTR 12[esp] 1057 mov edx, DWORD PTR 8[esp]
1064 or esi, ecx 1058 or eax, edi
1065 add eax, edi 1059 add ecx, edx
1066 xor esi, ebx 1060 xor eax, esi
1067 mov edi, -1 1061 mov edx, -1
1068 rol ecx, 10 1062 rol edi, 10
1069 lea eax, DWORD PTR 1352829926[esi*1+eax] 1063 lea ecx, DWORD PTR 1352829926[eax*1+ecx]
1070 sub edi, ecx 1064 sub edx, edi
1071 rol eax, 15 1065 rol ecx, 15
1072 add eax, ebp 1066 add ecx, ebp
1073 ; 86 1067 ; 86
1074 mov esi, DWORD PTR 48[esp] 1068 mov eax, DWORD PTR 44[esp]
1075 or edi, ebx 1069 or edx, esi
1076 add ebp, esi 1070 add ebp, eax
1077 xor edi, eax 1071 xor edx, ecx
1078 mov esi, -1 1072 mov eax, -1
1079 rol ebx, 10 1073 rol esi, 10
1080 lea ebp, DWORD PTR 1352829926[edi*1+ebp] 1074 lea ebp, DWORD PTR 1352829926[edx*1+ebp]
1081 sub esi, ebx 1075 sub eax, esi
1082 rol ebp, 15 1076 rol ebp, 15
1083 add ebp, edx 1077 add ebp, ebx
1084 ; 87 1078 ; 87
1085 mov edi, DWORD PTR 20[esp] 1079 mov edx, DWORD PTR 16[esp]
1086 or esi, eax 1080 or eax, ecx
1087 add edx, edi 1081 add ebx, edx
1088 xor esi, ebp 1082 xor eax, ebp
1089 mov edi, -1 1083 mov edx, -1
1090 rol eax, 10 1084 rol ecx, 10
1091 lea edx, DWORD PTR 1352829926[esi*1+edx] 1085 lea ebx, DWORD PTR 1352829926[eax*1+ebx]
1092 sub edi, eax 1086 sub edx, ecx
1093 rol edx, 5 1087 rol ebx, 5
1094 add edx, ecx 1088 add ebx, edi
1095 ; 88 1089 ; 88
1096 mov esi, DWORD PTR 56[esp] 1090 mov eax, DWORD PTR 52[esp]
1097 or edi, ebp 1091 or edx, ebp
1098 add ecx, esi 1092 add edi, eax
1099 xor edi, edx 1093 xor edx, ebx
1100 mov esi, -1 1094 mov eax, -1
1101 rol ebp, 10 1095 rol ebp, 10
1102 lea ecx, DWORD PTR 1352829926[edi*1+ecx] 1096 lea edi, DWORD PTR 1352829926[edx*1+edi]
1103 sub esi, ebp 1097 sub eax, ebp
1104 rol ecx, 7 1098 rol edi, 7
1105 add ecx, ebx 1099 add edi, esi
1106 ; 89 1100 ; 89
1107 mov edi, DWORD PTR 28[esp] 1101 mov edx, DWORD PTR 24[esp]
1108 or esi, edx 1102 or eax, ebx
1109 add ebx, edi 1103 add esi, edx
1110 xor esi, ecx 1104 xor eax, edi
1111 mov edi, -1 1105 mov edx, -1
1112 rol edx, 10 1106 rol ebx, 10
1113 lea ebx, DWORD PTR 1352829926[esi*1+ebx] 1107 lea esi, DWORD PTR 1352829926[eax*1+esi]
1114 sub edi, edx 1108 sub edx, ebx
1115 rol ebx, 7 1109 rol esi, 7
1116 add ebx, eax 1110 add esi, ecx
1117 ; 90 1111 ; 90
1118 mov esi, DWORD PTR 64[esp] 1112 mov eax, DWORD PTR 60[esp]
1119 or edi, ecx 1113 or edx, edi
1120 add eax, esi 1114 add ecx, eax
1121 xor edi, ebx 1115 xor edx, esi
1122 mov esi, -1 1116 mov eax, -1
1123 rol ecx, 10 1117 rol edi, 10
1124 lea eax, DWORD PTR 1352829926[edi*1+eax] 1118 lea ecx, DWORD PTR 1352829926[edx*1+ecx]
1125 sub esi, ecx 1119 sub eax, edi
1126 rol eax, 8 1120 rol ecx, 8
1127 add eax, ebp 1121 add ecx, ebp
1128 ; 91 1122 ; 91
1129 mov edi, DWORD PTR 36[esp] 1123 mov edx, DWORD PTR 32[esp]
1130 or esi, ebx 1124 or eax, esi
1131 add ebp, edi
1132 xor esi, eax
1133 mov edi, -1
1134 rol ebx, 10
1135 lea ebp, DWORD PTR 1352829926[esi*1+ebp]
1136 sub edi, ebx
1137 rol ebp, 11
1138 add ebp, edx 1125 add ebp, edx
1126 xor eax, ecx
1127 mov edx, -1
1128 rol esi, 10
1129 lea ebp, DWORD PTR 1352829926[eax*1+ebp]
1130 sub edx, esi
1131 rol ebp, 11
1132 add ebp, ebx
1139 ; 92 1133 ; 92
1140 mov esi, DWORD PTR 8[esp] 1134 mov eax, DWORD PTR 4[esp]
1141 or edi, eax 1135 or edx, ecx
1142 add edx, esi 1136 add ebx, eax
1143 xor edi, ebp 1137 xor edx, ebp
1144 mov esi, -1 1138 mov eax, -1
1145 rol eax, 10 1139 rol ecx, 10
1146 lea edx, DWORD PTR 1352829926[edi*1+edx] 1140 lea ebx, DWORD PTR 1352829926[edx*1+ebx]
1147 sub esi, eax 1141 sub eax, ecx
1148 rol edx, 14 1142 rol ebx, 14
1149 add edx, ecx 1143 add ebx, edi
1150 ; 93 1144 ; 93
1151 mov edi, DWORD PTR 44[esp] 1145 mov edx, DWORD PTR 40[esp]
1152 or esi, ebp 1146 or eax, ebp
1153 add ecx, edi 1147 add edi, edx
1154 xor esi, edx 1148 xor eax, ebx
1155 mov edi, -1 1149 mov edx, -1
1156 rol ebp, 10 1150 rol ebp, 10
1157 lea ecx, DWORD PTR 1352829926[esi*1+ecx] 1151 lea edi, DWORD PTR 1352829926[eax*1+edi]
1158 sub edi, ebp 1152 sub edx, ebp
1159 rol ecx, 14 1153 rol edi, 14
1160 add ecx, ebx 1154 add edi, esi
1161 ; 94 1155 ; 94
1162 mov esi, DWORD PTR 16[esp] 1156 mov eax, DWORD PTR 12[esp]
1163 or edi, edx 1157 or edx, ebx
1164 add ebx, esi 1158 add esi, eax
1165 xor edi, ecx 1159 xor edx, edi
1166 mov esi, -1 1160 mov eax, -1
1167 rol edx, 10 1161 rol ebx, 10
1168 lea ebx, DWORD PTR 1352829926[edi*1+ebx] 1162 lea esi, DWORD PTR 1352829926[edx*1+esi]
1169 sub esi, edx 1163 sub eax, ebx
1170 rol ebx, 12 1164 rol esi, 12
1171 add ebx, eax 1165 add esi, ecx
1172 ; 95 1166 ; 95
1173 mov edi, DWORD PTR 52[esp] 1167 mov edx, DWORD PTR 48[esp]
1174 or esi, ecx 1168 or eax, edi
1175 add eax, edi 1169 add ecx, edx
1176 xor esi, ebx 1170 xor eax, esi
1177 mov edi, -1 1171 mov edx, -1
1178 rol ecx, 10 1172 rol edi, 10
1179 lea eax, DWORD PTR 1352829926[esi*1+eax] 1173 lea ecx, DWORD PTR 1352829926[eax*1+ecx]
1180 mov esi, ecx 1174 mov eax, edi
1181 rol eax, 6 1175 rol ecx, 6
1182 add eax, ebp 1176 add ecx, ebp
1183 ; 96 1177 ; 96
1184 sub edi, ecx 1178 sub edx, edi
1185 and esi, eax 1179 and eax, ecx
1186 and edi, ebx 1180 and edx, esi
1187 or edi, esi 1181 or edx, eax
1188 mov esi, DWORD PTR 28[esp] 1182 mov eax, DWORD PTR 24[esp]
1189 rol ebx, 10 1183 rol esi, 10
1190 lea ebp, DWORD PTR 1548603684[edi+ebp] 1184 lea ebp, DWORD PTR 1548603684[edx+ebp]
1191 mov edi, -1 1185 mov edx, -1
1192 add ebp, esi 1186 add ebp, eax
1193 mov esi, ebx 1187 mov eax, esi
1194 rol ebp, 9 1188 rol ebp, 9
1195 add ebp, edx 1189 add ebp, ebx
1196 ; 97 1190 ; 97
1197 sub edi, ebx 1191 sub edx, esi
1198 and esi, ebp 1192 and eax, ebp
1199 and edi, eax 1193 and edx, ecx
1200 or edi, esi 1194 or edx, eax
1201 mov esi, DWORD PTR 48[esp] 1195 mov eax, DWORD PTR 44[esp]
1202 rol eax, 10 1196 rol ecx, 10
1203 lea edx, DWORD PTR 1548603684[edi+edx] 1197 lea ebx, DWORD PTR 1548603684[edx+ebx]
1204 mov edi, -1 1198 mov edx, -1
1205 add edx, esi 1199 add ebx, eax
1206 mov esi, eax 1200 mov eax, ecx
1207 rol edx, 13 1201 rol ebx, 13
1208 add edx, ecx 1202 add ebx, edi
1209 ; 98 1203 ; 98
1210 sub edi, eax 1204 sub edx, ecx
1211 and esi, edx 1205 and eax, ebx
1212 and edi, ebp 1206 and edx, ebp
1213 or edi, esi 1207 or edx, eax
1214 mov esi, DWORD PTR 16[esp] 1208 mov eax, DWORD PTR 12[esp]
1215 rol ebp, 10 1209 rol ebp, 10
1216 lea ecx, DWORD PTR 1548603684[edi+ecx] 1210 lea edi, DWORD PTR 1548603684[edx+edi]
1217 mov edi, -1 1211 mov edx, -1
1218 add ecx, esi 1212 add edi, eax
1219 mov esi, ebp 1213 mov eax, ebp
1220 rol ecx, 15 1214 rol edi, 15
1221 add ecx, ebx 1215 add edi, esi
1222 ; 99 1216 ; 99
1223 sub edi, ebp 1217 sub edx, ebp
1224 and esi, ecx 1218 and eax, edi
1225 and edi, edx 1219 and edx, ebx
1226 or edi, esi 1220 or edx, eax
1227 mov esi, DWORD PTR 32[esp] 1221 mov eax, DWORD PTR 28[esp]
1228 rol edx, 10 1222 rol ebx, 10
1229 lea ebx, DWORD PTR 1548603684[edi+ebx] 1223 lea esi, DWORD PTR 1548603684[edx+esi]
1230 mov edi, -1 1224 mov edx, -1
1231 add ebx, esi 1225 add esi, eax
1232 mov esi, edx 1226 mov eax, ebx
1233 rol ebx, 7 1227 rol esi, 7
1234 add ebx, eax 1228 add esi, ecx
1235 ; 100 1229 ; 100
1236 sub edi, edx 1230 sub edx, ebx
1237 and esi, ebx 1231 and eax, esi
1238 and edi, ecx 1232 and edx, edi
1239 or edi, esi 1233 or edx, eax
1240 mov esi, DWORD PTR 4[esp] 1234 mov eax, DWORD PTR [esp]
1241 rol ecx, 10 1235 rol edi, 10
1242 lea eax, DWORD PTR 1548603684[edi+eax] 1236 lea ecx, DWORD PTR 1548603684[edx+ecx]
1243 mov edi, -1 1237 mov edx, -1
1244 add eax, esi 1238 add ecx, eax
1245 mov esi, ecx 1239 mov eax, edi
1246 rol eax, 12 1240 rol ecx, 12
1247 add eax, ebp 1241 add ecx, ebp
1248 ; 101 1242 ; 101
1249 sub edi, ecx 1243 sub edx, edi
1250 and esi, eax 1244 and eax, ecx
1251 and edi, ebx 1245 and edx, esi
1252 or edi, esi 1246 or edx, eax
1253 mov esi, DWORD PTR 56[esp] 1247 mov eax, DWORD PTR 52[esp]
1254 rol ebx, 10 1248 rol esi, 10
1255 lea ebp, DWORD PTR 1548603684[edi+ebp] 1249 lea ebp, DWORD PTR 1548603684[edx+ebp]
1256 mov edi, -1 1250 mov edx, -1
1257 add ebp, esi 1251 add ebp, eax
1258 mov esi, ebx 1252 mov eax, esi
1259 rol ebp, 8 1253 rol ebp, 8
1260 add ebp, edx 1254 add ebp, ebx
1261 ; 102 1255 ; 102
1262 sub edi, ebx 1256 sub edx, esi
1263 and esi, ebp 1257 and eax, ebp
1264 and edi, eax 1258 and edx, ecx
1265 or edi, esi 1259 or edx, eax
1266 mov esi, DWORD PTR 24[esp] 1260 mov eax, DWORD PTR 20[esp]
1267 rol eax, 10 1261 rol ecx, 10
1268 lea edx, DWORD PTR 1548603684[edi+edx] 1262 lea ebx, DWORD PTR 1548603684[edx+ebx]
1269 mov edi, -1 1263 mov edx, -1
1270 add edx, esi 1264 add ebx, eax
1271 mov esi, eax 1265 mov eax, ecx
1272 rol edx, 9 1266 rol ebx, 9
1273 add edx, ecx 1267 add ebx, edi
1274 ; 103 1268 ; 103
1275 sub edi, eax 1269 sub edx, ecx
1276 and esi, edx 1270 and eax, ebx
1277 and edi, ebp 1271 and edx, ebp
1278 or edi, esi 1272 or edx, eax
1279 mov esi, DWORD PTR 44[esp] 1273 mov eax, DWORD PTR 40[esp]
1280 rol ebp, 10 1274 rol ebp, 10
1281 lea ecx, DWORD PTR 1548603684[edi+ecx] 1275 lea edi, DWORD PTR 1548603684[edx+edi]
1282 mov edi, -1 1276 mov edx, -1
1283 add ecx, esi 1277 add edi, eax
1284 mov esi, ebp 1278 mov eax, ebp
1285 rol ecx, 11 1279 rol edi, 11
1286 add ecx, ebx 1280 add edi, esi
1287 ; 104 1281 ; 104
1288 sub edi, ebp 1282 sub edx, ebp
1289 and esi, ecx 1283 and eax, edi
1290 and edi, edx 1284 and edx, ebx
1291 or edi, esi 1285 or edx, eax
1292 mov esi, DWORD PTR 60[esp] 1286 mov eax, DWORD PTR 56[esp]
1293 rol edx, 10 1287 rol ebx, 10
1294 lea ebx, DWORD PTR 1548603684[edi+ebx] 1288 lea esi, DWORD PTR 1548603684[edx+esi]
1295 mov edi, -1 1289 mov edx, -1
1296 add ebx, esi 1290 add esi, eax
1297 mov esi, edx 1291 mov eax, ebx
1298 rol ebx, 7 1292 rol esi, 7
1299 add ebx, eax 1293 add esi, ecx
1300 ; 105 1294 ; 105
1301 sub edi, edx 1295 sub edx, ebx
1302 and esi, ebx 1296 and eax, esi
1303 and edi, ecx 1297 and edx, edi
1304 or edi, esi 1298 or edx, eax
1305 mov esi, DWORD PTR 64[esp] 1299 mov eax, DWORD PTR 60[esp]
1306 rol ecx, 10 1300 rol edi, 10
1307 lea eax, DWORD PTR 1548603684[edi+eax] 1301 lea ecx, DWORD PTR 1548603684[edx+ecx]
1308 mov edi, -1 1302 mov edx, -1
1309 add eax, esi 1303 add ecx, eax
1310 mov esi, ecx 1304 mov eax, edi
1311 rol eax, 7 1305 rol ecx, 7
1312 add eax, ebp 1306 add ecx, ebp
1313 ; 106 1307 ; 106
1314 sub edi, ecx 1308 sub edx, edi
1315 and esi, eax 1309 and eax, ecx
1316 and edi, ebx 1310 and edx, esi
1317 or edi, esi 1311 or edx, eax
1318 mov esi, DWORD PTR 36[esp] 1312 mov eax, DWORD PTR 32[esp]
1319 rol ebx, 10 1313 rol esi, 10
1320 lea ebp, DWORD PTR 1548603684[edi+ebp] 1314 lea ebp, DWORD PTR 1548603684[edx+ebp]
1321 mov edi, -1 1315 mov edx, -1
1322 add ebp, esi 1316 add ebp, eax
1323 mov esi, ebx 1317 mov eax, esi
1324 rol ebp, 12 1318 rol ebp, 12
1325 add ebp, edx 1319 add ebp, ebx
1326 ; 107 1320 ; 107
1327 sub edi, ebx 1321 sub edx, esi
1328 and esi, ebp 1322 and eax, ebp
1329 and edi, eax 1323 and edx, ecx
1330 or edi, esi 1324 or edx, eax
1331 mov esi, DWORD PTR 52[esp] 1325 mov eax, DWORD PTR 48[esp]
1332 rol eax, 10 1326 rol ecx, 10
1333 lea edx, DWORD PTR 1548603684[edi+edx] 1327 lea ebx, DWORD PTR 1548603684[edx+ebx]
1334 mov edi, -1 1328 mov edx, -1
1335 add edx, esi 1329 add ebx, eax
1336 mov esi, eax 1330 mov eax, ecx
1337 rol edx, 7 1331 rol ebx, 7
1338 add edx, ecx 1332 add ebx, edi
1339 ; 108 1333 ; 108
1340 sub edi, eax 1334 sub edx, ecx
1341 and esi, edx 1335 and eax, ebx
1342 and edi, ebp 1336 and edx, ebp
1343 or edi, esi 1337 or edx, eax
1344 mov esi, DWORD PTR 20[esp] 1338 mov eax, DWORD PTR 16[esp]
1345 rol ebp, 10 1339 rol ebp, 10
1346 lea ecx, DWORD PTR 1548603684[edi+ecx] 1340 lea edi, DWORD PTR 1548603684[edx+edi]
1347 mov edi, -1 1341 mov edx, -1
1348 add ecx, esi 1342 add edi, eax
1349 mov esi, ebp 1343 mov eax, ebp
1350 rol ecx, 6 1344 rol edi, 6
1351 add ecx, ebx 1345 add edi, esi
1352 ; 109 1346 ; 109
1353 sub edi, ebp 1347 sub edx, ebp
1354 and esi, ecx 1348 and eax, edi
1355 and edi, edx 1349 and edx, ebx
1356 or edi, esi 1350 or edx, eax
1357 mov esi, DWORD PTR 40[esp] 1351 mov eax, DWORD PTR 36[esp]
1358 rol edx, 10 1352 rol ebx, 10
1359 lea ebx, DWORD PTR 1548603684[edi+ebx] 1353 lea esi, DWORD PTR 1548603684[edx+esi]
1360 mov edi, -1 1354 mov edx, -1
1361 add ebx, esi 1355 add esi, eax
1362 mov esi, edx 1356 mov eax, ebx
1363 rol ebx, 15 1357 rol esi, 15
1364 add ebx, eax 1358 add esi, ecx
1365 ; 110 1359 ; 110
1366 sub edi, edx 1360 sub edx, ebx
1367 and esi, ebx 1361 and eax, esi
1368 and edi, ecx 1362 and edx, edi
1369 or edi, esi 1363 or edx, eax
1370 mov esi, DWORD PTR 8[esp] 1364 mov eax, DWORD PTR 4[esp]
1371 rol ecx, 10 1365 rol edi, 10
1372 lea eax, DWORD PTR 1548603684[edi+eax] 1366 lea ecx, DWORD PTR 1548603684[edx+ecx]
1373 mov edi, -1 1367 mov edx, -1
1374 add eax, esi 1368 add ecx, eax
1375 mov esi, ecx 1369 mov eax, edi
1376 rol eax, 13 1370 rol ecx, 13
1377 add eax, ebp 1371 add ecx, ebp
1378 ; 111 1372 ; 111
1379 sub edi, ecx 1373 sub edx, edi
1380 and esi, eax 1374 and eax, ecx
1381 and edi, ebx 1375 and edx, esi
1382 or edi, esi 1376 or edx, eax
1383 mov esi, DWORD PTR 12[esp] 1377 mov eax, DWORD PTR 8[esp]
1384 rol ebx, 10 1378 rol esi, 10
1385 lea ebp, DWORD PTR 1548603684[edi+ebp] 1379 lea ebp, DWORD PTR 1548603684[edx+ebp]
1386 mov edi, -1 1380 mov edx, -1
1387 add ebp, esi 1381 add ebp, eax
1388 sub edi, eax 1382 sub edx, ecx
1389 rol ebp, 11 1383 rol ebp, 11
1390 add ebp, edx 1384 add ebp, ebx
1391 ; 112 1385 ; 112
1392 mov esi, DWORD PTR 64[esp] 1386 mov eax, DWORD PTR 60[esp]
1393 or edi, ebp 1387 or edx, ebp
1394 add edx, esi 1388 add ebx, eax
1395 xor edi, ebx 1389 xor edx, esi
1396 mov esi, -1 1390 mov eax, -1
1397 rol eax, 10 1391 rol ecx, 10
1398 lea edx, DWORD PTR 1836072691[edi*1+edx] 1392 lea ebx, DWORD PTR 1836072691[edx*1+ebx]
1399 sub esi, ebp 1393 sub eax, ebp
1400 rol edx, 9 1394 rol ebx, 9
1401 add edx, ecx 1395 add ebx, edi
1402 ; 113 1396 ; 113
1403 mov edi, DWORD PTR 24[esp] 1397 mov edx, DWORD PTR 20[esp]
1404 or esi, edx 1398 or eax, ebx
1405 add ecx, edi 1399 add edi, edx
1406 xor esi, eax 1400 xor eax, ecx
1407 mov edi, -1 1401 mov edx, -1
1408 rol ebp, 10 1402 rol ebp, 10
1409 lea ecx, DWORD PTR 1836072691[esi*1+ecx] 1403 lea edi, DWORD PTR 1836072691[eax*1+edi]
1410 sub edi, edx 1404 sub edx, ebx
1411 rol ecx, 7 1405 rol edi, 7
1412 add ecx, ebx 1406 add edi, esi
1413 ; 114 1407 ; 114
1414 mov esi, DWORD PTR 8[esp] 1408 mov eax, DWORD PTR 4[esp]
1415 or edi, ecx 1409 or edx, edi
1416 add ebx, esi 1410 add esi, eax
1417 xor edi, ebp 1411 xor edx, ebp
1418 mov esi, -1 1412 mov eax, -1
1419 rol edx, 10 1413 rol ebx, 10
1420 lea ebx, DWORD PTR 1836072691[edi*1+ebx] 1414 lea esi, DWORD PTR 1836072691[edx*1+esi]
1421 sub esi, ecx 1415 sub eax, edi
1422 rol ebx, 15 1416 rol esi, 15
1423 add ebx, eax 1417 add esi, ecx
1424 ; 115 1418 ; 115
1425 mov edi, DWORD PTR 16[esp] 1419 mov edx, DWORD PTR 12[esp]
1426 or esi, ebx 1420 or eax, esi
1427 add eax, edi 1421 add ecx, edx
1428 xor esi, edx 1422 xor eax, ebx
1429 mov edi, -1 1423 mov edx, -1
1430 rol ecx, 10 1424 rol edi, 10
1431 lea eax, DWORD PTR 1836072691[esi*1+eax] 1425 lea ecx, DWORD PTR 1836072691[eax*1+ecx]
1432 sub edi, ebx 1426 sub edx, esi
1433 rol eax, 11 1427 rol ecx, 11
1434 add eax, ebp 1428 add ecx, ebp
1435 ; 116 1429 ; 116
1436 mov esi, DWORD PTR 32[esp] 1430 mov eax, DWORD PTR 28[esp]
1437 or edi, eax 1431 or edx, ecx
1438 add ebp, esi 1432 add ebp, eax
1439 xor edi, ecx 1433 xor edx, edi
1440 mov esi, -1 1434 mov eax, -1
1441 rol ebx, 10 1435 rol esi, 10
1442 lea ebp, DWORD PTR 1836072691[edi*1+ebp] 1436 lea ebp, DWORD PTR 1836072691[edx*1+ebp]
1443 sub esi, eax 1437 sub eax, ecx
1444 rol ebp, 8 1438 rol ebp, 8
1445 add ebp, edx 1439 add ebp, ebx
1446 ; 117 1440 ; 117
1447 mov edi, DWORD PTR 60[esp] 1441 mov edx, DWORD PTR 56[esp]
1448 or esi, ebp 1442 or eax, ebp
1449 add edx, edi 1443 add ebx, edx
1450 xor esi, ebx 1444 xor eax, esi
1451 mov edi, -1 1445 mov edx, -1
1452 rol eax, 10 1446 rol ecx, 10
1453 lea edx, DWORD PTR 1836072691[esi*1+edx] 1447 lea ebx, DWORD PTR 1836072691[eax*1+ebx]
1454 sub edi, ebp 1448 sub edx, ebp
1455 rol edx, 6 1449 rol ebx, 6
1456 add edx, ecx 1450 add ebx, edi
1457 ; 118 1451 ; 118
1458 mov esi, DWORD PTR 28[esp] 1452 mov eax, DWORD PTR 24[esp]
1459 or edi, edx 1453 or edx, ebx
1460 add ecx, esi 1454 add edi, eax
1461 xor edi, eax 1455 xor edx, ecx
1462 mov esi, -1 1456 mov eax, -1
1463 rol ebp, 10 1457 rol ebp, 10
1464 lea ecx, DWORD PTR 1836072691[edi*1+ecx] 1458 lea edi, DWORD PTR 1836072691[edx*1+edi]
1465 sub esi, edx 1459 sub eax, ebx
1466 rol ecx, 6 1460 rol edi, 6
1467 add ecx, ebx 1461 add edi, esi
1468 ; 119 1462 ; 119
1469 mov edi, DWORD PTR 40[esp] 1463 mov edx, DWORD PTR 36[esp]
1470 or esi, ecx 1464 or eax, edi
1471 add ebx, edi 1465 add esi, edx
1472 xor esi, ebp 1466 xor eax, ebp
1473 mov edi, -1 1467 mov edx, -1
1474 rol edx, 10 1468 rol ebx, 10
1475 lea ebx, DWORD PTR 1836072691[esi*1+ebx] 1469 lea esi, DWORD PTR 1836072691[eax*1+esi]
1476 sub edi, ecx 1470 sub edx, edi
1477 rol ebx, 14 1471 rol esi, 14
1478 add ebx, eax 1472 add esi, ecx
1479 ; 120 1473 ; 120
1480 mov esi, DWORD PTR 48[esp] 1474 mov eax, DWORD PTR 44[esp]
1481 or edi, ebx 1475 or edx, esi
1482 add eax, esi 1476 add ecx, eax
1483 xor edi, edx 1477 xor edx, ebx
1484 mov esi, -1 1478 mov eax, -1
1485 rol ecx, 10 1479 rol edi, 10
1486 lea eax, DWORD PTR 1836072691[edi*1+eax] 1480 lea ecx, DWORD PTR 1836072691[edx*1+ecx]
1487 sub esi, ebx 1481 sub eax, esi
1488 rol eax, 12 1482 rol ecx, 12
1489 add eax, ebp 1483 add ecx, ebp
1490 ; 121 1484 ; 121
1491 mov edi, DWORD PTR 36[esp] 1485 mov edx, DWORD PTR 32[esp]
1492 or esi, eax 1486 or eax, ecx
1493 add ebp, edi
1494 xor esi, ecx
1495 mov edi, -1
1496 rol ebx, 10
1497 lea ebp, DWORD PTR 1836072691[esi*1+ebp]
1498 sub edi, eax
1499 rol ebp, 13
1500 add ebp, edx 1487 add ebp, edx
1488 xor eax, edi
1489 mov edx, -1
1490 rol esi, 10
1491 lea ebp, DWORD PTR 1836072691[eax*1+ebp]
1492 sub edx, ecx
1493 rol ebp, 13
1494 add ebp, ebx
1501 ; 122 1495 ; 122
1502 mov esi, DWORD PTR 52[esp] 1496 mov eax, DWORD PTR 48[esp]
1503 or edi, ebp 1497 or edx, ebp
1504 add edx, esi 1498 add ebx, eax
1505 xor edi, ebx 1499 xor edx, esi
1506 mov esi, -1 1500 mov eax, -1
1507 rol eax, 10 1501 rol ecx, 10
1508 lea edx, DWORD PTR 1836072691[edi*1+edx] 1502 lea ebx, DWORD PTR 1836072691[edx*1+ebx]
1509 sub esi, ebp 1503 sub eax, ebp
1510 rol edx, 5 1504 rol ebx, 5
1511 add edx, ecx 1505 add ebx, edi
1512 ; 123 1506 ; 123
1513 mov edi, DWORD PTR 12[esp] 1507 mov edx, DWORD PTR 8[esp]
1514 or esi, edx 1508 or eax, ebx
1515 add ecx, edi 1509 add edi, edx
1516 xor esi, eax 1510 xor eax, ecx
1517 mov edi, -1 1511 mov edx, -1
1518 rol ebp, 10 1512 rol ebp, 10
1519 lea ecx, DWORD PTR 1836072691[esi*1+ecx] 1513 lea edi, DWORD PTR 1836072691[eax*1+edi]
1520 sub edi, edx 1514 sub edx, ebx
1521 rol ecx, 14 1515 rol edi, 14
1522 add ecx, ebx 1516 add edi, esi
1523 ; 124 1517 ; 124
1524 mov esi, DWORD PTR 44[esp] 1518 mov eax, DWORD PTR 40[esp]
1525 or edi, ecx 1519 or edx, edi
1526 add ebx, esi 1520 add esi, eax
1527 xor edi, ebp 1521 xor edx, ebp
1528 mov esi, -1 1522 mov eax, -1
1529 rol edx, 10 1523 rol ebx, 10
1530 lea ebx, DWORD PTR 1836072691[edi*1+ebx] 1524 lea esi, DWORD PTR 1836072691[edx*1+esi]
1531 sub esi, ecx 1525 sub eax, edi
1532 rol ebx, 13 1526 rol esi, 13
1533 add ebx, eax 1527 add esi, ecx
1534 ; 125 1528 ; 125
1535 mov edi, DWORD PTR 4[esp] 1529 mov edx, DWORD PTR [esp]
1536 or esi, ebx 1530 or eax, esi
1537 add eax, edi 1531 add ecx, edx
1538 xor esi, edx 1532 xor eax, ebx
1539 mov edi, -1 1533 mov edx, -1
1540 rol ecx, 10 1534 rol edi, 10
1541 lea eax, DWORD PTR 1836072691[esi*1+eax] 1535 lea ecx, DWORD PTR 1836072691[eax*1+ecx]
1542 sub edi, ebx 1536 sub edx, esi
1543 rol eax, 13 1537 rol ecx, 13
1544 add eax, ebp 1538 add ecx, ebp
1545 ; 126 1539 ; 126
1546 mov esi, DWORD PTR 20[esp] 1540 mov eax, DWORD PTR 16[esp]
1547 or edi, eax 1541 or edx, ecx
1548 add ebp, esi 1542 add ebp, eax
1549 xor edi, ecx 1543 xor edx, edi
1550 mov esi, -1 1544 mov eax, -1
1551 rol ebx, 10 1545 rol esi, 10
1552 lea ebp, DWORD PTR 1836072691[edi*1+ebp] 1546 lea ebp, DWORD PTR 1836072691[edx*1+ebp]
1553 sub esi, eax 1547 sub eax, ecx
1554 rol ebp, 7 1548 rol ebp, 7
1555 add ebp, edx 1549 add ebp, ebx
1556 ; 127 1550 ; 127
1557 mov edi, DWORD PTR 56[esp] 1551 mov edx, DWORD PTR 52[esp]
1558 or esi, ebp 1552 or eax, ebp
1559 add edx, edi 1553 add ebx, edx
1560 xor esi, ebx 1554 xor eax, esi
1561 mov edi, DWORD PTR 36[esp] 1555 mov edx, DWORD PTR 32[esp]
1562 rol eax, 10 1556 rol ecx, 10
1563 lea edx, DWORD PTR 1836072691[esi*1+edx] 1557 lea ebx, DWORD PTR 1836072691[eax*1+ebx]
1564 mov esi, -1 1558 mov eax, -1
1565 rol edx, 5 1559 rol ebx, 5
1566 add edx, ecx 1560 add ebx, edi
1567 ; 128 1561 ; 128
1568 add ecx, edi 1562 add edi, edx
1569 mov edi, ebp 1563 mov edx, ebp
1570 sub esi, edx 1564 sub eax, ebx
1571 and edi, edx 1565 and edx, ebx
1572 and esi, eax 1566 and eax, ecx
1573 or edi, esi 1567 or edx, eax
1574 mov esi, DWORD PTR 28[esp] 1568 mov eax, DWORD PTR 24[esp]
1575 rol ebp, 10 1569 rol ebp, 10
1576 lea ecx, DWORD PTR 2053994217[edi*1+ecx] 1570 lea edi, DWORD PTR 2053994217[edx*1+edi]
1577 mov edi, -1 1571 mov edx, -1
1578 rol ecx, 15 1572 rol edi, 15
1579 add ecx, ebx 1573 add edi, esi
1580 ; 129 1574 ; 129
1581 add ebx, esi 1575 add esi, eax
1582 mov esi, edx 1576 mov eax, ebx
1583 sub edi, ecx 1577 sub edx, edi
1584 and esi, ecx 1578 and eax, edi
1585 and edi, ebp 1579 and edx, ebp
1586 or esi, edi 1580 or eax, edx
1587 mov edi, DWORD PTR 20[esp] 1581 mov edx, DWORD PTR 16[esp]
1588 rol edx, 10 1582 rol ebx, 10
1589 lea ebx, DWORD PTR 2053994217[esi*1+ebx] 1583 lea esi, DWORD PTR 2053994217[eax*1+esi]
1590 mov esi, -1 1584 mov eax, -1
1591 rol ebx, 5 1585 rol esi, 5
1592 add ebx, eax 1586 add esi, ecx
1593 ; 130 1587 ; 130
1594 add eax, edi 1588 add ecx, edx
1595 mov edi, ecx 1589 mov edx, edi
1596 sub esi, ebx 1590 sub eax, esi
1597 and edi, ebx 1591 and edx, esi
1598 and esi, edx 1592 and eax, ebx
1599 or edi, esi 1593 or edx, eax
1600 mov esi, DWORD PTR 8[esp] 1594 mov eax, DWORD PTR 4[esp]
1601 rol ecx, 10 1595 rol edi, 10
1602 lea eax, DWORD PTR 2053994217[edi*1+eax] 1596 lea ecx, DWORD PTR 2053994217[edx*1+ecx]
1603 mov edi, -1 1597 mov edx, -1
1604 rol eax, 8 1598 rol ecx, 8
1605 add eax, ebp 1599 add ecx, ebp
1606 ; 131 1600 ; 131
1607 add ebp, esi 1601 add ebp, eax
1608 mov esi, ebx 1602 mov eax, esi
1609 sub edi, eax 1603 sub edx, ecx
1610 and esi, eax 1604 and eax, ecx
1611 and edi, ecx 1605 and edx, edi
1612 or esi, edi 1606 or eax, edx
1613 mov edi, DWORD PTR 16[esp] 1607 mov edx, DWORD PTR 12[esp]
1614 rol ebx, 10 1608 rol esi, 10
1615 lea ebp, DWORD PTR 2053994217[esi*1+ebp] 1609 lea ebp, DWORD PTR 2053994217[eax*1+ebp]
1616 mov esi, -1 1610 mov eax, -1
1617 rol ebp, 11 1611 rol ebp, 11
1618 add ebp, edx 1612 add ebp, ebx
1619 ; 132 1613 ; 132
1620 add edx, edi 1614 add ebx, edx
1621 mov edi, eax 1615 mov edx, ecx
1622 sub esi, ebp 1616 sub eax, ebp
1623 and edi, ebp 1617 and edx, ebp
1624 and esi, ebx 1618 and eax, esi
1625 or edi, esi 1619 or edx, eax
1626 mov esi, DWORD PTR 48[esp] 1620 mov eax, DWORD PTR 44[esp]
1627 rol eax, 10 1621 rol ecx, 10
1628 lea edx, DWORD PTR 2053994217[edi*1+edx] 1622 lea ebx, DWORD PTR 2053994217[edx*1+ebx]
1629 mov edi, -1 1623 mov edx, -1
1630 rol edx, 14 1624 rol ebx, 14
1631 add edx, ecx 1625 add ebx, edi
1632 ; 133 1626 ; 133
1633 add ecx, esi 1627 add edi, eax
1634 mov esi, ebp 1628 mov eax, ebp
1635 sub edi, edx 1629 sub edx, ebx
1636 and esi, edx 1630 and eax, ebx
1637 and edi, eax 1631 and edx, ecx
1638 or esi, edi 1632 or eax, edx
1639 mov edi, DWORD PTR 64[esp] 1633 mov edx, DWORD PTR 60[esp]
1640 rol ebp, 10 1634 rol ebp, 10
1641 lea ecx, DWORD PTR 2053994217[esi*1+ecx] 1635 lea edi, DWORD PTR 2053994217[eax*1+edi]
1642 mov esi, -1 1636 mov eax, -1
1643 rol ecx, 14 1637 rol edi, 14
1644 add ecx, ebx 1638 add edi, esi
1645 ; 134 1639 ; 134
1646 add ebx, edi 1640 add esi, edx
1647 mov edi, edx 1641 mov edx, ebx
1648 sub esi, ecx 1642 sub eax, edi
1649 and edi, ecx 1643 and edx, edi
1650 and esi, ebp 1644 and eax, ebp
1651 or edi, esi 1645 or edx, eax
1652 mov esi, DWORD PTR 4[esp] 1646 mov eax, DWORD PTR [esp]
1653 rol edx, 10 1647 rol ebx, 10
1654 lea ebx, DWORD PTR 2053994217[edi*1+ebx] 1648 lea esi, DWORD PTR 2053994217[edx*1+esi]
1655 mov edi, -1 1649 mov edx, -1
1656 rol ebx, 6 1650 rol esi, 6
1657 add ebx, eax 1651 add esi, ecx
1658 ; 135 1652 ; 135
1659 add eax, esi 1653 add ecx, eax
1660 mov esi, ecx 1654 mov eax, edi
1661 sub edi, ebx 1655 sub edx, esi
1662 and esi, ebx 1656 and eax, esi
1663 and edi, edx 1657 and edx, ebx
1664 or esi, edi 1658 or eax, edx
1665 mov edi, DWORD PTR 24[esp] 1659 mov edx, DWORD PTR 20[esp]
1666 rol ecx, 10 1660 rol edi, 10
1667 lea eax, DWORD PTR 2053994217[esi*1+eax] 1661 lea ecx, DWORD PTR 2053994217[eax*1+ecx]
1668 mov esi, -1 1662 mov eax, -1
1669 rol eax, 14 1663 rol ecx, 14
1670 add eax, ebp 1664 add ecx, ebp
1671 ; 136 1665 ; 136
1672 add ebp, edi
1673 mov edi, ebx
1674 sub esi, eax
1675 and edi, eax
1676 and esi, ecx
1677 or edi, esi
1678 mov esi, DWORD PTR 52[esp]
1679 rol ebx, 10
1680 lea ebp, DWORD PTR 2053994217[edi*1+ebp]
1681 mov edi, -1
1682 rol ebp, 6
1683 add ebp, edx 1666 add ebp, edx
1667 mov edx, esi
1668 sub eax, ecx
1669 and edx, ecx
1670 and eax, edi
1671 or edx, eax
1672 mov eax, DWORD PTR 48[esp]
1673 rol esi, 10
1674 lea ebp, DWORD PTR 2053994217[edx*1+ebp]
1675 mov edx, -1
1676 rol ebp, 6
1677 add ebp, ebx
1684 ; 137 1678 ; 137
1685 add edx, esi 1679 add ebx, eax
1686 mov esi, eax 1680 mov eax, ecx
1687 sub edi, ebp 1681 sub edx, ebp
1688 and esi, ebp 1682 and eax, ebp
1689 and edi, ebx 1683 and edx, esi
1690 or esi, edi 1684 or eax, edx
1691 mov edi, DWORD PTR 12[esp] 1685 mov edx, DWORD PTR 8[esp]
1692 rol eax, 10 1686 rol ecx, 10
1693 lea edx, DWORD PTR 2053994217[esi*1+edx] 1687 lea ebx, DWORD PTR 2053994217[eax*1+ebx]
1694 mov esi, -1 1688 mov eax, -1
1695 rol edx, 9 1689 rol ebx, 9
1696 add edx, ecx 1690 add ebx, edi
1697 ; 138 1691 ; 138
1698 add ecx, edi 1692 add edi, edx
1699 mov edi, ebp 1693 mov edx, ebp
1700 sub esi, edx 1694 sub eax, ebx
1701 and edi, edx 1695 and edx, ebx
1702 and esi, eax 1696 and eax, ecx
1703 or edi, esi 1697 or edx, eax
1704 mov esi, DWORD PTR 56[esp] 1698 mov eax, DWORD PTR 52[esp]
1705 rol ebp, 10 1699 rol ebp, 10
1706 lea ecx, DWORD PTR 2053994217[edi*1+ecx] 1700 lea edi, DWORD PTR 2053994217[edx*1+edi]
1707 mov edi, -1 1701 mov edx, -1
1708 rol ecx, 12 1702 rol edi, 12
1709 add ecx, ebx 1703 add edi, esi
1710 ; 139 1704 ; 139
1711 add ebx, esi 1705 add esi, eax
1712 mov esi, edx 1706 mov eax, ebx
1713 sub edi, ecx 1707 sub edx, edi
1714 and esi, ecx 1708 and eax, edi
1715 and edi, ebp 1709 and edx, ebp
1716 or esi, edi 1710 or eax, edx
1717 mov edi, DWORD PTR 40[esp] 1711 mov edx, DWORD PTR 36[esp]
1718 rol edx, 10 1712 rol ebx, 10
1719 lea ebx, DWORD PTR 2053994217[esi*1+ebx] 1713 lea esi, DWORD PTR 2053994217[eax*1+esi]
1720 mov esi, -1 1714 mov eax, -1
1721 rol ebx, 9 1715 rol esi, 9
1722 add ebx, eax 1716 add esi, ecx
1723 ; 140 1717 ; 140
1724 add eax, edi 1718 add ecx, edx
1725 mov edi, ecx 1719 mov edx, edi
1726 sub esi, ebx 1720 sub eax, esi
1727 and edi, ebx 1721 and edx, esi
1728 and esi, edx 1722 and eax, ebx
1729 or edi, esi 1723 or edx, eax
1730 mov esi, DWORD PTR 32[esp] 1724 mov eax, DWORD PTR 28[esp]
1731 rol ecx, 10 1725 rol edi, 10
1732 lea eax, DWORD PTR 2053994217[edi*1+eax] 1726 lea ecx, DWORD PTR 2053994217[edx*1+ecx]
1733 mov edi, -1 1727 mov edx, -1
1734 rol eax, 12 1728 rol ecx, 12
1735 add eax, ebp 1729 add ecx, ebp
1736 ; 141 1730 ; 141
1737 add ebp, esi 1731 add ebp, eax
1738 mov esi, ebx 1732 mov eax, esi
1739 sub edi, eax 1733 sub edx, ecx
1740 and esi, eax 1734 and eax, ecx
1741 and edi, ecx 1735 and edx, edi
1742 or esi, edi 1736 or eax, edx
1743 mov edi, DWORD PTR 44[esp] 1737 mov edx, DWORD PTR 40[esp]
1744 rol ebx, 10 1738 rol esi, 10
1745 lea ebp, DWORD PTR 2053994217[esi*1+ebp] 1739 lea ebp, DWORD PTR 2053994217[eax*1+ebp]
1746 mov esi, -1 1740 mov eax, -1
1747 rol ebp, 5 1741 rol ebp, 5
1748 add ebp, edx 1742 add ebp, ebx
1749 ; 142 1743 ; 142
1750 add edx, edi 1744 add ebx, edx
1751 mov edi, eax 1745 mov edx, ecx
1752 sub esi, ebp 1746 sub eax, ebp
1753 and edi, ebp 1747 and edx, ebp
1754 and esi, ebx 1748 and eax, esi
1755 or edi, esi 1749 or edx, eax
1756 mov esi, DWORD PTR 60[esp] 1750 mov eax, DWORD PTR 56[esp]
1757 rol eax, 10 1751 rol ecx, 10
1758 lea edx, DWORD PTR 2053994217[edi*1+edx] 1752 lea ebx, DWORD PTR 2053994217[edx*1+ebx]
1759 mov edi, -1 1753 mov edx, -1
1760 rol edx, 15 1754 rol ebx, 15
1761 add edx, ecx 1755 add ebx, edi
1762 ; 143 1756 ; 143
1763 add ecx, esi 1757 add edi, eax
1764 mov esi, ebp 1758 mov eax, ebp
1765 sub edi, edx 1759 sub edx, ebx
1766 and esi, edx 1760 and eax, ebx
1767 and edi, eax 1761 and edx, ecx
1768 or edi, esi 1762 or edx, eax
1769 mov esi, edx 1763 mov eax, ebx
1770 rol ebp, 10 1764 rol ebp, 10
1771 lea ecx, DWORD PTR 2053994217[edi*1+ecx] 1765 lea edi, DWORD PTR 2053994217[edx*1+edi]
1772 xor esi, ebp 1766 xor eax, ebp
1773 rol ecx, 8 1767 rol edi, 8
1774 add ecx, ebx 1768 add edi, esi
1775 ; 144 1769 ; 144
1776 mov edi, DWORD PTR 52[esp] 1770 mov edx, DWORD PTR 48[esp]
1777 xor esi, ecx 1771 xor eax, edi
1778 add ebx, edi 1772 add esi, edx
1779 rol edx, 10 1773 rol ebx, 10
1780 add ebx, esi 1774 add esi, eax
1781 mov esi, ecx 1775 mov eax, edi
1782 rol ebx, 8 1776 rol esi, 8
1783 add ebx, eax 1777 add esi, ecx
1784 ; 145 1778 ; 145
1785 xor esi, edx 1779 xor eax, ebx
1786 mov edi, DWORD PTR 64[esp] 1780 mov edx, DWORD PTR 60[esp]
1787 xor esi, ebx 1781 xor eax, esi
1788 add eax, esi 1782 add ecx, eax
1789 mov esi, ebx 1783 mov eax, esi
1790 rol ecx, 10 1784 rol edi, 10
1791 add eax, edi 1785 add ecx, edx
1792 xor esi, ecx 1786 xor eax, edi
1793 rol eax, 5 1787 rol ecx, 5
1794 add eax, ebp 1788 add ecx, ebp
1795 ; 146 1789 ; 146
1796 mov edi, DWORD PTR 44[esp] 1790 mov edx, DWORD PTR 40[esp]
1797 xor esi, eax 1791 xor eax, ecx
1798 add ebp, edi
1799 rol ebx, 10
1800 add ebp, esi
1801 mov esi, eax
1802 rol ebp, 12
1803 add ebp, edx 1792 add ebp, edx
1793 rol esi, 10
1794 add ebp, eax
1795 mov eax, ecx
1796 rol ebp, 12
1797 add ebp, ebx
1804 ; 147 1798 ; 147
1805 xor esi, ebx 1799 xor eax, esi
1806 mov edi, DWORD PTR 20[esp] 1800 mov edx, DWORD PTR 16[esp]
1807 xor esi, ebp 1801 xor eax, ebp
1808 add edx, esi 1802 add ebx, eax
1809 mov esi, ebp 1803 mov eax, ebp
1810 rol eax, 10 1804 rol ecx, 10
1811 add edx, edi 1805 add ebx, edx
1812 xor esi, eax 1806 xor eax, ecx
1813 rol edx, 9 1807 rol ebx, 9
1814 add edx, ecx 1808 add ebx, edi
1815 ; 148 1809 ; 148
1816 mov edi, DWORD PTR 8[esp] 1810 mov edx, DWORD PTR 4[esp]
1817 xor esi, edx 1811 xor eax, ebx
1818 add ecx, edi 1812 add edi, edx
1819 rol ebp, 10 1813 rol ebp, 10
1820 add ecx, esi 1814 add edi, eax
1821 mov esi, edx 1815 mov eax, ebx
1822 rol ecx, 12 1816 rol edi, 12
1823 add ecx, ebx 1817 add edi, esi
1824 ; 149 1818 ; 149
1825 xor esi, ebp 1819 xor eax, ebp
1826 mov edi, DWORD PTR 24[esp] 1820 mov edx, DWORD PTR 20[esp]
1827 xor esi, ecx 1821 xor eax, edi
1828 add ebx, esi 1822 add esi, eax
1829 mov esi, ecx 1823 mov eax, edi
1830 rol edx, 10 1824 rol ebx, 10
1831 add ebx, edi 1825 add esi, edx
1832 xor esi, edx 1826 xor eax, ebx
1833 rol ebx, 5 1827 rol esi, 5
1834 add ebx, eax 1828 add esi, ecx
1835 ; 150 1829 ; 150
1836 mov edi, DWORD PTR 36[esp] 1830 mov edx, DWORD PTR 32[esp]
1837 xor esi, ebx 1831 xor eax, esi
1838 add eax, edi 1832 add ecx, edx
1839 rol ecx, 10 1833 rol edi, 10
1840 add eax, esi 1834 add ecx, eax
1841 mov esi, ebx 1835 mov eax, esi
1842 rol eax, 14 1836 rol ecx, 14
1843 add eax, ebp 1837 add ecx, ebp
1844 ; 151 1838 ; 151
1845 xor esi, ecx 1839 xor eax, edi
1846 mov edi, DWORD PTR 32[esp] 1840 mov edx, DWORD PTR 28[esp]
1847 xor esi, eax 1841 xor eax, ecx
1848 add ebp, esi 1842 add ebp, eax
1849 mov esi, eax 1843 mov eax, ecx
1850 rol ebx, 10 1844 rol esi, 10
1851 add ebp, edi
1852 xor esi, ebx
1853 rol ebp, 6
1854 add ebp, edx 1845 add ebp, edx
1846 xor eax, esi
1847 rol ebp, 6
1848 add ebp, ebx
1855 ; 152 1849 ; 152
1856 mov edi, DWORD PTR 28[esp] 1850 mov edx, DWORD PTR 24[esp]
1857 xor esi, ebp 1851 xor eax, ebp
1858 add edx, edi 1852 add ebx, edx
1859 rol eax, 10 1853 rol ecx, 10
1860 add edx, esi 1854 add ebx, eax
1861 mov esi, ebp 1855 mov eax, ebp
1862 rol edx, 8 1856 rol ebx, 8
1863 add edx, ecx 1857 add ebx, edi
1864 ; 153 1858 ; 153
1865 xor esi, eax 1859 xor eax, ecx
1866 mov edi, DWORD PTR 12[esp] 1860 mov edx, DWORD PTR 8[esp]
1867 xor esi, edx 1861 xor eax, ebx
1868 add ecx, esi 1862 add edi, eax
1869 mov esi, edx 1863 mov eax, ebx
1870 rol ebp, 10 1864 rol ebp, 10
1871 add ecx, edi 1865 add edi, edx
1872 xor esi, ebp 1866 xor eax, ebp
1873 rol ecx, 13 1867 rol edi, 13
1874 add ecx, ebx 1868 add edi, esi
1875 ; 154 1869 ; 154
1876 mov edi, DWORD PTR 56[esp] 1870 mov edx, DWORD PTR 52[esp]
1877 xor esi, ecx 1871 xor eax, edi
1878 add ebx, edi 1872 add esi, edx
1879 rol edx, 10 1873 rol ebx, 10
1880 add ebx, esi 1874 add esi, eax
1881 mov esi, ecx 1875 mov eax, edi
1882 rol ebx, 6 1876 rol esi, 6
1883 add ebx, eax 1877 add esi, ecx
1884 ; 155 1878 ; 155
1885 xor esi, edx 1879 xor eax, ebx
1886 mov edi, DWORD PTR 60[esp] 1880 mov edx, DWORD PTR 56[esp]
1887 xor esi, ebx 1881 xor eax, esi
1888 add eax, esi 1882 add ecx, eax
1889 mov esi, ebx 1883 mov eax, esi
1890 rol ecx, 10 1884 rol edi, 10
1891 add eax, edi 1885 add ecx, edx
1892 xor esi, ecx 1886 xor eax, edi
1893 rol eax, 5 1887 rol ecx, 5
1894 add eax, ebp 1888 add ecx, ebp
1895 ; 156 1889 ; 156
1896 mov edi, DWORD PTR 4[esp] 1890 mov edx, DWORD PTR [esp]
1897 xor esi, eax 1891 xor eax, ecx
1898 add ebp, edi
1899 rol ebx, 10
1900 add ebp, esi
1901 mov esi, eax
1902 rol ebp, 15
1903 add ebp, edx 1892 add ebp, edx
1893 rol esi, 10
1894 add ebp, eax
1895 mov eax, ecx
1896 rol ebp, 15
1897 add ebp, ebx
1904 ; 157 1898 ; 157
1905 xor esi, ebx 1899 xor eax, esi
1906 mov edi, DWORD PTR 16[esp] 1900 mov edx, DWORD PTR 12[esp]
1907 xor esi, ebp 1901 xor eax, ebp
1908 add edx, esi 1902 add ebx, eax
1909 mov esi, ebp 1903 mov eax, ebp
1910 rol eax, 10 1904 rol ecx, 10
1911 add edx, edi 1905 add ebx, edx
1912 xor esi, eax 1906 xor eax, ecx
1913 rol edx, 13 1907 rol ebx, 13
1914 add edx, ecx 1908 add ebx, edi
1915 ; 158 1909 ; 158
1916 mov edi, DWORD PTR 40[esp] 1910 mov edx, DWORD PTR 36[esp]
1917 xor esi, edx 1911 xor eax, ebx
1918 add ecx, edi 1912 add edi, edx
1919 rol ebp, 10 1913 rol ebp, 10
1920 add ecx, esi 1914 add edi, eax
1921 mov esi, edx 1915 mov eax, ebx
1922 rol ecx, 11 1916 rol edi, 11
1923 add ecx, ebx 1917 add edi, esi
1924 ; 159 1918 ; 159
1925 xor esi, ebp 1919 xor eax, ebp
1926 mov edi, DWORD PTR 48[esp] 1920 mov edx, DWORD PTR 44[esp]
1927 xor esi, ecx 1921 xor eax, edi
1928 add ebx, esi 1922 add esi, eax
1929 rol edx, 10 1923 rol ebx, 10
1930 add ebx, edi 1924 add esi, edx
1931 mov edi, DWORD PTR 108[esp] 1925 mov edx, DWORD PTR 128[esp]
1932 rol ebx, 11 1926 rol esi, 11
1927 add esi, ecx
1928 mov eax, DWORD PTR 4[edx]
1933 add ebx, eax 1929 add ebx, eax
1934 mov esi, DWORD PTR 4[edi] 1930 mov eax, DWORD PTR 72[esp]
1935 add edx, esi 1931 add ebx, eax
1936 mov esi, DWORD PTR 76[esp] 1932 mov eax, DWORD PTR 8[edx]
1937 add edx, esi 1933 add ebp, eax
1938 mov esi, DWORD PTR 8[edi] 1934 mov eax, DWORD PTR 76[esp]
1939 add ebp, esi 1935 add ebp, eax
1940 mov esi, DWORD PTR 80[esp] 1936 mov eax, DWORD PTR 12[edx]
1941 add ebp, esi 1937 add ecx, eax
1942 mov esi, DWORD PTR 12[edi] 1938 mov eax, DWORD PTR 80[esp]
1943 add eax, esi 1939 add ecx, eax
1944 mov esi, DWORD PTR 84[esp] 1940 mov eax, DWORD PTR 16[edx]
1945 add eax, esi 1941 add esi, eax
1946 mov esi, DWORD PTR 16[edi] 1942 mov eax, DWORD PTR 64[esp]
1947 add ebx, esi 1943 add esi, eax
1948 mov esi, DWORD PTR 68[esp] 1944 mov eax, DWORD PTR [edx]
1949 add ebx, esi 1945 add edi, eax
1950 mov esi, DWORD PTR [edi] 1946 mov eax, DWORD PTR 68[esp]
1951 add ecx, esi 1947 add edi, eax
1952 mov esi, DWORD PTR 72[esp] 1948 mov eax, DWORD PTR 136[esp]
1953 add ecx, esi 1949 mov DWORD PTR [edx],ebx
1954 mov DWORD PTR [edi],edx 1950 mov DWORD PTR 4[edx],ebp
1955 mov DWORD PTR 4[edi],ebp 1951 mov DWORD PTR 8[edx],ecx
1956 mov DWORD PTR 8[edi],eax 1952 sub eax, 1
1957 mov DWORD PTR 12[edi],ebx 1953 mov DWORD PTR 12[edx],esi
1958 mov DWORD PTR 16[edi],ecx 1954 mov DWORD PTR 16[edx],edi
1959 mov edi, DWORD PTR [esp] 1955 jle $L001get_out
1960 mov esi, DWORD PTR 112[esp] 1956 mov DWORD PTR 136[esp],eax
1961 cmp edi, esi 1957 mov edi, ecx
1962 mov edi, DWORD PTR 108[esp] 1958 mov eax, DWORD PTR 132[esp]
1963 jge L000start 1959 mov ecx, ebx
1964 add esp, 88 1960 add eax, 64
1961 mov esi, ebp
1962 mov DWORD PTR 132[esp],eax
1963 jmp L000start
1964$L001get_out:
1965 add esp, 108
1965 pop ebx 1966 pop ebx
1966 pop ebp 1967 pop ebp
1967 pop edi 1968 pop edi
1968 pop esi 1969 pop esi
1969 ret 1970 ret
1970_ripemd160_block_x86 ENDP 1971_ripemd160_block_asm_host_order ENDP
1971_TEXT ENDS 1972_TEXT ENDS
1972END 1973END
diff --git a/src/lib/libcrypto/ripemd/asm/rmd-586.pl b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
index e53c5fadba..0ab6f76bff 100644
--- a/src/lib/libcrypto/ripemd/asm/rmd-586.pl
+++ b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
@@ -1,9 +1,7 @@
1#!/usr/local/bin/perl 1#!/usr/local/bin/perl
2 2
3# Normal is the 3# Normal is the
4# ripemd160_block_x86(MD5_CTX *c, ULONG *X); 4# ripemd160_block_asm_host_order(RIPEMD160_CTX *c, ULONG *X,int blocks);
5# version, non-normal is the
6# ripemd160_block_x86(MD5_CTX *c, ULONG *X,int blocks);
7 5
8$normal=0; 6$normal=0;
9 7
@@ -12,13 +10,13 @@ require "x86asm.pl";
12 10
13&asm_init($ARGV[0],$0); 11&asm_init($ARGV[0],$0);
14 12
15$A="eax"; 13$A="ecx";
16$B="ebx"; 14$B="esi";
17$C="ecx"; 15$C="edi";
18$D="edx"; 16$D="ebx";
19$E="ebp"; 17$E="ebp";
20$tmp1="esi"; 18$tmp1="eax";
21$tmp2="edi"; 19$tmp2="edx";
22 20
23$KL1=0x5A827999; 21$KL1=0x5A827999;
24$KL2=0x6ED9EBA1; 22$KL2=0x6ED9EBA1;
@@ -58,13 +56,13 @@ $KR3=0x7A6D76E9;
58 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11, 56 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11,
59 ); 57 );
60 58
61&ripemd160_block("ripemd160_block_x86"); 59&ripemd160_block("ripemd160_block_asm_host_order");
62&asm_finish(); 60&asm_finish();
63 61
64sub Xv 62sub Xv
65 { 63 {
66 local($n)=@_; 64 local($n)=@_;
67 return(&swtmp($n+1)); 65 return(&swtmp($n));
68 # tmp on stack 66 # tmp on stack
69 } 67 }
70 68
@@ -82,7 +80,7 @@ sub RIP1
82 &comment($p++); 80 &comment($p++);
83 if ($p & 1) 81 if ($p & 1)
84 { 82 {
85 &mov($tmp1, $c) if $o == -1; 83 #&mov($tmp1, $c) if $o == -1;
86 &xor($tmp1, $d) if $o == -1; 84 &xor($tmp1, $d) if $o == -1;
87 &mov($tmp2, &Xv($pos)); 85 &mov($tmp2, &Xv($pos));
88 &xor($tmp1, $b); 86 &xor($tmp1, $b);
@@ -290,7 +288,7 @@ sub RIP5
290 &rotl($c, 10); 288 &rotl($c, 10);
291 &lea($a, &DWP($K,$a,$tmp1,1)); 289 &lea($a, &DWP($K,$a,$tmp1,1));
292 &sub($tmp2, &Np($d)) if $o <= 0; 290 &sub($tmp2, &Np($d)) if $o <= 0;
293 &mov(&swtmp(1+16), $A) if $o == 1; 291 &mov(&swtmp(16), $A) if $o == 1;
294 &mov($tmp1, &Np($d)) if $o == 2; 292 &mov($tmp1, &Np($d)) if $o == 2;
295 &rotl($a, $s); 293 &rotl($a, $s);
296 &add($a, $e); 294 &add($a, $e);
@@ -310,19 +308,25 @@ sub ripemd160_block
310 # D 12 308 # D 12
311 # E 16 309 # E 16
312 310
311 &mov($tmp2, &wparam(0));
312 &mov($tmp1, &wparam(1));
313 &push("esi"); 313 &push("esi");
314 &mov($C, &wparam(2)); 314 &mov($A, &DWP( 0,$tmp2,"",0));
315 &push("edi"); 315 &push("edi");
316 &mov($tmp1, &wparam(1)); # edi 316 &mov($B, &DWP( 4,$tmp2,"",0));
317 &push("ebp"); 317 &push("ebp");
318 &add($C, $tmp1); # offset we end at 318 &mov($C, &DWP( 8,$tmp2,"",0));
319 &push("ebx"); 319 &push("ebx");
320 &sub($C, 64); 320 &stack_push(16+5+6);
321 &stack_push(16+5+1); 321 # Special comment about the figure of 6.
322 # XXX 322 # Idea is to pad the current frame so
323 323 # that the top of the stack gets fairly
324 &mov(&swtmp(0), $C); 324 # aligned. Well, as you realize it would
325 &mov($tmp2, &wparam(0)); # Done at end of loop 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>
326 330
327 &set_label("start") unless $normal; 331 &set_label("start") unless $normal;
328 &comment(""); 332 &comment("");
@@ -332,16 +336,12 @@ sub ripemd160_block
332 336
333 for ($z=0; $z<16; $z+=2) 337 for ($z=0; $z<16; $z+=2)
334 { 338 {
335 &mov($A, &DWP( $z*4,$tmp1,"",0)); 339 &mov($D, &DWP( $z*4,$tmp1,"",0));
336 &mov($B, &DWP( ($z+1)*4,$tmp1,"",0)); 340 &mov($E, &DWP( ($z+1)*4,$tmp1,"",0));
337 &mov(&swtmp(1+$z), $A); 341 &mov(&swtmp($z), $D);
338 &mov(&swtmp(1+$z+1), $B); 342 &mov(&swtmp($z+1), $E);
339 } 343 }
340 &add($tmp1, 64); 344 &mov($tmp1, $C);
341 &mov($A, &DWP( 0,$tmp2,"",0));
342 &mov(&wparam(1),$tmp1);
343 &mov($B, &DWP( 4,$tmp2,"",0));
344 &mov($C, &DWP( 8,$tmp2,"",0));
345 &mov($D, &DWP(12,$tmp2,"",0)); 345 &mov($D, &DWP(12,$tmp2,"",0));
346 &mov($E, &DWP(16,$tmp2,"",0)); 346 &mov($E, &DWP(16,$tmp2,"",0));
347 347
@@ -431,14 +431,14 @@ sub ripemd160_block
431 &RIP5($B,$C,$D,$E,$A,$wl[79],$sl[79],$KL4,1); 431 &RIP5($B,$C,$D,$E,$A,$wl[79],$sl[79],$KL4,1);
432 432
433 # &mov($tmp2, &wparam(0)); # moved into last RIP5 433 # &mov($tmp2, &wparam(0)); # moved into last RIP5
434 # &mov(&swtmp(1+16), $A); 434 # &mov(&swtmp(16), $A);
435 &mov($A, &DWP( 0,$tmp2,"",0)); 435 &mov($A, &DWP( 0,$tmp2,"",0));
436 &mov(&swtmp(1+17), $B); 436 &mov(&swtmp(16+1), $B);
437 &mov(&swtmp(1+18), $C); 437 &mov(&swtmp(16+2), $C);
438 &mov($B, &DWP( 4,$tmp2,"",0)); 438 &mov($B, &DWP( 4,$tmp2,"",0));
439 &mov(&swtmp(1+19), $D); 439 &mov(&swtmp(16+3), $D);
440 &mov($C, &DWP( 8,$tmp2,"",0)); 440 &mov($C, &DWP( 8,$tmp2,"",0));
441 &mov(&swtmp(1+20), $E); 441 &mov(&swtmp(16+4), $E);
442 &mov($D, &DWP(12,$tmp2,"",0)); 442 &mov($D, &DWP(12,$tmp2,"",0));
443 &mov($E, &DWP(16,$tmp2,"",0)); 443 &mov($E, &DWP(16,$tmp2,"",0));
444 444
@@ -531,46 +531,54 @@ sub ripemd160_block
531 531
532 &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B 532 &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B
533 &add($D, $tmp1); 533 &add($D, $tmp1);
534 &mov($tmp1, &swtmp(1+18)); # $c 534 &mov($tmp1, &swtmp(16+2)); # $c
535 &add($D, $tmp1); 535 &add($D, $tmp1);
536 536
537 &mov($tmp1, &DWP( 8,$tmp2,"",0)); # ctx->C 537 &mov($tmp1, &DWP( 8,$tmp2,"",0)); # ctx->C
538 &add($E, $tmp1); 538 &add($E, $tmp1);
539 &mov($tmp1, &swtmp(1+19)); # $d 539 &mov($tmp1, &swtmp(16+3)); # $d
540 &add($E, $tmp1); 540 &add($E, $tmp1);
541 541
542 &mov($tmp1, &DWP(12,$tmp2,"",0)); # ctx->D 542 &mov($tmp1, &DWP(12,$tmp2,"",0)); # ctx->D
543 &add($A, $tmp1); 543 &add($A, $tmp1);
544 &mov($tmp1, &swtmp(1+20)); # $e 544 &mov($tmp1, &swtmp(16+4)); # $e
545 &add($A, $tmp1); 545 &add($A, $tmp1);
546 546
547 547
548 &mov($tmp1, &DWP(16,$tmp2,"",0)); # ctx->E 548 &mov($tmp1, &DWP(16,$tmp2,"",0)); # ctx->E
549 &add($B, $tmp1); 549 &add($B, $tmp1);
550 &mov($tmp1, &swtmp(1+16)); # $a 550 &mov($tmp1, &swtmp(16+0)); # $a
551 &add($B, $tmp1); 551 &add($B, $tmp1);
552 552
553 &mov($tmp1, &DWP( 0,$tmp2,"",0)); # ctx->A 553 &mov($tmp1, &DWP( 0,$tmp2,"",0)); # ctx->A
554 &add($C, $tmp1); 554 &add($C, $tmp1);
555 &mov($tmp1, &swtmp(1+17)); # $b 555 &mov($tmp1, &swtmp(16+1)); # $b
556 &add($C, $tmp1); 556 &add($C, $tmp1);
557 557
558 &mov($tmp1, &wparam(2));
559
558 &mov(&DWP( 0,$tmp2,"",0), $D); 560 &mov(&DWP( 0,$tmp2,"",0), $D);
559 &mov(&DWP( 4,$tmp2,"",0), $E); 561 &mov(&DWP( 4,$tmp2,"",0), $E);
560 &mov(&DWP( 8,$tmp2,"",0), $A); 562 &mov(&DWP( 8,$tmp2,"",0), $A);
561 &mov(&DWP(12,$tmp2,"",0), $B); 563 &sub($tmp1,1);
562 &mov(&DWP(16,$tmp2,"",0), $C); 564 &mov(&DWP(12,$tmp2,"",0), $B);
565 &mov(&DWP(16,$tmp2,"",0), $C);
563 566
564 &mov($tmp2, &swtmp(0)); 567 &jle(&label("get_out"));
565 &mov($tmp1, &wparam(1)); 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);
566 576
567 &cmp($tmp2,$tmp1); 577 &jmp(&label("start"));
568 &mov($tmp2, &wparam(0));
569 578
570 # XXX 579 &set_label("get_out");
571 &jge(&label("start"));
572 580
573 &stack_pop(16+5+1); 581 &stack_pop(16+5+6);
574 582
575 &pop("ebx"); 583 &pop("ebx");
576 &pop("ebp"); 584 &pop("ebp");
diff --git a/src/lib/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h
index ab76be4c33..dd1627cf40 100644
--- a/src/lib/libcrypto/ripemd/ripemd.h
+++ b/src/lib/libcrypto/ripemd/ripemd.h
@@ -67,26 +67,33 @@ extern "C" {
67#error RIPEMD is disabled. 67#error RIPEMD is disabled.
68#endif 68#endif
69 69
70#if defined(WIN16) || defined(__LP32__)
71#define RIPEMD160_LONG unsigned long
72#elif defined(_CRAY) || defined(__ILP64__)
73#define RIPEMD160_LONG unsigned long
74#define RIPEMD160_LONG_LOG2 3
75#else
76#define RIPEMD160_LONG unsigned int
77#endif
78
70#define RIPEMD160_CBLOCK 64 79#define RIPEMD160_CBLOCK 64
71#define RIPEMD160_LBLOCK 16 80#define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4)
72#define RIPEMD160_BLOCK 16
73#define RIPEMD160_LAST_BLOCK 56
74#define RIPEMD160_LENGTH_BLOCK 8
75#define RIPEMD160_DIGEST_LENGTH 20 81#define RIPEMD160_DIGEST_LENGTH 20
76 82
77typedef struct RIPEMD160state_st 83typedef struct RIPEMD160state_st
78 { 84 {
79 unsigned long A,B,C,D,E; 85 RIPEMD160_LONG A,B,C,D,E;
80 unsigned long Nl,Nh; 86 RIPEMD160_LONG Nl,Nh;
81 unsigned long data[RIPEMD160_LBLOCK]; 87 RIPEMD160_LONG data[RIPEMD160_LBLOCK];
82 int num; 88 int num;
83 } RIPEMD160_CTX; 89 } RIPEMD160_CTX;
84 90
85void RIPEMD160_Init(RIPEMD160_CTX *c); 91void RIPEMD160_Init(RIPEMD160_CTX *c);
86void RIPEMD160_Update(RIPEMD160_CTX *c, unsigned char *data, unsigned long len); 92void RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, unsigned long len);
87void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); 93void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
88unsigned char *RIPEMD160(unsigned char *d, unsigned long n, unsigned char *md); 94unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
89void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b); 95 unsigned char *md);
96void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);
90#ifdef __cplusplus 97#ifdef __cplusplus
91} 98}
92#endif 99#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c
index b590856229..bdfae270b6 100644
--- a/src/lib/libcrypto/ripemd/rmd_dgst.c
+++ b/src/lib/libcrypto/ripemd/rmd_dgst.c
@@ -60,7 +60,7 @@
60#include "rmd_locl.h" 60#include "rmd_locl.h"
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT; 63const char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
64 64
65# ifdef RMD160_ASM 65# ifdef RMD160_ASM
66 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num); 66 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num);
@@ -68,6 +68,7 @@ char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
68# else 68# else
69 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num); 69 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num);
70# endif 70# endif
71
71void RIPEMD160_Init(RIPEMD160_CTX *c) 72void RIPEMD160_Init(RIPEMD160_CTX *c)
72 { 73 {
73 c->A=RIPEMD160_A; 74 c->A=RIPEMD160_A;
@@ -80,180 +81,21 @@ void RIPEMD160_Init(RIPEMD160_CTX *c)
80 c->num=0; 81 c->num=0;
81 } 82 }
82 83
83void RIPEMD160_Update(RIPEMD160_CTX *c, register unsigned char *data, 84#ifndef ripemd160_block_host_order
84 unsigned long len) 85#ifdef X
85 { 86#undef X
86 register ULONG *p;
87 int sw,sc;
88 ULONG l;
89
90 if (len == 0) return;
91
92 l=(c->Nl+(len<<3))&0xffffffffL;
93 if (l < c->Nl) /* overflow */
94 c->Nh++;
95 c->Nh+=(len>>29);
96 c->Nl=l;
97
98 if (c->num != 0)
99 {
100 p=c->data;
101 sw=c->num>>2;
102 sc=c->num&0x03;
103
104 if ((c->num+len) >= RIPEMD160_CBLOCK)
105 {
106 l= p[sw];
107 p_c2l(data,l,sc);
108 p[sw++]=l;
109 for (; sw<RIPEMD160_LBLOCK; sw++)
110 {
111 c2l(data,l);
112 p[sw]=l;
113 }
114 len-=(RIPEMD160_CBLOCK-c->num);
115
116 ripemd160_block(c,p,64);
117 c->num=0;
118 /* drop through and do the rest */
119 }
120 else
121 {
122 int ew,ec;
123
124 c->num+=(int)len;
125 if ((sc+len) < 4) /* ugly, add char's to a word */
126 {
127 l= p[sw];
128 p_c2l_p(data,l,sc,len);
129 p[sw]=l;
130 }
131 else
132 {
133 ew=(c->num>>2);
134 ec=(c->num&0x03);
135 l= p[sw];
136 p_c2l(data,l,sc);
137 p[sw++]=l;
138 for (; sw < ew; sw++)
139 { c2l(data,l); p[sw]=l; }
140 if (ec)
141 {
142 c2l_p(data,l,ec);
143 p[sw]=l;
144 }
145 }
146 return;
147 }
148 }
149 /* we now can process the input data in blocks of RIPEMD160_CBLOCK
150 * chars and save the leftovers to c->data. */
151#ifdef L_ENDIAN
152 if ((((unsigned long)data)%sizeof(ULONG)) == 0)
153 {
154 sw=(int)len/RIPEMD160_CBLOCK;
155 if (sw > 0)
156 {
157 sw*=RIPEMD160_CBLOCK;
158 ripemd160_block(c,(ULONG *)data,sw);
159 data+=sw;
160 len-=sw;
161 }
162 }
163#endif
164 p=c->data;
165 while (len >= RIPEMD160_CBLOCK)
166 {
167#if defined(L_ENDIAN) || defined(B_ENDIAN)
168 if (p != (unsigned long *)data)
169 memcpy(p,data,RIPEMD160_CBLOCK);
170 data+=RIPEMD160_CBLOCK;
171#ifdef B_ENDIAN
172 for (sw=(RIPEMD160_LBLOCK/4); sw; sw--)
173 {
174 Endian_Reverse32(p[0]);
175 Endian_Reverse32(p[1]);
176 Endian_Reverse32(p[2]);
177 Endian_Reverse32(p[3]);
178 p+=4;
179 }
180#endif
181#else
182 for (sw=(RIPEMD160_LBLOCK/4); sw; sw--)
183 {
184 c2l(data,l); *(p++)=l;
185 c2l(data,l); *(p++)=l;
186 c2l(data,l); *(p++)=l;
187 c2l(data,l); *(p++)=l;
188 }
189#endif 87#endif
190 p=c->data; 88#define X(i) XX[i]
191 ripemd160_block(c,p,64); 89void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num)
192 len-=RIPEMD160_CBLOCK;
193 }
194 sc=(int)len;
195 c->num=sc;
196 if (sc)
197 {
198 sw=sc>>2; /* words to copy */
199#ifdef L_ENDIAN
200 p[sw]=0;
201 memcpy(p,data,sc);
202#else
203 sc&=0x03;
204 for ( ; sw; sw--)
205 { c2l(data,l); *(p++)=l; }
206 c2l_p(data,l,sc);
207 *p=l;
208#endif
209 }
210 }
211
212void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b)
213 { 90 {
214 ULONG p[16]; 91 const RIPEMD160_LONG *XX=p;
215#if !defined(L_ENDIAN) 92 register unsigned long A,B,C,D,E;
216 ULONG *q; 93 register unsigned long a,b,c,d,e;
217 int i;
218#endif
219 94
220#if defined(B_ENDIAN) || defined(L_ENDIAN) 95 for (;num--;XX+=HASH_LBLOCK)
221 memcpy(p,b,64);
222#ifdef B_ENDIAN
223 q=p;
224 for (i=(RIPEMD160_LBLOCK/4); i; i--)
225 {
226 Endian_Reverse32(q[0]);
227 Endian_Reverse32(q[1]);
228 Endian_Reverse32(q[2]);
229 Endian_Reverse32(q[3]);
230 q+=4;
231 }
232#endif
233#else
234 q=p;
235 for (i=(RIPEMD160_LBLOCK/4); i; i--)
236 { 96 {
237 ULONG l;
238 c2l(b,l); *(q++)=l;
239 c2l(b,l); *(q++)=l;
240 c2l(b,l); *(q++)=l;
241 c2l(b,l); *(q++)=l;
242 }
243#endif
244 ripemd160_block(c,p,64);
245 }
246
247#ifndef RMD160_ASM
248
249void ripemd160_block(RIPEMD160_CTX *ctx, register ULONG *X, int num)
250 {
251 register ULONG A,B,C,D,E;
252 ULONG a,b,c,d,e;
253 97
254 for (;;) 98 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
255 {
256 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
257 99
258 RIP1(A,B,C,D,E,WL00,SL00); 100 RIP1(A,B,C,D,E,WL00,SL00);
259 RIP1(E,A,B,C,D,WL01,SL01); 101 RIP1(E,A,B,C,D,WL01,SL01);
@@ -436,80 +278,216 @@ void ripemd160_block(RIPEMD160_CTX *ctx, register ULONG *X, int num)
436 ctx->E=ctx->A+b+C; 278 ctx->E=ctx->A+b+C;
437 ctx->A=D; 279 ctx->A=D;
438 280
439 X+=16;
440 num-=64;
441 if (num <= 0) break;
442 } 281 }
443 } 282 }
444#endif 283#endif
445 284
446void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c) 285#ifndef ripemd160_block_data_order
286#ifdef X
287#undef X
288#endif
289void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, int num)
447 { 290 {
448 register int i,j; 291 const unsigned char *data=p;
449 register ULONG l; 292 register unsigned long A,B,C,D,E;
450 register ULONG *p; 293 unsigned long a,b,c,d,e,l;
451 static unsigned char end[4]={0x80,0x00,0x00,0x00}; 294#ifndef MD32_XARRAY
452 unsigned char *cp=end; 295 /* See comment in crypto/sha/sha_locl.h for details. */
453 296 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
454 /* c->num should definitly have room for at least one more byte. */ 297 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
455 p=c->data; 298# define X(i) XX##i
456 j=c->num; 299#else
457 i=j>>2; 300 RIPEMD160_LONG XX[16];
458 301# define X(i) XX[i]
459 /* purify often complains about the following line as an
460 * Uninitialized Memory Read. While this can be true, the
461 * following p_c2l macro will reset l when that case is true.
462 * This is because j&0x03 contains the number of 'valid' bytes
463 * already in p[i]. If and only if j&0x03 == 0, the UMR will
464 * occur but this is also the only time p_c2l will do
465 * l= *(cp++) instead of l|= *(cp++)
466 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
467 * 'potential bug' */
468#ifdef PURIFY
469 if ((j&0x03) == 0) p[i]=0;
470#endif 302#endif
471 l=p[i]; 303
472 p_c2l(cp,l,j&0x03); 304 for (;num--;)
473 p[i]=l;
474 i++;
475 /* i is the next 'undefined word' */
476 if (c->num >= RIPEMD160_LAST_BLOCK)
477 { 305 {
478 for (; i<RIPEMD160_LBLOCK; i++)
479 p[i]=0;
480 ripemd160_block(c,p,64);
481 i=0;
482 }
483 for (; i<(RIPEMD160_LBLOCK-2); i++)
484 p[i]=0;
485 p[RIPEMD160_LBLOCK-2]=c->Nl;
486 p[RIPEMD160_LBLOCK-1]=c->Nh;
487 ripemd160_block(c,p,64);
488 cp=md;
489 l=c->A; l2c(l,cp);
490 l=c->B; l2c(l,cp);
491 l=c->C; l2c(l,cp);
492 l=c->D; l2c(l,cp);
493 l=c->E; l2c(l,cp);
494
495 /* clear stuff, ripemd160_block may be leaving some stuff on the stack
496 * but I'm not worried :-) */
497 c->num=0;
498/* memset((char *)&c,0,sizeof(c));*/
499 }
500 306
501#ifdef undef 307 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
502int printit(unsigned long *l) 308
503 { 309 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
504 int i,ii; 310 RIP1(A,B,C,D,E,WL00,SL00); HOST_c2l(data,l); X( 2)=l;
311 RIP1(E,A,B,C,D,WL01,SL01); HOST_c2l(data,l); X( 3)=l;
312 RIP1(D,E,A,B,C,WL02,SL02); HOST_c2l(data,l); X( 4)=l;
313 RIP1(C,D,E,A,B,WL03,SL03); HOST_c2l(data,l); X( 5)=l;
314 RIP1(B,C,D,E,A,WL04,SL04); HOST_c2l(data,l); X( 6)=l;
315 RIP1(A,B,C,D,E,WL05,SL05); HOST_c2l(data,l); X( 7)=l;
316 RIP1(E,A,B,C,D,WL06,SL06); HOST_c2l(data,l); X( 8)=l;
317 RIP1(D,E,A,B,C,WL07,SL07); HOST_c2l(data,l); X( 9)=l;
318 RIP1(C,D,E,A,B,WL08,SL08); HOST_c2l(data,l); X(10)=l;
319 RIP1(B,C,D,E,A,WL09,SL09); HOST_c2l(data,l); X(11)=l;
320 RIP1(A,B,C,D,E,WL10,SL10); HOST_c2l(data,l); X(12)=l;
321 RIP1(E,A,B,C,D,WL11,SL11); HOST_c2l(data,l); X(13)=l;
322 RIP1(D,E,A,B,C,WL12,SL12); HOST_c2l(data,l); X(14)=l;
323 RIP1(C,D,E,A,B,WL13,SL13); HOST_c2l(data,l); X(15)=l;
324 RIP1(B,C,D,E,A,WL14,SL14);
325 RIP1(A,B,C,D,E,WL15,SL15);
326
327 RIP2(E,A,B,C,D,WL16,SL16,KL1);
328 RIP2(D,E,A,B,C,WL17,SL17,KL1);
329 RIP2(C,D,E,A,B,WL18,SL18,KL1);
330 RIP2(B,C,D,E,A,WL19,SL19,KL1);
331 RIP2(A,B,C,D,E,WL20,SL20,KL1);
332 RIP2(E,A,B,C,D,WL21,SL21,KL1);
333 RIP2(D,E,A,B,C,WL22,SL22,KL1);
334 RIP2(C,D,E,A,B,WL23,SL23,KL1);
335 RIP2(B,C,D,E,A,WL24,SL24,KL1);
336 RIP2(A,B,C,D,E,WL25,SL25,KL1);
337 RIP2(E,A,B,C,D,WL26,SL26,KL1);
338 RIP2(D,E,A,B,C,WL27,SL27,KL1);
339 RIP2(C,D,E,A,B,WL28,SL28,KL1);
340 RIP2(B,C,D,E,A,WL29,SL29,KL1);
341 RIP2(A,B,C,D,E,WL30,SL30,KL1);
342 RIP2(E,A,B,C,D,WL31,SL31,KL1);
343
344 RIP3(D,E,A,B,C,WL32,SL32,KL2);
345 RIP3(C,D,E,A,B,WL33,SL33,KL2);
346 RIP3(B,C,D,E,A,WL34,SL34,KL2);
347 RIP3(A,B,C,D,E,WL35,SL35,KL2);
348 RIP3(E,A,B,C,D,WL36,SL36,KL2);
349 RIP3(D,E,A,B,C,WL37,SL37,KL2);
350 RIP3(C,D,E,A,B,WL38,SL38,KL2);
351 RIP3(B,C,D,E,A,WL39,SL39,KL2);
352 RIP3(A,B,C,D,E,WL40,SL40,KL2);
353 RIP3(E,A,B,C,D,WL41,SL41,KL2);
354 RIP3(D,E,A,B,C,WL42,SL42,KL2);
355 RIP3(C,D,E,A,B,WL43,SL43,KL2);
356 RIP3(B,C,D,E,A,WL44,SL44,KL2);
357 RIP3(A,B,C,D,E,WL45,SL45,KL2);
358 RIP3(E,A,B,C,D,WL46,SL46,KL2);
359 RIP3(D,E,A,B,C,WL47,SL47,KL2);
360
361 RIP4(C,D,E,A,B,WL48,SL48,KL3);
362 RIP4(B,C,D,E,A,WL49,SL49,KL3);
363 RIP4(A,B,C,D,E,WL50,SL50,KL3);
364 RIP4(E,A,B,C,D,WL51,SL51,KL3);
365 RIP4(D,E,A,B,C,WL52,SL52,KL3);
366 RIP4(C,D,E,A,B,WL53,SL53,KL3);
367 RIP4(B,C,D,E,A,WL54,SL54,KL3);
368 RIP4(A,B,C,D,E,WL55,SL55,KL3);
369 RIP4(E,A,B,C,D,WL56,SL56,KL3);
370 RIP4(D,E,A,B,C,WL57,SL57,KL3);
371 RIP4(C,D,E,A,B,WL58,SL58,KL3);
372 RIP4(B,C,D,E,A,WL59,SL59,KL3);
373 RIP4(A,B,C,D,E,WL60,SL60,KL3);
374 RIP4(E,A,B,C,D,WL61,SL61,KL3);
375 RIP4(D,E,A,B,C,WL62,SL62,KL3);
376 RIP4(C,D,E,A,B,WL63,SL63,KL3);
377
378 RIP5(B,C,D,E,A,WL64,SL64,KL4);
379 RIP5(A,B,C,D,E,WL65,SL65,KL4);
380 RIP5(E,A,B,C,D,WL66,SL66,KL4);
381 RIP5(D,E,A,B,C,WL67,SL67,KL4);
382 RIP5(C,D,E,A,B,WL68,SL68,KL4);
383 RIP5(B,C,D,E,A,WL69,SL69,KL4);
384 RIP5(A,B,C,D,E,WL70,SL70,KL4);
385 RIP5(E,A,B,C,D,WL71,SL71,KL4);
386 RIP5(D,E,A,B,C,WL72,SL72,KL4);
387 RIP5(C,D,E,A,B,WL73,SL73,KL4);
388 RIP5(B,C,D,E,A,WL74,SL74,KL4);
389 RIP5(A,B,C,D,E,WL75,SL75,KL4);
390 RIP5(E,A,B,C,D,WL76,SL76,KL4);
391 RIP5(D,E,A,B,C,WL77,SL77,KL4);
392 RIP5(C,D,E,A,B,WL78,SL78,KL4);
393 RIP5(B,C,D,E,A,WL79,SL79,KL4);
394
395 a=A; b=B; c=C; d=D; e=E;
396 /* Do other half */
397 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
398
399 RIP5(A,B,C,D,E,WR00,SR00,KR0);
400 RIP5(E,A,B,C,D,WR01,SR01,KR0);
401 RIP5(D,E,A,B,C,WR02,SR02,KR0);
402 RIP5(C,D,E,A,B,WR03,SR03,KR0);
403 RIP5(B,C,D,E,A,WR04,SR04,KR0);
404 RIP5(A,B,C,D,E,WR05,SR05,KR0);
405 RIP5(E,A,B,C,D,WR06,SR06,KR0);
406 RIP5(D,E,A,B,C,WR07,SR07,KR0);
407 RIP5(C,D,E,A,B,WR08,SR08,KR0);
408 RIP5(B,C,D,E,A,WR09,SR09,KR0);
409 RIP5(A,B,C,D,E,WR10,SR10,KR0);
410 RIP5(E,A,B,C,D,WR11,SR11,KR0);
411 RIP5(D,E,A,B,C,WR12,SR12,KR0);
412 RIP5(C,D,E,A,B,WR13,SR13,KR0);
413 RIP5(B,C,D,E,A,WR14,SR14,KR0);
414 RIP5(A,B,C,D,E,WR15,SR15,KR0);
415
416 RIP4(E,A,B,C,D,WR16,SR16,KR1);
417 RIP4(D,E,A,B,C,WR17,SR17,KR1);
418 RIP4(C,D,E,A,B,WR18,SR18,KR1);
419 RIP4(B,C,D,E,A,WR19,SR19,KR1);
420 RIP4(A,B,C,D,E,WR20,SR20,KR1);
421 RIP4(E,A,B,C,D,WR21,SR21,KR1);
422 RIP4(D,E,A,B,C,WR22,SR22,KR1);
423 RIP4(C,D,E,A,B,WR23,SR23,KR1);
424 RIP4(B,C,D,E,A,WR24,SR24,KR1);
425 RIP4(A,B,C,D,E,WR25,SR25,KR1);
426 RIP4(E,A,B,C,D,WR26,SR26,KR1);
427 RIP4(D,E,A,B,C,WR27,SR27,KR1);
428 RIP4(C,D,E,A,B,WR28,SR28,KR1);
429 RIP4(B,C,D,E,A,WR29,SR29,KR1);
430 RIP4(A,B,C,D,E,WR30,SR30,KR1);
431 RIP4(E,A,B,C,D,WR31,SR31,KR1);
432
433 RIP3(D,E,A,B,C,WR32,SR32,KR2);
434 RIP3(C,D,E,A,B,WR33,SR33,KR2);
435 RIP3(B,C,D,E,A,WR34,SR34,KR2);
436 RIP3(A,B,C,D,E,WR35,SR35,KR2);
437 RIP3(E,A,B,C,D,WR36,SR36,KR2);
438 RIP3(D,E,A,B,C,WR37,SR37,KR2);
439 RIP3(C,D,E,A,B,WR38,SR38,KR2);
440 RIP3(B,C,D,E,A,WR39,SR39,KR2);
441 RIP3(A,B,C,D,E,WR40,SR40,KR2);
442 RIP3(E,A,B,C,D,WR41,SR41,KR2);
443 RIP3(D,E,A,B,C,WR42,SR42,KR2);
444 RIP3(C,D,E,A,B,WR43,SR43,KR2);
445 RIP3(B,C,D,E,A,WR44,SR44,KR2);
446 RIP3(A,B,C,D,E,WR45,SR45,KR2);
447 RIP3(E,A,B,C,D,WR46,SR46,KR2);
448 RIP3(D,E,A,B,C,WR47,SR47,KR2);
449
450 RIP2(C,D,E,A,B,WR48,SR48,KR3);
451 RIP2(B,C,D,E,A,WR49,SR49,KR3);
452 RIP2(A,B,C,D,E,WR50,SR50,KR3);
453 RIP2(E,A,B,C,D,WR51,SR51,KR3);
454 RIP2(D,E,A,B,C,WR52,SR52,KR3);
455 RIP2(C,D,E,A,B,WR53,SR53,KR3);
456 RIP2(B,C,D,E,A,WR54,SR54,KR3);
457 RIP2(A,B,C,D,E,WR55,SR55,KR3);
458 RIP2(E,A,B,C,D,WR56,SR56,KR3);
459 RIP2(D,E,A,B,C,WR57,SR57,KR3);
460 RIP2(C,D,E,A,B,WR58,SR58,KR3);
461 RIP2(B,C,D,E,A,WR59,SR59,KR3);
462 RIP2(A,B,C,D,E,WR60,SR60,KR3);
463 RIP2(E,A,B,C,D,WR61,SR61,KR3);
464 RIP2(D,E,A,B,C,WR62,SR62,KR3);
465 RIP2(C,D,E,A,B,WR63,SR63,KR3);
466
467 RIP1(B,C,D,E,A,WR64,SR64);
468 RIP1(A,B,C,D,E,WR65,SR65);
469 RIP1(E,A,B,C,D,WR66,SR66);
470 RIP1(D,E,A,B,C,WR67,SR67);
471 RIP1(C,D,E,A,B,WR68,SR68);
472 RIP1(B,C,D,E,A,WR69,SR69);
473 RIP1(A,B,C,D,E,WR70,SR70);
474 RIP1(E,A,B,C,D,WR71,SR71);
475 RIP1(D,E,A,B,C,WR72,SR72);
476 RIP1(C,D,E,A,B,WR73,SR73);
477 RIP1(B,C,D,E,A,WR74,SR74);
478 RIP1(A,B,C,D,E,WR75,SR75);
479 RIP1(E,A,B,C,D,WR76,SR76);
480 RIP1(D,E,A,B,C,WR77,SR77);
481 RIP1(C,D,E,A,B,WR78,SR78);
482 RIP1(B,C,D,E,A,WR79,SR79);
483
484 D =ctx->B+c+D;
485 ctx->B=ctx->C+d+E;
486 ctx->C=ctx->D+e+A;
487 ctx->D=ctx->E+a+B;
488 ctx->E=ctx->A+b+C;
489 ctx->A=D;
505 490
506 for (i=0; i<2; i++)
507 {
508 for (ii=0; ii<8; ii++)
509 {
510 fprintf(stderr,"%08lx ",l[i*8+ii]);
511 }
512 fprintf(stderr,"\n");
513 } 491 }
514 } 492 }
515#endif 493#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h
index d6ba02001a..145cf316b9 100644
--- a/src/lib/libcrypto/ripemd/rmd_locl.h
+++ b/src/lib/libcrypto/ripemd/rmd_locl.h
@@ -58,134 +58,76 @@
58 58
59#include <stdlib.h> 59#include <stdlib.h>
60#include <string.h> 60#include <string.h>
61#include <openssl/opensslconf.h>
61#include <openssl/ripemd.h> 62#include <openssl/ripemd.h>
62 63
63#define ULONG unsigned long 64#ifndef RIPEMD160_LONG_LOG2
64#define UCHAR unsigned char 65#define RIPEMD160_LONG_LOG2 2 /* default to 32 bits */
65#define UINT unsigned int 66#endif
66 67
67#undef c2nl 68/*
68#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ 69 * DO EXAMINE COMMENTS IN crypto/md5/md5_locl.h & crypto/md5/md5_dgst.c
69 l|=(((unsigned long)(*((c)++)))<<16), \ 70 * FOR EXPLANATIONS ON FOLLOWING "CODE."
70 l|=(((unsigned long)(*((c)++)))<< 8), \ 71 * <appro@fy.chalmers.se>
71 l|=(((unsigned long)(*((c)++))) )) 72 */
72 73#ifdef RMD160_ASM
73#undef p_c2nl 74# if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
74#define p_c2nl(c,l,n) { \ 75# define ripemd160_block_host_order ripemd160_block_asm_host_order
75 switch (n) { \ 76# endif
76 case 0: l =((unsigned long)(*((c)++)))<<24; \ 77#endif
77 case 1: l|=((unsigned long)(*((c)++)))<<16; \ 78
78 case 2: l|=((unsigned long)(*((c)++)))<< 8; \ 79void ripemd160_block_host_order (RIPEMD160_CTX *c, const void *p,int num);
79 case 3: l|=((unsigned long)(*((c)++))); \ 80void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,int num);
80 } \ 81
81 } 82#if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
82 83#define ripemd160_block_data_order ripemd160_block_host_order
83#undef c2nl_p 84#endif
84/* NOTE the pointer is not incremented at the end of this */ 85
85#define c2nl_p(c,l,n) { \ 86#define DATA_ORDER_IS_LITTLE_ENDIAN
86 l=0; \ 87
87 (c)+=n; \ 88#define HASH_LONG RIPEMD160_LONG
88 switch (n) { \ 89#define HASH_LONG_LOG2 RIPEMD160_LONG_LOG2
89 case 3: l =((unsigned long)(*(--(c))))<< 8; \ 90#define HASH_CTX RIPEMD160_CTX
90 case 2: l|=((unsigned long)(*(--(c))))<<16; \ 91#define HASH_CBLOCK RIPEMD160_CBLOCK
91 case 1: l|=((unsigned long)(*(--(c))))<<24; \ 92#define HASH_LBLOCK RIPEMD160_LBLOCK
92 } \ 93#define HASH_UPDATE RIPEMD160_Update
93 } 94#define HASH_TRANSFORM RIPEMD160_Transform
94 95#define HASH_FINAL RIPEMD160_Final
95#undef p_c2nl_p 96#define HASH_BLOCK_HOST_ORDER ripemd160_block_host_order
96#define p_c2nl_p(c,l,sc,len) { \ 97#define HASH_MAKE_STRING(c,s) do { \
97 switch (sc) \ 98 unsigned long ll; \
98 { \ 99 ll=(c)->A; HOST_l2c(ll,(s)); \
99 case 0: l =((unsigned long)(*((c)++)))<<24; \ 100 ll=(c)->B; HOST_l2c(ll,(s)); \
100 if (--len == 0) break; \ 101 ll=(c)->C; HOST_l2c(ll,(s)); \
101 case 1: l|=((unsigned long)(*((c)++)))<<16; \ 102 ll=(c)->D; HOST_l2c(ll,(s)); \
102 if (--len == 0) break; \ 103 ll=(c)->E; HOST_l2c(ll,(s)); \
103 case 2: l|=((unsigned long)(*((c)++)))<< 8; \ 104 } while (0)
104 } \ 105#if !defined(L_ENDIAN) || defined(ripemd160_block_data_order)
105 } 106#define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order
106
107#undef nl2c
108#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
109 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
110 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
111 *((c)++)=(unsigned char)(((l) )&0xff))
112
113#undef c2l
114#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
115 l|=(((unsigned long)(*((c)++)))<< 8), \
116 l|=(((unsigned long)(*((c)++)))<<16), \
117 l|=(((unsigned long)(*((c)++)))<<24))
118
119#undef p_c2l
120#define p_c2l(c,l,n) { \
121 switch (n) { \
122 case 0: l =((unsigned long)(*((c)++))); \
123 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
124 case 2: l|=((unsigned long)(*((c)++)))<<16; \
125 case 3: l|=((unsigned long)(*((c)++)))<<24; \
126 } \
127 }
128
129#undef c2l_p
130/* NOTE the pointer is not incremented at the end of this */
131#define c2l_p(c,l,n) { \
132 l=0; \
133 (c)+=n; \
134 switch (n) { \
135 case 3: l =((unsigned long)(*(--(c))))<<16; \
136 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
137 case 1: l|=((unsigned long)(*(--(c)))); \
138 } \
139 }
140
141#undef p_c2l_p
142#define p_c2l_p(c,l,sc,len) { \
143 switch (sc) \
144 { \
145 case 0: l =((unsigned long)(*((c)++))); \
146 if (--len == 0) break; \
147 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
148 if (--len == 0) break; \
149 case 2: l|=((unsigned long)(*((c)++)))<<16; \
150 } \
151 }
152
153#undef l2c
154#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
155 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
156 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
157 *((c)++)=(unsigned char)(((l)>>24)&0xff))
158
159#undef ROTATE
160#if defined(WIN32)
161#define ROTATE(a,n) _lrotl(a,n)
162#else
163#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
164#endif 107#endif
165 108
166/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ 109#ifndef FLAT_INC
167#if defined(WIN32) 110#include "../md32_common.h"
168/* 5 instructions with rotate instruction, else 9 */
169#define Endian_Reverse32(a) \
170 { \
171 unsigned long l=(a); \
172 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
173 }
174#else 111#else
175/* 6 instructions with rotate instruction, else 8 */ 112#include "md32_common.h"
176#define Endian_Reverse32(a) \
177 { \
178 unsigned long l=(a); \
179 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
180 (a)=ROTATE(l,16L); \
181 }
182#endif 113#endif
183 114
115#if 0
184#define F1(x,y,z) ((x)^(y)^(z)) 116#define F1(x,y,z) ((x)^(y)^(z))
185#define F2(x,y,z) (((x)&(y))|((~x)&z)) 117#define F2(x,y,z) (((x)&(y))|((~x)&z))
186#define F3(x,y,z) (((x)|(~y))^(z)) 118#define F3(x,y,z) (((x)|(~y))^(z))
187#define F4(x,y,z) (((x)&(z))|((y)&(~(z)))) 119#define F4(x,y,z) (((x)&(z))|((y)&(~(z))))
188#define F5(x,y,z) ((x)^((y)|(~(z)))) 120#define F5(x,y,z) ((x)^((y)|(~(z))))
121#else
122/*
123 * Transformed F2 and F4 are courtesy of Wei Dai <weidai@eskimo.com>
124 */
125#define F1(x,y,z) ((x) ^ (y) ^ (z))
126#define F2(x,y,z) ((((y) ^ (z)) & (x)) ^ (z))
127#define F3(x,y,z) (((~(y)) | (x)) ^ (z))
128#define F4(x,y,z) ((((x) ^ (y)) & (z)) ^ (y))
129#define F5(x,y,z) (((~(z)) | (y)) ^ (x))
130#endif
189 131
190#define RIPEMD160_A 0x67452301L 132#define RIPEMD160_A 0x67452301L
191#define RIPEMD160_B 0xEFCDAB89L 133#define RIPEMD160_B 0xEFCDAB89L
@@ -196,27 +138,27 @@
196#include "rmdconst.h" 138#include "rmdconst.h"
197 139
198#define RIP1(a,b,c,d,e,w,s) { \ 140#define RIP1(a,b,c,d,e,w,s) { \
199 a+=F1(b,c,d)+X[w]; \ 141 a+=F1(b,c,d)+X(w); \
200 a=ROTATE(a,s)+e; \ 142 a=ROTATE(a,s)+e; \
201 c=ROTATE(c,10); } 143 c=ROTATE(c,10); }
202 144
203#define RIP2(a,b,c,d,e,w,s,K) { \ 145#define RIP2(a,b,c,d,e,w,s,K) { \
204 a+=F2(b,c,d)+X[w]+K; \ 146 a+=F2(b,c,d)+X(w)+K; \
205 a=ROTATE(a,s)+e; \ 147 a=ROTATE(a,s)+e; \
206 c=ROTATE(c,10); } 148 c=ROTATE(c,10); }
207 149
208#define RIP3(a,b,c,d,e,w,s,K) { \ 150#define RIP3(a,b,c,d,e,w,s,K) { \
209 a+=F3(b,c,d)+X[w]+K; \ 151 a+=F3(b,c,d)+X(w)+K; \
210 a=ROTATE(a,s)+e; \ 152 a=ROTATE(a,s)+e; \
211 c=ROTATE(c,10); } 153 c=ROTATE(c,10); }
212 154
213#define RIP4(a,b,c,d,e,w,s,K) { \ 155#define RIP4(a,b,c,d,e,w,s,K) { \
214 a+=F4(b,c,d)+X[w]+K; \ 156 a+=F4(b,c,d)+X(w)+K; \
215 a=ROTATE(a,s)+e; \ 157 a=ROTATE(a,s)+e; \
216 c=ROTATE(c,10); } 158 c=ROTATE(c,10); }
217 159
218#define RIP5(a,b,c,d,e,w,s,K) { \ 160#define RIP5(a,b,c,d,e,w,s,K) { \
219 a+=F5(b,c,d)+X[w]+K; \ 161 a+=F5(b,c,d)+X(w)+K; \
220 a=ROTATE(a,s)+e; \ 162 a=ROTATE(a,s)+e; \
221 c=ROTATE(c,10); } 163 c=ROTATE(c,10); }
222 164
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c
index 5b6ff14714..efdf2dd6ef 100644
--- a/src/lib/libcrypto/ripemd/rmd_one.c
+++ b/src/lib/libcrypto/ripemd/rmd_one.c
@@ -57,9 +57,10 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "rmd_locl.h" 60#include <string.h>
61#include <openssl/ripemd.h>
61 62
62unsigned char *RIPEMD160(unsigned char *d, unsigned long n, 63unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
63 unsigned char *md) 64 unsigned char *md)
64 { 65 {
65 RIPEMD160_CTX c; 66 RIPEMD160_CTX c;
diff --git a/src/lib/libcrypto/ripemd/rmdtest.c b/src/lib/libcrypto/ripemd/rmdtest.c
index 5e93d4627c..5d79c99725 100644
--- a/src/lib/libcrypto/ripemd/rmdtest.c
+++ b/src/lib/libcrypto/ripemd/rmdtest.c
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
73#include <openssl/ebcdic.h> 73#include <openssl/ebcdic.h>
74#endif 74#endif
75 75
76char *test[]={ 76static char *test[]={
77 "", 77 "",
78 "a", 78 "a",
79 "abc", 79 "abc",
@@ -85,7 +85,7 @@ char *test[]={
85 NULL, 85 NULL,
86 }; 86 };
87 87
88char *ret[]={ 88static char *ret[]={
89 "9c1185a5c5e9fc54612808977ee8f548b2258d31", 89 "9c1185a5c5e9fc54612808977ee8f548b2258d31",
90 "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", 90 "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
91 "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", 91 "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
diff --git a/src/lib/libcrypto/rsa/Makefile.ssl b/src/lib/libcrypto/rsa/Makefile.ssl
index 3bb89701a2..7b3960e70d 100644
--- a/src/lib/libcrypto/rsa/Makefile.ssl
+++ b/src/lib/libcrypto/rsa/Makefile.ssl
@@ -18,14 +18,14 @@ AR= ar r
18CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
19 19
20GENERAL=Makefile 20GENERAL=Makefile
21TEST=rsa_oaep_test.c 21TEST=rsa_test.c
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \ 25LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \
26 rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c 26 rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c rsa_null.c
27LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \ 27LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \
28 rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o 28 rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o rsa_null.o
29 29
30SRC= $(LIBSRC) 30SRC= $(LIBSRC)
31 31
@@ -83,52 +83,61 @@ clean:
83rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h 83rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
84rsa_chk.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 84rsa_chk.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
85rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h 85rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
86rsa_chk.o: ../../include/openssl/stack.h 86rsa_chk.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
87rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 87rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
88rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 88rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
89rsa_eay.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 89rsa_eay.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
90rsa_eay.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 90rsa_eay.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
91rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 91rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
92rsa_eay.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h 92rsa_eay.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
93rsa_eay.o: ../cryptlib.h 93rsa_eay.o: ../../include/openssl/stack.h ../cryptlib.h
94rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h 94rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
95rsa_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 95rsa_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
96rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h 96rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
97rsa_err.o: ../../include/openssl/stack.h 97rsa_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
98rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 98rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
99rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 99rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
100rsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 100rsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
101rsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 101rsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
102rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h 102rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
103rsa_gen.o: ../../include/openssl/stack.h ../cryptlib.h 103rsa_gen.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
104rsa_gen.o: ../cryptlib.h
104rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 105rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
105rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 106rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
106rsa_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 107rsa_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
107rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 108rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
108rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 109rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
109rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h 110rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
110rsa_lib.o: ../cryptlib.h 111rsa_lib.o: ../../include/openssl/stack.h ../cryptlib.h
111rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 112rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
112rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 113rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
113rsa_none.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 114rsa_none.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
114rsa_none.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 115rsa_none.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
115rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 116rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
116rsa_none.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h 117rsa_none.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
117rsa_none.o: ../cryptlib.h 118rsa_none.o: ../../include/openssl/stack.h ../cryptlib.h
119rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
120rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
121rsa_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
122rsa_null.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
123rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
124rsa_null.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
125rsa_null.o: ../../include/openssl/stack.h ../cryptlib.h
118rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 126rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
119rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 127rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
120rsa_oaep.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 128rsa_oaep.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
121rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 129rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
122rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 130rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
123rsa_oaep.o: ../../include/openssl/rsa.h ../../include/openssl/sha.h 131rsa_oaep.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
124rsa_oaep.o: ../../include/openssl/stack.h ../cryptlib.h 132rsa_oaep.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
133rsa_oaep.o: ../cryptlib.h
125rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 134rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
126rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 135rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
127rsa_pk1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 136rsa_pk1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
128rsa_pk1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 137rsa_pk1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
129rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 138rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
130rsa_pk1.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h 139rsa_pk1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
131rsa_pk1.o: ../cryptlib.h 140rsa_pk1.o: ../../include/openssl/stack.h ../cryptlib.h
132rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 141rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
133rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 142rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
134rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 143rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -168,5 +177,5 @@ rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
168rsa_ssl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 177rsa_ssl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
169rsa_ssl.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 178rsa_ssl.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
170rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 179rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
171rsa_ssl.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h 180rsa_ssl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
172rsa_ssl.o: ../cryptlib.h 181rsa_ssl.o: ../../include/openssl/stack.h ../cryptlib.h
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h
index 9230b2fcc9..f9f9b5cfe9 100644
--- a/src/lib/libcrypto/rsa/rsa.h
+++ b/src/lib/libcrypto/rsa/rsa.h
@@ -91,6 +91,18 @@ typedef struct rsa_meth_st
91 int (*finish)(RSA *rsa); /* called at free */ 91 int (*finish)(RSA *rsa); /* called at free */
92 int flags; /* RSA_METHOD_FLAG_* things */ 92 int flags; /* RSA_METHOD_FLAG_* things */
93 char *app_data; /* may be needed! */ 93 char *app_data; /* may be needed! */
94/* New sign and verify functions: some libraries don't allow arbitrary data
95 * to be signed/verified: this allows them to be used. Note: for this to work
96 * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used
97 * RSA_sign(), RSA_verify() should be used instead. Note: for backwards
98 * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER
99 * option is set in 'flags'.
100 */
101 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
102 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
103 int (*rsa_verify)(int dtype, unsigned char *m, unsigned int m_len,
104 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
105
94 } RSA_METHOD; 106 } RSA_METHOD;
95 107
96struct rsa_st 108struct rsa_st
@@ -140,12 +152,16 @@ struct rsa_st
140 */ 152 */
141#define RSA_FLAG_EXT_PKEY 0x20 153#define RSA_FLAG_EXT_PKEY 0x20
142 154
155/* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions.
156 */
157#define RSA_FLAG_SIGN_VER 0x40
158
143#define RSA_PKCS1_PADDING 1 159#define RSA_PKCS1_PADDING 1
144#define RSA_SSLV23_PADDING 2 160#define RSA_SSLV23_PADDING 2
145#define RSA_NO_PADDING 3 161#define RSA_NO_PADDING 3
146#define RSA_PKCS1_OAEP_PADDING 4 162#define RSA_PKCS1_OAEP_PADDING 4
147 163
148#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg) 164#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg)
149#define RSA_get_app_data(s) RSA_get_ex_data(s,0) 165#define RSA_get_app_data(s) RSA_get_ex_data(s,0)
150 166
151RSA * RSA_new(void); 167RSA * RSA_new(void);
@@ -181,6 +197,8 @@ RSA_METHOD *RSA_PKCS1_RSAref(void);
181/* these are the actual SSLeay RSA functions */ 197/* these are the actual SSLeay RSA functions */
182RSA_METHOD *RSA_PKCS1_SSLeay(void); 198RSA_METHOD *RSA_PKCS1_SSLeay(void);
183 199
200RSA_METHOD *RSA_null_method(void);
201
184void ERR_load_RSA_strings(void ); 202void ERR_load_RSA_strings(void );
185 203
186RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length); 204RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
@@ -241,10 +259,10 @@ int RSA_padding_add_none(unsigned char *to,int tlen,
241int RSA_padding_check_none(unsigned char *to,int tlen, 259int RSA_padding_check_none(unsigned char *to,int tlen,
242 unsigned char *f,int fl,int rsa_len); 260 unsigned char *f,int fl,int rsa_len);
243 261
244int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), 262int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
245 int (*dup_func)(), void (*free_func)()); 263 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
246int RSA_set_ex_data(RSA *r,int idx,char *arg); 264int RSA_set_ex_data(RSA *r,int idx,void *arg);
247char *RSA_get_ex_data(RSA *r, int idx); 265void *RSA_get_ex_data(RSA *r, int idx);
248 266
249/* BEGIN ERROR CODES */ 267/* BEGIN ERROR CODES */
250/* The following lines are auto generated by the script mkerr.pl. Any changes 268/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -262,6 +280,7 @@ char *RSA_get_ex_data(RSA *r, int idx);
262#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104 280#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104
263#define RSA_F_RSA_GENERATE_KEY 105 281#define RSA_F_RSA_GENERATE_KEY 105
264#define RSA_F_RSA_NEW_METHOD 106 282#define RSA_F_RSA_NEW_METHOD 106
283#define RSA_F_RSA_NULL 124
265#define RSA_F_RSA_PADDING_ADD_NONE 107 284#define RSA_F_RSA_PADDING_ADD_NONE 107
266#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 285#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
267#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 286#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
@@ -292,10 +311,11 @@ char *RSA_get_ex_data(RSA *r, int idx);
292#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 311#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
293#define RSA_R_DATA_TOO_SMALL 111 312#define RSA_R_DATA_TOO_SMALL 111
294#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 313#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
295#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
296#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 314#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
297#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 315#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
298#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 316#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
317#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
318#define RSA_R_INVALID_MESSAGE_LENGTH 131
299#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 319#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
300#define RSA_R_KEY_SIZE_TOO_SMALL 120 320#define RSA_R_KEY_SIZE_TOO_SMALL 120
301#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 321#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
@@ -304,6 +324,7 @@ char *RSA_get_ex_data(RSA *r, int idx);
304#define RSA_R_PADDING_CHECK_FAILED 114 324#define RSA_R_PADDING_CHECK_FAILED 114
305#define RSA_R_P_NOT_PRIME 128 325#define RSA_R_P_NOT_PRIME 128
306#define RSA_R_Q_NOT_PRIME 129 326#define RSA_R_Q_NOT_PRIME 129
327#define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130
307#define RSA_R_SSLV3_ROLLBACK_ATTACK 115 328#define RSA_R_SSLV3_ROLLBACK_ATTACK 115
308#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 329#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
309#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 330#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index 776324860c..179b7da90a 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -72,6 +72,8 @@
72#include <openssl/rsa.h> 72#include <openssl/rsa.h>
73#include <openssl/rand.h> 73#include <openssl/rand.h>
74 74
75#ifndef RSA_NULL
76
75static int RSA_eay_public_encrypt(int flen, unsigned char *from, 77static int RSA_eay_public_encrypt(int flen, unsigned char *from,
76 unsigned char *to, RSA *rsa,int padding); 78 unsigned char *to, RSA *rsa,int padding);
77static int RSA_eay_private_encrypt(int flen, unsigned char *from, 79static int RSA_eay_private_encrypt(int flen, unsigned char *from,
@@ -285,4 +287,4 @@ static int RSA_eay_finish(RSA *rsa)
285 return(1); 287 return(1);
286 } 288 }
287 289
288 290#endif
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c
index 9fb15e398d..5cfbea2b03 100644
--- a/src/lib/libcrypto/rsa/rsa_err.c
+++ b/src/lib/libcrypto/rsa/rsa_err.c
@@ -73,6 +73,7 @@ static ERR_STRING_DATA RSA_str_functs[]=
73{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"}, 73{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"},
74{ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"}, 74{ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"},
75{ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"}, 75{ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"},
76{ERR_PACK(0,RSA_F_RSA_NULL,0), "RSA_NULL"},
76{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"}, 77{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"},
77{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"}, 78{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"},
78{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"}, 79{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"},
@@ -106,10 +107,11 @@ static ERR_STRING_DATA RSA_str_reasons[]=
106{RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, 107{RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
107{RSA_R_DATA_TOO_SMALL ,"data too small"}, 108{RSA_R_DATA_TOO_SMALL ,"data too small"},
108{RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"}, 109{RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"},
109{RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"},
110{RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"}, 110{RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"},
111{RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"}, 111{RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"},
112{RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"}, 112{RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"},
113{RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"},
114{RSA_R_INVALID_MESSAGE_LENGTH ,"invalid message length"},
113{RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"}, 115{RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"},
114{RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"}, 116{RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"},
115{RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"}, 117{RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"},
@@ -118,6 +120,7 @@ static ERR_STRING_DATA RSA_str_reasons[]=
118{RSA_R_PADDING_CHECK_FAILED ,"padding check failed"}, 120{RSA_R_PADDING_CHECK_FAILED ,"padding check failed"},
119{RSA_R_P_NOT_PRIME ,"p not prime"}, 121{RSA_R_P_NOT_PRIME ,"p not prime"},
120{RSA_R_Q_NOT_PRIME ,"q not prime"}, 122{RSA_R_Q_NOT_PRIME ,"q not prime"},
123{RSA_R_RSA_OPERATIONS_NOT_SUPPORTED ,"rsa operations not supported"},
121{RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"}, 124{RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"},
122{RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, 125{RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
123{RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, 126{RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
index 3227dba794..b1ee5d8dce 100644
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ b/src/lib/libcrypto/rsa/rsa_gen.c
@@ -85,6 +85,7 @@ err:
85 RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN); 85 RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
86 ok=0; 86 ok=0;
87 } 87 }
88 BN_CTX_end(ctx);
88 BN_CTX_free(ctx); 89 BN_CTX_free(ctx);
89 BN_CTX_free(ctx2); 90 BN_CTX_free(ctx2);
90 91
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index c0ca2923a6..074a4f5074 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -67,7 +67,7 @@ const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT;
67 67
68static RSA_METHOD *default_RSA_meth=NULL; 68static RSA_METHOD *default_RSA_meth=NULL;
69static int rsa_meth_num=0; 69static int rsa_meth_num=0;
70static STACK *rsa_meth=NULL; 70static STACK_OF(CRYPTO_EX_DATA_FUNCS) *rsa_meth=NULL;
71 71
72RSA *RSA_new(void) 72RSA *RSA_new(void)
73 { 73 {
@@ -105,11 +105,15 @@ RSA *RSA_new_method(RSA_METHOD *meth)
105 105
106 if (default_RSA_meth == NULL) 106 if (default_RSA_meth == NULL)
107 { 107 {
108#ifdef RSA_NULL
109 default_RSA_meth=RSA_null_method();
110#else
108#ifdef RSAref 111#ifdef RSAref
109 default_RSA_meth=RSA_PKCS1_RSAref(); 112 default_RSA_meth=RSA_PKCS1_RSAref();
110#else 113#else
111 default_RSA_meth=RSA_PKCS1_SSLeay(); 114 default_RSA_meth=RSA_PKCS1_SSLeay();
112#endif 115#endif
116#endif
113 } 117 }
114 ret=(RSA *)Malloc(sizeof(RSA)); 118 ret=(RSA *)Malloc(sizeof(RSA));
115 if (ret == NULL) 119 if (ret == NULL)
@@ -146,7 +150,7 @@ RSA *RSA_new_method(RSA_METHOD *meth)
146 ret=NULL; 150 ret=NULL;
147 } 151 }
148 else 152 else
149 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data); 153 CRYPTO_new_ex_data(rsa_meth,ret,&ret->ex_data);
150 return(ret); 154 return(ret);
151 } 155 }
152 156
@@ -169,7 +173,7 @@ void RSA_free(RSA *r)
169 } 173 }
170#endif 174#endif
171 175
172 CRYPTO_free_ex_data(rsa_meth,(char *)r,&r->ex_data); 176 CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data);
173 177
174 if (r->meth->finish != NULL) 178 if (r->meth->finish != NULL)
175 r->meth->finish(r); 179 r->meth->finish(r);
@@ -187,20 +191,20 @@ void RSA_free(RSA *r)
187 Free(r); 191 Free(r);
188 } 192 }
189 193
190int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), 194int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
191 int (*dup_func)(), void (*free_func)()) 195 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
192 { 196 {
193 rsa_meth_num++; 197 rsa_meth_num++;
194 return(CRYPTO_get_ex_new_index(rsa_meth_num-1, 198 return(CRYPTO_get_ex_new_index(rsa_meth_num-1,
195 &rsa_meth,argl,argp,new_func,dup_func,free_func)); 199 &rsa_meth,argl,argp,new_func,dup_func,free_func));
196 } 200 }
197 201
198int RSA_set_ex_data(RSA *r, int idx, char *arg) 202int RSA_set_ex_data(RSA *r, int idx, void *arg)
199 { 203 {
200 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); 204 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
201 } 205 }
202 206
203char *RSA_get_ex_data(RSA *r, int idx) 207void *RSA_get_ex_data(RSA *r, int idx)
204 { 208 {
205 return(CRYPTO_get_ex_data(&r->ex_data,idx)); 209 return(CRYPTO_get_ex_data(&r->ex_data,idx));
206 } 210 }
@@ -265,19 +269,19 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
265 if (rsa->blinding != NULL) 269 if (rsa->blinding != NULL)
266 BN_BLINDING_free(rsa->blinding); 270 BN_BLINDING_free(rsa->blinding);
267 271
268 A= &(ctx->bn[0]); 272 BN_CTX_start(ctx);
269 ctx->tos++; 273 A = BN_CTX_get(ctx);
270 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err; 274 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
271 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; 275 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
272 276
273 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) 277 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
274 goto err; 278 goto err;
275 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); 279 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n);
276 ctx->tos--;
277 rsa->flags|=RSA_FLAG_BLINDING; 280 rsa->flags|=RSA_FLAG_BLINDING;
278 BN_free(Ai); 281 BN_free(Ai);
279 ret=1; 282 ret=1;
280err: 283err:
284 BN_CTX_end(ctx);
281 if (ctx != p_ctx) BN_CTX_free(ctx); 285 if (ctx != p_ctx) BN_CTX_free(ctx);
282 return(ret); 286 return(ret);
283 } 287 }
diff --git a/src/lib/libcrypto/rsa/rsa_null.c b/src/lib/libcrypto/rsa/rsa_null.c
new file mode 100644
index 0000000000..7b58a0eca3
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_null.c
@@ -0,0 +1,149 @@
1/* rsa_null.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65/* This is a dummy RSA implementation that just returns errors when called.
66 * It is designed to allow some RSA functions to work while stopping those
67 * covered by the RSA patent. That is RSA, encryption, decryption, signing
68 * and verify is not allowed but RSA key generation, key checking and other
69 * operations (like storing RSA keys) are permitted.
70 */
71
72static int RSA_null_public_encrypt(int flen, unsigned char *from,
73 unsigned char *to, RSA *rsa,int padding);
74static int RSA_null_private_encrypt(int flen, unsigned char *from,
75 unsigned char *to, RSA *rsa,int padding);
76static int RSA_null_public_decrypt(int flen, unsigned char *from,
77 unsigned char *to, RSA *rsa,int padding);
78static int RSA_null_private_decrypt(int flen, unsigned char *from,
79 unsigned char *to, RSA *rsa,int padding);
80#if 0 /* not currently used */
81static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa);
82#endif
83static int RSA_null_init(RSA *rsa);
84static int RSA_null_finish(RSA *rsa);
85static RSA_METHOD rsa_null_meth={
86 "Null RSA",
87 RSA_null_public_encrypt,
88 RSA_null_public_decrypt,
89 RSA_null_private_encrypt,
90 RSA_null_private_decrypt,
91 NULL, NULL,
92 RSA_null_init,
93 RSA_null_finish,
94 0,
95 NULL,
96 };
97
98RSA_METHOD *RSA_null_method(void)
99 {
100 return(&rsa_null_meth);
101 }
102
103static int RSA_null_public_encrypt(int flen, unsigned char *from,
104 unsigned char *to, RSA *rsa, int padding)
105 {
106 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
107 return -1;
108 }
109
110static int RSA_null_private_encrypt(int flen, unsigned char *from,
111 unsigned char *to, RSA *rsa, int padding)
112 {
113 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
114 return -1;
115 }
116
117static int RSA_null_private_decrypt(int flen, unsigned char *from,
118 unsigned char *to, RSA *rsa, int padding)
119 {
120 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
121 return -1;
122 }
123
124static int RSA_null_public_decrypt(int flen, unsigned char *from,
125 unsigned char *to, RSA *rsa, int padding)
126 {
127 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
128 return -1;
129 }
130
131#if 0 /* not currently used */
132static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
133 {
134 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
135 return -1;
136 }
137#endif
138
139static int RSA_null_init(RSA *rsa)
140 {
141 return(1);
142 }
143
144static int RSA_null_finish(RSA *rsa)
145 {
146 return(1);
147 }
148
149
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
index 843c40c864..1465c01f4f 100644
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ b/src/lib/libcrypto/rsa/rsa_oaep.c
@@ -50,7 +50,8 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
50 emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); 50 emlen - flen - 2 * SHA_DIGEST_LENGTH - 1);
51 db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; 51 db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01;
52 memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen); 52 memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen);
53 RAND_bytes(seed, SHA_DIGEST_LENGTH); 53 if (RAND_bytes(seed, SHA_DIGEST_LENGTH) <= 0)
54 return (0);
54#ifdef PKCS_TESTVECT 55#ifdef PKCS_TESTVECT
55 memcpy(seed, 56 memcpy(seed,
56 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f", 57 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f",
diff --git a/src/lib/libcrypto/rsa/rsa_oaep_test.c b/src/lib/libcrypto/rsa/rsa_oaep_test.c
index 0d4e39d3da..e69de29bb2 100644
--- a/src/lib/libcrypto/rsa/rsa_oaep_test.c
+++ b/src/lib/libcrypto/rsa/rsa_oaep_test.c
@@ -1,309 +0,0 @@
1/* test vectors from p1ovect1.txt */
2
3#include <stdio.h>
4#include <string.h>
5
6#include "openssl/e_os.h"
7
8#include <openssl/crypto.h>
9#include <openssl/err.h>
10#ifdef NO_RSA
11int main(int argc, char *argv[])
12{
13 printf("No RSA support\n");
14 return(0);
15}
16#else
17#include <openssl/rsa.h>
18
19#define SetKey \
20 key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
21 key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
22 key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
23 key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
24 key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
25 key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
26 key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
27 key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
28 memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
29 return (sizeof(ctext_ex) - 1);
30
31static int key1(RSA *key, unsigned char *c)
32 {
33 static unsigned char n[] =
34"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
35"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
36"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
37"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
38"\xF5";
39
40 static unsigned char e[] = "\x11";
41
42 static unsigned char d[] =
43"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
44"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
45"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
46"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
47
48 static unsigned char p[] =
49"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
50"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
51"\x0D";
52
53 static unsigned char q[] =
54"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
55"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
56"\x89";
57
58 static unsigned char dmp1[] =
59"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
60"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
61
62 static unsigned char dmq1[] =
63"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
64"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
65"\x51";
66
67 static unsigned char iqmp[] =
68"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
69"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
70
71 static unsigned char ctext_ex[] =
72"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
73"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
74"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
75"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
76
77 SetKey;
78 }
79
80static int key2(RSA *key, unsigned char *c)
81 {
82 static unsigned char n[] =
83"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
84"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
85"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
86"\x34\x77\xCF";
87
88 static unsigned char e[] = "\x3";
89
90 static unsigned char d[] =
91"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
92"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
93"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
94"\xE5\xEB";
95
96 static unsigned char p[] =
97"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
98"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
99
100 static unsigned char q[] =
101"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
102"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
103
104 static unsigned char dmp1[] =
105"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
106"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
107
108 static unsigned char dmq1[] =
109"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
110"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
111
112 static unsigned char iqmp[] =
113"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
114"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
115
116 static unsigned char ctext_ex[] =
117"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
118"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
119"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
120"\x62\x51";
121
122 SetKey;
123 }
124
125static int key3(RSA *key, unsigned char *c)
126 {
127 static unsigned char n[] =
128"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
129"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
130"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
131"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
132"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
133"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
134"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
135"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
136"\xCB";
137
138 static unsigned char e[] = "\x11";
139
140 static unsigned char d[] =
141"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
142"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
143"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
144"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
145"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
146"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
147"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
148"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
149"\xC1";
150
151 static unsigned char p[] =
152"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
153"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
154"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
155"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
156"\x99";
157
158 static unsigned char q[] =
159"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
160"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
161"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
162"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
163"\x03";
164
165 static unsigned char dmp1[] =
166"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
167"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
168"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
169"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
170
171 static unsigned char dmq1[] =
172"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
173"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
174"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
175"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
176
177 static unsigned char iqmp[] =
178"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
179"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
180"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
181"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
182"\xF7";
183
184 static unsigned char ctext_ex[] =
185"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
186"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
187"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
188"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
189"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
190"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
191"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
192"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
193
194 SetKey;
195 }
196
197static int pad_unknown(void)
198{
199 unsigned long l;
200 while ((l = ERR_get_error()) != 0)
201 if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
202 return(1);
203 return(0);
204}
205
206int main()
207 {
208 int err=0;
209 int v;
210 RSA *key;
211 unsigned char ptext[256];
212 unsigned char ctext[256];
213 static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
214 unsigned char ctext_ex[256];
215 int plen;
216 int clen = 0;
217 int num;
218
219 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
220
221 plen = sizeof(ptext_ex) - 1;
222
223 for (v = 0; v < 3; v++)
224 {
225 key = RSA_new();
226 switch (v) {
227 case 0:
228 clen = key1(key, ctext_ex);
229 break;
230 case 1:
231 clen = key2(key, ctext_ex);
232 break;
233 case 2:
234 clen = key3(key, ctext_ex);
235 break;
236 }
237
238 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
239 RSA_PKCS1_PADDING);
240 if (num != clen)
241 {
242 printf("PKCS#1 v1.5 encryption failed!\n");
243 err=1;
244 goto oaep;
245 }
246
247 num = RSA_private_decrypt(num, ctext, ptext, key,
248 RSA_PKCS1_PADDING);
249 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
250 {
251 printf("PKCS#1 v1.5 decryption failed!\n");
252 err=1;
253 }
254 else
255 printf("PKCS #1 v1.5 encryption/decryption ok\n");
256
257 oaep:
258 ERR_clear_error();
259 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
260 RSA_PKCS1_OAEP_PADDING);
261 if (num == -1 && pad_unknown())
262 {
263 printf("No OAEP support\n");
264 goto next;
265 }
266 if (num != clen)
267 {
268 printf("OAEP encryption failed!\n");
269 err=1;
270 goto next;
271 }
272
273 num = RSA_private_decrypt(num, ctext, ptext, key,
274 RSA_PKCS1_OAEP_PADDING);
275 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
276 {
277 printf("OAEP decryption (encrypted data) failed!\n");
278 err=1;
279 }
280 else if (memcmp(ctext, ctext_ex, num) == 0)
281 {
282 printf("OAEP test vector %d passed!\n", v);
283 goto next;
284 }
285
286 /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT).
287 Try decrypting ctext_ex */
288
289 num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
290 RSA_PKCS1_OAEP_PADDING);
291
292 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
293 {
294 printf("OAEP decryption (test vector data) failed!\n");
295 err=1;
296 }
297 else
298 printf("OAEP encryption/decryption ok\n");
299 next:
300 RSA_free(key);
301 }
302
303 ERR_remove_state(0);
304
305 CRYPTO_mem_leaks_fp(stdout);
306
307 return err;
308 }
309#endif
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c
index f0ae51f234..48a32bc264 100644
--- a/src/lib/libcrypto/rsa/rsa_pk1.c
+++ b/src/lib/libcrypto/rsa/rsa_pk1.c
@@ -79,7 +79,7 @@ int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
79 *(p++)=0; 79 *(p++)=0;
80 *(p++)=1; /* Private Key BT (Block Type) */ 80 *(p++)=1; /* Private Key BT (Block Type) */
81 81
82 /* padd out with 0xff data */ 82 /* pad out with 0xff data */
83 j=tlen-3-flen; 83 j=tlen-3-flen;
84 memset(p,0xff,j); 84 memset(p,0xff,j);
85 p+=j; 85 p+=j;
@@ -130,6 +130,11 @@ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
130 } 130 }
131 i++; /* Skip over the '\0' */ 131 i++; /* Skip over the '\0' */
132 j-=i; 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 }
133 memcpy(to,p,(unsigned int)j); 138 memcpy(to,p,(unsigned int)j);
134 139
135 return(j); 140 return(j);
@@ -155,12 +160,14 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
155 /* pad out with non-zero random data */ 160 /* pad out with non-zero random data */
156 j=tlen-3-flen; 161 j=tlen-3-flen;
157 162
158 RAND_bytes(p,j); 163 if (RAND_bytes(p,j) <= 0)
164 return(0);
159 for (i=0; i<j; i++) 165 for (i=0; i<j; i++)
160 { 166 {
161 if (*p == '\0') 167 if (*p == '\0')
162 do { 168 do {
163 RAND_bytes(p,1); 169 if (RAND_bytes(p,1) <= 0)
170 return(0);
164 } while (*p == '\0'); 171 } while (*p == '\0');
165 p++; 172 p++;
166 } 173 }
@@ -205,6 +212,11 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
205 } 212 }
206 i++; /* Skip over the '\0' */ 213 i++; /* Skip over the '\0' */
207 j-=i; 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 }
208 memcpy(to,p,(unsigned int)j); 220 memcpy(to,p,(unsigned int)j);
209 221
210 return(j); 222 return(j);
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
index 73b8b0c7ad..61efb0b00f 100644
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ b/src/lib/libcrypto/rsa/rsa_saos.c
@@ -136,7 +136,7 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype, unsigned char *m,
136 else 136 else
137 ret=1; 137 ret=1;
138err: 138err:
139 if (sig != NULL) ASN1_OCTET_STRING_free(sig); 139 if (sig != NULL) M_ASN1_OCTET_STRING_free(sig);
140 memset(s,0,(unsigned int)siglen); 140 memset(s,0,(unsigned int)siglen);
141 Free(s); 141 Free(s);
142 return(ret); 142 return(ret);
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index 1740494a4c..05bb7fb74a 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -63,59 +63,77 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66/* Size of an SSL signature: MD5+SHA1 */
67#define SSL_SIG_LENGTH 36
68
66int RSA_sign(int type, unsigned char *m, unsigned int m_len, 69int RSA_sign(int type, unsigned char *m, unsigned int m_len,
67 unsigned char *sigret, unsigned int *siglen, RSA *rsa) 70 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
68 { 71 {
69 X509_SIG sig; 72 X509_SIG sig;
70 ASN1_TYPE parameter; 73 ASN1_TYPE parameter;
71 int i,j,ret=1; 74 int i,j,ret=1;
72 unsigned char *p,*s; 75 unsigned char *p,*s = NULL;
73 X509_ALGOR algor; 76 X509_ALGOR algor;
74 ASN1_OCTET_STRING digest; 77 ASN1_OCTET_STRING digest;
75 78 if(rsa->flags & RSA_FLAG_SIGN_VER)
76 sig.algor= &algor; 79 return rsa->meth->rsa_sign(type, m, m_len, sigret, siglen, rsa);
77 sig.algor->algorithm=OBJ_nid2obj(type); 80 /* Special case: SSL signature, just check the length */
78 if (sig.algor->algorithm == NULL) 81 if(type == NID_md5_sha1) {
79 { 82 if(m_len != SSL_SIG_LENGTH) {
80 RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE); 83 RSAerr(RSA_F_RSA_SIGN,RSA_R_INVALID_MESSAGE_LENGTH);
81 return(0); 84 return(0);
82 }
83 if (sig.algor->algorithm->length == 0)
84 {
85 RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
86 return(0);
87 } 85 }
88 parameter.type=V_ASN1_NULL; 86 i = SSL_SIG_LENGTH;
89 parameter.value.ptr=NULL; 87 s = m;
90 sig.algor->parameter= &parameter; 88 } else {
89 sig.algor= &algor;
90 sig.algor->algorithm=OBJ_nid2obj(type);
91 if (sig.algor->algorithm == NULL)
92 {
93 RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE);
94 return(0);
95 }
96 if (sig.algor->algorithm->length == 0)
97 {
98 RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
99 return(0);
100 }
101 parameter.type=V_ASN1_NULL;
102 parameter.value.ptr=NULL;
103 sig.algor->parameter= &parameter;
91 104
92 sig.digest= &digest; 105 sig.digest= &digest;
93 sig.digest->data=m; 106 sig.digest->data=m;
94 sig.digest->length=m_len; 107 sig.digest->length=m_len;
95 108
96 i=i2d_X509_SIG(&sig,NULL); 109 i=i2d_X509_SIG(&sig,NULL);
110 }
97 j=RSA_size(rsa); 111 j=RSA_size(rsa);
98 if ((i-RSA_PKCS1_PADDING) > j) 112 if ((i-RSA_PKCS1_PADDING) > j)
99 { 113 {
100 RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); 114 RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
101 return(0); 115 return(0);
102 } 116 }
103 s=(unsigned char *)Malloc((unsigned int)j+1); 117 if(type != NID_md5_sha1) {
104 if (s == NULL) 118 s=(unsigned char *)Malloc((unsigned int)j+1);
105 { 119 if (s == NULL)
106 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE); 120 {
107 return(0); 121 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE);
108 } 122 return(0);
109 p=s; 123 }
110 i2d_X509_SIG(&sig,&p); 124 p=s;
125 i2d_X509_SIG(&sig,&p);
126 }
111 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); 127 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
112 if (i <= 0) 128 if (i <= 0)
113 ret=0; 129 ret=0;
114 else 130 else
115 *siglen=i; 131 *siglen=i;
116 132
117 memset(s,0,(unsigned int)j+1); 133 if(type != NID_md5_sha1) {
118 Free(s); 134 memset(s,0,(unsigned int)j+1);
135 Free(s);
136 }
119 return(ret); 137 return(ret);
120 } 138 }
121 139
@@ -132,53 +150,68 @@ int RSA_verify(int dtype, unsigned char *m, unsigned int m_len,
132 return(0); 150 return(0);
133 } 151 }
134 152
153 if(rsa->flags & RSA_FLAG_SIGN_VER)
154 return rsa->meth->rsa_verify(dtype, m, m_len, sigbuf, siglen, rsa);
155
135 s=(unsigned char *)Malloc((unsigned int)siglen); 156 s=(unsigned char *)Malloc((unsigned int)siglen);
136 if (s == NULL) 157 if (s == NULL)
137 { 158 {
138 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE); 159 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
139 goto err; 160 goto err;
140 } 161 }
162 if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {
163 RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
164 return(0);
165 }
141 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING); 166 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
142 167
143 if (i <= 0) goto err; 168 if (i <= 0) goto err;
144 169
145 p=s; 170 /* Special case: SSL signature */
146 sig=d2i_X509_SIG(NULL,&p,(long)i); 171 if(dtype == NID_md5_sha1) {
172 if((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))
173 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
174 else ret = 1;
175 } else {
176 p=s;
177 sig=d2i_X509_SIG(NULL,&p,(long)i);
147 178
148 if (sig == NULL) goto err; 179 if (sig == NULL) goto err;
149 sigtype=OBJ_obj2nid(sig->algor->algorithm); 180 sigtype=OBJ_obj2nid(sig->algor->algorithm);
150 181
151 182
152#ifdef RSA_DEBUG 183 #ifdef RSA_DEBUG
153 /* put a backward compatability flag in EAY */ 184 /* put a backward compatibility flag in EAY */
154 fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype), 185 fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype),
155 OBJ_nid2ln(dtype)); 186 OBJ_nid2ln(dtype));
156#endif 187 #endif
157 if (sigtype != dtype) 188 if (sigtype != dtype)
158 {
159 if (((dtype == NID_md5) &&
160 (sigtype == NID_md5WithRSAEncryption)) ||
161 ((dtype == NID_md2) &&
162 (sigtype == NID_md2WithRSAEncryption)))
163 { 189 {
164 /* ok, we will let it through */ 190 if (((dtype == NID_md5) &&
165#if !defined(NO_STDIO) && !defined(WIN16) 191 (sigtype == NID_md5WithRSAEncryption)) ||
166 fprintf(stderr,"signature has problems, re-make with post SSLeay045\n"); 192 ((dtype == NID_md2) &&
167#endif 193 (sigtype == NID_md2WithRSAEncryption)))
194 {
195 /* ok, we will let it through */
196 #if !defined(NO_STDIO) && !defined(WIN16)
197 fprintf(stderr,"signature has problems, re-make with post SSLeay045\n");
198 #endif
199 }
200 else
201 {
202 RSAerr(RSA_F_RSA_VERIFY,
203 RSA_R_ALGORITHM_MISMATCH);
204 goto err;
205 }
168 } 206 }
169 else 207 if ( ((unsigned int)sig->digest->length != m_len) ||
208 (memcmp(m,sig->digest->data,m_len) != 0))
170 { 209 {
171 RSAerr(RSA_F_RSA_VERIFY,RSA_R_ALGORITHM_MISMATCH); 210 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
172 goto err;
173 } 211 }
174 } 212 else
175 if ( ((unsigned int)sig->digest->length != m_len) || 213 ret=1;
176 (memcmp(m,sig->digest->data,m_len) != 0)) 214 }
177 {
178 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
179 }
180 else
181 ret=1;
182err: 215err:
183 if (sig != NULL) X509_SIG_free(sig); 216 if (sig != NULL) X509_SIG_free(sig);
184 memset(s,0,(unsigned int)siglen); 217 memset(s,0,(unsigned int)siglen);
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c
index 1050844f8d..81a857c813 100644
--- a/src/lib/libcrypto/rsa/rsa_ssl.c
+++ b/src/lib/libcrypto/rsa/rsa_ssl.c
@@ -82,12 +82,14 @@ int RSA_padding_add_SSLv23(unsigned char *to, int tlen, unsigned char *from,
82 /* pad out with non-zero random data */ 82 /* pad out with non-zero random data */
83 j=tlen-3-8-flen; 83 j=tlen-3-8-flen;
84 84
85 RAND_bytes(p,j); 85 if (RAND_bytes(p,j) <= 0)
86 return(0);
86 for (i=0; i<j; i++) 87 for (i=0; i<j; i++)
87 { 88 {
88 if (*p == '\0') 89 if (*p == '\0')
89 do { 90 do {
90 RAND_bytes(p,1); 91 if (RAND_bytes(p,1) <= 0)
92 return(0);
91 } while (*p == '\0'); 93 } while (*p == '\0');
92 p++; 94 p++;
93 } 95 }
@@ -140,6 +142,11 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen, unsigned char *from,
140 142
141 i++; /* Skip over the '\0' */ 143 i++; /* Skip over the '\0' */
142 j-=i; 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 }
143 memcpy(to,p,(unsigned int)j); 150 memcpy(to,p,(unsigned int)j);
144 151
145 return(j); 152 return(j);
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c
new file mode 100644
index 0000000000..e5ae0c1f69
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_test.c
@@ -0,0 +1,314 @@
1/* test vectors from p1ovect1.txt */
2
3#include <stdio.h>
4#include <string.h>
5
6#include "openssl/e_os.h"
7
8#include <openssl/crypto.h>
9#include <openssl/err.h>
10#include <openssl/rand.h>
11#ifdef NO_RSA
12int main(int argc, char *argv[])
13{
14 printf("No RSA support\n");
15 return(0);
16}
17#else
18#include <openssl/rsa.h>
19
20#define SetKey \
21 key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
22 key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
23 key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
24 key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
25 key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
26 key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
27 key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
28 key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
29 memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
30 return (sizeof(ctext_ex) - 1);
31
32static int key1(RSA *key, unsigned char *c)
33 {
34 static unsigned char n[] =
35"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
36"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
37"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
38"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
39"\xF5";
40
41 static unsigned char e[] = "\x11";
42
43 static unsigned char d[] =
44"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
45"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
46"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
47"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
48
49 static unsigned char p[] =
50"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
51"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
52"\x0D";
53
54 static unsigned char q[] =
55"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
56"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
57"\x89";
58
59 static unsigned char dmp1[] =
60"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
61"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
62
63 static unsigned char dmq1[] =
64"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
65"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
66"\x51";
67
68 static unsigned char iqmp[] =
69"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
70"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
71
72 static unsigned char ctext_ex[] =
73"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
74"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
75"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
76"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
77
78 SetKey;
79 }
80
81static int key2(RSA *key, unsigned char *c)
82 {
83 static unsigned char n[] =
84"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
85"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
86"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
87"\x34\x77\xCF";
88
89 static unsigned char e[] = "\x3";
90
91 static unsigned char d[] =
92"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
93"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
94"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
95"\xE5\xEB";
96
97 static unsigned char p[] =
98"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
99"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
100
101 static unsigned char q[] =
102"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
103"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
104
105 static unsigned char dmp1[] =
106"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
107"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
108
109 static unsigned char dmq1[] =
110"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
111"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
112
113 static unsigned char iqmp[] =
114"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
115"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
116
117 static unsigned char ctext_ex[] =
118"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
119"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
120"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
121"\x62\x51";
122
123 SetKey;
124 }
125
126static int key3(RSA *key, unsigned char *c)
127 {
128 static unsigned char n[] =
129"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
130"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
131"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
132"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
133"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
134"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
135"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
136"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
137"\xCB";
138
139 static unsigned char e[] = "\x11";
140
141 static unsigned char d[] =
142"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
143"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
144"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
145"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
146"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
147"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
148"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
149"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
150"\xC1";
151
152 static unsigned char p[] =
153"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
154"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
155"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
156"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
157"\x99";
158
159 static unsigned char q[] =
160"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
161"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
162"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
163"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
164"\x03";
165
166 static unsigned char dmp1[] =
167"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
168"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
169"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
170"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
171
172 static unsigned char dmq1[] =
173"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
174"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
175"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
176"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
177
178 static unsigned char iqmp[] =
179"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
180"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
181"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
182"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
183"\xF7";
184
185 static unsigned char ctext_ex[] =
186"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
187"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
188"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
189"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
190"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
191"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
192"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
193"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
194
195 SetKey;
196 }
197
198static int pad_unknown(void)
199{
200 unsigned long l;
201 while ((l = ERR_get_error()) != 0)
202 if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
203 return(1);
204 return(0);
205}
206
207static const char rnd_seed[] = "string to make the random number generator think it has entropy";
208
209int main(int argc, char *argv[])
210 {
211 int err=0;
212 int v;
213 RSA *key;
214 unsigned char ptext[256];
215 unsigned char ctext[256];
216 static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
217 unsigned char ctext_ex[256];
218 int plen;
219 int clen = 0;
220 int num;
221
222 RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
223
224 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
225
226 plen = sizeof(ptext_ex) - 1;
227
228 for (v = 0; v < 3; v++)
229 {
230 key = RSA_new();
231 switch (v) {
232 case 0:
233 clen = key1(key, ctext_ex);
234 break;
235 case 1:
236 clen = key2(key, ctext_ex);
237 break;
238 case 2:
239 clen = key3(key, ctext_ex);
240 break;
241 }
242
243 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
244 RSA_PKCS1_PADDING);
245 if (num != clen)
246 {
247 printf("PKCS#1 v1.5 encryption failed!\n");
248 err=1;
249 goto oaep;
250 }
251
252 num = RSA_private_decrypt(num, ctext, ptext, key,
253 RSA_PKCS1_PADDING);
254 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
255 {
256 printf("PKCS#1 v1.5 decryption failed!\n");
257 err=1;
258 }
259 else
260 printf("PKCS #1 v1.5 encryption/decryption ok\n");
261
262 oaep:
263 ERR_clear_error();
264 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
265 RSA_PKCS1_OAEP_PADDING);
266 if (num == -1 && pad_unknown())
267 {
268 printf("No OAEP support\n");
269 goto next;
270 }
271 if (num != clen)
272 {
273 printf("OAEP encryption failed!\n");
274 err=1;
275 goto next;
276 }
277
278 num = RSA_private_decrypt(num, ctext, ptext, key,
279 RSA_PKCS1_OAEP_PADDING);
280 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
281 {
282 printf("OAEP decryption (encrypted data) failed!\n");
283 err=1;
284 }
285 else if (memcmp(ctext, ctext_ex, num) == 0)
286 {
287 printf("OAEP test vector %d passed!\n", v);
288 goto next;
289 }
290
291 /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT).
292 Try decrypting ctext_ex */
293
294 num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
295 RSA_PKCS1_OAEP_PADDING);
296
297 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
298 {
299 printf("OAEP decryption (test vector data) failed!\n");
300 err=1;
301 }
302 else
303 printf("OAEP encryption/decryption ok\n");
304 next:
305 RSA_free(key);
306 }
307
308 ERR_remove_state(0);
309
310 CRYPTO_mem_leaks_fp(stdout);
311
312 return err;
313 }
314#endif
diff --git a/src/lib/libcrypto/sha/Makefile.ssl b/src/lib/libcrypto/sha/Makefile.ssl
index 6ea5b1d719..79ef43aa34 100644
--- a/src/lib/libcrypto/sha/Makefile.ssl
+++ b/src/lib/libcrypto/sha/Makefile.ssl
@@ -104,8 +104,8 @@ clean:
104sha1_one.o: ../../include/openssl/sha.h 104sha1_one.o: ../../include/openssl/sha.h
105sha1dgst.o: ../../include/openssl/opensslconf.h 105sha1dgst.o: ../../include/openssl/opensslconf.h
106sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h 106sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
107sha1dgst.o: sha_locl.h 107sha1dgst.o: ../md32_common.h sha_locl.h
108sha_dgst.o: ../../include/openssl/opensslconf.h 108sha_dgst.o: ../../include/openssl/opensslconf.h
109sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h 109sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
110sha_dgst.o: sha_locl.h 110sha_dgst.o: ../md32_common.h sha_locl.h
111sha_one.o: ../../include/openssl/sha.h 111sha_one.o: ../../include/openssl/sha.h
diff --git a/src/lib/libcrypto/sha/asm/s1-win32.asm b/src/lib/libcrypto/sha/asm/s1-win32.asm
index 61335666b9..699afdb022 100644
--- a/src/lib/libcrypto/sha/asm/s1-win32.asm
+++ b/src/lib/libcrypto/sha/asm/s1-win32.asm
@@ -8,302 +8,303 @@
8 .486 8 .486
9.model FLAT 9.model FLAT
10_TEXT SEGMENT 10_TEXT SEGMENT
11PUBLIC _sha1_block_x86 11PUBLIC _sha1_block_asm_data_order
12 12
13_sha1_block_x86 PROC NEAR 13_sha1_block_asm_data_order PROC NEAR
14 mov ecx, DWORD PTR 12[esp]
14 push esi 15 push esi
16 shl ecx, 6
17 mov esi, DWORD PTR 12[esp]
15 push ebp 18 push ebp
16 mov eax, DWORD PTR 20[esp] 19 add ecx, esi
17 mov esi, DWORD PTR 16[esp]
18 add eax, esi
19 mov ebp, DWORD PTR 12[esp]
20 push ebx 20 push ebx
21 sub eax, 64 21 mov ebp, DWORD PTR 16[esp]
22 push edi 22 push edi
23 mov ebx, DWORD PTR 4[ebp]
24 sub esp, 72
25 mov edx, DWORD PTR 12[ebp] 23 mov edx, DWORD PTR 12[ebp]
24 sub esp, 108
26 mov edi, DWORD PTR 16[ebp] 25 mov edi, DWORD PTR 16[ebp]
27 mov ecx, DWORD PTR 8[ebp] 26 mov ebx, DWORD PTR 8[ebp]
28 mov DWORD PTR 68[esp],eax 27 mov DWORD PTR 68[esp],ecx
29 ; First we need to setup the X array 28 ; First we need to setup the X array
30 mov eax, DWORD PTR [esi]
31L000start: 29L000start:
32 ; First, load the words onto the stack in network byte order 30 ; First, load the words onto the stack in network byte order
31 mov eax, DWORD PTR [esi]
32 mov ecx, DWORD PTR 4[esi]
33 bswap eax 33 bswap eax
34 bswap ecx
34 mov DWORD PTR [esp],eax 35 mov DWORD PTR [esp],eax
35 mov eax, DWORD PTR 4[esi] 36 mov DWORD PTR 4[esp],ecx
36 bswap eax
37 mov DWORD PTR 4[esp],eax
38 mov eax, DWORD PTR 8[esi] 37 mov eax, DWORD PTR 8[esi]
38 mov ecx, DWORD PTR 12[esi]
39 bswap eax 39 bswap eax
40 bswap ecx
40 mov DWORD PTR 8[esp],eax 41 mov DWORD PTR 8[esp],eax
41 mov eax, DWORD PTR 12[esi] 42 mov DWORD PTR 12[esp],ecx
42 bswap eax
43 mov DWORD PTR 12[esp],eax
44 mov eax, DWORD PTR 16[esi] 43 mov eax, DWORD PTR 16[esi]
44 mov ecx, DWORD PTR 20[esi]
45 bswap eax 45 bswap eax
46 bswap ecx
46 mov DWORD PTR 16[esp],eax 47 mov DWORD PTR 16[esp],eax
47 mov eax, DWORD PTR 20[esi] 48 mov DWORD PTR 20[esp],ecx
48 bswap eax
49 mov DWORD PTR 20[esp],eax
50 mov eax, DWORD PTR 24[esi] 49 mov eax, DWORD PTR 24[esi]
50 mov ecx, DWORD PTR 28[esi]
51 bswap eax 51 bswap eax
52 bswap ecx
52 mov DWORD PTR 24[esp],eax 53 mov DWORD PTR 24[esp],eax
53 mov eax, DWORD PTR 28[esi] 54 mov DWORD PTR 28[esp],ecx
54 bswap eax
55 mov DWORD PTR 28[esp],eax
56 mov eax, DWORD PTR 32[esi] 55 mov eax, DWORD PTR 32[esi]
56 mov ecx, DWORD PTR 36[esi]
57 bswap eax 57 bswap eax
58 bswap ecx
58 mov DWORD PTR 32[esp],eax 59 mov DWORD PTR 32[esp],eax
59 mov eax, DWORD PTR 36[esi] 60 mov DWORD PTR 36[esp],ecx
60 bswap eax
61 mov DWORD PTR 36[esp],eax
62 mov eax, DWORD PTR 40[esi] 61 mov eax, DWORD PTR 40[esi]
62 mov ecx, DWORD PTR 44[esi]
63 bswap eax 63 bswap eax
64 bswap ecx
64 mov DWORD PTR 40[esp],eax 65 mov DWORD PTR 40[esp],eax
65 mov eax, DWORD PTR 44[esi] 66 mov DWORD PTR 44[esp],ecx
66 bswap eax
67 mov DWORD PTR 44[esp],eax
68 mov eax, DWORD PTR 48[esi] 67 mov eax, DWORD PTR 48[esi]
68 mov ecx, DWORD PTR 52[esi]
69 bswap eax 69 bswap eax
70 bswap ecx
70 mov DWORD PTR 48[esp],eax 71 mov DWORD PTR 48[esp],eax
71 mov eax, DWORD PTR 52[esi] 72 mov DWORD PTR 52[esp],ecx
72 bswap eax
73 mov DWORD PTR 52[esp],eax
74 mov eax, DWORD PTR 56[esi] 73 mov eax, DWORD PTR 56[esi]
74 mov ecx, DWORD PTR 60[esi]
75 bswap eax 75 bswap eax
76 bswap ecx
76 mov DWORD PTR 56[esp],eax 77 mov DWORD PTR 56[esp],eax
77 mov eax, DWORD PTR 60[esi] 78 mov DWORD PTR 60[esp],ecx
78 bswap eax
79 mov DWORD PTR 60[esp],eax
80 ; We now have the X array on the stack 79 ; We now have the X array on the stack
81 ; starting at sp-4 80 ; starting at sp-4
82 mov DWORD PTR 64[esp],esi 81 mov DWORD PTR 132[esp],esi
82L001shortcut:
83 ; 83 ;
84 ; Start processing 84 ; Start processing
85 mov eax, DWORD PTR [ebp] 85 mov eax, DWORD PTR [ebp]
86 mov ecx, DWORD PTR 4[ebp]
86 ; 00_15 0 87 ; 00_15 0
87 mov esi, ecx 88 mov esi, ebx
88 mov ebp, eax 89 mov ebp, eax
89 xor esi, edx 90 xor esi, edx
90 rol ebp, 5 91 rol ebp, 5
91 and esi, ebx 92 and esi, ecx
92 add ebp, edi 93 add ebp, edi
93 ror ebx, 1 94 ror ecx, 1
94 mov edi, DWORD PTR [esp] 95 mov edi, DWORD PTR [esp]
95 ror ebx, 1 96 ror ecx, 1
96 xor esi, edx 97 xor esi, edx
97 lea ebp, DWORD PTR 1518500249[edi*1+ebp] 98 lea ebp, DWORD PTR 1518500249[edi*1+ebp]
98 mov edi, ebx 99 mov edi, ecx
99 add esi, ebp 100 add esi, ebp
100 xor edi, ecx 101 xor edi, ebx
101 mov ebp, esi 102 mov ebp, esi
102 and edi, eax 103 and edi, eax
103 rol ebp, 5 104 rol ebp, 5
104 add ebp, edx 105 add ebp, edx
105 mov edx, DWORD PTR 4[esp] 106 mov edx, DWORD PTR 4[esp]
106 ror eax, 1 107 ror eax, 1
107 xor edi, ecx 108 xor edi, ebx
108 ror eax, 1 109 ror eax, 1
109 lea ebp, DWORD PTR 1518500249[edx*1+ebp] 110 lea ebp, DWORD PTR 1518500249[edx*1+ebp]
110 add edi, ebp 111 add edi, ebp
111 ; 00_15 2 112 ; 00_15 2
112 mov edx, eax 113 mov edx, eax
113 mov ebp, edi 114 mov ebp, edi
114 xor edx, ebx 115 xor edx, ecx
115 rol ebp, 5 116 rol ebp, 5
116 and edx, esi 117 and edx, esi
117 add ebp, ecx 118 add ebp, ebx
118 ror esi, 1 119 ror esi, 1
119 mov ecx, DWORD PTR 8[esp] 120 mov ebx, DWORD PTR 8[esp]
120 ror esi, 1 121 ror esi, 1
121 xor edx, ebx 122 xor edx, ecx
122 lea ebp, DWORD PTR 1518500249[ecx*1+ebp] 123 lea ebp, DWORD PTR 1518500249[ebx*1+ebp]
123 mov ecx, esi 124 mov ebx, esi
124 add edx, ebp 125 add edx, ebp
125 xor ecx, eax 126 xor ebx, eax
126 mov ebp, edx 127 mov ebp, edx
127 and ecx, edi 128 and ebx, edi
128 rol ebp, 5 129 rol ebp, 5
129 add ebp, ebx 130 add ebp, ecx
130 mov ebx, DWORD PTR 12[esp] 131 mov ecx, DWORD PTR 12[esp]
131 ror edi, 1 132 ror edi, 1
132 xor ecx, eax 133 xor ebx, eax
133 ror edi, 1 134 ror edi, 1
134 lea ebp, DWORD PTR 1518500249[ebx*1+ebp] 135 lea ebp, DWORD PTR 1518500249[ecx*1+ebp]
135 add ecx, ebp 136 add ebx, ebp
136 ; 00_15 4 137 ; 00_15 4
137 mov ebx, edi 138 mov ecx, edi
138 mov ebp, ecx 139 mov ebp, ebx
139 xor ebx, esi 140 xor ecx, esi
140 rol ebp, 5 141 rol ebp, 5
141 and ebx, edx 142 and ecx, edx
142 add ebp, eax 143 add ebp, eax
143 ror edx, 1 144 ror edx, 1
144 mov eax, DWORD PTR 16[esp] 145 mov eax, DWORD PTR 16[esp]
145 ror edx, 1 146 ror edx, 1
146 xor ebx, esi 147 xor ecx, esi
147 lea ebp, DWORD PTR 1518500249[eax*1+ebp] 148 lea ebp, DWORD PTR 1518500249[eax*1+ebp]
148 mov eax, edx 149 mov eax, edx
149 add ebx, ebp 150 add ecx, ebp
150 xor eax, edi 151 xor eax, edi
151 mov ebp, ebx 152 mov ebp, ecx
152 and eax, ecx 153 and eax, ebx
153 rol ebp, 5 154 rol ebp, 5
154 add ebp, esi 155 add ebp, esi
155 mov esi, DWORD PTR 20[esp] 156 mov esi, DWORD PTR 20[esp]
156 ror ecx, 1 157 ror ebx, 1
157 xor eax, edi 158 xor eax, edi
158 ror ecx, 1 159 ror ebx, 1
159 lea ebp, DWORD PTR 1518500249[esi*1+ebp] 160 lea ebp, DWORD PTR 1518500249[esi*1+ebp]
160 add eax, ebp 161 add eax, ebp
161 ; 00_15 6 162 ; 00_15 6
162 mov esi, ecx 163 mov esi, ebx
163 mov ebp, eax 164 mov ebp, eax
164 xor esi, edx 165 xor esi, edx
165 rol ebp, 5 166 rol ebp, 5
166 and esi, ebx 167 and esi, ecx
167 add ebp, edi 168 add ebp, edi
168 ror ebx, 1 169 ror ecx, 1
169 mov edi, DWORD PTR 24[esp] 170 mov edi, DWORD PTR 24[esp]
170 ror ebx, 1 171 ror ecx, 1
171 xor esi, edx 172 xor esi, edx
172 lea ebp, DWORD PTR 1518500249[edi*1+ebp] 173 lea ebp, DWORD PTR 1518500249[edi*1+ebp]
173 mov edi, ebx 174 mov edi, ecx
174 add esi, ebp 175 add esi, ebp
175 xor edi, ecx 176 xor edi, ebx
176 mov ebp, esi 177 mov ebp, esi
177 and edi, eax 178 and edi, eax
178 rol ebp, 5 179 rol ebp, 5
179 add ebp, edx 180 add ebp, edx
180 mov edx, DWORD PTR 28[esp] 181 mov edx, DWORD PTR 28[esp]
181 ror eax, 1 182 ror eax, 1
182 xor edi, ecx 183 xor edi, ebx
183 ror eax, 1 184 ror eax, 1
184 lea ebp, DWORD PTR 1518500249[edx*1+ebp] 185 lea ebp, DWORD PTR 1518500249[edx*1+ebp]
185 add edi, ebp 186 add edi, ebp
186 ; 00_15 8 187 ; 00_15 8
187 mov edx, eax 188 mov edx, eax
188 mov ebp, edi 189 mov ebp, edi
189 xor edx, ebx 190 xor edx, ecx
190 rol ebp, 5 191 rol ebp, 5
191 and edx, esi 192 and edx, esi
192 add ebp, ecx 193 add ebp, ebx
193 ror esi, 1 194 ror esi, 1
194 mov ecx, DWORD PTR 32[esp] 195 mov ebx, DWORD PTR 32[esp]
195 ror esi, 1 196 ror esi, 1
196 xor edx, ebx 197 xor edx, ecx
197 lea ebp, DWORD PTR 1518500249[ecx*1+ebp] 198 lea ebp, DWORD PTR 1518500249[ebx*1+ebp]
198 mov ecx, esi 199 mov ebx, esi
199 add edx, ebp 200 add edx, ebp
200 xor ecx, eax 201 xor ebx, eax
201 mov ebp, edx 202 mov ebp, edx
202 and ecx, edi 203 and ebx, edi
203 rol ebp, 5 204 rol ebp, 5
204 add ebp, ebx 205 add ebp, ecx
205 mov ebx, DWORD PTR 36[esp] 206 mov ecx, DWORD PTR 36[esp]
206 ror edi, 1 207 ror edi, 1
207 xor ecx, eax 208 xor ebx, eax
208 ror edi, 1 209 ror edi, 1
209 lea ebp, DWORD PTR 1518500249[ebx*1+ebp] 210 lea ebp, DWORD PTR 1518500249[ecx*1+ebp]
210 add ecx, ebp 211 add ebx, ebp
211 ; 00_15 10 212 ; 00_15 10
212 mov ebx, edi 213 mov ecx, edi
213 mov ebp, ecx 214 mov ebp, ebx
214 xor ebx, esi 215 xor ecx, esi
215 rol ebp, 5 216 rol ebp, 5
216 and ebx, edx 217 and ecx, edx
217 add ebp, eax 218 add ebp, eax
218 ror edx, 1 219 ror edx, 1
219 mov eax, DWORD PTR 40[esp] 220 mov eax, DWORD PTR 40[esp]
220 ror edx, 1 221 ror edx, 1
221 xor ebx, esi 222 xor ecx, esi
222 lea ebp, DWORD PTR 1518500249[eax*1+ebp] 223 lea ebp, DWORD PTR 1518500249[eax*1+ebp]
223 mov eax, edx 224 mov eax, edx
224 add ebx, ebp 225 add ecx, ebp
225 xor eax, edi 226 xor eax, edi
226 mov ebp, ebx 227 mov ebp, ecx
227 and eax, ecx 228 and eax, ebx
228 rol ebp, 5 229 rol ebp, 5
229 add ebp, esi 230 add ebp, esi
230 mov esi, DWORD PTR 44[esp] 231 mov esi, DWORD PTR 44[esp]
231 ror ecx, 1 232 ror ebx, 1
232 xor eax, edi 233 xor eax, edi
233 ror ecx, 1 234 ror ebx, 1
234 lea ebp, DWORD PTR 1518500249[esi*1+ebp] 235 lea ebp, DWORD PTR 1518500249[esi*1+ebp]
235 add eax, ebp 236 add eax, ebp
236 ; 00_15 12 237 ; 00_15 12
237 mov esi, ecx 238 mov esi, ebx
238 mov ebp, eax 239 mov ebp, eax
239 xor esi, edx 240 xor esi, edx
240 rol ebp, 5 241 rol ebp, 5
241 and esi, ebx 242 and esi, ecx
242 add ebp, edi 243 add ebp, edi
243 ror ebx, 1 244 ror ecx, 1
244 mov edi, DWORD PTR 48[esp] 245 mov edi, DWORD PTR 48[esp]
245 ror ebx, 1 246 ror ecx, 1
246 xor esi, edx 247 xor esi, edx
247 lea ebp, DWORD PTR 1518500249[edi*1+ebp] 248 lea ebp, DWORD PTR 1518500249[edi*1+ebp]
248 mov edi, ebx 249 mov edi, ecx
249 add esi, ebp 250 add esi, ebp
250 xor edi, ecx 251 xor edi, ebx
251 mov ebp, esi 252 mov ebp, esi
252 and edi, eax 253 and edi, eax
253 rol ebp, 5 254 rol ebp, 5
254 add ebp, edx 255 add ebp, edx
255 mov edx, DWORD PTR 52[esp] 256 mov edx, DWORD PTR 52[esp]
256 ror eax, 1 257 ror eax, 1
257 xor edi, ecx 258 xor edi, ebx
258 ror eax, 1 259 ror eax, 1
259 lea ebp, DWORD PTR 1518500249[edx*1+ebp] 260 lea ebp, DWORD PTR 1518500249[edx*1+ebp]
260 add edi, ebp 261 add edi, ebp
261 ; 00_15 14 262 ; 00_15 14
262 mov edx, eax 263 mov edx, eax
263 mov ebp, edi 264 mov ebp, edi
264 xor edx, ebx 265 xor edx, ecx
265 rol ebp, 5 266 rol ebp, 5
266 and edx, esi 267 and edx, esi
267 add ebp, ecx 268 add ebp, ebx
268 ror esi, 1 269 ror esi, 1
269 mov ecx, DWORD PTR 56[esp] 270 mov ebx, DWORD PTR 56[esp]
270 ror esi, 1 271 ror esi, 1
271 xor edx, ebx 272 xor edx, ecx
272 lea ebp, DWORD PTR 1518500249[ecx*1+ebp] 273 lea ebp, DWORD PTR 1518500249[ebx*1+ebp]
273 mov ecx, esi 274 mov ebx, esi
274 add edx, ebp 275 add edx, ebp
275 xor ecx, eax 276 xor ebx, eax
276 mov ebp, edx 277 mov ebp, edx
277 and ecx, edi 278 and ebx, edi
278 rol ebp, 5 279 rol ebp, 5
279 add ebp, ebx 280 add ebp, ecx
280 mov ebx, DWORD PTR 60[esp] 281 mov ecx, DWORD PTR 60[esp]
281 ror edi, 1 282 ror edi, 1
282 xor ecx, eax 283 xor ebx, eax
283 ror edi, 1 284 ror edi, 1
284 lea ebp, DWORD PTR 1518500249[ebx*1+ebp] 285 lea ebp, DWORD PTR 1518500249[ecx*1+ebp]
285 add ecx, ebp 286 add ebx, ebp
286 ; 16_19 16 287 ; 16_19 16
287 nop 288 nop
288 mov ebp, DWORD PTR [esp] 289 mov ebp, DWORD PTR [esp]
289 mov ebx, DWORD PTR 8[esp] 290 mov ecx, DWORD PTR 8[esp]
290 xor ebx, ebp 291 xor ecx, ebp
291 mov ebp, DWORD PTR 32[esp] 292 mov ebp, DWORD PTR 32[esp]
292 xor ebx, ebp 293 xor ecx, ebp
293 mov ebp, DWORD PTR 52[esp] 294 mov ebp, DWORD PTR 52[esp]
294 xor ebx, ebp 295 xor ecx, ebp
295 mov ebp, edi 296 mov ebp, edi
296 rol ebx, 1 297 rol ecx, 1
297 xor ebp, esi 298 xor ebp, esi
298 mov DWORD PTR [esp],ebx 299 mov DWORD PTR [esp],ecx
299 and ebp, edx 300 and ebp, edx
300 lea ebx, DWORD PTR 1518500249[eax*1+ebx] 301 lea ecx, DWORD PTR 1518500249[eax*1+ecx]
301 xor ebp, esi 302 xor ebp, esi
302 mov eax, ecx 303 mov eax, ebx
303 add ebx, ebp 304 add ecx, ebp
304 rol eax, 5 305 rol eax, 5
305 ror edx, 1 306 ror edx, 1
306 add ebx, eax 307 add ecx, eax
307 mov eax, DWORD PTR 4[esp] 308 mov eax, DWORD PTR 4[esp]
308 mov ebp, DWORD PTR 12[esp] 309 mov ebp, DWORD PTR 12[esp]
309 xor eax, ebp 310 xor eax, ebp
@@ -316,14 +317,14 @@ L000start:
316 mov ebp, edx 317 mov ebp, edx
317 xor ebp, edi 318 xor ebp, edi
318 mov DWORD PTR 4[esp],eax 319 mov DWORD PTR 4[esp],eax
319 and ebp, ecx 320 and ebp, ebx
320 lea eax, DWORD PTR 1518500249[esi*1+eax] 321 lea eax, DWORD PTR 1518500249[esi*1+eax]
321 xor ebp, edi 322 xor ebp, edi
322 mov esi, ebx 323 mov esi, ecx
323 rol esi, 5 324 rol esi, 5
324 ror ecx, 1 325 ror ebx, 1
325 add eax, esi 326 add eax, esi
326 ror ecx, 1 327 ror ebx, 1
327 add eax, ebp 328 add eax, ebp
328 ; 16_19 18 329 ; 16_19 18
329 mov ebp, DWORD PTR 8[esp] 330 mov ebp, DWORD PTR 8[esp]
@@ -333,17 +334,17 @@ L000start:
333 xor esi, ebp 334 xor esi, ebp
334 mov ebp, DWORD PTR 60[esp] 335 mov ebp, DWORD PTR 60[esp]
335 xor esi, ebp 336 xor esi, ebp
336 mov ebp, ecx 337 mov ebp, ebx
337 rol esi, 1 338 rol esi, 1
338 xor ebp, edx 339 xor ebp, edx
339 mov DWORD PTR 8[esp],esi 340 mov DWORD PTR 8[esp],esi
340 and ebp, ebx 341 and ebp, ecx
341 lea esi, DWORD PTR 1518500249[edi*1+esi] 342 lea esi, DWORD PTR 1518500249[edi*1+esi]
342 xor ebp, edx 343 xor ebp, edx
343 mov edi, eax 344 mov edi, eax
344 add esi, ebp 345 add esi, ebp
345 rol edi, 5 346 rol edi, 5
346 ror ebx, 1 347 ror ecx, 1
347 add esi, edi 348 add esi, edi
348 mov edi, DWORD PTR 12[esp] 349 mov edi, DWORD PTR 12[esp]
349 mov ebp, DWORD PTR 20[esp] 350 mov ebp, DWORD PTR 20[esp]
@@ -351,15 +352,15 @@ L000start:
351 mov ebp, DWORD PTR 44[esp] 352 mov ebp, DWORD PTR 44[esp]
352 xor edi, ebp 353 xor edi, ebp
353 mov ebp, DWORD PTR [esp] 354 mov ebp, DWORD PTR [esp]
354 ror ebx, 1 355 ror ecx, 1
355 xor edi, ebp 356 xor edi, ebp
356 rol edi, 1 357 rol edi, 1
357 mov ebp, ebx 358 mov ebp, ecx
358 xor ebp, ecx 359 xor ebp, ebx
359 mov DWORD PTR 12[esp],edi 360 mov DWORD PTR 12[esp],edi
360 and ebp, eax 361 and ebp, eax
361 lea edi, DWORD PTR 1518500249[edx*1+edi] 362 lea edi, DWORD PTR 1518500249[edx*1+edi]
362 xor ebp, ecx 363 xor ebp, ebx
363 mov edx, esi 364 mov edx, esi
364 rol edx, 5 365 rol edx, 5
365 ror eax, 1 366 ror eax, 1
@@ -378,54 +379,54 @@ L000start:
378 rol edx, 1 379 rol edx, 1
379 xor ebp, eax 380 xor ebp, eax
380 mov DWORD PTR 16[esp],edx 381 mov DWORD PTR 16[esp],edx
381 xor ebp, ebx 382 xor ebp, ecx
382 lea edx, DWORD PTR 1859775393[ecx*1+edx] 383 lea edx, DWORD PTR 1859775393[ebx*1+edx]
383 mov ecx, edi 384 mov ebx, edi
384 rol ecx, 5 385 rol ebx, 5
385 ror esi, 1 386 ror esi, 1
386 add ecx, ebp 387 add ebx, ebp
387 ror esi, 1 388 ror esi, 1
388 add edx, ecx 389 add edx, ebx
389 ; 20_39 21 390 ; 20_39 21
390 mov ecx, DWORD PTR 20[esp] 391 mov ebx, DWORD PTR 20[esp]
391 mov ebp, DWORD PTR 28[esp] 392 mov ebp, DWORD PTR 28[esp]
392 xor ecx, ebp 393 xor ebx, ebp
393 mov ebp, DWORD PTR 52[esp] 394 mov ebp, DWORD PTR 52[esp]
394 xor ecx, ebp 395 xor ebx, ebp
395 mov ebp, DWORD PTR 8[esp] 396 mov ebp, DWORD PTR 8[esp]
396 xor ecx, ebp 397 xor ebx, ebp
397 mov ebp, edi 398 mov ebp, edi
398 rol ecx, 1 399 rol ebx, 1
399 xor ebp, esi 400 xor ebp, esi
400 mov DWORD PTR 20[esp],ecx 401 mov DWORD PTR 20[esp],ebx
401 xor ebp, eax 402 xor ebp, eax
402 lea ecx, DWORD PTR 1859775393[ebx*1+ecx] 403 lea ebx, DWORD PTR 1859775393[ecx*1+ebx]
403 mov ebx, edx 404 mov ecx, edx
404 rol ebx, 5 405 rol ecx, 5
405 ror edi, 1 406 ror edi, 1
406 add ebx, ebp 407 add ecx, ebp
407 ror edi, 1 408 ror edi, 1
408 add ecx, ebx 409 add ebx, ecx
409 ; 20_39 22 410 ; 20_39 22
410 mov ebx, DWORD PTR 24[esp] 411 mov ecx, DWORD PTR 24[esp]
411 mov ebp, DWORD PTR 32[esp] 412 mov ebp, DWORD PTR 32[esp]
412 xor ebx, ebp 413 xor ecx, ebp
413 mov ebp, DWORD PTR 56[esp] 414 mov ebp, DWORD PTR 56[esp]
414 xor ebx, ebp 415 xor ecx, ebp
415 mov ebp, DWORD PTR 12[esp] 416 mov ebp, DWORD PTR 12[esp]
416 xor ebx, ebp 417 xor ecx, ebp
417 mov ebp, edx 418 mov ebp, edx
418 rol ebx, 1 419 rol ecx, 1
419 xor ebp, edi 420 xor ebp, edi
420 mov DWORD PTR 24[esp],ebx 421 mov DWORD PTR 24[esp],ecx
421 xor ebp, esi 422 xor ebp, esi
422 lea ebx, DWORD PTR 1859775393[eax*1+ebx] 423 lea ecx, DWORD PTR 1859775393[eax*1+ecx]
423 mov eax, ecx 424 mov eax, ebx
424 rol eax, 5 425 rol eax, 5
425 ror edx, 1 426 ror edx, 1
426 add eax, ebp 427 add eax, ebp
427 ror edx, 1 428 ror edx, 1
428 add ebx, eax 429 add ecx, eax
429 ; 20_39 23 430 ; 20_39 23
430 mov eax, DWORD PTR 28[esp] 431 mov eax, DWORD PTR 28[esp]
431 mov ebp, DWORD PTR 36[esp] 432 mov ebp, DWORD PTR 36[esp]
@@ -434,17 +435,17 @@ L000start:
434 xor eax, ebp 435 xor eax, ebp
435 mov ebp, DWORD PTR 16[esp] 436 mov ebp, DWORD PTR 16[esp]
436 xor eax, ebp 437 xor eax, ebp
437 mov ebp, ecx 438 mov ebp, ebx
438 rol eax, 1 439 rol eax, 1
439 xor ebp, edx 440 xor ebp, edx
440 mov DWORD PTR 28[esp],eax 441 mov DWORD PTR 28[esp],eax
441 xor ebp, edi 442 xor ebp, edi
442 lea eax, DWORD PTR 1859775393[esi*1+eax] 443 lea eax, DWORD PTR 1859775393[esi*1+eax]
443 mov esi, ebx 444 mov esi, ecx
444 rol esi, 5 445 rol esi, 5
445 ror ecx, 1 446 ror ebx, 1
446 add esi, ebp 447 add esi, ebp
447 ror ecx, 1 448 ror ebx, 1
448 add eax, esi 449 add eax, esi
449 ; 20_39 24 450 ; 20_39 24
450 mov esi, DWORD PTR 32[esp] 451 mov esi, DWORD PTR 32[esp]
@@ -454,17 +455,17 @@ L000start:
454 xor esi, ebp 455 xor esi, ebp
455 mov ebp, DWORD PTR 20[esp] 456 mov ebp, DWORD PTR 20[esp]
456 xor esi, ebp 457 xor esi, ebp
457 mov ebp, ebx 458 mov ebp, ecx
458 rol esi, 1 459 rol esi, 1
459 xor ebp, ecx 460 xor ebp, ebx
460 mov DWORD PTR 32[esp],esi 461 mov DWORD PTR 32[esp],esi
461 xor ebp, edx 462 xor ebp, edx
462 lea esi, DWORD PTR 1859775393[edi*1+esi] 463 lea esi, DWORD PTR 1859775393[edi*1+esi]
463 mov edi, eax 464 mov edi, eax
464 rol edi, 5 465 rol edi, 5
465 ror ebx, 1 466 ror ecx, 1
466 add edi, ebp 467 add edi, ebp
467 ror ebx, 1 468 ror ecx, 1
468 add esi, edi 469 add esi, edi
469 ; 20_39 25 470 ; 20_39 25
470 mov edi, DWORD PTR 36[esp] 471 mov edi, DWORD PTR 36[esp]
@@ -476,9 +477,9 @@ L000start:
476 xor edi, ebp 477 xor edi, ebp
477 mov ebp, eax 478 mov ebp, eax
478 rol edi, 1 479 rol edi, 1
479 xor ebp, ebx
480 mov DWORD PTR 36[esp],edi
481 xor ebp, ecx 480 xor ebp, ecx
481 mov DWORD PTR 36[esp],edi
482 xor ebp, ebx
482 lea edi, DWORD PTR 1859775393[edx*1+edi] 483 lea edi, DWORD PTR 1859775393[edx*1+edi]
483 mov edx, esi 484 mov edx, esi
484 rol edx, 5 485 rol edx, 5
@@ -498,54 +499,54 @@ L000start:
498 rol edx, 1 499 rol edx, 1
499 xor ebp, eax 500 xor ebp, eax
500 mov DWORD PTR 40[esp],edx 501 mov DWORD PTR 40[esp],edx
501 xor ebp, ebx 502 xor ebp, ecx
502 lea edx, DWORD PTR 1859775393[ecx*1+edx] 503 lea edx, DWORD PTR 1859775393[ebx*1+edx]
503 mov ecx, edi 504 mov ebx, edi
504 rol ecx, 5 505 rol ebx, 5
505 ror esi, 1 506 ror esi, 1
506 add ecx, ebp 507 add ebx, ebp
507 ror esi, 1 508 ror esi, 1
508 add edx, ecx 509 add edx, ebx
509 ; 20_39 27 510 ; 20_39 27
510 mov ecx, DWORD PTR 44[esp] 511 mov ebx, DWORD PTR 44[esp]
511 mov ebp, DWORD PTR 52[esp] 512 mov ebp, DWORD PTR 52[esp]
512 xor ecx, ebp 513 xor ebx, ebp
513 mov ebp, DWORD PTR 12[esp] 514 mov ebp, DWORD PTR 12[esp]
514 xor ecx, ebp 515 xor ebx, ebp
515 mov ebp, DWORD PTR 32[esp] 516 mov ebp, DWORD PTR 32[esp]
516 xor ecx, ebp 517 xor ebx, ebp
517 mov ebp, edi 518 mov ebp, edi
518 rol ecx, 1 519 rol ebx, 1
519 xor ebp, esi 520 xor ebp, esi
520 mov DWORD PTR 44[esp],ecx 521 mov DWORD PTR 44[esp],ebx
521 xor ebp, eax 522 xor ebp, eax
522 lea ecx, DWORD PTR 1859775393[ebx*1+ecx] 523 lea ebx, DWORD PTR 1859775393[ecx*1+ebx]
523 mov ebx, edx 524 mov ecx, edx
524 rol ebx, 5 525 rol ecx, 5
525 ror edi, 1 526 ror edi, 1
526 add ebx, ebp 527 add ecx, ebp
527 ror edi, 1 528 ror edi, 1
528 add ecx, ebx 529 add ebx, ecx
529 ; 20_39 28 530 ; 20_39 28
530 mov ebx, DWORD PTR 48[esp] 531 mov ecx, DWORD PTR 48[esp]
531 mov ebp, DWORD PTR 56[esp] 532 mov ebp, DWORD PTR 56[esp]
532 xor ebx, ebp 533 xor ecx, ebp
533 mov ebp, DWORD PTR 16[esp] 534 mov ebp, DWORD PTR 16[esp]
534 xor ebx, ebp 535 xor ecx, ebp
535 mov ebp, DWORD PTR 36[esp] 536 mov ebp, DWORD PTR 36[esp]
536 xor ebx, ebp 537 xor ecx, ebp
537 mov ebp, edx 538 mov ebp, edx
538 rol ebx, 1 539 rol ecx, 1
539 xor ebp, edi 540 xor ebp, edi
540 mov DWORD PTR 48[esp],ebx 541 mov DWORD PTR 48[esp],ecx
541 xor ebp, esi 542 xor ebp, esi
542 lea ebx, DWORD PTR 1859775393[eax*1+ebx] 543 lea ecx, DWORD PTR 1859775393[eax*1+ecx]
543 mov eax, ecx 544 mov eax, ebx
544 rol eax, 5 545 rol eax, 5
545 ror edx, 1 546 ror edx, 1
546 add eax, ebp 547 add eax, ebp
547 ror edx, 1 548 ror edx, 1
548 add ebx, eax 549 add ecx, eax
549 ; 20_39 29 550 ; 20_39 29
550 mov eax, DWORD PTR 52[esp] 551 mov eax, DWORD PTR 52[esp]
551 mov ebp, DWORD PTR 60[esp] 552 mov ebp, DWORD PTR 60[esp]
@@ -554,17 +555,17 @@ L000start:
554 xor eax, ebp 555 xor eax, ebp
555 mov ebp, DWORD PTR 40[esp] 556 mov ebp, DWORD PTR 40[esp]
556 xor eax, ebp 557 xor eax, ebp
557 mov ebp, ecx 558 mov ebp, ebx
558 rol eax, 1 559 rol eax, 1
559 xor ebp, edx 560 xor ebp, edx
560 mov DWORD PTR 52[esp],eax 561 mov DWORD PTR 52[esp],eax
561 xor ebp, edi 562 xor ebp, edi
562 lea eax, DWORD PTR 1859775393[esi*1+eax] 563 lea eax, DWORD PTR 1859775393[esi*1+eax]
563 mov esi, ebx 564 mov esi, ecx
564 rol esi, 5 565 rol esi, 5
565 ror ecx, 1 566 ror ebx, 1
566 add esi, ebp 567 add esi, ebp
567 ror ecx, 1 568 ror ebx, 1
568 add eax, esi 569 add eax, esi
569 ; 20_39 30 570 ; 20_39 30
570 mov esi, DWORD PTR 56[esp] 571 mov esi, DWORD PTR 56[esp]
@@ -574,17 +575,17 @@ L000start:
574 xor esi, ebp 575 xor esi, ebp
575 mov ebp, DWORD PTR 44[esp] 576 mov ebp, DWORD PTR 44[esp]
576 xor esi, ebp 577 xor esi, ebp
577 mov ebp, ebx 578 mov ebp, ecx
578 rol esi, 1 579 rol esi, 1
579 xor ebp, ecx 580 xor ebp, ebx
580 mov DWORD PTR 56[esp],esi 581 mov DWORD PTR 56[esp],esi
581 xor ebp, edx 582 xor ebp, edx
582 lea esi, DWORD PTR 1859775393[edi*1+esi] 583 lea esi, DWORD PTR 1859775393[edi*1+esi]
583 mov edi, eax 584 mov edi, eax
584 rol edi, 5 585 rol edi, 5
585 ror ebx, 1 586 ror ecx, 1
586 add edi, ebp 587 add edi, ebp
587 ror ebx, 1 588 ror ecx, 1
588 add esi, edi 589 add esi, edi
589 ; 20_39 31 590 ; 20_39 31
590 mov edi, DWORD PTR 60[esp] 591 mov edi, DWORD PTR 60[esp]
@@ -596,9 +597,9 @@ L000start:
596 xor edi, ebp 597 xor edi, ebp
597 mov ebp, eax 598 mov ebp, eax
598 rol edi, 1 599 rol edi, 1
599 xor ebp, ebx
600 mov DWORD PTR 60[esp],edi
601 xor ebp, ecx 600 xor ebp, ecx
601 mov DWORD PTR 60[esp],edi
602 xor ebp, ebx
602 lea edi, DWORD PTR 1859775393[edx*1+edi] 603 lea edi, DWORD PTR 1859775393[edx*1+edi]
603 mov edx, esi 604 mov edx, esi
604 rol edx, 5 605 rol edx, 5
@@ -618,54 +619,54 @@ L000start:
618 rol edx, 1 619 rol edx, 1
619 xor ebp, eax 620 xor ebp, eax
620 mov DWORD PTR [esp],edx 621 mov DWORD PTR [esp],edx
621 xor ebp, ebx 622 xor ebp, ecx
622 lea edx, DWORD PTR 1859775393[ecx*1+edx] 623 lea edx, DWORD PTR 1859775393[ebx*1+edx]
623 mov ecx, edi 624 mov ebx, edi
624 rol ecx, 5 625 rol ebx, 5
625 ror esi, 1 626 ror esi, 1
626 add ecx, ebp 627 add ebx, ebp
627 ror esi, 1 628 ror esi, 1
628 add edx, ecx 629 add edx, ebx
629 ; 20_39 33 630 ; 20_39 33
630 mov ecx, DWORD PTR 4[esp] 631 mov ebx, DWORD PTR 4[esp]
631 mov ebp, DWORD PTR 12[esp] 632 mov ebp, DWORD PTR 12[esp]
632 xor ecx, ebp 633 xor ebx, ebp
633 mov ebp, DWORD PTR 36[esp] 634 mov ebp, DWORD PTR 36[esp]
634 xor ecx, ebp 635 xor ebx, ebp
635 mov ebp, DWORD PTR 56[esp] 636 mov ebp, DWORD PTR 56[esp]
636 xor ecx, ebp 637 xor ebx, ebp
637 mov ebp, edi 638 mov ebp, edi
638 rol ecx, 1 639 rol ebx, 1
639 xor ebp, esi 640 xor ebp, esi
640 mov DWORD PTR 4[esp],ecx 641 mov DWORD PTR 4[esp],ebx
641 xor ebp, eax 642 xor ebp, eax
642 lea ecx, DWORD PTR 1859775393[ebx*1+ecx] 643 lea ebx, DWORD PTR 1859775393[ecx*1+ebx]
643 mov ebx, edx 644 mov ecx, edx
644 rol ebx, 5 645 rol ecx, 5
645 ror edi, 1 646 ror edi, 1
646 add ebx, ebp 647 add ecx, ebp
647 ror edi, 1 648 ror edi, 1
648 add ecx, ebx 649 add ebx, ecx
649 ; 20_39 34 650 ; 20_39 34
650 mov ebx, DWORD PTR 8[esp] 651 mov ecx, DWORD PTR 8[esp]
651 mov ebp, DWORD PTR 16[esp] 652 mov ebp, DWORD PTR 16[esp]
652 xor ebx, ebp 653 xor ecx, ebp
653 mov ebp, DWORD PTR 40[esp] 654 mov ebp, DWORD PTR 40[esp]
654 xor ebx, ebp 655 xor ecx, ebp
655 mov ebp, DWORD PTR 60[esp] 656 mov ebp, DWORD PTR 60[esp]
656 xor ebx, ebp 657 xor ecx, ebp
657 mov ebp, edx 658 mov ebp, edx
658 rol ebx, 1 659 rol ecx, 1
659 xor ebp, edi 660 xor ebp, edi
660 mov DWORD PTR 8[esp],ebx 661 mov DWORD PTR 8[esp],ecx
661 xor ebp, esi 662 xor ebp, esi
662 lea ebx, DWORD PTR 1859775393[eax*1+ebx] 663 lea ecx, DWORD PTR 1859775393[eax*1+ecx]
663 mov eax, ecx 664 mov eax, ebx
664 rol eax, 5 665 rol eax, 5
665 ror edx, 1 666 ror edx, 1
666 add eax, ebp 667 add eax, ebp
667 ror edx, 1 668 ror edx, 1
668 add ebx, eax 669 add ecx, eax
669 ; 20_39 35 670 ; 20_39 35
670 mov eax, DWORD PTR 12[esp] 671 mov eax, DWORD PTR 12[esp]
671 mov ebp, DWORD PTR 20[esp] 672 mov ebp, DWORD PTR 20[esp]
@@ -674,17 +675,17 @@ L000start:
674 xor eax, ebp 675 xor eax, ebp
675 mov ebp, DWORD PTR [esp] 676 mov ebp, DWORD PTR [esp]
676 xor eax, ebp 677 xor eax, ebp
677 mov ebp, ecx 678 mov ebp, ebx
678 rol eax, 1 679 rol eax, 1
679 xor ebp, edx 680 xor ebp, edx
680 mov DWORD PTR 12[esp],eax 681 mov DWORD PTR 12[esp],eax
681 xor ebp, edi 682 xor ebp, edi
682 lea eax, DWORD PTR 1859775393[esi*1+eax] 683 lea eax, DWORD PTR 1859775393[esi*1+eax]
683 mov esi, ebx 684 mov esi, ecx
684 rol esi, 5 685 rol esi, 5
685 ror ecx, 1 686 ror ebx, 1
686 add esi, ebp 687 add esi, ebp
687 ror ecx, 1 688 ror ebx, 1
688 add eax, esi 689 add eax, esi
689 ; 20_39 36 690 ; 20_39 36
690 mov esi, DWORD PTR 16[esp] 691 mov esi, DWORD PTR 16[esp]
@@ -694,17 +695,17 @@ L000start:
694 xor esi, ebp 695 xor esi, ebp
695 mov ebp, DWORD PTR 4[esp] 696 mov ebp, DWORD PTR 4[esp]
696 xor esi, ebp 697 xor esi, ebp
697 mov ebp, ebx 698 mov ebp, ecx
698 rol esi, 1 699 rol esi, 1
699 xor ebp, ecx 700 xor ebp, ebx
700 mov DWORD PTR 16[esp],esi 701 mov DWORD PTR 16[esp],esi
701 xor ebp, edx 702 xor ebp, edx
702 lea esi, DWORD PTR 1859775393[edi*1+esi] 703 lea esi, DWORD PTR 1859775393[edi*1+esi]
703 mov edi, eax 704 mov edi, eax
704 rol edi, 5 705 rol edi, 5
705 ror ebx, 1 706 ror ecx, 1
706 add edi, ebp 707 add edi, ebp
707 ror ebx, 1 708 ror ecx, 1
708 add esi, edi 709 add esi, edi
709 ; 20_39 37 710 ; 20_39 37
710 mov edi, DWORD PTR 20[esp] 711 mov edi, DWORD PTR 20[esp]
@@ -716,9 +717,9 @@ L000start:
716 xor edi, ebp 717 xor edi, ebp
717 mov ebp, eax 718 mov ebp, eax
718 rol edi, 1 719 rol edi, 1
719 xor ebp, ebx
720 mov DWORD PTR 20[esp],edi
721 xor ebp, ecx 720 xor ebp, ecx
721 mov DWORD PTR 20[esp],edi
722 xor ebp, ebx
722 lea edi, DWORD PTR 1859775393[edx*1+edi] 723 lea edi, DWORD PTR 1859775393[edx*1+edi]
723 mov edx, esi 724 mov edx, esi
724 rol edx, 5 725 rol edx, 5
@@ -738,57 +739,57 @@ L000start:
738 rol edx, 1 739 rol edx, 1
739 xor ebp, eax 740 xor ebp, eax
740 mov DWORD PTR 24[esp],edx 741 mov DWORD PTR 24[esp],edx
741 xor ebp, ebx 742 xor ebp, ecx
742 lea edx, DWORD PTR 1859775393[ecx*1+edx] 743 lea edx, DWORD PTR 1859775393[ebx*1+edx]
743 mov ecx, edi 744 mov ebx, edi
744 rol ecx, 5 745 rol ebx, 5
745 ror esi, 1 746 ror esi, 1
746 add ecx, ebp 747 add ebx, ebp
747 ror esi, 1 748 ror esi, 1
748 add edx, ecx 749 add edx, ebx
749 ; 20_39 39 750 ; 20_39 39
750 mov ecx, DWORD PTR 28[esp] 751 mov ebx, DWORD PTR 28[esp]
751 mov ebp, DWORD PTR 36[esp] 752 mov ebp, DWORD PTR 36[esp]
752 xor ecx, ebp 753 xor ebx, ebp
753 mov ebp, DWORD PTR 60[esp] 754 mov ebp, DWORD PTR 60[esp]
754 xor ecx, ebp 755 xor ebx, ebp
755 mov ebp, DWORD PTR 16[esp] 756 mov ebp, DWORD PTR 16[esp]
756 xor ecx, ebp 757 xor ebx, ebp
757 mov ebp, edi 758 mov ebp, edi
758 rol ecx, 1 759 rol ebx, 1
759 xor ebp, esi 760 xor ebp, esi
760 mov DWORD PTR 28[esp],ecx 761 mov DWORD PTR 28[esp],ebx
761 xor ebp, eax 762 xor ebp, eax
762 lea ecx, DWORD PTR 1859775393[ebx*1+ecx] 763 lea ebx, DWORD PTR 1859775393[ecx*1+ebx]
763 mov ebx, edx 764 mov ecx, edx
764 rol ebx, 5 765 rol ecx, 5
765 ror edi, 1 766 ror edi, 1
766 add ebx, ebp 767 add ecx, ebp
767 ror edi, 1 768 ror edi, 1
768 add ecx, ebx 769 add ebx, ecx
769 ; 40_59 40 770 ; 40_59 40
770 mov ebx, DWORD PTR 32[esp] 771 mov ecx, DWORD PTR 32[esp]
771 mov ebp, DWORD PTR 40[esp] 772 mov ebp, DWORD PTR 40[esp]
772 xor ebx, ebp 773 xor ecx, ebp
773 mov ebp, DWORD PTR [esp] 774 mov ebp, DWORD PTR [esp]
774 xor ebx, ebp 775 xor ecx, ebp
775 mov ebp, DWORD PTR 20[esp] 776 mov ebp, DWORD PTR 20[esp]
776 xor ebx, ebp 777 xor ecx, ebp
777 mov ebp, edx 778 mov ebp, edx
778 rol ebx, 1 779 rol ecx, 1
779 or ebp, edi 780 or ebp, edi
780 mov DWORD PTR 32[esp],ebx 781 mov DWORD PTR 32[esp],ecx
781 and ebp, esi 782 and ebp, esi
782 lea ebx, DWORD PTR 2400959708[eax*1+ebx] 783 lea ecx, DWORD PTR 2400959708[eax*1+ecx]
783 mov eax, edx 784 mov eax, edx
784 ror edx, 1 785 ror edx, 1
785 and eax, edi 786 and eax, edi
786 or ebp, eax 787 or ebp, eax
787 mov eax, ecx 788 mov eax, ebx
788 rol eax, 5 789 rol eax, 5
789 add ebp, eax 790 add ebp, eax
790 mov eax, DWORD PTR 36[esp] 791 mov eax, DWORD PTR 36[esp]
791 add ebx, ebp 792 add ecx, ebp
792 mov ebp, DWORD PTR 44[esp] 793 mov ebp, DWORD PTR 44[esp]
793 xor eax, ebp 794 xor eax, ebp
794 mov ebp, DWORD PTR 4[esp] 795 mov ebp, DWORD PTR 4[esp]
@@ -797,19 +798,19 @@ L000start:
797 ror edx, 1 798 ror edx, 1
798 xor eax, ebp 799 xor eax, ebp
799 rol eax, 1 800 rol eax, 1
800 mov ebp, ecx 801 mov ebp, ebx
801 mov DWORD PTR 36[esp],eax 802 mov DWORD PTR 36[esp],eax
802 or ebp, edx 803 or ebp, edx
803 lea eax, DWORD PTR 2400959708[esi*1+eax] 804 lea eax, DWORD PTR 2400959708[esi*1+eax]
804 mov esi, ecx 805 mov esi, ebx
805 and ebp, edi 806 and ebp, edi
806 and esi, edx 807 and esi, edx
807 or ebp, esi 808 or ebp, esi
808 mov esi, ebx 809 mov esi, ecx
809 rol esi, 5 810 rol esi, 5
810 ror ecx, 1 811 ror ebx, 1
811 add ebp, esi 812 add ebp, esi
812 ror ecx, 1 813 ror ebx, 1
813 add eax, ebp 814 add eax, ebp
814 ; 40_59 41 815 ; 40_59 41
815 ; 40_59 42 816 ; 40_59 42
@@ -820,15 +821,15 @@ L000start:
820 xor esi, ebp 821 xor esi, ebp
821 mov ebp, DWORD PTR 28[esp] 822 mov ebp, DWORD PTR 28[esp]
822 xor esi, ebp 823 xor esi, ebp
823 mov ebp, ebx 824 mov ebp, ecx
824 rol esi, 1 825 rol esi, 1
825 or ebp, ecx 826 or ebp, ebx
826 mov DWORD PTR 40[esp],esi 827 mov DWORD PTR 40[esp],esi
827 and ebp, edx 828 and ebp, edx
828 lea esi, DWORD PTR 2400959708[edi*1+esi] 829 lea esi, DWORD PTR 2400959708[edi*1+esi]
829 mov edi, ebx 830 mov edi, ecx
830 ror ebx, 1 831 ror ecx, 1
831 and edi, ecx 832 and edi, ebx
832 or ebp, edi 833 or ebp, edi
833 mov edi, eax 834 mov edi, eax
834 rol edi, 5 835 rol edi, 5
@@ -840,16 +841,16 @@ L000start:
840 mov ebp, DWORD PTR 12[esp] 841 mov ebp, DWORD PTR 12[esp]
841 xor edi, ebp 842 xor edi, ebp
842 mov ebp, DWORD PTR 32[esp] 843 mov ebp, DWORD PTR 32[esp]
843 ror ebx, 1 844 ror ecx, 1
844 xor edi, ebp 845 xor edi, ebp
845 rol edi, 1 846 rol edi, 1
846 mov ebp, eax 847 mov ebp, eax
847 mov DWORD PTR 44[esp],edi 848 mov DWORD PTR 44[esp],edi
848 or ebp, ebx 849 or ebp, ecx
849 lea edi, DWORD PTR 2400959708[edx*1+edi] 850 lea edi, DWORD PTR 2400959708[edx*1+edi]
850 mov edx, eax 851 mov edx, eax
851 and ebp, ecx 852 and ebp, ebx
852 and edx, ebx 853 and edx, ecx
853 or ebp, edx 854 or ebp, edx
854 mov edx, esi 855 mov edx, esi
855 rol edx, 5 856 rol edx, 5
@@ -870,63 +871,63 @@ L000start:
870 rol edx, 1 871 rol edx, 1
871 or ebp, eax 872 or ebp, eax
872 mov DWORD PTR 48[esp],edx 873 mov DWORD PTR 48[esp],edx
873 and ebp, ebx 874 and ebp, ecx
874 lea edx, DWORD PTR 2400959708[ecx*1+edx] 875 lea edx, DWORD PTR 2400959708[ebx*1+edx]
875 mov ecx, esi 876 mov ebx, esi
876 ror esi, 1 877 ror esi, 1
877 and ecx, eax 878 and ebx, eax
878 or ebp, ecx 879 or ebp, ebx
879 mov ecx, edi 880 mov ebx, edi
880 rol ecx, 5 881 rol ebx, 5
881 add ebp, ecx 882 add ebp, ebx
882 mov ecx, DWORD PTR 52[esp] 883 mov ebx, DWORD PTR 52[esp]
883 add edx, ebp 884 add edx, ebp
884 mov ebp, DWORD PTR 60[esp] 885 mov ebp, DWORD PTR 60[esp]
885 xor ecx, ebp 886 xor ebx, ebp
886 mov ebp, DWORD PTR 20[esp] 887 mov ebp, DWORD PTR 20[esp]
887 xor ecx, ebp 888 xor ebx, ebp
888 mov ebp, DWORD PTR 40[esp] 889 mov ebp, DWORD PTR 40[esp]
889 ror esi, 1 890 ror esi, 1
890 xor ecx, ebp 891 xor ebx, ebp
891 rol ecx, 1 892 rol ebx, 1
892 mov ebp, edi 893 mov ebp, edi
893 mov DWORD PTR 52[esp],ecx 894 mov DWORD PTR 52[esp],ebx
894 or ebp, esi 895 or ebp, esi
895 lea ecx, DWORD PTR 2400959708[ebx*1+ecx] 896 lea ebx, DWORD PTR 2400959708[ecx*1+ebx]
896 mov ebx, edi 897 mov ecx, edi
897 and ebp, eax 898 and ebp, eax
898 and ebx, esi 899 and ecx, esi
899 or ebp, ebx 900 or ebp, ecx
900 mov ebx, edx 901 mov ecx, edx
901 rol ebx, 5 902 rol ecx, 5
902 ror edi, 1 903 ror edi, 1
903 add ebp, ebx 904 add ebp, ecx
904 ror edi, 1 905 ror edi, 1
905 add ecx, ebp 906 add ebx, ebp
906 ; 40_59 45 907 ; 40_59 45
907 ; 40_59 46 908 ; 40_59 46
908 mov ebx, DWORD PTR 56[esp] 909 mov ecx, DWORD PTR 56[esp]
909 mov ebp, DWORD PTR [esp] 910 mov ebp, DWORD PTR [esp]
910 xor ebx, ebp 911 xor ecx, ebp
911 mov ebp, DWORD PTR 24[esp] 912 mov ebp, DWORD PTR 24[esp]
912 xor ebx, ebp 913 xor ecx, ebp
913 mov ebp, DWORD PTR 44[esp] 914 mov ebp, DWORD PTR 44[esp]
914 xor ebx, ebp 915 xor ecx, ebp
915 mov ebp, edx 916 mov ebp, edx
916 rol ebx, 1 917 rol ecx, 1
917 or ebp, edi 918 or ebp, edi
918 mov DWORD PTR 56[esp],ebx 919 mov DWORD PTR 56[esp],ecx
919 and ebp, esi 920 and ebp, esi
920 lea ebx, DWORD PTR 2400959708[eax*1+ebx] 921 lea ecx, DWORD PTR 2400959708[eax*1+ecx]
921 mov eax, edx 922 mov eax, edx
922 ror edx, 1 923 ror edx, 1
923 and eax, edi 924 and eax, edi
924 or ebp, eax 925 or ebp, eax
925 mov eax, ecx 926 mov eax, ebx
926 rol eax, 5 927 rol eax, 5
927 add ebp, eax 928 add ebp, eax
928 mov eax, DWORD PTR 60[esp] 929 mov eax, DWORD PTR 60[esp]
929 add ebx, ebp 930 add ecx, ebp
930 mov ebp, DWORD PTR 4[esp] 931 mov ebp, DWORD PTR 4[esp]
931 xor eax, ebp 932 xor eax, ebp
932 mov ebp, DWORD PTR 28[esp] 933 mov ebp, DWORD PTR 28[esp]
@@ -935,19 +936,19 @@ L000start:
935 ror edx, 1 936 ror edx, 1
936 xor eax, ebp 937 xor eax, ebp
937 rol eax, 1 938 rol eax, 1
938 mov ebp, ecx 939 mov ebp, ebx
939 mov DWORD PTR 60[esp],eax 940 mov DWORD PTR 60[esp],eax
940 or ebp, edx 941 or ebp, edx
941 lea eax, DWORD PTR 2400959708[esi*1+eax] 942 lea eax, DWORD PTR 2400959708[esi*1+eax]
942 mov esi, ecx 943 mov esi, ebx
943 and ebp, edi 944 and ebp, edi
944 and esi, edx 945 and esi, edx
945 or ebp, esi 946 or ebp, esi
946 mov esi, ebx 947 mov esi, ecx
947 rol esi, 5 948 rol esi, 5
948 ror ecx, 1 949 ror ebx, 1
949 add ebp, esi 950 add ebp, esi
950 ror ecx, 1 951 ror ebx, 1
951 add eax, ebp 952 add eax, ebp
952 ; 40_59 47 953 ; 40_59 47
953 ; 40_59 48 954 ; 40_59 48
@@ -958,15 +959,15 @@ L000start:
958 xor esi, ebp 959 xor esi, ebp
959 mov ebp, DWORD PTR 52[esp] 960 mov ebp, DWORD PTR 52[esp]
960 xor esi, ebp 961 xor esi, ebp
961 mov ebp, ebx 962 mov ebp, ecx
962 rol esi, 1 963 rol esi, 1
963 or ebp, ecx 964 or ebp, ebx
964 mov DWORD PTR [esp],esi 965 mov DWORD PTR [esp],esi
965 and ebp, edx 966 and ebp, edx
966 lea esi, DWORD PTR 2400959708[edi*1+esi] 967 lea esi, DWORD PTR 2400959708[edi*1+esi]
967 mov edi, ebx 968 mov edi, ecx
968 ror ebx, 1 969 ror ecx, 1
969 and edi, ecx 970 and edi, ebx
970 or ebp, edi 971 or ebp, edi
971 mov edi, eax 972 mov edi, eax
972 rol edi, 5 973 rol edi, 5
@@ -978,16 +979,16 @@ L000start:
978 mov ebp, DWORD PTR 36[esp] 979 mov ebp, DWORD PTR 36[esp]
979 xor edi, ebp 980 xor edi, ebp
980 mov ebp, DWORD PTR 56[esp] 981 mov ebp, DWORD PTR 56[esp]
981 ror ebx, 1 982 ror ecx, 1
982 xor edi, ebp 983 xor edi, ebp
983 rol edi, 1 984 rol edi, 1
984 mov ebp, eax 985 mov ebp, eax
985 mov DWORD PTR 4[esp],edi 986 mov DWORD PTR 4[esp],edi
986 or ebp, ebx 987 or ebp, ecx
987 lea edi, DWORD PTR 2400959708[edx*1+edi] 988 lea edi, DWORD PTR 2400959708[edx*1+edi]
988 mov edx, eax 989 mov edx, eax
989 and ebp, ecx 990 and ebp, ebx
990 and edx, ebx 991 and edx, ecx
991 or ebp, edx 992 or ebp, edx
992 mov edx, esi 993 mov edx, esi
993 rol edx, 5 994 rol edx, 5
@@ -1008,63 +1009,63 @@ L000start:
1008 rol edx, 1 1009 rol edx, 1
1009 or ebp, eax 1010 or ebp, eax
1010 mov DWORD PTR 8[esp],edx 1011 mov DWORD PTR 8[esp],edx
1011 and ebp, ebx 1012 and ebp, ecx
1012 lea edx, DWORD PTR 2400959708[ecx*1+edx] 1013 lea edx, DWORD PTR 2400959708[ebx*1+edx]
1013 mov ecx, esi 1014 mov ebx, esi
1014 ror esi, 1 1015 ror esi, 1
1015 and ecx, eax 1016 and ebx, eax
1016 or ebp, ecx 1017 or ebp, ebx
1017 mov ecx, edi 1018 mov ebx, edi
1018 rol ecx, 5 1019 rol ebx, 5
1019 add ebp, ecx 1020 add ebp, ebx
1020 mov ecx, DWORD PTR 12[esp] 1021 mov ebx, DWORD PTR 12[esp]
1021 add edx, ebp 1022 add edx, ebp
1022 mov ebp, DWORD PTR 20[esp] 1023 mov ebp, DWORD PTR 20[esp]
1023 xor ecx, ebp 1024 xor ebx, ebp
1024 mov ebp, DWORD PTR 44[esp] 1025 mov ebp, DWORD PTR 44[esp]
1025 xor ecx, ebp 1026 xor ebx, ebp
1026 mov ebp, DWORD PTR [esp] 1027 mov ebp, DWORD PTR [esp]
1027 ror esi, 1 1028 ror esi, 1
1028 xor ecx, ebp 1029 xor ebx, ebp
1029 rol ecx, 1 1030 rol ebx, 1
1030 mov ebp, edi 1031 mov ebp, edi
1031 mov DWORD PTR 12[esp],ecx 1032 mov DWORD PTR 12[esp],ebx
1032 or ebp, esi 1033 or ebp, esi
1033 lea ecx, DWORD PTR 2400959708[ebx*1+ecx] 1034 lea ebx, DWORD PTR 2400959708[ecx*1+ebx]
1034 mov ebx, edi 1035 mov ecx, edi
1035 and ebp, eax 1036 and ebp, eax
1036 and ebx, esi 1037 and ecx, esi
1037 or ebp, ebx 1038 or ebp, ecx
1038 mov ebx, edx 1039 mov ecx, edx
1039 rol ebx, 5 1040 rol ecx, 5
1040 ror edi, 1 1041 ror edi, 1
1041 add ebp, ebx 1042 add ebp, ecx
1042 ror edi, 1 1043 ror edi, 1
1043 add ecx, ebp 1044 add ebx, ebp
1044 ; 40_59 51 1045 ; 40_59 51
1045 ; 40_59 52 1046 ; 40_59 52
1046 mov ebx, DWORD PTR 16[esp] 1047 mov ecx, DWORD PTR 16[esp]
1047 mov ebp, DWORD PTR 24[esp] 1048 mov ebp, DWORD PTR 24[esp]
1048 xor ebx, ebp 1049 xor ecx, ebp
1049 mov ebp, DWORD PTR 48[esp] 1050 mov ebp, DWORD PTR 48[esp]
1050 xor ebx, ebp 1051 xor ecx, ebp
1051 mov ebp, DWORD PTR 4[esp] 1052 mov ebp, DWORD PTR 4[esp]
1052 xor ebx, ebp 1053 xor ecx, ebp
1053 mov ebp, edx 1054 mov ebp, edx
1054 rol ebx, 1 1055 rol ecx, 1
1055 or ebp, edi 1056 or ebp, edi
1056 mov DWORD PTR 16[esp],ebx 1057 mov DWORD PTR 16[esp],ecx
1057 and ebp, esi 1058 and ebp, esi
1058 lea ebx, DWORD PTR 2400959708[eax*1+ebx] 1059 lea ecx, DWORD PTR 2400959708[eax*1+ecx]
1059 mov eax, edx 1060 mov eax, edx
1060 ror edx, 1 1061 ror edx, 1
1061 and eax, edi 1062 and eax, edi
1062 or ebp, eax 1063 or ebp, eax
1063 mov eax, ecx 1064 mov eax, ebx
1064 rol eax, 5 1065 rol eax, 5
1065 add ebp, eax 1066 add ebp, eax
1066 mov eax, DWORD PTR 20[esp] 1067 mov eax, DWORD PTR 20[esp]
1067 add ebx, ebp 1068 add ecx, ebp
1068 mov ebp, DWORD PTR 28[esp] 1069 mov ebp, DWORD PTR 28[esp]
1069 xor eax, ebp 1070 xor eax, ebp
1070 mov ebp, DWORD PTR 52[esp] 1071 mov ebp, DWORD PTR 52[esp]
@@ -1073,19 +1074,19 @@ L000start:
1073 ror edx, 1 1074 ror edx, 1
1074 xor eax, ebp 1075 xor eax, ebp
1075 rol eax, 1 1076 rol eax, 1
1076 mov ebp, ecx 1077 mov ebp, ebx
1077 mov DWORD PTR 20[esp],eax 1078 mov DWORD PTR 20[esp],eax
1078 or ebp, edx 1079 or ebp, edx
1079 lea eax, DWORD PTR 2400959708[esi*1+eax] 1080 lea eax, DWORD PTR 2400959708[esi*1+eax]
1080 mov esi, ecx 1081 mov esi, ebx
1081 and ebp, edi 1082 and ebp, edi
1082 and esi, edx 1083 and esi, edx
1083 or ebp, esi 1084 or ebp, esi
1084 mov esi, ebx 1085 mov esi, ecx
1085 rol esi, 5 1086 rol esi, 5
1086 ror ecx, 1 1087 ror ebx, 1
1087 add ebp, esi 1088 add ebp, esi
1088 ror ecx, 1 1089 ror ebx, 1
1089 add eax, ebp 1090 add eax, ebp
1090 ; 40_59 53 1091 ; 40_59 53
1091 ; 40_59 54 1092 ; 40_59 54
@@ -1096,15 +1097,15 @@ L000start:
1096 xor esi, ebp 1097 xor esi, ebp
1097 mov ebp, DWORD PTR 12[esp] 1098 mov ebp, DWORD PTR 12[esp]
1098 xor esi, ebp 1099 xor esi, ebp
1099 mov ebp, ebx 1100 mov ebp, ecx
1100 rol esi, 1 1101 rol esi, 1
1101 or ebp, ecx 1102 or ebp, ebx
1102 mov DWORD PTR 24[esp],esi 1103 mov DWORD PTR 24[esp],esi
1103 and ebp, edx 1104 and ebp, edx
1104 lea esi, DWORD PTR 2400959708[edi*1+esi] 1105 lea esi, DWORD PTR 2400959708[edi*1+esi]
1105 mov edi, ebx 1106 mov edi, ecx
1106 ror ebx, 1 1107 ror ecx, 1
1107 and edi, ecx 1108 and edi, ebx
1108 or ebp, edi 1109 or ebp, edi
1109 mov edi, eax 1110 mov edi, eax
1110 rol edi, 5 1111 rol edi, 5
@@ -1116,16 +1117,16 @@ L000start:
1116 mov ebp, DWORD PTR 60[esp] 1117 mov ebp, DWORD PTR 60[esp]
1117 xor edi, ebp 1118 xor edi, ebp
1118 mov ebp, DWORD PTR 16[esp] 1119 mov ebp, DWORD PTR 16[esp]
1119 ror ebx, 1 1120 ror ecx, 1
1120 xor edi, ebp 1121 xor edi, ebp
1121 rol edi, 1 1122 rol edi, 1
1122 mov ebp, eax 1123 mov ebp, eax
1123 mov DWORD PTR 28[esp],edi 1124 mov DWORD PTR 28[esp],edi
1124 or ebp, ebx 1125 or ebp, ecx
1125 lea edi, DWORD PTR 2400959708[edx*1+edi] 1126 lea edi, DWORD PTR 2400959708[edx*1+edi]
1126 mov edx, eax 1127 mov edx, eax
1127 and ebp, ecx 1128 and ebp, ebx
1128 and edx, ebx 1129 and edx, ecx
1129 or ebp, edx 1130 or ebp, edx
1130 mov edx, esi 1131 mov edx, esi
1131 rol edx, 5 1132 rol edx, 5
@@ -1146,63 +1147,63 @@ L000start:
1146 rol edx, 1 1147 rol edx, 1
1147 or ebp, eax 1148 or ebp, eax
1148 mov DWORD PTR 32[esp],edx 1149 mov DWORD PTR 32[esp],edx
1149 and ebp, ebx 1150 and ebp, ecx
1150 lea edx, DWORD PTR 2400959708[ecx*1+edx] 1151 lea edx, DWORD PTR 2400959708[ebx*1+edx]
1151 mov ecx, esi 1152 mov ebx, esi
1152 ror esi, 1 1153 ror esi, 1
1153 and ecx, eax 1154 and ebx, eax
1154 or ebp, ecx 1155 or ebp, ebx
1155 mov ecx, edi 1156 mov ebx, edi
1156 rol ecx, 5 1157 rol ebx, 5
1157 add ebp, ecx 1158 add ebp, ebx
1158 mov ecx, DWORD PTR 36[esp] 1159 mov ebx, DWORD PTR 36[esp]
1159 add edx, ebp 1160 add edx, ebp
1160 mov ebp, DWORD PTR 44[esp] 1161 mov ebp, DWORD PTR 44[esp]
1161 xor ecx, ebp 1162 xor ebx, ebp
1162 mov ebp, DWORD PTR 4[esp] 1163 mov ebp, DWORD PTR 4[esp]
1163 xor ecx, ebp 1164 xor ebx, ebp
1164 mov ebp, DWORD PTR 24[esp] 1165 mov ebp, DWORD PTR 24[esp]
1165 ror esi, 1 1166 ror esi, 1
1166 xor ecx, ebp 1167 xor ebx, ebp
1167 rol ecx, 1 1168 rol ebx, 1
1168 mov ebp, edi 1169 mov ebp, edi
1169 mov DWORD PTR 36[esp],ecx 1170 mov DWORD PTR 36[esp],ebx
1170 or ebp, esi 1171 or ebp, esi
1171 lea ecx, DWORD PTR 2400959708[ebx*1+ecx] 1172 lea ebx, DWORD PTR 2400959708[ecx*1+ebx]
1172 mov ebx, edi 1173 mov ecx, edi
1173 and ebp, eax 1174 and ebp, eax
1174 and ebx, esi 1175 and ecx, esi
1175 or ebp, ebx 1176 or ebp, ecx
1176 mov ebx, edx 1177 mov ecx, edx
1177 rol ebx, 5 1178 rol ecx, 5
1178 ror edi, 1 1179 ror edi, 1
1179 add ebp, ebx 1180 add ebp, ecx
1180 ror edi, 1 1181 ror edi, 1
1181 add ecx, ebp 1182 add ebx, ebp
1182 ; 40_59 57 1183 ; 40_59 57
1183 ; 40_59 58 1184 ; 40_59 58
1184 mov ebx, DWORD PTR 40[esp] 1185 mov ecx, DWORD PTR 40[esp]
1185 mov ebp, DWORD PTR 48[esp] 1186 mov ebp, DWORD PTR 48[esp]
1186 xor ebx, ebp 1187 xor ecx, ebp
1187 mov ebp, DWORD PTR 8[esp] 1188 mov ebp, DWORD PTR 8[esp]
1188 xor ebx, ebp 1189 xor ecx, ebp
1189 mov ebp, DWORD PTR 28[esp] 1190 mov ebp, DWORD PTR 28[esp]
1190 xor ebx, ebp 1191 xor ecx, ebp
1191 mov ebp, edx 1192 mov ebp, edx
1192 rol ebx, 1 1193 rol ecx, 1
1193 or ebp, edi 1194 or ebp, edi
1194 mov DWORD PTR 40[esp],ebx 1195 mov DWORD PTR 40[esp],ecx
1195 and ebp, esi 1196 and ebp, esi
1196 lea ebx, DWORD PTR 2400959708[eax*1+ebx] 1197 lea ecx, DWORD PTR 2400959708[eax*1+ecx]
1197 mov eax, edx 1198 mov eax, edx
1198 ror edx, 1 1199 ror edx, 1
1199 and eax, edi 1200 and eax, edi
1200 or ebp, eax 1201 or ebp, eax
1201 mov eax, ecx 1202 mov eax, ebx
1202 rol eax, 5 1203 rol eax, 5
1203 add ebp, eax 1204 add ebp, eax
1204 mov eax, DWORD PTR 44[esp] 1205 mov eax, DWORD PTR 44[esp]
1205 add ebx, ebp 1206 add ecx, ebp
1206 mov ebp, DWORD PTR 52[esp] 1207 mov ebp, DWORD PTR 52[esp]
1207 xor eax, ebp 1208 xor eax, ebp
1208 mov ebp, DWORD PTR 12[esp] 1209 mov ebp, DWORD PTR 12[esp]
@@ -1211,19 +1212,19 @@ L000start:
1211 ror edx, 1 1212 ror edx, 1
1212 xor eax, ebp 1213 xor eax, ebp
1213 rol eax, 1 1214 rol eax, 1
1214 mov ebp, ecx 1215 mov ebp, ebx
1215 mov DWORD PTR 44[esp],eax 1216 mov DWORD PTR 44[esp],eax
1216 or ebp, edx 1217 or ebp, edx
1217 lea eax, DWORD PTR 2400959708[esi*1+eax] 1218 lea eax, DWORD PTR 2400959708[esi*1+eax]
1218 mov esi, ecx 1219 mov esi, ebx
1219 and ebp, edi 1220 and ebp, edi
1220 and esi, edx 1221 and esi, edx
1221 or ebp, esi 1222 or ebp, esi
1222 mov esi, ebx 1223 mov esi, ecx
1223 rol esi, 5 1224 rol esi, 5
1224 ror ecx, 1 1225 ror ebx, 1
1225 add ebp, esi 1226 add ebp, esi
1226 ror ecx, 1 1227 ror ebx, 1
1227 add eax, ebp 1228 add eax, ebp
1228 ; 40_59 59 1229 ; 40_59 59
1229 ; 20_39 60 1230 ; 20_39 60
@@ -1234,17 +1235,17 @@ L000start:
1234 xor esi, ebp 1235 xor esi, ebp
1235 mov ebp, DWORD PTR 36[esp] 1236 mov ebp, DWORD PTR 36[esp]
1236 xor esi, ebp 1237 xor esi, ebp
1237 mov ebp, ebx 1238 mov ebp, ecx
1238 rol esi, 1 1239 rol esi, 1
1239 xor ebp, ecx 1240 xor ebp, ebx
1240 mov DWORD PTR 48[esp],esi 1241 mov DWORD PTR 48[esp],esi
1241 xor ebp, edx 1242 xor ebp, edx
1242 lea esi, DWORD PTR 3395469782[edi*1+esi] 1243 lea esi, DWORD PTR 3395469782[edi*1+esi]
1243 mov edi, eax 1244 mov edi, eax
1244 rol edi, 5 1245 rol edi, 5
1245 ror ebx, 1 1246 ror ecx, 1
1246 add edi, ebp 1247 add edi, ebp
1247 ror ebx, 1 1248 ror ecx, 1
1248 add esi, edi 1249 add esi, edi
1249 ; 20_39 61 1250 ; 20_39 61
1250 mov edi, DWORD PTR 52[esp] 1251 mov edi, DWORD PTR 52[esp]
@@ -1256,9 +1257,9 @@ L000start:
1256 xor edi, ebp 1257 xor edi, ebp
1257 mov ebp, eax 1258 mov ebp, eax
1258 rol edi, 1 1259 rol edi, 1
1259 xor ebp, ebx
1260 mov DWORD PTR 52[esp],edi
1261 xor ebp, ecx 1260 xor ebp, ecx
1261 mov DWORD PTR 52[esp],edi
1262 xor ebp, ebx
1262 lea edi, DWORD PTR 3395469782[edx*1+edi] 1263 lea edi, DWORD PTR 3395469782[edx*1+edi]
1263 mov edx, esi 1264 mov edx, esi
1264 rol edx, 5 1265 rol edx, 5
@@ -1278,54 +1279,54 @@ L000start:
1278 rol edx, 1 1279 rol edx, 1
1279 xor ebp, eax 1280 xor ebp, eax
1280 mov DWORD PTR 56[esp],edx 1281 mov DWORD PTR 56[esp],edx
1281 xor ebp, ebx 1282 xor ebp, ecx
1282 lea edx, DWORD PTR 3395469782[ecx*1+edx] 1283 lea edx, DWORD PTR 3395469782[ebx*1+edx]
1283 mov ecx, edi 1284 mov ebx, edi
1284 rol ecx, 5 1285 rol ebx, 5
1285 ror esi, 1 1286 ror esi, 1
1286 add ecx, ebp 1287 add ebx, ebp
1287 ror esi, 1 1288 ror esi, 1
1288 add edx, ecx 1289 add edx, ebx
1289 ; 20_39 63 1290 ; 20_39 63
1290 mov ecx, DWORD PTR 60[esp] 1291 mov ebx, DWORD PTR 60[esp]
1291 mov ebp, DWORD PTR 4[esp] 1292 mov ebp, DWORD PTR 4[esp]
1292 xor ecx, ebp 1293 xor ebx, ebp
1293 mov ebp, DWORD PTR 28[esp] 1294 mov ebp, DWORD PTR 28[esp]
1294 xor ecx, ebp 1295 xor ebx, ebp
1295 mov ebp, DWORD PTR 48[esp] 1296 mov ebp, DWORD PTR 48[esp]
1296 xor ecx, ebp 1297 xor ebx, ebp
1297 mov ebp, edi 1298 mov ebp, edi
1298 rol ecx, 1 1299 rol ebx, 1
1299 xor ebp, esi 1300 xor ebp, esi
1300 mov DWORD PTR 60[esp],ecx 1301 mov DWORD PTR 60[esp],ebx
1301 xor ebp, eax 1302 xor ebp, eax
1302 lea ecx, DWORD PTR 3395469782[ebx*1+ecx] 1303 lea ebx, DWORD PTR 3395469782[ecx*1+ebx]
1303 mov ebx, edx 1304 mov ecx, edx
1304 rol ebx, 5 1305 rol ecx, 5
1305 ror edi, 1 1306 ror edi, 1
1306 add ebx, ebp 1307 add ecx, ebp
1307 ror edi, 1 1308 ror edi, 1
1308 add ecx, ebx 1309 add ebx, ecx
1309 ; 20_39 64 1310 ; 20_39 64
1310 mov ebx, DWORD PTR [esp] 1311 mov ecx, DWORD PTR [esp]
1311 mov ebp, DWORD PTR 8[esp] 1312 mov ebp, DWORD PTR 8[esp]
1312 xor ebx, ebp 1313 xor ecx, ebp
1313 mov ebp, DWORD PTR 32[esp] 1314 mov ebp, DWORD PTR 32[esp]
1314 xor ebx, ebp 1315 xor ecx, ebp
1315 mov ebp, DWORD PTR 52[esp] 1316 mov ebp, DWORD PTR 52[esp]
1316 xor ebx, ebp 1317 xor ecx, ebp
1317 mov ebp, edx 1318 mov ebp, edx
1318 rol ebx, 1 1319 rol ecx, 1
1319 xor ebp, edi 1320 xor ebp, edi
1320 mov DWORD PTR [esp],ebx 1321 mov DWORD PTR [esp],ecx
1321 xor ebp, esi 1322 xor ebp, esi
1322 lea ebx, DWORD PTR 3395469782[eax*1+ebx] 1323 lea ecx, DWORD PTR 3395469782[eax*1+ecx]
1323 mov eax, ecx 1324 mov eax, ebx
1324 rol eax, 5 1325 rol eax, 5
1325 ror edx, 1 1326 ror edx, 1
1326 add eax, ebp 1327 add eax, ebp
1327 ror edx, 1 1328 ror edx, 1
1328 add ebx, eax 1329 add ecx, eax
1329 ; 20_39 65 1330 ; 20_39 65
1330 mov eax, DWORD PTR 4[esp] 1331 mov eax, DWORD PTR 4[esp]
1331 mov ebp, DWORD PTR 12[esp] 1332 mov ebp, DWORD PTR 12[esp]
@@ -1334,17 +1335,17 @@ L000start:
1334 xor eax, ebp 1335 xor eax, ebp
1335 mov ebp, DWORD PTR 56[esp] 1336 mov ebp, DWORD PTR 56[esp]
1336 xor eax, ebp 1337 xor eax, ebp
1337 mov ebp, ecx 1338 mov ebp, ebx
1338 rol eax, 1 1339 rol eax, 1
1339 xor ebp, edx 1340 xor ebp, edx
1340 mov DWORD PTR 4[esp],eax 1341 mov DWORD PTR 4[esp],eax
1341 xor ebp, edi 1342 xor ebp, edi
1342 lea eax, DWORD PTR 3395469782[esi*1+eax] 1343 lea eax, DWORD PTR 3395469782[esi*1+eax]
1343 mov esi, ebx 1344 mov esi, ecx
1344 rol esi, 5 1345 rol esi, 5
1345 ror ecx, 1 1346 ror ebx, 1
1346 add esi, ebp 1347 add esi, ebp
1347 ror ecx, 1 1348 ror ebx, 1
1348 add eax, esi 1349 add eax, esi
1349 ; 20_39 66 1350 ; 20_39 66
1350 mov esi, DWORD PTR 8[esp] 1351 mov esi, DWORD PTR 8[esp]
@@ -1354,17 +1355,17 @@ L000start:
1354 xor esi, ebp 1355 xor esi, ebp
1355 mov ebp, DWORD PTR 60[esp] 1356 mov ebp, DWORD PTR 60[esp]
1356 xor esi, ebp 1357 xor esi, ebp
1357 mov ebp, ebx 1358 mov ebp, ecx
1358 rol esi, 1 1359 rol esi, 1
1359 xor ebp, ecx 1360 xor ebp, ebx
1360 mov DWORD PTR 8[esp],esi 1361 mov DWORD PTR 8[esp],esi
1361 xor ebp, edx 1362 xor ebp, edx
1362 lea esi, DWORD PTR 3395469782[edi*1+esi] 1363 lea esi, DWORD PTR 3395469782[edi*1+esi]
1363 mov edi, eax 1364 mov edi, eax
1364 rol edi, 5 1365 rol edi, 5
1365 ror ebx, 1 1366 ror ecx, 1
1366 add edi, ebp 1367 add edi, ebp
1367 ror ebx, 1 1368 ror ecx, 1
1368 add esi, edi 1369 add esi, edi
1369 ; 20_39 67 1370 ; 20_39 67
1370 mov edi, DWORD PTR 12[esp] 1371 mov edi, DWORD PTR 12[esp]
@@ -1376,9 +1377,9 @@ L000start:
1376 xor edi, ebp 1377 xor edi, ebp
1377 mov ebp, eax 1378 mov ebp, eax
1378 rol edi, 1 1379 rol edi, 1
1379 xor ebp, ebx
1380 mov DWORD PTR 12[esp],edi
1381 xor ebp, ecx 1380 xor ebp, ecx
1381 mov DWORD PTR 12[esp],edi
1382 xor ebp, ebx
1382 lea edi, DWORD PTR 3395469782[edx*1+edi] 1383 lea edi, DWORD PTR 3395469782[edx*1+edi]
1383 mov edx, esi 1384 mov edx, esi
1384 rol edx, 5 1385 rol edx, 5
@@ -1398,54 +1399,54 @@ L000start:
1398 rol edx, 1 1399 rol edx, 1
1399 xor ebp, eax 1400 xor ebp, eax
1400 mov DWORD PTR 16[esp],edx 1401 mov DWORD PTR 16[esp],edx
1401 xor ebp, ebx 1402 xor ebp, ecx
1402 lea edx, DWORD PTR 3395469782[ecx*1+edx] 1403 lea edx, DWORD PTR 3395469782[ebx*1+edx]
1403 mov ecx, edi 1404 mov ebx, edi
1404 rol ecx, 5 1405 rol ebx, 5
1405 ror esi, 1 1406 ror esi, 1
1406 add ecx, ebp 1407 add ebx, ebp
1407 ror esi, 1 1408 ror esi, 1
1408 add edx, ecx 1409 add edx, ebx
1409 ; 20_39 69 1410 ; 20_39 69
1410 mov ecx, DWORD PTR 20[esp] 1411 mov ebx, DWORD PTR 20[esp]
1411 mov ebp, DWORD PTR 28[esp] 1412 mov ebp, DWORD PTR 28[esp]
1412 xor ecx, ebp 1413 xor ebx, ebp
1413 mov ebp, DWORD PTR 52[esp] 1414 mov ebp, DWORD PTR 52[esp]
1414 xor ecx, ebp 1415 xor ebx, ebp
1415 mov ebp, DWORD PTR 8[esp] 1416 mov ebp, DWORD PTR 8[esp]
1416 xor ecx, ebp 1417 xor ebx, ebp
1417 mov ebp, edi 1418 mov ebp, edi
1418 rol ecx, 1 1419 rol ebx, 1
1419 xor ebp, esi 1420 xor ebp, esi
1420 mov DWORD PTR 20[esp],ecx 1421 mov DWORD PTR 20[esp],ebx
1421 xor ebp, eax 1422 xor ebp, eax
1422 lea ecx, DWORD PTR 3395469782[ebx*1+ecx] 1423 lea ebx, DWORD PTR 3395469782[ecx*1+ebx]
1423 mov ebx, edx 1424 mov ecx, edx
1424 rol ebx, 5 1425 rol ecx, 5
1425 ror edi, 1 1426 ror edi, 1
1426 add ebx, ebp 1427 add ecx, ebp
1427 ror edi, 1 1428 ror edi, 1
1428 add ecx, ebx 1429 add ebx, ecx
1429 ; 20_39 70 1430 ; 20_39 70
1430 mov ebx, DWORD PTR 24[esp] 1431 mov ecx, DWORD PTR 24[esp]
1431 mov ebp, DWORD PTR 32[esp] 1432 mov ebp, DWORD PTR 32[esp]
1432 xor ebx, ebp 1433 xor ecx, ebp
1433 mov ebp, DWORD PTR 56[esp] 1434 mov ebp, DWORD PTR 56[esp]
1434 xor ebx, ebp 1435 xor ecx, ebp
1435 mov ebp, DWORD PTR 12[esp] 1436 mov ebp, DWORD PTR 12[esp]
1436 xor ebx, ebp 1437 xor ecx, ebp
1437 mov ebp, edx 1438 mov ebp, edx
1438 rol ebx, 1 1439 rol ecx, 1
1439 xor ebp, edi 1440 xor ebp, edi
1440 mov DWORD PTR 24[esp],ebx 1441 mov DWORD PTR 24[esp],ecx
1441 xor ebp, esi 1442 xor ebp, esi
1442 lea ebx, DWORD PTR 3395469782[eax*1+ebx] 1443 lea ecx, DWORD PTR 3395469782[eax*1+ecx]
1443 mov eax, ecx 1444 mov eax, ebx
1444 rol eax, 5 1445 rol eax, 5
1445 ror edx, 1 1446 ror edx, 1
1446 add eax, ebp 1447 add eax, ebp
1447 ror edx, 1 1448 ror edx, 1
1448 add ebx, eax 1449 add ecx, eax
1449 ; 20_39 71 1450 ; 20_39 71
1450 mov eax, DWORD PTR 28[esp] 1451 mov eax, DWORD PTR 28[esp]
1451 mov ebp, DWORD PTR 36[esp] 1452 mov ebp, DWORD PTR 36[esp]
@@ -1454,17 +1455,17 @@ L000start:
1454 xor eax, ebp 1455 xor eax, ebp
1455 mov ebp, DWORD PTR 16[esp] 1456 mov ebp, DWORD PTR 16[esp]
1456 xor eax, ebp 1457 xor eax, ebp
1457 mov ebp, ecx 1458 mov ebp, ebx
1458 rol eax, 1 1459 rol eax, 1
1459 xor ebp, edx 1460 xor ebp, edx
1460 mov DWORD PTR 28[esp],eax 1461 mov DWORD PTR 28[esp],eax
1461 xor ebp, edi 1462 xor ebp, edi
1462 lea eax, DWORD PTR 3395469782[esi*1+eax] 1463 lea eax, DWORD PTR 3395469782[esi*1+eax]
1463 mov esi, ebx 1464 mov esi, ecx
1464 rol esi, 5 1465 rol esi, 5
1465 ror ecx, 1 1466 ror ebx, 1
1466 add esi, ebp 1467 add esi, ebp
1467 ror ecx, 1 1468 ror ebx, 1
1468 add eax, esi 1469 add eax, esi
1469 ; 20_39 72 1470 ; 20_39 72
1470 mov esi, DWORD PTR 32[esp] 1471 mov esi, DWORD PTR 32[esp]
@@ -1474,17 +1475,17 @@ L000start:
1474 xor esi, ebp 1475 xor esi, ebp
1475 mov ebp, DWORD PTR 20[esp] 1476 mov ebp, DWORD PTR 20[esp]
1476 xor esi, ebp 1477 xor esi, ebp
1477 mov ebp, ebx 1478 mov ebp, ecx
1478 rol esi, 1 1479 rol esi, 1
1479 xor ebp, ecx 1480 xor ebp, ebx
1480 mov DWORD PTR 32[esp],esi 1481 mov DWORD PTR 32[esp],esi
1481 xor ebp, edx 1482 xor ebp, edx
1482 lea esi, DWORD PTR 3395469782[edi*1+esi] 1483 lea esi, DWORD PTR 3395469782[edi*1+esi]
1483 mov edi, eax 1484 mov edi, eax
1484 rol edi, 5 1485 rol edi, 5
1485 ror ebx, 1 1486 ror ecx, 1
1486 add edi, ebp 1487 add edi, ebp
1487 ror ebx, 1 1488 ror ecx, 1
1488 add esi, edi 1489 add esi, edi
1489 ; 20_39 73 1490 ; 20_39 73
1490 mov edi, DWORD PTR 36[esp] 1491 mov edi, DWORD PTR 36[esp]
@@ -1496,9 +1497,9 @@ L000start:
1496 xor edi, ebp 1497 xor edi, ebp
1497 mov ebp, eax 1498 mov ebp, eax
1498 rol edi, 1 1499 rol edi, 1
1499 xor ebp, ebx
1500 mov DWORD PTR 36[esp],edi
1501 xor ebp, ecx 1500 xor ebp, ecx
1501 mov DWORD PTR 36[esp],edi
1502 xor ebp, ebx
1502 lea edi, DWORD PTR 3395469782[edx*1+edi] 1503 lea edi, DWORD PTR 3395469782[edx*1+edi]
1503 mov edx, esi 1504 mov edx, esi
1504 rol edx, 5 1505 rol edx, 5
@@ -1518,54 +1519,54 @@ L000start:
1518 rol edx, 1 1519 rol edx, 1
1519 xor ebp, eax 1520 xor ebp, eax
1520 mov DWORD PTR 40[esp],edx 1521 mov DWORD PTR 40[esp],edx
1521 xor ebp, ebx 1522 xor ebp, ecx
1522 lea edx, DWORD PTR 3395469782[ecx*1+edx] 1523 lea edx, DWORD PTR 3395469782[ebx*1+edx]
1523 mov ecx, edi 1524 mov ebx, edi
1524 rol ecx, 5 1525 rol ebx, 5
1525 ror esi, 1 1526 ror esi, 1
1526 add ecx, ebp 1527 add ebx, ebp
1527 ror esi, 1 1528 ror esi, 1
1528 add edx, ecx 1529 add edx, ebx
1529 ; 20_39 75 1530 ; 20_39 75
1530 mov ecx, DWORD PTR 44[esp] 1531 mov ebx, DWORD PTR 44[esp]
1531 mov ebp, DWORD PTR 52[esp] 1532 mov ebp, DWORD PTR 52[esp]
1532 xor ecx, ebp 1533 xor ebx, ebp
1533 mov ebp, DWORD PTR 12[esp] 1534 mov ebp, DWORD PTR 12[esp]
1534 xor ecx, ebp 1535 xor ebx, ebp
1535 mov ebp, DWORD PTR 32[esp] 1536 mov ebp, DWORD PTR 32[esp]
1536 xor ecx, ebp 1537 xor ebx, ebp
1537 mov ebp, edi 1538 mov ebp, edi
1538 rol ecx, 1 1539 rol ebx, 1
1539 xor ebp, esi 1540 xor ebp, esi
1540 mov DWORD PTR 44[esp],ecx 1541 mov DWORD PTR 44[esp],ebx
1541 xor ebp, eax 1542 xor ebp, eax
1542 lea ecx, DWORD PTR 3395469782[ebx*1+ecx] 1543 lea ebx, DWORD PTR 3395469782[ecx*1+ebx]
1543 mov ebx, edx 1544 mov ecx, edx
1544 rol ebx, 5 1545 rol ecx, 5
1545 ror edi, 1 1546 ror edi, 1
1546 add ebx, ebp 1547 add ecx, ebp
1547 ror edi, 1 1548 ror edi, 1
1548 add ecx, ebx 1549 add ebx, ecx
1549 ; 20_39 76 1550 ; 20_39 76
1550 mov ebx, DWORD PTR 48[esp] 1551 mov ecx, DWORD PTR 48[esp]
1551 mov ebp, DWORD PTR 56[esp] 1552 mov ebp, DWORD PTR 56[esp]
1552 xor ebx, ebp 1553 xor ecx, ebp
1553 mov ebp, DWORD PTR 16[esp] 1554 mov ebp, DWORD PTR 16[esp]
1554 xor ebx, ebp 1555 xor ecx, ebp
1555 mov ebp, DWORD PTR 36[esp] 1556 mov ebp, DWORD PTR 36[esp]
1556 xor ebx, ebp 1557 xor ecx, ebp
1557 mov ebp, edx 1558 mov ebp, edx
1558 rol ebx, 1 1559 rol ecx, 1
1559 xor ebp, edi 1560 xor ebp, edi
1560 mov DWORD PTR 48[esp],ebx 1561 mov DWORD PTR 48[esp],ecx
1561 xor ebp, esi 1562 xor ebp, esi
1562 lea ebx, DWORD PTR 3395469782[eax*1+ebx] 1563 lea ecx, DWORD PTR 3395469782[eax*1+ecx]
1563 mov eax, ecx 1564 mov eax, ebx
1564 rol eax, 5 1565 rol eax, 5
1565 ror edx, 1 1566 ror edx, 1
1566 add eax, ebp 1567 add eax, ebp
1567 ror edx, 1 1568 ror edx, 1
1568 add ebx, eax 1569 add ecx, eax
1569 ; 20_39 77 1570 ; 20_39 77
1570 mov eax, DWORD PTR 52[esp] 1571 mov eax, DWORD PTR 52[esp]
1571 mov ebp, DWORD PTR 60[esp] 1572 mov ebp, DWORD PTR 60[esp]
@@ -1574,17 +1575,17 @@ L000start:
1574 xor eax, ebp 1575 xor eax, ebp
1575 mov ebp, DWORD PTR 40[esp] 1576 mov ebp, DWORD PTR 40[esp]
1576 xor eax, ebp 1577 xor eax, ebp
1577 mov ebp, ecx 1578 mov ebp, ebx
1578 rol eax, 1 1579 rol eax, 1
1579 xor ebp, edx 1580 xor ebp, edx
1580 mov DWORD PTR 52[esp],eax 1581 mov DWORD PTR 52[esp],eax
1581 xor ebp, edi 1582 xor ebp, edi
1582 lea eax, DWORD PTR 3395469782[esi*1+eax] 1583 lea eax, DWORD PTR 3395469782[esi*1+eax]
1583 mov esi, ebx 1584 mov esi, ecx
1584 rol esi, 5 1585 rol esi, 5
1585 ror ecx, 1 1586 ror ebx, 1
1586 add esi, ebp 1587 add esi, ebp
1587 ror ecx, 1 1588 ror ebx, 1
1588 add eax, esi 1589 add eax, esi
1589 ; 20_39 78 1590 ; 20_39 78
1590 mov esi, DWORD PTR 56[esp] 1591 mov esi, DWORD PTR 56[esp]
@@ -1594,17 +1595,17 @@ L000start:
1594 xor esi, ebp 1595 xor esi, ebp
1595 mov ebp, DWORD PTR 44[esp] 1596 mov ebp, DWORD PTR 44[esp]
1596 xor esi, ebp 1597 xor esi, ebp
1597 mov ebp, ebx 1598 mov ebp, ecx
1598 rol esi, 1 1599 rol esi, 1
1599 xor ebp, ecx 1600 xor ebp, ebx
1600 mov DWORD PTR 56[esp],esi 1601 mov DWORD PTR 56[esp],esi
1601 xor ebp, edx 1602 xor ebp, edx
1602 lea esi, DWORD PTR 3395469782[edi*1+esi] 1603 lea esi, DWORD PTR 3395469782[edi*1+esi]
1603 mov edi, eax 1604 mov edi, eax
1604 rol edi, 5 1605 rol edi, 5
1605 ror ebx, 1 1606 ror ecx, 1
1606 add edi, ebp 1607 add edi, ebp
1607 ror ebx, 1 1608 ror ecx, 1
1608 add esi, edi 1609 add esi, edi
1609 ; 20_39 79 1610 ; 20_39 79
1610 mov edi, DWORD PTR 60[esp] 1611 mov edi, DWORD PTR 60[esp]
@@ -1616,49 +1617,100 @@ L000start:
1616 xor edi, ebp 1617 xor edi, ebp
1617 mov ebp, eax 1618 mov ebp, eax
1618 rol edi, 1 1619 rol edi, 1
1619 xor ebp, ebx
1620 mov DWORD PTR 60[esp],edi
1621 xor ebp, ecx 1620 xor ebp, ecx
1621 mov DWORD PTR 60[esp],edi
1622 xor ebp, ebx
1622 lea edi, DWORD PTR 3395469782[edx*1+edi] 1623 lea edi, DWORD PTR 3395469782[edx*1+edi]
1623 mov edx, esi 1624 mov edx, esi
1624 rol edx, 5 1625 rol edx, 5
1625 add edx, ebp 1626 add edx, ebp
1626 mov ebp, DWORD PTR 92[esp] 1627 mov ebp, DWORD PTR 128[esp]
1627 ror eax, 1 1628 ror eax, 1
1628 add edi, edx 1629 add edi, edx
1629 ror eax, 1 1630 ror eax, 1
1630 ; End processing 1631 ; End processing
1631 ; 1632 ;
1632 mov edx, DWORD PTR 12[ebp] 1633 mov edx, DWORD PTR 12[ebp]
1633 add edx, ebx 1634 add edx, ecx
1634 mov ebx, DWORD PTR 4[ebp] 1635 mov ecx, DWORD PTR 4[ebp]
1635 add ebx, esi 1636 add ecx, esi
1636 mov esi, eax 1637 mov esi, eax
1637 mov eax, DWORD PTR [ebp] 1638 mov eax, DWORD PTR [ebp]
1638 mov DWORD PTR 12[ebp],edx 1639 mov DWORD PTR 12[ebp],edx
1639 add eax, edi 1640 add eax, edi
1640 mov edi, DWORD PTR 16[ebp] 1641 mov edi, DWORD PTR 16[ebp]
1641 add edi, ecx 1642 add edi, ebx
1642 mov ecx, DWORD PTR 8[ebp] 1643 mov ebx, DWORD PTR 8[ebp]
1643 add ecx, esi 1644 add ebx, esi
1644 mov DWORD PTR [ebp],eax 1645 mov DWORD PTR [ebp],eax
1645 mov esi, DWORD PTR 64[esp] 1646 mov esi, DWORD PTR 132[esp]
1646 mov DWORD PTR 8[ebp],ecx 1647 mov DWORD PTR 8[ebp],ebx
1647 add esi, 64 1648 add esi, 64
1648 mov eax, DWORD PTR 68[esp] 1649 mov eax, DWORD PTR 68[esp]
1649 mov DWORD PTR 16[ebp],edi 1650 mov DWORD PTR 16[ebp],edi
1650 cmp eax, esi 1651 cmp esi, eax
1651 mov DWORD PTR 4[ebp],ebx 1652 mov DWORD PTR 4[ebp],ecx
1652 jl $L001end 1653 jl L000start
1653 mov eax, DWORD PTR [esi] 1654 add esp, 108
1654 jmp L000start
1655$L001end:
1656 add esp, 72
1657 pop edi 1655 pop edi
1658 pop ebx 1656 pop ebx
1659 pop ebp 1657 pop ebp
1660 pop esi 1658 pop esi
1661 ret 1659 ret
1662_sha1_block_x86 ENDP 1660_TEXT SEGMENT
1661PUBLIC _sha1_block_asm_host_order
1662
1663_sha1_block_asm_host_order PROC NEAR
1664 mov ecx, DWORD PTR 12[esp]
1665 push esi
1666 shl ecx, 6
1667 mov esi, DWORD PTR 12[esp]
1668 push ebp
1669 add ecx, esi
1670 push ebx
1671 mov ebp, DWORD PTR 16[esp]
1672 push edi
1673 mov edx, DWORD PTR 12[ebp]
1674 sub esp, 108
1675 mov edi, DWORD PTR 16[ebp]
1676 mov ebx, DWORD PTR 8[ebp]
1677 mov DWORD PTR 68[esp],ecx
1678 ; First we need to setup the X array
1679 mov eax, DWORD PTR [esi]
1680 mov ecx, DWORD PTR 4[esi]
1681 mov DWORD PTR [esp],eax
1682 mov DWORD PTR 4[esp],ecx
1683 mov eax, DWORD PTR 8[esi]
1684 mov ecx, DWORD PTR 12[esi]
1685 mov DWORD PTR 8[esp],eax
1686 mov DWORD PTR 12[esp],ecx
1687 mov eax, DWORD PTR 16[esi]
1688 mov ecx, DWORD PTR 20[esi]
1689 mov DWORD PTR 16[esp],eax
1690 mov DWORD PTR 20[esp],ecx
1691 mov eax, DWORD PTR 24[esi]
1692 mov ecx, DWORD PTR 28[esi]
1693 mov DWORD PTR 24[esp],eax
1694 mov DWORD PTR 28[esp],ecx
1695 mov eax, DWORD PTR 32[esi]
1696 mov ecx, DWORD PTR 36[esi]
1697 mov DWORD PTR 32[esp],eax
1698 mov DWORD PTR 36[esp],ecx
1699 mov eax, DWORD PTR 40[esi]
1700 mov ecx, DWORD PTR 44[esi]
1701 mov DWORD PTR 40[esp],eax
1702 mov DWORD PTR 44[esp],ecx
1703 mov eax, DWORD PTR 48[esi]
1704 mov ecx, DWORD PTR 52[esi]
1705 mov DWORD PTR 48[esp],eax
1706 mov DWORD PTR 52[esp],ecx
1707 mov eax, DWORD PTR 56[esi]
1708 mov ecx, DWORD PTR 60[esi]
1709 mov DWORD PTR 56[esp],eax
1710 mov DWORD PTR 60[esp],ecx
1711 jmp L001shortcut
1712_sha1_block_asm_host_order ENDP
1713_TEXT ENDS
1714_sha1_block_asm_data_order ENDP
1663_TEXT ENDS 1715_TEXT ENDS
1664END 1716END
diff --git a/src/lib/libcrypto/sha/asm/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl
index 04e42ab09f..48d9192a4e 100644
--- a/src/lib/libcrypto/sha/asm/sha1-586.pl
+++ b/src/lib/libcrypto/sha/asm/sha1-586.pl
@@ -8,8 +8,8 @@ require "x86asm.pl";
8&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386"); 8&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386");
9 9
10$A="eax"; 10$A="eax";
11$B="ebx"; 11$B="ecx";
12$C="ecx"; 12$C="ebx";
13$D="edx"; 13$D="edx";
14$E="edi"; 14$E="edi";
15$T="esi"; 15$T="esi";
@@ -19,7 +19,7 @@ $off=9*4;
19 19
20@K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6); 20@K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6);
21 21
22&sha1_block("sha1_block_x86"); 22&sha1_block_data("sha1_block_asm_data_order");
23 23
24&asm_finish(); 24&asm_finish();
25 25
@@ -53,11 +53,14 @@ sub X_expand
53 local($in)=@_; 53 local($in)=@_;
54 54
55 &comment("First, load the words onto the stack in network byte order"); 55 &comment("First, load the words onto the stack in network byte order");
56 for ($i=0; $i<16; $i++) 56 for ($i=0; $i<16; $i+=2)
57 { 57 {
58 &mov("eax",&DWP(($i+0)*4,$in,"",0)) unless $i == 0; 58 &mov($A,&DWP(($i+0)*4,$in,"",0));# unless $i == 0;
59 &bswap("eax"); 59 &mov($B,&DWP(($i+1)*4,$in,"",0));
60 &mov(&swtmp($i+0),"eax"); 60 &bswap($A);
61 &bswap($B);
62 &mov(&swtmp($i+0),$A);
63 &mov(&swtmp($i+1),$B);
61 } 64 }
62 65
63 &comment("We now have the X array on the stack"); 66 &comment("We now have the X array on the stack");
@@ -312,7 +315,7 @@ sub BODY_60_79
312 &BODY_20_39(@_); 315 &BODY_20_39(@_);
313 } 316 }
314 317
315sub sha1_block 318sub sha1_block_host
316 { 319 {
317 local($name)=@_; 320 local($name)=@_;
318 321
@@ -325,35 +328,77 @@ sub sha1_block
325 # D 12 328 # D 12
326 # E 16 329 # E 16
327 330
328 &push("esi"); 331 &mov("ecx", &wparam(2));
329 &push("ebp"); 332 &push("esi");
330 &mov("eax", &wparam(2)); 333 &shl("ecx",6);
331 &mov("esi", &wparam(1)); 334 &mov("esi", &wparam(1));
332 &add("eax", "esi"); # offset to leave on 335 &push("ebp");
336 &add("ecx","esi"); # offset to leave on
337 &push("ebx");
333 &mov("ebp", &wparam(0)); 338 &mov("ebp", &wparam(0));
339 &push("edi");
340 &mov($D, &DWP(12,"ebp","",0));
341 &stack_push(18+9);
342 &mov($E, &DWP(16,"ebp","",0));
343 &mov($C, &DWP( 8,"ebp","",0));
344 &mov(&swtmp(17),"ecx");
345
346 &comment("First we need to setup the X array");
347
348 for ($i=0; $i<16; $i+=2)
349 {
350 &mov($A,&DWP(($i+0)*4,"esi","",0));# unless $i == 0;
351 &mov($B,&DWP(($i+1)*4,"esi","",0));
352 &mov(&swtmp($i+0),$A);
353 &mov(&swtmp($i+1),$B);
354 }
355 &jmp(&label("shortcut"));
356 &function_end_B($name);
357 }
358
359
360sub sha1_block_data
361 {
362 local($name)=@_;
363
364 &function_begin_B($name,"");
365
366 # parameter 1 is the MD5_CTX structure.
367 # A 0
368 # B 4
369 # C 8
370 # D 12
371 # E 16
372
373 &mov("ecx", &wparam(2));
374 &push("esi");
375 &shl("ecx",6);
376 &mov("esi", &wparam(1));
377 &push("ebp");
378 &add("ecx","esi"); # offset to leave on
334 &push("ebx"); 379 &push("ebx");
335 &sub("eax", 64); 380 &mov("ebp", &wparam(0));
336 &push("edi"); 381 &push("edi");
337 &mov($B, &DWP( 4,"ebp","",0));
338 &stack_push(18);
339 &mov($D, &DWP(12,"ebp","",0)); 382 &mov($D, &DWP(12,"ebp","",0));
340 &mov($E, &DWP(16,"ebp","",0)); 383 &stack_push(18+9);
341 &mov($C, &DWP( 8,"ebp","",0)); 384 &mov($E, &DWP(16,"ebp","",0));
342 &mov(&swtmp(17),"eax"); 385 &mov($C, &DWP( 8,"ebp","",0));
386 &mov(&swtmp(17),"ecx");
343 387
344 &comment("First we need to setup the X array"); 388 &comment("First we need to setup the X array");
345 &mov("eax",&DWP(0,"esi","",0)); # pulled out of X_expand
346 389
347 &set_label("start") unless $normal; 390 &set_label("start") unless $normal;
348 391
349 &X_expand("esi"); 392 &X_expand("esi");
350 &mov(&swtmp(16),"esi"); 393 &mov(&wparam(1),"esi");
351 394
395 &set_label("shortcut", 1);
352 &comment(""); 396 &comment("");
353 &comment("Start processing"); 397 &comment("Start processing");
354 398
355 # odd start 399 # odd start
356 &mov($A, &DWP( 0,"ebp","",0)); 400 &mov($A, &DWP( 0,"ebp","",0));
401 &mov($B, &DWP( 4,"ebp","",0));
357 $X="esp"; 402 $X="esp";
358 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T); 403 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T);
359 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E); 404 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E);
@@ -468,24 +513,26 @@ sub sha1_block
468 &add($C,$T); 513 &add($C,$T);
469 514
470 &mov(&DWP( 0,$tmp1,"",0),$A); 515 &mov(&DWP( 0,$tmp1,"",0),$A);
471 &mov("esi",&swtmp(16)); 516 &mov("esi",&wparam(1));
472 &mov(&DWP( 8,$tmp1,"",0),$C); # This is for looping 517 &mov(&DWP( 8,$tmp1,"",0),$C);
473 &add("esi",64); 518 &add("esi",64);
474 &mov("eax",&swtmp(17)); 519 &mov("eax",&swtmp(17));
475 &mov(&DWP(16,$tmp1,"",0),$E); 520 &mov(&DWP(16,$tmp1,"",0),$E);
476 &cmp("eax","esi"); 521 &cmp("esi","eax");
477 &mov(&DWP( 4,$tmp1,"",0),$B); # This is for looping 522 &mov(&DWP( 4,$tmp1,"",0),$B);
478 &jl(&label("end")); 523 &jl(&label("start"));
479 &mov("eax",&DWP(0,"esi","",0)); # Pulled down from 524
480 &jmp(&label("start")); 525 &stack_pop(18+9);
481
482 &set_label("end");
483 &stack_pop(18);
484 &pop("edi"); 526 &pop("edi");
485 &pop("ebx"); 527 &pop("ebx");
486 &pop("ebp"); 528 &pop("ebp");
487 &pop("esi"); 529 &pop("esi");
488 &ret(); 530 &ret();
531
532 # it has to reside within sha1_block_asm_host_order body
533 # because it calls &jmp(&label("shortcut"));
534 &sha1_block_host("sha1_block_asm_host_order");
535
489 &function_end_B($name); 536 &function_end_B($name);
490 } 537 }
491 538
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h
index cd6960ee1a..77f6d9695e 100644
--- a/src/lib/libcrypto/sha/sha.h
+++ b/src/lib/libcrypto/sha/sha.h
@@ -63,7 +63,7 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifdef NO_SHA 66#if defined(NO_SHA) || (defined(NO_SHA0) && defined(NO_SHA1))
67#error SHA is disabled. 67#error SHA is disabled.
68#endif 68#endif
69 69
@@ -100,17 +100,17 @@ typedef struct SHAstate_st
100 100
101#ifndef NO_SHA0 101#ifndef NO_SHA0
102void SHA_Init(SHA_CTX *c); 102void SHA_Init(SHA_CTX *c);
103void SHA_Update(SHA_CTX *c, const unsigned char *data, unsigned long len); 103void SHA_Update(SHA_CTX *c, const void *data, unsigned long len);
104void SHA_Final(unsigned char *md, SHA_CTX *c); 104void SHA_Final(unsigned char *md, SHA_CTX *c);
105unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md); 105unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md);
106void SHA_Transform(SHA_CTX *c, unsigned char *data); 106void SHA_Transform(SHA_CTX *c, const unsigned char *data);
107#endif 107#endif
108#ifndef NO_SHA1 108#ifndef NO_SHA1
109void SHA1_Init(SHA_CTX *c); 109void SHA1_Init(SHA_CTX *c);
110void SHA1_Update(SHA_CTX *c, const unsigned char *data, unsigned long len); 110void SHA1_Update(SHA_CTX *c, const void *data, unsigned long len);
111void SHA1_Final(unsigned char *md, SHA_CTX *c); 111void SHA1_Final(unsigned char *md, SHA_CTX *c);
112unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md); 112unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md);
113void SHA1_Transform(SHA_CTX *c, unsigned char *data); 113void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
114#endif 114#endif
115#ifdef __cplusplus 115#ifdef __cplusplus
116} 116}
diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c
index 66e885dd76..c09edb4cd7 100644
--- a/src/lib/libcrypto/sha/sha1dgst.c
+++ b/src/lib/libcrypto/sha/sha1dgst.c
@@ -56,443 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <stdio.h> 59#if !defined(NO_SHA1) && !defined(NO_SHA)
60#include <string.h> 60
61#undef SHA_0 61#undef SHA_0
62#define SHA_1 62#define SHA_1
63#include <openssl/sha.h>
64#include "sha_locl.h"
65#include <openssl/opensslv.h>
66
67#ifndef NO_SHA1
68char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
69
70/* Implemented from SHA-1 document - The Secure Hash Algorithm
71 */
72
73#define INIT_DATA_h0 0x67452301UL
74#define INIT_DATA_h1 0xefcdab89UL
75#define INIT_DATA_h2 0x98badcfeUL
76#define INIT_DATA_h3 0x10325476UL
77#define INIT_DATA_h4 0xc3d2e1f0UL
78
79#define K_00_19 0x5a827999UL
80#define K_20_39 0x6ed9eba1UL
81#define K_40_59 0x8f1bbcdcUL
82#define K_60_79 0xca62c1d6UL
83
84#ifdef SHA1_ASM
85 void sha1_block_x86(SHA_CTX *c, register SHA_LONG *p, int num);
86# define sha1_block(c,p,n) sha1_block_x86((c),(p),(n)*SHA_CBLOCK)
87#else
88 static void sha1_block(SHA_CTX *c, register SHA_LONG *p, int num);
89#endif
90
91#if !defined(B_ENDIAN) && defined(SHA1_ASM)
92# define M_c2nl c2l
93# define M_p_c2nl p_c2l
94# define M_c2nl_p c2l_p
95# define M_p_c2nl_p p_c2l_p
96# define M_nl2c l2c
97#else
98# define M_c2nl c2nl
99# define M_p_c2nl p_c2nl
100# define M_c2nl_p c2nl_p
101# define M_p_c2nl_p p_c2nl_p
102# define M_nl2c nl2c
103#endif
104
105void SHA1_Init(SHA_CTX *c)
106 {
107 c->h0=INIT_DATA_h0;
108 c->h1=INIT_DATA_h1;
109 c->h2=INIT_DATA_h2;
110 c->h3=INIT_DATA_h3;
111 c->h4=INIT_DATA_h4;
112 c->Nl=0;
113 c->Nh=0;
114 c->num=0;
115 }
116
117void SHA1_Update(SHA_CTX *c, register const unsigned char *data,
118 unsigned long len)
119 {
120 register SHA_LONG *p;
121 int ew,ec,sw,sc;
122 SHA_LONG l;
123
124 if (len == 0) return;
125
126 l=(c->Nl+(len<<3))&0xffffffffL;
127 if (l < c->Nl) /* overflow */
128 c->Nh++;
129 c->Nh+=(len>>29);
130 c->Nl=l;
131
132 if (c->num != 0)
133 {
134 p=c->data;
135 sw=c->num>>2;
136 sc=c->num&0x03;
137
138 if ((c->num+len) >= SHA_CBLOCK)
139 {
140 l= p[sw];
141 M_p_c2nl(data,l,sc);
142 p[sw++]=l;
143 for (; sw<SHA_LBLOCK; sw++)
144 {
145 M_c2nl(data,l);
146 p[sw]=l;
147 }
148 len-=(SHA_CBLOCK-c->num);
149
150 sha1_block(c,p,1);
151 c->num=0;
152 /* drop through and do the rest */
153 }
154 else
155 {
156 c->num+=(int)len;
157 if ((sc+len) < 4) /* ugly, add char's to a word */
158 {
159 l= p[sw];
160 M_p_c2nl_p(data,l,sc,len);
161 p[sw]=l;
162 }
163 else
164 {
165 ew=(c->num>>2);
166 ec=(c->num&0x03);
167 l= p[sw];
168 M_p_c2nl(data,l,sc);
169 p[sw++]=l;
170 for (; sw < ew; sw++)
171 { M_c2nl(data,l); p[sw]=l; }
172 if (ec)
173 {
174 M_c2nl_p(data,l,ec);
175 p[sw]=l;
176 }
177 }
178 return;
179 }
180 }
181 /* We can only do the following code for assember, the reason
182 * being that the sha1_block 'C' version changes the values
183 * in the 'data' array. The assember code avoids this and
184 * copies it to a local array. I should be able to do this for
185 * the C version as well....
186 */
187#if SHA_LONG_LOG2==2
188#if defined(B_ENDIAN) || defined(SHA1_ASM)
189 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
190 {
191 sw=len/SHA_CBLOCK;
192 if (sw)
193 {
194 sha1_block(c,(SHA_LONG *)data,sw);
195 sw*=SHA_CBLOCK;
196 data+=sw;
197 len-=sw;
198 }
199 }
200#endif
201#endif
202 /* we now can process the input data in blocks of SHA_CBLOCK
203 * chars and save the leftovers to c->data. */
204 p=c->data;
205 while (len >= SHA_CBLOCK)
206 {
207#if SHA_LONG_LOG2==2
208#if defined(B_ENDIAN) || defined(SHA1_ASM)
209#define SHA_NO_TAIL_CODE
210 /*
211 * Basically we get here only when data happens
212 * to be unaligned.
213 */
214 if (p != (SHA_LONG *)data)
215 memcpy(p,data,SHA_CBLOCK);
216 data+=SHA_CBLOCK;
217 sha1_block(c,p=c->data,1);
218 len-=SHA_CBLOCK;
219#elif defined(L_ENDIAN)
220#define BE_COPY(dst,src,i) { \
221 l = ((SHA_LONG *)src)[i]; \
222 Endian_Reverse32(l); \
223 dst[i] = l; \
224 }
225 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
226 {
227 for (sw=(SHA_LBLOCK/4); sw; sw--)
228 {
229 BE_COPY(p,data,0);
230 BE_COPY(p,data,1);
231 BE_COPY(p,data,2);
232 BE_COPY(p,data,3);
233 p+=4;
234 data += 4*sizeof(SHA_LONG);
235 }
236 sha1_block(c,p=c->data,1);
237 len-=SHA_CBLOCK;
238 continue;
239 }
240#endif
241#endif
242#ifndef SHA_NO_TAIL_CODE
243 /*
244 * In addition to "sizeof(SHA_LONG)!= 4" case the
245 * following code covers unaligned access cases on
246 * little-endian machines.
247 * <appro@fy.chalmers.se>
248 */
249 p=c->data;
250 for (sw=(SHA_LBLOCK/4); sw; sw--)
251 {
252 M_c2nl(data,l); p[0]=l;
253 M_c2nl(data,l); p[1]=l;
254 M_c2nl(data,l); p[2]=l;
255 M_c2nl(data,l); p[3]=l;
256 p+=4;
257 }
258 p=c->data;
259 sha1_block(c,p,1);
260 len-=SHA_CBLOCK;
261#endif
262 }
263 ec=(int)len;
264 c->num=ec;
265 ew=(ec>>2);
266 ec&=0x03;
267
268 for (sw=0; sw < ew; sw++)
269 { M_c2nl(data,l); p[sw]=l; }
270 M_c2nl_p(data,l,ec);
271 p[sw]=l;
272 }
273
274void SHA1_Transform(SHA_CTX *c, unsigned char *b)
275 {
276 SHA_LONG p[SHA_LBLOCK];
277
278#if SHA_LONG_LOG2==2
279#if defined(B_ENDIAN) || defined(SHA1_ASM)
280 memcpy(p,b,SHA_CBLOCK);
281 sha1_block(c,p,1);
282 return;
283#elif defined(L_ENDIAN)
284 if (((unsigned long)b%sizeof(SHA_LONG)) == 0)
285 {
286 SHA_LONG *q;
287 int i;
288
289 q=p;
290 for (i=(SHA_LBLOCK/4); i; i--)
291 {
292 unsigned long l;
293 BE_COPY(q,b,0); /* BE_COPY was defined above */
294 BE_COPY(q,b,1);
295 BE_COPY(q,b,2);
296 BE_COPY(q,b,3);
297 q+=4;
298 b+=4*sizeof(SHA_LONG);
299 }
300 sha1_block(c,p,1);
301 return;
302 }
303#endif
304#endif
305#ifndef SHA_NO_TAIL_CODE /* defined above, see comment */
306 {
307 SHA_LONG *q;
308 int i;
309
310 q=p;
311 for (i=(SHA_LBLOCK/4); i; i--)
312 {
313 SHA_LONG l;
314 c2nl(b,l); *(q++)=l;
315 c2nl(b,l); *(q++)=l;
316 c2nl(b,l); *(q++)=l;
317 c2nl(b,l); *(q++)=l;
318 }
319 sha1_block(c,p,1);
320 }
321#endif
322 }
323
324#ifndef SHA1_ASM
325static void sha1_block(SHA_CTX *c, register SHA_LONG *W, int num)
326 {
327 register SHA_LONG A,B,C,D,E,T;
328 SHA_LONG X[SHA_LBLOCK];
329
330 A=c->h0;
331 B=c->h1;
332 C=c->h2;
333 D=c->h3;
334 E=c->h4;
335 63
336 for (;;) 64#include <openssl/opensslv.h>
337 {
338 BODY_00_15( 0,A,B,C,D,E,T,W);
339 BODY_00_15( 1,T,A,B,C,D,E,W);
340 BODY_00_15( 2,E,T,A,B,C,D,W);
341 BODY_00_15( 3,D,E,T,A,B,C,W);
342 BODY_00_15( 4,C,D,E,T,A,B,W);
343 BODY_00_15( 5,B,C,D,E,T,A,W);
344 BODY_00_15( 6,A,B,C,D,E,T,W);
345 BODY_00_15( 7,T,A,B,C,D,E,W);
346 BODY_00_15( 8,E,T,A,B,C,D,W);
347 BODY_00_15( 9,D,E,T,A,B,C,W);
348 BODY_00_15(10,C,D,E,T,A,B,W);
349 BODY_00_15(11,B,C,D,E,T,A,W);
350 BODY_00_15(12,A,B,C,D,E,T,W);
351 BODY_00_15(13,T,A,B,C,D,E,W);
352 BODY_00_15(14,E,T,A,B,C,D,W);
353 BODY_00_15(15,D,E,T,A,B,C,W);
354 BODY_16_19(16,C,D,E,T,A,B,W,W,W,W);
355 BODY_16_19(17,B,C,D,E,T,A,W,W,W,W);
356 BODY_16_19(18,A,B,C,D,E,T,W,W,W,W);
357 BODY_16_19(19,T,A,B,C,D,E,W,W,W,X);
358
359 BODY_20_31(20,E,T,A,B,C,D,W,W,W,X);
360 BODY_20_31(21,D,E,T,A,B,C,W,W,W,X);
361 BODY_20_31(22,C,D,E,T,A,B,W,W,W,X);
362 BODY_20_31(23,B,C,D,E,T,A,W,W,W,X);
363 BODY_20_31(24,A,B,C,D,E,T,W,W,X,X);
364 BODY_20_31(25,T,A,B,C,D,E,W,W,X,X);
365 BODY_20_31(26,E,T,A,B,C,D,W,W,X,X);
366 BODY_20_31(27,D,E,T,A,B,C,W,W,X,X);
367 BODY_20_31(28,C,D,E,T,A,B,W,W,X,X);
368 BODY_20_31(29,B,C,D,E,T,A,W,W,X,X);
369 BODY_20_31(30,A,B,C,D,E,T,W,X,X,X);
370 BODY_20_31(31,T,A,B,C,D,E,W,X,X,X);
371 BODY_32_39(32,E,T,A,B,C,D,X);
372 BODY_32_39(33,D,E,T,A,B,C,X);
373 BODY_32_39(34,C,D,E,T,A,B,X);
374 BODY_32_39(35,B,C,D,E,T,A,X);
375 BODY_32_39(36,A,B,C,D,E,T,X);
376 BODY_32_39(37,T,A,B,C,D,E,X);
377 BODY_32_39(38,E,T,A,B,C,D,X);
378 BODY_32_39(39,D,E,T,A,B,C,X);
379
380 BODY_40_59(40,C,D,E,T,A,B,X);
381 BODY_40_59(41,B,C,D,E,T,A,X);
382 BODY_40_59(42,A,B,C,D,E,T,X);
383 BODY_40_59(43,T,A,B,C,D,E,X);
384 BODY_40_59(44,E,T,A,B,C,D,X);
385 BODY_40_59(45,D,E,T,A,B,C,X);
386 BODY_40_59(46,C,D,E,T,A,B,X);
387 BODY_40_59(47,B,C,D,E,T,A,X);
388 BODY_40_59(48,A,B,C,D,E,T,X);
389 BODY_40_59(49,T,A,B,C,D,E,X);
390 BODY_40_59(50,E,T,A,B,C,D,X);
391 BODY_40_59(51,D,E,T,A,B,C,X);
392 BODY_40_59(52,C,D,E,T,A,B,X);
393 BODY_40_59(53,B,C,D,E,T,A,X);
394 BODY_40_59(54,A,B,C,D,E,T,X);
395 BODY_40_59(55,T,A,B,C,D,E,X);
396 BODY_40_59(56,E,T,A,B,C,D,X);
397 BODY_40_59(57,D,E,T,A,B,C,X);
398 BODY_40_59(58,C,D,E,T,A,B,X);
399 BODY_40_59(59,B,C,D,E,T,A,X);
400
401 BODY_60_79(60,A,B,C,D,E,T,X);
402 BODY_60_79(61,T,A,B,C,D,E,X);
403 BODY_60_79(62,E,T,A,B,C,D,X);
404 BODY_60_79(63,D,E,T,A,B,C,X);
405 BODY_60_79(64,C,D,E,T,A,B,X);
406 BODY_60_79(65,B,C,D,E,T,A,X);
407 BODY_60_79(66,A,B,C,D,E,T,X);
408 BODY_60_79(67,T,A,B,C,D,E,X);
409 BODY_60_79(68,E,T,A,B,C,D,X);
410 BODY_60_79(69,D,E,T,A,B,C,X);
411 BODY_60_79(70,C,D,E,T,A,B,X);
412 BODY_60_79(71,B,C,D,E,T,A,X);
413 BODY_60_79(72,A,B,C,D,E,T,X);
414 BODY_60_79(73,T,A,B,C,D,E,X);
415 BODY_60_79(74,E,T,A,B,C,D,X);
416 BODY_60_79(75,D,E,T,A,B,C,X);
417 BODY_60_79(76,C,D,E,T,A,B,X);
418 BODY_60_79(77,B,C,D,E,T,A,X);
419 BODY_60_79(78,A,B,C,D,E,T,X);
420 BODY_60_79(79,T,A,B,C,D,E,X);
421
422 c->h0=(c->h0+E)&0xffffffffL;
423 c->h1=(c->h1+T)&0xffffffffL;
424 c->h2=(c->h2+A)&0xffffffffL;
425 c->h3=(c->h3+B)&0xffffffffL;
426 c->h4=(c->h4+C)&0xffffffffL;
427
428 if (--num <= 0) break;
429 65
430 A=c->h0; 66const char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
431 B=c->h1;
432 C=c->h2;
433 D=c->h3;
434 E=c->h4;
435 67
436 W+=SHA_LBLOCK; /* Note! This can happen only when sizeof(SHA_LONG) 68/* The implementation is in ../md32_common.h */
437 * is 4. Whenever it's not the actual case this
438 * function is never called with num larger than 1
439 * and we never advance down here.
440 * <appro@fy.chalmers.se>
441 */
442 }
443 }
444#endif
445 69
446void SHA1_Final(unsigned char *md, SHA_CTX *c) 70#include "sha_locl.h"
447 {
448 register int i,j;
449 register SHA_LONG l;
450 register SHA_LONG *p;
451 static unsigned char end[4]={0x80,0x00,0x00,0x00};
452 unsigned char *cp=end;
453
454 /* c->num should definitly have room for at least one more byte. */
455 p=c->data;
456 j=c->num;
457 i=j>>2;
458#ifdef PURIFY
459 if ((j&0x03) == 0) p[i]=0;
460#endif
461 l=p[i];
462 M_p_c2nl(cp,l,j&0x03);
463 p[i]=l;
464 i++;
465 /* i is the next 'undefined word' */
466 if (c->num >= SHA_LAST_BLOCK)
467 {
468 for (; i<SHA_LBLOCK; i++)
469 p[i]=0;
470 sha1_block(c,p,1);
471 i=0;
472 }
473 for (; i<(SHA_LBLOCK-2); i++)
474 p[i]=0;
475 p[SHA_LBLOCK-2]=c->Nh;
476 p[SHA_LBLOCK-1]=c->Nl;
477#if SHA_LONG_LOG2==2
478#if !defined(B_ENDIAN) && defined(SHA1_ASM)
479 Endian_Reverse32(p[SHA_LBLOCK-2]);
480 Endian_Reverse32(p[SHA_LBLOCK-1]);
481#endif
482#endif
483 sha1_block(c,p,1);
484 cp=md;
485 l=c->h0; nl2c(l,cp);
486 l=c->h1; nl2c(l,cp);
487 l=c->h2; nl2c(l,cp);
488 l=c->h3; nl2c(l,cp);
489 l=c->h4; nl2c(l,cp);
490 71
491 c->num=0;
492 /* sha_block may be leaving some stuff on the stack
493 * but I'm not worried :-)
494 memset((void *)c,0,sizeof(SHA_CTX));
495 */
496 }
497#endif 72#endif
498 73
diff --git a/src/lib/libcrypto/sha/sha1s.cpp b/src/lib/libcrypto/sha/sha1s.cpp
index 3103e1871b..af23d1e0f2 100644
--- a/src/lib/libcrypto/sha/sha1s.cpp
+++ b/src/lib/libcrypto/sha/sha1s.cpp
@@ -34,6 +34,7 @@ void GetTSC(unsigned long& tsc)
34#include <stdlib.h> 34#include <stdlib.h>
35#include <openssl/sha.h> 35#include <openssl/sha.h>
36 36
37#define sha1_block_x86 sha1_block_asm_data_order
37extern "C" { 38extern "C" {
38void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num); 39void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num);
39} 40}
@@ -55,8 +56,10 @@ void main(int argc,char *argv[])
55 if (num == 0) num=16; 56 if (num == 0) num=16;
56 if (num > 250) num=16; 57 if (num > 250) num=16;
57 numm=num+2; 58 numm=num+2;
59#if 0
58 num*=64; 60 num*=64;
59 numm*=64; 61 numm*=64;
62#endif
60 63
61 for (j=0; j<6; j++) 64 for (j=0; j<6; j++)
62 { 65 {
@@ -72,7 +75,7 @@ void main(int argc,char *argv[])
72 sha1_block_x86(&ctx,buffer,num); 75 sha1_block_x86(&ctx,buffer,num);
73 } 76 }
74 77
75 printf("sha1 (%d bytes) %d %d (%.2f)\n",num, 78 printf("sha1 (%d bytes) %d %d (%.2f)\n",num*64,
76 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2); 79 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
77 } 80 }
78 } 81 }
diff --git a/src/lib/libcrypto/sha/sha1test.c b/src/lib/libcrypto/sha/sha1test.c
index 9400ad2a61..688d06c637 100644
--- a/src/lib/libcrypto/sha/sha1test.c
+++ b/src/lib/libcrypto/sha/sha1test.c
@@ -76,26 +76,26 @@ int main(int argc, char *argv[])
76#undef SHA_0 /* FIPS 180 */ 76#undef SHA_0 /* FIPS 180 */
77#define SHA_1 /* FIPS 180-1 */ 77#define SHA_1 /* FIPS 180-1 */
78 78
79char *test[]={ 79static char *test[]={
80 "abc", 80 "abc",
81 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 81 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
82 NULL, 82 NULL,
83 }; 83 };
84 84
85#ifdef SHA_0 85#ifdef SHA_0
86char *ret[]={ 86static char *ret[]={
87 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", 87 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
88 "d2516ee1acfa5baf33dfc1c471e438449ef134c8", 88 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
89 }; 89 };
90char *bigret= 90static char *bigret=
91 "3232affa48628a26653b5aaa44541fd90d690603"; 91 "3232affa48628a26653b5aaa44541fd90d690603";
92#endif 92#endif
93#ifdef SHA_1 93#ifdef SHA_1
94char *ret[]={ 94static char *ret[]={
95 "a9993e364706816aba3e25717850c26c9cd0d89d", 95 "a9993e364706816aba3e25717850c26c9cd0d89d",
96 "84983e441c3bd26ebaae4aa1f95129e5e54670f1", 96 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
97 }; 97 };
98char *bigret= 98static char *bigret=
99 "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; 99 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
100#endif 100#endif
101 101
diff --git a/src/lib/libcrypto/sha/sha_dgst.c b/src/lib/libcrypto/sha/sha_dgst.c
index 4df535360f..894a96274a 100644
--- a/src/lib/libcrypto/sha/sha_dgst.c
+++ b/src/lib/libcrypto/sha/sha_dgst.c
@@ -1,4 +1,4 @@
1/* crypto/sha/sha_dgst.c */ 1/* crypto/sha/sha1dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,437 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <stdio.h> 59#if !defined(NO_SHA0) && !defined(NO_SHA)
60#include <string.h>
61#define SHA_0
62#undef SHA_1
63#include <openssl/sha.h>
64#include "sha_locl.h"
65#include <openssl/opensslv.h>
66
67#ifndef NO_SHA0
68char *SHA_version="SHA" OPENSSL_VERSION_PTEXT;
69
70/* Implemented from SHA-0 document - The Secure Hash Algorithm
71 */
72
73#define INIT_DATA_h0 0x67452301UL
74#define INIT_DATA_h1 0xefcdab89UL
75#define INIT_DATA_h2 0x98badcfeUL
76#define INIT_DATA_h3 0x10325476UL
77#define INIT_DATA_h4 0xc3d2e1f0UL
78
79#define K_00_19 0x5a827999UL
80#define K_20_39 0x6ed9eba1UL
81#define K_40_59 0x8f1bbcdcUL
82#define K_60_79 0xca62c1d6UL
83
84static void sha_block(SHA_CTX *c, register SHA_LONG *p, int num);
85
86#if !defined(B_ENDIAN) && defined(SHA_ASM)
87# define M_c2nl c2l
88# define M_p_c2nl p_c2l
89# define M_c2nl_p c2l_p
90# define M_p_c2nl_p p_c2l_p
91# define M_nl2c l2c
92#else
93# define M_c2nl c2nl
94# define M_p_c2nl p_c2nl
95# define M_c2nl_p c2nl_p
96# define M_p_c2nl_p p_c2nl_p
97# define M_nl2c nl2c
98#endif
99
100void SHA_Init(SHA_CTX *c)
101 {
102 c->h0=INIT_DATA_h0;
103 c->h1=INIT_DATA_h1;
104 c->h2=INIT_DATA_h2;
105 c->h3=INIT_DATA_h3;
106 c->h4=INIT_DATA_h4;
107 c->Nl=0;
108 c->Nh=0;
109 c->num=0;
110 }
111 60
112void SHA_Update(SHA_CTX *c, register const unsigned char *data, 61#undef SHA_1
113 unsigned long len) 62#define SHA_0
114 {
115 register SHA_LONG *p;
116 int ew,ec,sw,sc;
117 SHA_LONG l;
118
119 if (len == 0) return;
120
121 l=(c->Nl+(len<<3))&0xffffffffL;
122 if (l < c->Nl) /* overflow */
123 c->Nh++;
124 c->Nh+=(len>>29);
125 c->Nl=l;
126
127 if (c->num != 0)
128 {
129 p=c->data;
130 sw=c->num>>2;
131 sc=c->num&0x03;
132
133 if ((c->num+len) >= SHA_CBLOCK)
134 {
135 l= p[sw];
136 M_p_c2nl(data,l,sc);
137 p[sw++]=l;
138 for (; sw<SHA_LBLOCK; sw++)
139 {
140 M_c2nl(data,l);
141 p[sw]=l;
142 }
143 len-=(SHA_CBLOCK-c->num);
144
145 sha_block(c,p,1);
146 c->num=0;
147 /* drop through and do the rest */
148 }
149 else
150 {
151 c->num+=(int)len;
152 if ((sc+len) < 4) /* ugly, add char's to a word */
153 {
154 l= p[sw];
155 M_p_c2nl_p(data,l,sc,len);
156 p[sw]=l;
157 }
158 else
159 {
160 ew=(c->num>>2);
161 ec=(c->num&0x03);
162 l= p[sw];
163 M_p_c2nl(data,l,sc);
164 p[sw++]=l;
165 for (; sw < ew; sw++)
166 { M_c2nl(data,l); p[sw]=l; }
167 if (ec)
168 {
169 M_c2nl_p(data,l,ec);
170 p[sw]=l;
171 }
172 }
173 return;
174 }
175 }
176 /* We can only do the following code for assember, the reason
177 * being that the sha_block 'C' version changes the values
178 * in the 'data' array. The assember code avoids this and
179 * copies it to a local array. I should be able to do this for
180 * the C version as well....
181 */
182#if SHA_LONG_LOG2==2
183#if defined(B_ENDIAN) || defined(SHA_ASM)
184 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
185 {
186 sw=len/SHA_CBLOCK;
187 if (sw)
188 {
189 sha_block(c,(SHA_LONG *)data,sw);
190 sw*=SHA_CBLOCK;
191 data+=sw;
192 len-=sw;
193 }
194 }
195#endif
196#endif
197 /* we now can process the input data in blocks of SHA_CBLOCK
198 * chars and save the leftovers to c->data. */
199 p=c->data;
200 while (len >= SHA_CBLOCK)
201 {
202#if SHA_LONG_LOG2==2
203#if defined(B_ENDIAN) || defined(SHA_ASM)
204#define SHA_NO_TAIL_CODE
205 /*
206 * Basically we get here only when data happens
207 * to be unaligned.
208 */
209 if (p != (SHA_LONG *)data)
210 memcpy(p,data,SHA_CBLOCK);
211 data+=SHA_CBLOCK;
212 sha_block(c,p=c->data,1);
213 len-=SHA_CBLOCK;
214#elif defined(L_ENDIAN)
215#define BE_COPY(dst,src,i) { \
216 l = ((SHA_LONG *)src)[i]; \
217 Endian_Reverse32(l); \
218 dst[i] = l; \
219 }
220 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
221 {
222 for (sw=(SHA_LBLOCK/4); sw; sw--)
223 {
224 BE_COPY(p,data,0);
225 BE_COPY(p,data,1);
226 BE_COPY(p,data,2);
227 BE_COPY(p,data,3);
228 p+=4;
229 data += 4*sizeof(SHA_LONG);
230 }
231 sha_block(c,p=c->data,1);
232 len-=SHA_CBLOCK;
233 continue;
234 }
235#endif
236#endif
237#ifndef SHA_NO_TAIL_CODE
238 /*
239 * In addition to "sizeof(SHA_LONG)!= 4" case the
240 * following code covers unaligned access cases on
241 * little-endian machines.
242 * <appro@fy.chalmers.se>
243 */
244 p=c->data;
245 for (sw=(SHA_LBLOCK/4); sw; sw--)
246 {
247 M_c2nl(data,l); p[0]=l;
248 M_c2nl(data,l); p[1]=l;
249 M_c2nl(data,l); p[2]=l;
250 M_c2nl(data,l); p[3]=l;
251 p+=4;
252 }
253 p=c->data;
254 sha_block(c,p,1);
255 len-=SHA_CBLOCK;
256#endif
257 }
258 ec=(int)len;
259 c->num=ec;
260 ew=(ec>>2);
261 ec&=0x03;
262 63
263 for (sw=0; sw < ew; sw++) 64#include <openssl/opensslv.h>
264 { M_c2nl(data,l); p[sw]=l; }
265 M_c2nl_p(data,l,ec);
266 p[sw]=l;
267 }
268
269void SHA_Transform(SHA_CTX *c, unsigned char *b)
270 {
271 SHA_LONG p[SHA_LBLOCK];
272
273#if SHA_LONG_LOG2==2
274#if defined(B_ENDIAN) || defined(SHA_ASM)
275 memcpy(p,b,SHA_CBLOCK);
276 sha_block(c,p,1);
277 return;
278#elif defined(L_ENDIAN)
279 if (((unsigned long)b%sizeof(SHA_LONG)) == 0)
280 {
281 SHA_LONG *q;
282 int i;
283
284 q=p;
285 for (i=(SHA_LBLOCK/4); i; i--)
286 {
287 unsigned long l;
288 BE_COPY(q,b,0); /* BE_COPY was defined above */
289 BE_COPY(q,b,1);
290 BE_COPY(q,b,2);
291 BE_COPY(q,b,3);
292 q+=4;
293 b+=4*sizeof(SHA_LONG);
294 }
295 sha_block(c,p,1);
296 return;
297 }
298#endif
299#endif
300#ifndef SHA_NO_TAIL_CODE /* defined above, see comment */
301 {
302 SHA_LONG *q;
303 int i;
304
305 q=p;
306 for (i=(SHA_LBLOCK/4); i; i--)
307 {
308 SHA_LONG l;
309 c2nl(b,l); *(q++)=l;
310 c2nl(b,l); *(q++)=l;
311 c2nl(b,l); *(q++)=l;
312 c2nl(b,l); *(q++)=l;
313 }
314 sha_block(c,p,1);
315 }
316#endif
317 }
318
319#ifndef SHA_ASM
320static void sha_block(SHA_CTX *c, register SHA_LONG *W, int num)
321 {
322 register SHA_LONG A,B,C,D,E,T;
323 SHA_LONG X[SHA_LBLOCK];
324
325 A=c->h0;
326 B=c->h1;
327 C=c->h2;
328 D=c->h3;
329 E=c->h4;
330
331 for (;;)
332 {
333 BODY_00_15( 0,A,B,C,D,E,T,W);
334 BODY_00_15( 1,T,A,B,C,D,E,W);
335 BODY_00_15( 2,E,T,A,B,C,D,W);
336 BODY_00_15( 3,D,E,T,A,B,C,W);
337 BODY_00_15( 4,C,D,E,T,A,B,W);
338 BODY_00_15( 5,B,C,D,E,T,A,W);
339 BODY_00_15( 6,A,B,C,D,E,T,W);
340 BODY_00_15( 7,T,A,B,C,D,E,W);
341 BODY_00_15( 8,E,T,A,B,C,D,W);
342 BODY_00_15( 9,D,E,T,A,B,C,W);
343 BODY_00_15(10,C,D,E,T,A,B,W);
344 BODY_00_15(11,B,C,D,E,T,A,W);
345 BODY_00_15(12,A,B,C,D,E,T,W);
346 BODY_00_15(13,T,A,B,C,D,E,W);
347 BODY_00_15(14,E,T,A,B,C,D,W);
348 BODY_00_15(15,D,E,T,A,B,C,W);
349 BODY_16_19(16,C,D,E,T,A,B,W,W,W,W);
350 BODY_16_19(17,B,C,D,E,T,A,W,W,W,W);
351 BODY_16_19(18,A,B,C,D,E,T,W,W,W,W);
352 BODY_16_19(19,T,A,B,C,D,E,W,W,W,X);
353
354 BODY_20_31(20,E,T,A,B,C,D,W,W,W,X);
355 BODY_20_31(21,D,E,T,A,B,C,W,W,W,X);
356 BODY_20_31(22,C,D,E,T,A,B,W,W,W,X);
357 BODY_20_31(23,B,C,D,E,T,A,W,W,W,X);
358 BODY_20_31(24,A,B,C,D,E,T,W,W,X,X);
359 BODY_20_31(25,T,A,B,C,D,E,W,W,X,X);
360 BODY_20_31(26,E,T,A,B,C,D,W,W,X,X);
361 BODY_20_31(27,D,E,T,A,B,C,W,W,X,X);
362 BODY_20_31(28,C,D,E,T,A,B,W,W,X,X);
363 BODY_20_31(29,B,C,D,E,T,A,W,W,X,X);
364 BODY_20_31(30,A,B,C,D,E,T,W,X,X,X);
365 BODY_20_31(31,T,A,B,C,D,E,W,X,X,X);
366 BODY_32_39(32,E,T,A,B,C,D,X);
367 BODY_32_39(33,D,E,T,A,B,C,X);
368 BODY_32_39(34,C,D,E,T,A,B,X);
369 BODY_32_39(35,B,C,D,E,T,A,X);
370 BODY_32_39(36,A,B,C,D,E,T,X);
371 BODY_32_39(37,T,A,B,C,D,E,X);
372 BODY_32_39(38,E,T,A,B,C,D,X);
373 BODY_32_39(39,D,E,T,A,B,C,X);
374
375 BODY_40_59(40,C,D,E,T,A,B,X);
376 BODY_40_59(41,B,C,D,E,T,A,X);
377 BODY_40_59(42,A,B,C,D,E,T,X);
378 BODY_40_59(43,T,A,B,C,D,E,X);
379 BODY_40_59(44,E,T,A,B,C,D,X);
380 BODY_40_59(45,D,E,T,A,B,C,X);
381 BODY_40_59(46,C,D,E,T,A,B,X);
382 BODY_40_59(47,B,C,D,E,T,A,X);
383 BODY_40_59(48,A,B,C,D,E,T,X);
384 BODY_40_59(49,T,A,B,C,D,E,X);
385 BODY_40_59(50,E,T,A,B,C,D,X);
386 BODY_40_59(51,D,E,T,A,B,C,X);
387 BODY_40_59(52,C,D,E,T,A,B,X);
388 BODY_40_59(53,B,C,D,E,T,A,X);
389 BODY_40_59(54,A,B,C,D,E,T,X);
390 BODY_40_59(55,T,A,B,C,D,E,X);
391 BODY_40_59(56,E,T,A,B,C,D,X);
392 BODY_40_59(57,D,E,T,A,B,C,X);
393 BODY_40_59(58,C,D,E,T,A,B,X);
394 BODY_40_59(59,B,C,D,E,T,A,X);
395
396 BODY_60_79(60,A,B,C,D,E,T,X);
397 BODY_60_79(61,T,A,B,C,D,E,X);
398 BODY_60_79(62,E,T,A,B,C,D,X);
399 BODY_60_79(63,D,E,T,A,B,C,X);
400 BODY_60_79(64,C,D,E,T,A,B,X);
401 BODY_60_79(65,B,C,D,E,T,A,X);
402 BODY_60_79(66,A,B,C,D,E,T,X);
403 BODY_60_79(67,T,A,B,C,D,E,X);
404 BODY_60_79(68,E,T,A,B,C,D,X);
405 BODY_60_79(69,D,E,T,A,B,C,X);
406 BODY_60_79(70,C,D,E,T,A,B,X);
407 BODY_60_79(71,B,C,D,E,T,A,X);
408 BODY_60_79(72,A,B,C,D,E,T,X);
409 BODY_60_79(73,T,A,B,C,D,E,X);
410 BODY_60_79(74,E,T,A,B,C,D,X);
411 BODY_60_79(75,D,E,T,A,B,C,X);
412 BODY_60_79(76,C,D,E,T,A,B,X);
413 BODY_60_79(77,B,C,D,E,T,A,X);
414 BODY_60_79(78,A,B,C,D,E,T,X);
415 BODY_60_79(79,T,A,B,C,D,E,X);
416
417 c->h0=(c->h0+E)&0xffffffffL;
418 c->h1=(c->h1+T)&0xffffffffL;
419 c->h2=(c->h2+A)&0xffffffffL;
420 c->h3=(c->h3+B)&0xffffffffL;
421 c->h4=(c->h4+C)&0xffffffffL;
422
423 if (--num <= 0) break;
424 65
425 A=c->h0; 66const char *SHA_version="SHA" OPENSSL_VERSION_PTEXT;
426 B=c->h1;
427 C=c->h2;
428 D=c->h3;
429 E=c->h4;
430 67
431 W+=SHA_LBLOCK; /* Note! This can happen only when sizeof(SHA_LONG) 68/* The implementation is in ../md32_common.h */
432 * is 4. Whenever it's not the actual case this
433 * function is never called with num larger than 1
434 * and we never advance down here.
435 * <appro@fy.chalmers.se>
436 */
437 }
438 }
439#endif
440 69
441void SHA_Final(unsigned char *md, SHA_CTX *c) 70#include "sha_locl.h"
442 {
443 register int i,j;
444 register SHA_LONG l;
445 register SHA_LONG *p;
446 static unsigned char end[4]={0x80,0x00,0x00,0x00};
447 unsigned char *cp=end;
448 71
449 /* c->num should definitly have room for at least one more byte. */
450 p=c->data;
451 j=c->num;
452 i=j>>2;
453#ifdef PURIFY
454 if ((j&0x03) == 0) p[i]=0;
455#endif
456 l=p[i];
457 M_p_c2nl(cp,l,j&0x03);
458 p[i]=l;
459 i++;
460 /* i is the next 'undefined word' */
461 if (c->num >= SHA_LAST_BLOCK)
462 {
463 for (; i<SHA_LBLOCK; i++)
464 p[i]=0;
465 sha_block(c,p,1);
466 i=0;
467 }
468 for (; i<(SHA_LBLOCK-2); i++)
469 p[i]=0;
470 p[SHA_LBLOCK-2]=c->Nh;
471 p[SHA_LBLOCK-1]=c->Nl;
472#if SHA_LONG_LOG2==2
473#if !defined(B_ENDIAN) && defined(SHA_ASM)
474 Endian_Reverse32(p[SHA_LBLOCK-2]);
475 Endian_Reverse32(p[SHA_LBLOCK-1]);
476#endif 72#endif
477#endif
478 sha_block(c,p,1);
479 cp=md;
480 l=c->h0; nl2c(l,cp);
481 l=c->h1; nl2c(l,cp);
482 l=c->h2; nl2c(l,cp);
483 l=c->h3; nl2c(l,cp);
484 l=c->h4; nl2c(l,cp);
485 73
486 c->num=0;
487 /* sha_block may be leaving some stuff on the stack
488 * but I'm not worried :-)
489 memset((void *)c,0,sizeof(SHA_CTX));
490 */
491 }
492#endif
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h
index 6646a8915b..3e6f489b87 100644
--- a/src/lib/libcrypto/sha/sha_locl.h
+++ b/src/lib/libcrypto/sha/sha_locl.h
@@ -60,180 +60,105 @@
60#include <string.h> 60#include <string.h>
61 61
62#include <openssl/opensslconf.h> 62#include <openssl/opensslconf.h>
63 63#include <openssl/sha.h>
64#ifdef undef
65/* one or the other needs to be defined */
66#ifndef SHA_1 /* FIPE 180-1 */
67#define SHA_0 /* FIPS 180 */
68#endif
69#endif
70
71#undef c2nl
72#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
73 l|=(((unsigned long)(*((c)++)))<<16), \
74 l|=(((unsigned long)(*((c)++)))<< 8), \
75 l|=(((unsigned long)(*((c)++))) ))
76
77#undef p_c2nl
78#define p_c2nl(c,l,n) { \
79 switch (n) { \
80 case 0: l =((unsigned long)(*((c)++)))<<24; \
81 case 1: l|=((unsigned long)(*((c)++)))<<16; \
82 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
83 case 3: l|=((unsigned long)(*((c)++))); \
84 } \
85 }
86
87#undef c2nl_p
88/* NOTE the pointer is not incremented at the end of this */
89#define c2nl_p(c,l,n) { \
90 l=0; \
91 (c)+=n; \
92 switch (n) { \
93 case 3: l =((unsigned long)(*(--(c))))<< 8; \
94 case 2: l|=((unsigned long)(*(--(c))))<<16; \
95 case 1: l|=((unsigned long)(*(--(c))))<<24; \
96 } \
97 }
98
99#undef p_c2nl_p
100#define p_c2nl_p(c,l,sc,len) { \
101 switch (sc) \
102 { \
103 case 0: l =((unsigned long)(*((c)++)))<<24; \
104 if (--len == 0) break; \
105 case 1: l|=((unsigned long)(*((c)++)))<<16; \
106 if (--len == 0) break; \
107 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
108 } \
109 }
110
111#undef nl2c
112#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
113 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
114 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
115 *((c)++)=(unsigned char)(((l) )&0xff))
116
117#undef c2l
118#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
119 l|=(((unsigned long)(*((c)++)))<< 8), \
120 l|=(((unsigned long)(*((c)++)))<<16), \
121 l|=(((unsigned long)(*((c)++)))<<24))
122
123#undef p_c2l
124#define p_c2l(c,l,n) { \
125 switch (n) { \
126 case 0: l =((unsigned long)(*((c)++))); \
127 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
128 case 2: l|=((unsigned long)(*((c)++)))<<16; \
129 case 3: l|=((unsigned long)(*((c)++)))<<24; \
130 } \
131 }
132
133#undef c2l_p
134/* NOTE the pointer is not incremented at the end of this */
135#define c2l_p(c,l,n) { \
136 l=0; \
137 (c)+=n; \
138 switch (n) { \
139 case 3: l =((unsigned long)(*(--(c))))<<16; \
140 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
141 case 1: l|=((unsigned long)(*(--(c)))); \
142 } \
143 }
144
145#undef p_c2l_p
146#define p_c2l_p(c,l,sc,len) { \
147 switch (sc) \
148 { \
149 case 0: l =((unsigned long)(*((c)++))); \
150 if (--len == 0) break; \
151 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
152 if (--len == 0) break; \
153 case 2: l|=((unsigned long)(*((c)++)))<<16; \
154 } \
155 }
156
157#undef l2c
158#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
159 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
160 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
161 *((c)++)=(unsigned char)(((l)>>24)&0xff))
162 64
163#ifndef SHA_LONG_LOG2 65#ifndef SHA_LONG_LOG2
164#define SHA_LONG_LOG2 2 /* default to 32 bits */ 66#define SHA_LONG_LOG2 2 /* default to 32 bits */
165#endif 67#endif
166 68
167#undef ROTATE 69#define DATA_ORDER_IS_BIG_ENDIAN
168#undef Endian_Reverse32 70
169#if defined(WIN32) 71#define HASH_LONG SHA_LONG
170#define ROTATE(a,n) _lrotl(a,n) 72#define HASH_LONG_LOG2 SHA_LONG_LOG2
171#elif defined(__GNUC__) && !defined(PEDANTIC) 73#define HASH_CTX SHA_CTX
172/* some inline assembler templates by <appro@fy.chalmers.se> */ 74#define HASH_CBLOCK SHA_CBLOCK
173#if defined(__i386) && !defined(NO_ASM) 75#define HASH_LBLOCK SHA_LBLOCK
174#define ROTATE(a,n) ({ register unsigned int ret; \ 76#define HASH_MAKE_STRING(c,s) do { \
175 asm ("roll %1,%0" \ 77 unsigned long ll; \
176 : "=r"(ret) \ 78 ll=(c)->h0; HOST_l2c(ll,(s)); \
177 : "I"(n), "0"(a) \ 79 ll=(c)->h1; HOST_l2c(ll,(s)); \
178 : "cc"); \ 80 ll=(c)->h2; HOST_l2c(ll,(s)); \
179 ret; \ 81 ll=(c)->h3; HOST_l2c(ll,(s)); \
180 }) 82 ll=(c)->h4; HOST_l2c(ll,(s)); \
181#ifndef I386_ONLY 83 } while (0)
182#define Endian_Reverse32(a) \ 84
183 { register unsigned int ltmp=(a); \ 85#if defined(SHA_0)
184 asm ("bswapl %0" \ 86
185 : "=r"(ltmp) : "0"(ltmp)); \ 87# define HASH_UPDATE SHA_Update
186 (a)=ltmp; \ 88# define HASH_TRANSFORM SHA_Transform
187 } 89# define HASH_FINAL SHA_Final
188#endif 90# define HASH_INIT SHA_Init
189#elif defined(__powerpc) 91# define HASH_BLOCK_HOST_ORDER sha_block_host_order
190#define ROTATE(a,n) ({ register unsigned int ret; \ 92# define HASH_BLOCK_DATA_ORDER sha_block_data_order
191 asm ("rlwinm %0,%1,%2,0,31" \ 93# define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id))
192 : "=r"(ret) \ 94
193 : "r"(a), "I"(n)); \ 95 void sha_block_host_order (SHA_CTX *c, const void *p,int num);
194 ret; \ 96 void sha_block_data_order (SHA_CTX *c, const void *p,int num);
195 }) 97
196/* Endian_Reverse32 is not needed for PowerPC */ 98#elif defined(SHA_1)
197#endif 99
198#endif 100# define HASH_UPDATE SHA1_Update
101# define HASH_TRANSFORM SHA1_Transform
102# define HASH_FINAL SHA1_Final
103# define HASH_INIT SHA1_Init
104# define HASH_BLOCK_HOST_ORDER sha1_block_host_order
105# define HASH_BLOCK_DATA_ORDER sha1_block_data_order
106# if defined(__MWERKS__) && defined(__MC68K__)
107 /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */
108# define Xupdate(a,ix,ia,ib,ic,id) do { (a)=(ia^ib^ic^id); \
109 ix=(a)=ROTATE((a),1); \
110 } while (0)
111# else
112# define Xupdate(a,ix,ia,ib,ic,id) ( (a)=(ia^ib^ic^id), \
113 ix=(a)=ROTATE((a),1) \
114 )
115# endif
116
117# ifdef SHA1_ASM
118# if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
119# define sha1_block_host_order sha1_block_asm_host_order
120# define DONT_IMPLEMENT_BLOCK_HOST_ORDER
121# define sha1_block_data_order sha1_block_asm_data_order
122# define DONT_IMPLEMENT_BLOCK_DATA_ORDER
123# define HASH_BLOCK_DATA_ORDER_ALIGNED sha1_block_asm_data_order
124# endif
125# endif
126 void sha1_block_host_order (SHA_CTX *c, const void *p,int num);
127 void sha1_block_data_order (SHA_CTX *c, const void *p,int num);
199 128
200/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
201#ifdef ROTATE
202#ifndef Endian_Reverse32
203/* 5 instructions with rotate instruction, else 9 */
204#define Endian_Reverse32(a) \
205 { \
206 unsigned long t=(a); \
207 (a)=((ROTATE(t,8)&0x00FF00FF)|(ROTATE((t&0x00FF00FF),24))); \
208 }
209#endif
210#else 129#else
211#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) 130# error "Either SHA_0 or SHA_1 must be defined."
212#ifndef Endian_Reverse32
213/* 6 instructions with rotate instruction, else 8 */
214#define Endian_Reverse32(a) \
215 { \
216 unsigned long t=(a); \
217 t=(((t>>8)&0x00FF00FF)|((t&0x00FF00FF)<<8)); \
218 (a)=ROTATE(t,16); \
219 }
220#endif 131#endif
221/* 132
222 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|... 133#ifndef FLAT_INC
223 * It's rewritten as above for two reasons: 134#include "../md32_common.h"
224 * - RISCs aren't good at long constants and have to explicitely 135#else
225 * compose 'em with several (well, usually 2) instructions in a 136#include "md32_common.h"
226 * register before performing the actual operation and (as you
227 * already realized:-) having same constant should inspire the
228 * compiler to permanently allocate the only register for it;
229 * - most modern CPUs have two ALUs, but usually only one has
230 * circuitry for shifts:-( this minor tweak inspires compiler
231 * to schedule shift instructions in a better way...
232 *
233 * <appro@fy.chalmers.se>
234 */
235#endif 137#endif
236 138
139#define INIT_DATA_h0 0x67452301UL
140#define INIT_DATA_h1 0xefcdab89UL
141#define INIT_DATA_h2 0x98badcfeUL
142#define INIT_DATA_h3 0x10325476UL
143#define INIT_DATA_h4 0xc3d2e1f0UL
144
145void HASH_INIT (SHA_CTX *c)
146 {
147 c->h0=INIT_DATA_h0;
148 c->h1=INIT_DATA_h1;
149 c->h2=INIT_DATA_h2;
150 c->h3=INIT_DATA_h3;
151 c->h4=INIT_DATA_h4;
152 c->Nl=0;
153 c->Nh=0;
154 c->num=0;
155 }
156
157#define K_00_19 0x5a827999UL
158#define K_20_39 0x6ed9eba1UL
159#define K_40_59 0x8f1bbcdcUL
160#define K_60_79 0xca62c1d6UL
161
237/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be 162/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
238 * simplified to the code in F_00_19. Wei attributes these optimisations 163 * simplified to the code in F_00_19. Wei attributes these optimisations
239 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. 164 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
@@ -246,43 +171,305 @@
246#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) 171#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
247#define F_60_79(b,c,d) F_20_39(b,c,d) 172#define F_60_79(b,c,d) F_20_39(b,c,d)
248 173
249#undef Xupdate 174#define BODY_00_15(i,a,b,c,d,e,f,xi) \
250#ifdef SHA_0 175 (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
251#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\
252 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);
253#endif
254#ifdef SHA_1
255#define Xupdate(a,i,ia,ib,ic,id) (a)=\
256 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\
257 X[(i)&0x0f]=(a)=ROTATE((a),1);
258#endif
259
260#define BODY_00_15(i,a,b,c,d,e,f,xa) \
261 (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
262 (b)=ROTATE((b),30); 176 (b)=ROTATE((b),30);
263 177
264#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \ 178#define BODY_16_19(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
265 Xupdate(f,i,xa,xb,xc,xd); \ 179 Xupdate(f,xi,xa,xb,xc,xd); \
266 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ 180 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
267 (b)=ROTATE((b),30); 181 (b)=ROTATE((b),30);
268 182
269#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \ 183#define BODY_20_31(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
270 Xupdate(f,i,xa,xb,xc,xd); \ 184 Xupdate(f,xi,xa,xb,xc,xd); \
271 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ 185 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
272 (b)=ROTATE((b),30); 186 (b)=ROTATE((b),30);
273 187
274#define BODY_32_39(i,a,b,c,d,e,f,xa) \ 188#define BODY_32_39(i,a,b,c,d,e,f,xa,xb,xc,xd) \
275 Xupdate(f,i,xa,xa,xa,xa); \ 189 Xupdate(f,xa,xa,xb,xc,xd); \
276 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ 190 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
277 (b)=ROTATE((b),30); 191 (b)=ROTATE((b),30);
278 192
279#define BODY_40_59(i,a,b,c,d,e,f,xa) \ 193#define BODY_40_59(i,a,b,c,d,e,f,xa,xb,xc,xd) \
280 Xupdate(f,i,xa,xa,xa,xa); \ 194 Xupdate(f,xa,xa,xb,xc,xd); \
281 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \ 195 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
282 (b)=ROTATE((b),30); 196 (b)=ROTATE((b),30);
283 197
284#define BODY_60_79(i,a,b,c,d,e,f,xa) \ 198#define BODY_60_79(i,a,b,c,d,e,f,xa,xb,xc,xd) \
285 Xupdate(f,i,xa,xa,xa,xa); \ 199 Xupdate(f,xa,xa,xb,xc,xd); \
286 (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \ 200 (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
287 (b)=ROTATE((b),30); 201 (b)=ROTATE((b),30);
288 202
203#ifdef X
204#undef X
205#endif
206#ifndef MD32_XARRAY
207 /*
208 * Originally X was an array. As it's automatic it's natural
209 * to expect RISC compiler to accomodate at least part of it in
210 * the register bank, isn't it? Unfortunately not all compilers
211 * "find" this expectation reasonable:-( On order to make such
212 * compilers generate better code I replace X[] with a bunch of
213 * X0, X1, etc. See the function body below...
214 * <appro@fy.chalmers.se>
215 */
216# define X(i) XX##i
217#else
218 /*
219 * However! Some compilers (most notably HP C) get overwhelmed by
220 * that many local variables so that we have to have the way to
221 * fall down to the original behavior.
222 */
223# define X(i) XX[i]
224#endif
225
226#ifndef DONT_IMPLEMENT_BLOCK_HOST_ORDER
227void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num)
228 {
229 const SHA_LONG *W=d;
230 register unsigned long A,B,C,D,E,T;
231#ifndef MD32_XARRAY
232 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
233 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
234#else
235 SHA_LONG XX[16];
236#endif
237
238 A=c->h0;
239 B=c->h1;
240 C=c->h2;
241 D=c->h3;
242 E=c->h4;
243
244 for (;;)
245 {
246 BODY_00_15( 0,A,B,C,D,E,T,W[ 0]);
247 BODY_00_15( 1,T,A,B,C,D,E,W[ 1]);
248 BODY_00_15( 2,E,T,A,B,C,D,W[ 2]);
249 BODY_00_15( 3,D,E,T,A,B,C,W[ 3]);
250 BODY_00_15( 4,C,D,E,T,A,B,W[ 4]);
251 BODY_00_15( 5,B,C,D,E,T,A,W[ 5]);
252 BODY_00_15( 6,A,B,C,D,E,T,W[ 6]);
253 BODY_00_15( 7,T,A,B,C,D,E,W[ 7]);
254 BODY_00_15( 8,E,T,A,B,C,D,W[ 8]);
255 BODY_00_15( 9,D,E,T,A,B,C,W[ 9]);
256 BODY_00_15(10,C,D,E,T,A,B,W[10]);
257 BODY_00_15(11,B,C,D,E,T,A,W[11]);
258 BODY_00_15(12,A,B,C,D,E,T,W[12]);
259 BODY_00_15(13,T,A,B,C,D,E,W[13]);
260 BODY_00_15(14,E,T,A,B,C,D,W[14]);
261 BODY_00_15(15,D,E,T,A,B,C,W[15]);
262
263 BODY_16_19(16,C,D,E,T,A,B,X( 0),W[ 0],W[ 2],W[ 8],W[13]);
264 BODY_16_19(17,B,C,D,E,T,A,X( 1),W[ 1],W[ 3],W[ 9],W[14]);
265 BODY_16_19(18,A,B,C,D,E,T,X( 2),W[ 2],W[ 4],W[10],W[15]);
266 BODY_16_19(19,T,A,B,C,D,E,X( 3),W[ 3],W[ 5],W[11],X( 0));
267
268 BODY_20_31(20,E,T,A,B,C,D,X( 4),W[ 4],W[ 6],W[12],X( 1));
269 BODY_20_31(21,D,E,T,A,B,C,X( 5),W[ 5],W[ 7],W[13],X( 2));
270 BODY_20_31(22,C,D,E,T,A,B,X( 6),W[ 6],W[ 8],W[14],X( 3));
271 BODY_20_31(23,B,C,D,E,T,A,X( 7),W[ 7],W[ 9],W[15],X( 4));
272 BODY_20_31(24,A,B,C,D,E,T,X( 8),W[ 8],W[10],X( 0),X( 5));
273 BODY_20_31(25,T,A,B,C,D,E,X( 9),W[ 9],W[11],X( 1),X( 6));
274 BODY_20_31(26,E,T,A,B,C,D,X(10),W[10],W[12],X( 2),X( 7));
275 BODY_20_31(27,D,E,T,A,B,C,X(11),W[11],W[13],X( 3),X( 8));
276 BODY_20_31(28,C,D,E,T,A,B,X(12),W[12],W[14],X( 4),X( 9));
277 BODY_20_31(29,B,C,D,E,T,A,X(13),W[13],W[15],X( 5),X(10));
278 BODY_20_31(30,A,B,C,D,E,T,X(14),W[14],X( 0),X( 6),X(11));
279 BODY_20_31(31,T,A,B,C,D,E,X(15),W[15],X( 1),X( 7),X(12));
280
281 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
282 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
283 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
284 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
285 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
286 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
287 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
288 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
289
290 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
291 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
292 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
293 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
294 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
295 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
296 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
297 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
298 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
299 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
300 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
301 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
302 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
303 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
304 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
305 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
306 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
307 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
308 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
309 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
310
311 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
312 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
313 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
314 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
315 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
316 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
317 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
318 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
319 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
320 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
321 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
322 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
323 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
324 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
325 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
326 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
327 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
328 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
329 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
330 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
331
332 c->h0=(c->h0+E)&0xffffffffL;
333 c->h1=(c->h1+T)&0xffffffffL;
334 c->h2=(c->h2+A)&0xffffffffL;
335 c->h3=(c->h3+B)&0xffffffffL;
336 c->h4=(c->h4+C)&0xffffffffL;
337
338 if (--num <= 0) break;
339
340 A=c->h0;
341 B=c->h1;
342 C=c->h2;
343 D=c->h3;
344 E=c->h4;
345
346 W+=SHA_LBLOCK;
347 }
348 }
349#endif
350
351#ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER
352void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num)
353 {
354 const unsigned char *data=p;
355 register unsigned long A,B,C,D,E,T,l;
356#ifndef MD32_XARRAY
357 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
358 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
359#else
360 SHA_LONG XX[16];
361#endif
362
363 A=c->h0;
364 B=c->h1;
365 C=c->h2;
366 D=c->h3;
367 E=c->h4;
368
369 for (;;)
370 {
371
372 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
373 BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l;
374 BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l;
375 BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l;
376 BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l;
377 BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l;
378 BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l;
379 BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l;
380 BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l;
381 BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l;
382 BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l;
383 BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l;
384 BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l;
385 BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l;
386 BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l;
387 BODY_00_15(14,E,T,A,B,C,D,X(14));
388 BODY_00_15(15,D,E,T,A,B,C,X(15));
389
390 BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13));
391 BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14));
392 BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15));
393 BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0));
394
395 BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1));
396 BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2));
397 BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3));
398 BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4));
399 BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5));
400 BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6));
401 BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7));
402 BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8));
403 BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9));
404 BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10));
405 BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11));
406 BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12));
407
408 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
409 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
410 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
411 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
412 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
413 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
414 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
415 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
416
417 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
418 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
419 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
420 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
421 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
422 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
423 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
424 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
425 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
426 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
427 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
428 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
429 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
430 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
431 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
432 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
433 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
434 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
435 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
436 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
437
438 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
439 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
440 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
441 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
442 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
443 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
444 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
445 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
446 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
447 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
448 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
449 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
450 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
451 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
452 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
453 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
454 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
455 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
456 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
457 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
458
459 c->h0=(c->h0+E)&0xffffffffL;
460 c->h1=(c->h1+T)&0xffffffffL;
461 c->h2=(c->h2+A)&0xffffffffL;
462 c->h3=(c->h3+B)&0xffffffffL;
463 c->h4=(c->h4+C)&0xffffffffL;
464
465 if (--num <= 0) break;
466
467 A=c->h0;
468 B=c->h1;
469 C=c->h2;
470 D=c->h3;
471 E=c->h4;
472
473 }
474 }
475#endif
diff --git a/src/lib/libcrypto/sha/shatest.c b/src/lib/libcrypto/sha/shatest.c
index 2b0744d937..a5786bbf76 100644
--- a/src/lib/libcrypto/sha/shatest.c
+++ b/src/lib/libcrypto/sha/shatest.c
@@ -76,26 +76,26 @@ int main(int argc, char *argv[])
76#define SHA_0 /* FIPS 180 */ 76#define SHA_0 /* FIPS 180 */
77#undef SHA_1 /* FIPS 180-1 */ 77#undef SHA_1 /* FIPS 180-1 */
78 78
79char *test[]={ 79static char *test[]={
80 "abc", 80 "abc",
81 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 81 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
82 NULL, 82 NULL,
83 }; 83 };
84 84
85#ifdef SHA_0 85#ifdef SHA_0
86char *ret[]={ 86static char *ret[]={
87 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", 87 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
88 "d2516ee1acfa5baf33dfc1c471e438449ef134c8", 88 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
89 }; 89 };
90char *bigret= 90static char *bigret=
91 "3232affa48628a26653b5aaa44541fd90d690603"; 91 "3232affa48628a26653b5aaa44541fd90d690603";
92#endif 92#endif
93#ifdef SHA_1 93#ifdef SHA_1
94char *ret[]={ 94static char *ret[]={
95 "a9993e364706816aba3e25717850c26c9cd0d89d", 95 "a9993e364706816aba3e25717850c26c9cd0d89d",
96 "84983e441c3bd26ebaae4aa1f95129e5e54670f1", 96 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
97 }; 97 };
98char *bigret= 98static char *bigret=
99 "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; 99 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
100#endif 100#endif
101 101
diff --git a/src/lib/libcrypto/stack/Makefile.ssl b/src/lib/libcrypto/stack/Makefile.ssl
index faed4d0364..64a93b33ac 100644
--- a/src/lib/libcrypto/stack/Makefile.ssl
+++ b/src/lib/libcrypto/stack/Makefile.ssl
@@ -82,4 +82,5 @@ stack.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82stack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 82stack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83stack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 83stack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84stack.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 84stack.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
85stack.o: ../../include/openssl/stack.h ../cryptlib.h 85stack.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
86stack.o: ../cryptlib.h
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c
index 8b96713884..58e9126339 100644
--- a/src/lib/libcrypto/stack/stack.c
+++ b/src/lib/libcrypto/stack/stack.c
@@ -59,7 +59,7 @@
59/* Code for stacks 59/* Code for stacks
60 * Author - Eric Young v 1.0 60 * Author - Eric Young v 1.0
61 * 1.2 eay 12-Mar-97 - Modified sk_find so that it _DOES_ return the 61 * 1.2 eay 12-Mar-97 - Modified sk_find so that it _DOES_ return the
62 * lowest index for the seached item. 62 * lowest index for the searched item.
63 * 63 *
64 * 1.1 eay - Take from netdb and added to SSLeay 64 * 1.1 eay - Take from netdb and added to SSLeay
65 * 65 *
@@ -126,7 +126,7 @@ STACK *sk_new(int (*c)())
126 ret->sorted=0; 126 ret->sorted=0;
127 return(ret); 127 return(ret);
128err1: 128err1:
129 Free((char *)ret); 129 Free(ret);
130err0: 130err0:
131 return(NULL); 131 return(NULL);
132 } 132 }
@@ -276,8 +276,8 @@ void sk_pop_free(STACK *st, void (*func)())
276void sk_free(STACK *st) 276void sk_free(STACK *st)
277 { 277 {
278 if (st == NULL) return; 278 if (st == NULL) return;
279 if (st->data != NULL) Free((char *)st->data); 279 if (st->data != NULL) Free(st->data);
280 Free((char *)st); 280 Free(st);
281 } 281 }
282 282
283int sk_num(STACK *st) 283int sk_num(STACK *st)
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h
index 0f825cc0c4..a615d9b4c9 100644
--- a/src/lib/libcrypto/stack/stack.h
+++ b/src/lib/libcrypto/stack/stack.h
@@ -76,8 +76,8 @@ typedef struct stack_st
76 76
77#define sk_new_null() sk_new(NULL) 77#define sk_new_null() sk_new(NULL)
78 78
79#define M_sk_num(sk) ((sk)->num) 79#define M_sk_num(sk) ((sk) ? (sk)->num:-1)
80#define M_sk_value(sk,n) ((sk)->data[n]) 80#define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL)
81 81
82int sk_num(STACK *); 82int sk_num(STACK *);
83char *sk_value(STACK *, int); 83char *sk_value(STACK *, int);
diff --git a/src/lib/libcrypto/threads/README b/src/lib/libcrypto/threads/README
new file mode 100644
index 0000000000..df6b26e146
--- /dev/null
+++ b/src/lib/libcrypto/threads/README
@@ -0,0 +1,14 @@
1Mutithreading testing area.
2
3Since this stuff is very very platorm specific, this is not part of the
4normal build. Have a read of doc/threads.doc.
5
6mttest will do some testing and will currently build under Windows NT/95,
7Solaris and Linux. The IRIX stuff is not finished.
8
9I have tested this program on a 12 CPU ultra sparc box (solaris 2.5.1)
10and things seem to work ok.
11
12The Linux pthreads package can be retrieved from
13http://www.mit.edu:8001/people/proven/pthreads.html
14
diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c
index 142623edda..24713a3157 100644
--- a/src/lib/libcrypto/threads/mttest.c
+++ b/src/lib/libcrypto/threads/mttest.c
@@ -74,26 +74,29 @@
74#include <ulocks.h> 74#include <ulocks.h>
75#include <sys/prctl.h> 75#include <sys/prctl.h>
76#endif 76#endif
77#ifdef PTHREADS
78#include <pthread.h>
79#endif
77#include <openssl/lhash.h> 80#include <openssl/lhash.h>
78#include <openssl/crypto.h> 81#include <openssl/crypto.h>
79#include <openssl/buffer.h> 82#include <openssl/buffer.h>
80#include "../e_os.h" 83#include "../../e_os.h"
81#include <openssl/x509.h> 84#include <openssl/x509.h>
82#include <openssl/ssl.h> 85#include <openssl/ssl.h>
83#include <openssl/err.h> 86#include <openssl/err.h>
87#include <openssl/rand.h>
84 88
85#ifdef NO_FP_API 89#ifdef NO_FP_API
86#define APPS_WIN16 90#define APPS_WIN16
87#include "../crypto/buffer/bss_file.c" 91#include "../buffer/bss_file.c"
88#endif 92#endif
89 93
90#define TEST_SERVER_CERT "../apps/server.pem" 94#define TEST_SERVER_CERT "../../apps/server.pem"
91#define TEST_CLIENT_CERT "../apps/client.pem" 95#define TEST_CLIENT_CERT "../../apps/client.pem"
92 96
93#define MAX_THREAD_NUMBER 100 97#define MAX_THREAD_NUMBER 100
94 98
95int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, 99int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *xs);
96 int error,char *arg);
97void thread_setup(void); 100void thread_setup(void);
98void thread_cleanup(void); 101void thread_cleanup(void);
99void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); 102void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx);
@@ -121,6 +124,8 @@ int number_of_loops=10;
121int reconnect=0; 124int reconnect=0;
122int cache_stats=0; 125int cache_stats=0;
123 126
127static const char rnd_seed[] = "string to make the random number generator think it has entropy";
128
124int doit(char *ctx[4]); 129int doit(char *ctx[4]);
125static void print_stats(FILE *fp, SSL_CTX *ctx) 130static void print_stats(FILE *fp, SSL_CTX *ctx)
126{ 131{
@@ -170,6 +175,8 @@ int main(int argc, char *argv[])
170 char *ccert=TEST_CLIENT_CERT; 175 char *ccert=TEST_CLIENT_CERT;
171 SSL_METHOD *ssl_method=SSLv23_method(); 176 SSL_METHOD *ssl_method=SSLv23_method();
172 177
178 RAND_seed(rnd_seed, sizeof rnd_seed);
179
173 if (bio_err == NULL) 180 if (bio_err == NULL)
174 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 181 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
175 if (bio_stdout == NULL) 182 if (bio_stdout == NULL)
@@ -244,7 +251,7 @@ bad:
244 if (cipher == NULL) cipher=getenv("SSL_CIPHER"); 251 if (cipher == NULL) cipher=getenv("SSL_CIPHER");
245 252
246 SSL_load_error_strings(); 253 SSL_load_error_strings();
247 SSLeay_add_ssl_algorithms(); 254 OpenSSL_add_ssl_algorithms();
248 255
249 c_ctx=SSL_CTX_new(ssl_method); 256 c_ctx=SSL_CTX_new(ssl_method);
250 s_ctx=SSL_CTX_new(ssl_method); 257 s_ctx=SSL_CTX_new(ssl_method);
@@ -259,8 +266,15 @@ bad:
259 SSL_CTX_set_session_cache_mode(c_ctx, 266 SSL_CTX_set_session_cache_mode(c_ctx,
260 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); 267 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER);
261 268
262 SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM); 269 if (!SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM))
263 SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM); 270 {
271 ERR_print_errors(bio_err);
272 }
273 else if (!SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM))
274 {
275 ERR_print_errors(bio_err);
276 goto end;
277 }
264 278
265 if (client_auth) 279 if (client_auth)
266 { 280 {
@@ -489,6 +503,7 @@ int doit(char *ctx[4])
489 else 503 else
490 { 504 {
491 fprintf(stderr,"ERROR in CLIENT\n"); 505 fprintf(stderr,"ERROR in CLIENT\n");
506 ERR_print_errors_fp(stderr);
492 return(1); 507 return(1);
493 } 508 }
494 } 509 }
@@ -520,6 +535,7 @@ int doit(char *ctx[4])
520 else 535 else
521 { 536 {
522 fprintf(stderr,"ERROR in CLIENT\n"); 537 fprintf(stderr,"ERROR in CLIENT\n");
538 ERR_print_errors_fp(stderr);
523 return(1); 539 return(1);
524 } 540 }
525 } 541 }
@@ -652,18 +668,23 @@ err:
652 return(0); 668 return(0);
653 } 669 }
654 670
655int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, 671int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
656 int error, char *arg)
657 { 672 {
658 char buf[256]; 673 char *s, buf[256];
659 674
660 if (verbose) 675 if (verbose)
661 { 676 {
662 X509_NAME_oneline(X509_get_subject_name(xs),buf,256); 677 s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),
663 if (ok) 678 buf,256);
664 fprintf(stderr,"depth=%d %s\n",depth,buf); 679 if (s != NULL)
665 else 680 {
666 fprintf(stderr,"depth=%d error=%d %s\n",depth,error,buf); 681 if (ok)
682 fprintf(stderr,"depth=%d %s\n",
683 ctx->error_depth,buf);
684 else
685 fprintf(stderr,"depth=%d error=%d %s\n",
686 ctx->error_depth,ctx->error,buf);
687 }
667 } 688 }
668 return(ok); 689 return(ok);
669 } 690 }
@@ -672,13 +693,14 @@ int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
672 693
673#ifdef WIN32 694#ifdef WIN32
674 695
675static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; 696static HANDLE *lock_cs;
676 697
677void thread_setup(void) 698void thread_setup(void)
678 { 699 {
679 int i; 700 int i;
680 701
681 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 702 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE));
703 for (i=0; i<CRYPTO_num_locks(); i++)
682 { 704 {
683 lock_cs[i]=CreateMutex(NULL,FALSE,NULL); 705 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
684 } 706 }
@@ -692,8 +714,9 @@ void thread_cleanup(void)
692 int i; 714 int i;
693 715
694 CRYPTO_set_locking_callback(NULL); 716 CRYPTO_set_locking_callback(NULL);
695 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 717 for (i=0; i<CRYPTO_num_locks(); i++)
696 CloseHandle(lock_cs[i]); 718 CloseHandle(lock_cs[i]);
719 Free(lock_cs);
697 } 720 }
698 721
699void win32_locking_callback(int mode, int type, char *file, int line) 722void win32_locking_callback(int mode, int type, char *file, int line)
@@ -763,15 +786,17 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
763 786
764#ifdef SOLARIS 787#ifdef SOLARIS
765 788
766static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 789static mutex_t *lock_cs;
767/*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */ 790/*static rwlock_t *lock_cs; */
768static long lock_count[CRYPTO_NUM_LOCKS]; 791static long *lock_count;
769 792
770void thread_setup(void) 793void thread_setup(void)
771 { 794 {
772 int i; 795 int i;
773 796
774 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 797 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t));
798 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
799 for (i=0; i<CRYPTO_num_locks(); i++)
775 { 800 {
776 lock_count[i]=0; 801 lock_count[i]=0;
777 /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */ 802 /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */
@@ -787,31 +812,37 @@ void thread_cleanup(void)
787 int i; 812 int i;
788 813
789 CRYPTO_set_locking_callback(NULL); 814 CRYPTO_set_locking_callback(NULL);
790fprintf(stderr,"cleanup\n"); 815
791 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 816 fprintf(stderr,"cleanup\n");
817
818 for (i=0; i<CRYPTO_num_locks(); i++)
792 { 819 {
793 /* rwlock_destroy(&(lock_cs[i])); */ 820 /* rwlock_destroy(&(lock_cs[i])); */
794 mutex_destroy(&(lock_cs[i])); 821 mutex_destroy(&(lock_cs[i]));
795 fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i)); 822 fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i));
796 } 823 }
797fprintf(stderr,"done cleanup\n"); 824 Free(lock_cs);
825 Free(lock_count);
826
827 fprintf(stderr,"done cleanup\n");
828
798 } 829 }
799 830
800void solaris_locking_callback(int mode, int type, char *file, int line) 831void solaris_locking_callback(int mode, int type, char *file, int line)
801 { 832 {
802#ifdef undef 833#ifdef undef
803fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", 834 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
804 CRYPTO_thread_id(), 835 CRYPTO_thread_id(),
805 (mode&CRYPTO_LOCK)?"l":"u", 836 (mode&CRYPTO_LOCK)?"l":"u",
806 (type&CRYPTO_READ)?"r":"w",file,line); 837 (type&CRYPTO_READ)?"r":"w",file,line);
807#endif 838#endif
808 839
809/* 840 /*
810if (CRYPTO_LOCK_SSL_CERT == type) 841 if (CRYPTO_LOCK_SSL_CERT == type)
811 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", 842 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
812 CRYPTO_thread_id(), 843 CRYPTO_thread_id(),
813 mode,file,line); 844 mode,file,line);
814*/ 845 */
815 if (mode & CRYPTO_LOCK) 846 if (mode & CRYPTO_LOCK)
816 { 847 {
817 /* if (mode & CRYPTO_READ) 848 /* if (mode & CRYPTO_READ)
@@ -871,7 +902,7 @@ unsigned long solaris_thread_id(void)
871 902
872 903
873static usptr_t *arena; 904static usptr_t *arena;
874static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; 905static usema_t **lock_cs;
875 906
876void thread_setup(void) 907void thread_setup(void)
877 { 908 {
@@ -888,7 +919,8 @@ void thread_setup(void)
888 arena=usinit(filename); 919 arena=usinit(filename);
889 unlink(filename); 920 unlink(filename);
890 921
891 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 922 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *));
923 for (i=0; i<CRYPTO_num_locks(); i++)
892 { 924 {
893 lock_cs[i]=usnewsema(arena,1); 925 lock_cs[i]=usnewsema(arena,1);
894 } 926 }
@@ -902,7 +934,7 @@ void thread_cleanup(void)
902 int i; 934 int i;
903 935
904 CRYPTO_set_locking_callback(NULL); 936 CRYPTO_set_locking_callback(NULL);
905 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 937 for (i=0; i<CRYPTO_num_locks(); i++)
906 { 938 {
907 char buf[10]; 939 char buf[10];
908 940
@@ -910,6 +942,7 @@ void thread_cleanup(void)
910 usdumpsema(lock_cs[i],stdout,buf); 942 usdumpsema(lock_cs[i],stdout,buf);
911 usfreesema(lock_cs[i],arena); 943 usfreesema(lock_cs[i],arena);
912 } 944 }
945 Free(lock_cs);
913 } 946 }
914 947
915void irix_locking_callback(int mode, int type, char *file, int line) 948void irix_locking_callback(int mode, int type, char *file, int line)
@@ -962,14 +995,16 @@ unsigned long irix_thread_id(void)
962 995
963#ifdef PTHREADS 996#ifdef PTHREADS
964 997
965static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 998static pthread_mutex_t *lock_cs;
966static long lock_count[CRYPTO_NUM_LOCKS]; 999static long *lock_count;
967 1000
968void thread_setup(void) 1001void thread_setup(void)
969 { 1002 {
970 int i; 1003 int i;
971 1004
972 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 1005 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
1006 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
1007 for (i=0; i<CRYPTO_num_locks(); i++)
973 { 1008 {
974 lock_count[i]=0; 1009 lock_count[i]=0;
975 pthread_mutex_init(&(lock_cs[i]),NULL); 1010 pthread_mutex_init(&(lock_cs[i]),NULL);
@@ -985,12 +1020,15 @@ void thread_cleanup(void)
985 1020
986 CRYPTO_set_locking_callback(NULL); 1021 CRYPTO_set_locking_callback(NULL);
987 fprintf(stderr,"cleanup\n"); 1022 fprintf(stderr,"cleanup\n");
988 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 1023 for (i=0; i<CRYPTO_num_locks(); i++)
989 { 1024 {
990 pthread_mutex_destroy(&(lock_cs[i])); 1025 pthread_mutex_destroy(&(lock_cs[i]));
991 fprintf(stderr,"%8ld:%s\n",lock_count[i], 1026 fprintf(stderr,"%8ld:%s\n",lock_count[i],
992 CRYPTO_get_lock_name(i)); 1027 CRYPTO_get_lock_name(i));
993 } 1028 }
1029 Free(lock_cs);
1030 Free(lock_count);
1031
994 fprintf(stderr,"done cleanup\n"); 1032 fprintf(stderr,"done cleanup\n");
995 } 1033 }
996 1034
@@ -1045,7 +1083,7 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
1045 } 1083 }
1046 1084
1047 printf("pthreads threads done (%d,%d)\n", 1085 printf("pthreads threads done (%d,%d)\n",
1048 s_ctx->references,c_ctx->references); 1086 s_ctx->references,c_ctx->references);
1049 } 1087 }
1050 1088
1051unsigned long pthreads_thread_id(void) 1089unsigned long pthreads_thread_id(void)
diff --git a/src/lib/libcrypto/threads/profile.sh b/src/lib/libcrypto/threads/profile.sh
new file mode 100644
index 0000000000..6e3e342fc0
--- /dev/null
+++ b/src/lib/libcrypto/threads/profile.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -p -DSOLARIS -I../../include -g mttest.c -o mttest -L/usr/lib/libc -ldl -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/ptest.bat b/src/lib/libcrypto/threads/ptest.bat
new file mode 100644
index 0000000000..4071b5ffea
--- /dev/null
+++ b/src/lib/libcrypto/threads/ptest.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3purify cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssl32.lib ..\..\out\crypt32.lib
4
diff --git a/src/lib/libcrypto/threads/pthread.sh b/src/lib/libcrypto/threads/pthread.sh
new file mode 100644
index 0000000000..f1c49821d2
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthread.sh
@@ -0,0 +1,9 @@
1#!/bin/sh
2#
3# build using pthreads
4#
5# http://www.mit.edu:8001/people/proven/pthreads.html
6#
7/bin/rm -f mttest
8pgcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto
9
diff --git a/src/lib/libcrypto/threads/pthread2.sh b/src/lib/libcrypto/threads/pthread2.sh
new file mode 100644
index 0000000000..41264c6a50
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthread2.sh
@@ -0,0 +1,7 @@
1#!/bin/sh
2#
3# build using pthreads where it's already built into the system
4#
5/bin/rm -f mttest
6gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -lpthread
7
diff --git a/src/lib/libcrypto/threads/pthreads-vms.com b/src/lib/libcrypto/threads/pthreads-vms.com
new file mode 100644
index 0000000000..63f5b8cc2e
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthreads-vms.com
@@ -0,0 +1,9 @@
1$! To compile mttest on VMS.
2$!
3$! WARNING: only tested with DEC C so far.
4$
5$ arch := vax
6$ if f$getsyi("CPU") .ge. 128 then arch := axp
7$ define/user openssl [--.include.openssl]
8$ cc/def=PTHREADS mttest.c
9$ link mttest,[--.'arch'.exe.ssl]libssl/lib,[--.'arch'.exe.crypto]libcrypto/lib
diff --git a/src/lib/libcrypto/threads/purify.sh b/src/lib/libcrypto/threads/purify.sh
new file mode 100644
index 0000000000..6d44fe26b7
--- /dev/null
+++ b/src/lib/libcrypto/threads/purify.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3purify cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/solaris.sh b/src/lib/libcrypto/threads/solaris.sh
new file mode 100644
index 0000000000..bc93094a27
--- /dev/null
+++ b/src/lib/libcrypto/threads/solaris.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/th-lock.c b/src/lib/libcrypto/threads/th-lock.c
index afb4f4caf2..3ee978060c 100644
--- a/src/lib/libcrypto/threads/th-lock.c
+++ b/src/lib/libcrypto/threads/th-lock.c
@@ -74,6 +74,9 @@
74#include <ulocks.h> 74#include <ulocks.h>
75#include <sys/prctl.h> 75#include <sys/prctl.h>
76#endif 76#endif
77#ifdef PTHREADS
78#include <pthread.h>
79#endif
77#include <openssl/lhash.h> 80#include <openssl/lhash.h>
78#include <openssl/crypto.h> 81#include <openssl/crypto.h>
79#include <openssl/buffer.h> 82#include <openssl/buffer.h>
@@ -82,7 +85,7 @@
82#include <openssl/ssl.h> 85#include <openssl/ssl.h>
83#include <openssl/err.h> 86#include <openssl/err.h>
84 87
85int CRYPTO_thread_setup(void); 88void CRYPTO_thread_setup(void);
86void CRYPTO_thread_cleanup(void); 89void CRYPTO_thread_cleanup(void);
87 90
88static void irix_locking_callback(int mode,int type,char *file,int line); 91static void irix_locking_callback(int mode,int type,char *file,int line);
@@ -96,7 +99,7 @@ static unsigned long pthreads_thread_id(void );
96 99
97/* usage: 100/* usage:
98 * CRYPTO_thread_setup(); 101 * CRYPTO_thread_setup();
99 * applicaion code 102 * application code
100 * CRYPTO_thread_cleanup(); 103 * CRYPTO_thread_cleanup();
101 */ 104 */
102 105
@@ -104,13 +107,14 @@ static unsigned long pthreads_thread_id(void );
104 107
105#ifdef WIN32 108#ifdef WIN32
106 109
107static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; 110static HANDLE *lock_cs;
108 111
109int CRYPTO_thread_setup(void) 112void CRYPTO_thread_setup(void)
110 { 113 {
111 int i; 114 int i;
112 115
113 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 116 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE));
117 for (i=0; i<CRYPTO_num_locks(); i++)
114 { 118 {
115 lock_cs[i]=CreateMutex(NULL,FALSE,NULL); 119 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
116 } 120 }
@@ -125,8 +129,9 @@ static void CRYPTO_thread_cleanup(void)
125 int i; 129 int i;
126 130
127 CRYPTO_set_locking_callback(NULL); 131 CRYPTO_set_locking_callback(NULL);
128 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 132 for (i=0; i<CRYPTO_num_locks(); i++)
129 CloseHandle(lock_cs[i]); 133 CloseHandle(lock_cs[i]);
134 Free(lock_cs);
130 } 135 }
131 136
132void win32_locking_callback(int mode, int type, char *file, int line) 137void win32_locking_callback(int mode, int type, char *file, int line)
@@ -147,18 +152,24 @@ void win32_locking_callback(int mode, int type, char *file, int line)
147 152
148#define USE_MUTEX 153#define USE_MUTEX
149 154
150static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
151#ifdef USE_MUTEX 155#ifdef USE_MUTEX
152static long lock_count[CRYPTO_NUM_LOCKS]; 156static mutex_t *lock_cs;
153#else 157#else
154static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; 158static rwlock_t *lock_cs;
155#endif 159#endif
160static long *lock_count;
156 161
157void CRYPTO_thread_setup(void) 162void CRYPTO_thread_setup(void)
158 { 163 {
159 int i; 164 int i;
160 165
161 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 166#ifdef USE_MUTEX
167 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t));
168#else
169 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(rwlock_t));
170#endif
171 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
172 for (i=0; i<CRYPTO_num_locks(); i++)
162 { 173 {
163 lock_count[i]=0; 174 lock_count[i]=0;
164#ifdef USE_MUTEX 175#ifdef USE_MUTEX
@@ -177,7 +188,7 @@ void CRYPTO_thread_cleanup(void)
177 int i; 188 int i;
178 189
179 CRYPTO_set_locking_callback(NULL); 190 CRYPTO_set_locking_callback(NULL);
180 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 191 for (i=0; i<CRYPTO_num_locks(); i++)
181 { 192 {
182#ifdef USE_MUTEX 193#ifdef USE_MUTEX
183 mutex_destroy(&(lock_cs[i])); 194 mutex_destroy(&(lock_cs[i]));
@@ -185,6 +196,8 @@ void CRYPTO_thread_cleanup(void)
185 rwlock_destroy(&(lock_cs[i])); 196 rwlock_destroy(&(lock_cs[i]));
186#endif 197#endif
187 } 198 }
199 Free(lock_cs);
200 Free(lock_count);
188 } 201 }
189 202
190void solaris_locking_callback(int mode, int type, char *file, int line) 203void solaris_locking_callback(int mode, int type, char *file, int line)
@@ -237,7 +250,7 @@ unsigned long solaris_thread_id(void)
237/* I don't think this works..... */ 250/* I don't think this works..... */
238 251
239static usptr_t *arena; 252static usptr_t *arena;
240static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; 253static usema_t **lock_cs;
241 254
242void CRYPTO_thread_setup(void) 255void CRYPTO_thread_setup(void)
243 { 256 {
@@ -254,7 +267,8 @@ void CRYPTO_thread_setup(void)
254 arena=usinit(filename); 267 arena=usinit(filename);
255 unlink(filename); 268 unlink(filename);
256 269
257 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 270 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *));
271 for (i=0; i<CRYPTO_num_locks(); i++)
258 { 272 {
259 lock_cs[i]=usnewsema(arena,1); 273 lock_cs[i]=usnewsema(arena,1);
260 } 274 }
@@ -268,7 +282,7 @@ void CRYPTO_thread_cleanup(void)
268 int i; 282 int i;
269 283
270 CRYPTO_set_locking_callback(NULL); 284 CRYPTO_set_locking_callback(NULL);
271 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 285 for (i=0; i<CRYPTO_num_locks(); i++)
272 { 286 {
273 char buf[10]; 287 char buf[10];
274 288
@@ -276,6 +290,7 @@ void CRYPTO_thread_cleanup(void)
276 usdumpsema(lock_cs[i],stdout,buf); 290 usdumpsema(lock_cs[i],stdout,buf);
277 usfreesema(lock_cs[i],arena); 291 usfreesema(lock_cs[i],arena);
278 } 292 }
293 Free(lock_cs);
279 } 294 }
280 295
281void irix_locking_callback(int mode, int type, char *file, int line) 296void irix_locking_callback(int mode, int type, char *file, int line)
@@ -302,14 +317,16 @@ unsigned long irix_thread_id(void)
302/* Linux and a few others */ 317/* Linux and a few others */
303#ifdef PTHREADS 318#ifdef PTHREADS
304 319
305static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 320static pthread_mutex_t *lock_cs;
306static long lock_count[CRYPTO_NUM_LOCKS]; 321static long *lock_count;
307 322
308void CRYPTO_thread_setup(void) 323void CRYPTO_thread_setup(void)
309 { 324 {
310 int i; 325 int i;
311 326
312 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 327 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
328 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
329 for (i=0; i<CRYPTO_num_locks(); i++)
313 { 330 {
314 lock_count[i]=0; 331 lock_count[i]=0;
315 pthread_mutex_init(&(lock_cs[i]),NULL); 332 pthread_mutex_init(&(lock_cs[i]),NULL);
@@ -324,10 +341,12 @@ void thread_cleanup(void)
324 int i; 341 int i;
325 342
326 CRYPTO_set_locking_callback(NULL); 343 CRYPTO_set_locking_callback(NULL);
327 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 344 for (i=0; i<CRYPTO_num_locks(); i++)
328 { 345 {
329 pthread_mutex_destroy(&(lock_cs[i])); 346 pthread_mutex_destroy(&(lock_cs[i]));
330 } 347 }
348 Free(lock_cs);
349 Free(lock_count);
331 } 350 }
332 351
333void pthreads_locking_callback(int mode, int type, char *file, 352void pthreads_locking_callback(int mode, int type, char *file,
diff --git a/src/lib/libcrypto/threads/win32.bat b/src/lib/libcrypto/threads/win32.bat
new file mode 100644
index 0000000000..ee6da80a07
--- /dev/null
+++ b/src/lib/libcrypto/threads/win32.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssleay32.lib ..\..\out\libeay32.lib
4
diff --git a/src/lib/libcrypto/txt_db/Makefile.ssl b/src/lib/libcrypto/txt_db/Makefile.ssl
index 02b863bf89..a631dce6f2 100644
--- a/src/lib/libcrypto/txt_db/Makefile.ssl
+++ b/src/lib/libcrypto/txt_db/Makefile.ssl
@@ -82,5 +82,6 @@ txt_db.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82txt_db.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h 82txt_db.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83txt_db.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 83txt_db.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84txt_db.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 84txt_db.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
85txt_db.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 85txt_db.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
86txt_db.o: ../../include/openssl/txt_db.h ../cryptlib.h 86txt_db.o: ../../include/openssl/stack.h ../../include/openssl/txt_db.h
87txt_db.o: ../cryptlib.h
diff --git a/src/lib/libcrypto/txt_db/txt_db.c b/src/lib/libcrypto/txt_db/txt_db.c
index 9a9fa5ce55..33acc81f3f 100644
--- a/src/lib/libcrypto/txt_db/txt_db.c
+++ b/src/lib/libcrypto/txt_db/txt_db.c
@@ -181,7 +181,7 @@ err:
181#endif 181#endif
182 if (ret->data != NULL) sk_free(ret->data); 182 if (ret->data != NULL) sk_free(ret->data);
183 if (ret->index != NULL) Free(ret->index); 183 if (ret->index != NULL) Free(ret->index);
184 if (ret->qual != NULL) Free((char *)ret->qual); 184 if (ret->qual != NULL) Free(ret->qual);
185 if (ret != NULL) Free(ret); 185 if (ret != NULL) Free(ret);
186 return(NULL); 186 return(NULL);
187 } 187 }
@@ -205,7 +205,7 @@ char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value)
205 db->error=DB_ERROR_NO_INDEX; 205 db->error=DB_ERROR_NO_INDEX;
206 return(NULL); 206 return(NULL);
207 } 207 }
208 ret=(char **)lh_retrieve(lh,(char *)value); 208 ret=(char **)lh_retrieve(lh,value);
209 db->error=DB_ERROR_OK; 209 db->error=DB_ERROR_OK;
210 return(ret); 210 return(ret);
211 } 211 }
@@ -306,7 +306,7 @@ int TXT_DB_insert(TXT_DB *db, char **row)
306 { 306 {
307 if ((db->qual[i] != NULL) && 307 if ((db->qual[i] != NULL) &&
308 (db->qual[i](row) == 0)) continue; 308 (db->qual[i](row) == 0)) continue;
309 r=(char **)lh_retrieve(db->index[i],(char *)row); 309 r=(char **)lh_retrieve(db->index[i],row);
310 if (r != NULL) 310 if (r != NULL)
311 { 311 {
312 db->error=DB_ERROR_INDEX_CLASH; 312 db->error=DB_ERROR_INDEX_CLASH;
@@ -329,7 +329,7 @@ int TXT_DB_insert(TXT_DB *db, char **row)
329 { 329 {
330 if ((db->qual[i] != NULL) && 330 if ((db->qual[i] != NULL) &&
331 (db->qual[i](row) == 0)) continue; 331 (db->qual[i](row) == 0)) continue;
332 lh_insert(db->index[i],(char *)row); 332 lh_insert(db->index[i],row);
333 } 333 }
334 } 334 }
335 return(1); 335 return(1);
diff --git a/src/lib/libcrypto/util/domd b/src/lib/libcrypto/util/domd
index 324051f60b..9f75131f22 100644
--- a/src/lib/libcrypto/util/domd
+++ b/src/lib/libcrypto/util/domd
@@ -7,5 +7,5 @@ shift
7 7
8cp Makefile.ssl Makefile.save 8cp Makefile.ssl Makefile.save
9makedepend -f Makefile.ssl $@ 9makedepend -f Makefile.ssl $@
10$TOP/util/clean-depend.pl < Makefile.ssl > Makefile.new 10perl $TOP/util/clean-depend.pl < Makefile.ssl > Makefile.new
11mv Makefile.new Makefile.ssl 11mv Makefile.new Makefile.ssl
diff --git a/src/lib/libcrypto/util/libeay.num b/src/lib/libcrypto/util/libeay.num
index 59c2040a29..e3818ef6e4 100644
--- a/src/lib/libcrypto/util/libeay.num
+++ b/src/lib/libcrypto/util/libeay.num
@@ -499,9 +499,9 @@ SHA1_Update 504
499SHA_Final 505 499SHA_Final 505
500SHA_Init 506 500SHA_Init 506
501SHA_Update 507 501SHA_Update 507
502SSLeay_add_all_algorithms 508 502OpenSSL_add_all_algorithms 508
503SSLeay_add_all_ciphers 509 503OpenSSL_add_all_ciphers 509
504SSLeay_add_all_digests 510 504OpenSSL_add_all_digests 510
505TXT_DB_create_index 511 505TXT_DB_create_index 511
506TXT_DB_free 512 506TXT_DB_free 512
507TXT_DB_get_by_index 513 507TXT_DB_get_by_index 513
@@ -1304,13 +1304,12 @@ i2d_SXNETID 1329
1304d2i_SXNETID 1330 1304d2i_SXNETID 1330
1305SXNETID_new 1331 1305SXNETID_new 1331
1306SXNETID_free 1332 1306SXNETID_free 1332
1307DSA_SIG_new 1333 1307DSA_SIG_new 1333
1308DSA_SIG_free 1334 1308DSA_SIG_free 1334
1309DSA_do_sign 1335 1309DSA_do_sign 1335
1310DSA_do_verify 1336 1310DSA_do_verify 1336
1311d2i_DSA_SIG 1337 1311d2i_DSA_SIG 1337
1312i2d_DSA_SIG 1338 1312i2d_DSA_SIG 1338
1313
1314i2d_ASN1_VISIBLESTRING 1339 1313i2d_ASN1_VISIBLESTRING 1339
1315d2i_ASN1_VISIBLESTRING 1340 1314d2i_ASN1_VISIBLESTRING 1340
1316i2d_ASN1_UTF8STRING 1341 1315i2d_ASN1_UTF8STRING 1341
@@ -1844,3 +1843,387 @@ sk_DIST_POINT_sort 1868
1844RSA_check_key 1869 1843RSA_check_key 1869
1845OBJ_obj2txt 1870 1844OBJ_obj2txt 1870
1846DSA_dup_DH 1871 1845DSA_dup_DH 1871
1846X509_REQ_get_extensions 1872
1847X509_REQ_set_extension_nids 1873
1848BIO_nwrite 1874
1849X509_REQ_extension_nid 1875
1850BIO_nread 1876
1851X509_REQ_get_extension_nids 1877
1852BIO_nwrite0 1878
1853X509_REQ_add_extensions_nid 1879
1854BIO_nread0 1880
1855X509_REQ_add_extensions 1881
1856BIO_new_mem_buf 1882
1857DH_set_ex_data 1883
1858DH_set_method 1884
1859DSA_OpenSSL 1885
1860DH_get_ex_data 1886
1861DH_get_ex_new_index 1887
1862DSA_new_method 1888
1863DH_new_method 1889
1864DH_OpenSSL 1890
1865DSA_get_ex_new_index 1891
1866DH_get_default_method 1892
1867DSA_set_ex_data 1893
1868DH_set_default_method 1894
1869DSA_get_ex_data 1895
1870X509V3_EXT_REQ_add_conf 1896
1871NETSCAPE_SPKI_print 1897
1872NETSCAPE_SPKI_set_pubkey 1898
1873NETSCAPE_SPKI_b64_encode 1899
1874NETSCAPE_SPKI_get_pubkey 1900
1875NETSCAPE_SPKI_b64_decode 1901
1876UTF8_putc 1902
1877UTF8_getc 1903
1878RSA_null_method 1904
1879ASN1_tag2str 1905
1880BIO_ctrl_reset_read_request 1906
1881DISPLAYTEXT_new 1907
1882ASN1_GENERALIZEDTIME_free 1908
1883X509_REVOKED_get_ext_d2i 1909
1884X509_set_ex_data 1910
1885X509_reject_set_bit_asc 1911
1886X509_NAME_add_entry_by_txt 1912
1887sk_X509_TRUST_pop 1913
1888X509_NAME_add_entry_by_NID 1914
1889X509_PURPOSE_get0 1915
1890sk_ACCESS_DESCRIPTION_shift 1916
1891PEM_read_X509_AUX 1917
1892d2i_AUTHORITY_INFO_ACCESS 1918
1893sk_X509_TRUST_set_cmp_func 1919
1894sk_X509_TRUST_free 1920
1895PEM_write_PUBKEY 1921
1896sk_X509_TRUST_num 1922
1897sk_ACCESS_DESCRIPTION_delete 1923
1898sk_ASN1_STRING_TABLE_value 1924
1899ACCESS_DESCRIPTION_new 1925
1900X509_CERT_AUX_free 1926
1901d2i_ACCESS_DESCRIPTION 1927
1902X509_trust_clear 1928
1903sk_X509_PURPOSE_value 1929
1904sk_X509_PURPOSE_zero 1930
1905X509_TRUST_add 1931
1906ASN1_VISIBLESTRING_new 1932
1907X509_alias_set1 1933
1908ASN1_PRINTABLESTRING_free 1934
1909EVP_PKEY_get1_DSA 1935
1910ASN1_BMPSTRING_new 1936
1911ASN1_mbstring_copy 1937
1912ASN1_UTF8STRING_new 1938
1913sk_ACCESS_DESCRIPTION_set 1939
1914sk_X509_PURPOSE_pop 1940
1915DSA_get_default_method 1941
1916sk_X509_PURPOSE_push 1942
1917sk_X509_PURPOSE_delete 1943
1918sk_X509_PURPOSE_num 1944
1919i2d_ASN1_SET_OF_ACCESS_DESCRIPTION 1945
1920ASN1_T61STRING_free 1946
1921sk_ACCESS_DESCRIPTION_free 1947
1922sk_ASN1_STRING_TABLE_pop 1948
1923DSA_set_method 1949
1924X509_get_ex_data 1950
1925ASN1_STRING_type 1951
1926X509_PURPOSE_get_by_sname 1952
1927sk_X509_PURPOSE_find 1953
1928ASN1_TIME_free 1954
1929ASN1_OCTET_STRING_cmp 1955
1930sk_ACCESS_DESCRIPTION_value 1956
1931ASN1_BIT_STRING_new 1957
1932X509_get_ext_d2i 1958
1933PEM_read_bio_X509_AUX 1959
1934ASN1_STRING_set_default_mask_asc 1960
1935PEM_write_bio_RSA_PUBKEY 1961
1936sk_ASN1_STRING_TABLE_num 1962
1937ASN1_INTEGER_cmp 1963
1938d2i_RSA_PUBKEY_fp 1964
1939sk_ACCESS_DESCRIPTION_unshift 1965
1940sk_ASN1_STRING_TABLE_delete_ptr 1966
1941X509_trust_set_bit_asc 1967
1942PEM_write_bio_DSA_PUBKEY 1968
1943X509_STORE_CTX_free 1969
1944EVP_PKEY_set1_DSA 1970
1945i2d_DSA_PUBKEY_fp 1971
1946X509_load_cert_crl_file 1972
1947ASN1_TIME_new 1973
1948i2d_RSA_PUBKEY 1974
1949sk_X509_TRUST_pop_free 1975
1950X509_STORE_CTX_purpose_inherit 1976
1951PEM_read_RSA_PUBKEY 1977
1952sk_X509_TRUST_zero 1978
1953sk_ACCESS_DESCRIPTION_pop_free 1979
1954d2i_X509_AUX 1980
1955i2d_DSA_PUBKEY 1981
1956X509_CERT_AUX_print 1982
1957sk_X509_PURPOSE_new_null 1983
1958PEM_read_DSA_PUBKEY 1984
1959i2d_RSA_PUBKEY_bio 1985
1960ASN1_BIT_STRING_num_asc 1986
1961i2d_PUBKEY 1987
1962ASN1_UTCTIME_free 1988
1963DSA_set_default_method 1989
1964X509_PURPOSE_get_by_id 1990
1965sk_X509_TRUST_push 1991
1966sk_ASN1_STRING_TABLE_sort 1992
1967sk_X509_PURPOSE_set_cmp_func 1993
1968ACCESS_DESCRIPTION_free 1994
1969PEM_read_bio_PUBKEY 1995
1970ASN1_STRING_set_by_NID 1996
1971X509_PURPOSE_get_id 1997
1972DISPLAYTEXT_free 1998
1973OTHERNAME_new 1999
1974sk_X509_TRUST_find 2000
1975X509_CERT_AUX_new 2001
1976sk_ACCESS_DESCRIPTION_dup 2002
1977sk_ASN1_STRING_TABLE_pop_free 2003
1978sk_ASN1_STRING_TABLE_unshift 2004
1979sk_X509_TRUST_shift 2005
1980sk_ACCESS_DESCRIPTION_zero 2006
1981X509_TRUST_cleanup 2007
1982X509_NAME_add_entry_by_OBJ 2008
1983X509_CRL_get_ext_d2i 2009
1984sk_X509_TRUST_set 2010
1985X509_PURPOSE_get0_name 2011
1986PEM_read_PUBKEY 2012
1987sk_ACCESS_DESCRIPTION_new 2013
1988i2d_DSA_PUBKEY_bio 2014
1989i2d_OTHERNAME 2015
1990ASN1_OCTET_STRING_free 2016
1991ASN1_BIT_STRING_set_asc 2017
1992sk_ACCESS_DESCRIPTION_push 2018
1993X509_get_ex_new_index 2019
1994ASN1_STRING_TABLE_cleanup 2020
1995X509_TRUST_get_by_id 2021
1996X509_PURPOSE_get_trust 2022
1997ASN1_STRING_length 2023
1998d2i_ASN1_SET_OF_ACCESS_DESCRIPTION 2024
1999ASN1_PRINTABLESTRING_new 2025
2000X509V3_get_d2i 2026
2001ASN1_ENUMERATED_free 2027
2002i2d_X509_CERT_AUX 2028
2003sk_ACCESS_DESCRIPTION_find 2029
2004X509_STORE_CTX_set_trust 2030
2005sk_X509_PURPOSE_unshift 2031
2006ASN1_STRING_set_default_mask 2032
2007X509_STORE_CTX_new 2033
2008EVP_PKEY_get1_RSA 2034
2009sk_X509_PURPOSE_set 2035
2010sk_ASN1_STRING_TABLE_insert 2036
2011sk_X509_PURPOSE_sort 2037
2012DIRECTORYSTRING_free 2038
2013PEM_write_X509_AUX 2039
2014ASN1_OCTET_STRING_set 2040
2015d2i_DSA_PUBKEY_fp 2041
2016sk_ASN1_STRING_TABLE_free 2042
2017sk_X509_TRUST_value 2043
2018d2i_RSA_PUBKEY 2044
2019sk_ASN1_STRING_TABLE_set 2045
2020X509_TRUST_get0_name 2046
2021X509_TRUST_get0 2047
2022AUTHORITY_INFO_ACCESS_free 2048
2023ASN1_IA5STRING_new 2049
2024d2i_DSA_PUBKEY 2050
2025X509_check_purpose 2051
2026ASN1_ENUMERATED_new 2052
2027d2i_RSA_PUBKEY_bio 2053
2028d2i_PUBKEY 2054
2029X509_TRUST_get_trust 2055
2030X509_TRUST_get_flags 2056
2031ASN1_BMPSTRING_free 2057
2032ASN1_T61STRING_new 2058
2033sk_X509_TRUST_unshift 2059
2034ASN1_UTCTIME_new 2060
2035sk_ACCESS_DESCRIPTION_pop 2061
2036i2d_AUTHORITY_INFO_ACCESS 2062
2037EVP_PKEY_set1_RSA 2063
2038X509_STORE_CTX_set_purpose 2064
2039ASN1_IA5STRING_free 2065
2040PEM_write_bio_X509_AUX 2066
2041X509_PURPOSE_get_count 2067
2042CRYPTO_add_info 2068
2043sk_ACCESS_DESCRIPTION_num 2069
2044sk_ASN1_STRING_TABLE_set_cmp_func 2070
2045X509_NAME_ENTRY_create_by_txt 2071
2046ASN1_STRING_get_default_mask 2072
2047sk_X509_TRUST_dup 2073
2048X509_alias_get0 2074
2049ASN1_STRING_data 2075
2050sk_X509_TRUST_insert 2076
2051i2d_ACCESS_DESCRIPTION 2077
2052X509_trust_set_bit 2078
2053sk_X509_PURPOSE_delete_ptr 2079
2054ASN1_BIT_STRING_free 2080
2055PEM_read_bio_RSA_PUBKEY 2081
2056X509_add1_reject_object 2082
2057X509_check_trust 2083
2058sk_X509_TRUST_new_null 2084
2059sk_ACCESS_DESCRIPTION_new_null 2085
2060sk_ACCESS_DESCRIPTION_delete_ptr 2086
2061sk_X509_TRUST_sort 2087
2062PEM_read_bio_DSA_PUBKEY 2088
2063sk_X509_TRUST_new 2089
2064X509_PURPOSE_add 2090
2065ASN1_STRING_TABLE_get 2091
2066ASN1_UTF8STRING_free 2092
2067d2i_DSA_PUBKEY_bio 2093
2068sk_ASN1_STRING_TABLE_delete 2094
2069PEM_write_RSA_PUBKEY 2095
2070d2i_OTHERNAME 2096
2071sk_ACCESS_DESCRIPTION_insert 2097
2072X509_reject_set_bit 2098
2073sk_X509_TRUST_delete_ptr 2099
2074sk_X509_PURPOSE_pop_free 2100
2075PEM_write_DSA_PUBKEY 2101
2076sk_X509_PURPOSE_free 2102
2077sk_X509_PURPOSE_dup 2103
2078sk_ASN1_STRING_TABLE_zero 2104
2079X509_PURPOSE_get0_sname 2105
2080sk_ASN1_STRING_TABLE_shift 2106
2081EVP_PKEY_set1_DH 2107
2082ASN1_OCTET_STRING_dup 2108
2083ASN1_BIT_STRING_set 2109
2084X509_TRUST_get_count 2110
2085ASN1_INTEGER_free 2111
2086OTHERNAME_free 2112
2087i2d_RSA_PUBKEY_fp 2113
2088ASN1_INTEGER_dup 2114
2089d2i_X509_CERT_AUX 2115
2090sk_ASN1_STRING_TABLE_new_null 2116
2091PEM_write_bio_PUBKEY 2117
2092ASN1_VISIBLESTRING_free 2118
2093X509_PURPOSE_cleanup 2119
2094sk_ASN1_STRING_TABLE_push 2120
2095sk_ASN1_STRING_TABLE_dup 2121
2096sk_X509_PURPOSE_shift 2122
2097ASN1_mbstring_ncopy 2123
2098sk_X509_PURPOSE_new 2124
2099sk_X509_PURPOSE_insert 2125
2100ASN1_GENERALIZEDTIME_new 2126
2101sk_ACCESS_DESCRIPTION_sort 2127
2102EVP_PKEY_get1_DH 2128
2103sk_ACCESS_DESCRIPTION_set_cmp_func 2129
2104ASN1_OCTET_STRING_new 2130
2105ASN1_INTEGER_new 2131
2106i2d_X509_AUX 2132
2107sk_ASN1_STRING_TABLE_find 2133
2108ASN1_BIT_STRING_name_print 2134
2109X509_cmp 2135
2110ASN1_STRING_length_set 2136
2111DIRECTORYSTRING_new 2137
2112sk_ASN1_STRING_TABLE_new 2138
2113sk_X509_TRUST_delete 2139
2114X509_add1_trust_object 2140
2115PKCS12_newpass 2141
2116SMIME_write_PKCS7 2142
2117SMIME_read_PKCS7 2143
2118des_set_key_checked 2144
2119PKCS7_verify 2145
2120PKCS7_encrypt 2146
2121des_set_key_unchecked 2147
2122SMIME_crlf_copy 2148
2123i2d_ASN1_PRINTABLESTRING 2149
2124PKCS7_get0_signers 2150
2125PKCS7_decrypt 2151
2126SMIME_text 2152
2127PKCS7_simple_smimecap 2153
2128PKCS7_get_smimecap 2154
2129PKCS7_sign 2155
2130PKCS7_add_attrib_smimecap 2156
2131CRYPTO_dbg_set_options 2157
2132CRYPTO_remove_all_info 2158
2133CRYPTO_get_mem_debug_functions 2159
2134CRYPTO_is_mem_check_on 2160
2135CRYPTO_set_mem_debug_functions 2161
2136CRYPTO_pop_info 2162
2137CRYPTO_push_info_ 2163
2138CRYPTO_set_mem_debug_options 2164
2139PEM_write_PKCS8PrivateKey_nid 2165
2140PEM_write_bio_PKCS8PrivateKey_nid 2166
2141d2i_PKCS8PrivateKey_bio 2167
2142ASN1_NULL_free 2168
2143d2i_ASN1_NULL 2169
2144ASN1_NULL_new 2170
2145i2d_PKCS8PrivateKey_bio 2171
2146i2d_PKCS8PrivateKey_fp 2172
2147i2d_ASN1_NULL 2173
2148i2d_PKCS8PrivateKey_nid_fp 2174
2149d2i_PKCS8PrivateKey_fp 2175
2150i2d_PKCS8PrivateKey_nid_bio 2176
2151i2d_PKCS8PrivateKeyInfo_fp 2177
2152i2d_PKCS8PrivateKeyInfo_bio 2178
2153PEM_cb 2179
2154i2d_PrivateKey_fp 2180
2155d2i_PrivateKey_bio 2181
2156d2i_PrivateKey_fp 2182
2157i2d_PrivateKey_bio 2183
2158X509_reject_clear 2184
2159X509_TRUST_set_default 2185
2160d2i_AutoPrivateKey 2186
2161X509_ATTRIBUTE_get0_type 2187
2162X509_ATTRIBUTE_set1_data 2188
2163X509at_get_attr 2189
2164X509at_get_attr_count 2190
2165X509_ATTRIBUTE_create_by_NID 2191
2166X509_ATTRIBUTE_set1_object 2192
2167X509_ATTRIBUTE_count 2193
2168X509_ATTRIBUTE_create_by_OBJ 2194
2169X509_ATTRIBUTE_get0_object 2195
2170X509at_get_attr_by_NID 2196
2171X509at_add1_attr 2197
2172X509_ATTRIBUTE_get0_data 2198
2173X509at_delete_attr 2199
2174X509at_get_attr_by_OBJ 2200
2175RAND_add 2201
2176BIO_number_written 2202
2177BIO_number_read 2203
2178X509_STORE_CTX_get1_chain 2204
2179ERR_load_RAND_strings 2205
2180RAND_pseudo_bytes 2206
2181X509_REQ_get_attr_by_NID 2207
2182X509_REQ_get_attr 2208
2183X509_REQ_add1_attr_by_NID 2209
2184X509_REQ_get_attr_by_OBJ 2210
2185X509at_add1_attr_by_NID 2211
2186X509_REQ_add1_attr_by_OBJ 2212
2187X509_REQ_get_attr_count 2213
2188X509_REQ_add1_attr 2214
2189X509_REQ_delete_attr 2215
2190X509at_add1_attr_by_OBJ 2216
2191X509_REQ_add1_attr_by_txt 2217
2192X509_ATTRIBUTE_create_by_txt 2218
2193X509at_add1_attr_by_txt 2219
2194sk_CRYPTO_EX_DATA_FUNCS_delete 2220
2195sk_CRYPTO_EX_DATA_FUNCS_set 2221
2196sk_CRYPTO_EX_DATA_FUNCS_unshift 2222
2197sk_CRYPTO_EX_DATA_FUNCS_new_null 2223
2198sk_CRYPTO_EX_DATA_FUNCS_set_cmp_func 2224
2199sk_CRYPTO_EX_DATA_FUNCS_sort 2225
2200sk_CRYPTO_EX_DATA_FUNCS_dup 2226
2201sk_CRYPTO_EX_DATA_FUNCS_shift 2227
2202sk_CRYPTO_EX_DATA_FUNCS_value 2228
2203sk_CRYPTO_EX_DATA_FUNCS_pop 2229
2204sk_CRYPTO_EX_DATA_FUNCS_push 2230
2205sk_CRYPTO_EX_DATA_FUNCS_find 2231
2206sk_CRYPTO_EX_DATA_FUNCS_new 2232
2207sk_CRYPTO_EX_DATA_FUNCS_free 2233
2208sk_CRYPTO_EX_DATA_FUNCS_delete_ptr 2234
2209sk_CRYPTO_EX_DATA_FUNCS_num 2235
2210sk_CRYPTO_EX_DATA_FUNCS_pop_free 2236
2211sk_CRYPTO_EX_DATA_FUNCS_insert 2237
2212sk_CRYPTO_EX_DATA_FUNCS_zero 2238
2213BN_pseudo_rand 2239
2214BN_is_prime_fasttest 2240
2215BN_CTX_end 2241
2216BN_CTX_start 2242
2217BN_CTX_get 2243
2218EVP_PKEY2PKCS8_broken 2244
2219ASN1_STRING_TABLE_add 2245
2220CRYPTO_dbg_get_options 2246
2221AUTHORITY_INFO_ACCESS_new 2247
2222CRYPTO_get_mem_debug_options 2248
2223des_crypt 2249
2224PEM_write_bio_X509_REQ_NEW 2250
2225PEM_write_X509_REQ_NEW 2251
2226BIO_callback_ctrl 2252
2227RAND_egd 2253
2228RAND_status 2254
2229bn_dump1 2255
diff --git a/src/lib/libcrypto/util/mkdef.pl b/src/lib/libcrypto/util/mkdef.pl
index 80384af325..4e2845a4e1 100644
--- a/src/lib/libcrypto/util/mkdef.pl
+++ b/src/lib/libcrypto/util/mkdef.pl
@@ -6,26 +6,34 @@
6# prototyped functions: it then prunes the output. 6# prototyped functions: it then prunes the output.
7# 7#
8 8
9$crypto_num="util/libeay.num"; 9my $crypto_num="util/libeay.num";
10$ssl_num= "util/ssleay.num"; 10my $ssl_num= "util/ssleay.num";
11 11
12my $do_update = 0; 12my $do_update = 0;
13my $do_crypto = 0; 13my $do_crypto = 0;
14my $do_ssl = 0; 14my $do_ssl = 0;
15$rsaref = 0; 15my $do_ctest = 0;
16my $rsaref = 0;
16 17
17$W32=1; 18my $W32=1;
18$NT=0; 19my $NT=0;
19# Set this to make typesafe STACK definitions appear in DEF 20# Set this to make typesafe STACK definitions appear in DEF
20$safe_stack_def = 1; 21my $safe_stack_def = 1;
21 22
22$options=""; 23my $options="";
23open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n"; 24open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n";
24while(<IN>) { 25while(<IN>) {
25 $options=$1 if (/^OPTIONS=(.*)$/); 26 $options=$1 if (/^OPTIONS=(.*)$/);
26} 27}
27close(IN); 28close(IN);
28 29
30# The following ciphers may be excluded (by Configure). This means functions
31# defined with ifndef(NO_XXX) are not included in the .def file, and everything
32# in directory xxx is ignored.
33my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
34my $no_cast; my $no_md2; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
35my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0;
36
29foreach (@ARGV, split(/ /, $options)) 37foreach (@ARGV, split(/ /, $options))
30 { 38 {
31 $W32=1 if $_ eq "32"; 39 $W32=1 if $_ eq "32";
@@ -39,6 +47,7 @@ foreach (@ARGV, split(/ /, $options))
39 $do_crypto=1 if $_ eq "libeay"; 47 $do_crypto=1 if $_ eq "libeay";
40 $do_crypto=1 if $_ eq "crypto"; 48 $do_crypto=1 if $_ eq "crypto";
41 $do_update=1 if $_ eq "update"; 49 $do_update=1 if $_ eq "update";
50 $do_ctest=1 if $_ eq "ctest";
42 $rsaref=1 if $_ eq "rsaref"; 51 $rsaref=1 if $_ eq "rsaref";
43 52
44 if (/^no-rc2$/) { $no_rc2=1; } 53 if (/^no-rc2$/) { $no_rc2=1; }
@@ -59,6 +68,7 @@ foreach (@ARGV, split(/ /, $options))
59 elsif (/^no-hmac$/) { $no_hmac=1; } 68 elsif (/^no-hmac$/) { $no_hmac=1; }
60 } 69 }
61 70
71
62if (!$do_ssl && !$do_crypto) 72if (!$do_ssl && !$do_crypto)
63 { 73 {
64 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n"; 74 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n";
@@ -70,9 +80,9 @@ $max_ssl = $max_num;
70%crypto_list=&load_numbers($crypto_num); 80%crypto_list=&load_numbers($crypto_num);
71$max_crypto = $max_num; 81$max_crypto = $max_num;
72 82
73$ssl="ssl/ssl.h"; 83my $ssl="ssl/ssl.h";
74 84
75$crypto ="crypto/crypto.h"; 85my $crypto ="crypto/crypto.h";
76$crypto.=" crypto/des/des.h" unless $no_des; 86$crypto.=" crypto/des/des.h" unless $no_des;
77$crypto.=" crypto/idea/idea.h" unless $no_idea; 87$crypto.=" crypto/idea/idea.h" unless $no_idea;
78$crypto.=" crypto/rc4/rc4.h" unless $no_rc4; 88$crypto.=" crypto/rc4/rc4.h" unless $no_rc4;
@@ -115,8 +125,8 @@ $crypto.=" crypto/rand/rand.h";
115$crypto.=" crypto/comp/comp.h"; 125$crypto.=" crypto/comp/comp.h";
116$crypto.=" crypto/tmdiff.h"; 126$crypto.=" crypto/tmdiff.h";
117 127
118@ssl_func = &do_defs("SSLEAY", $ssl); 128my @ssl_func = &do_defs("SSLEAY", $ssl);
119@crypto_func = &do_defs("LIBEAY", $crypto); 129my @crypto_func = &do_defs("LIBEAY", $crypto);
120 130
121 131
122if ($do_update) { 132if ($do_update) {
@@ -131,7 +141,26 @@ if($do_crypto == 1) {
131 open(OUT, ">>$crypto_num"); 141 open(OUT, ">>$crypto_num");
132 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto, @crypto_func); 142 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto, @crypto_func);
133 close OUT; 143 close OUT;
134} 144}
145
146} elsif ($do_ctest) {
147
148 print <<"EOF";
149
150/* Test file to check all DEF file symbols are present by trying
151 * to link to all of them. This is *not* intended to be run!
152 */
153
154int main()
155{
156EOF
157 &print_test_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func)
158 if $do_ssl == 1;
159
160 &print_test_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func)
161 if $do_crypto == 1;
162
163 print "}\n";
135 164
136} else { 165} else {
137 166
@@ -147,14 +176,15 @@ if($do_crypto == 1) {
147sub do_defs 176sub do_defs
148{ 177{
149 my($name,$files)=@_; 178 my($name,$files)=@_;
179 my $file;
150 my @ret; 180 my @ret;
151 my %funcs; 181 my %funcs;
182 my $cpp;
152 183
153 foreach $file (split(/\s+/,$files)) 184 foreach $file (split(/\s+/,$files))
154 { 185 {
155 open(IN,"<$file") || die "unable to open $file:$!\n"; 186 open(IN,"<$file") || die "unable to open $file:$!\n";
156 187 my $line = "", my $def= "";
157 my $line = "", $def= "";
158 my %tag = ( 188 my %tag = (
159 FreeBSD => 0, 189 FreeBSD => 0,
160 NOPROTO => 0, 190 NOPROTO => 0,
@@ -164,6 +194,22 @@ sub do_defs
164 NO_FP_API => 0, 194 NO_FP_API => 0,
165 CONST_STRICT => 0, 195 CONST_STRICT => 0,
166 TRUE => 1, 196 TRUE => 1,
197 NO_RC2 => 0,
198 NO_RC4 => 0,
199 NO_RC5 => 0,
200 NO_IDEA => 0,
201 NO_DES => 0,
202 NO_BF => 0,
203 NO_CAST => 0,
204 NO_MD2 => 0,
205 NO_MD5 => 0,
206 NO_SHA => 0,
207 NO_RIPEMD => 0,
208 NO_MDC2 => 0,
209 NO_RSA => 0,
210 NO_DSA => 0,
211 NO_DH => 0,
212 NO_HMAC => 0,
167 ); 213 );
168 while(<IN>) { 214 while(<IN>) {
169 last if (/BEGIN ERROR CODES/); 215 last if (/BEGIN ERROR CODES/);
@@ -214,6 +260,11 @@ sub do_defs
214 push(@tag,"TRUE"); 260 push(@tag,"TRUE");
215 $tag{"TRUE"}=1; 261 $tag{"TRUE"}=1;
216 next; 262 next;
263 } elsif (/^\#\s*if\s+0/) {
264 # Dummy tag
265 push(@tag,"TRUE");
266 $tag{"TRUE"}=-1;
267 next;
217 } elsif (/^\#/) { 268 } elsif (/^\#/) {
218 next; 269 next;
219 } 270 }
@@ -250,7 +301,20 @@ sub do_defs
250 } 301 }
251 $funcs{"PEM_read_bio_${1}"} = 1; 302 $funcs{"PEM_read_bio_${1}"} = 1;
252 $funcs{"PEM_write_bio_${1}"} = 1; 303 $funcs{"PEM_write_bio_${1}"} = 1;
253 } elsif ( 304 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
305 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
306 if($W32) {
307 $funcs{"PEM_write_${1}"} = 1;
308 }
309 $funcs{"PEM_write_bio_${1}"} = 1;
310 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
311 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
312 if($W32) {
313 $funcs{"PEM_read_${1}"} = 1;
314 }
315 $funcs{"PEM_read_bio_${1}"} = 1;
316 } elsif (
317 ($tag{'TRUE'} != -1) &&
254 ($tag{'FreeBSD'} != 1) && 318 ($tag{'FreeBSD'} != 1) &&
255 ($tag{'CONST_STRICT'} != 1) && 319 ($tag{'CONST_STRICT'} != 1) &&
256 (($W32 && ($tag{'WIN16'} != 1)) || 320 (($W32 && ($tag{'WIN16'} != 1)) ||
@@ -260,7 +324,23 @@ sub do_defs
260 ((!$W32 && $tag{'_WINDLL'} != -1) || 324 ((!$W32 && $tag{'_WINDLL'} != -1) ||
261 ($W32 && $tag{'_WINDLL'} != 1)) && 325 ($W32 && $tag{'_WINDLL'} != 1)) &&
262 ((($tag{'NO_FP_API'} != 1) && $W32) || 326 ((($tag{'NO_FP_API'} != 1) && $W32) ||
263 (($tag{'NO_FP_API'} != -1) && !$W32))) 327 (($tag{'NO_FP_API'} != -1) && !$W32)) &&
328 ($tag{'NO_RC2'} == 0 || !$no_rc2) &&
329 ($tag{'NO_RC4'} == 0 || !$no_rc4) &&
330 ($tag{'NO_RC5'} == 0 || !$no_rc5) &&
331 ($tag{'NO_IDEA'} == 0 || !$no_idea) &&
332 ($tag{'NO_DES'} == 0 || !$no_des) &&
333 ($tag{'NO_BF'} == 0 || !$no_bf) &&
334 ($tag{'NO_CAST'} == 0 || !$no_cast) &&
335 ($tag{'NO_MD2'} == 0 || !$no_md2) &&
336 ($tag{'NO_MD5'} == 0 || !$no_md5) &&
337 ($tag{'NO_SHA'} == 0 || !$no_sha) &&
338 ($tag{'NO_RIPEMD'} == 0 || !$no_ripemd) &&
339 ($tag{'NO_MDC2'} == 0 || !$no_mdc2) &&
340 ($tag{'NO_RSA'} == 0 || !$no_rsa) &&
341 ($tag{'NO_DSA'} == 0 || !$no_dsa) &&
342 ($tag{'NO_DH'} == 0 || !$no_dh) &&
343 ($tag{'NO_HMAC'} == 0 || !$no_hmac))
264 { 344 {
265 if (/{|\/\*/) { # } 345 if (/{|\/\*/) { # }
266 $line = $_; 346 $line = $_;
@@ -309,8 +389,8 @@ sub do_defs
309 # Prune the returned functions 389 # Prune the returned functions
310 390
311 delete $funcs{"SSL_add_dir_cert_subjects_to_stack"}; 391 delete $funcs{"SSL_add_dir_cert_subjects_to_stack"};
312 delete $funcs{"des_crypt"};
313 delete $funcs{"RSA_PKCS1_RSAref"} unless $rsaref; 392 delete $funcs{"RSA_PKCS1_RSAref"} unless $rsaref;
393 delete $funcs{"bn_dump1"};
314 394
315 if($W32) { 395 if($W32) {
316 delete $funcs{"BIO_s_file_internal"}; 396 delete $funcs{"BIO_s_file_internal"};
@@ -334,10 +414,31 @@ sub do_defs
334 return(@ret); 414 return(@ret);
335} 415}
336 416
417sub print_test_file
418{
419 (*OUT,my $name,*nums,my @functions)=@_;
420 my $n = 1; my @e; my @r;
421 my $func;
422
423 (@e)=grep(/^SSLeay/,@functions);
424 (@r)=grep(!/^SSLeay/,@functions);
425 @functions=((sort @e),(sort @r));
426
427 foreach $func (@functions) {
428 if (!defined($nums{$func})) {
429 printf STDERR "$func does not have a number assigned\n"
430 if(!$do_update);
431 } else {
432 $n=$nums{$func};
433 print OUT "\t$func();\n";
434 }
435 }
436}
437
337sub print_def_file 438sub print_def_file
338{ 439{
339 (*OUT,my $name,*nums,@functions)=@_; 440 (*OUT,my $name,*nums,my @functions)=@_;
340 my $n =1; 441 my $n = 1; my @e; my @r;
341 442
342 if ($W32) 443 if ($W32)
343 { $name.="32"; } 444 { $name.="32"; }
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl
index 4b3bccb13e..ebc059ef22 100644
--- a/src/lib/libcrypto/util/mkerr.pl
+++ b/src/lib/libcrypto/util/mkerr.pl
@@ -450,7 +450,7 @@ void ERR_load_${lib}_strings(void)
450#ifdef ${lib}_LIB_NAME 450#ifdef ${lib}_LIB_NAME
451 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0); 451 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
452 ERR_load_strings(0,${lib}_lib_name); 452 ERR_load_strings(0,${lib}_lib_name);
453#endif; 453#endif
454 } 454 }
455 } 455 }
456 456
diff --git a/src/lib/libcrypto/util/pl/BC-32.pl b/src/lib/libcrypto/util/pl/BC-32.pl
index 09c45a21a6..df6e2c742e 100644
--- a/src/lib/libcrypto/util/pl/BC-32.pl
+++ b/src/lib/libcrypto/util/pl/BC-32.pl
@@ -19,7 +19,7 @@ $out_def="out32";
19$tmp_def="tmp32"; 19$tmp_def="tmp32";
20$inc_def="inc32"; 20$inc_def="inc32";
21#enable max error messages, disable most common warnings 21#enable max error messages, disable most common warnings
22$cflags="-DWIN32_LEAN_AND_MEAN -j255 -w-aus -w-par -w-inl -c -tWC -tWM -DWINDOWS -DWIN32 -DL_ENDIAN "; 22$cflags="-DWIN32_LEAN_AND_MEAN -q -w-aus -w-par -w-inl -c -tWC -tWM -DWINDOWS -DWIN32 -DL_ENDIAN ";
23if ($debug) 23if ($debug)
24{ 24{
25 $cflags.="-Od -y -v -vi- -D_DEBUG"; 25 $cflags.="-Od -y -v -vi- -D_DEBUG";
diff --git a/src/lib/libcrypto/util/pl/Mingw32.pl b/src/lib/libcrypto/util/pl/Mingw32.pl
index 84c2a22db3..585cacd820 100644
--- a/src/lib/libcrypto/util/pl/Mingw32.pl
+++ b/src/lib/libcrypto/util/pl/Mingw32.pl
@@ -17,7 +17,7 @@ $mkdir='gmkdir';
17 17
18$cc='gcc'; 18$cc='gcc';
19if ($debug) 19if ($debug)
20 { $cflags="-g2 -ggdb"; } 20 { $cflags="-DL_ENDIAN -g2 -ggdb"; }
21else 21else
22 { $cflags="-DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall"; } 22 { $cflags="-DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall"; }
23 23
diff --git a/src/lib/libcrypto/util/pl/VC-32.pl b/src/lib/libcrypto/util/pl/VC-32.pl
index 6db1c9fe23..046f0e253c 100644
--- a/src/lib/libcrypto/util/pl/VC-32.pl
+++ b/src/lib/libcrypto/util/pl/VC-32.pl
@@ -22,7 +22,7 @@ $inc_def="inc32";
22 22
23if ($debug) 23if ($debug)
24 { 24 {
25 $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWINDOWS -DWIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG"; 25 $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG";
26 $lflags.=" /debug"; 26 $lflags.=" /debug";
27 $mlflags.=' /debug'; 27 $mlflags.=' /debug';
28 } 28 }
diff --git a/src/lib/libcrypto/util/pod2man.pl b/src/lib/libcrypto/util/pod2man.pl
new file mode 100644
index 0000000000..f5ec0767ed
--- /dev/null
+++ b/src/lib/libcrypto/util/pod2man.pl
@@ -0,0 +1,1181 @@
1: #!/usr/bin/perl-5.005
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4
5$DEF_PM_SECTION = '3pm' || '3';
6
7=head1 NAME
8
9pod2man - translate embedded Perl pod directives into man pages
10
11=head1 SYNOPSIS
12
13B<pod2man>
14[ B<--section=>I<manext> ]
15[ B<--release=>I<relpatch> ]
16[ B<--center=>I<string> ]
17[ B<--date=>I<string> ]
18[ B<--fixed=>I<font> ]
19[ B<--official> ]
20[ B<--lax> ]
21I<inputfile>
22
23=head1 DESCRIPTION
24
25B<pod2man> converts its input file containing embedded pod directives (see
26L<perlpod>) into nroff source suitable for viewing with nroff(1) or
27troff(1) using the man(7) macro set.
28
29Besides the obvious pod conversions, B<pod2man> also takes care of
30func(), func(n), and simple variable references like $foo or @bar so
31you don't have to use code escapes for them; complex expressions like
32C<$fred{'stuff'}> will still need to be escaped, though. Other nagging
33little roffish things that it catches include translating the minus in
34something like foo-bar, making a long dash--like this--into a real em
35dash, fixing up "paired quotes", putting a little space after the
36parens in something like func(), making C++ and PI look right, making
37double underbars have a little tiny space between them, making ALLCAPS
38a teeny bit smaller in troff(1), and escaping backslashes so you don't
39have to.
40
41=head1 OPTIONS
42
43=over 8
44
45=item center
46
47Set the centered header to a specific string. The default is
48"User Contributed Perl Documentation", unless the C<--official> flag is
49given, in which case the default is "Perl Programmers Reference Guide".
50
51=item date
52
53Set the left-hand footer string to this value. By default,
54the modification date of the input file will be used.
55
56=item fixed
57
58The fixed font to use for code refs. Defaults to CW.
59
60=item official
61
62Set the default header to indicate that this page is of
63the standard release in case C<--center> is not given.
64
65=item release
66
67Set the centered footer. By default, this is the current
68perl release.
69
70=item section
71
72Set the section for the C<.TH> macro. The standard conventions on
73sections are to use 1 for user commands, 2 for system calls, 3 for
74functions, 4 for devices, 5 for file formats, 6 for games, 7 for
75miscellaneous information, and 8 for administrator commands. This works
76best if you put your Perl man pages in a separate tree, like
77F</usr/local/perl/man/>. By default, section 1 will be used
78unless the file ends in F<.pm> in which case section 3 will be selected.
79
80=item lax
81
82Don't complain when required sections aren't present.
83
84=back
85
86=head1 Anatomy of a Proper Man Page
87
88For those not sure of the proper layout of a man page, here's
89an example of the skeleton of a proper man page. Head of the
90major headers should be setout as a C<=head1> directive, and
91are historically written in the rather startling ALL UPPER CASE
92format, although this is not mandatory.
93Minor headers may be included using C<=head2>, and are
94typically in mixed case.
95
96=over 10
97
98=item NAME
99
100Mandatory section; should be a comma-separated list of programs or
101functions documented by this podpage, such as:
102
103 foo, bar - programs to do something
104
105=item SYNOPSIS
106
107A short usage summary for programs and functions, which
108may someday be deemed mandatory.
109
110=item DESCRIPTION
111
112Long drawn out discussion of the program. It's a good idea to break this
113up into subsections using the C<=head2> directives, like
114
115 =head2 A Sample Subection
116
117 =head2 Yet Another Sample Subection
118
119=item OPTIONS
120
121Some people make this separate from the description.
122
123=item RETURN VALUE
124
125What the program or function returns if successful.
126
127=item ERRORS
128
129Exceptions, return codes, exit stati, and errno settings.
130
131=item EXAMPLES
132
133Give some example uses of the program.
134
135=item ENVIRONMENT
136
137Envariables this program might care about.
138
139=item FILES
140
141All files used by the program. You should probably use the FE<lt>E<gt>
142for these.
143
144=item SEE ALSO
145
146Other man pages to check out, like man(1), man(7), makewhatis(8), or catman(8).
147
148=item NOTES
149
150Miscellaneous commentary.
151
152=item CAVEATS
153
154Things to take special care with; sometimes called WARNINGS.
155
156=item DIAGNOSTICS
157
158All possible messages the program can print out--and
159what they mean.
160
161=item BUGS
162
163Things that are broken or just don't work quite right.
164
165=item RESTRICTIONS
166
167Bugs you don't plan to fix :-)
168
169=item AUTHOR
170
171Who wrote it (or AUTHORS if multiple).
172
173=item HISTORY
174
175Programs derived from other sources sometimes have this, or
176you might keep a modification log here.
177
178=back
179
180=head1 EXAMPLES
181
182 pod2man program > program.1
183 pod2man some_module.pm > /usr/perl/man/man3/some_module.3
184 pod2man --section=7 note.pod > note.7
185
186=head1 DIAGNOSTICS
187
188The following diagnostics are generated by B<pod2man>. Items
189marked "(W)" are non-fatal, whereas the "(F)" errors will cause
190B<pod2man> to immediately exit with a non-zero status.
191
192=over 4
193
194=item bad option in paragraph %d of %s: ``%s'' should be [%s]<%s>
195
196(W) If you start include an option, you should set it off
197as bold, italic, or code.
198
199=item can't open %s: %s
200
201(F) The input file wasn't available for the given reason.
202
203=item Improper man page - no dash in NAME header in paragraph %d of %s
204
205(W) The NAME header did not have an isolated dash in it. This is
206considered important.
207
208=item Invalid man page - no NAME line in %s
209
210(F) You did not include a NAME header, which is essential.
211
212=item roff font should be 1 or 2 chars, not `%s' (F)
213
214(F) The font specified with the C<--fixed> option was not
215a one- or two-digit roff font.
216
217=item %s is missing required section: %s
218
219(W) Required sections include NAME, DESCRIPTION, and if you're
220using a section starting with a 3, also a SYNOPSIS. Actually,
221not having a NAME is a fatal.
222
223=item Unknown escape: %s in %s
224
225(W) An unknown HTML entity (probably for an 8-bit character) was given via
226a C<EE<lt>E<gt>> directive. Besides amp, lt, gt, and quot, recognized
227entities are Aacute, aacute, Acirc, acirc, AElig, aelig, Agrave, agrave,
228Aring, aring, Atilde, atilde, Auml, auml, Ccedil, ccedil, Eacute, eacute,
229Ecirc, ecirc, Egrave, egrave, ETH, eth, Euml, euml, Iacute, iacute, Icirc,
230icirc, Igrave, igrave, Iuml, iuml, Ntilde, ntilde, Oacute, oacute, Ocirc,
231ocirc, Ograve, ograve, Oslash, oslash, Otilde, otilde, Ouml, ouml, szlig,
232THORN, thorn, Uacute, uacute, Ucirc, ucirc, Ugrave, ugrave, Uuml, uuml,
233Yacute, yacute, and yuml.
234
235=item Unmatched =back
236
237(W) You have a C<=back> without a corresponding C<=over>.
238
239=item Unrecognized pod directive: %s
240
241(W) You specified a pod directive that isn't in the known list of
242C<=head1>, C<=head2>, C<=item>, C<=over>, C<=back>, or C<=cut>.
243
244
245=back
246
247=head1 NOTES
248
249If you would like to print out a lot of man page continuously, you
250probably want to set the C and D registers to set contiguous page
251numbering and even/odd paging, at least on some versions of man(7).
252Settting the F register will get you some additional experimental
253indexing:
254
255 troff -man -rC1 -rD1 -rF1 perl.1 perldata.1 perlsyn.1 ...
256
257The indexing merely outputs messages via C<.tm> for each
258major page, section, subsection, item, and any C<XE<lt>E<gt>>
259directives.
260
261
262=head1 RESTRICTIONS
263
264None at this time.
265
266=head1 BUGS
267
268The =over and =back directives don't really work right. They
269take absolute positions instead of offsets, don't nest well, and
270making people count is suboptimal in any event.
271
272=head1 AUTHORS
273
274Original prototype by Larry Wall, but so massively hacked over by
275Tom Christiansen such that Larry probably doesn't recognize it anymore.
276
277=cut
278
279$/ = "";
280$cutting = 1;
281@Indices = ();
282
283# We try first to get the version number from a local binary, in case we're
284# running an installed version of Perl to produce documentation from an
285# uninstalled newer version's pod files.
286if ($^O ne 'plan9' and $^O ne 'dos' and $^O ne 'os2' and $^O ne 'MSWin32') {
287 my $perl = (-x './perl' && -f './perl' ) ?
288 './perl' :
289 ((-x '../perl' && -f '../perl') ?
290 '../perl' :
291 '');
292 ($version,$patch) = `$perl -e 'print $]'` =~ /^(\d\.\d{3})(\d{2})?/ if $perl;
293}
294# No luck; we'll just go with the running Perl's version
295($version,$patch) = $] =~ /^(.{5})(\d{2})?/ unless $version;
296$DEF_RELEASE = "perl $version";
297$DEF_RELEASE .= ", patch $patch" if $patch;
298
299
300sub makedate {
301 my $secs = shift;
302 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs);
303 my $mname = (qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec})[$mon];
304 $year += 1900;
305 return "$mday/$mname/$year";
306}
307
308use Getopt::Long;
309
310$DEF_SECTION = 1;
311$DEF_CENTER = "User Contributed Perl Documentation";
312$STD_CENTER = "Perl Programmers Reference Guide";
313$DEF_FIXED = 'CW';
314$DEF_LAX = 0;
315
316sub usage {
317 warn "$0: @_\n" if @_;
318 die <<EOF;
319usage: $0 [options] podpage
320Options are:
321 --section=manext (default "$DEF_SECTION")
322 --release=relpatch (default "$DEF_RELEASE")
323 --center=string (default "$DEF_CENTER")
324 --date=string (default "$DEF_DATE")
325 --fixed=font (default "$DEF_FIXED")
326 --official (default NOT)
327 --lax (default NOT)
328EOF
329}
330
331$uok = GetOptions( qw(
332 section=s
333 release=s
334 center=s
335 date=s
336 fixed=s
337 official
338 lax
339 help));
340
341$DEF_DATE = makedate((stat($ARGV[0]))[9] || time());
342
343usage("Usage error!") unless $uok;
344usage() if $opt_help;
345usage("Need one and only one podpage argument") unless @ARGV == 1;
346
347$section = $opt_section || ($ARGV[0] =~ /\.pm$/
348 ? $DEF_PM_SECTION : $DEF_SECTION);
349$RP = $opt_release || $DEF_RELEASE;
350$center = $opt_center || ($opt_official ? $STD_CENTER : $DEF_CENTER);
351$lax = $opt_lax || $DEF_LAX;
352
353$CFont = $opt_fixed || $DEF_FIXED;
354
355if (length($CFont) == 2) {
356 $CFont_embed = "\\f($CFont";
357}
358elsif (length($CFont) == 1) {
359 $CFont_embed = "\\f$CFont";
360}
361else {
362 die "roff font should be 1 or 2 chars, not `$CFont_embed'";
363}
364
365$date = $opt_date || $DEF_DATE;
366
367for (qw{NAME DESCRIPTION}) {
368# for (qw{NAME DESCRIPTION AUTHOR}) {
369 $wanna_see{$_}++;
370}
371$wanna_see{SYNOPSIS}++ if $section =~ /^3/;
372
373
374$name = @ARGV ? $ARGV[0] : "<STDIN>";
375$Filename = $name;
376if ($section =~ /^1/) {
377 require File::Basename;
378 $name = uc File::Basename::basename($name);
379}
380$name =~ s/\.(pod|p[lm])$//i;
381
382# Lose everything up to the first of
383# */lib/*perl* standard or site_perl module
384# */*perl*/lib from -D prefix=/opt/perl
385# */*perl*/ random module hierarchy
386# which works.
387$name =~ s-//+-/-g;
388if ($name =~ s-^.*?/lib/[^/]*perl[^/]*/--i
389 or $name =~ s-^.*?/[^/]*perl[^/]*/lib/--i
390 or $name =~ s-^.*?/[^/]*perl[^/]*/--i) {
391 # Lose ^site(_perl)?/.
392 $name =~ s-^site(_perl)?/--;
393 # Lose ^arch/. (XXX should we use Config? Just for archname?)
394 $name =~ s~^(.*-$^O|$^O-.*)/~~o;
395 # Lose ^version/.
396 $name =~ s-^\d+\.\d+/--;
397}
398
399# Translate Getopt/Long to Getopt::Long, etc.
400$name =~ s(/)(::)g;
401
402if ($name ne 'something') {
403 FCHECK: {
404 open(F, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
405 while (<F>) {
406 next unless /^=\b/;
407 if (/^=head1\s+NAME\s*$/) { # an /m would forgive mistakes
408 $_ = <F>;
409 unless (/\s*-+\s+/) {
410 $oops++;
411 warn "$0: Improper man page - no dash in NAME header in paragraph $. of $ARGV[0]\n"
412 } else {
413 my @n = split /\s+-+\s+/;
414 if (@n != 2) {
415 $oops++;
416 warn "$0: Improper man page - malformed NAME header in paragraph $. of $ARGV[0]\n"
417 }
418 else {
419 %namedesc = @n;
420 }
421 }
422 last FCHECK;
423 }
424 next if /^=cut\b/; # DB_File and Net::Ping have =cut before NAME
425 next if /^=pod\b/; # It is OK to have =pod before NAME
426 die "$0: Invalid man page - 1st pod line is not NAME in $ARGV[0]\n" unless $lax;
427 }
428 die "$0: Invalid man page - no documentation in $ARGV[0]\n" unless $lax;
429 }
430 close F;
431}
432
433print <<"END";
434.rn '' }`
435''' \$RCSfile\$\$Revision\$\$Date\$
436'''
437''' \$Log\$
438'''
439.de Sh
440.br
441.if t .Sp
442.ne 5
443.PP
444\\fB\\\\\$1\\fR
445.PP
446..
447.de Sp
448.if t .sp .5v
449.if n .sp
450..
451.de Ip
452.br
453.ie \\\\n(.\$>=3 .ne \\\\\$3
454.el .ne 3
455.IP "\\\\\$1" \\\\\$2
456..
457.de Vb
458.ft $CFont
459.nf
460.ne \\\\\$1
461..
462.de Ve
463.ft R
464
465.fi
466..
467'''
468'''
469''' Set up \\*(-- to give an unbreakable dash;
470''' string Tr holds user defined translation string.
471''' Bell System Logo is used as a dummy character.
472'''
473.tr \\(*W-|\\(bv\\*(Tr
474.ie n \\{\\
475.ds -- \\(*W-
476.ds PI pi
477.if (\\n(.H=4u)&(1m=24u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-12u'-\\" diablo 10 pitch
478.if (\\n(.H=4u)&(1m=20u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-8u'-\\" diablo 12 pitch
479.ds L" ""
480.ds R" ""
481''' \\*(M", \\*(S", \\*(N" and \\*(T" are the equivalent of
482''' \\*(L" and \\*(R", except that they are used on ".xx" lines,
483''' such as .IP and .SH, which do another additional levels of
484''' double-quote interpretation
485.ds M" """
486.ds S" """
487.ds N" """""
488.ds T" """""
489.ds L' '
490.ds R' '
491.ds M' '
492.ds S' '
493.ds N' '
494.ds T' '
495'br\\}
496.el\\{\\
497.ds -- \\(em\\|
498.tr \\*(Tr
499.ds L" ``
500.ds R" ''
501.ds M" ``
502.ds S" ''
503.ds N" ``
504.ds T" ''
505.ds L' `
506.ds R' '
507.ds M' `
508.ds S' '
509.ds N' `
510.ds T' '
511.ds PI \\(*p
512'br\\}
513END
514
515print <<'END';
516.\" If the F register is turned on, we'll generate
517.\" index entries out stderr for the following things:
518.\" TH Title
519.\" SH Header
520.\" Sh Subsection
521.\" Ip Item
522.\" X<> Xref (embedded
523.\" Of course, you have to process the output yourself
524.\" in some meaninful fashion.
525.if \nF \{
526.de IX
527.tm Index:\\$1\t\\n%\t"\\$2"
528..
529.nr % 0
530.rr F
531.\}
532END
533
534print <<"END";
535.TH $name $section "$RP" "$date" "$center"
536.UC
537END
538
539push(@Indices, qq{.IX Title "$name $section"});
540
541while (($name, $desc) = each %namedesc) {
542 for ($name, $desc) { s/^\s+//; s/\s+$//; }
543 push(@Indices, qq(.IX Name "$name - $desc"\n));
544}
545
546print <<'END';
547.if n .hy 0
548.if n .na
549.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
550.de CQ \" put $1 in typewriter font
551END
552print ".ft $CFont\n";
553print <<'END';
554'if n "\c
555'if t \\&\\$1\c
556'if n \\&\\$1\c
557'if n \&"
558\\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
559'.ft R
560..
561.\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
562. \" AM - accent mark definitions
563.bd B 3
564. \" fudge factors for nroff and troff
565.if n \{\
566. ds #H 0
567. ds #V .8m
568. ds #F .3m
569. ds #[ \f1
570. ds #] \fP
571.\}
572.if t \{\
573. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
574. ds #V .6m
575. ds #F 0
576. ds #[ \&
577. ds #] \&
578.\}
579. \" simple accents for nroff and troff
580.if n \{\
581. ds ' \&
582. ds ` \&
583. ds ^ \&
584. ds , \&
585. ds ~ ~
586. ds ? ?
587. ds ! !
588. ds /
589. ds q
590.\}
591.if t \{\
592. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
593. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
594. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
595. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
596. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
597. ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
598. ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
599. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
600. ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
601.\}
602. \" troff and (daisy-wheel) nroff accents
603.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
604.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
605.ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
606.ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
607.ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
608.ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
609.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
610.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
611.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
612.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
613.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
614.ds ae a\h'-(\w'a'u*4/10)'e
615.ds Ae A\h'-(\w'A'u*4/10)'E
616.ds oe o\h'-(\w'o'u*4/10)'e
617.ds Oe O\h'-(\w'O'u*4/10)'E
618. \" corrections for vroff
619.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
620.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
621. \" for low resolution devices (crt and lpr)
622.if \n(.H>23 .if \n(.V>19 \
623\{\
624. ds : e
625. ds 8 ss
626. ds v \h'-1'\o'\(aa\(ga'
627. ds _ \h'-1'^
628. ds . \h'-1'.
629. ds 3 3
630. ds o a
631. ds d- d\h'-1'\(ga
632. ds D- D\h'-1'\(hy
633. ds th \o'bp'
634. ds Th \o'LP'
635. ds ae ae
636. ds Ae AE
637. ds oe oe
638. ds Oe OE
639.\}
640.rm #[ #] #H #V #F C
641END
642
643$indent = 0;
644
645$begun = "";
646
647# Unrolling [^A-Z>]|[A-Z](?!<) gives: // MRE pp 165.
648my $nonest = '(?:[^A-Z>]*(?:[A-Z](?!<)[^A-Z>]*)*)';
649
650while (<>) {
651 if ($cutting) {
652 next unless /^=/;
653 $cutting = 0;
654 }
655 if ($begun) {
656 if (/^=end\s+$begun/) {
657 $begun = "";
658 }
659 elsif ($begun =~ /^(roff|man)$/) {
660 print STDOUT $_;
661 }
662 next;
663 }
664 chomp;
665
666 # Translate verbatim paragraph
667
668 if (/^\s/) {
669 @lines = split(/\n/);
670 for (@lines) {
671 1 while s
672 {^( [^\t]* ) \t ( \t* ) }
673 { $1 . ' ' x (8 - (length($1)%8) + 8 * (length($2))) }ex;
674 s/\\/\\e/g;
675 s/\A/\\&/s;
676 }
677 $lines = @lines;
678 makespace() unless $verbatim++;
679 print ".Vb $lines\n";
680 print join("\n", @lines), "\n";
681 print ".Ve\n";
682 $needspace = 0;
683 next;
684 }
685
686 $verbatim = 0;
687
688 if (/^=for\s+(\S+)\s*/s) {
689 if ($1 eq "man" or $1 eq "roff") {
690 print STDOUT $',"\n\n";
691 } else {
692 # ignore unknown for
693 }
694 next;
695 }
696 elsif (/^=begin\s+(\S+)\s*/s) {
697 $begun = $1;
698 if ($1 eq "man" or $1 eq "roff") {
699 print STDOUT $'."\n\n";
700 }
701 next;
702 }
703
704 # check for things that'll hosed our noremap scheme; affects $_
705 init_noremap();
706
707 if (!/^=item/) {
708
709 # trofficate backslashes; must do it before what happens below
710 s/\\/noremap('\\e')/ge;
711
712 # protect leading periods and quotes against *roff
713 # mistaking them for directives
714 s/^(?:[A-Z]<)?[.']/\\&$&/gm;
715
716 # first hide the escapes in case we need to
717 # intuit something and get it wrong due to fmting
718
719 1 while s/([A-Z]<$nonest>)/noremap($1)/ge;
720
721 # func() is a reference to a perl function
722 s{
723 \b
724 (
725 [:\w]+ \(\)
726 )
727 } {I<$1>}gx;
728
729 # func(n) is a reference to a perl function or a man page
730 s{
731 ([:\w]+)
732 (
733 \( [^\051]+ \)
734 )
735 } {I<$1>\\|$2}gx;
736
737 # convert simple variable references
738 s/(\s+)([\$\@%][\w:]+)(?!\()/${1}C<$2>/g;
739
740 if (m{ (
741 [\-\w]+
742 \(
743 [^\051]*?
744 [\@\$,]
745 [^\051]*?
746 \)
747 )
748 }x && $` !~ /([LCI]<[^<>]*|-)$/ && !/^=\w/)
749 {
750 warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [LCI]<$1>\n";
751 $oops++;
752 }
753
754 while (/(-[a-zA-Z])\b/g && $` !~ /[\w\-]$/) {
755 warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [CB]<$1>\n";
756 $oops++;
757 }
758
759 # put it back so we get the <> processed again;
760 clear_noremap(0); # 0 means leave the E's
761
762 } else {
763 # trofficate backslashes
764 s/\\/noremap('\\e')/ge;
765
766 }
767
768 # need to hide E<> first; they're processed in clear_noremap
769 s/(E<[^<>]+>)/noremap($1)/ge;
770
771
772 $maxnest = 10;
773 while ($maxnest-- && /[A-Z]</) {
774
775 # can't do C font here
776 s/([BI])<($nonest)>/font($1) . $2 . font('R')/eg;
777
778 # files and filelike refs in italics
779 s/F<($nonest)>/I<$1>/g;
780
781 # no break -- usually we want C<> for this
782 s/S<($nonest)>/nobreak($1)/eg;
783
784 # LREF: a la HREF L<show this text|man/section>
785 s:L<([^|>]+)\|[^>]+>:$1:g;
786
787 # LREF: a manpage(3f)
788 s:L<([a-zA-Z][^\s\/]+)(\([^\)]+\))?>:the I<$1>$2 manpage:g;
789
790 # LREF: an =item on another manpage
791 s{
792 L<
793 ([^/]+)
794 /
795 (
796 [:\w]+
797 (\(\))?
798 )
799 >
800 } {the C<$2> entry in the I<$1> manpage}gx;
801
802 # LREF: an =item on this manpage
803 s{
804 ((?:
805 L<
806 /
807 (
808 [:\w]+
809 (\(\))?
810 )
811 >
812 (,?\s+(and\s+)?)?
813 )+)
814 } { internal_lrefs($1) }gex;
815
816 # LREF: a =head2 (head1?), maybe on a manpage, maybe right here
817 # the "func" can disambiguate
818 s{
819 L<
820 (?:
821 ([a-zA-Z]\S+?) /
822 )?
823 "?(.*?)"?
824 >
825 }{
826 do {
827 $1 # if no $1, assume it means on this page.
828 ? "the section on I<$2> in the I<$1> manpage"
829 : "the section on I<$2>"
830 }
831 }gesx; # s in case it goes over multiple lines, so . matches \n
832
833 s/Z<>/\\&/g;
834
835 # comes last because not subject to reprocessing
836 s/C<($nonest)>/noremap("${CFont_embed}${1}\\fR")/eg;
837 }
838
839 if (s/^=//) {
840 $needspace = 0; # Assume this.
841
842 s/\n/ /g;
843
844 ($Cmd, $_) = split(' ', $_, 2);
845
846 $dotlevel = 1;
847 if ($Cmd eq 'head1') {
848 $dotlevel = 1;
849 }
850 elsif ($Cmd eq 'head2') {
851 $dotlevel = 1;
852 }
853 elsif ($Cmd eq 'item') {
854 $dotlevel = 2;
855 }
856
857 if (defined $_) {
858 &escapes($dotlevel);
859 s/"/""/g;
860 }
861
862 clear_noremap(1);
863
864 if ($Cmd eq 'cut') {
865 $cutting = 1;
866 }
867 elsif ($Cmd eq 'head1') {
868 s/\s+$//;
869 delete $wanna_see{$_} if exists $wanna_see{$_};
870 print qq{.SH "$_"\n};
871 push(@Indices, qq{.IX Header "$_"\n});
872 }
873 elsif ($Cmd eq 'head2') {
874 print qq{.Sh "$_"\n};
875 push(@Indices, qq{.IX Subsection "$_"\n});
876 }
877 elsif ($Cmd eq 'over') {
878 push(@indent,$indent);
879 $indent += ($_ + 0) || 5;
880 }
881 elsif ($Cmd eq 'back') {
882 $indent = pop(@indent);
883 warn "$0: Unmatched =back in paragraph $. of $ARGV\n" unless defined $indent;
884 $needspace = 1;
885 }
886 elsif ($Cmd eq 'item') {
887 s/^\*( |$)/\\(bu$1/g;
888 # if you know how to get ":s please do
889 s/\\\*\(L"([^"]+?)\\\*\(R"/'$1'/g;
890 s/\\\*\(L"([^"]+?)""/'$1'/g;
891 s/[^"]""([^"]+?)""[^"]/'$1'/g;
892 # here do something about the $" in perlvar?
893 print STDOUT qq{.Ip "$_" $indent\n};
894 push(@Indices, qq{.IX Item "$_"\n});
895 }
896 elsif ($Cmd eq 'pod') {
897 # this is just a comment
898 }
899 else {
900 warn "$0: Unrecognized pod directive in paragraph $. of $ARGV: $Cmd\n";
901 }
902 }
903 else {
904 if ($needspace) {
905 &makespace;
906 }
907 &escapes(0);
908 clear_noremap(1);
909 print $_, "\n";
910 $needspace = 1;
911 }
912}
913
914print <<"END";
915
916.rn }` ''
917END
918
919if (%wanna_see && !$lax) {
920 @missing = keys %wanna_see;
921 warn "$0: $Filename is missing required section"
922 . (@missing > 1 && "s")
923 . ": @missing\n";
924 $oops++;
925}
926
927foreach (@Indices) { print "$_\n"; }
928
929exit;
930#exit ($oops != 0);
931
932#########################################################################
933
934sub nobreak {
935 my $string = shift;
936 $string =~ s/ /\\ /g;
937 $string;
938}
939
940sub escapes {
941 my $indot = shift;
942
943 s/X<(.*?)>/mkindex($1)/ge;
944
945 # translate the minus in foo-bar into foo\-bar for roff
946 s/([^0-9a-z-])-([^-])/$1\\-$2/g;
947
948 # make -- into the string version \*(-- (defined above)
949 s/\b--\b/\\*(--/g;
950 s/"--([^"])/"\\*(--$1/g; # should be a better way
951 s/([^"])--"/$1\\*(--"/g;
952
953 # fix up quotes; this is somewhat tricky
954 my $dotmacroL = 'L';
955 my $dotmacroR = 'R';
956 if ( $indot == 1 ) {
957 $dotmacroL = 'M';
958 $dotmacroR = 'S';
959 }
960 elsif ( $indot >= 2 ) {
961 $dotmacroL = 'N';
962 $dotmacroR = 'T';
963 }
964 if (!/""/) {
965 s/(^|\s)(['"])/noremap("$1\\*($dotmacroL$2")/ge;
966 s/(['"])($|[\-\s,;\\!?.])/noremap("\\*($dotmacroR$1$2")/ge;
967 }
968
969 #s/(?!")(?:.)--(?!")(?:.)/\\*(--/g;
970 #s/(?:(?!")(?:.)--(?:"))|(?:(?:")--(?!")(?:.))/\\*(--/g;
971
972
973 # make sure that func() keeps a bit a space tween the parens
974 ### s/\b\(\)/\\|()/g;
975 ### s/\b\(\)/(\\|)/g;
976
977 # make C++ into \*C+, which is a squinched version (defined above)
978 s/\bC\+\+/\\*(C+/g;
979
980 # make double underbars have a little tiny space between them
981 s/__/_\\|_/g;
982
983 # PI goes to \*(PI (defined above)
984 s/\bPI\b/noremap('\\*(PI')/ge;
985
986 # make all caps a teeny bit smaller, but don't muck with embedded code literals
987 my $hidCFont = font('C');
988 if ($Cmd !~ /^head1/) { # SH already makes smaller
989 # /g isn't enough; 1 while or we'll be off
990
991# 1 while s{
992# (?!$hidCFont)(..|^.|^)
993# \b
994# (
995# [A-Z][\/A-Z+:\-\d_$.]+
996# )
997# (s?)
998# \b
999# } {$1\\s-1$2\\s0}gmox;
1000
1001 1 while s{
1002 (?!$hidCFont)(..|^.|^)
1003 (
1004 \b[A-Z]{2,}[\/A-Z+:\-\d_\$]*\b
1005 )
1006 } {
1007 $1 . noremap( '\\s-1' . $2 . '\\s0' )
1008 }egmox;
1009
1010 }
1011}
1012
1013# make troff just be normal, but make small nroff get quoted
1014# decided to just put the quotes in the text; sigh;
1015sub ccvt {
1016 local($_,$prev) = @_;
1017 noremap(qq{.CQ "$_" \n\\&});
1018}
1019
1020sub makespace {
1021 if ($indent) {
1022 print ".Sp\n";
1023 }
1024 else {
1025 print ".PP\n";
1026 }
1027}
1028
1029sub mkindex {
1030 my ($entry) = @_;
1031 my @entries = split m:\s*/\s*:, $entry;
1032 push @Indices, ".IX Xref " . join ' ', map {qq("$_")} @entries;
1033 return '';
1034}
1035
1036sub font {
1037 local($font) = shift;
1038 return '\\f' . noremap($font);
1039}
1040
1041sub noremap {
1042 local($thing_to_hide) = shift;
1043 $thing_to_hide =~ tr/\000-\177/\200-\377/;
1044 return $thing_to_hide;
1045}
1046
1047sub init_noremap {
1048 # escape high bit characters in input stream
1049 s/([\200-\377])/"E<".ord($1).">"/ge;
1050}
1051
1052sub clear_noremap {
1053 my $ready_to_print = $_[0];
1054
1055 tr/\200-\377/\000-\177/;
1056
1057 # trofficate backslashes
1058 # s/(?!\\e)(?:..|^.|^)\\/\\e/g;
1059
1060 # now for the E<>s, which have been hidden until now
1061 # otherwise the interative \w<> processing would have
1062 # been hosed by the E<gt>
1063 s {
1064 E<
1065 (
1066 ( \d + )
1067 | ( [A-Za-z]+ )
1068 )
1069 >
1070 } {
1071 do {
1072 defined $2
1073 ? chr($2)
1074 :
1075 exists $HTML_Escapes{$3}
1076 ? do { $HTML_Escapes{$3} }
1077 : do {
1078 warn "$0: Unknown escape in paragraph $. of $ARGV: ``$&''\n";
1079 "E<$1>";
1080 }
1081 }
1082 }egx if $ready_to_print;
1083}
1084
1085sub internal_lrefs {
1086 local($_) = shift;
1087 local $trailing_and = s/and\s+$// ? "and " : "";
1088
1089 s{L</([^>]+)>}{$1}g;
1090 my(@items) = split( /(?:,?\s+(?:and\s+)?)/ );
1091 my $retstr = "the ";
1092 my $i;
1093 for ($i = 0; $i <= $#items; $i++) {
1094 $retstr .= "C<$items[$i]>";
1095 $retstr .= ", " if @items > 2 && $i != $#items;
1096 $retstr .= " and " if $i+2 == @items;
1097 }
1098
1099 $retstr .= " entr" . ( @items > 1 ? "ies" : "y" )
1100 . " elsewhere in this document";
1101 # terminal space to avoid words running together (pattern used
1102 # strips terminal spaces)
1103 $retstr .= " " if length $trailing_and;
1104 $retstr .= $trailing_and;
1105
1106 return $retstr;
1107
1108}
1109
1110BEGIN {
1111%HTML_Escapes = (
1112 'amp' => '&', # ampersand
1113 'lt' => '<', # left chevron, less-than
1114 'gt' => '>', # right chevron, greater-than
1115 'quot' => '"', # double quote
1116
1117 "Aacute" => "A\\*'", # capital A, acute accent
1118 "aacute" => "a\\*'", # small a, acute accent
1119 "Acirc" => "A\\*^", # capital A, circumflex accent
1120 "acirc" => "a\\*^", # small a, circumflex accent
1121 "AElig" => '\*(AE', # capital AE diphthong (ligature)
1122 "aelig" => '\*(ae', # small ae diphthong (ligature)
1123 "Agrave" => "A\\*`", # capital A, grave accent
1124 "agrave" => "A\\*`", # small a, grave accent
1125 "Aring" => 'A\\*o', # capital A, ring
1126 "aring" => 'a\\*o', # small a, ring
1127 "Atilde" => 'A\\*~', # capital A, tilde
1128 "atilde" => 'a\\*~', # small a, tilde
1129 "Auml" => 'A\\*:', # capital A, dieresis or umlaut mark
1130 "auml" => 'a\\*:', # small a, dieresis or umlaut mark
1131 "Ccedil" => 'C\\*,', # capital C, cedilla
1132 "ccedil" => 'c\\*,', # small c, cedilla
1133 "Eacute" => "E\\*'", # capital E, acute accent
1134 "eacute" => "e\\*'", # small e, acute accent
1135 "Ecirc" => "E\\*^", # capital E, circumflex accent
1136 "ecirc" => "e\\*^", # small e, circumflex accent
1137 "Egrave" => "E\\*`", # capital E, grave accent
1138 "egrave" => "e\\*`", # small e, grave accent
1139 "ETH" => '\\*(D-', # capital Eth, Icelandic
1140 "eth" => '\\*(d-', # small eth, Icelandic
1141 "Euml" => "E\\*:", # capital E, dieresis or umlaut mark
1142 "euml" => "e\\*:", # small e, dieresis or umlaut mark
1143 "Iacute" => "I\\*'", # capital I, acute accent
1144 "iacute" => "i\\*'", # small i, acute accent
1145 "Icirc" => "I\\*^", # capital I, circumflex accent
1146 "icirc" => "i\\*^", # small i, circumflex accent
1147 "Igrave" => "I\\*`", # capital I, grave accent
1148 "igrave" => "i\\*`", # small i, grave accent
1149 "Iuml" => "I\\*:", # capital I, dieresis or umlaut mark
1150 "iuml" => "i\\*:", # small i, dieresis or umlaut mark
1151 "Ntilde" => 'N\*~', # capital N, tilde
1152 "ntilde" => 'n\*~', # small n, tilde
1153 "Oacute" => "O\\*'", # capital O, acute accent
1154 "oacute" => "o\\*'", # small o, acute accent
1155 "Ocirc" => "O\\*^", # capital O, circumflex accent
1156 "ocirc" => "o\\*^", # small o, circumflex accent
1157 "Ograve" => "O\\*`", # capital O, grave accent
1158 "ograve" => "o\\*`", # small o, grave accent
1159 "Oslash" => "O\\*/", # capital O, slash
1160 "oslash" => "o\\*/", # small o, slash
1161 "Otilde" => "O\\*~", # capital O, tilde
1162 "otilde" => "o\\*~", # small o, tilde
1163 "Ouml" => "O\\*:", # capital O, dieresis or umlaut mark
1164 "ouml" => "o\\*:", # small o, dieresis or umlaut mark
1165 "szlig" => '\*8', # small sharp s, German (sz ligature)
1166 "THORN" => '\\*(Th', # capital THORN, Icelandic
1167 "thorn" => '\\*(th',, # small thorn, Icelandic
1168 "Uacute" => "U\\*'", # capital U, acute accent
1169 "uacute" => "u\\*'", # small u, acute accent
1170 "Ucirc" => "U\\*^", # capital U, circumflex accent
1171 "ucirc" => "u\\*^", # small u, circumflex accent
1172 "Ugrave" => "U\\*`", # capital U, grave accent
1173 "ugrave" => "u\\*`", # small u, grave accent
1174 "Uuml" => "U\\*:", # capital U, dieresis or umlaut mark
1175 "uuml" => "u\\*:", # small u, dieresis or umlaut mark
1176 "Yacute" => "Y\\*'", # capital Y, acute accent
1177 "yacute" => "y\\*'", # small y, acute accent
1178 "yuml" => "y\\*:", # small y, dieresis or umlaut mark
1179);
1180}
1181
diff --git a/src/lib/libcrypto/util/selftest.pl b/src/lib/libcrypto/util/selftest.pl
new file mode 100644
index 0000000000..91e962a312
--- /dev/null
+++ b/src/lib/libcrypto/util/selftest.pl
@@ -0,0 +1,174 @@
1#!/usr/local/bin/perl -w
2#
3# Run the test suite and generate a report
4#
5
6if (! -f "Configure") {
7 print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
8 exit 1;
9}
10
11my $report="testlog";
12my $os="??";
13my $version="??";
14my $platform0="??";
15my $platform="??";
16my $options="??";
17my $last="??";
18my $ok=0;
19my $cc="cc";
20my $cversion="??";
21my $sep="-----------------------------------------------------------------------------\n";
22
23open(OUT,">$report") or die;
24
25print OUT "OpenSSL self-test report:\n\n";
26
27$uname=`uname -a`;
28$uname="??" if $uname eq "";
29
30$c=`sh config -t`;
31foreach $_ (split("\n",$c)) {
32 $os=$1 if (/Operating system: (.*)$/);
33 $platform0=$1 if (/Configuring for (.*)$/);
34}
35
36system "sh config" if (! -f "Makefile.ssl");
37
38if (open(IN,"<Makefile.ssl")) {
39 while (<IN>) {
40 $version=$1 if (/^VERSION=(.*)$/);
41 $platform=$1 if (/^PLATFORM=(.*)$/);
42 $options=$1 if (/^OPTIONS=(.*)$/);
43 $cc=$1 if (/^CC= *(.*)$/);
44 }
45 close(IN);
46} else {
47 print OUT "Error running config!\n";
48}
49
50$cversion=`$cc -v 2>&1`;
51$cversion=`$cc -V 2>&1` if $cversion =~ "usage";
52$cversion=`$cc --version` if $cversion eq "";
53$cversion =~ s/Reading specs.*\n//;
54$cversion =~ s/usage.*\n//;
55chomp $cversion;
56
57if (open(IN,"<CHANGES")) {
58 while(<IN>) {
59 if (/\*\) (.{0,55})/) {
60 $last=$1;
61 last;
62 }
63 }
64 close(IN);
65}
66
67print OUT "OpenSSL version: $version\n";
68print OUT "Last change: $last...\n";
69print OUT "Options: $options\n" if $options ne "";
70print OUT "OS (uname): $uname";
71print OUT "OS (config): $os\n";
72print OUT "Target (default): $platform0\n";
73print OUT "Target: $platform\n";
74print OUT "Compiler: $cversion\n";
75print OUT "\n";
76
77print "Checking compiler...\n";
78if (open(TEST,">cctest.c")) {
79 print TEST "#include <stdio.h>\nmain(){printf(\"Hello world\\n\");}\n";
80 close(TEST);
81 system("$cc -o cctest cctest.c");
82 if (`./cctest` !~ /Hello world/) {
83 print OUT "Compiler doesn't work.\n";
84 goto err;
85 }
86} else {
87 print OUT "Can't create cctest.c\n";
88}
89if (open(TEST,">cctest.c")) {
90 print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
91 close(TEST);
92 system("$cc -o cctest -Iinclude cctest.c");
93 $cctest = `./cctest`;
94 if ($cctest !~ /OpenSSL $version/) {
95 if ($cctest =~ /OpenSSL/) {
96 print OUT "#include uses headers from different OpenSSL version!\n";
97 } else {
98 print OUT "Can't compile test program!\n";
99 }
100 goto err;
101 }
102} else {
103 print OUT "Can't create cctest.c\n";
104}
105
106print "Running make...\n";
107if (system("make 2>&1 | tee make.log") > 255) {
108
109 print OUT "make failed!\n";
110 if (open(IN,"<make.log")) {
111 print OUT $sep;
112 while (<IN>) {
113 print OUT;
114 }
115 close(IN);
116 print OUT $sep;
117 } else {
118 print OUT "make.log not found!\n";
119 }
120 goto err;
121}
122
123$_=$options;
124s/no-asm//;
125if (/no-/)
126{
127 print OUT "Test skipped.\n";
128 goto err;
129}
130
131print "Running make test...\n";
132if (system("make test 2>&1 | tee make.log") > 255)
133 {
134 print OUT "make test failed!\n";
135} else {
136 $ok=1;
137}
138
139if ($ok and open(IN,"<make.log")) {
140 while (<IN>) {
141 $ok=2 if /^platform: $platform/;
142 }
143 close(IN);
144}
145
146if ($ok != 2) {
147 print OUT "Failure!\n";
148 if (open(IN,"<make.log")) {
149 print OUT $sep;
150 while (<IN>) {
151 print OUT;
152 }
153 close(IN);
154 print OUT $sep;
155 } else {
156 print OUT "make.log not found!\n";
157 }
158} else {
159 print OUT "Test passed.\n";
160}
161err:
162close(OUT);
163
164print "\n";
165open(IN,"<$report") or die;
166while (<IN>) {
167 if (/$sep/) {
168 print "[...]\n";
169 last;
170 }
171 print;
172}
173print "\nTest report in file $report\n";
174
diff --git a/src/lib/libcrypto/util/ssleay.num b/src/lib/libcrypto/util/ssleay.num
index 8121738bd6..32b2e960c4 100644
--- a/src/lib/libcrypto/util/ssleay.num
+++ b/src/lib/libcrypto/util/ssleay.num
@@ -215,3 +215,13 @@ SSL_CTX_set_cert_verify_callback 232
215sk_SSL_COMP_sort 233 215sk_SSL_COMP_sort 233
216sk_SSL_CIPHER_sort 234 216sk_SSL_CIPHER_sort 234
217SSL_CTX_set_default_passwd_cb_userdata 235 217SSL_CTX_set_default_passwd_cb_userdata 235
218SSL_set_purpose 236
219SSL_CTX_set_trust 237
220SSL_CTX_set_purpose 238
221SSL_set_trust 239
222SSL_get_finished 240
223SSL_get_peer_finished 241
224SSL_get1_session 242
225SSL_CTX_callback_ctrl 243
226SSL_callback_ctrl 244
227SSL_CTX_sessions 245
diff --git a/src/lib/libcrypto/x509/Makefile.ssl b/src/lib/libcrypto/x509/Makefile.ssl
index c7ac35f6cc..48937b43af 100644
--- a/src/lib/libcrypto/x509/Makefile.ssl
+++ b/src/lib/libcrypto/x509/Makefile.ssl
@@ -23,17 +23,17 @@ APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \ 25LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \
26 x509_obj.c x509_req.c x509_vfy.c \ 26 x509_obj.c x509_req.c x509spki.c x509_vfy.c \
27 x509_set.c x509rset.c x509_err.c \ 27 x509_set.c x509rset.c x509_err.c \
28 x509name.c x509_v3.c x509_ext.c \ 28 x509name.c x509_v3.c x509_ext.c x509_att.c \
29 x509type.c x509_lu.c x_all.c x509_txt.c \ 29 x509type.c x509_lu.c x_all.c x509_txt.c \
30 by_file.c by_dir.c 30 x509_trs.c by_file.c by_dir.c
31LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \ 31LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \
32 x509_obj.o x509_req.o x509_vfy.o \ 32 x509_obj.o x509_req.o x509spki.o x509_vfy.o \
33 x509_set.o x509rset.o x509_err.o \ 33 x509_set.o x509rset.o x509_err.o \
34 x509name.o x509_v3.o x509_ext.o \ 34 x509name.o x509_v3.o x509_ext.o x509_att.o \
35 x509type.o x509_lu.o x_all.o x509_txt.o \ 35 x509type.o x509_lu.o x_all.o x509_txt.o \
36 by_file.o by_dir.o 36 x509_trs.o by_file.o by_dir.o
37 37
38SRC= $(LIBSRC) 38SRC= $(LIBSRC)
39 39
@@ -123,14 +123,33 @@ by_file.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
123by_file.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 123by_file.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
124by_file.o: ../../include/openssl/stack.h ../../include/openssl/x509.h 124by_file.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
125by_file.o: ../../include/openssl/x509_vfy.h ../cryptlib.h 125by_file.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
126x509_att.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
127x509_att.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
128x509_att.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
129x509_att.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
130x509_att.o: ../../include/openssl/des.h ../../include/openssl/dh.h
131x509_att.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
132x509_att.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
133x509_att.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
134x509_att.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
135x509_att.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
136x509_att.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
137x509_att.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
138x509_att.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
139x509_att.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
140x509_att.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
141x509_att.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
142x509_att.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
143x509_att.o: ../../include/openssl/x509v3.h ../cryptlib.h
126x509_cmp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 144x509_cmp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
127x509_cmp.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 145x509_cmp.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
128x509_cmp.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 146x509_cmp.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
129x509_cmp.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 147x509_cmp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
130x509_cmp.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 148x509_cmp.o: ../../include/openssl/des.h ../../include/openssl/dh.h
131x509_cmp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 149x509_cmp.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
132x509_cmp.o: ../../include/openssl/err.h ../../include/openssl/evp.h 150x509_cmp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
133x509_cmp.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 151x509_cmp.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
152x509_cmp.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
134x509_cmp.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 153x509_cmp.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
135x509_cmp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 154x509_cmp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
136x509_cmp.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h 155x509_cmp.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
@@ -139,7 +158,7 @@ x509_cmp.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
139x509_cmp.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 158x509_cmp.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
140x509_cmp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 159x509_cmp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
141x509_cmp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 160x509_cmp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
142x509_cmp.o: ../cryptlib.h 161x509_cmp.o: ../../include/openssl/x509v3.h ../cryptlib.h
143x509_d2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 162x509_d2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
144x509_d2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 163x509_d2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
145x509_d2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 164x509_d2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -192,11 +211,12 @@ x509_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
192x509_ext.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 211x509_ext.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
193x509_ext.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 212x509_ext.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
194x509_ext.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 213x509_ext.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
195x509_ext.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 214x509_ext.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
196x509_ext.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 215x509_ext.o: ../../include/openssl/des.h ../../include/openssl/dh.h
197x509_ext.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 216x509_ext.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
198x509_ext.o: ../../include/openssl/err.h ../../include/openssl/evp.h 217x509_ext.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
199x509_ext.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 218x509_ext.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
219x509_ext.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
200x509_ext.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 220x509_ext.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
201x509_ext.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 221x509_ext.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
202x509_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h 222x509_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
@@ -205,7 +225,7 @@ x509_ext.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
205x509_ext.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 225x509_ext.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
206x509_ext.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 226x509_ext.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
207x509_ext.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 227x509_ext.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
208x509_ext.o: ../cryptlib.h 228x509_ext.o: ../../include/openssl/x509v3.h ../cryptlib.h
209x509_lu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 229x509_lu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
210x509_lu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 230x509_lu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
211x509_lu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 231x509_lu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -293,6 +313,24 @@ x509_set.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
293x509_set.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 313x509_set.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
294x509_set.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 314x509_set.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
295x509_set.o: ../cryptlib.h 315x509_set.o: ../cryptlib.h
316x509_trs.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
317x509_trs.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
318x509_trs.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
319x509_trs.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
320x509_trs.o: ../../include/openssl/des.h ../../include/openssl/dh.h
321x509_trs.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
322x509_trs.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
323x509_trs.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
324x509_trs.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
325x509_trs.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
326x509_trs.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
327x509_trs.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
328x509_trs.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
329x509_trs.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
330x509_trs.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
331x509_trs.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
332x509_trs.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
333x509_trs.o: ../../include/openssl/x509v3.h ../cryptlib.h
296x509_txt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 334x509_txt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
297x509_txt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 335x509_txt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
298x509_txt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 336x509_txt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -314,11 +352,12 @@ x509_txt.o: ../cryptlib.h
314x509_v3.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 352x509_v3.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
315x509_v3.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 353x509_v3.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
316x509_v3.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 354x509_v3.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
317x509_v3.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 355x509_v3.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
318x509_v3.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 356x509_v3.o: ../../include/openssl/des.h ../../include/openssl/dh.h
319x509_v3.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 357x509_v3.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
320x509_v3.o: ../../include/openssl/err.h ../../include/openssl/evp.h 358x509_v3.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
321x509_v3.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 359x509_v3.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
360x509_v3.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
322x509_v3.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 361x509_v3.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
323x509_v3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 362x509_v3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
324x509_v3.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h 363x509_v3.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
@@ -327,25 +366,25 @@ x509_v3.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
327x509_v3.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 366x509_v3.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
328x509_v3.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 367x509_v3.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
329x509_v3.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 368x509_v3.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
330x509_v3.o: ../cryptlib.h 369x509_v3.o: ../../include/openssl/x509v3.h ../cryptlib.h
331x509_vfy.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 370x509_vfy.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
332x509_vfy.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 371x509_vfy.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
333x509_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 372x509_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
334x509_vfy.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 373x509_vfy.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
335x509_vfy.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 374x509_vfy.o: ../../include/openssl/des.h ../../include/openssl/dh.h
336x509_vfy.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 375x509_vfy.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
337x509_vfy.o: ../../include/openssl/err.h ../../include/openssl/evp.h 376x509_vfy.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
338x509_vfy.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h 377x509_vfy.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
339x509_vfy.o: ../../include/openssl/md2.h ../../include/openssl/md5.h 378x509_vfy.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
340x509_vfy.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h 379x509_vfy.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
341x509_vfy.o: ../../include/openssl/opensslconf.h 380x509_vfy.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
342x509_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h 381x509_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
343x509_vfy.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h 382x509_vfy.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
344x509_vfy.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h 383x509_vfy.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
345x509_vfy.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 384x509_vfy.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
346x509_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 385x509_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
347x509_vfy.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 386x509_vfy.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
348x509_vfy.o: ../cryptlib.h 387x509_vfy.o: ../../include/openssl/x509v3.h ../cryptlib.h
349x509name.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 388x509name.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
350x509name.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 389x509name.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
351x509name.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 390x509name.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -380,6 +419,24 @@ x509rset.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
380x509rset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 419x509rset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
381x509rset.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 420x509rset.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
382x509rset.o: ../cryptlib.h 421x509rset.o: ../cryptlib.h
422x509spki.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
423x509spki.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
424x509spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
425x509spki.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
426x509spki.o: ../../include/openssl/des.h ../../include/openssl/dh.h
427x509spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
428x509spki.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
429x509spki.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
430x509spki.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
431x509spki.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
432x509spki.o: ../../include/openssl/opensslconf.h
433x509spki.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
434x509spki.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
435x509spki.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
436x509spki.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
437x509spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
438x509spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
439x509spki.o: ../cryptlib.h
383x509type.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 440x509type.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
384x509type.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 441x509type.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
385x509type.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 442x509type.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c
index 734e39ac77..14d12c56bd 100644
--- a/src/lib/libcrypto/x509/by_dir.c
+++ b/src/lib/libcrypto/x509/by_dir.c
@@ -59,10 +59,18 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include <errno.h> 61#include <errno.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64 62
65#include "cryptlib.h" 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
66#include <openssl/lhash.h> 74#include <openssl/lhash.h>
67#include <openssl/x509.h> 75#include <openssl/x509.h>
68 76
@@ -210,9 +218,9 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
210 memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)* 218 memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)*
211 sizeof(int)); 219 sizeof(int));
212 if (ctx->dirs != NULL) 220 if (ctx->dirs != NULL)
213 Free((char *)ctx->dirs); 221 Free(ctx->dirs);
214 if (ctx->dirs_type != NULL) 222 if (ctx->dirs_type != NULL)
215 Free((char *)ctx->dirs_type); 223 Free(ctx->dirs_type);
216 ctx->dirs=pp; 224 ctx->dirs=pp;
217 ctx->dirs_type=ip; 225 ctx->dirs_type=ip;
218 } 226 }
@@ -318,8 +326,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
318 /* we have added it to the cache so now pull 326 /* we have added it to the cache so now pull
319 * it out again */ 327 * it out again */
320 CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); 328 CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE);
321 tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs, 329 tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs,&stmp);
322 (char *)&stmp);
323 CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); 330 CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
324 331
325 if (tmp != NULL) 332 if (tmp != NULL)
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c
index 00ee5e8bbc..78e9240a8d 100644
--- a/src/lib/libcrypto/x509/by_file.c
+++ b/src/lib/libcrypto/x509/by_file.c
@@ -59,8 +59,6 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include <errno.h> 61#include <errno.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64 62
65#include "cryptlib.h" 63#include "cryptlib.h"
66#include <openssl/lhash.h> 64#include <openssl/lhash.h>
@@ -94,7 +92,7 @@ X509_LOOKUP_METHOD *X509_LOOKUP_file(void)
94static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, 92static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
95 char **ret) 93 char **ret)
96 { 94 {
97 int ok=0,ok2=0; 95 int ok=0;
98 char *file; 96 char *file;
99 97
100 switch (cmd) 98 switch (cmd)
@@ -102,31 +100,30 @@ static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
102 case X509_L_FILE_LOAD: 100 case X509_L_FILE_LOAD:
103 if (argl == X509_FILETYPE_DEFAULT) 101 if (argl == X509_FILETYPE_DEFAULT)
104 { 102 {
105 ok=X509_load_cert_file(ctx,X509_get_default_cert_file(), 103 ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(),
106 X509_FILETYPE_PEM); 104 X509_FILETYPE_PEM) != 0);
107 ok2=X509_load_crl_file(ctx,X509_get_default_cert_file(), 105 if (!ok)
108 X509_FILETYPE_PEM);
109 if (!ok || !ok2)
110 { 106 {
111 X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS); 107 X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS);
112 } 108 }
113 else 109 else
114 { 110 {
115 file=(char *)Getenv(X509_get_default_cert_file_env()); 111 file=(char *)Getenv(X509_get_default_cert_file_env());
116 ok=X509_load_cert_file(ctx,file, 112 ok = (X509_load_cert_crl_file(ctx,file,
117 X509_FILETYPE_PEM); 113 X509_FILETYPE_PEM) != 0);
118 ok2=X509_load_crl_file(ctx,file,
119 X509_FILETYPE_PEM);
120 } 114 }
121 } 115 }
122 else 116 else
123 { 117 {
124 ok=X509_load_cert_file(ctx,argp,(int)argl); 118 if(argl == X509_FILETYPE_PEM)
125 ok2=X509_load_crl_file(ctx,argp,(int)argl); 119 ok = (X509_load_cert_crl_file(ctx,argp,
120 X509_FILETYPE_PEM) != 0);
121 else
122 ok = (X509_load_cert_file(ctx,argp,(int)argl) != 0);
126 } 123 }
127 break; 124 break;
128 } 125 }
129 return((ok && ok2)?ok:0); 126 return(ok);
130 } 127 }
131 128
132int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) 129int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
@@ -149,7 +146,7 @@ int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
149 { 146 {
150 for (;;) 147 for (;;)
151 { 148 {
152 x=PEM_read_bio_X509(in,NULL,NULL,NULL); 149 x=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL);
153 if (x == NULL) 150 if (x == NULL)
154 { 151 {
155 if ((ERR_GET_REASON(ERR_peek_error()) == 152 if ((ERR_GET_REASON(ERR_peek_error()) ==
@@ -263,5 +260,39 @@ err:
263 return(ret); 260 return(ret);
264 } 261 }
265 262
263int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type)
264{
265 STACK_OF(X509_INFO) *inf;
266 X509_INFO *itmp;
267 BIO *in;
268 int i, count = 0;
269 if(type != X509_FILETYPE_PEM)
270 return X509_load_cert_file(ctx, file, type);
271 in = BIO_new_file(file, "r");
272 if(!in) {
273 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_SYS_LIB);
274 return 0;
275 }
276 inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
277 BIO_free(in);
278 if(!inf) {
279 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB);
280 return 0;
281 }
282 for(i = 0; i < sk_X509_INFO_num(inf); i++) {
283 itmp = sk_X509_INFO_value(inf, i);
284 if(itmp->x509) {
285 X509_STORE_add_cert(ctx->store_ctx, itmp->x509);
286 count++;
287 } else if(itmp->crl) {
288 X509_STORE_add_crl(ctx->store_ctx, itmp->crl);
289 count++;
290 }
291 }
292 sk_X509_INFO_pop_free(inf, X509_INFO_free);
293 return count;
294}
295
296
266#endif /* NO_STDIO */ 297#endif /* NO_STDIO */
267 298
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
index 35f9484f8b..d3336d9ceb 100644
--- a/src/lib/libcrypto/x509/x509.h
+++ b/src/lib/libcrypto/x509/x509.h
@@ -176,9 +176,8 @@ typedef struct X509_extension_st
176 short critical; 176 short critical;
177 short netscape_hack; 177 short netscape_hack;
178 ASN1_OCTET_STRING *value; 178 ASN1_OCTET_STRING *value;
179 long argl; /* used when decoding */ 179 struct v3_ext_method *method; /* V3 method to use */
180 char *argp; /* used when decoding */ 180 void *ext_val; /* extension value */
181 void (*ex_free)(); /* clear argp stuff */
182 } X509_EXTENSION; 181 } X509_EXTENSION;
183 182
184DECLARE_STACK_OF(X509_EXTENSION) 183DECLARE_STACK_OF(X509_EXTENSION)
@@ -231,6 +230,21 @@ typedef struct x509_cinf_st
231 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */ 230 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
232 } X509_CINF; 231 } X509_CINF;
233 232
233/* This stuff is certificate "auxiliary info"
234 * it contains details which are useful in certificate
235 * stores and databases. When used this is tagged onto
236 * the end of the certificate itself
237 */
238
239typedef struct x509_cert_aux_st
240 {
241 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
242 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
243 ASN1_UTF8STRING *alias; /* "friendly name" */
244 ASN1_OCTET_STRING *keyid; /* key id of private key */
245 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
246 } X509_CERT_AUX;
247
234typedef struct x509_st 248typedef struct x509_st
235 { 249 {
236 X509_CINF *cert_info; 250 X509_CINF *cert_info;
@@ -239,11 +253,58 @@ typedef struct x509_st
239 int valid; 253 int valid;
240 int references; 254 int references;
241 char *name; 255 char *name;
256 CRYPTO_EX_DATA ex_data;
257 /* These contain copies of various extension values */
258 long ex_pathlen;
259 unsigned long ex_flags;
260 unsigned long ex_kusage;
261 unsigned long ex_xkusage;
262 unsigned long ex_nscert;
263#ifndef NO_SHA
264 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
265#endif
266 X509_CERT_AUX *aux;
242 } X509; 267 } X509;
243 268
244DECLARE_STACK_OF(X509) 269DECLARE_STACK_OF(X509)
245DECLARE_ASN1_SET_OF(X509) 270DECLARE_ASN1_SET_OF(X509)
246 271
272/* This is used for a table of trust checking functions */
273
274typedef struct x509_trust_st {
275 int trust;
276 int flags;
277 int (*check_trust)(struct x509_trust_st *, X509 *, int);
278 char *name;
279 int arg1;
280 void *arg2;
281} X509_TRUST;
282
283DECLARE_STACK_OF(X509_TRUST)
284
285/* standard trust ids */
286
287#define X509_TRUST_ANY 1
288#define X509_TRUST_SSL_CLIENT 2
289#define X509_TRUST_SSL_SERVER 3
290#define X509_TRUST_EMAIL 4
291#define X509_TRUST_OBJECT_SIGN 5
292
293/* Keep these up to date! */
294#define X509_TRUST_MIN 1
295#define X509_TRUST_MAX 5
296
297
298/* trust_flags values */
299#define X509_TRUST_DYNAMIC 1
300#define X509_TRUST_DYNAMIC_NAME 2
301
302/* check_trust return codes */
303
304#define X509_TRUST_TRUSTED 1
305#define X509_TRUST_REJECTED 2
306#define X509_TRUST_UNTRUSTED 3
307
247typedef struct X509_revoked_st 308typedef struct X509_revoked_st
248 { 309 {
249 ASN1_INTEGER *serialNumber; 310 ASN1_INTEGER *serialNumber;
@@ -318,7 +379,7 @@ DECLARE_STACK_OF(X509_INFO)
318 379
319/* The next 2 structures and their 8 routines were sent to me by 380/* The next 2 structures and their 8 routines were sent to me by
320 * Pat Richard <patr@x509.com> and are used to manipulate 381 * Pat Richard <patr@x509.com> and are used to manipulate
321 * Netscapes spki strucutres - usefull if you are writing a CA web page 382 * Netscapes spki structures - useful if you are writing a CA web page
322 */ 383 */
323typedef struct Netscape_spkac_st 384typedef struct Netscape_spkac_st
324 { 385 {
@@ -372,8 +433,10 @@ X509_ALGOR *prf;
372typedef struct pkcs8_priv_key_info_st 433typedef struct pkcs8_priv_key_info_st
373 { 434 {
374 int broken; /* Flag for various broken formats */ 435 int broken; /* Flag for various broken formats */
375#define PKCS8_OK 0 436#define PKCS8_OK 0
376#define PKCS8_NO_OCTET 1 437#define PKCS8_NO_OCTET 1
438#define PKCS8_EMBEDDED_PARAM 2
439#define PKCS8_NS_DB 3
377 ASN1_INTEGER *version; 440 ASN1_INTEGER *version;
378 X509_ALGOR *pkeyalg; 441 X509_ALGOR *pkeyalg;
379 ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */ 442 ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
@@ -552,13 +615,20 @@ int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
552int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); 615int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
553int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); 616int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
554 617
618NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len);
619char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x);
620EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x);
621int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);
622
623int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);
624
555int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); 625int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
556int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); 626int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
557int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md); 627int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
558int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md); 628int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
559 629
560int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len); 630int X509_digest(X509 *data,const EVP_MD *type,unsigned char *md,unsigned int *len);
561int X509_NAME_digest(X509_NAME *data,EVP_MD *type, 631int X509_NAME_digest(X509_NAME *data,const EVP_MD *type,
562 unsigned char *md,unsigned int *len); 632 unsigned char *md,unsigned int *len);
563#endif 633#endif
564 634
@@ -574,16 +644,23 @@ RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
574int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa); 644int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
575RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa); 645RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
576int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa); 646int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
647RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa);
648int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa);
577#endif 649#endif
578#ifndef NO_DSA 650#ifndef NO_DSA
651DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);
652int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
579DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); 653DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
580int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); 654int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
655#endif
581X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8); 656X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
582int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8); 657int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
583PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, 658PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
584 PKCS8_PRIV_KEY_INFO **p8inf); 659 PKCS8_PRIV_KEY_INFO **p8inf);
585int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf); 660int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
586#endif 661int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);
662int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
663EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
587#endif 664#endif
588 665
589#ifdef HEADER_BIO_H 666#ifdef HEADER_BIO_H
@@ -598,8 +675,12 @@ RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
598int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa); 675int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
599RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa); 676RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
600int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa); 677int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
678RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);
679int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);
601#endif 680#endif
602#ifndef NO_DSA 681#ifndef NO_DSA
682DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);
683int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
603DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); 684DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
604int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); 685int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
605#endif 686#endif
@@ -608,6 +689,9 @@ int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
608PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, 689PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
609 PKCS8_PRIV_KEY_INFO **p8inf); 690 PKCS8_PRIV_KEY_INFO **p8inf);
610int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf); 691int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
692int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);
693int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);
694EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
611#endif 695#endif
612 696
613X509 *X509_dup(X509 *x509); 697X509 *X509_dup(X509 *x509);
@@ -635,7 +719,7 @@ const char * X509_get_default_cert_dir_env(void );
635const char * X509_get_default_cert_file_env(void ); 719const char * X509_get_default_cert_file_env(void );
636const char * X509_get_default_private_dir(void ); 720const char * X509_get_default_private_dir(void );
637 721
638X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md); 722X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
639X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey); 723X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
640void ERR_load_X509_strings(void ); 724void ERR_load_X509_strings(void );
641 725
@@ -660,7 +744,19 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
660EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); 744EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
661int X509_get_pubkey_parameters(EVP_PKEY *pkey, 745int X509_get_pubkey_parameters(EVP_PKEY *pkey,
662 STACK_OF(X509) *chain); 746 STACK_OF(X509) *chain);
663 747int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
748EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,unsigned char **pp,
749 long length);
750#ifndef NO_RSA
751int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
752RSA * d2i_RSA_PUBKEY(RSA **a,unsigned char **pp,
753 long length);
754#endif
755#ifndef NO_DSA
756int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
757DSA * d2i_DSA_PUBKEY(DSA **a,unsigned char **pp,
758 long length);
759#endif
664 760
665X509_SIG * X509_SIG_new(void ); 761X509_SIG * X509_SIG_new(void );
666void X509_SIG_free(X509_SIG *a); 762void X509_SIG_free(X509_SIG *a);
@@ -714,6 +810,25 @@ X509 * X509_new(void);
714void X509_free(X509 *a); 810void X509_free(X509 *a);
715int i2d_X509(X509 *a,unsigned char **pp); 811int i2d_X509(X509 *a,unsigned char **pp);
716X509 * d2i_X509(X509 **a,unsigned char **pp,long length); 812X509 * d2i_X509(X509 **a,unsigned char **pp,long length);
813int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
814 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
815int X509_set_ex_data(X509 *r, int idx, void *arg);
816void *X509_get_ex_data(X509 *r, int idx);
817int i2d_X509_AUX(X509 *a,unsigned char **pp);
818X509 * d2i_X509_AUX(X509 **a,unsigned char **pp,long length);
819
820X509_CERT_AUX * X509_CERT_AUX_new(void);
821void X509_CERT_AUX_free(X509_CERT_AUX *a);
822int i2d_X509_CERT_AUX(X509_CERT_AUX *a,unsigned char **pp);
823X509_CERT_AUX * d2i_X509_CERT_AUX(X509_CERT_AUX **a,unsigned char **pp,
824 long length);
825int X509_alias_set1(X509 *x, unsigned char *name, int len);
826unsigned char * X509_alias_get0(X509 *x, int *len);
827int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);
828int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
829int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj);
830void X509_trust_clear(X509 *x);
831void X509_reject_clear(X509 *x);
717 832
718X509_REVOKED * X509_REVOKED_new(void); 833X509_REVOKED * X509_REVOKED_new(void);
719void X509_REVOKED_free(X509_REVOKED *a); 834void X509_REVOKED_free(X509_REVOKED *a);
@@ -762,7 +877,7 @@ char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
762int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1, 877int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
763 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey); 878 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
764 879
765int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data, 880int ASN1_digest(int (*i2d)(),const EVP_MD *type,char *data,
766 unsigned char *md,unsigned int *len); 881 unsigned char *md,unsigned int *len);
767 882
768int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2, 883int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
@@ -787,6 +902,30 @@ int X509_REQ_set_version(X509_REQ *x,long version);
787int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name); 902int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
788int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey); 903int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
789EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req); 904EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req);
905int X509_REQ_extension_nid(int nid);
906int * X509_REQ_get_extension_nids(void);
907void X509_REQ_set_extension_nids(int *nids);
908STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);
909int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
910 int nid);
911int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts);
912int X509_REQ_get_attr_count(const X509_REQ *req);
913int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
914 int lastpos);
915int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
916 int lastpos);
917X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
918X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
919int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
920int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
921 ASN1_OBJECT *obj, int type,
922 unsigned char *bytes, int len);
923int X509_REQ_add1_attr_by_NID(X509_REQ *req,
924 int nid, int type,
925 unsigned char *bytes, int len);
926int X509_REQ_add1_attr_by_txt(X509_REQ *req,
927 char *attrname, int type,
928 unsigned char *bytes, int len);
790 929
791int X509_check_private_key(X509 *x509,EVP_PKEY *pkey); 930int X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
792 931
@@ -799,6 +938,7 @@ unsigned long X509_issuer_name_hash(X509 *a);
799int X509_subject_name_cmp(X509 *a,X509 *b); 938int X509_subject_name_cmp(X509 *a,X509 *b);
800unsigned long X509_subject_name_hash(X509 *x); 939unsigned long X509_subject_name_hash(X509 *x);
801 940
941int X509_cmp (X509 *a, X509 *b);
802int X509_NAME_cmp (X509_NAME *a, X509_NAME *b); 942int X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
803unsigned long X509_NAME_hash(X509_NAME *x); 943unsigned long X509_NAME_hash(X509_NAME *x);
804 944
@@ -812,6 +952,7 @@ int X509_REQ_print_fp(FILE *bp,X509_REQ *req);
812#ifdef HEADER_BIO_H 952#ifdef HEADER_BIO_H
813int X509_NAME_print(BIO *bp, X509_NAME *name, int obase); 953int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
814int X509_print(BIO *bp,X509 *x); 954int X509_print(BIO *bp,X509 *x);
955int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent);
815int X509_CRL_print(BIO *bp,X509_CRL *x); 956int X509_CRL_print(BIO *bp,X509_CRL *x);
816int X509_REQ_print(BIO *bp,X509_REQ *req); 957int X509_REQ_print(BIO *bp,X509_REQ *req);
817#endif 958#endif
@@ -823,7 +964,7 @@ int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
823 char *buf,int len); 964 char *buf,int len);
824 965
825/* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use 966/* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use
826 * lastpos, seach after that position on. */ 967 * lastpos, search after that position on. */
827int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos); 968int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
828int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj, 969int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
829 int lastpos); 970 int lastpos);
@@ -831,8 +972,16 @@ X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
831X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); 972X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
832int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, 973int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
833 int loc, int set); 974 int loc, int set);
975int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
976 unsigned char *bytes, int len, int loc, int set);
977int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
978 unsigned char *bytes, int len, int loc, int set);
979X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
980 char *field, int type, unsigned char *bytes, int len);
834X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, 981X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
835 int type,unsigned char *bytes, int len); 982 int type,unsigned char *bytes, int len);
983int X509_NAME_add_entry_by_txt(X509_NAME *name, char *field, int type,
984 unsigned char *bytes, int len, int loc, int set);
836X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, 985X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
837 ASN1_OBJECT *obj, int type,unsigned char *bytes, 986 ASN1_OBJECT *obj, int type,unsigned char *bytes,
838 int len); 987 int len);
@@ -862,6 +1011,7 @@ int X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
862X509_EXTENSION *X509_get_ext(X509 *x, int loc); 1011X509_EXTENSION *X509_get_ext(X509 *x, int loc);
863X509_EXTENSION *X509_delete_ext(X509 *x, int loc); 1012X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
864int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); 1013int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
1014void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
865 1015
866int X509_CRL_get_ext_count(X509_CRL *x); 1016int X509_CRL_get_ext_count(X509_CRL *x);
867int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos); 1017int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
@@ -870,6 +1020,7 @@ int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
870X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc); 1020X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
871X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); 1021X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
872int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); 1022int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
1023void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
873 1024
874int X509_REVOKED_get_ext_count(X509_REVOKED *x); 1025int X509_REVOKED_get_ext_count(X509_REVOKED *x);
875int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos); 1026int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
@@ -878,6 +1029,7 @@ int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
878X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc); 1029X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
879X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); 1030X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
880int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc); 1031int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
1032void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
881 1033
882X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, 1034X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
883 int nid, int crit, ASN1_OCTET_STRING *data); 1035 int nid, int crit, ASN1_OCTET_STRING *data);
@@ -891,6 +1043,38 @@ ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex);
891ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); 1043ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
892int X509_EXTENSION_get_critical(X509_EXTENSION *ex); 1044int X509_EXTENSION_get_critical(X509_EXTENSION *ex);
893 1045
1046int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
1047int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
1048 int lastpos);
1049int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
1050 int lastpos);
1051X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
1052X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
1053STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
1054 X509_ATTRIBUTE *attr);
1055STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
1056 ASN1_OBJECT *obj, int type,
1057 unsigned char *bytes, int len);
1058STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
1059 int nid, int type,
1060 unsigned char *bytes, int len);
1061STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
1062 char *attrname, int type,
1063 unsigned char *bytes, int len);
1064X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
1065 int atrtype, void *data, int len);
1066X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
1067 ASN1_OBJECT *obj, int atrtype, void *data, int len);
1068X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
1069 char *atrname, int type, unsigned char *bytes, int len);
1070int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, ASN1_OBJECT *obj);
1071int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, void *data, int len);
1072void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
1073 int atrtype, void *data);
1074int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
1075ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
1076ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
1077
894int X509_verify_cert(X509_STORE_CTX *ctx); 1078int X509_verify_cert(X509_STORE_CTX *ctx);
895 1079
896/* lookup a cert from a X509 STACK */ 1080/* lookup a cert from a X509 STACK */
@@ -926,8 +1110,20 @@ void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
926 1110
927EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8); 1111EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
928PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); 1112PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
1113PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken);
929PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken); 1114PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
930 1115
1116int X509_check_trust(X509 *x, int id, int flags);
1117int X509_TRUST_get_count(void);
1118X509_TRUST * X509_TRUST_get0(int idx);
1119int X509_TRUST_get_by_id(int id);
1120int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
1121 char *name, int arg1, void *arg2);
1122void X509_TRUST_cleanup(void);
1123int X509_TRUST_get_flags(X509_TRUST *xp);
1124char *X509_TRUST_get0_name(X509_TRUST *xp);
1125int X509_TRUST_get_trust(X509_TRUST *xp);
1126
931/* BEGIN ERROR CODES */ 1127/* BEGIN ERROR CODES */
932/* The following lines are auto generated by the script mkerr.pl. Any changes 1128/* The following lines are auto generated by the script mkerr.pl. Any changes
933 * made after this point may be overwritten when the script is next run. 1129 * made after this point may be overwritten when the script is next run.
@@ -940,15 +1136,25 @@ PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
940#define X509_F_BY_FILE_CTRL 101 1136#define X509_F_BY_FILE_CTRL 101
941#define X509_F_DIR_CTRL 102 1137#define X509_F_DIR_CTRL 102
942#define X509_F_GET_CERT_BY_SUBJECT 103 1138#define X509_F_GET_CERT_BY_SUBJECT 103
1139#define X509_F_NETSCAPE_SPKI_B64_DECODE 129
1140#define X509_F_NETSCAPE_SPKI_B64_ENCODE 130
943#define X509_F_X509V3_ADD_EXT 104 1141#define X509_F_X509V3_ADD_EXT 104
1142#define X509_F_X509_ADD_ATTR 135
1143#define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136
1144#define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137
1145#define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140
1146#define X509_F_X509_ATTRIBUTE_GET0_DATA 139
1147#define X509_F_X509_ATTRIBUTE_SET1_DATA 138
944#define X509_F_X509_CHECK_PRIVATE_KEY 128 1148#define X509_F_X509_CHECK_PRIVATE_KEY 128
945#define X509_F_X509_EXTENSION_CREATE_BY_NID 108 1149#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
946#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 1150#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
947#define X509_F_X509_GET_PUBKEY_PARAMETERS 110 1151#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
1152#define X509_F_X509_LOAD_CERT_CRL_FILE 132
948#define X509_F_X509_LOAD_CERT_FILE 111 1153#define X509_F_X509_LOAD_CERT_FILE 111
949#define X509_F_X509_LOAD_CRL_FILE 112 1154#define X509_F_X509_LOAD_CRL_FILE 112
950#define X509_F_X509_NAME_ADD_ENTRY 113 1155#define X509_F_X509_NAME_ADD_ENTRY 113
951#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 1156#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114
1157#define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131
952#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 1158#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
953#define X509_F_X509_NAME_ONELINE 116 1159#define X509_F_X509_NAME_ONELINE 116
954#define X509_F_X509_NAME_PRINT 117 1160#define X509_F_X509_NAME_PRINT 117
@@ -960,15 +1166,19 @@ PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
960#define X509_F_X509_REQ_TO_X509 123 1166#define X509_F_X509_REQ_TO_X509 123
961#define X509_F_X509_STORE_ADD_CERT 124 1167#define X509_F_X509_STORE_ADD_CERT 124
962#define X509_F_X509_STORE_ADD_CRL 125 1168#define X509_F_X509_STORE_ADD_CRL 125
1169#define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134
963#define X509_F_X509_TO_X509_REQ 126 1170#define X509_F_X509_TO_X509_REQ 126
1171#define X509_F_X509_TRUST_ADD 133
964#define X509_F_X509_VERIFY_CERT 127 1172#define X509_F_X509_VERIFY_CERT 127
965 1173
966/* Reason codes. */ 1174/* Reason codes. */
967#define X509_R_BAD_X509_FILETYPE 100 1175#define X509_R_BAD_X509_FILETYPE 100
1176#define X509_R_BASE64_DECODE_ERROR 118
968#define X509_R_CANT_CHECK_DH_KEY 114 1177#define X509_R_CANT_CHECK_DH_KEY 114
969#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 1178#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
970#define X509_R_ERR_ASN1_LIB 102 1179#define X509_R_ERR_ASN1_LIB 102
971#define X509_R_INVALID_DIRECTORY 113 1180#define X509_R_INVALID_DIRECTORY 113
1181#define X509_R_INVALID_FIELD_NAME 119
972#define X509_R_KEY_TYPE_MISMATCH 115 1182#define X509_R_KEY_TYPE_MISMATCH 115
973#define X509_R_KEY_VALUES_MISMATCH 116 1183#define X509_R_KEY_VALUES_MISMATCH 116
974#define X509_R_LOADING_CERT_DIR 103 1184#define X509_R_LOADING_CERT_DIR 103
@@ -979,8 +1189,11 @@ PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
979#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 1189#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
980#define X509_R_UNKNOWN_KEY_TYPE 117 1190#define X509_R_UNKNOWN_KEY_TYPE 117
981#define X509_R_UNKNOWN_NID 109 1191#define X509_R_UNKNOWN_NID 109
1192#define X509_R_UNKNOWN_PURPOSE_ID 121
1193#define X509_R_UNKNOWN_TRUST_ID 120
982#define X509_R_UNSUPPORTED_ALGORITHM 111 1194#define X509_R_UNSUPPORTED_ALGORITHM 111
983#define X509_R_WRONG_LOOKUP_TYPE 112 1195#define X509_R_WRONG_LOOKUP_TYPE 112
1196#define X509_R_WRONG_TYPE 122
984 1197
985#ifdef __cplusplus 1198#ifdef __cplusplus
986} 1199}
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c
new file mode 100644
index 0000000000..caafde658f
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_att.c
@@ -0,0 +1,326 @@
1/* crypto/x509/x509_att.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x)
69{
70 if (!x) return 0;
71 return(sk_X509_ATTRIBUTE_num(x));
72}
73
74int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
75 int lastpos)
76{
77 ASN1_OBJECT *obj;
78
79 obj=OBJ_nid2obj(nid);
80 if (obj == NULL) return(-2);
81 return(X509at_get_attr_by_OBJ(x,obj,lastpos));
82}
83
84int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
85 int lastpos)
86{
87 int n;
88 X509_ATTRIBUTE *ex;
89
90 if (sk == NULL) return(-1);
91 lastpos++;
92 if (lastpos < 0)
93 lastpos=0;
94 n=sk_X509_ATTRIBUTE_num(sk);
95 for ( ; lastpos < n; lastpos++)
96 {
97 ex=sk_X509_ATTRIBUTE_value(sk,lastpos);
98 if (OBJ_cmp(ex->object,obj) == 0)
99 return(lastpos);
100 }
101 return(-1);
102}
103
104X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc)
105{
106 if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)
107 return NULL;
108 else
109 return sk_X509_ATTRIBUTE_value(x,loc);
110}
111
112X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc)
113{
114 X509_ATTRIBUTE *ret;
115
116 if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)
117 return(NULL);
118 ret=sk_X509_ATTRIBUTE_delete(x,loc);
119 return(ret);
120}
121
122STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
123 X509_ATTRIBUTE *attr)
124{
125 X509_ATTRIBUTE *new_attr=NULL;
126 STACK_OF(X509_ATTRIBUTE) *sk=NULL;
127
128 if ((x != NULL) && (*x == NULL))
129 {
130 if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL)
131 goto err;
132 }
133 else
134 sk= *x;
135
136 if ((new_attr=X509_ATTRIBUTE_dup(attr)) == NULL)
137 goto err2;
138 if (!sk_X509_ATTRIBUTE_push(sk,new_attr))
139 goto err;
140 if ((x != NULL) && (*x == NULL))
141 *x=sk;
142 return(sk);
143err:
144 X509err(X509_F_X509_ADD_ATTR,ERR_R_MALLOC_FAILURE);
145err2:
146 if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr);
147 if (sk != NULL) sk_X509_ATTRIBUTE_free(sk);
148 return(NULL);
149}
150
151STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
152 ASN1_OBJECT *obj, int type,
153 unsigned char *bytes, int len)
154{
155 X509_ATTRIBUTE *attr;
156 STACK_OF(X509_ATTRIBUTE) *ret;
157 attr = X509_ATTRIBUTE_create_by_OBJ(NULL, obj, type, bytes, len);
158 if(!attr) return 0;
159 ret = X509at_add1_attr(x, attr);
160 X509_ATTRIBUTE_free(attr);
161 return ret;
162}
163
164STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
165 int nid, int type,
166 unsigned char *bytes, int len)
167{
168 X509_ATTRIBUTE *attr;
169 STACK_OF(X509_ATTRIBUTE) *ret;
170 attr = X509_ATTRIBUTE_create_by_NID(NULL, nid, type, bytes, len);
171 if(!attr) return 0;
172 ret = X509at_add1_attr(x, attr);
173 X509_ATTRIBUTE_free(attr);
174 return ret;
175}
176
177STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
178 char *attrname, int type,
179 unsigned char *bytes, int len)
180{
181 X509_ATTRIBUTE *attr;
182 STACK_OF(X509_ATTRIBUTE) *ret;
183 attr = X509_ATTRIBUTE_create_by_txt(NULL, attrname, type, bytes, len);
184 if(!attr) return 0;
185 ret = X509at_add1_attr(x, attr);
186 X509_ATTRIBUTE_free(attr);
187 return ret;
188}
189
190X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
191 int atrtype, void *data, int len)
192{
193 ASN1_OBJECT *obj;
194 X509_ATTRIBUTE *ret;
195
196 obj=OBJ_nid2obj(nid);
197 if (obj == NULL)
198 {
199 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_NID,X509_R_UNKNOWN_NID);
200 return(NULL);
201 }
202 ret=X509_ATTRIBUTE_create_by_OBJ(attr,obj,atrtype,data,len);
203 if (ret == NULL) ASN1_OBJECT_free(obj);
204 return(ret);
205}
206
207X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
208 ASN1_OBJECT *obj, int atrtype, void *data, int len)
209{
210 X509_ATTRIBUTE *ret;
211
212 if ((attr == NULL) || (*attr == NULL))
213 {
214 if ((ret=X509_ATTRIBUTE_new()) == NULL)
215 {
216 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
217 return(NULL);
218 }
219 }
220 else
221 ret= *attr;
222
223 if (!X509_ATTRIBUTE_set1_object(ret,obj))
224 goto err;
225 if (!X509_ATTRIBUTE_set1_data(ret,atrtype,data,len))
226 goto err;
227
228 if ((attr != NULL) && (*attr == NULL)) *attr=ret;
229 return(ret);
230err:
231 if ((attr == NULL) || (ret != *attr))
232 X509_ATTRIBUTE_free(ret);
233 return(NULL);
234}
235
236X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
237 char *atrname, int type, unsigned char *bytes, int len)
238 {
239 ASN1_OBJECT *obj;
240 X509_ATTRIBUTE *nattr;
241
242 obj=OBJ_txt2obj(atrname, 0);
243 if (obj == NULL)
244 {
245 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT,
246 X509_R_INVALID_FIELD_NAME);
247 ERR_add_error_data(2, "name=", atrname);
248 return(NULL);
249 }
250 nattr = X509_ATTRIBUTE_create_by_OBJ(attr,obj,type,bytes,len);
251 ASN1_OBJECT_free(obj);
252 return nattr;
253 }
254
255int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, ASN1_OBJECT *obj)
256{
257 if ((attr == NULL) || (obj == NULL))
258 return(0);
259 ASN1_OBJECT_free(attr->object);
260 attr->object=OBJ_dup(obj);
261 return(1);
262}
263
264int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, void *data, int len)
265{
266 ASN1_TYPE *ttmp;
267 ASN1_STRING *stmp;
268 int atype;
269 if (!attr) return 0;
270 if(attrtype & MBSTRING_FLAG) {
271 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,
272 OBJ_obj2nid(attr->object));
273 if(!stmp) {
274 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_ASN1_LIB);
275 return 0;
276 }
277 atype = stmp->type;
278 } else {
279 if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err;
280 if(!ASN1_STRING_set(stmp, data, len)) goto err;
281 atype = attrtype;
282 }
283 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
284 if(!(ttmp = ASN1_TYPE_new())) goto err;
285 if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err;
286 attr->set = 1;
287 ASN1_TYPE_set(ttmp, atype, stmp);
288 return 1;
289 err:
290 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);
291 return 0;
292}
293
294int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr)
295{
296 if(attr->set) return sk_ASN1_TYPE_num(attr->value.set);
297 if(attr->value.single) return 1;
298 return 0;
299}
300
301ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr)
302{
303 if (attr == NULL) return(NULL);
304 return(attr->object);
305}
306
307void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
308 int atrtype, void *data)
309{
310 ASN1_TYPE *ttmp;
311 ttmp = X509_ATTRIBUTE_get0_type(attr, idx);
312 if(!ttmp) return NULL;
313 if(atrtype != ASN1_TYPE_get(ttmp)){
314 X509err(X509_F_X509_ATTRIBUTE_GET0_DATA, X509_R_WRONG_TYPE);
315 return NULL;
316 }
317 return ttmp->value.ptr;
318}
319
320ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx)
321{
322 if (attr == NULL) return(NULL);
323 if(idx >= X509_ATTRIBUTE_count(attr)) return NULL;
324 if(attr->set) return sk_ASN1_TYPE_value(attr->value.set, idx);
325 else return attr->value.single;
326}
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c
index 9a93bae3ff..a8a5ca8b03 100644
--- a/src/lib/libcrypto/x509/x509_cmp.c
+++ b/src/lib/libcrypto/x509/x509_cmp.c
@@ -57,12 +57,11 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <sys/types.h>
61#include <sys/stat.h>
62#include "cryptlib.h" 60#include "cryptlib.h"
63#include <openssl/asn1.h> 61#include <openssl/asn1.h>
64#include <openssl/objects.h> 62#include <openssl/objects.h>
65#include <openssl/x509.h> 63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
66 65
67int X509_issuer_and_serial_cmp(X509 *a, X509 *b) 66int X509_issuer_and_serial_cmp(X509 *a, X509 *b)
68 { 67 {
@@ -71,7 +70,7 @@ int X509_issuer_and_serial_cmp(X509 *a, X509 *b)
71 70
72 ai=a->cert_info; 71 ai=a->cert_info;
73 bi=b->cert_info; 72 bi=b->cert_info;
74 i=ASN1_INTEGER_cmp(ai->serialNumber,bi->serialNumber); 73 i=M_ASN1_INTEGER_cmp(ai->serialNumber,bi->serialNumber);
75 if (i) return(i); 74 if (i) return(i);
76 return(X509_NAME_cmp(ai->issuer,bi->issuer)); 75 return(X509_NAME_cmp(ai->issuer,bi->issuer));
77 } 76 }
@@ -138,6 +137,20 @@ unsigned long X509_subject_name_hash(X509 *x)
138 return(X509_NAME_hash(x->cert_info->subject)); 137 return(X509_NAME_hash(x->cert_info->subject));
139 } 138 }
140 139
140#ifndef NO_SHA
141/* Compare two certificates: they must be identical for
142 * this to work.
143 */
144int X509_cmp(X509 *a, X509 *b)
145{
146 /* ensure hash is valid */
147 X509_check_purpose(a, -1, 0);
148 X509_check_purpose(b, -1, 0);
149
150 return memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH);
151}
152#endif
153
141int X509_NAME_cmp(X509_NAME *a, X509_NAME *b) 154int X509_NAME_cmp(X509_NAME *a, X509_NAME *b)
142 { 155 {
143 int i,j; 156 int i,j;
@@ -175,7 +188,7 @@ int X509_NAME_cmp(X509_NAME *a, X509_NAME *b)
175 188
176#ifndef NO_MD5 189#ifndef NO_MD5
177/* I now DER encode the name and hash it. Since I cache the DER encoding, 190/* I now DER encode the name and hash it. Since I cache the DER encoding,
178 * this is reasonably effiecent. */ 191 * this is reasonably efficient. */
179unsigned long X509_NAME_hash(X509_NAME *x) 192unsigned long X509_NAME_hash(X509_NAME *x)
180 { 193 {
181 unsigned long ret=0; 194 unsigned long ret=0;
@@ -209,6 +222,8 @@ X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name,
209 X509_CINF cinf; 222 X509_CINF cinf;
210 X509 x,*x509=NULL; 223 X509 x,*x509=NULL;
211 224
225 if(!sk) return NULL;
226
212 x.cert_info= &cinf; 227 x.cert_info= &cinf;
213 cinf.serialNumber=serial; 228 cinf.serialNumber=serial;
214 cinf.issuer=name; 229 cinf.issuer=name;
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c
index 3e7ec5b432..753d53eb43 100644
--- a/src/lib/libcrypto/x509/x509_d2.c
+++ b/src/lib/libcrypto/x509/x509_d2.c
@@ -57,8 +57,6 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <sys/types.h>
61#include <sys/stat.h>
62#include "cryptlib.h" 60#include "cryptlib.h"
63#include <openssl/crypto.h> 61#include <openssl/crypto.h>
64#include <openssl/x509.h> 62#include <openssl/x509.h>
@@ -91,13 +89,15 @@ int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
91 { 89 {
92 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file()); 90 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
93 if (lookup == NULL) return(0); 91 if (lookup == NULL) return(0);
94 X509_LOOKUP_load_file(lookup,file,X509_FILETYPE_PEM); 92 if (X509_LOOKUP_load_file(lookup,file,X509_FILETYPE_PEM) != 1)
93 return(0);
95 } 94 }
96 if (path != NULL) 95 if (path != NULL)
97 { 96 {
98 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir()); 97 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
99 if (lookup == NULL) return(0); 98 if (lookup == NULL) return(0);
100 X509_LOOKUP_add_dir(lookup,path,X509_FILETYPE_PEM); 99 if (X509_LOOKUP_add_dir(lookup,path,X509_FILETYPE_PEM) != 1)
100 return(0);
101 } 101 }
102 if ((path == NULL) && (file == NULL)) 102 if ((path == NULL) && (file == NULL))
103 return(0); 103 return(0);
diff --git a/src/lib/libcrypto/x509/x509_def.c b/src/lib/libcrypto/x509/x509_def.c
index c4bee71569..e0ac151a76 100644
--- a/src/lib/libcrypto/x509/x509_def.c
+++ b/src/lib/libcrypto/x509/x509_def.c
@@ -57,8 +57,6 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <sys/types.h>
61#include <sys/stat.h>
62#include "cryptlib.h" 60#include "cryptlib.h"
63#include <openssl/crypto.h> 61#include <openssl/crypto.h>
64#include <openssl/x509.h> 62#include <openssl/x509.h>
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c
index 9afd4ccde5..fdedbdac34 100644
--- a/src/lib/libcrypto/x509/x509_err.c
+++ b/src/lib/libcrypto/x509/x509_err.c
@@ -69,15 +69,25 @@ static ERR_STRING_DATA X509_str_functs[]=
69{ERR_PACK(0,X509_F_BY_FILE_CTRL,0), "BY_FILE_CTRL"}, 69{ERR_PACK(0,X509_F_BY_FILE_CTRL,0), "BY_FILE_CTRL"},
70{ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"}, 70{ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"},
71{ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"}, 71{ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"},
72{ERR_PACK(0,X509_F_NETSCAPE_SPKI_B64_DECODE,0), "NETSCAPE_SPKI_b64_decode"},
73{ERR_PACK(0,X509_F_NETSCAPE_SPKI_B64_ENCODE,0), "NETSCAPE_SPKI_b64_encode"},
72{ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"}, 74{ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"},
75{ERR_PACK(0,X509_F_X509_ADD_ATTR,0), "X509_ADD_ATTR"},
76{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_NID,0), "X509_ATTRIBUTE_create_by_NID"},
77{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ,0), "X509_ATTRIBUTE_create_by_OBJ"},
78{ERR_PACK(0,X509_F_X509_ATTRIBUTE_CREATE_BY_TXT,0), "X509_ATTRIBUTE_create_by_txt"},
79{ERR_PACK(0,X509_F_X509_ATTRIBUTE_GET0_DATA,0), "X509_ATTRIBUTE_get0_data"},
80{ERR_PACK(0,X509_F_X509_ATTRIBUTE_SET1_DATA,0), "X509_ATTRIBUTE_set1_data"},
73{ERR_PACK(0,X509_F_X509_CHECK_PRIVATE_KEY,0), "X509_check_private_key"}, 81{ERR_PACK(0,X509_F_X509_CHECK_PRIVATE_KEY,0), "X509_check_private_key"},
74{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"}, 82{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"},
75{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"}, 83{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"},
76{ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"}, 84{ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"},
85{ERR_PACK(0,X509_F_X509_LOAD_CERT_CRL_FILE,0), "X509_load_cert_crl_file"},
77{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_load_cert_file"}, 86{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_load_cert_file"},
78{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_load_crl_file"}, 87{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_load_crl_file"},
79{ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"}, 88{ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"},
80{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"}, 89{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"},
90{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_TXT,0), "X509_NAME_ENTRY_create_by_txt"},
81{ERR_PACK(0,X509_F_X509_NAME_ENTRY_SET_OBJECT,0), "X509_NAME_ENTRY_set_object"}, 91{ERR_PACK(0,X509_F_X509_NAME_ENTRY_SET_OBJECT,0), "X509_NAME_ENTRY_set_object"},
82{ERR_PACK(0,X509_F_X509_NAME_ONELINE,0), "X509_NAME_oneline"}, 92{ERR_PACK(0,X509_F_X509_NAME_ONELINE,0), "X509_NAME_oneline"},
83{ERR_PACK(0,X509_F_X509_NAME_PRINT,0), "X509_NAME_print"}, 93{ERR_PACK(0,X509_F_X509_NAME_PRINT,0), "X509_NAME_print"},
@@ -89,7 +99,9 @@ static ERR_STRING_DATA X509_str_functs[]=
89{ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"}, 99{ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"},
90{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_add_cert"}, 100{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_add_cert"},
91{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_add_crl"}, 101{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_add_crl"},
102{ERR_PACK(0,X509_F_X509_STORE_CTX_PURPOSE_INHERIT,0), "X509_STORE_CTX_purpose_inherit"},
92{ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"}, 103{ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"},
104{ERR_PACK(0,X509_F_X509_TRUST_ADD,0), "X509_TRUST_add"},
93{ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"}, 105{ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"},
94{0,NULL} 106{0,NULL}
95 }; 107 };
@@ -97,10 +109,12 @@ static ERR_STRING_DATA X509_str_functs[]=
97static ERR_STRING_DATA X509_str_reasons[]= 109static ERR_STRING_DATA X509_str_reasons[]=
98 { 110 {
99{X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"}, 111{X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"},
112{X509_R_BASE64_DECODE_ERROR ,"base64 decode error"},
100{X509_R_CANT_CHECK_DH_KEY ,"cant check dh key"}, 113{X509_R_CANT_CHECK_DH_KEY ,"cant check dh key"},
101{X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"}, 114{X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"},
102{X509_R_ERR_ASN1_LIB ,"err asn1 lib"}, 115{X509_R_ERR_ASN1_LIB ,"err asn1 lib"},
103{X509_R_INVALID_DIRECTORY ,"invalid directory"}, 116{X509_R_INVALID_DIRECTORY ,"invalid directory"},
117{X509_R_INVALID_FIELD_NAME ,"invalid field name"},
104{X509_R_KEY_TYPE_MISMATCH ,"key type mismatch"}, 118{X509_R_KEY_TYPE_MISMATCH ,"key type mismatch"},
105{X509_R_KEY_VALUES_MISMATCH ,"key values mismatch"}, 119{X509_R_KEY_VALUES_MISMATCH ,"key values mismatch"},
106{X509_R_LOADING_CERT_DIR ,"loading cert dir"}, 120{X509_R_LOADING_CERT_DIR ,"loading cert dir"},
@@ -111,8 +125,11 @@ static ERR_STRING_DATA X509_str_reasons[]=
111{X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"}, 125{X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"},
112{X509_R_UNKNOWN_KEY_TYPE ,"unknown key type"}, 126{X509_R_UNKNOWN_KEY_TYPE ,"unknown key type"},
113{X509_R_UNKNOWN_NID ,"unknown nid"}, 127{X509_R_UNKNOWN_NID ,"unknown nid"},
128{X509_R_UNKNOWN_PURPOSE_ID ,"unknown purpose id"},
129{X509_R_UNKNOWN_TRUST_ID ,"unknown trust id"},
114{X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"}, 130{X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"},
115{X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"}, 131{X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"},
132{X509_R_WRONG_TYPE ,"wrong type"},
116{0,NULL} 133{0,NULL}
117 }; 134 };
118 135
diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c
index f8565a60b2..2955989807 100644
--- a/src/lib/libcrypto/x509/x509_ext.c
+++ b/src/lib/libcrypto/x509/x509_ext.c
@@ -63,6 +63,8 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/evp.h> 64#include <openssl/evp.h>
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
66 68
67int X509_CRL_get_ext_count(X509_CRL *x) 69int X509_CRL_get_ext_count(X509_CRL *x)
68 { 70 {
@@ -94,6 +96,11 @@ X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc)
94 return(X509v3_delete_ext(x->crl->extensions,loc)); 96 return(X509v3_delete_ext(x->crl->extensions,loc));
95 } 97 }
96 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
97int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc) 104int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc)
98 { 105 {
99 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL); 106 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL);
@@ -134,6 +141,11 @@ int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
134 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL); 141 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL);
135 } 142 }
136 143
144void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx)
145{
146 return X509V3_get_d2i(x->cert_info->extensions, nid, crit, idx);
147}
148
137int X509_REVOKED_get_ext_count(X509_REVOKED *x) 149int X509_REVOKED_get_ext_count(X509_REVOKED *x)
138 { 150 {
139 return(X509v3_get_ext_count(x->extensions)); 151 return(X509v3_get_ext_count(x->extensions));
@@ -170,5 +182,10 @@ int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc)
170 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL); 182 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL);
171 } 183 }
172 184
185void *X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx)
186{
187 return X509V3_get_d2i(x->extensions, nid, crit, idx);
188}
189
173IMPLEMENT_STACK_OF(X509_EXTENSION) 190IMPLEMENT_STACK_OF(X509_EXTENSION)
174IMPLEMENT_ASN1_SET_OF(X509_EXTENSION) 191IMPLEMENT_ASN1_SET_OF(X509_EXTENSION)
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c
index 18bfecb11e..a20006d67e 100644
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ b/src/lib/libcrypto/x509/x509_lu.c
@@ -61,8 +61,8 @@
61#include <openssl/lhash.h> 61#include <openssl/lhash.h>
62#include <openssl/x509.h> 62#include <openssl/x509.h>
63 63
64static STACK *x509_store_meth=NULL; 64static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_store_meth=NULL;
65static STACK *x509_store_ctx_meth=NULL; 65static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_store_ctx_meth=NULL;
66 66
67X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method) 67X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method)
68 { 68 {
@@ -244,7 +244,7 @@ void X509_STORE_free(X509_STORE *vfy)
244 } 244 }
245 sk_X509_LOOKUP_free(sk); 245 sk_X509_LOOKUP_free(sk);
246 246
247 CRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data); 247 CRYPTO_free_ex_data(x509_store_meth,vfy,&vfy->ex_data);
248 lh_doall(vfy->certs,cleanup); 248 lh_doall(vfy->certs,cleanup);
249 lh_free(vfy->certs); 249 lh_free(vfy->certs);
250 Free(vfy); 250 Free(vfy);
@@ -377,10 +377,24 @@ X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h, int type,
377 abort(); 377 abort();
378 } 378 }
379 379
380 tmp=(X509_OBJECT *)lh_retrieve(h,(char *)&stmp); 380 tmp=(X509_OBJECT *)lh_retrieve(h,&stmp);
381 return(tmp); 381 return(tmp);
382 } 382 }
383 383
384X509_STORE_CTX *X509_STORE_CTX_new(void)
385{
386 X509_STORE_CTX *ctx;
387 ctx = (X509_STORE_CTX *)Malloc(sizeof(X509_STORE_CTX));
388 if(ctx) memset(ctx, 0, sizeof(X509_STORE_CTX));
389 return ctx;
390}
391
392void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
393{
394 X509_STORE_CTX_cleanup(ctx);
395 Free(ctx);
396}
397
384void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, 398void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
385 STACK_OF(X509) *chain) 399 STACK_OF(X509) *chain)
386 { 400 {
@@ -389,6 +403,8 @@ void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
389 ctx->cert=x509; 403 ctx->cert=x509;
390 ctx->untrusted=chain; 404 ctx->untrusted=chain;
391 ctx->last_untrusted=0; 405 ctx->last_untrusted=0;
406 ctx->purpose=0;
407 ctx->trust=0;
392 ctx->valid=0; 408 ctx->valid=0;
393 ctx->chain=NULL; 409 ctx->chain=NULL;
394 ctx->depth=9; 410 ctx->depth=9;
@@ -404,7 +420,7 @@ void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
404 sk_X509_pop_free(ctx->chain,X509_free); 420 sk_X509_pop_free(ctx->chain,X509_free);
405 ctx->chain=NULL; 421 ctx->chain=NULL;
406 } 422 }
407 CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data)); 423 CRYPTO_free_ex_data(x509_store_ctx_meth,ctx,&(ctx->ex_data));
408 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA)); 424 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA));
409 } 425 }
410 426
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c
index bb4697ae60..db051033d9 100644
--- a/src/lib/libcrypto/x509/x509_r2x.c
+++ b/src/lib/libcrypto/x509/x509_r2x.c
@@ -82,7 +82,7 @@ X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
82 82
83 if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0) 83 if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0)
84 { 84 {
85 if ((xi->version=ASN1_INTEGER_new()) == NULL) goto err; 85 if ((xi->version=M_ASN1_INTEGER_new()) == NULL) goto err;
86 if (!ASN1_INTEGER_set(xi->version,2)) goto err; 86 if (!ASN1_INTEGER_set(xi->version,2)) goto err;
87/* xi->extensions=ri->attributes; <- bad, should not ever be done 87/* xi->extensions=ri->attributes; <- bad, should not ever be done
88 ri->attributes=NULL; */ 88 ri->attributes=NULL; */
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index 2ef94decd1..baef8790eb 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -66,7 +66,7 @@
66#include <openssl/buffer.h> 66#include <openssl/buffer.h>
67#include <openssl/pem.h> 67#include <openssl/pem.h>
68 68
69X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md) 69X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
70 { 70 {
71 X509_REQ *ret; 71 X509_REQ *ret;
72 X509_REQ_INFO *ri; 72 X509_REQ_INFO *ri;
@@ -113,3 +113,166 @@ EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)
113 return(X509_PUBKEY_get(req->req_info->pubkey)); 113 return(X509_PUBKEY_get(req->req_info->pubkey));
114 } 114 }
115 115
116/* It seems several organisations had the same idea of including a list of
117 * extensions in a certificate request. There are at least two OIDs that are
118 * used and there may be more: so the list is configurable.
119 */
120
121static int ext_nid_list[] = { NID_ms_ext_req, NID_ext_req, NID_undef};
122
123static int *ext_nids = ext_nid_list;
124
125int X509_REQ_extension_nid(int req_nid)
126{
127 int i, nid;
128 for(i = 0; ; i++) {
129 nid = ext_nids[i];
130 if(nid == NID_undef) return 0;
131 else if (req_nid == nid) return 1;
132 }
133}
134
135int *X509_REQ_get_extension_nids(void)
136{
137 return ext_nids;
138}
139
140void X509_REQ_set_extension_nids(int *nids)
141{
142 ext_nids = nids;
143}
144
145STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
146{
147 X509_ATTRIBUTE *attr;
148 STACK_OF(X509_ATTRIBUTE) *sk;
149 ASN1_TYPE *ext = NULL;
150 int i;
151 unsigned char *p;
152 if ((req == NULL) || (req->req_info == NULL))
153 return(NULL);
154 sk=req->req_info->attributes;
155 if (!sk) return NULL;
156 for(i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {
157 attr = sk_X509_ATTRIBUTE_value(sk, i);
158 if(X509_REQ_extension_nid(OBJ_obj2nid(attr->object))) {
159 if(attr->set && sk_ASN1_TYPE_num(attr->value.set))
160 ext = sk_ASN1_TYPE_value(attr->value.set, 0);
161 else ext = attr->value.single;
162 break;
163 }
164 }
165 if(!ext || (ext->type != V_ASN1_SEQUENCE)) return NULL;
166 p = ext->value.sequence->data;
167 return d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p,
168 ext->value.sequence->length,
169 d2i_X509_EXTENSION, X509_EXTENSION_free,
170 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
171}
172
173/* Add a STACK_OF extensions to a certificate request: allow alternative OIDs
174 * in case we want to create a non standard one.
175 */
176
177int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
178 int nid)
179{
180 unsigned char *p = NULL, *q;
181 long len;
182 ASN1_TYPE *at = NULL;
183 X509_ATTRIBUTE *attr = NULL;
184 if(!(at = ASN1_TYPE_new()) ||
185 !(at->value.sequence = ASN1_STRING_new())) goto err;
186
187 at->type = V_ASN1_SEQUENCE;
188 /* Generate encoding of extensions */
189 len = i2d_ASN1_SET_OF_X509_EXTENSION(exts, NULL, i2d_X509_EXTENSION,
190 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
191 if(!(p = Malloc(len))) goto err;
192 q = p;
193 i2d_ASN1_SET_OF_X509_EXTENSION(exts, &q, i2d_X509_EXTENSION,
194 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
195 at->value.sequence->data = p;
196 p = NULL;
197 at->value.sequence->length = len;
198 if(!(attr = X509_ATTRIBUTE_new())) goto err;
199 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
200 if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err;
201 at = NULL;
202 attr->set = 1;
203 attr->object = OBJ_nid2obj(nid);
204 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err;
205 return 1;
206 err:
207 if(p) Free(p);
208 X509_ATTRIBUTE_free(attr);
209 ASN1_TYPE_free(at);
210 return 0;
211}
212/* This is the normal usage: use the "official" OID */
213int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts)
214{
215 return X509_REQ_add_extensions_nid(req, exts, NID_ext_req);
216}
217
218/* Request attribute functions */
219
220int X509_REQ_get_attr_count(const X509_REQ *req)
221{
222 return X509at_get_attr_count(req->req_info->attributes);
223}
224
225int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
226 int lastpos)
227{
228 return X509at_get_attr_by_NID(req->req_info->attributes, nid, lastpos);
229}
230
231int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
232 int lastpos)
233{
234 return X509at_get_attr_by_OBJ(req->req_info->attributes, obj, lastpos);
235}
236
237X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc)
238{
239 return X509at_get_attr(req->req_info->attributes, loc);
240}
241
242X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc)
243{
244 return X509at_delete_attr(req->req_info->attributes, loc);
245}
246
247int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr)
248{
249 if(X509at_add1_attr(&req->req_info->attributes, attr)) return 1;
250 return 0;
251}
252
253int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
254 ASN1_OBJECT *obj, int type,
255 unsigned char *bytes, int len)
256{
257 if(X509at_add1_attr_by_OBJ(&req->req_info->attributes, obj,
258 type, bytes, len)) return 1;
259 return 0;
260}
261
262int X509_REQ_add1_attr_by_NID(X509_REQ *req,
263 int nid, int type,
264 unsigned char *bytes, int len)
265{
266 if(X509at_add1_attr_by_NID(&req->req_info->attributes, nid,
267 type, bytes, len)) return 1;
268 return 0;
269}
270
271int X509_REQ_add1_attr_by_txt(X509_REQ *req,
272 char *attrname, int type,
273 unsigned char *bytes, int len)
274{
275 if(X509at_add1_attr_by_txt(&req->req_info->attributes, attrname,
276 type, bytes, len)) return 1;
277 return 0;
278}
diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c
index 5a6f7b414f..add842d17a 100644
--- a/src/lib/libcrypto/x509/x509_set.c
+++ b/src/lib/libcrypto/x509/x509_set.c
@@ -68,7 +68,7 @@ int X509_set_version(X509 *x, long version)
68 if (x == NULL) return(0); 68 if (x == NULL) return(0);
69 if (x->cert_info->version == NULL) 69 if (x->cert_info->version == NULL)
70 { 70 {
71 if ((x->cert_info->version=ASN1_INTEGER_new()) == NULL) 71 if ((x->cert_info->version=M_ASN1_INTEGER_new()) == NULL)
72 return(0); 72 return(0);
73 } 73 }
74 return(ASN1_INTEGER_set(x->cert_info->version,version)); 74 return(ASN1_INTEGER_set(x->cert_info->version,version));
@@ -82,10 +82,10 @@ int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial)
82 in=x->cert_info->serialNumber; 82 in=x->cert_info->serialNumber;
83 if (in != serial) 83 if (in != serial)
84 { 84 {
85 in=ASN1_INTEGER_dup(serial); 85 in=M_ASN1_INTEGER_dup(serial);
86 if (in != NULL) 86 if (in != NULL)
87 { 87 {
88 ASN1_INTEGER_free(x->cert_info->serialNumber); 88 M_ASN1_INTEGER_free(x->cert_info->serialNumber);
89 x->cert_info->serialNumber=in; 89 x->cert_info->serialNumber=in;
90 } 90 }
91 } 91 }
@@ -112,10 +112,10 @@ int X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm)
112 in=x->cert_info->validity->notBefore; 112 in=x->cert_info->validity->notBefore;
113 if (in != tm) 113 if (in != tm)
114 { 114 {
115 in=ASN1_UTCTIME_dup(tm); 115 in=M_ASN1_UTCTIME_dup(tm);
116 if (in != NULL) 116 if (in != NULL)
117 { 117 {
118 ASN1_UTCTIME_free(x->cert_info->validity->notBefore); 118 M_ASN1_UTCTIME_free(x->cert_info->validity->notBefore);
119 x->cert_info->validity->notBefore=in; 119 x->cert_info->validity->notBefore=in;
120 } 120 }
121 } 121 }
@@ -130,10 +130,10 @@ int X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm)
130 in=x->cert_info->validity->notAfter; 130 in=x->cert_info->validity->notAfter;
131 if (in != tm) 131 if (in != tm)
132 { 132 {
133 in=ASN1_UTCTIME_dup(tm); 133 in=M_ASN1_UTCTIME_dup(tm);
134 if (in != NULL) 134 if (in != NULL)
135 { 135 {
136 ASN1_UTCTIME_free(x->cert_info->validity->notAfter); 136 M_ASN1_UTCTIME_free(x->cert_info->validity->notAfter);
137 x->cert_info->validity->notAfter=in; 137 x->cert_info->validity->notAfter=in;
138 } 138 }
139 } 139 }
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
new file mode 100644
index 0000000000..9f7d67952d
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509_trs.c
@@ -0,0 +1,263 @@
1/* x509_trs.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63
64static int tr_cmp(X509_TRUST **a, X509_TRUST **b);
65static void trtable_free(X509_TRUST *p);
66
67static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags);
68static int trust_any(X509_TRUST *trust, X509 *x, int flags);
69
70static int obj_trust(int id, X509 *x, int flags);
71static int (*default_trust)(int id, X509 *x, int flags) = obj_trust;
72
73/* WARNING: the following table should be kept in order of trust
74 * and without any gaps so we can just subtract the minimum trust
75 * value to get an index into the table
76 */
77
78static X509_TRUST trstandard[] = {
79{X509_TRUST_ANY, 0, trust_any, "Any", 0, NULL},
80{X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL},
81{X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Client", NID_server_auth, NULL},
82{X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL},
83};
84
85#define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST))
86
87IMPLEMENT_STACK_OF(X509_TRUST)
88
89static STACK_OF(X509_TRUST) *trtable = NULL;
90
91static int tr_cmp(X509_TRUST **a, X509_TRUST **b)
92{
93 return (*a)->trust - (*b)->trust;
94}
95
96int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int)
97{
98int (*oldtrust)(int , X509 *, int);
99oldtrust = default_trust;
100default_trust = trust;
101return oldtrust;
102}
103
104
105int X509_check_trust(X509 *x, int id, int flags)
106{
107 X509_TRUST *pt;
108 int idx;
109 if(id == -1) return 1;
110 if(!(idx = X509_TRUST_get_by_id(id)))
111 return default_trust(id, x, flags);
112 pt = X509_TRUST_get0(idx);
113 return pt->check_trust(pt, x, flags);
114}
115
116int X509_TRUST_get_count(void)
117{
118 if(!trtable) return X509_TRUST_COUNT;
119 return sk_X509_TRUST_num(trtable) + X509_TRUST_COUNT;
120}
121
122X509_TRUST * X509_TRUST_get0(int idx)
123{
124 if(idx < 0) return NULL;
125 if(idx < X509_TRUST_COUNT) return trstandard + idx;
126 return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
127}
128
129int X509_TRUST_get_by_id(int id)
130{
131 X509_TRUST tmp;
132 int idx;
133 if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
134 return id - X509_TRUST_MIN;
135 tmp.trust = id;
136 if(!trtable) return -1;
137 idx = sk_X509_TRUST_find(trtable, &tmp);
138 if(idx == -1) return -1;
139 return idx + X509_TRUST_COUNT;
140}
141
142int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
143 char *name, int arg1, void *arg2)
144{
145 int idx;
146 X509_TRUST *trtmp;
147 /* This is set according to what we change: application can't set it */
148 flags &= ~X509_TRUST_DYNAMIC;
149 /* This will always be set for application modified trust entries */
150 flags |= X509_TRUST_DYNAMIC_NAME;
151 /* Get existing entry if any */
152 idx = X509_TRUST_get_by_id(id);
153 /* Need a new entry */
154 if(idx == -1) {
155 if(!(trtmp = Malloc(sizeof(X509_TRUST)))) {
156 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
157 return 0;
158 }
159 trtmp->flags = X509_TRUST_DYNAMIC;
160 } else trtmp = X509_TRUST_get0(idx);
161
162 /* Free existing name if dynamic */
163 if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) Free(trtmp->name);
164 /* dup supplied name */
165 if(!(trtmp->name = BUF_strdup(name))) {
166 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
167 return 0;
168 }
169 /* Keep the dynamic flag of existing entry */
170 trtmp->flags &= X509_TRUST_DYNAMIC;
171 /* Set all other flags */
172 trtmp->flags |= flags;
173
174 trtmp->trust = id;
175 trtmp->check_trust = ck;
176 trtmp->arg1 = arg1;
177 trtmp->arg2 = arg2;
178
179 /* If its a new entry manage the dynamic table */
180 if(idx == -1) {
181 if(!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) {
182 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
183 return 0;
184 }
185 if (!sk_X509_TRUST_push(trtable, trtmp)) {
186 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
187 return 0;
188 }
189 }
190 return 1;
191}
192
193static void trtable_free(X509_TRUST *p)
194 {
195 if(!p) return;
196 if (p->flags & X509_TRUST_DYNAMIC)
197 {
198 if (p->flags & X509_TRUST_DYNAMIC_NAME)
199 Free(p->name);
200 Free(p);
201 }
202 }
203
204void X509_TRUST_cleanup(void)
205{
206 int i;
207 for(i = 0; i < X509_TRUST_COUNT; i++) trtable_free(trstandard + i);
208 sk_X509_TRUST_pop_free(trtable, trtable_free);
209 trtable = NULL;
210}
211
212int X509_TRUST_get_flags(X509_TRUST *xp)
213{
214 return xp->flags;
215}
216
217char *X509_TRUST_get0_name(X509_TRUST *xp)
218{
219 return xp->name;
220}
221
222int X509_TRUST_get_trust(X509_TRUST *xp)
223{
224 return xp->trust;
225}
226
227static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags)
228{
229 if(x->aux) return obj_trust(trust->arg1, x, flags);
230 /* we don't have any trust settings: for compatibility
231 * we return trusted if it is self signed
232 */
233 X509_check_purpose(x, -1, 0);
234 if(x->ex_flags & EXFLAG_SS) return X509_TRUST_TRUSTED;
235 else return X509_TRUST_UNTRUSTED;
236}
237
238static int obj_trust(int id, X509 *x, int flags)
239{
240 ASN1_OBJECT *obj;
241 int i;
242 X509_CERT_AUX *ax;
243 ax = x->aux;
244 if(!ax) return X509_TRUST_UNTRUSTED;
245 if(ax->reject) {
246 for(i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) {
247 obj = sk_ASN1_OBJECT_value(ax->reject, i);
248 if(OBJ_obj2nid(obj) == id) return X509_TRUST_REJECTED;
249 }
250 }
251 if(ax->trust) {
252 for(i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) {
253 obj = sk_ASN1_OBJECT_value(ax->trust, i);
254 if(OBJ_obj2nid(obj) == id) return X509_TRUST_TRUSTED;
255 }
256 }
257 return X509_TRUST_UNTRUSTED;
258}
259
260static int trust_any(X509_TRUST *trust, X509 *x, int flags)
261{
262 return X509_TRUST_TRUSTED;
263}
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c
index 11a3d2012f..209cf53191 100644
--- a/src/lib/libcrypto/x509/x509_txt.c
+++ b/src/lib/libcrypto/x509/x509_txt.c
@@ -59,7 +59,6 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include <errno.h> 61#include <errno.h>
62#include <sys/types.h>
63 62
64#include "cryptlib.h" 63#include "cryptlib.h"
65#include <openssl/lhash.h> 64#include <openssl/lhash.h>
@@ -121,6 +120,16 @@ const char *X509_verify_cert_error_string(long n)
121 return("certificate chain too long"); 120 return("certificate chain too long");
122 case X509_V_ERR_CERT_REVOKED: 121 case X509_V_ERR_CERT_REVOKED:
123 return("certificate revoked"); 122 return("certificate revoked");
123 case X509_V_ERR_INVALID_CA:
124 return ("invalid CA certificate");
125 case X509_V_ERR_PATH_LENGTH_EXCEEDED:
126 return ("path length constraint exceeded");
127 case X509_V_ERR_INVALID_PURPOSE:
128 return ("unsupported certificate purpose");
129 case X509_V_ERR_CERT_UNTRUSTED:
130 return ("certificate not trusted");
131 case X509_V_ERR_CERT_REJECTED:
132 return ("certificate rejected");
124 case X509_V_ERR_APPLICATION_VERIFICATION: 133 case X509_V_ERR_APPLICATION_VERIFICATION:
125 return("application verification failure"); 134 return("application verification failure");
126 default: 135 default:
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
index dd2f9f1b17..52887986fe 100644
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ b/src/lib/libcrypto/x509/x509_v3.c
@@ -63,6 +63,7 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/evp.h> 64#include <openssl/evp.h>
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
66 67
67int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x) 68int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x)
68 { 69 {
@@ -242,7 +243,7 @@ int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)
242 int i; 243 int i;
243 244
244 if (ex == NULL) return(0); 245 if (ex == NULL) return(0);
245 i=ASN1_OCTET_STRING_set(ex->value,data->data,data->length); 246 i=M_ASN1_OCTET_STRING_set(ex->value,data->data,data->length);
246 if (!i) return(0); 247 if (!i) return(0);
247 return(1); 248 return(1);
248 } 249 }
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
index c72ee4a385..4fdff54124 100644
--- a/src/lib/libcrypto/x509/x509_vfy.c
+++ b/src/lib/libcrypto/x509/x509_vfy.c
@@ -59,23 +59,24 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include <errno.h> 61#include <errno.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64 62
65#include <openssl/crypto.h>
66#include "cryptlib.h" 63#include "cryptlib.h"
64#include <openssl/crypto.h>
67#include <openssl/lhash.h> 65#include <openssl/lhash.h>
68#include <openssl/buffer.h> 66#include <openssl/buffer.h>
69#include <openssl/evp.h> 67#include <openssl/evp.h>
70#include <openssl/asn1.h> 68#include <openssl/asn1.h>
71#include <openssl/x509.h> 69#include <openssl/x509.h>
70#include <openssl/x509v3.h>
72#include <openssl/objects.h> 71#include <openssl/objects.h>
73 72
74static int null_callback(int ok,X509_STORE_CTX *e); 73static int null_callback(int ok,X509_STORE_CTX *e);
74static int check_chain_purpose(X509_STORE_CTX *ctx);
75static int check_trust(X509_STORE_CTX *ctx);
75static int internal_verify(X509_STORE_CTX *ctx); 76static int internal_verify(X509_STORE_CTX *ctx);
76const char *X509_version="X.509" OPENSSL_VERSION_PTEXT; 77const char *X509_version="X.509" OPENSSL_VERSION_PTEXT;
77 78
78static STACK *x509_store_ctx_method=NULL; 79static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_store_ctx_method=NULL;
79static int x509_store_ctx_num=0; 80static int x509_store_ctx_num=0;
80#if 0 81#if 0
81static int x509_store_num=1; 82static int x509_store_num=1;
@@ -127,7 +128,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
127 ctx->last_untrusted=1; 128 ctx->last_untrusted=1;
128 } 129 }
129 130
130 /* We use a temporary so we can chop and hack at it */ 131 /* We use a temporary STACK so we can chop and hack at it */
131 if (ctx->untrusted != NULL 132 if (ctx->untrusted != NULL
132 && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL) 133 && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
133 { 134 {
@@ -184,17 +185,37 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
184 185
185 i=sk_X509_num(ctx->chain); 186 i=sk_X509_num(ctx->chain);
186 x=sk_X509_value(ctx->chain,i-1); 187 x=sk_X509_value(ctx->chain,i-1);
187 if (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x)) 188 xn = X509_get_subject_name(x);
189 if (X509_NAME_cmp(xn,X509_get_issuer_name(x))
188 == 0) 190 == 0)
189 { 191 {
190 /* we have a self signed certificate */ 192 /* we have a self signed certificate */
191 if (sk_X509_num(ctx->chain) == 1) 193 if (sk_X509_num(ctx->chain) == 1)
192 { 194 {
193 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT; 195 /* We have a single self signed certificate: see if
194 ctx->current_cert=x; 196 * we can find it in the store. We must have an exact
195 ctx->error_depth=i-1; 197 * match to avoid possible impersonation.
196 ok=cb(0,ctx); 198 */
197 if (!ok) goto end; 199 ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);
200 if ((ok != X509_LU_X509) || X509_cmp(x, obj.data.x509))
201 {
202 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
203 ctx->current_cert=x;
204 ctx->error_depth=i-1;
205 if(ok == X509_LU_X509) X509_OBJECT_free_contents(&obj);
206 ok=cb(0,ctx);
207 if (!ok) goto end;
208 }
209 else
210 {
211 /* We have a match: replace certificate with store version
212 * so we get any trust settings.
213 */
214 X509_free(x);
215 x = obj.data.x509;
216 sk_X509_set(ctx->chain, i - 1, x);
217 ctx->last_untrusted=0;
218 }
198 } 219 }
199 else 220 else
200 { 221 {
@@ -272,6 +293,17 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
272 if (!ok) goto end; 293 if (!ok) goto end;
273 } 294 }
274 295
296 /* We have the chain complete: now we need to check its purpose */
297 if(ctx->purpose > 0) ok = check_chain_purpose(ctx);
298
299 if(!ok) goto end;
300
301 /* The chain extensions are OK: check trust */
302
303 if(ctx->trust > 0) ok = check_trust(ctx);
304
305 if(!ok) goto end;
306
275 /* We may as well copy down any DSA parameters that are required */ 307 /* We may as well copy down any DSA parameters that are required */
276 X509_get_pubkey_parameters(NULL,ctx->chain); 308 X509_get_pubkey_parameters(NULL,ctx->chain);
277 309
@@ -290,6 +322,71 @@ end:
290 return(ok); 322 return(ok);
291 } 323 }
292 324
325/* Check a certificate chains extensions for consistency
326 * with the supplied purpose
327 */
328
329static int check_chain_purpose(X509_STORE_CTX *ctx)
330{
331#ifdef NO_CHAIN_VERIFY
332 return 1;
333#else
334 int i, ok=0;
335 X509 *x;
336 int (*cb)();
337 cb=ctx->ctx->verify_cb;
338 if (cb == NULL) cb=null_callback;
339 /* Check all untrusted certificates */
340 for(i = 0; i < ctx->last_untrusted; i++) {
341 x = sk_X509_value(ctx->chain, i);
342 if(!X509_check_purpose(x, ctx->purpose, i)) {
343 if(i) ctx->error = X509_V_ERR_INVALID_CA;
344 else ctx->error = X509_V_ERR_INVALID_PURPOSE;
345 ctx->error_depth = i;
346 ctx->current_cert = x;
347 ok=cb(0,ctx);
348 if(!ok) goto end;
349 }
350 /* Check pathlen */
351 if((i > 1) && (x->ex_pathlen != -1)
352 && (i > (x->ex_pathlen + 1))) {
353 ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
354 ctx->error_depth = i;
355 ctx->current_cert = x;
356 ok=cb(0,ctx);
357 if(!ok) goto end;
358 }
359 }
360 ok = 1;
361 end:
362 return(ok);
363#endif
364}
365
366static int check_trust(X509_STORE_CTX *ctx)
367{
368#ifdef NO_CHAIN_VERIFY
369 return 1;
370#else
371 int i, ok;
372 X509 *x;
373 int (*cb)();
374 cb=ctx->ctx->verify_cb;
375 if (cb == NULL) cb=null_callback;
376/* For now just check the last certificate in the chain */
377 i = sk_X509_num(ctx->chain) - 1;
378 x = sk_X509_value(ctx->chain, i);
379 ok = X509_check_trust(x, ctx->trust, 0);
380 if(ok == X509_TRUST_TRUSTED) return 1;
381 ctx->error_depth = sk_X509_num(ctx->chain) - 1;
382 ctx->current_cert = x;
383 if(ok == X509_TRUST_REJECTED) ctx->error = X509_V_ERR_CERT_REJECTED;
384 else ctx->error = X509_V_ERR_CERT_UNTRUSTED;
385 ok = cb(0, ctx);
386 return(ok);
387#endif
388}
389
293static int internal_verify(X509_STORE_CTX *ctx) 390static int internal_verify(X509_STORE_CTX *ctx)
294 { 391 {
295 int i,ok=0,n; 392 int i,ok=0,n;
@@ -439,7 +536,7 @@ int X509_cmp_current_time(ASN1_UTCTIME *ctm)
439 atm.length=sizeof(buff2); 536 atm.length=sizeof(buff2);
440 atm.data=(unsigned char *)buff2; 537 atm.data=(unsigned char *)buff2;
441 538
442 X509_gmtime_adj(&atm,-offset); 539 X509_gmtime_adj(&atm,-offset*60);
443 540
444 i=(buff1[0]-'0')*10+(buff1[1]-'0'); 541 i=(buff1[0]-'0')*10+(buff1[1]-'0');
445 if (i < 50) i+=100; /* cf. RFC 2459 */ 542 if (i < 50) i+=100; /* cf. RFC 2459 */
@@ -525,13 +622,13 @@ int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
525 622
526 X509_OBJECT_up_ref_count(obj); 623 X509_OBJECT_up_ref_count(obj);
527 624
528 r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj); 625 r=(X509_OBJECT *)lh_insert(ctx->certs,obj);
529 if (r != NULL) 626 if (r != NULL)
530 { /* oops, put it back */ 627 { /* oops, put it back */
531 lh_delete(ctx->certs,(char *)obj); 628 lh_delete(ctx->certs,obj);
532 X509_OBJECT_free_contents(obj); 629 X509_OBJECT_free_contents(obj);
533 Free(obj); 630 Free(obj);
534 lh_insert(ctx->certs,(char *)r); 631 lh_insert(ctx->certs,r);
535 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE); 632 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);
536 ret=0; 633 ret=0;
537 } 634 }
@@ -560,13 +657,13 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
560 657
561 X509_OBJECT_up_ref_count(obj); 658 X509_OBJECT_up_ref_count(obj);
562 659
563 r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj); 660 r=(X509_OBJECT *)lh_insert(ctx->certs,obj);
564 if (r != NULL) 661 if (r != NULL)
565 { /* oops, put it back */ 662 { /* oops, put it back */
566 lh_delete(ctx->certs,(char *)obj); 663 lh_delete(ctx->certs,obj);
567 X509_OBJECT_free_contents(obj); 664 X509_OBJECT_free_contents(obj);
568 Free(obj); 665 Free(obj);
569 lh_insert(ctx->certs,(char *)r); 666 lh_insert(ctx->certs,r);
570 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE); 667 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE);
571 ret=0; 668 ret=0;
572 } 669 }
@@ -576,8 +673,8 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
576 return(ret); 673 return(ret);
577 } 674 }
578 675
579int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(), 676int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
580 int (*dup_func)(), void (*free_func)()) 677 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
581 { 678 {
582 x509_store_ctx_num++; 679 x509_store_ctx_num++;
583 return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1, 680 return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1,
@@ -620,6 +717,19 @@ STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx)
620 return(ctx->chain); 717 return(ctx->chain);
621 } 718 }
622 719
720STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
721 {
722 int i;
723 X509 *x;
724 STACK_OF(X509) *chain;
725 if(!ctx->chain || !(chain = sk_X509_dup(ctx->chain))) return NULL;
726 for(i = 0; i < sk_X509_num(chain); i++) {
727 x = sk_X509_value(chain, i);
728 CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
729 }
730 return(chain);
731 }
732
623void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x) 733void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)
624 { 734 {
625 ctx->cert=x; 735 ctx->cert=x;
@@ -630,6 +740,62 @@ void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
630 ctx->untrusted=sk; 740 ctx->untrusted=sk;
631 } 741 }
632 742
743int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose)
744 {
745 return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0);
746 }
747
748int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust)
749 {
750 return X509_STORE_CTX_purpose_inherit(ctx, 0, 0, trust);
751 }
752
753/* This function is used to set the X509_STORE_CTX purpose and trust
754 * values. This is intended to be used when another structure has its
755 * own trust and purpose values which (if set) will be inherited by
756 * the ctx. If they aren't set then we will usually have a default
757 * purpose in mind which should then be used to set the trust value.
758 * An example of this is SSL use: an SSL structure will have its own
759 * purpose and trust settings which the application can set: if they
760 * aren't set then we use the default of SSL client/server.
761 */
762
763int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
764 int purpose, int trust)
765{
766 int idx;
767 /* If purpose not set use default */
768 if(!purpose) purpose = def_purpose;
769 /* If we have a purpose then check it is valid */
770 if(purpose) {
771 idx = X509_PURPOSE_get_by_id(purpose);
772 if(idx == -1) {
773 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
774 X509_R_UNKNOWN_PURPOSE_ID);
775 return 0;
776 }
777 /* If trust not set then get from purpose default */
778 if(!trust) {
779 X509_PURPOSE *ptmp;
780 ptmp = X509_PURPOSE_get0(idx);
781 trust = ptmp->trust;
782 }
783 }
784 if(trust) {
785 idx = X509_TRUST_get_by_id(trust);
786 if(idx == -1) {
787 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
788 X509_R_UNKNOWN_TRUST_ID);
789 return 0;
790 }
791 }
792
793 if(purpose) ctx->purpose = purpose;
794 if(trust) ctx->trust = trust;
795 return 1;
796}
797
798
633IMPLEMENT_STACK_OF(X509) 799IMPLEMENT_STACK_OF(X509)
634IMPLEMENT_ASN1_SET_OF(X509) 800IMPLEMENT_ASN1_SET_OF(X509)
635 801
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h
index ecfd4cf9ed..4637aecedf 100644
--- a/src/lib/libcrypto/x509/x509_vfy.h
+++ b/src/lib/libcrypto/x509/x509_vfy.h
@@ -202,6 +202,8 @@ struct x509_store_state_st /* X509_STORE_CTX */
202 /* The following are set by the caller */ 202 /* The following are set by the caller */
203 X509 *cert; /* The cert to check */ 203 X509 *cert; /* The cert to check */
204 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */ 204 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */
205 int purpose; /* purpose to check untrusted certificates */
206 int trust; /* trust setting to check */
205 207
206 /* The following is built up */ 208 /* The following is built up */
207 int depth; /* how far to go looking up certs */ 209 int depth; /* how far to go looking up certs */
@@ -234,6 +236,7 @@ struct x509_store_state_st /* X509_STORE_CTX */
234 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) 236 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)
235 237
236#define X509_V_OK 0 238#define X509_V_OK 0
239/* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */
237 240
238#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 241#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
239#define X509_V_ERR_UNABLE_TO_GET_CRL 3 242#define X509_V_ERR_UNABLE_TO_GET_CRL 3
@@ -257,6 +260,11 @@ struct x509_store_state_st /* X509_STORE_CTX */
257#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 260#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21
258#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 261#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22
259#define X509_V_ERR_CERT_REVOKED 23 262#define X509_V_ERR_CERT_REVOKED 23
263#define X509_V_ERR_INVALID_CA 24
264#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25
265#define X509_V_ERR_INVALID_PURPOSE 26
266#define X509_V_ERR_CERT_UNTRUSTED 27
267#define X509_V_ERR_CERT_REJECTED 28
260 268
261/* The application is not happy */ 269/* The application is not happy */
262#define X509_V_ERR_APPLICATION_VERIFICATION 50 270#define X509_V_ERR_APPLICATION_VERIFICATION 50
@@ -284,6 +292,8 @@ void X509_OBJECT_free_contents(X509_OBJECT *a);
284X509_STORE *X509_STORE_new(void ); 292X509_STORE *X509_STORE_new(void );
285void X509_STORE_free(X509_STORE *v); 293void X509_STORE_free(X509_STORE *v);
286 294
295X509_STORE_CTX *X509_STORE_CTX_new(void);
296void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
287void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, 297void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
288 X509 *x509, STACK_OF(X509) *chain); 298 X509 *x509, STACK_OF(X509) *chain);
289void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); 299void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
@@ -305,6 +315,7 @@ int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
305#ifndef NO_STDIO 315#ifndef NO_STDIO
306int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type); 316int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
307int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type); 317int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
318int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type);
308#endif 319#endif
309 320
310 321
@@ -327,8 +338,8 @@ int X509_STORE_load_locations (X509_STORE *ctx,
327int X509_STORE_set_default_paths(X509_STORE *ctx); 338int X509_STORE_set_default_paths(X509_STORE *ctx);
328#endif 339#endif
329 340
330int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(), 341int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
331 int (*dup_func)(), void (*free_func)()); 342 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
332int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data); 343int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data);
333void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx); 344void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
334int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); 345int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
@@ -336,8 +347,13 @@ void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
336int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); 347int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
337X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); 348X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
338STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); 349STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
350STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
339void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x); 351void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
340void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk); 352void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);
353int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
354int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
355int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
356 int purpose, int trust);
341 357
342#ifdef __cplusplus 358#ifdef __cplusplus
343} 359}
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c
index 2a422be350..cf2382d42c 100644
--- a/src/lib/libcrypto/x509/x509name.c
+++ b/src/lib/libcrypto/x509/x509name.c
@@ -171,6 +171,42 @@ X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc)
171 return(ret); 171 return(ret);
172 } 172 }
173 173
174int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
175 unsigned char *bytes, int len, int loc, int set)
176{
177 X509_NAME_ENTRY *ne;
178 int ret;
179 ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len);
180 if(!ne) return 0;
181 ret = X509_NAME_add_entry(name, ne, loc, set);
182 X509_NAME_ENTRY_free(ne);
183 return ret;
184}
185
186int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
187 unsigned char *bytes, int len, int loc, int set)
188{
189 X509_NAME_ENTRY *ne;
190 int ret;
191 ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len);
192 if(!ne) return 0;
193 ret = X509_NAME_add_entry(name, ne, loc, set);
194 X509_NAME_ENTRY_free(ne);
195 return ret;
196}
197
198int X509_NAME_add_entry_by_txt(X509_NAME *name, char *field, int type,
199 unsigned char *bytes, int len, int loc, int set)
200{
201 X509_NAME_ENTRY *ne;
202 int ret;
203 ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len);
204 if(!ne) return 0;
205 ret = X509_NAME_add_entry(name, ne, loc, set);
206 X509_NAME_ENTRY_free(ne);
207 return ret;
208}
209
174/* if set is -1, append to previous set, 0 'a new one', and 1, 210/* if set is -1, append to previous set, 0 'a new one', and 1,
175 * prepend to the guy we are about to stomp on. */ 211 * prepend to the guy we are about to stomp on. */
176int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, 212int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
@@ -236,10 +272,30 @@ err:
236 return(0); 272 return(0);
237 } 273 }
238 274
275X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
276 char *field, int type, unsigned char *bytes, int len)
277 {
278 ASN1_OBJECT *obj;
279 X509_NAME_ENTRY *nentry;
280
281 obj=OBJ_txt2obj(field, 0);
282 if (obj == NULL)
283 {
284 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT,
285 X509_R_INVALID_FIELD_NAME);
286 ERR_add_error_data(2, "name=", field);
287 return(NULL);
288 }
289 nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len);
290 ASN1_OBJECT_free(obj);
291 return nentry;
292 }
293
239X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, 294X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
240 int type, unsigned char *bytes, int len) 295 int type, unsigned char *bytes, int len)
241 { 296 {
242 ASN1_OBJECT *obj; 297 ASN1_OBJECT *obj;
298 X509_NAME_ENTRY *nentry;
243 299
244 obj=OBJ_nid2obj(nid); 300 obj=OBJ_nid2obj(nid);
245 if (obj == NULL) 301 if (obj == NULL)
@@ -247,7 +303,9 @@ X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
247 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID); 303 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID);
248 return(NULL); 304 return(NULL);
249 } 305 }
250 return(X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len)); 306 nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len);
307 ASN1_OBJECT_free(obj);
308 return nentry;
251 } 309 }
252 310
253X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, 311X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
@@ -267,7 +325,7 @@ X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
267 goto err; 325 goto err;
268 if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len)) 326 if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len))
269 goto err; 327 goto err;
270 328
271 if ((ne != NULL) && (*ne == NULL)) *ne=ret; 329 if ((ne != NULL) && (*ne == NULL)) *ne=ret;
272 return(ret); 330 return(ret);
273err: 331err:
@@ -294,6 +352,10 @@ int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
294 int i; 352 int i;
295 353
296 if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0); 354 if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0);
355 if(type & MBSTRING_FLAG)
356 return ASN1_STRING_set_by_NID(&ne->value, bytes,
357 len, type,
358 OBJ_obj2nid(ne->object)) ? 1 : 0;
297 if (len < 0) len=strlen((char *)bytes); 359 if (len < 0) len=strlen((char *)bytes);
298 i=ASN1_STRING_set(ne->value,bytes,len); 360 i=ASN1_STRING_set(ne->value,bytes,len);
299 if (!i) return(0); 361 if (!i) return(0);
diff --git a/src/lib/libcrypto/x509/x509spki.c b/src/lib/libcrypto/x509/x509spki.c
new file mode 100644
index 0000000000..b35c3f92e7
--- /dev/null
+++ b/src/lib/libcrypto/x509/x509spki.c
@@ -0,0 +1,121 @@
1/* x509spki.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/asn1_mac.h>
63
64int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey)
65{
66 if ((x == NULL) || (x->spkac == NULL)) return(0);
67 return(X509_PUBKEY_set(&(x->spkac->pubkey),pkey));
68}
69
70EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x)
71{
72 if ((x == NULL) || (x->spkac == NULL))
73 return(NULL);
74 return(X509_PUBKEY_get(x->spkac->pubkey));
75}
76
77/* Load a Netscape SPKI from a base64 encoded string */
78
79NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len)
80{
81 unsigned char *spki_der, *p;
82 int spki_len;
83 NETSCAPE_SPKI *spki;
84 if(len <= 0) len = strlen(str);
85 if (!(spki_der = Malloc(len + 1))) {
86 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89 spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len);
90 if(spki_len < 0) {
91 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE,
92 X509_R_BASE64_DECODE_ERROR);
93 Free(spki_der);
94 return NULL;
95 }
96 p = spki_der;
97 spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len);
98 Free(spki_der);
99 return spki;
100}
101
102/* Generate a base64 encoded string from an SPKI */
103
104char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
105{
106 unsigned char *der_spki, *p;
107 char *b64_str;
108 int der_len;
109 der_len = i2d_NETSCAPE_SPKI(spki, NULL);
110 der_spki = Malloc(der_len);
111 b64_str = Malloc(der_len * 2);
112 if(!der_spki || !b64_str) {
113 X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE);
114 return NULL;
115 }
116 p = der_spki;
117 i2d_NETSCAPE_SPKI(spki, &p);
118 EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len);
119 Free(der_spki);
120 return b64_str;
121}
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c
index f2af895df0..d2bf3c8e1c 100644
--- a/src/lib/libcrypto/x509/x_all.c
+++ b/src/lib/libcrypto/x509/x_all.c
@@ -285,10 +285,22 @@ RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa)
285 (unsigned char **)(rsa))); 285 (unsigned char **)(rsa)));
286 } 286 }
287 287
288RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa)
289 {
290 return((RSA *)ASN1_d2i_fp((char *(*)())
291 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (fp),
292 (unsigned char **)(rsa)));
293 }
294
288int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) 295int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
289 { 296 {
290 return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa)); 297 return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa));
291 } 298 }
299
300int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa)
301 {
302 return(ASN1_i2d_fp(i2d_RSA_PUBKEY,fp,(unsigned char *)rsa));
303 }
292#endif 304#endif
293 305
294RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) 306RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa)
@@ -310,10 +322,22 @@ RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa)
310 (unsigned char **)(rsa))); 322 (unsigned char **)(rsa)));
311 } 323 }
312 324
325RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa)
326 {
327 return((RSA *)ASN1_d2i_bio((char *(*)())
328 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (bp),
329 (unsigned char **)(rsa)));
330 }
331
313int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) 332int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
314 { 333 {
315 return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa)); 334 return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa));
316 } 335 }
336
337int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
338 {
339 return(ASN1_i2d_bio(i2d_RSA_PUBKEY,bp,(unsigned char *)rsa));
340 }
317#endif 341#endif
318 342
319#ifndef NO_DSA 343#ifndef NO_DSA
@@ -329,6 +353,18 @@ int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
329 { 353 {
330 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa)); 354 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
331 } 355 }
356
357DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa)
358 {
359 return((DSA *)ASN1_d2i_fp((char *(*)())
360 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (fp),
361 (unsigned char **)(dsa)));
362 }
363
364int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa)
365 {
366 return(ASN1_i2d_fp(i2d_DSA_PUBKEY,fp,(unsigned char *)dsa));
367 }
332#endif 368#endif
333 369
334DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) 370DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa)
@@ -342,6 +378,19 @@ int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa)
342 { 378 {
343 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa)); 379 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
344 } 380 }
381
382DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa)
383 {
384 return((DSA *)ASN1_d2i_bio((char *(*)())
385 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (bp),
386 (unsigned char **)(dsa)));
387 }
388
389int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa)
390 {
391 return(ASN1_i2d_bio(i2d_DSA_PUBKEY,bp,(unsigned char *)dsa));
392 }
393
345#endif 394#endif
346 395
347X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn) 396X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn)
@@ -362,19 +411,19 @@ X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne)
362 (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne)); 411 (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne));
363 } 412 }
364 413
365int X509_digest(X509 *data, EVP_MD *type, unsigned char *md, 414int X509_digest(X509 *data, const EVP_MD *type, unsigned char *md,
366 unsigned int *len) 415 unsigned int *len)
367 { 416 {
368 return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)); 417 return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len));
369 } 418 }
370 419
371int X509_NAME_digest(X509_NAME *data, EVP_MD *type, unsigned char *md, 420int X509_NAME_digest(X509_NAME *data, const EVP_MD *type, unsigned char *md,
372 unsigned int *len) 421 unsigned int *len)
373 { 422 {
374 return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)); 423 return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len));
375 } 424 }
376 425
377int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, EVP_MD *type, 426int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type,
378 unsigned char *md, unsigned int *len) 427 unsigned char *md, unsigned int *len)
379 { 428 {
380 return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type, 429 return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,
@@ -420,6 +469,29 @@ int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
420 { 469 {
421 return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf)); 470 return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf));
422 } 471 }
472
473int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key)
474 {
475 PKCS8_PRIV_KEY_INFO *p8inf;
476 int ret;
477 p8inf = EVP_PKEY2PKCS8(key);
478 if(!p8inf) return 0;
479 ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf);
480 PKCS8_PRIV_KEY_INFO_free(p8inf);
481 return ret;
482 }
483
484int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey)
485 {
486 return(ASN1_i2d_fp(i2d_PrivateKey,fp,(unsigned char *)pkey));
487 }
488
489EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
490{
491 return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new,
492 (char *(*)())d2i_AutoPrivateKey, (fp),(unsigned char **)(a)));
493}
494
423#endif 495#endif
424 496
425PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, 497PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
@@ -435,3 +507,25 @@ int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
435 { 507 {
436 return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf)); 508 return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf));
437 } 509 }
510
511int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
512 {
513 PKCS8_PRIV_KEY_INFO *p8inf;
514 int ret;
515 p8inf = EVP_PKEY2PKCS8(key);
516 if(!p8inf) return 0;
517 ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
518 PKCS8_PRIV_KEY_INFO_free(p8inf);
519 return ret;
520 }
521
522int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey)
523 {
524 return(ASN1_i2d_bio(i2d_PrivateKey,bp,(unsigned char *)pkey));
525 }
526
527EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a)
528 {
529 return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new,
530 (char *(*)())d2i_AutoPrivateKey, (bp),(unsigned char **)(a)));
531 }
diff --git a/src/lib/libcrypto/x509v3/Makefile.ssl b/src/lib/libcrypto/x509v3/Makefile.ssl
index 72871edbc1..1bb746d52d 100644
--- a/src/lib/libcrypto/x509v3/Makefile.ssl
+++ b/src/lib/libcrypto/x509v3/Makefile.ssl
@@ -24,10 +24,10 @@ APPS=
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= v3_bcons.c v3_bitst.c v3_conf.c v3_extku.c v3_ia5.c \ 25LIBSRC= v3_bcons.c v3_bitst.c v3_conf.c v3_extku.c v3_ia5.c \
26v3_lib.c v3_prn.c v3_utl.c v3err.c v3_genn.c v3_alt.c v3_skey.c v3_akey.c \ 26v3_lib.c v3_prn.c v3_utl.c v3err.c v3_genn.c v3_alt.c v3_skey.c v3_akey.c \
27v3_pku.c v3_int.c v3_enum.c v3_sxnet.c v3_cpols.c v3_crld.c 27v3_pku.c v3_int.c v3_enum.c v3_sxnet.c v3_cpols.c v3_crld.c v3_purp.c v3_info.c
28LIBOBJ= v3_bcons.o v3_bitst.o v3_conf.o v3_extku.o v3_ia5.o v3_lib.o \ 28LIBOBJ= v3_bcons.o v3_bitst.o v3_conf.o v3_extku.o v3_ia5.o v3_lib.o \
29v3_prn.o v3_utl.o v3err.o v3_genn.o v3_alt.o v3_skey.o v3_akey.o v3_pku.o \ 29v3_prn.o v3_utl.o v3err.o v3_genn.o v3_alt.o v3_skey.o v3_akey.o v3_pku.o \
30v3_int.o v3_enum.o v3_sxnet.o v3_cpols.o v3_crld.o 30v3_int.o v3_enum.o v3_sxnet.o v3_cpols.o v3_crld.o v3_purp.o v3_info.o
31 31
32SRC= $(LIBSRC) 32SRC= $(LIBSRC)
33 33
@@ -285,6 +285,25 @@ v3_ia5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
285v3_ia5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 285v3_ia5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
286v3_ia5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 286v3_ia5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
287v3_ia5.o: ../../include/openssl/x509v3.h ../cryptlib.h 287v3_ia5.o: ../../include/openssl/x509v3.h ../cryptlib.h
288v3_info.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
289v3_info.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
290v3_info.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
291v3_info.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
292v3_info.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
293v3_info.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
294v3_info.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
295v3_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
296v3_info.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
297v3_info.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
298v3_info.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
299v3_info.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
300v3_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
301v3_info.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
302v3_info.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
303v3_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
304v3_info.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
305v3_info.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
306v3_info.o: ../cryptlib.h
288v3_int.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 307v3_int.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
289v3_int.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 308v3_int.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
290v3_int.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 309v3_int.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -320,7 +339,7 @@ v3_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
320v3_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 339v3_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
321v3_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 340v3_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
322v3_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 341v3_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
323v3_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h 342v3_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h ext_dat.h
324v3_pku.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h 343v3_pku.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
325v3_pku.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h 344v3_pku.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
326v3_pku.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 345v3_pku.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
@@ -358,6 +377,24 @@ v3_prn.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
358v3_prn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 377v3_prn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
359v3_prn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 378v3_prn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
360v3_prn.o: ../../include/openssl/x509v3.h ../cryptlib.h 379v3_prn.o: ../../include/openssl/x509v3.h ../cryptlib.h
380v3_purp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
381v3_purp.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
382v3_purp.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
383v3_purp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
384v3_purp.o: ../../include/openssl/des.h ../../include/openssl/dh.h
385v3_purp.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
386v3_purp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
387v3_purp.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
388v3_purp.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
389v3_purp.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
390v3_purp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
391v3_purp.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
392v3_purp.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
393v3_purp.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
394v3_purp.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
395v3_purp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
396v3_purp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
397v3_purp.o: ../../include/openssl/x509v3.h ../cryptlib.h
361v3_skey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 398v3_skey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
362v3_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 399v3_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
363v3_skey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 400v3_skey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
diff --git a/src/lib/libcrypto/x509v3/README b/src/lib/libcrypto/x509v3/README
index 3b2cc047be..e69de29bb2 100644
--- a/src/lib/libcrypto/x509v3/README
+++ b/src/lib/libcrypto/x509v3/README
@@ -1,4 +0,0 @@
1WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
2
3This is ***VERY*** new experimental code and is likely to change
4considerably or vanish altogether.
diff --git a/src/lib/libcrypto/x509v3/ext_dat.h b/src/lib/libcrypto/x509v3/ext_dat.h
new file mode 100644
index 0000000000..801a585a52
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/ext_dat.h
@@ -0,0 +1,97 @@
1/* ext_dat.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* This file contains a table of "standard" extensions */
59
60extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
61extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet, v3_info;
62extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
63extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld;
64
65/* This table will be searched using OBJ_bsearch so it *must* kept in
66 * order of the ext_nid values.
67 */
68
69static X509V3_EXT_METHOD *standard_exts[] = {
70&v3_nscert,
71&v3_ns_ia5_list[0],
72&v3_ns_ia5_list[1],
73&v3_ns_ia5_list[2],
74&v3_ns_ia5_list[3],
75&v3_ns_ia5_list[4],
76&v3_ns_ia5_list[5],
77&v3_ns_ia5_list[6],
78&v3_skey_id,
79&v3_key_usage,
80&v3_pkey_usage_period,
81&v3_alt[0],
82&v3_alt[1],
83&v3_bcons,
84&v3_crl_num,
85&v3_cpols,
86&v3_akey_id,
87&v3_crld,
88&v3_ext_ku,
89&v3_crl_reason,
90&v3_sxnet,
91&v3_info,
92};
93
94/* Number of standard extensions */
95
96#define STANDARD_EXTENSION_COUNT (sizeof(standard_exts)/sizeof(X509V3_EXT_METHOD *))
97
diff --git a/src/lib/libcrypto/x509v3/tabtest.c b/src/lib/libcrypto/x509v3/tabtest.c
new file mode 100644
index 0000000000..dad0d38dd5
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/tabtest.c
@@ -0,0 +1,88 @@
1/* tabtest.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Simple program to check the ext_dat.h is correct and print out
60 * problems if it is not.
61 */
62
63#include <stdio.h>
64
65#include <openssl/x509v3.h>
66
67#include "ext_dat.h"
68
69main()
70{
71 int i, prev = -1, bad = 0;
72 X509V3_EXT_METHOD **tmp;
73 i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *);
74 if(i != STANDARD_EXTENSION_COUNT)
75 fprintf(stderr, "Extension number invalid expecting %d\n", i);
76 tmp = standard_exts;
77 for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++) {
78 if((*tmp)->ext_nid < prev) bad = 1;
79 prev = (*tmp)->ext_nid;
80
81 }
82 if(bad) {
83 tmp = standard_exts;
84 fprintf(stderr, "Extensions out of order!\n");
85 for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
86 printf("%d : %s\n", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
87 } else fprintf(stderr, "Order OK\n");
88}
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c
index 4099e6019e..96c04fe4f5 100644
--- a/src/lib/libcrypto/x509v3/v3_akey.c
+++ b/src/lib/libcrypto/x509v3/v3_akey.c
@@ -129,10 +129,10 @@ AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp,
129void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a) 129void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a)
130{ 130{
131 if (a == NULL) return; 131 if (a == NULL) return;
132 ASN1_OCTET_STRING_free(a->keyid); 132 M_ASN1_OCTET_STRING_free(a->keyid);
133 sk_GENERAL_NAME_pop_free(a->issuer, GENERAL_NAME_free); 133 sk_GENERAL_NAME_pop_free(a->issuer, GENERAL_NAME_free);
134 ASN1_INTEGER_free (a->serial); 134 M_ASN1_INTEGER_free (a->serial);
135 Free ((char *)a); 135 Free (a);
136} 136}
137 137
138static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, 138static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
@@ -214,7 +214,7 @@ if(keyid) {
214 214
215if((issuer && !ikeyid) || (issuer == 2)) { 215if((issuer && !ikeyid) || (issuer == 2)) {
216 isname = X509_NAME_dup(X509_get_issuer_name(cert)); 216 isname = X509_NAME_dup(X509_get_issuer_name(cert));
217 serial = ASN1_INTEGER_dup(X509_get_serialNumber(cert)); 217 serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert));
218 if(!isname || !serial) { 218 if(!isname || !serial) {
219 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS); 219 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
220 goto err; 220 goto err;
@@ -241,8 +241,8 @@ return akeyid;
241 241
242err: 242err:
243X509_NAME_free(isname); 243X509_NAME_free(isname);
244ASN1_INTEGER_free(serial); 244M_ASN1_INTEGER_free(serial);
245ASN1_OCTET_STRING_free(ikeyid); 245M_ASN1_OCTET_STRING_free(ikeyid);
246return NULL; 246return NULL;
247 247
248} 248}
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c
index b5e1f8af96..5ccd1e0e3d 100644
--- a/src/lib/libcrypto/x509v3/v3_alt.c
+++ b/src/lib/libcrypto/x509v3/v3_alt.c
@@ -84,7 +84,6 @@ NULL, NULL,
84(X509V3_EXT_I2V)i2v_GENERAL_NAMES, 84(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
85(X509V3_EXT_V2I)v2i_issuer_alt, 85(X509V3_EXT_V2I)v2i_issuer_alt,
86NULL, NULL, NULL}, 86NULL, NULL, NULL},
87EXT_END
88}; 87};
89 88
90STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, 89STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
@@ -273,7 +272,7 @@ static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
273 while((i = X509_NAME_get_index_by_NID(nm, 272 while((i = X509_NAME_get_index_by_NID(nm,
274 NID_pkcs9_emailAddress, i)) > 0) { 273 NID_pkcs9_emailAddress, i)) > 0) {
275 ne = X509_NAME_get_entry(nm, i); 274 ne = X509_NAME_get_entry(nm, i);
276 email = ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne)); 275 email = M_ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne));
277 if(!email || !(gen = GENERAL_NAME_new())) { 276 if(!email || !(gen = GENERAL_NAME_new())) {
278 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE); 277 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
279 goto err; 278 goto err;
@@ -293,7 +292,7 @@ static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
293 292
294 err: 293 err:
295 GENERAL_NAME_free(gen); 294 GENERAL_NAME_free(gen);
296 ASN1_IA5STRING_free(email); 295 M_ASN1_IA5STRING_free(email);
297 return 0; 296 return 0;
298 297
299} 298}
@@ -371,7 +370,7 @@ if(!name_cmp(name, "email")) {
371 goto err; 370 goto err;
372 } 371 }
373 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4; 372 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4;
374 if(!(gen->d.ip = ASN1_OCTET_STRING_new()) || 373 if(!(gen->d.ip = M_ASN1_OCTET_STRING_new()) ||
375 !ASN1_STRING_set(gen->d.ip, ip, 4)) { 374 !ASN1_STRING_set(gen->d.ip, ip, 4)) {
376 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE); 375 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
377 goto err; 376 goto err;
@@ -384,7 +383,7 @@ if(!name_cmp(name, "email")) {
384} 383}
385 384
386if(is_string) { 385if(is_string) {
387 if(!(gen->d.ia5 = ASN1_IA5STRING_new()) || 386 if(!(gen->d.ia5 = M_ASN1_IA5STRING_new()) ||
388 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value, 387 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
389 strlen(value))) { 388 strlen(value))) {
390 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE); 389 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c
index de2f855c35..1e3edc205f 100644
--- a/src/lib/libcrypto/x509v3/v3_bcons.c
+++ b/src/lib/libcrypto/x509v3/v3_bcons.c
@@ -122,8 +122,8 @@ BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a,
122void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a) 122void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a)
123{ 123{
124 if (a == NULL) return; 124 if (a == NULL) return;
125 ASN1_INTEGER_free (a->pathlen); 125 M_ASN1_INTEGER_free (a->pathlen);
126 Free ((char *)a); 126 Free (a);
127} 127}
128 128
129static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, 129static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
diff --git a/src/lib/libcrypto/x509v3/v3_bitst.c b/src/lib/libcrypto/x509v3/v3_bitst.c
index 9828ba15b3..0e1167d05c 100644
--- a/src/lib/libcrypto/x509v3/v3_bitst.c
+++ b/src/lib/libcrypto/x509v3/v3_bitst.c
@@ -61,7 +61,6 @@
61#include <openssl/conf.h> 61#include <openssl/conf.h>
62#include <openssl/x509v3.h> 62#include <openssl/x509v3.h>
63 63
64static ASN1_BIT_STRING *asn1_bit_string_new(void);
65static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 64static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
66 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); 65 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
67static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 66static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
@@ -97,11 +96,6 @@ static BIT_STRING_BITNAME key_usage_type_table[] = {
97X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table); 96X509V3_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); 97X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table);
99 98
100static ASN1_BIT_STRING *asn1_bit_string_new(void)
101{
102 return ASN1_BIT_STRING_new();
103}
104
105static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 99static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
106 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret) 100 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret)
107{ 101{
@@ -120,7 +114,7 @@ static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
120 ASN1_BIT_STRING *bs; 114 ASN1_BIT_STRING *bs;
121 int i; 115 int i;
122 BIT_STRING_BITNAME *bnam; 116 BIT_STRING_BITNAME *bnam;
123 if(!(bs = ASN1_BIT_STRING_new())) { 117 if(!(bs = M_ASN1_BIT_STRING_new())) {
124 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE); 118 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE);
125 return NULL; 119 return NULL;
126 } 120 }
@@ -137,7 +131,7 @@ static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
137 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, 131 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
138 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT); 132 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
139 X509V3_conf_err(val); 133 X509V3_conf_err(val);
140 ASN1_BIT_STRING_free(bs); 134 M_ASN1_BIT_STRING_free(bs);
141 return NULL; 135 return NULL;
142 } 136 }
143 } 137 }
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
index f19bb3ad84..b2f03010cc 100644
--- a/src/lib/libcrypto/x509v3/v3_conf.c
+++ b/src/lib/libcrypto/x509v3/v3_conf.c
@@ -170,13 +170,13 @@ static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
170 if(!(ext_der = Malloc(ext_len))) goto merr; 170 if(!(ext_der = Malloc(ext_len))) goto merr;
171 p = ext_der; 171 p = ext_der;
172 method->i2d(ext_struc, &p); 172 method->i2d(ext_struc, &p);
173 if(!(ext_oct = ASN1_OCTET_STRING_new())) goto merr; 173 if(!(ext_oct = M_ASN1_OCTET_STRING_new())) goto merr;
174 ext_oct->data = ext_der; 174 ext_oct->data = ext_der;
175 ext_oct->length = ext_len; 175 ext_oct->length = ext_len;
176 176
177 ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct); 177 ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
178 if(!ext) goto merr; 178 if(!ext) goto merr;
179 ASN1_OCTET_STRING_free(ext_oct); 179 M_ASN1_OCTET_STRING_free(ext_oct);
180 180
181 return ext; 181 return ext;
182 182
@@ -220,7 +220,7 @@ static int v3_check_generic(char **value)
220 return 1; 220 return 1;
221} 221}
222 222
223/* Create a generic extension: for now just handle RAW type */ 223/* Create a generic extension: for now just handle DER type */
224static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, 224static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
225 int crit, int type) 225 int crit, int type)
226{ 226{
@@ -241,7 +241,7 @@ if(!(ext_der = string_to_hex(value, &ext_len))) {
241 goto err; 241 goto err;
242} 242}
243 243
244if(!(oct = ASN1_OCTET_STRING_new())) { 244if(!(oct = M_ASN1_OCTET_STRING_new())) {
245 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE); 245 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE);
246 goto err; 246 goto err;
247} 247}
@@ -254,7 +254,7 @@ extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
254 254
255err: 255err:
256ASN1_OBJECT_free(obj); 256ASN1_OBJECT_free(obj);
257ASN1_OCTET_STRING_free(oct); 257M_ASN1_OCTET_STRING_free(oct);
258if(ext_der) Free(ext_der); 258if(ext_der) Free(ext_der);
259return extension; 259return extension;
260} 260}
@@ -302,6 +302,30 @@ int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
302 return 1; 302 return 1;
303} 303}
304 304
305/* Add extensions to certificate request */
306
307int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
308 X509_REQ *req)
309{
310 X509_EXTENSION *ext;
311 STACK_OF(X509_EXTENSION) *extlist = NULL;
312 STACK_OF(CONF_VALUE) *nval;
313 CONF_VALUE *val;
314 int i;
315 if(!(nval = CONF_get_section(conf, section))) return 0;
316 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
317 val = sk_CONF_VALUE_value(nval, i);
318 if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value)))
319 return 0;
320 if(!extlist) extlist = sk_X509_EXTENSION_new_null();
321 sk_X509_EXTENSION_push(extlist, ext);
322 }
323 if(req) i = X509_REQ_add_extensions(req, extlist);
324 else i = 1;
325 sk_X509_EXTENSION_pop_free(extlist, X509_EXTENSION_free);
326 return i;
327}
328
305/* Config database functions */ 329/* Config database functions */
306 330
307char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section) 331char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
index b4d4883545..466713b50d 100644
--- a/src/lib/libcrypto/x509v3/v3_cpols.c
+++ b/src/lib/libcrypto/x509v3/v3_cpols.c
@@ -169,7 +169,7 @@ static POLICYINFO *policy_section(X509V3_CTX *ctx,
169 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) 169 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
170 goto merr; 170 goto merr;
171 qual->pqualid = OBJ_nid2obj(NID_id_qt_cps); 171 qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
172 qual->d.cpsuri = ASN1_IA5STRING_new(); 172 qual->d.cpsuri = M_ASN1_IA5STRING_new();
173 if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value, 173 if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
174 strlen(cnf->value))) goto merr; 174 strlen(cnf->value))) goto merr;
175 } else if(!name_cmp(cnf->name, "userNotice")) { 175 } else if(!name_cmp(cnf->name, "userNotice")) {
@@ -229,7 +229,7 @@ static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
229 for(i = 0; i < sk_CONF_VALUE_num(unot); i++) { 229 for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
230 cnf = sk_CONF_VALUE_value(unot, i); 230 cnf = sk_CONF_VALUE_value(unot, i);
231 if(!strcmp(cnf->name, "explicitText")) { 231 if(!strcmp(cnf->name, "explicitText")) {
232 not->exptext = ASN1_VISIBLESTRING_new(); 232 not->exptext = M_ASN1_VISIBLESTRING_new();
233 if(!ASN1_STRING_set(not->exptext, cnf->value, 233 if(!ASN1_STRING_set(not->exptext, cnf->value,
234 strlen(cnf->value))) goto merr; 234 strlen(cnf->value))) goto merr;
235 } else if(!strcmp(cnf->name, "organization")) { 235 } else if(!strcmp(cnf->name, "organization")) {
@@ -238,8 +238,8 @@ static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
238 if(!(nref = NOTICEREF_new())) goto merr; 238 if(!(nref = NOTICEREF_new())) goto merr;
239 not->noticeref = nref; 239 not->noticeref = nref;
240 } else nref = not->noticeref; 240 } else nref = not->noticeref;
241 if(ia5org) nref->organization = ASN1_IA5STRING_new(); 241 if(ia5org) nref->organization = M_ASN1_IA5STRING_new();
242 else nref->organization = ASN1_VISIBLESTRING_new(); 242 else nref->organization = M_ASN1_VISIBLESTRING_new();
243 if(!ASN1_STRING_set(nref->organization, cnf->value, 243 if(!ASN1_STRING_set(nref->organization, cnf->value,
244 strlen(cnf->value))) goto merr; 244 strlen(cnf->value))) goto merr;
245 } else if(!strcmp(cnf->name, "noticeNumbers")) { 245 } else if(!strcmp(cnf->name, "noticeNumbers")) {
@@ -538,7 +538,7 @@ void POLICYQUALINFO_free(POLICYQUALINFO *a)
538 if (a == NULL) return; 538 if (a == NULL) return;
539 switch(OBJ_obj2nid(a->pqualid)) { 539 switch(OBJ_obj2nid(a->pqualid)) {
540 case NID_id_qt_cps: 540 case NID_id_qt_cps:
541 ASN1_IA5STRING_free(a->d.cpsuri); 541 M_ASN1_IA5STRING_free(a->d.cpsuri);
542 break; 542 break;
543 543
544 case NID_id_qt_unotice: 544 case NID_id_qt_unotice:
@@ -596,7 +596,7 @@ void USERNOTICE_free(USERNOTICE *a)
596{ 596{
597 if (a == NULL) return; 597 if (a == NULL) return;
598 NOTICEREF_free(a->noticeref); 598 NOTICEREF_free(a->noticeref);
599 DISPLAYTEXT_free(a->exptext); 599 M_DISPLAYTEXT_free(a->exptext);
600 Free (a); 600 Free (a);
601} 601}
602 602
@@ -646,7 +646,7 @@ NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp,long length)
646void NOTICEREF_free(NOTICEREF *a) 646void NOTICEREF_free(NOTICEREF *a)
647{ 647{
648 if (a == NULL) return; 648 if (a == NULL) return;
649 DISPLAYTEXT_free(a->organization); 649 M_DISPLAYTEXT_free(a->organization);
650 sk_pop_free(a->noticenos, ASN1_STRING_free); 650 sk_pop_free(a->noticenos, ASN1_STRING_free);
651 Free (a); 651 Free (a);
652} 652}
diff --git a/src/lib/libcrypto/x509v3/v3_crld.c b/src/lib/libcrypto/x509v3/v3_crld.c
index 897ffb63e4..e459d2595a 100644
--- a/src/lib/libcrypto/x509v3/v3_crld.c
+++ b/src/lib/libcrypto/x509v3/v3_crld.c
@@ -211,20 +211,20 @@ void DIST_POINT_free(DIST_POINT *a)
211{ 211{
212 if (a == NULL) return; 212 if (a == NULL) return;
213 DIST_POINT_NAME_free(a->distpoint); 213 DIST_POINT_NAME_free(a->distpoint);
214 ASN1_BIT_STRING_free(a->reasons); 214 M_ASN1_BIT_STRING_free(a->reasons);
215 sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free); 215 sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free);
216 Free ((char *)a); 216 Free (a);
217} 217}
218 218
219int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp) 219int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
220{ 220{
221 int v = 0;
222 M_ASN1_I2D_vars(a); 221 M_ASN1_I2D_vars(a);
223 222
224 if(a->fullname) { 223 if(a->fullname) {
225 M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES); 224 M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES);
226 } else { 225 } else {
227 M_ASN1_I2D_len_EXP_opt (a->relativename, i2d_X509_NAME, 1, v); 226 M_ASN1_I2D_len_IMP_SET_opt_type(X509_NAME_ENTRY,
227 a->relativename, i2d_X509_NAME_ENTRY, 1);
228 } 228 }
229 229
230 /* Don't want a SEQUENCE so... */ 230 /* Don't want a SEQUENCE so... */
@@ -234,7 +234,8 @@ int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
234 if(a->fullname) { 234 if(a->fullname) {
235 M_ASN1_I2D_put_IMP_opt (a->fullname, i2d_GENERAL_NAMES, 0); 235 M_ASN1_I2D_put_IMP_opt (a->fullname, i2d_GENERAL_NAMES, 0);
236 } else { 236 } else {
237 M_ASN1_I2D_put_EXP_opt (a->relativename, i2d_X509_NAME, 1, v); 237 M_ASN1_I2D_put_IMP_SET_opt_type(X509_NAME_ENTRY,
238 a->relativename, i2d_X509_NAME_ENTRY, 1);
238 } 239 }
239 M_ASN1_I2D_finish(); 240 M_ASN1_I2D_finish();
240} 241}
@@ -253,9 +254,9 @@ DIST_POINT_NAME *DIST_POINT_NAME_new(void)
253void DIST_POINT_NAME_free(DIST_POINT_NAME *a) 254void DIST_POINT_NAME_free(DIST_POINT_NAME *a)
254{ 255{
255 if (a == NULL) return; 256 if (a == NULL) return;
256 X509_NAME_free(a->relativename); 257 sk_X509_NAME_ENTRY_pop_free(a->relativename, X509_NAME_ENTRY_free);
257 sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free); 258 sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free);
258 Free ((char *)a); 259 Free (a);
259} 260}
260 261
261DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp, 262DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
@@ -273,7 +274,8 @@ DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
273 M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES, 274 M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES,
274 V_ASN1_SEQUENCE); 275 V_ASN1_SEQUENCE);
275 } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) { 276 } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) {
276 M_ASN1_D2I_get_EXP_opt (ret->relativename, d2i_X509_NAME, 1); 277 M_ASN1_D2I_get_IMP_set_opt_type (X509_NAME_ENTRY,
278 ret->relativename, d2i_X509_NAME_ENTRY, X509_NAME_ENTRY_free, 1);
277 } else { 279 } else {
278 c.error = ASN1_R_BAD_TAG; 280 c.error = ASN1_R_BAD_TAG;
279 goto err; 281 goto err;
diff --git a/src/lib/libcrypto/x509v3/v3_enum.c b/src/lib/libcrypto/x509v3/v3_enum.c
index db423548ff..aecfdc87f8 100644
--- a/src/lib/libcrypto/x509v3/v3_enum.c
+++ b/src/lib/libcrypto/x509v3/v3_enum.c
@@ -60,8 +60,6 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/x509v3.h> 61#include <openssl/x509v3.h>
62 62
63static ASN1_ENUMERATED *asn1_enumerated_new(void);
64
65static ENUMERATED_NAMES crl_reasons[] = { 63static ENUMERATED_NAMES crl_reasons[] = {
66{0, "Unspecified", "unspecified"}, 64{0, "Unspecified", "unspecified"},
67{1, "Key Compromise", "keyCompromise"}, 65{1, "Key Compromise", "keyCompromise"},
@@ -76,20 +74,15 @@ static ENUMERATED_NAMES crl_reasons[] = {
76 74
77X509V3_EXT_METHOD v3_crl_reason = { 75X509V3_EXT_METHOD v3_crl_reason = {
78NID_crl_reason, 0, 76NID_crl_reason, 0,
79(X509V3_EXT_NEW)asn1_enumerated_new, 77(X509V3_EXT_NEW)ASN1_ENUMERATED_new,
80(X509V3_EXT_FREE)ASN1_STRING_free, 78(X509V3_EXT_FREE)ASN1_ENUMERATED_free,
81(X509V3_EXT_D2I)d2i_ASN1_ENUMERATED, 79(X509V3_EXT_D2I)d2i_ASN1_ENUMERATED,
82(X509V3_EXT_I2D)i2d_ASN1_ENUMERATED, 80(X509V3_EXT_I2D)i2d_ASN1_ENUMERATED,
83(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE, 81(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
84(X509V3_EXT_S2I)NULL, 82(X509V3_EXT_S2I)0,
85NULL, NULL, NULL, NULL, crl_reasons}; 83NULL, NULL, NULL, NULL, crl_reasons};
86 84
87 85
88static ASN1_ENUMERATED *asn1_enumerated_new(void)
89{
90 return ASN1_ENUMERATED_new();
91}
92
93char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method, 86char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
94 ASN1_ENUMERATED *e) 87 ASN1_ENUMERATED *e)
95{ 88{
diff --git a/src/lib/libcrypto/x509v3/v3_genn.c b/src/lib/libcrypto/x509v3/v3_genn.c
index af716232f8..894afa7e03 100644
--- a/src/lib/libcrypto/x509v3/v3_genn.c
+++ b/src/lib/libcrypto/x509v3/v3_genn.c
@@ -88,12 +88,15 @@ int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp)
88 88
89 switch(a->type) { 89 switch(a->type) {
90 90
91 case GEN_OTHERNAME:
92 case GEN_X400: 91 case GEN_X400:
93 case GEN_EDIPARTY: 92 case GEN_EDIPARTY:
94 ret = i2d_ASN1_TYPE(a->d.other, pp); 93 ret = i2d_ASN1_TYPE(a->d.other, pp);
95 break; 94 break;
96 95
96 case GEN_OTHERNAME:
97 ret = i2d_OTHERNAME(a->d.otherName, pp);
98 break;
99
97 case GEN_EMAIL: 100 case GEN_EMAIL:
98 case GEN_DNS: 101 case GEN_DNS:
99 case GEN_URI: 102 case GEN_URI:
@@ -137,12 +140,15 @@ GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp,
137 140
138 switch(ret->type) { 141 switch(ret->type) {
139 /* Just put these in a "blob" for now */ 142 /* Just put these in a "blob" for now */
140 case GEN_OTHERNAME:
141 case GEN_X400: 143 case GEN_X400:
142 case GEN_EDIPARTY: 144 case GEN_EDIPARTY:
143 M_ASN1_D2I_get_imp(ret->d.other, d2i_ASN1_TYPE,V_ASN1_SEQUENCE); 145 M_ASN1_D2I_get_imp(ret->d.other, d2i_ASN1_TYPE,V_ASN1_SEQUENCE);
144 break; 146 break;
145 147
148 case GEN_OTHERNAME:
149 M_ASN1_D2I_get_imp(ret->d.otherName, d2i_OTHERNAME,V_ASN1_SEQUENCE);
150 break;
151
146 case GEN_EMAIL: 152 case GEN_EMAIL:
147 case GEN_DNS: 153 case GEN_DNS:
148 case GEN_URI: 154 case GEN_URI:
@@ -176,17 +182,20 @@ void GENERAL_NAME_free(GENERAL_NAME *a)
176{ 182{
177 if (a == NULL) return; 183 if (a == NULL) return;
178 switch(a->type) { 184 switch(a->type) {
179 case GEN_OTHERNAME:
180 case GEN_X400: 185 case GEN_X400:
181 case GEN_EDIPARTY: 186 case GEN_EDIPARTY:
182 ASN1_TYPE_free(a->d.other); 187 ASN1_TYPE_free(a->d.other);
183 break; 188 break;
184 189
190 case GEN_OTHERNAME:
191 OTHERNAME_free(a->d.otherName);
192 break;
193
185 case GEN_EMAIL: 194 case GEN_EMAIL:
186 case GEN_DNS: 195 case GEN_DNS:
187 case GEN_URI: 196 case GEN_URI:
188 197
189 ASN1_IA5STRING_free(a->d.ia5); 198 M_ASN1_IA5STRING_free(a->d.ia5);
190 break; 199 break;
191 200
192 case GEN_DIRNAME: 201 case GEN_DIRNAME:
@@ -194,7 +203,7 @@ void GENERAL_NAME_free(GENERAL_NAME *a)
194 break; 203 break;
195 204
196 case GEN_IPADD: 205 case GEN_IPADD:
197 ASN1_OCTET_STRING_free(a->d.ip); 206 M_ASN1_OCTET_STRING_free(a->d.ip);
198 break; 207 break;
199 208
200 case GEN_RID: 209 case GEN_RID:
@@ -202,11 +211,11 @@ void GENERAL_NAME_free(GENERAL_NAME *a)
202 break; 211 break;
203 212
204 } 213 }
205 Free ((char *)a); 214 Free (a);
206} 215}
207 216
208/* Now the GeneralNames versions: a SEQUENCE OF GeneralName These are needed as 217/* Now the GeneralNames versions: a SEQUENCE OF GeneralName. These are needed as
209 * an explicit functions. 218 * explicit functions.
210 */ 219 */
211 220
212STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new() 221STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new()
@@ -235,3 +244,48 @@ return i2d_ASN1_SET_OF_GENERAL_NAME(a, pp, i2d_GENERAL_NAME, V_ASN1_SEQUENCE,
235IMPLEMENT_STACK_OF(GENERAL_NAME) 244IMPLEMENT_STACK_OF(GENERAL_NAME)
236IMPLEMENT_ASN1_SET_OF(GENERAL_NAME) 245IMPLEMENT_ASN1_SET_OF(GENERAL_NAME)
237 246
247int i2d_OTHERNAME(OTHERNAME *a, unsigned char **pp)
248{
249 int v = 0;
250 M_ASN1_I2D_vars(a);
251
252 M_ASN1_I2D_len(a->type_id, i2d_ASN1_OBJECT);
253 M_ASN1_I2D_len_EXP_opt(a->value, i2d_ASN1_TYPE, 0, v);
254
255 M_ASN1_I2D_seq_total();
256
257 M_ASN1_I2D_put(a->type_id, i2d_ASN1_OBJECT);
258 M_ASN1_I2D_put_EXP_opt(a->value, i2d_ASN1_TYPE, 0, v);
259
260 M_ASN1_I2D_finish();
261}
262
263OTHERNAME *OTHERNAME_new(void)
264{
265 OTHERNAME *ret=NULL;
266 ASN1_CTX c;
267 M_ASN1_New_Malloc(ret, OTHERNAME);
268 ret->type_id = OBJ_nid2obj(NID_undef);
269 M_ASN1_New(ret->value, ASN1_TYPE_new);
270 return (ret);
271 M_ASN1_New_Error(ASN1_F_OTHERNAME_NEW);
272}
273
274OTHERNAME *d2i_OTHERNAME(OTHERNAME **a, unsigned char **pp, long length)
275{
276 M_ASN1_D2I_vars(a,OTHERNAME *,OTHERNAME_new);
277 M_ASN1_D2I_Init();
278 M_ASN1_D2I_start_sequence();
279 M_ASN1_D2I_get(ret->type_id, d2i_ASN1_OBJECT);
280 M_ASN1_D2I_get_EXP_opt(ret->value, d2i_ASN1_TYPE, 0);
281 M_ASN1_D2I_Finish(a, OTHERNAME_free, ASN1_F_D2I_OTHERNAME);
282}
283
284void OTHERNAME_free(OTHERNAME *a)
285{
286 if (a == NULL) return;
287 ASN1_OBJECT_free(a->type_id);
288 ASN1_TYPE_free(a->value);
289 Free (a);
290}
291
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
index 3446c5cd6a..af3525f33e 100644
--- a/src/lib/libcrypto/x509v3/v3_ia5.c
+++ b/src/lib/libcrypto/x509v3/v3_ia5.c
@@ -63,7 +63,6 @@
63#include <openssl/conf.h> 63#include <openssl/conf.h>
64#include <openssl/x509v3.h> 64#include <openssl/x509v3.h>
65 65
66static ASN1_IA5STRING *ia5string_new(void);
67static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5); 66static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5);
68static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); 67static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
69X509V3_EXT_METHOD v3_ns_ia5_list[] = { 68X509V3_EXT_METHOD v3_ns_ia5_list[] = {
@@ -78,11 +77,6 @@ EXT_END
78}; 77};
79 78
80 79
81static ASN1_IA5STRING *ia5string_new(void)
82{
83 return ASN1_IA5STRING_new();
84}
85
86static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, 80static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
87 ASN1_IA5STRING *ia5) 81 ASN1_IA5STRING *ia5)
88{ 82{
@@ -102,12 +96,15 @@ static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
102 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT); 96 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT);
103 return NULL; 97 return NULL;
104 } 98 }
105 if(!(ia5 = ASN1_IA5STRING_new())) goto err; 99 if(!(ia5 = M_ASN1_IA5STRING_new())) goto err;
106 if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str, 100 if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str,
107 strlen(str))) { 101 strlen(str))) {
108 ASN1_IA5STRING_free(ia5); 102 M_ASN1_IA5STRING_free(ia5);
109 goto err; 103 goto err;
110 } 104 }
105#ifdef CHARSET_EBCDIC
106 ebcdic2ascii(ia5->data, ia5->data, ia5->length);
107#endif /*CHARSET_EBCDIC*/
111 return ia5; 108 return ia5;
112 err: 109 err:
113 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE); 110 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/x509v3/v3_info.c b/src/lib/libcrypto/x509v3/v3_info.c
new file mode 100644
index 0000000000..78d2135046
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_info.c
@@ -0,0 +1,236 @@
1/* v3_info.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
67 STACK_OF(ACCESS_DESCRIPTION) *ainfo,
68 STACK_OF(CONF_VALUE) *ret);
69static STACK_OF(ACCESS_DESCRIPTION) *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
70 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
71
72X509V3_EXT_METHOD v3_info =
73{ NID_info_access, X509V3_EXT_MULTILINE,
74(X509V3_EXT_NEW)AUTHORITY_INFO_ACCESS_new,
75(X509V3_EXT_FREE)AUTHORITY_INFO_ACCESS_free,
76(X509V3_EXT_D2I)d2i_AUTHORITY_INFO_ACCESS,
77(X509V3_EXT_I2D)i2d_AUTHORITY_INFO_ACCESS,
78NULL, NULL,
79(X509V3_EXT_I2V)i2v_AUTHORITY_INFO_ACCESS,
80(X509V3_EXT_V2I)v2i_AUTHORITY_INFO_ACCESS,
81NULL, NULL, NULL};
82
83static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
84 STACK_OF(ACCESS_DESCRIPTION) *ainfo,
85 STACK_OF(CONF_VALUE) *ret)
86{
87 ACCESS_DESCRIPTION *desc;
88 int i;
89 char objtmp[80], *ntmp;
90 CONF_VALUE *vtmp;
91 for(i = 0; i < sk_ACCESS_DESCRIPTION_num(ainfo); i++) {
92 desc = sk_ACCESS_DESCRIPTION_value(ainfo, i);
93 ret = i2v_GENERAL_NAME(method, desc->location, ret);
94 if(!ret) break;
95 vtmp = sk_CONF_VALUE_value(ret, i);
96 i2t_ASN1_OBJECT(objtmp, 80, desc->method);
97 ntmp = Malloc(strlen(objtmp) + strlen(vtmp->name) + 5);
98 if(!ntmp) {
99 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS,
100 ERR_R_MALLOC_FAILURE);
101 return NULL;
102 }
103 strcpy(ntmp, objtmp);
104 strcat(ntmp, " - ");
105 strcat(ntmp, vtmp->name);
106 Free(vtmp->name);
107 vtmp->name = ntmp;
108
109 }
110 if(!ret) return sk_CONF_VALUE_new_null();
111 return ret;
112}
113
114static STACK_OF(ACCESS_DESCRIPTION) *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
115 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
116{
117 STACK_OF(ACCESS_DESCRIPTION) *ainfo = NULL;
118 CONF_VALUE *cnf, ctmp;
119 ACCESS_DESCRIPTION *acc;
120 int i, objlen;
121 char *objtmp, *ptmp;
122 if(!(ainfo = sk_ACCESS_DESCRIPTION_new(NULL))) {
123 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
124 return NULL;
125 }
126 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
127 cnf = sk_CONF_VALUE_value(nval, i);
128 if(!(acc = ACCESS_DESCRIPTION_new())
129 || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) {
130 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
131 goto err;
132 }
133 ptmp = strchr(cnf->name, ';');
134 if(!ptmp) {
135 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_INVALID_SYNTAX);
136 goto err;
137 }
138 objlen = ptmp - cnf->name;
139 ctmp.name = ptmp + 1;
140 ctmp.value = cnf->value;
141 if(!(acc->location = v2i_GENERAL_NAME(method, ctx, &ctmp)))
142 goto err;
143 if(!(objtmp = Malloc(objlen + 1))) {
144 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
145 goto err;
146 }
147 strncpy(objtmp, cnf->name, objlen);
148 objtmp[objlen] = 0;
149 acc->method = OBJ_txt2obj(objtmp, 0);
150 if(!acc->method) {
151 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_BAD_OBJECT);
152 ERR_add_error_data(2, "value=", objtmp);
153 Free(objtmp);
154 goto err;
155 }
156 Free(objtmp);
157
158 }
159 return ainfo;
160 err:
161 sk_ACCESS_DESCRIPTION_pop_free(ainfo, ACCESS_DESCRIPTION_free);
162 return NULL;
163}
164
165int i2d_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION *a, unsigned char **pp)
166{
167 M_ASN1_I2D_vars(a);
168
169 M_ASN1_I2D_len(a->method, i2d_ASN1_OBJECT);
170 M_ASN1_I2D_len(a->location, i2d_GENERAL_NAME);
171
172 M_ASN1_I2D_seq_total();
173
174 M_ASN1_I2D_put(a->method, i2d_ASN1_OBJECT);
175 M_ASN1_I2D_put(a->location, i2d_GENERAL_NAME);
176
177 M_ASN1_I2D_finish();
178}
179
180ACCESS_DESCRIPTION *ACCESS_DESCRIPTION_new(void)
181{
182 ACCESS_DESCRIPTION *ret=NULL;
183 ASN1_CTX c;
184 M_ASN1_New_Malloc(ret, ACCESS_DESCRIPTION);
185 ret->method = OBJ_nid2obj(NID_undef);
186 ret->location = NULL;
187 return (ret);
188 M_ASN1_New_Error(ASN1_F_ACCESS_DESCRIPTION_NEW);
189}
190
191ACCESS_DESCRIPTION *d2i_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION **a, unsigned char **pp,
192 long length)
193{
194 M_ASN1_D2I_vars(a,ACCESS_DESCRIPTION *,ACCESS_DESCRIPTION_new);
195 M_ASN1_D2I_Init();
196 M_ASN1_D2I_start_sequence();
197 M_ASN1_D2I_get(ret->method, d2i_ASN1_OBJECT);
198 M_ASN1_D2I_get(ret->location, d2i_GENERAL_NAME);
199 M_ASN1_D2I_Finish(a, ACCESS_DESCRIPTION_free, ASN1_F_D2I_ACCESS_DESCRIPTION);
200}
201
202void ACCESS_DESCRIPTION_free(ACCESS_DESCRIPTION *a)
203{
204 if (a == NULL) return;
205 ASN1_OBJECT_free(a->method);
206 GENERAL_NAME_free(a->location);
207 Free (a);
208}
209
210STACK_OF(ACCESS_DESCRIPTION) *AUTHORITY_INFO_ACCESS_new(void)
211{
212 return sk_ACCESS_DESCRIPTION_new(NULL);
213}
214
215void AUTHORITY_INFO_ACCESS_free(STACK_OF(ACCESS_DESCRIPTION) *a)
216{
217 sk_ACCESS_DESCRIPTION_pop_free(a, ACCESS_DESCRIPTION_free);
218}
219
220STACK_OF(ACCESS_DESCRIPTION) *d2i_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) **a,
221 unsigned char **pp, long length)
222{
223return d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(a, pp, length, d2i_ACCESS_DESCRIPTION,
224 ACCESS_DESCRIPTION_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
225}
226
227int i2d_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) *a, unsigned char **pp)
228{
229return i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(a, pp, i2d_ACCESS_DESCRIPTION, V_ASN1_SEQUENCE,
230 V_ASN1_UNIVERSAL, IS_SEQUENCE);
231}
232
233IMPLEMENT_STACK_OF(ACCESS_DESCRIPTION)
234IMPLEMENT_ASN1_SET_OF(ACCESS_DESCRIPTION)
235
236
diff --git a/src/lib/libcrypto/x509v3/v3_int.c b/src/lib/libcrypto/x509v3/v3_int.c
index 637dd5e128..63c201e5f4 100644
--- a/src/lib/libcrypto/x509v3/v3_int.c
+++ b/src/lib/libcrypto/x509v3/v3_int.c
@@ -60,20 +60,13 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/x509v3.h> 61#include <openssl/x509v3.h>
62 62
63static ASN1_INTEGER *asn1_integer_new(void);
64
65X509V3_EXT_METHOD v3_crl_num = { 63X509V3_EXT_METHOD v3_crl_num = {
66NID_crl_number, 0, 64NID_crl_number, 0,
67(X509V3_EXT_NEW)asn1_integer_new, 65(X509V3_EXT_NEW)ASN1_INTEGER_new,
68(X509V3_EXT_FREE)ASN1_STRING_free, 66(X509V3_EXT_FREE)ASN1_INTEGER_free,
69(X509V3_EXT_D2I)d2i_ASN1_INTEGER, 67(X509V3_EXT_D2I)d2i_ASN1_INTEGER,
70(X509V3_EXT_I2D)i2d_ASN1_INTEGER, 68(X509V3_EXT_I2D)i2d_ASN1_INTEGER,
71(X509V3_EXT_I2S)i2s_ASN1_INTEGER, 69(X509V3_EXT_I2S)i2s_ASN1_INTEGER,
72(X509V3_EXT_S2I)NULL, 70(X509V3_EXT_S2I)0,
73NULL, NULL, NULL, NULL, NULL}; 71NULL, NULL, NULL, NULL, NULL};
74 72
75
76static ASN1_INTEGER *asn1_integer_new(void)
77{
78 return ASN1_INTEGER_new();
79}
diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c
index a0aa5de794..4242d130a2 100644
--- a/src/lib/libcrypto/x509v3/v3_lib.c
+++ b/src/lib/libcrypto/x509v3/v3_lib.c
@@ -62,6 +62,8 @@
62#include <openssl/conf.h> 62#include <openssl/conf.h>
63#include <openssl/x509v3.h> 63#include <openssl/x509v3.h>
64 64
65#include "ext_dat.h"
66
65static STACK *ext_list = NULL; 67static STACK *ext_list = NULL;
66 68
67static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b); 69static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
@@ -87,10 +89,15 @@ static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b)
87 89
88X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid) 90X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
89{ 91{
90 X509V3_EXT_METHOD tmp; 92 X509V3_EXT_METHOD tmp, *t = &tmp, **ret;
91 int idx; 93 int idx;
94 if(nid < 0) return NULL;
92 tmp.ext_nid = nid; 95 tmp.ext_nid = nid;
93 if(!ext_list || (tmp.ext_nid < 0) ) return NULL; 96 ret = (X509V3_EXT_METHOD **) OBJ_bsearch((char *)&t,
97 (char *)standard_exts, STANDARD_EXTENSION_COUNT,
98 sizeof(X509V3_EXT_METHOD *), (int (*)())ext_cmp);
99 if(ret) return *ret;
100 if(!ext_list) return NULL;
94 idx = sk_find(ext_list, (char *)&tmp); 101 idx = sk_find(ext_list, (char *)&tmp);
95 if(idx == -1) return NULL; 102 if(idx == -1) return NULL;
96 return (X509V3_EXT_METHOD *)sk_value(ext_list, idx); 103 return (X509V3_EXT_METHOD *)sk_value(ext_list, idx);
@@ -125,7 +132,7 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from)
125 *tmpext = *ext; 132 *tmpext = *ext;
126 tmpext->ext_nid = nid_to; 133 tmpext->ext_nid = nid_to;
127 tmpext->ext_flags |= X509V3_EXT_DYNAMIC; 134 tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
128 return 1; 135 return X509V3_EXT_add(tmpext);
129} 136}
130 137
131void X509V3_EXT_cleanup(void) 138void X509V3_EXT_cleanup(void)
@@ -139,28 +146,12 @@ static void ext_list_free(X509V3_EXT_METHOD *ext)
139 if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext); 146 if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext);
140} 147}
141 148
142extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku; 149/* Legacy function: we don't need to add standard extensions
143extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet; 150 * any more because they are now kept in ext_dat.h.
144extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id; 151 */
145
146extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld;
147 152
148int X509V3_add_standard_extensions(void) 153int X509V3_add_standard_extensions(void)
149{ 154{
150 X509V3_EXT_add_list(v3_ns_ia5_list);
151 X509V3_EXT_add_list(v3_alt);
152 X509V3_EXT_add(&v3_bcons);
153 X509V3_EXT_add(&v3_nscert);
154 X509V3_EXT_add(&v3_key_usage);
155 X509V3_EXT_add(&v3_ext_ku);
156 X509V3_EXT_add(&v3_skey_id);
157 X509V3_EXT_add(&v3_akey_id);
158 X509V3_EXT_add(&v3_pkey_usage_period);
159 X509V3_EXT_add(&v3_crl_num);
160 X509V3_EXT_add(&v3_sxnet);
161 X509V3_EXT_add(&v3_crl_reason);
162 X509V3_EXT_add(&v3_cpols);
163 X509V3_EXT_add(&v3_crld);
164 return 1; 155 return 1;
165} 156}
166 157
@@ -175,3 +166,56 @@ void *X509V3_EXT_d2i(X509_EXTENSION *ext)
175 return method->d2i(NULL, &p, ext->value->length); 166 return method->d2i(NULL, &p, ext->value->length);
176} 167}
177 168
169/* Get critical flag and decoded version of extension from a NID.
170 * The "idx" variable returns the last found extension and can
171 * be used to retrieve multiple extensions of the same NID.
172 * However multiple extensions with the same NID is usually
173 * due to a badly encoded certificate so if idx is NULL we
174 * choke if multiple extensions exist.
175 * The "crit" variable is set to the critical value.
176 * The return value is the decoded extension or NULL on
177 * error. The actual error can have several different causes,
178 * the value of *crit reflects the cause:
179 * >= 0, extension found but not decoded (reflects critical value).
180 * -1 extension not found.
181 * -2 extension occurs more than once.
182 */
183
184void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx)
185{
186 int lastpos, i;
187 X509_EXTENSION *ex, *found_ex = NULL;
188 if(!x) {
189 if(idx) *idx = -1;
190 if(crit) *crit = -1;
191 return NULL;
192 }
193 if(idx) lastpos = *idx + 1;
194 else lastpos = 0;
195 if(lastpos < 0) lastpos = 0;
196 for(i = lastpos; i < sk_X509_EXTENSION_num(x); i++)
197 {
198 ex = sk_X509_EXTENSION_value(x, i);
199 if(OBJ_obj2nid(ex->object) == nid) {
200 if(idx) {
201 *idx = i;
202 break;
203 } else if(found_ex) {
204 /* Found more than one */
205 if(crit) *crit = -2;
206 return NULL;
207 }
208 found_ex = ex;
209 }
210 }
211 if(found_ex) {
212 /* Found it */
213 if(crit) *crit = found_ex->critical;
214 return X509V3_EXT_d2i(found_ex);
215 }
216
217 /* Extension not found */
218 if(idx) *idx = -1;
219 if(crit) *crit = -1;
220 return NULL;
221}
diff --git a/src/lib/libcrypto/x509v3/v3_pku.c b/src/lib/libcrypto/x509v3/v3_pku.c
index c13e7d8f45..30a62c6090 100644
--- a/src/lib/libcrypto/x509v3/v3_pku.c
+++ b/src/lib/libcrypto/x509v3/v3_pku.c
@@ -119,9 +119,9 @@ PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a,
119void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a) 119void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a)
120{ 120{
121 if (a == NULL) return; 121 if (a == NULL) return;
122 ASN1_GENERALIZEDTIME_free(a->notBefore); 122 M_ASN1_GENERALIZEDTIME_free(a->notBefore);
123 ASN1_GENERALIZEDTIME_free(a->notAfter); 123 M_ASN1_GENERALIZEDTIME_free(a->notAfter);
124 Free ((char *)a); 124 Free (a);
125} 125}
126 126
127static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, 127static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c
index dc20c6bdba..bee624c6be 100644
--- a/src/lib/libcrypto/x509v3/v3_prn.c
+++ b/src/lib/libcrypto/x509v3/v3_prn.c
@@ -81,7 +81,15 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml)
81 nval = sk_CONF_VALUE_value(val, i); 81 nval = sk_CONF_VALUE_value(val, i);
82 if(!nval->name) BIO_puts(out, nval->value); 82 if(!nval->name) BIO_puts(out, nval->value);
83 else if(!nval->value) BIO_puts(out, nval->name); 83 else if(!nval->value) BIO_puts(out, nval->name);
84#ifndef CHARSET_EBCDIC
84 else BIO_printf(out, "%s:%s", nval->name, nval->value); 85 else BIO_printf(out, "%s:%s", nval->name, nval->value);
86#else
87 else {
88 char tmp[10240]; /* 10k is BIO_printf's limit anyway */
89 ascii2ebcdic(tmp, nval->value, strlen(nval->value)+1);
90 BIO_printf(out, "%s:%s", nval->name, tmp);
91 }
92#endif
85 if(ml) BIO_puts(out, "\n"); 93 if(ml) BIO_puts(out, "\n");
86 } 94 }
87} 95}
@@ -103,7 +111,15 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent)
103 ok = 0; 111 ok = 0;
104 goto err; 112 goto err;
105 } 113 }
114#ifndef CHARSET_EBCDIC
106 BIO_printf(out, "%*s%s", indent, "", value); 115 BIO_printf(out, "%*s%s", indent, "", value);
116#else
117 {
118 char tmp[10240]; /* 10k is BIO_printf's limit anyway */
119 ascii2ebcdic(tmp, value, strlen(value)+1);
120 BIO_printf(out, "%*s%s", indent, "", tmp);
121 }
122#endif
107 } else if(method->i2v) { 123 } else if(method->i2v) {
108 if(!(nval = method->i2v(method, ext_str, NULL))) { 124 if(!(nval = method->i2v(method, ext_str, NULL))) {
109 ok = 0; 125 ok = 0;
diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c
new file mode 100644
index 0000000000..b7494ebcd5
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_purp.c
@@ -0,0 +1,456 @@
1/* v3_purp.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63
64static void x509v3_cache_extensions(X509 *x);
65
66static int ca_check(X509 *x);
67static int check_purpose_ssl_client(X509_PURPOSE *xp, X509 *x, int ca);
68static int check_purpose_ssl_server(X509_PURPOSE *xp, X509 *x, int ca);
69static int check_purpose_ns_ssl_server(X509_PURPOSE *xp, X509 *x, int ca);
70static int purpose_smime(X509 *x, int ca);
71static int check_purpose_smime_sign(X509_PURPOSE *xp, X509 *x, int ca);
72static int check_purpose_smime_encrypt(X509_PURPOSE *xp, X509 *x, int ca);
73static int check_purpose_crl_sign(X509_PURPOSE *xp, X509 *x, int ca);
74
75static int xp_cmp(X509_PURPOSE **a, X509_PURPOSE **b);
76static void xptable_free(X509_PURPOSE *p);
77
78static X509_PURPOSE xstandard[] = {
79 {X509_PURPOSE_SSL_CLIENT, X509_TRUST_SSL_CLIENT, 0, check_purpose_ssl_client, "SSL client", "sslclient", NULL},
80 {X509_PURPOSE_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ssl_server, "SSL server", "sslserver", NULL},
81 {X509_PURPOSE_NS_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, check_purpose_ns_ssl_server, "Netscape SSL server", "nssslserver", NULL},
82 {X509_PURPOSE_SMIME_SIGN, X509_TRUST_EMAIL, 0, check_purpose_smime_sign, "S/MIME signing", "smimesign", NULL},
83 {X509_PURPOSE_SMIME_ENCRYPT, X509_TRUST_EMAIL, 0, check_purpose_smime_encrypt, "S/MIME encryption", "smimeencrypt", NULL},
84 {X509_PURPOSE_CRL_SIGN, X509_TRUST_ANY, 0, check_purpose_crl_sign, "CRL signing", "crlsign", NULL},
85};
86
87#define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
88
89IMPLEMENT_STACK_OF(X509_PURPOSE)
90
91static STACK_OF(X509_PURPOSE) *xptable = NULL;
92
93static int xp_cmp(X509_PURPOSE **a, X509_PURPOSE **b)
94{
95 return (*a)->purpose - (*b)->purpose;
96}
97
98int X509_check_purpose(X509 *x, int id, int ca)
99{
100 int idx;
101 X509_PURPOSE *pt;
102 if(!(x->ex_flags & EXFLAG_SET)) {
103 CRYPTO_w_lock(CRYPTO_LOCK_X509);
104 x509v3_cache_extensions(x);
105 CRYPTO_w_unlock(CRYPTO_LOCK_X509);
106 }
107 if(id == -1) return 1;
108 idx = X509_PURPOSE_get_by_id(id);
109 if(idx == -1) return -1;
110 pt = X509_PURPOSE_get0(idx);
111 return pt->check_purpose(pt, x, ca);
112}
113
114int X509_PURPOSE_get_count(void)
115{
116 if(!xptable) return X509_PURPOSE_COUNT;
117 return sk_X509_PURPOSE_num(xptable) + X509_PURPOSE_COUNT;
118}
119
120X509_PURPOSE * X509_PURPOSE_get0(int idx)
121{
122 if(idx < 0) return NULL;
123 if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
124 return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
125}
126
127int X509_PURPOSE_get_by_sname(char *sname)
128{
129 int i;
130 X509_PURPOSE *xptmp;
131 for(i = 0; i < X509_PURPOSE_get_count(); i++) {
132 xptmp = X509_PURPOSE_get0(i);
133 if(!strcmp(xptmp->sname, sname)) return i;
134 }
135 return -1;
136}
137
138
139int X509_PURPOSE_get_by_id(int purpose)
140{
141 X509_PURPOSE tmp;
142 int idx;
143 if((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
144 return purpose - X509_PURPOSE_MIN;
145 tmp.purpose = purpose;
146 if(!xptable) return -1;
147 idx = sk_X509_PURPOSE_find(xptable, &tmp);
148 if(idx == -1) return -1;
149 return idx + X509_PURPOSE_COUNT;
150}
151
152int X509_PURPOSE_add(int id, int trust, int flags,
153 int (*ck)(X509_PURPOSE *, X509 *, int),
154 char *name, char *sname, void *arg)
155{
156 int idx;
157 X509_PURPOSE *ptmp;
158 /* This is set according to what we change: application can't set it */
159 flags &= ~X509_PURPOSE_DYNAMIC;
160 /* This will always be set for application modified trust entries */
161 flags |= X509_PURPOSE_DYNAMIC_NAME;
162 /* Get existing entry if any */
163 idx = X509_PURPOSE_get_by_id(id);
164 /* Need a new entry */
165 if(idx == -1) {
166 if(!(ptmp = Malloc(sizeof(X509_PURPOSE)))) {
167 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
168 return 0;
169 }
170 ptmp->flags = X509_PURPOSE_DYNAMIC;
171 } else ptmp = X509_PURPOSE_get0(idx);
172
173 /* Free existing name if dynamic */
174 if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
175 Free(ptmp->name);
176 Free(ptmp->sname);
177 }
178 /* dup supplied name */
179 ptmp->name = BUF_strdup(name);
180 ptmp->sname = BUF_strdup(sname);
181 if(!ptmp->name || !ptmp->sname) {
182 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
183 return 0;
184 }
185 /* Keep the dynamic flag of existing entry */
186 ptmp->flags &= X509_PURPOSE_DYNAMIC;
187 /* Set all other flags */
188 ptmp->flags |= flags;
189
190 ptmp->purpose = id;
191 ptmp->trust = trust;
192 ptmp->check_purpose = ck;
193 ptmp->usr_data = arg;
194
195 /* If its a new entry manage the dynamic table */
196 if(idx == -1) {
197 if(!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) {
198 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
199 return 0;
200 }
201 if (!sk_X509_PURPOSE_push(xptable, ptmp)) {
202 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
203 return 0;
204 }
205 }
206 return 1;
207}
208
209static void xptable_free(X509_PURPOSE *p)
210 {
211 if(!p) return;
212 if (p->flags & X509_PURPOSE_DYNAMIC)
213 {
214 if (p->flags & X509_PURPOSE_DYNAMIC_NAME) {
215 Free(p->name);
216 Free(p->sname);
217 }
218 Free(p);
219 }
220 }
221
222void X509_PURPOSE_cleanup(void)
223{
224 int i;
225 sk_X509_PURPOSE_pop_free(xptable, xptable_free);
226 for(i = 0; i < X509_PURPOSE_COUNT; i++) xptable_free(xstandard + i);
227 xptable = NULL;
228}
229
230int X509_PURPOSE_get_id(X509_PURPOSE *xp)
231{
232 return xp->purpose;
233}
234
235char *X509_PURPOSE_get0_name(X509_PURPOSE *xp)
236{
237 return xp->name;
238}
239
240char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp)
241{
242 return xp->sname;
243}
244
245int X509_PURPOSE_get_trust(X509_PURPOSE *xp)
246{
247 return xp->trust;
248}
249
250#ifndef NO_SHA
251static void x509v3_cache_extensions(X509 *x)
252{
253 BASIC_CONSTRAINTS *bs;
254 ASN1_BIT_STRING *usage;
255 ASN1_BIT_STRING *ns;
256 STACK_OF(ASN1_OBJECT) *extusage;
257 int i;
258 if(x->ex_flags & EXFLAG_SET) return;
259 X509_digest(x, EVP_sha1(), x->sha1_hash, NULL);
260 /* Does subject name match issuer ? */
261 if(!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x)))
262 x->ex_flags |= EXFLAG_SS;
263 /* V1 should mean no extensions ... */
264 if(!X509_get_version(x)) x->ex_flags |= EXFLAG_V1;
265 /* Handle basic constraints */
266 if((bs=X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {
267 if(bs->ca) x->ex_flags |= EXFLAG_CA;
268 if(bs->pathlen) {
269 if((bs->pathlen->type == V_ASN1_NEG_INTEGER)
270 || !bs->ca) {
271 x->ex_flags |= EXFLAG_INVALID;
272 x->ex_pathlen = 0;
273 } else x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);
274 } else x->ex_pathlen = -1;
275 BASIC_CONSTRAINTS_free(bs);
276 x->ex_flags |= EXFLAG_BCONS;
277 }
278 /* Handle key usage */
279 if((usage=X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {
280 if(usage->length > 0) {
281 x->ex_kusage = usage->data[0];
282 if(usage->length > 1)
283 x->ex_kusage |= usage->data[1] << 8;
284 } else x->ex_kusage = 0;
285 x->ex_flags |= EXFLAG_KUSAGE;
286 ASN1_BIT_STRING_free(usage);
287 }
288 x->ex_xkusage = 0;
289 if((extusage=X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {
290 x->ex_flags |= EXFLAG_XKUSAGE;
291 for(i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {
292 switch(OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage,i))) {
293 case NID_server_auth:
294 x->ex_xkusage |= XKU_SSL_SERVER;
295 break;
296
297 case NID_client_auth:
298 x->ex_xkusage |= XKU_SSL_CLIENT;
299 break;
300
301 case NID_email_protect:
302 x->ex_xkusage |= XKU_SMIME;
303 break;
304
305 case NID_code_sign:
306 x->ex_xkusage |= XKU_CODE_SIGN;
307 break;
308
309 case NID_ms_sgc:
310 case NID_ns_sgc:
311 x->ex_xkusage |= XKU_SGC;
312 }
313 }
314 sk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);
315 }
316
317 if((ns=X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {
318 if(ns->length > 0) x->ex_nscert = ns->data[0];
319 else x->ex_nscert = 0;
320 x->ex_flags |= EXFLAG_NSCERT;
321 ASN1_BIT_STRING_free(ns);
322 }
323 x->ex_flags |= EXFLAG_SET;
324}
325#endif
326
327/* CA checks common to all purposes
328 * return codes:
329 * 0 not a CA
330 * 1 is a CA
331 * 2 basicConstraints absent so "maybe" a CA
332 * 3 basicConstraints absent but self signed V1.
333 */
334
335#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)
336#define ku_reject(x, usage) \
337 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
338#define xku_reject(x, usage) \
339 (((x)->ex_flags & EXFLAG_XKUSAGE) && !((x)->ex_xkusage & (usage)))
340#define ns_reject(x, usage) \
341 (((x)->ex_flags & EXFLAG_NSCERT) && !((x)->ex_nscert & (usage)))
342
343static int ca_check(X509 *x)
344{
345 /* keyUsage if present should allow cert signing */
346 if(ku_reject(x, KU_KEY_CERT_SIGN)) return 0;
347 if(x->ex_flags & EXFLAG_BCONS) {
348 if(x->ex_flags & EXFLAG_CA) return 1;
349 /* If basicConstraints says not a CA then say so */
350 else return 0;
351 } else {
352 if((x->ex_flags & V1_ROOT) == V1_ROOT) return 3;
353 else return 2;
354 }
355}
356
357
358static int check_purpose_ssl_client(X509_PURPOSE *xp, X509 *x, int ca)
359{
360 if(xku_reject(x,XKU_SSL_CLIENT)) return 0;
361 if(ca) {
362 int ca_ret;
363 ca_ret = ca_check(x);
364 if(!ca_ret) return 0;
365 /* check nsCertType if present */
366 if(x->ex_flags & EXFLAG_NSCERT) {
367 if(x->ex_nscert & NS_SSL_CA) return ca_ret;
368 return 0;
369 }
370 if(ca_ret != 2) return ca_ret;
371 else return 0;
372 }
373 /* We need to do digital signatures with it */
374 if(ku_reject(x,KU_DIGITAL_SIGNATURE)) return 0;
375 /* nsCertType if present should allow SSL client use */
376 if(ns_reject(x, NS_SSL_CLIENT)) return 0;
377 return 1;
378}
379
380static int check_purpose_ssl_server(X509_PURPOSE *xp, X509 *x, int ca)
381{
382 if(xku_reject(x,XKU_SSL_SERVER|XKU_SGC)) return 0;
383 /* Otherwise same as SSL client for a CA */
384 if(ca) return check_purpose_ssl_client(xp, x, 1);
385
386 if(ns_reject(x, NS_SSL_SERVER)) return 0;
387 /* Now as for keyUsage: we'll at least need to sign OR encipher */
388 if(ku_reject(x, KU_DIGITAL_SIGNATURE|KU_KEY_ENCIPHERMENT)) return 0;
389
390 return 1;
391
392}
393
394static int check_purpose_ns_ssl_server(X509_PURPOSE *xp, X509 *x, int ca)
395{
396 int ret;
397 ret = check_purpose_ssl_server(xp, x, ca);
398 if(!ret || ca) return ret;
399 /* We need to encipher or Netscape complains */
400 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
401 return ret;
402}
403
404/* common S/MIME checks */
405static int purpose_smime(X509 *x, int ca)
406{
407 if(xku_reject(x,XKU_SMIME)) return 0;
408 if(ca) {
409 int ca_ret;
410 ca_ret = ca_check(x);
411 if(!ca_ret) return 0;
412 /* check nsCertType if present */
413 if(x->ex_flags & EXFLAG_NSCERT) {
414 if(x->ex_nscert & NS_SMIME_CA) return ca_ret;
415 return 0;
416 }
417 if(ca_ret != 2) return ca_ret;
418 else return 0;
419 }
420 if(x->ex_flags & EXFLAG_NSCERT) {
421 if(x->ex_nscert & NS_SMIME) return 1;
422 /* Workaround for some buggy certificates */
423 if(x->ex_nscert & NS_SSL_CLIENT) return 2;
424 return 0;
425 }
426 return 1;
427}
428
429static int check_purpose_smime_sign(X509_PURPOSE *xp, X509 *x, int ca)
430{
431 int ret;
432 ret = purpose_smime(x, ca);
433 if(!ret || ca) return ret;
434 if(ku_reject(x, KU_DIGITAL_SIGNATURE)) return 0;
435 return ret;
436}
437
438static int check_purpose_smime_encrypt(X509_PURPOSE *xp, X509 *x, int ca)
439{
440 int ret;
441 ret = purpose_smime(x, ca);
442 if(!ret || ca) return ret;
443 if(ku_reject(x, KU_KEY_ENCIPHERMENT)) return 0;
444 return ret;
445}
446
447static int check_purpose_crl_sign(X509_PURPOSE *xp, X509 *x, int ca)
448{
449 if(ca) {
450 int ca_ret;
451 if((ca_ret = ca_check(x)) != 2) return ca_ret;
452 else return 0;
453 }
454 if(ku_reject(x, KU_CRL_SIGN)) return 0;
455 return 1;
456}
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c
index fb3e36014d..939845fa8f 100644
--- a/src/lib/libcrypto/x509v3/v3_skey.c
+++ b/src/lib/libcrypto/x509v3/v3_skey.c
@@ -61,24 +61,17 @@
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/x509v3.h> 62#include <openssl/x509v3.h>
63 63
64static ASN1_OCTET_STRING *octet_string_new(void);
65static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); 64static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
66X509V3_EXT_METHOD v3_skey_id = { 65X509V3_EXT_METHOD v3_skey_id = {
67NID_subject_key_identifier, 0, 66NID_subject_key_identifier, 0,
68(X509V3_EXT_NEW)octet_string_new, 67(X509V3_EXT_NEW)ASN1_OCTET_STRING_new,
69(X509V3_EXT_FREE)ASN1_STRING_free, 68(X509V3_EXT_FREE)ASN1_OCTET_STRING_free,
70(X509V3_EXT_D2I)d2i_ASN1_OCTET_STRING, 69(X509V3_EXT_D2I)d2i_ASN1_OCTET_STRING,
71(X509V3_EXT_I2D)i2d_ASN1_OCTET_STRING, 70(X509V3_EXT_I2D)i2d_ASN1_OCTET_STRING,
72(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING, 71(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING,
73(X509V3_EXT_S2I)s2i_skey_id, 72(X509V3_EXT_S2I)s2i_skey_id,
74NULL, NULL, NULL, NULL, NULL}; 73NULL, NULL, NULL, NULL, NULL};
75 74
76
77static ASN1_OCTET_STRING *octet_string_new(void)
78{
79 return ASN1_OCTET_STRING_new();
80}
81
82char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, 75char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
83 ASN1_OCTET_STRING *oct) 76 ASN1_OCTET_STRING *oct)
84{ 77{
@@ -91,13 +84,13 @@ ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
91 ASN1_OCTET_STRING *oct; 84 ASN1_OCTET_STRING *oct;
92 long length; 85 long length;
93 86
94 if(!(oct = ASN1_OCTET_STRING_new())) { 87 if(!(oct = M_ASN1_OCTET_STRING_new())) {
95 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); 88 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
96 return NULL; 89 return NULL;
97 } 90 }
98 91
99 if(!(oct->data = string_to_hex(str, &length))) { 92 if(!(oct->data = string_to_hex(str, &length))) {
100 ASN1_OCTET_STRING_free(oct); 93 M_ASN1_OCTET_STRING_free(oct);
101 return NULL; 94 return NULL;
102 } 95 }
103 96
@@ -118,7 +111,7 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
118 111
119 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str); 112 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str);
120 113
121 if(!(oct = ASN1_OCTET_STRING_new())) { 114 if(!(oct = M_ASN1_OCTET_STRING_new())) {
122 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE); 115 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
123 return NULL; 116 return NULL;
124 } 117 }
@@ -143,7 +136,7 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
143 EVP_DigestUpdate(&md, pk->data, pk->length); 136 EVP_DigestUpdate(&md, pk->data, pk->length);
144 EVP_DigestFinal(&md, pkey_dig, &diglen); 137 EVP_DigestFinal(&md, pkey_dig, &diglen);
145 138
146 if(!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) { 139 if(!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
147 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE); 140 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
148 goto err; 141 goto err;
149 } 142 }
@@ -151,6 +144,6 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
151 return oct; 144 return oct;
152 145
153 err: 146 err:
154 ASN1_OCTET_STRING_free(oct); 147 M_ASN1_OCTET_STRING_free(oct);
155 return NULL; 148 return NULL;
156} 149}
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
index 0687bb4e3d..20ba8ac8d6 100644
--- a/src/lib/libcrypto/x509v3/v3_sxnet.c
+++ b/src/lib/libcrypto/x509v3/v3_sxnet.c
@@ -111,7 +111,7 @@ SXNET *SXNET_new(void)
111 SXNET *ret=NULL; 111 SXNET *ret=NULL;
112 ASN1_CTX c; 112 ASN1_CTX c;
113 M_ASN1_New_Malloc(ret, SXNET); 113 M_ASN1_New_Malloc(ret, SXNET);
114 M_ASN1_New(ret->version,ASN1_INTEGER_new); 114 M_ASN1_New(ret->version,M_ASN1_INTEGER_new);
115 M_ASN1_New(ret->ids,sk_SXNETID_new_null); 115 M_ASN1_New(ret->ids,sk_SXNETID_new_null);
116 return (ret); 116 return (ret);
117 M_ASN1_New_Error(ASN1_F_SXNET_NEW); 117 M_ASN1_New_Error(ASN1_F_SXNET_NEW);
@@ -130,7 +130,7 @@ SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length)
130void SXNET_free(SXNET *a) 130void SXNET_free(SXNET *a)
131{ 131{
132 if (a == NULL) return; 132 if (a == NULL) return;
133 ASN1_INTEGER_free(a->version); 133 M_ASN1_INTEGER_free(a->version);
134 sk_SXNETID_pop_free(a->ids, SXNETID_free); 134 sk_SXNETID_pop_free(a->ids, SXNETID_free);
135 Free (a); 135 Free (a);
136} 136}
@@ -156,7 +156,7 @@ SXNETID *SXNETID_new(void)
156 ASN1_CTX c; 156 ASN1_CTX c;
157 M_ASN1_New_Malloc(ret, SXNETID); 157 M_ASN1_New_Malloc(ret, SXNETID);
158 ret->zone = NULL; 158 ret->zone = NULL;
159 M_ASN1_New(ret->user,ASN1_OCTET_STRING_new); 159 M_ASN1_New(ret->user,M_ASN1_OCTET_STRING_new);
160 return (ret); 160 return (ret);
161 M_ASN1_New_Error(ASN1_F_SXNETID_NEW); 161 M_ASN1_New_Error(ASN1_F_SXNETID_NEW);
162} 162}
@@ -174,8 +174,8 @@ SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length)
174void SXNETID_free(SXNETID *a) 174void SXNETID_free(SXNETID *a)
175{ 175{
176 if (a == NULL) return; 176 if (a == NULL) return;
177 ASN1_INTEGER_free(a->zone); 177 M_ASN1_INTEGER_free(a->zone);
178 ASN1_OCTET_STRING_free(a->user); 178 M_ASN1_OCTET_STRING_free(a->user);
179 Free (a); 179 Free (a);
180} 180}
181 181
@@ -193,7 +193,7 @@ static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
193 tmp = i2s_ASN1_INTEGER(NULL, id->zone); 193 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
194 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp); 194 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
195 Free(tmp); 195 Free(tmp);
196 ASN1_OCTET_STRING_print(out, id->user); 196 M_ASN1_OCTET_STRING_print(out, id->user);
197 } 197 }
198 return 1; 198 return 1;
199} 199}
@@ -244,9 +244,9 @@ int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
244 int userlen) 244 int userlen)
245{ 245{
246 ASN1_INTEGER *izone = NULL; 246 ASN1_INTEGER *izone = NULL;
247 if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { 247 if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
248 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE); 248 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
249 ASN1_INTEGER_free(izone); 249 M_ASN1_INTEGER_free(izone);
250 return 0; 250 return 0;
251 } 251 }
252 return SXNET_add_id_INTEGER(psx, izone, user, userlen); 252 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
@@ -285,7 +285,7 @@ int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
285 if(!(id = SXNETID_new())) goto err; 285 if(!(id = SXNETID_new())) goto err;
286 if(userlen == -1) userlen = strlen(user); 286 if(userlen == -1) userlen = strlen(user);
287 287
288 if(!ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err; 288 if(!M_ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err;
289 if(!sk_SXNETID_push(sx->ids, id)) goto err; 289 if(!sk_SXNETID_push(sx->ids, id)) goto err;
290 id->zone = zone; 290 id->zone = zone;
291 return 1; 291 return 1;
@@ -307,7 +307,7 @@ ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone)
307 return NULL; 307 return NULL;
308 } 308 }
309 oct = SXNET_get_id_INTEGER(sx, izone); 309 oct = SXNET_get_id_INTEGER(sx, izone);
310 ASN1_INTEGER_free(izone); 310 M_ASN1_INTEGER_free(izone);
311 return oct; 311 return oct;
312} 312}
313 313
@@ -315,13 +315,13 @@ ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
315{ 315{
316 ASN1_INTEGER *izone = NULL; 316 ASN1_INTEGER *izone = NULL;
317 ASN1_OCTET_STRING *oct; 317 ASN1_OCTET_STRING *oct;
318 if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { 318 if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
319 X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE); 319 X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);
320 ASN1_INTEGER_free(izone); 320 M_ASN1_INTEGER_free(izone);
321 return NULL; 321 return NULL;
322 } 322 }
323 oct = SXNET_get_id_INTEGER(sx, izone); 323 oct = SXNET_get_id_INTEGER(sx, izone);
324 ASN1_INTEGER_free(izone); 324 M_ASN1_INTEGER_free(izone);
325 return oct; 325 return oct;
326} 326}
327 327
@@ -331,7 +331,7 @@ ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
331 int i; 331 int i;
332 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) { 332 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
333 id = sk_SXNETID_value(sx->ids, i); 333 id = sk_SXNETID_value(sx->ids, i);
334 if(!ASN1_INTEGER_cmp(id->zone, zone)) return id->user; 334 if(!M_ASN1_INTEGER_cmp(id->zone, zone)) return id->user;
335 } 335 }
336 return NULL; 336 return NULL;
337} 337}
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
index 40f71c71b4..4c2c4a9483 100644
--- a/src/lib/libcrypto/x509v3/v3_utl.c
+++ b/src/lib/libcrypto/x509v3/v3_utl.c
@@ -104,7 +104,7 @@ void X509V3_conf_free(CONF_VALUE *conf)
104 if(conf->name) Free(conf->name); 104 if(conf->name) Free(conf->name);
105 if(conf->value) Free(conf->value); 105 if(conf->value) Free(conf->value);
106 if(conf->section) Free(conf->section); 106 if(conf->section) Free(conf->section);
107 Free((char *)conf); 107 Free(conf);
108} 108}
109 109
110int X509V3_add_value_bool(const char *name, int asn1_bool, 110int X509V3_add_value_bool(const char *name, int asn1_bool,
diff --git a/src/lib/libcrypto/x509v3/v3err.c b/src/lib/libcrypto/x509v3/v3err.c
index 50efa8d99d..b7d4e350c4 100644
--- a/src/lib/libcrypto/x509v3/v3err.c
+++ b/src/lib/libcrypto/x509v3/v3err.c
@@ -72,6 +72,7 @@ static ERR_STRING_DATA X509V3_str_functs[]=
72{ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"}, 72{ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"},
73{ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"}, 73{ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"},
74{ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"}, 74{ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"},
75{ERR_PACK(0,X509V3_F_I2V_AUTHORITY_INFO_ACCESS,0), "I2V_AUTHORITY_INFO_ACCESS"},
75{ERR_PACK(0,X509V3_F_NOTICE_SECTION,0), "NOTICE_SECTION"}, 76{ERR_PACK(0,X509V3_F_NOTICE_SECTION,0), "NOTICE_SECTION"},
76{ERR_PACK(0,X509V3_F_NREF_NOS,0), "NREF_NOS"}, 77{ERR_PACK(0,X509V3_F_NREF_NOS,0), "NREF_NOS"},
77{ERR_PACK(0,X509V3_F_POLICY_SECTION,0), "POLICY_SECTION"}, 78{ERR_PACK(0,X509V3_F_POLICY_SECTION,0), "POLICY_SECTION"},
@@ -87,6 +88,7 @@ static ERR_STRING_DATA X509V3_str_functs[]=
87{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_ULONG,0), "SXNET_add_id_ulong"}, 88{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_ULONG,0), "SXNET_add_id_ulong"},
88{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ASC,0), "SXNET_get_id_asc"}, 89{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ASC,0), "SXNET_get_id_asc"},
89{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ULONG,0), "SXNET_get_id_ulong"}, 90{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ULONG,0), "SXNET_get_id_ulong"},
91{ERR_PACK(0,X509V3_F_V2I_ACCESS_DESCRIPTION,0), "V2I_ACCESS_DESCRIPTION"},
90{ERR_PACK(0,X509V3_F_V2I_ASN1_BIT_STRING,0), "V2I_ASN1_BIT_STRING"}, 92{ERR_PACK(0,X509V3_F_V2I_ASN1_BIT_STRING,0), "V2I_ASN1_BIT_STRING"},
91{ERR_PACK(0,X509V3_F_V2I_AUTHORITY_KEYID,0), "V2I_AUTHORITY_KEYID"}, 93{ERR_PACK(0,X509V3_F_V2I_AUTHORITY_KEYID,0), "V2I_AUTHORITY_KEYID"},
92{ERR_PACK(0,X509V3_F_V2I_BASIC_CONSTRAINTS,0), "V2I_BASIC_CONSTRAINTS"}, 94{ERR_PACK(0,X509V3_F_V2I_BASIC_CONSTRAINTS,0), "V2I_BASIC_CONSTRAINTS"},
@@ -102,6 +104,7 @@ static ERR_STRING_DATA X509V3_str_functs[]=
102{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"}, 104{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"},
103{ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"}, 105{ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"},
104{ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"}, 106{ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"},
107{ERR_PACK(0,X509V3_F_X509_PURPOSE_ADD,0), "X509_PURPOSE_add"},
105{0,NULL} 108{0,NULL}
106 }; 109 };
107 110
@@ -132,6 +135,7 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
132{X509V3_R_INVALID_OPTION ,"invalid option"}, 135{X509V3_R_INVALID_OPTION ,"invalid option"},
133{X509V3_R_INVALID_POLICY_IDENTIFIER ,"invalid policy identifier"}, 136{X509V3_R_INVALID_POLICY_IDENTIFIER ,"invalid policy identifier"},
134{X509V3_R_INVALID_SECTION ,"invalid section"}, 137{X509V3_R_INVALID_SECTION ,"invalid section"},
138{X509V3_R_INVALID_SYNTAX ,"invalid syntax"},
135{X509V3_R_ISSUER_DECODE_ERROR ,"issuer decode error"}, 139{X509V3_R_ISSUER_DECODE_ERROR ,"issuer decode error"},
136{X509V3_R_MISSING_VALUE ,"missing value"}, 140{X509V3_R_MISSING_VALUE ,"missing value"},
137{X509V3_R_NEED_ORGANIZATION_AND_NUMBERS ,"need organization and numbers"}, 141{X509V3_R_NEED_ORGANIZATION_AND_NUMBERS ,"need organization and numbers"},
diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h
index 4eb04a5a89..fe01755797 100644
--- a/src/lib/libcrypto/x509v3/x509v3.h
+++ b/src/lib/libcrypto/x509v3/x509v3.h
@@ -136,12 +136,6 @@ typedef struct v3_ext_ctx X509V3_CTX;
136#define X509V3_EXT_CTX_DEP 0x2 136#define X509V3_EXT_CTX_DEP 0x2
137#define X509V3_EXT_MULTILINE 0x4 137#define X509V3_EXT_MULTILINE 0x4
138 138
139typedef struct BIT_STRING_BITNAME_st {
140int bitnum;
141const char *lname;
142const char *sname;
143} BIT_STRING_BITNAME;
144
145typedef BIT_STRING_BITNAME ENUMERATED_NAMES; 139typedef BIT_STRING_BITNAME ENUMERATED_NAMES;
146 140
147typedef struct BASIC_CONSTRAINTS_st { 141typedef struct BASIC_CONSTRAINTS_st {
@@ -155,6 +149,11 @@ ASN1_GENERALIZEDTIME *notBefore;
155ASN1_GENERALIZEDTIME *notAfter; 149ASN1_GENERALIZEDTIME *notAfter;
156} PKEY_USAGE_PERIOD; 150} PKEY_USAGE_PERIOD;
157 151
152typedef struct otherName_st {
153ASN1_OBJECT *type_id;
154ASN1_TYPE *value;
155} OTHERNAME;
156
158typedef struct GENERAL_NAME_st { 157typedef struct GENERAL_NAME_st {
159 158
160#define GEN_OTHERNAME (0|V_ASN1_CONTEXT_SPECIFIC) 159#define GEN_OTHERNAME (0|V_ASN1_CONTEXT_SPECIFIC)
@@ -174,17 +173,26 @@ union {
174 ASN1_OCTET_STRING *ip; /* iPAddress */ 173 ASN1_OCTET_STRING *ip; /* iPAddress */
175 X509_NAME *dirn; /* dirn */ 174 X509_NAME *dirn; /* dirn */
176 ASN1_OBJECT *rid; /* registeredID */ 175 ASN1_OBJECT *rid; /* registeredID */
177 ASN1_TYPE *other; /* otherName, ediPartyName, x400Address */ 176 OTHERNAME *otherName; /* otherName */
177 ASN1_TYPE *other; /* ediPartyName, x400Address */
178} d; 178} d;
179} GENERAL_NAME; 179} GENERAL_NAME;
180 180
181typedef struct ACCESS_DESCRIPTION_st {
182ASN1_OBJECT *method;
183GENERAL_NAME *location;
184} ACCESS_DESCRIPTION;
185
181DECLARE_STACK_OF(GENERAL_NAME) 186DECLARE_STACK_OF(GENERAL_NAME)
182DECLARE_ASN1_SET_OF(GENERAL_NAME) 187DECLARE_ASN1_SET_OF(GENERAL_NAME)
183 188
189DECLARE_STACK_OF(ACCESS_DESCRIPTION)
190DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION)
191
184typedef struct DIST_POINT_NAME_st { 192typedef struct DIST_POINT_NAME_st {
185/* NB: this is a CHOICE type and only one of these should be set */ 193/* NB: this is a CHOICE type and only one of these should be set */
186STACK_OF(GENERAL_NAME) *fullname; 194STACK_OF(GENERAL_NAME) *fullname;
187X509_NAME *relativename; 195STACK_OF(X509_NAME_ENTRY) *relativename;
188} DIST_POINT_NAME; 196} DIST_POINT_NAME;
189 197
190typedef struct DIST_POINT_st { 198typedef struct DIST_POINT_st {
@@ -255,8 +263,8 @@ DECLARE_ASN1_SET_OF(POLICYINFO)
255#define X509V3_set_ctx_nodb(ctx) ctx->db = NULL; 263#define X509V3_set_ctx_nodb(ctx) ctx->db = NULL;
256 264
257#define EXT_BITSTRING(nid, table) { nid, 0, \ 265#define EXT_BITSTRING(nid, table) { nid, 0, \
258 (X509V3_EXT_NEW)asn1_bit_string_new, \ 266 (X509V3_EXT_NEW)ASN1_BIT_STRING_new, \
259 (X509V3_EXT_FREE)ASN1_STRING_free, \ 267 (X509V3_EXT_FREE)ASN1_BIT_STRING_free, \
260 (X509V3_EXT_D2I)d2i_ASN1_BIT_STRING, \ 268 (X509V3_EXT_D2I)d2i_ASN1_BIT_STRING, \
261 (X509V3_EXT_I2D)i2d_ASN1_BIT_STRING, \ 269 (X509V3_EXT_I2D)i2d_ASN1_BIT_STRING, \
262 NULL, NULL, \ 270 NULL, NULL, \
@@ -266,8 +274,8 @@ DECLARE_ASN1_SET_OF(POLICYINFO)
266 (char *)table} 274 (char *)table}
267 275
268#define EXT_IA5STRING(nid) { nid, 0, \ 276#define EXT_IA5STRING(nid) { nid, 0, \
269 (X509V3_EXT_NEW)ia5string_new, \ 277 (X509V3_EXT_NEW)ASN1_IA5STRING_new, \
270 (X509V3_EXT_FREE)ASN1_STRING_free, \ 278 (X509V3_EXT_FREE)ASN1_IA5STRING_free, \
271 (X509V3_EXT_D2I)d2i_ASN1_IA5STRING, \ 279 (X509V3_EXT_D2I)d2i_ASN1_IA5STRING, \
272 (X509V3_EXT_I2D)i2d_ASN1_IA5STRING, \ 280 (X509V3_EXT_I2D)i2d_ASN1_IA5STRING, \
273 (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \ 281 (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \
@@ -279,6 +287,69 @@ DECLARE_ASN1_SET_OF(POLICYINFO)
279 NULL, NULL, NULL, NULL, \ 287 NULL, NULL, NULL, NULL, \
280 NULL} 288 NULL}
281 289
290
291/* X509_PURPOSE stuff */
292
293#define EXFLAG_BCONS 0x1
294#define EXFLAG_KUSAGE 0x2
295#define EXFLAG_XKUSAGE 0x4
296#define EXFLAG_NSCERT 0x8
297
298#define EXFLAG_CA 0x10
299#define EXFLAG_SS 0x20
300#define EXFLAG_V1 0x40
301#define EXFLAG_INVALID 0x80
302#define EXFLAG_SET 0x100
303
304#define KU_DIGITAL_SIGNATURE 0x0080
305#define KU_NON_REPUDIATION 0x0040
306#define KU_KEY_ENCIPHERMENT 0x0020
307#define KU_DATA_ENCIPHERMENT 0x0010
308#define KU_KEY_AGREEMENT 0x0008
309#define KU_KEY_CERT_SIGN 0x0004
310#define KU_CRL_SIGN 0x0002
311#define KU_ENCIPHER_ONLY 0x0001
312#define KU_DECIPHER_ONLY 0x8000
313
314#define NS_SSL_CLIENT 0x80
315#define NS_SSL_SERVER 0x40
316#define NS_SMIME 0x20
317#define NS_OBJSIGN 0x10
318#define NS_SSL_CA 0x04
319#define NS_SMIME_CA 0x02
320#define NS_OBJSIGN_CA 0x01
321
322#define XKU_SSL_SERVER 0x1
323#define XKU_SSL_CLIENT 0x2
324#define XKU_SMIME 0x4
325#define XKU_CODE_SIGN 0x8
326#define XKU_SGC 0x10
327
328#define X509_PURPOSE_DYNAMIC 0x1
329#define X509_PURPOSE_DYNAMIC_NAME 0x2
330
331typedef struct x509_purpose_st {
332 int purpose;
333 int trust; /* Default trust ID */
334 int flags;
335 int (*check_purpose)(struct x509_purpose_st *, X509 *, int);
336 char *name;
337 char *sname;
338 void *usr_data;
339} X509_PURPOSE;
340
341#define X509_PURPOSE_SSL_CLIENT 1
342#define X509_PURPOSE_SSL_SERVER 2
343#define X509_PURPOSE_NS_SSL_SERVER 3
344#define X509_PURPOSE_SMIME_SIGN 4
345#define X509_PURPOSE_SMIME_ENCRYPT 5
346#define X509_PURPOSE_CRL_SIGN 6
347
348#define X509_PURPOSE_MIN 1
349#define X509_PURPOSE_MAX 6
350
351DECLARE_STACK_OF(X509_PURPOSE)
352
282void ERR_load_X509V3_strings(void); 353void ERR_load_X509V3_strings(void);
283int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp); 354int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp);
284BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length); 355BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length);
@@ -328,6 +399,11 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
328STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method, 399STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
329 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); 400 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
330 401
402int i2d_OTHERNAME(OTHERNAME *a, unsigned char **pp);
403OTHERNAME *OTHERNAME_new(void);
404OTHERNAME *d2i_OTHERNAME(OTHERNAME **a, unsigned char **pp, long length);
405void OTHERNAME_free(OTHERNAME *a);
406
331char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5); 407char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
332ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); 408ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
333 409
@@ -380,12 +456,27 @@ void DIST_POINT_NAME_free(DIST_POINT_NAME *a);
380DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp, 456DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
381 long length); 457 long length);
382 458
459int i2d_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION *a, unsigned char **pp);
460ACCESS_DESCRIPTION *ACCESS_DESCRIPTION_new(void);
461void ACCESS_DESCRIPTION_free(ACCESS_DESCRIPTION *a);
462ACCESS_DESCRIPTION *d2i_ACCESS_DESCRIPTION(ACCESS_DESCRIPTION **a, unsigned char **pp,
463 long length);
464
465STACK_OF(ACCESS_DESCRIPTION) *AUTHORITY_INFO_ACCESS_new(void);
466void AUTHORITY_INFO_ACCESS_free(STACK_OF(ACCESS_DESCRIPTION) *a);
467STACK_OF(ACCESS_DESCRIPTION) *d2i_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) **a,
468 unsigned char **pp, long length);
469int i2d_AUTHORITY_INFO_ACCESS(STACK_OF(ACCESS_DESCRIPTION) *a, unsigned char **pp);
470
471
472
383#ifdef HEADER_CONF_H 473#ifdef HEADER_CONF_H
384GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf); 474GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf);
385void X509V3_conf_free(CONF_VALUE *val); 475void X509V3_conf_free(CONF_VALUE *val);
386X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value); 476X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
387X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value); 477X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
388int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert); 478int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
479int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_REQ *req);
389int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl); 480int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
390int X509V3_add_value_bool_nf(char *name, int asn1_bool, 481int X509V3_add_value_bool_nf(char *name, int asn1_bool,
391 STACK_OF(CONF_VALUE) **extlist); 482 STACK_OF(CONF_VALUE) **extlist);
@@ -423,6 +514,8 @@ X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
423int X509V3_add_standard_extensions(void); 514int X509V3_add_standard_extensions(void);
424STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line); 515STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line);
425void *X509V3_EXT_d2i(X509_EXTENSION *ext); 516void *X509V3_EXT_d2i(X509_EXTENSION *ext);
517void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
518
426X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); 519X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
427 520
428char *hex_to_string(unsigned char *buffer, long len); 521char *hex_to_string(unsigned char *buffer, long len);
@@ -434,6 +527,20 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,
434int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent); 527int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
435int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); 528int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
436 529
530int X509_check_purpose(X509 *x, int id, int ca);
531int X509_PURPOSE_get_count(void);
532X509_PURPOSE * X509_PURPOSE_get0(int idx);
533int X509_PURPOSE_get_by_sname(char *sname);
534int X509_PURPOSE_get_by_id(int id);
535int X509_PURPOSE_add(int id, int trust, int flags,
536 int (*ck)(X509_PURPOSE *, X509 *, int),
537 char *name, char *sname, void *arg);
538char *X509_PURPOSE_get0_name(X509_PURPOSE *xp);
539char *X509_PURPOSE_get0_sname(X509_PURPOSE *xp);
540int X509_PURPOSE_get_trust(X509_PURPOSE *xp);
541void X509_PURPOSE_cleanup(void);
542int X509_PURPOSE_get_id(X509_PURPOSE *);
543
437/* BEGIN ERROR CODES */ 544/* BEGIN ERROR CODES */
438/* The following lines are auto generated by the script mkerr.pl. Any changes 545/* The following lines are auto generated by the script mkerr.pl. Any changes
439 * made after this point may be overwritten when the script is next run. 546 * made after this point may be overwritten when the script is next run.
@@ -449,6 +556,7 @@ int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
449#define X509V3_F_HEX_TO_STRING 111 556#define X509V3_F_HEX_TO_STRING 111
450#define X509V3_F_I2S_ASN1_ENUMERATED 121 557#define X509V3_F_I2S_ASN1_ENUMERATED 121
451#define X509V3_F_I2S_ASN1_INTEGER 120 558#define X509V3_F_I2S_ASN1_INTEGER 120
559#define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138
452#define X509V3_F_NOTICE_SECTION 132 560#define X509V3_F_NOTICE_SECTION 132
453#define X509V3_F_NREF_NOS 133 561#define X509V3_F_NREF_NOS 133
454#define X509V3_F_POLICY_SECTION 131 562#define X509V3_F_POLICY_SECTION 131
@@ -464,6 +572,7 @@ int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
464#define X509V3_F_SXNET_ADD_ID_ULONG 127 572#define X509V3_F_SXNET_ADD_ID_ULONG 127
465#define X509V3_F_SXNET_GET_ID_ASC 128 573#define X509V3_F_SXNET_GET_ID_ASC 128
466#define X509V3_F_SXNET_GET_ID_ULONG 129 574#define X509V3_F_SXNET_GET_ID_ULONG 129
575#define X509V3_F_V2I_ACCESS_DESCRIPTION 139
467#define X509V3_F_V2I_ASN1_BIT_STRING 101 576#define X509V3_F_V2I_ASN1_BIT_STRING 101
468#define X509V3_F_V2I_AUTHORITY_KEYID 119 577#define X509V3_F_V2I_AUTHORITY_KEYID 119
469#define X509V3_F_V2I_BASIC_CONSTRAINTS 102 578#define X509V3_F_V2I_BASIC_CONSTRAINTS 102
@@ -479,6 +588,7 @@ int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
479#define X509V3_F_X509V3_EXT_I2D 136 588#define X509V3_F_X509V3_EXT_I2D 136
480#define X509V3_F_X509V3_GET_VALUE_BOOL 110 589#define X509V3_F_X509V3_GET_VALUE_BOOL 110
481#define X509V3_F_X509V3_PARSE_LIST 109 590#define X509V3_F_X509V3_PARSE_LIST 109
591#define X509V3_F_X509_PURPOSE_ADD 137
482 592
483/* Reason codes. */ 593/* Reason codes. */
484#define X509V3_R_BAD_IP_ADDRESS 118 594#define X509V3_R_BAD_IP_ADDRESS 118
@@ -506,6 +616,7 @@ int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
506#define X509V3_R_INVALID_OPTION 138 616#define X509V3_R_INVALID_OPTION 138
507#define X509V3_R_INVALID_POLICY_IDENTIFIER 134 617#define X509V3_R_INVALID_POLICY_IDENTIFIER 134
508#define X509V3_R_INVALID_SECTION 135 618#define X509V3_R_INVALID_SECTION 135
619#define X509V3_R_INVALID_SYNTAX 143
509#define X509V3_R_ISSUER_DECODE_ERROR 126 620#define X509V3_R_ISSUER_DECODE_ERROR 126
510#define X509V3_R_MISSING_VALUE 124 621#define X509V3_R_MISSING_VALUE 124
511#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142 622#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142